Skip to content

Commit 8796c89

Browse files
Russell Kingdavem330
authored andcommitted
phylink: add documentation for kernel APIs
Add kernel-doc documentation for phylink kernel APIs, and link it into the networking kapi documentation under "Network device support". Signed-off-by: Russell King <[email protected]> Reviewed-by: Florian Fainelli <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent 85b4394 commit 8796c89

File tree

3 files changed

+329
-48
lines changed

3 files changed

+329
-48
lines changed

Documentation/networking/kapi.rst

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -145,3 +145,15 @@ PHY Support
145145

146146
.. kernel-doc:: drivers/net/phy/mdio_bus.c
147147
:internal:
148+
149+
PHYLINK
150+
-------
151+
152+
PHYLINK interfaces traditional network drivers with PHYLIB, fixed-links,
153+
and SFF modules (eg, hot-pluggable SFP) that may contain PHYs. PHYLINK
154+
provides management of the link state and link modes.
155+
156+
.. kernel-doc:: include/linux/phylink.h
157+
:internal:
158+
159+
.. kernel-doc:: drivers/net/phy/phylink.c

drivers/net/phy/phylink.c

Lines changed: 182 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,11 @@ enum {
3636
PHYLINK_DISABLE_LINK,
3737
};
3838

39+
/**
40+
* struct phylink - internal data type for phylink
41+
*/
3942
struct phylink {
43+
/* private: */
4044
struct net_device *netdev;
4145
const struct phylink_mac_ops *ops;
4246

@@ -87,6 +91,13 @@ static inline bool linkmode_empty(const unsigned long *src)
8791
return bitmap_empty(src, __ETHTOOL_LINK_MODE_MASK_NBITS);
8892
}
8993

94+
/**
95+
* phylink_set_port_modes() - set the port type modes in the ethtool mask
96+
* @mask: ethtool link mode mask
97+
*
98+
* Sets all the port type modes in the ethtool mask. MAC drivers should
99+
* use this in their 'validate' callback.
100+
*/
90101
void phylink_set_port_modes(unsigned long *mask)
91102
{
92103
phylink_set(mask, TP);
@@ -496,6 +507,19 @@ static int phylink_register_sfp(struct phylink *pl, struct device_node *np)
496507
return 0;
497508
}
498509

510+
/**
511+
* phylink_create() - create a phylink instance
512+
* @ndev: a pointer to the &struct net_device
513+
* @np: a pointer to a &struct device_node describing the network interface
514+
* @iface: the desired link mode defined by &typedef phy_interface_t
515+
* @ops: a pointer to a &struct phylink_mac_ops for the MAC.
516+
*
517+
* Create a new phylink instance, and parse the link parameters found in @np.
518+
* This will parse in-band modes, fixed-link or SFP configuration.
519+
*
520+
* Returns a pointer to a &struct phylink, or an error-pointer value. Users
521+
* must use IS_ERR() to check for errors from this function.
522+
*/
499523
struct phylink *phylink_create(struct net_device *ndev, struct device_node *np,
500524
phy_interface_t iface,
501525
const struct phylink_mac_ops *ops)
@@ -548,6 +572,13 @@ struct phylink *phylink_create(struct net_device *ndev, struct device_node *np,
548572
}
549573
EXPORT_SYMBOL_GPL(phylink_create);
550574

575+
/**
576+
* phylink_destroy() - cleanup and destroy the phylink instance
577+
* @pl: a pointer to a &struct phylink returned from phylink_create()
578+
*
579+
* Destroy a phylink instance. Any PHY that has been attached must have been
580+
* cleaned up via phylink_disconnect_phy() prior to calling this function.
581+
*/
551582
void phylink_destroy(struct phylink *pl)
552583
{
553584
if (pl->sfp_bus)
@@ -644,6 +675,21 @@ static int phylink_bringup_phy(struct phylink *pl, struct phy_device *phy)
644675
return 0;
645676
}
646677

678+
/**
679+
* phylink_connect_phy() - connect a PHY to the phylink instance
680+
* @pl: a pointer to a &struct phylink returned from phylink_create()
681+
* @phy: a pointer to a &struct phy_device.
682+
*
683+
* Connect @phy to the phylink instance specified by @pl by calling
684+
* phy_attach_direct(). Configure the @phy according to the MAC driver's
685+
* capabilities, start the PHYLIB state machine and enable any interrupts
686+
* that the PHY supports.
687+
*
688+
* This updates the phylink's ethtool supported and advertising link mode
689+
* masks.
690+
*
691+
* Returns 0 on success or a negative errno.
692+
*/
647693
int phylink_connect_phy(struct phylink *pl, struct phy_device *phy)
648694
{
649695
int ret;
@@ -665,6 +711,17 @@ int phylink_connect_phy(struct phylink *pl, struct phy_device *phy)
665711
}
666712
EXPORT_SYMBOL_GPL(phylink_connect_phy);
667713

714+
/**
715+
* phylink_of_phy_connect() - connect the PHY specified in the DT mode.
716+
* @pl: a pointer to a &struct phylink returned from phylink_create()
717+
* @dn: a pointer to a &struct device_node.
718+
*
719+
* Connect the phy specified in the device node @dn to the phylink instance
720+
* specified by @pl. Actions specified in phylink_connect_phy() will be
721+
* performed.
722+
*
723+
* Returns 0 on success or a negative errno.
724+
*/
668725
int phylink_of_phy_connect(struct phylink *pl, struct device_node *dn)
669726
{
670727
struct device_node *phy_node;
@@ -706,6 +763,13 @@ int phylink_of_phy_connect(struct phylink *pl, struct device_node *dn)
706763
}
707764
EXPORT_SYMBOL_GPL(phylink_of_phy_connect);
708765

766+
/**
767+
* phylink_disconnect_phy() - disconnect any PHY attached to the phylink
768+
* instance.
769+
* @pl: a pointer to a &struct phylink returned from phylink_create()
770+
*
771+
* Disconnect any current PHY from the phylink instance described by @pl.
772+
*/
709773
void phylink_disconnect_phy(struct phylink *pl)
710774
{
711775
struct phy_device *phy;
@@ -727,6 +791,14 @@ void phylink_disconnect_phy(struct phylink *pl)
727791
}
728792
EXPORT_SYMBOL_GPL(phylink_disconnect_phy);
729793

794+
/**
795+
* phylink_mac_change() - notify phylink of a change in MAC state
796+
* @pl: a pointer to a &struct phylink returned from phylink_create()
797+
* @up: indicates whether the link is currently up.
798+
*
799+
* The MAC driver should call this driver when the state of its link
800+
* changes (eg, link failure, new negotiation results, etc.)
801+
*/
730802
void phylink_mac_change(struct phylink *pl, bool up)
731803
{
732804
if (!up)
@@ -736,6 +808,14 @@ void phylink_mac_change(struct phylink *pl, bool up)
736808
}
737809
EXPORT_SYMBOL_GPL(phylink_mac_change);
738810

811+
/**
812+
* phylink_start() - start a phylink instance
813+
* @pl: a pointer to a &struct phylink returned from phylink_create()
814+
*
815+
* Start the phylink instance specified by @pl, configuring the MAC for the
816+
* desired link mode(s) and negotiation style. This should be called from the
817+
* network device driver's &struct net_device_ops ndo_open() method.
818+
*/
739819
void phylink_start(struct phylink *pl)
740820
{
741821
WARN_ON(!lockdep_rtnl_is_held());
@@ -767,6 +847,15 @@ void phylink_start(struct phylink *pl)
767847
}
768848
EXPORT_SYMBOL_GPL(phylink_start);
769849

850+
/**
851+
* phylink_stop() - stop a phylink instance
852+
* @pl: a pointer to a &struct phylink returned from phylink_create()
853+
*
854+
* Stop the phylink instance specified by @pl. This should be called from the
855+
* network device driver's &struct net_device_ops ndo_stop() method. The
856+
* network device's carrier state should not be changed prior to calling this
857+
* function.
858+
*/
770859
void phylink_stop(struct phylink *pl)
771860
{
772861
WARN_ON(!lockdep_rtnl_is_held());
@@ -782,6 +871,15 @@ void phylink_stop(struct phylink *pl)
782871
}
783872
EXPORT_SYMBOL_GPL(phylink_stop);
784873

