From patchwork Tue Mar 31 16:45:56 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sagi Grimberg X-Patchwork-Id: 6132481 Return-Path: X-Original-To: patchwork-linux-rdma@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork1.web.kernel.org (Postfix) with ESMTP id EF9509F32E for ; Tue, 31 Mar 2015 16:46:25 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 145B9200E3 for ; Tue, 31 Mar 2015 16:46:25 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 091A9201C0 for ; Tue, 31 Mar 2015 16:46:24 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1755359AbbCaQqT (ORCPT ); Tue, 31 Mar 2015 12:46:19 -0400 Received: from mailp.voltaire.com ([193.47.165.129]:39659 "EHLO mellanox.co.il" rhost-flags-OK-FAIL-OK-FAIL) by vger.kernel.org with ESMTP id S1755347AbbCaQqL (ORCPT ); Tue, 31 Mar 2015 12:46:11 -0400 Received: from Internal Mail-Server by MTLPINE1 (envelope-from sagig@mellanox.com) with ESMTPS (AES256-SHA encrypted); 31 Mar 2015 19:46:06 +0300 Received: from r-vnc05.mtr.labs.mlnx (r-vnc05.mtr.labs.mlnx [10.208.0.115]) by labmailer.mlnx (8.13.8/8.13.8) with ESMTP id t2VGk68i025148; Tue, 31 Mar 2015 19:46:06 +0300 Received: from r-vnc05.mtr.labs.mlnx (localhost [127.0.0.1]) by r-vnc05.mtr.labs.mlnx (8.14.4/8.14.4) with ESMTP id t2VGk5MG015225; Tue, 31 Mar 2015 19:46:05 +0300 Received: (from sagig@localhost) by r-vnc05.mtr.labs.mlnx (8.14.4/8.14.4/Submit) id t2VGk5MC015224; Tue, 31 Mar 2015 19:46:05 +0300 From: Sagi Grimberg To: Roland Dreier Cc: linux-rdma@vger.kernel.org, Or Gerlitz Subject: [PATCH v2 16/18] IB/iser: Remove code duplication for a single DMA entry Date: Tue, 31 Mar 2015 19:45:56 +0300 Message-Id: <1427820358-15087-17-git-send-email-sagig@mellanox.com> X-Mailer: git-send-email 1.8.4.3 In-Reply-To: <1427820358-15087-1-git-send-email-sagig@mellanox.com> References: <1427820358-15087-1-git-send-email-sagig@mellanox.com> Sender: linux-rdma-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-rdma@vger.kernel.org X-Spam-Status: No, score=-6.9 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, T_RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP In singleton scatterlists, DMA memory registration code is taken both for Fastreg and FMR code paths. Move it to a function. This patch does not change any functionality. Signed-off-by: Sagi Grimberg Signed-off-by: Adir Lev --- drivers/infiniband/ulp/iser/iser_memory.c | 48 ++++++++++++---------------- 1 files changed, 21 insertions(+), 27 deletions(-) diff --git a/drivers/infiniband/ulp/iser/iser_memory.c b/drivers/infiniband/ulp/iser/iser_memory.c index b4b0098..e78ce53 100644 --- a/drivers/infiniband/ulp/iser/iser_memory.c +++ b/drivers/infiniband/ulp/iser/iser_memory.c @@ -334,6 +334,24 @@ void iser_dma_unmap_task_data(struct iscsi_iser_task *iser_task, ib_dma_unmap_sg(dev, data->sg, data->size, dir); } +static int +iser_reg_dma(struct iser_device *device, struct iser_data_buf *mem, + struct iser_mem_reg *reg) +{ + struct scatterlist *sg = mem->sg; + + reg->sge.lkey = device->mr->lkey; + reg->rkey = device->mr->rkey; + reg->sge.addr = ib_sg_dma_address(device->ib_device, &sg[0]); + reg->sge.length = ib_sg_dma_len(device->ib_device, &sg[0]); + + iser_dbg("Single DMA entry: lkey=0x%x, rkey=0x%x, addr=0x%llx," + " length=0x%x\n", reg->sge.lkey, reg->rkey, + reg->sge.addr, reg->sge.length); + + return 0; +} + static int fall_to_bounce_buf(struct iscsi_iser_task *iser_task, struct iser_data_buf *mem, enum iser_data_dir cmd_dir, @@ -461,7 +479,6 @@ int iser_reg_rdma_mem_fmr(struct iscsi_iser_task *iser_task, int aligned_len; int err; int i; - struct scatterlist *sg; mem_reg = &iser_task->rdma_reg[cmd_dir]; @@ -477,19 +494,7 @@ int iser_reg_rdma_mem_fmr(struct iscsi_iser_task *iser_task, /* if there a single dma entry, FMR is not needed */ if (mem->dma_nents == 1) { - sg = mem->sg; - - mem_reg->sge.lkey = device->mr->lkey; - mem_reg->rkey = device->mr->rkey; - mem_reg->sge.length = ib_sg_dma_len(ibdev, &sg[0]); - mem_reg->sge.addr = ib_sg_dma_address(ibdev, &sg[0]); - - iser_dbg("PHYSICAL Mem.register: lkey: 0x%08X rkey: 0x%08X " - "va: 0x%08lX sz: %ld]\n", - (unsigned int)mem_reg->sge.lkey, - (unsigned int)mem_reg->rkey, - (unsigned long)mem_reg->sge.addr, - (unsigned long)mem_reg->sge.length); + return iser_reg_dma(device, mem, mem_reg); } else { /* use FMR for multiple dma entries */ err = iser_reg_page_vec(iser_task, mem, ib_conn->fmr.page_vec, mem_reg); @@ -660,7 +665,6 @@ static int iser_fast_reg_mr(struct iscsi_iser_task *iser_task, struct fast_reg_descriptor *desc = mem_reg->mem_h; struct ib_conn *ib_conn = &iser_task->iser_conn->ib_conn; struct iser_device *device = ib_conn->device; - struct ib_device *ibdev = device->ib_device; struct ib_mr *mr; struct ib_fast_reg_page_list *frpl; struct ib_send_wr fastreg_wr, inv_wr; @@ -668,18 +672,8 @@ static int iser_fast_reg_mr(struct iscsi_iser_task *iser_task, int ret, offset, size, plen; /* if there a single dma entry, dma mr suffices */ - if (mem->dma_nents == 1) { - struct scatterlist *sg = mem->sg; - - reg->sge.lkey = device->mr->lkey; - reg->rkey = device->mr->rkey; - reg->sge.addr = ib_sg_dma_address(ibdev, &sg[0]); - reg->sge.length = ib_sg_dma_len(ibdev, &sg[0]); - - iser_dbg("Single DMA entry: lkey=0x%x, addr=0x%llx, length=0x%x\n", - reg->sge.lkey, reg->sge.addr, reg->sge.length); - return 0; - } + if (mem->dma_nents == 1) + return iser_reg_dma(device, mem, mem_reg); if (ind == ISER_DATA_KEY_VALID) { mr = desc->data_mr;