Commit graph

130 commits

Author SHA1 Message Date
Tomaz Zaman
ed6054cd77 CDX: multicast cleanup, dist FQR overflow guard, race fix
- Bump CDX_MAX_DIST_FQRS from 64 to 512 and add overflow guard to
  prevent silent array out-of-bounds in cdx_create_port_fqs

- Fix atomic_fetchadd_64 race in dist_fq_rx_callback: use return
  value instead of re-reading the (now stale) global counter

- Add mc_free_group to properly free multicast group heap allocations
  during module unload (pCtEntry, pRtEntry, group struct)

- Walk and free mc4/mc6 group lists in mc4_exit/mc6_exit to prevent
  memory leaks on module unload

- Guard against phyaddr==0 in cdx_add_mcast_table_entry when no
  valid member entry is found

- Add partial-update error logging in cdx_update_mcast_group

- Document locking model for multicast command serialization
  (ctrl->mutex serializes all dispatch, per-bucket spinlocks are
  for FMan packet path only)

- Document single-threaded safety of dpa_devlist walk in
  cdx_ioc_set_dpa_params
2026-03-13 20:16:52 +01:00
Tomaz Zaman
ce956d82b2 CMM: safety and correctness fixes from code review
- Fix P0 bug: remove O_NONBLOCK from control client sockets (breaks
  read_exact/write_exact which loop without EAGAIN handling), add
  SO_RCVTIMEO/SO_SNDTIMEO to bound misbehaving clients

- Add SO_RCVTIMEO on route query socket to prevent cmm_rtsock_get()
  from blocking the event loop indefinitely on missing kernel reply

- Add fci_handle NULL guards to ct4/ct6 register/deregister functions,
  consistent with existing guards in fe_reset and route_register

- Enforce deny rules in push path (handle_pf_ready): refactor
  cmm_deny_check into cmm_deny_check_tuple taking individual fields,
  callable from both poll and push paths

- Add bounds checking to cmm_rtsock_parse_addrs (takes msglen param)
  to prevent out-of-bounds reads on malformed routing messages

- Remove dead code cmm_route_send_fpp (trivial wrapper, tunnel code
  now calls cmm_fe_route_register directly)

- Add cross-reference comments between cmm_offload_eligible and
  pfn_event_eligible to prevent drift

- Enhanced debug logging for reply neighbor resolution failures
2026-03-13 20:16:30 +01:00
Tomaz Zaman
3118b3c75f CMM: use fe_reset for offload state reset, filter address events
Fix two bugs in cmm_reset_offload_state():

1. Per-connection CDX deregister fails when reply tuples have diverged
   (e.g. after NAT address change), leaving stale CDX entries that
   intercept traffic incorrectly. Replace with cmm_fe_reset() which
   does a guaranteed bulk wipe of all CDX conntracks and routes.

2. Reset fired on every RTM_NEWADDR/RTM_DELADDR including DHCP
   renewals with the same IP, link-local IPv6, and loopback — causing
   unnecessary offload interruptions. Filter address events: only
   reset when an address is genuinely new (itf_add_addr returns
   duplicate status), skip loopback and link-local IPv6.
2026-03-13 17:33:20 +01:00
Tomaz Zaman
5cc32242f0 CMM: full offload state reset on interface reassignment
When OPNsense reassigns the WAN interface (e.g. switching between
dtsec3 DHCP and pppoe0), cached routes become stale and RTM_GET
returns ESRCH. Rather than surgical per-route invalidation which
breaks in edge cases, flush all offload state on RTM_NEWADDR and
RTM_DELADDR: deregister all connections from CDX, flush route cache,
mark all neighbors stale. Connections stay in the hash table and
re-offload cleanly on the next poll cycle.
2026-03-13 15:55:21 +01:00
Tomaz Zaman
4408aa0ab8 PPPoE termination offload: session detection, flow offload, soft parser fix
CMM: detect PPPoE sessions via netgraph (NGM_PPPOE_GET_SESSION_INFO),
register with CDX (FPP_CMD_PPPOE_ENTRY), resolve point-to-point neighbor
MAC from session info instead of ARP.  Prevent duplicate CMM instances
via pidfile(3) locking.

CDX: fix egress PPPoE flags in dpa_get_tx_info_by_itf() — set
add_pppoe_hdr/ac_mac_addr instead of pppoe_present.  Add
pppoe_stats_offset for IPsec path.  Remove CDX_TODO_PPPOE ifdefs
in control_pppoe.c (timer always marks active, PF handles timeouts).

