From patchwork Fri Jan 19 09:32:25 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andre Werner X-Patchwork-Id: 189459 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7301:2bc4:b0:101:a8e8:374 with SMTP id hx4csp894542dyb; Fri, 19 Jan 2024 01:36:21 -0800 (PST) X-Google-Smtp-Source: AGHT+IHJngH1diPsHUzK2TAFmBQdUdaWX6MwL3fN6W6VDa9plDkJ5x0HUBMyjBlXEMdyfvPr2TL3 X-Received: by 2002:a05:6a00:4fc5:b0:6d9:cdf5:cc45 with SMTP id le5-20020a056a004fc500b006d9cdf5cc45mr2541817pfb.63.1705656981153; Fri, 19 Jan 2024 01:36:21 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1705656981; cv=pass; d=google.com; s=arc-20160816; b=NZJ6Y1C9qMsFNySqQ8Wa94epxs9gsFPEr1U3PybSg6dk340FQpDf2pvEzuKi1+8fJa u5RUhEGUYd4TGwp6saPJNKXhRtBIrXTW1DZBGuIc26O7YVtbFRChvcNhD/TWpDLeFdZe Aovm2DUPDxTteG2PCQdZRsGMBrdSzSf242BPuBfcxAM0n8v7l4STH/N/D3k0ZJtXDyLE EneGBzUGuEr6Y7aZr0lBV1TR4/9XW9Di8JgY12v0PAjPOBV05ZY+zpBpQHsNxaW35zCz nhXKE7IOzuTzSHXU456sXKW/aleXNtYR6Rf9B4+vvAZPzgcg03Xb59tKTNwGQTLRi0RH pG9w== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:message-id:date:subject:cc:to :from:dkim-signature:dkim-filter; bh=pU5zLdBie6WD4BylU5Qe/JyBc1oOisnlYg2DtaUpCgU=; fh=EW95u4Nxu1efLMnFaTYf/hfJfmSzKgtewn9i4CVxfk8=; b=Hl1J3LHJOxRbmtD7Cb25SeeKLMo34eQxP9183sp4xoU9MNpjiZ1cqoek/0li4YN97c zv6gdlZhnLE5CsIj3S7a06s/+0w5blqnYQ6imZ5ohe8oVlcQdlf48DlzEYNXBUEt5s1R zxd38WXSKa60ofWzd3St1mmS5z2QNMVkeZW7Yw/vrY7EV7UPp3n4KT3sPTEyOmwLj4LO 7aqnY3qw8XoZaxbKJBvaTe+xc6tFmHuvWrgLjEfaJ+ckTtLBlKLfUSJQDUHoyZtgwewl U5tVX4JIesaLrETIHm47+7dNI5uiTDP3bAx4zUFLVRvrSYeSKKMliJTuIcpV26B3C/PK fa/w== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@systec-electronic.com header.s=B34D3B04-5DC7-11EE-83E3-4D8CAB78E8CD header.b=GllQGoyl; arc=pass (i=1 spf=pass spfdomain=systec-electronic.com dkim=pass dkdomain=systec-electronic.com); spf=pass (google.com: domain of linux-kernel+bounces-30956-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) smtp.mailfrom="linux-kernel+bounces-30956-ouuuleilei=gmail.com@vger.kernel.org" Received: from sy.mirrors.kernel.org (sy.mirrors.kernel.org. [147.75.48.161]) by mx.google.com with ESMTPS id v18-20020a62a512000000b006dbaf6c303bsi2047445pfm.6.2024.01.19.01.36.20 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 19 Jan 2024 01:36:21 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-30956-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) client-ip=147.75.48.161; Authentication-Results: mx.google.com; dkim=pass header.i=@systec-electronic.com header.s=B34D3B04-5DC7-11EE-83E3-4D8CAB78E8CD header.b=GllQGoyl; arc=pass (i=1 spf=pass spfdomain=systec-electronic.com dkim=pass dkdomain=systec-electronic.com); spf=pass (google.com: domain of linux-kernel+bounces-30956-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) smtp.mailfrom="linux-kernel+bounces-30956-ouuuleilei=gmail.com@vger.kernel.org" Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sy.mirrors.kernel.org (Postfix) with ESMTPS id 19C4CB24326 for ; Fri, 19 Jan 2024 09:35:48 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 9FD673C699; Fri, 19 Jan 2024 09:35:16 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=systec-electronic.com header.i=@systec-electronic.com header.b="GllQGoyl" Received: from mail.systec-electronic.com (mail.systec-electronic.com [77.220.239.22]) (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 8F21A3C068; Fri, 19 Jan 2024 09:35:10 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=77.220.239.22 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1705656914; cv=none; b=o52LmaHP25RtoOy0xZ1HNOWTIrvFpe4rDD1mLWDMQUWTydyedXEqZsbTl9Msg5ZtfuRs/H7TPtw/Viy5OeuJaMxnfUAbT8VI0oWkmvL3DxyZR9SrJ8By6XpGYmillgf/Tz7d0/8ZJuTQVccEG3CsmA5fhjqQ2vIDmCdOR0prE9U= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1705656914; c=relaxed/simple; bh=0YMvfGZcQmvcq65wZ2XEdm0xWU66Inkuxy0qUZM42kM=; h=From:To:Cc:Subject:Date:Message-ID:MIME-Version; b=irruGzqSTXTPdqJNbFluNvlQsLM4lj+wJ/YsBAyrERcFIrNyD6A3AKds20IwiT0mz/U1+vlRjDYp9G1qbbSPQCCeYFZLll8CofzWphGJqkg+v7Go6s7x4tSCc9xuNQcasJLeNiuafTkiG/CufI5NL6KQxKCaFoFqCj//w9t1qys= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=systec-electronic.com; spf=pass smtp.mailfrom=systec-electronic.com; dkim=pass (2048-bit key) header.d=systec-electronic.com header.i=@systec-electronic.com header.b=GllQGoyl; arc=none smtp.client-ip=77.220.239.22 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=systec-electronic.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=systec-electronic.com Received: from localhost (localhost.localdomain [127.0.0.1]) by mail.systec-electronic.com (Postfix) with ESMTP id 234AD9400107; Fri, 19 Jan 2024 10:35:07 +0100 (CET) Received: from mail.systec-electronic.com ([127.0.0.1]) by localhost (mail.systec-electronic.com [127.0.0.1]) (amavis, port 10032) with ESMTP id NFsGSF9ZCjXb; Fri, 19 Jan 2024 10:35:07 +0100 (CET) Received: from localhost (localhost.localdomain [127.0.0.1]) by mail.systec-electronic.com (Postfix) with ESMTP id DF14C9400115; Fri, 19 Jan 2024 10:35:06 +0100 (CET) DKIM-Filter: OpenDKIM Filter v2.10.3 mail.systec-electronic.com DF14C9400115 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=systec-electronic.com; s=B34D3B04-5DC7-11EE-83E3-4D8CAB78E8CD; t=1705656906; bh=pU5zLdBie6WD4BylU5Qe/JyBc1oOisnlYg2DtaUpCgU=; h=From:To:Date:Message-ID:MIME-Version; b=GllQGoylb58VxeaP7hUICFJUWq8QTpuO94oY2HCutywZ/BEB9EC3mTTHwFuC2l59y oSsoveUBOV5ujtbAbT8rMV2amiGHV0EEzoX8lGtW8yZJkRwwm22n+HsoPP3ULzJ4KD aPeYnNgAEVPZaYgITEo0rTMF7ABt9oWKp0sfntp5AP8QLLhRWiu3CsZ7lM8/txfRYe sdpa/BHPjxs3cnmK3j3lVE3Tt/NFaKOPy8bfTVcLl0gLnE+EJHAj46kerohI6FhHVU jCgFmp/h9yyBamN9T2+/7HPOmskVyxTlIOZmHuZubgcCVa8AAfD1dp9mzmhlIrbmtL KyLhHosm6Mqww== X-Virus-Scanned: amavis at systec-electronic.com Received: from mail.systec-electronic.com ([127.0.0.1]) by localhost (mail.systec-electronic.com [127.0.0.1]) (amavis, port 10026) with ESMTP id Jj0hHIiFsOaP; Fri, 19 Jan 2024 10:35:06 +0100 (CET) Received: from ws-565760.systec.local (unknown [212.185.67.148]) by mail.systec-electronic.com (Postfix) with ESMTPSA id 8CC8B9400107; Fri, 19 Jan 2024 10:35:06 +0100 (CET) From: Andre Werner To: andrew@lunn.ch, hkallweit1@gmail.com, davem@davemloft.net, edumazet@google.com, kuba@kernel.org, pabeni@redhat.com Cc: linux@armlinux.org.uk, netdev@vger.kernel.org, linux-kernel@vger.kernel.org, Andre Werner Subject: [RFC net-next v3 1/2] net: phy: phy_device Prevent nullptr exceptions on ISR Date: Fri, 19 Jan 2024 10:32:25 +0100 Message-ID: <20240119093503.6370-1-andre.werner@systec-electronic.com> X-Mailer: git-send-email 2.43.0 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1788500920405961550 X-GMAIL-MSGID: 1788510974968242653 If phydev->irq is set unconditionally by MAC drivers, check for valid interrupt handler or fall back to polling mode to prevent nullptr exceptions. Signed-off-by: Andre Werner --- v3: - No changes to v2. Just to complete the series. --- drivers/net/phy/phy_device.c | 22 +++++++++++++++++----- 1 file changed, 17 insertions(+), 5 deletions(-) diff --git a/drivers/net/phy/phy_device.c b/drivers/net/phy/phy_device.c index 3611ea64875e..3986e103d25e 100644 --- a/drivers/net/phy/phy_device.c +++ b/drivers/net/phy/phy_device.c @@ -1413,6 +1413,11 @@ int phy_sfp_probe(struct phy_device *phydev, } EXPORT_SYMBOL(phy_sfp_probe); +static bool phy_drv_supports_irq(struct phy_driver *phydrv) +{ + return phydrv->config_intr && phydrv->handle_interrupt; +} + /** * phy_attach_direct - attach a network device to a given PHY device pointer * @dev: network device to attach @@ -1527,6 +1532,18 @@ int phy_attach_direct(struct net_device *dev, struct phy_device *phydev, if (phydev->dev_flags & PHY_F_NO_IRQ) phydev->irq = PHY_POLL; + /* + * Some drivers may add IRQ numbers unconditionally to a phy device that does + * not implement an interrupt handler after phy_probe is already done. + * Reset to PHY_POLL to prevent nullptr exceptions in that case. + */ + if (!phy_drv_supports_irq(phydev->drv) && phy_interrupt_is_valid(phydev)) { + phydev_warn(phydev, + "No handler for IRQ=%d available. Falling back to polling mode\n", + phydev->irq); + phydev->irq = PHY_POLL; + } + /* Port is set to PORT_TP by default and the actual PHY driver will set * it to different value depending on the PHY configuration. If we have * the generic PHY driver we can't figure it out, thus set the old @@ -2992,11 +3009,6 @@ s32 phy_get_internal_delay(struct phy_device *phydev, struct device *dev, } EXPORT_SYMBOL(phy_get_internal_delay); -static bool phy_drv_supports_irq(struct phy_driver *phydrv) -{ - return phydrv->config_intr && phydrv->handle_interrupt; -} - static int phy_led_set_brightness(struct led_classdev *led_cdev, enum led_brightness value) { From patchwork Fri Jan 19 09:32:26 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andre Werner X-Patchwork-Id: 189460 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7301:2bc4:b0:101:a8e8:374 with SMTP id hx4csp894591dyb; Fri, 19 Jan 2024 01:36:28 -0800 (PST) X-Google-Smtp-Source: AGHT+IEZCOwkKo6GmvZQoLaDZGPJQtH4zURePGNaUEybP0BbdheneNy/q7EZlC9gyOSt6Xi8Qk9a X-Received: by 2002:a17:90a:d185:b0:28d:fdba:79d4 with SMTP id fu5-20020a17090ad18500b0028dfdba79d4mr1660631pjb.46.1705656988199; Fri, 19 Jan 2024 01:36:28 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1705656988; cv=pass; d=google.com; s=arc-20160816; b=h6A0bkaYfXwcZBqSzd9dfyjsRc7BnGoDKsWMJjH9/jih1djLjnOcTZ2SoM9hgvp5dw fZayVNM+Q8IcG8ajyQrYwVeAWPlL+5LVIm7oleX8M/9dYD/0na63WhgUrBDNPPZv9kWn khPtfcZlQJGMmYI7wfelG5t75paLTerP8jeJc626g1GSxV9qKWnn/dpDDFVXFYU9DX/l f5x5RSCSvnY7IFn/ripKUDMiczw/kujiHAcKED0WIrH8htnFTa+JaWTVS3Lzc51N3lcI 9UenlRBwZVVr+zBtLwsQTVTH4kQza32yT3vJDNqg+RW7bRGQmt1CwsJW/Ez4kNwrCzV3 h3ZA== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature:dkim-filter; bh=MTKWH6m4my9WXHOKN9l10Su/eSbqGp9VEHgcHaprZdI=; fh=EW95u4Nxu1efLMnFaTYf/hfJfmSzKgtewn9i4CVxfk8=; b=HNJNxlMnCAG+ea2VfXRTLzt0OXF+/NYFU0cxmSHO2eI51jrT15+m/wYRqo00wGhaFW En98SOo8mJi47YbobrhIO/E/rIJ5crcfig+uvEGeVssw8M+m1nP35RTiYqDddS/rjmQU SJe9v7+q5hUH1eh8WAf0T6s6ars9/AO2qpf/elbWE8SXHZhoYvaJayV22tCAvMZf6yhD iDM6rR7B+z3XZafLZevRPUp4VgplODOhTaHqgerdVTXGudNVq3bsVTZBrG+OpwQjDJ4H 8FyCxW7khaOM078JPjZygXlkza/LfhcHahEOFmjJmlyKNFRSZy+8rX5Uxh51HUXfubvL 9n5g== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@systec-electronic.com header.s=B34D3B04-5DC7-11EE-83E3-4D8CAB78E8CD header.b=ic+Y+WSh; arc=pass (i=1 spf=pass spfdomain=systec-electronic.com dkim=pass dkdomain=systec-electronic.com); spf=pass (google.com: domain of linux-kernel+bounces-30957-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-30957-ouuuleilei=gmail.com@vger.kernel.org" Received: from sy.mirrors.kernel.org (sy.mirrors.kernel.org. [2604:1380:40f1:3f00::1]) by mx.google.com with ESMTPS id co1-20020a17090afe8100b0028dd0ff8c93si3022648pjb.73.2024.01.19.01.36.27 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 19 Jan 2024 01:36:28 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-30957-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) client-ip=2604:1380:40f1:3f00::1; Authentication-Results: mx.google.com; dkim=pass header.i=@systec-electronic.com header.s=B34D3B04-5DC7-11EE-83E3-4D8CAB78E8CD header.b=ic+Y+WSh; arc=pass (i=1 spf=pass spfdomain=systec-electronic.com dkim=pass dkdomain=systec-electronic.com); spf=pass (google.com: domain of linux-kernel+bounces-30957-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-30957-ouuuleilei=gmail.com@vger.kernel.org" Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sy.mirrors.kernel.org (Postfix) with ESMTPS id 8E6E7B24392 for ; Fri, 19 Jan 2024 09:35:52 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 2DCC33CF41; Fri, 19 Jan 2024 09:35:17 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=systec-electronic.com header.i=@systec-electronic.com header.b="ic+Y+WSh" Received: from mail.systec-electronic.com (mail.systec-electronic.com [77.220.239.22]) (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 8F1EC3C064; Fri, 19 Jan 2024 09:35:10 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=77.220.239.22 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1705656914; cv=none; b=dsYClYp1/hpMz96YiDgFfklulg7v2W0UxXJ/UjeJmEtGk8SpHJ+JzleYmKINNNH4dKJmYiyBoEY76tSqksF2wOn6daSn1/HUQHmsVHdzRkgKH7ERDtX7qf68vxD3KADqAuXaGahWOqzy0vensfJeZJZXQBnclqVfUmkouB8gDjk= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1705656914; c=relaxed/simple; bh=bSZg78YFLl5BAM4tDcveDpHKCzqi35Xitbywtzj/TzU=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=bxc6nCS5/dU8WQPEivSA3VOVWch9gJ9qrXmH5FKXLlNmPXY9fqJSD9D8/UZ/Fv+riqb0rzC7mjn5gcwzQjCPCFFvD27y/W/uHEUiJvUecanT8GJqxi4vbJ+vl/54WK4LILcdveTFx699j0bpvAXeDJQIoYEQpNKEnFU3zagsi2Q= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=systec-electronic.com; spf=pass smtp.mailfrom=systec-electronic.com; dkim=pass (2048-bit key) header.d=systec-electronic.com header.i=@systec-electronic.com header.b=ic+Y+WSh; arc=none smtp.client-ip=77.220.239.22 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=systec-electronic.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=systec-electronic.com Received: from localhost (localhost.localdomain [127.0.0.1]) by mail.systec-electronic.com (Postfix) with ESMTP id 60C9B940010D; Fri, 19 Jan 2024 10:35:07 +0100 (CET) Received: from mail.systec-electronic.com ([127.0.0.1]) by localhost (mail.systec-electronic.com [127.0.0.1]) (amavis, port 10032) with ESMTP id BqlB-VJgbLlM; Fri, 19 Jan 2024 10:35:07 +0100 (CET) Received: from localhost (localhost.localdomain [127.0.0.1]) by mail.systec-electronic.com (Postfix) with ESMTP id 374269400115; Fri, 19 Jan 2024 10:35:07 +0100 (CET) DKIM-Filter: OpenDKIM Filter v2.10.3 mail.systec-electronic.com 374269400115 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=systec-electronic.com; s=B34D3B04-5DC7-11EE-83E3-4D8CAB78E8CD; t=1705656907; bh=MTKWH6m4my9WXHOKN9l10Su/eSbqGp9VEHgcHaprZdI=; h=From:To:Date:Message-ID:MIME-Version; b=ic+Y+WSh3a6qyxugTBTDCRUWeMFXox7Nyf4qJ0JAWApiwd4e5cWhQiNNSwbqWAJgc O3tUWLS6RTIoM9i0qFk6Nu6jnGzLwN6LzGJl5iQZoHLiRh3dBCDBJX/n4IPOvsQHgi N18ilCmBVaywNWn1xV6+i3WeOIOt7PojhCf5xP0JsC4S3Nqkx1RAk2aWIcHQx+2Wu6 fHX7wPNe7/7sntYrtrBwc6pKmxT+MabBdoIvl9eOMsL796leM3PRquQRdwwa0FDO+V yhBmSbM8a+2wjsWB4xvGdnQkQfmNRDLmB3V9NEcEg1XqkDToA6Wp6sOoDVCIugkuwd IeYSnKKETVdPw== X-Virus-Scanned: amavis at systec-electronic.com Received: from mail.systec-electronic.com ([127.0.0.1]) by localhost (mail.systec-electronic.com [127.0.0.1]) (amavis, port 10026) with ESMTP id hfwp1lJeY7RI; Fri, 19 Jan 2024 10:35:07 +0100 (CET) Received: from ws-565760.systec.local (unknown [212.185.67.148]) by mail.systec-electronic.com (Postfix) with ESMTPSA id D3D6B940010D; Fri, 19 Jan 2024 10:35:06 +0100 (CET) From: Andre Werner To: andrew@lunn.ch, hkallweit1@gmail.com, davem@davemloft.net, edumazet@google.com, kuba@kernel.org, pabeni@redhat.com Cc: linux@armlinux.org.uk, netdev@vger.kernel.org, linux-kernel@vger.kernel.org, Andre Werner Subject: [RFC net-next v3 2/2] net: phy: adin1100: Add interrupt support for link change Date: Fri, 19 Jan 2024 10:32:26 +0100 Message-ID: <20240119093503.6370-2-andre.werner@systec-electronic.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240119093503.6370-1-andre.werner@systec-electronic.com> References: <20240119093503.6370-1-andre.werner@systec-electronic.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1788510982243325734 X-GMAIL-MSGID: 1788510982243325734 An interrupt handler was added to the driver as well as functions to enable interrupts at the phy. There are several interrupts maskable at the phy, but only link change interrupts are handled by the driver yet. Signed-off-by: Andre Werner --- v3: - Correct rashly format error that was reported by checker. --- drivers/net/phy/adin1100.c | 61 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 61 insertions(+) diff --git a/drivers/net/phy/adin1100.c b/drivers/net/phy/adin1100.c index 7619d6185801..32700b44e486 100644 --- a/drivers/net/phy/adin1100.c +++ b/drivers/net/phy/adin1100.c @@ -18,6 +18,12 @@ #define PHY_ID_ADIN1110 0x0283bc91 #define PHY_ID_ADIN2111 0x0283bca1 +#define ADIN_PHY_SUBSYS_IRQ_MASK 0x0021 +#define ADIN_LINK_STAT_CHNG_IRQ_EN BIT(1) + +#define ADIN_PHY_SUBSYS_IRQ_STATUS 0x0011 +#define ADIN_LINK_STAT_CHNG BIT(1) + #define ADIN_FORCED_MODE 0x8000 #define ADIN_FORCED_MODE_EN BIT(0) @@ -136,6 +142,59 @@ static int adin_config_aneg(struct phy_device *phydev) return genphy_c45_config_aneg(phydev); } +static int adin_phy_ack_intr(struct phy_device *phydev) +{ + /* Clear pending interrupts */ + int rc = phy_read_mmd(phydev, MDIO_MMD_VEND2, + ADIN_PHY_SUBSYS_IRQ_STATUS); + + return rc < 0 ? rc : 0; +} + +static int adin_config_intr(struct phy_device *phydev) +{ + int ret, regval; + + ret = adin_phy_ack_intr(phydev); + + if (ret) + return ret; + + regval = phy_read_mmd(phydev, MDIO_MMD_VEND2, + ADIN_PHY_SUBSYS_IRQ_MASK); + if (regval < 0) + return regval; + + if (phydev->interrupts == PHY_INTERRUPT_ENABLED) + regval |= ADIN_LINK_STAT_CHNG_IRQ_EN; + else + regval &= ~ADIN_LINK_STAT_CHNG_IRQ_EN; + + ret = phy_write_mmd(phydev, MDIO_MMD_VEND2, + ADIN_PHY_SUBSYS_IRQ_MASK, + regval); + return ret; +} + +static irqreturn_t adin_phy_handle_interrupt(struct phy_device *phydev) +{ + int irq_status; + + irq_status = phy_read_mmd(phydev, MDIO_MMD_VEND2, + ADIN_PHY_SUBSYS_IRQ_STATUS); + if (irq_status < 0) { + phy_error(phydev); + return IRQ_NONE; + } + + if (!(irq_status & ADIN_LINK_STAT_CHNG)) + return IRQ_NONE; + + phy_trigger_machine(phydev); + + return IRQ_HANDLED; +} + static int adin_set_powerdown_mode(struct phy_device *phydev, bool en) { int ret; @@ -275,6 +334,8 @@ static struct phy_driver adin_driver[] = { .probe = adin_probe, .config_aneg = adin_config_aneg, .read_status = adin_read_status, + .config_intr = adin_config_intr, + .handle_interrupt = adin_phy_handle_interrupt, .set_loopback = adin_set_loopback, .suspend = adin_suspend, .resume = adin_resume,