From 725b8aacf1ff4c0c8c23cb451fe4b47100a572de Mon Sep 17 00:00:00 2001 From: Sanath Kumar Gampa Date: Tue, 2 Jan 2024 06:49:36 +0000 Subject: [PATCH] linux:nvidia: macsec sysfs nodes only if enabled Issue: Accessing the macsec sysfs nodes is leading to crash when macsec is disabled in DT Fix: Do not create sysfs nodes if macsec is not enabled in DT. Also update the instance_id reading as part of ether_probe which will be executed even when macsec is disabled Bug 4431523 Bug 4449611 Change-Id: I354ac142b9d49852a0d5c7557a7368e1c36b0f63 Signed-off-by: Sanath Kumar Gampa Reviewed-on: https://git-master.nvidia.com/r/c/linux-nv-oot/+/3043570 (cherry picked from commit 43136118f6a5e3cbdb09b7366f6a44ca5e52f21c) Reviewed-on: https://git-master.nvidia.com/r/c/linux-nv-oot/+/3075216 Reviewed-on: https://git-master.nvidia.com/r/c/linux-nv-oot/+/3081231 Reviewed-by: Narayana Reddy P Reviewed-by: Bhadram Varka Reviewed-by: Srinivas Ramachandran GVS: Gerrit_Virtual_Submit Tested-by: Bhadram Varka --- .../ethernet/nvidia/nvethernet/ether_linux.c | 7 +++ .../net/ethernet/nvidia/nvethernet/macsec.c | 2 +- .../net/ethernet/nvidia/nvethernet/sysfs.c | 50 +++++++++++++++++-- 3 files changed, 55 insertions(+), 4 deletions(-) diff --git a/drivers/net/ethernet/nvidia/nvethernet/ether_linux.c b/drivers/net/ethernet/nvidia/nvethernet/ether_linux.c index 92b53d23..4f6b81e9 100644 --- a/drivers/net/ethernet/nvidia/nvethernet/ether_linux.c +++ b/drivers/net/ethernet/nvidia/nvethernet/ether_linux.c @@ -5774,6 +5774,13 @@ static int ether_parse_dt(struct ether_priv_data *pdata) } } + /* Read MAC instance id */ + ret = of_property_read_u32(np, "nvidia,instance_id", &osi_core->instance_id); + if (ret != 0) { + dev_info(dev, "DT instance_id missing\n"); + return -EINVAL; + } + if (osi_dma->num_dma_chans != osi_core->num_mtl_queues) { dev_err(dev, "mismatch in numbers of DMA channel and MTL Q\n"); return -EINVAL; diff --git a/drivers/net/ethernet/nvidia/nvethernet/macsec.c b/drivers/net/ethernet/nvidia/nvethernet/macsec.c index ece870d2..3140716a 100644 --- a/drivers/net/ethernet/nvidia/nvethernet/macsec.c +++ b/drivers/net/ethernet/nvidia/nvethernet/macsec.c @@ -1,5 +1,5 @@ // SPDX-License-Identifier: GPL-2.0-only -/* Copyright (c) 2019-2023, NVIDIA CORPORATION. All rights reserved */ +/* Copyright (c) 2019-2024, NVIDIA CORPORATION. All rights reserved */ #ifdef MACSEC_SUPPORT #include "ether_linux.h" diff --git a/drivers/net/ethernet/nvidia/nvethernet/sysfs.c b/drivers/net/ethernet/nvidia/nvethernet/sysfs.c index e48e2410..7560d54b 100644 --- a/drivers/net/ethernet/nvidia/nvethernet/sysfs.c +++ b/drivers/net/ethernet/nvidia/nvethernet/sysfs.c @@ -1,5 +1,5 @@ // SPDX-License-Identifier: GPL-2.0-only -/* Copyright (c) 2019-2023, NVIDIA CORPORATION & AFFILIATES. All rights reserved */ +/* Copyright (c) 2019-2024, NVIDIA CORPORATION. All rights reserved */ #include "ether_linux.h" #include "macsec.h" @@ -2735,6 +2735,33 @@ static struct attribute *ether_sysfs_attrs[] = { NULL }; +/** + * @brief Attributes for nvethernet sysfs without MACSEC + */ +static struct attribute *ether_sysfs_attrs_without_macsec[] = { +#ifndef OSI_STRIPPED_LIB +#ifdef OSI_DEBUG + &dev_attr_desc_dump_enable.attr, +#endif /* OSI_DEBUG */ + &dev_attr_mac_loopback.attr, + &dev_attr_ptp_mode.attr, + &dev_attr_ptp_sync.attr, + &dev_attr_frp.attr, + &dev_attr_uphy_gbe_mode.attr, + &dev_attr_phy_iface_mode.attr, +#ifdef ETHER_NVGRO + &dev_attr_nvgro_pkt_age_msec.attr, + &dev_attr_nvgro_timer_interval.attr, + &dev_attr_nvgro_stats.attr, + &dev_attr_nvgro_dump.attr, +#endif +#endif /* OSI_STRIPPED_LIB */ +#ifdef HSI_SUPPORT + &dev_attr_hsi_enable.attr, +#endif + NULL +}; + /** * @brief Ethernet sysfs attribute group */ @@ -2743,6 +2770,14 @@ static struct attribute_group ether_attribute_group = { .attrs = ether_sysfs_attrs, }; +/** + * @brief Ethernet sysfs attribute group without macsec + */ +static struct attribute_group ether_attribute_group_wo_macsec = { + .name = "nvethernet", + .attrs = ether_sysfs_attrs_without_macsec, +}; + #ifndef OSI_STRIPPED_LIB #ifdef CONFIG_DEBUG_FS static char *timestamp_system_source(unsigned int source) @@ -3331,7 +3366,12 @@ int ether_sysfs_register(struct ether_priv_data *pdata) #endif /* OSI_STRIPPED_LIB */ /* Create nvethernet sysfs group under /sys/devices// */ - return sysfs_create_group(&dev->kobj, ðer_attribute_group); + if (pdata->macsec_pdata != NULL) { + ret = sysfs_create_group(&dev->kobj, ðer_attribute_group); + } else { + ret = sysfs_create_group(&dev->kobj, ðer_attribute_group_wo_macsec); + } + return ret; } void ether_sysfs_unregister(struct ether_priv_data *pdata) @@ -3343,5 +3383,9 @@ void ether_sysfs_unregister(struct ether_priv_data *pdata) #endif #endif /* OSI_STRIPPED_LIB */ /* Remove nvethernet sysfs group under /sys/devices// */ - sysfs_remove_group(&dev->kobj, ðer_attribute_group); + if (pdata->macsec_pdata != NULL) { + sysfs_remove_group(&dev->kobj, ðer_attribute_group); + } else { + sysfs_remove_group(&dev->kobj, ðer_attribute_group_wo_macsec); + } }