drivers/crypto/intel/qat/qat_common/adf_clock.c
Source file repositories/reference/linux-study-clean/drivers/crypto/intel/qat/qat_common/adf_clock.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/crypto/intel/qat/qat_common/adf_clock.c- Extension
.c- Size
- 3566 bytes
- Lines
- 136
- Domain
- Driver Families
- Bucket
- drivers/crypto
- Inferred role
- Driver Families: exported/initcall integration point
- Status
- integration implementation candidate
Why This File Exists
Repeatable hardware-adapter layer. Deep compatibility for every driver is out of scope; this atlas records patterns, probe lifecycles, bus glue, IRQ/DMA usage, and links back to core abstractions.
- Repeatable hardware-adapter layer. Deep compatibility for every driver is out of scope; this atlas records patterns, probe lifecycles, bus glue, IRQ/DMA usage, and links back to core abstractions.
- Exports symbols or registers init work; inspect boot/module ordering and who consumes the exported contract.
- Defines or uses C structs; map object ownership, embedded links, reference counts, and lock ownership.
Dependency Surface
linux/delay.hlinux/dev_printk.hlinux/export.hlinux/math.hlinux/minmax.hlinux/time64.hlinux/types.hlinux/units.hasm/errno.hadf_admin.hadf_accel_devices.hadf_clock.hadf_common_drv.h
Detected Declarations
function timespec_to_usfunction timespec_to_msfunction adf_clock_get_current_timefunction measure_clockfunction adf_dev_measure_clockexport adf_dev_measure_clock
Annotated Snippet
if (ret) {
dev_err(&GET_DEV(accel_dev),
"Failed to get fw timestamp\n");
return ret;
}
ktime_get_real_ts64(&ts2);
delta_us = timespec_to_us(&ts2) - timespec_to_us(&ts1);
} while (delta_us > MEASURE_CLOCK_DELTA_THRESHOLD_US && --tries);
if (!tries) {
dev_err(&GET_DEV(accel_dev), "Excessive clock measure delay\n");
return -ETIMEDOUT;
}
fsleep(MEASURE_CLOCK_DELAY_US);
tries = MEASURE_CLOCK_RETRIES;
do {
ktime_get_real_ts64(&ts3);
if (adf_get_fw_timestamp(accel_dev, ×tamp2)) {
dev_err(&GET_DEV(accel_dev),
"Failed to get fw timestamp\n");
return -EIO;
}
ktime_get_real_ts64(&ts4);
delta_us = timespec_to_us(&ts4) - timespec_to_us(&ts3);
} while (delta_us > MEASURE_CLOCK_DELTA_THRESHOLD_US && --tries);
if (!tries) {
dev_err(&GET_DEV(accel_dev), "Excessive clock measure delay\n");
return -ETIMEDOUT;
}
delta_us = timespec_to_us(&ts3) - timespec_to_us(&ts1);
if (!delta_us)
return -EINVAL;
temp = (timestamp2 - timestamp1) * ME_CLK_DIVIDER * 10;
temp = DIV_ROUND_CLOSEST_ULL(temp, delta_us);
/*
* Enclose the division to allow the preprocessor to precalculate it,
* and avoid promoting r-value to 64-bit before division.
*/
*frequency = temp * (HZ_PER_MHZ / 10);
return 0;
}
/**
* adf_dev_measure_clock() - measures device clock frequency
* @accel_dev: Pointer to acceleration device.
* @frequency: Pointer to variable where result will be stored
* @min: Minimal allowed frequency value
* @max: Maximal allowed frequency value
*
* If the measurement result will go beyond the min/max thresholds the value
* will take the value of the crossed threshold.
*
* This algorithm compares the device firmware timestamp with the kernel
* timestamp. So we can't expect too high accuracy from this measurement.
*
* Return:
* * 0 - measurement succeed
* * -ETIMEDOUT - measurement failed
*/
int adf_dev_measure_clock(struct adf_accel_dev *accel_dev,
u32 *frequency, u32 min, u32 max)
{
int ret;
u32 freq;
ret = measure_clock(accel_dev, &freq);
if (ret)
return ret;
*frequency = clamp(freq, min, max);
if (*frequency != freq)
dev_warn(&GET_DEV(accel_dev),
"Measured clock %d Hz is out of range, assuming %d\n",
freq, *frequency);
return 0;
}
EXPORT_SYMBOL_GPL(adf_dev_measure_clock);
Annotation
- Immediate include surface: `linux/delay.h`, `linux/dev_printk.h`, `linux/export.h`, `linux/math.h`, `linux/minmax.h`, `linux/time64.h`, `linux/types.h`, `linux/units.h`.
- Detected declarations: `function timespec_to_us`, `function timespec_to_ms`, `function adf_clock_get_current_time`, `function measure_clock`, `function adf_dev_measure_clock`, `export adf_dev_measure_clock`.
- Atlas domain: Driver Families / drivers/crypto.
- Implementation status: integration implementation candidate.
Implementation Notes
- This generated page is the file-by-file coverage layer; curated subsystem chapters should link here when they synthesize a multi-file control flow.
- Core OS pages should be promoted from atlas-only to deep-reviewed when they explain data structures, invariants, locking, lifecycle, and C implementation snippets.
- Driver-family pages are intentionally pattern-oriented unless they are part of the selected PCIe/NVMe representative device path.