Lines Matching full:phc
79 /* PHC definitions */
1806 struct ena_com_phc_info *phc = &ena_dev->phc;
1808 memset(phc, 0x0, sizeof(*phc));
1810 /* Allocate shared mem used PHC timestamp retrieved from device */
1812 sizeof(*phc->virt_addr),
1813 phc->virt_addr,
1814 phc->phys_addr,
1815 phc->mem_handle);
1816 if (unlikely(!phc->virt_addr))
1819 ENA_SPINLOCK_INIT(phc->lock);
1821 phc->virt_addr->req_id = 0;
1822 phc->virt_addr->timestamp = 0;
1829 struct ena_com_phc_info *phc = &ena_dev->phc;
1835 /* Get default device PHC configuration */
1841 ena_trc_err(ena_dev, "Failed to get PHC feature configuration, error: %d\n", ret);
1845 /* Supporting only PHC V0 (readless mode with error bound) */
1846 if (get_feat_resp.u.phc.version != ENA_ADMIN_PHC_FEATURE_VERSION_0) {
1847 ena_trc_err(ena_dev, "Unsupprted PHC version (0x%X), error: %d\n",
1848 get_feat_resp.u.phc.version,
1853 /* Update PHC doorbell offset according to device value, used to write req_id to PHC bar */
1854 phc->doorbell_offset = get_feat_resp.u.phc.doorbell_offset;
1856 /* Update PHC expire timeout according to device or default driver value */
1857 phc->expire_timeout_usec = (get_feat_resp.u.phc.expire_timeout_usec) ?
1858 get_feat_resp.u.phc.expire_timeout_usec :
1861 /* Update PHC block timeout according to device or default driver value */
1862 phc->block_timeout_usec = (get_feat_resp.u.phc.block_timeout_usec) ?
1863 get_feat_resp.u.phc.block_timeout_usec :
1867 if (phc->expire_timeout_usec > phc->block_timeout_usec)
1868 phc->expire_timeout_usec = phc->block_timeout_usec;
1870 /* Prepare PHC config feature command */
1874 set_feat_cmd.u.phc.output_length = sizeof(*phc->virt_addr);
1875 ret = ena_com_mem_addr_set(ena_dev, &set_feat_cmd.u.phc.output_address, phc->phys_addr);
1877 ena_trc_err(ena_dev, "Failed setting PHC output address, error: %d\n", ret);
1881 /* Send PHC feature command to the device */
1889 ena_trc_err(ena_dev, "Failed to enable PHC, error: %d\n", ret);
1893 phc->active = true;
1894 ena_trc_dbg(ena_dev, "PHC is active in the device\n");
1901 struct ena_com_phc_info *phc = &ena_dev->phc;
1904 /* In case PHC is not supported by the device, silently exiting */
1905 if (!phc->virt_addr)
1908 ENA_SPINLOCK_LOCK(phc->lock, flags);
1909 phc->active = false;
1910 ENA_SPINLOCK_UNLOCK(phc->lock, flags);
1913 sizeof(*phc->virt_addr),
1914 phc->virt_addr,
1915 phc->phys_addr,
1916 phc->mem_handle);
1917 phc->virt_addr = NULL;
1919 ENA_SPINLOCK_DESTROY(phc->lock);
1924 volatile struct ena_admin_phc_resp *read_resp = ena_dev->phc.virt_addr;
1926 struct ena_com_phc_info *phc = &ena_dev->phc;
1932 if (!phc->active) {
1933 ena_trc_err(ena_dev, "PHC feature is not active in the device\n");
1937 ENA_SPINLOCK_LOCK(phc->lock, flags);
1939 /* Check if PHC is in blocked state */
1940 if (unlikely(ENA_TIME_COMPARE_HIGH_RES(phc->system_time, zero_system_time))) {
1942 block_time = ENA_GET_SYSTEM_TIMEOUT_HIGH_RES(phc->system_time,
1943 phc->block_timeout_usec);
1945 /* PHC is still in blocked state, skip PHC request */
1946 phc->stats.phc_skp++;
1951 /* PHC is in active state, update statistics according to req_id and error_flags */
1952 if ((READ_ONCE16(read_resp->req_id) != phc->req_id) ||
1957 phc->stats.phc_err++;
1960 phc->stats.phc_exp++;
1965 phc->system_time = ENA_GET_SYSTEM_TIME_HIGH_RES();
1966 block_time = ENA_GET_SYSTEM_TIMEOUT_HIGH_RES(phc->system_time, phc->block_timeout_usec);
1967 expire_time = ENA_GET_SYSTEM_TIMEOUT_HIGH_RES(phc->system_time, phc->expire_timeout_usec);
1969 /* We expect the device to return this req_id once the new PHC timestamp is updated */
1970 phc->req_id++;
1972 /* Initialize PHC shared memory with different req_id value to be able to identify once the
1975 read_resp->req_id = phc->req_id + ENA_PHC_REQ_ID_OFFSET;
1977 /* Writing req_id to PHC bar */
1978 ENA_REG_WRITE32(ena_dev->bus, phc->req_id, ena_dev->reg_bar + phc->doorbell_offset);
1983 /* Gave up waiting for updated req_id, PHC enters into blocked state until
1984 * passing blocking time, during this time any get PHC timestamp or
1987 phc->error_bound = ENA_PHC_MAX_ERROR_BOUND;
1993 if (READ_ONCE16(read_resp->req_id) != phc->req_id) {
1998 /* req_id was updated by the device which indicates that PHC timestamp, error_bound
2003 /* Retrieved timestamp or error bound errors, PHC enters into blocked state
2004 * until passing blocking time, during this time any get PHC timestamp or
2007 phc->error_bound = ENA_PHC_MAX_ERROR_BOUND;
2012 /* PHC timestamp value is returned to the caller */
2016 phc->error_bound = read_resp->error_bound;
2018 /* Update statistic on valid PHC timestamp retrieval */
2019 phc->stats.phc_cnt++;
2021 /* This indicates PHC state is active */
2022 phc->system_time = zero_system_time;
2027 ENA_SPINLOCK_UNLOCK(phc->lock, flags);
2034 struct ena_com_phc_info *phc = &ena_dev->phc;
2035 u32 local_error_bound = phc->error_bound;
2037 if (!phc->active) {
2038 ena_trc_err(ena_dev, "PHC feature is not active in the device\n");