Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PCIe/NVMe Driver #283

Draft
wants to merge 60 commits into
base: main
Choose a base branch
from
Draft

PCIe/NVMe Driver #283

wants to merge 60 commits into from

Conversation

midnightveil
Copy link
Contributor

@midnightveil midnightveil commented Nov 11, 2024

This is very draft and a WIP, notably that it doesn't seem to work in RISC-V platforms1. It also doesn't do any PCIe initialisation of which there is a significant amount.

Just creating this so this branch isn't lost.

U-Boot patch for PCI on imx8mm
diff --git a/configs/imx8mm_evk_defconfig b/configs/imx8mm_evk_defconfig
index 1a15292e2f..83e1999648 100644
--- a/configs/imx8mm_evk_defconfig
+++ b/configs/imx8mm_evk_defconfig
@@ -121,3 +121,20 @@ CONFIG_SDP_LOADADDR=0x40400000
 CONFIG_USB_GADGET_DOWNLOAD=y
 CONFIG_SPL_USB_SDP_SUPPORT=y
 CONFIG_IMX_WATCHDOG=y
+
+
+CONFIG_CMD_PCI=y
+CONFIG_PCI=y
+CONFIG_PCIE_DW_IMX=y
+CONFIG_SYS_PCI_64BIT=y
+CONFIG_CMD_NVME=y
+CONFIG_NVME=y
+CONFIG_NVME_PCI=y
+CONFIG_DM_PCI_COMPAT=y
+CONFIG_PCIE_DW_COMMON=y
+CONFIG_DM_RESET=y
+CONFIG_PHY_IMX8M_PCIE=y
+CONFIG_REGMAP=y
+CONFIG_SYSCON=y
+CONFIG_SPL_SYSCON=y
+CONFIG_SPL_REGMAP=y
diff --git a/drivers/pci/pcie_dw_imx.c b/drivers/pci/pcie_dw_imx.c
index fdb463710b..bab65939da 100644
--- a/drivers/pci/pcie_dw_imx.c
+++ b/drivers/pci/pcie_dw_imx.c
@@ -212,8 +212,15 @@ static int pcie_dw_imx_probe(struct udevice *dev)

        if (pcie_link_up(priv, LINK_SPEED_GEN_1)) {
                printf("PCIE-%d: Link down\n", dev_seq(dev));
-               ret = -ENODEV;
-               goto err_link;
+               printf("...ignoring, trying again\n");
+               // ret = -ENODEV;
+               // goto err_link;
+
+               for (int i = 0; i < 10; i++) {
+                       if (wait_link_up(priv)) {
+                               mdelay(90);
+                       }
+               }
        }

        printf("PCIE-%d: Link up (Gen%d-x%d, Bus%d)\n", dev_seq(dev),

Footnotes

  1. Infinite stream of interrupts (Star64) or only one interrupt even if not deasserted (QEMU). Not sure what's wrong with QEMU (maybe this?). Need to try figuring out the meaning of the platform-specific device registers for PCIe on the Star64 to see if there's some way of ACKing interrupts there (U-Boot somewhat knows about these)

Ivan-Velickovic and others added 30 commits November 8, 2024 14:28
Signed-off-by: julia <git.ts@trainwit.ch>
Signed-off-by: julia <git.ts@trainwit.ch>
Signed-off-by: julia <git.ts@trainwit.ch>
Signed-off-by: julia <git.ts@trainwit.ch>
Signed-off-by: julia <git.ts@trainwit.ch>
Signed-off-by: julia <git.ts@trainwit.ch>
Signed-off-by: julia <git.ts@trainwit.ch>
Signed-off-by: julia <git.ts@trainwit.ch>
Signed-off-by: Ivan Velickovic <i.velickovic@unsw.edu.au>
Signed-off-by: julia <git.ts@trainwit.ch>
Signed-off-by: julia <git.ts@trainwit.ch>
Signed-off-by: julia <git.ts@trainwit.ch>
Signed-off-by: julia <git.ts@trainwit.ch>
Signed-off-by: julia <git.ts@trainwit.ch>
Signed-off-by: julia <git.ts@trainwit.ch>
Signed-off-by: julia <git.ts@trainwit.ch>
Signed-off-by: julia <git.ts@trainwit.ch>
Signed-off-by: julia <git.ts@trainwit.ch>
Signed-off-by: julia <git.ts@trainwit.ch>
Signed-off-by: julia <git.ts@trainwit.ch>
Signed-off-by: julia <git.ts@trainwit.ch>
Signed-off-by: julia <git.ts@trainwit.ch>
Signed-off-by: julia <git.ts@trainwit.ch>
Signed-off-by: julia <git.ts@trainwit.ch>
turns out I was setting the "host page size" config bits incorrectly,
specifying a required page size alignment of 2^13 (i.e. 0x2000, not
0x1000).

the first queue was aligned to that, the second was not and was failing.
at some point i tried using the same queu eaddress for creating both
queues and that worked; so I went "is this some sort of alignment
issue?" and went off diving into u-boot to discover it aligns dma
buffers to 32bytes which didn't help since they were both page aligned
anyway. anyway so i then just started progressively masking off higher
and higher bits until the difference between 0x40283000 and 0x40282000
was that one bit

and then i was like ??? wtf went scouring through nvme docs, only
alignment i could find was dword aligned... then i realised that was
mostly talking about PRP entries (scatter-gather list dma) meanwhile i
was using just contiguous dma because easier, which references CC.MPS...
which i then looked and i thought just doing PAGE_SIZE >> 12 seemed off
cause 0x1000 >> 12 = 0x1 and 2^(12 + CC.MPS) is 2^13. and i realised it
wanted a log2 value not a shifted value

Signed-off-by: julia <git.ts@trainwit.ch>
Signed-off-by: julia <git.ts@trainwit.ch>
this traps with unimp :(

Signed-off-by: julia <git.ts@trainwit.ch>
.. or being entirely optimised out

https://cerberus.cl.cam.ac.uk/?short/cea8cb

this is undefined behaviour. god I love C

Signed-off-by: julia <git.ts@trainwit.ch>
Signed-off-by: julia <git.ts@trainwit.ch>
Signed-off-by: julia <git.ts@trainwit.ch>
Signed-off-by: julia <git.ts@trainwit.ch>
Signed-off-by: julia <git.ts@trainwit.ch>
Signed-off-by: julia <git.ts@trainwit.ch>
Signed-off-by: julia <git.ts@trainwit.ch>
Signed-off-by: julia <git.ts@trainwit.ch>
Signed-off-by: julia <git.ts@trainwit.ch>
Signed-off-by: julia <git.ts@trainwit.ch>
Signed-off-by: julia <git.ts@trainwit.ch>
Signed-off-by: julia <git.ts@trainwit.ch>
Signed-off-by: julia <git.ts@trainwit.ch>
these are undefined by PCIe/NVMe specs

Signed-off-by: julia <git.ts@trainwit.ch>
Signed-off-by: julia <git.ts@trainwit.ch>
Signed-off-by: julia <git.ts@trainwit.ch>
…upt sonce???? even though it should do forever???)

https://www.mail-archive.com/qemu-devel@nongnu.org/msg931360.html

might be this bug

Signed-off-by: julia <git.ts@trainwit.ch>
Signed-off-by: julia <git.ts@trainwit.ch>
Signed-off-by: julia <git.ts@trainwit.ch>
Signed-off-by: julia <git.ts@trainwit.ch>
Signed-off-by: julia <git.ts@trainwit.ch>
Signed-off-by: julia <git.ts@trainwit.ch>
Signed-off-by: julia <git.ts@trainwit.ch>
Signed-off-by: julia <git.ts@trainwit.ch>
Signed-off-by: julia <git.ts@trainwit.ch>
Signed-off-by: julia <git.ts@trainwit.ch>
Signed-off-by: julia <git.ts@trainwit.ch>
Signed-off-by: julia <git.ts@trainwit.ch>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants