0001
0002
0003 #include <linux/module.h>
0004 #include <linux/phylink.h>
0005 #include <linux/device.h>
0006 #include <linux/netdevice.h>
0007 #include <linux/phy/phy.h>
0008 #include <linux/sfp.h>
0009
0010 #include "lan966x_main.h"
0011
0012 static struct phylink_pcs *lan966x_phylink_mac_select(struct phylink_config *config,
0013 phy_interface_t interface)
0014 {
0015 struct lan966x_port *port = netdev_priv(to_net_dev(config->dev));
0016
0017 return &port->phylink_pcs;
0018 }
0019
0020 static void lan966x_phylink_mac_config(struct phylink_config *config,
0021 unsigned int mode,
0022 const struct phylink_link_state *state)
0023 {
0024 }
0025
0026 static int lan966x_phylink_mac_prepare(struct phylink_config *config,
0027 unsigned int mode,
0028 phy_interface_t iface)
0029 {
0030 struct lan966x_port *port = netdev_priv(to_net_dev(config->dev));
0031 int err;
0032
0033 if (port->serdes) {
0034 err = phy_set_mode_ext(port->serdes, PHY_MODE_ETHERNET,
0035 iface);
0036 if (err) {
0037 netdev_err(to_net_dev(config->dev),
0038 "Could not set mode of SerDes\n");
0039 return err;
0040 }
0041 }
0042
0043 return 0;
0044 }
0045
0046 static void lan966x_phylink_mac_link_up(struct phylink_config *config,
0047 struct phy_device *phy,
0048 unsigned int mode,
0049 phy_interface_t interface,
0050 int speed, int duplex,
0051 bool tx_pause, bool rx_pause)
0052 {
0053 struct lan966x_port *port = netdev_priv(to_net_dev(config->dev));
0054 struct lan966x_port_config *port_config = &port->config;
0055
0056 port_config->duplex = duplex;
0057 port_config->speed = speed;
0058 port_config->pause = 0;
0059 port_config->pause |= tx_pause ? MLO_PAUSE_TX : 0;
0060 port_config->pause |= rx_pause ? MLO_PAUSE_RX : 0;
0061
0062 lan966x_port_config_up(port);
0063 }
0064
0065 static void lan966x_phylink_mac_link_down(struct phylink_config *config,
0066 unsigned int mode,
0067 phy_interface_t interface)
0068 {
0069 struct lan966x_port *port = netdev_priv(to_net_dev(config->dev));
0070 struct lan966x *lan966x = port->lan966x;
0071
0072 lan966x_port_config_down(port);
0073
0074
0075 lan_rmw(DEV_CLOCK_CFG_PCS_RX_RST_SET(0) |
0076 DEV_CLOCK_CFG_PCS_TX_RST_SET(0),
0077 DEV_CLOCK_CFG_PCS_RX_RST |
0078 DEV_CLOCK_CFG_PCS_TX_RST,
0079 lan966x, DEV_CLOCK_CFG(port->chip_port));
0080 }
0081
0082 static struct lan966x_port *lan966x_pcs_to_port(struct phylink_pcs *pcs)
0083 {
0084 return container_of(pcs, struct lan966x_port, phylink_pcs);
0085 }
0086
0087 static void lan966x_pcs_get_state(struct phylink_pcs *pcs,
0088 struct phylink_link_state *state)
0089 {
0090 struct lan966x_port *port = lan966x_pcs_to_port(pcs);
0091
0092 lan966x_port_status_get(port, state);
0093 }
0094
0095 static int lan966x_pcs_config(struct phylink_pcs *pcs,
0096 unsigned int mode,
0097 phy_interface_t interface,
0098 const unsigned long *advertising,
0099 bool permit_pause_to_mac)
0100 {
0101 struct lan966x_port *port = lan966x_pcs_to_port(pcs);
0102 struct lan966x_port_config config;
0103 int ret;
0104
0105 config = port->config;
0106 config.portmode = interface;
0107 config.inband = phylink_autoneg_inband(mode);
0108 config.autoneg = phylink_test(advertising, Autoneg);
0109 config.advertising = advertising;
0110
0111 ret = lan966x_port_pcs_set(port, &config);
0112 if (ret)
0113 netdev_err(port->dev, "port PCS config failed: %d\n", ret);
0114
0115 return ret;
0116 }
0117
0118 static void lan966x_pcs_aneg_restart(struct phylink_pcs *pcs)
0119 {
0120
0121 }
0122
0123 const struct phylink_mac_ops lan966x_phylink_mac_ops = {
0124 .validate = phylink_generic_validate,
0125 .mac_select_pcs = lan966x_phylink_mac_select,
0126 .mac_config = lan966x_phylink_mac_config,
0127 .mac_prepare = lan966x_phylink_mac_prepare,
0128 .mac_link_down = lan966x_phylink_mac_link_down,
0129 .mac_link_up = lan966x_phylink_mac_link_up,
0130 };
0131
0132 const struct phylink_pcs_ops lan966x_phylink_pcs_ops = {
0133 .pcs_get_state = lan966x_pcs_get_state,
0134 .pcs_config = lan966x_pcs_config,
0135 .pcs_an_restart = lan966x_pcs_aneg_restart,
0136 };