Apple M1 (Pro/Max) NVMe driver
Subsystems (4)
v3 cover Apple M1 (Pro/Max) NVMe driver
Hi,
This series includes everything[*] required to get NVMe up and running on Apple's M1, M1 Pro and M1 Max SoCs.
v1: https://lore.kernel.org/linux-nvme/[email protected]/T/
v2: https://lore.kernel.org/linux-nvme/[email protected]/T/
Thanks everyone for the reviews of v2 again! There are just some minor changes since v2 listed in the individual commits again.
Thanks,
Sven
[*] The only missing part in this series are the device tree updates
but since these will go through arm-soc anyway I haven't included them here but will instead submit them once this series is in a shape where it can be merged.
Sven Peter (6):
dt-bindings: iommu: Add Apple SART DMA address filter
dt-bindings: nvme: Add Apple ANS NVMe
soc: apple: Always include Makefile
soc: apple: Add SART driver
soc: apple: Add RTKit IPC library
nvme-apple: Add initial Apple SoC NVMe driver
.../devicetree/bindings/iommu/apple,sart.yaml | 52 + .../bindings/nvme/apple,nvme-ans.yaml | 111 ++ MAINTAINERS | 4 + drivers/nvme/host/Kconfig | 13 + drivers/nvme/host/Makefile | 3 + drivers/nvme/host/apple.c | 1598 +++++++++++++++++ drivers/soc/Makefile | 2 +- drivers/soc/apple/Kconfig | 24 + drivers/soc/apple/Makefile | 6 + drivers/soc/apple/rtkit-crashlog.c | 154 ++ drivers/soc/apple/rtkit-internal.h | 62 + drivers/soc/apple/rtkit.c | 958 ++++++++++ drivers/soc/apple/sart.c | 328 ++++ include/linux/soc/apple/rtkit.h | 159 ++ include/linux/soc/apple/sart.h | 57 + 15 files changed, 3530 insertions(+), 1 deletion(-) create mode 100644 Documentation/devicetree/bindings/iommu/apple,sart.yaml create mode 100644 Documentation/devicetree/bindings/nvme/apple,nvme-ans.yaml create mode 100644 drivers/nvme/host/apple.c create mode 100644 drivers/soc/apple/rtkit-crashlog.c create mode 100644 drivers/soc/apple/rtkit-internal.h create mode 100644 drivers/soc/apple/rtkit.c create mode 100644 drivers/soc/apple/sart.c create mode 100644 include/linux/soc/apple/rtkit.h create mode 100644 include/linux/soc/apple/sart.h
Signature · 1 line
2.25.1
PATCH v3 1/6 dt-bindings: iommu: Add Apple SART DMA address filter
Apple SoCs such as the M1 come with a simple DMA address filter called SART. Unlike a real IOMMU no pagetables can be configured but instead DMA transactions can be allowed for up to 16 paddr regions. The consumer also needs special support since not all DMA allocations have to be added to this filter.
---
v2 -> v3:
- Added Rob's r-b tag
v1 -> v2:
- Moved to bindings/iommu since it is "Close enough to an IOMMU in terms of its purpose" (Rob Herring)
.../devicetree/bindings/iommu/apple,sart.yaml | 52 +++++++++++++++++++ MAINTAINERS | 1 + 2 files changed, 53 insertions(+) create mode 100644 Documentation/devicetree/bindings/iommu/apple,sart.yaml
Documentation/devicetree/bindings/iommu/apple,sart.yaml new file +52 -0
@@ -0,0 +1,52 @@ +# SPDX-License-Identifier: GPL-2.0 OR BSD-2-Clause +%YAML 1.2 +--- +$id: http://devicetree.org/schemas/iommu/apple,sart.yaml# +$schema: http://devicetree.org/meta-schemas/core.yaml# + +title: Apple SART DMA address filter + +maintainers: + - Sven Peter <[email protected]> + +description: + Apple SART is a simple address filter for DMA transactions. Regions of + physical memory must be added to the SART's allow list before any + DMA can target these. Unlike a proper IOMMU no remapping can be done and + special support in the consumer driver is required since not all DMA + transactions of a single device are subject to SART filtering. + + SART1 has first been used since at least the A11 (iPhone 8 and iPhone X) + and allows 36 bit of physical address space and filter entries with sizes + up to 24 bit. + + SART2, first seen in A14 and M1, allows 36 bit of physical address space + and filter entry size up to 36 bit. + + SART3, first seen in M1 Pro/Max, extends both the address space and filter + entry size to 42 bit. + +properties: + compatible: + enum: + - apple,t6000-sart + - apple,t8103-sart + + reg: + maxItems: 1 + + power-domains: + maxItems: 1 + +required: + - compatible + - reg + +additionalProperties: false + +examples: + - | + iommu@7bc50000 { + compatible = "apple,t8103-sart"; + reg = <0x7bc50000 0x4000>; + };
MAINTAINERS +1 -0
@@ -1836,6 +1836,7 @@ F: Documentation/devicetree/bindings/arm/apple/* F: Documentation/devicetree/bindings/clock/apple,nco.yaml F: Documentation/devicetree/bindings/i2c/apple,i2c.yaml F: Documentation/devicetree/bindings/interrupt-controller/apple,* +F: Documentation/devicetree/bindings/iommu/apple,sart.yaml F: Documentation/devicetree/bindings/mailbox/apple,mailbox.yaml F: Documentation/devicetree/bindings/pci/apple,pcie.yaml F: Documentation/devicetree/bindings/pinctrl/apple,pinctrl.yaml
Signature · 1 line
2.25.1
PATCH v3 2/6 dt-bindings: nvme: Add Apple ANS NVMe
In reply to Sven PeterApple SoCs such as the M1 come with an embedded NVMe coprocessor called ANS2.
---
v2 -> v3:
- Added Rob's r-b tag
v1 -> v2:
- Moved to bindings/nvme (Krzysztof Kozlowski)
- Added power-domains and power-domain-names min/maxItems (Krzysztof Kozlowski)
.../bindings/nvme/apple,nvme-ans.yaml | 111 ++++++++++++++++++ MAINTAINERS | 1 + 2 files changed, 112 insertions(+) create mode 100644 Documentation/devicetree/bindings/nvme/apple,nvme-ans.yaml
Documentation/devicetree/bindings/nvme/apple,nvme-ans.yaml new file +111 -0
@@ -0,0 +1,111 @@ +# SPDX-License-Identifier: GPL-2.0 OR BSD-2-Clause +%YAML 1.2 +--- +$id: http://devicetree.org/schemas/nvme/apple,nvme-ans.yaml# +$schema: http://devicetree.org/meta-schemas/core.yaml# + +title: Apple ANS NVM Express host controller + +maintainers: + - Sven Peter <[email protected]> + +properties: + compatible: + items: + - enum: + - apple,t8103-nvme-ans2 + - apple,t6000-nvme-ans2 + - const: apple,nvme-ans2 + + reg: + items: + - description: NVMe and NVMMU registers + - description: ANS2 co-processor control registers + + reg-names: + items: + - const: nvme + - const: ans + + resets: + maxItems: 1 + + power-domains: + # two domains for t8103, three for t6000 + minItems: 2 + items: + - description: power domain for the NVMe controller. + - description: power domain for the first PCIe bus connecting the NVMe + controller to the storage modules. + - description: optional power domain for the second PCIe bus + connecting the NVMe controller to the storage modules. + + power-domain-names: + minItems: 2 + items: + - const: ans + - const: apcie0 + - const: apcie1 + + mboxes: + maxItems: 1 + description: Mailbox of the ANS2 co-processor + + interrupts: + maxItems: 1 + + apple,sart: + maxItems: 1 + $ref: /schemas/types.yaml#/definitions/phandle + description: | + Reference to the SART address filter. + + The SART address filter is documented in iommu/apple,sart.yaml. + +if: + properties: + compatible: + contains: + const: apple,t8103-nvme-ans2 +then: + properties: + power-domains: + maxItems: 2 + power-domain-names: + maxItems: 2 +else: + properties: + power-domains: + minItems: 3 + power-domain-names: + minItems: 3 + +required: + - compatible + - reg + - reg-names + - resets + - power-domains + - power-domain-names + - mboxes + - interrupts + - apple,sart + +additionalProperties: false + +examples: + - | + #include <dt-bindings/interrupt-controller/apple-aic.h> + #include <dt-bindings/interrupt-controller/irq.h> + + nvme@7bcc0000 { + compatible = "apple,t8103-nvme-ans2", "apple,nvme-ans2"; + reg = <0x7bcc0000 0x40000>, <0x77400000 0x4000>; + reg-names = "nvme", "ans"; + interrupts = <AIC_IRQ 590 IRQ_TYPE_LEVEL_HIGH>; + mboxes = <&ans>; + apple,sart = <&sart>; + power-domains = <&ps_ans2>, <&ps_apcie_st>; + power-domain-names = "ans", "apcie0"; + resets = <&ps_ans2>; + };
MAINTAINERS +1 -0
@@ -1838,6 +1838,7 @@ F: Documentation/devicetree/bindings/i2c/apple,i2c.yaml F: Documentation/devicetree/bindings/interrupt-controller/apple,* F: Documentation/devicetree/bindings/iommu/apple,sart.yaml F: Documentation/devicetree/bindings/mailbox/apple,mailbox.yaml +F: Documentation/devicetree/bindings/nvme/apple,nvme-ans.yaml F: Documentation/devicetree/bindings/pci/apple,pcie.yaml F: Documentation/devicetree/bindings/pinctrl/apple,pinctrl.yaml F: Documentation/devicetree/bindings/power/apple*
Signature · 1 line
2.25.1
PATCH v3 3/6 soc: apple: Always include Makefile
In reply to Sven PeterWe want to allow the code inside drivers/soc/apple to be compiled with COMPILE_TEST but this will currently result in linking errors because ARCH_APPLE is not set and make will never recurse into drivers/soc/apple.
Let's just unconditionally recurse into apple/ since all drivers in there are guarded by config options anyways.
---
no changes since v1
drivers/soc/Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/soc/Makefile +1 -1
@@ -4,7 +4,7 @@ # obj-$(CONFIG_ARCH_ACTIONS) += actions/ -obj-$(CONFIG_ARCH_APPLE) += apple/ +obj-y += apple/ obj-y += aspeed/ obj-$(CONFIG_ARCH_AT91) += atmel/ obj-y += bcm/
Signature · 1 line
2.25.1
PATCH v3 4/6 soc: apple: Add SART driver
In reply to Sven PeterThe NVMe co-processor on the Apple M1 uses a DMA address filter called SART for some DMA transactions. This adds a simple driver used to configure the memory regions from which DMA transactions are allowed.
Unlike a real IOMMU, SART does not support any pagetables and can't be implemented inside the IOMMU subsystem using iommu_ops.
It also can't be implemented using dma_map_ops since not all DMA transactions of the NVMe controller are filtered by SART. Instead, most buffers have to be registered using the integrated NVMe IOMMU and we can't have two separate dma_map_ops implementations for a single device.
---
v2 -> v3:
- Moved more shared code between SART2 and SART3 to sart_set_entry
v1 -> v2:
- Added explanation why this can't be an IOMMU or dma_map_ops implementation (Arnd Bergmann)
- Used non-relaxed accessors everwhere since the paths aren't performance critical (Arnd Bergmann)
- Fixed errno return values to be negative (Arnd Bergmann)
- apple_sart_get -> devm_apple_sart_get to add put_device
- Disallow using the interface without CONFIG_APPLE_SART and make all consumers hard-depend on that (Arnd Bergmann)
MAINTAINERS | 1 + drivers/soc/apple/Kconfig | 11 ++ drivers/soc/apple/Makefile | 3 + drivers/soc/apple/sart.c | 328 +++++++++++++++++++++++++++++++++ include/linux/soc/apple/sart.h | 57 ++++++ 5 files changed, 400 insertions(+) create mode 100644 drivers/soc/apple/sart.c create mode 100644 include/linux/soc/apple/sart.h
MAINTAINERS +1 -0
@@ -1855,6 +1855,7 @@ F: drivers/watchdog/apple_wdt.c F: include/dt-bindings/interrupt-controller/apple-aic.h F: include/dt-bindings/pinctrl/apple.h F: include/linux/apple-mailbox.h +F: include/linux/soc/apple/* ARM/ARTPEC MACHINE SUPPORT M: Jesper Nilsson <[email protected]>
drivers/soc/apple/Kconfig +11 -0
@@ -17,6 +17,17 @@ config APPLE_PMGR_PWRSTATE controls for SoC devices. This driver manages them through the generic power domain framework, and also provides reset support. +config APPLE_SART + tristate "Apple SART DMA address filter" + depends on ARCH_APPLE || COMPILE_TEST + default ARCH_APPLE + help + Apple SART is a simple DMA address filter used on Apple SoCs such + as the M1. It is usually required for the NVMe coprocessor which does + not use a proper IOMMU. + + Say 'y' here if you have an Apple SoC. + endmenu endif
drivers/soc/apple/Makefile +3 -0
@@ -1,2 +1,5 @@ # SPDX-License-Identifier: GPL-2.0-only obj-$(CONFIG_APPLE_PMGR_PWRSTATE) += apple-pmgr-pwrstate.o + +obj-$(CONFIG_APPLE_SART) += apple-sart.o +apple-sart-y = sart.o
drivers/soc/apple/sart.c new file +328 -0
328 lines not on this page · raw message
include/linux/soc/apple/sart.h new file +57 -0
57 lines not on this page · raw message
Signature · 1 line
2.25.1
Re: [PATCH v3 4/6] soc: apple: Add SART driver
Quoted 14 lines · Sven Peter
The NVMe co-processor on the Apple M1 uses a DMA address filter called SART for some DMA transactions. This adds a simple driver used to configure the memory regions from which DMA transactions are allowed.
Unlike a real IOMMU, SART does not support any pagetables and can't be implemented inside the IOMMU subsystem using
iommu_ops.It also can't be implemented using
dma_map_opssince not all DMA transactions of the NVMe controller are filtered by SART. Instead, most buffers have to be registered using the integrated NVMe IOMMU and we can't have two separatedma_map_opsimplementations for a single device.
Quoted 3 lines
Co-developed-by Hector Martin <[email protected]>Signed-off-by Hector Martin <[email protected]>Signed-off-by Sven Peter <[email protected]>
One more detail I noticed:
include/linux/soc/apple/sart.h line 31
Quoted 13 lines
include/linux/soc/apple/sart.h new file +13
-0+#if IS_ENABLED (CONFIG_APPLE_SART ) + +struct apple_sart ; + +/* +* Get a reference to the SART attached to dev. +* +* Looks for the phandle reference in apple,sart and returns a pointer +* to the corresponding apple_sart struct to be used with +* apple_sart_add_allowed_region and apple_sart_remove_allowed_region. +*/ +struct apple_sart *devm_apple_sart_get (struct device *dev); +
In general, I don't like to hide declarations in a header behind an #if. Unless there is a good reason for doing this, just make the declaration unconditional, which avoids recompiling when the symbol changes.
The only other effect is that you get a link-time error instead of a compile-time
error if you messed up the Kconfig dependencies, but as long as the dependencies are correct it will be fine either way.
Arnd
PATCH v3 5/6 soc: apple: Add RTKit IPC library
In reply to Sven PeterApple SoCs such as the M1 come with multiple embedded co-processors running proprietary firmware. Communication with those is established over a simple mailbox using the RTKit IPC protocol.
This cannot be implement inside the mailbox subsystem since on top of communication over channels we also need support for starting, hibernating and resetting these co-processors. We also need to handle shared memory allocations differently depending on the co-processor and don't want to split that across multiple drivers.
---
v2 -> v3:
- Used {GENMASK,BIT}_ULL to allow compile testing on 32bit as well
v1 -> v2:
- Replaced custom kthread with workqueue (Arnd Bergmann)
- Fixed indentation issues and un-exported apple_rtkit_init (Arnd Bergmann)
- Added explanation why this can't be easily implemented as a mailbox (Krzysztof Kozlowski)
- Removed redundant shmem_setup arguments (Arnd Bergmann)
- Removed custom rtk_{err,warn,...} macros (Arnd Bergmann)
- Disallow using the interface without CONFIG_APPLE_RTKIT and make all consumers hard-depend on that (Arnd Bergmann)
- Documented power states (Alyssa Rosenzweig)
- Made recv_message optional
- Added recv_message_early for clients that must handle messages inside atomic context
- Changed send_message to allow calling from atomic context
drivers/soc/apple/Kconfig | 13 + drivers/soc/apple/Makefile | 3 + drivers/soc/apple/rtkit-crashlog.c | 154 +++++ drivers/soc/apple/rtkit-internal.h | 62 ++ drivers/soc/apple/rtkit.c | 958 +++++++++++++++++++++++++++++ include/linux/soc/apple/rtkit.h | 159 +++++ 6 files changed, 1349 insertions(+) create mode 100644 drivers/soc/apple/rtkit-crashlog.c create mode 100644 drivers/soc/apple/rtkit-internal.h create mode 100644 drivers/soc/apple/rtkit.c create mode 100644 include/linux/soc/apple/rtkit.h
drivers/soc/apple/Kconfig +13 -0
@@ -17,6 +17,19 @@ config APPLE_PMGR_PWRSTATE controls for SoC devices. This driver manages them through the generic power domain framework, and also provides reset support. +config APPLE_RTKIT + tristate "Apple RTKit co-processor IPC protocol" + depends on MAILBOX + depends on ARCH_APPLE || COMPILE_TEST + default ARCH_APPLE + help + Apple SoCs such as the M1 come with various co-processors running + their proprietary RTKit operating system. This option enables support + for the protocol library used to communicate with those. It is used + by various client drivers. + + Say 'y' here if you have an Apple SoC. + config APPLE_SART tristate "Apple SART DMA address filter" depends on ARCH_APPLE || COMPILE_TEST
drivers/soc/apple/Makefile +3 -0
@@ -1,5 +1,8 @@ # SPDX-License-Identifier: GPL-2.0-only obj-$(CONFIG_APPLE_PMGR_PWRSTATE) += apple-pmgr-pwrstate.o +obj-$(CONFIG_APPLE_RTKIT) += apple-rtkit.o +apple-rtkit-y = rtkit.o rtkit-crashlog.o + obj-$(CONFIG_APPLE_SART) += apple-sart.o apple-sart-y = sart.o
drivers/soc/apple/rtkit-crashlog.c new file +154 -0
154 lines not on this page · raw message
drivers/soc/apple/rtkit-internal.h new file +62 -0
62 lines not on this page · raw message
drivers/soc/apple/rtkit.c new file +958 -0
958 lines not on this page · raw message
include/linux/soc/apple/rtkit.h new file +159 -0
159 lines not on this page · raw message
Signature · 1 line
2.25.1
Re: [PATCH v3 5/6] soc: apple: Add RTKit IPC library
Quoted 5 lines · Sven Peter
Apple SoCs such as the M1 come with multiple embedded co-processors running proprietary firmware. Communication with those is established over a simple mailbox using the RTKit IPC protocol.
Quoted 7 lines
This cannot be implement inside the mailbox subsystem since on top of communication over channels we also need support for starting, hibernating and resetting these co-processors. We also need to handle shared memory allocations differently depending on the co-processor and don't want to split that across multiple drivers.
Signed-off-by Sven Peter <[email protected]>
Quoted 7 lines
drivers/soc/apple/rtkit.c new file +7
-0+bool apple_rtkit_is_running (struct apple_rtkit *rtk) +{ +if (rtk->crashed) +return false; +if ((rtk->iop_power_state &0xff ) !=APPLE_RTKIT_PWR_STATE_ON ) +return false; +if ((rtk->ap_power_state &0xff ) !=APPLE_RTKIT_PWR_STATE_ON )
drivers/soc/apple/rtkit.c line 102
Quoted 10 lines
drivers/soc/apple/rtkit.c new file +10
-0+return false; +return true; +} +EXPORT_SYMBOL_GPL (apple_rtkit_is_running); + +bool apple_rtkit_is_crashed (struct apple_rtkit *rtk) +{ +return rtk->crashed; +} +EXPORT_SYMBOL_GPL (apple_rtkit_is_crashed);
I noticed that you use EXPORT_SYMBOL_GPL() here, but a more permissive EXPORT_SYMBOL() in the SART driver. Is that intentional? I would have assumed that both are similarly private to the apple SoCs and would be the _GPL type, but this is something you get to pick as the author.
include/linux/soc/apple/rtkit.h line 18
Quoted 3 lines
include/linux/soc/apple/rtkit.h new file +3
-0+ +#if IS_ENABLED (CONFIG_APPLE_RTKIT ) +
Same comment about the #if as for the SART driver: I'd prefer it without the conditional compilation.
Arnd
Re: [PATCH v3 5/6] soc: apple: Add RTKit IPC library
Quoted 12 lines · Arnd Bergmann
Quoted 11 lines · Sven Peter
Apple SoCs such as the M1 come with multiple embedded co-processors running proprietary firmware. Communication with those is established over a simple mailbox using the RTKit IPC protocol.
This cannot be implement inside the mailbox subsystem since on top of communication over channels we also need support for starting, hibernating and resetting these co-processors. We also need to handle shared memory allocations differently depending on the co-processor and don't want to split that across multiple drivers.
Quoted 4 lines
Quoted 1 line
Signed-off-by Sven Peter <[email protected]>Reviewed-by Arnd Bergmann <[email protected]>
thanks!
Quoted 12 lines
Quoted 12 lines
drivers/soc/apple/rtkit.c new file +12
-0+bool apple_rtkit_is_running (struct apple_rtkit *rtk) +{ +if (rtk->crashed) +return false; +if ((rtk->iop_power_state &0xff ) !=APPLE_RTKIT_PWR_STATE_ON ) +return false; +if ((rtk->ap_power_state &0xff ) !=APPLE_RTKIT_PWR_STATE_ON ) +return false; +return true; +} +EXPORT_SYMBOL_GPL (apple_rtkit_is_running); +
Quoted 8 lines
drivers/soc/apple/rtkit.c line 102
Quoted 5 lines
drivers/soc/apple/rtkit.c new file +5
-0+bool apple_rtkit_is_crashed (struct apple_rtkit *rtk) +{ +return rtk->crashed; +} +EXPORT_SYMBOL_GPL (apple_rtkit_is_crashed);I noticed that you use
EXPORT_SYMBOL_GPL()here, but a more permissiveEXPORT_SYMBOL()in the SART driver. Is that intentional?
No idea why I used both but it wasn't intentional. I'll change all exports to EXPORT_SYMBOL_GPL.
Quoted 7 lines
include/linux/soc/apple/rtkit.h line 18
Quoted 4 lines
include/linux/soc/apple/rtkit.h new file +3
-0+ +#if IS_ENABLED (CONFIG_APPLE_RTKIT ) +Same comment about the #if as for the SART driver: I'd prefer it without the conditional compilation.
Ok, will remove those #ifs as well.
Sven
PATCH v3 6/6 nvme-apple: Add initial Apple SoC NVMe driver
In reply to Sven PeterApple SoCs such as the M1 come with an embedded NVMe controller that is not attached to any PCIe bus. Additionally, it doesn't conform to the NVMe specification and requires a bunch of changes to command submission and IOMMU configuration to work.
---
v2 -> v3:
- Used readq/writeq instead of lo_hi_writeq since the controller supports 64 bit MMIO access (Christoph Hellwig) but kept the io-64-nonatomic-lo-hi.h include to still allow compile testing on 32bit (Arnd Bergmann)
- Added missing ret = in front of dev_err_probe
- Added Christoph's r-b tag
v1 -> v2:
- Used non-relaxed accessors everywhere since there's no performance difference (Arnd Bergmann)
- Added put_device/get_device to tie the nvme_ctrl device to the platform device (Christoph Hellwig)
- Removed unneccesary include and DEBUG #define (Christoph Hellwig)
- Use nvme_is_write instead of custom #defines (Christoph Hellwig)
- Squashed follow-up commits into this one (Christoph Hellwig)
- Initialize cq_phase during queue allocation already to make it's not interpreted as a full cq if anything before queue initialization fails.
MAINTAINERS | 1 + drivers/nvme/host/Kconfig | 13 + drivers/nvme/host/Makefile | 3 + drivers/nvme/host/apple.c | 1598 ++++++++++++++++++++++++++++++++++++ 4 files changed, 1615 insertions(+) create mode 100644 drivers/nvme/host/apple.c
MAINTAINERS +1 -0
@@ -1849,6 +1849,7 @@ F: drivers/i2c/busses/i2c-pasemi-core.c F: drivers/i2c/busses/i2c-pasemi-platform.c F: drivers/irqchip/irq-apple-aic.c F: drivers/mailbox/apple-mailbox.c +F: drivers/nvme/host/apple.c F: drivers/pinctrl/pinctrl-apple-gpio.c F: drivers/soc/apple/* F: drivers/watchdog/apple_wdt.c
drivers/nvme/host/Kconfig +13 -0
@@ -91,3 +91,16 @@ config NVME_TCP from https://github.com/linux-nvme/nvme-cli. If unsure, say N. + +config NVME_APPLE + tristate "Apple ANS2 NVM Express host driver" + depends on OF && BLOCK + depends on APPLE_RTKIT && APPLE_SART + depends on ARCH_APPLE || COMPILE_TEST + select NVME_CORE + help + This provides support for the NVMe controller embedded in Apple SoCs + such as the M1. + + To compile this driver as a module, choose M here: the + module will be called nvme-apple.
drivers/nvme/host/Makefile +3 -0
@@ -8,6 +8,7 @@ obj-$(CONFIG_NVME_FABRICS) += nvme-fabrics.o obj-$(CONFIG_NVME_RDMA) += nvme-rdma.o obj-$(CONFIG_NVME_FC) += nvme-fc.o obj-$(CONFIG_NVME_TCP) += nvme-tcp.o +obj-$(CONFIG_NVME_APPLE) += nvme-apple.o nvme-core-y := core.o ioctl.o constants.o nvme-core-$(CONFIG_TRACING) += trace.o
@@ -25,3 +26,5 @@ nvme-rdma-y += rdma.o nvme-fc-y += fc.o nvme-tcp-y += tcp.o + +nvme-apple-y += apple.o
drivers/nvme/host/apple.c new file +1598 -0
1,598 lines not on this page · raw message
Signature · 1 line
2.25.1
Keith Busch
maintainerRe: [PATCH v3 6/6] nvme-apple: Add initial Apple SoC NVMe driver
Quoted 21 lines · Sven Peter
drivers/nvme/host/apple.c new file +21
-0+static enum blk_eh_timer_return apple_nvme_timeout (struct request *req, +bool reserved) +{ +struct apple_nvme_iod *iod =blk_mq_rq_to_pdu (req); +struct apple_nvme_queue *q = iod->q; +struct apple_nvme *anv =queue_to_apple_nvme (q); +unsigned long flags; +u32 csts =readl (anv->mmio_nvme +NVME_REG_CSTS ); + +if (anv->ctrl.state !=NVME_CTRL_LIVE ) { +/* +* From rdma.c: +* If we are resetting, connecting or deleting we should +* complete immediately because we may block controller +* teardown or setup sequence +* - ctrl disable/shutdown fabrics requests +* - connect requests +* - initialization admin requests +* - I/O requests that entered after unquiescing and +* the controller stopped responding +*
drivers/nvme/host/apple.c line 895
Quoted 10 lines
drivers/nvme/host/apple.c new file +10
-0+* All other requests should be cancelled by the error +* recovery work, so it's fine that we fail it here. +*/ +dev_warn (anv->dev, +"I/O %d(aq:%d) timeout while not in live state\n" , + req->tag, q->is_adminq); +if (blk_mq_request_started (req) && + !blk_mq_request_completed (req)) { +nvme_req (req)->status =NVME_SC_HOST_ABORTED_CMD ; +blk_mq_complete_request (req);
I think you need a 'nvme_req(req)->flags |= NVME_REQ_CANCELLED' here to get the expected -EINTR for any admin command timeouts during a reset. Without it, the resetting task is going to think it got a real response from the controller.
Other than that, this looks good.
Re: [PATCH v3 6/6] nvme-apple: Add initial Apple SoC NVMe driver
Quoted 28 lines · Keith Busch
Quoted 27 lines · Sven Peter
drivers/nvme/host/apple.c new file +27
-0+static enum blk_eh_timer_return apple_nvme_timeout (struct request *req, +bool reserved) +{ +struct apple_nvme_iod *iod =blk_mq_rq_to_pdu (req); +struct apple_nvme_queue *q = iod->q; +struct apple_nvme *anv =queue_to_apple_nvme (q); +unsigned long flags; +u32 csts =readl (anv->mmio_nvme +NVME_REG_CSTS ); + +if (anv->ctrl.state !=NVME_CTRL_LIVE ) { +/* +* From rdma.c: +* If we are resetting, connecting or deleting we should +* complete immediately because we may block controller +* teardown or setup sequence +* - ctrl disable/shutdown fabrics requests +* - connect requests +* - initialization admin requests +* - I/O requests that entered after unquiescing and +* the controller stopped responding +* +* All other requests should be cancelled by the error +* recovery work, so it's fine that we fail it here. +*/ +dev_warn (anv->dev, +"I/O %d(aq:%d) timeout while not in live state\n" , + req->tag, q->is_adminq);
Quoted 8 lines
drivers/nvme/host/apple.c line 895
Quoted 4 lines
drivers/nvme/host/apple.c new file +4
-0+if (blk_mq_request_started (req) && + !blk_mq_request_completed (req)) { +nvme_req (req)->status =NVME_SC_HOST_ABORTED_CMD ; +blk_mq_complete_request (req);I think you need a 'nvme_req(req)->flags |=
NVME_REQ_CANCELLED' here to get the expected-EINTRfor any admin command timeouts during a reset. Without it, the resetting task is going to think it got a real response from the controller.
Makes sense, will add it.
Sven
Re: [PATCH v3 6/6] nvme-apple: Add initial Apple SoC NVMe driver
In reply to Sven PeterQuoted 8 lines · Sven Peter
Apple SoCs such as the M1 come with an embedded NVMe controller that is not attached to any PCIe bus. Additionally, it doesn't conform to the NVMe specification and requires a bunch of changes to command submission and IOMMU configuration to work.
Reviewed-by Christoph Hellwig <[email protected]>Signed-off-by Sven Peter <[email protected]>
I did not do a detailed review of this again, but the previous version seemed mostly fine already.
One suggestion for a very minor improvement:
Quoted 3 lines
drivers/nvme/host/apple.c new file +3
-0+#ifdef CONFIG_PM_SLEEP +static int apple_nvme_resume (struct device *dev) +{
...
Quoted 12 lines
drivers/nvme/host/apple.c new file +12
-0+} + +static const struct dev_pm_ops apple_nvme_pm_ops = { + .suspend = apple_nvme_suspend, + .resume = apple_nvme_resume, +}; +#endif + +static const struct of_device_id apple_nvme_of_match[] = { + { .compatible ="apple,nvme-ans2" }, + {}, +};
drivers/nvme/host/apple.c line 1590
Quoted 10 lines
drivers/nvme/host/apple.c new file +10
-0+MODULE_DEVICE_TABLE (of, apple_nvme_of_match); + +static struct platform_driver apple_nvme_driver = { + .driver = { + .name ="nvme-apple" , + .of_match_table = apple_nvme_of_match, +#ifdef CONFIG_PM_SLEEP + .pm = &apple_nvme_pm_ops, +#endif + },
You can now use "static DEFINE_SIMPLE_DEV_PM_OPS()" to define the pm operations without these #ifdefs.
Arnd
Quoted 11 lines · Sven Peter
Hi,
This series includes everything[*] required to get NVMe up and running on Apple's M1, M1 Pro and M1 Max SoCs.
v1: https://lore.kernel.org/linux-nvme/[email protected]/T/
v2: https://lore.kernel.org/linux-nvme/[email protected]/T/Thanks everyone for the reviews of v2 again! There are just some minor changes since v2 listed in the individual commits again.
Nice! I had not looked at v2 in much detail, but I'm perfectly happy with this version,
I found a few things that could be improved if you do a respin, but nothing important.
Quoted 4 lines
[*] The only missing part in this series are the device tree updates
but since these will go through arm-soc anyway I haven't included them here but will instead submit them once this series is in a shape where it can be merged.
Just as a clarification: the drivers/soc/ portion should normally go through the soc tree as well, but I'm happy for those to get merged along with the nvme driver
if that helps get it all mainlined more quickly.
Arnd
Quoted 10 lines · Arnd Bergmann
Quoted 9 lines · Sven Peter
Hi,
This series includes everything[*] required to get NVMe up and running on Apple's M1, M1 Pro and M1 Max SoCs.
v1: https://lore.kernel.org/linux-nvme/[email protected]/T/
v2: https://lore.kernel.org/linux-nvme/[email protected]/T/
Quoted 8 lines
Quoted 2 lines
Thanks everyone for the reviews of v2 again! There are just some minor changes since v2 listed in the individual commits again.
Nice! I had not looked at v2 in much detail, but I'm perfectly happy with this version,
I found a few things that could be improved if you do a respin, but nothing important.
Thanks, I'll respin it later this week to fix those things!
Quoted 10 lines
Quoted 5 lines
[*] The only missing part in this series are the device tree updates
but since these will go through arm-soc anyway I haven't included them here but will instead submit them once this series is in a shape where it can be merged.Just as a clarification: the
drivers/soc/portion should normally go through the soc tree as well, but I'm happy for those to get merged along with the nvme driver
if that helps get it all mainlined more quickly.
Makes sense!
I don't think I'll be ready to submit USB3/USB4/Thunderbolt (which also needs RTKit) during this cycle but I think there's a decent chance marcan will submit SMC which also depends on RTKit and will go through a different subsystem. What's the best way to handle the RTKit commits in that case?
It would be great if we could get both into 5.19.
Sven
Quoted 9 lines · Sven Peter
Quoted 1 line · Arnd Bergmann
On Tue, Apr 26, 2022 at 10:15 PM Sven Peter <[email protected]> wrote:
Makes sense!
I don't think I'll be ready to submit USB3/USB4/Thunderbolt (which also needs RTKit) during this cycle but I think there's a decent chance marcan will submit SMC which also depends on RTKit and will go through a different subsystem. What's the best way to handle the RTKit commits in that case?
It would be great if we could get both into 5.19.
The usual trick is to have a branch with the shared patches and have that pulled into every other tree that needs these, but make sure you never rebase. In this case, you could have something like
a) rtkit driver in a shared branch (private only)
b) thunderbolt driver based on branch a), merged through thunderbolt/usb/pci tree (I don't know who is responsible here)
c) sart driver based on branch a), merged through soc tree
d) nvme driver based on branch c), merged through nvme tree
since the commit hashes are all identical, each patch only shows up in the git tree once, but you get a somewhat funny history.
Arnd
[email protected]
maintainerQuoted 4 lines · Arnd Bergmann
The usual trick is to have a branch with the shared patches and have that pulled into every other tree that needs these, but make sure you never rebase. In this case, you could have something like
Quoted 8 lines
a) rtkit driver in a shared branch (private only)
b) thunderbolt driver based on branch a), merged through thunderbolt/usb/pci tree (I don't know who is responsible here)
c) sart driver based on branch a), merged through soc tree
d) nvme driver based on branch c), merged through nvme treesince the commit hashes are all identical, each patch only shows up in the git tree once, but you get a somewhat funny history.
Given that the nvme driver is just addition of new code I'm perfectly fine with sending it through whatever tree is most convenient.
Quoted 11 lines · On Thu, Apr 28, 2022, at 16:24, [email protected] wrote:
Quoted 10 lines · Arnd Bergmann
The usual trick is to have a branch with the shared patches and have that pulled into every other tree that needs these, but make sure you never rebase. In this case, you could have something like
a) rtkit driver in a shared branch (private only)
b) thunderbolt driver based on branch a), merged through thunderbolt/usb/pci tree (I don't know who is responsible here)
c) sart driver based on branch a), merged through soc tree
d) nvme driver based on branch c), merged through nvme tree
Quoted 5 lines
Quoted 2 lines
since the commit hashes are all identical, each patch only shows up in the git tree once, but you get a somewhat funny history.
Given that the nvme driver is just addition of new code I'm perfectly fine with sending it through whatever tree is most convenient.
So If I understand all this correctly either
1) I send a pull request with rtkit+sart to Arnd/soc@ followed by a pull request with the same commits + the nvme driver to Christoph/nvme to make sure the commit hashes in both trees are the same.
or
2) I send a pull request with rtkit+sart+nvme to soc@ and we take the entire driver through there with Christoph's ack if Arnd is fine with carrying it as well.
In either case SMC (or thunderbolt if I finish in time) can also be based on the same rtkit commit and could go into 5.19 as well.
I don't have any preference here (not that my opinion matters much for this decision anyway :-))
Sven
Quoted 28 lines · Sven Peter
Quoted 11 lines · On Thu, Apr 28, 2022, at 16:24, [email protected] wrote:
Quoted 10 lines · Arnd Bergmann
The usual trick is to have a branch with the shared patches and have that pulled into every other tree that needs these, but make sure you never rebase. In this case, you could have something like
a) rtkit driver in a shared branch (private only)
b) thunderbolt driver based on branch a), merged through thunderbolt/usb/pci tree (I don't know who is responsible here)
c) sart driver based on branch a), merged through soc tree
d) nvme driver based on branch c), merged through nvme treeQuoted 5 lines
Quoted 2 lines
since the commit hashes are all identical, each patch only shows up in the git tree once, but you get a somewhat funny history.
Given that the nvme driver is just addition of new code I'm perfectly fine with sending it through whatever tree is most convenient.
So If I understand all this correctly either
1) I send a pull request with rtkit+sart to Arnd/soc@ followed by a pull request with the same commits + the nvme driver to Christoph/nvme to make sure the commit hashes in both trees are the same.
or
2) I send a pull request with rtkit+sart+nvme to soc@ and we take the entire driver through there with Christoph's ack if Arnd is fine with carrying it as well.
Quoted 4 lines
In either case SMC (or thunderbolt if I finish in time) can also be based on the same rtkit commit and could go into 5.19 as well.
I don't have any preference here (not that my opinion matters much for this decision anyway :-))
Correct, those are both ok.
Arnd