Received: by 2002:a6b:500f:0:0:0:0:0 with SMTP id e15csp6110756iob; Tue, 10 May 2022 10:32:07 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzqeQZZWnfXgo6KNs7x1wTQ8B0i0pkNRiVMJBUop8hs8ZzMLrXOQHV3eauD6RCAvod5dRVX X-Received: by 2002:a17:903:4044:b0:15e:f501:dab2 with SMTP id n4-20020a170903404400b0015ef501dab2mr18756465pla.116.1652203926872; Tue, 10 May 2022 10:32:06 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1652203926; cv=none; d=google.com; s=arc-20160816; b=PDBEiydob8FwoO8VI28Es7LafcoX9awofuBTij+lDlbzE5TEADtg8iTD8qLmPpX0Au rnKOjZ+OKFnxXdTEOmPoaw1ex1eM3MZOC/GAlInCm56jRl8XyBRfI9IjfoAi9AyMDeop 66tZ/WCU360iR+mXX/ksTNvYlpWPyiQ1+c9JT3dikW7MhgnW7rbvOyiyPRxJ8DHcpZcI Uw5CeB3ZyoxJZg44lbtG4N2+XMPN+hIrLwlGq/fIuKsP7sIDeIRU7Dy5aHInMcesoyf4 hKBsGT6v7J44PUV53MKcaTvzbg8TxQ4HuY3ayEn3lxrg4+PJ1glBpDjBT3NMx0Na4TLt Hjew== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:in-reply-to :content-language:references:cc:to:subject:from:user-agent :mime-version:date:message-id:dkim-signature; bh=Q9ZRcghSC4Zvb59xWNLpgwQRMRVcmsJ18TNHtRXVuxo=; b=mVCMiMVvLwCut225cxLWQ1vVMpJbZ8DqcHkMKeAXyrRG/QN7Ymq8NJ83Edu/rq93tM Q1osbypkOHS2HsVHMns1bN/y3fwugj6u37erxkzm/Hhs4Ylf4uiZF352eRLOmKI/bM/5 q6gVrAxGHfrCKnueeY2XPES54d3pjWc+cgbHounNyOjejtv4gWeHuGHzTl9YRsg7zzpw a/Uol49dITGjDDsTjvJtCIqxlG8EXEW6pEfJzIoGBXkL2fTvyfqTq7C2NcgDhyWCWvF9 zxtm70hckBKr3RABP89zZL/0W3lzBInmW5fcheqxznjuQJKop8UyJM2/uWC+2U5MixXN N4sQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@conchuod.ie header.s=google header.b="Z8rrIL6/"; 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=QUARANTINE sp=QUARANTINE dis=NONE) header.from=conchuod.ie Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id h19-20020a632113000000b003c6db7073dasi6957028pgh.604.2022.05.10.10.31.47; Tue, 10 May 2022 10:32:06 -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=@conchuod.ie header.s=google header.b="Z8rrIL6/"; 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=QUARANTINE sp=QUARANTINE dis=NONE) header.from=conchuod.ie Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S239337AbiEJL25 (ORCPT + 99 others); Tue, 10 May 2022 07:28:57 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34698 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232048AbiEJL2y (ORCPT ); Tue, 10 May 2022 07:28:54 -0400 Received: from mail-wm1-x334.google.com (mail-wm1-x334.google.com [IPv6:2a00:1450:4864:20::334]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A1A091B4358 for ; Tue, 10 May 2022 04:24:56 -0700 (PDT) Received: by mail-wm1-x334.google.com with SMTP id 125-20020a1c0283000000b003946c466c17so1161674wmc.4 for ; Tue, 10 May 2022 04:24:56 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=conchuod.ie; s=google; h=message-id:date:mime-version:user-agent:from:subject:to:cc :references:content-language:in-reply-to:content-transfer-encoding; bh=Q9ZRcghSC4Zvb59xWNLpgwQRMRVcmsJ18TNHtRXVuxo=; b=Z8rrIL6/GXzsZMveC2UvwKakgRmDeIw1l90/SleuXTMgs2cSdCxz/gmmODmAv6sEH2 h5XIM3/YspFdyoTA0JemciadBa44j3VSGsGllMClineyi7qIFswlQwNAJGfiQd0fUkxm JW66RrO1CCZMUOpvT7wgXBu5XGD8ySg9oIGHC8a2gCLcoqbqw80PAeySedyai8xjaUsv 17pQzZ6ahOXkqC0oGwYOtcTjzC8nSyfqjAPMXhzXgy9SJnG4Im7QxKiaRR/7utl42tYA x8ePtZRcgzb8SbMPv4rCE27OwGcwXqrVcPx6VWF9f5I27j6FL+PA+t74BY6wYzapSXgC Q5Dw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:message-id:date:mime-version:user-agent:from :subject:to:cc:references:content-language:in-reply-to :content-transfer-encoding; bh=Q9ZRcghSC4Zvb59xWNLpgwQRMRVcmsJ18TNHtRXVuxo=; b=Iavs/DNxiEc69SWT6NlGfxPavwxv9GDuGkk31CDDF8CH/eqR8g6GF5+K5Ij/e6U8Lk UEPpWhYiAdtl/L17BH4Tgr7NOBPLCfGAmpM4lE8t7e3yDCpu65cb/jfLo769d5KSG5kU m2m1qqbhfyyZU0C7obYrMN2N+R6XTaUgMMeSwQBXOaXQ0MWF2exLQIEz/gkBfFxFPq0I LVvpzHayv6cngN9CpHCW4P6MsTlsqEayY6OnHkWQHgRaXH2t1WSt0p9NRVz2Zm/bNkPC DbQYX1eSUIdFvJHCnxFAgFBuecwiThJmwhSY8gVfEmp6F4n6X/k+gpSEkUNDBQnbmsjS otog== X-Gm-Message-State: AOAM530G3CnaRZttc86SPBpunjkmCLGdmUGq7fat2OB66UxCpoYFhBn/ 2vSmI4TAUT/oti7PtYfcoiTFFt1VlOgIZ9V7 X-Received: by 2002:a7b:c76e:0:b0:394:8be3:a83c with SMTP id x14-20020a7bc76e000000b003948be3a83cmr12055521wmk.41.1652181895085; Tue, 10 May 2022 04:24:55 -0700 (PDT) Received: from [10.205.160.53] ([95.83.233.54]) by smtp.gmail.com with ESMTPSA id i6-20020a05600c354600b003942a244f33sm2404493wmq.12.2022.05.10.04.24.54 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Tue, 10 May 2022 04:24:54 -0700 (PDT) Message-ID: <4b752147-1a09-a4af-bc5d-3b132b84ef49@conchuod.ie> Date: Tue, 10 May 2022 12:29:54 +0100 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20100101 Thunderbird/91.8.1 From: Conor Dooley Subject: Re: [PATCH v11 2/3] fpga: microchip-spi: add Microchip MPF FPGA manager To: Ivan Bornyakov , Conor.Dooley@microchip.com Cc: mdf@kernel.org, hao.wu@intel.com, yilun.xu@intel.com, trix@redhat.com, robh+dt@kernel.org, krzysztof.kozlowski+dt@linaro.org, linux-fpga@vger.kernel.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, system@metrotek.ru References: <20220507074304.11144-1-i.bornyakov@metrotek.ru> <20220507074304.11144-3-i.bornyakov@metrotek.ru> <20220509171621.zk4owxwlngxjodgz@x260> Content-Language: en-US In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-3.0 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,NICE_REPLY_A,RCVD_IN_DNSWL_NONE, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE,URIBL_BLOCKED autolearn=ham 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 09/05/2022 19:56, Conor Dooley wrote: > On 09/05/2022 18:16, Ivan Bornyakov wrote: >> On Mon, May 09, 2022 at 11:41:18AM +0000, Conor.Dooley@microchip.com wrote: >>> Hey Ivan, one comment below. >>> Thanks, >>> Conor. >>> >>> On 07/05/2022 08:43, Ivan Bornyakov wrote: >>>> ... snip ... >>>> +static int mpf_read_status(struct spi_device *spi) >>>> +{ >>>> + u8 status, status_command = MPF_SPI_READ_STATUS; >>>> + struct spi_transfer xfer = { >>>> + .tx_buf = &status_command, >>>> + .rx_buf = &status, >>>> + .len = 1, >>>> + }; >>>> + int ret = spi_sync_transfer(spi, &xfer, 1); >>>> + >>>> + if ((status & MPF_STATUS_SPI_VIOLATION) || >>>> + (status & MPF_STATUS_SPI_ERROR)) >>>> + ret = -EIO; >>>> + >>>> + return ret ? : status; >>>> +} >>>> + >>>> ... snip ... >>>> + >>>> +static int poll_status_not_busy(struct spi_device *spi, u8 mask) >>>> +{ >>>> + int status, timeout = MPF_STATUS_POLL_TIMEOUT; >>>> + >>>> + while (timeout--) { >>>> + status = mpf_read_status(spi); >>>> + if (status < 0 || >>>> + (!(status & MPF_STATUS_BUSY) && (!mask || (status & mask)))) >>>> + return status; >>>> + >>>> + usleep_range(1000, 2000); >>>> + } >>>> + >>>> + return -EBUSY; >>>> +} >>> >>> Is there a reason you changed this from the snippet you sent me >>> in the responses to version 8: >>> static int poll_status_not_busy(struct spi_device *spi, u8 mask) >>> { >>> u8 status, status_command = MPF_SPI_READ_STATUS; >>> int ret, timeout = MPF_STATUS_POLL_TIMEOUT; >>> struct spi_transfer xfer = { >>> .tx_buf = &status_command, >>> .rx_buf = &status, >>> .len = 1, >>> }; >>> >>> while (timeout--) { >>> ret = spi_sync_transfer(spi, &xfer, 1); >>> if (ret < 0) >>> return ret; >>> >>> if (!(status & MPF_STATUS_BUSY) && (!mask || (status & mask))) >>> return status; >>> >>> usleep_range(1000, 2000); >>> } >>> >>> return -EBUSY; >>> } >>> >>> With the current version, I hit the "Failed to write bitstream >>> frame" check in mpf_ops_write at random points in the transfer. >>> Replacing poll_status_not_busy with the above allows it to run >>> to completion. >> >> In my eyes they are equivalent, aren't they? >> > > I was in a bit of a rush today & didn't have time to do proper > debugging, I'll put some debug code in tomorrow and try to find > exactly what is different between the two. > > Off the top of my head, since I don't have a board on me to test, > the only difference I can see is that with the snippet you only > checked if spi_sync_transfer was negative whereas now you check > if it has a value at all w/ that ternary operator. > > But even that seems like it *shouldn't* be the problem, since ret > should contain -errno or zero, right? > Either way, I will do some digging tomorrow. I put a printk("status %x, ret %d", status, ret); into the failure path of mpf_read_status() & it looks like a status 0xA is being returned - error & ready? That seems like a very odd combo to be getting back out of it. It shouldn't be dodgy driver/connection either, b/c that's what I see if I connect my protocol analyser: https://i.imgur.com/VbjgfCk.png That's mosi (hex), ss, sclk, mosi, miso (hex), miso in descending order. I think what was happening was with the snippet you returned one of the following: -EBUSY, ret (aka -errno) or status. Since status is positive, the checks in mpf_spi_write.*() saw nothing wrong at all and programming continued despite there being a problem. The new version fixes this by returning -EIO rather than status from poll_status_not_busy(). I wish I had a socketable PolarFire so I could investigate further, but this looks like it might a be hardware issue somewhere on my end? So ye, sorry for the noise and carry on! I'll try tofind what is to blame for it. Thanks, Conor.