874+
/**
875+
* phylink_ethtool_get_wol() - get the wake on lan parameters for the PHY
876+
* @pl: a pointer to a &struct phylink returned from phylink_create()
877+
* @wol: a pointer to &struct ethtool_wolinfo to hold the read parameters
878+
*
879+
* Read the wake on lan parameters from the PHY attached to the phylink
880+
* instance specified by @pl. If no PHY is currently attached, report no
881+
* support for wake on lan.
882+
*/
785883
void phylink_ethtool_get_wol(struct phylink *pl, struct ethtool_wolinfo *wol)
786884
{
787885
WARN_ON(!lockdep_rtnl_is_held());
@@ -794,6 +892,17 @@ void phylink_ethtool_get_wol(struct phylink *pl, struct ethtool_wolinfo *wol)
794892
}
795893
EXPORT_SYMBOL_GPL(phylink_ethtool_get_wol);
796894

895+
/**
896+
* phylink_ethtool_set_wol() - set wake on lan parameters
897+
* @pl: a pointer to a &struct phylink returned from phylink_create()
898+
* @wol: a pointer to &struct ethtool_wolinfo for the desired parameters
899+
*
900+
* Set the wake on lan parameters for the PHY attached to the phylink
901+
* instance specified by @pl. If no PHY is attached, returns %EOPNOTSUPP
902+
* error.
903+
*
904+
* Returns zero on success or negative errno code.
905+
*/
797906
int phylink_ethtool_set_wol(struct phylink *pl, struct ethtool_wolinfo *wol)
798907
{
799908
int ret = -EOPNOTSUPP;
@@ -829,6 +938,15 @@ static void phylink_get_ksettings(const struct phylink_link_state *state,
829938
AUTONEG_DISABLE;
830939
}
831940

941+
/**
942+
* phylink_ethtool_ksettings_get() - get the current link settings
943+
* @pl: a pointer to a &struct phylink returned from phylink_create()
944+
* @kset: a pointer to a &struct ethtool_link_ksettings to hold link settings
945+
*
946+
* Read the current link settings for the phylink instance specified by @pl.
947+
* This will be the link settings read from the MAC, PHY or fixed link
948+
* settings depending on the current negotiation mode.
949+
*/
832950
int phylink_ethtool_ksettings_get(struct phylink *pl,
833951
struct ethtool_link_ksettings *kset)
834952
{
@@ -875,6 +993,11 @@ int phylink_ethtool_ksettings_get(struct phylink *pl,
875993
}
876994
EXPORT_SYMBOL_GPL(phylink_ethtool_ksettings_get);
877995

996+
/**
997+
* phylink_ethtool_ksettings_set() - set the link settings
998+
* @pl: a pointer to a &struct phylink returned from phylink_create()
999+
* @kset: a pointer to a &struct ethtool_link_ksettings for the desired modes
1000+
*/
8781001
int phylink_ethtool_ksettings_set(struct phylink *pl,
8791002
const struct ethtool_link_ksettings *kset)
8801003
{
@@ -968,6 +1091,17 @@ int phylink_ethtool_ksettings_set(struct phylink *pl,
9681091
}
9691092
EXPORT_SYMBOL_GPL(phylink_ethtool_ksettings_set);
9701093

1094+
/**
1095+
* phylink_ethtool_nway_reset() - restart negotiation
1096+
* @pl: a pointer to a &struct phylink returned from phylink_create()
1097+
*
1098+
* Restart negotiation for the phylink instance specified by @pl. This will
1099+
* cause any attached phy to restart negotiation with the link partner, and
1100+
* if the MAC is in a BaseX mode, the MAC will also be requested to restart
1101+
* negotiation.
1102+
*
1103+
* Returns zero on success, or negative error code.
1104+
*/
9711105
int phylink_ethtool_nway_reset(struct phylink *pl)
9721106
{
9731107
int ret = 0;
@@ -982,6 +1116,11 @@ int phylink_ethtool_nway_reset(struct phylink *pl)
9821116
}
9831117
EXPORT_SYMBOL_GPL(phylink_ethtool_nway_reset);
9841118

1119+
/**
1120+
* phylink_ethtool_get_pauseparam() - get the current pause parameters
1121+
* @pl: a pointer to a &struct phylink returned from phylink_create()
1122+
* @pause: a pointer to a &struct ethtool_pauseparam
1123+
*/
9851124
void phylink_ethtool_get_pauseparam(struct phylink *pl,
9861125
struct ethtool_pauseparam *pause)
9871126
{
@@ -993,6 +1132,11 @@ void phylink_ethtool_get_pauseparam(struct phylink *pl,
9931132
}
9941133
EXPORT_SYMBOL_GPL(phylink_ethtool_get_pauseparam);
9951134

1135+
/**
1136+
* phylink_ethtool_set_pauseparam() - set the current pause parameters
1137+
* @pl: a pointer to a &struct phylink returned from phylink_create()
1138+
* @pause: a pointer to a &struct ethtool_pauseparam
1139+
*/
9961140
int phylink_ethtool_set_pauseparam(struct phylink *pl,
9971141
struct ethtool_pauseparam *pause)
9981142
{
@@ -1070,6 +1214,16 @@ int phylink_ethtool_get_module_eeprom(struct phylink *pl,
10701214
}
10711215
EXPORT_SYMBOL_GPL(phylink_ethtool_get_module_eeprom);
10721216

1217+
/**
1218+
* phylink_ethtool_get_eee_err() - read the energy efficient ethernet error
1219+
* counter
1220+
* @pl: a pointer to a &struct phylink returned from phylink_create().
1221+
*
1222+
* Read the Energy Efficient Ethernet error counter from the PHY associated
1223+
* with the phylink instance specified by @pl.
1224+
*
1225+
* Returns positive error counter value, or negative error code.
1226+
*/
10731227
int phylink_get_eee_err(struct phylink *pl)
10741228
{
10751229
int ret = 0;
@@ -1083,6 +1237,11 @@ int phylink_get_eee_err(struct phylink *pl)
10831237
}
10841238
EXPORT_SYMBOL_GPL(phylink_get_eee_err);
10851239

1240+
/**
1241+
* phylink_ethtool_get_eee() - read the energy efficient ethernet parameters
1242+
* @pl: a pointer to a &struct phylink returned from phylink_create()
1243+
* @eee: a pointer to a &struct ethtool_eee for the read parameters
1244+
*/
10861245
int phylink_ethtool_get_eee(struct phylink *pl, struct ethtool_eee *eee)
10871246
{
10881247
int ret = -EOPNOTSUPP;
@@ -1096,6 +1255,11 @@ int phylink_ethtool_get_eee(struct phylink *pl, struct ethtool_eee *eee)
10961255
}
10971256
EXPORT_SYMBOL_GPL(phylink_ethtool_get_eee);
10981257

1258+
/**
1259+
* phylink_ethtool_set_eee() - set the energy efficient ethernet parameters
1260+
* @pl: a pointer to a &struct phylink returned from phylink_create()
1261+
* @eee: a pointer to a &struct ethtool_eee for the desired parameters
1262+
*/
10991263
int phylink_ethtool_set_eee(struct phylink *pl, struct ethtool_eee *eee)
11001264
{
11011265
int ret = -EOPNOTSUPP;
@@ -1267,6 +1431,24 @@ static int phylink_mii_write(struct phylink *pl, unsigned int phy_id,
12671431
return 0;
12681432
}
12691433

1434+
/**
1435+
* phylink_mii_ioctl() - generic mii ioctl interface
1436+
* @pl: a pointer to a &struct phylink returned from phylink_create()
1437+
* @ifr: a pointer to a &struct ifreq for socket ioctls
1438+
* @cmd: ioctl cmd to execute
1439+
*
1440+
* Perform the specified MII ioctl on the PHY attached to the phylink instance
1441+
* specified by @pl. If no PHY is attached, emulate the presence of the PHY.
1442+
*
1443+
* Returns: zero on success or negative error code.
1444+
*
1445+
* %SIOCGMIIPHY:
1446+
* read register from the current PHY.
1447+
* %SIOCGMIIREG:
1448+
* read register from the specified PHY.
1449+
* %SIOCSMIIREG:
1450+
* set a register on the specified PHY.
1451+
*/
12701452
int phylink_mii_ioctl(struct phylink *pl, struct ifreq *ifr, int cmd)
12711453
{
12721454
struct mii_ioctl_data *mii = if_mii(ifr);

0 commit comments

Comments
 (0)