cptvf.h 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  1. /*
  2. * Copyright (C) 2016 Cavium, Inc.
  3. *
  4. * This program is free software; you can redistribute it and/or modify it
  5. * under the terms of version 2 of the GNU General Public License
  6. * as published by the Free Software Foundation.
  7. */
  8. #ifndef __CPTVF_H
  9. #define __CPTVF_H
  10. #include <linux/list.h>
  11. #include "cpt_common.h"
  12. /* Default command queue length */
  13. #define CPT_CMD_QLEN 2046
  14. #define CPT_CMD_QCHUNK_SIZE 1023
  15. /* Default command timeout in seconds */
  16. #define CPT_COMMAND_TIMEOUT 4
  17. #define CPT_TIMER_THOLD 0xFFFF
  18. #define CPT_NUM_QS_PER_VF 1
  19. #define CPT_INST_SIZE 64
  20. #define CPT_NEXT_CHUNK_PTR_SIZE 8
  21. #define CPT_VF_MSIX_VECTORS 2
  22. #define CPT_VF_INTR_MBOX_MASK BIT(0)
  23. #define CPT_VF_INTR_DOVF_MASK BIT(1)
  24. #define CPT_VF_INTR_IRDE_MASK BIT(2)
  25. #define CPT_VF_INTR_NWRP_MASK BIT(3)
  26. #define CPT_VF_INTR_SERR_MASK BIT(4)
  27. #define DMA_DIRECT_DIRECT 0 /* Input DIRECT, Output DIRECT */
  28. #define DMA_GATHER_SCATTER 1
  29. #define FROM_DPTR 1
  30. /**
  31. * Enumeration cpt_vf_int_vec_e
  32. *
  33. * CPT VF MSI-X Vector Enumeration
  34. * Enumerates the MSI-X interrupt vectors.
  35. */
  36. enum cpt_vf_int_vec_e {
  37. CPT_VF_INT_VEC_E_MISC = 0x00,
  38. CPT_VF_INT_VEC_E_DONE = 0x01
  39. };
  40. struct command_chunk {
  41. u8 *head;
  42. dma_addr_t dma_addr;
  43. u32 size; /* Chunk size, max CPT_INST_CHUNK_MAX_SIZE */
  44. struct hlist_node nextchunk;
  45. };
  46. struct command_queue {
  47. spinlock_t lock; /* command queue lock */
  48. u32 idx; /* Command queue host write idx */
  49. u32 nchunks; /* Number of command chunks */
  50. struct command_chunk *qhead; /* Command queue head, instructions
  51. * are inserted here
  52. */
  53. struct hlist_head chead;
  54. };
  55. struct command_qinfo {
  56. u32 cmd_size;
  57. u32 qchunksize; /* Command queue chunk size */
  58. struct command_queue queue[CPT_NUM_QS_PER_VF];
  59. };
  60. struct pending_entry {
  61. u8 busy; /* Entry status (free/busy) */
  62. volatile u64 *completion_addr; /* Completion address */
  63. void *post_arg;
  64. void (*callback)(int, void *); /* Kernel ASYNC request callabck */
  65. void *callback_arg; /* Kernel ASYNC request callabck arg */
  66. };
  67. struct pending_queue {
  68. struct pending_entry *head; /* head of the queue */
  69. u32 front; /* Process work from here */
  70. u32 rear; /* Append new work here */
  71. atomic64_t pending_count;
  72. spinlock_t lock; /* Queue lock */
  73. };
  74. struct pending_qinfo {
  75. u32 nr_queues; /* Number of queues supported */
  76. u32 qlen; /* Queue length */
  77. struct pending_queue queue[CPT_NUM_QS_PER_VF];
  78. };
  79. #define for_each_pending_queue(qinfo, q, i) \
  80. for (i = 0, q = &qinfo->queue[i]; i < qinfo->nr_queues; i++, \
  81. q = &qinfo->queue[i])
  82. struct cpt_vf {
  83. u16 flags; /* Flags to hold device status bits */
  84. u8 vfid; /* Device Index 0...CPT_MAX_VF_NUM */
  85. u8 vftype; /* VF type of SE_TYPE(1) or AE_TYPE(1) */
  86. u8 vfgrp; /* VF group (0 - 8) */
  87. u8 node; /* Operating node: Bits (46:44) in BAR0 address */
  88. u8 priority; /* VF priority ring: 1-High proirity round
  89. * robin ring;0-Low priority round robin ring;
  90. */
  91. struct pci_dev *pdev; /* pci device handle */
  92. void __iomem *reg_base; /* Register start address */
  93. void *wqe_info; /* BH worker info */
  94. /* MSI-X */
  95. cpumask_var_t affinity_mask[CPT_VF_MSIX_VECTORS];
  96. /* Command and Pending queues */
  97. u32 qsize;
  98. u32 nr_queues;
  99. struct command_qinfo cqinfo; /* Command queue information */
  100. struct pending_qinfo pqinfo; /* Pending queue information */
  101. /* VF-PF mailbox communication */
  102. bool pf_acked;
  103. bool pf_nacked;
  104. };
  105. int cptvf_send_vf_up(struct cpt_vf *cptvf);
  106. int cptvf_send_vf_down(struct cpt_vf *cptvf);
  107. int cptvf_send_vf_to_grp_msg(struct cpt_vf *cptvf);
  108. int cptvf_send_vf_priority_msg(struct cpt_vf *cptvf);
  109. int cptvf_send_vq_size_msg(struct cpt_vf *cptvf);
  110. int cptvf_check_pf_ready(struct cpt_vf *cptvf);
  111. void cptvf_handle_mbox_intr(struct cpt_vf *cptvf);
  112. void cvm_crypto_exit(void);
  113. int cvm_crypto_init(struct cpt_vf *cptvf);
  114. void vq_post_process(struct cpt_vf *cptvf, u32 qno);
  115. void cptvf_write_vq_doorbell(struct cpt_vf *cptvf, u32 val);
  116. #endif /* __CPTVF_H */