4 * Copyright (c) 2015-2016 Amazon.com, Inc. or its affiliates.
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
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
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.
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.
34 #ifndef _ENA_ETHDEV_H_
35 #define _ENA_ETHDEV_H_
41 #define ENA_REGS_BAR 0
44 #define ENA_MAX_NUM_QUEUES 128
46 #define ENA_DEFAULT_TX_SW_DESCS (1024)
47 #define ENA_DEFAULT_TX_HW_DESCS (1024)
48 #define ENA_DEFAULT_RING_SIZE (1024)
50 #define ENA_MIN_FRAME_LEN 64
52 #define ENA_NAME_MAX_LEN 20
53 #define ENA_IRQNAME_SIZE 40
55 #define ENA_PKT_MAX_BUFS 17
57 #define ENA_MMIO_DISABLE_REG_READ BIT(0)
59 #define ENA_CIRC_COUNT(head, tail, size) \
60 (((uint16_t)((uint16_t)(head) - (uint16_t)(tail))) & ((size) - 1))
62 #define ENA_CIRC_INC(index, step, size) \
63 ((uint16_t)(index) + (uint16_t)(step))
64 #define ENA_CIRC_INC_WRAP(index, step, size) \
65 (((uint16_t)(index) + (uint16_t)(step)) & ((size) - 1))
67 #define ENA_TX_RING_IDX_NEXT(idx, ring_size) \
68 ENA_CIRC_INC_WRAP(idx, 1, ring_size)
69 #define ENA_RX_RING_IDX_NEXT(idx, ring_size) \
70 ENA_CIRC_INC_WRAP(idx, 1, ring_size)
79 struct ena_tx_buffer {
80 struct rte_mbuf *mbuf;
81 unsigned int tx_descs;
82 unsigned int num_of_bufs;
83 struct ena_com_buf bufs[ENA_PKT_MAX_BUFS];
90 enum ena_ring_type type;
91 enum ena_admin_placement_policy_type tx_mem_queue_type;
92 /* Holds the empty requests for TX OOO completions */
93 uint16_t *empty_tx_reqs;
95 struct ena_tx_buffer *tx_buffer_info; /* contex of tx packet */
96 struct rte_mbuf **rx_buffer_info; /* contex of rx packet */
98 unsigned int ring_size; /* number of tx/rx_buffer_info's entries */
100 struct ena_com_io_cq *ena_com_io_cq;
101 struct ena_com_io_sq *ena_com_io_sq;
103 struct ena_com_rx_buf_info ena_bufs[ENA_PKT_MAX_BUFS]
106 struct rte_mempool *mb_pool;
107 unsigned int port_id;
109 /* Max length PMD can push to device for LLQ */
110 uint8_t tx_max_header_size;
112 struct ena_adapter *adapter;
113 } __rte_cache_aligned;
115 enum ena_adapter_state {
116 ENA_ADAPTER_STATE_FREE = 0,
117 ENA_ADAPTER_STATE_INIT = 1,
118 ENA_ADAPTER_STATE_RUNNING = 2,
119 ENA_ADAPTER_STATE_STOPPED = 3,
120 ENA_ADAPTER_STATE_CONFIG = 4,
123 struct ena_driver_stats {
124 rte_atomic64_t ierrors;
125 rte_atomic64_t oerrors;
126 rte_atomic64_t rx_nombuf;
129 struct ena_stats_dev {
139 struct ena_stats_tx {
147 u64 linearize_failed;
154 struct ena_stats_rx {
163 u64 small_copy_len_pkt;
166 /* board specific private data structure */
168 /* OS defined structs */
169 struct rte_pci_device *pdev;
170 struct rte_eth_dev_data *rte_eth_dev_data;
171 struct rte_eth_dev *rte_dev;
173 struct ena_com_dev ena_dev __rte_cache_aligned;
176 struct ena_ring tx_ring[ENA_MAX_NUM_QUEUES] __rte_cache_aligned;
180 struct ena_ring rx_ring[ENA_MAX_NUM_QUEUES] __rte_cache_aligned;
187 char name[ENA_NAME_MAX_LEN];
188 u8 mac_addr[ETHER_ADDR_LEN];
193 struct ena_driver_stats *drv_stats;
194 enum ena_adapter_state state;
198 #endif /* _ENA_ETHDEV_H_ */