From: Michael Walle <michael@walle.cc>
To: "David S . Miller" <davem@davemloft.net>,
Eric Dumazet <edumazet@google.com>,
Jakub Kicinski <kuba@kernel.org>, Paolo Abeni <pabeni@redhat.com>,
Rob Herring <robh+dt@kernel.org>,
Krzysztof Kozlowski <krzysztof.kozlowski+dt@linaro.org>,
Horatiu Vultur <horatiu.vultur@microchip.com>
Cc: UNGLinuxDriver@microchip.com, netdev@vger.kernel.org,
devicetree@vger.kernel.org, linux-kernel@vger.kernel.org,
Michael Walle <michael@walle.cc>
Subject: [PATCH net-next 1/4] net: lan966x: hardcode the number of external ports
Date: Thu, 30 Jun 2022 16:02:34 +0200 [thread overview]
Message-ID: <20220630140237.692986-2-michael@walle.cc> (raw)
In-Reply-To: <20220630140237.692986-1-michael@walle.cc>
Instead of counting the child nodes in the device tree, hardcode the
number of ports in the driver itself. The counting won't work at all
if an ethernet port is marked as disabled, eg. because it is not
connected on the board at all.
This is hardcoding the number of ports to eight for the generic
compatible string "microchip,lan966x-switch", although it clearly only
applies to the LAN9668. This is because, first, there is only one user
for now, and that is the LAN9668 and second, the generic compatible
string will be deprecated in favor of a more specific one. Therefore,
if there will be support for the LAN9662, it can be added by another
specific compatible string.
Signed-off-by: Michael Walle <michael@walle.cc>
---
.../ethernet/microchip/lan966x/lan966x_main.c | 23 +++++++++++++------
1 file changed, 16 insertions(+), 7 deletions(-)
diff --git a/drivers/net/ethernet/microchip/lan966x/lan966x_main.c b/drivers/net/ethernet/microchip/lan966x/lan966x_main.c
index 5784c4161e5e..d611b52d3a07 100644
--- a/drivers/net/ethernet/microchip/lan966x/lan966x_main.c
+++ b/drivers/net/ethernet/microchip/lan966x/lan966x_main.c
@@ -26,8 +26,16 @@
#define IO_RANGES 2
+struct lan966x_info {
+ u8 num_phys_ports;
+};
+
+static const struct lan966x_info lan9668_info = {
+ .num_phys_ports = 8,
+};
+
static const struct of_device_id lan966x_match[] = {
- { .compatible = "microchip,lan966x-switch" },
+ { .compatible = "microchip,lan966x-switch", .data = &lan9668_info },
{ }
};
MODULE_DEVICE_TABLE(of, lan966x_match);
@@ -992,9 +1000,10 @@ static int lan966x_reset_switch(struct lan966x *lan966x)
static int lan966x_probe(struct platform_device *pdev)
{
struct fwnode_handle *ports, *portnp;
+ const struct lan966x_info *info;
struct lan966x *lan966x;
u8 mac_addr[ETH_ALEN];
- int err, i;
+ int err;
lan966x = devm_kzalloc(&pdev->dev, sizeof(*lan966x), GFP_KERNEL);
if (!lan966x)
@@ -1003,6 +1012,10 @@ static int lan966x_probe(struct platform_device *pdev)
platform_set_drvdata(pdev, lan966x);
lan966x->dev = &pdev->dev;
+ info = device_get_match_data(&pdev->dev);
+ if (!info)
+ return -ENODEV;
+
if (!device_get_mac_address(&pdev->dev, mac_addr)) {
ether_addr_copy(lan966x->base_mac, mac_addr);
} else {
@@ -1025,11 +1038,7 @@ static int lan966x_probe(struct platform_device *pdev)
if (err)
return dev_err_probe(&pdev->dev, err, "Reset failed");
- i = 0;
- fwnode_for_each_available_child_node(ports, portnp)
- ++i;
-
- lan966x->num_phys_ports = i;
+ lan966x->num_phys_ports = info->num_phys_ports;
lan966x->ports = devm_kcalloc(&pdev->dev, lan966x->num_phys_ports,
sizeof(struct lan966x_port *),
GFP_KERNEL);
--
2.30.2
next prev parent reply other threads:[~2022-06-30 14:19 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-06-30 14:02 [PATCH net-next 0/4] net: lan966x: hardcode port count Michael Walle
2022-06-30 14:02 ` Michael Walle [this message]
2022-06-30 14:02 ` [PATCH net-next 2/4] dt-bindings: net: lan966x: add specific compatible string Michael Walle
2022-06-30 14:02 ` [PATCH net-next 3/4] net: lan966x: add new compatible microchip,lan9668-switch Michael Walle
2022-06-30 14:02 ` [PATCH net-next 4/4] ARM: dts: lan966x: use new microchip,lan9668-switch compatible Michael Walle
2022-06-30 19:18 ` Krzysztof Kozlowski
2022-06-30 20:44 ` [PATCH net-next 0/4] net: lan966x: hardcode port count Horatiu Vultur
2022-06-30 20:56 ` Michael Walle
2022-06-30 21:21 ` Horatiu Vultur
2022-06-30 21:08 ` Andrew Lunn
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20220630140237.692986-2-michael@walle.cc \
--to=michael@walle.cc \
--cc=UNGLinuxDriver@microchip.com \
--cc=davem@davemloft.net \
--cc=devicetree@vger.kernel.org \
--cc=edumazet@google.com \
--cc=horatiu.vultur@microchip.com \
--cc=krzysztof.kozlowski+dt@linaro.org \
--cc=kuba@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=netdev@vger.kernel.org \
--cc=pabeni@redhat.com \
--cc=robh+dt@kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox