Commit 17091180 authored by Ioana Ciornei's avatar Ioana Ciornei Committed by David S. Miller
Browse files

net: phylink: Add phylink_{printk, err, warn, info, dbg} macros



With the latest addition to the PHYLINK infrastructure, we are faced
with a decision on when to print necessary info using the struct
net_device and when with the struct device.

Add a series of macros that encapsulate this decision and replace all
uses of netdev_err&co with phylink_err.

Signed-off-by: default avatarIoana Ciornei <ioana.ciornei@nxp.com>
Signed-off-by: default avatarVladimir Oltean <olteanv@gmail.com>
Reviewed-by: default avatarFlorian Fainelli <f.fainelli@gmail.com>
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parent 43de6195
Loading
Loading
Loading
Loading
+77 −60
Original line number Diff line number Diff line
@@ -68,6 +68,23 @@ struct phylink {
	struct sfp_bus *sfp_bus;
};

#define phylink_printk(level, pl, fmt, ...) \
	do { \
		if ((pl)->config->type == PHYLINK_NETDEV) \
			netdev_printk(level, (pl)->netdev, fmt, ##__VA_ARGS__); \
		else if ((pl)->config->type == PHYLINK_DEV) \
			dev_printk(level, (pl)->dev, fmt, ##__VA_ARGS__); \
	} while (0)

#define phylink_err(pl, fmt, ...) \
	phylink_printk(KERN_ERR, pl, fmt, ##__VA_ARGS__)
#define phylink_warn(pl, fmt, ...) \
	phylink_printk(KERN_WARNING, pl, fmt, ##__VA_ARGS__)
#define phylink_info(pl, fmt, ...) \
	phylink_printk(KERN_INFO, pl, fmt, ##__VA_ARGS__)
#define phylink_dbg(pl, fmt, ...) \
	phylink_printk(KERN_DEBUG, pl, fmt, ##__VA_ARGS__)

/**
 * phylink_set_port_modes() - set the port type modes in the ethtool mask
 * @mask: ethtool link mode mask
@@ -164,7 +181,7 @@ static int phylink_parse_fixedlink(struct phylink *pl,
		ret = fwnode_property_read_u32_array(fwnode, "fixed-link",
						     NULL, 0);
		if (ret != ARRAY_SIZE(prop)) {
			netdev_err(pl->netdev, "broken fixed-link?\n");
			phylink_err(pl, "broken fixed-link?\n");
			return -EINVAL;
		}

@@ -183,7 +200,7 @@ static int phylink_parse_fixedlink(struct phylink *pl,

	if (pl->link_config.speed > SPEED_1000 &&
	    pl->link_config.duplex != DUPLEX_FULL)
		netdev_warn(pl->netdev, "fixed link specifies half duplex for %dMbps link?\n",
		phylink_warn(pl, "fixed link specifies half duplex for %dMbps link?\n",
			     pl->link_config.speed);

	bitmap_fill(pl->supported, __ETHTOOL_LINK_MODE_MASK_NBITS);
@@ -197,7 +214,7 @@ static int phylink_parse_fixedlink(struct phylink *pl,
	if (s) {
		__set_bit(s->bit, pl->supported);
	} else {
		netdev_warn(pl->netdev, "fixed link %s duplex %dMbps not recognised\n",
		phylink_warn(pl, "fixed link %s duplex %dMbps not recognised\n",
			     pl->link_config.duplex == DUPLEX_FULL ? "full" : "half",
			     pl->link_config.speed);
	}
@@ -224,7 +241,7 @@ static int phylink_parse_mode(struct phylink *pl, struct fwnode_handle *fwnode)
	if (fwnode_property_read_string(fwnode, "managed", &managed) == 0 &&
	    strcmp(managed, "in-band-status") == 0) {
		if (pl->link_an_mode == MLO_AN_FIXED) {
			netdev_err(pl->netdev,
			phylink_err(pl,
				    "can't use both fixed-link and in-band-status\n");
			return -EINVAL;
		}
@@ -272,7 +289,7 @@ static int phylink_parse_mode(struct phylink *pl, struct fwnode_handle *fwnode)
			break;

		default:
			netdev_err(pl->netdev,
			phylink_err(pl,
				    "incorrect link mode %s for in-band status\n",
				    phy_modes(pl->link_config.interface));
			return -EINVAL;
@@ -281,7 +298,7 @@ static int phylink_parse_mode(struct phylink *pl, struct fwnode_handle *fwnode)
		linkmode_copy(pl->link_config.advertising, pl->supported);

		if (phylink_validate(pl, pl->supported, &pl->link_config)) {
			netdev_err(pl->netdev,
			phylink_err(pl,
				    "failed to validate link configuration for in-band status\n");
			return -EINVAL;
		}
@@ -293,7 +310,7 @@ static int phylink_parse_mode(struct phylink *pl, struct fwnode_handle *fwnode)
static void phylink_mac_config(struct phylink *pl,
			       const struct phylink_link_state *state)
{
	netdev_dbg(pl->netdev,
	phylink_dbg(pl,
		    "%s: mode=%s/%s/%s/%s adv=%*pb pause=%02x link=%u an=%u\n",
		    __func__, phylink_an_mode_str(pl->link_an_mode),
		    phy_modes(state->interface),
@@ -409,7 +426,7 @@ static void phylink_mac_link_up(struct phylink *pl,
	if (ndev)
		netif_carrier_on(ndev);

	netdev_info(ndev,
	phylink_info(pl,
		     "Link is Up - %s/%s - flow control %s\n",
		     phy_speed_to_str(link_state.speed),
		     phy_duplex_to_str(link_state.duplex),
@@ -424,7 +441,7 @@ static void phylink_mac_link_down(struct phylink *pl)
		netif_carrier_off(ndev);
	pl->ops->mac_link_down(pl->config, pl->link_an_mode,
			       pl->phy_state.interface);
	netdev_info(ndev, "Link is Down\n");
	phylink_info(pl, "Link is Down\n");
}

static void phylink_resolve(struct work_struct *w)
@@ -537,7 +554,7 @@ static int phylink_register_sfp(struct phylink *pl,
		if (ret == -ENOENT)
			return 0;

		netdev_err(pl->netdev, "unable to parse \"sfp\" node: %d\n",
		phylink_err(pl, "unable to parse \"sfp\" node: %d\n",
			    ret);
		return ret;
	}
@@ -670,7 +687,7 @@ static void phylink_phy_change(struct phy_device *phydev, bool up,

	phylink_run_resolve(pl);

	netdev_dbg(pl->netdev, "phy link %s %s/%s/%s\n", up ? "up" : "down",
	phylink_dbg(pl, "phy link %s %s/%s/%s\n", up ? "up" : "down",
		    phy_modes(phydev->interface),
		    phy_speed_to_str(phydev->speed),
		    phy_duplex_to_str(phydev->duplex));
@@ -706,7 +723,7 @@ static int phylink_bringup_phy(struct phylink *pl, struct phy_device *phy)
	phy->phylink = pl;
	phy->phy_link_change = phylink_phy_change;

	netdev_info(pl->netdev,
	phylink_info(pl,
		     "PHY [%s] driver [%s]\n", dev_name(&phy->mdio.dev),
		     phy->drv->name);

@@ -721,7 +738,7 @@ static int phylink_bringup_phy(struct phylink *pl, struct phy_device *phy)
	mutex_unlock(&pl->state_mutex);
	mutex_unlock(&phy->lock);

	netdev_dbg(pl->netdev,
	phylink_dbg(pl,
		    "phy: setting supported %*pb advertising %*pb\n",
		    __ETHTOOL_LINK_MODE_MASK_NBITS, pl->supported,
		    __ETHTOOL_LINK_MODE_MASK_NBITS, phy->advertising);
@@ -902,7 +919,7 @@ void phylink_mac_change(struct phylink *pl, bool up)
	if (!up)
		pl->mac_link_dropped = true;
	phylink_run_resolve(pl);
	netdev_dbg(pl->netdev, "mac link %s\n", up ? "up" : "down");
	phylink_dbg(pl, "mac link %s\n", up ? "up" : "down");
}
EXPORT_SYMBOL_GPL(phylink_mac_change);

@@ -918,7 +935,7 @@ void phylink_start(struct phylink *pl)
{
	ASSERT_RTNL();

	netdev_info(pl->netdev, "configuring for %s/%s link mode\n",
	phylink_info(pl, "configuring for %s/%s link mode\n",
		     phylink_an_mode_str(pl->link_an_mode),
		     phy_modes(pl->link_config.interface));

@@ -1631,14 +1648,14 @@ static int phylink_sfp_module_insert(void *upstream,
	/* Ignore errors if we're expecting a PHY to attach later */
	ret = phylink_validate(pl, support, &config);
	if (ret) {
		netdev_err(pl->netdev, "validation with support %*pb failed: %d\n",
		phylink_err(pl, "validation with support %*pb failed: %d\n",
			    __ETHTOOL_LINK_MODE_MASK_NBITS, support, ret);
		return ret;
	}

	iface = sfp_select_interface(pl->sfp_bus, id, config.advertising);
	if (iface == PHY_INTERFACE_MODE_NA) {
		netdev_err(pl->netdev,
		phylink_err(pl,
			    "selection of interface failed, advertisement %*pb\n",
			    __ETHTOOL_LINK_MODE_MASK_NBITS, config.advertising);
		return -EINVAL;
@@ -1647,14 +1664,14 @@ static int phylink_sfp_module_insert(void *upstream,
	config.interface = iface;
	ret = phylink_validate(pl, support, &config);
	if (ret) {
		netdev_err(pl->netdev, "validation of %s/%s with support %*pb failed: %d\n",
		phylink_err(pl, "validation of %s/%s with support %*pb failed: %d\n",
			    phylink_an_mode_str(MLO_AN_INBAND),
			    phy_modes(config.interface),
			    __ETHTOOL_LINK_MODE_MASK_NBITS, support, ret);
		return ret;
	}

	netdev_dbg(pl->netdev, "requesting link mode %s/%s with support %*pb\n",
	phylink_dbg(pl, "requesting link mode %s/%s with support %*pb\n",
		    phylink_an_mode_str(MLO_AN_INBAND),
		    phy_modes(config.interface),
		    __ETHTOOL_LINK_MODE_MASK_NBITS, support);
@@ -1676,7 +1693,7 @@ static int phylink_sfp_module_insert(void *upstream,

		changed = true;

		netdev_info(pl->netdev, "switched to %s/%s link mode\n",
		phylink_info(pl, "switched to %s/%s link mode\n",
			     phylink_an_mode_str(MLO_AN_INBAND),
			     phy_modes(config.interface));
	}