Skip to content

Commit 8a30923

Browse files
rmchelsiodavem330
authored andcommitted
cxgb4/chcr: Save tx keys and handle HW response
As part of this patch generated and saved crypto keys, handled HW response of act_open_req and set_tcb_req. Defined connection state update. v1->v2: - optimized tcb update using control queue. - state machine handling when earlier states received. v2->v3: - Added one empty line after function declaration. Signed-off-by: Rohit Maheshwari <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent 34aba2c commit 8a30923

File tree

9 files changed

+391
-13
lines changed

9 files changed

+391
-13
lines changed

drivers/crypto/chelsio/chcr_common.h

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,10 @@
66

77
#include "cxgb4.h"
88

9+
#define CHCR_MAX_SALT 4
10+
#define CHCR_KEYCTX_MAC_KEY_SIZE_128 0
11+
#define CHCR_KEYCTX_CIPHER_KEY_SIZE_128 0
12+
913
enum chcr_state {
1014
CHCR_INIT = 0,
1115
CHCR_ATTACH,
@@ -28,5 +32,65 @@ struct uld_ctx {
2832
struct chcr_dev dev;
2933
};
3034

35+
struct ktls_key_ctx {
36+
__be32 ctx_hdr;
37+
u8 salt[CHCR_MAX_SALT];
38+
__be64 iv_to_auth;
39+
unsigned char key[TLS_CIPHER_AES_GCM_128_KEY_SIZE +
40+
TLS_CIPHER_AES_GCM_256_TAG_SIZE];
41+
};
42+
43+
/* Crypto key context */
44+
#define KEY_CONTEXT_CTX_LEN_S 24
45+
#define KEY_CONTEXT_CTX_LEN_V(x) ((x) << KEY_CONTEXT_CTX_LEN_S)
46+
47+
#define KEY_CONTEXT_SALT_PRESENT_S 10
48+
#define KEY_CONTEXT_SALT_PRESENT_V(x) ((x) << KEY_CONTEXT_SALT_PRESENT_S)
49+
#define KEY_CONTEXT_SALT_PRESENT_F KEY_CONTEXT_SALT_PRESENT_V(1U)
50+
51+
#define KEY_CONTEXT_VALID_S 0
52+
#define KEY_CONTEXT_VALID_V(x) ((x) << KEY_CONTEXT_VALID_S)
53+
#define KEY_CONTEXT_VALID_F KEY_CONTEXT_VALID_V(1U)
54+
55+
#define KEY_CONTEXT_CK_SIZE_S 6
56+
#define KEY_CONTEXT_CK_SIZE_V(x) ((x) << KEY_CONTEXT_CK_SIZE_S)
57+
58+
#define KEY_CONTEXT_MK_SIZE_S 2
59+
#define KEY_CONTEXT_MK_SIZE_V(x) ((x) << KEY_CONTEXT_MK_SIZE_S)
60+
61+
#define KEY_CONTEXT_OPAD_PRESENT_S 11
62+
#define KEY_CONTEXT_OPAD_PRESENT_V(x) ((x) << KEY_CONTEXT_OPAD_PRESENT_S)
63+
#define KEY_CONTEXT_OPAD_PRESENT_F KEY_CONTEXT_OPAD_PRESENT_V(1U)
64+
65+
#define FILL_KEY_CTX_HDR(ck_size, mk_size, ctx_len) \
66+
htonl(KEY_CONTEXT_MK_SIZE_V(mk_size) | \
67+
KEY_CONTEXT_CK_SIZE_V(ck_size) | \
68+
KEY_CONTEXT_VALID_F | \
69+
KEY_CONTEXT_SALT_PRESENT_F | \
70+
KEY_CONTEXT_CTX_LEN_V((ctx_len)))
71+
3172
struct uld_ctx *assign_chcr_device(void);
73+
74+
static inline void *chcr_copy_to_txd(const void *src, const struct sge_txq *q,
75+
void *pos, int length)
76+
{
77+
int left = (void *)q->stat - pos;
78+
u64 *p;
79+
80+
if (likely(length <= left)) {
81+
memcpy(pos, src, length);
82+
pos += length;
83+
} else {
84+
memcpy(pos, src, left);
85+
memcpy(q->desc, src + left, length - left);
86+
pos = (void *)q->desc + (length - left);
87+
}
88+
/* 0-pad to multiple of 16 */
89+
p = PTR_ALIGN(pos, 8);
90+
if ((uintptr_t)p & 8) {
91+
*p = 0;
92+
return p + 1;
93+
}
94+
return p;
95+
}
3296
#endif /* __CHCR_COMMON_H__ */

drivers/crypto/chelsio/chcr_core.c

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -28,13 +28,17 @@
2828

2929
static struct chcr_driver_data drv_data;
3030

31-
typedef int (*chcr_handler_func)(struct chcr_dev *dev, unsigned char *input);
32-
static int cpl_fw6_pld_handler(struct chcr_dev *dev, unsigned char *input);
31+
typedef int (*chcr_handler_func)(struct adapter *adap, unsigned char *input);
32+
static int cpl_fw6_pld_handler(struct adapter *adap, unsigned char *input);
3333
static void *chcr_uld_add(const struct cxgb4_lld_info *lld);
3434
static int chcr_uld_state_change(void *handle, enum cxgb4_state state);
3535

3636
static chcr_handler_func work_handlers[NUM_CPL_CMDS] = {
3737
[CPL_FW6_PLD] = cpl_fw6_pld_handler,
38+
#ifdef CONFIG_CHELSIO_TLS_DEVICE
39+
[CPL_ACT_OPEN_RPL] = chcr_ktls_cpl_act_open_rpl,
40+
[CPL_SET_TCB_RPL] = chcr_ktls_cpl_set_tcb_rpl,
41+
#endif
3842
};
3943

4044
static struct cxgb4_uld_info chcr_uld_info = {
@@ -150,14 +154,13 @@ static int chcr_dev_move(struct uld_ctx *u_ctx)
150154
return 0;
151155
}
152156

153-
static int cpl_fw6_pld_handler(struct chcr_dev *dev,
157+
static int cpl_fw6_pld_handler(struct adapter *adap,
154158
unsigned char *input)
155159
{
156160
struct crypto_async_request *req;
157161
struct cpl_fw6_pld *fw6_pld;
158162
u32 ack_err_status = 0;
159163
int error_status = 0;
160-
struct adapter *adap = padap(dev);
161164

162165
fw6_pld = (struct cpl_fw6_pld *)input;
163166
req = (struct crypto_async_request *)(uintptr_t)be64_to_cpu(
@@ -219,17 +222,18 @@ int chcr_uld_rx_handler(void *handle, const __be64 *rsp,
219222
{
220223
struct uld_ctx *u_ctx = (struct uld_ctx *)handle;
221224
struct chcr_dev *dev = &u_ctx->dev;
225+
struct adapter *adap = padap(dev);
222226
const struct cpl_fw6_pld *rpl = (struct cpl_fw6_pld *)rsp;
223227

224-
if (rpl->opcode != CPL_FW6_PLD) {
225-
pr_err("Unsupported opcode\n");
228+
if (!work_handlers[rpl->opcode]) {
229+
pr_err("Unsupported opcode %d received\n", rpl->opcode);
226230
return 0;
227231
}
228232

229233
if (!pgl)
230-
work_handlers[rpl->opcode](dev, (unsigned char *)&rsp[1]);
234+
work_handlers[rpl->opcode](adap, (unsigned char *)&rsp[1]);
231235
else
232-
work_handlers[rpl->opcode](dev, pgl->va);
236+
work_handlers[rpl->opcode](adap, pgl->va);
233237
return 0;
234238
}
235239

drivers/crypto/chelsio/chcr_core.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -225,5 +225,7 @@ void chcr_add_xfrmops(const struct cxgb4_lld_info *lld);
225225
#ifdef CONFIG_CHELSIO_TLS_DEVICE
226226
void chcr_enable_ktls(struct adapter *adap);
227227
void chcr_disable_ktls(struct adapter *adap);
228+
int chcr_ktls_cpl_act_open_rpl(struct adapter *adap, unsigned char *input);
229+
int chcr_ktls_cpl_set_tcb_rpl(struct adapter *adap, unsigned char *input);
228230
#endif
229231
#endif /* __CHCR_CORE_H__ */

0 commit comments

Comments
 (0)