intel-spi: Split hardware and software sequencing
cover intel-spi: Split hardware and software sequencing
Right now the only driver for Intel's spi has a DANGEROUS tag for a bug in the past on certain Lenovo platforms. It was cleared out that the bug was caused for the spi software sequencing mechanism and if we only use the driver with the hardware sequencing capabilities will be much safer[1].
This changes will remove all the software sequencing bits from the driver and left only the hardware sequencing functionality. If the software sequencing capabilities are needed, the old driver can be build using the DANGEROUS option from the menu.
[1] https://lkml.org/lkml/2021/11/11/468
Mauro Lima (2):
spi: intel-spi: Move software sequencing logic outside the core
spi: intel-spi: build the driver with hardware sequencing by default
drivers/spi/Kconfig | 15 +- drivers/spi/Makefile | 2 +- drivers/spi/spi-intel-common.h | 171 +++++++++++++++++ drivers/spi/spi-intel-swseq.c | 231 +++++++++++++++++++++++ drivers/spi/spi-intel-swseq.h | 23 +++ drivers/spi/spi-intel.c | 326 +++------------------------------ 6 files changed, 464 insertions(+), 304 deletions(-) create mode 100644 drivers/spi/spi-intel-common.h create mode 100644 drivers/spi/spi-intel-swseq.c create mode 100644 drivers/spi/spi-intel-swseq.h
Signature · 1 line
2.34.3
PATCH 1/2 spi: intel-spi: Move software sequencing logic outside the core
Move out the software sequencing logic from the core. Keep the functionality without changes.
--- drivers/spi/Makefile | 2 +- drivers/spi/spi-intel-common.h | 171 +++++++++++++++++ drivers/spi/spi-intel-swseq.c | 181 ++++++++++++++++++ drivers/spi/spi-intel-swseq.h | 23 +++ drivers/spi/spi-intel.c | 326 +++------------------------------ 5 files changed, 401 insertions(+), 302 deletions(-) create mode 100644 drivers/spi/spi-intel-common.h create mode 100644 drivers/spi/spi-intel-swseq.c create mode 100644 drivers/spi/spi-intel-swseq.h
drivers/spi/Makefile +1 -1
@@ -63,7 +63,7 @@ obj-$(CONFIG_SPI_HISI_SFC_V3XX) += spi-hisi-sfc-v3xx.o obj-$(CONFIG_SPI_IMG_SPFI) += spi-img-spfi.o obj-$(CONFIG_SPI_IMX) += spi-imx.o obj-$(CONFIG_SPI_INGENIC) += spi-ingenic.o -obj-$(CONFIG_SPI_INTEL) += spi-intel.o +obj-$(CONFIG_SPI_INTEL) += spi-intel.o spi-intel-swseq.o obj-$(CONFIG_SPI_INTEL_PCI) += spi-intel-pci.o obj-$(CONFIG_SPI_INTEL_PLATFORM) += spi-intel-platform.o obj-$(CONFIG_SPI_LANTIQ_SSC) += spi-lantiq-ssc.o
drivers/spi/spi-intel-common.h new file +171 -0
171 lines not on this page · raw message
drivers/spi/spi-intel-swseq.c new file +181 -0
181 lines not on this page · raw message
drivers/spi/spi-intel-swseq.h new file +23 -0
@@ -0,0 +1,23 @@ +/* SPDX-License-Identifier: GPL-2.0-only +* +* Intel PCH/PCU SPI flash driver. +* +* Copyright (C) 2016 - 2022, Intel Corporation +* Author: Mika Westerberg <[email protected]> +*/ + +#ifndef SPI_INTEL_SWSEQ_H +#define SPI_INTEL_SWSEQ_H + +#include <linux/types.h> + +int intel_spi_sw_cycle (struct intel_spi *ispi,u8 opcode,size_t len, +int optype); +inline bool is_swseq_enabled (void ); +int handle_swseq_wren (struct intel_spi *ispi); +bool mem_op_supported_on_spi_locked (const struct intel_spi *ispi, +const struct spi_mem_op *op); +void disable_smi_generation (const struct intel_spi *ispi); +void populate_opmenus (struct intel_spi *ispi,u32 *opmenu0,u32 *opmenu1); + +#endif /* SPI_INTEL_SWSEQ_H */
drivers/spi/spi-intel.c +25 -301
416 lines not on this page · raw message
Signature · 1 line
2.34.3
Re: [PATCH 1/2] spi: intel-spi: Move software sequencing logic outside the core
Hi,
drivers/spi/spi-intel-swseq.c line 13
Quoted 3 lines · Mauro Lima
drivers/spi/spi-intel-swseq.c new file +3
-0+#include "spi-intel.h" +#include "spi-intel-common.h" +#include "spi-intel-swseq.h"
Do we really need all these headers? Why not just "spi-intel.h"?
Quoted 6 lines
drivers/spi/spi-intel-swseq.c new file +6
-0+ +bool mem_op_supported_on_spi_locked (const struct intel_spi *ispi, +const struct spi_mem_op *op) +{ +int i; +
drivers/spi/spi-intel-swseq.c line 29
Quoted 10 lines
drivers/spi/spi-intel-swseq.c new file +10
-0+/* Check if it is in the locked opcodes list */ +for (i =0 ; i <ARRAY_SIZE (ispi->opcodes); i++) { +if (ispi->opcodes[i] == op->cmd.opcode) +return true; + } + +dev_dbg (ispi->dev,"%#x not supported\n" , op->cmd.opcode); +return false; +} +EXPORT_SYMBOL (mem_op_supported_on_spi_locked);
You need to namespace all these symbols with intel_spi_ or so (and use _GPL version of EXPORT_SYMBOL()).
However, I don't think we even need all these to be exported in the first place. It has been quite a while we discussed about this so I might be forgetting something but IIRC I did not suggest the split this way? ;-)
PATCH 2/2 spi: intel-spi: build the driver with hardware sequencing by default
In reply to Mauro LimaAdd menuconfig option to build the driver with hardware sequencing by default and another to specify software sequencing support if needed. For the software sequencing functionality preserve the *DANGEROUS* tag.
--- drivers/spi/Kconfig | 15 +++++++++-- drivers/spi/spi-intel-swseq.c | 50 +++++++++++++++++++++++++++++++++++ 2 files changed, 63 insertions(+), 2 deletions(-)
drivers/spi/Kconfig +13 -2
@@ -448,7 +448,7 @@ config SPI_INTEL tristate config SPI_INTEL_PCI - tristate "Intel PCH/PCU SPI flash PCI driver (DANGEROUS)" + tristate "Intel PCH/PCU SPI flash PCI driver" depends on PCI depends on X86 || COMPILE_TEST depends on SPI_MEM
@@ -458,6 +458,8 @@ config SPI_INTEL_PCI master mode. This controller is present in modern Intel hardware and is used to hold BIOS and other persistent settings. Using this driver it is possible to upgrade BIOS directly from Linux. + The driver will use hardware sequencing capabilities from the chip + by default. Say N here unless you know what you are doing. Overwriting the SPI flash may render the system unbootable.
@@ -466,7 +468,7 @@ config SPI_INTEL_PCI will be called spi-intel-pci. config SPI_INTEL_PLATFORM - tristate "Intel PCH/PCU SPI flash platform driver (DANGEROUS)" + tristate "Intel PCH/PCU SPI flash platform driver" depends on X86 || COMPILE_TEST depends on SPI_MEM select SPI_INTEL
@@ -476,6 +478,8 @@ config SPI_INTEL_PLATFORM Intel hardware and is used to hold BIOS and other persistent settings. Using this driver it is possible to upgrade BIOS directly from Linux. + The driver will use hardware sequencing capabilities from the chip + by default. Say N here unless you know what you are doing. Overwriting the SPI flash may render the system unbootable.
@@ -483,6 +487,13 @@ config SPI_INTEL_PLATFORM To compile this driver as a module, choose M here: the module will be called spi-intel-platform. +config SPI_INTEL_SWSEQ + tristate "Intel SPI controller software sequencing support (DANGEROUS)" + depends on X86 || COMPILE_TEST + depends on SPI_MEM + help + This enables software sequencing functionality to the SPI controller + config SPI_JCORE tristate "J-Core SPI Master" depends on OF && (SUPERH || COMPILE_TEST)
drivers/spi/spi-intel-swseq.c +50 -0
60 lines not on this page · raw message
Signature · 1 line
2.34.3
Hi,
Quoted 11 lines · Mauro Lima
Right now the only driver for Intel's spi has a DANGEROUS tag for a bug in the past on certain Lenovo platforms. It was cleared out that the bug was caused for the spi software sequencing mechanism and if we only use the driver with the hardware sequencing capabilities will be much safer[1].
This changes will remove all the software sequencing bits from the driver and left only the hardware sequencing functionality. If the software sequencing capabilities are needed, the old driver can be build using the DANGEROUS option from the menu.
Quoted 5 lines
[1] https://lkml.org/lkml/2021/11/11/468
Mauro Lima (2):
spi: intel-spi: Move software sequencing logic outside the core
spi: intel-spi: build the driver with hardware sequencing by default
I'be been thinking about this and I believe we can do something simpler instead.
All the modern "Core" CPUs expose this as PCI device and that only supports hardware sequencer which should be safe so I think we can do something like this:
1. Make spi-intel-pci.c to set the type to INTEL_SPI_CNL for all the controllers it supports (and double check that this is the case for all these controllers).
As a side effect the ispi->sregs will be set to NULL so the core driver does not even try to use the software seguencer.
2. Update Kconfig of SPI_INTEL_PCI to remove "DANGEROUS" and mention in the help text that this only supports the hardware sequencer and only the modern core hardware.
3. Update Kconfig of SPI_INTEL_PLATFORM help text to mention that most of these are using software sequencer, leave "DANGEROUS" there.
Does this make sense? Let me know what you think. I can do this myself as well (might take some while though since busy with other things usual).