LCOV - code coverage report
Current view: top level - disco/net - fd_net_tile.h (source / functions) Hit Total Coverage
Test: cov.lcov Lines: 0 25 0.0 %
Date: 2026-10-22 18:10:43 Functions: 0 123 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 declares public APIs used by network tiles, net consumers, and topology builders. */
       5             : 
       6             : #include "../fd_disco_base.h"
       7             : #include "../../tango/dcache/fd_dcache.h"
       8             : #include "../../waltz/xdp/fd_xdp1.h"
       9             : #include "../../waltz/ip/fd_fib4.h"
      10             : 
      11             : struct fd_topo;
      12             : typedef struct fd_topo fd_topo_t;
      13             : struct fd_topo_tile;
      14             : 
      15             : /* Helpers for consumers of net tile RX packets */
      16             : 
      17             : struct fd_net_rx_bounds {
      18             :   ulong base;   /* base address of wksp containing dcache */
      19             :   ulong pkt_lo; /* lowest permitted pointer to packet payload */
      20             :   ulong pkt_hi; /* one past last valid byte of packet payload region */
      21             : };
      22             : 
      23             : typedef struct fd_net_rx_bounds fd_net_rx_bounds_t;
      24             : 
      25             : /* FD_NET_BOND_SLAVE_MAX is the hardcoded max number of slave devices
      26             :    per network bonding setup. */
      27             : 
      28           0 : #define FD_NET_BOND_SLAVE_MAX 16U
      29             : 
      30             : /* FD_MLX5_BATCH_SIZE is the descriptor and completion batch size. */
      31             : 
      32           0 : #define FD_MLX5_BATCH_SIZE 64U
      33             : 
      34             : #define FD_MLX5_QUEUE_DEPTH_MAX 65536U
      35             : 
      36             : FD_PROTOTYPES_BEGIN
      37             : 
      38             : /* fd_net_rx_bounds_init initializes a bounds checker for RX packets
      39             :    produced by the net tile.  dcache is a local join to a dcache that
      40             :    will carry packet payloads. */
      41             : 
      42             : FD_FN_UNUSED static void
      43             : fd_net_rx_bounds_init( fd_net_rx_bounds_t * bounds,
      44           0 :                        void *               dcache ) {
      45           0 :   bounds->base   = (ulong)fd_wksp_containing( dcache );
      46           0 :   bounds->pkt_lo = (ulong)dcache;
      47           0 :   bounds->pkt_hi = bounds->pkt_lo + fd_dcache_data_sz( dcache );
      48           0 :   if( FD_UNLIKELY( !bounds->base ) ) FD_LOG_ERR(( "Failed to find wksp containing dcache" ));
      49           0 : }
      50             : 
      51             : /* fd_net_rx_translate_frag helps net tile consumers locate packet
      52             :    paylads.  bounds is a net_rx_bounds object for the net tile that the
      53             :    frag was received from.  chunk, ctl, sz are frag_meta parameters.
      54             : 
      55             :    Returns a pointer in the local address space to the first byte of an
      56             :    incoming packet.  Terminates the application if the given {chunk,ctl}
      57             :    params would produce an out of bounds buffer. */
      58             : 
      59             : FD_FN_UNUSED static void const *
      60             : fd_net_rx_translate_frag( fd_net_rx_bounds_t const * bounds,
      61             :                           ulong                      chunk,
      62             :                           ulong                      ctl,
      63           0 :                           ulong                      sz ) {
      64           0 :   ulong p = ((ulong)bounds->base + (chunk<<FD_CHUNK_LG_SZ) + ctl);
      65           0 :   if( FD_UNLIKELY( !( (p      >= bounds->pkt_lo) &
      66           0 :                       (p + sz <= bounds->pkt_hi ) &
      67           0 :                       (sz     <= FD_NET_MTU     ) ) ) ) {
      68           0 :     FD_LOG_ERR(( "frag %p (chunk=%lu ctl=%lu sz=%lu) is not in bounds [%p:%p)",
      69           0 :                  (void *)p, chunk, ctl, sz,
      70           0 :                  (void *)bounds->pkt_lo, (void *)bounds->pkt_hi ));
      71           0 :   }
      72           0 :   return (void const *)p;
      73           0 : }
      74             : 
      75             : FD_PROTOTYPES_END
      76             : 
      77             : /* Topology APIs */
      78             : 
      79             : FD_PROTOTYPES_BEGIN
      80             : 
      81             : /* fd_net_tile_name returns the tile name used by a configured network provider. */
      82             : 
      83             : char const *
      84             : fd_net_tile_name( char const * provider );
      85             : 
      86             : /* fd_net_get_driver writes the device driver name for if_name, or the
      87             :    common member driver for a bond.  Writes "n/a" if no single driver
      88             :    is available. */
      89             : void
      90             : fd_net_get_driver( char *       driver,
      91             :                    ulong        driver_sz,
      92             :                    char const * if_name );
      93             : 
      94             : /* fd_topos_net_tiles appends the selected network provider tiles to
      95             :    the topology. */
      96             : 
      97             : /* FIXME layering violation */
      98             : struct fd_config_net;
      99             : typedef struct fd_config_net fd_config_net_t;
     100             : 
     101             : void
     102             : fd_topos_net_tiles( fd_topo_t *             topo,
     103             :                     ulong                   net_tile_cnt,
     104             :                     fd_config_net_t const * net_config,
     105             :                     ulong                   netlnk_max_routes,
     106             :                     ulong                   netlnk_max_peer_routes,
     107             :                     ulong                   netlnk_max_neighbors,
     108             :                     int                     xsk_core_dump,
     109             :                     ulong const             tile_to_cpu[ FD_TILE_MAX ] );
     110             : 
     111             : /* fd_topos_net_rx_link is like fd_topob_link, but for net->app tile
     112             :    packet RX links. */
     113             : 
     114             : void
     115             : fd_topos_net_rx_link( fd_topo_t *  topo,
     116             :                       char const * link_name,
     117             :                       ulong        net_kind_id,
     118             :                       ulong        depth );
     119             : 
     120             : /* fd_topob_tile_in_net registers a net TX link with all net tiles. */
     121             : 
     122             : void
     123             : fd_topos_tile_in_net( fd_topo_t *  topo,
     124             :                       char const * fseq_wksp,
     125             :                       char const * link_name,
     126             :                       ulong        link_kind_id,
     127             :                       int          reliable,
     128             :                       int          polled );
     129             : 
     130             : /* This should be called *after* all app<->net tile links have been
     131             :    created.  Should be called once per net tile. */
     132             : 
     133             : void
     134             : fd_topos_net_tile_finish( fd_topo_t * topo,
     135             :                           ulong       net_kind_id );
     136             : 
     137             : /* fd_topos_sock_lo adds a loopback RX only sock tile with the same
     138             :    RX consumers as net_tile. */
     139             : void
     140             : fd_topos_sock_lo( fd_topo_t *                 topo,
     141             :                   struct fd_topo_tile const * net_tile );
     142             : 
     143             : /* sock_lo_net_tile_id returns the ID of the net tile whose CPU affinity
     144             :    sock copies, or ULONG_MAX if tile is not an RX only loopback sock. */
     145             : ulong
     146             : sock_lo_net_tile_id( struct fd_topo_tile const * tile );
     147             : 
     148             : /* sock_lo_set_affinity sets the loopback RX only sock's CPU affinity. */
     149             : void
     150             : sock_lo_set_affinity( fd_topo_t * topo );
     151             : 
     152             : /* fd_net_tile_fib4_join returns a pointer to the fib4 object a remote
     153             :    net tile's address space.  net_tile is an xdp ("net") or mlx5 tile.
     154             :    Intended for diagnostics only. */
     155             : 
     156             : fd_fib4_t *
     157             : fd_net_tile_fib4_join( fd_fib4_t *                 out,
     158             :                        fd_topo_t const *           topo,
     159             :                        struct fd_topo_tile const * net_tile,
     160             :                        int                         main_table );
     161             : 
     162             : fd_fib4_t *
     163             : fd_xdp_tile_fib4_join( fd_fib4_t *                 out,
     164             :                        fd_topo_t const *           topo,
     165             :                        struct fd_topo_tile const * net_tile,
     166             :                        int                         main_table );
     167             : 
     168             : fd_fib4_t *
     169             : fd_mlx5_tile_fib4_join( fd_fib4_t *                 out,
     170             :                         fd_topo_t const *           topo,
     171             :                         struct fd_topo_tile const * net_tile,
     172             :                         int                         main_table );
     173             : 
     174             : #if defined(__linux__)
     175             : 
     176             : #define FD_MLX5_TILE_MAX (8UL)
     177             : 
     178             : /* fd_mlx5_fds identifies the shared uverbs descriptors inherited by mlx5 tiles
     179             :    from the supervisor.  rx_comp_channel_fd[ i ] is inherited only by mlx5:i,
     180             :    and is present only in efficient mode (rx_comp_channel_fd_cnt is 0 otherwise). */
     181             : struct fd_mlx5_fds {
     182             :   int   cmd_fd;
     183             :   int   async_fd;
     184             :   ulong rx_comp_channel_fd_cnt;
     185             :   int   rx_comp_channel_fd[ FD_MLX5_TILE_MAX ];
     186             : };
     187             : typedef struct fd_mlx5_fds fd_mlx5_fds_t;
     188             : 
     189             : /* fd_topo_install_mlx5 creates the shared mlx5 context, protection domain,
     190             :    receive indirection table, RSS QP, flow rules, and each tile's queues before
     191             :    the tiles are launched. */
     192             : void
     193             : fd_topo_install_mlx5( fd_topo_t *     topo,
     194             :                       fd_mlx5_fds_t * fds );
     195             : 
     196             : /* fd_topo_install_xdp installs XDP programs to all network devices used
     197             :    by the topology.  This creates a number of file descriptors which
     198             :    will be returned into the fds array.  On entry *fds_cnt is the array
     199             :    size of fds.  On exit, *fds_cnt is the number of fd array entries
     200             :    used.  Closing these fds will undo XDP program installation.
     201             :    bind_addr is an optional IPv4 address to used for filtering by dst
     202             :    IP.  If dry_run is set, does not actually install XDP config, but
     203             :    just returns file descriptors where installs would have occurred. */
     204             : 
     205             : void
     206             : fd_topo_install_xdp( fd_topo_t const * topo,
     207             :                      fd_xdp_fds_t *    fds,
     208             :                      uint *            fds_cnt,
     209             :                      uint              bind_addr,
     210             :                      int               dry_run );
     211             : 
     212             : /* FD_TOPO_XDP_FDS_MAX is the max length of the fd_xdp_fds_t array for
     213             :    an arbitrary supported topology.  (Number of bond slave devices plus
     214             :    loopback) */
     215             : 
     216           0 : #define FD_TOPO_XDP_FDS_MAX (FD_NET_BOND_SLAVE_MAX+1)
     217             : 
     218             : /* fd_topo_install_xdp_simple is a convenience wrapper of the above. */
     219             : 
     220             : FD_FN_UNUSED static void
     221             : fd_topo_install_xdp_simple( fd_topo_t const * topo,
     222           0 :                             uint              bind_addr ) {
     223           0 :   fd_xdp_fds_t fds[ FD_TOPO_XDP_FDS_MAX ];
     224           0 :   uint         fds_cnt = FD_TOPO_XDP_FDS_MAX;
     225           0 :   fd_topo_install_xdp( topo, fds, &fds_cnt, bind_addr, 0 );
     226           0 : }
     227             : 
     228             : #endif /* defined(__linux__) */
     229             : 
     230             : FD_PROTOTYPES_END
     231             : 
     232             : #endif /* HEADER_fd_src_disco_net_fd_net_tile_h */

Generated by: LCOV version 1.14