2 * Copyright (c) 2006 Chelsio, Inc. All rights reserved.
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:
10 * Redistribution and use in source and binary forms, with or
11 * without modification, are permitted provided that the following
14 * - Redistributions of source code must retain the above
15 * copyright notice, this list of conditions and the following
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.
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
32 #include "iwch_provider.h"
39 static int iwch_build_rdma_send(union t3_wr
*wqe
, struct ib_send_wr
*wr
,
47 case IB_WR_SEND_WITH_IMM
:
48 if (wr
->send_flags
& IB_SEND_SOLICITED
)
49 wqe
->send
.rdmaop
= T3_SEND_WITH_SE
;
51 wqe
->send
.rdmaop
= T3_SEND
;
52 wqe
->send
.rem_stag
= 0;
54 #if 0 /* Not currently supported */
55 case TYPE_SEND_INVALIDATE
:
56 case TYPE_SEND_INVALIDATE_IMMEDIATE
:
57 wqe
->send
.rdmaop
= T3_SEND_WITH_INV
;
58 wqe
->send
.rem_stag
= cpu_to_be32(wr
->wr
.rdma
.rkey
);
60 case TYPE_SEND_SE_INVALIDATE
:
61 wqe
->send
.rdmaop
= T3_SEND_WITH_SE_INV
;
62 wqe
->send
.rem_stag
= cpu_to_be32(wr
->wr
.rdma
.rkey
);
68 if (wr
->num_sge
> T3_MAX_SGE
)
70 wqe
->send
.reserved
[0] = 0;
71 wqe
->send
.reserved
[1] = 0;
72 wqe
->send
.reserved
[2] = 0;
73 if (wr
->opcode
== IB_WR_SEND_WITH_IMM
) {
75 wqe
->send
.sgl
[0].stag
= wr
->imm_data
;
76 wqe
->send
.sgl
[0].len
= __constant_cpu_to_be32(0);
77 wqe
->send
.num_sgle
= __constant_cpu_to_be32(0);
81 for (i
= 0; i
< wr
->num_sge
; i
++) {
82 if ((plen
+ wr
->sg_list
[i
].length
) < plen
) {
85 plen
+= wr
->sg_list
[i
].length
;
86 wqe
->send
.sgl
[i
].stag
=
87 cpu_to_be32(wr
->sg_list
[i
].lkey
);
88 wqe
->send
.sgl
[i
].len
=
89 cpu_to_be32(wr
->sg_list
[i
].length
);
90 wqe
->send
.sgl
[i
].to
= cpu_to_be64(wr
->sg_list
[i
].addr
);
92 wqe
->send
.num_sgle
= cpu_to_be32(wr
->num_sge
);
93 *flit_cnt
= 4 + ((wr
->num_sge
) << 1);
95 wqe
->send
.plen
= cpu_to_be32(plen
);
99 static int iwch_build_rdma_write(union t3_wr
*wqe
, struct ib_send_wr
*wr
,
104 if (wr
->num_sge
> T3_MAX_SGE
)
106 wqe
->write
.rdmaop
= T3_RDMA_WRITE
;
107 wqe
->write
.reserved
[0] = 0;
108 wqe
->write
.reserved
[1] = 0;
109 wqe
->write
.reserved
[2] = 0;
110 wqe
->write
.stag_sink
= cpu_to_be32(wr
->wr
.rdma
.rkey
);
111 wqe
->write
.to_sink
= cpu_to_be64(wr
->wr
.rdma
.remote_addr
);
113 if (wr
->opcode
== IB_WR_RDMA_WRITE_WITH_IMM
) {
115 wqe
->write
.sgl
[0].stag
= wr
->imm_data
;
116 wqe
->write
.sgl
[0].len
= __constant_cpu_to_be32(0);
117 wqe
->write
.num_sgle
= __constant_cpu_to_be32(0);
121 for (i
= 0; i
< wr
->num_sge
; i
++) {
122 if ((plen
+ wr
->sg_list
[i
].length
) < plen
) {
125 plen
+= wr
->sg_list
[i
].length
;
126 wqe
->write
.sgl
[i
].stag
=
127 cpu_to_be32(wr
->sg_list
[i
].lkey
);
128 wqe
->write
.sgl
[i
].len
=
129 cpu_to_be32(wr
->sg_list
[i
].length
);
130 wqe
->write
.sgl
[i
].to
=
131 cpu_to_be64(wr
->sg_list
[i
].addr
);
133 wqe
->write
.num_sgle
= cpu_to_be32(wr
->num_sge
);
134 *flit_cnt
= 5 + ((wr
->num_sge
) << 1);
136 wqe
->write
.plen
= cpu_to_be32(plen
);
140 static int iwch_build_rdma_read(union t3_wr
*wqe
, struct ib_send_wr
*wr
,
145 wqe
->read
.rdmaop
= T3_READ_REQ
;
146 wqe
->read
.reserved
[0] = 0;
147 wqe
->read
.reserved
[1] = 0;
148 wqe
->read
.reserved
[2] = 0;
149 wqe
->read
.rem_stag
= cpu_to_be32(wr
->wr
.rdma
.rkey
);
150 wqe
->read
.rem_to
= cpu_to_be64(wr
->wr
.rdma
.remote_addr
);
151 wqe
->read
.local_stag
= cpu_to_be32(wr
->sg_list
[0].lkey
);
152 wqe
->read
.local_len
= cpu_to_be32(wr
->sg_list
[0].length
);
153 wqe
->read
.local_to
= cpu_to_be64(wr
->sg_list
[0].addr
);
154 *flit_cnt
= sizeof(struct t3_rdma_read_wr
) >> 3;
159 * TBD: this is going to be moved to firmware. Missing pdid/qpid check for now.
161 static int iwch_sgl2pbl_map(struct iwch_dev
*rhp
, struct ib_sge
*sg_list
,
162 u32 num_sgle
, u32
* pbl_addr
, u8
* page_size
)
167 for (i
= 0; i
< num_sgle
; i
++) {
169 mhp
= get_mhp(rhp
, (sg_list
[i
].lkey
) >> 8);
171 PDBG("%s %d\n", __FUNCTION__
, __LINE__
);
174 if (!mhp
->attr
.state
) {
175 PDBG("%s %d\n", __FUNCTION__
, __LINE__
);
178 if (mhp
->attr
.zbva
) {
179 PDBG("%s %d\n", __FUNCTION__
, __LINE__
);
183 if (sg_list
[i
].addr
< mhp
->attr
.va_fbo
) {
184 PDBG("%s %d\n", __FUNCTION__
, __LINE__
);
187 if (sg_list
[i
].addr
+ ((u64
) sg_list
[i
].length
) <
189 PDBG("%s %d\n", __FUNCTION__
, __LINE__
);
192 if (sg_list
[i
].addr
+ ((u64
) sg_list
[i
].length
) >
193 mhp
->attr
.va_fbo
+ ((u64
) mhp
->attr
.len
)) {
194 PDBG("%s %d\n", __FUNCTION__
, __LINE__
);
197 offset
= sg_list
[i
].addr
- mhp
->attr
.va_fbo
;
198 offset
+= ((u32
) mhp
->attr
.va_fbo
) %
199 (1UL << (12 + mhp
->attr
.page_size
));
200 pbl_addr
[i
] = ((mhp
->attr
.pbl_addr
-
201 rhp
->rdev
.rnic_info
.pbl_base
) >> 3) +
202 (offset
>> (12 + mhp
->attr
.page_size
));
203 page_size
[i
] = mhp
->attr
.page_size
;
208 static int iwch_build_rdma_recv(struct iwch_dev
*rhp
, union t3_wr
*wqe
,
209 struct ib_recv_wr
*wr
)
214 if (wr
->num_sge
> T3_MAX_SGE
)
216 err
= iwch_sgl2pbl_map(rhp
, wr
->sg_list
, wr
->num_sge
, pbl_addr
,
220 wqe
->recv
.pagesz
[0] = page_size
[0];
221 wqe
->recv
.pagesz
[1] = page_size
[1];
222 wqe
->recv
.pagesz
[2] = page_size
[2];
223 wqe
->recv
.pagesz
[3] = page_size
[3];
224 wqe
->recv
.num_sgle
= cpu_to_be32(wr
->num_sge
);
225 for (i
= 0; i
< wr
->num_sge
; i
++) {
226 wqe
->recv
.sgl
[i
].stag
= cpu_to_be32(wr
->sg_list
[i
].lkey
);
227 wqe
->recv
.sgl
[i
].len
= cpu_to_be32(wr
->sg_list
[i
].length
);
229 /* to in the WQE == the offset into the page */
230 wqe
->recv
.sgl
[i
].to
= cpu_to_be64(((u32
) wr
->sg_list
[i
].addr
) %
231 (1UL << (12 + page_size
[i
])));
233 /* pbl_addr is the adapters address in the PBL */
234 wqe
->recv
.pbl_addr
[i
] = cpu_to_be32(pbl_addr
[i
]);
236 for (; i
< T3_MAX_SGE
; i
++) {
237 wqe
->recv
.sgl
[i
].stag
= 0;
238 wqe
->recv
.sgl
[i
].len
= 0;
239 wqe
->recv
.sgl
[i
].to
= 0;
240 wqe
->recv
.pbl_addr
[i
] = 0;
245 int iwch_post_send(struct ib_qp
*ibqp
, struct ib_send_wr
*wr
,
246 struct ib_send_wr
**bad_wr
)
250 enum t3_wr_opcode t3_wr_opcode
= 0;
251 enum t3_wr_flags t3_wr_flags
;
259 qhp
= to_iwch_qp(ibqp
);
260 spin_lock_irqsave(&qhp
->lock
, flag
);
261 if (qhp
->attr
.state
> IWCH_QP_STATE_RTS
) {
262 spin_unlock_irqrestore(&qhp
->lock
, flag
);
265 num_wrs
= Q_FREECNT(qhp
->wq
.sq_rptr
, qhp
->wq
.sq_wptr
,
266 qhp
->wq
.sq_size_log2
);
268 spin_unlock_irqrestore(&qhp
->lock
, flag
);
277 idx
= Q_PTR2IDX(qhp
->wq
.wptr
, qhp
->wq
.size_log2
);
278 wqe
= (union t3_wr
*) (qhp
->wq
.queue
+ idx
);
280 if (wr
->send_flags
& IB_SEND_SOLICITED
)
281 t3_wr_flags
|= T3_SOLICITED_EVENT_FLAG
;
282 if (wr
->send_flags
& IB_SEND_FENCE
)
283 t3_wr_flags
|= T3_READ_FENCE_FLAG
;
284 if (wr
->send_flags
& IB_SEND_SIGNALED
)
285 t3_wr_flags
|= T3_COMPLETION_FLAG
;
287 Q_PTR2IDX(qhp
->wq
.sq_wptr
, qhp
->wq
.sq_size_log2
);
288 switch (wr
->opcode
) {
290 case IB_WR_SEND_WITH_IMM
:
291 t3_wr_opcode
= T3_WR_SEND
;
292 err
= iwch_build_rdma_send(wqe
, wr
, &t3_wr_flit_cnt
);
294 case IB_WR_RDMA_WRITE
:
295 case IB_WR_RDMA_WRITE_WITH_IMM
:
296 t3_wr_opcode
= T3_WR_WRITE
;
297 err
= iwch_build_rdma_write(wqe
, wr
, &t3_wr_flit_cnt
);
299 case IB_WR_RDMA_READ
:
300 t3_wr_opcode
= T3_WR_READ
;
301 t3_wr_flags
= 0; /* T3 reads are always signaled */
302 err
= iwch_build_rdma_read(wqe
, wr
, &t3_wr_flit_cnt
);
305 sqp
->read_len
= wqe
->read
.local_len
;
306 if (!qhp
->wq
.oldest_read
)
307 qhp
->wq
.oldest_read
= sqp
;
310 PDBG("%s post of type=%d TBD!\n", __FUNCTION__
,
318 wqe
->send
.wrid
.id0
.hi
= qhp
->wq
.sq_wptr
;
319 sqp
->wr_id
= wr
->wr_id
;
320 sqp
->opcode
= wr2opcode(t3_wr_opcode
);
321 sqp
->sq_wptr
= qhp
->wq
.sq_wptr
;
323 sqp
->signaled
= (wr
->send_flags
& IB_SEND_SIGNALED
);
325 build_fw_riwrh((void *) wqe
, t3_wr_opcode
, t3_wr_flags
,
326 Q_GENBIT(qhp
->wq
.wptr
, qhp
->wq
.size_log2
),
328 PDBG("%s cookie 0x%llx wq idx 0x%x swsq idx %ld opcode %d\n",
329 __FUNCTION__
, (unsigned long long) wr
->wr_id
, idx
,
330 Q_PTR2IDX(qhp
->wq
.sq_wptr
, qhp
->wq
.sq_size_log2
),
337 spin_unlock_irqrestore(&qhp
->lock
, flag
);
338 ring_doorbell(qhp
->wq
.doorbell
, qhp
->wq
.qpid
);
342 int iwch_post_receive(struct ib_qp
*ibqp
, struct ib_recv_wr
*wr
,
343 struct ib_recv_wr
**bad_wr
)
352 qhp
= to_iwch_qp(ibqp
);
353 spin_lock_irqsave(&qhp
->lock
, flag
);
354 if (qhp
->attr
.state
> IWCH_QP_STATE_RTS
) {
355 spin_unlock_irqrestore(&qhp
->lock
, flag
);
358 num_wrs
= Q_FREECNT(qhp
->wq
.rq_rptr
, qhp
->wq
.rq_wptr
,
359 qhp
->wq
.rq_size_log2
) - 1;
361 spin_unlock_irqrestore(&qhp
->lock
, flag
);
365 idx
= Q_PTR2IDX(qhp
->wq
.wptr
, qhp
->wq
.size_log2
);
366 wqe
= (union t3_wr
*) (qhp
->wq
.queue
+ idx
);
368 err
= iwch_build_rdma_recv(qhp
->rhp
, wqe
, wr
);
375 qhp
->wq
.rq
[Q_PTR2IDX(qhp
->wq
.rq_wptr
, qhp
->wq
.rq_size_log2
)] =
377 build_fw_riwrh((void *) wqe
, T3_WR_RCV
, T3_COMPLETION_FLAG
,
378 Q_GENBIT(qhp
->wq
.wptr
, qhp
->wq
.size_log2
),
379 0, sizeof(struct t3_receive_wr
) >> 3);
380 PDBG("%s cookie 0x%llx idx 0x%x rq_wptr 0x%x rw_rptr 0x%x "
381 "wqe %p \n", __FUNCTION__
, (unsigned long long) wr
->wr_id
,
382 idx
, qhp
->wq
.rq_wptr
, qhp
->wq
.rq_rptr
, wqe
);
388 spin_unlock_irqrestore(&qhp
->lock
, flag
);
389 ring_doorbell(qhp
->wq
.doorbell
, qhp
->wq
.qpid
);
393 int iwch_bind_mw(struct ib_qp
*qp
,
395 struct ib_mw_bind
*mw_bind
)
397 struct iwch_dev
*rhp
;
407 enum t3_wr_flags t3_wr_flags
;
411 qhp
= to_iwch_qp(qp
);
412 mhp
= to_iwch_mw(mw
);
415 spin_lock_irqsave(&qhp
->lock
, flag
);
416 if (qhp
->attr
.state
> IWCH_QP_STATE_RTS
) {
417 spin_unlock_irqrestore(&qhp
->lock
, flag
);
420 num_wrs
= Q_FREECNT(qhp
->wq
.sq_rptr
, qhp
->wq
.sq_wptr
,
421 qhp
->wq
.sq_size_log2
);
422 if ((num_wrs
) <= 0) {
423 spin_unlock_irqrestore(&qhp
->lock
, flag
);
426 idx
= Q_PTR2IDX(qhp
->wq
.wptr
, qhp
->wq
.size_log2
);
427 PDBG("%s: idx 0x%0x, mw 0x%p, mw_bind 0x%p\n", __FUNCTION__
, idx
,
429 wqe
= (union t3_wr
*) (qhp
->wq
.queue
+ idx
);
432 if (mw_bind
->send_flags
& IB_SEND_SIGNALED
)
433 t3_wr_flags
= T3_COMPLETION_FLAG
;
435 sgl
.addr
= mw_bind
->addr
;
436 sgl
.lkey
= mw_bind
->mr
->lkey
;
437 sgl
.length
= mw_bind
->length
;
438 wqe
->bind
.reserved
= 0;
439 wqe
->bind
.type
= T3_VA_BASED_TO
;
441 /* TBD: check perms */
442 wqe
->bind
.perms
= iwch_convert_access(mw_bind
->mw_access_flags
);
443 wqe
->bind
.mr_stag
= cpu_to_be32(mw_bind
->mr
->lkey
);
444 wqe
->bind
.mw_stag
= cpu_to_be32(mw
->rkey
);
445 wqe
->bind
.mw_len
= cpu_to_be32(mw_bind
->length
);
446 wqe
->bind
.mw_va
= cpu_to_be64(mw_bind
->addr
);
447 err
= iwch_sgl2pbl_map(rhp
, &sgl
, 1, &pbl_addr
, &page_size
);
449 spin_unlock_irqrestore(&qhp
->lock
, flag
);
452 wqe
->send
.wrid
.id0
.hi
= qhp
->wq
.sq_wptr
;
453 sqp
= qhp
->wq
.sq
+ Q_PTR2IDX(qhp
->wq
.sq_wptr
, qhp
->wq
.sq_size_log2
);
454 sqp
->wr_id
= mw_bind
->wr_id
;
455 sqp
->opcode
= T3_BIND_MW
;
456 sqp
->sq_wptr
= qhp
->wq
.sq_wptr
;
458 sqp
->signaled
= (mw_bind
->send_flags
& IB_SEND_SIGNALED
);
459 wqe
->bind
.mr_pbl_addr
= cpu_to_be32(pbl_addr
);
460 wqe
->bind
.mr_pagesz
= page_size
;
461 wqe
->flit
[T3_SQ_COOKIE_FLIT
] = mw_bind
->wr_id
;
462 build_fw_riwrh((void *)wqe
, T3_WR_BIND
, t3_wr_flags
,
463 Q_GENBIT(qhp
->wq
.wptr
, qhp
->wq
.size_log2
), 0,
464 sizeof(struct t3_bind_mw_wr
) >> 3);
467 spin_unlock_irqrestore(&qhp
->lock
, flag
);
469 ring_doorbell(qhp
->wq
.doorbell
, qhp
->wq
.qpid
);
474 static void build_term_codes(int t3err
, u8
*layer_type
, u8
*ecode
, int tagged
)
479 *layer_type
= LAYER_DDP
|DDP_TAGGED_ERR
;
480 *ecode
= DDPT_INV_STAG
;
481 } else if (tagged
== 2) {
482 *layer_type
= LAYER_RDMAP
|RDMAP_REMOTE_PROT
;
483 *ecode
= RDMAP_INV_STAG
;
490 *layer_type
= LAYER_DDP
|DDP_TAGGED_ERR
;
491 *ecode
= DDPT_STAG_NOT_ASSOC
;
492 } else if (tagged
== 2) {
493 *layer_type
= LAYER_RDMAP
|RDMAP_REMOTE_PROT
;
494 *ecode
= RDMAP_STAG_NOT_ASSOC
;
498 *layer_type
= LAYER_RDMAP
|RDMAP_REMOTE_PROT
;
499 *ecode
= RDMAP_TO_WRAP
;
503 *layer_type
= LAYER_DDP
|DDP_TAGGED_ERR
;
504 *ecode
= DDPT_BASE_BOUNDS
;
505 } else if (tagged
== 2) {
506 *layer_type
= LAYER_RDMAP
|RDMAP_REMOTE_PROT
;
507 *ecode
= RDMAP_BASE_BOUNDS
;
509 *layer_type
= LAYER_DDP
|DDP_UNTAGGED_ERR
;
510 *ecode
= DDPU_MSG_TOOBIG
;
513 case TPT_ERR_INVALIDATE_SHARED_MR
:
514 case TPT_ERR_INVALIDATE_MR_WITH_MW_BOUND
:
515 *layer_type
= LAYER_RDMAP
|RDMAP_REMOTE_OP
;
516 *ecode
= RDMAP_CANT_INV_STAG
;
519 case TPT_ERR_ECC_PSTAG
:
520 case TPT_ERR_INTERNAL_ERR
:
521 *layer_type
= LAYER_RDMAP
|RDMAP_LOCAL_CATA
;
524 case TPT_ERR_OUT_OF_RQE
:
525 *layer_type
= LAYER_DDP
|DDP_UNTAGGED_ERR
;
526 *ecode
= DDPU_INV_MSN_NOBUF
;
528 case TPT_ERR_PBL_ADDR_BOUND
:
529 *layer_type
= LAYER_DDP
|DDP_TAGGED_ERR
;
530 *ecode
= DDPT_BASE_BOUNDS
;
533 *layer_type
= LAYER_MPA
|DDP_LLP
;
534 *ecode
= MPA_CRC_ERR
;
537 *layer_type
= LAYER_MPA
|DDP_LLP
;
538 *ecode
= MPA_MARKER_ERR
;
540 case TPT_ERR_PDU_LEN_ERR
:
541 *layer_type
= LAYER_DDP
|DDP_UNTAGGED_ERR
;
542 *ecode
= DDPU_MSG_TOOBIG
;
544 case TPT_ERR_DDP_VERSION
:
546 *layer_type
= LAYER_DDP
|DDP_TAGGED_ERR
;
547 *ecode
= DDPT_INV_VERS
;
549 *layer_type
= LAYER_DDP
|DDP_UNTAGGED_ERR
;
550 *ecode
= DDPU_INV_VERS
;
553 case TPT_ERR_RDMA_VERSION
:
554 *layer_type
= LAYER_RDMAP
|RDMAP_REMOTE_OP
;
555 *ecode
= RDMAP_INV_VERS
;
558 *layer_type
= LAYER_RDMAP
|RDMAP_REMOTE_OP
;
559 *ecode
= RDMAP_INV_OPCODE
;
561 case TPT_ERR_DDP_QUEUE_NUM
:
562 *layer_type
= LAYER_DDP
|DDP_UNTAGGED_ERR
;
563 *ecode
= DDPU_INV_QN
;
566 case TPT_ERR_MSN_GAP
:
567 case TPT_ERR_MSN_RANGE
:
568 case TPT_ERR_IRD_OVERFLOW
:
569 *layer_type
= LAYER_DDP
|DDP_UNTAGGED_ERR
;
570 *ecode
= DDPU_INV_MSN_RANGE
;
573 *layer_type
= LAYER_DDP
|DDP_LOCAL_CATA
;
577 *layer_type
= LAYER_DDP
|DDP_UNTAGGED_ERR
;
578 *ecode
= DDPU_INV_MO
;
581 *layer_type
= LAYER_RDMAP
|DDP_LOCAL_CATA
;
588 * This posts a TERMINATE with layer=RDMA, type=catastrophic.
590 int iwch_post_terminate(struct iwch_qp
*qhp
, struct respQ_msg_t
*rsp_msg
)
593 struct terminate_message
*term
;
598 PDBG("%s %d\n", __FUNCTION__
, __LINE__
);
599 skb
= alloc_skb(40, GFP_ATOMIC
);
601 printk(KERN_ERR
"%s cannot send TERMINATE!\n", __FUNCTION__
);
604 wqe
= (union t3_wr
*)skb_put(skb
, 40);
606 wqe
->send
.rdmaop
= T3_TERMINATE
;
608 /* immediate data length */
609 wqe
->send
.plen
= htonl(4);
611 /* immediate data starts here. */
612 term
= (struct terminate_message
*)wqe
->send
.sgl
;
614 status
= CQE_STATUS(rsp_msg
->cqe
);
615 if (CQE_OPCODE(rsp_msg
->cqe
) == T3_RDMA_WRITE
)
617 if ((CQE_OPCODE(rsp_msg
->cqe
) == T3_READ_REQ
) ||
618 (CQE_OPCODE(rsp_msg
->cqe
) == T3_READ_RESP
))
621 status
= TPT_ERR_INTERNAL_ERR
;
623 build_term_codes(status
, &term
->layer_etype
, &term
->ecode
, tagged
);
624 build_fw_riwrh((void *)wqe
, T3_WR_SEND
,
625 T3_COMPLETION_FLAG
| T3_NOTIFY_FLAG
, 1,
627 skb
->priority
= CPL_PRIORITY_DATA
;
628 return cxgb3_ofld_send(qhp
->rhp
->rdev
.t3cdev_p
, skb
);
632 * Assumes qhp lock is held.
634 static void __flush_qp(struct iwch_qp
*qhp
, unsigned long *flag
)
636 struct iwch_cq
*rchp
, *schp
;
639 rchp
= get_chp(qhp
->rhp
, qhp
->attr
.rcq
);
640 schp
= get_chp(qhp
->rhp
, qhp
->attr
.scq
);
642 PDBG("%s qhp %p rchp %p schp %p\n", __FUNCTION__
, qhp
, rchp
, schp
);
643 /* take a ref on the qhp since we must release the lock */
644 atomic_inc(&qhp
->refcnt
);
645 spin_unlock_irqrestore(&qhp
->lock
, *flag
);
647 /* locking heirarchy: cq lock first, then qp lock. */
648 spin_lock_irqsave(&rchp
->lock
, *flag
);
649 spin_lock(&qhp
->lock
);
650 cxio_flush_hw_cq(&rchp
->cq
);
651 cxio_count_rcqes(&rchp
->cq
, &qhp
->wq
, &count
);
652 cxio_flush_rq(&qhp
->wq
, &rchp
->cq
, count
);
653 spin_unlock(&qhp
->lock
);
654 spin_unlock_irqrestore(&rchp
->lock
, *flag
);
656 /* locking heirarchy: cq lock first, then qp lock. */
657 spin_lock_irqsave(&schp
->lock
, *flag
);
658 spin_lock(&qhp
->lock
);
659 cxio_flush_hw_cq(&schp
->cq
);
660 cxio_count_scqes(&schp
->cq
, &qhp
->wq
, &count
);
661 cxio_flush_sq(&qhp
->wq
, &schp
->cq
, count
);
662 spin_unlock(&qhp
->lock
);
663 spin_unlock_irqrestore(&schp
->lock
, *flag
);
666 if (atomic_dec_and_test(&qhp
->refcnt
))
669 spin_lock_irqsave(&qhp
->lock
, *flag
);
672 static void flush_qp(struct iwch_qp
*qhp
, unsigned long *flag
)
674 if (t3b_device(qhp
->rhp
))
675 cxio_set_wq_in_error(&qhp
->wq
);
677 __flush_qp(qhp
, flag
);
682 * Return non zero if at least one RECV was pre-posted.
684 static int rqes_posted(struct iwch_qp
*qhp
)
686 return fw_riwrh_opcode((struct fw_riwrh
*)qhp
->wq
.queue
) == T3_WR_RCV
;
689 static int rdma_init(struct iwch_dev
*rhp
, struct iwch_qp
*qhp
,
690 enum iwch_qp_attr_mask mask
,
691 struct iwch_qp_attributes
*attrs
)
693 struct t3_rdma_init_attr init_attr
;
696 init_attr
.tid
= qhp
->ep
->hwtid
;
697 init_attr
.qpid
= qhp
->wq
.qpid
;
698 init_attr
.pdid
= qhp
->attr
.pd
;
699 init_attr
.scqid
= qhp
->attr
.scq
;
700 init_attr
.rcqid
= qhp
->attr
.rcq
;
701 init_attr
.rq_addr
= qhp
->wq
.rq_addr
;
702 init_attr
.rq_size
= 1 << qhp
->wq
.rq_size_log2
;
703 init_attr
.mpaattrs
= uP_RI_MPA_IETF_ENABLE
|
704 qhp
->attr
.mpa_attr
.recv_marker_enabled
|
705 (qhp
->attr
.mpa_attr
.xmit_marker_enabled
<< 1) |
706 (qhp
->attr
.mpa_attr
.crc_enabled
<< 2);
709 * XXX - The IWCM doesn't quite handle getting these
710 * attrs set before going into RTS. For now, just turn
714 init_attr
.qpcaps
= qhp
->attr
.enableRdmaRead
|
715 (qhp
->attr
.enableRdmaWrite
<< 1) |
716 (qhp
->attr
.enableBind
<< 2) |
717 (qhp
->attr
.enable_stag0_fastreg
<< 3) |
718 (qhp
->attr
.enable_stag0_fastreg
<< 4);
720 init_attr
.qpcaps
= 0x1f;
722 init_attr
.tcp_emss
= qhp
->ep
->emss
;
723 init_attr
.ord
= qhp
->attr
.max_ord
;
724 init_attr
.ird
= qhp
->attr
.max_ird
;
725 init_attr
.qp_dma_addr
= qhp
->wq
.dma_addr
;
726 init_attr
.qp_dma_size
= (1UL << qhp
->wq
.size_log2
);
727 init_attr
.flags
= rqes_posted(qhp
) ? RECVS_POSTED
: 0;
728 PDBG("%s init_attr.rq_addr 0x%x init_attr.rq_size = %d "
729 "flags 0x%x qpcaps 0x%x\n", __FUNCTION__
,
730 init_attr
.rq_addr
, init_attr
.rq_size
,
731 init_attr
.flags
, init_attr
.qpcaps
);
732 ret
= cxio_rdma_init(&rhp
->rdev
, &init_attr
);
733 PDBG("%s ret %d\n", __FUNCTION__
, ret
);
737 int iwch_modify_qp(struct iwch_dev
*rhp
, struct iwch_qp
*qhp
,
738 enum iwch_qp_attr_mask mask
,
739 struct iwch_qp_attributes
*attrs
,
743 struct iwch_qp_attributes newattr
= qhp
->attr
;
749 struct iwch_ep
*ep
= NULL
;
751 PDBG("%s qhp %p qpid 0x%x ep %p state %d -> %d\n", __FUNCTION__
,
752 qhp
, qhp
->wq
.qpid
, qhp
->ep
, qhp
->attr
.state
,
753 (mask
& IWCH_QP_ATTR_NEXT_STATE
) ? attrs
->next_state
: -1);
755 spin_lock_irqsave(&qhp
->lock
, flag
);
757 /* Process attr changes if in IDLE */
758 if (mask
& IWCH_QP_ATTR_VALID_MODIFY
) {
759 if (qhp
->attr
.state
!= IWCH_QP_STATE_IDLE
) {
763 if (mask
& IWCH_QP_ATTR_ENABLE_RDMA_READ
)
764 newattr
.enable_rdma_read
= attrs
->enable_rdma_read
;
765 if (mask
& IWCH_QP_ATTR_ENABLE_RDMA_WRITE
)
766 newattr
.enable_rdma_write
= attrs
->enable_rdma_write
;
767 if (mask
& IWCH_QP_ATTR_ENABLE_RDMA_BIND
)
768 newattr
.enable_bind
= attrs
->enable_bind
;
769 if (mask
& IWCH_QP_ATTR_MAX_ORD
) {
771 rhp
->attr
.max_rdma_read_qp_depth
) {
775 newattr
.max_ord
= attrs
->max_ord
;
777 if (mask
& IWCH_QP_ATTR_MAX_IRD
) {
779 rhp
->attr
.max_rdma_reads_per_qp
) {
783 newattr
.max_ird
= attrs
->max_ird
;
788 if (!(mask
& IWCH_QP_ATTR_NEXT_STATE
))
790 if (qhp
->attr
.state
== attrs
->next_state
)
793 switch (qhp
->attr
.state
) {
794 case IWCH_QP_STATE_IDLE
:
795 switch (attrs
->next_state
) {
796 case IWCH_QP_STATE_RTS
:
797 if (!(mask
& IWCH_QP_ATTR_LLP_STREAM_HANDLE
)) {
801 if (!(mask
& IWCH_QP_ATTR_MPA_ATTR
)) {
805 qhp
->attr
.mpa_attr
= attrs
->mpa_attr
;
806 qhp
->attr
.llp_stream_handle
= attrs
->llp_stream_handle
;
807 qhp
->ep
= qhp
->attr
.llp_stream_handle
;
808 qhp
->attr
.state
= IWCH_QP_STATE_RTS
;
811 * Ref the endpoint here and deref when we
812 * disassociate the endpoint from the QP. This
813 * happens in CLOSING->IDLE transition or *->ERROR
816 get_ep(&qhp
->ep
->com
);
817 spin_unlock_irqrestore(&qhp
->lock
, flag
);
818 ret
= rdma_init(rhp
, qhp
, mask
, attrs
);
819 spin_lock_irqsave(&qhp
->lock
, flag
);
823 case IWCH_QP_STATE_ERROR
:
824 qhp
->attr
.state
= IWCH_QP_STATE_ERROR
;
825 flush_qp(qhp
, &flag
);
832 case IWCH_QP_STATE_RTS
:
833 switch (attrs
->next_state
) {
834 case IWCH_QP_STATE_CLOSING
:
835 BUG_ON(atomic_read(&qhp
->ep
->com
.kref
.refcount
) < 2);
836 qhp
->attr
.state
= IWCH_QP_STATE_CLOSING
;
843 case IWCH_QP_STATE_TERMINATE
:
844 qhp
->attr
.state
= IWCH_QP_STATE_TERMINATE
;
845 if (t3b_device(qhp
->rhp
))
846 cxio_set_wq_in_error(&qhp
->wq
);
850 case IWCH_QP_STATE_ERROR
:
851 qhp
->attr
.state
= IWCH_QP_STATE_ERROR
;
864 case IWCH_QP_STATE_CLOSING
:
869 switch (attrs
->next_state
) {
870 case IWCH_QP_STATE_IDLE
:
871 qhp
->attr
.state
= IWCH_QP_STATE_IDLE
;
872 qhp
->attr
.llp_stream_handle
= NULL
;
873 put_ep(&qhp
->ep
->com
);
877 case IWCH_QP_STATE_ERROR
:
884 case IWCH_QP_STATE_ERROR
:
885 if (attrs
->next_state
!= IWCH_QP_STATE_IDLE
) {
890 if (!Q_EMPTY(qhp
->wq
.sq_rptr
, qhp
->wq
.sq_wptr
) ||
891 !Q_EMPTY(qhp
->wq
.rq_rptr
, qhp
->wq
.rq_wptr
)) {
895 qhp
->attr
.state
= IWCH_QP_STATE_IDLE
;
896 memset(&qhp
->attr
, 0, sizeof(qhp
->attr
));
898 case IWCH_QP_STATE_TERMINATE
:
906 printk(KERN_ERR
"%s in a bad state %d\n",
907 __FUNCTION__
, qhp
->attr
.state
);
914 PDBG("%s disassociating ep %p qpid 0x%x\n", __FUNCTION__
, qhp
->ep
,
917 /* disassociate the LLP connection */
918 qhp
->attr
.llp_stream_handle
= NULL
;
921 qhp
->attr
.state
= IWCH_QP_STATE_ERROR
;
925 flush_qp(qhp
, &flag
);
927 spin_unlock_irqrestore(&qhp
->lock
, flag
);
930 iwch_post_terminate(qhp
, NULL
);
933 * If disconnect is 1, then we need to initiate a disconnect
934 * on the EP. This can be a normal close (RTS->CLOSING) or
935 * an abnormal close (RTS/CLOSING->ERROR).
938 iwch_ep_disconnect(ep
, abort
, GFP_KERNEL
);
941 * If free is 1, then we've disassociated the EP from the QP
942 * and we need to dereference the EP.
947 PDBG("%s exit state %d\n", __FUNCTION__
, qhp
->attr
.state
);
951 static int quiesce_qp(struct iwch_qp
*qhp
)
953 spin_lock_irq(&qhp
->lock
);
954 iwch_quiesce_tid(qhp
->ep
);
955 qhp
->flags
|= QP_QUIESCED
;
956 spin_unlock_irq(&qhp
->lock
);
960 static int resume_qp(struct iwch_qp
*qhp
)
962 spin_lock_irq(&qhp
->lock
);
963 iwch_resume_tid(qhp
->ep
);
964 qhp
->flags
&= ~QP_QUIESCED
;
965 spin_unlock_irq(&qhp
->lock
);
969 int iwch_quiesce_qps(struct iwch_cq
*chp
)
974 for (i
=0; i
< T3_MAX_NUM_QP
; i
++) {
975 qhp
= get_qhp(chp
->rhp
, i
);
978 if ((qhp
->attr
.rcq
== chp
->cq
.cqid
) && !qp_quiesced(qhp
)) {
982 if ((qhp
->attr
.scq
== chp
->cq
.cqid
) && !qp_quiesced(qhp
))
988 int iwch_resume_qps(struct iwch_cq
*chp
)
993 for (i
=0; i
< T3_MAX_NUM_QP
; i
++) {
994 qhp
= get_qhp(chp
->rhp
, i
);
997 if ((qhp
->attr
.rcq
== chp
->cq
.cqid
) && qp_quiesced(qhp
)) {
1001 if ((qhp
->attr
.scq
== chp
->cq
.cqid
) && qp_quiesced(qhp
))