Commit 1e59fd16 authored by Maxime Chevallier's avatar Maxime Chevallier Committed by David S. Miller
Browse files

net: freescale: ucc_geth: split adjust_link for phylink conversion



Preparing the phylink conversion, split the adjust_link callbaclk, by
clearly separating the mac configuration, link_up and link_down phases.

Reviewed-by: default avatarAndrew Lunn <andrew@lunn.ch>
Signed-off-by: default avatarMaxime Chevallier <maxime.chevallier@bootlin.com>
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parent 3e42bb99
Loading
Loading
Loading
Loading
+93 −87
Original line number Diff line number Diff line
@@ -1548,41 +1548,31 @@ static void ugeth_activate(struct ucc_geth_private *ugeth)
	__netdev_watchdog_up(ugeth->ndev);
}

/* Called every time the controller might need to be made
 * aware of new link state.  The PHY code conveys this
 * information through variables in the ugeth structure, and this
 * function converts those variables into the appropriate
 * register values, and can bring down the device if needed.
 */

static void adjust_link(struct net_device *dev)
static void ugeth_link_up(struct ucc_geth_private *ugeth,
			  struct phy_device *phy,
			  phy_interface_t interface, int speed, int duplex)
{
	struct ucc_geth_private *ugeth = netdev_priv(dev);
	struct ucc_geth __iomem *ug_regs;
	struct ucc_fast __iomem *uf_regs;
	struct phy_device *phydev = ugeth->phydev;
	int new_state = 0;

	ug_regs = ugeth->ug_regs;
	uf_regs = ugeth->uccf->uf_regs;

	if (phydev->link) {
	struct ucc_geth __iomem *ug_regs = ugeth->ug_regs;
	struct ucc_fast __iomem *uf_regs = ugeth->uccf->uf_regs;
	u32 tempval = in_be32(&ug_regs->maccfg2);
	u32 upsmr = in_be32(&uf_regs->upsmr);
	int new_state = 0;

	/* Now we make sure that we can be in full duplex mode.
		 * If not, we operate in half-duplex mode. */
		if (phydev->duplex != ugeth->oldduplex) {
	 * If not, we operate in half-duplex mode.
	 */
	if (duplex != ugeth->oldduplex) {
		new_state = 1;
			if (!(phydev->duplex))
		if (duplex == DUPLEX_HALF)
			tempval &= ~(MACCFG2_FDX);
		else
			tempval |= MACCFG2_FDX;
			ugeth->oldduplex = phydev->duplex;
		ugeth->oldduplex = duplex;
	}

		if (phydev->speed != ugeth->oldspeed) {
	if (speed != ugeth->oldspeed) {
		new_state = 1;
			switch (phydev->speed) {
		switch (speed) {
		case SPEED_1000:
			tempval = ((tempval &
				    ~(MACCFG2_INTERFACE_MODE_MASK)) |
@@ -1594,13 +1584,10 @@ static void adjust_link(struct net_device *dev)
				    ~(MACCFG2_INTERFACE_MODE_MASK)) |
				    MACCFG2_INTERFACE_MODE_NIBBLE);
			/* if reduced mode, re-set UPSMR.R10M */
				if ((ugeth->phy_interface == PHY_INTERFACE_MODE_RMII) ||
				    (ugeth->phy_interface == PHY_INTERFACE_MODE_RGMII) ||
				    (ugeth->phy_interface == PHY_INTERFACE_MODE_RGMII_ID) ||
				    (ugeth->phy_interface == PHY_INTERFACE_MODE_RGMII_RXID) ||
				    (ugeth->phy_interface == PHY_INTERFACE_MODE_RGMII_TXID) ||
				    (ugeth->phy_interface == PHY_INTERFACE_MODE_RTBI)) {
					if (phydev->speed == SPEED_10)
			if (interface == PHY_INTERFACE_MODE_RMII ||
			    phy_interface_mode_is_rgmii(interface) ||
			    interface == PHY_INTERFACE_MODE_RTBI) {
				if (speed == SPEED_10)
					upsmr |= UCC_GETH_UPSMR_R10M;
				else
					upsmr &= ~UCC_GETH_UPSMR_R10M;
@@ -1608,12 +1595,11 @@ static void adjust_link(struct net_device *dev)
			break;
		default:
			if (netif_msg_link(ugeth))
					pr_warn(
						"%s: Ack!  Speed (%d) is not 10/100/1000!",
						dev->name, phydev->speed);
				pr_warn("%s:  Speed (%d) is not 10/100/1000!",
					netdev_name(ugeth->ndev), speed);
			break;
		}
			ugeth->oldspeed = phydev->speed;
		ugeth->oldspeed = speed;
	}

	if (!ugeth->oldlink) {
@@ -1638,15 +1624,35 @@ static void adjust_link(struct net_device *dev)
		ugeth_enable(ugeth, COMM_DIR_RX_AND_TX);
		ugeth_activate(ugeth);
	}
	} else if (ugeth->oldlink) {
			new_state = 1;

	if (netif_msg_link(ugeth))
		phy_print_status(phy);
}

static void ugeth_link_down(struct ucc_geth_private *ugeth)
{
	ugeth->oldlink = 0;
	ugeth->oldspeed = 0;
	ugeth->oldduplex = -1;
}

	if (new_state && netif_msg_link(ugeth))
		phy_print_status(phydev);
/* Called every time the controller might need to be made
 * aware of new link state.  The PHY code conveys this
 * information through variables in the ugeth structure, and this
 * function converts those variables into the appropriate
 * register values, and can bring down the device if needed.
 */

static void adjust_link(struct net_device *dev)
{
	struct ucc_geth_private *ugeth = netdev_priv(dev);
	struct phy_device *phydev = ugeth->phydev;

	if (phydev->link)
		ugeth_link_up(ugeth, phydev, phydev->interface,
			      phydev->speed, phydev->duplex);
	else
		ugeth_link_down(ugeth);
}

/* Initialize TBI PHY interface for communicating with the