2 * Copyright (c) 2016-2017 Intel Corporation.
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at:
7 * http://www.apache.org/licenses/LICENSE-2.0
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
26 * TCP stream creation parameters.
28 struct tle_tcp_stream_addr {
29 struct sockaddr_storage local; /**< stream local address. */
30 struct sockaddr_storage remote; /**< stream remote address. */
33 #define TLE_TCP_DEFAULT_RETRIES 3
35 struct tle_tcp_stream_cfg {
36 uint8_t nb_retries; /**< max number of retransmission attempts. */
38 /* _cb and _ev are mutually exclusive */
39 struct tle_event *err_ev; /**< error event to use. */
40 struct tle_stream_cb err_cb; /**< error callback to use. */
42 struct tle_event *recv_ev; /**< recv event to use. */
43 struct tle_stream_cb recv_cb; /**< recv callback to use. */
45 struct tle_event *send_ev; /**< send event to use. */
46 struct tle_stream_cb send_cb; /**< send callback to use. */
49 struct tle_tcp_stream_param {
50 struct tle_tcp_stream_addr addr;
51 struct tle_tcp_stream_cfg cfg;
66 * SYN time option values.
68 struct tle_tcp_syn_opts {
71 union tle_tcp_tsopt ts;
74 struct tle_tcp_conn_info {
78 struct tle_tcp_syn_opts so;
82 * create a new stream within given TCP context.
84 * TCP context to create new stream within.
86 * Parameters used to create and initialise the new stream.
88 * Pointer to TCP stream structure that can be used in future TCP API calls,
89 * or NULL on error, with error code set in rte_errno.
90 * Possible rte_errno errors include:
91 * - EINVAL - invalid parameter passed to function
92 * - ENOFILE - max limit of open streams reached for that context
95 tle_tcp_stream_open(struct tle_ctx *ctx,
96 const struct tle_tcp_stream_param *prm);
99 * close an open stream.
100 * if the stream is in connected state, then:
101 * - connection termination would be performed.
102 * - if stream contains unsent data, then actual close will be postponed
103 * till either remaining data will be TX-ed, or timeout will expire.
104 * All packets that belong to that stream and remain in the device
105 * TX queue will be kept for father transmission.
107 * Pointer to the stream to close.
109 * zero on successful completion.
110 * - -EINVAL - invalid parameter passed to function
111 * - -EDEADLK - close was already invoked on that stream
113 int tle_tcp_stream_close(struct tle_stream *s);
116 * close a group of open streams.
117 * if the stream is in connected state, then:
118 * - connection termination would be performed.
119 * - if stream contains unsent data, then actual close will be postponed
120 * till either remaining data will be TX-ed, or timeout will expire.
121 * All packets that belong to that stream and remain in the device
122 * TX queue will be kept for father transmission.
124 * An array of pointers to streams that have to be closed.
126 * Number of elements in the *ts* array.
128 * number of successfully closed streams.
129 * In case of error, error code set in rte_errno.
130 * Possible rte_errno errors include:
131 * - EINVAL - invalid parameter passed to function
132 * - EDEADLK - close was already invoked on that stream
135 tle_tcp_stream_close_bulk(struct tle_stream *ts[], uint32_t num);
138 * get open stream local and remote addresses.
140 * Pointer to the stream.
142 * zero on successful completion.
143 * - EINVAL - invalid parameter passed to function
146 tle_tcp_stream_get_addr(const struct tle_stream *s,
147 struct tle_tcp_stream_addr *addr);
150 * Get current TCP maximum segment size
152 * Stream to retrieve MSS information from.
154 * Maximum segment size in bytes, if successful.
155 * Negative on failure.
157 int tle_tcp_stream_get_mss(const struct tle_stream *ts);
160 tle_tcp_stream_establish(struct tle_ctx *ctx,
161 const struct tle_tcp_stream_param *prm,
162 const struct tle_tcp_conn_info *ci);
165 * Client mode connect API.
169 * Attempt to establish connection with the destination TCP endpoint.
170 * Stream write event (or callback) will fire, if the connection will be
171 * established successfully.
172 * Note that stream in listen state or stream with already established
173 * connection, can't be subject of connect() call.
174 * In case of unsuccessful attempt, error event (or callback) will be
177 * Pointer to the stream.
179 * Address of the destination endpoint.
181 * zero on successful completion.
182 * - -EINVAL - invalid parameter passed to function
184 int tle_tcp_stream_connect(struct tle_stream *s, const struct sockaddr *addr);
187 * Server mode connect API.
188 * Basic scheme for server mode API usage:
190 * <stream open happens here>
191 * tle_tcp_stream_listen(stream_to_listen);
192 * <wait for read event/callback on that stream>
193 * n = tle_tcp_accept(stream_to_listen, accepted_streams,
194 * sizeof(accepted_streams));
195 * for (i = 0, i != n; i++) {
196 * //prepare tle_tcp_stream_cfg for newly accepted streams
199 * k = tle_tcp_stream_update_cfg(rs, prm, n);
207 * Set stream into the listen state (passive opener), i.e. make stream ready
208 * to accept new connections.
209 * Stream read event (or callback) will be activated as new SYN requests
211 * Note that stream with already established (or establishing) connection
212 * can't be subject of listen() call.
214 * Pointer to the stream.
216 * zero on successful completion.
217 * - -EINVAL - invalid parameter passed to function
219 int tle_tcp_stream_listen(struct tle_stream *s);
222 * return up to *num* streams from the queue of pending connections
223 * for given TCP endpoint.
225 * TCP stream in listen state.
227 * An array of pointers to the newily accepted streams.
228 * Each such new stream represents a new connection to the given TCP endpoint.
229 * Newly accepted stream should be in connected state and ready to use
230 * by other FE API routines (send/recv/close/etc.).
232 * Number of elements in the *rs* array.
234 * number of entries filled inside *rs* array.
236 uint16_t tle_tcp_stream_accept(struct tle_stream *s, struct tle_stream *rs[],
240 * updates configuration (associated events, callbacks, stream parameters)
241 * for the given streams.
243 * An array of pointers to the streams to update.
245 * An array of parameters to update for the given streams.
247 * Number of elements in the *ts* and *prm* arrays.
249 * number of streams successfully updated.
250 * In case of error, error code set in rte_errno.
251 * Possible rte_errno errors include:
252 * - EINVAL - invalid parameter passed to function
254 uint32_t tle_tcp_stream_update_cfg(struct tle_stream *ts[],
255 struct tle_tcp_stream_cfg prm[], uint32_t num);
258 * Accept connection requests for the given stream.
259 * Note that the stream has to be in listen state.
260 * For each new connection a new stream will be open.
264 * An array of *tle_tcp_accept_param* structures that
265 * contains at least *num* elements in it.
267 * An array of pointers to *tle_stream* structures that
268 * must be large enough to store up to *num* pointers in it.
270 * Number of elements in the *prm* and *rs* arrays.
272 * number of of entries filled inside *rs* array.
273 * In case of error, error code set in rte_errno.
274 * Possible rte_errno errors include:
275 * - EINVAL - invalid parameter passed to function
276 * - ENFILE - no more streams are avaialble to open.
280 * Return up to *num* mbufs that was received for given TCP stream.
281 * Note that the stream has to be in connected state.
282 * Data ordering is preserved.
283 * For each returned mbuf:
284 * data_off set to the start of the packet's TCP data
285 * l2_len, l3_len, l4_len are setup properly
286 * (so user can still extract L2/L3 address info if needed)
287 * packet_type RTE_PTYPE_L2/L3/L4 bits are setup properly.
288 * L3/L4 checksum is verified.
290 * TCP stream to receive packets from.
292 * An array of pointers to *rte_mbuf* structures that
293 * must be large enough to store up to *num* pointers in it.
295 * Number of elements in the *pkt* array.
297 * number of of entries filled inside *pkt* array.
299 uint16_t tle_tcp_stream_recv(struct tle_stream *s, struct rte_mbuf *pkt[],
303 * Reads iovcnt buffers from the for given TCP stream.
304 * Note that the stream has to be in connected state.
305 * Data ordering is preserved.
306 * Buffers are processed in array order.
307 * This means that the function will comppletely fill iov[0]
308 * before proceeding to iov[1], and so on.
309 * If there is insufficient data, then not all buffers pointed to by iov
312 * TCP stream to receive data from.
314 * Points to an array of iovec structures.
316 * Number of elements in the *iov* array.
318 * On success, number of bytes read in the stream receive buffer.
319 * In case of error, returns -1 and error code will be set in rte_errno.
321 ssize_t tle_tcp_stream_readv(struct tle_stream *ts, const struct iovec *iov,
325 * Consume and queue up to *num* packets, that will be sent eventually
326 * by tle_tcp_tx_bulk().
327 * Note that the stream has to be in connected state.
328 * It is responsibility of that function is to determine over which TCP dev
329 * given packets have to be sent out and do necessary preparations for that.
330 * Based on the *dst_addr* it does route lookup, fills L2/L3/L4 headers,
331 * and, if necessary, fragments packets.
332 * Depending on the underlying device information, it either does
333 * IP/TCP checksum calculations in SW or sets mbuf TX checksum
334 * offload fields properly.
335 * For each input mbuf the following conditions have to be met:
336 * - data_off point to the start of packet's TCP data.
337 * - there is enough header space to prepend L2/L3/L4 headers.
339 * TCP stream to send packets over.
341 * The burst of output packets that need to be send.
343 * Number of elements in the *pkt* array.
345 * number of packets successfully queued in the stream send buffer.
346 * In case of error, error code can be set in rte_errno.
347 * Possible rte_errno errors include:
348 * - EAGAIN - operation can't be perfomed right now
349 * (most likely close() was perfomed on that stream allready).
350 * - ENOTCONN - the stream is not connected.
352 uint16_t tle_tcp_stream_send(struct tle_stream *s, struct rte_mbuf *pkt[],
356 * Writes iovcnt buffers of data described by iov to the for given TCP stream.
357 * Note that the stream has to be in connected state.
358 * Data ordering is preserved.
359 * Buffers are processed in array order.
360 * This means that the function will write out the entire contents of iov[0]
361 * before proceeding to iov[1], and so on.
362 * If there is insufficient space in stream send buffer,
363 * then not all buffers pointed to by iov may be written out.
365 * TCP stream to send data to.
367 * Points to an array of iovec structures.
369 * Number of elements in the *iov* array.
371 * On success, number of bytes written to the stream send buffer.
372 * In case of error, returns -1 and error code will be set in rte_errno.
373 * - EAGAIN - operation can't be perfomed right now
374 * (most likely close() was perfomed on that stream allready).
375 * - ENOTCONN - the stream is not connected.
376 * - ENOMEM - not enough internal buffer (mbuf) to store user provided data.
378 ssize_t tle_tcp_stream_writev(struct tle_stream *ts, struct rte_mempool *mp,
379 const struct iovec *iov, int iovcnt);
383 * BE API functions are not multi-thread safe.
384 * Supposed to be called by the L2/L3 processing layer.
388 * Take input mbufs and distribute them to open TCP streams.
389 * expects that for each input packet:
390 * - l2_len, l3_len, l4_len are setup correctly
391 * - (packet_type & (RTE_PTYPE_L3_IPV4 | RTE_PTYPE_L3_IPV6)) != 0,
392 * - (packet_type & RTE_PTYPE_L4_TCP) != 0,
393 * During delivery L3/L4 checksums will be verified
394 * (either relies on HW offload or in SW).
395 * May cause some extra packets to be queued for TX.
396 * This function is not multi-thread safe.
398 * TCP device the packets were received from.
400 * The burst of input packets that need to be processed.
402 * The array that will contain pointers of unprocessed packets at return.
403 * Should contain at least *num* elements.
405 * The array that will contain error code for corresponding rp[] entry:
406 * - ENOENT - no open stream matching this packet.
407 * - ENOBUFS - receive buffer of the destination stream is full.
408 * Should contain at least *num* elements.
410 * Number of elements in the *pkt* input array.
412 * number of packets delivered to the TCP streams.
414 uint16_t tle_tcp_rx_bulk(struct tle_dev *dev, struct rte_mbuf *pkt[],
415 struct rte_mbuf *rp[], int32_t rc[], uint16_t num);
418 * Fill *pkt* with pointers to the packets that have to be transmitted
419 * over given TCP device.
420 * Output packets have to be ready to be passed straight to rte_eth_tx_burst()
421 * without any extra processing.
422 * TCP/IPv4 checksum either already calculated or appropriate mbuf fields set
423 * properly for HW offload.
424 * This function is not multi-thread safe.
426 * TCP device the output packets will be transmitted over.
428 * An array of pointers to *rte_mbuf* structures that
429 * must be large enough to store up to *num* pointers in it.
431 * Number of elements in the *pkt* array.
433 * number of of entries filled inside *pkt* array.
435 uint16_t tle_tcp_tx_bulk(struct tle_dev *dev, struct rte_mbuf *pkt[],
439 * perform internal processing for given TCP context.
440 * Checks which timers are expired and performs the required actions
441 * (retransmission/connection abort, etc.)
442 * May cause some extra packets to be queued for TX.
443 * This function is not multi-thread safe.
445 * TCP context to process.
447 * maximum number of streams to process.
449 * zero on successful completion.
450 * - EINVAL - invalid parameter passed to function
453 int tle_tcp_process(struct tle_ctx *ctx, uint32_t num);
459 #endif /* _TLE_TCP_H_ */