drivers/net/ethernet/mellanox/mlx5/core/en/ptp.c
Source file repositories/reference/linux-study-clean/drivers/net/ethernet/mellanox/mlx5/core/en/ptp.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/net/ethernet/mellanox/mlx5/core/en/ptp.c- Extension
.c- Size
- 26806 bytes
- Lines
- 1036
- 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
en/ptp.hen/health.hen/txrx.hen/params.hen/fs_tt_redirect.hlinux/list.hlinux/spinlock.hnet/netdev_lock.h
Detected Declarations
struct mlx5e_ptp_fsstruct mlx5e_ptp_paramsstruct mlx5e_ptp_port_ts_cqe_trackerstruct mlx5e_ptp_port_ts_cqe_liststruct mlx5e_skb_cb_hwtstampfunction mlx5e_ptp_port_ts_cqe_list_addfunction mlx5e_ptp_port_ts_cqe_list_removefunction mlx5e_ptpsq_track_metadatafunction mlx5e_skb_cb_hwtstamp_initfunction mlx5e_skb_cb_hwtstamp_txfunction mlx5e_skb_cb_hwtstamp_handlerfunction mlx5e_ptp_metadata_map_lookupfunction mlx5e_ptp_metadata_map_removefunction mlx5e_ptp_metadata_map_unhealthyfunction mlx5e_ptpsq_mark_ts_cqes_undeliveredfunction mlx5e_ptp_handle_ts_cqefunction mlx5e_ptp_poll_ts_cqfunction mlx5e_ptp_napi_pollfunction mlx5e_ptp_alloc_txqsqfunction mlx5e_ptp_destroy_sqfunction mlx5e_ptp_alloc_traffic_dbfunction mlx5e_ptp_drain_metadata_mapfunction mlx5e_ptp_free_traffic_dbfunction mlx5e_ptpsq_unhealthy_workfunction mlx5e_ptp_open_txqsqfunction mlx5e_ptp_close_txqsqfunction mlx5e_ptp_open_txqsqsfunction mlx5e_ptp_close_txqsqsfunction mlx5e_ptp_open_tx_cqsfunction mlx5e_ptp_open_rx_cqfunction mlx5e_ptp_close_tx_cqsfunction mlx5e_ptp_build_sq_paramfunction mlx5e_ptp_build_rq_paramfunction mlx5e_ptp_build_paramsfunction mlx5e_init_ptp_rqfunction mlx5e_ptp_open_rqfunction mlx5e_ptp_open_queuesfunction mlx5e_ptp_close_queuesfunction mlx5e_ptp_set_statefunction mlx5e_ptp_rx_unset_fsfunction mlx5e_ptp_rx_set_fsfunction mlx5e_ptp_openfunction mlx5e_ptp_closefunction mlx5e_ptp_activate_channelfunction mlx5e_ptp_deactivate_channelfunction mlx5e_ptp_get_rqnfunction mlx5e_ptp_alloc_rx_fsfunction mlx5e_ptp_free_rx_fs
Annotated Snippet
struct mlx5e_ptp_fs {
struct mlx5_flow_handle *l2_rule;
struct mlx5_flow_handle *udp_v4_rule;
struct mlx5_flow_handle *udp_v6_rule;
bool valid;
};
struct mlx5e_ptp_params {
struct mlx5e_params params;
struct mlx5e_sq_param txq_sq_param;
struct mlx5e_rq_param rq_param;
};
struct mlx5e_ptp_port_ts_cqe_tracker {
u8 metadata_id;
bool inuse : 1;
struct list_head entry;
};
struct mlx5e_ptp_port_ts_cqe_list {
struct mlx5e_ptp_port_ts_cqe_tracker *nodes;
struct list_head tracker_list_head;
/* Sync list operations in xmit and napi_poll contexts */
spinlock_t tracker_list_lock;
};
static inline void
mlx5e_ptp_port_ts_cqe_list_add(struct mlx5e_ptp_port_ts_cqe_list *list, u8 metadata)
{
struct mlx5e_ptp_port_ts_cqe_tracker *tracker = &list->nodes[metadata];
WARN_ON_ONCE(tracker->inuse);
tracker->inuse = true;
spin_lock_bh(&list->tracker_list_lock);
list_add_tail(&tracker->entry, &list->tracker_list_head);
spin_unlock_bh(&list->tracker_list_lock);
}
static void
mlx5e_ptp_port_ts_cqe_list_remove(struct mlx5e_ptp_port_ts_cqe_list *list, u8 metadata)
{
struct mlx5e_ptp_port_ts_cqe_tracker *tracker = &list->nodes[metadata];
WARN_ON_ONCE(!tracker->inuse);
tracker->inuse = false;
spin_lock_bh(&list->tracker_list_lock);
list_del(&tracker->entry);
spin_unlock_bh(&list->tracker_list_lock);
}
void mlx5e_ptpsq_track_metadata(struct mlx5e_ptpsq *ptpsq, u8 metadata)
{
mlx5e_ptp_port_ts_cqe_list_add(ptpsq->ts_cqe_pending_list, metadata);
}
struct mlx5e_skb_cb_hwtstamp {
ktime_t cqe_hwtstamp;
ktime_t port_hwtstamp;
};
void mlx5e_skb_cb_hwtstamp_init(struct sk_buff *skb)
{
memset(skb->cb, 0, sizeof(struct mlx5e_skb_cb_hwtstamp));
}
static struct mlx5e_skb_cb_hwtstamp *mlx5e_skb_cb_get_hwts(struct sk_buff *skb)
{
BUILD_BUG_ON(sizeof(struct mlx5e_skb_cb_hwtstamp) > sizeof(skb->cb));
return (struct mlx5e_skb_cb_hwtstamp *)skb->cb;
}
static void mlx5e_skb_cb_hwtstamp_tx(struct sk_buff *skb,
struct mlx5e_ptpsq *ptpsq)
{
struct skb_shared_hwtstamps hwts = {};
ktime_t diff;
diff = abs(mlx5e_skb_cb_get_hwts(skb)->port_hwtstamp -
mlx5e_skb_cb_get_hwts(skb)->cqe_hwtstamp);
/* Maximal allowed diff is 1 / 128 second */
if (diff > (NSEC_PER_SEC >> 7)) {
struct mlx5e_txqsq *sq = &ptpsq->txqsq;
ptpsq->cq_stats->abort++;
ptpsq->cq_stats->abort_abs_diff_ns += diff;
if (diff > (NSEC_PER_SEC >> 1) &&
!test_and_set_bit(MLX5E_SQ_STATE_RECOVERING, &sq->state)) {
netdev_warn(sq->channel->netdev,
"PTP TX timestamp difference between CQE and port exceeds threshold: %lld ns, recovering SQ %u\n",
Annotation
- Immediate include surface: `en/ptp.h`, `en/health.h`, `en/txrx.h`, `en/params.h`, `en/fs_tt_redirect.h`, `linux/list.h`, `linux/spinlock.h`, `net/netdev_lock.h`.
- Detected declarations: `struct mlx5e_ptp_fs`, `struct mlx5e_ptp_params`, `struct mlx5e_ptp_port_ts_cqe_tracker`, `struct mlx5e_ptp_port_ts_cqe_list`, `struct mlx5e_skb_cb_hwtstamp`, `function mlx5e_ptp_port_ts_cqe_list_add`, `function mlx5e_ptp_port_ts_cqe_list_remove`, `function mlx5e_ptpsq_track_metadata`, `function mlx5e_skb_cb_hwtstamp_init`, `function mlx5e_skb_cb_hwtstamp_tx`.
- 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.