Skip to content

Commit 724d262

Browse files
christopher-s-hallgregkh
authored andcommitted
igc: add lock preventing multiple simultaneous PTM transactions
[ Upstream commit 1a931c4 ] Add a mutex around the PTM transaction to prevent multiple transactors Multiple processes try to initiate a PTM transaction, one or all may fail. This can be reproduced by running two instances of the following: $ sudo phc2sys -O 0 -i tsn0 -m PHC2SYS exits with: "ioctl PTP_OFFSET_PRECISE: Connection timed out" when the PTM transaction fails Note: Normally two instance of PHC2SYS will not run, but one process should not break another. Fixes: a90ec84 ("igc: Add support for PTP getcrosststamp()") Signed-off-by: Christopher S M Hall <[email protected]> Reviewed-by: Corinna Vinschen <[email protected]> Signed-off-by: Jacob Keller <[email protected]> Tested-by: Mor Bar-Gabay <[email protected]> Acked-by: Vinicius Costa Gomes <[email protected]> Signed-off-by: Tony Nguyen <[email protected]> Signed-off-by: Sasha Levin <[email protected]>
1 parent c15065a commit 724d262

File tree

2 files changed

+19
-2
lines changed

2 files changed

+19
-2
lines changed

drivers/net/ethernet/intel/igc/igc.h

+1
Original file line numberDiff line numberDiff line change
@@ -319,6 +319,7 @@ struct igc_adapter {
319319
struct timespec64 prev_ptp_time; /* Pre-reset PTP clock */
320320
ktime_t ptp_reset_start; /* Reset time in clock mono */
321321
struct system_time_snapshot snapshot;
322+
struct mutex ptm_lock; /* Only allow one PTM transaction at a time */
322323

323324
char fw_version[32];
324325

drivers/net/ethernet/intel/igc/igc_ptp.c

+18-2
Original file line numberDiff line numberDiff line change
@@ -974,6 +974,7 @@ static void igc_ptm_log_error(struct igc_adapter *adapter, u32 ptm_stat)
974974
}
975975
}
976976

977+
/* The PTM lock: adapter->ptm_lock must be held when calling igc_ptm_trigger() */
977978
static void igc_ptm_trigger(struct igc_hw *hw)
978979
{
979980
u32 ctrl;
@@ -990,6 +991,7 @@ static void igc_ptm_trigger(struct igc_hw *hw)
990991
wrfl();
991992
}
992993

994+
/* The PTM lock: adapter->ptm_lock must be held when calling igc_ptm_reset() */
993995
static void igc_ptm_reset(struct igc_hw *hw)
994996
{
995997
u32 ctrl;
@@ -1068,9 +1070,16 @@ static int igc_ptp_getcrosststamp(struct ptp_clock_info *ptp,
10681070
{
10691071
struct igc_adapter *adapter = container_of(ptp, struct igc_adapter,
10701072
ptp_caps);
1073+
int ret;
10711074

1072-
return get_device_system_crosststamp(igc_phc_get_syncdevicetime,
1073-
adapter, &adapter->snapshot, cts);
1075+
/* This blocks until any in progress PTM transactions complete */
1076+
mutex_lock(&adapter->ptm_lock);
1077+
1078+
ret = get_device_system_crosststamp(igc_phc_get_syncdevicetime,
1079+
adapter, &adapter->snapshot, cts);
1080+
mutex_unlock(&adapter->ptm_lock);
1081+
1082+
return ret;
10741083
}
10751084

10761085
static int igc_ptp_getcyclesx64(struct ptp_clock_info *ptp,
@@ -1169,6 +1178,7 @@ void igc_ptp_init(struct igc_adapter *adapter)
11691178
spin_lock_init(&adapter->ptp_tx_lock);
11701179
spin_lock_init(&adapter->free_timer_lock);
11711180
spin_lock_init(&adapter->tmreg_lock);
1181+
mutex_init(&adapter->ptm_lock);
11721182

11731183
adapter->tstamp_config.rx_filter = HWTSTAMP_FILTER_NONE;
11741184
adapter->tstamp_config.tx_type = HWTSTAMP_TX_OFF;
@@ -1181,6 +1191,7 @@ void igc_ptp_init(struct igc_adapter *adapter)
11811191
if (IS_ERR(adapter->ptp_clock)) {
11821192
adapter->ptp_clock = NULL;
11831193
netdev_err(netdev, "ptp_clock_register failed\n");
1194+
mutex_destroy(&adapter->ptm_lock);
11841195
} else if (adapter->ptp_clock) {
11851196
netdev_info(netdev, "PHC added\n");
11861197
adapter->ptp_flags |= IGC_PTP_ENABLED;
@@ -1210,10 +1221,12 @@ static void igc_ptm_stop(struct igc_adapter *adapter)
12101221
struct igc_hw *hw = &adapter->hw;
12111222
u32 ctrl;
12121223

1224+
mutex_lock(&adapter->ptm_lock);
12131225
ctrl = rd32(IGC_PTM_CTRL);
12141226
ctrl &= ~IGC_PTM_CTRL_EN;
12151227

12161228
wr32(IGC_PTM_CTRL, ctrl);
1229+
mutex_unlock(&adapter->ptm_lock);
12171230
}
12181231

12191232
/**
@@ -1255,6 +1268,7 @@ void igc_ptp_stop(struct igc_adapter *adapter)
12551268
netdev_info(adapter->netdev, "PHC removed\n");
12561269
adapter->ptp_flags &= ~IGC_PTP_ENABLED;
12571270
}
1271+
mutex_destroy(&adapter->ptm_lock);
12581272
}
12591273

12601274
/**
@@ -1294,6 +1308,7 @@ void igc_ptp_reset(struct igc_adapter *adapter)
12941308
if (!igc_is_crosststamp_supported(adapter))
12951309
break;
12961310

1311+
mutex_lock(&adapter->ptm_lock);
12971312
wr32(IGC_PCIE_DIG_DELAY, IGC_PCIE_DIG_DELAY_DEFAULT);
12981313
wr32(IGC_PCIE_PHY_DELAY, IGC_PCIE_PHY_DELAY_DEFAULT);
12991314

@@ -1317,6 +1332,7 @@ void igc_ptp_reset(struct igc_adapter *adapter)
13171332
netdev_err(adapter->netdev, "Timeout reading IGC_PTM_STAT register\n");
13181333

13191334
igc_ptm_reset(hw);
1335+
mutex_unlock(&adapter->ptm_lock);
13201336
break;
13211337
default:
13221338
/* No work to do. */

0 commit comments

Comments
 (0)