Skip to contentSkip to conversation

NTB: Add support for AMD PCI-Express Non-Transparent Bridge

PATCH Superseded Xiangliang Yu 2 participants 7 messages Jan 21, 2016

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH v5 1/1 NTB: Add support for AMD PCI-Express Non-Transparent Bridge

This adds support for AMD's PCI-Express Non-Transparent Bridge (NTB) device on the Zeppelin platform. The driver connnects to the standard NTB sub-system interface, with modification to add hooks for power management in a separate patch. The AMD NTB device has 3 memory windows, 16 doorbell, 16 scratch-pad registers, and supports up to 16 PCIe lanes running a Gen3 speeds.

---
 MAINTAINERS                     |    6 +
 drivers/ntb/hw/Kconfig          |    1 +
 drivers/ntb/hw/Makefile         |    1 +
 drivers/ntb/hw/amd/Kconfig      |    7 +
 drivers/ntb/hw/amd/Makefile     |    1 +
 drivers/ntb/hw/amd/ntb_hw_amd.c | 1143 +++++++++++++++++++++++++++++++++++++++
 drivers/ntb/hw/amd/ntb_hw_amd.h |  217 ++++++++
 7 files changed, 1376 insertions(+)
 create mode 100644 drivers/ntb/hw/amd/Kconfig
 create mode 100644 drivers/ntb/hw/amd/Makefile
 create mode 100644 drivers/ntb/hw/amd/ntb_hw_amd.c
 create mode 100644 drivers/ntb/hw/amd/ntb_hw_amd.h
MAINTAINERS +6 -0
index 5192700..908941a 100644
@@ -7585,6 +7585,12 @@ W:	https://github.com/jonmason/ntb/wiki
 T:	git git://github.com/jonmason/ntb.git
 F:	drivers/ntb/hw/intel/
 
+NTB AMD DRIVER
+M:	Xiangliang Yu <[email protected]>
+L:	[email protected]
+S:	Supported
+F:	drivers/ntb/hw/amd/
+
 NTFS FILESYSTEM
 M:	Anton Altaparmakov <[email protected]>
 L:	[email protected]
drivers/ntb/hw/Kconfig +1 -0
index 4d5535c..7116472 100644
@@ -1 +1,2 @@
+source "drivers/ntb/hw/amd/Kconfig"
 source "drivers/ntb/hw/intel/Kconfig"
drivers/ntb/hw/Makefile +1 -0
index 175d7c9..532e085 100644
@@ -1 +1,2 @@
+obj-$(CONFIG_NTB_AMD)	+= amd/
 obj-$(CONFIG_NTB_INTEL)	+= intel/
drivers/ntb/hw/amd/Kconfig new file +7 -0
new file mode 100644
index 0000000..cfe903c
@@ -0,0 +1,7 @@
+config NTB_AMD
+	tristate "AMD Non-Transparent Bridge support"
+	depends on X86_64
+	help
+	 This driver supports AMD NTB on capable Zeppelin hardware.
+
+	 If unsure, say N.
drivers/ntb/hw/amd/Makefile new file +1 -0
new file mode 100644
index 0000000..ad54da9
@@ -0,0 +1 @@
+obj-$(CONFIG_NTB_AMD) += ntb_hw_amd.o
drivers/ntb/hw/amd/ntb_hw_amd.c new file +1143 -0

1,143 lines not on this page · raw message

drivers/ntb/hw/amd/ntb_hw_amd.h new file +217 -0

217 lines not on this page · raw message

Signature · 1 line
1.9.1
#1 lore raw

From: Xiangliang Yu [mailto:[email protected]]

Quoted 7 lines

This adds support for AMD's PCI-Express Non-Transparent Bridge (NTB) device on the Zeppelin platform. The driver connnects to the standard NTB sub-system interface, with modification to add hooks for power management in a separate patch. The AMD NTB device has 3 memory windows, 16 doorbell, 16 scratch-pad registers, and supports up to 16 PCIe lanes running a Gen3 speeds.

Quoted 5 lines

Hold on a sec... what? Who? I don't remember signing off on this.

Signed-off-by has legal implications with regards to the developer certificate of origin. Please don't just put names on stuff! It's forgery!

#2 lore raw
Quoted 21 lines

-----Original Message-----
From: Hubbe, Allen [mailto:[email protected]]
Sent: Thursday, January 21, 2016 11:54 AM
To: Yu, Xiangliang; [email protected]; [email protected]; linux- [email protected]; [email protected]
Cc: SPG_Linux_Kernel
Subject: RE: [PATCH V5 1/1] NTB: Add support for AMD PCI-Express Non- Transparent Bridge

