* [PATCH v2 net-next 1/3] net: axienet: Unexport and remove unused mdio functions
2022-11-01 1:01 [PATCH v2 net-next 0/3] net: axienet: Use a DT property to configure frequency of the MDIO bus Andy Chiu
@ 2022-11-01 1:01 ` Andy Chiu
2022-11-01 23:49 ` Andrew Lunn
2022-11-01 1:01 ` [PATCH v2 net-next 2/3] net: axienet: set mdio clock according to bus-frequency Andy Chiu
1 sibling, 1 reply; 5+ messages in thread
From: Andy Chiu @ 2022-11-01 1:01 UTC (permalink / raw)
To: davem, kuba, michal.simek, radhey.shyam.pandey
Cc: netdev, devicetree, linux-arm-kernel, krzysztof.kozlowski+dt,
robh+dt, pabeni, edumazet, andy.chiu, greentime.hu
Both axienet_mdio_enable functions are no longer used in
xilinx_axienet_main.c due to 253761a0e61b7. And axienet_mdio_disable is
not even used in the mdio.c. So unexport and remove them.
Signed-off-by: Andy Chiu <andy.chiu@sifive.com>
---
drivers/net/ethernet/xilinx/xilinx_axienet.h | 2 --
drivers/net/ethernet/xilinx/xilinx_axienet_mdio.c | 13 +------------
2 files changed, 1 insertion(+), 14 deletions(-)
diff --git a/drivers/net/ethernet/xilinx/xilinx_axienet.h b/drivers/net/ethernet/xilinx/xilinx_axienet.h
index 6370c447ac5c..575ff9de8985 100644
--- a/drivers/net/ethernet/xilinx/xilinx_axienet.h
+++ b/drivers/net/ethernet/xilinx/xilinx_axienet.h
@@ -611,8 +611,6 @@ static inline void axienet_dma_out_addr(struct axienet_local *lp, off_t reg,
#endif /* CONFIG_64BIT */
/* Function prototypes visible in xilinx_axienet_mdio.c for other files */
-int axienet_mdio_enable(struct axienet_local *lp);
-void axienet_mdio_disable(struct axienet_local *lp);
int axienet_mdio_setup(struct axienet_local *lp);
void axienet_mdio_teardown(struct axienet_local *lp);
diff --git a/drivers/net/ethernet/xilinx/xilinx_axienet_mdio.c b/drivers/net/ethernet/xilinx/xilinx_axienet_mdio.c
index 0b3b6935c558..e1f51a071888 100644
--- a/drivers/net/ethernet/xilinx/xilinx_axienet_mdio.c
+++ b/drivers/net/ethernet/xilinx/xilinx_axienet_mdio.c
@@ -153,7 +153,7 @@ static int axienet_mdio_write(struct mii_bus *bus, int phy_id, int reg,
* Sets up the MDIO interface by initializing the MDIO clock and enabling the
* MDIO interface in hardware.
**/
-int axienet_mdio_enable(struct axienet_local *lp)
+static int axienet_mdio_enable(struct axienet_local *lp)
{
u32 host_clock;
@@ -226,17 +226,6 @@ int axienet_mdio_enable(struct axienet_local *lp)
return axienet_mdio_wait_until_ready(lp);
}
-/**
- * axienet_mdio_disable - MDIO hardware disable function
- * @lp: Pointer to axienet local data structure.
- *
- * Disable the MDIO interface in hardware.
- **/
-void axienet_mdio_disable(struct axienet_local *lp)
-{
- axienet_iow(lp, XAE_MDIO_MC_OFFSET, 0);
-}
-
/**
* axienet_mdio_setup - MDIO setup function
* @lp: Pointer to axienet local data structure.
--
2.36.0
^ permalink raw reply related [flat|nested] 5+ messages in thread
* [PATCH v2 net-next 2/3] net: axienet: set mdio clock according to bus-frequency
2022-11-01 1:01 [PATCH v2 net-next 0/3] net: axienet: Use a DT property to configure frequency of the MDIO bus Andy Chiu
2022-11-01 1:01 ` [PATCH v2 net-next 1/3] net: axienet: Unexport and remove unused mdio functions Andy Chiu
@ 2022-11-01 1:01 ` Andy Chiu
2022-11-02 0:39 ` Andrew Lunn
1 sibling, 1 reply; 5+ messages in thread
From: Andy Chiu @ 2022-11-01 1:01 UTC (permalink / raw)
To: davem, kuba, michal.simek, radhey.shyam.pandey
Cc: netdev, devicetree, linux-arm-kernel, krzysztof.kozlowski+dt,
robh+dt, pabeni, edumazet, andy.chiu, greentime.hu
Some FPGA platforms have 80KHz MDIO bus frequency constraint when
connecting Ethernet to its on-board external Marvell PHY. Thus, we may
have to set MDIO clock according to the DT. Otherwise, use the default
2.5 MHz, as specified by 802.3, if the entry is not present.
Signed-off-by: Andy Chiu <andy.chiu@sifive.com>
Reviewed-by: Greentime Hu <greentime.hu@sifive.com>
---
.../net/ethernet/xilinx/xilinx_axienet_mdio.c | 47 +++++++++++++------
1 file changed, 33 insertions(+), 14 deletions(-)
diff --git a/drivers/net/ethernet/xilinx/xilinx_axienet_mdio.c b/drivers/net/ethernet/xilinx/xilinx_axienet_mdio.c
index e1f51a071888..666df3713d92 100644
--- a/drivers/net/ethernet/xilinx/xilinx_axienet_mdio.c
+++ b/drivers/net/ethernet/xilinx/xilinx_axienet_mdio.c
@@ -18,6 +18,7 @@
#include "xilinx_axienet.h"
#define MAX_MDIO_FREQ 2500000 /* 2.5 MHz */
+#define MDIO_CLK_DIV_MASK 0x3f /* bits[5:0] */
#define DEFAULT_HOST_CLOCK 150000000 /* 150 MHz */
/* Wait till MDIO interface is ready to accept a new transaction.*/
@@ -147,15 +148,18 @@ static int axienet_mdio_write(struct mii_bus *bus, int phy_id, int reg,
/**
* axienet_mdio_enable - MDIO hardware setup function
* @lp: Pointer to axienet local data structure.
+ * @np: Pointer to mdio device tree node.
*
* Return: 0 on success, -ETIMEDOUT on a timeout.
*
* Sets up the MDIO interface by initializing the MDIO clock and enabling the
* MDIO interface in hardware.
**/
-static int axienet_mdio_enable(struct axienet_local *lp)
+static int axienet_mdio_enable(struct axienet_local *lp, struct device_node *np)
{
+ u32 clk_div;
u32 host_clock;
+ u32 mdio_freq = MAX_MDIO_FREQ;
lp->mii_clk_div = 0;
@@ -184,6 +188,12 @@ static int axienet_mdio_enable(struct axienet_local *lp)
host_clock);
}
+ if (np)
+ of_property_read_u32(np, "clock-frequency", &mdio_freq);
+ if (mdio_freq != MAX_MDIO_FREQ)
+ netdev_info(lp->ndev, "Setting non-standard mdio bus frequency to %u Hz\n",
+ mdio_freq);
+
/* clk_div can be calculated by deriving it from the equation:
* fMDIO = fHOST / ((1 + clk_div) * 2)
*
@@ -209,13 +219,20 @@ static int axienet_mdio_enable(struct axienet_local *lp)
* "clock-frequency" from the CPU
*/
- lp->mii_clk_div = (host_clock / (MAX_MDIO_FREQ * 2)) - 1;
+ clk_div = (host_clock / (mdio_freq * 2)) - 1;
/* If there is any remainder from the division of
- * fHOST / (MAX_MDIO_FREQ * 2), then we need to add
+ * fHOST / (mdio_freq * 2), then we need to add
* 1 to the clock divisor or we will surely be above 2.5 MHz
*/
- if (host_clock % (MAX_MDIO_FREQ * 2))
- lp->mii_clk_div++;
+ if (host_clock % (mdio_freq * 2))
+ clk_div++;
+
+ /* Check for overflow of mii_clk_div */
+ if (clk_div & ~MDIO_CLK_DIV_MASK) {
+ netdev_dbg(lp->ndev, "MDIO clock divisor overflow, setting to maximum value\n");
+ clk_div = MDIO_CLK_DIV_MASK;
+ }
+ lp->mii_clk_div = (u8)clk_div;
netdev_dbg(lp->ndev,
"Setting MDIO clock divisor to %u/%u Hz host clock.\n",
@@ -242,10 +259,6 @@ int axienet_mdio_setup(struct axienet_local *lp)
struct mii_bus *bus;
int ret;
- ret = axienet_mdio_enable(lp);
- if (ret < 0)
- return ret;
-
bus = mdiobus_alloc();
if (!bus)
return -ENOMEM;
@@ -261,15 +274,21 @@ int axienet_mdio_setup(struct axienet_local *lp)
lp->mii_bus = bus;
mdio_node = of_get_child_by_name(lp->dev->of_node, "mdio");
+ ret = axienet_mdio_enable(lp, mdio_node);
+ if (ret < 0)
+ goto unregister;
ret = of_mdiobus_register(bus, mdio_node);
+ if (ret)
+ goto unregister;
of_node_put(mdio_node);
- if (ret) {
- mdiobus_free(bus);
- lp->mii_bus = NULL;
- return ret;
- }
axienet_mdio_mdc_disable(lp);
return 0;
+
+unregister:
+ of_node_put(mdio_node);
+ mdiobus_free(bus);
+ lp->mii_bus = NULL;
+ return ret;
}
/**
--
2.36.0
^ permalink raw reply related [flat|nested] 5+ messages in thread