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>
Este commit está contenido en:
@@ -2710,39 +2710,11 @@ static void nes_cqp_ce_handler(struct nes_device *nesdev, struct nes_hw_cq *cq)
|
||||
barrier();
|
||||
cqp_request->request_done = 1;
|
||||
wake_up(&cqp_request->waitq);
|
||||
if (atomic_dec_and_test(&cqp_request->refcount)) {
|
||||
nes_debug(NES_DBG_CQP, "CQP request %p (opcode 0x%02X) freed.\n",
|
||||
cqp_request,
|
||||
le32_to_cpu(cqp_request->cqp_wqe.wqe_words[NES_CQP_WQE_OPCODE_IDX])&0x3f);
|
||||
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);
|
||||
}
|
||||
}
|
||||
} else if (cqp_request->callback) {
|
||||
/* Envoke the callback routine */
|
||||
cqp_request->cqp_callback(nesdev, cqp_request);
|
||||
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);
|
||||
}
|
||||
nes_put_cqp_request(nesdev, cqp_request);
|
||||
} else {
|
||||
nes_debug(NES_DBG_CQP, "CQP request %p (opcode 0x%02X) freed.\n",
|
||||
cqp_request,
|
||||
le32_to_cpu(cqp_request->cqp_wqe.wqe_words[NES_CQP_WQE_OPCODE_IDX]) & 0x3f);
|
||||
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);
|
||||
}
|
||||
if (cqp_request->callback)
|
||||
cqp_request->cqp_callback(nesdev, cqp_request);
|
||||
nes_free_cqp_request(nesdev, cqp_request);
|
||||
}
|
||||
} else {
|
||||
wake_up(&nesdev->cqp.waitq);
|
||||
@@ -3149,7 +3121,6 @@ int nes_manage_apbvt(struct nes_vnic *nesvnic, u32 accel_local_port,
|
||||
{
|
||||
struct nes_device *nesdev = nesvnic->nesdev;
|
||||
struct nes_hw_cqp_wqe *cqp_wqe;
|
||||
unsigned long flags;
|
||||
struct nes_cqp_request *cqp_request;
|
||||
int ret = 0;
|
||||
u16 major_code;
|
||||
@@ -3184,15 +3155,9 @@ int nes_manage_apbvt(struct nes_vnic *nesvnic, u32 accel_local_port,
|
||||
nes_debug(NES_DBG_QP, "Completed, ret=%u, CQP Major:Minor codes = 0x%04X:0x%04X\n",
|
||||
ret, cqp_request->major_code, cqp_request->minor_code);
|
||||
major_code = cqp_request->major_code;
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
nes_put_cqp_request(nesdev, cqp_request);
|
||||
|
||||
if (!ret)
|
||||
return -ETIME;
|
||||
else if (major_code)
|
||||
@@ -3262,7 +3227,6 @@ void nes_manage_arp_cache(struct net_device *netdev, unsigned char *mac_addr,
|
||||
void flush_wqes(struct nes_device *nesdev, struct nes_qp *nesqp,
|
||||
u32 which_wq, u32 wait_completion)
|
||||
{
|
||||
unsigned long flags;
|
||||
struct nes_cqp_request *cqp_request;
|
||||
struct nes_hw_cqp_wqe *cqp_wqe;
|
||||
int ret;
|
||||
@@ -3294,14 +3258,6 @@ void flush_wqes(struct nes_device *nesdev, struct nes_qp *nesqp,
|
||||
nes_debug(NES_DBG_QP, "Flush SQ QP WQEs completed, ret=%u,"
|
||||
" CQP Major:Minor codes = 0x%04X:0x%04X\n",
|
||||
ret, cqp_request->major_code, cqp_request->minor_code);
|
||||
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);
|
||||
}
|
||||
}
|
||||
nes_put_cqp_request(nesdev, cqp_request);
|
||||
}
|
||||
}
|
||||
|
Referencia en una nueva incidencia
Block a user