1 // SPDX-License-Identifier: GPL-2.0-only
2 /* Copyright (C) 2020 Chelsio Communications. All rights reserved. */
4 #ifdef CONFIG_CHELSIO_TLS_DEVICE
5 #include <linux/highmem.h>
9 static int chcr_init_tcb_fields(struct chcr_ktls_info
*tx_info
);
11 * chcr_ktls_save_keys: calculate and save crypto keys.
12 * @tx_info - driver specific tls info.
13 * @crypto_info - tls crypto information.
14 * @direction - TX/RX direction.
15 * return - SUCCESS/FAILURE.
17 static int chcr_ktls_save_keys(struct chcr_ktls_info
*tx_info
,
18 struct tls_crypto_info
*crypto_info
,
19 enum tls_offload_ctx_dir direction
)
21 int ck_size
, key_ctx_size
, mac_key_size
, keylen
, ghash_size
, ret
;
22 unsigned char ghash_h
[TLS_CIPHER_AES_GCM_256_TAG_SIZE
];
23 struct tls12_crypto_info_aes_gcm_128
*info_128_gcm
;
24 struct ktls_key_ctx
*kctx
= &tx_info
->key_ctx
;
25 struct crypto_cipher
*cipher
;
26 unsigned char *key
, *salt
;
28 switch (crypto_info
->cipher_type
) {
29 case TLS_CIPHER_AES_GCM_128
:
31 (struct tls12_crypto_info_aes_gcm_128
*)crypto_info
;
32 keylen
= TLS_CIPHER_AES_GCM_128_KEY_SIZE
;
33 ck_size
= CHCR_KEYCTX_CIPHER_KEY_SIZE_128
;
34 tx_info
->salt_size
= TLS_CIPHER_AES_GCM_128_SALT_SIZE
;
35 mac_key_size
= CHCR_KEYCTX_MAC_KEY_SIZE_128
;
36 tx_info
->iv_size
= TLS_CIPHER_AES_GCM_128_IV_SIZE
;
37 tx_info
->iv
= be64_to_cpu(*(__be64
*)info_128_gcm
->iv
);
39 ghash_size
= TLS_CIPHER_AES_GCM_128_TAG_SIZE
;
40 key
= info_128_gcm
->key
;
41 salt
= info_128_gcm
->salt
;
42 tx_info
->record_no
= *(u64
*)info_128_gcm
->rec_seq
;
44 /* The SCMD fields used when encrypting a full TLS
45 * record. Its a one time calculation till the
48 tx_info
->scmd0_seqno_numivs
=
49 SCMD_SEQ_NO_CTRL_V(CHCR_SCMD_SEQ_NO_CTRL_64BIT
) |
50 SCMD_CIPH_AUTH_SEQ_CTRL_F
|
51 SCMD_PROTO_VERSION_V(CHCR_SCMD_PROTO_VERSION_TLS
) |
52 SCMD_CIPH_MODE_V(CHCR_SCMD_CIPHER_MODE_AES_GCM
) |
53 SCMD_AUTH_MODE_V(CHCR_SCMD_AUTH_MODE_GHASH
) |
54 SCMD_IV_SIZE_V(TLS_CIPHER_AES_GCM_128_IV_SIZE
>> 1) |
57 /* keys will be sent inline. */
58 tx_info
->scmd0_ivgen_hdrlen
= SCMD_KEY_CTX_INLINE_F
;
60 /* The SCMD fields used when encrypting a partial TLS
61 * record (no trailer and possibly a truncated payload).
63 tx_info
->scmd0_short_seqno_numivs
=
64 SCMD_CIPH_AUTH_SEQ_CTRL_F
|
65 SCMD_PROTO_VERSION_V(CHCR_SCMD_PROTO_VERSION_GENERIC
) |
66 SCMD_CIPH_MODE_V(CHCR_SCMD_CIPHER_MODE_AES_CTR
) |
67 SCMD_IV_SIZE_V(AES_BLOCK_LEN
>> 1);
69 tx_info
->scmd0_short_ivgen_hdrlen
=
70 tx_info
->scmd0_ivgen_hdrlen
| SCMD_AADIVDROP_F
;
75 pr_err("GCM: cipher type 0x%x not supported\n",
76 crypto_info
->cipher_type
);
81 key_ctx_size
= CHCR_KTLS_KEY_CTX_LEN
+
82 roundup(keylen
, 16) + ghash_size
;
83 /* Calculate the H = CIPH(K, 0 repeated 16 times).
84 * It will go in key context
86 cipher
= crypto_alloc_cipher("aes", 0, 0);
92 ret
= crypto_cipher_setkey(cipher
, key
, keylen
);
96 memset(ghash_h
, 0, ghash_size
);
97 crypto_cipher_encrypt_one(cipher
, ghash_h
, ghash_h
);
99 /* fill the Key context */
100 if (direction
== TLS_OFFLOAD_CTX_DIR_TX
) {
101 kctx
->ctx_hdr
= FILL_KEY_CTX_HDR(ck_size
,
109 memcpy(kctx
->salt
, salt
, tx_info
->salt_size
);
110 memcpy(kctx
->key
, key
, keylen
);
111 memcpy(kctx
->key
+ keylen
, ghash_h
, ghash_size
);
112 tx_info
->key_ctx_len
= key_ctx_size
;
115 crypto_free_cipher(cipher
);
120 static int chcr_ktls_update_connection_state(struct chcr_ktls_info
*tx_info
,
123 /* This function can be called from both rx (interrupt context) and tx
126 spin_lock_bh(&tx_info
->lock
);
127 switch (tx_info
->connection_state
) {
128 case KTLS_CONN_CLOSED
:
129 tx_info
->connection_state
= new_state
;
132 case KTLS_CONN_ACT_OPEN_REQ
:
133 /* only go forward if state is greater than current state. */
134 if (new_state
<= tx_info
->connection_state
)
136 /* update to the next state and also initialize TCB */
137 tx_info
->connection_state
= new_state
;
139 case KTLS_CONN_ACT_OPEN_RPL
:
140 /* if we are stuck in this state, means tcb init might not
141 * received by HW, try sending it again.
143 if (!chcr_init_tcb_fields(tx_info
))
144 tx_info
->connection_state
= KTLS_CONN_SET_TCB_REQ
;
147 case KTLS_CONN_SET_TCB_REQ
:
148 /* only go forward if state is greater than current state. */
149 if (new_state
<= tx_info
->connection_state
)
151 /* update to the next state and check if l2t_state is valid */
152 tx_info
->connection_state
= new_state
;
154 case KTLS_CONN_SET_TCB_RPL
:
155 /* Check if l2t state is valid, then move to ready state. */
156 if (cxgb4_check_l2t_valid(tx_info
->l2te
)) {
157 tx_info
->connection_state
= KTLS_CONN_TX_READY
;
158 atomic64_inc(&tx_info
->adap
->chcr_stats
.ktls_tx_ctx
);
162 case KTLS_CONN_TX_READY
:
163 /* nothing to be done here */
167 pr_err("unknown KTLS connection state\n");
170 spin_unlock_bh(&tx_info
->lock
);
172 return tx_info
->connection_state
;
175 * chcr_ktls_act_open_req: creates TCB entry for ipv4 connection.
177 * @tx_info - driver specific tls info.
178 * @atid - connection active tid.
179 * return - send success/failure.
181 static int chcr_ktls_act_open_req(struct sock
*sk
,
182 struct chcr_ktls_info
*tx_info
,
185 struct inet_sock
*inet
= inet_sk(sk
);
186 struct cpl_t6_act_open_req
*cpl6
;
187 struct cpl_act_open_req
*cpl
;
194 skb
= alloc_skb(len
, GFP_KERNEL
);
197 /* mark it a control pkt */
198 set_wr_txq(skb
, CPL_PRIORITY_CONTROL
, tx_info
->port_id
);
200 cpl6
= __skb_put_zero(skb
, len
);
201 cpl
= (struct cpl_act_open_req
*)cpl6
;
203 qid_atid
= TID_QID_V(tx_info
->rx_qid
) |
205 OPCODE_TID(cpl
) = htonl(MK_OPCODE_TID(CPL_ACT_OPEN_REQ
, qid_atid
));
206 cpl
->local_port
= inet
->inet_sport
;
207 cpl
->peer_port
= inet
->inet_dport
;
208 cpl
->local_ip
= inet
->inet_rcv_saddr
;
209 cpl
->peer_ip
= inet
->inet_daddr
;
211 /* fill first 64 bit option field. */
212 options
= TCAM_BYPASS_F
| ULP_MODE_V(ULP_MODE_NONE
) | NON_OFFLOAD_F
|
213 SMAC_SEL_V(tx_info
->smt_idx
) | TX_CHAN_V(tx_info
->tx_chan
);
214 cpl
->opt0
= cpu_to_be64(options
);
216 /* next 64 bit option field. */
218 TX_QUEUE_V(tx_info
->adap
->params
.tp
.tx_modq
[tx_info
->tx_chan
]);
219 cpl
->opt2
= htonl(options
);
221 return cxgb4_l2t_send(tx_info
->netdev
, skb
, tx_info
->l2te
);
225 * chcr_ktls_act_open_req6: creates TCB entry for ipv6 connection.
227 * @tx_info - driver specific tls info.
228 * @atid - connection active tid.
229 * return - send success/failure.
231 static int chcr_ktls_act_open_req6(struct sock
*sk
,
232 struct chcr_ktls_info
*tx_info
,
235 struct inet_sock
*inet
= inet_sk(sk
);
236 struct cpl_t6_act_open_req6
*cpl6
;
237 struct cpl_act_open_req6
*cpl
;
244 skb
= alloc_skb(len
, GFP_KERNEL
);
247 /* mark it a control pkt */
248 set_wr_txq(skb
, CPL_PRIORITY_CONTROL
, tx_info
->port_id
);
250 cpl6
= __skb_put_zero(skb
, len
);
251 cpl
= (struct cpl_act_open_req6
*)cpl6
;
253 qid_atid
= TID_QID_V(tx_info
->rx_qid
) | TID_TID_V(atid
);
254 OPCODE_TID(cpl
) = htonl(MK_OPCODE_TID(CPL_ACT_OPEN_REQ6
, qid_atid
));
255 cpl
->local_port
= inet
->inet_sport
;
256 cpl
->peer_port
= inet
->inet_dport
;
257 cpl
->local_ip_hi
= *(__be64
*)&sk
->sk_v6_rcv_saddr
.in6_u
.u6_addr8
[0];
258 cpl
->local_ip_lo
= *(__be64
*)&sk
->sk_v6_rcv_saddr
.in6_u
.u6_addr8
[8];
259 cpl
->peer_ip_hi
= *(__be64
*)&sk
->sk_v6_daddr
.in6_u
.u6_addr8
[0];
260 cpl
->peer_ip_lo
= *(__be64
*)&sk
->sk_v6_daddr
.in6_u
.u6_addr8
[8];
262 /* first 64 bit option field. */
263 options
= TCAM_BYPASS_F
| ULP_MODE_V(ULP_MODE_NONE
) | NON_OFFLOAD_F
|
264 SMAC_SEL_V(tx_info
->smt_idx
) | TX_CHAN_V(tx_info
->tx_chan
);
265 cpl
->opt0
= cpu_to_be64(options
);
266 /* next 64 bit option field. */
268 TX_QUEUE_V(tx_info
->adap
->params
.tp
.tx_modq
[tx_info
->tx_chan
]);
269 cpl
->opt2
= htonl(options
);
271 return cxgb4_l2t_send(tx_info
->netdev
, skb
, tx_info
->l2te
);
275 * chcr_setup_connection: create a TCB entry so that TP will form tcp packets.
277 * @tx_info - driver specific tls info.
278 * return: NET_TX_OK/NET_XMIT_DROP
280 static int chcr_setup_connection(struct sock
*sk
,
281 struct chcr_ktls_info
*tx_info
)
283 struct tid_info
*t
= &tx_info
->adap
->tids
;
286 atid
= cxgb4_alloc_atid(t
, tx_info
);
290 tx_info
->atid
= atid
;
291 tx_info
->ip_family
= sk
->sk_family
;
293 if (sk
->sk_family
== AF_INET
||
294 (sk
->sk_family
== AF_INET6
&& !sk
->sk_ipv6only
&&
295 ipv6_addr_type(&sk
->sk_v6_daddr
) == IPV6_ADDR_MAPPED
)) {
296 tx_info
->ip_family
= AF_INET
;
297 ret
= chcr_ktls_act_open_req(sk
, tx_info
, atid
);
299 tx_info
->ip_family
= AF_INET6
;
301 cxgb4_clip_get(tx_info
->netdev
,
302 (const u32
*)&sk
->sk_v6_rcv_saddr
.in6_u
.u6_addr8
,
306 ret
= chcr_ktls_act_open_req6(sk
, tx_info
, atid
);
309 /* if return type is NET_XMIT_CN, msg will be sent but delayed, mark ret
310 * success, if any other return type clear atid and return that failure.
313 if (ret
== NET_XMIT_CN
)
316 cxgb4_free_atid(t
, atid
);
320 /* update the connection state */
321 chcr_ktls_update_connection_state(tx_info
, KTLS_CONN_ACT_OPEN_REQ
);
327 * chcr_set_tcb_field: update tcb fields.
328 * @tx_info - driver specific tls info.
330 * @mask - TCB word related mask.
331 * @val - TCB word related value.
332 * @no_reply - set 1 if not looking for TP response.
334 static int chcr_set_tcb_field(struct chcr_ktls_info
*tx_info
, u16 word
,
335 u64 mask
, u64 val
, int no_reply
)
337 struct cpl_set_tcb_field
*req
;
340 skb
= alloc_skb(sizeof(struct cpl_set_tcb_field
), GFP_ATOMIC
);
344 req
= (struct cpl_set_tcb_field
*)__skb_put_zero(skb
, sizeof(*req
));
345 INIT_TP_WR_CPL(req
, CPL_SET_TCB_FIELD
, tx_info
->tid
);
346 req
->reply_ctrl
= htons(QUEUENO_V(tx_info
->rx_qid
) |
347 NO_REPLY_V(no_reply
));
348 req
->word_cookie
= htons(TCB_WORD_V(word
));
349 req
->mask
= cpu_to_be64(mask
);
350 req
->val
= cpu_to_be64(val
);
352 set_wr_txq(skb
, CPL_PRIORITY_CONTROL
, tx_info
->port_id
);
353 return cxgb4_ofld_send(tx_info
->netdev
, skb
);
357 * chcr_ktls_mark_tcb_close: mark tcb state to CLOSE
358 * @tx_info - driver specific tls info.
359 * return: NET_TX_OK/NET_XMIT_DROP.
361 static int chcr_ktls_mark_tcb_close(struct chcr_ktls_info
*tx_info
)
363 return chcr_set_tcb_field(tx_info
, TCB_T_STATE_W
,
364 TCB_T_STATE_V(TCB_T_STATE_M
),
365 CHCR_TCB_STATE_CLOSED
, 1);
369 * chcr_ktls_dev_del: call back for tls_dev_del.
370 * Remove the tid and l2t entry and close the connection.
371 * it per connection basis.
372 * @netdev - net device.
373 * @tls_cts - tls context.
374 * @direction - TX/RX crypto direction
376 static void chcr_ktls_dev_del(struct net_device
*netdev
,
377 struct tls_context
*tls_ctx
,
378 enum tls_offload_ctx_dir direction
)
380 struct chcr_ktls_ofld_ctx_tx
*tx_ctx
=
381 chcr_get_ktls_tx_context(tls_ctx
);
382 struct chcr_ktls_info
*tx_info
= tx_ctx
->chcr_info
;
389 spin_lock(&tx_info
->lock
);
390 tx_info
->connection_state
= KTLS_CONN_CLOSED
;
391 spin_unlock(&tx_info
->lock
);
393 /* clear l2t entry */
395 cxgb4_l2t_release(tx_info
->l2te
);
397 /* clear clip entry */
398 if (tx_info
->ip_family
== AF_INET6
)
399 cxgb4_clip_release(netdev
,
400 (const u32
*)&sk
->sk_v6_daddr
.in6_u
.u6_addr8
,
404 if (tx_info
->tid
!= -1) {
405 /* clear tcb state and then release tid */
406 chcr_ktls_mark_tcb_close(tx_info
);
407 cxgb4_remove_tid(&tx_info
->adap
->tids
, tx_info
->tx_chan
,
408 tx_info
->tid
, tx_info
->ip_family
);
411 atomic64_inc(&tx_info
->adap
->chcr_stats
.ktls_tx_connection_close
);
413 tx_ctx
->chcr_info
= NULL
;
417 * chcr_ktls_dev_add: call back for tls_dev_add.
418 * Create a tcb entry for TP. Also add l2t entry for the connection. And
419 * generate keys & save those keys locally.
420 * @netdev - net device.
421 * @tls_cts - tls context.
422 * @direction - TX/RX crypto direction
423 * return: SUCCESS/FAILURE.
425 static int chcr_ktls_dev_add(struct net_device
*netdev
, struct sock
*sk
,
426 enum tls_offload_ctx_dir direction
,
427 struct tls_crypto_info
*crypto_info
,
428 u32 start_offload_tcp_sn
)
430 struct tls_context
*tls_ctx
= tls_get_ctx(sk
);
431 struct chcr_ktls_ofld_ctx_tx
*tx_ctx
;
432 struct chcr_ktls_info
*tx_info
;
433 struct dst_entry
*dst
;
434 struct adapter
*adap
;
435 struct port_info
*pi
;
440 tx_ctx
= chcr_get_ktls_tx_context(tls_ctx
);
442 pi
= netdev_priv(netdev
);
444 if (direction
== TLS_OFFLOAD_CTX_DIR_RX
) {
445 pr_err("not expecting for RX direction\n");
449 if (tx_ctx
->chcr_info
) {
454 tx_info
= kvzalloc(sizeof(*tx_info
), GFP_KERNEL
);
460 spin_lock_init(&tx_info
->lock
);
462 /* clear connection state */
463 spin_lock(&tx_info
->lock
);
464 tx_info
->connection_state
= KTLS_CONN_CLOSED
;
465 spin_unlock(&tx_info
->lock
);
468 /* initialize tid and atid to -1, 0 is a also a valid id. */
472 tx_info
->adap
= adap
;
473 tx_info
->netdev
= netdev
;
474 tx_info
->first_qset
= pi
->first_qset
;
475 tx_info
->tx_chan
= pi
->tx_chan
;
476 tx_info
->smt_idx
= pi
->smt_idx
;
477 tx_info
->port_id
= pi
->port_id
;
479 tx_info
->rx_qid
= chcr_get_first_rx_qid(adap
);
480 if (unlikely(tx_info
->rx_qid
< 0))
483 tx_info
->prev_seq
= start_offload_tcp_sn
;
484 tx_info
->tcp_start_seq_number
= start_offload_tcp_sn
;
486 /* save crypto keys */
487 ret
= chcr_ktls_save_keys(tx_info
, crypto_info
, direction
);
492 if (sk
->sk_family
== AF_INET
||
493 (sk
->sk_family
== AF_INET6
&& !sk
->sk_ipv6only
&&
494 ipv6_addr_type(&sk
->sk_v6_daddr
) == IPV6_ADDR_MAPPED
)) {
495 memcpy(daaddr
, &sk
->sk_daddr
, 4);
497 memcpy(daaddr
, sk
->sk_v6_daddr
.in6_u
.u6_addr8
, 16);
500 /* get the l2t index */
501 dst
= sk_dst_get(sk
);
503 pr_err("DST entry not found\n");
506 n
= dst_neigh_lookup(dst
, daaddr
);
508 pr_err("neighbour not found\n");
512 tx_info
->l2te
= cxgb4_l2t_get(adap
->l2t
, n
, n
->dev
, 0);
517 if (!tx_info
->l2te
) {
518 pr_err("l2t entry not found\n");
522 tx_ctx
->chcr_info
= tx_info
;
524 /* create a filter and call cxgb4_l2t_send to send the packet out, which
525 * will take care of updating l2t entry in hw if not already done.
527 ret
= chcr_setup_connection(sk
, tx_info
);
531 atomic64_inc(&adap
->chcr_stats
.ktls_tx_connection_open
);
536 atomic64_inc(&adap
->chcr_stats
.ktls_tx_connection_fail
);
540 static const struct tlsdev_ops chcr_ktls_ops
= {
541 .tls_dev_add
= chcr_ktls_dev_add
,
542 .tls_dev_del
= chcr_ktls_dev_del
,
546 * chcr_enable_ktls: add NETIF_F_HW_TLS_TX flag in all the ports.
548 void chcr_enable_ktls(struct adapter
*adap
)
550 struct net_device
*netdev
;
553 for_each_port(adap
, i
) {
554 netdev
= adap
->port
[i
];
555 netdev
->features
|= NETIF_F_HW_TLS_TX
;
556 netdev
->hw_features
|= NETIF_F_HW_TLS_TX
;
557 netdev
->tlsdev_ops
= &chcr_ktls_ops
;
562 * chcr_disable_ktls: remove NETIF_F_HW_TLS_TX flag from all the ports.
564 void chcr_disable_ktls(struct adapter
*adap
)
566 struct net_device
*netdev
;
569 for_each_port(adap
, i
) {
570 netdev
= adap
->port
[i
];
571 netdev
->features
&= ~NETIF_F_HW_TLS_TX
;
572 netdev
->hw_features
&= ~NETIF_F_HW_TLS_TX
;
573 netdev
->tlsdev_ops
= NULL
;
578 * chcr_init_tcb_fields: Initialize tcb fields to handle TCP seq number
580 * @tx_info - driver specific tls info.
581 * return: NET_TX_OK/NET_XMIT_DROP
583 static int chcr_init_tcb_fields(struct chcr_ktls_info
*tx_info
)
587 /* set tcb in offload and bypass */
589 chcr_set_tcb_field(tx_info
, TCB_T_FLAGS_W
,
590 TCB_T_FLAGS_V(TF_CORE_BYPASS_F
| TF_NON_OFFLOAD_F
),
591 TCB_T_FLAGS_V(TF_CORE_BYPASS_F
), 1);
594 /* reset snd_una and snd_next fields in tcb */
595 ret
= chcr_set_tcb_field(tx_info
, TCB_SND_UNA_RAW_W
,
596 TCB_SND_NXT_RAW_V(TCB_SND_NXT_RAW_M
) |
597 TCB_SND_UNA_RAW_V(TCB_SND_UNA_RAW_M
),
603 ret
= chcr_set_tcb_field(tx_info
, TCB_SND_MAX_RAW_W
,
604 TCB_SND_MAX_RAW_V(TCB_SND_MAX_RAW_M
),
609 /* update l2t index and request for tp reply to confirm tcb is
610 * initialised to handle tx traffic.
612 ret
= chcr_set_tcb_field(tx_info
, TCB_L2T_IX_W
,
613 TCB_L2T_IX_V(TCB_L2T_IX_M
),
614 TCB_L2T_IX_V(tx_info
->l2te
->idx
), 0);
619 * chcr_ktls_cpl_act_open_rpl: connection reply received from TP.
621 int chcr_ktls_cpl_act_open_rpl(struct adapter
*adap
, unsigned char *input
)
623 const struct cpl_act_open_rpl
*p
= (void *)input
;
624 struct chcr_ktls_info
*tx_info
= NULL
;
625 unsigned int atid
, tid
, status
;
629 status
= AOPEN_STATUS_G(ntohl(p
->atid_status
));
630 atid
= TID_TID_G(AOPEN_ATID_G(ntohl(p
->atid_status
)));
633 tx_info
= lookup_atid(t
, atid
);
635 if (!tx_info
|| tx_info
->atid
!= atid
) {
636 pr_err("tx_info or atid is not correct\n");
642 cxgb4_insert_tid(t
, tx_info
, tx_info
->tid
, tx_info
->ip_family
);
644 cxgb4_free_atid(t
, atid
);
646 /* update the connection state */
647 chcr_ktls_update_connection_state(tx_info
,
648 KTLS_CONN_ACT_OPEN_RPL
);
654 * chcr_ktls_cpl_set_tcb_rpl: TCB reply received from TP.
656 int chcr_ktls_cpl_set_tcb_rpl(struct adapter
*adap
, unsigned char *input
)
658 const struct cpl_set_tcb_rpl
*p
= (void *)input
;
659 struct chcr_ktls_info
*tx_info
= NULL
;
666 tx_info
= lookup_tid(t
, tid
);
667 if (!tx_info
|| tx_info
->tid
!= tid
) {
668 pr_err("tx_info or atid is not correct\n");
671 /* update the connection state */
672 chcr_ktls_update_connection_state(tx_info
, KTLS_CONN_SET_TCB_RPL
);
676 static void *__chcr_write_cpl_set_tcb_ulp(struct chcr_ktls_info
*tx_info
,
677 u32 tid
, void *pos
, u16 word
, u64 mask
,
680 struct cpl_set_tcb_field_core
*cpl
;
681 struct ulptx_idata
*idata
;
682 struct ulp_txpkt
*txpkt
;
686 txpkt
->cmd_dest
= htonl(ULPTX_CMD_V(ULP_TX_PKT
) | ULP_TXPKT_DEST_V(0));
687 txpkt
->len
= htonl(DIV_ROUND_UP(CHCR_SET_TCB_FIELD_LEN
, 16));
689 /* ULPTX_IDATA sub-command */
690 idata
= (struct ulptx_idata
*)(txpkt
+ 1);
691 idata
->cmd_more
= htonl(ULPTX_CMD_V(ULP_TX_SC_IMM
));
692 idata
->len
= htonl(sizeof(*cpl
));
696 /* CPL_SET_TCB_FIELD */
697 OPCODE_TID(cpl
) = htonl(MK_OPCODE_TID(CPL_SET_TCB_FIELD
, tid
));
698 cpl
->reply_ctrl
= htons(QUEUENO_V(tx_info
->rx_qid
) |
700 cpl
->word_cookie
= htons(TCB_WORD_V(word
));
701 cpl
->mask
= cpu_to_be64(mask
);
702 cpl
->val
= cpu_to_be64(val
);
705 idata
= (struct ulptx_idata
*)(cpl
+ 1);
706 idata
->cmd_more
= htonl(ULPTX_CMD_V(ULP_TX_SC_NOOP
));
707 idata
->len
= htonl(0);
715 * chcr_write_cpl_set_tcb_ulp: update tcb values.
716 * TCB is responsible to create tcp headers, so all the related values
717 * should be correctly updated.
718 * @tx_info - driver specific tls info.
719 * @q - tx queue on which packet is going out.
720 * @tid - TCB identifier.
721 * @pos - current index where should we start writing.
723 * @mask - TCB word related mask.
724 * @val - TCB word related value.
725 * @reply - set 1 if looking for TP response.
726 * return - next position to write.
728 static void *chcr_write_cpl_set_tcb_ulp(struct chcr_ktls_info
*tx_info
,
729 struct sge_eth_txq
*q
, u32 tid
,
730 void *pos
, u16 word
, u64 mask
,
733 int left
= (void *)q
->q
.stat
- pos
;
735 if (unlikely(left
< CHCR_SET_TCB_FIELD_LEN
)) {
741 __chcr_write_cpl_set_tcb_ulp(tx_info
, tid
, buf
, word
,
744 return chcr_copy_to_txd(buf
, &q
->q
, pos
,
745 CHCR_SET_TCB_FIELD_LEN
);
749 pos
= __chcr_write_cpl_set_tcb_ulp(tx_info
, tid
, pos
, word
,
752 /* check again if we are at the end of the queue */
753 if (left
== CHCR_SET_TCB_FIELD_LEN
)
760 * chcr_ktls_xmit_tcb_cpls: update tcb entry so that TP will create the header
761 * with updated values like tcp seq, ack, window etc.
762 * @tx_info - driver specific tls info.
767 * return: NETDEV_TX_BUSY/NET_TX_OK.
769 static int chcr_ktls_xmit_tcb_cpls(struct chcr_ktls_info
*tx_info
,
770 struct sge_eth_txq
*q
, u64 tcp_seq
,
771 u64 tcp_ack
, u64 tcp_win
)
773 bool first_wr
= ((tx_info
->prev_ack
== 0) && (tx_info
->prev_win
== 0));
774 u32 len
, cpl
= 0, ndesc
, wr_len
;
775 struct fw_ulptx_wr
*wr
;
779 wr_len
= sizeof(*wr
);
780 /* there can be max 4 cpls, check if we have enough credits */
781 len
= wr_len
+ 4 * roundup(CHCR_SET_TCB_FIELD_LEN
, 16);
782 ndesc
= DIV_ROUND_UP(len
, 64);
784 credits
= chcr_txq_avail(&q
->q
) - ndesc
;
785 if (unlikely(credits
< 0)) {
786 chcr_eth_txq_stop(q
);
787 return NETDEV_TX_BUSY
;
790 pos
= &q
->q
.desc
[q
->q
.pidx
];
791 /* make space for WR, we'll fill it later when we know all the cpls
792 * being sent out and have complete length.
796 /* update tx_max if its a re-transmit or the first wr */
797 if (first_wr
|| tcp_seq
!= tx_info
->prev_seq
) {
798 pos
= chcr_write_cpl_set_tcb_ulp(tx_info
, q
, tx_info
->tid
, pos
,
800 TCB_TX_MAX_V(TCB_TX_MAX_M
),
801 TCB_TX_MAX_V(tcp_seq
), 0);
804 /* reset snd una if it's a re-transmit pkt */
805 if (tcp_seq
!= tx_info
->prev_seq
) {
807 pos
= chcr_write_cpl_set_tcb_ulp(tx_info
, q
, tx_info
->tid
, pos
,
811 TCB_SND_UNA_RAW_V(0), 0);
812 atomic64_inc(&tx_info
->adap
->chcr_stats
.ktls_tx_ooo
);
816 if (first_wr
|| tx_info
->prev_ack
!= tcp_ack
) {
817 pos
= chcr_write_cpl_set_tcb_ulp(tx_info
, q
, tx_info
->tid
, pos
,
819 TCB_RCV_NXT_V(TCB_RCV_NXT_M
),
820 TCB_RCV_NXT_V(tcp_ack
), 0);
821 tx_info
->prev_ack
= tcp_ack
;
824 /* update receive window */
825 if (first_wr
|| tx_info
->prev_win
!= tcp_win
) {
826 pos
= chcr_write_cpl_set_tcb_ulp(tx_info
, q
, tx_info
->tid
, pos
,
828 TCB_RCV_WND_V(TCB_RCV_WND_M
),
829 TCB_RCV_WND_V(tcp_win
), 0);
830 tx_info
->prev_win
= tcp_win
;
835 /* get the actual length */
836 len
= wr_len
+ cpl
* roundup(CHCR_SET_TCB_FIELD_LEN
, 16);
838 wr
->op_to_compl
= htonl(FW_WR_OP_V(FW_ULPTX_WR
));
840 /* fill len in wr field */
841 wr
->flowid_len16
= htonl(FW_WR_LEN16_V(DIV_ROUND_UP(len
, 16)));
843 ndesc
= DIV_ROUND_UP(len
, 64);
844 chcr_txq_advance(&q
->q
, ndesc
);
845 cxgb4_ring_tx_db(tx_info
->adap
, &q
->q
, ndesc
);
852 * @nskb - new skb where the frags to be added.
853 * @skb - old skb from which frags will be copied.
855 static void chcr_ktls_skb_copy(struct sk_buff
*skb
, struct sk_buff
*nskb
)
859 for (i
= 0; i
< skb_shinfo(skb
)->nr_frags
; i
++) {
860 skb_shinfo(nskb
)->frags
[i
] = skb_shinfo(skb
)->frags
[i
];
861 __skb_frag_ref(&skb_shinfo(nskb
)->frags
[i
]);
864 skb_shinfo(nskb
)->nr_frags
= skb_shinfo(skb
)->nr_frags
;
865 nskb
->len
+= skb
->data_len
;
866 nskb
->data_len
= skb
->data_len
;
867 nskb
->truesize
+= skb
->data_len
;
871 * chcr_ktls_get_tx_flits
872 * returns number of flits to be sent out, it includes key context length, WR
873 * size and skb fragments.
876 chcr_ktls_get_tx_flits(const struct sk_buff
*skb
, unsigned int key_ctx_len
)
878 return chcr_sgl_len(skb_shinfo(skb
)->nr_frags
) +
879 DIV_ROUND_UP(key_ctx_len
+ CHCR_KTLS_WR_SIZE
, 8);
883 * chcr_ktls_check_tcp_options: To check if there is any TCP option availbale
884 * other than timestamp.
885 * @skb - skb contains partial record..
889 chcr_ktls_check_tcp_options(struct tcphdr
*tcp
)
891 int cnt
, opt
, optlen
;
894 cp
= (u_char
*)(tcp
+ 1);
895 cnt
= (tcp
->doff
<< 2) - sizeof(struct tcphdr
);
896 for (; cnt
> 0; cnt
-= optlen
, cp
+= optlen
) {
898 if (opt
== TCPOPT_EOL
)
900 if (opt
== TCPOPT_NOP
) {
906 if (optlen
< 2 || optlen
> cnt
)
920 * chcr_ktls_write_tcp_options : TP can't send out all the options, we need to
921 * send out separately.
922 * @tx_info - driver specific tls info.
923 * @skb - skb contains partial record..
925 * @tx_chan - channel number.
926 * return: NETDEV_TX_OK/NETDEV_TX_BUSY.
929 chcr_ktls_write_tcp_options(struct chcr_ktls_info
*tx_info
, struct sk_buff
*skb
,
930 struct sge_eth_txq
*q
, uint32_t tx_chan
)
932 struct fw_eth_tx_pkt_wr
*wr
;
933 struct cpl_tx_pkt_core
*cpl
;
934 u32 ctrl
, iplen
, maclen
;
944 iplen
= skb_network_header_len(skb
);
945 maclen
= skb_mac_header_len(skb
);
947 /* packet length = eth hdr len + ip hdr len + tcp hdr len
948 * (including options).
950 pktlen
= skb
->len
- skb
->data_len
;
952 ctrl
= sizeof(*cpl
) + pktlen
;
953 len16
= DIV_ROUND_UP(sizeof(*wr
) + ctrl
, 16);
954 /* check how many descriptors needed */
955 ndesc
= DIV_ROUND_UP(len16
, 4);
957 credits
= chcr_txq_avail(&q
->q
) - ndesc
;
958 if (unlikely(credits
< 0)) {
959 chcr_eth_txq_stop(q
);
960 return NETDEV_TX_BUSY
;
963 pos
= &q
->q
.desc
[q
->q
.pidx
];
966 /* Firmware work request header */
967 wr
->op_immdlen
= htonl(FW_WR_OP_V(FW_ETH_TX_PKT_WR
) |
968 FW_WR_IMMDLEN_V(ctrl
));
970 wr
->equiq_to_len16
= htonl(FW_WR_LEN16_V(len16
));
973 cpl
= (void *)(wr
+ 1);
976 cpl
->ctrl0
= htonl(TXPKT_OPCODE_V(CPL_TX_PKT
) | TXPKT_INTF_V(tx_chan
) |
977 TXPKT_PF_V(tx_info
->adap
->pf
));
979 cpl
->len
= htons(pktlen
);
980 /* checksum offload */
985 memcpy(buf
, skb
->data
, pktlen
);
986 if (tx_info
->ip_family
== AF_INET
) {
987 /* we need to correct ip header len */
988 ip
= (struct iphdr
*)(buf
+ maclen
);
989 ip
->tot_len
= htons(pktlen
- maclen
);
991 ip6
= (struct ipv6hdr
*)(buf
+ maclen
);
992 ip6
->payload_len
= htons(pktlen
- maclen
- iplen
);
994 /* now take care of the tcp header, if fin is not set then clear push
995 * bit as well, and if fin is set, it will be sent at the last so we
996 * need to update the tcp sequence number as per the last packet.
998 tcp
= (struct tcphdr
*)(buf
+ maclen
+ iplen
);
1003 tcp
->seq
= htonl(tx_info
->prev_seq
);
1005 chcr_copy_to_txd(buf
, &q
->q
, pos
, pktlen
);
1007 chcr_txq_advance(&q
->q
, ndesc
);
1008 cxgb4_ring_tx_db(tx_info
->adap
, &q
->q
, ndesc
);
1012 /* chcr_ktls_skb_shift - Shifts request length paged data from skb to another.
1013 * @tgt- buffer into which tail data gets added
1014 * @skb- buffer from which the paged data comes from
1015 * @shiftlen- shift up to this many bytes
1017 static int chcr_ktls_skb_shift(struct sk_buff
*tgt
, struct sk_buff
*skb
,
1020 skb_frag_t
*fragfrom
, *fragto
;
1023 WARN_ON(shiftlen
> skb
->data_len
);
1028 fragfrom
= &skb_shinfo(skb
)->frags
[from
];
1030 while ((todo
> 0) && (from
< skb_shinfo(skb
)->nr_frags
)) {
1031 fragfrom
= &skb_shinfo(skb
)->frags
[from
];
1032 fragto
= &skb_shinfo(tgt
)->frags
[to
];
1034 if (todo
>= skb_frag_size(fragfrom
)) {
1035 *fragto
= *fragfrom
;
1036 todo
-= skb_frag_size(fragfrom
);
1041 __skb_frag_ref(fragfrom
);
1042 skb_frag_page_copy(fragto
, fragfrom
);
1043 skb_frag_off_copy(fragto
, fragfrom
);
1044 skb_frag_size_set(fragto
, todo
);
1046 skb_frag_off_add(fragfrom
, todo
);
1047 skb_frag_size_sub(fragfrom
, todo
);
1055 /* Ready to "commit" this state change to tgt */
1056 skb_shinfo(tgt
)->nr_frags
= to
;
1058 /* Reposition in the original skb */
1060 while (from
< skb_shinfo(skb
)->nr_frags
)
1061 skb_shinfo(skb
)->frags
[to
++] = skb_shinfo(skb
)->frags
[from
++];
1063 skb_shinfo(skb
)->nr_frags
= to
;
1065 WARN_ON(todo
> 0 && !skb_shinfo(skb
)->nr_frags
);
1067 skb
->len
-= shiftlen
;
1068 skb
->data_len
-= shiftlen
;
1069 skb
->truesize
-= shiftlen
;
1070 tgt
->len
+= shiftlen
;
1071 tgt
->data_len
+= shiftlen
;
1072 tgt
->truesize
+= shiftlen
;
1078 * chcr_ktls_xmit_wr_complete: This sends out the complete record. If an skb
1079 * received has partial end part of the record, send out the complete record, so
1080 * that crypto block will be able to generate TAG/HASH.
1081 * @skb - segment which has complete or partial end part.
1082 * @tx_info - driver specific tls info.
1085 * @tcp_push - tcp push bit.
1086 * @mss - segment size.
1087 * return: NETDEV_TX_BUSY/NET_TX_OK.
1089 static int chcr_ktls_xmit_wr_complete(struct sk_buff
*skb
,
1090 struct chcr_ktls_info
*tx_info
,
1091 struct sge_eth_txq
*q
, u32 tcp_seq
,
1092 bool tcp_push
, u32 mss
)
1094 u32 len16
, wr_mid
= 0, flits
= 0, ndesc
, cipher_start
;
1095 struct adapter
*adap
= tx_info
->adap
;
1096 int credits
, left
, last_desc
;
1097 struct tx_sw_desc
*sgl_sdesc
;
1098 struct cpl_tx_data
*tx_data
;
1099 struct cpl_tx_sec_pdu
*cpl
;
1100 struct ulptx_idata
*idata
;
1101 struct ulp_txpkt
*ulptx
;
1102 struct fw_ulptx_wr
*wr
;
1106 /* get the number of flits required */
1107 flits
= chcr_ktls_get_tx_flits(skb
, tx_info
->key_ctx_len
);
1108 /* number of descriptors */
1109 ndesc
= chcr_flits_to_desc(flits
);
1110 /* check if enough credits available */
1111 credits
= chcr_txq_avail(&q
->q
) - ndesc
;
1112 if (unlikely(credits
< 0)) {
1113 chcr_eth_txq_stop(q
);
1114 return NETDEV_TX_BUSY
;
1117 if (unlikely(credits
< ETHTXQ_STOP_THRES
)) {
1118 /* Credits are below the threshold vaues, stop the queue after
1119 * injecting the Work Request for this packet.
1121 chcr_eth_txq_stop(q
);
1122 wr_mid
|= FW_WR_EQUEQ_F
| FW_WR_EQUIQ_F
;
1125 last_desc
= q
->q
.pidx
+ ndesc
- 1;
1126 if (last_desc
>= q
->q
.size
)
1127 last_desc
-= q
->q
.size
;
1128 sgl_sdesc
= &q
->q
.sdesc
[last_desc
];
1130 if (unlikely(cxgb4_map_skb(adap
->pdev_dev
, skb
, sgl_sdesc
->addr
) < 0)) {
1131 memset(sgl_sdesc
->addr
, 0, sizeof(sgl_sdesc
->addr
));
1133 return NETDEV_TX_BUSY
;
1136 pos
= &q
->q
.desc
[q
->q
.pidx
];
1137 end
= (u64
*)pos
+ flits
;
1140 /* WR will need len16 */
1141 len16
= DIV_ROUND_UP(flits
, 2);
1142 wr
->op_to_compl
= htonl(FW_WR_OP_V(FW_ULPTX_WR
));
1143 wr
->flowid_len16
= htonl(wr_mid
| FW_WR_LEN16_V(len16
));
1148 ulptx
->cmd_dest
= htonl(ULPTX_CMD_V(ULP_TX_PKT
) |
1149 ULP_TXPKT_CHANNELID_V(tx_info
->port_id
) |
1150 ULP_TXPKT_FID_V(q
->q
.cntxt_id
) |
1152 ulptx
->len
= htonl(len16
- 1);
1153 /* ULPTX_IDATA sub-command */
1154 idata
= (struct ulptx_idata
*)(ulptx
+ 1);
1155 idata
->cmd_more
= htonl(ULPTX_CMD_V(ULP_TX_SC_IMM
) | ULP_TX_SC_MORE_F
);
1156 /* idata length will include cpl_tx_sec_pdu + key context size +
1157 * cpl_tx_data header.
1159 idata
->len
= htonl(sizeof(*cpl
) + tx_info
->key_ctx_len
+
1162 cpl
= (struct cpl_tx_sec_pdu
*)(idata
+ 1);
1163 cpl
->op_ivinsrtofst
=
1164 htonl(CPL_TX_SEC_PDU_OPCODE_V(CPL_TX_SEC_PDU
) |
1165 CPL_TX_SEC_PDU_CPLLEN_V(CHCR_CPL_TX_SEC_PDU_LEN_64BIT
) |
1166 CPL_TX_SEC_PDU_PLACEHOLDER_V(1) |
1167 CPL_TX_SEC_PDU_IVINSRTOFST_V(TLS_HEADER_SIZE
+ 1));
1168 cpl
->pldlen
= htonl(skb
->data_len
);
1170 /* encryption should start after tls header size + iv size */
1171 cipher_start
= TLS_HEADER_SIZE
+ tx_info
->iv_size
+ 1;
1173 cpl
->aadstart_cipherstop_hi
=
1174 htonl(CPL_TX_SEC_PDU_AADSTART_V(1) |
1175 CPL_TX_SEC_PDU_AADSTOP_V(TLS_HEADER_SIZE
) |
1176 CPL_TX_SEC_PDU_CIPHERSTART_V(cipher_start
));
1178 /* authentication will also start after tls header + iv size */
1179 cpl
->cipherstop_lo_authinsert
=
1180 htonl(CPL_TX_SEC_PDU_AUTHSTART_V(cipher_start
) |
1181 CPL_TX_SEC_PDU_AUTHSTOP_V(TLS_CIPHER_AES_GCM_128_TAG_SIZE
) |
1182 CPL_TX_SEC_PDU_AUTHINSERT_V(TLS_CIPHER_AES_GCM_128_TAG_SIZE
));
1184 /* These two flits are actually a CPL_TLS_TX_SCMD_FMT. */
1185 cpl
->seqno_numivs
= htonl(tx_info
->scmd0_seqno_numivs
);
1186 cpl
->ivgen_hdrlen
= htonl(tx_info
->scmd0_ivgen_hdrlen
);
1187 cpl
->scmd1
= cpu_to_be64(tx_info
->record_no
);
1190 /* check if space left to fill the keys */
1191 left
= (void *)q
->q
.stat
- pos
;
1193 left
= (void *)end
- (void *)q
->q
.stat
;
1198 pos
= chcr_copy_to_txd(&tx_info
->key_ctx
, &q
->q
, pos
,
1199 tx_info
->key_ctx_len
);
1200 left
= (void *)q
->q
.stat
- pos
;
1203 left
= (void *)end
- (void *)q
->q
.stat
;
1208 tx_data
= (void *)pos
;
1209 OPCODE_TID(tx_data
) = htonl(MK_OPCODE_TID(CPL_TX_DATA
, tx_info
->tid
));
1210 tx_data
->len
= htonl(TX_DATA_MSS_V(mss
) | TX_LENGTH_V(skb
->data_len
));
1212 tx_data
->rsvd
= htonl(tcp_seq
);
1214 tx_data
->flags
= htonl(TX_BYPASS_F
);
1216 tx_data
->flags
|= htonl(TX_PUSH_F
| TX_SHOVE_F
);
1218 /* check left again, it might go beyond queue limit */
1220 left
= (void *)q
->q
.stat
- pos
;
1222 /* check the position again */
1224 left
= (void *)end
- (void *)q
->q
.stat
;
1229 /* send the complete packet except the header */
1230 cxgb4_write_sgl(skb
, &q
->q
, pos
, end
, skb
->len
- skb
->data_len
,
1232 sgl_sdesc
->skb
= skb
;
1234 chcr_txq_advance(&q
->q
, ndesc
);
1235 cxgb4_ring_tx_db(adap
, &q
->q
, ndesc
);
1236 atomic64_inc(&adap
->chcr_stats
.ktls_tx_send_records
);
1242 * chcr_ktls_xmit_wr_short: This is to send out partial records. If its
1243 * a middle part of a record, fetch the prior data to make it 16 byte aligned
1244 * and then only send it out.
1246 * @skb - skb contains partial record..
1247 * @tx_info - driver specific tls info.
1250 * @tcp_push - tcp push bit.
1251 * @mss - segment size.
1252 * @tls_rec_offset - offset from start of the tls record.
1253 * @perior_data - data before the current segment, required to make this record
1255 * @prior_data_len - prior_data length (less than 16)
1256 * return: NETDEV_TX_BUSY/NET_TX_OK.
1258 static int chcr_ktls_xmit_wr_short(struct sk_buff
*skb
,
1259 struct chcr_ktls_info
*tx_info
,
1260 struct sge_eth_txq
*q
,
1261 u32 tcp_seq
, bool tcp_push
, u32 mss
,
1262 u32 tls_rec_offset
, u8
*prior_data
,
1265 struct adapter
*adap
= tx_info
->adap
;
1266 u32 len16
, wr_mid
= 0, cipher_start
;
1267 unsigned int flits
= 0, ndesc
;
1268 int credits
, left
, last_desc
;
1269 struct tx_sw_desc
*sgl_sdesc
;
1270 struct cpl_tx_data
*tx_data
;
1271 struct cpl_tx_sec_pdu
*cpl
;
1272 struct ulptx_idata
*idata
;
1273 struct ulp_txpkt
*ulptx
;
1274 struct fw_ulptx_wr
*wr
;
1279 /* get the number of flits required, it's a partial record so 2 flits
1280 * (AES_BLOCK_SIZE) will be added.
1282 flits
= chcr_ktls_get_tx_flits(skb
, tx_info
->key_ctx_len
) + 2;
1283 /* get the correct 8 byte IV of this record */
1284 iv_record
= cpu_to_be64(tx_info
->iv
+ tx_info
->record_no
);
1285 /* If it's a middle record and not 16 byte aligned to run AES CTR, need
1286 * to make it 16 byte aligned. So atleadt 2 extra flits of immediate
1287 * data will be added.
1291 /* number of descriptors */
1292 ndesc
= chcr_flits_to_desc(flits
);
1293 /* check if enough credits available */
1294 credits
= chcr_txq_avail(&q
->q
) - ndesc
;
1295 if (unlikely(credits
< 0)) {
1296 chcr_eth_txq_stop(q
);
1297 return NETDEV_TX_BUSY
;
1300 if (unlikely(credits
< ETHTXQ_STOP_THRES
)) {
1301 chcr_eth_txq_stop(q
);
1302 wr_mid
|= FW_WR_EQUEQ_F
| FW_WR_EQUIQ_F
;
1305 last_desc
= q
->q
.pidx
+ ndesc
- 1;
1306 if (last_desc
>= q
->q
.size
)
1307 last_desc
-= q
->q
.size
;
1308 sgl_sdesc
= &q
->q
.sdesc
[last_desc
];
1310 if (unlikely(cxgb4_map_skb(adap
->pdev_dev
, skb
, sgl_sdesc
->addr
) < 0)) {
1311 memset(sgl_sdesc
->addr
, 0, sizeof(sgl_sdesc
->addr
));
1313 return NETDEV_TX_BUSY
;
1316 pos
= &q
->q
.desc
[q
->q
.pidx
];
1317 end
= (u64
*)pos
+ flits
;
1320 /* WR will need len16 */
1321 len16
= DIV_ROUND_UP(flits
, 2);
1322 wr
->op_to_compl
= htonl(FW_WR_OP_V(FW_ULPTX_WR
));
1323 wr
->flowid_len16
= htonl(wr_mid
| FW_WR_LEN16_V(len16
));
1328 ulptx
->cmd_dest
= htonl(ULPTX_CMD_V(ULP_TX_PKT
) |
1329 ULP_TXPKT_CHANNELID_V(tx_info
->port_id
) |
1330 ULP_TXPKT_FID_V(q
->q
.cntxt_id
) |
1332 ulptx
->len
= htonl(len16
- 1);
1333 /* ULPTX_IDATA sub-command */
1334 idata
= (struct ulptx_idata
*)(ulptx
+ 1);
1335 idata
->cmd_more
= htonl(ULPTX_CMD_V(ULP_TX_SC_IMM
) | ULP_TX_SC_MORE_F
);
1336 /* idata length will include cpl_tx_sec_pdu + key context size +
1337 * cpl_tx_data header.
1339 idata
->len
= htonl(sizeof(*cpl
) + tx_info
->key_ctx_len
+
1340 sizeof(*tx_data
) + AES_BLOCK_LEN
+ prior_data_len
);
1342 cpl
= (struct cpl_tx_sec_pdu
*)(idata
+ 1);
1343 /* cipher start will have tls header + iv size extra if its a header
1344 * part of tls record. else only 16 byte IV will be added.
1348 (!tls_rec_offset
? TLS_HEADER_SIZE
+ tx_info
->iv_size
: 0);
1350 cpl
->op_ivinsrtofst
=
1351 htonl(CPL_TX_SEC_PDU_OPCODE_V(CPL_TX_SEC_PDU
) |
1352 CPL_TX_SEC_PDU_CPLLEN_V(CHCR_CPL_TX_SEC_PDU_LEN_64BIT
) |
1353 CPL_TX_SEC_PDU_IVINSRTOFST_V(1));
1354 cpl
->pldlen
= htonl(skb
->data_len
+ AES_BLOCK_LEN
+ prior_data_len
);
1355 cpl
->aadstart_cipherstop_hi
=
1356 htonl(CPL_TX_SEC_PDU_CIPHERSTART_V(cipher_start
));
1357 cpl
->cipherstop_lo_authinsert
= 0;
1358 /* These two flits are actually a CPL_TLS_TX_SCMD_FMT. */
1359 cpl
->seqno_numivs
= htonl(tx_info
->scmd0_short_seqno_numivs
);
1360 cpl
->ivgen_hdrlen
= htonl(tx_info
->scmd0_short_ivgen_hdrlen
);
1364 /* check if space left to fill the keys */
1365 left
= (void *)q
->q
.stat
- pos
;
1367 left
= (void *)end
- (void *)q
->q
.stat
;
1372 pos
= chcr_copy_to_txd(&tx_info
->key_ctx
, &q
->q
, pos
,
1373 tx_info
->key_ctx_len
);
1374 left
= (void *)q
->q
.stat
- pos
;
1377 left
= (void *)end
- (void *)q
->q
.stat
;
1382 tx_data
= (void *)pos
;
1383 OPCODE_TID(tx_data
) = htonl(MK_OPCODE_TID(CPL_TX_DATA
, tx_info
->tid
));
1384 tx_data
->len
= htonl(TX_DATA_MSS_V(mss
) |
1385 TX_LENGTH_V(skb
->data_len
+ prior_data_len
));
1386 tx_data
->rsvd
= htonl(tcp_seq
);
1387 tx_data
->flags
= htonl(TX_BYPASS_F
);
1389 tx_data
->flags
|= htonl(TX_PUSH_F
| TX_SHOVE_F
);
1391 /* check left again, it might go beyond queue limit */
1393 left
= (void *)q
->q
.stat
- pos
;
1395 /* check the position again */
1397 left
= (void *)end
- (void *)q
->q
.stat
;
1401 /* copy the 16 byte IV for AES-CTR, which includes 4 bytes of salt, 8
1402 * bytes of actual IV and 4 bytes of 16 byte-sequence.
1404 memcpy(pos
, tx_info
->key_ctx
.salt
, tx_info
->salt_size
);
1405 memcpy(pos
+ tx_info
->salt_size
, &iv_record
, tx_info
->iv_size
);
1406 *(__be32
*)(pos
+ tx_info
->salt_size
+ tx_info
->iv_size
) =
1407 htonl(2 + (tls_rec_offset
? ((tls_rec_offset
-
1408 (TLS_HEADER_SIZE
+ tx_info
->iv_size
)) / AES_BLOCK_LEN
) : 0));
1411 /* Prior_data_len will always be less than 16 bytes, fill the
1412 * prio_data_len after AES_CTRL_BLOCK and clear the remaining length
1416 pos
= chcr_copy_to_txd(prior_data
, &q
->q
, pos
, 16);
1417 /* send the complete packet except the header */
1418 cxgb4_write_sgl(skb
, &q
->q
, pos
, end
, skb
->len
- skb
->data_len
,
1420 sgl_sdesc
->skb
= skb
;
1422 chcr_txq_advance(&q
->q
, ndesc
);
1423 cxgb4_ring_tx_db(adap
, &q
->q
, ndesc
);
1429 * chcr_ktls_tx_plaintxt: This handler will take care of the records which has
1430 * only plain text (only tls header and iv)
1431 * @tx_info - driver specific tls info.
1432 * @skb - skb contains partial record..
1434 * @mss - segment size.
1435 * @tcp_push - tcp push bit.
1437 * @port_id : port number
1438 * @perior_data - data before the current segment, required to make this record
1440 * @prior_data_len - prior_data length (less than 16)
1441 * return: NETDEV_TX_BUSY/NET_TX_OK.
1443 static int chcr_ktls_tx_plaintxt(struct chcr_ktls_info
*tx_info
,
1444 struct sk_buff
*skb
, u32 tcp_seq
, u32 mss
,
1445 bool tcp_push
, struct sge_eth_txq
*q
,
1446 u32 port_id
, u8
*prior_data
,
1449 int credits
, left
, len16
, last_desc
;
1450 unsigned int flits
= 0, ndesc
;
1451 struct tx_sw_desc
*sgl_sdesc
;
1452 struct cpl_tx_data
*tx_data
;
1453 struct ulptx_idata
*idata
;
1454 struct ulp_txpkt
*ulptx
;
1455 struct fw_ulptx_wr
*wr
;
1460 flits
= DIV_ROUND_UP(CHCR_PLAIN_TX_DATA_LEN
, 8);
1461 flits
+= chcr_sgl_len(skb_shinfo(skb
)->nr_frags
);
1464 /* WR will need len16 */
1465 len16
= DIV_ROUND_UP(flits
, 2);
1466 /* check how many descriptors needed */
1467 ndesc
= DIV_ROUND_UP(flits
, 8);
1469 credits
= chcr_txq_avail(&q
->q
) - ndesc
;
1470 if (unlikely(credits
< 0)) {
1471 chcr_eth_txq_stop(q
);
1472 return NETDEV_TX_BUSY
;
1475 if (unlikely(credits
< ETHTXQ_STOP_THRES
)) {
1476 chcr_eth_txq_stop(q
);
1477 wr_mid
|= FW_WR_EQUEQ_F
| FW_WR_EQUIQ_F
;
1480 last_desc
= q
->q
.pidx
+ ndesc
- 1;
1481 if (last_desc
>= q
->q
.size
)
1482 last_desc
-= q
->q
.size
;
1483 sgl_sdesc
= &q
->q
.sdesc
[last_desc
];
1485 if (unlikely(cxgb4_map_skb(tx_info
->adap
->pdev_dev
, skb
,
1486 sgl_sdesc
->addr
) < 0)) {
1487 memset(sgl_sdesc
->addr
, 0, sizeof(sgl_sdesc
->addr
));
1489 return NETDEV_TX_BUSY
;
1492 pos
= &q
->q
.desc
[q
->q
.pidx
];
1493 end
= (u64
*)pos
+ flits
;
1496 wr
->op_to_compl
= htonl(FW_WR_OP_V(FW_ULPTX_WR
));
1497 wr
->flowid_len16
= htonl(wr_mid
| FW_WR_LEN16_V(len16
));
1501 ulptx
= (struct ulp_txpkt
*)(wr
+ 1);
1502 ulptx
->cmd_dest
= htonl(ULPTX_CMD_V(ULP_TX_PKT
) |
1503 ULP_TXPKT_DATAMODIFY_V(0) |
1504 ULP_TXPKT_CHANNELID_V(tx_info
->port_id
) |
1505 ULP_TXPKT_DEST_V(0) |
1506 ULP_TXPKT_FID_V(q
->q
.cntxt_id
) | ULP_TXPKT_RO_V(1));
1507 ulptx
->len
= htonl(len16
- 1);
1508 /* ULPTX_IDATA sub-command */
1509 idata
= (struct ulptx_idata
*)(ulptx
+ 1);
1510 idata
->cmd_more
= htonl(ULPTX_CMD_V(ULP_TX_SC_IMM
) | ULP_TX_SC_MORE_F
);
1511 idata
->len
= htonl(sizeof(*tx_data
) + prior_data_len
);
1513 tx_data
= (struct cpl_tx_data
*)(idata
+ 1);
1514 OPCODE_TID(tx_data
) = htonl(MK_OPCODE_TID(CPL_TX_DATA
, tx_info
->tid
));
1515 tx_data
->len
= htonl(TX_DATA_MSS_V(mss
) |
1516 TX_LENGTH_V(skb
->data_len
+ prior_data_len
));
1517 /* set tcp seq number */
1518 tx_data
->rsvd
= htonl(tcp_seq
);
1519 tx_data
->flags
= htonl(TX_BYPASS_F
);
1521 tx_data
->flags
|= htonl(TX_PUSH_F
| TX_SHOVE_F
);
1524 /* apart from prior_data_len, we should set remaining part of 16 bytes
1528 pos
= chcr_copy_to_txd(prior_data
, &q
->q
, pos
, 16);
1530 /* check left again, it might go beyond queue limit */
1531 left
= (void *)q
->q
.stat
- pos
;
1533 /* check the position again */
1535 left
= (void *)end
- (void *)q
->q
.stat
;
1539 /* send the complete packet including the header */
1540 cxgb4_write_sgl(skb
, &q
->q
, pos
, end
, skb
->len
- skb
->data_len
,
1542 sgl_sdesc
->skb
= skb
;
1544 chcr_txq_advance(&q
->q
, ndesc
);
1545 cxgb4_ring_tx_db(tx_info
->adap
, &q
->q
, ndesc
);
1550 * chcr_ktls_copy_record_in_skb
1551 * @nskb - new skb where the frags to be added.
1552 * @record - specific record which has complete 16k record in frags.
1554 static void chcr_ktls_copy_record_in_skb(struct sk_buff
*nskb
,
1555 struct tls_record_info
*record
)
1559 for (i
= 0; i
< record
->num_frags
; i
++) {
1560 skb_shinfo(nskb
)->frags
[i
] = record
->frags
[i
];
1561 /* increase the frag ref count */
1562 __skb_frag_ref(&skb_shinfo(nskb
)->frags
[i
]);
1565 skb_shinfo(nskb
)->nr_frags
= record
->num_frags
;
1566 nskb
->data_len
= record
->len
;
1567 nskb
->len
+= record
->len
;
1568 nskb
->truesize
+= record
->len
;
1572 * chcr_ktls_update_snd_una: Reset the SEND_UNA. It will be done to avoid
1573 * sending the same segment again. It will discard the segment which is before
1574 * the current tx max.
1575 * @tx_info - driver specific tls info.
1577 * return: NET_TX_OK/NET_XMIT_DROP.
1579 static int chcr_ktls_update_snd_una(struct chcr_ktls_info
*tx_info
,
1580 struct sge_eth_txq
*q
)
1582 struct fw_ulptx_wr
*wr
;
1588 len
= sizeof(*wr
) + roundup(CHCR_SET_TCB_FIELD_LEN
, 16);
1589 ndesc
= DIV_ROUND_UP(len
, 64);
1591 credits
= chcr_txq_avail(&q
->q
) - ndesc
;
1592 if (unlikely(credits
< 0)) {
1593 chcr_eth_txq_stop(q
);
1594 return NETDEV_TX_BUSY
;
1597 pos
= &q
->q
.desc
[q
->q
.pidx
];
1601 wr
->op_to_compl
= htonl(FW_WR_OP_V(FW_ULPTX_WR
));
1603 /* fill len in wr field */
1604 wr
->flowid_len16
= htonl(FW_WR_LEN16_V(DIV_ROUND_UP(len
, 16)));
1608 pos
= chcr_write_cpl_set_tcb_ulp(tx_info
, q
, tx_info
->tid
, pos
,
1610 TCB_SND_UNA_RAW_V(TCB_SND_UNA_RAW_M
),
1611 TCB_SND_UNA_RAW_V(0), 0);
1613 chcr_txq_advance(&q
->q
, ndesc
);
1614 cxgb4_ring_tx_db(tx_info
->adap
, &q
->q
, ndesc
);
1620 * chcr_end_part_handler: This handler will handle the record which
1621 * is complete or if record's end part is received. T6 adapter has a issue that
1622 * it can't send out TAG with partial record so if its an end part then we have
1623 * to send TAG as well and for which we need to fetch the complete record and
1624 * send it to crypto module.
1625 * @tx_info - driver specific tls info.
1626 * @skb - skb contains partial record.
1627 * @record - complete record of 16K size.
1629 * @mss - segment size in which TP needs to chop a packet.
1630 * @tcp_push_no_fin - tcp push if fin is not set.
1632 * @tls_end_offset - offset from end of the record.
1633 * @last wr : check if this is the last part of the skb going out.
1634 * return: NETDEV_TX_OK/NETDEV_TX_BUSY.
1636 static int chcr_end_part_handler(struct chcr_ktls_info
*tx_info
,
1637 struct sk_buff
*skb
,
1638 struct tls_record_info
*record
,
1639 u32 tcp_seq
, int mss
, bool tcp_push_no_fin
,
1640 struct sge_eth_txq
*q
,
1641 u32 tls_end_offset
, bool last_wr
)
1643 struct sk_buff
*nskb
= NULL
;
1644 /* check if it is a complete record */
1645 if (tls_end_offset
== record
->len
) {
1647 atomic64_inc(&tx_info
->adap
->chcr_stats
.ktls_tx_complete_pkts
);
1649 dev_kfree_skb_any(skb
);
1651 nskb
= alloc_skb(0, GFP_KERNEL
);
1653 return NETDEV_TX_BUSY
;
1654 /* copy complete record in skb */
1655 chcr_ktls_copy_record_in_skb(nskb
, record
);
1656 /* packet is being sent from the beginning, update the tcp_seq
1659 tcp_seq
= tls_record_start_seq(record
);
1660 /* reset snd una, so the middle record won't send the already
1663 if (chcr_ktls_update_snd_una(tx_info
, q
))
1665 atomic64_inc(&tx_info
->adap
->chcr_stats
.ktls_tx_end_pkts
);
1668 if (chcr_ktls_xmit_wr_complete(nskb
, tx_info
, q
, tcp_seq
,
1669 (last_wr
&& tcp_push_no_fin
),
1675 dev_kfree_skb_any(nskb
);
1676 return NETDEV_TX_BUSY
;
1680 * chcr_short_record_handler: This handler will take care of the records which
1681 * doesn't have end part (1st part or the middle part(/s) of a record). In such
1682 * cases, AES CTR will be used in place of AES GCM to send out partial packet.
1683 * This partial record might be the first part of the record, or the middle
1684 * part. In case of middle record we should fetch the prior data to make it 16
1685 * byte aligned. If it has a partial tls header or iv then get to the start of
1686 * tls header. And if it has partial TAG, then remove the complete TAG and send
1688 * There is one more possibility that it gets a partial header, send that
1689 * portion as a plaintext.
1690 * @tx_info - driver specific tls info.
1691 * @skb - skb contains partial record..
1692 * @record - complete record of 16K size.
1694 * @mss - segment size in which TP needs to chop a packet.
1695 * @tcp_push_no_fin - tcp push if fin is not set.
1697 * @tls_end_offset - offset from end of the record.
1698 * return: NETDEV_TX_OK/NETDEV_TX_BUSY.
1700 static int chcr_short_record_handler(struct chcr_ktls_info
*tx_info
,
1701 struct sk_buff
*skb
,
1702 struct tls_record_info
*record
,
1703 u32 tcp_seq
, int mss
, bool tcp_push_no_fin
,
1704 struct sge_eth_txq
*q
, u32 tls_end_offset
)
1706 u32 tls_rec_offset
= tcp_seq
- tls_record_start_seq(record
);
1707 u8 prior_data
[16] = {0};
1708 u32 prior_data_len
= 0;
1711 /* check if the skb is ending in middle of tag/HASH, its a big
1712 * trouble, send the packet before the HASH.
1714 int remaining_record
= tls_end_offset
- skb
->data_len
;
1716 if (remaining_record
> 0 &&
1717 remaining_record
< TLS_CIPHER_AES_GCM_128_TAG_SIZE
) {
1718 int trimmed_len
= skb
->data_len
-
1719 (TLS_CIPHER_AES_GCM_128_TAG_SIZE
- remaining_record
);
1720 struct sk_buff
*tmp_skb
= NULL
;
1721 /* don't process the pkt if it is only a partial tag */
1722 if (skb
->data_len
< TLS_CIPHER_AES_GCM_128_TAG_SIZE
)
1725 WARN_ON(trimmed_len
> skb
->data_len
);
1727 /* shift to those many bytes */
1728 tmp_skb
= alloc_skb(0, GFP_KERNEL
);
1729 if (unlikely(!tmp_skb
))
1732 chcr_ktls_skb_shift(tmp_skb
, skb
, trimmed_len
);
1733 /* free the last trimmed portion */
1734 dev_kfree_skb_any(skb
);
1736 atomic64_inc(&tx_info
->adap
->chcr_stats
.ktls_tx_trimmed_pkts
);
1738 data_len
= skb
->data_len
;
1739 /* check if the middle record's start point is 16 byte aligned. CTR
1740 * needs 16 byte aligned start point to start encryption.
1742 if (tls_rec_offset
) {
1743 /* there is an offset from start, means its a middle record */
1746 if (tls_rec_offset
< (TLS_HEADER_SIZE
+ tx_info
->iv_size
)) {
1747 prior_data_len
= tls_rec_offset
;
1753 (TLS_HEADER_SIZE
+ tx_info
->iv_size
))
1755 remaining
= tls_rec_offset
- prior_data_len
;
1758 /* if prior_data_len is not zero, means we need to fetch prior
1759 * data to make this record 16 byte aligned, or we need to reach
1762 if (prior_data_len
) {
1767 int frag_size
= 0, frag_delta
= 0;
1769 while (remaining
> 0) {
1770 frag_size
= skb_frag_size(&record
->frags
[i
]);
1771 if (remaining
< frag_size
)
1774 remaining
-= frag_size
;
1777 f
= &record
->frags
[i
];
1778 vaddr
= kmap_atomic(skb_frag_page(f
));
1780 data
= vaddr
+ skb_frag_off(f
) + remaining
;
1781 frag_delta
= skb_frag_size(f
) - remaining
;
1783 if (frag_delta
>= prior_data_len
) {
1784 memcpy(prior_data
, data
, prior_data_len
);
1785 kunmap_atomic(vaddr
);
1787 memcpy(prior_data
, data
, frag_delta
);
1788 kunmap_atomic(vaddr
);
1789 /* get the next page */
1790 f
= &record
->frags
[i
+ 1];
1791 vaddr
= kmap_atomic(skb_frag_page(f
));
1792 data
= vaddr
+ skb_frag_off(f
);
1793 memcpy(prior_data
+ frag_delta
,
1794 data
, (prior_data_len
- frag_delta
));
1795 kunmap_atomic(vaddr
);
1797 /* reset tcp_seq as per the prior_data_required len */
1798 tcp_seq
-= prior_data_len
;
1799 /* include prio_data_len for further calculation.
1801 data_len
+= prior_data_len
;
1803 /* reset snd una, so the middle record won't send the already
1806 if (chcr_ktls_update_snd_una(tx_info
, q
))
1808 atomic64_inc(&tx_info
->adap
->chcr_stats
.ktls_tx_middle_pkts
);
1810 /* Else means, its a partial first part of the record. Check if
1811 * its only the header, don't need to send for encryption then.
1813 if (data_len
<= TLS_HEADER_SIZE
+ tx_info
->iv_size
) {
1814 if (chcr_ktls_tx_plaintxt(tx_info
, skb
, tcp_seq
, mss
,
1823 atomic64_inc(&tx_info
->adap
->chcr_stats
.ktls_tx_start_pkts
);
1826 if (chcr_ktls_xmit_wr_short(skb
, tx_info
, q
, tcp_seq
, tcp_push_no_fin
,
1827 mss
, tls_rec_offset
, prior_data
,
1834 dev_kfree_skb_any(skb
);
1835 return NETDEV_TX_BUSY
;
1838 /* nic tls TX handler */
1839 int chcr_ktls_xmit(struct sk_buff
*skb
, struct net_device
*dev
)
1841 struct chcr_ktls_ofld_ctx_tx
*tx_ctx
;
1842 struct tcphdr
*th
= tcp_hdr(skb
);
1843 int data_len
, qidx
, ret
= 0, mss
;
1844 struct tls_record_info
*record
;
1845 struct chcr_stats_debug
*stats
;
1846 struct chcr_ktls_info
*tx_info
;
1847 u32 tls_end_offset
, tcp_seq
;
1848 struct tls_context
*tls_ctx
;
1849 struct sk_buff
*local_skb
;
1850 int new_connection_state
;
1851 struct sge_eth_txq
*q
;
1852 struct adapter
*adap
;
1853 unsigned long flags
;
1855 tcp_seq
= ntohl(th
->seq
);
1857 mss
= skb_is_gso(skb
) ? skb_shinfo(skb
)->gso_size
: skb
->data_len
;
1859 /* check if we haven't set it for ktls offload */
1860 if (!skb
->sk
|| !tls_is_sk_tx_device_offloaded(skb
->sk
))
1863 tls_ctx
= tls_get_ctx(skb
->sk
);
1864 if (unlikely(tls_ctx
->netdev
!= dev
))
1867 tx_ctx
= chcr_get_ktls_tx_context(tls_ctx
);
1868 tx_info
= tx_ctx
->chcr_info
;
1870 if (unlikely(!tx_info
))
1873 /* check the connection state, we don't need to pass new connection
1874 * state, state machine will check and update the new state if it is
1875 * stuck due to responses not received from HW.
1876 * Start the tx handling only if state is KTLS_CONN_TX_READY.
1878 new_connection_state
= chcr_ktls_update_connection_state(tx_info
, 0);
1879 if (new_connection_state
!= KTLS_CONN_TX_READY
)
1882 /* don't touch the original skb, make a new skb to extract each records
1883 * and send them separately.
1885 local_skb
= alloc_skb(0, GFP_KERNEL
);
1887 if (unlikely(!local_skb
))
1888 return NETDEV_TX_BUSY
;
1890 adap
= tx_info
->adap
;
1891 stats
= &adap
->chcr_stats
;
1893 qidx
= skb
->queue_mapping
;
1894 q
= &adap
->sge
.ethtxq
[qidx
+ tx_info
->first_qset
];
1895 cxgb4_reclaim_completed_tx(adap
, &q
->q
, true);
1896 /* if tcp options are set but finish is not send the options first */
1897 if (!th
->fin
&& chcr_ktls_check_tcp_options(th
)) {
1898 ret
= chcr_ktls_write_tcp_options(tx_info
, skb
, q
,
1901 return NETDEV_TX_BUSY
;
1904 ret
= chcr_ktls_xmit_tcb_cpls(tx_info
, q
, ntohl(th
->seq
),
1908 dev_kfree_skb_any(local_skb
);
1909 return NETDEV_TX_BUSY
;
1912 /* copy skb contents into local skb */
1913 chcr_ktls_skb_copy(skb
, local_skb
);
1915 /* go through the skb and send only one record at a time. */
1916 data_len
= skb
->data_len
;
1917 /* TCP segments can be in received either complete or partial.
1918 * chcr_end_part_handler will handle cases if complete record or end
1919 * part of the record is received. Incase of partial end part of record,
1920 * we will send the complete record again.
1926 cxgb4_reclaim_completed_tx(adap
, &q
->q
, true);
1928 spin_lock_irqsave(&tx_ctx
->base
.lock
, flags
);
1929 /* fetch the tls record */
1930 record
= tls_get_record(&tx_ctx
->base
, tcp_seq
,
1931 &tx_info
->record_no
);
1932 /* By the time packet reached to us, ACK is received, and record
1933 * won't be found in that case, handle it gracefully.
1935 if (unlikely(!record
)) {
1936 spin_unlock_irqrestore(&tx_ctx
->base
.lock
, flags
);
1937 atomic64_inc(&stats
->ktls_tx_drop_no_sync_data
);
1941 if (unlikely(tls_record_is_start_marker(record
))) {
1942 spin_unlock_irqrestore(&tx_ctx
->base
.lock
, flags
);
1943 atomic64_inc(&stats
->ktls_tx_skip_no_sync_data
);
1947 /* increase page reference count of the record, so that there
1948 * won't be any chance of page free in middle if in case stack
1949 * receives ACK and try to delete the record.
1951 for (i
= 0; i
< record
->num_frags
; i
++)
1952 __skb_frag_ref(&record
->frags
[i
]);
1954 spin_unlock_irqrestore(&tx_ctx
->base
.lock
, flags
);
1956 tls_end_offset
= record
->end_seq
- tcp_seq
;
1958 pr_debug("seq 0x%x, end_seq 0x%x prev_seq 0x%x, datalen 0x%x\n",
1959 tcp_seq
, record
->end_seq
, tx_info
->prev_seq
, data_len
);
1960 /* if a tls record is finishing in this SKB */
1961 if (tls_end_offset
<= data_len
) {
1962 struct sk_buff
*nskb
= NULL
;
1964 if (tls_end_offset
< data_len
) {
1965 nskb
= alloc_skb(0, GFP_KERNEL
);
1966 if (unlikely(!nskb
)) {
1971 chcr_ktls_skb_shift(nskb
, local_skb
,
1974 /* its the only record in this skb, directly
1979 ret
= chcr_end_part_handler(tx_info
, nskb
, record
,
1981 (!th
->fin
&& th
->psh
), q
,
1983 (nskb
== local_skb
));
1985 if (ret
&& nskb
!= local_skb
)
1986 dev_kfree_skb_any(local_skb
);
1988 data_len
-= tls_end_offset
;
1989 /* tcp_seq increment is required to handle next record.
1991 tcp_seq
+= tls_end_offset
;
1993 ret
= chcr_short_record_handler(tx_info
, local_skb
,
1994 record
, tcp_seq
, mss
,
1995 (!th
->fin
&& th
->psh
),
2000 /* clear the frag ref count which increased locally before */
2001 for (i
= 0; i
< record
->num_frags
; i
++) {
2002 /* clear the frag ref count */
2003 __skb_frag_unref(&record
->frags
[i
]);
2005 /* if any failure, come out from the loop. */
2008 /* length should never be less than 0 */
2009 WARN_ON(data_len
< 0);
2011 } while (data_len
> 0);
2013 tx_info
->prev_seq
= ntohl(th
->seq
) + skb
->data_len
;
2015 atomic64_inc(&stats
->ktls_tx_encrypted_packets
);
2016 atomic64_add(skb
->data_len
, &stats
->ktls_tx_encrypted_bytes
);
2018 /* tcp finish is set, send a separate tcp msg including all the options
2022 chcr_ktls_write_tcp_options(tx_info
, skb
, q
, tx_info
->tx_chan
);
2025 dev_kfree_skb_any(skb
);
2026 return NETDEV_TX_OK
;
2028 #endif /* CONFIG_CHELSIO_TLS_DEVICE */