66986ea93b3f19d6b702dec9bf2301fcb39c005d
[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
121 /* AVF_DEV_PRIVATE_TO */
122 #define AVF_DEV_PRIVATE_TO_ADAPTER(adapter) \
123         ((struct avf_adapter *)adapter)
124 #define AVF_DEV_PRIVATE_TO_VF(adapter) \
125         (&((struct avf_adapter *)adapter)->vf)
126 #define AVF_DEV_PRIVATE_TO_HW(adapter) \
127         (&((struct avf_adapter *)adapter)->hw)
128
129 /* AVF_VSI_TO */
130 #define AVF_VSI_TO_HW(vsi) \
131         (&(((struct avf_vsi *)vsi)->adapter->hw))
132 #define AVF_VSI_TO_VF(vsi) \
133         (&(((struct avf_vsi *)vsi)->adapter->vf))
134 #define AVF_VSI_TO_ETH_DEV(vsi) \
135         (((struct avf_vsi *)vsi)->adapter->eth_dev)
136
137 static inline void
138 avf_init_adminq_parameter(struct avf_hw *hw)
139 {
140         hw->aq.num_arq_entries = AVF_AQ_LEN;
141         hw->aq.num_asq_entries = AVF_AQ_LEN;
142         hw->aq.arq_buf_size = AVF_AQ_BUF_SZ;
143         hw->aq.asq_buf_size = AVF_AQ_BUF_SZ;
144 }
145
146 static inline uint16_t
147 avf_calc_itr_interval(int16_t interval)
148 {
149         if (interval < 0 || interval > AVF_QUEUE_ITR_INTERVAL_MAX)
150                 interval = AVF_QUEUE_ITR_INTERVAL_DEFAULT;
151
152         /* Convert to hardware count, as writing each 1 represents 2 us */
153         return interval / 2;
154 }
155
156 /* structure used for sending and checking response of virtchnl ops */
157 struct avf_cmd_info {
158         enum virtchnl_ops ops;
159         uint8_t *in_args;       /* buffer for sending */
160         uint32_t in_args_size;  /* buffer size for sending */
161         uint8_t *out_buffer;    /* buffer for response */
162         uint32_t out_size;      /* buffer size for response */
163 };
164
165 /* clear current command. Only call in case execute
166  * _atomic_set_cmd successfully.
167  */
168 static inline void
169 _clear_cmd(struct avf_info *vf)
170 {
171         rte_wmb();
172         vf->pend_cmd = VIRTCHNL_OP_UNKNOWN;
173         vf->cmd_retval = VIRTCHNL_STATUS_SUCCESS;
174 }
175
176 /* Check there is pending cmd in execution. If none, set new command. */
177 static inline int
178 _atomic_set_cmd(struct avf_info *vf, enum virtchnl_ops ops)
179 {
180         int ret = rte_atomic32_cmpset(&vf->pend_cmd, VIRTCHNL_OP_UNKNOWN, ops);
181
182         if (!ret)
183                 PMD_DRV_LOG(ERR, "There is incomplete cmd %d", vf->pend_cmd);
184
185         return !ret;
186 }
187
188 int avf_check_api_version(struct avf_adapter *adapter);
189 int avf_get_vf_resource(struct avf_adapter *adapter);
190 void avf_handle_virtchnl_msg(struct rte_eth_dev *dev);
191 int avf_enable_vlan_strip(struct avf_adapter *adapter);
192 int avf_disable_vlan_strip(struct avf_adapter *adapter);
193 int avf_switch_queue(struct avf_adapter *adapter, uint16_t qid,
194                      bool rx, bool on);
195 int avf_enable_queues(struct avf_adapter *adapter);
196 int avf_disable_queues(struct avf_adapter *adapter);
197 int avf_configure_rss_lut(struct avf_adapter *adapter);
198 int avf_configure_rss_key(struct avf_adapter *adapter);
199 int avf_configure_queues(struct avf_adapter *adapter);
200 int avf_config_irq_map(struct avf_adapter *adapter);
201 void avf_add_del_all_mac_addr(struct avf_adapter *adapter, bool add);
202 int avf_dev_link_update(struct rte_eth_dev *dev,
203                         __rte_unused int wait_to_complete);
204 int avf_query_stats(struct avf_adapter *adapter,
205                     struct virtchnl_eth_stats **pstats);
206 int avf_config_promisc(struct avf_adapter *adapter, bool enable_unicast,
207                        bool enable_multicast);
208 int avf_add_del_eth_addr(struct avf_adapter *adapter,
209                          struct ether_addr *addr, bool add);
210 int avf_add_del_vlan(struct avf_adapter *adapter, uint16_t vlanid, bool add);
211 #endif /* _AVF_ETHDEV_H_ */