From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mx0a-001b2d01.pphosted.com (mx0b-001b2d01.pphosted.com [148.163.158.5]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by lists.ozlabs.org (Postfix) with ESMTPS id 3vl2G524mfzDq5W for ; Fri, 17 Mar 2017 21:51:40 +1100 (AEDT) Received: from pps.filterd (m0098413.ppops.net [127.0.0.1]) by mx0b-001b2d01.pphosted.com (8.16.0.20/8.16.0.20) with SMTP id v2HAnAjW020753 for ; Fri, 17 Mar 2017 06:51:36 -0400 Received: from e06smtp12.uk.ibm.com (e06smtp12.uk.ibm.com [195.75.94.108]) by mx0b-001b2d01.pphosted.com with ESMTP id 297ym5h4hr-1 (version=TLSv1.2 cipher=AES256-SHA bits=256 verify=NOT) for ; Fri, 17 Mar 2017 06:51:35 -0400 Received: from localhost by e06smtp12.uk.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Fri, 17 Mar 2017 10:51:34 -0000 Subject: Re: [PATCH 1/3] cxl: Re-factor cxl_pci_afu_read_err_buffer() To: Vaibhav Jain , linuxppc-dev@lists.ozlabs.org References: <20170314040606.16894-1-vaibhav@linux.vnet.ibm.com> <20170314040606.16894-2-vaibhav@linux.vnet.ibm.com> Cc: Andrew Donnellan , Ian Munsie , Christophe Lombard , Philippe Bergheaud , Greg Kurz From: Frederic Barrat Date: Fri, 17 Mar 2017 11:51:03 +0100 MIME-Version: 1.0 In-Reply-To: <20170314040606.16894-2-vaibhav@linux.vnet.ibm.com> Content-Type: text/plain; charset=windows-1252; format=flowed Message-Id: List-Id: Linux on PowerPC Developers Mail List List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Le 14/03/2017 à 05:06, Vaibhav Jain a écrit : > This patch moves,renames and re-factors the function > afu_pci_afu_err_buffer(). The function is now moved to native.c from > pci.c and renamed as native_afu_read_err_buffer(). > > Also the ability of copying data from h/w enforcing 4/8 byte aligned > access is useful and better shared across other functions. So this > patch moves the core logic of existing cxl_pci_afu_read_err_buffer() > to a new function named __aligned_memcpy().The new implementation of > native_afu_read_err_buffer() is simply a call to __aligned_memcpy() > with appropriate actual parameters. > > Signed-off-by: Vaibhav Jain > --- Acked-by: Frederic Barrat > drivers/misc/cxl/cxl.h | 3 --- > drivers/misc/cxl/native.c | 56 ++++++++++++++++++++++++++++++++++++++++++++++- > drivers/misc/cxl/pci.c | 44 ------------------------------------- > 3 files changed, 55 insertions(+), 48 deletions(-) > > diff --git a/drivers/misc/cxl/cxl.h b/drivers/misc/cxl/cxl.h > index 79e60ec..ef683b7 100644 > --- a/drivers/misc/cxl/cxl.h > +++ b/drivers/misc/cxl/cxl.h > @@ -739,9 +739,6 @@ static inline u64 cxl_p2n_read(struct cxl_afu *afu, cxl_p2n_reg_t reg) > return ~0ULL; > } > > -ssize_t cxl_pci_afu_read_err_buffer(struct cxl_afu *afu, char *buf, > - loff_t off, size_t count); > - > /* Internal functions wrapped in cxl_base to allow PHB to call them */ > bool _cxl_pci_associate_default_context(struct pci_dev *dev, struct cxl_afu *afu); > void _cxl_pci_disable_device(struct pci_dev *dev); > diff --git a/drivers/misc/cxl/native.c b/drivers/misc/cxl/native.c > index 7ae7105..20d3df6 100644 > --- a/drivers/misc/cxl/native.c > +++ b/drivers/misc/cxl/native.c > @@ -1276,6 +1276,60 @@ static int native_afu_cr_write8(struct cxl_afu *afu, int cr, u64 off, u8 in) > return rc; > } > > +#define ERR_BUFF_MAX_COPY_SIZE PAGE_SIZE > + > +/* > + * __aligned_memcpy: > + * Copies count or max_read bytes (whichever is smaller) from src to dst buffer > + * starting at offset off in src buffer. This specialized implementation of > + * memcpy_fromio is needed as capi h/w only supports 4/8 bytes aligned access. > + * So in case the requested offset/count arent 8 byte aligned the function uses > + * a bounce buffer which can be max ERR_BUFF_MAX_COPY_SIZE == PAGE_SIZE > + */ > +static ssize_t __aligned_memcpy(void *dst, void __iomem *src, loff_t off, > + size_t count, size_t max_read) > +{ > + loff_t aligned_start, aligned_end; > + size_t aligned_length; > + void *tbuf; > + > + if (count == 0 || off < 0 || (size_t)off >= max_read) > + return 0; > + > + /* calculate aligned read window */ > + count = min((size_t)(max_read - off), count); > + aligned_start = round_down(off, 8); > + aligned_end = round_up(off + count, 8); > + aligned_length = aligned_end - aligned_start; > + > + /* max we can copy in one read is PAGE_SIZE */ > + if (aligned_length > ERR_BUFF_MAX_COPY_SIZE) { > + aligned_length = ERR_BUFF_MAX_COPY_SIZE; > + count = ERR_BUFF_MAX_COPY_SIZE - (off & 0x7); > + } > + > + /* use bounce buffer for copy */ > + tbuf = (void *)__get_free_page(GFP_TEMPORARY); > + if (!tbuf) > + return -ENOMEM; > + > + /* perform aligned read from the mmio region */ > + memcpy_fromio(tbuf, src + aligned_start, aligned_length); > + memcpy(dst, tbuf + (off & 0x7), count); > + > + free_page((unsigned long)tbuf); > + > + return count; > +} > + > +static ssize_t native_afu_read_err_buffer(struct cxl_afu *afu, char *buf, > + loff_t off, size_t count) > +{ > + void __iomem *ebuf = afu->native->afu_desc_mmio + afu->eb_offset; > + > + return __aligned_memcpy(buf, ebuf, off, count, afu->eb_len); > +} > + > const struct cxl_backend_ops cxl_native_ops = { > .module = THIS_MODULE, > .adapter_reset = cxl_pci_reset, > @@ -1294,7 +1348,7 @@ const struct cxl_backend_ops cxl_native_ops = { > .support_attributes = native_support_attributes, > .link_ok = cxl_adapter_link_ok, > .release_afu = cxl_pci_release_afu, > - .afu_read_err_buffer = cxl_pci_afu_read_err_buffer, > + .afu_read_err_buffer = native_afu_read_err_buffer, > .afu_check_and_enable = native_afu_check_and_enable, > .afu_activate_mode = native_afu_activate_mode, > .afu_deactivate_mode = native_afu_deactivate_mode, > diff --git a/drivers/misc/cxl/pci.c b/drivers/misc/cxl/pci.c > index 91f6459..541dc9a 100644 > --- a/drivers/misc/cxl/pci.c > +++ b/drivers/misc/cxl/pci.c > @@ -1051,50 +1051,6 @@ static int sanitise_afu_regs(struct cxl_afu *afu) > return 0; > } > > -#define ERR_BUFF_MAX_COPY_SIZE PAGE_SIZE > -/* > - * afu_eb_read: > - * Called from sysfs and reads the afu error info buffer. The h/w only supports > - * 4/8 bytes aligned access. So in case the requested offset/count arent 8 byte > - * aligned the function uses a bounce buffer which can be max PAGE_SIZE. > - */ > -ssize_t cxl_pci_afu_read_err_buffer(struct cxl_afu *afu, char *buf, > - loff_t off, size_t count) > -{ > - loff_t aligned_start, aligned_end; > - size_t aligned_length; > - void *tbuf; > - const void __iomem *ebuf = afu->native->afu_desc_mmio + afu->eb_offset; > - > - if (count == 0 || off < 0 || (size_t)off >= afu->eb_len) > - return 0; > - > - /* calculate aligned read window */ > - count = min((size_t)(afu->eb_len - off), count); > - aligned_start = round_down(off, 8); > - aligned_end = round_up(off + count, 8); > - aligned_length = aligned_end - aligned_start; > - > - /* max we can copy in one read is PAGE_SIZE */ > - if (aligned_length > ERR_BUFF_MAX_COPY_SIZE) { > - aligned_length = ERR_BUFF_MAX_COPY_SIZE; > - count = ERR_BUFF_MAX_COPY_SIZE - (off & 0x7); > - } > - > - /* use bounce buffer for copy */ > - tbuf = (void *)__get_free_page(GFP_TEMPORARY); > - if (!tbuf) > - return -ENOMEM; > - > - /* perform aligned read from the mmio region */ > - memcpy_fromio(tbuf, ebuf + aligned_start, aligned_length); > - memcpy(buf, tbuf + (off & 0x7), count); > - > - free_page((unsigned long)tbuf); > - > - return count; > -} > - > static int pci_configure_afu(struct cxl_afu *afu, struct cxl *adapter, struct pci_dev *dev) > { > int rc; >