Received: by 2002:a05:6358:11c7:b0:104:8066:f915 with SMTP id i7csp2505244rwl; Sat, 1 Apr 2023 08:56:56 -0700 (PDT) X-Google-Smtp-Source: AKy350Yog705Bla/QhPn849Iuo4p4NjKF2yxuzBrp0mP1tDqVzwc9IIuKW671hRsAgz5ODoigR8V X-Received: by 2002:a17:90b:1d8e:b0:23f:37b6:48f4 with SMTP id pf14-20020a17090b1d8e00b0023f37b648f4mr34092659pjb.43.1680364616269; Sat, 01 Apr 2023 08:56:56 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1680364616; cv=none; d=google.com; s=arc-20160816; b=PjEdOL3FpM2bsBZst5M+q56V5goeScJeNhxnRxRn+wajvad8W9lW0fq7QO07wcxQ9K H/jkOkEGwmEUNstckKHeHY3r6lLtnOUntCv0jE7FMWosltemRgBTA2LFv/vzb2xMxhx4 JeAfJwiKdjEwGlqx/UBGZ6XNYUQC7Hr8eunvmLI+x1ZBxlJnPdcDjFXPYzkgsT3pfugW v87vRqowNXRv/uvNiz08IedPK39UhxRfF9jh8qaFepRfKEn+xIOJM9fUPxkKRTOXABZ4 1jYcS0hCF0EwJBacpt0g7SIMsLibd/Rxh+jpxMb6WPe+xNd/FipP//pFralHfLMsqrpO lIVg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=VRkO/jIoV9g1yKeMQrEzpeYvFI7BRt+QE6mGrnlpfaU=; b=Cim/GXvdJOhZ5mkZc99s0OQ/26QeoKbKv/i+Qm4UjZkduCn+3Pe+At6DcPLAKd91mN EKQiu5fa4iamLQNzpB22OOtal5fYwZMp/AXwYmt+SzKy7WGohv75PI3Ykr+AkMGQ0ci8 KGg4Jo402CSb55IkhFHLpA0dCOOs7vfjFbk3zs4uqecb3yDScOoKLc9WzL08yF8oKidB NeTcW66l5HH9CflUm7qLTU4hfzwb9TaaeVaLCVALe87UYO0TemZwDu1IsnA0MkioeeHJ 5olmikb9RbLLAnhbCXWbwHIdgUxULIe2JGeC7G47038CPp4Ko9XfftzRugUV7lxsx3CR urVg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b="A7Iz9/5K"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id hk14-20020a17090b224e00b0023499c3ddedsi9805975pjb.15.2023.04.01.08.56.45; Sat, 01 Apr 2023 08:56:56 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b="A7Iz9/5K"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229830AbjDAPzb (ORCPT + 99 others); Sat, 1 Apr 2023 11:55:31 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36986 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229461AbjDAPza (ORCPT ); Sat, 1 Apr 2023 11:55:30 -0400 Received: from mga12.intel.com (mga12.intel.com [192.55.52.136]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 835B820620; Sat, 1 Apr 2023 08:55:26 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1680364526; x=1711900526; h=date:from:to:cc:subject:message-id:references: mime-version:in-reply-to; bh=Gh91C+ZNgnlHe95VEAG2ZvyvuVbTO3suX8aj+cqURKc=; b=A7Iz9/5KUtB8mfSBV71mY5Md0QkuQHVhnnycr3BTT2oBdoEfNUo8BbNM 1wpo4Qcm9g1w1x6OOsuIUy0+9WBArhHZigFllGm12OX0a04N+y2ZVA81y Kdmx47zswHFgX0t/g4jNWDcJj+DOrUxo6BsLuoFMzVF/vj8xUHY9FPZqY 5hyWHlIhWJZx4m+/C97RNhsCul4kzS+X3br4rrEqSOTQkMPuYGBafnGzh HQg31Wk3P2sei9SZKhJoLLuDTKPc+uDwyeh3P3hlYjr/EUiY23BmBBjD/ 5rsRnqtJmBrIOzQsS8Uuw4Z+wBRC9q1X0IEXlO428arbJ9vYlc4wOw0MZ A==; X-IronPort-AV: E=McAfee;i="6600,9927,10667"; a="321319307" X-IronPort-AV: E=Sophos;i="5.98,310,1673942400"; d="scan'208";a="321319307" Received: from orsmga006.jf.intel.com ([10.7.209.51]) by fmsmga106.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 01 Apr 2023 08:55:26 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10667"; a="662716294" X-IronPort-AV: E=Sophos;i="5.98,310,1673942400"; d="scan'208";a="662716294" Received: from yilunxu-optiplex-7050.sh.intel.com (HELO localhost) ([10.239.159.165]) by orsmga006.jf.intel.com with ESMTP; 01 Apr 2023 08:55:23 -0700 Date: Sat, 1 Apr 2023 23:43:48 +0800 From: Xu Yilun To: "Manne, Nava kishore" Cc: "mdf@kernel.org" , "hao.wu@intel.com" , "trix@redhat.com" , "michal.simek@xilinx.com" , "linux-fpga@vger.kernel.org" , "linux-arm-kernel@lists.infradead.org" , "linux-kernel@vger.kernel.org" Subject: Re: [PATCH] fpga: zynqmp: Make word align the configuration data Message-ID: References: <20230314094222.66916-1-nava.kishore.manne@amd.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: X-Spam-Status: No, score=-2.5 required=5.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_MED,SPF_HELO_PASS, SPF_NONE autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 2023-03-28 at 09:33:17 +0000, Manne, Nava kishore wrote: > Hi Yilun, > > Please find my response inline. > > > -----Original Message----- > > From: Xu Yilun > > Sent: Saturday, March 18, 2023 2:55 PM > > To: Manne, Nava kishore > > Cc: mdf@kernel.org; hao.wu@intel.com; trix@redhat.com; > > michal.simek@xilinx.com; linux-fpga@vger.kernel.org; linux-arm- > > kernel@lists.infradead.org; linux-kernel@vger.kernel.org > > Subject: Re: [PATCH] fpga: zynqmp: Make word align the configuration data > > > > On 2023-03-14 at 15:12:22 +0530, Nava kishore Manne wrote: > > > To avoid unwanted copies at firmware(PMUFW) this patch provides a fix > > > > The copy happens in firmware? Please help briefly describe the firmware > > operations in commit message. > > > > Yes, If the firmware receives unaligned Bitstream file from Linux to make them align > it will do one more copy at firmware and this copy takes much time as firmware code > runs on microblaze(32-bit processor and runs at lower frequency). > So, we suggested the users to handle the alignment issues at top layers(Before submitting request to the firmware). > > Will update the description in v2. > > > > to align programmable logic(PL) configuration data if the data is not > > > word-aligned. To align the configuration data this patch adds a few > > > padding bytes and these additional padding bytes will not create any > > > functional impact on the PL configuration. > > > > > > Signed-off-by: Nava kishore Manne > > > --- > > > drivers/fpga/zynqmp-fpga.c | 15 +++++++++++++-- > > > 1 file changed, 13 insertions(+), 2 deletions(-) > > > > > > diff --git a/drivers/fpga/zynqmp-fpga.c b/drivers/fpga/zynqmp-fpga.c > > > index c60f20949c47..70a12dc6e15c 100644 > > > --- a/drivers/fpga/zynqmp-fpga.c > > > +++ b/drivers/fpga/zynqmp-fpga.c > > > @@ -15,6 +15,9 @@ > > > /* Constant Definitions */ > > > #define IXR_FPGA_DONE_MASK BIT(3) > > > > > > +#define DUMMY_PAD_BYTE 0xFF > > > +#define FPGA_WORD_SIZE 4 > > > + > > > /** > > > * struct zynqmp_fpga_priv - Private data structure > > > * @dev: Device data structure > > > @@ -41,18 +44,26 @@ static int zynqmp_fpga_ops_write(struct > > fpga_manager *mgr, > > > const char *buf, size_t size) > > > { > > > struct zynqmp_fpga_priv *priv; > > > + int word_align, ret, index; > > > dma_addr_t dma_addr; > > > u32 eemi_flags = 0; > > > char *kbuf; > > > - int ret; > > > > > > priv = mgr->priv; > > > + word_align = size % FPGA_WORD_SIZE; > > > + if (word_align) > > > + word_align = FPGA_WORD_SIZE - word_align; > > > + > > > + size = size + word_align; > > > > Does the Macro ALIGN() help? > > > > Will fix in v2. > > > > > > > kbuf = dma_alloc_coherent(priv->dev, size, &dma_addr, > > GFP_KERNEL); > > > if (!kbuf) > > > return -ENOMEM; > > > > > > - memcpy(kbuf, buf, size); > > > > This is historical, but why do the realloc & copy? Any better way? > > > > Firmware internally uses the AXI DMA engine to transfer PL data from memory to the device > and it supports only continues DMA-able memory access(It will not support scatter-gather memory access). > So, this extra copy is needed to copy the data from kernel memory(allocated by the firmware subsystem using page allocators) I see, but seems the issues are generic. Same issues for versal-fpga 1. fpga_mgr_buf_load_mapped(), fpgamanager_ops::write are intended for contiguous (and maybe dma-safe) buffer but fpga_mgr_firmware_load() breaks this. This may also affect spi backend drivers. 2. Some drivers needs dma addr rather than cpu addr, this could be generally supported. But allocating a bounce buffer by dma_alloc_coherent() is not a good idea. 3. fpga_manager_ops::write() may also be called for each fragment of a sg buffer, could the firmware OK to handle this case? I think framework refactoring is needed for these issues. I may not have time to do the refactoring but will support these topics in first priority. Thanks, Yilun > to continues DMA-able memory. > > > > + for (index = 0; index < word_align; index++) > > > + kbuf[index] = DUMMY_PAD_BYTE; > > > + > > > + memcpy(&kbuf[index], buf, size - index); > > > > Generally I object to massive copy in fpga_manager_ops::write if not > > necessary. If there is an alignment requirement from HW, it should be > > noticed to the caller in some way, before the buffer is created. > > > > Agree, we should find a way to support this kind of use cases. > > Regards, > Navakishore. >