chcr_core.h 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196
  1. /*
  2. * This file is part of the Chelsio T6 Crypto driver for Linux.
  3. *
  4. * Copyright (c) 2003-2016 Chelsio Communications, Inc. All rights reserved.
  5. *
  6. * This software is available to you under a choice of one of two
  7. * licenses. You may choose to be licensed under the terms of the GNU
  8. * General Public License (GPL) Version 2, available from the file
  9. * COPYING in the main directory of this source tree, or the
  10. * OpenIB.org BSD license below:
  11. *
  12. * Redistribution and use in source and binary forms, with or
  13. * without modification, are permitted provided that the following
  14. * conditions are met:
  15. *
  16. * - Redistributions of source code must retain the above
  17. * copyright notice, this list of conditions and the following
  18. * disclaimer.
  19. *
  20. * - Redistributions in binary form must reproduce the above
  21. * copyright notice, this list of conditions and the following
  22. * disclaimer in the documentation and/or other materials
  23. * provided with the distribution.
  24. *
  25. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  26. * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  27. * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  28. * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
  29. * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
  30. * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
  31. * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
  32. * SOFTWARE.
  33. *
  34. */
  35. #ifndef __CHCR_CORE_H__
  36. #define __CHCR_CORE_H__
  37. #include <crypto/algapi.h>
  38. #include "t4_hw.h"
  39. #include "cxgb4.h"
  40. #include "t4_msg.h"
  41. #include "cxgb4_uld.h"
  42. #define DRV_MODULE_NAME "chcr"
  43. #define DRV_VERSION "1.0.0.0"
  44. #define MAX_PENDING_REQ_TO_HW 20
  45. #define CHCR_TEST_RESPONSE_TIMEOUT 1000
  46. #define PAD_ERROR_BIT 1
  47. #define CHK_PAD_ERR_BIT(x) (((x) >> PAD_ERROR_BIT) & 1)
  48. #define MAC_ERROR_BIT 0
  49. #define CHK_MAC_ERR_BIT(x) (((x) >> MAC_ERROR_BIT) & 1)
  50. #define MAX_SALT 4
  51. #define CIP_WR_MIN_LEN (sizeof(struct chcr_wr) + \
  52. sizeof(struct cpl_rx_phys_dsgl) + \
  53. sizeof(struct ulptx_sgl) + 16) //IV
  54. #define HASH_WR_MIN_LEN (sizeof(struct chcr_wr) + \
  55. DUMMY_BYTES + \
  56. sizeof(struct ulptx_sgl))
  57. #define padap(dev) pci_get_drvdata(dev->u_ctx->lldi.pdev)
  58. struct uld_ctx;
  59. struct _key_ctx {
  60. __be32 ctx_hdr;
  61. u8 salt[MAX_SALT];
  62. __be64 iv_to_auth;
  63. unsigned char key[0];
  64. };
  65. #define KEYCTX_TX_WR_IV_S 55
  66. #define KEYCTX_TX_WR_IV_M 0x1ffULL
  67. #define KEYCTX_TX_WR_IV_V(x) ((x) << KEYCTX_TX_WR_IV_S)
  68. #define KEYCTX_TX_WR_IV_G(x) \
  69. (((x) >> KEYCTX_TX_WR_IV_S) & KEYCTX_TX_WR_IV_M)
  70. #define KEYCTX_TX_WR_AAD_S 47
  71. #define KEYCTX_TX_WR_AAD_M 0xffULL
  72. #define KEYCTX_TX_WR_AAD_V(x) ((x) << KEYCTX_TX_WR_AAD_S)
  73. #define KEYCTX_TX_WR_AAD_G(x) (((x) >> KEYCTX_TX_WR_AAD_S) & \
  74. KEYCTX_TX_WR_AAD_M)
  75. #define KEYCTX_TX_WR_AADST_S 39
  76. #define KEYCTX_TX_WR_AADST_M 0xffULL
  77. #define KEYCTX_TX_WR_AADST_V(x) ((x) << KEYCTX_TX_WR_AADST_S)
  78. #define KEYCTX_TX_WR_AADST_G(x) \
  79. (((x) >> KEYCTX_TX_WR_AADST_S) & KEYCTX_TX_WR_AADST_M)
  80. #define KEYCTX_TX_WR_CIPHER_S 30
  81. #define KEYCTX_TX_WR_CIPHER_M 0x1ffULL
  82. #define KEYCTX_TX_WR_CIPHER_V(x) ((x) << KEYCTX_TX_WR_CIPHER_S)
  83. #define KEYCTX_TX_WR_CIPHER_G(x) \
  84. (((x) >> KEYCTX_TX_WR_CIPHER_S) & KEYCTX_TX_WR_CIPHER_M)
  85. #define KEYCTX_TX_WR_CIPHERST_S 23
  86. #define KEYCTX_TX_WR_CIPHERST_M 0x7f
  87. #define KEYCTX_TX_WR_CIPHERST_V(x) ((x) << KEYCTX_TX_WR_CIPHERST_S)
  88. #define KEYCTX_TX_WR_CIPHERST_G(x) \
  89. (((x) >> KEYCTX_TX_WR_CIPHERST_S) & KEYCTX_TX_WR_CIPHERST_M)
  90. #define KEYCTX_TX_WR_AUTH_S 14
  91. #define KEYCTX_TX_WR_AUTH_M 0x1ff
  92. #define KEYCTX_TX_WR_AUTH_V(x) ((x) << KEYCTX_TX_WR_AUTH_S)
  93. #define KEYCTX_TX_WR_AUTH_G(x) \
  94. (((x) >> KEYCTX_TX_WR_AUTH_S) & KEYCTX_TX_WR_AUTH_M)
  95. #define KEYCTX_TX_WR_AUTHST_S 7
  96. #define KEYCTX_TX_WR_AUTHST_M 0x7f
  97. #define KEYCTX_TX_WR_AUTHST_V(x) ((x) << KEYCTX_TX_WR_AUTHST_S)
  98. #define KEYCTX_TX_WR_AUTHST_G(x) \
  99. (((x) >> KEYCTX_TX_WR_AUTHST_S) & KEYCTX_TX_WR_AUTHST_M)
  100. #define KEYCTX_TX_WR_AUTHIN_S 0
  101. #define KEYCTX_TX_WR_AUTHIN_M 0x7f
  102. #define KEYCTX_TX_WR_AUTHIN_V(x) ((x) << KEYCTX_TX_WR_AUTHIN_S)
  103. #define KEYCTX_TX_WR_AUTHIN_G(x) \
  104. (((x) >> KEYCTX_TX_WR_AUTHIN_S) & KEYCTX_TX_WR_AUTHIN_M)
  105. struct chcr_wr {
  106. struct fw_crypto_lookaside_wr wreq;
  107. struct ulp_txpkt ulptx;
  108. struct ulptx_idata sc_imm;
  109. struct cpl_tx_sec_pdu sec_cpl;
  110. struct _key_ctx key_ctx;
  111. };
  112. struct chcr_dev {
  113. spinlock_t lock_chcr_dev;
  114. struct uld_ctx *u_ctx;
  115. unsigned char tx_channel_id;
  116. unsigned char rx_channel_id;
  117. };
  118. struct uld_ctx {
  119. struct list_head entry;
  120. struct cxgb4_lld_info lldi;
  121. struct chcr_dev *dev;
  122. };
  123. struct sge_opaque_hdr {
  124. void *dev;
  125. dma_addr_t addr[MAX_SKB_FRAGS + 1];
  126. };
  127. struct chcr_ipsec_req {
  128. struct ulp_txpkt ulptx;
  129. struct ulptx_idata sc_imm;
  130. struct cpl_tx_sec_pdu sec_cpl;
  131. struct _key_ctx key_ctx;
  132. };
  133. struct chcr_ipsec_wr {
  134. struct fw_ulptx_wr wreq;
  135. struct chcr_ipsec_req req;
  136. };
  137. struct ipsec_sa_entry {
  138. int hmac_ctrl;
  139. unsigned int enckey_len;
  140. unsigned int kctx_len;
  141. unsigned int authsize;
  142. __be32 key_ctx_hdr;
  143. char salt[MAX_SALT];
  144. char key[2 * AES_MAX_KEY_SIZE];
  145. };
  146. /*
  147. * sgl_len - calculates the size of an SGL of the given capacity
  148. * @n: the number of SGL entries
  149. * Calculates the number of flits needed for a scatter/gather list that
  150. * can hold the given number of entries.
  151. */
  152. static inline unsigned int sgl_len(unsigned int n)
  153. {
  154. n--;
  155. return (3 * n) / 2 + (n & 1) + 2;
  156. }
  157. struct uld_ctx *assign_chcr_device(void);
  158. int chcr_send_wr(struct sk_buff *skb);
  159. int start_crypto(void);
  160. int stop_crypto(void);
  161. int chcr_uld_rx_handler(void *handle, const __be64 *rsp,
  162. const struct pkt_gl *pgl);
  163. int chcr_uld_tx_handler(struct sk_buff *skb, struct net_device *dev);
  164. int chcr_handle_resp(struct crypto_async_request *req, unsigned char *input,
  165. int err);
  166. int chcr_ipsec_xmit(struct sk_buff *skb, struct net_device *dev);
  167. void chcr_add_xfrmops(const struct cxgb4_lld_info *lld);
  168. #endif /* __CHCR_CORE_H__ */