Received: by 2002:a05:6a10:2726:0:0:0:0 with SMTP id ib38csp1008743pxb; Wed, 6 Apr 2022 06:36:35 -0700 (PDT) X-Google-Smtp-Source: ABdhPJz7/iHzf9S8ALG0hVkJSthokPYQA+I6MCL63HJ9mcu44t+0ZPKIdJfHoPUrrR+WRyM9Xod6 X-Received: by 2002:a05:6a02:282:b0:381:6565:e080 with SMTP id bk2-20020a056a02028200b003816565e080mr7161376pgb.272.1649252195027; Wed, 06 Apr 2022 06:36:35 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1649252195; cv=none; d=google.com; s=arc-20160816; b=kXqX5j5ukKQoAqxxzNh7KMrdNrRUAXzM6g14DMb61SpZuHzUEj2xnqlk+wd7ryQncr GQE/S33GmpAFJLLJiWt5gsIdvr2wsTM6WX8SqOkDQAyPXVbgHCgdC9t/N8htIWimbOx+ KAk7cQfDNktHW33rdtPWbXCO52yDDFrlPmmbjKAiknPNTcg0sVRaFvIsOyjAZyGuLXld LkUcfkE+VZGeYCweW4g1q16HzWlmpJ6Ew/MXBCtzIeCkNv7R4YzPFiib5KhW5UcsuryU gzrvNQ7oga0/AA3JJPZwPLcAW3ntzZZJZ5pfzqYvca7hoqMmZMyFwN5lon7I1tfDd+GO FOPQ== 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-transfer-encoding :content-disposition:mime-version:references:message-id:subject:cc :to:from:date:dkim-signature; bh=ryPzySi+sY1PGhJYHg8EDNmmr6lLqwb9RbsI5qhyyH0=; b=lIjrW18FMRZwMOyBaPHbUJk1mxWWC9cWRY0kLKYZQhMs2P+sgJrBoEgKAtIoQyz27/ gv+u4J7vjQXvmpZ7+auEtPMNZ3OoO7wDYb3EOThQAeCQblOSqlVzaT3dlVlSOKoqelBA /yZMHjv5bYDTE2x4AeBpWeK/MO12bdPg1BC+zRT0hCHRQ8DTL000A5nFhu02xR867jwS 21ApLHRfzl9+YsetGGUKzXKRn7oAfKfEjWPHMvd6MZHyF7cLWEdBpZOFt9zRj8qJG7t7 9rqTUOS84jTiCKgUM5GzADVyyfPsJ9B5gIjrwvAtVUHdgei/PlHGjgVriN/lQOEsx8Fp iYZg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@ti.com header.s=ti-com-17Q1 header.b=aaRdE5nn; spf=softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=NONE dis=NONE) header.from=ti.com Return-Path: Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [23.128.96.19]) by mx.google.com with ESMTPS id f10-20020a639c0a000000b003816043f0e8si15167953pge.733.2022.04.06.06.36.34 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 06 Apr 2022 06:36:35 -0700 (PDT) Received-SPF: softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) client-ip=23.128.96.19; Authentication-Results: mx.google.com; dkim=pass header.i=@ti.com header.s=ti-com-17Q1 header.b=aaRdE5nn; spf=softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=NONE dis=NONE) header.from=ti.com Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 07DDC6D7E66; Wed, 6 Apr 2022 04:19:45 -0700 (PDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1839585AbiDFBFF (ORCPT + 99 others); Tue, 5 Apr 2022 21:05:05 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34620 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1573649AbiDETal (ORCPT ); Tue, 5 Apr 2022 15:30:41 -0400 Received: from lelv0142.ext.ti.com (lelv0142.ext.ti.com [198.47.23.249]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C178DDF47; Tue, 5 Apr 2022 12:28:41 -0700 (PDT) Received: from lelv0265.itg.ti.com ([10.180.67.224]) by lelv0142.ext.ti.com (8.15.2/8.15.2) with ESMTP id 235JRwNC034240; Tue, 5 Apr 2022 14:27:58 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ti.com; s=ti-com-17Q1; t=1649186878; bh=ryPzySi+sY1PGhJYHg8EDNmmr6lLqwb9RbsI5qhyyH0=; h=Date:From:To:CC:Subject:References:In-Reply-To; b=aaRdE5nnYIrJf5T+fvuEYm5nR9xQxzxlSRRn/11310CZYxzxNFRWA3N/1ujm2T/TD iQut+m7fr7M0lJZSODgNTzU3SajLEUSGBv+SS5169QFUIrTVCzmMAtYMs4uXO5c/Ao KSacvEvmH13gp+mUPEcdV2goz9m+jWLuc4CEsZn8= Received: from DFLE109.ent.ti.com (dfle109.ent.ti.com [10.64.6.30]) by lelv0265.itg.ti.com (8.15.2/8.15.2) with ESMTPS id 235JRw2p027239 (version=TLSv1.2 cipher=AES256-GCM-SHA384 bits=256 verify=FAIL); Tue, 5 Apr 2022 14:27:58 -0500 Received: from DFLE106.ent.ti.com (10.64.6.27) by DFLE109.ent.ti.com (10.64.6.30) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256_P256) id 15.1.2308.14; Tue, 5 Apr 2022 14:27:58 -0500 Received: from lelv0326.itg.ti.com (10.180.67.84) by DFLE106.ent.ti.com (10.64.6.27) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256_P256) id 15.1.2308.14 via Frontend Transport; Tue, 5 Apr 2022 14:27:58 -0500 Received: from localhost (ileax41-snat.itg.ti.com [10.172.224.153]) by lelv0326.itg.ti.com (8.15.2/8.15.2) with ESMTP id 235JRvNp005681; Tue, 5 Apr 2022 14:27:58 -0500 Date: Wed, 6 Apr 2022 00:57:57 +0530 From: Pratyush Yadav To: =?utf-8?Q?C=C3=A9dric?= Le Goater CC: , , Mark Brown , Tudor Ambarus , Miquel Raynal , Richard Weinberger , Vignesh Raghavendra , , Joel Stanley , Andrew Jeffery , Chin-Ting Kuo , , Rob Herring , , , Tao Ren Subject: Re: [PATCH v4 04/11] spi: aspeed: Add support for direct mapping Message-ID: <20220405192757.v356zx2u4mpgpnlq@ti.com> References: <20220325100849.2019209-1-clg@kaod.org> <20220325100849.2019209-5-clg@kaod.org> <20220330194548.zldbkaoctlhgwcl2@ti.com> <3e5ea70d-805a-ff30-663b-e802d9116a49@kaod.org> MIME-Version: 1.0 Content-Type: text/plain; charset="iso-8859-1" Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <3e5ea70d-805a-ff30-663b-e802d9116a49@kaod.org> X-EXCLAIMER-MD-CONFIG: e1e8a2fd-e40a-4ac6-ac9b-f7e9cc9ee180 X-Spam-Status: No, score=-2.0 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,RDNS_NONE,SPF_HELO_NONE,T_SCC_BODY_TEXT_LINE autolearn=no 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 04/04/22 09:11AM, C?dric Le Goater wrote: > On 3/30/22 21:45, Pratyush Yadav wrote: > > On 25/03/22 11:08AM, C?dric Le Goater wrote: > > > Use direct mapping to read the flash device contents. This operation > > > mode is called "Command mode" on Aspeed SoC SMC controllers. It uses a > > > Control Register for the settings to apply when a memory operation is > > > performed on the flash device mapping window. > > > > > > If the window is not big enough, fall back to the "User mode" to > > > perform the read. > > > > > > Since direct mapping now handles all reads of the flash device > > > contents, also use memcpy_fromio for other address spaces, such as > > > SFDP. > > > > > > Direct mapping for writes will come later when validated. > > > > > > Reviewed-by: Joel Stanley > > > Tested-by: Joel Stanley > > > Tested-by: Tao Ren > > > Signed-off-by: C?dric Le Goater > > > --- > > > drivers/spi/spi-aspeed-smc.c | 67 ++++++++++++++++++++++++++++++++++-- > > > 1 file changed, 65 insertions(+), 2 deletions(-) > > > > > > diff --git a/drivers/spi/spi-aspeed-smc.c b/drivers/spi/spi-aspeed-smc.c > > > index 997ec2e45118..0951766baef4 100644 > > > --- a/drivers/spi/spi-aspeed-smc.c > > > +++ b/drivers/spi/spi-aspeed-smc.c > > > @@ -322,8 +322,8 @@ static int do_aspeed_spi_exec_op(struct spi_mem *mem, const struct spi_mem_op *o > > > if (!op->addr.nbytes) > > > ret = aspeed_spi_read_reg(chip, op); > > > else > > > - ret = aspeed_spi_read_user(chip, op, op->addr.val, > > > - op->data.nbytes, op->data.buf.in); > > > + memcpy_fromio(op->data.buf.in, chip->ahb_base + op->addr.val, > > > + op->data.nbytes); > > > > I think I commented on this earlier too, though I failed to respond to > > your reply. Let me bring the topic back up. I think this can cause an > > invalid memory address to be accessed. Not all SPI MEM consumers will > > use dirmap APIs, and they won't use them all the time. For example, SPI > > NOR can perform some operations to reset the flash before shutting down. > > For example, SPI NOR turns off 4byte address mode during shutdown. This > > will be a register read/write operation, which usually has a different > > opcode. > > It's only a small optimization for startup when the SFDP probing is done. > There are quite a few reads which are large : > > spi-aspeed-smc 1e630000.spi: CE0 read OP 0x5a mode:1.1.1.1 naddr:0x3 ndummies:0x1 len:0x10 > spi-aspeed-smc 1e630000.spi: CE0 read OP 0x5a mode:1.1.1.1 naddr:0x3 ndummies:0x1 len:0x10 > spi-aspeed-smc 1e630000.spi: CE0 read OP 0x5a mode:1.1.1.1 naddr:0x3 ndummies:0x1 len:0x120 > spi-aspeed-smc 1e630000.spi: CE0 read OP 0x5a mode:1.1.1.1 naddr:0x3 ndummies:0x1 len:0x40 > spi-aspeed-smc 1e630000.spi: CE0 read OP 0x5a mode:1.1.1.1 naddr:0x3 ndummies:0x1 len:0x8 Is the overhead large enough to cause any significant delays? This would only happen once, it is not on a hot path. Anyway, I had not noticed earlier that you set opcode, dummy, etc. in do_aspeed_spi_exec_op() so I was thinking you would always end up using the "main" read operation for this. I am fine with this as long as you add range checks to make sure there are no overflows. > > > > > So I think you should keep dirmap and exec_op() independent of each > > other. > > OK. I understand. It's not a problem as it works either way. > > Thanks, > > C. > > > > > } else { > > > if (!op->addr.nbytes) > > > ret = aspeed_spi_write_reg(chip, op); > > > @@ -403,10 +403,73 @@ static int aspeed_spi_chip_set_default_window(struct aspeed_spi_chip *chip) > > > return chip->ahb_window_size ? 0 : -1; > > > } > > > +static int aspeed_spi_dirmap_create(struct spi_mem_dirmap_desc *desc) > > > +{ > > > + struct aspeed_spi *aspi = spi_controller_get_devdata(desc->mem->spi->master); > > > + struct aspeed_spi_chip *chip = &aspi->chips[desc->mem->spi->chip_select]; > > > + struct spi_mem_op *op = &desc->info.op_tmpl; > > > + u32 ctl_val; > > > + int ret = 0; > > > + > > > + chip->clk_freq = desc->mem->spi->max_speed_hz; > > > + > > > + /* Only for reads */ > > > + if (op->data.dir != SPI_MEM_DATA_IN) > > > + return -EOPNOTSUPP; > > > + > > > + if (desc->info.length > chip->ahb_window_size) > > > + dev_warn(aspi->dev, "CE%d window (%dMB) too small for mapping", > > > + chip->cs, chip->ahb_window_size >> 20); > > > + > > > + /* Define the default IO read settings */ > > > + ctl_val = readl(chip->ctl) & ~CTRL_IO_CMD_MASK; > > > + ctl_val |= aspeed_spi_get_io_mode(op) | > > > + op->cmd.opcode << CTRL_COMMAND_SHIFT | > > > + CTRL_IO_DUMMY_SET(op->dummy.nbytes / op->dummy.buswidth) | > > > + CTRL_IO_MODE_READ; > > > + > > > + /* Tune 4BYTE address mode */ > > > + if (op->addr.nbytes) { > > > + u32 addr_mode = readl(aspi->regs + CE_CTRL_REG); > > > + > > > + if (op->addr.nbytes == 4) > > > + addr_mode |= (0x11 << chip->cs); > > > + else > > > + addr_mode &= ~(0x11 << chip->cs); > > > + writel(addr_mode, aspi->regs + CE_CTRL_REG); > > > + } > > > + > > > + /* READ mode is the controller default setting */ > > > + chip->ctl_val[ASPEED_SPI_READ] = ctl_val; > > > + writel(chip->ctl_val[ASPEED_SPI_READ], chip->ctl); > > > + > > > + dev_info(aspi->dev, "CE%d read buswidth:%d [0x%08x]\n", > > > + chip->cs, op->data.buswidth, chip->ctl_val[ASPEED_SPI_READ]); > > > + > > > + return ret; > > > +} > > > + > > > +static ssize_t aspeed_spi_dirmap_read(struct spi_mem_dirmap_desc *desc, > > > + u64 offset, size_t len, void *buf) > > > +{ > > > + struct aspeed_spi *aspi = spi_controller_get_devdata(desc->mem->spi->master); > > > + struct aspeed_spi_chip *chip = &aspi->chips[desc->mem->spi->chip_select]; > > > + > > > + /* Switch to USER command mode if mapping window is too small */ > > > + if (chip->ahb_window_size < offset + len) > > > + aspeed_spi_read_user(chip, &desc->info.op_tmpl, offset, len, buf); > > > + else > > > + memcpy_fromio(buf, chip->ahb_base + offset, len); > > > + > > > + return len; > > > +} > > > + > > > static const struct spi_controller_mem_ops aspeed_spi_mem_ops = { > > > .supports_op = aspeed_spi_supports_op, > > > .exec_op = aspeed_spi_exec_op, > > > .get_name = aspeed_spi_get_name, > > > + .dirmap_create = aspeed_spi_dirmap_create, > > > + .dirmap_read = aspeed_spi_dirmap_read, > > > }; > > > static void aspeed_spi_chip_set_type(struct aspeed_spi *aspi, unsigned int cs, int type) > > > -- > > > 2.34.1 > > > > > > -- Regards, Pratyush Yadav Texas Instruments Inc.