dc3080ffd3d91ebcf9e9fffe04339de29137d25f
[deb_dpdk.git] / drivers / net / ena / ena_ethdev.h
1 /*-
2 * BSD LICENSE
3 *
4 * Copyright (c) 2015-2016 Amazon.com, Inc. or its affiliates.
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 copyright holder 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 _ENA_ETHDEV_H_
35 #define _ENA_ETHDEV_H_
36
37 #include <rte_pci.h>
38
39 #include "ena_com.h"
40
41 #define ENA_REGS_BAR    0
42 #define ENA_MEM_BAR     2
43
44 #define ENA_MAX_NUM_QUEUES      128
45 #define ENA_DEFAULT_RING_SIZE   (1024)
46 #define ENA_MIN_FRAME_LEN       64
47 #define ENA_NAME_MAX_LEN        20
48 #define ENA_PKT_MAX_BUFS        17
49
50 #define ENA_MMIO_DISABLE_REG_READ       BIT(0)
51
52 struct ena_adapter;
53
54 enum ena_ring_type {
55         ENA_RING_TYPE_RX = 1,
56         ENA_RING_TYPE_TX = 2,
57 };
58
59 struct ena_tx_buffer {
60         struct rte_mbuf *mbuf;
61         unsigned int tx_descs;
62         unsigned int num_of_bufs;
63         struct ena_com_buf bufs[ENA_PKT_MAX_BUFS];
64 };
65
66 struct ena_ring {
67         u16 next_to_use;
68         u16 next_to_clean;
69
70         enum ena_ring_type type;
71         enum ena_admin_placement_policy_type tx_mem_queue_type;
72         /* Holds the empty requests for TX OOO completions */
73         uint16_t *empty_tx_reqs;
74         union {
75                 struct ena_tx_buffer *tx_buffer_info; /* contex of tx packet */
76                 struct rte_mbuf **rx_buffer_info; /* contex of rx packet */
77         };
78         unsigned int ring_size; /* number of tx/rx_buffer_info's entries */
79
80         struct ena_com_io_cq *ena_com_io_cq;
81         struct ena_com_io_sq *ena_com_io_sq;
82
83         struct ena_com_rx_buf_info ena_bufs[ENA_PKT_MAX_BUFS]
84                                                 __rte_cache_aligned;
85
86         struct rte_mempool *mb_pool;
87         unsigned int port_id;
88         unsigned int id;
89         /* Max length PMD can push to device for LLQ */
90         uint8_t tx_max_header_size;
91         int configured;
92         struct ena_adapter *adapter;
93 } __rte_cache_aligned;
94
95 enum ena_adapter_state {
96         ENA_ADAPTER_STATE_FREE    = 0,
97         ENA_ADAPTER_STATE_INIT    = 1,
98         ENA_ADAPTER_STATE_RUNNING  = 2,
99         ENA_ADAPTER_STATE_STOPPED = 3,
100         ENA_ADAPTER_STATE_CONFIG  = 4,
101 };
102
103 struct ena_driver_stats {
104         rte_atomic64_t ierrors;
105         rte_atomic64_t oerrors;
106         rte_atomic64_t rx_nombuf;
107 };
108
109 struct ena_stats_dev {
110         u64 tx_timeout;
111         u64 io_suspend;
112         u64 io_resume;
113         u64 wd_expired;
114         u64 interface_up;
115         u64 interface_down;
116         u64 admin_q_pause;
117 };
118
119 struct ena_stats_tx {
120         u64 cnt;
121         u64 bytes;
122         u64 queue_stop;
123         u64 prepare_ctx_err;
124         u64 queue_wakeup;
125         u64 dma_mapping_err;
126         u64 linearize;
127         u64 linearize_failed;
128         u64 tx_poll;
129         u64 doorbells;
130         u64 missing_tx_comp;
131         u64 bad_req_id;
132 };
133
134 struct ena_stats_rx {
135         u64 cnt;
136         u64 bytes;
137         u64 refil_partial;
138         u64 bad_csum;
139         u64 page_alloc_fail;
140         u64 skb_alloc_fail;
141         u64 dma_mapping_err;
142         u64 bad_desc_num;
143         u64 small_copy_len_pkt;
144 };
145
146 /* board specific private data structure */
147 struct ena_adapter {
148         /* OS defined structs */
149         struct rte_pci_device *pdev;
150         struct rte_eth_dev_data *rte_eth_dev_data;
151         struct rte_eth_dev *rte_dev;
152
153         struct ena_com_dev ena_dev __rte_cache_aligned;
154
155         /* TX */
156         struct ena_ring tx_ring[ENA_MAX_NUM_QUEUES] __rte_cache_aligned;
157         int tx_ring_size;
158
159         /* RX */
160         struct ena_ring rx_ring[ENA_MAX_NUM_QUEUES] __rte_cache_aligned;
161         int rx_ring_size;
162
163         u16 num_queues;
164         u16 max_mtu;
165         u8 tso4_supported;
166
167         int id_number;
168         char name[ENA_NAME_MAX_LEN];
169         u8 mac_addr[ETHER_ADDR_LEN];
170
171         void *regs;
172         void *dev_mem_base;
173
174         struct ena_driver_stats *drv_stats;
175         enum ena_adapter_state state;
176
177 };
178
179 #endif /* _ENA_ETHDEV_H_ */