tx.c 33 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210
  1. /****************************************************************************
  2. * Driver for Solarflare Solarstorm network controllers and boards
  3. * Copyright 2005-2006 Fen Systems Ltd.
  4. * Copyright 2005-2010 Solarflare Communications Inc.
  5. *
  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. #include <linux/pci.h>
  11. #include <linux/tcp.h>
  12. #include <linux/ip.h>
  13. #include <linux/in.h>
  14. #include <linux/ipv6.h>
  15. #include <linux/slab.h>
  16. #include <net/ipv6.h>
  17. #include <linux/if_ether.h>
  18. #include <linux/highmem.h>
  19. #include "net_driver.h"
  20. #include "efx.h"
  21. #include "nic.h"
  22. #include "workarounds.h"
  23. /*
  24. * TX descriptor ring full threshold
  25. *
  26. * The tx_queue descriptor ring fill-level must fall below this value
  27. * before we restart the netif queue
  28. */
  29. #define EFX_TXQ_THRESHOLD(_efx) ((_efx)->txq_entries / 2u)
  30. static void efx_dequeue_buffer(struct efx_tx_queue *tx_queue,
  31. struct efx_tx_buffer *buffer)
  32. {
  33. if (buffer->unmap_len) {
  34. struct pci_dev *pci_dev = tx_queue->efx->pci_dev;
  35. dma_addr_t unmap_addr = (buffer->dma_addr + buffer->len -
  36. buffer->unmap_len);
  37. if (buffer->unmap_single)
  38. pci_unmap_single(pci_dev, unmap_addr, buffer->unmap_len,
  39. PCI_DMA_TODEVICE);
  40. else
  41. pci_unmap_page(pci_dev, unmap_addr, buffer->unmap_len,
  42. PCI_DMA_TODEVICE);
  43. buffer->unmap_len = 0;
  44. buffer->unmap_single = false;
  45. }
  46. if (buffer->skb) {
  47. dev_kfree_skb_any((struct sk_buff *) buffer->skb);
  48. buffer->skb = NULL;
  49. netif_vdbg(tx_queue->efx, tx_done, tx_queue->efx->net_dev,
  50. "TX queue %d transmission id %x complete\n",
  51. tx_queue->queue, tx_queue->read_count);
  52. }
  53. }
  54. /**
  55. * struct efx_tso_header - a DMA mapped buffer for packet headers
  56. * @next: Linked list of free ones.
  57. * The list is protected by the TX queue lock.
  58. * @dma_unmap_len: Length to unmap for an oversize buffer, or 0.
  59. * @dma_addr: The DMA address of the header below.
  60. *
  61. * This controls the memory used for a TSO header. Use TSOH_DATA()
  62. * to find the packet header data. Use TSOH_SIZE() to calculate the
  63. * total size required for a given packet header length. TSO headers
  64. * in the free list are exactly %TSOH_STD_SIZE bytes in size.
  65. */
  66. struct efx_tso_header {
  67. union {
  68. struct efx_tso_header *next;
  69. size_t unmap_len;
  70. };
  71. dma_addr_t dma_addr;
  72. };
  73. static int efx_enqueue_skb_tso(struct efx_tx_queue *tx_queue,
  74. struct sk_buff *skb);
  75. static void efx_fini_tso(struct efx_tx_queue *tx_queue);
  76. static void efx_tsoh_heap_free(struct efx_tx_queue *tx_queue,
  77. struct efx_tso_header *tsoh);
  78. static void efx_tsoh_free(struct efx_tx_queue *tx_queue,
  79. struct efx_tx_buffer *buffer)
  80. {
  81. if (buffer->tsoh) {
  82. if (likely(!buffer->tsoh->unmap_len)) {
  83. buffer->tsoh->next = tx_queue->tso_headers_free;
  84. tx_queue->tso_headers_free = buffer->tsoh;
  85. } else {
  86. efx_tsoh_heap_free(tx_queue, buffer->tsoh);
  87. }
  88. buffer->tsoh = NULL;
  89. }
  90. }
  91. static inline unsigned
  92. efx_max_tx_len(struct efx_nic *efx, dma_addr_t dma_addr)
  93. {
  94. /* Depending on the NIC revision, we can use descriptor
  95. * lengths up to 8K or 8K-1. However, since PCI Express
  96. * devices must split read requests at 4K boundaries, there is
  97. * little benefit from using descriptors that cross those
  98. * boundaries and we keep things simple by not doing so.
  99. */
  100. unsigned len = (~dma_addr & 0xfff) + 1;
  101. /* Work around hardware bug for unaligned buffers. */
  102. if (EFX_WORKAROUND_5391(efx) && (dma_addr & 0xf))
  103. len = min_t(unsigned, len, 512 - (dma_addr & 0xf));
  104. return len;
  105. }
  106. /*
  107. * Add a socket buffer to a TX queue
  108. *
  109. * This maps all fragments of a socket buffer for DMA and adds them to
  110. * the TX queue. The queue's insert pointer will be incremented by
  111. * the number of fragments in the socket buffer.
  112. *
  113. * If any DMA mapping fails, any mapped fragments will be unmapped,
  114. * the queue's insert pointer will be restored to its original value.
  115. *
  116. * This function is split out from efx_hard_start_xmit to allow the
  117. * loopback test to direct packets via specific TX queues.
  118. *
  119. * Returns NETDEV_TX_OK or NETDEV_TX_BUSY
  120. * You must hold netif_tx_lock() to call this function.
  121. */
  122. netdev_tx_t efx_enqueue_skb(struct efx_tx_queue *tx_queue, struct sk_buff *skb)
  123. {
  124. struct efx_nic *efx = tx_queue->efx;
  125. struct pci_dev *pci_dev = efx->pci_dev;
  126. struct efx_tx_buffer *buffer;
  127. skb_frag_t *fragment;
  128. struct page *page;
  129. int page_offset;
  130. unsigned int len, unmap_len = 0, fill_level, insert_ptr;
  131. dma_addr_t dma_addr, unmap_addr = 0;
  132. unsigned int dma_len;
  133. bool unmap_single;
  134. int q_space, i = 0;
  135. netdev_tx_t rc = NETDEV_TX_OK;
  136. EFX_BUG_ON_PARANOID(tx_queue->write_count != tx_queue->insert_count);
  137. if (skb_shinfo(skb)->gso_size)
  138. return efx_enqueue_skb_tso(tx_queue, skb);
  139. /* Get size of the initial fragment */
  140. len = skb_headlen(skb);
  141. /* Pad if necessary */
  142. if (EFX_WORKAROUND_15592(efx) && skb->len <= 32) {
  143. EFX_BUG_ON_PARANOID(skb->data_len);
  144. len = 32 + 1;
  145. if (skb_pad(skb, len - skb->len))
  146. return NETDEV_TX_OK;
  147. }
  148. fill_level = tx_queue->insert_count - tx_queue->old_read_count;
  149. q_space = efx->txq_entries - 1 - fill_level;
  150. /* Map for DMA. Use pci_map_single rather than pci_map_page
  151. * since this is more efficient on machines with sparse
  152. * memory.
  153. */
  154. unmap_single = true;
  155. dma_addr = pci_map_single(pci_dev, skb->data, len, PCI_DMA_TODEVICE);
  156. /* Process all fragments */
  157. while (1) {
  158. if (unlikely(pci_dma_mapping_error(pci_dev, dma_addr)))
  159. goto pci_err;
  160. /* Store fields for marking in the per-fragment final
  161. * descriptor */
  162. unmap_len = len;
  163. unmap_addr = dma_addr;
  164. /* Add to TX queue, splitting across DMA boundaries */
  165. do {
  166. if (unlikely(q_space-- <= 0)) {
  167. /* It might be that completions have
  168. * happened since the xmit path last
  169. * checked. Update the xmit path's
  170. * copy of read_count.
  171. */
  172. netif_tx_stop_queue(tx_queue->core_txq);
  173. /* This memory barrier protects the
  174. * change of queue state from the access
  175. * of read_count. */
  176. smp_mb();
  177. tx_queue->old_read_count =
  178. ACCESS_ONCE(tx_queue->read_count);
  179. fill_level = (tx_queue->insert_count
  180. - tx_queue->old_read_count);
  181. q_space = efx->txq_entries - 1 - fill_level;
  182. if (unlikely(q_space-- <= 0)) {
  183. rc = NETDEV_TX_BUSY;
  184. goto unwind;
  185. }
  186. smp_mb();
  187. netif_tx_start_queue(tx_queue->core_txq);
  188. }
  189. insert_ptr = tx_queue->insert_count & tx_queue->ptr_mask;
  190. buffer = &tx_queue->buffer[insert_ptr];
  191. efx_tsoh_free(tx_queue, buffer);
  192. EFX_BUG_ON_PARANOID(buffer->tsoh);
  193. EFX_BUG_ON_PARANOID(buffer->skb);
  194. EFX_BUG_ON_PARANOID(buffer->len);
  195. EFX_BUG_ON_PARANOID(!buffer->continuation);
  196. EFX_BUG_ON_PARANOID(buffer->unmap_len);
  197. dma_len = efx_max_tx_len(efx, dma_addr);
  198. if (likely(dma_len >= len))
  199. dma_len = len;
  200. /* Fill out per descriptor fields */
  201. buffer->len = dma_len;
  202. buffer->dma_addr = dma_addr;
  203. len -= dma_len;
  204. dma_addr += dma_len;
  205. ++tx_queue->insert_count;
  206. } while (len);
  207. /* Transfer ownership of the unmapping to the final buffer */
  208. buffer->unmap_single = unmap_single;
  209. buffer->unmap_len = unmap_len;
  210. unmap_len = 0;
  211. /* Get address and size of next fragment */
  212. if (i >= skb_shinfo(skb)->nr_frags)
  213. break;
  214. fragment = &skb_shinfo(skb)->frags[i];
  215. len = fragment->size;
  216. page = fragment->page;
  217. page_offset = fragment->page_offset;
  218. i++;
  219. /* Map for DMA */
  220. unmap_single = false;
  221. dma_addr = pci_map_page(pci_dev, page, page_offset, len,
  222. PCI_DMA_TODEVICE);
  223. }
  224. /* Transfer ownership of the skb to the final buffer */
  225. buffer->skb = skb;
  226. buffer->continuation = false;
  227. /* Pass off to hardware */
  228. efx_nic_push_buffers(tx_queue);
  229. return NETDEV_TX_OK;
  230. pci_err:
  231. netif_err(efx, tx_err, efx->net_dev,
  232. " TX queue %d could not map skb with %d bytes %d "
  233. "fragments for DMA\n", tx_queue->queue, skb->len,
  234. skb_shinfo(skb)->nr_frags + 1);
  235. /* Mark the packet as transmitted, and free the SKB ourselves */
  236. dev_kfree_skb_any(skb);
  237. unwind:
  238. /* Work backwards until we hit the original insert pointer value */
  239. while (tx_queue->insert_count != tx_queue->write_count) {
  240. --tx_queue->insert_count;
  241. insert_ptr = tx_queue->insert_count & tx_queue->ptr_mask;
  242. buffer = &tx_queue->buffer[insert_ptr];
  243. efx_dequeue_buffer(tx_queue, buffer);
  244. buffer->len = 0;
  245. }
  246. /* Free the fragment we were mid-way through pushing */
  247. if (unmap_len) {
  248. if (unmap_single)
  249. pci_unmap_single(pci_dev, unmap_addr, unmap_len,
  250. PCI_DMA_TODEVICE);
  251. else
  252. pci_unmap_page(pci_dev, unmap_addr, unmap_len,
  253. PCI_DMA_TODEVICE);
  254. }
  255. return rc;
  256. }
  257. /* Remove packets from the TX queue
  258. *
  259. * This removes packets from the TX queue, up to and including the
  260. * specified index.
  261. */
  262. static void efx_dequeue_buffers(struct efx_tx_queue *tx_queue,
  263. unsigned int index)
  264. {
  265. struct efx_nic *efx = tx_queue->efx;
  266. unsigned int stop_index, read_ptr;
  267. stop_index = (index + 1) & tx_queue->ptr_mask;
  268. read_ptr = tx_queue->read_count & tx_queue->ptr_mask;
  269. while (read_ptr != stop_index) {
  270. struct efx_tx_buffer *buffer = &tx_queue->buffer[read_ptr];
  271. if (unlikely(buffer->len == 0)) {
  272. netif_err(efx, tx_err, efx->net_dev,
  273. "TX queue %d spurious TX completion id %x\n",
  274. tx_queue->queue, read_ptr);
  275. efx_schedule_reset(efx, RESET_TYPE_TX_SKIP);
  276. return;
  277. }
  278. efx_dequeue_buffer(tx_queue, buffer);
  279. buffer->continuation = true;
  280. buffer->len = 0;
  281. ++tx_queue->read_count;
  282. read_ptr = tx_queue->read_count & tx_queue->ptr_mask;
  283. }
  284. }
  285. /* Initiate a packet transmission. We use one channel per CPU
  286. * (sharing when we have more CPUs than channels). On Falcon, the TX
  287. * completion events will be directed back to the CPU that transmitted
  288. * the packet, which should be cache-efficient.
  289. *
  290. * Context: non-blocking.
  291. * Note that returning anything other than NETDEV_TX_OK will cause the
  292. * OS to free the skb.
  293. */
  294. netdev_tx_t efx_hard_start_xmit(struct sk_buff *skb,
  295. struct net_device *net_dev)
  296. {
  297. struct efx_nic *efx = netdev_priv(net_dev);
  298. struct efx_tx_queue *tx_queue;
  299. unsigned index, type;
  300. if (unlikely(efx->port_inhibited))
  301. return NETDEV_TX_BUSY;
  302. index = skb_get_queue_mapping(skb);
  303. type = skb->ip_summed == CHECKSUM_PARTIAL ? EFX_TXQ_TYPE_OFFLOAD : 0;
  304. if (index >= efx->n_tx_channels) {
  305. index -= efx->n_tx_channels;
  306. type |= EFX_TXQ_TYPE_HIGHPRI;
  307. }
  308. tx_queue = efx_get_tx_queue(efx, index, type);
  309. return efx_enqueue_skb(tx_queue, skb);
  310. }
  311. void efx_init_tx_queue_core_txq(struct efx_tx_queue *tx_queue)
  312. {
  313. struct efx_nic *efx = tx_queue->efx;
  314. /* Must be inverse of queue lookup in efx_hard_start_xmit() */
  315. tx_queue->core_txq =
  316. netdev_get_tx_queue(efx->net_dev,
  317. tx_queue->queue / EFX_TXQ_TYPES +
  318. ((tx_queue->queue & EFX_TXQ_TYPE_HIGHPRI) ?
  319. efx->n_tx_channels : 0));
  320. }
  321. int efx_setup_tc(struct net_device *net_dev, u8 num_tc)
  322. {
  323. struct efx_nic *efx = netdev_priv(net_dev);
  324. struct efx_channel *channel;
  325. struct efx_tx_queue *tx_queue;
  326. unsigned tc;
  327. int rc;
  328. if (efx_nic_rev(efx) < EFX_REV_FALCON_B0 || num_tc > EFX_MAX_TX_TC)
  329. return -EINVAL;
  330. if (num_tc == net_dev->num_tc)
  331. return 0;
  332. for (tc = 0; tc < num_tc; tc++) {
  333. net_dev->tc_to_txq[tc].offset = tc * efx->n_tx_channels;
  334. net_dev->tc_to_txq[tc].count = efx->n_tx_channels;
  335. }
  336. if (num_tc > net_dev->num_tc) {
  337. /* Initialise high-priority queues as necessary */
  338. efx_for_each_channel(channel, efx) {
  339. efx_for_each_possible_channel_tx_queue(tx_queue,
  340. channel) {
  341. if (!(tx_queue->queue & EFX_TXQ_TYPE_HIGHPRI))
  342. continue;
  343. if (!tx_queue->buffer) {
  344. rc = efx_probe_tx_queue(tx_queue);
  345. if (rc)
  346. return rc;
  347. }
  348. if (!tx_queue->initialised)
  349. efx_init_tx_queue(tx_queue);
  350. efx_init_tx_queue_core_txq(tx_queue);
  351. }
  352. }
  353. } else {
  354. /* Reduce number of classes before number of queues */
  355. net_dev->num_tc = num_tc;
  356. }
  357. rc = netif_set_real_num_tx_queues(net_dev,
  358. max_t(int, num_tc, 1) *
  359. efx->n_tx_channels);
  360. if (rc)
  361. return rc;
  362. /* Do not destroy high-priority queues when they become
  363. * unused. We would have to flush them first, and it is
  364. * fairly difficult to flush a subset of TX queues. Leave
  365. * it to efx_fini_channels().
  366. */
  367. net_dev->num_tc = num_tc;
  368. return 0;
  369. }
  370. void efx_xmit_done(struct efx_tx_queue *tx_queue, unsigned int index)
  371. {
  372. unsigned fill_level;
  373. struct efx_nic *efx = tx_queue->efx;
  374. EFX_BUG_ON_PARANOID(index > tx_queue->ptr_mask);
  375. efx_dequeue_buffers(tx_queue, index);
  376. /* See if we need to restart the netif queue. This barrier
  377. * separates the update of read_count from the test of the
  378. * queue state. */
  379. smp_mb();
  380. if (unlikely(netif_tx_queue_stopped(tx_queue->core_txq)) &&
  381. likely(efx->port_enabled)) {
  382. fill_level = tx_queue->insert_count - tx_queue->read_count;
  383. if (fill_level < EFX_TXQ_THRESHOLD(efx)) {
  384. EFX_BUG_ON_PARANOID(!efx_dev_registered(efx));
  385. netif_tx_wake_queue(tx_queue->core_txq);
  386. }
  387. }
  388. /* Check whether the hardware queue is now empty */
  389. if ((int)(tx_queue->read_count - tx_queue->old_write_count) >= 0) {
  390. tx_queue->old_write_count = ACCESS_ONCE(tx_queue->write_count);
  391. if (tx_queue->read_count == tx_queue->old_write_count) {
  392. smp_mb();
  393. tx_queue->empty_read_count =
  394. tx_queue->read_count | EFX_EMPTY_COUNT_VALID;
  395. }
  396. }
  397. }
  398. int efx_probe_tx_queue(struct efx_tx_queue *tx_queue)
  399. {
  400. struct efx_nic *efx = tx_queue->efx;
  401. unsigned int entries;
  402. int i, rc;
  403. /* Create the smallest power-of-two aligned ring */
  404. entries = max(roundup_pow_of_two(efx->txq_entries), EFX_MIN_DMAQ_SIZE);
  405. EFX_BUG_ON_PARANOID(entries > EFX_MAX_DMAQ_SIZE);
  406. tx_queue->ptr_mask = entries - 1;
  407. netif_dbg(efx, probe, efx->net_dev,
  408. "creating TX queue %d size %#x mask %#x\n",
  409. tx_queue->queue, efx->txq_entries, tx_queue->ptr_mask);
  410. /* Allocate software ring */
  411. tx_queue->buffer = kzalloc(entries * sizeof(*tx_queue->buffer),
  412. GFP_KERNEL);
  413. if (!tx_queue->buffer)
  414. return -ENOMEM;
  415. for (i = 0; i <= tx_queue->ptr_mask; ++i)
  416. tx_queue->buffer[i].continuation = true;
  417. /* Allocate hardware ring */
  418. rc = efx_nic_probe_tx(tx_queue);
  419. if (rc)
  420. goto fail;
  421. return 0;
  422. fail:
  423. kfree(tx_queue->buffer);
  424. tx_queue->buffer = NULL;
  425. return rc;
  426. }
  427. void efx_init_tx_queue(struct efx_tx_queue *tx_queue)
  428. {
  429. netif_dbg(tx_queue->efx, drv, tx_queue->efx->net_dev,
  430. "initialising TX queue %d\n", tx_queue->queue);
  431. tx_queue->insert_count = 0;
  432. tx_queue->write_count = 0;
  433. tx_queue->old_write_count = 0;
  434. tx_queue->read_count = 0;
  435. tx_queue->old_read_count = 0;
  436. tx_queue->empty_read_count = 0 | EFX_EMPTY_COUNT_VALID;
  437. /* Set up TX descriptor ring */
  438. efx_nic_init_tx(tx_queue);
  439. tx_queue->initialised = true;
  440. }
  441. void efx_release_tx_buffers(struct efx_tx_queue *tx_queue)
  442. {
  443. struct efx_tx_buffer *buffer;
  444. if (!tx_queue->buffer)
  445. return;
  446. /* Free any buffers left in the ring */
  447. while (tx_queue->read_count != tx_queue->write_count) {
  448. buffer = &tx_queue->buffer[tx_queue->read_count & tx_queue->ptr_mask];
  449. efx_dequeue_buffer(tx_queue, buffer);
  450. buffer->continuation = true;
  451. buffer->len = 0;
  452. ++tx_queue->read_count;
  453. }
  454. }
  455. void efx_fini_tx_queue(struct efx_tx_queue *tx_queue)
  456. {
  457. if (!tx_queue->initialised)
  458. return;
  459. netif_dbg(tx_queue->efx, drv, tx_queue->efx->net_dev,
  460. "shutting down TX queue %d\n", tx_queue->queue);
  461. tx_queue->initialised = false;
  462. /* Flush TX queue, remove descriptor ring */
  463. efx_nic_fini_tx(tx_queue);
  464. efx_release_tx_buffers(tx_queue);
  465. /* Free up TSO header cache */
  466. efx_fini_tso(tx_queue);
  467. }
  468. void efx_remove_tx_queue(struct efx_tx_queue *tx_queue)
  469. {
  470. if (!tx_queue->buffer)
  471. return;
  472. netif_dbg(tx_queue->efx, drv, tx_queue->efx->net_dev,
  473. "destroying TX queue %d\n", tx_queue->queue);
  474. efx_nic_remove_tx(tx_queue);
  475. kfree(tx_queue->buffer);
  476. tx_queue->buffer = NULL;
  477. }
  478. /* Efx TCP segmentation acceleration.
  479. *
  480. * Why? Because by doing it here in the driver we can go significantly
  481. * faster than the GSO.
  482. *
  483. * Requires TX checksum offload support.
  484. */
  485. /* Number of bytes inserted at the start of a TSO header buffer,
  486. * similar to NET_IP_ALIGN.
  487. */
  488. #ifdef CONFIG_HAVE_EFFICIENT_UNALIGNED_ACCESS
  489. #define TSOH_OFFSET 0
  490. #else
  491. #define TSOH_OFFSET NET_IP_ALIGN
  492. #endif
  493. #define TSOH_BUFFER(tsoh) ((u8 *)(tsoh + 1) + TSOH_OFFSET)
  494. /* Total size of struct efx_tso_header, buffer and padding */
  495. #define TSOH_SIZE(hdr_len) \
  496. (sizeof(struct efx_tso_header) + TSOH_OFFSET + hdr_len)
  497. /* Size of blocks on free list. Larger blocks must be allocated from
  498. * the heap.
  499. */
  500. #define TSOH_STD_SIZE 128
  501. #define PTR_DIFF(p1, p2) ((u8 *)(p1) - (u8 *)(p2))
  502. #define ETH_HDR_LEN(skb) (skb_network_header(skb) - (skb)->data)
  503. #define SKB_TCP_OFF(skb) PTR_DIFF(tcp_hdr(skb), (skb)->data)
  504. #define SKB_IPV4_OFF(skb) PTR_DIFF(ip_hdr(skb), (skb)->data)
  505. #define SKB_IPV6_OFF(skb) PTR_DIFF(ipv6_hdr(skb), (skb)->data)
  506. /**
  507. * struct tso_state - TSO state for an SKB
  508. * @out_len: Remaining length in current segment
  509. * @seqnum: Current sequence number
  510. * @ipv4_id: Current IPv4 ID, host endian
  511. * @packet_space: Remaining space in current packet
  512. * @dma_addr: DMA address of current position
  513. * @in_len: Remaining length in current SKB fragment
  514. * @unmap_len: Length of SKB fragment
  515. * @unmap_addr: DMA address of SKB fragment
  516. * @unmap_single: DMA single vs page mapping flag
  517. * @protocol: Network protocol (after any VLAN header)
  518. * @header_len: Number of bytes of header
  519. * @full_packet_size: Number of bytes to put in each outgoing segment
  520. *
  521. * The state used during segmentation. It is put into this data structure
  522. * just to make it easy to pass into inline functions.
  523. */
  524. struct tso_state {
  525. /* Output position */
  526. unsigned out_len;
  527. unsigned seqnum;
  528. unsigned ipv4_id;
  529. unsigned packet_space;
  530. /* Input position */
  531. dma_addr_t dma_addr;
  532. unsigned in_len;
  533. unsigned unmap_len;
  534. dma_addr_t unmap_addr;
  535. bool unmap_single;
  536. __be16 protocol;
  537. unsigned header_len;
  538. int full_packet_size;
  539. };
  540. /*
  541. * Verify that our various assumptions about sk_buffs and the conditions
  542. * under which TSO will be attempted hold true. Return the protocol number.
  543. */
  544. static __be16 efx_tso_check_protocol(struct sk_buff *skb)
  545. {
  546. __be16 protocol = skb->protocol;
  547. EFX_BUG_ON_PARANOID(((struct ethhdr *)skb->data)->h_proto !=
  548. protocol);
  549. if (protocol == htons(ETH_P_8021Q)) {
  550. /* Find the encapsulated protocol; reset network header
  551. * and transport header based on that. */
  552. struct vlan_ethhdr *veh = (struct vlan_ethhdr *)skb->data;
  553. protocol = veh->h_vlan_encapsulated_proto;
  554. skb_set_network_header(skb, sizeof(*veh));
  555. if (protocol == htons(ETH_P_IP))
  556. skb_set_transport_header(skb, sizeof(*veh) +
  557. 4 * ip_hdr(skb)->ihl);
  558. else if (protocol == htons(ETH_P_IPV6))
  559. skb_set_transport_header(skb, sizeof(*veh) +
  560. sizeof(struct ipv6hdr));
  561. }
  562. if (protocol == htons(ETH_P_IP)) {
  563. EFX_BUG_ON_PARANOID(ip_hdr(skb)->protocol != IPPROTO_TCP);
  564. } else {
  565. EFX_BUG_ON_PARANOID(protocol != htons(ETH_P_IPV6));
  566. EFX_BUG_ON_PARANOID(ipv6_hdr(skb)->nexthdr != NEXTHDR_TCP);
  567. }
  568. EFX_BUG_ON_PARANOID((PTR_DIFF(tcp_hdr(skb), skb->data)
  569. + (tcp_hdr(skb)->doff << 2u)) >
  570. skb_headlen(skb));
  571. return protocol;
  572. }
  573. /*
  574. * Allocate a page worth of efx_tso_header structures, and string them
  575. * into the tx_queue->tso_headers_free linked list. Return 0 or -ENOMEM.
  576. */
  577. static int efx_tsoh_block_alloc(struct efx_tx_queue *tx_queue)
  578. {
  579. struct pci_dev *pci_dev = tx_queue->efx->pci_dev;
  580. struct efx_tso_header *tsoh;
  581. dma_addr_t dma_addr;
  582. u8 *base_kva, *kva;
  583. base_kva = pci_alloc_consistent(pci_dev, PAGE_SIZE, &dma_addr);
  584. if (base_kva == NULL) {
  585. netif_err(tx_queue->efx, tx_err, tx_queue->efx->net_dev,
  586. "Unable to allocate page for TSO headers\n");
  587. return -ENOMEM;
  588. }
  589. /* pci_alloc_consistent() allocates pages. */
  590. EFX_BUG_ON_PARANOID(dma_addr & (PAGE_SIZE - 1u));
  591. for (kva = base_kva; kva < base_kva + PAGE_SIZE; kva += TSOH_STD_SIZE) {
  592. tsoh = (struct efx_tso_header *)kva;
  593. tsoh->dma_addr = dma_addr + (TSOH_BUFFER(tsoh) - base_kva);
  594. tsoh->next = tx_queue->tso_headers_free;
  595. tx_queue->tso_headers_free = tsoh;
  596. }
  597. return 0;
  598. }
  599. /* Free up a TSO header, and all others in the same page. */
  600. static void efx_tsoh_block_free(struct efx_tx_queue *tx_queue,
  601. struct efx_tso_header *tsoh,
  602. struct pci_dev *pci_dev)
  603. {
  604. struct efx_tso_header **p;
  605. unsigned long base_kva;
  606. dma_addr_t base_dma;
  607. base_kva = (unsigned long)tsoh & PAGE_MASK;
  608. base_dma = tsoh->dma_addr & PAGE_MASK;
  609. p = &tx_queue->tso_headers_free;
  610. while (*p != NULL) {
  611. if (((unsigned long)*p & PAGE_MASK) == base_kva)
  612. *p = (*p)->next;
  613. else
  614. p = &(*p)->next;
  615. }
  616. pci_free_consistent(pci_dev, PAGE_SIZE, (void *)base_kva, base_dma);
  617. }
  618. static struct efx_tso_header *
  619. efx_tsoh_heap_alloc(struct efx_tx_queue *tx_queue, size_t header_len)
  620. {
  621. struct efx_tso_header *tsoh;
  622. tsoh = kmalloc(TSOH_SIZE(header_len), GFP_ATOMIC | GFP_DMA);
  623. if (unlikely(!tsoh))
  624. return NULL;
  625. tsoh->dma_addr = pci_map_single(tx_queue->efx->pci_dev,
  626. TSOH_BUFFER(tsoh), header_len,
  627. PCI_DMA_TODEVICE);
  628. if (unlikely(pci_dma_mapping_error(tx_queue->efx->pci_dev,
  629. tsoh->dma_addr))) {
  630. kfree(tsoh);
  631. return NULL;
  632. }
  633. tsoh->unmap_len = header_len;
  634. return tsoh;
  635. }
  636. static void
  637. efx_tsoh_heap_free(struct efx_tx_queue *tx_queue, struct efx_tso_header *tsoh)
  638. {
  639. pci_unmap_single(tx_queue->efx->pci_dev,
  640. tsoh->dma_addr, tsoh->unmap_len,
  641. PCI_DMA_TODEVICE);
  642. kfree(tsoh);
  643. }
  644. /**
  645. * efx_tx_queue_insert - push descriptors onto the TX queue
  646. * @tx_queue: Efx TX queue
  647. * @dma_addr: DMA address of fragment
  648. * @len: Length of fragment
  649. * @final_buffer: The final buffer inserted into the queue
  650. *
  651. * Push descriptors onto the TX queue. Return 0 on success or 1 if
  652. * @tx_queue full.
  653. */
  654. static int efx_tx_queue_insert(struct efx_tx_queue *tx_queue,
  655. dma_addr_t dma_addr, unsigned len,
  656. struct efx_tx_buffer **final_buffer)
  657. {
  658. struct efx_tx_buffer *buffer;
  659. struct efx_nic *efx = tx_queue->efx;
  660. unsigned dma_len, fill_level, insert_ptr;
  661. int q_space;
  662. EFX_BUG_ON_PARANOID(len <= 0);
  663. fill_level = tx_queue->insert_count - tx_queue->old_read_count;
  664. /* -1 as there is no way to represent all descriptors used */
  665. q_space = efx->txq_entries - 1 - fill_level;
  666. while (1) {
  667. if (unlikely(q_space-- <= 0)) {
  668. /* It might be that completions have happened
  669. * since the xmit path last checked. Update
  670. * the xmit path's copy of read_count.
  671. */
  672. netif_tx_stop_queue(tx_queue->core_txq);
  673. /* This memory barrier protects the change of
  674. * queue state from the access of read_count. */
  675. smp_mb();
  676. tx_queue->old_read_count =
  677. ACCESS_ONCE(tx_queue->read_count);
  678. fill_level = (tx_queue->insert_count
  679. - tx_queue->old_read_count);
  680. q_space = efx->txq_entries - 1 - fill_level;
  681. if (unlikely(q_space-- <= 0)) {
  682. *final_buffer = NULL;
  683. return 1;
  684. }
  685. smp_mb();
  686. netif_tx_start_queue(tx_queue->core_txq);
  687. }
  688. insert_ptr = tx_queue->insert_count & tx_queue->ptr_mask;
  689. buffer = &tx_queue->buffer[insert_ptr];
  690. ++tx_queue->insert_count;
  691. EFX_BUG_ON_PARANOID(tx_queue->insert_count -
  692. tx_queue->read_count >=
  693. efx->txq_entries);
  694. efx_tsoh_free(tx_queue, buffer);
  695. EFX_BUG_ON_PARANOID(buffer->len);
  696. EFX_BUG_ON_PARANOID(buffer->unmap_len);
  697. EFX_BUG_ON_PARANOID(buffer->skb);
  698. EFX_BUG_ON_PARANOID(!buffer->continuation);
  699. EFX_BUG_ON_PARANOID(buffer->tsoh);
  700. buffer->dma_addr = dma_addr;
  701. dma_len = efx_max_tx_len(efx, dma_addr);
  702. /* If there is enough space to send then do so */
  703. if (dma_len >= len)
  704. break;
  705. buffer->len = dma_len; /* Don't set the other members */
  706. dma_addr += dma_len;
  707. len -= dma_len;
  708. }
  709. EFX_BUG_ON_PARANOID(!len);
  710. buffer->len = len;
  711. *final_buffer = buffer;
  712. return 0;
  713. }
  714. /*
  715. * Put a TSO header into the TX queue.
  716. *
  717. * This is special-cased because we know that it is small enough to fit in
  718. * a single fragment, and we know it doesn't cross a page boundary. It
  719. * also allows us to not worry about end-of-packet etc.
  720. */
  721. static void efx_tso_put_header(struct efx_tx_queue *tx_queue,
  722. struct efx_tso_header *tsoh, unsigned len)
  723. {
  724. struct efx_tx_buffer *buffer;
  725. buffer = &tx_queue->buffer[tx_queue->insert_count & tx_queue->ptr_mask];
  726. efx_tsoh_free(tx_queue, buffer);
  727. EFX_BUG_ON_PARANOID(buffer->len);
  728. EFX_BUG_ON_PARANOID(buffer->unmap_len);
  729. EFX_BUG_ON_PARANOID(buffer->skb);
  730. EFX_BUG_ON_PARANOID(!buffer->continuation);
  731. EFX_BUG_ON_PARANOID(buffer->tsoh);
  732. buffer->len = len;
  733. buffer->dma_addr = tsoh->dma_addr;
  734. buffer->tsoh = tsoh;
  735. ++tx_queue->insert_count;
  736. }
  737. /* Remove descriptors put into a tx_queue. */
  738. static void efx_enqueue_unwind(struct efx_tx_queue *tx_queue)
  739. {
  740. struct efx_tx_buffer *buffer;
  741. dma_addr_t unmap_addr;
  742. /* Work backwards until we hit the original insert pointer value */
  743. while (tx_queue->insert_count != tx_queue->write_count) {
  744. --tx_queue->insert_count;
  745. buffer = &tx_queue->buffer[tx_queue->insert_count &
  746. tx_queue->ptr_mask];
  747. efx_tsoh_free(tx_queue, buffer);
  748. EFX_BUG_ON_PARANOID(buffer->skb);
  749. if (buffer->unmap_len) {
  750. unmap_addr = (buffer->dma_addr + buffer->len -
  751. buffer->unmap_len);
  752. if (buffer->unmap_single)
  753. pci_unmap_single(tx_queue->efx->pci_dev,
  754. unmap_addr, buffer->unmap_len,
  755. PCI_DMA_TODEVICE);
  756. else
  757. pci_unmap_page(tx_queue->efx->pci_dev,
  758. unmap_addr, buffer->unmap_len,
  759. PCI_DMA_TODEVICE);
  760. buffer->unmap_len = 0;
  761. }
  762. buffer->len = 0;
  763. buffer->continuation = true;
  764. }
  765. }
  766. /* Parse the SKB header and initialise state. */
  767. static void tso_start(struct tso_state *st, const struct sk_buff *skb)
  768. {
  769. /* All ethernet/IP/TCP headers combined size is TCP header size
  770. * plus offset of TCP header relative to start of packet.
  771. */
  772. st->header_len = ((tcp_hdr(skb)->doff << 2u)
  773. + PTR_DIFF(tcp_hdr(skb), skb->data));
  774. st->full_packet_size = st->header_len + skb_shinfo(skb)->gso_size;
  775. if (st->protocol == htons(ETH_P_IP))
  776. st->ipv4_id = ntohs(ip_hdr(skb)->id);
  777. else
  778. st->ipv4_id = 0;
  779. st->seqnum = ntohl(tcp_hdr(skb)->seq);
  780. EFX_BUG_ON_PARANOID(tcp_hdr(skb)->urg);
  781. EFX_BUG_ON_PARANOID(tcp_hdr(skb)->syn);
  782. EFX_BUG_ON_PARANOID(tcp_hdr(skb)->rst);
  783. st->packet_space = st->full_packet_size;
  784. st->out_len = skb->len - st->header_len;
  785. st->unmap_len = 0;
  786. st->unmap_single = false;
  787. }
  788. static int tso_get_fragment(struct tso_state *st, struct efx_nic *efx,
  789. skb_frag_t *frag)
  790. {
  791. st->unmap_addr = pci_map_page(efx->pci_dev, frag->page,
  792. frag->page_offset, frag->size,
  793. PCI_DMA_TODEVICE);
  794. if (likely(!pci_dma_mapping_error(efx->pci_dev, st->unmap_addr))) {
  795. st->unmap_single = false;
  796. st->unmap_len = frag->size;
  797. st->in_len = frag->size;
  798. st->dma_addr = st->unmap_addr;
  799. return 0;
  800. }
  801. return -ENOMEM;
  802. }
  803. static int tso_get_head_fragment(struct tso_state *st, struct efx_nic *efx,
  804. const struct sk_buff *skb)
  805. {
  806. int hl = st->header_len;
  807. int len = skb_headlen(skb) - hl;
  808. st->unmap_addr = pci_map_single(efx->pci_dev, skb->data + hl,
  809. len, PCI_DMA_TODEVICE);
  810. if (likely(!pci_dma_mapping_error(efx->pci_dev, st->unmap_addr))) {
  811. st->unmap_single = true;
  812. st->unmap_len = len;
  813. st->in_len = len;
  814. st->dma_addr = st->unmap_addr;
  815. return 0;
  816. }
  817. return -ENOMEM;
  818. }
  819. /**
  820. * tso_fill_packet_with_fragment - form descriptors for the current fragment
  821. * @tx_queue: Efx TX queue
  822. * @skb: Socket buffer
  823. * @st: TSO state
  824. *
  825. * Form descriptors for the current fragment, until we reach the end
  826. * of fragment or end-of-packet. Return 0 on success, 1 if not enough
  827. * space in @tx_queue.
  828. */
  829. static int tso_fill_packet_with_fragment(struct efx_tx_queue *tx_queue,
  830. const struct sk_buff *skb,
  831. struct tso_state *st)
  832. {
  833. struct efx_tx_buffer *buffer;
  834. int n, end_of_packet, rc;
  835. if (st->in_len == 0)
  836. return 0;
  837. if (st->packet_space == 0)
  838. return 0;
  839. EFX_BUG_ON_PARANOID(st->in_len <= 0);
  840. EFX_BUG_ON_PARANOID(st->packet_space <= 0);
  841. n = min(st->in_len, st->packet_space);
  842. st->packet_space -= n;
  843. st->out_len -= n;
  844. st->in_len -= n;
  845. rc = efx_tx_queue_insert(tx_queue, st->dma_addr, n, &buffer);
  846. if (likely(rc == 0)) {
  847. if (st->out_len == 0)
  848. /* Transfer ownership of the skb */
  849. buffer->skb = skb;
  850. end_of_packet = st->out_len == 0 || st->packet_space == 0;
  851. buffer->continuation = !end_of_packet;
  852. if (st->in_len == 0) {
  853. /* Transfer ownership of the pci mapping */
  854. buffer->unmap_len = st->unmap_len;
  855. buffer->unmap_single = st->unmap_single;
  856. st->unmap_len = 0;
  857. }
  858. }
  859. st->dma_addr += n;
  860. return rc;
  861. }
  862. /**
  863. * tso_start_new_packet - generate a new header and prepare for the new packet
  864. * @tx_queue: Efx TX queue
  865. * @skb: Socket buffer
  866. * @st: TSO state
  867. *
  868. * Generate a new header and prepare for the new packet. Return 0 on
  869. * success, or -1 if failed to alloc header.
  870. */
  871. static int tso_start_new_packet(struct efx_tx_queue *tx_queue,
  872. const struct sk_buff *skb,
  873. struct tso_state *st)
  874. {
  875. struct efx_tso_header *tsoh;
  876. struct tcphdr *tsoh_th;
  877. unsigned ip_length;
  878. u8 *header;
  879. /* Allocate a DMA-mapped header buffer. */
  880. if (likely(TSOH_SIZE(st->header_len) <= TSOH_STD_SIZE)) {
  881. if (tx_queue->tso_headers_free == NULL) {
  882. if (efx_tsoh_block_alloc(tx_queue))
  883. return -1;
  884. }
  885. EFX_BUG_ON_PARANOID(!tx_queue->tso_headers_free);
  886. tsoh = tx_queue->tso_headers_free;
  887. tx_queue->tso_headers_free = tsoh->next;
  888. tsoh->unmap_len = 0;
  889. } else {
  890. tx_queue->tso_long_headers++;
  891. tsoh = efx_tsoh_heap_alloc(tx_queue, st->header_len);
  892. if (unlikely(!tsoh))
  893. return -1;
  894. }
  895. header = TSOH_BUFFER(tsoh);
  896. tsoh_th = (struct tcphdr *)(header + SKB_TCP_OFF(skb));
  897. /* Copy and update the headers. */
  898. memcpy(header, skb->data, st->header_len);
  899. tsoh_th->seq = htonl(st->seqnum);
  900. st->seqnum += skb_shinfo(skb)->gso_size;
  901. if (st->out_len > skb_shinfo(skb)->gso_size) {
  902. /* This packet will not finish the TSO burst. */
  903. ip_length = st->full_packet_size - ETH_HDR_LEN(skb);
  904. tsoh_th->fin = 0;
  905. tsoh_th->psh = 0;
  906. } else {
  907. /* This packet will be the last in the TSO burst. */
  908. ip_length = st->header_len - ETH_HDR_LEN(skb) + st->out_len;
  909. tsoh_th->fin = tcp_hdr(skb)->fin;
  910. tsoh_th->psh = tcp_hdr(skb)->psh;
  911. }
  912. if (st->protocol == htons(ETH_P_IP)) {
  913. struct iphdr *tsoh_iph =
  914. (struct iphdr *)(header + SKB_IPV4_OFF(skb));
  915. tsoh_iph->tot_len = htons(ip_length);
  916. /* Linux leaves suitable gaps in the IP ID space for us to fill. */
  917. tsoh_iph->id = htons(st->ipv4_id);
  918. st->ipv4_id++;
  919. } else {
  920. struct ipv6hdr *tsoh_iph =
  921. (struct ipv6hdr *)(header + SKB_IPV6_OFF(skb));
  922. tsoh_iph->payload_len = htons(ip_length - sizeof(*tsoh_iph));
  923. }
  924. st->packet_space = skb_shinfo(skb)->gso_size;
  925. ++tx_queue->tso_packets;
  926. /* Form a descriptor for this header. */
  927. efx_tso_put_header(tx_queue, tsoh, st->header_len);
  928. return 0;
  929. }
  930. /**
  931. * efx_enqueue_skb_tso - segment and transmit a TSO socket buffer
  932. * @tx_queue: Efx TX queue
  933. * @skb: Socket buffer
  934. *
  935. * Context: You must hold netif_tx_lock() to call this function.
  936. *
  937. * Add socket buffer @skb to @tx_queue, doing TSO or return != 0 if
  938. * @skb was not enqueued. In all cases @skb is consumed. Return
  939. * %NETDEV_TX_OK or %NETDEV_TX_BUSY.
  940. */
  941. static int efx_enqueue_skb_tso(struct efx_tx_queue *tx_queue,
  942. struct sk_buff *skb)
  943. {
  944. struct efx_nic *efx = tx_queue->efx;
  945. int frag_i, rc, rc2 = NETDEV_TX_OK;
  946. struct tso_state state;
  947. /* Find the packet protocol and sanity-check it */
  948. state.protocol = efx_tso_check_protocol(skb);
  949. EFX_BUG_ON_PARANOID(tx_queue->write_count != tx_queue->insert_count);
  950. tso_start(&state, skb);
  951. /* Assume that skb header area contains exactly the headers, and
  952. * all payload is in the frag list.
  953. */
  954. if (skb_headlen(skb) == state.header_len) {
  955. /* Grab the first payload fragment. */
  956. EFX_BUG_ON_PARANOID(skb_shinfo(skb)->nr_frags < 1);
  957. frag_i = 0;
  958. rc = tso_get_fragment(&state, efx,
  959. skb_shinfo(skb)->frags + frag_i);
  960. if (rc)
  961. goto mem_err;
  962. } else {
  963. rc = tso_get_head_fragment(&state, efx, skb);
  964. if (rc)
  965. goto mem_err;
  966. frag_i = -1;
  967. }
  968. if (tso_start_new_packet(tx_queue, skb, &state) < 0)
  969. goto mem_err;
  970. while (1) {
  971. rc = tso_fill_packet_with_fragment(tx_queue, skb, &state);
  972. if (unlikely(rc)) {
  973. rc2 = NETDEV_TX_BUSY;
  974. goto unwind;
  975. }
  976. /* Move onto the next fragment? */
  977. if (state.in_len == 0) {
  978. if (++frag_i >= skb_shinfo(skb)->nr_frags)
  979. /* End of payload reached. */
  980. break;
  981. rc = tso_get_fragment(&state, efx,
  982. skb_shinfo(skb)->frags + frag_i);
  983. if (rc)
  984. goto mem_err;
  985. }
  986. /* Start at new packet? */
  987. if (state.packet_space == 0 &&
  988. tso_start_new_packet(tx_queue, skb, &state) < 0)
  989. goto mem_err;
  990. }
  991. /* Pass off to hardware */
  992. efx_nic_push_buffers(tx_queue);
  993. tx_queue->tso_bursts++;
  994. return NETDEV_TX_OK;
  995. mem_err:
  996. netif_err(efx, tx_err, efx->net_dev,
  997. "Out of memory for TSO headers, or PCI mapping error\n");
  998. dev_kfree_skb_any(skb);
  999. unwind:
  1000. /* Free the DMA mapping we were in the process of writing out */
  1001. if (state.unmap_len) {
  1002. if (state.unmap_single)
  1003. pci_unmap_single(efx->pci_dev, state.unmap_addr,
  1004. state.unmap_len, PCI_DMA_TODEVICE);
  1005. else
  1006. pci_unmap_page(efx->pci_dev, state.unmap_addr,
  1007. state.unmap_len, PCI_DMA_TODEVICE);
  1008. }
  1009. efx_enqueue_unwind(tx_queue);
  1010. return rc2;
  1011. }
  1012. /*
  1013. * Free up all TSO datastructures associated with tx_queue. This
  1014. * routine should be called only once the tx_queue is both empty and
  1015. * will no longer be used.
  1016. */
  1017. static void efx_fini_tso(struct efx_tx_queue *tx_queue)
  1018. {
  1019. unsigned i;
  1020. if (tx_queue->buffer) {
  1021. for (i = 0; i <= tx_queue->ptr_mask; ++i)
  1022. efx_tsoh_free(tx_queue, &tx_queue->buffer[i]);
  1023. }
  1024. while (tx_queue->tso_headers_free != NULL)
  1025. efx_tsoh_block_free(tx_queue, tx_queue->tso_headers_free,
  1026. tx_queue->efx->pci_dev);
  1027. }