1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35#include "cxgb4.h"
36#include "t4_msg.h"
37#include "srq.h"
38
39struct srq_data *t4_init_srq(int srq_size)
40{
41 struct srq_data *s;
42
43 s = kvzalloc(sizeof(*s), GFP_KERNEL);
44 if (!s)
45 return NULL;
46
47 s->srq_size = srq_size;
48 init_completion(&s->comp);
49 mutex_init(&s->lock);
50
51 return s;
52}
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68int cxgb4_get_srq_entry(struct net_device *dev,
69 int srq_idx, struct srq_entry *entryp)
70{
71 struct cpl_srq_table_req *req;
72 struct adapter *adap;
73 struct sk_buff *skb;
74 struct srq_data *s;
75 int rc = -ENODEV;
76
77 adap = netdev2adap(dev);
78 s = adap->srq;
79
80 if (!(adap->flags & FULL_INIT_DONE) || !s)
81 goto out;
82
83 skb = alloc_skb(sizeof(*req), GFP_KERNEL);
84 if (!skb)
85 return -ENOMEM;
86 req = (struct cpl_srq_table_req *)
87 __skb_put_zero(skb, sizeof(*req));
88 INIT_TP_WR(req, 0);
89 OPCODE_TID(req) = htonl(MK_OPCODE_TID(CPL_SRQ_TABLE_REQ,
90 TID_TID_V(srq_idx) |
91 TID_QID_V(adap->sge.fw_evtq.abs_id)));
92 req->idx = srq_idx;
93
94 mutex_lock(&s->lock);
95
96 s->entryp = entryp;
97 t4_mgmt_tx(adap, skb);
98
99 rc = wait_for_completion_timeout(&s->comp, SRQ_WAIT_TO);
100 if (rc)
101 rc = 0;
102 else
103 rc = -ETIMEDOUT;
104
105 WARN_ON_ONCE(entryp->idx != srq_idx);
106 mutex_unlock(&s->lock);
107out:
108 return rc;
109}
110EXPORT_SYMBOL(cxgb4_get_srq_entry);
111
112void do_srq_table_rpl(struct adapter *adap,
113 const struct cpl_srq_table_rpl *rpl)
114{
115 unsigned int idx = TID_TID_G(GET_TID(rpl));
116 struct srq_data *s = adap->srq;
117 struct srq_entry *e;
118
119 if (unlikely(rpl->status != CPL_CONTAINS_READ_RPL)) {
120 dev_err(adap->pdev_dev,
121 "Unexpected SRQ_TABLE_RPL status %u for entry %u\n",
122 rpl->status, idx);
123 goto out;
124 }
125
126
127 e = s->entryp;
128 e->valid = 1;
129 e->idx = idx;
130 e->pdid = SRQT_PDID_G(be64_to_cpu(rpl->rsvd_pdid));
131 e->qlen = SRQT_QLEN_G(be32_to_cpu(rpl->qlen_qbase));
132 e->qbase = SRQT_QBASE_G(be32_to_cpu(rpl->qlen_qbase));
133 e->cur_msn = be16_to_cpu(rpl->cur_msn);
134 e->max_msn = be16_to_cpu(rpl->max_msn);
135out:
136 complete(&s->comp);
137}
138