1*4882a593Smuzhiyun /*
2*4882a593Smuzhiyun * This file is part of the Chelsio T6 Ethernet driver for Linux.
3*4882a593Smuzhiyun *
4*4882a593Smuzhiyun * Copyright (c) 2017-2018 Chelsio Communications, Inc. All rights reserved.
5*4882a593Smuzhiyun *
6*4882a593Smuzhiyun * This software is available to you under a choice of one of two
7*4882a593Smuzhiyun * licenses. You may choose to be licensed under the terms of the GNU
8*4882a593Smuzhiyun * General Public License (GPL) Version 2, available from the file
9*4882a593Smuzhiyun * COPYING in the main directory of this source tree, or the
10*4882a593Smuzhiyun * OpenIB.org BSD license below:
11*4882a593Smuzhiyun *
12*4882a593Smuzhiyun * Redistribution and use in source and binary forms, with or
13*4882a593Smuzhiyun * without modification, are permitted provided that the following
14*4882a593Smuzhiyun * conditions are met:
15*4882a593Smuzhiyun *
16*4882a593Smuzhiyun * - Redistributions of source code must retain the above
17*4882a593Smuzhiyun * copyright notice, this list of conditions and the following
18*4882a593Smuzhiyun * disclaimer.
19*4882a593Smuzhiyun *
20*4882a593Smuzhiyun * - Redistributions in binary form must reproduce the above
21*4882a593Smuzhiyun * copyright notice, this list of conditions and the following
22*4882a593Smuzhiyun * disclaimer in the documentation and/or other materials
23*4882a593Smuzhiyun * provided with the distribution.
24*4882a593Smuzhiyun *
25*4882a593Smuzhiyun * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
26*4882a593Smuzhiyun * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
27*4882a593Smuzhiyun * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
28*4882a593Smuzhiyun * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
29*4882a593Smuzhiyun * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
30*4882a593Smuzhiyun * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
31*4882a593Smuzhiyun * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
32*4882a593Smuzhiyun * SOFTWARE.
33*4882a593Smuzhiyun */
34*4882a593Smuzhiyun
35*4882a593Smuzhiyun #include "cxgb4.h"
36*4882a593Smuzhiyun #include "t4_msg.h"
37*4882a593Smuzhiyun #include "srq.h"
38*4882a593Smuzhiyun
t4_init_srq(int srq_size)39*4882a593Smuzhiyun struct srq_data *t4_init_srq(int srq_size)
40*4882a593Smuzhiyun {
41*4882a593Smuzhiyun struct srq_data *s;
42*4882a593Smuzhiyun
43*4882a593Smuzhiyun s = kvzalloc(sizeof(*s), GFP_KERNEL);
44*4882a593Smuzhiyun if (!s)
45*4882a593Smuzhiyun return NULL;
46*4882a593Smuzhiyun
47*4882a593Smuzhiyun s->srq_size = srq_size;
48*4882a593Smuzhiyun init_completion(&s->comp);
49*4882a593Smuzhiyun mutex_init(&s->lock);
50*4882a593Smuzhiyun
51*4882a593Smuzhiyun return s;
52*4882a593Smuzhiyun }
53*4882a593Smuzhiyun
54*4882a593Smuzhiyun /* cxgb4_get_srq_entry: read the SRQ table entry
55*4882a593Smuzhiyun * @dev: Pointer to the net_device
56*4882a593Smuzhiyun * @idx: Index to the srq
57*4882a593Smuzhiyun * @entryp: pointer to the srq entry
58*4882a593Smuzhiyun *
59*4882a593Smuzhiyun * Sends CPL_SRQ_TABLE_REQ message for the given index.
60*4882a593Smuzhiyun * Contents will be returned in CPL_SRQ_TABLE_RPL message.
61*4882a593Smuzhiyun *
62*4882a593Smuzhiyun * Returns zero if the read is successful, else a error
63*4882a593Smuzhiyun * number will be returned. Caller should not use the srq
64*4882a593Smuzhiyun * entry if the return value is non-zero.
65*4882a593Smuzhiyun *
66*4882a593Smuzhiyun *
67*4882a593Smuzhiyun */
cxgb4_get_srq_entry(struct net_device * dev,int srq_idx,struct srq_entry * entryp)68*4882a593Smuzhiyun int cxgb4_get_srq_entry(struct net_device *dev,
69*4882a593Smuzhiyun int srq_idx, struct srq_entry *entryp)
70*4882a593Smuzhiyun {
71*4882a593Smuzhiyun struct cpl_srq_table_req *req;
72*4882a593Smuzhiyun struct adapter *adap;
73*4882a593Smuzhiyun struct sk_buff *skb;
74*4882a593Smuzhiyun struct srq_data *s;
75*4882a593Smuzhiyun int rc = -ENODEV;
76*4882a593Smuzhiyun
77*4882a593Smuzhiyun adap = netdev2adap(dev);
78*4882a593Smuzhiyun s = adap->srq;
79*4882a593Smuzhiyun
80*4882a593Smuzhiyun if (!(adap->flags & CXGB4_FULL_INIT_DONE) || !s)
81*4882a593Smuzhiyun goto out;
82*4882a593Smuzhiyun
83*4882a593Smuzhiyun skb = alloc_skb(sizeof(*req), GFP_KERNEL);
84*4882a593Smuzhiyun if (!skb)
85*4882a593Smuzhiyun return -ENOMEM;
86*4882a593Smuzhiyun req = (struct cpl_srq_table_req *)
87*4882a593Smuzhiyun __skb_put_zero(skb, sizeof(*req));
88*4882a593Smuzhiyun INIT_TP_WR(req, 0);
89*4882a593Smuzhiyun OPCODE_TID(req) = htonl(MK_OPCODE_TID(CPL_SRQ_TABLE_REQ,
90*4882a593Smuzhiyun TID_TID_V(srq_idx) |
91*4882a593Smuzhiyun TID_QID_V(adap->sge.fw_evtq.abs_id)));
92*4882a593Smuzhiyun req->idx = srq_idx;
93*4882a593Smuzhiyun
94*4882a593Smuzhiyun mutex_lock(&s->lock);
95*4882a593Smuzhiyun
96*4882a593Smuzhiyun s->entryp = entryp;
97*4882a593Smuzhiyun t4_mgmt_tx(adap, skb);
98*4882a593Smuzhiyun
99*4882a593Smuzhiyun rc = wait_for_completion_timeout(&s->comp, SRQ_WAIT_TO);
100*4882a593Smuzhiyun if (rc)
101*4882a593Smuzhiyun rc = 0;
102*4882a593Smuzhiyun else /* !rc means we timed out */
103*4882a593Smuzhiyun rc = -ETIMEDOUT;
104*4882a593Smuzhiyun
105*4882a593Smuzhiyun WARN_ON_ONCE(entryp->idx != srq_idx);
106*4882a593Smuzhiyun mutex_unlock(&s->lock);
107*4882a593Smuzhiyun out:
108*4882a593Smuzhiyun return rc;
109*4882a593Smuzhiyun }
110*4882a593Smuzhiyun EXPORT_SYMBOL(cxgb4_get_srq_entry);
111*4882a593Smuzhiyun
do_srq_table_rpl(struct adapter * adap,const struct cpl_srq_table_rpl * rpl)112*4882a593Smuzhiyun void do_srq_table_rpl(struct adapter *adap,
113*4882a593Smuzhiyun const struct cpl_srq_table_rpl *rpl)
114*4882a593Smuzhiyun {
115*4882a593Smuzhiyun unsigned int idx = TID_TID_G(GET_TID(rpl));
116*4882a593Smuzhiyun struct srq_data *s = adap->srq;
117*4882a593Smuzhiyun struct srq_entry *e;
118*4882a593Smuzhiyun
119*4882a593Smuzhiyun if (unlikely(rpl->status != CPL_CONTAINS_READ_RPL)) {
120*4882a593Smuzhiyun dev_err(adap->pdev_dev,
121*4882a593Smuzhiyun "Unexpected SRQ_TABLE_RPL status %u for entry %u\n",
122*4882a593Smuzhiyun rpl->status, idx);
123*4882a593Smuzhiyun goto out;
124*4882a593Smuzhiyun }
125*4882a593Smuzhiyun
126*4882a593Smuzhiyun /* Store the read entry */
127*4882a593Smuzhiyun e = s->entryp;
128*4882a593Smuzhiyun e->valid = 1;
129*4882a593Smuzhiyun e->idx = idx;
130*4882a593Smuzhiyun e->pdid = SRQT_PDID_G(be64_to_cpu(rpl->rsvd_pdid));
131*4882a593Smuzhiyun e->qlen = SRQT_QLEN_G(be32_to_cpu(rpl->qlen_qbase));
132*4882a593Smuzhiyun e->qbase = SRQT_QBASE_G(be32_to_cpu(rpl->qlen_qbase));
133*4882a593Smuzhiyun e->cur_msn = be16_to_cpu(rpl->cur_msn);
134*4882a593Smuzhiyun e->max_msn = be16_to_cpu(rpl->max_msn);
135*4882a593Smuzhiyun out:
136*4882a593Smuzhiyun complete(&s->comp);
137*4882a593Smuzhiyun }
138