idpf_controlq_api.h 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174
  1. /* SPDX-License-Identifier: GPL-2.0-only */
  2. /* Copyright (C) 2023 Intel Corporation */
  3. #ifndef _IDPF_CONTROLQ_API_H_
  4. #define _IDPF_CONTROLQ_API_H_
  5. #include "idpf_mem.h"
  6. struct idpf_hw;
  7. /* Used for queue init, response and events */
  8. enum idpf_ctlq_type {
  9. IDPF_CTLQ_TYPE_MAILBOX_TX = 0,
  10. IDPF_CTLQ_TYPE_MAILBOX_RX = 1,
  11. IDPF_CTLQ_TYPE_CONFIG_TX = 2,
  12. IDPF_CTLQ_TYPE_CONFIG_RX = 3,
  13. IDPF_CTLQ_TYPE_EVENT_RX = 4,
  14. IDPF_CTLQ_TYPE_RDMA_TX = 5,
  15. IDPF_CTLQ_TYPE_RDMA_RX = 6,
  16. IDPF_CTLQ_TYPE_RDMA_COMPL = 7
  17. };
  18. /* Generic Control Queue Structures */
  19. struct idpf_ctlq_reg {
  20. /* used for queue tracking */
  21. u32 head;
  22. u32 tail;
  23. /* Below applies only to default mb (if present) */
  24. u32 len;
  25. u32 bah;
  26. u32 bal;
  27. u32 len_mask;
  28. u32 len_ena_mask;
  29. u32 head_mask;
  30. };
  31. /* Generic queue msg structure */
  32. struct idpf_ctlq_msg {
  33. u8 vmvf_type; /* represents the source of the message on recv */
  34. #define IDPF_VMVF_TYPE_VF 0
  35. #define IDPF_VMVF_TYPE_VM 1
  36. #define IDPF_VMVF_TYPE_PF 2
  37. u8 host_id;
  38. /* 3b field used only when sending a message to CP - to be used in
  39. * combination with target func_id to route the message
  40. */
  41. #define IDPF_HOST_ID_MASK 0x7
  42. u16 opcode;
  43. u16 data_len; /* data_len = 0 when no payload is attached */
  44. union {
  45. u16 func_id; /* when sending a message */
  46. u16 status; /* when receiving a message */
  47. };
  48. union {
  49. struct {
  50. u32 chnl_opcode;
  51. u32 chnl_retval;
  52. } mbx;
  53. } cookie;
  54. union {
  55. #define IDPF_DIRECT_CTX_SIZE 16
  56. #define IDPF_INDIRECT_CTX_SIZE 8
  57. /* 16 bytes of context can be provided or 8 bytes of context
  58. * plus the address of a DMA buffer
  59. */
  60. u8 direct[IDPF_DIRECT_CTX_SIZE];
  61. struct {
  62. u8 context[IDPF_INDIRECT_CTX_SIZE];
  63. struct idpf_dma_mem *payload;
  64. } indirect;
  65. struct {
  66. u32 rsvd;
  67. u16 data;
  68. u16 flags;
  69. } sw_cookie;
  70. } ctx;
  71. };
  72. /* Generic queue info structures */
  73. /* MB, CONFIG and EVENT q do not have extended info */
  74. struct idpf_ctlq_create_info {
  75. enum idpf_ctlq_type type;
  76. int id; /* absolute queue offset passed as input
  77. * -1 for default mailbox if present
  78. */
  79. u16 len; /* Queue length passed as input */
  80. u16 buf_size; /* buffer size passed as input */
  81. u64 base_address; /* output, HPA of the Queue start */
  82. struct idpf_ctlq_reg reg; /* registers accessed by ctlqs */
  83. int ext_info_size;
  84. void *ext_info; /* Specific to q type */
  85. };
  86. /* Control Queue information */
  87. struct idpf_ctlq_info {
  88. struct list_head cq_list;
  89. enum idpf_ctlq_type cq_type;
  90. int q_id;
  91. spinlock_t cq_lock; /* control queue lock */
  92. /* used for interrupt processing */
  93. u16 next_to_use;
  94. u16 next_to_clean;
  95. u16 next_to_post; /* starting descriptor to post buffers
  96. * to after recev
  97. */
  98. struct idpf_dma_mem desc_ring; /* descriptor ring memory
  99. * idpf_dma_mem is defined in OSdep.h
  100. */
  101. union {
  102. struct idpf_dma_mem **rx_buff;
  103. struct idpf_ctlq_msg **tx_msg;
  104. } bi;
  105. u16 buf_size; /* queue buffer size */
  106. u16 ring_size; /* Number of descriptors */
  107. struct idpf_ctlq_reg reg; /* registers accessed by ctlqs */
  108. };
  109. /**
  110. * enum idpf_mbx_opc - PF/VF mailbox commands
  111. * @idpf_mbq_opc_send_msg_to_cp: used by PF or VF to send a message to its CP
  112. */
  113. enum idpf_mbx_opc {
  114. idpf_mbq_opc_send_msg_to_cp = 0x0801,
  115. };
  116. /* API supported for control queue management */
  117. /* Will init all required q including default mb. "q_info" is an array of
  118. * create_info structs equal to the number of control queues to be created.
  119. */
  120. int idpf_ctlq_init(struct idpf_hw *hw, u8 num_q,
  121. struct idpf_ctlq_create_info *q_info);
  122. /* Allocate and initialize a single control queue, which will be added to the
  123. * control queue list; returns a handle to the created control queue
  124. */
  125. int idpf_ctlq_add(struct idpf_hw *hw,
  126. struct idpf_ctlq_create_info *qinfo,
  127. struct idpf_ctlq_info **cq);
  128. /* Deinitialize and deallocate a single control queue */
  129. void idpf_ctlq_remove(struct idpf_hw *hw,
  130. struct idpf_ctlq_info *cq);
  131. /* Sends messages to HW and will also free the buffer*/
  132. int idpf_ctlq_send(struct idpf_hw *hw,
  133. struct idpf_ctlq_info *cq,
  134. u16 num_q_msg,
  135. struct idpf_ctlq_msg q_msg[]);
  136. /* Receives messages and called by interrupt handler/polling
  137. * initiated by app/process. Also caller is supposed to free the buffers
  138. */
  139. int idpf_ctlq_recv(struct idpf_ctlq_info *cq, u16 *num_q_msg,
  140. struct idpf_ctlq_msg *q_msg);
  141. /* Reclaims send descriptors on HW write back */
  142. int idpf_ctlq_clean_sq(struct idpf_ctlq_info *cq, u16 *clean_count,
  143. struct idpf_ctlq_msg *msg_status[]);
  144. /* Indicate RX buffers are done being processed */
  145. int idpf_ctlq_post_rx_buffs(struct idpf_hw *hw,
  146. struct idpf_ctlq_info *cq,
  147. u16 *buff_count,
  148. struct idpf_dma_mem **buffs);
  149. /* Will destroy all q including the default mb */
  150. void idpf_ctlq_deinit(struct idpf_hw *hw);
  151. #endif /* _IDPF_CONTROLQ_API_H_ */