Skip to content

Commit 131db49

Browse files
vvfedorenkokuba-moo
authored andcommitted
bnxt_en: reset PHC frequency in free-running mode
When using a PHC in shared between multiple hosts, the previous frequency value may not be reset and could lead to host being unable to compensate the offset with timecounter adjustments. To avoid such state reset the hardware frequency of PHC to zero on init. Some refactoring is needed to make code readable. Fixes: 85036ae ("bnxt_en: Add a non-real time mode to access NIC clock") Signed-off-by: Vadim Fedorenko <[email protected]> Reviewed-by: Pavan Chebbi <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Jakub Kicinski <[email protected]>
1 parent 064d705 commit 131db49

File tree

3 files changed

+35
-29
lines changed

3 files changed

+35
-29
lines changed

drivers/net/ethernet/broadcom/bnxt/bnxt.c

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6990,11 +6990,9 @@ static int bnxt_hwrm_func_qcfg(struct bnxt *bp)
69906990
if (flags & FUNC_QCFG_RESP_FLAGS_FW_DCBX_AGENT_ENABLED)
69916991
bp->fw_cap |= BNXT_FW_CAP_DCBX_AGENT;
69926992
}
6993-
if (BNXT_PF(bp) && (flags & FUNC_QCFG_RESP_FLAGS_MULTI_HOST)) {
6993+
if (BNXT_PF(bp) && (flags & FUNC_QCFG_RESP_FLAGS_MULTI_HOST))
69946994
bp->flags |= BNXT_FLAG_MULTI_HOST;
6995-
if (bp->fw_cap & BNXT_FW_CAP_PTP_RTC)
6996-
bp->fw_cap &= ~BNXT_FW_CAP_PTP_RTC;
6997-
}
6995+
69986996
if (flags & FUNC_QCFG_RESP_FLAGS_RING_MONITOR_ENABLED)
69996997
bp->fw_cap |= BNXT_FW_CAP_RING_MONITOR;
70006998

drivers/net/ethernet/broadcom/bnxt/bnxt.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2000,6 +2000,8 @@ struct bnxt {
20002000
u32 fw_dbg_cap;
20012001

20022002
#define BNXT_NEW_RM(bp) ((bp)->fw_cap & BNXT_FW_CAP_NEW_RM)
2003+
#define BNXT_PTP_USE_RTC(bp) (!BNXT_MH(bp) && \
2004+
((bp)->fw_cap & BNXT_FW_CAP_PTP_RTC))
20032005
u32 hwrm_spec_code;
20042006
u16 hwrm_cmd_seq;
20052007
u16 hwrm_cmd_kong_seq;

drivers/net/ethernet/broadcom/bnxt/bnxt_ptp.c

Lines changed: 31 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ static int bnxt_ptp_settime(struct ptp_clock_info *ptp_info,
6363
ptp_info);
6464
u64 ns = timespec64_to_ns(ts);
6565

66-
if (ptp->bp->fw_cap & BNXT_FW_CAP_PTP_RTC)
66+
if (BNXT_PTP_USE_RTC(ptp->bp))
6767
return bnxt_ptp_cfg_settime(ptp->bp, ns);
6868

6969
spin_lock_bh(&ptp->ptp_lock);
@@ -196,7 +196,7 @@ static int bnxt_ptp_adjtime(struct ptp_clock_info *ptp_info, s64 delta)
196196
struct bnxt_ptp_cfg *ptp = container_of(ptp_info, struct bnxt_ptp_cfg,
197197
ptp_info);
198198

199-
if (ptp->bp->fw_cap & BNXT_FW_CAP_PTP_RTC)
199+
if (BNXT_PTP_USE_RTC(ptp->bp))
200200
return bnxt_ptp_adjphc(ptp, delta);
201201

202202
spin_lock_bh(&ptp->ptp_lock);
@@ -205,34 +205,39 @@ static int bnxt_ptp_adjtime(struct ptp_clock_info *ptp_info, s64 delta)
205205
return 0;
206206
}
207207

