Commit 6dad4e8a authored by Atul Gupta's avatar Atul Gupta Committed by Herbert Xu

chcr: Add support for Inline IPSec

register xfrmdev_ops callbacks, Send IPsec tunneled data
to HW for inline processing.
The driver use hardware crypto accelerator to encrypt and
generate ICV for the transmitted packet in Inline mode.
Signed-off-by: default avatarAtul Gupta <atul.gupta@chelsio.com>
Signed-off-by: default avatarHarsh Jain <harsh@chelsio.com>
Signed-off-by: default avatarGanesh Goudar <ganeshgr@chelsio.com>
Signed-off-by: default avatarHerbert Xu <herbert@gondor.apana.org.au>
parent a6ec572b
...@@ -18,3 +18,13 @@ config CRYPTO_DEV_CHELSIO ...@@ -18,3 +18,13 @@ config CRYPTO_DEV_CHELSIO
To compile this driver as a module, choose M here: the module To compile this driver as a module, choose M here: the module
will be called chcr. will be called chcr.
config CHELSIO_IPSEC_INLINE
bool "Chelsio IPSec XFRM Tx crypto offload"
depends on CHELSIO_T4
depends on CRYPTO_DEV_CHELSIO
depends on XFRM_OFFLOAD
depends on INET_ESP_OFFLOAD || INET6_ESP_OFFLOAD
default n
---help---
Enable support for IPSec Tx Inline.
...@@ -2,3 +2,4 @@ ccflags-y := -Idrivers/net/ethernet/chelsio/cxgb4 ...@@ -2,3 +2,4 @@ ccflags-y := -Idrivers/net/ethernet/chelsio/cxgb4
obj-$(CONFIG_CRYPTO_DEV_CHELSIO) += chcr.o obj-$(CONFIG_CRYPTO_DEV_CHELSIO) += chcr.o
chcr-objs := chcr_core.o chcr_algo.o chcr-objs := chcr_core.o chcr_algo.o
chcr-$(CONFIG_CHELSIO_IPSEC_INLINE) += chcr_ipsec.o
This diff is collapsed.
...@@ -226,15 +226,6 @@ ...@@ -226,15 +226,6 @@
#define SPACE_LEFT(len) \ #define SPACE_LEFT(len) \
((SGE_MAX_WR_LEN - WR_MIN_LEN - (len))) ((SGE_MAX_WR_LEN - WR_MIN_LEN - (len)))
unsigned int sgl_ent_len[] = {0, 0, 16, 24, 40, 48, 64, 72, 88,
96, 112, 120, 136, 144, 160, 168, 184,
192, 208, 216, 232, 240, 256, 264, 280,
288, 304, 312, 328, 336, 352, 360, 376};
unsigned int dsgl_ent_len[] = {0, 32, 32, 48, 48, 64, 64, 80, 80,
112, 112, 128, 128, 144, 144, 160, 160,
192, 192, 208, 208, 224, 224, 240, 240,
272, 272, 288, 288, 304, 304, 320, 320};
struct algo_param { struct algo_param {
unsigned int auth_mode; unsigned int auth_mode;
unsigned int mk_size; unsigned int mk_size;
...@@ -404,10 +395,4 @@ static inline u32 aes_ks_subword(const u32 w) ...@@ -404,10 +395,4 @@ static inline u32 aes_ks_subword(const u32 w)
return *(u32 *)(&bytes[0]); return *(u32 *)(&bytes[0]);
} }
static u32 round_constant[11] = {
0x01000000, 0x02000000, 0x04000000, 0x08000000,
0x10000000, 0x20000000, 0x40000000, 0x80000000,
0x1B000000, 0x36000000, 0x6C000000
};
#endif /* __CHCR_ALGO_H__ */ #endif /* __CHCR_ALGO_H__ */
...@@ -48,6 +48,9 @@ static struct cxgb4_uld_info chcr_uld_info = { ...@@ -48,6 +48,9 @@ static struct cxgb4_uld_info chcr_uld_info = {
.add = chcr_uld_add, .add = chcr_uld_add,
.state_change = chcr_uld_state_change, .state_change = chcr_uld_state_change,
.rx_handler = chcr_uld_rx_handler, .rx_handler = chcr_uld_rx_handler,
#ifdef CONFIG_CHELSIO_IPSEC_INLINE
.tx_handler = chcr_uld_tx_handler,
#endif /* CONFIG_CHELSIO_IPSEC_INLINE */
}; };
struct uld_ctx *assign_chcr_device(void) struct uld_ctx *assign_chcr_device(void)
...@@ -164,6 +167,10 @@ static void *chcr_uld_add(const struct cxgb4_lld_info *lld) ...@@ -164,6 +167,10 @@ static void *chcr_uld_add(const struct cxgb4_lld_info *lld)
goto out; goto out;
} }
u_ctx->lldi = *lld; u_ctx->lldi = *lld;
#ifdef CONFIG_CHELSIO_IPSEC_INLINE
if (lld->crypto & ULP_CRYPTO_IPSEC_INLINE)
chcr_add_xfrmops(lld);
#endif /* CONFIG_CHELSIO_IPSEC_INLINE */
out: out:
return u_ctx; return u_ctx;
} }
...@@ -187,6 +194,13 @@ int chcr_uld_rx_handler(void *handle, const __be64 *rsp, ...@@ -187,6 +194,13 @@ int chcr_uld_rx_handler(void *handle, const __be64 *rsp,
return 0; return 0;
} }
#ifdef CONFIG_CHELSIO_IPSEC_INLINE
int chcr_uld_tx_handler(struct sk_buff *skb, struct net_device *dev)
{
return chcr_ipsec_xmit(skb, dev);
}
#endif /* CONFIG_CHELSIO_IPSEC_INLINE */
static int chcr_uld_state_change(void *handle, enum cxgb4_state state) static int chcr_uld_state_change(void *handle, enum cxgb4_state state)
{ {
struct uld_ctx *u_ctx = handle; struct uld_ctx *u_ctx = handle;
......
...@@ -39,6 +39,7 @@ ...@@ -39,6 +39,7 @@
#include <crypto/algapi.h> #include <crypto/algapi.h>
#include "t4_hw.h" #include "t4_hw.h"
#include "cxgb4.h" #include "cxgb4.h"
#include "t4_msg.h"
#include "cxgb4_uld.h" #include "cxgb4_uld.h"
#define DRV_MODULE_NAME "chcr" #define DRV_MODULE_NAME "chcr"
...@@ -89,12 +90,49 @@ struct uld_ctx { ...@@ -89,12 +90,49 @@ struct uld_ctx {
struct chcr_dev *dev; struct chcr_dev *dev;
}; };
struct chcr_ipsec_req {
struct ulp_txpkt ulptx;
struct ulptx_idata sc_imm;
struct cpl_tx_sec_pdu sec_cpl;
struct _key_ctx key_ctx;
};
struct chcr_ipsec_wr {
struct fw_ulptx_wr wreq;
struct chcr_ipsec_req req;
};
struct ipsec_sa_entry {
int hmac_ctrl;
unsigned int enckey_len;
unsigned int kctx_len;
unsigned int authsize;
__be32 key_ctx_hdr;
char salt[MAX_SALT];
char key[2 * AES_MAX_KEY_SIZE];
};
/*
* sgl_len - calculates the size of an SGL of the given capacity
* @n: the number of SGL entries
* Calculates the number of flits needed for a scatter/gather list that
* can hold the given number of entries.
*/
static inline unsigned int sgl_len(unsigned int n)
{
n--;
return (3 * n) / 2 + (n & 1) + 2;
}
struct uld_ctx *assign_chcr_device(void); struct uld_ctx *assign_chcr_device(void);
int chcr_send_wr(struct sk_buff *skb); int chcr_send_wr(struct sk_buff *skb);
int start_crypto(void); int start_crypto(void);
int stop_crypto(void); int stop_crypto(void);
int chcr_uld_rx_handler(void *handle, const __be64 *rsp, int chcr_uld_rx_handler(void *handle, const __be64 *rsp,
const struct pkt_gl *pgl); const struct pkt_gl *pgl);
int chcr_uld_tx_handler(struct sk_buff *skb, struct net_device *dev);
int chcr_handle_resp(struct crypto_async_request *req, unsigned char *input, int chcr_handle_resp(struct crypto_async_request *req, unsigned char *input,
int err); int err);
int chcr_ipsec_xmit(struct sk_buff *skb, struct net_device *dev);
void chcr_add_xfrmops(const struct cxgb4_lld_info *lld);
#endif /* __CHCR_CORE_H__ */ #endif /* __CHCR_CORE_H__ */
...@@ -210,8 +210,6 @@ struct dsgl_walk { ...@@ -210,8 +210,6 @@ struct dsgl_walk {
struct phys_sge_pairs *to; struct phys_sge_pairs *to;
}; };
struct chcr_gcm_ctx { struct chcr_gcm_ctx {
u8 ghash_h[AEAD_H_SIZE]; u8 ghash_h[AEAD_H_SIZE];
}; };
...@@ -227,8 +225,6 @@ struct __aead_ctx { ...@@ -227,8 +225,6 @@ struct __aead_ctx {
struct chcr_authenc_ctx authenc[0]; struct chcr_authenc_ctx authenc[0];
}; };
struct chcr_aead_ctx { struct chcr_aead_ctx {
__be32 key_ctx_hdr; __be32 key_ctx_hdr;
unsigned int enckey_len; unsigned int enckey_len;
...@@ -240,8 +236,6 @@ struct chcr_aead_ctx { ...@@ -240,8 +236,6 @@ struct chcr_aead_ctx {
struct __aead_ctx ctx[0]; struct __aead_ctx ctx[0];
}; };
struct hmac_ctx { struct hmac_ctx {
struct crypto_shash *base_hash; struct crypto_shash *base_hash;
u8 ipad[CHCR_HASH_MAX_BLOCK_SIZE_128]; u8 ipad[CHCR_HASH_MAX_BLOCK_SIZE_128];
...@@ -307,44 +301,29 @@ typedef struct sk_buff *(*create_wr_t)(struct aead_request *req, ...@@ -307,44 +301,29 @@ typedef struct sk_buff *(*create_wr_t)(struct aead_request *req,
int size, int size,
unsigned short op_type); unsigned short op_type);
static int chcr_aead_op(struct aead_request *req_base, void chcr_verify_tag(struct aead_request *req, u8 *input, int *err);
unsigned short op_type, int chcr_aead_dma_map(struct device *dev, struct aead_request *req,
int size, unsigned short op_type);
create_wr_t create_wr_fn); void chcr_aead_dma_unmap(struct device *dev, struct aead_request *req,
static inline int get_aead_subtype(struct crypto_aead *aead); unsigned short op_type);
static int chcr_handle_cipher_resp(struct ablkcipher_request *req, void chcr_add_aead_dst_ent(struct aead_request *req,
unsigned char *input, int err); struct cpl_rx_phys_dsgl *phys_cpl,
static void chcr_verify_tag(struct aead_request *req, u8 *input, int *err); unsigned int assoclen, unsigned short op_type,
static int chcr_aead_dma_map(struct device *dev, struct aead_request *req, unsigned short qid);
unsigned short op_type); void chcr_add_aead_src_ent(struct aead_request *req, struct ulptx_sgl *ulptx,
static void chcr_aead_dma_unmap(struct device *dev, struct aead_request unsigned int assoclen, unsigned short op_type);
*req, unsigned short op_type); void chcr_add_cipher_src_ent(struct ablkcipher_request *req,
static inline void chcr_add_aead_dst_ent(struct aead_request *req, struct ulptx_sgl *ulptx,
struct cpl_rx_phys_dsgl *phys_cpl, struct cipher_wr_param *wrparam);
unsigned int assoclen, int chcr_cipher_dma_map(struct device *dev, struct ablkcipher_request *req);
unsigned short op_type, void chcr_cipher_dma_unmap(struct device *dev, struct ablkcipher_request *req);
unsigned short qid); void chcr_add_cipher_dst_ent(struct ablkcipher_request *req,
static inline void chcr_add_aead_src_ent(struct aead_request *req, struct cpl_rx_phys_dsgl *phys_cpl,
struct ulptx_sgl *ulptx, struct cipher_wr_param *wrparam,
unsigned int assoclen, unsigned short qid);
unsigned short op_type);
static inline void chcr_add_cipher_src_ent(struct ablkcipher_request *req,
struct ulptx_sgl *ulptx,
struct cipher_wr_param *wrparam);
static int chcr_cipher_dma_map(struct device *dev,
struct ablkcipher_request *req);
static void chcr_cipher_dma_unmap(struct device *dev,
struct ablkcipher_request *req);
static inline void chcr_add_cipher_dst_ent(struct ablkcipher_request *req,
struct cpl_rx_phys_dsgl *phys_cpl,
struct cipher_wr_param *wrparam,
unsigned short qid);
int sg_nents_len_skip(struct scatterlist *sg, u64 len, u64 skip); int sg_nents_len_skip(struct scatterlist *sg, u64 len, u64 skip);
static inline void chcr_add_hash_src_ent(struct ahash_request *req, void chcr_add_hash_src_ent(struct ahash_request *req, struct ulptx_sgl *ulptx,
struct ulptx_sgl *ulptx, struct hash_wr_param *param);
struct hash_wr_param *param); int chcr_hash_dma_map(struct device *dev, struct ahash_request *req);
static inline int chcr_hash_dma_map(struct device *dev, void chcr_hash_dma_unmap(struct device *dev, struct ahash_request *req);
struct ahash_request *req);
static inline void chcr_hash_dma_unmap(struct device *dev,
struct ahash_request *req);
#endif /* __CHCR_CRYPTO_H__ */ #endif /* __CHCR_CRYPTO_H__ */
This diff is collapsed.
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment