Skip to content

Commit 24699cc

Browse files
Russell King (Oracle)davem330
authored andcommitted
net: phylink: add support for PCS link change notifications
Add a function, phylink_pcs_change() which can be used by PCs drivers to notify phylink about changes to the PCS link state. Signed-off-by: Russell King (Oracle) <rmk+kernel@armlinux.org.uk> Signed-off-by: David S. Miller <davem@davemloft.net>
1 parent aee6098 commit 24699cc

File tree

2 files changed

+41
-4
lines changed

2 files changed

+41
-4
lines changed

drivers/net/phy/phylink.c

Lines changed: 34 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1137,6 +1137,11 @@ static void phylink_major_config(struct phylink *pl, bool restart,
11371137
if (pcs_changed) {
11381138
phylink_pcs_disable(pl->pcs);
11391139

1140+
if (pl->pcs)
1141+
pl->pcs->phylink = NULL;
1142+
1143+
pcs->phylink = pl;
1144+
11401145
pl->pcs = pcs;
11411146
}
11421147

@@ -1991,6 +1996,14 @@ void phylink_disconnect_phy(struct phylink *pl)
19911996
}
19921997
EXPORT_SYMBOL_GPL(phylink_disconnect_phy);
19931998

1999+
static void phylink_link_changed(struct phylink *pl, bool up, const char *what)
2000+
{
2001+
if (!up)
2002+
pl->mac_link_dropped = true;
2003+
phylink_run_resolve(pl);
2004+
phylink_dbg(pl, "%s link %s\n", what, up ? "up" : "down");
2005+
}
2006+
19942007
/**
19952008
* phylink_mac_change() - notify phylink of a change in MAC state
19962009
* @pl: a pointer to a &struct phylink returned from phylink_create()
@@ -2001,13 +2014,30 @@ EXPORT_SYMBOL_GPL(phylink_disconnect_phy);
20012014
*/
20022015
void phylink_mac_change(struct phylink *pl, bool up)
20032016
{
2004-
if (!up)
2005-
pl->mac_link_dropped = true;
2006-
phylink_run_resolve(pl);
2007-
phylink_dbg(pl, "mac link %s\n", up ? "up" : "down");
2017+
phylink_link_changed(pl, up, "mac");
20082018
}
20092019
EXPORT_SYMBOL_GPL(phylink_mac_change);
20102020

2021+
/**
2022+
* phylink_pcs_change() - notify phylink of a change to PCS link state
2023+
* @pcs: pointer to &struct phylink_pcs
2024+
* @up: indicates whether the link is currently up.
2025+
*
2026+
* The PCS driver should call this when the state of its link changes
2027+
* (e.g. link failure, new negotiation results, etc.) Note: it should
2028+
* not determine "up" by reading the BMSR. If in doubt about the link
2029+
* state at interrupt time, then pass true if pcs_get_state() returns
2030+
* the latched link-down state, otherwise pass false.
2031+
*/
2032+
void phylink_pcs_change(struct phylink_pcs *pcs, bool up)
2033+
{
2034+
struct phylink *pl = pcs->phylink;
2035+
2036+
if (pl)
2037+
phylink_link_changed(pl, up, "pcs");
2038+
}
2039+
EXPORT_SYMBOL_GPL(phylink_pcs_change);
2040+
20112041
static irqreturn_t phylink_link_handler(int irq, void *data)
20122042
{
20132043
struct phylink *pl = data;

include/linux/phylink.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ struct device_node;
99
struct ethtool_cmd;
1010
struct fwnode_handle;
1111
struct net_device;
12+
struct phylink;
1213

1314
enum {
1415
MLO_PAUSE_NONE,
@@ -520,14 +521,19 @@ struct phylink_pcs_ops;
520521
/**
521522
* struct phylink_pcs - PHYLINK PCS instance
522523
* @ops: a pointer to the &struct phylink_pcs_ops structure
524+
* @phylink: pointer to &struct phylink_config
523525
* @neg_mode: provide PCS neg mode via "mode" argument
524526
* @poll: poll the PCS for link changes
525527
*
526528
* This structure is designed to be embedded within the PCS private data,
527529
* and will be passed between phylink and the PCS.
530+
*
531+
* The @phylink member is private to phylink and must not be touched by
532+
* the PCS driver.
528533
*/
529534
struct phylink_pcs {
530535
const struct phylink_pcs_ops *ops;
536+
struct phylink *phylink;
531537
bool neg_mode;
532538
bool poll;
533539
};
@@ -699,6 +705,7 @@ int phylink_fwnode_phy_connect(struct phylink *pl,
699705
void phylink_disconnect_phy(struct phylink *);
700706

701707
void phylink_mac_change(struct phylink *, bool up);
708+
void phylink_pcs_change(struct phylink_pcs *, bool up);
702709

703710
void phylink_start(struct phylink *);
704711
void phylink_stop(struct phylink *);

0 commit comments

Comments
 (0)