Skip to contentSkip to conversation

NTB: Add AMD PCI-Express NTB driver

PATCH In review Xiangliang Yu 2 participants 3 messages Dec 17, 2015 – Dec 18, 2015

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

PATCH 1/3 NTB: Add AMD PCI-Express NTB driver

AMD NTB support following main features:
(1) Three memory windows;
(2) Sixteen 32-bit scratch pad;
(3) Two 16-bit doorbell interrupt;
(4) Five event interrupts;
(5) One system can wake up opposite system of NTB;
(6) Flush previous request to the opposite system;
(7) There are reset and PME_TO mechanisms between two systems;

---
 drivers/ntb/hw/amd/Kconfig      |    7 +
 drivers/ntb/hw/amd/Makefile     |    1 +
 drivers/ntb/hw/amd/ntb_hw_amd.c | 1225 +++++++++++++++++++++++++++++++++++++++
 drivers/ntb/hw/amd/ntb_hw_amd.h |  266 +++++++++
 4 files changed, 1499 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
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 +1225 -0

1,225 lines not on this page · raw message

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

266 lines not on this page · raw message

Signature · 1 line
1.9.1
maintainer
#1 lore raw
Quoted 10 lines · Xiangliang Yu

AMD NTB support following main features:
(1) Three memory windows;
(2) Sixteen 32-bit scratch pad;
(3) Two 16-bit doorbell interrupt;
(4) Five event interrupts;
(5) One system can wake up opposite system of NTB;
(6) Flush previous request to the opposite system;
(7) There are reset and PME_TO mechanisms between two systems;

Is hardware available on which this can be tested?

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

Quoted 8 lines

+++ b/drivers/ntb/hw/amd/ntb_hw_amd.c

drivers/ntb/hw/amd/ntb_hw_amd.c new file +6 -0
+static u64 amd_ntb_db_read(struct ntb_dev *ntb)
+{
+       struct amd_ntb_dev *ndev = ntb_ndev(ntb);
+
+       return (u64)NTB_READ_REG(DBSTAT);
+}

DBSTAT hides the use of ndev, or ndev is unused. The code should be more clear, here, and in other places where NTB_READ_REG and NTB_WRITE_REG are used with a macro argument.

