Skip to content

Commit 6f8b4c0

Browse files
Jiawen WuPaolo Abeni
authored andcommitted
net: txgbe: Implement PHYLINK for AML 25G/10G devices
There is a new PHY attached to AML 25G/10G NIC, which is different from SP 10G/1G NIC. But the PHY configuration is handed over to firmware, and also I2C is controlled by firmware. So the different PHYLINK fixed-link mode is added for these devices. Signed-off-by: Jiawen Wu <[email protected]> Reviewed-by: Simon Horman <[email protected]> Link: https://patch.msgid.link/[email protected] Signed-off-by: Paolo Abeni <[email protected]>
1 parent 39709fe commit 6f8b4c0

File tree

7 files changed

+195
-6
lines changed

7 files changed

+195
-6
lines changed

drivers/net/ethernet/wangxun/libwx/wx_hw.c

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2252,10 +2252,8 @@ int wx_stop_adapter(struct wx *wx)
22522252
}
22532253
EXPORT_SYMBOL(wx_stop_adapter);
22542254

2255-
void wx_reset_misc(struct wx *wx)
2255+
void wx_reset_mac(struct wx *wx)
22562256
{
2257-
int i;
2258-
22592257
/* receive packets that size > 2048 */
22602258
wr32m(wx, WX_MAC_RX_CFG, WX_MAC_RX_CFG_JE, WX_MAC_RX_CFG_JE);
22612259

@@ -2267,6 +2265,14 @@ void wx_reset_misc(struct wx *wx)
22672265
WX_MAC_RX_FLOW_CTRL_RFE, WX_MAC_RX_FLOW_CTRL_RFE);
22682266

