cxgb4/chcr : Register to tls add and del callback
[linux-2.6-microblaze.git] / drivers / crypto / chelsio / chcr_ktls.h
1 /* SPDX-License-Identifier: GPL-2.0-only */
2 /* Copyright (C) 2020 Chelsio Communications.  All rights reserved. */
3
4 #ifndef __CHCR_KTLS_H__
5 #define __CHCR_KTLS_H__
6
7 #ifdef CONFIG_CHELSIO_TLS_DEVICE
8 #include <net/tls.h>
9 #include "cxgb4.h"
10 #include "t4_msg.h"
11 #include "t4_tcb.h"
12 #include "l2t.h"
13 #include "chcr_common.h"
14
15 #define CHCR_TCB_STATE_CLOSED   0
16
17 enum chcr_ktls_conn_state {
18         KTLS_CONN_CLOSED,
19 };
20
21 struct chcr_ktls_info {
22         struct sock *sk;
23         spinlock_t lock; /* state machine lock */
24         struct adapter *adap;
25         struct l2t_entry *l2te;
26         struct net_device *netdev;
27         int tid;
28         int atid;
29         int rx_qid;
30         u32 prev_seq;
31         u32 tcp_start_seq_number;
32         enum chcr_ktls_conn_state connection_state;
33         u8 tx_chan;
34         u8 smt_idx;
35         u8 port_id;
36         u8 ip_family;
37 };
38
39 struct chcr_ktls_ofld_ctx_tx {
40         struct tls_offload_context_tx base;
41         struct chcr_ktls_info *chcr_info;
42 };
43
44 static inline struct chcr_ktls_ofld_ctx_tx *
45 chcr_get_ktls_tx_context(struct tls_context *tls_ctx)
46 {
47         BUILD_BUG_ON(sizeof(struct chcr_ktls_ofld_ctx_tx) >
48                      TLS_OFFLOAD_CONTEXT_SIZE_TX);
49         return container_of(tls_offload_ctx_tx(tls_ctx),
50                             struct chcr_ktls_ofld_ctx_tx,
51                             base);
52 }
53
54 static inline int chcr_get_first_rx_qid(struct adapter *adap)
55 {
56         /* u_ctx is saved in adap, fetch it */
57         struct uld_ctx *u_ctx = adap->uld[CXGB4_ULD_CRYPTO].handle;
58
59         if (!u_ctx)
60                 return -1;
61         return u_ctx->lldi.rxq_ids[0];
62 }
63
64 void chcr_enable_ktls(struct adapter *adap);
65 void chcr_disable_ktls(struct adapter *adap);
66 #endif /* CONFIG_CHELSIO_TLS_DEVICE */
67 #endif /* __CHCR_KTLS_H__ */