Skip to content

Commit 824c2d6

Browse files
committed
Merge branch 'phylink-dsa-prep'
Florian Fainelli says: ==================== PHYLINK preparatory patches for DSA In preparation for having DSA migrate to PHYLINK, I had to come up with a number of preparatory patches: - we need to be able to pass phy_flags from an external component calling phylink_of_phy_connect() - DSA tries to connect through OF first, then fallsback using its own internal MDIO bus, in that case we would both show an error, but also not know what the correct phy_interface_t would be, instead use the PHY device/driver provided one - Finally bcm_sf2 makes use of all possible PHYs out there: internal, external, fixed, and MoCA, the latter requires a bit of help to signal link notifications through a MMIO interrupt, as well a report a correct PORT type Changes in v2: - rebased against latest net-next/master - added kernel doc documentation - dropped error message in phylink_of_phy_connect() as suggested by Russell ==================== Signed-off-by: David S. Miller <davem@davemloft.net>
2 parents 7268586 + 4be11ef commit 824c2d6

File tree

2 files changed

+52
-9
lines changed

2 files changed

+52
-9
lines changed

drivers/net/phy/phylink.c

Lines changed: 48 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,8 @@ struct phylink {
5454
/* The link configuration settings */
5555
struct phylink_link_state link_config;
5656
struct gpio_desc *link_gpio;
57+
void (*get_fixed_state)(struct net_device *dev,
58+
struct phylink_link_state *s);
5759

5860
struct mutex state_mutex;
5961
struct phylink_link_state phy_state;
@@ -350,12 +352,14 @@ static int phylink_get_mac_state(struct phylink *pl, struct phylink_link_state *
350352
}
351353

352354
/* The fixed state is... fixed except for the link state,
353-
* which may be determined by a GPIO.
355+
* which may be determined by a GPIO or a callback.
354356
*/
355357
static void phylink_get_fixed_state(struct phylink *pl, struct phylink_link_state *state)
356358
{
357359
*state = pl->link_config;
358-
if (pl->link_gpio)
360+
if (pl->get_fixed_state)
361+
pl->get_fixed_state(pl->netdev, state);
362+
else if (pl->link_gpio)
359363
state->link = !!gpiod_get_value(pl->link_gpio);
360364
}
361365

@@ -552,7 +556,10 @@ struct phylink *phylink_create(struct net_device *ndev,
552556
pl->netdev = ndev;
553557
pl->phy_state.interface = iface;
554558
pl->link_interface = iface;
555-
pl->link_port = PORT_MII;
559+
if (iface == PHY_INTERFACE_MODE_MOCA)
560+
pl->link_port = PORT_BNC;
561+
else
562+
pl->link_port = PORT_MII;
556563
pl->link_config.interface = iface;
557564
pl->link_config.pause = MLO_PAUSE_AN;
558565
pl->link_config.speed = SPEED_UNKNOWN;
@@ -715,6 +722,12 @@ int phylink_connect_phy(struct phylink *pl, struct phy_device *phy)
715722
phy_interface_mode_is_8023z(pl->link_interface))))
716723
return -EINVAL;
717724

725+
/* Use PHY device/driver interface */
726+
if (pl->link_interface == PHY_INTERFACE_MODE_NA) {
727+
pl->link_interface = phy->interface;
728+
pl->link_config.interface = pl->link_interface;
729+
}
730+
718731
ret = phy_attach_direct(pl->netdev, phy, 0, pl->link_interface);
719732
if (ret)
720733
return ret;
@@ -731,14 +744,16 @@ EXPORT_SYMBOL_GPL(phylink_connect_phy);
731744
* phylink_of_phy_connect() - connect the PHY specified in the DT mode.
732745
* @pl: a pointer to a &struct phylink returned from phylink_create()
733746
* @dn: a pointer to a &struct device_node.
747+
* @flags: PHY-specific flags to communicate to the PHY device driver
734748
*
735749
* Connect the phy specified in the device node @dn to the phylink instance
736750
* specified by @pl. Actions specified in phylink_connect_phy() will be
737751
* performed.
738752
*
739753
* Returns 0 on success or a negative errno.
740754
*/
741-
int phylink_of_phy_connect(struct phylink *pl, struct device_node *dn)
755+
int phylink_of_phy_connect(struct phylink *pl, struct device_node *dn,
756+
u32 flags)
742757
{
743758
struct device_node *phy_node;
744759
struct phy_device *phy_dev;
@@ -757,14 +772,13 @@ int phylink_of_phy_connect(struct phylink *pl, struct device_node *dn)
757772
phy_node = of_parse_phandle(dn, "phy-device", 0);
758773

759774
if (!phy_node) {
760-
if (pl->link_an_mode == MLO_AN_PHY) {
761-
netdev_err(pl->netdev, "unable to find PHY node\n");
775+
if (pl->link_an_mode == MLO_AN_PHY)
762776
return -ENODEV;
763-
}
764777
return 0;
765778
}
766779

767-
phy_dev = of_phy_attach(pl->netdev, phy_node, 0, pl->link_interface);
780+
phy_dev = of_phy_attach(pl->netdev, phy_node, flags,
781+
pl->link_interface);
768782
/* We're done with the phy_node handle */
769783
of_node_put(phy_node);
770784

@@ -807,6 +821,32 @@ void phylink_disconnect_phy(struct phylink *pl)
807821
}
808822
EXPORT_SYMBOL_GPL(phylink_disconnect_phy);
809823

824+
/**
825+
* phylink_fixed_state_cb() - allow setting a fixed link callback
826+
* @pl: a pointer to a &struct phylink returned from phylink_create()
827+
* @cb: callback to execute to determine the fixed link state.
828+
*
829+
* The MAC driver should call this driver when the state of its link
830+
* can be determined through e.g: an out of band MMIO register.
831+
*/
832+
int phylink_fixed_state_cb(struct phylink *pl,
833+
void (*cb)(struct net_device *dev,
834+
struct phylink_link_state *state))
835+
{
836+
/* It does not make sense to let the link be overriden unless we use
837+
* MLO_AN_FIXED
838+
*/
839+
if (pl->link_an_mode != MLO_AN_FIXED)
840+
return -EINVAL;
841+
842+
mutex_lock(&pl->state_mutex);
843+
pl->get_fixed_state = cb;
844+
mutex_unlock(&pl->state_mutex);
845+
846+
return 0;
847+
}
848+
EXPORT_SYMBOL_GPL(phylink_fixed_state_cb);
849+
810850
/**
811851
* phylink_mac_change() - notify phylink of a change in MAC state
812852
* @pl: a pointer to a &struct phylink returned from phylink_create()

include/linux/phylink.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -188,8 +188,11 @@ struct phylink *phylink_create(struct net_device *, struct fwnode_handle *,
188188
void phylink_destroy(struct phylink *);
189189

190190
int phylink_connect_phy(struct phylink *, struct phy_device *);
191-
int phylink_of_phy_connect(struct phylink *, struct device_node *);
191+
int phylink_of_phy_connect(struct phylink *, struct device_node *, u32 flags);
192192
void phylink_disconnect_phy(struct phylink *);
193+
int phylink_fixed_state_cb(struct phylink *,
194+
void (*cb)(struct net_device *dev,
195+
struct phylink_link_state *));
193196

194197
void phylink_mac_change(struct phylink *, bool up);
195198

0 commit comments

Comments
 (0)