Skip to contentSkip to conversation

net: macb: Wake-on-Lan magic packet GEM and MACB handling

PATCH In review [email protected] 2 participants 4 messages Jul 20, 2020 – Jul 21, 2020

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

v7 cover net: macb: Wake-on-Lan magic packet GEM and MACB handling

From: Nicolas Ferre <[email protected]>

Hi,

Here is the second part of support for WoL magic-packet on the current macb driver. This one
is addressing the bulk of the feature and is based on current net-next/master.

MACB and GEM code must co-exist and as they don't share exactly the same register layout, I had to specialize a bit the suspend/resume paths and plug a specific IRQ handler in order to avoid overloading the "normal" IRQ hot path.

These changes were tested on both sam9x60 which embeds a MACB+FIFO controller and sama5d2 which has a GEM+packet buffer type of controller.

Best regards,
Nicolas

Changes in v7:
- Release the spinlock before exiting macb_suspend/resume in case of error changing IRQ handler

Changes in v6:
- rebase on net-next/master now that the "fixes" patches of the series are merged in both net and net-next.
- GEM addition and MACB update to finish the support of WoL magic-packet on the two revisions of the controller.

These 2 patches were last posted in v3 series.

History of previous changes already added to git commit message here:
https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/?id=f9f41e3db40ee8d61b427d4d88c7365d968052a9

Nicolas Ferre (2):
net: macb: WoL support for GEM type of Ethernet controller
net: macb: Add WoL interrupt support for MACB type of Ethernet
controller

 drivers/net/ethernet/cadence/macb.h      |   3 +
 drivers/net/ethernet/cadence/macb_main.c | 191 +++++++++++++++++++----
 2 files changed, 167 insertions(+), 27 deletions(-)
Signature · 1 line
2.27.0
#1 lore raw

PATCH v7 1/2 net: macb: WoL support for GEM type of Ethernet controller

From: Nicolas Ferre <[email protected]>

Adapt the Wake-on-Lan feature to the Cadence GEM Ethernet controller. This controller has different register layout and cannot be handled by previous code.
We disable completely interrupts on all the queues but the queue 0. Handling of WoL interrupt is done in another interrupt handler positioned depending on the controller version used, just between suspend() and resume() calls.
It allows to lower pressure on the generic interrupt hot path by removing the need to handle 2 tests for each IRQ: the first figuring out the controller revision, the second for actually knowing if the WoL bit is set.

Queue management in suspend()/resume() functions inspired from RFC patch by Harini Katakam <[email protected]>, thanks!

Cc Claudiu Beznea <[email protected]>
Cc Harini Katakam <[email protected]>

---
Changes in v7:
- Release the spinlock before exiting macb_suspend/resume in case of error changing IRQ handler

 drivers/net/ethernet/cadence/macb.h      |   3 +
 drivers/net/ethernet/cadence/macb_main.c | 153 +++++++++++++++++++----
 2 files changed, 129 insertions(+), 27 deletions(-)
drivers/net/ethernet/cadence/macb.h +3 -0
index ab827fb4b6b9..4f1b41569260 100644
@@ -90,6 +90,7 @@
 #define GEM_SA3T		0x009C /* Specific3 Top */
 #define GEM_SA4B		0x00A0 /* Specific4 Bottom */
 #define GEM_SA4T		0x00A4 /* Specific4 Top */
+#define GEM_WOL			0x00b8 /* Wake on LAN */
 #define GEM_EFTSH		0x00e8 /* PTP Event Frame Transmitted Seconds Register 47:32 */
 #define GEM_EFRSH		0x00ec /* PTP Event Frame Received Seconds Register 47:32 */
 #define GEM_PEFTSH		0x00f0 /* PTP Peer Event Frame Transmitted Seconds Register 47:32 */
@@ -396,6 +397,8 @@
 #define MACB_PDRSFT_SIZE	1
 #define MACB_SRI_OFFSET		26 /* TSU Seconds Register Increment */
 #define MACB_SRI_SIZE		1
+#define GEM_WOL_OFFSET		28 /* Enable wake-on-lan interrupt */
+#define GEM_WOL_SIZE		1
 
 /* Timer increment fields */
 #define MACB_TI_CNS_OFFSET	0
drivers/net/ethernet/cadence/macb_main.c +126 -27

207 lines not on this page · raw message

Signature · 1 line
2.27.0
#2 lore raw