From: Xiangliang Yu [mailto:[email protected]]

Quoted 4 lines

This adds support for AMD's PCI-Express Non-Transparent Bridge (NTB) device on the Zeppelin platform. The driver connnects to the standard NTB sub-system interface, with modification to add hooks for power management in a separate patch. The AMD NTB device has 3

memory

Quoted 4 lines

windows, 16 doorbell, 16 scratch-pad registers, and supports up to 16 PCIe lanes running a Gen3 speeds.

Quoted 7 lines
Quoted 2 lines

Hold on a sec... what? Who? I don't remember signing off on this.

Signed-off-by has legal implications with regards to the developer certificate of origin. Please don't just put names on stuff! It's forgery!

Please help change it to reviewer-by when applying it. Thanks!

#3 lore raw
In reply to Xiangliang Yu

From: Xiangliang Yu <[email protected]>

Quoted 11 lines

This adds support for AMD's PCI-Express Non-Transparent Bridge (NTB) device on the Zeppelin platform. The driver connnects to the standard NTB sub-system interface, with modification to add hooks for power management in a separate patch. The AMD NTB device has 3 memory windows, 16 doorbell, 16 scratch-pad registers, and supports up to 16 PCIe lanes running a Gen3 speeds.

NO.

Quoted 6 lines
drivers/ntb/hw/amd/ntb_hw_amd.c new file +6 -0
+		/* set and verify setting the translation address */
+		write64(addr, peer_mmio + xlat_reg);
+		reg_val = read64(peer_mmio + xlat_reg);
+		if (reg_val != addr) {
+			write64(0, peer_mmio + xlat_reg);
+			return -EIO;

drivers/ntb/hw/amd/ntb_hw_amd.c line 191

Quoted 10 lines
drivers/ntb/hw/amd/ntb_hw_amd.c new file +10 -0
+		}
+
+		/* set and verify setting the limit */
+		writel(limit, mmio + limit_reg);
+		reg_val = readl(mmio + limit_reg);
+		if (reg_val != limit) {
+			writel(base_addr, mmio + limit_reg);
+			writel(0, peer_mmio + xlat_reg);
+			return -EIO;
+		}

I see what you did there, change iowrite64 to write64.

What I meant was:
- change readl to ioread32.
- change writel to iowrite32.
- change readb, readw, writeb, writew (if there are any)
- leave ioread64 and iowrite64 as they were.

Why: http://www.makelinux.net/ldd3/chp-9-sect-4

Quote: "If you read through the kernel source, you see many calls to an older set of functions when I/O memory is being used. These functions still work, but their use in new code is discouraged. Among other things, they are less safe because they do not perform the same sort of type checking."

The "older set of functions" are read[bwl], write[bwl]. This is a new driver, with all new code. Please use the ioread/iowrite variants.

Quoted 8 lines
drivers/ntb/hw/amd/ntb_hw_amd.c new file +8 -0
+static int amd_link_is_up(struct amd_ntb_dev *ndev)
+{
+	if (!ndev->peer_sta)
+		return NTB_LNK_STA_ACTIVE(ndev->cntl_sta);
+
+	/* If peer_sta is reset or D0 event, the ISR has
+	 * started a timer to check link status of hardware.
+	 * So here just clear status bit. And if peer_sta is

drivers/ntb/hw/amd/ntb_hw_amd.c line 214

Quoted 10 lines
drivers/ntb/hw/amd/ntb_hw_amd.c new file +10 -0
+	 * D3 or PME_TO, D0/reset event will be happened when
+	 * system wakeup/poweron, so do nothing here.
+	 */
+	if (ndev->peer_sta & AMD_PEER_RESET_EVENT)
+		ndev->peer_sta &= ~AMD_PEER_RESET_EVENT;
+	else if (ndev->peer_sta & AMD_PEER_D0_EVENT)
+		ndev->peer_sta = 0;
+
+	return 0;
+}

Thanks. This is much better.

Quoted 1 line

+static void amd_handle_event(struct amd_ntb_dev *ndev, int vec)

...

Quoted 1 line
drivers/ntb/hw/amd/ntb_hw_amd.c new file +1 -0
+	case AMD_PEER_D0_EVENT:

...

drivers/ntb/hw/amd/ntb_hw_amd.c line 541

Quoted 3 lines
drivers/ntb/hw/amd/ntb_hw_amd.c new file +3 -0
+		/* start a timer to poll link status */
+		schedule_delayed_work(&ndev->hb_timer,
+					      AMD_LINK_HB_TIMEOUT);

