Skip to content

Commit

Permalink
net: ngbe: Add ngbe mdio bus driver.
Browse files Browse the repository at this point in the history
Add mdio bus register for ngbe.
The internal phy and external phy need to be handled separately.
Add phy changed event detection.

Signed-off-by: Mengyuan Lou <mengyuanlou@net-swift.com>
Reviewed-by: Andrew Lunn <andrew@lunn.ch>
Link: https://lore.kernel.org/r/20230111111718.40745-1-mengyuanlou@net-swift.com
Signed-off-by: Jakub Kicinski <kuba@kernel.org>
  • Loading branch information
Mengyuan Lou authored and Jakub Kicinski committed Jan 13, 2023
1 parent 296403f commit a1cf597
Show file tree
Hide file tree
Showing 9 changed files with 397 additions and 14 deletions.
1 change: 1 addition & 0 deletions drivers/net/ethernet/wangxun/Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ config NGBE
tristate "Wangxun(R) GbE PCI Express adapters support"
depends on PCI
select LIBWX
select PHYLIB
help
This driver supports Wangxun(R) GbE PCI Express family of
adapters.
Expand Down
9 changes: 9 additions & 0 deletions drivers/net/ethernet/wangxun/libwx/wx_type.h
Original file line number Diff line number Diff line change
Expand Up @@ -133,11 +133,14 @@
/************************************* ETH MAC *****************************/
#define WX_MAC_TX_CFG 0x11000
#define WX_MAC_TX_CFG_TE BIT(0)
#define WX_MAC_TX_CFG_SPEED_MASK GENMASK(30, 29)
#define WX_MAC_TX_CFG_SPEED_1G (0x3 << 29)
#define WX_MAC_RX_CFG 0x11004
#define WX_MAC_RX_CFG_RE BIT(0)
#define WX_MAC_RX_CFG_JE BIT(8)
#define WX_MAC_PKT_FLT 0x11008
#define WX_MAC_PKT_FLT_PR BIT(0) /* promiscuous mode */
#define WX_MAC_WDG_TIMEOUT 0x1100C
#define WX_MAC_RX_FLOW_CTRL 0x11090
#define WX_MAC_RX_FLOW_CTRL_RFE BIT(0) /* receive fc enable */
#define WX_MMC_CONTROL 0x11800
Expand Down Expand Up @@ -330,6 +333,12 @@ struct wx {
char eeprom_id[32];
enum wx_reset_type reset_type;

/* PHY stuff */
unsigned int link;
int speed;
int duplex;
struct phy_device *phydev;

bool wol_enabled;
bool ncsi_enabled;
bool gpio_ctrl;
Expand Down
2 changes: 1 addition & 1 deletion drivers/net/ethernet/wangxun/ngbe/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,4 @@

obj-$(CONFIG_NGBE) += ngbe.o

ngbe-objs := ngbe_main.o ngbe_hw.o
ngbe-objs := ngbe_main.o ngbe_hw.o ngbe_mdio.o
39 changes: 29 additions & 10 deletions drivers/net/ethernet/wangxun/ngbe/ngbe_hw.c
Original file line number Diff line number Diff line change
Expand Up @@ -39,16 +39,24 @@ int ngbe_eeprom_chksum_hostif(struct wx *wx)
static int ngbe_reset_misc(struct wx *wx)
{
wx_reset_misc(wx);
if (wx->mac_type == em_mac_type_rgmii)
wr32(wx, NGBE_MDIO_CLAUSE_SELECT, 0xF);
if (wx->gpio_ctrl) {
/* gpio0 is used to power on/off control*/
wr32(wx, NGBE_GPIO_DDR, 0x1);
wr32(wx, NGBE_GPIO_DR, NGBE_GPIO_DR_0);
ngbe_sfp_modules_txrx_powerctl(wx, false);
}
return 0;
}

void ngbe_sfp_modules_txrx_powerctl(struct wx *wx, bool swi)
{
if (swi)
/* gpio0 is used to power on control*/
wr32(wx, NGBE_GPIO_DR, 0);
else
/* gpio0 is used to power off control*/
wr32(wx, NGBE_GPIO_DR, NGBE_GPIO_DR_0);
}

/**
* ngbe_reset_hw - Perform hardware reset
* @wx: pointer to hardware structure
Expand All @@ -59,15 +67,26 @@ static int ngbe_reset_misc(struct wx *wx)
**/
int ngbe_reset_hw(struct wx *wx)
{
int status = 0;
u32 reset = 0;
u32 val = 0;
int ret = 0;

/* Call wx stop to disable tx/rx and clear interrupts */
status = wx_stop_adapter(wx);
if (status != 0)
return status;
reset = WX_MIS_RST_LAN_RST(wx->bus.func);
wr32(wx, WX_MIS_RST, reset | rd32(wx, WX_MIS_RST));
ret = wx_stop_adapter(wx);
if (ret != 0)
return ret;

if (wx->mac_type != em_mac_type_mdi) {
val = WX_MIS_RST_LAN_RST(wx->bus.func);
wr32(wx, WX_MIS_RST, val | rd32(wx, WX_MIS_RST));

ret = read_poll_timeout(rd32, val,
!(val & (BIT(9) << wx->bus.func)), 1000,
100000, false, wx, 0x10028);
if (ret) {
wx_err(wx, "Lan reset exceed s maximum times.\n");
return ret;
}
}
ngbe_reset_misc(wx);

/* Store the permanent mac address */
Expand Down
1 change: 1 addition & 0 deletions drivers/net/ethernet/wangxun/ngbe/ngbe_hw.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,6 @@
#define _NGBE_HW_H_

int ngbe_eeprom_chksum_hostif(struct wx *wx);
void ngbe_sfp_modules_txrx_powerctl(struct wx *wx, bool swi);
int ngbe_reset_hw(struct wx *wx);
#endif /* _NGBE_HW_H_ */
37 changes: 34 additions & 3 deletions drivers/net/ethernet/wangxun/ngbe/ngbe_main.c
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,12 @@
#include <linux/aer.h>
#include <linux/etherdevice.h>
#include <net/ip.h>
#include <linux/phy.h>

#include "../libwx/wx_type.h"
#include "../libwx/wx_hw.h"
#include "ngbe_type.h"
#include "ngbe_mdio.h"
#include "ngbe_hw.h"

char ngbe_driver_name[] = "ngbe";
Expand Down Expand Up @@ -146,11 +148,29 @@ static int ngbe_sw_init(struct wx *wx)
return 0;
}

static void ngbe_disable_device(struct wx *wx)
{
struct net_device *netdev = wx->netdev;

/* disable receives */
wx_disable_rx(wx);
netif_tx_disable(netdev);
if (wx->gpio_ctrl)
ngbe_sfp_modules_txrx_powerctl(wx, false);
}

static void ngbe_down(struct wx *wx)
{
netif_carrier_off(wx->netdev);
netif_tx_disable(wx->netdev);
};
phy_stop(wx->phydev);
ngbe_disable_device(wx);
}

