tx.c 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645
  1. // SPDX-License-Identifier: GPL-2.0-only
  2. /****************************************************************************
  3. * Driver for Solarflare network controllers and boards
  4. * Copyright 2005-2006 Fen Systems Ltd.
  5. * Copyright 2005-2013 Solarflare Communications Inc.
  6. */
  7. #include <linux/pci.h>
  8. #include <linux/tcp.h>
  9. #include <linux/ip.h>
  10. #include <linux/in.h>
  11. #include <linux/ipv6.h>
  12. #include <linux/slab.h>
  13. #include <net/ipv6.h>
  14. #include <linux/if_ether.h>
  15. #include <linux/highmem.h>
  16. #include <linux/cache.h>
  17. #include "net_driver.h"
  18. #include "efx.h"
  19. #include "io.h"
  20. #include "nic.h"
  21. #include "tx.h"
  22. #include "tx_common.h"
  23. #include "workarounds.h"
  24. #include "ef10_regs.h"
  25. #ifdef EFX_USE_PIO
  26. #define EFX_PIOBUF_SIZE_DEF ALIGN(256, L1_CACHE_BYTES)
  27. unsigned int efx_piobuf_size __read_mostly = EFX_PIOBUF_SIZE_DEF;
  28. #endif /* EFX_USE_PIO */
  29. static inline u8 *efx_tx_get_copy_buffer(struct efx_tx_queue *tx_queue,
  30. struct efx_tx_buffer *buffer)
  31. {
  32. unsigned int index = efx_tx_queue_get_insert_index(tx_queue);
  33. struct efx_buffer *page_buf =
  34. &tx_queue->cb_page[index >> (PAGE_SHIFT - EFX_TX_CB_ORDER)];
  35. unsigned int offset =
  36. ((index << EFX_TX_CB_ORDER) + NET_IP_ALIGN) & (PAGE_SIZE - 1);
  37. if (unlikely(!page_buf->addr) &&
  38. efx_nic_alloc_buffer(tx_queue->efx, page_buf, PAGE_SIZE,
  39. GFP_ATOMIC))
  40. return NULL;
  41. buffer->dma_addr = page_buf->dma_addr + offset;
  42. buffer->unmap_len = 0;
  43. return (u8 *)page_buf->addr + offset;
  44. }
  45. u8 *efx_tx_get_copy_buffer_limited(struct efx_tx_queue *tx_queue,
  46. struct efx_tx_buffer *buffer, size_t len)
  47. {
  48. if (len > EFX_TX_CB_SIZE)
  49. return NULL;
  50. return efx_tx_get_copy_buffer(tx_queue, buffer);
  51. }
  52. static void efx_tx_maybe_stop_queue(struct efx_tx_queue *txq1)
  53. {
  54. /* We need to consider all queues that the net core sees as one */
  55. struct efx_nic *efx = txq1->efx;
  56. struct efx_tx_queue *txq2;
  57. unsigned int fill_level;
  58. fill_level = efx_channel_tx_old_fill_level(txq1->channel);
  59. if (likely(fill_level < efx->txq_stop_thresh))
  60. return;
  61. /* We used the stale old_read_count above, which gives us a
  62. * pessimistic estimate of the fill level (which may even
  63. * validly be >= efx->txq_entries). Now try again using
  64. * read_count (more likely to be a cache miss).
  65. *
  66. * If we read read_count and then conditionally stop the
  67. * queue, it is possible for the completion path to race with
  68. * us and complete all outstanding descriptors in the middle,
  69. * after which there will be no more completions to wake it.
  70. * Therefore we stop the queue first, then read read_count
  71. * (with a memory barrier to ensure the ordering), then
  72. * restart the queue if the fill level turns out to be low
  73. * enough.
  74. */
  75. netif_tx_stop_queue(txq1->core_txq);
  76. smp_mb();
  77. efx_for_each_channel_tx_queue(txq2, txq1->channel)
  78. txq2->old_read_count = READ_ONCE(txq2->read_count);
  79. fill_level = efx_channel_tx_old_fill_level(txq1->channel);
  80. EFX_WARN_ON_ONCE_PARANOID(fill_level >= efx->txq_entries);
  81. if (likely(fill_level < efx->txq_stop_thresh)) {
  82. smp_mb();
  83. if (likely(!efx->loopback_selftest))
  84. netif_tx_start_queue(txq1->core_txq);
  85. }
  86. }
  87. static int efx_enqueue_skb_copy(struct efx_tx_queue *tx_queue,
  88. struct sk_buff *skb)
  89. {
  90. unsigned int copy_len = skb->len;
  91. struct efx_tx_buffer *buffer;
  92. u8 *copy_buffer;
  93. int rc;
  94. EFX_WARN_ON_ONCE_PARANOID(copy_len > EFX_TX_CB_SIZE);
  95. buffer = efx_tx_queue_get_insert_buffer(tx_queue);
  96. copy_buffer = efx_tx_get_copy_buffer(tx_queue, buffer);
  97. if (unlikely(!copy_buffer))
  98. return -ENOMEM;
  99. rc = skb_copy_bits(skb, 0, copy_buffer, copy_len);
  100. EFX_WARN_ON_PARANOID(rc);
  101. buffer->len = copy_len;
  102. buffer->skb = skb;
  103. buffer->flags = EFX_TX_BUF_SKB;
  104. ++tx_queue->insert_count;
  105. return rc;
  106. }
  107. #ifdef EFX_USE_PIO
  108. struct efx_short_copy_buffer {
  109. int used;
  110. u8 buf[L1_CACHE_BYTES];
  111. };
  112. /* Copy to PIO, respecting that writes to PIO buffers must be dword aligned.
  113. * Advances piobuf pointer. Leaves additional data in the copy buffer.
  114. */
  115. static void efx_memcpy_toio_aligned(struct efx_nic *efx, u8 __iomem **piobuf,
  116. u8 *data, int len,
  117. struct efx_short_copy_buffer *copy_buf)
  118. {
  119. int block_len = len & ~(sizeof(copy_buf->buf) - 1);
  120. __iowrite64_copy(*piobuf, data, block_len >> 3);
  121. *piobuf += block_len;
  122. len -= block_len;
  123. if (len) {
  124. data += block_len;
  125. BUG_ON(copy_buf->used);
  126. BUG_ON(len > sizeof(copy_buf->buf));
  127. memcpy(copy_buf->buf, data, len);
  128. copy_buf->used = len;
  129. }
  130. }
  131. /* Copy to PIO, respecting dword alignment, popping data from copy buffer first.
  132. * Advances piobuf pointer. Leaves additional data in the copy buffer.
  133. */
  134. static void efx_memcpy_toio_aligned_cb(struct efx_nic *efx, u8 __iomem **piobuf,
  135. u8 *data, int len,
  136. struct efx_short_copy_buffer *copy_buf)
  137. {
  138. if (copy_buf->used) {
  139. /* if the copy buffer is partially full, fill it up and write */
  140. int copy_to_buf =
  141. min_t(int, sizeof(copy_buf->buf) - copy_buf->used, len);
  142. memcpy(copy_buf->buf + copy_buf->used, data, copy_to_buf);
  143. copy_buf->used += copy_to_buf;
  144. /* if we didn't fill it up then we're done for now */
  145. if (copy_buf->used < sizeof(copy_buf->buf))
  146. return;
  147. __iowrite64_copy(*piobuf, copy_buf->buf,
  148. sizeof(copy_buf->buf) >> 3);
  149. *piobuf += sizeof(copy_buf->buf);
  150. data += copy_to_buf;
  151. len -= copy_to_buf;
  152. copy_buf->used = 0;
  153. }
  154. efx_memcpy_toio_aligned(efx, piobuf, data, len, copy_buf);
  155. }
  156. static void efx_flush_copy_buffer(struct efx_nic *efx, u8 __iomem *piobuf,
  157. struct efx_short_copy_buffer *copy_buf)
  158. {
  159. /* if there's anything in it, write the whole buffer, including junk */
  160. if (copy_buf->used)
  161. __iowrite64_copy(piobuf, copy_buf->buf,
  162. sizeof(copy_buf->buf) >> 3);
  163. }
  164. /* Traverse skb structure and copy fragments in to PIO buffer.
  165. * Advances piobuf pointer.
  166. */
  167. static void efx_skb_copy_bits_to_pio(struct efx_nic *efx, struct sk_buff *skb,
  168. u8 __iomem **piobuf,
  169. struct efx_short_copy_buffer *copy_buf)
  170. {
  171. int i;
  172. efx_memcpy_toio_aligned(efx, piobuf, skb->data, skb_headlen(skb),
  173. copy_buf);
  174. for (i = 0; i < skb_shinfo(skb)->nr_frags; ++i) {
  175. skb_frag_t *f = &skb_shinfo(skb)->frags[i];
  176. u8 *vaddr;
  177. vaddr = kmap_atomic(skb_frag_page(f));
  178. efx_memcpy_toio_aligned_cb(efx, piobuf, vaddr + skb_frag_off(f),
  179. skb_frag_size(f), copy_buf);
  180. kunmap_atomic(vaddr);
  181. }
  182. EFX_WARN_ON_ONCE_PARANOID(skb_shinfo(skb)->frag_list);
  183. }
  184. static int efx_enqueue_skb_pio(struct efx_tx_queue *tx_queue,
  185. struct sk_buff *skb)
  186. {
  187. struct efx_tx_buffer *buffer =
  188. efx_tx_queue_get_insert_buffer(tx_queue);
  189. u8 __iomem *piobuf = tx_queue->piobuf;
  190. /* Copy to PIO buffer. Ensure the writes are padded to the end
  191. * of a cache line, as this is required for write-combining to be
  192. * effective on at least x86.
  193. */
  194. if (skb_shinfo(skb)->nr_frags) {
  195. /* The size of the copy buffer will ensure all writes
  196. * are the size of a cache line.
  197. */
  198. struct efx_short_copy_buffer copy_buf;
  199. copy_buf.used = 0;
  200. efx_skb_copy_bits_to_pio(tx_queue->efx, skb,
  201. &piobuf, &copy_buf);
  202. efx_flush_copy_buffer(tx_queue->efx, piobuf, &copy_buf);
  203. } else {
  204. /* Pad the write to the size of a cache line.
  205. * We can do this because we know the skb_shared_info struct is
  206. * after the source, and the destination buffer is big enough.
  207. */
  208. BUILD_BUG_ON(L1_CACHE_BYTES >
  209. SKB_DATA_ALIGN(sizeof(struct skb_shared_info)));
  210. __iowrite64_copy(tx_queue->piobuf, skb->data,
  211. ALIGN(skb->len, L1_CACHE_BYTES) >> 3);
  212. }
  213. buffer->skb = skb;
  214. buffer->flags = EFX_TX_BUF_SKB | EFX_TX_BUF_OPTION;
  215. EFX_POPULATE_QWORD_5(buffer->option,
  216. ESF_DZ_TX_DESC_IS_OPT, 1,
  217. ESF_DZ_TX_OPTION_TYPE, ESE_DZ_TX_OPTION_DESC_PIO,
  218. ESF_DZ_TX_PIO_CONT, 0,
  219. ESF_DZ_TX_PIO_BYTE_CNT, skb->len,
  220. ESF_DZ_TX_PIO_BUF_ADDR,
  221. tx_queue->piobuf_offset);
  222. ++tx_queue->insert_count;
  223. return 0;
  224. }
  225. /* Decide whether we can use TX PIO, ie. write packet data directly into
  226. * a buffer on the device. This can reduce latency at the expense of
  227. * throughput, so we only do this if both hardware and software TX rings
  228. * are empty, including all queues for the channel. This also ensures that
  229. * only one packet at a time can be using the PIO buffer. If the xmit_more
  230. * flag is set then we don't use this - there'll be another packet along
  231. * shortly and we want to hold off the doorbell.
  232. */
  233. static bool efx_tx_may_pio(struct efx_tx_queue *tx_queue)
  234. {
  235. struct efx_channel *channel = tx_queue->channel;
  236. if (!tx_queue->piobuf)
  237. return false;
  238. EFX_WARN_ON_ONCE_PARANOID(!channel->efx->type->option_descriptors);
  239. efx_for_each_channel_tx_queue(tx_queue, channel)
  240. if (!efx_nic_tx_is_empty(tx_queue, tx_queue->packet_write_count))
  241. return false;
  242. return true;
  243. }
  244. #endif /* EFX_USE_PIO */
  245. /* Send any pending traffic for a channel. xmit_more is shared across all
  246. * queues for a channel, so we must check all of them.
  247. */
  248. static void efx_tx_send_pending(struct efx_channel *channel)
  249. {
  250. struct efx_tx_queue *q;
  251. efx_for_each_channel_tx_queue(q, channel) {
  252. if (q->xmit_pending)
  253. efx_nic_push_buffers(q);
  254. }
  255. }
  256. /*
  257. * Add a socket buffer to a TX queue
  258. *
  259. * This maps all fragments of a socket buffer for DMA and adds them to
  260. * the TX queue. The queue's insert pointer will be incremented by
  261. * the number of fragments in the socket buffer.
  262. *
  263. * If any DMA mapping fails, any mapped fragments will be unmapped,
  264. * the queue's insert pointer will be restored to its original value.
  265. *
  266. * This function is split out from efx_hard_start_xmit to allow the
  267. * loopback test to direct packets via specific TX queues.
  268. *
  269. * Returns NETDEV_TX_OK.
  270. * You must hold netif_tx_lock() to call this function.
  271. */
  272. netdev_tx_t __efx_enqueue_skb(struct efx_tx_queue *tx_queue, struct sk_buff *skb)
  273. {
  274. unsigned int old_insert_count = tx_queue->insert_count;
  275. bool xmit_more = netdev_xmit_more();
  276. bool data_mapped = false;
  277. unsigned int segments;
  278. unsigned int skb_len;
  279. int rc;
  280. skb_len = skb->len;
  281. segments = skb_is_gso(skb) ? skb_shinfo(skb)->gso_segs : 0;
  282. if (segments == 1)
  283. segments = 0; /* Don't use TSO for a single segment. */
  284. /* Handle TSO first - it's *possible* (although unlikely) that we might
  285. * be passed a packet to segment that's smaller than the copybreak/PIO
  286. * size limit.
  287. */
  288. if (segments) {
  289. switch (tx_queue->tso_version) {
  290. case 1:
  291. rc = efx_enqueue_skb_tso(tx_queue, skb, &data_mapped);
  292. break;
  293. case 2:
  294. rc = efx_ef10_tx_tso_desc(tx_queue, skb, &data_mapped);
  295. break;
  296. case 0: /* No TSO on this queue, SW fallback needed */
  297. default:
  298. rc = -EINVAL;
  299. break;
  300. }
  301. if (rc == -EINVAL) {
  302. rc = efx_tx_tso_fallback(tx_queue, skb);
  303. tx_queue->tso_fallbacks++;
  304. if (rc == 0)
  305. return 0;
  306. }
  307. if (rc)
  308. goto err;
  309. #ifdef EFX_USE_PIO
  310. } else if (skb_len <= efx_piobuf_size && !xmit_more &&
  311. efx_tx_may_pio(tx_queue)) {
  312. /* Use PIO for short packets with an empty queue. */
  313. if (efx_enqueue_skb_pio(tx_queue, skb))
  314. goto err;
  315. tx_queue->pio_packets++;
  316. data_mapped = true;
  317. #endif
  318. } else if (skb->data_len && skb_len <= EFX_TX_CB_SIZE) {
  319. /* Pad short packets or coalesce short fragmented packets. */
  320. if (efx_enqueue_skb_copy(tx_queue, skb))
  321. goto err;
  322. tx_queue->cb_packets++;
  323. data_mapped = true;
  324. }
  325. /* Map for DMA and create descriptors if we haven't done so already. */
  326. if (!data_mapped && (efx_tx_map_data(tx_queue, skb, segments)))
  327. goto err;
  328. efx_tx_maybe_stop_queue(tx_queue);
  329. tx_queue->xmit_pending = true;
  330. /* Pass off to hardware */
  331. if (__netdev_tx_sent_queue(tx_queue->core_txq, skb_len, xmit_more))
  332. efx_tx_send_pending(tx_queue->channel);
  333. if (segments) {
  334. tx_queue->tso_bursts++;
  335. tx_queue->tso_packets += segments;
  336. tx_queue->tx_packets += segments;
  337. } else {
  338. tx_queue->tx_packets++;
  339. }
  340. return NETDEV_TX_OK;
  341. err:
  342. efx_enqueue_unwind(tx_queue, old_insert_count);
  343. dev_kfree_skb_any(skb);
  344. /* If we're not expecting another transmit and we had something to push
  345. * on this queue or a partner queue then we need to push here to get the
  346. * previous packets out.
  347. */
  348. if (!xmit_more)
  349. efx_tx_send_pending(tx_queue->channel);
  350. return NETDEV_TX_OK;
  351. }
  352. /* Transmit a packet from an XDP buffer
  353. *
  354. * Returns number of packets sent on success, error code otherwise.
  355. * Runs in NAPI context, either in our poll (for XDP TX) or a different NIC
  356. * (for XDP redirect).
  357. */
  358. int efx_xdp_tx_buffers(struct efx_nic *efx, int n, struct xdp_frame **xdpfs,
  359. bool flush)
  360. {
  361. struct efx_tx_buffer *tx_buffer;
  362. struct efx_tx_queue *tx_queue;
  363. struct xdp_frame *xdpf;
  364. dma_addr_t dma_addr;
  365. unsigned int len;
  366. int space;
  367. int cpu;
  368. int i = 0;
  369. if (unlikely(n && !xdpfs))
  370. return -EINVAL;
  371. if (unlikely(!n))
  372. return 0;
  373. cpu = raw_smp_processor_id();
  374. if (unlikely(cpu >= efx->xdp_tx_queue_count))
  375. return -EINVAL;
  376. tx_queue = efx->xdp_tx_queues[cpu];
  377. if (unlikely(!tx_queue))
  378. return -EINVAL;
  379. if (!tx_queue->initialised)
  380. return -EINVAL;
  381. if (efx->xdp_txq_queues_mode != EFX_XDP_TX_QUEUES_DEDICATED)
  382. HARD_TX_LOCK(efx->net_dev, tx_queue->core_txq, cpu);
  383. /* If we're borrowing net stack queues we have to handle stop-restart
  384. * or we might block the queue and it will be considered as frozen
  385. */
  386. if (efx->xdp_txq_queues_mode == EFX_XDP_TX_QUEUES_BORROWED) {
  387. if (netif_tx_queue_stopped(tx_queue->core_txq))
  388. goto unlock;
  389. efx_tx_maybe_stop_queue(tx_queue);
  390. }
  391. /* Check for available space. We should never need multiple
  392. * descriptors per frame.
  393. */
  394. space = efx->txq_entries +
  395. tx_queue->read_count - tx_queue->insert_count;
  396. for (i = 0; i < n; i++) {
  397. xdpf = xdpfs[i];
  398. if (i >= space)
  399. break;
  400. /* We'll want a descriptor for this tx. */
  401. prefetchw(__efx_tx_queue_get_insert_buffer(tx_queue));
  402. len = xdpf->len;
  403. /* Map for DMA. */
  404. dma_addr = dma_map_single(&efx->pci_dev->dev,
  405. xdpf->data, len,
  406. DMA_TO_DEVICE);
  407. if (dma_mapping_error(&efx->pci_dev->dev, dma_addr))
  408. break;
  409. /* Create descriptor and set up for unmapping DMA. */
  410. tx_buffer = efx_tx_map_chunk(tx_queue, dma_addr, len);
  411. tx_buffer->xdpf = xdpf;
  412. tx_buffer->flags = EFX_TX_BUF_XDP |
  413. EFX_TX_BUF_MAP_SINGLE;
  414. tx_buffer->dma_offset = 0;
  415. tx_buffer->unmap_len = len;
  416. tx_queue->tx_packets++;
  417. }
  418. /* Pass mapped frames to hardware. */
  419. if (flush && i > 0)
  420. efx_nic_push_buffers(tx_queue);
  421. unlock:
  422. if (efx->xdp_txq_queues_mode != EFX_XDP_TX_QUEUES_DEDICATED)
  423. HARD_TX_UNLOCK(efx->net_dev, tx_queue->core_txq);
  424. return i == 0 ? -EIO : i;
  425. }
  426. /* Initiate a packet transmission. We use one channel per CPU
  427. * (sharing when we have more CPUs than channels).
  428. *
  429. * Context: non-blocking.
  430. * Should always return NETDEV_TX_OK and consume the skb.
  431. */
  432. netdev_tx_t efx_hard_start_xmit(struct sk_buff *skb,
  433. struct net_device *net_dev)
  434. {
  435. struct efx_nic *efx = efx_netdev_priv(net_dev);
  436. struct efx_tx_queue *tx_queue;
  437. unsigned index, type;
  438. EFX_WARN_ON_PARANOID(!netif_device_present(net_dev));
  439. index = skb_get_queue_mapping(skb);
  440. type = efx_tx_csum_type_skb(skb);
  441. if (index >= efx->n_tx_channels) {
  442. index -= efx->n_tx_channels;
  443. type |= EFX_TXQ_TYPE_HIGHPRI;
  444. }
  445. /* PTP "event" packet */
  446. if (unlikely(efx_xmit_with_hwtstamp(skb)) &&
  447. ((efx_ptp_use_mac_tx_timestamps(efx) && efx->ptp_data) ||
  448. unlikely(efx_ptp_is_ptp_tx(efx, skb)))) {
  449. /* There may be existing transmits on the channel that are
  450. * waiting for this packet to trigger the doorbell write.
  451. * We need to send the packets at this point.
  452. */
  453. efx_tx_send_pending(efx_get_tx_channel(efx, index));
  454. return efx_ptp_tx(efx, skb);
  455. }
  456. tx_queue = efx_get_tx_queue(efx, index, type);
  457. if (WARN_ON_ONCE(!tx_queue)) {
  458. /* We don't have a TXQ of the right type.
  459. * This should never happen, as we don't advertise offload
  460. * features unless we can support them.
  461. */
  462. dev_kfree_skb_any(skb);
  463. /* If we're not expecting another transmit and we had something to push
  464. * on this queue or a partner queue then we need to push here to get the
  465. * previous packets out.
  466. */
  467. if (!netdev_xmit_more())
  468. efx_tx_send_pending(efx_get_tx_channel(efx, index));
  469. return NETDEV_TX_OK;
  470. }
  471. return __efx_enqueue_skb(tx_queue, skb);
  472. }
  473. void efx_xmit_done_single(struct efx_tx_queue *tx_queue)
  474. {
  475. unsigned int pkts_compl = 0, bytes_compl = 0;
  476. unsigned int efv_pkts_compl = 0;
  477. unsigned int read_ptr;
  478. bool finished = false;
  479. read_ptr = tx_queue->read_count & tx_queue->ptr_mask;
  480. while (!finished) {
  481. struct efx_tx_buffer *buffer = &tx_queue->buffer[read_ptr];
  482. if (!efx_tx_buffer_in_use(buffer)) {
  483. struct efx_nic *efx = tx_queue->efx;
  484. netif_err(efx, hw, efx->net_dev,
  485. "TX queue %d spurious single TX completion\n",
  486. tx_queue->queue);
  487. efx_schedule_reset(efx, RESET_TYPE_TX_SKIP);
  488. return;
  489. }
  490. /* Need to check the flag before dequeueing. */
  491. if (buffer->flags & EFX_TX_BUF_SKB)
  492. finished = true;
  493. efx_dequeue_buffer(tx_queue, buffer, &pkts_compl, &bytes_compl,
  494. &efv_pkts_compl);
  495. ++tx_queue->read_count;
  496. read_ptr = tx_queue->read_count & tx_queue->ptr_mask;
  497. }
  498. tx_queue->pkts_compl += pkts_compl;
  499. tx_queue->bytes_compl += bytes_compl;
  500. EFX_WARN_ON_PARANOID(pkts_compl + efv_pkts_compl != 1);
  501. efx_xmit_done_check_empty(tx_queue);
  502. }
  503. void efx_init_tx_queue_core_txq(struct efx_tx_queue *tx_queue)
  504. {
  505. struct efx_nic *efx = tx_queue->efx;
  506. /* Must be inverse of queue lookup in efx_hard_start_xmit() */
  507. tx_queue->core_txq =
  508. netdev_get_tx_queue(efx->net_dev,
  509. tx_queue->channel->channel +
  510. ((tx_queue->type & EFX_TXQ_TYPE_HIGHPRI) ?
  511. efx->n_tx_channels : 0));
  512. }
  513. int efx_setup_tc(struct net_device *net_dev, enum tc_setup_type type,
  514. void *type_data)
  515. {
  516. struct efx_nic *efx = efx_netdev_priv(net_dev);
  517. struct tc_mqprio_qopt *mqprio = type_data;
  518. unsigned tc, num_tc;
  519. if (type != TC_SETUP_QDISC_MQPRIO)
  520. return -EOPNOTSUPP;
  521. /* Only Siena supported highpri queues */
  522. if (efx_nic_rev(efx) > EFX_REV_SIENA_A0)
  523. return -EOPNOTSUPP;
  524. num_tc = mqprio->num_tc;
  525. if (num_tc > EFX_MAX_TX_TC)
  526. return -EINVAL;
  527. mqprio->hw = TC_MQPRIO_HW_OFFLOAD_TCS;
  528. if (num_tc == net_dev->num_tc)
  529. return 0;
  530. for (tc = 0; tc < num_tc; tc++) {
  531. net_dev->tc_to_txq[tc].offset = tc * efx->n_tx_channels;
  532. net_dev->tc_to_txq[tc].count = efx->n_tx_channels;
  533. }
  534. net_dev->num_tc = num_tc;
  535. return netif_set_real_num_tx_queues(net_dev,
  536. max_t(int, num_tc, 1) *
  537. efx->n_tx_channels);
  538. }