From patchwork Sun Apr 6 22:13:54 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christian Marangi X-Patchwork-Id: 14039566 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id EB93BC36002 for ; Sun, 6 Apr 2025 22:18:54 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender:List-Subscribe:List-Help :List-Post:List-Archive:List-Unsubscribe:List-Id:Content-Transfer-Encoding: MIME-Version:References:In-Reply-To:Message-ID:Date:Subject:Cc:To:From: Reply-To:Content-Type:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=fbjlynKWg/4l7XREwNXFX/8RA/bU/RRJTqy0Jin3hBE=; b=VrSZs05ZslN4FyqQJTjFm1hb0j lTaKP+dO9l2W5R7m6CvYC0il/lMXqnTPRxIZ2YWOT2CIRgcQzLN5W8XHxSMugZ3+G7oMonFISy+7V 3SUlN8yTqLkaQ88F9UQEq49S5WAQPnUsA0f2DWL18sg5P+qcMLlFDuPloj2zNr8xR+PFLiUO27URP sP8k21Z946rl29T7GKXuybnSCuQkoeygjpFxhq6Qv8oMeknKRBYNoeGNXAik4vX9QD2O+Klsu48MT 5IjA70snFPo/sl50FvdVKTbTH/hV1ZxtCPLi9duiaoNHADMfk8ZLqrItl0awDL+22uCgfHUKb6Ttj sLhJkKOQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.98.1 #2 (Red Hat Linux)) id 1u1YKD-0000000Ftgk-21IN; Sun, 06 Apr 2025 22:18:45 +0000 Received: from mail-wm1-x334.google.com ([2a00:1450:4864:20::334]) by bombadil.infradead.org with esmtps (Exim 4.98.1 #2 (Red Hat Linux)) id 1u1YGc-0000000Fsu3-1ZiI; Sun, 06 Apr 2025 22:15:03 +0000 Received: by mail-wm1-x334.google.com with SMTP id 5b1f17b1804b1-43d0359b1fcso23385825e9.0; Sun, 06 Apr 2025 15:15:02 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1743977701; x=1744582501; darn=lists.infradead.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=fbjlynKWg/4l7XREwNXFX/8RA/bU/RRJTqy0Jin3hBE=; b=fBl0sECHdTdBaN31W/ZBltEcNW09E/oCFZ8igHaghfD1sXXIPvhJRL0CI4cew+l2tq rgptbJpQxHPHVxRiY3FFOXnHqAh2emmc0iDsEgSyddKbQAHLPO92zMWk5B5Tys2AlGsE 4SaCIPfy5ulqHTUMDHCZrmCD9Vb68qcprzUgG2Pjb9T8t+NDLm0JdE3ATr4Haoc73Kuf hS6sWz398lywi27eS3oJ10KKZyc1OhMDm1rtCqDIZoSWso4GmGljDhAYwpUwWtvFrvnU 1rHPqxJtoLZGrO8pVs2H23AHCvDoX01ktndqUTxnzLgPKqVe0x8BkOIiZvcZKBFC/Avh hrlA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1743977701; x=1744582501; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=fbjlynKWg/4l7XREwNXFX/8RA/bU/RRJTqy0Jin3hBE=; b=DxnbCK9WTuM/6YhPJKaF3DiX3aXCLXGr1tTBqNqfkGqiXrgFwHtS/2PFJifOZAtvmz 7uF06BEvOJv4LjwculXlDsIfG/QPcBRxZzcwpOUtj1aGpborrsItx+YEPVnJizXEhQAO rHyS/FY08Rc9125otIuT68nzZw8vYyykSwrC8qwwgAcjoTxOWJYRAvTZIlWw7632PgkQ HkkXveDtSVIM18SFWXyCgXWsGFtOOZkyWuV2avw6Ok9d/CyTn7anP8xL2/v9xmXXC2ji LbkqhxYns/2ZvslGKTTK4ETzpOTa7ig6ynZnNJnTZsZS6Mr6eSdi31nqLemBbPJJs6cd EsNA== X-Forwarded-Encrypted: i=1; AJvYcCUrtzBlSr/CEpCsz+VKA2Qpw9mCSXusqn54pJaAZlkre1Ncgb+gH6TZNH9TwR//0VpFz/FDicRas8IhkOxQl9Y=@lists.infradead.org, AJvYcCWn/qj6Saq6Dxx32fewgCAJWm58chGqZs1fwSu/PWZvurWhIylornefXc/jjOfzfYsgOdYxjotHRdtL1JEq3FMr@lists.infradead.org X-Gm-Message-State: AOJu0Yy54dkm6lW7Tc2uQDc4lbw34yIh+3rdfSQ2tI1cUqfhI5o4On4a hF5T1QJAEofvGzqe5Fh34NppVUlGcqY4eXVy5grqOBJVsWQjUPjG X-Gm-Gg: ASbGncvstTWxkAwIQRu8e6erYGJ/CoVR8vO4adtRwgu1vWCSZ0hPVYNvFoCejPdATN3 /38NEG3zZohCEK8jszWO+2O3omQA2DqJi2xdlMi2kG5+dTMO9BoBleXmHhDuA776ElCoPzYgibS aHtMiDvry8o0Y3TpzXI3NbrGMpgVEauq5m4jiN9952/HY19UK/aJMRShqKJvmvYbgw/26lQTr1e hYPdvbHrYyMyIDCxinXq2UoTGgclh/+B+cOl6g1BF0wDLMY2lBxZgUKuxwcgRw3vCH+a9iQNmEV DurFb6jQQsRadi/sWjQZyo2mEaWx5MMoogFspvw1w5ymSxMMjOhWwsMzasXtMHqIRbl2y/dZpl4 S+CwqNXAFGXVJkg== X-Google-Smtp-Source: AGHT+IEdcsmazJ3h4gV5FB1N2QFgWw4lBR8V7yh2Q970uDPmQsNJz+c+C9tAeyVOD9FOQdxcIx726Q== X-Received: by 2002:a05:600c:190b:b0:43d:fa5f:7d04 with SMTP id 5b1f17b1804b1-43ebf017220mr153587975e9.16.1743977700662; Sun, 06 Apr 2025 15:15:00 -0700 (PDT) Received: from localhost.localdomain (93-34-88-225.ip49.fastwebnet.it. [93.34.88.225]) by smtp.googlemail.com with ESMTPSA id 5b1f17b1804b1-43ec366aa29sm111517055e9.39.2025.04.06.15.14.59 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 06 Apr 2025 15:15:00 -0700 (PDT) From: Christian Marangi To: Andrew Lunn , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Rob Herring , Krzysztof Kozlowski , Conor Dooley , Lorenzo Bianconi , Heiner Kallweit , Russell King , Philipp Zabel , Christian Marangi , Daniel Golle , "Russell King (Oracle)" , netdev@vger.kernel.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-mediatek@lists.infradead.org, "Lei Wei (QUIC)" Cc: stable@vger.kernel.org Subject: [RFC PATCH net-next v2 01/11] net: phylink: fix possible circular locking dep with config in-band Date: Mon, 7 Apr 2025 00:13:54 +0200 Message-ID: <20250406221423.9723-2-ansuelsmth@gmail.com> X-Mailer: git-send-email 2.48.1 In-Reply-To: <20250406221423.9723-1-ansuelsmth@gmail.com> References: <20250406221423.9723-1-ansuelsmth@gmail.com> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20250406_151502_418578_3BE0AD74 X-CRM114-Status: GOOD ( 15.47 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org Debug lock detection revealed a possible circular locking dependency between phylink_major_config() and phylink_bringup_phy(). This was introduced by the addition of phy_config_inband(), which acquires the phydev lock. This made the locking order in phylink_bringup_phy() inconsistent, as it acquires the phydev lock before phylink's state_mutex. A deadlock can occur when phylink_major_config() is called from phylink_resolve(), where the state_mutex is taken first and then the phydev lock. This is the reverse of the order used in phylink_bringup_phy(). To avoid this circular dependency, change the locking order in phylink_bringup_phy() to match the pattern used in phylink_resolve(): take state_mutex first, then the phydev lock. A sample lockdep warning is included below for reference: [ 147.749178] [ 147.750682] ====================================================== [ 147.756850] WARNING: possible circular locking dependency detected [ 147.763019] 6.14.0-next-20250404+ #0 Tainted: G O [ 147.769189] ------------------------------------------------------ [ 147.775356] kworker/u16:0/12 is trying to acquire lock: [ 147.780571] ffffff80ce9bcf08 (&dev->lock#2){+.+.}-{4:4}, at: phy_config_inband+0x44/0x90 [ 147.788672] [ 147.788672] but task is already holding lock: [ 147.794492] ffffff80c0dfbda0 (&pl->state_mutex){+.+.}-{4:4}, at: phylink_resolve+0x2c/0x6a8 [ 147.802840] [ 147.802840] which lock already depends on the new lock. [ 147.802840] [ 147.811002] [ 147.811002] the existing dependency chain (in reverse order) is: [ 147.818472] [ 147.818472] -> #1 (&pl->state_mutex){+.+.}-{4:4}: [ 147.824647] __mutex_lock+0x90/0x924 [ 147.828738] mutex_lock_nested+0x20/0x28 [ 147.833173] phylink_bringup_phy+0x210/0x700 [ 147.837954] phylink_fwnode_phy_connect+0xe0/0x124 [ 147.843256] phylink_of_phy_connect+0x18/0x20 [ 147.848124] dsa_user_create+0x210/0x414 [ 147.852561] dsa_port_setup+0xd4/0x14c [ 147.856823] dsa_register_switch+0xbb0/0xe40 [ 147.861605] mt7988_probe+0xf8/0x140 [ 147.865694] platform_probe+0x64/0xbc [ 147.869869] really_probe+0xbc/0x388 [ 147.873955] __driver_probe_device+0x78/0x154 [ 147.878823] driver_probe_device+0x3c/0xd4 [ 147.883430] __device_attach_driver+0xb0/0x144 [ 147.888383] bus_for_each_drv+0x6c/0xb0 [ 147.892732] __device_attach+0x9c/0x19c [ 147.897078] device_initial_probe+0x10/0x18 [ 147.901771] bus_probe_device+0xa8/0xac [ 147.906118] deferred_probe_work_func+0xb8/0x118 [ 147.911245] process_one_work+0x224/0x610 [ 147.915769] worker_thread+0x1b8/0x35c [ 147.920029] kthread+0x11c/0x1e8 [ 147.923769] ret_from_fork+0x10/0x20 [ 147.927857] [ 147.927857] -> #0 (&dev->lock#2){+.+.}-{4:4}: [ 147.933686] __lock_acquire+0x12b8/0x1ff0 [ 147.938209] lock_acquire+0xf4/0x2d8 [ 147.942295] __mutex_lock+0x90/0x924 [ 147.946383] mutex_lock_nested+0x20/0x28 [ 147.950817] phy_config_inband+0x44/0x90 [ 147.955252] phylink_major_config+0x684/0xa64 [ 147.960120] phylink_resolve+0x24c/0x6a8 [ 147.964554] process_one_work+0x224/0x610 [ 147.969075] worker_thread+0x1b8/0x35c [ 147.973335] kthread+0x11c/0x1e8 [ 147.977075] ret_from_fork+0x10/0x20 [ 147.981162] [ 147.981162] other info that might help us debug this: [ 147.981162] [ 147.989150] Possible unsafe locking scenario: [ 147.989150] [ 147.995056] CPU0 CPU1 [ 147.999575] ---- ---- [ 148.004094] lock(&pl->state_mutex); [ 148.007748] lock(&dev->lock#2); [ 148.013572] lock(&pl->state_mutex); [ 148.019742] lock(&dev->lock#2); [ 148.023051] [ 148.023051] *** DEADLOCK *** [ 148.023051] [ 148.028958] 3 locks held by kworker/u16:0/12: [ 148.033304] #0: ffffff80c0011d48 ((wq_completion)events_power_efficient){+.+.}-{0:0}, at: process_one_work+0x1a8/0x610 [ 148.044082] #1: ffffffc081ca3dd8 ((work_completion)(&pl->resolve)){+.+.}-{0:0}, at: process_one_work+0x1d0/0x610 [ 148.054338] #2: ffffff80c0dfbda0 (&pl->state_mutex){+.+.}-{4:4}, at: phylink_resolve+0x2c/0x6a8 [ 148.063119] [ 148.063119] stack backtrace: [ 148.067465] CPU: 3 UID: 0 PID: 12 Comm: kworker/u16:0 Tainted: G O 6.14.0-next-20250404+ #0 NONE [ 148.067472] Tainted: [O]=OOT_MODULE [ 148.067474] Hardware name: Bananapi BPI-R4 2.5GE PoE (DT) [ 148.067476] Workqueue: events_power_efficient phylink_resolve [ 148.067482] Call trace: [ 148.067484] show_stack+0x14/0x1c (C) [ 148.067492] dump_stack_lvl+0x84/0xc0 [ 148.067497] dump_stack+0x14/0x1c [ 148.067500] print_circular_bug+0x330/0x43c [ 148.067505] check_noncircular+0x124/0x134 [ 148.067508] __lock_acquire+0x12b8/0x1ff0 [ 148.067512] lock_acquire+0xf4/0x2d8 [ 148.067516] __mutex_lock+0x90/0x924 [ 148.067521] mutex_lock_nested+0x20/0x28 [ 148.067527] phy_config_inband+0x44/0x90 [ 148.067531] phylink_major_config+0x684/0xa64 [ 148.067535] phylink_resolve+0x24c/0x6a8 [ 148.067539] process_one_work+0x224/0x610 [ 148.067544] worker_thread+0x1b8/0x35c [ 148.067548] kthread+0x11c/0x1e8 [ 148.067552] ret_from_fork+0x10/0x20 Cc: stable@vger.kernel.org Fixes: 5fd0f1a02e75 ("net: phylink: add negotiation of in-band capabilities") Signed-off-by: Christian Marangi --- drivers/net/phy/phylink.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/drivers/net/phy/phylink.c b/drivers/net/phy/phylink.c index 69ca765485db..4a1edf19dfad 100644 --- a/drivers/net/phy/phylink.c +++ b/drivers/net/phy/phylink.c @@ -2072,8 +2072,8 @@ static int phylink_bringup_phy(struct phylink *pl, struct phy_device *phy, dev_name(&phy->mdio.dev), phy->drv->name, irq_str); kfree(irq_str); - mutex_lock(&phy->lock); mutex_lock(&pl->state_mutex); + mutex_lock(&phy->lock); pl->phydev = phy; pl->phy_state.interface = interface; pl->phy_state.pause = MLO_PAUSE_NONE; @@ -2115,8 +2115,8 @@ static int phylink_bringup_phy(struct phylink *pl, struct phy_device *phy, phy_disable_eee(phy); } - mutex_unlock(&pl->state_mutex); mutex_unlock(&phy->lock); + mutex_unlock(&pl->state_mutex); phylink_dbg(pl, "phy: %s setting supported %*pb advertising %*pb\n", From patchwork Sun Apr 6 22:13:55 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christian Marangi X-Patchwork-Id: 14039570 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id E75B9C36002 for ; Sun, 6 Apr 2025 22:20:46 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender:List-Subscribe:List-Help :List-Post:List-Archive:List-Unsubscribe:List-Id:Content-Transfer-Encoding: MIME-Version:References:In-Reply-To:Message-ID:Date:Subject:To:From:Reply-To: Cc:Content-Type:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=1jotKc/Fqpl2Jd1jPfcmFs0z7oPm/HmjlcBjHuS3pTY=; b=jYNTnHIuYPLEAd0vzHVsOH754Q GDtHlfkxL/LwIhAPG0zxWG9R3YT5HAVzvL7YzST5JVv7HP3QJZwCzs78QRkg/IVdOYvdoE6r9xLX0 zA8Z+5mWZbhVMYwiOjukpuyi49fKGXdeA35359X2rGpQmSYv60dHOCC5ClLlmR4Fbwe8ko3BB+Tkc 8ZIQkAH4w8pK5f6+hgySQDRWnO2BApN4z2zPR5q6iAszuz2mfkMoCj5QF3YaXATY1YVeAuvTR5M1O XQOEjR6cMqIW+ZanEZSCvZeouqlNQWNiDDbUOwfARu8a/uL7KmLmr0GCeI36oUxMSiRUtM5lxSiTu HPRe9KDA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.98.1 #2 (Red Hat Linux)) id 1u1YM0-0000000Fu4l-3QJH; Sun, 06 Apr 2025 22:20:36 +0000 Received: from mail-wm1-x334.google.com ([2a00:1450:4864:20::334]) by bombadil.infradead.org with esmtps (Exim 4.98.1 #2 (Red Hat Linux)) id 1u1YGd-0000000FsuY-29Yd; Sun, 06 Apr 2025 22:15:04 +0000 Received: by mail-wm1-x334.google.com with SMTP id 5b1f17b1804b1-43d2d952eb1so24972675e9.1; Sun, 06 Apr 2025 15:15:03 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1743977702; x=1744582502; darn=lists.infradead.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:from:to:cc:subject:date:message-id :reply-to; bh=1jotKc/Fqpl2Jd1jPfcmFs0z7oPm/HmjlcBjHuS3pTY=; b=DVwX2YzZwbMxgw7aTEvaQ5reMcOdKB300IuE88owaJD/3aMTZ8DHiEG+f8rkQ2qlrf s6AK6f2Q3O1nnLTSQ924N3vIYfkqoWo9Z3tshQhMyo6+Zk1Rlrl0WTZPKf2aMdpQb9Pm TFGX+TFNTtvXHE4bYaNBg5Q4ICgAT3iKpgL1RBNSOUfe9mQftRQW9+I179ROkQoee645 MrGQxoO5zfEDRjHNIbghSeCaLTLsYUBj3DpJLVN5e55Y29wWebJLfe6eL9j8HeDyAeBV fd1sQjzbRE9IGPd1GDp0/sYEVGBKf0dI6yVTBomDMk9VBNBiuTuc78Cj01TLUV4y5j5T ECJA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1743977702; x=1744582502; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=1jotKc/Fqpl2Jd1jPfcmFs0z7oPm/HmjlcBjHuS3pTY=; b=puVugBocdAkiI4tLinhttFPkhKY9NIhH0jGFxKaPlvFke6ZMwwoNRk64RUl1UfM0wE fT/LpqFsCNDOY/e5P8X8Nl+VXz36LppkDP8X61qyT9ntkvP38DqvFVnQgJR3G4gtZ1Np ztT2Mqz7jVqExiMd8d+Pqy/KVHFpVa+9QqAS6+gEOobkOuC+1hSGKbA23+2wXnvwlxNE t6Ywfn6qibQRBgEWp4olim2RmKZOHj5mEiUnGGQw2VxKR7u7J0RxXS/K82xuvQtv3FBv ktveATKvlUZAZr0fLdM/A5ZfKCbSPI/qTM1t9IUupU1cLA/7zkWB1G0T9HV5GaCxTNsf Vp8A== X-Forwarded-Encrypted: i=1; AJvYcCUKcZoIMqz5tL5wUBJLY1lONv0S8fYtjFpOp8ZtrFQq0ulU9/LF6YCPDpcumkDom8Aj0nlvqkxCXrRh+6tCb0Zn@lists.infradead.org, AJvYcCWJyU4KA2hVjO2fvdKyVTIFAmzuoSMFFc/5J0oIDWfNlAQbAaA4jiMHFTuVeUUZIy3v9eiPhr5RKi20KGxPUt4=@lists.infradead.org X-Gm-Message-State: AOJu0YwoKNlq5PJxqansmwu+rtYVlrB5p+24kauBNaTInReZCPPBAyxQ LDIqblvJ532fsQTq2qtI6VjHtTwtAqz0QhtsW9TogHeRDXhCEp4S X-Gm-Gg: ASbGncsDos12XhDMQA0hhESOqxHG9HFLOm7tHsRxPPEaN8rz6HCvQGK2S4RABQQq9m2 K+CjIf6W1yyHAs8TIB3EA1XvF2G5x29/o7G+bcRJrAVAFMDGfdqBCjcw2sJrQ7x+qSSxaPor9z4 uM3vccEZiWCw9BrdJOS816f/uyyMMTj8Tr0xS2kCUyuMKl0k+RpSUe+JMwxmv2jG6Bj66jq8rrG rcG9JQIyY5EP+0QjL503K9t+mNuKrFP5bbrM5BOjDwZthXCgL7ovo+FzhNh+OAT1cKsITqFoDdY RcoNpy5JN0BcvI9C9Q9WarCOLvrHeJRr0EujT5p4pmpOHBb99XSWXGix82Iy+LPsTpnAvpWZDRn rh8ac4jLJWcxu9w== X-Google-Smtp-Source: AGHT+IF4Orsr0uagyxWiA2SygCLbqK10XpF3iEqB0Ey1M4fJ6BNRGD2Cn9NKoC8AeNVhrjTx7AWL5g== X-Received: by 2002:a05:600c:5785:b0:43d:209:21fd with SMTP id 5b1f17b1804b1-43ee0783d96mr59382275e9.30.1743977701942; Sun, 06 Apr 2025 15:15:01 -0700 (PDT) Received: from localhost.localdomain (93-34-88-225.ip49.fastwebnet.it. [93.34.88.225]) by smtp.googlemail.com with ESMTPSA id 5b1f17b1804b1-43ec366aa29sm111517055e9.39.2025.04.06.15.15.00 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 06 Apr 2025 15:15:01 -0700 (PDT) From: Christian Marangi To: Andrew Lunn , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Rob Herring , Krzysztof Kozlowski , Conor Dooley , Lorenzo Bianconi , Heiner Kallweit , Russell King , Philipp Zabel , Christian Marangi , Daniel Golle , "Russell King (Oracle)" , netdev@vger.kernel.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-mediatek@lists.infradead.org, "Lei Wei (QUIC)" Subject: [RFC PATCH net-next v2 02/11] net: phylink: keep and use MAC supported_interfaces in phylink struct Date: Mon, 7 Apr 2025 00:13:55 +0200 Message-ID: <20250406221423.9723-3-ansuelsmth@gmail.com> X-Mailer: git-send-email 2.48.1 In-Reply-To: <20250406221423.9723-1-ansuelsmth@gmail.com> References: <20250406221423.9723-1-ansuelsmth@gmail.com> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20250406_151503_568023_7C128977 X-CRM114-Status: GOOD ( 18.77 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org Add in phylink struct a copy of supported_interfaces from phylink_config and make use of that instead of relying on phylink_config value. This in preparation for support of PCS handling internally to phylink where a PCS can be removed or added after the phylink is created and we need both a reference of the supported_interfaces value from phylink_config and an internal value that can be updated with the new PCS info. Signed-off-by: Christian Marangi --- drivers/net/phy/phylink.c | 22 +++++++++++++++------- 1 file changed, 15 insertions(+), 7 deletions(-) diff --git a/drivers/net/phy/phylink.c b/drivers/net/phy/phylink.c index 4a1edf19dfad..6a7d6e3768da 100644 --- a/drivers/net/phy/phylink.c +++ b/drivers/net/phy/phylink.c @@ -66,6 +66,11 @@ struct phylink { /* The link configuration settings */ struct phylink_link_state link_config; + /* What interface are supported by the current link. + * Can change on removal or addition of new PCS. + */ + DECLARE_PHY_INTERFACE_MASK(supported_interfaces); + /* The current settings */ phy_interface_t cur_interface; @@ -616,7 +621,7 @@ static int phylink_validate_mask(struct phylink *pl, struct phy_device *phy, static int phylink_validate(struct phylink *pl, unsigned long *supported, struct phylink_link_state *state) { - const unsigned long *interfaces = pl->config->supported_interfaces; + const unsigned long *interfaces = pl->supported_interfaces; if (state->interface == PHY_INTERFACE_MODE_NA) return phylink_validate_mask(pl, NULL, supported, state, @@ -1815,6 +1820,9 @@ struct phylink *phylink_create(struct phylink_config *config, mutex_init(&pl->state_mutex); INIT_WORK(&pl->resolve, phylink_resolve); + phy_interface_copy(pl->supported_interfaces, + config->supported_interfaces); + pl->config = config; if (config->type == PHYLINK_NETDEV) { pl->netdev = to_net_dev(config->dev); @@ -1973,7 +1981,7 @@ static int phylink_validate_phy(struct phylink *pl, struct phy_device *phy, * those which the host supports. */ phy_interface_and(interfaces, phy->possible_interfaces, - pl->config->supported_interfaces); + pl->supported_interfaces); if (phy_interface_empty(interfaces)) { phylink_err(pl, "PHY has no common interfaces\n"); @@ -2685,12 +2693,12 @@ static phy_interface_t phylink_sfp_select_interface(struct phylink *pl, return interface; } - if (!test_bit(interface, pl->config->supported_interfaces)) { + if (!test_bit(interface, pl->supported_interfaces)) { phylink_err(pl, "selection of interface failed, SFP selected %s (%u) but MAC supports %*pbl\n", phy_modes(interface), interface, (int)PHY_INTERFACE_MODE_MAX, - pl->config->supported_interfaces); + pl->supported_interfaces); return PHY_INTERFACE_MODE_NA; } @@ -3577,14 +3585,14 @@ static int phylink_sfp_config_optical(struct phylink *pl) phylink_dbg(pl, "optical SFP: interfaces=[mac=%*pbl, sfp=%*pbl]\n", (int)PHY_INTERFACE_MODE_MAX, - pl->config->supported_interfaces, + pl->supported_interfaces, (int)PHY_INTERFACE_MODE_MAX, pl->sfp_interfaces); /* Find the union of the supported interfaces by the PCS/MAC and * the SFP module. */ - phy_interface_and(interfaces, pl->config->supported_interfaces, + phy_interface_and(interfaces, pl->supported_interfaces, pl->sfp_interfaces); if (phy_interface_empty(interfaces)) { phylink_err(pl, "unsupported SFP module: no common interface modes\n"); @@ -3730,7 +3738,7 @@ static int phylink_sfp_connect_phy(void *upstream, struct phy_device *phy) /* Set the PHY's host supported interfaces */ phy_interface_and(phy->host_interfaces, phylink_sfp_interfaces, - pl->config->supported_interfaces); + pl->supported_interfaces); /* Do the initial configuration */ return phylink_sfp_config_phy(pl, phy); From patchwork Sun Apr 6 22:13:56 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christian Marangi X-Patchwork-Id: 14039571 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 960C9C3600C for ; Sun, 6 Apr 2025 22:22:36 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender:List-Subscribe:List-Help :List-Post:List-Archive:List-Unsubscribe:List-Id:Content-Transfer-Encoding: MIME-Version:References:In-Reply-To:Message-ID:Date:Subject:To:From:Reply-To: Cc:Content-Type:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=ayn/+ArG131gi18wLCzFlJOt7i4mpT3rXpgfAV6sJtQ=; b=UZtVulmjwex1GNMhfinPP//Cn7 mPlTmc/CRH9wopWF7A3PM4EyLLGPAJ8RNkm+6sJeBrp/y+sdFE5R69ZuJX8dYMTlclRCDEvu+epHT I0pi/p+/A7161dgXVZSwjI8CZ3eqsyMuR/oND/8xwfIW1p24l4o+YBtiMyFIUVwHTfx5QaAOdYQ5Y teZIm+SouKANIJXC2sioFoPoTQvTaOLwzoKn5Gcq/BTM+jjn9ySYIlayWbFN329xyWihJJYcwbDsv KLIUnR9UTXK0MaDYpf53FCV4J0d3Ch3Yij7gFw0iSJbkFGRUrDcCiRHIVmr1U0aznaaZYniXAfV1F yMasTaPQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.98.1 #2 (Red Hat Linux)) id 1u1YNn-0000000FuMU-3uVz; Sun, 06 Apr 2025 22:22:27 +0000 Received: from mail-wm1-x329.google.com ([2a00:1450:4864:20::329]) by bombadil.infradead.org with esmtps (Exim 4.98.1 #2 (Red Hat Linux)) id 1u1YGf-0000000Fsv8-125R; Sun, 06 Apr 2025 22:15:06 +0000 Received: by mail-wm1-x329.google.com with SMTP id 5b1f17b1804b1-43cfba466b2so37474775e9.3; Sun, 06 Apr 2025 15:15:04 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1743977703; x=1744582503; darn=lists.infradead.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:from:to:cc:subject:date:message-id :reply-to; bh=ayn/+ArG131gi18wLCzFlJOt7i4mpT3rXpgfAV6sJtQ=; b=F2YMpcfpvww/9ICKMYexWe0TnbJ8Kbw0SRZSJpGAPxJvuEie7P6dUdz8Jk1DLOE2MB JVxhtDHQFrDrW3oanCgDiMrnEkUdgWh4//1ugt1PBtKRdPoYH6A5Xe4tX4zsxd9MFXUx 3qvudQQN31Of69dStMchnxd1Mw+AIeU9VhZ30acAMHDex08XxpmeGjG/bN48JGu+q8iv k4RLNJ3UZJtOoOCCobOSrfKFT4Y7JreKmAtQxxW2WX+A87N058nmCbNTtBr2cqQiu7MR gHltFp0SZJ/vj/M7KbQemaO6/9OYfT7JqqqqpxFaT3Jaz4MEb4Kv056ZINSCvk0kR9gO yLWQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1743977703; x=1744582503; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=ayn/+ArG131gi18wLCzFlJOt7i4mpT3rXpgfAV6sJtQ=; b=Qwe4dmgZmrPDkdAc1KjfW93zhUQ2JDYrYgW+5Tcvv18S6gnBh6tXm/+f1m/TgeXxVg WSIvnjufE38nSGLsuo4vgy7fpCYZ/8tBNYaHmyW/agnqiq2NH9WE7VMX32C1WhnE6wjn bYVzaSHZx0cFJLQScEXkEHG7iwGCrnPXbuR6q6v3I5rgzQFq5IgfxoLvUalAkgusLHTf N9HTWeFfd+FT0UfVXaKv9kdzv8126h/FOQn2VGzAINUOaBm/9v2oiwBw4dNsUBy9Tly7 wX4HPz57Vnifch3Wtja3rsOMGu0qRckpoyqJ/SRMps57YFWawhGJSMruwtV44UmU0Acu 9yXA== X-Forwarded-Encrypted: i=1; AJvYcCUrJoAJ13jQ7dMSi9qCCfWFVWK7UHzcnkNf8NH1PKKg7s05DI5R+8UPr3lo0mNVQwZ8D58TkjDGaTyUN7jcsLdT@lists.infradead.org, AJvYcCWApF+lLEKG3dziCE1mR2rZwdCBYwDnfXEnDbFSXOX3/yH2STzEWaVPEpXgwNAkCpKtmOI3hJoEnKWrOTzoi14=@lists.infradead.org X-Gm-Message-State: AOJu0YxaitglYUgI4X59O4ClzIYG/BMPq8uiJZ6K6mLfFRcFgpZ5cXZR Jr3cNUQqd6QjPaBCNIRlHsvHsCk+IDv0+BsMAiu7RRUUC/r9OpJv X-Gm-Gg: ASbGnctFj18oLlyG4x3ELrN59hUVQEquSaTxrTRExsvE5r597sILB9/+2iN4dhTeyFo EeLho9vAXAaAOmOIKpcmUYE+OAOjwrNzWpDeB0qgp+rmD/qMm7VroVqLHAN1JAZTnuuMSteKaQx fo1fOTfopm3rg431nFnayqrk033MYJBFYTpoAII+T8h00J1D7ipGyEKIXFaI1/FheX0Y3Y2MVRA 2DPMdf4FfM3mUsz0sjDYLN9fVI/XY3gyeh0RQpteCd3bX8FcemO12DbYTmMGjW4Ct+WDXMZ6fTy BKNn57M7TxuEHXBSJap/HUrVbUXSnCwCzs4PugXIAJbBfDAZvgLi+l75oM3+17vebmuxAgKI8VB TszxMczn67Aeldw== X-Google-Smtp-Source: AGHT+IENfMJTLXOWwcQUAP+VYmlM77Qj1I7980ItCU7kcoUNHVy1gAOdc18HDYP2esin/LYBB6Ur7g== X-Received: by 2002:a05:600c:1c07:b0:43d:45a:8fc1 with SMTP id 5b1f17b1804b1-43ecf84287dmr98127335e9.4.1743977703199; Sun, 06 Apr 2025 15:15:03 -0700 (PDT) Received: from localhost.localdomain (93-34-88-225.ip49.fastwebnet.it. [93.34.88.225]) by smtp.googlemail.com with ESMTPSA id 5b1f17b1804b1-43ec366aa29sm111517055e9.39.2025.04.06.15.15.02 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 06 Apr 2025 15:15:02 -0700 (PDT) From: Christian Marangi To: Andrew Lunn , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Rob Herring , Krzysztof Kozlowski , Conor Dooley , Lorenzo Bianconi , Heiner Kallweit , Russell King , Philipp Zabel , Christian Marangi , Daniel Golle , "Russell King (Oracle)" , netdev@vger.kernel.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-mediatek@lists.infradead.org, "Lei Wei (QUIC)" Subject: [RFC PATCH net-next v2 03/11] net: phy: introduce phy_interface_copy helper Date: Mon, 7 Apr 2025 00:13:56 +0200 Message-ID: <20250406221423.9723-4-ansuelsmth@gmail.com> X-Mailer: git-send-email 2.48.1 In-Reply-To: <20250406221423.9723-1-ansuelsmth@gmail.com> References: <20250406221423.9723-1-ansuelsmth@gmail.com> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20250406_151505_284758_98EF2B2B X-CRM114-Status: GOOD ( 11.38 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org Introduce phy_interface_copy helper as a shorthand to copy the PHY interface bitmap to a different location. This is useful if a PHY interface bitmap needs to be stored in a different variable and needs to be reset to an original value saved in a different bitmap. Signed-off-by: Christian Marangi --- include/linux/phy.h | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/include/linux/phy.h b/include/linux/phy.h index a2bfae80c449..65c520e556aa 100644 --- a/include/linux/phy.h +++ b/include/linux/phy.h @@ -173,6 +173,11 @@ static inline void phy_interface_or(unsigned long *dst, const unsigned long *a, bitmap_or(dst, a, b, PHY_INTERFACE_MODE_MAX); } +static inline void phy_interface_copy(unsigned long *dst, const unsigned long *src) +{ + bitmap_copy(dst, src, PHY_INTERFACE_MODE_MAX); +} + static inline void phy_interface_set_rgmii(unsigned long *intf) { __set_bit(PHY_INTERFACE_MODE_RGMII, intf); From patchwork Sun Apr 6 22:13:57 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christian Marangi X-Patchwork-Id: 14039572 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id CEC52C36002 for ; Sun, 6 Apr 2025 22:24:29 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender:List-Subscribe:List-Help :List-Post:List-Archive:List-Unsubscribe:List-Id:Content-Transfer-Encoding: MIME-Version:References:In-Reply-To:Message-ID:Date:Subject:To:From:Reply-To: Cc:Content-Type:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=5SVzT3jCIpt/kTPAnKwWGxsSgtoaKNGf4OiBXndvyMw=; b=s1CZwj2BzYWhBj/zZdC0JQ09vY pILLjWObLp40US/DIvT3DyETmasZG7h3VfoJK+8aG1KMmluxtiwbGp2l0q7ORgABLCSMX8ozEVPOq ZVXB1pBw8dPQDwzQKXYh9EecxirWFNpn7gp4k5XknW1IcsK9kv+WwXFOujwsvpc4szW8Etn5oOzem 6e8FDq6a6818ey6ehDoMelEWkIE2px3Uv24m5E9XkQOV0+yZpqWATVhEVwtIcMAdHjm7s3gpoi9I4 6xXzRp5ICrS/GIATvJr707NaYG86yIej5dHbZNkMCU+BMJVvzffn3KZ77UdzN6+8ZjsQDnNeyNr8g Cy8JCh1A==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.98.1 #2 (Red Hat Linux)) id 1u1YPa-0000000Fugg-481p; Sun, 06 Apr 2025 22:24:18 +0000 Received: from mail-wr1-x433.google.com ([2a00:1450:4864:20::433]) by bombadil.infradead.org with esmtps (Exim 4.98.1 #2 (Red Hat Linux)) id 1u1YGg-0000000FsvY-1aXK; Sun, 06 Apr 2025 22:15:07 +0000 Received: by mail-wr1-x433.google.com with SMTP id ffacd0b85a97d-39c14016868so3301874f8f.1; Sun, 06 Apr 2025 15:15:06 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1743977705; x=1744582505; darn=lists.infradead.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:from:to:cc:subject:date:message-id :reply-to; bh=5SVzT3jCIpt/kTPAnKwWGxsSgtoaKNGf4OiBXndvyMw=; b=M+xyb3de01BNx1Uv5MQqUmrryAdb23V51/OfS8RY/u0GreGvfw4c6LLTI+zRcIbDYj m6ZkNqyjzbmSsNyo49osuXzx/zPdQbpuRsYgvQBJsn63J44ZkXNFU5sikFgrd+1BbVy8 bc+FV9N2QWSjK4Ulmq6WFF247ILwU6L6m7LiMXABMhE3sH+wmNbAgDDU22HmTaNZJQZE FsCepOcBuWJDP+WyGYzDd2tLXVOnkG6qTtQiTieZT5m1xLE60+xlLmebheWDdVRgbTOb Ec39WMLM2FXoPT9UxpYx6AX2Qwu67hZfiz6jWMmfx1xP+6P2JZacONhCLASBKGl+LbG+ ULUA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1743977705; x=1744582505; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=5SVzT3jCIpt/kTPAnKwWGxsSgtoaKNGf4OiBXndvyMw=; b=Su/jFaDm/NAgbpuhwewq4pt4HrBgZyjKYz5CveEF1MhqTwsld1MkFiLeVsJwU7YJoa hrs7G96WSOVrEbcUHmT/yMknvf1petDBGr4FmXgw2U0m1zsJzykvna5wjIIEhRkLhVz3 CL84PqjGcLmow9hKiYmPdvQqhK5W1zDD/I3cbi419YlOJr0M7hYZIZxcbIegD2WTesaA BCdYABmUbsiUi5vvM4a4XQct74E8tEYdSXjUhEGzAUKNbd17M5hxzxFwzuXGlcMQb0zo eGy1dgDaDvpgoKQ+2GxZaXQZuye5AIXl4xFYYpL2pGz714AOf5IaLIdXk4hPbjSBEKQL tL9Q== X-Forwarded-Encrypted: i=1; AJvYcCVr44QJdtH7LO8OL7lH1MO8CskYBiBOJMxfxoyzHmO2MW5rqeARwoD+NhCgSFc2XWiIHe46qZDEqnBTfyMyYDue@lists.infradead.org, AJvYcCX7A+YMwAga64qmMo5nYlUxNohVYs8sAvLsrshyifm4hLRWh/B6I2XjOdaGfmUHtbZ/XoH2p/OMel58uy7hYOo=@lists.infradead.org X-Gm-Message-State: AOJu0Yy5/DN4uCCfLPnntT24vbZ+JVzi/yg8wM6XM1DIz1akOu/A+4xB q5UMHVHrGr55gZBtzkM0Nm6HCJmvfhGn7ZKlbcfV7AGJQM1uArto X-Gm-Gg: ASbGncsf/9aD3fQv7LidwwnlrFDbsC2HOH6STopZn16IbVGUmnGg7K7Swgn1StzXEO6 f2BTmvxO1Jb8M9sqkOMWNjv1uqaTwjPbJTR7XUGWHPt3rZxbDweXRCpAcynzbW8lLgnsmLDlSDY ijBWoNK5wvZe8lIb++TN30cXSNy1EskRfKWlHfFMx2Ecap1ej7qhAU3DfppgOhFyKqPSU9A6ZaU qSZRxcMbEBAEwXOlIYmHLM/igdsXnkJebv+sBunf0rJo811kznXxap8SqiGnYGrNXPsYUFp8b9K uplxJT1rKI/nK/wKPsQobty0pZok0VZdgFw1fvFznEWSXrtcspM9C+YgnzX0Vfej4MGmAVTbrE5 Nw65nu/3tNkthxg== X-Google-Smtp-Source: AGHT+IFhhEBdDIehuxH/183ggtu2Kb0/mVb91yA/cUDjgY3KEJVITCWD/N41eSwqTm2RsECbNT7+qA== X-Received: by 2002:adf:b644:0:b0:39c:1257:cd40 with SMTP id ffacd0b85a97d-39d14663109mr5731160f8f.58.1743977704555; Sun, 06 Apr 2025 15:15:04 -0700 (PDT) Received: from localhost.localdomain (93-34-88-225.ip49.fastwebnet.it. [93.34.88.225]) by smtp.googlemail.com with ESMTPSA id 5b1f17b1804b1-43ec366aa29sm111517055e9.39.2025.04.06.15.15.03 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 06 Apr 2025 15:15:04 -0700 (PDT) From: Christian Marangi To: Andrew Lunn , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Rob Herring , Krzysztof Kozlowski , Conor Dooley , Lorenzo Bianconi , Heiner Kallweit , Russell King , Philipp Zabel , Christian Marangi , Daniel Golle , "Russell King (Oracle)" , netdev@vger.kernel.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-mediatek@lists.infradead.org, "Lei Wei (QUIC)" Subject: [RFC PATCH net-next v2 04/11] net: phylink: introduce internal phylink PCS handling Date: Mon, 7 Apr 2025 00:13:57 +0200 Message-ID: <20250406221423.9723-5-ansuelsmth@gmail.com> X-Mailer: git-send-email 2.48.1 In-Reply-To: <20250406221423.9723-1-ansuelsmth@gmail.com> References: <20250406221423.9723-1-ansuelsmth@gmail.com> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20250406_151506_450991_87BFD2F6 X-CRM114-Status: GOOD ( 39.75 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org Introduce internal handling of PCS for phylink. This is an alternative to .mac_select_pcs that moves the selection logic of the PCS entirely to phylink with the usage of supported_interface value in the PCS struct. MAC should now provide an array of available PCS in phylink_config in .available_pcs and fill the .num_available_pcs with the number of elements in the array. MAC should also define a new bitmap, pcs_interfaces, in phylink_config to define for what interface mode a dedicated PCS is required. On phylink_create() this array is parsed and a linked list of PCS is created based on the PCS passed in phylink_config. Also the supported_interface value in phylink struct is updated with the new supported_interface from the provided PCS. On phylink_start() every PCS in phylink PCS list gets attached to the phylink instance. This is done by setting the phylink value in phylink_pcs struct to the phylink instance. On phylink_stop(), every PCS in phylink PCS list is detached from the phylink instance. This is done by setting the phylink value in phylink_pcs struct to NULL. On phylink_stop(), every PCS in phylink PCS list is removed from the list. phylink_validate_mac_and_pcs(), phylink_major_config() and phylink_inband_caps() are updated to support this new implementation with the PCS list stored in phylink. They will make use of phylink_validate_pcs_interface() that will loop for every PCS in the phylink PCS available list and find one that supports the passed interface. phylink_validate_pcs_interface() apply the same logic of .mac_select_pcs where if a supported_interface value is not set for the PCS struct, then it's assumed every interface is supported. It's required for a MAC that implement either a .mac_select_pcs or make use of the PCS list implementation. Implementing both will result in a fail on MAC/PCS validation. phylink value in phylink_pcs struct with this implementation is used to track from PCS side when it's attached to a phylink instance. PCS driver will make use of this information to correctly detach from a phylink instance if needed. The .mac_select_pcs implementation is not changed but it's expected that every MAC driver migrates to the new implementation to later deprecate and remove .mac_select_pcs. Signed-off-by: Christian Marangi --- drivers/net/phy/phylink.c | 147 +++++++++++++++++++++++++++++++++----- include/linux/phylink.h | 10 +++ 2 files changed, 139 insertions(+), 18 deletions(-) diff --git a/drivers/net/phy/phylink.c b/drivers/net/phy/phylink.c index 6a7d6e3768da..f889fced379d 100644 --- a/drivers/net/phy/phylink.c +++ b/drivers/net/phy/phylink.c @@ -66,6 +66,9 @@ struct phylink { /* The link configuration settings */ struct phylink_link_state link_config; + /* List of available PCS */ + struct list_head pcs_list; + /* What interface are supported by the current link. * Can change on removal or addition of new PCS. */ @@ -150,6 +153,8 @@ static const phy_interface_t phylink_sfp_interface_preference[] = { static DECLARE_PHY_INTERFACE_MASK(phylink_sfp_interfaces); +static void phylink_run_resolve(struct phylink *pl); + /** * phylink_set_port_modes() - set the port type modes in the ethtool mask * @mask: ethtool link mode mask @@ -505,22 +510,59 @@ static void phylink_validate_mask_caps(unsigned long *supported, linkmode_and(state->advertising, state->advertising, mask); } +static int phylink_validate_pcs_interface(struct phylink_pcs *pcs, + phy_interface_t interface) +{ + /* If PCS define an empty supported_interfaces value, assume + * all interface are supported. + */ + if (phy_interface_empty(pcs->supported_interfaces)) + return 0; + + /* Ensure that this PCS supports the interface mode */ + if (!test_bit(interface, pcs->supported_interfaces)) + return -EINVAL; + + return 0; +} + static int phylink_validate_mac_and_pcs(struct phylink *pl, unsigned long *supported, struct phylink_link_state *state) { - struct phylink_pcs *pcs = NULL; unsigned long capabilities; + struct phylink_pcs *pcs; + bool pcs_found = false; int ret; /* Get the PCS for this interface mode */ if (pl->mac_ops->mac_select_pcs) { + /* Make sure either PCS internal validation or .mac_select_pcs + * is used. Return error if both are defined. + */ + if (!list_empty(&pl->pcs_list)) { + phylink_err(pl, "either phylink_pcs_add() or .mac_select_pcs must be used\n"); + return -EINVAL; + } + pcs = pl->mac_ops->mac_select_pcs(pl->config, state->interface); if (IS_ERR(pcs)) return PTR_ERR(pcs); + + pcs_found = !!pcs; + } else { + /* Check every assigned PCS and search for one that supports + * the interface. + */ + list_for_each_entry(pcs, &pl->pcs_list, list) { + if (!phylink_validate_pcs_interface(pcs, state->interface)) { + pcs_found = true; + break; + } + } } - if (pcs) { + if (pcs_found) { /* The PCS, if present, must be setup before phylink_create() * has been called. If the ops is not initialised, print an * error and backtrace rather than oopsing the kernel. @@ -532,13 +574,10 @@ static int phylink_validate_mac_and_pcs(struct phylink *pl, return -EINVAL; } - /* Ensure that this PCS supports the interface which the MAC - * returned it for. It is an error for the MAC to return a PCS - * that does not support the interface mode. - */ - if (!phy_interface_empty(pcs->supported_interfaces) && - !test_bit(state->interface, pcs->supported_interfaces)) { - phylink_err(pl, "MAC returned PCS which does not support %s\n", + /* Recheck PCS to handle legacy way for .mac_select_pcs */ + ret = phylink_validate_pcs_interface(pcs, state->interface); + if (ret) { + phylink_err(pl, "selected PCS does not support %s\n", phy_modes(state->interface)); return -EINVAL; } @@ -943,12 +982,22 @@ static unsigned int phylink_inband_caps(struct phylink *pl, phy_interface_t interface) { struct phylink_pcs *pcs; + bool pcs_found = false; - if (!pl->mac_ops->mac_select_pcs) - return 0; + if (pl->mac_ops->mac_select_pcs) { + pcs = pl->mac_ops->mac_select_pcs(pl->config, + interface); + pcs_found = !!pcs; + } else { + list_for_each_entry(pcs, &pl->pcs_list, list) { + if (!phylink_validate_pcs_interface(pcs, interface)) { + pcs_found = true; + break; + } + } + } - pcs = pl->mac_ops->mac_select_pcs(pl->config, interface); - if (!pcs) + if (!pcs_found) return 0; return phylink_pcs_inband_caps(pcs, interface); @@ -1234,10 +1283,36 @@ static void phylink_major_config(struct phylink *pl, bool restart, pl->major_config_failed = true; return; } + /* Find a PCS in available PCS list for the requested interface. + * This doesn't overwrite the previous .mac_select_pcs as either + * .mac_select_pcs or PCS list implementation are permitted. + * + * Skip searching if the MAC doesn't require a dedicaed PCS for + * the requested interface. + */ + } else if (test_bit(state->interface, pl->config->pcs_interfaces)) { + bool pcs_found = false; + + list_for_each_entry(pcs, &pl->pcs_list, list) { + if (!phylink_validate_pcs_interface(pcs, + state->interface)) { + pcs_found = true; + break; + } + } + + if (!pcs_found) { + phylink_err(pl, + "couldn't find a PCS for %s\n", + phy_modes(state->interface)); - pcs_changed = pl->pcs != pcs; + pl->major_config_failed = true; + return; + } } + pcs_changed = pl->pcs != pcs; + phylink_pcs_neg_mode(pl, pcs, state->interface, state->advertising); phylink_dbg(pl, "major config, active %s/%s/%s\n", @@ -1264,10 +1339,12 @@ static void phylink_major_config(struct phylink *pl, bool restart, if (pcs_changed) { phylink_pcs_disable(pl->pcs); - if (pl->pcs) - pl->pcs->phylink = NULL; + if (pl->mac_ops->mac_select_pcs) { + if (pl->pcs) + pl->pcs->phylink = NULL; - pcs->phylink = pl; + pcs->phylink = pl; + } pl->pcs = pcs; } @@ -1803,8 +1880,9 @@ struct phylink *phylink_create(struct phylink_config *config, phy_interface_t iface, const struct phylink_mac_ops *mac_ops) { + struct phylink_pcs *pcs; struct phylink *pl; - int ret; + int i, ret; /* Validate the supplied configuration */ if (phy_interface_empty(config->supported_interfaces)) { @@ -1819,9 +1897,21 @@ struct phylink *phylink_create(struct phylink_config *config, mutex_init(&pl->state_mutex); INIT_WORK(&pl->resolve, phylink_resolve); + INIT_LIST_HEAD(&pl->pcs_list); + + /* Fill the PCS list with available PCS from phylink config */ + for (i = 0; i < config->num_available_pcs; i++) { + pcs = config->available_pcs[i]; + + list_add(&pcs->list, &pl->pcs_list); + } phy_interface_copy(pl->supported_interfaces, config->supported_interfaces); + list_for_each_entry(pcs, &pl->pcs_list, list) + phy_interface_or(pl->supported_interfaces, + pl->supported_interfaces, + pcs->supported_interfaces); pl->config = config; if (config->type == PHYLINK_NETDEV) { @@ -1900,10 +1990,16 @@ EXPORT_SYMBOL_GPL(phylink_create); */ void phylink_destroy(struct phylink *pl) { + struct phylink_pcs *pcs, *tmp; + sfp_bus_del_upstream(pl->sfp_bus); if (pl->link_gpio) gpiod_put(pl->link_gpio); + /* Remove every PCS from phylink PCS list */ + list_for_each_entry_safe(pcs, tmp, &pl->pcs_list, list) + list_del(&pcs->list); + cancel_work_sync(&pl->resolve); kfree(pl); } @@ -2380,6 +2476,7 @@ static irqreturn_t phylink_link_handler(int irq, void *data) */ void phylink_start(struct phylink *pl) { + struct phylink_pcs *pcs; bool poll = false; ASSERT_RTNL(); @@ -2406,6 +2503,10 @@ void phylink_start(struct phylink *pl) pl->pcs_state = PCS_STATE_STARTED; + /* link available PCS to phylink struct */ + list_for_each_entry(pcs, &pl->pcs_list, list) + pcs->phylink = pl; + phylink_enable_and_run_resolve(pl, PHYLINK_DISABLE_STOPPED); if (pl->cfg_link_an_mode == MLO_AN_FIXED && pl->link_gpio) { @@ -2450,6 +2551,8 @@ EXPORT_SYMBOL_GPL(phylink_start); */ void phylink_stop(struct phylink *pl) { + struct phylink_pcs *pcs; + ASSERT_RTNL(); if (pl->sfp_bus) @@ -2467,6 +2570,14 @@ void phylink_stop(struct phylink *pl) pl->pcs_state = PCS_STATE_DOWN; phylink_pcs_disable(pl->pcs); + + /* Drop link between phylink and PCS */ + list_for_each_entry(pcs, &pl->pcs_list, list) + pcs->phylink = NULL; + + /* Restore original supported interfaces */ + phy_interface_copy(pl->supported_interfaces, + pl->config->supported_interfaces); } EXPORT_SYMBOL_GPL(phylink_stop); diff --git a/include/linux/phylink.h b/include/linux/phylink.h index 1f5773ab5660..7d69e6a44f68 100644 --- a/include/linux/phylink.h +++ b/include/linux/phylink.h @@ -150,12 +150,16 @@ enum phylink_op_type { * if MAC link is at %MLO_AN_FIXED mode. * @supported_interfaces: bitmap describing which PHY_INTERFACE_MODE_xxx * are supported by the MAC/PCS. + * @pcs_interfaces: bitmap describing for which PHY_INTERFACE_MODE_xxx a + * dedicated PCS is required. * @lpi_interfaces: bitmap describing which PHY interface modes can support * LPI signalling. * @mac_capabilities: MAC pause/speed/duplex capabilities. * @lpi_capabilities: MAC speeds which can support LPI signalling * @lpi_timer_default: Default EEE LPI timer setting. * @eee_enabled_default: If set, EEE will be enabled by phylink at creation time + * @available_pcs: array of available phylink_pcs PCS + * @num_available_pcs: num of available phylink_pcs PCS */ struct phylink_config { struct device *dev; @@ -168,11 +172,14 @@ struct phylink_config { void (*get_fixed_state)(struct phylink_config *config, struct phylink_link_state *state); DECLARE_PHY_INTERFACE_MASK(supported_interfaces); + DECLARE_PHY_INTERFACE_MASK(pcs_interfaces); DECLARE_PHY_INTERFACE_MASK(lpi_interfaces); unsigned long mac_capabilities; unsigned long lpi_capabilities; u32 lpi_timer_default; bool eee_enabled_default; + struct phylink_pcs **available_pcs; + unsigned int num_available_pcs; }; void phylink_limit_mac_speed(struct phylink_config *config, u32 max_speed); @@ -460,6 +467,9 @@ struct phylink_pcs { struct phylink *phylink; bool poll; bool rxc_always_on; + + /* private: */ + struct list_head list; }; /** From patchwork Sun Apr 6 22:13:58 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christian Marangi X-Patchwork-Id: 14039576 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id B9D56C3600C for ; Sun, 6 Apr 2025 22:26:20 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender:List-Subscribe:List-Help :List-Post:List-Archive:List-Unsubscribe:List-Id:Content-Transfer-Encoding: MIME-Version:References:In-Reply-To:Message-ID:Date:Subject:To:From:Reply-To: Cc:Content-Type:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=dHvlV+lAo07PEsn7Y5rgyOxBhBSPObcKBZUiEs7jo8c=; b=rZGBsX1IGCZCU4V1L+tN4Yka4z WPY3F9S7zii/vgH8jHPGjXuXhGGSENibLOedM/nwZOL9AgMKHigF5uEOl26/4XJdKdSTAaEjgWT4u S4I+0Rqg4Po4j3CmeeegdeiBKgRqmnBF+rP0Mp5aqZuS+ipGFySxrAv7HcV/+ROz/reyGaD8ju1UU q5B9dghz+kymocH0VuFf5384Mp1YVFU14IhhCaOXwb6qNP7+DCaskMnCjxrvRalN+Itngt/KWLOgU aPQLB7/ED5IC1aKOFX0MLFSSq8aUiRPR55A4wChFnEyZw1i7JKFdH08WmK2kzJ3D6wKydSlCDlWJt tC1q1Btw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.98.1 #2 (Red Hat Linux)) id 1u1YRO-0000000Fv2P-1LQe; Sun, 06 Apr 2025 22:26:10 +0000 Received: from mail-wm1-x333.google.com ([2a00:1450:4864:20::333]) by bombadil.infradead.org with esmtps (Exim 4.98.1 #2 (Red Hat Linux)) id 1u1YGh-0000000Fsvy-2NzG; Sun, 06 Apr 2025 22:15:08 +0000 Received: by mail-wm1-x333.google.com with SMTP id 5b1f17b1804b1-43cf680d351so27472145e9.0; Sun, 06 Apr 2025 15:15:07 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1743977706; x=1744582506; darn=lists.infradead.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:from:to:cc:subject:date:message-id :reply-to; bh=dHvlV+lAo07PEsn7Y5rgyOxBhBSPObcKBZUiEs7jo8c=; b=gEUyNChPf7ZzPGZkr+UEDVQQFozAHHNRVK97nkYCqUU0QQP9dpB905SGkFW/WC3Bam gdZRGSLi+AOfk3EL8AhChv9W2rbq5iTSWCHaNlrY82EyU9zCk1jdUUghlTc/3WdkrQQM iKTu8yjAHObcvPReTN948pV2ZW/GckTkk5jA5QSq+X/AxkWcW1E8PWJ+t6B7VCbvda+Z Rx+DZWdhDeYEQpYc1lrw2nkNs/i4d3dr3Rx23W93d156ItPf1at4AynGvGYFvs3S8DgL H63yF+ap9LjG9izy+Br3A4cZSjq7TQ/ct6iS+N1FtMkYlete2TrPWvoYdhgLQMKBjyg1 Ihvw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1743977706; x=1744582506; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=dHvlV+lAo07PEsn7Y5rgyOxBhBSPObcKBZUiEs7jo8c=; b=ewWDNTtvgGmKGACrset1Av1TiZcmmbhUWtlqrw2YrG4TzN05zogTAF97V+vi8/mQC/ jvCZPKIRBU9ZOmUEaJ0rDKocu/z0in60VFwGhuuve+Pz0UXKDtJq5s2WLg4Bx0kAQ1d1 BqwMx1PMnJYdyrzJ9RAitgGVsFPJYYk77qzg17hMTgfaempctzSA5K5k5a/03GG32Uju 4uBaGnqz3IS0Uz6M2ckMDDPB7bDGMq/aG2zzsGXwtR6EEPwZrgG1ImdQZLXdoRxJNzWf pZqmOUKx/VYIbajreDJ7waKcyu67F/UcZRa5iKXuRCdujOJ56ydFOY0DpG+mqfWJ4aM1 NwNg== X-Forwarded-Encrypted: i=1; AJvYcCV3mpbCscA2zl7PKhWTO7XQJojpkF12DHXd8or9F5gC70+pbvyPnFGoTqWcWFT4/zmsBKWHGCjPUcHmLJZrcyk=@lists.infradead.org, AJvYcCXslmdGuw3lvBJsjjLepGCeSR8DsY8vIr6S9wmpQTEpE+0RCFk8UB+AsVLC8Kzuc1S9jYiOqOULXc3JmgC+UoDO@lists.infradead.org X-Gm-Message-State: AOJu0Yzm8Vru3j3FkNh0jvClEl7ei2Wnm7yruIYbjCpU6unmuVzRLYtA f4BofCJii5SwloPqKlAnn7o4Er66uTrpCkK1mHco4wAfT6KhhpKE X-Gm-Gg: ASbGncvzN3NS34Nw/0WD4Q1n3pWLl9SX1iB+qCGSHE5OdoyEAMwjcE6jn6dpqpEkWN6 tklTuLP70g/hm6YTYBKNHpTv30e++NZgL3idYZ30eZViziVDL6TuGfeTvT70Q5p2Ymx106ux8Zd eb2i4FKIL+Llu+INLx0ntOB5cLxT7ldeAUNmDFLSrQDrD4bGADtrNa9lP0nYRiCijILdPXl6hog RgzbK083ntqWCpRBbZIp9XbzXUMtWTav8LTJdvN75ft8uXeMyL1q2awoqIMFI9Jifjj3NHfDU8X TSMP0rM0lbcYsPzgfBOx8hkzXUR4d4GdklJ+PFS0De8I5dNFbdvmATSUUAtWExxnGVp+VRSBsiY Mv+qE/VPCYAJvLoOYVufvQv/R X-Google-Smtp-Source: AGHT+IFRTaVaadmWLO6m7IMNHXw2Yzhsjhiip2R7g0xWIMlaJ4D41OkBeAWnSLDQM4PNIiZljl1KyQ== X-Received: by 2002:a05:600c:1e1b:b0:43d:16a0:d98d with SMTP id 5b1f17b1804b1-43eceee3375mr103173255e9.15.1743977705889; Sun, 06 Apr 2025 15:15:05 -0700 (PDT) Received: from localhost.localdomain (93-34-88-225.ip49.fastwebnet.it. [93.34.88.225]) by smtp.googlemail.com with ESMTPSA id 5b1f17b1804b1-43ec366aa29sm111517055e9.39.2025.04.06.15.15.04 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 06 Apr 2025 15:15:05 -0700 (PDT) From: Christian Marangi To: Andrew Lunn , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Rob Herring , Krzysztof Kozlowski , Conor Dooley , Lorenzo Bianconi , Heiner Kallweit , Russell King , Philipp Zabel , Christian Marangi , Daniel Golle , "Russell King (Oracle)" , netdev@vger.kernel.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-mediatek@lists.infradead.org, "Lei Wei (QUIC)" Subject: [RFC PATCH net-next v2 05/11] net: phylink: add phylink_release_pcs() to externally release a PCS Date: Mon, 7 Apr 2025 00:13:58 +0200 Message-ID: <20250406221423.9723-6-ansuelsmth@gmail.com> X-Mailer: git-send-email 2.48.1 In-Reply-To: <20250406221423.9723-1-ansuelsmth@gmail.com> References: <20250406221423.9723-1-ansuelsmth@gmail.com> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20250406_151507_611979_1C683752 X-CRM114-Status: GOOD ( 25.90 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org Add phylink_release_pcs() to externally release a PCS from a phylink instance. This can be used to handle case when a single PCS needs to be removed and the phylink instance needs to be refreshed. On calling phylink_release_pcs(), the PCS will be removed from the phylink internal PCS list and the phylink supported_interfaces value is reparsed with the remaining PCS interfaces. Also a phylink resolve is triggered to handle the PCS removal. It's also added to phylink a flag to make phylink resolve reconfigure the interface mode (even if it didn't change). This is needed to handle the special case when the current PCS used by phylink is removed and a major_config is needed to propagae the configuration change. With this option enabled we also force mac_config even if the PHY link is not up for the in-band case. Signed-off-by: Christian Marangi --- drivers/net/phy/phylink.c | 58 ++++++++++++++++++++++++++++++++++++++- include/linux/phylink.h | 2 ++ 2 files changed, 59 insertions(+), 1 deletion(-) diff --git a/drivers/net/phy/phylink.c b/drivers/net/phy/phylink.c index f889fced379d..e6bb6e5cb63e 100644 --- a/drivers/net/phy/phylink.c +++ b/drivers/net/phy/phylink.c @@ -90,6 +90,7 @@ struct phylink { bool link_failed; bool major_config_failed; + bool reconfig_interface; bool mac_supports_eee_ops; bool mac_supports_eee; bool phy_enable_tx_lpi; @@ -901,6 +902,55 @@ static void phylink_resolve_an_pause(struct phylink_link_state *state) } } +/** + * phylink_release_pcs - Removes a PCS from the phylink PCS available list + * @pcs: a pointer to the phylink_pcs struct to be released + * + * This function release a PCS from the phylink PCS available list if + * actually in use. It also refreshes the supported interfaces of the + * phylink instance by copying the supported interfaces from the phylink + * conf and merging the supported interfaces of the remaining available PCS + * in the list and trigger a resolve. + */ +void phylink_release_pcs(struct phylink_pcs *pcs) +{ + struct phylink *pl; + + ASSERT_RTNL(); + + pl = pcs->phylink; + if (!pl) + return; + + list_del(&pcs->list); + pcs->phylink = NULL; + + /* Check if we are removing the PCS currently + * in use by phylink. If this is the case, + * force phylink resolve to reconfigure the interface + * mode and set the phylink PCS to NULL. + */ + if (pl->pcs == pcs) { + mutex_lock(&pl->state_mutex); + + pl->reconfig_interface = true; + pl->pcs = NULL; + + mutex_unlock(&pl->state_mutex); + } + + /* Refresh supported interfaces */ + phy_interface_copy(pl->supported_interfaces, + pl->config->supported_interfaces); + list_for_each_entry(pcs, &pl->pcs_list, list) + phy_interface_or(pl->supported_interfaces, + pl->supported_interfaces, + pcs->supported_interfaces); + + phylink_run_resolve(pl); +} +EXPORT_SYMBOL_GPL(phylink_release_pcs); + static unsigned int phylink_pcs_inband_caps(struct phylink_pcs *pcs, phy_interface_t interface) { @@ -1694,6 +1744,10 @@ static void phylink_resolve(struct work_struct *w) if (pl->phydev) link_state.link &= pl->phy_state.link; + /* Force mac_config if we need to reconfig the interface */ + if (pl->reconfig_interface) + mac_config = true; + /* Only update if the PHY link is up */ if (pl->phydev && pl->phy_state.link) { /* If the interface has changed, force a link down @@ -1728,7 +1782,8 @@ static void phylink_resolve(struct work_struct *w) phylink_apply_manual_flow(pl, &link_state); if (mac_config) { - if (link_state.interface != pl->link_config.interface) { + if (link_state.interface != pl->link_config.interface || + pl->reconfig_interface) { /* The interface has changed, force the link down and * then reconfigure. */ @@ -1738,6 +1793,7 @@ static void phylink_resolve(struct work_struct *w) } phylink_major_config(pl, false, &link_state); pl->link_config.interface = link_state.interface; + pl->reconfig_interface = false; } } diff --git a/include/linux/phylink.h b/include/linux/phylink.h index 7d69e6a44f68..09e19859a71c 100644 --- a/include/linux/phylink.h +++ b/include/linux/phylink.h @@ -708,6 +708,8 @@ void phylink_disconnect_phy(struct phylink *); int phylink_set_fixed_link(struct phylink *, const struct phylink_link_state *); +void phylink_release_pcs(struct phylink_pcs *pcs); + void phylink_mac_change(struct phylink *, bool up); void phylink_pcs_change(struct phylink_pcs *, bool up); From patchwork Sun Apr 6 22:13:59 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christian Marangi X-Patchwork-Id: 14039577 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id A06F0C3600C for ; Sun, 6 Apr 2025 22:28:11 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender:List-Subscribe:List-Help :List-Post:List-Archive:List-Unsubscribe:List-Id:Content-Transfer-Encoding: MIME-Version:References:In-Reply-To:Message-ID:Date:Subject:To:From:Reply-To: Cc:Content-Type:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=c9xqHcI6eEdBoYc8sq0yd0T9xMnWM8DZJfsMIYVhLZU=; b=2YMV8hW14U3D1P3NhtKwf0Rhzt 2B73BjGbIm8zN9t0ZVVtJMFCu9fgmLhUV4oc7SKh1xYhS2MKpvWtf/rMHgiO5yIaLuWViTz93ClYX 8HZo9gN7AK69MtpwoIiVLd4+aTMa9J4zkE2i+hXok771rqv+ZUBLa84WUfqwGD2fLloF3nuVjK2Zu HA5WA/8QbbpBsWYXq4KtwUpa/nlXxzGJVJwQ/efCvCr+NrtODtBb0kRzKoqz6KO7NI/5YnkckmnyB YUnO5+c3zP5MQQLNleaTfTvNtO1Dux+6d/aMjfrG/c/tGrYI2h7xFEaTexcR+eJFoMAz4yopA6/qr cWXJCg7w==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.98.1 #2 (Red Hat Linux)) id 1u1YTA-0000000FvOt-2B6I; Sun, 06 Apr 2025 22:28:00 +0000 Received: from mail-wm1-x32f.google.com ([2a00:1450:4864:20::32f]) by bombadil.infradead.org with esmtps (Exim 4.98.1 #2 (Red Hat Linux)) id 1u1YGi-0000000FswO-3zdt; Sun, 06 Apr 2025 22:15:10 +0000 Received: by mail-wm1-x32f.google.com with SMTP id 5b1f17b1804b1-43ede096d73so11203045e9.2; Sun, 06 Apr 2025 15:15:08 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1743977707; x=1744582507; darn=lists.infradead.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:from:to:cc:subject:date:message-id :reply-to; bh=c9xqHcI6eEdBoYc8sq0yd0T9xMnWM8DZJfsMIYVhLZU=; b=gadB/DIu96PHnFaeyRg6tnTz8A8gVIkSw6jbmZvZVuPhYx3Dh2O+oFlFy50Ay8WNXS QTlEB2RNzTNeEwFqIBYcpsIObmAWezje0L5W2O2vVqKX6co2qpig0nA34v9YSZBtMhhd IRUlTHmlRol076Z/0ZpOHUgsnPFQaTNjDO4APz63+hbs5Onlbd87vgrdhTiWESu/5EyT uAVmTvzXPsGh4Zq2HFsQTlPrvPz/mcKsxXQ5Qcre00tjaxCNTuRfCsOW9HRuxUviMuNG cYRFTACDmuTpxBiLAX455nXcPfsTgXollFSDsTFv3UQDA73iPTY6jwCfNGrhmO9Rtj9X e+wg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1743977707; x=1744582507; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=c9xqHcI6eEdBoYc8sq0yd0T9xMnWM8DZJfsMIYVhLZU=; b=XxcUrlmHffBq/HRnDx4vTMJNAv33lLGcrrsB/T7idgrdgUDaw7zVZabQCOqmITYDf7 r+A5DUF9Dr0doFXyoWKN2ChFZGfVRIWElQU8C5k8NrltJDFHz8pW5N3CYTWL+8RA+rAn 4tIkey+Xx5rz4Jq7yzyOQa2Z0uwbfCkHORjF/w/fc5he4tp7mnZIYMcgI6bgKrne8EmH xNlo9wKLOMX0xJ97ncDuQaR+HEzftLvW9fzSpBHHRskG11WsismF95bFfA58owIhptwF K92GvlQdnLNJXAkaK/KRReY1hiEBfhPuQU4PQvm0VnQlNEE1JhYfXyRSc1NDfW3wrjFN uyAA== X-Forwarded-Encrypted: i=1; AJvYcCUxnA+z+THvsqQ+kGt8q/ArWGWWWR5elfdQ8UZ4Sn71MA+KW986/CJHXjJ2pxiUA64R5AVx3y/V/2o3UghfqKQ=@lists.infradead.org, AJvYcCWgCgRuB8g/ZYlJhiR5d2RTbOcJ1VjfCb1eKsq/QPAwCZpP3SUwxbbPm7Lw2WLFowMPHZ19BqN21f3htECriqK1@lists.infradead.org X-Gm-Message-State: AOJu0Yw+Z4sWNEXCmhRqRslkrF61I2Pa0I3xXxIKVVLJBrYFMxD8grGi O0je9Tkbdk/WRm3fhI94GAILyaqPh/wf3cNiqp/DDwo0itQV5Zvu X-Gm-Gg: ASbGnctCp89iaBuJHf+k3O9Wxm6QeUcS+/c2xEJfLGi9huwNS+18SF94YJCNJuveSZT Re/xO8zTO8lqUrptRHcHwDD2ZtBC6d/Bs8Is0kfdGnR5lhhwa4L+jTeIca+ndbDpdWMz4cB1GXI lH93EOnA/2mXl0GZ6I8rT7JvJSIJ4FSABwBnODAfxaf7ITNujYUtg/H9ojSurNhN6uhc3hkKdLi cQ8xrzlLBcg8CdaIgDFnwudAxnjkGjq4mBBiuQDBNwxWR+nJhs0J16XLO+rIMk7AFDkisvH6BIp sPDWTB9IKTNXOuwuShlgBy2Wmlq98TeO3ceSO+P+sxtTHYdGG0sC5/o1sAwhD8i1pD8otO1+Iir BC9AFTNtOgraQiw== X-Google-Smtp-Source: AGHT+IHHGzqQcd0yxNmInYcS6+JqZl5EtjnstzVnRpxCfifNdrZhAMxa8fvFxvPHu5vzKgxQcN6MHA== X-Received: by 2002:a05:600c:3504:b0:43d:54a:221c with SMTP id 5b1f17b1804b1-43eeb5c0212mr45020395e9.18.1743977707112; Sun, 06 Apr 2025 15:15:07 -0700 (PDT) Received: from localhost.localdomain (93-34-88-225.ip49.fastwebnet.it. [93.34.88.225]) by smtp.googlemail.com with ESMTPSA id 5b1f17b1804b1-43ec366aa29sm111517055e9.39.2025.04.06.15.15.05 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 06 Apr 2025 15:15:06 -0700 (PDT) From: Christian Marangi To: Andrew Lunn , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Rob Herring , Krzysztof Kozlowski , Conor Dooley , Lorenzo Bianconi , Heiner Kallweit , Russell King , Philipp Zabel , Christian Marangi , Daniel Golle , "Russell King (Oracle)" , netdev@vger.kernel.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-mediatek@lists.infradead.org, "Lei Wei (QUIC)" Subject: [RFC PATCH net-next v2 06/11] net: pcs: implement Firmware node support for PCS driver Date: Mon, 7 Apr 2025 00:13:59 +0200 Message-ID: <20250406221423.9723-7-ansuelsmth@gmail.com> X-Mailer: git-send-email 2.48.1 In-Reply-To: <20250406221423.9723-1-ansuelsmth@gmail.com> References: <20250406221423.9723-1-ansuelsmth@gmail.com> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20250406_151508_996682_5F5A9283 X-CRM114-Status: GOOD ( 36.20 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org Implement the foundation of Firmware node support for PCS driver. To support this, implement a simple Provider API where a PCS driver can expose multiple PCS with an xlate .get function. PCS driver will have to call fwnode_pcs_add_provider() and pass the firmware node pointer and a xlate function to return the correct PCS for the passed #pcs-cells. This will register the PCS in a global list of providers so that consumer can access it. Consumer will then use fwnode_pcs_get() to get the actual PCS by passing the firmware node pointer and the index for #pcs-cells. For simple implementation where #pcs-cells is 0 and the PCS driver expose a single PCS, the xlate function fwnode_pcs_simple_get() is provided. For advanced implementation a custom xlate function is required. PCS driver on removal should first delete as a provider with the usage of fwnode_pcs_del_provider() and then call phylink_release_pcs() on every PCS the driver provides and A generic function fwnode_phylink_pcs_parse() is provided for any MAC driver that will declare PCS in DT (or ACPI). This function will parse "pcs-handle" property and fill the passed array with the parsed PCS in availabel_pcs up to the passed num_pcs value. It's also possible to pass NULL as array to only parse the PCS and update the num_pcs value with the count of scanned PCS. Co-developed-by: Daniel Golle Signed-off-by: Daniel Golle Signed-off-by: Christian Marangi --- drivers/net/pcs/Kconfig | 7 ++ drivers/net/pcs/Makefile | 1 + drivers/net/pcs/pcs.c | 201 +++++++++++++++++++++++++++++++ include/linux/pcs/pcs-provider.h | 41 +++++++ include/linux/pcs/pcs.h | 56 +++++++++ 5 files changed, 306 insertions(+) create mode 100644 drivers/net/pcs/pcs.c create mode 100644 include/linux/pcs/pcs-provider.h create mode 100644 include/linux/pcs/pcs.h diff --git a/drivers/net/pcs/Kconfig b/drivers/net/pcs/Kconfig index f6aa437473de..2951aa2f4cda 100644 --- a/drivers/net/pcs/Kconfig +++ b/drivers/net/pcs/Kconfig @@ -5,6 +5,13 @@ menu "PCS device drivers" +config FWNODE_PCS + tristate + depends on (ACPI || OF) + depends on PHYLINK + help + Firmware node PCS accessors + config PCS_XPCS tristate "Synopsys DesignWare Ethernet XPCS" select PHYLINK diff --git a/drivers/net/pcs/Makefile b/drivers/net/pcs/Makefile index 4f7920618b90..3005cdd89ab7 100644 --- a/drivers/net/pcs/Makefile +++ b/drivers/net/pcs/Makefile @@ -1,6 +1,7 @@ # SPDX-License-Identifier: GPL-2.0 # Makefile for Linux PCS drivers +obj-$(CONFIG_FWNODE_PCS) += pcs.o pcs_xpcs-$(CONFIG_PCS_XPCS) := pcs-xpcs.o pcs-xpcs-plat.o \ pcs-xpcs-nxp.o pcs-xpcs-wx.o diff --git a/drivers/net/pcs/pcs.c b/drivers/net/pcs/pcs.c new file mode 100644 index 000000000000..14a5cd3eeda1 --- /dev/null +++ b/drivers/net/pcs/pcs.c @@ -0,0 +1,201 @@ +// SPDX-License-Identifier: GPL-2.0-or-later + +#include +#include +#include +#include +#include + +MODULE_DESCRIPTION("PCS library"); +MODULE_AUTHOR("Christian Marangi "); +MODULE_LICENSE("GPL"); + +struct fwnode_pcs_provider { + struct list_head link; + + struct fwnode_handle *fwnode; + struct phylink_pcs *(*get)(struct fwnode_reference_args *pcsspec, + void *data); + + void *data; +}; + +static LIST_HEAD(fwnode_pcs_providers); +static DEFINE_MUTEX(fwnode_pcs_mutex); + +struct phylink_pcs *fwnode_pcs_simple_get(struct fwnode_reference_args *pcsspec, + void *data) +{ + return data; +} +EXPORT_SYMBOL_GPL(fwnode_pcs_simple_get); + +int fwnode_pcs_add_provider(struct fwnode_handle *fwnode, + struct phylink_pcs *(*get)(struct fwnode_reference_args *pcsspec, + void *data), + void *data) +{ + struct fwnode_pcs_provider *pp; + + if (!fwnode) + return 0; + + pp = kzalloc(sizeof(*pp), GFP_KERNEL); + if (!pp) + return -ENOMEM; + + pp->fwnode = fwnode_handle_get(fwnode); + pp->data = data; + pp->get = get; + + mutex_lock(&fwnode_pcs_mutex); + list_add(&pp->link, &fwnode_pcs_providers); + mutex_unlock(&fwnode_pcs_mutex); + pr_debug("Added pcs provider from %pfwf\n", fwnode); + + fwnode_dev_initialized(fwnode, true); + + return 0; +} +EXPORT_SYMBOL_GPL(fwnode_pcs_add_provider); + +void fwnode_pcs_del_provider(struct fwnode_handle *fwnode) +{ + struct fwnode_pcs_provider *pp; + + if (!fwnode) + return; + + mutex_lock(&fwnode_pcs_mutex); + list_for_each_entry(pp, &fwnode_pcs_providers, link) { + if (pp->fwnode == fwnode) { + list_del(&pp->link); + fwnode_dev_initialized(pp->fwnode, false); + fwnode_handle_put(pp->fwnode); + kfree(pp); + break; + } + } + mutex_unlock(&fwnode_pcs_mutex); +} +EXPORT_SYMBOL_GPL(fwnode_pcs_del_provider); + +static int fwnode_parse_pcsspec(const struct fwnode_handle *fwnode, int index, + const char *name, + struct fwnode_reference_args *out_args) +{ + int ret = -ENOENT; + + if (!fwnode) + return -ENOENT; + + if (name) + index = fwnode_property_match_string(fwnode, "pcs-names", + name); + + ret = fwnode_property_get_reference_args(fwnode, "pcs-handle", + "#pcs-cells", + -1, index, out_args); + if (ret || (name && index < 0)) + return ret; + + return 0; +} + +static struct phylink_pcs * +fwnode_pcs_get_from_pcsspec(struct fwnode_reference_args *pcsspec) +{ + struct fwnode_pcs_provider *provider; + struct phylink_pcs *pcs = ERR_PTR(-EPROBE_DEFER); + + if (!pcsspec) + return ERR_PTR(-EINVAL); + + mutex_lock(&fwnode_pcs_mutex); + list_for_each_entry(provider, &fwnode_pcs_providers, link) { + if (provider->fwnode == pcsspec->fwnode) { + pcs = provider->get(pcsspec, provider->data); + if (!IS_ERR(pcs)) + break; + } + } + mutex_unlock(&fwnode_pcs_mutex); + + return pcs; +} + +static struct phylink_pcs *__fwnode_pcs_get(struct fwnode_handle *fwnode, + int index, const char *con_id) +{ + struct fwnode_reference_args pcsspec; + struct phylink_pcs *pcs; + int ret; + + ret = fwnode_parse_pcsspec(fwnode, index, con_id, &pcsspec); + if (ret) + return ERR_PTR(ret); + + pcs = fwnode_pcs_get_from_pcsspec(&pcsspec); + fwnode_handle_put(pcsspec.fwnode); + + return pcs; +} + +struct phylink_pcs *fwnode_pcs_get(struct fwnode_handle *fwnode, int index) +{ + return __fwnode_pcs_get(fwnode, index, NULL); +} +EXPORT_SYMBOL_GPL(fwnode_pcs_get); + +static int fwnode_phylink_pcs_count(struct fwnode_handle *fwnode, + unsigned int *num_pcs) +{ + struct fwnode_reference_args out_args; + int index = 0; + int ret; + + while (true) { + ret = fwnode_property_get_reference_args(fwnode, "pcs-handle", + "#pcs-cells", + -1, index, &out_args); + /* We expect to reach an -ENOENT error while counting */ + if (ret) + break; + + fwnode_handle_put(out_args.fwnode); + index++; + } + + /* Update num_pcs with parsed PCS */ + *num_pcs = index; + + /* Return error if we didn't found any PCS */ + return index > 0 ? 0 : -ENOENT; +} + +int fwnode_phylink_pcs_parse(struct fwnode_handle *fwnode, + struct phylink_pcs **available_pcs, + unsigned int *num_pcs) +{ + int i; + + if (!fwnode_property_present(fwnode, "pcs-handle")) + return -ENODEV; + + /* With available_pcs NULL, only count the PCS */ + if (!available_pcs) + return fwnode_phylink_pcs_count(fwnode, num_pcs); + + for (i = 0; i < *num_pcs; i++) { + struct phylink_pcs *pcs; + + pcs = fwnode_pcs_get(fwnode, i); + if (IS_ERR(pcs)) + return PTR_ERR(pcs); + + available_pcs[i] = pcs; + } + + return 0; +} +EXPORT_SYMBOL_GPL(fwnode_phylink_pcs_parse); diff --git a/include/linux/pcs/pcs-provider.h b/include/linux/pcs/pcs-provider.h new file mode 100644 index 000000000000..2fcc1d696c97 --- /dev/null +++ b/include/linux/pcs/pcs-provider.h @@ -0,0 +1,41 @@ +/* SPDX-License-Identifier: GPL-2.0-or-later */ +#ifndef __LINUX_PCS_PROVIDER_H +#define __LINUX_PCS_PROVIDER_H + +/** + * fwnode_pcs_simple_get - Simple xlate function to retrieve PCS + * @pcsspec: reference arguments + * @data: Context data (assumed assigned to the single PCS) + * + * Returns the PCS. (pointed by data) + */ +struct phylink_pcs *fwnode_pcs_simple_get(struct fwnode_reference_args *pcsspec, + void *data); + +/** + * fwnode_pcs_add_provider - Registers a new PCS provider + * @np: Firmware node + * @get: xlate function to retrieve the PCS + * @data: Context data + * + * Register and add a new PCS to the global providers list + * for the firmware node. A function to get the PCS from + * firmware node with the use fwnode reference arguments. + * To the get function is also passed the interface type + * requested for the PHY. PCS driver will use the passed + * interface to understand if the PCS can support it or not. + * + * Returns 0 on success or -ENOMEM on allocation failure. + */ +int fwnode_pcs_add_provider(struct fwnode_handle *fwnode, + struct phylink_pcs *(*get)(struct fwnode_reference_args *pcsspec, + void *data), + void *data); + +/** + * fwnode_pcs_del_provider - Removes a PCS provider + * @fwnode: Firmware node + */ +void fwnode_pcs_del_provider(struct fwnode_handle *fwnode); + +#endif /* __LINUX_PCS_PROVIDER_H */ diff --git a/include/linux/pcs/pcs.h b/include/linux/pcs/pcs.h new file mode 100644 index 000000000000..c7a4d63bcd6d --- /dev/null +++ b/include/linux/pcs/pcs.h @@ -0,0 +1,56 @@ +/* SPDX-License-Identifier: GPL-2.0-or-later */ +#ifndef __LINUX_PCS_H +#define __LINUX_PCS_H + +#include + +#if IS_ENABLED(CONFIG_FWNODE_PCS) +/** + * fwnode_pcs_get - Retrieves a PCS from a firmware node + * @fwnode: firmware node + * @index: index fwnode PCS handle in firmware node + * + * Get a PCS from the firmware node at index. + * + * Returns a pointer to the phylink_pcs or a negative + * error pointer. Can return -EPROBE_DEFER if the PCS is not + * present in global providers list (either due to driver + * still needs to be probed or it failed to probe/removed) + */ +struct phylink_pcs *fwnode_pcs_get(struct fwnode_handle *fwnode, + int index); + +/** + * fwnode_phylink_pcs_parse - generic PCS parse for fwnode PCS provider + * @fwnode: firmware node + * @available_pcs: pointer to preallocated array of PCS + * @num_pcs: where to store count of parsed PCS + * + * Generic helper function to fill available_pcs array with PCS parsed + * from a "pcs-handle" fwnode property defined in firmware node up to + * passed num_pcs. + * + * If available_pcs is NULL, num_pcs is updated with the count of the + * parsed PCS. + * + * Returns 0 or a negative error. + */ +int fwnode_phylink_pcs_parse(struct fwnode_handle *fwnode, + struct phylink_pcs **available_pcs, + unsigned int *num_pcs); +#else +static inline struct phylink_pcs *fwnode_pcs_get(struct fwnode_handle *fwnode, + int index) +{ + return ERR_PTR(-ENOENT); +} + +static inline int fwnode_phylink_pcs_parse(struct fwnode_handle *fwnode, + struct phylink_pcs **available_pcs, + unsigned int *num_pcs) +{ + return -EOPNOTSUPP; +} +#endif + +#endif /* __LINUX_PCS_H */ From patchwork Sun Apr 6 22:14:00 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christian Marangi X-Patchwork-Id: 14039578 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 0EF03C3600C for ; Sun, 6 Apr 2025 22:30:01 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender:List-Subscribe:List-Help :List-Post:List-Archive:List-Unsubscribe:List-Id:Content-Transfer-Encoding: MIME-Version:References:In-Reply-To:Message-ID:Date:Subject:To:From:Reply-To: Cc:Content-Type:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=NheK5r8NI2wjWbCB6pBIM1rY7N6lb54Ew5FqwDMD4TY=; b=qNQI+exu7nnT1NYek1VUAyb/Hn 4Q1e7X/DwI+edpxPDKXF6MpS+1bPQcqAoyAH3K+5L+pwA+BJc55Vi+gTDylgCXxJFeCAMSKEPFQHI /Pv6yPT46lV4uKRYxunxUQe3Lbc8cc7BEqdIpXGhNRmXetBXrOLnrqKE25awkUIB0DDGnPUyedURt enD0n0kfVzy2iF6s1Y/t0azv6q8PIHohgsW1nGM4hVHH1j/CQ5oH7tIfyc00UT6/fxUO3iqPxzKUO HIZZLiSSLvcjD33AVqw2sjCZbkdFKavvPfN4Mdr+LJ0nn4Ta4rEdtdK7S4+QNSHziXHpVk7annXeG B37Q3IrA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.98.1 #2 (Red Hat Linux)) id 1u1YUy-0000000Fvhj-2JUY; Sun, 06 Apr 2025 22:29:52 +0000 Received: from mail-wm1-x32a.google.com ([2a00:1450:4864:20::32a]) by bombadil.infradead.org with esmtps (Exim 4.98.1 #2 (Red Hat Linux)) id 1u1YGk-0000000Fswk-0q5f; Sun, 06 Apr 2025 22:15:11 +0000 Received: by mail-wm1-x32a.google.com with SMTP id 5b1f17b1804b1-43cf257158fso25177475e9.2; Sun, 06 Apr 2025 15:15:09 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1743977708; x=1744582508; darn=lists.infradead.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:from:to:cc:subject:date:message-id :reply-to; bh=NheK5r8NI2wjWbCB6pBIM1rY7N6lb54Ew5FqwDMD4TY=; b=l0Wehog/4FWmntUdUXfOkSaWXGepLvRqX2uQJG255WIs8WU+ikjNVwVeSN5Trh+AkR dB4gAIGHsmPmKWi6oT725J00Poe+3A61ur5MZTI2eLEJCrrNIXmzQcKwCItedq/bRf33 bUCN+h1yvOluqoy2xpPJVhv1RQXnRVpIv9e8GhUNpNcVG2SvPCHTSO3siIwuMXuFfhTE WaLq/J6Rp7dIHPem9EO525pK3/Itis7fIs/clIDmanSj/E3Ajn17PaRSub5C9F+QnNnr 5D8q2LgHzMEH3lqnH8j1cEKGrf9r+aTZQuaLMjB/rzCSLPyJv9Kn4VrULEWyBKjJJJMb Qb+A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1743977708; x=1744582508; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=NheK5r8NI2wjWbCB6pBIM1rY7N6lb54Ew5FqwDMD4TY=; b=f3A6fTkmmQQfi3eYh0HXXPdBCtF1zitoXJN03jGDN80yH7feZmGdnG9OF616TmnNA9 xX9cArkvro6FzpilChnyJyD+TWtaKW5Q1nvtnR+LYwedGbsMW9jJBpV7+6W7qYK2HFzT VEB1LHIZKkohQL5M1AxsAJXQGfa0kPhBgAZBL4hFpDN60UNDr3KmOcLR8SnN0dd4UHHT 4B+ZRSW1F1FRRzLBV5/Vyw7z9pmj6YoJRQ9I2vLH3f0kIngH0qq8n4lozybHBK8CGzkL fgqN7yWuqBEuJq/zCaGRAYx195qV7LvB/5yCDNdg++zerEdJ+HKu+e1hXjdxTaEqsPYb yFpA== X-Forwarded-Encrypted: i=1; AJvYcCUUnfrgZwqOlZmf7u8cCBPbT5mvYOgL2HKwuGfoMzEbKVBXK9vVENEpe6WR9UdIYHH58XuH8CAioJ6+C06LKJc=@lists.infradead.org, AJvYcCWXF9YORm1qdAX69zI24RTV9uHvAg32qhrKZTtJqWpAP3f/H+hP0XHOQDSndEZi6jHoLF4EZjWOAEEYMZF856/p@lists.infradead.org X-Gm-Message-State: AOJu0Yw7RVARCQzszy3fg0w08TObFs4ayw1BUcZ5CLePSrFC+8BunVpW B4eZqtZhy+49QT0kZ9oncqQBg+rgj+uK/WknW4VVij0gR2+/UYbt X-Gm-Gg: ASbGncsymzyPmQ+F1Gk/3gQyx11V5vgWIEgxcI6EB/JG48QnjEVfus2Q8UPWrkxmW7c epvHDm4Uh6j3ltG4/UmlyX5Bigk3OL8pGHQFEa3i06hsSptcBeAhgrlpf8C4TIng+PaPRPGTHBa g6U7chey1aQl3X6739UtUZ0wnHJWbRKAgVY8vMvylMsv7tRtB/NKNT412Ffq0WhjxcHivWPWQdr XAWwWy6szIgBlaOtpjJsHv0UWi6haolT3vFelOQCJ8SJ7lUfmADFLA5hSSBnpsWMpPnVTQNqYwp 59gLJkA7YURpGh3GuF+/7dsUhJazLVVxPOAzo6eWrthp98qPj6VodXnNzI0gbX0P8w9pZ1byJG9 O6c4ugjo1Yim/LA== X-Google-Smtp-Source: AGHT+IHaz2i92ocrx4+wErQZTjeioBLSqGXinrgyqWLyRujet6CpsWu8yc7v9VQuGpHgAyRsELf1uA== X-Received: by 2002:a05:600c:4705:b0:43d:53c:1ad6 with SMTP id 5b1f17b1804b1-43ecfa02754mr67372745e9.26.1743977708364; Sun, 06 Apr 2025 15:15:08 -0700 (PDT) Received: from localhost.localdomain (93-34-88-225.ip49.fastwebnet.it. [93.34.88.225]) by smtp.googlemail.com with ESMTPSA id 5b1f17b1804b1-43ec366aa29sm111517055e9.39.2025.04.06.15.15.07 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 06 Apr 2025 15:15:08 -0700 (PDT) From: Christian Marangi To: Andrew Lunn , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Rob Herring , Krzysztof Kozlowski , Conor Dooley , Lorenzo Bianconi , Heiner Kallweit , Russell King , Philipp Zabel , Christian Marangi , Daniel Golle , "Russell King (Oracle)" , netdev@vger.kernel.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-mediatek@lists.infradead.org, "Lei Wei (QUIC)" Subject: [RFC PATCH net-next v2 07/11] net: phylink: support late PCS provider attach Date: Mon, 7 Apr 2025 00:14:00 +0200 Message-ID: <20250406221423.9723-8-ansuelsmth@gmail.com> X-Mailer: git-send-email 2.48.1 In-Reply-To: <20250406221423.9723-1-ansuelsmth@gmail.com> References: <20250406221423.9723-1-ansuelsmth@gmail.com> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20250406_151510_241270_BEDEE0F3 X-CRM114-Status: GOOD ( 26.66 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org Add support in phylink for late PCS provider attach to a phylink instance. This works by creating a global notifier for the PCS provider and making each phylink instance that makes use of fwnode subscribe to this notifier. The PCS notifier will emit the event FWNODE_PCS_PROVIDER_ADD every time a new PCS provider is added. phylink will then react to this event and will call the new function fwnode_phylink_pcs_get_from_fwnode() that will check if the PCS fwnode provided by the event is present in the phy-handle property of the phylink instance. If a related PCS is found, then such PCS is added to the phylink instance PCS list. Then we link the PCS to the phylink instance if it's not disable and we refresh the supported interfaces of the phylink instance. Finally we check if we are in a major_config_failed scenario and trigger an interface reconfiguration in the next phylink resolve. If link was previously torn down due to removal of PCS, the link will be established again as the PCS came back and is not available to phylink. Signed-off-by: Christian Marangi --- drivers/net/pcs/pcs.c | 34 +++++++++++++++++++++++++ drivers/net/phy/phylink.c | 52 +++++++++++++++++++++++++++++++++++++++ include/linux/pcs/pcs.h | 48 ++++++++++++++++++++++++++++++++++++ 3 files changed, 134 insertions(+) diff --git a/drivers/net/pcs/pcs.c b/drivers/net/pcs/pcs.c index 14a5cd3eeda1..a7352effa92f 100644 --- a/drivers/net/pcs/pcs.c +++ b/drivers/net/pcs/pcs.c @@ -22,6 +22,13 @@ struct fwnode_pcs_provider { static LIST_HEAD(fwnode_pcs_providers); static DEFINE_MUTEX(fwnode_pcs_mutex); +static BLOCKING_NOTIFIER_HEAD(fwnode_pcs_notify_list); + +int register_fwnode_pcs_notifier(struct notifier_block *nb) +{ + return blocking_notifier_chain_register(&fwnode_pcs_notify_list, nb); +} +EXPORT_SYMBOL_GPL(register_fwnode_pcs_notifier); struct phylink_pcs *fwnode_pcs_simple_get(struct fwnode_reference_args *pcsspec, void *data) @@ -55,6 +62,10 @@ int fwnode_pcs_add_provider(struct fwnode_handle *fwnode, fwnode_dev_initialized(fwnode, true); + blocking_notifier_call_chain(&fwnode_pcs_notify_list, + FWNODE_PCS_PROVIDER_ADD, + fwnode); + return 0; } EXPORT_SYMBOL_GPL(fwnode_pcs_add_provider); @@ -147,6 +158,29 @@ struct phylink_pcs *fwnode_pcs_get(struct fwnode_handle *fwnode, int index) } EXPORT_SYMBOL_GPL(fwnode_pcs_get); +struct phylink_pcs * +fwnode_phylink_pcs_get_from_fwnode(struct fwnode_handle *fwnode, + struct fwnode_handle *pcs_fwnode) +{ + struct fwnode_reference_args pcsspec; + int i = 0; + int ret; + + while (true) { + ret = fwnode_parse_pcsspec(fwnode, i, NULL, &pcsspec); + if (ret) + break; + + if (pcsspec.fwnode == pcs_fwnode) + break; + + i++; + } + + return fwnode_pcs_get(fwnode, i); +} +EXPORT_SYMBOL_GPL(fwnode_phylink_pcs_get_from_fwnode); + static int fwnode_phylink_pcs_count(struct fwnode_handle *fwnode, unsigned int *num_pcs) { diff --git a/drivers/net/phy/phylink.c b/drivers/net/phy/phylink.c index e6bb6e5cb63e..b189d42b6a9b 100644 --- a/drivers/net/phy/phylink.c +++ b/drivers/net/phy/phylink.c @@ -12,6 +12,7 @@ #include #include #include +#include #include #include #include @@ -68,6 +69,7 @@ struct phylink { /* List of available PCS */ struct list_head pcs_list; + struct notifier_block fwnode_pcs_nb; /* What interface are supported by the current link. * Can change on removal or addition of new PCS. @@ -1915,6 +1917,51 @@ int phylink_set_fixed_link(struct phylink *pl, } EXPORT_SYMBOL_GPL(phylink_set_fixed_link); +static int pcs_provider_notify(struct notifier_block *self, + unsigned long val, void *data) +{ + struct phylink *pl = container_of(self, struct phylink, fwnode_pcs_nb); + struct fwnode_handle *pcs_fwnode = data; + struct phylink_pcs *pcs; + + /* Check if the just added PCS provider is + * in the phylink instance phy-handle property + */ + pcs = fwnode_phylink_pcs_get_from_fwnode(dev_fwnode(pl->config->dev), + pcs_fwnode); + if (IS_ERR(pcs)) + return NOTIFY_DONE; + + /* Add the PCS */ + rtnl_lock(); + + list_add(&pcs->list, &pl->pcs_list); + + /* Link phylink if we are started */ + if (!pl->phylink_disable_state) + pcs->phylink = pl; + + /* Refresh supported interfaces */ + phy_interface_copy(pl->supported_interfaces, + pl->config->supported_interfaces); + list_for_each_entry(pcs, &pl->pcs_list, list) + phy_interface_or(pl->supported_interfaces, + pl->supported_interfaces, + pcs->supported_interfaces); + + mutex_lock(&pl->state_mutex); + /* Force an interface reconfig if major config fail */ + if (pl->major_config_failed) + pl->reconfig_interface = true; + mutex_unlock(&pl->state_mutex); + + rtnl_unlock(); + + phylink_run_resolve(pl); + + return NOTIFY_OK; +} + /** * phylink_create() - create a phylink instance * @config: a pointer to the target &struct phylink_config @@ -1969,6 +2016,11 @@ struct phylink *phylink_create(struct phylink_config *config, pl->supported_interfaces, pcs->supported_interfaces); + if (!phy_interface_empty(config->pcs_interfaces)) { + pl->fwnode_pcs_nb.notifier_call = pcs_provider_notify; + register_fwnode_pcs_notifier(&pl->fwnode_pcs_nb); + } + pl->config = config; if (config->type == PHYLINK_NETDEV) { pl->netdev = to_net_dev(config->dev); diff --git a/include/linux/pcs/pcs.h b/include/linux/pcs/pcs.h index c7a4d63bcd6d..480c155a3f03 100644 --- a/include/linux/pcs/pcs.h +++ b/include/linux/pcs/pcs.h @@ -4,7 +4,24 @@ #include +enum fwnode_pcs_notify_event { + FWNODE_PCS_PROVIDER_ADD, +}; + #if IS_ENABLED(CONFIG_FWNODE_PCS) +/** + * register_fwnode_pcs_notifier - Register a notifier block for fwnode + * PCS events + * @nb: pointer to the notifier block + * + * Registers a notifier block to the fwnode_pcs_notify_list blocking + * notifier chain. This allows phylink instance to subscribe for + * PCS provider events. + * + * Returns 0 or a negative error. + */ +int register_fwnode_pcs_notifier(struct notifier_block *nb); + /** * fwnode_pcs_get - Retrieves a PCS from a firmware node * @fwnode: firmware node @@ -20,6 +37,25 @@ struct phylink_pcs *fwnode_pcs_get(struct fwnode_handle *fwnode, int index); +/** + * fwnode_phylink_pcs_get_from_fwnode - Retrieves the PCS provided + * by the firmware node from a + * firmware node + * @fwnode: firmware node + * @pcs_fwnode: PCS firmware node + * + * Parse 'pcs-handle' in 'fwnode' and get the PCS that match + * 'pcs_fwnode' firmware node. + * + * Returns a pointer to the phylink_pcs or a negative + * error pointer. Can return -EPROBE_DEFER if the PCS is not + * present in global providers list (either due to driver + * still needs to be probed or it failed to probe/removed) + */ +struct phylink_pcs * +fwnode_phylink_pcs_get_from_fwnode(struct fwnode_handle *fwnode, + struct fwnode_handle *pcs_fwnode); + /** * fwnode_phylink_pcs_parse - generic PCS parse for fwnode PCS provider * @fwnode: firmware node @@ -39,12 +75,24 @@ int fwnode_phylink_pcs_parse(struct fwnode_handle *fwnode, struct phylink_pcs **available_pcs, unsigned int *num_pcs); #else +static int register_fwnode_pcs_notifier(struct notifier_block *nb) +{ + return -EOPNOTSUPP; +} + static inline struct phylink_pcs *fwnode_pcs_get(struct fwnode_handle *fwnode, int index) { return ERR_PTR(-ENOENT); } +static struct phylink_pcs * +fwnode_phylink_pcs_get_from_fwnode(struct fwnode_handle *fwnode, + struct fwnode_handle *pcs_fwnode) +{ + return ERR_PTR(-ENOENT); +} + static inline int fwnode_phylink_pcs_parse(struct fwnode_handle *fwnode, struct phylink_pcs **available_pcs, unsigned int *num_pcs) From patchwork Sun Apr 6 22:14:01 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christian Marangi X-Patchwork-Id: 14039582 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 03B1FC36002 for ; Sun, 6 Apr 2025 22:31:56 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender:List-Subscribe:List-Help :List-Post:List-Archive:List-Unsubscribe:List-Id:Content-Transfer-Encoding: MIME-Version:References:In-Reply-To:Message-ID:Date:Subject:To:From:Reply-To: Cc:Content-Type:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=sm/ZIdkSaGh1P4y2c0zDVUpHmGlbMlKT0SYr00OWyVM=; b=2AyhtBbT/GkI7QHSjFLcPchx7I b+kpFhvGIUBXhABZy9GFXQ0GnYwiYN1MieDdTov/kEZ8ME7I5ekn5Nprj/bzbOiU/0/BCC6wJmory DovJnpTA8+AKV/7Korqc7B6gqLjaKB3nP3YgJll6mR+GgqLuEpQKVYDNcS75rKCpVmejkj9CmtTA/ nRz3VmU2n0DsyqpPvNhx/0HMeLDm7SIPhgwfJlxDR7nsdPqeHPeDUvbSdglv2oX8guOCye2HKblWi /BDRaJii0iz/AedGHJcKjkg0KwsSX0cxYsH5Jo2kO9tKcyJKixG+l+UwyDIzkYs7Y4dhgHppVmXkX BeN0GAaQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.98.1 #2 (Red Hat Linux)) id 1u1YWn-0000000Fvyl-0BeX; Sun, 06 Apr 2025 22:31:45 +0000 Received: from mail-wm1-x32f.google.com ([2a00:1450:4864:20::32f]) by bombadil.infradead.org with esmtps (Exim 4.98.1 #2 (Red Hat Linux)) id 1u1YGm-0000000FsxP-13jE; Sun, 06 Apr 2025 22:15:13 +0000 Received: by mail-wm1-x32f.google.com with SMTP id 5b1f17b1804b1-43cef035a3bso24342815e9.1; Sun, 06 Apr 2025 15:15:12 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1743977711; x=1744582511; darn=lists.infradead.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:from:to:cc:subject:date:message-id :reply-to; bh=sm/ZIdkSaGh1P4y2c0zDVUpHmGlbMlKT0SYr00OWyVM=; b=YPJcA8wF+aF1RcBpVfCpJ59X1jVTDgzFqJWU12fRYzDAmolWi2rxhDuLbP3RJGdmqu d8WrvB86GQop43r0CNN5QbRHug2dC+bwooj70ZslDWz+siA3ptyreuOea9VrmAhLvGv8 mZnvRb+EdQIZcgoetedsWjXg1KTkyjUqPgKBu0lHdefPXxdGnhd1hHCHZaWwHpMu1AzO dV1cZJMS4qA9iIv0KsN78D8MEoADY8IvxvIvSFwabsxa7KpVTKYrsahlTQtuv7/fWxGU iKh6wMdUgleoWQHPnNYsplxEl5jsFgtEhhZxy5oIkkABk5oENULhvKiNYgWohRONJu/A A+8Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1743977711; x=1744582511; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=sm/ZIdkSaGh1P4y2c0zDVUpHmGlbMlKT0SYr00OWyVM=; b=kLa2VTzJkQ2JeklRMDSWNvRpAroGKoYynGYuTUspdpYE8ruC+DQPjC0GGfYS62QGrZ +Ye9wtPj29lunAxOJAvzZiyQOE+sSOinjnMdfyuxKzgdU7F5/x23txqbAS+7U9KmG9Ct 6bwsqRB3xyNjcsjn5qLO4oqzTIOL7jZyV0F2MG0s5iMgCF5ZJKAM8TW1k7MmSS5tz5UL 9RqVRJWPfZ0urVYJQgsha6sFQzYUlQwwuOJb+foSOj70+S/SKhSeskeI52VpefghAMes AnA/2Iv8r6Ab0xEI/P9kK55ntSCZ5oIYGNLXnxEMGARKmBCVF1twahgIwVzPxEigpRr1 fmfA== X-Forwarded-Encrypted: i=1; AJvYcCVgm5U0iNXyRCU6UYhXPzjW4aZNmRXngXRsssI/q3ZXYfZjEh2pzropaN8ZePCOiEv1S+JXTv7l5itnlKrdYdXV@lists.infradead.org, AJvYcCXAgphHMNc0qZID+ljoLBj2KdBvjftGds669fBBEbD09Yce75zROTPBGlStkvUE0KT+3+iK2dSMlPBtfF8rcdI=@lists.infradead.org X-Gm-Message-State: AOJu0Yw3oMUxvdXanIIO/Qv+FNwu24ymWIM/s14vVpdVqvje2smW9X+f 6AhXOrux5HxuQtxmDc6RkDuydSJAt8O9Gu9g+ekdZ3TvK3OYQKXu X-Gm-Gg: ASbGncvhhbvwaDncwc9AgKNr7fRMS6yJ61w2nZ+NEEhffq7u4uaVJbjCGux7tbj/twn jlrWtf5zERwtpvZcfP63vXz+dtVkQe9ZQHNNcwURcnSLo8WkjiR/Psa8vkxscZtrnPrplsrROF/ A8JZJFHbV2wtMzu1p9VIIea2ftYMrGgwD1hFyxK5OXY9ADjOtgIrsZO2jzUZ3FNMCWaNQ/QLpJt 6UYcSEIsZw4eo48IkHZnKe9qlS/do7e1VFOMnJk6OYT6h2PUqhEleHPnpwKac7lV4HTcHWSp0hc NIzbz5vIBZ8yCcxBN+0lmyxFIifUYBhvMYpyu0EwN5BQ/rDIQQGdP963SAwgjyVFqjeC3mUI4eO TOpcqSSUE7aecVg== X-Google-Smtp-Source: AGHT+IHxaGvWEB3NGSJbMPNiv9bPepD1ALCIv/tPzMQD98V+RZ+Iyvgwi83L4i5nUBXgE8BY0b3p2A== X-Received: by 2002:a05:600c:500c:b0:43d:bb9:ad00 with SMTP id 5b1f17b1804b1-43ecf8cf6b2mr116582275e9.15.1743977710829; Sun, 06 Apr 2025 15:15:10 -0700 (PDT) Received: from localhost.localdomain (93-34-88-225.ip49.fastwebnet.it. [93.34.88.225]) by smtp.googlemail.com with ESMTPSA id 5b1f17b1804b1-43ec366aa29sm111517055e9.39.2025.04.06.15.15.08 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 06 Apr 2025 15:15:09 -0700 (PDT) From: Christian Marangi To: Andrew Lunn , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Rob Herring , Krzysztof Kozlowski , Conor Dooley , Lorenzo Bianconi , Heiner Kallweit , Russell King , Philipp Zabel , Christian Marangi , Daniel Golle , "Russell King (Oracle)" , netdev@vger.kernel.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-mediatek@lists.infradead.org, "Lei Wei (QUIC)" Subject: [RFC PATCH net-next v2 08/11] dt-bindings: net: ethernet-controller: permit to define multiple PCS Date: Mon, 7 Apr 2025 00:14:01 +0200 Message-ID: <20250406221423.9723-9-ansuelsmth@gmail.com> X-Mailer: git-send-email 2.48.1 In-Reply-To: <20250406221423.9723-1-ansuelsmth@gmail.com> References: <20250406221423.9723-1-ansuelsmth@gmail.com> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20250406_151512_298841_11C7B57C X-CRM114-Status: GOOD ( 11.28 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org Drop the limitation of a single PCS in pcs-handle property. Multiple PCS can be defined for an ethrnet-controller node to support various PHY interface mode type. It's very common for SoCs to have a dedicated PCS for SGMII mode and one for USXGMII mode. Signed-off-by: Christian Marangi --- (for Rob, I didn't ignore the comments, just want to make sure the driver side is done, please ignore) Documentation/devicetree/bindings/net/ethernet-controller.yaml | 2 -- 1 file changed, 2 deletions(-) diff --git a/Documentation/devicetree/bindings/net/ethernet-controller.yaml b/Documentation/devicetree/bindings/net/ethernet-controller.yaml index 45819b235800..a260ab8e056e 100644 --- a/Documentation/devicetree/bindings/net/ethernet-controller.yaml +++ b/Documentation/devicetree/bindings/net/ethernet-controller.yaml @@ -110,8 +110,6 @@ properties: pcs-handle: $ref: /schemas/types.yaml#/definitions/phandle-array - items: - maxItems: 1 description: Specifies a reference to a node representing a PCS PHY device on a MDIO bus to link with an external PHY (phy-handle) if exists. From patchwork Sun Apr 6 22:14:03 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christian Marangi X-Patchwork-Id: 14039583 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id E22B0C36002 for ; Sun, 6 Apr 2025 22:33:47 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender:List-Subscribe:List-Help :List-Post:List-Archive:List-Unsubscribe:List-Id:Content-Transfer-Encoding: MIME-Version:References:In-Reply-To:Message-ID:Date:Subject:To:From:Reply-To: Cc:Content-Type:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=JGytfW8G6gwhO327U2YL1/GYm/l6ThozJnofzfzJ7Fs=; b=WfkTxLHve3RXHi3CbKTlnzGaDK OSisRCSv6P8BOMeMG6THzKJt4/IdGhdgi695gcz75ziiA7T0QnkBB+UUN1QRvtYBRyu0bJMm38lFk 21rPutm2LVABO6v0owvz0WuxgciQBtINcmC/W8D/0euCHPRPHTu+UM/YLNLbTgAGBlyxG12cgtz5/ WuNyW2dh3408EWxKKTJWKvdoewCtXpvPk3U5Mf05GHWfwnK0z83+YSFR/VN4FMQLovUXyMw8tR+Xz 5kQ79BOJyDsnx43AFtwefeV2n72jF+cdE+l8B1KUJvF2g04ae2RIGEAM/87DxEgZA8QvNavQe9NNJ 9H+FG8FA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.98.1 #2 (Red Hat Linux)) id 1u1YYa-0000000FwBZ-3Qx0; Sun, 06 Apr 2025 22:33:36 +0000 Received: from mail-wm1-x32c.google.com ([2a00:1450:4864:20::32c]) by bombadil.infradead.org with esmtps (Exim 4.98.1 #2 (Red Hat Linux)) id 1u1YGq-0000000Fsy1-0NqX; Sun, 06 Apr 2025 22:15:17 +0000 Received: by mail-wm1-x32c.google.com with SMTP id 5b1f17b1804b1-43d2d952eb1so24973235e9.1; Sun, 06 Apr 2025 15:15:15 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1743977714; x=1744582514; darn=lists.infradead.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:from:to:cc:subject:date:message-id :reply-to; bh=JGytfW8G6gwhO327U2YL1/GYm/l6ThozJnofzfzJ7Fs=; b=H0o/Ffaei3QbnABBC48NsfdkXE3+Q595PLVBjEUIyhinzBDMPVbmXLTExSrwhtngvV J7btwS52dV1SOtBPvd1NTQfBUGJ5vZC0GjmU6l26a7FhpkTuHn/gyJNmtYyiHi4OwIO+ gcIy36IUUVAHXBtjIqiICMLRjbZT70yxrh8xHYatcCEMjpjv62mVEY3LIlrHveszOy/9 92B4M0w15Yx2xIfvB5lsshTmdf8AJr1CD+MAwgVx79L319b9qly03OLOBKE1lkiVmzAU OHc+LmZZMP3sZMNGaRM4OcdEby58aEp8ymnlj4/wDkXsDFauXC/RtVN00duMFCerLCaf kyuw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1743977714; x=1744582514; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=JGytfW8G6gwhO327U2YL1/GYm/l6ThozJnofzfzJ7Fs=; b=Yy/GrEbToJ45TDWljLE3OsSJ+7WraQGKZnSeYC0JNnHTkchjBUKdz4Go5B2VgIK8sM pEgS9Vl6V9ARdqDCih1m3n9P8UYADBM6ymbcYY+1DEqwV/ZMEUCg64uNTzG3FcHkcptv 7uezrFlWMTpkThla4/5UZDZrq2Yw6xitZYpbCi/Xv5C3uRkir8QV6M5G/BQU+KLoKctD /RMntc/O2J0VKpTzV15/NcuBeIvuK7DjYmQEfZQ3O3e/jVrzGVMQVP1jJ88a8TtCzf1Z v4w5dkBlne7e9nHqkXfGdG0lQZI8ByfUhGmLXjVayDdsgGpwn7kuTN5wXCHYYe73+mZE CMbw== X-Forwarded-Encrypted: i=1; AJvYcCUSeBzZ0pKz2ZBpCEi+zbImKkYTN6RJI82Ilmvjed5E7xWeOuZrjd8HYMeTr+3AgI8/3LHU6QWRDzeoeIShT5A=@lists.infradead.org, AJvYcCUnDmANSQNRoRzuIAWPiwvC/B9y4p9KEOi87Tv/MIdZioz7OqH4ve7ajUC3wRWyWAc0bS9H44nCeVgvs6ORNJO2@lists.infradead.org X-Gm-Message-State: AOJu0YzMPUrNmRwkHJcGz5Cu+r3qSEJC4OIqgB3M4K4Avp+vJRhAVoNs c1JdcsxFLsdZecxwIEi5L6zYqwlaS/YMT+cE5/LoACujafGkGtHp X-Gm-Gg: ASbGncvDmv6jhevBu+wuB0RTC13rb5Gnc+45Ba8h15/FcxtN6/9kE/RSwAhscVyptEU t5pQOWrySTo/l+hzG4dEFmSVf3TWB72E8ZNXLtniDhu0uCAyAo4qohjYeyJ+JTlfXqpgRMLfQg0 4kKQo314qWguxl21RMwx3eg3vWAYH4vt8Bre1svoHn9PA2SJWdWVeZkTnbsaF5BRR7P4nwsEXTP 95c5B472d9P2Pt6K4NEKv9atpuSoKLGmww7aseE43ZKo2nge+/CWQtSQelXSVerJ4M2LYY4nvjZ 7HG5R4kUfay949OUGK6jN0FVgUhBu1oUICIsCModx6jhVHVoaD9uaFWXGVQXM4u7NOX/QnB+Or/ Riq2cNhsYLX079Q== X-Google-Smtp-Source: AGHT+IHf3hR2LUO2pSoHA5YRJXlajHrhcin+0UjxBL/5XqhdoqEDVFhBZWmKSGSo0LJNPC3tk0VNsQ== X-Received: by 2002:a05:600c:4f4f:b0:43c:ec28:d301 with SMTP id 5b1f17b1804b1-43ee076d88cmr58173825e9.26.1743977714232; Sun, 06 Apr 2025 15:15:14 -0700 (PDT) Received: from localhost.localdomain (93-34-88-225.ip49.fastwebnet.it. [93.34.88.225]) by smtp.googlemail.com with ESMTPSA id 5b1f17b1804b1-43ec366aa29sm111517055e9.39.2025.04.06.15.15.12 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 06 Apr 2025 15:15:13 -0700 (PDT) From: Christian Marangi To: Andrew Lunn , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Rob Herring , Krzysztof Kozlowski , Conor Dooley , Lorenzo Bianconi , Heiner Kallweit , Russell King , Philipp Zabel , Christian Marangi , Daniel Golle , "Russell King (Oracle)" , netdev@vger.kernel.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-mediatek@lists.infradead.org, "Lei Wei (QUIC)" Subject: [RFC PATCH net-next v2 10/11] dt-bindings: net: pcs: Document support for Airoha Ethernet PCS Date: Mon, 7 Apr 2025 00:14:03 +0200 Message-ID: <20250406221423.9723-11-ansuelsmth@gmail.com> X-Mailer: git-send-email 2.48.1 In-Reply-To: <20250406221423.9723-1-ansuelsmth@gmail.com> References: <20250406221423.9723-1-ansuelsmth@gmail.com> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20250406_151516_131131_072E85BD X-CRM114-Status: GOOD ( 14.32 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org Document support for Airoha Ethernet PCS for AN7581 SoC. Airoha AN7581 SoC expose multiple Physical Coding Sublayer (PCS) for the various Serdes port supporting different Media Independent Interface (10BASE-R, USXGMII, 2500BASE-X, 1000BASE-X, SGMII). This follow the new PCS provider with the use of #pcs-cells property. Signed-off-by: Christian Marangi --- (for Rob, I didn't ignore the comments, just want to make sure the driver side is done, please ignore) .../bindings/net/pcs/airoha,pcs.yaml | 112 ++++++++++++++++++ 1 file changed, 112 insertions(+) create mode 100644 Documentation/devicetree/bindings/net/pcs/airoha,pcs.yaml diff --git a/Documentation/devicetree/bindings/net/pcs/airoha,pcs.yaml b/Documentation/devicetree/bindings/net/pcs/airoha,pcs.yaml new file mode 100644 index 000000000000..8bcf7757c728 --- /dev/null +++ b/Documentation/devicetree/bindings/net/pcs/airoha,pcs.yaml @@ -0,0 +1,112 @@ +# SPDX-License-Identifier: GPL-2.0-only OR BSD-2-Clause +%YAML 1.2 +--- +$id: http://devicetree.org/schemas/net/pcs/airoha,pcs.yaml# +$schema: http://devicetree.org/meta-schemas/core.yaml# + +title: Airoha Ethernet PCS and Serdes + +maintainers: + - Christian Marangi + +description: + Airoha AN7581 SoC expose multiple Physical Coding Sublayer (PCS) for + the various Serdes port supporting different Media Independent Interface + (10BASE-R, USXGMII, 2500BASE-X, 1000BASE-X, SGMII). + +properties: + compatible: + enum: + - airoha,an7581-pcs-eth + - airoha,an7581-pcs-pon + + reg: + items: + - description: XFI MAC reg + - description: HSGMII AN reg + - description: HSGMII PCS reg + - description: MULTI SGMII reg + - description: USXGMII reg + - description: HSGMII rate adaption reg + - description: XFI Analog register + - description: XFI PMA (Physical Medium Attachment) register + + reg-names: + items: + - const: xfi_mac + - const: hsgmii_an + - const: hsgmii_pcs + - const: multi_sgmii + - const: usxgmii + - const: hsgmii_rate_adp + - const: xfi_ana + - const: xfi_pma + + resets: + items: + - description: MAC reset + - description: PHY reset + + reset-names: + items: + - const: mac + - const: phy + + "#pcs-cells": + const: 0 + +required: + - compatible + - reg + - reg-names + - resets + - reset-names + - "#pcs-cells" + +additionalProperties: false + +examples: + - | + #include + + pcs@1fa08000 { + compatible = "airoha,an7581-pcs-pon"; + reg = <0x1fa08000 0x1000>, + <0x1fa80000 0x60>, + <0x1fa80a00 0x164>, + <0x1fa84000 0x450>, + <0x1fa85900 0x338>, + <0x1fa86000 0x300>, + <0x1fa8a000 0x1000>, + <0x1fa8b000 0x1000>; + reg-names = "xfi_mac", "hsgmii_an", "hsgmii_pcs", + "multi_sgmii", "usxgmii", + "hsgmii_rate_adp", "xfi_ana", "xfi_pma"; + + resets = <&scuclk EN7581_XPON_MAC_RST>, + <&scuclk EN7581_XPON_PHY_RST>; + reset-names = "mac", "phy"; + + #pcs-cells = <0>; + }; + + pcs@1fa09000 { + compatible = "airoha,an7581-pcs-eth"; + reg = <0x1fa09000 0x1000>, + <0x1fa70000 0x60>, + <0x1fa70a00 0x164>, + <0x1fa74000 0x450>, + <0x1fa75900 0x338>, + <0x1fa76000 0x300>, + <0x1fa7a000 0x1000>, + <0x1fa7b000 0x1000>; + reg-names = "xfi_mac", "hsgmii_an", "hsgmii_pcs", + "multi_sgmii", "usxgmii", + "hsgmii_rate_adp", "xfi_ana", "xfi_pma"; + + resets = <&scuclk EN7581_XSI_MAC_RST>, + <&scuclk EN7581_XSI_PHY_RST>; + reset-names = "mac", "phy"; + + #pcs-cells = <0>; + }; From patchwork Sun Apr 6 22:14:04 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christian Marangi X-Patchwork-Id: 14039585 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 35B33C36002 for ; Sun, 6 Apr 2025 22:35:38 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender:List-Subscribe:List-Help :List-Post:List-Archive:List-Unsubscribe:List-Id:Content-Transfer-Encoding: MIME-Version:References:In-Reply-To:Message-ID:Date:Subject:To:From:Reply-To: Cc:Content-Type:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=b96fP0PKnSqz6xZp1n4Stntc07MfkBqVjxTOrAFZBU8=; b=aaMYrN/eBV2IoP/PN36Wx+zIou Sa5zC7RfJG7shp+A5jRTwdrO2dvYTAyejqhn3HGWhjvTXrPgjoHl+aYXv3LSn6stRsGjEq5CiFCqV G71e8WRYim6b3drPziGBtChNqZGbOzKRr6S0oA4/o5n/qeiV8SxSfuJqidAGko/KDYxojngamVyaV VsDqILGfwaQYbuiYM/Tvrk376LJMElVpenBUD3r3tHP312SVfqx4XVa26PVsGumPcrX3Xo3om3nIb /cBNu6JlNh/T4oDaALnxdhEKdfagpat432Bi+ik7RRIcKU7ZVhhqqyc/Dg90gKhEZzCk+h1Xiv4De cn7/qSqw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.98.1 #2 (Red Hat Linux)) id 1u1YaO-0000000FwOQ-3UJ5; Sun, 06 Apr 2025 22:35:29 +0000 Received: from mail-wm1-x333.google.com ([2a00:1450:4864:20::333]) by bombadil.infradead.org with esmtps (Exim 4.98.1 #2 (Red Hat Linux)) id 1u1YGr-0000000FsyK-11NX; Sun, 06 Apr 2025 22:15:18 +0000 Received: by mail-wm1-x333.google.com with SMTP id 5b1f17b1804b1-43edb40f357so14827175e9.0; Sun, 06 Apr 2025 15:15:17 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1743977716; x=1744582516; darn=lists.infradead.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:from:to:cc:subject:date:message-id :reply-to; bh=b96fP0PKnSqz6xZp1n4Stntc07MfkBqVjxTOrAFZBU8=; b=HUb8sqHsnV8cgZIPQU5Uh1k5RedC6VAXsPbThRGndzoOclhC+PRhMEi1rwRCxZ0kQu 7oKktJpKstKCvdRf8MYUbnAqHfMPvlJjLUUr4Y1stAVx/gNATjUNSN3E8ubhlXQ/p06J 5U2TZItOwVDeQsgNsVkpSgfBh7TN/IpK/onlyjP/FyK1e2LiJGo3S4VfCJOqAeQNiulL 185g0rzCvwbNLcsUdm1ApnhZlWAjceNAjfXqmbbLTpLmxMLk4AnCXFmxk/0aiDOfWBOz 3HoEjJifCL5p5bWckwd4SHEzEROm6NClOJEBWCGofKTSAhUO0upathL9d6qcKZ5gFEZ+ BQFA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1743977716; x=1744582516; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=b96fP0PKnSqz6xZp1n4Stntc07MfkBqVjxTOrAFZBU8=; b=I6jYIWwXj66LVY+4o+eJwxjui191j56vflmpBptZuJG1j9MJOznPosoaxsAAT9GFBm 0gJDP3GWKjTPbEiCK+RfvjLfa5KfvhzMxc4b3/uBtEQkLY+bdDKzQMhJSGdWHn7GEbEK MaqR3rzR8+PCp4JG5/SWdikMzPNXJ4nmHswIj5aJ4hGIGS0g+FmOknAhkk5che9xcHed EMpCEiX274LXF5BwRrZxGv0CM+L8F+94w1wfCMftUhjK0QhQd5mSxiO9NHQN0PcYUYqA WdHARQWFqKbtSKnAT8yhVKDoA1zYsNARutegCIUL5sGwcUjUOElv+joI5SUOuCEtroRL y+Vg== X-Forwarded-Encrypted: i=1; AJvYcCX1Krag+NIyqwyd6u4oERh2OAhd4X5rbCT7ixRLjDqK4AqLMpOtwkKqm1aDC4kHTr4nwiNqmRumnyvMS1QfdUQ=@lists.infradead.org, AJvYcCXmU95PcCCunU4nBDW85VXik05w8yobiWendF9nIwtP+zRAtNJINA4VDWQR6ebrKT2dbE8AGRDseiMNwTN+zskg@lists.infradead.org X-Gm-Message-State: AOJu0Yx5epeMPlzQ/WADFTAURZkKBAKJ1TPS8WohnuqlUeWeIhG43PuZ 0AHEo3h++e+MqawLD/SwG6FRHhoTsneKfZbE/TSF94t+65MkoVvX X-Gm-Gg: ASbGncshyJfgRhW9iSNkfxAlqKuD+aCAlGhZxLK2yfhh2uant05PejaIMFYJkMosMdA S7DTGaLHrp9VeqshhEKFy46ycYy2snf94rcILwl4kvAEmdBUEvXlsI7F2DvYwIfOjbUSD+S1nZy gl7OubU7UTn6zDil9FJhzb5Qi/X3WmIx+oe0I3yxRgUmTHE9fvyGdTSIH9Sgxs/cevsVQyfPap7 unqmzf2TSMR1EMjXfBoDikJ6SyicqDPkta5A47T+yPACQcg311Yw01mrXm+aaqFDh+vakXcOXQc vVfje8s9DZ6/Qr8joa9vDYHIKl8se1jBtkFBrM1sbfmfVWGXXepwg9E1aQs2gjs31WwgSEScrt3 VpITKyj1vOEnNAg4ctvgT5s0T X-Google-Smtp-Source: AGHT+IF3Ek6iO4PYxtYKLThazbN2LB6KUW0Tmo9V03xxyHAX8IEpXOCaqbayQqhjyu1/kpycZ5YfOQ== X-Received: by 2002:a05:600c:3489:b0:43c:f0ae:da7 with SMTP id 5b1f17b1804b1-43ee0617025mr62016505e9.7.1743977715512; Sun, 06 Apr 2025 15:15:15 -0700 (PDT) Received: from localhost.localdomain (93-34-88-225.ip49.fastwebnet.it. [93.34.88.225]) by smtp.googlemail.com with ESMTPSA id 5b1f17b1804b1-43ec366aa29sm111517055e9.39.2025.04.06.15.15.14 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 06 Apr 2025 15:15:15 -0700 (PDT) From: Christian Marangi To: Andrew Lunn , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Rob Herring , Krzysztof Kozlowski , Conor Dooley , Lorenzo Bianconi , Heiner Kallweit , Russell King , Philipp Zabel , Christian Marangi , Daniel Golle , "Russell King (Oracle)" , netdev@vger.kernel.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-mediatek@lists.infradead.org, "Lei Wei (QUIC)" Subject: [RFC PATCH net-next v2 11/11] net: airoha: add phylink support for GDM2/3/4 Date: Mon, 7 Apr 2025 00:14:04 +0200 Message-ID: <20250406221423.9723-12-ansuelsmth@gmail.com> X-Mailer: git-send-email 2.48.1 In-Reply-To: <20250406221423.9723-1-ansuelsmth@gmail.com> References: <20250406221423.9723-1-ansuelsmth@gmail.com> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20250406_151517_415847_FEFD9AE3 X-CRM114-Status: GOOD ( 23.62 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org Add phylink support for GDM2/3/4 port that require configuration of the PCS to make the external PHY or attached SFP cage work. These needs to be defined in the GDM port node using the pcs-handle property. Signed-off-by: Christian Marangi --- drivers/net/ethernet/airoha/airoha_eth.c | 266 +++++++++++++++++++++- drivers/net/ethernet/airoha/airoha_eth.h | 4 + drivers/net/ethernet/airoha/airoha_regs.h | 12 + include/linux/pcs/pcs-airoha.h | 15 ++ 4 files changed, 296 insertions(+), 1 deletion(-) diff --git a/drivers/net/ethernet/airoha/airoha_eth.c b/drivers/net/ethernet/airoha/airoha_eth.c index c0a642568ac1..40d5d7cb1410 100644 --- a/drivers/net/ethernet/airoha/airoha_eth.c +++ b/drivers/net/ethernet/airoha/airoha_eth.c @@ -5,9 +5,13 @@ */ #include #include +#include #include #include +#include +#include #include +#include #include #include #include @@ -76,6 +80,11 @@ static bool airhoa_is_lan_gdm_port(struct airoha_gdm_port *port) return port->id == 1; } +static bool airhoa_is_phy_external(struct airoha_gdm_port *port) +{ + return port->id != 1; +} + static void airoha_set_macaddr(struct airoha_gdm_port *port, const u8 *addr) { struct airoha_eth *eth = port->qdma->eth; @@ -1535,6 +1544,17 @@ static int airoha_dev_open(struct net_device *dev) struct airoha_gdm_port *port = netdev_priv(dev); struct airoha_qdma *qdma = port->qdma; + if (airhoa_is_phy_external(port)) { + err = phylink_of_phy_connect(port->phylink, dev->dev.of_node, 0); + if (err) { + netdev_err(dev, "%s: could not attach PHY: %d\n", __func__, + err); + return err; + } + + phylink_start(port->phylink); + } + netif_tx_start_all_queues(dev); err = airoha_set_vip_for_gdm_port(port, true); if (err) @@ -1587,19 +1607,36 @@ static int airoha_dev_stop(struct net_device *dev) } } + if (airhoa_is_phy_external(port)) { + phylink_stop(port->phylink); + phylink_disconnect_phy(port->phylink); + } + return 0; } static int airoha_dev_set_macaddr(struct net_device *dev, void *p) { struct airoha_gdm_port *port = netdev_priv(dev); + const u8 *mac_addr = dev->dev_addr; int err; err = eth_mac_addr(dev, p); if (err) return err; - airoha_set_macaddr(port, dev->dev_addr); + airoha_set_macaddr(port, mac_addr); + + /* Update XFI mac address */ + if (airhoa_is_phy_external(port)) { + regmap_write(port->xfi_mac, AIROHA_PCS_XFI_MAC_XFI_MACADDRL, + FIELD_PREP(AIROHA_PCS_XFI_MAC_MACADDRL, + mac_addr[0] << 24 | mac_addr[1] << 16 | + mac_addr[2] << 8 | mac_addr[3])); + regmap_write(port->xfi_mac, AIROHA_PCS_XFI_MAC_XFI_MACADDRH, + FIELD_PREP(AIROHA_PCS_XFI_MAC_MACADDRH, + mac_addr[4] << 8 | mac_addr[5])); + } return 0; } @@ -2454,6 +2491,210 @@ static void airoha_metadata_dst_free(struct airoha_gdm_port *port) } } +static void airoha_mac_config(struct phylink_config *config, unsigned int mode, + const struct phylink_link_state *state) +{ + struct airoha_gdm_port *port = container_of(config, struct airoha_gdm_port, + phylink_config); + + /* Frag disable */ + regmap_update_bits(port->xfi_mac, AIROHA_PCS_XFI_MAC_XFI_GIB_CFG, + AIROHA_PCS_XFI_RX_FRAG_LEN, + FIELD_PREP(AIROHA_PCS_XFI_RX_FRAG_LEN, 31)); + regmap_update_bits(port->xfi_mac, AIROHA_PCS_XFI_MAC_XFI_GIB_CFG, + AIROHA_PCS_XFI_TX_FRAG_LEN, + FIELD_PREP(AIROHA_PCS_XFI_TX_FRAG_LEN, 31)); + + /* IPG NUM */ + regmap_update_bits(port->xfi_mac, AIROHA_PCS_XFI_MAC_XFI_GIB_CFG, + AIROHA_PCS_XFI_IPG_NUM, + FIELD_PREP(AIROHA_PCS_XFI_IPG_NUM, 10)); + + /* Enable TX/RX flow control */ + regmap_set_bits(port->xfi_mac, AIROHA_PCS_XFI_MAC_XFI_GIB_CFG, + AIROHA_PCS_XFI_TX_FC_EN); + regmap_set_bits(port->xfi_mac, AIROHA_PCS_XFI_MAC_XFI_GIB_CFG, + AIROHA_PCS_XFI_RX_FC_EN); +} + +static int airoha_mac_prepare(struct phylink_config *config, unsigned int mode, + phy_interface_t iface) +{ + struct airoha_gdm_port *port = container_of(config, struct airoha_gdm_port, + phylink_config); + + /* MPI MBI disable */ + regmap_set_bits(port->xfi_mac, AIROHA_PCS_XFI_MAC_XFI_GIB_CFG, + AIROHA_PCS_XFI_RXMPI_STOP | + AIROHA_PCS_XFI_RXMBI_STOP | + AIROHA_PCS_XFI_TXMPI_STOP | + AIROHA_PCS_XFI_TXMBI_STOP); + + /* Write 1 to trigger reset and clear */ + regmap_clear_bits(port->xfi_mac, AIROHA_PCS_XFI_MAC_XFI_LOGIC_RST, + AIROHA_PCS_XFI_MAC_LOGIC_RST); + regmap_set_bits(port->xfi_mac, AIROHA_PCS_XFI_MAC_XFI_LOGIC_RST, + AIROHA_PCS_XFI_MAC_LOGIC_RST); + + usleep_range(1000, 2000); + + /* Clear XFI MAC counter */ + regmap_set_bits(port->xfi_mac, AIROHA_PCS_XFI_MAC_XFI_CNT_CLR, + AIROHA_PCS_XFI_GLB_CNT_CLR); + + return 0; +} + +static void airoha_mac_link_down(struct phylink_config *config, unsigned int mode, + phy_interface_t interface) +{ + struct airoha_gdm_port *port = container_of(config, struct airoha_gdm_port, + phylink_config); + + /* MPI MBI disable */ + regmap_set_bits(port->xfi_mac, AIROHA_PCS_XFI_MAC_XFI_GIB_CFG, + AIROHA_PCS_XFI_RXMPI_STOP | + AIROHA_PCS_XFI_RXMBI_STOP | + AIROHA_PCS_XFI_TXMPI_STOP | + AIROHA_PCS_XFI_TXMBI_STOP); +} + +static void airoha_mac_link_up(struct phylink_config *config, struct phy_device *phy, + unsigned int mode, phy_interface_t interface, + int speed, int duplex, bool tx_pause, bool rx_pause) +{ + struct airoha_gdm_port *port = container_of(config, struct airoha_gdm_port, + phylink_config); + struct airoha_qdma *qdma = port->qdma; + struct airoha_eth *eth = qdma->eth; + u32 frag_size_tx, frag_size_rx; + + switch (speed) { + case SPEED_10000: + case SPEED_5000: + frag_size_tx = 8; + frag_size_rx = 8; + break; + case SPEED_2500: + frag_size_tx = 2; + frag_size_rx = 1; + break; + default: + frag_size_tx = 1; + frag_size_rx = 0; + } + + /* Configure TX/RX frag based on speed */ + if (port->id == 4) { + airoha_fe_rmw(eth, REG_GDMA4_TMBI_FRAG, GDMA4_SGMII0_TX_FRAG_SIZE, + FIELD_PREP(GDMA4_SGMII0_TX_FRAG_SIZE, frag_size_tx)); + + airoha_fe_rmw(eth, REG_GDMA4_RMBI_FRAG, GDMA4_SGMII0_RX_FRAG_SIZE, + FIELD_PREP(GDMA4_SGMII0_RX_FRAG_SIZE, frag_size_rx)); + } + + /* BPI BMI enable */ + regmap_clear_bits(port->xfi_mac, AIROHA_PCS_XFI_MAC_XFI_GIB_CFG, + AIROHA_PCS_XFI_RXMPI_STOP | + AIROHA_PCS_XFI_RXMBI_STOP | + AIROHA_PCS_XFI_TXMPI_STOP | + AIROHA_PCS_XFI_TXMBI_STOP); +} + +static const struct phylink_mac_ops airoha_phylink_ops = { + .mac_config = airoha_mac_config, + .mac_prepare = airoha_mac_prepare, + .mac_link_down = airoha_mac_link_down, + .mac_link_up = airoha_mac_link_up, +}; + +static int airoha_setup_phylink(struct net_device *dev) +{ + struct device_node *pcs_np, *np = dev->dev.of_node; + struct airoha_gdm_port *port = netdev_priv(dev); + struct phylink_pcs **available_pcs; + struct platform_device *pdev; + phy_interface_t phy_mode; + struct phylink *phylink; + unsigned int num_pcs; + int err; + + err = of_get_phy_mode(np, &phy_mode); + if (err) { + dev_err(&dev->dev, "incorrect phy-mode\n"); + return err; + } + + pcs_np = of_parse_phandle(np, "pcs-handle", 0); + if (!pcs_np) + return -ENODEV; + + if (!of_device_is_available(pcs_np)) { + of_node_put(pcs_np); + return -ENODEV; + } + + pdev = of_find_device_by_node(pcs_np); + of_node_put(pcs_np); + if (!pdev || !platform_get_drvdata(pdev)) { + if (pdev) + put_device(&pdev->dev); + return -EPROBE_DEFER; + } + + port->xfi_mac = dev_get_regmap(&pdev->dev, "xfi_mac"); + if (IS_ERR(port->xfi_mac)) + return PTR_ERR(port->xfi_mac); + + port->phylink_config.dev = &dev->dev; + port->phylink_config.type = PHYLINK_NETDEV; + port->phylink_config.mac_capabilities = MAC_ASYM_PAUSE | MAC_SYM_PAUSE | + MAC_10 | MAC_100 | MAC_1000 | MAC_2500FD | + MAC_5000FD | MAC_10000FD; + + err = fwnode_phylink_pcs_parse(dev_fwnode(&dev->dev), NULL, &num_pcs); + if (err) + return err; + + available_pcs = kcalloc(num_pcs, sizeof(*available_pcs), GFP_KERNEL); + if (!available_pcs) + return -ENOMEM; + + err = fwnode_phylink_pcs_parse(dev_fwnode(&dev->dev), available_pcs, + &num_pcs); + if (err) + goto out; + + port->phylink_config.available_pcs = available_pcs; + port->phylink_config.num_available_pcs = num_pcs; + + __set_bit(PHY_INTERFACE_MODE_SGMII, + port->phylink_config.supported_interfaces); + __set_bit(PHY_INTERFACE_MODE_1000BASEX, + port->phylink_config.supported_interfaces); + __set_bit(PHY_INTERFACE_MODE_2500BASEX, + port->phylink_config.supported_interfaces); + __set_bit(PHY_INTERFACE_MODE_USXGMII, + port->phylink_config.supported_interfaces); + + phy_interface_copy(port->phylink_config.pcs_interfaces, + port->phylink_config.supported_interfaces); + + phylink = phylink_create(&port->phylink_config, + of_fwnode_handle(np), + phy_mode, &airoha_phylink_ops); + if (IS_ERR(phylink)) { + err = PTR_ERR(phylink); + goto out; + } + + port->phylink = phylink; +out: + kfree(available_pcs); + + return err; +} + static int airoha_alloc_gdm_port(struct airoha_eth *eth, struct device_node *np, int index) { @@ -2532,6 +2773,23 @@ static int airoha_alloc_gdm_port(struct airoha_eth *eth, if (err) return err; + if (airhoa_is_phy_external(port)) { + const u8 *mac_addr = dev->dev_addr; + + err = airoha_setup_phylink(dev); + if (err) + return err; + + /* Setup XFI mac address */ + regmap_write(port->xfi_mac, AIROHA_PCS_XFI_MAC_XFI_MACADDRL, + FIELD_PREP(AIROHA_PCS_XFI_MAC_MACADDRL, + mac_addr[0] << 24 | mac_addr[1] << 16 | + mac_addr[2] << 8 | mac_addr[3])); + regmap_write(port->xfi_mac, AIROHA_PCS_XFI_MAC_XFI_MACADDRH, + FIELD_PREP(AIROHA_PCS_XFI_MAC_MACADDRH, + mac_addr[4] << 8 | mac_addr[5])); + } + return register_netdev(dev); } @@ -2626,6 +2884,9 @@ static int airoha_probe(struct platform_device *pdev) struct airoha_gdm_port *port = eth->ports[i]; if (port && port->dev->reg_state == NETREG_REGISTERED) { + if (airhoa_is_phy_external(port)) + phylink_destroy(port->phylink); + unregister_netdev(port->dev); airoha_metadata_dst_free(port); } @@ -2653,6 +2914,9 @@ static void airoha_remove(struct platform_device *pdev) continue; airoha_dev_stop(port->dev); + if (airhoa_is_phy_external(port)) + phylink_destroy(port->phylink); + unregister_netdev(port->dev); airoha_metadata_dst_free(port); } diff --git a/drivers/net/ethernet/airoha/airoha_eth.h b/drivers/net/ethernet/airoha/airoha_eth.h index 60690b685710..bc0cbeb6bd6d 100644 --- a/drivers/net/ethernet/airoha/airoha_eth.h +++ b/drivers/net/ethernet/airoha/airoha_eth.h @@ -460,6 +460,10 @@ struct airoha_gdm_port { struct net_device *dev; int id; + struct phylink *phylink; + struct phylink_config phylink_config; + struct regmap *xfi_mac; + struct airoha_hw_stats stats; DECLARE_BITMAP(qos_sq_bmap, AIROHA_NUM_QOS_CHANNELS); diff --git a/drivers/net/ethernet/airoha/airoha_regs.h b/drivers/net/ethernet/airoha/airoha_regs.h index 8146cde4e8ba..72f7824fcc2e 100644 --- a/drivers/net/ethernet/airoha/airoha_regs.h +++ b/drivers/net/ethernet/airoha/airoha_regs.h @@ -356,6 +356,18 @@ #define IP_FRAGMENT_PORT_MASK GENMASK(8, 5) #define IP_FRAGMENT_NBQ_MASK GENMASK(4, 0) +#define REG_GDMA4_TMBI_FRAG 0x2028 +#define GDMA4_SGMII1_TX_WEIGHT GENMASK(31, 26) +#define GDMA4_SGMII1_TX_FRAG_SIZE GENMASK(25, 16) +#define GDMA4_SGMII0_TX_WEIGHT GENMASK(15, 10) +#define GDMA4_SGMII0_TX_FRAG_SIZE GENMASK(9, 0) + +#define REG_GDMA4_RMBI_FRAG 0x202c +#define GDMA4_SGMII1_RX_WEIGHT GENMASK(31, 26) +#define GDMA4_SGMII1_RX_FRAG_SIZE GENMASK(25, 16) +#define GDMA4_SGMII0_RX_WEIGHT GENMASK(15, 10) +#define GDMA4_SGMII0_RX_FRAG_SIZE GENMASK(9, 0) + #define REG_MC_VLAN_EN 0x2100 #define MC_VLAN_EN_MASK BIT(0) diff --git a/include/linux/pcs/pcs-airoha.h b/include/linux/pcs/pcs-airoha.h index 07797645ff15..947dbcbc5206 100644 --- a/include/linux/pcs/pcs-airoha.h +++ b/include/linux/pcs/pcs-airoha.h @@ -5,7 +5,22 @@ /* XFI_MAC */ #define AIROHA_PCS_XFI_MAC_XFI_GIB_CFG 0x0 +#define AIROHA_PCS_XFI_RX_FRAG_LEN GENMASK(26, 22) +#define AIROHA_PCS_XFI_TX_FRAG_LEN GENMASK(21, 17) +#define AIROHA_PCS_XFI_IPG_NUM GENMASK(15, 10) #define AIROHA_PCS_XFI_TX_FC_EN BIT(5) #define AIROHA_PCS_XFI_RX_FC_EN BIT(4) +#define AIROHA_PCS_XFI_RXMPI_STOP BIT(3) +#define AIROHA_PCS_XFI_RXMBI_STOP BIT(2) +#define AIROHA_PCS_XFI_TXMPI_STOP BIT(1) +#define AIROHA_PCS_XFI_TXMBI_STOP BIT(0) +#define AIROHA_PCS_XFI_MAC_XFI_LOGIC_RST 0x10 +#define AIROHA_PCS_XFI_MAC_LOGIC_RST BIT(0) +#define AIROHA_PCS_XFI_MAC_XFI_MACADDRH 0x60 +#define AIROHA_PCS_XFI_MAC_MACADDRH GENMASK(15, 0) +#define AIROHA_PCS_XFI_MAC_XFI_MACADDRL 0x64 +#define AIROHA_PCS_XFI_MAC_MACADDRL GENMASK(31, 0) +#define AIROHA_PCS_XFI_MAC_XFI_CNT_CLR 0x100 +#define AIROHA_PCS_XFI_GLB_CNT_CLR BIT(0) #endif /* __LINUX_PCS_AIROHA_H */