Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1756127AbdDMWRG (ORCPT ); Thu, 13 Apr 2017 18:17:06 -0400 Received: from ale.deltatee.com ([207.54.116.67]:38185 "EHLO ale.deltatee.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752853AbdDMWG1 (ORCPT ); Thu, 13 Apr 2017 18:06:27 -0400 From: Logan Gunthorpe To: Christoph Hellwig , "Martin K. Petersen" , Sagi Grimberg , Jens Axboe , Tejun Heo , Greg Kroah-Hartman , Dan Williams , Ross Zwisler , Matthew Wilcox , Sumit Semwal , Ming Lin , linux-kernel@vger.kernel.org, linux-crypto@vger.kernel.org, linux-media@vger.kernel.org, dri-devel@lists.freedesktop.org, linaro-mm-sig@lists.linaro.org, intel-gfx@lists.freedesktop.org, linux-raid@vger.kernel.org, linux-mmc@vger.kernel.org, linux-nvme@lists.infradead.org, linux-nvdimm@ml01.01.org, linux-scsi@vger.kernel.org, fcoe-devel@open-fcoe.org, open-iscsi@googlegroups.com, megaraidlinux.pdl@broadcom.com, sparmaintainer@unisys.com, devel@driverdev.osuosl.org, target-devel@vger.kernel.org, netdev@vger.kernel.org, linux-rdma@vger.kernel.org, rds-devel@oss.oracle.com Cc: Steve Wise , Stephen Bates , Logan Gunthorpe Date: Thu, 13 Apr 2017 16:05:28 -0600 Message-Id: <1492121135-4437-16-git-send-email-logang@deltatee.com> X-Mailer: git-send-email 2.1.4 In-Reply-To: <1492121135-4437-1-git-send-email-logang@deltatee.com> References: <1492121135-4437-1-git-send-email-logang@deltatee.com> X-SA-Exim-Connect-IP: 172.16.1.31 X-SA-Exim-Rcpt-To: hch@lst.de, martin.petersen@oracle.com, sagi@grimberg.me, axboe@kernel.dk, tj@kernel.org, gregkh@linuxfoundation.org, dan.j.williams@intel.com, ross.zwisler@linux.intel.com, mawilcox@microsoft.com, sumit.semwal@linaro.org, ming.l@ssi.samsung.com, linaro-mm-sig@lists.linaro.org, dri-devel@lists.freedesktop.org, intel-gfx@lists.freedesktop.org, linux-nvme@lists.infradead.org, linux-nvdimm@lists.01.org, fcoe-devel@open-fcoe.org, open-iscsi@googlegroups.com, megaraidlinux.pdl@broadcom.com, sparmaintainer@unisys.com, devel@driverdev.osuosl.org, linux-kernel@vger.kernel.org, linux-crypto@vger.kernel.org, linux-media@vger.kernel.org, linux-raid@vger.kernel.org, linux-mmc@vger.kernel.org, linux-scsi@vger.kernel.org, target-devel@vger.kernel.org, netdev@vger.kernel.org, linux-rdma@vger.kernel.org, rds-devel@oss.oracle.com, swise@opengridcomputing.com, sbates@raithlin.com, logang@deltatee.com X-SA-Exim-Mail-From: gunthorp@deltatee.com Subject: [PATCH 15/22] scsi: libfc, csiostor: Change to sg_copy_buffer in two drivers X-SA-Exim-Version: 4.2.1 (built Mon, 26 Dec 2011 16:24:06 +0000) X-SA-Exim-Scanned: Yes (on ale.deltatee.com) Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 4011 Lines: 143 These two drivers appear to duplicate the functionality of sg_copy_buffer. So we clean them up to use the common code. This helps us remove a couple of instances that would otherwise be slightly tricky sg_map usages. Signed-off-by: Logan Gunthorpe --- drivers/scsi/csiostor/csio_scsi.c | 54 +++------------------------------------ drivers/scsi/libfc/fc_libfc.c | 49 ++++++++--------------------------- 2 files changed, 14 insertions(+), 89 deletions(-) diff --git a/drivers/scsi/csiostor/csio_scsi.c b/drivers/scsi/csiostor/csio_scsi.c index a1ff75f..bd9d062 100644 --- a/drivers/scsi/csiostor/csio_scsi.c +++ b/drivers/scsi/csiostor/csio_scsi.c @@ -1489,60 +1489,14 @@ static inline uint32_t csio_scsi_copy_to_sgl(struct csio_hw *hw, struct csio_ioreq *req) { struct scsi_cmnd *scmnd = (struct scsi_cmnd *)csio_scsi_cmnd(req); - struct scatterlist *sg; - uint32_t bytes_left; - uint32_t bytes_copy; - uint32_t buf_off = 0; - uint32_t start_off = 0; - uint32_t sg_off = 0; - void *sg_addr; - void *buf_addr; struct csio_dma_buf *dma_buf; + size_t copied; - bytes_left = scsi_bufflen(scmnd); - sg = scsi_sglist(scmnd); dma_buf = (struct csio_dma_buf *)csio_list_next(&req->gen_list); + copied = sg_copy_from_buffer(scsi_sglist(scmnd), scsi_sg_count(scmnd), + dma_buf->vaddr, scsi_bufflen(scmnd)); - /* Copy data from driver buffer to SGs of SCSI CMD */ - while (bytes_left > 0 && sg && dma_buf) { - if (buf_off >= dma_buf->len) { - buf_off = 0; - dma_buf = (struct csio_dma_buf *) - csio_list_next(dma_buf); - continue; - } - - if (start_off >= sg->length) { - start_off -= sg->length; - sg = sg_next(sg); - continue; - } - - buf_addr = dma_buf->vaddr + buf_off; - sg_off = sg->offset + start_off; - bytes_copy = min((dma_buf->len - buf_off), - sg->length - start_off); - bytes_copy = min((uint32_t)(PAGE_SIZE - (sg_off & ~PAGE_MASK)), - bytes_copy); - - sg_addr = kmap_atomic(sg_page(sg) + (sg_off >> PAGE_SHIFT)); - if (!sg_addr) { - csio_err(hw, "failed to kmap sg:%p of ioreq:%p\n", - sg, req); - break; - } - - csio_dbg(hw, "copy_to_sgl:sg_addr %p sg_off %d buf %p len %d\n", - sg_addr, sg_off, buf_addr, bytes_copy); - memcpy(sg_addr + (sg_off & ~PAGE_MASK), buf_addr, bytes_copy); - kunmap_atomic(sg_addr); - - start_off += bytes_copy; - buf_off += bytes_copy; - bytes_left -= bytes_copy; - } - - if (bytes_left > 0) + if (copied != scsi_bufflen(scmnd)) return DID_ERROR; else return DID_OK; diff --git a/drivers/scsi/libfc/fc_libfc.c b/drivers/scsi/libfc/fc_libfc.c index d623d08..ce0805a 100644 --- a/drivers/scsi/libfc/fc_libfc.c +++ b/drivers/scsi/libfc/fc_libfc.c @@ -113,45 +113,16 @@ u32 fc_copy_buffer_to_sglist(void *buf, size_t len, u32 *nents, size_t *offset, u32 *crc) { - size_t remaining = len; - u32 copy_len = 0; - - while (remaining > 0 && sg) { - size_t off, sg_bytes; - void *page_addr; - - if (*offset >= sg->length) { - /* - * Check for end and drop resources - * from the last iteration. - */ - if (!(*nents)) - break; - --(*nents); - *offset -= sg->length; - sg = sg_next(sg); - continue; - } - sg_bytes = min(remaining, sg->length - *offset); - - /* - * The scatterlist item may be bigger than PAGE_SIZE, - * but we are limited to mapping PAGE_SIZE at a time. - */ - off = *offset + sg->offset; - sg_bytes = min(sg_bytes, - (size_t)(PAGE_SIZE - (off & ~PAGE_MASK))); - page_addr = kmap_atomic(sg_page(sg) + (off >> PAGE_SHIFT)); - if (crc) - *crc = crc32(*crc, buf, sg_bytes); - memcpy((char *)page_addr + (off & ~PAGE_MASK), buf, sg_bytes); - kunmap_atomic(page_addr); - buf += sg_bytes; - *offset += sg_bytes; - remaining -= sg_bytes; - copy_len += sg_bytes; - } - return copy_len; + size_t copied; + + copied = sg_pcopy_from_buffer(sg, sg_nents(sg), + buf, len, *offset); + + *offset += copied; + if (crc) + *crc = crc32(*crc, buf, copied); + + return copied; } /** -- 2.1.4