Skip to content

Commit 3df7fd7

Browse files
Andre GuedesJeff Kirsher
authored andcommitted
igc: Refactor igc_ptp_set_timestamp_mode()
Current igc_ptp_set_timestamp_mode() logic is a bit tangled since it handles many different hardware configurations in one single place, making it harder to follow. This patch untangles that code by breaking it into helper functions. Quick note about the hw->mac.type check which was removed in this refactoring: this check it not really needed since igc_i225 is the only type supported by the IGC driver. Signed-off-by: Andre Guedes <[email protected]> Tested-by: Aaron Brown <[email protected]> Signed-off-by: Jeff Kirsher <[email protected]>
1 parent 3b44d4c commit 3df7fd7

File tree

1 file changed

+53
-50
lines changed

1 file changed

+53
-50
lines changed

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

Lines changed: 53 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -239,6 +239,54 @@ static void igc_ptp_enable_tstamp_all_rxqueues(struct igc_adapter *adapter,
239239
}
240240
}
241241

242+
static void igc_ptp_disable_rx_timestamp(struct igc_adapter *adapter)
243+
{
244+
struct igc_hw *hw = &adapter->hw;
245+
u32 val;
246+
247+
wr32(IGC_TSYNCRXCTL, 0);
248+
249+
val = rd32(IGC_RXPBS);
250+
val &= ~IGC_RXPBS_CFG_TS_EN;
251+
wr32(IGC_RXPBS, val);
252+
}
253+
254+
static void igc_ptp_enable_rx_timestamp(struct igc_adapter *adapter)
255+
{
256+
struct igc_hw *hw = &adapter->hw;
257+
u32 val;
258+
259+
val = rd32(IGC_RXPBS);
260+
val |= IGC_RXPBS_CFG_TS_EN;
261+
wr32(IGC_RXPBS, val);
262+
263+
/* FIXME: For now, only support retrieving RX timestamps from timer 0
264+
*/
265+
igc_ptp_enable_tstamp_all_rxqueues(adapter, 0);
266+
267+
val = IGC_TSYNCRXCTL_ENABLED | IGC_TSYNCRXCTL_TYPE_ALL |
268+
IGC_TSYNCRXCTL_RXSYNSIG;
269+
wr32(IGC_TSYNCRXCTL, val);
270+
}
271+
272+
static void igc_ptp_disable_tx_timestamp(struct igc_adapter *adapter)
273+
{
274+
struct igc_hw *hw = &adapter->hw;
275+
276+
wr32(IGC_TSYNCTXCTL, 0);
277+
}
278+
279+
static void igc_ptp_enable_tx_timestamp(struct igc_adapter *adapter)
280+
{
281+
struct igc_hw *hw = &adapter->hw;
282+
283+
wr32(IGC_TSYNCTXCTL, IGC_TSYNCTXCTL_ENABLED | IGC_TSYNCTXCTL_TXSYNSIG);
284+
285+
/* Read TXSTMP registers to discard any timestamp previously stored. */
286+
rd32(IGC_TXSTMPL);
287+
rd32(IGC_TXSTMPH);
288+
}
289+
242290
/**
243291
* igc_ptp_set_timestamp_mode - setup hardware for timestamping
244292
* @adapter: networking device structure
@@ -249,27 +297,24 @@ static void igc_ptp_enable_tstamp_all_rxqueues(struct igc_adapter *adapter,
249297
static int igc_ptp_set_timestamp_mode(struct igc_adapter *adapter,
250298
struct hwtstamp_config *config)
251299
{
252-
u32 tsync_tx_ctl = IGC_TSYNCTXCTL_ENABLED;
253-
u32 tsync_rx_ctl = IGC_TSYNCRXCTL_ENABLED;
254-
struct igc_hw *hw = &adapter->hw;
255-
u32 regval;
256-
257300
/* reserved for future extensions */
258301
if (config->flags)
259302
return -EINVAL;
260303

261304
switch (config->tx_type) {
262305
case HWTSTAMP_TX_OFF:
263-
tsync_tx_ctl = 0;
306+
igc_ptp_disable_tx_timestamp(adapter);
307+
break;
264308
case HWTSTAMP_TX_ON:
309+
igc_ptp_enable_tx_timestamp(adapter);
265310
break;
266311
default:
267312
return -ERANGE;
268313
}
269314

270315
switch (config->rx_filter) {
271316
case HWTSTAMP_FILTER_NONE:
272-
tsync_rx_ctl = 0;
317+
igc_ptp_disable_rx_timestamp(adapter);
273318
break;
274319
case HWTSTAMP_FILTER_PTP_V1_L4_SYNC:
275320
case HWTSTAMP_FILTER_PTP_V1_L4_DELAY_REQ:
@@ -285,55 +330,13 @@ static int igc_ptp_set_timestamp_mode(struct igc_adapter *adapter,
285330
case HWTSTAMP_FILTER_PTP_V1_L4_EVENT:
286331
case HWTSTAMP_FILTER_NTP_ALL:
287332
case HWTSTAMP_FILTER_ALL:
288-
tsync_rx_ctl |= IGC_TSYNCRXCTL_TYPE_ALL;
333+
igc_ptp_enable_rx_timestamp(adapter);
289334
config->rx_filter = HWTSTAMP_FILTER_ALL;
290335
break;
291336
default:
292-
config->rx_filter = HWTSTAMP_FILTER_NONE;
293337
return -ERANGE;
294338
}
295339

296-
if (tsync_rx_ctl) {
297-
tsync_rx_ctl = IGC_TSYNCRXCTL_ENABLED;
298-
tsync_rx_ctl |= IGC_TSYNCRXCTL_TYPE_ALL;
299-
tsync_rx_ctl |= IGC_TSYNCRXCTL_RXSYNSIG;
300-
config->rx_filter = HWTSTAMP_FILTER_ALL;
301-
302-
if (hw->mac.type == igc_i225) {
303-
regval = rd32(IGC_RXPBS);
304-
regval |= IGC_RXPBS_CFG_TS_EN;
305-
wr32(IGC_RXPBS, regval);
306-
307-
/* FIXME: For now, only support retrieving RX
308-
* timestamps from timer 0
309-
*/
310-
igc_ptp_enable_tstamp_all_rxqueues(adapter, 0);
311-
}
312-
}
313-
314-
if (tsync_tx_ctl) {
315-
tsync_tx_ctl = IGC_TSYNCTXCTL_ENABLED;
316-
tsync_tx_ctl |= IGC_TSYNCTXCTL_TXSYNSIG;
317-
}
318-
319-
/* enable/disable TX */
320-
regval = rd32(IGC_TSYNCTXCTL);
321-
regval &= ~IGC_TSYNCTXCTL_ENABLED;
322-
regval |= tsync_tx_ctl;
323-
wr32(IGC_TSYNCTXCTL, regval);
324-
325-
/* enable/disable RX */
326-
regval = rd32(IGC_TSYNCRXCTL);
327-
regval &= ~(IGC_TSYNCRXCTL_ENABLED | IGC_TSYNCRXCTL_TYPE_MASK);
328-
regval |= tsync_rx_ctl;
329-
wr32(IGC_TSYNCRXCTL, regval);
330-
331-
wrfl();
332-
333-
/* clear TX time stamp registers, just to be sure */
334-
regval = rd32(IGC_TXSTMPL);
335-
regval = rd32(IGC_TXSTMPH);
336-
337340
return 0;
338341
}
339342

0 commit comments

Comments
 (0)