All of lore.kernel.org
 help / color / mirror / Atom feed
From: Logan Gunthorpe <logang@deltatee.com>
To: linux-ntb@googlegroups.com, linux-pci@vger.kernel.org,
	linux-kernel@vger.kernel.org
Cc: Jon Mason <jdmason@kudzu.us>, Dave Jiang <dave.jiang@intel.com>,
	Allen Hubbe <Allen.Hubbe@emc.com>,
	Bjorn Helgaas <bhelgaas@google.com>,
	Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
	Kurt Schwemmer <kurt.schwemmer@microsemi.com>,
	Stephen Bates <sbates@raithlin.com>,
	Serge Semin <fancer.lancer@gmail.com>,
	Logan Gunthorpe <logang@deltatee.com>
Subject: [PATCH 10/16] switchtec_ntb: initialize hardware for doorbells and messages
Date: Wed, 28 Jun 2017 21:26:42 -0600	[thread overview]
Message-ID: <20170629032648.3073-11-logang@deltatee.com> (raw)
In-Reply-To: <20170629032648.3073-1-logang@deltatee.com>

This patch sets up some hardware registers and creates interrupt service
routines for the doorbells and messages.

There are 64 doorbells in the switch that are shared between all
partitions. The upper 4 doorbells are also shared with the messages
and are there for not used. Thus, this code provides 28 doorbells
for each partition.

Signed-off-by: Logan Gunthorpe <logang@deltatee.com>
Reviewed-by: Stephen Bates <sbates@raithlin.com>
Reviewed-by: Kurt Schwemmer <kurt.schwemmer@microsemi.com>
---
 drivers/ntb/hw/mscc/switchtec_ntb.c | 144 ++++++++++++++++++++++++++++++++++++
 1 file changed, 144 insertions(+)

diff --git a/drivers/ntb/hw/mscc/switchtec_ntb.c b/drivers/ntb/hw/mscc/switchtec_ntb.c
index ff03424153d9..4f48b34ce0b5 100644
--- a/drivers/ntb/hw/mscc/switchtec_ntb.c
+++ b/drivers/ntb/hw/mscc/switchtec_ntb.c
@@ -17,6 +17,7 @@
 #include <linux/module.h>
 #include <linux/delay.h>
 #include <linux/kthread.h>
+#include <linux/interrupt.h>
 
 MODULE_DESCRIPTION("Microsemi Switchtec(tm) NTB Driver");
 MODULE_VERSION("0.1");
@@ -77,6 +78,9 @@ struct switchtec_ntb {
 	int self_partition;
 	int peer_partition;
 
+	int doorbell_irq;
+	int message_irq;
+
 	struct ntb_info_regs __iomem *mmio_ntb;
 	struct ntb_ctrl_regs __iomem *mmio_ctrl;
 	struct ntb_dbmsg_regs __iomem *mmio_dbmsg;
@@ -88,6 +92,11 @@ struct switchtec_ntb {
 	struct shared_mw __iomem *peer_shared;
 	dma_addr_t self_shared_dma;
 
+	u64 db_mask;
+	u64 db_valid_mask;
+	int db_shift;
+	int db_peer_shift;
+
 	int nr_direct_mw;
 	int nr_lut_mw;
 	int direct_mw_to_bar[MAX_DIRECT_MW];
@@ -196,6 +205,49 @@ static void switchtec_ntb_init_mw(struct switchtec_ntb *sndev)
 		sndev->nr_direct_mw, cnt - sndev->nr_direct_mw);
 }
 
+/*
+ * There are 64 doorbells in the switch hardware but this is
+ * shared among all partitions. So we must split them in half
+ * (32 for each partition). However, the message interrupts are
+ * also shared with the top 4 doorbells so we just limit this to
+ * 28 doorbells per partition
+ */
+static void switchtec_ntb_init_db(struct switchtec_ntb *sndev)
+{
+	sndev->db_valid_mask = 0x0FFFFFFF;
+
+	if (sndev->self_partition < sndev->peer_partition) {
+		sndev->db_shift = 0;
+		sndev->db_peer_shift = 32;
+	} else {
+		sndev->db_shift = 32;
+		sndev->db_peer_shift = 0;
+	}
+
+	sndev->db_mask = 0x0FFFFFFFFFFFFFFFULL;
+	iowrite64(~sndev->db_mask, &sndev->mmio_self_dbmsg->idb_mask);
+	iowrite64(sndev->db_valid_mask << sndev->db_peer_shift,
+		  &sndev->mmio_self_dbmsg->odb_mask);
+}
+
+static void switchtec_ntb_init_msgs(struct switchtec_ntb *sndev)
+{
+	int i;
+	u32 msg_map = 0;
+
+	for (i = 0; i < ARRAY_SIZE(sndev->mmio_self_dbmsg->imsg); i++) {
+		int m = i | sndev->peer_partition << 2;
+
+		msg_map |= m << i * 8;
+	}
+
+	iowrite32(msg_map, &sndev->mmio_self_dbmsg->msg_map);
+
+	for (i = 0; i < ARRAY_SIZE(sndev->mmio_self_dbmsg->imsg); i++)
+		iowrite64(NTB_DBMSG_IMSG_STATUS | NTB_DBMSG_IMSG_MASK,
+			  &sndev->mmio_self_dbmsg->imsg[i]);
+}
+
 static int switchtec_ntb_init_req_id_table(struct switchtec_ntb *sndev)
 {
 	int rc = 0;
@@ -342,6 +394,87 @@ static void switchtec_ntb_deinit_shared_mw(struct switchtec_ntb *sndev)
 				  sndev->self_shared_dma);
 }
 
