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.
33 TLE_TCP_ST_ESTABLISHED,
34 TLE_TCP_ST_FIN_WAIT_1,
35 TLE_TCP_ST_FIN_WAIT_2,
36 TLE_TCP_ST_CLOSE_WAIT,
44 * User control operations for TCP stream
47 TLE_TCP_OP_LISTEN = 0x1,
48 TLE_TCP_OP_ACCEPT = 0x2,
49 TLE_TCP_OP_CONNECT = 0x4,
50 TLE_TCP_OP_ESTABLISH = 0x8,
51 TLE_TCP_OP_CLOSE = 0x10,
55 * termination/error events from remote peer
58 TLE_TCP_REV_FIN = 0x1, /** FIN received from peer*/
59 TLE_TCP_REV_RST = 0x2, /** RST received from peer */
60 TLE_TCP_REV_RTO = 0x4, /** receive timed-out */
64 * TCP stream creation parameters.
66 struct tle_tcp_stream_addr {
67 struct sockaddr_storage local; /**< stream local address. */
68 struct sockaddr_storage remote; /**< stream remote address. */
71 #define TLE_TCP_DEFAULT_RETRIES 3
73 struct tle_tcp_stream_cfg {
74 uint8_t nb_retries; /**< max number of retransmission attempts. */
76 uint64_t udata; /**< user data to be associated with the stream. */
78 /* _cb and _ev are mutually exclusive */
79 struct tle_event *err_ev; /**< error event to use. */
80 struct tle_stream_cb err_cb; /**< error callback to use. */
82 struct tle_event *recv_ev; /**< recv event to use. */
83 struct tle_stream_cb recv_cb; /**< recv callback to use. */
85 struct tle_event *send_ev; /**< send event to use. */
86 struct tle_stream_cb send_cb; /**< send callback to use. */
89 struct tle_tcp_stream_param {
90 struct tle_tcp_stream_addr addr;
91 struct tle_tcp_stream_cfg cfg;
106 * SYN time option values.
108 struct tle_tcp_syn_opts {
111 union tle_tcp_tsopt ts;
114 struct tle_tcp_conn_info {
118 struct tle_tcp_syn_opts so;
122 * TCP stream state information.
124 struct tle_tcp_stream_state {
125 /** current TCP state (one of TLE_TCP_ST_*) */
127 /** bitmask of control ops performed by user (TLE_TCP_OP_*) */
129 /** bitmask of remote termination events (TLE_TCP_REV_*) */
134 * create a new stream within given TCP context.
136 * TCP context to create new stream within.
138 * Parameters used to create and initialise the new stream.
140 * Pointer to TCP stream structure that can be used in future TCP API calls,
141 * or NULL on error, with error code set in rte_errno.
142 * Possible rte_errno errors include:
143 * - EINVAL - invalid parameter passed to function
144 * - ENOFILE - max limit of open streams reached for that context
147 tle_tcp_stream_open(struct tle_ctx *ctx,
148 const struct tle_tcp_stream_param *prm);
151 * close an open stream.
152 * if the stream is in connected state, then:
153 * - connection termination would be performed.
154 * - if stream contains unsent data, then actual close will be postponed
155 * till either remaining data will be TX-ed, or timeout will expire.
156 * All packets that belong to that stream and remain in the device
157 * TX queue will be kept for father transmission.
159 * Pointer to the stream to close.
161 * zero on successful completion.
162 * - -EINVAL - invalid parameter passed to function
163 * - -EDEADLK - close was already invoked on that stream
165 int tle_tcp_stream_close(struct tle_stream *s);
168 * close a group of open streams.
169 * if the stream is in connected state, then:
170 * - connection termination would be performed.
171 * - if stream contains unsent data, then actual close will be postponed
172 * till either remaining data will be TX-ed, or timeout will expire.
173 * All packets that belong to that stream and remain in the device
174 * TX queue will be kept for father transmission.
176 * An array of pointers to streams that have to be closed.
178 * Number of elements in the *ts* array.
180 * number of successfully closed streams.
181 * In case of error, error code set in rte_errno.
182 * Possible rte_errno errors include:
183 * - EINVAL - invalid parameter passed to function
184 * - EDEADLK - close was already invoked on that stream
187 tle_tcp_stream_close_bulk(struct tle_stream *ts[], uint32_t num);
190 * get open stream local and remote addresses.
192 * Pointer to the stream.
194 * zero on successful completion.
195 * - EINVAL - invalid parameter passed to function
198 tle_tcp_stream_get_addr(const struct tle_stream *s,
199 struct tle_tcp_stream_addr *addr);
202 * Get current TCP maximum segment size
204 * Stream to retrieve MSS information from.
206 * Maximum segment size in bytes, if successful.
207 * Negative on failure.
209 int tle_tcp_stream_get_mss(const struct tle_stream *ts);
212 * Get current TCP stream state
214 * Stream to retrieve state information from.
216 * zero on successful completion.
217 * - EINVAL - invalid parameter passed to function
219 int tle_tcp_stream_get_state(const struct tle_stream *ts,
220 struct tle_tcp_stream_state *st);
223 tle_tcp_stream_establish(struct tle_ctx *ctx,
224 const struct tle_tcp_stream_param *prm,
225 const struct tle_tcp_conn_info *ci);
228 * Client mode connect API.
232 * Attempt to establish connection with the destination TCP endpoint.
233 * Stream write event (or callback) will fire, if the connection will be
234 * established successfully.
235 * Note that stream in listen state or stream with already established
236 * connection, can't be subject of connect() call.
237 * In case of unsuccessful attempt, error event (or callback) will be
240 * Pointer to the stream.
242 * Address of the destination endpoint.
244 * zero on successful completion.
245 * - -EINVAL - invalid parameter passed to function
247 int tle_tcp_stream_connect(struct tle_stream *s, const struct sockaddr *addr);
250 * Server mode connect API.
251 * Basic scheme for server mode API usage:
253 * <stream open happens here>
254 * tle_tcp_stream_listen(stream_to_listen);
255 * <wait for read event/callback on that stream>
256 * n = tle_tcp_accept(stream_to_listen, accepted_streams,
257 * sizeof(accepted_streams));
258 * for (i = 0, i != n; i++) {
259 * //prepare tle_tcp_stream_cfg for newly accepted streams
262 * k = tle_tcp_stream_update_cfg(rs, prm, n);
270 * Set stream into the listen state (passive opener), i.e. make stream ready
271 * to accept new connections.
272 * Stream read event (or callback) will be activated as new SYN requests
274 * Note that stream with already established (or establishing) connection
275 * can't be subject of listen() call.
277 * Pointer to the stream.
279 * zero on successful completion.
280 * - -EINVAL - invalid parameter passed to function
282 int tle_tcp_stream_listen(struct tle_stream *s);
285 * return up to *num* streams from the queue of pending connections
286 * for given TCP endpoint.
288 * TCP stream in listen state.
290 * An array of pointers to the newily accepted streams.
291 * Each such new stream represents a new connection to the given TCP endpoint.
292 * Newly accepted stream should be in connected state and ready to use
293 * by other FE API routines (send/recv/close/etc.).
295 * Number of elements in the *rs* array.
297 * number of entries filled inside *rs* array.
299 uint16_t tle_tcp_stream_accept(struct tle_stream *s, struct tle_stream *rs[],
303 * updates configuration (associated events, callbacks, stream parameters)
304 * for the given streams.
306 * An array of pointers to the streams to update.
308 * An array of parameters to update for the given streams.
310 * Number of elements in the *ts* and *prm* arrays.
312 * number of streams successfully updated.
313 * In case of error, error code set in rte_errno.
314 * Possible rte_errno errors include:
315 * - EINVAL - invalid parameter passed to function
317 uint32_t tle_tcp_stream_update_cfg(struct tle_stream *ts[],
318 struct tle_tcp_stream_cfg prm[], uint32_t num);
321 * Accept connection requests for the given stream.
322 * Note that the stream has to be in listen state.
323 * For each new connection a new stream will be open.
327 * An array of *tle_tcp_accept_param* structures that
328 * contains at least *num* elements in it.
330 * An array of pointers to *tle_stream* structures that
331 * must be large enough to store up to *num* pointers in it.
333 * Number of elements in the *prm* and *rs* arrays.
335 * number of of entries filled inside *rs* array.
336 * In case of error, error code set in rte_errno.
337 * Possible rte_errno errors include:
338 * - EINVAL - invalid parameter passed to function
339 * - ENFILE - no more streams are avaialble to open.
343 * Return up to *num* mbufs that was received for given TCP stream.
344 * Note that the stream has to be in connected state.
345 * Data ordering is preserved.
346 * For each returned mbuf:
347 * data_off set to the start of the packet's TCP data
348 * l2_len, l3_len, l4_len are setup properly
349 * (so user can still extract L2/L3 address info if needed)
350 * packet_type RTE_PTYPE_L2/L3/L4 bits are setup properly.
351 * L3/L4 checksum is verified.
353 * TCP stream to receive packets from.
355 * An array of pointers to *rte_mbuf* structures that
356 * must be large enough to store up to *num* pointers in it.
358 * Number of elements in the *pkt* array.
360 * number of of entries filled inside *pkt* array.
362 uint16_t tle_tcp_stream_recv(struct tle_stream *s, struct rte_mbuf *pkt[],
366 * Reads iovcnt buffers from the for given TCP stream.
367 * Note that the stream has to be in connected state.
368 * Data ordering is preserved.
369 * Buffers are processed in array order.
370 * This means that the function will comppletely fill iov[0]
371 * before proceeding to iov[1], and so on.
372 * If there is insufficient data, then not all buffers pointed to by iov
375 * TCP stream to receive data from.
377 * Points to an array of iovec structures.
379 * Number of elements in the *iov* array.
381 * On success, number of bytes read in the stream receive buffer.
382 * In case of error, returns -1 and error code will be set in rte_errno.
384 ssize_t tle_tcp_stream_readv(struct tle_stream *ts, const struct iovec *iov,
388 * Consume and queue up to *num* packets, that will be sent eventually
389 * by tle_tcp_tx_bulk().
390 * Note that the stream has to be in connected state.
391 * It is responsibility of that function is to determine over which TCP dev
392 * given packets have to be sent out and do necessary preparations for that.
393 * Based on the *dst_addr* it does route lookup, fills L2/L3/L4 headers,
394 * and, if necessary, fragments packets.
395 * Depending on the underlying device information, it either does
396 * IP/TCP checksum calculations in SW or sets mbuf TX checksum
397 * offload fields properly.
398 * For each input mbuf the following conditions have to be met:
399 * - data_off point to the start of packet's TCP data.
400 * - there is enough header space to prepend L2/L3/L4 headers.
402 * TCP stream to send packets over.
404 * The burst of output packets that need to be send.
406 * Number of elements in the *pkt* array.
408 * number of packets successfully queued in the stream send buffer.
409 * In case of error, error code can be set in rte_errno.
410 * Possible rte_errno errors include:
411 * - EAGAIN - operation can't be perfomed right now
412 * (most likely close() was perfomed on that stream allready).
413 * - ENOTCONN - the stream is not connected.
415 uint16_t tle_tcp_stream_send(struct tle_stream *s, struct rte_mbuf *pkt[],
419 * Writes iovcnt buffers of data described by iov to the for given TCP stream.
420 * Note that the stream has to be in connected state.
421 * Data ordering is preserved.
422 * Buffers are processed in array order.
423 * This means that the function will write out the entire contents of iov[0]
424 * before proceeding to iov[1], and so on.
425 * If there is insufficient space in stream send buffer,
426 * then not all buffers pointed to by iov may be written out.
428 * TCP stream to send data to.
430 * Points to an array of iovec structures.
432 * Number of elements in the *iov* array.
434 * On success, number of bytes written to the stream send buffer.
435 * In case of error, returns -1 and error code will be set in rte_errno.
436 * - EAGAIN - operation can't be perfomed right now
437 * (most likely close() was perfomed on that stream allready).
438 * - ENOTCONN - the stream is not connected.
439 * - ENOMEM - not enough internal buffer (mbuf) to store user provided data.
441 ssize_t tle_tcp_stream_writev(struct tle_stream *ts, struct rte_mempool *mp,
442 const struct iovec *iov, int iovcnt);
446 * BE API functions are not multi-thread safe.
447 * Supposed to be called by the L2/L3 processing layer.
451 * Take input mbufs and distribute them to open TCP streams.
452 * expects that for each input packet:
453 * - l2_len, l3_len, l4_len are setup correctly
454 * - (packet_type & (RTE_PTYPE_L3_IPV4 | RTE_PTYPE_L3_IPV6)) != 0,
455 * - (packet_type & RTE_PTYPE_L4_TCP) != 0,
456 * During delivery L3/L4 checksums will be verified
457 * (either relies on HW offload or in SW).
458 * May cause some extra packets to be queued for TX.
459 * This function is not multi-thread safe.
461 * TCP device the packets were received from.
463 * The burst of input packets that need to be processed.
465 * The array that will contain pointers of unprocessed packets at return.
466 * Should contain at least *num* elements.
468 * The array that will contain error code for corresponding rp[] entry:
469 * - ENOENT - no open stream matching this packet.
470 * - ENOBUFS - receive buffer of the destination stream is full.
471 * Should contain at least *num* elements.
473 * Number of elements in the *pkt* input array.
475 * number of packets delivered to the TCP streams.
477 uint16_t tle_tcp_rx_bulk(struct tle_dev *dev, struct rte_mbuf *pkt[],
478 struct rte_mbuf *rp[], int32_t rc[], uint16_t num);
482 * Take input mbufs and put them for processing to given TCP streams.
483 * expects that for each input packet:
484 * - l2_len, l3_len, l4_len are setup correctly
485 * - (packet_type & (RTE_PTYPE_L3_IPV4 | RTE_PTYPE_L3_IPV6)) != 0,
486 * - (packet_type & RTE_PTYPE_L4_TCP) != 0,
487 * During delivery L3/L4 checksums will be verified
488 * (either relies on HW offload or in SW).
489 * May cause some extra packets to be queued for TX.
490 * This function is not multi-thread safe.
492 * TCP stream given packets belong to.
493 * Note that it is caller repsonsibility to make sure that input packets
494 * belong to given stream.
496 * The burst of input packets that need to be processed.
498 * The array that will contain pointers of unprocessed packets at return.
499 * Should contain at least *num* elements.
501 * The array that will contain error code for corresponding rp[] entry:
502 * - ENOENT - invalid stream.
503 * - ENOBUFS - receive buffer of the destination stream is full.
504 * - EINVAL - invalid input packet encountered.
505 * Should contain at least *num* elements.
507 * Number of elements in the *pkt* input array.
509 * number of packets delivered to the TCP stream.
511 uint16_t tle_tcp_stream_rx_bulk(struct tle_stream *ts, struct rte_mbuf *pkt[],
512 struct rte_mbuf *rp[], int32_t rc[], uint16_t num);
515 * Fill *pkt* with pointers to the packets that have to be transmitted
516 * over given TCP device.
517 * Output packets have to be ready to be passed straight to rte_eth_tx_burst()
518 * without any extra processing.
519 * TCP/IPv4 checksum either already calculated or appropriate mbuf fields set
520 * properly for HW offload.
521 * This function is not multi-thread safe.
523 * TCP device the output packets will be transmitted over.
525 * An array of pointers to *rte_mbuf* structures that
526 * must be large enough to store up to *num* pointers in it.
528 * Number of elements in the *pkt* array.
530 * number of of entries filled inside *pkt* array.
532 uint16_t tle_tcp_tx_bulk(struct tle_dev *dev, struct rte_mbuf *pkt[],
536 * perform internal processing for given TCP context.
537 * Checks which timers are expired and performs the required actions
538 * (retransmission/connection abort, etc.)
539 * May cause some extra packets to be queued for TX.
540 * This function is not multi-thread safe.
542 * TCP context to process.
544 * maximum number of streams to process.
546 * zero on successful completion.
547 * - EINVAL - invalid parameter passed to function
550 int tle_tcp_process(struct tle_ctx *ctx, uint32_t num);
556 #endif /* _TLE_TCP_H_ */