From patchwork Sat Apr 6 20:13:28 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrew Lunn X-Patchwork-Id: 13619916 X-Patchwork-Delegate: kuba@kernel.org Received: from vps0.lunn.ch (vps0.lunn.ch [156.67.10.101]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 5BD8240BFE for ; Sat, 6 Apr 2024 20:14:03 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=156.67.10.101 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712434444; cv=none; b=rouFN3QBG/2ftFSjUs2TKN6PDEMYoPPI39mKQMmnwQqueDGReS0kdt8IdyJTLTyUF66D+iPhvAStnM9he7dvgLse7GRdpeJ11a9+3S94y246TyevIAQHys46jgFC1yxbCnwZ6hslzUqeLEcAyA8dE4SaOyluR6R5DuNG9ZCwY6E= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712434444; c=relaxed/simple; bh=dPK4yJ/wMTUGXfY11lM69yuurbQ4o+h92kvAzJWymQI=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=o4SD3Q4dyT7J332WdnTdFpMgSF5QAY42mN2oy5cXPDr5pfvob9c7Ev3eWtwTg00b7l6xy4YUlkc1oznGIl2ksFRaQ03mvXt+g6Wglo0R/wp6H+f19fZsNCPGX2mi3fh/sesqjcKX6dnfmicjA9gVWW4w99EJRj9grEXqcFUw0+4= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=lunn.ch; spf=pass smtp.mailfrom=lunn.ch; dkim=pass (1024-bit key) header.d=lunn.ch header.i=@lunn.ch header.b=lEGet9oK; arc=none smtp.client-ip=156.67.10.101 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=lunn.ch Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=lunn.ch Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=lunn.ch header.i=@lunn.ch header.b="lEGet9oK" DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lunn.ch; s=20171124; h=Cc:To:In-Reply-To:References:Message-Id: Content-Transfer-Encoding:Content-Type:MIME-Version:Subject:Date:From:From: Sender:Reply-To:Subject:Date:Message-ID:To:Cc:MIME-Version:Content-Type: Content-Transfer-Encoding:Content-ID:Content-Description:Content-Disposition: In-Reply-To:References; bh=l9yzCC1WmjUwoD3WEo32xMh7QV1dA91xU2AoG/lzElg=; b=lE Get9oKN/zOuw+AwAaOyeiKOyR1tjRoiW2q0ZbHNEvGQ+T/hXhYb8m57Lf6X3Bhrt4YIR4wqw+qgaI g6BDCFn18Byob3GEIGwFQEVdxDOTAEtq2qAAep7zzPUBzMGyQl6nSol6uW4pyOz056CANRAL4lwKI +yFJhPnULaBmZx8=; Received: from c-76-156-36-110.hsd1.mn.comcast.net ([76.156.36.110] helo=thinkpad.home.lunn.ch) by vps0.lunn.ch with esmtpsa (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1rtCQJ-00COA7-9K; Sat, 06 Apr 2024 22:13:59 +0200 From: Andrew Lunn Date: Sat, 06 Apr 2024 15:13:28 -0500 Subject: [PATCH net-next v4 1/8] net: dsa: consolidate setup and teardown for shared ports Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20240406-v6-8-0-net-next-mv88e6xxx-leds-v4-v4-1-eb97665e7f96@lunn.ch> References: <20240406-v6-8-0-net-next-mv88e6xxx-leds-v4-v4-0-eb97665e7f96@lunn.ch> In-Reply-To: <20240406-v6-8-0-net-next-mv88e6xxx-leds-v4-v4-0-eb97665e7f96@lunn.ch> To: Florian Fainelli , Vladimir Oltean , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Russell King , Gregory Clement Cc: netdev@vger.kernel.org, Andrew Lunn , Vladimir Oltean X-Mailer: b4 0.13.0 X-Developer-Signature: v=1; a=openpgp-sha256; l=1710; i=andrew@lunn.ch; h=from:subject:message-id; bh=8EbkyqPBZ3n1DjiPoB84kJWTcYoVICCluJIHblFC+i4=; b=owEBbQKS/ZANAwAKAea/DcumaUyEAcsmYgBmEaz+C9t1x42l3WIJJdM9XZTt3rjE4sjUUyijb 9AgLPCmahaJAjMEAAEKAB0WIQRh+xAly1MmORb54bfmvw3LpmlMhAUCZhGs/gAKCRDmvw3LpmlM hJZHD/9YHLf5GYcqrBEy/rVwIY+CyKyEimirBedTB18kF0iNfy5dvFBGMUyGX7cV/jxnc3L0+0O I4xKkoCNT6nXBs1+DlW31/h92w/xir9KyoIXljZlTlGy6wITqMdPN1BLeXDPVAwa+UIkFeXoezT Ifp/OBdZA7FNjR/A2YirrPb+QXmdxipn2m0FKTtuDPIKVU75RKFc/fM0bTxTwiNOBVo0nmJIb7p GxnmUdqfhbguC0XC+T0t+MkZ6I5AT5kXDfSB4Tr+HvhtLG21T3L/GJgBxv95/sAmlIeKuWj6KSg ms0O9hqXDz7RLr1PZBS5ZtChAk4uR+RBhzqgMGJ8yyGrmxtWU9Z3xYbkUVmpKr1ClzGsKUBQnBj dymgnecLD9iA0pfVtL4Ora4sDwULiAO1DvLl2cSAKbldFR3b0tjGdlrA1I7+9qC8jjtBnWP3lGg QuOV02tfHYjFKO4WaqmWS/nORBH7vTIlpfnsVgO1ZxcCmR3o3tMzczrfGqfEz1vOXOmf6b+eAZi 36y0WJd2QLADmQiXKAXVLvhUfIMYSBRL3ySupDF5t5nGFy3MS2ehnSUgqenqRCWXtCpnQTKGGF5 J9ww2TDBi8ICiIl2PI6Gs8Mom3q7otvsKw30g/198EbVnyOhi/s42qTz7gg+qxR7nLeCuM2Uv/V ttli+sBTefIwwXA== X-Developer-Key: i=andrew@lunn.ch; a=openpgp; fpr=61FB1025CB53263916F9E1B7E6BF0DCBA6694C84 X-Patchwork-Delegate: kuba@kernel.org From: Vladimir Oltean CPU and DSA ports have the same port setup and teardown logic, only the string that gets printed on error differs. Consolidate the code paths. Signed-off-by: Vladimir Oltean Signed-off-by: Andrew Lunn --- net/dsa/dsa.c | 24 ++---------------------- 1 file changed, 2 insertions(+), 22 deletions(-) diff --git a/net/dsa/dsa.c b/net/dsa/dsa.c index 09d2f5d4b3dd..64369fa5fd07 100644 --- a/net/dsa/dsa.c +++ b/net/dsa/dsa.c @@ -479,23 +479,6 @@ static int dsa_port_setup(struct dsa_port *dp) dsa_port_disable(dp); break; case DSA_PORT_TYPE_CPU: - if (dp->dn) { - err = dsa_shared_port_link_register_of(dp); - if (err) - break; - dsa_port_link_registered = true; - } else { - dev_warn(ds->dev, - "skipping link registration for CPU port %d\n", - dp->index); - } - - err = dsa_port_enable(dp, NULL); - if (err) - break; - dsa_port_enabled = true; - - break; case DSA_PORT_TYPE_DSA: if (dp->dn) { err = dsa_shared_port_link_register_of(dp); @@ -504,7 +487,8 @@ static int dsa_port_setup(struct dsa_port *dp) dsa_port_link_registered = true; } else { dev_warn(ds->dev, - "skipping link registration for DSA port %d\n", + "skipping link registration for %s port %d\n", + dsa_port_is_cpu(dp) ? "CPU" : "DSA", dp->index); } @@ -543,10 +527,6 @@ static void dsa_port_teardown(struct dsa_port *dp) case DSA_PORT_TYPE_UNUSED: break; case DSA_PORT_TYPE_CPU: - dsa_port_disable(dp); - if (dp->dn) - dsa_shared_port_link_unregister_of(dp); - break; case DSA_PORT_TYPE_DSA: dsa_port_disable(dp); if (dp->dn) From patchwork Sat Apr 6 20:13:29 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrew Lunn X-Patchwork-Id: 13619918 X-Patchwork-Delegate: kuba@kernel.org Received: from vps0.lunn.ch (vps0.lunn.ch [156.67.10.101]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 86C7E4C610 for ; Sat, 6 Apr 2024 20:14:04 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=156.67.10.101 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712434446; cv=none; b=GFKQLpQgTIskGhQN+NqAIkVyxkQC4S7dlk6qjH7kIDe9KYgAMdhBuDZdGXLKcpXnboJui8J4BRaKiCOBh4M0mf1dbPPvE6VqqiHS7s18t0ZfiTV+w5kf03TQ7cTzyMtjwxeUI4t5LYEMj6ycAl5aEainm9rULvNgxkoMKLy7JQU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712434446; c=relaxed/simple; bh=bE8D8/N3rAVLAFyNDOg7tStifl1F1eidOd4mG2J8mIA=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=DpyLkAVIfBuH4bzArAkPFWP4l9JzPS9zGB6OHUUvg2cMb61LdD05oiIu4JOxZNeKG5TW273gZd4TVwAD2iM7isoee9RdbqHZBFyYfDtQd9hYJp5yxSA03b7yWgIOpgWLHqBvVrFmI0DIFojjsLDLD/9vb1U6kymQKmAU/6DBPiM= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=lunn.ch; spf=pass smtp.mailfrom=lunn.ch; dkim=pass (1024-bit key) header.d=lunn.ch header.i=@lunn.ch header.b=UUNT1Gvz; arc=none smtp.client-ip=156.67.10.101 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=lunn.ch Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=lunn.ch Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=lunn.ch header.i=@lunn.ch header.b="UUNT1Gvz" DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lunn.ch; s=20171124; h=Cc:To:In-Reply-To:References:Message-Id: Content-Transfer-Encoding:Content-Type:MIME-Version:Subject:Date:From:From: Sender:Reply-To:Subject:Date:Message-ID:To:Cc:MIME-Version:Content-Type: Content-Transfer-Encoding:Content-ID:Content-Description:Content-Disposition: In-Reply-To:References; bh=ZzOptbSM+ThCI68o1UXhs7ybp5SEQu4+mvoh3ouFUcA=; b=UU NT1GvzoUUT53adKOrLPXPBCYvR7z2/MMYhw5Q7bPDWlsdXwH7WucHzOAi5NLeKknImep7MfN+YBno 4zo6GC0Um/LgGcy1xquuxelMt8eO1HT58GgVCourTRh7ShHQRLJrbUW4G/zPDNclaZmygiq6J5doJ arcnXawGYYhTBUk=; Received: from c-76-156-36-110.hsd1.mn.comcast.net ([76.156.36.110] helo=thinkpad.home.lunn.ch) by vps0.lunn.ch with esmtpsa (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1rtCQM-00COA7-5o; Sat, 06 Apr 2024 22:14:02 +0200 From: Andrew Lunn Date: Sat, 06 Apr 2024 15:13:29 -0500 Subject: [PATCH net-next v4 2/8] net: dsa: break out port setup and teardown code per port type Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20240406-v6-8-0-net-next-mv88e6xxx-leds-v4-v4-2-eb97665e7f96@lunn.ch> References: <20240406-v6-8-0-net-next-mv88e6xxx-leds-v4-v4-0-eb97665e7f96@lunn.ch> In-Reply-To: <20240406-v6-8-0-net-next-mv88e6xxx-leds-v4-v4-0-eb97665e7f96@lunn.ch> To: Florian Fainelli , Vladimir Oltean , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Russell King , Gregory Clement Cc: netdev@vger.kernel.org, Andrew Lunn , Vladimir Oltean X-Mailer: b4 0.13.0 X-Developer-Signature: v=1; a=openpgp-sha256; l=3791; i=andrew@lunn.ch; h=from:subject:message-id; bh=m4R+FzkPdG0f2iBbW8//G6Yqgb/4rK41MXzEqU3faJc=; b=owEBbQKS/ZANAwAKAea/DcumaUyEAcsmYgBmEaz/oWeYWZ7x19cv6BBmUR6zfoYns9XKlGdRj vTAt/lUxbyJAjMEAAEKAB0WIQRh+xAly1MmORb54bfmvw3LpmlMhAUCZhGs/wAKCRDmvw3LpmlM hJkSD/91j7Saqkbix9xbNxCp94OgeaaIL0L+DJFIRBzLkwheDHXViSFNNQJ9o+zuYDYVZPyDY0z Ra/VyVuZ2kFm3K98cjERcuMdoMZCnMWuXww7knZH0E3um2pyUKAPvCwzO1BOc6ZxiWFFFJcvFbo A5qLGTDcN3IsolKQozU8Fs81sistglgAQ8RGH9OJhr7GpKM3QFX0VcLXDDNSUsOoelaT3FQUEBe dtA2UNehudN2/N9Ka2P06I/PnlXbLurRDHT+oiQL1brrmN4ISXYtKq/o2fZEOhouQlKw38bzlmz aexPPxiHwsTUL9scTaVlk1kKpFpKwTiRMwQ+N9HaiR6US0WGkoMhPCg6EioAI6KWW38CQgF4ATs R/jMTllqZhmwTnLmtT2bnDA4B7sf3MGtLgy7E5HI4tslOzja9/gYRqHl+VZCh63nfXd/Sj3DRRS 1KVDDH0yxeCDo8clWW3SwWUDhSV7cIZgCx6olzIEaOsllt1X//Kopv1c6RjbM16URb6TIhXIcq3 GNxwUW4/IbEqh8v/jGxiL+xDXrthlE4WsuSdi8VeSqPRZRxF2uk7yDsvwN5Vl33Trh/Gc3GTMF7 B/bfR/FESAAu0paCe3mUSg8PdT5NFfJ4Nz7xPPE1NWnI7kG/fvBlQ+ZELDRa4LDA8civXQGu43f zwXZoKHBu3A5ThA== X-Developer-Key: i=andrew@lunn.ch; a=openpgp; fpr=61FB1025CB53263916F9E1B7E6BF0DCBA6694C84 X-Patchwork-Delegate: kuba@kernel.org From: Vladimir Oltean It is very hard to make changes to the control flow of dsa_port_setup(), and this is because the different port types need a different setup procedure. By breaking these out into separate functions, it becomes clearer what needs what, and how the teardown should look like. Signed-off-by: Vladimir Oltean Signed-off-by: Andrew Lunn --- net/dsa/dsa.c | 102 ++++++++++++++++++++++++++++++++++++++-------------------- 1 file changed, 67 insertions(+), 35 deletions(-) diff --git a/net/dsa/dsa.c b/net/dsa/dsa.c index 64369fa5fd07..5d65da9a1971 100644 --- a/net/dsa/dsa.c +++ b/net/dsa/dsa.c @@ -460,12 +460,69 @@ static void dsa_tree_teardown_cpu_ports(struct dsa_switch_tree *dst) dp->cpu_dp = NULL; } -static int dsa_port_setup(struct dsa_port *dp) +static int dsa_unused_port_setup(struct dsa_port *dp) +{ + dsa_port_disable(dp); + + return 0; +} + +static void dsa_unused_port_teardown(struct dsa_port *dp) +{ +} + +static int dsa_shared_port_setup(struct dsa_port *dp) { - bool dsa_port_link_registered = false; struct dsa_switch *ds = dp->ds; - bool dsa_port_enabled = false; - int err = 0; + bool link_registered = false; + int err; + + if (dp->dn) { + err = dsa_shared_port_link_register_of(dp); + if (err) + return err; + + link_registered = true; + } else { + dev_warn(ds->dev, + "skipping link registration for %s port %d\n", + dsa_port_is_cpu(dp) ? "CPU" : "DSA", + dp->index); + } + + err = dsa_port_enable(dp, NULL); + if (err && link_registered) + dsa_shared_port_link_unregister_of(dp); + + return err; +} + +static void dsa_shared_port_teardown(struct dsa_port *dp) +{ + dsa_port_disable(dp); + if (dp->dn) + dsa_shared_port_link_unregister_of(dp); +} + +static int dsa_user_port_setup(struct dsa_port *dp) +{ + of_get_mac_address(dp->dn, dp->mac); + + return dsa_user_create(dp); +} + +static void dsa_user_port_teardown(struct dsa_port *dp) +{ + if (!dp->user) + return; + + dsa_user_destroy(dp->user); + dp->user = NULL; +} + +static int dsa_port_setup(struct dsa_port *dp) +{ + int err; if (dp->setup) return 0; @@ -476,38 +533,17 @@ static int dsa_port_setup(struct dsa_port *dp) switch (dp->type) { case DSA_PORT_TYPE_UNUSED: - dsa_port_disable(dp); + err = dsa_unused_port_setup(dp); break; case DSA_PORT_TYPE_CPU: case DSA_PORT_TYPE_DSA: - if (dp->dn) { - err = dsa_shared_port_link_register_of(dp); - if (err) - break; - dsa_port_link_registered = true; - } else { - dev_warn(ds->dev, - "skipping link registration for %s port %d\n", - dsa_port_is_cpu(dp) ? "CPU" : "DSA", - dp->index); - } - - err = dsa_port_enable(dp, NULL); - if (err) - break; - dsa_port_enabled = true; - + err = dsa_shared_port_setup(dp); break; case DSA_PORT_TYPE_USER: - of_get_mac_address(dp->dn, dp->mac); - err = dsa_user_create(dp); + err = dsa_user_port_setup(dp); break; } - if (err && dsa_port_enabled) - dsa_port_disable(dp); - if (err && dsa_port_link_registered) - dsa_shared_port_link_unregister_of(dp); if (err) { dsa_port_devlink_teardown(dp); return err; @@ -525,18 +561,14 @@ static void dsa_port_teardown(struct dsa_port *dp) switch (dp->type) { case DSA_PORT_TYPE_UNUSED: + dsa_unused_port_teardown(dp); break; case DSA_PORT_TYPE_CPU: case DSA_PORT_TYPE_DSA: - dsa_port_disable(dp); - if (dp->dn) - dsa_shared_port_link_unregister_of(dp); + dsa_shared_port_teardown(dp); break; case DSA_PORT_TYPE_USER: - if (dp->user) { - dsa_user_destroy(dp->user); - dp->user = NULL; - } + dsa_user_port_teardown(dp); break; } From patchwork Sat Apr 6 20:13:30 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrew Lunn X-Patchwork-Id: 13619919 X-Patchwork-Delegate: kuba@kernel.org Received: from vps0.lunn.ch (vps0.lunn.ch [156.67.10.101]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 6DAAB4EB43 for ; Sat, 6 Apr 2024 20:14:07 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=156.67.10.101 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712434449; cv=none; b=Zo8V7FuIy7Fz7sNyfZHcURZe5KeBoI1MMzMz/wLcSoCRJQsGaERVAWnzbffc2cI7f/T7Ia3nm37OLa5vQYxdJLtWMnyZ6NEpN4yWnw3GPdjQg2B+56F8PtmXDTNmRK8tgIS7vpFWMRAjU7uGhH9VKla5AZg6YdTwOisJQ+z+1WA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712434449; c=relaxed/simple; bh=p7dt1sYAFleXe7WJbo7I++W2evAAUObqgPZGrVymRS0=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=GAJbgCQND+B3Ed5sv8U8EKR24Vmo4e2ObLqZfKt2vCwZxpasW1sidEbGFcVCiBDZWLH78jRNJ0J5KQ8l8LQiDe6x2FJcgTP3EL2eqx0e1B5mq1haHea/41aManx0y9HUY4QhNiNJFgJA7kZB//5n2fS4hW70ziSUw8yo/AyXb18= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=lunn.ch; spf=pass smtp.mailfrom=lunn.ch; dkim=pass (1024-bit key) header.d=lunn.ch header.i=@lunn.ch header.b=P+cQMZJF; arc=none smtp.client-ip=156.67.10.101 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=lunn.ch Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=lunn.ch Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=lunn.ch header.i=@lunn.ch header.b="P+cQMZJF" DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lunn.ch; s=20171124; h=Cc:To:In-Reply-To:References:Message-Id: Content-Transfer-Encoding:Content-Type:MIME-Version:Subject:Date:From:From: Sender:Reply-To:Subject:Date:Message-ID:To:Cc:MIME-Version:Content-Type: Content-Transfer-Encoding:Content-ID:Content-Description:Content-Disposition: In-Reply-To:References; bh=HzFEEq0e1hj2eRrvH4HUFfwK1pjYzpPU5ffG+djjhUA=; b=P+ cQMZJFnHw4+Gvw0/fMXkKT2JUpFP1vfSjVcrb0PHTLPJE7cH5L8EGsoyjLrFpycztViDxSZsPdC7C NAZUBLi2QASZFs9wDIVQYRjSXkWugcLfyj20FESp0K2Y/HW7aAFBkKvZqnhHYJ09UcjnlVpwCY0hY QRp8tjbTDhiGj74=; Received: from c-76-156-36-110.hsd1.mn.comcast.net ([76.156.36.110] helo=thinkpad.home.lunn.ch) by vps0.lunn.ch with esmtpsa (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1rtCQP-00COA7-1c; Sat, 06 Apr 2024 22:14:05 +0200 From: Andrew Lunn Date: Sat, 06 Apr 2024 15:13:30 -0500 Subject: [PATCH net-next v4 3/8] net: dsa: move call to driver port_setup after creation of netdev Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20240406-v6-8-0-net-next-mv88e6xxx-leds-v4-v4-3-eb97665e7f96@lunn.ch> References: <20240406-v6-8-0-net-next-mv88e6xxx-leds-v4-v4-0-eb97665e7f96@lunn.ch> In-Reply-To: <20240406-v6-8-0-net-next-mv88e6xxx-leds-v4-v4-0-eb97665e7f96@lunn.ch> To: Florian Fainelli , Vladimir Oltean , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Russell King , Gregory Clement Cc: netdev@vger.kernel.org, Andrew Lunn , Vladimir Oltean X-Mailer: b4 0.13.0 X-Developer-Signature: v=1; a=openpgp-sha256; l=4470; i=andrew@lunn.ch; h=from:subject:message-id; bh=BGV2AxUQLBPNtICKS0EgkQ3O7rWT8QxXcz7h1ZGAEIs=; b=owEBbQKS/ZANAwAKAea/DcumaUyEAcsmYgBmEaz/BS5RJTeqRhCZ0GsQ+8sYy9CZ8NUnudeLV QRgR9nrLgeJAjMEAAEKAB0WIQRh+xAly1MmORb54bfmvw3LpmlMhAUCZhGs/wAKCRDmvw3LpmlM hKANEACkl73pNnvroDWqYtroWDTw/nFp7I3HWhEHhu295RAOs8OkPvhXgNFAkH5uI5h2QgLhWiv waADTLNMqgLU6ejQ8kyZT+XGDsRCRecv/HGhZLLjZFk2SmPOoShkhlconxh7vNDP+YM7T7fSnJR +LE7g6Jyuqx/1lGiXLmT2jNuoJfhXmzb8tDN7b+vXig4lq6+noRgdwyBlYY11l/ApGNaL2TwhHD VkIkqpjaahyVNFyGw2z8YV1/WtitVplt4qpR9VEWdMQKxGG59UaOhI+WCFH1JdkWDcFsilyCch2 4Uotn5Lt9ywwf34wEx4XmxG+xkXDDU9I25fbf5NhbdTHRQ1ctZnpPYO6PmtXa/SHiIAE+RMHJq1 8srrS0p8Sb95RXELQPwx5VxmGZrwapiiAhR9YzZOHlamekSl/iNmfOAfRgqtL+h9YFj/cGhTE2c NVp6lMe0SVKJG+rSjVVTmskwzo5tUB5nX10pszQ6WyBDsUxbG2D3MhH91Jn3mOQwuYxdszrgEce fSchPNpte+yUV5iyWzEZbZK4iSfrIKzfROfKNGlD6J30BJR3XEtZ61twKIGJpqpEhNqyFXjZnXS PZ6L6Dzj0s5X4MlzDhC7rqL4ioTTyb8IZzZ3CZCiMmcAKosvmojGDmZF8GWUOZALi2Yulz0tIlB ti/OOXIgFzpdyFg== X-Developer-Key: i=andrew@lunn.ch; a=openpgp; fpr=61FB1025CB53263916F9E1B7E6BF0DCBA6694C84 X-Patchwork-Delegate: kuba@kernel.org From: Vladimir Oltean The driver-facing method port_setup() is a good place to add the LEDs of a port to the netdev representing the port. However, when port_setup() is called in dsa_port_devlink_setup(), the netdev does not exist yet. That only happens in dsa_user_create(), which is later in dsa_port_setup(). Move the call to port_setup() out of dsa_port_devlink_setup() and to the end of dsa_port_setup() where the netdev will exist. For the other port types, the call to port_setup() and port_teardown() remains where it was before (functionally speaking), but now it needs to be open-coded in their respective setup/teardown logic. Signed-off-by: Vladimir Oltean Signed-off-by: Andrew Lunn --- net/dsa/devlink.c | 17 +--------------- net/dsa/dsa.c | 59 +++++++++++++++++++++++++++++++++++++++++++++++++++++-- 2 files changed, 58 insertions(+), 18 deletions(-) diff --git a/net/dsa/devlink.c b/net/dsa/devlink.c index 431bf52290a1..9c3dc6319269 100644 --- a/net/dsa/devlink.c +++ b/net/dsa/devlink.c @@ -294,20 +294,12 @@ int dsa_port_devlink_setup(struct dsa_port *dp) struct dsa_switch_tree *dst = dp->ds->dst; struct devlink_port_attrs attrs = {}; struct devlink *dl = dp->ds->devlink; - struct dsa_switch *ds = dp->ds; const unsigned char *id; unsigned char len; - int err; memset(dlp, 0, sizeof(*dlp)); devlink_port_init(dl, dlp); - if (ds->ops->port_setup) { - err = ds->ops->port_setup(ds, dp->index); - if (err) - return err; - } - id = (const unsigned char *)&dst->index; len = sizeof(dst->index); @@ -331,14 +323,7 @@ int dsa_port_devlink_setup(struct dsa_port *dp) } devlink_port_attrs_set(dlp, &attrs); - err = devlink_port_register(dl, dlp, dp->index); - if (err) { - if (ds->ops->port_teardown) - ds->ops->port_teardown(ds, dp->index); - return err; - } - - return 0; + return devlink_port_register(dl, dlp, dp->index); } void dsa_port_devlink_teardown(struct dsa_port *dp) diff --git a/net/dsa/dsa.c b/net/dsa/dsa.c index 5d65da9a1971..d8aa869e17ba 100644 --- a/net/dsa/dsa.c +++ b/net/dsa/dsa.c @@ -462,6 +462,15 @@ static void dsa_tree_teardown_cpu_ports(struct dsa_switch_tree *dst) static int dsa_unused_port_setup(struct dsa_port *dp) { + struct dsa_switch *ds = dp->ds; + int err; + + if (ds->ops->port_setup) { + err = ds->ops->port_setup(ds, dp->index); + if (err) + return err; + } + dsa_port_disable(dp); return 0; @@ -469,6 +478,10 @@ static int dsa_unused_port_setup(struct dsa_port *dp) static void dsa_unused_port_teardown(struct dsa_port *dp) { + struct dsa_switch *ds = dp->ds; + + if (ds->ops->port_teardown) + ds->ops->port_teardown(ds, dp->index); } static int dsa_shared_port_setup(struct dsa_port *dp) @@ -490,8 +503,23 @@ static int dsa_shared_port_setup(struct dsa_port *dp) dp->index); } + if (ds->ops->port_setup) { + err = ds->ops->port_setup(ds, dp->index); + if (err) + goto unregister_link; + } + err = dsa_port_enable(dp, NULL); - if (err && link_registered) + if (err) + goto port_teardown; + + return 0; + +port_teardown: + if (ds->ops->port_teardown) + ds->ops->port_teardown(ds, dp->index); +unregister_link: + if (link_registered) dsa_shared_port_link_unregister_of(dp); return err; @@ -499,23 +527,50 @@ static int dsa_shared_port_setup(struct dsa_port *dp) static void dsa_shared_port_teardown(struct dsa_port *dp) { + struct dsa_switch *ds = dp->ds; + dsa_port_disable(dp); + if (ds->ops->port_teardown) + ds->ops->port_teardown(ds, dp->index); if (dp->dn) dsa_shared_port_link_unregister_of(dp); } static int dsa_user_port_setup(struct dsa_port *dp) { + struct dsa_switch *ds = dp->ds; + int err; + of_get_mac_address(dp->dn, dp->mac); - return dsa_user_create(dp); + err = dsa_user_create(dp); + if (err) + return err; + + if (ds->ops->port_setup) { + err = ds->ops->port_setup(ds, dp->index); + if (err) + goto user_destroy; + } + + return 0; + +user_destroy: + dsa_user_destroy(dp->user); + dp->user = NULL; + return err; } static void dsa_user_port_teardown(struct dsa_port *dp) { + struct dsa_switch *ds = dp->ds; + if (!dp->user) return; + if (ds->ops->port_teardown) + ds->ops->port_teardown(ds, dp->index); + dsa_user_destroy(dp->user); dp->user = NULL; } From patchwork Sat Apr 6 20:13:31 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrew Lunn X-Patchwork-Id: 13619920 X-Patchwork-Delegate: kuba@kernel.org Received: from vps0.lunn.ch (vps0.lunn.ch [156.67.10.101]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id E2CBC4EB55 for ; Sat, 6 Apr 2024 20:14:09 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=156.67.10.101 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712434451; cv=none; b=sQdqD6KefBjoMG1tRW7FFhCvgfIduZCXMotcOsKwfqiijef7OHT8o6j9g19mRViXNpThSrXIANDJ/EGhWVcAhL+o8AblcvJhxo6C9NIifgwSYM3xQRk9mYkLiq9S4VcwIdXSwPSx+dhiRp9DFz0mnCFIjW/9lC/iPPVDyw9Lq0w= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712434451; c=relaxed/simple; bh=5c/LeEUlIOtE+8gy1/iUzzqk5iYILTlD+nwjHKT76NQ=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=qOgwr8VRip90Qmj4Dv7iN6UhmvpLm1D5GhIAKQ3aEIblj67ZaulEfS9U3IKBeU8Ru2fUVcZWJuU7vKWD3CqnQlHwezDg9t2EsoJbJVdxJRsGwCjNWLiRJPoHGcwYJfrLttbByAqvnWn9xXFmKIBRAomOa4tqsD7OjHSzU5tfIZ8= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=lunn.ch; spf=pass smtp.mailfrom=lunn.ch; dkim=pass (1024-bit key) header.d=lunn.ch header.i=@lunn.ch header.b=JmiLBtFz; arc=none smtp.client-ip=156.67.10.101 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=lunn.ch Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=lunn.ch Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=lunn.ch header.i=@lunn.ch header.b="JmiLBtFz" DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lunn.ch; s=20171124; h=Cc:To:In-Reply-To:References:Message-Id: Content-Transfer-Encoding:Content-Type:MIME-Version:Subject:Date:From:From: Sender:Reply-To:Subject:Date:Message-ID:To:Cc:MIME-Version:Content-Type: Content-Transfer-Encoding:Content-ID:Content-Description:Content-Disposition: In-Reply-To:References; bh=uWtW/XSwpo6clFLMk/FD9MvkIl41Cc/iKiNTFPUgXss=; b=Jm iLBtFzK06Jdwv6/oP1I7X8pS6QXkPABOV8FUB7DqT/d+pXtD5CQs1kWDiSNWwP8VYk4rkYv8rE5WC s5CpOyqlWv82tCi7jzOS0fjEonNikDrRW5ih9nDYVdj8SkGNe3A2R2oRcOCC90HAyzWJPI3hZJEaC ex1DhdscyHtp86U=; Received: from c-76-156-36-110.hsd1.mn.comcast.net ([76.156.36.110] helo=thinkpad.home.lunn.ch) by vps0.lunn.ch with esmtpsa (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1rtCQR-00COA7-Mz; Sat, 06 Apr 2024 22:14:07 +0200 From: Andrew Lunn Date: Sat, 06 Apr 2024 15:13:31 -0500 Subject: [PATCH net-next v4 4/8] net: Add helpers for netdev LEDs Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20240406-v6-8-0-net-next-mv88e6xxx-leds-v4-v4-4-eb97665e7f96@lunn.ch> References: <20240406-v6-8-0-net-next-mv88e6xxx-leds-v4-v4-0-eb97665e7f96@lunn.ch> In-Reply-To: <20240406-v6-8-0-net-next-mv88e6xxx-leds-v4-v4-0-eb97665e7f96@lunn.ch> To: Florian Fainelli , Vladimir Oltean , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Russell King , Gregory Clement Cc: netdev@vger.kernel.org, Andrew Lunn X-Mailer: b4 0.13.0 X-Developer-Signature: v=1; a=openpgp-sha256; l=9120; i=andrew@lunn.ch; h=from:subject:message-id; bh=5c/LeEUlIOtE+8gy1/iUzzqk5iYILTlD+nwjHKT76NQ=; b=owEBbQKS/ZANAwAKAea/DcumaUyEAcsmYgBmEaz/uKh+V3LO7v4F+8eqm92GE9i0a8jJVrCia 1aDL3QhpHKJAjMEAAEKAB0WIQRh+xAly1MmORb54bfmvw3LpmlMhAUCZhGs/wAKCRDmvw3LpmlM hKw8EACno28OT1ZiOqNB04JGNShM48rtF/p2e/vH0uKBYCs3GD0ZFOqDrWt9nvjIugR946b7g2/ /sphgunymLsGD1dbxbZfILAU4ntA9yVvNc67Z1JrWrkJzYrYfSQ9nryEVJ81ZAHAILIxYaj8D2x 4qO4nAyJXwfYJtepRhCZaS/S0GxpN/NjXfWA0X1iB+fJsoyKXByGR1ljQOsIq1VMazFTy77NKxl YzGwTuyK5vyj0YuyVQxJbrmGdCoJ7pagtyR0Mi2gi7CIylk0L1ynbq5hRkpA2r2EHPIJeGXasGM t/nf0g7oNm9q72Ih9vXwnjmCuTHnCUazsgLKjJAt4MknsRU05BxdysERAoEQ8dQ9Qj6usG23kwY wOM2/pU/CirFXm211ctI/GNz7Iq/H8E7cfI1M+Ky2CG0qiyXPB0Z+Y5blMVgKOrYA2qLFEn2OUB gLwJExmd5339e6CK42zYIxDGmouszBdVqSqObKAwExforZ94DxrG2gZ/K80FMyQ9cZR6QmhKxml Sbgtz0X+uc7T8PUGuCqDuaPFHpchMM/u4c6SS7U417Vb/1oP70pIx+I5BPHeyYBYTWdESC3itgZ wrcVL63tjMKnhzLsL3zzHNLs/LAYCoz2vgaZL0jivrHsCCC3DrI4sK4M7ZT2HDDyW0paaxmGG2H WWtZc6aY1jeLipg== X-Developer-Key: i=andrew@lunn.ch; a=openpgp; fpr=61FB1025CB53263916F9E1B7E6BF0DCBA6694C84 X-Patchwork-Delegate: kuba@kernel.org Add a set of helpers for parsing the standard device tree properties for LEDs as part of an ethernet device, and registering them with the LED subsystem. This code can be used by any sort of netdev driver, including plain MAC, DSA switches or pure switchdev switch driver. The MAC driver should call netdev_leds_teardown() before destroying the netdev to ensure the ops cannot be called after unbinding the device. Signed-off-by: Andrew Lunn --- include/net/netdev_leds.h | 50 ++++++++++++ net/Kconfig | 11 +++ net/core/Makefile | 1 + net/core/netdev-leds.c | 199 ++++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 261 insertions(+) diff --git a/include/net/netdev_leds.h b/include/net/netdev_leds.h new file mode 100644 index 000000000000..30053891561c --- /dev/null +++ b/include/net/netdev_leds.h @@ -0,0 +1,50 @@ +/* SPDX-License-Identifier: GPL-2.0+ */ +/* + * Helpers used for creating and managing LEDs on a netdev MAC + * driver. + */ + +#ifndef _NET_NETDEV_LEDS_H +#define _NET_NETDEV_LEDS_H + +#include +#include + +struct net_device; +struct list_head; + +struct netdev_leds_ops { + int (*brightness_set)(struct net_device *ndev, u8 led, + enum led_brightness brightness); + int (*blink_set)(struct net_device *ndev, u8 led, + unsigned long *delay_on, unsigned long *delay_off); + int (*hw_control_is_supported)(struct net_device *ndev, u8 led, + unsigned long flags); + int (*hw_control_set)(struct net_device *ndev, u8 led, + unsigned long flags); + int (*hw_control_get)(struct net_device *ndev, u8 led, + unsigned long *flags); +}; + +#ifdef CONFIG_NETDEV_LEDS +int netdev_leds_setup(struct net_device *ndev, struct device_node *np, + struct list_head *list, struct netdev_leds_ops *ops, + int max_leds); + +void netdev_leds_teardown(struct list_head *list); + +#else +static inline int netdev_leds_setup(struct net_device *ndev, + struct device_node *np, + struct list_head *list, + struct netdev_leds_ops *ops) +{ + return 0; +} + +static inline void netdev_leds_teardown(struct list_head *list) +{ +} +#endif /* CONFIG_NETDEV_LEDS */ + +#endif /* _NET_PORT_LEDS_H */ diff --git a/net/Kconfig b/net/Kconfig index 3e57ccf0da27..5301b95744cd 100644 --- a/net/Kconfig +++ b/net/Kconfig @@ -516,4 +516,15 @@ config NET_TEST If unsure, say N. +config NETDEV_LEDS + bool "NETDEV helper code for MAC LEDs" + select LEDS_CLASS + select LEDS_TRIGGERS + select LEDS_TRIGGER_NETDEV + help + NICs and switches often contain LED controllers. When the LEDs + are part of the MAC, the MAC driver, aka netdev driver, should + make the LEDs available. NETDEV_LEDS offers a small library + of code to help MAC drivers do this. + endif # if NET diff --git a/net/core/Makefile b/net/core/Makefile index 21d6fbc7e884..d04ce07541b5 100644 --- a/net/core/Makefile +++ b/net/core/Makefile @@ -42,3 +42,4 @@ obj-$(CONFIG_BPF_SYSCALL) += sock_map.o obj-$(CONFIG_BPF_SYSCALL) += bpf_sk_storage.o obj-$(CONFIG_OF) += of_net.o obj-$(CONFIG_NET_TEST) += net_test.o +obj-$(CONFIG_NETDEV_LEDS) += netdev-leds.o diff --git a/net/core/netdev-leds.c b/net/core/netdev-leds.c new file mode 100644 index 000000000000..bea981ff42ea --- /dev/null +++ b/net/core/netdev-leds.c @@ -0,0 +1,199 @@ +// SPDX-License-Identifier: GPL-2.0+ + +#include +#include +#include +#include +#include +#include +#include + +struct netdev_led { + struct list_head led_list; + struct led_classdev led_cdev; + struct netdev_leds_ops *ops; + struct net_device *ndev; + u8 index; +}; + +#define to_netdev_led(d) container_of(d, struct netdev_led, led_cdev) + +static int netdev_brightness_set(struct led_classdev *led_cdev, + enum led_brightness value) +{ + struct netdev_led *netdev_led = to_netdev_led(led_cdev); + + return netdev_led->ops->brightness_set(netdev_led->ndev, + netdev_led->index, + value); +} + +static int netdev_blink_set(struct led_classdev *led_cdev, + unsigned long *delay_on, unsigned long *delay_off) +{ + struct netdev_led *netdev_led = to_netdev_led(led_cdev); + + return netdev_led->ops->blink_set(netdev_led->ndev, + netdev_led->index, + delay_on, delay_off); +} + +static __maybe_unused int +netdev_hw_control_is_supported(struct led_classdev *led_cdev, + unsigned long flags) +{ + struct netdev_led *netdev_led = to_netdev_led(led_cdev); + + return netdev_led->ops->hw_control_is_supported(netdev_led->ndev, + netdev_led->index, + flags); +} + +static __maybe_unused int netdev_hw_control_set(struct led_classdev *led_cdev, + unsigned long flags) +{ + struct netdev_led *netdev_led = to_netdev_led(led_cdev); + + return netdev_led->ops->hw_control_set(netdev_led->ndev, + netdev_led->index, + flags); +} + +static __maybe_unused int netdev_hw_control_get(struct led_classdev *led_cdev, + unsigned long *flags) +{ + struct netdev_led *netdev_led = to_netdev_led(led_cdev); + + return netdev_led->ops->hw_control_get(netdev_led->ndev, + netdev_led->index, + flags); +} + +static struct device * +netdev_hw_control_get_device(struct led_classdev *led_cdev) +{ + struct netdev_led *netdev_led = to_netdev_led(led_cdev); + + return &netdev_led->ndev->dev; +} + +static int netdev_led_setup(struct net_device *ndev, struct device_node *led, + struct list_head *list, struct netdev_leds_ops *ops, + int max_leds) +{ + struct led_init_data init_data = {}; + struct device *dev = &ndev->dev; + struct netdev_led *netdev_led; + struct led_classdev *cdev; + u32 index; + int err; + + netdev_led = kzalloc(sizeof(*netdev_led), GFP_KERNEL); + if (!netdev_led) + return -ENOMEM; + + netdev_led->ndev = ndev; + netdev_led->ops = ops; + cdev = &netdev_led->led_cdev; + + err = of_property_read_u32(led, "reg", &index); + if (err) + return err; + + if (index >= max_leds) + return -EINVAL; + + netdev_led->index = index; + + if (ops->brightness_set) + cdev->brightness_set_blocking = netdev_brightness_set; + if (ops->blink_set) + cdev->blink_set = netdev_blink_set; +#ifdef CONFIG_LEDS_TRIGGERS + if (ops->hw_control_is_supported) + cdev->hw_control_is_supported = netdev_hw_control_is_supported; + if (ops->hw_control_set) + cdev->hw_control_set = netdev_hw_control_set; + if (ops->hw_control_get) + cdev->hw_control_get = netdev_hw_control_get; + cdev->hw_control_trigger = "netdev"; +#endif + cdev->hw_control_get_device = netdev_hw_control_get_device; + cdev->max_brightness = 1; + init_data.fwnode = of_fwnode_handle(led); + init_data.devname_mandatory = true; + + init_data.devicename = dev_name(dev); + err = led_classdev_register_ext(dev, cdev, &init_data); + if (err) + return err; + + INIT_LIST_HEAD(&netdev_led->led_list); + list_add(&netdev_led->led_list, list); + + return 0; +} + +/** + * netdev_leds_setup - Parse DT node and create LEDs for netdev + * + * @ndev: struct netdev for the MAC + * @np: ethernet-node in device tree + * @list: list to add LEDs to + * @ops: structure of ops to manipulate the LED. + * @max_leds: maximum number of LEDs support by netdev. + * + * Parse the device tree node, as described in + * ethernet-controller.yaml, and find any LEDs. For each LED found, + * ensure the reg value is less than max_leds, create an LED and + * register it with the LED subsystem. The LED will be added to the + * list, which should be unique to the netdev. The ops structure + * contains the callbacks needed to control the LEDs. + * + * Return 0 in success, otherwise an negative error code. + */ +int netdev_leds_setup(struct net_device *ndev, struct device_node *np, + struct list_head *list, struct netdev_leds_ops *ops, + int max_leds) +{ + struct device_node *leds, *led; + int err; + + leds = of_get_child_by_name(np, "leds"); + if (!leds) + return 0; + + for_each_available_child_of_node(leds, led) { + err = netdev_led_setup(ndev, led, list, ops, max_leds); + if (err) { + of_node_put(leds); + of_node_put(led); + return err; + } + } + of_node_put(leds); + + return 0; +} +EXPORT_SYMBOL_GPL(netdev_leds_setup); + +/** + * netdev_leds_teardown - Remove LEDs for a netdev + * + * @list: list to add LEDs to teardown + * + * Unregister all LEDs from the given list of LEDS, freeing up any + * allocated memory. + */ +void netdev_leds_teardown(struct list_head *list) +{ + struct netdev_led *netdev_led; + struct led_classdev *cdev; + + list_for_each_entry(netdev_led, list, led_list) { + cdev = &netdev_led->led_cdev; + led_classdev_unregister(cdev); + kfree(netdev_led); + } +} +EXPORT_SYMBOL_GPL(netdev_leds_teardown); From patchwork Sat Apr 6 20:13:32 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrew Lunn X-Patchwork-Id: 13619921 X-Patchwork-Delegate: kuba@kernel.org Received: from vps0.lunn.ch (vps0.lunn.ch [156.67.10.101]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 718654F1F1 for ; Sat, 6 Apr 2024 20:14:12 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=156.67.10.101 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712434454; cv=none; b=pPHIBu1vaoTQvL2FU1jca3UtecDxVN/L8WGt9cY6uX7WYbe7PGd+hfRiSH+nNVkGgcUOpJjbbWl9vW7ffr6+CNATdyW0JFtTHv6qUoVgGc/hF22Kjt+WVeyvMQBg5fhIKC+KTO2iAWdwguhQPrhPegSYe0xljumEHg8C0A6nWL4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712434454; c=relaxed/simple; bh=Ba8ZRPcHIpN0lalX1MJan4IYyVadQnFD5BsiVvTcBu0=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=c8y7rwoG5S3t2oryxPCYUAR0YhJbFabeWETkRZRxeKoVlYQxdUEdoi/pqnfDUnx0wcMszHhSpe8XvrCJ6NXf1BTgCKkPHy8m9CeVQCdFi5SPtiPRze+o3PVK4s6wgqZGmqeOPcly83Ou51BMk03LApWlAj4zkrCO2Fq+mJyLYEM= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=lunn.ch; spf=pass smtp.mailfrom=lunn.ch; dkim=pass (1024-bit key) header.d=lunn.ch header.i=@lunn.ch header.b=I8doBuUP; arc=none smtp.client-ip=156.67.10.101 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=lunn.ch Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=lunn.ch Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=lunn.ch header.i=@lunn.ch header.b="I8doBuUP" DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lunn.ch; s=20171124; h=Cc:To:In-Reply-To:References:Message-Id: Content-Transfer-Encoding:Content-Type:MIME-Version:Subject:Date:From:From: Sender:Reply-To:Subject:Date:Message-ID:To:Cc:MIME-Version:Content-Type: Content-Transfer-Encoding:Content-ID:Content-Description:Content-Disposition: In-Reply-To:References; bh=horO3WQSlmE1YpmKxwySgRee+ScV5A7WgNw1ql2FvsM=; b=I8 doBuUPj1WvlqLlx/S7F0/FofZ1G5IVqtho6gbiOf0lLmOXS0yhMHZ8TKfJCEG6kCFOvYV3c/7f20C Z1AYOeBkIxTbMjM4CIsPAZAWt+l4aHF0YIcpu4loLlz8vYvw87ZYSlFKn5hcJKhPACJGVQS3dqh/d OTlcN11/JJ0xnPY=; Received: from c-76-156-36-110.hsd1.mn.comcast.net ([76.156.36.110] helo=thinkpad.home.lunn.ch) by vps0.lunn.ch with esmtpsa (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1rtCQU-00COA7-C3; Sat, 06 Apr 2024 22:14:10 +0200 From: Andrew Lunn Date: Sat, 06 Apr 2024 15:13:32 -0500 Subject: [PATCH net-next v4 5/8] net: dsa: mv88e6xxx: Add helpers for 6352 LED blink and brightness Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20240406-v6-8-0-net-next-mv88e6xxx-leds-v4-v4-5-eb97665e7f96@lunn.ch> References: <20240406-v6-8-0-net-next-mv88e6xxx-leds-v4-v4-0-eb97665e7f96@lunn.ch> In-Reply-To: <20240406-v6-8-0-net-next-mv88e6xxx-leds-v4-v4-0-eb97665e7f96@lunn.ch> To: Florian Fainelli , Vladimir Oltean , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Russell King , Gregory Clement Cc: netdev@vger.kernel.org, Andrew Lunn X-Mailer: b4 0.13.0 X-Developer-Signature: v=1; a=openpgp-sha256; l=8530; i=andrew@lunn.ch; h=from:subject:message-id; bh=Ba8ZRPcHIpN0lalX1MJan4IYyVadQnFD5BsiVvTcBu0=; b=owEBbQKS/ZANAwAKAea/DcumaUyEAcsmYgBmEa0A9FaU/dk2swNAx/Tdc98Ng6k+Y0ckA/lY8 Sv3N5xWTk2JAjMEAAEKAB0WIQRh+xAly1MmORb54bfmvw3LpmlMhAUCZhGtAAAKCRDmvw3LpmlM hPvuD/9cvuyPVyvbKeGWCxDOQL+395j7WteZq8NczjPv3A10/3lzPhe+6QZbgB2qrwa5ZHdfVJU owlAVaEGeu03Fhf2+kmf6nOVf0UxFsgzGQNNguafSy6cPuDabPy/CRMVnWdJF50IwxFqUT0OmYM m4dgP7Dz3UbMiq+Knlm88KS2bIhZ6ExSf0h6gUdfllUUmGMup9kTyhw56QGyswvnGOUwtlvGTnz YWlhoVY/ppiIrPwPavGE2pRORg+c57Es4X5FfcmCO1QKWegP1y685ab8L1RPBXvFFtAnz4GRZEI sedfy1UQKrW0YgxbaOV/2vGpt08o6nG+tRT6i8uyZA+XrlOSPCfDhmwQQOcIElIC08bbb1D5jjJ aXvILkr8PMt1Z+iB8iRCK1u/D+KaAkC4Ui+A55SZvu//FZ95KqSOH+/nxXfuiSGwllphfYIqpsY QwP1e41e5W8kWCZjATD/dDgNwfJksnLkJG8qm+RMIyj2kQoM6RGuD9TNeOUy21vjyp7D+KGXeER ToD9EgLfqROv4XmiO8YU7thYDfQ+dPpYJpksKEd/mhBng//n5xexMacw0kF4CU5eEqQRq/+Hc6+ RsxTd5tqZRBl85I7DfaCG3k0nyNylmsQNyOtbMPJ9CGLYwLfLnXx4I5WlFXC1n1OskwyHWnzPVM cYIZ/EHvLtwHGGA== X-Developer-Key: i=andrew@lunn.ch; a=openpgp; fpr=61FB1025CB53263916F9E1B7E6BF0DCBA6694C84 X-Patchwork-Delegate: kuba@kernel.org The 6352 family has two LEDs per port for ports 0-4. Ports 5 and 6 share a couple of LEDs. Add support functions to set the brightness, i.e. on or off, and to make the LEDs blink at a fixed rate. Signed-off-by: Andrew Lunn --- drivers/net/dsa/mv88e6xxx/port.c | 93 ++++++++++++++++++++++++++++++++++++++++ drivers/net/dsa/mv88e6xxx/port.h | 76 +++++++++++++++++++++++++++++++- 2 files changed, 168 insertions(+), 1 deletion(-) diff --git a/drivers/net/dsa/mv88e6xxx/port.c b/drivers/net/dsa/mv88e6xxx/port.c index 5394a8cf7bf1..37315a4aa9cf 100644 --- a/drivers/net/dsa/mv88e6xxx/port.c +++ b/drivers/net/dsa/mv88e6xxx/port.c @@ -1723,3 +1723,96 @@ int mv88e6393x_port_set_policy(struct mv88e6xxx_chip *chip, int port, return mv88e6393x_port_policy_write(chip, port, ptr, reg); } + +/* Offset 0x16: LED Control Register */ + +static int mv88e6352_port_led_write(struct mv88e6xxx_chip *chip, int port, + u16 pointer, u16 data) +{ + u16 reg = MV88E6352_PORT_LED_CTL_UPDATE | pointer | data; + + return mv88e6xxx_port_write(chip, port, MV88E6352_PORT_LED_CTL, reg); +} + +static int mv88e6352_port_led_read(struct mv88e6xxx_chip *chip, int port, + u16 pointer, u16 *data) +{ + int err; + u16 val; + + err = mv88e6xxx_port_write(chip, port, MV88E6352_PORT_LED_CTL, pointer); + if (err) + return err; + + err = mv88e6xxx_port_read(chip, port, MV88E6352_PORT_LED_CTL, &val); + if (err) + return err; + + *data = val & MV88E6352_PORT_LED_CTL_DATA_MASK; + + return 0; +} + +int mv88e6352_port_led_brightness_set(struct mv88e6xxx_chip *chip, int port, + u8 led, enum led_brightness value) +{ + int err; + u16 val; + + if (port > 5) + return -EOPNOTSUPP; + + err = mv88e6352_port_led_read(chip, port, + MV88E6352_PORT_LED_CTL_PTR_LED01, + &val); + if (err) + return err; + + if (led == 0) { + val &= ~MV88E6352_PORT_LED_CTL_DATA_LED01_LED0_MASK; + if (value) + val |= MV88E6352_PORT_LED_CTL_DATA_LED01_LED0_ON; + else + val |= MV88E6352_PORT_LED_CTL_DATA_LED01_LED0_OFF; + } else { + val &= ~MV88E6352_PORT_LED_CTL_DATA_LED01_LED1_MASK; + if (value) + val |= MV88E6352_PORT_LED_CTL_DATA_LED01_LED1_ON; + else + val |= MV88E6352_PORT_LED_CTL_DATA_LED01_LED1_OFF; + } + return mv88e6352_port_led_write(chip, port, + MV88E6352_PORT_LED_CTL_PTR_LED01, + val); +} + +int mv88e6352_port_led_blink_set(struct mv88e6xxx_chip *chip, int port, u8 led, + unsigned long *delay_on, + unsigned long *delay_off) +{ + int err; + u16 val; + + if (port > 5) + return -EOPNOTSUPP; + + /* Reset default is 84ms */ + *delay_on = 84 / 2; + *delay_off = 84 / 2; + err = mv88e6352_port_led_read(chip, port, + MV88E6352_PORT_LED_CTL_PTR_LED01, + &val); + if (err) + return err; + + if (led == 0) { + val &= ~MV88E6352_PORT_LED_CTL_DATA_LED01_LED0_MASK; + val |= MV88E6352_PORT_LED_CTL_DATA_LED01_LED0_BLINK; + } else { + val &= ~MV88E6352_PORT_LED_CTL_DATA_LED01_LED1_MASK; + val |= MV88E6352_PORT_LED_CTL_DATA_LED01_LED1_BLINK; + } + return mv88e6352_port_led_write(chip, port, + MV88E6352_PORT_LED_CTL_PTR_LED01, + val); +} diff --git a/drivers/net/dsa/mv88e6xxx/port.h b/drivers/net/dsa/mv88e6xxx/port.h index 86deeb347cbc..72556e4d154c 100644 --- a/drivers/net/dsa/mv88e6xxx/port.h +++ b/drivers/net/dsa/mv88e6xxx/port.h @@ -294,6 +294,76 @@ /* Offset 0x13: OutFiltered Counter */ #define MV88E6XXX_PORT_OUT_FILTERED 0x13 +/* Offset 0x16: LED Control */ +#define MV88E6352_PORT_LED_CTL 0x16 +#define MV88E6352_PORT_LED_CTL_UPDATE 0x8000 +#define MV88E6352_PORT_LED_CTL_PTR_LED01 0x0000 +#define MV88E6352_PORT_LED_CTL_PTR_STRETCH_BLINK 0x6000 +#define MV88E6352_PORT_LED_CTL_PTR_SPECIAL 0x7000 +#define MV88E6352_PORT_LED_CTL_DATA_MASK 0x03ff +/* Ports 0-4 */ +#define MV88E6352_PORT_LED_CTL_DATA_LED01_LED1_P2_SPECIAL 0x0000 +#define MV88E6352_PORT_LED_CTL_DATA_LED01_LED1_10_100_ACT 0x0010 +#define MV88E6352_PORT_LED_CTL_DATA_LED01_LED1_1000 0x0030 +#define MV88E6352_PORT_LED_CTL_DATA_LED01_LED1_P1_SPECIAL 0x0040 +#define MV88E6352_PORT_LED_CTL_DATA_LED01_LED1_10_1000_ACT 0x0060 +#define MV88E6352_PORT_LED_CTL_DATA_LED01_LED1_10_1000 0x0070 +#define MV88E6352_PORT_LED_CTL_DATA_LED01_LED1_ACT 0x0080 +#define MV88E6352_PORT_LED_CTL_DATA_LED01_LED1_100 0x0090 +#define MV88E6352_PORT_LED_CTL_DATA_LED01_LED1_100_ACT 0x00A0 +#define MV88E6352_PORT_LED_CTL_DATA_LED01_LED1_10_100 0x00B0 +#define MV88E6352_PORT_LED_CTL_DATA_LED01_LED1_PTP_ACT 0x00C0 +#define MV88E6352_PORT_LED_CTL_DATA_LED01_LED1_BLINK 0x00D0 +#define MV88E6352_PORT_LED_CTL_DATA_LED01_LED1_OFF 0x00E0 +#define MV88E6352_PORT_LED_CTL_DATA_LED01_LED1_ON 0x00F0 +#define MV88E6352_PORT_LED_CTL_DATA_LED01_LED1_MASK 0x00F0 +#define MV88E6352_PORT_LED_CTL_DATA_LED01_LED1_LINK_ACT 0x0000 +#define MV88E6352_PORT_LED_CTL_DATA_LED01_LED0_100_1000_ACT 0x0001 +#define MV88E6352_PORT_LED_CTL_DATA_LED01_LED0_1000_ACT 0x0002 +#define MV88E6352_PORT_LED_CTL_DATA_LED01_LED0_LINK_ACT 0x0003 +#define MV88E6352_PORT_LED_CTL_DATA_LED01_LED0_P0_SPECIAL 0x0004 +#define MV88E6352_PORT_LED_CTL_DATA_LED01_LED0_DUPLEX_COL 0x0006 +#define MV88E6352_PORT_LED_CTL_DATA_LED01_LED0_10_1000_ACT 0x0007 +#define MV88E6352_PORT_LED_CTL_DATA_LED01_LED0_LINK 0x0008 +#define MV88E6352_PORT_LED_CTL_DATA_LED01_LED0_10 0x0009 +#define MV88E6352_PORT_LED_CTL_DATA_LED01_LED0_10_ACT 0x000A +#define MV88E6352_PORT_LED_CTL_DATA_LED01_LED0_100_1000 0x000B +#define MV88E6352_PORT_LED_CTL_DATA_LED01_LED0_PTP_ACT 0x000C +#define MV88E6352_PORT_LED_CTL_DATA_LED01_LED0_BLINK 0x000D +#define MV88E6352_PORT_LED_CTL_DATA_LED01_LED0_OFF 0x000E +#define MV88E6352_PORT_LED_CTL_DATA_LED01_LED0_ON 0x000F +#define MV88E6352_PORT_LED_CTL_DATA_LED01_LED0_MASK 0x000F + +/* Port 5 */ +#define MV88E6352_PORT_LED_CTL_DATA5_LED01_LED1_P6_ACT 0x0000 +#define MV88E6352_PORT_LED_CTL_DATA5_LED01_LED1_FIBER_1000_ACT 0x0010 +#define MV88E6352_PORT_LED_CTL_DATA5_LED01_LED1_FIBER_100_ACT 0x0020 +#define MV88E6352_PORT_LED_CTL_DATA5_LED01_LED1_FIBER 0x0030 +#define MV88E6352_PORT_LED_CTL_DATA5_LED01_LED1_P5_ACT 0x0040 +#define MV88E6352_PORT_LED_CTL_DATA5_LED01_LED1_P6_LINK 0x0050 +#define MV88E6352_PORT_LED_CTL_DATA5_LED01_LED1_P6_DUPLEX_COL 0x0060 +#define MV88E6352_PORT_LED_CTL_DATA5_LED01_LED1_P6_LINK_ACT 0x0070 +#define MV88E6352_PORT_LED_CTL_DATA5_LED01_LED1_P0_SPECIAL 0x0080 +#define MV88E6352_PORT_LED_CTL_DATA5_LED01_LED1_P1_SPECIAL 0x0090 +#define MV88E6352_PORT_LED_CTL_DATA5_LED01_LED1_P2_SPECIAL 0x00A0 +#define MV88E6352_PORT_LED_CTL_DATA5_LED01_LED1_P6_PTP_ACT 0x00C0 +#define MV88E6352_PORT_LED_CTL_DATA5_LED01_LED1_BLINK 0x00D0 +#define MV88E6352_PORT_LED_CTL_DATA5_LED01_LED1_OFF 0x00E0 +#define MV88E6352_PORT_LED_CTL_DATA5_LED01_LED1_ON 0x00F0 +#define MV88E6352_PORT_LED_CTL_DATA5_LED01_LED1_P5_LINK_ACT 0x0000 +#define MV88E6352_PORT_LED_CTL_DATA5_LED01_LED0_FIBER_100_ACT 0x0001 +#define MV88E6352_PORT_LED_CTL_DATA5_LED01_LED0_FIBER_1000_ACT 0x0002 +#define MV88E6352_PORT_LED_CTL_DATA5_LED01_LED0_P0_SPECIAL 0x0003 +#define MV88E6352_PORT_LED_CTL_DATA5_LED01_LED0_P1_SPECIAL 0x0004 +#define MV88E6352_PORT_LED_CTL_DATA5_LED01_LED0_P2_SPECIAL 0x0005 +#define MV88E6352_PORT_LED_CTL_DATA5_LED01_LED0_P5_DUPLEX_COL 0x0006 +#define MV88E6352_PORT_LED_CTL_DATA5_LED01_LED0_P5_LINK_ACT 0x0007 +#define MV88E6352_PORT_LED_CTL_DATA5_LED01_LED0_P6_LINK_ACT 0x0008 +#define MV88E6352_PORT_LED_CTL_DATA5_LED01_LED0_BLINK 0x000D +#define MV88E6352_PORT_LED_CTL_DATA5_LED01_LED0_OFF 0x000E +#define MV88E6352_PORT_LED_CTL_DATA5_LED01_LED0_ON 0x000F +/* Port 6 does not have any LEDs */ + /* Offset 0x18: IEEE Priority Mapping Table */ #define MV88E6390_PORT_IEEE_PRIO_MAP_TABLE 0x18 #define MV88E6390_PORT_IEEE_PRIO_MAP_TABLE_UPDATE 0x8000 @@ -459,5 +529,9 @@ int mv88e6xxx_port_hidden_write(struct mv88e6xxx_chip *chip, int block, int mv88e6xxx_port_hidden_wait(struct mv88e6xxx_chip *chip); int mv88e6xxx_port_hidden_read(struct mv88e6xxx_chip *chip, int block, int port, int reg, u16 *val); - +int mv88e6352_port_led_brightness_set(struct mv88e6xxx_chip *chip, int port, + u8 led, enum led_brightness value); +int mv88e6352_port_led_blink_set(struct mv88e6xxx_chip *chip, int port, u8 led, + unsigned long *delay_on, + unsigned long *delay_off); #endif /* _MV88E6XXX_PORT_H */ From patchwork Sat Apr 6 20:13:33 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrew Lunn X-Patchwork-Id: 13619922 X-Patchwork-Delegate: kuba@kernel.org Received: from vps0.lunn.ch (vps0.lunn.ch [156.67.10.101]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 1BDE44EB55 for ; Sat, 6 Apr 2024 20:14:14 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=156.67.10.101 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712434456; cv=none; b=TucN+3NeATUFZjdqXDN/M2BmRo/UeLcQWDkJTItPCmavbZ20c2usuuhuh9QpyLqfCFbhnampxrMFEoxBal/UhLaC5F7QoQqZUcYAdy91lck/K3phHdv1pYdov24o460jyFHRGo7Agy60U5Bcjhsl/AC+ag4XcT6QvE42l3v3NNg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712434456; c=relaxed/simple; bh=7REgVx3Hk+G70l5YOIE6zqEavzl38e/93gZxmXsSzgA=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=TnSJDuKy+PYs/jLlnpTrfDeY3ZqSycPd+3aOwamqGMdkv4I6wuB4Pmkng+0/8WJMY1lj1sueRoNikJYg1L3hdpMNiB93qB8jmGaXazxpfMzKJoDssuxIaQKCvPFjNabXFcq48GOuQ2nzGO9KWLBxW9VGgtWET+Y5y5nzXubgjsw= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=lunn.ch; spf=pass smtp.mailfrom=lunn.ch; dkim=pass (1024-bit key) header.d=lunn.ch header.i=@lunn.ch header.b=CA6hejSZ; arc=none smtp.client-ip=156.67.10.101 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=lunn.ch Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=lunn.ch Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=lunn.ch header.i=@lunn.ch header.b="CA6hejSZ" DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lunn.ch; s=20171124; h=Cc:To:In-Reply-To:References:Message-Id: Content-Transfer-Encoding:Content-Type:MIME-Version:Subject:Date:From:From: Sender:Reply-To:Subject:Date:Message-ID:To:Cc:MIME-Version:Content-Type: Content-Transfer-Encoding:Content-ID:Content-Description:Content-Disposition: In-Reply-To:References; bh=iHiJcTca4uqI5eVNh//6Wjc2B/iJjDsQUALvb+o+t0E=; b=CA 6hejSZpXcCohrnhilAAXy7vuCSd6Hv+/67dtsgEaVjHfNYBpT5/fCF7e/7oa782R7+Y2fXdAspoTe DeuccLdUloA/wPn79toguTBEV+2ofAAaxdO+1BGsDSMoIcS48PV3E+6d3d+mlC1TFSM8DZky7P4e7 OkUdwH0f8JPZjHA=; Received: from c-76-156-36-110.hsd1.mn.comcast.net ([76.156.36.110] helo=thinkpad.home.lunn.ch) by vps0.lunn.ch with esmtpsa (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1rtCQX-00COA7-1A; Sat, 06 Apr 2024 22:14:13 +0200 From: Andrew Lunn Date: Sat, 06 Apr 2024 15:13:33 -0500 Subject: [PATCH net-next v4 6/8] net: dsa: mv88e6xxx: Tie the low level LED functions to device ops Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20240406-v6-8-0-net-next-mv88e6xxx-leds-v4-v4-6-eb97665e7f96@lunn.ch> References: <20240406-v6-8-0-net-next-mv88e6xxx-leds-v4-v4-0-eb97665e7f96@lunn.ch> In-Reply-To: <20240406-v6-8-0-net-next-mv88e6xxx-leds-v4-v4-0-eb97665e7f96@lunn.ch> To: Florian Fainelli , Vladimir Oltean , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Russell King , Gregory Clement Cc: netdev@vger.kernel.org, Andrew Lunn X-Mailer: b4 0.13.0 X-Developer-Signature: v=1; a=openpgp-sha256; l=2653; i=andrew@lunn.ch; h=from:subject:message-id; bh=7REgVx3Hk+G70l5YOIE6zqEavzl38e/93gZxmXsSzgA=; b=owEBbQKS/ZANAwAKAea/DcumaUyEAcsmYgBmEa0AIoXnHYGwc/vXgqKM6A7W8nJwed2gaKLQm ArTsPfZMliJAjMEAAEKAB0WIQRh+xAly1MmORb54bfmvw3LpmlMhAUCZhGtAAAKCRDmvw3LpmlM hFd/D/92AWTD4vJ4zr4KpGZA2CoZ43Ur/qp4D4Lm+sANe3O1/kntagidATmeh+5lRh8nO+2zmMc +ZX2a3Mf7Nhf6Hh1RcKyXNObvGgAFy6UMPTAEIf+2aH6GSLXV3mnAKWEvNNJGADSCy78WkmEzfv 3UyvB9zBGzZrMHvgR90QGTbqoOE66ha9P7fG6yS9tuonKMzcmGdNW0T24b2RaB7i3BNs5cppv9C uw26cbfcyvJcnNa9PwfcrtjCQIiHuqyb6tRL2RDPYROanypMONMy0PN+MqtH+fiIwmw3/L0Chbx FDiUPBM0HhqiA3UrqDMH0UFYeNaoVz5v7LzyII3j3oanEjceBSWPR2j78E1klGPM+PK2ZFhHzSW UwioxbL0Le45JDba3DHR1rGO36Vc5M9ZDhKRoC4Z23kVFbW4Maxv+JwRxD4aB+VKRzzeumRqYll 7ViIKVo/K6UfVtJoQCrgTOWjop0xKV0Gi+c/juZ04dctyTmfdXgmW/VvVatY9watAICKawrtww1 vuWXiJAArXgA3F4Tm14+5e5xmPqgLQMJWBSroWL3FuBKSqR+he4rphXH+AG7UuLkdKnOdwFX6tH dBX3RTqLrvEWQTjpvtknTdcyuhOl3PEl9sTfOpNUXbfIYQvQgJ8U2YB+YtxwI1H3o+MT0lSgO3q ckEGztNlqbIanfQ== X-Developer-Key: i=andrew@lunn.ch; a=openpgp; fpr=61FB1025CB53263916F9E1B7E6BF0DCBA6694C84 X-Patchwork-Delegate: kuba@kernel.org Make the LED brightness and blink helpers available for the 6352 family via their ops structure. Signed-off-by: Andrew Lunn --- drivers/net/dsa/mv88e6xxx/chip.c | 8 ++++++++ drivers/net/dsa/mv88e6xxx/chip.h | 7 +++++++ 2 files changed, 15 insertions(+) diff --git a/drivers/net/dsa/mv88e6xxx/chip.c b/drivers/net/dsa/mv88e6xxx/chip.c index 9ed1821184ec..3d7e4aa9293a 100644 --- a/drivers/net/dsa/mv88e6xxx/chip.c +++ b/drivers/net/dsa/mv88e6xxx/chip.c @@ -4526,6 +4526,8 @@ static const struct mv88e6xxx_ops mv88e6172_ops = { .gpio_ops = &mv88e6352_gpio_ops, .phylink_get_caps = mv88e6352_phylink_get_caps, .pcs_ops = &mv88e6352_pcs_ops, + .led_brightness_set = mv88e6352_port_led_brightness_set, + .led_blink_set = mv88e6352_port_led_blink_set, }; static const struct mv88e6xxx_ops mv88e6175_ops = { @@ -4628,6 +4630,8 @@ static const struct mv88e6xxx_ops mv88e6176_ops = { .gpio_ops = &mv88e6352_gpio_ops, .phylink_get_caps = mv88e6352_phylink_get_caps, .pcs_ops = &mv88e6352_pcs_ops, + .led_brightness_set = mv88e6352_port_led_brightness_set, + .led_blink_set = mv88e6352_port_led_blink_set, }; static const struct mv88e6xxx_ops mv88e6185_ops = { @@ -4897,6 +4901,8 @@ static const struct mv88e6xxx_ops mv88e6240_ops = { .ptp_ops = &mv88e6352_ptp_ops, .phylink_get_caps = mv88e6352_phylink_get_caps, .pcs_ops = &mv88e6352_pcs_ops, + .led_brightness_set = mv88e6352_port_led_brightness_set, + .led_blink_set = mv88e6352_port_led_blink_set, }; static const struct mv88e6xxx_ops mv88e6250_ops = { @@ -5310,6 +5316,8 @@ static const struct mv88e6xxx_ops mv88e6352_ops = { .serdes_set_tx_amplitude = mv88e6352_serdes_set_tx_amplitude, .phylink_get_caps = mv88e6352_phylink_get_caps, .pcs_ops = &mv88e6352_pcs_ops, + .led_brightness_set = mv88e6352_port_led_brightness_set, + .led_blink_set = mv88e6352_port_led_blink_set, }; static const struct mv88e6xxx_ops mv88e6390_ops = { diff --git a/drivers/net/dsa/mv88e6xxx/chip.h b/drivers/net/dsa/mv88e6xxx/chip.h index 85eb293381a7..64f8bde68ccf 100644 --- a/drivers/net/dsa/mv88e6xxx/chip.h +++ b/drivers/net/dsa/mv88e6xxx/chip.h @@ -661,6 +661,13 @@ struct mv88e6xxx_ops { /* Max Frame Size */ int (*set_max_frame_size)(struct mv88e6xxx_chip *chip, int mtu); + + /* LEDs */ + int (*led_brightness_set)(struct mv88e6xxx_chip *chip, int port, + u8 led, enum led_brightness value); + int (*led_blink_set)(struct mv88e6xxx_chip *chip, int port, u8 led, + unsigned long *delay_on, + unsigned long *delay_off); }; struct mv88e6xxx_irq_ops { From patchwork Sat Apr 6 20:13:34 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrew Lunn X-Patchwork-Id: 13619923 X-Patchwork-Delegate: kuba@kernel.org Received: from vps0.lunn.ch (vps0.lunn.ch [156.67.10.101]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id B1B164F5F9 for ; Sat, 6 Apr 2024 20:14:17 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=156.67.10.101 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712434459; cv=none; b=Td84mTR9fo35YgAlyKDXQ/sHfJQj7zaJAQ5Lq0DG4PB0a8RfQ/Sl3Ht8wS8ldpfR7CLwvgflJKl1y3bP8LhqOPqrZAM5zRa2YYidoNLQ3to3vMAd7yXU9hdaXFCDolJ0cz2qd1iqgrN/JlbFb4HvO7gUIPxDkv86F8T5CpmRHYQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712434459; c=relaxed/simple; bh=zdSFNxjfLA1vj0wL9Qk7dYbfsefbjxh136VgsdiSg3s=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=eK3qYuJeXMYR5eaVS98xVX7vrYQfye4T8yVuVAp3xseg/t5qfgCSMFgd13ua0cJgoneCEG8pMhImOsxJ8wuQiZu2Jc/MbKR+2sd8LoVKGzJ7EmqoWw+Q5W+nBsF0WHEt5TMotMh/vsCjelpYzdrG87vrBvyToliLFpD56N8q2Ng= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=lunn.ch; spf=pass smtp.mailfrom=lunn.ch; dkim=pass (1024-bit key) header.d=lunn.ch header.i=@lunn.ch header.b=M4d/j/XQ; arc=none smtp.client-ip=156.67.10.101 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=lunn.ch Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=lunn.ch Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=lunn.ch header.i=@lunn.ch header.b="M4d/j/XQ" DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lunn.ch; s=20171124; h=Cc:To:In-Reply-To:References:Message-Id: Content-Transfer-Encoding:Content-Type:MIME-Version:Subject:Date:From:From: Sender:Reply-To:Subject:Date:Message-ID:To:Cc:MIME-Version:Content-Type: Content-Transfer-Encoding:Content-ID:Content-Description:Content-Disposition: In-Reply-To:References; bh=Oqh2XRP/MH/MweeMUWi+g8QbT8VLHwXzrU+lz6qGOH4=; b=M4 d/j/XQRFuOrPW2mUrqmkcG0AqiOZNrgBDnBJG/TJyYPGrint4iRehKt7OKwYfoinuqPYCyVsMIyqi mUN70aBO70MYWaVXzh//gkYL38A9ln9PVshkqZElHKbmM+M/aajEqDtgrVQpw837UVN/nyJZAK96O gZbbFYz1jG2V6vI=; Received: from c-76-156-36-110.hsd1.mn.comcast.net ([76.156.36.110] helo=thinkpad.home.lunn.ch) by vps0.lunn.ch with esmtpsa (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1rtCQZ-00COA7-Ma; Sat, 06 Apr 2024 22:14:15 +0200 From: Andrew Lunn Date: Sat, 06 Apr 2024 15:13:34 -0500 Subject: [PATCH net-next v4 7/8] dsa: mv88e6xxx: Create port/netdev LEDs Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20240406-v6-8-0-net-next-mv88e6xxx-leds-v4-v4-7-eb97665e7f96@lunn.ch> References: <20240406-v6-8-0-net-next-mv88e6xxx-leds-v4-v4-0-eb97665e7f96@lunn.ch> In-Reply-To: <20240406-v6-8-0-net-next-mv88e6xxx-leds-v4-v4-0-eb97665e7f96@lunn.ch> To: Florian Fainelli , Vladimir Oltean , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Russell King , Gregory Clement Cc: netdev@vger.kernel.org, Andrew Lunn X-Mailer: b4 0.13.0 X-Developer-Signature: v=1; a=openpgp-sha256; l=6865; i=andrew@lunn.ch; h=from:subject:message-id; bh=zdSFNxjfLA1vj0wL9Qk7dYbfsefbjxh136VgsdiSg3s=; b=owEBbQKS/ZANAwAKAea/DcumaUyEAcsmYgBmEa0A1GTEDn8nTNCdd6O2tOppxe4UwhAGEE1bJ 2M8x0Mn4siJAjMEAAEKAB0WIQRh+xAly1MmORb54bfmvw3LpmlMhAUCZhGtAAAKCRDmvw3LpmlM hBDgEACjznnHWJx48FGisZW4GAVzSSl19fLaObfL/uG3e9J9/ggBuz30/J8ZOXFqx9NC/xK4eJu iQyhM+auHk7yJvpXIeds4YHNseFHLiveUGc6dx5qMuJbHKVieU/50//rrP7yM7A9YLBUEl4zHWT 5oSBRXSiiQfSDN0ZJNFPn+Lsyyuli9YY7RMUgoum4ZIDSUBgyin75wkhC+coGnT0vKfxc8mURE9 sRPAiL1VoixJt/eOdhY7eRy0YbI4pXu2BM3+myBH9GEjQstvITFfMTUzI9sNNe+7lo/JU/5DWKz kTQ3CDb8Otb2V+VxOFnC3w2Dh8wPiK4LubQywJ1tTYv0tZriipQuWUikqdOZAmnWgDxuzq3ejKi V42A9m7kFQBwvOplW2zcsIjQNZdaty2PrDTpB8l9MmQM3eGNTaZX4xzt6pRmElPxQgRVdwlyDtx T43Z0qgyHSKFnetGFYX0rlV/UZXuYU15VsP6O2g9c87cquxVV4utNm6JCPZ+6xxhSwHHRLIaxKx nLCXy9uH+xBwT1m9ZxQ5S02cTaxM+X4+0Q7dwo/zDVeOJZv3EjOhI0L9IQuk9L1ePqK9rmtlPZx mpw7n41GEChCW7D6qLB0m7qsnvA/f9qvLsgB8wHpj5zgXFIqRp2RbRJXxkPg4OK8u3b30BZ7nRg hiacV2svsSnlYtg== X-Developer-Key: i=andrew@lunn.ch; a=openpgp; fpr=61FB1025CB53263916F9E1B7E6BF0DCBA6694C84 X-Patchwork-Delegate: kuba@kernel.org Make use of the helpers to add LEDs to the user ports when the port is setup. Also remove the LEDs when the port is destroyed to avoid any race conditions with users of /sys/class/leds and LED triggers after the driver has been removed. Signed-off-by: Andrew Lunn --- drivers/net/dsa/mv88e6xxx/Kconfig | 1 + drivers/net/dsa/mv88e6xxx/chip.c | 119 +++++++++++++++++++++++++++++++++++++- drivers/net/dsa/mv88e6xxx/chip.h | 13 +++++ 3 files changed, 132 insertions(+), 1 deletion(-) diff --git a/drivers/net/dsa/mv88e6xxx/Kconfig b/drivers/net/dsa/mv88e6xxx/Kconfig index e3181d5471df..ded5c6b9132b 100644 --- a/drivers/net/dsa/mv88e6xxx/Kconfig +++ b/drivers/net/dsa/mv88e6xxx/Kconfig @@ -5,6 +5,7 @@ config NET_DSA_MV88E6XXX select IRQ_DOMAIN select NET_DSA_TAG_EDSA select NET_DSA_TAG_DSA + select NETDEV_LEDS help This driver adds support for most of the Marvell 88E6xxx models of Ethernet switch chips, except 88E6060. diff --git a/drivers/net/dsa/mv88e6xxx/chip.c b/drivers/net/dsa/mv88e6xxx/chip.c index 3d7e4aa9293a..4e4031f11088 100644 --- a/drivers/net/dsa/mv88e6xxx/chip.c +++ b/drivers/net/dsa/mv88e6xxx/chip.c @@ -31,6 +31,7 @@ #include #include #include +#include #include "chip.h" #include "devlink.h" @@ -3129,6 +3130,105 @@ static int mv88e6xxx_switch_reset(struct mv88e6xxx_chip *chip) return mv88e6xxx_software_reset(chip); } +static int mv88e6xxx_led_brightness_set(struct net_device *ndev, + u8 led, enum led_brightness value) +{ + struct dsa_port *dp = dsa_port_from_netdev(ndev); + struct mv88e6xxx_chip *chip = dp->ds->priv; + int port = dp->index; + int err; + + if (chip->info->ops->led_brightness_set) { + mv88e6xxx_reg_lock(chip); + err = chip->info->ops->led_brightness_set(chip, port, led, + value); + mv88e6xxx_reg_unlock(chip); + return err; + } + return -EOPNOTSUPP; +} + +static int mv88e6xxx_led_blink_set(struct net_device *ndev, u8 led, + unsigned long *delay_on, + unsigned long *delay_off) +{ + struct dsa_port *dp = dsa_port_from_netdev(ndev); + struct mv88e6xxx_chip *chip = dp->ds->priv; + int port = dp->index; + int err; + + if (chip->info->ops->led_blink_set) { + mv88e6xxx_reg_lock(chip); + err = chip->info->ops->led_blink_set(chip, port, led, + delay_on, delay_off); + mv88e6xxx_reg_unlock(chip); + return err; + } + return -EOPNOTSUPP; +} + +static int mv88e6xxx_led_hw_control_is_supported(struct net_device *ndev, + u8 led, unsigned long flags) +{ + struct dsa_port *dp = dsa_port_from_netdev(ndev); + struct mv88e6xxx_chip *chip = dp->ds->priv; + int port = dp->index; + int err; + + if (chip->info->ops->led_hw_control_is_supported) { + mv88e6xxx_reg_lock(chip); + err = chip->info->ops->led_hw_control_is_supported(chip, port, + led, flags); + mv88e6xxx_reg_unlock(chip); + return err; + } + return -EOPNOTSUPP; +} + +static int mv88e6xxx_led_hw_control_set(struct net_device *ndev, u8 led, + unsigned long flags) +{ + struct dsa_port *dp = dsa_port_from_netdev(ndev); + struct mv88e6xxx_chip *chip = dp->ds->priv; + int port = dp->index; + int err; + + if (chip->info->ops->led_hw_control_set) { + mv88e6xxx_reg_lock(chip); + err = chip->info->ops->led_hw_control_set(chip, port, + led, flags); + mv88e6xxx_reg_unlock(chip); + return err; + } + return -EOPNOTSUPP; +} + +static int mv88e6xxx_led_hw_control_get(struct net_device *ndev, + u8 led, unsigned long *flags) +{ + struct dsa_port *dp = dsa_port_from_netdev(ndev); + struct mv88e6xxx_chip *chip = dp->ds->priv; + int port = dp->index; + int err; + + if (chip->info->ops->led_hw_control_get) { + mv88e6xxx_reg_lock(chip); + err = chip->info->ops->led_hw_control_get(chip, port, + led, flags); + mv88e6xxx_reg_unlock(chip); + return err; + } + return -EOPNOTSUPP; +} + +static struct netdev_leds_ops mv88e6xxx_netdev_leds_ops = { + .brightness_set = mv88e6xxx_led_brightness_set, + .blink_set = mv88e6xxx_led_blink_set, + .hw_control_is_supported = mv88e6xxx_led_hw_control_is_supported, + .hw_control_set = mv88e6xxx_led_hw_control_set, + .hw_control_get = mv88e6xxx_led_hw_control_get, +}; + static int mv88e6xxx_set_port_mode(struct mv88e6xxx_chip *chip, int port, enum mv88e6xxx_frame_mode frame, enum mv88e6xxx_egress_mode egress, u16 etype) @@ -4006,7 +4106,9 @@ static int mv88e6xxx_setup(struct dsa_switch *ds) static int mv88e6xxx_port_setup(struct dsa_switch *ds, int port) { + struct dsa_port *dp = dsa_to_port(ds, port); struct mv88e6xxx_chip *chip = ds->priv; + struct mv88e6xxx_port *p; int err; if (chip->info->ops->pcs_ops && @@ -4016,13 +4118,28 @@ static int mv88e6xxx_port_setup(struct dsa_switch *ds, int port) return err; } - return mv88e6xxx_setup_devlink_regions_port(ds, port); + err = mv88e6xxx_setup_devlink_regions_port(ds, port); + if (err) + return err; + + if (dp->dn && dsa_is_user_port(ds, port)) { + p = &chip->ports[port]; + INIT_LIST_HEAD(&p->leds); + err = netdev_leds_setup(dp->user, dp->dn, &p->leds, + &mv88e6xxx_netdev_leds_ops, 2); + if (err) + mv88e6xxx_teardown_devlink_regions_port(ds, port); + } + return err; } static void mv88e6xxx_port_teardown(struct dsa_switch *ds, int port) { struct mv88e6xxx_chip *chip = ds->priv; + if (dsa_is_user_port(ds, port)) + netdev_leds_teardown(&chip->ports[port].leds); + mv88e6xxx_teardown_devlink_regions_port(ds, port); if (chip->info->ops->pcs_ops && diff --git a/drivers/net/dsa/mv88e6xxx/chip.h b/drivers/net/dsa/mv88e6xxx/chip.h index 64f8bde68ccf..d15bb5810831 100644 --- a/drivers/net/dsa/mv88e6xxx/chip.h +++ b/drivers/net/dsa/mv88e6xxx/chip.h @@ -291,6 +291,9 @@ struct mv88e6xxx_port { /* MacAuth Bypass control flag */ bool mab; + + /* LEDs associated to the port */ + struct list_head leds; }; enum mv88e6xxx_region_id { @@ -432,6 +435,7 @@ struct mv88e6xxx_chip { /* Bridge MST to SID mappings */ struct list_head msts; + }; struct mv88e6xxx_bus_ops { @@ -668,6 +672,15 @@ struct mv88e6xxx_ops { int (*led_blink_set)(struct mv88e6xxx_chip *chip, int port, u8 led, unsigned long *delay_on, unsigned long *delay_off); + int (*led_hw_control_is_supported)(struct mv88e6xxx_chip *chip, + int port, u8 led, + unsigned long flags); + int (*led_hw_control_set)(struct mv88e6xxx_chip *chip, + int port, u8 led, + unsigned long flags); + int (*led_hw_control_get)(struct mv88e6xxx_chip *chip, + int port, u8 led, + unsigned long *flags); }; struct mv88e6xxx_irq_ops { From patchwork Sat Apr 6 20:13:35 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrew Lunn X-Patchwork-Id: 13619924 X-Patchwork-Delegate: kuba@kernel.org Received: from vps0.lunn.ch (vps0.lunn.ch [156.67.10.101]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id AA7554F898 for ; Sat, 6 Apr 2024 20:14:20 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=156.67.10.101 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712434462; cv=none; b=OhufT7leDmAkomUZY59rjN6T/CPMPKCgFvamq8ZURKa9gQGZcSqwQhKoWRJZCkmtsGTDM255cKwBKuZ4imF+WYTm362wHCy6PXOCN9ANiRZHcEds0798FyrCrP5SQaiYIKlLnpcYv1KWFQBfxZpjHPDEV4enuLRnanxZALNIQE0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712434462; c=relaxed/simple; bh=mWoe6XecMAQFp0MvO0h2Kv+BG0hzV24l7Cv7PCawBDw=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=nHFxaoaWntVnjku+vBGsHh7ZMhks84+Wgsq1znveCY3oMNoyf6/9Dtx78eFUeebUVBpxv+OhC0F9GFZYoI77LHDWWh1uqvwBvgDjdEwdjGaGfuLKzaQquqGqHrDzuM68mXnaQi4xlz88XTf4M16tXOEgYhLdE9J1E+RDQBbcE1M= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=lunn.ch; spf=pass smtp.mailfrom=lunn.ch; dkim=pass (1024-bit key) header.d=lunn.ch header.i=@lunn.ch header.b=BTD90+o1; arc=none smtp.client-ip=156.67.10.101 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=lunn.ch Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=lunn.ch Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=lunn.ch header.i=@lunn.ch header.b="BTD90+o1" DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lunn.ch; s=20171124; h=Cc:To:In-Reply-To:References:Message-Id: Content-Transfer-Encoding:Content-Type:MIME-Version:Subject:Date:From:From: Sender:Reply-To:Subject:Date:Message-ID:To:Cc:MIME-Version:Content-Type: Content-Transfer-Encoding:Content-ID:Content-Description:Content-Disposition: In-Reply-To:References; bh=+a3f0+ge0K0FerbA4ZdfzhGLOqls39mHI6MZCyekdvY=; b=BT D90+o1NAZ6pz3dS0ZWHxZng5TFwvQGiCbgaK9Qj3m1WkfDvE8//OTZySWkOgqv+hqOMWN4MkR+vcS RCfAxMUnfP71JDBoIQFpaZUdY+5jiAmz3hDNP3DMSIXTXhQZ/X70T0xaHkzvBdCj66ylymsy1aVoZ eG2hZJpd21WEj/U=; Received: from c-76-156-36-110.hsd1.mn.comcast.net ([76.156.36.110] helo=thinkpad.home.lunn.ch) by vps0.lunn.ch with esmtpsa (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1rtCQc-00COA7-Bc; Sat, 06 Apr 2024 22:14:18 +0200 From: Andrew Lunn Date: Sat, 06 Apr 2024 15:13:35 -0500 Subject: [PATCH net-next v4 8/8] arm: boot: dts: mvebu: linksys-mamba: Add Ethernet LEDs Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20240406-v6-8-0-net-next-mv88e6xxx-leds-v4-v4-8-eb97665e7f96@lunn.ch> References: <20240406-v6-8-0-net-next-mv88e6xxx-leds-v4-v4-0-eb97665e7f96@lunn.ch> In-Reply-To: <20240406-v6-8-0-net-next-mv88e6xxx-leds-v4-v4-0-eb97665e7f96@lunn.ch> To: Florian Fainelli , Vladimir Oltean , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Russell King , Gregory Clement Cc: netdev@vger.kernel.org, Andrew Lunn X-Mailer: b4 0.13.0 X-Developer-Signature: v=1; a=openpgp-sha256; l=2554; i=andrew@lunn.ch; h=from:subject:message-id; bh=mWoe6XecMAQFp0MvO0h2Kv+BG0hzV24l7Cv7PCawBDw=; b=owEBbQKS/ZANAwAKAea/DcumaUyEAcsmYgBmEa0BY7t1ylkc0ukcAP2Nd1fjQRCuPtUS4NgsH M2bNaI1mFqJAjMEAAEKAB0WIQRh+xAly1MmORb54bfmvw3LpmlMhAUCZhGtAQAKCRDmvw3LpmlM hGfMEACa/tKsEF4Ph0F7OuNfkHsqnko8VRE6TinKAeHWYIHJJVrkQmwKbi0q8kxgMsKuHGfKgFP A70Vk2roZ3HghftM/zf1qpbgDZD9bwSU8ml1o/1Y7BICFAzrwcGWY+oUcEgbbnJQ6ittSHE9M6n KU0d9/jj8Wca44mNpSA1J6+IPbp6ffDyBXkr+qewxqMCiY9QL37zxlpqwzh1NiNSOqLW3QFKNMO 37uDbNxdo8xUW5vl9ziscciwB2y1Pi5CDkGu2vuViFe0ouHv2xx5QRLdTeI0+ACrj71tyZwaEEb 7TLUnGLQna+8avGUqBJ2JiRtsD92Nmgu79CKLowoj97yZmzgu9nc4/Jmk0RMHEqCsO2sjf9wZm+ 8TLmbsvuMLid/rWsUuZr6LjkpGOQ05r3kjawzG4/hGTLCi9Bj8ggUdtFKfcomFhNk2pEaMHLp6N rygBeR+m/oFzv4PNwPYgdZWRzSn/sVaZ73T5aa/wSvS05Yem5IJ+Jqp5GfuqwOsm8m7/sxwqlrA jq3rVbE9dgHX4C32bS4/HGe/162H5h2Lu6JChCwX9tqvLVhyb0PBI/u5JPGRQNUqTnWq38cU/OG zpswf4zVu3TMgLV8BI5kqJaG0lQ307hjxTS93KljNVpISoB9BAHgM/X5ihbI3lOay8JBgBA2aef nrh2StcanesoFTQ== X-Developer-Key: i=andrew@lunn.ch; a=openpgp; fpr=61FB1025CB53263916F9E1B7E6BF0DCBA6694C84 X-Patchwork-Delegate: kuba@kernel.org List the front panel Ethernet LEDs in the switch section of the device tree. They can then be controlled via /sys/class/led/ The node contains a label property to influence the name of the LED. Without it, all the LEDs get the name lan:white, which classes, and so some get a number appended. lan:white_1, lan:white_2, etc. Using the label the LEDs are named lan1:front, lan2:front, lan3:front, where lanX indicates the interface name, and front indicates they are on the front of the box. Signed-off-by: Andrew Lunn --- .../boot/dts/marvell/armada-xp-linksys-mamba.dts | 53 ++++++++++++++++++++++ 1 file changed, 53 insertions(+) diff --git a/arch/arm/boot/dts/marvell/armada-xp-linksys-mamba.dts b/arch/arm/boot/dts/marvell/armada-xp-linksys-mamba.dts index ea859f7ea042..34ea2338bf3c 100644 --- a/arch/arm/boot/dts/marvell/armada-xp-linksys-mamba.dts +++ b/arch/arm/boot/dts/marvell/armada-xp-linksys-mamba.dts @@ -19,6 +19,7 @@ /dts-v1/; #include #include +#include #include "armada-xp-mv78230.dtsi" / { @@ -276,21 +277,73 @@ ethernet-ports { ethernet-port@0 { reg = <0>; label = "lan4"; + + leds { + #address-cells = <1>; + #size-cells = <0>; + + led@0 { + reg = <0>; + color = ; + function = LED_FUNCTION_LAN; + label = "front"; + default-state = "keep"; + }; + }; }; ethernet-port@1 { reg = <1>; label = "lan3"; + + leds { + #address-cells = <1>; + #size-cells = <0>; + + led@0 { + reg = <0>; + color = ; + function = LED_FUNCTION_LAN; + label = "front"; + default-state = "keep"; + }; + }; }; ethernet-port@2 { reg = <2>; label = "lan2"; + + leds { + #address-cells = <1>; + #size-cells = <0>; + + led@0 { + reg = <0>; + color = ; + function = LED_FUNCTION_LAN; + label = "front"; + default-state = "keep"; + }; + }; }; ethernet-port@3 { reg = <3>; label = "lan1"; + + leds { + #address-cells = <1>; + #size-cells = <0>; + + led@0 { + reg = <0>; + color = ; + function = LED_FUNCTION_LAN; + label = "front"; + default-state = "keep"; + }; + }; }; ethernet-port@4 {