drivers/net/ethernet/chelsio/cxgb4/cxgb4_ptp.c
Source file repositories/reference/linux-study-clean/drivers/net/ethernet/chelsio/cxgb4/cxgb4_ptp.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/net/ethernet/chelsio/cxgb4/cxgb4_ptp.c- Extension
.c- Size
- 13311 bytes
- Lines
- 469
- 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.
- Defines or uses C structs; map object ownership, embedded links, reference counts, and lock ownership.
Dependency Surface
linux/module.hlinux/net_tstamp.hlinux/skbuff.hlinux/netdevice.hlinux/pps_kernel.hlinux/ptp_clock_kernel.hlinux/ptp_classify.hlinux/udp.hcxgb4.ht4_hw.ht4_regs.ht4_msg.ht4fw_api.hcxgb4_ptp.h
Detected Declarations
function Copyrightfunction is_ptp_enabledfunction cxgb4_ptp_is_ptp_rxfunction cxgb4_ptp_read_hwstampfunction cxgb4_ptprx_timestampingfunction cxgb4_ptp_txtypefunction cxgb4_ptp_redirect_rx_packetfunction cxgb4_ptp_adjfinefunction cxgb4_ptp_fineadjtimefunction cxgb4_ptp_adjtimefunction cxgb4_ptp_gettimefunction cxgb4_ptp_settimefunction cxgb4_init_ptp_timerfunction Enablefunction cxgb4_ptp_initfunction cxgb4_ptp_stop
Annotated Snippet
#include <linux/module.h>
#include <linux/net_tstamp.h>
#include <linux/skbuff.h>
#include <linux/netdevice.h>
#include <linux/pps_kernel.h>
#include <linux/ptp_clock_kernel.h>
#include <linux/ptp_classify.h>
#include <linux/udp.h>
#include "cxgb4.h"
#include "t4_hw.h"
#include "t4_regs.h"
#include "t4_msg.h"
#include "t4fw_api.h"
#include "cxgb4_ptp.h"
/**
* cxgb4_ptp_is_ptp_tx - determine whether TX packet is PTP or not
* @skb: skb of outgoing ptp request
*
*/
bool cxgb4_ptp_is_ptp_tx(struct sk_buff *skb)
{
struct udphdr *uh;
uh = udp_hdr(skb);
return skb->len >= PTP_MIN_LENGTH &&
skb->len <= PTP_IN_TRANSMIT_PACKET_MAXNUM &&
likely(skb->protocol == htons(ETH_P_IP)) &&
ip_hdr(skb)->protocol == IPPROTO_UDP &&
uh->dest == htons(PTP_EVENT_PORT);
}
bool is_ptp_enabled(struct sk_buff *skb, struct net_device *dev)
{
struct port_info *pi;
pi = netdev_priv(dev);
return (pi->ptp_enable && cxgb4_xmit_with_hwtstamp(skb) &&
cxgb4_ptp_is_ptp_tx(skb));
}
/**
* cxgb4_ptp_is_ptp_rx - determine whether RX packet is PTP or not
* @skb: skb of incoming ptp request
*
*/
bool cxgb4_ptp_is_ptp_rx(struct sk_buff *skb)
{
struct udphdr *uh = (struct udphdr *)(skb->data + ETH_HLEN +
IPV4_HLEN(skb->data));
return uh->dest == htons(PTP_EVENT_PORT) &&
uh->source == htons(PTP_EVENT_PORT);
}
/**
* cxgb4_ptp_read_hwstamp - read timestamp for TX event PTP message
* @adapter: board private structure
* @pi: port private structure
*
*/
void cxgb4_ptp_read_hwstamp(struct adapter *adapter, struct port_info *pi)
{
struct skb_shared_hwtstamps *skb_ts = NULL;
u64 tx_ts;
skb_ts = skb_hwtstamps(adapter->ptp_tx_skb);
tx_ts = t4_read_reg(adapter,
T5_PORT_REG(pi->port_id, MAC_PORT_TX_TS_VAL_LO));
tx_ts |= (u64)t4_read_reg(adapter,
T5_PORT_REG(pi->port_id,
MAC_PORT_TX_TS_VAL_HI)) << 32;
skb_ts->hwtstamp = ns_to_ktime(tx_ts);
skb_tstamp_tx(adapter->ptp_tx_skb, skb_ts);
dev_kfree_skb_any(adapter->ptp_tx_skb);
spin_lock(&adapter->ptp_lock);
adapter->ptp_tx_skb = NULL;
spin_unlock(&adapter->ptp_lock);
}
/**
* cxgb4_ptprx_timestamping - Enable Timestamp for RX PTP event message
* @pi: port private structure
* @port: pot number
* @mode: RX mode
*
*/
Annotation
- Immediate include surface: `linux/module.h`, `linux/net_tstamp.h`, `linux/skbuff.h`, `linux/netdevice.h`, `linux/pps_kernel.h`, `linux/ptp_clock_kernel.h`, `linux/ptp_classify.h`, `linux/udp.h`.
- Detected declarations: `function Copyright`, `function is_ptp_enabled`, `function cxgb4_ptp_is_ptp_rx`, `function cxgb4_ptp_read_hwstamp`, `function cxgb4_ptprx_timestamping`, `function cxgb4_ptp_txtype`, `function cxgb4_ptp_redirect_rx_packet`, `function cxgb4_ptp_adjfine`, `function cxgb4_ptp_fineadjtime`, `function cxgb4_ptp_adjtime`.
- 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.