nitrox_dev.h 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181
  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. #define VERSION_LEN 32
  8. struct nitrox_cmdq {
  9. /* command queue lock */
  10. spinlock_t cmdq_lock;
  11. /* response list lock */
  12. spinlock_t response_lock;
  13. /* backlog list lock */
  14. spinlock_t backlog_lock;
  15. /* request submitted to chip, in progress */
  16. struct list_head response_head;
  17. /* hw queue full, hold in backlog list */
  18. struct list_head backlog_head;
  19. /* doorbell address */
  20. u8 __iomem *dbell_csr_addr;
  21. /* base address of the queue */
  22. u8 *head;
  23. struct nitrox_device *ndev;
  24. /* flush pending backlog commands */
  25. struct work_struct backlog_qflush;
  26. /* requests posted waiting for completion */
  27. atomic_t pending_count;
  28. /* requests in backlog queues */
  29. atomic_t backlog_count;
  30. int write_idx;
  31. /* command size 32B/64B */
  32. u8 instr_size;
  33. u8 qno;
  34. u32 qsize;
  35. /* unaligned addresses */
  36. u8 *head_unaligned;
  37. dma_addr_t dma_unaligned;
  38. /* dma address of the base */
  39. dma_addr_t dma;
  40. };
  41. struct nitrox_hw {
  42. /* firmware version */
  43. char fw_name[VERSION_LEN];
  44. u16 vendor_id;
  45. u16 device_id;
  46. u8 revision_id;
  47. /* CNN55XX cores */
  48. u8 se_cores;
  49. u8 ae_cores;
  50. u8 zip_cores;
  51. };
  52. #define MAX_MSIX_VECTOR_NAME 20
  53. /**
  54. * vectors for queues (64 AE, 64 SE and 64 ZIP) and
  55. * error condition/mailbox.
  56. */
  57. #define MAX_MSIX_VECTORS 192
  58. struct nitrox_msix {
  59. struct msix_entry *entries;
  60. char **names;
  61. DECLARE_BITMAP(irqs, MAX_MSIX_VECTORS);
  62. u32 nr_entries;
  63. };
  64. struct bh_data {
  65. /* slc port completion count address */
  66. u8 __iomem *completion_cnt_csr_addr;
  67. struct nitrox_cmdq *cmdq;
  68. struct tasklet_struct resp_handler;
  69. };
  70. struct nitrox_bh {
  71. struct bh_data *slc;
  72. };
  73. /* NITROX-V driver state */
  74. #define NITROX_UCODE_LOADED 0
  75. #define NITROX_READY 1
  76. /* command queue size */
  77. #define DEFAULT_CMD_QLEN 2048
  78. /* command timeout in milliseconds */
  79. #define CMD_TIMEOUT 2000
  80. #define DEV(ndev) ((struct device *)(&(ndev)->pdev->dev))
  81. #define PF_MODE 0
  82. #define NITROX_CSR_ADDR(ndev, offset) \
  83. ((ndev)->bar_addr + (offset))
  84. /**
  85. * struct nitrox_device - NITROX Device Information.
  86. * @list: pointer to linked list of devices
  87. * @bar_addr: iomap address
  88. * @pdev: PCI device information
  89. * @status: NITROX status
  90. * @timeout: Request timeout in jiffies
  91. * @refcnt: Device usage count
  92. * @idx: device index (0..N)
  93. * @node: NUMA node id attached
  94. * @qlen: Command queue length
  95. * @nr_queues: Number of command queues
  96. * @ctx_pool: DMA pool for crypto context
  97. * @pkt_cmdqs: SE Command queues
  98. * @msix: MSI-X information
  99. * @bh: post processing work
  100. * @hw: hardware information
  101. * @debugfs_dir: debugfs directory
  102. */
  103. struct nitrox_device {
  104. struct list_head list;
  105. u8 __iomem *bar_addr;
  106. struct pci_dev *pdev;
  107. unsigned long status;
  108. unsigned long timeout;
  109. refcount_t refcnt;
  110. u8 idx;
  111. int node;
  112. u16 qlen;
  113. u16 nr_queues;
  114. struct dma_pool *ctx_pool;
  115. struct nitrox_cmdq *pkt_cmdqs;
  116. struct nitrox_msix msix;
  117. struct nitrox_bh bh;
  118. struct nitrox_hw hw;
  119. #if IS_ENABLED(CONFIG_DEBUG_FS)
  120. struct dentry *debugfs_dir;
  121. #endif
  122. };
  123. /**
  124. * nitrox_read_csr - Read from device register
  125. * @ndev: NITROX device
  126. * @offset: offset of the register to read
  127. *
  128. * Returns: value read
  129. */
  130. static inline u64 nitrox_read_csr(struct nitrox_device *ndev, u64 offset)
  131. {
  132. return readq(ndev->bar_addr + offset);
  133. }
  134. /**
  135. * nitrox_write_csr - Write to device register
  136. * @ndev: NITROX device
  137. * @offset: offset of the register to write
  138. * @value: value to write
  139. */
  140. static inline void nitrox_write_csr(struct nitrox_device *ndev, u64 offset,
  141. u64 value)
  142. {
  143. writeq(value, (ndev->bar_addr + offset));
  144. }
  145. static inline int nitrox_ready(struct nitrox_device *ndev)
  146. {
  147. return test_bit(NITROX_READY, &ndev->status);
  148. }
  149. #endif /* __NITROX_DEV_H */