diff options
| author | Laurence Evans <levans@solarflare.com> | 2013-11-21 05:38:24 -0500 |
|---|---|---|
| committer | Ben Hutchings <bhutchings@solarflare.com> | 2013-12-12 17:07:08 -0500 |
| commit | dfd8d581fbdce9f3b4777a7c59d28ca35ed194be (patch) | |
| tree | e48f0e1fb90d2b0d57ecb99508b985ae2a3a4727 | |
| parent | 94cd60d09eba9e8de0522d416d867fb16858fccd (diff) | |
sfc: Tidy up PTP synchronization code
Signed-off-by: Ben Hutchings <bhutchings@solarflare.com>
| -rw-r--r-- | drivers/net/ethernet/sfc/ptp.c | 44 |
1 files changed, 24 insertions, 20 deletions
diff --git a/drivers/net/ethernet/sfc/ptp.c b/drivers/net/ethernet/sfc/ptp.c index 82d8e27e8a58..361d7cedd897 100644 --- a/drivers/net/ethernet/sfc/ptp.c +++ b/drivers/net/ethernet/sfc/ptp.c | |||
| @@ -435,7 +435,6 @@ efx_ptp_process_times(struct efx_nic *efx, MCDI_DECLARE_STRUCT_PTR(synch_buf), | |||
| 435 | MCDI_VAR_ARRAY_LEN(response_length, | 435 | MCDI_VAR_ARRAY_LEN(response_length, |
| 436 | PTP_OUT_SYNCHRONIZE_TIMESET); | 436 | PTP_OUT_SYNCHRONIZE_TIMESET); |
| 437 | unsigned i; | 437 | unsigned i; |
| 438 | unsigned total; | ||
| 439 | unsigned ngood = 0; | 438 | unsigned ngood = 0; |
| 440 | unsigned last_good = 0; | 439 | unsigned last_good = 0; |
| 441 | struct efx_ptp_data *ptp = efx->ptp_data; | 440 | struct efx_ptp_data *ptp = efx->ptp_data; |
| @@ -446,33 +445,38 @@ efx_ptp_process_times(struct efx_nic *efx, MCDI_DECLARE_STRUCT_PTR(synch_buf), | |||
| 446 | if (number_readings == 0) | 445 | if (number_readings == 0) |
| 447 | return -EAGAIN; | 446 | return -EAGAIN; |
| 448 | 447 | ||
| 449 | /* Read the set of results and increment stats for any results that | 448 | /* Read the set of results and find the last good host-MC |
| 450 | * appera to be erroneous. | 449 | * synchronization result. The MC times when it finishes reading the |
| 450 | * host time so the corrected window time should be fairly constant | ||
| 451 | * for a given platform. | ||
| 451 | */ | 452 | */ |
| 452 | for (i = 0; i < number_readings; i++) { | 453 | for (i = 0; i < number_readings; i++) { |
| 454 | s32 window, corrected; | ||
| 455 | |||
| 453 | efx_ptp_read_timeset( | 456 | efx_ptp_read_timeset( |
| 454 | MCDI_ARRAY_STRUCT_PTR(synch_buf, | 457 | MCDI_ARRAY_STRUCT_PTR(synch_buf, |
| 455 | PTP_OUT_SYNCHRONIZE_TIMESET, i), | 458 | PTP_OUT_SYNCHRONIZE_TIMESET, i), |
| 456 | &ptp->timeset[i]); | 459 | &ptp->timeset[i]); |
| 457 | } | ||
| 458 | 460 | ||
| 459 | /* Find the last good host-MC synchronization result. The MC times | 461 | window = ptp->timeset[i].window; |
| 460 | * when it finishes reading the host time so the corrected window time | 462 | corrected = window - ptp->timeset[i].waitns; |
| 461 | * should be fairly constant for a given platform. | 463 | |
| 462 | */ | 464 | /* We expect the uncorrected synchronization window to be at |
| 463 | total = 0; | 465 | * least as large as the interval between host start and end |
| 464 | for (i = 0; i < number_readings; i++) | 466 | * times. If it is smaller than this then this is mostly likely |
| 465 | if (ptp->timeset[i].window > ptp->timeset[i].waitns) { | 467 | * to be a consequence of the host's time being adjusted. |
| 466 | unsigned win; | 468 | * Check that the corrected sync window is in a reasonable |
| 467 | 469 | * range. If it is out of range it is likely to be because an | |
| 468 | win = ptp->timeset[i].window - ptp->timeset[i].waitns; | 470 | * interrupt or other delay occurred between reading the system |
| 469 | if (win >= MIN_SYNCHRONISATION_NS && | 471 | * time and writing it to MC memory. |
| 470 | win < MAX_SYNCHRONISATION_NS) { | 472 | */ |
| 471 | total += ptp->timeset[i].window; | 473 | if (window >= SYNCHRONISATION_GRANULARITY_NS && |
| 472 | ngood++; | 474 | corrected < MAX_SYNCHRONISATION_NS && |
| 473 | last_good = i; | 475 | corrected >= MIN_SYNCHRONISATION_NS) { |
| 474 | } | 476 | ngood++; |
| 477 | last_good = i; | ||
| 475 | } | 478 | } |
| 479 | } | ||
| 476 | 480 | ||
| 477 | if (ngood == 0) { | 481 | if (ngood == 0) { |
| 478 | netif_warn(efx, drv, efx->net_dev, | 482 | netif_warn(efx, drv, efx->net_dev, |
