Commit a1cf597b authored by Mengyuan Lou's avatar Mengyuan Lou Committed by Jakub Kicinski
Browse files

net: ngbe: Add ngbe mdio bus driver.



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: default avatarMengyuan Lou <mengyuanlou@net-swift.com>
Reviewed-by: default avatarAndrew Lunn <andrew@lunn.ch>
Link: https://lore.kernel.org/r/20230111111718.40745-1-mengyuanlou@net-swift.com


Signed-off-by: default avatarJakub Kicinski <kuba@kernel.org>
parent 296403f9
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -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.
+9 −0
Original line number Diff line number Diff line
@@ -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
@@ -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;
+1 −1
Original line number Diff line number Diff line
@@ -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
+29 −10
Original line number Diff line number Diff line
@@ -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
@@ -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 */
+1 −0
Original line number Diff line number Diff line
@@ -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_ */
Loading