tx.c 32 KB

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