net: atlantic: add PTP support for AQC113 (Antigua)
Subsystems (4)
[email protected]
maintainerv4 cover net: atlantic: add PTP support for AQC113 (Antigua)
From: Sukhdeep Singh <[email protected]>
This series adds IEEE 1588 PTP support for the AQC113 (Antigua) network controller. AQC113 is the successor to the existing AQC107 (Atlantic) chip already supported by the atlantic driver.
AQC113 uses a substantially different hardware architecture for PTP compared to AQC107:
- Dual on-chip TSG clocks with direct register access instead of PHY-based timestamping via firmware
- TX timestamps via descriptor writeback instead of firmware mailbox
- Hardware L3/L4 RX filters for PTP multicast steering with both IPv4 and IPv6 support
- Reference-counted shared filter slots managed through an Action Resolver Table (ART), allowing multiple rules to share L3/L4 hardware filters when their match criteria are identical
The series is structured in four parts:
Patches 1-3 prepare the existing L3/L4 filter path:
Patch 1 corrects flow_type masking and IPv6 address handling in aq_set_data_fl3l4(). Patch 2 moves the active_ipv4/ipv6 bitmap updates to after the hardware write succeeds. Patch 3 decouples the function from driver-internal structures so it can be called directly by the AQC113 PTP filter setup code.
Patches 4-5 add the AQC113 hardware infrastructure:
Patch 4 adds the low-level register definitions and accessor functions. Patch 5 adds filter data structures and firmware capability query.
Patches 6-7 implement the AQC113 L2/L3/L4 RX filter management:
Patch 6 fixes the AQC113 HW init path: ART section selection, L2 filter slot assignment, and MAC address programming. Patch 7 implements the complete L3/L4 RX filter ops including reference- counted ART sharing and IPv4/IPv6 steering.
Patches 8-12 add the AQC113 PTP feature:
Patch 8 reserves the dedicated PTP traffic class buffer and configures the TX path. Patch 9 extends the hw_ops interface with PTP-specific function pointers and updates AQC107 to the new signatures. Patches 10-12 implement the full PTP subsystem:
Patch 10 adds the hw_atl2 register-level PTP clock ops, Patch 11 adds TX timestamp polling and PTP TX traffic classification, and Patch 12 integrates PTP into aq_ptp and the driver core.
The existing AQC107 PTP implementation is not functionally changed by this series; AQC113-specific code paths are gated on chip detection throughout.
Tested on AQC113 at 1G, 2.5G, 5G, and 10G link speeds using ptp4l/phc2sys with hardware timestamping in both L2 and L4 (IPv4/IPv6) modes.
Changes in v4:
Patch 6:
- Fix commit message: the selective memset replaces the unconditional memset(priv, 0) specifically to allow -1 sentinel initialization for l3l4_filters[i].l3_index/l4_index, since 0 is a valid filter index; the previous "preserve firmware layout" rationale was inaccurate as hw_atl2_utils_get_filter_caps() repopulates those fields unconditionally after reset
- Add art_mask == 0 fallback: if FW reports rslv_tbl_base_index >= 16, both clamped section values collapse to 16 and art_mask becomes 0; add guard to fall back to 0xFFFF in that case to avoid disabling the entire Action Resolver Table
- Add l2_filters_base_index bounds check in hw_atl2_utils_get_filter_caps(): clamp to HW_ATL2_MAC_UC if >= HW_ATL2_MAC_MAX, protecting all three consumer sites (hw_atl2_hw_init_new_rx_filters, hw_atl2_hw_init_rx_path, hw_atl2_hw_mac_addr_set) from out-of-range MMIO access
Patch 10:
- Declare hw_atl2_txts_s::ctrl as __le32 (was u32) and add le32_to_cpu() in hw_ring_tx_ptp_get_ts for correct big-endian portability
Patch 11:
- Fix timeout path in aq_ring_tx_clean(): add goto out after buff->skb = NULL to prevent fall-through to aq_ptp_tx_hwtstamp() with a freed skb, which would report a bogus zero timestamp
- Move aq_reapply_rxnfc_all_rules() and aq_filters_vlans_update() removal from aq_ndev_open() and addition to aq_nic_start() into this patch; previously the removal was in patch 11 and the addition in patch 12, leaving a bisect window where filters were dropped but not yet restored
Patch 12:
- Move dx_buff->skb = skb and dx_buff->xdpf = NULL before the PTP timestamp block in aq_nic_map_skb() to prevent skb leak and potential use-after-free when hw_get_clk_sel() returns negative
- Clear all existing L3L4 hardware filters at the start of the if (enable_flags) path in aq_ptp_dpath_enable() to prevent stale L4 filters remaining active when reconfiguring from L2+L4 to L2-only
- Update aq_ptp->hwtstamp_config inside ptp_filter_lock on success to prevent aq_ptp_clock_init() on a concurrent link bounce from reading a stale software filter state
Changes in v3:
Structural (suggested by Paolo Abeni):
- Split old patch 6 into two patches: patch 6 now covers the AQC113 HW init fixes (ART section selection, L2 filter slot, MAC address), and patch 7 covers the L2/L3/L4 RX filter ops
- Split old patch 9 into three patches: patch 10 covers hw_atl2 PTP register ops, patch 11 covers TX timestamp polling and PTP TX classification, and patch 12 covers aq_ptp and driver core integration
Patch 2:
- Fix commit message: remove incorrect claim that bitmap updates are removed from aq_nic_reserve_filter() and aq_nic_release_filter(); the updates are intentionally retained there to support the AQC113 PTP path which programs filters directly without going through aq_add_del_fl3l4()
Patch 5:
- Clamp mac_regs_count loop bound with min_t(ARRAY_SIZE) to prevent out-of-bounds reads if firmware reports an inflated count
- Add base_index overflow check for l3_v6_filter_count (was missing, already present for l3_v4 and l4 categories)
Patches 6-7 (old patch 6):
- Drop unused hw_get_version op from hw_atl2_ops
- Clamp art_first_sec/art_last_sec to 16 before BIT() to avoid shift-past-width UB on section indices >= 32
- Fix hw_atl2_hw_init() to call hw_atl2_hw_mac_addr_set() instead of the A1 function hw_atl_b0_hw_mac_addr_set()
- Fix hw_atl2_hw_init_rx_path() to enable the l2_filters_base_index slot rather than a hardcoded slot 0
- Fix L3 filter family-switch undo path: remove cross-family pointer aliasing; add a guard that aborts reconfiguration when the address family changes and the old slot is still in use
Patch 8 (old patch 7):
- Remove unconditional accept_all_mc enable: per-multicast L2 filter handles PTP multicast steering; accept_all caused non-PTP multicast traffic to receive false timestamps
- Fix commit message: PCIe extended tag enablement is unconditional for AQC113 when firmware has enabled the feature, not gated on PTP
Patches 10-12 (old patch 9):
- Initialize clk_select = -1 in aq_pci_probe() instead of aq_nic_hw_prepare() so that the sentinel survives resume and hw_atl2_hw_reset() can distinguish uninitialised from active
- Add clk_sel < 0 guard in all TSG clock helpers (hw_atl2_tsg_clock_ read/add/sub/increment_set) to prevent out-of-range MMIO access during the window between ptp_clock_register() and hw_atl2_enable_ptp() setting clk_select to 0 or 1
- Use WRITE_ONCE/READ_ONCE for clk_select accesses in hw_atl2_enable_ptp() and ring init to prevent compiler tearing
- Add READ_ONCE(txts->ctrl) + dma_rmb() before reading txts->ts in hw_ring_tx_ptp_get_ts to prevent speculative load reordering on weakly-ordered architectures
- Declare hw_atl2_txts_s::ts as __le64 and use le64_to_cpu() for correct big-endian portability
- Fix teardown order in aq_ptp_free(): cancel_delayed_work_sync() must precede hw_atl2_enable_ptp(..., 0) to prevent the work item from re-arming itself after cancellation
- Add ptp_filter_lock mutex in both aq_ptp_clock_init() and aq_ptp_hwtstamp_config_set() to serialise concurrent filter enable/disable from link state changes and ioctl
- Gate hw_filter_l2_set on AQ_HW_PTP_L2_ENABLE flag in aq_ptp_dpath_enable() to prevent a spurious zero-ethertype L2 filter being installed when only L4 mode is active
- Fix error path in aq_ptp_ring_alloc() to use aq_ring_hwts_rx_free() instead of aq_ring_free() (wrong DMA size)
- Propagate PTP ring init return values from hw_atl2_hw_ring_rx_init() and hw_atl2_hw_ring_tx_init()
- Move skb_tx_timestamp() from aq_ndev_start_xmit() to aq_nic_xmit() after aq_nic_map_skb(), ensuring the SW timestamp is recorded after the DMA mapping is committed
- Remove AQ_HW_FLAG_STARTED flag: it has no reader in this series
- Remove stale references to aq_ptp_tx_ts_timedout/aq_ptp_tx_ts_clear (functions that do not exist); describe the actual timeout mechanism via ptp_ts_deadline in the commit message
- Document double-unmap prevention: buff->is_mapped and buff->pa are cleared before the ts==0 break, preventing a second DMA unmap on the next aq_ring_tx_clean() pass
- Update HW_ATL2_RXBUF_MAX comment: 172 is the AQC113 hardware maximum for data TCs (not a PTP-specific reduction)
Changes in v2:
- Patch 6: Remove redundant variable initializers for art_mask, h, l and err as suggested by Vadim Fedorenko
Sukhdeep Singh (12):
net: atlantic: correct L3L4 filter flow_type masking and IPv6 handling
net: atlantic: move active_ipv4/ipv6 bitmap updates after HW write
net: atlantic: decouple aq_set_data_fl3l4() from driver internals
net: atlantic: add AQC113 hardware register definitions and accessors
net: atlantic: add AQC113 filter data structures and firmware query
net: atlantic: fix AQC113 HW init: ART, L2 filter slot, MAC address
net: atlantic: implement AQC113 L2/L3/L4 RX filter ops
net: atlantic: add AQC113 PTP traffic class and TX path setup
net: atlantic: extend hw_ops and TX descriptor for AQC113 PTP
net: atlantic: add AQC113 PTP hardware ops in hw_atl2
net: atlantic: add AQC113 TX timestamp polling and PTP TX classification
net: atlantic: add AQC113 PTP support in aq_ptp and driver core
.../net/ethernet/aquantia/atlantic/aq_filters.c | 98 ++- .../net/ethernet/aquantia/atlantic/aq_filters.h | 3 + drivers/net/ethernet/aquantia/atlantic/aq_hw.h | 35 +- drivers/net/ethernet/aquantia/atlantic/aq_main.c | 30 +- drivers/net/ethernet/aquantia/atlantic/aq_nic.c | 53 +- .../net/ethernet/aquantia/atlantic/aq_pci_func.c | 5 +- drivers/net/ethernet/aquantia/atlantic/aq_ptp.c | 540 ++++++++++--- drivers/net/ethernet/aquantia/atlantic/aq_ptp.h | 15 +- drivers/net/ethernet/aquantia/atlantic/aq_ring.c | 22 +- drivers/net/ethernet/aquantia/atlantic/aq_ring.h | 5 +- .../ethernet/aquantia/atlantic/hw_atl/hw_atl_b0.c | 15 +- .../ethernet/aquantia/atlantic/hw_atl2/hw_atl2.c | 834 ++++++++++++++++++++- .../ethernet/aquantia/atlantic/hw_atl2/hw_atl2.h | 12 + .../aquantia/atlantic/hw_atl2/hw_atl2_internal.h | 68 +- .../aquantia/atlantic/hw_atl2/hw_atl2_llh.c | 359 +++++++++ .../aquantia/atlantic/hw_atl2/hw_atl2_llh.h | 107 ++- .../atlantic/hw_atl2/hw_atl2_llh_internal.h | 204 ++++- .../aquantia/atlantic/hw_atl2/hw_atl2_utils.c | 33 + .../aquantia/atlantic/hw_atl2/hw_atl2_utils.h | 15 + .../aquantia/atlantic/hw_atl2/hw_atl2_utils_fw.c | 52 ++ 20 files changed, 2287 insertions(+), 218 deletions(-)
Signature · 1 line
2.43.0
[email protected]
maintainerPATCH v4 1/12 net: atlantic: correct L3L4 filter flow_type masking and IPv6 handling
From: Sukhdeep Singh <[email protected]>
Correct three issues in aq_set_data_fl3l4() required for the AQC113 PTP filter path introduced later in this series:
1. Mask FLOW_EXT from flow_type before the protocol switch statement. Flow types with FLOW_EXT set (e.g. TCP_V4_FLOW | FLOW_EXT) fall through to the default case and skip protocol comparison flags.
2. Extend the L3 address comparison check to cover all four IPv6 words. The original code only checked ip_src[0]/ip_dst[0] and required !is_ipv6, so CMP_SRC_ADDR_L3/CMP_DEST_ADDR_L3 were never set for IPv6 filters.
3. Use explicit flow type checks for port extraction instead of negating IP_USER_FLOW/IPV6_USER_FLOW. The old check did not mask FLOW_EXT, so IP_USER_FLOW | FLOW_EXT would incorrectly attempt port extraction. Use the actual flow type to pick the correct union member directly.
--- .../ethernet/aquantia/atlantic/aq_filters.c | 33 ++++++++++--------- 1 file changed, 17 insertions(+), 16 deletions(-)
drivers/net/ethernet/aquantia/atlantic/aq_filters.c +17 -16
@@ -472,6 +472,7 @@ static int aq_set_data_fl3l4(struct aq_nic_s *aq_nic, {struct aq_hw_rx_fltrs_s *rx_fltrs =aq_get_hw_rx_fltrs (aq_nic);const struct ethtool_rx_flow_spec *fsp = &aq_rx_fltr->aq_fsp; +u32 flow = fsp->flow_type & ~FLOW_EXT ;memset (data,0 ,sizeof (*data));
@@ -490,7 +491,7 @@ static int aq_set_data_fl3l4(struct aq_nic_s *aq_nic, data->cmd |=HW_ATL_RX_ENABLE_FLTR_L3L4 ; -switch (fsp->flow_type) { +switch (flow) {case TCP_V4_FLOW :case TCP_V6_FLOW : data->cmd |=HW_ATL_RX_ENABLE_CMP_PROT_L4 ;
@@ -527,23 +528,23 @@ static int aq_set_data_fl3l4(struct aq_nic_s *aq_nic, } data->cmd |=HW_ATL_RX_ENABLE_L3_IPV6 ; } -if (fsp->flow_type !=IP_USER_FLOW && - fsp->flow_type !=IPV6_USER_FLOW ) { -if (!data->is_ipv6) { - data->p_dst = -ntohs (fsp->h_u.tcp_ip4_spec.pdst); - data->p_src = -ntohs (fsp->h_u.tcp_ip4_spec.psrc); - }else { - data->p_dst = -ntohs (fsp->h_u.tcp_ip6_spec.pdst); - data->p_src = -ntohs (fsp->h_u.tcp_ip6_spec.psrc); - } +if (flow ==TCP_V4_FLOW || flow ==UDP_V4_FLOW || + flow ==SCTP_V4_FLOW ) { + data->p_dst =ntohs (fsp->h_u.tcp_ip4_spec.pdst); + data->p_src =ntohs (fsp->h_u.tcp_ip4_spec.psrc); + } +if (flow ==TCP_V6_FLOW || flow ==UDP_V6_FLOW || + flow ==SCTP_V6_FLOW ) { + data->p_dst =ntohs (fsp->h_u.tcp_ip6_spec.pdst); + data->p_src =ntohs (fsp->h_u.tcp_ip6_spec.psrc); } -if (data->ip_src[0 ] && !data->is_ipv6) +if (data->ip_src[0 ] || + (data->is_ipv6 && (data->ip_src[1 ] || data->ip_src[2 ] || + data->ip_src[3 ]))) data->cmd |=HW_ATL_RX_ENABLE_CMP_SRC_ADDR_L3 ; -if (data->ip_dst[0 ] && !data->is_ipv6) +if (data->ip_dst[0 ] || + (data->is_ipv6 && (data->ip_dst[1 ] || data->ip_dst[2 ] || + data->ip_dst[3 ]))) data->cmd |=HW_ATL_RX_ENABLE_CMP_DEST_ADDR_L3 ;if (data->p_dst) data->cmd |=HW_ATL_RX_ENABLE_CMP_DEST_PORT_L4 ;
Signature · 1 line
2.43.0
[email protected]
maintainerPATCH v4 2/12 net: atlantic: move active_ipv4/ipv6 bitmap updates after HW write
In reply to [email protected]From: Sukhdeep Singh <[email protected]>
Move active_ipv4/active_ipv6 bitmap updates from aq_set_data_fl3l4() into aq_add_del_fl3l4() after the hardware write succeeds. The bitmaps track which filter slots are actively programmed in hardware and must only be updated once the HW write is confirmed.
The bitmap updates in aq_nic_reserve_filter() and aq_nic_release_filter() are intentionally retained: they guard the aq_check_approve_fl3l4() IPv4/IPv6 mixing validation for callers such as the AQC113 PTP path that program filters directly via hw_atl2_new_fl3l4_configure() without going through aq_add_del_fl3l4().
--- .../ethernet/aquantia/atlantic/aq_filters.c | 36 ++++++++++++------- 1 file changed, 23 insertions(+), 13 deletions(-)
drivers/net/ethernet/aquantia/atlantic/aq_filters.c +23 -13
@@ -479,15 +479,8 @@ static int aq_set_data_fl3l4(struct aq_nic_s *aq_nic, data->is_ipv6 = rx_fltrs->fl3l4.is_ipv6; data->location =HW_ATL_GET_REG_LOCATION_FL3L4 (fsp->location); -if (!add) { -if (!data->is_ipv6) - rx_fltrs->fl3l4.active_ipv4 &= ~BIT (data->location); -else - rx_fltrs->fl3l4.active_ipv6 &= - ~BIT ((data->location) /4 ); - +if (!add)return 0 ; - } data->cmd |=HW_ATL_RX_ENABLE_FLTR_L3L4 ;
@@ -515,11 +508,9 @@ static int aq_set_data_fl3l4(struct aq_nic_s *aq_nic,ntohl (fsp->h_u.tcp_ip4_spec.ip4src); data->ip_dst[0 ] =ntohl (fsp->h_u.tcp_ip4_spec.ip4dst); - rx_fltrs->fl3l4.active_ipv4 |=BIT (data->location); }else {int i; - rx_fltrs->fl3l4.active_ipv6 |=BIT ((data->location) /4 );for (i =0 ; i <HW_ATL_RX_CNT_REG_ADDR_IPV6 ; ++i) { data->ip_dst[i] =ntohl (fsp->h_u.tcp_ip6_spec.ip6dst[i]);
@@ -574,16 +565,35 @@ static int aq_set_fl3l4(struct aq_hw_s *aq_hw,static int aq_add_del_fl3l4 (struct aq_nic_s *aq_nic,struct aq_rx_filter *aq_rx_fltr,bool add) { +struct aq_hw_rx_fltrs_s *rx_fltrs =aq_get_hw_rx_fltrs (aq_nic);const struct aq_hw_ops *aq_hw_ops = aq_nic->aq_hw_ops;struct aq_hw_s *aq_hw = aq_nic->aq_hw;struct aq_rx_filter_l3l4 data; +int err;if (unlikely (aq_rx_fltr->aq_fsp.location <AQ_RX_FIRST_LOC_FL3L4 || - aq_rx_fltr->aq_fsp.location >AQ_RX_LAST_LOC_FL3L4 || -aq_set_data_fl3l4 (aq_nic, aq_rx_fltr, &data, add))) + aq_rx_fltr->aq_fsp.location >AQ_RX_LAST_LOC_FL3L4 ))return -EINVAL ; -return aq_set_fl3l4 (aq_hw, aq_hw_ops, &data); +aq_set_data_fl3l4 (aq_nic, aq_rx_fltr, &data, add); + + err =aq_set_fl3l4 (aq_hw, aq_hw_ops, &data); +if (err) +return err; + +if (add) { +if (!data.is_ipv6) + rx_fltrs->fl3l4.active_ipv4 |=BIT (data.location); +else + rx_fltrs->fl3l4.active_ipv6 |=BIT (data.location /4 ); + }else { +if (!data.is_ipv6) + rx_fltrs->fl3l4.active_ipv4 &= ~BIT (data.location); +else + rx_fltrs->fl3l4.active_ipv6 &= ~BIT (data.location /4 ); + } + +return 0 ; } static int aq_add_del_rule(struct aq_nic_s *aq_nic,
Signature · 1 line
2.43.0
[email protected]
maintainerPATCH v4 3/12 net: atlantic: decouple aq_set_data_fl3l4() from driver internals
In reply to [email protected]From: Sukhdeep Singh <[email protected]>
Refactor aq_set_data_fl3l4() to take an ethtool_rx_flow_spec pointer and an explicit HW register location instead of driver-internal structures (aq_nic_s, aq_rx_filter). This makes the function reusable for PTP filter setup which constructs flow specs independently.
Key changes:
- Add aq_is_ipv6_flow_type() helper to derive IPv6 status from the flow_type field, replacing the dependency on rx_fltrs->fl3l4.is_ipv6 shared state.
- Change aq_set_data_fl3l4() signature to accept (fsp, data, location, add) and export it via aq_filters.h.
- Update aq_add_del_fl3l4() to compute the HW register location and pass it explicitly.
--- .../ethernet/aquantia/atlantic/aq_filters.c | 31 ++++++++++++++----- .../ethernet/aquantia/atlantic/aq_filters.h | 3 ++ 2 files changed, 26 insertions(+), 8 deletions(-)
drivers/net/ethernet/aquantia/atlantic/aq_filters.c +23 -8
@@ -181,6 +181,20 @@ aq_check_approve_fvlan(struct aq_nic_s *aq_nic,return 0 ; } +static bool aq_is_ipv6_flow_type (const struct ethtool_rx_flow_spec *fsp) +{ +switch (fsp->flow_type & ~FLOW_EXT ) { +case TCP_V6_FLOW : +case UDP_V6_FLOW : +case SCTP_V6_FLOW : +case IPV6_FLOW : +case IPV6_USER_FLOW : +return true; +default : +return false; + } +} +static int __must_check aq_check_filter (struct aq_nic_s *aq_nic,struct ethtool_rx_flow_spec *fsp)
@@ -466,18 +480,16 @@ static int aq_add_del_fvlan(struct aq_nic_s *aq_nic,return aq_filters_vlans_update (aq_nic); } -static int aq_set_data_fl3l4 (struct aq_nic_s *aq_nic, -struct aq_rx_filter *aq_rx_fltr, -struct aq_rx_filter_l3l4 *data,bool add) +int aq_set_data_fl3l4 (const struct ethtool_rx_flow_spec *fsp, +struct aq_rx_filter_l3l4 *data, +int location,bool add) { -struct aq_hw_rx_fltrs_s *rx_fltrs =aq_get_hw_rx_fltrs (aq_nic); -const struct ethtool_rx_flow_spec *fsp = &aq_rx_fltr->aq_fsp;u32 flow = fsp->flow_type & ~FLOW_EXT ;memset (data,0 ,sizeof (*data)); - data->is_ipv6 = rx_fltrs->fl3l4.is_ipv6; - data->location =HW_ATL_GET_REG_LOCATION_FL3L4 (fsp->location); + data->is_ipv6 =aq_is_ipv6_flow_type (fsp); + data->location = location;if (!add)return 0 ;
@@ -569,13 +581,16 @@ static int aq_add_del_fl3l4(struct aq_nic_s *aq_nic,const struct aq_hw_ops *aq_hw_ops = aq_nic->aq_hw_ops;struct aq_hw_s *aq_hw = aq_nic->aq_hw;struct aq_rx_filter_l3l4 data; +int location;int err;if (unlikely (aq_rx_fltr->aq_fsp.location <AQ_RX_FIRST_LOC_FL3L4 || aq_rx_fltr->aq_fsp.location >AQ_RX_LAST_LOC_FL3L4 ))return -EINVAL ; -aq_set_data_fl3l4 (aq_nic, aq_rx_fltr, &data, add); + location =HW_ATL_GET_REG_LOCATION_FL3L4 (aq_rx_fltr->aq_fsp.location); + +aq_set_data_fl3l4 (&aq_rx_fltr->aq_fsp, &data, location, add); err =aq_set_fl3l4 (aq_hw, aq_hw_ops, &data);if (err)
drivers/net/ethernet/aquantia/atlantic/aq_filters.h +3 -0
@@ -32,5 +32,8 @@ int aq_clear_rxnfc_all_rules(struct aq_nic_s *aq_nic);int aq_reapply_rxnfc_all_rules (struct aq_nic_s *aq_nic);int aq_filters_vlans_update (struct aq_nic_s *aq_nic);int aq_filters_vlan_offload_off (struct aq_nic_s *aq_nic); +int aq_set_data_fl3l4 (const struct ethtool_rx_flow_spec *fsp, +struct aq_rx_filter_l3l4 *data, +int location,bool add);#endif /* AQ_FILTERS_H */
Signature · 1 line
2.43.0
[email protected]
maintainerPATCH v4 4/12 net: atlantic: add AQC113 hardware register definitions and accessors
In reply to [email protected]From: Sukhdeep Singh <[email protected]>
Add low-level hardware register definitions and accessor functions for AQC113 (Antigua) chip features:
- L3/L4 filter command, tag, and address registers for IPv4/IPv6
- Ethertype filter tag registers
- TSG (Time Stamp Generator) clock control, modification, and GPIO event generation/input timestamp registers
- TX descriptor timestamp writeback, timestamp enable, and AVB enable registers
- TX data/descriptor read request limit registers
- TPB highest priority TC registers
- PCIe extended tag enable register
- RX descriptor timestamp request register
- Action resolver section enable getter
- GPIO special mode and TSG external GPIO TS input select
--- .../aquantia/atlantic/hw_atl2/hw_atl2_llh.c | 322 ++++++++++++++++++ .../aquantia/atlantic/hw_atl2/hw_atl2_llh.h | 97 +++++- .../atlantic/hw_atl2/hw_atl2_llh_internal.h | 204 ++++++++++- 3 files changed, 617 insertions(+), 6 deletions(-)
drivers/net/ethernet/aquantia/atlantic/hw_atl2/hw_atl2_llh.c +322 -0
@@ -7,6 +7,13 @@#include "hw_atl2_llh_internal.h" #include "aq_hw_utils.h" +u32 hw_atl2_phi_ext_tag_get (struct aq_hw_s *aq_hw) +{ +return aq_hw_read_reg_bit (aq_hw,HW_ATL2_PHI_EXT_TAG_EN_ADR , +HW_ATL2_PHI_EXT_TAG_EN_MSK , +HW_ATL2_PHI_EXT_TAG_EN_SHIFT ); +} +void hw_atl2_rpf_redirection_table2_select_set (struct aq_hw_s *aq_hw,u32 select) {
@@ -66,6 +73,266 @@ void hw_atl2_rpf_vlan_flr_tag_set(struct aq_hw_s *aq_hw, u32 tag, u32 filter) tag); } +void hw_atl2_rpf_etht_flr_tag_set (struct aq_hw_s *aq_hw,u32 tag,u32 filter) +{ +aq_hw_write_reg_bit (aq_hw,HW_ATL2_RPF_ET_TAG_ADR (filter), +HW_ATL2_RPF_ET_TAG_MSK , +HW_ATL2_RPF_ET_TAG_SHIFT , tag); +} + +u32 hw_atl2_rpf_etht_flr_tag_get (struct aq_hw_s *aq_hw,u32 filter) +{ +return aq_hw_read_reg_bit (aq_hw,HW_ATL2_RPF_ET_TAG_ADR (filter), +HW_ATL2_RPF_ET_TAG_MSK , +HW_ATL2_RPF_ET_TAG_SHIFT ); +} + +void hw_atl2_rpf_l3_v4_dest_addr_set (struct aq_hw_s *aq_hw,u32 filter,u32 val) +{ +u32 addr_set =6 + ((filter <4 ) ?0 :1 ); +u32 dword = filter %4 ; + +aq_hw_write_reg (aq_hw,HW_ATL2_RPF_L3_DA_DW_ADR (addr_set, dword), val); +} + +void hw_atl2_rpf_l3_v4_src_addr_set (struct aq_hw_s *aq_hw,u32 filter,u32 val) +{ +u32 addr_set =6 + ((filter <4 ) ?0 :1 ); +u32 dword = filter %4 ; + +aq_hw_write_reg (aq_hw,HW_ATL2_RPF_L3_SA_DW_ADR (addr_set, dword), val); +} + +void hw_atl2_rpf_l3_v6_dest_addr_set (struct aq_hw_s *aq_hw,u8 location, +u32 *ipv6_dst) +{ +int i; + +for (i =0 ; i <4 ; ++i) +aq_hw_write_reg (aq_hw, +HW_ATL2_RPF_L3_DA_DW_ADR (location,3 - i), + ipv6_dst[i]); +} + +void hw_atl2_rpf_l3_v6_src_addr_set (struct aq_hw_s *aq_hw,u8 location, +u32 *ipv6_src) +{ +int i; + +for (i =0 ; i <4 ; ++i) +aq_hw_write_reg (aq_hw, +HW_ATL2_RPF_L3_SA_DW_ADR (location,3 - i), + ipv6_src[i]); +} + +void hw_atl2_rpf_l3_v4_cmd_set (struct aq_hw_s *aq_hw,u32 val,u32 filter) +{ +aq_hw_write_reg_bit (aq_hw,HW_ATL2_RPF_L3_V4_CMD_ADR (filter), +HW_ATL2_RPF_L3_V4_CMD_MSK , +HW_ATL2_RPF_L3_V4_CMD_SHIFT , val); +} + +void hw_atl2_rpf_l3_v6_cmd_set (struct aq_hw_s *aq_hw,u32 val,u32 filter) +{ +aq_hw_write_reg_bit (aq_hw,HW_ATL2_RPF_L3_V6_CMD_ADR (filter), +HW_ATL2_RPF_L3_V6_CMD_MSK , +HW_ATL2_RPF_L3_V6_CMD_SHIFT , val); +} + +void hw_atl2_rpf_l3_v6_v4_select_set (struct aq_hw_s *aq_hw,u32 val) +{ +aq_hw_write_reg_bit (aq_hw,HW_ATL2_RPF_L3_V6_V4_SELECT_ADR , +HW_ATL2_RPF_L3_V6_V4_SELECT_MSK , +HW_ATL2_RPF_L3_V6_V4_SELECT_SHIFT , val); +} + +void hw_atl2_rpf_l3_v4_tag_set (struct aq_hw_s *aq_hw,u32 val,u32 filter) +{ +aq_hw_write_reg_bit (aq_hw,HW_ATL2_RPF_L3_V4_TAG_ADR (filter), +HW_ATL2_RPF_L3_V4_TAG_MSK , +HW_ATL2_RPF_L3_V4_TAG_SHIFT , val); +} + +void hw_atl2_rpf_l3_v6_tag_set (struct aq_hw_s *aq_hw,u32 val,u32 filter) +{ +aq_hw_write_reg_bit (aq_hw,HW_ATL2_RPF_L3_V6_TAG_ADR (filter), +HW_ATL2_RPF_L3_V6_TAG_MSK , +HW_ATL2_RPF_L3_V6_TAG_SHIFT , val); +} + +void hw_atl2_rpf_l4_tag_set (struct aq_hw_s *aq_hw,u32 val,u32 filter) +{ +aq_hw_write_reg_bit (aq_hw,HW_ATL2_RPF_L4_TAG_ADR (filter), +HW_ATL2_RPF_L4_TAG_MSK , +HW_ATL2_RPF_L4_TAG_SHIFT , val); +} + +void hw_atl2_rpf_l4_cmd_set (struct aq_hw_s *aq_hw,u32 val,u32 filter) +{ +aq_hw_write_reg_bit (aq_hw,HW_ATL2_RPF_L4_CMD_ADR (filter), +HW_ATL2_RPF_L4_CMD_MSK , +HW_ATL2_RPF_L4_CMD_SHIFT , val); +} + +/* tsg */ +static void hw_atl2_clock_modif_value_set (struct aq_hw_s *aq_hw, +u32 clock_sel,u64 ns) +{ +aq_hw_write_reg64 (aq_hw, +HW_ATL2_TSG_REG_ADR (clock_sel,CLOCK_MODIF_VAL_LSW ), + ns); +} + +void hw_atl2_tsg_clock_en (struct aq_hw_s *aq_hw, +u32 clock_sel,u32 clock_enable) +{ +aq_hw_write_reg_bit (aq_hw,HW_ATL2_TSG_REG_ADR (clock_sel,CLOCK_CFG ), +HW_ATL2_TSG_CLOCK_EN_MSK , +HW_ATL2_TSG_CLOCK_EN_SHIFT , + clock_enable); +} + +void hw_atl2_tsg_clock_reset (struct aq_hw_s *aq_hw,u32 clock_sel) +{ +aq_hw_write_reg_bit (aq_hw,HW_ATL2_TSG_REG_ADR (clock_sel,CLOCK_CFG ), +HW_ATL2_TSG_SYNC_RESET_MSK , +HW_ATL2_TSG_SYNC_RESET_SHIFT ,1 ); +aq_hw_write_reg_bit (aq_hw,HW_ATL2_TSG_REG_ADR (clock_sel,CLOCK_CFG ), +HW_ATL2_TSG_SYNC_RESET_MSK , +HW_ATL2_TSG_SYNC_RESET_SHIFT ,0 ); +} + +u64 hw_atl2_tsg_clock_read (struct aq_hw_s *aq_hw,u32 clock_sel) +{ +return aq_hw_read_reg64 (aq_hw, +HW_ATL2_TSG_REG_ADR (clock_sel, +READ_CUR_NS_LSW )); +} + +void hw_atl2_tsg_clock_add (struct aq_hw_s *aq_hw,u32 clock_sel,u64 ns) +{ +hw_atl2_clock_modif_value_set (aq_hw, clock_sel, ns); +aq_hw_write_reg (aq_hw, +HW_ATL2_TSG_REG_ADR (clock_sel,CLOCK_MODIF_CTRL ), +HW_ATL2_TSG_ADD_COUNTER_MSK ); +} + +void hw_atl2_tsg_clock_sub (struct aq_hw_s *aq_hw,u32 clock_sel,u64 ns) +{ +hw_atl2_clock_modif_value_set (aq_hw, clock_sel, ns); +aq_hw_write_reg (aq_hw, +HW_ATL2_TSG_REG_ADR (clock_sel,CLOCK_MODIF_CTRL ), +HW_ATL2_TSG_SUBTRACT_COUNTER_MSK ); +} + +void hw_atl2_tsg_clock_increment_set (struct aq_hw_s *aq_hw, +u32 clock_sel,u32 ns,u32 fns) +{ +u32 nsfns = (ns &0xff ) | (fns &0xffffff00 ); + +aq_hw_write_reg (aq_hw, +HW_ATL2_TSG_REG_ADR (clock_sel,CLOCK_INC_CFG ), + nsfns); +aq_hw_write_reg (aq_hw, +HW_ATL2_TSG_REG_ADR (clock_sel,CLOCK_MODIF_CTRL ), +HW_ATL2_TSG_LOAD_INC_CFG_MSK ); +} + +void hw_atl2_tpb_tps_highest_priority_tc_enable_set (struct aq_hw_s *aq_hw, +u32 tps_highest_prio_tc_en) +{ +aq_hw_write_reg_bit (aq_hw,HW_ATL2_TPB_HIGHEST_PRIO_TC_EN_ADR , +HW_ATL2_TPB_HIGHEST_PRIO_TC_EN_MSK , +HW_ATL2_TPB_HIGHEST_PRIO_TC_EN_SHIFT , + tps_highest_prio_tc_en); +} + +void hw_atl2_tpb_tps_highest_priority_tc_set (struct aq_hw_s *aq_hw, +u32 tps_highest_prio_tc) +{ +aq_hw_write_reg_bit (aq_hw,HW_ATL2_TPB_HIGHEST_PRIO_TC_ADR , +HW_ATL2_TPB_HIGHEST_PRIO_TC_MSK , +HW_ATL2_TPB_HIGHEST_PRIO_TC_SHIFT , + tps_highest_prio_tc); +} + +void hw_atl2_tsg_gpio_isr_to_host_set (struct aq_hw_s *aq_hw, +int on,u32 clock_sel) +{ +aq_hw_write_reg_bit (aq_hw, +HW_ATL2_GLOBAL_HIGH_PRIO_INTERRUPT_1_MASK_ADR , + clock_sel ==1 ?HW_ATL2_TSG_TSG1_GPIO_INTERRUPT_MSK : +HW_ATL2_TSG_TSG0_GPIO_INTERRUPT_MSK , + clock_sel ==1 ?HW_ATL2_TSG_TSG1_GPIO_INTERRUPT_SHIFT : +HW_ATL2_TSG_TSG0_GPIO_INTERRUPT_SHIFT , + !!on); +} + +void hw_atl2_tsg_gpio_clear_status (struct aq_hw_s *aq_hw) +{ +aq_hw_read_reg (aq_hw,HW_ATL2_GLOBAL_INTERNAL_ALARMS_1_ADR ); +} + +void hw_atl2_tsg_gpio_input_event_info_get (struct aq_hw_s *aq_hw, +u32 clock_sel, +u32 *event_count, +u64 *event_ts) +{ +if (event_count) + *event_count =aq_hw_read_reg (aq_hw, +HW_ATL2_TSG_REG_ADR (clock_sel, +EXT_CLK_COUNT )); + +if (event_ts) + *event_ts =aq_hw_read_reg64 (aq_hw, +HW_ATL2_TSG_REG_ADR (clock_sel, +GPIO_EVENT_TS_LSW )); +} + +void hw_atl2_tsg_ptp_gpio_gen_pulse (struct aq_hw_s *aq_hw,u32 clk_sel, +u64 ts,u32 period,u32 hightime) +{ +u32 val = (HW_ATL2_TSG_GPIO_EVENT_MODE_SET_ON_TIME << + (HW_ATL2_TSG_GPIO_EVENT_MODE_SHIFT - +HW_ATL2_TSG_GPIO_OUTPUT_EN_SHIFT )) | + (HW_ATL2_TSG_GPIO_GEN_OUTPUT_EN_MSK ) | + (HW_ATL2_TSG_GPIO_OUTPUT_EN_MSK ); + +if (ts !=0 ) { +aq_hw_write_reg64 (aq_hw, +HW_ATL2_TSG_REG_ADR (clk_sel, +GPIO_EVENT_GEN_TS_LSW ), + ts); + +aq_hw_write_reg64 (aq_hw, +HW_ATL2_TSG_REG_ADR (clk_sel, +GPIO_EVENT_HIGH_TIME_LSW ), + hightime); + +aq_hw_write_reg64 (aq_hw, +HW_ATL2_TSG_REG_ADR (clk_sel, +GPIO_EVENT_LOW_TIME_LSW ), + (period - hightime)); + } + +aq_hw_write_reg_bit (aq_hw, +HW_ATL2_TSG_REG_ADR (clk_sel,GPIO_EVENT_GEN_CFG ), +HW_ATL2_TSG_GPIO_EVENT_MODE_MSK | +HW_ATL2_TSG_GPIO_OUTPUT_EN_MSK | +HW_ATL2_TSG_GPIO_GEN_OUTPUT_EN_MSK , +HW_ATL2_TSG_GPIO_OUTPUT_EN_SHIFT , + (!ts ?0 : val)); +} + +void hw_atl2_rpf_rx_desc_timestamp_req_set (struct aq_hw_s *aq_hw,u32 request, +u32 descriptor) +{ +aq_hw_write_reg_bit (aq_hw, +HW_ATL2_RPF_TIMESTAMP_REQ_DESCD_ADR (descriptor), +HW_ATL2_RPF_TIMESTAMP_REQ_DESCD_MSK , +HW_ATL2_RPF_TIMESTAMP_REQ_DESCD_SHIFT , request); +} +/* TX */ void hw_atl2_tpb_tx_tc_q_rand_map_en_set(struct aq_hw_s *aq_hw,
@@ -93,6 +360,30 @@ void hw_atl2_reg_tx_intr_moder_ctrl_set(struct aq_hw_s *aq_hw, tx_intr_moderation_ctl); } +void hw_atl2_tdm_tx_desc_timestamp_writeback_en_set (struct aq_hw_s *aq_hw, +u32 enable,u32 descriptor) +{ +aq_hw_write_reg_bit (aq_hw,HW_ATL2_TDM_DESCD_TS_WRB_EN_ADR (descriptor), +HW_ATL2_TDM_DESCD_TS_WRB_EN_MSK , +HW_ATL2_TDM_DESCD_TS_WRB_EN_SHIFT , enable); +} + +void hw_atl2_tdm_tx_desc_timestamp_en_set (struct aq_hw_s *aq_hw,u32 enable, +u32 descriptor) +{ +aq_hw_write_reg_bit (aq_hw,HW_ATL2_TDM_DESCD_TS_EN_ADR (descriptor), +HW_ATL2_TDM_DESCD_TS_EN_MSK , +HW_ATL2_TDM_DESCD_TS_EN_SHIFT , enable); +} + +void hw_atl2_tdm_tx_desc_avb_en_set (struct aq_hw_s *aq_hw,u32 enable, +u32 descriptor) +{ +aq_hw_write_reg_bit (aq_hw,HW_ATL2_TDM_DESCD_AVB_EN_ADR (descriptor), +HW_ATL2_TDM_DESCD_AVB_EN_MSK , +HW_ATL2_TDM_DESCD_AVB_EN_SHIFT , enable); +} +void hw_atl2_tps_tx_pkt_shed_data_arb_mode_set (struct aq_hw_s *aq_hw,const u32 data_arb_mode) {
@@ -122,6 +413,20 @@ void hw_atl2_tps_tx_pkt_shed_tc_data_weight_set(struct aq_hw_s *aq_hw, weight); } +void hw_atl2_tdm_tx_data_read_req_limit_set (struct aq_hw_s *aq_hw,u32 limit) +{ +aq_hw_write_reg_bit (aq_hw,HW_ATL2_TDM_TX_DATA_RD_REQ_LIMIT_ADR , +HW_ATL2_TDM_TX_DATA_RD_REQ_LIMIT_MSK , +HW_ATL2_TDM_TX_DATA_RD_REQ_LIMIT_SHIFT , limit); +} + +void hw_atl2_tdm_tx_desc_read_req_limit_set (struct aq_hw_s *aq_hw,u32 limit) +{ +aq_hw_write_reg_bit (aq_hw,HW_ATL2_TDM_TX_DESC_RD_REQ_LIMIT_ADR , +HW_ATL2_TDM_TX_DESC_RD_REQ_LIMIT_MSK , +HW_ATL2_TDM_TX_DESC_RD_REQ_LIMIT_SHIFT , limit); +} +u32 hw_atl2_get_hw_version (struct aq_hw_s *aq_hw) {return aq_hw_read_reg (aq_hw,HW_ATL2_FPGA_VER_ADR );
@@ -164,6 +469,13 @@ void hw_atl2_rpf_act_rslvr_section_en_set(struct aq_hw_s *aq_hw, u32 sections) sections); } +u32 hw_atl2_rpf_act_rslvr_section_en_get (struct aq_hw_s *aq_hw) +{ +return aq_hw_read_reg_bit (aq_hw,HW_ATL2_RPF_REC_TAB_EN_ADR , +HW_ATL2_RPF_REC_TAB_EN_MSK , +HW_ATL2_RPF_REC_TAB_EN_SHIFT ); +} +void hw_atl2_mif_shared_buf_get (struct aq_hw_s *aq_hw,int offset,u32 *data,int len) {
@@ -232,3 +544,13 @@ void hw_atl2_mif_host_req_int_clr(struct aq_hw_s *aq_hw, u32 val)return aq_hw_write_reg (aq_hw,HW_ATL2_MCP_HOST_REQ_INT_CLR_ADR , val); } + +void hw_atl2_gpio_special_mode_set (struct aq_hw_s *aq_hw, +u32 gpio_special_mode, +u32 pin) +{ +aq_hw_write_reg_bit (aq_hw,HW_ATL2_GPIO_PIN_SPEC_MODE_ADR (pin), +HW_ATL2_GPIO_PIN_SPEC_MODE_MSK , +HW_ATL2_GPIO_PIN_SPEC_MODE_SHIFT , + gpio_special_mode); +}
drivers/net/ethernet/aquantia/atlantic/hw_atl2/hw_atl2_llh.h +96 -1
139 lines not on this page · raw message
drivers/net/ethernet/aquantia/atlantic/hw_atl2/hw_atl2_llh_internal.h +199 -5
238 lines not on this page · raw message
Signature · 1 line
2.43.0
[email protected]
maintainerPATCH v4 5/12 net: atlantic: add AQC113 filter data structures and firmware query
In reply to [email protected]From: Sukhdeep Singh <[email protected]>
Add filter infrastructure for AQC113 hardware:
- Define L3 (IPv4/IPv6), L4 (TCP/UDP/SCTP), and combined L3L4 filter structures with reference-counted sharing support.
- Define tag policy structure for ethertype filter management.
- Add RPF L3/L4 command bit definitions for filter programming.
- Add filter count constants for L3L4, L3V4, L4, VLAN, and ethertype.
- Extend hw_atl2_priv with filter arrays, base indices, and counts discovered from firmware.
Query filter capabilities from firmware shared memory at init time to discover available L2/L3/L4/VLAN/ethertype filter resources and ART (Action Resolver Table) configuration.
Add hardware register dump utility for AQC113 debug support.
--- .../atlantic/hw_atl2/hw_atl2_internal.h | 63 +++++++++++++++ .../aquantia/atlantic/hw_atl2/hw_atl2_utils.c | 34 ++++++++ .../aquantia/atlantic/hw_atl2/hw_atl2_utils.h | 5 ++ .../atlantic/hw_atl2/hw_atl2_utils_fw.c | 77 +++++++++++++++++++ 4 files changed, 179 insertions(+)
drivers/net/ethernet/aquantia/atlantic/hw_atl2/hw_atl2_internal.h +63 -0
@@ -84,6 +84,18 @@ enum HW_ATL2_RPF_ART_INDEX { HW_ATL_VLAN_MAX_FILTERS, }; +#define HW_ATL2_RPF_L3_CMD_EN BIT(0) +#define HW_ATL2_RPF_L3_CMD_SA_EN BIT(1) +#define HW_ATL2_RPF_L3_CMD_DA_EN BIT(2) +#define HW_ATL2_RPF_L3_CMD_PROTO_EN BIT(3) +#define HW_ATL2_RPF_L3_V6_CMD_EN BIT(0x10) +#define HW_ATL2_RPF_L3_V6_CMD_SA_EN BIT(0x11) +#define HW_ATL2_RPF_L3_V6_CMD_DA_EN BIT(0x12) +#define HW_ATL2_RPF_L3_V6_CMD_PROTO_EN BIT(0x13) +#define HW_ATL2_RPF_L4_CMD_EN BIT(0) +#define HW_ATL2_RPF_L4_CMD_DP_EN BIT(1) +#define HW_ATL2_RPF_L4_CMD_SP_EN BIT(2) +#define HW_ATL2_ACTION (ACTION ,RSS ,INDEX ,VALID ) \ ((((ACTION) & 0x3U) << 8) | \ (((RSS) & 0x1U) << 7) | \
@@ -94,6 +106,12 @@ enum HW_ATL2_RPF_ART_INDEX {#define HW_ATL2_ACTION_DISABLE HW_ATL2_ACTION(0, 0, 0, 0)#define HW_ATL2_ACTION_ASSIGN_QUEUE (QUEUE ) HW_ATL2_ACTION(1, 0, (QUEUE), 1)#define HW_ATL2_ACTION_ASSIGN_TC (TC ) HW_ATL2_ACTION(1, 1, (TC), 1) +#define HW_ATL2_RPF_L3L4_FILTERS 8 +#define HW_ATL2_RPF_L3V4_FILTERS 8 +#define HW_ATL2_RPF_L4_FILTERS 8 +#define HW_ATL2_RPF_VLAN_FILTERS 16 +#define HW_ATL2_RPF_ETYPE_FILTERS 16 +#define HW_ATL2_RPF_ETYPE_TAGS 7enum HW_ATL2_RPF_RSS_HASH_TYPE {HW_ATL2_RPF_RSS_HASH_TYPE_NONE =0 ,
@@ -119,9 +137,54 @@ enum HW_ATL2_RPF_RSS_HASH_TYPE {#define HW_ATL_MCAST_FLT_ANY_TO_HOST 0x00010FFFU +struct hw_atl2_l3_filter { +u8 proto; +u8 usage; +u32 cmd; +u32 srcip[4 ]; +u32 dstip[4 ]; +}; + +struct hw_atl2_l4_filter { +u8 usage; +u32 cmd; +u16 sport; +u16 dport; +}; + +struct hw_atl2_l3l4_filter { +s8 l3_index; +s8 l4_index; +u8 ipv6; +}; + +struct hw_atl2_tag_policy { +u16 action; +u16 usage; +}; +struct hw_atl2_priv { +struct hw_atl2_l3_filter l3_v4_filters[HW_ATL2_RPF_L3L4_FILTERS ]; +struct hw_atl2_l3_filter l3_v6_filters[HW_ATL2_RPF_L3L4_FILTERS ]; +struct hw_atl2_l4_filter l4_filters[HW_ATL2_RPF_L3L4_FILTERS ]; +struct hw_atl2_l3l4_filter l3l4_filters[HW_ATL2_RPF_L3L4_FILTERS ]; +struct hw_atl2_tag_policy etype_policy[HW_ATL2_RPF_ETYPE_FILTERS ];struct statistics_s last_stats;unsigned int art_base_index; +unsigned int art_count; +unsigned int l2_filters_base_index; +unsigned int l2_filter_count; +unsigned int etype_filter_base_index; +unsigned int etype_filter_count; +unsigned int etype_filter_tag_top; +unsigned int vlan_filter_base_index; +unsigned int vlan_filter_count; +unsigned int l3_v4_filter_base_index; +unsigned int l3_v4_filter_count; +unsigned int l3_v6_filter_base_index; +unsigned int l3_v6_filter_count; +unsigned int l4_filter_base_index; +unsigned int l4_filter_count; };#endif /* HW_ATL2_INTERNAL_H */
drivers/net/ethernet/aquantia/atlantic/hw_atl2/hw_atl2_utils.c +34 -0
@@ -128,3 +128,37 @@ int hw_atl2_utils_soft_reset(struct aq_hw_s *self) err_exit:return err; } + +static const u32 hw_atl2_utils_hw_mac_regs[] = { +0x00005580U ,0x00005590U ,0x000055B0U ,0x000055B4U , +0x000055C0U ,0x00005B00U ,0x00005B04U ,0x00005B08U , +0x00005B0CU ,0x00005B10U ,0x00005B14U ,0x00005B18U , +0x00005B1CU ,0x00005B20U ,0x00005B24U ,0x00005B28U , +0x00005B2CU ,0x00005B30U ,0x00005B34U ,0x00005B38U , +0x00005B3CU ,0x00005B40U ,0x00005B44U ,0x00005B48U , +0x00005B4CU ,0x00005B50U ,0x00005B54U ,0x00005B58U , +0x00005B5CU ,0x00005B60U ,0x00005B64U ,0x00005B68U , +0x00005B6CU ,0x00005B70U ,0x00005B74U ,0x00005B78U , +0x00005B7CU ,0x00007C00U ,0x00007C04U ,0x00007C08U , +0x00007C0CU ,0x00007C10U ,0x00007C14U ,0x00007C18U , +0x00007C1CU ,0x00007C20U ,0x00007C40U ,0x00007C44U , +0x00007C48U ,0x00007C4CU ,0x00007C50U ,0x00007C54U , +0x00007C58U ,0x00007C5CU ,0x00007C60U ,0x00007C80U , +0x00007C84U ,0x00007C88U ,0x00007C8CU ,0x00007C90U , +0x00007C94U ,0x00007C98U ,0x00007C9CU ,0x00007CA0U , +0x00007CC0U ,0x00007CC4U ,0x00007CC8U ,0x00007CCCU , +0x00007CD0U ,0x00007CD4U ,0x00007CD8U ,0x00007CDCU , +}; + +int hw_atl2_utils_hw_get_regs (struct aq_hw_s *self, +const struct aq_hw_caps_s *aq_hw_caps, +u32 *regs_buff) +{ +unsigned int i; + +for (i =0 ; i <min_t (u32, aq_hw_caps->mac_regs_count, +ARRAY_SIZE (hw_atl2_utils_hw_mac_regs)); i++) + regs_buff[i] =aq_hw_read_reg (self, + hw_atl2_utils_hw_mac_regs[i]); +return 0 ; +}
drivers/net/ethernet/aquantia/atlantic/hw_atl2/hw_atl2_utils.h +5 -0
@@ -626,10 +626,15 @@ int hw_atl2_utils_initfw(struct aq_hw_s *self, const struct aq_fw_ops **fw_ops);int hw_atl2_utils_soft_reset (struct aq_hw_s *self); +int hw_atl2_utils_hw_get_regs (struct aq_hw_s *self, +const struct aq_hw_caps_s *aq_hw_caps, +u32 *regs_buff); +u32 hw_atl2_utils_get_fw_version (struct aq_hw_s *self);int hw_atl2_utils_get_action_resolve_table_caps (struct aq_hw_s *self,u8 *base_index,u8 *count); +int hw_atl2_utils_get_filter_caps (struct aq_hw_s *self);extern const struct aq_fw_ops aq_a2_fw_ops;
drivers/net/ethernet/aquantia/atlantic/hw_atl2/hw_atl2_utils_fw.c +77 -0
89 lines not on this page · raw message
Signature · 1 line
2.43.0
Jakub Kicinski
maintainerRe: [PATCH net-next v4 5/12] net: atlantic: add AQC113 filter data structures and firmware query
This is an AI-generated review of your patch. The human sending this email has considered the AI review valid, or at least plausible.
---
net: atlantic: add AQC113 filter data structures and firmware query
This patch adds L3/L4/L3L4 and ethertype tag filter data structures to hw_atl2_priv, defines RPF L3/L4 command bits and several filter count constants, and queries filter capabilities from firmware shared memory during aq_a2_fw_init(). It also adds an unrelated MAC register dump helper hw_atl2_utils_hw_get_regs().
A few questions inline.
Quoted 4 lines
drivers/net/ethernet/aquantia/atlantic/hw_atl2/hw_atl2_internal.h +0
-0
[ ... ]
drivers/net/ethernet/aquantia/atlantic/hw_atl2/hw_atl2_internal.h enum HW_ATL2_RPF_ART_INDEX { · line 114
Quoted 10 lines
drivers/net/ethernet/aquantia/atlantic/hw_atl2/hw_atl2_internal.h +6
-0@@ -94,6 +106,12 @@ enum HW_ATL2_RPF_ART_INDEX {#define HW_ATL2_ACTION_DISABLE HW_ATL2_ACTION(0, 0, 0, 0)#define HW_ATL2_ACTION_ASSIGN_QUEUE (QUEUE ) HW_ATL2_ACTION(1, 0, (QUEUE), 1)#define HW_ATL2_ACTION_ASSIGN_TC (TC ) HW_ATL2_ACTION(1, 1, (TC), 1) +#define HW_ATL2_RPF_L3L4_FILTERS 8 +#define HW_ATL2_RPF_L3V4_FILTERS 8 +#define HW_ATL2_RPF_L4_FILTERS 8 +#define HW_ATL2_RPF_VLAN_FILTERS 16 +#define HW_ATL2_RPF_ETYPE_FILTERS 16 +#define HW_ATL2_RPF_ETYPE_TAGS 7
[Low]HW_ATL2_RPF_L3V4_FILTERS and HW_ATL2_RPF_L4_FILTERS look unused.
Every array in hw_atl2_priv (l3_v4_filters[], l3_v6_filters[], l4_filters[], l3l4_filters[]) is sized with HW_ATL2_RPF_L3L4_FILTERS, and the bounds clamps in hw_atl2_utils_get_filter_caps() also compare against HW_ATL2_RPF_L3L4_FILTERS. HW_ATL2_RPF_L3V4_FILTERS and HW_ATL2_RPF_L4_FILTERS appear nowhere else in tree, and there is no symmetric HW_ATL2_RPF_L3V6_FILTERS even though the commit message enumerates IPv4 and IPv6 as distinct categories.
Should the unused names be dropped, or should the arrays and clamps be switched to use them so that, for example, lowering HW_ATL2_RPF_L4_FILTERS in the future actually has effect?
[ ... ]
Quoted 4 lines
drivers/net/ethernet/aquantia/atlantic/hw_atl2/hw_atl2_internal.h +4
-0+struct hw_atl2_l3_filter { +u8 proto; +u8 usage; +u32 cmd;
drivers/net/ethernet/aquantia/atlantic/hw_atl2/hw_atl2_internal.h enum HW_ATL2_RPF_RSS_HASH_TYPE { · line 153
Quoted 10 lines
drivers/net/ethernet/aquantia/atlantic/hw_atl2/hw_atl2_internal.h +10
-0+u32 srcip[4 ]; +u32 dstip[4 ]; +}; + +struct hw_atl2_l4_filter { +u8 usage; +u32 cmd; +u16 sport; +u16 dport; +};
[Low]
The commit message says these structures provide "reference-counted sharing support", but the only field that looks like a refcount is a plain u8 usage with no atomic_t, refcount_t, or paired inc/dec helpers in this commit. Could the wording in the commit message be tightened to match what is actually added (a serialized usage counter, not a refcount)?
[ ... ]
drivers/net/ethernet/aquantia/atlantic/hw_atl2/hw_atl2_utils.c int hw_atl2_utils_soft_reset(struct aq_hw_s *self) · line 132
Quoted 10 lines
drivers/net/ethernet/aquantia/atlantic/hw_atl2/hw_atl2_utils.c +2
-0@@ -128,3 +128,37 @@ int hw_atl2_utils_soft_reset(struct aq_hw_s *self) err_exit:return err; } + +static const u32 hw_atl2_utils_hw_mac_regs[] = {
[Low]
The subject and body describe filter data structures and firmware capability discovery, but the diff also adds a 72-entry MAC register table and the new register-dump helper hw_atl2_utils_hw_get_regs(). The register dump utility is unrelated to filter discovery and is not mentioned in the subject.
Would it be better to split this into a separate patch (or fold it into the follow-up commit that wires hw_atl2_utils_hw_get_regs() into hw_atl2_ops) so that this patch is one logical change?
[ ... ]
Quoted 4 lines
drivers/net/ethernet/aquantia/atlantic/hw_atl2/hw_atl2_utils_fw.c +0
-0
[ ... ]
Quoted 6 lines
drivers/net/ethernet/aquantia/atlantic/hw_atl2/hw_atl2_utils_fw.c +6
-0+int hw_atl2_utils_get_filter_caps (struct aq_hw_s *self) +{ +struct hw_atl2_priv *priv = self->priv; +struct filter_caps_s filter_caps; +u32 tag_top; +int err;
drivers/net/ethernet/aquantia/atlantic/hw_atl2/hw_atl2_utils_fw.c u32 hw_atl2_utils_get_fw_version(struct aq_hw_s *self) · line 628
Quoted 10 lines
drivers/net/ethernet/aquantia/atlantic/hw_atl2/hw_atl2_utils_fw.c +10
-0+u32 min_val; + + err =hw_atl2_shared_buffer_read_safe (self, filter_caps, &filter_caps); +if (err) +return err; + + priv->art_base_index = filter_caps.rslv_tbl_base_index *8 ; + priv->art_count = filter_caps.rslv_tbl_count *8 ; +if (priv->art_count ==0 ) + priv->art_count =128 ;
[Low]
What does the literal 128 represent here? It has no #define, no comment, and no log message. If firmware legitimately reports a 0 count (feature unavailable, FW bug, restricted SKU), this silently substitutes 128 ART entries and the driver could later program slots beyond what the part actually has.
Could this be promoted to a named macro alongside HW_ATL2_RPF_ART_INDEX with a short rationale, and possibly a netdev_warn() noting that the firmware did not advertise an ART count?
[Low]priv->art_base_index now has two writers reading the same firmware field. This function sets:
priv->art_base_index = filter_caps.rslv_tbl_base_index * 8;
while the pre-existing helper
int hw_atl2_utils_get_action_resolve_table_caps(struct aq_hw_s *self, u8 *base_index, u8 *count);
is still called from hw_atl2.c, which then assigns priv->art_base_index = base_index * 8 from its out-parameter.
Is one of these now redundant? Should callers move to consume the cached priv->art_base_index, or is there a reason to keep both sources of truth?
drivers/net/ethernet/aquantia/atlantic/hw_atl2/hw_atl2_utils_fw.c u32 hw_atl2_utils_get_fw_version(struct aq_hw_s *self) · line 635
Quoted 7 lines
drivers/net/ethernet/aquantia/atlantic/hw_atl2/hw_atl2_utils_fw.c +7
-0+ priv->l2_filters_base_index = filter_caps.l2_filters_base_index; + priv->l2_filter_count = filter_caps.l2_filter_count; + priv->etype_filter_base_index = filter_caps.ethertype_filter_base_index; + priv->etype_filter_count = filter_caps.ethertype_filter_count; + priv->etype_filter_tag_top = + (priv->etype_filter_count >=HW_ATL2_RPF_ETYPE_TAGS ) ? + (HW_ATL2_RPF_ETYPE_TAGS ) : (HW_ATL2_RPF_ETYPE_TAGS >>1 );
[Low]
The L3 and L4 paths below clamp base_index against HW_ATL2_RPF_L3L4_FILTERS and use min_t() on the count, but the etype, l2 and vlan_filter_base_index fields are copied verbatim from filter_caps_s u8 values (range 0..255).
Is that asymmetry intentional? It would be easier for future consumers to reason about if every firmware-supplied capability field were range-checked against its compile-time array bound (etype_policy[] is sized HW_ATL2_RPF_ETYPE_FILTERS, etc.) at the FW boundary, in this one place.
drivers/net/ethernet/aquantia/atlantic/hw_atl2/hw_atl2_utils_fw.c u32 hw_atl2_utils_get_fw_version(struct aq_hw_s *self) · line 648
Quoted 13 lines
drivers/net/ethernet/aquantia/atlantic/hw_atl2/hw_atl2_utils_fw.c +13
-0+ priv->vlan_filter_base_index = filter_caps.vlan_filter_base_index; +/* 0 - no tag, 1 - reserved for vlan-filter-offload filters */ + tag_top = + (filter_caps.vlan_filter_count ==HW_ATL2_RPF_VLAN_FILTERS ) ? + (HW_ATL2_RPF_VLAN_FILTERS -2 ) : + (HW_ATL2_RPF_VLAN_FILTERS /2 -2 ); + +if (filter_caps.vlan_filter_count >2 ) + priv->vlan_filter_count =min_t (u32, + filter_caps.vlan_filter_count -2 , + tag_top); +else + priv->vlan_filter_count =0 ;
[Low]
When firmware reports filter_caps.vlan_filter_count of 1 or 2, the "> 2" gate forces priv->vlan_filter_count to 0 silently, with no netdev_dbg()/netdev_warn(). The comment only documents the 2-entry reservation when the count is large.
Is the silent disable on a small but nonzero count intentional, and worth a short log line so users can tell why VLAN filtering came up disabled?
drivers/net/ethernet/aquantia/atlantic/hw_atl2/hw_atl2_utils_fw.c u32 hw_atl2_utils_get_fw_version(struct aq_hw_s *self) · line 659
Quoted 10 lines
drivers/net/ethernet/aquantia/atlantic/hw_atl2/hw_atl2_utils_fw.c +10
-0+ priv->l3_v4_filter_base_index = filter_caps.l3_ip4_filter_base_index; +if (priv->l3_v4_filter_base_index >=HW_ATL2_RPF_L3L4_FILTERS ) { + priv->l3_v4_filter_base_index =0 ; + priv->l3_v4_filter_count =0 ; + }else { + min_val =HW_ATL2_RPF_L3L4_FILTERS -1 - priv->l3_v4_filter_base_index; + priv->l3_v4_filter_count =min_t (u32, + filter_caps.l3_ip4_filter_count, + min_val); + }
[Medium]
Is the "- 1" in this clamp intentional?
The arrays are sized HW_ATL2_RPF_L3L4_FILTERS (= 8), and consumers in the follow-up patch "net: atlantic: implement AQC113 L2/L3/L4 RX filter ops" iterate over priv->l3_v4_filters[] / l3_v6_filters[] / l4_filters[] as a half-open range:
for (i = base; i < base + count; i++)
With base_index = 0 and firmware reporting count = 8 (the natural maximum for a 4-bit field):
min_val = 8 - 1 - 0 = 7 priv->l3_v4_filter_count = min_t(u32, 8, 7) = 7
so slot 7 is permanently unreachable. With base_index = 7 (still in-range, since the validity check is ">= HW_ATL2_RPF_L3L4_FILTERS"):
min_val = 8 - 1 - 7 = 0 priv->l3_v4_filter_count = 0
so the entire pool reports zero filters even though slot 7 exists.
For the half-open consumer convention, the formula that exactly fills the array is:
min_val = HW_ATL2_RPF_L3L4_FILTERS - priv->l3_v4_filter_base_index;
The same pattern is duplicated in the l3_v6 and l4 blocks below, and unlike the VLAN logic in this same function (which has the "- 2" comment explaining its reservation), the "- 1" here is undocumented.
Quoted 15 lines
drivers/net/ethernet/aquantia/atlantic/hw_atl2/hw_atl2_utils_fw.c +15
-0+ + priv->l3_v6_filter_base_index = filter_caps.l3_ip6_filter_base_index; +if (priv->l3_v6_filter_base_index >=HW_ATL2_RPF_L3L4_FILTERS ) { + priv->l3_v6_filter_base_index =0 ; + priv->l3_v6_filter_count =0 ; + }else { + min_val =HW_ATL2_RPF_L3L4_FILTERS -1 - priv->l3_v6_filter_base_index; + priv->l3_v6_filter_count =min_t (u32, + filter_caps.l3_ip6_filter_count, + min_val); + } + + priv->l4_filter_base_index = filter_caps.l4_filter_base_index; +if (priv->l4_filter_base_index >=HW_ATL2_RPF_L3L4_FILTERS ) { + priv->l4_filter_base_index =0 ;
drivers/net/ethernet/aquantia/atlantic/hw_atl2/hw_atl2_utils_fw.c u32 hw_atl2_utils_get_fw_version(struct aq_hw_s *self) · line 684
Quoted 10 lines
drivers/net/ethernet/aquantia/atlantic/hw_atl2/hw_atl2_utils_fw.c +10
-0+ priv->l4_filter_count =0 ; + }else { + min_val =HW_ATL2_RPF_L3L4_FILTERS -1 - priv->l4_filter_base_index; + priv->l4_filter_count =min_t (u32, + filter_caps.l4_filter_count, + min_val); + } + +return 0 ; +}
Same "- 1" question as above for the l3_v6 and l4 blocks.
Sukhdeep Soni [C]
maintainerRE: [EXTERNAL] Re: [PATCH net-next v4 5/12] net: atlantic: add AQC113 filter data structures and firmware query
Quoted 40 lines · Jakub Kicinski
net: atlantic: add AQC113 filter data structures and firmware query
This patch adds L3/L4/L3L4 and ethertype tag filter data structures to
hw_atl2_priv, defines RPF L3/L4 command bits and several filter count constants, and queries filter capabilities from firmware shared memory duringaq_a2_fw_init(). It also adds an unrelated MAC register dump helperhw_atl2_utils_hw_get_regs().A few questions inline.
drivers/net/ethernet/aquantia/atlantic/hw_atl2/hw_atl2_internal.h +6
-0@@ -94,6 +106,12 @@ enum HW_ATL2_RPF_ART_INDEX {#define HW_ATL2_ACTION_DISABLE HW_ATL2_ACTION(0, 0, 0, 0)#define HW_ATL2_ACTION_ASSIGN_QUEUE (QUEUE ) HW_ATL2_ACTION(1, 0, (QUEUE), 1)#define HW_ATL2_ACTION_ASSIGN_TC (TC ) HW_ATL2_ACTION(1, 1, (TC), 1) +#define HW_ATL2_RPF_L3L4_FILTERS 8 +#define HW_ATL2_RPF_L3V4_FILTERS 8 +#define HW_ATL2_RPF_L4_FILTERS 8 +#define HW_ATL2_RPF_VLAN_FILTERS 16 +#define HW_ATL2_RPF_ETYPE_FILTERS 16 +#define HW_ATL2_RPF_ETYPE_TAGS 7[Low]
HW_ATL2_RPF_L3V4_FILTERSandHW_ATL2_RPF_L4_FILTERSlook unused.Every array in
hw_atl2_priv(l3_v4_filters[], l3_v6_filters[], l4_filters[], l3l4_filters[]) is sized withHW_ATL2_RPF_L3L4_FILTERS, and the bounds clamps inhw_atl2_utils_get_filter_caps()also compare againstHW_ATL2_RPF_L3L4_FILTERS.HW_ATL2_RPF_L3V4_FILTERSandHW_ATL2_RPF_L4_FILTERSappear nowhere else in tree, and there is no symmetricHW_ATL2_RPF_L3V6_FILTERSeven though the commit message enumerates IPv4 and IPv6 as distinct categories.
Quoted 5 lines
Should the unused names be dropped, or should the arrays and clamps be switched to use them so that, for example, lowering
HW_ATL2_RPF_L4_FILTERSin the future actually has effect?[ ... ]
HW_ATL2_RPF_L3V4_FILTERS and HW_ATL2_RPF_L4_FILTERS are now
used as min_t() upper bounds in hw_atl2_utils_get_filter_caps(). HW_ATL2_RPF_L3V6_FILTERS has also been added with its own clamp for the IPv6 filter count, so all three filter categories now have named per-type constants and consistent clamping at the firmware boundary.
Quoted 23 lines
drivers/net/ethernet/aquantia/atlantic/hw_atl2/hw_atl2_internal.h +14
-0+struct hw_atl2_l3_filter { +u8 proto; +u8 usage; +u32 cmd; +u32 srcip[4 ]; +u32 dstip[4 ]; +}; + +struct hw_atl2_l4_filter { +u8 usage; +u32 cmd; +u16 sport; +u16 dport; +};[Low]
The commit message says these structures provide "reference-counted sharing support", but the only field that looks like a refcount is a plain u8 usage with noatomic_t,refcount_t, or paired inc/dec helpers in this commit. Could the wording in the commit message be tightened to match what is actually added (a serialized usage counter, not a refcount)?
Quoted 1 line
[ ... ]
Will fix in v5 - the commit message now reads "serialized usage counter for filter sharing" rather than "reference-counted sharing support".
Quoted 18 lines
drivers/net/ethernet/aquantia/atlantic/hw_atl2/hw_atl2_utils.c +2
-0@@ -128,3 +128,37 @@ int hw_atl2_utils_soft_reset(struct aq_hw_s *self) err_exit:return err; } + +static const u32 hw_atl2_utils_hw_mac_regs[] = {[Low]
The subject and body describe filter data structures and firmware capability discovery, but the diff also adds a 72-entry MAC register table and the new register-dump helperhw_atl2_utils_hw_get_regs(). The register dump utility is unrelated to filter discovery and is not mentioned in the subject.
Quoted 5 lines
Would it be better to split this into a separate patch (or fold it into the follow-up commit that wires
hw_atl2_utils_hw_get_regs()intohw_atl2_ops) so that this patch is one logical change?[ ... ]
The subject line is updated in v5 to explicitly include "register dump" alongside filter data structures and firmware query. The register dump helper hw_atl2_utils_hw_get_regs() is intentionally placed here rather than in patch 6 because patch 5 is where hw_atl2_utils.c is first touched - moving it to patch 6 would leave the function declaration in patch 5 with no definition until the next patch, which is worse for bisectability.
Quoted 32 lines
drivers/net/ethernet/aquantia/atlantic/hw_atl2/hw_atl2_utils_fw.c +16
-0+int hw_atl2_utils_get_filter_caps (struct aq_hw_s *self) +{ +struct hw_atl2_priv *priv = self->priv; +struct filter_caps_s filter_caps; +u32 tag_top; +int err; +u32 min_val; + + err =hw_atl2_shared_buffer_read_safe (self, filter_caps, &filter_caps); +if (err) +return err; + + priv->art_base_index = filter_caps.rslv_tbl_base_index *8 ; + priv->art_count = filter_caps.rslv_tbl_count *8 ; +if (priv->art_count ==0 ) + priv->art_count =128 ;[Low]
What does the literal 128 represent here? It has no #define, no comment, and no log message. If firmware legitimately reports a 0 count (feature unavailable, FW bug, restricted SKU), this silently substitutes 128 ART entries and the driver could later program slots beyond what the part actually has.
Quoted 3 lines
Could this be promoted to a named macro alongside
HW_ATL2_RPF_ART_INDEXwith a short rationale, and possibly anetdev_warn()noting that the firmware did not advertise an ART count?
The literal 128 has been promoted to HW_ATL2_ART_TOTAL_ENTRIES defined alongside the other RPF constants. Regarding the netdev_warn(): this fallback is the normal boot path on older firmware that predates the capability advertisement field - a warning on every such boot would be misleading noise. The silent fallback to the hardware maximum matches the vendor reference driver behaviour.
Quoted 11 lines
[Low]
priv->art_base_indexnow has two writers reading the same firmware field. This function sets:priv->art_base_index = filter_caps.rslv_tbl_base_index * 8;while the pre-existing helper
int hw_atl2_utils_get_action_resolve_table_caps(struct aq_hw_s *self, u8 *base_index, u8 *count);
Quoted 6 lines
is still called from
hw_atl2.c, which then assignspriv->art_base_index=base_index* 8 from its out-parameter.Is one of these now redundant? Should callers move to consume the cached
priv->art_base_index, or is there a reason to keep both sources of truth?
hw_atl2_utils_get_action_resolve_table_caps() no longer exists in v5 - it was removed as part of consolidating filter capability discovery into hw_atl2_utils_get_filter_caps(). There is only one writer of priv->art_base_index in this series, so there is no duplicate source of truth.
Quoted 13 lines
drivers/net/ethernet/aquantia/atlantic/hw_atl2/hw_atl2_utils_fw.c +7
-0+ priv->l2_filters_base_index = filter_caps.l2_filters_base_index; + priv->l2_filter_count = filter_caps.l2_filter_count; + priv->etype_filter_base_index = filter_caps.ethertype_filter_base_index; + priv->etype_filter_count = filter_caps.ethertype_filter_count; + priv->etype_filter_tag_top = + (priv->etype_filter_count >=HW_ATL2_RPF_ETYPE_TAGS ) ? + (HW_ATL2_RPF_ETYPE_TAGS ) : (HW_ATL2_RPF_ETYPE_TAGS >>1 );[Low]
The L3 and L4 paths below clampbase_indexagainstHW_ATL2_RPF_L3L4_FILTERSand usemin_t()on the count, but the etype, l2 andvlan_filter_base_indexfields are copied verbatim fromfilter_caps_su8 values (range 0..255).
Quoted 5 lines
Is that asymmetry intentional? It would be easier for future consumers to reason about if every firmware-supplied capability field were range-checked against its compile-time array bound (etype_policy[] is sized
HW_ATL2_RPF_ETYPE_FILTERS, etc.) at the FW boundary, in this one place.
The asymmetry is inherited from the vendor reference driver, which applies the same pattern. The l3/l4 min_t() clamps exist there because those counts drive array indexing against fixed-size arrays, while the etype/l2 base_index and count fields are used only as hardware register offsets - they are not used to index into software arrays in the current code. Adding defensive clamping for all fields at the FW boundary is a reasonable future cleanup, but changing the pattern beyond what the reference driver does is out of scope for this series.
Quoted 20 lines
drivers/net/ethernet/aquantia/atlantic/hw_atl2/hw_atl2_utils_fw.c +13
-0+ priv->vlan_filter_base_index = filter_caps.vlan_filter_base_index; +/* 0 - no tag, 1 - reserved for vlan-filter-offload filters */ + tag_top = + (filter_caps.vlan_filter_count ==HW_ATL2_RPF_VLAN_FILTERS ) ? + (HW_ATL2_RPF_VLAN_FILTERS -2 ) : + (HW_ATL2_RPF_VLAN_FILTERS /2 -2 ); + +if (filter_caps.vlan_filter_count >2 ) + priv->vlan_filter_count =min_t (u32, + filter_caps.vlan_filter_count -2 , + tag_top); +else + priv->vlan_filter_count =0 ;[Low]
When firmware reports filter_caps.vlan_filter_count of 1 or 2, the "> 2" gate forcespriv->vlan_filter_countto 0 silently, with no netdev_dbg()/netdev_warn(). The comment only documents the 2-entry reservation when the count is large.
Quoted 3 lines
Is the silent disable on a small but nonzero count intentional, and worth a short log line so users can tell why VLAN filtering came up disabled?
The silent disable is intentional - a firmware-reported count of 1 or 2 means all slots are consumed by the two reserved entries
(tag 0 = no tag, tag 1 = vlan-filter-offload), leaving zero usable slots. This is a hardware constraint, not a runtime error. The > 2 guard was added as a deliberate improvement over the vendor reference driver which usesmin_t(u32, vlan_filter_count - 2, tag_top) directly with no underflow protection. We will add a pr_debug() to make the condition observable for debugging.
Quoted 35 lines
drivers/net/ethernet/aquantia/atlantic/hw_atl2/hw_atl2_utils_fw.c +10
-0+ priv->l3_v4_filter_base_index = filter_caps.l3_ip4_filter_base_index; +if (priv->l3_v4_filter_base_index >=HW_ATL2_RPF_L3L4_FILTERS ) { + priv->l3_v4_filter_base_index =0 ; + priv->l3_v4_filter_count =0 ; + }else { + min_val =HW_ATL2_RPF_L3L4_FILTERS -1 - priv->l3_v4_filter_base_index; + priv->l3_v4_filter_count =min_t (u32, + filter_caps.l3_ip4_filter_count, + min_val); + }[Medium]
Is the "- 1" in this clamp intentional?The arrays are sized
HW_ATL2_RPF_L3L4_FILTERS(= 8), and consumers in the follow-up patch "net: atlantic: implement AQC113 L2/L3/L4 RX filter ops" iterate over priv->l3_v4_filters[] / l3_v6_filters[] / l4_filters[] as a half-open range:for (i = base; i < base + count; i++)
With
base_index= 0 and firmware reporting count = 8 (the natural maximum for a 4-bit field):min_val = 8 - 1 - 0 = 7 priv->l3_v4_filter_count = min_t(u32, 8, 7) = 7so slot 7 is permanently unreachable. With
base_index= 7 (still in-range, since the validity check is ">=HW_ATL2_RPF_L3L4_FILTERS"):min_val = 8 - 1 - 7 = 0 priv->l3_v4_filter_count = 0so the entire pool reports zero filters even though slot 7 exists.
Quoted 8 lines
For the half-open consumer convention, the formula that exactly fills the array is:
min_val = HW_ATL2_RPF_L3L4_FILTERS - priv->l3_v4_filter_base_index;The same pattern is duplicated in the
l3_v6and l4 blocks below, and unlike the VLAN logic in this same function (which has the "- 2" comment explaining its reservation), the "- 1" here is undocumented.
You are right about - base_index being incorrect - with base_index=7 it produces min_val=0, making that slot unreachable. We will simplify to HW_ATL2_RPF_L3L4_FILTERS - 1 (same cap the vendor reference driver uses). The - 1 is intentional - it reserves one slot at the top of the array for internal use, matching the reference driver's HW_ATL2_RPF_L3V4_FILTERS - 1 convention. We will add a comment to make that explicit. Same fix for l3_v6 and l4 blocks, and min_val will be dropped.
Quoted 26 lines
drivers/net/ethernet/aquantia/atlantic/hw_atl2/hw_atl2_utils_fw.c +25
-0+ + priv->l3_v6_filter_base_index = filter_caps.l3_ip6_filter_base_index; +if (priv->l3_v6_filter_base_index >=HW_ATL2_RPF_L3L4_FILTERS ) { + priv->l3_v6_filter_base_index =0 ; + priv->l3_v6_filter_count =0 ; + }else { + min_val =HW_ATL2_RPF_L3L4_FILTERS -1 - priv->l3_v6_filter_base_index; + priv->l3_v6_filter_count =min_t (u32, + filter_caps.l3_ip6_filter_count, + min_val); + } + + priv->l4_filter_base_index = filter_caps.l4_filter_base_index; +if (priv->l4_filter_base_index >=HW_ATL2_RPF_L3L4_FILTERS ) { + priv->l4_filter_base_index =0 ; + priv->l4_filter_count =0 ; + }else { + min_val =HW_ATL2_RPF_L3L4_FILTERS -1 - priv->l4_filter_base_index; + priv->l4_filter_count =min_t (u32, + filter_caps.l4_filter_count, + min_val); + } + +return 0 ; +}
Quoted 1 line
Same "- 1" question as above for the
l3_v6and l4 blocks.
Same fix as above for l3_v6 and l4 blocks, and min_val will be dropped.
[email protected]
maintainerPATCH v4 6/12 net: atlantic: fix AQC113 HW init: ART, L2 filter slot, MAC address
In reply to [email protected]From: Sukhdeep Singh <[email protected]>
Fix initialization issues in hw_atl2 to correctly support AQC113:
- hw_atl2_hw_reset: replace unconditional priv memset with selective field clears so that l3l4_filters[].l3_index and l4_index can be initialized to -1 (not allocated) rather than 0; 0 is a valid filter index and would incorrectly appear as an occupied slot after a reset.
- hw_atl2_hw_init_new_rx_filters: use firmware-reported ART section base and count (clamped to 16) instead of hardcoded 0xFFFF mask; enable simultaneous IPv4/IPv6 L3 filter mode (rpf_l3_v6_v4_select); tag the UC MAC slot using firmware-supplied l2_filters_base_index instead of hardcoded HW_ATL2_MAC_UC.
- hw_atl2_hw_init_rx_path: enable only the firmware-assigned MAC slot (priv->l2_filters_base_index) instead of always slot 0.
- Add hw_atl2_hw_mac_addr_set() that programs the MAC address into the firmware-assigned L2 filter slot. Wire into hw_atl2_ops replacing the A1 hw_atl_b0_hw_mac_addr_set; call it from hw_init.
- Wire .hw_get_regs into hw_atl2_ops.
--- .../aquantia/atlantic/hw_atl2/hw_atl2.c | 69 +++++++++++++++++-- .../atlantic/hw_atl2/hw_atl2_utils_fw.c | 2 + 2 files changed, 65 insertions(+), 6 deletions(-)
drivers/net/ethernet/aquantia/atlantic/hw_atl2/hw_atl2.c +63 -6
@@ -11,6 +11,7 @@#include "hw_atl/hw_atl_utils.h" #include "hw_atl/hw_atl_llh.h" #include "hw_atl/hw_atl_llh_internal.h" +#include "hw_atl2.h" #include "hw_atl2_utils.h" #include "hw_atl2_llh.h" #include "hw_atl2_internal.h"
@@ -95,12 +96,21 @@ static int hw_atl2_hw_reset(struct aq_hw_s *self) {struct hw_atl2_priv *priv = self->priv;int err; +int i; err =hw_atl2_utils_soft_reset (self);if (err)return err; -memset (priv,0 ,sizeof (*priv)); +memset (&priv->last_stats,0 ,sizeof (priv->last_stats)); +memset (priv->l3_v4_filters,0 ,sizeof (priv->l3_v4_filters)); +memset (priv->l3_v6_filters,0 ,sizeof (priv->l3_v6_filters)); +memset (priv->l4_filters,0 ,sizeof (priv->l4_filters)); +memset (priv->etype_policy,0 ,sizeof (priv->etype_policy)); +for (i =0 ; i <HW_ATL2_RPF_L3L4_FILTERS ; i++) { + priv->l3l4_filters[i].l3_index =-1 ; + priv->l3l4_filters[i].l4_index =-1 ; + } self->aq_fw_ops->set_state (self,MPI_RESET );
@@ -380,6 +390,9 @@ static void hw_atl2_hw_init_new_rx_filters(struct aq_hw_s *self) {u8 *prio_tc_map = self->aq_nic_cfg->prio_tc_map;struct hw_atl2_priv *priv = self->priv; +u32 art_first_sec, art_last_sec; +u32 art_sections; +u32 art_mask;u16 action;u8 index;int i;
@@ -394,9 +407,20 @@ static void hw_atl2_hw_init_new_rx_filters(struct aq_hw_s *self)* REC entry is used for further processing. If multiple entries match, * the lowest REC entry, Action field will be selected. */ -hw_atl2_rpf_act_rslvr_section_en_set (self,0xFFFF ); + art_last_sec =min_t (u32, + priv->art_base_index /8 + priv->art_count /8 , +16U ); + art_first_sec =min_t (u32, priv->art_base_index /8 ,16U ); + art_mask = (BIT (art_last_sec) -1 ) - (BIT (art_first_sec) -1 ); +if (!art_mask) { +/* ART base index is out of range, enabling all sections */ + art_mask =0xFFFF ; + } + art_sections =hw_atl2_rpf_act_rslvr_section_en_get (self) | art_mask; +hw_atl2_rpf_act_rslvr_section_en_set (self, art_sections); +hw_atl2_rpf_l3_v6_v4_select_set (self,1 );hw_atl2_rpfl2_uc_flr_tag_set (self,HW_ATL2_RPF_TAG_BASE_UC , -HW_ATL2_MAC_UC ); + priv->l2_filters_base_index);hw_atl2_rpfl2_bc_flr_tag_set (self,HW_ATL2_RPF_TAG_BASE_UC );/* FW reserves the beginning of ART, thus all driver entries must
@@ -484,6 +508,7 @@ static int hw_atl2_act_rslvr_table_set(struct aq_hw_s *self, u8 location,static int hw_atl2_hw_init_rx_path (struct aq_hw_s *self) {struct aq_nic_cfg_s *cfg = self->aq_nic_cfg; +struct hw_atl2_priv *priv = self->priv;int i;/* Rx TC/RSS number config */
@@ -499,7 +524,9 @@ static int hw_atl2_hw_init_rx_path(struct aq_hw_s *self)/* Multicast filters */ for (i =HW_ATL2_MAC_MAX ; i--;) { -hw_atl_rpfl2_uc_flr_en_set (self, (i ==0U ) ?1U :0U , i); +hw_atl_rpfl2_uc_flr_en_set (self, + (i == priv->l2_filters_base_index) ? +1U :0U , i);hw_atl_rpfl2unicast_flr_act_set (self,1U , i); }
@@ -530,6 +557,35 @@ static int hw_atl2_hw_init_rx_path(struct aq_hw_s *self)return aq_hw_err_from_flags (self); } +static int hw_atl2_hw_mac_addr_set (struct aq_hw_s *self,const u8 *mac_addr) +{ +struct hw_atl2_priv *priv = self->priv; +u32 location = priv->l2_filters_base_index; +unsigned int h; +unsigned int l; +int err; + +if (!mac_addr) { + err = -EINVAL ; + goto err_exit; + } + h = (mac_addr[0 ] <<8 ) | (mac_addr[1 ]); + l = (mac_addr[2 ] <<24 ) | (mac_addr[3 ] <<16 ) | + (mac_addr[4 ] <<8 ) | mac_addr[5 ]; + +hw_atl_rpfl2_uc_flr_en_set (self,0U , location); +hw_atl_rpfl2unicast_dest_addresslsw_set (self, l, location); +hw_atl_rpfl2unicast_dest_addressmsw_set (self, h, location); +hw_atl_rpfl2unicast_flr_act_set (self,1U , location); +hw_atl2_rpfl2_uc_flr_tag_set (self,HW_ATL2_RPF_TAG_BASE_UC , location); +hw_atl_rpfl2_uc_flr_en_set (self,1U , location); + + err =aq_hw_err_from_flags (self); + +err_exit: +return err; +} +static int hw_atl2_hw_init (struct aq_hw_s *self,const u8 *mac_addr) {static u32 aq_hw_atl2_igcr_table_[4 ][2 ] = {
@@ -556,7 +612,7 @@ static int hw_atl2_hw_init(struct aq_hw_s *self, const u8 *mac_addr)hw_atl2_hw_init_tx_path (self);hw_atl2_hw_init_rx_path (self); -hw_atl_b0_hw_mac_addr_set (self, mac_addr); +hw_atl2_hw_mac_addr_set (self, mac_addr); self->aq_fw_ops->set_link_speed (self, aq_nic_cfg->link_speed_msk); self->aq_fw_ops->set_state (self,MPI_INIT );
@@ -825,7 +881,7 @@ static int hw_atl2_hw_vlan_ctrl(struct aq_hw_s *self, bool enable)const struct aq_hw_ops hw_atl2_ops = { .hw_soft_reset = hw_atl2_utils_soft_reset, .hw_prepare = hw_atl2_utils_initfw, - .hw_set_mac_address = hw_atl_b0_hw_mac_addr_set, + .hw_set_mac_address = hw_atl2_hw_mac_addr_set, .hw_init = hw_atl2_hw_init, .hw_reset = hw_atl2_hw_reset, .hw_start = hw_atl_b0_hw_start,
@@ -855,6 +911,7 @@ const struct aq_hw_ops hw_atl2_ops = { .hw_rss_set = hw_atl2_hw_rss_set, .hw_rss_hash_set = hw_atl_b0_hw_rss_hash_set, .hw_tc_rate_limit_set = hw_atl2_hw_init_tx_tc_rate_limit, + .hw_get_regs = hw_atl2_utils_hw_get_regs, .hw_get_hw_stats = hw_atl2_utils_get_hw_stats, .hw_get_fw_version = hw_atl2_utils_get_fw_version, .hw_set_offload = hw_atl_b0_hw_offload_set,
drivers/net/ethernet/aquantia/atlantic/hw_atl2/hw_atl2_utils_fw.c +2 -0
@@ -627,6 +627,8 @@ int hw_atl2_utils_get_filter_caps(struct aq_hw_s *self)if (priv->art_count ==0 ) priv->art_count =128 ; priv->l2_filters_base_index = filter_caps.l2_filters_base_index; +if (priv->l2_filters_base_index >=HW_ATL2_MAC_MAX ) + priv->l2_filters_base_index =HW_ATL2_MAC_UC ; priv->l2_filter_count = filter_caps.l2_filter_count; priv->etype_filter_base_index = filter_caps.ethertype_filter_base_index; priv->etype_filter_count = filter_caps.ethertype_filter_count;
Signature · 1 line
2.43.0
Jakub Kicinski
maintainerRe: [PATCH net-next v4 6/12] net: atlantic: fix AQC113 HW init: ART, L2 filter slot, MAC address
This is an AI-generated review of your patch. The human sending this email has considered the AI review valid, or at least plausible.
---
net: atlantic: fix AQC113 HW init: ART, L2 filter slot, MAC address
This patch updates hw_atl2 init to use firmware-reported ART and L2 filter base indices for AQC113, adds hw_atl2_hw_mac_addr_set() that programs the MAC into the firmware-assigned L2 filter slot, and wires .hw_get_regs into hw_atl2_ops.
Quoted 4 lines
drivers/net/ethernet/aquantia/atlantic/hw_atl2/hw_atl2.c +0
-0
[ ... ]
Quoted 9 lines
drivers/net/ethernet/aquantia/atlantic/hw_atl2/hw_atl2.c +1
-0@@ -484,6 +508,7 @@ static int hw_atl2_act_rslvr_table_set(struct aq_hw_s *self, u8 location,static int hw_atl2_hw_init_rx_path (struct aq_hw_s *self) {struct aq_nic_cfg_s *cfg = self->aq_nic_cfg; +struct hw_atl2_priv *priv = self->priv;int i;/* Rx TC/RSS number config */
drivers/net/ethernet/aquantia/atlantic/hw_atl2/hw_atl2.c static int hw_atl2_hw_init_rx_path(struct aq_hw_s *self) · line 531
Quoted 9 lines
drivers/net/ethernet/aquantia/atlantic/hw_atl2/hw_atl2.c +3
-1@@ -499,7 +524,9 @@ static int hw_atl2_hw_init_rx_path(struct aq_hw_s *self)/* Multicast filters */ for (i =HW_ATL2_MAC_MAX ; i--;) { -hw_atl_rpfl2_uc_flr_en_set (self, (i ==0U ) ?1U :0U , i); +hw_atl_rpfl2_uc_flr_en_set (self, + (i == priv->l2_filters_base_index) ? +1U :0U , i);hw_atl_rpfl2unicast_flr_act_set (self,1U , i); }
[High]
Can the multicast list handler now collide with the UC MAC slot?
After this patch, the host MAC is programmed at slot priv->l2_filters_base_index (firmware-supplied, clamped by the new check in hw_atl2_utils_get_filter_caps() to the range [0, HW_ATL2_MAC_MAX-1] i.e. [0, 37]). However, hw_atl2_hw_multicast_list_set() still iterates multicast entries into slots HW_ATL2_MAC_MIN + i (i.e. starting at slot 1):
for (cfg->mc_list_count = 0U;
cfg->mc_list_count < count;
++cfg->mc_list_count) {
u32 i = cfg->mc_list_count;
...
hw_atl_rpfl2_uc_flr_en_set(self, 0U, HW_ATL2_MAC_MIN + i);
hw_atl_rpfl2unicast_dest_addresslsw_set(self, l,
HW_ATL2_MAC_MIN + i);
hw_atl_rpfl2unicast_dest_addressmsw_set(self, h,
HW_ATL2_MAC_MIN + i);
hw_atl2_rpfl2_uc_flr_tag_set(self, 1, HW_ATL2_MAC_MIN + i);
hw_atl_rpfl2_uc_flr_en_set(self, (cfg->is_mc_list_enabled),
HW_ATL2_MAC_MIN + i);
}If the firmware reports any value N in [1, 37] for l2_filters_base_index (which is the case the patch is intended to support, since for N=0 the change vs. the old hardcoded HW_ATL2_MAC_UC=0 is a no-op) and the multicast list contains at least N entries, the iteration with i = N - 1 writes to slot HW_ATL2_MAC_MIN + (N - 1) = N, which is the UC MAC filter slot.
Wouldn't routine ndo_set_rx_mode invocations (for example IGMP/MLD group joins or link state changes) then silently overwrite the host MAC's UC filter with a multicast address, causing the NIC to stop accepting unicast frames for the host?
Should hw_atl2_hw_multicast_list_set() also be updated to skip or offset around priv->l2_filters_base_index, in the same way hw_atl2_hw_init_rx_path() and hw_atl2_hw_mac_addr_set() were?
Sukhdeep Soni [C]
maintainerRE: [EXTERNAL] Re: [PATCH net-next v4 6/12] net: atlantic: fix AQC113 HW init: ART, L2 filter slot, MAC address
Quoted 66 lines · Jakub Kicinski
net: atlantic: fix AQC113 HW init: ART, L2 filter slot, MAC address
This patch updates
hw_atl2init to use firmware-reported ART and L2 filter base indices for AQC113, addshw_atl2_hw_mac_addr_set()that programs the MAC into the firmware-assigned L2 filter slot, and wires .hw_get_regs intohw_atl2_ops.drivers/net/ethernet/aquantia/atlantic/hw_atl2/hw_atl2.c +4
-1@@ -484,6 +508,7 @@ static int hw_atl2_act_rslvr_table_set(struct aq_hw_s *self, u8 location,static int hw_atl2_hw_init_rx_path (struct aq_hw_s *self) {struct aq_nic_cfg_s *cfg = self->aq_nic_cfg; +struct hw_atl2_priv *priv = self->priv;int i;/* Rx TC/RSS number config */ @@ -499,7 +524,9 @@ static int hw_atl2_hw_init_rx_path(struct aq_hw_s *self)/* Multicast filters */ for (i =HW_ATL2_MAC_MAX ; i--;) { -hw_atl_rpfl2_uc_flr_en_set (self, (i ==0U ) ?1U :0U , i); +hw_atl_rpfl2_uc_flr_en_set (self, + (i == priv->l2_filters_base_index) ? +1U :0U , i);hw_atl_rpfl2unicast_flr_act_set (self,1U , i); }[High]
Can the multicast list handler now collide with the UC MAC slot?
After this patch, the host MAC is programmed at slot
priv->l2_filters_base_index(firmware-supplied, clamped by the new check inhw_atl2_utils_get_filter_caps()to the range [0, HW_ATL2_MAC_MAX-1] i.e. [0, 37]). However,hw_atl2_hw_multicast_list_set()still iterates multicast entries into slotsHW_ATL2_MAC_MIN+ i (i.e. starting at slot 1):for (cfg->mc_list_count = 0U; cfg->mc_list_count < count; ++cfg->mc_list_count) { u32 i = cfg->mc_list_count; ... hw_atl_rpfl2_uc_flr_en_set(self, 0U, HW_ATL2_MAC_MIN + i); hw_atl_rpfl2unicast_dest_addresslsw_set(self, l, HW_ATL2_MAC_MIN + i); hw_atl_rpfl2unicast_dest_addressmsw_set(self, h, HW_ATL2_MAC_MIN + i); hw_atl2_rpfl2_uc_flr_tag_set(self, 1, HW_ATL2_MAC_MIN + i); hw_atl_rpfl2_uc_flr_en_set(self, (cfg->is_mc_list_enabled), HW_ATL2_MAC_MIN + i);}
If the firmware reports any value N in [1, 37] for
l2_filters_base_index(which is the case the patch is intended to support, since for N=0 the change vs. the old hardcoded HW_ATL2_MAC_UC=0 is a no-op) and the multicast list contains at least N entries, the iteration with i = N - 1 writes to slotHW_ATL2_MAC_MIN+ (N - 1) = N, which is the UC MAC filter slot.
Quoted 8 lines
Wouldn't routine
ndo_set_rx_modeinvocations (for example IGMP/MLD group joins or link state changes) then silently overwrite the host MAC's UC filter with a multicast address, causing the NIC to stop accepting unicast frames for the host?Should
hw_atl2_hw_multicast_list_set()also be updated to skip or offset aroundpriv->l2_filters_base_index, in the same wayhw_atl2_hw_init_rx_path()andhw_atl2_hw_mac_addr_set()were?
The collision you describe will be handled in v5. hw_atl2_hw_multicast_list_set() introduces base_location = priv->l2_filters_base_index + 1 and replaces all HW_ATL2_MAC_MIN + i slot references with base_location + i, placing multicast entries immediately after the UC MAC slot. So if firmware reports l2_filters_base_index = N, the UC MAC occupies slot N and multicast entries start at slot N+1 - no collision is possible.
[email protected]
maintainerPATCH v4 7/12 net: atlantic: implement AQC113 L2/L3/L4 RX filter ops
In reply to [email protected]From: Sukhdeep Singh <[email protected]>
Implement complete RX filter management for AQC113 hardware:
- Add tag-based filter policy with reference-counted sharing (hw_atl2_filter_tag_get/put), allowing multiple filter rules to share the same L3 or L4 hardware filter when their match criteria are identical.
- Implement L3 (IPv4/IPv6 source/destination address and protocol) filter find, get (program HW and increment refcount), and put (decrement refcount and clear HW when last user releases).
- Implement L4 (TCP/UDP/SCTP source/destination port) filter management with the same find/get/put pattern.
- Add combined L3L4 filter configuration (hw_atl2_new_fl3l4_configure) that translates legacy aq_rx_filter_l3l4 commands into AQC113 separate L3+L4 filter programming with Action Resolver Table (ART) entries.
- Add L2 ethertype filter set/clear (hw_atl2_hw_fl2_set/clear) with tag-based ART integration.
- Wire .hw_filter_l2_set, .hw_filter_l2_clear, .hw_filter_l3l4_set into hw_atl2_ops.
--- .../aquantia/atlantic/hw_atl2/hw_atl2.c | 518 ++++++++++++++++++ 1 file changed, 518 insertions(+)
drivers/net/ethernet/aquantia/atlantic/hw_atl2/hw_atl2.c +518 -0
@@ -87,6 +87,38 @@ const struct aq_hw_caps_s hw_atl2_caps_aqc116c = { AQ_NIC_RATE_10M, }; +/* Find tag with the same action or new free tag +* top - top inclusive tag value +* action - action for ActionResolverTable +*/ +static int hw_atl2_filter_tag_get (struct hw_atl2_tag_policy *tags, +int top,u16 action) +{ +int i; + +for (i =1 ; i <= top; i++) +if (tags[i].usage >0 && tags[i].action == action) { + tags[i].usage++; +return i; + } + +for (i =1 ; i <= top; i++) +if (tags[i].usage ==0 ) { + tags[i].usage =1 ; + tags[i].action = action; +return i; + } + +return -1 ; +} + +static void hw_atl2_filter_tag_put (struct hw_atl2_tag_policy *tags, +int tag) +{ +if (tags[tag].usage >0 ) + tags[tag].usage--; +} +static u32 hw_atl2_sem_act_rslvr_get (struct aq_hw_s *self) {return hw_atl_reg_glb_cpu_sem_get (self,HW_ATL2_FW_SM_ACT_RSLVR );
@@ -819,6 +851,489 @@ static struct aq_stats_s *hw_atl2_utils_get_hw_stats(struct aq_hw_s *self)return &self->curr_stats; } +static bool hw_atl2_rxf_l3_is_equal (struct hw_atl2_l3_filter *f1, +struct hw_atl2_l3_filter *f2) +{ +if (f1->cmd != f2->cmd) +return false; + +if (f1->cmd &HW_ATL2_RPF_L3_CMD_SA_EN ) +if (f1->srcip[0 ] != f2->srcip[0 ]) +return false; + +if (f1->cmd &HW_ATL2_RPF_L3_CMD_DA_EN ) +if (f1->dstip[0 ] != f2->dstip[0 ]) +return false; + +if (f1->cmd & (HW_ATL2_RPF_L3_CMD_PROTO_EN | +HW_ATL2_RPF_L3_V6_CMD_PROTO_EN )) +if (f1->proto != f2->proto) +return false; + +if (f1->cmd &HW_ATL2_RPF_L3_V6_CMD_SA_EN ) +if (memcmp (f1->srcip, f2->srcip,16 )) +return false; + +if (f1->cmd &HW_ATL2_RPF_L3_V6_CMD_DA_EN ) +if (memcmp (f1->dstip, f2->dstip,16 )) +return false; + +return true; +} + +static int hw_atl2_new_fl3l4_find_l3 (struct aq_hw_s *self, +struct hw_atl2_l3_filter *l3) +{ +struct hw_atl2_priv *priv = self->priv; +struct hw_atl2_l3_filter *l3_filters; +int i, first, last; + +if (l3->cmd &HW_ATL2_RPF_L3_V6_CMD_EN ) { + l3_filters = priv->l3_v6_filters; + first = priv->l3_v6_filter_base_index; + last = priv->l3_v6_filter_base_index + + priv->l3_v6_filter_count; + }else { + l3_filters = priv->l3_v4_filters; + first = priv->l3_v4_filter_base_index; + last = priv->l3_v4_filter_base_index + + priv->l3_v4_filter_count; + } +for (i = first; i < last; i++) { +if (hw_atl2_rxf_l3_is_equal (&l3_filters[i], l3)) +return i; + } + +for (i = first; i < last; i++) { +u32 l3_enable_mask =HW_ATL2_RPF_L3_CMD_EN | +HW_ATL2_RPF_L3_V6_CMD_EN ; + +if (!(l3_filters[i].cmd & l3_enable_mask)) +return i; + } + +return -ENOSPC ; +} + +static void hw_atl2_rxf_l3_get (struct aq_hw_s *self, +struct hw_atl2_l3_filter *l3,int idx, +const struct hw_atl2_l3_filter *_l3) +{ +int i; + + l3->usage++; +if (l3->usage ==1 ) { + l3->cmd = _l3->cmd; +for (i =0 ; i <4 ; i++) { + l3->srcip[i] = _l3->srcip[i]; + l3->dstip[i] = _l3->dstip[i]; + } + l3->proto = _l3->proto; + +if (l3->cmd &HW_ATL2_RPF_L3_CMD_EN ) { +hw_atl2_rpf_l3_v4_cmd_set (self, l3->cmd, idx); +hw_atl2_rpf_l3_v4_tag_set (self, idx +1 , idx); +hw_atl2_rpf_l3_v4_dest_addr_set (self, + idx, + l3->dstip[0 ]); +hw_atl2_rpf_l3_v4_src_addr_set (self, + idx, + l3->srcip[0 ]); + }else { +hw_atl2_rpf_l3_v6_cmd_set (self, l3->cmd, idx); +hw_atl2_rpf_l3_v6_tag_set (self, idx +1 , idx); +hw_atl2_rpf_l3_v6_dest_addr_set (self, + idx, + l3->dstip); +hw_atl2_rpf_l3_v6_src_addr_set (self, + idx, + l3->srcip); + } + } +} + +static void hw_atl2_rxf_l3_put (struct aq_hw_s *self, +struct hw_atl2_l3_filter *l3,int idx) +{ +if (l3->usage) + l3->usage--; + +if (!l3->usage) { +if (l3->cmd &HW_ATL2_RPF_L3_V6_CMD_EN ) +hw_atl2_rpf_l3_v6_cmd_set (self,0 , idx); +else +hw_atl2_rpf_l3_v4_cmd_set (self,0 , idx); + l3->cmd =0 ; + } +} + +static bool hw_atl2_rxf_l4_is_equal (struct hw_atl2_l4_filter *f1, +struct hw_atl2_l4_filter *f2) +{ +if (f1->cmd != f2->cmd) +return false; + +if (f1->cmd &HW_ATL2_RPF_L4_CMD_SP_EN ) +if (f1->sport != f2->sport) +return false; + +if (f1->cmd &HW_ATL2_RPF_L4_CMD_DP_EN ) +if (f1->dport != f2->dport) +return false; + +return true; +} + +static int hw_atl2_new_fl3l4_find_l4 (struct aq_hw_s *self, +struct hw_atl2_l4_filter *l4) +{ +struct hw_atl2_priv *priv = self->priv; +int i, first, last; + + first = priv->l4_filter_base_index; + last = priv->l4_filter_base_index + priv->l4_filter_count; + +for (i = first; i < last; i++) +if (hw_atl2_rxf_l4_is_equal (&priv->l4_filters[i], l4)) +return i; + +for (i = first; i < last; i++) +if ((priv->l4_filters[i].cmd &HW_ATL2_RPF_L4_CMD_EN ) ==0 ) +return i; + +return -ENOSPC ; +} + +static void hw_atl2_rxf_l4_put (struct aq_hw_s *self, +struct hw_atl2_l4_filter *l4,int idx) +{ +if (l4->usage) + l4->usage--; + +if (!l4->usage) { + l4->cmd =0 ; +hw_atl2_rpf_l4_cmd_set (self, l4->cmd, idx); + } +} + +static void hw_atl2_rxf_l4_get (struct aq_hw_s *self, +struct hw_atl2_l4_filter *l4,int idx, +const struct hw_atl2_l4_filter *_l4) +{ + l4->usage++; +if (l4->usage ==1 ) { + l4->cmd = _l4->cmd; + l4->sport = _l4->sport; + l4->dport = _l4->dport; + +hw_atl2_rpf_l4_cmd_set (self, l4->cmd, idx); +hw_atl2_rpf_l4_tag_set (self, idx +1 , idx); +hw_atl_rpf_l4_spd_set (self, l4->sport, idx); +hw_atl_rpf_l4_dpd_set (self, l4->dport, idx); + } +} + +static int hw_atl2_new_fl3l4_configure (struct aq_hw_s *self, +struct aq_rx_filter_l3l4 *data) +{ +struct hw_atl2_priv *priv = self->priv; +s8 old_l3_index = priv->l3l4_filters[data->location].l3_index; +s8 old_l4_index = priv->l3l4_filters[data->location].l4_index; +u8 old_ipv6 = priv->l3l4_filters[data->location].ipv6; +struct hw_atl2_l3_filter *l3_filters; +struct hw_atl2_l3_filter l3; +struct hw_atl2_l4_filter l4; +s8 l3_idx =-1 ; +s8 l4_idx =-1 ; + +if (!(data->cmd &HW_ATL_RX_ENABLE_FLTR_L3L4 )) +return 0 ; + +memset (&l3,0 ,sizeof (l3)); +memset (&l4,0 ,sizeof (l4)); + +/* convert legacy filter to new */ +if (data->cmd &HW_ATL_RX_ENABLE_CMP_PROT_L4 ) { + l3.cmd |= data->is_ipv6 ?HW_ATL2_RPF_L3_V6_CMD_PROTO_EN : +HW_ATL2_RPF_L3_CMD_PROTO_EN ; + l3.cmd |= data->is_ipv6 ?HW_ATL2_RPF_L3_V6_CMD_EN : +HW_ATL2_RPF_L3_CMD_EN ; +switch (data->cmd &0x7 ) { +case HW_ATL_RX_TCP : + l3.cmd |=IPPROTO_TCP << (data->is_ipv6 ?0x18 :8 ); +break ; +case HW_ATL_RX_UDP : + l3.cmd |=IPPROTO_UDP << (data->is_ipv6 ?0x18 :8 ); +break ; +case HW_ATL_RX_SCTP : + l3.cmd |=IPPROTO_SCTP << (data->is_ipv6 ?0x18 :8 ); +break ; +case HW_ATL_RX_ICMP : + l3.cmd |=IPPROTO_ICMP << (data->is_ipv6 ?0x18 :8 ); +break ; + } + } + +if (data->cmd &HW_ATL_RX_ENABLE_CMP_SRC_ADDR_L3 ) { +if (data->is_ipv6) { + l3.cmd |=HW_ATL2_RPF_L3_V6_CMD_SA_EN | +HW_ATL2_RPF_L3_V6_CMD_EN ; +memcpy (l3.srcip, data->ip_src,sizeof (l3.srcip)); + }else { + l3.cmd |=HW_ATL2_RPF_L3_CMD_SA_EN | +HW_ATL2_RPF_L3_CMD_EN ; + l3.srcip[0 ] = data->ip_src[0 ]; + } + } +if (data->cmd &HW_ATL_RX_ENABLE_CMP_DEST_ADDR_L3 ) { +if (data->is_ipv6) { + l3.cmd |=HW_ATL2_RPF_L3_V6_CMD_DA_EN | +HW_ATL2_RPF_L3_V6_CMD_EN ; +memcpy (l3.dstip, data->ip_dst,sizeof (l3.dstip)); + }else { + l3.cmd |=HW_ATL2_RPF_L3_CMD_DA_EN | +HW_ATL2_RPF_L3_CMD_EN ; + l3.dstip[0 ] = data->ip_dst[0 ]; + } + } + +if (data->cmd &HW_ATL_RX_ENABLE_CMP_DEST_PORT_L4 ) { + l4.cmd |=HW_ATL2_RPF_L4_CMD_DP_EN |HW_ATL2_RPF_L4_CMD_EN ; + l4.dport = data->p_dst; + } +if (data->cmd &HW_ATL_RX_ENABLE_CMP_SRC_PORT_L4 ) { + l4.cmd |=HW_ATL2_RPF_L4_CMD_SP_EN |HW_ATL2_RPF_L4_CMD_EN ; + l4.sport = data->p_src; + } + +/* find L3 and L4 filters */ +if (l3.cmd & (HW_ATL2_RPF_L3_CMD_EN |HW_ATL2_RPF_L3_V6_CMD_EN )) { + l3_idx =hw_atl2_new_fl3l4_find_l3 (self, &l3); +if (l3_idx <0 ) +return l3_idx; + +if (l3.cmd &HW_ATL2_RPF_L3_V6_CMD_EN ) + l3_filters = priv->l3_v6_filters; +else + l3_filters = priv->l3_v4_filters; + +if (priv->l3l4_filters[data->location].l3_index != l3_idx || + old_ipv6 != !!(l3.cmd &HW_ATL2_RPF_L3_V6_CMD_EN )) +hw_atl2_rxf_l3_get (self, &l3_filters[l3_idx], + l3_idx, &l3); + } + +if (old_l3_index !=-1 ) { +if (old_ipv6) + l3_filters = priv->l3_v6_filters; +else + l3_filters = priv->l3_v4_filters; + +if (!(hw_atl2_rxf_l3_is_equal (&l3, + &l3_filters[old_l3_index]))) { +hw_atl2_rxf_l3_put (self, + &l3_filters[old_l3_index], + old_l3_index); + } + } +if (l3.cmd &HW_ATL2_RPF_L3_V6_CMD_EN ) + priv->l3l4_filters[data->location].ipv6 =1 ; +else + priv->l3l4_filters[data->location].ipv6 =0 ; + priv->l3l4_filters[data->location].l3_index = l3_idx; + +if (l4.cmd &HW_ATL2_RPF_L4_CMD_EN ) { + l4_idx =hw_atl2_new_fl3l4_find_l4 (self, &l4); +if (l4_idx <0 ) +return -EINVAL ; + +if (priv->l3l4_filters[data->location].l4_index != l4_idx) +hw_atl2_rxf_l4_get (self, &priv->l4_filters[l4_idx], + l4_idx, &l4); + } + +if (old_l4_index !=-1 ) { +if (!(hw_atl2_rxf_l4_is_equal (&priv->l4_filters[old_l4_index], + &l4))) { +hw_atl2_rxf_l4_put (self, + &priv->l4_filters[old_l4_index], + old_l4_index); + } + } + priv->l3l4_filters[data->location].l4_index = l4_idx; + +return 0 ; +} + +static int hw_atl2_hw_fl3l4_set (struct aq_hw_s *self, +struct aq_rx_filter_l3l4 *data) +{ +struct hw_atl2_priv *priv = self->priv; +struct hw_atl2_l3_filter *l3_filters; +struct hw_atl2_l3_filter *l3 =NULL ; +struct hw_atl2_l4_filter *l4 =NULL ; +u8 location = data->location; +u32 req_tag =0 ; +u16 action =0 ; +int l3_index; +int l4_index; +u32 mask =0 ; +u8 index; +u8 ipv6; +int res; + + res =hw_atl2_new_fl3l4_configure (self, data); +if (res) +return res; + + l3_index = priv->l3l4_filters[location].l3_index; + l4_index = priv->l3l4_filters[location].l4_index; + ipv6 = priv->l3l4_filters[location].ipv6; +if (ipv6) + l3_filters = priv->l3_v6_filters; +else + l3_filters = priv->l3_v4_filters; + +if (!(data->cmd &HW_ATL_RX_ENABLE_FLTR_L3L4 )) { +if (l3_index >-1 ) +hw_atl2_rxf_l3_put (self, &l3_filters[l3_index], + l3_index); + +if (l4_index >-1 ) +hw_atl2_rxf_l4_put (self, &priv->l4_filters[l4_index], + l4_index); + + priv->l3l4_filters[location].l3_index =-1 ; + priv->l3l4_filters[location].l4_index =-1 ; + index = priv->art_base_index +HW_ATL2_RPF_L3L4_USER_INDEX + + location; +hw_atl2_act_rslvr_table_set (self, index,0 ,0 , +HW_ATL2_ACTION_DISABLE ); + +return 0 ; + } + +if (l3_index !=-1 ) + l3 = &l3_filters[l3_index]; +if (l4_index !=-1 ) + l4 = &priv->l4_filters[l4_index]; + +if (l4 && (l4->cmd &HW_ATL2_RPF_L4_CMD_EN )) { + req_tag |= (l4_index +1 ) <<HW_ATL2_RPF_TAG_L4_OFFSET ; + mask |=HW_ATL2_RPF_TAG_L4_MASK ; + } + +if (l3) { +if (l3->cmd &HW_ATL2_RPF_L3_V6_CMD_EN ) { + req_tag |= (l3_index +1 ) << +HW_ATL2_RPF_TAG_L3_V6_OFFSET ; + mask |=HW_ATL2_RPF_TAG_L3_V6_MASK ; + }else { + req_tag |= (l3_index +1 ) << +HW_ATL2_RPF_TAG_L3_V4_OFFSET ; + mask |=HW_ATL2_RPF_TAG_L3_V4_MASK ; + } + } + +if (data->cmd & (HW_ATL_RX_HOST <<HW_ATL2_RPF_L3_L4_ACTF_SHIFT )) + action =HW_ATL2_ACTION_ASSIGN_QUEUE ((data->cmd & +HW_ATL2_RPF_L3_L4_RXQF_MSK ) >> +HW_ATL2_RPF_L3_L4_RXQF_SHIFT ); +else + action =HW_ATL2_ACTION_DROP ; + + index = priv->art_base_index +HW_ATL2_RPF_L3L4_USER_INDEX + location; +hw_atl2_act_rslvr_table_set (self, index, req_tag, mask, action); +return 0 ; +} + +static int hw_atl2_hw_fl2_set (struct aq_hw_s *self, +struct aq_rx_filter_l2 *data) +{ +struct hw_atl2_priv *priv = self->priv; +u32 mask =HW_ATL2_RPF_TAG_ET_MASK ; +u32 req_tag =0 ; +u16 action =0 ; +u32 location; +u8 index; +int tag; + + location = priv->etype_filter_base_index + data->location; + +hw_atl_rpf_etht_flr_set (self, data->ethertype, location); +hw_atl_rpf_etht_user_priority_en_set (self, + !!data->user_priority_en, + location); +if (data->user_priority_en) { +hw_atl_rpf_etht_user_priority_set (self, + data->user_priority, + location); + req_tag |= data->user_priority <<HW_ATL2_RPF_TAG_PCP_OFFSET ; + mask |=HW_ATL2_RPF_TAG_PCP_MASK ; + } + +if (data->queue <0 ) { +hw_atl_rpf_etht_flr_act_set (self,0U , location); +hw_atl_rpf_etht_rx_queue_en_set (self,0U , location); + action =HW_ATL2_ACTION_DROP ; + }else { +hw_atl_rpf_etht_flr_act_set (self,1U , location); +hw_atl_rpf_etht_rx_queue_en_set (self,1U , location); +hw_atl_rpf_etht_rx_queue_set (self, data->queue, location); + action =HW_ATL2_ACTION_ASSIGN_QUEUE (data->queue); + } + + tag =hw_atl2_filter_tag_get (priv->etype_policy, + priv->etype_filter_tag_top, + action); + +if (tag <0 ) +return -ENOSPC ; + + req_tag |= tag <<HW_ATL2_RPF_TAG_ET_OFFSET ; +hw_atl2_rpf_etht_flr_tag_set (self, tag, location); + index = priv->art_base_index +HW_ATL2_RPF_ET_PCP_USER_INDEX + + data->location; +hw_atl2_act_rslvr_table_set (self, index, req_tag, mask, action); + +hw_atl_rpf_etht_flr_en_set (self,1U , location); + +return aq_hw_err_from_flags (self); +} + +static int hw_atl2_hw_fl2_clear (struct aq_hw_s *self, +struct aq_rx_filter_l2 *data) +{ +struct hw_atl2_priv *priv = self->priv; +u32 location; +u8 index; +u32 tag; + + location = priv->etype_filter_base_index + data->location; +hw_atl_rpf_etht_flr_en_set (self,0U , location); +hw_atl_rpf_etht_flr_set (self,0U , location); +hw_atl_rpf_etht_user_priority_en_set (self,0U , location); + + index = priv->art_base_index +HW_ATL2_RPF_ET_PCP_USER_INDEX + + data->location; +hw_atl2_act_rslvr_table_set (self, index,0 ,0 , +HW_ATL2_ACTION_DISABLE ); + tag =hw_atl2_rpf_etht_flr_tag_get (self, location); +hw_atl2_filter_tag_put (priv->etype_policy, tag); + +return aq_hw_err_from_flags (self); +} + +/* +* Set VLAN filter table +* Configure VLAN filter table to accept (and assign the queue) traffic +* for the particular vlan ids. +* Note: use this function under vlan promisc mode not to lost the traffic +* +* param - aq_hw_s +* param - aq_rx_filter_vlan VLAN filter configuration +* return 0 - OK, <0 - error +*/ static int hw_atl2_hw_vlan_set (struct aq_hw_s *self,struct aq_rx_filter_vlan *aq_vlans) {
@@ -900,6 +1415,9 @@ const struct aq_hw_ops hw_atl2_ops = { .hw_ring_rx_init = hw_atl2_hw_ring_rx_init, .hw_ring_tx_init = hw_atl2_hw_ring_tx_init, .hw_packet_filter_set = hw_atl2_hw_packet_filter_set, + .hw_filter_l2_set = hw_atl2_hw_fl2_set, + .hw_filter_l2_clear = hw_atl2_hw_fl2_clear, + .hw_filter_l3l4_set = hw_atl2_hw_fl3l4_set, .hw_filter_vlan_set = hw_atl2_hw_vlan_set, .hw_filter_vlan_ctrl = hw_atl2_hw_vlan_ctrl, .hw_multicast_list_set = hw_atl2_hw_multicast_list_set,
Signature · 1 line
2.43.0
Jakub Kicinski
maintainerRe: [PATCH net-next v4 7/12] net: atlantic: implement AQC113 L2/L3/L4 RX filter ops
This is an AI-generated review of your patch. The human sending this email has considered the AI review valid, or at least plausible.
---
net: atlantic: implement AQC113 L2/L3/L4 RX filter ops
This patch adds tag-based L2/L3/L4 RX filter management for AQC113, including reference-counted L3 and L4 filter slots, an ART-based L3L4 configuration helper, and L2 ethertype set/clear, and wires the new ops into hw_atl2_ops.
[Low]
The commit message describes hw_atl2_filter_tag_get/put as:
Add tag-based filter policy with reference-counted sharing (hw_atl2_filter_tag_get/put), allowing multiple filter rules to share the same L3 or L4 hardware filter when their match criteria are identical.
In the patch, hw_atl2_filter_tag_get/put operate only on priv->etype_policy[] and are called only from hw_atl2_hw_fl2_set/clear. The L3 and L4 sharing is implemented separately via the usage field on hw_atl2_l3_filter / hw_atl2_l4_filter and hw_atl2_rxf_l3_get/put / hw_atl2_rxf_l4_get/put.
Could the description be reworded so it does not conflate the etype tag policy with the L3/L4 filter refcounts?
Quoted 21 lines
drivers/net/ethernet/aquantia/atlantic/hw_atl2/hw_atl2.c +13
-0@@ -87,6 +87,38 @@ const struct aq_hw_caps_s hw_atl2_caps_aqc116c = { AQ_NIC_RATE_10M, }; +/* Find tag with the same action or new free tag +* top - top inclusive tag value +* action - action for ActionResolverTable +*/ +static int hw_atl2_filter_tag_get (struct hw_atl2_tag_policy *tags, +int top,u16 action) +{ +int i; + +for (i =1 ; i <= top; i++) +if (tags[i].usage >0 && tags[i].action == action) { + tags[i].usage++; +return i;
drivers/net/ethernet/aquantia/atlantic/hw_atl2/hw_atl2.c const struct aq_hw_caps_s hw_atl2_caps_aqc116c = { · line 112
Quoted 10 lines
drivers/net/ethernet/aquantia/atlantic/hw_atl2/hw_atl2.c +10
-0+ } + +for (i =1 ; i <= top; i++) +if (tags[i].usage ==0 ) { + tags[i].usage =1 ; + tags[i].action = action; +return i; + } + +return -1 ;
[Low]
Sibling helpers introduced in this patch (hw_atl2_new_fl3l4_find_l3 / _find_l4) return -ENOSPC on the no-free-slot path, but this helper returns the bare value -1.
The current caller hw_atl2_hw_fl2_set() translates it into -ENOSPC manually, but if a future caller propagates the value unchanged it becomes -EPERM. Would returning -ENOSPC here directly be more consistent?
Quoted 1 line
drivers/net/ethernet/aquantia/atlantic/hw_atl2/hw_atl2.c +1
-0+}
[ ... ]
Quoted 12 lines
drivers/net/ethernet/aquantia/atlantic/hw_atl2/hw_atl2.c +8
-0@@ -823,6 +855,489 @@ static struct aq_stats_s *hw_atl2_utils_get_hw_stats(struct aq_hw_s *self)return &self->curr_stats; } +static bool hw_atl2_rxf_l3_is_equal (struct hw_atl2_l3_filter *f1, +struct hw_atl2_l3_filter *f2) +{ +if (f1->cmd != f2->cmd) +return false; + +if (f1->cmd &HW_ATL2_RPF_L3_CMD_SA_EN ) +if (f1->srcip[0 ] != f2->srcip[0 ])
drivers/net/ethernet/aquantia/atlantic/hw_atl2/hw_atl2.c static struct aq_stats_s *hw_atl2_utils_get_hw_stats(struct aq_hw_s *self) · line 875
Quoted 10 lines
drivers/net/ethernet/aquantia/atlantic/hw_atl2/hw_atl2.c +10
-0+return false; + +if (f1->cmd &HW_ATL2_RPF_L3_CMD_DA_EN ) +if (f1->dstip[0 ] != f2->dstip[0 ]) +return false; + +if (f1->cmd & (HW_ATL2_RPF_L3_CMD_PROTO_EN | +HW_ATL2_RPF_L3_V6_CMD_PROTO_EN )) +if (f1->proto != f2->proto) +return false;
[Low]
Where is l3.proto ever populated? In hw_atl2_new_fl3l4_configure() the local l3 is memset to 0 and the protocol value is encoded into the upper bits of l3.cmd via:
l3.cmd |= IPPROTO_TCP << (data->is_ipv6 ? 0x18 : 8);
hw_atl2_rxf_l3_get() then copies _l3->proto (=0) into the tracked slot, so this proto comparison appears to be 0 == 0 in all cases. The actual protocol comparison happens implicitly via the f1->cmd != f2->cmd check above.
Should l3.proto be removed, or populated consistently from the cmd encoding, so future code that begins setting one but not the other does not silently produce false negatives in the sharing check?
Quoted 11 lines
drivers/net/ethernet/aquantia/atlantic/hw_atl2/hw_atl2.c +11
-0+ +if (f1->cmd &HW_ATL2_RPF_L3_V6_CMD_SA_EN ) +if (memcmp (f1->srcip, f2->srcip,16 )) +return false; + +if (f1->cmd &HW_ATL2_RPF_L3_V6_CMD_DA_EN ) +if (memcmp (f1->dstip, f2->dstip,16 )) +return false; + +return true; +}
[ ... ]
Quoted 26 lines
drivers/net/ethernet/aquantia/atlantic/hw_atl2/hw_atl2.c +26
-0+static void hw_atl2_rxf_l3_get (struct aq_hw_s *self, +struct hw_atl2_l3_filter *l3,int idx, +const struct hw_atl2_l3_filter *_l3) +{ +int i; + + l3->usage++; +if (l3->usage ==1 ) { + l3->cmd = _l3->cmd; +for (i =0 ; i <4 ; i++) { + l3->srcip[i] = _l3->srcip[i]; + l3->dstip[i] = _l3->dstip[i]; + } + l3->proto = _l3->proto; + +if (l3->cmd &HW_ATL2_RPF_L3_CMD_EN ) { +hw_atl2_rpf_l3_v4_cmd_set (self, l3->cmd, idx); +hw_atl2_rpf_l3_v4_tag_set (self, idx +1 , idx); +hw_atl2_rpf_l3_v4_dest_addr_set (self, + idx, + l3->dstip[0 ]); +hw_atl2_rpf_l3_v4_src_addr_set (self, + idx, + l3->srcip[0 ]); + }else { +hw_atl2_rpf_l3_v6_cmd_set (self, l3->cmd, idx);
drivers/net/ethernet/aquantia/atlantic/hw_atl2/hw_atl2.c static struct aq_stats_s *hw_atl2_utils_get_hw_stats(struct aq_hw_s *self) · line 953
Quoted 10 lines
drivers/net/ethernet/aquantia/atlantic/hw_atl2/hw_atl2.c +10
-0+hw_atl2_rpf_l3_v6_tag_set (self, idx +1 , idx); +hw_atl2_rpf_l3_v6_dest_addr_set (self, + idx, + l3->dstip); +hw_atl2_rpf_l3_v6_src_addr_set (self, + idx, + l3->srcip); + } + } +}
[Medium]
Is the ordering of the MMIO writes here intentional?
The cmd word containing the EN/SA_EN/DA_EN/PROTO_EN bits is committed first via hw_atl2_rpf_l3_v4_cmd_set() (the v4 mask is 0xFFFF and includes the EN bit), and only afterwards are the destination and source address registers programmed.
Between the cmd write and the address writes, the filter is enabled while its DA/SA registers still hold whatever value they had before (stale, zero, or a previously programmed filter's addresses).
The IPv6 path is worse because hw_atl2_rpf_l3_v6_dest_addr_set() and _src_addr_set() each issue four separate register writes (one per dword), so the filter is enabled with a partially-programmed address for several MMIO cycles.
The same pattern is in hw_atl2_rxf_l4_get() below. Would it be safer to program the addresses (or ports) and tag first and write the cmd word with EN last?
[ ... ]
Quoted 20 lines
drivers/net/ethernet/aquantia/atlantic/hw_atl2/hw_atl2.c +20
-0+static void hw_atl2_rxf_l4_get (struct aq_hw_s *self, +struct hw_atl2_l4_filter *l4,int idx, +const struct hw_atl2_l4_filter *_l4) +{ + l4->usage++; +if (l4->usage ==1 ) { + l4->cmd = _l4->cmd; + l4->sport = _l4->sport; + l4->dport = _l4->dport; + +hw_atl2_rpf_l4_cmd_set (self, l4->cmd, idx); +hw_atl2_rpf_l4_tag_set (self, idx +1 , idx); +hw_atl_rpf_l4_spd_set (self, l4->sport, idx); +hw_atl_rpf_l4_dpd_set (self, l4->dport, idx); + } +} + +static int hw_atl2_new_fl3l4_configure (struct aq_hw_s *self, +struct aq_rx_filter_l3l4 *data) +{
[ ... ]
Quoted 9 lines
drivers/net/ethernet/aquantia/atlantic/hw_atl2/hw_atl2.c +9
-0+/* convert legacy filter to new */ +if (data->cmd &HW_ATL_RX_ENABLE_CMP_PROT_L4 ) { + l3.cmd |= data->is_ipv6 ?HW_ATL2_RPF_L3_V6_CMD_PROTO_EN : +HW_ATL2_RPF_L3_CMD_PROTO_EN ; + l3.cmd |= data->is_ipv6 ?HW_ATL2_RPF_L3_V6_CMD_EN : +HW_ATL2_RPF_L3_CMD_EN ; +switch (data->cmd &0x7 ) { +case HW_ATL_RX_TCP : + l3.cmd |=IPPROTO_TCP << (data->is_ipv6 ?0x18 :8 );
drivers/net/ethernet/aquantia/atlantic/hw_atl2/hw_atl2.c static struct aq_stats_s *hw_atl2_utils_get_hw_stats(struct aq_hw_s *self) · line 1073
Quoted 10 lines
drivers/net/ethernet/aquantia/atlantic/hw_atl2/hw_atl2.c +10
-0+break ; +case HW_ATL_RX_UDP : + l3.cmd |=IPPROTO_UDP << (data->is_ipv6 ?0x18 :8 ); +break ; +case HW_ATL_RX_SCTP : + l3.cmd |=IPPROTO_SCTP << (data->is_ipv6 ?0x18 :8 ); +break ; +case HW_ATL_RX_ICMP : + l3.cmd |=IPPROTO_ICMP << (data->is_ipv6 ?0x18 :8 ); +break ;
[Low]
For the IPv6 branch of HW_ATL_RX_ICMP, should the next-header value be IPPROTO_ICMPV6 (58) rather than IPPROTO_ICMP (1)? Real ICMPv6 traffic uses next-header 58, so this branch will not match ICMPv6 packets.
The aq_set_data_fl3l4() helper in aq_filters.c does not currently set HW_ATL_RX_ICMP for any flow type, so the case is not reachable from the in-tree ethtool ntuple path today, but it is written explicitly here.
[Low]
The shift values 0x18 and 8 are repeated four times here, while the matching enable bits are named constants (HW_ATL2_RPF_L3_CMD_PROTO_EN and HW_ATL2_RPF_L3_V6_CMD_PROTO_EN). Would a pair of named shift macros (for example HW_ATL2_RPF_L3_CMD_PROTO_SHIFT / HW_ATL2_RPF_L3_V6_CMD_PROTO_SHIFT) make the relationship between the enable bit and the protocol byte position clearer and harder to mis-edit?
Quoted 2 lines
drivers/net/ethernet/aquantia/atlantic/hw_atl2/hw_atl2.c +2
-0+ } + }
[ ... ]
Quoted 30 lines
drivers/net/ethernet/aquantia/atlantic/hw_atl2/hw_atl2.c +30
-0+/* find L3 and L4 filters */ +if (l3.cmd & (HW_ATL2_RPF_L3_CMD_EN |HW_ATL2_RPF_L3_V6_CMD_EN )) { + l3_idx =hw_atl2_new_fl3l4_find_l3 (self, &l3); +if (l3_idx <0 ) +return l3_idx; + +if (l3.cmd &HW_ATL2_RPF_L3_V6_CMD_EN ) + l3_filters = priv->l3_v6_filters; +else + l3_filters = priv->l3_v4_filters; + +if (priv->l3l4_filters[data->location].l3_index != l3_idx || + old_ipv6 != !!(l3.cmd &HW_ATL2_RPF_L3_V6_CMD_EN )) +hw_atl2_rxf_l3_get (self, &l3_filters[l3_idx], + l3_idx, &l3); + } + +if (old_l3_index !=-1 ) { +if (old_ipv6) + l3_filters = priv->l3_v6_filters; +else + l3_filters = priv->l3_v4_filters; + +if (!(hw_atl2_rxf_l3_is_equal (&l3, + &l3_filters[old_l3_index]))) { +hw_atl2_rxf_l3_put (self, + &l3_filters[old_l3_index], + old_l3_index); + } + }
drivers/net/ethernet/aquantia/atlantic/hw_atl2/hw_atl2.c static struct aq_stats_s *hw_atl2_utils_get_hw_stats(struct aq_hw_s *self) · line 1148
Quoted 10 lines
drivers/net/ethernet/aquantia/atlantic/hw_atl2/hw_atl2.c +10
-0+if (l3.cmd &HW_ATL2_RPF_L3_V6_CMD_EN ) + priv->l3l4_filters[data->location].ipv6 =1 ; +else + priv->l3l4_filters[data->location].ipv6 =0 ; + priv->l3l4_filters[data->location].l3_index = l3_idx; + +if (l4.cmd &HW_ATL2_RPF_L4_CMD_EN ) { + l4_idx =hw_atl2_new_fl3l4_find_l4 (self, &l4); +if (l4_idx <0 ) +return -EINVAL ;
[High, Low]
By the time this L4 search runs, hw_atl2_new_fl3l4_configure() has already mutated state for the new request:
- hw_atl2_rxf_l3_get() programmed the new L3 hardware filter and bumped its refcount,
- the old L3 filter has typically been released via hw_atl2_rxf_l3_put() (clearing its HW slot if it was the last user, since match criteria differ), and
- priv->l3l4_filters[location].l3_index and .ipv6 have been overwritten to point at the new L3 slot.
When this branch returns, hw_atl2_hw_fl3l4_set() simply propagates the error and skips the ART write, so the device is left with the new L3 filter enabled (refcount 1) but no ART entry referencing its tag, the old ART entry still pointing at the now-cleared old L3 tag, and the user's previously-installed working rule effectively destroyed.
Userspace receives an error and will not call the disable path, so the new L3 slot stays leaked. With only HW_ATL2_RPF_L3L4_FILTERS slots per family, repeated failures rapidly exhaust the pool.
Could this path roll back the L3-side state (and refcounts) before returning?
As a separate question, the L3 path uses:
if (l3_idx < 0)
return l3_idx;while the L4 path overwrites the more specific value with -EINVAL:
if (l4_idx < 0)
return -EINVAL;Should the L4 path also propagate l4_idx so userspace can distinguish -ENOSPC from -EINVAL?
Quoted 5 lines
drivers/net/ethernet/aquantia/atlantic/hw_atl2/hw_atl2.c +5
-0+ +if (priv->l3l4_filters[data->location].l4_index != l4_idx) +hw_atl2_rxf_l4_get (self, &priv->l4_filters[l4_idx], + l4_idx, &l4); + }
[ ... ]
Quoted 3 lines
drivers/net/ethernet/aquantia/atlantic/hw_atl2/hw_atl2.c +3
-0+static int hw_atl2_hw_fl2_set (struct aq_hw_s *self, +struct aq_rx_filter_l2 *data) +{
[ ... ]
Quoted 7 lines
drivers/net/ethernet/aquantia/atlantic/hw_atl2/hw_atl2.c +7
-0+ tag =hw_atl2_filter_tag_get (priv->etype_policy, + priv->etype_filter_tag_top, + action); + +if (tag <0 ) +return -ENOSPC ; +
drivers/net/ethernet/aquantia/atlantic/hw_atl2/hw_atl2.c static struct aq_stats_s *hw_atl2_utils_get_hw_stats(struct aq_hw_s *self) · line 1302
Quoted 10 lines
drivers/net/ethernet/aquantia/atlantic/hw_atl2/hw_atl2.c +10
-0+ req_tag |= tag <<HW_ATL2_RPF_TAG_ET_OFFSET ; +hw_atl2_rpf_etht_flr_tag_set (self, tag, location); + index = priv->art_base_index +HW_ATL2_RPF_ET_PCP_USER_INDEX + + data->location; +hw_atl2_act_rslvr_table_set (self, index, req_tag, mask, action); + +hw_atl_rpf_etht_flr_en_set (self,1U , location); + +return aq_hw_err_from_flags (self); +}
[Medium]
Once hw_atl2_filter_tag_get() succeeds, the etype_policy slot's usage count has been incremented. After that point this function still has two ways to return an error without releasing that tag:
- hw_atl2_act_rslvr_table_set() may return an error (semaphore poll timeout) — its return value is ignored here, but
- aq_hw_err_from_flags(self) at the end can return -ENXIO or -EIO if AQ_HW_FLAG_ERR_UNPLUG / AQ_HW_FLAG_ERR_HW have been set during the register writes above.
Because HW_ATL2_RPF_ETYPE_TAGS is small (7), repeated transient HW errors would gradually permanently exhaust the etype tag pool until no L2 filter can be installed. Should a failure path here call hw_atl2_filter_tag_put() before returning?
Sukhdeep Soni [C]
maintainerRE: [EXTERNAL] Re: [PATCH net-next v4 7/12] net: atlantic: implement AQC113 L2/L3/L4 RX filter ops
Quoted 15 lines · Jakub Kicinski
net: atlantic: implement AQC113 L2/L3/L4 RX filter ops
This patch adds tag-based L2/L3/L4 RX filter management for AQC113, including reference-counted L3 and L4 filter slots, an ART-based L3L4 configuration helper, and L2 ethertype set/clear, and wires the new ops into
hw_atl2_ops.[Low]
The commit message describes hw_atl2_filter_tag_get/put as:Add tag-based filter policy with reference-counted sharing (hw_atl2_filter_tag_get/put), allowing multiple filter rules to share the same L3 or L4 hardware filter when their match criteria are identical.
Quoted 8 lines
In the patch, hw_atl2_filter_tag_get/put operate only on priv->etype_policy[] and are called only from hw_atl2_hw_fl2_set/clear. The L3 and L4 sharing is implemented separately via the usage field on
hw_atl2_l3_filter/hw_atl2_l4_filterand hw_atl2_rxf_l3_get/put / hw_atl2_rxf_l4_get/put.Could the description be reworded so it does not conflate the etype tag policy with the L3/L4 filter refcounts?
The commit message has been reworded in v5 to clearly separate the two mechanisms:
- hw_atl2_filter_tag_get/put - tag-based policy for L2 ethertype filters, allocating and releasing ART tag slots
- hw_atl2_rxf_l3_get/put / hw_atl2_rxf_l4_get/put - serialized usage counter based sharing for L3 and L4 hardware filter slots when match criteria are identical
Quoted 37 lines
drivers/net/ethernet/aquantia/atlantic/hw_atl2/hw_atl2.c +23
-0@@ -87,6 +87,38 @@ const struct aq_hw_caps_s hw_atl2_caps_aqc116c = { AQ_NIC_RATE_10M, }; +/* Find tag with the same action or new free tag +* top - top inclusive tag value +* action - action for ActionResolverTable +*/ +static int hw_atl2_filter_tag_get (struct hw_atl2_tag_policy *tags, +int top,u16 action) +{ +int i; + +for (i =1 ; i <= top; i++) +if (tags[i].usage >0 && tags[i].action == action) { + tags[i].usage++; +return i; + } + +for (i =1 ; i <= top; i++) +if (tags[i].usage ==0 ) { + tags[i].usage =1 ; + tags[i].action = action; +return i; + } + +return -1 ;[Low]
Sibling helpers introduced in this patch (hw_atl2_new_fl3l4_find_l3/_find_l4) return-ENOSPCon the no-free-slot path, but this helper returns the bare value -1.
Quoted 4 lines
The current caller
hw_atl2_hw_fl2_set()translates it into-ENOSPCmanually, but if a future caller propagates the value unchanged it becomes-EPERM. Would returning-ENOSPChere directly be more consistent?
Fixed - hw_atl2_filter_tag_get() now returns -ENOSPC directly on the no-free-slot path, consistent with the sibling helpers. The caller's if (tag < 0) check is unaffected since -ENOSPC is still negative.
Quoted 34 lines
drivers/net/ethernet/aquantia/atlantic/hw_atl2/hw_atl2.c +19
-0+}@@ -823,6 +855,489 @@ static struct aq_stats_s *hw_atl2_utils_get_hw_stats(struct aq_hw_s *self)return &self->curr_stats; } +static bool hw_atl2_rxf_l3_is_equal (struct hw_atl2_l3_filter *f1, +struct hw_atl2_l3_filter *f2) +{ +if (f1->cmd != f2->cmd) +return false; + +if (f1->cmd &HW_ATL2_RPF_L3_CMD_SA_EN ) +if (f1->srcip[0 ] != f2->srcip[0 ]) +return false; + +if (f1->cmd &HW_ATL2_RPF_L3_CMD_DA_EN ) +if (f1->dstip[0 ] != f2->dstip[0 ]) +return false; + +if (f1->cmd & (HW_ATL2_RPF_L3_CMD_PROTO_EN | +HW_ATL2_RPF_L3_V6_CMD_PROTO_EN )) +if (f1->proto != f2->proto) +return false;[Low]
Where is l3.proto ever populated? Inhw_atl2_new_fl3l4_configure()the local l3 is memset to 0 and the protocol value is encoded into the upper bits of l3.cmd via:l3.cmd |= IPPROTO_TCP << (data->is_ipv6 ? 0x18 : 8);
Quoted 8 lines
hw_atl2_rxf_l3_get()then copies_l3->proto(=0) into the tracked slot, so this proto comparison appears to be 0 == 0 in all cases. The actual protocol comparison happens implicitly via thef1->cmd!=f2->cmdcheck above.Should l3.proto be removed, or populated consistently from the cmd encoding, so future code that begins setting one but not the other does not silently produce false negatives in the sharing check?
The vendor reference driver has the same pattern - protocol is encoded into l3.cmd bits and the f1->cmd != f2->cmd check already covers it. The proto field comparison is redundant but not harmful. We will leave it as-is to stay close to the reference driver, but can clean it up as a follow-up.
Quoted 68 lines
drivers/net/ethernet/aquantia/atlantic/hw_atl2/hw_atl2.c +47
-0+ +if (f1->cmd &HW_ATL2_RPF_L3_V6_CMD_SA_EN ) +if (memcmp (f1->srcip, f2->srcip,16 )) +return false; + +if (f1->cmd &HW_ATL2_RPF_L3_V6_CMD_DA_EN ) +if (memcmp (f1->dstip, f2->dstip,16 )) +return false; + +return true; +} +static void hw_atl2_rxf_l3_get (struct aq_hw_s *self, +struct hw_atl2_l3_filter *l3,int idx, +const struct hw_atl2_l3_filter *_l3) +{ +int i; + + l3->usage++; +if (l3->usage ==1 ) { + l3->cmd = _l3->cmd; +for (i =0 ; i <4 ; i++) { + l3->srcip[i] = _l3->srcip[i]; + l3->dstip[i] = _l3->dstip[i]; + } + l3->proto = _l3->proto; + +if (l3->cmd &HW_ATL2_RPF_L3_CMD_EN ) { +hw_atl2_rpf_l3_v4_cmd_set (self, l3->cmd, idx); +hw_atl2_rpf_l3_v4_tag_set (self, idx +1 , idx); +hw_atl2_rpf_l3_v4_dest_addr_set (self, + idx, + l3->dstip[0 ]); +hw_atl2_rpf_l3_v4_src_addr_set (self, + idx, + l3->srcip[0 ]); + }else { +hw_atl2_rpf_l3_v6_cmd_set (self, l3->cmd, idx); +hw_atl2_rpf_l3_v6_tag_set (self, idx +1 , idx); +hw_atl2_rpf_l3_v6_dest_addr_set (self, + idx, + l3->dstip); +hw_atl2_rpf_l3_v6_src_addr_set (self, + idx, + l3->srcip); + } + } +}[Medium]
Is the ordering of the MMIO writes here intentional?The cmd word containing the EN/SA_EN/DA_EN/PROTO_EN bits is committed first via
hw_atl2_rpf_l3_v4_cmd_set()(the v4 mask is0xFFFFand includes the EN bit), and only afterwards are the destination and source address registers programmed.Between the cmd write and the address writes, the filter is enabled while its DA/SA registers still hold whatever value they had before (stale, zero, or a previously programmed filter's addresses).
The IPv6 path is worse because
hw_atl2_rpf_l3_v6_dest_addr_set()and_src_addr_set()each issue four separate register writes (one per dword), so the filter is enabled with a partially-programmed address for several MMIO cycles.
Quoted 5 lines
The same pattern is in
hw_atl2_rxf_l4_get()below. Would it be safer to program the addresses (or ports) and tag first and write the cmd word with EN last?[ ... ]
The ordering is inherited from the vendor reference driver which uses the same sequence. No change needed.
Quoted 43 lines
drivers/net/ethernet/aquantia/atlantic/hw_atl2/hw_atl2.c +39
-0+static void hw_atl2_rxf_l4_get (struct aq_hw_s *self, +struct hw_atl2_l4_filter *l4,int idx, +const struct hw_atl2_l4_filter *_l4) +{ + l4->usage++; +if (l4->usage ==1 ) { + l4->cmd = _l4->cmd; + l4->sport = _l4->sport; + l4->dport = _l4->dport; + +hw_atl2_rpf_l4_cmd_set (self, l4->cmd, idx); +hw_atl2_rpf_l4_tag_set (self, idx +1 , idx); +hw_atl_rpf_l4_spd_set (self, l4->sport, idx); +hw_atl_rpf_l4_dpd_set (self, l4->dport, idx); + } +} + +static int hw_atl2_new_fl3l4_configure (struct aq_hw_s *self, +struct aq_rx_filter_l3l4 *data) +{ +/* convert legacy filter to new */ +if (data->cmd &HW_ATL_RX_ENABLE_CMP_PROT_L4 ) { + l3.cmd |= data->is_ipv6 ?HW_ATL2_RPF_L3_V6_CMD_PROTO_EN : +HW_ATL2_RPF_L3_CMD_PROTO_EN ; + l3.cmd |= data->is_ipv6 ?HW_ATL2_RPF_L3_V6_CMD_EN : +HW_ATL2_RPF_L3_CMD_EN ; +switch (data->cmd &0x7 ) { +case HW_ATL_RX_TCP : + l3.cmd |=IPPROTO_TCP << (data->is_ipv6 ?0x18 :8 ); +break ; +case HW_ATL_RX_UDP : + l3.cmd |=IPPROTO_UDP << (data->is_ipv6 ?0x18 :8 ); +break ; +case HW_ATL_RX_SCTP : + l3.cmd |=IPPROTO_SCTP << (data->is_ipv6 ?0x18 :8 ); +break ; +case HW_ATL_RX_ICMP : + l3.cmd |=IPPROTO_ICMP << (data->is_ipv6 ?0x18 :8 ); +break ;
Quoted 9 lines
[Low]
For the IPv6 branch ofHW_ATL_RX_ICMP, should the next-header value beIPPROTO_ICMPV6(58) rather thanIPPROTO_ICMP(1)? Real ICMPv6 traffic uses next-header 58, so this branch will not match ICMPv6 packets.The
aq_set_data_fl3l4()helper inaq_filters.cdoes not currently setHW_ATL_RX_ICMPfor any flow type, so the case is not reachable from the in-tree ethtool ntuple path today, but it is written explicitly here.
The reference driver uses IPPROTO_ICMP for both IPv4 and IPv6 paths. As noted, HW_ATL_RX_ICMP is unreachable from the in-tree ethtool ntuple path today, so this is a pre-existing inconsistency in the reference driver We will leave it as-is to stay aligned, but note it as a potential future fix when ICMPv6 support is wired up.
Quoted 8 lines
[Low]
The shift values0x18and 8 are repeated four times here, while the matching enable bits are named constants (HW_ATL2_RPF_L3_CMD_PROTO_ENandHW_ATL2_RPF_L3_V6_CMD_PROTO_EN). Would a pair of named shift macros (for exampleHW_ATL2_RPF_L3_CMD_PROTO_SHIFT/HW_ATL2_RPF_L3_V6_CMD_PROTO_SHIFT) make the relationship between the enable bit and the protocol byte position clearer and harder to mis-edit?
The bare shift values 0x18 and 8 are taken directly from the vendor reference driver which uses the same literals. Adding named macros is a reasonable cleanup but goes beyond the scope of this series. We will leave it as-is to minimize divergence from the reference driver.
Quoted 76 lines
drivers/net/ethernet/aquantia/atlantic/hw_atl2/hw_atl2.c +42
-0+ } + } +/* find L3 and L4 filters */ +if (l3.cmd & (HW_ATL2_RPF_L3_CMD_EN |HW_ATL2_RPF_L3_V6_CMD_EN )) { + l3_idx =hw_atl2_new_fl3l4_find_l3 (self, &l3); +if (l3_idx <0 ) +return l3_idx; + +if (l3.cmd &HW_ATL2_RPF_L3_V6_CMD_EN ) + l3_filters = priv->l3_v6_filters; +else + l3_filters = priv->l3_v4_filters; + +if (priv->l3l4_filters[data->location].l3_index != l3_idx || + old_ipv6 != !!(l3.cmd &HW_ATL2_RPF_L3_V6_CMD_EN )) +hw_atl2_rxf_l3_get (self, &l3_filters[l3_idx], + l3_idx, &l3); + } + +if (old_l3_index !=-1 ) { +if (old_ipv6) + l3_filters = priv->l3_v6_filters; +else + l3_filters = priv->l3_v4_filters; + +if (!(hw_atl2_rxf_l3_is_equal (&l3, + &l3_filters[old_l3_index]))) { +hw_atl2_rxf_l3_put (self, + &l3_filters[old_l3_index], + old_l3_index); + } + } +if (l3.cmd &HW_ATL2_RPF_L3_V6_CMD_EN ) + priv->l3l4_filters[data->location].ipv6 =1 ; +else + priv->l3l4_filters[data->location].ipv6 =0 ; + priv->l3l4_filters[data->location].l3_index = l3_idx; + +if (l4.cmd &HW_ATL2_RPF_L4_CMD_EN ) { + l4_idx =hw_atl2_new_fl3l4_find_l4 (self, &l4); +if (l4_idx <0 ) +return -EINVAL ;[High, Low]
By the time this L4 search runs,hw_atl2_new_fl3l4_configure()has already mutated state for the new request:-
hw_atl2_rxf_l3_get()programmed the new L3 hardware filter and bumped its refcount,
- the old L3 filter has typically been released viahw_atl2_rxf_l3_put()(clearing its HW slot if it was the last user, since match criteria differ), and
- priv->l3l4_filters[location].l3_index and .ipv6 have been overwritten to point at the new L3 slot.When this branch returns,
hw_atl2_hw_fl3l4_set()simply propagates the error and skips the ART write, so the device is left with the new L3 filter enabled (refcount 1) but no ART entry referencing its tag, the old ART entry still pointing at the now-cleared old L3 tag, and the user's previously-installed working rule effectively destroyed.Userspace receives an error and will not call the disable path, so the new L3 slot stays leaked. With only
HW_ATL2_RPF_L3L4_FILTERSslots per family, repeated failures rapidly exhaust the pool.Could this path roll back the L3-side state (and refcounts) before returning?
As a separate question, the L3 path uses:
if (l3_idx < 0) return l3_idx;
Quoted 7 lines
while the L4 path overwrites the more specific value with
-EINVAL:if (l4_idx < 0) return -EINVAL;Should the L4 path also propagate
l4_idxso userspace can distinguish-ENOSPCfrom-EINVAL?
Both observations are valid, but both are pre-existing in the vendor reference driver which has the identical no-rollback pattern and return -EINVAL on the L4 error path.
For the rollback issue: adding proper rollback would require undoing hw_atl2_rxf_l3_get(), restoring priv->l3l4_filters[location], and potentially re-programming the old L3 HW slot - a non-trivial change that goes beyond this series. We will note it as a known limitation for a follow-up.
For the -EINVAL vs propagating l4_idx: agreed, return l4_idx is more informative. Will fix this since it is a trivial one-line change.
Quoted 43 lines
drivers/net/ethernet/aquantia/atlantic/hw_atl2/hw_atl2.c +25
-0+ +if (priv->l3l4_filters[data->location].l4_index != l4_idx) +hw_atl2_rxf_l4_get (self, &priv->l4_filters[l4_idx], + l4_idx, &l4); + } +static int hw_atl2_hw_fl2_set (struct aq_hw_s *self, +struct aq_rx_filter_l2 *data) +{ + tag =hw_atl2_filter_tag_get (priv->etype_policy, + priv->etype_filter_tag_top, + action); + +if (tag <0 ) +return -ENOSPC ; + + req_tag |= tag <<HW_ATL2_RPF_TAG_ET_OFFSET ; +hw_atl2_rpf_etht_flr_tag_set (self, tag, location); + index = priv->art_base_index +HW_ATL2_RPF_ET_PCP_USER_INDEX + + data->location; +hw_atl2_act_rslvr_table_set (self, index, req_tag, mask, action); + +hw_atl_rpf_etht_flr_en_set (self,1U , location); + +return aq_hw_err_from_flags (self); +}[Medium]
Oncehw_atl2_filter_tag_get()succeeds, theetype_policyslot's usage count has been incremented. After that point this function still has two ways to return an error without releasing that tag:-
hw_atl2_act_rslvr_table_set()may return an error (semaphore poll timeout) — its return value is ignored here, but
-aq_hw_err_from_flags(self)at the end can return-ENXIOor-EIOifAQ_HW_FLAG_ERR_UNPLUG/AQ_HW_FLAG_ERR_HWhave been set during the register writes above.
Quoted 4 lines
Because
HW_ATL2_RPF_ETYPE_TAGSis small (7), repeated transient HW Errors would gradually permanently exhaust the etype tag pool until no L2 filter can be installed. Should a failure path here callhw_atl2_filter_tag_put()before returning?
The tag leak on the aq_hw_err_from_flags() error path is a valid observation.
However the vendor reference driver has the identical pattern - no filter_tag_put()
on the error path. In practice aq_hw_err_from_flags() returns an error only when AQ_HW_FLAG_ERR_UNPLUG or AQ_HW_FLAG_ERR_HW are set, which are fatal
hardware states where the device is already non-functional and filter management is moot. Fixing this properly would require adding cleanup on the aq_hw_err_from_flags() path across the entire driver, which is out of scope for this series. We will note it as a known limitation.
[email protected]
maintainerPATCH v4 8/12 net: atlantic: add AQC113 PTP traffic class and TX path setup
In reply to [email protected]From: Sukhdeep Singh <[email protected]>
Add PTP traffic class (TC) buffer reservation and TX path improvements for AQC113:
- Reserve dedicated TX and RX buffer space for PTP TC when PTP is enabled, reducing user TC buffers accordingly (TX: 8KB, RX: 16KB).
- Configure PTP TC with no flow control and highest priority scheduling to ensure timely PTP packet transmission.
TX path improvements:
- Increase TX data and descriptor read-request limits when firmware has already enabled extended PCIe tag mode.
Also simplify RSS queue calculation in hw_atl2_hw_rss_set() by extracting to a local variable and use unsigned types for loop variables to match their usage.
--- .../aquantia/atlantic/hw_atl2/hw_atl2.c | 49 ++++++++++++++++--- .../atlantic/hw_atl2/hw_atl2_internal.h | 4 +- 2 files changed, 46 insertions(+), 7 deletions(-)
drivers/net/ethernet/aquantia/atlantic/hw_atl2/hw_atl2.c +43 -6
@@ -151,6 +151,24 @@ static int hw_atl2_hw_reset(struct aq_hw_s *self)return err; } +static int hw_atl2_tc_ptp_set (struct aq_hw_s *self) +{ +/* Init TC2 for PTP_TX */ +hw_atl_tpb_tx_pkt_buff_size_per_tc_set (self,HW_ATL2_PTP_TXBUF_SIZE , +AQ_HW_PTP_TC ); + +/* Init TC2 for PTP_RX */ +hw_atl_rpb_rx_pkt_buff_size_per_tc_set (self,HW_ATL2_PTP_RXBUF_SIZE , +AQ_HW_PTP_TC ); + +/* No flow control for PTP */ +hw_atl_rpb_rx_xoff_en_per_tc_set (self,0U ,AQ_HW_PTP_TC ); + +hw_atl2_tpb_tps_highest_priority_tc_set (self,AQ_HW_PTP_TC ); + +return aq_hw_err_from_flags (self); +} +static int hw_atl2_hw_queue_to_tc_map_set (struct aq_hw_s *self) {struct aq_nic_cfg_s *cfg = self->aq_nic_cfg;
@@ -209,6 +227,11 @@ static int hw_atl2_hw_qos_set(struct aq_hw_s *self)unsigned int prio =0U ;u32 tc =0U ; +if (cfg->is_ptp) { + tx_buff_size -=HW_ATL2_PTP_TXBUF_SIZE ; + rx_buff_size -=HW_ATL2_PTP_RXBUF_SIZE ; + } +/* TPS Descriptor rate init */ hw_atl_tps_tx_pkt_shed_desc_rate_curr_time_res_set (self,0x0U );hw_atl_tps_tx_pkt_shed_desc_rate_lim_set (self,0xA );
@@ -242,6 +265,9 @@ static int hw_atl2_hw_qos_set(struct aq_hw_s *self)hw_atl_b0_set_fc (self, self->aq_nic_cfg->fc.req, tc); } +if (cfg->is_ptp) +hw_atl2_tc_ptp_set (self); +/* QoS 802.1p priority -> TC mapping */ for (prio =0 ; prio <8 ; ++prio) hw_atl_rpf_rpb_user_priority_tc_map_set(self, prio,
@@ -259,8 +285,9 @@ static int hw_atl2_hw_rss_set(struct aq_hw_s *self,u8 *indirection_table = rss_params->indirection_table;const u32 num_tcs =aq_hw_num_tcs (self);u32 rpf_redir2_enable; -int tc; -int i; +u32 queue; +u32 tc; +u32 i; rpf_redir2_enable = num_tcs >4 ?1 :0 ;
@@ -268,10 +295,9 @@ static int hw_atl2_hw_rss_set(struct aq_hw_s *self,for (i =HW_ATL2_RSS_REDIRECTION_MAX ; i--;) {for (tc =0 ; tc != num_tcs; tc++) { -hw_atl2_new_rpf_rss_redir_set (self, tc, i, - tc * -aq_hw_q_per_tc (self) + - indirection_table[i]); + queue = tc *aq_hw_q_per_tc (self) + + indirection_table[i]; +hw_atl2_new_rpf_rss_redir_set (self, tc, i, queue); } }
@@ -415,9 +441,20 @@ static int hw_atl2_hw_init_tx_path(struct aq_hw_s *self)hw_atl2_tpb_tx_buf_clk_gate_en_set (self,0U ); +if (hw_atl2_phi_ext_tag_get (self)) { +hw_atl2_tdm_tx_data_read_req_limit_set (self,0x7F ); +hw_atl2_tdm_tx_desc_read_req_limit_set (self,0x0F ); + } +return aq_hw_err_from_flags (self); } +/* Initialise new rx filters +* L2 promisc OFF +* VLAN promisc OFF +* +* User priority to TC +*/ static void hw_atl2_hw_init_new_rx_filters (struct aq_hw_s *self) {u8 *prio_tc_map = self->aq_nic_cfg->prio_tc_map;
drivers/net/ethernet/aquantia/atlantic/hw_atl2/hw_atl2_internal.h +3 -1
@@ -27,8 +27,10 @@#define HW_ATL2_INT_MASK (0xFFFFFFFFU)#define HW_ATL2_TXBUF_MAX 128U -#define HW_ATL2_RXBUF_MAX 192U +#define HW_ATL2_PTP_TXBUF_SIZE 8U +#define HW_ATL2_RXBUF_MAX 192U +#define HW_ATL2_PTP_RXBUF_SIZE 16U#define HW_ATL2_RSS_REDIRECTION_MAX 64U#define HW_ATL2_TC_MAX 8U
Signature · 1 line
2.43.0
[email protected]
maintainerPATCH v4 9/12 net: atlantic: extend hw_ops and TX descriptor for AQC113 PTP
In reply to [email protected]From: Sukhdeep Singh <[email protected]>
Extend the aq_hw_ops interface with new function pointers required for PTP support on AQC113:
- enable_ptp: enable/disable PTP counter with clock selection
- hw_ring_tx_ptp_get_ts: read TX timestamp from descriptor writeback
- hw_tx_ptp_ring_init/hw_rx_ptp_ring_init: per-ring PTP initialization
- hw_get_clk_sel: query active TSG clock selection
Update existing hw_ops signatures to support AQC113 dual-clock architecture:
- hw_gpio_pulse: add clk_sel and hightime parameters
- hw_extts_gpio_enable: add channel parameter
Add PTP-related hardware defines:
- AQ_HW_TXD_CTL_TS_EN/TS_TSG0 for TX descriptor timestamp control
- AQ2_HW_PTP_COUNTER_HZ for AQC113 TSG clock frequency
- AQ_HW_PTP_IRQS for PTP interrupt vector accounting
- PTP enable flags (L2/L4) and TSG clock selection constants
Add request_ts and clk_sel bitfields to aq_ring_buff_s for per-packet TX timestamp request tracking.
Update hw_atl_b0.c (AQC107) implementations:
- Adapt gpio_pulse and extts_gpio_enable to new signatures
- Add TX descriptor timestamp bits for AQC113 when ANTIGUA chip feature is detected
--- .../net/ethernet/aquantia/atlantic/aq_hw.h | 34 +++++++++++++++++-- .../net/ethernet/aquantia/atlantic/aq_ptp.c | 4 +-- .../net/ethernet/aquantia/atlantic/aq_ring.h | 4 ++- .../aquantia/atlantic/hw_atl/hw_atl_b0.c | 15 ++++++-- 4 files changed, 48 insertions(+), 9 deletions(-)
drivers/net/ethernet/aquantia/atlantic/aq_hw.h +31 -3
@@ -19,6 +19,9 @@#define AQ_HW_MAC_COUNTER_HZ 312500000ll#define AQ_HW_PHY_COUNTER_HZ 160000000ll +#define AQ_HW_TXD_CTL_TS_EN 0x40000000U +#define AQ_HW_TXD_CTL_TS_TSG0 0x80000000U +enum aq_tc_mode {AQ_TC_MODE_INVALID =-1 ,AQ_TC_MODE_8TCS ,
@@ -38,6 +41,8 @@ enum aq_tc_mode {#define AQ_FRAC_PER_NS 0x100000000LL +#define AQ2_HW_PTP_COUNTER_HZ 156250000ll +/* Used for rate to Mbps conversion */ #define AQ_MBPS_DIVISOR 125000/* 1000000 / 8 */
@@ -109,6 +114,7 @@ struct aq_stats_s {#define AQ_HW_IRQ_MSIX 3U#define AQ_HW_SERVICE_IRQS 1U +#define AQ_HW_PTP_IRQS 1U#define AQ_HW_POWER_STATE_D0 0U#define AQ_HW_POWER_STATE_D3 3U
@@ -157,6 +163,15 @@ enum aq_priv_flags { AQ_HW_LOOPBACK_PHYEXT_SYS, }; +enum { +AQ_HW_PTP_DISABLE =0 , +AQ_HW_PTP_L2_ENABLE =BIT (1 ), +AQ_HW_PTP_L4_ENABLE =BIT (2 ), +}; + +#define ATL_TSG_CLOCK_SEL_0 0 +#define ATL_TSG_CLOCK_SEL_1 1 +#define AQ_HW_LOOPBACK_MASK (BIT(AQ_HW_LOOPBACK_DMA_SYS) |\ BIT(AQ_HW_LOOPBACK_PKT_SYS) |\ BIT(AQ_HW_LOOPBACK_DMA_NET) |\
@@ -198,6 +213,7 @@ struct aq_hw_s {u32 rpc_tid;struct hw_atl_utils_fw_rpc rpc;s64 ptp_clk_offset; +s8 clk_select;u16 phy_id;void *priv; };
@@ -323,11 +339,15 @@ struct aq_hw_ops {int (*hw_ts_to_sys_clock)(struct aq_hw_s *self,u64 ts,u64 *time); -int (*hw_gpio_pulse)(struct aq_hw_s *self,u32 index,u64 start, -u32 period); +int (*hw_gpio_pulse)(struct aq_hw_s *self,u32 index, +u32 clk_sel,u64 start, +u32 period,u32 hightime);int (*hw_extts_gpio_enable)(struct aq_hw_s *self,u32 index, -u32 enable); +u32 channel,int enable); + +void (*enable_ptp)(struct aq_hw_s *self,unsigned int param, +int enable);int (*hw_get_sync_ts)(struct aq_hw_s *self,u64 *ts);
@@ -337,6 +357,14 @@ struct aq_hw_ops {int (*extract_hwts)(struct aq_hw_s *self,u8 *p,unsigned int len,u64 *timestamp); +u64 (*hw_ring_tx_ptp_get_ts)(struct aq_ring_s *ring); + +int (*hw_tx_ptp_ring_init)(struct aq_hw_s *self, +struct aq_ring_s *aq_ring); +int (*hw_rx_ptp_ring_init)(struct aq_hw_s *self, +struct aq_ring_s *aq_ring); +u32 (*hw_get_clk_sel)(struct aq_hw_s *self); +int (*hw_set_fc)(struct aq_hw_s *self,u32 fc,u32 tc);int (*hw_set_loopback)(struct aq_hw_s *self,u32 mode,bool enable);
drivers/net/ethernet/aquantia/atlantic/aq_ptp.c +2 -2
@@ -380,7 +380,7 @@ static int aq_ptp_hw_pin_conf(struct aq_nic_s *aq_nic, u32 pin_index, u64 start,*/ mutex_lock (&aq_nic->fwreq_mutex); aq_nic->aq_hw_ops->hw_gpio_pulse (aq_nic->aq_hw, pin_index, - start, (u32 )period); +0 , start, (u32 )period,0 );mutex_unlock (&aq_nic->fwreq_mutex);return 0 ;
@@ -454,7 +454,7 @@ static void aq_ptp_extts_pin_ctrl(struct aq_ptp_s *aq_ptp)if (aq_nic->aq_hw_ops->hw_extts_gpio_enable) aq_nic->aq_hw_ops->hw_extts_gpio_enable (aq_nic->aq_hw,0 , - enable); +0 , enable); } static int aq_ptp_extts_pin_configure(struct ptp_clock_info *ptp,
drivers/net/ethernet/aquantia/atlantic/aq_ring.h +3 -1
@@ -85,7 +85,9 @@ struct __packed aq_ring_buff_s { u32 is_error:1; u32 is_vlan:1; u32 is_lro:1; - u32 rsvd3:3; + u32 request_ts:1; + u32 clk_sel:1; + u32 rsvd3:1;u16 eop_index;u16 rsvd4; };
drivers/net/ethernet/aquantia/atlantic/hw_atl/hw_atl_b0.c +12 -3
@@ -736,6 +736,15 @@ int hw_atl_b0_hw_ring_tx_xmit(struct aq_hw_s *self, struct aq_ring_s *ring, txd->ctl |=HW_ATL_B0_TXD_CTL_CMD_WB ; is_gso = false; is_vlan = false; + +if (ATL_HW_IS_CHIP_FEATURE (self,ANTIGUA ) && +unlikely (buff->request_ts)) { + txd->ctl |=AQ_HW_TXD_CTL_TS_EN ; +if (buff->clk_sel !=ATL_TSG_CLOCK_SEL_1 ) + txd->ctl |=AQ_HW_TXD_CTL_TS_TSG0 ; +/* The only DD+TS is required */ + txd->ctl &= ~HW_ATL_B0_TXD_CTL_CMD_WB ; + } } } ring->sw_tail =aq_ring_next_dx (ring, ring->sw_tail);
@@ -1323,8 +1332,8 @@ static int hw_atl_b0_adj_clock_freq(struct aq_hw_s *self, s32 ppb)return self->aq_fw_ops->send_fw_request (self, &fwreq, size); } -static int hw_atl_b0_gpio_pulse (struct aq_hw_s *self,u32 index, -u64 start,u32 period) +static int hw_atl_b0_gpio_pulse (struct aq_hw_s *self,u32 index,u32 clk_sel, +u64 start,u32 period,u32 hightime) {struct hw_fw_request_iface fwreq;size_t size;
@@ -1342,7 +1351,7 @@ static int hw_atl_b0_gpio_pulse(struct aq_hw_s *self, u32 index, }static int hw_atl_b0_extts_gpio_enable (struct aq_hw_s *self,u32 index, -u32 enable) +u32 channel,int enable) {/* Enable/disable Sync1588 GPIO Timestamping */ aq_phy_write_reg (self,MDIO_MMD_PCS ,0xc611 , enable ?0x71 :0 );
Signature · 1 line
2.43.0
[email protected]
maintainerPATCH v4 10/12 net: atlantic: add AQC113 PTP hardware ops in hw_atl2
In reply to [email protected]From: Sukhdeep Singh <[email protected]>
Add the hardware-layer PTP implementation for AQC113 (Antigua):
- hw_atl2.h/hw_atl2_utils.h/hw_atl2_internal.h: export PTP function prototypes, per-instance aq_ptp_offset arrays, RX timestamp size (HW_ATL2_RX_TS_SIZE=8), and reduced HW_ATL2_RXBUF_MAX=172 (AQC113 on-chip RX packet buffer hardware limit for data TCs).
- hw_atl2.c: implement hw_atl2_enable_ptp() to program TSG clocks, PTP TC receive path and filter ART entries, and re-enable PTP state after hardware reset.
- hw_atl2.c: implement hw_atl2_adj_sys_clock(), hw_atl2_adj_clock_freq(), and aq_get_ptp_ts() for TSG clock read/adjust/increment operations.
- hw_atl2.c: implement hw_atl2_gpio_pulse() for PPS output generation via TSG pulse generator.
- hw_atl2.c: implement hw_atl2_hw_tx_ptp_ring_init() and hw_atl2_hw_rx_ptp_ring_init() for PTP ring setup.
- hw_atl2.c: implement hw_atl2_hw_ring_tx_ptp_get_ts() to read TX timestamp from descriptor writeback, and hw_atl2_hw_rx_extract_ts() to extract RX timestamp from the 8-byte packet trailer.
- hw_atl2.c: add hw_atl2_hw_get_clk_sel() helper.
- Wire all new ops into hw_atl2_ops.
--- .../aquantia/atlantic/hw_atl2/hw_atl2.c | 202 +++++++++++++++++- .../aquantia/atlantic/hw_atl2/hw_atl2.h | 12 ++ .../atlantic/hw_atl2/hw_atl2_internal.h | 3 +- .../aquantia/atlantic/hw_atl2/hw_atl2_utils.h | 10 + 4 files changed, 224 insertions(+), 3 deletions(-)
drivers/net/ethernet/aquantia/atlantic/hw_atl2/hw_atl2.c +200 -2
@@ -7,6 +7,7 @@#include "aq_hw_utils.h" #include "aq_ring.h" #include "aq_nic.h" +#include "aq_ptp.h" #include "hw_atl/hw_atl_b0.h" #include "hw_atl/hw_atl_utils.h" #include "hw_atl/hw_atl_llh.h"
@@ -20,6 +21,15 @@static int hw_atl2_act_rslvr_table_set (struct aq_hw_s *self,u8 location,u32 tag,u32 mask,u32 action); +static void hw_atl2_enable_ptp (struct aq_hw_s *self, +unsigned int param,int enable); +static int hw_atl2_hw_tx_ptp_ring_init (struct aq_hw_s *self, +struct aq_ring_s *aq_ring); +static int hw_atl2_hw_rx_ptp_ring_init (struct aq_hw_s *self, +struct aq_ring_s *aq_ring); +static void aq_get_ptp_ts (struct aq_hw_s *self,u64 *stamp); +static int hw_atl2_adj_clock_freq (struct aq_hw_s *self,s32 ppb); +#define DEFAULT_BOARD_BASIC_CAPABILITIES \ .is_64_dma = true, \ .op64bit = true, \
@@ -127,6 +137,7 @@ static u32 hw_atl2_sem_act_rslvr_get(struct aq_hw_s *self)static int hw_atl2_hw_reset (struct aq_hw_s *self) {struct hw_atl2_priv *priv = self->priv; +s8 clk_sel;int err;int i;
@@ -144,6 +155,13 @@ static int hw_atl2_hw_reset(struct aq_hw_s *self) priv->l3l4_filters[i].l4_index =-1 ; } + clk_sel =READ_ONCE (self->clk_select); +if (clk_sel !=-1 ) +hw_atl2_enable_ptp (self, + clk_sel, +aq_utils_obj_test (&self->flags,AQ_HW_PTP_AVAILABLE ) ? +1 :0 ); + self->aq_fw_ops->set_state (self,MPI_RESET ); err =aq_hw_err_from_flags (self);
@@ -725,14 +743,32 @@ static int hw_atl2_hw_ring_rx_init(struct aq_hw_s *self,struct aq_ring_s *aq_ring, struct aq_ring_param_s *aq_ring_param) { - return hw_atl_b0_hw_ring_rx_init(self, aq_ring, aq_ring_param); + int res = hw_atl_b0_hw_ring_rx_init(self, aq_ring, aq_ring_param); + +if (!res &&aq_ptp_ring (aq_ring->aq_nic, aq_ring)) { +int rx_err =hw_atl2_hw_rx_ptp_ring_init (self, aq_ring); + +if (!res) + res = rx_err; + } + +return res; }static int hw_atl2_hw_ring_tx_init (struct aq_hw_s *self,struct aq_ring_s *aq_ring,struct aq_ring_param_s *aq_ring_param) { -return hw_atl_b0_hw_ring_tx_init (self, aq_ring, aq_ring_param); +int res =hw_atl_b0_hw_ring_tx_init (self, aq_ring, aq_ring_param); + +if (!res &&aq_ptp_ring (aq_ring->aq_nic, aq_ring)) { +int tx_err =hw_atl2_hw_tx_ptp_ring_init (self, aq_ring); + +if (!res) + res = tx_err; + } + +return res; }#define IS_FILTER_ENABLED (_F_) ((packet_filter & (_F_)) ? 1U : 0U)
@@ -892,6 +928,151 @@ static struct aq_stats_s *hw_atl2_utils_get_hw_stats(struct aq_hw_s *self)return &self->curr_stats; } +static void hw_atl2_enable_ptp (struct aq_hw_s *self, +unsigned int param,int enable) +{ +WRITE_ONCE (self->clk_select, (s8 )param); + +/* enable tsg counter */ +hw_atl2_tsg_clock_reset (self, self->clk_select); +hw_atl2_tsg_clock_en (self, !self->clk_select, enable); +hw_atl2_tsg_clock_en (self, self->clk_select, enable); + +if (enable) +hw_atl2_adj_clock_freq (self,0 ); + +hw_atl2_tpb_tps_highest_priority_tc_enable_set (self, enable); +} + +static void aq_get_ptp_ts (struct aq_hw_s *self,u64 *stamp) +{ +s8 clk_sel =READ_ONCE (self->clk_select); + +if (clk_sel <0 ) +return ; +if (stamp) + *stamp =hw_atl2_tsg_clock_read (self, clk_sel); +} + +static u64 hw_atl2_hw_ring_tx_ptp_get_ts (struct aq_ring_s *ring) +{ +struct hw_atl2_txts_s *txts; +u32 ctrl; + + txts = (struct hw_atl2_txts_s *)&ring->dx_ring[ring->sw_head * +HW_ATL2_TXD_SIZE ]; +/* DD + TS_VALID */ + ctrl =le32_to_cpu (READ_ONCE (txts->ctrl)); +if ((ctrl &HW_ATL2_TXTS_DD ) && (ctrl &HW_ATL2_TXTS_TS_VALID )) { +dma_rmb (); +return le64_to_cpu (txts->ts); + } + +return 0 ; +} + +static u16 hw_atl2_hw_rx_extract_ts (struct aq_hw_s *self,u8 *p, +unsigned int len,u64 *timestamp) +{ +unsigned int offset =HW_ATL2_RX_TS_SIZE ; +__le64 ts; +u8 *ptr; + +if (len <= offset || !timestamp) +return 0 ; + + ptr = p + (len - offset); +memcpy (&ts, ptr,sizeof (ts)); + *timestamp =le64_to_cpu (ts); + +return HW_ATL2_RX_TS_SIZE ; +} + +static int hw_atl2_adj_sys_clock (struct aq_hw_s *self,s64 delta) +{ +s8 clk_sel =READ_ONCE (self->clk_select); + +if (clk_sel <0 ) +return -ENODEV ; +if (delta >=0 ) +hw_atl2_tsg_clock_add (self, clk_sel, (u64 )delta); +else +hw_atl2_tsg_clock_sub (self, clk_sel, (u64)(-delta)); + +return 0 ; +} + +static int hw_atl2_adj_clock_freq (struct aq_hw_s *self,s32 ppb) +{ +u32 freq =AQ2_HW_PTP_COUNTER_HZ ; +u64 divisor =0 , base_ns; +u32 nsi_frac =0 , nsi; +u32 nsi_rem; +s8 clk_sel; + + base_ns =div_u64 ((u64)((s64 )ppb +NSEC_PER_SEC ) *NSEC_PER_SEC , freq); + nsi = (u32 )div_u64_rem (base_ns,NSEC_PER_SEC , &nsi_rem); +if (nsi_rem !=0 ) { + divisor =div_u64 (mul_u32_u32 (NSEC_PER_SEC ,NSEC_PER_SEC ), + nsi_rem); + nsi_frac = (u32 )div64_u64 (AQ_FRAC_PER_NS *NSEC_PER_SEC , + divisor); + } + + clk_sel =READ_ONCE (self->clk_select); +if (clk_sel <0 ) +return -ENODEV ; +hw_atl2_tsg_clock_increment_set (self, clk_sel, nsi, nsi_frac); + +return 0 ; +} + +static int hw_atl2_hw_tx_ptp_ring_init (struct aq_hw_s *self, +struct aq_ring_s *aq_ring) +{ +hw_atl2_tdm_tx_desc_timestamp_writeback_en_set (self, true, + aq_ring->idx); +hw_atl2_tdm_tx_desc_timestamp_en_set (self, true, aq_ring->idx); +hw_atl2_tdm_tx_desc_avb_en_set (self, true, aq_ring->idx); + +return aq_hw_err_from_flags (self); +} + +static int hw_atl2_hw_rx_ptp_ring_init (struct aq_hw_s *self, +struct aq_ring_s *aq_ring) +{ +hw_atl2_rpf_rx_desc_timestamp_req_set (self, + self->clk_select ==ATL_TSG_CLOCK_SEL_1 ?2 :1 , + aq_ring->idx); +return aq_hw_err_from_flags (self); +} + +static u32 hw_atl2_hw_get_clk_sel (struct aq_hw_s *self) +{ +return READ_ONCE (self->clk_select); +} + +static int hw_atl2_gpio_pulse (struct aq_hw_s *self,u32 index,u32 clk_sel, +u64 start,u32 period,u32 hightime) +{ +u32 mode; + +if (index !=1 && index !=3 ) +return -EINVAL ; + +if (start ==0 ) + mode =HW_ATL2_GPIO_PIN_SPEC_MODE_GPIO ; +else if (clk_sel ==ATL_TSG_CLOCK_SEL_0 ) + mode =HW_ATL2_GPIO_PIN_SPEC_MODE_TSG0_EVENT_OUTPUT ; +else + mode =HW_ATL2_GPIO_PIN_SPEC_MODE_TSG1_EVENT_OUTPUT ; + +hw_atl2_gpio_special_mode_set (self, mode, index); +hw_atl2_tsg_ptp_gpio_gen_pulse (self, clk_sel, start, period, hightime); + +return 0 ; +} +static bool hw_atl2_rxf_l3_is_equal (struct hw_atl2_l3_filter *f1,struct hw_atl2_l3_filter *f2) {
@@ -1472,4 +1653,21 @@ const struct aq_hw_ops hw_atl2_ops = { .hw_set_offload = hw_atl_b0_hw_offload_set, .hw_set_loopback = hw_atl_b0_set_loopback, .hw_set_fc = hw_atl_b0_set_fc, + + .hw_ring_hwts_rx_fill = NULL, + .hw_ring_hwts_rx_receive = NULL, + + .hw_get_ptp_ts = aq_get_ptp_ts, + .hw_adj_clock_freq = hw_atl2_adj_clock_freq, + .hw_adj_sys_clock = hw_atl2_adj_sys_clock, + .hw_gpio_pulse = hw_atl2_gpio_pulse, + + .enable_ptp = hw_atl2_enable_ptp, + .hw_ring_tx_ptp_get_ts = hw_atl2_hw_ring_tx_ptp_get_ts, + .rx_extract_ts = hw_atl2_hw_rx_extract_ts, + .hw_tx_ptp_ring_init = hw_atl2_hw_tx_ptp_ring_init, + .hw_rx_ptp_ring_init = hw_atl2_hw_rx_ptp_ring_init, + .hw_get_clk_sel = hw_atl2_hw_get_clk_sel, + .extract_hwts = NULL, + .hw_extts_gpio_enable = NULL, };
drivers/net/ethernet/aquantia/atlantic/hw_atl2/hw_atl2.h +12 -0
@@ -7,6 +7,18 @@#define HW_ATL2_H #include "aq_common.h" +#define HW_ATL2_RX_TS_SIZE 8 + +#define HW_ATL2_PTP_OFFSET_INGRESS_100 768 +#define HW_ATL2_PTP_OFFSET_EGRESS_100 336 +#define HW_ATL2_PTP_OFFSET_INGRESS_1000 510 +#define HW_ATL2_PTP_OFFSET_EGRESS_1000 105 +#define HW_ATL2_PTP_OFFSET_INGRESS_2500 2447 +#define HW_ATL2_PTP_OFFSET_EGRESS_2500 634 +#define HW_ATL2_PTP_OFFSET_INGRESS_5000 1426 +#define HW_ATL2_PTP_OFFSET_EGRESS_5000 361 +#define HW_ATL2_PTP_OFFSET_INGRESS_10000 997 +#define HW_ATL2_PTP_OFFSET_EGRESS_10000 203extern const struct aq_hw_caps_s hw_atl2_caps_aqc113;extern const struct aq_hw_caps_s hw_atl2_caps_aqc115c;
drivers/net/ethernet/aquantia/atlantic/hw_atl2/hw_atl2_internal.h +2 -1
@@ -29,7 +29,8 @@#define HW_ATL2_TXBUF_MAX 128U#define HW_ATL2_PTP_TXBUF_SIZE 8U -#define HW_ATL2_RXBUF_MAX 192U +/* AQC113 on-chip RX packet buffer available for data TCs */ +#define HW_ATL2_RXBUF_MAX 172U#define HW_ATL2_PTP_RXBUF_SIZE 16U#define HW_ATL2_RSS_REDIRECTION_MAX 64U
drivers/net/ethernet/aquantia/atlantic/hw_atl2/hw_atl2_utils.h +10 -0
@@ -8,6 +8,16 @@#include "aq_hw.h" +/* Hardware tx launch time descriptor */ +struct hw_atl2_txts_s { +__le64 ts; +__le32 ctrl; +u32 reserved; +}; + +#define HW_ATL2_TXTS_DD BIT(3) +#define HW_ATL2_TXTS_TS_VALID BIT(20) +/* F W A P I */ struct link_options_s {
Signature · 1 line
2.43.0
Jakub Kicinski
maintainerRe: [PATCH net-next v4 10/12] net: atlantic: add AQC113 PTP hardware ops in hw_atl2
This is an AI-generated review of your patch. The human sending this email has considered the AI review valid, or at least plausible.
---
net: atlantic: add AQC113 PTP hardware ops in hw_atl2
This patch wires the AQC113 (Antigua) PTP hardware ops into hw_atl2:
TSG clock setup/adjust, PTP ring init, TX timestamp readback from descriptor writeback, RX timestamp extraction from packet trailer, and GPIO pulse / PPS output. It also reduces HW_ATL2_RXBUF_MAX from 192 to 172.
[Low]
On the commit message itself, a couple of descriptions look like they do not quite match the code that landed in this patch:
- hw_atl2.h/hw_atl2_utils.h/hw_atl2_internal.h: export PTP function prototypes, per-instance aq_ptp_offset arrays, RX timestamp size
Every new hw_atl2 PTP function is static in hw_atl2.c and is reached only through hw_atl2_ops, so are any prototypes actually being exported from the headers? The new HW_ATL2_PTP_OFFSET_* additions in hw_atl2.h are also individual scalar #defines, not arrays — should the wording be adjusted?
- hw_atl2.c: implement hw_atl2_enable_ptp() to program TSG clocks, PTP TC receive path and filter ART entries, and re-enable PTP state after hardware reset.
The hw_atl2_enable_ptp() body only resets/enables the TSG clocks, optionally calls hw_atl2_adj_clock_freq(), and toggles hw_atl2_tpb_tps_highest_priority_tc_enable_set(). Is the "PTP TC receive path and filter ART entries" claim describing this patch, or work that lives in another patch in the series?
Quoted 4 lines
drivers/net/ethernet/aquantia/atlantic/hw_atl2/hw_atl2.c +0
-0
[ ... ]
Quoted 9 lines
drivers/net/ethernet/aquantia/atlantic/hw_atl2/hw_atl2.c +1
-0@@ -127,6 +137,7 @@ static u32 hw_atl2_sem_act_rslvr_get(struct aq_hw_s *self)static int hw_atl2_hw_reset (struct aq_hw_s *self) {struct hw_atl2_priv *priv = self->priv; +s8 clk_sel;int err;int i;
drivers/net/ethernet/aquantia/atlantic/hw_atl2/hw_atl2.c static int hw_atl2_hw_reset(struct aq_hw_s *self) · line 164
Quoted 10 lines
drivers/net/ethernet/aquantia/atlantic/hw_atl2/hw_atl2.c +7
-0@@ -144,6 +155,13 @@ static int hw_atl2_hw_reset(struct aq_hw_s *self) priv->l3l4_filters[i].l4_index =-1 ; } + clk_sel =READ_ONCE (self->clk_select); +if (clk_sel !=-1 ) +hw_atl2_enable_ptp (self, + clk_sel, +aq_utils_obj_test (&self->flags,AQ_HW_PTP_AVAILABLE ) ? +1 :0 ); +
[Medium]
Where is self->clk_select initialised to -1?
struct aq_hw_s is allocated through kzalloc_obj() in aq_pci_func.c, so clk_select starts as 0, and 0 is also a valid clock index (ATL_TSG_CLOCK_SEL_0). On the very first aq_nic_init()->hw_reset() the test:
if (clk_sel != -1) hw_atl2_enable_ptp(self, clk_sel, ...);
evaluates true with clk_sel == 0, and AQ_HW_PTP_AVAILABLE is not set yet at this point in the series (aq_ptp_init() in this tree only sets it for the a1 PTP path), so hw_atl2_enable_ptp(self, 0, 0) gets unconditionally called for every hw_atl2 chip including aqc115c and aqc116c.
That call then does:
hw_atl2_tsg_clock_reset(self, 0); hw_atl2_tsg_clock_en(self, 1, 0); hw_atl2_tsg_clock_en(self, 0, 0); hw_atl2_tpb_tps_highest_priority_tc_enable_set(self, 0);
on parts that may have no PTP setup at all. Should the -1 sentinel initialisation that lives in a later patch in the series be folded into this commit so each commit is self-contained for bisection?
Quoted 26 lines
drivers/net/ethernet/aquantia/atlantic/hw_atl2/hw_atl2.c +11
-2self->aq_fw_ops->set_state (self,MPI_RESET ); err =aq_hw_err_from_flags (self);@@ -725,14 +743,32 @@ static int hw_atl2_hw_ring_rx_init(struct aq_hw_s *self,struct aq_ring_s *aq_ring, struct aq_ring_param_s *aq_ring_param) { - return hw_atl_b0_hw_ring_rx_init(self, aq_ring, aq_ring_param); + int res = hw_atl_b0_hw_ring_rx_init(self, aq_ring, aq_ring_param); + +if (!res &&aq_ptp_ring (aq_ring->aq_nic, aq_ring)) { +int rx_err =hw_atl2_hw_rx_ptp_ring_init (self, aq_ring); + +if (!res) + res = rx_err; + } + +return res; }static int hw_atl2_hw_ring_tx_init (struct aq_hw_s *self,struct aq_ring_s *aq_ring,struct aq_ring_param_s *aq_ring_param) { -return hw_atl_b0_hw_ring_tx_init (self, aq_ring, aq_ring_param); +int res =hw_atl_b0_hw_ring_tx_init (self, aq_ring, aq_ring_param);
drivers/net/ethernet/aquantia/atlantic/hw_atl2/hw_atl2.c static int hw_atl2_hw_ring_rx_init(struct aq_hw_s *self, · line 772
Quoted 10 lines
drivers/net/ethernet/aquantia/atlantic/hw_atl2/hw_atl2.c +9
-0+ +if (!res &&aq_ptp_ring (aq_ring->aq_nic, aq_ring)) { +int tx_err =hw_atl2_hw_tx_ptp_ring_init (self, aq_ring); + +if (!res) + res = tx_err; + } + +return res; }
[Low]
The inner if (!res) check is provably always true here — the outer if (!res && aq_ptp_ring(...)) already established res == 0 for the whole block:
if (!res && aq_ptp_ring(aq_ring->aq_nic, aq_ring)) {
int rx_err = hw_atl2_hw_rx_ptp_ring_init(self, aq_ring);
if (!res) /* always true */
res = rx_err;
}Was the intent to also call the PTP ring init when the b0 init had already failed (and only then preserve the first error), or is the inner test simply redundant and meant to be a plain res = rx_err?
[ ... ]
Quoted 9 lines
drivers/net/ethernet/aquantia/atlantic/hw_atl2/hw_atl2.c +5
-0@@ -892,6 +928,151 @@ static struct aq_stats_s *hw_atl2_utils_get_hw_stats(struct aq_hw_s *self)return &self->curr_stats; } +static void hw_atl2_enable_ptp (struct aq_hw_s *self, +unsigned int param,int enable) +{ +WRITE_ONCE (self->clk_select, (s8 )param); +
drivers/net/ethernet/aquantia/atlantic/hw_atl2/hw_atl2.c static struct aq_stats_s *hw_atl2_utils_get_hw_stats(struct aq_hw_s *self) · line 945
Quoted 10 lines
drivers/net/ethernet/aquantia/atlantic/hw_atl2/hw_atl2.c +10
-0+/* enable tsg counter */ +hw_atl2_tsg_clock_reset (self, self->clk_select); +hw_atl2_tsg_clock_en (self, !self->clk_select, enable); +hw_atl2_tsg_clock_en (self, self->clk_select, enable); + +if (enable) +hw_atl2_adj_clock_freq (self,0 ); + +hw_atl2_tpb_tps_highest_priority_tc_enable_set (self, enable); +}
[Low]
Is mixing one WRITE_ONCE store with three plain reads of the same field intentional?
The other accessors in this file (hw_atl2_hw_reset(), aq_get_ptp_ts(), hw_atl2_adj_sys_clock(), hw_atl2_adj_clock_freq(), hw_atl2_hw_get_clk_sel()) consistently use READ_ONCE(self->clk_select), suggesting the field is treated as concurrent state. Here the three plain reads after WRITE_ONCE() defeat that protocol and KCSAN will flag the inconsistent annotations.
Would using the local param value (which is what was just stored) be clearer, e.g.:
s8 sel = (s8)param; WRITE_ONCE(self->clk_select, sel); hw_atl2_tsg_clock_reset(self, sel); hw_atl2_tsg_clock_en(self, !sel, enable); hw_atl2_tsg_clock_en(self, sel, enable);
drivers/net/ethernet/aquantia/atlantic/hw_atl2/hw_atl2.c static struct aq_stats_s *hw_atl2_utils_get_hw_stats(struct aq_hw_s *self) · line 955
Quoted 10 lines
drivers/net/ethernet/aquantia/atlantic/hw_atl2/hw_atl2.c +10
-0+ +static void aq_get_ptp_ts (struct aq_hw_s *self,u64 *stamp) +{ +s8 clk_sel =READ_ONCE (self->clk_select); + +if (clk_sel <0 ) +return ; +if (stamp) + *stamp =hw_atl2_tsg_clock_read (self, clk_sel); +}
[Medium]
Can this leave *stamp uninitialised on the early return?
The existing callers in aq_ptp.c declare an uninitialised stack variable and pass its address straight in, expecting the callee to populate it:
aq_ptp_gettime():
u64 ns; aq_ptp_get_sync_time_from_pkt(aq_nic, NULL, &ns); ... hw_get_ptp_ts() variants are called the same way
aq_ptp_settime():
u64 now; aq_nic->aq_hw_ops->hw_get_ptp_ts(aq_nic->aq_hw, &now);
aq_ptp_pps_pin_configure():
u64 start; aq_nic->aq_hw_ops->hw_get_ptp_ts(aq_nic->aq_hw, &start);
When clk_sel < 0 the new aq_get_ptp_ts() returns without touching *stamp, so the caller then forwards stack garbage as a timestamp (into ns_to_timespec64() in the gettime path, into hw_adj_sys_clock() in settime). Should the early return set *stamp = 0 first, or should the prototype be changed to return an error?
Quoted 1 line
drivers/net/ethernet/aquantia/atlantic/hw_atl2/hw_atl2.c +1
-0+
[ ... ]
drivers/net/ethernet/aquantia/atlantic/hw_atl2/hw_atl2.c static struct aq_stats_s *hw_atl2_utils_get_hw_stats(struct aq_hw_s *self) · line 1048
Quoted 8 lines
drivers/net/ethernet/aquantia/atlantic/hw_atl2/hw_atl2.c +8
-0+static int hw_atl2_hw_rx_ptp_ring_init (struct aq_hw_s *self, +struct aq_ring_s *aq_ring) +{ +hw_atl2_rpf_rx_desc_timestamp_req_set (self, + self->clk_select ==ATL_TSG_CLOCK_SEL_1 ?2 :1 , + aq_ring->idx); +return aq_hw_err_from_flags (self); +}
[Low]
This reads self->clk_select with a plain access while every other reader of the same field in this file uses READ_ONCE(). Should this also be:
s8 clk_sel = READ_ONCE(self->clk_select); hw_atl2_rpf_rx_desc_timestamp_req_set(self, clk_sel == ATL_TSG_CLOCK_SEL_1 ? 2 : 1, aq_ring->idx);
[ ... ]
drivers/net/ethernet/aquantia/atlantic/hw_atl2/hw_atl2_internal.h line 35
Quoted 13 lines
drivers/net/ethernet/aquantia/atlantic/hw_atl2/hw_atl2_internal.h +2
-1@@ -29,7 +29,8 @@#define HW_ATL2_TXBUF_MAX 128U#define HW_ATL2_PTP_TXBUF_SIZE 8U -#define HW_ATL2_RXBUF_MAX 192U +/* AQC113 on-chip RX packet buffer available for data TCs */ +#define HW_ATL2_RXBUF_MAX 172U#define HW_ATL2_PTP_RXBUF_SIZE 16U#define HW_ATL2_RSS_REDIRECTION_MAX 64U
[Medium]
The comment scopes this change to AQC113, but HW_ATL2_RXBUF_MAX is used unconditionally in hw_atl2_hw_qos_set():
u32 rx_buff_size = HW_ATL2_RXBUF_MAX;
for hw_atl2_caps_aqc113, hw_atl2_caps_aqc115c and hw_atl2_caps_aqc116c, with no per-chip selection. Does the same on-chip 172 KB limit apply to aqc115c and aqc116c, or does this silently shrink the RX buffer pool for chips outside the stated scope of the patch?
The non-PTP path on AQC113 is also affected: hw_atl2_hw_qos_set() already subtracts HW_ATL2_PTP_RXBUF_SIZE (16) when cfg->is_ptp is set, so the PTP TC reservation is independent of this base value. Would it make sense to split the RXBUF_MAX change into its own commit with a Fixes: tag (if 192 was wrong) or a justification (if this is a tradeoff for a new TC layout)?
[ ... ]
Sukhdeep Soni [C]
maintainerRE: [EXTERNAL] Re: [PATCH net-next v4 10/12] net: atlantic: add AQC113 PTP hardware ops in hw_atl2
Quoted 25 lines · Jakub Kicinski
net: atlantic: add AQC113 PTP hardware ops in
hw_atl2This patch wires the AQC113 (Antigua) PTP hardware ops into
hw_atl2:
TSG clock setup/adjust, PTP ring init, TX timestamp readback from descriptor writeback, RX timestamp extraction from packet trailer, and GPIO pulse / PPS output. It also reducesHW_ATL2_RXBUF_MAXfrom 192 to 172.[Low]
On the commit message itself, a couple of descriptions look like they do not quite match the code that landed in this patch:-
hw_atl2.h/hw_atl2_utils.h/hw_atl2_internal.h: export PTP function prototypes, per-instanceaq_ptp_offsetarrays, RX timestamp sizeEvery new
hw_atl2PTP function is static inhw_atl2.cand is reached only throughhw_atl2_ops, so are any prototypes actually being exported from the headers? The new HW_ATL2_PTP_OFFSET_* additions inhw_atl2.hare also individual scalar #defines, not arrays — should the wording be adjusted?-
hw_atl2.c: implementhw_atl2_enable_ptp()to program TSG clocks, PTP TC receive path and filter ART entries, and re-enable PTP state after hardware reset.
Quoted 5 lines
The
hw_atl2_enable_ptp()body only resets/enables the TSG clocks, optionally callshw_atl2_adj_clock_freq(), and toggleshw_atl2_tpb_tps_highest_priority_tc_enable_set(). Is the "PTP TC receive path and filter ART entries" claim describing this patch, or work that lives in another patch in the series?
Both descriptions have been corrected in v5:
- The header bullet now reads "add PTP offset constants, RX timestamp size (HW_ATL2_RX_TS_SIZE=8), and reduced HW_ATL2_RXBUF_MAX=172" - no mention of exported prototypes or arrays.
- The hw_atl2_enable_ptp() bullet now reads "reset and enable TSG clocks and set PTP TC scheduling priority after hardware reset" - accurately reflecting what the function does.
Quoted 46 lines
drivers/net/ethernet/aquantia/atlantic/hw_atl2/hw_atl2.c +8
-0@@ -127,6 +137,7 @@ static u32 hw_atl2_sem_act_rslvr_get(struct aq_hw_s *self)static int hw_atl2_hw_reset (struct aq_hw_s *self) {struct hw_atl2_priv *priv = self->priv; +s8 clk_sel;int err;int i;@@ -144,6 +155,13 @@ static int hw_atl2_hw_reset(struct aq_hw_s *self) priv->l3l4_filters[i].l4_index =-1 ; } + clk_sel =READ_ONCE (self->clk_select); +if (clk_sel !=-1 ) +hw_atl2_enable_ptp (self, + clk_sel, +aq_utils_obj_test (&self->flags,AQ_HW_PTP_AVAILABLE ) ? +1 :0 ); +[Medium]
Where isself->clk_selectinitialised to -1?struct
aq_hw_sis allocated throughkzalloc_obj()inaq_pci_func.c, soclk_selectstarts as 0, and 0 is also a valid clock index (ATL_TSG_CLOCK_SEL_0). On the very first aq_nic_init()->hw_reset() the test:if (clk_sel != -1) hw_atl2_enable_ptp(self, clk_sel, ...);evaluates true with
clk_sel== 0, andAQ_HW_PTP_AVAILABLEis not set yet at this point in the series (aq_ptp_init()in this tree only sets it for the a1 PTP path), sohw_atl2_enable_ptp(self, 0, 0)gets unconditionally called for everyhw_atl2chip including aqc115c and aqc116c.That call then does:
Quoted 8 lines
hw_atl2_tsg_clock_reset(self, 0); hw_atl2_tsg_clock_en(self, 1, 0); hw_atl2_tsg_clock_en(self, 0, 0); hw_atl2_tpb_tps_highest_priority_tc_enable_set(self, 0);on parts that may have no PTP setup at all. Should the -1 sentinel initialisation that lives in a later patch in the series be folded into this commit so each commit is self-contained for bisection?
The -1 sentinel initialisation has been moved into this patch - self->aq_hw->clk_select = -1 is now set in aq_pci_func.c within this commit, before hw_reset() is ever called. Each commit is now self-contained for bisection.
Quoted 49 lines
drivers/net/ethernet/aquantia/atlantic/hw_atl2/hw_atl2.c +20
-2self->aq_fw_ops->set_state (self,MPI_RESET ); err =aq_hw_err_from_flags (self);@@ -725,14 +743,32 @@ static int hw_atl2_hw_ring_rx_init(struct aq_hw_s *self,struct aq_ring_s *aq_ring, struct aq_ring_param_s *aq_ring_param) { - return hw_atl_b0_hw_ring_rx_init(self, aq_ring, aq_ring_param); + int res = hw_atl_b0_hw_ring_rx_init(self, aq_ring, aq_ring_param); + +if (!res &&aq_ptp_ring (aq_ring->aq_nic, aq_ring)) { +int rx_err =hw_atl2_hw_rx_ptp_ring_init (self, aq_ring); + +if (!res) + res = rx_err; + } + +return res; }static int hw_atl2_hw_ring_tx_init (struct aq_hw_s *self,struct aq_ring_s *aq_ring,struct aq_ring_param_s *aq_ring_param) { -return hw_atl_b0_hw_ring_tx_init (self, aq_ring, aq_ring_param); +int res =hw_atl_b0_hw_ring_tx_init (self, aq_ring, aq_ring_param); + +if (!res &&aq_ptp_ring (aq_ring->aq_nic, aq_ring)) { +int tx_err =hw_atl2_hw_tx_ptp_ring_init (self, aq_ring); + +if (!res) + res = tx_err; + } + +return res; }[Low]
The inner if (!res) check is provably always true here — the outer if (!res &&aq_ptp_ring(...)) already established res == 0 for the whole block:if (!res && aq_ptp_ring(aq_ring->aq_nic, aq_ring)) { int rx_err = hw_atl2_hw_rx_ptp_ring_init(self, aq_ring); if (!res) /* always true */ res = rx_err; }
Quoted 5 lines
Was the intent to also call the PTP ring init when the b0 init had already failed (and only then preserve the first error), or is the inner test simply redundant and meant to be a plain res =
rx_err?[ ... ]
fixed - the redundant inner if (!res) check has been removed.
Quoted 34 lines
drivers/net/ethernet/aquantia/atlantic/hw_atl2/hw_atl2.c +15
-0@@ -892,6 +928,151 @@ static struct aq_stats_s *hw_atl2_utils_get_hw_stats(struct aq_hw_s *self)return &self->curr_stats; } +static void hw_atl2_enable_ptp (struct aq_hw_s *self, +unsigned int param,int enable) +{ +WRITE_ONCE (self->clk_select, (s8 )param); + +/* enable tsg counter */ +hw_atl2_tsg_clock_reset (self, self->clk_select); +hw_atl2_tsg_clock_en (self, !self->clk_select, enable); +hw_atl2_tsg_clock_en (self, self->clk_select, enable); + +if (enable) +hw_atl2_adj_clock_freq (self,0 ); + +hw_atl2_tpb_tps_highest_priority_tc_enable_set (self, enable); +}[Low]
Is mixing oneWRITE_ONCEstore with three plain reads of the same field intentional?The other accessors in this file (
hw_atl2_hw_reset(),aq_get_ptp_ts(),hw_atl2_adj_sys_clock(),hw_atl2_adj_clock_freq(),hw_atl2_hw_get_clk_sel()) consistently useREAD_ONCE(self->clk_select), suggesting the field is treated as concurrent state. Here the three plain reads afterWRITE_ONCE()defeat that protocol and KCSAN will flag the inconsistent annotations.Would using the local param value (which is what was just stored) be clearer, e.g.:
Quoted 6 lines
s8 sel = (s8)param; WRITE_ONCE(self->clk_select, sel); hw_atl2_tsg_clock_reset(self, sel); hw_atl2_tsg_clock_en(self, !sel, enable); hw_atl2_tsg_clock_en(self, sel, enable);
fixed - hw_atl2_enable_ptp() now stores to a local s8 sel = (s8)param, uses WRITE_ONCE(self->clk_select, sel) for the store, and passes sel directly to all subsequent calls. No bare reads of self->clk_select after the WRITE_ONCE.
Quoted 35 lines
drivers/net/ethernet/aquantia/atlantic/hw_atl2/hw_atl2.c +10
-0+ +static void aq_get_ptp_ts (struct aq_hw_s *self,u64 *stamp) +{ +s8 clk_sel =READ_ONCE (self->clk_select); + +if (clk_sel <0 ) +return ; +if (stamp) + *stamp =hw_atl2_tsg_clock_read (self, clk_sel); +}[Medium]
Can this leave *stamp uninitialised on the early return?The existing callers in
aq_ptp.cdeclare an uninitialised stack variable and pass its address straight in, expecting the callee to populate it:
aq_ptp_gettime():u64 ns; aq_ptp_get_sync_time_from_pkt(aq_nic, NULL, &ns); ... hw_get_ptp_ts() variants are called the same way
aq_ptp_settime():u64 now; aq_nic->aq_hw_ops->hw_get_ptp_ts(aq_nic->aq_hw, &now);
aq_ptp_pps_pin_configure():u64 start; aq_nic->aq_hw_ops->hw_get_ptp_ts(aq_nic->aq_hw, &start);
Quoted 5 lines
When
clk_sel< 0 the newaq_get_ptp_ts()returns without touching *stamp, so the caller then forwards stack garbage as a timestamp (intons_to_timespec64()in the gettime path, intohw_adj_sys_clock()in settime). Should the early return set *stamp = 0 first, or should the prototype be changed to return an error?
fixed - the early return path now sets *stamp = 0 before returning when clk_sel < 0, so callers never observe an uninitialised stack variable.
Quoted 1 line
+
[ ... ]
Quoted 14 lines
drivers/net/ethernet/aquantia/atlantic/hw_atl2/hw_atl2.c +8
-0+static int hw_atl2_hw_rx_ptp_ring_init (struct aq_hw_s *self, +struct aq_ring_s *aq_ring) +{ +hw_atl2_rpf_rx_desc_timestamp_req_set (self, + self->clk_select ==ATL_TSG_CLOCK_SEL_1 ?2 :1 , + aq_ring->idx); +return aq_hw_err_from_flags (self); +}[Low]
This readsself->clk_selectwith a plain access while every other reader of the same field in this file usesREAD_ONCE(). Should this also be:
Quoted 7 lines
s8 clk_sel = READ_ONCE(self->clk_select); hw_atl2_rpf_rx_desc_timestamp_req_set(self, clk_sel == ATL_TSG_CLOCK_SEL_1 ? 2 : 1, aq_ring->idx);[ ... ]
Fixed - hw_atl2_hw_rx_ptp_ring_init() now uses
s8 clk_sel = READ_ONCE(self->clk_select) consistent with all other readers of the field.
Quoted 27 lines
drivers/net/ethernet/aquantia/atlantic/hw_atl2/hw_atl2_internal.h +2
-1@@ -29,7 +29,8 @@#define HW_ATL2_TXBUF_MAX 128U#define HW_ATL2_PTP_TXBUF_SIZE 8U -#define HW_ATL2_RXBUF_MAX 192U +/* AQC113 on-chip RX packet buffer available for data TCs */ +#define HW_ATL2_RXBUF_MAX 172U#define HW_ATL2_PTP_RXBUF_SIZE 16U#define HW_ATL2_RSS_REDIRECTION_MAX 64U[Medium]
The comment scopes this change to AQC113, butHW_ATL2_RXBUF_MAXis used unconditionally inhw_atl2_hw_qos_set():u32 rx_buff_size = HW_ATL2_RXBUF_MAX;for
hw_atl2_caps_aqc113,hw_atl2_caps_aqc115candhw_atl2_caps_aqc116c, with no per-chip selection. Does the same on-chip 172 KB limit apply to aqc115c and aqc116c, or does this silently shrink the RX buffer pool for chips outside the stated scope of the patch?
Quoted 8 lines
The non-PTP path on AQC113 is also affected:
hw_atl2_hw_qos_set()already subtractsHW_ATL2_PTP_RXBUF_SIZE(16) whencfg->is_ptpis set, so the PTP TC reservation is independent of this base value. Would it make sense to split theRXBUF_MAXchange into its own commit with a Fixes: tag (if 192 was wrong) or a justification (if this is a tradeoff for a new TC layout)?[ ... ]
The value 172 is taken directly from the vendor reference driver which uses HW_ATL2_RXBUF_MAX = 172U for all hw_atl2 variants. The 192 value in the upstream tree was incorrect - 172 KB is the correct on-chip RX packet buffer limit across all hw_atl2 chips (aqc113, aqc115c, aqc116c). We will update the comment to remove the AQC113 scope and reflect that this corrects the value for all hw_atl2 variants.
[email protected]
maintainerPATCH v4 11/12 net: atlantic: add AQC113 TX timestamp polling and PTP TX classification
In reply to [email protected]From: Sukhdeep Singh <[email protected]>
aq_ring.h / aq_ring.c:
- Add ptp_ts_deadline field to aq_ring_s to track TX timestamp timeout.
- In aq_ring_tx_clean(): when hw_ring_tx_ptp_get_ts() returns 0 (HW not yet written back the timestamp), clear buff->is_mapped and buff->pa before breaking to prevent double dma_unmap on retry. When ptp_ts_deadline expires, clear request_ts and free the skb via dev_kfree_skb_any() to unblock the ring if HW never delivers the timestamp.
aq_main.c:
- Add IPv6 PTP packet detection in aq_ndev_start_xmit() using ipv6_hdr()->nexthdr for ETH_P_IPV6 frames, steering them through aq_ptp_xmit() alongside the existing IPv4 path.
- Use PTP_EV_PORT/PTP_GEN_PORT constants instead of magic numbers 319/320.
- Remove stale aq_ndev_open() PTP call that was moved to aq_nic_start().
aq_nic.c:
- Move aq_reapply_rxnfc_all_rules() and aq_filters_vlans_update() into aq_nic_start() after hardware init, replacing the duplicate calls that were removed from aq_ndev_open().
--- .../net/ethernet/aquantia/atlantic/aq_main.c | 30 ++++++++++--------- .../net/ethernet/aquantia/atlantic/aq_nic.c | 8 +++++ .../net/ethernet/aquantia/atlantic/aq_ring.c | 23 +++++++++++++- .../net/ethernet/aquantia/atlantic/aq_ring.h | 1 + 4 files changed, 47 insertions(+), 15 deletions(-)
drivers/net/ethernet/aquantia/atlantic/aq_main.c +16 -14
@@ -19,8 +19,10 @@#include <linux/netdevice.h> #include <linux/module.h> #include <linux/ip.h> +#include <linux/ipv6.h> #include <linux/udp.h> #include <net/pkt_cls.h> +#include <linux/ptp_classify.h> #include <net/pkt_sched.h> #include <linux/filter.h>
@@ -68,14 +70,6 @@ int aq_ndev_open(struct net_device *ndev)if (err <0 ) goto err_exit; - err =aq_reapply_rxnfc_all_rules (aq_nic); -if (err <0 ) - goto err_exit; - - err =aq_filters_vlans_update (aq_nic); -if (err <0 ) - goto err_exit; - err =aq_nic_start (aq_nic);if (err <0 ) {aq_nic_stop (aq_nic);
@@ -113,12 +107,20 @@ static netdev_tx_t aq_ndev_start_xmit(struct sk_buff *skb, struct net_device *nd* and hardware PTP design of the chip. Otherwise ptp stream * will fail to sync */ -if (unlikely (skb_shinfo (skb)->tx_flags &SKBTX_HW_TSTAMP ) || -unlikely ((ip_hdr (skb)->version ==4 ) && - (ip_hdr (skb)->protocol ==IPPROTO_UDP ) && - ((udp_hdr (skb)->dest ==htons (319 )) || - (udp_hdr (skb)->dest ==htons (320 )))) || -unlikely (eth_hdr (skb)->h_proto ==htons (ETH_P_1588 ))) +if (unlikely (skb->protocol ==htons (ETH_P_IP ) && +ip_hdr (skb)->protocol ==IPPROTO_UDP && + (udp_hdr (skb)->dest ==htons (PTP_EV_PORT ) || +udp_hdr (skb)->dest ==htons (PTP_GEN_PORT )))) +return aq_ptp_xmit (aq_nic, skb); + +/* PTP over IPv6 does not use extension headers */ +if (unlikely (skb->protocol ==htons (ETH_P_IPV6 ) && +ipv6_hdr (skb)->nexthdr ==IPPROTO_UDP && + (udp_hdr (skb)->dest ==htons (PTP_EV_PORT ) || +udp_hdr (skb)->dest ==htons (PTP_GEN_PORT )))) +return aq_ptp_xmit (aq_nic, skb); + +if (unlikely (eth_hdr (skb)->h_proto ==htons (ETH_P_1588 ))) return aq_ptp_xmit(aq_nic, skb); }#endif
drivers/net/ethernet/aquantia/atlantic/aq_nic.c +8 -0
@@ -496,6 +496,14 @@ int aq_nic_start(struct aq_nic_s *self) goto err_exit; } + err =aq_reapply_rxnfc_all_rules (self); +if (err <0 ) + goto err_exit; + + err =aq_filters_vlans_update (self); +if (err <0 ) + goto err_exit; + err =aq_ptp_ring_start (self);if (err <0 ) goto err_exit;
drivers/net/ethernet/aquantia/atlantic/aq_ring.c +22 -1
@@ -311,6 +311,27 @@ bool aq_ring_tx_clean(struct aq_ring_s *self)if (likely (!buff->is_eop)) goto out; +if (unlikely (buff->request_ts) && + self->aq_nic->aq_hw_ops->hw_ring_tx_ptp_get_ts) { +u64 ts = self->aq_nic->aq_hw_ops->hw_ring_tx_ptp_get_ts (self); + +if (!ts) { +if (time_after (jiffies, + self->ptp_ts_deadline)) { +/* Timeout: free skb, unblock ring */ + buff->request_ts =0 ; +dev_kfree_skb_any (buff->skb); + buff->skb =NULL ; + goto out; + }else { + buff->is_mapped =0 ; + buff->pa =0U ; +break ; + } + } + +aq_ptp_tx_hwtstamp (self->aq_nic, ts); + }if (buff->skb) {u64_stats_update_begin (&self->stats.tx.syncp); ++self->stats.tx.packets;
@@ -570,7 +591,7 @@ static int __aq_ring_rx_clean(struct aq_ring_s *self, struct napi_struct *napi, self->hw_head);if (unlikely (!is_rsc_completed) || - frag_cnt >MAX_SKB_FRAGS ) { + frag_cnt >MAX_SKB_FRAGS ) { err =0 ; goto err_exit; }
drivers/net/ethernet/aquantia/atlantic/aq_ring.h +1 -0
@@ -154,6 +154,7 @@ struct aq_ring_s {struct bpf_prog *xdp_prog;enum atl_ring_type ring_type;struct xdp_rxq_info xdp_rxq; +unsigned long ptp_ts_deadline; };struct aq_ring_param_s {
Signature · 1 line
2.43.0
Jakub Kicinski
maintainerRe: [PATCH net-next v4 11/12] net: atlantic: add AQC113 TX timestamp polling and PTP TX classification
This is an AI-generated review of your patch. The human sending this email has considered the AI review valid, or at least plausible.
---
net: atlantic: add AQC113 TX timestamp polling and PTP TX classification
This patch wires PTP TX timestamp polling into aq_ring_tx_clean(), adds IPv6 PTP packet classification in aq_ndev_start_xmit(), and moves the RX-flow and VLAN filter reapply calls from aq_ndev_open() into aq_nic_start().
Quoted 7 lines
drivers/net/ethernet/aquantia/atlantic/aq_main.c +0
-0@@ -68,14 +70,6 @@ int aq_ndev_open(struct net_device *ndev)if (err <0 ) goto err_exit;
drivers/net/ethernet/aquantia/atlantic/aq_main.c int aq_ndev_open(struct net_device *ndev) · line 73
Quoted 10 lines
drivers/net/ethernet/aquantia/atlantic/aq_main.c +0
-8- err =aq_reapply_rxnfc_all_rules (aq_nic); -if (err <0 ) - goto err_exit; - - err =aq_filters_vlans_update (aq_nic); -if (err <0 ) - goto err_exit; - err =aq_nic_start (aq_nic);
[Low]
The commit message bullet says:
Remove stale aq_ndev_open() PTP call that was moved to aq_nic_start().
The lines actually removed from aq_ndev_open() are aq_reapply_rxnfc_all_rules() and aq_filters_vlans_update(), which are RX-flow-classifier and VLAN-filter helpers rather than PTP calls. Should this bullet be reworded to describe the filter helpers that were actually moved?
Also, aq_nic_start() is invoked from atl_resume_common() in aq_pci_func.c in addition to aq_ndev_open(). Moving these helpers into aq_nic_start() means RX-flow and VLAN filters will now be reapplied on every PM resume, which is a behavioral change beyond plain deduplication. Should the changelog call this resume-path side effect out explicitly?
[ ... ]
Quoted 10 lines
drivers/net/ethernet/aquantia/atlantic/aq_ring.c +2
-0@@ -311,6 +311,27 @@ bool aq_ring_tx_clean(struct aq_ring_s *self)if (likely (!buff->is_eop)) goto out; +if (unlikely (buff->request_ts) && + self->aq_nic->aq_hw_ops->hw_ring_tx_ptp_get_ts) {
drivers/net/ethernet/aquantia/atlantic/aq_ring.c bool aq_ring_tx_clean(struct aq_ring_s *self) · line 325
Quoted 10 lines
drivers/net/ethernet/aquantia/atlantic/aq_ring.c +10
-0+u64 ts = self->aq_nic->aq_hw_ops->hw_ring_tx_ptp_get_ts (self); + +if (!ts) { +if (time_after (jiffies, + self->ptp_ts_deadline)) { +/* Timeout: free skb, unblock ring */ + buff->request_ts =0 ; +dev_kfree_skb_any (buff->skb); + buff->skb =NULL ; + goto out;
[Medium]
Can the timeout branch desynchronize aq_ptp->skb_ring from buff_ring?
aq_ptp_xmit() pushes every PTP TX skb into aq_ptp->skb_ring via aq_ptp_skb_put() (which holds its own reference via skb_get()), and aq_ptp_tx_hwtstamp() consumes them in strict FIFO order:
aq_ptp.c:aq_ptp_tx_hwtstamp() {
struct sk_buff *skb = aq_ptp_skb_get(&aq_ptp->skb_ring);
...
skb_tstamp_tx(skb, &hwtstamp);
dev_kfree_skb_any(skb);
}The new timeout branch frees buff->skb and advances sw_head, but does not dequeue the matching entry from aq_ptp->skb_ring. After a timeout, the stale skb pointer remains at the head of skb_ring while the buff_ring moves on.
When the next PTP TX timestamp arrives, would aq_ptp_tx_hwtstamp() pop that stale skb and call skb_tstamp_tx() with the timestamp belonging to a later, unrelated packet? Every subsequent PTP packet would then have its TX timestamp misattributed by one slot until aq_ptp_tx_timeout_check() calls aq_ptp_skb_ring_clean() to fully drain skb_ring (~10s later).
Should the timeout branch also dequeue and drop the head of skb_ring, e.g. via aq_ptp_skb_get() followed by dev_kfree_skb_any() of the returned skb, to keep skb_ring and buff_ring in lockstep?
Quoted 12 lines
drivers/net/ethernet/aquantia/atlantic/aq_ring.c +9
-0+ }else { + buff->is_mapped =0 ; + buff->pa =0U ; +break ; + } + } + +aq_ptp_tx_hwtstamp (self->aq_nic, ts); + }if (buff->skb) {u64_stats_update_begin (&self->stats.tx.syncp); ++self->stats.tx.packets;
[ ... ]
Sukhdeep Soni [C]
maintainerRE: [EXTERNAL] Re: [PATCH net-next v4 11/12] net: atlantic: add AQC113 TX timestamp polling and PTP TX classification
Quoted 36 lines · Jakub Kicinski
net: atlantic: add AQC113 TX timestamp polling and PTP TX classification
This patch wires PTP TX timestamp polling into
aq_ring_tx_clean(), adds IPv6 PTP packet classification inaq_ndev_start_xmit(), and moves the RX-flow and VLAN filter reapply calls fromaq_ndev_open()intoaq_nic_start().drivers/net/ethernet/aquantia/atlantic/aq_main.c +0
-8@@ -68,14 +70,6 @@ int aq_ndev_open(struct net_device *ndev)if (err <0 ) goto err_exit; - err =aq_reapply_rxnfc_all_rules (aq_nic); -if (err <0 ) - goto err_exit; - - err =aq_filters_vlans_update (aq_nic); -if (err <0 ) - goto err_exit; - err =aq_nic_start (aq_nic);[Low]
The commit message bullet says:Remove stale
aq_ndev_open()PTP call that was moved toaq_nic_start().The lines actually removed from
aq_ndev_open()areaq_reapply_rxnfc_all_rules()andaq_filters_vlans_update(), which are RX-flow-classifier and VLAN-filter helpers rather than PTP calls. Should this bullet be reworded to describe the filter helpers that were actually moved?
Quoted 7 lines
Also,
aq_nic_start()is invoked fromatl_resume_common()inaq_pci_func.cin addition toaq_ndev_open(). Moving these helpers intoaq_nic_start()means RX-flow and VLAN filters will now be reapplied on every PM resume, which is a behavioral change beyond plain deduplication. Should the changelog call this resume-path side effect out explicitly?[ ... ]
Both points are already addressed in the commit message:
- The bullet correctly names aq_reapply_rxnfc_all_rules() and aq_filters_vlans_update() as the calls removed from aq_ndev_open() — no mention of "PTP call".
- The PM resume side effect is explicitly documented:
"which also ensures filters are restored correctly after PM resume".
Quoted 54 lines
drivers/net/ethernet/aquantia/atlantic/aq_ring.c +12
-0@@ -311,6 +311,27 @@ bool aq_ring_tx_clean(struct aq_ring_s *self)if (likely (!buff->is_eop)) goto out; +if (unlikely (buff->request_ts) && + self->aq_nic->aq_hw_ops->hw_ring_tx_ptp_get_ts) { +u64 ts = self->aq_nic->aq_hw_ops->hw_ring_tx_ptp_get_ts (self); + +if (!ts) { +if (time_after (jiffies, + self->ptp_ts_deadline)) { +/* Timeout: free skb, unblock ring */ + buff->request_ts =0 ; +dev_kfree_skb_any (buff->skb); + buff->skb =NULL ; + goto out;[Medium]
Can the timeout branch desynchronizeaq_ptp->skb_ringfrombuff_ring?
aq_ptp_xmit()pushes every PTP TX skb intoaq_ptp->skb_ringviaaq_ptp_skb_put()(which holds its own reference viaskb_get()), andaq_ptp_tx_hwtstamp()consumes them in strict FIFO order:aq_ptp.c:aq_ptp_tx_hwtstamp() { struct sk_buff *skb = aq_ptp_skb_get(&aq_ptp->skb_ring); ... skb_tstamp_tx(skb, &hwtstamp); dev_kfree_skb_any(skb); }The new timeout branch frees
buff->skband advancessw_head, but does not dequeue the matching entry fromaq_ptp->skb_ring. After a timeout, the stale skb pointer remains at the head ofskb_ringwhile thebuff_ringmoves on.When the next PTP TX timestamp arrives, would
aq_ptp_tx_hwtstamp()pop that stale skb and callskb_tstamp_tx()with the timestamp belonging to a later, unrelated packet? Every subsequent PTP packet would then have its TX timestamp misattributed by one slot untilaq_ptp_tx_timeout_check()callsaq_ptp_skb_ring_clean()to fully drainskb_ring(~10s later).Should the timeout branch also dequeue and drop the head of
skb_ring, e.g. viaaq_ptp_skb_get()followed bydev_kfree_skb_any()of the returned skb, to keepskb_ringandbuff_ringin lockstep?drivers/net/ethernet/aquantia/atlantic/aq_ring.c +4
-0+ }else { + buff->is_mapped =0 ; + buff->pa =0U ; +break ;
drivers/net/ethernet/aquantia/atlantic/aq_ring.c bool aq_ring_tx_clean(struct aq_ring_s *self)
Quoted 10 lines
drivers/net/ethernet/aquantia/atlantic/aq_ring.c +5
-0+ } + } + +aq_ptp_tx_hwtstamp (self->aq_nic, ts); + }if (buff->skb) {u64_stats_update_begin (&self->stats.tx.syncp); ++self->stats.tx.packets;
handled - aq_ptp_tx_skb_drop_head() is introduced in this patch precisely to address this desynchronization. The timeout branch calls it before advancing sw_head, which calls aq_ptp_skb_get(&aq_ptp->skb_ring) followed by dev_kfree_skb_any() on the returned skb, keeping skb_ring and buff_ring in lockstep.
[email protected]
maintainerPATCH v4 12/12 net: atlantic: add AQC113 PTP support in aq_ptp and driver core
In reply to [email protected]From: Sukhdeep Singh <[email protected]>
aq_ptp.c / aq_ptp.h:
- Add aq_ptp_state enum (AQ_PTP_FIRST_INIT, AQ_PTP_LINK_UP, AQ_PTP_NO_LINK) to distinguish first init from link-change events; on AQC113 only reset the TSG clock on first init to avoid disrupting ongoing synchronization.
- Add aq_ptp_dpath_enable() for comprehensive L3/L4 PTP filter setup/teardown, replacing the previous single-filter approach with an array of 4 slots for IPv4 and IPv6 PTP multicast addresses (224.0.1.129, 224.0.0.107, ff0e::181, ff02::6b).
- Add aq_ptp_parse_rx_filters() to map hwtstamp_rx_filters to L2/L4 enable flags and call aq_ptp_dpath_enable().
- Re-apply RX filters on link change (hardware state lost after reset).
- Extend PTP ring alloc/init/start/stop to handle AQC113 PTP ring ops.
- Add per-instance PTP offset table for AQC113 with empirically measured values at 100M/1G/2.5G/5G/10G link speeds.
- Export aq_ptp_dpath_enable() and updated ring helpers in aq_ptp.h.
aq_hw.h:
- Include hw_atl2/hw_atl2.h for AQC113 PTP type definitions.
aq_nic.c:
- Account for PTP IRQ vector (AQ_HW_PTP_IRQS) in vector count math.
- Call hw_atl2 PTP re-enable hook after hardware reset in aq_nic_update_link_status().
aq_pci_func.c:
- Pass PTP IRQ index to aq_ptp_irq_alloc() in probe path.
--- .../net/ethernet/aquantia/atlantic/aq_hw.h | 1 + .../net/ethernet/aquantia/atlantic/aq_nic.c | 42 +- .../ethernet/aquantia/atlantic/aq_pci_func.c | 5 +- .../net/ethernet/aquantia/atlantic/aq_ptp.c | 558 ++++++++++++++---- .../net/ethernet/aquantia/atlantic/aq_ptp.h | 15 +- 5 files changed, 483 insertions(+), 138 deletions(-)
drivers/net/ethernet/aquantia/atlantic/aq_hw.h +1 -0
@@ -15,6 +15,7 @@#include "aq_common.h" #include "aq_rss.h" #include "hw_atl/hw_atl_utils.h" +#include "hw_atl2/hw_atl2.h" #define AQ_HW_MAC_COUNTER_HZ 312500000ll#define AQ_HW_PHY_COUNTER_HZ 160000000ll
drivers/net/ethernet/aquantia/atlantic/aq_nic.c +37 -5
84 lines not on this page · raw message
drivers/net/ethernet/aquantia/atlantic/aq_pci_func.c +3 -2
@@ -250,6 +250,7 @@ static int aq_pci_probe(struct pci_dev *pdev, goto err_ioremap; } self->aq_hw->aq_nic_cfg =aq_nic_get_cfg (self); + self->aq_hw->clk_select =-1 ;if (self->aq_hw->aq_nic_cfg->aq_hw_caps->priv_data_len) {int len = self->aq_hw->aq_nic_cfg->aq_hw_caps->priv_data_len;
@@ -293,8 +294,8 @@ static int aq_pci_probe(struct pci_dev *pdev, numvecs =min ((u8 )AQ_CFG_VECS_DEF ,aq_nic_get_cfg (self)->aq_hw_caps->msix_irqs); numvecs =min (numvecs,num_online_cpus ()); -/* Request IRQ vector for PTP */ - numvecs +=1 ; +/* Request IRQ lines for PTP */ + numvecs +=AQ_HW_PTP_IRQS ; numvecs +=AQ_HW_SERVICE_IRQS ;/*enable interrupts */
drivers/net/ethernet/aquantia/atlantic/aq_ptp.c +431 -127
837 lines not on this page · raw message
drivers/net/ethernet/aquantia/atlantic/aq_ptp.h +11 -4
@@ -14,6 +14,12 @@#include "aq_ring.h" +enum aq_ptp_state { +AQ_PTP_NO_LINK =0 , +AQ_PTP_FIRST_INIT =1 , +AQ_PTP_LINK_UP =2 , +}; +#define PTP_8TC_RING_IDX 8#define PTP_4TC_RING_IDX 16#define PTP_HWST_RING_IDX 31
@@ -32,7 +38,7 @@ static inline unsigned int aq_ptp_ring_idx(const enum aq_tc_mode tc_mode)#if IS_REACHABLE (CONFIG_PTP_1588_CLOCK )/* Common functions */ -int aq_ptp_init (struct aq_nic_s *aq_nic,unsigned int idx_vec); +int aq_ptp_init (struct aq_nic_s *aq_nic,unsigned int idx_ptp_vec);void aq_ptp_unregister (struct aq_nic_s *aq_nic);void aq_ptp_free (struct aq_nic_s *aq_nic);
@@ -52,7 +58,7 @@ void aq_ptp_service_task(struct aq_nic_s *aq_nic);void aq_ptp_tm_offset_set (struct aq_nic_s *aq_nic,unsigned int mbps); -void aq_ptp_clock_init (struct aq_nic_s *aq_nic); +void aq_ptp_clock_init (struct aq_nic_s *aq_nic,enum aq_ptp_state state);/* Traffic processing functions */ int aq_ptp_xmit (struct aq_nic_s *aq_nic,struct sk_buff *skb);
@@ -80,7 +86,7 @@ u64 *aq_ptp_get_stats(struct aq_nic_s *aq_nic, u64 *data);#else -static inline int aq_ptp_init (struct aq_nic_s *aq_nic,unsigned int idx_vec) +static inline int aq_ptp_init (struct aq_nic_s *aq_nic,unsigned int idx_ptp_vec) {return 0 ; }
@@ -122,7 +128,8 @@ static inline void aq_ptp_ring_deinit(struct aq_nic_s *aq_nic) {}static inline void aq_ptp_service_task (struct aq_nic_s *aq_nic) {}static inline void aq_ptp_tm_offset_set (struct aq_nic_s *aq_nic,unsigned int mbps) {} -static inline void aq_ptp_clock_init (struct aq_nic_s *aq_nic) {} +static inline void aq_ptp_clock_init (struct aq_nic_s *aq_nic, +enum aq_ptp_state state) {}static inline int aq_ptp_xmit (struct aq_nic_s *aq_nic,struct sk_buff *skb) {return -EOPNOTSUPP ;
Signature · 1 line
2.43.0
Jakub Kicinski
maintainerRe: [PATCH net-next v4 12/12] net: atlantic: add AQC113 PTP support in aq_ptp and driver core
This is an AI-generated review of your patch. The human sending this email has considered the AI review valid, or at least plausible.
---
net: atlantic: add AQC113 PTP support in aq_ptp and driver core
This patch extends the atlantic driver's PTP support to AQC113 (Antigua)
hardware: it adds a per-instance PTP offset table, replaces the single L3/L4 filter with an array of 4 multicast filter slots, introduces an aq_ptp_state enum so link-change events can be distinguished from first init, and reworks vector accounting for the new PTP IRQ count.
Thanks for the patch. A few questions follow inline.
Quoted 4 lines
drivers/net/ethernet/aquantia/atlantic/aq_nic.c +0
-0
[ ... ]
drivers/net/ethernet/aquantia/atlantic/aq_nic.c static int aq_nic_update_link_status(struct aq_nic_s *self) · line 187
Quoted 10 lines
drivers/net/ethernet/aquantia/atlantic/aq_nic.c +5
-1@@ -172,7 +180,11 @@ static int aq_nic_update_link_status(struct aq_nic_s *self)aq_nic_update_interrupt_moderation_settings (self);if (self->aq_ptp) { -aq_ptp_clock_init (self); +/* PTP does not work in some modes even if physical link is up */ +bool ptp_link_good = (self->aq_hw->aq_link_status.mbps >=100 && + self->aq_hw->aq_link_status.full_duplex); + +aq_ptp_clock_init (self, ptp_link_good ?AQ_PTP_LINK_UP :AQ_PTP_NO_LINK );
[Low]
Could the comment here be expanded to record which modes are unsupported and why? PTP is silently disabled below 100 Mbps and for any half-duplex configuration, but the predicate has no reference to a datasheet section, errata, or test result, so a future maintainer adding a new link speed cannot validate or update it.
Quoted 3 lines
drivers/net/ethernet/aquantia/atlantic/aq_nic.c +0
-0aq_ptp_tm_offset_set (self, self->aq_hw->aq_link_status.mbps);aq_ptp_link_change (self);
[ ... ]
Quoted 4 lines
drivers/net/ethernet/aquantia/atlantic/aq_ptp.c +0
-0
[ ... ]
Quoted 9 lines
drivers/net/ethernet/aquantia/atlantic/aq_ptp.c +9
-0+static int aq_ptp_add_a2_filter (struct aq_ptp_s *aq_ptp, +struct ethtool_rx_flow_spec *fsp, +int *flt_idx) +{ +struct aq_nic_s *aq_nic = aq_ptp->aq_nic; +int err; + + err = aq_set_data_fl3l4(fsp, + &aq_ptp->udp_filter[*flt_idx],
drivers/net/ethernet/aquantia/atlantic/aq_ptp.c void aq_ptp_tx_hwtstamp(struct aq_nic_s *aq_nic, u64 timestamp) · line 623
Quoted 10 lines
drivers/net/ethernet/aquantia/atlantic/aq_ptp.c +10
-0+ aq_ptp->udp_filter[*flt_idx].location, + true); +if (!err) { +netdev_dbg (aq_nic->ndev, +"PTP MC filter prepared. Loc: %x\n" , + aq_ptp->udp_filter[*flt_idx].location); + (*flt_idx)++; + } +return err; +}
[Low]
Can aq_set_data_fl3l4() ever return non-zero? Looking at its body it has only one return statement at the end returning 0, which means the caller's "UDPv4/UDPv6 filter prepare failed" debug paths and the flt_idx++ guard here are unreachable. Was the helper expected to validate input (e.g., bad ring_cookie or oversized fields) and reject it?
Quoted 4 lines
drivers/net/ethernet/aquantia/atlantic/aq_ptp.c +4
-0+ +static int aq_ptp_dpath_enable (struct aq_ptp_s *aq_ptp, +int enable_flags,u16 rx_queue) +{
[ ... ]
drivers/net/ethernet/aquantia/atlantic/aq_ptp.c void aq_ptp_tx_hwtstamp(struct aq_nic_s *aq_nic, u64 timestamp) · line 652
Quoted 13 lines
drivers/net/ethernet/aquantia/atlantic/aq_ptp.c +13
-0+if (enable_flags) { +/* Clear all existing L4 filters before applying new config */ +for (i =0 ; i <PTP_UDP_FILTERS_CNT ; i++) { + aq_ptp->udp_filter[i].cmd &= + ~HW_ATL_RX_ENABLE_FLTR_L3L4 ; +if (hw_ops->hw_filter_l3l4_set) { + err = hw_ops->hw_filter_l3l4_set (aq_nic->aq_hw, + &aq_ptp->udp_filter[i]); +if (err) +netdev_dbg (aq_nic->ndev, +"Set UDP filter failed\n" ); + } + }
[Medium]
Can this loop hide partial failures? err is overwritten by every iteration, so if filter[0] or filter[1] fail to clear but filter[3] succeeds, err is reset to 0 by the last call and the function continues on to program new filters on top of a partially-stale slot table with no signal to the caller.
[ ... ]
Quoted 11 lines
drivers/net/ethernet/aquantia/atlantic/aq_ptp.c +11
-0+ }else { +/* PTP disabled, clear all UDP/L2 filters */ +for (i =0 ; i <PTP_UDP_FILTERS_CNT ; i++) { + aq_ptp->udp_filter[i].cmd &= + ~HW_ATL_RX_ENABLE_FLTR_L3L4 ; +if (hw_ops->hw_filter_l3l4_set) { + err = hw_ops->hw_filter_l3l4_set (aq_nic->aq_hw, + &aq_ptp->udp_filter[i]); +if (err) +netdev_dbg (aq_nic->ndev, +"Set UDP filter failed\n" );
drivers/net/ethernet/aquantia/atlantic/aq_ptp.c void aq_ptp_tx_hwtstamp(struct aq_nic_s *aq_nic, u64 timestamp) · line 764
Quoted 10 lines
drivers/net/ethernet/aquantia/atlantic/aq_ptp.c +10
-0+ } + } + +if (!err && hw_ops->hw_filter_l2_clear) + err = hw_ops->hw_filter_l2_clear (aq_nic->aq_hw, + &aq_ptp->eth_type_filter); + } + +return err; +}
[Medium]
Same pattern repeats here on the disable path: an early failing slot is masked by a later successful one, so the function can return success while leaving the L3/L4 slot table partially programmed.
[ ... ]
Quoted 43 lines
int aq_ptp_hwtstamp_config_set(struct
aq_ptp_s*aq_ptp,drivers/net/ethernet/aquantia/atlantic/aq_ptp.c +13
-23struct kernel_hwtstamp_config *config) { +unsigned int ptp_en_flags =aq_ptp_parse_rx_filters (config->rx_filter);struct aq_nic_s *aq_nic = aq_ptp->aq_nic; -const struct aq_hw_ops *hw_ops;int err =0 ; - hw_ops = aq_nic->aq_hw_ops; -if (config->tx_type ==HWTSTAMP_TX_ON || - config->rx_filter ==HWTSTAMP_FILTER_PTP_V2_EVENT ) { -aq_ptp_prepare_filters (aq_ptp); -if (hw_ops->hw_filter_l3l4_set) { - err = hw_ops->hw_filter_l3l4_set (aq_nic->aq_hw, - &aq_ptp->udp_filter); - } -if (!err && hw_ops->hw_filter_l2_set) { - err = hw_ops->hw_filter_l2_set (aq_nic->aq_hw, - &aq_ptp->eth_type_filter); - } +if (aq_ptp->hwtstamp_config.rx_filter != config->rx_filter) { +mutex_lock (&aq_ptp->ptp_filter_lock); + err =aq_ptp_dpath_enable (aq_ptp, + ptp_en_flags, + aq_ptp->ptp_rx.idx); +if (!err) + aq_ptp->hwtstamp_config = *config; +mutex_unlock (&aq_ptp->ptp_filter_lock); + } + +if (ptp_en_flags !=AQ_HW_PTP_DISABLE )aq_utils_obj_set (&aq_nic->flags,AQ_NIC_PTP_DPATH_UP ); - }else { - aq_ptp->udp_filter.cmd &= ~HW_ATL_RX_ENABLE_FLTR_L3L4 ; -if (hw_ops->hw_filter_l3l4_set) { - err = hw_ops->hw_filter_l3l4_set (aq_nic->aq_hw, - &aq_ptp->udp_filter); - } -if (!err && hw_ops->hw_filter_l2_clear) { - err = hw_ops->hw_filter_l2_clear (aq_nic->aq_hw, - &aq_ptp->eth_type_filter); - } +else
drivers/net/ethernet/aquantia/atlantic/aq_ptp.c void aq_ptp_hwtstamp_config_get(struct aq_ptp_s *aq_ptp, · line 844
Quoted 10 lines
drivers/net/ethernet/aquantia/atlantic/aq_ptp.c +0
-3aq_utils_obj_clear (&aq_nic->flags,AQ_NIC_PTP_DPATH_UP ); - }if (err)return -EREMOTEIO ; - aq_ptp->hwtstamp_config = *config; -return 0 ; }
[High]
Can changes to tx_type now be silently lost? The pre-patch code unconditionally cached the new config on success. The new code only writes aq_ptp->hwtstamp_config when rx_filter changed:
if (aq_ptp->hwtstamp_config.rx_filter != config->rx_filter) {
...
if (!err)
aq_ptp->hwtstamp_config = *config;
...
}A user calling SIOCSHWTSTAMP with the same rx_filter but a different tx_type (for example flipping HWTSTAMP_TX_ON) gets a return of 0, but the new tx_type is never stored, so a follow-up SIOCGHWTSTAMP returns the stale prior value.
[High]
Does TX-only HW timestamping still work after this change? Previously "tx_type == HWTSTAMP_TX_ON" alone was enough to install filters and assert AQ_NIC_PTP_DPATH_UP. After the patch, AQ_NIC_PTP_DPATH_UP is driven solely by aq_ptp_parse_rx_filters(config->rx_filter), so a request with rx_filter=NONE and tx_type=ON no longer raises that flag.
aq_ndev_start_xmit() in aq_main.c gates its PTP TX redirection on AQ_NIC_PTP_DPATH_UP, so PTP TX frames are no longer diverted to the PTP TX ring, and TX hardware timestamping silently breaks in TX-only mode.
[Medium]
Can the rx_filter compare race against itself? The check
if (aq_ptp->hwtstamp_config.rx_filter != config->rx_filter)
is performed without holding ptp_filter_lock, while the same field is written under the lock further down in this function and read by aq_ptp_clock_init() on the link-change path.
[Medium]
Is the AQ_NIC_PTP_DPATH_UP update safe outside the lock? The aq_utils_obj_set/clear calls run unconditionally based on the requested ptp_en_flags, even when:
- aq_ptp_dpath_enable() was not invoked at all because rx_filter was unchanged, or
- it was invoked but returned an error and hwtstamp_config was therefore not updated.
In the failure case the function still asserts AQ_NIC_PTP_DPATH_UP and then returns -EREMOTEIO, so userspace is told the operation failed while the global flag claims the datapath is up and steers transmits to a PTP ring whose hardware setup may be inconsistent.
[ ... ]
Quoted 18 lines
drivers/net/ethernet/aquantia/atlantic/aq_ptp.c +11
-4-void aq_ptp_clock_init (struct aq_nic_s *aq_nic) +void aq_ptp_clock_init (struct aq_nic_s *aq_nic,enum aq_ptp_state state) {struct aq_ptp_s *aq_ptp = aq_nic->aq_ptp; -struct timespec64 ts; -ktime_get_real_ts64 (&ts); -aq_ptp_settime (&aq_ptp->ptp_info, &ts); +if (!aq_ptp) +return ; + +if (aq_ptp->a1_ptp || state ==AQ_PTP_FIRST_INIT ) { +struct timespec64 ts; + +ktime_get_real_ts64 (&ts); +aq_ptp_settime (&aq_ptp->ptp_info, &ts); + } +
drivers/net/ethernet/aquantia/atlantic/aq_ptp.c static void aq_ptp_gpio_init(struct ptp_clock_info *info, · line 1397
Quoted 10 lines
drivers/net/ethernet/aquantia/atlantic/aq_ptp.c +9
-0+if (!aq_ptp->a1_ptp && state !=AQ_PTP_FIRST_INIT ) { +unsigned int ptp_en_flags = +aq_ptp_parse_rx_filters (state ==AQ_PTP_LINK_UP ? + aq_ptp->hwtstamp_config.rx_filter : +HWTSTAMP_FILTER_NONE ); +mutex_lock (&aq_ptp->ptp_filter_lock); +aq_ptp_dpath_enable (aq_ptp, ptp_en_flags, aq_ptp->ptp_rx.idx); +mutex_unlock (&aq_ptp->ptp_filter_lock); + } }
[Medium]
Should the read of aq_ptp->hwtstamp_config.rx_filter happen inside ptp_filter_lock? The field is sampled here without holding the lock, then the lock is acquired to call aq_ptp_dpath_enable() with the value read. The same field is mutated under the lock by aq_ptp_hwtstamp_config_set().
A concurrent SIOCSHWTSTAMP from userspace can race with the link-change caller (process context: aq_nic_service_task or aq_linkstate_threaded_isr): the link path reads the old rx_filter, queues behind the writer for the lock, then applies the old filter set to hardware after the writer just installed the new one.
The unlocked read is also a data race per the kernel memory model.
[Medium]
Is it intentional that the return value of aq_ptp_dpath_enable() is discarded here? The commit message says this path exists to "Re-apply RX filters on link change (hardware state lost after reset)", so a silent failure means PTP RX timestamping is silently broken across the link change.
aq_ptp_hwtstamp_config_set() captures and propagates the same return value, so the asymmetry looks like an oversight.
[ ... ]
Quoted 3 lines
drivers/net/ethernet/aquantia/atlantic/aq_ptp.c +1
-1-int aq_ptp_init (struct aq_nic_s *aq_nic,unsigned int idx_vec) +int aq_ptp_init (struct aq_nic_s *aq_nic,unsigned int idx_ptp_vec) {
[ ... ]
Quoted 9 lines
drivers/net/ethernet/aquantia/atlantic/aq_ptp.c +3
-0aq_ptp->aq_nic = aq_nic; aq_ptp->a1_ptp = a1_ptp; + aq_ptp->a2_ptp = a2_ptp;spin_lock_init (&aq_ptp->ptp_lock);spin_lock_init (&aq_ptp->ptp_ring_lock); +mutex_init (&aq_ptp->ptp_filter_lock); +aq_ptp_offset_init (aq_ptp, &mbox.info.ptp_offset);
[ ... ]
Quoted 22 lines
drivers/net/ethernet/aquantia/atlantic/aq_ptp.c +9
-5- aq_ptp->idx_vector = idx_vec; + aq_ptp->idx_ptp_vector = idx_ptp_vec; aq_nic->aq_ptp = aq_ptp;/* enable ptp counter */ + aq_ptp->ptp_clock_sel =ATL_TSG_CLOCK_SEL_0 ;aq_utils_obj_set (&aq_nic->aq_hw->flags,AQ_HW_PTP_AVAILABLE ); -mutex_lock (&aq_nic->fwreq_mutex); - aq_nic->aq_fw_ops->enable_ptp (aq_nic->aq_hw,1 ); -aq_ptp_clock_init (aq_nic); -mutex_unlock (&aq_nic->fwreq_mutex); +if (a1_ptp) { +mutex_lock (&aq_nic->fwreq_mutex); + aq_nic->aq_fw_ops->enable_ptp (aq_nic->aq_hw,1 ); +mutex_unlock (&aq_nic->fwreq_mutex); + } +if (a2_ptp) + aq_nic->aq_hw_ops->enable_ptp (aq_nic->aq_hw, aq_ptp->ptp_clock_sel,1 );INIT_DELAYED_WORK (&aq_ptp->poll_sync, &aq_ptp_poll_sync_work_cb); aq_ptp->eth_type_filter.location =
drivers/net/ethernet/aquantia/atlantic/aq_ptp.c int aq_ptp_init(struct aq_nic_s *aq_nic, unsigned int idx_vec) · line 1514
Quoted 10 lines
drivers/net/ethernet/aquantia/atlantic/aq_ptp.c +7
-2-aq_nic_reserve_filter (aq_nic, aq_rx_filter_ethertype); - aq_ptp->udp_filter.location = +aq_nic_reserve_filter (aq_nic, aq_rx_filter_ethertype); + +for (i =0 ; i <PTP_UDP_FILTERS_CNT ; i++) { + aq_ptp->udp_filter[i].location =aq_nic_reserve_filter (aq_nic, aq_rx_filter_l3l4); + } + +aq_ptp_clock_init (aq_nic,AQ_PTP_FIRST_INIT );
[Low]
Should the TSG clock be initialized with wall-clock time before it is started? On AQC113 the call sequence is:
aq_nic->aq_hw_ops->enable_ptp(aq_nic->aq_hw, aq_ptp->ptp_clock_sel, 1);
...
aq_ptp_clock_init(aq_nic, AQ_PTP_FIRST_INIT);hw_atl2_enable_ptp(self, 0, 1) zeroes the TSG counter and starts it, while aq_ptp_clock_init(AQ_PTP_FIRST_INIT) is the only path that calls aq_ptp_settime() to load wall-clock time. Between these two steps the TSG clock is freely incrementing from zero with AQ_HW_PTP_AVAILABLE already set and aq_nic->aq_ptp already published, so a concurrent reader observes an enabled-but-uninitialized clock returning a near- zero value.
[Medium]
On AQC107 (a1_ptp), only a single L3/L4 filter is ever programmed in aq_ptp_dpath_enable() (the a1_ptp branch installs one UDPv4 filter and increments flt_idx once), but this loop reserves PTP_UDP_FILTERS_CNT == 4 slots on every chip:
for (i = 0; i < PTP_UDP_FILTERS_CNT; i++) {
aq_ptp->udp_filter[i].location =
aq_nic_reserve_filter(aq_nic, aq_rx_filter_l3l4);
}The L3/L4 slot pool has eight entries (AQ_RX_LAST_LOC_FL3L4 - AQ_RX_FIRST_LOC_FL3L4 + 1). Reserving four instead of one on AQC107 reduces user-visible ethtool ntuple ring- cookie capacity from seven to four. Could the reservation count be gated on a2_ptp?
[Low]
Is the publication order of aq_nic->aq_ptp and AQ_HW_PTP_AVAILABLE intentional?
aq_nic->aq_ptp = aq_ptp;
...
aq_utils_obj_set(&aq_nic->aq_hw->flags, AQ_HW_PTP_AVAILABLE);
...
INIT_DELAYED_WORK(&aq_ptp->poll_sync, ...);
aq_ptp->eth_type_filter.location = ...;
for (i = 0; i < PTP_UDP_FILTERS_CNT; i++)
aq_ptp->udp_filter[i].location = ...;The pointer and the global flag are exposed several statements before INIT_DELAYED_WORK and before filter slot reservations. Any future error-recovery rollback that calls aq_ptp_free() on a partially- initialized aq_ptp will run cancel_delayed_work_sync() on an uninitialized struct delayed_work.
Quoted 4 lines
drivers/net/ethernet/aquantia/atlantic/aq_ptp.c +0
-0return 0 ;@@ -1244,30 +1533,45 @@ void aq_ptp_unregister(struct aq_nic_s *aq_nic)
[ ... ]
Quoted 7 lines
void
aq_ptp_free(struct aq_nic_s *aq_nic)
{drivers/net/ethernet/aquantia/atlantic/aq_ptp.c +1
-0struct aq_ptp_s *aq_ptp = aq_nic->aq_ptp; +int i;if (!aq_ptp)return ;
[ ... ]
drivers/net/ethernet/aquantia/atlantic/aq_ptp.c void aq_ptp_unregister(struct aq_nic_s *aq_nic) · line 1576
Quoted 8 lines
drivers/net/ethernet/aquantia/atlantic/aq_ptp.c +2
-0kfree (aq_ptp->ptp_info.pin_config); + aq_ptp->ptp_info.pin_config =NULL ;netif_napi_del (&aq_ptp->napi);kfree (aq_ptp); +aq_utils_obj_clear (&aq_nic->aq_hw->flags,AQ_HW_PTP_AVAILABLE ); aq_nic->aq_ptp =NULL ; }
[Low]
A few small issues in this teardown:
- kfree(aq_ptp) is called before aq_nic->aq_ptp = NULL, leaving aq_nic->aq_ptp dangling for the duration of the aq_utils_obj_clear() call between them.
- mutex_destroy(&aq_ptp->ptp_filter_lock) is missing before kfree; CONFIG_DEBUG_MUTEXES would have caught this.
Sukhdeep Soni [C]
maintainerRE: [EXTERNAL] Re: [PATCH net-next v4 12/12] net: atlantic: add AQC113 PTP support in aq_ptp and driver core
Quoted 28 lines · Jakub Kicinski
net: atlantic: add AQC113 PTP support in
aq_ptpand driver coreThis patch extends the atlantic driver's PTP support to AQC113 (Antigua)
hardware: it adds a per-instance PTP offset table, replaces the single L3/L4 filter with an array of 4 multicast filter slots, introduces anaq_ptp_stateenum so link-change events can be distinguished from first init, and reworks vector accounting for the new PTP IRQ count.Thanks for the patch. A few questions follow inline.
drivers/net/ethernet/aquantia/atlantic/aq_nic.c +5
-1@@ -172,7 +180,11 @@ static int aq_nic_update_link_status(struct aq_nic_s *self)aq_nic_update_interrupt_moderation_settings (self);if (self->aq_ptp) { -aq_ptp_clock_init (self); +/* PTP does not work in some modes even if physical link is up */ +bool ptp_link_good = (self->aq_hw->aq_link_status.mbps >=100 && + self->aq_hw->aq_link_status.full_duplex); + +aq_ptp_clock_init (self, ptp_link_good ?AQ_PTP_LINK_UP :AQ_PTP_NO_LINK );
Quoted 6 lines
[Low]
Could the comment here be expanded to record which modes are unsupported and why? PTP is silently disabled below 100 Mbps and for any half-duplex configuration, but the predicate has no reference to a datasheet section, errata, or test result, so a future maintainer adding a new link speed cannot validate or update it.
The comment is taken from the vendor reference driver. The predicate itself (mbps >= 100 && full_duplex) is self-documenting. Without a specific datasheet section reference we would be guessing at the rationale, which risks misleading future maintainers more than the current terse comment does.
Quoted 33 lines
drivers/net/ethernet/aquantia/atlantic/aq_nic.c +0
-0aq_ptp_tm_offset_set (self, self->aq_hw->aq_link_status.mbps);aq_ptp_link_change (self);drivers/net/ethernet/aquantia/atlantic/aq_ptp.c +19
-0+static int aq_ptp_add_a2_filter (struct aq_ptp_s *aq_ptp, +struct ethtool_rx_flow_spec *fsp, +int *flt_idx) +{ +struct aq_nic_s *aq_nic = aq_ptp->aq_nic; +int err; + + err =aq_set_data_fl3l4 (fsp, + &aq_ptp->udp_filter[*flt_idx], + aq_ptp->udp_filter[*flt_idx].location, + true); +if (!err) { +netdev_dbg (aq_nic->ndev, +"PTP MC filter prepared. Loc: %x\n" , + aq_ptp->udp_filter[*flt_idx].location); + (*flt_idx)++; + } +return err; +}
Quoted 7 lines
[Low]
Canaq_set_data_fl3l4()ever return non-zero? Looking at its body it has only one return statement at the end returning 0, which means the caller's "UDPv4/UDPv6 filter prepare failed" debug paths and the flt_idx++ guard here are unreachable. Was the helper expected to validate input (e.g., badring_cookieor oversized fields) and reject it?
Fixed - aq_set_data_fl3l4() always returns 0 so the if (!err) guard and "filter prepare failed" debug paths were dead code. aq_ptp_add_a2_filter() is now void, flt_idx is incremented unconditionally, and all four call sites are simplified accordingly.
Quoted 21 lines
drivers/net/ethernet/aquantia/atlantic/aq_ptp.c +17
-0+ +static int aq_ptp_dpath_enable (struct aq_ptp_s *aq_ptp, +int enable_flags,u16 rx_queue) +{ +if (enable_flags) { +/* Clear all existing L4 filters before applying new config */ +for (i =0 ; i <PTP_UDP_FILTERS_CNT ; i++) { + aq_ptp->udp_filter[i].cmd &= + ~HW_ATL_RX_ENABLE_FLTR_L3L4 ; +if (hw_ops->hw_filter_l3l4_set) { + err = hw_ops->hw_filter_l3l4_set (aq_nic->aq_hw, + &aq_ptp->udp_filter[i]); +if (err) +netdev_dbg (aq_nic->ndev, +"Set UDP filter failed\n" ); + } + }
Quoted 8 lines
[Medium]
Can this loop hide partial failures? err is overwritten by every iteration, so if filter[0] or filter[1] fail to clear but filter[3] succeeds, err is reset to 0 by the last call and the function continues on to program new filters on top of a partially-stale slot table with no signal to the caller.[ ... ]
The continuing-on-error pattern in the clear loop is intentional and matches the vendor reference driver. For filter disable/clear operations, stopping on the first error would leave subsequent hardware slots in an unknown state. Continuing and clearing all slots - even if some fail - is preferable to leaving a partially-stale table. The netdev_dbg on each failure makes individual failures observable. The caller receives the last iteration's error, which is a known limitation shared with the reference driver.
Quoted 22 lines
drivers/net/ethernet/aquantia/atlantic/aq_ptp.c +21
-0+ }else { +/* PTP disabled, clear all UDP/L2 filters */ +for (i =0 ; i <PTP_UDP_FILTERS_CNT ; i++) { + aq_ptp->udp_filter[i].cmd &= + ~HW_ATL_RX_ENABLE_FLTR_L3L4 ; +if (hw_ops->hw_filter_l3l4_set) { + err = hw_ops->hw_filter_l3l4_set (aq_nic->aq_hw, + &aq_ptp->udp_filter[i]); +if (err) +netdev_dbg (aq_nic->ndev, +"Set UDP filter failed\n" ); + } + } + +if (!err && hw_ops->hw_filter_l2_clear) + err = hw_ops->hw_filter_l2_clear (aq_nic->aq_hw, + &aq_ptp->eth_type_filter); + } + +return err; +}
Quoted 6 lines
[Medium]
Same pattern repeats here on the disable path: an early failing slot is masked by a later successful one, so the function can return success while leaving the L3/L4 slot table partially programmed.[ ... ]
Same rationale as above - the reference driver uses the same continue-on-error pattern for the disable path. Clearing all slots even on partial failure is preferable to leaving stale entries. This is a known limitation shared with the vendor reference driver.
Quoted 78 lines
int aq_ptp_hwtstamp_config_set(struct
aq_ptp_s*aq_ptp,drivers/net/ethernet/aquantia/atlantic/aq_ptp.c +13
-26struct kernel_hwtstamp_config *config) { +unsigned int ptp_en_flags =aq_ptp_parse_rx_filters (config->rx_filter);struct aq_nic_s *aq_nic = aq_ptp->aq_nic; -const struct aq_hw_ops *hw_ops;int err =0 ; - hw_ops = aq_nic->aq_hw_ops; -if (config->tx_type ==HWTSTAMP_TX_ON || - config->rx_filter ==HWTSTAMP_FILTER_PTP_V2_EVENT ) { -aq_ptp_prepare_filters (aq_ptp); -if (hw_ops->hw_filter_l3l4_set) { - err = hw_ops->hw_filter_l3l4_set (aq_nic->aq_hw, - &aq_ptp->udp_filter); - } -if (!err && hw_ops->hw_filter_l2_set) { - err = hw_ops->hw_filter_l2_set (aq_nic->aq_hw, - &aq_ptp->eth_type_filter); - } +if (aq_ptp->hwtstamp_config.rx_filter != config->rx_filter) { +mutex_lock (&aq_ptp->ptp_filter_lock); + err =aq_ptp_dpath_enable (aq_ptp, + ptp_en_flags, + aq_ptp->ptp_rx.idx); +if (!err) + aq_ptp->hwtstamp_config = *config; +mutex_unlock (&aq_ptp->ptp_filter_lock); + } + +if (ptp_en_flags !=AQ_HW_PTP_DISABLE )aq_utils_obj_set (&aq_nic->flags,AQ_NIC_PTP_DPATH_UP ); - }else { - aq_ptp->udp_filter.cmd &= ~HW_ATL_RX_ENABLE_FLTR_L3L4 ; -if (hw_ops->hw_filter_l3l4_set) { - err = hw_ops->hw_filter_l3l4_set (aq_nic->aq_hw, - &aq_ptp->udp_filter); - } -if (!err && hw_ops->hw_filter_l2_clear) { - err = hw_ops->hw_filter_l2_clear (aq_nic->aq_hw, - &aq_ptp->eth_type_filter); - } +else aq_utils_obj_clear (&aq_nic->flags,AQ_NIC_PTP_DPATH_UP ); - }if (err)return -EREMOTEIO ; - aq_ptp->hwtstamp_config = *config; -return 0 ; }[High]
Can changes totx_typenow be silently lost? The pre-patch code unconditionally cached the new config on success. The new code only writesaq_ptp->hwtstamp_configwhenrx_filterchanged:if (aq_ptp->hwtstamp_config.rx_filter != config->rx_filter) { ... if (!err) aq_ptp->hwtstamp_config = *config; ... }A user calling SIOCSHWTSTAMP with the same
rx_filterbut a differenttx_type(for example flippingHWTSTAMP_TX_ON) gets a return of 0, but the newtx_typeis never stored, so a follow-up SIOCGHWTSTAMP returns the stale prior value.[High]
Does TX-only HW timestamping still work after this change? Previously "tx_type==HWTSTAMP_TX_ON" alone was enough to install filters and assertAQ_NIC_PTP_DPATH_UP. After the patch,AQ_NIC_PTP_DPATH_UPis driven solely byaq_ptp_parse_rx_filters(config->rx_filter), so a request with rx_filter=NONE and tx_type=ON no longer raises that flag.
Quoted 3 lines
aq_ndev_start_xmit()inaq_main.cgates its PTP TX redirection onAQ_NIC_PTP_DPATH_UP, so PTP TX frames are no longer diverted to the PTP TX ring, and TX hardware timestamping silently breaks in TX-only mode.
Both issues are already addressed:
1. tx_type silently lost: Fixed - aq_ptp->hwtstamp_config =
*config is now unconditional after the error check, saving all config changes including tx_type.
2. TX-only mode: The reference driver has the same behaviour - AQ_NIC_PTP_DPATH_UP is driven solely by ptp_en_flags from aq_ptp_parse_rx_filters(). TX-only timestamping without an RX filter is not a supported mode in this hardware design; the PTP data path requires RX filters to be active. This matches the vendor reference driver.
Quoted 8 lines
[Medium]
Can therx_filtercompare race against itself? The checkif (aq_ptp->hwtstamp_config.rx_filter != config->rx_filter)is performed without holding
ptp_filter_lock, while the same field is written under the lock further down in this function and read byaq_ptp_clock_init()on the link-change path.
The compare is performed inside ptp_filter_lock - the ock is acquired before the check, so concurrent hwtstamp_config_set calls
are serialized. The race with aq_ptp_clock_init() on the link-change path is the same pattern as the vendor reference driver which has no lock at all.
Quoted 10 lines
[Medium]
Is theAQ_NIC_PTP_DPATH_UPupdate safe outside the lock? The aq_utils_obj_set/clear calls run unconditionally based on the requestedptp_en_flags, even when:-
aq_ptp_dpath_enable()was not invoked at all becauserx_filterwas unchanged, or
- it was invoked but returned an error andhwtstamp_configwas therefore not updated.
Quoted 6 lines
In the failure case the function still asserts
AQ_NIC_PTP_DPATH_UPand then returns-EREMOTEIO, so userspace is told the operation failed while the global flag claims the datapath is up and steers transmits to a PTP ring whose hardware setup may be inconsistent.[ ... ]
Fixed - aq_utils_obj_set/clear is now moved after the if (err) return -EREMOTEIO check, so AQ_NIC_PTP_DPATH_UP is only updated when aq_ptp_dpath_enable() succeeded.
Quoted 36 lines
drivers/net/ethernet/aquantia/atlantic/aq_ptp.c +20
-4-void aq_ptp_clock_init (struct aq_nic_s *aq_nic) +void aq_ptp_clock_init (struct aq_nic_s *aq_nic,enum aq_ptp_state state) {struct aq_ptp_s *aq_ptp = aq_nic->aq_ptp; -struct timespec64 ts; -ktime_get_real_ts64 (&ts); -aq_ptp_settime (&aq_ptp->ptp_info, &ts); +if (!aq_ptp) +return ; + +if (aq_ptp->a1_ptp || state ==AQ_PTP_FIRST_INIT ) { +struct timespec64 ts; + +ktime_get_real_ts64 (&ts); +aq_ptp_settime (&aq_ptp->ptp_info, &ts); + } + +if (!aq_ptp->a1_ptp && state !=AQ_PTP_FIRST_INIT ) { +unsigned int ptp_en_flags = +aq_ptp_parse_rx_filters (state ==AQ_PTP_LINK_UP ? + aq_ptp->hwtstamp_config.rx_filter : +HWTSTAMP_FILTER_NONE ); +mutex_lock (&aq_ptp->ptp_filter_lock); +aq_ptp_dpath_enable (aq_ptp, ptp_en_flags, aq_ptp->ptp_rx.idx); +mutex_unlock (&aq_ptp->ptp_filter_lock); + } }[Medium]
Should the read ofaq_ptp->hwtstamp_config.rx_filterhappen insideptp_filter_lock? The field is sampled here without holding the lock, then the lock is acquired to callaq_ptp_dpath_enable()with the value read. The same field is mutated under the lock byaq_ptp_hwtstamp_config_set().
Quoted 7 lines
A concurrent SIOCSHWTSTAMP from userspace can race with the link-change caller (process context:
aq_nic_service_taskoraq_linkstate_threaded_isr): the link path reads the oldrx_filter, queues behind the writer for the lock, then applies the old filter set to hardware after the writer just installed the new one.The unlocked read is also a data race per the kernel memory model.
Fixed. The read of hwtstamp_config.rx_filter in aq_ptp_clock_init() is now performed inside ptp_filter_lock, so the link-change path holds the lock for the entire read-then-apply sequence. A concurrent SIOCSHWTSTAMP either completes before the link path reads the field, or waits until the link path is done - the stale-read window is closed.
Quoted 11 lines
[Medium]
Is it intentional that the return value ofaq_ptp_dpath_enable()is discarded here? The commit message says this path exists to "Re-apply RX filters on link change (hardware state lost after reset)", so a silent failure means PTP RX timestamping is silently broken across the link change.
aq_ptp_hwtstamp_config_set()captures and propagates the same return value, so the asymmetry looks like an oversight.[ ... ]
Not an oversight. The return value is checked and a netdev_warn is emitted on failure, so a filter restore failure on link change is visible in the kernel log. The function cannot propagate the error to a caller here since aq_ptp_clock_init() returns void - logging is the appropriate action for a link-change path.
Quoted 59 lines
drivers/net/ethernet/aquantia/atlantic/aq_ptp.c +20
-8-int aq_ptp_init (struct aq_nic_s *aq_nic,unsigned int idx_vec) +int aq_ptp_init (struct aq_nic_s *aq_nic,unsigned int idx_ptp_vec) { aq_ptp->aq_nic = aq_nic; aq_ptp->a1_ptp = a1_ptp; + aq_ptp->a2_ptp = a2_ptp;spin_lock_init (&aq_ptp->ptp_lock);spin_lock_init (&aq_ptp->ptp_ring_lock); +mutex_init (&aq_ptp->ptp_filter_lock); +aq_ptp_offset_init (aq_ptp, &mbox.info.ptp_offset); - aq_ptp->idx_vector = idx_vec; + aq_ptp->idx_ptp_vector = idx_ptp_vec; aq_nic->aq_ptp = aq_ptp;/* enable ptp counter */ + aq_ptp->ptp_clock_sel =ATL_TSG_CLOCK_SEL_0 ;aq_utils_obj_set (&aq_nic->aq_hw->flags,AQ_HW_PTP_AVAILABLE ); -mutex_lock (&aq_nic->fwreq_mutex); - aq_nic->aq_fw_ops->enable_ptp (aq_nic->aq_hw,1 ); -aq_ptp_clock_init (aq_nic); -mutex_unlock (&aq_nic->fwreq_mutex); +if (a1_ptp) { +mutex_lock (&aq_nic->fwreq_mutex); + aq_nic->aq_fw_ops->enable_ptp (aq_nic->aq_hw,1 ); +mutex_unlock (&aq_nic->fwreq_mutex); + } +if (a2_ptp) + aq_nic->aq_hw_ops->enable_ptp (aq_nic->aq_hw, aq_ptp->ptp_clock_sel,1 );INIT_DELAYED_WORK (&aq_ptp->poll_sync, &aq_ptp_poll_sync_work_cb); aq_ptp->eth_type_filter.location = -aq_nic_reserve_filter (aq_nic, aq_rx_filter_ethertype); - aq_ptp->udp_filter.location = +aq_nic_reserve_filter (aq_nic, aq_rx_filter_ethertype); + +for (i =0 ; i <PTP_UDP_FILTERS_CNT ; i++) { + aq_ptp->udp_filter[i].location =aq_nic_reserve_filter (aq_nic, aq_rx_filter_l3l4); + } + +aq_ptp_clock_init (aq_nic,AQ_PTP_FIRST_INIT );[Low]
Should the TSG clock be initialized with wall-clock time before it is started? On AQC113 the call sequence is:aq_nic->aq_hw_ops->enable_ptp(aq_nic->aq_hw, aq_ptp->ptp_clock_sel, 1); ... aq_ptp_clock_init(aq_nic, AQ_PTP_FIRST_INIT);
Quoted 7 lines
hw_atl2_enable_ptp(self, 0, 1)zeroes the TSG counter and starts it, whileaq_ptp_clock_init(AQ_PTP_FIRST_INIT)is the only path that callsaq_ptp_settime()to load wall-clock time. Between these two steps the TSG clock is freely incrementing from zero withAQ_HW_PTP_AVAILABLEalready set andaq_nic->aq_ptpalready published, so a concurrent reader observes an enabled-but-uninitialized clock returning a near- zero value.
TSG clock started before wall-clock time: The reference driver has the identical sequence - enable_ptp before aq_ptp_clock_init. This is an inherent initialization window that exists in all PTP hardware drivers. The near-zero timestamp window is brief and ptp4l handles clock startup gracefully.
Quoted 11 lines
[Medium]
On AQC107 (a1_ptp), only a single L3/L4 filter is ever programmed inaq_ptp_dpath_enable()(thea1_ptpbranch installs one UDPv4 filter and incrementsflt_idxonce), but this loop reservesPTP_UDP_FILTERS_CNT== 4 slots on every chip:for (i = 0; i < PTP_UDP_FILTERS_CNT; i++) { aq_ptp->udp_filter[i].location = aq_nic_reserve_filter(aq_nic, aq_rx_filter_l3l4); }
Quoted 5 lines
The L3/L4 slot pool has eight entries (
AQ_RX_LAST_LOC_FL3L4-AQ_RX_FIRST_LOC_FL3L4+ 1). Reserving four instead of one on AQC107 reduces user-visible ethtool ntuple ring- cookie capacity from seven to four. Could the reservation count be gated ona2_ptp?
AQC107 reserves 4 L3/L4 slots: The reference driver uses the same PTP_UDP_FILTERS_CNT loop for all chip variants. Gating on a2_ptp is a reasonable optimization but is out of scope for this series. We will note it for a follow-up.
Quoted 23 lines
[Low]
Is the publication order ofaq_nic->aq_ptpandAQ_HW_PTP_AVAILABLEintentional?aq_nic->aq_ptp = aq_ptp; ... aq_utils_obj_set(&aq_nic->aq_hw->flags, AQ_HW_PTP_AVAILABLE); ... INIT_DELAYED_WORK(&aq_ptp->poll_sync, ...); aq_ptp->eth_type_filter.location = ...; for (i = 0; i < PTP_UDP_FILTERS_CNT; i++) aq_ptp->udp_filter[i].location = ...;The pointer and the global flag are exposed several statements before
INIT_DELAYED_WORKand before filter slot reservations. Any future error-recovery rollback that callsaq_ptp_free()on a partially- initializedaq_ptpwill runcancel_delayed_work_sync()on an uninitialized structdelayed_work.drivers/net/ethernet/aquantia/atlantic/aq_ptp.c +0
-0return 0 ;
drivers/net/ethernet/aquantia/atlantic/aq_ptp.c void aq_ptp_unregister(struct aq_nic_s *aq_nic) · line 1533
Quoted 2 lines
drivers/net/ethernet/aquantia/atlantic/aq_ptp.c +0
-0@@ -1244,30 +1533,45 @@ void aq_ptp_unregister(struct aq_nic_s *aq_nic)
Publication order of aq_ptp and AQ_HW_PTP_AVAILABLE: The reference driver has the identical ordering. The cancel_delayed_work_sync() concern is a future hypothetical - there is no error-recovery rollback path in the current code that calls aq_ptp_free() on a partially-initialized struct. The ordering is intentional and matches the reference driver.
Quoted 22 lines
void
aq_ptp_free(struct aq_nic_s *aq_nic)
{drivers/net/ethernet/aquantia/atlantic/aq_ptp.c +3
-0struct aq_ptp_s *aq_ptp = aq_nic->aq_ptp; +int i;if (!aq_ptp)return ;kfree (aq_ptp->ptp_info.pin_config); + aq_ptp->ptp_info.pin_config =NULL ;netif_napi_del (&aq_ptp->napi);kfree (aq_ptp); +aq_utils_obj_clear (&aq_nic->aq_hw->flags,AQ_HW_PTP_AVAILABLE ); aq_nic->aq_ptp =NULL ; }[Low]
A few small issues in this teardown:
Quoted 6 lines
-
kfree(aq_ptp)is called beforeaq_nic->aq_ptp= NULL, leavingaq_nic->aq_ptpdangling for the duration of theaq_utils_obj_clear()call between them.-
mutex_destroy(&aq_ptp->ptp_filter_lock)is missing before kfree;CONFIG_DEBUG_MUTEXESwould have caught this.
Fixed both points. mutex_destroy(&aq_ptp->ptp_filter_lock) is now called before kfree, and the teardown order is corrected: AQ_HW_PTP_AVAILABLE is cleared and aq_nic->aq_ptp is set to NULL before kfree(aq_ptp), eliminating the dangling pointer window.