Soft parser (cdx_sp.xml): PPPoE data frames now return to HXS instead
of short-circuiting to relay CC table.  HXS chains PPPoE→IPv4→TCP/UDP
naturally, enabling PCD KeyGen to build 5-tuple hash keys for IPv4 CC
table matching.  LCP control packets still go directly to host.

Verified: 1.6 Gbps through PPPoE with hardware offload (all cores idle,
zero FMan drops).  Bottleneck is test infrastructure PPPoE server, not GDK.
2026-03-13 15:55:21 +01:00
Tomaz Zaman
162890791d PPPoE termination offload: session detection, flow offload, soft parser fix
CMM: detect PPPoE sessions via netgraph (NGM_PPPOE_GET_SESSION_INFO),
register with CDX (FPP_CMD_PPPOE_ENTRY), resolve point-to-point neighbor
MAC from session info instead of ARP.  Prevent duplicate CMM instances
via pidfile(3) locking.

CDX: fix egress PPPoE flags in dpa_get_tx_info_by_itf() — set
add_pppoe_hdr/ac_mac_addr instead of pppoe_present.  Add
pppoe_stats_offset for IPsec path.  Remove CDX_TODO_PPPOE ifdefs
in control_pppoe.c (timer always marks active, PF handles timeouts).

Soft parser (cdx_sp.xml): PPPoE data frames now return to HXS instead
of short-circuiting to relay CC table.  HXS chains PPPoE→IPv4→TCP/UDP
naturally, enabling PCD KeyGen to build 5-tuple hash keys for IPv4 CC
table matching.  LCP control packets still go directly to host.

Verified: 1.6 Gbps through PPPoE with hardware offload (all cores idle,
zero FMan drops).  Bottleneck is test infrastructure PPPoE server, not GDK.
2026-03-13 11:34:47 +01:00
Tomaz Zaman
c08fcc125b vendor/cdx: remove 25 unused files replaced by FreeBSD ports
Delete 23 .c files that have FreeBSD-specific replacements in cdx/
(e.g. cdx_main.c → cdx_main_freebsd.c) or are Linux-only (procfs.c,
dpa_test.c, vsp_cfg.c). Delete 2 .h files (procfs.h, cdx_ceetm_gdef.h)
only included by the removed sources. Build verified clean.
2026-03-12 13:03:37 +01:00
Tomaz Zaman
82bb31fb7a CDX/CMM: LAGG loadbalance failover with multi-port hash entries
Three problems solved for laggproto loadbalance with CDX flow offload:

1. Multi-port hash entries: CDX uses (portid + 5-tuple) as the FMan
   enhanced hash table key. With loadbalance LAGG, the remote host's
   bond can send traffic on either member port. Previously only one
   port's portid was in the hash key — packets on the other port missed
   CDX and fell to PF, causing split-path TCP corruption.

   Now install sibling hash entries for all LAGG member ports. Each
   sibling has identical forwarding actions but a different portid in
   byte 0 of the key. Statistics are aggregated across siblings.

2. Member-set-change detection: CMM now tracks all LAGG member ports
   (not just the active parent). When a port is replugged, CMM detects
   the member set change, deregisters/re-registers the LAGG, invalidates
   routes, and re-offloads flows with hash entries covering all ports.

3. PF sloppy state: When CDX offloads a flow, PF's TCP sequence tracking
   goes stale. During failover, returning packets were dropped by PF as
   "BAD state" (out-of-window sequence), causing ~20s TCP recovery due
   to exponential retransmit backoff. Now pf_notify marks all states as
   PFSTATE_SLOPPY at creation, so PF uses lenient sequence validation.
2026-03-11 01:19:44 +01:00
Tomaz Zaman
eebe159e1c CDX/CMM: add LAGG (link aggregation) support for hardware flow offload
LAGG is transparent to header manipulation — no CDX microcode opcodes
needed, only route/port resolution through the interface hierarchy.

CDX kernel module:
- New control_lagg.c/h: LAGG command handler (register/deregister/reset)
- cdx_devman_freebsd.c: dpa_add_lagg_if() registers LAGG in DPA iface
  list, all 6 hierarchy walkers updated with LAGG skip-through clauses
  (devman_find_eth_parent, dpa_get_tx_info_by_itf,
  dpa_get_iface_stats_entries, dpa_get_num_vlan_iface_stats_entries,
  dpa_check_for_logical_iface_types, dpa_get_l2l3_info)
