ixgbe: support port hotplug
[dpdk.git] / drivers / net / ixgbe / ixgbe_ethdev.h
1 /*-
2  *   BSD LICENSE
3  *
4  *   Copyright(c) 2010-2015 Intel Corporation. All rights reserved.
5  *   All rights reserved.
6  *
7  *   Redistribution and use in source and binary forms, with or without
8  *   modification, are permitted provided that the following conditions
9  *   are met:
10  *
11  *     * Redistributions of source code must retain the above copyright
12  *       notice, this list of conditions and the following disclaimer.
13  *     * Redistributions in binary form must reproduce the above copyright
14  *       notice, this list of conditions and the following disclaimer in
15  *       the documentation and/or other materials provided with the
16  *       distribution.
17  *     * Neither the name of Intel Corporation nor the names of its
18  *       contributors may be used to endorse or promote products derived
19  *       from this software without specific prior written permission.
20  *
21  *   THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
22  *   "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
23  *   LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
24  *   A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
25  *   OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
26  *   SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
27  *   LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
28  *   DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
29  *   THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
30  *   (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
31  *   OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32  */
33
34 #ifndef _IXGBE_ETHDEV_H_
35 #define _IXGBE_ETHDEV_H_
36 #include "base/ixgbe_dcb.h"
37 #include "base/ixgbe_dcb_82599.h"
38 #include "base/ixgbe_dcb_82598.h"
39 #include "ixgbe_bypass.h"
40
41 /* need update link, bit flag */
42 #define IXGBE_FLAG_NEED_LINK_UPDATE (uint32_t)(1 << 0)
43 #define IXGBE_FLAG_MAILBOX          (uint32_t)(1 << 1)
44
45 /*
46  * Defines that were not part of ixgbe_type.h as they are not used by the
47  * FreeBSD driver.
48  */
49 #define IXGBE_ADVTXD_MAC_1588       0x00080000 /* IEEE1588 Timestamp packet */
50 #define IXGBE_RXD_STAT_TMST         0x10000    /* Timestamped Packet indication */
51 #define IXGBE_ADVTXD_TUCMD_L4T_RSV  0x00001800 /* L4 Packet TYPE, resvd  */
52 #define IXGBE_RXDADV_ERR_CKSUM_BIT  30
53 #define IXGBE_RXDADV_ERR_CKSUM_MSK  3
54 #define IXGBE_ADVTXD_MACLEN_SHIFT   9          /* Bit shift for l2_len */
55 #define IXGBE_NB_STAT_MAPPING_REGS  32
56 #define IXGBE_EXTENDED_VLAN       (uint32_t)(1 << 26) /* EXTENDED VLAN ENABLE */
57 #define IXGBE_VFTA_SIZE 128
58 #define IXGBE_VLAN_TAG_SIZE 4
59 #define IXGBE_MAX_RX_QUEUE_NUM  128
60 #ifndef NBBY
61 #define NBBY    8       /* number of bits in a byte */
62 #endif
63 #define IXGBE_HWSTRIP_BITMAP_SIZE (IXGBE_MAX_RX_QUEUE_NUM / (sizeof(uint32_t) * NBBY))
64
65 /* EITR Inteval is in 2048ns uinits for 1G and 10G link */
66 #define IXGBE_EITR_INTERVAL_UNIT_NS     2048
67 #define IXGBE_EITR_ITR_INT_SHIFT       3
68 #define IXGBE_EITR_INTERVAL_US(us) \
69         (((us) * 1000 / IXGBE_EITR_INTERVAL_UNIT_NS << IXGBE_EITR_ITR_INT_SHIFT) & \
70                 IXGBE_EITR_ITR_INT_MASK)
71
72
73 /* Loopback operation modes */
74 /* 82599 specific loopback operation types */
75 #define IXGBE_LPBK_82599_NONE   0x0 /* Default value. Loopback is disabled. */
76 #define IXGBE_LPBK_82599_TX_RX  0x1 /* Tx->Rx loopback operation is enabled. */
77
78 #define IXGBE_MAX_JUMBO_FRAME_SIZE      0x2600 /* Maximum Jumbo frame size. */
79
80 #define IXGBE_RTTBCNRC_RF_INT_MASK_BASE 0x000003FF
81 #define IXGBE_RTTBCNRC_RF_INT_MASK_M \
82         (IXGBE_RTTBCNRC_RF_INT_MASK_BASE << IXGBE_RTTBCNRC_RF_INT_SHIFT)
83
84 #define IXGBE_MAX_QUEUE_NUM_PER_VF  8
85
86 #define IXGBE_SYN_FILTER_ENABLE         0x00000001 /* syn filter enable field */
87 #define IXGBE_SYN_FILTER_QUEUE          0x000000FE /* syn filter queue field */
88 #define IXGBE_SYN_FILTER_QUEUE_SHIFT    1          /* syn filter queue field shift */
89 #define IXGBE_SYN_FILTER_SYNQFP         0x80000000 /* syn filter SYNQFP */
90
91 #define IXGBE_ETQF_UP                   0x00070000 /* ethertype filter priority field */
92 #define IXGBE_ETQF_SHIFT                16
93 #define IXGBE_ETQF_UP_EN                0x00080000
94 #define IXGBE_ETQF_ETHERTYPE            0x0000FFFF /* ethertype filter ethertype field */
95 #define IXGBE_ETQF_MAX_PRI              7
96
97 #define IXGBE_SDPQF_DSTPORT             0xFFFF0000 /* dst port field */
98 #define IXGBE_SDPQF_DSTPORT_SHIFT       16         /* dst port field shift */
99 #define IXGBE_SDPQF_SRCPORT             0x0000FFFF /* src port field */
100
101 #define IXGBE_L34T_IMIR_SIZE_BP         0x00001000
102 #define IXGBE_L34T_IMIR_RESERVE         0x00080000 /* bit 13 to 19 must be set to 1000000b. */
103 #define IXGBE_L34T_IMIR_LLI             0x00100000
104 #define IXGBE_L34T_IMIR_QUEUE           0x0FE00000
105 #define IXGBE_L34T_IMIR_QUEUE_SHIFT     21
106 #define IXGBE_5TUPLE_MAX_PRI            7
107 #define IXGBE_5TUPLE_MIN_PRI            1
108
109 #define IXGBE_RSS_OFFLOAD_ALL ( \
110         ETH_RSS_IPV4 | \
111         ETH_RSS_NONFRAG_IPV4_TCP | \
112         ETH_RSS_NONFRAG_IPV4_UDP | \
113         ETH_RSS_IPV6 | \
114         ETH_RSS_NONFRAG_IPV6_TCP | \
115         ETH_RSS_NONFRAG_IPV6_UDP | \
116         ETH_RSS_IPV6_EX | \
117         ETH_RSS_IPV6_TCP_EX | \
118         ETH_RSS_IPV6_UDP_EX)
119
120 /*
121  * Information about the fdir mode.
122  */
123
124 struct ixgbe_hw_fdir_mask {
125         uint16_t vlan_tci_mask;
126         uint32_t src_ipv4_mask;
127         uint32_t dst_ipv4_mask;
128         uint16_t src_ipv6_mask;
129         uint16_t dst_ipv6_mask;
130         uint16_t src_port_mask;
131         uint16_t dst_port_mask;
132         uint16_t flex_bytes_mask;
133 };
134
135 struct ixgbe_hw_fdir_info {
136         struct ixgbe_hw_fdir_mask mask;
137         uint8_t     flex_bytes_offset;
138         uint16_t    collision;
139         uint16_t    free;
140         uint16_t    maxhash;
141         uint8_t     maxlen;
142         uint64_t    add;
143         uint64_t    remove;
144         uint64_t    f_add;
145         uint64_t    f_remove;
146 };
147
148 /* structure for interrupt relative data */
149 struct ixgbe_interrupt {
150         uint32_t flags;
151         uint32_t mask;
152 };
153
154 struct ixgbe_stat_mapping_registers {
155         uint32_t tqsm[IXGBE_NB_STAT_MAPPING_REGS];
156         uint32_t rqsmr[IXGBE_NB_STAT_MAPPING_REGS];
157 };
158
159 struct ixgbe_vfta {
160         uint32_t vfta[IXGBE_VFTA_SIZE];
161 };
162
163 struct ixgbe_hwstrip {
164         uint32_t bitmap[IXGBE_HWSTRIP_BITMAP_SIZE];
165 };
166
167 /*
168  * VF data which used by PF host only
169  */
170 #define IXGBE_MAX_VF_MC_ENTRIES         30
171 #define IXGBE_MAX_MR_RULE_ENTRIES       4 /* number of mirroring rules supported */
172 #define IXGBE_MAX_UTA                   128
173
174 struct ixgbe_uta_info {
175         uint8_t  uc_filter_type;
176         uint16_t uta_in_use;
177         uint32_t uta_shadow[IXGBE_MAX_UTA];
178 };
179
180 #define IXGBE_MAX_MIRROR_RULES 4  /* Maximum nb. of mirror rules. */
181
182 struct ixgbe_mirror_info {
183         struct rte_eth_mirror_conf mr_conf[IXGBE_MAX_MIRROR_RULES];
184         /**< store PF mirror rules configuration*/
185 };
186
187 struct ixgbe_vf_info {
188         uint8_t vf_mac_addresses[ETHER_ADDR_LEN];
189         uint16_t vf_mc_hashes[IXGBE_MAX_VF_MC_ENTRIES];
190         uint16_t num_vf_mc_hashes;
191         uint16_t default_vf_vlan_id;
192         uint16_t vlans_enabled;
193         bool clear_to_send;
194         uint16_t tx_rate[IXGBE_MAX_QUEUE_NUM_PER_VF];
195         uint16_t vlan_count;
196         uint8_t spoofchk_enabled;
197         uint8_t api_version;
198 };
199
200 /*
201  *  Possible l4type of 5tuple filters.
202  */
203 enum ixgbe_5tuple_protocol {
204         IXGBE_FILTER_PROTOCOL_TCP = 0,
205         IXGBE_FILTER_PROTOCOL_UDP,
206         IXGBE_FILTER_PROTOCOL_SCTP,
207         IXGBE_FILTER_PROTOCOL_NONE,
208 };
209
210 TAILQ_HEAD(ixgbe_5tuple_filter_list, ixgbe_5tuple_filter);
211
212 struct ixgbe_5tuple_filter_info {
213         uint32_t dst_ip;
214         uint32_t src_ip;
215         uint16_t dst_port;
216         uint16_t src_port;
217         enum ixgbe_5tuple_protocol proto;        /* l4 protocol. */
218         uint8_t priority;        /* seven levels (001b-111b), 111b is highest,
219                                       used when more than one filter matches. */
220         uint8_t dst_ip_mask:1,   /* if mask is 1b, do not compare dst ip. */
221                 src_ip_mask:1,   /* if mask is 1b, do not compare src ip. */
222                 dst_port_mask:1, /* if mask is 1b, do not compare dst port. */
223                 src_port_mask:1, /* if mask is 1b, do not compare src port. */
224                 proto_mask:1;    /* if mask is 1b, do not compare protocol. */
225 };
226
227 /* 5tuple filter structure */
228 struct ixgbe_5tuple_filter {
229         TAILQ_ENTRY(ixgbe_5tuple_filter) entries;
230         uint16_t index;       /* the index of 5tuple filter */
231         struct ixgbe_5tuple_filter_info filter_info;
232         uint16_t queue;       /* rx queue assigned to */
233 };
234
235 #define IXGBE_5TUPLE_ARRAY_SIZE \
236         (RTE_ALIGN(IXGBE_MAX_FTQF_FILTERS, (sizeof(uint32_t) * NBBY)) / \
237          (sizeof(uint32_t) * NBBY))
238
239 /*
240  * Structure to store filters' info.
241  */
242 struct ixgbe_filter_info {
243         uint8_t ethertype_mask;  /* Bit mask for every used ethertype filter */
244         /* store used ethertype filters*/
245         uint16_t ethertype_filters[IXGBE_MAX_ETQF_FILTERS];
246         /* Bit mask for every used 5tuple filter */
247         uint32_t fivetuple_mask[IXGBE_5TUPLE_ARRAY_SIZE];
248         struct ixgbe_5tuple_filter_list fivetuple_list;
249 };
250
251 /*
252  * Structure to store private data for each driver instance (for each port).
253  */
254 struct ixgbe_adapter {
255         struct ixgbe_hw             hw;
256         struct ixgbe_hw_stats       stats;
257         struct ixgbe_hw_fdir_info   fdir;
258         struct ixgbe_interrupt      intr;
259         struct ixgbe_stat_mapping_registers stat_mappings;
260         struct ixgbe_vfta           shadow_vfta;
261         struct ixgbe_hwstrip            hwstrip;
262         struct ixgbe_dcb_config     dcb_config;
263         struct ixgbe_mirror_info    mr_data;
264         struct ixgbe_vf_info        *vfdata;
265         struct ixgbe_uta_info       uta_info;
266 #ifdef RTE_NIC_BYPASS
267         struct ixgbe_bypass_info    bps;
268 #endif /* RTE_NIC_BYPASS */
269         struct ixgbe_filter_info    filter;
270
271         bool rx_bulk_alloc_allowed;
272         bool rx_vec_allowed;
273 };
274
275 #define IXGBE_DEV_PRIVATE_TO_HW(adapter)\
276         (&((struct ixgbe_adapter *)adapter)->hw)
277
278 #define IXGBE_DEV_PRIVATE_TO_STATS(adapter) \
279         (&((struct ixgbe_adapter *)adapter)->stats)
280
281 #define IXGBE_DEV_PRIVATE_TO_INTR(adapter) \
282         (&((struct ixgbe_adapter *)adapter)->intr)
283
284 #define IXGBE_DEV_PRIVATE_TO_FDIR_INFO(adapter) \
285         (&((struct ixgbe_adapter *)adapter)->fdir)
286
287 #define IXGBE_DEV_PRIVATE_TO_STAT_MAPPINGS(adapter) \
288         (&((struct ixgbe_adapter *)adapter)->stat_mappings)
289
290 #define IXGBE_DEV_PRIVATE_TO_VFTA(adapter) \
291         (&((struct ixgbe_adapter *)adapter)->shadow_vfta)
292
293 #define IXGBE_DEV_PRIVATE_TO_HWSTRIP_BITMAP(adapter) \
294         (&((struct ixgbe_adapter *)adapter)->hwstrip)
295
296 #define IXGBE_DEV_PRIVATE_TO_DCB_CFG(adapter) \
297         (&((struct ixgbe_adapter *)adapter)->dcb_config)
298
299 #define IXGBE_DEV_PRIVATE_TO_P_VFDATA(adapter) \
300         (&((struct ixgbe_adapter *)adapter)->vfdata)
301
302 #define IXGBE_DEV_PRIVATE_TO_PFDATA(adapter) \
303         (&((struct ixgbe_adapter *)adapter)->mr_data)
304
305 #define IXGBE_DEV_PRIVATE_TO_UTA(adapter) \
306         (&((struct ixgbe_adapter *)adapter)->uta_info)
307
308 #define IXGBE_DEV_PRIVATE_TO_FILTER_INFO(adapter) \
309         (&((struct ixgbe_adapter *)adapter)->filter)
310
311 /*
312  * RX/TX function prototypes
313  */
314 void ixgbe_dev_clear_queues(struct rte_eth_dev *dev);
315
316 void ixgbe_dev_rx_queue_release(void *rxq);
317
318 void ixgbe_dev_tx_queue_release(void *txq);
319
320 int  ixgbe_dev_rx_queue_setup(struct rte_eth_dev *dev, uint16_t rx_queue_id,
321                 uint16_t nb_rx_desc, unsigned int socket_id,
322                 const struct rte_eth_rxconf *rx_conf,
323                 struct rte_mempool *mb_pool);
324
325 int  ixgbe_dev_tx_queue_setup(struct rte_eth_dev *dev, uint16_t tx_queue_id,
326                 uint16_t nb_tx_desc, unsigned int socket_id,
327                 const struct rte_eth_txconf *tx_conf);
328
329 uint32_t ixgbe_dev_rx_queue_count(struct rte_eth_dev *dev,
330                 uint16_t rx_queue_id);
331
332 int ixgbe_dev_rx_descriptor_done(void *rx_queue, uint16_t offset);
333
334 int ixgbe_dev_rx_init(struct rte_eth_dev *dev);
335
336 void ixgbe_dev_tx_init(struct rte_eth_dev *dev);
337
338 int ixgbe_dev_rxtx_start(struct rte_eth_dev *dev);
339
340 int ixgbe_dev_rx_queue_start(struct rte_eth_dev *dev, uint16_t rx_queue_id);
341
342 int ixgbe_dev_rx_queue_stop(struct rte_eth_dev *dev, uint16_t rx_queue_id);
343
344 int ixgbe_dev_tx_queue_start(struct rte_eth_dev *dev, uint16_t tx_queue_id);
345
346 int ixgbe_dev_tx_queue_stop(struct rte_eth_dev *dev, uint16_t tx_queue_id);
347
348 int ixgbevf_dev_rx_init(struct rte_eth_dev *dev);
349
350 void ixgbevf_dev_tx_init(struct rte_eth_dev *dev);
351
352 void ixgbevf_dev_rxtx_start(struct rte_eth_dev *dev);
353
354 uint16_t ixgbe_recv_pkts(void *rx_queue, struct rte_mbuf **rx_pkts,
355                 uint16_t nb_pkts);
356
357 uint16_t ixgbe_recv_pkts_lro_single_alloc(void *rx_queue,
358                 struct rte_mbuf **rx_pkts, uint16_t nb_pkts);
359 uint16_t ixgbe_recv_pkts_lro_bulk_alloc(void *rx_queue,
360                 struct rte_mbuf **rx_pkts, uint16_t nb_pkts);
361
362 uint16_t ixgbe_xmit_pkts(void *tx_queue, struct rte_mbuf **tx_pkts,
363                 uint16_t nb_pkts);
364
365 uint16_t ixgbe_xmit_pkts_simple(void *tx_queue, struct rte_mbuf **tx_pkts,
366                 uint16_t nb_pkts);
367
368 int ixgbe_dev_rss_hash_update(struct rte_eth_dev *dev,
369                               struct rte_eth_rss_conf *rss_conf);
370
371 int ixgbe_dev_rss_hash_conf_get(struct rte_eth_dev *dev,
372                                 struct rte_eth_rss_conf *rss_conf);
373
374 /*
375  * Flow director function prototypes
376  */
377 int ixgbe_fdir_configure(struct rte_eth_dev *dev);
378
379 void ixgbe_configure_dcb(struct rte_eth_dev *dev);
380
381 /*
382  * misc function prototypes
383  */
384 void ixgbe_vlan_hw_filter_enable(struct rte_eth_dev *dev);
385
386 void ixgbe_vlan_hw_filter_disable(struct rte_eth_dev *dev);
387
388 void ixgbe_vlan_hw_strip_enable_all(struct rte_eth_dev *dev);
389
390 void ixgbe_vlan_hw_strip_disable_all(struct rte_eth_dev *dev);
391
392 void ixgbe_pf_host_init(struct rte_eth_dev *eth_dev);
393
394 void ixgbe_pf_host_uninit(struct rte_eth_dev *eth_dev);
395
396 void ixgbe_pf_mbx_process(struct rte_eth_dev *eth_dev);
397
398 int ixgbe_pf_host_configure(struct rte_eth_dev *eth_dev);
399
400 uint32_t ixgbe_convert_vm_rx_mask_to_val(uint16_t rx_mask, uint32_t orig_val);
401
402 int ixgbe_fdir_ctrl_func(struct rte_eth_dev *dev,
403                         enum rte_filter_op filter_op, void *arg);
404 #endif /* _IXGBE_ETHDEV_H_ */