xref: /linux/drivers/infiniband/hw/hfi1/verbs_txreq.h (revision d642ef71)
1 /* SPDX-License-Identifier: GPL-2.0 OR BSD-3-Clause */
2 /*
3  * Copyright(c) 2016 - 2018 Intel Corporation.
4  */
5 
6 #ifndef HFI1_VERBS_TXREQ_H
7 #define HFI1_VERBS_TXREQ_H
8 
9 #include <linux/types.h>
10 #include <linux/slab.h>
11 
12 #include "verbs.h"
13 #include "sdma_txreq.h"
14 #include "iowait.h"
15 
16 struct verbs_txreq {
17 	struct hfi1_sdma_header	phdr;
18 	struct sdma_txreq       txreq;
19 	struct rvt_qp           *qp;
20 	struct rvt_swqe         *wqe;
21 	struct rvt_mregion	*mr;
22 	struct rvt_sge_state    *ss;
23 	struct sdma_engine     *sde;
24 	struct send_context     *psc;
25 	u16                     hdr_dwords;
26 	u16			s_cur_size;
27 };
28 
29 struct hfi1_ibdev;
30 struct verbs_txreq *__get_txreq(struct hfi1_ibdev *dev,
31 				struct rvt_qp *qp);
32 
33 #define VERBS_TXREQ_GFP (GFP_ATOMIC | __GFP_NOWARN)
34 static inline struct verbs_txreq *get_txreq(struct hfi1_ibdev *dev,
35 					    struct rvt_qp *qp)
36 	__must_hold(&qp->slock)
37 {
38 	struct verbs_txreq *tx;
39 	struct hfi1_qp_priv *priv = qp->priv;
40 
41 	tx = kmem_cache_alloc(dev->verbs_txreq_cache, VERBS_TXREQ_GFP);
42 	if (unlikely(!tx)) {
43 		/* call slow path to get the lock */
44 		tx = __get_txreq(dev, qp);
45 		if (!tx)
46 			return tx;
47 	}
48 	tx->qp = qp;
49 	tx->mr = NULL;
50 	tx->sde = priv->s_sde;
51 	tx->psc = priv->s_sendcontext;
52 	/* so that we can test if the sdma descriptors are there */
53 	tx->txreq.num_desc = 0;
54 	/* Set the header type */
55 	tx->phdr.hdr.hdr_type = priv->hdr_type;
56 	tx->txreq.flags = 0;
57 	return tx;
58 }
59 
60 static inline struct verbs_txreq *get_waiting_verbs_txreq(struct iowait_work *w)
61 {
62 	struct sdma_txreq *stx;
63 
64 	stx = iowait_get_txhead(w);
65 	if (stx)
66 		return container_of(stx, struct verbs_txreq, txreq);
67 	return NULL;
68 }
69 
70 static inline bool verbs_txreq_queued(struct iowait_work *w)
71 {
72 	return iowait_packet_queued(w);
73 }
74 
75 void hfi1_put_txreq(struct verbs_txreq *tx);
76 int verbs_txreq_init(struct hfi1_ibdev *dev);
77 void verbs_txreq_exit(struct hfi1_ibdev *dev);
78 
79 #endif                         /* HFI1_VERBS_TXREQ_H */
80