Lines Matching full:phc

44 /* PHC definitions */
1657 struct ena_com_phc_info *phc = &ena_dev->phc; in ena_com_phc_init() local
1659 memset(phc, 0x0, sizeof(*phc)); in ena_com_phc_init()
1661 /* Allocate shared mem used PHC timestamp retrieved from device */ in ena_com_phc_init()
1662 phc->virt_addr = dma_alloc_coherent(ena_dev->dmadev, in ena_com_phc_init()
1663 sizeof(*phc->virt_addr), in ena_com_phc_init()
1664 &phc->phys_addr, in ena_com_phc_init()
1666 if (unlikely(!phc->virt_addr)) in ena_com_phc_init()
1669 spin_lock_init(&phc->lock); in ena_com_phc_init()
1671 phc->virt_addr->req_id = 0; in ena_com_phc_init()
1672 phc->virt_addr->timestamp = 0; in ena_com_phc_init()
1679 struct ena_com_phc_info *phc = &ena_dev->phc; in ena_com_phc_config() local
1685 /* Get device PHC default configuration */ in ena_com_phc_config()
1692 "Failed to get PHC feature configuration, error: %d\n", in ena_com_phc_config()
1697 /* Supporting only readless PHC retrieval */ in ena_com_phc_config()
1698 if (get_feat_resp.u.phc.type != ENA_ADMIN_PHC_TYPE_READLESS) { in ena_com_phc_config()
1700 "Unsupported PHC type, error: %d\n", in ena_com_phc_config()
1705 /* Update PHC doorbell offset according to device value, in ena_com_phc_config()
1706 * used to write req_id to PHC bar in ena_com_phc_config()
1708 phc->doorbell_offset = get_feat_resp.u.phc.doorbell_offset; in ena_com_phc_config()
1710 /* Update PHC expire timeout according to device in ena_com_phc_config()
1713 phc->expire_timeout_usec = (get_feat_resp.u.phc.expire_timeout_usec) ? in ena_com_phc_config()
1714 get_feat_resp.u.phc.expire_timeout_usec : in ena_com_phc_config()
1717 /* Update PHC block timeout according to device in ena_com_phc_config()
1720 phc->block_timeout_usec = (get_feat_resp.u.phc.block_timeout_usec) ? in ena_com_phc_config()
1721 get_feat_resp.u.phc.block_timeout_usec : in ena_com_phc_config()
1725 if (phc->expire_timeout_usec > phc->block_timeout_usec) in ena_com_phc_config()
1726 phc->expire_timeout_usec = phc->block_timeout_usec; in ena_com_phc_config()
1728 /* Prepare PHC feature command */ in ena_com_phc_config()
1732 set_feat_cmd.u.phc.output_length = sizeof(*phc->virt_addr); in ena_com_phc_config()
1734 &set_feat_cmd.u.phc.output_address, in ena_com_phc_config()
1735 phc->phys_addr); in ena_com_phc_config()
1738 "Failed setting PHC output address, error: %d\n", in ena_com_phc_config()
1743 /* Send PHC feature command to the device */ in ena_com_phc_config()
1752 "Failed to enable PHC, error: %d\n", in ena_com_phc_config()
1757 phc->active = true; in ena_com_phc_config()
1758 netdev_dbg(ena_dev->net_device, "PHC is active in the device\n"); in ena_com_phc_config()
1765 struct ena_com_phc_info *phc = &ena_dev->phc; in ena_com_phc_destroy() local
1768 /* In case PHC is not supported by the device, silently exiting */ in ena_com_phc_destroy()
1769 if (!phc->virt_addr) in ena_com_phc_destroy()
1772 spin_lock_irqsave(&phc->lock, flags); in ena_com_phc_destroy()
1773 phc->active = false; in ena_com_phc_destroy()
1774 spin_unlock_irqrestore(&phc->lock, flags); in ena_com_phc_destroy()
1777 sizeof(*phc->virt_addr), in ena_com_phc_destroy()
1778 phc->virt_addr, in ena_com_phc_destroy()
1779 phc->phys_addr); in ena_com_phc_destroy()
1780 phc->virt_addr = NULL; in ena_com_phc_destroy()
1785 volatile struct ena_admin_phc_resp *resp = ena_dev->phc.virt_addr; in ena_com_phc_get_timestamp()
1787 struct ena_com_phc_info *phc = &ena_dev->phc; in ena_com_phc_get_timestamp() local
1793 if (!phc->active) { in ena_com_phc_get_timestamp()
1794 netdev_err(ena_dev->net_device, "PHC feature is not active in the device\n"); in ena_com_phc_get_timestamp()
1798 spin_lock_irqsave(&phc->lock, flags); in ena_com_phc_get_timestamp()
1800 /* Check if PHC is in blocked state */ in ena_com_phc_get_timestamp()
1801 if (unlikely(ktime_compare(phc->system_time, zero_system_time))) { in ena_com_phc_get_timestamp()
1803 block_time = ktime_add_us(phc->system_time, phc->block_timeout_usec); in ena_com_phc_get_timestamp()
1805 /* PHC is still in blocked state, skip PHC request */ in ena_com_phc_get_timestamp()
1806 phc->stats.phc_skp++; in ena_com_phc_get_timestamp()
1811 /* PHC is in active state, update statistics according in ena_com_phc_get_timestamp()
1814 if (READ_ONCE(resp->req_id) != phc->req_id) { in ena_com_phc_get_timestamp()
1819 "PHC get time request 0x%x failed (device error)\n", in ena_com_phc_get_timestamp()
1820 phc->req_id); in ena_com_phc_get_timestamp()
1821 phc->stats.phc_err_dv++; in ena_com_phc_get_timestamp()
1824 * a PHC error, this occurs if device: in ena_com_phc_get_timestamp()
1829 "PHC get time request 0x%x failed (error 0x%x)\n", in ena_com_phc_get_timestamp()
1830 phc->req_id, in ena_com_phc_get_timestamp()
1832 phc->stats.phc_err_ts += !!(resp->error_flags & in ena_com_phc_get_timestamp()
1838 phc->stats.phc_exp++; in ena_com_phc_get_timestamp()
1843 phc->system_time = ktime_get(); in ena_com_phc_get_timestamp()
1844 block_time = ktime_add_us(phc->system_time, phc->block_timeout_usec); in ena_com_phc_get_timestamp()
1845 expire_time = ktime_add_us(phc->system_time, phc->expire_timeout_usec); in ena_com_phc_get_timestamp()
1848 * the new PHC timestamp is updated in ena_com_phc_get_timestamp()
1850 phc->req_id++; in ena_com_phc_get_timestamp()
1852 /* Initialize PHC shared memory with different req_id value in ena_com_phc_get_timestamp()
1855 resp->req_id = phc->req_id + ENA_PHC_REQ_ID_OFFSET; in ena_com_phc_get_timestamp()
1857 /* Writing req_id to PHC bar */ in ena_com_phc_get_timestamp()
1858 writel(phc->req_id, ena_dev->reg_bar + phc->doorbell_offset); in ena_com_phc_get_timestamp()
1863 /* Gave up waiting for updated req_id, PHC enters into in ena_com_phc_get_timestamp()
1865 * during this time any get PHC timestamp will fail with in ena_com_phc_get_timestamp()
1873 if (READ_ONCE(resp->req_id) != phc->req_id) { in ena_com_phc_get_timestamp()
1881 * PHC timestamp and error_flags are updated too, in ena_com_phc_get_timestamp()
1885 /* Retrieved invalid PHC timestamp, PHC enters into in ena_com_phc_get_timestamp()
1887 * during this time any get PHC timestamp requests in ena_com_phc_get_timestamp()
1894 /* PHC timestamp value is returned to the caller */ in ena_com_phc_get_timestamp()
1897 /* Update statistic on valid PHC timestamp retrieval */ in ena_com_phc_get_timestamp()
1898 phc->stats.phc_cnt++; in ena_com_phc_get_timestamp()
1900 /* This indicates PHC state is active */ in ena_com_phc_get_timestamp()
1901 phc->system_time = zero_system_time; in ena_com_phc_get_timestamp()
1906 spin_unlock_irqrestore(&phc->lock, flags); in ena_com_phc_get_timestamp()