From nobody Sat Nov 30 03:46:14 2024 Received: from esa.microchip.iphmx.com (esa.microchip.iphmx.com [68.232.153.233]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 84FA91AC454; Wed, 11 Sep 2024 16:15:24 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=68.232.153.233 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1726071326; cv=none; b=dv+Az93aePueoV+hoIdJ/zpKLKpwh2EzKyl+kV8T02+4250k8M9vPncqPJhSAI/YNl33yRxOzNVJSxRYB/eD8rRPTrmHaBcGEKdqOf9PJuScGGaoa0XypinbyY7r1wncJIs2wQ//6BTvW7Lh4bQ16Mj0VmD42WilM2rbKKZBUSg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1726071326; c=relaxed/simple; bh=sIvyob1olP4zFEKTbhbc5N7sm72ACzP8pnPALstswF4=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=dmB1Zi4jP0Q+l4WM4TiQAw+e4pFh5KmSXhUMYAQoIQp6eif8RuwxGFuTxgud1VkNblMWHPffEh4f8HMYY1lcddsgOoe+cz/pVT1wJCUhC4GyYwcg28sZXexPNmEsOq470gh0XSuY3nXAwVLUxt1a5U+pE00HljcwvGwS3Q5IpgQ= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=microchip.com; spf=pass smtp.mailfrom=microchip.com; dkim=pass (2048-bit key) header.d=microchip.com header.i=@microchip.com header.b=SHSXdk7i; arc=none smtp.client-ip=68.232.153.233 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=microchip.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=microchip.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=microchip.com header.i=@microchip.com header.b="SHSXdk7i" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=microchip.com; i=@microchip.com; q=dns/txt; s=mchp; t=1726071325; x=1757607325; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=sIvyob1olP4zFEKTbhbc5N7sm72ACzP8pnPALstswF4=; b=SHSXdk7irajcF5s41M3Zs+Kt5sKCsOq6uiCwSgCvbcBV3QlZrF80kNXY /KvNhm5MOSEvJiY4rhJjQSOwiTaKgS+sZoX2kMdnf0QK66EJfCuPAPndk Tnh7Dd+ZZLZb6NJdMhK+TsDYEpQ68YesZDh4ldQCNz5hlXL+6iTSmUMmp A1i+deAhMXZQcDQMbD4E4mwzzhIqiWmjYS7O4QUC0wWz5v0HSSVkk+sCK 6YyvJh00Q0Q5YLjvsdp6fElxhOREse1cSYlxUE656zfFtpiCdQpvLbPUV QHWHKt7bPWx4fxqz4XVezt7KnIK/kjwqyuAE6SFiRONz5Sm8BZwCNWN2K g==; X-CSE-ConnectionGUID: 2nHLmdpiRE6ZQX98BGaY/g== X-CSE-MsgGUID: Q0BdccpkScySrlrlOaP5kQ== X-IronPort-AV: E=Sophos;i="6.10,220,1719903600"; d="scan'208";a="262640538" X-Amp-Result: SKIPPED(no attachment in message) Received: from unknown (HELO email.microchip.com) ([170.129.1.10]) by esa5.microchip.iphmx.com with ESMTP/TLS/ECDHE-RSA-AES128-GCM-SHA256; 11 Sep 2024 09:15:22 -0700 Received: from chn-vm-ex02.mchp-main.com (10.10.87.72) by chn-vm-ex02.mchp-main.com (10.10.87.72) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.35; Wed, 11 Sep 2024 09:14:55 -0700 Received: from HYD-DK-UNGSW21.microchip.com (10.10.85.11) by chn-vm-ex02.mchp-main.com (10.10.85.144) with Microsoft SMTP Server id 15.1.2507.35 via Frontend Transport; Wed, 11 Sep 2024 09:14:50 -0700 From: Raju Lakkaraju To: CC: , , , , , , , , , , , , , Subject: [PATCH net-next V2 1/5] net: lan743x: Add SFP support check flag Date: Wed, 11 Sep 2024 21:40:50 +0530 Message-ID: <20240911161054.4494-2-Raju.Lakkaraju@microchip.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240911161054.4494-1-Raju.Lakkaraju@microchip.com> References: <20240911161054.4494-1-Raju.Lakkaraju@microchip.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Support for SFP in the PCI11x1x devices is indicated by the "is_sfp_support= _en" flag in the STRAP register. This register is loaded at power up from the PCI11x1x EEPROM contents (which specify the board configuration). Signed-off-by: Raju Lakkaraju --- Change List: =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D V1 -> V2: - Change variable name from "chip_rev" to "fpga_rev"=20 V0 -> V1: - No changes drivers/net/ethernet/microchip/lan743x_main.c | 34 +++++++++++++++---- drivers/net/ethernet/microchip/lan743x_main.h | 3 ++ 2 files changed, 30 insertions(+), 7 deletions(-) diff --git a/drivers/net/ethernet/microchip/lan743x_main.c b/drivers/net/et= hernet/microchip/lan743x_main.c index 4dc5adcda6a3..20a42a2c7b0e 100644 --- a/drivers/net/ethernet/microchip/lan743x_main.c +++ b/drivers/net/ethernet/microchip/lan743x_main.c @@ -28,9 +28,9 @@ =20 #define RFE_RD_FIFO_TH_3_DWORDS 0x3 =20 -static void pci11x1x_strap_get_status(struct lan743x_adapter *adapter) +static int pci11x1x_strap_get_status(struct lan743x_adapter *adapter) { - u32 chip_rev; + u32 fpga_rev; u32 cfg_load; u32 hw_cfg; u32 strap; @@ -41,7 +41,7 @@ static void pci11x1x_strap_get_status(struct lan743x_adap= ter *adapter) if (ret < 0) { netif_err(adapter, drv, adapter->netdev, "Sys Lock acquire failed ret:%d\n", ret); - return; + return ret; } =20 cfg_load =3D lan743x_csr_read(adapter, ETH_SYS_CONFIG_LOAD_STARTED_REG); @@ -55,10 +55,15 @@ static void pci11x1x_strap_get_status(struct lan743x_ad= apter *adapter) adapter->is_sgmii_en =3D true; else adapter->is_sgmii_en =3D false; + + if ((strap & STRAP_SFP_USE_EN_) && (strap & STRAP_SFP_EN_)) + adapter->is_sfp_support_en =3D true; + else + adapter->is_sfp_support_en =3D false; } else { - chip_rev =3D lan743x_csr_read(adapter, FPGA_REV); - if (chip_rev) { - if (chip_rev & FPGA_SGMII_OP) + fpga_rev =3D lan743x_csr_read(adapter, FPGA_REV); + if (fpga_rev) { + if (fpga_rev & FPGA_SGMII_OP) adapter->is_sgmii_en =3D true; else adapter->is_sgmii_en =3D false; @@ -66,8 +71,21 @@ static void pci11x1x_strap_get_status(struct lan743x_ada= pter *adapter) adapter->is_sgmii_en =3D false; } } + + if (adapter->is_pci11x1x && !adapter->is_sgmii_en && + adapter->is_sfp_support_en) { + netif_err(adapter, drv, adapter->netdev, + "Invalid eeprom cfg: sfp enabled with sgmii disabled"); + return -EINVAL; + } + netif_dbg(adapter, drv, adapter->netdev, "SGMII I/F %sable\n", adapter->is_sgmii_en ? "En" : "Dis"); + netif_dbg(adapter, drv, adapter->netdev, + "SFP support %sable\n", adapter->is_sfp_support_en ? + "En" : "Dis"); + + return 0; } =20 static bool is_pci11x1x_chip(struct lan743x_adapter *adapter) @@ -3470,7 +3488,9 @@ static int lan743x_hardware_init(struct lan743x_adapt= er *adapter, adapter->max_tx_channels =3D PCI11X1X_MAX_TX_CHANNELS; adapter->used_tx_channels =3D PCI11X1X_USED_TX_CHANNELS; adapter->max_vector_count =3D PCI11X1X_MAX_VECTOR_COUNT; - pci11x1x_strap_get_status(adapter); + ret =3D pci11x1x_strap_get_status(adapter); + if (ret < 0) + return ret; spin_lock_init(&adapter->eth_syslock_spinlock); mutex_init(&adapter->sgmii_rw_lock); pci11x1x_set_rfe_rd_fifo_threshold(adapter); diff --git a/drivers/net/ethernet/microchip/lan743x_main.h b/drivers/net/et= hernet/microchip/lan743x_main.h index 8ef897c114d3..f7e96496600b 100644 --- a/drivers/net/ethernet/microchip/lan743x_main.h +++ b/drivers/net/ethernet/microchip/lan743x_main.h @@ -36,6 +36,8 @@ =20 #define STRAP_READ (0x0C) #define STRAP_READ_USE_SGMII_EN_ BIT(22) +#define STRAP_SFP_USE_EN_ BIT(31) +#define STRAP_SFP_EN_ BIT(15) #define STRAP_READ_SGMII_EN_ BIT(6) #define STRAP_READ_SGMII_REFCLK_ BIT(5) #define STRAP_READ_SGMII_2_5G_ BIT(4) @@ -1079,6 +1081,7 @@ struct lan743x_adapter { u8 max_tx_channels; u8 used_tx_channels; u8 max_vector_count; + bool is_sfp_support_en; =20 #define LAN743X_ADAPTER_FLAG_OTP BIT(0) u32 flags; --=20 2.34.1 From nobody Sat Nov 30 03:46:14 2024 Received: from esa.microchip.iphmx.com (esa.microchip.iphmx.com [68.232.154.123]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id E2F8F1ABEBA; Wed, 11 Sep 2024 16:15:12 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=68.232.154.123 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1726071315; cv=none; b=EHNTTRuhmq9f/v9hUg2cKD30F80abXylb+dtE6uNY1Kz3Thxh8EvHVlu2Frllqtbsk9eMB5dBzFM8myk/xKB1QCONlPzHdQDS8hKyH32mXGJBjB3/8tUjmgZ/etMZHZLn9QYwvgVKBSILtouRWx7c3o365OioiUVTI6fg7qwRyY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1726071315; c=relaxed/simple; bh=KTKOhBVaRC9Y4aEDAHvhxydRKStYcMQJHFGLeIh2EUE=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=YtnQ6O2AIBCJzS/TSqvnO/VkhrHIJKiYTmlLTTW9I+kcddkMHmLQWRF3KoFZK/sbfNbHfQLlQUEHzFQYwabNwZgGEZDFWbx6Waou9Z55xaPZBc75xiMTJzRBkyvo6Y46Qpth28SIVNFbfP24Okp+uCEndlTY/BsqHbBnEUtCXVk= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=microchip.com; spf=pass smtp.mailfrom=microchip.com; dkim=pass (2048-bit key) header.d=microchip.com header.i=@microchip.com header.b=hniAZTJs; arc=none smtp.client-ip=68.232.154.123 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=microchip.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=microchip.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=microchip.com header.i=@microchip.com header.b="hniAZTJs" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=microchip.com; i=@microchip.com; q=dns/txt; s=mchp; t=1726071313; x=1757607313; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=KTKOhBVaRC9Y4aEDAHvhxydRKStYcMQJHFGLeIh2EUE=; b=hniAZTJsrnaFXcpW6SLUxxftHkASmkqrkCvFEzxaMZvmLos394f9+ug3 6F+l0RYZZBsBaEWcJ+0/gclYjNLFMtaqUS7Xbo+hWFOKsi/USuCCCDK9P D2BnPwG8wsHQJGudpiLVj3cJhFOarXPXFfhzqQBbIX/ZugAPYvuFCwlYk rlbP/bn0dBqMVecvn7wBaBT2vHRfrbJYB/hjf6Pg4j5GH0HoS4mIoXahq RKdZQLS9WMn6BiCP2+fg08Drl5Xw1uUhs6cNjjwDx30FGTnQW0eR746oW Fljk7mciC0RfQ9uevhpJGw29xz3WFY1wz5NLC1EV21PG9JXjRSZL4PGDQ A==; X-CSE-ConnectionGUID: I+zUQG3KSiiiwGtN22Ixjw== X-CSE-MsgGUID: RrGUA+tSQM6vKfXV7qU2WA== X-IronPort-AV: E=Sophos;i="6.10,220,1719903600"; d="scan'208";a="32280146" X-Amp-Result: SKIPPED(no attachment in message) Received: from unknown (HELO email.microchip.com) ([170.129.1.10]) by esa2.microchip.iphmx.com with ESMTP/TLS/ECDHE-RSA-AES128-GCM-SHA256; 11 Sep 2024 09:15:11 -0700 Received: from chn-vm-ex02.mchp-main.com (10.10.85.144) by chn-vm-ex03.mchp-main.com (10.10.85.151) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.35; Wed, 11 Sep 2024 09:15:00 -0700 Received: from HYD-DK-UNGSW21.microchip.com (10.10.85.11) by chn-vm-ex02.mchp-main.com (10.10.85.144) with Microsoft SMTP Server id 15.1.2507.35 via Frontend Transport; Wed, 11 Sep 2024 09:14:55 -0700 From: Raju Lakkaraju To: CC: , , , , , , , , , , , , , Subject: [PATCH net-next V2 2/5] net: lan743x: Add support to software-nodes for sfp Date: Wed, 11 Sep 2024 21:40:51 +0530 Message-ID: <20240911161054.4494-3-Raju.Lakkaraju@microchip.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240911161054.4494-1-Raju.Lakkaraju@microchip.com> References: <20240911161054.4494-1-Raju.Lakkaraju@microchip.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Register software nodes and define the device properties. software-node contains following properties. - gpio pin details - i2c bus information - sfp signals - phylink mode Signed-off-by: Raju Lakkaraju --- Change List: =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D V1 -> V2: - SFP GPIO definitions and other macros move from lan743x_main.c to lan743x_main.h file - Change from "PCI11X1X_" to "PCI11X1X_EVB_PCI11010_" strings for GPIO ma= cros V0 -> V1: = =20 - No changes drivers/net/ethernet/microchip/Kconfig | 2 + drivers/net/ethernet/microchip/lan743x_main.c | 198 +++++++++++++++++- drivers/net/ethernet/microchip/lan743x_main.h | 82 ++++++++ 3 files changed, 278 insertions(+), 4 deletions(-) diff --git a/drivers/net/ethernet/microchip/Kconfig b/drivers/net/ethernet/= microchip/Kconfig index 2e3eb37a45cd..9c08a4af257a 100644 --- a/drivers/net/ethernet/microchip/Kconfig +++ b/drivers/net/ethernet/microchip/Kconfig @@ -50,6 +50,8 @@ config LAN743X select CRC16 select CRC32 select PHYLINK + select I2C_PCI1XXXX + select GP_PCI1XXXX help Support for the Microchip LAN743x and PCI11x1x families of PCI Express Ethernet devices diff --git a/drivers/net/ethernet/microchip/lan743x_main.c b/drivers/net/et= hernet/microchip/lan743x_main.c index 20a42a2c7b0e..dc571020ae1b 100644 --- a/drivers/net/ethernet/microchip/lan743x_main.c +++ b/drivers/net/ethernet/microchip/lan743x_main.c @@ -100,8 +100,98 @@ static bool is_pci11x1x_chip(struct lan743x_adapter *a= dapter) return false; } =20 +static void *pci1xxxx_perif_drvdata_get(struct lan743x_adapter *adapter, + u16 perif_id) +{ + struct pci_dev *pdev =3D adapter->pdev; + struct pci_bus *perif_bus; + struct pci_dev *perif_dev; + struct pci_dev *br_dev; + struct pci_bus *br_bus; + struct pci_dev *dev; + + /* PCI11x1x devices' PCIe topology consists of a top level pcie + * switch with up to four downstream ports, some of which have + * integrated endpoints connected to them. One of the downstream ports + * has an embedded single function pcie ethernet controller which is + * handled by this driver. Another downstream port has an + * embedded multifunction pcie endpoint, with four pcie functions + * (the "peripheral controllers": I2C controller, GPIO controller, + * UART controllers, SPIcontrollers) + * The code below navigates the PCI11x1x topology + * to find (by matching its PCI device ID) the peripheral controller + * that should be paired to the embedded ethernet controller. + */ + br_dev =3D pci_upstream_bridge(pdev); + if (!br_dev) { + netif_err(adapter, drv, adapter->netdev, + "upstream bridge not found\n"); + return br_dev; + } + + br_bus =3D br_dev->bus; + list_for_each_entry(dev, &br_bus->devices, bus_list) { + if (dev->vendor =3D=3D PCI1XXXX_VENDOR_ID && + (dev->device & ~PCI1XXXX_DEV_MASK) =3D=3D + PCI1XXXX_BR_PERIF_ID) { + perif_bus =3D dev->subordinate; + list_for_each_entry(perif_dev, &perif_bus->devices, + bus_list) { + if (perif_dev->vendor =3D=3D PCI1XXXX_VENDOR_ID && + (perif_dev->device & ~PCI1XXXX_DEV_MASK) =3D=3D + perif_id) + return pci_get_drvdata(perif_dev); + } + } + } + + netif_err(adapter, drv, adapter->netdev, + "pci1xxxx peripheral (0x%X) device not found\n", perif_id); + + return NULL; +} + +static int pci1xxxx_i2c_adapter_get(struct lan743x_adapter *adapter) +{ + struct pci1xxxx_i2c *i2c_drvdata; + + i2c_drvdata =3D pci1xxxx_perif_drvdata_get(adapter, PCI1XXXX_PERIF_I2C_ID= ); + if (!i2c_drvdata) + return -EPROBE_DEFER; + + adapter->i2c_adap =3D &i2c_drvdata->adap; + snprintf(adapter->nodes->i2c_name, sizeof(adapter->nodes->i2c_name), + adapter->i2c_adap->name); + netif_dbg(adapter, drv, adapter->netdev, "Found %s\n", + adapter->i2c_adap->name); + + return 0; +} + +static int pci1xxxx_gpio_dev_get(struct lan743x_adapter *adapter) +{ + struct aux_bus_device *aux_bus; + struct device *gpio_dev; + + aux_bus =3D pci1xxxx_perif_drvdata_get(adapter, PCI1XXXX_PERIF_GPIO_ID); + if (!aux_bus) + return -EPROBE_DEFER; + + gpio_dev =3D &aux_bus->aux_device_wrapper[1]->aux_dev.dev; + snprintf(adapter->nodes->gpio_name, sizeof(adapter->nodes->gpio_name), + dev_name(gpio_dev)); + netif_dbg(adapter, drv, adapter->netdev, "Found %s\n", + adapter->nodes->gpio_name); + return 0; +} + static void lan743x_pci_cleanup(struct lan743x_adapter *adapter) { + if (adapter->nodes) { + software_node_unregister_node_group(adapter->nodes->group); + kfree(adapter->nodes); + } + pci_release_selected_regions(adapter->pdev, pci_select_bars(adapter->pdev, IORESOURCE_MEM)); @@ -2888,6 +2978,90 @@ static int lan743x_rx_open(struct lan743x_rx *rx) return ret; } =20 +static int lan743x_swnodes_register(struct lan743x_adapter *adapter) +{ + struct pci_dev *pdev =3D adapter->pdev; + struct lan743x_sw_nodes *nodes; + struct software_node *swnodes; + int ret; + u32 id; + + nodes =3D kzalloc(sizeof(*nodes), GFP_KERNEL); + if (!nodes) + return -ENOMEM; + + adapter->nodes =3D nodes; + + ret =3D pci1xxxx_gpio_dev_get(adapter); + if (ret < 0) + return ret; + + ret =3D pci1xxxx_i2c_adapter_get(adapter); + if (ret < 0) + return ret; + + id =3D (pdev->bus->number << 8) | pdev->devfn; + snprintf(nodes->sfp_name, sizeof(nodes->sfp_name), + "sfp-%d", id); + snprintf(nodes->phylink_name, sizeof(nodes->phylink_name), + "mchp-pci1xxxx-phylink-%d", id); + + swnodes =3D nodes->swnodes; + + nodes->gpio_props[0] =3D PROPERTY_ENTRY_STRING("pinctrl-names", + "default"); + swnodes[SWNODE_GPIO] =3D NODE_PROP(nodes->gpio_name, nodes->gpio_props); + + nodes->tx_fault_ref[0] =3D SOFTWARE_NODE_REFERENCE(&swnodes[SWNODE_GPIO], + PCI11X1X_EVB_PCI11010_TX_FAULT_GPIO, + GPIO_ACTIVE_HIGH); + nodes->tx_disable_ref[0] =3D SOFTWARE_NODE_REFERENCE(&swnodes[SWNODE_GPIO= ], + PCI11X1X_EVB_PCI11010_TX_DIS_GPIO, + GPIO_ACTIVE_HIGH); + nodes->mod_def0_ref[0] =3D SOFTWARE_NODE_REFERENCE(&swnodes[SWNODE_GPIO], + PCI11X1X_EVB_PCI11010_MOD_DEF0_GPIO, + GPIO_ACTIVE_LOW); + nodes->los_ref[0] =3D SOFTWARE_NODE_REFERENCE(&swnodes[SWNODE_GPIO], + PCI11X1X_EVB_PCI11010_LOS_GPIO, + GPIO_ACTIVE_HIGH); + nodes->rate_sel0_ref[0] =3D SOFTWARE_NODE_REFERENCE(&swnodes[SWNODE_GPIO], + PCI11X1X_EVB_PCI11010_RATE_SEL0_GPIO, + GPIO_ACTIVE_HIGH); + + nodes->i2c_props[0] =3D PROPERTY_ENTRY_STRING("pinctrl-names", "default"); + swnodes[SWNODE_I2C] =3D NODE_PROP(nodes->i2c_name, nodes->i2c_props); + nodes->i2c_ref[0] =3D SOFTWARE_NODE_REFERENCE(&swnodes[SWNODE_I2C]); + + nodes->sfp_props[0] =3D PROPERTY_ENTRY_STRING("compatible", "sff,sfp"); + nodes->sfp_props[1] =3D PROPERTY_ENTRY_REF_ARRAY("i2c-bus", + nodes->i2c_ref); + nodes->sfp_props[2] =3D PROPERTY_ENTRY_REF_ARRAY("tx-fault-gpios", + nodes->tx_fault_ref); + nodes->sfp_props[3] =3D PROPERTY_ENTRY_REF_ARRAY("tx-disable-gpios", + nodes->tx_disable_ref); + nodes->sfp_props[4] =3D PROPERTY_ENTRY_REF_ARRAY("mod-def0-gpios", + nodes->mod_def0_ref); + nodes->sfp_props[5] =3D PROPERTY_ENTRY_REF_ARRAY("los-gpios", + nodes->los_ref); + nodes->sfp_props[6] =3D PROPERTY_ENTRY_REF_ARRAY("rate-select0-gpios", + nodes->rate_sel0_ref); + swnodes[SWNODE_SFP] =3D NODE_PROP(nodes->sfp_name, nodes->sfp_props); + nodes->sfp_ref[0] =3D SOFTWARE_NODE_REFERENCE(&swnodes[SWNODE_SFP]); + nodes->phylink_props[0] =3D PROPERTY_ENTRY_STRING("managed", + "in-band-status"); + nodes->phylink_props[1] =3D PROPERTY_ENTRY_REF_ARRAY("sfp", + nodes->sfp_ref); + swnodes[SWNODE_PHYLINK] =3D NODE_PROP(nodes->phylink_name, + nodes->phylink_props); + + nodes->group[SWNODE_GPIO] =3D &swnodes[SWNODE_GPIO]; + nodes->group[SWNODE_I2C] =3D &swnodes[SWNODE_I2C]; + nodes->group[SWNODE_SFP] =3D &swnodes[SWNODE_SFP]; + nodes->group[SWNODE_PHYLINK] =3D &swnodes[SWNODE_PHYLINK]; + + return software_node_register_node_group(nodes->group); +} + static int lan743x_phylink_sgmii_config(struct lan743x_adapter *adapter) { u32 sgmii_ctl; @@ -3105,6 +3279,7 @@ static const struct phylink_mac_ops lan743x_phylink_m= ac_ops =3D { static int lan743x_phylink_create(struct lan743x_adapter *adapter) { struct net_device *netdev =3D adapter->netdev; + struct fwnode_handle *fwnode =3D NULL; struct phylink *pl; =20 adapter->phylink_config.dev =3D &netdev->dev; @@ -3138,7 +3313,13 @@ static int lan743x_phylink_create(struct lan743x_ada= pter *adapter) phy_interface_set_rgmii(adapter->phylink_config.supported_interfaces); } =20 - pl =3D phylink_create(&adapter->phylink_config, NULL, + if (adapter->nodes) { + fwnode =3D software_node_fwnode(adapter->nodes->group[SWNODE_PHYLINK]); + if (!fwnode) + return -ENODEV; + } + + pl =3D phylink_create(&adapter->phylink_config, fwnode, adapter->phy_interface, &lan743x_phylink_mac_ops); =20 if (IS_ERR(pl)) { @@ -3511,9 +3692,18 @@ static int lan743x_hardware_init(struct lan743x_adap= ter *adapter, if (ret) return ret; =20 - ret =3D lan743x_phy_init(adapter); - if (ret) - return ret; + if (adapter->is_sfp_support_en && !adapter->nodes) { + ret =3D lan743x_swnodes_register(adapter); + if (ret) { + netdev_err(adapter->netdev, + "failed to register software nodes\n"); + return ret; + } + } else { + ret =3D lan743x_phy_init(adapter); + if (ret) + return ret; + } =20 ret =3D lan743x_ptp_init(adapter); if (ret) diff --git a/drivers/net/ethernet/microchip/lan743x_main.h b/drivers/net/et= hernet/microchip/lan743x_main.h index f7e96496600b..bf0d0f285e39 100644 --- a/drivers/net/ethernet/microchip/lan743x_main.h +++ b/drivers/net/ethernet/microchip/lan743x_main.h @@ -6,6 +6,10 @@ =20 #include #include +#include +#include +#include +#include #include "lan743x_ptp.h" =20 #define DRIVER_AUTHOR "Bryan Whitehead " @@ -1047,6 +1051,40 @@ enum lan743x_sgmii_lsd { =20 #define MAC_SUPPORTED_WAKES (WAKE_BCAST | WAKE_UCAST | WAKE_MCAST | \ WAKE_MAGIC | WAKE_ARP) + +enum lan743x_swnodes { + SWNODE_GPIO =3D 0, + SWNODE_I2C, + SWNODE_SFP, + SWNODE_PHYLINK, + SWNODE_MAX +}; + +#define I2C_DRV_NAME 48 +#define GPIO_DRV_NAME 32 +#define SFP_NODE_NAME 32 +#define PHYLINK_NODE_NAME 32 + +struct lan743x_sw_nodes { + char gpio_name[GPIO_DRV_NAME]; + char i2c_name[I2C_DRV_NAME]; + char sfp_name[SFP_NODE_NAME]; + char phylink_name[PHYLINK_NODE_NAME]; + struct property_entry gpio_props[1]; + struct property_entry i2c_props[1]; + struct property_entry sfp_props[8]; + struct property_entry phylink_props[2]; + struct software_node_ref_args i2c_ref[1]; + struct software_node_ref_args tx_fault_ref[1]; + struct software_node_ref_args tx_disable_ref[1]; + struct software_node_ref_args mod_def0_ref[1]; + struct software_node_ref_args los_ref[1]; + struct software_node_ref_args rate_sel0_ref[1]; + struct software_node_ref_args sfp_ref[1]; + struct software_node swnodes[SWNODE_MAX]; + const struct software_node *group[SWNODE_MAX + 1]; +}; + struct lan743x_adapter { struct net_device *netdev; struct mii_bus *mdiobus; @@ -1089,6 +1127,8 @@ struct lan743x_adapter { phy_interface_t phy_interface; struct phylink *phylink; struct phylink_config phylink_config; + struct lan743x_sw_nodes *nodes; + struct i2c_adapter *i2c_adap; }; =20 #define LAN743X_COMPONENT_FLAG_RX(channel) BIT(20 + (channel)) @@ -1202,6 +1242,48 @@ struct lan743x_rx_buffer_info { #define RX_PROCESS_RESULT_NOTHING_TO_DO (0) #define RX_PROCESS_RESULT_BUFFER_RECEIVED (1) =20 +#define PCI1XXXX_VENDOR_ID 0x1055 +#define PCI1XXXX_BR_PERIF_ID 0xA00C +#define PCI1XXXX_PERIF_I2C_ID 0xA003 +#define PCI1XXXX_PERIF_GPIO_ID 0xA005 +#define PCI1XXXX_DEV_MASK GENMASK(7, 4) + +#define PCI11X1X_EVB_PCI11010_TX_FAULT_GPIO 46 +#define PCI11X1X_EVB_PCI11010_TX_DIS_GPIO 47 +#define PCI11X1X_EVB_PCI11010_RATE_SEL0_GPIO 48 +#define PCI11X1X_EVB_PCI11010_LOS_GPIO 49 +#define PCI11X1X_EVB_PCI11010_MOD_DEF0_GPIO 51 + +#define NODE_PROP(_NAME, _PROP) \ + ((const struct software_node) { \ + .name =3D _NAME, \ + .properties =3D _PROP, \ + }) + +struct pci1xxxx_i2c { + struct completion i2c_xfer_done; + bool i2c_xfer_in_progress; + struct i2c_adapter adap; + void __iomem *i2c_base; + u32 freq; + u32 flags; +}; + +struct gp_aux_data_type { + int irq_num; + resource_size_t region_start; + resource_size_t region_length; +}; + +struct auxiliary_device_wrapper { + struct auxiliary_device aux_dev; + struct gp_aux_data_type gp_aux_data; +}; + +struct aux_bus_device { + struct auxiliary_device_wrapper *aux_device_wrapper[2]; +}; + u32 lan743x_csr_read(struct lan743x_adapter *adapter, int offset); void lan743x_csr_write(struct lan743x_adapter *adapter, int offset, u32 da= ta); int lan743x_hs_syslock_acquire(struct lan743x_adapter *adapter, u16 timeou= t); --=20 2.34.1 From nobody Sat Nov 30 03:46:14 2024 Received: from esa.microchip.iphmx.com (esa.microchip.iphmx.com [68.232.154.123]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 8DAB81AB6D7; Wed, 11 Sep 2024 16:15:15 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=68.232.154.123 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1726071317; cv=none; b=uk5hCTcYWeo5dM/ocjaK3jTIDdvPXdG4U9WGenj21YOWPDOWOaETarD2Q4cFPK+UlYrCXLqKMQgi+foKTOxSjCjbyGMzjQvVs3XYJMI2JGn8KdTe35tXrqBRnaPhWp/T7V9SsY4eYOGX6NPjGMg4FL/Zj72qnyAhAoM4uGP9wIE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1726071317; c=relaxed/simple; bh=1bQ6ImyF/jGacshZUQQdTdRKhwSlL3Wx8mjhu+pdUFg=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=N6UdNPlHLZ9bdOl0GRnkrSjhcpaim3I0qqWvlRJ0b0oja3+1ORqZb99LkjNANTrJlvc1uHIRBjpxMU9X1zn3J5YPOxl5n0eKWdow7rS3TRA9W6pTKGH9xNjVIshBlWJhSROo00n8EtV+B2vHhaKeowmKvgYfRul7dszmJqOnKpU= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=microchip.com; spf=pass smtp.mailfrom=microchip.com; dkim=pass (2048-bit key) header.d=microchip.com header.i=@microchip.com header.b=SusyNQmg; arc=none smtp.client-ip=68.232.154.123 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=microchip.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=microchip.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=microchip.com header.i=@microchip.com header.b="SusyNQmg" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=microchip.com; i=@microchip.com; q=dns/txt; s=mchp; t=1726071315; x=1757607315; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=1bQ6ImyF/jGacshZUQQdTdRKhwSlL3Wx8mjhu+pdUFg=; b=SusyNQmgkYTWZIQuRHLa5uUVwS71Pb/lD36cXbz0+tYygj2+oIdtGLFR SXd8VX/JVkt2/p+dBBnZ3IukIFZVjhevXkaVJnIbx2CAyiUzI1nKOXPPP SwiWvnux9bxwQKZQki0KbEKQBkJC3WlX1GYNtpbXjbFd0RbCmeCs8+Vv4 STBu4TUBpsdrAHG/qXYAxuyyAdQ+w0p1/abY2PBe/oZG8TsmK9eWk1Xc/ O/GHpMVtVsHstVtNBuQ0iGEMhmMM7N0qNgYu4e4mngr7VH74ZWFSjySwT XqoTFgMU2o1gN9qJN+Ok95M7WEGqeqd2ROtdPlfJftFVKqXWmVSbpwsTS Q==; X-CSE-ConnectionGUID: I+zUQG3KSiiiwGtN22Ixjw== X-CSE-MsgGUID: 8lKrkbRIRvCbJptRylhr1Q== X-IronPort-AV: E=Sophos;i="6.10,220,1719903600"; d="scan'208";a="32280150" X-Amp-Result: SKIPPED(no attachment in message) Received: from unknown (HELO email.microchip.com) ([170.129.1.10]) by esa2.microchip.iphmx.com with ESMTP/TLS/ECDHE-RSA-AES128-GCM-SHA256; 11 Sep 2024 09:15:12 -0700 Received: from chn-vm-ex02.mchp-main.com (10.10.85.144) by chn-vm-ex03.mchp-main.com (10.10.85.151) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.35; Wed, 11 Sep 2024 09:15:05 -0700 Received: from HYD-DK-UNGSW21.microchip.com (10.10.85.11) by chn-vm-ex02.mchp-main.com (10.10.85.144) with Microsoft SMTP Server id 15.1.2507.35 via Frontend Transport; Wed, 11 Sep 2024 09:15:00 -0700 From: Raju Lakkaraju To: CC: , , , , , , , , , , , , , Subject: [PATCH net-next V2 3/5] net: lan743x: Register the platform device for sfp pluggable module Date: Wed, 11 Sep 2024 21:40:52 +0530 Message-ID: <20240911161054.4494-4-Raju.Lakkaraju@microchip.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240911161054.4494-1-Raju.Lakkaraju@microchip.com> References: <20240911161054.4494-1-Raju.Lakkaraju@microchip.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Add support for sfp pluggable module as platform device handle the gpio input and output signals and i2c bus access the sfp eeprom data. Signed-off-by: Raju Lakkaraju --- Change List: =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D V1 -> V2: - Add platform_device_unregister( ) when sfp register fail=20 V0 -> V1: - No change drivers/net/ethernet/microchip/Kconfig | 1 + drivers/net/ethernet/microchip/lan743x_main.c | 43 +++++++++++++++++++ drivers/net/ethernet/microchip/lan743x_main.h | 1 + 3 files changed, 45 insertions(+) diff --git a/drivers/net/ethernet/microchip/Kconfig b/drivers/net/ethernet/= microchip/Kconfig index 9c08a4af257a..3dacf39b49b4 100644 --- a/drivers/net/ethernet/microchip/Kconfig +++ b/drivers/net/ethernet/microchip/Kconfig @@ -52,6 +52,7 @@ config LAN743X select PHYLINK select I2C_PCI1XXXX select GP_PCI1XXXX + select SFP help Support for the Microchip LAN743x and PCI11x1x families of PCI Express Ethernet devices diff --git a/drivers/net/ethernet/microchip/lan743x_main.c b/drivers/net/et= hernet/microchip/lan743x_main.c index dc571020ae1b..c1061e2972f9 100644 --- a/drivers/net/ethernet/microchip/lan743x_main.c +++ b/drivers/net/ethernet/microchip/lan743x_main.c @@ -16,6 +16,7 @@ #include #include #include +#include #include "lan743x_main.h" #include "lan743x_ethtool.h" =20 @@ -187,6 +188,11 @@ static int pci1xxxx_gpio_dev_get(struct lan743x_adapte= r *adapter) =20 static void lan743x_pci_cleanup(struct lan743x_adapter *adapter) { + if (adapter->sfp_dev) { + platform_device_unregister(adapter->sfp_dev); + adapter->sfp_dev =3D NULL; + } + if (adapter->nodes) { software_node_unregister_node_group(adapter->nodes->group); kfree(adapter->nodes); @@ -3062,6 +3068,31 @@ static int lan743x_swnodes_register(struct lan743x_a= dapter *adapter) return software_node_register_node_group(nodes->group); } =20 +static int lan743x_sfp_register(struct lan743x_adapter *adapter) +{ + struct pci_dev *pdev =3D adapter->pdev; + struct platform_device_info sfp_info; + struct platform_device *sfp_dev; + + memset(&sfp_info, 0, sizeof(sfp_info)); + sfp_info.parent =3D &adapter->pdev->dev; + sfp_info.fwnode =3D software_node_fwnode(adapter->nodes->group[SWNODE_SFP= ]); + sfp_info.name =3D "sfp"; + sfp_info.id =3D (pdev->bus->number << 8) | pdev->devfn; + sfp_dev =3D platform_device_register_full(&sfp_info); + if (IS_ERR(sfp_dev)) { + netif_err(adapter, drv, adapter->netdev, + "Failed to register SFP device\n"); + return PTR_ERR(sfp_dev); + } + + adapter->sfp_dev =3D sfp_dev; + netif_dbg(adapter, drv, adapter->netdev, + "SFP platform device registered"); + + return 0; +} + static int lan743x_phylink_sgmii_config(struct lan743x_adapter *adapter) { u32 sgmii_ctl; @@ -3851,6 +3882,18 @@ static int lan743x_pcidev_probe(struct pci_dev *pdev, if (ret) goto cleanup_pci; =20 + if (adapter->is_sfp_support_en) { + adapter->i2c_adap->dev.fwnode =3D + software_node_fwnode(adapter->nodes->group[SWNODE_I2C]); + + ret =3D lan743x_sfp_register(adapter); + if (ret < 0) { + netif_err(adapter, probe, netdev, + "Failed to register sfp (%d)\n", ret); + goto cleanup_pci; + } + } + ret =3D lan743x_mdiobus_init(adapter); if (ret) goto cleanup_hardware; diff --git a/drivers/net/ethernet/microchip/lan743x_main.h b/drivers/net/et= hernet/microchip/lan743x_main.h index bf0d0f285e39..c303a69c3bea 100644 --- a/drivers/net/ethernet/microchip/lan743x_main.h +++ b/drivers/net/ethernet/microchip/lan743x_main.h @@ -1129,6 +1129,7 @@ struct lan743x_adapter { struct phylink_config phylink_config; struct lan743x_sw_nodes *nodes; struct i2c_adapter *i2c_adap; + struct platform_device *sfp_dev; }; =20 #define LAN743X_COMPONENT_FLAG_RX(channel) BIT(20 + (channel)) --=20 2.34.1 From nobody Sat Nov 30 03:46:14 2024 Received: from esa.microchip.iphmx.com (esa.microchip.iphmx.com [68.232.154.123]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 1A1901AC885; Wed, 11 Sep 2024 16:15:15 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=68.232.154.123 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1726071317; cv=none; b=Cg3NNRJq47wEeN5FDHmhGXhfczCulk7hCo8PtD3dGV2H6PlS0gFh2XWiiWCpEGwJVWogUJ9tu/7Fr7HslNkewDAdhqdernwsoDf2Og4/8rCXKFQQL/4hFtpxiTyV85gKOsxprYcGsQSgtL7DlcaszcZW9YlfTNrs7vQEKXiV3PU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1726071317; c=relaxed/simple; bh=ftM+DDnmQmOYnwN5aQVtFV0dJlz1AGJWP+A1i0WPDNQ=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=sS+sXpWHY+PQNkm9l9X1/kCVlVJF2Zad2t5/XUnNBN2WAPXLaDQ3WK9H+gdbPCBaTm3GEn1ePCR0E5odkxyictuD9yL3IUbKjqupHFi3K1iJYhNjg9F031kxmci4A1hksdNJUw0azzYJ7Fp5FKcnlE76OLSeRZGrr8P23sMlANM= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=microchip.com; spf=pass smtp.mailfrom=microchip.com; dkim=pass (2048-bit key) header.d=microchip.com header.i=@microchip.com header.b=rEBXGX1N; arc=none smtp.client-ip=68.232.154.123 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=microchip.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=microchip.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=microchip.com header.i=@microchip.com header.b="rEBXGX1N" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=microchip.com; i=@microchip.com; q=dns/txt; s=mchp; t=1726071316; x=1757607316; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=ftM+DDnmQmOYnwN5aQVtFV0dJlz1AGJWP+A1i0WPDNQ=; b=rEBXGX1N4OLxZX09J2SWsuc3MdXPWTViQQJAyNFuEZWnkVCemVIXFJLS 1TwvuG+BcTIHUB+lL/q5tcndaILSXePdTZocxFIaD0hLLfPyCvyF4inuU nqPSDAUPwYHf/bKGMHE5gP9oQfPm1lIfeqt+cDvs6jwA0iNd8XbDh1BUk 3PeeK9bCmIfCCW/ktSTeyOzcdvTbJpuWiBlHs56epUf9E5QDifzkFh7w1 JJSqEnaKUp0QtT+gaZMg8Z+Hyvo9fItTYtmzSmql0El1Ou7UR5BuWdB8Z iFT4NMNHSzXdeVgcsAgcd3ELpvwx0xH3uMOzPuyBSf+WNh2aIgeZ3+tmX w==; X-CSE-ConnectionGUID: I+zUQG3KSiiiwGtN22Ixjw== X-CSE-MsgGUID: c072b4IOQiqRjevIyY933Q== X-IronPort-AV: E=Sophos;i="6.10,220,1719903600"; d="scan'208";a="32280151" X-Amp-Result: SKIPPED(no attachment in message) Received: from unknown (HELO email.microchip.com) ([170.129.1.10]) by esa2.microchip.iphmx.com with ESMTP/TLS/ECDHE-RSA-AES128-GCM-SHA256; 11 Sep 2024 09:15:12 -0700 Received: from chn-vm-ex02.mchp-main.com (10.10.85.144) by chn-vm-ex03.mchp-main.com (10.10.85.151) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.35; Wed, 11 Sep 2024 09:15:10 -0700 Received: from HYD-DK-UNGSW21.microchip.com (10.10.85.11) by chn-vm-ex02.mchp-main.com (10.10.85.144) with Microsoft SMTP Server id 15.1.2507.35 via Frontend Transport; Wed, 11 Sep 2024 09:15:05 -0700 From: Raju Lakkaraju To: CC: , , , , , , , , , , , , , Subject: [PATCH net-next V2 4/5] net: lan743x: Implement phylink pcs Date: Wed, 11 Sep 2024 21:40:53 +0530 Message-ID: <20240911161054.4494-5-Raju.Lakkaraju@microchip.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240911161054.4494-1-Raju.Lakkaraju@microchip.com> References: <20240911161054.4494-1-Raju.Lakkaraju@microchip.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Register MDIO bus for PCS layer to use Synopsys designware XPCS, support SGMII/1000Base-X/2500Base-X interfaces. Signed-off-by: Raju Lakkaraju --- Change List: =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D = =20 V2 : Include this new patch in the V2 series.=20 drivers/net/ethernet/microchip/Kconfig | 1 + drivers/net/ethernet/microchip/lan743x_main.c | 72 ++++++++++++++++++- drivers/net/ethernet/microchip/lan743x_main.h | 2 + 3 files changed, 73 insertions(+), 2 deletions(-) diff --git a/drivers/net/ethernet/microchip/Kconfig b/drivers/net/ethernet/= microchip/Kconfig index 3dacf39b49b4..793a20ef51fc 100644 --- a/drivers/net/ethernet/microchip/Kconfig +++ b/drivers/net/ethernet/microchip/Kconfig @@ -53,6 +53,7 @@ config LAN743X select I2C_PCI1XXXX select GP_PCI1XXXX select SFP + select PCS_XPCS help Support for the Microchip LAN743x and PCI11x1x families of PCI Express Ethernet devices diff --git a/drivers/net/ethernet/microchip/lan743x_main.c b/drivers/net/et= hernet/microchip/lan743x_main.c index c1061e2972f9..ef76d0c1642f 100644 --- a/drivers/net/ethernet/microchip/lan743x_main.c +++ b/drivers/net/ethernet/microchip/lan743x_main.c @@ -1143,6 +1143,28 @@ static int lan743x_get_lsd(int speed, int duplex, u8= mss) return lsd; } =20 +static int pci11x1x_pcs_read(struct mii_bus *bus, int addr, int devnum, + int regnum) +{ + struct lan743x_adapter *adapter =3D bus->priv; + + if (addr) + return -EOPNOTSUPP; + + return lan743x_sgmii_read(adapter, devnum, regnum); +} + +static int pci11x1x_pcs_write(struct mii_bus *bus, int addr, int devnum, + int regnum, u16 val) +{ + struct lan743x_adapter *adapter =3D bus->priv; + + if (addr) + return -EOPNOTSUPP; + + return lan743x_sgmii_write(adapter, devnum, regnum, val); +} + static int lan743x_sgmii_mpll_set(struct lan743x_adapter *adapter, u16 baud) { @@ -3201,6 +3223,19 @@ void lan743x_mac_eee_enable(struct lan743x_adapter *= adapter, bool enable) lan743x_csr_write(adapter, MAC_CR, mac_cr); } =20 +static struct phylink_pcs * +lan743x_phylink_mac_select_pcs(struct phylink_config *config, + phy_interface_t interface) +{ + struct net_device *netdev =3D to_net_dev(config->dev); + struct lan743x_adapter *adapter =3D netdev_priv(netdev); + + if (adapter->xpcs) + return &adapter->xpcs->pcs; + + return NULL; +} + static void lan743x_phylink_mac_config(struct phylink_config *config, unsigned int link_an_mode, const struct phylink_link_state *state) @@ -3302,6 +3337,7 @@ static void lan743x_phylink_mac_link_up(struct phylin= k_config *config, } =20 static const struct phylink_mac_ops lan743x_phylink_mac_ops =3D { + .mac_select_pcs =3D lan743x_phylink_mac_select_pcs, .mac_config =3D lan743x_phylink_mac_config, .mac_link_down =3D lan743x_phylink_mac_link_down, .mac_link_up =3D lan743x_phylink_mac_link_up, @@ -3654,6 +3690,9 @@ static void lan743x_hardware_cleanup(struct lan743x_a= dapter *adapter) =20 static void lan743x_mdiobus_cleanup(struct lan743x_adapter *adapter) { + if (adapter->xpcs) + xpcs_destroy(adapter->xpcs); + mdiobus_unregister(adapter->mdiobus); } =20 @@ -3763,6 +3802,7 @@ static int lan743x_hardware_init(struct lan743x_adapt= er *adapter, =20 static int lan743x_mdiobus_init(struct lan743x_adapter *adapter) { + struct dw_xpcs *xpcs; u32 sgmii_ctl; int ret; =20 @@ -3783,8 +3823,17 @@ static int lan743x_mdiobus_init(struct lan743x_adapt= er *adapter) "SGMII operation\n"); adapter->mdiobus->read =3D lan743x_mdiobus_read_c22; adapter->mdiobus->write =3D lan743x_mdiobus_write_c22; - adapter->mdiobus->read_c45 =3D lan743x_mdiobus_read_c45; - adapter->mdiobus->write_c45 =3D lan743x_mdiobus_write_c45; + if (adapter->is_sfp_support_en) { + adapter->mdiobus->read_c45 =3D + pci11x1x_pcs_read; + adapter->mdiobus->write_c45 =3D + pci11x1x_pcs_write; + } else { + adapter->mdiobus->read_c45 =3D + lan743x_mdiobus_read_c45; + adapter->mdiobus->write_c45 =3D + lan743x_mdiobus_write_c45; + } adapter->mdiobus->name =3D "lan743x-mdiobus-c45"; netif_dbg(adapter, drv, adapter->netdev, "lan743x-mdiobus-c45\n"); @@ -3820,9 +3869,28 @@ static int lan743x_mdiobus_init(struct lan743x_adapt= er *adapter) ret =3D mdiobus_register(adapter->mdiobus); if (ret < 0) goto return_error; + + if (adapter->is_sfp_support_en) { + if (!adapter->phy_interface) + lan743x_phy_interface_select(adapter); + + xpcs =3D xpcs_create_mdiodev(adapter->mdiobus, 0, + adapter->phy_interface); + if (IS_ERR(xpcs)) { + netdev_err(adapter->netdev, "failed to create xpcs\n"); + ret =3D PTR_ERR(xpcs); + goto err_destroy_xpcs; + } + adapter->xpcs =3D xpcs; + } + return 0; =20 +err_destroy_xpcs: + xpcs_destroy(xpcs); + return_error: + mdiobus_free(adapter->mdiobus); return ret; } =20 diff --git a/drivers/net/ethernet/microchip/lan743x_main.h b/drivers/net/et= hernet/microchip/lan743x_main.h index c303a69c3bea..f7480a401a27 100644 --- a/drivers/net/ethernet/microchip/lan743x_main.h +++ b/drivers/net/ethernet/microchip/lan743x_main.h @@ -10,6 +10,7 @@ #include #include #include +#include #include "lan743x_ptp.h" =20 #define DRIVER_AUTHOR "Bryan Whitehead " @@ -1130,6 +1131,7 @@ struct lan743x_adapter { struct lan743x_sw_nodes *nodes; struct i2c_adapter *i2c_adap; struct platform_device *sfp_dev; + struct dw_xpcs *xpcs; }; =20 #define LAN743X_COMPONENT_FLAG_RX(channel) BIT(20 + (channel)) --=20 2.34.1 From nobody Sat Nov 30 03:46:14 2024 Received: from esa.microchip.iphmx.com (esa.microchip.iphmx.com [68.232.153.233]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 903EA1AD40D; Wed, 11 Sep 2024 16:15:51 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=68.232.153.233 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1726071353; cv=none; b=NbqfoI/J88i8cXty3OZnzDoVq/tbuerf4mLLX15axz+qA9hVD7CrXRvz01ScpyH3UKkyQehdVu7hxeygUKW+hYvGLsi2rrKhBlsOJNbYZ4qDgP7OMjr2fRC8cBOm7pNFO3Oc1CrstpFhr8s2IolmJCUpxUk9g1pj97Q5Fp98F/Q= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1726071353; c=relaxed/simple; bh=DGQSUDDdyRJOFJ1VH1Rob5rJribm+UEFtdMpF8HJa/c=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=tCcUX3boIy+zfNpyZ17Xa1a1ObQ6uS5oapT/zNKbHQFLIeintC++H6ITK3mDQGNG5TkjiuzDgT/UsJc+XxToHe82lE7cPD856KrW7zNunFBcwaEUQWc7G0GGg8cz1DtdFrtv12ucrtEzzD+KiwHcUTUd7LKVE1Qk66MnX4wvJFw= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=microchip.com; spf=pass smtp.mailfrom=microchip.com; dkim=pass (2048-bit key) header.d=microchip.com header.i=@microchip.com header.b=Re5r7x30; arc=none smtp.client-ip=68.232.153.233 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=microchip.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=microchip.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=microchip.com header.i=@microchip.com header.b="Re5r7x30" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=microchip.com; i=@microchip.com; q=dns/txt; s=mchp; t=1726071351; x=1757607351; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=DGQSUDDdyRJOFJ1VH1Rob5rJribm+UEFtdMpF8HJa/c=; b=Re5r7x30RQQZfymvdu3Oel0wtUao0yurL+SUISivC1LCmxIjQssyJBdR f67zcg/imbW3HArJvtfVv+0hZNlrlWN6/iV1zxnQm+5hzUUbmhHk/RVmS g4I4c0no5IEOLq2JWdGxvUwarFUYZiXgk8ecO3jIWNT+2UhFrTXjwPc+u VBs7h7zd7mfkBpHXpYgpeMxNEpRCbZ7/Z+EMeSVcsOLvnzVxPkvxlAsUL Cy4/4dMPbvmbWHsXwM97n5XBxTvTUnmf573LzBxNyU0KmABluZUhujXVj 2v327uP0Aq+WymGijumS5OHaFkYg1BRV86iQUg4No2M5m2RnGOpMyRcfi A==; X-CSE-ConnectionGUID: wQTYqSpVRaKatvgABLE7Ew== X-CSE-MsgGUID: Za8HzPuCTpetq2lmKjkOpA== X-IronPort-AV: E=Sophos;i="6.10,220,1719903600"; d="scan'208";a="34798045" X-Amp-Result: SKIPPED(no attachment in message) Received: from unknown (HELO email.microchip.com) ([170.129.1.10]) by esa1.microchip.iphmx.com with ESMTP/TLS/ECDHE-RSA-AES128-GCM-SHA256; 11 Sep 2024 09:15:50 -0700 Received: from chn-vm-ex02.mchp-main.com (10.10.85.144) by chn-vm-ex03.mchp-main.com (10.10.85.151) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.35; Wed, 11 Sep 2024 09:15:15 -0700 Received: from HYD-DK-UNGSW21.microchip.com (10.10.85.11) by chn-vm-ex02.mchp-main.com (10.10.85.144) with Microsoft SMTP Server id 15.1.2507.35 via Frontend Transport; Wed, 11 Sep 2024 09:15:11 -0700 From: Raju Lakkaraju To: CC: , , , , , , , , , , , , , Subject: [PATCH net-next V2 5/5] net: lan743x: Add Support for 2.5G SFP with 2500Base-X Interface Date: Wed, 11 Sep 2024 21:40:54 +0530 Message-ID: <20240911161054.4494-6-Raju.Lakkaraju@microchip.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240911161054.4494-1-Raju.Lakkaraju@microchip.com> References: <20240911161054.4494-1-Raju.Lakkaraju@microchip.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Support for 2.5G SFP modules utilizing the 2500Base-X interface. The implementation includes integration with the Phylink subsystem to manage the link state and configuration dynamically. Signed-off-by: Raju Lakkaraju --- Change List: =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D V2 : Include this new patch in the V2 series.=20 drivers/net/ethernet/microchip/lan743x_main.c | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/drivers/net/ethernet/microchip/lan743x_main.c b/drivers/net/et= hernet/microchip/lan743x_main.c index ef76d0c1642f..7fe699e5a134 100644 --- a/drivers/net/ethernet/microchip/lan743x_main.c +++ b/drivers/net/ethernet/microchip/lan743x_main.c @@ -1495,7 +1495,10 @@ static void lan743x_phy_interface_select(struct lan7= 43x_adapter *adapter) data =3D lan743x_csr_read(adapter, MAC_CR); id_rev =3D adapter->csr.id_rev & ID_REV_ID_MASK_; =20 - if (adapter->is_pci11x1x && adapter->is_sgmii_en) + if (adapter->is_pci11x1x && adapter->is_sgmii_en && + adapter->is_sfp_support_en) + adapter->phy_interface =3D PHY_INTERFACE_MODE_2500BASEX; + else if (adapter->is_pci11x1x && adapter->is_sgmii_en) adapter->phy_interface =3D PHY_INTERFACE_MODE_SGMII; else if (id_rev =3D=3D ID_REV_ID_LAN7430_) adapter->phy_interface =3D PHY_INTERFACE_MODE_GMII; @@ -3359,6 +3362,7 @@ static int lan743x_phylink_create(struct lan743x_adap= ter *adapter) lan743x_phy_interface_select(adapter); =20 switch (adapter->phy_interface) { + case PHY_INTERFACE_MODE_2500BASEX: case PHY_INTERFACE_MODE_SGMII: __set_bit(PHY_INTERFACE_MODE_SGMII, adapter->phylink_config.supported_interfaces); @@ -3412,12 +3416,13 @@ static int lan743x_phylink_connect(struct lan743x_a= dapter *adapter) struct device_node *dn =3D adapter->pdev->dev.of_node; struct net_device *dev =3D adapter->netdev; struct phy_device *phydev; - int ret; + int ret =3D 0; =20 if (dn) ret =3D phylink_of_phy_connect(adapter->phylink, dn, 0); =20 - if (!dn || (ret && !lan743x_phy_handle_exists(dn))) { + if (!adapter->is_sfp_support_en && + (!dn || (ret && !lan743x_phy_handle_exists(dn)))) { phydev =3D phy_find_first(adapter->mdiobus); if (phydev) { /* attach the mac to the phy */ --=20 2.34.1