Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752872AbcLFKGP (ORCPT ); Tue, 6 Dec 2016 05:06:15 -0500 Received: from mail-by2nam01on0086.outbound.protection.outlook.com ([104.47.34.86]:24704 "EHLO NAM01-BY2-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1752043AbcLFKGL (ORCPT ); Tue, 6 Dec 2016 05:06:11 -0500 Authentication-Results: spf=fail (sender IP is 192.88.168.50) smtp.mailfrom=nxp.com; gmail.com; dkim=none (message not signed) header.d=none;gmail.com; dmarc=fail action=none header.from=nxp.com; X-IncomingTopHeaderMarker: OriginalChecksum:;UpperCasedChecksum:;SizeAsReceived:843;Count:10 From: Ioana Radulescu To: CC: , , , , , , , , Subject: [PATCH 4/8] staging: fsl-dpaa2/eth: Add ethtool support Date: Tue, 6 Dec 2016 03:34:38 -0600 Message-ID: <20161206093442.11362-5-ruxandra.radulescu@nxp.com> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20161206093442.11362-1-ruxandra.radulescu@nxp.com> References: <20161206093442.11362-1-ruxandra.radulescu@nxp.com> X-IncomingHeaderCount: 10 X-EOPAttributedMessage: 0 X-Matching-Connectors: 131254904843658479;(91ab9b29-cfa4-454e-5278-08d120cd25b8);() X-Forefront-Antispam-Report: CIP:192.88.168.50;IPV:NLI;CTRY:US;EFV:NLI;SFV:NSPM;SFS:(10009020)(6009001)(7916002)(2980300002)(1110001)(1109001)(336004)(339900001)(189002)(199003)(6666003)(305945005)(76176999)(50986999)(8666005)(5003940100001)(77096006)(2906002)(356003)(39450400002)(2351001)(106466001)(36756003)(39840400001)(48376002)(50466002)(105606002)(8936002)(86362001)(39860400001)(50226002)(85426001)(47776003)(39060400001)(33646002)(39380400001)(38730400001)(7846002)(92566002)(39400400001)(39410400001)(97736004)(81156014)(4326007)(8676002)(189998001)(39850400001)(68736007)(7416002)(1076002)(626004)(2950100002)(81166006)(5660300001)(6916009)(104016004)(110136003)(7059030)(2004002);DIR:OUT;SFP:1101;SCL:1;SRVR:CY1PR0301MB0746;H:tx30smr01.am.freescale.net;FPR:;SPF:Fail;PTR:InfoDomainNonexistent;MX:1;A:1;LANG:en; X-Microsoft-Exchange-Diagnostics: 1;BN1AFFO11FD026;1:8LFBHLBDkG6mPgXeVdqdvTRUZ8vYquJqLB7bQTO68dXCMq7u7Z/zDyfkmut7RSicFhv4LQ4n9Fj2u1sWS0Cuv+4enpyUN3VDoof71wlnob8dUmsb7NsRqNjbbE/n1UJWgzPYMH/gFAgOFcXYpJ2W7gUQu2YbwSa1OaMnWwsfAqgDP1YvXAUUoJ0KMsjRVyQYqGQ49jNsO2n91qFWqtSl4vr8JMVDc8GXYH/UsYsQbDrl4Yi01ShqITI3YQ2bZBzAJFGQVNpgn3l/RxVNJpWVrthQeL5253rUoTHtZAXRnai1UNSCEpr8AxpmLS0vUVbzhCSF9+hz+NA/zzeKDlTHC8nlARyWoEhEfPvB5pl4xf4Jnivhe0sV+dFBZ2hUjg87Hb4jaoEwpEdnedIwsnXsLMl8ysnXZf2gjCa7V+zy5SCD3eneDTD9aJp8jmwGqOPxzzh+OlPhVOsTbEWNkSnvump0WlF30Et5srIXq1+x8b1gqCuuIBgE/QehalN7xqtjpda++KXETQhTpao4cnV+YfIqz523s0iDD2n9mGOBhzCxuX/PZB93lyHijLo07qbHHo16GzoWmo9NuvIQYEZzQvudeA13yNKg3z1ICbdkfFYm/oKGqASnQCaXltbp+bvA MIME-Version: 1.0 Content-Type: text/plain X-Microsoft-Exchange-Diagnostics: 1;CY1PR0301MB0746;2:ODpavh928a9t3qELx7PR+KzA6YfeTVmj5UfR4JQ1LKfZHaz2Xmrr2lqeu3SWq5xn69EMCtI2YqTS5DJEtfm/yIQy0Q2XrndedKYfxLbSpwDm/5KKQWMW9V+rq7Z8B0TXCKCOydcDPh6TJZG3pn5Gc3ORbboDNMgGGH/VfSt5Cwk=;3:2wRd8Uepg/2grQQNGRBIVO79vmgyD5GkQZ/QZTSLVfnM3ob9QgtkZh9YG54tzgPAZHRv9Dlxoci3WkO76E34980b12dpWpikmZbtDWnE+Pe5GskxgiA6wQjYsoY27w3b//xltIOwMTmjCrRR5VfqpGJuMYCy6RwScR0j8fZhMOtp4CvN2FveCaTSgRCc4JtSohMgoM0YFEqmvG9azML3YDfJzkoDmT9Zwaq1/Xx1hhG5cuOJRDJO9r4jzgqi7RcKWy7heUVOak7C0wEqtwUIPw== X-MS-Office365-Filtering-Correlation-Id: cb7ca273-c6eb-4c12-222d-08d41dbb1cae X-Microsoft-Antispam: UriScan:;BCL:0;PCL:0;RULEID:(22001);SRVR:CY1PR0301MB0746; X-Microsoft-Exchange-Diagnostics: 1;CY1PR0301MB0746;25:vjXLdc9Mvl/4rftUC5y1A8pS+U5jcElvOMq7C8CayUsLggEcN+ApxsaUfgcnsYEulsB9iEAZgA88SQpmRCuqVPWnbTIVZOXFTQuQJPjtQWSCtSekkhD8Pb3Etdx5kB8+lWTQBKpYj688ofnIl5baed6I57hK+un6vLmsa7/4efpCOmoFoS5LwC/DlnJNy6n3vCtLVK5tigfvYGFEKsxgpBrKDeb0OS3ToaMZPcxchkOYsXrADO/yGJhT/nAlt3GH+jNcoXtMCCeJ33qlzxrsEqB1t+T9g29YEwMr64gDbKQRw1Vw7L3Bp2tNUFdWXRClS4XQVR5zY3OtOatByaWEhhRwzGQJ+ortvIYSGPn0Qkqgt1IKdISPwsV+ekfT8JGQXcNsr5Bu/NvbS9VFd4VXVmfjw6Rv72NuKALioi1kG64DzfTC+Fn5ZriDPafXqHs4+DZXGXqfAfPt085jKF8zFlFjcpSq51wUMnDmAgMAwrC+bwo4iHUrfdwaBnEA8VPcql/sq/aGIBUAv/6n3fUWLbXIOxot/eUvTXZUYH+4IsHSMjMV2TG/ZERtbE7tB1ela3Gns5i35ulJEYdsIsG7K+EX1cbKJyg7zvGrt9pR6dt3YiIARlxDHWMPFdCWIvHbnVUKaDwgRcpGOTtKj6rAZVjKe4MrfBRd1Y8fPY+NISoKVAv9NTkUH2lgZCfcDqaDia2/CuKPYybNwtEu6/jVO8i5YQSF8fbq9p3ouY7kc3xVH7gaJuJdUfLPQKLqVeh9/T3VXYSPiRJzUa6fom3K2Hdmn+YIy22/QSyS+vII7uE= X-Microsoft-Exchange-Diagnostics: 1;CY1PR0301MB0746;31:Rg0cc4ikx371K3HE8eULEgbKtncfn9MCoyCgeB+QDmxVZCFGZQERuFTpIsqtzLsMIpTAXSxZdR0ktatBvHOh3muCJnksK4tSSzACcNaDCabi9F6pygVUVZqkwWmBMzH59fIWOFMjHexo/lSwneWBA8EGGSBft9AAkXo34hpyNWxljNyGgn011hgIa7O523cuipFR3Yggil0EhMwOOsOi/AUHvKdAd8lTIP4jXggkW+F9jU/rO4XmEDy2HE65xQiSW/RhH/vDmUBIUxvOJWhaSKSjj+2FD2M5Hgs85deLK2F9a1INW6o/2ms1eyVZ0vED X-Microsoft-Antispam-PRVS: X-Exchange-Antispam-Report-Test: UriScan:(185117386973197); X-Exchange-Antispam-Report-CFA-Test: BCL:0;PCL:0;RULEID:(6095060)(601004)(2401047)(5005006)(8121501046)(13023025)(13024025)(13015025)(13017025)(13018025)(10201501046)(3002001)(6055026)(6096035)(20161123565025)(20161123559025)(20161123556025)(20161123563025)(20161123561025);SRVR:CY1PR0301MB0746;BCL:0;PCL:0;RULEID:(400006);SRVR:CY1PR0301MB0746; X-Microsoft-Exchange-Diagnostics: 1;CY1PR0301MB0746;4:c+/1C/LfEKg7PX+39U9+9gOnc81099Pj9BDFgKThbkT1Agudx/dbGkZFjLXI66K798WF4VGzGAMOjxxcYyhR+Pmaz5gpBgd/r9lu1G0T2GoZDZFQ6PQnQ2Td+fvcq6ikmm+FGqMpNdZHT8tO2WLbDYkfP3sexUe5r5XtNQcA1k3MrP0DDG1FApvH+CTbBYhDxvBRluLiTs461ZS9lwqUaUEeEp5RvO7qNnuCTCZVo1CjGZT0KnnBCSJrg0+8Eav8eGE5+0XazYHEW2DBJBTuP4+CmwCc4zvIjUgnGD9Y8p7zhe+blQpDuVDj1434CBLNecFuh4Q/R/kMOIYJP3b/ebguwWITelXiVNkg+C3Pp6XzI/ssgbi23em5d09RB/AL4gWZPrGaRMxe9VcDWbcn5iZlynQfhzxMaLBOLfzkhKu+V2lGDnEbkZF3hsDYIOfNkfF1FhI78TCA5N/ypBKmrGIV06jmqxyP0NuQuqGmnnJF1MIHakfvF/tErZyV+utWZFpBVxwGJ+rp+lWqSFXh1VaOUgMBeGW1Yw4ODoH3ZJK+JqEFH4j69EL23HiKFB8j+CmeNiKo9R7CtZ0iilGOxpJcUJmsbo48SQphumXmfoeExqASdAua6213EH1fjXvjC3copzm0jsZFI8uXnGy51y087neP9nM3SQih5x9uqxq/pys1GdbQrodEeie9XxPgun+Ig8B7dDGh99QxG5f348ls2LSJl6lzdW5EmN1/6awA0q38rkH123ieqpiPr4UE X-Forefront-PRVS: 01480965DA X-Microsoft-Exchange-Diagnostics: =?us-ascii?Q?1;CY1PR0301MB0746;23:clW+CnmygKiLPhXqLqaVEWh8Nc4KBJMiohkiB5+?= =?us-ascii?Q?bO/vd0fedKNbhCnyDpNfPlCWmXgFq05yK7ujE1uOPd4siX6QN24QwQ6AL5Xs?= =?us-ascii?Q?9YzE5TUivubmabMdd0SetJLO1QDF0tmulJ1BAoJUxTMjzUM8P6naZl+blCoD?= =?us-ascii?Q?/t+wvpEOPSB8IaDRV8D/KV5YWon1D3MBoht7m+K0XAvr+XYIB4xMPvxmFiMl?= =?us-ascii?Q?A2QuYhthDH40Cj67V6KP4FN5/AHG+JJpqRaTGkLvwgR58UjJNZYP+/hC3TKA?= =?us-ascii?Q?mcqBZ6SsB+MgfpYhbtu9yiCCFpD8CWm/YECgVpzY90ty/bAI9edo+MtlLZzH?= =?us-ascii?Q?m/DFWNS3fsHIGhsSlWs/tmWYgb6s+R+02FxJ8UzU2RV6XD66CSWb6oKdmRNd?= =?us-ascii?Q?gIfi/Do2B929lJfaLGaxMFGHZGOhdRB5VT3qcWbjfNKgRCzA0Smtglo9mb4q?= =?us-ascii?Q?KVh023M2ka0ZIJJV2pGD8Xpq5j4+0hy8JJrvfii1/l9/KpK07oAdu42L6xQF?= =?us-ascii?Q?j5ElzJkg53Ugq4E99crUuyCNCz3s+VMHLBbVObVQrc6EbtiM0mZKCB8BL/EN?= =?us-ascii?Q?8xRp55Oz62CDJIURvsnAFfxqg3s2jcqkaBaMeAQ/a/mTIkZn/y7wcRUS42qc?= =?us-ascii?Q?wqttewI1QPNkGnnTNEfphozQ4Bgl2/RRf24/gjFJlyfBnLVaw7D2cRTDJcZg?= =?us-ascii?Q?kVAW3dFwEpGDdfAseCUZoih5Cwmrz/0/Ort9ku/W8RVhEwVX1Kof1nNVakBb?= =?us-ascii?Q?uDt87f36x3pQ0fMoVXE2zT/qJlEAKZZ2/fUZuCWzYAGurA83aXOpBk/ivMHf?= =?us-ascii?Q?/THh17fq53HKRFR71d4ygQAkPo6QgimIBdF0P5R1z3K/OMiByBq2T+IJCD2S?= =?us-ascii?Q?3HWzhVxXCwogtC/IB3CFxHHO+yhVfWYDZqCd0gvPcjb0gx+GjP7KwHtYQ/Rk?= =?us-ascii?Q?Z7UbWK1zC+yttNSyElVwBnpdjmnvGTPsrXR+x8StFPPN+eK4OBVwzy8dtjd0?= =?us-ascii?Q?2AKgx9nQapGDVJy7kcBHvx8xV4DJzPHJnfuj6EXW7tikH7rV1CNWZ7J51gNA?= =?us-ascii?Q?9BxO/USDC7DuON+pQ0o5/qAQvoGD+BcazI93dRCMP5YaFAkswIQtvltobV3L?= =?us-ascii?Q?BuIz6kFhKHLDwooxt3DwkpThFWcLbo6XTml+UfsDcXJBLdaxsiuWc7MzitVh?= =?us-ascii?Q?zw0E6yQi2H7zunexF34O91ai0LScrMCl9E4xQ0KrkB5S1enjJsTtCYy/nOHN?= =?us-ascii?Q?BtPCDhD8xdXsTc7OiTDCVn5IhPoYZgXN8llmItvIhXFasBYVZF/ktzQclTsH?= =?us-ascii?Q?YhSl73w671A8256o6kG5zfECfgip0toAy9e7c8dcGwHRIIRnJOpZM5BEWCnv?= =?us-ascii?Q?f3H7pBxxXetJTn74ZD18AeSo0FlA=3D?= X-Microsoft-Exchange-Diagnostics: 1;CY1PR0301MB0746;6:PR9zQdxNaQ6g9ld0HAq+lU4m7RO9LkRjgiCLuisVC0UE921cCiyowy2RduJxu6rQkMDtDZMSMsck8d0y8nxrL38hXJN1aS5jzjb/LG0oUkusOPn+ru6bQYfzzqKZxLgevLYvrNnqdphqAcPNznWPaQ8kYYcfFWREkgA9TBtHQa1QNXWOBT6DY7Nxb1Vn3yd5xtdzlRlrDT6PESQnl6QRsiMFYcgMNtdRqrcDVM8aECL4XL3Qia6oRUn1fvwpaVQnzwY8Bab1WM9IuNIbQiTZN3sR4WzKpzHysj8NTiL1DK4C5JeYoRB6pjA7NNz0B1XEXE5OsmeDFiVJaOvR2XBmww==;5:bJHejw6rfkNkDOjghSM5KwRpQSBbVlZU9n6ljdeT9KXCEQ0RoglKtzdEFZklRVdBd07Lx4rofzBmNV4bgS3WO8d09a1B8/Z1dEbbD3Szag3AkKuHfuqaj8YtoxrkwZpwXVyqwheOIUAl15jti1fK+F346CSRSc5stDL1MqI/+lyoJZ+TboUiAhMg0Ys8/RHj;24:qQOT+CF/DVxhptAhdo8MnODaoqKM3FzHP7DgCUXOm3n0X7FLIxSOeZ8P+cCKv5JwRyR75e5uKgjAjmYlD3MqlkNLc6JcOFRT821Qu5aORoc= SpamDiagnosticOutput: 1:99 SpamDiagnosticMetadata: NSPM X-Microsoft-Exchange-Diagnostics: 1;CY1PR0301MB0746;7:KePPO8fe34q5ue+oPuUnVI+K30uX/4IvzbcbHkwiZEOZszrF8U5gA67y6ULZSD76eo/Sch51dScDa5g8QlYoO8z6BK6H06T+9IJtm9QHR1ua/X9qO66yiGPs9mfKSZseIn/hglxhp2njl5iVMMVdNmAamju0f3XpGSTrUdZU1YXOiarvabIJvfD1E7ahUGI4B6ImJG4TF8MtnQmtFJKTBpB+LAdJJ0yl0Ob95OQckcbYGWpjpLyONGtbNIEWeEzFy+76NC0xXDMZ/7AJqWXOR4uMFaf00B1cPe3tMPuN2ozG7FGOdnAmLizaLR9iEta5aT/L4xPxfNJ/e8cdrS1sJZsJ+LJovA2j1ovG/ibrmIY= X-MS-Exchange-CrossTenant-OriginalArrivalTime: 06 Dec 2016 09:34:44.1630 (UTC) X-MS-Exchange-CrossTenant-Id: 5afe0b00-7697-4969-b663-5eab37d5f47e X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=5afe0b00-7697-4969-b663-5eab37d5f47e;Ip=[192.88.168.50];Helo=[tx30smr01.am.freescale.net] X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: CY1PR0301MB0746 Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 10760 Lines: 319 Add support for several ethtool operations: show hardware statistics, get/set link settings, get hash configuration. Signed-off-by: Ioana Radulescu Signed-off-by: Bogdan Hamciuc --- drivers/staging/fsl-dpaa2/ethernet/Makefile | 2 +- drivers/staging/fsl-dpaa2/ethernet/dpaa2-eth.c | 6 + drivers/staging/fsl-dpaa2/ethernet/dpaa2-eth.h | 6 + drivers/staging/fsl-dpaa2/ethernet/dpaa2-ethtool.c | 233 ++++++++++++++++++++ 4 files changed, 246 insertions(+), 1 deletions(-) create mode 100644 drivers/staging/fsl-dpaa2/ethernet/dpaa2-ethtool.c diff --git a/drivers/staging/fsl-dpaa2/ethernet/Makefile b/drivers/staging/fsl-dpaa2/ethernet/Makefile index 4897d39..4327ebe 100644 --- a/drivers/staging/fsl-dpaa2/ethernet/Makefile +++ b/drivers/staging/fsl-dpaa2/ethernet/Makefile @@ -4,4 +4,4 @@ obj-$(CONFIG_FSL_DPAA2_ETH) += fsl-dpaa2-eth.o -fsl-dpaa2-eth-objs := dpaa2-eth.o dpni.o +fsl-dpaa2-eth-objs := dpaa2-eth.o dpaa2-ethtool.o dpni.o diff --git a/drivers/staging/fsl-dpaa2/ethernet/dpaa2-eth.c b/drivers/staging/fsl-dpaa2/ethernet/dpaa2-eth.c index eda7885..cfa1d36 100644 --- a/drivers/staging/fsl-dpaa2/ethernet/dpaa2-eth.c +++ b/drivers/staging/fsl-dpaa2/ethernet/dpaa2-eth.c @@ -45,6 +45,8 @@ MODULE_AUTHOR("Freescale Semiconductor, Inc"); MODULE_DESCRIPTION("Freescale DPAA2 Ethernet Driver"); +const char dpaa2_eth_drv_version[] = "0.1"; + static void validate_rx_csum(struct dpaa2_eth_priv *priv, u32 fd_status, struct sk_buff *skb) @@ -1939,6 +1941,8 @@ int dpaa2_eth_set_hash(struct net_device *net_dev, u64 flags) key->extract.from_hdr.type = DPKG_FULL_FIELD; key->extract.from_hdr.field = hash_fields[i].cls_field; cls_cfg.num_extracts++; + + priv->rx_hash_fields |= hash_fields[i].rxnfc_field; } dma_mem = kzalloc(DPAA2_CLASSIFIER_DMA_SIZE, GFP_DMA | GFP_KERNEL); @@ -2365,6 +2369,8 @@ static int dpaa2_eth_probe(struct fsl_mc_device *dpni_dev) if (err) goto err_alloc_rings; + net_dev->ethtool_ops = &dpaa2_ethtool_ops; + err = setup_irqs(dpni_dev); if (err) { netdev_warn(net_dev, "Failed to set link interrupt, fall back to polling\n"); diff --git a/drivers/staging/fsl-dpaa2/ethernet/dpaa2-eth.h b/drivers/staging/fsl-dpaa2/ethernet/dpaa2-eth.h index 8827c24..b757a99 100644 --- a/drivers/staging/fsl-dpaa2/ethernet/dpaa2-eth.h +++ b/drivers/staging/fsl-dpaa2/ethernet/dpaa2-eth.h @@ -279,6 +279,9 @@ struct dpaa2_eth_priv { struct dpni_link_state link_state; bool do_link_poll; struct task_struct *poll_thread; + + /* enabled ethtool hashing bits */ + u64 rx_hash_fields; }; /* default Rx hash options, set during probing */ @@ -292,6 +295,9 @@ struct dpaa2_eth_priv { /* Required by struct dpni_rx_tc_dist_cfg::key_cfg_iova */ #define DPAA2_CLASSIFIER_DMA_SIZE 256 +extern const struct ethtool_ops dpaa2_ethtool_ops; +extern const char dpaa2_eth_drv_version[]; + int dpaa2_eth_set_hash(struct net_device *net_dev, u64 flags); static int dpaa2_eth_queue_count(struct dpaa2_eth_priv *priv) diff --git a/drivers/staging/fsl-dpaa2/ethernet/dpaa2-ethtool.c b/drivers/staging/fsl-dpaa2/ethernet/dpaa2-ethtool.c new file mode 100644 index 0000000..09cc2c7 --- /dev/null +++ b/drivers/staging/fsl-dpaa2/ethernet/dpaa2-ethtool.c @@ -0,0 +1,233 @@ +/* Copyright 2014-2016 Freescale Semiconductor Inc. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * * Neither the name of Freescale Semiconductor nor the + * names of its contributors may be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * + * ALTERNATIVELY, this software may be distributed under the terms of the + * GNU General Public License ("GPL") as published by the Free Software + * Foundation, either version 2 of that License or (at your option) any + * later version. + * + * THIS SOFTWARE IS PROVIDED BY Freescale Semiconductor ``AS IS'' AND ANY + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL Freescale Semiconductor BE LIABLE FOR ANY + * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include "dpni.h" /* DPNI_LINK_OPT_* */ +#include "dpaa2-eth.h" + +/* To be kept in sync with DPNI statistics */ +char dpaa2_ethtool_stats[][ETH_GSTRING_LEN] = { + "rx frames", + "rx bytes", + "rx mcast frames", + "rx mcast bytes", + "rx bcast frames", + "rx bcast bytes", + "tx frames", + "tx bytes", + "tx mcast frames", + "tx mcast bytes", + "tx bcast frames", + "tx bcast bytes", + "rx filtered frames", + "rx discarded frames", + "rx nobuffer discards", + "tx discarded frames", + "tx confirmed frames", +}; + +#define DPAA2_ETH_NUM_STATS ARRAY_SIZE(dpaa2_ethtool_stats) + +static void dpaa2_eth_get_drvinfo(struct net_device *net_dev, + struct ethtool_drvinfo *drvinfo) +{ + strlcpy(drvinfo->driver, KBUILD_MODNAME, sizeof(drvinfo->driver)); + strlcpy(drvinfo->version, dpaa2_eth_drv_version, + sizeof(drvinfo->version)); + strlcpy(drvinfo->fw_version, "N/A", sizeof(drvinfo->fw_version)); + strlcpy(drvinfo->bus_info, dev_name(net_dev->dev.parent->parent), + sizeof(drvinfo->bus_info)); +} + +static int +dpaa2_eth_get_link_ksettings(struct net_device *net_dev, + struct ethtool_link_ksettings *link_settings) +{ + struct dpni_link_state state = {0}; + int err = 0; + struct dpaa2_eth_priv *priv = netdev_priv(net_dev); + + err = dpni_get_link_state(priv->mc_io, 0, priv->mc_token, &state); + if (err) { + netdev_err(net_dev, "ERROR %d getting link state", err); + goto out; + } + + /* At the moment, we have no way of interrogating the DPMAC + * from the DPNI side - and for that matter there may exist + * no DPMAC at all. So for now we just don't report anything + * beyond the DPNI attributes. + */ + if (state.options & DPNI_LINK_OPT_AUTONEG) + link_settings->base.autoneg = AUTONEG_ENABLE; + if (!(state.options & DPNI_LINK_OPT_HALF_DUPLEX)) + link_settings->base.duplex = DUPLEX_FULL; + link_settings->base.speed = state.rate; + +out: + return err; +} + +static int +dpaa2_eth_set_link_ksettings(struct net_device *net_dev, + const struct ethtool_link_ksettings *link_settings) +{ + struct dpni_link_cfg cfg = {0}; + struct dpaa2_eth_priv *priv = netdev_priv(net_dev); + int err = 0; + + netdev_dbg(net_dev, "Setting link parameters..."); + + /* Due to a temporary MC limitation, the DPNI must be down + * in order to be able to change link settings. Taking steps to let + * the user know that. + */ + if (netif_running(net_dev)) { + netdev_info(net_dev, "Sorry, interface must be brought down first.\n"); + return -EACCES; + } + + cfg.rate = link_settings->base.speed; + if (link_settings->base.autoneg == AUTONEG_ENABLE) + cfg.options |= DPNI_LINK_OPT_AUTONEG; + else + cfg.options &= ~DPNI_LINK_OPT_AUTONEG; + if (link_settings->base.duplex == DUPLEX_HALF) + cfg.options |= DPNI_LINK_OPT_HALF_DUPLEX; + else + cfg.options &= ~DPNI_LINK_OPT_HALF_DUPLEX; + + err = dpni_set_link_cfg(priv->mc_io, 0, priv->mc_token, &cfg); + if (err) + /* ethtool will be loud enough if we return an error; no point + * in putting our own error message on the console by default + */ + netdev_dbg(net_dev, "ERROR %d setting link cfg", err); + + return err; +} + +static void dpaa2_eth_get_strings(struct net_device *netdev, u32 stringset, + u8 *data) +{ + u8 *p = data; + int i; + + switch (stringset) { + case ETH_SS_STATS: + for (i = 0; i < DPAA2_ETH_NUM_STATS; i++) { + strlcpy(p, dpaa2_ethtool_stats[i], ETH_GSTRING_LEN); + p += ETH_GSTRING_LEN; + } + break; + } +} + +static int dpaa2_eth_get_sset_count(struct net_device *net_dev, int sset) +{ + switch (sset) { + case ETH_SS_STATS: /* ethtool_get_stats(), ethtool_get_drvinfo() */ + return DPAA2_ETH_NUM_STATS; + default: + return -EOPNOTSUPP; + } +} + +/** Fill in hardware counters, as returned by MC. + */ +static void dpaa2_eth_get_ethtool_stats(struct net_device *net_dev, + struct ethtool_stats *stats, + u64 *data) +{ + int i = 0; + int j, k, err; + int num_cnt; + union dpni_statistics dpni_stats; + struct dpaa2_eth_priv *priv = netdev_priv(net_dev); + + memset(data, 0, sizeof(u64) * DPAA2_ETH_NUM_STATS); + + /* Print standard counters, from DPNI statistics */ + for (j = 0; j <= 2; j++) { + err = dpni_get_statistics(priv->mc_io, 0, priv->mc_token, + j, &dpni_stats); + if (err != 0) + netdev_warn(net_dev, "dpni_get_stats(%d) failed", j); + switch (j) { + case 0: + num_cnt = sizeof(dpni_stats.page_0) / sizeof(u64); + break; + case 1: + num_cnt = sizeof(dpni_stats.page_1) / sizeof(u64); + break; + case 2: + num_cnt = sizeof(dpni_stats.page_2) / sizeof(u64); + break; + default: + break; + } + for (k = 0; k < num_cnt; k++) + *(data + i++) = dpni_stats.raw.counter[k]; + } +} + +static int dpaa2_eth_get_rxnfc(struct net_device *net_dev, + struct ethtool_rxnfc *rxnfc, u32 *rule_locs) +{ + struct dpaa2_eth_priv *priv = netdev_priv(net_dev); + + switch (rxnfc->cmd) { + case ETHTOOL_GRXFH: + /* we purposely ignore cmd->flow_type for now, because the + * classifier only supports a single set of fields for all + * protocols + */ + rxnfc->data = priv->rx_hash_fields; + break; + case ETHTOOL_GRXRINGS: + rxnfc->data = dpaa2_eth_queue_count(priv); + break; + default: + return -EOPNOTSUPP; + } + + return 0; +} + +const struct ethtool_ops dpaa2_ethtool_ops = { + .get_drvinfo = dpaa2_eth_get_drvinfo, + .get_link = ethtool_op_get_link, + .get_link_ksettings = dpaa2_eth_get_link_ksettings, + .set_link_ksettings = dpaa2_eth_set_link_ksettings, + .get_sset_count = dpaa2_eth_get_sset_count, + .get_ethtool_stats = dpaa2_eth_get_ethtool_stats, + .get_strings = dpaa2_eth_get_strings, + .get_rxnfc = dpaa2_eth_get_rxnfc, +}; -- 1.7.3.4