Quoted 13 lines
drivers/ntb/hw/amd/ntb_hw_amd.c new file +13 -0
+static void amd_ack_SMU(struct amd_ntb_dev *ndev, u32 bit)
+{
+       int reg;
+
+       reg = NTB_READ_REG(SMUACK);
+       reg |= bit;
+       NTB_WRITE_REG(reg, SMUACK);
+
+       ndev->peer_sta |= bit;
+}
+
+/*
+ * flush the requests to peer side

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

Quoted 10 lines
drivers/ntb/hw/amd/ntb_hw_amd.c new file +10 -0
+ */
+static int amd_flush_peer_requests(struct amd_ntb_dev *ndev)
+{
+       u32 reg;
+
+       if (!amd_link_is_up(ndev)) {
+               dev_err(ndev_dev(ndev), "link is down.\n");
+               return -EINVAL;
+       }
+

Add reinit_completion, or this may already be "complete" from a previous flush.

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

Quoted 5 lines
drivers/ntb/hw/amd/ntb_hw_amd.c new file +5 -0
+       reg = NTB_READ_REG(FLUSHTRIG);
+       reg |= 0x1;
+       NTB_WRITE_REG(reg, FLUSHTRIG);
+
+       wait_for_completion(&ndev->flush_cmpl);

Because of wait_for_completion, that this can only be called in a thread context. This is unlike other functions of ntb.h, so there should at least be a note in the api documentation.

Quoted 6 lines
drivers/ntb/hw/amd/ntb_hw_amd.c new file +6 -0
+
+       return 0;
+}
+
+/*
+ * wake up the peer side

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

Quoted 10 lines
drivers/ntb/hw/amd/ntb_hw_amd.c new file +10 -0
+ */
+static int amd_wakeup_peer_side(struct amd_ntb_dev *ndev)
+{
+       u32 reg;
+
+       if (!amd_link_is_up(ndev)) {
+               dev_warn(ndev_dev(ndev), "link is down.\n");
+               return -EINVAL;
+       }
+

See previous comment.

Quoted 57 lines
drivers/ntb/hw/amd/ntb_hw_amd.c new file +55 -0
+       NTB_READ_REG(PMSGTRIG);
+       reg |= 0x1;
+       NTB_WRITE_REG(reg, PMSGTRIG);
+
+       wait_for_completion(&ndev->wakeup_cmpl);
+
+       return 0;
+}
 
 
+static void amd_handle_event(struct amd_ntb_dev *ndev, int vec)
+{
+       u32 status;
+
+       status = NTB_READ_REG(INTSTAT);
+       if (!(status & AMD_EVENT_INTMASK))
+               return;
+
+       dev_dbg(ndev_dev(ndev), "status = 0x%x and vec = %d\n", status, vec);
+
+       status &= AMD_EVENT_INTMASK;
+       switch (status) {
+       case AMD_PEER_FLUSH_EVENT:
+               complete(&ndev->flush_cmpl);
+               break;
+       case AMD_PEER_RESET_EVENT:
+               amd_ack_SMU(ndev, AMD_PEER_RESET_EVENT);
+
+               /* link down first */
+               ntb_link_event(&ndev->ntb);
+               /* polling peer status */
+               schedule_delayed_work(&ndev->hb_timer, AMD_LINK_HB_TIMEOUT);
+
+               break;
+       case AMD_PEER_D3_EVENT:
+       case AMD_PEER_PMETO_EVENT:
+               amd_ack_SMU(ndev, status);
+
+               /* link down */
+               ntb_link_event(&ndev->ntb);
+
+               break;
+       case AMD_PEER_D0_EVENT:
+               status = NTB_READ_PEER_REG(PMESTAT);
+               /* check if this is WAKEUP event */
+               if (status & 0x1)
+                       complete(&ndev->wakeup_cmpl);
+
+               amd_ack_SMU(ndev, AMD_PEER_D0_EVENT);
+
+               if (amd_link_is_up(ndev))
+                       ntb_link_event(&ndev->ntb);
+               else
+                       schedule_delayed_work(&ndev->hb_timer,
+                                               AMD_LINK_HB_TIMEOUT);
+               break;
+       default:

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

Quoted 10 lines
drivers/ntb/hw/amd/ntb_hw_amd.c new file +10 -0
+               pr_err("Unsupported interrupt.\n");
+               break;
+       }
+}
+
+static irqreturn_t ndev_interrupt(struct amd_ntb_dev *ndev, int vec)
+{
+       dev_dbg(ndev_dev(ndev), "vec %d\n", vec);
+
+       if (vec > 20) {

This duplicates the "default" case of amd_handle_event.

Quoted 12 lines
drivers/ntb/hw/amd/ntb_hw_amd.c new file +12 -0
+               dev_err(ndev_dev(ndev), "Invalid interrupt.\n");
+               return IRQ_HANDLED;
+       }
+
+       if (vec > 16 || (ndev->msix_vec_count == 1))
+               amd_handle_event(ndev, vec);
+
+       if (vec < 16)
+               ntb_db_event(&ndev->ntb, vec);
+
+       return IRQ_HANDLED;
+}
#2 lore raw
Quoted 18 lines

From: Allen Hubbe [mailto:[email protected]]
Sent: Friday, December 18, 2015 12:46 AM
To: Yu, Xiangliang
Cc: [email protected]; [email protected]; [email protected]; [email protected]; SPG_Linux_Kernel
Subject: Re: [PATCH 1/3] NTB: Add AMD PCI-Express NTB driver

Quoted 9 lines · Xiangliang Yu

AMD NTB support following main features:
(1) Three memory windows;
(2) Sixteen 32-bit scratch pad;
(3) Two 16-bit doorbell interrupt;
(4) Five event interrupts;
(5) One system can wake up opposite system of NTB;
(6) Flush previous request to the opposite system;
(7) There are reset and PME_TO mechanisms between two systems;

Quoted 3 lines
Quoted 1 line

Is hardware available on which this can be tested?

No yet. Right now, verified the driver on emulator.

Quoted 11 lines

drivers/ntb/hw/amd/ntb_hw_amd.c

Quoted 7 lines

+++ b/drivers/ntb/hw/amd/ntb_hw_amd.c

drivers/ntb/hw/amd/ntb_hw_amd.c new file +4 -0
+static u64 amd_ntb_db_read(struct ntb_dev *ntb) {
+       struct amd_ntb_dev *ndev = ntb_ndev(ntb);
+
+       return (u64)NTB_READ_REG(DBSTAT); }

DBSTAT hides the use of ndev, or ndev is unused. The code should be more clear, here, and in other places where NTB_READ_REG and NTB_WRITE_REG are used with a macro argument.

Got it, I will add ndev into macro arguments.

