qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Peter Maydell <peter.maydell@linaro.org>
To: qemu-devel@nongnu.org
Subject: [PULL 17/21] hw/net/imx_fec: Support two Ethernet interfaces connected to single MDIO bus
Date: Thu, 20 Apr 2023 11:04:52 +0100	[thread overview]
Message-ID: <20230420100456.944969-18-peter.maydell@linaro.org> (raw)
In-Reply-To: <20230420100456.944969-1-peter.maydell@linaro.org>

From: Guenter Roeck <linux@roeck-us.net>

The SOC on i.MX6UL and i.MX7 has 2 Ethernet interfaces. The PHY on each may
be connected to separate MDIO busses, or both may be connected on the same
MDIO bus using different PHY addresses. Commit 461c51ad4275 ("Add a phy-num
property to the i.MX FEC emulator") added support for specifying PHY
addresses, but it did not provide support for linking the second PHY on
a given MDIO bus to the other Ethernet interface.

To be able to support two PHY instances on a single MDIO bus, two properties
are needed: First, there needs to be a flag indicating if the MDIO bus on
a given Ethernet interface is connected. If not, attempts to read from this
bus must always return 0xffff. Implement this property as phy-connected.
Second, if the MDIO bus on an interface is active, it needs a link to the
consumer interface to be able to provide PHY access for it. Implement this
property as phy-consumer.

Signed-off-by: Guenter Roeck <linux@roeck-us.net>
Message-id: 20230315145248.1639364-2-linux@roeck-us.net
Reviewed-by: Peter Maydell <peter.maydell@linaro.org>
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
---
 include/hw/net/imx_fec.h |  2 ++
 hw/net/imx_fec.c         | 27 +++++++++++++++++++++++----
 2 files changed, 25 insertions(+), 4 deletions(-)

diff --git a/include/hw/net/imx_fec.h b/include/hw/net/imx_fec.h
index e3a8755db92..2d13290c787 100644
--- a/include/hw/net/imx_fec.h
+++ b/include/hw/net/imx_fec.h
@@ -270,6 +270,8 @@ struct IMXFECState {
     uint32_t phy_int;
     uint32_t phy_int_mask;
     uint32_t phy_num;
+    bool phy_connected;
+    struct IMXFECState *phy_consumer;
 
     bool is_fec;
 
diff --git a/hw/net/imx_fec.c b/hw/net/imx_fec.c
index c862d965930..5d1f1f104cc 100644
--- a/hw/net/imx_fec.c
+++ b/hw/net/imx_fec.c
@@ -282,11 +282,19 @@ static uint32_t imx_phy_read(IMXFECState *s, int reg)
     uint32_t val;
     uint32_t phy = reg / 32;
 
-    if (phy != s->phy_num) {
-        trace_imx_phy_read_num(phy, s->phy_num);
+    if (!s->phy_connected) {
         return 0xffff;
     }
 
+    if (phy != s->phy_num) {
+        if (s->phy_consumer && phy == s->phy_consumer->phy_num) {
+            s = s->phy_consumer;
+        } else {
+            trace_imx_phy_read_num(phy, s->phy_num);
+            return 0xffff;
+        }
+    }
+
     reg %= 32;
 
     switch (reg) {
@@ -343,11 +351,19 @@ static void imx_phy_write(IMXFECState *s, int reg, uint32_t val)
 {
     uint32_t phy = reg / 32;
 
-    if (phy != s->phy_num) {
-        trace_imx_phy_write_num(phy, s->phy_num);
+    if (!s->phy_connected) {
         return;
     }
 
+    if (phy != s->phy_num) {
+        if (s->phy_consumer && phy == s->phy_consumer->phy_num) {
+            s = s->phy_consumer;
+        } else {
+            trace_imx_phy_write_num(phy, s->phy_num);
+            return;
+        }
+    }
+
     reg %= 32;
 
     trace_imx_phy_write(val, phy, reg);
@@ -1327,6 +1343,9 @@ static Property imx_eth_properties[] = {
     DEFINE_NIC_PROPERTIES(IMXFECState, conf),
     DEFINE_PROP_UINT32("tx-ring-num", IMXFECState, tx_ring_num, 1),
     DEFINE_PROP_UINT32("phy-num", IMXFECState, phy_num, 0),
+    DEFINE_PROP_BOOL("phy-connected", IMXFECState, phy_connected, true),
+    DEFINE_PROP_LINK("phy-consumer", IMXFECState, phy_consumer, TYPE_IMX_FEC,
+                     IMXFECState *),
     DEFINE_PROP_END_OF_LIST(),
 };
 
-- 
2.34.1



  parent reply	other threads:[~2023-04-20 10:06 UTC|newest]

Thread overview: 24+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-04-20 10:04 [PULL 00/21] target-arm queue Peter Maydell
2023-04-20 10:04 ` [PULL 01/21] hw/arm: Fix some typos in comments (most found by codespell) Peter Maydell
2023-04-20 10:04 ` [PULL 02/21] exynos: Fix out-of-bounds access in exynos4210_gcomp_find debug printf Peter Maydell
2023-04-20 10:04 ` [PULL 03/21] hw/watchdog: Allwinner WDT emulation for system reset Peter Maydell
2023-04-20 10:04 ` [PULL 04/21] hw/arm: Add WDT to Allwinner-A10 and Cubieboard Peter Maydell
2023-04-20 10:04 ` [PULL 05/21] hw/arm: Add WDT to Allwinner-H3 and Orangepi-PC Peter Maydell
2023-04-20 10:04 ` [PULL 06/21] tests/avocado: Add reboot tests to Cubieboard Peter Maydell
2023-04-20 10:04 ` [PULL 07/21] hw/timer/imx_epit: don't shadow variable Peter Maydell
2023-04-20 10:04 ` [PULL 08/21] hw/timer/imx_epit: fix limit check Peter Maydell
2023-04-20 10:04 ` [PULL 09/21] target/arm: Remove KVM AArch32 CPU definitions Peter Maydell
2023-04-20 10:04 ` [PULL 10/21] hw/arm/virt: Restrict Cortex-A7 check to TCG Peter Maydell
2023-04-20 10:04 ` [PULL 11/21] target/arm: Initialize debug capabilities only once Peter Maydell
2023-04-20 10:04 ` [PULL 12/21] target/arm: Pass ARMMMUFaultInfo to merge_syn_data_abort() Peter Maydell
2023-04-20 10:04 ` [PULL 13/21] target/arm: Don't set ISV when reporting stage 1 faults in ESR_EL2 Peter Maydell
2023-04-20 10:04 ` [PULL 14/21] target/arm: Implement FEAT_PAN3 Peter Maydell
2023-04-20 10:04 ` [PULL 15/21] docs/devel/kconfig.rst: Fix incorrect markup Peter Maydell
2023-04-20 10:04 ` [PULL 16/21] target/arm: Report pauth information to gdb as 'pauth_v2' Peter Maydell
2023-04-20 10:04 ` Peter Maydell [this message]
2023-04-20 10:04 ` [PULL 18/21] fsl-imx6ul: Add fec[12]-phy-connected properties Peter Maydell
2023-04-20 10:04 ` [PULL 19/21] arm/mcimx6ul-evk: Set fec1-phy-connected property to false Peter Maydell
2023-04-20 10:04 ` [PULL 20/21] fsl-imx7: Add fec[12]-phy-connected properties Peter Maydell
2023-04-20 10:04 ` [PULL 21/21] arm/mcimx7d-sabre: Set fec2-phy-connected property to false Peter Maydell
2023-04-21 10:49 ` [PULL 00/21] target-arm queue Richard Henderson
2023-04-21 11:54   ` Peter Maydell

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=20230420100456.944969-18-peter.maydell@linaro.org \
    --to=peter.maydell@linaro.org \
    --cc=qemu-devel@nongnu.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;
as well as URLs for NNTP newsgroup(s).