xref: /linux/drivers/net/ethernet/intel/ice/ice_txrx_lib.h (revision 24bce201d79807b668bf9d9e0aca801c5c0d5f78)
1 /* SPDX-License-Identifier: GPL-2.0 */
2 /* Copyright (c) 2019, Intel Corporation. */
3 
4 #ifndef _ICE_TXRX_LIB_H_
5 #define _ICE_TXRX_LIB_H_
6 #include "ice.h"
7 
8 /**
9  * ice_test_staterr - tests bits in Rx descriptor status and error fields
10  * @status_err_n: Rx descriptor status_error0 or status_error1 bits
11  * @stat_err_bits: value to mask
12  *
13  * This function does some fast chicanery in order to return the
14  * value of the mask which is really only used for boolean tests.
15  * The status_error_len doesn't need to be shifted because it begins
16  * at offset zero.
17  */
18 static inline bool
19 ice_test_staterr(__le16 status_err_n, const u16 stat_err_bits)
20 {
21 	return !!(status_err_n & cpu_to_le16(stat_err_bits));
22 }
23 
24 static inline __le64
25 ice_build_ctob(u64 td_cmd, u64 td_offset, unsigned int size, u64 td_tag)
26 {
27 	return cpu_to_le64(ICE_TX_DESC_DTYPE_DATA |
28 			   (td_cmd    << ICE_TXD_QW1_CMD_S) |
29 			   (td_offset << ICE_TXD_QW1_OFFSET_S) |
30 			   ((u64)size << ICE_TXD_QW1_TX_BUF_SZ_S) |
31 			   (td_tag    << ICE_TXD_QW1_L2TAG1_S));
32 }
33 
34 /**
35  * ice_get_vlan_tag_from_rx_desc - get VLAN from Rx flex descriptor
36  * @rx_desc: Rx 32b flex descriptor with RXDID=2
37  *
38  * The OS and current PF implementation only support stripping a single VLAN tag
39  * at a time, so there should only ever be 0 or 1 tags in the l2tag* fields. If
40  * one is found return the tag, else return 0 to mean no VLAN tag was found.
41  */
42 static inline u16
43 ice_get_vlan_tag_from_rx_desc(union ice_32b_rx_flex_desc *rx_desc)
44 {
45 	u16 stat_err_bits;
46 
47 	stat_err_bits = BIT(ICE_RX_FLEX_DESC_STATUS0_L2TAG1P_S);
48 	if (ice_test_staterr(rx_desc->wb.status_error0, stat_err_bits))
49 		return le16_to_cpu(rx_desc->wb.l2tag1);
50 
51 	stat_err_bits = BIT(ICE_RX_FLEX_DESC_STATUS1_L2TAG2P_S);
52 	if (ice_test_staterr(rx_desc->wb.status_error1, stat_err_bits))
53 		return le16_to_cpu(rx_desc->wb.l2tag2_2nd);
54 
55 	return 0;
56 }
57 
58 /**
59  * ice_xdp_ring_update_tail - Updates the XDP Tx ring tail register
60  * @xdp_ring: XDP Tx ring
61  *
62  * This function updates the XDP Tx ring tail register.
63  */
64 static inline void ice_xdp_ring_update_tail(struct ice_tx_ring *xdp_ring)
65 {
66 	/* Force memory writes to complete before letting h/w
67 	 * know there are new descriptors to fetch.
68 	 */
69 	wmb();
70 	writel_relaxed(xdp_ring->next_to_use, xdp_ring->tail);
71 }
72 
73 void ice_finalize_xdp_rx(struct ice_tx_ring *xdp_ring, unsigned int xdp_res);
74 int ice_xmit_xdp_buff(struct xdp_buff *xdp, struct ice_tx_ring *xdp_ring);
75 int ice_xmit_xdp_ring(void *data, u16 size, struct ice_tx_ring *xdp_ring);
76 void ice_release_rx_desc(struct ice_rx_ring *rx_ring, u16 val);
77 void
78 ice_process_skb_fields(struct ice_rx_ring *rx_ring,
79 		       union ice_32b_rx_flex_desc *rx_desc,
80 		       struct sk_buff *skb, u16 ptype);
81 void
82 ice_receive_skb(struct ice_rx_ring *rx_ring, struct sk_buff *skb, u16 vlan_tag);
83 #endif /* !_ICE_TXRX_LIB_H_ */
84