From patchwork Fri Sep 6 09:39:54 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Niklas_S=C3=B6derlund?= X-Patchwork-Id: 13793772 X-Patchwork-Delegate: kuba@kernel.org Received: from fhigh4-smtp.messagingengine.com (fhigh4-smtp.messagingengine.com [103.168.172.155]) (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 82D791CBE8B; Fri, 6 Sep 2024 09:40:56 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=103.168.172.155 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725615658; cv=none; b=GwOaLxj/KrUBNdouXOwXwhdtxiTIgXOv+KBfZVxWIshR6rafiUCCOLkOkNt+VtVf2f4J40+/bgN4/T+fAH7f6zaSB5Q1I0ZsKRylu6FImzY59T4Oqy/viNsos7dl/WmMdEx6WjiWdWb+JkeOeGW4pdc2+bBtRovKUrmOP+Av5fA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725615658; c=relaxed/simple; bh=kLB/Wn6rE+ZqmX3Yfd6fuixjc3CxaBmkdWnUTgQWgQk=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=qExV5J54nuFM0xIdDDRMNqZ51CVtR6i710nvUe9EI3H+jrPP1A0YE13pYwfFKtdWVMGdzo1e9CM+0c5q/SUELlNzNNHRdEDabBMpRI9fU3eYfKwAlPV+2vZwDipdrkPlubOMKx9j6pDWFVKQbHDUwZXRA691/7ZDO3xynFkraMg= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=ragnatech.se; spf=pass smtp.mailfrom=ragnatech.se; dkim=pass (2048-bit key) header.d=ragnatech.se header.i=@ragnatech.se header.b=JiRUsU6O; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b=qtO9cIzD; arc=none smtp.client-ip=103.168.172.155 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=ragnatech.se Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=ragnatech.se Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=ragnatech.se header.i=@ragnatech.se header.b="JiRUsU6O"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="qtO9cIzD" Received: from phl-compute-12.internal (phl-compute-12.phl.internal [10.202.2.52]) by mailfhigh.phl.internal (Postfix) with ESMTP id 623E91140350; Fri, 6 Sep 2024 05:40:55 -0400 (EDT) Received: from phl-mailfrontend-02 ([10.202.2.163]) by phl-compute-12.internal (MEProxy); Fri, 06 Sep 2024 05:40:55 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ragnatech.se; h= cc:cc:content-transfer-encoding:content-type:content-type:date :date:from:from:in-reply-to:in-reply-to:message-id:mime-version :references:reply-to:subject:subject:to:to; s=fm3; t=1725615655; x=1725702055; bh=ykG5dYqIHxzf95CtT5qtRbEJ/JTemLDU7J2+tcjYA9I=; b= JiRUsU6OyNGaAL1Tfl+sv7qaTVJHNE016qSjH2OCl+it8kXG+abhd1ln6798UVur IChKE9ct+WRkf+p3+tvjx7PMD7HNZBfPW4lvoA6RcjlC3YKvd3EnkZagYme92TYT p1HQXgeOH9ZtjRFOJMjUkH20h/L4yiM96ijRvmMP5OWPvX3V0VlfLEhRFCAobKIb XM+gHCn3I1Bq7QS9nfLdfrxalAk5eroN8HrwJ9B8PcOykiiJnmuuhHEiqmu/uHRj U9UmcbzBuaiaP9Tabd4FsADoNqEU+eUUk2uPzIqxsjvzyLS9M45Tr2qaDx7hM37y oPpDKNXJM9EopAcO7MS5OQ== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:cc:content-transfer-encoding :content-type:content-type:date:date:feedback-id:feedback-id :from:from:in-reply-to:in-reply-to:message-id:mime-version :references:reply-to:subject:subject:to:to:x-me-proxy:x-me-proxy :x-me-sender:x-me-sender:x-sasl-enc; s=fm1; t=1725615655; x= 1725702055; bh=ykG5dYqIHxzf95CtT5qtRbEJ/JTemLDU7J2+tcjYA9I=; b=q tO9cIzDOPUqdyjslizA+Hi5wQxpLU6fJXhi8bL9IpWmIoeLpyP04Q8MAzZVbyOfI bq10SgpN3RmCCY1OSofZrLNgoZ9+wOFjg241MtKyjknN5kvxAypbT7epvC8VBX5w H0YB9zkc+l6/9UXa24gIMHW3OAV0AMb7P+E9YdcOPb/lEgHwnd08c5eT/xmlMFpd WtIo2/GadpVHw70/thOyN0BsBzj/FJXUACo3qrwNUHE0kMXEfgkqepVcBH5SROvY y/HbP6OKW2jZM7zL5vzb6xOuEgsFjcXtLeTKpbto/eICtHuIKPRDl/O0Fs1+juDe osFp5kWsC4J/zvke83RmQ== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeeftddrudeiuddgudelucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdggtfgfnhhsuhgsshgtrhhisggvpdfu rfetoffkrfgpnffqhgenuceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnh htshculddquddttddmnecujfgurhephffvvefufffkofgjfhggtgfgsehtkeertdertdej necuhfhrohhmpefpihhklhgrshcuufpnuggvrhhluhhnugcuoehnihhklhgrshdrshhoug gvrhhluhhnugdorhgvnhgvshgrshesrhgrghhnrghtvggthhdrshgvqeenucggtffrrght thgvrhhnpeehiefgueevuedtfefhheegkeevtdelueeukeevfeduhefhhfejfffggeffle efgeenucevlhhushhtvghrufhiiigvpedtnecurfgrrhgrmhepmhgrihhlfhhrohhmpehn ihhklhgrshdrshhouggvrhhluhhnugesrhgrghhnrghtvggthhdrshgvpdhnsggprhgtph htthhopeduuddpmhhouggvpehsmhhtphhouhhtpdhrtghpthhtoheprghnughrvgifsehl uhhnnhdrtghhpdhrtghpthhtohephhhkrghllhifvghithdusehgmhgrihhlrdgtohhmpd hrtghpthhtoheplhhinhhugiesrghrmhhlihhnuhigrdhorhhgrdhukhdprhgtphhtthho pegurghvvghmsegurghvvghmlhhofhhtrdhnvghtpdhrtghpthhtohepvgguuhhmrgiivg htsehgohhoghhlvgdrtghomhdprhgtphhtthhopehkuhgsrgeskhgvrhhnvghlrdhorhhg pdhrtghpthhtohepphgrsggvnhhisehrvgguhhgrthdrtghomhdprhgtphhtthhopeihoh hshhhihhhirhhordhshhhimhhouggrrdhuhhesrhgvnhgvshgrshdrtghomhdprhgtphht thhopehnvghtuggvvhesvhhgvghrrdhkvghrnhgvlhdrohhrgh X-ME-Proxy: Feedback-ID: i80c9496c:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Fri, 6 Sep 2024 05:40:54 -0400 (EDT) From: =?utf-8?q?Niklas_S=C3=B6derlund?= To: Andrew Lunn , Heiner Kallweit , Russell King , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Yoshihiro Shimoda , netdev@vger.kernel.org Cc: linux-renesas-soc@vger.kernel.org, =?utf-8?q?Niklas_S=C3=B6derlund?= Subject: [net-next 1/2] net: phy: Expose the direct mdiobus access functions Date: Fri, 6 Sep 2024 11:39:54 +0200 Message-ID: <20240906093955.3083245-2-niklas.soderlund+renesas@ragnatech.se> X-Mailer: git-send-email 2.46.0 In-Reply-To: <20240906093955.3083245-1-niklas.soderlund+renesas@ragnatech.se> References: <20240906093955.3083245-1-niklas.soderlund+renesas@ragnatech.se> Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Patchwork-Delegate: kuba@kernel.org Expose the direct mdiobus read and write functions. These will be needed to refactor the SIOCGMIIREG and SIOCSMIIREG IOCTLs to fallback to indirect C45 access if needed. Signed-off-by: Niklas Söderlund --- drivers/net/phy/phy-core.c | 10 ++++++---- include/linux/phy.h | 12 ++++++++++++ 2 files changed, 18 insertions(+), 4 deletions(-) diff --git a/drivers/net/phy/phy-core.c b/drivers/net/phy/phy-core.c index 1f98b6a96c15..2845294053eb 100644 --- a/drivers/net/phy/phy-core.c +++ b/drivers/net/phy/phy-core.c @@ -542,8 +542,8 @@ static void mmd_phy_indirect(struct mii_bus *bus, int phy_addr, int devad, devad | MII_MMD_CTRL_NOINCR); } -static int mmd_phy_read(struct mii_bus *bus, int phy_addr, bool is_c45, - int devad, u32 regnum) +int mmd_phy_read(struct mii_bus *bus, int phy_addr, bool is_c45, + int devad, u32 regnum) { if (is_c45) return __mdiobus_c45_read(bus, phy_addr, devad, regnum); @@ -552,9 +552,10 @@ static int mmd_phy_read(struct mii_bus *bus, int phy_addr, bool is_c45, /* Read the content of the MMD's selected register */ return __mdiobus_read(bus, phy_addr, MII_MMD_DATA); } +EXPORT_SYMBOL(mmd_phy_read); -static int mmd_phy_write(struct mii_bus *bus, int phy_addr, bool is_c45, - int devad, u32 regnum, u16 val) +int mmd_phy_write(struct mii_bus *bus, int phy_addr, bool is_c45, + int devad, u32 regnum, u16 val) { if (is_c45) return __mdiobus_c45_write(bus, phy_addr, devad, regnum, val); @@ -563,6 +564,7 @@ static int mmd_phy_write(struct mii_bus *bus, int phy_addr, bool is_c45, /* Write the data into MMD's selected register */ return __mdiobus_write(bus, phy_addr, MII_MMD_DATA, val); } +EXPORT_SYMBOL(mmd_phy_write); /** * __phy_read_mmd - Convenience function for reading a register diff --git a/include/linux/phy.h b/include/linux/phy.h index a98bc91a0cde..10af3e3711fa 100644 --- a/include/linux/phy.h +++ b/include/linux/phy.h @@ -1402,6 +1402,18 @@ int phy_read_mmd(struct phy_device *phydev, int devad, u32 regnum); __ret; \ }) +/* + * mmd_phy_read - Convenience function for direct mdiobus read. + */ +int mmd_phy_read(struct mii_bus *bus, int phy_addr, bool is_c45, int devad, + u32 regnum); + +/* + * mmd_phy_write - Convenience function for direct mdiobus write. + */ +int mmd_phy_write(struct mii_bus *bus, int phy_addr, bool is_c45, + int devad, u32 regnum, u16 val); + /* * __phy_read_mmd - Convenience function for reading a register * from an MMD on a given PHY. From patchwork Fri Sep 6 09:39:55 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Niklas_S=C3=B6derlund?= X-Patchwork-Id: 13793773 X-Patchwork-Delegate: kuba@kernel.org Received: from fhigh4-smtp.messagingengine.com (fhigh4-smtp.messagingengine.com [103.168.172.155]) (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 459991CBEAD; Fri, 6 Sep 2024 09:40:57 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=103.168.172.155 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725615660; cv=none; b=bSSBYAZ7r1mgSZMXERpTBSQplnSr4AJjYYV1nOA408cX2vvYJRaBmzl5iTIuwavM4pgpZQEx3EiOl5sqaxdaU86QTsiOxUOS/zA4Z2JDVAjBSUkfpLf7Xh6tHkBcK+wmKDSRpgjmko3fJZrNH8gwL2leOoIdSMWT4L7SFEAjPXI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725615660; c=relaxed/simple; bh=UcktmCft6cqYHncEMNstLmr5ElEBkpJXSnXHPCL0j2s=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=cYnG3V9gD7r1yJDxLHl8+t/xNy6Pq+BfAIjyA5NwVdIz56vlhF8BPoZsf1SiXuxq5ec6KHU/HbOVveOjhivbW97suJSGKt70CcOPew6N9G6EqThC4+mZcY337XISXPaacn2YPB1ZfD0e2Qxtb8MOGevxz4Z/5Zv2Na4BIqoCK4o= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=ragnatech.se; spf=pass smtp.mailfrom=ragnatech.se; dkim=pass (2048-bit key) header.d=ragnatech.se header.i=@ragnatech.se header.b=AlGUVMie; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b=U3zXzSlr; arc=none smtp.client-ip=103.168.172.155 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=ragnatech.se Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=ragnatech.se Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=ragnatech.se header.i=@ragnatech.se header.b="AlGUVMie"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="U3zXzSlr" Received: from phl-compute-06.internal (phl-compute-06.phl.internal [10.202.2.46]) by mailfhigh.phl.internal (Postfix) with ESMTP id 51A8A1140358; Fri, 6 Sep 2024 05:40:57 -0400 (EDT) Received: from phl-mailfrontend-01 ([10.202.2.162]) by phl-compute-06.internal (MEProxy); Fri, 06 Sep 2024 05:40:57 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ragnatech.se; h= cc:cc:content-transfer-encoding:content-type:content-type:date :date:from:from:in-reply-to:in-reply-to:message-id:mime-version :references:reply-to:subject:subject:to:to; s=fm3; t=1725615657; x=1725702057; bh=toIFJlP41E6goXLblveoKyuDvLh5QaLAlC3413pszJY=; b= AlGUVMiec+ATndYlBpjaesT41lHcf75oIYpbgXxnKtCbZFsxOeFE1vn+SPtbB4+4 WKnR34CGyWsg7u9Ze/cFPskZnWmHC7XBP8NPpD94x6JI6FdgTgkVa//To4d8ISe/ +vpr4hf0U/umaI8JMp6U5ktKdZm35hU5DnzSFSG33BZZj3hW69zZZDqrBdZ7v8mI uQegliLNWTpLbtb8KczdGaGi326S2qp70/ZgT7JsG/6vy2959+e4/QLfQ+uCa8dI fTuOnMReLXk5js4qtg53zPRnDxIYpV60d1TZI808QjK74aMQS8bnnvEm5emUkXCM aqyXdNOG6hoFep3WAvQPAQ== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:cc:content-transfer-encoding :content-type:content-type:date:date:feedback-id:feedback-id :from:from:in-reply-to:in-reply-to:message-id:mime-version :references:reply-to:subject:subject:to:to:x-me-proxy:x-me-proxy :x-me-sender:x-me-sender:x-sasl-enc; s=fm1; t=1725615657; x= 1725702057; bh=toIFJlP41E6goXLblveoKyuDvLh5QaLAlC3413pszJY=; b=U 3zXzSlrMoCG4CbEdd8j5n1u5o5IlHlg1xtS6izPrIbk+VqO8iz53z95UF2ZM2MAG XVSI7RV470S8TJcxV5E3be0eOB4w/wO34e/EOu1G3y98nWarwMCPwACcWXTaqZhM y6aXzoARyqeaZBnh2s3um4VKzDklm50T+OVDZkit/lEQcqYzw1NA0Kj6L8GcEL5a QKxLJIPqP259yJuJgJ1r1rHFDM2EOpn++4ZNcaJLF45xObcSrCfpeeOqqogu5l+Y A7r55/ZcZbkehpW9oexj7LuTJ+xBo14sXQ009WNlprRr0ICfrKYVB8IWuInegStq PaIUoNF2KtNdzsbwFKukg== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeeftddrudeiuddgudelucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdggtfgfnhhsuhgsshgtrhhisggvpdfu rfetoffkrfgpnffqhgenuceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnh htshculddquddttddmnecujfgurhephffvvefufffkofgjfhggtgfgsehtkeertdertdej necuhfhrohhmpefpihhklhgrshcuufpnuggvrhhluhhnugcuoehnihhklhgrshdrshhoug gvrhhluhhnugdorhgvnhgvshgrshesrhgrghhnrghtvggthhdrshgvqeenucggtffrrght thgvrhhnpeehiefgueevuedtfefhheegkeevtdelueeukeevfeduhefhhfejfffggeffle efgeenucevlhhushhtvghrufhiiigvpedtnecurfgrrhgrmhepmhgrihhlfhhrohhmpehn ihhklhgrshdrshhouggvrhhluhhnugesrhgrghhnrghtvggthhdrshgvpdhnsggprhgtph htthhopeduuddpmhhouggvpehsmhhtphhouhhtpdhrtghpthhtoheprghnughrvgifsehl uhhnnhdrtghhpdhrtghpthhtohephhhkrghllhifvghithdusehgmhgrihhlrdgtohhmpd hrtghpthhtoheplhhinhhugiesrghrmhhlihhnuhigrdhorhhgrdhukhdprhgtphhtthho pegurghvvghmsegurghvvghmlhhofhhtrdhnvghtpdhrtghpthhtohepvgguuhhmrgiivg htsehgohhoghhlvgdrtghomhdprhgtphhtthhopehkuhgsrgeskhgvrhhnvghlrdhorhhg pdhrtghpthhtohepphgrsggvnhhisehrvgguhhgrthdrtghomhdprhgtphhtthhopeihoh hshhhihhhirhhordhshhhimhhouggrrdhuhhesrhgvnhgvshgrshdrtghomhdprhgtphht thhopehnvghtuggvvhesvhhgvghrrdhkvghrnhgvlhdrohhrgh X-ME-Proxy: Feedback-ID: i80c9496c:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Fri, 6 Sep 2024 05:40:56 -0400 (EDT) From: =?utf-8?q?Niklas_S=C3=B6derlund?= To: Andrew Lunn , Heiner Kallweit , Russell King , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Yoshihiro Shimoda , netdev@vger.kernel.org Cc: linux-renesas-soc@vger.kernel.org, =?utf-8?q?Niklas_S=C3=B6derlund?= Subject: [net-next 2/2] net: phy: Fallback to C22 access if needed in phy_mii_ioctl() Date: Fri, 6 Sep 2024 11:39:55 +0200 Message-ID: <20240906093955.3083245-3-niklas.soderlund+renesas@ragnatech.se> X-Mailer: git-send-email 2.46.0 In-Reply-To: <20240906093955.3083245-1-niklas.soderlund+renesas@ragnatech.se> References: <20240906093955.3083245-1-niklas.soderlund+renesas@ragnatech.se> Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Patchwork-Delegate: kuba@kernel.org If a C45 only PHY is attached to a driver that only knows how to talk C22 phylib will fallback and use indirect access. This frees the driver from having to implement this themself. The IOCTL implementation for SIOCGMIIREG and SIOCSMIIREG do not use these convenience functions and instead fail if a C45 PHY is used together with a driver that only knows how to speak C22. Fix this by using the two convince functions that knows when to fallback to indirect access to read/write to the MDIO bus when needed. Signed-off-by: Niklas Söderlund --- drivers/net/phy/phy.c | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/drivers/net/phy/phy.c b/drivers/net/phy/phy.c index 4f3e742907cb..89f52bb123aa 100644 --- a/drivers/net/phy/phy.c +++ b/drivers/net/phy/phy.c @@ -342,9 +342,12 @@ int phy_mii_ioctl(struct phy_device *phydev, struct ifreq *ifr, int cmd) if (mdio_phy_id_is_c45(mii_data->phy_id)) { prtad = mdio_phy_id_prtad(mii_data->phy_id); devad = mdio_phy_id_devad(mii_data->phy_id); - ret = mdiobus_c45_read(phydev->mdio.bus, prtad, devad, - mii_data->reg_num); + mutex_lock(&phydev->mdio.bus->mdio_lock); + ret = mmd_phy_read(phydev->mdio.bus, prtad, + phydev->is_c45, devad, + mii_data->reg_num); + mutex_unlock(&phydev->mdio.bus->mdio_lock); } else { ret = mdiobus_read(phydev->mdio.bus, mii_data->phy_id, mii_data->reg_num); @@ -403,11 +406,14 @@ int phy_mii_ioctl(struct phy_device *phydev, struct ifreq *ifr, int cmd) } } - if (mdio_phy_id_is_c45(mii_data->phy_id)) - mdiobus_c45_write(phydev->mdio.bus, prtad, devad, - mii_data->reg_num, val); - else + if (mdio_phy_id_is_c45(mii_data->phy_id)) { + mutex_lock(&phydev->mdio.bus->mdio_lock); + mmd_phy_write(phydev->mdio.bus, prtad, phydev->is_c45, + devad, mii_data->reg_num, val); + mutex_unlock(&phydev->mdio.bus->mdio_lock); + } else { mdiobus_write(phydev->mdio.bus, prtad, devad, val); + } if (prtad == phydev->mdio.addr && devad == MII_BMCR &&