- cdx_cmdhandler_freebsd.c: FC_LAGG dispatch to EVENT_LAGG
- layer2.h: IF_TYPE_LAGG (1<<9), tracked in if_flags only (U8 overflow)
- portdefs.h: lagg_iface_info in dpa_iface_info union

CMM userspace:
- New cmm_lagg.c/h: LAGG detection via SIOCGLAGG ioctl, FPP registration
- cmm_itf.c: itf_detect_lagg() in both init and RTM_IFINFO paths
- cmm.c: LAGG init before VLAN (VLAN parent may be LAGG)
- fpp.h: FPP_CMD_LAGG_ENTRY/RESET commands and fpp_lagg_cmd_t struct

Tested: flows through lagg0 (loadbalance, dtsec1+dtsec2) offload
successfully with 0% CPU utilization.
2026-03-10 00:28:03 +01:00
Tomaz Zaman
85d5debe29 CDX: fix VLAN hardware flow offload (3 bugs)
1. control_vlan.c: wrap Linux dev_get_by_name()/dev_put() in
   #ifndef NCSW_FREEBSD — the FreeBSD stub always returns NULL,
   preventing VLAN interfaces from registering in gOnif_DB[].

2. cdx_devman_freebsd.c: add htons() to vlan_id storage in
   dpa_add_vlan_if() to match Linux double-swap convention — without
   this, the VLAN ID was stored in network order instead of host order,
   causing the microcode to insert/validate the wrong VID.

3. cdx_devman_freebsd.c: add missing dpa_check_for_logical_iface_types()
   call in dpa_get_tx_info_by_itf() for ingress interface discovery —
   without this, ingress VLAN stripping was never configured, so the
   STRIP_L2_HDR opcode left the 4-byte VLAN tag in the frame, corrupting
   the IP packet. Also remove incorrect vlan_present=1 from the egress
   walk (Linux only sets this flag from the ingress check).
2026-03-09 22:31:23 +01:00
Tomaz Zaman
ef5b163670 WiFi UAP: WPA3-SAE PMF fix, rc.d service, CMM loopback fix
- Fix WPA3-SAE authentication failure by injecting custom RSN IE with
  PMF capability bits (MFPC/MFPR) via MLAN_OID_MISC_CUSTOM_IE. Without
  PMF advertised in beacons, WPA3 clients reject the connection.
- Use PROTOCOL_WPA2 + KEY_MGMT_SAE instead of PROTOCOL_WPA3_SAE so
  mlan TLV builder emits AKMP/cipher/passphrase TLVs correctly.
- Add SAE password field population for WPA3 and WPA2+WPA3 modes.
- Add UAP sysctls: country code, beacon interval, DTIM period.
- Add mwifiex_uap rc.d service script for rc.conf-based AP config.
- Load dpaa_wifi module before mwifiex in early syshook script.
- Fix CMM route offload logging thousands of errors for loopback input
  device — skip lo0 in cmm_fe_route_register() since CDX can't use it.
- Remove uninformative debug printk from CDX control_wifi.c.
2026-03-06 21:59:21 +01:00
Tomaz Zaman
96a1d5ade8 WiFi offload: per-VAP FQs, SG inject, backpressure, debug control
dpaa_wifi: Add per-VAP distribution FQs (64 per VAP, hash across CPUs)
for CDX→WiFi download, with fallback to OH default FQ. Add SG inject
path for oversized frames. Add TX backpressure via BMan pool threshold.
Add sysctl tree (dev.dpaa_wifi.*) for runtime stats and tuning. Switch
RX paths to copy-then-free model to prevent dtsec BMan pool drain.
Add enqueue retry loop and per-VAP/global counters.

mwifiex: Route debug prints through log() instead of printf() so they
go to syslog, not console. MFATAL still goes to console, MERROR to
syslog, everything else suppressed unless dev.mwifiex.0.debug=1.
Add TX backpressure (IFF_DRV_OACTIVE) with configurable watermark.
Fix UAP 5 GHz rate table, HT capabilities, and MLAN_STATUS_PENDING
reschedule in main_task.

cdx: Use per-VAP distribution FQs for WiFi TX routing with OH fallback.
Add dist fallback callback for dtsec-BPID frames on OH port dist FQs.

