2 * Copyright (c) 2006 - 2008 NetEffect, 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
34 #include <linux/module.h>
35 #include <linux/moduleparam.h>
36 #include <linux/random.h>
37 #include <linux/highmem.h>
38 #include <asm/byteorder.h>
40 #include <rdma/ib_verbs.h>
41 #include <rdma/iw_cm.h>
42 #include <rdma/ib_user_verbs.h>
46 #include <rdma/ib_umem.h>
48 atomic_t mod_qp_timouts
;
50 atomic_t sw_qps_destroyed
;
52 static void nes_unregister_ofa_device(struct nes_ib_device
*nesibdev
);
57 static struct ib_mw
*nes_alloc_mw(struct ib_pd
*ibpd
) {
58 struct nes_pd
*nespd
= to_nespd(ibpd
);
59 struct nes_vnic
*nesvnic
= to_nesvnic(ibpd
->device
);
60 struct nes_device
*nesdev
= nesvnic
->nesdev
;
61 struct nes_adapter
*nesadapter
= nesdev
->nesadapter
;
62 struct nes_cqp_request
*cqp_request
;
65 struct nes_hw_cqp_wqe
*cqp_wqe
;
69 u32 next_stag_index
= 0;
73 get_random_bytes(&next_stag_index
, sizeof(next_stag_index
));
74 stag_key
= (u8
)next_stag_index
;
78 next_stag_index
>>= 8;
79 next_stag_index
%= nesadapter
->max_mr
;
81 ret
= nes_alloc_resource(nesadapter
, nesadapter
->allocated_mrs
,
82 nesadapter
->max_mr
, &stag_index
, &next_stag_index
);
87 nesmr
= kzalloc(sizeof(*nesmr
), GFP_KERNEL
);
89 nes_free_resource(nesadapter
, nesadapter
->allocated_mrs
, stag_index
);
90 return ERR_PTR(-ENOMEM
);
93 stag
= stag_index
<< 8;
95 stag
+= (u32
)stag_key
;
97 nes_debug(NES_DBG_MR
, "Registering STag 0x%08X, index = 0x%08X\n",
100 /* Register the region with the adapter */
101 cqp_request
= nes_get_cqp_request(nesdev
);
102 if (cqp_request
== NULL
) {
104 nes_free_resource(nesadapter
, nesadapter
->allocated_mrs
, stag_index
);
105 return ERR_PTR(-ENOMEM
);
108 cqp_request
->waiting
= 1;
109 cqp_wqe
= &cqp_request
->cqp_wqe
;
111 cqp_wqe
->wqe_words
[NES_CQP_WQE_OPCODE_IDX
] =
112 cpu_to_le32( NES_CQP_ALLOCATE_STAG
| NES_CQP_STAG_RIGHTS_REMOTE_READ
|
113 NES_CQP_STAG_RIGHTS_REMOTE_WRITE
| NES_CQP_STAG_VA_TO
|
114 NES_CQP_STAG_REM_ACC_EN
);
116 nes_fill_init_cqp_wqe(cqp_wqe
, nesdev
);
117 set_wqe_32bit_value(cqp_wqe
->wqe_words
, NES_CQP_STAG_WQE_LEN_HIGH_PD_IDX
, (nespd
->pd_id
& 0x00007fff));
118 set_wqe_32bit_value(cqp_wqe
->wqe_words
, NES_CQP_STAG_WQE_STAG_IDX
, stag
);
120 atomic_set(&cqp_request
->refcount
, 2);
121 nes_post_cqp_request(nesdev
, cqp_request
);
124 ret
= wait_event_timeout(cqp_request
->waitq
, (cqp_request
->request_done
!= 0),
126 nes_debug(NES_DBG_MR
, "Register STag 0x%08X completed, wait_event_timeout ret = %u,"
127 " CQP Major:Minor codes = 0x%04X:0x%04X.\n",
128 stag
, ret
, cqp_request
->major_code
, cqp_request
->minor_code
);
129 if ((!ret
) || (cqp_request
->major_code
)) {
130 nes_put_cqp_request(nesdev
, cqp_request
);
132 nes_free_resource(nesadapter
, nesadapter
->allocated_mrs
, stag_index
);
134 return ERR_PTR(-ETIME
);
136 return ERR_PTR(-ENOMEM
);
139 nes_put_cqp_request(nesdev
, cqp_request
);
141 nesmr
->ibmw
.rkey
= stag
;
142 nesmr
->mode
= IWNES_MEMREG_TYPE_MW
;
145 nesmr
->pbls_used
= 0;
154 static int nes_dealloc_mw(struct ib_mw
*ibmw
)
156 struct nes_mr
*nesmr
= to_nesmw(ibmw
);
157 struct nes_vnic
*nesvnic
= to_nesvnic(ibmw
->device
);
158 struct nes_device
*nesdev
= nesvnic
->nesdev
;
159 struct nes_adapter
*nesadapter
= nesdev
->nesadapter
;
160 struct nes_hw_cqp_wqe
*cqp_wqe
;
161 struct nes_cqp_request
*cqp_request
;
165 /* Deallocate the window with the adapter */
166 cqp_request
= nes_get_cqp_request(nesdev
);
167 if (cqp_request
== NULL
) {
168 nes_debug(NES_DBG_MR
, "Failed to get a cqp_request.\n");
171 cqp_request
->waiting
= 1;
172 cqp_wqe
= &cqp_request
->cqp_wqe
;
173 nes_fill_init_cqp_wqe(cqp_wqe
, nesdev
);
174 set_wqe_32bit_value(cqp_wqe
->wqe_words
, NES_CQP_WQE_OPCODE_IDX
, NES_CQP_DEALLOCATE_STAG
);
175 set_wqe_32bit_value(cqp_wqe
->wqe_words
, NES_CQP_STAG_WQE_STAG_IDX
, ibmw
->rkey
);
177 atomic_set(&cqp_request
->refcount
, 2);
178 nes_post_cqp_request(nesdev
, cqp_request
);
181 nes_debug(NES_DBG_MR
, "Waiting for deallocate STag 0x%08X to complete.\n",
183 ret
= wait_event_timeout(cqp_request
->waitq
, (0 != cqp_request
->request_done
),
185 nes_debug(NES_DBG_MR
, "Deallocate STag completed, wait_event_timeout ret = %u,"
186 " CQP Major:Minor codes = 0x%04X:0x%04X.\n",
187 ret
, cqp_request
->major_code
, cqp_request
->minor_code
);
190 else if (cqp_request
->major_code
)
193 nes_put_cqp_request(nesdev
, cqp_request
);
195 nes_free_resource(nesadapter
, nesadapter
->allocated_mrs
,
196 (ibmw
->rkey
& 0x0fffff00) >> 8);
206 static int nes_bind_mw(struct ib_qp
*ibqp
, struct ib_mw
*ibmw
,
207 struct ib_mw_bind
*ibmw_bind
)
210 struct nes_vnic
*nesvnic
= to_nesvnic(ibqp
->device
);
211 struct nes_device
*nesdev
= nesvnic
->nesdev
;
212 /* struct nes_mr *nesmr = to_nesmw(ibmw); */
213 struct nes_qp
*nesqp
= to_nesqp(ibqp
);
214 struct nes_hw_qp_wqe
*wqe
;
215 unsigned long flags
= 0;
220 if (nesqp
->ibqp_state
> IB_QPS_RTS
)
223 spin_lock_irqsave(&nesqp
->lock
, flags
);
225 head
= nesqp
->hwqp
.sq_head
;
226 qsize
= nesqp
->hwqp
.sq_tail
;
228 /* Check for SQ overflow */
229 if (((head
+ (2 * qsize
) - nesqp
->hwqp
.sq_tail
) % qsize
) == (qsize
- 1)) {
230 spin_unlock_irqrestore(&nesqp
->lock
, flags
);
234 wqe
= &nesqp
->hwqp
.sq_vbase
[head
];
235 /* nes_debug(NES_DBG_MR, "processing sq wqe at %p, head = %u.\n", wqe, head); */
236 nes_fill_init_qp_wqe(wqe
, nesqp
, head
);
237 u64temp
= ibmw_bind
->wr_id
;
238 set_wqe_64bit_value(wqe
->wqe_words
, NES_IWARP_SQ_WQE_COMP_SCRATCH_LOW_IDX
, u64temp
);
239 wqe_misc
= NES_IWARP_SQ_OP_BIND
;
241 wqe_misc
|= NES_IWARP_SQ_WQE_LOCAL_FENCE
;
243 if (ibmw_bind
->send_flags
& IB_SEND_SIGNALED
)
244 wqe_misc
|= NES_IWARP_SQ_WQE_SIGNALED_COMPL
;
246 if (ibmw_bind
->mw_access_flags
& IB_ACCESS_REMOTE_WRITE
) {
247 wqe_misc
|= NES_CQP_STAG_RIGHTS_REMOTE_WRITE
;
249 if (ibmw_bind
->mw_access_flags
& IB_ACCESS_REMOTE_READ
) {
250 wqe_misc
|= NES_CQP_STAG_RIGHTS_REMOTE_READ
;
253 set_wqe_32bit_value(wqe
->wqe_words
, NES_IWARP_SQ_WQE_MISC_IDX
, wqe_misc
);
254 set_wqe_32bit_value(wqe
->wqe_words
, NES_IWARP_SQ_BIND_WQE_MR_IDX
, ibmw_bind
->mr
->lkey
);
255 set_wqe_32bit_value(wqe
->wqe_words
, NES_IWARP_SQ_BIND_WQE_MW_IDX
, ibmw
->rkey
);
256 set_wqe_32bit_value(wqe
->wqe_words
, NES_IWARP_SQ_BIND_WQE_LENGTH_LOW_IDX
,
258 wqe
->wqe_words
[NES_IWARP_SQ_BIND_WQE_LENGTH_HIGH_IDX
] = 0;
259 u64temp
= (u64
)ibmw_bind
->addr
;
260 set_wqe_64bit_value(wqe
->wqe_words
, NES_IWARP_SQ_BIND_WQE_VA_FBO_LOW_IDX
, u64temp
);
266 nesqp
->hwqp
.sq_head
= head
;
269 nes_write32(nesdev
->regs
+NES_WQE_ALLOC
,
270 (1 << 24) | 0x00800000 | nesqp
->hwqp
.qp_id
);
272 spin_unlock_irqrestore(&nesqp
->lock
, flags
);
281 static struct ib_fmr
*nes_alloc_fmr(struct ib_pd
*ibpd
,
282 int ibmr_access_flags
,
283 struct ib_fmr_attr
*ibfmr_attr
)
286 struct nes_pd
*nespd
= to_nespd(ibpd
);
287 struct nes_vnic
*nesvnic
= to_nesvnic(ibpd
->device
);
288 struct nes_device
*nesdev
= nesvnic
->nesdev
;
289 struct nes_adapter
*nesadapter
= nesdev
->nesadapter
;
290 struct nes_fmr
*nesfmr
;
291 struct nes_cqp_request
*cqp_request
;
292 struct nes_hw_cqp_wqe
*cqp_wqe
;
296 u32 next_stag_index
= 0;
301 struct nes_vpbl vpbl
;
303 get_random_bytes(&next_stag_index
, sizeof(next_stag_index
));
304 stag_key
= (u8
)next_stag_index
;
308 next_stag_index
>>= 8;
309 next_stag_index
%= nesadapter
->max_mr
;
311 ret
= nes_alloc_resource(nesadapter
, nesadapter
->allocated_mrs
,
312 nesadapter
->max_mr
, &stag_index
, &next_stag_index
);
314 goto failed_resource_alloc
;
317 nesfmr
= kzalloc(sizeof(*nesfmr
), GFP_KERNEL
);
320 goto failed_fmr_alloc
;
323 nesfmr
->nesmr
.mode
= IWNES_MEMREG_TYPE_FMR
;
324 if (ibfmr_attr
->max_pages
== 1) {
325 /* use zero length PBL */
326 nesfmr
->nesmr
.pbl_4k
= 0;
327 nesfmr
->nesmr
.pbls_used
= 0;
328 } else if (ibfmr_attr
->max_pages
<= 32) {
330 nesfmr
->nesmr
.pbl_4k
= 0;
331 nesfmr
->nesmr
.pbls_used
= 1;
332 } else if (ibfmr_attr
->max_pages
<= 512) {
334 nesfmr
->nesmr
.pbl_4k
= 1;
335 nesfmr
->nesmr
.pbls_used
= 1;
337 /* use two level 4K PBLs */
338 /* add support for two level 256B PBLs */
339 nesfmr
->nesmr
.pbl_4k
= 1;
340 nesfmr
->nesmr
.pbls_used
= 1 + (ibfmr_attr
->max_pages
>> 9) +
341 ((ibfmr_attr
->max_pages
& 511) ? 1 : 0);
343 /* Register the region with the adapter */
344 spin_lock_irqsave(&nesadapter
->pbl_lock
, flags
);
346 /* track PBL resources */
347 if (nesfmr
->nesmr
.pbls_used
!= 0) {
348 if (nesfmr
->nesmr
.pbl_4k
) {
349 if (nesfmr
->nesmr
.pbls_used
> nesadapter
->free_4kpbl
) {
350 spin_unlock_irqrestore(&nesadapter
->pbl_lock
, flags
);
352 goto failed_vpbl_avail
;
354 nesadapter
->free_4kpbl
-= nesfmr
->nesmr
.pbls_used
;
357 if (nesfmr
->nesmr
.pbls_used
> nesadapter
->free_256pbl
) {
358 spin_unlock_irqrestore(&nesadapter
->pbl_lock
, flags
);
360 goto failed_vpbl_avail
;
362 nesadapter
->free_256pbl
-= nesfmr
->nesmr
.pbls_used
;
368 if (nesfmr
->nesmr
.pbls_used
== 0) {
369 nesfmr
->root_vpbl
.pbl_vbase
= NULL
;
370 nes_debug(NES_DBG_MR
, "zero level pbl \n");
371 } else if (nesfmr
->nesmr
.pbls_used
== 1) {
372 /* can change it to kmalloc & dma_map_single */
373 nesfmr
->root_vpbl
.pbl_vbase
= pci_alloc_consistent(nesdev
->pcidev
, 4096,
374 &nesfmr
->root_vpbl
.pbl_pbase
);
375 if (!nesfmr
->root_vpbl
.pbl_vbase
) {
376 spin_unlock_irqrestore(&nesadapter
->pbl_lock
, flags
);
378 goto failed_vpbl_alloc
;
380 nesfmr
->leaf_pbl_cnt
= 0;
381 nes_debug(NES_DBG_MR
, "one level pbl, root_vpbl.pbl_vbase=%p \n",
382 nesfmr
->root_vpbl
.pbl_vbase
);
386 nesfmr
->root_vpbl
.pbl_vbase
= pci_alloc_consistent(nesdev
->pcidev
, 8192,
387 &nesfmr
->root_vpbl
.pbl_pbase
);
388 if (!nesfmr
->root_vpbl
.pbl_vbase
) {
389 spin_unlock_irqrestore(&nesadapter
->pbl_lock
, flags
);
391 goto failed_vpbl_alloc
;
394 nesfmr
->leaf_pbl_cnt
= nesfmr
->nesmr
.pbls_used
-1;
395 nesfmr
->root_vpbl
.leaf_vpbl
= kzalloc(sizeof(*nesfmr
->root_vpbl
.leaf_vpbl
)*1024, GFP_ATOMIC
);
396 if (!nesfmr
->root_vpbl
.leaf_vpbl
) {
397 spin_unlock_irqrestore(&nesadapter
->pbl_lock
, flags
);
399 goto failed_leaf_vpbl_alloc
;
402 nes_debug(NES_DBG_MR
, "two level pbl, root_vpbl.pbl_vbase=%p"
403 " leaf_pbl_cnt=%d root_vpbl.leaf_vpbl=%p\n",
404 nesfmr
->root_vpbl
.pbl_vbase
, nesfmr
->leaf_pbl_cnt
, nesfmr
->root_vpbl
.leaf_vpbl
);
406 for (i
=0; i
<nesfmr
->leaf_pbl_cnt
; i
++)
407 nesfmr
->root_vpbl
.leaf_vpbl
[i
].pbl_vbase
= NULL
;
409 for (i
=0; i
<nesfmr
->leaf_pbl_cnt
; i
++) {
410 vpbl
.pbl_vbase
= pci_alloc_consistent(nesdev
->pcidev
, 4096,
413 if (!vpbl
.pbl_vbase
) {
415 spin_unlock_irqrestore(&nesadapter
->pbl_lock
, flags
);
416 goto failed_leaf_vpbl_pages_alloc
;
419 nesfmr
->root_vpbl
.pbl_vbase
[i
].pa_low
= cpu_to_le32((u32
)vpbl
.pbl_pbase
);
420 nesfmr
->root_vpbl
.pbl_vbase
[i
].pa_high
= cpu_to_le32((u32
)((((u64
)vpbl
.pbl_pbase
)>>32)));
421 nesfmr
->root_vpbl
.leaf_vpbl
[i
] = vpbl
;
423 nes_debug(NES_DBG_MR
, "pbase_low=0x%x, pbase_high=0x%x, vpbl=%p\n",
424 nesfmr
->root_vpbl
.pbl_vbase
[i
].pa_low
,
425 nesfmr
->root_vpbl
.pbl_vbase
[i
].pa_high
,
426 &nesfmr
->root_vpbl
.leaf_vpbl
[i
]);
429 nesfmr
->ib_qp
= NULL
;
430 nesfmr
->access_rights
=0;
432 stag
= stag_index
<< 8;
434 stag
+= (u32
)stag_key
;
436 spin_unlock_irqrestore(&nesadapter
->pbl_lock
, flags
);
437 cqp_request
= nes_get_cqp_request(nesdev
);
438 if (cqp_request
== NULL
) {
439 nes_debug(NES_DBG_MR
, "Failed to get a cqp_request.\n");
441 goto failed_leaf_vpbl_pages_alloc
;
443 cqp_request
->waiting
= 1;
444 cqp_wqe
= &cqp_request
->cqp_wqe
;
446 nes_debug(NES_DBG_MR
, "Registering STag 0x%08X, index = 0x%08X\n",
449 opcode
= NES_CQP_ALLOCATE_STAG
| NES_CQP_STAG_VA_TO
| NES_CQP_STAG_MR
;
451 if (nesfmr
->nesmr
.pbl_4k
== 1)
452 opcode
|= NES_CQP_STAG_PBL_BLK_SIZE
;
454 if (ibmr_access_flags
& IB_ACCESS_REMOTE_WRITE
) {
455 opcode
|= NES_CQP_STAG_RIGHTS_REMOTE_WRITE
|
456 NES_CQP_STAG_RIGHTS_LOCAL_WRITE
| NES_CQP_STAG_REM_ACC_EN
;
457 nesfmr
->access_rights
|=
458 NES_CQP_STAG_RIGHTS_REMOTE_WRITE
| NES_CQP_STAG_RIGHTS_LOCAL_WRITE
|
459 NES_CQP_STAG_REM_ACC_EN
;
462 if (ibmr_access_flags
& IB_ACCESS_REMOTE_READ
) {
463 opcode
|= NES_CQP_STAG_RIGHTS_REMOTE_READ
|
464 NES_CQP_STAG_RIGHTS_LOCAL_READ
| NES_CQP_STAG_REM_ACC_EN
;
465 nesfmr
->access_rights
|=
466 NES_CQP_STAG_RIGHTS_REMOTE_READ
| NES_CQP_STAG_RIGHTS_LOCAL_READ
|
467 NES_CQP_STAG_REM_ACC_EN
;
470 nes_fill_init_cqp_wqe(cqp_wqe
, nesdev
);
471 set_wqe_32bit_value(cqp_wqe
->wqe_words
, NES_CQP_WQE_OPCODE_IDX
, opcode
);
472 set_wqe_32bit_value(cqp_wqe
->wqe_words
, NES_CQP_STAG_WQE_LEN_HIGH_PD_IDX
, (nespd
->pd_id
& 0x00007fff));
473 set_wqe_32bit_value(cqp_wqe
->wqe_words
, NES_CQP_STAG_WQE_STAG_IDX
, stag
);
475 cqp_wqe
->wqe_words
[NES_CQP_STAG_WQE_PBL_BLK_COUNT_IDX
] =
476 cpu_to_le32((nesfmr
->nesmr
.pbls_used
>1) ?
477 (nesfmr
->nesmr
.pbls_used
-1) : nesfmr
->nesmr
.pbls_used
);
479 atomic_set(&cqp_request
->refcount
, 2);
480 nes_post_cqp_request(nesdev
, cqp_request
);
483 ret
= wait_event_timeout(cqp_request
->waitq
, (cqp_request
->request_done
!= 0),
485 nes_debug(NES_DBG_MR
, "Register STag 0x%08X completed, wait_event_timeout ret = %u,"
486 " CQP Major:Minor codes = 0x%04X:0x%04X.\n",
487 stag
, ret
, cqp_request
->major_code
, cqp_request
->minor_code
);
489 if ((!ret
) || (cqp_request
->major_code
)) {
490 nes_put_cqp_request(nesdev
, cqp_request
);
491 ret
= (!ret
) ? -ETIME
: -EIO
;
492 goto failed_leaf_vpbl_pages_alloc
;
494 nes_put_cqp_request(nesdev
, cqp_request
);
495 nesfmr
->nesmr
.ibfmr
.lkey
= stag
;
496 nesfmr
->nesmr
.ibfmr
.rkey
= stag
;
497 nesfmr
->attr
= *ibfmr_attr
;
499 return &nesfmr
->nesmr
.ibfmr
;
501 failed_leaf_vpbl_pages_alloc
:
502 /* unroll all allocated pages */
503 for (i
=0; i
<nesfmr
->leaf_pbl_cnt
; i
++) {
504 if (nesfmr
->root_vpbl
.leaf_vpbl
[i
].pbl_vbase
) {
505 pci_free_consistent(nesdev
->pcidev
, 4096, nesfmr
->root_vpbl
.leaf_vpbl
[i
].pbl_vbase
,
506 nesfmr
->root_vpbl
.leaf_vpbl
[i
].pbl_pbase
);
509 if (nesfmr
->root_vpbl
.leaf_vpbl
)
510 kfree(nesfmr
->root_vpbl
.leaf_vpbl
);
512 failed_leaf_vpbl_alloc
:
513 if (nesfmr
->leaf_pbl_cnt
== 0) {
514 if (nesfmr
->root_vpbl
.pbl_vbase
)
515 pci_free_consistent(nesdev
->pcidev
, 4096, nesfmr
->root_vpbl
.pbl_vbase
,
516 nesfmr
->root_vpbl
.pbl_pbase
);
518 pci_free_consistent(nesdev
->pcidev
, 8192, nesfmr
->root_vpbl
.pbl_vbase
,
519 nesfmr
->root_vpbl
.pbl_pbase
);
522 if (nesfmr
->nesmr
.pbls_used
!= 0) {
523 spin_lock_irqsave(&nesadapter
->pbl_lock
, flags
);
524 if (nesfmr
->nesmr
.pbl_4k
)
525 nesadapter
->free_4kpbl
+= nesfmr
->nesmr
.pbls_used
;
527 nesadapter
->free_256pbl
+= nesfmr
->nesmr
.pbls_used
;
528 spin_unlock_irqrestore(&nesadapter
->pbl_lock
, flags
);
535 nes_free_resource(nesadapter
, nesadapter
->allocated_mrs
, stag_index
);
537 failed_resource_alloc
:
545 static int nes_dealloc_fmr(struct ib_fmr
*ibfmr
)
548 struct nes_mr
*nesmr
= to_nesmr_from_ibfmr(ibfmr
);
549 struct nes_fmr
*nesfmr
= to_nesfmr(nesmr
);
550 struct nes_vnic
*nesvnic
= to_nesvnic(ibfmr
->device
);
551 struct nes_device
*nesdev
= nesvnic
->nesdev
;
552 struct nes_adapter
*nesadapter
= nesdev
->nesadapter
;
555 /* free the resources */
556 if (nesfmr
->leaf_pbl_cnt
== 0) {
557 /* single PBL case */
558 if (nesfmr
->root_vpbl
.pbl_vbase
)
559 pci_free_consistent(nesdev
->pcidev
, 4096, nesfmr
->root_vpbl
.pbl_vbase
,
560 nesfmr
->root_vpbl
.pbl_pbase
);
562 for (i
= 0; i
< nesfmr
->leaf_pbl_cnt
; i
++) {
563 pci_free_consistent(nesdev
->pcidev
, 4096, nesfmr
->root_vpbl
.leaf_vpbl
[i
].pbl_vbase
,
564 nesfmr
->root_vpbl
.leaf_vpbl
[i
].pbl_pbase
);
566 kfree(nesfmr
->root_vpbl
.leaf_vpbl
);
567 pci_free_consistent(nesdev
->pcidev
, 8192, nesfmr
->root_vpbl
.pbl_vbase
,
568 nesfmr
->root_vpbl
.pbl_pbase
);
570 nesmr
->ibmw
.device
= ibfmr
->device
;
571 nesmr
->ibmw
.pd
= ibfmr
->pd
;
572 nesmr
->ibmw
.rkey
= ibfmr
->rkey
;
573 nesmr
->ibmw
.uobject
= NULL
;
575 if (nesfmr
->nesmr
.pbls_used
!= 0) {
576 spin_lock_irqsave(&nesadapter
->pbl_lock
, flags
);
577 if (nesfmr
->nesmr
.pbl_4k
) {
578 nesadapter
->free_4kpbl
+= nesfmr
->nesmr
.pbls_used
;
579 WARN_ON(nesadapter
->free_4kpbl
> nesadapter
->max_4kpbl
);
581 nesadapter
->free_256pbl
+= nesfmr
->nesmr
.pbls_used
;
582 WARN_ON(nesadapter
->free_256pbl
> nesadapter
->max_256pbl
);
584 spin_unlock_irqrestore(&nesadapter
->pbl_lock
, flags
);
587 return nes_dealloc_mw(&nesmr
->ibmw
);
594 static int nes_map_phys_fmr(struct ib_fmr
*ibfmr
, u64
*page_list
,
595 int list_len
, u64 iova
)
604 static int nes_unmap_fmr(struct list_head
*ibfmr_list
)
614 static int nes_query_device(struct ib_device
*ibdev
, struct ib_device_attr
*props
)
616 struct nes_vnic
*nesvnic
= to_nesvnic(ibdev
);
617 struct nes_device
*nesdev
= nesvnic
->nesdev
;
618 struct nes_ib_device
*nesibdev
= nesvnic
->nesibdev
;
620 memset(props
, 0, sizeof(*props
));
621 memcpy(&props
->sys_image_guid
, nesvnic
->netdev
->dev_addr
, 6);
623 props
->fw_ver
= nesdev
->nesadapter
->fw_ver
;
624 props
->device_cap_flags
= nesdev
->nesadapter
->device_cap_flags
;
625 props
->vendor_id
= nesdev
->nesadapter
->vendor_id
;
626 props
->vendor_part_id
= nesdev
->nesadapter
->vendor_part_id
;
627 props
->hw_ver
= nesdev
->nesadapter
->hw_rev
;
628 props
->max_mr_size
= 0x80000000;
629 props
->max_qp
= nesibdev
->max_qp
;
630 props
->max_qp_wr
= nesdev
->nesadapter
->max_qp_wr
- 2;
631 props
->max_sge
= nesdev
->nesadapter
->max_sge
;
632 props
->max_cq
= nesibdev
->max_cq
;
633 props
->max_cqe
= nesdev
->nesadapter
->max_cqe
- 1;
634 props
->max_mr
= nesibdev
->max_mr
;
635 props
->max_mw
= nesibdev
->max_mr
;
636 props
->max_pd
= nesibdev
->max_pd
;
637 props
->max_sge_rd
= 1;
638 switch (nesdev
->nesadapter
->max_irrq_wr
) {
640 props
->max_qp_rd_atom
= 1;
643 props
->max_qp_rd_atom
= 4;
646 props
->max_qp_rd_atom
= 16;
649 props
->max_qp_rd_atom
= 32;
652 props
->max_qp_rd_atom
= 0;
654 props
->max_qp_init_rd_atom
= props
->max_qp_wr
;
655 props
->atomic_cap
= IB_ATOMIC_NONE
;
656 props
->max_map_per_fmr
= 1;
665 static int nes_query_port(struct ib_device
*ibdev
, u8 port
, struct ib_port_attr
*props
)
667 memset(props
, 0, sizeof(*props
));
669 props
->max_mtu
= IB_MTU_2048
;
670 props
->active_mtu
= IB_MTU_2048
;
675 props
->state
= IB_PORT_ACTIVE
;
676 props
->phys_state
= 0;
677 props
->port_cap_flags
= IB_PORT_CM_SUP
| IB_PORT_REINIT_SUP
|
678 IB_PORT_VENDOR_CLASS_SUP
| IB_PORT_BOOT_MGMT_SUP
;
679 props
->gid_tbl_len
= 1;
680 props
->pkey_tbl_len
= 1;
681 props
->qkey_viol_cntr
= 0;
682 props
->active_width
= IB_WIDTH_4X
;
683 props
->active_speed
= 1;
684 props
->max_msg_sz
= 0x80000000;
693 static int nes_modify_port(struct ib_device
*ibdev
, u8 port
,
694 int port_modify_mask
, struct ib_port_modify
*props
)
703 static int nes_query_pkey(struct ib_device
*ibdev
, u8 port
, u16 index
, u16
*pkey
)
713 static int nes_query_gid(struct ib_device
*ibdev
, u8 port
,
714 int index
, union ib_gid
*gid
)
716 struct nes_vnic
*nesvnic
= to_nesvnic(ibdev
);
718 memset(&(gid
->raw
[0]), 0, sizeof(gid
->raw
));
719 memcpy(&(gid
->raw
[0]), nesvnic
->netdev
->dev_addr
, 6);
726 * nes_alloc_ucontext - Allocate the user context data structure. This keeps track
727 * of all objects associated with a particular user-mode client.
729 static struct ib_ucontext
*nes_alloc_ucontext(struct ib_device
*ibdev
,
730 struct ib_udata
*udata
)
732 struct nes_vnic
*nesvnic
= to_nesvnic(ibdev
);
733 struct nes_device
*nesdev
= nesvnic
->nesdev
;
734 struct nes_adapter
*nesadapter
= nesdev
->nesadapter
;
735 struct nes_alloc_ucontext_req req
;
736 struct nes_alloc_ucontext_resp uresp
;
737 struct nes_ucontext
*nes_ucontext
;
738 struct nes_ib_device
*nesibdev
= nesvnic
->nesibdev
;
741 if (ib_copy_from_udata(&req
, udata
, sizeof(struct nes_alloc_ucontext_req
))) {
742 printk(KERN_ERR PFX
"Invalid structure size on allocate user context.\n");
743 return ERR_PTR(-EINVAL
);
746 if (req
.userspace_ver
!= NES_ABI_USERSPACE_VER
) {
747 printk(KERN_ERR PFX
"Invalid userspace driver version detected. Detected version %d, should be %d\n",
748 req
.userspace_ver
, NES_ABI_USERSPACE_VER
);
749 return ERR_PTR(-EINVAL
);
753 memset(&uresp
, 0, sizeof uresp
);
755 uresp
.max_qps
= nesibdev
->max_qp
;
756 uresp
.max_pds
= nesibdev
->max_pd
;
757 uresp
.wq_size
= nesdev
->nesadapter
->max_qp_wr
* 2;
758 uresp
.virtwq
= nesadapter
->virtwq
;
759 uresp
.kernel_ver
= NES_ABI_KERNEL_VER
;
761 nes_ucontext
= kzalloc(sizeof *nes_ucontext
, GFP_KERNEL
);
763 return ERR_PTR(-ENOMEM
);
765 nes_ucontext
->nesdev
= nesdev
;
766 nes_ucontext
->mmap_wq_offset
= uresp
.max_pds
;
767 nes_ucontext
->mmap_cq_offset
= nes_ucontext
->mmap_wq_offset
+
768 ((sizeof(struct nes_hw_qp_wqe
) * uresp
.max_qps
* 2) + PAGE_SIZE
-1) /
772 if (ib_copy_to_udata(udata
, &uresp
, sizeof uresp
)) {
774 return ERR_PTR(-EFAULT
);
777 INIT_LIST_HEAD(&nes_ucontext
->cq_reg_mem_list
);
778 INIT_LIST_HEAD(&nes_ucontext
->qp_reg_mem_list
);
779 atomic_set(&nes_ucontext
->usecnt
, 1);
780 return &nes_ucontext
->ibucontext
;
785 * nes_dealloc_ucontext
787 static int nes_dealloc_ucontext(struct ib_ucontext
*context
)
789 /* struct nes_vnic *nesvnic = to_nesvnic(context->device); */
790 /* struct nes_device *nesdev = nesvnic->nesdev; */
791 struct nes_ucontext
*nes_ucontext
= to_nesucontext(context
);
793 if (!atomic_dec_and_test(&nes_ucontext
->usecnt
))
803 static int nes_mmap(struct ib_ucontext
*context
, struct vm_area_struct
*vma
)
806 struct nes_vnic
*nesvnic
= to_nesvnic(context
->device
);
807 struct nes_device
*nesdev
= nesvnic
->nesdev
;
808 /* struct nes_adapter *nesadapter = nesdev->nesadapter; */
809 struct nes_ucontext
*nes_ucontext
;
810 struct nes_qp
*nesqp
;
812 nes_ucontext
= to_nesucontext(context
);
815 if (vma
->vm_pgoff
>= nes_ucontext
->mmap_wq_offset
) {
816 index
= (vma
->vm_pgoff
- nes_ucontext
->mmap_wq_offset
) * PAGE_SIZE
;
817 index
/= ((sizeof(struct nes_hw_qp_wqe
) * nesdev
->nesadapter
->max_qp_wr
* 2) +
818 PAGE_SIZE
-1) & (~(PAGE_SIZE
-1));
819 if (!test_bit(index
, nes_ucontext
->allocated_wqs
)) {
820 nes_debug(NES_DBG_MMAP
, "wq %lu not allocated\n", index
);
823 nesqp
= nes_ucontext
->mmap_nesqp
[index
];
825 nes_debug(NES_DBG_MMAP
, "wq %lu has a NULL QP base.\n", index
);
828 if (remap_pfn_range(vma
, vma
->vm_start
,
829 virt_to_phys(nesqp
->hwqp
.sq_vbase
) >> PAGE_SHIFT
,
830 vma
->vm_end
- vma
->vm_start
,
831 vma
->vm_page_prot
)) {
832 nes_debug(NES_DBG_MMAP
, "remap_pfn_range failed.\n");
835 vma
->vm_private_data
= nesqp
;
838 index
= vma
->vm_pgoff
;
839 if (!test_bit(index
, nes_ucontext
->allocated_doorbells
))
842 vma
->vm_page_prot
= pgprot_noncached(vma
->vm_page_prot
);
843 if (io_remap_pfn_range(vma
, vma
->vm_start
,
844 (nesdev
->doorbell_start
+
845 ((nes_ucontext
->mmap_db_index
[index
] - nesdev
->base_doorbell_index
) * 4096))
846 >> PAGE_SHIFT
, PAGE_SIZE
, vma
->vm_page_prot
))
848 vma
->vm_private_data
= nes_ucontext
;
859 static struct ib_pd
*nes_alloc_pd(struct ib_device
*ibdev
,
860 struct ib_ucontext
*context
, struct ib_udata
*udata
)
862 struct nes_pd
*nespd
;
863 struct nes_vnic
*nesvnic
= to_nesvnic(ibdev
);
864 struct nes_device
*nesdev
= nesvnic
->nesdev
;
865 struct nes_adapter
*nesadapter
= nesdev
->nesadapter
;
866 struct nes_ucontext
*nesucontext
;
867 struct nes_alloc_pd_resp uresp
;
871 nes_debug(NES_DBG_PD
, "nesvnic=%p, netdev=%p %s, ibdev=%p, context=%p, netdev refcnt=%u\n",
872 nesvnic
, nesdev
->netdev
[0], nesdev
->netdev
[0]->name
, ibdev
, context
,
873 atomic_read(&nesvnic
->netdev
->refcnt
));
875 err
= nes_alloc_resource(nesadapter
, nesadapter
->allocated_pds
,
876 nesadapter
->max_pd
, &pd_num
, &nesadapter
->next_pd
);
881 nespd
= kzalloc(sizeof (struct nes_pd
), GFP_KERNEL
);
883 nes_free_resource(nesadapter
, nesadapter
->allocated_pds
, pd_num
);
884 return ERR_PTR(-ENOMEM
);
887 nes_debug(NES_DBG_PD
, "Allocating PD (%p) for ib device %s\n",
888 nespd
, nesvnic
->nesibdev
->ibdev
.name
);
890 nespd
->pd_id
= (pd_num
<< (PAGE_SHIFT
-12)) + nesadapter
->base_pd
;
893 nesucontext
= to_nesucontext(context
);
894 nespd
->mmap_db_index
= find_next_zero_bit(nesucontext
->allocated_doorbells
,
895 NES_MAX_USER_DB_REGIONS
, nesucontext
->first_free_db
);
896 nes_debug(NES_DBG_PD
, "find_first_zero_biton doorbells returned %u, mapping pd_id %u.\n",
897 nespd
->mmap_db_index
, nespd
->pd_id
);
898 if (nespd
->mmap_db_index
>= NES_MAX_USER_DB_REGIONS
) {
899 nes_debug(NES_DBG_PD
, "mmap_db_index > MAX\n");
900 nes_free_resource(nesadapter
, nesadapter
->allocated_pds
, pd_num
);
902 return ERR_PTR(-ENOMEM
);
905 uresp
.pd_id
= nespd
->pd_id
;
906 uresp
.mmap_db_index
= nespd
->mmap_db_index
;
907 if (ib_copy_to_udata(udata
, &uresp
, sizeof (struct nes_alloc_pd_resp
))) {
908 nes_free_resource(nesadapter
, nesadapter
->allocated_pds
, pd_num
);
910 return ERR_PTR(-EFAULT
);
913 set_bit(nespd
->mmap_db_index
, nesucontext
->allocated_doorbells
);
914 nesucontext
->mmap_db_index
[nespd
->mmap_db_index
] = nespd
->pd_id
;
915 nesucontext
->first_free_db
= nespd
->mmap_db_index
+ 1;
918 nes_debug(NES_DBG_PD
, "PD%u structure located @%p.\n", nespd
->pd_id
, nespd
);
926 static int nes_dealloc_pd(struct ib_pd
*ibpd
)
928 struct nes_ucontext
*nesucontext
;
929 struct nes_pd
*nespd
= to_nespd(ibpd
);
930 struct nes_vnic
*nesvnic
= to_nesvnic(ibpd
->device
);
931 struct nes_device
*nesdev
= nesvnic
->nesdev
;
932 struct nes_adapter
*nesadapter
= nesdev
->nesadapter
;
934 if ((ibpd
->uobject
) && (ibpd
->uobject
->context
)) {
935 nesucontext
= to_nesucontext(ibpd
->uobject
->context
);
936 nes_debug(NES_DBG_PD
, "Clearing bit %u from allocated doorbells\n",
937 nespd
->mmap_db_index
);
938 clear_bit(nespd
->mmap_db_index
, nesucontext
->allocated_doorbells
);
939 nesucontext
->mmap_db_index
[nespd
->mmap_db_index
] = 0;
940 if (nesucontext
->first_free_db
> nespd
->mmap_db_index
) {
941 nesucontext
->first_free_db
= nespd
->mmap_db_index
;
945 nes_debug(NES_DBG_PD
, "Deallocating PD%u structure located @%p.\n",
946 nespd
->pd_id
, nespd
);
947 nes_free_resource(nesadapter
, nesadapter
->allocated_pds
,
948 (nespd
->pd_id
-nesadapter
->base_pd
)>>(PAGE_SHIFT
-12));
958 static struct ib_ah
*nes_create_ah(struct ib_pd
*pd
, struct ib_ah_attr
*ah_attr
)
960 return ERR_PTR(-ENOSYS
);
967 static int nes_destroy_ah(struct ib_ah
*ah
)
974 * nes_get_encoded_size
976 static inline u8
nes_get_encoded_size(int *size
)
982 } else if (*size
<= 128) {
985 } else if (*size
<= 512) {
989 return (encoded_size
);
997 static int nes_setup_virt_qp(struct nes_qp
*nesqp
, struct nes_pbl
*nespbl
,
998 struct nes_vnic
*nesvnic
, int sq_size
, int rq_size
)
1000 unsigned long flags
;
1005 struct nes_device
*nesdev
= nesvnic
->nesdev
;
1006 struct nes_adapter
*nesadapter
= nesdev
->nesadapter
;
1011 pbl_entries
= nespbl
->pbl_size
>> 3;
1012 nes_debug(NES_DBG_QP
, "Userspace PBL, pbl_size=%u, pbl_entries = %d pbl_vbase=%p, pbl_pbase=%lx\n",
1013 nespbl
->pbl_size
, pbl_entries
,
1014 (void *)nespbl
->pbl_vbase
,
1015 (unsigned long) nespbl
->pbl_pbase
);
1016 pbl
= (__le64
*) nespbl
->pbl_vbase
; /* points to first pbl entry */
1017 /* now lets set the sq_vbase as well as rq_vbase addrs we will assign */
1018 /* the first pbl to be fro the rq_vbase... */
1019 rq_pbl_entries
= (rq_size
* sizeof(struct nes_hw_qp_wqe
)) >> 12;
1020 sq_pbl_entries
= (sq_size
* sizeof(struct nes_hw_qp_wqe
)) >> 12;
1021 nesqp
->hwqp
.sq_pbase
= (le32_to_cpu(((__le32
*)pbl
)[0])) | ((u64
)((le32_to_cpu(((__le32
*)pbl
)[1]))) << 32);
1022 if (!nespbl
->page
) {
1023 nes_debug(NES_DBG_QP
, "QP nespbl->page is NULL \n");
1028 nesqp
->hwqp
.sq_vbase
= kmap(nespbl
->page
);
1029 nesqp
->page
= nespbl
->page
;
1030 if (!nesqp
->hwqp
.sq_vbase
) {
1031 nes_debug(NES_DBG_QP
, "QP sq_vbase kmap failed\n");
1036 /* Now to get to sq.. we need to calculate how many */
1037 /* PBL entries were used by the rq.. */
1038 pbl
+= sq_pbl_entries
;
1039 nesqp
->hwqp
.rq_pbase
= (le32_to_cpu(((__le32
*)pbl
)[0])) | ((u64
)((le32_to_cpu(((__le32
*)pbl
)[1]))) << 32);
1040 /* nesqp->hwqp.rq_vbase = bus_to_virt(*pbl); */
1041 /*nesqp->hwqp.rq_vbase = phys_to_virt(*pbl); */
1043 nes_debug(NES_DBG_QP
, "QP sq_vbase= %p sq_pbase=%lx rq_vbase=%p rq_pbase=%lx\n",
1044 nesqp
->hwqp
.sq_vbase
, (unsigned long) nesqp
->hwqp
.sq_pbase
,
1045 nesqp
->hwqp
.rq_vbase
, (unsigned long) nesqp
->hwqp
.rq_pbase
);
1046 spin_lock_irqsave(&nesadapter
->pbl_lock
, flags
);
1047 if (!nesadapter
->free_256pbl
) {
1048 pci_free_consistent(nesdev
->pcidev
, nespbl
->pbl_size
, nespbl
->pbl_vbase
,
1050 spin_unlock_irqrestore(&nesadapter
->pbl_lock
, flags
);
1051 kunmap(nesqp
->page
);
1055 nesadapter
->free_256pbl
--;
1056 spin_unlock_irqrestore(&nesadapter
->pbl_lock
, flags
);
1058 nesqp
->pbl_vbase
= pci_alloc_consistent(nesdev
->pcidev
, 256, &nesqp
->pbl_pbase
);
1059 pblbuffer
= nesqp
->pbl_vbase
;
1060 if (!nesqp
->pbl_vbase
) {
1061 /* memory allocated during nes_reg_user_mr() */
1062 pci_free_consistent(nesdev
->pcidev
, nespbl
->pbl_size
, nespbl
->pbl_vbase
,
1065 spin_lock_irqsave(&nesadapter
->pbl_lock
, flags
);
1066 nesadapter
->free_256pbl
++;
1067 spin_unlock_irqrestore(&nesadapter
->pbl_lock
, flags
);
1068 kunmap(nesqp
->page
);
1071 memset(nesqp
->pbl_vbase
, 0, 256);
1072 /* fill in the page address in the pbl buffer.. */
1073 tpbl
= pblbuffer
+ 16;
1074 pbl
= (__le64
*)nespbl
->pbl_vbase
;
1075 while (sq_pbl_entries
--)
1078 while (rq_pbl_entries
--)
1081 /* done with memory allocated during nes_reg_user_mr() */
1082 pci_free_consistent(nesdev
->pcidev
, nespbl
->pbl_size
, nespbl
->pbl_vbase
,
1086 nesqp
->qp_mem_size
=
1087 max((u32
)sizeof(struct nes_qp_context
), ((u32
)256)) + 256; /* this is Q2 */
1088 /* Round up to a multiple of a page */
1089 nesqp
->qp_mem_size
+= PAGE_SIZE
- 1;
1090 nesqp
->qp_mem_size
&= ~(PAGE_SIZE
- 1);
1092 mem
= pci_alloc_consistent(nesdev
->pcidev
, nesqp
->qp_mem_size
,
1093 &nesqp
->hwqp
.q2_pbase
);
1096 pci_free_consistent(nesdev
->pcidev
, 256, nesqp
->pbl_vbase
, nesqp
->pbl_pbase
);
1097 nesqp
->pbl_vbase
= NULL
;
1098 spin_lock_irqsave(&nesadapter
->pbl_lock
, flags
);
1099 nesadapter
->free_256pbl
++;
1100 spin_unlock_irqrestore(&nesadapter
->pbl_lock
, flags
);
1101 kunmap(nesqp
->page
);
1104 nesqp
->hwqp
.q2_vbase
= mem
;
1106 memset(nesqp
->hwqp
.q2_vbase
, 0, 256);
1107 nesqp
->nesqp_context
= mem
;
1108 memset(nesqp
->nesqp_context
, 0, sizeof(*nesqp
->nesqp_context
));
1109 nesqp
->nesqp_context_pbase
= nesqp
->hwqp
.q2_pbase
+ 256;
1118 static int nes_setup_mmap_qp(struct nes_qp
*nesqp
, struct nes_vnic
*nesvnic
,
1119 int sq_size
, int rq_size
)
1122 struct nes_device
*nesdev
= nesvnic
->nesdev
;
1124 nesqp
->qp_mem_size
= (sizeof(struct nes_hw_qp_wqe
) * sq_size
) +
1125 (sizeof(struct nes_hw_qp_wqe
) * rq_size
) +
1126 max((u32
)sizeof(struct nes_qp_context
), ((u32
)256)) +
1127 256; /* this is Q2 */
1128 /* Round up to a multiple of a page */
1129 nesqp
->qp_mem_size
+= PAGE_SIZE
- 1;
1130 nesqp
->qp_mem_size
&= ~(PAGE_SIZE
- 1);
1132 mem
= pci_alloc_consistent(nesdev
->pcidev
, nesqp
->qp_mem_size
,
1133 &nesqp
->hwqp
.sq_pbase
);
1136 nes_debug(NES_DBG_QP
, "PCI consistent memory for "
1137 "host descriptor rings located @ %p (pa = 0x%08lX.) size = %u.\n",
1138 mem
, (unsigned long)nesqp
->hwqp
.sq_pbase
, nesqp
->qp_mem_size
);
1140 memset(mem
, 0, nesqp
->qp_mem_size
);
1142 nesqp
->hwqp
.sq_vbase
= mem
;
1143 mem
+= sizeof(struct nes_hw_qp_wqe
) * sq_size
;
1145 nesqp
->hwqp
.rq_vbase
= mem
;
1146 nesqp
->hwqp
.rq_pbase
= nesqp
->hwqp
.sq_pbase
+
1147 sizeof(struct nes_hw_qp_wqe
) * sq_size
;
1148 mem
+= sizeof(struct nes_hw_qp_wqe
) * rq_size
;
1150 nesqp
->hwqp
.q2_vbase
= mem
;
1151 nesqp
->hwqp
.q2_pbase
= nesqp
->hwqp
.rq_pbase
+
1152 sizeof(struct nes_hw_qp_wqe
) * rq_size
;
1154 memset(nesqp
->hwqp
.q2_vbase
, 0, 256);
1156 nesqp
->nesqp_context
= mem
;
1157 nesqp
->nesqp_context_pbase
= nesqp
->hwqp
.q2_pbase
+ 256;
1158 memset(nesqp
->nesqp_context
, 0, sizeof(*nesqp
->nesqp_context
));
1164 * nes_free_qp_mem() is to free up the qp's pci_alloc_consistent() memory.
1166 static inline void nes_free_qp_mem(struct nes_device
*nesdev
,
1167 struct nes_qp
*nesqp
, int virt_wqs
)
1169 unsigned long flags
;
1170 struct nes_adapter
*nesadapter
= nesdev
->nesadapter
;
1172 pci_free_consistent(nesdev
->pcidev
, nesqp
->qp_mem_size
,
1173 nesqp
->hwqp
.sq_vbase
, nesqp
->hwqp
.sq_pbase
);
1175 spin_lock_irqsave(&nesadapter
->pbl_lock
, flags
);
1176 nesadapter
->free_256pbl
++;
1177 spin_unlock_irqrestore(&nesadapter
->pbl_lock
, flags
);
1178 pci_free_consistent(nesdev
->pcidev
, nesqp
->qp_mem_size
, nesqp
->hwqp
.q2_vbase
, nesqp
->hwqp
.q2_pbase
);
1179 pci_free_consistent(nesdev
->pcidev
, 256, nesqp
->pbl_vbase
, nesqp
->pbl_pbase
);
1180 nesqp
->pbl_vbase
= NULL
;
1181 kunmap(nesqp
->page
);
1189 static struct ib_qp
*nes_create_qp(struct ib_pd
*ibpd
,
1190 struct ib_qp_init_attr
*init_attr
, struct ib_udata
*udata
)
1194 struct nes_pd
*nespd
= to_nespd(ibpd
);
1195 struct nes_vnic
*nesvnic
= to_nesvnic(ibpd
->device
);
1196 struct nes_device
*nesdev
= nesvnic
->nesdev
;
1197 struct nes_adapter
*nesadapter
= nesdev
->nesadapter
;
1198 struct nes_qp
*nesqp
;
1199 struct nes_cq
*nescq
;
1200 struct nes_ucontext
*nes_ucontext
;
1201 struct nes_hw_cqp_wqe
*cqp_wqe
;
1202 struct nes_cqp_request
*cqp_request
;
1203 struct nes_create_qp_req req
;
1204 struct nes_create_qp_resp uresp
;
1205 struct nes_pbl
*nespbl
= NULL
;
1208 /* u32 counter = 0; */
1210 unsigned long flags
;
1220 if (init_attr
->create_flags
)
1221 return ERR_PTR(-EINVAL
);
1223 atomic_inc(&qps_created
);
1224 switch (init_attr
->qp_type
) {
1226 if (nes_drv_opt
& NES_DRV_OPT_NO_INLINE_DATA
) {
1227 init_attr
->cap
.max_inline_data
= 0;
1229 init_attr
->cap
.max_inline_data
= 64;
1231 sq_size
= init_attr
->cap
.max_send_wr
;
1232 rq_size
= init_attr
->cap
.max_recv_wr
;
1234 /* check if the encoded sizes are OK or not... */
1235 sq_encoded_size
= nes_get_encoded_size(&sq_size
);
1236 rq_encoded_size
= nes_get_encoded_size(&rq_size
);
1238 if ((!sq_encoded_size
) || (!rq_encoded_size
)) {
1239 nes_debug(NES_DBG_QP
, "ERROR bad rq (%u) or sq (%u) size\n",
1241 return ERR_PTR(-EINVAL
);
1244 init_attr
->cap
.max_send_wr
= sq_size
-2;
1245 init_attr
->cap
.max_recv_wr
= rq_size
-1;
1246 nes_debug(NES_DBG_QP
, "RQ size=%u, SQ Size=%u\n", rq_size
, sq_size
);
1248 ret
= nes_alloc_resource(nesadapter
, nesadapter
->allocated_qps
,
1249 nesadapter
->max_qp
, &qp_num
, &nesadapter
->next_qp
);
1251 return ERR_PTR(ret
);
1254 /* Need 512 (actually now 1024) byte alignment on this structure */
1255 mem
= kzalloc(sizeof(*nesqp
)+NES_SW_CONTEXT_ALIGN
-1, GFP_KERNEL
);
1257 nes_free_resource(nesadapter
, nesadapter
->allocated_qps
, qp_num
);
1258 nes_debug(NES_DBG_QP
, "Unable to allocate QP\n");
1259 return ERR_PTR(-ENOMEM
);
1261 u64nesqp
= (unsigned long)mem
;
1262 u64nesqp
+= ((u64
)NES_SW_CONTEXT_ALIGN
) - 1;
1263 u64temp
= ((u64
)NES_SW_CONTEXT_ALIGN
) - 1;
1264 u64nesqp
&= ~u64temp
;
1265 nesqp
= (struct nes_qp
*)(unsigned long)u64nesqp
;
1266 /* nes_debug(NES_DBG_QP, "nesqp=%p, allocated buffer=%p. Rounded to closest %u\n",
1267 nesqp, mem, NES_SW_CONTEXT_ALIGN); */
1268 nesqp
->allocated_buffer
= mem
;
1271 if (ib_copy_from_udata(&req
, udata
, sizeof(struct nes_create_qp_req
))) {
1272 nes_free_resource(nesadapter
, nesadapter
->allocated_qps
, qp_num
);
1273 kfree(nesqp
->allocated_buffer
);
1274 nes_debug(NES_DBG_QP
, "ib_copy_from_udata() Failed \n");
1277 if (req
.user_wqe_buffers
) {
1280 if ((ibpd
->uobject
) && (ibpd
->uobject
->context
)) {
1281 nesqp
->user_mode
= 1;
1282 nes_ucontext
= to_nesucontext(ibpd
->uobject
->context
);
1285 list_for_each_entry(nespbl
, &nes_ucontext
->qp_reg_mem_list
, list
) {
1286 if (nespbl
->user_base
== (unsigned long )req
.user_wqe_buffers
) {
1287 list_del(&nespbl
->list
);
1289 nes_debug(NES_DBG_QP
, "Found PBL for virtual QP. nespbl=%p. user_base=0x%lx\n",
1290 nespbl
, nespbl
->user_base
);
1295 nes_debug(NES_DBG_QP
, "Didn't Find PBL for virtual QP. address = %llx.\n",
1296 (long long unsigned int)req
.user_wqe_buffers
);
1297 nes_free_resource(nesadapter
, nesadapter
->allocated_qps
, qp_num
);
1298 kfree(nesqp
->allocated_buffer
);
1299 return ERR_PTR(-EFAULT
);
1303 nes_ucontext
= to_nesucontext(ibpd
->uobject
->context
);
1304 nesqp
->mmap_sq_db_index
=
1305 find_next_zero_bit(nes_ucontext
->allocated_wqs
,
1306 NES_MAX_USER_WQ_REGIONS
, nes_ucontext
->first_free_wq
);
1307 /* nes_debug(NES_DBG_QP, "find_first_zero_biton wqs returned %u\n",
1308 nespd->mmap_db_index); */
1309 if (nesqp
->mmap_sq_db_index
>= NES_MAX_USER_WQ_REGIONS
) {
1310 nes_debug(NES_DBG_QP
,
1311 "db index > max user regions, failing create QP\n");
1312 nes_free_resource(nesadapter
, nesadapter
->allocated_qps
, qp_num
);
1314 pci_free_consistent(nesdev
->pcidev
, nespbl
->pbl_size
, nespbl
->pbl_vbase
,
1318 kfree(nesqp
->allocated_buffer
);
1319 return ERR_PTR(-ENOMEM
);
1321 set_bit(nesqp
->mmap_sq_db_index
, nes_ucontext
->allocated_wqs
);
1322 nes_ucontext
->mmap_nesqp
[nesqp
->mmap_sq_db_index
] = nesqp
;
1323 nes_ucontext
->first_free_wq
= nesqp
->mmap_sq_db_index
+ 1;
1325 nes_free_resource(nesadapter
, nesadapter
->allocated_qps
, qp_num
);
1326 kfree(nesqp
->allocated_buffer
);
1327 return ERR_PTR(-EFAULT
);
1330 err
= (!virt_wqs
) ? nes_setup_mmap_qp(nesqp
, nesvnic
, sq_size
, rq_size
) :
1331 nes_setup_virt_qp(nesqp
, nespbl
, nesvnic
, sq_size
, rq_size
);
1333 nes_debug(NES_DBG_QP
,
1334 "error geting qp mem code = %d\n", err
);
1335 nes_free_resource(nesadapter
, nesadapter
->allocated_qps
, qp_num
);
1336 kfree(nesqp
->allocated_buffer
);
1337 return ERR_PTR(-ENOMEM
);
1340 nesqp
->hwqp
.sq_size
= sq_size
;
1341 nesqp
->hwqp
.sq_encoded_size
= sq_encoded_size
;
1342 nesqp
->hwqp
.sq_head
= 1;
1343 nesqp
->hwqp
.rq_size
= rq_size
;
1344 nesqp
->hwqp
.rq_encoded_size
= rq_encoded_size
;
1345 /* nes_debug(NES_DBG_QP, "nesqp->nesqp_context_pbase = %p\n",
1346 (void *)nesqp->nesqp_context_pbase);
1348 nesqp
->hwqp
.qp_id
= qp_num
;
1349 nesqp
->ibqp
.qp_num
= nesqp
->hwqp
.qp_id
;
1350 nesqp
->nespd
= nespd
;
1352 nescq
= to_nescq(init_attr
->send_cq
);
1353 nesqp
->nesscq
= nescq
;
1354 nescq
= to_nescq(init_attr
->recv_cq
);
1355 nesqp
->nesrcq
= nescq
;
1357 nesqp
->nesqp_context
->misc
|= cpu_to_le32((u32
)PCI_FUNC(nesdev
->pcidev
->devfn
) <<
1358 NES_QPCONTEXT_MISC_PCI_FCN_SHIFT
);
1359 nesqp
->nesqp_context
->misc
|= cpu_to_le32((u32
)nesqp
->hwqp
.rq_encoded_size
<<
1360 NES_QPCONTEXT_MISC_RQ_SIZE_SHIFT
);
1361 nesqp
->nesqp_context
->misc
|= cpu_to_le32((u32
)nesqp
->hwqp
.sq_encoded_size
<<
1362 NES_QPCONTEXT_MISC_SQ_SIZE_SHIFT
);
1364 nesqp
->nesqp_context
->misc
|= cpu_to_le32(NES_QPCONTEXT_MISC_PRIV_EN
);
1365 nesqp
->nesqp_context
->misc
|= cpu_to_le32(NES_QPCONTEXT_MISC_FAST_REGISTER_EN
);
1367 nesqp
->nesqp_context
->cqs
= cpu_to_le32(nesqp
->nesscq
->hw_cq
.cq_number
+
1368 ((u32
)nesqp
->nesrcq
->hw_cq
.cq_number
<< 16));
1369 u64temp
= (u64
)nesqp
->hwqp
.sq_pbase
;
1370 nesqp
->nesqp_context
->sq_addr_low
= cpu_to_le32((u32
)u64temp
);
1371 nesqp
->nesqp_context
->sq_addr_high
= cpu_to_le32((u32
)(u64temp
>> 32));
1375 u64temp
= (u64
)nesqp
->hwqp
.sq_pbase
;
1376 nesqp
->nesqp_context
->sq_addr_low
= cpu_to_le32((u32
)u64temp
);
1377 nesqp
->nesqp_context
->sq_addr_high
= cpu_to_le32((u32
)(u64temp
>> 32));
1378 u64temp
= (u64
)nesqp
->hwqp
.rq_pbase
;
1379 nesqp
->nesqp_context
->rq_addr_low
= cpu_to_le32((u32
)u64temp
);
1380 nesqp
->nesqp_context
->rq_addr_high
= cpu_to_le32((u32
)(u64temp
>> 32));
1382 u64temp
= (u64
)nesqp
->pbl_pbase
;
1383 nesqp
->nesqp_context
->rq_addr_low
= cpu_to_le32((u32
)u64temp
);
1384 nesqp
->nesqp_context
->rq_addr_high
= cpu_to_le32((u32
)(u64temp
>> 32));
1387 /* nes_debug(NES_DBG_QP, "next_qp_nic_index=%u, using nic_index=%d\n",
1388 nesvnic->next_qp_nic_index,
1389 nesvnic->qp_nic_index[nesvnic->next_qp_nic_index]); */
1390 spin_lock_irqsave(&nesdev
->cqp
.lock
, flags
);
1391 nesqp
->nesqp_context
->misc2
|= cpu_to_le32(
1392 (u32
)nesvnic
->qp_nic_index
[nesvnic
->next_qp_nic_index
] <<
1393 NES_QPCONTEXT_MISC2_NIC_INDEX_SHIFT
);
1394 nesvnic
->next_qp_nic_index
++;
1395 if ((nesvnic
->next_qp_nic_index
> 3) ||
1396 (nesvnic
->qp_nic_index
[nesvnic
->next_qp_nic_index
] == 0xf)) {
1397 nesvnic
->next_qp_nic_index
= 0;
1399 spin_unlock_irqrestore(&nesdev
->cqp
.lock
, flags
);
1401 nesqp
->nesqp_context
->pd_index_wscale
|= cpu_to_le32((u32
)nesqp
->nespd
->pd_id
<< 16);
1402 u64temp
= (u64
)nesqp
->hwqp
.q2_pbase
;
1403 nesqp
->nesqp_context
->q2_addr_low
= cpu_to_le32((u32
)u64temp
);
1404 nesqp
->nesqp_context
->q2_addr_high
= cpu_to_le32((u32
)(u64temp
>> 32));
1405 nesqp
->nesqp_context
->aeq_token_low
= cpu_to_le32((u32
)((unsigned long)(nesqp
)));
1406 nesqp
->nesqp_context
->aeq_token_high
= cpu_to_le32((u32
)(upper_32_bits((unsigned long)(nesqp
))));
1407 nesqp
->nesqp_context
->ird_ord_sizes
= cpu_to_le32(NES_QPCONTEXT_ORDIRD_ALSMM
|
1408 ((((u32
)nesadapter
->max_irrq_wr
) <<
1409 NES_QPCONTEXT_ORDIRD_IRDSIZE_SHIFT
) & NES_QPCONTEXT_ORDIRD_IRDSIZE_MASK
));
1410 if (disable_mpa_crc
) {
1411 nes_debug(NES_DBG_QP
, "Disabling MPA crc checking due to module option.\n");
1412 nesqp
->nesqp_context
->ird_ord_sizes
|= cpu_to_le32(NES_QPCONTEXT_ORDIRD_RNMC
);
1417 cqp_request
= nes_get_cqp_request(nesdev
);
1418 if (cqp_request
== NULL
) {
1419 nes_debug(NES_DBG_QP
, "Failed to get a cqp_request\n");
1420 nes_free_resource(nesadapter
, nesadapter
->allocated_qps
, qp_num
);
1421 nes_free_qp_mem(nesdev
, nesqp
,virt_wqs
);
1422 kfree(nesqp
->allocated_buffer
);
1423 return ERR_PTR(-ENOMEM
);
1425 cqp_request
->waiting
= 1;
1426 cqp_wqe
= &cqp_request
->cqp_wqe
;
1429 opcode
= NES_CQP_CREATE_QP
| NES_CQP_QP_TYPE_IWARP
|
1430 NES_CQP_QP_IWARP_STATE_IDLE
;
1432 opcode
= NES_CQP_CREATE_QP
| NES_CQP_QP_TYPE_IWARP
| NES_CQP_QP_VIRT_WQS
|
1433 NES_CQP_QP_IWARP_STATE_IDLE
;
1435 opcode
|= NES_CQP_QP_CQS_VALID
;
1436 nes_fill_init_cqp_wqe(cqp_wqe
, nesdev
);
1437 set_wqe_32bit_value(cqp_wqe
->wqe_words
, NES_CQP_WQE_OPCODE_IDX
, opcode
);
1438 set_wqe_32bit_value(cqp_wqe
->wqe_words
, NES_CQP_WQE_ID_IDX
, nesqp
->hwqp
.qp_id
);
1440 u64temp
= (u64
)nesqp
->nesqp_context_pbase
;
1441 set_wqe_64bit_value(cqp_wqe
->wqe_words
, NES_CQP_QP_WQE_CONTEXT_LOW_IDX
, u64temp
);
1443 atomic_set(&cqp_request
->refcount
, 2);
1444 nes_post_cqp_request(nesdev
, cqp_request
);
1447 nes_debug(NES_DBG_QP
, "Waiting for create iWARP QP%u to complete.\n",
1449 ret
= wait_event_timeout(cqp_request
->waitq
,
1450 (cqp_request
->request_done
!= 0), NES_EVENT_TIMEOUT
);
1451 nes_debug(NES_DBG_QP
, "Create iwarp QP%u completed, wait_event_timeout ret=%u,"
1452 " nesdev->cqp_head = %u, nesdev->cqp.sq_tail = %u,"
1453 " CQP Major:Minor codes = 0x%04X:0x%04X.\n",
1454 nesqp
->hwqp
.qp_id
, ret
, nesdev
->cqp
.sq_head
, nesdev
->cqp
.sq_tail
,
1455 cqp_request
->major_code
, cqp_request
->minor_code
);
1456 if ((!ret
) || (cqp_request
->major_code
)) {
1457 nes_put_cqp_request(nesdev
, cqp_request
);
1458 nes_free_resource(nesadapter
, nesadapter
->allocated_qps
, qp_num
);
1459 nes_free_qp_mem(nesdev
, nesqp
,virt_wqs
);
1460 kfree(nesqp
->allocated_buffer
);
1462 return ERR_PTR(-ETIME
);
1464 return ERR_PTR(-EIO
);
1468 nes_put_cqp_request(nesdev
, cqp_request
);
1470 if (ibpd
->uobject
) {
1471 uresp
.mmap_sq_db_index
= nesqp
->mmap_sq_db_index
;
1472 uresp
.actual_sq_size
= sq_size
;
1473 uresp
.actual_rq_size
= rq_size
;
1474 uresp
.qp_id
= nesqp
->hwqp
.qp_id
;
1475 uresp
.nes_drv_opt
= nes_drv_opt
;
1476 if (ib_copy_to_udata(udata
, &uresp
, sizeof uresp
)) {
1477 nes_free_resource(nesadapter
, nesadapter
->allocated_qps
, qp_num
);
1478 nes_free_qp_mem(nesdev
, nesqp
,virt_wqs
);
1479 kfree(nesqp
->allocated_buffer
);
1480 return ERR_PTR(-EFAULT
);
1484 nes_debug(NES_DBG_QP
, "QP%u structure located @%p.Size = %u.\n",
1485 nesqp
->hwqp
.qp_id
, nesqp
, (u32
)sizeof(*nesqp
));
1486 spin_lock_init(&nesqp
->lock
);
1487 init_waitqueue_head(&nesqp
->state_waitq
);
1488 init_waitqueue_head(&nesqp
->kick_waitq
);
1489 nes_add_ref(&nesqp
->ibqp
);
1492 nes_debug(NES_DBG_QP
, "Invalid QP type: %d\n", init_attr
->qp_type
);
1493 return ERR_PTR(-EINVAL
);
1496 /* update the QP table */
1497 nesdev
->nesadapter
->qp_table
[nesqp
->hwqp
.qp_id
-NES_FIRST_QPN
] = nesqp
;
1498 nes_debug(NES_DBG_QP
, "netdev refcnt=%u\n",
1499 atomic_read(&nesvnic
->netdev
->refcnt
));
1501 return &nesqp
->ibqp
;
1508 static int nes_destroy_qp(struct ib_qp
*ibqp
)
1510 struct nes_qp
*nesqp
= to_nesqp(ibqp
);
1511 /* struct nes_vnic *nesvnic = to_nesvnic(ibqp->device); */
1512 struct nes_ucontext
*nes_ucontext
;
1513 struct ib_qp_attr attr
;
1514 struct iw_cm_id
*cm_id
;
1515 struct iw_cm_event cm_event
;
1518 atomic_inc(&sw_qps_destroyed
);
1519 nesqp
->destroyed
= 1;
1521 /* Blow away the connection if it exists. */
1522 if (nesqp
->ibqp_state
>= IB_QPS_INIT
&& nesqp
->ibqp_state
<= IB_QPS_RTS
) {
1523 /* if (nesqp->ibqp_state == IB_QPS_RTS) { */
1524 attr
.qp_state
= IB_QPS_ERR
;
1525 nes_modify_qp(&nesqp
->ibqp
, &attr
, IB_QP_STATE
, NULL
);
1528 if (((nesqp
->ibqp_state
== IB_QPS_INIT
) ||
1529 (nesqp
->ibqp_state
== IB_QPS_RTR
)) && (nesqp
->cm_id
)) {
1530 cm_id
= nesqp
->cm_id
;
1531 cm_event
.event
= IW_CM_EVENT_CONNECT_REPLY
;
1532 cm_event
.status
= IW_CM_EVENT_STATUS_TIMEOUT
;
1533 cm_event
.local_addr
= cm_id
->local_addr
;
1534 cm_event
.remote_addr
= cm_id
->remote_addr
;
1535 cm_event
.private_data
= NULL
;
1536 cm_event
.private_data_len
= 0;
1538 nes_debug(NES_DBG_QP
, "Generating a CM Timeout Event for "
1539 "QP%u. cm_id = %p, refcount = %u. \n",
1540 nesqp
->hwqp
.qp_id
, cm_id
, atomic_read(&nesqp
->refcount
));
1542 cm_id
->rem_ref(cm_id
);
1543 ret
= cm_id
->event_handler(cm_id
, &cm_event
);
1545 nes_debug(NES_DBG_QP
, "OFA CM event_handler returned, ret=%d\n", ret
);
1549 if (nesqp
->user_mode
) {
1550 if ((ibqp
->uobject
)&&(ibqp
->uobject
->context
)) {
1551 nes_ucontext
= to_nesucontext(ibqp
->uobject
->context
);
1552 clear_bit(nesqp
->mmap_sq_db_index
, nes_ucontext
->allocated_wqs
);
1553 nes_ucontext
->mmap_nesqp
[nesqp
->mmap_sq_db_index
] = NULL
;
1554 if (nes_ucontext
->first_free_wq
> nesqp
->mmap_sq_db_index
) {
1555 nes_ucontext
->first_free_wq
= nesqp
->mmap_sq_db_index
;
1558 if (nesqp
->pbl_pbase
)
1559 kunmap(nesqp
->page
);
1562 nes_rem_ref(&nesqp
->ibqp
);
1570 static struct ib_cq
*nes_create_cq(struct ib_device
*ibdev
, int entries
,
1572 struct ib_ucontext
*context
, struct ib_udata
*udata
)
1575 struct nes_vnic
*nesvnic
= to_nesvnic(ibdev
);
1576 struct nes_device
*nesdev
= nesvnic
->nesdev
;
1577 struct nes_adapter
*nesadapter
= nesdev
->nesadapter
;
1578 struct nes_cq
*nescq
;
1579 struct nes_ucontext
*nes_ucontext
= NULL
;
1580 struct nes_cqp_request
*cqp_request
;
1582 struct nes_hw_cqp_wqe
*cqp_wqe
;
1583 struct nes_pbl
*nespbl
= NULL
;
1584 struct nes_create_cq_req req
;
1585 struct nes_create_cq_resp resp
;
1588 u32 pbl_entries
= 1;
1590 unsigned long flags
;
1593 err
= nes_alloc_resource(nesadapter
, nesadapter
->allocated_cqs
,
1594 nesadapter
->max_cq
, &cq_num
, &nesadapter
->next_cq
);
1596 return ERR_PTR(err
);
1599 nescq
= kzalloc(sizeof(struct nes_cq
), GFP_KERNEL
);
1601 nes_free_resource(nesadapter
, nesadapter
->allocated_cqs
, cq_num
);
1602 nes_debug(NES_DBG_CQ
, "Unable to allocate nes_cq struct\n");
1603 return ERR_PTR(-ENOMEM
);
1606 nescq
->hw_cq
.cq_size
= max(entries
+ 1, 5);
1607 nescq
->hw_cq
.cq_number
= cq_num
;
1608 nescq
->ibcq
.cqe
= nescq
->hw_cq
.cq_size
- 1;
1612 nes_ucontext
= to_nesucontext(context
);
1613 if (ib_copy_from_udata(&req
, udata
, sizeof (struct nes_create_cq_req
))) {
1614 nes_free_resource(nesadapter
, nesadapter
->allocated_cqs
, cq_num
);
1616 return ERR_PTR(-EFAULT
);
1618 nesvnic
->mcrq_ucontext
= nes_ucontext
;
1619 nes_ucontext
->mcrqf
= req
.mcrqf
;
1620 if (nes_ucontext
->mcrqf
) {
1621 if (nes_ucontext
->mcrqf
& 0x80000000)
1622 nescq
->hw_cq
.cq_number
= nesvnic
->nic
.qp_id
+ 28 + 2 * ((nes_ucontext
->mcrqf
& 0xf) - 1);
1623 else if (nes_ucontext
->mcrqf
& 0x40000000)
1624 nescq
->hw_cq
.cq_number
= nes_ucontext
->mcrqf
& 0xffff;
1626 nescq
->hw_cq
.cq_number
= nesvnic
->mcrq_qp_id
+ nes_ucontext
->mcrqf
-1;
1627 nes_free_resource(nesadapter
, nesadapter
->allocated_cqs
, cq_num
);
1629 nes_debug(NES_DBG_CQ
, "CQ Virtual Address = %08lX, size = %u.\n",
1630 (unsigned long)req
.user_cq_buffer
, entries
);
1632 list_for_each_entry(nespbl
, &nes_ucontext
->cq_reg_mem_list
, list
) {
1633 if (nespbl
->user_base
== (unsigned long )req
.user_cq_buffer
) {
1634 list_del(&nespbl
->list
);
1636 nes_debug(NES_DBG_CQ
, "Found PBL for virtual CQ. nespbl=%p.\n",
1642 nes_free_resource(nesadapter
, nesadapter
->allocated_cqs
, cq_num
);
1644 return ERR_PTR(-EFAULT
);
1647 pbl_entries
= nespbl
->pbl_size
>> 3;
1648 nescq
->cq_mem_size
= 0;
1650 nescq
->cq_mem_size
= nescq
->hw_cq
.cq_size
* sizeof(struct nes_hw_cqe
);
1651 nes_debug(NES_DBG_CQ
, "Attempting to allocate pci memory (%u entries, %u bytes) for CQ%u.\n",
1652 entries
, nescq
->cq_mem_size
, nescq
->hw_cq
.cq_number
);
1654 /* allocate the physical buffer space */
1655 mem
= pci_alloc_consistent(nesdev
->pcidev
, nescq
->cq_mem_size
,
1656 &nescq
->hw_cq
.cq_pbase
);
1658 printk(KERN_ERR PFX
"Unable to allocate pci memory for cq\n");
1659 nes_free_resource(nesadapter
, nesadapter
->allocated_cqs
, cq_num
);
1661 return ERR_PTR(-ENOMEM
);
1664 memset(mem
, 0, nescq
->cq_mem_size
);
1665 nescq
->hw_cq
.cq_vbase
= mem
;
1666 nescq
->hw_cq
.cq_head
= 0;
1667 nes_debug(NES_DBG_CQ
, "CQ%u virtual address @ %p, phys = 0x%08X\n",
1668 nescq
->hw_cq
.cq_number
, nescq
->hw_cq
.cq_vbase
,
1669 (u32
)nescq
->hw_cq
.cq_pbase
);
1672 nescq
->hw_cq
.ce_handler
= nes_iwarp_ce_handler
;
1673 spin_lock_init(&nescq
->lock
);
1675 /* send CreateCQ request to CQP */
1676 cqp_request
= nes_get_cqp_request(nesdev
);
1677 if (cqp_request
== NULL
) {
1678 nes_debug(NES_DBG_CQ
, "Failed to get a cqp_request.\n");
1680 pci_free_consistent(nesdev
->pcidev
, nescq
->cq_mem_size
, mem
,
1681 nescq
->hw_cq
.cq_pbase
);
1682 nes_free_resource(nesadapter
, nesadapter
->allocated_cqs
, cq_num
);
1684 return ERR_PTR(-ENOMEM
);
1686 cqp_request
->waiting
= 1;
1687 cqp_wqe
= &cqp_request
->cqp_wqe
;
1689 opcode
= NES_CQP_CREATE_CQ
| NES_CQP_CQ_CEQ_VALID
|
1690 NES_CQP_CQ_CHK_OVERFLOW
|
1691 NES_CQP_CQ_CEQE_MASK
| ((u32
)nescq
->hw_cq
.cq_size
<< 16);
1693 spin_lock_irqsave(&nesadapter
->pbl_lock
, flags
);
1695 if (pbl_entries
!= 1) {
1696 if (pbl_entries
> 32) {
1698 nes_debug(NES_DBG_CQ
, "pbl_entries=%u, use a 4k PBL\n", pbl_entries
);
1699 if (nesadapter
->free_4kpbl
== 0) {
1700 spin_unlock_irqrestore(&nesadapter
->pbl_lock
, flags
);
1701 nes_free_cqp_request(nesdev
, cqp_request
);
1703 pci_free_consistent(nesdev
->pcidev
, nescq
->cq_mem_size
, mem
,
1704 nescq
->hw_cq
.cq_pbase
);
1705 nes_free_resource(nesadapter
, nesadapter
->allocated_cqs
, cq_num
);
1707 return ERR_PTR(-ENOMEM
);
1709 opcode
|= (NES_CQP_CQ_VIRT
| NES_CQP_CQ_4KB_CHUNK
);
1710 nescq
->virtual_cq
= 2;
1711 nesadapter
->free_4kpbl
--;
1714 /* use 256 byte pbl */
1715 nes_debug(NES_DBG_CQ
, "pbl_entries=%u, use a 256 byte PBL\n", pbl_entries
);
1716 if (nesadapter
->free_256pbl
== 0) {
1717 spin_unlock_irqrestore(&nesadapter
->pbl_lock
, flags
);
1718 nes_free_cqp_request(nesdev
, cqp_request
);
1720 pci_free_consistent(nesdev
->pcidev
, nescq
->cq_mem_size
, mem
,
1721 nescq
->hw_cq
.cq_pbase
);
1722 nes_free_resource(nesadapter
, nesadapter
->allocated_cqs
, cq_num
);
1724 return ERR_PTR(-ENOMEM
);
1726 opcode
|= NES_CQP_CQ_VIRT
;
1727 nescq
->virtual_cq
= 1;
1728 nesadapter
->free_256pbl
--;
1733 spin_unlock_irqrestore(&nesadapter
->pbl_lock
, flags
);
1735 nes_fill_init_cqp_wqe(cqp_wqe
, nesdev
);
1736 set_wqe_32bit_value(cqp_wqe
->wqe_words
, NES_CQP_WQE_OPCODE_IDX
, opcode
);
1737 set_wqe_32bit_value(cqp_wqe
->wqe_words
, NES_CQP_WQE_ID_IDX
,
1738 (nescq
->hw_cq
.cq_number
| ((u32
)nesdev
->ceq_index
<< 16)));
1741 if (pbl_entries
!= 1)
1742 u64temp
= (u64
)nespbl
->pbl_pbase
;
1744 u64temp
= le64_to_cpu(nespbl
->pbl_vbase
[0]);
1745 set_wqe_32bit_value(cqp_wqe
->wqe_words
, NES_CQP_CQ_WQE_DOORBELL_INDEX_HIGH_IDX
,
1746 nes_ucontext
->mmap_db_index
[0]);
1748 u64temp
= (u64
)nescq
->hw_cq
.cq_pbase
;
1749 cqp_wqe
->wqe_words
[NES_CQP_CQ_WQE_DOORBELL_INDEX_HIGH_IDX
] = 0;
1751 set_wqe_64bit_value(cqp_wqe
->wqe_words
, NES_CQP_CQ_WQE_PBL_LOW_IDX
, u64temp
);
1752 cqp_wqe
->wqe_words
[NES_CQP_CQ_WQE_CQ_CONTEXT_HIGH_IDX
] = 0;
1753 u64temp
= (u64
)(unsigned long)&nescq
->hw_cq
;
1754 cqp_wqe
->wqe_words
[NES_CQP_CQ_WQE_CQ_CONTEXT_LOW_IDX
] =
1755 cpu_to_le32((u32
)(u64temp
>> 1));
1756 cqp_wqe
->wqe_words
[NES_CQP_CQ_WQE_CQ_CONTEXT_HIGH_IDX
] =
1757 cpu_to_le32(((u32
)((u64temp
) >> 33)) & 0x7FFFFFFF);
1759 atomic_set(&cqp_request
->refcount
, 2);
1760 nes_post_cqp_request(nesdev
, cqp_request
);
1763 nes_debug(NES_DBG_CQ
, "Waiting for create iWARP CQ%u to complete.\n",
1764 nescq
->hw_cq
.cq_number
);
1765 ret
= wait_event_timeout(cqp_request
->waitq
, (0 != cqp_request
->request_done
),
1766 NES_EVENT_TIMEOUT
* 2);
1767 nes_debug(NES_DBG_CQ
, "Create iWARP CQ%u completed, wait_event_timeout ret = %d.\n",
1768 nescq
->hw_cq
.cq_number
, ret
);
1769 if ((!ret
) || (cqp_request
->major_code
)) {
1770 nes_put_cqp_request(nesdev
, cqp_request
);
1772 pci_free_consistent(nesdev
->pcidev
, nescq
->cq_mem_size
, mem
,
1773 nescq
->hw_cq
.cq_pbase
);
1774 nes_free_resource(nesadapter
, nesadapter
->allocated_cqs
, cq_num
);
1776 return ERR_PTR(-EIO
);
1778 nes_put_cqp_request(nesdev
, cqp_request
);
1781 /* free the nespbl */
1782 pci_free_consistent(nesdev
->pcidev
, nespbl
->pbl_size
, nespbl
->pbl_vbase
,
1785 resp
.cq_id
= nescq
->hw_cq
.cq_number
;
1786 resp
.cq_size
= nescq
->hw_cq
.cq_size
;
1787 resp
.mmap_db_index
= 0;
1788 if (ib_copy_to_udata(udata
, &resp
, sizeof resp
)) {
1789 nes_free_resource(nesadapter
, nesadapter
->allocated_cqs
, cq_num
);
1791 return ERR_PTR(-EFAULT
);
1795 return &nescq
->ibcq
;
1802 static int nes_destroy_cq(struct ib_cq
*ib_cq
)
1804 struct nes_cq
*nescq
;
1805 struct nes_device
*nesdev
;
1806 struct nes_vnic
*nesvnic
;
1807 struct nes_adapter
*nesadapter
;
1808 struct nes_hw_cqp_wqe
*cqp_wqe
;
1809 struct nes_cqp_request
*cqp_request
;
1810 unsigned long flags
;
1817 nescq
= to_nescq(ib_cq
);
1818 nesvnic
= to_nesvnic(ib_cq
->device
);
1819 nesdev
= nesvnic
->nesdev
;
1820 nesadapter
= nesdev
->nesadapter
;
1822 nes_debug(NES_DBG_CQ
, "Destroy CQ%u\n", nescq
->hw_cq
.cq_number
);
1824 /* Send DestroyCQ request to CQP */
1825 cqp_request
= nes_get_cqp_request(nesdev
);
1826 if (cqp_request
== NULL
) {
1827 nes_debug(NES_DBG_CQ
, "Failed to get a cqp_request.\n");
1830 cqp_request
->waiting
= 1;
1831 cqp_wqe
= &cqp_request
->cqp_wqe
;
1832 opcode
= NES_CQP_DESTROY_CQ
| (nescq
->hw_cq
.cq_size
<< 16);
1833 spin_lock_irqsave(&nesadapter
->pbl_lock
, flags
);
1834 if (nescq
->virtual_cq
== 1) {
1835 nesadapter
->free_256pbl
++;
1836 if (nesadapter
->free_256pbl
> nesadapter
->max_256pbl
) {
1837 printk(KERN_ERR PFX
"%s: free 256B PBLs(%u) has exceeded the max(%u)\n",
1838 __func__
, nesadapter
->free_256pbl
, nesadapter
->max_256pbl
);
1840 } else if (nescq
->virtual_cq
== 2) {
1841 nesadapter
->free_4kpbl
++;
1842 if (nesadapter
->free_4kpbl
> nesadapter
->max_4kpbl
) {
1843 printk(KERN_ERR PFX
"%s: free 4K PBLs(%u) has exceeded the max(%u)\n",
1844 __func__
, nesadapter
->free_4kpbl
, nesadapter
->max_4kpbl
);
1846 opcode
|= NES_CQP_CQ_4KB_CHUNK
;
1849 spin_unlock_irqrestore(&nesadapter
->pbl_lock
, flags
);
1851 nes_fill_init_cqp_wqe(cqp_wqe
, nesdev
);
1852 set_wqe_32bit_value(cqp_wqe
->wqe_words
, NES_CQP_WQE_OPCODE_IDX
, opcode
);
1853 set_wqe_32bit_value(cqp_wqe
->wqe_words
, NES_CQP_WQE_ID_IDX
,
1854 (nescq
->hw_cq
.cq_number
| ((u32
)PCI_FUNC(nesdev
->pcidev
->devfn
) << 16)));
1855 nes_free_resource(nesadapter
, nesadapter
->allocated_cqs
, nescq
->hw_cq
.cq_number
);
1856 atomic_set(&cqp_request
->refcount
, 2);
1857 nes_post_cqp_request(nesdev
, cqp_request
);
1860 nes_debug(NES_DBG_CQ
, "Waiting for destroy iWARP CQ%u to complete.\n",
1861 nescq
->hw_cq
.cq_number
);
1862 ret
= wait_event_timeout(cqp_request
->waitq
, (0 != cqp_request
->request_done
),
1864 nes_debug(NES_DBG_CQ
, "Destroy iWARP CQ%u completed, wait_event_timeout ret = %u,"
1865 " CQP Major:Minor codes = 0x%04X:0x%04X.\n",
1866 nescq
->hw_cq
.cq_number
, ret
, cqp_request
->major_code
,
1867 cqp_request
->minor_code
);
1869 nes_debug(NES_DBG_CQ
, "iWARP CQ%u destroy timeout expired\n",
1870 nescq
->hw_cq
.cq_number
);
1872 } else if (cqp_request
->major_code
) {
1873 nes_debug(NES_DBG_CQ
, "iWARP CQ%u destroy failed\n",
1874 nescq
->hw_cq
.cq_number
);
1879 nes_put_cqp_request(nesdev
, cqp_request
);
1881 if (nescq
->cq_mem_size
)
1882 pci_free_consistent(nesdev
->pcidev
, nescq
->cq_mem_size
,
1883 nescq
->hw_cq
.cq_vbase
, nescq
->hw_cq
.cq_pbase
);
1893 static int nes_reg_mr(struct nes_device
*nesdev
, struct nes_pd
*nespd
,
1894 u32 stag
, u64 region_length
, struct nes_root_vpbl
*root_vpbl
,
1895 dma_addr_t single_buffer
, u16 pbl_count
, u16 residual_page_count
,
1896 int acc
, u64
*iova_start
)
1898 struct nes_hw_cqp_wqe
*cqp_wqe
;
1899 struct nes_cqp_request
*cqp_request
;
1900 unsigned long flags
;
1902 struct nes_adapter
*nesadapter
= nesdev
->nesadapter
;
1907 /* Register the region with the adapter */
1908 cqp_request
= nes_get_cqp_request(nesdev
);
1909 if (cqp_request
== NULL
) {
1910 nes_debug(NES_DBG_MR
, "Failed to get a cqp_request.\n");
1913 cqp_request
->waiting
= 1;
1914 cqp_wqe
= &cqp_request
->cqp_wqe
;
1916 spin_lock_irqsave(&nesadapter
->pbl_lock
, flags
);
1917 /* track PBL resources */
1918 if (pbl_count
!= 0) {
1919 if (pbl_count
> 1) {
1921 if ((pbl_count
+1) > nesadapter
->free_4kpbl
) {
1922 nes_debug(NES_DBG_MR
, "Out of 4KB Pbls for two level request.\n");
1923 spin_unlock_irqrestore(&nesadapter
->pbl_lock
, flags
);
1924 nes_free_cqp_request(nesdev
, cqp_request
);
1927 nesadapter
->free_4kpbl
-= pbl_count
+1;
1929 } else if (residual_page_count
> 32) {
1930 if (pbl_count
> nesadapter
->free_4kpbl
) {
1931 nes_debug(NES_DBG_MR
, "Out of 4KB Pbls.\n");
1932 spin_unlock_irqrestore(&nesadapter
->pbl_lock
, flags
);
1933 nes_free_cqp_request(nesdev
, cqp_request
);
1936 nesadapter
->free_4kpbl
-= pbl_count
;
1939 if (pbl_count
> nesadapter
->free_256pbl
) {
1940 nes_debug(NES_DBG_MR
, "Out of 256B Pbls.\n");
1941 spin_unlock_irqrestore(&nesadapter
->pbl_lock
, flags
);
1942 nes_free_cqp_request(nesdev
, cqp_request
);
1945 nesadapter
->free_256pbl
-= pbl_count
;
1950 spin_unlock_irqrestore(&nesadapter
->pbl_lock
, flags
);
1952 opcode
= NES_CQP_REGISTER_STAG
| NES_CQP_STAG_RIGHTS_LOCAL_READ
|
1953 NES_CQP_STAG_VA_TO
| NES_CQP_STAG_MR
;
1954 if (acc
& IB_ACCESS_LOCAL_WRITE
)
1955 opcode
|= NES_CQP_STAG_RIGHTS_LOCAL_WRITE
;
1956 if (acc
& IB_ACCESS_REMOTE_WRITE
)
1957 opcode
|= NES_CQP_STAG_RIGHTS_REMOTE_WRITE
| NES_CQP_STAG_REM_ACC_EN
;
1958 if (acc
& IB_ACCESS_REMOTE_READ
)
1959 opcode
|= NES_CQP_STAG_RIGHTS_REMOTE_READ
| NES_CQP_STAG_REM_ACC_EN
;
1960 if (acc
& IB_ACCESS_MW_BIND
)
1961 opcode
|= NES_CQP_STAG_RIGHTS_WINDOW_BIND
| NES_CQP_STAG_REM_ACC_EN
;
1963 nes_fill_init_cqp_wqe(cqp_wqe
, nesdev
);
1964 set_wqe_32bit_value(cqp_wqe
->wqe_words
, NES_CQP_WQE_OPCODE_IDX
, opcode
);
1965 set_wqe_64bit_value(cqp_wqe
->wqe_words
, NES_CQP_STAG_WQE_VA_LOW_IDX
, *iova_start
);
1966 set_wqe_32bit_value(cqp_wqe
->wqe_words
, NES_CQP_STAG_WQE_LEN_LOW_IDX
, region_length
);
1968 cqp_wqe
->wqe_words
[NES_CQP_STAG_WQE_LEN_HIGH_PD_IDX
] =
1969 cpu_to_le32((u32
)(region_length
>> 8) & 0xff000000);
1970 cqp_wqe
->wqe_words
[NES_CQP_STAG_WQE_LEN_HIGH_PD_IDX
] |=
1971 cpu_to_le32(nespd
->pd_id
& 0x00007fff);
1972 set_wqe_32bit_value(cqp_wqe
->wqe_words
, NES_CQP_STAG_WQE_STAG_IDX
, stag
);
1974 if (pbl_count
== 0) {
1975 set_wqe_64bit_value(cqp_wqe
->wqe_words
, NES_CQP_STAG_WQE_PA_LOW_IDX
, single_buffer
);
1977 set_wqe_64bit_value(cqp_wqe
->wqe_words
, NES_CQP_STAG_WQE_PA_LOW_IDX
, root_vpbl
->pbl_pbase
);
1978 set_wqe_32bit_value(cqp_wqe
->wqe_words
, NES_CQP_STAG_WQE_PBL_BLK_COUNT_IDX
, pbl_count
);
1979 set_wqe_32bit_value(cqp_wqe
->wqe_words
, NES_CQP_STAG_WQE_PBL_LEN_IDX
,
1980 (((pbl_count
- 1) * 4096) + (residual_page_count
*8)));
1982 if ((pbl_count
> 1) || (residual_page_count
> 32))
1983 cqp_wqe
->wqe_words
[NES_CQP_WQE_OPCODE_IDX
] |= cpu_to_le32(NES_CQP_STAG_PBL_BLK_SIZE
);
1987 atomic_set(&cqp_request
->refcount
, 2);
1988 nes_post_cqp_request(nesdev
, cqp_request
);
1991 ret
= wait_event_timeout(cqp_request
->waitq
, (0 != cqp_request
->request_done
),
1993 nes_debug(NES_DBG_MR
, "Register STag 0x%08X completed, wait_event_timeout ret = %u,"
1994 " CQP Major:Minor codes = 0x%04X:0x%04X.\n",
1995 stag
, ret
, cqp_request
->major_code
, cqp_request
->minor_code
);
1996 major_code
= cqp_request
->major_code
;
1997 nes_put_cqp_request(nesdev
, cqp_request
);
2001 else if (major_code
)
2013 static struct ib_mr
*nes_reg_phys_mr(struct ib_pd
*ib_pd
,
2014 struct ib_phys_buf
*buffer_list
, int num_phys_buf
, int acc
,
2018 struct nes_pd
*nespd
= to_nespd(ib_pd
);
2019 struct nes_vnic
*nesvnic
= to_nesvnic(ib_pd
->device
);
2020 struct nes_device
*nesdev
= nesvnic
->nesdev
;
2021 struct nes_adapter
*nesadapter
= nesdev
->nesadapter
;
2022 struct nes_mr
*nesmr
;
2024 struct nes_vpbl vpbl
;
2025 struct nes_root_vpbl root_vpbl
;
2029 u32 next_stag_index
= 0;
2031 u32 root_pbl_index
= 0;
2032 u32 cur_pbl_index
= 0;
2033 int err
= 0, pbl_depth
= 0;
2041 vpbl
.pbl_vbase
= NULL
;
2042 root_vpbl
.pbl_vbase
= NULL
;
2043 root_vpbl
.pbl_pbase
= 0;
2045 get_random_bytes(&next_stag_index
, sizeof(next_stag_index
));
2046 stag_key
= (u8
)next_stag_index
;
2050 next_stag_index
>>= 8;
2051 next_stag_index
%= nesadapter
->max_mr
;
2052 if (num_phys_buf
> (1024*512)) {
2053 return ERR_PTR(-E2BIG
);
2056 err
= nes_alloc_resource(nesadapter
, nesadapter
->allocated_mrs
, nesadapter
->max_mr
,
2057 &stag_index
, &next_stag_index
);
2059 return ERR_PTR(err
);
2062 nesmr
= kzalloc(sizeof(*nesmr
), GFP_KERNEL
);
2064 nes_free_resource(nesadapter
, nesadapter
->allocated_mrs
, stag_index
);
2065 return ERR_PTR(-ENOMEM
);
2068 for (i
= 0; i
< num_phys_buf
; i
++) {
2070 if ((i
& 0x01FF) == 0) {
2071 if (root_pbl_index
== 1) {
2072 /* Allocate the root PBL */
2073 root_vpbl
.pbl_vbase
= pci_alloc_consistent(nesdev
->pcidev
, 8192,
2074 &root_vpbl
.pbl_pbase
);
2075 nes_debug(NES_DBG_MR
, "Allocating root PBL, va = %p, pa = 0x%08X\n",
2076 root_vpbl
.pbl_vbase
, (unsigned int)root_vpbl
.pbl_pbase
);
2077 if (!root_vpbl
.pbl_vbase
) {
2078 pci_free_consistent(nesdev
->pcidev
, 4096, vpbl
.pbl_vbase
,
2080 nes_free_resource(nesadapter
, nesadapter
->allocated_mrs
, stag_index
);
2082 return ERR_PTR(-ENOMEM
);
2084 root_vpbl
.leaf_vpbl
= kzalloc(sizeof(*root_vpbl
.leaf_vpbl
)*1024, GFP_KERNEL
);
2085 if (!root_vpbl
.leaf_vpbl
) {
2086 pci_free_consistent(nesdev
->pcidev
, 8192, root_vpbl
.pbl_vbase
,
2087 root_vpbl
.pbl_pbase
);
2088 pci_free_consistent(nesdev
->pcidev
, 4096, vpbl
.pbl_vbase
,
2090 nes_free_resource(nesadapter
, nesadapter
->allocated_mrs
, stag_index
);
2092 return ERR_PTR(-ENOMEM
);
2094 root_vpbl
.pbl_vbase
[0].pa_low
= cpu_to_le32((u32
)vpbl
.pbl_pbase
);
2095 root_vpbl
.pbl_vbase
[0].pa_high
=
2096 cpu_to_le32((u32
)((((u64
)vpbl
.pbl_pbase
) >> 32)));
2097 root_vpbl
.leaf_vpbl
[0] = vpbl
;
2099 /* Allocate a 4K buffer for the PBL */
2100 vpbl
.pbl_vbase
= pci_alloc_consistent(nesdev
->pcidev
, 4096,
2102 nes_debug(NES_DBG_MR
, "Allocating leaf PBL, va = %p, pa = 0x%016lX\n",
2103 vpbl
.pbl_vbase
, (unsigned long)vpbl
.pbl_pbase
);
2104 if (!vpbl
.pbl_vbase
) {
2105 nes_free_resource(nesadapter
, nesadapter
->allocated_mrs
, stag_index
);
2106 ibmr
= ERR_PTR(-ENOMEM
);
2110 /* Fill in the root table */
2111 if (1 <= root_pbl_index
) {
2112 root_vpbl
.pbl_vbase
[root_pbl_index
].pa_low
=
2113 cpu_to_le32((u32
)vpbl
.pbl_pbase
);
2114 root_vpbl
.pbl_vbase
[root_pbl_index
].pa_high
=
2115 cpu_to_le32((u32
)((((u64
)vpbl
.pbl_pbase
) >> 32)));
2116 root_vpbl
.leaf_vpbl
[root_pbl_index
] = vpbl
;
2121 if (buffer_list
[i
].addr
& ~PAGE_MASK
) {
2122 /* TODO: Unwind allocated buffers */
2123 nes_free_resource(nesadapter
, nesadapter
->allocated_mrs
, stag_index
);
2124 nes_debug(NES_DBG_MR
, "Unaligned Memory Buffer: 0x%x\n",
2125 (unsigned int) buffer_list
[i
].addr
);
2126 ibmr
= ERR_PTR(-EINVAL
);
2131 if (!buffer_list
[i
].size
) {
2132 nes_free_resource(nesadapter
, nesadapter
->allocated_mrs
, stag_index
);
2133 nes_debug(NES_DBG_MR
, "Invalid Buffer Size\n");
2134 ibmr
= ERR_PTR(-EINVAL
);
2139 region_length
+= buffer_list
[i
].size
;
2140 if ((i
!= 0) && (single_page
)) {
2141 if ((buffer_list
[i
-1].addr
+PAGE_SIZE
) != buffer_list
[i
].addr
)
2144 vpbl
.pbl_vbase
[cur_pbl_index
].pa_low
= cpu_to_le32((u32
)buffer_list
[i
].addr
);
2145 vpbl
.pbl_vbase
[cur_pbl_index
++].pa_high
=
2146 cpu_to_le32((u32
)((((u64
)buffer_list
[i
].addr
) >> 32)));
2149 stag
= stag_index
<< 8;
2151 stag
+= (u32
)stag_key
;
2153 nes_debug(NES_DBG_MR
, "Registering STag 0x%08X, VA = 0x%016lX,"
2154 " length = 0x%016lX, index = 0x%08X\n",
2155 stag
, (unsigned long)*iova_start
, (unsigned long)region_length
, stag_index
);
2157 region_length
-= (*iova_start
)&PAGE_MASK
;
2159 /* Make the leaf PBL the root if only one PBL */
2160 if (root_pbl_index
== 1) {
2161 root_vpbl
.pbl_pbase
= vpbl
.pbl_pbase
;
2167 pbl_count
= root_pbl_index
;
2169 ret
= nes_reg_mr(nesdev
, nespd
, stag
, region_length
, &root_vpbl
,
2170 buffer_list
[0].addr
, pbl_count
, (u16
)cur_pbl_index
, acc
, iova_start
);
2173 nesmr
->ibmr
.rkey
= stag
;
2174 nesmr
->ibmr
.lkey
= stag
;
2175 nesmr
->mode
= IWNES_MEMREG_TYPE_MEM
;
2176 ibmr
= &nesmr
->ibmr
;
2177 nesmr
->pbl_4k
= ((pbl_count
> 1) || (cur_pbl_index
> 32)) ? 1 : 0;
2178 nesmr
->pbls_used
= pbl_count
;
2179 if (pbl_count
> 1) {
2184 ibmr
= ERR_PTR(-ENOMEM
);
2188 /* free the resources */
2189 if (root_pbl_index
== 1) {
2190 /* single PBL case */
2191 pci_free_consistent(nesdev
->pcidev
, 4096, vpbl
.pbl_vbase
, vpbl
.pbl_pbase
);
2193 for (i
=0; i
<root_pbl_index
; i
++) {
2194 pci_free_consistent(nesdev
->pcidev
, 4096, root_vpbl
.leaf_vpbl
[i
].pbl_vbase
,
2195 root_vpbl
.leaf_vpbl
[i
].pbl_pbase
);
2197 kfree(root_vpbl
.leaf_vpbl
);
2198 pci_free_consistent(nesdev
->pcidev
, 8192, root_vpbl
.pbl_vbase
,
2199 root_vpbl
.pbl_pbase
);
2209 static struct ib_mr
*nes_get_dma_mr(struct ib_pd
*pd
, int acc
)
2211 struct ib_phys_buf bl
;
2214 nes_debug(NES_DBG_MR
, "\n");
2216 bl
.size
= (u64
)0xffffffffffULL
;
2218 return nes_reg_phys_mr(pd
, &bl
, 1, acc
, &kva
);
2225 static struct ib_mr
*nes_reg_user_mr(struct ib_pd
*pd
, u64 start
, u64 length
,
2226 u64 virt
, int acc
, struct ib_udata
*udata
)
2231 dma_addr_t last_dma_addr
= 0;
2232 dma_addr_t first_dma_addr
= 0;
2233 struct nes_pd
*nespd
= to_nespd(pd
);
2234 struct nes_vnic
*nesvnic
= to_nesvnic(pd
->device
);
2235 struct nes_device
*nesdev
= nesvnic
->nesdev
;
2236 struct nes_adapter
*nesadapter
= nesdev
->nesadapter
;
2237 struct ib_mr
*ibmr
= ERR_PTR(-EINVAL
);
2238 struct ib_umem_chunk
*chunk
;
2239 struct nes_ucontext
*nes_ucontext
;
2240 struct nes_pbl
*nespbl
;
2241 struct nes_mr
*nesmr
;
2242 struct ib_umem
*region
;
2243 struct nes_mem_reg_req req
;
2244 struct nes_vpbl vpbl
;
2245 struct nes_root_vpbl root_vpbl
;
2246 int nmap_index
, page_index
;
2248 int err
, pbl_depth
= 0;
2253 u32 next_stag_index
;
2255 u32 root_pbl_index
= 0;
2256 u32 cur_pbl_index
= 0;
2262 region
= ib_umem_get(pd
->uobject
->context
, start
, length
, acc
, 0);
2263 if (IS_ERR(region
)) {
2264 return (struct ib_mr
*)region
;
2267 nes_debug(NES_DBG_MR
, "User base = 0x%lX, Virt base = 0x%lX, length = %u,"
2268 " offset = %u, page size = %u.\n",
2269 (unsigned long int)start
, (unsigned long int)virt
, (u32
)length
,
2270 region
->offset
, region
->page_size
);
2272 skip_pages
= ((u32
)region
->offset
) >> 12;
2274 if (ib_copy_from_udata(&req
, udata
, sizeof(req
)))
2275 return ERR_PTR(-EFAULT
);
2276 nes_debug(NES_DBG_MR
, "Memory Registration type = %08X.\n", req
.reg_type
);
2278 switch (req
.reg_type
) {
2279 case IWNES_MEMREG_TYPE_MEM
:
2282 vpbl
.pbl_vbase
= NULL
;
2283 root_vpbl
.pbl_vbase
= NULL
;
2284 root_vpbl
.pbl_pbase
= 0;
2286 get_random_bytes(&next_stag_index
, sizeof(next_stag_index
));
2287 stag_key
= (u8
)next_stag_index
;
2289 driver_key
= next_stag_index
& 0x70000000;
2291 next_stag_index
>>= 8;
2292 next_stag_index
%= nesadapter
->max_mr
;
2294 err
= nes_alloc_resource(nesadapter
, nesadapter
->allocated_mrs
,
2295 nesadapter
->max_mr
, &stag_index
, &next_stag_index
);
2297 ib_umem_release(region
);
2298 return ERR_PTR(err
);
2301 nesmr
= kzalloc(sizeof(*nesmr
), GFP_KERNEL
);
2303 ib_umem_release(region
);
2304 nes_free_resource(nesadapter
, nesadapter
->allocated_mrs
, stag_index
);
2305 return ERR_PTR(-ENOMEM
);
2307 nesmr
->region
= region
;
2309 list_for_each_entry(chunk
, ®ion
->chunk_list
, list
) {
2310 nes_debug(NES_DBG_MR
, "Chunk: nents = %u, nmap = %u .\n",
2311 chunk
->nents
, chunk
->nmap
);
2312 for (nmap_index
= 0; nmap_index
< chunk
->nmap
; ++nmap_index
) {
2313 if (sg_dma_address(&chunk
->page_list
[nmap_index
]) & ~PAGE_MASK
) {
2314 ib_umem_release(region
);
2315 nes_free_resource(nesadapter
, nesadapter
->allocated_mrs
, stag_index
);
2316 nes_debug(NES_DBG_MR
, "Unaligned Memory Buffer: 0x%x\n",
2317 (unsigned int) sg_dma_address(&chunk
->page_list
[nmap_index
]));
2318 ibmr
= ERR_PTR(-EINVAL
);
2320 goto reg_user_mr_err
;
2323 if (!sg_dma_len(&chunk
->page_list
[nmap_index
])) {
2324 ib_umem_release(region
);
2325 nes_free_resource(nesadapter
, nesadapter
->allocated_mrs
,
2327 nes_debug(NES_DBG_MR
, "Invalid Buffer Size\n");
2328 ibmr
= ERR_PTR(-EINVAL
);
2330 goto reg_user_mr_err
;
2333 region_length
+= sg_dma_len(&chunk
->page_list
[nmap_index
]);
2334 chunk_pages
= sg_dma_len(&chunk
->page_list
[nmap_index
]) >> 12;
2335 region_length
-= skip_pages
<< 12;
2336 for (page_index
=skip_pages
; page_index
< chunk_pages
; page_index
++) {
2338 if ((page_count
!=0)&&(page_count
<<12)-(region
->offset
&(4096-1))>=region
->length
)
2340 if ((page_count
&0x01FF) == 0) {
2341 if (page_count
>= 1024 * 512) {
2342 ib_umem_release(region
);
2343 nes_free_resource(nesadapter
,
2344 nesadapter
->allocated_mrs
, stag_index
);
2346 ibmr
= ERR_PTR(-E2BIG
);
2347 goto reg_user_mr_err
;
2349 if (root_pbl_index
== 1) {
2350 root_vpbl
.pbl_vbase
= pci_alloc_consistent(nesdev
->pcidev
,
2351 8192, &root_vpbl
.pbl_pbase
);
2352 nes_debug(NES_DBG_MR
, "Allocating root PBL, va = %p, pa = 0x%08X\n",
2353 root_vpbl
.pbl_vbase
, (unsigned int)root_vpbl
.pbl_pbase
);
2354 if (!root_vpbl
.pbl_vbase
) {
2355 ib_umem_release(region
);
2356 pci_free_consistent(nesdev
->pcidev
, 4096, vpbl
.pbl_vbase
,
2358 nes_free_resource(nesadapter
, nesadapter
->allocated_mrs
,
2361 ibmr
= ERR_PTR(-ENOMEM
);
2362 goto reg_user_mr_err
;
2364 root_vpbl
.leaf_vpbl
= kzalloc(sizeof(*root_vpbl
.leaf_vpbl
)*1024,
2366 if (!root_vpbl
.leaf_vpbl
) {
2367 ib_umem_release(region
);
2368 pci_free_consistent(nesdev
->pcidev
, 8192, root_vpbl
.pbl_vbase
,
2369 root_vpbl
.pbl_pbase
);
2370 pci_free_consistent(nesdev
->pcidev
, 4096, vpbl
.pbl_vbase
,
2372 nes_free_resource(nesadapter
, nesadapter
->allocated_mrs
,
2375 ibmr
= ERR_PTR(-ENOMEM
);
2376 goto reg_user_mr_err
;
2378 root_vpbl
.pbl_vbase
[0].pa_low
=
2379 cpu_to_le32((u32
)vpbl
.pbl_pbase
);
2380 root_vpbl
.pbl_vbase
[0].pa_high
=
2381 cpu_to_le32((u32
)((((u64
)vpbl
.pbl_pbase
) >> 32)));
2382 root_vpbl
.leaf_vpbl
[0] = vpbl
;
2384 vpbl
.pbl_vbase
= pci_alloc_consistent(nesdev
->pcidev
, 4096,
2386 nes_debug(NES_DBG_MR
, "Allocating leaf PBL, va = %p, pa = 0x%08X\n",
2387 vpbl
.pbl_vbase
, (unsigned int)vpbl
.pbl_pbase
);
2388 if (!vpbl
.pbl_vbase
) {
2389 ib_umem_release(region
);
2390 nes_free_resource(nesadapter
, nesadapter
->allocated_mrs
, stag_index
);
2391 ibmr
= ERR_PTR(-ENOMEM
);
2393 goto reg_user_mr_err
;
2395 if (1 <= root_pbl_index
) {
2396 root_vpbl
.pbl_vbase
[root_pbl_index
].pa_low
=
2397 cpu_to_le32((u32
)vpbl
.pbl_pbase
);
2398 root_vpbl
.pbl_vbase
[root_pbl_index
].pa_high
=
2399 cpu_to_le32((u32
)((((u64
)vpbl
.pbl_pbase
)>>32)));
2400 root_vpbl
.leaf_vpbl
[root_pbl_index
] = vpbl
;
2406 if (page_count
!= 0) {
2407 if ((last_dma_addr
+4096) !=
2408 (sg_dma_address(&chunk
->page_list
[nmap_index
])+
2411 last_dma_addr
= sg_dma_address(&chunk
->page_list
[nmap_index
])+
2414 first_dma_addr
= sg_dma_address(&chunk
->page_list
[nmap_index
])+
2416 last_dma_addr
= first_dma_addr
;
2420 vpbl
.pbl_vbase
[cur_pbl_index
].pa_low
=
2421 cpu_to_le32((u32
)(sg_dma_address(&chunk
->page_list
[nmap_index
])+
2422 (page_index
*4096)));
2423 vpbl
.pbl_vbase
[cur_pbl_index
].pa_high
=
2424 cpu_to_le32((u32
)((((u64
)(sg_dma_address(&chunk
->page_list
[nmap_index
])+
2425 (page_index
*4096))) >> 32)));
2432 nes_debug(NES_DBG_MR
, "calculating stag, stag_index=0x%08x, driver_key=0x%08x,"
2433 " stag_key=0x%08x\n",
2434 stag_index
, driver_key
, stag_key
);
2435 stag
= stag_index
<< 8;
2437 stag
+= (u32
)stag_key
;
2443 /* Make the leaf PBL the root if only one PBL */
2444 if (root_pbl_index
== 1) {
2445 root_vpbl
.pbl_pbase
= vpbl
.pbl_pbase
;
2451 pbl_count
= root_pbl_index
;
2454 nes_debug(NES_DBG_MR
, "Registering STag 0x%08X, VA = 0x%08X, length = 0x%08X,"
2455 " index = 0x%08X, region->length=0x%08llx, pbl_count = %u\n",
2456 stag
, (unsigned int)iova_start
,
2457 (unsigned int)region_length
, stag_index
,
2458 (unsigned long long)region
->length
, pbl_count
);
2459 ret
= nes_reg_mr( nesdev
, nespd
, stag
, region
->length
, &root_vpbl
,
2460 first_dma_addr
, pbl_count
, (u16
)cur_pbl_index
, acc
, &iova_start
);
2462 nes_debug(NES_DBG_MR
, "ret=%d\n", ret
);
2465 nesmr
->ibmr
.rkey
= stag
;
2466 nesmr
->ibmr
.lkey
= stag
;
2467 nesmr
->mode
= IWNES_MEMREG_TYPE_MEM
;
2468 ibmr
= &nesmr
->ibmr
;
2469 nesmr
->pbl_4k
= ((pbl_count
> 1) || (cur_pbl_index
> 32)) ? 1 : 0;
2470 nesmr
->pbls_used
= pbl_count
;
2471 if (pbl_count
> 1) {
2475 ib_umem_release(region
);
2477 ibmr
= ERR_PTR(-ENOMEM
);
2481 /* free the resources */
2482 if (root_pbl_index
== 1) {
2483 pci_free_consistent(nesdev
->pcidev
, 4096, vpbl
.pbl_vbase
,
2486 for (page_index
=0; page_index
<root_pbl_index
; page_index
++) {
2487 pci_free_consistent(nesdev
->pcidev
, 4096,
2488 root_vpbl
.leaf_vpbl
[page_index
].pbl_vbase
,
2489 root_vpbl
.leaf_vpbl
[page_index
].pbl_pbase
);
2491 kfree(root_vpbl
.leaf_vpbl
);
2492 pci_free_consistent(nesdev
->pcidev
, 8192, root_vpbl
.pbl_vbase
,
2493 root_vpbl
.pbl_pbase
);
2496 nes_debug(NES_DBG_MR
, "Leaving, ibmr=%p", ibmr
);
2499 case IWNES_MEMREG_TYPE_QP
:
2500 case IWNES_MEMREG_TYPE_CQ
:
2501 nespbl
= kzalloc(sizeof(*nespbl
), GFP_KERNEL
);
2503 nes_debug(NES_DBG_MR
, "Unable to allocate PBL\n");
2504 ib_umem_release(region
);
2505 return ERR_PTR(-ENOMEM
);
2507 nesmr
= kzalloc(sizeof(*nesmr
), GFP_KERNEL
);
2509 ib_umem_release(region
);
2511 nes_debug(NES_DBG_MR
, "Unable to allocate nesmr\n");
2512 return ERR_PTR(-ENOMEM
);
2514 nesmr
->region
= region
;
2515 nes_ucontext
= to_nesucontext(pd
->uobject
->context
);
2516 pbl_depth
= region
->length
>> 12;
2517 pbl_depth
+= (region
->length
& (4096-1)) ? 1 : 0;
2518 nespbl
->pbl_size
= pbl_depth
*sizeof(u64
);
2519 if (req
.reg_type
== IWNES_MEMREG_TYPE_QP
) {
2520 nes_debug(NES_DBG_MR
, "Attempting to allocate QP PBL memory");
2522 nes_debug(NES_DBG_MR
, "Attempting to allocate CP PBL memory");
2525 nes_debug(NES_DBG_MR
, " %u bytes, %u entries.\n",
2526 nespbl
->pbl_size
, pbl_depth
);
2527 pbl
= pci_alloc_consistent(nesdev
->pcidev
, nespbl
->pbl_size
,
2528 &nespbl
->pbl_pbase
);
2530 ib_umem_release(region
);
2533 nes_debug(NES_DBG_MR
, "Unable to allocate PBL memory\n");
2534 return ERR_PTR(-ENOMEM
);
2537 nespbl
->pbl_vbase
= (u64
*)pbl
;
2538 nespbl
->user_base
= start
;
2539 nes_debug(NES_DBG_MR
, "Allocated PBL memory, %u bytes, pbl_pbase=%lx,"
2540 " pbl_vbase=%p user_base=0x%lx\n",
2541 nespbl
->pbl_size
, (unsigned long) nespbl
->pbl_pbase
,
2542 (void *) nespbl
->pbl_vbase
, nespbl
->user_base
);
2544 list_for_each_entry(chunk
, ®ion
->chunk_list
, list
) {
2545 for (nmap_index
= 0; nmap_index
< chunk
->nmap
; ++nmap_index
) {
2546 chunk_pages
= sg_dma_len(&chunk
->page_list
[nmap_index
]) >> 12;
2547 chunk_pages
+= (sg_dma_len(&chunk
->page_list
[nmap_index
]) & (4096-1)) ? 1 : 0;
2548 nespbl
->page
= sg_page(&chunk
->page_list
[0]);
2549 for (page_index
=0; page_index
<chunk_pages
; page_index
++) {
2550 ((__le32
*)pbl
)[0] = cpu_to_le32((u32
)
2551 (sg_dma_address(&chunk
->page_list
[nmap_index
])+
2552 (page_index
*4096)));
2553 ((__le32
*)pbl
)[1] = cpu_to_le32(((u64
)
2554 (sg_dma_address(&chunk
->page_list
[nmap_index
])+
2555 (page_index
*4096)))>>32);
2556 nes_debug(NES_DBG_MR
, "pbl=%p, *pbl=0x%016llx, 0x%08x%08x\n", pbl
,
2557 (unsigned long long)*pbl
,
2558 le32_to_cpu(((__le32
*)pbl
)[1]), le32_to_cpu(((__le32
*)pbl
)[0]));
2563 if (req
.reg_type
== IWNES_MEMREG_TYPE_QP
) {
2564 list_add_tail(&nespbl
->list
, &nes_ucontext
->qp_reg_mem_list
);
2566 list_add_tail(&nespbl
->list
, &nes_ucontext
->cq_reg_mem_list
);
2568 nesmr
->ibmr
.rkey
= -1;
2569 nesmr
->ibmr
.lkey
= -1;
2570 nesmr
->mode
= req
.reg_type
;
2571 return &nesmr
->ibmr
;
2574 return ERR_PTR(-ENOSYS
);
2581 static int nes_dereg_mr(struct ib_mr
*ib_mr
)
2583 struct nes_mr
*nesmr
= to_nesmr(ib_mr
);
2584 struct nes_vnic
*nesvnic
= to_nesvnic(ib_mr
->device
);
2585 struct nes_device
*nesdev
= nesvnic
->nesdev
;
2586 struct nes_adapter
*nesadapter
= nesdev
->nesadapter
;
2587 struct nes_hw_cqp_wqe
*cqp_wqe
;
2588 struct nes_cqp_request
*cqp_request
;
2589 unsigned long flags
;
2594 if (nesmr
->region
) {
2595 ib_umem_release(nesmr
->region
);
2597 if (nesmr
->mode
!= IWNES_MEMREG_TYPE_MEM
) {
2602 /* Deallocate the region with the adapter */
2604 cqp_request
= nes_get_cqp_request(nesdev
);
2605 if (cqp_request
== NULL
) {
2606 nes_debug(NES_DBG_MR
, "Failed to get a cqp_request.\n");
2609 cqp_request
->waiting
= 1;
2610 cqp_wqe
= &cqp_request
->cqp_wqe
;
2612 spin_lock_irqsave(&nesadapter
->pbl_lock
, flags
);
2613 if (nesmr
->pbls_used
!= 0) {
2614 if (nesmr
->pbl_4k
) {
2615 nesadapter
->free_4kpbl
+= nesmr
->pbls_used
;
2616 if (nesadapter
->free_4kpbl
> nesadapter
->max_4kpbl
) {
2617 printk(KERN_ERR PFX
"free 4KB PBLs(%u) has exceeded the max(%u)\n",
2618 nesadapter
->free_4kpbl
, nesadapter
->max_4kpbl
);
2621 nesadapter
->free_256pbl
+= nesmr
->pbls_used
;
2622 if (nesadapter
->free_256pbl
> nesadapter
->max_256pbl
) {
2623 printk(KERN_ERR PFX
"free 256B PBLs(%u) has exceeded the max(%u)\n",
2624 nesadapter
->free_256pbl
, nesadapter
->max_256pbl
);
2629 spin_unlock_irqrestore(&nesadapter
->pbl_lock
, flags
);
2630 nes_fill_init_cqp_wqe(cqp_wqe
, nesdev
);
2631 set_wqe_32bit_value(cqp_wqe
->wqe_words
, NES_CQP_WQE_OPCODE_IDX
,
2632 NES_CQP_DEALLOCATE_STAG
| NES_CQP_STAG_VA_TO
|
2633 NES_CQP_STAG_DEALLOC_PBLS
| NES_CQP_STAG_MR
);
2634 set_wqe_32bit_value(cqp_wqe
->wqe_words
, NES_CQP_STAG_WQE_STAG_IDX
, ib_mr
->rkey
);
2636 atomic_set(&cqp_request
->refcount
, 2);
2637 nes_post_cqp_request(nesdev
, cqp_request
);
2640 nes_debug(NES_DBG_MR
, "Waiting for deallocate STag 0x%08X completed\n", ib_mr
->rkey
);
2641 ret
= wait_event_timeout(cqp_request
->waitq
, (cqp_request
->request_done
!= 0),
2643 nes_debug(NES_DBG_MR
, "Deallocate STag 0x%08X completed, wait_event_timeout ret = %u,"
2644 " CQP Major:Minor codes = 0x%04X:0x%04X\n",
2645 ib_mr
->rkey
, ret
, cqp_request
->major_code
, cqp_request
->minor_code
);
2647 nes_free_resource(nesadapter
, nesadapter
->allocated_mrs
,
2648 (ib_mr
->rkey
& 0x0fffff00) >> 8);
2652 major_code
= cqp_request
->major_code
;
2653 minor_code
= cqp_request
->minor_code
;
2655 nes_put_cqp_request(nesdev
, cqp_request
);
2658 nes_debug(NES_DBG_MR
, "Timeout waiting to destroy STag,"
2659 " ib_mr=%p, rkey = 0x%08X\n",
2660 ib_mr
, ib_mr
->rkey
);
2662 } else if (major_code
) {
2663 nes_debug(NES_DBG_MR
, "Error (0x%04X:0x%04X) while attempting"
2664 " to destroy STag, ib_mr=%p, rkey = 0x%08X\n",
2665 major_code
, minor_code
, ib_mr
, ib_mr
->rkey
);
2675 static ssize_t
show_rev(struct device
*dev
, struct device_attribute
*attr
,
2678 struct nes_ib_device
*nesibdev
=
2679 container_of(dev
, struct nes_ib_device
, ibdev
.dev
);
2680 struct nes_vnic
*nesvnic
= nesibdev
->nesvnic
;
2682 nes_debug(NES_DBG_INIT
, "\n");
2683 return sprintf(buf
, "%x\n", nesvnic
->nesdev
->nesadapter
->hw_rev
);
2690 static ssize_t
show_fw_ver(struct device
*dev
, struct device_attribute
*attr
,
2693 struct nes_ib_device
*nesibdev
=
2694 container_of(dev
, struct nes_ib_device
, ibdev
.dev
);
2695 struct nes_vnic
*nesvnic
= nesibdev
->nesvnic
;
2697 nes_debug(NES_DBG_INIT
, "\n");
2698 return sprintf(buf
, "%x.%x.%x\n",
2699 (int)(nesvnic
->nesdev
->nesadapter
->fw_ver
>> 32),
2700 (int)(nesvnic
->nesdev
->nesadapter
->fw_ver
>> 16) & 0xffff,
2701 (int)(nesvnic
->nesdev
->nesadapter
->fw_ver
& 0xffff));
2708 static ssize_t
show_hca(struct device
*dev
, struct device_attribute
*attr
,
2711 nes_debug(NES_DBG_INIT
, "\n");
2712 return sprintf(buf
, "NES020\n");
2719 static ssize_t
show_board(struct device
*dev
, struct device_attribute
*attr
,
2722 nes_debug(NES_DBG_INIT
, "\n");
2723 return sprintf(buf
, "%.*s\n", 32, "NES020 Board ID");
2727 static DEVICE_ATTR(hw_rev
, S_IRUGO
, show_rev
, NULL
);
2728 static DEVICE_ATTR(fw_ver
, S_IRUGO
, show_fw_ver
, NULL
);
2729 static DEVICE_ATTR(hca_type
, S_IRUGO
, show_hca
, NULL
);
2730 static DEVICE_ATTR(board_id
, S_IRUGO
, show_board
, NULL
);
2732 static struct device_attribute
*nes_dev_attributes
[] = {
2743 static int nes_query_qp(struct ib_qp
*ibqp
, struct ib_qp_attr
*attr
,
2744 int attr_mask
, struct ib_qp_init_attr
*init_attr
)
2746 struct nes_qp
*nesqp
= to_nesqp(ibqp
);
2748 nes_debug(NES_DBG_QP
, "\n");
2750 attr
->qp_access_flags
= 0;
2751 attr
->cap
.max_send_wr
= nesqp
->hwqp
.sq_size
;
2752 attr
->cap
.max_recv_wr
= nesqp
->hwqp
.rq_size
;
2753 attr
->cap
.max_recv_sge
= 1;
2754 if (nes_drv_opt
& NES_DRV_OPT_NO_INLINE_DATA
) {
2755 init_attr
->cap
.max_inline_data
= 0;
2757 init_attr
->cap
.max_inline_data
= 64;
2760 init_attr
->event_handler
= nesqp
->ibqp
.event_handler
;
2761 init_attr
->qp_context
= nesqp
->ibqp
.qp_context
;
2762 init_attr
->send_cq
= nesqp
->ibqp
.send_cq
;
2763 init_attr
->recv_cq
= nesqp
->ibqp
.recv_cq
;
2764 init_attr
->srq
= nesqp
->ibqp
.srq
= nesqp
->ibqp
.srq
;
2765 init_attr
->cap
= attr
->cap
;
2774 int nes_hw_modify_qp(struct nes_device
*nesdev
, struct nes_qp
*nesqp
,
2775 u32 next_iwarp_state
, u32 wait_completion
)
2777 struct nes_hw_cqp_wqe
*cqp_wqe
;
2778 /* struct iw_cm_id *cm_id = nesqp->cm_id; */
2779 /* struct iw_cm_event cm_event; */
2780 struct nes_cqp_request
*cqp_request
;
2784 nes_debug(NES_DBG_MOD_QP
, "QP%u, refcount=%d\n",
2785 nesqp
->hwqp
.qp_id
, atomic_read(&nesqp
->refcount
));
2787 cqp_request
= nes_get_cqp_request(nesdev
);
2788 if (cqp_request
== NULL
) {
2789 nes_debug(NES_DBG_MOD_QP
, "Failed to get a cqp_request.\n");
2792 if (wait_completion
) {
2793 cqp_request
->waiting
= 1;
2795 cqp_request
->waiting
= 0;
2797 cqp_wqe
= &cqp_request
->cqp_wqe
;
2799 set_wqe_32bit_value(cqp_wqe
->wqe_words
, NES_CQP_WQE_OPCODE_IDX
,
2800 NES_CQP_MODIFY_QP
| NES_CQP_QP_TYPE_IWARP
| next_iwarp_state
);
2801 nes_debug(NES_DBG_MOD_QP
, "using next_iwarp_state=%08x, wqe_words=%08x\n",
2802 next_iwarp_state
, le32_to_cpu(cqp_wqe
->wqe_words
[NES_CQP_WQE_OPCODE_IDX
]));
2803 nes_fill_init_cqp_wqe(cqp_wqe
, nesdev
);
2804 set_wqe_32bit_value(cqp_wqe
->wqe_words
, NES_CQP_WQE_ID_IDX
, nesqp
->hwqp
.qp_id
);
2805 set_wqe_64bit_value(cqp_wqe
->wqe_words
, NES_CQP_QP_WQE_CONTEXT_LOW_IDX
, (u64
)nesqp
->nesqp_context_pbase
);
2807 atomic_set(&cqp_request
->refcount
, 2);
2808 nes_post_cqp_request(nesdev
, cqp_request
);
2811 if (wait_completion
) {
2812 /* nes_debug(NES_DBG_MOD_QP, "Waiting for modify iWARP QP%u to complete.\n",
2813 nesqp->hwqp.qp_id); */
2814 ret
= wait_event_timeout(cqp_request
->waitq
, (cqp_request
->request_done
!= 0),
2816 nes_debug(NES_DBG_MOD_QP
, "Modify iwarp QP%u completed, wait_event_timeout ret=%u, "
2817 "CQP Major:Minor codes = 0x%04X:0x%04X.\n",
2818 nesqp
->hwqp
.qp_id
, ret
, cqp_request
->major_code
, cqp_request
->minor_code
);
2819 major_code
= cqp_request
->major_code
;
2821 nes_debug(NES_DBG_MOD_QP
, "Modify iwarp QP%u failed"
2822 "CQP Major:Minor codes = 0x%04X:0x%04X, intended next state = 0x%08X.\n",
2823 nesqp
->hwqp
.qp_id
, cqp_request
->major_code
,
2824 cqp_request
->minor_code
, next_iwarp_state
);
2827 nes_put_cqp_request(nesdev
, cqp_request
);
2831 else if (major_code
)
2844 int nes_modify_qp(struct ib_qp
*ibqp
, struct ib_qp_attr
*attr
,
2845 int attr_mask
, struct ib_udata
*udata
)
2847 struct nes_qp
*nesqp
= to_nesqp(ibqp
);
2848 struct nes_vnic
*nesvnic
= to_nesvnic(ibqp
->device
);
2849 struct nes_device
*nesdev
= nesvnic
->nesdev
;
2852 u32 next_iwarp_state
= 0;
2854 unsigned long qplockflags
;
2856 u16 original_last_aeq
;
2857 u8 issue_modify_qp
= 0;
2858 u8 issue_disconnect
= 0;
2861 nes_debug(NES_DBG_MOD_QP
, "QP%u: QP State=%u, cur QP State=%u,"
2862 " iwarp_state=0x%X, refcount=%d\n",
2863 nesqp
->hwqp
.qp_id
, attr
->qp_state
, nesqp
->ibqp_state
,
2864 nesqp
->iwarp_state
, atomic_read(&nesqp
->refcount
));
2866 spin_lock_irqsave(&nesqp
->lock
, qplockflags
);
2868 nes_debug(NES_DBG_MOD_QP
, "QP%u: hw_iwarp_state=0x%X, hw_tcp_state=0x%X,"
2869 " QP Access Flags=0x%X, attr_mask = 0x%0x\n",
2870 nesqp
->hwqp
.qp_id
, nesqp
->hw_iwarp_state
,
2871 nesqp
->hw_tcp_state
, attr
->qp_access_flags
, attr_mask
);
2873 if (attr_mask
& IB_QP_STATE
) {
2874 switch (attr
->qp_state
) {
2876 nes_debug(NES_DBG_MOD_QP
, "QP%u: new state = init\n",
2878 if (nesqp
->iwarp_state
> (u32
)NES_CQP_QP_IWARP_STATE_IDLE
) {
2879 spin_unlock_irqrestore(&nesqp
->lock
, qplockflags
);
2882 next_iwarp_state
= NES_CQP_QP_IWARP_STATE_IDLE
;
2883 issue_modify_qp
= 1;
2886 nes_debug(NES_DBG_MOD_QP
, "QP%u: new state = rtr\n",
2888 if (nesqp
->iwarp_state
>(u32
)NES_CQP_QP_IWARP_STATE_IDLE
) {
2889 spin_unlock_irqrestore(&nesqp
->lock
, qplockflags
);
2892 next_iwarp_state
= NES_CQP_QP_IWARP_STATE_IDLE
;
2893 issue_modify_qp
= 1;
2896 nes_debug(NES_DBG_MOD_QP
, "QP%u: new state = rts\n",
2898 if (nesqp
->iwarp_state
>(u32
)NES_CQP_QP_IWARP_STATE_RTS
) {
2899 spin_unlock_irqrestore(&nesqp
->lock
, qplockflags
);
2902 if (nesqp
->cm_id
== NULL
) {
2903 nes_debug(NES_DBG_MOD_QP
, "QP%u: Failing attempt to move QP to RTS without a CM_ID. \n",
2904 nesqp
->hwqp
.qp_id
);
2905 spin_unlock_irqrestore(&nesqp
->lock
, qplockflags
);
2908 next_iwarp_state
= NES_CQP_QP_IWARP_STATE_RTS
;
2909 if (nesqp
->iwarp_state
!= NES_CQP_QP_IWARP_STATE_RTS
)
2910 next_iwarp_state
|= NES_CQP_QP_CONTEXT_VALID
|
2911 NES_CQP_QP_ARP_VALID
| NES_CQP_QP_ORD_VALID
;
2912 issue_modify_qp
= 1;
2913 nesqp
->hw_tcp_state
= NES_AEQE_TCP_STATE_ESTABLISHED
;
2914 nesqp
->hw_iwarp_state
= NES_AEQE_IWARP_STATE_RTS
;
2915 nesqp
->hte_added
= 1;
2918 issue_modify_qp
= 1;
2919 nes_debug(NES_DBG_MOD_QP
, "QP%u: new state=closing. SQ head=%u, SQ tail=%u\n",
2920 nesqp
->hwqp
.qp_id
, nesqp
->hwqp
.sq_head
, nesqp
->hwqp
.sq_tail
);
2921 if (nesqp
->iwarp_state
== (u32
)NES_CQP_QP_IWARP_STATE_CLOSING
) {
2922 spin_unlock_irqrestore(&nesqp
->lock
, qplockflags
);
2925 if (nesqp
->iwarp_state
> (u32
)NES_CQP_QP_IWARP_STATE_CLOSING
) {
2926 nes_debug(NES_DBG_MOD_QP
, "QP%u: State change to closing"
2927 " ignored due to current iWARP state\n",
2929 spin_unlock_irqrestore(&nesqp
->lock
, qplockflags
);
2932 if (nesqp
->hw_iwarp_state
!= NES_AEQE_IWARP_STATE_RTS
) {
2933 nes_debug(NES_DBG_MOD_QP
, "QP%u: State change to closing"
2934 " already done based on hw state.\n",
2936 issue_modify_qp
= 0;
2937 nesqp
->in_disconnect
= 0;
2939 switch (nesqp
->hw_iwarp_state
) {
2940 case NES_AEQE_IWARP_STATE_CLOSING
:
2941 next_iwarp_state
= NES_CQP_QP_IWARP_STATE_CLOSING
;
2942 case NES_AEQE_IWARP_STATE_TERMINATE
:
2943 next_iwarp_state
= NES_CQP_QP_IWARP_STATE_TERMINATE
;
2945 case NES_AEQE_IWARP_STATE_ERROR
:
2946 next_iwarp_state
= NES_CQP_QP_IWARP_STATE_ERROR
;
2949 next_iwarp_state
= NES_CQP_QP_IWARP_STATE_CLOSING
;
2950 nesqp
->in_disconnect
= 1;
2951 nesqp
->hw_iwarp_state
= NES_AEQE_IWARP_STATE_CLOSING
;
2957 nes_debug(NES_DBG_MOD_QP
, "QP%u: new state = terminate\n",
2959 if (nesqp
->iwarp_state
>=(u32
)NES_CQP_QP_IWARP_STATE_TERMINATE
) {
2960 spin_unlock_irqrestore(&nesqp
->lock
, qplockflags
);
2963 /* next_iwarp_state = (NES_CQP_QP_IWARP_STATE_TERMINATE | 0x02000000); */
2964 next_iwarp_state
= NES_CQP_QP_IWARP_STATE_TERMINATE
;
2965 nesqp
->hw_iwarp_state
= NES_AEQE_IWARP_STATE_TERMINATE
;
2966 issue_modify_qp
= 1;
2967 nesqp
->in_disconnect
= 1;
2971 if (nesqp
->iwarp_state
== (u32
)NES_CQP_QP_IWARP_STATE_ERROR
) {
2972 spin_unlock_irqrestore(&nesqp
->lock
, qplockflags
);
2975 nes_debug(NES_DBG_MOD_QP
, "QP%u: new state = error\n",
2977 next_iwarp_state
= NES_CQP_QP_IWARP_STATE_ERROR
;
2978 /* next_iwarp_state = (NES_CQP_QP_IWARP_STATE_TERMINATE | 0x02000000); */
2979 if (nesqp
->hte_added
) {
2980 nes_debug(NES_DBG_MOD_QP
, "set CQP_QP_DEL_HTE\n");
2981 next_iwarp_state
|= NES_CQP_QP_DEL_HTE
;
2982 nesqp
->hte_added
= 0;
2984 if ((nesqp
->hw_tcp_state
> NES_AEQE_TCP_STATE_CLOSED
) &&
2985 (nesqp
->hw_tcp_state
!= NES_AEQE_TCP_STATE_TIME_WAIT
)) {
2986 next_iwarp_state
|= NES_CQP_QP_RESET
;
2987 nesqp
->in_disconnect
= 1;
2989 nes_debug(NES_DBG_MOD_QP
, "QP%u NOT setting NES_CQP_QP_RESET since TCP state = %u\n",
2990 nesqp
->hwqp
.qp_id
, nesqp
->hw_tcp_state
);
2993 issue_modify_qp
= 1;
2994 nesqp
->hw_iwarp_state
= NES_AEQE_IWARP_STATE_ERROR
;
2997 spin_unlock_irqrestore(&nesqp
->lock
, qplockflags
);
3002 nesqp
->ibqp_state
= attr
->qp_state
;
3003 if (((nesqp
->iwarp_state
& NES_CQP_QP_IWARP_STATE_MASK
) ==
3004 (u32
)NES_CQP_QP_IWARP_STATE_RTS
) &&
3005 ((next_iwarp_state
& NES_CQP_QP_IWARP_STATE_MASK
) >
3006 (u32
)NES_CQP_QP_IWARP_STATE_RTS
)) {
3007 nesqp
->iwarp_state
= next_iwarp_state
& NES_CQP_QP_IWARP_STATE_MASK
;
3008 nes_debug(NES_DBG_MOD_QP
, "Change nesqp->iwarp_state=%08x\n",
3009 nesqp
->iwarp_state
);
3010 issue_disconnect
= 1;
3012 nesqp
->iwarp_state
= next_iwarp_state
& NES_CQP_QP_IWARP_STATE_MASK
;
3013 nes_debug(NES_DBG_MOD_QP
, "Change nesqp->iwarp_state=%08x\n",
3014 nesqp
->iwarp_state
);
3018 if (attr_mask
& IB_QP_ACCESS_FLAGS
) {
3019 if (attr
->qp_access_flags
& IB_ACCESS_LOCAL_WRITE
) {
3020 nesqp
->nesqp_context
->misc
|= cpu_to_le32(NES_QPCONTEXT_MISC_RDMA_WRITE_EN
|
3021 NES_QPCONTEXT_MISC_RDMA_READ_EN
);
3022 issue_modify_qp
= 1;
3024 if (attr
->qp_access_flags
& IB_ACCESS_REMOTE_WRITE
) {
3025 nesqp
->nesqp_context
->misc
|= cpu_to_le32(NES_QPCONTEXT_MISC_RDMA_WRITE_EN
);
3026 issue_modify_qp
= 1;
3028 if (attr
->qp_access_flags
& IB_ACCESS_REMOTE_READ
) {
3029 nesqp
->nesqp_context
->misc
|= cpu_to_le32(NES_QPCONTEXT_MISC_RDMA_READ_EN
);
3030 issue_modify_qp
= 1;
3032 if (attr
->qp_access_flags
& IB_ACCESS_MW_BIND
) {
3033 nesqp
->nesqp_context
->misc
|= cpu_to_le32(NES_QPCONTEXT_MISC_WBIND_EN
);
3034 issue_modify_qp
= 1;
3037 if (nesqp
->user_mode
) {
3038 nesqp
->nesqp_context
->misc
|= cpu_to_le32(NES_QPCONTEXT_MISC_RDMA_WRITE_EN
|
3039 NES_QPCONTEXT_MISC_RDMA_READ_EN
);
3040 issue_modify_qp
= 1;
3044 original_last_aeq
= nesqp
->last_aeq
;
3045 spin_unlock_irqrestore(&nesqp
->lock
, qplockflags
);
3047 nes_debug(NES_DBG_MOD_QP
, "issue_modify_qp=%u\n", issue_modify_qp
);
3052 if (issue_modify_qp
) {
3053 nes_debug(NES_DBG_MOD_QP
, "call nes_hw_modify_qp\n");
3054 ret
= nes_hw_modify_qp(nesdev
, nesqp
, next_iwarp_state
, 1);
3056 nes_debug(NES_DBG_MOD_QP
, "nes_hw_modify_qp (next_iwarp_state = 0x%08X)"
3057 " failed for QP%u.\n",
3058 next_iwarp_state
, nesqp
->hwqp
.qp_id
);
3062 if ((issue_modify_qp
) && (nesqp
->ibqp_state
> IB_QPS_RTS
)) {
3063 nes_debug(NES_DBG_MOD_QP
, "QP%u Issued ModifyQP refcount (%d),"
3064 " original_last_aeq = 0x%04X. last_aeq = 0x%04X.\n",
3065 nesqp
->hwqp
.qp_id
, atomic_read(&nesqp
->refcount
),
3066 original_last_aeq
, nesqp
->last_aeq
);
3068 ((original_last_aeq
!= NES_AEQE_AEID_RDMAP_ROE_BAD_LLP_CLOSE
) &&
3071 if (nesqp
->cm_id
&& nesqp
->hw_tcp_state
!= 0) {
3072 nes_debug(NES_DBG_MOD_QP
, "QP%u Queuing fake disconnect for QP refcount (%d),"
3073 " original_last_aeq = 0x%04X. last_aeq = 0x%04X.\n",
3074 nesqp
->hwqp
.qp_id
, atomic_read(&nesqp
->refcount
),
3075 original_last_aeq
, nesqp
->last_aeq
);
3076 /* this one is for the cm_disconnect thread */
3077 spin_lock_irqsave(&nesqp
->lock
, qplockflags
);
3078 nesqp
->hw_tcp_state
= NES_AEQE_TCP_STATE_CLOSED
;
3079 nesqp
->last_aeq
= NES_AEQE_AEID_RESET_SENT
;
3080 spin_unlock_irqrestore(&nesqp
->lock
, qplockflags
);
3081 nes_cm_disconn(nesqp
);
3083 nes_debug(NES_DBG_MOD_QP
, "QP%u No fake disconnect, QP refcount=%d\n",
3084 nesqp
->hwqp
.qp_id
, atomic_read(&nesqp
->refcount
));
3087 spin_lock_irqsave(&nesqp
->lock
, qplockflags
);
3089 /* These two are for the timer thread */
3090 if (atomic_inc_return(&nesqp
->close_timer_started
) == 1) {
3091 nesqp
->cm_id
->add_ref(nesqp
->cm_id
);
3092 nes_debug(NES_DBG_MOD_QP
, "QP%u Not decrementing QP refcount (%d),"
3093 " need ae to finish up, original_last_aeq = 0x%04X."
3094 " last_aeq = 0x%04X, scheduling timer.\n",
3095 nesqp
->hwqp
.qp_id
, atomic_read(&nesqp
->refcount
),
3096 original_last_aeq
, nesqp
->last_aeq
);
3097 schedule_nes_timer(nesqp
->cm_node
, (struct sk_buff
*) nesqp
, NES_TIMER_TYPE_CLOSE
, 1, 0);
3099 spin_unlock_irqrestore(&nesqp
->lock
, qplockflags
);
3101 spin_unlock_irqrestore(&nesqp
->lock
, qplockflags
);
3102 nes_debug(NES_DBG_MOD_QP
, "QP%u Not decrementing QP refcount (%d),"
3103 " need ae to finish up, original_last_aeq = 0x%04X."
3104 " last_aeq = 0x%04X.\n",
3105 nesqp
->hwqp
.qp_id
, atomic_read(&nesqp
->refcount
),
3106 original_last_aeq
, nesqp
->last_aeq
);
3110 nes_debug(NES_DBG_MOD_QP
, "QP%u Decrementing QP refcount (%d), No ae to finish up,"
3111 " original_last_aeq = 0x%04X. last_aeq = 0x%04X.\n",
3112 nesqp
->hwqp
.qp_id
, atomic_read(&nesqp
->refcount
),
3113 original_last_aeq
, nesqp
->last_aeq
);
3116 nes_debug(NES_DBG_MOD_QP
, "QP%u Decrementing QP refcount (%d), No ae to finish up,"
3117 " original_last_aeq = 0x%04X. last_aeq = 0x%04X.\n",
3118 nesqp
->hwqp
.qp_id
, atomic_read(&nesqp
->refcount
),
3119 original_last_aeq
, nesqp
->last_aeq
);
3124 nes_debug(NES_DBG_MOD_QP
, "QP%u Leaving, refcount=%d\n",
3125 nesqp
->hwqp
.qp_id
, atomic_read(&nesqp
->refcount
));
3132 * nes_muticast_attach
3134 static int nes_multicast_attach(struct ib_qp
*ibqp
, union ib_gid
*gid
, u16 lid
)
3136 nes_debug(NES_DBG_INIT
, "\n");
3142 * nes_multicast_detach
3144 static int nes_multicast_detach(struct ib_qp
*ibqp
, union ib_gid
*gid
, u16 lid
)
3146 nes_debug(NES_DBG_INIT
, "\n");
3154 static int nes_process_mad(struct ib_device
*ibdev
, int mad_flags
,
3155 u8 port_num
, struct ib_wc
*in_wc
, struct ib_grh
*in_grh
,
3156 struct ib_mad
*in_mad
, struct ib_mad
*out_mad
)
3158 nes_debug(NES_DBG_INIT
, "\n");
3163 fill_wqe_sg_send(struct nes_hw_qp_wqe
*wqe
, struct ib_send_wr
*ib_wr
, u32 uselkey
)
3166 int total_payload_length
= 0;
3167 for (sge_index
= 0; sge_index
< ib_wr
->num_sge
; sge_index
++) {
3168 set_wqe_64bit_value(wqe
->wqe_words
, NES_IWARP_SQ_WQE_FRAG0_LOW_IDX
+(sge_index
*4),
3169 ib_wr
->sg_list
[sge_index
].addr
);
3170 set_wqe_32bit_value(wqe
->wqe_words
, NES_IWARP_SQ_WQE_LENGTH0_IDX
+ (sge_index
*4),
3171 ib_wr
->sg_list
[sge_index
].length
);
3173 set_wqe_32bit_value(wqe
->wqe_words
, NES_IWARP_SQ_WQE_STAG0_IDX
+ (sge_index
*4),
3174 (ib_wr
->sg_list
[sge_index
].lkey
));
3176 set_wqe_32bit_value(wqe
->wqe_words
, NES_IWARP_SQ_WQE_STAG0_IDX
+ (sge_index
*4), 0);
3178 total_payload_length
+= ib_wr
->sg_list
[sge_index
].length
;
3180 nes_debug(NES_DBG_IW_TX
, "UC UC UC, sending total_payload_length=%u \n",
3181 total_payload_length
);
3182 set_wqe_32bit_value(wqe
->wqe_words
, NES_IWARP_SQ_WQE_TOTAL_PAYLOAD_IDX
,
3183 total_payload_length
);
3189 static int nes_post_send(struct ib_qp
*ibqp
, struct ib_send_wr
*ib_wr
,
3190 struct ib_send_wr
**bad_wr
)
3193 unsigned long flags
= 0;
3194 struct nes_vnic
*nesvnic
= to_nesvnic(ibqp
->device
);
3195 struct nes_device
*nesdev
= nesvnic
->nesdev
;
3196 struct nes_qp
*nesqp
= to_nesqp(ibqp
);
3197 struct nes_hw_qp_wqe
*wqe
;
3199 u32 qsize
= nesqp
->hwqp
.sq_size
;
3204 u32 total_payload_length
;
3209 total_payload_length
= 0;
3211 if (nesqp
->ibqp_state
> IB_QPS_RTS
)
3214 spin_lock_irqsave(&nesqp
->lock
, flags
);
3216 head
= nesqp
->hwqp
.sq_head
;
3219 /* Check for SQ overflow */
3220 if (((head
+ (2 * qsize
) - nesqp
->hwqp
.sq_tail
) % qsize
) == (qsize
- 1)) {
3225 wqe
= &nesqp
->hwqp
.sq_vbase
[head
];
3226 /* nes_debug(NES_DBG_IW_TX, "processing sq wqe for QP%u at %p, head = %u.\n",
3227 nesqp->hwqp.qp_id, wqe, head); */
3228 nes_fill_init_qp_wqe(wqe
, nesqp
, head
);
3229 u64temp
= (u64
)(ib_wr
->wr_id
);
3230 set_wqe_64bit_value(wqe
->wqe_words
, NES_IWARP_SQ_WQE_COMP_SCRATCH_LOW_IDX
,
3232 switch (ib_wr
->opcode
) {
3234 if (ib_wr
->send_flags
& IB_SEND_SOLICITED
) {
3235 wqe_misc
= NES_IWARP_SQ_OP_SENDSE
;
3237 wqe_misc
= NES_IWARP_SQ_OP_SEND
;
3239 if (ib_wr
->num_sge
> nesdev
->nesadapter
->max_sge
) {
3243 if (ib_wr
->send_flags
& IB_SEND_FENCE
) {
3244 wqe_misc
|= NES_IWARP_SQ_WQE_LOCAL_FENCE
;
3246 if ((ib_wr
->send_flags
& IB_SEND_INLINE
) &&
3247 ((nes_drv_opt
& NES_DRV_OPT_NO_INLINE_DATA
) == 0) &&
3248 (ib_wr
->sg_list
[0].length
<= 64)) {
3249 memcpy(&wqe
->wqe_words
[NES_IWARP_SQ_WQE_IMM_DATA_START_IDX
],
3250 (void *)(unsigned long)ib_wr
->sg_list
[0].addr
, ib_wr
->sg_list
[0].length
);
3251 set_wqe_32bit_value(wqe
->wqe_words
, NES_IWARP_SQ_WQE_TOTAL_PAYLOAD_IDX
,
3252 ib_wr
->sg_list
[0].length
);
3253 wqe_misc
|= NES_IWARP_SQ_WQE_IMM_DATA
;
3255 fill_wqe_sg_send(wqe
, ib_wr
, 1);
3259 case IB_WR_RDMA_WRITE
:
3260 wqe_misc
= NES_IWARP_SQ_OP_RDMAW
;
3261 if (ib_wr
->num_sge
> nesdev
->nesadapter
->max_sge
) {
3262 nes_debug(NES_DBG_IW_TX
, "Exceeded max sge, ib_wr=%u, max=%u\n",
3264 nesdev
->nesadapter
->max_sge
);
3268 if (ib_wr
->send_flags
& IB_SEND_FENCE
) {
3269 wqe_misc
|= NES_IWARP_SQ_WQE_LOCAL_FENCE
;
3272 set_wqe_32bit_value(wqe
->wqe_words
, NES_IWARP_SQ_WQE_RDMA_STAG_IDX
,
3273 ib_wr
->wr
.rdma
.rkey
);
3274 set_wqe_64bit_value(wqe
->wqe_words
, NES_IWARP_SQ_WQE_RDMA_TO_LOW_IDX
,
3275 ib_wr
->wr
.rdma
.remote_addr
);
3277 if ((ib_wr
->send_flags
& IB_SEND_INLINE
) &&
3278 ((nes_drv_opt
& NES_DRV_OPT_NO_INLINE_DATA
) == 0) &&
3279 (ib_wr
->sg_list
[0].length
<= 64)) {
3280 memcpy(&wqe
->wqe_words
[NES_IWARP_SQ_WQE_IMM_DATA_START_IDX
],
3281 (void *)(unsigned long)ib_wr
->sg_list
[0].addr
, ib_wr
->sg_list
[0].length
);
3282 set_wqe_32bit_value(wqe
->wqe_words
, NES_IWARP_SQ_WQE_TOTAL_PAYLOAD_IDX
,
3283 ib_wr
->sg_list
[0].length
);
3284 wqe_misc
|= NES_IWARP_SQ_WQE_IMM_DATA
;
3286 fill_wqe_sg_send(wqe
, ib_wr
, 1);
3288 wqe
->wqe_words
[NES_IWARP_SQ_WQE_RDMA_LENGTH_IDX
] =
3289 wqe
->wqe_words
[NES_IWARP_SQ_WQE_TOTAL_PAYLOAD_IDX
];
3291 case IB_WR_RDMA_READ
:
3292 /* iWARP only supports 1 sge for RDMA reads */
3293 if (ib_wr
->num_sge
> 1) {
3294 nes_debug(NES_DBG_IW_TX
, "Exceeded max sge, ib_wr=%u, max=1\n",
3299 wqe_misc
= NES_IWARP_SQ_OP_RDMAR
;
3300 set_wqe_64bit_value(wqe
->wqe_words
, NES_IWARP_SQ_WQE_RDMA_TO_LOW_IDX
,
3301 ib_wr
->wr
.rdma
.remote_addr
);
3302 set_wqe_32bit_value(wqe
->wqe_words
, NES_IWARP_SQ_WQE_RDMA_STAG_IDX
,
3303 ib_wr
->wr
.rdma
.rkey
);
3304 set_wqe_32bit_value(wqe
->wqe_words
, NES_IWARP_SQ_WQE_RDMA_LENGTH_IDX
,
3305 ib_wr
->sg_list
->length
);
3306 set_wqe_64bit_value(wqe
->wqe_words
, NES_IWARP_SQ_WQE_FRAG0_LOW_IDX
,
3307 ib_wr
->sg_list
->addr
);
3308 set_wqe_32bit_value(wqe
->wqe_words
, NES_IWARP_SQ_WQE_STAG0_IDX
,
3309 ib_wr
->sg_list
->lkey
);
3317 if (ib_wr
->send_flags
& IB_SEND_SIGNALED
) {
3318 wqe_misc
|= NES_IWARP_SQ_WQE_SIGNALED_COMPL
;
3320 wqe
->wqe_words
[NES_IWARP_SQ_WQE_MISC_IDX
] = cpu_to_le32(wqe_misc
);
3322 ib_wr
= ib_wr
->next
;
3330 nesqp
->hwqp
.sq_head
= head
;
3333 counter
= min(wqe_count
, ((u32
)255));
3334 wqe_count
-= counter
;
3335 nes_write32(nesdev
->regs
+ NES_WQE_ALLOC
,
3336 (counter
<< 24) | 0x00800000 | nesqp
->hwqp
.qp_id
);
3339 spin_unlock_irqrestore(&nesqp
->lock
, flags
);
3350 static int nes_post_recv(struct ib_qp
*ibqp
, struct ib_recv_wr
*ib_wr
,
3351 struct ib_recv_wr
**bad_wr
)
3354 unsigned long flags
= 0;
3355 struct nes_vnic
*nesvnic
= to_nesvnic(ibqp
->device
);
3356 struct nes_device
*nesdev
= nesvnic
->nesdev
;
3357 struct nes_qp
*nesqp
= to_nesqp(ibqp
);
3358 struct nes_hw_qp_wqe
*wqe
;
3361 u32 qsize
= nesqp
->hwqp
.rq_size
;
3365 u32 total_payload_length
;
3367 if (nesqp
->ibqp_state
> IB_QPS_RTS
)
3370 spin_lock_irqsave(&nesqp
->lock
, flags
);
3372 head
= nesqp
->hwqp
.rq_head
;
3375 if (ib_wr
->num_sge
> nesdev
->nesadapter
->max_sge
) {
3379 /* Check for RQ overflow */
3380 if (((head
+ (2 * qsize
) - nesqp
->hwqp
.rq_tail
) % qsize
) == (qsize
- 1)) {
3385 nes_debug(NES_DBG_IW_RX
, "ibwr sge count = %u.\n", ib_wr
->num_sge
);
3386 wqe
= &nesqp
->hwqp
.rq_vbase
[head
];
3388 /* nes_debug(NES_DBG_IW_RX, "QP%u:processing rq wqe at %p, head = %u.\n",
3389 nesqp->hwqp.qp_id, wqe, head); */
3390 nes_fill_init_qp_wqe(wqe
, nesqp
, head
);
3391 u64temp
= (u64
)(ib_wr
->wr_id
);
3392 set_wqe_64bit_value(wqe
->wqe_words
, NES_IWARP_SQ_WQE_COMP_SCRATCH_LOW_IDX
,
3394 total_payload_length
= 0;
3395 for (sge_index
=0; sge_index
< ib_wr
->num_sge
; sge_index
++) {
3396 set_wqe_64bit_value(wqe
->wqe_words
, NES_IWARP_RQ_WQE_FRAG0_LOW_IDX
+(sge_index
*4),
3397 ib_wr
->sg_list
[sge_index
].addr
);
3398 set_wqe_32bit_value(wqe
->wqe_words
, NES_IWARP_RQ_WQE_LENGTH0_IDX
+(sge_index
*4),
3399 ib_wr
->sg_list
[sge_index
].length
);
3400 set_wqe_32bit_value(wqe
->wqe_words
,NES_IWARP_RQ_WQE_STAG0_IDX
+(sge_index
*4),
3401 ib_wr
->sg_list
[sge_index
].lkey
);
3403 total_payload_length
+= ib_wr
->sg_list
[sge_index
].length
;
3405 set_wqe_32bit_value(wqe
->wqe_words
, NES_IWARP_RQ_WQE_TOTAL_PAYLOAD_IDX
,
3406 total_payload_length
);
3408 ib_wr
= ib_wr
->next
;
3415 nesqp
->hwqp
.rq_head
= head
;
3418 counter
= min(wqe_count
, ((u32
)255));
3419 wqe_count
-= counter
;
3420 nes_write32(nesdev
->regs
+NES_WQE_ALLOC
, (counter
<<24) | nesqp
->hwqp
.qp_id
);
3423 spin_unlock_irqrestore(&nesqp
->lock
, flags
);
3434 static int nes_poll_cq(struct ib_cq
*ibcq
, int num_entries
, struct ib_wc
*entry
)
3439 unsigned long flags
= 0;
3440 struct nes_vnic
*nesvnic
= to_nesvnic(ibcq
->device
);
3441 struct nes_device
*nesdev
= nesvnic
->nesdev
;
3442 struct nes_cq
*nescq
= to_nescq(ibcq
);
3443 struct nes_qp
*nesqp
;
3444 struct nes_hw_cqe cqe
;
3453 nes_debug(NES_DBG_CQ
, "\n");
3455 spin_lock_irqsave(&nescq
->lock
, flags
);
3457 head
= nescq
->hw_cq
.cq_head
;
3458 cq_size
= nescq
->hw_cq
.cq_size
;
3460 while (cqe_count
< num_entries
) {
3461 if (le32_to_cpu(nescq
->hw_cq
.cq_vbase
[head
].cqe_words
[NES_CQE_OPCODE_IDX
]) &
3464 * Make sure we read CQ entry contents *after*
3465 * we've checked the valid bit.
3469 cqe
= nescq
->hw_cq
.cq_vbase
[head
];
3470 nescq
->hw_cq
.cq_vbase
[head
].cqe_words
[NES_CQE_OPCODE_IDX
] = 0;
3471 u32temp
= le32_to_cpu(cqe
.cqe_words
[NES_CQE_COMP_COMP_CTX_LOW_IDX
]);
3472 wqe_index
= u32temp
&
3473 (nesdev
->nesadapter
->max_qp_wr
- 1);
3474 u32temp
&= ~(NES_SW_CONTEXT_ALIGN
-1);
3475 /* parse CQE, get completion context from WQE (either rq or sq */
3476 u64temp
= (((u64
)(le32_to_cpu(cqe
.cqe_words
[NES_CQE_COMP_COMP_CTX_HIGH_IDX
])))<<32) |
3478 nesqp
= *((struct nes_qp
**)&u64temp
);
3479 memset(entry
, 0, sizeof *entry
);
3480 if (cqe
.cqe_words
[NES_CQE_ERROR_CODE_IDX
] == 0) {
3481 entry
->status
= IB_WC_SUCCESS
;
3483 entry
->status
= IB_WC_WR_FLUSH_ERR
;
3486 entry
->qp
= &nesqp
->ibqp
;
3487 entry
->src_qp
= nesqp
->hwqp
.qp_id
;
3489 if (le32_to_cpu(cqe
.cqe_words
[NES_CQE_OPCODE_IDX
]) & NES_CQE_SQ
) {
3490 if (nesqp
->skip_lsmm
) {
3491 nesqp
->skip_lsmm
= 0;
3492 wq_tail
= nesqp
->hwqp
.sq_tail
++;
3495 /* Working on a SQ Completion*/
3496 wq_tail
= wqe_index
;
3497 nesqp
->hwqp
.sq_tail
= (wqe_index
+1)&(nesqp
->hwqp
.sq_size
- 1);
3498 wrid
= (((u64
)(cpu_to_le32((u32
)nesqp
->hwqp
.sq_vbase
[wq_tail
].
3499 wqe_words
[NES_IWARP_SQ_WQE_COMP_SCRATCH_HIGH_IDX
]))) << 32) |
3500 ((u64
)(cpu_to_le32((u32
)nesqp
->hwqp
.sq_vbase
[wq_tail
].
3501 wqe_words
[NES_IWARP_SQ_WQE_COMP_SCRATCH_LOW_IDX
])));
3502 entry
->byte_len
= le32_to_cpu(nesqp
->hwqp
.sq_vbase
[wq_tail
].
3503 wqe_words
[NES_IWARP_SQ_WQE_TOTAL_PAYLOAD_IDX
]);
3505 switch (le32_to_cpu(nesqp
->hwqp
.sq_vbase
[wq_tail
].
3506 wqe_words
[NES_IWARP_SQ_WQE_MISC_IDX
]) & 0x3f) {
3507 case NES_IWARP_SQ_OP_RDMAW
:
3508 nes_debug(NES_DBG_CQ
, "Operation = RDMA WRITE.\n");
3509 entry
->opcode
= IB_WC_RDMA_WRITE
;
3511 case NES_IWARP_SQ_OP_RDMAR
:
3512 nes_debug(NES_DBG_CQ
, "Operation = RDMA READ.\n");
3513 entry
->opcode
= IB_WC_RDMA_READ
;
3514 entry
->byte_len
= le32_to_cpu(nesqp
->hwqp
.sq_vbase
[wq_tail
].
3515 wqe_words
[NES_IWARP_SQ_WQE_RDMA_LENGTH_IDX
]);
3517 case NES_IWARP_SQ_OP_SENDINV
:
3518 case NES_IWARP_SQ_OP_SENDSEINV
:
3519 case NES_IWARP_SQ_OP_SEND
:
3520 case NES_IWARP_SQ_OP_SENDSE
:
3521 nes_debug(NES_DBG_CQ
, "Operation = Send.\n");
3522 entry
->opcode
= IB_WC_SEND
;
3526 /* Working on a RQ Completion*/
3527 wq_tail
= wqe_index
;
3528 nesqp
->hwqp
.rq_tail
= (wqe_index
+1)&(nesqp
->hwqp
.rq_size
- 1);
3529 entry
->byte_len
= le32_to_cpu(cqe
.cqe_words
[NES_CQE_PAYLOAD_LENGTH_IDX
]);
3530 wrid
= ((u64
)(le32_to_cpu(nesqp
->hwqp
.rq_vbase
[wq_tail
].wqe_words
[NES_IWARP_RQ_WQE_COMP_SCRATCH_LOW_IDX
]))) |
3531 ((u64
)(le32_to_cpu(nesqp
->hwqp
.rq_vbase
[wq_tail
].wqe_words
[NES_IWARP_RQ_WQE_COMP_SCRATCH_HIGH_IDX
]))<<32);
3532 entry
->opcode
= IB_WC_RECV
;
3534 entry
->wr_id
= wrid
;
3536 if (++head
>= cq_size
)
3539 nescq
->polled_completions
++;
3540 if ((nescq
->polled_completions
> (cq_size
/ 2)) ||
3541 (nescq
->polled_completions
== 255)) {
3542 nes_debug(NES_DBG_CQ
, "CQ%u Issuing CQE Allocate since more than half of cqes"
3543 " are pending %u of %u.\n",
3544 nescq
->hw_cq
.cq_number
, nescq
->polled_completions
, cq_size
);
3545 nes_write32(nesdev
->regs
+NES_CQE_ALLOC
,
3546 nescq
->hw_cq
.cq_number
| (nescq
->polled_completions
<< 16));
3547 nescq
->polled_completions
= 0;
3554 if (nescq
->polled_completions
) {
3555 nes_write32(nesdev
->regs
+NES_CQE_ALLOC
,
3556 nescq
->hw_cq
.cq_number
| (nescq
->polled_completions
<< 16));
3557 nescq
->polled_completions
= 0;
3560 nescq
->hw_cq
.cq_head
= head
;
3561 nes_debug(NES_DBG_CQ
, "Reporting %u completions for CQ%u.\n",
3562 cqe_count
, nescq
->hw_cq
.cq_number
);
3564 spin_unlock_irqrestore(&nescq
->lock
, flags
);
3573 static int nes_req_notify_cq(struct ib_cq
*ibcq
, enum ib_cq_notify_flags notify_flags
)
3575 struct nes_vnic
*nesvnic
= to_nesvnic(ibcq
->device
);
3576 struct nes_device
*nesdev
= nesvnic
->nesdev
;
3577 struct nes_cq
*nescq
= to_nescq(ibcq
);
3580 nes_debug(NES_DBG_CQ
, "Requesting notification for CQ%u.\n",
3581 nescq
->hw_cq
.cq_number
);
3583 cq_arm
= nescq
->hw_cq
.cq_number
;
3584 if ((notify_flags
& IB_CQ_SOLICITED_MASK
) == IB_CQ_NEXT_COMP
)
3585 cq_arm
|= NES_CQE_ALLOC_NOTIFY_NEXT
;
3586 else if ((notify_flags
& IB_CQ_SOLICITED_MASK
) == IB_CQ_SOLICITED
)
3587 cq_arm
|= NES_CQE_ALLOC_NOTIFY_SE
;
3591 nes_write32(nesdev
->regs
+NES_CQE_ALLOC
, cq_arm
);
3592 nes_read32(nesdev
->regs
+NES_CQE_ALLOC
);
3599 * nes_init_ofa_device
3601 struct nes_ib_device
*nes_init_ofa_device(struct net_device
*netdev
)
3603 struct nes_ib_device
*nesibdev
;
3604 struct nes_vnic
*nesvnic
= netdev_priv(netdev
);
3605 struct nes_device
*nesdev
= nesvnic
->nesdev
;
3607 nesibdev
= (struct nes_ib_device
*)ib_alloc_device(sizeof(struct nes_ib_device
));
3608 if (nesibdev
== NULL
) {
3611 strlcpy(nesibdev
->ibdev
.name
, "nes%d", IB_DEVICE_NAME_MAX
);
3612 nesibdev
->ibdev
.owner
= THIS_MODULE
;
3614 nesibdev
->ibdev
.node_type
= RDMA_NODE_RNIC
;
3615 memset(&nesibdev
->ibdev
.node_guid
, 0, sizeof(nesibdev
->ibdev
.node_guid
));
3616 memcpy(&nesibdev
->ibdev
.node_guid
, netdev
->dev_addr
, 6);
3618 nesibdev
->ibdev
.uverbs_cmd_mask
=
3619 (1ull << IB_USER_VERBS_CMD_GET_CONTEXT
) |
3620 (1ull << IB_USER_VERBS_CMD_QUERY_DEVICE
) |
3621 (1ull << IB_USER_VERBS_CMD_QUERY_PORT
) |
3622 (1ull << IB_USER_VERBS_CMD_ALLOC_PD
) |
3623 (1ull << IB_USER_VERBS_CMD_DEALLOC_PD
) |
3624 (1ull << IB_USER_VERBS_CMD_REG_MR
) |
3625 (1ull << IB_USER_VERBS_CMD_DEREG_MR
) |
3626 (1ull << IB_USER_VERBS_CMD_CREATE_COMP_CHANNEL
) |
3627 (1ull << IB_USER_VERBS_CMD_CREATE_CQ
) |
3628 (1ull << IB_USER_VERBS_CMD_DESTROY_CQ
) |
3629 (1ull << IB_USER_VERBS_CMD_CREATE_AH
) |
3630 (1ull << IB_USER_VERBS_CMD_DESTROY_AH
) |
3631 (1ull << IB_USER_VERBS_CMD_REQ_NOTIFY_CQ
) |
3632 (1ull << IB_USER_VERBS_CMD_CREATE_QP
) |
3633 (1ull << IB_USER_VERBS_CMD_MODIFY_QP
) |
3634 (1ull << IB_USER_VERBS_CMD_POLL_CQ
) |
3635 (1ull << IB_USER_VERBS_CMD_DESTROY_QP
) |
3636 (1ull << IB_USER_VERBS_CMD_ALLOC_MW
) |
3637 (1ull << IB_USER_VERBS_CMD_BIND_MW
) |
3638 (1ull << IB_USER_VERBS_CMD_DEALLOC_MW
) |
3639 (1ull << IB_USER_VERBS_CMD_POST_RECV
) |
3640 (1ull << IB_USER_VERBS_CMD_POST_SEND
);
3642 nesibdev
->ibdev
.phys_port_cnt
= 1;
3643 nesibdev
->ibdev
.num_comp_vectors
= 1;
3644 nesibdev
->ibdev
.dma_device
= &nesdev
->pcidev
->dev
;
3645 nesibdev
->ibdev
.dev
.parent
= &nesdev
->pcidev
->dev
;
3646 nesibdev
->ibdev
.query_device
= nes_query_device
;
3647 nesibdev
->ibdev
.query_port
= nes_query_port
;
3648 nesibdev
->ibdev
.modify_port
= nes_modify_port
;
3649 nesibdev
->ibdev
.query_pkey
= nes_query_pkey
;
3650 nesibdev
->ibdev
.query_gid
= nes_query_gid
;
3651 nesibdev
->ibdev
.alloc_ucontext
= nes_alloc_ucontext
;
3652 nesibdev
->ibdev
.dealloc_ucontext
= nes_dealloc_ucontext
;
3653 nesibdev
->ibdev
.mmap
= nes_mmap
;
3654 nesibdev
->ibdev
.alloc_pd
= nes_alloc_pd
;
3655 nesibdev
->ibdev
.dealloc_pd
= nes_dealloc_pd
;
3656 nesibdev
->ibdev
.create_ah
= nes_create_ah
;
3657 nesibdev
->ibdev
.destroy_ah
= nes_destroy_ah
;
3658 nesibdev
->ibdev
.create_qp
= nes_create_qp
;
3659 nesibdev
->ibdev
.modify_qp
= nes_modify_qp
;
3660 nesibdev
->ibdev
.query_qp
= nes_query_qp
;
3661 nesibdev
->ibdev
.destroy_qp
= nes_destroy_qp
;
3662 nesibdev
->ibdev
.create_cq
= nes_create_cq
;
3663 nesibdev
->ibdev
.destroy_cq
= nes_destroy_cq
;
3664 nesibdev
->ibdev
.poll_cq
= nes_poll_cq
;
3665 nesibdev
->ibdev
.get_dma_mr
= nes_get_dma_mr
;
3666 nesibdev
->ibdev
.reg_phys_mr
= nes_reg_phys_mr
;
3667 nesibdev
->ibdev
.reg_user_mr
= nes_reg_user_mr
;
3668 nesibdev
->ibdev
.dereg_mr
= nes_dereg_mr
;
3669 nesibdev
->ibdev
.alloc_mw
= nes_alloc_mw
;
3670 nesibdev
->ibdev
.dealloc_mw
= nes_dealloc_mw
;
3671 nesibdev
->ibdev
.bind_mw
= nes_bind_mw
;
3673 nesibdev
->ibdev
.alloc_fmr
= nes_alloc_fmr
;
3674 nesibdev
->ibdev
.unmap_fmr
= nes_unmap_fmr
;
3675 nesibdev
->ibdev
.dealloc_fmr
= nes_dealloc_fmr
;
3676 nesibdev
->ibdev
.map_phys_fmr
= nes_map_phys_fmr
;
3678 nesibdev
->ibdev
.attach_mcast
= nes_multicast_attach
;
3679 nesibdev
->ibdev
.detach_mcast
= nes_multicast_detach
;
3680 nesibdev
->ibdev
.process_mad
= nes_process_mad
;
3682 nesibdev
->ibdev
.req_notify_cq
= nes_req_notify_cq
;
3683 nesibdev
->ibdev
.post_send
= nes_post_send
;
3684 nesibdev
->ibdev
.post_recv
= nes_post_recv
;
3686 nesibdev
->ibdev
.iwcm
= kzalloc(sizeof(*nesibdev
->ibdev
.iwcm
), GFP_KERNEL
);
3687 if (nesibdev
->ibdev
.iwcm
== NULL
) {
3688 ib_dealloc_device(&nesibdev
->ibdev
);
3691 nesibdev
->ibdev
.iwcm
->add_ref
= nes_add_ref
;
3692 nesibdev
->ibdev
.iwcm
->rem_ref
= nes_rem_ref
;
3693 nesibdev
->ibdev
.iwcm
->get_qp
= nes_get_qp
;
3694 nesibdev
->ibdev
.iwcm
->connect
= nes_connect
;
3695 nesibdev
->ibdev
.iwcm
->accept
= nes_accept
;
3696 nesibdev
->ibdev
.iwcm
->reject
= nes_reject
;
3697 nesibdev
->ibdev
.iwcm
->create_listen
= nes_create_listen
;
3698 nesibdev
->ibdev
.iwcm
->destroy_listen
= nes_destroy_listen
;
3705 * nes_destroy_ofa_device
3707 void nes_destroy_ofa_device(struct nes_ib_device
*nesibdev
)
3709 if (nesibdev
== NULL
)
3712 nes_unregister_ofa_device(nesibdev
);
3714 kfree(nesibdev
->ibdev
.iwcm
);
3715 ib_dealloc_device(&nesibdev
->ibdev
);
3720 * nes_register_ofa_device
3722 int nes_register_ofa_device(struct nes_ib_device
*nesibdev
)
3724 struct nes_vnic
*nesvnic
= nesibdev
->nesvnic
;
3725 struct nes_device
*nesdev
= nesvnic
->nesdev
;
3726 struct nes_adapter
*nesadapter
= nesdev
->nesadapter
;
3729 ret
= ib_register_device(&nesvnic
->nesibdev
->ibdev
);
3734 /* Get the resources allocated to this device */
3735 nesibdev
->max_cq
= (nesadapter
->max_cq
-NES_FIRST_QPN
) / nesadapter
->port_count
;
3736 nesibdev
->max_mr
= nesadapter
->max_mr
/ nesadapter
->port_count
;
3737 nesibdev
->max_qp
= (nesadapter
->max_qp
-NES_FIRST_QPN
) / nesadapter
->port_count
;
3738 nesibdev
->max_pd
= nesadapter
->max_pd
/ nesadapter
->port_count
;
3740 for (i
= 0; i
< ARRAY_SIZE(nes_dev_attributes
); ++i
) {
3741 ret
= device_create_file(&nesibdev
->ibdev
.dev
, nes_dev_attributes
[i
]);
3745 device_remove_file(&nesibdev
->ibdev
.dev
,
3746 nes_dev_attributes
[i
]);
3748 ib_unregister_device(&nesibdev
->ibdev
);
3753 nesvnic
->of_device_registered
= 1;
3760 * nes_unregister_ofa_device
3762 static void nes_unregister_ofa_device(struct nes_ib_device
*nesibdev
)
3764 struct nes_vnic
*nesvnic
= nesibdev
->nesvnic
;
3767 for (i
= 0; i
< ARRAY_SIZE(nes_dev_attributes
); ++i
) {
3768 device_remove_file(&nesibdev
->ibdev
.dev
, nes_dev_attributes
[i
]);
3771 if (nesvnic
->of_device_registered
) {
3772 ib_unregister_device(&nesibdev
->ibdev
);
3775 nesvnic
->of_device_registered
= 0;