1 /* SPDX-License-Identifier: GPL-2.0 */
2 /* Copyright (c) 2019, Intel Corporation. */
4 #ifndef _ICE_TXRX_LIB_H_
5 #define _ICE_TXRX_LIB_H_
9 * ice_set_rx_bufs_act - propagate Rx buffer action to frags
10 * @xdp: XDP buffer representing frame (linear and frags part)
11 * @rx_ring: Rx ring struct
12 * act: action to store onto Rx buffers related to XDP buffer parts
14 * Set action that should be taken before putting Rx buffer from first frag
18 ice_set_rx_bufs_act(struct xdp_buff *xdp, const struct ice_rx_ring *rx_ring,
19 const unsigned int act)
21 u32 sinfo_frags = xdp_get_shared_info_from_buff(xdp)->nr_frags;
22 u32 nr_frags = rx_ring->nr_frags + 1;
23 u32 idx = rx_ring->first_desc;
24 u32 cnt = rx_ring->count;
25 struct ice_rx_buf *buf;
27 for (int i = 0; i < nr_frags; i++) {
28 buf = &rx_ring->rx_buf[idx];
35 /* adjust pagecnt_bias on frags freed by XDP prog */
36 if (sinfo_frags < rx_ring->nr_frags && act == ICE_XDP_CONSUMED) {
37 u32 delta = rx_ring->nr_frags - sinfo_frags;
44 buf = &rx_ring->rx_buf[idx];
52 * ice_test_staterr - tests bits in Rx descriptor status and error fields
53 * @status_err_n: Rx descriptor status_error0 or status_error1 bits
54 * @stat_err_bits: value to mask
56 * This function does some fast chicanery in order to return the
57 * value of the mask which is really only used for boolean tests.
58 * The status_error_len doesn't need to be shifted because it begins
62 ice_test_staterr(__le16 status_err_n, const u16 stat_err_bits)
64 return !!(status_err_n & cpu_to_le16(stat_err_bits));
68 * ice_is_non_eop - process handling of non-EOP buffers
69 * @rx_ring: Rx ring being processed
70 * @rx_desc: Rx descriptor for current buffer
72 * If the buffer is an EOP buffer, this function exits returning false,
73 * otherwise return true indicating that this is in fact a non-EOP buffer.
76 ice_is_non_eop(const struct ice_rx_ring *rx_ring,
77 const union ice_32b_rx_flex_desc *rx_desc)
79 /* if we are the last buffer then there is nothing else to do */
80 #define ICE_RXD_EOF BIT(ICE_RX_FLEX_DESC_STATUS0_EOF_S)
81 if (likely(ice_test_staterr(rx_desc->wb.status_error0, ICE_RXD_EOF)))
84 rx_ring->ring_stats->rx_stats.non_eop_descs++;
90 ice_build_ctob(u64 td_cmd, u64 td_offset, unsigned int size, u64 td_tag)
92 return cpu_to_le64(ICE_TX_DESC_DTYPE_DATA |
93 (td_cmd << ICE_TXD_QW1_CMD_S) |
94 (td_offset << ICE_TXD_QW1_OFFSET_S) |
95 ((u64)size << ICE_TXD_QW1_TX_BUF_SZ_S) |
96 (td_tag << ICE_TXD_QW1_L2TAG1_S));
100 * ice_get_vlan_tci - get VLAN TCI from Rx flex descriptor
101 * @rx_desc: Rx 32b flex descriptor with RXDID=2
103 * The OS and current PF implementation only support stripping a single VLAN tag
104 * at a time, so there should only ever be 0 or 1 tags in the l2tag* fields. If
105 * one is found return the tag, else return 0 to mean no VLAN tag was found.
108 ice_get_vlan_tci(const union ice_32b_rx_flex_desc *rx_desc)
112 stat_err_bits = BIT(ICE_RX_FLEX_DESC_STATUS0_L2TAG1P_S);
113 if (ice_test_staterr(rx_desc->wb.status_error0, stat_err_bits))
114 return le16_to_cpu(rx_desc->wb.l2tag1);
116 stat_err_bits = BIT(ICE_RX_FLEX_DESC_STATUS1_L2TAG2P_S);
117 if (ice_test_staterr(rx_desc->wb.status_error1, stat_err_bits))
118 return le16_to_cpu(rx_desc->wb.l2tag2_2nd);
124 * ice_xdp_ring_update_tail - Updates the XDP Tx ring tail register
125 * @xdp_ring: XDP Tx ring
127 * This function updates the XDP Tx ring tail register.
129 static inline void ice_xdp_ring_update_tail(struct ice_tx_ring *xdp_ring)
131 /* Force memory writes to complete before letting h/w
132 * know there are new descriptors to fetch.
135 writel_relaxed(xdp_ring->next_to_use, xdp_ring->tail);
139 * ice_set_rs_bit - set RS bit on last produced descriptor (one behind current NTU)
140 * @xdp_ring: XDP ring to produce the HW Tx descriptors on
142 * returns index of descriptor that had RS bit produced on
144 static inline u32 ice_set_rs_bit(const struct ice_tx_ring *xdp_ring)
146 u32 rs_idx = xdp_ring->next_to_use ? xdp_ring->next_to_use - 1 : xdp_ring->count - 1;
147 struct ice_tx_desc *tx_desc;
149 tx_desc = ICE_TX_DESC(xdp_ring, rs_idx);
150 tx_desc->cmd_type_offset_bsz |=
151 cpu_to_le64(ICE_TX_DESC_CMD_RS << ICE_TXD_QW1_CMD_S);
156 void ice_finalize_xdp_rx(struct ice_tx_ring *xdp_ring, unsigned int xdp_res, u32 first_idx);
157 int ice_xmit_xdp_buff(struct xdp_buff *xdp, struct ice_tx_ring *xdp_ring);
158 int __ice_xmit_xdp_ring(struct xdp_buff *xdp, struct ice_tx_ring *xdp_ring,
160 void ice_release_rx_desc(struct ice_rx_ring *rx_ring, u16 val);
162 ice_process_skb_fields(struct ice_rx_ring *rx_ring,
163 union ice_32b_rx_flex_desc *rx_desc,
164 struct sk_buff *skb);
166 ice_receive_skb(struct ice_rx_ring *rx_ring, struct sk_buff *skb, u16 vlan_tci);
169 ice_xdp_meta_set_desc(struct xdp_buff *xdp,
170 union ice_32b_rx_flex_desc *eop_desc)
172 struct ice_xdp_buff *xdp_ext = container_of(xdp, struct ice_xdp_buff,
175 xdp_ext->eop_desc = eop_desc;
177 #endif /* !_ICE_TXRX_LIB_H_ */