New upstream version 18.02
[deb_dpdk.git] / drivers / net / avf / avf.h
1 /* SPDX-License-Identifier: BSD-3-Clause
2  * Copyright(c) 2017 Intel Corporation
3  */
4
5 #ifndef _AVF_ETHDEV_H_
6 #define _AVF_ETHDEV_H_
7
8 #include <rte_kvargs.h>
9
10 #define AVF_AQ_LEN               32
11 #define AVF_AQ_BUF_SZ            4096
12 #define AVF_RESET_WAIT_CNT       50
13 #define AVF_BUF_SIZE_MIN         1024
14 #define AVF_FRAME_SIZE_MAX       9728
15 #define AVF_QUEUE_BASE_ADDR_UNIT 128
16
17 #define AVF_MAX_NUM_QUEUES       16
18
19 #define AVF_NUM_MACADDR_MAX      64
20
21 #define AVF_DEFAULT_RX_PTHRESH      8
22 #define AVF_DEFAULT_RX_HTHRESH      8
23 #define AVF_DEFAULT_RX_WTHRESH      0
24
25 #define AVF_DEFAULT_RX_FREE_THRESH  32
26
27 #define AVF_DEFAULT_TX_PTHRESH      32
28 #define AVF_DEFAULT_TX_HTHRESH      0
29 #define AVF_DEFAULT_TX_WTHRESH      0
30
31 #define AVF_DEFAULT_TX_FREE_THRESH  32
32 #define AVF_DEFAULT_TX_RS_THRESH 32
33
34 #define AVF_BASIC_OFFLOAD_CAPS  ( \
35         VF_BASE_MODE_OFFLOADS | \
36         VIRTCHNL_VF_OFFLOAD_WB_ON_ITR | \
37         VIRTCHNL_VF_OFFLOAD_RX_POLLING)
38
39 #define AVF_RSS_OFFLOAD_ALL ( \
40         ETH_RSS_FRAG_IPV4 |         \
41         ETH_RSS_NONFRAG_IPV4_TCP |  \
42         ETH_RSS_NONFRAG_IPV4_UDP |  \
43         ETH_RSS_NONFRAG_IPV4_SCTP | \
44         ETH_RSS_NONFRAG_IPV4_OTHER)
45
46 #define AVF_MISC_VEC_ID                RTE_INTR_VEC_ZERO_OFFSET
47 #define AVF_RX_VEC_START               RTE_INTR_VEC_RXTX_OFFSET
48
49 /* Default queue interrupt throttling time in microseconds */
50 #define AVF_ITR_INDEX_DEFAULT          0
51 #define AVF_QUEUE_ITR_INTERVAL_DEFAULT 32 /* 32 us */
52 #define AVF_QUEUE_ITR_INTERVAL_MAX     8160 /* 8160 us */
53
54 /* The overhead from MTU to max frame size.
55  * Considering QinQ packet, the VLAN tag needs to be counted twice.
56  */
57 #define AVF_VLAN_TAG_SIZE               4
58 #define AVF_ETH_OVERHEAD \
59         (ETHER_HDR_LEN + ETHER_CRC_LEN + AVF_VLAN_TAG_SIZE * 2)
60
61 struct avf_adapter;
62 struct avf_rx_queue;
63 struct avf_tx_queue;
64
65 /* Structure that defines a VSI, associated with a adapter. */
66 struct avf_vsi {
67         struct avf_adapter *adapter; /* Backreference to associated adapter */
68         uint16_t vsi_id;
69         uint16_t nb_qps;         /* Number of queue pairs VSI can occupy */
70         uint16_t nb_used_qps;    /* Number of queue pairs VSI uses */
71         uint16_t max_macaddrs;   /* Maximum number of MAC addresses */
72         uint16_t base_vector;
73         uint16_t msix_intr;      /* The MSIX interrupt binds to VSI */
74 };
75
76 /* TODO: is that correct to assume the max number to be 16 ?*/
77 #define AVF_MAX_MSIX_VECTORS   16
78
79 /* Structure to store private data specific for VF instance. */
80 struct avf_info {
81         uint16_t num_queue_pairs;
82         uint16_t max_pkt_len; /* Maximum packet length */
83         uint16_t mac_num;     /* Number of MAC addresses */
84         bool promisc_unicast_enabled;
85         bool promisc_multicast_enabled;
86
87         struct virtchnl_version_info virtchnl_version;
88         struct virtchnl_vf_resource *vf_res; /* VF resource */
89         struct virtchnl_vsi_resource *vsi_res; /* LAN VSI */
90
91         volatile enum virtchnl_ops pend_cmd; /* pending command not finished */
92         uint32_t cmd_retval; /* return value of the cmd response from PF */
93         uint8_t *aq_resp; /* buffer to store the adminq response from PF */
94
95         /* Event from pf */
96         bool dev_closed;
97         bool link_up;
98         enum virtchnl_link_speed link_speed;
99
100         struct avf_vsi vsi;
101         bool vf_reset;
102         uint64_t flags;
103
104         uint8_t *rss_lut;
105         uint8_t *rss_key;
106         uint16_t nb_msix;   /* number of MSI-X interrupts on Rx */
107         uint16_t msix_base; /* msix vector base from */
108         /* queue bitmask for each vector */
109         uint16_t rxq_map[AVF_MAX_MSIX_VECTORS];
110 };
111
112 #define AVF_MAX_PKT_TYPE 256
113
114 /* Structure to store private data for each VF instance. */
115 struct avf_adapter {
116         struct avf_hw hw;
117         struct rte_eth_dev *eth_dev;
118         struct avf_info vf;
119
120         bool rx_bulk_alloc_allowed;
121         /* For vector PMD */
122         bool rx_vec_allowed;
123         bool tx_vec_allowed;
124 };
125
126 /* AVF_DEV_PRIVATE_TO */
127 #define AVF_DEV_PRIVATE_TO_ADAPTER(adapter) \
128         ((struct avf_adapter *)adapter)
129 #define AVF_DEV_PRIVATE_TO_VF(adapter) \
130         (&((struct avf_adapter *)adapter)->vf)
131 #define AVF_DEV_PRIVATE_TO_HW(adapter) \
132         (&((struct avf_adapter *)adapter)->hw)
133
134 /* AVF_VSI_TO */
135 #define AVF_VSI_TO_HW(vsi) \
136         (&(((struct avf_vsi *)vsi)->adapter->hw))
137 #define AVF_VSI_TO_VF(vsi) \
138         (&(((struct avf_vsi *)vsi)->adapter->vf))
139 #define AVF_VSI_TO_ETH_DEV(vsi) \
140         (((struct avf_vsi *)vsi)->adapter->eth_dev)
141
142 static inline void
143 avf_init_adminq_parameter(struct avf_hw *hw)
144 {
145         hw->aq.num_arq_entries = AVF_AQ_LEN;
146         hw->aq.num_asq_entries = AVF_AQ_LEN;
147         hw->aq.arq_buf_size = AVF_AQ_BUF_SZ;
148         hw->aq.asq_buf_size = AVF_AQ_BUF_SZ;
149 }
150
151 static inline uint16_t
152 avf_calc_itr_interval(int16_t interval)
153 {
154         if (interval < 0 || interval > AVF_QUEUE_ITR_INTERVAL_MAX)
155                 interval = AVF_QUEUE_ITR_INTERVAL_DEFAULT;
156
157         /* Convert to hardware count, as writing each 1 represents 2 us */
158         return interval / 2;
159 }
160
161 /* structure used for sending and checking response of virtchnl ops */
162 struct avf_cmd_info {
163         enum virtchnl_ops ops;
164         uint8_t *in_args;       /* buffer for sending */
165         uint32_t in_args_size;  /* buffer size for sending */
166         uint8_t *out_buffer;    /* buffer for response */
167         uint32_t out_size;      /* buffer size for response */
168 };
169
170 /* clear current command. Only call in case execute
171  * _atomic_set_cmd successfully.
172  */
173 static inline void
174 _clear_cmd(struct avf_info *vf)
175 {
176         rte_wmb();
177         vf->pend_cmd = VIRTCHNL_OP_UNKNOWN;
178         vf->cmd_retval = VIRTCHNL_STATUS_SUCCESS;
179 }
180
181 /* Check there is pending cmd in execution. If none, set new command. */
182 static inline int
183 _atomic_set_cmd(struct avf_info *vf, enum virtchnl_ops ops)
184 {
185         int ret = rte_atomic32_cmpset(&vf->pend_cmd, VIRTCHNL_OP_UNKNOWN, ops);
186
187         if (!ret)
188                 PMD_DRV_LOG(ERR, "There is incomplete cmd %d", vf->pend_cmd);
189
190         return !ret;
191 }
192
193 int avf_check_api_version(struct avf_adapter *adapter);
194 int avf_get_vf_resource(struct avf_adapter *adapter);
195 void avf_handle_virtchnl_msg(struct rte_eth_dev *dev);
196 int avf_enable_vlan_strip(struct avf_adapter *adapter);
197 int avf_disable_vlan_strip(struct avf_adapter *adapter);
198 int avf_switch_queue(struct avf_adapter *adapter, uint16_t qid,
199                      bool rx, bool on);
200 int avf_enable_queues(struct avf_adapter *adapter);
201 int avf_disable_queues(struct avf_adapter *adapter);
202 int avf_configure_rss_lut(struct avf_adapter *adapter);
203 int avf_configure_rss_key(struct avf_adapter *adapter);
204 int avf_configure_queues(struct avf_adapter *adapter);
205 int avf_config_irq_map(struct avf_adapter *adapter);
206 void avf_add_del_all_mac_addr(struct avf_adapter *adapter, bool add);
207 int avf_dev_link_update(struct rte_eth_dev *dev,
208                         __rte_unused int wait_to_complete);
209 int avf_query_stats(struct avf_adapter *adapter,
210                     struct virtchnl_eth_stats **pstats);
211 int avf_config_promisc(struct avf_adapter *adapter, bool enable_unicast,
212                        bool enable_multicast);
213 int avf_add_del_eth_addr(struct avf_adapter *adapter,
214                          struct ether_addr *addr, bool add);
215 int avf_add_del_vlan(struct avf_adapter *adapter, uint16_t vlanid, bool add);
216 #endif /* _AVF_ETHDEV_H_ */