From patchwork Mon Jan 22 19:17:15 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andre Werner X-Patchwork-Id: 190361 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7301:2bc4:b0:101:a8e8:374 with SMTP id hx4csp2787521dyb; Mon, 22 Jan 2024 11:26:24 -0800 (PST) X-Google-Smtp-Source: AGHT+IEVxmQ/3rTn8UJwdAxSax6fdjfqVsdRjQhronsF/H6xA7wLIWVOappdv+UUTmQL4V0wZU89 X-Received: by 2002:a9d:618c:0:b0:6e0:b2c3:2442 with SMTP id g12-20020a9d618c000000b006e0b2c32442mr4961666otk.59.1705951584630; Mon, 22 Jan 2024 11:26:24 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1705951584; cv=pass; d=google.com; s=arc-20160816; b=BY699QCUjTyGpe3EyFROhS2yJ/IqFcRkev1WfHDM+dEw8DSx0o7rEoRrMVhR1iZrTm oLnNGVpN2iiNR0IGCTT3CLwaduwnPgjqSe21KdEHbdC9NCB5OPxSovEP2vQ1O/gipa5z FpdOX04Wk1/i9xM6Xx3Qx0S8cg+pHzX7vbA+fRFG4S8oVjb12JoMdpWxaLTldG68NAjG aosGFk1EZt3nguHf/54DsOoS1ANJ4xFf3JOBL4AFKAgyNqOK7ELfQirDdqAiOwzz4EdA wm3cyRyphqR06kitvE4DcVZExBOIUT8FS3NL2RcSYStRhnBIIQpV8JGYa8fXOCAq4giq hu5w== 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=mW08HNSPy56HL8/Wc/HNt69swvBgRv/uYpr/mOogiqk=; fh=EW95u4Nxu1efLMnFaTYf/hfJfmSzKgtewn9i4CVxfk8=; b=AvJ34vpc1ExCwpYMkPllGVy7MTIHvo2c01Ov86nVoHddM3WZ1D7fQFh5QOSwBHk2No ROJbktk5xnH480jU1hCAxUhV7jiemh/VnIEGnX5pxP6M7h7OSlM/6dEOU0E79StRbXhD LY1vqHu2rjD11JjYq1xU40cyFlWVrBJ4s06WllVNMqwtF4iQwXom7Nvdzrb+DoOFe9kc hmMKin2HqZzKEGHBY0gXK1PSI6dYLytiQG2MD9/rPYS7yEHQHaUaYn6a5QbM/vJpORTt 7dfvzXMbv6ogctRd26A6Njlrj6iNDi6XPRvHUKskOs7l5YqKLt42Wa9UBIeGHFq4c2pC aUFA== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@systec-electronic.com header.s=B34D3B04-5DC7-11EE-83E3-4D8CAB78E8CD header.b="iTM7P/Xg"; 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-34050-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-34050-ouuuleilei=gmail.com@vger.kernel.org" Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [147.75.199.223]) by mx.google.com with ESMTPS id c15-20020a05622a058f00b00429d5815307si6230543qtb.362.2024.01.22.11.26.24 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 22 Jan 2024 11:26:24 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-34050-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) client-ip=147.75.199.223; Authentication-Results: mx.google.com; dkim=pass header.i=@systec-electronic.com header.s=B34D3B04-5DC7-11EE-83E3-4D8CAB78E8CD header.b="iTM7P/Xg"; 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-34050-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-34050-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 ny.mirrors.kernel.org (Postfix) with ESMTPS id 6A7941C248F9 for ; Mon, 22 Jan 2024 19:26:24 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 1F7CB4642F; Mon, 22 Jan 2024 19:24:24 +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="iTM7P/Xg" 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 96FD7405EE; Mon, 22 Jan 2024 19:24:18 +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=1705951461; cv=none; b=VuSOu4qGGahYAATVp1pppr4UBfxtZMvGkgkg+askNywP8DlUzYO+V6ooo3/Y2LYqa6TvtpRIn0K52pJdoZbpF6SdLVw75D8EuJPygW1zIjlXy40APC4gbSf244Viov97q7Y8khhuzM5Zik0IWPzMqiJdeP+g4tclUGB2aMIGHC0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1705951461; c=relaxed/simple; bh=C7ED0YFMfngV6TLDyUhwMv6dkN7P2bIDcDODkYH1lqo=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=l13UOC/Y9AcWgR8qpsBvByuOGnMaoRyPqTeRETK102mSv8D7R0Ut6hcBrFtVJkYED7a1YFdWmbqfsT3yKkD55VltpQ+HkY2Q8Mg+7xuhqCQvmKj6DE1jtn72X7ejRDqHlNEqL5cd5z8yiRvHYlDFGJMy/HoRRpQtRaqOR4fDXDY= 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=iTM7P/Xg; 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 7426D940010B; Mon, 22 Jan 2024 20:24:16 +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 FV1Q_8zrO4mP; Mon, 22 Jan 2024 20:24:16 +0100 (CET) Received: from localhost (localhost.localdomain [127.0.0.1]) by mail.systec-electronic.com (Postfix) with ESMTP id 4F695941A5CE; Mon, 22 Jan 2024 20:24:16 +0100 (CET) DKIM-Filter: OpenDKIM Filter v2.10.3 mail.systec-electronic.com 4F695941A5CE DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=systec-electronic.com; s=B34D3B04-5DC7-11EE-83E3-4D8CAB78E8CD; t=1705951456; bh=mW08HNSPy56HL8/Wc/HNt69swvBgRv/uYpr/mOogiqk=; h=From:To:Date:Message-ID:MIME-Version; b=iTM7P/XgxsQC7eC/71RricBfuVa4P+e8OFpkViAJYMxDC+ZAKPcmEezNjpeLu3PZf AB1weJs7o/8sfFlaC+WVPKJosuYDKxQzXG3X0qcTmP7z7KA1lzS7qgzBok/gV6h+w2 IJF3RlhO1xtVNFEOe7vtXaHdcf97XjKHqVI1rgTfGRfTjHDah00hdfMu+JqSakUzpA 9+AOLFm5vOQIomgwNW8CtahHJCPEfbM5Xur73pGpr/PKVjbq8m1RgNEZ/exLFIqSv2 GLnq6++tWufmzYzZRO6pYWf2vBUWhj6kDvS6cRtuxA+KK9DbQwAB6epP2nXCnGhKKq AbXObUORwk4MA== 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 HmfUjs_cKSmL; Mon, 22 Jan 2024 20:24:16 +0100 (CET) Received: from ws-565760.systec.local (unknown [212.185.67.148]) by mail.systec-electronic.com (Postfix) with ESMTPSA id 04D42940010B; Mon, 22 Jan 2024 20:24:16 +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 v5 1/2] net: phy: phy_device: Prevent nullptr exceptions on ISR Date: Mon, 22 Jan 2024 20:17:15 +0100 Message-ID: <20240122192401.26836-2-andre.werner@systec-electronic.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240122192401.26836-1-andre.werner@systec-electronic.com> References: <20240122192401.26836-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: 1788819888626491213 X-GMAIL-MSGID: 1788819888626491213 If phydev->irq is set unconditionally, check for valid interrupt handler or fall back to polling mode to prevent nullptr exceptions in interrupt service routine. Signed-off-by: Andre Werner Reviewed-by: Andrew Lunn --- v5: - No functional changes. Add Reviewed-by tag. v4: - Delete phydev_warn and comment as suggested. v3: - No changes to v2. Just to complete the series. v2: - Add changes suggested in discussion about adin1100.c driver to phy_attach_direct. --- drivers/net/phy/phy_device.c | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/drivers/net/phy/phy_device.c b/drivers/net/phy/phy_device.c index 3611ea64875e..7cbe7c714177 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,9 @@ int phy_attach_direct(struct net_device *dev, struct phy_device *phydev, if (phydev->dev_flags & PHY_F_NO_IRQ) phydev->irq = PHY_POLL; + if (!phy_drv_supports_irq(phydev->drv) && phy_interrupt_is_valid(phydev)) + 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 +3000,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 Mon Jan 22 19:17:16 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andre Werner X-Patchwork-Id: 190362 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7301:2bc4:b0:101:a8e8:374 with SMTP id hx4csp2788362dyb; Mon, 22 Jan 2024 11:28:20 -0800 (PST) X-Google-Smtp-Source: AGHT+IGbuU/3g1Oj4nwZH+LXvblTLZ1fpAngkhfU6jVM/Drd5YqT1scnnlIBHB3CvsjRX40N1/QR X-Received: by 2002:a17:906:9c87:b0:a30:8d46:4cac with SMTP id fj7-20020a1709069c8700b00a308d464cacmr676668ejc.67.1705951700385; Mon, 22 Jan 2024 11:28:20 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1705951700; cv=pass; d=google.com; s=arc-20160816; b=j3BrprJEzd79C5vbXXaltpufjQ/DHZDyjYo7kmbLWpVOmqH6cXQiMb8ZdQ6E9f0xsS ppgtb0SIO4eJx/PeeSXmIwEJZGo6Yn9qbGYcJltftX15pxkgBOyDeCnT6nwfNqo1peAk 9LInTrUO8EwOITYZOaLMzprzgnhZd0jwa7MKAutAgvsWZ4K1aKrS4jcGOK8zbGDec1Vl HMW406ucFyGYBTs0CGn5ooHSbTgYSD4r4c2AQo0hrjQZ4asYiSVaQlrEppwk66QDKcoG 6V483VMY+UL9Ccj16w1b3weppLGJAzoBWnnn5a2s9sqNgho+AaY+lNJxuykPbOkvDa9D r18g== 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=BLVBSipavZztTYx8CwSVW5BhkEJvYHjdnvg38MQ/MRg=; fh=EW95u4Nxu1efLMnFaTYf/hfJfmSzKgtewn9i4CVxfk8=; b=qbHMERmtr6wM9w+AcyEjz8i05J7QR3R9NXuVcIe0mMRF5xjxPBz2mVEUYz15mM2l32 EupH6pB0PK1FYuljgIz/wmtvfY4iNVegxUIcBnj5Wa9aG+VKRPlH+8Rj2rGlYQU0Jg9G AX6ryKJgUtsJU2RrdVDOov6TJ/pWoAaDuQuR2S4Q9q9Zg1J1pxeJkOmXX2oIJskTRHEe 5pFTEDRLMQ4s4I5q4v3thn+hksKG0B+K5E0ZIja/GkK0n3T8klmOOzdTySkvgG+HKrGz lUbKEQlNBlLgfkTPfPGtJ6+kZJVMzWRJwVo77/t9A9xnGkAda0WBNVCpW5Qul/v2x276 FgEQ== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@systec-electronic.com header.s=B34D3B04-5DC7-11EE-83E3-4D8CAB78E8CD header.b=gyyaOMGF; 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-34051-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-34051-ouuuleilei=gmail.com@vger.kernel.org" Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [2604:1380:4601:e00::3]) by mx.google.com with ESMTPS id a6-20020a170906274600b00a28475b5e4csi10847283ejd.704.2024.01.22.11.28.20 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 22 Jan 2024 11:28:20 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-34051-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) client-ip=2604:1380:4601:e00::3; Authentication-Results: mx.google.com; dkim=pass header.i=@systec-electronic.com header.s=B34D3B04-5DC7-11EE-83E3-4D8CAB78E8CD header.b=gyyaOMGF; 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-34051-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-34051-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 am.mirrors.kernel.org (Postfix) with ESMTPS id 2BF1A1F24C5F for ; Mon, 22 Jan 2024 19:26:35 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id D564E46528; Mon, 22 Jan 2024 19:24:24 +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="gyyaOMGF" 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 BDA5D405F5; Mon, 22 Jan 2024 19:24:18 +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=1705951462; cv=none; b=XKQMA/rEXg9CKwPiSqunkd9wBgKQL8TNWMDqytBX8zY/0OL/KIUiwtsvM+XJPGcxammspTUiQV9KWli3vDTpfa6DmzPnDcSBUW57U+rRX++7BCHpONb6mfhgXRPS2Zpe1cEfnRCXDjfZWTJHZ42KR4Prd1n95obtC8rMxpl+/eA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1705951462; c=relaxed/simple; bh=Ai3CARrEENYU4ep+MOW7EaLMr7eb+dJKM7gjFW62Ec0=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=gJDtKqAnExR6n2as53+qZntiqfNad6IBrcSnxcAnxYt09py518zr/ZpiOvKxmDyEMdC2Dgaa3TR5gzH1Nn0GPv45LoftbZfakL3EihGppzsN/+3CnhGZZ7fg5XJO0jRGddwMCLjoPD1rMGrv7x92XCuAM9PKfDL0HJLcW9D3l+g= 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=gyyaOMGF; 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 C222B9401683; Mon, 22 Jan 2024 20:24:16 +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 ni_2G3t3zrlu; Mon, 22 Jan 2024 20:24:16 +0100 (CET) Received: from localhost (localhost.localdomain [127.0.0.1]) by mail.systec-electronic.com (Postfix) with ESMTP id 9BB99941A5CE; Mon, 22 Jan 2024 20:24:16 +0100 (CET) DKIM-Filter: OpenDKIM Filter v2.10.3 mail.systec-electronic.com 9BB99941A5CE DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=systec-electronic.com; s=B34D3B04-5DC7-11EE-83E3-4D8CAB78E8CD; t=1705951456; bh=BLVBSipavZztTYx8CwSVW5BhkEJvYHjdnvg38MQ/MRg=; h=From:To:Date:Message-ID:MIME-Version; b=gyyaOMGFyUUx07vqyMDN7NYM5SLND6NpbUsXh0ofwkOynGVjugL+b2WTdFpUflKok 4P3O47Yn0Z9uLMqPrz/Cz3seGkuhZOTwry3c9Ty1ZXcy5ZGK4NTNVKn55Vqb45LAfG umIo5iqJrmjb9QokP6uYI7oJyO8grZaH3qQYm/4fdcNtZZNWmryGxOJq1tCFUraJCG kVt28wrrbNfGrRcmxq/pSL/GadVCTJ5UEhvafpTOMu2f/G9Tujk3E6C3VR9oMnz9hl hBmiSoulpqQheq/9xI54Z7b1mJFY/8d33vxvLoz9DkWb/ykqu8hFFQQG/toKNtkoNA wIu5FZUyti2Yg== 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 JTjcKVjBY-d6; Mon, 22 Jan 2024 20:24:16 +0100 (CET) Received: from ws-565760.systec.local (unknown [212.185.67.148]) by mail.systec-electronic.com (Postfix) with ESMTPSA id 4815B9401683; Mon, 22 Jan 2024 20:24:16 +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 v5 2/2] net: phy: adin1100: Add interrupt support for link change Date: Mon, 22 Jan 2024 20:17:16 +0100 Message-ID: <20240122192401.26836-3-andre.werner@systec-electronic.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240122192401.26836-1-andre.werner@systec-electronic.com> References: <20240122192401.26836-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: 1788820010194306328 X-GMAIL-MSGID: 1788820010194306328 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 --- v5: - Add reversed-x-max-notation to variables in adin_config_intr. - Delete empty line between function call and if statement. v4: - Change read-modify-write behavior as suggested to phy_modify_mmd. v3: - Correct rashly format error that was reported by checker. v2: - Clean format and reword commit message as suggested by reviewer of first patch submission --- drivers/net/phy/adin1100.c | 55 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 55 insertions(+) diff --git a/drivers/net/phy/adin1100.c b/drivers/net/phy/adin1100.c index 7619d6185801..85f910e2d4fb 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,53 @@ 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) +{ + u16 irq_mask; + int ret; + + ret = adin_phy_ack_intr(phydev); + if (ret) + return ret; + + if (phydev->interrupts == PHY_INTERRUPT_ENABLED) + irq_mask = ADIN_LINK_STAT_CHNG_IRQ_EN; + else + irq_mask = 0; + + return phy_modify_mmd(phydev, MDIO_MMD_VEND2, + ADIN_PHY_SUBSYS_IRQ_MASK, + ADIN_LINK_STAT_CHNG_IRQ_EN, irq_mask); +} + +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 +328,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,