Imported Upstream version 16.07-rc1
[deb_dpdk.git] / drivers / net / vmxnet3 / vmxnet3_ethdev.h
1 /*-
2  *   BSD LICENSE
3  *
4  *   Copyright(c) 2010-2014 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 _VMXNET3_ETHDEV_H_
35 #define _VMXNET3_ETHDEV_H_
36
37 #define VMXNET3_MAX_MAC_ADDRS 1
38
39 /* UPT feature to negotiate */
40 #define VMXNET3_F_RXCSUM      0x0001
41 #define VMXNET3_F_RSS         0x0002
42 #define VMXNET3_F_RXVLAN      0x0004
43 #define VMXNET3_F_LRO         0x0008
44
45 /* Hash Types supported by device */
46 #define VMXNET3_RSS_HASH_TYPE_NONE      0x0
47 #define VMXNET3_RSS_HASH_TYPE_IPV4      0x01
48 #define VMXNET3_RSS_HASH_TYPE_TCP_IPV4  0x02
49 #define VMXNET3_RSS_HASH_TYPE_IPV6      0x04
50 #define VMXNET3_RSS_HASH_TYPE_TCP_IPV6  0x08
51
52 #define VMXNET3_RSS_HASH_FUNC_NONE      0x0
53 #define VMXNET3_RSS_HASH_FUNC_TOEPLITZ  0x01
54
55 #define VMXNET3_RSS_MAX_KEY_SIZE        40
56 #define VMXNET3_RSS_MAX_IND_TABLE_SIZE  128
57
58 #define VMXNET3_RSS_OFFLOAD_ALL ( \
59         ETH_RSS_IPV4 | \
60         ETH_RSS_NONFRAG_IPV4_TCP | \
61         ETH_RSS_IPV6 | \
62         ETH_RSS_NONFRAG_IPV6_TCP)
63
64 /* RSS configuration structure - shared with device through GPA */
65 typedef
66 struct VMXNET3_RSSConf {
67         uint16_t   hashType;
68         uint16_t   hashFunc;
69         uint16_t   hashKeySize;
70         uint16_t   indTableSize;
71         uint8_t    hashKey[VMXNET3_RSS_MAX_KEY_SIZE];
72         /*
73          * indTable is only element that can be changed without
74          * device quiesce-reset-update-activation cycle
75          */
76         uint8_t    indTable[VMXNET3_RSS_MAX_IND_TABLE_SIZE];
77 } VMXNET3_RSSConf;
78
79 typedef
80 struct vmxnet3_mf_table {
81         void          *mfTableBase; /* Multicast addresses list */
82         uint64_t      mfTablePA;    /* Physical address of the list */
83         uint16_t      num_addrs;    /* number of multicast addrs */
84 } vmxnet3_mf_table_t;
85
86 struct vmxnet3_hw {
87
88         uint8_t *hw_addr0;      /* BAR0: PT-Passthrough Regs    */
89         uint8_t *hw_addr1;      /* BAR1: VD-Virtual Device Regs */
90         /* BAR2: MSI-X Regs */
91         /* BAR3: Port IO    */
92         void *back;
93
94         uint16_t device_id;
95         uint16_t vendor_id;
96         uint16_t subsystem_device_id;
97         uint16_t subsystem_vendor_id;
98         bool adapter_stopped;
99
100         uint8_t perm_addr[ETHER_ADDR_LEN];
101         uint8_t num_tx_queues;
102         uint8_t num_rx_queues;
103         uint8_t bufs_per_pkt;
104
105         Vmxnet3_TxQueueDesc   *tqd_start;       /* start address of all tx queue desc */
106         Vmxnet3_RxQueueDesc   *rqd_start;       /* start address of all rx queue desc */
107
108         Vmxnet3_DriverShared  *shared;
109         uint64_t              sharedPA;
110
111         uint64_t              queueDescPA;
112         uint16_t              queue_desc_len;
113
114         VMXNET3_RSSConf          *rss_conf;
115         uint64_t                         rss_confPA;
116         vmxnet3_mf_table_t   *mf_table;
117         uint32_t              shadow_vfta[VMXNET3_VFT_SIZE];
118 #define VMXNET3_VFT_TABLE_SIZE     (VMXNET3_VFT_SIZE * sizeof(uint32_t))
119 };
120
121 #define VMXNET3_GET_ADDR_LO(reg)   ((uint32_t)(reg))
122 #define VMXNET3_GET_ADDR_HI(reg)   ((uint32_t)(((uint64_t)(reg)) >> 32))
123
124 /* Config space read/writes */
125
126 #define VMXNET3_PCI_REG(reg) (*((volatile uint32_t *)(reg)))
127
128 static inline uint32_t vmxnet3_read_addr(volatile void *addr)
129 {
130         return VMXNET3_PCI_REG(addr);
131 }
132
133 #define VMXNET3_PCI_REG_WRITE(reg, value) do { \
134         VMXNET3_PCI_REG((reg)) = (value); \
135 } while(0)
136
137 #define VMXNET3_PCI_BAR0_REG_ADDR(hw, reg) \
138         ((volatile uint32_t *)((char *)(hw)->hw_addr0 + (reg)))
139 #define VMXNET3_READ_BAR0_REG(hw, reg) \
140         vmxnet3_read_addr(VMXNET3_PCI_BAR0_REG_ADDR((hw), (reg)))
141 #define VMXNET3_WRITE_BAR0_REG(hw, reg, value) \
142         VMXNET3_PCI_REG_WRITE(VMXNET3_PCI_BAR0_REG_ADDR((hw), (reg)), (value))
143
144 #define VMXNET3_PCI_BAR1_REG_ADDR(hw, reg) \
145         ((volatile uint32_t *)((char *)(hw)->hw_addr1 + (reg)))
146 #define VMXNET3_READ_BAR1_REG(hw, reg) \
147         vmxnet3_read_addr(VMXNET3_PCI_BAR1_REG_ADDR((hw), (reg)))
148 #define VMXNET3_WRITE_BAR1_REG(hw, reg, value) \
149         VMXNET3_PCI_REG_WRITE(VMXNET3_PCI_BAR1_REG_ADDR((hw), (reg)), (value))
150
151 /*
152  * RX/TX function prototypes
153  */
154
155 void vmxnet3_dev_clear_queues(struct rte_eth_dev *dev);
156
157 void vmxnet3_dev_rx_queue_release(void *rxq);
158 void vmxnet3_dev_tx_queue_release(void *txq);
159
160 int  vmxnet3_dev_rx_queue_setup(struct rte_eth_dev *dev, uint16_t rx_queue_id,
161                 uint16_t nb_rx_desc, unsigned int socket_id,
162                 const struct rte_eth_rxconf *rx_conf,
163                 struct rte_mempool *mb_pool);
164 int  vmxnet3_dev_tx_queue_setup(struct rte_eth_dev *dev, uint16_t tx_queue_id,
165                 uint16_t nb_tx_desc, unsigned int socket_id,
166                 const struct rte_eth_txconf *tx_conf);
167
168 int vmxnet3_dev_rxtx_init(struct rte_eth_dev *dev);
169
170 int vmxnet3_rss_configure(struct rte_eth_dev *dev);
171
172 uint16_t vmxnet3_recv_pkts(void *rx_queue, struct rte_mbuf **rx_pkts,
173                 uint16_t nb_pkts);
174 uint16_t vmxnet3_xmit_pkts(void *tx_queue, struct rte_mbuf **tx_pkts,
175                 uint16_t nb_pkts);
176
177 #endif /* _VMXNET3_ETHDEV_H_ */