tx.c 33 KB

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