Pull acpica into release branch
[pandora-kernel.git] / drivers / infiniband / hw / ipath / ipath_ud.c
1 /*
2  * Copyright (c) 2005, 2006 PathScale, Inc. All rights reserved.
3  *
4  * This software is available to you under a choice of one of two
5  * licenses.  You may choose to be licensed under the terms of the GNU
6  * General Public License (GPL) Version 2, available from the file
7  * COPYING in the main directory of this source tree, or the
8  * OpenIB.org BSD license below:
9  *
10  *     Redistribution and use in source and binary forms, with or
11  *     without modification, are permitted provided that the following
12  *     conditions are met:
13  *
14  *      - Redistributions of source code must retain the above
15  *        copyright notice, this list of conditions and the following
16  *        disclaimer.
17  *
18  *      - Redistributions in binary form must reproduce the above
19  *        copyright notice, this list of conditions and the following
20  *        disclaimer in the documentation and/or other materials
21  *        provided with the distribution.
22  *
23  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
24  * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
25  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
26  * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
27  * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
28  * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
29  * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
30  * SOFTWARE.
31  */
32
33 #include <rdma/ib_smi.h>
34
35 #include "ipath_verbs.h"
36 #include "ips_common.h"
37
38 /**
39  * ipath_ud_loopback - handle send on loopback QPs
40  * @sqp: the QP
41  * @ss: the SGE state
42  * @length: the length of the data to send
43  * @wr: the work request
44  * @wc: the work completion entry
45  *
46  * This is called from ipath_post_ud_send() to forward a WQE addressed
47  * to the same HCA.
48  */
49 static void ipath_ud_loopback(struct ipath_qp *sqp,
50                               struct ipath_sge_state *ss,
51                               u32 length, struct ib_send_wr *wr,
52                               struct ib_wc *wc)
53 {
54         struct ipath_ibdev *dev = to_idev(sqp->ibqp.device);
55         struct ipath_qp *qp;
56         struct ib_ah_attr *ah_attr;
57         unsigned long flags;
58         struct ipath_rq *rq;
59         struct ipath_srq *srq;
60         struct ipath_sge_state rsge;
61         struct ipath_sge *sge;
62         struct ipath_rwqe *wqe;
63
64         qp = ipath_lookup_qpn(&dev->qp_table, wr->wr.ud.remote_qpn);
65         if (!qp)
66                 return;
67
68         /*
69          * Check that the qkey matches (except for QP0, see 9.6.1.4.1).
70          * Qkeys with the high order bit set mean use the
71          * qkey from the QP context instead of the WR (see 10.2.5).
72          */
73         if (unlikely(qp->ibqp.qp_num &&
74                      ((int) wr->wr.ud.remote_qkey < 0
75                       ? qp->qkey : wr->wr.ud.remote_qkey) != qp->qkey)) {
76                 /* XXX OK to lose a count once in a while. */
77                 dev->qkey_violations++;
78                 dev->n_pkt_drops++;
79                 goto done;
80         }
81
82         /*
83          * A GRH is expected to preceed the data even if not
84          * present on the wire.
85          */
86         wc->byte_len = length + sizeof(struct ib_grh);
87
88         if (wr->opcode == IB_WR_SEND_WITH_IMM) {
89                 wc->wc_flags = IB_WC_WITH_IMM;
90                 wc->imm_data = wr->imm_data;
91         } else {
92                 wc->wc_flags = 0;
93                 wc->imm_data = 0;
94         }
95
96         /*
97          * Get the next work request entry to find where to put the data.
98          * Note that it is safe to drop the lock after changing rq->tail
99          * since ipath_post_receive() won't fill the empty slot.
100          */
101         if (qp->ibqp.srq) {
102                 srq = to_isrq(qp->ibqp.srq);
103                 rq = &srq->rq;
104         } else {
105                 srq = NULL;
106                 rq = &qp->r_rq;
107         }
108         spin_lock_irqsave(&rq->lock, flags);
109         if (rq->tail == rq->head) {
110                 spin_unlock_irqrestore(&rq->lock, flags);
111                 dev->n_pkt_drops++;
112                 goto done;
113         }
114         /* Silently drop packets which are too big. */
115         wqe = get_rwqe_ptr(rq, rq->tail);
116         if (wc->byte_len > wqe->length) {
117                 spin_unlock_irqrestore(&rq->lock, flags);
118                 dev->n_pkt_drops++;
119                 goto done;
120         }
121         wc->wr_id = wqe->wr_id;
122         rsge.sge = wqe->sg_list[0];
123         rsge.sg_list = wqe->sg_list + 1;
124         rsge.num_sge = wqe->num_sge;
125         if (++rq->tail >= rq->size)
126                 rq->tail = 0;
127         if (srq && srq->ibsrq.event_handler) {
128                 u32 n;
129
130                 if (rq->head < rq->tail)
131                         n = rq->size + rq->head - rq->tail;
132                 else
133                         n = rq->head - rq->tail;
134                 if (n < srq->limit) {
135                         struct ib_event ev;
136
137                         srq->limit = 0;
138                         spin_unlock_irqrestore(&rq->lock, flags);
139                         ev.device = qp->ibqp.device;
140                         ev.element.srq = qp->ibqp.srq;
141                         ev.event = IB_EVENT_SRQ_LIMIT_REACHED;
142                         srq->ibsrq.event_handler(&ev,
143                                                  srq->ibsrq.srq_context);
144                 } else
145                         spin_unlock_irqrestore(&rq->lock, flags);
146         } else
147                 spin_unlock_irqrestore(&rq->lock, flags);
148         ah_attr = &to_iah(wr->wr.ud.ah)->attr;
149         if (ah_attr->ah_flags & IB_AH_GRH) {
150                 ipath_copy_sge(&rsge, &ah_attr->grh, sizeof(struct ib_grh));
151                 wc->wc_flags |= IB_WC_GRH;
152         } else
153                 ipath_skip_sge(&rsge, sizeof(struct ib_grh));
154         sge = &ss->sge;
155         while (length) {
156                 u32 len = sge->length;
157
158                 if (len > length)
159                         len = length;
160                 BUG_ON(len == 0);
161                 ipath_copy_sge(&rsge, sge->vaddr, len);
162                 sge->vaddr += len;
163                 sge->length -= len;
164                 sge->sge_length -= len;
165                 if (sge->sge_length == 0) {
166                         if (--ss->num_sge)
167                                 *sge = *ss->sg_list++;
168                 } else if (sge->length == 0 && sge->mr != NULL) {
169                         if (++sge->n >= IPATH_SEGSZ) {
170                                 if (++sge->m >= sge->mr->mapsz)
171                                         break;
172                                 sge->n = 0;
173                         }
174                         sge->vaddr =
175                                 sge->mr->map[sge->m]->segs[sge->n].vaddr;
176                         sge->length =
177                                 sge->mr->map[sge->m]->segs[sge->n].length;
178                 }
179                 length -= len;
180         }
181         wc->status = IB_WC_SUCCESS;
182         wc->opcode = IB_WC_RECV;
183         wc->vendor_err = 0;
184         wc->qp_num = qp->ibqp.qp_num;
185         wc->src_qp = sqp->ibqp.qp_num;
186         /* XXX do we know which pkey matched? Only needed for GSI. */
187         wc->pkey_index = 0;
188         wc->slid = ipath_layer_get_lid(dev->dd) |
189                 (ah_attr->src_path_bits &
190                  ((1 << (dev->mkeyprot_resv_lmc & 7)) - 1));
191         wc->sl = ah_attr->sl;
192         wc->dlid_path_bits =
193                 ah_attr->dlid & ((1 << (dev->mkeyprot_resv_lmc & 7)) - 1);
194         /* Signal completion event if the solicited bit is set. */
195         ipath_cq_enter(to_icq(qp->ibqp.recv_cq), wc,
196                        wr->send_flags & IB_SEND_SOLICITED);
197
198 done:
199         if (atomic_dec_and_test(&qp->refcount))
200                 wake_up(&qp->wait);
201 }
202
203 /**
204  * ipath_post_ud_send - post a UD send on QP
205  * @qp: the QP
206  * @wr: the work request
207  *
208  * Note that we actually send the data as it is posted instead of putting
209  * the request into a ring buffer.  If we wanted to use a ring buffer,
210  * we would need to save a reference to the destination address in the SWQE.
211  */
212 int ipath_post_ud_send(struct ipath_qp *qp, struct ib_send_wr *wr)
213 {
214         struct ipath_ibdev *dev = to_idev(qp->ibqp.device);
215         struct ipath_other_headers *ohdr;
216         struct ib_ah_attr *ah_attr;
217         struct ipath_sge_state ss;
218         struct ipath_sge *sg_list;
219         struct ib_wc wc;
220         u32 hwords;
221         u32 nwords;
222         u32 len;
223         u32 extra_bytes;
224         u32 bth0;
225         u16 lrh0;
226         u16 lid;
227         int i;
228         int ret;
229
230         if (!(ib_ipath_state_ops[qp->state] & IPATH_PROCESS_SEND_OK)) {
231                 ret = 0;
232                 goto bail;
233         }
234
235         /* IB spec says that num_sge == 0 is OK. */
236         if (wr->num_sge > qp->s_max_sge) {
237                 ret = -EINVAL;
238                 goto bail;
239         }
240
241         if (wr->num_sge > 1) {
242                 sg_list = kmalloc((qp->s_max_sge - 1) * sizeof(*sg_list),
243                                   GFP_ATOMIC);
244                 if (!sg_list) {
245                         ret = -ENOMEM;
246                         goto bail;
247                 }
248         } else
249                 sg_list = NULL;
250
251         /* Check the buffer to send. */
252         ss.sg_list = sg_list;
253         ss.sge.mr = NULL;
254         ss.sge.vaddr = NULL;
255         ss.sge.length = 0;
256         ss.sge.sge_length = 0;
257         ss.num_sge = 0;
258         len = 0;
259         for (i = 0; i < wr->num_sge; i++) {
260                 /* Check LKEY */
261                 if (to_ipd(qp->ibqp.pd)->user && wr->sg_list[i].lkey == 0) {
262                         ret = -EINVAL;
263                         goto bail;
264                 }
265
266                 if (wr->sg_list[i].length == 0)
267                         continue;
268                 if (!ipath_lkey_ok(&dev->lk_table, ss.num_sge ?
269                                    sg_list + ss.num_sge - 1 : &ss.sge,
270                                    &wr->sg_list[i], 0)) {
271                         ret = -EINVAL;
272                         goto bail;
273                 }
274                 len += wr->sg_list[i].length;
275                 ss.num_sge++;
276         }
277         extra_bytes = (4 - len) & 3;
278         nwords = (len + extra_bytes) >> 2;
279
280         /* Construct the header. */
281         ah_attr = &to_iah(wr->wr.ud.ah)->attr;
282         if (ah_attr->dlid == 0) {
283                 ret = -EINVAL;
284                 goto bail;
285         }
286         if (ah_attr->dlid >= IPS_MULTICAST_LID_BASE) {
287                 if (ah_attr->dlid != IPS_PERMISSIVE_LID)
288                         dev->n_multicast_xmit++;
289                 else
290                         dev->n_unicast_xmit++;
291         } else {
292                 dev->n_unicast_xmit++;
293                 lid = ah_attr->dlid &
294                         ~((1 << (dev->mkeyprot_resv_lmc & 7)) - 1);
295                 if (unlikely(lid == ipath_layer_get_lid(dev->dd))) {
296                         /*
297                          * Pass in an uninitialized ib_wc to save stack
298                          * space.
299                          */
300                         ipath_ud_loopback(qp, &ss, len, wr, &wc);
301                         goto done;
302                 }
303         }
304         if (ah_attr->ah_flags & IB_AH_GRH) {
305                 /* Header size in 32-bit words. */
306                 hwords = 17;
307                 lrh0 = IPS_LRH_GRH;
308                 ohdr = &qp->s_hdr.u.l.oth;
309                 qp->s_hdr.u.l.grh.version_tclass_flow =
310                         cpu_to_be32((6 << 28) |
311                                     (ah_attr->grh.traffic_class << 20) |
312                                     ah_attr->grh.flow_label);
313                 qp->s_hdr.u.l.grh.paylen =
314                         cpu_to_be16(((wr->opcode ==
315                                       IB_WR_SEND_WITH_IMM ? 6 : 5) +
316                                      nwords + SIZE_OF_CRC) << 2);
317                 /* next_hdr is defined by C8-7 in ch. 8.4.1 */
318                 qp->s_hdr.u.l.grh.next_hdr = 0x1B;
319                 qp->s_hdr.u.l.grh.hop_limit = ah_attr->grh.hop_limit;
320                 /* The SGID is 32-bit aligned. */
321                 qp->s_hdr.u.l.grh.sgid.global.subnet_prefix =
322                         dev->gid_prefix;
323                 qp->s_hdr.u.l.grh.sgid.global.interface_id =
324                         ipath_layer_get_guid(dev->dd);
325                 qp->s_hdr.u.l.grh.dgid = ah_attr->grh.dgid;
326                 /*
327                  * Don't worry about sending to locally attached multicast
328                  * QPs.  It is unspecified by the spec. what happens.
329                  */
330         } else {
331                 /* Header size in 32-bit words. */
332                 hwords = 7;
333                 lrh0 = IPS_LRH_BTH;
334                 ohdr = &qp->s_hdr.u.oth;
335         }
336         if (wr->opcode == IB_WR_SEND_WITH_IMM) {
337                 ohdr->u.ud.imm_data = wr->imm_data;
338                 wc.imm_data = wr->imm_data;
339                 hwords += 1;
340                 bth0 = IB_OPCODE_UD_SEND_ONLY_WITH_IMMEDIATE << 24;
341         } else if (wr->opcode == IB_WR_SEND) {
342                 wc.imm_data = 0;
343                 bth0 = IB_OPCODE_UD_SEND_ONLY << 24;
344         } else {
345                 ret = -EINVAL;
346                 goto bail;
347         }
348         lrh0 |= ah_attr->sl << 4;
349         if (qp->ibqp.qp_type == IB_QPT_SMI)
350                 lrh0 |= 0xF000; /* Set VL (see ch. 13.5.3.1) */
351         qp->s_hdr.lrh[0] = cpu_to_be16(lrh0);
352         qp->s_hdr.lrh[1] = cpu_to_be16(ah_attr->dlid);  /* DEST LID */
353         qp->s_hdr.lrh[2] = cpu_to_be16(hwords + nwords + SIZE_OF_CRC);
354         lid = ipath_layer_get_lid(dev->dd);
355         if (lid) {
356                 lid |= ah_attr->src_path_bits &
357                         ((1 << (dev->mkeyprot_resv_lmc & 7)) - 1);
358                 qp->s_hdr.lrh[3] = cpu_to_be16(lid);
359         } else
360                 qp->s_hdr.lrh[3] = IB_LID_PERMISSIVE;
361         if (wr->send_flags & IB_SEND_SOLICITED)
362                 bth0 |= 1 << 23;
363         bth0 |= extra_bytes << 20;
364         bth0 |= qp->ibqp.qp_type == IB_QPT_SMI ? IPS_DEFAULT_P_KEY :
365                 ipath_layer_get_pkey(dev->dd, qp->s_pkey_index);
366         ohdr->bth[0] = cpu_to_be32(bth0);
367         /*
368          * Use the multicast QP if the destination LID is a multicast LID.
369          */
370         ohdr->bth[1] = ah_attr->dlid >= IPS_MULTICAST_LID_BASE &&
371                 ah_attr->dlid != IPS_PERMISSIVE_LID ?
372                 __constant_cpu_to_be32(IPS_MULTICAST_QPN) :
373                 cpu_to_be32(wr->wr.ud.remote_qpn);
374         /* XXX Could lose a PSN count but not worth locking */
375         ohdr->bth[2] = cpu_to_be32(qp->s_next_psn++ & IPS_PSN_MASK);
376         /*
377          * Qkeys with the high order bit set mean use the
378          * qkey from the QP context instead of the WR (see 10.2.5).
379          */
380         ohdr->u.ud.deth[0] = cpu_to_be32((int)wr->wr.ud.remote_qkey < 0 ?
381                                          qp->qkey : wr->wr.ud.remote_qkey);
382         ohdr->u.ud.deth[1] = cpu_to_be32(qp->ibqp.qp_num);
383         if (ipath_verbs_send(dev->dd, hwords, (u32 *) &qp->s_hdr,
384                              len, &ss))
385                 dev->n_no_piobuf++;
386
387 done:
388         /* Queue the completion status entry. */
389         if (!test_bit(IPATH_S_SIGNAL_REQ_WR, &qp->s_flags) ||
390             (wr->send_flags & IB_SEND_SIGNALED)) {
391                 wc.wr_id = wr->wr_id;
392                 wc.status = IB_WC_SUCCESS;
393                 wc.vendor_err = 0;
394                 wc.opcode = IB_WC_SEND;
395                 wc.byte_len = len;
396                 wc.qp_num = qp->ibqp.qp_num;
397                 wc.src_qp = 0;
398                 wc.wc_flags = 0;
399                 /* XXX initialize other fields? */
400                 ipath_cq_enter(to_icq(qp->ibqp.send_cq), &wc, 0);
401         }
402         kfree(sg_list);
403
404         ret = 0;
405
406 bail:
407         return ret;
408 }
409
410 /**
411  * ipath_ud_rcv - receive an incoming UD packet
412  * @dev: the device the packet came in on
413  * @hdr: the packet header
414  * @has_grh: true if the packet has a GRH
415  * @data: the packet data
416  * @tlen: the packet length
417  * @qp: the QP the packet came on
418  *
419  * This is called from ipath_qp_rcv() to process an incoming UD packet
420  * for the given QP.
421  * Called at interrupt level.
422  */
423 void ipath_ud_rcv(struct ipath_ibdev *dev, struct ipath_ib_header *hdr,
424                   int has_grh, void *data, u32 tlen, struct ipath_qp *qp)
425 {
426         struct ipath_other_headers *ohdr;
427         int opcode;
428         u32 hdrsize;
429         u32 pad;
430         unsigned long flags;
431         struct ib_wc wc;
432         u32 qkey;
433         u32 src_qp;
434         struct ipath_rq *rq;
435         struct ipath_srq *srq;
436         struct ipath_rwqe *wqe;
437         u16 dlid;
438         int header_in_data;
439
440         /* Check for GRH */
441         if (!has_grh) {
442                 ohdr = &hdr->u.oth;
443                 hdrsize = 8 + 12 + 8;   /* LRH + BTH + DETH */
444                 qkey = be32_to_cpu(ohdr->u.ud.deth[0]);
445                 src_qp = be32_to_cpu(ohdr->u.ud.deth[1]);
446                 header_in_data = 0;
447         } else {
448                 ohdr = &hdr->u.l.oth;
449                 hdrsize = 8 + 40 + 12 + 8; /* LRH + GRH + BTH + DETH */
450                 /*
451                  * The header with GRH is 68 bytes and the core driver sets
452                  * the eager header buffer size to 56 bytes so the last 12
453                  * bytes of the IB header is in the data buffer.
454                  */
455                 header_in_data =
456                         ipath_layer_get_rcvhdrentsize(dev->dd) == 16;
457                 if (header_in_data) {
458                         qkey = be32_to_cpu(((__be32 *) data)[1]);
459                         src_qp = be32_to_cpu(((__be32 *) data)[2]);
460                         data += 12;
461                 } else {
462                         qkey = be32_to_cpu(ohdr->u.ud.deth[0]);
463                         src_qp = be32_to_cpu(ohdr->u.ud.deth[1]);
464                 }
465         }
466         src_qp &= IPS_QPN_MASK;
467
468         /*
469          * Check that the permissive LID is only used on QP0
470          * and the QKEY matches (see 9.6.1.4.1 and 9.6.1.5.1).
471          */
472         if (qp->ibqp.qp_num) {
473                 if (unlikely(hdr->lrh[1] == IB_LID_PERMISSIVE ||
474                              hdr->lrh[3] == IB_LID_PERMISSIVE)) {
475                         dev->n_pkt_drops++;
476                         goto bail;
477                 }
478                 if (unlikely(qkey != qp->qkey)) {
479                         /* XXX OK to lose a count once in a while. */
480                         dev->qkey_violations++;
481                         dev->n_pkt_drops++;
482                         goto bail;
483                 }
484         } else if (hdr->lrh[1] == IB_LID_PERMISSIVE ||
485                    hdr->lrh[3] == IB_LID_PERMISSIVE) {
486                 struct ib_smp *smp = (struct ib_smp *) data;
487
488                 if (smp->mgmt_class != IB_MGMT_CLASS_SUBN_DIRECTED_ROUTE) {
489                         dev->n_pkt_drops++;
490                         goto bail;
491                 }
492         }
493
494         /* Get the number of bytes the message was padded by. */
495         pad = (be32_to_cpu(ohdr->bth[0]) >> 20) & 3;
496         if (unlikely(tlen < (hdrsize + pad + 4))) {
497                 /* Drop incomplete packets. */
498                 dev->n_pkt_drops++;
499                 goto bail;
500         }
501         tlen -= hdrsize + pad + 4;
502
503         /* Drop invalid MAD packets (see 13.5.3.1). */
504         if (unlikely((qp->ibqp.qp_num == 0 &&
505                       (tlen != 256 ||
506                        (be16_to_cpu(hdr->lrh[0]) >> 12) != 15)) ||
507                      (qp->ibqp.qp_num == 1 &&
508                       (tlen != 256 ||
509                        (be16_to_cpu(hdr->lrh[0]) >> 12) == 15)))) {
510                 dev->n_pkt_drops++;
511                 goto bail;
512         }
513
514         /*
515          * A GRH is expected to preceed the data even if not
516          * present on the wire.
517          */
518         wc.byte_len = tlen + sizeof(struct ib_grh);
519
520         /*
521          * The opcode is in the low byte when its in network order
522          * (top byte when in host order).
523          */
524         opcode = be32_to_cpu(ohdr->bth[0]) >> 24;
525         if (qp->ibqp.qp_num > 1 &&
526             opcode == IB_OPCODE_UD_SEND_ONLY_WITH_IMMEDIATE) {
527                 if (header_in_data) {
528                         wc.imm_data = *(__be32 *) data;
529                         data += sizeof(__be32);
530                 } else
531                         wc.imm_data = ohdr->u.ud.imm_data;
532                 wc.wc_flags = IB_WC_WITH_IMM;
533                 hdrsize += sizeof(u32);
534         } else if (opcode == IB_OPCODE_UD_SEND_ONLY) {
535                 wc.imm_data = 0;
536                 wc.wc_flags = 0;
537         } else {
538                 dev->n_pkt_drops++;
539                 goto bail;
540         }
541
542         /*
543          * Get the next work request entry to find where to put the data.
544          * Note that it is safe to drop the lock after changing rq->tail
545          * since ipath_post_receive() won't fill the empty slot.
546          */
547         if (qp->ibqp.srq) {
548                 srq = to_isrq(qp->ibqp.srq);
549                 rq = &srq->rq;
550         } else {
551                 srq = NULL;
552                 rq = &qp->r_rq;
553         }
554         spin_lock_irqsave(&rq->lock, flags);
555         if (rq->tail == rq->head) {
556                 spin_unlock_irqrestore(&rq->lock, flags);
557                 dev->n_pkt_drops++;
558                 goto bail;
559         }
560         /* Silently drop packets which are too big. */
561         wqe = get_rwqe_ptr(rq, rq->tail);
562         if (wc.byte_len > wqe->length) {
563                 spin_unlock_irqrestore(&rq->lock, flags);
564                 dev->n_pkt_drops++;
565                 goto bail;
566         }
567         wc.wr_id = wqe->wr_id;
568         qp->r_sge.sge = wqe->sg_list[0];
569         qp->r_sge.sg_list = wqe->sg_list + 1;
570         qp->r_sge.num_sge = wqe->num_sge;
571         if (++rq->tail >= rq->size)
572                 rq->tail = 0;
573         if (srq && srq->ibsrq.event_handler) {
574                 u32 n;
575
576                 if (rq->head < rq->tail)
577                         n = rq->size + rq->head - rq->tail;
578                 else
579                         n = rq->head - rq->tail;
580                 if (n < srq->limit) {
581                         struct ib_event ev;
582
583                         srq->limit = 0;
584                         spin_unlock_irqrestore(&rq->lock, flags);
585                         ev.device = qp->ibqp.device;
586                         ev.element.srq = qp->ibqp.srq;
587                         ev.event = IB_EVENT_SRQ_LIMIT_REACHED;
588                         srq->ibsrq.event_handler(&ev,
589                                                  srq->ibsrq.srq_context);
590                 } else
591                         spin_unlock_irqrestore(&rq->lock, flags);
592         } else
593                 spin_unlock_irqrestore(&rq->lock, flags);
594         if (has_grh) {
595                 ipath_copy_sge(&qp->r_sge, &hdr->u.l.grh,
596                                sizeof(struct ib_grh));
597                 wc.wc_flags |= IB_WC_GRH;
598         } else
599                 ipath_skip_sge(&qp->r_sge, sizeof(struct ib_grh));
600         ipath_copy_sge(&qp->r_sge, data,
601                        wc.byte_len - sizeof(struct ib_grh));
602         wc.status = IB_WC_SUCCESS;
603         wc.opcode = IB_WC_RECV;
604         wc.vendor_err = 0;
605         wc.qp_num = qp->ibqp.qp_num;
606         wc.src_qp = src_qp;
607         /* XXX do we know which pkey matched? Only needed for GSI. */
608         wc.pkey_index = 0;
609         wc.slid = be16_to_cpu(hdr->lrh[3]);
610         wc.sl = (be16_to_cpu(hdr->lrh[0]) >> 4) & 0xF;
611         dlid = be16_to_cpu(hdr->lrh[1]);
612         /*
613          * Save the LMC lower bits if the destination LID is a unicast LID.
614          */
615         wc.dlid_path_bits = dlid >= IPS_MULTICAST_LID_BASE ? 0 :
616                 dlid & ((1 << (dev->mkeyprot_resv_lmc & 7)) - 1);
617         /* Signal completion event if the solicited bit is set. */
618         ipath_cq_enter(to_icq(qp->ibqp.recv_cq), &wc,
619                        (ohdr->bth[0] &
620                         __constant_cpu_to_be32(1 << 23)) != 0);
621
622 bail:;
623 }