From patchwork Sat Mar 24 20:07:41 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sergei Shtylyov X-Patchwork-Id: 10306363 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 4C870600CC for ; Sat, 24 Mar 2018 20:07:50 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 3A6ED28939 for ; Sat, 24 Mar 2018 20:07:50 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 2F09428E3D; Sat, 24 Mar 2018 20:07:50 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.8 required=2.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_HI,T_DKIM_INVALID autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 39F7B28939 for ; Sat, 24 Mar 2018 20:07:49 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753693AbeCXUHr (ORCPT ); Sat, 24 Mar 2018 16:07:47 -0400 Received: from mail-lf0-f67.google.com ([209.85.215.67]:45562 "EHLO mail-lf0-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753618AbeCXUHp (ORCPT ); Sat, 24 Mar 2018 16:07:45 -0400 Received: by mail-lf0-f67.google.com with SMTP id l4-v6so18536574lfg.12 for ; Sat, 24 Mar 2018 13:07:44 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=cogentembedded-com.20150623.gappssmtp.com; s=20150623; h=subject:from:to:cc:references:organization:message-id:date :user-agent:mime-version:in-reply-to:content-language :content-transfer-encoding; bh=PNVrXQNkf+FztehSAy/xQCqbSGPUl8nKvmfz8/3to6I=; b=PK0hpY/xJhp9ynuySBeohxMdiyS/YHw1y3vnd401T58qHVhZs9KWTJwhVIZvruj/7V zFgduRrI2dcJerqEkORGZc15r0GoQcSBPWEdcPpbhEdlspKsvbyoEJj7UrEyZfJ+w1pX MXHOX9tYF48YDHskvi+BXVyBbsVu/CEjsVF0e05GKQ0sz59XVGj0BhVjkdpNe37HGaVD xj1/8P/5YG8noZjbeqtJvK6BQO56QQhF1c9yBSRx/tCjsSmqKZCY8wbZQ42uhdJcY4XY 9FNOtnY9i5ypG7SFJkddT+jNH/Bg/9IuH5I5S3Ryf5yZNzPSKRHmKzHpzLjDh0QOrzZv a43g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:subject:from:to:cc:references:organization :message-id:date:user-agent:mime-version:in-reply-to :content-language:content-transfer-encoding; bh=PNVrXQNkf+FztehSAy/xQCqbSGPUl8nKvmfz8/3to6I=; b=aEOPv+L32s9t/3eg1j7CbQ1s4Poyey5vsnRzIVIetw1VJzEl2xLwNlsg59CiCcd8m6 8YqoIjCJQAPkTptD5x3SISylFbKDWdRuilnEVOeyQIuVjAxEWikE2LJ3UAj6Tw6I4k4u M03n4siVQUYbxZe+GcX8LrSd5tUdv/1gjgsX/CF9roHE6Qw6gN4vzuBG48zn3gTEfGZN JNBbQECQZd64MupyM3ktnj47UV3ufjuBVN+RpNw44BWc7h/S5WYglbasFyUWje4MIqJC DJ7OwtB4fGxE1bVqJMsfP++rPlLsm1cK2i6Ts7YavGX36/H7xcHWNun/wC07abHEzmRV 4Rmg== X-Gm-Message-State: AElRT7GNiylunS6hAgX7unX97f/koNHHCx10HEbWDGYKcUOgvEj0ybul 5fnzeTET//9pDQFkbM4qeJq5NIuRddA= X-Google-Smtp-Source: AG47ELuy2/krMuig7r9bKfNixapqEka/9I6T8BqxUR1boQBbY+ZUW0EbD7XJU3nge0q0nrq19BBZDA== X-Received: by 10.46.154.145 with SMTP id p17mr13700268lji.28.1521922063462; Sat, 24 Mar 2018 13:07:43 -0700 (PDT) Received: from wasted.cogentembedded.com ([31.173.80.64]) by smtp.gmail.com with ESMTPSA id o8sm2591292ljj.42.2018.03.24.13.07.42 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sat, 24 Mar 2018 13:07:42 -0700 (PDT) Subject: [PATCH 1/5] sh_eth: add sh_eth_cpu_data::soft_reset() method From: Sergei Shtylyov To: netdev@vger.kernel.org Cc: linux-renesas-soc@vger.kernel.org, linux-sh@vger.kernel.org References: Organization: Cogent Embedded Message-ID: Date: Sat, 24 Mar 2018 23:07:41 +0300 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.2.1 MIME-Version: 1.0 In-Reply-To: Content-Language: en-MW Sender: linux-sh-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-sh@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP sh_eth_reset() performs a software reset which is implemented in a completely different way for the GEther-like controllers vs the other controllers due to a different layout of EDMR (and other factors) -- it therefore makes sense to convert this function to a mandatory sh_eth_cpu_data::soft_reset() method and thus get rid of the runtime controller type check via sh_eth_is_{gether|rz_fast_ether}(). Signed-off-by: Sergei Shtylyov --- drivers/net/ethernet/renesas/sh_eth.c | 135 ++++++++++++++++++++-------------- drivers/net/ethernet/renesas/sh_eth.h | 3 2 files changed, 83 insertions(+), 55 deletions(-) -- To unsubscribe from this list: send the line "unsubscribe linux-sh" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Index: net-next/drivers/net/ethernet/renesas/sh_eth.c =================================================================== --- net-next.orig/drivers/net/ethernet/renesas/sh_eth.c +++ net-next/drivers/net/ethernet/renesas/sh_eth.c @@ -501,6 +501,62 @@ static void sh_eth_chip_reset(struct net mdelay(1); } +static int sh_eth_soft_reset(struct net_device *ndev) +{ + sh_eth_modify(ndev, EDMR, EDMR_SRST_ETHER, EDMR_SRST_ETHER); + mdelay(3); + sh_eth_modify(ndev, EDMR, EDMR_SRST_ETHER, 0); + + return 0; +} + +static int sh_eth_check_soft_reset(struct net_device *ndev) +{ + int cnt; + + for (cnt = 100; cnt > 0; cnt--) { + if (!(sh_eth_read(ndev, EDMR) & EDMR_SRST_GETHER)) + return 0; + mdelay(1); + } + + netdev_err(ndev, "Device reset failed\n"); + return -ETIMEDOUT; +} + +static int sh_eth_soft_reset_gether(struct net_device *ndev) +{ + struct sh_eth_private *mdp = netdev_priv(ndev); + int ret; + + sh_eth_write(ndev, EDSR_ENALL, EDSR); + sh_eth_modify(ndev, EDMR, EDMR_SRST_GETHER, EDMR_SRST_GETHER); + + ret = sh_eth_check_soft_reset(ndev); + if (ret) + return ret; + + /* Table Init */ + sh_eth_write(ndev, 0, TDLAR); + sh_eth_write(ndev, 0, TDFAR); + sh_eth_write(ndev, 0, TDFXR); + sh_eth_write(ndev, 0, TDFFR); + sh_eth_write(ndev, 0, RDLAR); + sh_eth_write(ndev, 0, RDFAR); + sh_eth_write(ndev, 0, RDFXR); + sh_eth_write(ndev, 0, RDFFR); + + /* Reset HW CRC register */ + if (mdp->cd->hw_checksum) + sh_eth_write(ndev, 0, CSMR); + + /* Select MII mode */ + if (mdp->cd->select_mii) + sh_eth_select_mii(ndev); + + return ret; +} + static void sh_eth_set_rate_gether(struct net_device *ndev) { struct sh_eth_private *mdp = netdev_priv(ndev); @@ -521,6 +577,8 @@ static void sh_eth_set_rate_gether(struc #ifdef CONFIG_OF /* R7S72100 */ static struct sh_eth_cpu_data r7s72100_data = { + .soft_reset = sh_eth_soft_reset_gether, + .chip_reset = sh_eth_chip_reset, .set_duplex = sh_eth_set_duplex, @@ -565,6 +623,8 @@ static void sh_eth_chip_reset_r8a7740(st /* R8A7740 */ static struct sh_eth_cpu_data r8a7740_data = { + .soft_reset = sh_eth_soft_reset_gether, + .chip_reset = sh_eth_chip_reset_r8a7740, .set_duplex = sh_eth_set_duplex, .set_rate = sh_eth_set_rate_gether, @@ -620,6 +680,8 @@ static void sh_eth_set_rate_rcar(struct /* R-Car Gen1 */ static struct sh_eth_cpu_data rcar_gen1_data = { + .soft_reset = sh_eth_soft_reset, + .set_duplex = sh_eth_set_duplex, .set_rate = sh_eth_set_rate_rcar, @@ -647,6 +709,8 @@ static struct sh_eth_cpu_data rcar_gen1_ /* R-Car Gen2 and RZ/G1 */ static struct sh_eth_cpu_data rcar_gen2_data = { + .soft_reset = sh_eth_soft_reset, + .set_duplex = sh_eth_set_duplex, .set_rate = sh_eth_set_rate_rcar, @@ -694,6 +758,8 @@ static void sh_eth_set_rate_sh7724(struc /* SH7724 */ static struct sh_eth_cpu_data sh7724_data = { + .soft_reset = sh_eth_soft_reset, + .set_duplex = sh_eth_set_duplex, .set_rate = sh_eth_set_rate_sh7724, @@ -736,6 +802,8 @@ static void sh_eth_set_rate_sh7757(struc /* SH7757 */ static struct sh_eth_cpu_data sh7757_data = { + .soft_reset = sh_eth_soft_reset, + .set_duplex = sh_eth_set_duplex, .set_rate = sh_eth_set_rate_sh7757, @@ -808,6 +876,8 @@ static void sh_eth_set_rate_giga(struct /* SH7757(GETHERC) */ static struct sh_eth_cpu_data sh7757_data_giga = { + .soft_reset = sh_eth_soft_reset_gether, + .chip_reset = sh_eth_chip_reset_giga, .set_duplex = sh_eth_set_duplex, .set_rate = sh_eth_set_rate_giga, @@ -847,6 +917,8 @@ static struct sh_eth_cpu_data sh7757_dat /* SH7734 */ static struct sh_eth_cpu_data sh7734_data = { + .soft_reset = sh_eth_soft_reset_gether, + .chip_reset = sh_eth_chip_reset, .set_duplex = sh_eth_set_duplex, .set_rate = sh_eth_set_rate_gether, @@ -883,6 +955,8 @@ static struct sh_eth_cpu_data sh7734_dat /* SH7763 */ static struct sh_eth_cpu_data sh7763_data = { + .soft_reset = sh_eth_soft_reset_gether, + .chip_reset = sh_eth_chip_reset, .set_duplex = sh_eth_set_duplex, .set_rate = sh_eth_set_rate_gether, @@ -917,6 +991,8 @@ static struct sh_eth_cpu_data sh7763_dat }; static struct sh_eth_cpu_data sh7619_data = { + .soft_reset = sh_eth_soft_reset, + .register_type = SH_ETH_REG_FAST_SH3_SH2, .eesipr_value = EESIPR_RFCOFIP | EESIPR_ECIIP | @@ -935,6 +1011,8 @@ static struct sh_eth_cpu_data sh7619_dat }; static struct sh_eth_cpu_data sh771x_data = { + .soft_reset = sh_eth_soft_reset, + .register_type = SH_ETH_REG_FAST_SH3_SH2, .eesipr_value = EESIPR_RFCOFIP | EESIPR_ECIIP | @@ -974,59 +1052,6 @@ static void sh_eth_set_default_cpu_data( cd->trscer_err_mask = DEFAULT_TRSCER_ERR_MASK; } -static int sh_eth_check_reset(struct net_device *ndev) -{ - int cnt; - - for (cnt = 100; cnt > 0; cnt--) { - if (!(sh_eth_read(ndev, EDMR) & EDMR_SRST_GETHER)) - return 0; - mdelay(1); - } - - netdev_err(ndev, "Device reset failed\n"); - return -ETIMEDOUT; -} - -static int sh_eth_reset(struct net_device *ndev) -{ - struct sh_eth_private *mdp = netdev_priv(ndev); - int ret = 0; - - if (sh_eth_is_gether(mdp) || sh_eth_is_rz_fast_ether(mdp)) { - sh_eth_write(ndev, EDSR_ENALL, EDSR); - sh_eth_modify(ndev, EDMR, EDMR_SRST_GETHER, EDMR_SRST_GETHER); - - ret = sh_eth_check_reset(ndev); - if (ret) - return ret; - - /* Table Init */ - sh_eth_write(ndev, 0x0, TDLAR); - sh_eth_write(ndev, 0x0, TDFAR); - sh_eth_write(ndev, 0x0, TDFXR); - sh_eth_write(ndev, 0x0, TDFFR); - sh_eth_write(ndev, 0x0, RDLAR); - sh_eth_write(ndev, 0x0, RDFAR); - sh_eth_write(ndev, 0x0, RDFXR); - sh_eth_write(ndev, 0x0, RDFFR); - - /* Reset HW CRC register */ - if (mdp->cd->hw_checksum) - sh_eth_write(ndev, 0x0, CSMR); - - /* Select MII mode */ - if (mdp->cd->select_mii) - sh_eth_select_mii(ndev); - } else { - sh_eth_modify(ndev, EDMR, EDMR_SRST_ETHER, EDMR_SRST_ETHER); - mdelay(3); - sh_eth_modify(ndev, EDMR, EDMR_SRST_ETHER, 0); - } - - return ret; -} - static void sh_eth_set_receive_align(struct sk_buff *skb) { uintptr_t reserve = (uintptr_t)skb->data & (SH_ETH_RX_ALIGN - 1); @@ -1362,7 +1387,7 @@ static int sh_eth_dev_init(struct net_de int ret; /* Soft Reset */ - ret = sh_eth_reset(ndev); + ret = mdp->cd->soft_reset(ndev); if (ret) return ret; @@ -1463,7 +1488,7 @@ static void sh_eth_dev_exit(struct net_d */ msleep(2); /* max frame time at 10 Mbps < 1250 us */ sh_eth_get_stats(ndev); - sh_eth_reset(ndev); + mdp->cd->soft_reset(ndev); /* Set MAC address again */ update_mac_address(ndev); Index: net-next/drivers/net/ethernet/renesas/sh_eth.h =================================================================== --- net-next.orig/drivers/net/ethernet/renesas/sh_eth.h +++ net-next/drivers/net/ethernet/renesas/sh_eth.h @@ -469,6 +469,9 @@ struct sh_eth_rxdesc { /* This structure is used by each CPU dependency handling. */ struct sh_eth_cpu_data { + /* mandatory functions */ + int (*soft_reset)(struct net_device *ndev); + /* optional functions */ void (*chip_reset)(struct net_device *ndev); void (*set_duplex)(struct net_device *ndev);