Skip to content

Commit

Permalink
net: txgbe: use phylink bits added in libwx
Browse files Browse the repository at this point in the history
Convert txgbe to use phylink and phylink_config added in libwx.

Signed-off-by: Jiawen Wu <jiawenwu@trustnetic.com>
Reviewed-by: Russell King (Oracle) <rmk+kernel@armlinux.org.uk>
Signed-off-by: David S. Miller <davem@davemloft.net>
  • Loading branch information
Jiawen Wu authored and David S. Miller committed Jan 4, 2024
1 parent e8e138c commit 4491c60
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 62 deletions.
29 changes: 3 additions & 26 deletions drivers/net/ethernet/wangxun/txgbe/txgbe_ethtool.c
Original file line number Diff line number Diff line change
Expand Up @@ -10,35 +10,12 @@
#include "txgbe_type.h"
#include "txgbe_ethtool.h"

static int txgbe_nway_reset(struct net_device *netdev)
{
struct txgbe *txgbe = netdev_to_txgbe(netdev);

return phylink_ethtool_nway_reset(txgbe->phylink);
}

static int txgbe_get_link_ksettings(struct net_device *netdev,
struct ethtool_link_ksettings *cmd)
{
struct txgbe *txgbe = netdev_to_txgbe(netdev);

return phylink_ethtool_ksettings_get(txgbe->phylink, cmd);
}

static int txgbe_set_link_ksettings(struct net_device *netdev,
const struct ethtool_link_ksettings *cmd)
{
struct txgbe *txgbe = netdev_to_txgbe(netdev);

return phylink_ethtool_ksettings_set(txgbe->phylink, cmd);
}

