hw_channel.h 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211
  1. /* SPDX-License-Identifier: GPL-2.0 OR BSD-3-Clause */
  2. /* Copyright (c) 2021, Microsoft Corporation. */
  3. #ifndef _HW_CHANNEL_H
  4. #define _HW_CHANNEL_H
  5. #define DEFAULT_LOG2_THROTTLING_FOR_ERROR_EQ 4
  6. #define HW_CHANNEL_MAX_REQUEST_SIZE 0x1000
  7. #define HW_CHANNEL_MAX_RESPONSE_SIZE 0x1000
  8. #define HW_CHANNEL_VF_BOOTSTRAP_QUEUE_DEPTH 1
  9. #define HWC_INIT_DATA_CQID 1
  10. #define HWC_INIT_DATA_RQID 2
  11. #define HWC_INIT_DATA_SQID 3
  12. #define HWC_INIT_DATA_QUEUE_DEPTH 4
  13. #define HWC_INIT_DATA_MAX_REQUEST 5
  14. #define HWC_INIT_DATA_MAX_RESPONSE 6
  15. #define HWC_INIT_DATA_MAX_NUM_CQS 7
  16. #define HWC_INIT_DATA_PDID 8
  17. #define HWC_INIT_DATA_GPA_MKEY 9
  18. #define HWC_INIT_DATA_PF_DEST_RQ_ID 10
  19. #define HWC_INIT_DATA_PF_DEST_CQ_ID 11
  20. #define HWC_DATA_CFG_HWC_TIMEOUT 1
  21. #define HWC_DATA_HW_LINK_CONNECT 2
  22. #define HWC_DATA_HW_LINK_DISCONNECT 3
  23. #define HW_CHANNEL_WAIT_RESOURCE_TIMEOUT_MS 30000
  24. /* Structures labeled with "HW DATA" are exchanged with the hardware. All of
  25. * them are naturally aligned and hence don't need __packed.
  26. */
  27. union hwc_init_eq_id_db {
  28. u32 as_uint32;
  29. struct {
  30. u32 eq_id : 16;
  31. u32 doorbell : 16;
  32. };
  33. }; /* HW DATA */
  34. union hwc_init_type_data {
  35. u32 as_uint32;
  36. struct {
  37. u32 value : 24;
  38. u32 type : 8;
  39. };
  40. }; /* HW DATA */
  41. union hwc_init_soc_service_type {
  42. u32 as_uint32;
  43. struct {
  44. u32 value : 28;
  45. u32 type : 4;
  46. };
  47. }; /* HW DATA */
  48. struct hwc_rx_oob {
  49. u32 type : 6;
  50. u32 eom : 1;
  51. u32 som : 1;
  52. u32 vendor_err : 8;
  53. u32 reserved1 : 16;
  54. u32 src_virt_wq : 24;
  55. u32 src_vfid : 8;
  56. u32 reserved2;
  57. union {
  58. u32 wqe_addr_low;
  59. u32 wqe_offset;
  60. };
  61. u32 wqe_addr_high;
  62. u32 client_data_unit : 14;
  63. u32 reserved3 : 18;
  64. u32 tx_oob_data_size;
  65. u32 chunk_offset : 21;
  66. u32 reserved4 : 11;
  67. }; /* HW DATA */
  68. struct hwc_tx_oob {
  69. u32 reserved1;
  70. u32 reserved2;
  71. u32 vrq_id : 24;
  72. u32 dest_vfid : 8;
  73. u32 vrcq_id : 24;
  74. u32 reserved3 : 8;
  75. u32 vscq_id : 24;
  76. u32 loopback : 1;
  77. u32 lso_override: 1;
  78. u32 dest_pf : 1;
  79. u32 reserved4 : 5;
  80. u32 vsq_id : 24;
  81. u32 reserved5 : 8;
  82. }; /* HW DATA */
  83. struct hwc_work_request {
  84. void *buf_va;
  85. void *buf_sge_addr;
  86. u32 buf_len;
  87. u32 msg_size;
  88. struct gdma_wqe_request wqe_req;
  89. struct hwc_tx_oob tx_oob;
  90. struct gdma_sge sge;
  91. };
  92. /* hwc_dma_buf represents the array of in-flight WQEs.
  93. * mem_info as know as the GDMA mapped memory is partitioned and used by
  94. * in-flight WQEs.
  95. * The number of WQEs is determined by the number of in-flight messages.
  96. */
  97. struct hwc_dma_buf {
  98. struct gdma_mem_info mem_info;
  99. u32 gpa_mkey;
  100. u32 num_reqs;
  101. struct hwc_work_request reqs[] __counted_by(num_reqs);
  102. };
  103. typedef void hwc_rx_event_handler_t(void *ctx, u32 gdma_rxq_id,
  104. const struct hwc_rx_oob *rx_oob);
  105. typedef void hwc_tx_event_handler_t(void *ctx, u32 gdma_txq_id,
  106. const struct hwc_rx_oob *rx_oob);
  107. struct hwc_cq {
  108. struct hw_channel_context *hwc;
  109. struct gdma_queue *gdma_cq;
  110. struct gdma_queue *gdma_eq;
  111. struct gdma_comp *comp_buf;
  112. u16 queue_depth;
  113. hwc_rx_event_handler_t *rx_event_handler;
  114. void *rx_event_ctx;
  115. hwc_tx_event_handler_t *tx_event_handler;
  116. void *tx_event_ctx;
  117. };
  118. struct hwc_wq {
  119. struct hw_channel_context *hwc;
  120. struct gdma_queue *gdma_wq;
  121. struct hwc_dma_buf *msg_buf;
  122. u16 queue_depth;
  123. struct hwc_cq *hwc_cq;
  124. };
  125. struct hwc_caller_ctx {
  126. struct completion comp_event;
  127. void *output_buf;
  128. u32 output_buflen;
  129. u32 error; /* Linux error code */
  130. u32 status_code;
  131. };
  132. struct hw_channel_context {
  133. struct gdma_dev *gdma_dev;
  134. struct device *dev;
  135. u16 num_inflight_msg;
  136. u32 max_req_msg_size;
  137. u16 hwc_init_q_depth_max;
  138. u32 hwc_init_max_req_msg_size;
  139. u32 hwc_init_max_resp_msg_size;
  140. struct completion hwc_init_eqe_comp;
  141. struct hwc_wq *rxq;
  142. struct hwc_wq *txq;
  143. struct hwc_cq *cq;
  144. struct semaphore sema;
  145. struct gdma_resource inflight_msg_res;
  146. u32 pf_dest_vrq_id;
  147. u32 pf_dest_vrcq_id;
  148. u32 hwc_timeout;
  149. struct hwc_caller_ctx *caller_ctx;
  150. };
  151. int mana_hwc_create_channel(struct gdma_context *gc);
  152. void mana_hwc_destroy_channel(struct gdma_context *gc);
  153. int mana_hwc_send_request(struct hw_channel_context *hwc, u32 req_len,
  154. const void *req, u32 resp_len, void *resp);
  155. #endif /* _HW_CHANNEL_H */