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
,
125 /* This function can be called from both rx (interrupt context) and tx
128 spin_lock_irqsave(&tx_info
->lock
, flags
);
129 switch (tx_info
->connection_state
) {
130 case KTLS_CONN_CLOSED
:
131 tx_info
->connection_state
= new_state
;
134 case KTLS_CONN_ACT_OPEN_REQ
:
135 /* only go forward if state is greater than current state. */
136 if (new_state
<= tx_info
->connection_state
)
138 /* update to the next state and also initialize TCB */
139 tx_info
->connection_state
= new_state
;
141 case KTLS_CONN_ACT_OPEN_RPL
:
142 /* if we are stuck in this state, means tcb init might not
143 * received by HW, try sending it again.
145 if (!chcr_init_tcb_fields(tx_info
))
146 tx_info
->connection_state
= KTLS_CONN_SET_TCB_REQ
;
149 case KTLS_CONN_SET_TCB_REQ
:
150 /* only go forward if state is greater than current state. */
151 if (new_state
<= tx_info
->connection_state
)
153 /* update to the next state and check if l2t_state is valid */
154 tx_info
->connection_state
= new_state
;
156 case KTLS_CONN_SET_TCB_RPL
:
157 /* Check if l2t state is valid, then move to ready state. */
158 if (cxgb4_check_l2t_valid(tx_info
->l2te
)) {
159 tx_info
->connection_state
= KTLS_CONN_TX_READY
;
160 atomic64_inc(&tx_info
->adap
->chcr_stats
.ktls_tx_ctx
);
164 case KTLS_CONN_TX_READY
:
165 /* nothing to be done here */
169 pr_err("unknown KTLS connection state\n");
172 spin_unlock_irqrestore(&tx_info
->lock
, flags
);
174 return tx_info
->connection_state
;
177 * chcr_ktls_act_open_req: creates TCB entry for ipv4 connection.
179 * @tx_info - driver specific tls info.
180 * @atid - connection active tid.
181 * return - send success/failure.
183 static int chcr_ktls_act_open_req(struct sock
*sk
,
184 struct chcr_ktls_info
*tx_info
,
187 struct inet_sock
*inet
= inet_sk(sk
);
188 struct cpl_t6_act_open_req
*cpl6
;
189 struct cpl_act_open_req
*cpl
;
196 skb
= alloc_skb(len
, GFP_KERNEL
);
199 /* mark it a control pkt */
200 set_wr_txq(skb
, CPL_PRIORITY_CONTROL
, tx_info
->port_id
);
202 cpl6
= __skb_put_zero(skb
, len
);
203 cpl
= (struct cpl_act_open_req
*)cpl6
;
205 qid_atid
= TID_QID_V(tx_info
->rx_qid
) |
207 OPCODE_TID(cpl
) = htonl(MK_OPCODE_TID(CPL_ACT_OPEN_REQ
, qid_atid
));
208 cpl
->local_port
= inet
->inet_sport
;
209 cpl
->peer_port
= inet
->inet_dport
;
210 cpl
->local_ip
= inet
->inet_rcv_saddr
;
211 cpl
->peer_ip
= inet
->inet_daddr
;
213 /* fill first 64 bit option field. */
214 options
= TCAM_BYPASS_F
| ULP_MODE_V(ULP_MODE_NONE
) | NON_OFFLOAD_F
|
215 SMAC_SEL_V(tx_info
->smt_idx
) | TX_CHAN_V(tx_info
->tx_chan
);
216 cpl
->opt0
= cpu_to_be64(options
);
218 /* next 64 bit option field. */
220 TX_QUEUE_V(tx_info
->adap
->params
.tp
.tx_modq
[tx_info
->tx_chan
]);
221 cpl
->opt2
= htonl(options
);
223 return cxgb4_l2t_send(tx_info
->netdev
, skb
, tx_info
->l2te
);
227 * chcr_ktls_act_open_req6: creates TCB entry for ipv6 connection.
229 * @tx_info - driver specific tls info.
230 * @atid - connection active tid.
231 * return - send success/failure.
233 static int chcr_ktls_act_open_req6(struct sock
*sk
,
234 struct chcr_ktls_info
*tx_info
,
237 struct inet_sock
*inet
= inet_sk(sk
);
238 struct cpl_t6_act_open_req6
*cpl6
;
239 struct cpl_act_open_req6
*cpl
;
246 skb
= alloc_skb(len
, GFP_KERNEL
);
249 /* mark it a control pkt */
250 set_wr_txq(skb
, CPL_PRIORITY_CONTROL
, tx_info
->port_id
);
252 cpl6
= __skb_put_zero(skb
, len
);
253 cpl
= (struct cpl_act_open_req6
*)cpl6
;
255 qid_atid
= TID_QID_V(tx_info
->rx_qid
) | TID_TID_V(atid
);
256 OPCODE_TID(cpl
) = htonl(MK_OPCODE_TID(CPL_ACT_OPEN_REQ6
, qid_atid
));
257 cpl
->local_port
= inet
->inet_sport
;
258 cpl
->peer_port
= inet
->inet_dport
;
259 cpl
->local_ip_hi
= *(__be64
*)&sk
->sk_v6_rcv_saddr
.in6_u
.u6_addr8
[0];
260 cpl
->local_ip_lo
= *(__be64
*)&sk
->sk_v6_rcv_saddr
.in6_u
.u6_addr8
[8];
261 cpl
->peer_ip_hi
= *(__be64
*)&sk
->sk_v6_daddr
.in6_u
.u6_addr8
[0];
262 cpl
->peer_ip_lo
= *(__be64
*)&sk
->sk_v6_daddr
.in6_u
.u6_addr8
[8];
264 /* first 64 bit option field. */
265 options
= TCAM_BYPASS_F
| ULP_MODE_V(ULP_MODE_NONE
) | NON_OFFLOAD_F
|
266 SMAC_SEL_V(tx_info
->smt_idx
) | TX_CHAN_V(tx_info
->tx_chan
);
267 cpl
->opt0
= cpu_to_be64(options
);
268 /* next 64 bit option field. */
270 TX_QUEUE_V(tx_info
->adap
->params
.tp
.tx_modq
[tx_info
->tx_chan
]);
271 cpl
->opt2
= htonl(options
);
273 return cxgb4_l2t_send(tx_info
->netdev
, skb
, tx_info
->l2te
);
277 * chcr_setup_connection: create a TCB entry so that TP will form tcp packets.
279 * @tx_info - driver specific tls info.
280 * return: NET_TX_OK/NET_XMIT_DROP
282 static int chcr_setup_connection(struct sock
*sk
,
283 struct chcr_ktls_info
*tx_info
)
285 struct tid_info
*t
= &tx_info
->adap
->tids
;
288 atid
= cxgb4_alloc_atid(t
, tx_info
);
292 tx_info
->atid
= atid
;
293 tx_info
->ip_family
= sk
->sk_family
;
295 if (sk
->sk_family
== AF_INET
||
296 (sk
->sk_family
== AF_INET6
&& !sk
->sk_ipv6only
&&
297 ipv6_addr_type(&sk
->sk_v6_daddr
) == IPV6_ADDR_MAPPED
)) {
298 tx_info
->ip_family
= AF_INET
;
299 ret
= chcr_ktls_act_open_req(sk
, tx_info
, atid
);
301 tx_info
->ip_family
= AF_INET6
;
303 cxgb4_clip_get(tx_info
->netdev
,
304 (const u32
*)&sk
->sk_v6_rcv_saddr
.in6_u
.u6_addr8
,
308 ret
= chcr_ktls_act_open_req6(sk
, tx_info
, atid
);
311 /* if return type is NET_XMIT_CN, msg will be sent but delayed, mark ret
312 * success, if any other return type clear atid and return that failure.
315 if (ret
== NET_XMIT_CN
)
318 cxgb4_free_atid(t
, atid
);
322 /* update the connection state */
323 chcr_ktls_update_connection_state(tx_info
, KTLS_CONN_ACT_OPEN_REQ
);
329 * chcr_set_tcb_field: update tcb fields.
330 * @tx_info - driver specific tls info.
332 * @mask - TCB word related mask.
333 * @val - TCB word related value.
334 * @no_reply - set 1 if not looking for TP response.
336 static int chcr_set_tcb_field(struct chcr_ktls_info
*tx_info
, u16 word
,
337 u64 mask
, u64 val
, int no_reply
)
339 struct cpl_set_tcb_field
*req
;
342 skb
= alloc_skb(sizeof(struct cpl_set_tcb_field
), GFP_ATOMIC
);
346 req
= (struct cpl_set_tcb_field
*)__skb_put_zero(skb
, sizeof(*req
));
347 INIT_TP_WR_CPL(req
, CPL_SET_TCB_FIELD
, tx_info
->tid
);
348 req
->reply_ctrl
= htons(QUEUENO_V(tx_info
->rx_qid
) |
349 NO_REPLY_V(no_reply
));
350 req
->word_cookie
= htons(TCB_WORD_V(word
));
351 req
->mask
= cpu_to_be64(mask
);
352 req
->val
= cpu_to_be64(val
);
354 set_wr_txq(skb
, CPL_PRIORITY_CONTROL
, tx_info
->port_id
);
355 return cxgb4_ofld_send(tx_info
->netdev
, skb
);
359 * chcr_ktls_mark_tcb_close: mark tcb state to CLOSE
360 * @tx_info - driver specific tls info.
361 * return: NET_TX_OK/NET_XMIT_DROP.
363 static int chcr_ktls_mark_tcb_close(struct chcr_ktls_info
*tx_info
)
365 return chcr_set_tcb_field(tx_info
, TCB_T_STATE_W
,
366 TCB_T_STATE_V(TCB_T_STATE_M
),
367 CHCR_TCB_STATE_CLOSED
, 1);
371 * chcr_ktls_dev_del: call back for tls_dev_del.
372 * Remove the tid and l2t entry and close the connection.
373 * it per connection basis.
374 * @netdev - net device.
375 * @tls_cts - tls context.
376 * @direction - TX/RX crypto direction
378 static void chcr_ktls_dev_del(struct net_device
*netdev
,
379 struct tls_context
*tls_ctx
,
380 enum tls_offload_ctx_dir direction
)
382 struct chcr_ktls_ofld_ctx_tx
*tx_ctx
=
383 chcr_get_ktls_tx_context(tls_ctx
);
384 struct chcr_ktls_info
*tx_info
= tx_ctx
->chcr_info
;
391 spin_lock(&tx_info
->lock
);
392 tx_info
->connection_state
= KTLS_CONN_CLOSED
;
393 spin_unlock(&tx_info
->lock
);
395 /* clear l2t entry */
397 cxgb4_l2t_release(tx_info
->l2te
);
399 /* clear clip entry */
400 if (tx_info
->ip_family
== AF_INET6
)
401 cxgb4_clip_release(netdev
,
402 (const u32
*)&sk
->sk_v6_daddr
.in6_u
.u6_addr8
,
406 if (tx_info
->tid
!= -1) {
407 /* clear tcb state and then release tid */
408 chcr_ktls_mark_tcb_close(tx_info
);
409 cxgb4_remove_tid(&tx_info
->adap
->tids
, tx_info
->tx_chan
,
410 tx_info
->tid
, tx_info
->ip_family
);
413 atomic64_inc(&tx_info
->adap
->chcr_stats
.ktls_tx_connection_close
);
415 tx_ctx
->chcr_info
= NULL
;
419 * chcr_ktls_dev_add: call back for tls_dev_add.
420 * Create a tcb entry for TP. Also add l2t entry for the connection. And
421 * generate keys & save those keys locally.
422 * @netdev - net device.
423 * @tls_cts - tls context.
424 * @direction - TX/RX crypto direction
425 * return: SUCCESS/FAILURE.
427 static int chcr_ktls_dev_add(struct net_device
*netdev
, struct sock
*sk
,
428 enum tls_offload_ctx_dir direction
,
429 struct tls_crypto_info
*crypto_info
,
430 u32 start_offload_tcp_sn
)
432 struct tls_context
*tls_ctx
= tls_get_ctx(sk
);
433 struct chcr_ktls_ofld_ctx_tx
*tx_ctx
;
434 struct chcr_ktls_info
*tx_info
;
435 struct dst_entry
*dst
;
436 struct adapter
*adap
;
437 struct port_info
*pi
;
442 tx_ctx
= chcr_get_ktls_tx_context(tls_ctx
);
444 pi
= netdev_priv(netdev
);
446 if (direction
== TLS_OFFLOAD_CTX_DIR_RX
) {
447 pr_err("not expecting for RX direction\n");
451 if (tx_ctx
->chcr_info
) {
456 tx_info
= kvzalloc(sizeof(*tx_info
), GFP_KERNEL
);
462 spin_lock_init(&tx_info
->lock
);
464 /* clear connection state */
465 spin_lock(&tx_info
->lock
);
466 tx_info
->connection_state
= KTLS_CONN_CLOSED
;
467 spin_unlock(&tx_info
->lock
);
470 /* initialize tid and atid to -1, 0 is a also a valid id. */
474 tx_info
->adap
= adap
;
475 tx_info
->netdev
= netdev
;
476 tx_info
->first_qset
= pi
->first_qset
;
477 tx_info
->tx_chan
= pi
->tx_chan
;
478 tx_info
->smt_idx
= pi
->smt_idx
;
479 tx_info
->port_id
= pi
->port_id
;
481 tx_info
->rx_qid
= chcr_get_first_rx_qid(adap
);
482 if (unlikely(tx_info
->rx_qid
< 0))
485 tx_info
->prev_seq
= start_offload_tcp_sn
;
486 tx_info
->tcp_start_seq_number
= start_offload_tcp_sn
;
488 /* save crypto keys */
489 ret
= chcr_ktls_save_keys(tx_info
, crypto_info
, direction
);
494 if (sk
->sk_family
== AF_INET
||
495 (sk
->sk_family
== AF_INET6
&& !sk
->sk_ipv6only
&&
496 ipv6_addr_type(&sk
->sk_v6_daddr
) == IPV6_ADDR_MAPPED
)) {
497 memcpy(daaddr
, &sk
->sk_daddr
, 4);
499 memcpy(daaddr
, sk
->sk_v6_daddr
.in6_u
.u6_addr8
, 16);
502 /* get the l2t index */
503 dst
= sk_dst_get(sk
);
505 pr_err("DST entry not found\n");
508 n
= dst_neigh_lookup(dst
, daaddr
);
510 pr_err("neighbour not found\n");
514 tx_info
->l2te
= cxgb4_l2t_get(adap
->l2t
, n
, n
->dev
, 0);
519 if (!tx_info
->l2te
) {
520 pr_err("l2t entry not found\n");
524 tx_ctx
->chcr_info
= tx_info
;
526 /* create a filter and call cxgb4_l2t_send to send the packet out, which
527 * will take care of updating l2t entry in hw if not already done.
529 ret
= chcr_setup_connection(sk
, tx_info
);
533 atomic64_inc(&adap
->chcr_stats
.ktls_tx_connection_open
);
538 atomic64_inc(&adap
->chcr_stats
.ktls_tx_connection_fail
);
542 static const struct tlsdev_ops chcr_ktls_ops
= {
543 .tls_dev_add
= chcr_ktls_dev_add
,
544 .tls_dev_del
= chcr_ktls_dev_del
,
548 * chcr_enable_ktls: add NETIF_F_HW_TLS_TX flag in all the ports.
550 void chcr_enable_ktls(struct adapter
*adap
)
552 struct net_device
*netdev
;
555 for_each_port(adap
, i
) {
556 netdev
= adap
->port
[i
];
557 netdev
->features
|= NETIF_F_HW_TLS_TX
;
558 netdev
->hw_features
|= NETIF_F_HW_TLS_TX
;
559 netdev
->tlsdev_ops
= &chcr_ktls_ops
;
564 * chcr_disable_ktls: remove NETIF_F_HW_TLS_TX flag from all the ports.
566 void chcr_disable_ktls(struct adapter
*adap
)
568 struct net_device
*netdev
;
571 for_each_port(adap
, i
) {
572 netdev
= adap
->port
[i
];
573 netdev
->features
&= ~NETIF_F_HW_TLS_TX
;
574 netdev
->hw_features
&= ~NETIF_F_HW_TLS_TX
;
575 netdev
->tlsdev_ops
= NULL
;
580 * chcr_init_tcb_fields: Initialize tcb fields to handle TCP seq number
582 * @tx_info - driver specific tls info.
583 * return: NET_TX_OK/NET_XMIT_DROP
585 static int chcr_init_tcb_fields(struct chcr_ktls_info
*tx_info
)
589 /* set tcb in offload and bypass */
591 chcr_set_tcb_field(tx_info
, TCB_T_FLAGS_W
,
592 TCB_T_FLAGS_V(TF_CORE_BYPASS_F
| TF_NON_OFFLOAD_F
),
593 TCB_T_FLAGS_V(TF_CORE_BYPASS_F
), 1);
596 /* reset snd_una and snd_next fields in tcb */
597 ret
= chcr_set_tcb_field(tx_info
, TCB_SND_UNA_RAW_W
,
598 TCB_SND_NXT_RAW_V(TCB_SND_NXT_RAW_M
) |
599 TCB_SND_UNA_RAW_V(TCB_SND_UNA_RAW_M
),
605 ret
= chcr_set_tcb_field(tx_info
, TCB_SND_MAX_RAW_W
,
606 TCB_SND_MAX_RAW_V(TCB_SND_MAX_RAW_M
),
611 /* update l2t index and request for tp reply to confirm tcb is
612 * initialised to handle tx traffic.
614 ret
= chcr_set_tcb_field(tx_info
, TCB_L2T_IX_W
,
615 TCB_L2T_IX_V(TCB_L2T_IX_M
),
616 TCB_L2T_IX_V(tx_info
->l2te
->idx
), 0);
621 * chcr_ktls_cpl_act_open_rpl: connection reply received from TP.
623 int chcr_ktls_cpl_act_open_rpl(struct adapter
*adap
, unsigned char *input
)
625 const struct cpl_act_open_rpl
*p
= (void *)input
;
626 struct chcr_ktls_info
*tx_info
= NULL
;
627 unsigned int atid
, tid
, status
;
631 status
= AOPEN_STATUS_G(ntohl(p
->atid_status
));
632 atid
= TID_TID_G(AOPEN_ATID_G(ntohl(p
->atid_status
)));
635 tx_info
= lookup_atid(t
, atid
);
637 if (!tx_info
|| tx_info
->atid
!= atid
) {
638 pr_err("tx_info or atid is not correct\n");
644 cxgb4_insert_tid(t
, tx_info
, tx_info
->tid
, tx_info
->ip_family
);
646 cxgb4_free_atid(t
, atid
);
648 /* update the connection state */
649 chcr_ktls_update_connection_state(tx_info
,
650 KTLS_CONN_ACT_OPEN_RPL
);
656 * chcr_ktls_cpl_set_tcb_rpl: TCB reply received from TP.
658 int chcr_ktls_cpl_set_tcb_rpl(struct adapter
*adap
, unsigned char *input
)
660 const struct cpl_set_tcb_rpl
*p
= (void *)input
;
661 struct chcr_ktls_info
*tx_info
= NULL
;
668 tx_info
= lookup_tid(t
, tid
);
669 if (!tx_info
|| tx_info
->tid
!= tid
) {
670 pr_err("tx_info or atid is not correct\n");
673 /* update the connection state */
674 chcr_ktls_update_connection_state(tx_info
, KTLS_CONN_SET_TCB_RPL
);
679 * chcr_write_cpl_set_tcb_ulp: update tcb values.
680 * TCB is responsible to create tcp headers, so all the related values
681 * should be correctly updated.
682 * @tx_info - driver specific tls info.
683 * @q - tx queue on which packet is going out.
684 * @tid - TCB identifier.
685 * @pos - current index where should we start writing.
687 * @mask - TCB word related mask.
688 * @val - TCB word related value.
689 * @reply - set 1 if looking for TP response.
690 * return - next position to write.
692 static void *chcr_write_cpl_set_tcb_ulp(struct chcr_ktls_info
*tx_info
,
693 struct sge_eth_txq
*q
, u32 tid
,
694 void *pos
, u16 word
, u64 mask
,
697 struct cpl_set_tcb_field_core
*cpl
;
698 struct ulptx_idata
*idata
;
699 struct ulp_txpkt
*txpkt
;
700 void *save_pos
= NULL
;
704 left
= (void *)q
->q
.stat
- pos
;
705 if (unlikely(left
< CHCR_SET_TCB_FIELD_LEN
)) {
715 txpkt
->cmd_dest
= htonl(ULPTX_CMD_V(ULP_TX_PKT
) | ULP_TXPKT_DEST_V(0));
716 txpkt
->len
= htonl(DIV_ROUND_UP(CHCR_SET_TCB_FIELD_LEN
, 16));
718 /* ULPTX_IDATA sub-command */
719 idata
= (struct ulptx_idata
*)(txpkt
+ 1);
720 idata
->cmd_more
= htonl(ULPTX_CMD_V(ULP_TX_SC_IMM
));
721 idata
->len
= htonl(sizeof(*cpl
));
725 /* CPL_SET_TCB_FIELD */
726 OPCODE_TID(cpl
) = htonl(MK_OPCODE_TID(CPL_SET_TCB_FIELD
, tid
));
727 cpl
->reply_ctrl
= htons(QUEUENO_V(tx_info
->rx_qid
) |
729 cpl
->word_cookie
= htons(TCB_WORD_V(word
));
730 cpl
->mask
= cpu_to_be64(mask
);
731 cpl
->val
= cpu_to_be64(val
);
734 idata
= (struct ulptx_idata
*)(cpl
+ 1);
735 idata
->cmd_more
= htonl(ULPTX_CMD_V(ULP_TX_SC_NOOP
));
736 idata
->len
= htonl(0);
739 pos
= chcr_copy_to_txd(buf
, &q
->q
, save_pos
,
740 CHCR_SET_TCB_FIELD_LEN
);
742 /* check again if we are at the end of the queue */
743 if (left
== CHCR_SET_TCB_FIELD_LEN
)
753 * chcr_ktls_xmit_tcb_cpls: update tcb entry so that TP will create the header
754 * with updated values like tcp seq, ack, window etc.
755 * @tx_info - driver specific tls info.
760 * return: NETDEV_TX_BUSY/NET_TX_OK.
762 static int chcr_ktls_xmit_tcb_cpls(struct chcr_ktls_info
*tx_info
,
763 struct sge_eth_txq
*q
, u64 tcp_seq
,
764 u64 tcp_ack
, u64 tcp_win
)
766 bool first_wr
= ((tx_info
->prev_ack
== 0) && (tx_info
->prev_win
== 0));
767 u32 len
, cpl
= 0, ndesc
, wr_len
;
768 struct fw_ulptx_wr
*wr
;
772 wr_len
= sizeof(*wr
);
773 /* there can be max 4 cpls, check if we have enough credits */
774 len
= wr_len
+ 4 * roundup(CHCR_SET_TCB_FIELD_LEN
, 16);
775 ndesc
= DIV_ROUND_UP(len
, 64);
777 credits
= chcr_txq_avail(&q
->q
) - ndesc
;
778 if (unlikely(credits
< 0)) {
779 chcr_eth_txq_stop(q
);
780 return NETDEV_TX_BUSY
;
783 pos
= &q
->q
.desc
[q
->q
.pidx
];
784 /* make space for WR, we'll fill it later when we know all the cpls
785 * being sent out and have complete length.
789 /* update tx_max if its a re-transmit or the first wr */
790 if (first_wr
|| tcp_seq
!= tx_info
->prev_seq
) {
791 pos
= chcr_write_cpl_set_tcb_ulp(tx_info
, q
, tx_info
->tid
, pos
,
793 TCB_TX_MAX_V(TCB_TX_MAX_M
),
794 TCB_TX_MAX_V(tcp_seq
), 0);
797 /* reset snd una if it's a re-transmit pkt */
798 if (tcp_seq
!= tx_info
->prev_seq
) {
800 pos
= chcr_write_cpl_set_tcb_ulp(tx_info
, q
, tx_info
->tid
, pos
,
804 TCB_SND_UNA_RAW_V(0), 0);
805 atomic64_inc(&tx_info
->adap
->chcr_stats
.ktls_tx_ooo
);
809 if (first_wr
|| tx_info
->prev_ack
!= tcp_ack
) {
810 pos
= chcr_write_cpl_set_tcb_ulp(tx_info
, q
, tx_info
->tid
, pos
,
812 TCB_RCV_NXT_V(TCB_RCV_NXT_M
),
813 TCB_RCV_NXT_V(tcp_ack
), 0);
814 tx_info
->prev_ack
= tcp_ack
;
817 /* update receive window */
818 if (first_wr
|| tx_info
->prev_win
!= tcp_win
) {
819 pos
= chcr_write_cpl_set_tcb_ulp(tx_info
, q
, tx_info
->tid
, pos
,
821 TCB_RCV_WND_V(TCB_RCV_WND_M
),
822 TCB_RCV_WND_V(tcp_win
), 0);
823 tx_info
->prev_win
= tcp_win
;
828 /* get the actual length */
829 len
= wr_len
+ cpl
* roundup(CHCR_SET_TCB_FIELD_LEN
, 16);
831 wr
->op_to_compl
= htonl(FW_WR_OP_V(FW_ULPTX_WR
));
833 /* fill len in wr field */
834 wr
->flowid_len16
= htonl(FW_WR_LEN16_V(DIV_ROUND_UP(len
, 16)));
836 ndesc
= DIV_ROUND_UP(len
, 64);
837 chcr_txq_advance(&q
->q
, ndesc
);
838 cxgb4_ring_tx_db(tx_info
->adap
, &q
->q
, ndesc
);
845 * @nskb - new skb where the frags to be added.
846 * @skb - old skb from which frags will be copied.
848 static void chcr_ktls_skb_copy(struct sk_buff
*skb
, struct sk_buff
*nskb
)
852 for (i
= 0; i
< skb_shinfo(skb
)->nr_frags
; i
++) {
853 skb_shinfo(nskb
)->frags
[i
] = skb_shinfo(skb
)->frags
[i
];
854 __skb_frag_ref(&skb_shinfo(nskb
)->frags
[i
]);
857 skb_shinfo(nskb
)->nr_frags
= skb_shinfo(skb
)->nr_frags
;
858 nskb
->len
+= skb
->data_len
;
859 nskb
->data_len
= skb
->data_len
;
860 nskb
->truesize
+= skb
->data_len
;
864 * chcr_ktls_get_tx_flits
865 * returns number of flits to be sent out, it includes key context length, WR
866 * size and skb fragments.
869 chcr_ktls_get_tx_flits(const struct sk_buff
*skb
, unsigned int key_ctx_len
)
871 return chcr_sgl_len(skb_shinfo(skb
)->nr_frags
) +
872 DIV_ROUND_UP(key_ctx_len
+ CHCR_KTLS_WR_SIZE
, 8);
876 * chcr_ktls_check_tcp_options: To check if there is any TCP option availbale
877 * other than timestamp.
878 * @skb - skb contains partial record..
882 chcr_ktls_check_tcp_options(struct tcphdr
*tcp
)
884 int cnt
, opt
, optlen
;
887 cp
= (u_char
*)(tcp
+ 1);
888 cnt
= (tcp
->doff
<< 2) - sizeof(struct tcphdr
);
889 for (; cnt
> 0; cnt
-= optlen
, cp
+= optlen
) {
891 if (opt
== TCPOPT_EOL
)
893 if (opt
== TCPOPT_NOP
) {
899 if (optlen
< 2 || optlen
> cnt
)
913 * chcr_ktls_write_tcp_options : TP can't send out all the options, we need to
914 * send out separately.
915 * @tx_info - driver specific tls info.
916 * @skb - skb contains partial record..
918 * @tx_chan - channel number.
919 * return: NETDEV_TX_OK/NETDEV_TX_BUSY.
922 chcr_ktls_write_tcp_options(struct chcr_ktls_info
*tx_info
, struct sk_buff
*skb
,
923 struct sge_eth_txq
*q
, uint32_t tx_chan
)
925 struct fw_eth_tx_pkt_wr
*wr
;
926 struct cpl_tx_pkt_core
*cpl
;
927 u32 ctrl
, iplen
, maclen
;
937 iplen
= skb_network_header_len(skb
);
938 maclen
= skb_mac_header_len(skb
);
940 /* packet length = eth hdr len + ip hdr len + tcp hdr len
941 * (including options).
943 pktlen
= skb
->len
- skb
->data_len
;
945 ctrl
= sizeof(*cpl
) + pktlen
;
946 len16
= DIV_ROUND_UP(sizeof(*wr
) + ctrl
, 16);
947 /* check how many descriptors needed */
948 ndesc
= DIV_ROUND_UP(len16
, 4);
950 credits
= chcr_txq_avail(&q
->q
) - ndesc
;
951 if (unlikely(credits
< 0)) {
952 chcr_eth_txq_stop(q
);
953 return NETDEV_TX_BUSY
;
956 pos
= &q
->q
.desc
[q
->q
.pidx
];
959 /* Firmware work request header */
960 wr
->op_immdlen
= htonl(FW_WR_OP_V(FW_ETH_TX_PKT_WR
) |
961 FW_WR_IMMDLEN_V(ctrl
));
963 wr
->equiq_to_len16
= htonl(FW_WR_LEN16_V(len16
));
966 cpl
= (void *)(wr
+ 1);
969 cpl
->ctrl0
= htonl(TXPKT_OPCODE_V(CPL_TX_PKT
) | TXPKT_INTF_V(tx_chan
) |
970 TXPKT_PF_V(tx_info
->adap
->pf
));
972 cpl
->len
= htons(pktlen
);
973 /* checksum offload */
978 memcpy(buf
, skb
->data
, pktlen
);
979 if (tx_info
->ip_family
== AF_INET
) {
980 /* we need to correct ip header len */
981 ip
= (struct iphdr
*)(buf
+ maclen
);
982 ip
->tot_len
= htons(pktlen
- maclen
);
984 ip6
= (struct ipv6hdr
*)(buf
+ maclen
);
985 ip6
->payload_len
= htons(pktlen
- maclen
- iplen
);
987 /* now take care of the tcp header, if fin is not set then clear push
988 * bit as well, and if fin is set, it will be sent at the last so we
989 * need to update the tcp sequence number as per the last packet.
991 tcp
= (struct tcphdr
*)(buf
+ maclen
+ iplen
);
996 tcp
->seq
= htonl(tx_info
->prev_seq
);
998 chcr_copy_to_txd(buf
, &q
->q
, pos
, pktlen
);
1000 chcr_txq_advance(&q
->q
, ndesc
);
1001 cxgb4_ring_tx_db(tx_info
->adap
, &q
->q
, ndesc
);
1005 /* chcr_ktls_skb_shift - Shifts request length paged data from skb to another.
1006 * @tgt- buffer into which tail data gets added
1007 * @skb- buffer from which the paged data comes from
1008 * @shiftlen- shift up to this many bytes
1010 static int chcr_ktls_skb_shift(struct sk_buff
*tgt
, struct sk_buff
*skb
,
1013 skb_frag_t
*fragfrom
, *fragto
;
1016 WARN_ON(shiftlen
> skb
->data_len
);
1021 fragfrom
= &skb_shinfo(skb
)->frags
[from
];
1023 while ((todo
> 0) && (from
< skb_shinfo(skb
)->nr_frags
)) {
1024 fragfrom
= &skb_shinfo(skb
)->frags
[from
];
1025 fragto
= &skb_shinfo(tgt
)->frags
[to
];
1027 if (todo
>= skb_frag_size(fragfrom
)) {
1028 *fragto
= *fragfrom
;
1029 todo
-= skb_frag_size(fragfrom
);
1034 __skb_frag_ref(fragfrom
);
1035 skb_frag_page_copy(fragto
, fragfrom
);
1036 skb_frag_off_copy(fragto
, fragfrom
);
1037 skb_frag_size_set(fragto
, todo
);
1039 skb_frag_off_add(fragfrom
, todo
);
1040 skb_frag_size_sub(fragfrom
, todo
);
1048 /* Ready to "commit" this state change to tgt */
1049 skb_shinfo(tgt
)->nr_frags
= to
;
1051 /* Reposition in the original skb */
1053 while (from
< skb_shinfo(skb
)->nr_frags
)
1054 skb_shinfo(skb
)->frags
[to
++] = skb_shinfo(skb
)->frags
[from
++];
1056 skb_shinfo(skb
)->nr_frags
= to
;
1058 WARN_ON(todo
> 0 && !skb_shinfo(skb
)->nr_frags
);
1060 skb
->len
-= shiftlen
;
1061 skb
->data_len
-= shiftlen
;
1062 skb
->truesize
-= shiftlen
;
1063 tgt
->len
+= shiftlen
;
1064 tgt
->data_len
+= shiftlen
;
1065 tgt
->truesize
+= shiftlen
;
1071 * chcr_ktls_xmit_wr_complete: This sends out the complete record. If an skb
1072 * received has partial end part of the record, send out the complete record, so
1073 * that crypto block will be able to generate TAG/HASH.
1074 * @skb - segment which has complete or partial end part.
1075 * @tx_info - driver specific tls info.
1078 * @tcp_push - tcp push bit.
1079 * @mss - segment size.
1080 * return: NETDEV_TX_BUSY/NET_TX_OK.
1082 static int chcr_ktls_xmit_wr_complete(struct sk_buff
*skb
,
1083 struct chcr_ktls_info
*tx_info
,
1084 struct sge_eth_txq
*q
, u32 tcp_seq
,
1085 bool tcp_push
, u32 mss
)
1087 u32 len16
, wr_mid
= 0, flits
= 0, ndesc
, cipher_start
;
1088 struct adapter
*adap
= tx_info
->adap
;
1089 int credits
, left
, last_desc
;
1090 struct tx_sw_desc
*sgl_sdesc
;
1091 struct cpl_tx_data
*tx_data
;
1092 struct cpl_tx_sec_pdu
*cpl
;
1093 struct ulptx_idata
*idata
;
1094 struct ulp_txpkt
*ulptx
;
1095 struct fw_ulptx_wr
*wr
;
1099 /* get the number of flits required */
1100 flits
= chcr_ktls_get_tx_flits(skb
, tx_info
->key_ctx_len
);
1101 /* number of descriptors */
1102 ndesc
= chcr_flits_to_desc(flits
);
1103 /* check if enough credits available */
1104 credits
= chcr_txq_avail(&q
->q
) - ndesc
;
1105 if (unlikely(credits
< 0)) {
1106 chcr_eth_txq_stop(q
);
1107 return NETDEV_TX_BUSY
;
1110 if (unlikely(credits
< ETHTXQ_STOP_THRES
)) {
1111 /* Credits are below the threshold vaues, stop the queue after
1112 * injecting the Work Request for this packet.
1114 chcr_eth_txq_stop(q
);
1115 wr_mid
|= FW_WR_EQUEQ_F
| FW_WR_EQUIQ_F
;
1118 last_desc
= q
->q
.pidx
+ ndesc
- 1;
1119 if (last_desc
>= q
->q
.size
)
1120 last_desc
-= q
->q
.size
;
1121 sgl_sdesc
= &q
->q
.sdesc
[last_desc
];
1123 if (unlikely(cxgb4_map_skb(adap
->pdev_dev
, skb
, sgl_sdesc
->addr
) < 0)) {
1124 memset(sgl_sdesc
->addr
, 0, sizeof(sgl_sdesc
->addr
));
1126 return NETDEV_TX_BUSY
;
1129 pos
= &q
->q
.desc
[q
->q
.pidx
];
1130 end
= (u64
*)pos
+ flits
;
1133 /* WR will need len16 */
1134 len16
= DIV_ROUND_UP(flits
, 2);
1135 wr
->op_to_compl
= htonl(FW_WR_OP_V(FW_ULPTX_WR
));
1136 wr
->flowid_len16
= htonl(wr_mid
| FW_WR_LEN16_V(len16
));
1141 ulptx
->cmd_dest
= htonl(ULPTX_CMD_V(ULP_TX_PKT
) |
1142 ULP_TXPKT_CHANNELID_V(tx_info
->port_id
) |
1143 ULP_TXPKT_FID_V(q
->q
.cntxt_id
) |
1145 ulptx
->len
= htonl(len16
- 1);
1146 /* ULPTX_IDATA sub-command */
1147 idata
= (struct ulptx_idata
*)(ulptx
+ 1);
1148 idata
->cmd_more
= htonl(ULPTX_CMD_V(ULP_TX_SC_IMM
) | ULP_TX_SC_MORE_F
);
1149 /* idata length will include cpl_tx_sec_pdu + key context size +
1150 * cpl_tx_data header.
1152 idata
->len
= htonl(sizeof(*cpl
) + tx_info
->key_ctx_len
+
1155 cpl
= (struct cpl_tx_sec_pdu
*)(idata
+ 1);
1156 cpl
->op_ivinsrtofst
=
1157 htonl(CPL_TX_SEC_PDU_OPCODE_V(CPL_TX_SEC_PDU
) |
1158 CPL_TX_SEC_PDU_CPLLEN_V(CHCR_CPL_TX_SEC_PDU_LEN_64BIT
) |
1159 CPL_TX_SEC_PDU_PLACEHOLDER_V(1) |
1160 CPL_TX_SEC_PDU_IVINSRTOFST_V(TLS_HEADER_SIZE
+ 1));
1161 cpl
->pldlen
= htonl(skb
->data_len
);
1163 /* encryption should start after tls header size + iv size */
1164 cipher_start
= TLS_HEADER_SIZE
+ tx_info
->iv_size
+ 1;
1166 cpl
->aadstart_cipherstop_hi
=
1167 htonl(CPL_TX_SEC_PDU_AADSTART_V(1) |
1168 CPL_TX_SEC_PDU_AADSTOP_V(TLS_HEADER_SIZE
) |
1169 CPL_TX_SEC_PDU_CIPHERSTART_V(cipher_start
));
1171 /* authentication will also start after tls header + iv size */
1172 cpl
->cipherstop_lo_authinsert
=
1173 htonl(CPL_TX_SEC_PDU_AUTHSTART_V(cipher_start
) |
1174 CPL_TX_SEC_PDU_AUTHSTOP_V(TLS_CIPHER_AES_GCM_128_TAG_SIZE
) |
1175 CPL_TX_SEC_PDU_AUTHINSERT_V(TLS_CIPHER_AES_GCM_128_TAG_SIZE
));
1177 /* These two flits are actually a CPL_TLS_TX_SCMD_FMT. */
1178 cpl
->seqno_numivs
= htonl(tx_info
->scmd0_seqno_numivs
);
1179 cpl
->ivgen_hdrlen
= htonl(tx_info
->scmd0_ivgen_hdrlen
);
1180 cpl
->scmd1
= cpu_to_be64(tx_info
->record_no
);
1183 /* check if space left to fill the keys */
1184 left
= (void *)q
->q
.stat
- pos
;
1186 left
= (void *)end
- (void *)q
->q
.stat
;
1191 pos
= chcr_copy_to_txd(&tx_info
->key_ctx
, &q
->q
, pos
,
1192 tx_info
->key_ctx_len
);
1193 left
= (void *)q
->q
.stat
- pos
;
1196 left
= (void *)end
- (void *)q
->q
.stat
;
1201 tx_data
= (void *)pos
;
1202 OPCODE_TID(tx_data
) = htonl(MK_OPCODE_TID(CPL_TX_DATA
, tx_info
->tid
));
1203 tx_data
->len
= htonl(TX_DATA_MSS_V(mss
) | TX_LENGTH_V(skb
->data_len
));
1205 tx_data
->rsvd
= htonl(tcp_seq
);
1207 tx_data
->flags
= htonl(TX_BYPASS_F
);
1209 tx_data
->flags
|= htonl(TX_PUSH_F
| TX_SHOVE_F
);
1211 /* check left again, it might go beyond queue limit */
1213 left
= (void *)q
->q
.stat
- pos
;
1215 /* check the position again */
1217 left
= (void *)end
- (void *)q
->q
.stat
;
1222 /* send the complete packet except the header */
1223 cxgb4_write_sgl(skb
, &q
->q
, pos
, end
, skb
->len
- skb
->data_len
,
1225 sgl_sdesc
->skb
= skb
;
1227 chcr_txq_advance(&q
->q
, ndesc
);
1228 cxgb4_ring_tx_db(adap
, &q
->q
, ndesc
);
1229 atomic64_inc(&adap
->chcr_stats
.ktls_tx_send_records
);
1235 * chcr_ktls_xmit_wr_short: This is to send out partial records. If its
1236 * a middle part of a record, fetch the prior data to make it 16 byte aligned
1237 * and then only send it out.
1239 * @skb - skb contains partial record..
1240 * @tx_info - driver specific tls info.
1243 * @tcp_push - tcp push bit.
1244 * @mss - segment size.
1245 * @tls_rec_offset - offset from start of the tls record.
1246 * @perior_data - data before the current segment, required to make this record
1248 * @prior_data_len - prior_data length (less than 16)
1249 * return: NETDEV_TX_BUSY/NET_TX_OK.
1251 static int chcr_ktls_xmit_wr_short(struct sk_buff
*skb
,
1252 struct chcr_ktls_info
*tx_info
,
1253 struct sge_eth_txq
*q
,
1254 u32 tcp_seq
, bool tcp_push
, u32 mss
,
1255 u32 tls_rec_offset
, u8
*prior_data
,
1258 struct adapter
*adap
= tx_info
->adap
;
1259 u32 len16
, wr_mid
= 0, cipher_start
;
1260 unsigned int flits
= 0, ndesc
;
1261 int credits
, left
, last_desc
;
1262 struct tx_sw_desc
*sgl_sdesc
;
1263 struct cpl_tx_data
*tx_data
;
1264 struct cpl_tx_sec_pdu
*cpl
;
1265 struct ulptx_idata
*idata
;
1266 struct ulp_txpkt
*ulptx
;
1267 struct fw_ulptx_wr
*wr
;
1272 /* get the number of flits required, it's a partial record so 2 flits
1273 * (AES_BLOCK_SIZE) will be added.
1275 flits
= chcr_ktls_get_tx_flits(skb
, tx_info
->key_ctx_len
) + 2;
1276 /* get the correct 8 byte IV of this record */
1277 iv_record
= cpu_to_be64(tx_info
->iv
+ tx_info
->record_no
);
1278 /* If it's a middle record and not 16 byte aligned to run AES CTR, need
1279 * to make it 16 byte aligned. So atleadt 2 extra flits of immediate
1280 * data will be added.
1284 /* number of descriptors */
1285 ndesc
= chcr_flits_to_desc(flits
);
1286 /* check if enough credits available */
1287 credits
= chcr_txq_avail(&q
->q
) - ndesc
;
1288 if (unlikely(credits
< 0)) {
1289 chcr_eth_txq_stop(q
);
1290 return NETDEV_TX_BUSY
;
1293 if (unlikely(credits
< ETHTXQ_STOP_THRES
)) {
1294 chcr_eth_txq_stop(q
);
1295 wr_mid
|= FW_WR_EQUEQ_F
| FW_WR_EQUIQ_F
;
1298 last_desc
= q
->q
.pidx
+ ndesc
- 1;
1299 if (last_desc
>= q
->q
.size
)
1300 last_desc
-= q
->q
.size
;
1301 sgl_sdesc
= &q
->q
.sdesc
[last_desc
];
1303 if (unlikely(cxgb4_map_skb(adap
->pdev_dev
, skb
, sgl_sdesc
->addr
) < 0)) {
1304 memset(sgl_sdesc
->addr
, 0, sizeof(sgl_sdesc
->addr
));
1306 return NETDEV_TX_BUSY
;
1309 pos
= &q
->q
.desc
[q
->q
.pidx
];
1310 end
= (u64
*)pos
+ flits
;
1313 /* WR will need len16 */
1314 len16
= DIV_ROUND_UP(flits
, 2);
1315 wr
->op_to_compl
= htonl(FW_WR_OP_V(FW_ULPTX_WR
));
1316 wr
->flowid_len16
= htonl(wr_mid
| FW_WR_LEN16_V(len16
));
1321 ulptx
->cmd_dest
= htonl(ULPTX_CMD_V(ULP_TX_PKT
) |
1322 ULP_TXPKT_CHANNELID_V(tx_info
->port_id
) |
1323 ULP_TXPKT_FID_V(q
->q
.cntxt_id
) |
1325 ulptx
->len
= htonl(len16
- 1);
1326 /* ULPTX_IDATA sub-command */
1327 idata
= (struct ulptx_idata
*)(ulptx
+ 1);
1328 idata
->cmd_more
= htonl(ULPTX_CMD_V(ULP_TX_SC_IMM
) | ULP_TX_SC_MORE_F
);
1329 /* idata length will include cpl_tx_sec_pdu + key context size +
1330 * cpl_tx_data header.
1332 idata
->len
= htonl(sizeof(*cpl
) + tx_info
->key_ctx_len
+
1333 sizeof(*tx_data
) + AES_BLOCK_LEN
+ prior_data_len
);
1335 cpl
= (struct cpl_tx_sec_pdu
*)(idata
+ 1);
1336 /* cipher start will have tls header + iv size extra if its a header
1337 * part of tls record. else only 16 byte IV will be added.
1341 (!tls_rec_offset
? TLS_HEADER_SIZE
+ tx_info
->iv_size
: 0);
1343 cpl
->op_ivinsrtofst
=
1344 htonl(CPL_TX_SEC_PDU_OPCODE_V(CPL_TX_SEC_PDU
) |
1345 CPL_TX_SEC_PDU_CPLLEN_V(CHCR_CPL_TX_SEC_PDU_LEN_64BIT
) |
1346 CPL_TX_SEC_PDU_IVINSRTOFST_V(1));
1347 cpl
->pldlen
= htonl(skb
->data_len
+ AES_BLOCK_LEN
+ prior_data_len
);
1348 cpl
->aadstart_cipherstop_hi
=
1349 htonl(CPL_TX_SEC_PDU_CIPHERSTART_V(cipher_start
));
1350 cpl
->cipherstop_lo_authinsert
= 0;
1351 /* These two flits are actually a CPL_TLS_TX_SCMD_FMT. */
1352 cpl
->seqno_numivs
= htonl(tx_info
->scmd0_short_seqno_numivs
);
1353 cpl
->ivgen_hdrlen
= htonl(tx_info
->scmd0_short_ivgen_hdrlen
);
1357 /* check if space left to fill the keys */
1358 left
= (void *)q
->q
.stat
- pos
;
1360 left
= (void *)end
- (void *)q
->q
.stat
;
1365 pos
= chcr_copy_to_txd(&tx_info
->key_ctx
, &q
->q
, pos
,
1366 tx_info
->key_ctx_len
);
1367 left
= (void *)q
->q
.stat
- pos
;
1370 left
= (void *)end
- (void *)q
->q
.stat
;
1375 tx_data
= (void *)pos
;
1376 OPCODE_TID(tx_data
) = htonl(MK_OPCODE_TID(CPL_TX_DATA
, tx_info
->tid
));
1377 tx_data
->len
= htonl(TX_DATA_MSS_V(mss
) |
1378 TX_LENGTH_V(skb
->data_len
+ prior_data_len
));
1379 tx_data
->rsvd
= htonl(tcp_seq
);
1380 tx_data
->flags
= htonl(TX_BYPASS_F
);
1382 tx_data
->flags
|= htonl(TX_PUSH_F
| TX_SHOVE_F
);
1384 /* check left again, it might go beyond queue limit */
1386 left
= (void *)q
->q
.stat
- pos
;
1388 /* check the position again */
1390 left
= (void *)end
- (void *)q
->q
.stat
;
1394 /* copy the 16 byte IV for AES-CTR, which includes 4 bytes of salt, 8
1395 * bytes of actual IV and 4 bytes of 16 byte-sequence.
1397 memcpy(pos
, tx_info
->key_ctx
.salt
, tx_info
->salt_size
);
1398 memcpy(pos
+ tx_info
->salt_size
, &iv_record
, tx_info
->iv_size
);
1399 *(__be32
*)(pos
+ tx_info
->salt_size
+ tx_info
->iv_size
) =
1400 htonl(2 + (tls_rec_offset
? ((tls_rec_offset
-
1401 (TLS_HEADER_SIZE
+ tx_info
->iv_size
)) / AES_BLOCK_LEN
) : 0));
1404 /* Prior_data_len will always be less than 16 bytes, fill the
1405 * prio_data_len after AES_CTRL_BLOCK and clear the remaining length
1409 pos
= chcr_copy_to_txd(prior_data
, &q
->q
, pos
, 16);
1410 /* send the complete packet except the header */
1411 cxgb4_write_sgl(skb
, &q
->q
, pos
, end
, skb
->len
- skb
->data_len
,
1413 sgl_sdesc
->skb
= skb
;
1415 chcr_txq_advance(&q
->q
, ndesc
);
1416 cxgb4_ring_tx_db(adap
, &q
->q
, ndesc
);
1422 * chcr_ktls_tx_plaintxt: This handler will take care of the records which has
1423 * only plain text (only tls header and iv)
1424 * @tx_info - driver specific tls info.
1425 * @skb - skb contains partial record..
1427 * @mss - segment size.
1428 * @tcp_push - tcp push bit.
1430 * @port_id : port number
1431 * @perior_data - data before the current segment, required to make this record
1433 * @prior_data_len - prior_data length (less than 16)
1434 * return: NETDEV_TX_BUSY/NET_TX_OK.
1436 static int chcr_ktls_tx_plaintxt(struct chcr_ktls_info
*tx_info
,
1437 struct sk_buff
*skb
, u32 tcp_seq
, u32 mss
,
1438 bool tcp_push
, struct sge_eth_txq
*q
,
1439 u32 port_id
, u8
*prior_data
,
1442 int credits
, left
, len16
, last_desc
;
1443 unsigned int flits
= 0, ndesc
;
1444 struct tx_sw_desc
*sgl_sdesc
;
1445 struct cpl_tx_data
*tx_data
;
1446 struct ulptx_idata
*idata
;
1447 struct ulp_txpkt
*ulptx
;
1448 struct fw_ulptx_wr
*wr
;
1453 flits
= DIV_ROUND_UP(CHCR_PLAIN_TX_DATA_LEN
, 8);
1454 flits
+= chcr_sgl_len(skb_shinfo(skb
)->nr_frags
);
1457 /* WR will need len16 */
1458 len16
= DIV_ROUND_UP(flits
, 2);
1459 /* check how many descriptors needed */
1460 ndesc
= DIV_ROUND_UP(flits
, 8);
1462 credits
= chcr_txq_avail(&q
->q
) - ndesc
;
1463 if (unlikely(credits
< 0)) {
1464 chcr_eth_txq_stop(q
);
1465 return NETDEV_TX_BUSY
;
1468 if (unlikely(credits
< ETHTXQ_STOP_THRES
)) {
1469 chcr_eth_txq_stop(q
);
1470 wr_mid
|= FW_WR_EQUEQ_F
| FW_WR_EQUIQ_F
;
1473 last_desc
= q
->q
.pidx
+ ndesc
- 1;
1474 if (last_desc
>= q
->q
.size
)
1475 last_desc
-= q
->q
.size
;
1476 sgl_sdesc
= &q
->q
.sdesc
[last_desc
];
1478 if (unlikely(cxgb4_map_skb(tx_info
->adap
->pdev_dev
, skb
,
1479 sgl_sdesc
->addr
) < 0)) {
1480 memset(sgl_sdesc
->addr
, 0, sizeof(sgl_sdesc
->addr
));
1482 return NETDEV_TX_BUSY
;
1485 pos
= &q
->q
.desc
[q
->q
.pidx
];
1486 end
= (u64
*)pos
+ flits
;
1489 wr
->op_to_compl
= htonl(FW_WR_OP_V(FW_ULPTX_WR
));
1490 wr
->flowid_len16
= htonl(wr_mid
| FW_WR_LEN16_V(len16
));
1494 ulptx
= (struct ulp_txpkt
*)(wr
+ 1);
1495 ulptx
->cmd_dest
= htonl(ULPTX_CMD_V(ULP_TX_PKT
) |
1496 ULP_TXPKT_DATAMODIFY_V(0) |
1497 ULP_TXPKT_CHANNELID_V(tx_info
->port_id
) |
1498 ULP_TXPKT_DEST_V(0) |
1499 ULP_TXPKT_FID_V(q
->q
.cntxt_id
) | ULP_TXPKT_RO_V(1));
1500 ulptx
->len
= htonl(len16
- 1);
1501 /* ULPTX_IDATA sub-command */
1502 idata
= (struct ulptx_idata
*)(ulptx
+ 1);
1503 idata
->cmd_more
= htonl(ULPTX_CMD_V(ULP_TX_SC_IMM
) | ULP_TX_SC_MORE_F
);
1504 idata
->len
= htonl(sizeof(*tx_data
) + prior_data_len
);
1506 tx_data
= (struct cpl_tx_data
*)(idata
+ 1);
1507 OPCODE_TID(tx_data
) = htonl(MK_OPCODE_TID(CPL_TX_DATA
, tx_info
->tid
));
1508 tx_data
->len
= htonl(TX_DATA_MSS_V(mss
) |
1509 TX_LENGTH_V(skb
->data_len
+ prior_data_len
));
1510 /* set tcp seq number */
1511 tx_data
->rsvd
= htonl(tcp_seq
);
1512 tx_data
->flags
= htonl(TX_BYPASS_F
);
1514 tx_data
->flags
|= htonl(TX_PUSH_F
| TX_SHOVE_F
);
1517 /* apart from prior_data_len, we should set remaining part of 16 bytes
1521 pos
= chcr_copy_to_txd(prior_data
, &q
->q
, pos
, 16);
1523 /* check left again, it might go beyond queue limit */
1524 left
= (void *)q
->q
.stat
- pos
;
1526 /* check the position again */
1528 left
= (void *)end
- (void *)q
->q
.stat
;
1532 /* send the complete packet including the header */
1533 cxgb4_write_sgl(skb
, &q
->q
, pos
, end
, skb
->len
- skb
->data_len
,
1535 sgl_sdesc
->skb
= skb
;
1537 chcr_txq_advance(&q
->q
, ndesc
);
1538 cxgb4_ring_tx_db(tx_info
->adap
, &q
->q
, ndesc
);
1543 * chcr_ktls_copy_record_in_skb
1544 * @nskb - new skb where the frags to be added.
1545 * @record - specific record which has complete 16k record in frags.
1547 static void chcr_ktls_copy_record_in_skb(struct sk_buff
*nskb
,
1548 struct tls_record_info
*record
)
1552 for (i
= 0; i
< record
->num_frags
; i
++) {
1553 skb_shinfo(nskb
)->frags
[i
] = record
->frags
[i
];
1554 /* increase the frag ref count */
1555 __skb_frag_ref(&skb_shinfo(nskb
)->frags
[i
]);
1558 skb_shinfo(nskb
)->nr_frags
= record
->num_frags
;
1559 nskb
->data_len
= record
->len
;
1560 nskb
->len
+= record
->len
;
1561 nskb
->truesize
+= record
->len
;
1565 * chcr_ktls_update_snd_una: Reset the SEND_UNA. It will be done to avoid
1566 * sending the same segment again. It will discard the segment which is before
1567 * the current tx max.
1568 * @tx_info - driver specific tls info.
1570 * return: NET_TX_OK/NET_XMIT_DROP.
1572 static int chcr_ktls_update_snd_una(struct chcr_ktls_info
*tx_info
,
1573 struct sge_eth_txq
*q
)
1575 struct fw_ulptx_wr
*wr
;
1581 len
= sizeof(*wr
) + roundup(CHCR_SET_TCB_FIELD_LEN
, 16);
1582 ndesc
= DIV_ROUND_UP(len
, 64);
1584 credits
= chcr_txq_avail(&q
->q
) - ndesc
;
1585 if (unlikely(credits
< 0)) {
1586 chcr_eth_txq_stop(q
);
1587 return NETDEV_TX_BUSY
;
1590 pos
= &q
->q
.desc
[q
->q
.pidx
];
1594 wr
->op_to_compl
= htonl(FW_WR_OP_V(FW_ULPTX_WR
));
1596 /* fill len in wr field */
1597 wr
->flowid_len16
= htonl(FW_WR_LEN16_V(DIV_ROUND_UP(len
, 16)));
1601 pos
= chcr_write_cpl_set_tcb_ulp(tx_info
, q
, tx_info
->tid
, pos
,
1603 TCB_SND_UNA_RAW_V(TCB_SND_UNA_RAW_M
),
1604 TCB_SND_UNA_RAW_V(0), 0);
1606 chcr_txq_advance(&q
->q
, ndesc
);
1607 cxgb4_ring_tx_db(tx_info
->adap
, &q
->q
, ndesc
);
1613 * chcr_end_part_handler: This handler will handle the record which
1614 * is complete or if record's end part is received. T6 adapter has a issue that
1615 * it can't send out TAG with partial record so if its an end part then we have
1616 * to send TAG as well and for which we need to fetch the complete record and
1617 * send it to crypto module.
1618 * @tx_info - driver specific tls info.
1619 * @skb - skb contains partial record.
1620 * @record - complete record of 16K size.
1622 * @mss - segment size in which TP needs to chop a packet.
1623 * @tcp_push_no_fin - tcp push if fin is not set.
1625 * @tls_end_offset - offset from end of the record.
1626 * @last wr : check if this is the last part of the skb going out.
1627 * return: NETDEV_TX_OK/NETDEV_TX_BUSY.
1629 static int chcr_end_part_handler(struct chcr_ktls_info
*tx_info
,
1630 struct sk_buff
*skb
,
1631 struct tls_record_info
*record
,
1632 u32 tcp_seq
, int mss
, bool tcp_push_no_fin
,
1633 struct sge_eth_txq
*q
,
1634 u32 tls_end_offset
, bool last_wr
)
1636 struct sk_buff
*nskb
= NULL
;
1637 /* check if it is a complete record */
1638 if (tls_end_offset
== record
->len
) {
1640 atomic64_inc(&tx_info
->adap
->chcr_stats
.ktls_tx_complete_pkts
);
1642 dev_kfree_skb_any(skb
);
1644 nskb
= alloc_skb(0, GFP_KERNEL
);
1646 return NETDEV_TX_BUSY
;
1647 /* copy complete record in skb */
1648 chcr_ktls_copy_record_in_skb(nskb
, record
);
1649 /* packet is being sent from the beginning, update the tcp_seq
1652 tcp_seq
= tls_record_start_seq(record
);
1653 /* reset snd una, so the middle record won't send the already
1656 if (chcr_ktls_update_snd_una(tx_info
, q
))
1658 atomic64_inc(&tx_info
->adap
->chcr_stats
.ktls_tx_end_pkts
);
1661 if (chcr_ktls_xmit_wr_complete(nskb
, tx_info
, q
, tcp_seq
,
1662 (last_wr
&& tcp_push_no_fin
),
1668 dev_kfree_skb_any(nskb
);
1669 return NETDEV_TX_BUSY
;
1673 * chcr_short_record_handler: This handler will take care of the records which
1674 * doesn't have end part (1st part or the middle part(/s) of a record). In such
1675 * cases, AES CTR will be used in place of AES GCM to send out partial packet.
1676 * This partial record might be the first part of the record, or the middle
1677 * part. In case of middle record we should fetch the prior data to make it 16
1678 * byte aligned. If it has a partial tls header or iv then get to the start of
1679 * tls header. And if it has partial TAG, then remove the complete TAG and send
1681 * There is one more possibility that it gets a partial header, send that
1682 * portion as a plaintext.
1683 * @tx_info - driver specific tls info.
1684 * @skb - skb contains partial record..
1685 * @record - complete record of 16K size.
1687 * @mss - segment size in which TP needs to chop a packet.
1688 * @tcp_push_no_fin - tcp push if fin is not set.
1690 * @tls_end_offset - offset from end of the record.
1691 * return: NETDEV_TX_OK/NETDEV_TX_BUSY.
1693 static int chcr_short_record_handler(struct chcr_ktls_info
*tx_info
,
1694 struct sk_buff
*skb
,
1695 struct tls_record_info
*record
,
1696 u32 tcp_seq
, int mss
, bool tcp_push_no_fin
,
1697 struct sge_eth_txq
*q
, u32 tls_end_offset
)
1699 u32 tls_rec_offset
= tcp_seq
- tls_record_start_seq(record
);
1700 u8 prior_data
[16] = {0};
1701 u32 prior_data_len
= 0;
1704 /* check if the skb is ending in middle of tag/HASH, its a big
1705 * trouble, send the packet before the HASH.
1707 int remaining_record
= tls_end_offset
- skb
->data_len
;
1709 if (remaining_record
> 0 &&
1710 remaining_record
< TLS_CIPHER_AES_GCM_128_TAG_SIZE
) {
1711 int trimmed_len
= skb
->data_len
-
1712 (TLS_CIPHER_AES_GCM_128_TAG_SIZE
- remaining_record
);
1713 struct sk_buff
*tmp_skb
= NULL
;
1714 /* don't process the pkt if it is only a partial tag */
1715 if (skb
->data_len
< TLS_CIPHER_AES_GCM_128_TAG_SIZE
)
1718 WARN_ON(trimmed_len
> skb
->data_len
);
1720 /* shift to those many bytes */
1721 tmp_skb
= alloc_skb(0, GFP_KERNEL
);
1722 if (unlikely(!tmp_skb
))
1725 chcr_ktls_skb_shift(tmp_skb
, skb
, trimmed_len
);
1726 /* free the last trimmed portion */
1727 dev_kfree_skb_any(skb
);
1729 atomic64_inc(&tx_info
->adap
->chcr_stats
.ktls_tx_trimmed_pkts
);
1731 data_len
= skb
->data_len
;
1732 /* check if the middle record's start point is 16 byte aligned. CTR
1733 * needs 16 byte aligned start point to start encryption.
1735 if (tls_rec_offset
) {
1736 /* there is an offset from start, means its a middle record */
1739 if (tls_rec_offset
< (TLS_HEADER_SIZE
+ tx_info
->iv_size
)) {
1740 prior_data_len
= tls_rec_offset
;
1746 (TLS_HEADER_SIZE
+ tx_info
->iv_size
))
1748 remaining
= tls_rec_offset
- prior_data_len
;
1751 /* if prior_data_len is not zero, means we need to fetch prior
1752 * data to make this record 16 byte aligned, or we need to reach
1755 if (prior_data_len
) {
1760 int frag_size
= 0, frag_delta
= 0;
1762 while (remaining
> 0) {
1763 frag_size
= skb_frag_size(&record
->frags
[i
]);
1764 if (remaining
< frag_size
)
1767 remaining
-= frag_size
;
1770 f
= &record
->frags
[i
];
1771 vaddr
= kmap_atomic(skb_frag_page(f
));
1773 data
= vaddr
+ skb_frag_off(f
) + remaining
;
1774 frag_delta
= skb_frag_size(f
) - remaining
;
1776 if (frag_delta
>= prior_data_len
) {
1777 memcpy(prior_data
, data
, prior_data_len
);
1778 kunmap_atomic(vaddr
);
1780 memcpy(prior_data
, data
, frag_delta
);
1781 kunmap_atomic(vaddr
);
1782 /* get the next page */
1783 f
= &record
->frags
[i
+ 1];
1784 vaddr
= kmap_atomic(skb_frag_page(f
));
1785 data
= vaddr
+ skb_frag_off(f
);
1786 memcpy(prior_data
+ frag_delta
,
1787 data
, (prior_data_len
- frag_delta
));
1788 kunmap_atomic(vaddr
);
1790 /* reset tcp_seq as per the prior_data_required len */
1791 tcp_seq
-= prior_data_len
;
1792 /* include prio_data_len for further calculation.
1794 data_len
+= prior_data_len
;
1796 /* reset snd una, so the middle record won't send the already
1799 if (chcr_ktls_update_snd_una(tx_info
, q
))
1801 atomic64_inc(&tx_info
->adap
->chcr_stats
.ktls_tx_middle_pkts
);
1803 /* Else means, its a partial first part of the record. Check if
1804 * its only the header, don't need to send for encryption then.
1806 if (data_len
<= TLS_HEADER_SIZE
+ tx_info
->iv_size
) {
1807 if (chcr_ktls_tx_plaintxt(tx_info
, skb
, tcp_seq
, mss
,
1816 atomic64_inc(&tx_info
->adap
->chcr_stats
.ktls_tx_start_pkts
);
1819 if (chcr_ktls_xmit_wr_short(skb
, tx_info
, q
, tcp_seq
, tcp_push_no_fin
,
1820 mss
, tls_rec_offset
, prior_data
,
1827 dev_kfree_skb_any(skb
);
1828 return NETDEV_TX_BUSY
;
1831 /* nic tls TX handler */
1832 int chcr_ktls_xmit(struct sk_buff
*skb
, struct net_device
*dev
)
1834 struct chcr_ktls_ofld_ctx_tx
*tx_ctx
;
1835 struct tcphdr
*th
= tcp_hdr(skb
);
1836 int data_len
, qidx
, ret
= 0, mss
;
1837 struct tls_record_info
*record
;
1838 struct chcr_stats_debug
*stats
;
1839 struct chcr_ktls_info
*tx_info
;
1840 u32 tls_end_offset
, tcp_seq
;
1841 struct tls_context
*tls_ctx
;
1842 struct sk_buff
*local_skb
;
1843 int new_connection_state
;
1844 struct sge_eth_txq
*q
;
1845 struct adapter
*adap
;
1846 unsigned long flags
;
1848 tcp_seq
= ntohl(th
->seq
);
1850 mss
= skb_is_gso(skb
) ? skb_shinfo(skb
)->gso_size
: skb
->data_len
;
1852 /* check if we haven't set it for ktls offload */
1853 if (!skb
->sk
|| !tls_is_sk_tx_device_offloaded(skb
->sk
))
1856 tls_ctx
= tls_get_ctx(skb
->sk
);
1857 if (unlikely(tls_ctx
->netdev
!= dev
))
1860 tx_ctx
= chcr_get_ktls_tx_context(tls_ctx
);
1861 tx_info
= tx_ctx
->chcr_info
;
1863 if (unlikely(!tx_info
))
1866 /* check the connection state, we don't need to pass new connection
1867 * state, state machine will check and update the new state if it is
1868 * stuck due to responses not received from HW.
1869 * Start the tx handling only if state is KTLS_CONN_TX_READY.
1871 new_connection_state
= chcr_ktls_update_connection_state(tx_info
, 0);
1872 if (new_connection_state
!= KTLS_CONN_TX_READY
)
1875 /* don't touch the original skb, make a new skb to extract each records
1876 * and send them separately.
1878 local_skb
= alloc_skb(0, GFP_KERNEL
);
1880 if (unlikely(!local_skb
))
1881 return NETDEV_TX_BUSY
;
1883 adap
= tx_info
->adap
;
1884 stats
= &adap
->chcr_stats
;
1886 qidx
= skb
->queue_mapping
;
1887 q
= &adap
->sge
.ethtxq
[qidx
+ tx_info
->first_qset
];
1888 cxgb4_reclaim_completed_tx(adap
, &q
->q
, true);
1889 /* if tcp options are set but finish is not send the options first */
1890 if (!th
->fin
&& chcr_ktls_check_tcp_options(th
)) {
1891 ret
= chcr_ktls_write_tcp_options(tx_info
, skb
, q
,
1894 return NETDEV_TX_BUSY
;
1897 ret
= chcr_ktls_xmit_tcb_cpls(tx_info
, q
, ntohl(th
->seq
),
1901 dev_kfree_skb_any(local_skb
);
1902 return NETDEV_TX_BUSY
;
1905 /* copy skb contents into local skb */
1906 chcr_ktls_skb_copy(skb
, local_skb
);
1908 /* go through the skb and send only one record at a time. */
1909 data_len
= skb
->data_len
;
1910 /* TCP segments can be in received either complete or partial.
1911 * chcr_end_part_handler will handle cases if complete record or end
1912 * part of the record is received. Incase of partial end part of record,
1913 * we will send the complete record again.
1919 cxgb4_reclaim_completed_tx(adap
, &q
->q
, true);
1921 spin_lock_irqsave(&tx_ctx
->base
.lock
, flags
);
1922 /* fetch the tls record */
1923 record
= tls_get_record(&tx_ctx
->base
, tcp_seq
,
1924 &tx_info
->record_no
);
1925 /* By the time packet reached to us, ACK is received, and record
1926 * won't be found in that case, handle it gracefully.
1928 if (unlikely(!record
)) {
1929 spin_unlock_irqrestore(&tx_ctx
->base
.lock
, flags
);
1930 atomic64_inc(&stats
->ktls_tx_drop_no_sync_data
);
1934 if (unlikely(tls_record_is_start_marker(record
))) {
1935 spin_unlock_irqrestore(&tx_ctx
->base
.lock
, flags
);
1936 atomic64_inc(&stats
->ktls_tx_skip_no_sync_data
);
1940 /* increase page reference count of the record, so that there
1941 * won't be any chance of page free in middle if in case stack
1942 * receives ACK and try to delete the record.
1944 for (i
= 0; i
< record
->num_frags
; i
++)
1945 __skb_frag_ref(&record
->frags
[i
]);
1947 spin_unlock_irqrestore(&tx_ctx
->base
.lock
, flags
);
1949 tls_end_offset
= record
->end_seq
- tcp_seq
;
1951 pr_debug("seq 0x%x, end_seq 0x%x prev_seq 0x%x, datalen 0x%x\n",
1952 tcp_seq
, record
->end_seq
, tx_info
->prev_seq
, data_len
);
1953 /* if a tls record is finishing in this SKB */
1954 if (tls_end_offset
<= data_len
) {
1955 struct sk_buff
*nskb
= NULL
;
1957 if (tls_end_offset
< data_len
) {
1958 nskb
= alloc_skb(0, GFP_KERNEL
);
1959 if (unlikely(!nskb
)) {
1964 chcr_ktls_skb_shift(nskb
, local_skb
,
1967 /* its the only record in this skb, directly
1972 ret
= chcr_end_part_handler(tx_info
, nskb
, record
,
1974 (!th
->fin
&& th
->psh
), q
,
1976 (nskb
== local_skb
));
1978 if (ret
&& nskb
!= local_skb
)
1979 dev_kfree_skb_any(local_skb
);
1981 data_len
-= tls_end_offset
;
1982 /* tcp_seq increment is required to handle next record.
1984 tcp_seq
+= tls_end_offset
;
1986 ret
= chcr_short_record_handler(tx_info
, local_skb
,
1987 record
, tcp_seq
, mss
,
1988 (!th
->fin
&& th
->psh
),
1993 /* clear the frag ref count which increased locally before */
1994 for (i
= 0; i
< record
->num_frags
; i
++) {
1995 /* clear the frag ref count */
1996 __skb_frag_unref(&record
->frags
[i
]);
1998 /* if any failure, come out from the loop. */
2001 /* length should never be less than 0 */
2002 WARN_ON(data_len
< 0);
2004 } while (data_len
> 0);
2006 tx_info
->prev_seq
= ntohl(th
->seq
) + skb
->data_len
;
2008 atomic64_inc(&stats
->ktls_tx_encrypted_packets
);
2009 atomic64_add(skb
->data_len
, &stats
->ktls_tx_encrypted_bytes
);
2011 /* tcp finish is set, send a separate tcp msg including all the options
2015 chcr_ktls_write_tcp_options(tx_info
, skb
, q
, tx_info
->tx_chan
);
2018 dev_kfree_skb_any(skb
);
2019 return NETDEV_TX_OK
;
2021 #endif /* CONFIG_CHELSIO_TLS_DEVICE */