tx.c 33 KB

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