aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/infiniband
diff options
context:
space:
mode:
authorRoland Dreier <rolandd@cisco.com>2008-07-15 02:48:49 -0400
committerRoland Dreier <rolandd@cisco.com>2008-07-15 02:48:49 -0400
commit1ff66e8c1faee7c2711b84b9c89e1c5fcd767839 (patch)
tree7a42adc119605abd1acb54d16b8a93f1effd2069 /drivers/infiniband
parentee1e2c82c245a5fb2864e9dbcdaab3390fde3fcc (diff)
RDMA/nes: Encapsulate logic nes_put_cqp_request()
The iw_nes driver repeats the logic if (atomic_dec_and_test(&cqp_request->refcount)) { if (cqp_request->dynamic) { kfree(cqp_request); } else { spin_lock_irqsave(&nesdev->cqp.lock, flags); list_add_tail(&cqp_request->list, &nesdev->cqp_avail_reqs); spin_unlock_irqrestore(&nesdev->cqp.lock, flags); } } over and over. Wrap this up in functions nes_free_cqp_request() and nes_put_cqp_request() to simplify such code. In addition to making the source smaller and more readable, this shrinks the compiled code quite a bit: add/remove: 2/0 grow/shrink: 0/13 up/down: 164/-1692 (-1528) function old new delta nes_free_cqp_request - 147 +147 nes_put_cqp_request - 17 +17 nes_modify_qp 2316 2293 -23 nes_hw_modify_qp 737 657 -80 nes_dereg_mr 945 860 -85 flush_wqes 501 416 -85 nes_manage_apbvt 648 560 -88 nes_reg_mr 1117 1026 -91 nes_cqp_ce_handler 927 769 -158 nes_alloc_mw 1052 884 -168 nes_create_qp 5314 5141 -173 nes_alloc_fmr 2212 2035 -177 nes_destroy_cq 1097 918 -179 nes_create_cq 2787 2598 -189 nes_dealloc_mw 762 566 -196 Signed-off-by: Roland Dreier <rolandd@cisco.com> Acked-by: Faisal Latif <flatif@neteffect.com>
Diffstat (limited to 'drivers/infiniband')
-rw-r--r--drivers/infiniband/hw/nes/nes.h4
-rw-r--r--drivers/infiniband/hw/nes/nes_hw.c60
-rw-r--r--drivers/infiniband/hw/nes/nes_utils.c24
-rw-r--r--drivers/infiniband/hw/nes/nes_verbs.c189
4 files changed, 66 insertions, 211 deletions
diff --git a/drivers/infiniband/hw/nes/nes.h b/drivers/infiniband/hw/nes/nes.h
index 61b46e9c7d2..fe88bec4894 100644
--- a/drivers/infiniband/hw/nes/nes.h
+++ b/drivers/infiniband/hw/nes/nes.h
@@ -538,6 +538,10 @@ void nes_read_1G_phy_reg(struct nes_device *, u8, u8, u16 *);
538void nes_write_10G_phy_reg(struct nes_device *, u16, u8, u16, u16); 538void nes_write_10G_phy_reg(struct nes_device *, u16, u8, u16, u16);
539void nes_read_10G_phy_reg(struct nes_device *, u8, u8, u16); 539void nes_read_10G_phy_reg(struct nes_device *, u8, u8, u16);
540struct nes_cqp_request *nes_get_cqp_request(struct nes_device *); 540struct nes_cqp_request *nes_get_cqp_request(struct nes_device *);
541void nes_free_cqp_request(struct nes_device *nesdev,
542 struct nes_cqp_request *cqp_request);
543void nes_put_cqp_request(struct nes_device *nesdev,
544 struct nes_cqp_request *cqp_request);
541void nes_post_cqp_request(struct nes_device *, struct nes_cqp_request *, int); 545void nes_post_cqp_request(struct nes_device *, struct nes_cqp_request *, int);
542int nes_arp_table(struct nes_device *, u32, u8 *, u32); 546int nes_arp_table(struct nes_device *, u32, u8 *, u32);
543void nes_mh_fix(unsigned long); 547void nes_mh_fix(unsigned long);
diff --git a/drivers/infiniband/hw/nes/nes_hw.c b/drivers/infiniband/hw/nes/nes_hw.c
index d3278f111ca..80e486653ec 100644
--- a/drivers/infiniband/hw/nes/nes_hw.c
+++ b/drivers/infiniband/hw/nes/nes_hw.c
@@ -2710,39 +2710,11 @@ static void nes_cqp_ce_handler(struct nes_device *nesdev, struct nes_hw_cq *cq)
2710 barrier(); 2710 barrier();
2711 cqp_request->request_done = 1; 2711 cqp_request->request_done = 1;
2712 wake_up(&cqp_request->waitq); 2712 wake_up(&cqp_request->waitq);
2713 if (atomic_dec_and_test(&cqp_request->refcount)) { 2713 nes_put_cqp_request(nesdev, cqp_request);
2714 nes_debug(NES_DBG_CQP, "CQP request %p (opcode 0x%02X) freed.\n",
2715 cqp_request,
2716 le32_to_cpu(cqp_request->cqp_wqe.wqe_words[NES_CQP_WQE_OPCODE_IDX])&0x3f);
2717 if (cqp_request->dynamic) {
2718 kfree(cqp_request);
2719 } else {
2720 spin_lock_irqsave(&nesdev->cqp.lock, flags);
2721 list_add_tail(&cqp_request->list, &nesdev->cqp_avail_reqs);
2722 spin_unlock_irqrestore(&nesdev->cqp.lock, flags);
2723 }
2724 }
2725 } else if (cqp_request->callback) {
2726 /* Envoke the callback routine */
2727 cqp_request->cqp_callback(nesdev, cqp_request);
2728 if (cqp_request->dynamic) {
2729 kfree(cqp_request);
2730 } else {
2731 spin_lock_irqsave(&nesdev->cqp.lock, flags);
2732 list_add_tail(&cqp_request->list, &nesdev->cqp_avail_reqs);
2733 spin_unlock_irqrestore(&nesdev->cqp.lock, flags);
2734 }
2735 } else { 2714 } else {
2736 nes_debug(NES_DBG_CQP, "CQP request %p (opcode 0x%02X) freed.\n", 2715 if (cqp_request->callback)
2737 cqp_request, 2716 cqp_request->cqp_callback(nesdev, cqp_request);
2738 le32_to_cpu(cqp_request->cqp_wqe.wqe_words[NES_CQP_WQE_OPCODE_IDX]) & 0x3f); 2717 nes_free_cqp_request(nesdev, cqp_request);
2739 if (cqp_request->dynamic) {
2740 kfree(cqp_request);
2741 } else {
2742 spin_lock_irqsave(&nesdev->cqp.lock, flags);
2743 list_add_tail(&cqp_request->list, &nesdev->cqp_avail_reqs);
2744 spin_unlock_irqrestore(&nesdev->cqp.lock, flags);
2745 }
2746 } 2718 }
2747 } else { 2719 } else {
2748 wake_up(&nesdev->cqp.waitq); 2720 wake_up(&nesdev->cqp.waitq);
@@ -3149,7 +3121,6 @@ int nes_manage_apbvt(struct nes_vnic *nesvnic, u32 accel_local_port,
3149{ 3121{
3150 struct nes_device *nesdev = nesvnic->nesdev; 3122 struct nes_device *nesdev = nesvnic->nesdev;
3151 struct nes_hw_cqp_wqe *cqp_wqe; 3123 struct nes_hw_cqp_wqe *cqp_wqe;
3152 unsigned long flags;
3153 struct nes_cqp_request *cqp_request; 3124 struct nes_cqp_request *cqp_request;
3154 int ret = 0; 3125 int ret = 0;
3155 u16 major_code; 3126 u16 major_code;
@@ -3184,15 +3155,9 @@ int nes_manage_apbvt(struct nes_vnic *nesvnic, u32 accel_local_port,
3184 nes_debug(NES_DBG_QP, "Completed, ret=%u, CQP Major:Minor codes = 0x%04X:0x%04X\n", 3155 nes_debug(NES_DBG_QP, "Completed, ret=%u, CQP Major:Minor codes = 0x%04X:0x%04X\n",
3185 ret, cqp_request->major_code, cqp_request->minor_code); 3156 ret, cqp_request->major_code, cqp_request->minor_code);
3186 major_code = cqp_request->major_code; 3157 major_code = cqp_request->major_code;
3187 if (atomic_dec_and_test(&cqp_request->refcount)) { 3158
3188 if (cqp_request->dynamic) { 3159 nes_put_cqp_request(nesdev, cqp_request);
3189 kfree(cqp_request); 3160
3190 } else {
3191 spin_lock_irqsave(&nesdev->cqp.lock, flags);
3192 list_add_tail(&cqp_request->list, &nesdev->cqp_avail_reqs);
3193 spin_unlock_irqrestore(&nesdev->cqp.lock, flags);
3194 }
3195 }
3196 if (!ret) 3161 if (!ret)
3197 return -ETIME; 3162 return -ETIME;
3198 else if (major_code) 3163 else if (major_code)
@@ -3262,7 +3227,6 @@ void nes_manage_arp_cache(struct net_device *netdev, unsigned char *mac_addr,
3262void flush_wqes(struct nes_device *nesdev, struct nes_qp *nesqp, 3227void flush_wqes(struct nes_device *nesdev, struct nes_qp *nesqp,
3263 u32 which_wq, u32 wait_completion) 3228 u32 which_wq, u32 wait_completion)
3264{ 3229{
3265 unsigned long flags;
3266 struct nes_cqp_request *cqp_request; 3230 struct nes_cqp_request *cqp_request;
3267 struct nes_hw_cqp_wqe *cqp_wqe; 3231 struct nes_hw_cqp_wqe *cqp_wqe;
3268 int ret; 3232 int ret;
@@ -3294,14 +3258,6 @@ void flush_wqes(struct nes_device *nesdev, struct nes_qp *nesqp,
3294 nes_debug(NES_DBG_QP, "Flush SQ QP WQEs completed, ret=%u," 3258 nes_debug(NES_DBG_QP, "Flush SQ QP WQEs completed, ret=%u,"
3295 " CQP Major:Minor codes = 0x%04X:0x%04X\n", 3259 " CQP Major:Minor codes = 0x%04X:0x%04X\n",
3296 ret, cqp_request->major_code, cqp_request->minor_code); 3260 ret, cqp_request->major_code, cqp_request->minor_code);
3297 if (atomic_dec_and_test(&cqp_request->refcount)) { 3261 nes_put_cqp_request(nesdev, cqp_request);
3298 if (cqp_request->dynamic) {
3299 kfree(cqp_request);
3300 } else {
3301 spin_lock_irqsave(&nesdev->cqp.lock, flags);
3302 list_add_tail(&cqp_request->list, &nesdev->cqp_avail_reqs);
3303 spin_unlock_irqrestore(&nesdev->cqp.lock, flags);
3304 }
3305 }
3306 } 3262 }
3307} 3263}
diff --git a/drivers/infiniband/hw/nes/nes_utils.c b/drivers/infiniband/hw/nes/nes_utils.c
index fe83d1b2b17..8f519c86087 100644
--- a/drivers/infiniband/hw/nes/nes_utils.c
+++ b/drivers/infiniband/hw/nes/nes_utils.c
@@ -567,6 +567,30 @@ struct nes_cqp_request *nes_get_cqp_request(struct nes_device *nesdev)
567 return cqp_request; 567 return cqp_request;
568} 568}
569 569
570void nes_free_cqp_request(struct nes_device *nesdev,
571 struct nes_cqp_request *cqp_request)
572{
573 unsigned long flags;
574
575 nes_debug(NES_DBG_CQP, "CQP request %p (opcode 0x%02X) freed.\n",
576 cqp_request,
577 le32_to_cpu(cqp_request->cqp_wqe.wqe_words[NES_CQP_WQE_OPCODE_IDX]) & 0x3f);
578
579 if (cqp_request->dynamic) {
580 kfree(cqp_request);
581 } else {
582 spin_lock_irqsave(&nesdev->cqp.lock, flags);
583 list_add_tail(&cqp_request->list, &nesdev->cqp_avail_reqs);
584 spin_unlock_irqrestore(&nesdev->cqp.lock, flags);
585 }
586}
587
588void nes_put_cqp_request(struct nes_device *nesdev,
589 struct nes_cqp_request *cqp_request)
590{
591 if (atomic_dec_and_test(&cqp_request->refcount))
592 nes_free_cqp_request(nesdev, cqp_request);
593}
570 594
571/** 595/**
572 * nes_post_cqp_request 596 * nes_post_cqp_request
diff --git a/drivers/infiniband/hw/nes/nes_verbs.c b/drivers/infiniband/hw/nes/nes_verbs.c
index d617da9bd35..464a98a6e11 100644
--- a/drivers/infiniband/hw/nes/nes_verbs.c
+++ b/drivers/infiniband/hw/nes/nes_verbs.c
@@ -55,7 +55,6 @@ static void nes_unregister_ofa_device(struct nes_ib_device *nesibdev);
55 * nes_alloc_mw 55 * nes_alloc_mw
56 */ 56 */
57static struct ib_mw *nes_alloc_mw(struct ib_pd *ibpd) { 57static struct ib_mw *nes_alloc_mw(struct ib_pd *ibpd) {
58 unsigned long flags;
59 struct nes_pd *nespd = to_nespd(ibpd); 58 struct nes_pd *nespd = to_nespd(ibpd);
60 struct nes_vnic *nesvnic = to_nesvnic(ibpd->device); 59 struct nes_vnic *nesvnic = to_nesvnic(ibpd->device);
61 struct nes_device *nesdev = nesvnic->nesdev; 60 struct nes_device *nesdev = nesvnic->nesdev;
@@ -128,15 +127,7 @@ static struct ib_mw *nes_alloc_mw(struct ib_pd *ibpd) {
128 " CQP Major:Minor codes = 0x%04X:0x%04X.\n", 127 " CQP Major:Minor codes = 0x%04X:0x%04X.\n",
129 stag, ret, cqp_request->major_code, cqp_request->minor_code); 128 stag, ret, cqp_request->major_code, cqp_request->minor_code);
130 if ((!ret) || (cqp_request->major_code)) { 129 if ((!ret) || (cqp_request->major_code)) {
131 if (atomic_dec_and_test(&cqp_request->refcount)) { 130 nes_put_cqp_request(nesdev, cqp_request);
132 if (cqp_request->dynamic) {
133 kfree(cqp_request);
134 } else {
135 spin_lock_irqsave(&nesdev->cqp.lock, flags);
136 list_add_tail(&cqp_request->list, &nesdev->cqp_avail_reqs);
137 spin_unlock_irqrestore(&nesdev->cqp.lock, flags);
138 }
139 }
140 kfree(nesmr); 131 kfree(nesmr);
141 nes_free_resource(nesadapter, nesadapter->allocated_mrs, stag_index); 132 nes_free_resource(nesadapter, nesadapter->allocated_mrs, stag_index);
142 if (!ret) { 133 if (!ret) {
@@ -144,17 +135,8 @@ static struct ib_mw *nes_alloc_mw(struct ib_pd *ibpd) {
144 } else { 135 } else {
145 return ERR_PTR(-ENOMEM); 136 return ERR_PTR(-ENOMEM);
146 } 137 }
147 } else {
148 if (atomic_dec_and_test(&cqp_request->refcount)) {
149 if (cqp_request->dynamic) {
150 kfree(cqp_request);
151 } else {
152 spin_lock_irqsave(&nesdev->cqp.lock, flags);
153 list_add_tail(&cqp_request->list, &nesdev->cqp_avail_reqs);
154 spin_unlock_irqrestore(&nesdev->cqp.lock, flags);
155 }
156 }
157 } 138 }
139 nes_put_cqp_request(nesdev, cqp_request);
158 140
159 nesmr->ibmw.rkey = stag; 141 nesmr->ibmw.rkey = stag;
160 nesmr->mode = IWNES_MEMREG_TYPE_MW; 142 nesmr->mode = IWNES_MEMREG_TYPE_MW;
@@ -178,7 +160,6 @@ static int nes_dealloc_mw(struct ib_mw *ibmw)
178 struct nes_hw_cqp_wqe *cqp_wqe; 160 struct nes_hw_cqp_wqe *cqp_wqe;
179 struct nes_cqp_request *cqp_request; 161 struct nes_cqp_request *cqp_request;
180 int err = 0; 162 int err = 0;
181 unsigned long flags;
182 int ret; 163 int ret;
183 164
184 /* Deallocate the window with the adapter */ 165 /* Deallocate the window with the adapter */
@@ -204,32 +185,12 @@ static int nes_dealloc_mw(struct ib_mw *ibmw)
204 nes_debug(NES_DBG_MR, "Deallocate STag completed, wait_event_timeout ret = %u," 185 nes_debug(NES_DBG_MR, "Deallocate STag completed, wait_event_timeout ret = %u,"
205 " CQP Major:Minor codes = 0x%04X:0x%04X.\n", 186 " CQP Major:Minor codes = 0x%04X:0x%04X.\n",
206 ret, cqp_request->major_code, cqp_request->minor_code); 187 ret, cqp_request->major_code, cqp_request->minor_code);
207 if ((!ret) || (cqp_request->major_code)) { 188 if (!ret)
208 if (atomic_dec_and_test(&cqp_request->refcount)) { 189 err = -ETIME;
209 if (cqp_request->dynamic) { 190 else if (cqp_request->major_code)
210 kfree(cqp_request); 191 err = -EIO;
211 } else { 192
212 spin_lock_irqsave(&nesdev->cqp.lock, flags); 193 nes_put_cqp_request(nesdev, cqp_request);
213 list_add_tail(&cqp_request->list, &nesdev->cqp_avail_reqs);
214 spin_unlock_irqrestore(&nesdev->cqp.lock, flags);
215 }
216 }
217 if (!ret) {
218 err = -ETIME;
219 } else {
220 err = -EIO;
221 }
222 } else {
223 if (atomic_dec_and_test(&cqp_request->refcount)) {
224 if (cqp_request->dynamic) {
225 kfree(cqp_request);
226 } else {
227 spin_lock_irqsave(&nesdev->cqp.lock, flags);
228 list_add_tail(&cqp_request->list, &nesdev->cqp_avail_reqs);
229 spin_unlock_irqrestore(&nesdev->cqp.lock, flags);
230 }
231 }
232 }
233 194
234 nes_free_resource(nesadapter, nesadapter->allocated_mrs, 195 nes_free_resource(nesadapter, nesadapter->allocated_mrs,
235 (ibmw->rkey & 0x0fffff00) >> 8); 196 (ibmw->rkey & 0x0fffff00) >> 8);
@@ -526,29 +487,11 @@ static struct ib_fmr *nes_alloc_fmr(struct ib_pd *ibpd,
526 stag, ret, cqp_request->major_code, cqp_request->minor_code); 487 stag, ret, cqp_request->major_code, cqp_request->minor_code);
527 488
528 if ((!ret) || (cqp_request->major_code)) { 489 if ((!ret) || (cqp_request->major_code)) {
529 if (atomic_dec_and_test(&cqp_request->refcount)) { 490 nes_put_cqp_request(nesdev, cqp_request);
530 if (cqp_request->dynamic) {
531 kfree(cqp_request);
532 } else {
533 spin_lock_irqsave(&nesdev->cqp.lock, flags);
534 list_add_tail(&cqp_request->list, &nesdev->cqp_avail_reqs);
535 spin_unlock_irqrestore(&nesdev->cqp.lock, flags);
536 }
537 }
538 ret = (!ret) ? -ETIME : -EIO; 491 ret = (!ret) ? -ETIME : -EIO;
539 goto failed_leaf_vpbl_pages_alloc; 492 goto failed_leaf_vpbl_pages_alloc;
540 } else {
541 if (atomic_dec_and_test(&cqp_request->refcount)) {
542 if (cqp_request->dynamic) {
543 kfree(cqp_request);
544 } else {
545 spin_lock_irqsave(&nesdev->cqp.lock, flags);
546 list_add_tail(&cqp_request->list, &nesdev->cqp_avail_reqs);
547 spin_unlock_irqrestore(&nesdev->cqp.lock, flags);
548 }
549 }
550 } 493 }
551 494 nes_put_cqp_request(nesdev, cqp_request);
552 nesfmr->nesmr.ibfmr.lkey = stag; 495 nesfmr->nesmr.ibfmr.lkey = stag;
553 nesfmr->nesmr.ibfmr.rkey = stag; 496 nesfmr->nesmr.ibfmr.rkey = stag;
554 nesfmr->attr = *ibfmr_attr; 497 nesfmr->attr = *ibfmr_attr;
@@ -1487,15 +1430,7 @@ static struct ib_qp *nes_create_qp(struct ib_pd *ibpd,
1487 nesqp->hwqp.qp_id, ret, nesdev->cqp.sq_head, nesdev->cqp.sq_tail, 1430 nesqp->hwqp.qp_id, ret, nesdev->cqp.sq_head, nesdev->cqp.sq_tail,
1488 cqp_request->major_code, cqp_request->minor_code); 1431 cqp_request->major_code, cqp_request->minor_code);
1489 if ((!ret) || (cqp_request->major_code)) { 1432 if ((!ret) || (cqp_request->major_code)) {
1490 if (atomic_dec_and_test(&cqp_request->refcount)) { 1433 nes_put_cqp_request(nesdev, cqp_request);
1491 if (cqp_request->dynamic) {
1492 kfree(cqp_request);
1493 } else {
1494 spin_lock_irqsave(&nesdev->cqp.lock, flags);
1495 list_add_tail(&cqp_request->list, &nesdev->cqp_avail_reqs);
1496 spin_unlock_irqrestore(&nesdev->cqp.lock, flags);
1497 }
1498 }
1499 nes_free_resource(nesadapter, nesadapter->allocated_qps, qp_num); 1434 nes_free_resource(nesadapter, nesadapter->allocated_qps, qp_num);
1500 nes_free_qp_mem(nesdev, nesqp,virt_wqs); 1435 nes_free_qp_mem(nesdev, nesqp,virt_wqs);
1501 kfree(nesqp->allocated_buffer); 1436 kfree(nesqp->allocated_buffer);
@@ -1504,18 +1439,10 @@ static struct ib_qp *nes_create_qp(struct ib_pd *ibpd,
1504 } else { 1439 } else {
1505 return ERR_PTR(-EIO); 1440 return ERR_PTR(-EIO);
1506 } 1441 }
1507 } else {
1508 if (atomic_dec_and_test(&cqp_request->refcount)) {
1509 if (cqp_request->dynamic) {
1510 kfree(cqp_request);
1511 } else {
1512 spin_lock_irqsave(&nesdev->cqp.lock, flags);
1513 list_add_tail(&cqp_request->list, &nesdev->cqp_avail_reqs);
1514 spin_unlock_irqrestore(&nesdev->cqp.lock, flags);
1515 }
1516 }
1517 } 1442 }
1518 1443
1444 nes_put_cqp_request(nesdev, cqp_request);
1445
1519 if (ibpd->uobject) { 1446 if (ibpd->uobject) {
1520 uresp.mmap_sq_db_index = nesqp->mmap_sq_db_index; 1447 uresp.mmap_sq_db_index = nesqp->mmap_sq_db_index;
1521 uresp.actual_sq_size = sq_size; 1448 uresp.actual_sq_size = sq_size;
@@ -1827,32 +1754,15 @@ static struct ib_cq *nes_create_cq(struct ib_device *ibdev, int entries,
1827 nes_debug(NES_DBG_CQ, "Create iWARP CQ%u completed, wait_event_timeout ret = %d.\n", 1754 nes_debug(NES_DBG_CQ, "Create iWARP CQ%u completed, wait_event_timeout ret = %d.\n",
1828 nescq->hw_cq.cq_number, ret); 1755 nescq->hw_cq.cq_number, ret);
1829 if ((!ret) || (cqp_request->major_code)) { 1756 if ((!ret) || (cqp_request->major_code)) {
1830 if (atomic_dec_and_test(&cqp_request->refcount)) { 1757 nes_put_cqp_request(nesdev, cqp_request);
1831 if (cqp_request->dynamic) {
1832 kfree(cqp_request);
1833 } else {
1834 spin_lock_irqsave(&nesdev->cqp.lock, flags);
1835 list_add_tail(&cqp_request->list, &nesdev->cqp_avail_reqs);
1836 spin_unlock_irqrestore(&nesdev->cqp.lock, flags);
1837 }
1838 }
1839 if (!context) 1758 if (!context)
1840 pci_free_consistent(nesdev->pcidev, nescq->cq_mem_size, mem, 1759 pci_free_consistent(nesdev->pcidev, nescq->cq_mem_size, mem,
1841 nescq->hw_cq.cq_pbase); 1760 nescq->hw_cq.cq_pbase);
1842 nes_free_resource(nesadapter, nesadapter->allocated_cqs, cq_num); 1761 nes_free_resource(nesadapter, nesadapter->allocated_cqs, cq_num);
1843 kfree(nescq); 1762 kfree(nescq);
1844 return ERR_PTR(-EIO); 1763 return ERR_PTR(-EIO);
1845 } else {
1846 if (atomic_dec_and_test(&cqp_request->refcount)) {
1847 if (cqp_request->dynamic) {
1848 kfree(cqp_request);
1849 } else {
1850 spin_lock_irqsave(&nesdev->cqp.lock, flags);
1851 list_add_tail(&cqp_request->list, &nesdev->cqp_avail_reqs);
1852 spin_unlock_irqrestore(&nesdev->cqp.lock, flags);
1853 }
1854 }
1855 } 1764 }
1765 nes_put_cqp_request(nesdev, cqp_request);
1856 1766
1857 if (context) { 1767 if (context) {
1858 /* free the nespbl */ 1768 /* free the nespbl */
@@ -1942,37 +1852,18 @@ static int nes_destroy_cq(struct ib_cq *ib_cq)
1942 " CQP Major:Minor codes = 0x%04X:0x%04X.\n", 1852 " CQP Major:Minor codes = 0x%04X:0x%04X.\n",
1943 nescq->hw_cq.cq_number, ret, cqp_request->major_code, 1853 nescq->hw_cq.cq_number, ret, cqp_request->major_code,
1944 cqp_request->minor_code); 1854 cqp_request->minor_code);
1945 if ((!ret) || (cqp_request->major_code)) { 1855 if (!ret) {
1946 if (atomic_dec_and_test(&cqp_request->refcount)) { 1856 nes_debug(NES_DBG_CQ, "iWARP CQ%u destroy timeout expired\n",
1947 if (cqp_request->dynamic) {
1948 kfree(cqp_request);
1949 } else {
1950 spin_lock_irqsave(&nesdev->cqp.lock, flags);
1951 list_add_tail(&cqp_request->list, &nesdev->cqp_avail_reqs);
1952 spin_unlock_irqrestore(&nesdev->cqp.lock, flags);
1953 }
1954 }
1955 if (!ret) {
1956 nes_debug(NES_DBG_CQ, "iWARP CQ%u destroy timeout expired\n",
1957 nescq->hw_cq.cq_number); 1857 nescq->hw_cq.cq_number);
1958 ret = -ETIME; 1858 ret = -ETIME;
1959 } else { 1859 } else if (cqp_request->major_code) {
1960 nes_debug(NES_DBG_CQ, "iWARP CQ%u destroy failed\n", 1860 nes_debug(NES_DBG_CQ, "iWARP CQ%u destroy failed\n",
1961 nescq->hw_cq.cq_number); 1861 nescq->hw_cq.cq_number);
1962 ret = -EIO; 1862 ret = -EIO;
1963 }
1964 } else { 1863 } else {
1965 ret = 0; 1864 ret = 0;
1966 if (atomic_dec_and_test(&cqp_request->refcount)) {
1967 if (cqp_request->dynamic) {
1968 kfree(cqp_request);
1969 } else {
1970 spin_lock_irqsave(&nesdev->cqp.lock, flags);
1971 list_add_tail(&cqp_request->list, &nesdev->cqp_avail_reqs);
1972 spin_unlock_irqrestore(&nesdev->cqp.lock, flags);
1973 }
1974 }
1975 } 1865 }
1866 nes_put_cqp_request(nesdev, cqp_request);
1976 1867
1977 if (nescq->cq_mem_size) 1868 if (nescq->cq_mem_size)
1978 pci_free_consistent(nesdev->pcidev, nescq->cq_mem_size, 1869 pci_free_consistent(nesdev->pcidev, nescq->cq_mem_size,
@@ -2105,15 +1996,8 @@ static int nes_reg_mr(struct nes_device *nesdev, struct nes_pd *nespd,
2105 " CQP Major:Minor codes = 0x%04X:0x%04X.\n", 1996 " CQP Major:Minor codes = 0x%04X:0x%04X.\n",
2106 stag, ret, cqp_request->major_code, cqp_request->minor_code); 1997 stag, ret, cqp_request->major_code, cqp_request->minor_code);
2107 major_code = cqp_request->major_code; 1998 major_code = cqp_request->major_code;
2108 if (atomic_dec_and_test(&cqp_request->refcount)) { 1999 nes_put_cqp_request(nesdev, cqp_request);
2109 if (cqp_request->dynamic) { 2000
2110 kfree(cqp_request);
2111 } else {
2112 spin_lock_irqsave(&nesdev->cqp.lock, flags);
2113 list_add_tail(&cqp_request->list, &nesdev->cqp_avail_reqs);
2114 spin_unlock_irqrestore(&nesdev->cqp.lock, flags);
2115 }
2116 }
2117 if (!ret) 2001 if (!ret)
2118 return -ETIME; 2002 return -ETIME;
2119 else if (major_code) 2003 else if (major_code)
@@ -2771,15 +2655,9 @@ static int nes_dereg_mr(struct ib_mr *ib_mr)
2771 2655
2772 major_code = cqp_request->major_code; 2656 major_code = cqp_request->major_code;
2773 minor_code = cqp_request->minor_code; 2657 minor_code = cqp_request->minor_code;
2774 if (atomic_dec_and_test(&cqp_request->refcount)) { 2658
2775 if (cqp_request->dynamic) { 2659 nes_put_cqp_request(nesdev, cqp_request);
2776 kfree(cqp_request); 2660
2777 } else {
2778 spin_lock_irqsave(&nesdev->cqp.lock, flags);
2779 list_add_tail(&cqp_request->list, &nesdev->cqp_avail_reqs);
2780 spin_unlock_irqrestore(&nesdev->cqp.lock, flags);
2781 }
2782 }
2783 if (!ret) { 2661 if (!ret) {
2784 nes_debug(NES_DBG_MR, "Timeout waiting to destroy STag," 2662 nes_debug(NES_DBG_MR, "Timeout waiting to destroy STag,"
2785 " ib_mr=%p, rkey = 0x%08X\n", 2663 " ib_mr=%p, rkey = 0x%08X\n",
@@ -2904,7 +2782,6 @@ int nes_hw_modify_qp(struct nes_device *nesdev, struct nes_qp *nesqp,
2904 /* struct iw_cm_id *cm_id = nesqp->cm_id; */ 2782 /* struct iw_cm_id *cm_id = nesqp->cm_id; */
2905 /* struct iw_cm_event cm_event; */ 2783 /* struct iw_cm_event cm_event; */
2906 struct nes_cqp_request *cqp_request; 2784 struct nes_cqp_request *cqp_request;
2907 unsigned long flags;
2908 int ret; 2785 int ret;
2909 u16 major_code; 2786 u16 major_code;
2910 2787
@@ -2950,15 +2827,9 @@ int nes_hw_modify_qp(struct nes_device *nesdev, struct nes_qp *nesqp,
2950 nesqp->hwqp.qp_id, cqp_request->major_code, 2827 nesqp->hwqp.qp_id, cqp_request->major_code,
2951 cqp_request->minor_code, next_iwarp_state); 2828 cqp_request->minor_code, next_iwarp_state);
2952 } 2829 }
2953 if (atomic_dec_and_test(&cqp_request->refcount)) { 2830
2954 if (cqp_request->dynamic) { 2831 nes_put_cqp_request(nesdev, cqp_request);
2955 kfree(cqp_request); 2832
2956 } else {
2957 spin_lock_irqsave(&nesdev->cqp.lock, flags);
2958 list_add_tail(&cqp_request->list, &nesdev->cqp_avail_reqs);
2959 spin_unlock_irqrestore(&nesdev->cqp.lock, flags);
2960 }
2961 }
2962 if (!ret) 2833 if (!ret)
2963 return -ETIME; 2834 return -ETIME;
2964 else if (major_code) 2835 else if (major_code)