Received: by 2002:a05:6a10:1287:0:0:0:0 with SMTP id d7csp6505829pxv; Thu, 29 Jul 2021 16:56:25 -0700 (PDT) X-Google-Smtp-Source: ABdhPJydz+TRPeSZatywbPHKentXQipfYj9p9bXrhx/w4SAStBC9PAiUmhCW71EcvEo8vc2wZdjX X-Received: by 2002:a02:85a5:: with SMTP id d34mr6516001jai.132.1627602985501; Thu, 29 Jul 2021 16:56:25 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1627602985; cv=none; d=google.com; s=arc-20160816; b=xmkoy/4K2WSCDIQP1/0eLoWZnRP0ibMPGdv4s2ybiv8Ds29rztDXT5Sl+JkD20Ek3j oibMjjBDtqGShygwOM51hMeU8Dv3Ck0/faHHd6keZZKdyqfQmRkmuuNeIK2ZKJagBxry cwmv+eUt9zY/UJ+r/aqADnsgvTwe3oXFiHd9HR/cr0Te+HhkZmbYOmwnC88wKQp4nxVs maFoQq9d8XaPWUzbrNWF9rYdDqoCe7mEobrj+ZC41sMQMiq0xRdFVF9fXkffPMvmvGgd N11LfJDQxxTSikZR0RvIaSgWdbWONVr8sX/rEO8wecqQSZa6dbMDzEeKLfmvakOrKXwC 34jQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from:dkim-signature; bh=HW1DeExVgL7VR9caV/O8C8vq3x0daXvbXqbPLUM4oaY=; b=pPwIY4GjDNQ5RuaoCKI7R3yAtrWoxG2LEqoTJXk2ZC9kVIWBXf6MBbu7yiQAKCnW7B ldzj33hoN0U7q0fdc0FfRKpQtuInjqZDoUBKByNlQHG7nl7kI1NlTJBSYd2PmmKUvevR LxZItcpwOjlN/Jv8C9VjJT6USQ2s6U3S2JUkXcomvgfpd9RzH89a9sccYKaEl7lE9tob VMzw/hN+ssOP5yuOWTwiuv/dAq5hBLAi7oNhXxE1RC0kuD+79mpawwiSRPGoFISmttsU 7pnc9KyD8xzpFIXEJonwQM3emDaAmf0UEppPMTFpeTV7Dz7TPbCBVyN9d6oD9AilvNZI JxPA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@cisco.com header.s=iport header.b=YAwUwPJX; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=cisco.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id g6si4684103ioc.2.2021.07.29.16.55.58; Thu, 29 Jul 2021 16:56:25 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@cisco.com header.s=iport header.b=YAwUwPJX; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=cisco.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235149AbhG2Xvy (ORCPT + 99 others); Thu, 29 Jul 2021 19:51:54 -0400 Received: from rcdn-iport-7.cisco.com ([173.37.86.78]:45804 "EHLO rcdn-iport-7.cisco.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234826AbhG2Xvy (ORCPT ); Thu, 29 Jul 2021 19:51:54 -0400 X-Greylist: delayed 425 seconds by postgrey-1.27 at vger.kernel.org; Thu, 29 Jul 2021 19:51:54 EDT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=cisco.com; i=@cisco.com; l=7288; q=dns/txt; s=iport; t=1627602710; x=1628812310; h=from:to:cc:subject:date:message-id:mime-version: content-transfer-encoding; bh=/Ap9mbPXpL2l+I0gCWzJlCwjSQrqoLRXRbu/ViyjT8A=; b=YAwUwPJX+8Zvr6umXiDLN/gmM+2vp82QcP8yiKABunvdzTtW+ZfZOMPT w99HAr19Nj2WW34DL+488VJagL0+/oHGNQ1A+MKglhcTONDT0kIwlS/di UsQswd6EbpxWUcbouQfOSuEe4Rz8o58OzRruDajfKOrU9S05ceDGgrowH s=; X-IronPort-AV: E=Sophos;i="5.84,280,1620691200"; d="scan'208";a="899786753" Received: from rcdn-core-6.cisco.com ([173.37.93.157]) by rcdn-iport-7.cisco.com with ESMTP/TLS/DHE-RSA-SEED-SHA; 29 Jul 2021 23:44:44 +0000 Received: from zorba.cisco.com ([10.24.25.127]) by rcdn-core-6.cisco.com (8.15.2/8.15.2) with ESMTP id 16TNihvU032246; Thu, 29 Jul 2021 23:44:43 GMT From: Daniel Walker To: Giuseppe Cavallaro , Alexandre Torgue , Jose Abreu , Maxime Coquelin , Russell King Cc: Balamurugan Selvarajan , xe-linux-external@cisco.com, "David S. Miller" , Jakub Kicinski , netdev@vger.kernel.org, linux-stm32@st-md-mailman.stormreply.com, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org Subject: [RFC-PATCH] net: stmmac: Add KR port support. Date: Thu, 29 Jul 2021 16:44:42 -0700 Message-Id: <20210729234443.1713722-1-danielwa@cisco.com> X-Mailer: git-send-email 2.25.1 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Auto-Response-Suppress: DR, OOF, AutoReply X-Outbound-SMTP-Client: 10.24.25.127, [10.24.25.127] X-Outbound-Node: rcdn-core-6.cisco.com Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Balamurugan Selvarajan For KR port the mii interface is a chip-to-chip interface without a mechanical connector. So PHY inits are not applicable. In this case MAC is configured to operate at forced speed(1000Mbps) and full duplex. Modified driver to accommodate PHY and NON-PHY mode. Cc: xe-linux-external@cisco.com Signed-off-by: Balamurugan Selvarajan Signed-off-by: Daniel Walker --- drivers/net/ethernet/stmicro/stmmac/common.h | 2 + .../net/ethernet/stmicro/stmmac/stmmac_main.c | 89 +++++++++++++------ 2 files changed, 65 insertions(+), 26 deletions(-) diff --git a/drivers/net/ethernet/stmicro/stmmac/common.h b/drivers/net/ethernet/stmicro/stmmac/common.h index 5fecc83f175b..6458ce5ec0bd 100644 --- a/drivers/net/ethernet/stmicro/stmmac/common.h +++ b/drivers/net/ethernet/stmicro/stmmac/common.h @@ -435,6 +435,8 @@ struct dma_features { #define MAC_CTRL_REG 0x00000000 /* MAC Control */ #define MAC_ENABLE_TX 0x00000008 /* Transmitter Enable */ #define MAC_ENABLE_RX 0x00000004 /* Receiver Enable */ +#define MAC_FULL_DUPLEX 0x00000800 +#define MAC_PORT_SELECT 0x00008000 /* Default LPI timers */ #define STMMAC_DEFAULT_LIT_LS 0x3E8 diff --git a/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c b/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c index 7b8404a21544..0b31aae65f3a 100644 --- a/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c +++ b/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c @@ -3212,6 +3212,7 @@ static int stmmac_hw_setup(struct net_device *dev, bool init_ptp) bool sph_en; u32 chan; int ret; + int speed; /* DMA initialization and SW reset */ ret = stmmac_init_dma_engine(priv); @@ -3226,7 +3227,9 @@ static int stmmac_hw_setup(struct net_device *dev, bool init_ptp) /* PS and related bits will be programmed according to the speed */ if (priv->hw->pcs) { - int speed = priv->plat->mac_port_sel_speed; + speed = priv->plat->mac_port_sel_speed; + if (priv->plat->phy_interface == PHY_INTERFACE_MODE_NA) + speed = SPEED_1000; if ((speed == SPEED_10) || (speed == SPEED_100) || (speed == SPEED_1000)) { @@ -3256,6 +3259,17 @@ static int stmmac_hw_setup(struct net_device *dev, bool init_ptp) /* Enable the MAC Rx/Tx */ stmmac_mac_set(priv, priv->ioaddr, true); + if (priv->plat->phy_interface == PHY_INTERFACE_MODE_NA) { + /* + * Force MAC PORT SPEED to 1000Mbps and Full Duplex. + */ + u32 ctrl = readl(priv->ioaddr + MAC_CTRL_REG); + ctrl |= MAC_FULL_DUPLEX; + ctrl &= ~(MAC_PORT_SELECT); + writel(ctrl, priv->ioaddr + MAC_CTRL_REG); + } + + /* Set the HW DMA mode and the COE */ stmmac_dma_operation_mode(priv); @@ -3291,8 +3305,14 @@ static int stmmac_hw_setup(struct net_device *dev, bool init_ptp) } } - if (priv->hw->pcs) - stmmac_pcs_ctrl_ane(priv, priv->ioaddr, 1, priv->hw->ps, 0); + if (priv->hw->pcs) { + if (priv->plat->phy_interface != PHY_INTERFACE_MODE_NA) { + stmmac_pcs_ctrl_ane(priv, priv->ioaddr, 1, priv->hw->ps, 0); + } else { + /* Disable Autoneg */ + writel(0x0, priv->ioaddr + GMAC_PCS_BASE); + } + } /* set TX and RX rings length */ stmmac_set_rings_length(priv); @@ -3644,12 +3664,14 @@ int stmmac_open(struct net_device *dev) priv->hw->pcs != STMMAC_PCS_RTBI && (!priv->hw->xpcs || xpcs_get_an_mode(priv->hw->xpcs, mode) != DW_AN_C73)) { - ret = stmmac_init_phy(dev); - if (ret) { - netdev_err(priv->dev, - "%s: Cannot attach to PHY (error: %d)\n", - __func__, ret); - goto init_phy_error; + if (priv->plat->phy_interface != PHY_INTERFACE_MODE_NA) { + ret = stmmac_init_phy(dev); + if (ret) { + netdev_err(priv->dev, + "%s: Cannot attach to PHY (error: %d)\n", + __func__, ret); + goto init_phy_error; + } } } @@ -3705,7 +3727,8 @@ int stmmac_open(struct net_device *dev) stmmac_init_coalesce(priv); - phylink_start(priv->phylink); + if (priv->plat->phy_interface != PHY_INTERFACE_MODE_NA) + phylink_start(priv->phylink); /* We may have called phylink_speed_down before */ phylink_speed_up(priv->phylink); @@ -3716,10 +3739,14 @@ int stmmac_open(struct net_device *dev) stmmac_enable_all_queues(priv); netif_tx_start_all_queues(priv->dev); + if (priv->plat->phy_interface == PHY_INTERFACE_MODE_NA) + netif_carrier_on(dev); + return 0; irq_error: - phylink_stop(priv->phylink); + if (priv->plat->phy_interface != PHY_INTERFACE_MODE_NA) + phylink_stop(priv->phylink); for (chan = 0; chan < priv->plat->tx_queues_to_use; chan++) hrtimer_cancel(&priv->tx_queue[chan].txtimer); @@ -3728,7 +3755,8 @@ int stmmac_open(struct net_device *dev) init_error: free_dma_desc_resources(priv); dma_desc_error: - phylink_disconnect_phy(priv->phylink); + if (priv->plat->phy_interface != PHY_INTERFACE_MODE_NA) + phylink_disconnect_phy(priv->phylink); init_phy_error: pm_runtime_put(priv->device); return ret; @@ -3758,8 +3786,10 @@ int stmmac_release(struct net_device *dev) if (device_may_wakeup(priv->device)) phylink_speed_down(priv->phylink, false); /* Stop and disconnect the PHY */ - phylink_stop(priv->phylink); - phylink_disconnect_phy(priv->phylink); + if (priv->plat->phy_interface != PHY_INTERFACE_MODE_NA) { + phylink_stop(priv->phylink); + phylink_disconnect_phy(priv->phylink); + } stmmac_disable_all_queues(priv); @@ -6986,12 +7016,15 @@ int stmmac_dvr_probe(struct device *device, if (priv->hw->pcs != STMMAC_PCS_TBI && priv->hw->pcs != STMMAC_PCS_RTBI) { /* MDIO bus Registration */ - ret = stmmac_mdio_register(ndev); - if (ret < 0) { - dev_err(priv->device, - "%s: MDIO bus (id: %d) registration failed", - __func__, priv->plat->bus_id); - goto error_mdio_register; + + if (priv->plat->phy_interface != PHY_INTERFACE_MODE_NA) { + ret = stmmac_mdio_register(ndev); + if (ret < 0) { + dev_err(priv->device, + "%s: MDIO bus (id: %d) registration failed", + __func__, priv->plat->bus_id); + goto error_mdio_register; + } } } @@ -7004,10 +7037,12 @@ int stmmac_dvr_probe(struct device *device, goto error_xpcs_setup; } - ret = stmmac_phy_setup(priv); - if (ret) { - netdev_err(ndev, "failed to setup phy (%d)\n", ret); - goto error_phy_setup; + if (priv->plat->phy_interface != PHY_INTERFACE_MODE_NA) { + ret = stmmac_phy_setup(priv); + if (ret) { + netdev_err(ndev, "failed to setup phy (%d)\n", ret); + goto error_phy_setup; + } } ret = register_netdev(ndev); @@ -7039,11 +7074,13 @@ int stmmac_dvr_probe(struct device *device, error_serdes_powerup: unregister_netdev(ndev); error_netdev_register: - phylink_destroy(priv->phylink); + if (priv->plat->phy_interface != PHY_INTERFACE_MODE_NA) + phylink_destroy(priv->phylink); error_xpcs_setup: error_phy_setup: if (priv->hw->pcs != STMMAC_PCS_TBI && - priv->hw->pcs != STMMAC_PCS_RTBI) + priv->hw->pcs != STMMAC_PCS_RTBI && + priv->plat->phy_interface != PHY_INTERFACE_MODE_NA) stmmac_mdio_unregister(ndev); error_mdio_register: stmmac_napi_del(ndev); -- 2.25.1