ena_eth_com.h 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161
  1. /*
  2. * Copyright 2015 Amazon.com, Inc. or its affiliates.
  3. *
  4. * This software is available to you under a choice of one of two
  5. * licenses. You may choose to be licensed under the terms of the GNU
  6. * General Public License (GPL) Version 2, available from the file
  7. * COPYING in the main directory of this source tree, or the
  8. * BSD license below:
  9. *
  10. * Redistribution and use in source and binary forms, with or
  11. * without modification, are permitted provided that the following
  12. * conditions are met:
  13. *
  14. * - Redistributions of source code must retain the above
  15. * copyright notice, this list of conditions and the following
  16. * disclaimer.
  17. *
  18. * - Redistributions in binary form must reproduce the above
  19. * copyright notice, this list of conditions and the following
  20. * disclaimer in the documentation and/or other materials
  21. * provided with the distribution.
  22. *
  23. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  24. * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  25. * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  26. * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
  27. * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
  28. * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
  29. * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
  30. * SOFTWARE.
  31. */
  32. #ifndef ENA_ETH_COM_H_
  33. #define ENA_ETH_COM_H_
  34. #include "ena_com.h"
  35. /* head update threshold in units of (queue size / ENA_COMP_HEAD_THRESH) */
  36. #define ENA_COMP_HEAD_THRESH 4
  37. struct ena_com_tx_ctx {
  38. struct ena_com_tx_meta ena_meta;
  39. struct ena_com_buf *ena_bufs;
  40. /* For LLQ, header buffer - pushed to the device mem space */
  41. void *push_header;
  42. enum ena_eth_io_l3_proto_index l3_proto;
  43. enum ena_eth_io_l4_proto_index l4_proto;
  44. u16 num_bufs;
  45. u16 req_id;
  46. /* For regular queue, indicate the size of the header
  47. * For LLQ, indicate the size of the pushed buffer
  48. */
  49. u16 header_len;
  50. u8 meta_valid;
  51. u8 tso_enable;
  52. u8 l3_csum_enable;
  53. u8 l4_csum_enable;
  54. u8 l4_csum_partial;
  55. u8 df; /* Don't fragment */
  56. };
  57. struct ena_com_rx_ctx {
  58. struct ena_com_rx_buf_info *ena_bufs;
  59. enum ena_eth_io_l3_proto_index l3_proto;
  60. enum ena_eth_io_l4_proto_index l4_proto;
  61. bool l3_csum_err;
  62. bool l4_csum_err;
  63. /* fragmented packet */
  64. bool frag;
  65. u32 hash;
  66. u16 descs;
  67. int max_bufs;
  68. };
  69. int ena_com_prepare_tx(struct ena_com_io_sq *io_sq,
  70. struct ena_com_tx_ctx *ena_tx_ctx,
  71. int *nb_hw_desc);
  72. int ena_com_rx_pkt(struct ena_com_io_cq *io_cq,
  73. struct ena_com_io_sq *io_sq,
  74. struct ena_com_rx_ctx *ena_rx_ctx);
  75. int ena_com_add_single_rx_desc(struct ena_com_io_sq *io_sq,
  76. struct ena_com_buf *ena_buf,
  77. u16 req_id);
  78. int ena_com_tx_comp_req_id_get(struct ena_com_io_cq *io_cq, u16 *req_id);
  79. static inline void ena_com_unmask_intr(struct ena_com_io_cq *io_cq,
  80. struct ena_eth_io_intr_reg *intr_reg)
  81. {
  82. writel(intr_reg->intr_control, io_cq->unmask_reg);
  83. }
  84. static inline int ena_com_sq_empty_space(struct ena_com_io_sq *io_sq)
  85. {
  86. u16 tail, next_to_comp, cnt;
  87. next_to_comp = io_sq->next_to_comp;
  88. tail = io_sq->tail;
  89. cnt = tail - next_to_comp;
  90. return io_sq->q_depth - 1 - cnt;
  91. }
  92. static inline int ena_com_write_sq_doorbell(struct ena_com_io_sq *io_sq)
  93. {
  94. u16 tail;
  95. tail = io_sq->tail;
  96. pr_debug("write submission queue doorbell for queue: %d tail: %d\n",
  97. io_sq->qid, tail);
  98. writel(tail, io_sq->db_addr);
  99. return 0;
  100. }
  101. static inline int ena_com_update_dev_comp_head(struct ena_com_io_cq *io_cq)
  102. {
  103. u16 unreported_comp, head;
  104. bool need_update;
  105. head = io_cq->head;
  106. unreported_comp = head - io_cq->last_head_update;
  107. need_update = unreported_comp > (io_cq->q_depth / ENA_COMP_HEAD_THRESH);
  108. if (io_cq->cq_head_db_reg && need_update) {
  109. pr_debug("Write completion queue doorbell for queue %d: head: %d\n",
  110. io_cq->qid, head);
  111. writel(head, io_cq->cq_head_db_reg);
  112. io_cq->last_head_update = head;
  113. }
  114. return 0;
  115. }
  116. static inline void ena_com_update_numa_node(struct ena_com_io_cq *io_cq,
  117. u8 numa_node)
  118. {
  119. struct ena_eth_io_numa_node_cfg_reg numa_cfg;
  120. if (!io_cq->numa_node_cfg_reg)
  121. return;
  122. numa_cfg.numa_cfg = (numa_node & ENA_ETH_IO_NUMA_NODE_CFG_REG_NUMA_MASK)
  123. | ENA_ETH_IO_NUMA_NODE_CFG_REG_ENABLED_MASK;
  124. writel(numa_cfg.numa_cfg, io_cq->numa_node_cfg_reg);
  125. }
  126. static inline void ena_com_comp_ack(struct ena_com_io_sq *io_sq, u16 elem)
  127. {
  128. io_sq->next_to_comp += elem;
  129. }
  130. #endif /* ENA_ETH_COM_H_ */