1*4882a593Smuzhiyun /*
2*4882a593Smuzhiyun * Copyright(c) 2016 - 2018 Intel Corporation.
3*4882a593Smuzhiyun *
4*4882a593Smuzhiyun * This file is provided under a dual BSD/GPLv2 license. When using or
5*4882a593Smuzhiyun * redistributing this file, you may do so under either license.
6*4882a593Smuzhiyun *
7*4882a593Smuzhiyun * GPL LICENSE SUMMARY
8*4882a593Smuzhiyun *
9*4882a593Smuzhiyun * This program is free software; you can redistribute it and/or modify
10*4882a593Smuzhiyun * it under the terms of version 2 of the GNU General Public License as
11*4882a593Smuzhiyun * published by the Free Software Foundation.
12*4882a593Smuzhiyun *
13*4882a593Smuzhiyun * This program is distributed in the hope that it will be useful, but
14*4882a593Smuzhiyun * WITHOUT ANY WARRANTY; without even the implied warranty of
15*4882a593Smuzhiyun * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16*4882a593Smuzhiyun * General Public License for more details.
17*4882a593Smuzhiyun *
18*4882a593Smuzhiyun * BSD LICENSE
19*4882a593Smuzhiyun *
20*4882a593Smuzhiyun * Redistribution and use in source and binary forms, with or without
21*4882a593Smuzhiyun * modification, are permitted provided that the following conditions
22*4882a593Smuzhiyun * are met:
23*4882a593Smuzhiyun *
24*4882a593Smuzhiyun * - Redistributions of source code must retain the above copyright
25*4882a593Smuzhiyun * notice, this list of conditions and the following disclaimer.
26*4882a593Smuzhiyun * - Redistributions in binary form must reproduce the above copyright
27*4882a593Smuzhiyun * notice, this list of conditions and the following disclaimer in
28*4882a593Smuzhiyun * the documentation and/or other materials provided with the
29*4882a593Smuzhiyun * distribution.
30*4882a593Smuzhiyun * - Neither the name of Intel Corporation nor the names of its
31*4882a593Smuzhiyun * contributors may be used to endorse or promote products derived
32*4882a593Smuzhiyun * from this software without specific prior written permission.
33*4882a593Smuzhiyun *
34*4882a593Smuzhiyun * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
35*4882a593Smuzhiyun * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
36*4882a593Smuzhiyun * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
37*4882a593Smuzhiyun * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
38*4882a593Smuzhiyun * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
39*4882a593Smuzhiyun * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
40*4882a593Smuzhiyun * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
41*4882a593Smuzhiyun * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
42*4882a593Smuzhiyun * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
43*4882a593Smuzhiyun * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
44*4882a593Smuzhiyun * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
45*4882a593Smuzhiyun *
46*4882a593Smuzhiyun */
47*4882a593Smuzhiyun
48*4882a593Smuzhiyun #include "hfi.h"
49*4882a593Smuzhiyun #include "verbs_txreq.h"
50*4882a593Smuzhiyun #include "qp.h"
51*4882a593Smuzhiyun #include "trace.h"
52*4882a593Smuzhiyun
53*4882a593Smuzhiyun #define TXREQ_LEN 24
54*4882a593Smuzhiyun
hfi1_put_txreq(struct verbs_txreq * tx)55*4882a593Smuzhiyun void hfi1_put_txreq(struct verbs_txreq *tx)
56*4882a593Smuzhiyun {
57*4882a593Smuzhiyun struct hfi1_ibdev *dev;
58*4882a593Smuzhiyun struct rvt_qp *qp;
59*4882a593Smuzhiyun unsigned long flags;
60*4882a593Smuzhiyun unsigned int seq;
61*4882a593Smuzhiyun struct hfi1_qp_priv *priv;
62*4882a593Smuzhiyun
63*4882a593Smuzhiyun qp = tx->qp;
64*4882a593Smuzhiyun dev = to_idev(qp->ibqp.device);
65*4882a593Smuzhiyun
66*4882a593Smuzhiyun if (tx->mr)
67*4882a593Smuzhiyun rvt_put_mr(tx->mr);
68*4882a593Smuzhiyun
69*4882a593Smuzhiyun sdma_txclean(dd_from_dev(dev), &tx->txreq);
70*4882a593Smuzhiyun
71*4882a593Smuzhiyun /* Free verbs_txreq and return to slab cache */
72*4882a593Smuzhiyun kmem_cache_free(dev->verbs_txreq_cache, tx);
73*4882a593Smuzhiyun
74*4882a593Smuzhiyun do {
75*4882a593Smuzhiyun seq = read_seqbegin(&dev->txwait_lock);
76*4882a593Smuzhiyun if (!list_empty(&dev->txwait)) {
77*4882a593Smuzhiyun struct iowait *wait;
78*4882a593Smuzhiyun
79*4882a593Smuzhiyun write_seqlock_irqsave(&dev->txwait_lock, flags);
80*4882a593Smuzhiyun wait = list_first_entry(&dev->txwait, struct iowait,
81*4882a593Smuzhiyun list);
82*4882a593Smuzhiyun qp = iowait_to_qp(wait);
83*4882a593Smuzhiyun priv = qp->priv;
84*4882a593Smuzhiyun list_del_init(&priv->s_iowait.list);
85*4882a593Smuzhiyun /* refcount held until actual wake up */
86*4882a593Smuzhiyun write_sequnlock_irqrestore(&dev->txwait_lock, flags);
87*4882a593Smuzhiyun hfi1_qp_wakeup(qp, RVT_S_WAIT_TX);
88*4882a593Smuzhiyun break;
89*4882a593Smuzhiyun }
90*4882a593Smuzhiyun } while (read_seqretry(&dev->txwait_lock, seq));
91*4882a593Smuzhiyun }
92*4882a593Smuzhiyun
__get_txreq(struct hfi1_ibdev * dev,struct rvt_qp * qp)93*4882a593Smuzhiyun struct verbs_txreq *__get_txreq(struct hfi1_ibdev *dev,
94*4882a593Smuzhiyun struct rvt_qp *qp)
95*4882a593Smuzhiyun __must_hold(&qp->s_lock)
96*4882a593Smuzhiyun {
97*4882a593Smuzhiyun struct verbs_txreq *tx = NULL;
98*4882a593Smuzhiyun
99*4882a593Smuzhiyun write_seqlock(&dev->txwait_lock);
100*4882a593Smuzhiyun if (ib_rvt_state_ops[qp->state] & RVT_PROCESS_RECV_OK) {
101*4882a593Smuzhiyun struct hfi1_qp_priv *priv;
102*4882a593Smuzhiyun
103*4882a593Smuzhiyun tx = kmem_cache_alloc(dev->verbs_txreq_cache, VERBS_TXREQ_GFP);
104*4882a593Smuzhiyun if (tx)
105*4882a593Smuzhiyun goto out;
106*4882a593Smuzhiyun priv = qp->priv;
107*4882a593Smuzhiyun if (list_empty(&priv->s_iowait.list)) {
108*4882a593Smuzhiyun dev->n_txwait++;
109*4882a593Smuzhiyun qp->s_flags |= RVT_S_WAIT_TX;
110*4882a593Smuzhiyun list_add_tail(&priv->s_iowait.list, &dev->txwait);
111*4882a593Smuzhiyun priv->s_iowait.lock = &dev->txwait_lock;
112*4882a593Smuzhiyun trace_hfi1_qpsleep(qp, RVT_S_WAIT_TX);
113*4882a593Smuzhiyun rvt_get_qp(qp);
114*4882a593Smuzhiyun }
115*4882a593Smuzhiyun qp->s_flags &= ~RVT_S_BUSY;
116*4882a593Smuzhiyun }
117*4882a593Smuzhiyun out:
118*4882a593Smuzhiyun write_sequnlock(&dev->txwait_lock);
119*4882a593Smuzhiyun return tx;
120*4882a593Smuzhiyun }
121*4882a593Smuzhiyun
verbs_txreq_init(struct hfi1_ibdev * dev)122*4882a593Smuzhiyun int verbs_txreq_init(struct hfi1_ibdev *dev)
123*4882a593Smuzhiyun {
124*4882a593Smuzhiyun char buf[TXREQ_LEN];
125*4882a593Smuzhiyun struct hfi1_devdata *dd = dd_from_dev(dev);
126*4882a593Smuzhiyun
127*4882a593Smuzhiyun snprintf(buf, sizeof(buf), "hfi1_%u_vtxreq_cache", dd->unit);
128*4882a593Smuzhiyun dev->verbs_txreq_cache = kmem_cache_create(buf,
129*4882a593Smuzhiyun sizeof(struct verbs_txreq),
130*4882a593Smuzhiyun 0, SLAB_HWCACHE_ALIGN,
131*4882a593Smuzhiyun NULL);
132*4882a593Smuzhiyun if (!dev->verbs_txreq_cache)
133*4882a593Smuzhiyun return -ENOMEM;
134*4882a593Smuzhiyun return 0;
135*4882a593Smuzhiyun }
136*4882a593Smuzhiyun
verbs_txreq_exit(struct hfi1_ibdev * dev)137*4882a593Smuzhiyun void verbs_txreq_exit(struct hfi1_ibdev *dev)
138*4882a593Smuzhiyun {
139*4882a593Smuzhiyun kmem_cache_destroy(dev->verbs_txreq_cache);
140*4882a593Smuzhiyun dev->verbs_txreq_cache = NULL;
141*4882a593Smuzhiyun }
142