From patchwork Tue Mar 18 06:47:18 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Byungho An X-Patchwork-Id: 26456 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-qc0-f197.google.com (mail-qc0-f197.google.com [209.85.216.197]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id 53CC42057E for ; Tue, 18 Mar 2014 06:48:13 +0000 (UTC) Received: by mail-qc0-f197.google.com with SMTP id i8sf15580296qcq.8 for ; Mon, 17 Mar 2014 23:48:13 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:delivered-to:from:to:cc:subject:date:message-id :mime-version:thread-index:dlp-filter:sender:precedence:list-id :x-original-sender:x-original-authentication-results:mailing-list :list-post:list-help:list-archive:list-unsubscribe:content-type :content-transfer-encoding:content-language; bh=papbRYjCMKGhAaSkvpkOtQbi0z8DLTjv8w9sbtf3uWo=; b=VN0w5xwk76ngbPQ+ma7wEytWZBaTH22Qe1HDx02BPmIbePK0h7wWUstoa181AEFTzz HLBjJF0lRUviL6Hz4Y5Nj525MLBX5MucJgY3ugsBFsnpPQbnnPcMAdMfN0HBNrj9kwZA B2oHEaSC5vNMrFWv2Q1yXrOOpdie/NH9wxg0VpMXNrMQ4Qg7kisGqDzUkIRmjU9NE7Ly 6ahpEvr8A5TSiPk8DbfG1LyxK962R9BEF05d90TlYJmT4ZPneqfuKLw14WX9CdkYv2XS 6aEFZu7LBg6AOjj5Rs2NDHBOIZcd/1zJeg+se8ddc79TWYjwVpoaCNjWej+TJpbnNnDY dMCw== X-Gm-Message-State: ALoCoQn2uApFXiYD+JNH+TTi7avpcMHL7WdT2ycwp4LCijKfSYqKTWFy12qn7KZMNRGVLs7To7Ia X-Received: by 10.236.4.101 with SMTP id 65mr141435yhi.57.1395125293157; Mon, 17 Mar 2014 23:48:13 -0700 (PDT) X-BeenThere: patchwork-forward@linaro.org Received: by 10.140.107.198 with SMTP id h64ls712522qgf.84.gmail; Mon, 17 Mar 2014 23:48:13 -0700 (PDT) X-Received: by 10.52.175.166 with SMTP id cb6mr19543043vdc.1.1395125293049; Mon, 17 Mar 2014 23:48:13 -0700 (PDT) Received: from mail-vc0-f179.google.com (mail-vc0-f179.google.com [209.85.220.179]) by mx.google.com with ESMTPS id sq9si2429154vdc.125.2014.03.17.23.48.13 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Mon, 17 Mar 2014 23:48:13 -0700 (PDT) Received-SPF: neutral (google.com: 209.85.220.179 is neither permitted nor denied by best guess record for domain of patch+caf_=patchwork-forward=linaro.org@linaro.org) client-ip=209.85.220.179; Received: by mail-vc0-f179.google.com with SMTP id ij19so6698971vcb.38 for ; Mon, 17 Mar 2014 23:48:13 -0700 (PDT) X-Received: by 10.58.207.74 with SMTP id lu10mr22920984vec.15.1395125292918; Mon, 17 Mar 2014 23:48:12 -0700 (PDT) X-Forwarded-To: patchwork-forward@linaro.org X-Forwarded-For: patch@linaro.org patchwork-forward@linaro.org Delivered-To: patch@linaro.org Received: by 10.220.78.9 with SMTP id i9csp181796vck; Mon, 17 Mar 2014 23:48:12 -0700 (PDT) X-Received: by 10.68.227.4 with SMTP id rw4mr31674961pbc.3.1395125290361; Mon, 17 Mar 2014 23:48:10 -0700 (PDT) Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id dj5si10849574pad.205.2014.03.17.23.48.09; Mon, 17 Mar 2014 23:48:09 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-samsung-soc-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753459AbaCRGro (ORCPT + 8 others); Tue, 18 Mar 2014 02:47:44 -0400 Received: from mailout2.samsung.com ([203.254.224.25]:57106 "EHLO mailout2.samsung.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753366AbaCRGra (ORCPT ); Tue, 18 Mar 2014 02:47:30 -0400 Received: from epcpsbgr2.samsung.com (u142.gpu120.samsung.co.kr [203.254.230.142]) by mailout2.samsung.com (Oracle Communications Messaging Server 7u4-24.01 (7.0.4.24.0) 64bit (built Nov 17 2011)) with ESMTP id <0N2M000W3DJ4S2B0@mailout2.samsung.com>; Tue, 18 Mar 2014 15:47:28 +0900 (KST) Received: from epcpsbgm2.samsung.com ( [203.254.230.49]) by epcpsbgr2.samsung.com (EPCPMTA) with SMTP id FE.95.09028.FFBE7235; Tue, 18 Mar 2014 15:47:28 +0900 (KST) X-AuditID: cbfee68e-b7f566d000002344-67-5327ebff7f7e Received: from epmmp2 ( [203.254.227.17]) by epcpsbgm2.samsung.com (EPCPMTA) with SMTP id 41.FD.28157.FFBE7235; Tue, 18 Mar 2014 15:47:27 +0900 (KST) Received: from VISITOR1LAB ([105.128.19.10]) by mmp2.samsung.com (Oracle Communications Messaging Server 7u4-24.01 (7.0.4.24.0) 64bit (built Nov 17 2011)) with ESMTPA id <0N2M005LDDIQUQ90@mmp2.samsung.com>; Tue, 18 Mar 2014 15:47:27 +0900 (KST) From: Byungho An To: netdev@vger.kernel.org, linux-samsung-soc@vger.kernel.org Cc: davem@davemloft.net, ks.giri@samsung.com, ilho215.lee@samsung.com Subject: [PATCH V4 6/8] net: sxgbe: add WOL(Wakeup-On-Lan)support for Samsung sxgbe Date: Mon, 17 Mar 2014 23:47:18 -0700 Message-id: <00fb01cf4275$eaab3790$c001a6b0$@samsung.com> MIME-version: 1.0 X-Mailer: Microsoft Outlook 14.0 Thread-index: Ac9CdVpuZeSjqEzdQRKe7LR7rQWWOA== X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFtrKIsWRmVeSWpSXmKPExsVy+t8zQ12GN+rBBq8OMVnMOd/CYnH030JG i/lHdzBZzDi/j8ni2AIxB1aPLStvMnn0bVnF6PF5k1wAcxSXTUpqTmZZapG+XQJXxv07P9gK NqRXNDX9ZWtgvBTWxcjJISFgIrFqx34WCFtM4sK99WxdjFwcQgLLGCU23O5lgylquruJESIx nVFi8erfrBDOH0aJy613mUGq2ATUJJpnXgbrEBGwlVhy5DN7FyMHB7OAq0TPDQ2QsLBAqMS3 R7PBtrEIqEo8XnIHzOYVsJRYuK6LHcIWlPgx+R5YnFlAS2L9zuNMELa8xOY1b5khDlKQ2HH2 NSPEKj2JR3eWsUPUiEtMevCQHeQ2CYFt7BLzvn9ihFgmIPFt8iEWkHskBGQlNh2AmiMpcXDF DZYJjGKzkKyehWT1LCSrZyFZsYCRZRWjaGpBckFxUnqRkV5xYm5xaV66XnJ+7iZGSJT17WC8 ecD6EGMy0PqJzFKiyfnAKM0riTc0NjOyMDUxNTYytzQjTVhJnHfRw6QgIYH0xJLU7NTUgtSi +KLSnNTiQ4xMHJxSDYzS1rmCr6yz/h96fnZ+hni/WYLti6MLbsc7z85oYGZ7Zj114cSPrwI2 rjvKb9X/eRqvmIXIvbKYKfJPHtXzfWk/n/v3nMyumBTDfToBjuUNff5lz53ERAUVZZX2ajEZ /Di1cmXjDbZN6wxnnMziVLe3OfJc5L1h1MZr+QymTwVmO83Lr5kw6bASS3FGoqEWc1FxIgCX g9/OyAIAAA== X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFprEKsWRmVeSWpSXmKPExsVy+t9jQd3/r9WDDe5ctrSYc76FxeLov4WM FvOP7mCymHF+H5PFsQViDqweW1beZPLo27KK0ePzJrkA5qgGRpuM1MSU1CKF1Lzk/JTMvHRb Je/geOd4UzMDQ11DSwtzJYW8xNxUWyUXnwBdt8wcoJVKCmWJOaVAoYDE4mIlfTtME0JD3HQt YBojdH1DguB6jAzQQMI6xoz7d36wFWxIr2hq+svWwHgprIuRk0NCwESi6e4mRghbTOLCvfVs XYxcHEIC0xklFq/+zQrh/GGUuNx6lxmkik1ATaJ55mU2EFtEwFZiyZHP7F2MHBzMAq4SPTc0 QMLCAqES3x7NZgGxWQRUJR4vuQNm8wpYSixc18UOYQtK/Jh8DyzOLKAlsX7ncSYIW15i85q3 zBAHKUjsOPuaEWKVnsSjO8vYIWrEJSY9eMg+gVFgFpJRs5CMmoVk1CwkLQsYWVYxiqYWJBcU J6XnGukVJ+YWl+al6yXn525iBMfwM+kdjKsaLA4xCnAwKvHwvmBTDxZiTSwrrsw9xCjBwawk wrt0MlCINyWxsiq1KD++qDQntfgQYzLQpxOZpUST84HpJa8k3tDYxMzI0sjMwsjE3Jw0YSVx 3oOt1oFCAumJJanZqakFqUUwW5g4OKUaGHPV3m25eyXLwtXNdPHtBXbS//pXTD23dm0Wp9Wz ipLfJ09PUkrbctuf++R9HxVm+/wN738FBh5xum1XeMd74dm2oPTnP94anOXd3thztWvCKRtT ZdG5i9+U8D8/0Pnzcc9XSY9qsUcreg3DO1sX/Dm3qHDh7stHtyWwZ6/Ss9cUr7Mxup5rzqHE UpyRaKjFXFScCACHbOI8JQMAAA== DLP-Filter: Pass X-MTR: 20000000000000000@CPGS X-CFilter-Loop: Reflected Sender: linux-samsung-soc-owner@vger.kernel.org Precedence: list List-ID: X-Mailing-List: linux-samsung-soc@vger.kernel.org X-Removed-Original-Auth: Dkim didn't pass. X-Original-Sender: bh74.an@samsung.com X-Original-Authentication-Results: mx.google.com; spf=neutral (google.com: 209.85.220.179 is neither permitted nor denied by best guess record for domain of patch+caf_=patchwork-forward=linaro.org@linaro.org) smtp.mail=patch+caf_=patchwork-forward=linaro.org@linaro.org Mailing-list: list patchwork-forward@linaro.org; contact patchwork-forward+owners@linaro.org X-Google-Group-Id: 836684582541 List-Post: , List-Help: , List-Archive: List-Unsubscribe: , Content-type: text/plain; charset=us-ascii Content-transfer-encoding: 7bit Content-language: en-us From: Girish K S This patch adds support for wake up on magic frame arrival. Also remote wake up on all other packets (unicast, multicast broadcast) is supported. Signed-off-by: Girish K S Neatening-by: Joe Perches Signed-off-by: Byungho An --- drivers/net/ethernet/samsung/sxgbe/sxgbe_common.h | 15 +++++ drivers/net/ethernet/samsung/sxgbe/sxgbe_core.c | 29 ++++++++ drivers/net/ethernet/samsung/sxgbe/sxgbe_ethtool.c | 47 +++++++++++++ drivers/net/ethernet/samsung/sxgbe/sxgbe_main.c | 71 ++++++++++++++++++++ drivers/net/ethernet/samsung/sxgbe/sxgbe_mtl.c | 43 +++++++++++- drivers/net/ethernet/samsung/sxgbe/sxgbe_mtl.h | 4 ++ .../net/ethernet/samsung/sxgbe/sxgbe_platform.c | 4 ++ drivers/net/ethernet/samsung/sxgbe/sxgbe_reg.h | 3 + 8 files changed, 215 insertions(+), 1 deletion(-) diff --git a/drivers/net/ethernet/samsung/sxgbe/sxgbe_common.h b/drivers/net/ethernet/samsung/sxgbe/sxgbe_common.h index 22db49f..d94e8d9 100644 --- a/drivers/net/ethernet/samsung/sxgbe/sxgbe_common.h +++ b/drivers/net/ethernet/samsung/sxgbe/sxgbe_common.h @@ -121,9 +121,18 @@ struct sxgbe_mtl_ops; #define RX_ENTRY_LPI_MODE 0x40 #define RX_EXIT_LPI_MODE 0x80 +/* PMT mode bits */ +#define PMT_PWRDWN BIT(0) +#define PMT_MGPKT_EN BIT(1) +#define PMT_RWKPKT_EN BIT(2) +#define PMT_GUCAST_EN BIT(9) + /* EEE-LPI Interrupt status flag */ #define LPI_INT_STATUS BIT(5) +/* PMT Interrupt status */ +#define PMT_INT_STATUS BIT(4) + /* EEE-LPI Default timer values */ #define LPI_LINK_STATUS_TIMER 0x3E8 #define LPI_MAC_WAIT_TIMER 0x00 @@ -225,6 +234,7 @@ struct sxgbe_extra_stats { unsigned long rx_desc_access_err; unsigned long rx_buffer_access_err; unsigned long rx_data_transfer_err; + unsigned long pmt_irq_event_n; /* EEE-LPI stats */ unsigned long tx_lpi_entry_n; @@ -489,6 +499,11 @@ struct sxgbe_priv_data { int eee_enabled; int eee_active; int tx_lpi_timer; + + /* PM-WOL specific members */ + int wolopts; + int wolenabled; + int wol_irq; }; /* Function prototypes */ diff --git a/drivers/net/ethernet/samsung/sxgbe/sxgbe_core.c b/drivers/net/ethernet/samsung/sxgbe/sxgbe_core.c index 5885fd6..334d196 100644 --- a/drivers/net/ethernet/samsung/sxgbe/sxgbe_core.c +++ b/drivers/net/ethernet/samsung/sxgbe/sxgbe_core.c @@ -78,12 +78,41 @@ static int sxgbe_core_host_irq_status(void __iomem *ioaddr, if (unlikely(irq_status & LPI_INT_STATUS)) status |= sxgbe_get_lpi_status(ioaddr, irq_status); + if (unlikely(irq_status & PMT_INT_STATUS)) { + /* clear the PMT bits 5 and 6 by reading the PMT status reg */ + readl(ioaddr + SXGBE_CORE_PMT_CTL_STATUS_REG); + x->pmt_irq_event_n++; + } + return status; } /* Set power management mode (e.g. magic frame) */ static void sxgbe_core_pmt(void __iomem *ioaddr, unsigned long mode) { + unsigned int pmt = 0; + + if (mode & WAKE_MAGIC) { + pr_debug("WOL Magic frame\n"); + pmt |= PMT_MGPKT_EN; + } + if (mode & WAKE_UCAST) { + pr_debug("WOL on global unicast\n"); + pmt |= PMT_GUCAST_EN; + } + if (mode & (WAKE_MCAST | WAKE_BCAST)) { + pr_debug("WOL on any other packet\n"); + pmt |= PMT_RWKPKT_EN; + } + + writel(pmt, ioaddr + SXGBE_CORE_PMT_CTL_STATUS_REG); + + /* Enable power down bit if any of the requested mode is enabled */ + if (pmt) { + writel(SXGBE_RX_ENABLE, ioaddr + SXGBE_CORE_RX_CONFIG_REG); + pmt |= PMT_PWRDWN; + writel(pmt, ioaddr + SXGBE_CORE_PMT_CTL_STATUS_REG); + } } /* Set/Get Unicast MAC addresses */ diff --git a/drivers/net/ethernet/samsung/sxgbe/sxgbe_ethtool.c b/drivers/net/ethernet/samsung/sxgbe/sxgbe_ethtool.c index 9083300..89b1450 100644 --- a/drivers/net/ethernet/samsung/sxgbe/sxgbe_ethtool.c +++ b/drivers/net/ethernet/samsung/sxgbe/sxgbe_ethtool.c @@ -12,6 +12,7 @@ #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt +#include #include #include #include @@ -37,6 +38,7 @@ static const struct sxgbe_stats sxgbe_gstrings_stats[] = { SXGBE_STAT(rx_lpi_entry_n), SXGBE_STAT(rx_lpi_exit_n), SXGBE_STAT(eee_wakeup_error_n), + SXGBE_STAT(pmt_irq_event_n), }; #define SXGBE_STATS_LEN ARRAY_SIZE(sxgbe_gstrings_stats) @@ -80,9 +82,54 @@ static int sxgbe_ethtool_set_eee(struct net_device *dev, return phy_ethtool_set_eee(priv->phydev, edata); } +static void sxgbe_get_wol(struct net_device *dev, struct ethtool_wolinfo *wol) +{ + struct sxgbe_priv_data *priv = netdev_priv(dev); + + wol->wolopts = 0; + if (!device_can_wakeup(priv->device)) { + dev_err(priv->device, "cannot wakeup device\n"); + return; + } + + if (priv->hw_cap.pmt_magic_frame) + wol->supported |= WAKE_MAGIC; + + if (priv->hw_cap.pmt_remote_wake_up) + wol->supported |= (WAKE_UCAST | WAKE_MCAST | WAKE_BCAST); + + wol->wolopts = priv->wolopts; +} + +static int sxgbe_set_wol(struct net_device *dev, struct ethtool_wolinfo *wol) +{ + struct sxgbe_priv_data *priv = netdev_priv(dev); + + if (wol->wolopts & (WAKE_PHY | WAKE_ARP | WAKE_MAGICSECURE)) + return -EOPNOTSUPP; + + if (!device_can_wakeup(priv->device)) + return -EOPNOTSUPP; + + if (wol->wolopts) { + netdev_info(dev, "wakeup enable\n"); + device_set_wakeup_enable(priv->device, true); + enable_irq_wake(priv->wol_irq); + } else { + device_set_wakeup_enable(priv->device, false); + disable_irq_wake(priv->wol_irq); + } + + priv->wolopts = wol->wolopts; + + return 0; +} + static const struct ethtool_ops sxgbe_ethtool_ops = { .get_eee = sxgbe_ethtool_get_eee, .set_eee = sxgbe_ethtool_set_eee, + .get_wol = sxgbe_get_wol, + .set_wol = sxgbe_set_wol, }; void sxgbe_set_ethtool_ops(struct net_device *netdev) diff --git a/drivers/net/ethernet/samsung/sxgbe/sxgbe_main.c b/drivers/net/ethernet/samsung/sxgbe/sxgbe_main.c index 13bdb54..d0e2769 100644 --- a/drivers/net/ethernet/samsung/sxgbe/sxgbe_main.c +++ b/drivers/net/ethernet/samsung/sxgbe/sxgbe_main.c @@ -1089,6 +1089,18 @@ static int sxgbe_open(struct net_device *dev) goto init_error; } + /* Request the Wake IRQ in case of another line is used for WoL */ + if (priv->wol_irq != dev->irq) { + ret = devm_request_irq(priv->device, priv->wol_irq, + sxgbe_common_interrupt, IRQF_SHARED, + dev->name, dev); + if (unlikely(ret < 0)) { + netdev_err(dev, "%s: ERROR: allocating the WoL IRQ %d (%d)\n", + __func__, priv->wol_irq, ret); + goto init_error; + } + } + /* If the LPI irq is different from the mac irq * register a dedicated handler */ @@ -2058,6 +2070,27 @@ static int sxgbe_hw_init(struct sxgbe_priv_data * const priv) return 0; } +static void sxgbe_set_pmt_capabilities(struct sxgbe_priv_data *priv) +{ + u32 ctrl; + + priv->wolopts = 0; + + ctrl = readl(priv->ioaddr + SXGBE_CORE_PMT_CTL_STATUS_REG); + /* Enable maagic packet reception */ + if (priv->hw_cap.pmt_magic_frame) { + priv->wolopts |= WAKE_MAGIC; + ctrl |= PMT_MGPKT_EN; + } + if (priv->hw_cap.pmt_remote_wake_up) { + priv->wolopts |= WAKE_UCAST | WAKE_MCAST | WAKE_BCAST; + ctrl |= (PMT_RWKPKT_EN | PMT_GUCAST_EN); + } + writel(ctrl, priv->ioaddr + SXGBE_CORE_PMT_CTL_STATUS_REG); + + device_init_wakeup(priv->device, true); +} + /** * sxgbe_dvr_probe * @device: device pointer @@ -2180,6 +2213,7 @@ struct sxgbe_priv_data *sxgbe_dvr_probe(struct device *device, goto error_mdio_register; } + sxgbe_set_pmt_capabilities(priv); sxgbe_check_ether_addr(priv); return priv; @@ -2230,11 +2264,48 @@ int sxgbe_dvr_remove(struct net_device *ndev) #ifdef CONFIG_PM int sxgbe_suspend(struct net_device *ndev) { + struct sxgbe_priv_data *priv = netdev_priv(ndev); + struct netdev_hw_addr *ha; + int queue_num = 0, reg = 0; + + /* Disable TX and wait till all frames flushed out */ + priv->hw->mac->enable_tx(priv->ioaddr, false); + sxgbe_tx_all_clean(priv); + SXGBE_FOR_EACH_QUEUE(SXGBE_TX_QUEUES, queue_num) + priv->hw->mtl->mtl_flush_txqueue(priv->ioaddr, queue_num); + + /* Disable RX and wait till all frames read into memory */ + priv->hw->mac->enable_rx(priv->ioaddr, false); + SXGBE_FOR_EACH_QUEUE(SXGBE_RX_QUEUES, queue_num) + priv->hw->mtl->mtl_readout_rxqueue(priv->ioaddr, queue_num); + + /* Enable Power down mode by programming the PMT regs */ + if (device_may_wakeup(priv->device)) { + priv->hw->mac->pmt(priv->ioaddr, priv->wolopts); + } else { + netdev_for_each_uc_addr(ha, ndev) + priv->hw->mac->set_umac_addr(priv->ioaddr, ha->addr, + reg++); + /* Disable clock in case of PWM is off */ + clk_disable_unprepare(priv->sxgbe_clk); + } + return 0; } int sxgbe_resume(struct net_device *ndev) { + struct sxgbe_priv_data *priv = netdev_priv(ndev); + + if (device_may_wakeup(priv->device)) + priv->hw->mac->pmt(priv->ioaddr, 0); + else + /* enable the clk prevously disabled */ + clk_prepare_enable(priv->sxgbe_clk); + + priv->hw->mac->enable_rx(priv->ioaddr, true); + priv->hw->mac->enable_tx(priv->ioaddr, true); + return 0; } diff --git a/drivers/net/ethernet/samsung/sxgbe/sxgbe_mtl.c b/drivers/net/ethernet/samsung/sxgbe/sxgbe_mtl.c index d3ec6eb..6f6202c 100644 --- a/drivers/net/ethernet/samsung/sxgbe/sxgbe_mtl.c +++ b/drivers/net/ethernet/samsung/sxgbe/sxgbe_mtl.c @@ -174,6 +174,45 @@ static void sxgbe_mtl_fup_disable(void __iomem *ioaddr, int queue_num) writel(reg_val, ioaddr + SXGBE_MTL_RXQ_OPMODE_REG(queue_num)); } +static int sxgbe_mtl_flush_txqueue(void __iomem *ioaddr, int queue_num) +{ + unsigned long timeout; + u32 reg_val; + + timeout = jiffies + msecs_to_jiffies(5); + + reg_val = readl(ioaddr + SXGBE_MTL_TXQ_OPMODE_REG(queue_num)); + while ((reg_val & + (SXGBE_MTL_TXQ_EMPTY_STAT | SXGBE_MTL_TXQ_WRITE_STAT))) { + if (time_after(jiffies, timeout)) { + pr_err("cannot flush tx queue - timeout\n"); + return -ETIMEDOUT; + } + reg_val = readl(ioaddr + SXGBE_MTL_TXQ_OPMODE_REG(queue_num)); + } + + return 0; +} + +static int sxgbe_mtl_readout_rxqueue(void __iomem *ioaddr, int queue_num) +{ + unsigned long timeout; + u32 reg_val; + + timeout = jiffies + msecs_to_jiffies(5); + + reg_val = readl(ioaddr + SXGBE_MTL_TXQ_OPMODE_REG(queue_num)); + while ((reg_val & + (SXGBE_MTL_TXQ_EMPTY_STAT | SXGBE_MTL_TXQ_WRITE_STAT))) { + if (time_after(jiffies, timeout)) { + pr_err("cannot flush tx queue - timeout\n"); + return -ETIMEDOUT; + } + reg_val = readl(ioaddr + SXGBE_MTL_TXQ_OPMODE_REG(queue_num)); + } + + return 0; +} static void sxgbe_set_tx_mtl_mode(void __iomem *ioaddr, int queue_num, int tx_mode) @@ -243,7 +282,9 @@ static const struct sxgbe_mtl_ops mtl_ops = { .mtl_fep_enable = sxgbe_mtl_fep_enable, .mtl_fep_disable = sxgbe_mtl_fep_disable, .mtl_fup_enable = sxgbe_mtl_fup_enable, - .mtl_fup_disable = sxgbe_mtl_fup_disable + .mtl_fup_disable = sxgbe_mtl_fup_disable, + .mtl_flush_txqueue = sxgbe_mtl_flush_txqueue, + .mtl_readout_rxqueue = sxgbe_mtl_readout_rxqueue }; const struct sxgbe_mtl_ops *sxgbe_get_mtl_ops(void) diff --git a/drivers/net/ethernet/samsung/sxgbe/sxgbe_mtl.h b/drivers/net/ethernet/samsung/sxgbe/sxgbe_mtl.h index 7e4810c..b2f3f10 100644 --- a/drivers/net/ethernet/samsung/sxgbe/sxgbe_mtl.h +++ b/drivers/net/ethernet/samsung/sxgbe/sxgbe_mtl.h @@ -97,6 +97,10 @@ struct sxgbe_mtl_ops { void (*mtl_fup_enable)(void __iomem *ioaddr, int queue_num); void (*mtl_fup_disable)(void __iomem *ioaddr, int queue_num); + + int (*mtl_flush_txqueue)(void __iomem *ioaddr, int queue_num); + + int (*mtl_readout_rxqueue)(void __iomem *ioaddr, int queue_num); }; const struct sxgbe_mtl_ops *sxgbe_get_mtl_ops(void); diff --git a/drivers/net/ethernet/samsung/sxgbe/sxgbe_platform.c b/drivers/net/ethernet/samsung/sxgbe/sxgbe_platform.c index d1ffff5..797aa8a 100644 --- a/drivers/net/ethernet/samsung/sxgbe/sxgbe_platform.c +++ b/drivers/net/ethernet/samsung/sxgbe/sxgbe_platform.c @@ -165,6 +165,10 @@ static int sxgbe_platform_probe(struct platform_device *pdev) if (priv->lpi_irq == -ENXIO) priv->lpi_irq = priv->dev->irq; + priv->wol_irq = irq_of_parse_and_map(dev->of_node, loop++); + if (priv->wol_irq == -ENXIO) + priv->wol_irq = priv->dev->irq; + platform_set_drvdata(pdev, priv->dev); pr_debug("platform driver registration completed\n"); diff --git a/drivers/net/ethernet/samsung/sxgbe/sxgbe_reg.h b/drivers/net/ethernet/samsung/sxgbe/sxgbe_reg.h index 85a7b31..bd85923 100644 --- a/drivers/net/ethernet/samsung/sxgbe/sxgbe_reg.h +++ b/drivers/net/ethernet/samsung/sxgbe/sxgbe_reg.h @@ -257,6 +257,9 @@ #define SXGBE_MTL_SFMODE BIT(1) #define SXGBE_MTL_FIFO_LSHIFT 16 #define SXGBE_MTL_ENABLE_QUEUE 0x00000008 +#define SXGBE_MTL_TXQ_EMPTY_STAT BIT(4) +#define SXGBE_MTL_TXQ_WRITE_STAT BIT(3) + #define SXGBE_MTL_TXQ_UNDERFLOW_REG(qnum) \ (SXGBE_MTL_TC_TXBASE_REG + (qnum * 0x80) + 0x04) #define SXGBE_MTL_TXQ_DEBUG_REG(qnum) \