Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1755826AbcK2Byh (ORCPT ); Mon, 28 Nov 2016 20:54:37 -0500 Received: from mail-db5eur01on0075.outbound.protection.outlook.com ([104.47.2.75]:22560 "EHLO EUR01-DB5-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1751758AbcK2By3 (ORCPT ); Mon, 28 Nov 2016 20:54:29 -0500 From: Andy Duan To: Nikita Yushchenko , "David S. Miller" , Troy Kisky , "Andrew Lunn" , Eric Nelson , Philippe Reynes , Johannes Berg , "netdev@vger.kernel.org" CC: Chris Healy , Fabio Estevam , "linux-kernel@vger.kernel.org" Subject: RE: [patch net] net: fec: cache statistics while device is down Thread-Topic: [patch net] net: fec: cache statistics while device is down Thread-Index: AQHSSYOGe6n5ZOnz2kK4ltAF+D7Dv6DvKEwg Date: Tue, 29 Nov 2016 01:22:01 +0000 Message-ID: References: <1480343227-725-1-git-send-email-nikita.yoush@cogentembedded.com> In-Reply-To: <1480343227-725-1-git-send-email-nikita.yoush@cogentembedded.com> Accept-Language: zh-CN, en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: authentication-results: spf=none (sender IP is ) smtp.mailfrom=fugang.duan@nxp.com; x-originating-ip: [199.59.225.131] x-ms-office365-filtering-correlation-id: fd8f1d0c-6cdd-4570-9e66-08d417f61ebc x-microsoft-antispam: UriScan:;BCL:0;PCL:0;RULEID:(22001);SRVR:DB6PR0402MB2742; x-microsoft-exchange-diagnostics: 1;DB6PR0402MB2742;7:RHoVi27AM9V5NfTEaSe8um++cw6sxluD66f0C6vdYKTwe46/GeI/++fJos1cOGmTZwT02fkK/hsSjjFqrJOPY4bPLs72L1255arCXU09T3CsMV2rCsEsPbDMBamGuXfP24aMthBS7IRMHXUG34iQZfcCGtFK7LnKbGaNAJEo8wP5IwBNhpjcdo7rhtZb2JOUymKbNvGQm8mgEDiGt2259PbNL+bOnWFPXmotCKo22upmxY3Q9nb8U29MAxvr+KUxZxqEiSYV7WlOKcsEU1N7bwomGRvdgB2JSDbWCnrmJ0Ftmo6C9R7RYrRUwyE+Hie/vf/VJRX5I9WkTi3Eu4LT8AIHx64UHmOfxZDD5MH+9SP93KUFyhBw+fe6DHxUyTKFFeeTD/fFUrlr3EJdMEzvYdddDIDYJyovCbq/RvOHfQ8FgBn5ExpMuOnrjWLsFb5wsXnxczGCIssSkRKhEGyVRQ== x-microsoft-antispam-prvs: x-exchange-antispam-report-test: UriScan:(9452136761055)(185117386973197); x-exchange-antispam-report-cfa-test: BCL:0;PCL:0;RULEID:(6060326)(6040361)(6045199)(601004)(2401047)(8121501046)(5005006)(3002001)(10201501046)(6055026)(6041248)(6061324)(6046074)(20161123555025)(20161123560025)(20161123562025)(20161123564025)(6072148);SRVR:DB6PR0402MB2742;BCL:0;PCL:0;RULEID:;SRVR:DB6PR0402MB2742; x-forefront-prvs: 01415BB535 x-forefront-antispam-report: SFV:NSPM;SFS:(10009020)(979002)(6009001)(7916002)(377454003)(189002)(199003)(2900100001)(92566002)(105586002)(106356001)(6506003)(106116001)(5001770100001)(38730400001)(189998001)(39060400001)(305945005)(97736004)(7736002)(229853002)(86362001)(76576001)(74316002)(7846002)(3846002)(6116002)(102836003)(4326007)(122556002)(66066001)(8936002)(33656002)(8676002)(3280700002)(9686002)(68736007)(3660700001)(81166006)(81156014)(5660300001)(2950100002)(50986999)(39410400001)(39380400001)(7696004)(39400400001)(7416002)(2501003)(54356999)(101416001)(2906002)(39450400002)(76176999)(77096006)(969003)(989001)(999001)(1009001)(1019001);DIR:OUT;SFP:1101;SCL:1;SRVR:DB6PR0402MB2742;H:AM4PR0401MB2260.eurprd04.prod.outlook.com;FPR:;SPF:None;PTR:InfoNoRecords;MX:1;A:1;LANG:en; spamdiagnosticoutput: 1:99 spamdiagnosticmetadata: NSPM Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 X-OriginatorOrg: nxp.com X-MS-Exchange-CrossTenant-originalarrivaltime: 29 Nov 2016 01:22:01.0253 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: 686ea1d3-bc2b-4c6f-a92c-d99c5c301635 X-MS-Exchange-Transport-CrossTenantHeadersStamped: DB6PR0402MB2742 Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Transfer-Encoding: 8bit X-MIME-Autoconverted: from quoted-printable to 8bit by mail.home.local id uAT1sfKH007878 Content-Length: 4074 Lines: 104 From: Nikita Yushchenko Sent: Monday, November 28, 2016 10:27 PM >To: David S. Miller ; Andy Duan >; Troy Kisky ; >Andrew Lunn ; Eric Nelson ; Philippe >Reynes ; Johannes Berg ; >netdev@vger.kernel.org >Cc: Chris Healy ; Fabio Estevam >; linux-kernel@vger.kernel.org; Nikita >Yushchenko >Subject: [patch net] net: fec: cache statistics while device is down > >Execution 'ethtool -S' on fec device that is down causes OOPS on Vybrid >board: > >Unhandled fault: external abort on non-linefetch (0x1008) at 0xe0898200 pgd >= ddecc000 [e0898200] *pgd=9e406811, *pte=400d1653, *ppte=400d1453 >Internal error: : 1008 [#1] SMP ARM ... > >Reason of OOPS is that fec_enet_get_ethtool_stats() accesses fec registers >while IPG clock is stopped by PM. > >Fix that by caching statistics in fec_enet_private. Cache is updated just >before statistics request if device is up, and also just before turning device >off on down path. > >Additional locking is not needed, since cached statistics is always updated >under rtnl_lock(). > >Signed-off-by: Nikita Yushchenko >--- > drivers/net/ethernet/freescale/fec.h | 2 ++ > drivers/net/ethernet/freescale/fec_main.c | 21 +++++++++++++++++---- > 2 files changed, 19 insertions(+), 4 deletions(-) > >diff --git a/drivers/net/ethernet/freescale/fec.h >b/drivers/net/ethernet/freescale/fec.h >index c865135f3cb9..5ea740b4cf14 100644 >--- a/drivers/net/ethernet/freescale/fec.h >+++ b/drivers/net/ethernet/freescale/fec.h >@@ -574,6 +574,8 @@ struct fec_enet_private { > unsigned int reload_period; > int pps_enable; > unsigned int next_counter; >+ >+ u64 ethtool_stats[0]; > }; > > void fec_ptp_init(struct platform_device *pdev); diff --git >a/drivers/net/ethernet/freescale/fec_main.c >b/drivers/net/ethernet/freescale/fec_main.c >index 5aa9d4ded214..7da2d94ec8e5 100644 >--- a/drivers/net/ethernet/freescale/fec_main.c >+++ b/drivers/net/ethernet/freescale/fec_main.c >@@ -2313,14 +2313,24 @@ static const struct fec_stat { > { "IEEE_rx_octets_ok", IEEE_R_OCTETS_OK }, }; > >-static void fec_enet_get_ethtool_stats(struct net_device *dev, >- struct ethtool_stats *stats, u64 *data) >+static void fec_enet_update_ethtool_stats(struct net_device *dev) > { > struct fec_enet_private *fep = netdev_priv(dev); > int i; > > for (i = 0; i < ARRAY_SIZE(fec_stats); i++) >- data[i] = readl(fep->hwp + fec_stats[i].offset); >+ fep->ethtool_stats[i] = readl(fep->hwp + >fec_stats[i].offset); } >+ >+static void fec_enet_get_ethtool_stats(struct net_device *dev, >+ struct ethtool_stats *stats, u64 *data) { >+ struct fec_enet_private *fep = netdev_priv(dev); >+ >+ if (netif_running(dev)) >+ fec_enet_update_ethtool_stats(dev); >+ >+ memcpy(data, fep->ethtool_stats, ARRAY_SIZE(fec_stats) * >sizeof(u64)); > } > > static void fec_enet_get_strings(struct net_device *netdev, @@ -2874,6 >+2884,8 @@ fec_enet_close(struct net_device *ndev) > if (fep->quirks & FEC_QUIRK_ERR006687) > imx6q_cpuidle_fec_irqs_unused(); > >+ fec_enet_update_ethtool_stats(ndev); >+ If user never open the interface, ethtool_stats[] always is 0 that are not expected. So, it also should be called at . fec_enet_init() ? > fec_enet_clk_enable(ndev, false); > pinctrl_pm_select_sleep_state(&fep->pdev->dev); > pm_runtime_mark_last_busy(&fep->pdev->dev); >@@ -3278,7 +3290,8 @@ fec_probe(struct platform_device *pdev) > fec_enet_get_queue_num(pdev, &num_tx_qs, &num_rx_qs); > > /* Init network device */ >- ndev = alloc_etherdev_mqs(sizeof(struct fec_enet_private), >+ ndev = alloc_etherdev_mqs(sizeof(struct fec_enet_private) + >+ ARRAY_SIZE(fec_stats) * sizeof(u64), > num_tx_qs, num_rx_qs); > if (!ndev) > return -ENOMEM; >-- >2.1.4