This is different from v4. It used to be:

if (amd_link_is_up())

	ntb_link_event();
else
	schedule_delayed_work();

Why is v5 correct?
Why was v4 incorrect?

I'm nervous about ndev->peer_sta, the behavior of link_is_up, timers... unexplained changes to a fragile bit of code - not just this code, but any code that deals with parallel or asynchronous behaviors. With the comment in link_is_up, this code is much better, but any changes to this whole link state mechanism need to be explained.

Allen

#4 lore raw
Quoted 11 lines

From: Xiangliang Yu <[email protected]>

Quoted 4 lines

This adds support for AMD's PCI-Express Non-Transparent Bridge (NTB) device on the Zeppelin platform. The driver connnects to the standard NTB sub-system interface, with modification to add hooks for power management in a separate patch. The AMD NTB device has 3

memory

Quoted 3 lines

windows, 16 doorbell, 16 scratch-pad registers, and supports up to 16 PCIe lanes running a Gen3 speeds.

Quoted 6 lines
Quoted 4 lines

NO.

Ok, I'll change it if you doesn't want to change it.

Quoted 28 lines
Quoted 7 lines
drivers/ntb/hw/amd/ntb_hw_amd.c new file +6 -0
+		/* set and verify setting the translation address */
+		write64(addr, peer_mmio + xlat_reg);
+		reg_val = read64(peer_mmio + xlat_reg);
+		if (reg_val != addr) {
+			write64(0, peer_mmio + xlat_reg);
+			return -EIO;

drivers/ntb/hw/amd/ntb_hw_amd.c line 191

Quoted 10 lines
drivers/ntb/hw/amd/ntb_hw_amd.c new file +10 -0
+		}
+
+		/* set and verify setting the limit */
+		writel(limit, mmio + limit_reg);
+		reg_val = readl(mmio + limit_reg);
+		if (reg_val != limit) {
+			writel(base_addr, mmio + limit_reg);
+			writel(0, peer_mmio + xlat_reg);
+			return -EIO;
+		}

I see what you did there, change iowrite64 to write64.

What I meant was:
- change readl to ioread32.
- change writel to iowrite32.
- change readb, readw, writeb, writew (if there are any)
- leave ioread64 and iowrite64 as they were.

Why: http://www.makelinux.net/ldd3/chp-9-sect-4

Quoted 7 lines

Quote: "If you read through the kernel source, you see many calls to an older set of functions when I/O memory is being used. These functions still work, but their use in new code is discouraged. Among other things, they are less safe because they do not perform the same sort of type checking."

The "older set of functions" are read[bwl], write[bwl]. This is a new driver, with all new code. Please use the ioread/iowrite variants.

I don’t think so. In here, the i/o memory is only happened when pci_iomap return Success, so the register can't be accessed through IO port way. And ioread* will Check if the memory type is mmio type or IO port type (please see the definition).
I don’t think we need to check It, so I use read* because It can make more efficient.
I think we need to think about actual usage, not only follow book.
And, I have said it in previous version, I don’t like explain it again, and again. If you have any concern, please tell me after my comment.

Quoted 30 lines
Quoted 7 lines
drivers/ntb/hw/amd/ntb_hw_amd.c new file +7 -0
+static int amd_link_is_up(struct amd_ntb_dev *ndev) {
+	if (!ndev->peer_sta)
+		return NTB_LNK_STA_ACTIVE(ndev->cntl_sta);
+
+	/* If peer_sta is reset or D0 event, the ISR has
+	 * started a timer to check link status of hardware.
+	 * So here just clear status bit. And if peer_sta is

drivers/ntb/hw/amd/ntb_hw_amd.c line 214

Quoted 10 lines
drivers/ntb/hw/amd/ntb_hw_amd.c new file +10 -0
+	 * D3 or PME_TO, D0/reset event will be happened when
+	 * system wakeup/poweron, so do nothing here.
+	 */
+	if (ndev->peer_sta & AMD_PEER_RESET_EVENT)
+		ndev->peer_sta &= ~AMD_PEER_RESET_EVENT;
+	else if (ndev->peer_sta & AMD_PEER_D0_EVENT)
+		ndev->peer_sta = 0;
+
+	return 0;
+}

Thanks. This is much better.

Quoted 1 line

+static void amd_handle_event(struct amd_ntb_dev *ndev, int vec)

...

Quoted 1 line
drivers/ntb/hw/amd/ntb_hw_amd.c new file +1 -0
+	case AMD_PEER_D0_EVENT:

