ice_txrx_lib.h 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  1. /* SPDX-License-Identifier: GPL-2.0 */
  2. /* Copyright (c) 2019, Intel Corporation. */
  3. #ifndef _ICE_TXRX_LIB_H_
  4. #define _ICE_TXRX_LIB_H_
  5. #include "ice.h"
  6. /**
  7. * ice_test_staterr - tests bits in Rx descriptor status and error fields
  8. * @status_err_n: Rx descriptor status_error0 or status_error1 bits
  9. * @stat_err_bits: value to mask
  10. *
  11. * This function does some fast chicanery in order to return the
  12. * value of the mask which is really only used for boolean tests.
  13. * The status_error_len doesn't need to be shifted because it begins
  14. * at offset zero.
  15. */
  16. static inline bool
  17. ice_test_staterr(__le16 status_err_n, const u16 stat_err_bits)
  18. {
  19. return !!(status_err_n & cpu_to_le16(stat_err_bits));
  20. }
  21. /**
  22. * ice_is_non_eop - process handling of non-EOP buffers
  23. * @rx_ring: Rx ring being processed
  24. * @rx_desc: Rx descriptor for current buffer
  25. *
  26. * If the buffer is an EOP buffer, this function exits returning false,
  27. * otherwise return true indicating that this is in fact a non-EOP buffer.
  28. */
  29. static inline bool
  30. ice_is_non_eop(const struct ice_rx_ring *rx_ring,
  31. const union ice_32b_rx_flex_desc *rx_desc)
  32. {
  33. /* if we are the last buffer then there is nothing else to do */
  34. #define ICE_RXD_EOF BIT(ICE_RX_FLEX_DESC_STATUS0_EOF_S)
  35. if (likely(ice_test_staterr(rx_desc->wb.status_error0, ICE_RXD_EOF)))
  36. return false;
  37. rx_ring->ring_stats->rx_stats.non_eop_descs++;
  38. return true;
  39. }
  40. static inline __le64
  41. ice_build_ctob(u64 td_cmd, u64 td_offset, unsigned int size, u64 td_tag)
  42. {
  43. return cpu_to_le64(ICE_TX_DESC_DTYPE_DATA |
  44. (td_cmd << ICE_TXD_QW1_CMD_S) |
  45. (td_offset << ICE_TXD_QW1_OFFSET_S) |
  46. ((u64)size << ICE_TXD_QW1_TX_BUF_SZ_S) |
  47. (td_tag << ICE_TXD_QW1_L2TAG1_S));
  48. }
  49. /**
  50. * ice_get_vlan_tci - get VLAN TCI from Rx flex descriptor
  51. * @rx_desc: Rx 32b flex descriptor with RXDID=2
  52. *
  53. * The OS and current PF implementation only support stripping a single VLAN tag
  54. * at a time, so there should only ever be 0 or 1 tags in the l2tag* fields. If
  55. * one is found return the tag, else return 0 to mean no VLAN tag was found.
  56. */
  57. static inline u16
  58. ice_get_vlan_tci(const union ice_32b_rx_flex_desc *rx_desc)
  59. {
  60. u16 stat_err_bits;
  61. stat_err_bits = BIT(ICE_RX_FLEX_DESC_STATUS0_L2TAG1P_S);
  62. if (ice_test_staterr(rx_desc->wb.status_error0, stat_err_bits))
  63. return le16_to_cpu(rx_desc->wb.l2tag1);
  64. stat_err_bits = BIT(ICE_RX_FLEX_DESC_STATUS1_L2TAG2P_S);
  65. if (ice_test_staterr(rx_desc->wb.status_error1, stat_err_bits))
  66. return le16_to_cpu(rx_desc->wb.l2tag2_2nd);
  67. return 0;
  68. }
  69. /**
  70. * ice_xdp_ring_update_tail - Updates the XDP Tx ring tail register
  71. * @xdp_ring: XDP Tx ring
  72. *
  73. * This function updates the XDP Tx ring tail register.
  74. */
  75. static inline void ice_xdp_ring_update_tail(struct ice_tx_ring *xdp_ring)
  76. {
  77. /* Force memory writes to complete before letting h/w
  78. * know there are new descriptors to fetch.
  79. */
  80. wmb();
  81. writel_relaxed(xdp_ring->next_to_use, xdp_ring->tail);
  82. }
  83. /**
  84. * ice_set_rs_bit - set RS bit on last produced descriptor (one behind current NTU)
  85. * @xdp_ring: XDP ring to produce the HW Tx descriptors on
  86. *
  87. * returns index of descriptor that had RS bit produced on
  88. */
  89. static inline u32 ice_set_rs_bit(const struct ice_tx_ring *xdp_ring)
  90. {
  91. u32 rs_idx = xdp_ring->next_to_use ? xdp_ring->next_to_use - 1 : xdp_ring->count - 1;
  92. struct ice_tx_desc *tx_desc;
  93. tx_desc = ICE_TX_DESC(xdp_ring, rs_idx);
  94. tx_desc->cmd_type_offset_bsz |=
  95. cpu_to_le64(ICE_TX_DESC_CMD_RS << ICE_TXD_QW1_CMD_S);
  96. return rs_idx;
  97. }
  98. void ice_finalize_xdp_rx(struct ice_tx_ring *xdp_ring, unsigned int xdp_res, u32 first_idx);
  99. int ice_xmit_xdp_buff(struct xdp_buff *xdp, struct ice_tx_ring *xdp_ring);
  100. int __ice_xmit_xdp_ring(struct xdp_buff *xdp, struct ice_tx_ring *xdp_ring,
  101. bool frame);
  102. void ice_release_rx_desc(struct ice_rx_ring *rx_ring, u16 val);
  103. void
  104. ice_process_skb_fields(struct ice_rx_ring *rx_ring,
  105. union ice_32b_rx_flex_desc *rx_desc,
  106. struct sk_buff *skb);
  107. void
  108. ice_receive_skb(struct ice_rx_ring *rx_ring, struct sk_buff *skb, u16 vlan_tci);
  109. static inline void
  110. ice_xdp_meta_set_desc(struct xdp_buff *xdp,
  111. union ice_32b_rx_flex_desc *eop_desc)
  112. {
  113. struct ice_xdp_buff *xdp_ext = container_of(xdp, struct ice_xdp_buff,
  114. xdp_buff);
  115. xdp_ext->eop_desc = eop_desc;
  116. }
  117. #endif /* !_ICE_TXRX_LIB_H_ */