hw_channel.h 3.8 KB

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