diff options
author | Ioana Ciornei <ioana.ciornei@nxp.com> | 2019-05-28 13:38:14 -0400 |
---|---|---|
committer | David S. Miller <davem@davemloft.net> | 2019-05-30 00:48:53 -0400 |
commit | 17091180b1521ee9b4455d75ab61b35bc0b216ff (patch) | |
tree | 6258da517a7da5ff9938eff8d817d3a874fb2a1d | |
parent | 43de61959b999279bafb031c0c9bdf0f6cd1c501 (diff) |
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: Ioana Ciornei <ioana.ciornei@nxp.com>
Signed-off-by: Vladimir Oltean <olteanv@gmail.com>
Reviewed-by: Florian Fainelli <f.fainelli@gmail.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
-rw-r--r-- | drivers/net/phy/phylink.c | 137 |
1 files changed, 77 insertions, 60 deletions
diff --git a/drivers/net/phy/phylink.c b/drivers/net/phy/phylink.c index 5f6120f3fa3f..68d0a89c52be 100644 --- a/drivers/net/phy/phylink.c +++ b/drivers/net/phy/phylink.c | |||
@@ -68,6 +68,23 @@ struct phylink { | |||
68 | struct sfp_bus *sfp_bus; | 68 | struct sfp_bus *sfp_bus; |
69 | }; | 69 | }; |
70 | 70 | ||
71 | #define phylink_printk(level, pl, fmt, ...) \ | ||
72 | do { \ | ||
73 | if ((pl)->config->type == PHYLINK_NETDEV) \ | ||
74 | netdev_printk(level, (pl)->netdev, fmt, ##__VA_ARGS__); \ | ||
75 | else if ((pl)->config->type == PHYLINK_DEV) \ | ||
76 | dev_printk(level, (pl)->dev, fmt, ##__VA_ARGS__); \ | ||
77 | } while (0) | ||
78 | |||
79 | #define phylink_err(pl, fmt, ...) \ | ||
80 | phylink_printk(KERN_ERR, pl, fmt, ##__VA_ARGS__) | ||
81 | #define phylink_warn(pl, fmt, ...) \ | ||
82 | phylink_printk(KERN_WARNING, pl, fmt, ##__VA_ARGS__) | ||
83 | #define phylink_info(pl, fmt, ...) \ | ||
84 | phylink_printk(KERN_INFO, pl, fmt, ##__VA_ARGS__) | ||
85 | #define phylink_dbg(pl, fmt, ...) \ | ||
86 | phylink_printk(KERN_DEBUG, pl, fmt, ##__VA_ARGS__) | ||
87 | |||
71 | /** | 88 | /** |
72 | * phylink_set_port_modes() - set the port type modes in the ethtool mask | 89 | * phylink_set_port_modes() - set the port type modes in the ethtool mask |
73 | * @mask: ethtool link mode mask | 90 | * @mask: ethtool link mode mask |
@@ -164,7 +181,7 @@ static int phylink_parse_fixedlink(struct phylink *pl, | |||
164 | ret = fwnode_property_read_u32_array(fwnode, "fixed-link", | 181 | ret = fwnode_property_read_u32_array(fwnode, "fixed-link", |
165 | NULL, 0); | 182 | NULL, 0); |
166 | if (ret != ARRAY_SIZE(prop)) { | 183 | if (ret != ARRAY_SIZE(prop)) { |
167 | netdev_err(pl->netdev, "broken fixed-link?\n"); | 184 | phylink_err(pl, "broken fixed-link?\n"); |
168 | return -EINVAL; | 185 | return -EINVAL; |
169 | } | 186 | } |
170 | 187 | ||
@@ -183,8 +200,8 @@ static int phylink_parse_fixedlink(struct phylink *pl, | |||
183 | 200 | ||
184 | if (pl->link_config.speed > SPEED_1000 && | 201 | if (pl->link_config.speed > SPEED_1000 && |
185 | pl->link_config.duplex != DUPLEX_FULL) | 202 | pl->link_config.duplex != DUPLEX_FULL) |
186 | netdev_warn(pl->netdev, "fixed link specifies half duplex for %dMbps link?\n", | 203 | phylink_warn(pl, "fixed link specifies half duplex for %dMbps link?\n", |
187 | pl->link_config.speed); | 204 | pl->link_config.speed); |
188 | 205 | ||
189 | bitmap_fill(pl->supported, __ETHTOOL_LINK_MODE_MASK_NBITS); | 206 | bitmap_fill(pl->supported, __ETHTOOL_LINK_MODE_MASK_NBITS); |
190 | linkmode_copy(pl->link_config.advertising, pl->supported); | 207 | linkmode_copy(pl->link_config.advertising, pl->supported); |
@@ -197,9 +214,9 @@ static int phylink_parse_fixedlink(struct phylink *pl, | |||
197 | if (s) { | 214 | if (s) { |
198 | __set_bit(s->bit, pl->supported); | 215 | __set_bit(s->bit, pl->supported); |
199 | } else { | 216 | } else { |
200 | netdev_warn(pl->netdev, "fixed link %s duplex %dMbps not recognised\n", | 217 | phylink_warn(pl, "fixed link %s duplex %dMbps not recognised\n", |
201 | pl->link_config.duplex == DUPLEX_FULL ? "full" : "half", | 218 | pl->link_config.duplex == DUPLEX_FULL ? "full" : "half", |
202 | pl->link_config.speed); | 219 | pl->link_config.speed); |
203 | } | 220 | } |
204 | 221 | ||
205 | linkmode_and(pl->link_config.advertising, pl->link_config.advertising, | 222 | linkmode_and(pl->link_config.advertising, pl->link_config.advertising, |
@@ -224,8 +241,8 @@ static int phylink_parse_mode(struct phylink *pl, struct fwnode_handle *fwnode) | |||
224 | if (fwnode_property_read_string(fwnode, "managed", &managed) == 0 && | 241 | if (fwnode_property_read_string(fwnode, "managed", &managed) == 0 && |
225 | strcmp(managed, "in-band-status") == 0) { | 242 | strcmp(managed, "in-band-status") == 0) { |
226 | if (pl->link_an_mode == MLO_AN_FIXED) { | 243 | if (pl->link_an_mode == MLO_AN_FIXED) { |
227 | netdev_err(pl->netdev, | 244 | phylink_err(pl, |
228 | "can't use both fixed-link and in-band-status\n"); | 245 | "can't use both fixed-link and in-band-status\n"); |
229 | return -EINVAL; | 246 | return -EINVAL; |
230 | } | 247 | } |
231 | 248 | ||
@@ -272,17 +289,17 @@ static int phylink_parse_mode(struct phylink *pl, struct fwnode_handle *fwnode) | |||
272 | break; | 289 | break; |
273 | 290 | ||
274 | default: | 291 | default: |
275 | netdev_err(pl->netdev, | 292 | phylink_err(pl, |
276 | "incorrect link mode %s for in-band status\n", | 293 | "incorrect link mode %s for in-band status\n", |
277 | phy_modes(pl->link_config.interface)); | 294 | phy_modes(pl->link_config.interface)); |
278 | return -EINVAL; | 295 | return -EINVAL; |
279 | } | 296 | } |
280 | 297 | ||
281 | linkmode_copy(pl->link_config.advertising, pl->supported); | 298 | linkmode_copy(pl->link_config.advertising, pl->supported); |
282 | 299 | ||
283 | if (phylink_validate(pl, pl->supported, &pl->link_config)) { | 300 | if (phylink_validate(pl, pl->supported, &pl->link_config)) { |
284 | netdev_err(pl->netdev, | 301 | phylink_err(pl, |
285 | "failed to validate link configuration for in-band status\n"); | 302 | "failed to validate link configuration for in-band status\n"); |
286 | return -EINVAL; | 303 | return -EINVAL; |
287 | } | 304 | } |
288 | } | 305 | } |
@@ -293,14 +310,14 @@ static int phylink_parse_mode(struct phylink *pl, struct fwnode_handle *fwnode) | |||
293 | static void phylink_mac_config(struct phylink *pl, | 310 | static void phylink_mac_config(struct phylink *pl, |
294 | const struct phylink_link_state *state) | 311 | const struct phylink_link_state *state) |
295 | { | 312 | { |
296 | netdev_dbg(pl->netdev, | 313 | phylink_dbg(pl, |
297 | "%s: mode=%s/%s/%s/%s adv=%*pb pause=%02x link=%u an=%u\n", | 314 | "%s: mode=%s/%s/%s/%s adv=%*pb pause=%02x link=%u an=%u\n", |
298 | __func__, phylink_an_mode_str(pl->link_an_mode), | 315 | __func__, phylink_an_mode_str(pl->link_an_mode), |
299 | phy_modes(state->interface), | 316 | phy_modes(state->interface), |
300 | phy_speed_to_str(state->speed), | 317 | phy_speed_to_str(state->speed), |
301 | phy_duplex_to_str(state->duplex), | 318 | phy_duplex_to_str(state->duplex), |
302 | __ETHTOOL_LINK_MODE_MASK_NBITS, state->advertising, | 319 | __ETHTOOL_LINK_MODE_MASK_NBITS, state->advertising, |
303 | state->pause, state->link, state->an_enabled); | 320 | state->pause, state->link, state->an_enabled); |
304 | 321 | ||
305 | pl->ops->mac_config(pl->config, pl->link_an_mode, state); | 322 | pl->ops->mac_config(pl->config, pl->link_an_mode, state); |
306 | } | 323 | } |
@@ -409,11 +426,11 @@ static void phylink_mac_link_up(struct phylink *pl, | |||
409 | if (ndev) | 426 | if (ndev) |
410 | netif_carrier_on(ndev); | 427 | netif_carrier_on(ndev); |
411 | 428 | ||
412 | netdev_info(ndev, | 429 | phylink_info(pl, |
413 | "Link is Up - %s/%s - flow control %s\n", | 430 | "Link is Up - %s/%s - flow control %s\n", |
414 | phy_speed_to_str(link_state.speed), | 431 | phy_speed_to_str(link_state.speed), |
415 | phy_duplex_to_str(link_state.duplex), | 432 | phy_duplex_to_str(link_state.duplex), |
416 | phylink_pause_to_str(link_state.pause)); | 433 | phylink_pause_to_str(link_state.pause)); |
417 | } | 434 | } |
418 | 435 | ||
419 | static void phylink_mac_link_down(struct phylink *pl) | 436 | static void phylink_mac_link_down(struct phylink *pl) |
@@ -424,7 +441,7 @@ static void phylink_mac_link_down(struct phylink *pl) | |||
424 | netif_carrier_off(ndev); | 441 | netif_carrier_off(ndev); |
425 | pl->ops->mac_link_down(pl->config, pl->link_an_mode, | 442 | pl->ops->mac_link_down(pl->config, pl->link_an_mode, |
426 | pl->phy_state.interface); | 443 | pl->phy_state.interface); |
427 | netdev_info(ndev, "Link is Down\n"); | 444 | phylink_info(pl, "Link is Down\n"); |
428 | } | 445 | } |
429 | 446 | ||
430 | static void phylink_resolve(struct work_struct *w) | 447 | static void phylink_resolve(struct work_struct *w) |
@@ -537,8 +554,8 @@ static int phylink_register_sfp(struct phylink *pl, | |||
537 | if (ret == -ENOENT) | 554 | if (ret == -ENOENT) |
538 | return 0; | 555 | return 0; |
539 | 556 | ||
540 | netdev_err(pl->netdev, "unable to parse \"sfp\" node: %d\n", | 557 | phylink_err(pl, "unable to parse \"sfp\" node: %d\n", |
541 | ret); | 558 | ret); |
542 | return ret; | 559 | return ret; |
543 | } | 560 | } |
544 | 561 | ||
@@ -670,10 +687,10 @@ static void phylink_phy_change(struct phy_device *phydev, bool up, | |||
670 | 687 | ||
671 | phylink_run_resolve(pl); | 688 | phylink_run_resolve(pl); |
672 | 689 | ||
673 | netdev_dbg(pl->netdev, "phy link %s %s/%s/%s\n", up ? "up" : "down", | 690 | phylink_dbg(pl, "phy link %s %s/%s/%s\n", up ? "up" : "down", |
674 | phy_modes(phydev->interface), | 691 | phy_modes(phydev->interface), |
675 | phy_speed_to_str(phydev->speed), | 692 | phy_speed_to_str(phydev->speed), |
676 | phy_duplex_to_str(phydev->duplex)); | 693 | phy_duplex_to_str(phydev->duplex)); |
677 | } | 694 | } |
678 | 695 | ||
679 | static int phylink_bringup_phy(struct phylink *pl, struct phy_device *phy) | 696 | static int phylink_bringup_phy(struct phylink *pl, struct phy_device *phy) |
@@ -706,9 +723,9 @@ static int phylink_bringup_phy(struct phylink *pl, struct phy_device *phy) | |||
706 | phy->phylink = pl; | 723 | phy->phylink = pl; |
707 | phy->phy_link_change = phylink_phy_change; | 724 | phy->phy_link_change = phylink_phy_change; |
708 | 725 | ||
709 | netdev_info(pl->netdev, | 726 | phylink_info(pl, |
710 | "PHY [%s] driver [%s]\n", dev_name(&phy->mdio.dev), | 727 | "PHY [%s] driver [%s]\n", dev_name(&phy->mdio.dev), |
711 | phy->drv->name); | 728 | phy->drv->name); |
712 | 729 | ||
713 | mutex_lock(&phy->lock); | 730 | mutex_lock(&phy->lock); |
714 | mutex_lock(&pl->state_mutex); | 731 | mutex_lock(&pl->state_mutex); |
@@ -721,10 +738,10 @@ static int phylink_bringup_phy(struct phylink *pl, struct phy_device *phy) | |||
721 | mutex_unlock(&pl->state_mutex); | 738 | mutex_unlock(&pl->state_mutex); |
722 | mutex_unlock(&phy->lock); | 739 | mutex_unlock(&phy->lock); |
723 | 740 | ||
724 | netdev_dbg(pl->netdev, | 741 | phylink_dbg(pl, |
725 | "phy: setting supported %*pb advertising %*pb\n", | 742 | "phy: setting supported %*pb advertising %*pb\n", |
726 | __ETHTOOL_LINK_MODE_MASK_NBITS, pl->supported, | 743 | __ETHTOOL_LINK_MODE_MASK_NBITS, pl->supported, |
727 | __ETHTOOL_LINK_MODE_MASK_NBITS, phy->advertising); | 744 | __ETHTOOL_LINK_MODE_MASK_NBITS, phy->advertising); |
728 | 745 | ||
729 | if (phy_interrupt_is_valid(phy)) | 746 | if (phy_interrupt_is_valid(phy)) |
730 | phy_request_interrupt(phy); | 747 | phy_request_interrupt(phy); |
@@ -902,7 +919,7 @@ void phylink_mac_change(struct phylink *pl, bool up) | |||
902 | if (!up) | 919 | if (!up) |
903 | pl->mac_link_dropped = true; | 920 | pl->mac_link_dropped = true; |
904 | phylink_run_resolve(pl); | 921 | phylink_run_resolve(pl); |
905 | netdev_dbg(pl->netdev, "mac link %s\n", up ? "up" : "down"); | 922 | phylink_dbg(pl, "mac link %s\n", up ? "up" : "down"); |
906 | } | 923 | } |
907 | EXPORT_SYMBOL_GPL(phylink_mac_change); | 924 | EXPORT_SYMBOL_GPL(phylink_mac_change); |
908 | 925 | ||
@@ -918,9 +935,9 @@ void phylink_start(struct phylink *pl) | |||
918 | { | 935 | { |
919 | ASSERT_RTNL(); | 936 | ASSERT_RTNL(); |
920 | 937 | ||
921 | netdev_info(pl->netdev, "configuring for %s/%s link mode\n", | 938 | phylink_info(pl, "configuring for %s/%s link mode\n", |
922 | phylink_an_mode_str(pl->link_an_mode), | 939 | phylink_an_mode_str(pl->link_an_mode), |
923 | phy_modes(pl->link_config.interface)); | 940 | phy_modes(pl->link_config.interface)); |
924 | 941 | ||
925 | /* Always set the carrier off */ | 942 | /* Always set the carrier off */ |
926 | if (pl->netdev) | 943 | if (pl->netdev) |
@@ -1631,33 +1648,33 @@ static int phylink_sfp_module_insert(void *upstream, | |||
1631 | /* Ignore errors if we're expecting a PHY to attach later */ | 1648 | /* Ignore errors if we're expecting a PHY to attach later */ |
1632 | ret = phylink_validate(pl, support, &config); | 1649 | ret = phylink_validate(pl, support, &config); |
1633 | if (ret) { | 1650 | if (ret) { |
1634 | netdev_err(pl->netdev, "validation with support %*pb failed: %d\n", | 1651 | phylink_err(pl, "validation with support %*pb failed: %d\n", |
1635 | __ETHTOOL_LINK_MODE_MASK_NBITS, support, ret); | 1652 | __ETHTOOL_LINK_MODE_MASK_NBITS, support, ret); |
1636 | return ret; | 1653 | return ret; |
1637 | } | 1654 | } |
1638 | 1655 | ||
1639 | iface = sfp_select_interface(pl->sfp_bus, id, config.advertising); | 1656 | iface = sfp_select_interface(pl->sfp_bus, id, config.advertising); |
1640 | if (iface == PHY_INTERFACE_MODE_NA) { | 1657 | if (iface == PHY_INTERFACE_MODE_NA) { |
1641 | netdev_err(pl->netdev, | 1658 | phylink_err(pl, |
1642 | "selection of interface failed, advertisement %*pb\n", | 1659 | "selection of interface failed, advertisement %*pb\n", |
1643 | __ETHTOOL_LINK_MODE_MASK_NBITS, config.advertising); | 1660 | __ETHTOOL_LINK_MODE_MASK_NBITS, config.advertising); |
1644 | return -EINVAL; | 1661 | return -EINVAL; |
1645 | } | 1662 | } |
1646 | 1663 | ||
1647 | config.interface = iface; | 1664 | config.interface = iface; |
1648 | ret = phylink_validate(pl, support, &config); | 1665 | ret = phylink_validate(pl, support, &config); |
1649 | if (ret) { | 1666 | if (ret) { |
1650 | netdev_err(pl->netdev, "validation of %s/%s with support %*pb failed: %d\n", | 1667 | phylink_err(pl, "validation of %s/%s with support %*pb failed: %d\n", |
1651 | phylink_an_mode_str(MLO_AN_INBAND), | 1668 | phylink_an_mode_str(MLO_AN_INBAND), |
1652 | phy_modes(config.interface), | 1669 | phy_modes(config.interface), |
1653 | __ETHTOOL_LINK_MODE_MASK_NBITS, support, ret); | 1670 | __ETHTOOL_LINK_MODE_MASK_NBITS, support, ret); |
1654 | return ret; | 1671 | return ret; |
1655 | } | 1672 | } |
1656 | 1673 | ||
1657 | netdev_dbg(pl->netdev, "requesting link mode %s/%s with support %*pb\n", | 1674 | phylink_dbg(pl, "requesting link mode %s/%s with support %*pb\n", |
1658 | phylink_an_mode_str(MLO_AN_INBAND), | 1675 | phylink_an_mode_str(MLO_AN_INBAND), |
1659 | phy_modes(config.interface), | 1676 | phy_modes(config.interface), |
1660 | __ETHTOOL_LINK_MODE_MASK_NBITS, support); | 1677 | __ETHTOOL_LINK_MODE_MASK_NBITS, support); |
1661 | 1678 | ||
1662 | if (phy_interface_mode_is_8023z(iface) && pl->phydev) | 1679 | if (phy_interface_mode_is_8023z(iface) && pl->phydev) |
1663 | return -EINVAL; | 1680 | return -EINVAL; |
@@ -1676,9 +1693,9 @@ static int phylink_sfp_module_insert(void *upstream, | |||
1676 | 1693 | ||
1677 | changed = true; | 1694 | changed = true; |
1678 | 1695 | ||
1679 | netdev_info(pl->netdev, "switched to %s/%s link mode\n", | 1696 | phylink_info(pl, "switched to %s/%s link mode\n", |
1680 | phylink_an_mode_str(MLO_AN_INBAND), | 1697 | phylink_an_mode_str(MLO_AN_INBAND), |
1681 | phy_modes(config.interface)); | 1698 | phy_modes(config.interface)); |
1682 | } | 1699 | } |
1683 | 1700 | ||
1684 | pl->link_port = port; | 1701 | pl->link_port = port; |