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"
19 /* Add a convenience helper */
20 #define CIRC_ADD(val, add, size) (((val) + (add)) & ((size) - 1))
21 #define CIRC_NEXT(val, size) CIRC_ADD(val, 1, size)
22 #define CIRC_PREV(val, size) CIRC_ADD(val, -1, size)
25 * struct ipoib_txreq - IPOIB transmit descriptor
26 * @txreq: sdma transmit request
27 * @sdma_hdr: 9b ib headers
28 * @sdma_status: status returned by sdma engine
29 * @priv: ipoib netdev private data
30 * @txq: txq on which skb was output
34 struct sdma_txreq txreq
;
35 struct hfi1_sdma_header sdma_hdr
;
37 struct hfi1_ipoib_dev_priv
*priv
;
38 struct hfi1_ipoib_txq
*txq
;
42 struct ipoib_txparms
{
43 struct hfi1_devdata
*dd
;
44 struct rdma_ah_attr
*ah_attr
;
45 struct hfi1_ibport
*ibp
;
46 struct hfi1_ipoib_txq
*txq
;
47 union hfi1_ipoib_flow flow
;
53 static u64
hfi1_ipoib_txreqs(const u64 sent
, const u64 completed
)
55 return sent
- completed
;
58 static u64
hfi1_ipoib_used(struct hfi1_ipoib_txq
*txq
)
60 return hfi1_ipoib_txreqs(txq
->sent_txreqs
,
61 atomic64_read(&txq
->complete_txreqs
));
64 static void hfi1_ipoib_stop_txq(struct hfi1_ipoib_txq
*txq
)
66 if (atomic_inc_return(&txq
->stops
) == 1)
67 netif_stop_subqueue(txq
->priv
->netdev
, txq
->q_idx
);
70 static void hfi1_ipoib_wake_txq(struct hfi1_ipoib_txq
*txq
)
72 if (atomic_dec_and_test(&txq
->stops
))
73 netif_wake_subqueue(txq
->priv
->netdev
, txq
->q_idx
);
76 static uint
hfi1_ipoib_ring_hwat(struct hfi1_ipoib_txq
*txq
)
78 return min_t(uint
, txq
->priv
->netdev
->tx_queue_len
,
79 txq
->tx_ring
.max_items
- 1);
82 static uint
hfi1_ipoib_ring_lwat(struct hfi1_ipoib_txq
*txq
)
84 return min_t(uint
, txq
->priv
->netdev
->tx_queue_len
,
85 txq
->tx_ring
.max_items
) >> 1;
88 static void hfi1_ipoib_check_queue_depth(struct hfi1_ipoib_txq
*txq
)
91 if (hfi1_ipoib_used(txq
) >= hfi1_ipoib_ring_hwat(txq
) &&
92 !atomic_xchg(&txq
->ring_full
, 1))
93 hfi1_ipoib_stop_txq(txq
);
96 static void hfi1_ipoib_check_queue_stopped(struct hfi1_ipoib_txq
*txq
)
98 struct net_device
*dev
= txq
->priv
->netdev
;
100 /* If shutting down just return as queue state is irrelevant */
101 if (unlikely(dev
->reg_state
!= NETREG_REGISTERED
))
105 * When the queue has been drained to less than half full it will be
107 * The size of the txreq ring is fixed at initialization.
108 * The tx queue len can be adjusted upward while the interface is
110 * The tx queue len can be large enough to overflow the txreq_ring.
111 * Use the minimum of the current tx_queue_len or the rings max txreqs
112 * to protect against ring overflow.
114 if (hfi1_ipoib_used(txq
) < hfi1_ipoib_ring_lwat(txq
) &&
115 atomic_xchg(&txq
->ring_full
, 0))
116 hfi1_ipoib_wake_txq(txq
);
119 static void hfi1_ipoib_free_tx(struct ipoib_txreq
*tx
, int budget
)
121 struct hfi1_ipoib_dev_priv
*priv
= tx
->priv
;
123 if (likely(!tx
->sdma_status
)) {
124 dev_sw_netstats_tx_add(priv
->netdev
, 1, tx
->skb
->len
);
126 ++priv
->netdev
->stats
.tx_errors
;
127 dd_dev_warn(priv
->dd
,
128 "%s: Status = 0x%x pbc 0x%llx txq = %d sde = %d\n",
129 __func__
, tx
->sdma_status
,
130 le64_to_cpu(tx
->sdma_hdr
.pbc
), tx
->txq
->q_idx
,
131 tx
->txq
->sde
->this_idx
);
134 napi_consume_skb(tx
->skb
, budget
);
135 sdma_txclean(priv
->dd
, &tx
->txreq
);
136 kmem_cache_free(priv
->txreq_cache
, tx
);
139 static int hfi1_ipoib_drain_tx_ring(struct hfi1_ipoib_txq
*txq
, int budget
)
141 struct hfi1_ipoib_circ_buf
*tx_ring
= &txq
->tx_ring
;
148 spin_lock_bh(&tx_ring
->consumer_lock
);
150 /* Read index before reading contents at that index. */
151 head
= smp_load_acquire(&tx_ring
->head
);
152 tail
= tx_ring
->tail
;
153 max_tx
= tx_ring
->max_items
;
155 work_done
= min_t(int, CIRC_CNT(head
, tail
, max_tx
), budget
);
157 for (tx_count
= work_done
; tx_count
; tx_count
--) {
158 hfi1_ipoib_free_tx(tx_ring
->items
[tail
], budget
);
159 tail
= CIRC_NEXT(tail
, max_tx
);
162 atomic64_add(work_done
, &txq
->complete_txreqs
);
164 /* Finished freeing tx items so store the tail value. */
165 smp_store_release(&tx_ring
->tail
, tail
);
167 spin_unlock_bh(&tx_ring
->consumer_lock
);
169 hfi1_ipoib_check_queue_stopped(txq
);
174 static int hfi1_ipoib_process_tx_ring(struct napi_struct
*napi
, int budget
)
176 struct hfi1_ipoib_dev_priv
*priv
= hfi1_ipoib_priv(napi
->dev
);
177 struct hfi1_ipoib_txq
*txq
= &priv
->txqs
[napi
- priv
->tx_napis
];
179 int work_done
= hfi1_ipoib_drain_tx_ring(txq
, budget
);
181 if (work_done
< budget
)
182 napi_complete_done(napi
, work_done
);
187 static void hfi1_ipoib_add_tx(struct ipoib_txreq
*tx
)
189 struct hfi1_ipoib_circ_buf
*tx_ring
= &tx
->txq
->tx_ring
;
194 spin_lock(&tx_ring
->producer_lock
);
196 head
= tx_ring
->head
;
197 tail
= READ_ONCE(tx_ring
->tail
);
198 max_tx
= tx_ring
->max_items
;
200 if (likely(CIRC_SPACE(head
, tail
, max_tx
))) {
201 tx_ring
->items
[head
] = tx
;
203 /* Finish storing txreq before incrementing head. */
204 smp_store_release(&tx_ring
->head
, CIRC_ADD(head
, 1, max_tx
));
205 napi_schedule(tx
->txq
->napi
);
207 struct hfi1_ipoib_txq
*txq
= tx
->txq
;
208 struct hfi1_ipoib_dev_priv
*priv
= tx
->priv
;
211 hfi1_ipoib_free_tx(tx
, 0);
212 atomic64_inc(&txq
->complete_txreqs
);
213 dd_dev_dbg(priv
->dd
, "txq %d full.\n", txq
->q_idx
);
216 spin_unlock(&tx_ring
->producer_lock
);
219 static void hfi1_ipoib_sdma_complete(struct sdma_txreq
*txreq
, int status
)
221 struct ipoib_txreq
*tx
= container_of(txreq
, struct ipoib_txreq
, txreq
);
223 tx
->sdma_status
= status
;
225 hfi1_ipoib_add_tx(tx
);
228 static int hfi1_ipoib_build_ulp_payload(struct ipoib_txreq
*tx
,
229 struct ipoib_txparms
*txp
)
231 struct hfi1_devdata
*dd
= txp
->dd
;
232 struct sdma_txreq
*txreq
= &tx
->txreq
;
233 struct sk_buff
*skb
= tx
->skb
;
237 if (skb_headlen(skb
)) {
238 ret
= sdma_txadd_kvaddr(dd
, txreq
, skb
->data
, skb_headlen(skb
));
243 for (i
= 0; i
< skb_shinfo(skb
)->nr_frags
; i
++) {
244 const skb_frag_t
*frag
= &skb_shinfo(skb
)->frags
[i
];
246 ret
= sdma_txadd_page(dd
,
250 skb_frag_size(frag
));
258 static int hfi1_ipoib_build_tx_desc(struct ipoib_txreq
*tx
,
259 struct ipoib_txparms
*txp
)
261 struct hfi1_devdata
*dd
= txp
->dd
;
262 struct sdma_txreq
*txreq
= &tx
->txreq
;
263 struct hfi1_sdma_header
*sdma_hdr
= &tx
->sdma_hdr
;
265 sizeof(sdma_hdr
->pbc
) + (txp
->hdr_dwords
<< 2) + tx
->skb
->len
;
268 ret
= sdma_txinit(txreq
, 0, pkt_bytes
, hfi1_ipoib_sdma_complete
);
272 /* add pbc + headers */
273 ret
= sdma_txadd_kvaddr(dd
,
276 sizeof(sdma_hdr
->pbc
) + (txp
->hdr_dwords
<< 2));
280 /* add the ulp payload */
281 return hfi1_ipoib_build_ulp_payload(tx
, txp
);
284 static void hfi1_ipoib_build_ib_tx_headers(struct ipoib_txreq
*tx
,
285 struct ipoib_txparms
*txp
)
287 struct hfi1_ipoib_dev_priv
*priv
= tx
->priv
;
288 struct hfi1_sdma_header
*sdma_hdr
= &tx
->sdma_hdr
;
289 struct sk_buff
*skb
= tx
->skb
;
290 struct hfi1_pportdata
*ppd
= ppd_from_ibp(txp
->ibp
);
291 struct rdma_ah_attr
*ah_attr
= txp
->ah_attr
;
292 struct ib_other_headers
*ohdr
;
299 u32 sqpn
= (u32
)(priv
->netdev
->dev_addr
[1] << 16 |
300 priv
->netdev
->dev_addr
[2] << 8 |
301 priv
->netdev
->dev_addr
[3]);
305 pad_cnt
= -skb
->len
& 3;
308 payload_dwords
= ((skb
->len
+ pad_cnt
) >> 2) + SIZE_OF_CRC
;
310 /* header size in dwords LRH+BTH+DETH = (8+12+8)/4. */
313 if (rdma_ah_get_ah_flags(ah_attr
) & IB_AH_GRH
) {
314 grh
= &sdma_hdr
->hdr
.ibh
.u
.l
.grh
;
316 hfi1_make_grh(txp
->ibp
,
318 rdma_ah_read_grh(ah_attr
),
319 txp
->hdr_dwords
- LRH_9B_DWORDS
,
322 ohdr
= &sdma_hdr
->hdr
.ibh
.u
.l
.oth
;
325 ohdr
= &sdma_hdr
->hdr
.ibh
.u
.oth
;
328 lrh0
|= (rdma_ah_get_sl(ah_attr
) & 0xf) << 4;
329 lrh0
|= (txp
->flow
.sc5
& 0xf) << 12;
331 dlid
= opa_get_lid(rdma_ah_get_dlid(ah_attr
), 9B
);
332 if (dlid
== be16_to_cpu(IB_LID_PERMISSIVE
)) {
333 slid
= be16_to_cpu(IB_LID_PERMISSIVE
);
335 u16 lid
= (u16
)ppd
->lid
;
338 lid
|= rdma_ah_get_path_bits(ah_attr
) &
339 ((1 << ppd
->lmc
) - 1);
342 slid
= be16_to_cpu(IB_LID_PERMISSIVE
);
347 dwords
= txp
->hdr_dwords
+ payload_dwords
;
350 sdma_hdr
->hdr
.hdr_type
= HFI1_PKT_TYPE_9B
;
351 hfi1_make_ib_hdr(&sdma_hdr
->hdr
.ibh
, lrh0
, dwords
, dlid
, slid
);
354 bth0
= (IB_OPCODE_UD_SEND_ONLY
<< 24) | (pad_cnt
<< 20) | priv
->pkey
;
356 ohdr
->bth
[0] = cpu_to_be32(bth0
);
357 ohdr
->bth
[1] = cpu_to_be32(txp
->dqpn
);
358 ohdr
->bth
[2] = cpu_to_be32(mask_psn((u32
)txp
->txq
->sent_txreqs
));
361 ohdr
->u
.ud
.deth
[0] = cpu_to_be32(priv
->qkey
);
362 ohdr
->u
.ud
.deth
[1] = cpu_to_be32((txp
->entropy
<<
363 HFI1_IPOIB_ENTROPY_SHIFT
) | sqpn
);
365 /* Construct the pbc. */
367 cpu_to_le64(create_pbc(ppd
,
368 ib_is_sc5(txp
->flow
.sc5
) <<
371 sc_to_vlt(priv
->dd
, txp
->flow
.sc5
),
372 dwords
- SIZE_OF_CRC
+
373 (sizeof(sdma_hdr
->pbc
) >> 2)));
376 static struct ipoib_txreq
*hfi1_ipoib_send_dma_common(struct net_device
*dev
,
378 struct ipoib_txparms
*txp
)
380 struct hfi1_ipoib_dev_priv
*priv
= hfi1_ipoib_priv(dev
);
381 struct ipoib_txreq
*tx
;
384 tx
= kmem_cache_alloc_node(priv
->txreq_cache
,
388 return ERR_PTR(-ENOMEM
);
390 /* so that we can test if the sdma descriptors are there */
391 tx
->txreq
.num_desc
= 0;
395 INIT_LIST_HEAD(&tx
->txreq
.list
);
397 hfi1_ipoib_build_ib_tx_headers(tx
, txp
);
399 ret
= hfi1_ipoib_build_tx_desc(tx
, txp
);
401 if (txp
->txq
->flow
.as_int
!= txp
->flow
.as_int
) {
402 txp
->txq
->flow
.tx_queue
= txp
->flow
.tx_queue
;
403 txp
->txq
->flow
.sc5
= txp
->flow
.sc5
;
405 sdma_select_engine_sc(priv
->dd
,
413 sdma_txclean(priv
->dd
, &tx
->txreq
);
414 kmem_cache_free(priv
->txreq_cache
, tx
);
419 static int hfi1_ipoib_submit_tx_list(struct net_device
*dev
,
420 struct hfi1_ipoib_txq
*txq
)
425 ret
= sdma_send_txlist(txq
->sde
,
426 iowait_get_ib_work(&txq
->wait
),
429 if (likely(!ret
) || ret
== -EBUSY
|| ret
== -ECOMM
)
432 dd_dev_warn(txq
->priv
->dd
, "cannot send skb tx list, err %d.\n", ret
);
437 static int hfi1_ipoib_flush_tx_list(struct net_device
*dev
,
438 struct hfi1_ipoib_txq
*txq
)
442 if (!list_empty(&txq
->tx_list
)) {
443 /* Flush the current list */
444 ret
= hfi1_ipoib_submit_tx_list(dev
, txq
);
448 ++dev
->stats
.tx_carrier_errors
;
454 static int hfi1_ipoib_submit_tx(struct hfi1_ipoib_txq
*txq
,
455 struct ipoib_txreq
*tx
)
459 ret
= sdma_send_txreq(txq
->sde
,
460 iowait_get_ib_work(&txq
->wait
),
464 txq
->pkts_sent
= true;
465 iowait_starve_clear(txq
->pkts_sent
, &txq
->wait
);
471 static int hfi1_ipoib_send_dma_single(struct net_device
*dev
,
473 struct ipoib_txparms
*txp
)
475 struct hfi1_ipoib_dev_priv
*priv
= hfi1_ipoib_priv(dev
);
476 struct hfi1_ipoib_txq
*txq
= txp
->txq
;
477 struct ipoib_txreq
*tx
;
480 tx
= hfi1_ipoib_send_dma_common(dev
, skb
, txp
);
482 int ret
= PTR_ERR(tx
);
484 dev_kfree_skb_any(skb
);
487 ++dev
->stats
.tx_errors
;
489 ++dev
->stats
.tx_carrier_errors
;
494 ret
= hfi1_ipoib_submit_tx(txq
, tx
);
497 trace_sdma_output_ibhdr(tx
->priv
->dd
,
499 ib_is_sc5(txp
->flow
.sc5
));
500 hfi1_ipoib_check_queue_depth(txq
);
504 txq
->pkts_sent
= false;
506 if (ret
== -EBUSY
|| ret
== -ECOMM
)
509 sdma_txclean(priv
->dd
, &tx
->txreq
);
510 dev_kfree_skb_any(skb
);
511 kmem_cache_free(priv
->txreq_cache
, tx
);
512 ++dev
->stats
.tx_carrier_errors
;
517 static int hfi1_ipoib_send_dma_list(struct net_device
*dev
,
519 struct ipoib_txparms
*txp
)
521 struct hfi1_ipoib_txq
*txq
= txp
->txq
;
522 struct ipoib_txreq
*tx
;
524 /* Has the flow change ? */
525 if (txq
->flow
.as_int
!= txp
->flow
.as_int
) {
528 ret
= hfi1_ipoib_flush_tx_list(dev
, txq
);
531 ++dev
->stats
.tx_dropped
;
532 dev_kfree_skb_any(skb
);
536 tx
= hfi1_ipoib_send_dma_common(dev
, skb
, txp
);
538 int ret
= PTR_ERR(tx
);
540 dev_kfree_skb_any(skb
);
543 ++dev
->stats
.tx_errors
;
545 ++dev
->stats
.tx_carrier_errors
;
550 list_add_tail(&tx
->txreq
.list
, &txq
->tx_list
);
552 hfi1_ipoib_check_queue_depth(txq
);
554 trace_sdma_output_ibhdr(tx
->priv
->dd
,
556 ib_is_sc5(txp
->flow
.sc5
));
558 if (!netdev_xmit_more())
559 (void)hfi1_ipoib_flush_tx_list(dev
, txq
);
564 static u8
hfi1_ipoib_calc_entropy(struct sk_buff
*skb
)
566 if (skb_transport_header_was_set(skb
)) {
567 u8
*hdr
= (u8
*)skb_transport_header(skb
);
569 return (hdr
[0] ^ hdr
[1] ^ hdr
[2] ^ hdr
[3]);
572 return (u8
)skb_get_queue_mapping(skb
);
575 int hfi1_ipoib_send_dma(struct net_device
*dev
,
577 struct ib_ah
*address
,
580 struct hfi1_ipoib_dev_priv
*priv
= hfi1_ipoib_priv(dev
);
581 struct ipoib_txparms txp
;
582 struct rdma_netdev
*rn
= netdev_priv(dev
);
584 if (unlikely(skb
->len
> rn
->mtu
+ HFI1_IPOIB_ENCAP_LEN
)) {
585 dd_dev_warn(priv
->dd
, "packet len %d (> %d) too long to send, dropping\n",
587 rn
->mtu
+ HFI1_IPOIB_ENCAP_LEN
);
588 ++dev
->stats
.tx_dropped
;
589 ++dev
->stats
.tx_errors
;
590 dev_kfree_skb_any(skb
);
595 txp
.ah_attr
= &ibah_to_rvtah(address
)->attr
;
596 txp
.ibp
= to_iport(priv
->device
, priv
->port_num
);
597 txp
.txq
= &priv
->txqs
[skb_get_queue_mapping(skb
)];
599 txp
.flow
.sc5
= txp
.ibp
->sl_to_sc
[rdma_ah_get_sl(txp
.ah_attr
)];
600 txp
.flow
.tx_queue
= (u8
)skb_get_queue_mapping(skb
);
601 txp
.entropy
= hfi1_ipoib_calc_entropy(skb
);
603 if (netdev_xmit_more() || !list_empty(&txp
.txq
->tx_list
))
604 return hfi1_ipoib_send_dma_list(dev
, skb
, &txp
);
606 return hfi1_ipoib_send_dma_single(dev
, skb
, &txp
);
610 * hfi1_ipoib_sdma_sleep - ipoib sdma sleep function
612 * This function gets called from sdma_send_txreq() when there are not enough
613 * sdma descriptors available to send the packet. It adds Tx queue's wait
614 * structure to sdma engine's dmawait list to be woken up when descriptors
617 static int hfi1_ipoib_sdma_sleep(struct sdma_engine
*sde
,
618 struct iowait_work
*wait
,
619 struct sdma_txreq
*txreq
,
623 struct hfi1_ipoib_txq
*txq
=
624 container_of(wait
->iow
, struct hfi1_ipoib_txq
, wait
);
626 write_seqlock(&sde
->waitlock
);
628 if (likely(txq
->priv
->netdev
->reg_state
== NETREG_REGISTERED
)) {
629 if (sdma_progress(sde
, seq
, txreq
)) {
630 write_sequnlock(&sde
->waitlock
);
634 if (list_empty(&txreq
->list
))
635 /* came from non-list submit */
636 list_add_tail(&txreq
->list
, &txq
->tx_list
);
637 if (list_empty(&txq
->wait
.list
)) {
638 if (!atomic_xchg(&txq
->no_desc
, 1))
639 hfi1_ipoib_stop_txq(txq
);
640 iowait_queue(pkts_sent
, wait
->iow
, &sde
->dmawait
);
643 write_sequnlock(&sde
->waitlock
);
647 write_sequnlock(&sde
->waitlock
);
652 * hfi1_ipoib_sdma_wakeup - ipoib sdma wakeup function
654 * This function gets called when SDMA descriptors becomes available and Tx
655 * queue's wait structure was previously added to sdma engine's dmawait list.
657 static void hfi1_ipoib_sdma_wakeup(struct iowait
*wait
, int reason
)
659 struct hfi1_ipoib_txq
*txq
=
660 container_of(wait
, struct hfi1_ipoib_txq
, wait
);
662 if (likely(txq
->priv
->netdev
->reg_state
== NETREG_REGISTERED
))
663 iowait_schedule(wait
, system_highpri_wq
, WORK_CPU_UNBOUND
);
666 static void hfi1_ipoib_flush_txq(struct work_struct
*work
)
668 struct iowait_work
*ioww
=
669 container_of(work
, struct iowait_work
, iowork
);
670 struct iowait
*wait
= iowait_ioww_to_iow(ioww
);
671 struct hfi1_ipoib_txq
*txq
=
672 container_of(wait
, struct hfi1_ipoib_txq
, wait
);
673 struct net_device
*dev
= txq
->priv
->netdev
;
675 if (likely(dev
->reg_state
== NETREG_REGISTERED
) &&
676 likely(!hfi1_ipoib_flush_tx_list(dev
, txq
)))
677 if (atomic_xchg(&txq
->no_desc
, 0))
678 hfi1_ipoib_wake_txq(txq
);
681 int hfi1_ipoib_txreq_init(struct hfi1_ipoib_dev_priv
*priv
)
683 struct net_device
*dev
= priv
->netdev
;
684 char buf
[HFI1_IPOIB_TXREQ_NAME_LEN
];
685 unsigned long tx_ring_size
;
689 * Ring holds 1 less than tx_ring_size
690 * Round up to next power of 2 in order to hold at least tx_queue_len
692 tx_ring_size
= roundup_pow_of_two((unsigned long)dev
->tx_queue_len
+ 1);
694 snprintf(buf
, sizeof(buf
), "hfi1_%u_ipoib_txreq_cache", priv
->dd
->unit
);
695 priv
->txreq_cache
= kmem_cache_create(buf
,
696 sizeof(struct ipoib_txreq
),
700 if (!priv
->txreq_cache
)
703 priv
->tx_napis
= kcalloc_node(dev
->num_tx_queues
,
704 sizeof(struct napi_struct
),
708 goto free_txreq_cache
;
710 priv
->txqs
= kcalloc_node(dev
->num_tx_queues
,
711 sizeof(struct hfi1_ipoib_txq
),
717 for (i
= 0; i
< dev
->num_tx_queues
; i
++) {
718 struct hfi1_ipoib_txq
*txq
= &priv
->txqs
[i
];
720 iowait_init(&txq
->wait
,
722 hfi1_ipoib_flush_txq
,
724 hfi1_ipoib_sdma_sleep
,
725 hfi1_ipoib_sdma_wakeup
,
730 INIT_LIST_HEAD(&txq
->tx_list
);
731 atomic64_set(&txq
->complete_txreqs
, 0);
732 atomic_set(&txq
->stops
, 0);
733 atomic_set(&txq
->ring_full
, 0);
734 atomic_set(&txq
->no_desc
, 0);
736 txq
->flow
.tx_queue
= 0xff;
737 txq
->flow
.sc5
= 0xff;
738 txq
->pkts_sent
= false;
740 netdev_queue_numa_node_write(netdev_get_tx_queue(dev
, i
),
744 vzalloc_node(array_size(tx_ring_size
,
745 sizeof(struct ipoib_txreq
)),
747 if (!txq
->tx_ring
.items
)
750 spin_lock_init(&txq
->tx_ring
.producer_lock
);
751 spin_lock_init(&txq
->tx_ring
.consumer_lock
);
752 txq
->tx_ring
.max_items
= tx_ring_size
;
754 txq
->napi
= &priv
->tx_napis
[i
];
755 netif_tx_napi_add(dev
, txq
->napi
,
756 hfi1_ipoib_process_tx_ring
,
763 for (i
--; i
>= 0; i
--) {
764 struct hfi1_ipoib_txq
*txq
= &priv
->txqs
[i
];
766 netif_napi_del(txq
->napi
);
767 vfree(txq
->tx_ring
.items
);
774 kfree(priv
->tx_napis
);
775 priv
->tx_napis
= NULL
;
778 kmem_cache_destroy(priv
->txreq_cache
);
779 priv
->txreq_cache
= NULL
;
783 static void hfi1_ipoib_drain_tx_list(struct hfi1_ipoib_txq
*txq
)
785 struct sdma_txreq
*txreq
;
786 struct sdma_txreq
*txreq_tmp
;
787 atomic64_t
*complete_txreqs
= &txq
->complete_txreqs
;
789 list_for_each_entry_safe(txreq
, txreq_tmp
, &txq
->tx_list
, list
) {
790 struct ipoib_txreq
*tx
=
791 container_of(txreq
, struct ipoib_txreq
, txreq
);
793 list_del(&txreq
->list
);
794 sdma_txclean(txq
->priv
->dd
, &tx
->txreq
);
795 dev_kfree_skb_any(tx
->skb
);
796 kmem_cache_free(txq
->priv
->txreq_cache
, tx
);
797 atomic64_inc(complete_txreqs
);
800 if (hfi1_ipoib_used(txq
))
801 dd_dev_warn(txq
->priv
->dd
,
802 "txq %d not empty found %llu requests\n",
804 hfi1_ipoib_txreqs(txq
->sent_txreqs
,
805 atomic64_read(complete_txreqs
)));
808 void hfi1_ipoib_txreq_deinit(struct hfi1_ipoib_dev_priv
*priv
)
812 for (i
= 0; i
< priv
->netdev
->num_tx_queues
; i
++) {
813 struct hfi1_ipoib_txq
*txq
= &priv
->txqs
[i
];
815 iowait_cancel_work(&txq
->wait
);
816 iowait_sdma_drain(&txq
->wait
);
817 hfi1_ipoib_drain_tx_list(txq
);
818 netif_napi_del(txq
->napi
);
819 (void)hfi1_ipoib_drain_tx_ring(txq
, txq
->tx_ring
.max_items
);
820 vfree(txq
->tx_ring
.items
);
826 kfree(priv
->tx_napis
);
827 priv
->tx_napis
= NULL
;
829 kmem_cache_destroy(priv
->txreq_cache
);
830 priv
->txreq_cache
= NULL
;
833 void hfi1_ipoib_napi_tx_enable(struct net_device
*dev
)
835 struct hfi1_ipoib_dev_priv
*priv
= hfi1_ipoib_priv(dev
);
838 for (i
= 0; i
< dev
->num_tx_queues
; i
++) {
839 struct hfi1_ipoib_txq
*txq
= &priv
->txqs
[i
];
841 napi_enable(txq
->napi
);
845 void hfi1_ipoib_napi_tx_disable(struct net_device
*dev
)
847 struct hfi1_ipoib_dev_priv
*priv
= hfi1_ipoib_priv(dev
);
850 for (i
= 0; i
< dev
->num_tx_queues
; i
++) {
851 struct hfi1_ipoib_txq
*txq
= &priv
->txqs
[i
];
853 napi_disable(txq
->napi
);
854 (void)hfi1_ipoib_drain_tx_ring(txq
, txq
->tx_ring
.max_items
);