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