0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019
0020
0021
0022
0023
0024
0025
0026
0027
0028
0029
0030
0031
0032
0033
0034
0035
0036 #ifndef __CHCR_CORE_H__
0037 #define __CHCR_CORE_H__
0038
0039 #include <crypto/algapi.h>
0040 #include <net/tls.h>
0041 #include "t4_hw.h"
0042 #include "cxgb4.h"
0043 #include "t4_msg.h"
0044 #include "cxgb4_uld.h"
0045
0046 #define DRV_MODULE_NAME "chcr"
0047 #define DRV_DESC "Chelsio T6 Crypto Co-processor Driver"
0048
0049 #define MAX_PENDING_REQ_TO_HW 20
0050 #define CHCR_TEST_RESPONSE_TIMEOUT 1000
0051 #define WQ_DETACH_TM (msecs_to_jiffies(50))
0052 #define PAD_ERROR_BIT 1
0053 #define CHK_PAD_ERR_BIT(x) (((x) >> PAD_ERROR_BIT) & 1)
0054
0055 #define MAC_ERROR_BIT 0
0056 #define CHK_MAC_ERR_BIT(x) (((x) >> MAC_ERROR_BIT) & 1)
0057 #define MAX_SALT 4
0058 #define CIP_WR_MIN_LEN (sizeof(struct chcr_wr) + \
0059 sizeof(struct cpl_rx_phys_dsgl) + \
0060 sizeof(struct ulptx_sgl) + 16)
0061
0062 #define HASH_WR_MIN_LEN (sizeof(struct chcr_wr) + \
0063 DUMMY_BYTES + \
0064 sizeof(struct ulptx_sgl))
0065 struct uld_ctx;
0066
0067 struct _key_ctx {
0068 __be32 ctx_hdr;
0069 u8 salt[MAX_SALT];
0070 __be64 iv_to_auth;
0071 unsigned char key[];
0072 };
0073
0074 #define WQ_RETRY 5
0075 struct chcr_driver_data {
0076 struct list_head act_dev;
0077 struct list_head inact_dev;
0078 atomic_t dev_count;
0079 struct mutex drv_mutex;
0080 struct uld_ctx *last_dev;
0081 };
0082
0083 enum chcr_state {
0084 CHCR_INIT = 0,
0085 CHCR_ATTACH,
0086 CHCR_DETACH,
0087 };
0088 struct chcr_wr {
0089 struct fw_crypto_lookaside_wr wreq;
0090 struct ulp_txpkt ulptx;
0091 struct ulptx_idata sc_imm;
0092 struct cpl_tx_sec_pdu sec_cpl;
0093 struct _key_ctx key_ctx;
0094 };
0095
0096 struct chcr_dev {
0097 spinlock_t lock_chcr_dev;
0098 enum chcr_state state;
0099 atomic_t inflight;
0100 int wqretry;
0101 struct delayed_work detach_work;
0102 struct completion detach_comp;
0103 };
0104
0105 struct uld_ctx {
0106 struct list_head entry;
0107 struct cxgb4_lld_info lldi;
0108 struct chcr_dev dev;
0109 };
0110
0111
0112
0113
0114
0115
0116
0117 static inline unsigned int sgl_len(unsigned int n)
0118 {
0119 n--;
0120 return (3 * n) / 2 + (n & 1) + 2;
0121 }
0122
0123 static inline void *padap(struct chcr_dev *dev)
0124 {
0125 struct uld_ctx *u_ctx = container_of(dev, struct uld_ctx, dev);
0126
0127 return pci_get_drvdata(u_ctx->lldi.pdev);
0128 }
0129
0130 struct uld_ctx *assign_chcr_device(void);
0131 int chcr_send_wr(struct sk_buff *skb);
0132 int start_crypto(void);
0133 int stop_crypto(void);
0134 int chcr_uld_rx_handler(void *handle, const __be64 *rsp,
0135 const struct pkt_gl *pgl);
0136 int chcr_uld_tx_handler(struct sk_buff *skb, struct net_device *dev);
0137 int chcr_handle_resp(struct crypto_async_request *req, unsigned char *input,
0138 int err);
0139 #endif