...

drivers/ntb/hw/amd/ntb_hw_amd.c line 541

Quoted 3 lines
drivers/ntb/hw/amd/ntb_hw_amd.c new file +3 -0
+		/* start a timer to poll link status */
+		schedule_delayed_work(&ndev->hb_timer,
+					      AMD_LINK_HB_TIMEOUT);

This is different from v4. It used to be:

Quoted 7 lines

if (amd_link_is_up())

	ntb_link_event();
else
	schedule_delayed_work();

Why is v5 correct?
Why was v4 incorrect?

Because peer_sta is change to 0, so amd_link_is_up will return 0 (offline) And will not check hardware link status. So It maybe make it offline forever

Quoted 5 lines

I'm nervous about ndev->peer_sta, the behavior of link_is_up, timers... unexplained changes to a fragile bit of code - not just this code, but any code that deals with parallel or asynchronous behaviors. With the comment in link_is_up, this code is much better, but any changes to this whole link state mechanism need to be explained.

Actually, the code is designed according to Atom NTB, except for the peer_sta. I'll add the explaination when having changes.

Reviewed-by
#5 lore raw

From: Yu, Xiangliang [mailto:[email protected]]

Quoted 6 lines
Quoted 4 lines
Quoted 2 lines

NO.

Ok, I'll change it if you doesn't want to change it.

Nah, just remember it for next time...

I'm satisfied with this v5.

Quoted 4 lines

I don’t think so. In here, the i/o memory is only happened when pci_iomap return
Success, so the register can't be accessed through IO port way. And ioread* will

Quoted 8 lines

Check if the memory type is mmio type or IO port type (please see the definition).
I don’t think we need to check It, so I use read* because It can make
more efficient.
I think we need to think about actual usage, not only follow book. And, I have said it in previous version, I don’t like explain it again, and again.
If you have any concern, please tell me after my comment.

It's not more efficient, on this platform it's the same.

If it were my driver I would change it... but you can keep it this way.

Quoted 6 lines
Quoted 1 line

This is different from v4. It used to be:

Because peer_sta is change to 0, so amd_link_is_up will return 0 (offline)
And will not check hardware link status. So It maybe make it offline forever

It fixed a bug? Great!

Quoted 5 lines
Quoted 2 lines

I'm nervous about ndev->peer_sta, the behavior of link_is_up, timers...

Actually, the code is designed according to Atom NTB, except for the peer_sta.

Except for peer_sta, and that's a pretty critical design change. I'm still nervous, but I'll trust that you have been able to test this behavior thourougly.

Quoted 1 line

I'll add the explaination when having changes.

Thanks.

Allen

#6 lore raw
Quoted 6 lines

From: Yu, Xiangliang [mailto:[email protected]]

Quoted 5 lines
Quoted 4 lines
Quoted 2 lines

NO.

Quoted 7 lines
Quoted 1 line

Ok, I'll change it if you doesn't want to change it.

Nah, just remember it for next time...

I'm satisfied with this v5.

Ok, I'll change it and resend V5

Quoted 13 lines
Quoted 4 lines

I don’t think so. In here, the i/o memory is only happened when pci_iomap return Success, so the register can't be accessed through IO port way. And
ioread* will

Quoted 8 lines

Check if the memory type is mmio type or IO port type (please see the definition).
I don’t think we need to check It, so I use read* because It can make
more efficient.
I think we need to think about actual usage, not only follow book. And, I have said it in previous version, I don’t like explain it again, and again.
If you have any concern, please tell me after my comment.

Quoted 3 lines

It's not more efficient, on this platform it's the same.

If it were my driver I would change it... but you can keep it this way.

Because my previous SATA experience, I'd like to use this way.

Quoted 12 lines
Quoted 6 lines
Quoted 1 line

This is different from v4. It used to be:

Because peer_sta is change to 0, so amd_link_is_up will return 0 (offline)
And will not check hardware link status. So It maybe make it offline forever

It fixed a bug? Great!

Quoted 3 lines
Quoted 2 lines

I'm nervous about ndev->peer_sta, the behavior of link_is_up, timers...

Quoted 6 lines
Quoted 2 lines

Actually, the code is designed according to Atom NTB, except for the peer_sta.

Except for peer_sta, and that's a pretty critical design change. I'm still nervous, but I'll trust that you have been able to test this behavior thourougly.

Yes, the part of code will be changed in future because hardware design is Being changed too.

Quoted 2 lines
Quoted 2 lines

I'll add the explaination when having changes.