22692267
wr32(wx, WX_MAC_PKT_FLT, WX_MAC_PKT_FLT_PR);
2268+
}
2269+
EXPORT_SYMBOL(wx_reset_mac);
2270+
2271+
void wx_reset_misc(struct wx *wx)
2272+
{
2273+
int i;
2274+
2275+
wx_reset_mac(wx);
22702276

22712277
wr32m(wx, WX_MIS_RST_ST,
22722278
WX_MIS_RST_ST_RST_INIT, 0x1E00);

drivers/net/ethernet/wangxun/libwx/wx_hw.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ void wx_configure(struct wx *wx);
4242
void wx_start_hw(struct wx *wx);
4343
int wx_disable_pcie_master(struct wx *wx);
4444
int wx_stop_adapter(struct wx *wx);
45+
void wx_reset_mac(struct wx *wx);
4546
void wx_reset_misc(struct wx *wx);
4647
int wx_get_pcie_msix_counts(struct wx *wx, u16 *msix_count, u16 max_msix_count);
4748
int wx_sw_init(struct wx *wx);

drivers/net/ethernet/wangxun/txgbe/Makefile

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,4 +11,5 @@ txgbe-objs := txgbe_main.o \
1111
txgbe_phy.o \
1212
txgbe_irq.o \
1313
txgbe_fdir.o \
14-
txgbe_ethtool.o
14+
txgbe_ethtool.o \
15+
txgbe_aml.o
Lines changed: 154 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,154 @@
1+
// SPDX-License-Identifier: GPL-2.0
2+
/* Copyright (c) 2015 - 2025 Beijing WangXun Technology Co., Ltd. */
3+
4+
#include <linux/phylink.h>
5+
#include <linux/iopoll.h>
6+
#include <linux/pci.h>
7+
#include <linux/phy.h>
8+
9+
#include "../libwx/wx_type.h"
10+
#include "../libwx/wx_lib.h"
11+
#include "../libwx/wx_hw.h"
12+
#include "txgbe_type.h"
13+
#include "txgbe_aml.h"
14+
#include "txgbe_hw.h"
15+
16+
static void txgbe_get_phy_link(struct wx *wx, int *speed)
17+
{
18+
u32 status;
19+
20+
status = rd32(wx, TXGBE_CFG_PORT_ST);
21+
if (!(status & TXGBE_CFG_PORT_ST_LINK_UP))
22+
*speed = SPEED_UNKNOWN;
23+
else if (status & TXGBE_CFG_PORT_ST_LINK_AML_25G)
24+
*speed = SPEED_25000;
25+
else if (status & TXGBE_CFG_PORT_ST_LINK_AML_10G)
26+
*speed = SPEED_10000;
27+
else
28+
*speed = SPEED_UNKNOWN;
29+
}
30+
31+
static void txgbe_get_link_state(struct phylink_config *config,
32+
struct phylink_link_state *state)
33+
{
34+
struct wx *wx = phylink_to_wx(config);
35+
int speed;
36+
37+
txgbe_get_phy_link(wx, &speed);
38+
state->link = speed != SPEED_UNKNOWN;
39+
state->speed = speed;
40+
state->duplex = state->link ? DUPLEX_FULL : DUPLEX_UNKNOWN;
41+
}
42+
43+
static void txgbe_reconfig_mac(struct wx *wx)
44+
{
45+
u32 wdg, fc;
46+
47+
wdg = rd32(wx, WX_MAC_WDG_TIMEOUT);
48+
fc = rd32(wx, WX_MAC_RX_FLOW_CTRL);
49+
50+
wr32(wx, WX_MIS_RST, TXGBE_MIS_RST_MAC_RST(wx->bus.func));
51+
/* wait for MAC reset complete */
52+
usleep_range(1000, 1500);
53+
54+
wr32m(wx, TXGBE_MAC_MISC_CTL, TXGBE_MAC_MISC_CTL_LINK_STS_MOD,
55+
TXGBE_MAC_MISC_CTL_LINK_BOTH);
56+
wx_reset_mac(wx);
57+
58+
wr32(wx, WX_MAC_WDG_TIMEOUT, wdg);
59+
wr32(wx, WX_MAC_RX_FLOW_CTRL, fc);
60+
}
61+
62+
static void txgbe_mac_link_up_aml(struct phylink_config *config,
63+
struct phy_device *phy,
64+
unsigned int mode,
65+
phy_interface_t interface,
66+
int speed, int duplex,
67+
bool tx_pause, bool rx_pause)
68+
{
69+
struct wx *wx = phylink_to_wx(config);
70+
u32 txcfg;
71+
72+
wx_fc_enable(wx, tx_pause, rx_pause);
73+
74+
txgbe_reconfig_mac(wx);
75+
76+
txcfg = rd32(wx, TXGBE_AML_MAC_TX_CFG);
77+
txcfg &= ~TXGBE_AML_MAC_TX_CFG_SPEED_MASK;
78+
79+
switch (speed) {
80+
case SPEED_25000:
81+
txcfg |= TXGBE_AML_MAC_TX_CFG_SPEED_25G;
82+
break;
83+
case SPEED_10000:
84+
txcfg |= TXGBE_AML_MAC_TX_CFG_SPEED_10G;
85+
break;
86+
default:
87+
break;
88+
}
89+
90+
wr32m(wx, WX_MAC_RX_CFG, WX_MAC_RX_CFG_RE, WX_MAC_RX_CFG_RE);
91+
wr32(wx, TXGBE_AML_MAC_TX_CFG, txcfg | TXGBE_AML_MAC_TX_CFG_TE);
92+
93+
wx->speed = speed;
94+
}
95+
96+
static void txgbe_mac_link_down_aml(struct phylink_config *config,
97+
unsigned int mode,
98+
phy_interface_t interface)
99+
{
100+
struct wx *wx = phylink_to_wx(config);
101+
102+
wr32m(wx, TXGBE_AML_MAC_TX_CFG, TXGBE_AML_MAC_TX_CFG_TE, 0);
103+
wr32m(wx, WX_MAC_RX_CFG, WX_MAC_RX_CFG_RE, 0);
104+
105+
wx->speed = SPEED_UNKNOWN;
106+
}
107+
108+
static void txgbe_mac_config_aml(struct phylink_config *config, unsigned int mode,
109+
const struct phylink_link_state *state)
110+
{
111+
}
112+
113+
static const struct phylink_mac_ops txgbe_mac_ops_aml = {
114+
.mac_config = txgbe_mac_config_aml,
115+
.mac_link_down = txgbe_mac_link_down_aml,
116+
.mac_link_up = txgbe_mac_link_up_aml,
117+
};
118+
119+
int txgbe_phylink_init_aml(struct txgbe *txgbe)
120+
{
121+
struct phylink_link_state state;
122+
struct phylink_config *config;
123+
struct wx *wx = txgbe->wx;
124+
phy_interface_t phy_mode;
125+
struct phylink *phylink;
126+
int err;
127+
128+
config = &wx->phylink_config;
129+
config->dev = &wx->netdev->dev;
130+
config->type = PHYLINK_NETDEV;
131+
config->mac_capabilities = MAC_25000FD | MAC_10000FD |
132+
MAC_SYM_PAUSE | MAC_ASYM_PAUSE;
133+
config->get_fixed_state = txgbe_get_link_state;
134+
135+
phy_mode = PHY_INTERFACE_MODE_25GBASER;
136+
__set_bit(PHY_INTERFACE_MODE_25GBASER, config->supported_interfaces);
137+
__set_bit(PHY_INTERFACE_MODE_10GBASER, config->supported_interfaces);
138+
139+
phylink = phylink_create(config, NULL, phy_mode, &txgbe_mac_ops_aml);
140+
if (IS_ERR(phylink))
141+
return PTR_ERR(phylink);
142+
143+
state.speed = SPEED_25000;
144+
state.duplex = DUPLEX_FULL;
145+
err = phylink_set_fixed_link(phylink, &state);
146+
if (err) {
147+
wx_err(wx, "Failed to set fixed link\n");
148+
return err;
149+
}
150+
151+
wx->phylink = phylink;
152+
153+
return 0;
154+
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
/* SPDX-License-Identifier: GPL-2.0 */
2+
/* Copyright (c) 2015 - 2025 Beijing WangXun Technology Co., Ltd. */
3+
4+
#ifndef _TXGBE_AML_H_
5+
#define _TXGBE_AML_H_
6+
7+
int txgbe_phylink_init_aml(struct txgbe *txgbe);
8+
9+
#endif /* _TXGBE_AML_H_ */

drivers/net/ethernet/wangxun/txgbe/txgbe_phy.c

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
#include "../libwx/wx_mbx.h"
2121
#include "../libwx/wx_hw.h"
2222
#include "txgbe_type.h"
23+
#include "txgbe_aml.h"
2324
#include "txgbe_phy.h"
2425
#include "txgbe_hw.h"
2526

@@ -318,7 +319,10 @@ irqreturn_t txgbe_link_irq_handler(int irq, void *data)
318319
status = rd32(wx, TXGBE_CFG_PORT_ST);
319320
up = !!(status & TXGBE_CFG_PORT_ST_LINK_UP);
320321

321-
phylink_pcs_change(txgbe->pcs, up);
322+
if (txgbe->pcs)
323+
phylink_pcs_change(txgbe->pcs, up);
324+
else
325+
phylink_mac_change(wx->phylink, up);
322326

323327
return IRQ_HANDLED;
324328
}
@@ -575,8 +579,9 @@ int txgbe_init_phy(struct txgbe *txgbe)
575579

576580
switch (wx->mac.type) {
577581
case wx_mac_aml40:
578-
case wx_mac_aml:
579582
return 0;
583+
case wx_mac_aml:
584+
return txgbe_phylink_init_aml(txgbe);
580585
case wx_mac_sp:
581586
if (wx->media_type == wx_media_copper)
582587
return txgbe_ext_phy_init(txgbe);
@@ -648,7 +653,9 @@ void txgbe_remove_phy(struct txgbe *txgbe)
648653
{
649654
switch (txgbe->wx->mac.type) {
650655
case wx_mac_aml40:
656+
return;
651657
case wx_mac_aml:
658+
phylink_destroy(txgbe->wx->phylink);
652659
return;
653660
case wx_mac_sp:
654661
if (txgbe->wx->media_type == wx_media_copper) {

drivers/net/ethernet/wangxun/txgbe/txgbe_type.h

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,8 @@
5050

5151
/**************** SP Registers ****************************/
5252
/* chip control Registers */
53+
#define TXGBE_MIS_RST 0x1000C
54+
#define TXGBE_MIS_RST_MAC_RST(_i) BIT(20 - (_i) * 3)
5355
#define TXGBE_MIS_PRB_CTL 0x10010
5456
#define TXGBE_MIS_PRB_CTL_LAN_UP(_i) BIT(1 - (_i))
5557
/* FMGR Registers */
@@ -62,6 +64,11 @@
6264
#define TXGBE_TS_CTL 0x10300
6365
#define TXGBE_TS_CTL_EVAL_MD BIT(31)
6466

67+
/* MAC Misc Registers */
68+
#define TXGBE_MAC_MISC_CTL 0x11F00
69+
#define TXGBE_MAC_MISC_CTL_LINK_STS_MOD BIT(0)
70+
#define TXGBE_MAC_MISC_CTL_LINK_PCS FIELD_PREP(BIT(0), 0)
71+
#define TXGBE_MAC_MISC_CTL_LINK_BOTH FIELD_PREP(BIT(0), 1)
6572
/* GPIO register bit */
6673
#define TXGBE_GPIOBIT_0 BIT(0) /* I:tx fault */
6774
#define TXGBE_GPIOBIT_1 BIT(1) /* O:tx disabled */
@@ -88,6 +95,8 @@
8895
/* Port cfg registers */
8996
#define TXGBE_CFG_PORT_ST 0x14404
9097
#define TXGBE_CFG_PORT_ST_LINK_UP BIT(0)
98+
#define TXGBE_CFG_PORT_ST_LINK_AML_25G BIT(3)
99+
#define TXGBE_CFG_PORT_ST_LINK_AML_10G BIT(4)
91100
#define TXGBE_CFG_VXLAN 0x14410
92101
#define TXGBE_CFG_VXLAN_GPE 0x14414
93102
#define TXGBE_CFG_GENEVE 0x14418
@@ -151,9 +160,11 @@
151160
/*************************** Amber Lite Registers ****************************/
152161
#define TXGBE_PX_PF_BME 0x4B8
153162
#define TXGBE_AML_MAC_TX_CFG 0x11000
163+
#define TXGBE_AML_MAC_TX_CFG_TE BIT(0)
154164
#define TXGBE_AML_MAC_TX_CFG_SPEED_MASK GENMASK(30, 27)
155165
#define TXGBE_AML_MAC_TX_CFG_SPEED_40G FIELD_PREP(GENMASK(30, 27), 0)
156166
#define TXGBE_AML_MAC_TX_CFG_SPEED_25G FIELD_PREP(GENMASK(30, 27), 2)
167+
#define TXGBE_AML_MAC_TX_CFG_SPEED_10G FIELD_PREP(GENMASK(30, 27), 8)
157168
#define TXGBE_RDM_RSC_CTL 0x1200C
158169
#define TXGBE_RDM_RSC_CTL_FREE_CTL BIT(7)
159170

0 commit comments

Comments
 (0)