nitrox_dev.h 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302
  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. /* Maximum queues in PF mode */
  10. #define MAX_PF_QUEUES 64
  11. /* Maximum device queues */
  12. #define MAX_DEV_QUEUES (MAX_PF_QUEUES)
  13. /* Maximum UCD Blocks */
  14. #define CNN55XX_MAX_UCD_BLOCKS 8
  15. /**
  16. * struct nitrox_cmdq - NITROX command queue
  17. * @cmd_qlock: command queue lock
  18. * @resp_qlock: response queue lock
  19. * @backlog_qlock: backlog queue lock
  20. * @ndev: NITROX device
  21. * @response_head: submitted request list
  22. * @backlog_head: backlog queue
  23. * @dbell_csr_addr: doorbell register address for this queue
  24. * @compl_cnt_csr_addr: completion count register address of the slc port
  25. * @base: command queue base address
  26. * @dma: dma address of the base
  27. * @pending_count: request pending at device
  28. * @backlog_count: backlog request count
  29. * @write_idx: next write index for the command
  30. * @instr_size: command size
  31. * @qno: command queue number
  32. * @qsize: command queue size
  33. * @unalign_base: unaligned base address
  34. * @unalign_dma: unaligned dma address
  35. */
  36. struct nitrox_cmdq {
  37. spinlock_t cmd_qlock;
  38. spinlock_t resp_qlock;
  39. spinlock_t backlog_qlock;
  40. struct nitrox_device *ndev;
  41. struct list_head response_head;
  42. struct list_head backlog_head;
  43. u8 __iomem *dbell_csr_addr;
  44. u8 __iomem *compl_cnt_csr_addr;
  45. u8 *base;
  46. dma_addr_t dma;
  47. struct work_struct backlog_qflush;
  48. atomic_t pending_count;
  49. atomic_t backlog_count;
  50. int write_idx;
  51. u8 instr_size;
  52. u8 qno;
  53. u32 qsize;
  54. u8 *unalign_base;
  55. dma_addr_t unalign_dma;
  56. };
  57. /**
  58. * struct nitrox_hw - NITROX hardware information
  59. * @partname: partname ex: CNN55xxx-xxx
  60. * @fw_name: firmware version
  61. * @freq: NITROX frequency
  62. * @vendor_id: vendor ID
  63. * @device_id: device ID
  64. * @revision_id: revision ID
  65. * @se_cores: number of symmetric cores
  66. * @ae_cores: number of asymmetric cores
  67. * @zip_cores: number of zip cores
  68. */
  69. struct nitrox_hw {
  70. char partname[IFNAMSIZ * 2];
  71. char fw_name[CNN55XX_MAX_UCD_BLOCKS][VERSION_LEN];
  72. int freq;
  73. u16 vendor_id;
  74. u16 device_id;
  75. u8 revision_id;
  76. u8 se_cores;
  77. u8 ae_cores;
  78. u8 zip_cores;
  79. };
  80. struct nitrox_stats {
  81. atomic64_t posted;
  82. atomic64_t completed;
  83. atomic64_t dropped;
  84. };
  85. #define IRQ_NAMESZ 32
  86. struct nitrox_q_vector {
  87. char name[IRQ_NAMESZ];
  88. bool valid;
  89. int ring;
  90. struct tasklet_struct resp_tasklet;
  91. union {
  92. struct nitrox_cmdq *cmdq;
  93. struct nitrox_device *ndev;
  94. };
  95. };
  96. enum mcode_type {
  97. MCODE_TYPE_INVALID,
  98. MCODE_TYPE_AE,
  99. MCODE_TYPE_SE_SSL,
  100. MCODE_TYPE_SE_IPSEC,
  101. };
  102. /**
  103. * mbox_msg - Mailbox message data
  104. * @type: message type
  105. * @opcode: message opcode
  106. * @data: message data
  107. */
  108. union mbox_msg {
  109. u64 value;
  110. struct {
  111. u64 type: 2;
  112. u64 opcode: 6;
  113. u64 data: 58;
  114. };
  115. struct {
  116. u64 type: 2;
  117. u64 opcode: 6;
  118. u64 chipid: 8;
  119. u64 vfid: 8;
  120. } id;
  121. struct {
  122. u64 type: 2;
  123. u64 opcode: 6;
  124. u64 count: 4;
  125. u64 info: 40;
  126. u64 next_se_grp: 3;
  127. u64 next_ae_grp: 3;
  128. } mcode_info;
  129. };
  130. /**
  131. * nitrox_vfdev - NITROX VF device instance in PF
  132. * @state: VF device state
  133. * @vfno: VF number
  134. * @nr_queues: number of queues enabled in VF
  135. * @ring: ring to communicate with VF
  136. * @msg: Mailbox message data from VF
  137. * @mbx_resp: Mailbox counters
  138. */
  139. struct nitrox_vfdev {
  140. atomic_t state;
  141. int vfno;
  142. int nr_queues;
  143. int ring;
  144. union mbox_msg msg;
  145. atomic64_t mbx_resp;
  146. };
  147. /**
  148. * struct nitrox_iov - SR-IOV information
  149. * @num_vfs: number of VF(s) enabled
  150. * @max_vf_queues: Maximum number of queues allowed for VF
  151. * @vfdev: VF(s) devices
  152. * @pf2vf_wq: workqueue for PF2VF communication
  153. * @msix: MSI-X entry for PF in SR-IOV case
  154. */
  155. struct nitrox_iov {
  156. int num_vfs;
  157. int max_vf_queues;
  158. struct nitrox_vfdev *vfdev;
  159. struct workqueue_struct *pf2vf_wq;
  160. struct msix_entry msix;
  161. };
  162. /*
  163. * NITROX Device states
  164. */
  165. enum ndev_state {
  166. __NDEV_NOT_READY,
  167. __NDEV_READY,
  168. __NDEV_IN_RESET,
  169. };
  170. /* NITROX support modes for VF(s) */
  171. enum vf_mode {
  172. __NDEV_MODE_PF,
  173. __NDEV_MODE_VF16,
  174. __NDEV_MODE_VF32,
  175. __NDEV_MODE_VF64,
  176. __NDEV_MODE_VF128,
  177. };
  178. #define __NDEV_SRIOV_BIT 0
  179. /* command queue size */
  180. #define DEFAULT_CMD_QLEN 2048
  181. /* command timeout in milliseconds */
  182. #define CMD_TIMEOUT 2000
  183. #define DEV(ndev) ((struct device *)(&(ndev)->pdev->dev))
  184. #define NITROX_CSR_ADDR(ndev, offset) \
  185. ((ndev)->bar_addr + (offset))
  186. /**
  187. * struct nitrox_device - NITROX Device Information.
  188. * @list: pointer to linked list of devices
  189. * @bar_addr: iomap address
  190. * @pdev: PCI device information
  191. * @state: NITROX device state
  192. * @flags: flags to indicate device the features
  193. * @timeout: Request timeout in jiffies
  194. * @refcnt: Device usage count
  195. * @idx: device index (0..N)
  196. * @node: NUMA node id attached
  197. * @qlen: Command queue length
  198. * @nr_queues: Number of command queues
  199. * @mode: Device mode PF/VF
  200. * @ctx_pool: DMA pool for crypto context
  201. * @pkt_inq: Packet input rings
  202. * @aqmq: AQM command queues
  203. * @qvec: MSI-X queue vectors information
  204. * @iov: SR-IOV informatin
  205. * @num_vecs: number of MSI-X vectors
  206. * @stats: request statistics
  207. * @hw: hardware information
  208. * @debugfs_dir: debugfs directory
  209. */
  210. struct nitrox_device {
  211. struct list_head list;
  212. u8 __iomem *bar_addr;
  213. struct pci_dev *pdev;
  214. atomic_t state;
  215. unsigned long flags;
  216. unsigned long timeout;
  217. refcount_t refcnt;
  218. u8 idx;
  219. int node;
  220. u16 qlen;
  221. u16 nr_queues;
  222. enum vf_mode mode;
  223. struct dma_pool *ctx_pool;
  224. struct nitrox_cmdq *pkt_inq;
  225. struct nitrox_cmdq *aqmq[MAX_DEV_QUEUES] ____cacheline_aligned_in_smp;
  226. struct nitrox_q_vector *qvec;
  227. struct nitrox_iov iov;
  228. int num_vecs;
  229. struct nitrox_stats stats;
  230. struct nitrox_hw hw;
  231. #if IS_ENABLED(CONFIG_DEBUG_FS)
  232. struct dentry *debugfs_dir;
  233. #endif
  234. };
  235. /**
  236. * nitrox_read_csr - Read from device register
  237. * @ndev: NITROX device
  238. * @offset: offset of the register to read
  239. *
  240. * Returns: value read
  241. */
  242. static inline u64 nitrox_read_csr(struct nitrox_device *ndev, u64 offset)
  243. {
  244. return readq(ndev->bar_addr + offset);
  245. }
  246. /**
  247. * nitrox_write_csr - Write to device register
  248. * @ndev: NITROX device
  249. * @offset: offset of the register to write
  250. * @value: value to write
  251. */
  252. static inline void nitrox_write_csr(struct nitrox_device *ndev, u64 offset,
  253. u64 value)
  254. {
  255. writeq(value, (ndev->bar_addr + offset));
  256. }
  257. static inline bool nitrox_ready(struct nitrox_device *ndev)
  258. {
  259. return atomic_read(&ndev->state) == __NDEV_READY;
  260. }
  261. static inline bool nitrox_vfdev_ready(struct nitrox_vfdev *vfdev)
  262. {
  263. return atomic_read(&vfdev->state) == __NDEV_READY;
  264. }
  265. #endif /* __NITROX_DEV_H */