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