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