xref: /linux/drivers/net/ethernet/sfc/siena/tx.c (revision 4f2c0a4acffbec01079c28f839422e64ddeff004)
1d48523cbSMartin Habets // SPDX-License-Identifier: GPL-2.0-only
2d48523cbSMartin Habets /****************************************************************************
3d48523cbSMartin Habets  * Driver for Solarflare network controllers and boards
4d48523cbSMartin Habets  * Copyright 2005-2006 Fen Systems Ltd.
5d48523cbSMartin Habets  * Copyright 2005-2013 Solarflare Communications Inc.
6d48523cbSMartin Habets  */
7d48523cbSMartin Habets 
8d48523cbSMartin Habets #include <linux/pci.h>
9d48523cbSMartin Habets #include <linux/tcp.h>
10d48523cbSMartin Habets #include <linux/ip.h>
11d48523cbSMartin Habets #include <linux/in.h>
12d48523cbSMartin Habets #include <linux/ipv6.h>
13d48523cbSMartin Habets #include <linux/slab.h>
14d48523cbSMartin Habets #include <net/ipv6.h>
15d48523cbSMartin Habets #include <linux/if_ether.h>
16d48523cbSMartin Habets #include <linux/highmem.h>
17d48523cbSMartin Habets #include <linux/cache.h>
18d48523cbSMartin Habets #include "net_driver.h"
19d48523cbSMartin Habets #include "efx.h"
20d48523cbSMartin Habets #include "io.h"
21d48523cbSMartin Habets #include "nic.h"
22d48523cbSMartin Habets #include "tx.h"
23d48523cbSMartin Habets #include "tx_common.h"
24d48523cbSMartin Habets #include "workarounds.h"
25d48523cbSMartin Habets 
efx_tx_get_copy_buffer(struct efx_tx_queue * tx_queue,struct efx_tx_buffer * buffer)26d48523cbSMartin Habets static inline u8 *efx_tx_get_copy_buffer(struct efx_tx_queue *tx_queue,
27d48523cbSMartin Habets 					 struct efx_tx_buffer *buffer)
28d48523cbSMartin Habets {
29d48523cbSMartin Habets 	unsigned int index = efx_tx_queue_get_insert_index(tx_queue);
30d48523cbSMartin Habets 	struct efx_buffer *page_buf =
31d48523cbSMartin Habets 		&tx_queue->cb_page[index >> (PAGE_SHIFT - EFX_TX_CB_ORDER)];
32d48523cbSMartin Habets 	unsigned int offset =
33d48523cbSMartin Habets 		((index << EFX_TX_CB_ORDER) + NET_IP_ALIGN) & (PAGE_SIZE - 1);
34d48523cbSMartin Habets 
35d48523cbSMartin Habets 	if (unlikely(!page_buf->addr) &&
36c8443b69SMartin Habets 	    efx_siena_alloc_buffer(tx_queue->efx, page_buf, PAGE_SIZE,
37d48523cbSMartin Habets 				   GFP_ATOMIC))
38d48523cbSMartin Habets 		return NULL;
39d48523cbSMartin Habets 	buffer->dma_addr = page_buf->dma_addr + offset;
40d48523cbSMartin Habets 	buffer->unmap_len = 0;
41d48523cbSMartin Habets 	return (u8 *)page_buf->addr + offset;
42d48523cbSMartin Habets }
43d48523cbSMartin Habets 
efx_tx_maybe_stop_queue(struct efx_tx_queue * txq1)44d48523cbSMartin Habets static void efx_tx_maybe_stop_queue(struct efx_tx_queue *txq1)
45d48523cbSMartin Habets {
46d48523cbSMartin Habets 	/* We need to consider all queues that the net core sees as one */
47d48523cbSMartin Habets 	struct efx_nic *efx = txq1->efx;
48d48523cbSMartin Habets 	struct efx_tx_queue *txq2;
49d48523cbSMartin Habets 	unsigned int fill_level;
50d48523cbSMartin Habets 
51d48523cbSMartin Habets 	fill_level = efx_channel_tx_old_fill_level(txq1->channel);
52d48523cbSMartin Habets 	if (likely(fill_level < efx->txq_stop_thresh))
53d48523cbSMartin Habets 		return;
54d48523cbSMartin Habets 
55d48523cbSMartin Habets 	/* We used the stale old_read_count above, which gives us a
56d48523cbSMartin Habets 	 * pessimistic estimate of the fill level (which may even
57d48523cbSMartin Habets 	 * validly be >= efx->txq_entries).  Now try again using
58d48523cbSMartin Habets 	 * read_count (more likely to be a cache miss).
59d48523cbSMartin Habets 	 *
60d48523cbSMartin Habets 	 * If we read read_count and then conditionally stop the
61d48523cbSMartin Habets 	 * queue, it is possible for the completion path to race with
62d48523cbSMartin Habets 	 * us and complete all outstanding descriptors in the middle,
63d48523cbSMartin Habets 	 * after which there will be no more completions to wake it.
64d48523cbSMartin Habets 	 * Therefore we stop the queue first, then read read_count
65d48523cbSMartin Habets 	 * (with a memory barrier to ensure the ordering), then
66d48523cbSMartin Habets 	 * restart the queue if the fill level turns out to be low
67d48523cbSMartin Habets 	 * enough.
68d48523cbSMartin Habets 	 */
69d48523cbSMartin Habets 	netif_tx_stop_queue(txq1->core_txq);
70d48523cbSMartin Habets 	smp_mb();
71d48523cbSMartin Habets 	efx_for_each_channel_tx_queue(txq2, txq1->channel)
72d48523cbSMartin Habets 		txq2->old_read_count = READ_ONCE(txq2->read_count);
73d48523cbSMartin Habets 
74d48523cbSMartin Habets 	fill_level = efx_channel_tx_old_fill_level(txq1->channel);
75d48523cbSMartin Habets 	EFX_WARN_ON_ONCE_PARANOID(fill_level >= efx->txq_entries);
76d48523cbSMartin Habets 	if (likely(fill_level < efx->txq_stop_thresh)) {
77d48523cbSMartin Habets 		smp_mb();
78d48523cbSMartin Habets 		if (likely(!efx->loopback_selftest))
79d48523cbSMartin Habets 			netif_tx_start_queue(txq1->core_txq);
80d48523cbSMartin Habets 	}
81d48523cbSMartin Habets }
82d48523cbSMartin Habets 
efx_enqueue_skb_copy(struct efx_tx_queue * tx_queue,struct sk_buff * skb)83d48523cbSMartin Habets static int efx_enqueue_skb_copy(struct efx_tx_queue *tx_queue,
84d48523cbSMartin Habets 				struct sk_buff *skb)
85d48523cbSMartin Habets {
86d48523cbSMartin Habets 	unsigned int copy_len = skb->len;
87d48523cbSMartin Habets 	struct efx_tx_buffer *buffer;
88d48523cbSMartin Habets 	u8 *copy_buffer;
89d48523cbSMartin Habets 	int rc;
90d48523cbSMartin Habets 
91d48523cbSMartin Habets 	EFX_WARN_ON_ONCE_PARANOID(copy_len > EFX_TX_CB_SIZE);
92d48523cbSMartin Habets 
93d48523cbSMartin Habets 	buffer = efx_tx_queue_get_insert_buffer(tx_queue);
94d48523cbSMartin Habets 
95d48523cbSMartin Habets 	copy_buffer = efx_tx_get_copy_buffer(tx_queue, buffer);
96d48523cbSMartin Habets 	if (unlikely(!copy_buffer))
97d48523cbSMartin Habets 		return -ENOMEM;
98d48523cbSMartin Habets 
99d48523cbSMartin Habets 	rc = skb_copy_bits(skb, 0, copy_buffer, copy_len);
100d48523cbSMartin Habets 	EFX_WARN_ON_PARANOID(rc);
101d48523cbSMartin Habets 	buffer->len = copy_len;
102d48523cbSMartin Habets 
103d48523cbSMartin Habets 	buffer->skb = skb;
104d48523cbSMartin Habets 	buffer->flags = EFX_TX_BUF_SKB;
105d48523cbSMartin Habets 
106d48523cbSMartin Habets 	++tx_queue->insert_count;
107d48523cbSMartin Habets 	return rc;
108d48523cbSMartin Habets }
109d48523cbSMartin Habets 
110d48523cbSMartin Habets /* Send any pending traffic for a channel. xmit_more is shared across all
111d48523cbSMartin Habets  * queues for a channel, so we must check all of them.
112d48523cbSMartin Habets  */
efx_tx_send_pending(struct efx_channel * channel)113d48523cbSMartin Habets static void efx_tx_send_pending(struct efx_channel *channel)
114d48523cbSMartin Habets {
115d48523cbSMartin Habets 	struct efx_tx_queue *q;
116d48523cbSMartin Habets 
117d48523cbSMartin Habets 	efx_for_each_channel_tx_queue(q, channel) {
118d48523cbSMartin Habets 		if (q->xmit_pending)
119d48523cbSMartin Habets 			efx_nic_push_buffers(q);
120d48523cbSMartin Habets 	}
121d48523cbSMartin Habets }
122d48523cbSMartin Habets 
123d48523cbSMartin Habets /*
124d48523cbSMartin Habets  * Add a socket buffer to a TX queue
125d48523cbSMartin Habets  *
126d48523cbSMartin Habets  * This maps all fragments of a socket buffer for DMA and adds them to
127d48523cbSMartin Habets  * the TX queue.  The queue's insert pointer will be incremented by
128d48523cbSMartin Habets  * the number of fragments in the socket buffer.
129d48523cbSMartin Habets  *
130d48523cbSMartin Habets  * If any DMA mapping fails, any mapped fragments will be unmapped,
131d48523cbSMartin Habets  * the queue's insert pointer will be restored to its original value.
132d48523cbSMartin Habets  *
13371ad88f6SMartin Habets  * This function is split out from efx_siena_hard_start_xmit to allow the
134d48523cbSMartin Habets  * loopback test to direct packets via specific TX queues.
135d48523cbSMartin Habets  *
136d48523cbSMartin Habets  * Returns NETDEV_TX_OK.
137d48523cbSMartin Habets  * You must hold netif_tx_lock() to call this function.
138d48523cbSMartin Habets  */
__efx_siena_enqueue_skb(struct efx_tx_queue * tx_queue,struct sk_buff * skb)13971ad88f6SMartin Habets netdev_tx_t __efx_siena_enqueue_skb(struct efx_tx_queue *tx_queue,
14071ad88f6SMartin Habets 				    struct sk_buff *skb)
141d48523cbSMartin Habets {
142d48523cbSMartin Habets 	unsigned int old_insert_count = tx_queue->insert_count;
143d48523cbSMartin Habets 	bool xmit_more = netdev_xmit_more();
144d48523cbSMartin Habets 	bool data_mapped = false;
145d48523cbSMartin Habets 	unsigned int segments;
146d48523cbSMartin Habets 	unsigned int skb_len;
147d48523cbSMartin Habets 	int rc;
148d48523cbSMartin Habets 
149d48523cbSMartin Habets 	skb_len = skb->len;
150d48523cbSMartin Habets 	segments = skb_is_gso(skb) ? skb_shinfo(skb)->gso_segs : 0;
151d48523cbSMartin Habets 	if (segments == 1)
152d48523cbSMartin Habets 		segments = 0; /* Don't use TSO for a single segment. */
153d48523cbSMartin Habets 
154d48523cbSMartin Habets 	/* Handle TSO first - it's *possible* (although unlikely) that we might
155d48523cbSMartin Habets 	 * be passed a packet to segment that's smaller than the copybreak/PIO
156d48523cbSMartin Habets 	 * size limit.
157d48523cbSMartin Habets 	 */
158d48523cbSMartin Habets 	if (segments) {
1597f9e4b2aSMartin Habets 		rc = efx_siena_tx_tso_fallback(tx_queue, skb);
160d48523cbSMartin Habets 		tx_queue->tso_fallbacks++;
161d48523cbSMartin Habets 		if (rc == 0)
162d48523cbSMartin Habets 			return 0;
163d48523cbSMartin Habets 		goto err;
164d48523cbSMartin Habets 	} else if (skb->data_len && skb_len <= EFX_TX_CB_SIZE) {
165d48523cbSMartin Habets 		/* Pad short packets or coalesce short fragmented packets. */
166d48523cbSMartin Habets 		if (efx_enqueue_skb_copy(tx_queue, skb))
167d48523cbSMartin Habets 			goto err;
168d48523cbSMartin Habets 		tx_queue->cb_packets++;
169d48523cbSMartin Habets 		data_mapped = true;
170d48523cbSMartin Habets 	}
171d48523cbSMartin Habets 
172d48523cbSMartin Habets 	/* Map for DMA and create descriptors if we haven't done so already. */
1737f9e4b2aSMartin Habets 	if (!data_mapped && (efx_siena_tx_map_data(tx_queue, skb, segments)))
174d48523cbSMartin Habets 		goto err;
175d48523cbSMartin Habets 
176d48523cbSMartin Habets 	efx_tx_maybe_stop_queue(tx_queue);
177d48523cbSMartin Habets 
178d48523cbSMartin Habets 	tx_queue->xmit_pending = true;
179d48523cbSMartin Habets 
180d48523cbSMartin Habets 	/* Pass off to hardware */
181d48523cbSMartin Habets 	if (__netdev_tx_sent_queue(tx_queue->core_txq, skb_len, xmit_more))
182d48523cbSMartin Habets 		efx_tx_send_pending(tx_queue->channel);
183d48523cbSMartin Habets 
184d48523cbSMartin Habets 	tx_queue->tx_packets++;
185d48523cbSMartin Habets 	return NETDEV_TX_OK;
186d48523cbSMartin Habets 
187d48523cbSMartin Habets 
188d48523cbSMartin Habets err:
1897f9e4b2aSMartin Habets 	efx_siena_enqueue_unwind(tx_queue, old_insert_count);
190d48523cbSMartin Habets 	dev_kfree_skb_any(skb);
191d48523cbSMartin Habets 
192d48523cbSMartin Habets 	/* If we're not expecting another transmit and we had something to push
193d48523cbSMartin Habets 	 * on this queue or a partner queue then we need to push here to get the
194d48523cbSMartin Habets 	 * previous packets out.
195d48523cbSMartin Habets 	 */
196d48523cbSMartin Habets 	if (!xmit_more)
197d48523cbSMartin Habets 		efx_tx_send_pending(tx_queue->channel);
198d48523cbSMartin Habets 
199d48523cbSMartin Habets 	return NETDEV_TX_OK;
200d48523cbSMartin Habets }
201d48523cbSMartin Habets 
202d48523cbSMartin Habets /* Transmit a packet from an XDP buffer
203d48523cbSMartin Habets  *
204d48523cbSMartin Habets  * Returns number of packets sent on success, error code otherwise.
205d48523cbSMartin Habets  * Runs in NAPI context, either in our poll (for XDP TX) or a different NIC
206d48523cbSMartin Habets  * (for XDP redirect).
207d48523cbSMartin Habets  */
efx_siena_xdp_tx_buffers(struct efx_nic * efx,int n,struct xdp_frame ** xdpfs,bool flush)20871ad88f6SMartin Habets int efx_siena_xdp_tx_buffers(struct efx_nic *efx, int n, struct xdp_frame **xdpfs,
209d48523cbSMartin Habets 			     bool flush)
210d48523cbSMartin Habets {
211d48523cbSMartin Habets 	struct efx_tx_buffer *tx_buffer;
212d48523cbSMartin Habets 	struct efx_tx_queue *tx_queue;
213d48523cbSMartin Habets 	struct xdp_frame *xdpf;
214d48523cbSMartin Habets 	dma_addr_t dma_addr;
215d48523cbSMartin Habets 	unsigned int len;
216d48523cbSMartin Habets 	int space;
217d48523cbSMartin Habets 	int cpu;
218d48523cbSMartin Habets 	int i = 0;
219d48523cbSMartin Habets 
220d48523cbSMartin Habets 	if (unlikely(n && !xdpfs))
221d48523cbSMartin Habets 		return -EINVAL;
222d48523cbSMartin Habets 	if (unlikely(!n))
223d48523cbSMartin Habets 		return 0;
224d48523cbSMartin Habets 
225d48523cbSMartin Habets 	cpu = raw_smp_processor_id();
226d48523cbSMartin Habets 	if (unlikely(cpu >= efx->xdp_tx_queue_count))
227d48523cbSMartin Habets 		return -EINVAL;
228d48523cbSMartin Habets 
229d48523cbSMartin Habets 	tx_queue = efx->xdp_tx_queues[cpu];
230d48523cbSMartin Habets 	if (unlikely(!tx_queue))
231d48523cbSMartin Habets 		return -EINVAL;
232d48523cbSMartin Habets 
233d48523cbSMartin Habets 	if (!tx_queue->initialised)
234d48523cbSMartin Habets 		return -EINVAL;
235d48523cbSMartin Habets 
236d48523cbSMartin Habets 	if (efx->xdp_txq_queues_mode != EFX_XDP_TX_QUEUES_DEDICATED)
237d48523cbSMartin Habets 		HARD_TX_LOCK(efx->net_dev, tx_queue->core_txq, cpu);
238d48523cbSMartin Habets 
239d48523cbSMartin Habets 	/* If we're borrowing net stack queues we have to handle stop-restart
240d48523cbSMartin Habets 	 * or we might block the queue and it will be considered as frozen
241d48523cbSMartin Habets 	 */
242d48523cbSMartin Habets 	if (efx->xdp_txq_queues_mode == EFX_XDP_TX_QUEUES_BORROWED) {
243d48523cbSMartin Habets 		if (netif_tx_queue_stopped(tx_queue->core_txq))
244d48523cbSMartin Habets 			goto unlock;
245d48523cbSMartin Habets 		efx_tx_maybe_stop_queue(tx_queue);
246d48523cbSMartin Habets 	}
247d48523cbSMartin Habets 
248d48523cbSMartin Habets 	/* Check for available space. We should never need multiple
249d48523cbSMartin Habets 	 * descriptors per frame.
250d48523cbSMartin Habets 	 */
251d48523cbSMartin Habets 	space = efx->txq_entries +
252d48523cbSMartin Habets 		tx_queue->read_count - tx_queue->insert_count;
253d48523cbSMartin Habets 
254d48523cbSMartin Habets 	for (i = 0; i < n; i++) {
255d48523cbSMartin Habets 		xdpf = xdpfs[i];
256d48523cbSMartin Habets 
257d48523cbSMartin Habets 		if (i >= space)
258d48523cbSMartin Habets 			break;
259d48523cbSMartin Habets 
260d48523cbSMartin Habets 		/* We'll want a descriptor for this tx. */
261d48523cbSMartin Habets 		prefetchw(__efx_tx_queue_get_insert_buffer(tx_queue));
262d48523cbSMartin Habets 
263d48523cbSMartin Habets 		len = xdpf->len;
264d48523cbSMartin Habets 
265d48523cbSMartin Habets 		/* Map for DMA. */
266d48523cbSMartin Habets 		dma_addr = dma_map_single(&efx->pci_dev->dev,
267d48523cbSMartin Habets 					  xdpf->data, len,
268d48523cbSMartin Habets 					  DMA_TO_DEVICE);
269d48523cbSMartin Habets 		if (dma_mapping_error(&efx->pci_dev->dev, dma_addr))
270d48523cbSMartin Habets 			break;
271d48523cbSMartin Habets 
272d48523cbSMartin Habets 		/*  Create descriptor and set up for unmapping DMA. */
2737f9e4b2aSMartin Habets 		tx_buffer = efx_siena_tx_map_chunk(tx_queue, dma_addr, len);
274d48523cbSMartin Habets 		tx_buffer->xdpf = xdpf;
275d48523cbSMartin Habets 		tx_buffer->flags = EFX_TX_BUF_XDP |
276d48523cbSMartin Habets 				   EFX_TX_BUF_MAP_SINGLE;
277d48523cbSMartin Habets 		tx_buffer->dma_offset = 0;
278d48523cbSMartin Habets 		tx_buffer->unmap_len = len;
279d48523cbSMartin Habets 		tx_queue->tx_packets++;
280d48523cbSMartin Habets 	}
281d48523cbSMartin Habets 
282d48523cbSMartin Habets 	/* Pass mapped frames to hardware. */
283d48523cbSMartin Habets 	if (flush && i > 0)
284d48523cbSMartin Habets 		efx_nic_push_buffers(tx_queue);
285d48523cbSMartin Habets 
286d48523cbSMartin Habets unlock:
287d48523cbSMartin Habets 	if (efx->xdp_txq_queues_mode != EFX_XDP_TX_QUEUES_DEDICATED)
288d48523cbSMartin Habets 		HARD_TX_UNLOCK(efx->net_dev, tx_queue->core_txq);
289d48523cbSMartin Habets 
290d48523cbSMartin Habets 	return i == 0 ? -EIO : i;
291d48523cbSMartin Habets }
292d48523cbSMartin Habets 
293d48523cbSMartin Habets /* Initiate a packet transmission.  We use one channel per CPU
294d48523cbSMartin Habets  * (sharing when we have more CPUs than channels).
295d48523cbSMartin Habets  *
296d48523cbSMartin Habets  * Context: non-blocking.
297d48523cbSMartin Habets  * Should always return NETDEV_TX_OK and consume the skb.
298d48523cbSMartin Habets  */
efx_siena_hard_start_xmit(struct sk_buff * skb,struct net_device * net_dev)29971ad88f6SMartin Habets netdev_tx_t efx_siena_hard_start_xmit(struct sk_buff *skb,
300d48523cbSMartin Habets 				      struct net_device *net_dev)
301d48523cbSMartin Habets {
302d48523cbSMartin Habets 	struct efx_nic *efx = netdev_priv(net_dev);
303d48523cbSMartin Habets 	struct efx_tx_queue *tx_queue;
304d48523cbSMartin Habets 	unsigned index, type;
305d48523cbSMartin Habets 
306d48523cbSMartin Habets 	EFX_WARN_ON_PARANOID(!netif_device_present(net_dev));
307d48523cbSMartin Habets 
308d48523cbSMartin Habets 	index = skb_get_queue_mapping(skb);
309d48523cbSMartin Habets 	type = efx_tx_csum_type_skb(skb);
310d48523cbSMartin Habets 	if (index >= efx->n_tx_channels) {
311d48523cbSMartin Habets 		index -= efx->n_tx_channels;
312d48523cbSMartin Habets 		type |= EFX_TXQ_TYPE_HIGHPRI;
313d48523cbSMartin Habets 	}
314d48523cbSMartin Habets 
315d48523cbSMartin Habets 	/* PTP "event" packet */
316d48523cbSMartin Habets 	if (unlikely(efx_xmit_with_hwtstamp(skb)) &&
31795e96f77SMartin Habets 	    ((efx_siena_ptp_use_mac_tx_timestamps(efx) && efx->ptp_data) ||
31895e96f77SMartin Habets 	     unlikely(efx_siena_ptp_is_ptp_tx(efx, skb)))) {
319d48523cbSMartin Habets 		/* There may be existing transmits on the channel that are
320d48523cbSMartin Habets 		 * waiting for this packet to trigger the doorbell write.
321d48523cbSMartin Habets 		 * We need to send the packets at this point.
322d48523cbSMartin Habets 		 */
323d48523cbSMartin Habets 		efx_tx_send_pending(efx_get_tx_channel(efx, index));
32495e96f77SMartin Habets 		return efx_siena_ptp_tx(efx, skb);
325d48523cbSMartin Habets 	}
326d48523cbSMartin Habets 
327d48523cbSMartin Habets 	tx_queue = efx_get_tx_queue(efx, index, type);
328d48523cbSMartin Habets 	if (WARN_ON_ONCE(!tx_queue)) {
329d48523cbSMartin Habets 		/* We don't have a TXQ of the right type.
330d48523cbSMartin Habets 		 * This should never happen, as we don't advertise offload
331d48523cbSMartin Habets 		 * features unless we can support them.
332d48523cbSMartin Habets 		 */
333d48523cbSMartin Habets 		dev_kfree_skb_any(skb);
334d48523cbSMartin Habets 		/* If we're not expecting another transmit and we had something to push
335d48523cbSMartin Habets 		 * on this queue or a partner queue then we need to push here to get the
336d48523cbSMartin Habets 		 * previous packets out.
337d48523cbSMartin Habets 		 */
338d48523cbSMartin Habets 		if (!netdev_xmit_more())
339*589c6edeSÍñigo Huguet 			efx_tx_send_pending(efx_get_tx_channel(efx, index));
340d48523cbSMartin Habets 		return NETDEV_TX_OK;
341d48523cbSMartin Habets 	}
342d48523cbSMartin Habets 
34371ad88f6SMartin Habets 	return __efx_siena_enqueue_skb(tx_queue, skb);
344d48523cbSMartin Habets }
345d48523cbSMartin Habets 
efx_siena_init_tx_queue_core_txq(struct efx_tx_queue * tx_queue)34671ad88f6SMartin Habets void efx_siena_init_tx_queue_core_txq(struct efx_tx_queue *tx_queue)
347d48523cbSMartin Habets {
348d48523cbSMartin Habets 	struct efx_nic *efx = tx_queue->efx;
349d48523cbSMartin Habets 
35071ad88f6SMartin Habets 	/* Must be inverse of queue lookup in efx_siena_hard_start_xmit() */
351d48523cbSMartin Habets 	tx_queue->core_txq =
352d48523cbSMartin Habets 		netdev_get_tx_queue(efx->net_dev,
353d48523cbSMartin Habets 				    tx_queue->channel->channel +
354d48523cbSMartin Habets 				    ((tx_queue->type & EFX_TXQ_TYPE_HIGHPRI) ?
355d48523cbSMartin Habets 				     efx->n_tx_channels : 0));
356d48523cbSMartin Habets }
357d48523cbSMartin Habets 
efx_siena_setup_tc(struct net_device * net_dev,enum tc_setup_type type,void * type_data)35871ad88f6SMartin Habets int efx_siena_setup_tc(struct net_device *net_dev, enum tc_setup_type type,
359d48523cbSMartin Habets 		       void *type_data)
360d48523cbSMartin Habets {
361d48523cbSMartin Habets 	struct efx_nic *efx = netdev_priv(net_dev);
362d48523cbSMartin Habets 	struct tc_mqprio_qopt *mqprio = type_data;
363d48523cbSMartin Habets 	unsigned tc, num_tc;
364d48523cbSMartin Habets 
365d48523cbSMartin Habets 	if (type != TC_SETUP_QDISC_MQPRIO)
366d48523cbSMartin Habets 		return -EOPNOTSUPP;
367d48523cbSMartin Habets 
368d48523cbSMartin Habets 	/* Only Siena supported highpri queues */
369d48523cbSMartin Habets 	if (efx_nic_rev(efx) > EFX_REV_SIENA_A0)
370d48523cbSMartin Habets 		return -EOPNOTSUPP;
371d48523cbSMartin Habets 
372d48523cbSMartin Habets 	num_tc = mqprio->num_tc;
373d48523cbSMartin Habets 
374d48523cbSMartin Habets 	if (num_tc > EFX_MAX_TX_TC)
375d48523cbSMartin Habets 		return -EINVAL;
376d48523cbSMartin Habets 
377d48523cbSMartin Habets 	mqprio->hw = TC_MQPRIO_HW_OFFLOAD_TCS;
378d48523cbSMartin Habets 
379d48523cbSMartin Habets 	if (num_tc == net_dev->num_tc)
380d48523cbSMartin Habets 		return 0;
381d48523cbSMartin Habets 
382d48523cbSMartin Habets 	for (tc = 0; tc < num_tc; tc++) {
383d48523cbSMartin Habets 		net_dev->tc_to_txq[tc].offset = tc * efx->n_tx_channels;
384d48523cbSMartin Habets 		net_dev->tc_to_txq[tc].count = efx->n_tx_channels;
385d48523cbSMartin Habets 	}
386d48523cbSMartin Habets 
387d48523cbSMartin Habets 	net_dev->num_tc = num_tc;
388d48523cbSMartin Habets 
389d48523cbSMartin Habets 	return netif_set_real_num_tx_queues(net_dev,
390d48523cbSMartin Habets 					    max_t(int, num_tc, 1) *
391d48523cbSMartin Habets 					    efx->n_tx_channels);
392d48523cbSMartin Habets }
393