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