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#include "c2.h"
34#include <rdma/iw_cm.h>
35#include "c2_status.h"
36#include "c2_ae.h"
37
38static int c2_convert_cm_status(u32 c2_status)
39{
40 switch (c2_status) {
41 case C2_CONN_STATUS_SUCCESS:
42 return 0;
43 case C2_CONN_STATUS_REJECTED:
44 return -ENETRESET;
45 case C2_CONN_STATUS_REFUSED:
46 return -ECONNREFUSED;
47 case C2_CONN_STATUS_TIMEDOUT:
48 return -ETIMEDOUT;
49 case C2_CONN_STATUS_NETUNREACH:
50 return -ENETUNREACH;
51 case C2_CONN_STATUS_HOSTUNREACH:
52 return -EHOSTUNREACH;
53 case C2_CONN_STATUS_INVALID_RNIC:
54 return -EINVAL;
55 case C2_CONN_STATUS_INVALID_QP:
56 return -EINVAL;
57 case C2_CONN_STATUS_INVALID_QP_STATE:
58 return -EINVAL;
59 case C2_CONN_STATUS_ADDR_NOT_AVAIL:
60 return -EADDRNOTAVAIL;
61 default:
62 printk(KERN_ERR PFX
63 "%s - Unable to convert CM status: %d\n",
64 __func__, c2_status);
65 return -EIO;
66 }
67}
68
69static const char* to_event_str(int event)
70{
71 static const char* event_str[] = {
72 "CCAE_REMOTE_SHUTDOWN",
73 "CCAE_ACTIVE_CONNECT_RESULTS",
74 "CCAE_CONNECTION_REQUEST",
75 "CCAE_LLP_CLOSE_COMPLETE",
76 "CCAE_TERMINATE_MESSAGE_RECEIVED",
77 "CCAE_LLP_CONNECTION_RESET",
78 "CCAE_LLP_CONNECTION_LOST",
79 "CCAE_LLP_SEGMENT_SIZE_INVALID",
80 "CCAE_LLP_INVALID_CRC",
81 "CCAE_LLP_BAD_FPDU",
82 "CCAE_INVALID_DDP_VERSION",
83 "CCAE_INVALID_RDMA_VERSION",
84 "CCAE_UNEXPECTED_OPCODE",
85 "CCAE_INVALID_DDP_QUEUE_NUMBER",
86 "CCAE_RDMA_READ_NOT_ENABLED",
87 "CCAE_RDMA_WRITE_NOT_ENABLED",
88 "CCAE_RDMA_READ_TOO_SMALL",
89 "CCAE_NO_L_BIT",
90 "CCAE_TAGGED_INVALID_STAG",
91 "CCAE_TAGGED_BASE_BOUNDS_VIOLATION",
92 "CCAE_TAGGED_ACCESS_RIGHTS_VIOLATION",
93 "CCAE_TAGGED_INVALID_PD",
94 "CCAE_WRAP_ERROR",
95 "CCAE_BAD_CLOSE",
96 "CCAE_BAD_LLP_CLOSE",
97 "CCAE_INVALID_MSN_RANGE",
98 "CCAE_INVALID_MSN_GAP",
99 "CCAE_IRRQ_OVERFLOW",
100 "CCAE_IRRQ_MSN_GAP",
101 "CCAE_IRRQ_MSN_RANGE",
102 "CCAE_IRRQ_INVALID_STAG",
103 "CCAE_IRRQ_BASE_BOUNDS_VIOLATION",
104 "CCAE_IRRQ_ACCESS_RIGHTS_VIOLATION",
105 "CCAE_IRRQ_INVALID_PD",
106 "CCAE_IRRQ_WRAP_ERROR",
107 "CCAE_CQ_SQ_COMPLETION_OVERFLOW",
108 "CCAE_CQ_RQ_COMPLETION_ERROR",
109 "CCAE_QP_SRQ_WQE_ERROR",
110 "CCAE_QP_LOCAL_CATASTROPHIC_ERROR",
111 "CCAE_CQ_OVERFLOW",
112 "CCAE_CQ_OPERATION_ERROR",
113 "CCAE_SRQ_LIMIT_REACHED",
114 "CCAE_QP_RQ_LIMIT_REACHED",
115 "CCAE_SRQ_CATASTROPHIC_ERROR",
116 "CCAE_RNIC_CATASTROPHIC_ERROR"
117 };
118
119 if (event < CCAE_REMOTE_SHUTDOWN ||
120 event > CCAE_RNIC_CATASTROPHIC_ERROR)
121 return "<invalid event>";
122
123 event -= CCAE_REMOTE_SHUTDOWN;
124 return event_str[event];
125}
126
127static const char *to_qp_state_str(int state)
128{
129 switch (state) {
130 case C2_QP_STATE_IDLE:
131 return "C2_QP_STATE_IDLE";
132 case C2_QP_STATE_CONNECTING:
133 return "C2_QP_STATE_CONNECTING";
134 case C2_QP_STATE_RTS:
135 return "C2_QP_STATE_RTS";
136 case C2_QP_STATE_CLOSING:
137 return "C2_QP_STATE_CLOSING";
138 case C2_QP_STATE_TERMINATE:
139 return "C2_QP_STATE_TERMINATE";
140 case C2_QP_STATE_ERROR:
141 return "C2_QP_STATE_ERROR";
142 default:
143 return "<invalid QP state>";
144 }
145}
146
147void c2_ae_event(struct c2_dev *c2dev, u32 mq_index)
148{
149 struct c2_mq *mq = c2dev->qptr_array[mq_index];
150 union c2wr *wr;
151 void *resource_user_context;
152 struct iw_cm_event cm_event;
153 struct ib_event ib_event;
154 enum c2_resource_indicator resource_indicator;
155 enum c2_event_id event_id;
156 unsigned long flags;
157 int status;
158 struct sockaddr_in *laddr = (struct sockaddr_in *)&cm_event.local_addr;
159 struct sockaddr_in *raddr = (struct sockaddr_in *)&cm_event.remote_addr;
160
161
162
163
164 wr = c2_mq_consume(mq);
165 if (!wr)
166 return;
167
168 memset(&ib_event, 0, sizeof(ib_event));
169 memset(&cm_event, 0, sizeof(cm_event));
170
171 event_id = c2_wr_get_id(wr);
172 resource_indicator = be32_to_cpu(wr->ae.ae_generic.resource_type);
173 resource_user_context =
174 (void *) (unsigned long) wr->ae.ae_generic.user_context;
175
176 status = cm_event.status = c2_convert_cm_status(c2_wr_get_result(wr));
177
178 pr_debug("event received c2_dev=%p, event_id=%d, "
179 "resource_indicator=%d, user_context=%p, status = %d\n",
180 c2dev, event_id, resource_indicator, resource_user_context,
181 status);
182
183 switch (resource_indicator) {
184 case C2_RES_IND_QP:{
185
186 struct c2_qp *qp = (struct c2_qp *)resource_user_context;
187 struct iw_cm_id *cm_id = qp->cm_id;
188 struct c2wr_ae_active_connect_results *res;
189
190 if (!cm_id) {
191 pr_debug("event received, but cm_id is <nul>, qp=%p!\n",
192 qp);
193 goto ignore_it;
194 }
195 pr_debug("%s: event = %s, user_context=%llx, "
196 "resource_type=%x, "
197 "resource=%x, qp_state=%s\n",
198 __func__,
199 to_event_str(event_id),
200 (unsigned long long) wr->ae.ae_generic.user_context,
201 be32_to_cpu(wr->ae.ae_generic.resource_type),
202 be32_to_cpu(wr->ae.ae_generic.resource),
203 to_qp_state_str(be32_to_cpu(wr->ae.ae_generic.qp_state)));
204
205 c2_set_qp_state(qp, be32_to_cpu(wr->ae.ae_generic.qp_state));
206
207 switch (event_id) {
208 case CCAE_ACTIVE_CONNECT_RESULTS:
209 res = &wr->ae.ae_active_connect_results;
210 cm_event.event = IW_CM_EVENT_CONNECT_REPLY;
211 laddr->sin_addr.s_addr = res->laddr;
212 raddr->sin_addr.s_addr = res->raddr;
213 laddr->sin_port = res->lport;
214 raddr->sin_port = res->rport;
215 if (status == 0) {
216 cm_event.private_data_len =
217 be32_to_cpu(res->private_data_length);
218 cm_event.private_data = res->private_data;
219 } else {
220 spin_lock_irqsave(&qp->lock, flags);
221 if (qp->cm_id) {
222 qp->cm_id->rem_ref(qp->cm_id);
223 qp->cm_id = NULL;
224 }
225 spin_unlock_irqrestore(&qp->lock, flags);
226 cm_event.private_data_len = 0;
227 cm_event.private_data = NULL;
228 }
229 if (cm_id->event_handler)
230 cm_id->event_handler(cm_id, &cm_event);
231 break;
232 case CCAE_TERMINATE_MESSAGE_RECEIVED:
233 case CCAE_CQ_SQ_COMPLETION_OVERFLOW:
234 ib_event.device = &c2dev->ibdev;
235 ib_event.element.qp = &qp->ibqp;
236 ib_event.event = IB_EVENT_QP_REQ_ERR;
237
238 if (qp->ibqp.event_handler)
239 qp->ibqp.event_handler(&ib_event,
240 qp->ibqp.
241 qp_context);
242 break;
243 case CCAE_BAD_CLOSE:
244 case CCAE_LLP_CLOSE_COMPLETE:
245 case CCAE_LLP_CONNECTION_RESET:
246 case CCAE_LLP_CONNECTION_LOST:
247 BUG_ON(cm_id->event_handler==(void*)0x6b6b6b6b);
248
249 spin_lock_irqsave(&qp->lock, flags);
250 if (qp->cm_id) {
251 qp->cm_id->rem_ref(qp->cm_id);
252 qp->cm_id = NULL;
253 }
254 spin_unlock_irqrestore(&qp->lock, flags);
255 cm_event.event = IW_CM_EVENT_CLOSE;
256 cm_event.status = 0;
257 if (cm_id->event_handler)
258 cm_id->event_handler(cm_id, &cm_event);
259 break;
260 default:
261 BUG_ON(1);
262 pr_debug("%s:%d Unexpected event_id=%d on QP=%p, "
263 "CM_ID=%p\n",
264 __func__, __LINE__,
265 event_id, qp, cm_id);
266 break;
267 }
268 break;
269 }
270
271 case C2_RES_IND_EP:{
272
273 struct c2wr_ae_connection_request *req =
274 &wr->ae.ae_connection_request;
275 struct iw_cm_id *cm_id =
276 (struct iw_cm_id *)resource_user_context;
277
278 pr_debug("C2_RES_IND_EP event_id=%d\n", event_id);
279 if (event_id != CCAE_CONNECTION_REQUEST) {
280 pr_debug("%s: Invalid event_id: %d\n",
281 __func__, event_id);
282 break;
283 }
284 cm_event.event = IW_CM_EVENT_CONNECT_REQUEST;
285 cm_event.provider_data = (void*)(unsigned long)req->cr_handle;
286 laddr->sin_addr.s_addr = req->laddr;
287 raddr->sin_addr.s_addr = req->raddr;
288 laddr->sin_port = req->lport;
289 raddr->sin_port = req->rport;
290 cm_event.private_data_len =
291 be32_to_cpu(req->private_data_length);
292 cm_event.private_data = req->private_data;
293
294
295
296
297 cm_event.ird = cm_event.ord = 128;
298
299 if (cm_id->event_handler)
300 cm_id->event_handler(cm_id, &cm_event);
301 break;
302 }
303
304 case C2_RES_IND_CQ:{
305 struct c2_cq *cq =
306 (struct c2_cq *) resource_user_context;
307
308 pr_debug("IB_EVENT_CQ_ERR\n");
309 ib_event.device = &c2dev->ibdev;
310 ib_event.element.cq = &cq->ibcq;
311 ib_event.event = IB_EVENT_CQ_ERR;
312
313 if (cq->ibcq.event_handler)
314 cq->ibcq.event_handler(&ib_event,
315 cq->ibcq.cq_context);
316 break;
317 }
318
319 default:
320 printk("Bad resource indicator = %d\n",
321 resource_indicator);
322 break;
323 }
324
325 ignore_it:
326 c2_mq_free(mq);
327}
328