208+
static int bnxt_ptp_adjfine_rtc(struct bnxt *bp, long scaled_ppm)
209+
{
210+
s32 ppb = scaled_ppm_to_ppb(scaled_ppm);
211+
struct hwrm_port_mac_cfg_input *req;
212+
int rc;
213+
214+
rc = hwrm_req_init(bp, req, HWRM_PORT_MAC_CFG);
215+
if (rc)
216+
return rc;
217+
218+
req->ptp_freq_adj_ppb = cpu_to_le32(ppb);
219+
req->enables = cpu_to_le32(PORT_MAC_CFG_REQ_ENABLES_PTP_FREQ_ADJ_PPB);
220+
rc = hwrm_req_send(bp, req);
221+
if (rc)
222+
netdev_err(bp->dev,
223+
"ptp adjfine failed. rc = %d\n", rc);
224+
return rc;
225+
}
226+
208227
static int bnxt_ptp_adjfine(struct ptp_clock_info *ptp_info, long scaled_ppm)
209228
{
210229
struct bnxt_ptp_cfg *ptp = container_of(ptp_info, struct bnxt_ptp_cfg,
211230
ptp_info);
212-
struct hwrm_port_mac_cfg_input *req;
213231
struct bnxt *bp = ptp->bp;
214-
int rc = 0;
215232

216-
if (!(ptp->bp->fw_cap & BNXT_FW_CAP_PTP_RTC)) {
217-
spin_lock_bh(&ptp->ptp_lock);
218-
timecounter_read(&ptp->tc);
219-
ptp->cc.mult = adjust_by_scaled_ppm(ptp->cmult, scaled_ppm);
220-
spin_unlock_bh(&ptp->ptp_lock);
221-
} else {
222-
s32 ppb = scaled_ppm_to_ppb(scaled_ppm);
223-
224-
rc = hwrm_req_init(bp, req, HWRM_PORT_MAC_CFG);
225-
if (rc)
226-
return rc;
233+
if (BNXT_PTP_USE_RTC(bp))
234+
return bnxt_ptp_adjfine_rtc(bp, scaled_ppm);
227235

228-
req->ptp_freq_adj_ppb = cpu_to_le32(ppb);
229-
req->enables = cpu_to_le32(PORT_MAC_CFG_REQ_ENABLES_PTP_FREQ_ADJ_PPB);
230-
rc = hwrm_req_send(ptp->bp, req);
231-
if (rc)
232-
netdev_err(ptp->bp->dev,
233-
"ptp adjfine failed. rc = %d\n", rc);
234-
}
235-
return rc;
236+
spin_lock_bh(&ptp->ptp_lock);
237+
timecounter_read(&ptp->tc);
238+
ptp->cc.mult = adjust_by_scaled_ppm(ptp->cmult, scaled_ppm);
239+
spin_unlock_bh(&ptp->ptp_lock);
240+
return 0;
236241
}
237242

238243
void bnxt_ptp_pps_event(struct bnxt *bp, u32 data1, u32 data2)
@@ -879,7 +884,7 @@ int bnxt_ptp_init_rtc(struct bnxt *bp, bool phc_cfg)
879884
u64 ns;
880885
int rc;
881886

882-
if (!bp->ptp_cfg || !(bp->fw_cap & BNXT_FW_CAP_PTP_RTC))
887+
if (!bp->ptp_cfg || !BNXT_PTP_USE_RTC(bp))
883888
return -ENODEV;
884889

885890
if (!phc_cfg) {
@@ -932,13 +937,14 @@ int bnxt_ptp_init(struct bnxt *bp, bool phc_cfg)
932937
atomic_set(&ptp->tx_avail, BNXT_MAX_TX_TS);
933938
spin_lock_init(&ptp->ptp_lock);
934939

935-
if (bp->fw_cap & BNXT_FW_CAP_PTP_RTC) {
940+
if (BNXT_PTP_USE_RTC(bp)) {
936941
bnxt_ptp_timecounter_init(bp, false);
937942
rc = bnxt_ptp_init_rtc(bp, phc_cfg);
938943
if (rc)
939944
goto out;
940945
} else {
941946
bnxt_ptp_timecounter_init(bp, true);
947+
bnxt_ptp_adjfine_rtc(bp, 0);
942948
}
943949

944950
ptp->ptp_info = bnxt_ptp_caps;

0 commit comments

Comments
 (0)