1324429d7SHariprasad Shenai /*
2324429d7SHariprasad Shenai * This file is part of the Chelsio T6 Crypto driver for Linux.
3324429d7SHariprasad Shenai *
4324429d7SHariprasad Shenai * Copyright (c) 2003-2016 Chelsio Communications, Inc. All rights reserved.
5324429d7SHariprasad Shenai *
6324429d7SHariprasad Shenai * This software is available to you under a choice of one of two
7324429d7SHariprasad Shenai * licenses. You may choose to be licensed under the terms of the GNU
8324429d7SHariprasad Shenai * General Public License (GPL) Version 2, available from the file
9324429d7SHariprasad Shenai * COPYING in the main directory of this source tree, or the
10324429d7SHariprasad Shenai * OpenIB.org BSD license below:
11324429d7SHariprasad Shenai *
12324429d7SHariprasad Shenai * Redistribution and use in source and binary forms, with or
13324429d7SHariprasad Shenai * without modification, are permitted provided that the following
14324429d7SHariprasad Shenai * conditions are met:
15324429d7SHariprasad Shenai *
16324429d7SHariprasad Shenai * - Redistributions of source code must retain the above
17324429d7SHariprasad Shenai * copyright notice, this list of conditions and the following
18324429d7SHariprasad Shenai * disclaimer.
19324429d7SHariprasad Shenai *
20324429d7SHariprasad Shenai * - Redistributions in binary form must reproduce the above
21324429d7SHariprasad Shenai * copyright notice, this list of conditions and the following
22324429d7SHariprasad Shenai * disclaimer in the documentation and/or other materials
23324429d7SHariprasad Shenai * provided with the distribution.
24324429d7SHariprasad Shenai *
25324429d7SHariprasad Shenai * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
26324429d7SHariprasad Shenai * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
27324429d7SHariprasad Shenai * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
28324429d7SHariprasad Shenai * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
29324429d7SHariprasad Shenai * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
30324429d7SHariprasad Shenai * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
31324429d7SHariprasad Shenai * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
32324429d7SHariprasad Shenai * SOFTWARE.
33324429d7SHariprasad Shenai *
34324429d7SHariprasad Shenai */
35324429d7SHariprasad Shenai
36324429d7SHariprasad Shenai #ifndef __CHCR_CORE_H__
37324429d7SHariprasad Shenai #define __CHCR_CORE_H__
38324429d7SHariprasad Shenai
39324429d7SHariprasad Shenai #include <crypto/algapi.h>
40*a3ac249aSRohit Maheshwari #include <net/tls.h>
41324429d7SHariprasad Shenai #include "t4_hw.h"
42324429d7SHariprasad Shenai #include "cxgb4.h"
436dad4e8aSAtul Gupta #include "t4_msg.h"
44324429d7SHariprasad Shenai #include "cxgb4_uld.h"
45324429d7SHariprasad Shenai
46324429d7SHariprasad Shenai #define DRV_MODULE_NAME "chcr"
4700adbe71SDevulapally Shiva Krishna #define DRV_DESC "Chelsio T6 Crypto Co-processor Driver"
48324429d7SHariprasad Shenai
49324429d7SHariprasad Shenai #define MAX_PENDING_REQ_TO_HW 20
50324429d7SHariprasad Shenai #define CHCR_TEST_RESPONSE_TIMEOUT 1000
51fef4912bSHarsh Jain #define WQ_DETACH_TM (msecs_to_jiffies(50))
52324429d7SHariprasad Shenai #define PAD_ERROR_BIT 1
53324429d7SHariprasad Shenai #define CHK_PAD_ERR_BIT(x) (((x) >> PAD_ERROR_BIT) & 1)
54324429d7SHariprasad Shenai
55324429d7SHariprasad Shenai #define MAC_ERROR_BIT 0
56324429d7SHariprasad Shenai #define CHK_MAC_ERR_BIT(x) (((x) >> MAC_ERROR_BIT) & 1)
57358961d1SHarsh Jain #define MAX_SALT 4
585110e655SHarsh Jain #define CIP_WR_MIN_LEN (sizeof(struct chcr_wr) + \
59b8fd1f41SHarsh Jain sizeof(struct cpl_rx_phys_dsgl) + \
60335bcc4aSHarsh Jain sizeof(struct ulptx_sgl) + 16) //IV
61324429d7SHariprasad Shenai
625110e655SHarsh Jain #define HASH_WR_MIN_LEN (sizeof(struct chcr_wr) + \
635110e655SHarsh Jain DUMMY_BYTES + \
645110e655SHarsh Jain sizeof(struct ulptx_sgl))
65324429d7SHariprasad Shenai struct uld_ctx;
66324429d7SHariprasad Shenai
67358961d1SHarsh Jain struct _key_ctx {
68358961d1SHarsh Jain __be32 ctx_hdr;
69358961d1SHarsh Jain u8 salt[MAX_SALT];
70639d28a1SAtul Gupta __be64 iv_to_auth;
715a8a0765SGustavo A. R. Silva unsigned char key[];
72358961d1SHarsh Jain };
73358961d1SHarsh Jain
74fef4912bSHarsh Jain #define WQ_RETRY 5
75fef4912bSHarsh Jain struct chcr_driver_data {
76fef4912bSHarsh Jain struct list_head act_dev;
77fef4912bSHarsh Jain struct list_head inact_dev;
78fef4912bSHarsh Jain atomic_t dev_count;
79fef4912bSHarsh Jain struct mutex drv_mutex;
80fef4912bSHarsh Jain struct uld_ctx *last_dev;
81fef4912bSHarsh Jain };
82fef4912bSHarsh Jain
83fef4912bSHarsh Jain enum chcr_state {
84fef4912bSHarsh Jain CHCR_INIT = 0,
85fef4912bSHarsh Jain CHCR_ATTACH,
86fef4912bSHarsh Jain CHCR_DETACH,
87fef4912bSHarsh Jain };
88358961d1SHarsh Jain struct chcr_wr {
89358961d1SHarsh Jain struct fw_crypto_lookaside_wr wreq;
90358961d1SHarsh Jain struct ulp_txpkt ulptx;
91358961d1SHarsh Jain struct ulptx_idata sc_imm;
92358961d1SHarsh Jain struct cpl_tx_sec_pdu sec_cpl;
93358961d1SHarsh Jain struct _key_ctx key_ctx;
94358961d1SHarsh Jain };
95358961d1SHarsh Jain
96324429d7SHariprasad Shenai struct chcr_dev {
97324429d7SHariprasad Shenai spinlock_t lock_chcr_dev;
98fef4912bSHarsh Jain enum chcr_state state;
99fef4912bSHarsh Jain atomic_t inflight;
100fef4912bSHarsh Jain int wqretry;
101fef4912bSHarsh Jain struct delayed_work detach_work;
102fef4912bSHarsh Jain struct completion detach_comp;
103324429d7SHariprasad Shenai };
104324429d7SHariprasad Shenai
105324429d7SHariprasad Shenai struct uld_ctx {
106324429d7SHariprasad Shenai struct list_head entry;
107324429d7SHariprasad Shenai struct cxgb4_lld_info lldi;
108fef4912bSHarsh Jain struct chcr_dev dev;
109324429d7SHariprasad Shenai };
110324429d7SHariprasad Shenai
1116dad4e8aSAtul Gupta /*
1126dad4e8aSAtul Gupta * sgl_len - calculates the size of an SGL of the given capacity
1136dad4e8aSAtul Gupta * @n: the number of SGL entries
1146dad4e8aSAtul Gupta * Calculates the number of flits needed for a scatter/gather list that
1156dad4e8aSAtul Gupta * can hold the given number of entries.
1166dad4e8aSAtul Gupta */
sgl_len(unsigned int n)1176dad4e8aSAtul Gupta static inline unsigned int sgl_len(unsigned int n)
1186dad4e8aSAtul Gupta {
1196dad4e8aSAtul Gupta n--;
1206dad4e8aSAtul Gupta return (3 * n) / 2 + (n & 1) + 2;
1216dad4e8aSAtul Gupta }
1226dad4e8aSAtul Gupta
padap(struct chcr_dev * dev)123fef4912bSHarsh Jain static inline void *padap(struct chcr_dev *dev)
124fef4912bSHarsh Jain {
125fef4912bSHarsh Jain struct uld_ctx *u_ctx = container_of(dev, struct uld_ctx, dev);
126fef4912bSHarsh Jain
127fef4912bSHarsh Jain return pci_get_drvdata(u_ctx->lldi.pdev);
128fef4912bSHarsh Jain }
129fef4912bSHarsh Jain
13014c19b17SHarsh Jain struct uld_ctx *assign_chcr_device(void);
131324429d7SHariprasad Shenai int chcr_send_wr(struct sk_buff *skb);
132324429d7SHariprasad Shenai int start_crypto(void);
133324429d7SHariprasad Shenai int stop_crypto(void);
134324429d7SHariprasad Shenai int chcr_uld_rx_handler(void *handle, const __be64 *rsp,
135324429d7SHariprasad Shenai const struct pkt_gl *pgl);
136324429d7SHariprasad Shenai int chcr_handle_resp(struct crypto_async_request *req, unsigned char *input,
137324429d7SHariprasad Shenai int err);
138324429d7SHariprasad Shenai #endif /* __CHCR_CORE_H__ */
139