drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_ptp.c
Source file repositories/reference/linux-study-clean/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_ptp.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_ptp.c- Extension
.c- Size
- 14688 bytes
- Lines
- 561
- Domain
- Driver Families
- Bucket
- drivers/net
- Inferred role
- Driver Families: implementation source
- Status
- source 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.
- Uses kernel synchronization; read lock ordering, sleepability, and interrupt context assumptions before translating.
- Allocates kernel memory; connect allocation flags and lifetime to context constraints.
- Defines or uses C structs; map object ownership, embedded links, reference counts, and lock ownership.
Dependency Surface
linux/skbuff.hlinux/string_choices.hhclge_main.hhnae3.h
Detected Declarations
function hclge_ptp_get_cyclefunction hclge_ptp_adjfinefunction hclge_ptp_set_tx_infofunction hclge_ptp_clean_tx_hwtsfunction hclge_ptp_get_rx_hwtsfunction hclge_ptp_gettimexfunction hclge_ptp_settimefunction hclge_ptp_adjtimefunction hclge_ptp_get_cfgfunction hclge_ptp_int_enfunction hclge_ptp_cfg_qryfunction hclge_ptp_cfgfunction hclge_ptp_set_tx_modefunction hclge_ptp_set_rx_modefunction hclge_ptp_set_ts_modefunction hclge_ptp_set_cfgfunction hclge_ptp_get_ts_infofunction hclge_ptp_create_clockfunction hclge_ptp_destroy_clockfunction hclge_ptp_initfunction hclge_ptp_uninit
Annotated Snippet
test_and_set_bit(HCLGE_STATE_PTP_TX_HANDLING, &hdev->state)) {
ptp->tx_skipped++;
return false;
}
ptp->tx_start = jiffies;
ptp->tx_skb = skb_get(skb);
ptp->tx_cnt++;
return true;
}
void hclge_ptp_clean_tx_hwts(struct hclge_dev *hdev)
{
struct sk_buff *skb = hdev->ptp->tx_skb;
struct skb_shared_hwtstamps hwts;
u32 hi, lo;
u64 ns;
ns = readl(hdev->ptp->io_base + HCLGE_PTP_TX_TS_NSEC_REG) &
HCLGE_PTP_TX_TS_NSEC_MASK;
lo = readl(hdev->ptp->io_base + HCLGE_PTP_TX_TS_SEC_L_REG);
hi = readl(hdev->ptp->io_base + HCLGE_PTP_TX_TS_SEC_H_REG) &
HCLGE_PTP_TX_TS_SEC_H_MASK;
hdev->ptp->last_tx_seqid = readl(hdev->ptp->io_base +
HCLGE_PTP_TX_TS_SEQID_REG);
if (skb) {
hdev->ptp->tx_skb = NULL;
hdev->ptp->tx_cleaned++;
ns += (((u64)hi) << 32 | lo) * NSEC_PER_SEC;
hwts.hwtstamp = ns_to_ktime(ns);
skb_tstamp_tx(skb, &hwts);
dev_kfree_skb_any(skb);
}
clear_bit(HCLGE_STATE_PTP_TX_HANDLING, &hdev->state);
}
void hclge_ptp_get_rx_hwts(struct hnae3_handle *handle, struct sk_buff *skb,
u32 nsec, u32 sec)
{
struct hclge_vport *vport = hclge_get_vport(handle);
struct hclge_dev *hdev = vport->back;
unsigned long flags;
u64 ns = nsec;
u32 sec_h;
if (!hdev->ptp || !test_bit(HCLGE_PTP_FLAG_RX_EN, &hdev->ptp->flags))
return;
/* Since the BD does not have enough space for the higher 16 bits of
* second, and this part will not change frequently, so read it
* from register.
*/
spin_lock_irqsave(&hdev->ptp->lock, flags);
sec_h = readl(hdev->ptp->io_base + HCLGE_PTP_CUR_TIME_SEC_H_REG);
spin_unlock_irqrestore(&hdev->ptp->lock, flags);
ns += (((u64)sec_h) << HCLGE_PTP_SEC_H_OFFSET | sec) * NSEC_PER_SEC;
skb_hwtstamps(skb)->hwtstamp = ns_to_ktime(ns);
hdev->ptp->last_rx = jiffies;
hdev->ptp->rx_cnt++;
}
static int hclge_ptp_gettimex(struct ptp_clock_info *ptp, struct timespec64 *ts,
struct ptp_system_timestamp *sts)
{
struct hclge_dev *hdev = hclge_ptp_get_hdev(ptp);
unsigned long flags;
u32 hi, lo;
u64 ns;
spin_lock_irqsave(&hdev->ptp->lock, flags);
ns = readl(hdev->ptp->io_base + HCLGE_PTP_CUR_TIME_NSEC_REG);
hi = readl(hdev->ptp->io_base + HCLGE_PTP_CUR_TIME_SEC_H_REG);
lo = readl(hdev->ptp->io_base + HCLGE_PTP_CUR_TIME_SEC_L_REG);
spin_unlock_irqrestore(&hdev->ptp->lock, flags);
ns += (((u64)hi) << HCLGE_PTP_SEC_H_OFFSET | lo) * NSEC_PER_SEC;
*ts = ns_to_timespec64(ns);
return 0;
}
static int hclge_ptp_settime(struct ptp_clock_info *ptp,
const struct timespec64 *ts)
{
struct hclge_dev *hdev = hclge_ptp_get_hdev(ptp);
Annotation
- Immediate include surface: `linux/skbuff.h`, `linux/string_choices.h`, `hclge_main.h`, `hnae3.h`.
- Detected declarations: `function hclge_ptp_get_cycle`, `function hclge_ptp_adjfine`, `function hclge_ptp_set_tx_info`, `function hclge_ptp_clean_tx_hwts`, `function hclge_ptp_get_rx_hwts`, `function hclge_ptp_gettimex`, `function hclge_ptp_settime`, `function hclge_ptp_adjtime`, `function hclge_ptp_get_cfg`, `function hclge_ptp_int_en`.
- Atlas domain: Driver Families / drivers/net.
- Implementation status: source implementation candidate.
- Synchronization appears in or near this file; preserve lock ordering, sleepability, and interrupt-context constraints.
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.