chcr_core.h 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
  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 <net/tls.h>
  39. #include "t4_hw.h"
  40. #include "cxgb4.h"
  41. #include "t4_msg.h"
  42. #include "cxgb4_uld.h"
  43. #define DRV_MODULE_NAME "chcr"
  44. #define DRV_DESC "Chelsio T6 Crypto Co-processor Driver"
  45. #define MAX_PENDING_REQ_TO_HW 20
  46. #define CHCR_TEST_RESPONSE_TIMEOUT 1000
  47. #define WQ_DETACH_TM (msecs_to_jiffies(50))
  48. #define PAD_ERROR_BIT 1
  49. #define CHK_PAD_ERR_BIT(x) (((x) >> PAD_ERROR_BIT) & 1)
  50. #define MAC_ERROR_BIT 0
  51. #define CHK_MAC_ERR_BIT(x) (((x) >> MAC_ERROR_BIT) & 1)
  52. #define MAX_SALT 4
  53. #define CIP_WR_MIN_LEN (sizeof(struct chcr_wr) + \
  54. sizeof(struct cpl_rx_phys_dsgl) + \
  55. sizeof(struct ulptx_sgl) + 16) //IV
  56. #define HASH_WR_MIN_LEN (sizeof(struct chcr_wr) + \
  57. DUMMY_BYTES + \
  58. sizeof(struct ulptx_sgl))
  59. struct uld_ctx;
  60. struct _key_ctx {
  61. __be32 ctx_hdr;
  62. u8 salt[MAX_SALT];
  63. __be64 iv_to_auth;
  64. unsigned char key[];
  65. };
  66. #define WQ_RETRY 5
  67. struct chcr_driver_data {
  68. struct list_head act_dev;
  69. struct list_head inact_dev;
  70. atomic_t dev_count;
  71. struct mutex drv_mutex;
  72. struct uld_ctx *last_dev;
  73. };
  74. enum chcr_state {
  75. CHCR_INIT = 0,
  76. CHCR_ATTACH,
  77. CHCR_DETACH,
  78. };
  79. struct chcr_wr {
  80. struct fw_crypto_lookaside_wr wreq;
  81. struct ulp_txpkt ulptx;
  82. struct ulptx_idata sc_imm;
  83. struct cpl_tx_sec_pdu sec_cpl;
  84. struct _key_ctx key_ctx;
  85. };
  86. struct chcr_dev {
  87. spinlock_t lock_chcr_dev;
  88. enum chcr_state state;
  89. atomic_t inflight;
  90. int wqretry;
  91. struct delayed_work detach_work;
  92. struct completion detach_comp;
  93. };
  94. struct uld_ctx {
  95. struct list_head entry;
  96. struct cxgb4_lld_info lldi;
  97. struct chcr_dev dev;
  98. };
  99. /*
  100. * sgl_len - calculates the size of an SGL of the given capacity
  101. * @n: the number of SGL entries
  102. * Calculates the number of flits needed for a scatter/gather list that
  103. * can hold the given number of entries.
  104. */
  105. static inline unsigned int sgl_len(unsigned int n)
  106. {
  107. n--;
  108. return (3 * n) / 2 + (n & 1) + 2;
  109. }
  110. static inline void *padap(struct chcr_dev *dev)
  111. {
  112. struct uld_ctx *u_ctx = container_of(dev, struct uld_ctx, dev);
  113. return pci_get_drvdata(u_ctx->lldi.pdev);
  114. }
  115. struct uld_ctx *assign_chcr_device(void);
  116. int chcr_send_wr(struct sk_buff *skb);
  117. int start_crypto(void);
  118. int stop_crypto(void);
  119. int chcr_uld_rx_handler(void *handle, const __be64 *rsp,
  120. const struct pkt_gl *pgl);
  121. int chcr_handle_resp(struct crypto_async_request *req, unsigned char *input,
  122. int err);
  123. #endif /* __CHCR_CORE_H__ */