+static irqreturn_t switchtec_ntb_doorbell_isr(int irq, void *dev)
+{
+	struct switchtec_ntb *sndev = dev;
+
+	dev_dbg(&sndev->stdev->dev, "doorbell\n");
+
+	return IRQ_HANDLED;
+}
+
+static irqreturn_t switchtec_ntb_message_isr(int irq, void *dev)
+{
+	int i;
+	struct switchtec_ntb *sndev = dev;
+
+	for (i = 0; i < ARRAY_SIZE(sndev->mmio_self_dbmsg->imsg); i++) {
+		u64 msg = ioread64(&sndev->mmio_self_dbmsg->imsg[i]);
+
+		if (msg & NTB_DBMSG_IMSG_STATUS) {
+			dev_dbg(&sndev->stdev->dev, "message: %d %08x\n", i,
+				(u32)msg);
+			iowrite8(1, &sndev->mmio_self_dbmsg->imsg[i].status);
+		}
+	}
+
+	return IRQ_HANDLED;
+}
+
+static int switchtec_ntb_init_db_msg_irq(struct switchtec_ntb *sndev)
+{
+	int i;
+	int rc;
+	int doorbell_irq = 0;
+	int message_irq = 0;
+	int event_irq;
+	int idb_vecs = sizeof(sndev->mmio_self_dbmsg->idb_vec_map);
+
+	event_irq = ioread32(&sndev->stdev->mmio_part_cfg->vep_vector_number);
+
+	while (doorbell_irq == event_irq)
+		doorbell_irq++;
+	while (message_irq == doorbell_irq ||
+	       message_irq == event_irq)
+		message_irq++;
+
+	dev_dbg(&sndev->stdev->dev, "irqs - event: %d, db: %d, msgs: %d",
+		event_irq, doorbell_irq, message_irq);
+
+	for (i = 0; i < idb_vecs - 4; i++)
+		iowrite8(doorbell_irq,
+			 &sndev->mmio_self_dbmsg->idb_vec_map[i]);
+
+	for (; i < idb_vecs; i++)
+		iowrite8(message_irq,
+			 &sndev->mmio_self_dbmsg->idb_vec_map[i]);
+
+	sndev->doorbell_irq = pci_irq_vector(sndev->stdev->pdev, doorbell_irq);
+	sndev->message_irq = pci_irq_vector(sndev->stdev->pdev, message_irq);
+
+	rc = request_irq(sndev->doorbell_irq,
+			 switchtec_ntb_doorbell_isr, 0,
+			 "switchtec_ntb_doorbell", sndev);
+	if (rc)
+		return rc;
+
+	rc = request_irq(sndev->message_irq,
+			 switchtec_ntb_message_isr, 0,
+			 "switchtec_ntb_message", sndev);
+	if (rc) {
+		free_irq(sndev->doorbell_irq, sndev);
+		return rc;
+	}
+
+	return 0;
+}
+
+static void switchtec_ntb_deinit_db_msg_irq(struct switchtec_ntb *sndev)
+{
+	free_irq(sndev->doorbell_irq, sndev);
+	free_irq(sndev->message_irq, sndev);
+}
+
 static int switchtec_ntb_add(struct device *dev,
 			     struct class_interface *class_intf)
 {
@@ -365,6 +498,8 @@ static int switchtec_ntb_add(struct device *dev,
 
 	switchtec_ntb_init_sndev(sndev);
 	switchtec_ntb_init_mw(sndev);
+	switchtec_ntb_init_db(sndev);
+	switchtec_ntb_init_msgs(sndev);
 
 	rc = switchtec_ntb_init_req_id_table(sndev);
 	if (rc)
@@ -374,11 +509,19 @@ static int switchtec_ntb_add(struct device *dev,
 	if (rc)
 		goto free_and_exit;
 
+	rc = switchtec_ntb_init_db_msg_irq(sndev);
+	if (rc)
+		goto deinit_shared_and_exit;
+
+	switchtec_ntb_init_mw(sndev);
+
 	stdev->sndev = sndev;
 	dev_info(dev, "NTB device registered");
 
 	return 0;
 
+deinit_shared_and_exit:
+	switchtec_ntb_deinit_shared_mw(sndev);
 free_and_exit:
 	kfree(sndev);
 	dev_err(dev, "failed to register ntb device: %d", rc);
@@ -395,6 +538,7 @@ void switchtec_ntb_remove(struct device *dev,
 		return;
 
 	stdev->sndev = NULL;
+	switchtec_ntb_deinit_db_msg_irq(sndev);
 	switchtec_ntb_deinit_shared_mw(sndev);
 	kfree(sndev);
 	dev_info(dev, "ntb device unregistered");
-- 
2.11.0


  parent reply	other threads:[~2017-06-29  3:27 UTC|newest]

Thread overview: 47+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-06-29  3:26 [PATCH 00/16] Logan Gunthorpe
2017-06-29  3:26 ` [PATCH 01/16] switchtec: move structure definitions into a common header Logan Gunthorpe
2017-07-05 19:37   ` Bjorn Helgaas
2017-06-29  3:26 ` [PATCH 02/16] switchtec: export class symbol for use in upper layer driver Logan Gunthorpe
2017-06-29  3:26 ` [PATCH 03/16] switchtec: add ntb hardware register definitions Logan Gunthorpe
2017-06-29  3:26 ` [PATCH 04/16] switchtec: add link event notifier callback Logan Gunthorpe
2017-06-29  3:26 ` [PATCH 05/16] ntb: ensure ntb_mw_get_align is only called when the link is up Logan Gunthorpe
2017-06-29 18:11   ` Allen Hubbe
2017-06-29 18:11     ` Allen Hubbe
2017-06-29  3:26 ` [PATCH 06/16] ntb: add check and comment for link up to mw_count and mw_get_align Logan Gunthorpe
2017-06-29 18:11   ` Allen Hubbe
2017-06-29 18:11     ` Allen Hubbe
2017-06-29 18:11     ` Allen Hubbe
2017-06-29 19:00     ` Logan Gunthorpe
2017-06-29 20:13       ` Allen Hubbe
2017-06-29 20:13         ` Allen Hubbe
2017-06-29 20:13         ` Allen Hubbe
2017-06-29 20:17         ` Logan Gunthorpe
2017-06-29 21:27           ` Hubbe, Allen
2017-06-29 21:27             ` Hubbe, Allen
2017-06-29 21:35           ` Allen Hubbe
2017-06-29 21:35             ` Allen Hubbe
2017-06-29 22:14             ` Logan Gunthorpe
2017-06-29  3:26 ` [PATCH 07/16] ntb: ntb_test: ensure the link is up before trying to configure the mws Logan Gunthorpe
2017-06-29  3:26 ` [PATCH 08/16] switchtec_ntb: introduce initial ntb driver Logan Gunthorpe
2017-06-29  3:26 ` [PATCH 09/16] switchtec_ntb: initialize hardware for memory windows Logan Gunthorpe
2017-06-29  3:26 ` Logan Gunthorpe [this message]
2017-06-29  3:26 ` [PATCH 11/16] switchtec_ntb: add skeleton ntb driver Logan Gunthorpe
2017-06-29  3:26 ` [PATCH 12/16] switchtec_ntb: add link management Logan Gunthorpe
2017-06-29 18:11   ` Allen Hubbe
2017-06-29 18:11     ` Allen Hubbe
2017-06-29 18:11     ` Allen Hubbe
2017-06-29 18:37     ` Logan Gunthorpe
2017-06-29  3:26 ` [PATCH 13/16] switchtec_ntb: implement doorbell registers Logan Gunthorpe
2017-07-05 19:42   ` Bjorn Helgaas
2017-06-29  3:26 ` [PATCH 14/16] switchtec_ntb: implement scratchpad registers Logan Gunthorpe
2017-06-29 18:11   ` Allen Hubbe
2017-06-29 18:11     ` Allen Hubbe
2017-06-29 18:11     ` Allen Hubbe
2017-06-29 18:33     ` Logan Gunthorpe
2017-06-29  3:26 ` [PATCH 15/16] switchtec_ntb: add memory window support Logan Gunthorpe
2017-07-05 19:46   ` Bjorn Helgaas
2017-06-29  3:26 ` [PATCH 16/16] switchtec_ntb: update switchtec documentation with notes for ntb Logan Gunthorpe
2017-06-29 15:15 ` [PATCH 00/16] Greg Kroah-Hartman
2017-06-29 15:37   ` Logan Gunthorpe
2017-07-05 19:47 ` Bjorn Helgaas
2017-07-05 19:50   ` Logan Gunthorpe

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20170629032648.3073-11-logang@deltatee.com \
    --to=logang@deltatee.com \
    --cc=Allen.Hubbe@emc.com \
    --cc=bhelgaas@google.com \
    --cc=dave.jiang@intel.com \
    --cc=fancer.lancer@gmail.com \
    --cc=gregkh@linuxfoundation.org \
    --cc=jdmason@kudzu.us \
    --cc=kurt.schwemmer@microsemi.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-ntb@googlegroups.com \
    --cc=linux-pci@vger.kernel.org \
    --cc=sbates@raithlin.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.