From af9274369951ff5b1eed4017ac3220ac3f3d1610 Mon Sep 17 00:00:00 2001 From: Bhadram Varka Date: Mon, 3 May 2021 22:36:28 +0530 Subject: [PATCH] nvethernet: update UPHY GBE mode with DT/sysfs Bug 3288030 Change-Id: Id700c2b074c3fd8968ac632e84d7cdc0d75d1e32 Signed-off-by: Bhadram Varka Reviewed-on: https://git-master.nvidia.com/r/c/linux-nvidia/+/2531233 Reviewed-by: Narayan Reddy Reviewed-by: Rakesh Goyal --- .../ethernet/nvidia/nvethernet/ether_linux.c | 8 +++ .../net/ethernet/nvidia/nvethernet/sysfs.c | 71 +++++++++++++++++++ 2 files changed, 79 insertions(+) diff --git a/drivers/net/ethernet/nvidia/nvethernet/ether_linux.c b/drivers/net/ethernet/nvidia/nvethernet/ether_linux.c index 18d76248..9e66a47e 100644 --- a/drivers/net/ethernet/nvidia/nvethernet/ether_linux.c +++ b/drivers/net/ethernet/nvidia/nvethernet/ether_linux.c @@ -5028,6 +5028,14 @@ static int ether_parse_dt(struct ether_priv_data *pdata) return -EINVAL; } + ret = of_property_read_u32(np, "nvidia,uphy-gbe-mode", + &osi_core->uphy_gbe_mode); + if (ret < 0) { + dev_info(dev, + "failed to read UPHY GBE mode - default to 10G\n"); + osi_core->uphy_gbe_mode = OSI_ENABLE; + } + /* Enable VLAN strip by default */ osi_core->strip_vlan_tag = OSI_ENABLE; diff --git a/drivers/net/ethernet/nvidia/nvethernet/sysfs.c b/drivers/net/ethernet/nvidia/nvethernet/sysfs.c index 1888d807..b2df07e9 100644 --- a/drivers/net/ethernet/nvidia/nvethernet/sysfs.c +++ b/drivers/net/ethernet/nvidia/nvethernet/sysfs.c @@ -1938,6 +1938,76 @@ static DEVICE_ATTR(macsec_irq_stats, (S_IRUGO | S_IWUSR), NULL); #endif /* MACSEC_SUPPORT */ +/** + * @brief Shows the current driver setting for UPHY GBE mocd + * + * Algorithm: Display the current PTP mode setting. + * + * @param[in] dev: Device data. + * @param[in] attr: Device attribute + * @param[in] buf: Buffer to store the current PTP mode + * + * @note MAC and PHY need to be initialized. + */ +static ssize_t ether_uphy_gbe_mode_show(struct device *dev, + struct device_attribute *attr, + char *buf) +{ + struct net_device *ndev = (struct net_device *)dev_get_drvdata(dev); + struct ether_priv_data *pdata = netdev_priv(ndev); + struct osi_core_priv_data *osi_core = pdata->osi_core; + + return scnprintf(buf, PAGE_SIZE, "%s\n", + (osi_core->uphy_gbe_mode == OSI_ENABLE) ? + "10G" : "5G"); +} + +/** + * @brief Set the user setting of UPHY GBE mode. + * + * Algorithm: This is used to set the user mode settings of UPHY GBE mode + * @param[in] dev: Device data. + * @param[in] attr: Device attribute + * @param[in] buf: Buffer which contains the user settings of UPHY GBE mode + * @param[in] size: size of buffer + * + * @note MAC and PHY need to be initialized. + * + * @return size of buffer. + */ +static ssize_t ether_uphy_gbe_mode_store(struct device *dev, + struct device_attribute *attr, + const char *buf, size_t size) +{ + struct net_device *ndev = (struct net_device *)dev_get_drvdata(dev); + struct ether_priv_data *pdata = netdev_priv(ndev); + struct osi_core_priv_data *osi_core = pdata->osi_core; + + if (netif_running(ndev)) { + dev_err(pdata->dev, "Not Allowed. Ether interface is up\n"); + return size; + } + + if (strncmp(buf, "10G", 3) == 0U) { + osi_core->uphy_gbe_mode = OSI_ENABLE; + } else if (strncmp(buf, "5G", 2) == 0U) { + osi_core->uphy_gbe_mode = OSI_DISABLE; + } else { + dev_err(pdata->dev, + "Invalid value passed. Valid values are 10G or 5G\n"); + } + + return size; +} + +/** + * @brief Sysfs attribute for UPHY GBE Mode + * + */ +static DEVICE_ATTR(uphy_gbe_mode, (S_IRUGO | S_IWUSR), + ether_uphy_gbe_mode_show, + ether_uphy_gbe_mode_store); + /** * @brief Sysfs attribute for MAC loopback * @@ -2163,6 +2233,7 @@ static struct attribute *ether_sysfs_attrs[] = { &dev_attr_macsec_dbg_buffers.attr, &dev_attr_macsec_dbg_events.attr, #endif /* MACSEC_SUPPORT */ + &dev_attr_uphy_gbe_mode.attr, NULL };