LCOV - code coverage report
Current view: top level - disco/net - fd_net_tile.h (source / functions) Hit Total Coverage
Test: cov.lcov Lines: 0 24 0.0 %
Date: 2026-01-23 05:02:40 Functions: 0 75 0.0 %

          Line data    Source code
       1             : #ifndef HEADER_fd_src_disco_net_fd_net_tile_h
       2             : #define HEADER_fd_src_disco_net_fd_net_tile_h
       3             : 
       4             : /* fd_net_tile.h contains APIs for providing XDP networking to a
       5             :    Firedancer topology using the 'net' tile. */
       6             : 
       7             : #include "../fd_disco_base.h"
       8             : #include "../../tango/dcache/fd_dcache.h"
       9             : #include "../../waltz/xdp/fd_xdp1.h"
      10             : 
      11             : struct fd_topo;
      12             : typedef struct fd_topo fd_topo_t;
      13             : 
      14             : /* Helpers for consumers of net tile RX packets */
      15             : 
      16             : struct fd_net_rx_bounds {
      17             :   ulong base;       /* base address of wksp containing dcache */
      18             :   ulong pkt_lo;     /* lowest permitted pointer to packet payload */
      19             :   ulong pkt_wmark;  /* highest " */
      20             : };
      21             : 
      22             : typedef struct fd_net_rx_bounds fd_net_rx_bounds_t;
      23             : 
      24             : /* FD_NET_BOND_SLAVE_MAX is the hardcoded max number of slave devices
      25             :    per network bonding setup. */
      26             : 
      27           0 : #define FD_NET_BOND_SLAVE_MAX 16U
      28             : 
      29             : FD_PROTOTYPES_BEGIN
      30             : 
      31             : /* fd_net_rx_bounds_init initializes a bounds checker for RX packets
      32             :    produced by the net tile.  dcache is a local join to a dcache that
      33             :    will carry packet payloads. */
      34             : 
      35             : FD_FN_UNUSED static void
      36             : fd_net_rx_bounds_init( fd_net_rx_bounds_t * bounds,
      37           0 :                        void *               dcache ) {
      38           0 :   bounds->base      = (ulong)fd_wksp_containing( dcache );
      39           0 :   bounds->pkt_lo    = (ulong)dcache;
      40           0 :   bounds->pkt_wmark = bounds->pkt_lo + fd_dcache_data_sz( dcache ) - FD_NET_MTU;
      41           0 :   if( FD_UNLIKELY( !bounds->base ) ) FD_LOG_ERR(( "Failed to find wksp containing dcache" ));
      42           0 : }
      43             : 
      44             : /* fd_net_rx_translate_frag helps net tile consumers locate packet
      45             :    paylads.  bounds is a net_rx_bounds object for the net tile that the
      46             :    frag was received from.  chunk, ctl, sz are frag_meta parameters.
      47             : 
      48             :    Returns a pointer in the local address space to the first byte of an
      49             :    incoming packet.  Terminates the application if the given {chunk,ctl}
      50             :    params would produce an out of bounds buffer. */
      51             : 
      52             : FD_FN_UNUSED static void const *
      53             : fd_net_rx_translate_frag( fd_net_rx_bounds_t const * bounds,
      54             :                           ulong                      chunk,
      55             :                           ulong                      ctl,
      56           0 :                           ulong                      sz ) {
      57           0 :   ulong p = ((ulong)bounds->base + (chunk<<FD_CHUNK_LG_SZ) + ctl);
      58           0 :   if( FD_UNLIKELY( !( (p  >= bounds->pkt_lo   ) &
      59           0 :                       (p  <= bounds->pkt_wmark) &
      60           0 :                       (sz <= FD_NET_MTU       ) ) ) ) {
      61           0 :     FD_LOG_ERR(( "frag %p (chunk=%lu ctl=%lu sz=%lu) is not in bounds [%p:%p]",
      62           0 :                  (void *)p, chunk, ctl, sz,
      63           0 :                  (void *)bounds->pkt_lo, (void *)bounds->pkt_wmark ));
      64           0 :   }
      65           0 :   return (void const *)p;
      66           0 : }
      67             : 
      68             : FD_PROTOTYPES_END
      69             : 
      70             : /* Topology APIs */
      71             : 
      72             : FD_PROTOTYPES_BEGIN
      73             : 
      74             : /* fd_topos_net_tiles appends the net and netlnk tiles to the
      75             :    topology.  These tiles provide fast XDP networking. */
      76             : 
      77             : /* FIXME layering violation */
      78             : struct fd_config_net;
      79             : typedef struct fd_config_net fd_config_net_t;
      80             : 
      81             : void
      82             : fd_topos_net_tiles( fd_topo_t *             topo,
      83             :                     ulong                   net_tile_cnt,
      84             :                     fd_config_net_t const * net_config,
      85             :                     ulong                   netlnk_max_routes,
      86             :                     ulong                   netlnk_max_peer_routes,
      87             :                     ulong                   netlnk_max_neighbors,
      88             :                     int                     xsk_core_dump,
      89             :                     ulong const             tile_to_cpu[ FD_TILE_MAX ] );
      90             : 
      91             : /* fd_topos_net_rx_link is like fd_topob_link, but for net->app tile
      92             :    packet RX links. */
      93             : 
      94             : void
      95             : fd_topos_net_rx_link( fd_topo_t *  topo,
      96             :                       char const * link_name,
      97             :                       ulong        net_kind_id,
      98             :                       ulong        depth );
      99             : 
     100             : /* fd_topob_tile_in_net registers a net TX link with all net tiles. */
     101             : 
     102             : void
     103             : fd_topos_tile_in_net( fd_topo_t *  topo,
     104             :                       char const * fseq_wksp,
     105             :                       char const * link_name,
     106             :                       ulong        link_kind_id,
     107             :                       int          reliable,
     108             :                       int          polled );
     109             : 
     110             : /* This should be called *after* all app<->net tile links have been
     111             :    created.  Should be called once per net tile. */
     112             : 
     113             : void
     114             : fd_topos_net_tile_finish( fd_topo_t * topo,
     115             :                           ulong       net_kind_id );
     116             : 
     117             : #if defined(__linux__)
     118             : 
     119             : /* fd_topo_install_xdp installs XDP programs to all network devices used
     120             :    by the topology.  This creates a number of file descriptors which
     121             :    will be returned into the fds array.  On entry *fds_cnt is the array
     122             :    size of fds.  On exit, *fds_cnt is the number of fd array entries
     123             :    used.  Closing these fds will undo XDP program installation.
     124             :    bind_addr is an optional IPv4 address to used for filtering by dst
     125             :    IP.  If dry_run is set, does not actually install XDP config, but
     126             :    just returns file descriptors where installs would have occurred. */
     127             : 
     128             : void
     129             : fd_topo_install_xdp( fd_topo_t const * topo,
     130             :                      fd_xdp_fds_t *    fds,
     131             :                      uint *            fds_cnt,
     132             :                      uint              bind_addr,
     133             :                      int               dry_run );
     134             : 
     135             : /* FD_TOPO_XDP_FDS_MAX is the max length of the fd_xdp_fds_t array for
     136             :    an arbitrary supported topology.  (Number of bond slave devices plus
     137             :    loopback) */
     138             : 
     139           0 : #define FD_TOPO_XDP_FDS_MAX (FD_NET_BOND_SLAVE_MAX+1)
     140             : 
     141             : /* fd_topo_install_xdp_simple is a convenience wrapper of the above. */
     142             : 
     143             : FD_FN_UNUSED static void
     144             : fd_topo_install_xdp_simple( fd_topo_t const * topo,
     145           0 :                             uint              bind_addr ) {
     146           0 :   fd_xdp_fds_t fds[ FD_TOPO_XDP_FDS_MAX ];
     147           0 :   uint         fds_cnt = FD_TOPO_XDP_FDS_MAX;
     148           0 :   fd_topo_install_xdp( topo, fds, &fds_cnt, bind_addr, 0 );
     149           0 : }
     150             : 
     151             : #endif /* defined(__linux__) */
     152             : 
     153             : FD_PROTOTYPES_END
     154             : 
     155             : #endif /* HEADER_fd_src_disco_net_fd_net_tile_h */

Generated by: LCOV version 1.14