From patchwork Mon Jan 29 13:55:04 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andre Werner X-Patchwork-Id: 193492 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7301:2087:b0:106:209c:c626 with SMTP id gs7csp591411dyb; Mon, 29 Jan 2024 06:12:29 -0800 (PST) X-Google-Smtp-Source: AGHT+IGZdAQD6hpviX8g4wI0kLkoZq2YOrPJYA6wlk4xVF8lyn5gcFEjD0mlEucn/8k03bBusbRg X-Received: by 2002:a05:6358:938c:b0:176:ca53:38a9 with SMTP id h12-20020a056358938c00b00176ca5338a9mr3303603rwb.19.1706537549203; Mon, 29 Jan 2024 06:12:29 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1706537549; cv=pass; d=google.com; s=arc-20160816; b=VMyVoE1Dxo08UgYvYLtnKQxBS4voPN9gdmDfJjLVTi7roUJ2zXkMLwjbgjkSApQGeR cFQF9Tkr0unZLpp7RBKqncZB9xtFCp4wuvcNJTNqkQs5iTl0xAonTBVjztR/YWZ71+rd goIDPs/PvaMTo2NMl2tGWQq540tacEZnf3XUaGIzwHRItaWUODZL675DCsUZW7l1n9XZ PNBOeE9kPyoA/55EXHACcnlb50kXEideVaX/NBhyxj4VMJfCqV1MHqcqQvs4uD4IuzSA RReQVKSsKd9o6AcSoe3KRfLOfNSn4Odj8Ewiy5/v8LYCwEecMpGxbdaOVKM4xBGvzTuh CqOw== 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=oZtabn9a4o/r0XaHKQFRL1aLV2Wi+F8tuHdV9IBDvBk=; fh=EW95u4Nxu1efLMnFaTYf/hfJfmSzKgtewn9i4CVxfk8=; b=b7aRPtDEKvAAicDlv0pODnZMSvgwd5mZScFPRISm1gmASmkspeCiTg93/UO56SkxX9 1Bl5G7xTO/H4Jnnx0qi+KD1mRlwu1m1EoTuYLI1eKwLDNEuX6da0T8OtZrOAMN/LaMMb EGyH69DJM4CKPi4VCFAzRoGH2FCCA8wjQtmJLi5b6zxJRKO4ZNfAIyMKIjzSur3mVEYR orryF2eGd1oPx4qOswRzSYdkAM7QGAsLP7h8kA4LpNF2tdXNmX9nePk++je6NTcXai4B uUWzl4EVB7SvuJAzls2bdw9LX7w8R+gzUYYbB5dddJYTNjM1G4rf+CUjwxrksX5UqKEk SZMA== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@systec-electronic.com header.s=B34D3B04-5DC7-11EE-83E3-4D8CAB78E8CD header.b="joSwU/ud"; 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-42850-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-42850-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 bx40-20020a056a02052800b005d8bf74a070si3129135pgb.556.2024.01.29.06.12.28 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 29 Jan 2024 06:12:29 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-42850-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="joSwU/ud"; 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-42850-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-42850-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 C1461B2102D for ; Mon, 29 Jan 2024 13:59:07 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 254456773B; Mon, 29 Jan 2024 13:57:48 +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="joSwU/ud" 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 C693C65BC1; Mon, 29 Jan 2024 13:57:42 +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=1706536665; cv=none; b=Pmbu/5Oe3QaYK5D0+HULRJQPe5fNl/Yichjbt+5FqQ1DMN+5heG0ir4tqgQfgpZIl2sLB/FDy77HCac2qPy7+2knMMiVzLrYJ6mnLeoKPvD8fYvoj3emPBQfEafqlYgtO6zpTPA0TuCeVEPbWLP9abWfZ0Iz2xYUbeFWv0TW5xE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706536665; c=relaxed/simple; bh=UMJfFUGL5hSKpcaLyoAlFXOxYOstCOE9Bj+KlKW0jB0=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=o+tFcwVtM/tOBfIToxQpVCVG2VXO0nbDbrKfzTboihHMNfGVvwNsRs5JkHGcADM62XbyL3ZsDNYUPthu4x/6lANosGKINcnA3OKPq97huA1WzVdGxVnKtdNB6cZ2H2VO3kvszP6ac1daStMwlIkDtMLdsMHInDm7m6gdYrHHoOY= 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=joSwU/ud; 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 08AEF941A5D4; Mon, 29 Jan 2024 14:57:40 +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 J_rKWW5O-2Ds; Mon, 29 Jan 2024 14:57:39 +0100 (CET) Received: from localhost (localhost.localdomain [127.0.0.1]) by mail.systec-electronic.com (Postfix) with ESMTP id D739A941A5D7; Mon, 29 Jan 2024 14:57:39 +0100 (CET) DKIM-Filter: OpenDKIM Filter v2.10.3 mail.systec-electronic.com D739A941A5D7 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=systec-electronic.com; s=B34D3B04-5DC7-11EE-83E3-4D8CAB78E8CD; t=1706536659; bh=oZtabn9a4o/r0XaHKQFRL1aLV2Wi+F8tuHdV9IBDvBk=; h=From:To:Date:Message-ID:MIME-Version; b=joSwU/ud2Nm/3IIaEXsyLC42ZXDiFSaQD95b1W/FlEFwJuEL+aMvvsA65a9Ux4fpu V4jXpMqTsyZhuQ4JUgxsCida0JqUVBi6vw7qUm6vQR75nxbyWstUTENejrWXhNJtef APWXQfPELTicMlhttQ3qrGQSSrt8/SJ3Lyx2EIIWK0Xke3Z+mIx26TdXwxmEBjDr8Q hONqEh+/UfcsvyrIb20VHA0NGxf9fRXsBwRZKL9rqqwHML5kuJ7Jsyap9MQyX4s+Qb f8F6jIU9pYF5fXlY0mkvUI+BHwHL8e8pq/9eWiLmdTLDqWHY5G9WhQlmmaNmydllp6 BToilcpZCv+fA== 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 NHV68fuSjWCQ; Mon, 29 Jan 2024 14:57:39 +0100 (CET) Received: from ws-565760.systec.local (unknown [212.185.67.148]) by mail.systec-electronic.com (Postfix) with ESMTPSA id 8A384941A5D4; Mon, 29 Jan 2024 14:57:39 +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: [net-next v5 1/2] net: phy: phy_device: Prevent nullptr exceptions on ISR Date: Mon, 29 Jan 2024 14:55:04 +0100 Message-ID: <20240129135734.18975-2-andre.werner@systec-electronic.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240129135734.18975-1-andre.werner@systec-electronic.com> References: <20240129135734.18975-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: 1789434317124836277 X-GMAIL-MSGID: 1789434317124836277 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 dd778c7fde1d..52828d1c64f7 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 29 13:55:05 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andre Werner X-Patchwork-Id: 193490 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7301:2087:b0:106:209c:c626 with SMTP id gs7csp582746dyb; Mon, 29 Jan 2024 06:01:38 -0800 (PST) X-Google-Smtp-Source: AGHT+IG6Rglz/Bb52HiXHeUlqB6VRWuuoCFsjKwUYlw3U4sd2Mg1j0el0FZMvagp1T+kZ9jq3Dua X-Received: by 2002:a05:6358:5e11:b0:176:2874:3a2 with SMTP id q17-20020a0563585e1100b00176287403a2mr7362936rwn.47.1706536898664; Mon, 29 Jan 2024 06:01:38 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1706536898; cv=pass; d=google.com; s=arc-20160816; b=EH2xWBgBVWOvgg3Tgqi33+E653R1D3/uSKC5OPUH2+/mJ3f7inspNYxmZRRRqHHp8l +gsQwZm1IVp3c1YxkKnsyTK24XSvdpcLkv/xuYFbXeqRQTqk/Z4GoRZKrAI/hm0ILtoa o4B/LzlOmpUaRLqpy5fN6j8w31swtU8/vQvCFNQ9GkVJIkMdOVXSuS1M2jArDxBrA3/R r2Z7xLDzeXwIU37MuPjBI7flGsf9HpMzqtFrwK2MoG1xwWaNxhUSp/1EnTwVpFp3H9rn OsTIrRG8c5JuElskjmV3kOOEr16Fd1LckJAvONt3Msuslhz4ch2BzXU0olo3TY/nf0ko UcWQ== 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=KRXoTs/yH3UfLmz9fE1DvMsCYUEpsJN/WO/AYZNj592RpeVYk/nJPjF0nd3inrt4wd ZDfVTdvoaM2hCTqxOkSWMKeRUuTpPao+/HEgAnun/L41sUu6n5zQveh0yJMco+oRzZyo b5JyggJaAoScFwSfRSxLUEJi+BrCujp8Ue8KKnWdRT7zHDt/qvma8AoSnYEXBN5TVzwu 65MI93fdmJ7QVxS1sZtQg+ZbrufP78J333sGN/vH9nnWNy0aSMyt3Pryql0BsH+mPPDJ JifQPVo/t0Ch2sSv0ptT5OE4GY/TrvxewDr0M9TQ3znGCKgemDP53xmiVXxZZONIGpwY UhNg== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@systec-electronic.com header.s=B34D3B04-5DC7-11EE-83E3-4D8CAB78E8CD header.b=W16Xs31P; 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-42849-ouuuleilei=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-42849-ouuuleilei=gmail.com@vger.kernel.org" Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [139.178.88.99]) by mx.google.com with ESMTPS id 7-20020a630d47000000b005bdf597ed49si5768227pgn.56.2024.01.29.06.01.38 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 29 Jan 2024 06:01:38 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-42849-ouuuleilei=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) client-ip=139.178.88.99; Authentication-Results: mx.google.com; dkim=pass header.i=@systec-electronic.com header.s=B34D3B04-5DC7-11EE-83E3-4D8CAB78E8CD header.b=W16Xs31P; 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-42849-ouuuleilei=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-42849-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 sv.mirrors.kernel.org (Postfix) with ESMTPS id EF07728B366 for ; Mon, 29 Jan 2024 13:59:01 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id B369E66B4C; Mon, 29 Jan 2024 13:57:47 +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="W16Xs31P" 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 C52AD65BC0; Mon, 29 Jan 2024 13:57:42 +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=1706536664; cv=none; b=qZOAFyiYKHJxTz4vIS+LoFPRn3sMRP5/RnCivYzBNmxWGaOYaTNuoKfslbp5eEIC/anSrdzHeOqHIuW/PuHMEIFyj9ckkTo3Yfs9TbuEsvdhceG6pQ5nmaKbRlvcseEKKKJx06dUhtAo7XtK7Al/+UWXH3kc1EWiFKId1IwB9OE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706536664; c=relaxed/simple; bh=Ai3CARrEENYU4ep+MOW7EaLMr7eb+dJKM7gjFW62Ec0=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=N4iGmDpPiWMPHWiHDG4lhDrlJShwwbOXX9JQqal4/pwO6wgMLP+/qYkPbxiN9uFDEsBLUSM+zaLnEDePshZsMHDn4W5kc/8Sb8q34dlJnJwzr4+nrRBOwtyLPK84uvthE6rbwNai3ejhlNSLZm9MpG6GoMZ340GYJ5+LmDHVxVo= 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=W16Xs31P; 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 49E37941A5CF; Mon, 29 Jan 2024 14:57:40 +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 z1Fsjbw-VISF; Mon, 29 Jan 2024 14:57:40 +0100 (CET) Received: from localhost (localhost.localdomain [127.0.0.1]) by mail.systec-electronic.com (Postfix) with ESMTP id 24587941A5D5; Mon, 29 Jan 2024 14:57:40 +0100 (CET) DKIM-Filter: OpenDKIM Filter v2.10.3 mail.systec-electronic.com 24587941A5D5 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=systec-electronic.com; s=B34D3B04-5DC7-11EE-83E3-4D8CAB78E8CD; t=1706536660; bh=BLVBSipavZztTYx8CwSVW5BhkEJvYHjdnvg38MQ/MRg=; h=From:To:Date:Message-ID:MIME-Version; b=W16Xs31Phn0uLjZewKehKQq3Xgw6cOXveXd3Q2fcJua8zWKfqyRQYs0zXF3hCnuix oOZbc7Y08flzfNCqkSrVbJm38LGbI7bUrKJBj1kAdcP4rgNWgGYqEZ+4GnJGuzbMs2 gBGXvOkaBTT/gmmuUGEca3BuS5jPPCGmOW4T9KXmcQFg7U1FOt+NVR9nU4zshZrfED LW58r9B/r7iO4J7pV70v280SD4F2Cg22GKnNUWkUD+VURgC2QcoiXT9s2LhnHRL9Ht 6Inucs3Wtsdpf906N8YIqEhS+80gJp0FbESxka6HjfmwE0XtwNZzey1vfGHkNFPGH3 0/I8tklEqEjmw== 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 Heug1LM32S_s; Mon, 29 Jan 2024 14:57:40 +0100 (CET) Received: from ws-565760.systec.local (unknown [212.185.67.148]) by mail.systec-electronic.com (Postfix) with ESMTPSA id CB609941A5CF; Mon, 29 Jan 2024 14:57:39 +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: [net-next v5 2/2] net: phy: adin1100: Add interrupt support for link change Date: Mon, 29 Jan 2024 14:55:05 +0100 Message-ID: <20240129135734.18975-3-andre.werner@systec-electronic.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240129135734.18975-1-andre.werner@systec-electronic.com> References: <20240129135734.18975-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: 1789433635357296213 X-GMAIL-MSGID: 1789433635357296213 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,