static void ngbe_up(struct wx *wx)
{
if (wx->gpio_ctrl)
ngbe_sfp_modules_txrx_powerctl(wx, true);
phy_start(wx->phydev);
}

/**
* ngbe_open - Called when a network interface is made active
Expand All @@ -164,8 +184,13 @@ static void ngbe_down(struct wx *wx)
static int ngbe_open(struct net_device *netdev)
{
struct wx *wx = netdev_priv(netdev);
int err;

wx_control_hw(wx, true);
err = ngbe_phy_connect(wx);
if (err)
return err;
ngbe_up(wx);

return 0;
}
Expand All @@ -186,6 +211,7 @@ static int ngbe_close(struct net_device *netdev)
struct wx *wx = netdev_priv(netdev);

ngbe_down(wx);
phy_disconnect(wx->phydev);
wx_control_hw(wx, false);

return 0;
Expand Down Expand Up @@ -385,6 +411,11 @@ static int ngbe_probe(struct pci_dev *pdev,
eth_hw_addr_set(netdev, wx->mac.perm_addr);
wx_mac_set_default_filter(wx, wx->mac.perm_addr);

/* phy Interface Configuration */
err = ngbe_mdio_init(wx);
if (err)
goto err_free_mac_table;

err = register_netdev(netdev);
if (err)
goto err_register;
Expand Down
Loading

0 comments on commit a1cf597

Please sign in to comment.