Skip to content

Commit 182af02

Browse files
Jiawen WuPaolo Abeni
authored andcommitted
net: txgbe: Implement PTP for AML devices
Support PTP clock and 1PPS output signal for AML devices. Signed-off-by: Jiawen Wu <[email protected]> Link: https://patch.msgid.link/[email protected] Signed-off-by: Paolo Abeni <[email protected]>
1 parent d84a3ff commit 182af02

File tree

4 files changed

+39
-5
lines changed

4 files changed

+39
-5
lines changed

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

Lines changed: 26 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,14 @@
1515
#define WX_INCVAL_100 0xA00000
1616
#define WX_INCVAL_10 0xC7F380
1717
#define WX_INCVAL_EM 0x2000000
18+
#define WX_INCVAL_AML 0xA00000
1819

1920
#define WX_INCVAL_SHIFT_10GB 20
2021
#define WX_INCVAL_SHIFT_1GB 18
2122
#define WX_INCVAL_SHIFT_100 15
2223
#define WX_INCVAL_SHIFT_10 12
2324
#define WX_INCVAL_SHIFT_EM 22
25+
#define WX_INCVAL_SHIFT_AML 21
2426

2527
#define WX_OVERFLOW_PERIOD (HZ * 30)
2628
#define WX_PTP_TX_TIMEOUT (HZ)
@@ -504,15 +506,27 @@ static long wx_ptp_create_clock(struct wx *wx)
504506
wx->ptp_caps.gettimex64 = wx_ptp_gettimex64;
505507
wx->ptp_caps.settime64 = wx_ptp_settime64;
506508
wx->ptp_caps.do_aux_work = wx_ptp_do_aux_work;
507-
if (wx->mac.type == wx_mac_em) {
508-
wx->ptp_caps.max_adj = 500000000;
509+
switch (wx->mac.type) {
510+
case wx_mac_aml:
511+
case wx_mac_aml40:
512+
wx->ptp_caps.max_adj = 250000000;
509513
wx->ptp_caps.n_per_out = 1;
510514
wx->ptp_setup_sdp = wx_ptp_setup_sdp;
511515
wx->ptp_caps.enable = wx_ptp_feature_enable;
512-
} else {
516+
break;
517+
case wx_mac_sp:
513518
wx->ptp_caps.max_adj = 250000000;
514519
wx->ptp_caps.n_per_out = 0;
515520
wx->ptp_setup_sdp = NULL;
521+
break;
522+
case wx_mac_em:
523+
wx->ptp_caps.max_adj = 500000000;
524+
wx->ptp_caps.n_per_out = 1;
525+
wx->ptp_setup_sdp = wx_ptp_setup_sdp;
526+
wx->ptp_caps.enable = wx_ptp_feature_enable;
527+
break;
528+
default:
529+
return -EOPNOTSUPP;
516530
}
517531

518532
wx->ptp_clock = ptp_clock_register(&wx->ptp_caps, &wx->pdev->dev);
@@ -647,10 +661,18 @@ static u64 wx_ptp_read(const struct cyclecounter *hw_cc)
647661

648662
static void wx_ptp_link_speed_adjust(struct wx *wx, u32 *shift, u32 *incval)
649663
{
650-
if (wx->mac.type == wx_mac_em) {
664+
switch (wx->mac.type) {
665+
case wx_mac_aml:
666+
case wx_mac_aml40:
667+
*shift = WX_INCVAL_SHIFT_AML;
668+
*incval = WX_INCVAL_AML;
669+
return;
670+
case wx_mac_em:
651671
*shift = WX_INCVAL_SHIFT_EM;
652672
*incval = WX_INCVAL_EM;
653673
return;
674+
default:
675+
break;
654676
}
655677

656678
switch (wx->speed) {

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88

99
#include "../libwx/wx_type.h"
1010
#include "../libwx/wx_lib.h"
11+
#include "../libwx/wx_ptp.h"
1112
#include "../libwx/wx_hw.h"
1213
#include "txgbe_type.h"
1314
#include "txgbe_aml.h"
@@ -311,6 +312,9 @@ static void txgbe_mac_link_up_aml(struct phylink_config *config,
311312
wr32(wx, TXGBE_AML_MAC_TX_CFG, txcfg | TXGBE_AML_MAC_TX_CFG_TE);
312313

313314
wx->speed = speed;
315+
wx->last_rx_ptp_check = jiffies;
316+
if (test_bit(WX_STATE_PTP_RUNNING, wx->state))
317+
wx_ptp_reset_cyclecounter(wx);
314318
}
315319

316320
static void txgbe_mac_link_down_aml(struct phylink_config *config,
@@ -323,6 +327,8 @@ static void txgbe_mac_link_down_aml(struct phylink_config *config,
323327
wr32m(wx, WX_MAC_RX_CFG, WX_MAC_RX_CFG_RE, 0);
324328

325329
wx->speed = SPEED_UNKNOWN;
330+
if (test_bit(WX_STATE_PTP_RUNNING, wx->state))
331+
wx_ptp_reset_cyclecounter(wx);
326332
}
327333

328334
static void txgbe_mac_config_aml(struct phylink_config *config, unsigned int mode,

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
#include "../libwx/wx_type.h"
88
#include "../libwx/wx_lib.h"
9+
#include "../libwx/wx_ptp.h"
910
#include "../libwx/wx_hw.h"
1011
#include "../libwx/wx_sriov.h"
1112
#include "txgbe_type.h"
@@ -178,6 +179,10 @@ static irqreturn_t txgbe_misc_irq_thread_fn(int irq, void *data)
178179
handle_nested_irq(sub_irq);
179180
nhandled++;
180181
}
182+
if (unlikely(eicr & TXGBE_PX_MISC_IC_TIMESYNC)) {
183+
wx_ptp_check_pps_event(wx);
184+
nhandled++;
185+
}
181186

182187
wx_intr_enable(wx, TXGBE_INTR_MISC);
183188
return (nhandled > 0 ? IRQ_HANDLED : IRQ_NONE);

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,7 @@
8282
/* Extended Interrupt Enable Set */
8383
#define TXGBE_PX_MISC_ETH_LKDN BIT(8)
8484
#define TXGBE_PX_MISC_DEV_RST BIT(10)
85+
#define TXGBE_PX_MISC_IC_TIMESYNC BIT(11)
8586
#define TXGBE_PX_MISC_ETH_EVENT BIT(17)
8687
#define TXGBE_PX_MISC_ETH_LK BIT(18)
8788
#define TXGBE_PX_MISC_ETH_AN BIT(19)
@@ -92,7 +93,7 @@
9293
(TXGBE_PX_MISC_ETH_LKDN | TXGBE_PX_MISC_DEV_RST | \
9394
TXGBE_PX_MISC_ETH_EVENT | TXGBE_PX_MISC_ETH_LK | \
9495
TXGBE_PX_MISC_ETH_AN | TXGBE_PX_MISC_INT_ERR | \
95-
TXGBE_PX_MISC_IC_VF_MBOX)
96+
TXGBE_PX_MISC_IC_VF_MBOX | TXGBE_PX_MISC_IC_TIMESYNC)
9697

9798
/* Port cfg registers */
9899
#define TXGBE_CFG_PORT_ST 0x14404

0 commit comments

Comments
 (0)