Skip to content

Commit 92456e7

Browse files
jacob-kelleranguy11
authored andcommitted
ice: Add unified ice_capture_crosststamp
Devices supported by ice driver use essentially the same logic for performing a crosstimestamp. The only difference is that E830 hardware has different offsets. Instead of having multiple implementations, combine them into a single ice_capture_crosststamp() function. To support both hardware types, the ice_capture_crosststamp function must be able to determine the appropriate registers to access. To handle this, pass a custom context structure instead of the PF pointer. This structure, ice_crosststamp_ctx, contains a pointer to the PF, and a pointer to the device configuration structure. This new structure also will make it easier to implement historic snapshot support in a future commit. The device configuration structure is a static const data which defines the offsets and flags for the various registers. This includes the lock register, the cross timestamp control register, the upper and lower ART system time capture registers, and the upper and lower device time capture registers for each timer index. Use the configuration structure to access all of the registers in ice_capture_crosststamp(). Ensure that we don't over-run the device time array by checking that the timer index is 0 or 1. Previously this was simply assumed, and it would cause the device to read an incorrect and likely garbage register. It does feel like there should be a kernel interface for managing register offsets like this, but the closest thing I saw was <linux/regmap.h> which is interesting but not quite what we're looking for... Use rd32_poll_timeout() to read lock_reg and ctl_reg. Add snapshot system time for historic interpolation. Remove X86_FEATURE_ART and X86_FEATURE_TSC_KNOWN_FREQ from all E82X devices because those are SoCs, which will always have those features. Reviewed-by: Przemek Kitszel <przemyslaw.kitszel@intel.com> Signed-off-by: Jacob Keller <jacob.e.keller@intel.com> Signed-off-by: Karol Kolacinski <karol.kolacinski@intel.com> Tested-by: Pucha Himasekhar Reddy <himasekharx.reddy.pucha@intel.com> (A Contingent worker at Intel) Signed-off-by: Tony Nguyen <anthony.l.nguyen@intel.com>
1 parent f9472aa commit 92456e7

File tree

1 file changed

+129
-75
lines changed

1 file changed

+129
-75
lines changed

drivers/net/ethernet/intel/ice/ice_ptp.c

Lines changed: 129 additions & 75 deletions
Original file line numberDiff line numberDiff line change
@@ -2179,116 +2179,174 @@ static int ice_ptp_adjtime(struct ptp_clock_info *info, s64 delta)
21792179
return 0;
21802180
}
21812181