PATCH v7 2/2 net: macb: Add WoL interrupt support for MACB type of Ethernet controller

In reply to [email protected]

From: Nicolas Ferre <[email protected]>

Handle the Wake-on-Lan interrupt for the Cadence MACB Ethernet controller.
As we do for the GEM version, we handle of WoL interrupt in a specialized interrupt handler for MACB version that is positionned just between suspend() and resume() calls.

Cc Claudiu Beznea <[email protected]>
Cc Harini Katakam <[email protected]>

---
Changes in v7:
- Release the spinlock before exiting macb_suspend in case of error changing IRQ handler

 drivers/net/ethernet/cadence/macb_main.c | 40 +++++++++++++++++++++++-
 1 file changed, 39 insertions(+), 1 deletion(-)
drivers/net/ethernet/cadence/macb_main.c +39 -1
index 0f2417f09514..a6a35e1b0115 100644
@@ -1517,6 +1517,35 @@ static void macb_tx_restart(struct macb_queue *queue)
 	macb_writel(bp, NCR, macb_readl(bp, NCR) | MACB_BIT(TSTART));
 }
 
+static irqreturn_t macb_wol_interrupt(int irq, void *dev_id)
+{
+	struct macb_queue *queue = dev_id;
+	struct macb *bp = queue->bp;
+	u32 status;
+
+	status = queue_readl(queue, ISR);
+
+	if (unlikely(!status))
+		return IRQ_NONE;
+
+	spin_lock(&bp->lock);
+
+	if (status & MACB_BIT(WOL)) {
+		queue_writel(queue, IDR, MACB_BIT(WOL));
+		macb_writel(bp, WOL, 0);
+		netdev_vdbg(bp->dev, "MACB WoL: queue = %u, isr = 0x%08lx\n",
+			    (unsigned int)(queue - bp->queues),
+			    (unsigned long)status);
+		if (bp->caps & MACB_CAPS_ISR_CLEAR_ON_WRITE)
+			queue_writel(queue, ISR, MACB_BIT(WOL));
+		pm_wakeup_event(&bp->pdev->dev, 0);
+	}
+
+	spin_unlock(&bp->lock);
+
+	return IRQ_HANDLED;
+}
+
 static irqreturn_t gem_wol_interrupt(int irq, void *dev_id)
 {
 	struct macb_queue *queue = dev_id;
@@ -4619,8 +4648,8 @@ static int __maybe_unused macb_suspend(struct device *dev)
 		/* Change interrupt handler and
 		 * Enable WoL IRQ on queue 0
 		 */
+		devm_free_irq(dev, bp->queues[0].irq, bp->queues);
 		if (macb_is_gem(bp)) {
-			devm_free_irq(dev, bp->queues[0].irq, bp->queues);
 			err = devm_request_irq(dev, bp->queues[0].irq, gem_wol_interrupt,
 					       IRQF_SHARED, netdev->name, bp->queues);
 			if (err) {
@@ -4633,6 +4662,15 @@ static int __maybe_unused macb_suspend(struct device *dev)
 			queue_writel(bp->queues, IER, GEM_BIT(WOL));
 			gem_writel(bp, WOL, MACB_BIT(MAG));
 		} else {
+			err = devm_request_irq(dev, bp->queues[0].irq, macb_wol_interrupt,
+					       IRQF_SHARED, netdev->name, bp->queues);
+			if (err) {
+				dev_err(dev,
+					"Unable to request IRQ %d (error %d)\n",
+					bp->queues[0].irq, err);
+				spin_unlock_irqrestore(&bp->lock, flags);
+				return err;
+			}
 			queue_writel(bp->queues, IER, MACB_BIT(WOL));
 			macb_writel(bp, WOL, MACB_BIT(MAG));
 		}
Signature · 1 line
2.27.0
maintainer
#3 lore raw
In reply to [email protected]

From: <[email protected]>
Date: Mon, 20 Jul 2020 10:56:51 +0200

Quoted 10 lines

Here is the second part of support for WoL magic-packet on the current macb driver. This one
is addressing the bulk of the feature and is based on current net-next/master.

MACB and GEM code must co-exist and as they don't share exactly the same register layout, I had to specialize a bit the suspend/resume paths and plug a specific IRQ handler in order to avoid overloading the "normal" IRQ hot path.

These changes were tested on both sam9x60 which embeds a MACB+FIFO controller and sama5d2 which has a GEM+packet buffer type of controller.

Series applied to net-next, thanks.