/*
- * Copyright (c) 2016 Intel Corporation.
+ * Copyright (c) 2016-2017 Intel Corporation.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at:
extern "C" {
#endif
+/**
+ * TCP stream states
+ */
+enum {
+ TLE_TCP_ST_CLOSED,
+ TLE_TCP_ST_LISTEN,
+ TLE_TCP_ST_SYN_SENT,
+ TLE_TCP_ST_SYN_RCVD,
+ TLE_TCP_ST_ESTABLISHED,
+ TLE_TCP_ST_FIN_WAIT_1,
+ TLE_TCP_ST_FIN_WAIT_2,
+ TLE_TCP_ST_CLOSE_WAIT,
+ TLE_TCP_ST_CLOSING,
+ TLE_TCP_ST_LAST_ACK,
+ TLE_TCP_ST_TIME_WAIT,
+ TLE_TCP_ST_NUM
+};
+
+/**
+ * User control operations for TCP stream
+ */
+enum {
+ TLE_TCP_OP_LISTEN = 0x1,
+ TLE_TCP_OP_ACCEPT = 0x2,
+ TLE_TCP_OP_CONNECT = 0x4,
+ TLE_TCP_OP_ESTABLISH = 0x8,
+ TLE_TCP_OP_CLOSE = 0x10,
+ TLE_TCP_OP_ABORT = 0x20,
+};
+
+#define TLE_TCP_OP_CLOSE_ABORT (TLE_TCP_OP_CLOSE | TLE_TCP_OP_ABORT)
+
+/**
+ * termination/error events from remote peer
+ */
+enum {
+ TLE_TCP_REV_FIN = 0x1, /** FIN received from peer*/
+ TLE_TCP_REV_RST = 0x2, /** RST received from peer */
+ TLE_TCP_REV_RTO = 0x4, /** receive timed-out */
+};
+
/**
* TCP stream creation parameters.
*/
struct tle_tcp_stream_cfg {
uint8_t nb_retries; /**< max number of retransmission attempts. */
+ uint64_t udata; /**< user data to be associated with the stream. */
+
/* _cb and _ev are mutually exclusive */
struct tle_event *err_ev; /**< error event to use. */
struct tle_stream_cb err_cb; /**< error callback to use. */
struct tle_tcp_stream_cfg cfg;
};
+/**
+ * Timestamp option.
+ */
+union tle_tcp_tsopt {
+ uint64_t raw;
+ struct {
+ uint32_t val;
+ uint32_t ecr;
+ };
+};
+
+/**
+ * SYN time option values.
+ */
+struct tle_tcp_syn_opts {
+ uint16_t mss;
+ uint8_t wscale;
+ union tle_tcp_tsopt ts;
+};
+
+struct tle_tcp_conn_info {
+ uint16_t wnd;
+ uint32_t seq;
+ uint32_t ack;
+ struct tle_tcp_syn_opts so;
+};
+
+/**
+ * TCP stream state information.
+ */
+struct tle_tcp_stream_state {
+ /** current TCP state (one of TLE_TCP_ST_*) */
+ uint16_t state;
+ /** bitmask of control ops performed by user (TLE_TCP_OP_*) */
+ uint16_t uop;
+ /** bitmask of remote termination events (TLE_TCP_REV_*) */
+ uint16_t rev;
+};
+
/**
* create a new stream within given TCP context.
* @param ctx
* - if stream contains unsent data, then actual close will be postponed
* till either remaining data will be TX-ed, or timeout will expire.
* All packets that belong to that stream and remain in the device
- * TX queue will be kept for father transmission.
+ * TX queue will be kept for further transmission.
* @param s
* Pointer to the stream to close.
* @return
*/
int tle_tcp_stream_close(struct tle_stream *s);
+/**
+ * abnormal stream termination.
+ * if the stream is in connected state, then:
+ * - abnormal connection termination would be performed.
+ * - if stream contains unread data, then it will be wiped out.
+ * - if stream contains unsent data, then it will be wiped out,
+ * without further attempt to TX it.
+ * All packets that belong to that stream and remain in the device
+ * TX queue will be kept for further transmission.
+ * @param s
+ * Pointer to the stream to close.
+ * @return
+ * zero on successful completion.
+ * - -EINVAL - invalid parameter passed to function
+ * - -EDEADLK - close was already invoked on that stream
+ */
+int tle_tcp_stream_abort(struct tle_stream *s);
+
+
/**
* close a group of open streams.
* if the stream is in connected state, then:
tle_tcp_stream_get_addr(const struct tle_stream *s,
struct tle_tcp_stream_addr *addr);
+/**
+ * Get current TCP maximum segment size
+ * @param ts
+ * Stream to retrieve MSS information from.
+ * @return
+ * Maximum segment size in bytes, if successful.
+ * Negative on failure.
+ */
+int tle_tcp_stream_get_mss(const struct tle_stream *ts);
+
+/**
+ * Get current TCP stream state
+ * @param ts
+ * Stream to retrieve state information from.
+ * @return
+ * zero on successful completion.
+ * - EINVAL - invalid parameter passed to function
+ */
+int tle_tcp_stream_get_state(const struct tle_stream *ts,
+ struct tle_tcp_stream_state *st);
+
+struct tle_stream *
+tle_tcp_stream_establish(struct tle_ctx *ctx,
+ const struct tle_tcp_stream_param *prm,
+ const struct tle_tcp_conn_info *ci);
+
/**
* Client mode connect API.
*/
uint16_t tle_tcp_stream_recv(struct tle_stream *s, struct rte_mbuf *pkt[],
uint16_t num);
+/**
+ * Reads iovcnt buffers from the for given TCP stream.
+ * Note that the stream has to be in connected state.
+ * Data ordering is preserved.
+ * Buffers are processed in array order.
+ * This means that the function will comppletely fill iov[0]
+ * before proceeding to iov[1], and so on.
+ * If there is insufficient data, then not all buffers pointed to by iov
+ * may be filled.
+ * @param ts
+ * TCP stream to receive data from.
+ * @param iov
+ * Points to an array of iovec structures.
+ * @param iovcnt
+ * Number of elements in the *iov* array.
+ * @return
+ * On success, number of bytes read in the stream receive buffer.
+ * In case of error, returns -1 and error code will be set in rte_errno.
+ */
+ssize_t tle_tcp_stream_readv(struct tle_stream *ts, const struct iovec *iov,
+ int iovcnt);
+
/**
* Consume and queue up to *num* packets, that will be sent eventually
* by tle_tcp_tx_bulk().
* number of packets successfully queued in the stream send buffer.
* In case of error, error code can be set in rte_errno.
* Possible rte_errno errors include:
- * - EAGAIN - operation can be perfomed right now
+ * - EAGAIN - operation can't be perfomed right now
* (most likely close() was perfomed on that stream allready).
* - ENOTCONN - the stream is not connected.
*/
uint16_t tle_tcp_stream_send(struct tle_stream *s, struct rte_mbuf *pkt[],
uint16_t num);
+/**
+ * Writes iovcnt buffers of data described by iov to the for given TCP stream.
+ * Note that the stream has to be in connected state.
+ * Data ordering is preserved.
+ * Buffers are processed in array order.
+ * This means that the function will write out the entire contents of iov[0]
+ * before proceeding to iov[1], and so on.
+ * If there is insufficient space in stream send buffer,
+ * then not all buffers pointed to by iov may be written out.
+ * @param ts
+ * TCP stream to send data to.
+ * @param iov
+ * Points to an array of iovec structures.
+ * @param iovcnt
+ * Number of elements in the *iov* array.
+ * @return
+ * On success, number of bytes written to the stream send buffer.
+ * In case of error, returns -1 and error code will be set in rte_errno.
+ * - EAGAIN - operation can't be perfomed right now
+ * (most likely close() was perfomed on that stream allready).
+ * - ENOTCONN - the stream is not connected.
+ * - ENOMEM - not enough internal buffer (mbuf) to store user provided data.
+ */
+ssize_t tle_tcp_stream_writev(struct tle_stream *ts, struct rte_mempool *mp,
+ const struct iovec *iov, int iovcnt);
+
/**
* Back End (BE) API.
* BE API functions are not multi-thread safe.
uint16_t tle_tcp_rx_bulk(struct tle_dev *dev, struct rte_mbuf *pkt[],
struct rte_mbuf *rp[], int32_t rc[], uint16_t num);
+
+/**
+ * Take input mbufs and put them for processing to given TCP streams.
+ * expects that for each input packet:
+ * - l2_len, l3_len, l4_len are setup correctly
+ * - (packet_type & (RTE_PTYPE_L3_IPV4 | RTE_PTYPE_L3_IPV6)) != 0,
+ * - (packet_type & RTE_PTYPE_L4_TCP) != 0,
+ * During delivery L3/L4 checksums will be verified
+ * (either relies on HW offload or in SW).
+ * May cause some extra packets to be queued for TX.
+ * This function is not multi-thread safe.
+ * @param ts
+ * TCP stream given packets belong to.
+ * Note that it is caller repsonsibility to make sure that input packets
+ * belong to given stream.
+ * @param pkt
+ * The burst of input packets that need to be processed.
+ * @param rp
+ * The array that will contain pointers of unprocessed packets at return.
+ * Should contain at least *num* elements.
+ * @param rc
+ * The array that will contain error code for corresponding rp[] entry:
+ * - ENOENT - invalid stream.
+ * - ENOBUFS - receive buffer of the destination stream is full.
+ * - EINVAL - invalid input packet encountered.
+ * Should contain at least *num* elements.
+ * @param num
+ * Number of elements in the *pkt* input array.
+ * @return
+ * number of packets delivered to the TCP stream.
+ */
+uint16_t tle_tcp_stream_rx_bulk(struct tle_stream *ts, struct rte_mbuf *pkt[],
+ struct rte_mbuf *rp[], int32_t rc[], uint16_t num);
+
/**
* Fill *pkt* with pointers to the packets that have to be transmitted
* over given TCP device.