New upstream version 18.08
[deb_dpdk.git] / drivers / net / bnxt / bnxt_rxr.h
1 /* SPDX-License-Identifier: BSD-3-Clause
2  * Copyright(c) 2014-2018 Broadcom
3  * All rights reserved.
4  */
5
6 #ifndef _BNXT_RXR_H_
7 #define _BNXT_RXR_H_
8
9 #define B_RX_DB(db, prod)                                               \
10                 (*(uint32_t *)db = (DB_KEY_RX | prod))
11
12 #define BNXT_TPA_L4_SIZE(x)     \
13         { \
14                 typeof(x) hdr_info = (x); \
15                 (((hdr_info) & 0xf8000000) ? ((hdr_info) >> 27) : 32) \
16         }
17
18 #define BNXT_TPA_INNER_L3_OFF(hdr_info) \
19         (((hdr_info) >> 18) & 0x1ff)
20
21 #define BNXT_TPA_INNER_L2_OFF(hdr_info) \
22         (((hdr_info) >> 9) & 0x1ff)
23
24 #define BNXT_TPA_OUTER_L3_OFF(hdr_info) \
25         ((hdr_info) & 0x1ff)
26
27 #define RX_CMP_L4_CS_BITS       \
28         rte_cpu_to_le_32(RX_PKT_CMPL_FLAGS2_L4_CS_CALC | \
29                          RX_PKT_CMPL_FLAGS2_T_L4_CS_CALC)
30
31 #define RX_CMP_L4_CS_ERR_BITS   \
32         rte_cpu_to_le_32(RX_PKT_CMPL_ERRORS_L4_CS_ERROR | \
33                          RX_PKT_CMPL_ERRORS_T_L4_CS_ERROR)
34
35 #define RX_CMP_L4_CS_OK(rxcmp1)                                         \
36             (((rxcmp1)->flags2 & RX_CMP_L4_CS_BITS) &&          \
37              !((rxcmp1)->errors_v2 & RX_CMP_L4_CS_ERR_BITS))
38
39 #define RX_CMP_L4_CS_UNKNOWN(rxcmp1)                                    \
40             !((rxcmp1)->flags2 & RX_CMP_L4_CS_BITS)
41
42 #define RX_CMP_IP_CS_ERR_BITS   \
43         rte_cpu_to_le_32(RX_PKT_CMPL_ERRORS_IP_CS_ERROR | \
44                          RX_PKT_CMPL_ERRORS_T_IP_CS_ERROR)
45
46 #define RX_CMP_IP_CS_BITS       \
47         rte_cpu_to_le_32(RX_PKT_CMPL_FLAGS2_IP_CS_CALC | \
48                          RX_PKT_CMPL_FLAGS2_T_IP_CS_CALC)
49
50 #define RX_CMP_IP_CS_OK(rxcmp1)                                         \
51                 (((rxcmp1)->flags2 & RX_CMP_IP_CS_BITS) &&      \
52                 !((rxcmp1)->errors_v2 & RX_CMP_IP_CS_ERR_BITS))
53
54 #define RX_CMP_IP_CS_UNKNOWN(rxcmp1)                                    \
55                 !((rxcmp1)->flags2 & RX_CMP_IP_CS_BITS)
56
57 #define BNXT_RX_POST_THRESH     32
58
59 enum pkt_hash_types {
60         PKT_HASH_TYPE_NONE,     /* Undefined type */
61         PKT_HASH_TYPE_L2,       /* Input: src_MAC, dest_MAC */
62         PKT_HASH_TYPE_L3,       /* Input: src_IP, dst_IP */
63         PKT_HASH_TYPE_L4,       /* Input: src_IP, dst_IP, src_port, dst_port */
64 };
65
66 struct bnxt_tpa_info {
67         struct rte_mbuf         *mbuf;
68         uint16_t                        len;
69         unsigned short          gso_type;
70         uint32_t                        flags2;
71         uint32_t                        metadata;
72         enum pkt_hash_types     hash_type;
73         uint32_t                        rss_hash;
74         uint32_t                        hdr_info;
75 };
76
77 struct bnxt_sw_rx_bd {
78         struct rte_mbuf         *mbuf; /* data associated with RX descriptor */
79 };
80
81 struct bnxt_rx_ring_info {
82         uint16_t                rx_prod;
83         uint16_t                ag_prod;
84         void                    *rx_doorbell;
85         void                    *ag_doorbell;
86
87         struct rx_prod_pkt_bd   *rx_desc_ring;
88         struct rx_prod_pkt_bd   *ag_desc_ring;
89         struct bnxt_sw_rx_bd    *rx_buf_ring; /* sw ring */
90         struct bnxt_sw_rx_bd    *ag_buf_ring; /* sw ring */
91
92         rte_iova_t              rx_desc_mapping;
93         rte_iova_t              ag_desc_mapping;
94
95         struct bnxt_ring        *rx_ring_struct;
96         struct bnxt_ring        *ag_ring_struct;
97
98         /*
99          * To deal with out of order return from TPA, use free buffer indicator
100          */
101         struct rte_bitmap       *ag_bitmap;
102
103         struct bnxt_tpa_info *tpa_info;
104 };
105
106 uint16_t bnxt_recv_pkts(void *rx_queue, struct rte_mbuf **rx_pkts,
107                                uint16_t nb_pkts);
108 void bnxt_free_rx_rings(struct bnxt *bp);
109 int bnxt_init_rx_ring_struct(struct bnxt_rx_queue *rxq, unsigned int socket_id);
110 int bnxt_init_one_rx_ring(struct bnxt_rx_queue *rxq);
111 int bnxt_rx_queue_start(struct rte_eth_dev *dev, uint16_t rx_queue_id);
112 int bnxt_rx_queue_stop(struct rte_eth_dev *dev, uint16_t rx_queue_id);
113 #endif