1 // SPDX-License-Identifier: (GPL-2.0 OR BSD-3-Clause)
3 * Copyright(c) 2020 Intel Corporation.
8 * This file contains HFI1 support for IPOIB SDMA functionality
11 #include <linux/log2.h>
12 #include <linux/circ_buf.h>
16 #include "trace_ibhdrs.h"
20 /* Add a convenience helper */
21 #define CIRC_ADD(val, add, size) (((val) + (add)) & ((size) - 1))
22 #define CIRC_NEXT(val, size) CIRC_ADD(val, 1, size)
23 #define CIRC_PREV(val, size) CIRC_ADD(val, -1, size)
26 * struct ipoib_txreq - IPOIB transmit descriptor
27 * @txreq: sdma transmit request
28 * @sdma_hdr: 9b ib headers
29 * @sdma_status: status returned by sdma engine
30 * @priv: ipoib netdev private data
31 * @txq: txq on which skb was output
35 struct sdma_txreq txreq;
36 struct hfi1_sdma_header sdma_hdr;
38 struct hfi1_ipoib_dev_priv *priv;
39 struct hfi1_ipoib_txq *txq;
43 struct ipoib_txparms {
44 struct hfi1_devdata *dd;
45 struct rdma_ah_attr *ah_attr;
46 struct hfi1_ibport *ibp;
47 struct hfi1_ipoib_txq *txq;
48 union hfi1_ipoib_flow flow;
54 static u64 hfi1_ipoib_txreqs(const u64 sent, const u64 completed)
56 return sent - completed;
59 static u64 hfi1_ipoib_used(struct hfi1_ipoib_txq *txq)
61 return hfi1_ipoib_txreqs(txq->sent_txreqs,
62 atomic64_read(&txq->complete_txreqs));
65 static void hfi1_ipoib_stop_txq(struct hfi1_ipoib_txq *txq)
67 trace_hfi1_txq_stop(txq);
68 if (atomic_inc_return(&txq->stops) == 1)
69 netif_stop_subqueue(txq->priv->netdev, txq->q_idx);
72 static void hfi1_ipoib_wake_txq(struct hfi1_ipoib_txq *txq)
74 trace_hfi1_txq_wake(txq);
75 if (atomic_dec_and_test(&txq->stops))
76 netif_wake_subqueue(txq->priv->netdev, txq->q_idx);
79 static uint hfi1_ipoib_ring_hwat(struct hfi1_ipoib_txq *txq)
81 return min_t(uint, txq->priv->netdev->tx_queue_len,
82 txq->tx_ring.max_items - 1);
85 static uint hfi1_ipoib_ring_lwat(struct hfi1_ipoib_txq *txq)
87 return min_t(uint, txq->priv->netdev->tx_queue_len,
88 txq->tx_ring.max_items) >> 1;
91 static void hfi1_ipoib_check_queue_depth(struct hfi1_ipoib_txq *txq)
94 if (hfi1_ipoib_used(txq) >= hfi1_ipoib_ring_hwat(txq) &&
95 !atomic_xchg(&txq->ring_full, 1)) {
96 trace_hfi1_txq_full(txq);
97 hfi1_ipoib_stop_txq(txq);
101 static void hfi1_ipoib_check_queue_stopped(struct hfi1_ipoib_txq *txq)
103 struct net_device *dev = txq->priv->netdev;
105 /* If shutting down just return as queue state is irrelevant */
106 if (unlikely(dev->reg_state != NETREG_REGISTERED))
110 * When the queue has been drained to less than half full it will be
112 * The size of the txreq ring is fixed at initialization.
113 * The tx queue len can be adjusted upward while the interface is
115 * The tx queue len can be large enough to overflow the txreq_ring.
116 * Use the minimum of the current tx_queue_len or the rings max txreqs
117 * to protect against ring overflow.
119 if (hfi1_ipoib_used(txq) < hfi1_ipoib_ring_lwat(txq) &&
120 atomic_xchg(&txq->ring_full, 0)) {
121 trace_hfi1_txq_xmit_unstopped(txq);
122 hfi1_ipoib_wake_txq(txq);
126 static void hfi1_ipoib_free_tx(struct ipoib_txreq *tx, int budget)
128 struct hfi1_ipoib_dev_priv *priv = tx->priv;
130 if (likely(!tx->sdma_status)) {
131 hfi1_ipoib_update_tx_netstats(priv, 1, tx->skb->len);
133 ++priv->netdev->stats.tx_errors;
134 dd_dev_warn(priv->dd,
135 "%s: Status = 0x%x pbc 0x%llx txq = %d sde = %d\n",
136 __func__, tx->sdma_status,
137 le64_to_cpu(tx->sdma_hdr.pbc), tx->txq->q_idx,
138 tx->txq->sde->this_idx);
141 napi_consume_skb(tx->skb, budget);
142 sdma_txclean(priv->dd, &tx->txreq);
143 kmem_cache_free(priv->txreq_cache, tx);
146 static int hfi1_ipoib_drain_tx_ring(struct hfi1_ipoib_txq *txq, int budget)
148 struct hfi1_ipoib_circ_buf *tx_ring = &txq->tx_ring;
155 spin_lock_bh(&tx_ring->consumer_lock);
157 /* Read index before reading contents at that index. */
158 head = smp_load_acquire(&tx_ring->head);
159 tail = tx_ring->tail;
160 max_tx = tx_ring->max_items;
162 work_done = min_t(int, CIRC_CNT(head, tail, max_tx), budget);
164 for (tx_count = work_done; tx_count; tx_count--) {
165 hfi1_ipoib_free_tx(tx_ring->items[tail], budget);
166 tail = CIRC_NEXT(tail, max_tx);
169 atomic64_add(work_done, &txq->complete_txreqs);
171 /* Finished freeing tx items so store the tail value. */
172 smp_store_release(&tx_ring->tail, tail);
174 spin_unlock_bh(&tx_ring->consumer_lock);
176 hfi1_ipoib_check_queue_stopped(txq);
181 static int hfi1_ipoib_process_tx_ring(struct napi_struct *napi, int budget)
183 struct hfi1_ipoib_dev_priv *priv = hfi1_ipoib_priv(napi->dev);
184 struct hfi1_ipoib_txq *txq = &priv->txqs[napi - priv->tx_napis];
186 int work_done = hfi1_ipoib_drain_tx_ring(txq, budget);
188 if (work_done < budget)
189 napi_complete_done(napi, work_done);
194 static void hfi1_ipoib_add_tx(struct ipoib_txreq *tx)
196 struct hfi1_ipoib_circ_buf *tx_ring = &tx->txq->tx_ring;
201 spin_lock(&tx_ring->producer_lock);
203 head = tx_ring->head;
204 tail = READ_ONCE(tx_ring->tail);
205 max_tx = tx_ring->max_items;
207 if (likely(CIRC_SPACE(head, tail, max_tx))) {
208 tx_ring->items[head] = tx;
210 /* Finish storing txreq before incrementing head. */
211 smp_store_release(&tx_ring->head, CIRC_ADD(head, 1, max_tx));
212 napi_schedule(tx->txq->napi);
214 struct hfi1_ipoib_txq *txq = tx->txq;
215 struct hfi1_ipoib_dev_priv *priv = tx->priv;
218 hfi1_ipoib_free_tx(tx, 0);
219 atomic64_inc(&txq->complete_txreqs);
220 dd_dev_dbg(priv->dd, "txq %d full.\n", txq->q_idx);
223 spin_unlock(&tx_ring->producer_lock);
226 static void hfi1_ipoib_sdma_complete(struct sdma_txreq *txreq, int status)
228 struct ipoib_txreq *tx = container_of(txreq, struct ipoib_txreq, txreq);
230 tx->sdma_status = status;
232 hfi1_ipoib_add_tx(tx);
235 static int hfi1_ipoib_build_ulp_payload(struct ipoib_txreq *tx,
236 struct ipoib_txparms *txp)
238 struct hfi1_devdata *dd = txp->dd;
239 struct sdma_txreq *txreq = &tx->txreq;
240 struct sk_buff *skb = tx->skb;
244 if (skb_headlen(skb)) {
245 ret = sdma_txadd_kvaddr(dd, txreq, skb->data, skb_headlen(skb));
250 for (i = 0; i < skb_shinfo(skb)->nr_frags; i++) {
251 const skb_frag_t *frag = &skb_shinfo(skb)->frags[i];
253 ret = sdma_txadd_page(dd,
266 static int hfi1_ipoib_build_tx_desc(struct ipoib_txreq *tx,
267 struct ipoib_txparms *txp)
269 struct hfi1_devdata *dd = txp->dd;
270 struct sdma_txreq *txreq = &tx->txreq;
271 struct hfi1_sdma_header *sdma_hdr = &tx->sdma_hdr;
273 sizeof(sdma_hdr->pbc) + (txp->hdr_dwords << 2) + tx->skb->len;
276 ret = sdma_txinit(txreq, 0, pkt_bytes, hfi1_ipoib_sdma_complete);
280 /* add pbc + headers */
281 ret = sdma_txadd_kvaddr(dd,
284 sizeof(sdma_hdr->pbc) + (txp->hdr_dwords << 2));
288 /* add the ulp payload */
289 return hfi1_ipoib_build_ulp_payload(tx, txp);
292 static void hfi1_ipoib_build_ib_tx_headers(struct ipoib_txreq *tx,
293 struct ipoib_txparms *txp)
295 struct hfi1_ipoib_dev_priv *priv = tx->priv;
296 struct hfi1_sdma_header *sdma_hdr = &tx->sdma_hdr;
297 struct sk_buff *skb = tx->skb;
298 struct hfi1_pportdata *ppd = ppd_from_ibp(txp->ibp);
299 struct rdma_ah_attr *ah_attr = txp->ah_attr;
300 struct ib_other_headers *ohdr;
307 u32 sqpn = (u32)(priv->netdev->dev_addr[1] << 16 |
308 priv->netdev->dev_addr[2] << 8 |
309 priv->netdev->dev_addr[3]);
313 pad_cnt = -skb->len & 3;
316 payload_dwords = ((skb->len + pad_cnt) >> 2) + SIZE_OF_CRC;
318 /* header size in dwords LRH+BTH+DETH = (8+12+8)/4. */
321 if (rdma_ah_get_ah_flags(ah_attr) & IB_AH_GRH) {
322 grh = &sdma_hdr->hdr.ibh.u.l.grh;
324 hfi1_make_grh(txp->ibp,
326 rdma_ah_read_grh(ah_attr),
327 txp->hdr_dwords - LRH_9B_DWORDS,
330 ohdr = &sdma_hdr->hdr.ibh.u.l.oth;
333 ohdr = &sdma_hdr->hdr.ibh.u.oth;
336 lrh0 |= (rdma_ah_get_sl(ah_attr) & 0xf) << 4;
337 lrh0 |= (txp->flow.sc5 & 0xf) << 12;
339 dlid = opa_get_lid(rdma_ah_get_dlid(ah_attr), 9B);
340 if (dlid == be16_to_cpu(IB_LID_PERMISSIVE)) {
341 slid = be16_to_cpu(IB_LID_PERMISSIVE);
343 u16 lid = (u16)ppd->lid;
346 lid |= rdma_ah_get_path_bits(ah_attr) &
347 ((1 << ppd->lmc) - 1);
350 slid = be16_to_cpu(IB_LID_PERMISSIVE);
355 dwords = txp->hdr_dwords + payload_dwords;
358 sdma_hdr->hdr.hdr_type = HFI1_PKT_TYPE_9B;
359 hfi1_make_ib_hdr(&sdma_hdr->hdr.ibh, lrh0, dwords, dlid, slid);
362 bth0 = (IB_OPCODE_UD_SEND_ONLY << 24) | (pad_cnt << 20) | priv->pkey;
364 ohdr->bth[0] = cpu_to_be32(bth0);
365 ohdr->bth[1] = cpu_to_be32(txp->dqpn);
366 ohdr->bth[2] = cpu_to_be32(mask_psn((u32)txp->txq->sent_txreqs));
369 ohdr->u.ud.deth[0] = cpu_to_be32(priv->qkey);
370 ohdr->u.ud.deth[1] = cpu_to_be32((txp->entropy <<
371 HFI1_IPOIB_ENTROPY_SHIFT) | sqpn);
373 /* Construct the pbc. */
375 cpu_to_le64(create_pbc(ppd,
376 ib_is_sc5(txp->flow.sc5) <<
379 sc_to_vlt(priv->dd, txp->flow.sc5),
380 dwords - SIZE_OF_CRC +
381 (sizeof(sdma_hdr->pbc) >> 2)));
384 static struct ipoib_txreq *hfi1_ipoib_send_dma_common(struct net_device *dev,
386 struct ipoib_txparms *txp)
388 struct hfi1_ipoib_dev_priv *priv = hfi1_ipoib_priv(dev);
389 struct ipoib_txreq *tx;
392 tx = kmem_cache_alloc_node(priv->txreq_cache,
396 return ERR_PTR(-ENOMEM);
398 /* so that we can test if the sdma descriptors are there */
399 tx->txreq.num_desc = 0;
403 INIT_LIST_HEAD(&tx->txreq.list);
405 hfi1_ipoib_build_ib_tx_headers(tx, txp);
407 ret = hfi1_ipoib_build_tx_desc(tx, txp);
409 if (txp->txq->flow.as_int != txp->flow.as_int) {
410 txp->txq->flow.tx_queue = txp->flow.tx_queue;
411 txp->txq->flow.sc5 = txp->flow.sc5;
413 sdma_select_engine_sc(priv->dd,
416 trace_hfi1_flow_switch(txp->txq);
422 sdma_txclean(priv->dd, &tx->txreq);
423 kmem_cache_free(priv->txreq_cache, tx);
428 static int hfi1_ipoib_submit_tx_list(struct net_device *dev,
429 struct hfi1_ipoib_txq *txq)
434 ret = sdma_send_txlist(txq->sde,
435 iowait_get_ib_work(&txq->wait),
438 if (likely(!ret) || ret == -EBUSY || ret == -ECOMM)
441 dd_dev_warn(txq->priv->dd, "cannot send skb tx list, err %d.\n", ret);
446 static int hfi1_ipoib_flush_tx_list(struct net_device *dev,
447 struct hfi1_ipoib_txq *txq)
451 if (!list_empty(&txq->tx_list)) {
452 /* Flush the current list */
453 ret = hfi1_ipoib_submit_tx_list(dev, txq);
457 ++dev->stats.tx_carrier_errors;
463 static int hfi1_ipoib_submit_tx(struct hfi1_ipoib_txq *txq,
464 struct ipoib_txreq *tx)
468 ret = sdma_send_txreq(txq->sde,
469 iowait_get_ib_work(&txq->wait),
473 txq->pkts_sent = true;
474 iowait_starve_clear(txq->pkts_sent, &txq->wait);
480 static int hfi1_ipoib_send_dma_single(struct net_device *dev,
482 struct ipoib_txparms *txp)
484 struct hfi1_ipoib_dev_priv *priv = hfi1_ipoib_priv(dev);
485 struct hfi1_ipoib_txq *txq = txp->txq;
486 struct ipoib_txreq *tx;
489 tx = hfi1_ipoib_send_dma_common(dev, skb, txp);
491 int ret = PTR_ERR(tx);
493 dev_kfree_skb_any(skb);
496 ++dev->stats.tx_errors;
498 ++dev->stats.tx_carrier_errors;
503 ret = hfi1_ipoib_submit_tx(txq, tx);
506 trace_sdma_output_ibhdr(tx->priv->dd,
508 ib_is_sc5(txp->flow.sc5));
509 hfi1_ipoib_check_queue_depth(txq);
513 txq->pkts_sent = false;
515 if (ret == -EBUSY || ret == -ECOMM)
518 sdma_txclean(priv->dd, &tx->txreq);
519 dev_kfree_skb_any(skb);
520 kmem_cache_free(priv->txreq_cache, tx);
521 ++dev->stats.tx_carrier_errors;
526 static int hfi1_ipoib_send_dma_list(struct net_device *dev,
528 struct ipoib_txparms *txp)
530 struct hfi1_ipoib_txq *txq = txp->txq;
531 struct ipoib_txreq *tx;
533 /* Has the flow change ? */
534 if (txq->flow.as_int != txp->flow.as_int) {
537 trace_hfi1_flow_flush(txq);
538 ret = hfi1_ipoib_flush_tx_list(dev, txq);
541 ++dev->stats.tx_dropped;
542 dev_kfree_skb_any(skb);
546 tx = hfi1_ipoib_send_dma_common(dev, skb, txp);
548 int ret = PTR_ERR(tx);
550 dev_kfree_skb_any(skb);
553 ++dev->stats.tx_errors;
555 ++dev->stats.tx_carrier_errors;
560 list_add_tail(&tx->txreq.list, &txq->tx_list);
562 hfi1_ipoib_check_queue_depth(txq);
564 trace_sdma_output_ibhdr(tx->priv->dd,
566 ib_is_sc5(txp->flow.sc5));
568 if (!netdev_xmit_more())
569 (void)hfi1_ipoib_flush_tx_list(dev, txq);
574 static u8 hfi1_ipoib_calc_entropy(struct sk_buff *skb)
576 if (skb_transport_header_was_set(skb)) {
577 u8 *hdr = (u8 *)skb_transport_header(skb);
579 return (hdr[0] ^ hdr[1] ^ hdr[2] ^ hdr[3]);
582 return (u8)skb_get_queue_mapping(skb);
585 int hfi1_ipoib_send_dma(struct net_device *dev,
587 struct ib_ah *address,
590 struct hfi1_ipoib_dev_priv *priv = hfi1_ipoib_priv(dev);
591 struct ipoib_txparms txp;
592 struct rdma_netdev *rn = netdev_priv(dev);
594 if (unlikely(skb->len > rn->mtu + HFI1_IPOIB_ENCAP_LEN)) {
595 dd_dev_warn(priv->dd, "packet len %d (> %d) too long to send, dropping\n",
597 rn->mtu + HFI1_IPOIB_ENCAP_LEN);
598 ++dev->stats.tx_dropped;
599 ++dev->stats.tx_errors;
600 dev_kfree_skb_any(skb);
605 txp.ah_attr = &ibah_to_rvtah(address)->attr;
606 txp.ibp = to_iport(priv->device, priv->port_num);
607 txp.txq = &priv->txqs[skb_get_queue_mapping(skb)];
609 txp.flow.sc5 = txp.ibp->sl_to_sc[rdma_ah_get_sl(txp.ah_attr)];
610 txp.flow.tx_queue = (u8)skb_get_queue_mapping(skb);
611 txp.entropy = hfi1_ipoib_calc_entropy(skb);
613 if (netdev_xmit_more() || !list_empty(&txp.txq->tx_list))
614 return hfi1_ipoib_send_dma_list(dev, skb, &txp);
616 return hfi1_ipoib_send_dma_single(dev, skb, &txp);
620 * hfi1_ipoib_sdma_sleep - ipoib sdma sleep function
622 * This function gets called from sdma_send_txreq() when there are not enough
623 * sdma descriptors available to send the packet. It adds Tx queue's wait
624 * structure to sdma engine's dmawait list to be woken up when descriptors
627 static int hfi1_ipoib_sdma_sleep(struct sdma_engine *sde,
628 struct iowait_work *wait,
629 struct sdma_txreq *txreq,
633 struct hfi1_ipoib_txq *txq =
634 container_of(wait->iow, struct hfi1_ipoib_txq, wait);
636 write_seqlock(&sde->waitlock);
638 if (likely(txq->priv->netdev->reg_state == NETREG_REGISTERED)) {
639 if (sdma_progress(sde, seq, txreq)) {
640 write_sequnlock(&sde->waitlock);
644 if (list_empty(&txreq->list))
645 /* came from non-list submit */
646 list_add_tail(&txreq->list, &txq->tx_list);
647 if (list_empty(&txq->wait.list)) {
648 if (!atomic_xchg(&txq->no_desc, 1)) {
649 trace_hfi1_txq_queued(txq);
650 hfi1_ipoib_stop_txq(txq);
652 iowait_queue(pkts_sent, wait->iow, &sde->dmawait);
655 write_sequnlock(&sde->waitlock);
659 write_sequnlock(&sde->waitlock);
664 * hfi1_ipoib_sdma_wakeup - ipoib sdma wakeup function
666 * This function gets called when SDMA descriptors becomes available and Tx
667 * queue's wait structure was previously added to sdma engine's dmawait list.
669 static void hfi1_ipoib_sdma_wakeup(struct iowait *wait, int reason)
671 struct hfi1_ipoib_txq *txq =
672 container_of(wait, struct hfi1_ipoib_txq, wait);
674 trace_hfi1_txq_wakeup(txq);
675 if (likely(txq->priv->netdev->reg_state == NETREG_REGISTERED))
676 iowait_schedule(wait, system_highpri_wq, WORK_CPU_UNBOUND);
679 static void hfi1_ipoib_flush_txq(struct work_struct *work)
681 struct iowait_work *ioww =
682 container_of(work, struct iowait_work, iowork);
683 struct iowait *wait = iowait_ioww_to_iow(ioww);
684 struct hfi1_ipoib_txq *txq =
685 container_of(wait, struct hfi1_ipoib_txq, wait);
686 struct net_device *dev = txq->priv->netdev;
688 if (likely(dev->reg_state == NETREG_REGISTERED) &&
689 likely(!hfi1_ipoib_flush_tx_list(dev, txq)))
690 if (atomic_xchg(&txq->no_desc, 0))
691 hfi1_ipoib_wake_txq(txq);
694 int hfi1_ipoib_txreq_init(struct hfi1_ipoib_dev_priv *priv)
696 struct net_device *dev = priv->netdev;
697 char buf[HFI1_IPOIB_TXREQ_NAME_LEN];
698 unsigned long tx_ring_size;
702 * Ring holds 1 less than tx_ring_size
703 * Round up to next power of 2 in order to hold at least tx_queue_len
705 tx_ring_size = roundup_pow_of_two((unsigned long)dev->tx_queue_len + 1);
707 snprintf(buf, sizeof(buf), "hfi1_%u_ipoib_txreq_cache", priv->dd->unit);
708 priv->txreq_cache = kmem_cache_create(buf,
709 sizeof(struct ipoib_txreq),
713 if (!priv->txreq_cache)
716 priv->tx_napis = kcalloc_node(dev->num_tx_queues,
717 sizeof(struct napi_struct),
721 goto free_txreq_cache;
723 priv->txqs = kcalloc_node(dev->num_tx_queues,
724 sizeof(struct hfi1_ipoib_txq),
730 for (i = 0; i < dev->num_tx_queues; i++) {
731 struct hfi1_ipoib_txq *txq = &priv->txqs[i];
733 iowait_init(&txq->wait,
735 hfi1_ipoib_flush_txq,
737 hfi1_ipoib_sdma_sleep,
738 hfi1_ipoib_sdma_wakeup,
743 INIT_LIST_HEAD(&txq->tx_list);
744 atomic64_set(&txq->complete_txreqs, 0);
745 atomic_set(&txq->stops, 0);
746 atomic_set(&txq->ring_full, 0);
747 atomic_set(&txq->no_desc, 0);
749 txq->flow.tx_queue = 0xff;
750 txq->flow.sc5 = 0xff;
751 txq->pkts_sent = false;
753 netdev_queue_numa_node_write(netdev_get_tx_queue(dev, i),
757 kcalloc_node(tx_ring_size,
758 sizeof(struct ipoib_txreq *),
759 GFP_KERNEL, priv->dd->node);
760 if (!txq->tx_ring.items)
763 spin_lock_init(&txq->tx_ring.producer_lock);
764 spin_lock_init(&txq->tx_ring.consumer_lock);
765 txq->tx_ring.max_items = tx_ring_size;
767 txq->napi = &priv->tx_napis[i];
768 netif_tx_napi_add(dev, txq->napi,
769 hfi1_ipoib_process_tx_ring,
776 for (i--; i >= 0; i--) {
777 struct hfi1_ipoib_txq *txq = &priv->txqs[i];
779 netif_napi_del(txq->napi);
780 kfree(txq->tx_ring.items);
787 kfree(priv->tx_napis);
788 priv->tx_napis = NULL;
791 kmem_cache_destroy(priv->txreq_cache);
792 priv->txreq_cache = NULL;
796 static void hfi1_ipoib_drain_tx_list(struct hfi1_ipoib_txq *txq)
798 struct sdma_txreq *txreq;
799 struct sdma_txreq *txreq_tmp;
800 atomic64_t *complete_txreqs = &txq->complete_txreqs;
802 list_for_each_entry_safe(txreq, txreq_tmp, &txq->tx_list, list) {
803 struct ipoib_txreq *tx =
804 container_of(txreq, struct ipoib_txreq, txreq);
806 list_del(&txreq->list);
807 sdma_txclean(txq->priv->dd, &tx->txreq);
808 dev_kfree_skb_any(tx->skb);
809 kmem_cache_free(txq->priv->txreq_cache, tx);
810 atomic64_inc(complete_txreqs);
813 if (hfi1_ipoib_used(txq))
814 dd_dev_warn(txq->priv->dd,
815 "txq %d not empty found %llu requests\n",
817 hfi1_ipoib_txreqs(txq->sent_txreqs,
818 atomic64_read(complete_txreqs)));
821 void hfi1_ipoib_txreq_deinit(struct hfi1_ipoib_dev_priv *priv)
825 for (i = 0; i < priv->netdev->num_tx_queues; i++) {
826 struct hfi1_ipoib_txq *txq = &priv->txqs[i];
828 iowait_cancel_work(&txq->wait);
829 iowait_sdma_drain(&txq->wait);
830 hfi1_ipoib_drain_tx_list(txq);
831 netif_napi_del(txq->napi);
832 (void)hfi1_ipoib_drain_tx_ring(txq, txq->tx_ring.max_items);
833 kfree(txq->tx_ring.items);
839 kfree(priv->tx_napis);
840 priv->tx_napis = NULL;
842 kmem_cache_destroy(priv->txreq_cache);
843 priv->txreq_cache = NULL;
846 void hfi1_ipoib_napi_tx_enable(struct net_device *dev)
848 struct hfi1_ipoib_dev_priv *priv = hfi1_ipoib_priv(dev);
851 for (i = 0; i < dev->num_tx_queues; i++) {
852 struct hfi1_ipoib_txq *txq = &priv->txqs[i];
854 napi_enable(txq->napi);
858 void hfi1_ipoib_napi_tx_disable(struct net_device *dev)
860 struct hfi1_ipoib_dev_priv *priv = hfi1_ipoib_priv(dev);
863 for (i = 0; i < dev->num_tx_queues; i++) {
864 struct hfi1_ipoib_txq *txq = &priv->txqs[i];
866 napi_disable(txq->napi);
867 (void)hfi1_ipoib_drain_tx_ring(txq, txq->tx_ring.max_items);