nitrox_dev.h 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229
  1. /* SPDX-License-Identifier: GPL-2.0 */
  2. #ifndef __NITROX_DEV_H
  3. #define __NITROX_DEV_H
  4. #include <linux/dma-mapping.h>
  5. #include <linux/interrupt.h>
  6. #include <linux/pci.h>
  7. #include <linux/if.h>
  8. #define VERSION_LEN 32
  9. /**
  10. * struct nitrox_cmdq - NITROX command queue
  11. * @cmd_qlock: command queue lock
  12. * @resp_qlock: response queue lock
  13. * @backlog_qlock: backlog queue lock
  14. * @ndev: NITROX device
  15. * @response_head: submitted request list
  16. * @backlog_head: backlog queue
  17. * @dbell_csr_addr: doorbell register address for this queue
  18. * @compl_cnt_csr_addr: completion count register address of the slc port
  19. * @base: command queue base address
  20. * @dma: dma address of the base
  21. * @pending_count: request pending at device
  22. * @backlog_count: backlog request count
  23. * @write_idx: next write index for the command
  24. * @instr_size: command size
  25. * @qno: command queue number
  26. * @qsize: command queue size
  27. * @unalign_base: unaligned base address
  28. * @unalign_dma: unaligned dma address
  29. */
  30. struct nitrox_cmdq {
  31. spinlock_t cmd_qlock;
  32. spinlock_t resp_qlock;
  33. spinlock_t backlog_qlock;
  34. struct nitrox_device *ndev;
  35. struct list_head response_head;
  36. struct list_head backlog_head;
  37. u8 __iomem *dbell_csr_addr;
  38. u8 __iomem *compl_cnt_csr_addr;
  39. u8 *base;
  40. dma_addr_t dma;
  41. struct work_struct backlog_qflush;
  42. atomic_t pending_count;
  43. atomic_t backlog_count;
  44. int write_idx;
  45. u8 instr_size;
  46. u8 qno;
  47. u32 qsize;
  48. u8 *unalign_base;
  49. dma_addr_t unalign_dma;
  50. };
  51. /**
  52. * struct nitrox_hw - NITROX hardware information
  53. * @partname: partname ex: CNN55xxx-xxx
  54. * @fw_name: firmware version
  55. * @freq: NITROX frequency
  56. * @vendor_id: vendor ID
  57. * @device_id: device ID
  58. * @revision_id: revision ID
  59. * @se_cores: number of symmetric cores
  60. * @ae_cores: number of asymmetric cores
  61. * @zip_cores: number of zip cores
  62. */
  63. struct nitrox_hw {
  64. char partname[IFNAMSIZ * 2];
  65. char fw_name[VERSION_LEN];
  66. int freq;
  67. u16 vendor_id;
  68. u16 device_id;
  69. u8 revision_id;
  70. u8 se_cores;
  71. u8 ae_cores;
  72. u8 zip_cores;
  73. };
  74. struct nitrox_stats {
  75. atomic64_t posted;
  76. atomic64_t completed;
  77. atomic64_t dropped;
  78. };
  79. #define IRQ_NAMESZ 32
  80. struct nitrox_q_vector {
  81. char name[IRQ_NAMESZ];
  82. bool valid;
  83. int ring;
  84. struct tasklet_struct resp_tasklet;
  85. union {
  86. struct nitrox_cmdq *cmdq;
  87. struct nitrox_device *ndev;
  88. };
  89. };
  90. /*
  91. * NITROX Device states
  92. */
  93. enum ndev_state {
  94. __NDEV_NOT_READY,
  95. __NDEV_READY,
  96. __NDEV_IN_RESET,
  97. };
  98. /* NITROX support modes for VF(s) */
  99. enum vf_mode {
  100. __NDEV_MODE_PF,
  101. __NDEV_MODE_VF16,
  102. __NDEV_MODE_VF32,
  103. __NDEV_MODE_VF64,
  104. __NDEV_MODE_VF128,
  105. };
  106. #define __NDEV_SRIOV_BIT 0
  107. /* command queue size */
  108. #define DEFAULT_CMD_QLEN 2048
  109. /* command timeout in milliseconds */
  110. #define CMD_TIMEOUT 2000
  111. #define DEV(ndev) ((struct device *)(&(ndev)->pdev->dev))
  112. #define NITROX_CSR_ADDR(ndev, offset) \
  113. ((ndev)->bar_addr + (offset))
  114. /**
  115. * struct nitrox_device - NITROX Device Information.
  116. * @list: pointer to linked list of devices
  117. * @bar_addr: iomap address
  118. * @pdev: PCI device information
  119. * @state: NITROX device state
  120. * @flags: flags to indicate device the features
  121. * @timeout: Request timeout in jiffies
  122. * @refcnt: Device usage count
  123. * @idx: device index (0..N)
  124. * @node: NUMA node id attached
  125. * @qlen: Command queue length
  126. * @nr_queues: Number of command queues
  127. * @mode: Device mode PF/VF
  128. * @ctx_pool: DMA pool for crypto context
  129. * @pkt_inq: Packet input rings
  130. * @qvec: MSI-X queue vectors information
  131. * @hw: hardware information
  132. * @debugfs_dir: debugfs directory
  133. */
  134. struct nitrox_device {
  135. struct list_head list;
  136. u8 __iomem *bar_addr;
  137. struct pci_dev *pdev;
  138. atomic_t state;
  139. unsigned long flags;
  140. unsigned long timeout;
  141. refcount_t refcnt;
  142. u8 idx;
  143. int node;
  144. u16 qlen;
  145. u16 nr_queues;
  146. int num_vfs;
  147. enum vf_mode mode;
  148. struct dma_pool *ctx_pool;
  149. struct nitrox_cmdq *pkt_inq;
  150. struct nitrox_q_vector *qvec;
  151. int num_vecs;
  152. struct nitrox_stats stats;
  153. struct nitrox_hw hw;
  154. #if IS_ENABLED(CONFIG_DEBUG_FS)
  155. struct dentry *debugfs_dir;
  156. #endif
  157. };
  158. /**
  159. * nitrox_read_csr - Read from device register
  160. * @ndev: NITROX device
  161. * @offset: offset of the register to read
  162. *
  163. * Returns: value read
  164. */
  165. static inline u64 nitrox_read_csr(struct nitrox_device *ndev, u64 offset)
  166. {
  167. return readq(ndev->bar_addr + offset);
  168. }
  169. /**
  170. * nitrox_write_csr - Write to device register
  171. * @ndev: NITROX device
  172. * @offset: offset of the register to write
  173. * @value: value to write
  174. */
  175. static inline void nitrox_write_csr(struct nitrox_device *ndev, u64 offset,
  176. u64 value)
  177. {
  178. writeq(value, (ndev->bar_addr + offset));
  179. }
  180. static inline bool nitrox_ready(struct nitrox_device *ndev)
  181. {
  182. return atomic_read(&ndev->state) == __NDEV_READY;
  183. }
  184. #ifdef CONFIG_DEBUG_FS
  185. int nitrox_debugfs_init(struct nitrox_device *ndev);
  186. void nitrox_debugfs_exit(struct nitrox_device *ndev);
  187. #else
  188. static inline int nitrox_debugfs_init(struct nitrox_device *ndev)
  189. {
  190. return 0;
  191. }
  192. static inline void nitrox_debugfs_exit(struct nitrox_device *ndev)
  193. { }
  194. #endif
  195. #endif /* __NITROX_DEV_H */