[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <47b3197a0cf95aa3ac1da8e76b93adacfa69d9e9.camel@microchip.com>
Date: Thu, 7 Dec 2023 04:57:23 +0000
From: <Arun.Ramadoss@...rochip.com>
To: <andrew@...n.ch>, <olteanv@...il.com>, <davem@...emloft.net>,
<Woojung.Huh@...rochip.com>, <pabeni@...hat.com>, <o.rempel@...gutronix.de>,
<edumazet@...gle.com>, <f.fainelli@...il.com>, <kuba@...nel.org>
CC: <kernel@...gutronix.de>, <linux-kernel@...r.kernel.org>,
<netdev@...r.kernel.org>, <UNGLinuxDriver@...rochip.com>
Subject: Re: [PATCH net-next v1 1/3] net: dsa: microchip: ksz8: move BMCR
specific code to separate function
Hi Oleksij,
On Tue, 2023-11-21 at 16:24 +0100, Oleksij Rempel wrote:
> EXTERNAL EMAIL: Do not click links or open attachments unless you
> know the content is safe
>
> Isolate the Basic Mode Control Register (BMCR) operations in the
> ksz8795
> driver by moving the BMCR-related code segments from the ksz8_r_phy()
> and ksz8_w_phy() functions to newly created ksz8_r_phy_bmcr() and
> ksz8_w_phy_bmcr() functions.
>
> Signed-off-by: Oleksij Rempel <o.rempel@...gutronix.de>
> ---
> drivers/net/dsa/microchip/ksz8795.c | 351 ++++++++++++++++++------
> ----
> 1 file changed, 227 insertions(+), 124 deletions(-)
>
> diff --git a/drivers/net/dsa/microchip/ksz8795.c
> b/drivers/net/dsa/microchip/ksz8795.c
> index 4bf4d67557dc..835157815937 100644
> --- a/drivers/net/dsa/microchip/ksz8795.c
> +++ b/drivers/net/dsa/microchip/ksz8795.c
> @@ -676,9 +676,98 @@ static int ksz8_r_phy_ctrl(struct ksz_device
> *dev, int port, u16 *val)
> return 0;
> }
>
>
> int ksz8_r_phy(struct ksz_device *dev, u16 phy, u16 reg, u16 *val)
> {
> - u8 restart, speed, ctrl, link;
> + u8 ctrl, link;
> int processed = true;
Reverse christmas tree
> const u16 *regs;
> u8 val1, val2;
> @@ -690,45 +779,9 @@ int ksz8_r_phy(struct ksz_device *dev, u16 phy,
> u16 reg, u16 *val)
>
> switch (reg) {
> case MII_BMCR:
> - ret = ksz_pread8(dev, p, regs[P_NEG_RESTART_CTRL],
> &restart);
> - if (ret)
> - return ret;
> -
> - ret = ksz_pread8(dev, p, regs[P_SPEED_STATUS],
> &speed);
> - if (ret)
> - return ret;
> -
> - ret = ksz_pread8(dev, p, regs[P_FORCE_CTRL], &ctrl);
> + ret = ksz8_r_phy_bmcr(dev, p, &data);
> if (ret)
> return ret;
>
> +static int ksz8_w_phy_bmcr(struct ksz_device *dev, int port, u16
> val)
> {
> - u8 restart, speed, ctrl, data;
> - const u16 *regs;
> - u8 p = phy;
> + const u16 *regs = dev->info->regs;
> + u8 restart, ctrl, speed, data;
> int ret;
>
> - regs = dev->info->regs;
> + /* Do not support PHY reset function. */
> + if (val & BMCR_RESET)
> + return 0;
>
> - switch (reg) {
> - case MII_BMCR:
> + ret = ksz_pread8(dev, port, regs[P_SPEED_STATUS], &speed);
> + if (ret)
> + return ret;
>
> - /* Do not support PHY reset function. */
> - if (val & BMCR_RESET)
> - break;
> - ret = ksz_pread8(dev, p, regs[P_SPEED_STATUS],
> &speed);
> + data = speed;
> + if (val & KSZ886X_BMCR_HP_MDIX)
> + data |= PORT_HP_MDIX;
> + else
> + data &= ~PORT_HP_MDIX;
> +
> + if (data != speed) {
> + ret = ksz_pwrite8(dev, port, regs[P_SPEED_STATUS],
> data);
> if (ret)
> return ret;
> + }
> +
> + ret = ksz_pread8(dev, port, regs[P_FORCE_CTRL], &ctrl);
> + if (ret)
> + return ret;
>
> - data = speed;
> - if (val & KSZ886X_BMCR_HP_MDIX)
> - data |= PORT_HP_MDIX;
> + data = ctrl;
> + if (ksz_is_ksz88x3(dev)) {
> + if ((val & BMCR_ANENABLE))
> + data |= PORT_AUTO_NEG_ENABLE;
> + else
> + data &= ~PORT_AUTO_NEG_ENABLE;
> + } else {
> + if (!(val & BMCR_ANENABLE))
> + data |= PORT_AUTO_NEG_DISABLE;
> else
> - data &= ~PORT_HP_MDIX;
> + data &= ~PORT_AUTO_NEG_DISABLE;
>
> - if (data != speed) {
> - ret = ksz_pwrite8(dev, p,
> regs[P_SPEED_STATUS], data);
> - if (ret)
> - return ret;
> - }
> + /* Fiber port does not support auto-negotiation. */
> + if (dev->ports[port].fiber)
> + data |= PORT_AUTO_NEG_DISABLE;
> + }
>
> - ret = ksz_pread8(dev, p, regs[P_FORCE_CTRL], &ctrl);
> + if (val & BMCR_SPEED100)
> + data |= PORT_FORCE_100_MBIT;
> + else
> + data &= ~PORT_FORCE_100_MBIT;
> + if (val & BMCR_FULLDPLX)
> + data |= PORT_FORCE_FULL_DUPLEX;
> + else
> + data &= ~PORT_FORCE_FULL_DUPLEX;
> +
> + if (data != ctrl) {
> + ret = ksz_pwrite8(dev, port, regs[P_FORCE_CTRL],
> data);
> if (ret)
> return ret;
> + }
>
> - data = ctrl;
> - if (ksz_is_ksz88x3(dev)) {
> - if ((val & BMCR_ANENABLE))
> - data |= PORT_AUTO_NEG_ENABLE;
> - else
> - data &= ~PORT_AUTO_NEG_ENABLE;
> - } else {
> - if (!(val & BMCR_ANENABLE))
> - data |= PORT_AUTO_NEG_DISABLE;
> - else
> - data &= ~PORT_AUTO_NEG_DISABLE;
> -
> - /* Fiber port does not support auto-
> negotiation. */
> - if (dev->ports[p].fiber)
> - data |= PORT_AUTO_NEG_DISABLE;
> - }
> + ret = ksz_pread8(dev, port, regs[P_NEG_RESTART_CTRL],
> &restart);
> + if (ret)
> + return ret;
>
> - if (val & BMCR_SPEED100)
> - data |= PORT_FORCE_100_MBIT;
> - else
> - data &= ~PORT_FORCE_100_MBIT;
suggestion: blank line between them increases readability.
> - if (val & BMCR_FULLDPLX)
> - data |= PORT_FORCE_FULL_DUPLEX;
> - else
> - data &= ~PORT_FORCE_FULL_DUPLEX;
> + data = restart;
> + if (val & KSZ886X_BMCR_DISABLE_LED)
> + data |= PORT_LED_OFF;
> + else
> + data &= ~PORT_LED_OFF;
> + if (val & KSZ886X_BMCR_DISABLE_TRANSMIT)
> + data |= PORT_TX_DISABLE;
> + else
> + data &= ~PORT_TX_DISABLE;
> + if (val & BMCR_ANRESTART)
> + data |= PORT_AUTO_NEG_RESTART;
> + else
> + data &= ~(PORT_AUTO_NEG_RESTART);
> + if (val & BMCR_PDOWN)
> + data |= PORT_POWER_DOWN;
> + else
> + data &= ~PORT_POWER_DOWN;
> + if (val & KSZ886X_BMCR_DISABLE_AUTO_MDIX)
> + data |= PORT_AUTO_MDIX_DISABLE;
> + else
> + data &= ~PORT_AUTO_MDIX_DISABLE;
> + if (val & KSZ886X_BMCR_FORCE_MDI)
> + data |= PORT_FORCE_MDIX;
> + else
> + data &= ~PORT_FORCE_MDIX;
> + if (val & BMCR_LOOPBACK)
> + data |= PORT_PHY_LOOPBACK;
> + else
> + data &= ~PORT_PHY_LOOPBACK;
>
> - if (data != ctrl) {
> - ret = ksz_pwrite8(dev, p, regs[P_FORCE_CTRL],
> data);
> - if (ret)
> - return ret;
> - }
> + if (data != restart) {
> + ret = ksz_pwrite8(dev, port,
> regs[P_NEG_RESTART_CTRL],
> + data);
> + if (ret)
> + return ret;
> + }
>
> - ret = ksz_pread8(dev, p, regs[P_NEG_RESTART_CTRL],
> &restart);
> + return 0;
> +}
> +
> +int ksz8_w_phy(struct ksz_device *dev, u16 phy, u16 reg, u16 val)
> +{
> + u8 ctrl, data;
> + const u16 *regs;
reverse christmas tree
> + u8 p = phy;
> + int ret;
> +
> + regs = dev->info->regs;
> +
> + switch (reg) {
> + case MII_BMCR:
> + ret = ksz8_w_phy_bmcr(dev, p, val);
In ksz8_w_phy_bmcr, p is of int, here you are passing p which is u8.
also it is assigned using u16. Any reason behind it. if not, have
consistency.
> if (ret)
> return ret;
>
> - data = restart;
> - if (val & KSZ886X_BMCR_DISABLE_LED)
> - data |= PORT_LED_OFF;
> - else
> - data &= ~PORT_LED_OFF;
> - if (val & KSZ886X_BMCR_DISABLE_TRANSMIT)
> - data |= PORT_TX_DISABLE;
> - else
> - data &= ~PORT_TX_DISABLE;
> - if (val & BMCR_ANRESTART)
> - data |= PORT_AUTO_NEG_RESTART;
> - else
> - data &= ~(PORT_AUTO_NEG_RESTART);
> - if (val & BMCR_PDOWN)
> - data |= PORT_POWER_DOWN;
> - else
> - data &= ~PORT_POWER_DOWN;
> - if (val & KSZ886X_BMCR_DISABLE_AUTO_MDIX)
> - data |= PORT_AUTO_MDIX_DISABLE;
> - else
> - data &= ~PORT_AUTO_MDIX_DISABLE;
> - if (val & KSZ886X_BMCR_FORCE_MDI)
> - data |= PORT_FORCE_MDIX;
> - else
> - data &= ~PORT_FORCE_MDIX;
> - if (val & BMCR_LOOPBACK)
> - data |= PORT_PHY_LOOPBACK;
> - else
> - data &= ~PORT_PHY_LOOPBACK;
>
> - if (data != restart) {
> - ret = ksz_pwrite8(dev, p,
> regs[P_NEG_RESTART_CTRL],
> - data);
> - if (ret)
> - return ret;
> - }
> break;
> case MII_ADVERTISE:
> ret = ksz_pread8(dev, p, regs[P_LOCAL_CTRL], &ctrl);
> --
> 2.39.2
>
Powered by blists - more mailing lists