tx.c 33 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209
  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. unsigned int *pkts_compl,
  33. unsigned int *bytes_compl)
  34. {
  35. if (buffer->unmap_len) {
  36. struct device *dma_dev = &tx_queue->efx->pci_dev->dev;
  37. dma_addr_t unmap_addr = (buffer->dma_addr + buffer->len -
  38. buffer->unmap_len);
  39. if (buffer->unmap_single)
  40. dma_unmap_single(dma_dev, unmap_addr, buffer->unmap_len,
  41. DMA_TO_DEVICE);
  42. else
  43. dma_unmap_page(dma_dev, unmap_addr, buffer->unmap_len,
  44. DMA_TO_DEVICE);
  45. buffer->unmap_len = 0;
  46. buffer->unmap_single = false;
  47. }
  48. if (buffer->skb) {
  49. (*pkts_compl)++;
  50. (*bytes_compl) += buffer->skb->len;
  51. dev_kfree_skb_any((struct sk_buff *) buffer->skb);
  52. buffer->skb = NULL;
  53. netif_vdbg(tx_queue->efx, tx_done, tx_queue->efx->net_dev,
  54. "TX queue %d transmission id %x complete\n",
  55. tx_queue->queue, tx_queue->read_count);
  56. }
  57. }
  58. /**
  59. * struct efx_tso_header - a DMA mapped buffer for packet headers
  60. * @next: Linked list of free ones.
  61. * The list is protected by the TX queue lock.
  62. * @dma_unmap_len: Length to unmap for an oversize buffer, or 0.
  63. * @dma_addr: The DMA address of the header below.
  64. *
  65. * This controls the memory used for a TSO header. Use TSOH_DATA()
  66. * to find the packet header data. Use TSOH_SIZE() to calculate the
  67. * total size required for a given packet header length. TSO headers
  68. * in the free list are exactly %TSOH_STD_SIZE bytes in size.
  69. */
  70. struct efx_tso_header {
  71. union {
  72. struct efx_tso_header *next;
  73. size_t unmap_len;
  74. };
  75. dma_addr_t dma_addr;
  76. };
  77. static int efx_enqueue_skb_tso(struct efx_tx_queue *tx_queue,
  78. struct sk_buff *skb);
  79. static void efx_fini_tso(struct efx_tx_queue *tx_queue);
  80. static void efx_tsoh_heap_free(struct efx_tx_queue *tx_queue,
  81. struct efx_tso_header *tsoh);
  82. static void efx_tsoh_free(struct efx_tx_queue *tx_queue,
  83. struct efx_tx_buffer *buffer)
  84. {
  85. if (buffer->tsoh) {
  86. if (likely(!buffer->tsoh->unmap_len)) {
  87. buffer->tsoh->next = tx_queue->tso_headers_free;
  88. tx_queue->tso_headers_free = buffer->tsoh;
  89. } else {
  90. efx_tsoh_heap_free(tx_queue, buffer->tsoh);
  91. }
  92. buffer->tsoh = NULL;
  93. }
  94. }
  95. static inline unsigned
  96. efx_max_tx_len(struct efx_nic *efx, dma_addr_t dma_addr)
  97. {
  98. /* Depending on the NIC revision, we can use descriptor
  99. * lengths up to 8K or 8K-1. However, since PCI Express
  100. * devices must split read requests at 4K boundaries, there is
  101. * little benefit from using descriptors that cross those
  102. * boundaries and we keep things simple by not doing so.
  103. */
  104. unsigned len = (~dma_addr & (EFX_PAGE_SIZE - 1)) + 1;
  105. /* Work around hardware bug for unaligned buffers. */
  106. if (EFX_WORKAROUND_5391(efx) && (dma_addr & 0xf))
  107. len = min_t(unsigned, len, 512 - (dma_addr & 0xf));
  108. return len;
  109. }
  110. /*
  111. * Add a socket buffer to a TX queue
  112. *
  113. * This maps all fragments of a socket buffer for DMA and adds them to
  114. * the TX queue. The queue's insert pointer will be incremented by
  115. * the number of fragments in the socket buffer.
  116. *
  117. * If any DMA mapping fails, any mapped fragments will be unmapped,
  118. * the queue's insert pointer will be restored to its original value.
  119. *
  120. * This function is split out from efx_hard_start_xmit to allow the
  121. * loopback test to direct packets via specific TX queues.
  122. *
  123. * Returns NETDEV_TX_OK or NETDEV_TX_BUSY
  124. * You must hold netif_tx_lock() to call this function.
  125. */
  126. netdev_tx_t efx_enqueue_skb(struct efx_tx_queue *tx_queue, struct sk_buff *skb)
  127. {
  128. struct efx_nic *efx = tx_queue->efx;
  129. struct device *dma_dev = &efx->pci_dev->dev;
  130. struct efx_tx_buffer *buffer;
  131. skb_frag_t *fragment;
  132. unsigned int len, unmap_len = 0, fill_level, insert_ptr;
  133. dma_addr_t dma_addr, unmap_addr = 0;
  134. unsigned int dma_len;
  135. bool unmap_single;
  136. int q_space, i = 0;
  137. netdev_tx_t rc = NETDEV_TX_OK;
  138. EFX_BUG_ON_PARANOID(tx_queue->write_count != tx_queue->insert_count);
  139. if (skb_shinfo(skb)->gso_size)
  140. return efx_enqueue_skb_tso(tx_queue, skb);
  141. /* Get size of the initial fragment */
  142. len = skb_headlen(skb);
  143. /* Pad if necessary */
  144. if (EFX_WORKAROUND_15592(efx) && skb->len <= 32) {
  145. EFX_BUG_ON_PARANOID(skb->data_len);
  146. len = 32 + 1;
  147. if (skb_pad(skb, len - skb->len))
  148. return NETDEV_TX_OK;
  149. }
  150. fill_level = tx_queue->insert_count - tx_queue->old_read_count;
  151. q_space = efx->txq_entries - 1 - fill_level;
  152. /* Map for DMA. Use dma_map_single rather than dma_map_page
  153. * since this is more efficient on machines with sparse
  154. * memory.
  155. */
  156. unmap_single = true;
  157. dma_addr = dma_map_single(dma_dev, skb->data, len, PCI_DMA_TODEVICE);
  158. /* Process all fragments */
  159. while (1) {
  160. if (unlikely(dma_mapping_error(dma_dev, dma_addr)))
  161. goto dma_err;
  162. /* Store fields for marking in the per-fragment final
  163. * descriptor */
  164. unmap_len = len;
  165. unmap_addr = dma_addr;
  166. /* Add to TX queue, splitting across DMA boundaries */
  167. do {
  168. if (unlikely(q_space-- <= 0)) {
  169. /* It might be that completions have
  170. * happened since the xmit path last
  171. * checked. Update the xmit path's
  172. * copy of read_count.
  173. */
  174. netif_tx_stop_queue(tx_queue->core_txq);
  175. /* This memory barrier protects the
  176. * change of queue state from the access
  177. * of read_count. */
  178. smp_mb();
  179. tx_queue->old_read_count =
  180. ACCESS_ONCE(tx_queue->read_count);
  181. fill_level = (tx_queue->insert_count
  182. - tx_queue->old_read_count);
  183. q_space = efx->txq_entries - 1 - fill_level;
  184. if (unlikely(q_space-- <= 0)) {
  185. rc = NETDEV_TX_BUSY;
  186. goto unwind;
  187. }
  188. smp_mb();
  189. if (likely(!efx->loopback_selftest))
  190. netif_tx_start_queue(
  191. tx_queue->core_txq);
  192. }
  193. insert_ptr = tx_queue->insert_count & tx_queue->ptr_mask;
  194. buffer = &tx_queue->buffer[insert_ptr];
  195. efx_tsoh_free(tx_queue, buffer);
  196. EFX_BUG_ON_PARANOID(buffer->tsoh);
  197. EFX_BUG_ON_PARANOID(buffer->skb);
  198. EFX_BUG_ON_PARANOID(buffer->len);
  199. EFX_BUG_ON_PARANOID(!buffer->continuation);
  200. EFX_BUG_ON_PARANOID(buffer->unmap_len);
  201. dma_len = efx_max_tx_len(efx, dma_addr);
  202. if (likely(dma_len >= len))
  203. dma_len = len;
  204. /* Fill out per descriptor fields */
  205. buffer->len = dma_len;
  206. buffer->dma_addr = dma_addr;
  207. len -= dma_len;
  208. dma_addr += dma_len;
  209. ++tx_queue->insert_count;
  210. } while (len);
  211. /* Transfer ownership of the unmapping to the final buffer */
  212. buffer->unmap_single = unmap_single;
  213. buffer->unmap_len = unmap_len;
  214. unmap_len = 0;
  215. /* Get address and size of next fragment */
  216. if (i >= skb_shinfo(skb)->nr_frags)
  217. break;
  218. fragment = &skb_shinfo(skb)->frags[i];
  219. len = skb_frag_size(fragment);
  220. i++;
  221. /* Map for DMA */
  222. unmap_single = false;
  223. dma_addr = skb_frag_dma_map(dma_dev, fragment, 0, len,
  224. DMA_TO_DEVICE);
  225. }
  226. /* Transfer ownership of the skb to the final buffer */
  227. buffer->skb = skb;
  228. buffer->continuation = false;
  229. netdev_tx_sent_queue(tx_queue->core_txq, skb->len);
  230. /* Pass off to hardware */
  231. efx_nic_push_buffers(tx_queue);
  232. return NETDEV_TX_OK;
  233. dma_err:
  234. netif_err(efx, tx_err, efx->net_dev,
  235. " TX queue %d could not map skb with %d bytes %d "
  236. "fragments for DMA\n", tx_queue->queue, skb->len,
  237. skb_shinfo(skb)->nr_frags + 1);
  238. /* Mark the packet as transmitted, and free the SKB ourselves */
  239. dev_kfree_skb_any(skb);
  240. unwind:
  241. /* Work backwards until we hit the original insert pointer value */
  242. while (tx_queue->insert_count != tx_queue->write_count) {
  243. unsigned int pkts_compl = 0, bytes_compl = 0;
  244. --tx_queue->insert_count;
  245. insert_ptr = tx_queue->insert_count & tx_queue->ptr_mask;
  246. buffer = &tx_queue->buffer[insert_ptr];
  247. efx_dequeue_buffer(tx_queue, buffer, &pkts_compl, &bytes_compl);
  248. buffer->len = 0;
  249. }
  250. /* Free the fragment we were mid-way through pushing */
  251. if (unmap_len) {
  252. if (unmap_single)
  253. dma_unmap_single(dma_dev, unmap_addr, unmap_len,
  254. DMA_TO_DEVICE);
  255. else
  256. dma_unmap_page(dma_dev, unmap_addr, unmap_len,
  257. DMA_TO_DEVICE);
  258. }
  259. return rc;
  260. }
  261. /* Remove packets from the TX queue
  262. *
  263. * This removes packets from the TX queue, up to and including the
  264. * specified index.
  265. */
  266. static void efx_dequeue_buffers(struct efx_tx_queue *tx_queue,
  267. unsigned int index,
  268. unsigned int *pkts_compl,
  269. unsigned int *bytes_compl)
  270. {
  271. struct efx_nic *efx = tx_queue->efx;
  272. unsigned int stop_index, read_ptr;
  273. stop_index = (index + 1) & tx_queue->ptr_mask;
  274. read_ptr = tx_queue->read_count & tx_queue->ptr_mask;
  275. while (read_ptr != stop_index) {
  276. struct efx_tx_buffer *buffer = &tx_queue->buffer[read_ptr];
  277. if (unlikely(buffer->len == 0)) {
  278. netif_err(efx, tx_err, efx->net_dev,
  279. "TX queue %d spurious TX completion id %x\n",
  280. tx_queue->queue, read_ptr);
  281. efx_schedule_reset(efx, RESET_TYPE_TX_SKIP);
  282. return;
  283. }
  284. efx_dequeue_buffer(tx_queue, buffer, pkts_compl, bytes_compl);
  285. buffer->continuation = true;
  286. buffer->len = 0;
  287. ++tx_queue->read_count;
  288. read_ptr = tx_queue->read_count & tx_queue->ptr_mask;
  289. }
  290. }
  291. /* Initiate a packet transmission. We use one channel per CPU
  292. * (sharing when we have more CPUs than channels). On Falcon, the TX
  293. * completion events will be directed back to the CPU that transmitted
  294. * the packet, which should be cache-efficient.
  295. *
  296. * Context: non-blocking.
  297. * Note that returning anything other than NETDEV_TX_OK will cause the
  298. * OS to free the skb.
  299. */
  300. netdev_tx_t efx_hard_start_xmit(struct sk_buff *skb,
  301. struct net_device *net_dev)
  302. {
  303. struct efx_nic *efx = netdev_priv(net_dev);
  304. struct efx_tx_queue *tx_queue;
  305. unsigned index, type;
  306. EFX_WARN_ON_PARANOID(!netif_device_present(net_dev));
  307. index = skb_get_queue_mapping(skb);
  308. type = skb->ip_summed == CHECKSUM_PARTIAL ? EFX_TXQ_TYPE_OFFLOAD : 0;
  309. if (index >= efx->n_tx_channels) {
  310. index -= efx->n_tx_channels;
  311. type |= EFX_TXQ_TYPE_HIGHPRI;
  312. }
  313. tx_queue = efx_get_tx_queue(efx, index, type);
  314. return efx_enqueue_skb(tx_queue, skb);
  315. }
  316. void efx_init_tx_queue_core_txq(struct efx_tx_queue *tx_queue)
  317. {
  318. struct efx_nic *efx = tx_queue->efx;
  319. /* Must be inverse of queue lookup in efx_hard_start_xmit() */
  320. tx_queue->core_txq =
  321. netdev_get_tx_queue(efx->net_dev,
  322. tx_queue->queue / EFX_TXQ_TYPES +
  323. ((tx_queue->queue & EFX_TXQ_TYPE_HIGHPRI) ?
  324. efx->n_tx_channels : 0));
  325. }
  326. int efx_setup_tc(struct net_device *net_dev, u8 num_tc)
  327. {
  328. struct efx_nic *efx = netdev_priv(net_dev);
  329. struct efx_channel *channel;
  330. struct efx_tx_queue *tx_queue;
  331. unsigned tc;
  332. int rc;
  333. if (efx_nic_rev(efx) < EFX_REV_FALCON_B0 || num_tc > EFX_MAX_TX_TC)
  334. return -EINVAL;
  335. if (num_tc == net_dev->num_tc)
  336. return 0;
  337. for (tc = 0; tc < num_tc; tc++) {
  338. net_dev->tc_to_txq[tc].offset = tc * efx->n_tx_channels;
  339. net_dev->tc_to_txq[tc].count = efx->n_tx_channels;
  340. }
  341. if (num_tc > net_dev->num_tc) {
  342. /* Initialise high-priority queues as necessary */
  343. efx_for_each_channel(channel, efx) {
  344. efx_for_each_possible_channel_tx_queue(tx_queue,
  345. channel) {
  346. if (!(tx_queue->queue & EFX_TXQ_TYPE_HIGHPRI))
  347. continue;
  348. if (!tx_queue->buffer) {
  349. rc = efx_probe_tx_queue(tx_queue);
  350. if (rc)
  351. return rc;
  352. }
  353. if (!tx_queue->initialised)
  354. efx_init_tx_queue(tx_queue);
  355. efx_init_tx_queue_core_txq(tx_queue);
  356. }
  357. }
  358. } else {
  359. /* Reduce number of classes before number of queues */
  360. net_dev->num_tc = num_tc;
  361. }
  362. rc = netif_set_real_num_tx_queues(net_dev,
  363. max_t(int, num_tc, 1) *
  364. efx->n_tx_channels);
  365. if (rc)
  366. return rc;
  367. /* Do not destroy high-priority queues when they become
  368. * unused. We would have to flush them first, and it is
  369. * fairly difficult to flush a subset of TX queues. Leave
  370. * it to efx_fini_channels().
  371. */
  372. net_dev->num_tc = num_tc;
  373. return 0;
  374. }
  375. void efx_xmit_done(struct efx_tx_queue *tx_queue, unsigned int index)
  376. {
  377. unsigned fill_level;
  378. struct efx_nic *efx = tx_queue->efx;
  379. unsigned int pkts_compl = 0, bytes_compl = 0;
  380. EFX_BUG_ON_PARANOID(index > tx_queue->ptr_mask);
  381. efx_dequeue_buffers(tx_queue, index, &pkts_compl, &bytes_compl);
  382. netdev_tx_completed_queue(tx_queue->core_txq, pkts_compl, bytes_compl);
  383. /* See if we need to restart the netif queue. This barrier
  384. * separates the update of read_count from the test of the
  385. * queue state. */
  386. smp_mb();
  387. if (unlikely(netif_tx_queue_stopped(tx_queue->core_txq)) &&
  388. likely(efx->port_enabled) &&
  389. likely(netif_device_present(efx->net_dev))) {
  390. fill_level = tx_queue->insert_count - tx_queue->read_count;
  391. if (fill_level < EFX_TXQ_THRESHOLD(efx))
  392. netif_tx_wake_queue(tx_queue->core_txq);
  393. }
  394. /* Check whether the hardware queue is now empty */
  395. if ((int)(tx_queue->read_count - tx_queue->old_write_count) >= 0) {
  396. tx_queue->old_write_count = ACCESS_ONCE(tx_queue->write_count);
  397. if (tx_queue->read_count == tx_queue->old_write_count) {
  398. smp_mb();
  399. tx_queue->empty_read_count =
  400. tx_queue->read_count | EFX_EMPTY_COUNT_VALID;
  401. }
  402. }
  403. }
  404. int efx_probe_tx_queue(struct efx_tx_queue *tx_queue)
  405. {
  406. struct efx_nic *efx = tx_queue->efx;
  407. unsigned int entries;
  408. int i, rc;
  409. /* Create the smallest power-of-two aligned ring */
  410. entries = max(roundup_pow_of_two(efx->txq_entries), EFX_MIN_DMAQ_SIZE);
  411. EFX_BUG_ON_PARANOID(entries > EFX_MAX_DMAQ_SIZE);
  412. tx_queue->ptr_mask = entries - 1;
  413. netif_dbg(efx, probe, efx->net_dev,
  414. "creating TX queue %d size %#x mask %#x\n",
  415. tx_queue->queue, efx->txq_entries, tx_queue->ptr_mask);
  416. /* Allocate software ring */
  417. tx_queue->buffer = kcalloc(entries, sizeof(*tx_queue->buffer),
  418. GFP_KERNEL);
  419. if (!tx_queue->buffer)
  420. return -ENOMEM;
  421. for (i = 0; i <= tx_queue->ptr_mask; ++i)
  422. tx_queue->buffer[i].continuation = true;
  423. /* Allocate hardware ring */
  424. rc = efx_nic_probe_tx(tx_queue);
  425. if (rc)
  426. goto fail;
  427. return 0;
  428. fail:
  429. kfree(tx_queue->buffer);
  430. tx_queue->buffer = NULL;
  431. return rc;
  432. }
  433. void efx_init_tx_queue(struct efx_tx_queue *tx_queue)
  434. {
  435. netif_dbg(tx_queue->efx, drv, tx_queue->efx->net_dev,
  436. "initialising TX queue %d\n", tx_queue->queue);
  437. tx_queue->insert_count = 0;
  438. tx_queue->write_count = 0;
  439. tx_queue->old_write_count = 0;
  440. tx_queue->read_count = 0;
  441. tx_queue->old_read_count = 0;
  442. tx_queue->empty_read_count = 0 | EFX_EMPTY_COUNT_VALID;
  443. /* Set up TX descriptor ring */
  444. efx_nic_init_tx(tx_queue);
  445. tx_queue->initialised = true;
  446. }
  447. void efx_release_tx_buffers(struct efx_tx_queue *tx_queue)
  448. {
  449. struct efx_tx_buffer *buffer;
  450. if (!tx_queue->buffer)
  451. return;
  452. /* Free any buffers left in the ring */
  453. while (tx_queue->read_count != tx_queue->write_count) {
  454. unsigned int pkts_compl = 0, bytes_compl = 0;
  455. buffer = &tx_queue->buffer[tx_queue->read_count & tx_queue->ptr_mask];
  456. efx_dequeue_buffer(tx_queue, buffer, &pkts_compl, &bytes_compl);
  457. buffer->continuation = true;
  458. buffer->len = 0;
  459. ++tx_queue->read_count;
  460. }
  461. netdev_tx_reset_queue(tx_queue->core_txq);
  462. }
  463. void efx_fini_tx_queue(struct efx_tx_queue *tx_queue)
  464. {
  465. if (!tx_queue->initialised)
  466. return;
  467. netif_dbg(tx_queue->efx, drv, tx_queue->efx->net_dev,
  468. "shutting down TX queue %d\n", tx_queue->queue);
  469. tx_queue->initialised = false;
  470. /* Flush TX queue, remove descriptor ring */
  471. efx_nic_fini_tx(tx_queue);
  472. efx_release_tx_buffers(tx_queue);
  473. /* Free up TSO header cache */
  474. efx_fini_tso(tx_queue);
  475. }
  476. void efx_remove_tx_queue(struct efx_tx_queue *tx_queue)
  477. {
  478. if (!tx_queue->buffer)
  479. return;
  480. netif_dbg(tx_queue->efx, drv, tx_queue->efx->net_dev,
  481. "destroying TX queue %d\n", tx_queue->queue);
  482. efx_nic_remove_tx(tx_queue);
  483. kfree(tx_queue->buffer);
  484. tx_queue->buffer = NULL;
  485. }
  486. /* Efx TCP segmentation acceleration.
  487. *
  488. * Why? Because by doing it here in the driver we can go significantly
  489. * faster than the GSO.
  490. *
  491. * Requires TX checksum offload support.
  492. */
  493. /* Number of bytes inserted at the start of a TSO header buffer,
  494. * similar to NET_IP_ALIGN.
  495. */
  496. #ifdef CONFIG_HAVE_EFFICIENT_UNALIGNED_ACCESS
  497. #define TSOH_OFFSET 0
  498. #else
  499. #define TSOH_OFFSET NET_IP_ALIGN
  500. #endif
  501. #define TSOH_BUFFER(tsoh) ((u8 *)(tsoh + 1) + TSOH_OFFSET)
  502. /* Total size of struct efx_tso_header, buffer and padding */
  503. #define TSOH_SIZE(hdr_len) \
  504. (sizeof(struct efx_tso_header) + TSOH_OFFSET + hdr_len)
  505. /* Size of blocks on free list. Larger blocks must be allocated from
  506. * the heap.
  507. */
  508. #define TSOH_STD_SIZE 128
  509. #define PTR_DIFF(p1, p2) ((u8 *)(p1) - (u8 *)(p2))
  510. #define ETH_HDR_LEN(skb) (skb_network_header(skb) - (skb)->data)
  511. #define SKB_TCP_OFF(skb) PTR_DIFF(tcp_hdr(skb), (skb)->data)
  512. #define SKB_IPV4_OFF(skb) PTR_DIFF(ip_hdr(skb), (skb)->data)
  513. #define SKB_IPV6_OFF(skb) PTR_DIFF(ipv6_hdr(skb), (skb)->data)
  514. /**
  515. * struct tso_state - TSO state for an SKB
  516. * @out_len: Remaining length in current segment
  517. * @seqnum: Current sequence number
  518. * @ipv4_id: Current IPv4 ID, host endian
  519. * @packet_space: Remaining space in current packet
  520. * @dma_addr: DMA address of current position
  521. * @in_len: Remaining length in current SKB fragment
  522. * @unmap_len: Length of SKB fragment
  523. * @unmap_addr: DMA address of SKB fragment
  524. * @unmap_single: DMA single vs page mapping flag
  525. * @protocol: Network protocol (after any VLAN header)
  526. * @header_len: Number of bytes of header
  527. * @full_packet_size: Number of bytes to put in each outgoing segment
  528. *
  529. * The state used during segmentation. It is put into this data structure
  530. * just to make it easy to pass into inline functions.
  531. */
  532. struct tso_state {
  533. /* Output position */
  534. unsigned out_len;
  535. unsigned seqnum;
  536. unsigned ipv4_id;
  537. unsigned packet_space;
  538. /* Input position */
  539. dma_addr_t dma_addr;
  540. unsigned in_len;
  541. unsigned unmap_len;
  542. dma_addr_t unmap_addr;
  543. bool unmap_single;
  544. __be16 protocol;
  545. unsigned header_len;
  546. int full_packet_size;
  547. };
  548. /*
  549. * Verify that our various assumptions about sk_buffs and the conditions
  550. * under which TSO will be attempted hold true. Return the protocol number.
  551. */
  552. static __be16 efx_tso_check_protocol(struct sk_buff *skb)
  553. {
  554. __be16 protocol = skb->protocol;
  555. EFX_BUG_ON_PARANOID(((struct ethhdr *)skb->data)->h_proto !=
  556. protocol);
  557. if (protocol == htons(ETH_P_8021Q)) {
  558. struct vlan_ethhdr *veh = (struct vlan_ethhdr *)skb->data;
  559. protocol = veh->h_vlan_encapsulated_proto;
  560. }
  561. if (protocol == htons(ETH_P_IP)) {
  562. EFX_BUG_ON_PARANOID(ip_hdr(skb)->protocol != IPPROTO_TCP);
  563. } else {
  564. EFX_BUG_ON_PARANOID(protocol != htons(ETH_P_IPV6));
  565. EFX_BUG_ON_PARANOID(ipv6_hdr(skb)->nexthdr != NEXTHDR_TCP);
  566. }
  567. EFX_BUG_ON_PARANOID((PTR_DIFF(tcp_hdr(skb), skb->data)
  568. + (tcp_hdr(skb)->doff << 2u)) >
  569. skb_headlen(skb));
  570. return protocol;
  571. }
  572. /*
  573. * Allocate a page worth of efx_tso_header structures, and string them
  574. * into the tx_queue->tso_headers_free linked list. Return 0 or -ENOMEM.
  575. */
  576. static int efx_tsoh_block_alloc(struct efx_tx_queue *tx_queue)
  577. {
  578. struct device *dma_dev = &tx_queue->efx->pci_dev->dev;
  579. struct efx_tso_header *tsoh;
  580. dma_addr_t dma_addr;
  581. u8 *base_kva, *kva;
  582. base_kva = dma_alloc_coherent(dma_dev, PAGE_SIZE, &dma_addr, GFP_ATOMIC);
  583. if (base_kva == NULL) {
  584. netif_err(tx_queue->efx, tx_err, tx_queue->efx->net_dev,
  585. "Unable to allocate page for TSO headers\n");
  586. return -ENOMEM;
  587. }
  588. /* dma_alloc_coherent() allocates pages. */
  589. EFX_BUG_ON_PARANOID(dma_addr & (PAGE_SIZE - 1u));
  590. for (kva = base_kva; kva < base_kva + PAGE_SIZE; kva += TSOH_STD_SIZE) {
  591. tsoh = (struct efx_tso_header *)kva;
  592. tsoh->dma_addr = dma_addr + (TSOH_BUFFER(tsoh) - base_kva);
  593. tsoh->next = tx_queue->tso_headers_free;
  594. tx_queue->tso_headers_free = tsoh;
  595. }
  596. return 0;
  597. }
  598. /* Free up a TSO header, and all others in the same page. */
  599. static void efx_tsoh_block_free(struct efx_tx_queue *tx_queue,
  600. struct efx_tso_header *tsoh,
  601. struct device *dma_dev)
  602. {
  603. struct efx_tso_header **p;
  604. unsigned long base_kva;
  605. dma_addr_t base_dma;
  606. base_kva = (unsigned long)tsoh & PAGE_MASK;
  607. base_dma = tsoh->dma_addr & PAGE_MASK;
  608. p = &tx_queue->tso_headers_free;
  609. while (*p != NULL) {
  610. if (((unsigned long)*p & PAGE_MASK) == base_kva)
  611. *p = (*p)->next;
  612. else
  613. p = &(*p)->next;
  614. }
  615. dma_free_coherent(dma_dev, PAGE_SIZE, (void *)base_kva, base_dma);
  616. }
  617. static struct efx_tso_header *
  618. efx_tsoh_heap_alloc(struct efx_tx_queue *tx_queue, size_t header_len)
  619. {
  620. struct efx_tso_header *tsoh;
  621. tsoh = kmalloc(TSOH_SIZE(header_len), GFP_ATOMIC | GFP_DMA);
  622. if (unlikely(!tsoh))
  623. return NULL;
  624. tsoh->dma_addr = dma_map_single(&tx_queue->efx->pci_dev->dev,
  625. TSOH_BUFFER(tsoh), header_len,
  626. DMA_TO_DEVICE);
  627. if (unlikely(dma_mapping_error(&tx_queue->efx->pci_dev->dev,
  628. tsoh->dma_addr))) {
  629. kfree(tsoh);
  630. return NULL;
  631. }
  632. tsoh->unmap_len = header_len;
  633. return tsoh;
  634. }
  635. static void
  636. efx_tsoh_heap_free(struct efx_tx_queue *tx_queue, struct efx_tso_header *tsoh)
  637. {
  638. dma_unmap_single(&tx_queue->efx->pci_dev->dev,
  639. tsoh->dma_addr, tsoh->unmap_len,
  640. DMA_TO_DEVICE);
  641. kfree(tsoh);
  642. }
  643. /**
  644. * efx_tx_queue_insert - push descriptors onto the TX queue
  645. * @tx_queue: Efx TX queue
  646. * @dma_addr: DMA address of fragment
  647. * @len: Length of fragment
  648. * @final_buffer: The final buffer inserted into the queue
  649. *
  650. * Push descriptors onto the TX queue. Return 0 on success or 1 if
  651. * @tx_queue full.
  652. */
  653. static int efx_tx_queue_insert(struct efx_tx_queue *tx_queue,
  654. dma_addr_t dma_addr, unsigned len,
  655. struct efx_tx_buffer **final_buffer)
  656. {
  657. struct efx_tx_buffer *buffer;
  658. struct efx_nic *efx = tx_queue->efx;
  659. unsigned dma_len, fill_level, insert_ptr;
  660. int q_space;
  661. EFX_BUG_ON_PARANOID(len <= 0);
  662. fill_level = tx_queue->insert_count - tx_queue->old_read_count;
  663. /* -1 as there is no way to represent all descriptors used */
  664. q_space = efx->txq_entries - 1 - fill_level;
  665. while (1) {
  666. if (unlikely(q_space-- <= 0)) {
  667. /* It might be that completions have happened
  668. * since the xmit path last checked. Update
  669. * the xmit path's copy of read_count.
  670. */
  671. netif_tx_stop_queue(tx_queue->core_txq);
  672. /* This memory barrier protects the change of
  673. * queue state from the access of read_count. */
  674. smp_mb();
  675. tx_queue->old_read_count =
  676. ACCESS_ONCE(tx_queue->read_count);
  677. fill_level = (tx_queue->insert_count
  678. - tx_queue->old_read_count);
  679. q_space = efx->txq_entries - 1 - fill_level;
  680. if (unlikely(q_space-- <= 0)) {
  681. *final_buffer = NULL;
  682. return 1;
  683. }
  684. smp_mb();
  685. netif_tx_start_queue(tx_queue->core_txq);
  686. }
  687. insert_ptr = tx_queue->insert_count & tx_queue->ptr_mask;
  688. buffer = &tx_queue->buffer[insert_ptr];
  689. ++tx_queue->insert_count;
  690. EFX_BUG_ON_PARANOID(tx_queue->insert_count -
  691. tx_queue->read_count >=
  692. efx->txq_entries);
  693. efx_tsoh_free(tx_queue, buffer);
  694. EFX_BUG_ON_PARANOID(buffer->len);
  695. EFX_BUG_ON_PARANOID(buffer->unmap_len);
  696. EFX_BUG_ON_PARANOID(buffer->skb);
  697. EFX_BUG_ON_PARANOID(!buffer->continuation);
  698. EFX_BUG_ON_PARANOID(buffer->tsoh);
  699. buffer->dma_addr = dma_addr;
  700. dma_len = efx_max_tx_len(efx, dma_addr);
  701. /* If there is enough space to send then do so */
  702. if (dma_len >= len)
  703. break;
  704. buffer->len = dma_len; /* Don't set the other members */
  705. dma_addr += dma_len;
  706. len -= dma_len;
  707. }
  708. EFX_BUG_ON_PARANOID(!len);
  709. buffer->len = len;
  710. *final_buffer = buffer;
  711. return 0;
  712. }
  713. /*
  714. * Put a TSO header into the TX queue.
  715. *
  716. * This is special-cased because we know that it is small enough to fit in
  717. * a single fragment, and we know it doesn't cross a page boundary. It
  718. * also allows us to not worry about end-of-packet etc.
  719. */
  720. static void efx_tso_put_header(struct efx_tx_queue *tx_queue,
  721. struct efx_tso_header *tsoh, unsigned len)
  722. {
  723. struct efx_tx_buffer *buffer;
  724. buffer = &tx_queue->buffer[tx_queue->insert_count & tx_queue->ptr_mask];
  725. efx_tsoh_free(tx_queue, buffer);
  726. EFX_BUG_ON_PARANOID(buffer->len);
  727. EFX_BUG_ON_PARANOID(buffer->unmap_len);
  728. EFX_BUG_ON_PARANOID(buffer->skb);
  729. EFX_BUG_ON_PARANOID(!buffer->continuation);
  730. EFX_BUG_ON_PARANOID(buffer->tsoh);
  731. buffer->len = len;
  732. buffer->dma_addr = tsoh->dma_addr;
  733. buffer->tsoh = tsoh;
  734. ++tx_queue->insert_count;
  735. }
  736. /* Remove descriptors put into a tx_queue. */
  737. static void efx_enqueue_unwind(struct efx_tx_queue *tx_queue)
  738. {
  739. struct efx_tx_buffer *buffer;
  740. dma_addr_t unmap_addr;
  741. /* Work backwards until we hit the original insert pointer value */
  742. while (tx_queue->insert_count != tx_queue->write_count) {
  743. --tx_queue->insert_count;
  744. buffer = &tx_queue->buffer[tx_queue->insert_count &
  745. tx_queue->ptr_mask];
  746. efx_tsoh_free(tx_queue, buffer);
  747. EFX_BUG_ON_PARANOID(buffer->skb);
  748. if (buffer->unmap_len) {
  749. unmap_addr = (buffer->dma_addr + buffer->len -
  750. buffer->unmap_len);
  751. if (buffer->unmap_single)
  752. dma_unmap_single(&tx_queue->efx->pci_dev->dev,
  753. unmap_addr, buffer->unmap_len,
  754. DMA_TO_DEVICE);
  755. else
  756. dma_unmap_page(&tx_queue->efx->pci_dev->dev,
  757. unmap_addr, buffer->unmap_len,
  758. DMA_TO_DEVICE);
  759. buffer->unmap_len = 0;
  760. }
  761. buffer->len = 0;
  762. buffer->continuation = true;
  763. }
  764. }
  765. /* Parse the SKB header and initialise state. */
  766. static void tso_start(struct tso_state *st, const struct sk_buff *skb)
  767. {
  768. /* All ethernet/IP/TCP headers combined size is TCP header size
  769. * plus offset of TCP header relative to start of packet.
  770. */
  771. st->header_len = ((tcp_hdr(skb)->doff << 2u)
  772. + PTR_DIFF(tcp_hdr(skb), skb->data));
  773. st->full_packet_size = st->header_len + skb_shinfo(skb)->gso_size;
  774. if (st->protocol == htons(ETH_P_IP))
  775. st->ipv4_id = ntohs(ip_hdr(skb)->id);
  776. else
  777. st->ipv4_id = 0;
  778. st->seqnum = ntohl(tcp_hdr(skb)->seq);
  779. EFX_BUG_ON_PARANOID(tcp_hdr(skb)->urg);
  780. EFX_BUG_ON_PARANOID(tcp_hdr(skb)->syn);
  781. EFX_BUG_ON_PARANOID(tcp_hdr(skb)->rst);
  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 = dma_map_single(&efx->pci_dev->dev, skb->data + hl,
  806. len, DMA_TO_DEVICE);
  807. if (likely(!dma_mapping_error(&efx->pci_dev->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 DMA 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. netdev_tx_sent_queue(tx_queue->core_txq, skb->len);
  989. /* Pass off to hardware */
  990. efx_nic_push_buffers(tx_queue);
  991. tx_queue->tso_bursts++;
  992. return NETDEV_TX_OK;
  993. mem_err:
  994. netif_err(efx, tx_err, efx->net_dev,
  995. "Out of memory for TSO headers, or DMA mapping error\n");
  996. dev_kfree_skb_any(skb);
  997. unwind:
  998. /* Free the DMA mapping we were in the process of writing out */
  999. if (state.unmap_len) {
  1000. if (state.unmap_single)
  1001. dma_unmap_single(&efx->pci_dev->dev, state.unmap_addr,
  1002. state.unmap_len, DMA_TO_DEVICE);
  1003. else
  1004. dma_unmap_page(&efx->pci_dev->dev, state.unmap_addr,
  1005. state.unmap_len, DMA_TO_DEVICE);
  1006. }
  1007. efx_enqueue_unwind(tx_queue);
  1008. return rc2;
  1009. }
  1010. /*
  1011. * Free up all TSO datastructures associated with tx_queue. This
  1012. * routine should be called only once the tx_queue is both empty and
  1013. * will no longer be used.
  1014. */
  1015. static void efx_fini_tso(struct efx_tx_queue *tx_queue)
  1016. {
  1017. unsigned i;
  1018. if (tx_queue->buffer) {
  1019. for (i = 0; i <= tx_queue->ptr_mask; ++i)
  1020. efx_tsoh_free(tx_queue, &tx_queue->buffer[i]);
  1021. }
  1022. while (tx_queue->tso_headers_free != NULL)
  1023. efx_tsoh_block_free(tx_queue, tx_queue->tso_headers_free,
  1024. &tx_queue->efx->pci_dev->dev);
  1025. }