pf_notify: Keep PF state alive while CDX offloads the flow by updating
expire on counter sync, preventing premature state purge.
2026-03-06 12:24:24 +01:00
Tomaz Zaman
1bc132cc48 CDX: PLCR/KG miss fixup, per-CPU dist FQs, clean kldunload
- Miss action fixup: Ethernet/PPPoE tables → PLCR policer (rate-limits
  exception traffic), all other tables → KG scheme with CC_EN (re-enters
  CC tree). Replaces previous ENQ_FRAME-to-default-FQID approach.

- Distribution FQRs now use per-CPU SW portal channels instead of pool
  channel, preventing TCP reordering on miss path.

- BMan buffer refill: cdx_dist_fq_rx_callback now calls
  dtsec_rm_pool_rx_refill_bpid() and frees buffers via
  dtsec_rm_buf_free_external() (per-port UMA zone) instead of direct
  bman_put_buffer().

- Clean kldunload: cdx_destroy_port_fqs() retires all dist FQRs,
  qman_portal_quiesce() drains in-flight portal polls.
  FM_PORT_DeletePCD() called on all dtsec RX + OH ports before hash
  table deletion, preventing FMan PCD exceptions after unload.
2026-03-05 23:49:54 +01:00
Tomaz Zaman
2339ecc091 Fix CAAM detach stale children, update CEETM and kernel patches 2026-03-03 21:05:53 +01:00
Tomaz Zaman
0ac9dbe362 Fix CAAM JR double enumeration, stale NOP interrupt, add make image target 2026-03-03 17:32:47 +01:00
Tomaz Zaman
1e9d5523f6 Shutdown working correctly 2026-03-03 14:41:50 +01:00
Tomaz Zaman
9fb890cc1d Fix CAAM JR RNG polling failure caused by ISR/NOP-test race on sc_out_ridx 2026-03-03 11:46:55 +01:00
Tomaz Zaman
0e2ab6a33b Network interface mapping clarification 2026-03-03 02:25:08 +01:00
Tomaz Zaman
55441f0eca Add hwmon dashboard widget and fix EMC2302 fan stall detection 2026-03-03 02:02:49 +01:00
Tomaz Zaman
f535564d2d Add TI TMP431 dual-channel temperature sensor driver 2026-03-03 01:42:55 +01:00
Tomaz Zaman
28d6e831d2 Updated documentation for corectness and clarity, removed dead build code 2026-03-02 23:13:00 +01:00
Tomaz Zaman
d0764a8f5c Force clean build for package target, add CDX route diagnostics
Make 'package' depend on 'clean' so stale .ko files from incremental
builds can't end up in the image. Iterative development targets (all,
build-cdx, etc.) still use incremental builds.

Add diagnostic prints to CDX route registration and classification
table insert paths to show interface names and route IDs when lookups
fail, making NULL underlying_input_itf errors actionable.
2026-03-02 14:37:31 +01:00
Tomaz Zaman
7dcc939229 Split monolithic kernel patch into 6 format-patches
Replace the single OPNsense-26.1-aarch64-GATEWAY.patch with per-subsystem
format-patches in patches/. These are generated from the opnsense-src
mono-gateway branch via git format-patch and can be applied with git am.

Also fix package build: add pcf2131.ko and caam.ko to plist, clean stale
packages before creating new ones, and update README with build instructions
and the git am workflow.
2026-03-02 13:57:35 +01:00
Tomaz Zaman
f88576c880 Move pcf2131 and caam to out-of-tree kernel modules 2026-03-02 13:57:35 +01:00
Tomaz Zaman
69b7fea989 Better versioning 2026-02-27 14:20:28 +01:00
Tomaz Zaman
de9d9bf700 Package instead of copy 2026-02-27 14:09:48 +01:00
Tomaz Zaman
6dae3f78f7 Add mono-gateway FreeBSD package build target 2026-02-27 13:19:20 +01:00
Tomaz Zaman
811da14fb4 Sync CDX hardware flow counters into PF state table via pfnotify ioctl 2026-02-27 01:38:14 +01:00
Tomaz Zaman
dbcfb29e00 BMan RX: switch to consumption model (free buffers after use, refill from UMA) 2026-02-25 23:35:42 +01:00
Tomaz Zaman
2ba3a06032 ncsw: replace fixed MallocSmart pool with Linux-style malloc wrapper 2026-02-25 21:59:54 +01:00
Tomaz Zaman
96db298a82 growfs early script bugfix 2026-02-25 19:57:54 +01:00
Tomaz Zaman
2b3e5563d7 Proper repositories and commits 2026-02-25 15:21:07 +01:00
Tomaz Zaman
5514d65ac5 Hello world. 2026-02-25 15:13:46 +01:00