Quoted 17 lines
Quoted 17 lines
drivers/ntb/hw/amd/ntb_hw_amd.c new file +16 -0
+static void amd_ack_SMU(struct amd_ntb_dev *ndev, u32 bit) {
+       int reg;
+
+       reg = NTB_READ_REG(SMUACK);
+       reg |= bit;
+       NTB_WRITE_REG(reg, SMUACK);
+
+       ndev->peer_sta |= bit;
+}
+
+/*
+ * flush the requests to peer side
+ */
+static int amd_flush_peer_requests(struct amd_ntb_dev *ndev) {
+       u32 reg;
+
Quoted 8 lines

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

Quoted 5 lines
drivers/ntb/hw/amd/ntb_hw_amd.c new file +5 -0
+       if (!amd_link_is_up(ndev)) {
+               dev_err(ndev_dev(ndev), "link is down.\n");
+               return -EINVAL;
+       }
+

Add reinit_completion, or this may already be "complete" from a previous flush.

Ok.

Quoted 10 lines

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

Quoted 6 lines
drivers/ntb/hw/amd/ntb_hw_amd.c new file +5 -0
+       reg = NTB_READ_REG(FLUSHTRIG);
+       reg |= 0x1;
+       NTB_WRITE_REG(reg, FLUSHTRIG);
+
+       wait_for_completion(&ndev->flush_cmpl);

Because of wait_for_completion, that this can only be called in a thread context. This is unlike other functions of ntb.h, so there should at least be a note in the api documentation.

Ok.

Quoted 81 lines
Quoted 6 lines
drivers/ntb/hw/amd/ntb_hw_amd.c new file +5 -0
+
+       return 0;
+}
+
+/*

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

Quoted 10 lines
drivers/ntb/hw/amd/ntb_hw_amd.c new file +10 -0
+ * wake up the peer side
+ */
+static int amd_wakeup_peer_side(struct amd_ntb_dev *ndev) {
+       u32 reg;
+
+       if (!amd_link_is_up(ndev)) {
+               dev_warn(ndev_dev(ndev), "link is down.\n");
+               return -EINVAL;
+       }
+

See previous comment.

Quoted 62 lines
drivers/ntb/hw/amd/ntb_hw_amd.c new file +60 -0
+       NTB_READ_REG(PMSGTRIG);
+       reg |= 0x1;
+       NTB_WRITE_REG(reg, PMSGTRIG);
+
+       wait_for_completion(&ndev->wakeup_cmpl);
+
+       return 0;
+}
 
 
+static void amd_handle_event(struct amd_ntb_dev *ndev, int vec) {
+       u32 status;
+
+       status = NTB_READ_REG(INTSTAT);
+       if (!(status & AMD_EVENT_INTMASK))
+               return;
+
+       dev_dbg(ndev_dev(ndev), "status = 0x%x and vec = %d\n",
+ status, vec);
+
+       status &= AMD_EVENT_INTMASK;
+       switch (status) {
+       case AMD_PEER_FLUSH_EVENT:
+               complete(&ndev->flush_cmpl);
+               break;
+       case AMD_PEER_RESET_EVENT:
+               amd_ack_SMU(ndev, AMD_PEER_RESET_EVENT);
+
+               /* link down first */
+               ntb_link_event(&ndev->ntb);
+               /* polling peer status */
+               schedule_delayed_work(&ndev->hb_timer,
+ AMD_LINK_HB_TIMEOUT);
+
+               break;
+       case AMD_PEER_D3_EVENT:
+       case AMD_PEER_PMETO_EVENT:
+               amd_ack_SMU(ndev, status);
+
+               /* link down */
+               ntb_link_event(&ndev->ntb);
+
+               break;
+       case AMD_PEER_D0_EVENT:
+               status = NTB_READ_PEER_REG(PMESTAT);
+               /* check if this is WAKEUP event */
+               if (status & 0x1)
+                       complete(&ndev->wakeup_cmpl);
+
+               amd_ack_SMU(ndev, AMD_PEER_D0_EVENT);
+
+               if (amd_link_is_up(ndev))
+                       ntb_link_event(&ndev->ntb);
+               else
+                       schedule_delayed_work(&ndev->hb_timer,
+                                               AMD_LINK_HB_TIMEOUT);
+               break;
+       default:
+               pr_err("Unsupported interrupt.\n");
+               break;
+       }
+}
Quoted 8 lines

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

Quoted 6 lines
drivers/ntb/hw/amd/ntb_hw_amd.c new file +6 -0
+
+static irqreturn_t ndev_interrupt(struct amd_ntb_dev *ndev, int vec)
+{
+       dev_dbg(ndev_dev(ndev), "vec %d\n", vec);
+
+       if (vec > 20) {

This duplicates the "default" case of amd_handle_event.

Ok, I'll refine the code.

Quoted 13 lines
Quoted 13 lines
drivers/ntb/hw/amd/ntb_hw_amd.c new file +12 -0
+               dev_err(ndev_dev(ndev), "Invalid interrupt.\n");
+               return IRQ_HANDLED;
+       }
+
+       if (vec > 16 || (ndev->msix_vec_count == 1))
+               amd_handle_event(ndev, vec);
+
+       if (vec < 16)
+               ntb_db_event(&ndev->ntb, vec);
+
+       return IRQ_HANDLED;
+}