2182-
#ifdef CONFIG_ICE_HWTS
21832182
/**
2184-
* ice_ptp_get_syncdevicetime - Get the cross time stamp info
2183+
* struct ice_crosststamp_cfg - Device cross timestamp configuration
2184+
* @lock_reg: The hardware semaphore lock to use
2185+
* @lock_busy: Bit in the semaphore lock indicating the lock is busy
2186+
* @ctl_reg: The hardware register to request cross timestamp
2187+
* @ctl_active: Bit in the control register to request cross timestamp
2188+
* @art_time_l: Lower 32-bits of ART system time
2189+
* @art_time_h: Upper 32-bits of ART system time
2190+
* @dev_time_l: Lower 32-bits of device time (per timer index)
2191+
* @dev_time_h: Upper 32-bits of device time (per timer index)
2192+
*/
2193+
struct ice_crosststamp_cfg {
2194+
/* HW semaphore lock register */
2195+
u32 lock_reg;
2196+
u32 lock_busy;
2197+
2198+
/* Capture control register */
2199+
u32 ctl_reg;
2200+
u32 ctl_active;
2201+
2202+
/* Time storage */
2203+
u32 art_time_l;
2204+
u32 art_time_h;
2205+
u32 dev_time_l[2];
2206+
u32 dev_time_h[2];
2207+
};
2208+
2209+
static const struct ice_crosststamp_cfg ice_crosststamp_cfg_e82x = {
2210+
.lock_reg = PFHH_SEM,
2211+
.lock_busy = PFHH_SEM_BUSY_M,
2212+
.ctl_reg = GLHH_ART_CTL,
2213+
.ctl_active = GLHH_ART_CTL_ACTIVE_M,
2214+
.art_time_l = GLHH_ART_TIME_L,
2215+
.art_time_h = GLHH_ART_TIME_H,
2216+
.dev_time_l[0] = GLTSYN_HHTIME_L(0),
2217+
.dev_time_h[0] = GLTSYN_HHTIME_H(0),
2218+
.dev_time_l[1] = GLTSYN_HHTIME_L(1),
2219+
.dev_time_h[1] = GLTSYN_HHTIME_H(1),
2220+
};
2221+
2222+
/**
2223+
* struct ice_crosststamp_ctx - Device cross timestamp context
2224+
* @snapshot: snapshot of system clocks for historic interpolation
2225+
* @pf: pointer to the PF private structure
2226+
* @cfg: pointer to hardware configuration for cross timestamp
2227+
*/
2228+
struct ice_crosststamp_ctx {
2229+
struct system_time_snapshot snapshot;
2230+
struct ice_pf *pf;
2231+
const struct ice_crosststamp_cfg *cfg;
2232+
};
2233+
2234+
/**
2235+
* ice_capture_crosststamp - Capture a device/system cross timestamp
21852236
* @device: Current device time
21862237
* @system: System counter value read synchronously with device time
2187-
* @ctx: Context provided by timekeeping code
2238+
* @__ctx: Context passed from ice_ptp_getcrosststamp
21882239
*
21892240
* Read device and system (ART) clock simultaneously and return the corrected
21902241
* clock values in ns.
2242+
*
2243+
* Return: zero on success, or a negative error code on failure.
21912244
*/
2192-
static int
2193-
ice_ptp_get_syncdevicetime(ktime_t *device,
2194-
struct system_counterval_t *system,
2195-
void *ctx)
2245+
static int ice_capture_crosststamp(ktime_t *device,
2246+
struct system_counterval_t *system,
2247+
void *__ctx)
21962248
{
2197-
struct ice_pf *pf = (struct ice_pf *)ctx;
2198-
struct ice_hw *hw = &pf->hw;
2199-
u32 hh_lock, hh_art_ctl;
2200-
int i;
2249+
struct ice_crosststamp_ctx *ctx = __ctx;
2250+
const struct ice_crosststamp_cfg *cfg;
2251+
u32 lock, ctl, ts_lo, ts_hi, tmr_idx;
2252+
struct ice_pf *pf;
2253+
struct ice_hw *hw;
2254+
int err;
2255+
u64 ts;
22012256

2202-
#define MAX_HH_HW_LOCK_TRIES 5
2203-
#define MAX_HH_CTL_LOCK_TRIES 100
2257+
cfg = ctx->cfg;
2258+
pf = ctx->pf;
2259+
hw = &pf->hw;
22042260

2205-
for (i = 0; i < MAX_HH_HW_LOCK_TRIES; i++) {
2206-
/* Get the HW lock */
2207-
hh_lock = rd32(hw, PFHH_SEM + (PFTSYN_SEM_BYTES * hw->pf_id));
2208-
if (hh_lock & PFHH_SEM_BUSY_M) {
2209-
usleep_range(10000, 15000);
2210-
continue;
2211-
}
2212-
break;
2213-
}
2214-
if (hh_lock & PFHH_SEM_BUSY_M) {
2215-
dev_err(ice_pf_to_dev(pf), "PTP failed to get hh lock\n");
2261+
tmr_idx = hw->func_caps.ts_func_info.tmr_index_assoc;
2262+
if (tmr_idx > 1)
2263+
return -EINVAL;
2264+
2265+
/* Poll until we obtain the cross-timestamp hardware semaphore */
2266+
err = rd32_poll_timeout(hw, cfg->lock_reg, lock,
2267+
!(lock & cfg->lock_busy),
2268+
10 * USEC_PER_MSEC, 50 * USEC_PER_MSEC);
2269+
if (err) {
2270+
dev_err(ice_pf_to_dev(pf), "PTP failed to get cross timestamp lock\n");
22162271
return -EBUSY;
22172272
}
22182273

2274+
/* Snapshot system time for historic interpolation */
2275+
ktime_get_snapshot(&ctx->snapshot);
2276+
22192277
/* Program cmd to master timer */
22202278
ice_ptp_src_cmd(hw, ICE_PTP_READ_TIME);
22212279

22222280
/* Start the ART and device clock sync sequence */
2223-
hh_art_ctl = rd32(hw, GLHH_ART_CTL);
2224-
hh_art_ctl = hh_art_ctl | GLHH_ART_CTL_ACTIVE_M;
2225-
wr32(hw, GLHH_ART_CTL, hh_art_ctl);
2226-
2227-
for (i = 0; i < MAX_HH_CTL_LOCK_TRIES; i++) {
2228-
/* Wait for sync to complete */
2229-
hh_art_ctl = rd32(hw, GLHH_ART_CTL);
2230-
if (hh_art_ctl & GLHH_ART_CTL_ACTIVE_M) {
2231-
udelay(1);
2232-
continue;
2233-
} else {
2234-
u32 hh_ts_lo, hh_ts_hi, tmr_idx;
2235-
u64 hh_ts;
2236-
2237-
tmr_idx = hw->func_caps.ts_func_info.tmr_index_assoc;
2238-
/* Read ART time */
2239-
hh_ts_lo = rd32(hw, GLHH_ART_TIME_L);
2240-
hh_ts_hi = rd32(hw, GLHH_ART_TIME_H);
2241-
hh_ts = ((u64)hh_ts_hi << 32) | hh_ts_lo;
2242-
system->cycles = hh_ts;
2243-
system->cs_id = CSID_X86_ART;
2244-
/* Read Device source clock time */
2245-
hh_ts_lo = rd32(hw, GLTSYN_HHTIME_L(tmr_idx));
2246-
hh_ts_hi = rd32(hw, GLTSYN_HHTIME_H(tmr_idx));
2247-
hh_ts = ((u64)hh_ts_hi << 32) | hh_ts_lo;
2248-
*device = ns_to_ktime(hh_ts);
2249-
break;
2250-
}
2251-
}
2281+
ctl = rd32(hw, cfg->ctl_reg);
2282+
ctl |= cfg->ctl_active;
2283+
wr32(hw, cfg->ctl_reg, ctl);
22522284

2285+
/* Poll until hardware completes the capture */
2286+
err = rd32_poll_timeout(hw, cfg->ctl_reg, ctl, !(ctl & cfg->ctl_active),
2287+
5, 20 * USEC_PER_MSEC);
2288+
if (err)
2289+
goto err_timeout;
2290+
2291+
/* Read ART system time */
2292+
ts_lo = rd32(hw, cfg->art_time_l);
2293+
ts_hi = rd32(hw, cfg->art_time_h);
2294+
ts = ((u64)ts_hi << 32) | ts_lo;
2295+
system->cycles = ts;
2296+
system->cs_id = CSID_X86_ART;
2297+
2298+
/* Read Device source clock time */
2299+
ts_lo = rd32(hw, cfg->dev_time_l[tmr_idx]);
2300+
ts_hi = rd32(hw, cfg->dev_time_h[tmr_idx]);
2301+
ts = ((u64)ts_hi << 32) | ts_lo;
2302+
*device = ns_to_ktime(ts);
2303+
2304+
err_timeout:
22532305
/* Clear the master timer */
22542306
ice_ptp_src_cmd(hw, ICE_PTP_NOP);
22552307

22562308
/* Release HW lock */
2257-
hh_lock = rd32(hw, PFHH_SEM + (PFTSYN_SEM_BYTES * hw->pf_id));
2258-
hh_lock = hh_lock & ~PFHH_SEM_BUSY_M;
2259-
wr32(hw, PFHH_SEM + (PFTSYN_SEM_BYTES * hw->pf_id), hh_lock);
2260-
2261-
if (i == MAX_HH_CTL_LOCK_TRIES)
2262-
return -ETIMEDOUT;
2309+
lock = rd32(hw, cfg->lock_reg);
2310+
lock &= ~cfg->lock_busy;
2311+
wr32(hw, cfg->lock_reg, lock);
22632312

2264-
return 0;
2313+
return err;
22652314
}
22662315

22672316
/**
2268-
* ice_ptp_getcrosststamp_e82x - Capture a device cross timestamp
2317+
* ice_ptp_getcrosststamp - Capture a device cross timestamp
22692318
* @info: the driver's PTP info structure
22702319
* @cts: The memory to fill the cross timestamp info
22712320
*
22722321
* Capture a cross timestamp between the ART and the device PTP hardware
22732322
* clock. Fill the cross timestamp information and report it back to the
22742323
* caller.
22752324
*
2276-
* This is only valid for E822 and E823 devices which have support for
2277-
* generating the cross timestamp via PCIe PTM.
2278-
*
22792325
* In order to correctly correlate the ART timestamp back to the TSC time, the
22802326
* CPU must have X86_FEATURE_TSC_KNOWN_FREQ.
2327+
*
2328+
* Return: zero on success, or a negative error code on failure.
22812329
*/
2282-
static int
2283-
ice_ptp_getcrosststamp_e82x(struct ptp_clock_info *info,
2284-
struct system_device_crosststamp *cts)
2330+
static int ice_ptp_getcrosststamp(struct ptp_clock_info *info,
2331+
struct system_device_crosststamp *cts)
22852332
{
22862333
struct ice_pf *pf = ptp_info_to_pf(info);
2334+
struct ice_crosststamp_ctx ctx = {
2335+
.pf = pf,
2336+
};
2337+
2338+
switch (pf->hw.mac_type) {
2339+
case ICE_MAC_GENERIC:
2340+
case ICE_MAC_GENERIC_3K_E825:
2341+
ctx.cfg = &ice_crosststamp_cfg_e82x;
2342+
break;
2343+
default:
2344+
return -EOPNOTSUPP;
2345+
}
22872346

2288-
return get_device_system_crosststamp(ice_ptp_get_syncdevicetime,
2289-
pf, NULL, cts);
2347+
return get_device_system_crosststamp(ice_capture_crosststamp, &ctx,
2348+
&ctx.snapshot, cts);
22902349
}
2291-
#endif /* CONFIG_ICE_HWTS */
22922350

22932351
/**
22942352
* ice_ptp_get_ts_config - ioctl interface to read the timestamping config
@@ -2549,12 +2607,8 @@ static int ice_ptp_parse_sdp_entries(struct ice_pf *pf, __le16 *entries,
25492607
*/
25502608
static void ice_ptp_set_funcs_e82x(struct ice_pf *pf)
25512609
{
2552-
#ifdef CONFIG_ICE_HWTS
2553-
if (boot_cpu_has(X86_FEATURE_ART) &&
2554-
boot_cpu_has(X86_FEATURE_TSC_KNOWN_FREQ))
2555-
pf->ptp.info.getcrosststamp = ice_ptp_getcrosststamp_e82x;
2610+
pf->ptp.info.getcrosststamp = ice_ptp_getcrosststamp;
25562611

2557-
#endif /* CONFIG_ICE_HWTS */
25582612
if (pf->hw.mac_type == ICE_MAC_GENERIC_3K_E825) {
25592613
pf->ptp.ice_pin_desc = ice_pin_desc_e825c;
25602614
pf->ptp.info.n_pins = ICE_PIN_DESC_ARR_LEN(ice_pin_desc_e825c);

0 commit comments

Comments
 (0)