Branch data Line data Source code
1 : : /* SPDX-License-Identifier: BSD-3-Clause
2 : : * Copyright(c) 2010-2015 Intel Corporation
3 : : */
4 : :
5 : : #include <sys/queue.h>
6 : : #include <stdalign.h>
7 : : #include <stdio.h>
8 : : #include <errno.h>
9 : : #include <stdint.h>
10 : : #include <string.h>
11 : : #include <unistd.h>
12 : : #include <stdarg.h>
13 : : #include <fcntl.h>
14 : : #include <inttypes.h>
15 : : #include <rte_byteorder.h>
16 : : #include <rte_common.h>
17 : : #include <rte_cycles.h>
18 : :
19 : : #include <rte_interrupts.h>
20 : : #include <rte_log.h>
21 : : #include <rte_debug.h>
22 : : #include <rte_pci.h>
23 : : #include <bus_pci_driver.h>
24 : : #include <rte_branch_prediction.h>
25 : : #include <rte_memory.h>
26 : : #include <rte_memzone.h>
27 : : #include <rte_eal.h>
28 : : #include <rte_alarm.h>
29 : : #include <rte_ether.h>
30 : : #include <ethdev_driver.h>
31 : : #include <ethdev_pci.h>
32 : : #include <rte_string_fns.h>
33 : : #include <rte_malloc.h>
34 : : #include <dev_driver.h>
35 : :
36 : : #include "base/vmxnet3_defs.h"
37 : :
38 : : #include "vmxnet3_ring.h"
39 : : #include "vmxnet3_logs.h"
40 : : #include "vmxnet3_ethdev.h"
41 : :
42 : : #define VMXNET3_TX_MAX_SEG UINT8_MAX
43 : :
44 : : #define VMXNET3_TX_OFFLOAD_CAP \
45 : : (RTE_ETH_TX_OFFLOAD_VLAN_INSERT | \
46 : : RTE_ETH_TX_OFFLOAD_TCP_CKSUM | \
47 : : RTE_ETH_TX_OFFLOAD_UDP_CKSUM | \
48 : : RTE_ETH_TX_OFFLOAD_TCP_TSO | \
49 : : RTE_ETH_TX_OFFLOAD_MULTI_SEGS)
50 : :
51 : : #define VMXNET3_RX_OFFLOAD_CAP \
52 : : (RTE_ETH_RX_OFFLOAD_VLAN_STRIP | \
53 : : RTE_ETH_RX_OFFLOAD_VLAN_FILTER | \
54 : : RTE_ETH_RX_OFFLOAD_SCATTER | \
55 : : RTE_ETH_RX_OFFLOAD_UDP_CKSUM | \
56 : : RTE_ETH_RX_OFFLOAD_TCP_CKSUM | \
57 : : RTE_ETH_RX_OFFLOAD_TCP_LRO | \
58 : : RTE_ETH_RX_OFFLOAD_RSS_HASH)
59 : :
60 : : int vmxnet3_segs_dynfield_offset = -1;
61 : :
62 : : static int eth_vmxnet3_dev_init(struct rte_eth_dev *eth_dev);
63 : : static int eth_vmxnet3_dev_uninit(struct rte_eth_dev *eth_dev);
64 : : static int vmxnet3_dev_configure(struct rte_eth_dev *dev);
65 : : static int vmxnet3_dev_start(struct rte_eth_dev *dev);
66 : : static int vmxnet3_dev_stop(struct rte_eth_dev *dev);
67 : : static int vmxnet3_dev_close(struct rte_eth_dev *dev);
68 : : static int vmxnet3_dev_reset(struct rte_eth_dev *dev);
69 : : static void vmxnet3_dev_set_rxmode(struct vmxnet3_hw *hw, uint32_t feature, int set);
70 : : static int vmxnet3_dev_promiscuous_enable(struct rte_eth_dev *dev);
71 : : static int vmxnet3_dev_promiscuous_disable(struct rte_eth_dev *dev);
72 : : static int vmxnet3_dev_allmulticast_enable(struct rte_eth_dev *dev);
73 : : static int vmxnet3_dev_allmulticast_disable(struct rte_eth_dev *dev);
74 : : static int __vmxnet3_dev_link_update(struct rte_eth_dev *dev,
75 : : int wait_to_complete);
76 : : static int vmxnet3_dev_link_update(struct rte_eth_dev *dev,
77 : : int wait_to_complete);
78 : : static void vmxnet3_hw_stats_save(struct vmxnet3_hw *hw);
79 : : static int vmxnet3_dev_stats_get(struct rte_eth_dev *dev,
80 : : struct rte_eth_stats *stats,
81 : : struct eth_queue_stats *qstats);
82 : : static int vmxnet3_dev_stats_reset(struct rte_eth_dev *dev);
83 : : static int vmxnet3_dev_xstats_get_names(struct rte_eth_dev *dev,
84 : : struct rte_eth_xstat_name *xstats,
85 : : unsigned int n);
86 : : static int vmxnet3_dev_xstats_get(struct rte_eth_dev *dev,
87 : : struct rte_eth_xstat *xstats, unsigned int n);
88 : : static int vmxnet3_dev_info_get(struct rte_eth_dev *dev,
89 : : struct rte_eth_dev_info *dev_info);
90 : : static int vmxnet3_hw_ver_get(struct rte_eth_dev *dev,
91 : : char *fw_version, size_t fw_size);
92 : : static const uint32_t *
93 : : vmxnet3_dev_supported_ptypes_get(struct rte_eth_dev *dev,
94 : : size_t *no_of_elements);
95 : : static int vmxnet3_dev_mtu_set(struct rte_eth_dev *dev, uint16_t mtu);
96 : : static int vmxnet3_dev_vlan_filter_set(struct rte_eth_dev *dev,
97 : : uint16_t vid, int on);
98 : : static int vmxnet3_dev_vlan_offload_set(struct rte_eth_dev *dev, int mask);
99 : : static int vmxnet3_mac_addr_set(struct rte_eth_dev *dev,
100 : : struct rte_ether_addr *mac_addr);
101 : : static void vmxnet3_process_events(struct rte_eth_dev *dev);
102 : : static void vmxnet3_interrupt_handler(void *param);
103 : : static int
104 : : vmxnet3_rss_reta_update(struct rte_eth_dev *dev,
105 : : struct rte_eth_rss_reta_entry64 *reta_conf,
106 : : uint16_t reta_size);
107 : : static int
108 : : vmxnet3_rss_reta_query(struct rte_eth_dev *dev,
109 : : struct rte_eth_rss_reta_entry64 *reta_conf,
110 : : uint16_t reta_size);
111 : :
112 : : static int vmxnet3_dev_rx_queue_intr_enable(struct rte_eth_dev *dev,
113 : : uint16_t queue_id);
114 : : static int vmxnet3_dev_rx_queue_intr_disable(struct rte_eth_dev *dev,
115 : : uint16_t queue_id);
116 : :
117 : : /*
118 : : * The set of PCI devices this driver supports
119 : : */
120 : : #define VMWARE_PCI_VENDOR_ID 0x15AD
121 : : #define VMWARE_DEV_ID_VMXNET3 0x07B0
122 : : static const struct rte_pci_id pci_id_vmxnet3_map[] = {
123 : : { RTE_PCI_DEVICE(VMWARE_PCI_VENDOR_ID, VMWARE_DEV_ID_VMXNET3) },
124 : : { .vendor_id = 0, /* sentinel */ },
125 : : };
126 : :
127 : : static const struct eth_dev_ops vmxnet3_eth_dev_ops = {
128 : : .dev_configure = vmxnet3_dev_configure,
129 : : .dev_start = vmxnet3_dev_start,
130 : : .dev_stop = vmxnet3_dev_stop,
131 : : .dev_close = vmxnet3_dev_close,
132 : : .dev_reset = vmxnet3_dev_reset,
133 : : .link_update = vmxnet3_dev_link_update,
134 : : .promiscuous_enable = vmxnet3_dev_promiscuous_enable,
135 : : .promiscuous_disable = vmxnet3_dev_promiscuous_disable,
136 : : .allmulticast_enable = vmxnet3_dev_allmulticast_enable,
137 : : .allmulticast_disable = vmxnet3_dev_allmulticast_disable,
138 : : .mac_addr_set = vmxnet3_mac_addr_set,
139 : : .mtu_set = vmxnet3_dev_mtu_set,
140 : : .stats_get = vmxnet3_dev_stats_get,
141 : : .stats_reset = vmxnet3_dev_stats_reset,
142 : : .xstats_get = vmxnet3_dev_xstats_get,
143 : : .xstats_get_names = vmxnet3_dev_xstats_get_names,
144 : : .dev_infos_get = vmxnet3_dev_info_get,
145 : : .fw_version_get = vmxnet3_hw_ver_get,
146 : : .dev_supported_ptypes_get = vmxnet3_dev_supported_ptypes_get,
147 : : .vlan_filter_set = vmxnet3_dev_vlan_filter_set,
148 : : .vlan_offload_set = vmxnet3_dev_vlan_offload_set,
149 : : .rx_queue_setup = vmxnet3_dev_rx_queue_setup,
150 : : .rx_queue_release = vmxnet3_dev_rx_queue_release,
151 : : .rx_queue_intr_enable = vmxnet3_dev_rx_queue_intr_enable,
152 : : .rx_queue_intr_disable = vmxnet3_dev_rx_queue_intr_disable,
153 : : .tx_queue_setup = vmxnet3_dev_tx_queue_setup,
154 : : .tx_queue_release = vmxnet3_dev_tx_queue_release,
155 : : .reta_update = vmxnet3_rss_reta_update,
156 : : .reta_query = vmxnet3_rss_reta_query,
157 : : };
158 : :
159 : : struct vmxnet3_xstats_name_off {
160 : : char name[RTE_ETH_XSTATS_NAME_SIZE];
161 : : unsigned int offset;
162 : : };
163 : :
164 : : /* tx_qX_ is prepended to the name string here */
165 : : static const struct vmxnet3_xstats_name_off vmxnet3_txq_stat_strings[] = {
166 : : {"drop_total", offsetof(struct vmxnet3_txq_stats, drop_total)},
167 : : {"drop_too_many_segs", offsetof(struct vmxnet3_txq_stats, drop_too_many_segs)},
168 : : {"drop_tso", offsetof(struct vmxnet3_txq_stats, drop_tso)},
169 : : {"tx_ring_full", offsetof(struct vmxnet3_txq_stats, tx_ring_full)},
170 : : };
171 : :
172 : : /* rx_qX_ is prepended to the name string here */
173 : : static const struct vmxnet3_xstats_name_off vmxnet3_rxq_stat_strings[] = {
174 : : {"drop_total", offsetof(struct vmxnet3_rxq_stats, drop_total)},
175 : : {"drop_err", offsetof(struct vmxnet3_rxq_stats, drop_err)},
176 : : {"drop_fcs", offsetof(struct vmxnet3_rxq_stats, drop_fcs)},
177 : : {"rx_buf_alloc_failure", offsetof(struct vmxnet3_rxq_stats, rx_buf_alloc_failure)},
178 : : };
179 : :
180 : : static const struct rte_memzone *
181 : 0 : gpa_zone_reserve(struct rte_eth_dev *dev, uint32_t size,
182 : : const char *post_string, int socket_id,
183 : : uint16_t align, bool reuse)
184 : : {
185 : : char z_name[RTE_MEMZONE_NAMESIZE];
186 : : const struct rte_memzone *mz;
187 : :
188 : 0 : snprintf(z_name, sizeof(z_name), "eth_p%d_%s",
189 : 0 : dev->data->port_id, post_string);
190 : :
191 : 0 : mz = rte_memzone_lookup(z_name);
192 [ # # ]: 0 : if (!reuse) {
193 : 0 : rte_memzone_free(mz);
194 : 0 : return rte_memzone_reserve_aligned(z_name, size, socket_id,
195 : : RTE_MEMZONE_IOVA_CONTIG, align);
196 : : }
197 : :
198 [ # # ]: 0 : if (mz)
199 : : return mz;
200 : :
201 : 0 : return rte_memzone_reserve_aligned(z_name, size, socket_id,
202 : : RTE_MEMZONE_IOVA_CONTIG, align);
203 : : }
204 : :
205 : : /*
206 : : * Enable the given interrupt
207 : : */
208 : : static void
209 : 0 : vmxnet3_enable_intr(struct vmxnet3_hw *hw, unsigned int intr_idx)
210 : : {
211 : 0 : PMD_INIT_FUNC_TRACE();
212 : 0 : VMXNET3_WRITE_BAR0_REG(hw, VMXNET3_REG_IMR + intr_idx * 8, 0);
213 : 0 : }
214 : :
215 : : /*
216 : : * Disable the given interrupt
217 : : */
218 : : static void
219 : 0 : vmxnet3_disable_intr(struct vmxnet3_hw *hw, unsigned int intr_idx)
220 : : {
221 : 0 : PMD_INIT_FUNC_TRACE();
222 : 0 : VMXNET3_WRITE_BAR0_REG(hw, VMXNET3_REG_IMR + intr_idx * 8, 1);
223 : 0 : }
224 : :
225 : : /*
226 : : * Simple helper to get intrCtrl and eventIntrIdx based on config and hw version
227 : : */
228 : : static void
229 : : vmxnet3_get_intr_ctrl_ev(struct vmxnet3_hw *hw,
230 : : uint8 **out_eventIntrIdx,
231 : : uint32 **out_intrCtrl)
232 : : {
233 : :
234 [ # # # # : 0 : if (VMXNET3_VERSION_GE_6(hw) && hw->queuesExtEnabled) {
# # # # #
# # # ]
235 : 0 : *out_eventIntrIdx = &hw->shared->devReadExt.intrConfExt.eventIntrIdx;
236 : 0 : *out_intrCtrl = &hw->shared->devReadExt.intrConfExt.intrCtrl;
237 : : } else {
238 : 0 : *out_eventIntrIdx = &hw->shared->devRead.intrConf.eventIntrIdx;
239 : 0 : *out_intrCtrl = &hw->shared->devRead.intrConf.intrCtrl;
240 : : }
241 : : }
242 : :
243 : : /*
244 : : * Disable all intrs used by the device
245 : : */
246 : : static void
247 : 0 : vmxnet3_disable_all_intrs(struct vmxnet3_hw *hw)
248 : : {
249 : : int i;
250 : : uint8 *eventIntrIdx;
251 : : uint32 *intrCtrl;
252 : :
253 : 0 : PMD_INIT_FUNC_TRACE();
254 : : vmxnet3_get_intr_ctrl_ev(hw, &eventIntrIdx, &intrCtrl);
255 : :
256 : 0 : *intrCtrl |= rte_cpu_to_le_32(VMXNET3_IC_DISABLE_ALL);
257 : :
258 [ # # ]: 0 : for (i = 0; i < hw->intr.num_intrs; i++)
259 : 0 : vmxnet3_disable_intr(hw, i);
260 : 0 : }
261 : :
262 : : #ifndef RTE_EXEC_ENV_FREEBSD
263 : : /*
264 : : * Enable all intrs used by the device
265 : : */
266 : : static void
267 : 0 : vmxnet3_enable_all_intrs(struct vmxnet3_hw *hw)
268 : : {
269 : : uint8 *eventIntrIdx;
270 : : uint32 *intrCtrl;
271 : :
272 : 0 : PMD_INIT_FUNC_TRACE();
273 : : vmxnet3_get_intr_ctrl_ev(hw, &eventIntrIdx, &intrCtrl);
274 : :
275 : 0 : *intrCtrl &= rte_cpu_to_le_32(~VMXNET3_IC_DISABLE_ALL);
276 : :
277 [ # # ]: 0 : if (hw->intr.lsc_only) {
278 : 0 : vmxnet3_enable_intr(hw, *eventIntrIdx);
279 : : } else {
280 : : int i;
281 : :
282 [ # # ]: 0 : for (i = 0; i < hw->intr.num_intrs; i++)
283 : 0 : vmxnet3_enable_intr(hw, i);
284 : : }
285 : 0 : }
286 : : #endif
287 : :
288 : : /*
289 : : * Gets tx data ring descriptor size.
290 : : */
291 : : static uint16_t
292 : : eth_vmxnet3_txdata_get(struct vmxnet3_hw *hw)
293 : : {
294 : : uint16 txdata_desc_size;
295 : :
296 : 0 : VMXNET3_WRITE_BAR1_REG(hw, VMXNET3_REG_CMD,
297 : : VMXNET3_CMD_GET_TXDATA_DESC_SIZE);
298 : 0 : txdata_desc_size = VMXNET3_READ_BAR1_REG(hw, VMXNET3_REG_CMD);
299 : :
300 : 0 : return (txdata_desc_size < VMXNET3_TXDATA_DESC_MIN_SIZE ||
301 : 0 : txdata_desc_size > VMXNET3_TXDATA_DESC_MAX_SIZE ||
302 [ # # ]: 0 : txdata_desc_size & VMXNET3_TXDATA_DESC_SIZE_MASK) ?
303 [ # # ]: 0 : sizeof(struct Vmxnet3_TxDataDesc) : txdata_desc_size;
304 : : }
305 : :
306 : : static int
307 : 0 : eth_vmxnet3_setup_capabilities(struct vmxnet3_hw *hw,
308 : : struct rte_eth_dev *eth_dev)
309 : : {
310 : : uint32_t dcr, ptcr, value;
311 : 0 : struct rte_pci_device *pci_dev = RTE_ETH_DEV_TO_PCI(eth_dev);
312 : :
313 : 0 : VMXNET3_WRITE_BAR1_REG(hw, VMXNET3_REG_CMD,
314 : : VMXNET3_CMD_GET_MAX_CAPABILITIES);
315 : 0 : value = VMXNET3_READ_BAR1_REG(hw, VMXNET3_REG_CMD);
316 : 0 : hw->max_capabilities[0] = value;
317 : 0 : dcr = VMXNET3_READ_BAR1_REG(hw, VMXNET3_REG_DCR);
318 : 0 : hw->DCR_capabilities[0] = dcr;
319 : 0 : hw->used_DCR_capabilities[0] = 0;
320 : 0 : ptcr = VMXNET3_READ_BAR1_REG(hw, VMXNET3_REG_PTCR);
321 : 0 : hw->PTCR_capabilities[0] = ptcr;
322 : 0 : hw->used_PTCR_capabilities[0] = 0;
323 : :
324 [ # # # # ]: 0 : if (hw->uptv2_enabled && !(ptcr & (1 << VMXNET3_DCR_ERROR))) {
325 : 0 : PMD_DRV_LOG(NOTICE, "UPTv2 enabled");
326 : 0 : hw->used_PTCR_capabilities[0] = ptcr;
327 : : } else {
328 : : /* Use all DCR capabilities, but disable large bar */
329 : 0 : hw->used_DCR_capabilities[0] = dcr &
330 : : (~(1UL << VMXNET3_CAP_LARGE_BAR));
331 : 0 : PMD_DRV_LOG(NOTICE, "UPTv2 disabled");
332 : : }
333 [ # # ]: 0 : if (hw->DCR_capabilities[0] & (1UL << VMXNET3_CAP_OOORX_COMP) &&
334 [ # # ]: 0 : hw->PTCR_capabilities[0] & (1UL << VMXNET3_CAP_OOORX_COMP)) {
335 [ # # ]: 0 : if (hw->uptv2_enabled) {
336 : 0 : hw->used_PTCR_capabilities[0] |=
337 : : (1UL << VMXNET3_CAP_OOORX_COMP);
338 : : }
339 : : }
340 [ # # ]: 0 : if (hw->used_PTCR_capabilities[0]) {
341 : 0 : VMXNET3_WRITE_BAR1_REG(hw, VMXNET3_REG_DCR,
342 : : hw->used_PTCR_capabilities[0]);
343 [ # # ]: 0 : } else if (hw->used_DCR_capabilities[0]) {
344 : 0 : VMXNET3_WRITE_BAR1_REG(hw, VMXNET3_REG_DCR,
345 : : hw->used_DCR_capabilities[0]);
346 : : }
347 : 0 : VMXNET3_WRITE_BAR1_REG(hw, VMXNET3_REG_CMD, VMXNET3_CMD_GET_DCR0_REG);
348 : 0 : dcr = VMXNET3_READ_BAR1_REG(hw, VMXNET3_REG_CMD);
349 : 0 : hw->used_DCR_capabilities[0] = dcr;
350 [ # # ]: 0 : PMD_DRV_LOG(DEBUG, "Dev " PCI_PRI_FMT ", vmxnet3 v%d, UPT enabled: %s, "
351 : : "DCR0=0x%08x, used DCR=0x%08x, "
352 : : "PTCR=0x%08x, used PTCR=0x%08x",
353 : : pci_dev->addr.domain, pci_dev->addr.bus,
354 : : pci_dev->addr.devid, pci_dev->addr.function, hw->version,
355 : : hw->uptv2_enabled ? "true" : "false",
356 : : hw->DCR_capabilities[0], hw->used_DCR_capabilities[0],
357 : : hw->PTCR_capabilities[0], hw->used_PTCR_capabilities[0]);
358 : 0 : return 0;
359 : : }
360 : :
361 : : /*
362 : : * It returns 0 on success.
363 : : */
364 : : static int
365 : 0 : eth_vmxnet3_dev_init(struct rte_eth_dev *eth_dev)
366 : : {
367 : : struct rte_pci_device *pci_dev;
368 : 0 : struct vmxnet3_hw *hw = eth_dev->data->dev_private;
369 : : uint32_t mac_hi, mac_lo, ver;
370 : : struct rte_eth_link link;
371 : : static const struct rte_mbuf_dynfield vmxnet3_segs_dynfield_desc = {
372 : : .name = VMXNET3_SEGS_DYNFIELD_NAME,
373 : : .size = sizeof(vmxnet3_segs_dynfield_t),
374 : : .align = alignof(vmxnet3_segs_dynfield_t),
375 : : };
376 : :
377 : 0 : PMD_INIT_FUNC_TRACE();
378 : :
379 : 0 : eth_dev->dev_ops = &vmxnet3_eth_dev_ops;
380 : 0 : eth_dev->rx_pkt_burst = &vmxnet3_recv_pkts;
381 : 0 : eth_dev->tx_pkt_burst = &vmxnet3_xmit_pkts;
382 : 0 : eth_dev->tx_pkt_prepare = vmxnet3_prep_pkts;
383 : 0 : eth_dev->rx_queue_count = vmxnet3_dev_rx_queue_count;
384 : 0 : pci_dev = RTE_ETH_DEV_TO_PCI(eth_dev);
385 : :
386 : : /* extra mbuf field is required to guess MSS */
387 : 0 : vmxnet3_segs_dynfield_offset =
388 : 0 : rte_mbuf_dynfield_register(&vmxnet3_segs_dynfield_desc);
389 [ # # ]: 0 : if (vmxnet3_segs_dynfield_offset < 0) {
390 : 0 : PMD_INIT_LOG(ERR, "Cannot register mbuf field.");
391 : 0 : return -rte_errno;
392 : : }
393 : :
394 : : /*
395 : : * for secondary processes, we don't initialize any further as primary
396 : : * has already done this work.
397 : : */
398 [ # # ]: 0 : if (rte_eal_process_type() != RTE_PROC_PRIMARY)
399 : : return 0;
400 : :
401 : 0 : rte_eth_copy_pci_info(eth_dev, pci_dev);
402 : 0 : eth_dev->data->dev_flags |= RTE_ETH_DEV_AUTOFILL_QUEUE_XSTATS;
403 : :
404 : : /* Vendor and Device ID need to be set before init of shared code */
405 : 0 : hw->device_id = pci_dev->id.device_id;
406 : 0 : hw->vendor_id = pci_dev->id.vendor_id;
407 : 0 : hw->adapter_stopped = TRUE;
408 : 0 : hw->hw_addr0 = (void *)pci_dev->mem_resource[0].addr;
409 : 0 : hw->hw_addr1 = (void *)pci_dev->mem_resource[1].addr;
410 : :
411 : 0 : hw->num_rx_queues = 1;
412 : 0 : hw->num_tx_queues = 1;
413 : 0 : hw->bufs_per_pkt = 1;
414 : :
415 : : /* Check h/w version compatibility with driver. */
416 : : ver = VMXNET3_READ_BAR1_REG(hw, VMXNET3_REG_VRRS);
417 : :
418 [ # # ]: 0 : if (ver & (1 << VMXNET3_REV_7)) {
419 : 0 : VMXNET3_WRITE_BAR1_REG(hw, VMXNET3_REG_VRRS,
420 : : 1 << VMXNET3_REV_7);
421 : 0 : hw->version = VMXNET3_REV_7 + 1;
422 [ # # ]: 0 : } else if (ver & (1 << VMXNET3_REV_6)) {
423 : 0 : VMXNET3_WRITE_BAR1_REG(hw, VMXNET3_REG_VRRS,
424 : : 1 << VMXNET3_REV_6);
425 : 0 : hw->version = VMXNET3_REV_6 + 1;
426 [ # # ]: 0 : } else if (ver & (1 << VMXNET3_REV_5)) {
427 : 0 : VMXNET3_WRITE_BAR1_REG(hw, VMXNET3_REG_VRRS,
428 : : 1 << VMXNET3_REV_5);
429 : 0 : hw->version = VMXNET3_REV_5 + 1;
430 [ # # ]: 0 : } else if (ver & (1 << VMXNET3_REV_4)) {
431 : 0 : VMXNET3_WRITE_BAR1_REG(hw, VMXNET3_REG_VRRS,
432 : : 1 << VMXNET3_REV_4);
433 : 0 : hw->version = VMXNET3_REV_4 + 1;
434 [ # # ]: 0 : } else if (ver & (1 << VMXNET3_REV_3)) {
435 : 0 : VMXNET3_WRITE_BAR1_REG(hw, VMXNET3_REG_VRRS,
436 : : 1 << VMXNET3_REV_3);
437 : 0 : hw->version = VMXNET3_REV_3 + 1;
438 [ # # ]: 0 : } else if (ver & (1 << VMXNET3_REV_2)) {
439 : 0 : VMXNET3_WRITE_BAR1_REG(hw, VMXNET3_REG_VRRS,
440 : : 1 << VMXNET3_REV_2);
441 : 0 : hw->version = VMXNET3_REV_2 + 1;
442 [ # # ]: 0 : } else if (ver & (1 << VMXNET3_REV_1)) {
443 : 0 : VMXNET3_WRITE_BAR1_REG(hw, VMXNET3_REG_VRRS,
444 : : 1 << VMXNET3_REV_1);
445 : 0 : hw->version = VMXNET3_REV_1 + 1;
446 : : } else {
447 : 0 : PMD_INIT_LOG(ERR, "Incompatible hardware version: %d", ver);
448 : 0 : return -EIO;
449 : : }
450 : :
451 : 0 : PMD_INIT_LOG(INFO, "Using device v%d", hw->version);
452 : :
453 : : /* Check UPT version compatibility with driver. */
454 : 0 : ver = VMXNET3_READ_BAR1_REG(hw, VMXNET3_REG_UVRS);
455 : 0 : PMD_INIT_LOG(DEBUG, "UPT hardware version : %d", ver);
456 [ # # ]: 0 : if (ver & 0x1)
457 : 0 : VMXNET3_WRITE_BAR1_REG(hw, VMXNET3_REG_UVRS, 1);
458 : : else {
459 : 0 : PMD_INIT_LOG(ERR, "Incompatible UPT version.");
460 : 0 : return -EIO;
461 : : }
462 : :
463 [ # # ]: 0 : if (VMXNET3_VERSION_GE_7(hw)) {
464 : : /* start with UPTv2 enabled to avoid ESXi issues */
465 : 0 : hw->uptv2_enabled = TRUE;
466 : 0 : eth_vmxnet3_setup_capabilities(hw, eth_dev);
467 : : }
468 : :
469 [ # # ]: 0 : if (hw->used_DCR_capabilities[0] & (1 << VMXNET3_CAP_LARGE_BAR)) {
470 : 0 : hw->tx_prod_offset = VMXNET3_REG_LB_TXPROD;
471 : 0 : hw->rx_prod_offset[0] = VMXNET3_REG_LB_RXPROD;
472 : 0 : hw->rx_prod_offset[1] = VMXNET3_REG_LB_RXPROD2;
473 : : } else {
474 : 0 : hw->tx_prod_offset = VMXNET3_REG_TXPROD;
475 : 0 : hw->rx_prod_offset[0] = VMXNET3_REG_RXPROD;
476 : 0 : hw->rx_prod_offset[1] = VMXNET3_REG_RXPROD2;
477 : : }
478 : :
479 : : /* Getting MAC Address */
480 : 0 : mac_lo = VMXNET3_READ_BAR1_REG(hw, VMXNET3_REG_MACL);
481 : 0 : mac_hi = VMXNET3_READ_BAR1_REG(hw, VMXNET3_REG_MACH);
482 : 0 : memcpy(hw->perm_addr, &mac_lo, 4);
483 : 0 : memcpy(hw->perm_addr + 4, &mac_hi, 2);
484 : :
485 : : /* Allocate memory for storing MAC addresses */
486 : 0 : eth_dev->data->mac_addrs = rte_zmalloc("vmxnet3", RTE_ETHER_ADDR_LEN *
487 : : VMXNET3_MAX_MAC_ADDRS, 0);
488 [ # # ]: 0 : if (eth_dev->data->mac_addrs == NULL) {
489 : 0 : PMD_INIT_LOG(ERR,
490 : : "Failed to allocate %d bytes needed to store MAC addresses",
491 : : RTE_ETHER_ADDR_LEN * VMXNET3_MAX_MAC_ADDRS);
492 : 0 : return -ENOMEM;
493 : : }
494 : : /* Copy the permanent MAC address */
495 : : rte_ether_addr_copy((struct rte_ether_addr *)hw->perm_addr,
496 : : ð_dev->data->mac_addrs[0]);
497 : :
498 : 0 : PMD_INIT_LOG(DEBUG, "MAC Address : " RTE_ETHER_ADDR_PRT_FMT,
499 : : hw->perm_addr[0], hw->perm_addr[1], hw->perm_addr[2],
500 : : hw->perm_addr[3], hw->perm_addr[4], hw->perm_addr[5]);
501 : :
502 : : /* Put device in Quiesce Mode */
503 : 0 : VMXNET3_WRITE_BAR1_REG(hw, VMXNET3_REG_CMD, VMXNET3_CMD_QUIESCE_DEV);
504 : :
505 : : /* allow untagged pkts */
506 : 0 : VMXNET3_SET_VFTABLE_ENTRY(hw->shadow_vfta, 0);
507 : :
508 [ # # ]: 0 : hw->txdata_desc_size = VMXNET3_VERSION_GE_3(hw) ?
509 : : eth_vmxnet3_txdata_get(hw) : sizeof(struct Vmxnet3_TxDataDesc);
510 : :
511 [ # # ]: 0 : hw->rxdata_desc_size = VMXNET3_VERSION_GE_3(hw) ?
512 : : VMXNET3_DEF_RXDATA_DESC_SIZE : 0;
513 : : RTE_ASSERT((hw->rxdata_desc_size & ~VMXNET3_RXDATA_DESC_SIZE_MASK) ==
514 : : hw->rxdata_desc_size);
515 : :
516 : : /* clear shadow stats */
517 : 0 : memset(hw->saved_tx_stats, 0, sizeof(hw->saved_tx_stats));
518 : 0 : memset(hw->saved_rx_stats, 0, sizeof(hw->saved_rx_stats));
519 : :
520 : : /* clear snapshot stats */
521 : 0 : memset(hw->snapshot_tx_stats, 0, sizeof(hw->snapshot_tx_stats));
522 : 0 : memset(hw->snapshot_rx_stats, 0, sizeof(hw->snapshot_rx_stats));
523 : :
524 : : /* set the initial link status */
525 : : memset(&link, 0, sizeof(link));
526 : 0 : link.link_duplex = RTE_ETH_LINK_FULL_DUPLEX;
527 : 0 : link.link_speed = RTE_ETH_SPEED_NUM_10G;
528 : : link.link_autoneg = RTE_ETH_LINK_FIXED;
529 : 0 : rte_eth_linkstatus_set(eth_dev, &link);
530 : :
531 : 0 : return 0;
532 : : }
533 : :
534 : : static int
535 : 0 : eth_vmxnet3_dev_uninit(struct rte_eth_dev *eth_dev)
536 : : {
537 : 0 : struct vmxnet3_hw *hw = eth_dev->data->dev_private;
538 : :
539 : 0 : PMD_INIT_FUNC_TRACE();
540 : :
541 [ # # ]: 0 : if (rte_eal_process_type() != RTE_PROC_PRIMARY)
542 : : return 0;
543 : :
544 [ # # ]: 0 : if (hw->adapter_stopped == 0) {
545 : 0 : PMD_INIT_LOG(DEBUG, "Device has not been closed.");
546 : 0 : return -EBUSY;
547 : : }
548 : :
549 : : return 0;
550 : : }
551 : :
552 : 0 : static int eth_vmxnet3_pci_probe(struct rte_pci_driver *pci_drv __rte_unused,
553 : : struct rte_pci_device *pci_dev)
554 : : {
555 : 0 : return rte_eth_dev_pci_generic_probe(pci_dev,
556 : : sizeof(struct vmxnet3_hw), eth_vmxnet3_dev_init);
557 : : }
558 : :
559 : 0 : static int eth_vmxnet3_pci_remove(struct rte_pci_device *pci_dev)
560 : : {
561 : 0 : return rte_eth_dev_pci_generic_remove(pci_dev, eth_vmxnet3_dev_uninit);
562 : : }
563 : :
564 : : static struct rte_pci_driver rte_vmxnet3_pmd = {
565 : : .id_table = pci_id_vmxnet3_map,
566 : : .drv_flags = RTE_PCI_DRV_NEED_MAPPING | RTE_PCI_DRV_INTR_LSC,
567 : : .probe = eth_vmxnet3_pci_probe,
568 : : .remove = eth_vmxnet3_pci_remove,
569 : : };
570 : :
571 : : static void
572 : 0 : vmxnet3_alloc_intr_resources(struct rte_eth_dev *dev)
573 : : {
574 : 0 : struct vmxnet3_hw *hw = dev->data->dev_private;
575 : : uint32_t cfg;
576 : : int nvec = 1; /* for link event */
577 : :
578 : : /* intr settings */
579 : 0 : VMXNET3_WRITE_BAR1_REG(hw, VMXNET3_REG_CMD,
580 : : VMXNET3_CMD_GET_CONF_INTR);
581 : 0 : cfg = VMXNET3_READ_BAR1_REG(hw, VMXNET3_REG_CMD);
582 : 0 : hw->intr.type = cfg & 0x3;
583 : 0 : hw->intr.mask_mode = (cfg >> 2) & 0x3;
584 : :
585 [ # # ]: 0 : if (hw->intr.type == VMXNET3_IT_AUTO)
586 : 0 : hw->intr.type = VMXNET3_IT_MSIX;
587 : :
588 [ # # ]: 0 : if (hw->intr.type == VMXNET3_IT_MSIX) {
589 : : /* only support shared tx/rx intr */
590 [ # # ]: 0 : if (hw->num_tx_queues != hw->num_rx_queues)
591 : 0 : goto msix_err;
592 : :
593 : : nvec += hw->num_rx_queues;
594 : 0 : hw->intr.num_intrs = nvec;
595 : 0 : return;
596 : : }
597 : :
598 : 0 : msix_err:
599 : : /* the tx/rx queue interrupt will be disabled */
600 : 0 : hw->intr.num_intrs = 2;
601 : 0 : hw->intr.lsc_only = TRUE;
602 : 0 : PMD_INIT_LOG(INFO, "Enabled MSI-X with %d vectors", hw->intr.num_intrs);
603 : : }
604 : :
605 : : static int
606 : 0 : vmxnet3_dev_configure(struct rte_eth_dev *dev)
607 : : {
608 : : const struct rte_memzone *mz;
609 : 0 : struct vmxnet3_hw *hw = dev->data->dev_private;
610 : : size_t size;
611 : :
612 : 0 : PMD_INIT_FUNC_TRACE();
613 : :
614 : : /* Disabling RSS for single queue pair */
615 [ # # ]: 0 : if (dev->data->nb_rx_queues == 1 &&
616 [ # # ]: 0 : dev->data->dev_conf.rxmode.mq_mode == RTE_ETH_MQ_RX_RSS) {
617 : 0 : dev->data->dev_conf.rxmode.mq_mode = RTE_ETH_MQ_RX_NONE;
618 : 0 : PMD_INIT_LOG(ERR, "WARN: Disabling RSS for single Rx queue");
619 : : }
620 : :
621 [ # # ]: 0 : if (dev->data->dev_conf.rxmode.mq_mode & RTE_ETH_MQ_RX_RSS_FLAG)
622 : 0 : dev->data->dev_conf.rxmode.offloads |= RTE_ETH_RX_OFFLOAD_RSS_HASH;
623 : :
624 [ # # ]: 0 : if (!VMXNET3_VERSION_GE_6(hw)) {
625 [ # # ]: 0 : if (!rte_is_power_of_2(dev->data->nb_rx_queues)) {
626 : 0 : PMD_INIT_LOG(ERR,
627 : : "ERROR: Number of rx queues not power of 2");
628 : 0 : return -EINVAL;
629 : : }
630 : : }
631 : :
632 : : /* At this point, the number of queues requested has already
633 : : * been validated against dev_infos max queues by EAL
634 : : */
635 [ # # ]: 0 : if (dev->data->nb_rx_queues > VMXNET3_MAX_RX_QUEUES ||
636 [ # # ]: 0 : dev->data->nb_tx_queues > VMXNET3_MAX_TX_QUEUES) {
637 : 0 : hw->queuesExtEnabled = 1;
638 : : } else {
639 : 0 : hw->queuesExtEnabled = 0;
640 : : }
641 : :
642 : 0 : size = dev->data->nb_rx_queues * sizeof(struct Vmxnet3_TxQueueDesc) +
643 : 0 : dev->data->nb_tx_queues * sizeof(struct Vmxnet3_RxQueueDesc);
644 : :
645 [ # # ]: 0 : if (size > UINT16_MAX)
646 : : return -EINVAL;
647 : :
648 : 0 : hw->num_rx_queues = (uint8_t)dev->data->nb_rx_queues;
649 : 0 : hw->num_tx_queues = (uint8_t)dev->data->nb_tx_queues;
650 : :
651 : : /*
652 : : * Allocate a memzone for Vmxnet3_DriverShared - Vmxnet3_DSDevRead
653 : : * on current socket
654 : : */
655 : 0 : mz = gpa_zone_reserve(dev, sizeof(struct Vmxnet3_DriverShared),
656 : 0 : "shared", rte_socket_id(), 8, 1);
657 : :
658 [ # # ]: 0 : if (mz == NULL) {
659 : 0 : PMD_INIT_LOG(ERR, "ERROR: Creating shared zone");
660 : 0 : return -ENOMEM;
661 : : }
662 : 0 : memset(mz->addr, 0, mz->len);
663 : :
664 : 0 : hw->shared = mz->addr;
665 : 0 : hw->sharedPA = mz->iova;
666 : :
667 : : /*
668 : : * Allocate a memzone for Vmxnet3_RxQueueDesc - Vmxnet3_TxQueueDesc
669 : : * on current socket.
670 : : *
671 : : * We cannot reuse this memzone from previous allocation as its size
672 : : * depends on the number of tx and rx queues, which could be different
673 : : * from one config to another.
674 : : */
675 : 0 : mz = gpa_zone_reserve(dev, size, "queuedesc", rte_socket_id(),
676 : : VMXNET3_QUEUE_DESC_ALIGN, 0);
677 [ # # ]: 0 : if (mz == NULL) {
678 : 0 : PMD_INIT_LOG(ERR, "ERROR: Creating queue descriptors zone");
679 : 0 : return -ENOMEM;
680 : : }
681 [ # # ]: 0 : memset(mz->addr, 0, mz->len);
682 : :
683 : 0 : hw->tqd_start = (Vmxnet3_TxQueueDesc *)mz->addr;
684 : 0 : hw->rqd_start = (Vmxnet3_RxQueueDesc *)(hw->tqd_start + hw->num_tx_queues);
685 : :
686 : 0 : hw->queueDescPA = mz->iova;
687 : 0 : hw->queue_desc_len = (uint16_t)size;
688 : :
689 [ # # ]: 0 : if (dev->data->dev_conf.rxmode.mq_mode == RTE_ETH_MQ_RX_RSS) {
690 : : /* Allocate memory structure for UPT1_RSSConf and configure */
691 : 0 : mz = gpa_zone_reserve(dev, sizeof(struct VMXNET3_RSSConf),
692 : 0 : "rss_conf", rte_socket_id(),
693 : : RTE_CACHE_LINE_SIZE, 1);
694 [ # # ]: 0 : if (mz == NULL) {
695 : 0 : PMD_INIT_LOG(ERR,
696 : : "ERROR: Creating rss_conf structure zone");
697 : 0 : return -ENOMEM;
698 : : }
699 : 0 : memset(mz->addr, 0, mz->len);
700 : :
701 : 0 : hw->rss_conf = mz->addr;
702 : 0 : hw->rss_confPA = mz->iova;
703 : : }
704 : :
705 : 0 : vmxnet3_alloc_intr_resources(dev);
706 : :
707 : 0 : return 0;
708 : : }
709 : :
710 : : static void
711 : 0 : vmxnet3_write_mac(struct vmxnet3_hw *hw, const uint8_t *addr)
712 : : {
713 : : uint32_t val;
714 : :
715 : 0 : PMD_INIT_LOG(DEBUG,
716 : : "Writing MAC Address : " RTE_ETHER_ADDR_PRT_FMT,
717 : : addr[0], addr[1], addr[2],
718 : : addr[3], addr[4], addr[5]);
719 : :
720 : : memcpy(&val, addr, 4);
721 : 0 : VMXNET3_WRITE_BAR1_REG(hw, VMXNET3_REG_MACL, val);
722 : :
723 : : memcpy(&val, addr + 4, 2);
724 : 0 : VMXNET3_WRITE_BAR1_REG(hw, VMXNET3_REG_MACH, val);
725 : 0 : }
726 : :
727 : : /*
728 : : * Configure the hardware to generate MSI-X interrupts.
729 : : * If setting up MSIx fails, try setting up MSI (only 1 interrupt vector
730 : : * which will be disabled to allow lsc to work).
731 : : *
732 : : * Returns 0 on success and -1 otherwise.
733 : : */
734 : : static int
735 : 0 : vmxnet3_configure_msix(struct rte_eth_dev *dev)
736 : : {
737 : 0 : struct vmxnet3_hw *hw = dev->data->dev_private;
738 : 0 : struct rte_intr_handle *intr_handle = dev->intr_handle;
739 : : uint16_t intr_vector;
740 : : int i;
741 : :
742 : 0 : hw->intr.event_intr_idx = 0;
743 : :
744 : : /* only vfio-pci driver can support interrupt mode. */
745 [ # # ]: 0 : if (!rte_intr_cap_multiple(intr_handle) ||
746 [ # # ]: 0 : dev->data->dev_conf.intr_conf.rxq == 0)
747 : : return -1;
748 : :
749 : 0 : intr_vector = dev->data->nb_rx_queues;
750 [ # # # # ]: 0 : if (intr_vector > MAX_RX_QUEUES(hw)) {
751 : 0 : PMD_INIT_LOG(ERR, "At most %d intr queues supported",
752 : : MAX_RX_QUEUES(hw));
753 : 0 : return -ENOTSUP;
754 : : }
755 : :
756 [ # # ]: 0 : if (rte_intr_efd_enable(intr_handle, intr_vector)) {
757 : 0 : PMD_INIT_LOG(ERR, "Failed to enable fastpath event fd");
758 : 0 : return -1;
759 : : }
760 : :
761 [ # # ]: 0 : if (rte_intr_dp_is_en(intr_handle)) {
762 [ # # ]: 0 : if (rte_intr_vec_list_alloc(intr_handle, "intr_vec",
763 : 0 : dev->data->nb_rx_queues)) {
764 : 0 : PMD_INIT_LOG(ERR, "Failed to allocate %d Rx queues intr_vec",
765 : : dev->data->nb_rx_queues);
766 : 0 : rte_intr_efd_disable(intr_handle);
767 : 0 : return -ENOMEM;
768 : : }
769 : : }
770 : :
771 [ # # ]: 0 : if (!rte_intr_allow_others(intr_handle) &&
772 [ # # ]: 0 : dev->data->dev_conf.intr_conf.lsc != 0) {
773 : 0 : PMD_INIT_LOG(ERR, "not enough intr vector to support both Rx interrupt and LSC");
774 : 0 : rte_intr_vec_list_free(intr_handle);
775 : 0 : rte_intr_efd_disable(intr_handle);
776 : 0 : return -1;
777 : : }
778 : :
779 : : /* if we cannot allocate one MSI-X vector per queue, don't enable
780 : : * interrupt mode.
781 : : */
782 : 0 : if (hw->intr.num_intrs !=
783 [ # # ]: 0 : (rte_intr_nb_efd_get(intr_handle) + 1)) {
784 : 0 : PMD_INIT_LOG(ERR, "Device configured with %d Rx intr vectors, expecting %d",
785 : : hw->intr.num_intrs,
786 : : rte_intr_nb_efd_get(intr_handle) + 1);
787 : 0 : rte_intr_vec_list_free(intr_handle);
788 : 0 : rte_intr_efd_disable(intr_handle);
789 : 0 : return -1;
790 : : }
791 : :
792 [ # # ]: 0 : for (i = 0; i < dev->data->nb_rx_queues; i++)
793 [ # # ]: 0 : if (rte_intr_vec_list_index_set(intr_handle, i, i + 1))
794 : 0 : return -rte_errno;
795 : :
796 [ # # ]: 0 : for (i = 0; i < hw->intr.num_intrs; i++)
797 : 0 : hw->intr.mod_levels[i] = UPT1_IML_ADAPTIVE;
798 : :
799 : 0 : PMD_INIT_LOG(INFO, "intr type %u, mode %u, %u vectors allocated",
800 : : hw->intr.type, hw->intr.mask_mode, hw->intr.num_intrs);
801 : :
802 : 0 : return 0;
803 : : }
804 : :
805 : : static int
806 : 0 : vmxnet3_dev_setup_memreg(struct rte_eth_dev *dev)
807 : : {
808 : 0 : struct vmxnet3_hw *hw = dev->data->dev_private;
809 : 0 : Vmxnet3_DriverShared *shared = hw->shared;
810 : : Vmxnet3_CmdInfo *cmdInfo;
811 : : struct rte_mempool *mp[VMXNET3_MAX_RX_QUEUES];
812 : : uint16_t index[VMXNET3_MAX_MEMREG_QUEUES];
813 : : uint16_t tx_index_mask;
814 : : uint32_t num, tx_num, i, j, size;
815 : :
816 [ # # ]: 0 : if (hw->memRegsPA == 0) {
817 : : const struct rte_memzone *mz;
818 : :
819 : : size = sizeof(Vmxnet3_MemRegs) +
820 : : (2 * VMXNET3_MAX_MEMREG_QUEUES) *
821 : : sizeof(Vmxnet3_MemoryRegion);
822 : :
823 : 0 : mz = gpa_zone_reserve(dev, size, "memRegs", rte_socket_id(), 8,
824 : : 1);
825 [ # # ]: 0 : if (mz == NULL) {
826 : 0 : PMD_INIT_LOG(ERR, "ERROR: Creating memRegs zone");
827 : 0 : return -ENOMEM;
828 : : }
829 : 0 : memset(mz->addr, 0, mz->len);
830 : 0 : hw->memRegs = mz->addr;
831 : 0 : hw->memRegsPA = mz->iova;
832 : : }
833 : :
834 : 0 : num = RTE_MIN(hw->num_rx_queues, VMXNET3_MAX_MEMREG_QUEUES);
835 : 0 : tx_num = RTE_MIN(hw->num_tx_queues, VMXNET3_MAX_MEMREG_QUEUES);
836 : 0 : tx_index_mask = (uint16_t)((1UL << tx_num) - 1);
837 : :
838 [ # # ]: 0 : for (i = 0; i < num; i++) {
839 : 0 : vmxnet3_rx_queue_t *rxq = dev->data->rx_queues[i];
840 : :
841 : 0 : mp[i] = rxq->mp;
842 : 0 : index[i] = 1 << i;
843 : : }
844 : :
845 : : /*
846 : : * The same mempool could be used by multiple queues. In such a case,
847 : : * remove duplicate mempool entries. Only one entry is kept with
848 : : * bitmask indicating queues that are using this mempool.
849 : : */
850 [ # # ]: 0 : for (i = 1; i < num; i++) {
851 [ # # ]: 0 : for (j = 0; j < i; j++) {
852 [ # # ]: 0 : if (mp[i] == mp[j]) {
853 : 0 : mp[i] = NULL;
854 : 0 : index[j] |= 1 << i;
855 : 0 : break;
856 : : }
857 : : }
858 : : }
859 : :
860 : : j = 0;
861 [ # # ]: 0 : for (i = 0; i < num; i++) {
862 [ # # ]: 0 : if (mp[i] == NULL)
863 : 0 : continue;
864 : :
865 : 0 : Vmxnet3_MemoryRegion *mr = &hw->memRegs->memRegs[j];
866 : :
867 : 0 : mr->startPA =
868 : 0 : (uintptr_t)STAILQ_FIRST(&mp[i]->mem_list)->iova;
869 : 0 : mr->length = STAILQ_FIRST(&mp[i]->mem_list)->len <= INT32_MAX ?
870 : 0 : STAILQ_FIRST(&mp[i]->mem_list)->len : INT32_MAX;
871 : 0 : mr->rxQueueBits = index[i];
872 : : /* tx uses same pool, but there may be fewer tx queues */
873 : 0 : mr->txQueueBits = index[i] & tx_index_mask;
874 : :
875 : 0 : PMD_INIT_LOG(INFO,
876 : : "index: %u startPA: %" PRIu64 " length: %u, "
877 : : "rxBits: %x, txBits: %x",
878 : : j, mr->startPA, mr->length,
879 : : mr->rxQueueBits, mr->txQueueBits);
880 : 0 : j++;
881 : : }
882 : 0 : hw->memRegs->numRegs = j;
883 : 0 : PMD_INIT_LOG(INFO, "numRegs: %u", j);
884 : :
885 : 0 : size = sizeof(Vmxnet3_MemRegs) +
886 : 0 : (j - 1) * sizeof(Vmxnet3_MemoryRegion);
887 : :
888 : : cmdInfo = &shared->cu.cmdInfo;
889 : 0 : cmdInfo->varConf.confVer = 1;
890 : 0 : cmdInfo->varConf.confLen = size;
891 : 0 : cmdInfo->varConf.confPA = hw->memRegsPA;
892 : :
893 : 0 : return 0;
894 : : }
895 : :
896 : : static int
897 : 0 : vmxnet3_setup_driver_shared(struct rte_eth_dev *dev)
898 : : {
899 : 0 : struct rte_eth_conf port_conf = dev->data->dev_conf;
900 : 0 : struct vmxnet3_hw *hw = dev->data->dev_private;
901 : 0 : struct rte_intr_handle *intr_handle = dev->intr_handle;
902 : 0 : uint32_t mtu = dev->data->mtu;
903 : 0 : Vmxnet3_DriverShared *shared = hw->shared;
904 : : Vmxnet3_DSDevRead *devRead = &shared->devRead;
905 : : struct Vmxnet3_DSDevReadExt *devReadExt = &shared->devReadExt;
906 : 0 : uint64_t rx_offloads = dev->data->dev_conf.rxmode.offloads;
907 : : uint32_t i;
908 : : int ret;
909 : :
910 : 0 : hw->mtu = mtu;
911 : :
912 : 0 : shared->magic = VMXNET3_REV1_MAGIC;
913 : 0 : devRead->misc.driverInfo.version = VMXNET3_DRIVER_VERSION_NUM;
914 : :
915 : : /* Setting up Guest OS information */
916 : 0 : devRead->misc.driverInfo.gos.gosBits = sizeof(void *) == 4 ?
917 : : VMXNET3_GOS_BITS_32 : VMXNET3_GOS_BITS_64;
918 : 0 : devRead->misc.driverInfo.gos.gosType = VMXNET3_GOS_TYPE_LINUX;
919 : 0 : devRead->misc.driverInfo.vmxnet3RevSpt = 1;
920 : 0 : devRead->misc.driverInfo.uptVerSpt = 1;
921 : :
922 : 0 : devRead->misc.mtu = rte_le_to_cpu_32(mtu);
923 : 0 : devRead->misc.queueDescPA = hw->queueDescPA;
924 : 0 : devRead->misc.queueDescLen = hw->queue_desc_len;
925 : 0 : devRead->misc.numTxQueues = hw->num_tx_queues;
926 : 0 : devRead->misc.numRxQueues = hw->num_rx_queues;
927 : :
928 [ # # ]: 0 : for (i = 0; i < hw->num_tx_queues; i++) {
929 : 0 : Vmxnet3_TxQueueDesc *tqd = &hw->tqd_start[i];
930 : 0 : vmxnet3_tx_queue_t *txq = dev->data->tx_queues[i];
931 : :
932 : 0 : txq->shared = &hw->tqd_start[i];
933 : :
934 : 0 : tqd->ctrl.txNumDeferred = 0;
935 : 0 : tqd->ctrl.txThreshold = 1;
936 : 0 : tqd->conf.txRingBasePA = txq->cmd_ring.basePA;
937 : 0 : tqd->conf.compRingBasePA = txq->comp_ring.basePA;
938 : 0 : tqd->conf.dataRingBasePA = txq->data_ring.basePA;
939 : :
940 : 0 : tqd->conf.txRingSize = txq->cmd_ring.size;
941 : 0 : tqd->conf.compRingSize = txq->comp_ring.size;
942 : 0 : tqd->conf.dataRingSize = txq->data_ring.size;
943 : 0 : tqd->conf.txDataRingDescSize = txq->txdata_desc_size;
944 : :
945 [ # # ]: 0 : if (hw->intr.lsc_only)
946 : 0 : tqd->conf.intrIdx = 1;
947 : : else
948 : 0 : tqd->conf.intrIdx =
949 : 0 : rte_intr_vec_list_index_get(intr_handle,
950 : : i);
951 : 0 : tqd->status.stopped = TRUE;
952 : 0 : tqd->status.error = 0;
953 : 0 : memset(&tqd->stats, 0, sizeof(tqd->stats));
954 : : }
955 : :
956 [ # # ]: 0 : for (i = 0; i < hw->num_rx_queues; i++) {
957 : 0 : Vmxnet3_RxQueueDesc *rqd = &hw->rqd_start[i];
958 : 0 : vmxnet3_rx_queue_t *rxq = dev->data->rx_queues[i];
959 : :
960 : 0 : rxq->shared = &hw->rqd_start[i];
961 : :
962 : 0 : rqd->conf.rxRingBasePA[0] = rxq->cmd_ring[0].basePA;
963 : 0 : rqd->conf.rxRingBasePA[1] = rxq->cmd_ring[1].basePA;
964 : 0 : rqd->conf.compRingBasePA = rxq->comp_ring.basePA;
965 : :
966 : 0 : rqd->conf.rxRingSize[0] = rxq->cmd_ring[0].size;
967 : 0 : rqd->conf.rxRingSize[1] = rxq->cmd_ring[1].size;
968 : 0 : rqd->conf.compRingSize = rxq->comp_ring.size;
969 : :
970 [ # # ]: 0 : if (VMXNET3_VERSION_GE_3(hw)) {
971 : 0 : rqd->conf.rxDataRingBasePA = rxq->data_ring.basePA;
972 : 0 : rqd->conf.rxDataRingDescSize = rxq->data_desc_size;
973 : : }
974 : :
975 [ # # ]: 0 : if (hw->intr.lsc_only)
976 : 0 : rqd->conf.intrIdx = 1;
977 : : else
978 : 0 : rqd->conf.intrIdx =
979 : 0 : rte_intr_vec_list_index_get(intr_handle,
980 : : i);
981 : 0 : rqd->status.stopped = TRUE;
982 : 0 : rqd->status.error = 0;
983 : 0 : memset(&rqd->stats, 0, sizeof(rqd->stats));
984 : : }
985 : :
986 : : /* intr settings */
987 [ # # # # ]: 0 : if (VMXNET3_VERSION_GE_6(hw) && hw->queuesExtEnabled) {
988 : 0 : devReadExt->intrConfExt.autoMask = hw->intr.mask_mode ==
989 : : VMXNET3_IMM_AUTO;
990 : 0 : devReadExt->intrConfExt.numIntrs = hw->intr.num_intrs;
991 [ # # ]: 0 : for (i = 0; i < hw->intr.num_intrs; i++)
992 : 0 : devReadExt->intrConfExt.modLevels[i] =
993 : 0 : hw->intr.mod_levels[i];
994 : :
995 : 0 : devReadExt->intrConfExt.eventIntrIdx = hw->intr.event_intr_idx;
996 : 0 : devReadExt->intrConfExt.intrCtrl |=
997 : : rte_cpu_to_le_32(VMXNET3_IC_DISABLE_ALL);
998 : : } else {
999 : 0 : devRead->intrConf.autoMask = hw->intr.mask_mode ==
1000 : : VMXNET3_IMM_AUTO;
1001 : 0 : devRead->intrConf.numIntrs = hw->intr.num_intrs;
1002 [ # # ]: 0 : for (i = 0; i < hw->intr.num_intrs; i++)
1003 : 0 : devRead->intrConf.modLevels[i] = hw->intr.mod_levels[i];
1004 : :
1005 : 0 : devRead->intrConf.eventIntrIdx = hw->intr.event_intr_idx;
1006 : 0 : devRead->intrConf.intrCtrl |= rte_cpu_to_le_32(VMXNET3_IC_DISABLE_ALL);
1007 : : }
1008 : :
1009 : : /* RxMode set to 0 of VMXNET3_RXM_xxx */
1010 : 0 : devRead->rxFilterConf.rxMode = 0;
1011 : :
1012 : : /* Setting up feature flags */
1013 [ # # ]: 0 : if (rx_offloads & RTE_ETH_RX_OFFLOAD_CHECKSUM)
1014 : 0 : devRead->misc.uptFeatures |= VMXNET3_F_RXCSUM;
1015 : :
1016 [ # # ]: 0 : if (rx_offloads & RTE_ETH_RX_OFFLOAD_TCP_LRO) {
1017 : 0 : devRead->misc.uptFeatures |= VMXNET3_F_LRO;
1018 : 0 : devRead->misc.maxNumRxSG = 0;
1019 : : }
1020 : :
1021 [ # # ]: 0 : if (port_conf.rxmode.mq_mode == RTE_ETH_MQ_RX_RSS) {
1022 : 0 : ret = vmxnet3_rss_configure(dev);
1023 [ # # ]: 0 : if (ret != VMXNET3_SUCCESS)
1024 : : return ret;
1025 : :
1026 : 0 : devRead->misc.uptFeatures |= VMXNET3_F_RSS;
1027 : 0 : devRead->rssConfDesc.confVer = 1;
1028 : 0 : devRead->rssConfDesc.confLen = sizeof(struct VMXNET3_RSSConf);
1029 : 0 : devRead->rssConfDesc.confPA = hw->rss_confPA;
1030 : : }
1031 : :
1032 : 0 : ret = vmxnet3_dev_vlan_offload_set(dev,
1033 : : RTE_ETH_VLAN_STRIP_MASK | RTE_ETH_VLAN_FILTER_MASK);
1034 [ # # ]: 0 : if (ret)
1035 : : return ret;
1036 : :
1037 : 0 : vmxnet3_write_mac(hw, dev->data->mac_addrs->addr_bytes);
1038 : :
1039 : 0 : return VMXNET3_SUCCESS;
1040 : : }
1041 : :
1042 : : static void
1043 : : vmxnet3_init_bufsize(struct vmxnet3_hw *hw)
1044 : : {
1045 : 0 : struct Vmxnet3_DriverShared *shared = hw->shared;
1046 : : union Vmxnet3_CmdInfo *cmd_info = &shared->cu.cmdInfo;
1047 : :
1048 [ # # ]: 0 : if (!VMXNET3_VERSION_GE_7(hw))
1049 : : return;
1050 : :
1051 : 0 : cmd_info->ringBufSize.ring1BufSizeType0 = hw->rxdata_buf_size;
1052 : 0 : cmd_info->ringBufSize.ring1BufSizeType1 = 0;
1053 : 0 : cmd_info->ringBufSize.ring2BufSizeType1 = hw->rxdata_buf_size;
1054 : 0 : VMXNET3_WRITE_BAR1_REG(hw, VMXNET3_REG_CMD,
1055 : : VMXNET3_CMD_SET_RING_BUFFER_SIZE);
1056 : : }
1057 : :
1058 : : /*
1059 : : * Configure device link speed and setup link.
1060 : : * Must be called after eth_vmxnet3_dev_init. Other wise it might fail
1061 : : * It returns 0 on success.
1062 : : */
1063 : : static int
1064 : 0 : vmxnet3_dev_start(struct rte_eth_dev *dev)
1065 : : {
1066 : : int ret;
1067 : 0 : struct vmxnet3_hw *hw = dev->data->dev_private;
1068 : : uint16_t i;
1069 : :
1070 : 0 : PMD_INIT_FUNC_TRACE();
1071 : :
1072 : : /* Save stats before it is reset by CMD_ACTIVATE */
1073 : 0 : vmxnet3_hw_stats_save(hw);
1074 : :
1075 : : /* configure MSI-X */
1076 : 0 : ret = vmxnet3_configure_msix(dev);
1077 [ # # ]: 0 : if (ret < 0) {
1078 : : /* revert to lsc only */
1079 : 0 : hw->intr.num_intrs = 2;
1080 : 0 : hw->intr.lsc_only = TRUE;
1081 : : }
1082 : :
1083 : 0 : ret = vmxnet3_setup_driver_shared(dev);
1084 [ # # ]: 0 : if (ret != VMXNET3_SUCCESS)
1085 : : return ret;
1086 : :
1087 : : /* Exchange shared data with device */
1088 : 0 : VMXNET3_WRITE_BAR1_REG(hw, VMXNET3_REG_DSAL,
1089 : : VMXNET3_GET_ADDR_LO(hw->sharedPA));
1090 : 0 : VMXNET3_WRITE_BAR1_REG(hw, VMXNET3_REG_DSAH,
1091 : : VMXNET3_GET_ADDR_HI(hw->sharedPA));
1092 : :
1093 : : /* Activate device by register write */
1094 : 0 : VMXNET3_WRITE_BAR1_REG(hw, VMXNET3_REG_CMD, VMXNET3_CMD_ACTIVATE_DEV);
1095 : 0 : ret = VMXNET3_READ_BAR1_REG(hw, VMXNET3_REG_CMD);
1096 : :
1097 [ # # ]: 0 : if (ret != 0) {
1098 : 0 : PMD_INIT_LOG(ERR, "Device activation: UNSUCCESSFUL");
1099 : 0 : return -EINVAL;
1100 : : }
1101 : :
1102 : : /* Check memregs restrictions first */
1103 [ # # ]: 0 : if (dev->data->nb_rx_queues <= VMXNET3_MAX_MEMREG_QUEUES &&
1104 [ # # ]: 0 : dev->data->nb_tx_queues <= VMXNET3_MAX_MEMREG_QUEUES) {
1105 : 0 : ret = vmxnet3_dev_setup_memreg(dev);
1106 [ # # ]: 0 : if (ret == 0) {
1107 : 0 : VMXNET3_WRITE_BAR1_REG(hw, VMXNET3_REG_CMD,
1108 : : VMXNET3_CMD_REGISTER_MEMREGS);
1109 : 0 : ret = VMXNET3_READ_BAR1_REG(hw, VMXNET3_REG_CMD);
1110 [ # # ]: 0 : if (ret != 0)
1111 : 0 : PMD_INIT_LOG(DEBUG,
1112 : : "Failed in setup memory region cmd");
1113 : : ret = 0;
1114 : : } else {
1115 : 0 : PMD_INIT_LOG(DEBUG, "Failed to setup memory region");
1116 : : }
1117 : : } else {
1118 : 0 : PMD_INIT_LOG(WARNING, "Memregs can't init (rx: %d, tx: %d)",
1119 : : dev->data->nb_rx_queues, dev->data->nb_tx_queues);
1120 : : }
1121 : :
1122 [ # # ]: 0 : if (VMXNET3_VERSION_GE_4(hw) &&
1123 [ # # ]: 0 : dev->data->dev_conf.rxmode.mq_mode == RTE_ETH_MQ_RX_RSS) {
1124 : : /* Check for additional RSS */
1125 : 0 : ret = vmxnet3_v4_rss_configure(dev);
1126 [ # # ]: 0 : if (ret != VMXNET3_SUCCESS) {
1127 : 0 : PMD_INIT_LOG(ERR, "Failed to configure v4 RSS");
1128 : 0 : return ret;
1129 : : }
1130 : : }
1131 : :
1132 : : /*
1133 : : * Load RX queues with blank mbufs and update next2fill index for device
1134 : : * Update RxMode of the device
1135 : : */
1136 : 0 : ret = vmxnet3_dev_rxtx_init(dev);
1137 [ # # ]: 0 : if (ret != VMXNET3_SUCCESS) {
1138 : 0 : PMD_INIT_LOG(ERR, "Device queue init: UNSUCCESSFUL");
1139 : 0 : return ret;
1140 : : }
1141 : :
1142 : : vmxnet3_init_bufsize(hw);
1143 : :
1144 : 0 : hw->adapter_stopped = FALSE;
1145 : :
1146 : : /* Setting proper Rx Mode and issue Rx Mode Update command */
1147 : : vmxnet3_dev_set_rxmode(hw, VMXNET3_RXM_UCAST | VMXNET3_RXM_BCAST, 1);
1148 : :
1149 : : #ifndef RTE_EXEC_ENV_FREEBSD
1150 : : /* Setup interrupt callback */
1151 : 0 : rte_intr_callback_register(dev->intr_handle,
1152 : : vmxnet3_interrupt_handler, dev);
1153 : :
1154 [ # # ]: 0 : if (rte_intr_enable(dev->intr_handle) < 0) {
1155 : 0 : PMD_INIT_LOG(ERR, "interrupt enable failed");
1156 : 0 : return -EIO;
1157 : : }
1158 : :
1159 : : /* enable all intrs */
1160 : 0 : vmxnet3_enable_all_intrs(hw);
1161 : : #endif
1162 : :
1163 : 0 : vmxnet3_process_events(dev);
1164 : :
1165 : : /*
1166 : : * Update link state from device since this won't be
1167 : : * done upon starting with lsc in use. This is done
1168 : : * only after enabling interrupts to avoid any race
1169 : : * where the link state could change without an
1170 : : * interrupt being fired.
1171 : : */
1172 : 0 : __vmxnet3_dev_link_update(dev, 0);
1173 : :
1174 [ # # ]: 0 : for (i = 0; i < dev->data->nb_rx_queues; i++)
1175 : 0 : dev->data->rx_queue_state[i] = RTE_ETH_QUEUE_STATE_STARTED;
1176 [ # # ]: 0 : for (i = 0; i < dev->data->nb_tx_queues; i++)
1177 : 0 : dev->data->tx_queue_state[i] = RTE_ETH_QUEUE_STATE_STARTED;
1178 : :
1179 : : return VMXNET3_SUCCESS;
1180 : : }
1181 : :
1182 : : /*
1183 : : * Stop device: disable rx and tx functions to allow for reconfiguring.
1184 : : */
1185 : : static int
1186 : 0 : vmxnet3_dev_stop(struct rte_eth_dev *dev)
1187 : : {
1188 : : struct rte_eth_link link;
1189 : 0 : struct vmxnet3_hw *hw = dev->data->dev_private;
1190 : 0 : struct rte_intr_handle *intr_handle = dev->intr_handle;
1191 : : uint16_t i;
1192 : : int ret;
1193 : :
1194 : 0 : PMD_INIT_FUNC_TRACE();
1195 : :
1196 [ # # ]: 0 : if (hw->adapter_stopped == 1) {
1197 : 0 : PMD_INIT_LOG(DEBUG, "Device already stopped.");
1198 : 0 : return 0;
1199 : : }
1200 : :
1201 : : do {
1202 : : /* Unregister has lock to make sure there is no running cb.
1203 : : * This has to happen first since vmxnet3_interrupt_handler
1204 : : * reenables interrupts by calling vmxnet3_enable_intr
1205 : : */
1206 : 0 : ret = rte_intr_callback_unregister(intr_handle,
1207 : : vmxnet3_interrupt_handler,
1208 : : (void *)-1);
1209 [ # # ]: 0 : } while (ret == -EAGAIN);
1210 : :
1211 [ # # ]: 0 : if (ret < 0)
1212 : 0 : PMD_DRV_LOG(ERR, "Error attempting to unregister intr cb: %d",
1213 : : ret);
1214 : :
1215 : 0 : PMD_INIT_LOG(DEBUG, "Disabled %d intr callbacks", ret);
1216 : :
1217 : : /* disable interrupts */
1218 : 0 : vmxnet3_disable_all_intrs(hw);
1219 : :
1220 : 0 : rte_intr_disable(intr_handle);
1221 : :
1222 : : /* Clean datapath event and queue/vector mapping */
1223 : 0 : rte_intr_efd_disable(intr_handle);
1224 : 0 : rte_intr_vec_list_free(intr_handle);
1225 : :
1226 : : /* quiesce the device first */
1227 : 0 : VMXNET3_WRITE_BAR1_REG(hw, VMXNET3_REG_CMD, VMXNET3_CMD_QUIESCE_DEV);
1228 : 0 : VMXNET3_WRITE_BAR1_REG(hw, VMXNET3_REG_DSAL, 0);
1229 : 0 : VMXNET3_WRITE_BAR1_REG(hw, VMXNET3_REG_DSAH, 0);
1230 : :
1231 : : /* reset the device */
1232 : 0 : VMXNET3_WRITE_BAR1_REG(hw, VMXNET3_REG_CMD, VMXNET3_CMD_RESET_DEV);
1233 : 0 : PMD_INIT_LOG(DEBUG, "Device reset.");
1234 : :
1235 : 0 : vmxnet3_dev_clear_queues(dev);
1236 : :
1237 : : /* Clear recorded link status */
1238 : : memset(&link, 0, sizeof(link));
1239 : 0 : link.link_duplex = RTE_ETH_LINK_FULL_DUPLEX;
1240 : 0 : link.link_speed = RTE_ETH_SPEED_NUM_10G;
1241 : : link.link_autoneg = RTE_ETH_LINK_FIXED;
1242 : 0 : rte_eth_linkstatus_set(dev, &link);
1243 : :
1244 : 0 : hw->adapter_stopped = 1;
1245 : 0 : dev->data->dev_started = 0;
1246 : :
1247 [ # # ]: 0 : for (i = 0; i < dev->data->nb_rx_queues; i++)
1248 : 0 : dev->data->rx_queue_state[i] = RTE_ETH_QUEUE_STATE_STOPPED;
1249 [ # # ]: 0 : for (i = 0; i < dev->data->nb_tx_queues; i++)
1250 : 0 : dev->data->tx_queue_state[i] = RTE_ETH_QUEUE_STATE_STOPPED;
1251 : :
1252 : : return 0;
1253 : : }
1254 : :
1255 : : static void
1256 : 0 : vmxnet3_free_queues(struct rte_eth_dev *dev)
1257 : : {
1258 : : int i;
1259 : :
1260 : 0 : PMD_INIT_FUNC_TRACE();
1261 : :
1262 [ # # ]: 0 : for (i = 0; i < dev->data->nb_rx_queues; i++)
1263 : 0 : vmxnet3_dev_rx_queue_release(dev, i);
1264 : 0 : dev->data->nb_rx_queues = 0;
1265 : :
1266 [ # # ]: 0 : for (i = 0; i < dev->data->nb_tx_queues; i++)
1267 : 0 : vmxnet3_dev_tx_queue_release(dev, i);
1268 : 0 : dev->data->nb_tx_queues = 0;
1269 : 0 : }
1270 : :
1271 : : /*
1272 : : * Reset and stop device.
1273 : : */
1274 : : static int
1275 : 0 : vmxnet3_dev_close(struct rte_eth_dev *dev)
1276 : : {
1277 : : int ret;
1278 : 0 : PMD_INIT_FUNC_TRACE();
1279 [ # # ]: 0 : if (rte_eal_process_type() != RTE_PROC_PRIMARY)
1280 : : return 0;
1281 : :
1282 : 0 : ret = vmxnet3_dev_stop(dev);
1283 : 0 : vmxnet3_free_queues(dev);
1284 : :
1285 : 0 : return ret;
1286 : : }
1287 : :
1288 : : static int
1289 : 0 : vmxnet3_dev_reset(struct rte_eth_dev *dev)
1290 : : {
1291 : : int ret;
1292 : :
1293 : 0 : ret = eth_vmxnet3_dev_uninit(dev);
1294 [ # # ]: 0 : if (ret)
1295 : : return ret;
1296 : 0 : ret = eth_vmxnet3_dev_init(dev);
1297 : 0 : return ret;
1298 : : }
1299 : :
1300 : : static void
1301 : 0 : vmxnet3_hw_tx_stats_get(struct vmxnet3_hw *hw, unsigned int q,
1302 : : struct UPT1_TxStats *res)
1303 : : {
1304 : : #define VMXNET3_UPDATE_TX_STAT(h, i, f, r) \
1305 : : ((r)->f = (h)->tqd_start[(i)].stats.f + \
1306 : : (h)->saved_tx_stats[(i)].f)
1307 : :
1308 : 0 : VMXNET3_UPDATE_TX_STAT(hw, q, ucastPktsTxOK, res);
1309 : 0 : VMXNET3_UPDATE_TX_STAT(hw, q, mcastPktsTxOK, res);
1310 : 0 : VMXNET3_UPDATE_TX_STAT(hw, q, bcastPktsTxOK, res);
1311 : 0 : VMXNET3_UPDATE_TX_STAT(hw, q, ucastBytesTxOK, res);
1312 : 0 : VMXNET3_UPDATE_TX_STAT(hw, q, mcastBytesTxOK, res);
1313 : 0 : VMXNET3_UPDATE_TX_STAT(hw, q, bcastBytesTxOK, res);
1314 : 0 : VMXNET3_UPDATE_TX_STAT(hw, q, pktsTxError, res);
1315 : 0 : VMXNET3_UPDATE_TX_STAT(hw, q, pktsTxDiscard, res);
1316 : :
1317 : : #undef VMXNET3_UPDATE_TX_STAT
1318 : 0 : }
1319 : :
1320 : : static void
1321 : 0 : vmxnet3_hw_rx_stats_get(struct vmxnet3_hw *hw, unsigned int q,
1322 : : struct UPT1_RxStats *res)
1323 : : {
1324 : : #define VMXNET3_UPDATE_RX_STAT(h, i, f, r) \
1325 : : ((r)->f = (h)->rqd_start[(i)].stats.f + \
1326 : : (h)->saved_rx_stats[(i)].f)
1327 : :
1328 : 0 : VMXNET3_UPDATE_RX_STAT(hw, q, ucastPktsRxOK, res);
1329 : 0 : VMXNET3_UPDATE_RX_STAT(hw, q, mcastPktsRxOK, res);
1330 : 0 : VMXNET3_UPDATE_RX_STAT(hw, q, bcastPktsRxOK, res);
1331 : 0 : VMXNET3_UPDATE_RX_STAT(hw, q, ucastBytesRxOK, res);
1332 : 0 : VMXNET3_UPDATE_RX_STAT(hw, q, mcastBytesRxOK, res);
1333 : 0 : VMXNET3_UPDATE_RX_STAT(hw, q, bcastBytesRxOK, res);
1334 : 0 : VMXNET3_UPDATE_RX_STAT(hw, q, pktsRxError, res);
1335 : 0 : VMXNET3_UPDATE_RX_STAT(hw, q, pktsRxOutOfBuf, res);
1336 : :
1337 : : #undef VMXNET3_UPDATE_RX_STAT
1338 : 0 : }
1339 : :
1340 : : static void
1341 : 0 : vmxnet3_tx_stats_get(struct vmxnet3_hw *hw, unsigned int q,
1342 : : struct UPT1_TxStats *res)
1343 : : {
1344 : 0 : vmxnet3_hw_tx_stats_get(hw, q, res);
1345 : :
1346 : : #define VMXNET3_REDUCE_SNAPSHOT_TX_STAT(h, i, f, r) \
1347 : : ((r)->f -= (h)->snapshot_tx_stats[(i)].f)
1348 : :
1349 : 0 : VMXNET3_REDUCE_SNAPSHOT_TX_STAT(hw, q, ucastPktsTxOK, res);
1350 : 0 : VMXNET3_REDUCE_SNAPSHOT_TX_STAT(hw, q, mcastPktsTxOK, res);
1351 : 0 : VMXNET3_REDUCE_SNAPSHOT_TX_STAT(hw, q, bcastPktsTxOK, res);
1352 : 0 : VMXNET3_REDUCE_SNAPSHOT_TX_STAT(hw, q, ucastBytesTxOK, res);
1353 : 0 : VMXNET3_REDUCE_SNAPSHOT_TX_STAT(hw, q, mcastBytesTxOK, res);
1354 : 0 : VMXNET3_REDUCE_SNAPSHOT_TX_STAT(hw, q, bcastBytesTxOK, res);
1355 : 0 : VMXNET3_REDUCE_SNAPSHOT_TX_STAT(hw, q, pktsTxError, res);
1356 : 0 : VMXNET3_REDUCE_SNAPSHOT_TX_STAT(hw, q, pktsTxDiscard, res);
1357 : :
1358 : : #undef VMXNET3_REDUCE_SNAPSHOT_TX_STAT
1359 : 0 : }
1360 : :
1361 : : static void
1362 : 0 : vmxnet3_rx_stats_get(struct vmxnet3_hw *hw, unsigned int q,
1363 : : struct UPT1_RxStats *res)
1364 : : {
1365 : 0 : vmxnet3_hw_rx_stats_get(hw, q, res);
1366 : :
1367 : : #define VMXNET3_REDUCE_SNAPSHOT_RX_STAT(h, i, f, r) \
1368 : : ((r)->f -= (h)->snapshot_rx_stats[(i)].f)
1369 : :
1370 : 0 : VMXNET3_REDUCE_SNAPSHOT_RX_STAT(hw, q, ucastPktsRxOK, res);
1371 : 0 : VMXNET3_REDUCE_SNAPSHOT_RX_STAT(hw, q, mcastPktsRxOK, res);
1372 : 0 : VMXNET3_REDUCE_SNAPSHOT_RX_STAT(hw, q, bcastPktsRxOK, res);
1373 : 0 : VMXNET3_REDUCE_SNAPSHOT_RX_STAT(hw, q, ucastBytesRxOK, res);
1374 : 0 : VMXNET3_REDUCE_SNAPSHOT_RX_STAT(hw, q, mcastBytesRxOK, res);
1375 : 0 : VMXNET3_REDUCE_SNAPSHOT_RX_STAT(hw, q, bcastBytesRxOK, res);
1376 : 0 : VMXNET3_REDUCE_SNAPSHOT_RX_STAT(hw, q, pktsRxError, res);
1377 : 0 : VMXNET3_REDUCE_SNAPSHOT_RX_STAT(hw, q, pktsRxOutOfBuf, res);
1378 : :
1379 : : #undef VMXNET3_REDUCE_SNAPSHOT_RX_STAT
1380 : 0 : }
1381 : :
1382 : : static void
1383 : 0 : vmxnet3_hw_stats_save(struct vmxnet3_hw *hw)
1384 : : {
1385 : : unsigned int i;
1386 : :
1387 : 0 : VMXNET3_WRITE_BAR1_REG(hw, VMXNET3_REG_CMD, VMXNET3_CMD_GET_STATS);
1388 : :
1389 [ # # ]: 0 : for (i = 0; i < hw->num_tx_queues; i++)
1390 : 0 : vmxnet3_hw_tx_stats_get(hw, i, &hw->saved_tx_stats[i]);
1391 [ # # ]: 0 : for (i = 0; i < hw->num_rx_queues; i++)
1392 : 0 : vmxnet3_hw_rx_stats_get(hw, i, &hw->saved_rx_stats[i]);
1393 : 0 : }
1394 : :
1395 : : static int
1396 : 0 : vmxnet3_dev_xstats_get_names(struct rte_eth_dev *dev,
1397 : : struct rte_eth_xstat_name *xstats_names,
1398 : : unsigned int n)
1399 : : {
1400 : : unsigned int i, t, count = 0;
1401 : 0 : unsigned int nstats =
1402 : 0 : dev->data->nb_tx_queues * RTE_DIM(vmxnet3_txq_stat_strings) +
1403 : 0 : dev->data->nb_rx_queues * RTE_DIM(vmxnet3_rxq_stat_strings);
1404 : :
1405 [ # # ]: 0 : if (!xstats_names || n < nstats)
1406 : 0 : return nstats;
1407 : :
1408 [ # # ]: 0 : for (i = 0; i < dev->data->nb_rx_queues; i++) {
1409 [ # # ]: 0 : if (!dev->data->rx_queues[i])
1410 : 0 : continue;
1411 : :
1412 [ # # ]: 0 : for (t = 0; t < RTE_DIM(vmxnet3_rxq_stat_strings); t++) {
1413 : 0 : snprintf(xstats_names[count].name,
1414 : : sizeof(xstats_names[count].name),
1415 : : "rx_q%u_%s", i,
1416 : 0 : vmxnet3_rxq_stat_strings[t].name);
1417 : 0 : count++;
1418 : : }
1419 : : }
1420 : :
1421 [ # # ]: 0 : for (i = 0; i < dev->data->nb_tx_queues; i++) {
1422 [ # # ]: 0 : if (!dev->data->tx_queues[i])
1423 : 0 : continue;
1424 : :
1425 [ # # ]: 0 : for (t = 0; t < RTE_DIM(vmxnet3_txq_stat_strings); t++) {
1426 : 0 : snprintf(xstats_names[count].name,
1427 : : sizeof(xstats_names[count].name),
1428 : : "tx_q%u_%s", i,
1429 : 0 : vmxnet3_txq_stat_strings[t].name);
1430 : 0 : count++;
1431 : : }
1432 : : }
1433 : :
1434 : 0 : return count;
1435 : : }
1436 : :
1437 : : static int
1438 : 0 : vmxnet3_dev_xstats_get(struct rte_eth_dev *dev, struct rte_eth_xstat *xstats,
1439 : : unsigned int n)
1440 : : {
1441 : : unsigned int i, t, count = 0;
1442 : 0 : unsigned int nstats =
1443 : 0 : dev->data->nb_tx_queues * RTE_DIM(vmxnet3_txq_stat_strings) +
1444 : 0 : dev->data->nb_rx_queues * RTE_DIM(vmxnet3_rxq_stat_strings);
1445 : :
1446 [ # # ]: 0 : if (n < nstats)
1447 : 0 : return nstats;
1448 : :
1449 [ # # ]: 0 : for (i = 0; i < dev->data->nb_rx_queues; i++) {
1450 : 0 : struct vmxnet3_rx_queue *rxq = dev->data->rx_queues[i];
1451 : :
1452 [ # # ]: 0 : if (rxq == NULL)
1453 : 0 : continue;
1454 : :
1455 [ # # ]: 0 : for (t = 0; t < RTE_DIM(vmxnet3_rxq_stat_strings); t++) {
1456 : 0 : xstats[count].value = *(uint64_t *)(((char *)&rxq->stats) +
1457 : 0 : vmxnet3_rxq_stat_strings[t].offset);
1458 : 0 : xstats[count].id = count;
1459 : 0 : count++;
1460 : : }
1461 : : }
1462 : :
1463 [ # # ]: 0 : for (i = 0; i < dev->data->nb_tx_queues; i++) {
1464 : 0 : struct vmxnet3_tx_queue *txq = dev->data->tx_queues[i];
1465 : :
1466 [ # # ]: 0 : if (txq == NULL)
1467 : 0 : continue;
1468 : :
1469 [ # # ]: 0 : for (t = 0; t < RTE_DIM(vmxnet3_txq_stat_strings); t++) {
1470 : 0 : xstats[count].value = *(uint64_t *)(((char *)&txq->stats) +
1471 : 0 : vmxnet3_txq_stat_strings[t].offset);
1472 : 0 : xstats[count].id = count;
1473 : 0 : count++;
1474 : : }
1475 : : }
1476 : :
1477 : 0 : return count;
1478 : : }
1479 : :
1480 : : static int
1481 : 0 : vmxnet3_dev_stats_get(struct rte_eth_dev *dev, struct rte_eth_stats *stats,
1482 : : struct eth_queue_stats *qstats)
1483 : : {
1484 : : unsigned int i;
1485 : 0 : struct vmxnet3_hw *hw = dev->data->dev_private;
1486 : : struct UPT1_TxStats txStats;
1487 : : struct UPT1_RxStats rxStats;
1488 : : uint64_t packets, bytes;
1489 : :
1490 : 0 : VMXNET3_WRITE_BAR1_REG(hw, VMXNET3_REG_CMD, VMXNET3_CMD_GET_STATS);
1491 : :
1492 [ # # ]: 0 : for (i = 0; i < hw->num_tx_queues; i++) {
1493 : 0 : vmxnet3_tx_stats_get(hw, i, &txStats);
1494 : :
1495 : 0 : packets = txStats.ucastPktsTxOK +
1496 : 0 : txStats.mcastPktsTxOK +
1497 : 0 : txStats.bcastPktsTxOK;
1498 : :
1499 : 0 : bytes = txStats.ucastBytesTxOK +
1500 : 0 : txStats.mcastBytesTxOK +
1501 : 0 : txStats.bcastBytesTxOK;
1502 : :
1503 : 0 : stats->opackets += packets;
1504 : 0 : stats->obytes += bytes;
1505 : 0 : stats->oerrors += txStats.pktsTxError + txStats.pktsTxDiscard;
1506 : :
1507 [ # # ]: 0 : if (qstats != NULL && i < RTE_ETHDEV_QUEUE_STAT_CNTRS) {
1508 : 0 : qstats->q_opackets[i] = packets;
1509 : 0 : qstats->q_obytes[i] = bytes;
1510 : : }
1511 : : }
1512 : :
1513 [ # # ]: 0 : for (i = 0; i < hw->num_rx_queues; i++) {
1514 : 0 : vmxnet3_rx_stats_get(hw, i, &rxStats);
1515 : :
1516 : 0 : packets = rxStats.ucastPktsRxOK +
1517 : 0 : rxStats.mcastPktsRxOK +
1518 : 0 : rxStats.bcastPktsRxOK;
1519 : :
1520 : 0 : bytes = rxStats.ucastBytesRxOK +
1521 : 0 : rxStats.mcastBytesRxOK +
1522 : 0 : rxStats.bcastBytesRxOK;
1523 : :
1524 : 0 : stats->ipackets += packets;
1525 : 0 : stats->ibytes += bytes;
1526 : 0 : stats->ierrors += rxStats.pktsRxError;
1527 : 0 : stats->imissed += rxStats.pktsRxOutOfBuf;
1528 : :
1529 [ # # ]: 0 : if (qstats != NULL && i < RTE_ETHDEV_QUEUE_STAT_CNTRS) {
1530 : 0 : qstats->q_ipackets[i] = packets;
1531 : 0 : qstats->q_ibytes[i] = bytes;
1532 : 0 : qstats->q_errors[i] = rxStats.pktsRxError;
1533 : : }
1534 : : }
1535 : :
1536 : 0 : return 0;
1537 : : }
1538 : :
1539 : : static int
1540 : 0 : vmxnet3_dev_stats_reset(struct rte_eth_dev *dev)
1541 : : {
1542 : : unsigned int i;
1543 : 0 : struct vmxnet3_hw *hw = dev->data->dev_private;
1544 : 0 : struct UPT1_TxStats txStats = {0};
1545 : 0 : struct UPT1_RxStats rxStats = {0};
1546 : :
1547 : 0 : VMXNET3_WRITE_BAR1_REG(hw, VMXNET3_REG_CMD, VMXNET3_CMD_GET_STATS);
1548 : :
1549 [ # # ]: 0 : for (i = 0; i < hw->num_tx_queues; i++) {
1550 : 0 : vmxnet3_hw_tx_stats_get(hw, i, &txStats);
1551 : 0 : memcpy(&hw->snapshot_tx_stats[i], &txStats,
1552 : : sizeof(hw->snapshot_tx_stats[0]));
1553 : : }
1554 [ # # ]: 0 : for (i = 0; i < hw->num_rx_queues; i++) {
1555 : 0 : vmxnet3_hw_rx_stats_get(hw, i, &rxStats);
1556 : 0 : memcpy(&hw->snapshot_rx_stats[i], &rxStats,
1557 : : sizeof(hw->snapshot_rx_stats[0]));
1558 : : }
1559 : :
1560 : 0 : return 0;
1561 : : }
1562 : :
1563 : : static int
1564 : 0 : vmxnet3_dev_info_get(struct rte_eth_dev *dev,
1565 : : struct rte_eth_dev_info *dev_info)
1566 : : {
1567 : 0 : struct vmxnet3_hw *hw = dev->data->dev_private;
1568 : : int queues = 0;
1569 : :
1570 [ # # ]: 0 : if (VMXNET3_VERSION_GE_6(hw)) {
1571 : 0 : VMXNET3_WRITE_BAR1_REG(hw, VMXNET3_REG_CMD,
1572 : : VMXNET3_CMD_GET_MAX_QUEUES_CONF);
1573 : 0 : queues = VMXNET3_READ_BAR1_REG(hw, VMXNET3_REG_CMD);
1574 : :
1575 [ # # ]: 0 : if (queues > 0) {
1576 : 0 : dev_info->max_rx_queues =
1577 : 0 : RTE_MIN(VMXNET3_EXT_MAX_RX_QUEUES, ((queues >> 8) & 0xff));
1578 : 0 : dev_info->max_tx_queues =
1579 : 0 : RTE_MIN(VMXNET3_EXT_MAX_TX_QUEUES, (queues & 0xff));
1580 : : } else {
1581 : 0 : dev_info->max_rx_queues = VMXNET3_MAX_RX_QUEUES;
1582 : 0 : dev_info->max_tx_queues = VMXNET3_MAX_TX_QUEUES;
1583 : : }
1584 : : } else {
1585 : 0 : dev_info->max_rx_queues = VMXNET3_MAX_RX_QUEUES;
1586 : 0 : dev_info->max_tx_queues = VMXNET3_MAX_TX_QUEUES;
1587 : : }
1588 : :
1589 : 0 : dev_info->min_rx_bufsize = 1518 + RTE_PKTMBUF_HEADROOM;
1590 : 0 : dev_info->max_rx_pktlen = 16384; /* includes CRC, cf MAXFRS register */
1591 : 0 : dev_info->min_mtu = VMXNET3_MIN_MTU;
1592 [ # # ]: 0 : dev_info->max_mtu = VMXNET3_VERSION_GE_6(hw) ? VMXNET3_V6_MAX_MTU : VMXNET3_MAX_MTU;
1593 : 0 : dev_info->speed_capa = RTE_ETH_LINK_SPEED_10G;
1594 : 0 : dev_info->max_mac_addrs = VMXNET3_MAX_MAC_ADDRS;
1595 : :
1596 : 0 : dev_info->flow_type_rss_offloads = VMXNET3_RSS_OFFLOAD_ALL;
1597 : :
1598 [ # # ]: 0 : if (VMXNET3_VERSION_GE_4(hw)) {
1599 : 0 : dev_info->flow_type_rss_offloads |= VMXNET3_V4_RSS_MASK;
1600 : : }
1601 : :
1602 : 0 : dev_info->rx_desc_lim = (struct rte_eth_desc_lim) {
1603 : : .nb_max = VMXNET3_RX_RING_MAX_SIZE,
1604 : : .nb_min = VMXNET3_DEF_RX_RING_SIZE,
1605 : : .nb_align = 1,
1606 : : };
1607 : :
1608 : 0 : dev_info->tx_desc_lim = (struct rte_eth_desc_lim) {
1609 : : .nb_max = VMXNET3_TX_RING_MAX_SIZE,
1610 : : .nb_min = VMXNET3_DEF_TX_RING_SIZE,
1611 : : .nb_align = 1,
1612 : : .nb_seg_max = VMXNET3_TX_MAX_SEG,
1613 : : .nb_mtu_seg_max = VMXNET3_MAX_TXD_PER_PKT,
1614 : : };
1615 : :
1616 : 0 : dev_info->rx_offload_capa = VMXNET3_RX_OFFLOAD_CAP;
1617 : 0 : dev_info->rx_queue_offload_capa = 0;
1618 : 0 : dev_info->tx_offload_capa = VMXNET3_TX_OFFLOAD_CAP;
1619 : 0 : dev_info->tx_queue_offload_capa = 0;
1620 [ # # ]: 0 : if (hw->rss_conf == NULL) {
1621 : : /* RSS not configured */
1622 : 0 : dev_info->reta_size = 0;
1623 : : } else {
1624 : 0 : dev_info->reta_size = hw->rss_conf->indTableSize;
1625 : : }
1626 : 0 : return 0;
1627 : : }
1628 : :
1629 : : static int
1630 : 0 : vmxnet3_hw_ver_get(struct rte_eth_dev *dev,
1631 : : char *fw_version, size_t fw_size)
1632 : : {
1633 : : int ret;
1634 : 0 : struct vmxnet3_hw *hw = dev->data->dev_private;
1635 : :
1636 [ # # ]: 0 : ret = snprintf(fw_version, fw_size, "v%d", hw->version);
1637 : :
1638 : 0 : ret += 1; /* add the size of '\0' */
1639 [ # # ]: 0 : if (fw_size < (uint32_t)ret)
1640 : : return ret;
1641 : : else
1642 : 0 : return 0;
1643 : : }
1644 : :
1645 : : static const uint32_t *
1646 : 0 : vmxnet3_dev_supported_ptypes_get(struct rte_eth_dev *dev,
1647 : : size_t *no_of_elements)
1648 : : {
1649 : : static const uint32_t ptypes[] = {
1650 : : RTE_PTYPE_L3_IPV4_EXT,
1651 : : RTE_PTYPE_L3_IPV4,
1652 : : };
1653 : :
1654 [ # # ]: 0 : if (dev->rx_pkt_burst == vmxnet3_recv_pkts) {
1655 : 0 : *no_of_elements = RTE_DIM(ptypes);
1656 : 0 : return ptypes;
1657 : : }
1658 : : return NULL;
1659 : : }
1660 : :
1661 : : static int
1662 : 0 : vmxnet3_mac_addr_set(struct rte_eth_dev *dev, struct rte_ether_addr *mac_addr)
1663 : : {
1664 : 0 : struct vmxnet3_hw *hw = dev->data->dev_private;
1665 : :
1666 : : rte_ether_addr_copy(mac_addr, (struct rte_ether_addr *)(hw->perm_addr));
1667 : 0 : vmxnet3_write_mac(hw, mac_addr->addr_bytes);
1668 : 0 : return 0;
1669 : : }
1670 : :
1671 : : static int
1672 : 0 : vmxnet3_dev_mtu_set(struct rte_eth_dev *dev, uint16_t mtu)
1673 : : {
1674 : 0 : struct vmxnet3_hw *hw = dev->data->dev_private;
1675 : 0 : uint32_t frame_size = mtu + RTE_ETHER_HDR_LEN + RTE_ETHER_CRC_LEN + 4;
1676 : :
1677 [ # # ]: 0 : if (mtu < VMXNET3_MIN_MTU)
1678 : : return -EINVAL;
1679 : :
1680 [ # # ]: 0 : if (VMXNET3_VERSION_GE_6(hw)) {
1681 [ # # ]: 0 : if (mtu > VMXNET3_V6_MAX_MTU)
1682 : : return -EINVAL;
1683 : : } else {
1684 [ # # ]: 0 : if (mtu > VMXNET3_MAX_MTU) {
1685 : 0 : PMD_DRV_LOG(ERR, "MTU %d too large in device version v%d",
1686 : : mtu, hw->version);
1687 : 0 : return -EINVAL;
1688 : : }
1689 : : }
1690 : :
1691 : 0 : dev->data->mtu = mtu;
1692 : : /* update max frame size */
1693 : 0 : dev->data->dev_conf.rxmode.mtu = frame_size;
1694 : :
1695 [ # # ]: 0 : if (dev->data->dev_started == 0)
1696 : : return 0;
1697 : :
1698 : : /* changing mtu for vmxnet3 pmd does not require a restart
1699 : : * as it does not need to repopulate the rx rings to support
1700 : : * different mtu size. We stop and restart the device here
1701 : : * just to pass the mtu info to the backend.
1702 : : */
1703 : 0 : vmxnet3_dev_stop(dev);
1704 : 0 : vmxnet3_dev_start(dev);
1705 : :
1706 : 0 : return 0;
1707 : : }
1708 : :
1709 : : /* return 0 means link status changed, -1 means not changed */
1710 : : static int
1711 : 0 : __vmxnet3_dev_link_update(struct rte_eth_dev *dev,
1712 : : __rte_unused int wait_to_complete)
1713 : : {
1714 : 0 : struct vmxnet3_hw *hw = dev->data->dev_private;
1715 : : struct rte_eth_link link;
1716 : : uint32_t ret;
1717 : :
1718 : : memset(&link, 0, sizeof(link));
1719 : :
1720 : 0 : VMXNET3_WRITE_BAR1_REG(hw, VMXNET3_REG_CMD, VMXNET3_CMD_GET_LINK);
1721 : 0 : ret = VMXNET3_READ_BAR1_REG(hw, VMXNET3_REG_CMD);
1722 : :
1723 [ # # ]: 0 : if (ret & 0x1)
1724 : 0 : link.link_status = RTE_ETH_LINK_UP;
1725 : 0 : link.link_duplex = RTE_ETH_LINK_FULL_DUPLEX;
1726 : 0 : link.link_speed = RTE_ETH_SPEED_NUM_10G;
1727 [ # # ]: 0 : link.link_autoneg = RTE_ETH_LINK_FIXED;
1728 : :
1729 : 0 : return rte_eth_linkstatus_set(dev, &link);
1730 : : }
1731 : :
1732 : : static int
1733 : 0 : vmxnet3_dev_link_update(struct rte_eth_dev *dev, int wait_to_complete)
1734 : : {
1735 : : /* Link status doesn't change for stopped dev */
1736 [ # # # # ]: 0 : if (dev->data->dev_started == 0)
1737 : : return -1;
1738 : :
1739 : 0 : return __vmxnet3_dev_link_update(dev, wait_to_complete);
1740 : : }
1741 : :
1742 : : /* Updating rxmode through Vmxnet3_DriverShared structure in adapter */
1743 : : static void
1744 : : vmxnet3_dev_set_rxmode(struct vmxnet3_hw *hw, uint32_t feature, int set)
1745 : : {
1746 : 0 : struct Vmxnet3_RxFilterConf *rxConf = &hw->shared->devRead.rxFilterConf;
1747 : :
1748 : : if (set)
1749 : 0 : rxConf->rxMode = rxConf->rxMode | feature;
1750 : : else
1751 : 0 : rxConf->rxMode = rxConf->rxMode & (~feature);
1752 : :
1753 : 0 : VMXNET3_WRITE_BAR1_REG(hw, VMXNET3_REG_CMD, VMXNET3_CMD_UPDATE_RX_MODE);
1754 : : }
1755 : :
1756 : : /* Promiscuous supported only if Vmxnet3_DriverShared is initialized in adapter */
1757 : : static int
1758 : 0 : vmxnet3_dev_promiscuous_enable(struct rte_eth_dev *dev)
1759 : : {
1760 : 0 : struct vmxnet3_hw *hw = dev->data->dev_private;
1761 : 0 : uint32_t *vf_table = hw->shared->devRead.rxFilterConf.vfTable;
1762 : :
1763 : : memset(vf_table, 0, VMXNET3_VFT_TABLE_SIZE);
1764 : : vmxnet3_dev_set_rxmode(hw, VMXNET3_RXM_PROMISC, 1);
1765 : :
1766 : 0 : VMXNET3_WRITE_BAR1_REG(hw, VMXNET3_REG_CMD,
1767 : : VMXNET3_CMD_UPDATE_VLAN_FILTERS);
1768 : :
1769 : 0 : return 0;
1770 : : }
1771 : :
1772 : : /* Promiscuous supported only if Vmxnet3_DriverShared is initialized in adapter */
1773 : : static int
1774 : 0 : vmxnet3_dev_promiscuous_disable(struct rte_eth_dev *dev)
1775 : : {
1776 : 0 : struct vmxnet3_hw *hw = dev->data->dev_private;
1777 : 0 : uint32_t *vf_table = hw->shared->devRead.rxFilterConf.vfTable;
1778 : 0 : uint64_t rx_offloads = dev->data->dev_conf.rxmode.offloads;
1779 : :
1780 [ # # ]: 0 : if (rx_offloads & RTE_ETH_RX_OFFLOAD_VLAN_FILTER)
1781 : 0 : memcpy(vf_table, hw->shadow_vfta, VMXNET3_VFT_TABLE_SIZE);
1782 : : else
1783 : : memset(vf_table, 0xff, VMXNET3_VFT_TABLE_SIZE);
1784 : : vmxnet3_dev_set_rxmode(hw, VMXNET3_RXM_PROMISC, 0);
1785 : 0 : VMXNET3_WRITE_BAR1_REG(hw, VMXNET3_REG_CMD,
1786 : : VMXNET3_CMD_UPDATE_VLAN_FILTERS);
1787 : :
1788 : 0 : return 0;
1789 : : }
1790 : :
1791 : : /* Allmulticast supported only if Vmxnet3_DriverShared is initialized in adapter */
1792 : : static int
1793 : 0 : vmxnet3_dev_allmulticast_enable(struct rte_eth_dev *dev)
1794 : : {
1795 : 0 : struct vmxnet3_hw *hw = dev->data->dev_private;
1796 : :
1797 : : vmxnet3_dev_set_rxmode(hw, VMXNET3_RXM_ALL_MULTI, 1);
1798 : :
1799 : 0 : return 0;
1800 : : }
1801 : :
1802 : : /* Allmulticast supported only if Vmxnet3_DriverShared is initialized in adapter */
1803 : : static int
1804 : 0 : vmxnet3_dev_allmulticast_disable(struct rte_eth_dev *dev)
1805 : : {
1806 : 0 : struct vmxnet3_hw *hw = dev->data->dev_private;
1807 : :
1808 : : vmxnet3_dev_set_rxmode(hw, VMXNET3_RXM_ALL_MULTI, 0);
1809 : :
1810 : 0 : return 0;
1811 : : }
1812 : :
1813 : : /* Enable/disable filter on vlan */
1814 : : static int
1815 : 0 : vmxnet3_dev_vlan_filter_set(struct rte_eth_dev *dev, uint16_t vid, int on)
1816 : : {
1817 : 0 : struct vmxnet3_hw *hw = dev->data->dev_private;
1818 : 0 : struct Vmxnet3_RxFilterConf *rxConf = &hw->shared->devRead.rxFilterConf;
1819 : 0 : uint32_t *vf_table = rxConf->vfTable;
1820 : :
1821 : : /* save state for restore */
1822 [ # # ]: 0 : if (on)
1823 : 0 : VMXNET3_SET_VFTABLE_ENTRY(hw->shadow_vfta, vid);
1824 : : else
1825 : 0 : VMXNET3_CLEAR_VFTABLE_ENTRY(hw->shadow_vfta, vid);
1826 : :
1827 : : /* don't change active filter if in promiscuous mode */
1828 [ # # ]: 0 : if (rxConf->rxMode & VMXNET3_RXM_PROMISC)
1829 : : return 0;
1830 : :
1831 : : /* set in hardware */
1832 [ # # ]: 0 : if (on)
1833 : 0 : VMXNET3_SET_VFTABLE_ENTRY(vf_table, vid);
1834 : : else
1835 : 0 : VMXNET3_CLEAR_VFTABLE_ENTRY(vf_table, vid);
1836 : :
1837 : 0 : VMXNET3_WRITE_BAR1_REG(hw, VMXNET3_REG_CMD,
1838 : : VMXNET3_CMD_UPDATE_VLAN_FILTERS);
1839 : 0 : return 0;
1840 : : }
1841 : :
1842 : : static int
1843 : 0 : vmxnet3_dev_vlan_offload_set(struct rte_eth_dev *dev, int mask)
1844 : : {
1845 : 0 : struct vmxnet3_hw *hw = dev->data->dev_private;
1846 : 0 : Vmxnet3_DSDevRead *devRead = &hw->shared->devRead;
1847 : 0 : uint32_t *vf_table = devRead->rxFilterConf.vfTable;
1848 : 0 : uint64_t rx_offloads = dev->data->dev_conf.rxmode.offloads;
1849 : :
1850 [ # # ]: 0 : if (mask & RTE_ETH_VLAN_STRIP_MASK) {
1851 [ # # ]: 0 : if (rx_offloads & RTE_ETH_RX_OFFLOAD_VLAN_STRIP)
1852 : 0 : devRead->misc.uptFeatures |= UPT1_F_RXVLAN;
1853 : : else
1854 : 0 : devRead->misc.uptFeatures &= ~UPT1_F_RXVLAN;
1855 : :
1856 : 0 : VMXNET3_WRITE_BAR1_REG(hw, VMXNET3_REG_CMD,
1857 : : VMXNET3_CMD_UPDATE_FEATURE);
1858 : : }
1859 : :
1860 [ # # ]: 0 : if (mask & RTE_ETH_VLAN_FILTER_MASK) {
1861 [ # # ]: 0 : if (rx_offloads & RTE_ETH_RX_OFFLOAD_VLAN_FILTER)
1862 : 0 : memcpy(vf_table, hw->shadow_vfta, VMXNET3_VFT_TABLE_SIZE);
1863 : : else
1864 : : memset(vf_table, 0xff, VMXNET3_VFT_TABLE_SIZE);
1865 : :
1866 : 0 : VMXNET3_WRITE_BAR1_REG(hw, VMXNET3_REG_CMD,
1867 : : VMXNET3_CMD_UPDATE_VLAN_FILTERS);
1868 : : }
1869 : :
1870 : 0 : return 0;
1871 : : }
1872 : :
1873 : : static void
1874 : 0 : vmxnet3_process_events(struct rte_eth_dev *dev)
1875 : : {
1876 : 0 : struct vmxnet3_hw *hw = dev->data->dev_private;
1877 : 0 : uint32_t events = hw->shared->ecr;
1878 : : int i;
1879 : :
1880 [ # # ]: 0 : if (!events)
1881 : : return;
1882 : :
1883 : : /*
1884 : : * ECR bits when written with 1b are cleared. Hence write
1885 : : * events back to ECR so that the bits which were set will be reset.
1886 : : */
1887 : 0 : VMXNET3_WRITE_BAR1_REG(hw, VMXNET3_REG_ECR, events);
1888 : :
1889 : : /* Check if link state has changed */
1890 [ # # ]: 0 : if (events & VMXNET3_ECR_LINK) {
1891 : 0 : PMD_DRV_LOG(DEBUG, "Process events: VMXNET3_ECR_LINK event");
1892 [ # # ]: 0 : if (vmxnet3_dev_link_update(dev, 0) == 0)
1893 : 0 : rte_eth_dev_callback_process(dev,
1894 : : RTE_ETH_EVENT_INTR_LSC,
1895 : : NULL);
1896 : : }
1897 : :
1898 : : /* Check if there is an error on xmit/recv queues */
1899 [ # # ]: 0 : if (events & (VMXNET3_ECR_TQERR | VMXNET3_ECR_RQERR)) {
1900 : 0 : VMXNET3_WRITE_BAR1_REG(hw, VMXNET3_REG_CMD,
1901 : : VMXNET3_CMD_GET_QUEUE_STATUS);
1902 : :
1903 : 0 : PMD_DRV_LOG(ERR, "queue error event 0x%x for "
1904 : : RTE_ETHER_ADDR_PRT_FMT, events,
1905 : : hw->perm_addr[0], hw->perm_addr[1],
1906 : : hw->perm_addr[2], hw->perm_addr[3],
1907 : : hw->perm_addr[4], hw->perm_addr[5]);
1908 : :
1909 [ # # ]: 0 : for (i = 0; i < hw->num_tx_queues; i++) {
1910 [ # # ]: 0 : if (hw->tqd_start[i].status.stopped)
1911 : 0 : PMD_DRV_LOG(ERR, "tq %d error 0x%x",
1912 : : i, hw->tqd_start[i].status.error);
1913 : : }
1914 [ # # ]: 0 : for (i = 0; i < hw->num_rx_queues; i++) {
1915 [ # # ]: 0 : if (hw->rqd_start[i].status.stopped)
1916 : 0 : PMD_DRV_LOG(ERR, "rq %d error 0x%x",
1917 : : i, hw->rqd_start[i].status.error);
1918 : : }
1919 : :
1920 : : /* Have to reset the device */
1921 : : /* Notify the application so that it can reset the device */
1922 : 0 : rte_eth_dev_callback_process(dev,
1923 : : RTE_ETH_EVENT_INTR_RESET,
1924 : : NULL);
1925 : : }
1926 : :
1927 [ # # ]: 0 : if (events & VMXNET3_ECR_DIC)
1928 : 0 : PMD_DRV_LOG(DEBUG, "Device implementation change event.");
1929 : :
1930 [ # # ]: 0 : if (events & VMXNET3_ECR_DEBUG)
1931 : 0 : PMD_DRV_LOG(DEBUG, "Debug event generated by device.");
1932 : : }
1933 : :
1934 : : static void
1935 : 0 : vmxnet3_interrupt_handler(void *param)
1936 : : {
1937 : : struct rte_eth_dev *dev = param;
1938 : 0 : struct vmxnet3_hw *hw = dev->data->dev_private;
1939 : : uint32_t events;
1940 : : uint8 *eventIntrIdx;
1941 : : uint32 *intrCtrl;
1942 : :
1943 : 0 : PMD_INIT_FUNC_TRACE();
1944 : :
1945 : : vmxnet3_get_intr_ctrl_ev(hw, &eventIntrIdx, &intrCtrl);
1946 : 0 : vmxnet3_disable_intr(hw, *eventIntrIdx);
1947 : :
1948 : 0 : events = VMXNET3_READ_BAR1_REG(hw, VMXNET3_REG_ECR);
1949 [ # # ]: 0 : if (events == 0)
1950 : 0 : goto done;
1951 : :
1952 : 0 : PMD_DRV_LOG(DEBUG, "Reading events: 0x%X", events);
1953 : 0 : vmxnet3_process_events(dev);
1954 : 0 : done:
1955 : 0 : vmxnet3_enable_intr(hw, *eventIntrIdx);
1956 : 0 : }
1957 : :
1958 : : static int
1959 : 0 : vmxnet3_dev_rx_queue_intr_enable(struct rte_eth_dev *dev, uint16_t queue_id)
1960 : : {
1961 : : #ifndef RTE_EXEC_ENV_FREEBSD
1962 : 0 : struct vmxnet3_hw *hw = dev->data->dev_private;
1963 : :
1964 : 0 : vmxnet3_enable_intr(hw,
1965 : 0 : rte_intr_vec_list_index_get(dev->intr_handle,
1966 : : queue_id));
1967 : : #endif
1968 : :
1969 : 0 : return 0;
1970 : : }
1971 : :
1972 : : static int
1973 : 0 : vmxnet3_dev_rx_queue_intr_disable(struct rte_eth_dev *dev, uint16_t queue_id)
1974 : : {
1975 : 0 : struct vmxnet3_hw *hw = dev->data->dev_private;
1976 : :
1977 : 0 : vmxnet3_disable_intr(hw,
1978 : 0 : rte_intr_vec_list_index_get(dev->intr_handle, queue_id));
1979 : :
1980 : 0 : return 0;
1981 : : }
1982 : :
1983 : 254 : RTE_PMD_REGISTER_PCI(net_vmxnet3, rte_vmxnet3_pmd);
1984 : : RTE_PMD_REGISTER_PCI_TABLE(net_vmxnet3, pci_id_vmxnet3_map);
1985 : : RTE_PMD_REGISTER_KMOD_DEP(net_vmxnet3, "* igb_uio | uio_pci_generic | vfio-pci");
1986 [ - + ]: 254 : RTE_LOG_REGISTER_SUFFIX(vmxnet3_logtype_init, init, NOTICE);
1987 [ - + ]: 254 : RTE_LOG_REGISTER_SUFFIX(vmxnet3_logtype_driver, driver, NOTICE);
1988 : :
1989 : : static int
1990 : 0 : vmxnet3_rss_reta_update(struct rte_eth_dev *dev,
1991 : : struct rte_eth_rss_reta_entry64 *reta_conf,
1992 : : uint16_t reta_size)
1993 : : {
1994 : : int i, idx, shift;
1995 : 0 : struct vmxnet3_hw *hw = dev->data->dev_private;
1996 : 0 : struct VMXNET3_RSSConf *dev_rss_conf = hw->rss_conf;
1997 : :
1998 [ # # ]: 0 : if (reta_size != dev_rss_conf->indTableSize) {
1999 : 0 : PMD_DRV_LOG(ERR,
2000 : : "The size of hash lookup table configured (%d) doesn't match "
2001 : : "the supported number (%d)",
2002 : : reta_size, dev_rss_conf->indTableSize);
2003 : 0 : return -EINVAL;
2004 : : }
2005 : :
2006 [ # # ]: 0 : for (i = 0; i < reta_size; i++) {
2007 : 0 : idx = i / RTE_ETH_RETA_GROUP_SIZE;
2008 : 0 : shift = i % RTE_ETH_RETA_GROUP_SIZE;
2009 [ # # ]: 0 : if (reta_conf[idx].mask & RTE_BIT64(shift))
2010 : 0 : dev_rss_conf->indTable[i] = (uint8_t)reta_conf[idx].reta[shift];
2011 : : }
2012 : :
2013 : 0 : VMXNET3_WRITE_BAR1_REG(hw, VMXNET3_REG_CMD,
2014 : : VMXNET3_CMD_UPDATE_RSSIDT);
2015 : :
2016 : 0 : return 0;
2017 : : }
2018 : :
2019 : : static int
2020 : 0 : vmxnet3_rss_reta_query(struct rte_eth_dev *dev,
2021 : : struct rte_eth_rss_reta_entry64 *reta_conf,
2022 : : uint16_t reta_size)
2023 : : {
2024 : : int i, idx, shift;
2025 : 0 : struct vmxnet3_hw *hw = dev->data->dev_private;
2026 : 0 : struct VMXNET3_RSSConf *dev_rss_conf = hw->rss_conf;
2027 : :
2028 [ # # ]: 0 : if (reta_size != dev_rss_conf->indTableSize) {
2029 : 0 : PMD_DRV_LOG(ERR,
2030 : : "Size of requested hash lookup table (%d) doesn't "
2031 : : "match the configured size (%d)",
2032 : : reta_size, dev_rss_conf->indTableSize);
2033 : 0 : return -EINVAL;
2034 : : }
2035 : :
2036 [ # # ]: 0 : for (i = 0; i < reta_size; i++) {
2037 : 0 : idx = i / RTE_ETH_RETA_GROUP_SIZE;
2038 : 0 : shift = i % RTE_ETH_RETA_GROUP_SIZE;
2039 [ # # ]: 0 : if (reta_conf[idx].mask & RTE_BIT64(shift))
2040 : 0 : reta_conf[idx].reta[shift] = dev_rss_conf->indTable[i];
2041 : : }
2042 : :
2043 : : return 0;
2044 : : }
|