1 // SPDX-License-Identifier: GPL-2.0-only
2 /* Copyright (C) 2020 Chelsio Communications. All rights reserved. */
4 #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
6 #include <linux/skbuff.h>
7 #include <linux/module.h>
8 #include <linux/highmem.h>
11 #include <linux/netdevice.h>
12 #include "chcr_ktls.h"
14 static LIST_HEAD(uld_ctx_list);
15 static DEFINE_MUTEX(dev_mutex);
17 static int chcr_init_tcb_fields(struct chcr_ktls_info *tx_info);
19 * chcr_ktls_save_keys: calculate and save crypto keys.
20 * @tx_info - driver specific tls info.
21 * @crypto_info - tls crypto information.
22 * @direction - TX/RX direction.
23 * return - SUCCESS/FAILURE.
25 static int chcr_ktls_save_keys(struct chcr_ktls_info *tx_info,
26 struct tls_crypto_info *crypto_info,
27 enum tls_offload_ctx_dir direction)
29 int ck_size, key_ctx_size, mac_key_size, keylen, ghash_size, ret;
30 unsigned char ghash_h[TLS_CIPHER_AES_GCM_256_TAG_SIZE];
31 struct tls12_crypto_info_aes_gcm_128 *info_128_gcm;
32 struct ktls_key_ctx *kctx = &tx_info->key_ctx;
33 struct crypto_cipher *cipher;
34 unsigned char *key, *salt;
36 switch (crypto_info->cipher_type) {
37 case TLS_CIPHER_AES_GCM_128:
39 (struct tls12_crypto_info_aes_gcm_128 *)crypto_info;
40 keylen = TLS_CIPHER_AES_GCM_128_KEY_SIZE;
41 ck_size = CHCR_KEYCTX_CIPHER_KEY_SIZE_128;
42 tx_info->salt_size = TLS_CIPHER_AES_GCM_128_SALT_SIZE;
43 mac_key_size = CHCR_KEYCTX_MAC_KEY_SIZE_128;
44 tx_info->iv_size = TLS_CIPHER_AES_GCM_128_IV_SIZE;
45 tx_info->iv = be64_to_cpu(*(__be64 *)info_128_gcm->iv);
47 ghash_size = TLS_CIPHER_AES_GCM_128_TAG_SIZE;
48 key = info_128_gcm->key;
49 salt = info_128_gcm->salt;
50 tx_info->record_no = *(u64 *)info_128_gcm->rec_seq;
52 /* The SCMD fields used when encrypting a full TLS
53 * record. Its a one time calculation till the
56 tx_info->scmd0_seqno_numivs =
57 SCMD_SEQ_NO_CTRL_V(CHCR_SCMD_SEQ_NO_CTRL_64BIT) |
58 SCMD_CIPH_AUTH_SEQ_CTRL_F |
59 SCMD_PROTO_VERSION_V(CHCR_SCMD_PROTO_VERSION_TLS) |
60 SCMD_CIPH_MODE_V(CHCR_SCMD_CIPHER_MODE_AES_GCM) |
61 SCMD_AUTH_MODE_V(CHCR_SCMD_AUTH_MODE_GHASH) |
62 SCMD_IV_SIZE_V(TLS_CIPHER_AES_GCM_128_IV_SIZE >> 1) |
65 /* keys will be sent inline. */
66 tx_info->scmd0_ivgen_hdrlen = SCMD_KEY_CTX_INLINE_F;
68 /* The SCMD fields used when encrypting a partial TLS
69 * record (no trailer and possibly a truncated payload).
71 tx_info->scmd0_short_seqno_numivs =
72 SCMD_CIPH_AUTH_SEQ_CTRL_F |
73 SCMD_PROTO_VERSION_V(CHCR_SCMD_PROTO_VERSION_GENERIC) |
74 SCMD_CIPH_MODE_V(CHCR_SCMD_CIPHER_MODE_AES_CTR) |
75 SCMD_IV_SIZE_V(AES_BLOCK_LEN >> 1);
77 tx_info->scmd0_short_ivgen_hdrlen =
78 tx_info->scmd0_ivgen_hdrlen | SCMD_AADIVDROP_F;
83 pr_err("GCM: cipher type 0x%x not supported\n",
84 crypto_info->cipher_type);
89 key_ctx_size = CHCR_KTLS_KEY_CTX_LEN +
90 roundup(keylen, 16) + ghash_size;
91 /* Calculate the H = CIPH(K, 0 repeated 16 times).
92 * It will go in key context
94 cipher = crypto_alloc_cipher("aes", 0, 0);
100 ret = crypto_cipher_setkey(cipher, key, keylen);
104 memset(ghash_h, 0, ghash_size);
105 crypto_cipher_encrypt_one(cipher, ghash_h, ghash_h);
107 /* fill the Key context */
108 if (direction == TLS_OFFLOAD_CTX_DIR_TX) {
109 kctx->ctx_hdr = FILL_KEY_CTX_HDR(ck_size,
117 memcpy(kctx->salt, salt, tx_info->salt_size);
118 memcpy(kctx->key, key, keylen);
119 memcpy(kctx->key + keylen, ghash_h, ghash_size);
120 tx_info->key_ctx_len = key_ctx_size;
123 crypto_free_cipher(cipher);
129 * chcr_ktls_act_open_req: creates TCB entry for ipv4 connection.
131 * @tx_info - driver specific tls info.
132 * @atid - connection active tid.
133 * return - send success/failure.
135 static int chcr_ktls_act_open_req(struct sock *sk,
136 struct chcr_ktls_info *tx_info,
139 struct inet_sock *inet = inet_sk(sk);
140 struct cpl_t6_act_open_req *cpl6;
141 struct cpl_act_open_req *cpl;
148 skb = alloc_skb(len, GFP_KERNEL);
151 /* mark it a control pkt */
152 set_wr_txq(skb, CPL_PRIORITY_CONTROL, tx_info->port_id);
154 cpl6 = __skb_put_zero(skb, len);
155 cpl = (struct cpl_act_open_req *)cpl6;
157 qid_atid = TID_QID_V(tx_info->rx_qid) |
159 OPCODE_TID(cpl) = htonl(MK_OPCODE_TID(CPL_ACT_OPEN_REQ, qid_atid));
160 cpl->local_port = inet->inet_sport;
161 cpl->peer_port = inet->inet_dport;
162 cpl->local_ip = inet->inet_rcv_saddr;
163 cpl->peer_ip = inet->inet_daddr;
165 /* fill first 64 bit option field. */
166 options = TCAM_BYPASS_F | ULP_MODE_V(ULP_MODE_NONE) | NON_OFFLOAD_F |
167 SMAC_SEL_V(tx_info->smt_idx) | TX_CHAN_V(tx_info->tx_chan);
168 cpl->opt0 = cpu_to_be64(options);
170 /* next 64 bit option field. */
172 TX_QUEUE_V(tx_info->adap->params.tp.tx_modq[tx_info->tx_chan]);
173 cpl->opt2 = htonl(options);
175 return cxgb4_l2t_send(tx_info->netdev, skb, tx_info->l2te);
178 #if IS_ENABLED(CONFIG_IPV6)
180 * chcr_ktls_act_open_req6: creates TCB entry for ipv6 connection.
182 * @tx_info - driver specific tls info.
183 * @atid - connection active tid.
184 * return - send success/failure.
186 static int chcr_ktls_act_open_req6(struct sock *sk,
187 struct chcr_ktls_info *tx_info,
190 struct inet_sock *inet = inet_sk(sk);
191 struct cpl_t6_act_open_req6 *cpl6;
192 struct cpl_act_open_req6 *cpl;
199 skb = alloc_skb(len, GFP_KERNEL);
202 /* mark it a control pkt */
203 set_wr_txq(skb, CPL_PRIORITY_CONTROL, tx_info->port_id);
205 cpl6 = __skb_put_zero(skb, len);
206 cpl = (struct cpl_act_open_req6 *)cpl6;
208 qid_atid = TID_QID_V(tx_info->rx_qid) | TID_TID_V(atid);
209 OPCODE_TID(cpl) = htonl(MK_OPCODE_TID(CPL_ACT_OPEN_REQ6, qid_atid));
210 cpl->local_port = inet->inet_sport;
211 cpl->peer_port = inet->inet_dport;
212 cpl->local_ip_hi = *(__be64 *)&sk->sk_v6_rcv_saddr.in6_u.u6_addr8[0];
213 cpl->local_ip_lo = *(__be64 *)&sk->sk_v6_rcv_saddr.in6_u.u6_addr8[8];
214 cpl->peer_ip_hi = *(__be64 *)&sk->sk_v6_daddr.in6_u.u6_addr8[0];
215 cpl->peer_ip_lo = *(__be64 *)&sk->sk_v6_daddr.in6_u.u6_addr8[8];
217 /* first 64 bit option field. */
218 options = TCAM_BYPASS_F | ULP_MODE_V(ULP_MODE_NONE) | NON_OFFLOAD_F |
219 SMAC_SEL_V(tx_info->smt_idx) | TX_CHAN_V(tx_info->tx_chan);
220 cpl->opt0 = cpu_to_be64(options);
221 /* next 64 bit option field. */
223 TX_QUEUE_V(tx_info->adap->params.tp.tx_modq[tx_info->tx_chan]);
224 cpl->opt2 = htonl(options);
226 return cxgb4_l2t_send(tx_info->netdev, skb, tx_info->l2te);
228 #endif /* #if IS_ENABLED(CONFIG_IPV6) */
231 * chcr_setup_connection: create a TCB entry so that TP will form tcp packets.
233 * @tx_info - driver specific tls info.
234 * return: NET_TX_OK/NET_XMIT_DROP
236 static int chcr_setup_connection(struct sock *sk,
237 struct chcr_ktls_info *tx_info)
239 struct tid_info *t = &tx_info->adap->tids;
242 atid = cxgb4_alloc_atid(t, tx_info);
246 tx_info->atid = atid;
248 if (tx_info->ip_family == AF_INET) {
249 ret = chcr_ktls_act_open_req(sk, tx_info, atid);
250 #if IS_ENABLED(CONFIG_IPV6)
252 ret = cxgb4_clip_get(tx_info->netdev, (const u32 *)
253 &sk->sk_v6_rcv_saddr,
257 ret = chcr_ktls_act_open_req6(sk, tx_info, atid);
261 /* if return type is NET_XMIT_CN, msg will be sent but delayed, mark ret
262 * success, if any other return type clear atid and return that failure.
265 if (ret == NET_XMIT_CN) {
268 #if IS_ENABLED(CONFIG_IPV6)
269 /* clear clip entry */
270 if (tx_info->ip_family == AF_INET6)
271 cxgb4_clip_release(tx_info->netdev,
273 &sk->sk_v6_rcv_saddr,
276 cxgb4_free_atid(t, atid);
284 * chcr_set_tcb_field: update tcb fields.
285 * @tx_info - driver specific tls info.
287 * @mask - TCB word related mask.
288 * @val - TCB word related value.
289 * @no_reply - set 1 if not looking for TP response.
291 static int chcr_set_tcb_field(struct chcr_ktls_info *tx_info, u16 word,
292 u64 mask, u64 val, int no_reply)
294 struct cpl_set_tcb_field *req;
297 skb = alloc_skb(sizeof(struct cpl_set_tcb_field), GFP_ATOMIC);
301 req = (struct cpl_set_tcb_field *)__skb_put_zero(skb, sizeof(*req));
302 INIT_TP_WR_CPL(req, CPL_SET_TCB_FIELD, tx_info->tid);
303 req->reply_ctrl = htons(QUEUENO_V(tx_info->rx_qid) |
304 NO_REPLY_V(no_reply));
305 req->word_cookie = htons(TCB_WORD_V(word));
306 req->mask = cpu_to_be64(mask);
307 req->val = cpu_to_be64(val);
309 set_wr_txq(skb, CPL_PRIORITY_CONTROL, tx_info->port_id);
310 return cxgb4_ofld_send(tx_info->netdev, skb);
314 * chcr_ktls_mark_tcb_close: mark tcb state to CLOSE
315 * @tx_info - driver specific tls info.
316 * return: NET_TX_OK/NET_XMIT_DROP.
318 static int chcr_ktls_mark_tcb_close(struct chcr_ktls_info *tx_info)
320 return chcr_set_tcb_field(tx_info, TCB_T_STATE_W,
321 TCB_T_STATE_V(TCB_T_STATE_M),
322 CHCR_TCB_STATE_CLOSED, 1);
326 * chcr_ktls_dev_del: call back for tls_dev_del.
327 * Remove the tid and l2t entry and close the connection.
328 * it per connection basis.
329 * @netdev - net device.
330 * @tls_cts - tls context.
331 * @direction - TX/RX crypto direction
333 static void chcr_ktls_dev_del(struct net_device *netdev,
334 struct tls_context *tls_ctx,
335 enum tls_offload_ctx_dir direction)
337 struct chcr_ktls_ofld_ctx_tx *tx_ctx =
338 chcr_get_ktls_tx_context(tls_ctx);
339 struct chcr_ktls_info *tx_info = tx_ctx->chcr_info;
340 struct ch_ktls_port_stats_debug *port_stats;
345 /* clear l2t entry */
347 cxgb4_l2t_release(tx_info->l2te);
349 #if IS_ENABLED(CONFIG_IPV6)
350 /* clear clip entry */
351 if (tx_info->ip_family == AF_INET6)
352 cxgb4_clip_release(netdev, (const u32 *)
353 &tx_info->sk->sk_v6_rcv_saddr,
358 if (tx_info->tid != -1) {
359 /* clear tcb state and then release tid */
360 chcr_ktls_mark_tcb_close(tx_info);
361 cxgb4_remove_tid(&tx_info->adap->tids, tx_info->tx_chan,
362 tx_info->tid, tx_info->ip_family);
365 port_stats = &tx_info->adap->ch_ktls_stats.ktls_port[tx_info->port_id];
366 atomic64_inc(&port_stats->ktls_tx_connection_close);
368 tx_ctx->chcr_info = NULL;
369 /* release module refcount */
370 module_put(THIS_MODULE);
374 * chcr_ktls_dev_add: call back for tls_dev_add.
375 * Create a tcb entry for TP. Also add l2t entry for the connection. And
376 * generate keys & save those keys locally.
377 * @netdev - net device.
378 * @tls_cts - tls context.
379 * @direction - TX/RX crypto direction
380 * return: SUCCESS/FAILURE.
382 static int chcr_ktls_dev_add(struct net_device *netdev, struct sock *sk,
383 enum tls_offload_ctx_dir direction,
384 struct tls_crypto_info *crypto_info,
385 u32 start_offload_tcp_sn)
387 struct tls_context *tls_ctx = tls_get_ctx(sk);
388 struct ch_ktls_port_stats_debug *port_stats;
389 struct chcr_ktls_ofld_ctx_tx *tx_ctx;
390 struct chcr_ktls_info *tx_info;
391 struct dst_entry *dst;
392 struct adapter *adap;
393 struct port_info *pi;
398 tx_ctx = chcr_get_ktls_tx_context(tls_ctx);
400 pi = netdev_priv(netdev);
402 port_stats = &adap->ch_ktls_stats.ktls_port[pi->port_id];
403 atomic64_inc(&port_stats->ktls_tx_connection_open);
405 if (direction == TLS_OFFLOAD_CTX_DIR_RX) {
406 pr_err("not expecting for RX direction\n");
410 if (tx_ctx->chcr_info)
413 tx_info = kvzalloc(sizeof(*tx_info), GFP_KERNEL);
418 spin_lock_init(&tx_info->lock);
419 /* initialize tid and atid to -1, 0 is a also a valid id. */
423 tx_info->adap = adap;
424 tx_info->netdev = netdev;
425 tx_info->first_qset = pi->first_qset;
426 tx_info->tx_chan = pi->tx_chan;
427 tx_info->smt_idx = pi->smt_idx;
428 tx_info->port_id = pi->port_id;
429 tx_info->prev_ack = 0;
430 tx_info->prev_win = 0;
432 tx_info->rx_qid = chcr_get_first_rx_qid(adap);
433 if (unlikely(tx_info->rx_qid < 0))
436 tx_info->prev_seq = start_offload_tcp_sn;
437 tx_info->tcp_start_seq_number = start_offload_tcp_sn;
439 /* save crypto keys */
440 ret = chcr_ktls_save_keys(tx_info, crypto_info, direction);
445 if (sk->sk_family == AF_INET) {
446 memcpy(daaddr, &sk->sk_daddr, 4);
447 tx_info->ip_family = AF_INET;
448 #if IS_ENABLED(CONFIG_IPV6)
450 if (!sk->sk_ipv6only &&
451 ipv6_addr_type(&sk->sk_v6_daddr) == IPV6_ADDR_MAPPED) {
452 memcpy(daaddr, &sk->sk_daddr, 4);
453 tx_info->ip_family = AF_INET;
455 memcpy(daaddr, sk->sk_v6_daddr.in6_u.u6_addr8, 16);
456 tx_info->ip_family = AF_INET6;
461 /* get the l2t index */
462 dst = sk_dst_get(sk);
464 pr_err("DST entry not found\n");
467 n = dst_neigh_lookup(dst, daaddr);
469 pr_err("neighbour not found\n");
473 tx_info->l2te = cxgb4_l2t_get(adap->l2t, n, n->dev, 0);
478 if (!tx_info->l2te) {
479 pr_err("l2t entry not found\n");
483 /* Driver shouldn't be removed until any single connection exists */
484 if (!try_module_get(THIS_MODULE))
487 init_completion(&tx_info->completion);
488 /* create a filter and call cxgb4_l2t_send to send the packet out, which
489 * will take care of updating l2t entry in hw if not already done.
491 tx_info->open_state = CH_KTLS_OPEN_PENDING;
493 if (chcr_setup_connection(sk, tx_info))
497 wait_for_completion_timeout(&tx_info->completion, 30 * HZ);
498 spin_lock_bh(&tx_info->lock);
499 if (tx_info->open_state) {
500 /* need to wait for hw response, can't free tx_info yet. */
501 if (tx_info->open_state == CH_KTLS_OPEN_PENDING)
502 tx_info->pending_close = true;
503 /* free the lock after the cleanup */
506 spin_unlock_bh(&tx_info->lock);
509 reinit_completion(&tx_info->completion);
510 /* mark it pending for hw response */
511 tx_info->open_state = CH_KTLS_OPEN_PENDING;
513 if (chcr_init_tcb_fields(tx_info))
517 wait_for_completion_timeout(&tx_info->completion, 30 * HZ);
518 spin_lock_bh(&tx_info->lock);
519 if (tx_info->open_state) {
520 /* need to wait for hw response, can't free tx_info yet. */
521 tx_info->pending_close = true;
522 /* free the lock after cleanup */
525 spin_unlock_bh(&tx_info->lock);
527 if (!cxgb4_check_l2t_valid(tx_info->l2te))
530 atomic64_inc(&port_stats->ktls_tx_ctx);
531 tx_ctx->chcr_info = tx_info;
536 chcr_ktls_mark_tcb_close(tx_info);
537 #if IS_ENABLED(CONFIG_IPV6)
538 /* clear clip entry */
539 if (tx_info->ip_family == AF_INET6)
540 cxgb4_clip_release(netdev, (const u32 *)
541 &sk->sk_v6_rcv_saddr,
544 cxgb4_remove_tid(&tx_info->adap->tids, tx_info->tx_chan,
545 tx_info->tid, tx_info->ip_family);
548 /* release module refcount */
549 module_put(THIS_MODULE);
551 cxgb4_l2t_release(tx_info->l2te);
553 if (tx_info->pending_close)
554 spin_unlock_bh(&tx_info->lock);
558 atomic64_inc(&port_stats->ktls_tx_connection_fail);
563 * chcr_init_tcb_fields: Initialize tcb fields to handle TCP seq number
565 * @tx_info - driver specific tls info.
566 * return: NET_TX_OK/NET_XMIT_DROP
568 static int chcr_init_tcb_fields(struct chcr_ktls_info *tx_info)
572 /* set tcb in offload and bypass */
574 chcr_set_tcb_field(tx_info, TCB_T_FLAGS_W,
575 TCB_T_FLAGS_V(TF_CORE_BYPASS_F | TF_NON_OFFLOAD_F),
576 TCB_T_FLAGS_V(TF_CORE_BYPASS_F), 1);
579 /* reset snd_una and snd_next fields in tcb */
580 ret = chcr_set_tcb_field(tx_info, TCB_SND_UNA_RAW_W,
581 TCB_SND_NXT_RAW_V(TCB_SND_NXT_RAW_M) |
582 TCB_SND_UNA_RAW_V(TCB_SND_UNA_RAW_M),
588 ret = chcr_set_tcb_field(tx_info, TCB_SND_MAX_RAW_W,
589 TCB_SND_MAX_RAW_V(TCB_SND_MAX_RAW_M),
594 /* update l2t index and request for tp reply to confirm tcb is
595 * initialised to handle tx traffic.
597 ret = chcr_set_tcb_field(tx_info, TCB_L2T_IX_W,
598 TCB_L2T_IX_V(TCB_L2T_IX_M),
599 TCB_L2T_IX_V(tx_info->l2te->idx), 0);
604 * chcr_ktls_cpl_act_open_rpl: connection reply received from TP.
606 static int chcr_ktls_cpl_act_open_rpl(struct adapter *adap,
607 unsigned char *input)
609 const struct cpl_act_open_rpl *p = (void *)input;
610 struct chcr_ktls_info *tx_info = NULL;
611 unsigned int atid, tid, status;
615 status = AOPEN_STATUS_G(ntohl(p->atid_status));
616 atid = TID_TID_G(AOPEN_ATID_G(ntohl(p->atid_status)));
619 tx_info = lookup_atid(t, atid);
621 if (!tx_info || tx_info->atid != atid) {
622 pr_err("%s: incorrect tx_info or atid\n", __func__);
626 cxgb4_free_atid(t, atid);
629 spin_lock(&tx_info->lock);
630 /* HW response is very close, finish pending cleanup */
631 if (tx_info->pending_close) {
632 spin_unlock(&tx_info->lock);
634 /* it's a late success, tcb status is establised,
637 chcr_ktls_mark_tcb_close(tx_info);
638 cxgb4_remove_tid(&tx_info->adap->tids, tx_info->tx_chan,
639 tid, tx_info->ip_family);
647 cxgb4_insert_tid(t, tx_info, tx_info->tid, tx_info->ip_family);
648 tx_info->open_state = CH_KTLS_OPEN_SUCCESS;
650 tx_info->open_state = CH_KTLS_OPEN_FAILURE;
652 spin_unlock(&tx_info->lock);
654 complete(&tx_info->completion);
659 * chcr_ktls_cpl_set_tcb_rpl: TCB reply received from TP.
661 static int chcr_ktls_cpl_set_tcb_rpl(struct adapter *adap, unsigned char *input)
663 const struct cpl_set_tcb_rpl *p = (void *)input;
664 struct chcr_ktls_info *tx_info = NULL;
671 tx_info = lookup_tid(t, tid);
673 if (!tx_info || tx_info->tid != tid) {
674 pr_err("%s: incorrect tx_info or tid\n", __func__);
678 spin_lock(&tx_info->lock);
679 if (tx_info->pending_close) {
680 spin_unlock(&tx_info->lock);
684 tx_info->open_state = false;
685 spin_unlock(&tx_info->lock);
687 complete(&tx_info->completion);
691 static void *__chcr_write_cpl_set_tcb_ulp(struct chcr_ktls_info *tx_info,
692 u32 tid, void *pos, u16 word, u64 mask,
695 struct cpl_set_tcb_field_core *cpl;
696 struct ulptx_idata *idata;
697 struct ulp_txpkt *txpkt;
701 txpkt->cmd_dest = htonl(ULPTX_CMD_V(ULP_TX_PKT) | ULP_TXPKT_DEST_V(0));
702 txpkt->len = htonl(DIV_ROUND_UP(CHCR_SET_TCB_FIELD_LEN, 16));
704 /* ULPTX_IDATA sub-command */
705 idata = (struct ulptx_idata *)(txpkt + 1);
706 idata->cmd_more = htonl(ULPTX_CMD_V(ULP_TX_SC_IMM));
707 idata->len = htonl(sizeof(*cpl));
711 /* CPL_SET_TCB_FIELD */
712 OPCODE_TID(cpl) = htonl(MK_OPCODE_TID(CPL_SET_TCB_FIELD, tid));
713 cpl->reply_ctrl = htons(QUEUENO_V(tx_info->rx_qid) |
715 cpl->word_cookie = htons(TCB_WORD_V(word));
716 cpl->mask = cpu_to_be64(mask);
717 cpl->val = cpu_to_be64(val);
720 idata = (struct ulptx_idata *)(cpl + 1);
721 idata->cmd_more = htonl(ULPTX_CMD_V(ULP_TX_SC_NOOP));
722 idata->len = htonl(0);
730 * chcr_write_cpl_set_tcb_ulp: update tcb values.
731 * TCB is responsible to create tcp headers, so all the related values
732 * should be correctly updated.
733 * @tx_info - driver specific tls info.
734 * @q - tx queue on which packet is going out.
735 * @tid - TCB identifier.
736 * @pos - current index where should we start writing.
738 * @mask - TCB word related mask.
739 * @val - TCB word related value.
740 * @reply - set 1 if looking for TP response.
741 * return - next position to write.
743 static void *chcr_write_cpl_set_tcb_ulp(struct chcr_ktls_info *tx_info,
744 struct sge_eth_txq *q, u32 tid,
745 void *pos, u16 word, u64 mask,
748 int left = (void *)q->q.stat - pos;
750 if (unlikely(left < CHCR_SET_TCB_FIELD_LEN)) {
756 __chcr_write_cpl_set_tcb_ulp(tx_info, tid, buf, word,
759 return chcr_copy_to_txd(buf, &q->q, pos,
760 CHCR_SET_TCB_FIELD_LEN);
764 pos = __chcr_write_cpl_set_tcb_ulp(tx_info, tid, pos, word,
767 /* check again if we are at the end of the queue */
768 if (left == CHCR_SET_TCB_FIELD_LEN)
775 * chcr_ktls_xmit_tcb_cpls: update tcb entry so that TP will create the header
776 * with updated values like tcp seq, ack, window etc.
777 * @tx_info - driver specific tls info.
782 * return: NETDEV_TX_BUSY/NET_TX_OK.
784 static int chcr_ktls_xmit_tcb_cpls(struct chcr_ktls_info *tx_info,
785 struct sge_eth_txq *q, u64 tcp_seq,
786 u64 tcp_ack, u64 tcp_win)
788 bool first_wr = ((tx_info->prev_ack == 0) && (tx_info->prev_win == 0));
789 struct ch_ktls_port_stats_debug *port_stats;
790 u32 len, cpl = 0, ndesc, wr_len;
791 struct fw_ulptx_wr *wr;
795 wr_len = sizeof(*wr);
796 /* there can be max 4 cpls, check if we have enough credits */
797 len = wr_len + 4 * roundup(CHCR_SET_TCB_FIELD_LEN, 16);
798 ndesc = DIV_ROUND_UP(len, 64);
800 credits = chcr_txq_avail(&q->q) - ndesc;
801 if (unlikely(credits < 0)) {
802 chcr_eth_txq_stop(q);
803 return NETDEV_TX_BUSY;
806 pos = &q->q.desc[q->q.pidx];
807 /* make space for WR, we'll fill it later when we know all the cpls
808 * being sent out and have complete length.
812 /* update tx_max if its a re-transmit or the first wr */
813 if (first_wr || tcp_seq != tx_info->prev_seq) {
814 pos = chcr_write_cpl_set_tcb_ulp(tx_info, q, tx_info->tid, pos,
816 TCB_TX_MAX_V(TCB_TX_MAX_M),
817 TCB_TX_MAX_V(tcp_seq), 0);
820 /* reset snd una if it's a re-transmit pkt */
821 if (tcp_seq != tx_info->prev_seq) {
824 &tx_info->adap->ch_ktls_stats.ktls_port[tx_info->port_id];
825 pos = chcr_write_cpl_set_tcb_ulp(tx_info, q, tx_info->tid, pos,
829 TCB_SND_UNA_RAW_V(0), 0);
830 atomic64_inc(&port_stats->ktls_tx_ooo);
834 if (first_wr || tx_info->prev_ack != tcp_ack) {
835 pos = chcr_write_cpl_set_tcb_ulp(tx_info, q, tx_info->tid, pos,
837 TCB_RCV_NXT_V(TCB_RCV_NXT_M),
838 TCB_RCV_NXT_V(tcp_ack), 0);
839 tx_info->prev_ack = tcp_ack;
842 /* update receive window */
843 if (first_wr || tx_info->prev_win != tcp_win) {
844 pos = chcr_write_cpl_set_tcb_ulp(tx_info, q, tx_info->tid, pos,
846 TCB_RCV_WND_V(TCB_RCV_WND_M),
847 TCB_RCV_WND_V(tcp_win), 0);
848 tx_info->prev_win = tcp_win;
853 /* get the actual length */
854 len = wr_len + cpl * roundup(CHCR_SET_TCB_FIELD_LEN, 16);
856 wr->op_to_compl = htonl(FW_WR_OP_V(FW_ULPTX_WR));
858 /* fill len in wr field */
859 wr->flowid_len16 = htonl(FW_WR_LEN16_V(DIV_ROUND_UP(len, 16)));
861 ndesc = DIV_ROUND_UP(len, 64);
862 chcr_txq_advance(&q->q, ndesc);
863 cxgb4_ring_tx_db(tx_info->adap, &q->q, ndesc);
870 * @nskb - new skb where the frags to be added.
871 * @skb - old skb from which frags will be copied.
873 static void chcr_ktls_skb_copy(struct sk_buff *skb, struct sk_buff *nskb)
877 for (i = 0; i < skb_shinfo(skb)->nr_frags; i++) {
878 skb_shinfo(nskb)->frags[i] = skb_shinfo(skb)->frags[i];
879 __skb_frag_ref(&skb_shinfo(nskb)->frags[i]);
882 skb_shinfo(nskb)->nr_frags = skb_shinfo(skb)->nr_frags;
883 nskb->len += skb->data_len;
884 nskb->data_len = skb->data_len;
885 nskb->truesize += skb->data_len;
889 * chcr_ktls_get_tx_flits
890 * returns number of flits to be sent out, it includes key context length, WR
891 * size and skb fragments.
894 chcr_ktls_get_tx_flits(const struct sk_buff *skb, unsigned int key_ctx_len)
896 return chcr_sgl_len(skb_shinfo(skb)->nr_frags) +
897 DIV_ROUND_UP(key_ctx_len + CHCR_KTLS_WR_SIZE, 8);
901 * chcr_ktls_check_tcp_options: To check if there is any TCP option availbale
902 * other than timestamp.
903 * @skb - skb contains partial record..
907 chcr_ktls_check_tcp_options(struct tcphdr *tcp)
909 int cnt, opt, optlen;
912 cp = (u_char *)(tcp + 1);
913 cnt = (tcp->doff << 2) - sizeof(struct tcphdr);
914 for (; cnt > 0; cnt -= optlen, cp += optlen) {
916 if (opt == TCPOPT_EOL)
918 if (opt == TCPOPT_NOP) {
924 if (optlen < 2 || optlen > cnt)
938 * chcr_ktls_write_tcp_options : TP can't send out all the options, we need to
939 * send out separately.
940 * @tx_info - driver specific tls info.
941 * @skb - skb contains partial record..
943 * @tx_chan - channel number.
944 * return: NETDEV_TX_OK/NETDEV_TX_BUSY.
947 chcr_ktls_write_tcp_options(struct chcr_ktls_info *tx_info, struct sk_buff *skb,
948 struct sge_eth_txq *q, uint32_t tx_chan)
950 struct fw_eth_tx_pkt_wr *wr;
951 struct cpl_tx_pkt_core *cpl;
952 u32 ctrl, iplen, maclen;
953 #if IS_ENABLED(CONFIG_IPV6)
964 iplen = skb_network_header_len(skb);
965 maclen = skb_mac_header_len(skb);
967 /* packet length = eth hdr len + ip hdr len + tcp hdr len
968 * (including options).
970 pktlen = skb->len - skb->data_len;
972 ctrl = sizeof(*cpl) + pktlen;
973 len16 = DIV_ROUND_UP(sizeof(*wr) + ctrl, 16);
974 /* check how many descriptors needed */
975 ndesc = DIV_ROUND_UP(len16, 4);
977 credits = chcr_txq_avail(&q->q) - ndesc;
978 if (unlikely(credits < 0)) {
979 chcr_eth_txq_stop(q);
980 return NETDEV_TX_BUSY;
983 pos = &q->q.desc[q->q.pidx];
986 /* Firmware work request header */
987 wr->op_immdlen = htonl(FW_WR_OP_V(FW_ETH_TX_PKT_WR) |
988 FW_WR_IMMDLEN_V(ctrl));
990 wr->equiq_to_len16 = htonl(FW_WR_LEN16_V(len16));
993 cpl = (void *)(wr + 1);
996 cpl->ctrl0 = htonl(TXPKT_OPCODE_V(CPL_TX_PKT) | TXPKT_INTF_V(tx_chan) |
997 TXPKT_PF_V(tx_info->adap->pf));
999 cpl->len = htons(pktlen);
1000 /* checksum offload */
1005 memcpy(buf, skb->data, pktlen);
1006 if (tx_info->ip_family == AF_INET) {
1007 /* we need to correct ip header len */
1008 ip = (struct iphdr *)(buf + maclen);
1009 ip->tot_len = htons(pktlen - maclen);
1010 #if IS_ENABLED(CONFIG_IPV6)
1012 ip6 = (struct ipv6hdr *)(buf + maclen);
1013 ip6->payload_len = htons(pktlen - maclen - iplen);
1016 /* now take care of the tcp header, if fin is not set then clear push
1017 * bit as well, and if fin is set, it will be sent at the last so we
1018 * need to update the tcp sequence number as per the last packet.
1020 tcp = (struct tcphdr *)(buf + maclen + iplen);
1025 tcp->seq = htonl(tx_info->prev_seq);
1027 chcr_copy_to_txd(buf, &q->q, pos, pktlen);
1029 chcr_txq_advance(&q->q, ndesc);
1030 cxgb4_ring_tx_db(tx_info->adap, &q->q, ndesc);
1034 /* chcr_ktls_skb_shift - Shifts request length paged data from skb to another.
1035 * @tgt- buffer into which tail data gets added
1036 * @skb- buffer from which the paged data comes from
1037 * @shiftlen- shift up to this many bytes
1039 static int chcr_ktls_skb_shift(struct sk_buff *tgt, struct sk_buff *skb,
1042 skb_frag_t *fragfrom, *fragto;
1045 WARN_ON(shiftlen > skb->data_len);
1050 fragfrom = &skb_shinfo(skb)->frags[from];
1052 while ((todo > 0) && (from < skb_shinfo(skb)->nr_frags)) {
1053 fragfrom = &skb_shinfo(skb)->frags[from];
1054 fragto = &skb_shinfo(tgt)->frags[to];
1056 if (todo >= skb_frag_size(fragfrom)) {
1057 *fragto = *fragfrom;
1058 todo -= skb_frag_size(fragfrom);
1063 __skb_frag_ref(fragfrom);
1064 skb_frag_page_copy(fragto, fragfrom);
1065 skb_frag_off_copy(fragto, fragfrom);
1066 skb_frag_size_set(fragto, todo);
1068 skb_frag_off_add(fragfrom, todo);
1069 skb_frag_size_sub(fragfrom, todo);
1077 /* Ready to "commit" this state change to tgt */
1078 skb_shinfo(tgt)->nr_frags = to;
1080 /* Reposition in the original skb */
1082 while (from < skb_shinfo(skb)->nr_frags)
1083 skb_shinfo(skb)->frags[to++] = skb_shinfo(skb)->frags[from++];
1085 skb_shinfo(skb)->nr_frags = to;
1087 WARN_ON(todo > 0 && !skb_shinfo(skb)->nr_frags);
1089 skb->len -= shiftlen;
1090 skb->data_len -= shiftlen;
1091 skb->truesize -= shiftlen;
1092 tgt->len += shiftlen;
1093 tgt->data_len += shiftlen;
1094 tgt->truesize += shiftlen;
1100 * chcr_ktls_xmit_wr_complete: This sends out the complete record. If an skb
1101 * received has partial end part of the record, send out the complete record, so
1102 * that crypto block will be able to generate TAG/HASH.
1103 * @skb - segment which has complete or partial end part.
1104 * @tx_info - driver specific tls info.
1107 * @tcp_push - tcp push bit.
1108 * @mss - segment size.
1109 * return: NETDEV_TX_BUSY/NET_TX_OK.
1111 static int chcr_ktls_xmit_wr_complete(struct sk_buff *skb,
1112 struct chcr_ktls_info *tx_info,
1113 struct sge_eth_txq *q, u32 tcp_seq,
1114 bool tcp_push, u32 mss)
1116 u32 len16, wr_mid = 0, flits = 0, ndesc, cipher_start;
1117 struct adapter *adap = tx_info->adap;
1118 int credits, left, last_desc;
1119 struct tx_sw_desc *sgl_sdesc;
1120 struct cpl_tx_data *tx_data;
1121 struct cpl_tx_sec_pdu *cpl;
1122 struct ulptx_idata *idata;
1123 struct ulp_txpkt *ulptx;
1124 struct fw_ulptx_wr *wr;
1128 /* get the number of flits required */
1129 flits = chcr_ktls_get_tx_flits(skb, tx_info->key_ctx_len);
1130 /* number of descriptors */
1131 ndesc = chcr_flits_to_desc(flits);
1132 /* check if enough credits available */
1133 credits = chcr_txq_avail(&q->q) - ndesc;
1134 if (unlikely(credits < 0)) {
1135 chcr_eth_txq_stop(q);
1136 return NETDEV_TX_BUSY;
1139 if (unlikely(credits < ETHTXQ_STOP_THRES)) {
1140 /* Credits are below the threshold vaues, stop the queue after
1141 * injecting the Work Request for this packet.
1143 chcr_eth_txq_stop(q);
1144 wr_mid |= FW_WR_EQUEQ_F | FW_WR_EQUIQ_F;
1147 last_desc = q->q.pidx + ndesc - 1;
1148 if (last_desc >= q->q.size)
1149 last_desc -= q->q.size;
1150 sgl_sdesc = &q->q.sdesc[last_desc];
1152 if (unlikely(cxgb4_map_skb(adap->pdev_dev, skb, sgl_sdesc->addr) < 0)) {
1153 memset(sgl_sdesc->addr, 0, sizeof(sgl_sdesc->addr));
1155 return NETDEV_TX_BUSY;
1158 pos = &q->q.desc[q->q.pidx];
1159 end = (u64 *)pos + flits;
1162 /* WR will need len16 */
1163 len16 = DIV_ROUND_UP(flits, 2);
1164 wr->op_to_compl = htonl(FW_WR_OP_V(FW_ULPTX_WR));
1165 wr->flowid_len16 = htonl(wr_mid | FW_WR_LEN16_V(len16));
1170 ulptx->cmd_dest = htonl(ULPTX_CMD_V(ULP_TX_PKT) |
1171 ULP_TXPKT_CHANNELID_V(tx_info->port_id) |
1172 ULP_TXPKT_FID_V(q->q.cntxt_id) |
1174 ulptx->len = htonl(len16 - 1);
1175 /* ULPTX_IDATA sub-command */
1176 idata = (struct ulptx_idata *)(ulptx + 1);
1177 idata->cmd_more = htonl(ULPTX_CMD_V(ULP_TX_SC_IMM) | ULP_TX_SC_MORE_F);
1178 /* idata length will include cpl_tx_sec_pdu + key context size +
1179 * cpl_tx_data header.
1181 idata->len = htonl(sizeof(*cpl) + tx_info->key_ctx_len +
1184 cpl = (struct cpl_tx_sec_pdu *)(idata + 1);
1185 cpl->op_ivinsrtofst =
1186 htonl(CPL_TX_SEC_PDU_OPCODE_V(CPL_TX_SEC_PDU) |
1187 CPL_TX_SEC_PDU_CPLLEN_V(CHCR_CPL_TX_SEC_PDU_LEN_64BIT) |
1188 CPL_TX_SEC_PDU_PLACEHOLDER_V(1) |
1189 CPL_TX_SEC_PDU_IVINSRTOFST_V(TLS_HEADER_SIZE + 1));
1190 cpl->pldlen = htonl(skb->data_len);
1192 /* encryption should start after tls header size + iv size */
1193 cipher_start = TLS_HEADER_SIZE + tx_info->iv_size + 1;
1195 cpl->aadstart_cipherstop_hi =
1196 htonl(CPL_TX_SEC_PDU_AADSTART_V(1) |
1197 CPL_TX_SEC_PDU_AADSTOP_V(TLS_HEADER_SIZE) |
1198 CPL_TX_SEC_PDU_CIPHERSTART_V(cipher_start));
1200 /* authentication will also start after tls header + iv size */
1201 cpl->cipherstop_lo_authinsert =
1202 htonl(CPL_TX_SEC_PDU_AUTHSTART_V(cipher_start) |
1203 CPL_TX_SEC_PDU_AUTHSTOP_V(TLS_CIPHER_AES_GCM_128_TAG_SIZE) |
1204 CPL_TX_SEC_PDU_AUTHINSERT_V(TLS_CIPHER_AES_GCM_128_TAG_SIZE));
1206 /* These two flits are actually a CPL_TLS_TX_SCMD_FMT. */
1207 cpl->seqno_numivs = htonl(tx_info->scmd0_seqno_numivs);
1208 cpl->ivgen_hdrlen = htonl(tx_info->scmd0_ivgen_hdrlen);
1209 cpl->scmd1 = cpu_to_be64(tx_info->record_no);
1212 /* check if space left to fill the keys */
1213 left = (void *)q->q.stat - pos;
1215 left = (void *)end - (void *)q->q.stat;
1220 pos = chcr_copy_to_txd(&tx_info->key_ctx, &q->q, pos,
1221 tx_info->key_ctx_len);
1222 left = (void *)q->q.stat - pos;
1225 left = (void *)end - (void *)q->q.stat;
1230 tx_data = (void *)pos;
1231 OPCODE_TID(tx_data) = htonl(MK_OPCODE_TID(CPL_TX_DATA, tx_info->tid));
1232 tx_data->len = htonl(TX_DATA_MSS_V(mss) | TX_LENGTH_V(skb->data_len));
1234 tx_data->rsvd = htonl(tcp_seq);
1236 tx_data->flags = htonl(TX_BYPASS_F);
1238 tx_data->flags |= htonl(TX_PUSH_F | TX_SHOVE_F);
1240 /* check left again, it might go beyond queue limit */
1242 left = (void *)q->q.stat - pos;
1244 /* check the position again */
1246 left = (void *)end - (void *)q->q.stat;
1251 /* send the complete packet except the header */
1252 cxgb4_write_sgl(skb, &q->q, pos, end, skb->len - skb->data_len,
1254 sgl_sdesc->skb = skb;
1256 chcr_txq_advance(&q->q, ndesc);
1257 cxgb4_ring_tx_db(adap, &q->q, ndesc);
1258 atomic64_inc(&adap->ch_ktls_stats.ktls_tx_send_records);
1264 * chcr_ktls_xmit_wr_short: This is to send out partial records. If its
1265 * a middle part of a record, fetch the prior data to make it 16 byte aligned
1266 * and then only send it out.
1268 * @skb - skb contains partial record..
1269 * @tx_info - driver specific tls info.
1272 * @tcp_push - tcp push bit.
1273 * @mss - segment size.
1274 * @tls_rec_offset - offset from start of the tls record.
1275 * @perior_data - data before the current segment, required to make this record
1277 * @prior_data_len - prior_data length (less than 16)
1278 * return: NETDEV_TX_BUSY/NET_TX_OK.
1280 static int chcr_ktls_xmit_wr_short(struct sk_buff *skb,
1281 struct chcr_ktls_info *tx_info,
1282 struct sge_eth_txq *q,
1283 u32 tcp_seq, bool tcp_push, u32 mss,
1284 u32 tls_rec_offset, u8 *prior_data,
1287 struct adapter *adap = tx_info->adap;
1288 u32 len16, wr_mid = 0, cipher_start;
1289 unsigned int flits = 0, ndesc;
1290 int credits, left, last_desc;
1291 struct tx_sw_desc *sgl_sdesc;
1292 struct cpl_tx_data *tx_data;
1293 struct cpl_tx_sec_pdu *cpl;
1294 struct ulptx_idata *idata;
1295 struct ulp_txpkt *ulptx;
1296 struct fw_ulptx_wr *wr;
1301 /* get the number of flits required, it's a partial record so 2 flits
1302 * (AES_BLOCK_SIZE) will be added.
1304 flits = chcr_ktls_get_tx_flits(skb, tx_info->key_ctx_len) + 2;
1305 /* get the correct 8 byte IV of this record */
1306 iv_record = cpu_to_be64(tx_info->iv + tx_info->record_no);
1307 /* If it's a middle record and not 16 byte aligned to run AES CTR, need
1308 * to make it 16 byte aligned. So atleadt 2 extra flits of immediate
1309 * data will be added.
1313 /* number of descriptors */
1314 ndesc = chcr_flits_to_desc(flits);
1315 /* check if enough credits available */
1316 credits = chcr_txq_avail(&q->q) - ndesc;
1317 if (unlikely(credits < 0)) {
1318 chcr_eth_txq_stop(q);
1319 return NETDEV_TX_BUSY;
1322 if (unlikely(credits < ETHTXQ_STOP_THRES)) {
1323 chcr_eth_txq_stop(q);
1324 wr_mid |= FW_WR_EQUEQ_F | FW_WR_EQUIQ_F;
1327 last_desc = q->q.pidx + ndesc - 1;
1328 if (last_desc >= q->q.size)
1329 last_desc -= q->q.size;
1330 sgl_sdesc = &q->q.sdesc[last_desc];
1332 if (unlikely(cxgb4_map_skb(adap->pdev_dev, skb, sgl_sdesc->addr) < 0)) {
1333 memset(sgl_sdesc->addr, 0, sizeof(sgl_sdesc->addr));
1335 return NETDEV_TX_BUSY;
1338 pos = &q->q.desc[q->q.pidx];
1339 end = (u64 *)pos + flits;
1342 /* WR will need len16 */
1343 len16 = DIV_ROUND_UP(flits, 2);
1344 wr->op_to_compl = htonl(FW_WR_OP_V(FW_ULPTX_WR));
1345 wr->flowid_len16 = htonl(wr_mid | FW_WR_LEN16_V(len16));
1350 ulptx->cmd_dest = htonl(ULPTX_CMD_V(ULP_TX_PKT) |
1351 ULP_TXPKT_CHANNELID_V(tx_info->port_id) |
1352 ULP_TXPKT_FID_V(q->q.cntxt_id) |
1354 ulptx->len = htonl(len16 - 1);
1355 /* ULPTX_IDATA sub-command */
1356 idata = (struct ulptx_idata *)(ulptx + 1);
1357 idata->cmd_more = htonl(ULPTX_CMD_V(ULP_TX_SC_IMM) | ULP_TX_SC_MORE_F);
1358 /* idata length will include cpl_tx_sec_pdu + key context size +
1359 * cpl_tx_data header.
1361 idata->len = htonl(sizeof(*cpl) + tx_info->key_ctx_len +
1362 sizeof(*tx_data) + AES_BLOCK_LEN + prior_data_len);
1364 cpl = (struct cpl_tx_sec_pdu *)(idata + 1);
1365 /* cipher start will have tls header + iv size extra if its a header
1366 * part of tls record. else only 16 byte IV will be added.
1370 (!tls_rec_offset ? TLS_HEADER_SIZE + tx_info->iv_size : 0);
1372 cpl->op_ivinsrtofst =
1373 htonl(CPL_TX_SEC_PDU_OPCODE_V(CPL_TX_SEC_PDU) |
1374 CPL_TX_SEC_PDU_CPLLEN_V(CHCR_CPL_TX_SEC_PDU_LEN_64BIT) |
1375 CPL_TX_SEC_PDU_IVINSRTOFST_V(1));
1376 cpl->pldlen = htonl(skb->data_len + AES_BLOCK_LEN + prior_data_len);
1377 cpl->aadstart_cipherstop_hi =
1378 htonl(CPL_TX_SEC_PDU_CIPHERSTART_V(cipher_start));
1379 cpl->cipherstop_lo_authinsert = 0;
1380 /* These two flits are actually a CPL_TLS_TX_SCMD_FMT. */
1381 cpl->seqno_numivs = htonl(tx_info->scmd0_short_seqno_numivs);
1382 cpl->ivgen_hdrlen = htonl(tx_info->scmd0_short_ivgen_hdrlen);
1386 /* check if space left to fill the keys */
1387 left = (void *)q->q.stat - pos;
1389 left = (void *)end - (void *)q->q.stat;
1394 pos = chcr_copy_to_txd(&tx_info->key_ctx, &q->q, pos,
1395 tx_info->key_ctx_len);
1396 left = (void *)q->q.stat - pos;
1399 left = (void *)end - (void *)q->q.stat;
1404 tx_data = (void *)pos;
1405 OPCODE_TID(tx_data) = htonl(MK_OPCODE_TID(CPL_TX_DATA, tx_info->tid));
1406 tx_data->len = htonl(TX_DATA_MSS_V(mss) |
1407 TX_LENGTH_V(skb->data_len + prior_data_len));
1408 tx_data->rsvd = htonl(tcp_seq);
1409 tx_data->flags = htonl(TX_BYPASS_F);
1411 tx_data->flags |= htonl(TX_PUSH_F | TX_SHOVE_F);
1413 /* check left again, it might go beyond queue limit */
1415 left = (void *)q->q.stat - pos;
1417 /* check the position again */
1419 left = (void *)end - (void *)q->q.stat;
1423 /* copy the 16 byte IV for AES-CTR, which includes 4 bytes of salt, 8
1424 * bytes of actual IV and 4 bytes of 16 byte-sequence.
1426 memcpy(pos, tx_info->key_ctx.salt, tx_info->salt_size);
1427 memcpy(pos + tx_info->salt_size, &iv_record, tx_info->iv_size);
1428 *(__be32 *)(pos + tx_info->salt_size + tx_info->iv_size) =
1429 htonl(2 + (tls_rec_offset ? ((tls_rec_offset -
1430 (TLS_HEADER_SIZE + tx_info->iv_size)) / AES_BLOCK_LEN) : 0));
1433 /* Prior_data_len will always be less than 16 bytes, fill the
1434 * prio_data_len after AES_CTRL_BLOCK and clear the remaining length
1438 pos = chcr_copy_to_txd(prior_data, &q->q, pos, 16);
1439 /* send the complete packet except the header */
1440 cxgb4_write_sgl(skb, &q->q, pos, end, skb->len - skb->data_len,
1442 sgl_sdesc->skb = skb;
1444 chcr_txq_advance(&q->q, ndesc);
1445 cxgb4_ring_tx_db(adap, &q->q, ndesc);
1451 * chcr_ktls_tx_plaintxt: This handler will take care of the records which has
1452 * only plain text (only tls header and iv)
1453 * @tx_info - driver specific tls info.
1454 * @skb - skb contains partial record..
1456 * @mss - segment size.
1457 * @tcp_push - tcp push bit.
1459 * @port_id : port number
1460 * @perior_data - data before the current segment, required to make this record
1462 * @prior_data_len - prior_data length (less than 16)
1463 * return: NETDEV_TX_BUSY/NET_TX_OK.
1465 static int chcr_ktls_tx_plaintxt(struct chcr_ktls_info *tx_info,
1466 struct sk_buff *skb, u32 tcp_seq, u32 mss,
1467 bool tcp_push, struct sge_eth_txq *q,
1468 u32 port_id, u8 *prior_data,
1471 int credits, left, len16, last_desc;
1472 unsigned int flits = 0, ndesc;
1473 struct tx_sw_desc *sgl_sdesc;
1474 struct cpl_tx_data *tx_data;
1475 struct ulptx_idata *idata;
1476 struct ulp_txpkt *ulptx;
1477 struct fw_ulptx_wr *wr;
1482 flits = DIV_ROUND_UP(CHCR_PLAIN_TX_DATA_LEN, 8);
1483 flits += chcr_sgl_len(skb_shinfo(skb)->nr_frags);
1486 /* WR will need len16 */
1487 len16 = DIV_ROUND_UP(flits, 2);
1488 /* check how many descriptors needed */
1489 ndesc = DIV_ROUND_UP(flits, 8);
1491 credits = chcr_txq_avail(&q->q) - ndesc;
1492 if (unlikely(credits < 0)) {
1493 chcr_eth_txq_stop(q);
1494 return NETDEV_TX_BUSY;
1497 if (unlikely(credits < ETHTXQ_STOP_THRES)) {
1498 chcr_eth_txq_stop(q);
1499 wr_mid |= FW_WR_EQUEQ_F | FW_WR_EQUIQ_F;
1502 last_desc = q->q.pidx + ndesc - 1;
1503 if (last_desc >= q->q.size)
1504 last_desc -= q->q.size;
1505 sgl_sdesc = &q->q.sdesc[last_desc];
1507 if (unlikely(cxgb4_map_skb(tx_info->adap->pdev_dev, skb,
1508 sgl_sdesc->addr) < 0)) {
1509 memset(sgl_sdesc->addr, 0, sizeof(sgl_sdesc->addr));
1511 return NETDEV_TX_BUSY;
1514 pos = &q->q.desc[q->q.pidx];
1515 end = (u64 *)pos + flits;
1518 wr->op_to_compl = htonl(FW_WR_OP_V(FW_ULPTX_WR));
1519 wr->flowid_len16 = htonl(wr_mid | FW_WR_LEN16_V(len16));
1523 ulptx = (struct ulp_txpkt *)(wr + 1);
1524 ulptx->cmd_dest = htonl(ULPTX_CMD_V(ULP_TX_PKT) |
1525 ULP_TXPKT_DATAMODIFY_V(0) |
1526 ULP_TXPKT_CHANNELID_V(tx_info->port_id) |
1527 ULP_TXPKT_DEST_V(0) |
1528 ULP_TXPKT_FID_V(q->q.cntxt_id) | ULP_TXPKT_RO_V(1));
1529 ulptx->len = htonl(len16 - 1);
1530 /* ULPTX_IDATA sub-command */
1531 idata = (struct ulptx_idata *)(ulptx + 1);
1532 idata->cmd_more = htonl(ULPTX_CMD_V(ULP_TX_SC_IMM) | ULP_TX_SC_MORE_F);
1533 idata->len = htonl(sizeof(*tx_data) + prior_data_len);
1535 tx_data = (struct cpl_tx_data *)(idata + 1);
1536 OPCODE_TID(tx_data) = htonl(MK_OPCODE_TID(CPL_TX_DATA, tx_info->tid));
1537 tx_data->len = htonl(TX_DATA_MSS_V(mss) |
1538 TX_LENGTH_V(skb->data_len + prior_data_len));
1539 /* set tcp seq number */
1540 tx_data->rsvd = htonl(tcp_seq);
1541 tx_data->flags = htonl(TX_BYPASS_F);
1543 tx_data->flags |= htonl(TX_PUSH_F | TX_SHOVE_F);
1546 /* apart from prior_data_len, we should set remaining part of 16 bytes
1550 pos = chcr_copy_to_txd(prior_data, &q->q, pos, 16);
1552 /* check left again, it might go beyond queue limit */
1553 left = (void *)q->q.stat - pos;
1555 /* check the position again */
1557 left = (void *)end - (void *)q->q.stat;
1561 /* send the complete packet including the header */
1562 cxgb4_write_sgl(skb, &q->q, pos, end, skb->len - skb->data_len,
1564 sgl_sdesc->skb = skb;
1566 chcr_txq_advance(&q->q, ndesc);
1567 cxgb4_ring_tx_db(tx_info->adap, &q->q, ndesc);
1572 * chcr_ktls_copy_record_in_skb
1573 * @nskb - new skb where the frags to be added.
1574 * @record - specific record which has complete 16k record in frags.
1576 static void chcr_ktls_copy_record_in_skb(struct sk_buff *nskb,
1577 struct tls_record_info *record)
1581 for (i = 0; i < record->num_frags; i++) {
1582 skb_shinfo(nskb)->frags[i] = record->frags[i];
1583 /* increase the frag ref count */
1584 __skb_frag_ref(&skb_shinfo(nskb)->frags[i]);
1587 skb_shinfo(nskb)->nr_frags = record->num_frags;
1588 nskb->data_len = record->len;
1589 nskb->len += record->len;
1590 nskb->truesize += record->len;
1594 * chcr_ktls_update_snd_una: Reset the SEND_UNA. It will be done to avoid
1595 * sending the same segment again. It will discard the segment which is before
1596 * the current tx max.
1597 * @tx_info - driver specific tls info.
1599 * return: NET_TX_OK/NET_XMIT_DROP.
1601 static int chcr_ktls_update_snd_una(struct chcr_ktls_info *tx_info,
1602 struct sge_eth_txq *q)
1604 struct fw_ulptx_wr *wr;
1610 len = sizeof(*wr) + roundup(CHCR_SET_TCB_FIELD_LEN, 16);
1611 ndesc = DIV_ROUND_UP(len, 64);
1613 credits = chcr_txq_avail(&q->q) - ndesc;
1614 if (unlikely(credits < 0)) {
1615 chcr_eth_txq_stop(q);
1616 return NETDEV_TX_BUSY;
1619 pos = &q->q.desc[q->q.pidx];
1623 wr->op_to_compl = htonl(FW_WR_OP_V(FW_ULPTX_WR));
1625 /* fill len in wr field */
1626 wr->flowid_len16 = htonl(FW_WR_LEN16_V(DIV_ROUND_UP(len, 16)));
1630 pos = chcr_write_cpl_set_tcb_ulp(tx_info, q, tx_info->tid, pos,
1632 TCB_SND_UNA_RAW_V(TCB_SND_UNA_RAW_M),
1633 TCB_SND_UNA_RAW_V(0), 0);
1635 chcr_txq_advance(&q->q, ndesc);
1636 cxgb4_ring_tx_db(tx_info->adap, &q->q, ndesc);
1642 * chcr_end_part_handler: This handler will handle the record which
1643 * is complete or if record's end part is received. T6 adapter has a issue that
1644 * it can't send out TAG with partial record so if its an end part then we have
1645 * to send TAG as well and for which we need to fetch the complete record and
1646 * send it to crypto module.
1647 * @tx_info - driver specific tls info.
1648 * @skb - skb contains partial record.
1649 * @record - complete record of 16K size.
1651 * @mss - segment size in which TP needs to chop a packet.
1652 * @tcp_push_no_fin - tcp push if fin is not set.
1654 * @tls_end_offset - offset from end of the record.
1655 * @last wr : check if this is the last part of the skb going out.
1656 * return: NETDEV_TX_OK/NETDEV_TX_BUSY.
1658 static int chcr_end_part_handler(struct chcr_ktls_info *tx_info,
1659 struct sk_buff *skb,
1660 struct tls_record_info *record,
1661 u32 tcp_seq, int mss, bool tcp_push_no_fin,
1662 struct sge_eth_txq *q,
1663 u32 tls_end_offset, bool last_wr)
1665 struct sk_buff *nskb = NULL;
1666 /* check if it is a complete record */
1667 if (tls_end_offset == record->len) {
1669 atomic64_inc(&tx_info->adap->ch_ktls_stats.ktls_tx_complete_pkts);
1671 dev_kfree_skb_any(skb);
1673 nskb = alloc_skb(0, GFP_KERNEL);
1675 return NETDEV_TX_BUSY;
1676 /* copy complete record in skb */
1677 chcr_ktls_copy_record_in_skb(nskb, record);
1678 /* packet is being sent from the beginning, update the tcp_seq
1681 tcp_seq = tls_record_start_seq(record);
1682 /* reset snd una, so the middle record won't send the already
1685 if (chcr_ktls_update_snd_una(tx_info, q))
1687 atomic64_inc(&tx_info->adap->ch_ktls_stats.ktls_tx_end_pkts);
1690 if (chcr_ktls_xmit_wr_complete(nskb, tx_info, q, tcp_seq,
1691 (last_wr && tcp_push_no_fin),
1697 dev_kfree_skb_any(nskb);
1698 return NETDEV_TX_BUSY;
1702 * chcr_short_record_handler: This handler will take care of the records which
1703 * doesn't have end part (1st part or the middle part(/s) of a record). In such
1704 * cases, AES CTR will be used in place of AES GCM to send out partial packet.
1705 * This partial record might be the first part of the record, or the middle
1706 * part. In case of middle record we should fetch the prior data to make it 16
1707 * byte aligned. If it has a partial tls header or iv then get to the start of
1708 * tls header. And if it has partial TAG, then remove the complete TAG and send
1710 * There is one more possibility that it gets a partial header, send that
1711 * portion as a plaintext.
1712 * @tx_info - driver specific tls info.
1713 * @skb - skb contains partial record..
1714 * @record - complete record of 16K size.
1716 * @mss - segment size in which TP needs to chop a packet.
1717 * @tcp_push_no_fin - tcp push if fin is not set.
1719 * @tls_end_offset - offset from end of the record.
1720 * return: NETDEV_TX_OK/NETDEV_TX_BUSY.
1722 static int chcr_short_record_handler(struct chcr_ktls_info *tx_info,
1723 struct sk_buff *skb,
1724 struct tls_record_info *record,
1725 u32 tcp_seq, int mss, bool tcp_push_no_fin,
1726 struct sge_eth_txq *q, u32 tls_end_offset)
1728 u32 tls_rec_offset = tcp_seq - tls_record_start_seq(record);
1729 u8 prior_data[16] = {0};
1730 u32 prior_data_len = 0;
1733 /* check if the skb is ending in middle of tag/HASH, its a big
1734 * trouble, send the packet before the HASH.
1736 int remaining_record = tls_end_offset - skb->data_len;
1738 if (remaining_record > 0 &&
1739 remaining_record < TLS_CIPHER_AES_GCM_128_TAG_SIZE) {
1740 int trimmed_len = skb->data_len -
1741 (TLS_CIPHER_AES_GCM_128_TAG_SIZE - remaining_record);
1742 struct sk_buff *tmp_skb = NULL;
1743 /* don't process the pkt if it is only a partial tag */
1744 if (skb->data_len < TLS_CIPHER_AES_GCM_128_TAG_SIZE)
1747 WARN_ON(trimmed_len > skb->data_len);
1749 /* shift to those many bytes */
1750 tmp_skb = alloc_skb(0, GFP_KERNEL);
1751 if (unlikely(!tmp_skb))
1754 chcr_ktls_skb_shift(tmp_skb, skb, trimmed_len);
1755 /* free the last trimmed portion */
1756 dev_kfree_skb_any(skb);
1758 atomic64_inc(&tx_info->adap->ch_ktls_stats.ktls_tx_trimmed_pkts);
1760 data_len = skb->data_len;
1761 /* check if the middle record's start point is 16 byte aligned. CTR
1762 * needs 16 byte aligned start point to start encryption.
1764 if (tls_rec_offset) {
1765 /* there is an offset from start, means its a middle record */
1768 if (tls_rec_offset < (TLS_HEADER_SIZE + tx_info->iv_size)) {
1769 prior_data_len = tls_rec_offset;
1775 (TLS_HEADER_SIZE + tx_info->iv_size))
1777 remaining = tls_rec_offset - prior_data_len;
1780 /* if prior_data_len is not zero, means we need to fetch prior
1781 * data to make this record 16 byte aligned, or we need to reach
1784 if (prior_data_len) {
1789 int frag_size = 0, frag_delta = 0;
1791 while (remaining > 0) {
1792 frag_size = skb_frag_size(&record->frags[i]);
1793 if (remaining < frag_size)
1796 remaining -= frag_size;
1799 f = &record->frags[i];
1800 vaddr = kmap_atomic(skb_frag_page(f));
1802 data = vaddr + skb_frag_off(f) + remaining;
1803 frag_delta = skb_frag_size(f) - remaining;
1805 if (frag_delta >= prior_data_len) {
1806 memcpy(prior_data, data, prior_data_len);
1807 kunmap_atomic(vaddr);
1809 memcpy(prior_data, data, frag_delta);
1810 kunmap_atomic(vaddr);
1811 /* get the next page */
1812 f = &record->frags[i + 1];
1813 vaddr = kmap_atomic(skb_frag_page(f));
1814 data = vaddr + skb_frag_off(f);
1815 memcpy(prior_data + frag_delta,
1816 data, (prior_data_len - frag_delta));
1817 kunmap_atomic(vaddr);
1819 /* reset tcp_seq as per the prior_data_required len */
1820 tcp_seq -= prior_data_len;
1821 /* include prio_data_len for further calculation.
1823 data_len += prior_data_len;
1825 /* reset snd una, so the middle record won't send the already
1828 if (chcr_ktls_update_snd_una(tx_info, q))
1830 atomic64_inc(&tx_info->adap->ch_ktls_stats.ktls_tx_middle_pkts);
1832 /* Else means, its a partial first part of the record. Check if
1833 * its only the header, don't need to send for encryption then.
1835 if (data_len <= TLS_HEADER_SIZE + tx_info->iv_size) {
1836 if (chcr_ktls_tx_plaintxt(tx_info, skb, tcp_seq, mss,
1845 atomic64_inc(&tx_info->adap->ch_ktls_stats.ktls_tx_start_pkts);
1848 if (chcr_ktls_xmit_wr_short(skb, tx_info, q, tcp_seq, tcp_push_no_fin,
1849 mss, tls_rec_offset, prior_data,
1856 dev_kfree_skb_any(skb);
1857 return NETDEV_TX_BUSY;
1860 /* nic tls TX handler */
1861 static int chcr_ktls_xmit(struct sk_buff *skb, struct net_device *dev)
1863 struct ch_ktls_port_stats_debug *port_stats;
1864 struct chcr_ktls_ofld_ctx_tx *tx_ctx;
1865 struct ch_ktls_stats_debug *stats;
1866 struct tcphdr *th = tcp_hdr(skb);
1867 int data_len, qidx, ret = 0, mss;
1868 struct tls_record_info *record;
1869 struct chcr_ktls_info *tx_info;
1870 u32 tls_end_offset, tcp_seq;
1871 struct tls_context *tls_ctx;
1872 struct sk_buff *local_skb;
1873 struct sge_eth_txq *q;
1874 struct adapter *adap;
1875 unsigned long flags;
1877 tcp_seq = ntohl(th->seq);
1879 mss = skb_is_gso(skb) ? skb_shinfo(skb)->gso_size : skb->data_len;
1881 /* check if we haven't set it for ktls offload */
1882 if (!skb->sk || !tls_is_sk_tx_device_offloaded(skb->sk))
1885 tls_ctx = tls_get_ctx(skb->sk);
1886 if (unlikely(tls_ctx->netdev != dev))
1889 tx_ctx = chcr_get_ktls_tx_context(tls_ctx);
1890 tx_info = tx_ctx->chcr_info;
1892 if (unlikely(!tx_info))
1895 /* don't touch the original skb, make a new skb to extract each records
1896 * and send them separately.
1898 local_skb = alloc_skb(0, GFP_KERNEL);
1900 if (unlikely(!local_skb))
1901 return NETDEV_TX_BUSY;
1903 adap = tx_info->adap;
1904 stats = &adap->ch_ktls_stats;
1905 port_stats = &stats->ktls_port[tx_info->port_id];
1907 qidx = skb->queue_mapping;
1908 q = &adap->sge.ethtxq[qidx + tx_info->first_qset];
1909 cxgb4_reclaim_completed_tx(adap, &q->q, true);
1910 /* if tcp options are set but finish is not send the options first */
1911 if (!th->fin && chcr_ktls_check_tcp_options(th)) {
1912 ret = chcr_ktls_write_tcp_options(tx_info, skb, q,
1915 return NETDEV_TX_BUSY;
1918 ret = chcr_ktls_xmit_tcb_cpls(tx_info, q, ntohl(th->seq),
1922 dev_kfree_skb_any(local_skb);
1923 return NETDEV_TX_BUSY;
1926 /* copy skb contents into local skb */
1927 chcr_ktls_skb_copy(skb, local_skb);
1929 /* go through the skb and send only one record at a time. */
1930 data_len = skb->data_len;
1931 /* TCP segments can be in received either complete or partial.
1932 * chcr_end_part_handler will handle cases if complete record or end
1933 * part of the record is received. Incase of partial end part of record,
1934 * we will send the complete record again.
1940 cxgb4_reclaim_completed_tx(adap, &q->q, true);
1942 spin_lock_irqsave(&tx_ctx->base.lock, flags);
1943 /* fetch the tls record */
1944 record = tls_get_record(&tx_ctx->base, tcp_seq,
1945 &tx_info->record_no);
1946 /* By the time packet reached to us, ACK is received, and record
1947 * won't be found in that case, handle it gracefully.
1949 if (unlikely(!record)) {
1950 spin_unlock_irqrestore(&tx_ctx->base.lock, flags);
1951 atomic64_inc(&port_stats->ktls_tx_drop_no_sync_data);
1955 if (unlikely(tls_record_is_start_marker(record))) {
1956 spin_unlock_irqrestore(&tx_ctx->base.lock, flags);
1957 atomic64_inc(&port_stats->ktls_tx_skip_no_sync_data);
1961 /* increase page reference count of the record, so that there
1962 * won't be any chance of page free in middle if in case stack
1963 * receives ACK and try to delete the record.
1965 for (i = 0; i < record->num_frags; i++)
1966 __skb_frag_ref(&record->frags[i]);
1968 spin_unlock_irqrestore(&tx_ctx->base.lock, flags);
1970 tls_end_offset = record->end_seq - tcp_seq;
1972 pr_debug("seq 0x%x, end_seq 0x%x prev_seq 0x%x, datalen 0x%x\n",
1973 tcp_seq, record->end_seq, tx_info->prev_seq, data_len);
1974 /* if a tls record is finishing in this SKB */
1975 if (tls_end_offset <= data_len) {
1976 struct sk_buff *nskb = NULL;
1978 if (tls_end_offset < data_len) {
1979 nskb = alloc_skb(0, GFP_KERNEL);
1980 if (unlikely(!nskb)) {
1985 chcr_ktls_skb_shift(nskb, local_skb,
1988 /* its the only record in this skb, directly
1993 ret = chcr_end_part_handler(tx_info, nskb, record,
1995 (!th->fin && th->psh), q,
1997 (nskb == local_skb));
1999 if (ret && nskb != local_skb)
2000 dev_kfree_skb_any(local_skb);
2002 data_len -= tls_end_offset;
2003 /* tcp_seq increment is required to handle next record.
2005 tcp_seq += tls_end_offset;
2007 ret = chcr_short_record_handler(tx_info, local_skb,
2008 record, tcp_seq, mss,
2009 (!th->fin && th->psh),
2014 /* clear the frag ref count which increased locally before */
2015 for (i = 0; i < record->num_frags; i++) {
2016 /* clear the frag ref count */
2017 __skb_frag_unref(&record->frags[i]);
2019 /* if any failure, come out from the loop. */
2022 /* length should never be less than 0 */
2023 WARN_ON(data_len < 0);
2025 } while (data_len > 0);
2027 tx_info->prev_seq = ntohl(th->seq) + skb->data_len;
2028 atomic64_inc(&port_stats->ktls_tx_encrypted_packets);
2029 atomic64_add(skb->data_len, &port_stats->ktls_tx_encrypted_bytes);
2031 /* tcp finish is set, send a separate tcp msg including all the options
2035 chcr_ktls_write_tcp_options(tx_info, skb, q, tx_info->tx_chan);
2038 dev_kfree_skb_any(skb);
2039 return NETDEV_TX_OK;
2042 static void *chcr_ktls_uld_add(const struct cxgb4_lld_info *lldi)
2044 struct chcr_ktls_uld_ctx *u_ctx;
2046 pr_info_once("%s - version %s\n", CHCR_KTLS_DRV_DESC,
2047 CHCR_KTLS_DRV_VERSION);
2048 u_ctx = kzalloc(sizeof(*u_ctx), GFP_KERNEL);
2050 u_ctx = ERR_PTR(-ENOMEM);
2053 u_ctx->lldi = *lldi;
2058 static const struct tlsdev_ops chcr_ktls_ops = {
2059 .tls_dev_add = chcr_ktls_dev_add,
2060 .tls_dev_del = chcr_ktls_dev_del,
2063 static chcr_handler_func work_handlers[NUM_CPL_CMDS] = {
2064 [CPL_ACT_OPEN_RPL] = chcr_ktls_cpl_act_open_rpl,
2065 [CPL_SET_TCB_RPL] = chcr_ktls_cpl_set_tcb_rpl,
2068 static int chcr_ktls_uld_rx_handler(void *handle, const __be64 *rsp,
2069 const struct pkt_gl *pgl)
2071 const struct cpl_act_open_rpl *rpl = (struct cpl_act_open_rpl *)rsp;
2072 struct chcr_ktls_uld_ctx *u_ctx = handle;
2073 u8 opcode = rpl->ot.opcode;
2074 struct adapter *adap;
2076 adap = pci_get_drvdata(u_ctx->lldi.pdev);
2078 if (!work_handlers[opcode]) {
2079 pr_err("Unsupported opcode %d received\n", opcode);
2083 work_handlers[opcode](adap, (unsigned char *)&rsp[1]);
2087 static int chcr_ktls_uld_state_change(void *handle, enum cxgb4_state new_state)
2089 struct chcr_ktls_uld_ctx *u_ctx = handle;
2091 switch (new_state) {
2092 case CXGB4_STATE_UP:
2093 pr_info("%s: Up\n", pci_name(u_ctx->lldi.pdev));
2094 mutex_lock(&dev_mutex);
2095 list_add_tail(&u_ctx->entry, &uld_ctx_list);
2096 mutex_unlock(&dev_mutex);
2098 case CXGB4_STATE_START_RECOVERY:
2099 case CXGB4_STATE_DOWN:
2100 case CXGB4_STATE_DETACH:
2101 pr_info("%s: Down\n", pci_name(u_ctx->lldi.pdev));
2102 mutex_lock(&dev_mutex);
2103 list_del(&u_ctx->entry);
2104 mutex_unlock(&dev_mutex);
2113 static struct cxgb4_uld_info chcr_ktls_uld_info = {
2114 .name = CHCR_KTLS_DRV_MODULE_NAME,
2117 .add = chcr_ktls_uld_add,
2118 .tx_handler = chcr_ktls_xmit,
2119 .rx_handler = chcr_ktls_uld_rx_handler,
2120 .state_change = chcr_ktls_uld_state_change,
2121 .tlsdev_ops = &chcr_ktls_ops,
2124 static int __init chcr_ktls_init(void)
2126 cxgb4_register_uld(CXGB4_ULD_KTLS, &chcr_ktls_uld_info);
2130 static void __exit chcr_ktls_exit(void)
2132 struct chcr_ktls_uld_ctx *u_ctx, *tmp;
2133 struct adapter *adap;
2135 pr_info("driver unloaded\n");
2137 mutex_lock(&dev_mutex);
2138 list_for_each_entry_safe(u_ctx, tmp, &uld_ctx_list, entry) {
2139 adap = pci_get_drvdata(u_ctx->lldi.pdev);
2140 memset(&adap->ch_ktls_stats, 0, sizeof(adap->ch_ktls_stats));
2141 list_del(&u_ctx->entry);
2144 mutex_unlock(&dev_mutex);
2145 cxgb4_unregister_uld(CXGB4_ULD_KTLS);
2148 module_init(chcr_ktls_init);
2149 module_exit(chcr_ktls_exit);
2151 MODULE_DESCRIPTION("Chelsio NIC TLS ULD driver");
2152 MODULE_LICENSE("GPL");
2153 MODULE_AUTHOR("Chelsio Communications");
2154 MODULE_VERSION(CHCR_KTLS_DRV_VERSION);