static const struct ethtool_ops txgbe_ethtool_ops = {
.get_drvinfo = wx_get_drvinfo,
.nway_reset = txgbe_nway_reset,
.nway_reset = wx_nway_reset,
.get_link = ethtool_op_get_link,
.get_link_ksettings = txgbe_get_link_ksettings,
.set_link_ksettings = txgbe_set_link_ksettings,
.get_link_ksettings = wx_get_link_ksettings,
.set_link_ksettings = wx_set_link_ksettings,
.get_sset_count = wx_get_sset_count,
.get_strings = wx_get_strings,
.get_ethtool_stats = wx_get_ethtool_stats,
Expand Down
8 changes: 2 additions & 6 deletions drivers/net/ethernet/wangxun/txgbe/txgbe_main.c
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,6 @@ static int txgbe_request_irq(struct wx *wx)
static void txgbe_up_complete(struct wx *wx)
{
struct net_device *netdev = wx->netdev;
struct txgbe *txgbe;

wx_control_hw(wx, true);
wx_configure_vectors(wx);
Expand All @@ -215,8 +214,7 @@ static void txgbe_up_complete(struct wx *wx)
smp_mb__before_atomic();
wx_napi_enable_all(wx);

txgbe = netdev_to_txgbe(netdev);
phylink_start(txgbe->phylink);
phylink_start(wx->phylink);

/* clear any pending interrupts, may auto mask */
rd32(wx, WX_PX_IC(0));
Expand Down Expand Up @@ -292,11 +290,9 @@ static void txgbe_disable_device(struct wx *wx)

static void txgbe_down(struct wx *wx)
{
struct txgbe *txgbe = netdev_to_txgbe(wx->netdev);

txgbe_disable_device(wx);
txgbe_reset(wx);
phylink_stop(txgbe->phylink);
phylink_stop(wx->phylink);

wx_clean_all_tx_rings(wx);
wx_clean_all_rx_rings(wx);
Expand Down
43 changes: 21 additions & 22 deletions drivers/net/ethernet/wangxun/txgbe/txgbe_phy.c
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,8 @@ static int txgbe_mdio_pcs_init(struct txgbe *txgbe)
static struct phylink_pcs *txgbe_phylink_mac_select(struct phylink_config *config,
phy_interface_t interface)
{
struct txgbe *txgbe = netdev_to_txgbe(to_net_dev(config->dev));
struct wx *wx = phylink_to_wx(config);
struct txgbe *txgbe = wx->priv;

if (interface == PHY_INTERFACE_MODE_10GBASER)
return &txgbe->xpcs->pcs;
Expand All @@ -175,7 +176,7 @@ static void txgbe_mac_config(struct phylink_config *config, unsigned int mode,
static void txgbe_mac_link_down(struct phylink_config *config,
unsigned int mode, phy_interface_t interface)
{
struct wx *wx = netdev_priv(to_net_dev(config->dev));
struct wx *wx = phylink_to_wx(config);

wr32m(wx, WX_MAC_TX_CFG, WX_MAC_TX_CFG_TE, 0);
}
Expand All @@ -186,7 +187,7 @@ static void txgbe_mac_link_up(struct phylink_config *config,
int speed, int duplex,
bool tx_pause, bool rx_pause)
{
struct wx *wx = netdev_priv(to_net_dev(config->dev));
struct wx *wx = phylink_to_wx(config);
u32 txcfg, wdg;

txcfg = rd32(wx, WX_MAC_TX_CFG);
Expand Down Expand Up @@ -217,7 +218,7 @@ static void txgbe_mac_link_up(struct phylink_config *config,
static int txgbe_mac_prepare(struct phylink_config *config, unsigned int mode,
phy_interface_t interface)
{
struct wx *wx = netdev_priv(to_net_dev(config->dev));
struct wx *wx = phylink_to_wx(config);

wr32m(wx, WX_MAC_TX_CFG, WX_MAC_TX_CFG_TE, 0);
wr32m(wx, WX_MAC_RX_CFG, WX_MAC_RX_CFG_RE, 0);
Expand All @@ -228,7 +229,7 @@ static int txgbe_mac_prepare(struct phylink_config *config, unsigned int mode,
static int txgbe_mac_finish(struct phylink_config *config, unsigned int mode,
phy_interface_t interface)
{
struct wx *wx = netdev_priv(to_net_dev(config->dev));
struct wx *wx = phylink_to_wx(config);

txgbe_enable_sec_tx_path(wx);
wr32m(wx, WX_MAC_RX_CFG, WX_MAC_RX_CFG_RE, WX_MAC_RX_CFG_RE);
Expand All @@ -253,10 +254,7 @@ static int txgbe_phylink_init(struct txgbe *txgbe)
phy_interface_t phy_mode;
struct phylink *phylink;

config = devm_kzalloc(&wx->pdev->dev, sizeof(*config), GFP_KERNEL);
if (!config)
return -ENOMEM;

config = &wx->phylink_config;
config->dev = &wx->netdev->dev;
config->type = PHYLINK_NETDEV;
config->mac_capabilities = MAC_10000FD | MAC_1000FD | MAC_100FD |
Expand Down Expand Up @@ -287,7 +285,7 @@ static int txgbe_phylink_init(struct txgbe *txgbe)
}
}

txgbe->phylink = phylink;
wx->phylink = phylink;

return 0;
}
Expand Down Expand Up @@ -483,7 +481,7 @@ static void txgbe_irq_handler(struct irq_desc *desc)
TXGBE_PX_MISC_ETH_AN)) {
u32 reg = rd32(wx, TXGBE_CFG_PORT_ST);

phylink_mac_change(txgbe->phylink, !!(reg & TXGBE_CFG_PORT_ST_LINK_UP));
phylink_mac_change(wx->phylink, !!(reg & TXGBE_CFG_PORT_ST_LINK_UP));
}

/* unmask interrupt */
Expand Down Expand Up @@ -701,50 +699,51 @@ static int txgbe_ext_phy_init(struct txgbe *txgbe)

int txgbe_init_phy(struct txgbe *txgbe)
{
struct wx *wx = txgbe->wx;
int ret;

if (txgbe->wx->media_type == sp_media_copper)
return txgbe_ext_phy_init(txgbe);

ret = txgbe_swnodes_register(txgbe);
if (ret) {
wx_err(txgbe->wx, "failed to register software nodes\n");
wx_err(wx, "failed to register software nodes\n");
return ret;
}

ret = txgbe_mdio_pcs_init(txgbe);
if (ret) {
wx_err(txgbe->wx, "failed to init mdio pcs: %d\n", ret);
wx_err(wx, "failed to init mdio pcs: %d\n", ret);
goto err_unregister_swnode;
}

ret = txgbe_phylink_init(txgbe);
if (ret) {
wx_err(txgbe->wx, "failed to init phylink\n");
wx_err(wx, "failed to init phylink\n");
goto err_destroy_xpcs;
}

ret = txgbe_gpio_init(txgbe);
if (ret) {
wx_err(txgbe->wx, "failed to init gpio\n");
wx_err(wx, "failed to init gpio\n");
goto err_destroy_phylink;
}

ret = txgbe_clock_register(txgbe);
if (ret) {
wx_err(txgbe->wx, "failed to register clock: %d\n", ret);
wx_err(wx, "failed to register clock: %d\n", ret);
goto err_destroy_phylink;
}

ret = txgbe_i2c_register(txgbe);
if (ret) {
wx_err(txgbe->wx, "failed to init i2c interface: %d\n", ret);
wx_err(wx, "failed to init i2c interface: %d\n", ret);
goto err_unregister_clk;
}

ret = txgbe_sfp_register(txgbe);
if (ret) {
wx_err(txgbe->wx, "failed to register sfp\n");
wx_err(wx, "failed to register sfp\n");
goto err_unregister_i2c;
}

Expand All @@ -756,7 +755,7 @@ int txgbe_init_phy(struct txgbe *txgbe)
clkdev_drop(txgbe->clock);
clk_unregister(txgbe->clk);
err_destroy_phylink:
phylink_destroy(txgbe->phylink);
phylink_destroy(wx->phylink);
err_destroy_xpcs:
xpcs_destroy(txgbe->xpcs);
err_unregister_swnode:
Expand All @@ -768,16 +767,16 @@ int txgbe_init_phy(struct txgbe *txgbe)
void txgbe_remove_phy(struct txgbe *txgbe)
{
if (txgbe->wx->media_type == sp_media_copper) {
phylink_disconnect_phy(txgbe->phylink);
phylink_destroy(txgbe->phylink);
phylink_disconnect_phy(txgbe->wx->phylink);
phylink_destroy(txgbe->wx->phylink);
return;
}

platform_device_unregister(txgbe->sfp_dev);
platform_device_unregister(txgbe->i2c_dev);
clkdev_drop(txgbe->clock);
clk_unregister(txgbe->clk);
phylink_destroy(txgbe->phylink);
phylink_destroy(txgbe->wx->phylink);
xpcs_destroy(txgbe->xpcs);
software_node_unregister_node_group(txgbe->nodes.group);
}
8 changes: 0 additions & 8 deletions drivers/net/ethernet/wangxun/txgbe/txgbe_type.h
Original file line number Diff line number Diff line change
Expand Up @@ -129,13 +129,6 @@

extern char txgbe_driver_name[];

static inline struct txgbe *netdev_to_txgbe(struct net_device *netdev)
{
struct wx *wx = netdev_priv(netdev);

return wx->priv;
}

#define NODE_PROP(_NAME, _PROP) \
(const struct software_node) { \
.name = _NAME, \
Expand Down Expand Up @@ -175,7 +168,6 @@ struct txgbe {
struct wx *wx;
struct txgbe_nodes nodes;
struct dw_xpcs *xpcs;
struct phylink *phylink;
struct platform_device *sfp_dev;
struct platform_device *i2c_dev;
struct clk_lookup *clock;
Expand Down

0 comments on commit 4491c60

Please sign in to comment.