From patchwork Fri Jan 19 06:51:13 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andre Werner X-Patchwork-Id: 189411 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7301:2bc4:b0:101:a8e8:374 with SMTP id hx4csp834202dyb; Thu, 18 Jan 2024 22:56:32 -0800 (PST) X-Google-Smtp-Source: AGHT+IFMMGs0esgEtKc0V0uspCGfUa/dLczKAkjbMllvgE+XgxUfwkR9KIEfr8QiWrrhHyZIeibw X-Received: by 2002:a05:6512:39c1:b0:50e:7b9e:359c with SMTP id k1-20020a05651239c100b0050e7b9e359cmr498021lfu.29.1705647392708; Thu, 18 Jan 2024 22:56:32 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1705647392; cv=pass; d=google.com; s=arc-20160816; b=KJvhhDOMuGPbXm/gv3xDgIT+lPD6xcTG5iojq95qTo054qb/85SMopfe0HZuofWBA1 I5bUoO9CIji27/aIJ+M9LKxWbBCmPvVIhSoi+cW+1f6THQm6KYntZ7d52iIOHbHAg9Ej sEgjgCHo6MXwigKZbjTBZVRRATj0LCm9THwzWKX6rtfXwDecDDR50bNZJuqRHHNkCy+E vFKJc6MCtys1Sb4qs1dDnzhr+2eiivY2VsnOYJTBPouFgnHmX2IAbQdy2NjKtWEV6SVk bRhgCr7iWXIOWs0nS0pOgXCn28L5LQnHjfCIf2Kxg+HNLiv/QlchiDRWpWWAQm6mkUEy Z+7A== 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=1bp2JHVqKgh6eV2IyrM4+ZNotlv2F+x5CxIeVH2IOsE=; fh=EW95u4Nxu1efLMnFaTYf/hfJfmSzKgtewn9i4CVxfk8=; b=D+ji6Jdh6zEiEr4GcuWCgTcn3F0eEjQyc0GAAYUBb4FFe47jLJ3BFE6VQkl8Ll/lEB QZ8i9kQ7U71fvqrqwUjxaOyPCV/zw8I8CXDapTbLYYv6b6rU5dv/WnleMTbZHEAnfYAs J841ay5Azx1qM0zCcnZbwU0+h8mJqpj8QrmAnV0MKlYxHJzT0NK5yrBTZZDRlh8edSRO BXZWPZ3nobxSyRt9xXQs1YA80i53oy9vl4yN8Dm4D1ZHABo4oi6BYNQPQWozPnIUa2mL ZYWgn5PNQpvtGdkQIjF+x90APCmnNM1Wrh7QuJo7Kj5igwO63fEqBSw6XUfVXyRp0YXX /U1A== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@systec-electronic.com header.s=B34D3B04-5DC7-11EE-83E3-4D8CAB78E8CD header.b=O7qv4Ew5; 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-30830-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-30830-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 u23-20020a1709063b9700b00a298aedd421si7243301ejf.543.2024.01.18.22.56.32 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 18 Jan 2024 22:56:32 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-30830-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=O7qv4Ew5; 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-30830-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-30830-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 188A21F225A1 for ; Fri, 19 Jan 2024 06:56:32 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id CE982DDA0; Fri, 19 Jan 2024 06:55:59 +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="O7qv4Ew5" 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 61ECE3C17; Fri, 19 Jan 2024 06:55:54 +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=1705647356; cv=none; b=A2Q7BpbwodUO3fJPxSLzcWNf/IQQetk9jkTbxjXn9hdfQAEuccaOLkXRFlGbSnjMdIPSlNo4dM5G1Z++dVP4OBuTir6vufDvhW224930jZ/R2kQGhsK7/3HDZXsIAy9uUIkDPRzFJte3N7pUBVlRtkS4LAI52qtDBV68CPgEKz8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1705647356; c=relaxed/simple; bh=EzdJOK/zJZATzSg79oEE1SrvYSP+J0rhqwg1XzobUgc=; h=From:To:Cc:Subject:Date:Message-ID:MIME-Version; b=kXyc5jB/crTlcSOp/L3taLLrTNy8OHAi8Siriv5N7NQ4i7SHrA4y/M1pw09oCJlZvX+hA4N2T8dPa2MVd6tyHxQYBaLu+8RuJCUpzfuFVg1oCggCETKTH/+hRz7xQ7mhJyDlUhDRQJS/VZhEFeoGI1tHzIrBW8bA7Ggq7RNF1zo= 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=O7qv4Ew5; 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 995539400107; Fri, 19 Jan 2024 07:55:52 +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 NI2KU7HkxeRZ; Fri, 19 Jan 2024 07:55:52 +0100 (CET) Received: from localhost (localhost.localdomain [127.0.0.1]) by mail.systec-electronic.com (Postfix) with ESMTP id 681EF940010D; Fri, 19 Jan 2024 07:55:52 +0100 (CET) DKIM-Filter: OpenDKIM Filter v2.10.3 mail.systec-electronic.com 681EF940010D DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=systec-electronic.com; s=B34D3B04-5DC7-11EE-83E3-4D8CAB78E8CD; t=1705647352; bh=1bp2JHVqKgh6eV2IyrM4+ZNotlv2F+x5CxIeVH2IOsE=; h=From:To:Date:Message-ID:MIME-Version; b=O7qv4Ew521oxlL4dPIzgD2fJ00EIUXUZpOtTBtAwgLrp90Wv972QV3KCnR3rZKOdq M6XA/Z5GJ3Q8q/8uFVie/VDg1hAIRwYKyzaTRvWzBzRssFygL4hXCoVAwlDC0TxlNW 9+NHqfQwQzYZBiz4bg/P/YC85LJhHIWWCfjy5n2ICtHpojlx6SAyPM+gUFUx8ipSjB aHckHevMEhlWL+NjLAmsj1DkniwZ+pE/6NyhTFZfyCSBkHIz5w7O/dEcJIEMx8H2fd s66N1lDndC2c9LlbedgBwiaPUFWJyHP45OUeiuq1nP667wxdwrssou0h4UVZw9Y/+L Jt59zDeihlG4g== 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 71MDglRghmsS; Fri, 19 Jan 2024 07:55:52 +0100 (CET) Received: from ws-565760.systec.local (unknown [212.185.67.148]) by mail.systec-electronic.com (Postfix) with ESMTPSA id 0C5879400107; Fri, 19 Jan 2024 07:55:52 +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 v2 1/2] net: phy: phy_device Prevent nullptr exceptions on ISR Date: Fri, 19 Jan 2024 07:51:13 +0100 Message-ID: <20240119065542.30279-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: 1788500920405961550 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 --- It was exact the way described by Heiner Kallweit. The Kernel Oops looked as follows: [ +0.004455] smsc95xx v2.0.0 [ +0.578343] ADIN1100 usb-001:007:00: attached PHY driver (mii_bus:phy_addr=usb-001:007:00, irq=149) [ +0.000526] smsc95xx 1-4:1.0 eth0: register 'smsc95xx' at usb-0000:00:14.0-4, smsc95xx USB 2.0 Ethernet, 44:d5:f2:a0:4d:bc [ +0.027107] smsc95xx 1-4:1.0 enp0s20f0u4: renamed from eth0 [ +0.073992] smsc95xx 1-4:1.0 enp0s20f0u4: Link is Down [ +9.559260] BUG: kernel NULL pointer dereference, address: 0000000000000000 [ +0.000020] #PF: supervisor instruction fetch in kernel mode [ +0.000008] #PF: error_code(0x0010) - not-present page [ +0.000009] PGD 0 P4D 0 [ +0.000011] Oops: 0010 [#1] PREEMPT SMP NOPTI [ +0.000013] CPU: 4 PID: 2073 Comm: irq/149-usb-001 Tainted: G OE 6.5.5-arch1-1 #1 d82a0f532dd8cfe67d5795c1738d9c01059a0c62 [ +0.000014] Hardware name: LENOVO 20RD001CGE/20RD001CGE, BIOS R16ET29W (1.15 ) 12/03/2020 [ +0.000006] RIP: 0010:0x0 [ +0.000100] Code: Unable to access opcode bytes at 0xffffffffffffffd6. [ +0.000007] RSP: 0018:ffffb3b8c35b3e58 EFLAGS: 00010246 [ +0.000011] RAX: 0000000000000000 RBX: ffff8e5a84d10800 RCX: 0000000000000002 [ +0.000007] RDX: ffff8e5aeba52100 RSI: ffff8e5a84d10800 RDI: ffff8e5a84d10800 [ +0.000007] RBP: ffff8e5a84d10d48 R08: 0000000000000000 R09: 0000000000000000 [ +0.000007] R10: 0000000000000001 R11: 0000000000000100 R12: ffffffffc22720a0 [ +0.000007] R13: ffff8e5a8a0a0c80 R14: ffffffff983505e0 R15: ffff8e5aed177940 [ +0.000006] FS: 0000000000000000(0000) GS:ffff8e5dd1500000(0000) knlGS:0000000000000000 [ +0.000009] CS: 0010 DS: 0000 ES: 0000 CR0: 0000000080050033 [ +0.000007] CR2: ffffffffffffffd6 CR3: 000000025b020004 CR4: 00000000003706e0 [ +0.000007] Call Trace: [ +0.000006] [ +0.000008] ? __die+0x23/0x70 [ +0.000018] ? page_fault_oops+0x171/0x4e0 [ +0.000017] ? sched_clock+0x10/0x30 [ +0.000010] ? sched_clock_cpu+0xf/0x190 [ +0.000015] ? exc_page_fault+0x7f/0x180 [ +0.000018] ? asm_exc_page_fault+0x26/0x30 [ +0.000014] ? __pfx_irq_thread_fn+0x10/0x10 [ +0.000031] phy_interrupt+0xac/0xf0 [libphy 6d44c9178d1bba7d6a381c1347a9242562ba5983] [ +0.000097] irq_thread_fn+0x20/0x60 [ +0.000014] irq_thread+0xfb/0x1c0 [ +0.000012] ? __pfx_irq_thread_dtor+0x10/0x10 [ +0.000013] ? __pfx_irq_thread+0x10/0x10 [ +0.000011] kthread+0xe5/0x120 [ +0.000013] ? __pfx_kthread+0x10/0x10 [ +0.000012] ret_from_fork+0x31/0x50 [ +0.000010] ? __pfx_kthread+0x10/0x10 [ +0.000011] ret_from_fork_asm+0x1b/0x30 [ +0.000022] [ +0.000005] Modules linked in: adin1100 smsc95xx selftests usbnet [..] [ +0.000082] CR2: 0000000000000000 [ +0.000007] ---[ end trace 0000000000000000 ]--- v2: - Added the workaround to phy_attach_direct as discussed in first patch submission. TODO: Make phy_device->irq private and add access function that proves availability of interrupt handler in phy driver. --- 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 06:51:14 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andre Werner X-Patchwork-Id: 189412 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7301:2bc4:b0:101:a8e8:374 with SMTP id hx4csp834243dyb; Thu, 18 Jan 2024 22:56:39 -0800 (PST) X-Google-Smtp-Source: AGHT+IG3pk8P04jOufcR93m0+1oCjuoCv8gekG7poj/MhYPAEkOkU0VBY0s5I6WwUtbJ2BZ/xA84 X-Received: by 2002:a25:ab86:0:b0:dc2:4d19:4fea with SMTP id v6-20020a25ab86000000b00dc24d194feamr1730633ybi.11.1705647399130; Thu, 18 Jan 2024 22:56:39 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1705647399; cv=pass; d=google.com; s=arc-20160816; b=whF7sJQG3mzXQa6ztva3rzxTh4jDOIdynkBmHLFzAJLywI5hEJI7m7gxt24WW0vd1m KFUMBBjpTI2e2IUzMHPHR5iK5m9X3tAK1GwRaMSmlfrYu+24H5i+rvyncHLk3bdsU9Ia jMzTSweeth+qqnkMV86xQrn1BW4KQkShLDxnY0hcDacZTNckhoZWRVU2WDE8zHaFDh/8 NBk3/s9dZBlZNQ+WHX2qDweRw+ECqH5Vp1bPLNgjYxL6dwVu0cJb49FXm066TsqQFFf7 he+0JS4v9HQI4rvqRYfsVCZrAwPvEu8u2aOFZdnhWkAdI9Cqk89q1A1BZveYrtjcHoxv YalA== 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=R2H+wxpHRJ7ij8BQv9/AjquxQAEYGY9PEXxh3X7nW18=; fh=EW95u4Nxu1efLMnFaTYf/hfJfmSzKgtewn9i4CVxfk8=; b=AXsPx3K15bGulQMaDBQXybS1Q3JMg0wIoI3BrdDotsZx4BHs2wwwd0l/AZ2koU/FJM bspZP2DNfqH5BxG5sqyQtuP6dKuv05WO4o9/6htkk1I2L9oEEPPLdl6KHu3n+vAaPWw1 agAdZRD2KS+P5a7hkgjO9DdSY1atzWZL4VoahRYjKiOGZkCKLZiRdfiTeVm3/Zq17pOf wEVpib1ma+jcsAOqHFhZbmuWJgBX1jrSP/yhwV4JmGyOmiBuQTKEEt8mzfzWq2o97ovd snK8IyzoZ7F0uX/La8DJtZ95sNWPbbtmYWF6MSY6814w7SKemqlPz2PVP7TnDGAvvXuX qiTg== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@systec-electronic.com header.s=B34D3B04-5DC7-11EE-83E3-4D8CAB78E8CD header.b=iM314C9W; 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-30831-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-30831-ouuuleilei=gmail.com@vger.kernel.org" Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [2604:1380:45d1:ec00::1]) by mx.google.com with ESMTPS id n6-20020a0ce486000000b0068198037a7asi2415048qvl.28.2024.01.18.22.56.39 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 18 Jan 2024 22:56:39 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-30831-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) client-ip=2604:1380:45d1:ec00::1; Authentication-Results: mx.google.com; dkim=pass header.i=@systec-electronic.com header.s=B34D3B04-5DC7-11EE-83E3-4D8CAB78E8CD header.b=iM314C9W; 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-30831-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-30831-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 D928E1C22C24 for ; Fri, 19 Jan 2024 06:56:38 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 021D1DDD5; Fri, 19 Jan 2024 06:56:01 +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="iM314C9W" 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 C37A6184E; Fri, 19 Jan 2024 06:55:56 +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=1705647358; cv=none; b=Rsbm4lV0ZKtCxkCpZRC4i3w3nUogEkaX1t6wSvXbRBgL00F95TN1ZAvgbjjAxlEqeBgwkO/f83lxyFpTVhGpHCz0wpJakY6nUFFdZsHtZLQbE8owDwS9wRho1+fpqspEyUhSOyZ7i3TJhKsY505fXV7fMrGpJuQu58JJVBIhgjY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1705647358; c=relaxed/simple; bh=fzZ9PqYrfw2bV7Rfs2G/n0BHJjQaonVjoKgOKh5vznc=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=F0tAFVSkwtjziy0J5GR/R8prgUR5k+XMF10kFkQQFEuFhGZy0FYf+6dTsG5SXZW0/RjCjLobbZ41NxuN2ws1bEZEP//l9x9JivMR6hR44ri2sW7qE+8q/6m/j8ppvN4wSMAqpzhg2YHkL6X3FNX7NVtyCDBQ2GwYa4QyGCO24fI= 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=iM314C9W; 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 01CCF940010D; Fri, 19 Jan 2024 07:55:55 +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 Q8OpYxjlMZbe; Fri, 19 Jan 2024 07:55:54 +0100 (CET) Received: from localhost (localhost.localdomain [127.0.0.1]) by mail.systec-electronic.com (Postfix) with ESMTP id BDA089400115; Fri, 19 Jan 2024 07:55:54 +0100 (CET) DKIM-Filter: OpenDKIM Filter v2.10.3 mail.systec-electronic.com BDA089400115 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=systec-electronic.com; s=B34D3B04-5DC7-11EE-83E3-4D8CAB78E8CD; t=1705647354; bh=R2H+wxpHRJ7ij8BQv9/AjquxQAEYGY9PEXxh3X7nW18=; h=From:To:Date:Message-ID:MIME-Version; b=iM314C9WPLk/qprc7zek/T3vwG/ee4kK4VD4Q7avuTkfBvoHAFhH+3OSGE3ttQGxh zPj3QEh0pcNeBs5GUmVAO5lQff7Idtq+5Kv40kb5GFhJxsV5cDYh396OCgA8Ju8j1v UnJPVK9Qq4/L6reEqVhyd4SvbRVwMubpnZI0nfjWpxUqPGvtIzMel3587UzK6m12yY XmYAe033xaLMPNSAPRk+c5bdhtRecjEoPhC/2M0AhN+kJNEk4M8zUDHTZKEkjQ52uT d5XqJKhxMnKX4k9VpumoG3cRYsdfTcfGaDPQxrnt237MtZP6lASbQ+gzsmLsbyA4Zc x9bNEfRTSqzPg== 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 XjM1_v4EJDbj; Fri, 19 Jan 2024 07:55:54 +0100 (CET) Received: from ws-565760.systec.local (unknown [212.185.67.148]) by mail.systec-electronic.com (Postfix) with ESMTPSA id 724CF940010D; Fri, 19 Jan 2024 07:55:54 +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 v2 2/2] net: phy: adin1100: Add interrupt support for link change Date: Fri, 19 Jan 2024 07:51:14 +0100 Message-ID: <20240119065542.30279-2-andre.werner@systec-electronic.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240119065542.30279-1-andre.werner@systec-electronic.com> References: <20240119065542.30279-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: 1788500927190283237 X-GMAIL-MSGID: 1788500927190283237 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 --- v2: - Clean format and reword commit message as suggested by reviewer of first patch submission --- 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..fb1146cf881a 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,