Commit 17a7d24a authored by Atul Gupta's avatar Atul Gupta Committed by Herbert Xu

crypto: chtls - generic handling of data and hdr

removed redundant check and made TLS PDU and header recv
handling common as received from HW.
Ensure that only tls header is read in cpl_rx_tls_cmp
read-ahead and skb is freed when entire data is processed.
Signed-off-by: default avatarAtul Gupta <atul.gupta@chelsio.com>
Signed-off-by: default avatarHarsh Jain <harsh@chelsio.com>
Signed-off-by: default avatarHerbert Xu <herbert@gondor.apana.org.au>
parent 6ecc9d9f
...@@ -67,11 +67,6 @@ enum { ...@@ -67,11 +67,6 @@ enum {
CPL_RET_UNKNOWN_TID = 4 /* unexpected unknown TID */ CPL_RET_UNKNOWN_TID = 4 /* unexpected unknown TID */
}; };
#define TLS_RCV_ST_READ_HEADER 0xF0
#define TLS_RCV_ST_READ_BODY 0xF1
#define TLS_RCV_ST_READ_DONE 0xF2
#define TLS_RCV_ST_READ_NB 0xF3
#define LISTEN_INFO_HASH_SIZE 32 #define LISTEN_INFO_HASH_SIZE 32
#define RSPQ_HASH_BITS 5 #define RSPQ_HASH_BITS 5
struct listen_info { struct listen_info {
...@@ -278,6 +273,7 @@ struct tlsrx_cmp_hdr { ...@@ -278,6 +273,7 @@ struct tlsrx_cmp_hdr {
#define TLSRX_HDR_PKT_MAC_ERROR_F TLSRX_HDR_PKT_MAC_ERROR_V(1U) #define TLSRX_HDR_PKT_MAC_ERROR_F TLSRX_HDR_PKT_MAC_ERROR_V(1U)
#define TLSRX_HDR_PKT_ERROR_M 0x1F #define TLSRX_HDR_PKT_ERROR_M 0x1F
#define CONTENT_TYPE_ERROR 0x7F
struct ulp_mem_rw { struct ulp_mem_rw {
__be32 cmd; __be32 cmd;
...@@ -347,8 +343,8 @@ enum { ...@@ -347,8 +343,8 @@ enum {
ULPCB_FLAG_HOLD = 1 << 3, /* skb not ready for Tx yet */ ULPCB_FLAG_HOLD = 1 << 3, /* skb not ready for Tx yet */
ULPCB_FLAG_COMPL = 1 << 4, /* request WR completion */ ULPCB_FLAG_COMPL = 1 << 4, /* request WR completion */
ULPCB_FLAG_URG = 1 << 5, /* urgent data */ ULPCB_FLAG_URG = 1 << 5, /* urgent data */
ULPCB_FLAG_TLS_ND = 1 << 6, /* payload of zero length */ ULPCB_FLAG_TLS_HDR = 1 << 6, /* payload with tls hdr */
ULPCB_FLAG_NO_HDR = 1 << 7, /* not a ofld wr */ ULPCB_FLAG_NO_HDR = 1 << 7, /* not a ofld wr */
}; };
/* The ULP mode/submode of an skbuff */ /* The ULP mode/submode of an skbuff */
......
...@@ -1608,12 +1608,14 @@ static void chtls_set_hdrlen(struct sk_buff *skb, unsigned int nlen) ...@@ -1608,12 +1608,14 @@ static void chtls_set_hdrlen(struct sk_buff *skb, unsigned int nlen)
static void chtls_rx_hdr(struct sock *sk, struct sk_buff *skb) static void chtls_rx_hdr(struct sock *sk, struct sk_buff *skb)
{ {
struct cpl_rx_tls_cmp *cmp_cpl = cplhdr(skb); struct tlsrx_cmp_hdr *tls_hdr_pkt;
struct cpl_rx_tls_cmp *cmp_cpl;
struct sk_buff *skb_rec; struct sk_buff *skb_rec;
struct chtls_sock *csk; struct chtls_sock *csk;
struct chtls_hws *tlsk; struct chtls_hws *tlsk;
struct tcp_sock *tp; struct tcp_sock *tp;
cmp_cpl = cplhdr(skb);
csk = rcu_dereference_sk_user_data(sk); csk = rcu_dereference_sk_user_data(sk);
tlsk = &csk->tlshws; tlsk = &csk->tlshws;
tp = tcp_sk(sk); tp = tcp_sk(sk);
...@@ -1623,16 +1625,18 @@ static void chtls_rx_hdr(struct sock *sk, struct sk_buff *skb) ...@@ -1623,16 +1625,18 @@ static void chtls_rx_hdr(struct sock *sk, struct sk_buff *skb)
skb_reset_transport_header(skb); skb_reset_transport_header(skb);
__skb_pull(skb, sizeof(*cmp_cpl)); __skb_pull(skb, sizeof(*cmp_cpl));
tls_hdr_pkt = (struct tlsrx_cmp_hdr *)skb->data;
if (tls_hdr_pkt->res_to_mac_error & TLSRX_HDR_PKT_ERROR_M)
tls_hdr_pkt->type = CONTENT_TYPE_ERROR;
if (!skb->data_len) if (!skb->data_len)
__skb_trim(skb, CPL_RX_TLS_CMP_LENGTH_G __skb_trim(skb, TLS_HEADER_LENGTH);
(ntohl(cmp_cpl->pdulength_length)));
tp->rcv_nxt += tp->rcv_nxt +=
CPL_RX_TLS_CMP_PDULENGTH_G(ntohl(cmp_cpl->pdulength_length)); CPL_RX_TLS_CMP_PDULENGTH_G(ntohl(cmp_cpl->pdulength_length));
ULP_SKB_CB(skb)->flags |= ULPCB_FLAG_TLS_HDR;
skb_rec = __skb_dequeue(&tlsk->sk_recv_queue); skb_rec = __skb_dequeue(&tlsk->sk_recv_queue);
if (!skb_rec) { if (!skb_rec) {
ULP_SKB_CB(skb)->flags |= ULPCB_FLAG_TLS_ND;
__skb_queue_tail(&sk->sk_receive_queue, skb); __skb_queue_tail(&sk->sk_receive_queue, skb);
} else { } else {
chtls_set_hdrlen(skb, tlsk->pldlen); chtls_set_hdrlen(skb, tlsk->pldlen);
......
...@@ -1449,31 +1449,13 @@ static int chtls_pt_recvmsg(struct sock *sk, struct msghdr *msg, size_t len, ...@@ -1449,31 +1449,13 @@ static int chtls_pt_recvmsg(struct sock *sk, struct msghdr *msg, size_t len,
} }
} }
} }
if (hws->rstate == TLS_RCV_ST_READ_BODY) { if (skb_copy_datagram_msg(skb, offset, msg, avail)) {
if (skb_copy_datagram_msg(skb, offset, if (!copied) {
msg, avail)) { copied = -EFAULT;
if (!copied) { break;
copied = -EFAULT;
break;
}
}
} else {
struct tlsrx_cmp_hdr *tls_hdr_pkt =
(struct tlsrx_cmp_hdr *)skb->data;
if ((tls_hdr_pkt->res_to_mac_error &
TLSRX_HDR_PKT_ERROR_M))
tls_hdr_pkt->type = 0x7F;
/* CMP pld len is for recv seq */
hws->rcvpld = skb->hdr_len;
if (skb_copy_datagram_msg(skb, offset, msg, avail)) {
if (!copied) {
copied = -EFAULT;
break;
}
} }
} }
copied += avail; copied += avail;
len -= avail; len -= avail;
hws->copied_seq += avail; hws->copied_seq += avail;
...@@ -1481,32 +1463,20 @@ static int chtls_pt_recvmsg(struct sock *sk, struct msghdr *msg, size_t len, ...@@ -1481,32 +1463,20 @@ static int chtls_pt_recvmsg(struct sock *sk, struct msghdr *msg, size_t len,
if (tp->urg_data && after(tp->copied_seq, tp->urg_seq)) if (tp->urg_data && after(tp->copied_seq, tp->urg_seq))
tp->urg_data = 0; tp->urg_data = 0;
if (hws->rstate == TLS_RCV_ST_READ_BODY && if ((avail + offset) >= skb->len) {
(avail + offset) >= skb->len) {
if (likely(skb)) if (likely(skb))
chtls_free_skb(sk, skb); chtls_free_skb(sk, skb);
buffers_freed++; buffers_freed++;
hws->rstate = TLS_RCV_ST_READ_HEADER; if (ULP_SKB_CB(skb)->flags & ULPCB_FLAG_TLS_HDR) {
atomic_inc(&adap->chcr_stats.tls_pdu_rx); tp->copied_seq += skb->len;
tp->copied_seq += hws->rcvpld; hws->rcvpld = skb->hdr_len;
} else {
tp->copied_seq += hws->rcvpld;
}
hws->copied_seq = 0; hws->copied_seq = 0;
if (copied >= target && if (copied >= target &&
!skb_peek(&sk->sk_receive_queue)) !skb_peek(&sk->sk_receive_queue))
break; break;
} else {
if (likely(skb)) {
if (ULP_SKB_CB(skb)->flags &
ULPCB_FLAG_TLS_ND)
hws->rstate =
TLS_RCV_ST_READ_HEADER;
else
hws->rstate =
TLS_RCV_ST_READ_BODY;
chtls_free_skb(sk, skb);
}
buffers_freed++;
tp->copied_seq += avail;
hws->copied_seq = 0;
} }
} while (len > 0); } while (len > 0);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment