tx.c 33 KB

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