en_tx.c 32 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185
  1. /*
  2. * Copyright (c) 2007 Mellanox Technologies. All rights reserved.
  3. *
  4. * This software is available to you under a choice of one of two
  5. * licenses. You may choose to be licensed under the terms of the GNU
  6. * General Public License (GPL) Version 2, available from the file
  7. * COPYING in the main directory of this source tree, or the
  8. * OpenIB.org BSD license below:
  9. *
  10. * Redistribution and use in source and binary forms, with or
  11. * without modification, are permitted provided that the following
  12. * conditions are met:
  13. *
  14. * - Redistributions of source code must retain the above
  15. * copyright notice, this list of conditions and the following
  16. * disclaimer.
  17. *
  18. * - Redistributions in binary form must reproduce the above
  19. * copyright notice, this list of conditions and the following
  20. * disclaimer in the documentation and/or other materials
  21. * provided with the distribution.
  22. *
  23. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  24. * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  25. * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  26. * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
  27. * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
  28. * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
  29. * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
  30. * SOFTWARE.
  31. *
  32. */
  33. #include <asm/page.h>
  34. #include <linux/mlx4/cq.h>
  35. #include <linux/slab.h>
  36. #include <linux/mlx4/qp.h>
  37. #include <linux/skbuff.h>
  38. #include <linux/if_vlan.h>
  39. #include <linux/prefetch.h>
  40. #include <linux/vmalloc.h>
  41. #include <linux/tcp.h>
  42. #include <linux/ip.h>
  43. #include <linux/ipv6.h>
  44. #include <linux/moduleparam.h>
  45. #include "mlx4_en.h"
  46. int mlx4_en_create_tx_ring(struct mlx4_en_priv *priv,
  47. struct mlx4_en_tx_ring **pring, u32 size,
  48. u16 stride, int node, int queue_index)
  49. {
  50. struct mlx4_en_dev *mdev = priv->mdev;
  51. struct mlx4_en_tx_ring *ring;
  52. int tmp;
  53. int err;
  54. ring = kzalloc_node(sizeof(*ring), GFP_KERNEL, node);
  55. if (!ring) {
  56. ring = kzalloc(sizeof(*ring), GFP_KERNEL);
  57. if (!ring) {
  58. en_err(priv, "Failed allocating TX ring\n");
  59. return -ENOMEM;
  60. }
  61. }
  62. ring->size = size;
  63. ring->size_mask = size - 1;
  64. ring->stride = stride;
  65. ring->full_size = ring->size - HEADROOM - MAX_DESC_TXBBS;
  66. tmp = size * sizeof(struct mlx4_en_tx_info);
  67. ring->tx_info = kmalloc_node(tmp, GFP_KERNEL | __GFP_NOWARN, node);
  68. if (!ring->tx_info) {
  69. ring->tx_info = vmalloc(tmp);
  70. if (!ring->tx_info) {
  71. err = -ENOMEM;
  72. goto err_ring;
  73. }
  74. }
  75. en_dbg(DRV, priv, "Allocated tx_info ring at addr:%p size:%d\n",
  76. ring->tx_info, tmp);
  77. ring->bounce_buf = kmalloc_node(MAX_DESC_SIZE, GFP_KERNEL, node);
  78. if (!ring->bounce_buf) {
  79. ring->bounce_buf = kmalloc(MAX_DESC_SIZE, GFP_KERNEL);
  80. if (!ring->bounce_buf) {
  81. err = -ENOMEM;
  82. goto err_info;
  83. }
  84. }
  85. ring->buf_size = ALIGN(size * ring->stride, MLX4_EN_PAGE_SIZE);
  86. /* Allocate HW buffers on provided NUMA node */
  87. set_dev_node(&mdev->dev->persist->pdev->dev, node);
  88. err = mlx4_alloc_hwq_res(mdev->dev, &ring->wqres, ring->buf_size);
  89. set_dev_node(&mdev->dev->persist->pdev->dev, mdev->dev->numa_node);
  90. if (err) {
  91. en_err(priv, "Failed allocating hwq resources\n");
  92. goto err_bounce;
  93. }
  94. ring->buf = ring->wqres.buf.direct.buf;
  95. en_dbg(DRV, priv, "Allocated TX ring (addr:%p) - buf:%p size:%d buf_size:%d dma:%llx\n",
  96. ring, ring->buf, ring->size, ring->buf_size,
  97. (unsigned long long) ring->wqres.buf.direct.map);
  98. err = mlx4_qp_reserve_range(mdev->dev, 1, 1, &ring->qpn,
  99. MLX4_RESERVE_ETH_BF_QP);
  100. if (err) {
  101. en_err(priv, "failed reserving qp for TX ring\n");
  102. goto err_hwq_res;
  103. }
  104. err = mlx4_qp_alloc(mdev->dev, ring->qpn, &ring->qp, GFP_KERNEL);
  105. if (err) {
  106. en_err(priv, "Failed allocating qp %d\n", ring->qpn);
  107. goto err_reserve;
  108. }
  109. ring->qp.event = mlx4_en_sqp_event;
  110. err = mlx4_bf_alloc(mdev->dev, &ring->bf, node);
  111. if (err) {
  112. en_dbg(DRV, priv, "working without blueflame (%d)\n", err);
  113. ring->bf.uar = &mdev->priv_uar;
  114. ring->bf.uar->map = mdev->uar_map;
  115. ring->bf_enabled = false;
  116. ring->bf_alloced = false;
  117. priv->pflags &= ~MLX4_EN_PRIV_FLAGS_BLUEFLAME;
  118. } else {
  119. ring->bf_alloced = true;
  120. ring->bf_enabled = !!(priv->pflags &
  121. MLX4_EN_PRIV_FLAGS_BLUEFLAME);
  122. }
  123. ring->hwtstamp_tx_type = priv->hwtstamp_config.tx_type;
  124. ring->queue_index = queue_index;
  125. if (queue_index < priv->num_tx_rings_p_up)
  126. cpumask_set_cpu(cpumask_local_spread(queue_index,
  127. priv->mdev->dev->numa_node),
  128. &ring->affinity_mask);
  129. *pring = ring;
  130. return 0;
  131. err_reserve:
  132. mlx4_qp_release_range(mdev->dev, ring->qpn, 1);
  133. err_hwq_res:
  134. mlx4_free_hwq_res(mdev->dev, &ring->wqres, ring->buf_size);
  135. err_bounce:
  136. kfree(ring->bounce_buf);
  137. ring->bounce_buf = NULL;
  138. err_info:
  139. kvfree(ring->tx_info);
  140. ring->tx_info = NULL;
  141. err_ring:
  142. kfree(ring);
  143. *pring = NULL;
  144. return err;
  145. }
  146. void mlx4_en_destroy_tx_ring(struct mlx4_en_priv *priv,
  147. struct mlx4_en_tx_ring **pring)
  148. {
  149. struct mlx4_en_dev *mdev = priv->mdev;
  150. struct mlx4_en_tx_ring *ring = *pring;
  151. en_dbg(DRV, priv, "Destroying tx ring, qpn: %d\n", ring->qpn);
  152. if (ring->bf_alloced)
  153. mlx4_bf_free(mdev->dev, &ring->bf);
  154. mlx4_qp_remove(mdev->dev, &ring->qp);
  155. mlx4_qp_free(mdev->dev, &ring->qp);
  156. mlx4_qp_release_range(priv->mdev->dev, ring->qpn, 1);
  157. mlx4_free_hwq_res(mdev->dev, &ring->wqres, ring->buf_size);
  158. kfree(ring->bounce_buf);
  159. ring->bounce_buf = NULL;
  160. kvfree(ring->tx_info);
  161. ring->tx_info = NULL;
  162. kfree(ring);
  163. *pring = NULL;
  164. }
  165. int mlx4_en_activate_tx_ring(struct mlx4_en_priv *priv,
  166. struct mlx4_en_tx_ring *ring,
  167. int cq, int user_prio)
  168. {
  169. struct mlx4_en_dev *mdev = priv->mdev;
  170. int err;
  171. ring->cqn = cq;
  172. ring->prod = 0;
  173. ring->cons = 0xffffffff;
  174. ring->last_nr_txbb = 1;
  175. memset(ring->tx_info, 0, ring->size * sizeof(struct mlx4_en_tx_info));
  176. memset(ring->buf, 0, ring->buf_size);
  177. ring->free_tx_desc = mlx4_en_free_tx_desc;
  178. ring->qp_state = MLX4_QP_STATE_RST;
  179. ring->doorbell_qpn = cpu_to_be32(ring->qp.qpn << 8);
  180. ring->mr_key = cpu_to_be32(mdev->mr.key);
  181. mlx4_en_fill_qp_context(priv, ring->size, ring->stride, 1, 0, ring->qpn,
  182. ring->cqn, user_prio, &ring->context);
  183. if (ring->bf_alloced)
  184. ring->context.usr_page =
  185. cpu_to_be32(mlx4_to_hw_uar_index(mdev->dev,
  186. ring->bf.uar->index));
  187. err = mlx4_qp_to_ready(mdev->dev, &ring->wqres.mtt, &ring->context,
  188. &ring->qp, &ring->qp_state);
  189. if (!cpumask_empty(&ring->affinity_mask))
  190. netif_set_xps_queue(priv->dev, &ring->affinity_mask,
  191. ring->queue_index);
  192. return err;
  193. }
  194. void mlx4_en_deactivate_tx_ring(struct mlx4_en_priv *priv,
  195. struct mlx4_en_tx_ring *ring)
  196. {
  197. struct mlx4_en_dev *mdev = priv->mdev;
  198. mlx4_qp_modify(mdev->dev, NULL, ring->qp_state,
  199. MLX4_QP_STATE_RST, NULL, 0, 0, &ring->qp);
  200. }
  201. static inline bool mlx4_en_is_tx_ring_full(struct mlx4_en_tx_ring *ring)
  202. {
  203. return ring->prod - ring->cons > ring->full_size;
  204. }
  205. static void mlx4_en_stamp_wqe(struct mlx4_en_priv *priv,
  206. struct mlx4_en_tx_ring *ring, int index,
  207. u8 owner)
  208. {
  209. __be32 stamp = cpu_to_be32(STAMP_VAL | (!!owner << STAMP_SHIFT));
  210. struct mlx4_en_tx_desc *tx_desc = ring->buf + index * TXBB_SIZE;
  211. struct mlx4_en_tx_info *tx_info = &ring->tx_info[index];
  212. void *end = ring->buf + ring->buf_size;
  213. __be32 *ptr = (__be32 *)tx_desc;
  214. int i;
  215. /* Optimize the common case when there are no wraparounds */
  216. if (likely((void *)tx_desc + tx_info->nr_txbb * TXBB_SIZE <= end)) {
  217. /* Stamp the freed descriptor */
  218. for (i = 0; i < tx_info->nr_txbb * TXBB_SIZE;
  219. i += STAMP_STRIDE) {
  220. *ptr = stamp;
  221. ptr += STAMP_DWORDS;
  222. }
  223. } else {
  224. /* Stamp the freed descriptor */
  225. for (i = 0; i < tx_info->nr_txbb * TXBB_SIZE;
  226. i += STAMP_STRIDE) {
  227. *ptr = stamp;
  228. ptr += STAMP_DWORDS;
  229. if ((void *)ptr >= end) {
  230. ptr = ring->buf;
  231. stamp ^= cpu_to_be32(0x80000000);
  232. }
  233. }
  234. }
  235. }
  236. u32 mlx4_en_free_tx_desc(struct mlx4_en_priv *priv,
  237. struct mlx4_en_tx_ring *ring,
  238. int index, u8 owner, u64 timestamp,
  239. int napi_mode)
  240. {
  241. struct mlx4_en_tx_info *tx_info = &ring->tx_info[index];
  242. struct mlx4_en_tx_desc *tx_desc = ring->buf + index * TXBB_SIZE;
  243. struct mlx4_wqe_data_seg *data = (void *) tx_desc + tx_info->data_offset;
  244. void *end = ring->buf + ring->buf_size;
  245. struct sk_buff *skb = tx_info->skb;
  246. int nr_maps = tx_info->nr_maps;
  247. int i;
  248. /* We do not touch skb here, so prefetch skb->users location
  249. * to speedup consume_skb()
  250. */
  251. prefetchw(&skb->users);
  252. if (unlikely(timestamp)) {
  253. struct skb_shared_hwtstamps hwts;
  254. mlx4_en_fill_hwtstamps(priv->mdev, &hwts, timestamp);
  255. skb_tstamp_tx(skb, &hwts);
  256. }
  257. /* Optimize the common case when there are no wraparounds */
  258. if (likely((void *) tx_desc + tx_info->nr_txbb * TXBB_SIZE <= end)) {
  259. if (!tx_info->inl) {
  260. if (tx_info->linear)
  261. dma_unmap_single(priv->ddev,
  262. tx_info->map0_dma,
  263. tx_info->map0_byte_count,
  264. PCI_DMA_TODEVICE);
  265. else
  266. dma_unmap_page(priv->ddev,
  267. tx_info->map0_dma,
  268. tx_info->map0_byte_count,
  269. PCI_DMA_TODEVICE);
  270. for (i = 1; i < nr_maps; i++) {
  271. data++;
  272. dma_unmap_page(priv->ddev,
  273. (dma_addr_t)be64_to_cpu(data->addr),
  274. be32_to_cpu(data->byte_count),
  275. PCI_DMA_TODEVICE);
  276. }
  277. }
  278. } else {
  279. if (!tx_info->inl) {
  280. if ((void *) data >= end) {
  281. data = ring->buf + ((void *)data - end);
  282. }
  283. if (tx_info->linear)
  284. dma_unmap_single(priv->ddev,
  285. tx_info->map0_dma,
  286. tx_info->map0_byte_count,
  287. PCI_DMA_TODEVICE);
  288. else
  289. dma_unmap_page(priv->ddev,
  290. tx_info->map0_dma,
  291. tx_info->map0_byte_count,
  292. PCI_DMA_TODEVICE);
  293. for (i = 1; i < nr_maps; i++) {
  294. data++;
  295. /* Check for wraparound before unmapping */
  296. if ((void *) data >= end)
  297. data = ring->buf;
  298. dma_unmap_page(priv->ddev,
  299. (dma_addr_t)be64_to_cpu(data->addr),
  300. be32_to_cpu(data->byte_count),
  301. PCI_DMA_TODEVICE);
  302. }
  303. }
  304. }
  305. napi_consume_skb(skb, napi_mode);
  306. return tx_info->nr_txbb;
  307. }
  308. u32 mlx4_en_recycle_tx_desc(struct mlx4_en_priv *priv,
  309. struct mlx4_en_tx_ring *ring,
  310. int index, u8 owner, u64 timestamp,
  311. int napi_mode)
  312. {
  313. struct mlx4_en_tx_info *tx_info = &ring->tx_info[index];
  314. struct mlx4_en_rx_alloc frame = {
  315. .page = tx_info->page,
  316. .dma = tx_info->map0_dma,
  317. .page_offset = 0,
  318. .page_size = PAGE_SIZE,
  319. };
  320. if (!mlx4_en_rx_recycle(ring->recycle_ring, &frame)) {
  321. dma_unmap_page(priv->ddev, tx_info->map0_dma,
  322. PAGE_SIZE, priv->frag_info[0].dma_dir);
  323. put_page(tx_info->page);
  324. }
  325. return tx_info->nr_txbb;
  326. }
  327. int mlx4_en_free_tx_buf(struct net_device *dev, struct mlx4_en_tx_ring *ring)
  328. {
  329. struct mlx4_en_priv *priv = netdev_priv(dev);
  330. int cnt = 0;
  331. /* Skip last polled descriptor */
  332. ring->cons += ring->last_nr_txbb;
  333. en_dbg(DRV, priv, "Freeing Tx buf - cons:0x%x prod:0x%x\n",
  334. ring->cons, ring->prod);
  335. if ((u32) (ring->prod - ring->cons) > ring->size) {
  336. if (netif_msg_tx_err(priv))
  337. en_warn(priv, "Tx consumer passed producer!\n");
  338. return 0;
  339. }
  340. while (ring->cons != ring->prod) {
  341. ring->last_nr_txbb = ring->free_tx_desc(priv, ring,
  342. ring->cons & ring->size_mask,
  343. !!(ring->cons & ring->size), 0,
  344. 0 /* Non-NAPI caller */);
  345. ring->cons += ring->last_nr_txbb;
  346. cnt++;
  347. }
  348. netdev_tx_reset_queue(ring->tx_queue);
  349. if (cnt)
  350. en_dbg(DRV, priv, "Freed %d uncompleted tx descriptors\n", cnt);
  351. return cnt;
  352. }
  353. static bool mlx4_en_process_tx_cq(struct net_device *dev,
  354. struct mlx4_en_cq *cq, int napi_budget)
  355. {
  356. struct mlx4_en_priv *priv = netdev_priv(dev);
  357. struct mlx4_cq *mcq = &cq->mcq;
  358. struct mlx4_en_tx_ring *ring = priv->tx_ring[cq->ring];
  359. struct mlx4_cqe *cqe;
  360. u16 index;
  361. u16 new_index, ring_index, stamp_index;
  362. u32 txbbs_skipped = 0;
  363. u32 txbbs_stamp = 0;
  364. u32 cons_index = mcq->cons_index;
  365. int size = cq->size;
  366. u32 size_mask = ring->size_mask;
  367. struct mlx4_cqe *buf = cq->buf;
  368. u32 packets = 0;
  369. u32 bytes = 0;
  370. int factor = priv->cqe_factor;
  371. int done = 0;
  372. int budget = priv->tx_work_limit;
  373. u32 last_nr_txbb;
  374. u32 ring_cons;
  375. if (!priv->port_up)
  376. return true;
  377. netdev_txq_bql_complete_prefetchw(ring->tx_queue);
  378. index = cons_index & size_mask;
  379. cqe = mlx4_en_get_cqe(buf, index, priv->cqe_size) + factor;
  380. last_nr_txbb = ACCESS_ONCE(ring->last_nr_txbb);
  381. ring_cons = ACCESS_ONCE(ring->cons);
  382. ring_index = ring_cons & size_mask;
  383. stamp_index = ring_index;
  384. /* Process all completed CQEs */
  385. while (XNOR(cqe->owner_sr_opcode & MLX4_CQE_OWNER_MASK,
  386. cons_index & size) && (done < budget)) {
  387. /*
  388. * make sure we read the CQE after we read the
  389. * ownership bit
  390. */
  391. dma_rmb();
  392. if (unlikely((cqe->owner_sr_opcode & MLX4_CQE_OPCODE_MASK) ==
  393. MLX4_CQE_OPCODE_ERROR)) {
  394. struct mlx4_err_cqe *cqe_err = (struct mlx4_err_cqe *)cqe;
  395. en_err(priv, "CQE error - vendor syndrome: 0x%x syndrome: 0x%x\n",
  396. cqe_err->vendor_err_syndrome,
  397. cqe_err->syndrome);
  398. }
  399. /* Skip over last polled CQE */
  400. new_index = be16_to_cpu(cqe->wqe_index) & size_mask;
  401. do {
  402. u64 timestamp = 0;
  403. txbbs_skipped += last_nr_txbb;
  404. ring_index = (ring_index + last_nr_txbb) & size_mask;
  405. if (unlikely(ring->tx_info[ring_index].ts_requested))
  406. timestamp = mlx4_en_get_cqe_ts(cqe);
  407. /* free next descriptor */
  408. last_nr_txbb = ring->free_tx_desc(
  409. priv, ring, ring_index,
  410. !!((ring_cons + txbbs_skipped) &
  411. ring->size), timestamp, napi_budget);
  412. mlx4_en_stamp_wqe(priv, ring, stamp_index,
  413. !!((ring_cons + txbbs_stamp) &
  414. ring->size));
  415. stamp_index = ring_index;
  416. txbbs_stamp = txbbs_skipped;
  417. packets++;
  418. bytes += ring->tx_info[ring_index].nr_bytes;
  419. } while ((++done < budget) && (ring_index != new_index));
  420. ++cons_index;
  421. index = cons_index & size_mask;
  422. cqe = mlx4_en_get_cqe(buf, index, priv->cqe_size) + factor;
  423. }
  424. /*
  425. * To prevent CQ overflow we first update CQ consumer and only then
  426. * the ring consumer.
  427. */
  428. mcq->cons_index = cons_index;
  429. mlx4_cq_set_ci(mcq);
  430. wmb();
  431. /* we want to dirty this cache line once */
  432. ACCESS_ONCE(ring->last_nr_txbb) = last_nr_txbb;
  433. ACCESS_ONCE(ring->cons) = ring_cons + txbbs_skipped;
  434. if (ring->free_tx_desc == mlx4_en_recycle_tx_desc)
  435. return done < budget;
  436. netdev_tx_completed_queue(ring->tx_queue, packets, bytes);
  437. /* Wakeup Tx queue if this stopped, and ring is not full.
  438. */
  439. if (netif_tx_queue_stopped(ring->tx_queue) &&
  440. !mlx4_en_is_tx_ring_full(ring)) {
  441. netif_tx_wake_queue(ring->tx_queue);
  442. ring->wake_queue++;
  443. }
  444. return done < budget;
  445. }
  446. void mlx4_en_tx_irq(struct mlx4_cq *mcq)
  447. {
  448. struct mlx4_en_cq *cq = container_of(mcq, struct mlx4_en_cq, mcq);
  449. struct mlx4_en_priv *priv = netdev_priv(cq->dev);
  450. if (likely(priv->port_up))
  451. napi_schedule_irqoff(&cq->napi);
  452. else
  453. mlx4_en_arm_cq(priv, cq);
  454. }
  455. /* TX CQ polling - called by NAPI */
  456. int mlx4_en_poll_tx_cq(struct napi_struct *napi, int budget)
  457. {
  458. struct mlx4_en_cq *cq = container_of(napi, struct mlx4_en_cq, napi);
  459. struct net_device *dev = cq->dev;
  460. struct mlx4_en_priv *priv = netdev_priv(dev);
  461. int clean_complete;
  462. clean_complete = mlx4_en_process_tx_cq(dev, cq, budget);
  463. if (!clean_complete)
  464. return budget;
  465. napi_complete(napi);
  466. mlx4_en_arm_cq(priv, cq);
  467. return 0;
  468. }
  469. static struct mlx4_en_tx_desc *mlx4_en_bounce_to_desc(struct mlx4_en_priv *priv,
  470. struct mlx4_en_tx_ring *ring,
  471. u32 index,
  472. unsigned int desc_size)
  473. {
  474. u32 copy = (ring->size - index) * TXBB_SIZE;
  475. int i;
  476. for (i = desc_size - copy - 4; i >= 0; i -= 4) {
  477. if ((i & (TXBB_SIZE - 1)) == 0)
  478. wmb();
  479. *((u32 *) (ring->buf + i)) =
  480. *((u32 *) (ring->bounce_buf + copy + i));
  481. }
  482. for (i = copy - 4; i >= 4 ; i -= 4) {
  483. if ((i & (TXBB_SIZE - 1)) == 0)
  484. wmb();
  485. *((u32 *) (ring->buf + index * TXBB_SIZE + i)) =
  486. *((u32 *) (ring->bounce_buf + i));
  487. }
  488. /* Return real descriptor location */
  489. return ring->buf + index * TXBB_SIZE;
  490. }
  491. /* Decide if skb can be inlined in tx descriptor to avoid dma mapping
  492. *
  493. * It seems strange we do not simply use skb_copy_bits().
  494. * This would allow to inline all skbs iff skb->len <= inline_thold
  495. *
  496. * Note that caller already checked skb was not a gso packet
  497. */
  498. static bool is_inline(int inline_thold, const struct sk_buff *skb,
  499. const struct skb_shared_info *shinfo,
  500. void **pfrag)
  501. {
  502. void *ptr;
  503. if (skb->len > inline_thold || !inline_thold)
  504. return false;
  505. if (shinfo->nr_frags == 1) {
  506. ptr = skb_frag_address_safe(&shinfo->frags[0]);
  507. if (unlikely(!ptr))
  508. return false;
  509. *pfrag = ptr;
  510. return true;
  511. }
  512. if (shinfo->nr_frags)
  513. return false;
  514. return true;
  515. }
  516. static int inline_size(const struct sk_buff *skb)
  517. {
  518. if (skb->len + CTRL_SIZE + sizeof(struct mlx4_wqe_inline_seg)
  519. <= MLX4_INLINE_ALIGN)
  520. return ALIGN(skb->len + CTRL_SIZE +
  521. sizeof(struct mlx4_wqe_inline_seg), 16);
  522. else
  523. return ALIGN(skb->len + CTRL_SIZE + 2 *
  524. sizeof(struct mlx4_wqe_inline_seg), 16);
  525. }
  526. static int get_real_size(const struct sk_buff *skb,
  527. const struct skb_shared_info *shinfo,
  528. struct net_device *dev,
  529. int *lso_header_size,
  530. bool *inline_ok,
  531. void **pfrag)
  532. {
  533. struct mlx4_en_priv *priv = netdev_priv(dev);
  534. int real_size;
  535. if (shinfo->gso_size) {
  536. *inline_ok = false;
  537. if (skb->encapsulation)
  538. *lso_header_size = (skb_inner_transport_header(skb) - skb->data) + inner_tcp_hdrlen(skb);
  539. else
  540. *lso_header_size = skb_transport_offset(skb) + tcp_hdrlen(skb);
  541. real_size = CTRL_SIZE + shinfo->nr_frags * DS_SIZE +
  542. ALIGN(*lso_header_size + 4, DS_SIZE);
  543. if (unlikely(*lso_header_size != skb_headlen(skb))) {
  544. /* We add a segment for the skb linear buffer only if
  545. * it contains data */
  546. if (*lso_header_size < skb_headlen(skb))
  547. real_size += DS_SIZE;
  548. else {
  549. if (netif_msg_tx_err(priv))
  550. en_warn(priv, "Non-linear headers\n");
  551. return 0;
  552. }
  553. }
  554. } else {
  555. *lso_header_size = 0;
  556. *inline_ok = is_inline(priv->prof->inline_thold, skb,
  557. shinfo, pfrag);
  558. if (*inline_ok)
  559. real_size = inline_size(skb);
  560. else
  561. real_size = CTRL_SIZE +
  562. (shinfo->nr_frags + 1) * DS_SIZE;
  563. }
  564. return real_size;
  565. }
  566. static void build_inline_wqe(struct mlx4_en_tx_desc *tx_desc,
  567. const struct sk_buff *skb,
  568. const struct skb_shared_info *shinfo,
  569. void *fragptr)
  570. {
  571. struct mlx4_wqe_inline_seg *inl = &tx_desc->inl;
  572. int spc = MLX4_INLINE_ALIGN - CTRL_SIZE - sizeof *inl;
  573. unsigned int hlen = skb_headlen(skb);
  574. if (skb->len <= spc) {
  575. if (likely(skb->len >= MIN_PKT_LEN)) {
  576. inl->byte_count = cpu_to_be32(1 << 31 | skb->len);
  577. } else {
  578. inl->byte_count = cpu_to_be32(1 << 31 | MIN_PKT_LEN);
  579. memset(((void *)(inl + 1)) + skb->len, 0,
  580. MIN_PKT_LEN - skb->len);
  581. }
  582. skb_copy_from_linear_data(skb, inl + 1, hlen);
  583. if (shinfo->nr_frags)
  584. memcpy(((void *)(inl + 1)) + hlen, fragptr,
  585. skb_frag_size(&shinfo->frags[0]));
  586. } else {
  587. inl->byte_count = cpu_to_be32(1 << 31 | spc);
  588. if (hlen <= spc) {
  589. skb_copy_from_linear_data(skb, inl + 1, hlen);
  590. if (hlen < spc) {
  591. memcpy(((void *)(inl + 1)) + hlen,
  592. fragptr, spc - hlen);
  593. fragptr += spc - hlen;
  594. }
  595. inl = (void *) (inl + 1) + spc;
  596. memcpy(((void *)(inl + 1)), fragptr, skb->len - spc);
  597. } else {
  598. skb_copy_from_linear_data(skb, inl + 1, spc);
  599. inl = (void *) (inl + 1) + spc;
  600. skb_copy_from_linear_data_offset(skb, spc, inl + 1,
  601. hlen - spc);
  602. if (shinfo->nr_frags)
  603. memcpy(((void *)(inl + 1)) + hlen - spc,
  604. fragptr,
  605. skb_frag_size(&shinfo->frags[0]));
  606. }
  607. dma_wmb();
  608. inl->byte_count = cpu_to_be32(1 << 31 | (skb->len - spc));
  609. }
  610. }
  611. u16 mlx4_en_select_queue(struct net_device *dev, struct sk_buff *skb,
  612. void *accel_priv, select_queue_fallback_t fallback)
  613. {
  614. struct mlx4_en_priv *priv = netdev_priv(dev);
  615. u16 rings_p_up = priv->num_tx_rings_p_up;
  616. u8 up = 0;
  617. if (dev->num_tc)
  618. return skb_tx_hash(dev, skb);
  619. if (skb_vlan_tag_present(skb))
  620. up = skb_vlan_tag_get(skb) >> VLAN_PRIO_SHIFT;
  621. return fallback(dev, skb) % rings_p_up + up * rings_p_up;
  622. }
  623. static void mlx4_bf_copy(void __iomem *dst, const void *src,
  624. unsigned int bytecnt)
  625. {
  626. __iowrite64_copy(dst, src, bytecnt / 8);
  627. }
  628. void mlx4_en_xmit_doorbell(struct mlx4_en_tx_ring *ring)
  629. {
  630. wmb();
  631. /* Since there is no iowrite*_native() that writes the
  632. * value as is, without byteswapping - using the one
  633. * the doesn't do byteswapping in the relevant arch
  634. * endianness.
  635. */
  636. #if defined(__LITTLE_ENDIAN)
  637. iowrite32(
  638. #else
  639. iowrite32be(
  640. #endif
  641. ring->doorbell_qpn,
  642. ring->bf.uar->map + MLX4_SEND_DOORBELL);
  643. }
  644. static void mlx4_en_tx_write_desc(struct mlx4_en_tx_ring *ring,
  645. struct mlx4_en_tx_desc *tx_desc,
  646. union mlx4_wqe_qpn_vlan qpn_vlan,
  647. int desc_size, int bf_index,
  648. __be32 op_own, bool bf_ok,
  649. bool send_doorbell)
  650. {
  651. tx_desc->ctrl.qpn_vlan = qpn_vlan;
  652. if (bf_ok) {
  653. op_own |= htonl((bf_index & 0xffff) << 8);
  654. /* Ensure new descriptor hits memory
  655. * before setting ownership of this descriptor to HW
  656. */
  657. dma_wmb();
  658. tx_desc->ctrl.owner_opcode = op_own;
  659. wmb();
  660. mlx4_bf_copy(ring->bf.reg + ring->bf.offset, &tx_desc->ctrl,
  661. desc_size);
  662. wmb();
  663. ring->bf.offset ^= ring->bf.buf_size;
  664. } else {
  665. /* Ensure new descriptor hits memory
  666. * before setting ownership of this descriptor to HW
  667. */
  668. dma_wmb();
  669. tx_desc->ctrl.owner_opcode = op_own;
  670. if (send_doorbell)
  671. mlx4_en_xmit_doorbell(ring);
  672. else
  673. ring->xmit_more++;
  674. }
  675. }
  676. netdev_tx_t mlx4_en_xmit(struct sk_buff *skb, struct net_device *dev)
  677. {
  678. struct skb_shared_info *shinfo = skb_shinfo(skb);
  679. struct mlx4_en_priv *priv = netdev_priv(dev);
  680. union mlx4_wqe_qpn_vlan qpn_vlan = {};
  681. struct device *ddev = priv->ddev;
  682. struct mlx4_en_tx_ring *ring;
  683. struct mlx4_en_tx_desc *tx_desc;
  684. struct mlx4_wqe_data_seg *data;
  685. struct mlx4_en_tx_info *tx_info;
  686. int tx_ind = 0;
  687. int nr_txbb;
  688. int desc_size;
  689. int real_size;
  690. u32 index, bf_index;
  691. __be32 op_own;
  692. u16 vlan_proto = 0;
  693. int i_frag;
  694. int lso_header_size;
  695. void *fragptr = NULL;
  696. bool bounce = false;
  697. bool send_doorbell;
  698. bool stop_queue;
  699. bool inline_ok;
  700. u32 ring_cons;
  701. bool bf_ok;
  702. tx_ind = skb_get_queue_mapping(skb);
  703. ring = priv->tx_ring[tx_ind];
  704. if (!priv->port_up)
  705. goto tx_drop;
  706. /* fetch ring->cons far ahead before needing it to avoid stall */
  707. ring_cons = ACCESS_ONCE(ring->cons);
  708. real_size = get_real_size(skb, shinfo, dev, &lso_header_size,
  709. &inline_ok, &fragptr);
  710. if (unlikely(!real_size))
  711. goto tx_drop_count;
  712. /* Align descriptor to TXBB size */
  713. desc_size = ALIGN(real_size, TXBB_SIZE);
  714. nr_txbb = desc_size / TXBB_SIZE;
  715. if (unlikely(nr_txbb > MAX_DESC_TXBBS)) {
  716. if (netif_msg_tx_err(priv))
  717. en_warn(priv, "Oversized header or SG list\n");
  718. goto tx_drop_count;
  719. }
  720. bf_ok = ring->bf_enabled;
  721. if (skb_vlan_tag_present(skb)) {
  722. qpn_vlan.vlan_tag = cpu_to_be16(skb_vlan_tag_get(skb));
  723. vlan_proto = be16_to_cpu(skb->vlan_proto);
  724. if (vlan_proto == ETH_P_8021AD)
  725. qpn_vlan.ins_vlan = MLX4_WQE_CTRL_INS_SVLAN;
  726. else if (vlan_proto == ETH_P_8021Q)
  727. qpn_vlan.ins_vlan = MLX4_WQE_CTRL_INS_CVLAN;
  728. else
  729. qpn_vlan.ins_vlan = 0;
  730. bf_ok = false;
  731. }
  732. netdev_txq_bql_enqueue_prefetchw(ring->tx_queue);
  733. /* Track current inflight packets for performance analysis */
  734. AVG_PERF_COUNTER(priv->pstats.inflight_avg,
  735. (u32)(ring->prod - ring_cons - 1));
  736. /* Packet is good - grab an index and transmit it */
  737. index = ring->prod & ring->size_mask;
  738. bf_index = ring->prod;
  739. /* See if we have enough space for whole descriptor TXBB for setting
  740. * SW ownership on next descriptor; if not, use a bounce buffer. */
  741. if (likely(index + nr_txbb <= ring->size))
  742. tx_desc = ring->buf + index * TXBB_SIZE;
  743. else {
  744. tx_desc = (struct mlx4_en_tx_desc *) ring->bounce_buf;
  745. bounce = true;
  746. bf_ok = false;
  747. }
  748. /* Save skb in tx_info ring */
  749. tx_info = &ring->tx_info[index];
  750. tx_info->skb = skb;
  751. tx_info->nr_txbb = nr_txbb;
  752. data = &tx_desc->data;
  753. if (lso_header_size)
  754. data = ((void *)&tx_desc->lso + ALIGN(lso_header_size + 4,
  755. DS_SIZE));
  756. /* valid only for none inline segments */
  757. tx_info->data_offset = (void *)data - (void *)tx_desc;
  758. tx_info->inl = inline_ok;
  759. tx_info->linear = (lso_header_size < skb_headlen(skb) &&
  760. !inline_ok) ? 1 : 0;
  761. tx_info->nr_maps = shinfo->nr_frags + tx_info->linear;
  762. data += tx_info->nr_maps - 1;
  763. if (!tx_info->inl) {
  764. dma_addr_t dma = 0;
  765. u32 byte_count = 0;
  766. /* Map fragments if any */
  767. for (i_frag = shinfo->nr_frags - 1; i_frag >= 0; i_frag--) {
  768. const struct skb_frag_struct *frag;
  769. frag = &shinfo->frags[i_frag];
  770. byte_count = skb_frag_size(frag);
  771. dma = skb_frag_dma_map(ddev, frag,
  772. 0, byte_count,
  773. DMA_TO_DEVICE);
  774. if (dma_mapping_error(ddev, dma))
  775. goto tx_drop_unmap;
  776. data->addr = cpu_to_be64(dma);
  777. data->lkey = ring->mr_key;
  778. dma_wmb();
  779. data->byte_count = cpu_to_be32(byte_count);
  780. --data;
  781. }
  782. /* Map linear part if needed */
  783. if (tx_info->linear) {
  784. byte_count = skb_headlen(skb) - lso_header_size;
  785. dma = dma_map_single(ddev, skb->data +
  786. lso_header_size, byte_count,
  787. PCI_DMA_TODEVICE);
  788. if (dma_mapping_error(ddev, dma))
  789. goto tx_drop_unmap;
  790. data->addr = cpu_to_be64(dma);
  791. data->lkey = ring->mr_key;
  792. dma_wmb();
  793. data->byte_count = cpu_to_be32(byte_count);
  794. }
  795. /* tx completion can avoid cache line miss for common cases */
  796. tx_info->map0_dma = dma;
  797. tx_info->map0_byte_count = byte_count;
  798. }
  799. /*
  800. * For timestamping add flag to skb_shinfo and
  801. * set flag for further reference
  802. */
  803. tx_info->ts_requested = 0;
  804. if (unlikely(ring->hwtstamp_tx_type == HWTSTAMP_TX_ON &&
  805. shinfo->tx_flags & SKBTX_HW_TSTAMP)) {
  806. shinfo->tx_flags |= SKBTX_IN_PROGRESS;
  807. tx_info->ts_requested = 1;
  808. }
  809. /* Prepare ctrl segement apart opcode+ownership, which depends on
  810. * whether LSO is used */
  811. tx_desc->ctrl.srcrb_flags = priv->ctrl_flags;
  812. if (likely(skb->ip_summed == CHECKSUM_PARTIAL)) {
  813. if (!skb->encapsulation)
  814. tx_desc->ctrl.srcrb_flags |= cpu_to_be32(MLX4_WQE_CTRL_IP_CSUM |
  815. MLX4_WQE_CTRL_TCP_UDP_CSUM);
  816. else
  817. tx_desc->ctrl.srcrb_flags |= cpu_to_be32(MLX4_WQE_CTRL_IP_CSUM);
  818. ring->tx_csum++;
  819. }
  820. if (priv->flags & MLX4_EN_FLAG_ENABLE_HW_LOOPBACK) {
  821. struct ethhdr *ethh;
  822. /* Copy dst mac address to wqe. This allows loopback in eSwitch,
  823. * so that VFs and PF can communicate with each other
  824. */
  825. ethh = (struct ethhdr *)skb->data;
  826. tx_desc->ctrl.srcrb_flags16[0] = get_unaligned((__be16 *)ethh->h_dest);
  827. tx_desc->ctrl.imm = get_unaligned((__be32 *)(ethh->h_dest + 2));
  828. }
  829. /* Handle LSO (TSO) packets */
  830. if (lso_header_size) {
  831. int i;
  832. /* Mark opcode as LSO */
  833. op_own = cpu_to_be32(MLX4_OPCODE_LSO | (1 << 6)) |
  834. ((ring->prod & ring->size) ?
  835. cpu_to_be32(MLX4_EN_BIT_DESC_OWN) : 0);
  836. /* Fill in the LSO prefix */
  837. tx_desc->lso.mss_hdr_size = cpu_to_be32(
  838. shinfo->gso_size << 16 | lso_header_size);
  839. /* Copy headers;
  840. * note that we already verified that it is linear */
  841. memcpy(tx_desc->lso.header, skb->data, lso_header_size);
  842. ring->tso_packets++;
  843. i = ((skb->len - lso_header_size) / shinfo->gso_size) +
  844. !!((skb->len - lso_header_size) % shinfo->gso_size);
  845. tx_info->nr_bytes = skb->len + (i - 1) * lso_header_size;
  846. ring->packets += i;
  847. } else {
  848. /* Normal (Non LSO) packet */
  849. op_own = cpu_to_be32(MLX4_OPCODE_SEND) |
  850. ((ring->prod & ring->size) ?
  851. cpu_to_be32(MLX4_EN_BIT_DESC_OWN) : 0);
  852. tx_info->nr_bytes = max_t(unsigned int, skb->len, ETH_ZLEN);
  853. ring->packets++;
  854. }
  855. ring->bytes += tx_info->nr_bytes;
  856. netdev_tx_sent_queue(ring->tx_queue, tx_info->nr_bytes);
  857. AVG_PERF_COUNTER(priv->pstats.tx_pktsz_avg, skb->len);
  858. if (tx_info->inl)
  859. build_inline_wqe(tx_desc, skb, shinfo, fragptr);
  860. if (skb->encapsulation) {
  861. union {
  862. struct iphdr *v4;
  863. struct ipv6hdr *v6;
  864. unsigned char *hdr;
  865. } ip;
  866. u8 proto;
  867. ip.hdr = skb_inner_network_header(skb);
  868. proto = (ip.v4->version == 4) ? ip.v4->protocol :
  869. ip.v6->nexthdr;
  870. if (proto == IPPROTO_TCP || proto == IPPROTO_UDP)
  871. op_own |= cpu_to_be32(MLX4_WQE_CTRL_IIP | MLX4_WQE_CTRL_ILP);
  872. else
  873. op_own |= cpu_to_be32(MLX4_WQE_CTRL_IIP);
  874. }
  875. ring->prod += nr_txbb;
  876. /* If we used a bounce buffer then copy descriptor back into place */
  877. if (unlikely(bounce))
  878. tx_desc = mlx4_en_bounce_to_desc(priv, ring, index, desc_size);
  879. skb_tx_timestamp(skb);
  880. /* Check available TXBBs And 2K spare for prefetch */
  881. stop_queue = mlx4_en_is_tx_ring_full(ring);
  882. if (unlikely(stop_queue)) {
  883. netif_tx_stop_queue(ring->tx_queue);
  884. ring->queue_stopped++;
  885. }
  886. send_doorbell = !skb->xmit_more || netif_xmit_stopped(ring->tx_queue);
  887. real_size = (real_size / 16) & 0x3f;
  888. bf_ok &= desc_size <= MAX_BF && send_doorbell;
  889. if (bf_ok)
  890. qpn_vlan.bf_qpn = ring->doorbell_qpn | cpu_to_be32(real_size);
  891. else
  892. qpn_vlan.fence_size = real_size;
  893. mlx4_en_tx_write_desc(ring, tx_desc, qpn_vlan, desc_size, bf_index,
  894. op_own, bf_ok, send_doorbell);
  895. if (unlikely(stop_queue)) {
  896. /* If queue was emptied after the if (stop_queue) , and before
  897. * the netif_tx_stop_queue() - need to wake the queue,
  898. * or else it will remain stopped forever.
  899. * Need a memory barrier to make sure ring->cons was not
  900. * updated before queue was stopped.
  901. */
  902. smp_rmb();
  903. ring_cons = ACCESS_ONCE(ring->cons);
  904. if (unlikely(!mlx4_en_is_tx_ring_full(ring))) {
  905. netif_tx_wake_queue(ring->tx_queue);
  906. ring->wake_queue++;
  907. }
  908. }
  909. return NETDEV_TX_OK;
  910. tx_drop_unmap:
  911. en_err(priv, "DMA mapping error\n");
  912. while (++i_frag < shinfo->nr_frags) {
  913. ++data;
  914. dma_unmap_page(ddev, (dma_addr_t) be64_to_cpu(data->addr),
  915. be32_to_cpu(data->byte_count),
  916. PCI_DMA_TODEVICE);
  917. }
  918. tx_drop_count:
  919. ring->tx_dropped++;
  920. tx_drop:
  921. dev_kfree_skb_any(skb);
  922. return NETDEV_TX_OK;
  923. }
  924. netdev_tx_t mlx4_en_xmit_frame(struct mlx4_en_rx_alloc *frame,
  925. struct net_device *dev, unsigned int length,
  926. int tx_ind, int *doorbell_pending)
  927. {
  928. struct mlx4_en_priv *priv = netdev_priv(dev);
  929. union mlx4_wqe_qpn_vlan qpn_vlan = {};
  930. struct mlx4_en_tx_ring *ring;
  931. struct mlx4_en_tx_desc *tx_desc;
  932. struct mlx4_wqe_data_seg *data;
  933. struct mlx4_en_tx_info *tx_info;
  934. int index, bf_index;
  935. bool send_doorbell;
  936. int nr_txbb = 1;
  937. bool stop_queue;
  938. dma_addr_t dma;
  939. int real_size;
  940. __be32 op_own;
  941. u32 ring_cons;
  942. bool bf_ok;
  943. BUILD_BUG_ON_MSG(ALIGN(CTRL_SIZE + DS_SIZE, TXBB_SIZE) != TXBB_SIZE,
  944. "mlx4_en_xmit_frame requires minimum size tx desc");
  945. ring = priv->tx_ring[tx_ind];
  946. if (!priv->port_up)
  947. goto tx_drop;
  948. if (mlx4_en_is_tx_ring_full(ring))
  949. goto tx_drop_count;
  950. /* fetch ring->cons far ahead before needing it to avoid stall */
  951. ring_cons = READ_ONCE(ring->cons);
  952. index = ring->prod & ring->size_mask;
  953. tx_info = &ring->tx_info[index];
  954. bf_ok = ring->bf_enabled;
  955. /* Track current inflight packets for performance analysis */
  956. AVG_PERF_COUNTER(priv->pstats.inflight_avg,
  957. (u32)(ring->prod - ring_cons - 1));
  958. bf_index = ring->prod;
  959. tx_desc = ring->buf + index * TXBB_SIZE;
  960. data = &tx_desc->data;
  961. dma = frame->dma;
  962. tx_info->page = frame->page;
  963. frame->page = NULL;
  964. tx_info->map0_dma = dma;
  965. tx_info->map0_byte_count = length;
  966. tx_info->nr_txbb = nr_txbb;
  967. tx_info->nr_bytes = max_t(unsigned int, length, ETH_ZLEN);
  968. tx_info->data_offset = (void *)data - (void *)tx_desc;
  969. tx_info->ts_requested = 0;
  970. tx_info->nr_maps = 1;
  971. tx_info->linear = 1;
  972. tx_info->inl = 0;
  973. dma_sync_single_for_device(priv->ddev, dma, length, PCI_DMA_TODEVICE);
  974. data->addr = cpu_to_be64(dma);
  975. data->lkey = ring->mr_key;
  976. dma_wmb();
  977. data->byte_count = cpu_to_be32(length);
  978. /* tx completion can avoid cache line miss for common cases */
  979. tx_desc->ctrl.srcrb_flags = priv->ctrl_flags;
  980. op_own = cpu_to_be32(MLX4_OPCODE_SEND) |
  981. ((ring->prod & ring->size) ?
  982. cpu_to_be32(MLX4_EN_BIT_DESC_OWN) : 0);
  983. ring->packets++;
  984. ring->bytes += tx_info->nr_bytes;
  985. AVG_PERF_COUNTER(priv->pstats.tx_pktsz_avg, length);
  986. ring->prod += nr_txbb;
  987. stop_queue = mlx4_en_is_tx_ring_full(ring);
  988. send_doorbell = stop_queue ||
  989. *doorbell_pending > MLX4_EN_DOORBELL_BUDGET;
  990. bf_ok &= send_doorbell;
  991. real_size = ((CTRL_SIZE + nr_txbb * DS_SIZE) / 16) & 0x3f;
  992. if (bf_ok)
  993. qpn_vlan.bf_qpn = ring->doorbell_qpn | cpu_to_be32(real_size);
  994. else
  995. qpn_vlan.fence_size = real_size;
  996. mlx4_en_tx_write_desc(ring, tx_desc, qpn_vlan, TXBB_SIZE, bf_index,
  997. op_own, bf_ok, send_doorbell);
  998. *doorbell_pending = send_doorbell ? 0 : *doorbell_pending + 1;
  999. return NETDEV_TX_OK;
  1000. tx_drop_count:
  1001. ring->tx_dropped++;
  1002. tx_drop:
  1003. return NETDEV_TX_BUSY;
  1004. }