1 /* SPDX-License-Identifier: BSD-3-Clause
2 * Copyright(c) 2013-2017 Wind River Systems, Inc.
11 #include <rte_ethdev_driver.h>
12 #include <rte_ethdev_pci.h>
13 #include <rte_memcpy.h>
14 #include <rte_string_fns.h>
15 #include <rte_malloc.h>
16 #include <rte_atomic.h>
17 #include <rte_branch_prediction.h>
19 #include <rte_bus_pci.h>
20 #include <rte_ether.h>
21 #include <rte_common.h>
22 #include <rte_cycles.h>
23 #include <rte_spinlock.h>
24 #include <rte_byteorder.h>
26 #include <rte_memory.h>
30 #include "rte_avp_common.h"
31 #include "rte_avp_fifo.h"
35 int avp_logtype_driver;
37 static int avp_dev_create(struct rte_pci_device *pci_dev,
38 struct rte_eth_dev *eth_dev);
40 static int avp_dev_configure(struct rte_eth_dev *dev);
41 static int avp_dev_start(struct rte_eth_dev *dev);
42 static void avp_dev_stop(struct rte_eth_dev *dev);
43 static void avp_dev_close(struct rte_eth_dev *dev);
44 static void avp_dev_info_get(struct rte_eth_dev *dev,
45 struct rte_eth_dev_info *dev_info);
46 static int avp_vlan_offload_set(struct rte_eth_dev *dev, int mask);
47 static int avp_dev_link_update(struct rte_eth_dev *dev, int wait_to_complete);
48 static void avp_dev_promiscuous_enable(struct rte_eth_dev *dev);
49 static void avp_dev_promiscuous_disable(struct rte_eth_dev *dev);
51 static int avp_dev_rx_queue_setup(struct rte_eth_dev *dev,
54 unsigned int socket_id,
55 const struct rte_eth_rxconf *rx_conf,
56 struct rte_mempool *pool);
58 static int avp_dev_tx_queue_setup(struct rte_eth_dev *dev,
61 unsigned int socket_id,
62 const struct rte_eth_txconf *tx_conf);
64 static uint16_t avp_recv_scattered_pkts(void *rx_queue,
65 struct rte_mbuf **rx_pkts,
68 static uint16_t avp_recv_pkts(void *rx_queue,
69 struct rte_mbuf **rx_pkts,
72 static uint16_t avp_xmit_scattered_pkts(void *tx_queue,
73 struct rte_mbuf **tx_pkts,
76 static uint16_t avp_xmit_pkts(void *tx_queue,
77 struct rte_mbuf **tx_pkts,
80 static void avp_dev_rx_queue_release(void *rxq);
81 static void avp_dev_tx_queue_release(void *txq);
83 static int avp_dev_stats_get(struct rte_eth_dev *dev,
84 struct rte_eth_stats *stats);
85 static void avp_dev_stats_reset(struct rte_eth_dev *dev);
88 #define AVP_MAX_RX_BURST 64
89 #define AVP_MAX_TX_BURST 64
90 #define AVP_MAX_MAC_ADDRS 1
91 #define AVP_MIN_RX_BUFSIZE ETHER_MIN_LEN
95 * Defines the number of microseconds to wait before checking the response
96 * queue for completion.
98 #define AVP_REQUEST_DELAY_USECS (5000)
101 * Defines the number times to check the response queue for completion before
102 * declaring a timeout.
104 #define AVP_MAX_REQUEST_RETRY (100)
106 /* Defines the current PCI driver version number */
107 #define AVP_DPDK_DRIVER_VERSION RTE_AVP_CURRENT_GUEST_VERSION
110 * The set of PCI devices this driver supports
112 static const struct rte_pci_id pci_id_avp_map[] = {
113 { .vendor_id = RTE_AVP_PCI_VENDOR_ID,
114 .device_id = RTE_AVP_PCI_DEVICE_ID,
115 .subsystem_vendor_id = RTE_AVP_PCI_SUB_VENDOR_ID,
116 .subsystem_device_id = RTE_AVP_PCI_SUB_DEVICE_ID,
117 .class_id = RTE_CLASS_ANY_ID,
120 { .vendor_id = 0, /* sentinel */
125 * dev_ops for avp, bare necessities for basic operation
127 static const struct eth_dev_ops avp_eth_dev_ops = {
128 .dev_configure = avp_dev_configure,
129 .dev_start = avp_dev_start,
130 .dev_stop = avp_dev_stop,
131 .dev_close = avp_dev_close,
132 .dev_infos_get = avp_dev_info_get,
133 .vlan_offload_set = avp_vlan_offload_set,
134 .stats_get = avp_dev_stats_get,
135 .stats_reset = avp_dev_stats_reset,
136 .link_update = avp_dev_link_update,
137 .promiscuous_enable = avp_dev_promiscuous_enable,
138 .promiscuous_disable = avp_dev_promiscuous_disable,
139 .rx_queue_setup = avp_dev_rx_queue_setup,
140 .rx_queue_release = avp_dev_rx_queue_release,
141 .tx_queue_setup = avp_dev_tx_queue_setup,
142 .tx_queue_release = avp_dev_tx_queue_release,
145 /**@{ AVP device flags */
146 #define AVP_F_PROMISC (1 << 1)
147 #define AVP_F_CONFIGURED (1 << 2)
148 #define AVP_F_LINKUP (1 << 3)
149 #define AVP_F_DETACHED (1 << 4)
152 /* Ethernet device validation marker */
153 #define AVP_ETHDEV_MAGIC 0x92972862
156 * Defines the AVP device attributes which are attached to an RTE ethernet
160 uint32_t magic; /**< Memory validation marker */
161 uint64_t device_id; /**< Unique system identifier */
162 struct ether_addr ethaddr; /**< Host specified MAC address */
163 struct rte_eth_dev_data *dev_data;
164 /**< Back pointer to ethernet device data */
165 volatile uint32_t flags; /**< Device operational flags */
166 uint16_t port_id; /**< Ethernet port identifier */
167 struct rte_mempool *pool; /**< pkt mbuf mempool */
168 unsigned int guest_mbuf_size; /**< local pool mbuf size */
169 unsigned int host_mbuf_size; /**< host mbuf size */
170 unsigned int max_rx_pkt_len; /**< maximum receive unit */
171 uint32_t host_features; /**< Supported feature bitmap */
172 uint32_t features; /**< Enabled feature bitmap */
173 unsigned int num_tx_queues; /**< Negotiated number of transmit queues */
174 unsigned int max_tx_queues; /**< Maximum number of transmit queues */
175 unsigned int num_rx_queues; /**< Negotiated number of receive queues */
176 unsigned int max_rx_queues; /**< Maximum number of receive queues */
178 struct rte_avp_fifo *tx_q[RTE_AVP_MAX_QUEUES]; /**< TX queue */
179 struct rte_avp_fifo *rx_q[RTE_AVP_MAX_QUEUES]; /**< RX queue */
180 struct rte_avp_fifo *alloc_q[RTE_AVP_MAX_QUEUES];
181 /**< Allocated mbufs queue */
182 struct rte_avp_fifo *free_q[RTE_AVP_MAX_QUEUES];
183 /**< To be freed mbufs queue */
185 /* mutual exclusion over the 'flag' and 'resp_q/req_q' fields */
188 /* For request & response */
189 struct rte_avp_fifo *req_q; /**< Request queue */
190 struct rte_avp_fifo *resp_q; /**< Response queue */
191 void *host_sync_addr; /**< (host) Req/Resp Mem address */
192 void *sync_addr; /**< Req/Resp Mem address */
193 void *host_mbuf_addr; /**< (host) MBUF pool start address */
194 void *mbuf_addr; /**< MBUF pool start address */
195 } __rte_cache_aligned;
197 /* RTE ethernet private data */
200 } __rte_cache_aligned;
203 /* 32-bit MMIO register write */
204 #define AVP_WRITE32(_value, _addr) rte_write32_relaxed((_value), (_addr))
206 /* 32-bit MMIO register read */
207 #define AVP_READ32(_addr) rte_read32_relaxed((_addr))
209 /* Macro to cast the ethernet device private data to a AVP object */
210 #define AVP_DEV_PRIVATE_TO_HW(adapter) \
211 (&((struct avp_adapter *)adapter)->avp)
214 * Defines the structure of a AVP device queue for the purpose of handling the
215 * receive and transmit burst callback functions
218 struct rte_eth_dev_data *dev_data;
219 /**< Backpointer to ethernet device data */
220 struct avp_dev *avp; /**< Backpointer to AVP device */
222 /**< Queue identifier used for indexing current queue */
224 /**< Base queue identifier for queue servicing */
225 uint16_t queue_limit;
226 /**< Maximum queue identifier for queue servicing */
233 /* send a request and wait for a response
235 * @warning must be called while holding the avp->lock spinlock.
238 avp_dev_process_request(struct avp_dev *avp, struct rte_avp_request *request)
240 unsigned int retry = AVP_MAX_REQUEST_RETRY;
241 void *resp_addr = NULL;
245 PMD_DRV_LOG(DEBUG, "Sending request %u to host\n", request->req_id);
247 request->result = -ENOTSUP;
249 /* Discard any stale responses before starting a new request */
250 while (avp_fifo_get(avp->resp_q, (void **)&resp_addr, 1))
251 PMD_DRV_LOG(DEBUG, "Discarding stale response\n");
253 rte_memcpy(avp->sync_addr, request, sizeof(*request));
254 count = avp_fifo_put(avp->req_q, &avp->host_sync_addr, 1);
256 PMD_DRV_LOG(ERR, "Cannot send request %u to host\n",
263 /* wait for a response */
264 usleep(AVP_REQUEST_DELAY_USECS);
266 count = avp_fifo_count(avp->resp_q);
268 /* response received */
272 if ((count < 1) && (retry == 0)) {
273 PMD_DRV_LOG(ERR, "Timeout while waiting for a response for %u\n",
280 /* retrieve the response */
281 count = avp_fifo_get(avp->resp_q, (void **)&resp_addr, 1);
282 if ((count != 1) || (resp_addr != avp->host_sync_addr)) {
283 PMD_DRV_LOG(ERR, "Invalid response from host, count=%u resp=%p host_sync_addr=%p\n",
284 count, resp_addr, avp->host_sync_addr);
289 /* copy to user buffer */
290 rte_memcpy(request, avp->sync_addr, sizeof(*request));
293 PMD_DRV_LOG(DEBUG, "Result %d received for request %u\n",
294 request->result, request->req_id);
301 avp_dev_ctrl_set_link_state(struct rte_eth_dev *eth_dev, unsigned int state)
303 struct avp_dev *avp = AVP_DEV_PRIVATE_TO_HW(eth_dev->data->dev_private);
304 struct rte_avp_request request;
307 /* setup a link state change request */
308 memset(&request, 0, sizeof(request));
309 request.req_id = RTE_AVP_REQ_CFG_NETWORK_IF;
310 request.if_up = state;
312 ret = avp_dev_process_request(avp, &request);
314 return ret == 0 ? request.result : ret;
318 avp_dev_ctrl_set_config(struct rte_eth_dev *eth_dev,
319 struct rte_avp_device_config *config)
321 struct avp_dev *avp = AVP_DEV_PRIVATE_TO_HW(eth_dev->data->dev_private);
322 struct rte_avp_request request;
325 /* setup a configure request */
326 memset(&request, 0, sizeof(request));
327 request.req_id = RTE_AVP_REQ_CFG_DEVICE;
328 memcpy(&request.config, config, sizeof(request.config));
330 ret = avp_dev_process_request(avp, &request);
332 return ret == 0 ? request.result : ret;
336 avp_dev_ctrl_shutdown(struct rte_eth_dev *eth_dev)
338 struct avp_dev *avp = AVP_DEV_PRIVATE_TO_HW(eth_dev->data->dev_private);
339 struct rte_avp_request request;
342 /* setup a shutdown request */
343 memset(&request, 0, sizeof(request));
344 request.req_id = RTE_AVP_REQ_SHUTDOWN_DEVICE;
346 ret = avp_dev_process_request(avp, &request);
348 return ret == 0 ? request.result : ret;
351 /* translate from host mbuf virtual address to guest virtual address */
353 avp_dev_translate_buffer(struct avp_dev *avp, void *host_mbuf_address)
355 return RTE_PTR_ADD(RTE_PTR_SUB(host_mbuf_address,
356 (uintptr_t)avp->host_mbuf_addr),
357 (uintptr_t)avp->mbuf_addr);
360 /* translate from host physical address to guest virtual address */
362 avp_dev_translate_address(struct rte_eth_dev *eth_dev,
363 rte_iova_t host_phys_addr)
365 struct rte_pci_device *pci_dev = RTE_ETH_DEV_TO_PCI(eth_dev);
366 struct rte_mem_resource *resource;
367 struct rte_avp_memmap_info *info;
368 struct rte_avp_memmap *map;
373 addr = pci_dev->mem_resource[RTE_AVP_PCI_MEMORY_BAR].addr;
374 resource = &pci_dev->mem_resource[RTE_AVP_PCI_MEMMAP_BAR];
375 info = (struct rte_avp_memmap_info *)resource->addr;
378 for (i = 0; i < info->nb_maps; i++) {
379 /* search all segments looking for a matching address */
380 map = &info->maps[i];
382 if ((host_phys_addr >= map->phys_addr) &&
383 (host_phys_addr < (map->phys_addr + map->length))) {
384 /* address is within this segment */
385 offset += (host_phys_addr - map->phys_addr);
386 addr = RTE_PTR_ADD(addr, offset);
388 PMD_DRV_LOG(DEBUG, "Translating host physical 0x%" PRIx64 " to guest virtual 0x%p\n",
389 host_phys_addr, addr);
393 offset += map->length;
399 /* verify that the incoming device version is compatible with our version */
401 avp_dev_version_check(uint32_t version)
403 uint32_t driver = RTE_AVP_STRIP_MINOR_VERSION(AVP_DPDK_DRIVER_VERSION);
404 uint32_t device = RTE_AVP_STRIP_MINOR_VERSION(version);
406 if (device <= driver) {
407 /* the host driver version is less than or equal to ours */
414 /* verify that memory regions have expected version and validation markers */
416 avp_dev_check_regions(struct rte_eth_dev *eth_dev)
418 struct rte_pci_device *pci_dev = RTE_ETH_DEV_TO_PCI(eth_dev);
419 struct rte_avp_memmap_info *memmap;
420 struct rte_avp_device_info *info;
421 struct rte_mem_resource *resource;
424 /* Dump resource info for debug */
425 for (i = 0; i < PCI_MAX_RESOURCE; i++) {
426 resource = &pci_dev->mem_resource[i];
427 if ((resource->phys_addr == 0) || (resource->len == 0))
430 PMD_DRV_LOG(DEBUG, "resource[%u]: phys=0x%" PRIx64 " len=%" PRIu64 " addr=%p\n",
431 i, resource->phys_addr,
432 resource->len, resource->addr);
435 case RTE_AVP_PCI_MEMMAP_BAR:
436 memmap = (struct rte_avp_memmap_info *)resource->addr;
437 if ((memmap->magic != RTE_AVP_MEMMAP_MAGIC) ||
438 (memmap->version != RTE_AVP_MEMMAP_VERSION)) {
439 PMD_DRV_LOG(ERR, "Invalid memmap magic 0x%08x and version %u\n",
440 memmap->magic, memmap->version);
445 case RTE_AVP_PCI_DEVICE_BAR:
446 info = (struct rte_avp_device_info *)resource->addr;
447 if ((info->magic != RTE_AVP_DEVICE_MAGIC) ||
448 avp_dev_version_check(info->version)) {
449 PMD_DRV_LOG(ERR, "Invalid device info magic 0x%08x or version 0x%08x > 0x%08x\n",
450 info->magic, info->version,
451 AVP_DPDK_DRIVER_VERSION);
456 case RTE_AVP_PCI_MEMORY_BAR:
457 case RTE_AVP_PCI_MMIO_BAR:
458 if (resource->addr == NULL) {
459 PMD_DRV_LOG(ERR, "Missing address space for BAR%u\n",
465 case RTE_AVP_PCI_MSIX_BAR:
467 /* no validation required */
476 avp_dev_detach(struct rte_eth_dev *eth_dev)
478 struct avp_dev *avp = AVP_DEV_PRIVATE_TO_HW(eth_dev->data->dev_private);
481 PMD_DRV_LOG(NOTICE, "Detaching port %u from AVP device 0x%" PRIx64 "\n",
482 eth_dev->data->port_id, avp->device_id);
484 rte_spinlock_lock(&avp->lock);
486 if (avp->flags & AVP_F_DETACHED) {
487 PMD_DRV_LOG(NOTICE, "port %u already detached\n",
488 eth_dev->data->port_id);
493 /* shutdown the device first so the host stops sending us packets. */
494 ret = avp_dev_ctrl_shutdown(eth_dev);
496 PMD_DRV_LOG(ERR, "Failed to send/recv shutdown to host, ret=%d\n",
498 avp->flags &= ~AVP_F_DETACHED;
502 avp->flags |= AVP_F_DETACHED;
505 /* wait for queues to acknowledge the presence of the detach flag */
511 rte_spinlock_unlock(&avp->lock);
516 _avp_set_rx_queue_mappings(struct rte_eth_dev *eth_dev, uint16_t rx_queue_id)
518 struct avp_dev *avp =
519 AVP_DEV_PRIVATE_TO_HW(eth_dev->data->dev_private);
520 struct avp_queue *rxq;
521 uint16_t queue_count;
524 rxq = (struct avp_queue *)eth_dev->data->rx_queues[rx_queue_id];
527 * Must map all AVP fifos as evenly as possible between the configured
528 * device queues. Each device queue will service a subset of the AVP
529 * fifos. If there is an odd number of device queues the first set of
530 * device queues will get the extra AVP fifos.
532 queue_count = avp->num_rx_queues / eth_dev->data->nb_rx_queues;
533 remainder = avp->num_rx_queues % eth_dev->data->nb_rx_queues;
534 if (rx_queue_id < remainder) {
535 /* these queues must service one extra FIFO */
536 rxq->queue_base = rx_queue_id * (queue_count + 1);
537 rxq->queue_limit = rxq->queue_base + (queue_count + 1) - 1;
539 /* these queues service the regular number of FIFO */
540 rxq->queue_base = ((remainder * (queue_count + 1)) +
541 ((rx_queue_id - remainder) * queue_count));
542 rxq->queue_limit = rxq->queue_base + queue_count - 1;
545 PMD_DRV_LOG(DEBUG, "rxq %u at %p base %u limit %u\n",
546 rx_queue_id, rxq, rxq->queue_base, rxq->queue_limit);
548 rxq->queue_id = rxq->queue_base;
552 _avp_set_queue_counts(struct rte_eth_dev *eth_dev)
554 struct rte_pci_device *pci_dev = RTE_ETH_DEV_TO_PCI(eth_dev);
555 struct avp_dev *avp = AVP_DEV_PRIVATE_TO_HW(eth_dev->data->dev_private);
556 struct rte_avp_device_info *host_info;
559 addr = pci_dev->mem_resource[RTE_AVP_PCI_DEVICE_BAR].addr;
560 host_info = (struct rte_avp_device_info *)addr;
563 * the transmit direction is not negotiated beyond respecting the max
564 * number of queues because the host can handle arbitrary guest tx
565 * queues (host rx queues).
567 avp->num_tx_queues = eth_dev->data->nb_tx_queues;
570 * the receive direction is more restrictive. The host requires a
571 * minimum number of guest rx queues (host tx queues) therefore
572 * negotiate a value that is at least as large as the host minimum
573 * requirement. If the host and guest values are not identical then a
574 * mapping will be established in the receive_queue_setup function.
576 avp->num_rx_queues = RTE_MAX(host_info->min_rx_queues,
577 eth_dev->data->nb_rx_queues);
579 PMD_DRV_LOG(DEBUG, "Requesting %u Tx and %u Rx queues from host\n",
580 avp->num_tx_queues, avp->num_rx_queues);
584 avp_dev_attach(struct rte_eth_dev *eth_dev)
586 struct avp_dev *avp = AVP_DEV_PRIVATE_TO_HW(eth_dev->data->dev_private);
587 struct rte_avp_device_config config;
591 PMD_DRV_LOG(NOTICE, "Attaching port %u to AVP device 0x%" PRIx64 "\n",
592 eth_dev->data->port_id, avp->device_id);
594 rte_spinlock_lock(&avp->lock);
596 if (!(avp->flags & AVP_F_DETACHED)) {
597 PMD_DRV_LOG(NOTICE, "port %u already attached\n",
598 eth_dev->data->port_id);
604 * make sure that the detached flag is set prior to reconfiguring the
607 avp->flags |= AVP_F_DETACHED;
611 * re-run the device create utility which will parse the new host info
612 * and setup the AVP device queue pointers.
614 ret = avp_dev_create(RTE_ETH_DEV_TO_PCI(eth_dev), eth_dev);
616 PMD_DRV_LOG(ERR, "Failed to re-create AVP device, ret=%d\n",
621 if (avp->flags & AVP_F_CONFIGURED) {
623 * Update the receive queue mapping to handle cases where the
624 * source and destination hosts have different queue
625 * requirements. As long as the DETACHED flag is asserted the
626 * queue table should not be referenced so it should be safe to
629 _avp_set_queue_counts(eth_dev);
630 for (i = 0; i < eth_dev->data->nb_rx_queues; i++)
631 _avp_set_rx_queue_mappings(eth_dev, i);
634 * Update the host with our config details so that it knows the
637 memset(&config, 0, sizeof(config));
638 config.device_id = avp->device_id;
639 config.driver_type = RTE_AVP_DRIVER_TYPE_DPDK;
640 config.driver_version = AVP_DPDK_DRIVER_VERSION;
641 config.features = avp->features;
642 config.num_tx_queues = avp->num_tx_queues;
643 config.num_rx_queues = avp->num_rx_queues;
644 config.if_up = !!(avp->flags & AVP_F_LINKUP);
646 ret = avp_dev_ctrl_set_config(eth_dev, &config);
648 PMD_DRV_LOG(ERR, "Config request failed by host, ret=%d\n",
655 avp->flags &= ~AVP_F_DETACHED;
660 rte_spinlock_unlock(&avp->lock);
665 avp_dev_interrupt_handler(void *data)
667 struct rte_eth_dev *eth_dev = data;
668 struct rte_pci_device *pci_dev = RTE_ETH_DEV_TO_PCI(eth_dev);
669 void *registers = pci_dev->mem_resource[RTE_AVP_PCI_MMIO_BAR].addr;
670 uint32_t status, value;
673 if (registers == NULL)
674 rte_panic("no mapped MMIO register space\n");
676 /* read the interrupt status register
677 * note: this register clears on read so all raised interrupts must be
678 * handled or remembered for later processing
681 RTE_PTR_ADD(registers,
682 RTE_AVP_INTERRUPT_STATUS_OFFSET));
684 if (status & RTE_AVP_MIGRATION_INTERRUPT_MASK) {
685 /* handle interrupt based on current status */
687 RTE_PTR_ADD(registers,
688 RTE_AVP_MIGRATION_STATUS_OFFSET));
690 case RTE_AVP_MIGRATION_DETACHED:
691 ret = avp_dev_detach(eth_dev);
693 case RTE_AVP_MIGRATION_ATTACHED:
694 ret = avp_dev_attach(eth_dev);
697 PMD_DRV_LOG(ERR, "unexpected migration status, status=%u\n",
702 /* acknowledge the request by writing out our current status */
703 value = (ret == 0 ? value : RTE_AVP_MIGRATION_ERROR);
705 RTE_PTR_ADD(registers,
706 RTE_AVP_MIGRATION_ACK_OFFSET));
708 PMD_DRV_LOG(NOTICE, "AVP migration interrupt handled\n");
711 if (status & ~RTE_AVP_MIGRATION_INTERRUPT_MASK)
712 PMD_DRV_LOG(WARNING, "AVP unexpected interrupt, status=0x%08x\n",
715 /* re-enable UIO interrupt handling */
716 ret = rte_intr_enable(&pci_dev->intr_handle);
718 PMD_DRV_LOG(ERR, "Failed to re-enable UIO interrupts, ret=%d\n",
725 avp_dev_enable_interrupts(struct rte_eth_dev *eth_dev)
727 struct rte_pci_device *pci_dev = RTE_ETH_DEV_TO_PCI(eth_dev);
728 void *registers = pci_dev->mem_resource[RTE_AVP_PCI_MMIO_BAR].addr;
731 if (registers == NULL)
734 /* enable UIO interrupt handling */
735 ret = rte_intr_enable(&pci_dev->intr_handle);
737 PMD_DRV_LOG(ERR, "Failed to enable UIO interrupts, ret=%d\n",
742 /* inform the device that all interrupts are enabled */
743 AVP_WRITE32(RTE_AVP_APP_INTERRUPTS_MASK,
744 RTE_PTR_ADD(registers, RTE_AVP_INTERRUPT_MASK_OFFSET));
750 avp_dev_disable_interrupts(struct rte_eth_dev *eth_dev)
752 struct rte_pci_device *pci_dev = RTE_ETH_DEV_TO_PCI(eth_dev);
753 void *registers = pci_dev->mem_resource[RTE_AVP_PCI_MMIO_BAR].addr;
756 if (registers == NULL)
759 /* inform the device that all interrupts are disabled */
760 AVP_WRITE32(RTE_AVP_NO_INTERRUPTS_MASK,
761 RTE_PTR_ADD(registers, RTE_AVP_INTERRUPT_MASK_OFFSET));
763 /* enable UIO interrupt handling */
764 ret = rte_intr_disable(&pci_dev->intr_handle);
766 PMD_DRV_LOG(ERR, "Failed to disable UIO interrupts, ret=%d\n",
775 avp_dev_setup_interrupts(struct rte_eth_dev *eth_dev)
777 struct rte_pci_device *pci_dev = RTE_ETH_DEV_TO_PCI(eth_dev);
780 /* register a callback handler with UIO for interrupt notifications */
781 ret = rte_intr_callback_register(&pci_dev->intr_handle,
782 avp_dev_interrupt_handler,
785 PMD_DRV_LOG(ERR, "Failed to register UIO interrupt callback, ret=%d\n",
790 /* enable interrupt processing */
791 return avp_dev_enable_interrupts(eth_dev);
795 avp_dev_migration_pending(struct rte_eth_dev *eth_dev)
797 struct rte_pci_device *pci_dev = RTE_ETH_DEV_TO_PCI(eth_dev);
798 void *registers = pci_dev->mem_resource[RTE_AVP_PCI_MMIO_BAR].addr;
801 if (registers == NULL)
804 value = AVP_READ32(RTE_PTR_ADD(registers,
805 RTE_AVP_MIGRATION_STATUS_OFFSET));
806 if (value == RTE_AVP_MIGRATION_DETACHED) {
807 /* migration is in progress; ack it if we have not already */
809 RTE_PTR_ADD(registers,
810 RTE_AVP_MIGRATION_ACK_OFFSET));
817 * create a AVP device using the supplied device info by first translating it
818 * to guest address space(s).
821 avp_dev_create(struct rte_pci_device *pci_dev,
822 struct rte_eth_dev *eth_dev)
824 struct avp_dev *avp = AVP_DEV_PRIVATE_TO_HW(eth_dev->data->dev_private);
825 struct rte_avp_device_info *host_info;
826 struct rte_mem_resource *resource;
829 resource = &pci_dev->mem_resource[RTE_AVP_PCI_DEVICE_BAR];
830 if (resource->addr == NULL) {
831 PMD_DRV_LOG(ERR, "BAR%u is not mapped\n",
832 RTE_AVP_PCI_DEVICE_BAR);
835 host_info = (struct rte_avp_device_info *)resource->addr;
837 if ((host_info->magic != RTE_AVP_DEVICE_MAGIC) ||
838 avp_dev_version_check(host_info->version)) {
839 PMD_DRV_LOG(ERR, "Invalid AVP PCI device, magic 0x%08x version 0x%08x > 0x%08x\n",
840 host_info->magic, host_info->version,
841 AVP_DPDK_DRIVER_VERSION);
845 PMD_DRV_LOG(DEBUG, "AVP host device is v%u.%u.%u\n",
846 RTE_AVP_GET_RELEASE_VERSION(host_info->version),
847 RTE_AVP_GET_MAJOR_VERSION(host_info->version),
848 RTE_AVP_GET_MINOR_VERSION(host_info->version));
850 PMD_DRV_LOG(DEBUG, "AVP host supports %u to %u TX queue(s)\n",
851 host_info->min_tx_queues, host_info->max_tx_queues);
852 PMD_DRV_LOG(DEBUG, "AVP host supports %u to %u RX queue(s)\n",
853 host_info->min_rx_queues, host_info->max_rx_queues);
854 PMD_DRV_LOG(DEBUG, "AVP host supports features 0x%08x\n",
855 host_info->features);
857 if (avp->magic != AVP_ETHDEV_MAGIC) {
859 * First time initialization (i.e., not during a VM
862 memset(avp, 0, sizeof(*avp));
863 avp->magic = AVP_ETHDEV_MAGIC;
864 avp->dev_data = eth_dev->data;
865 avp->port_id = eth_dev->data->port_id;
866 avp->host_mbuf_size = host_info->mbuf_size;
867 avp->host_features = host_info->features;
868 rte_spinlock_init(&avp->lock);
869 memcpy(&avp->ethaddr.addr_bytes[0],
870 host_info->ethaddr, ETHER_ADDR_LEN);
871 /* adjust max values to not exceed our max */
873 RTE_MIN(host_info->max_tx_queues, RTE_AVP_MAX_QUEUES);
875 RTE_MIN(host_info->max_rx_queues, RTE_AVP_MAX_QUEUES);
877 /* Re-attaching during migration */
879 /* TODO... requires validation of host values */
880 if ((host_info->features & avp->features) != avp->features) {
881 PMD_DRV_LOG(ERR, "AVP host features mismatched; 0x%08x, host=0x%08x\n",
882 avp->features, host_info->features);
883 /* this should not be possible; continue for now */
887 /* the device id is allowed to change over migrations */
888 avp->device_id = host_info->device_id;
890 /* translate incoming host addresses to guest address space */
891 PMD_DRV_LOG(DEBUG, "AVP first host tx queue at 0x%" PRIx64 "\n",
893 PMD_DRV_LOG(DEBUG, "AVP first host alloc queue at 0x%" PRIx64 "\n",
894 host_info->alloc_phys);
895 for (i = 0; i < avp->max_tx_queues; i++) {
896 avp->tx_q[i] = avp_dev_translate_address(eth_dev,
897 host_info->tx_phys + (i * host_info->tx_size));
899 avp->alloc_q[i] = avp_dev_translate_address(eth_dev,
900 host_info->alloc_phys + (i * host_info->alloc_size));
903 PMD_DRV_LOG(DEBUG, "AVP first host rx queue at 0x%" PRIx64 "\n",
905 PMD_DRV_LOG(DEBUG, "AVP first host free queue at 0x%" PRIx64 "\n",
906 host_info->free_phys);
907 for (i = 0; i < avp->max_rx_queues; i++) {
908 avp->rx_q[i] = avp_dev_translate_address(eth_dev,
909 host_info->rx_phys + (i * host_info->rx_size));
910 avp->free_q[i] = avp_dev_translate_address(eth_dev,
911 host_info->free_phys + (i * host_info->free_size));
914 PMD_DRV_LOG(DEBUG, "AVP host request queue at 0x%" PRIx64 "\n",
915 host_info->req_phys);
916 PMD_DRV_LOG(DEBUG, "AVP host response queue at 0x%" PRIx64 "\n",
917 host_info->resp_phys);
918 PMD_DRV_LOG(DEBUG, "AVP host sync address at 0x%" PRIx64 "\n",
919 host_info->sync_phys);
920 PMD_DRV_LOG(DEBUG, "AVP host mbuf address at 0x%" PRIx64 "\n",
921 host_info->mbuf_phys);
922 avp->req_q = avp_dev_translate_address(eth_dev, host_info->req_phys);
923 avp->resp_q = avp_dev_translate_address(eth_dev, host_info->resp_phys);
925 avp_dev_translate_address(eth_dev, host_info->sync_phys);
927 avp_dev_translate_address(eth_dev, host_info->mbuf_phys);
930 * store the host mbuf virtual address so that we can calculate
931 * relative offsets for each mbuf as they are processed
933 avp->host_mbuf_addr = host_info->mbuf_va;
934 avp->host_sync_addr = host_info->sync_va;
937 * store the maximum packet length that is supported by the host.
939 avp->max_rx_pkt_len = host_info->max_rx_pkt_len;
940 PMD_DRV_LOG(DEBUG, "AVP host max receive packet length is %u\n",
941 host_info->max_rx_pkt_len);
947 * This function is based on probe() function in avp_pci.c
948 * It returns 0 on success.
951 eth_avp_dev_init(struct rte_eth_dev *eth_dev)
953 struct avp_dev *avp =
954 AVP_DEV_PRIVATE_TO_HW(eth_dev->data->dev_private);
955 struct rte_pci_device *pci_dev;
958 pci_dev = RTE_ETH_DEV_TO_PCI(eth_dev);
959 eth_dev->dev_ops = &avp_eth_dev_ops;
960 eth_dev->rx_pkt_burst = &avp_recv_pkts;
961 eth_dev->tx_pkt_burst = &avp_xmit_pkts;
963 if (rte_eal_process_type() != RTE_PROC_PRIMARY) {
965 * no setup required on secondary processes. All data is saved
966 * in dev_private by the primary process. All resource should
967 * be mapped to the same virtual address so all pointers should
970 if (eth_dev->data->scattered_rx) {
971 PMD_DRV_LOG(NOTICE, "AVP device configured for chained mbufs\n");
972 eth_dev->rx_pkt_burst = avp_recv_scattered_pkts;
973 eth_dev->tx_pkt_burst = avp_xmit_scattered_pkts;
978 rte_eth_copy_pci_info(eth_dev, pci_dev);
980 /* Check current migration status */
981 if (avp_dev_migration_pending(eth_dev)) {
982 PMD_DRV_LOG(ERR, "VM live migration operation in progress\n");
986 /* Check BAR resources */
987 ret = avp_dev_check_regions(eth_dev);
989 PMD_DRV_LOG(ERR, "Failed to validate BAR resources, ret=%d\n",
994 /* Enable interrupts */
995 ret = avp_dev_setup_interrupts(eth_dev);
997 PMD_DRV_LOG(ERR, "Failed to enable interrupts, ret=%d\n", ret);
1001 /* Handle each subtype */
1002 ret = avp_dev_create(pci_dev, eth_dev);
1004 PMD_DRV_LOG(ERR, "Failed to create device, ret=%d\n", ret);
1008 /* Allocate memory for storing MAC addresses */
1009 eth_dev->data->mac_addrs = rte_zmalloc("avp_ethdev", ETHER_ADDR_LEN, 0);
1010 if (eth_dev->data->mac_addrs == NULL) {
1011 PMD_DRV_LOG(ERR, "Failed to allocate %d bytes needed to store MAC addresses\n",
1016 /* Get a mac from device config */
1017 ether_addr_copy(&avp->ethaddr, ð_dev->data->mac_addrs[0]);
1023 eth_avp_dev_uninit(struct rte_eth_dev *eth_dev)
1027 if (rte_eal_process_type() != RTE_PROC_PRIMARY)
1030 if (eth_dev->data == NULL)
1033 ret = avp_dev_disable_interrupts(eth_dev);
1035 PMD_DRV_LOG(ERR, "Failed to disable interrupts, ret=%d\n", ret);
1039 if (eth_dev->data->mac_addrs != NULL) {
1040 rte_free(eth_dev->data->mac_addrs);
1041 eth_dev->data->mac_addrs = NULL;
1048 eth_avp_pci_probe(struct rte_pci_driver *pci_drv __rte_unused,
1049 struct rte_pci_device *pci_dev)
1051 struct rte_eth_dev *eth_dev;
1054 eth_dev = rte_eth_dev_pci_allocate(pci_dev,
1055 sizeof(struct avp_adapter));
1056 if (eth_dev == NULL)
1059 ret = eth_avp_dev_init(eth_dev);
1061 rte_eth_dev_pci_release(eth_dev);
1067 eth_avp_pci_remove(struct rte_pci_device *pci_dev)
1069 return rte_eth_dev_pci_generic_remove(pci_dev,
1070 eth_avp_dev_uninit);
1073 static struct rte_pci_driver rte_avp_pmd = {
1074 .id_table = pci_id_avp_map,
1075 .drv_flags = RTE_PCI_DRV_NEED_MAPPING,
1076 .probe = eth_avp_pci_probe,
1077 .remove = eth_avp_pci_remove,
1081 avp_dev_enable_scattered(struct rte_eth_dev *eth_dev,
1082 struct avp_dev *avp)
1084 unsigned int max_rx_pkt_len;
1086 max_rx_pkt_len = eth_dev->data->dev_conf.rxmode.max_rx_pkt_len;
1088 if ((max_rx_pkt_len > avp->guest_mbuf_size) ||
1089 (max_rx_pkt_len > avp->host_mbuf_size)) {
1091 * If the guest MTU is greater than either the host or guest
1092 * buffers then chained mbufs have to be enabled in the TX
1093 * direction. It is assumed that the application will not need
1094 * to send packets larger than their max_rx_pkt_len (MRU).
1099 if ((avp->max_rx_pkt_len > avp->guest_mbuf_size) ||
1100 (avp->max_rx_pkt_len > avp->host_mbuf_size)) {
1102 * If the host MRU is greater than its own mbuf size or the
1103 * guest mbuf size then chained mbufs have to be enabled in the
1113 avp_dev_rx_queue_setup(struct rte_eth_dev *eth_dev,
1114 uint16_t rx_queue_id,
1115 uint16_t nb_rx_desc,
1116 unsigned int socket_id,
1117 const struct rte_eth_rxconf *rx_conf,
1118 struct rte_mempool *pool)
1120 struct avp_dev *avp = AVP_DEV_PRIVATE_TO_HW(eth_dev->data->dev_private);
1121 struct rte_pktmbuf_pool_private *mbp_priv;
1122 struct avp_queue *rxq;
1124 if (rx_queue_id >= eth_dev->data->nb_rx_queues) {
1125 PMD_DRV_LOG(ERR, "RX queue id is out of range: rx_queue_id=%u, nb_rx_queues=%u\n",
1126 rx_queue_id, eth_dev->data->nb_rx_queues);
1130 /* Save mbuf pool pointer */
1133 /* Save the local mbuf size */
1134 mbp_priv = rte_mempool_get_priv(pool);
1135 avp->guest_mbuf_size = (uint16_t)(mbp_priv->mbuf_data_room_size);
1136 avp->guest_mbuf_size -= RTE_PKTMBUF_HEADROOM;
1138 if (avp_dev_enable_scattered(eth_dev, avp)) {
1139 if (!eth_dev->data->scattered_rx) {
1140 PMD_DRV_LOG(NOTICE, "AVP device configured for chained mbufs\n");
1141 eth_dev->data->scattered_rx = 1;
1142 eth_dev->rx_pkt_burst = avp_recv_scattered_pkts;
1143 eth_dev->tx_pkt_burst = avp_xmit_scattered_pkts;
1147 PMD_DRV_LOG(DEBUG, "AVP max_rx_pkt_len=(%u,%u) mbuf_size=(%u,%u)\n",
1148 avp->max_rx_pkt_len,
1149 eth_dev->data->dev_conf.rxmode.max_rx_pkt_len,
1150 avp->host_mbuf_size,
1151 avp->guest_mbuf_size);
1153 /* allocate a queue object */
1154 rxq = rte_zmalloc_socket("ethdev RX queue", sizeof(struct avp_queue),
1155 RTE_CACHE_LINE_SIZE, socket_id);
1157 PMD_DRV_LOG(ERR, "Failed to allocate new Rx queue object\n");
1161 /* save back pointers to AVP and Ethernet devices */
1163 rxq->dev_data = eth_dev->data;
1164 eth_dev->data->rx_queues[rx_queue_id] = (void *)rxq;
1166 /* setup the queue receive mapping for the current queue. */
1167 _avp_set_rx_queue_mappings(eth_dev, rx_queue_id);
1169 PMD_DRV_LOG(DEBUG, "Rx queue %u setup at %p\n", rx_queue_id, rxq);
1177 avp_dev_tx_queue_setup(struct rte_eth_dev *eth_dev,
1178 uint16_t tx_queue_id,
1179 uint16_t nb_tx_desc,
1180 unsigned int socket_id,
1181 const struct rte_eth_txconf *tx_conf)
1183 struct avp_dev *avp = AVP_DEV_PRIVATE_TO_HW(eth_dev->data->dev_private);
1184 struct avp_queue *txq;
1186 if (tx_queue_id >= eth_dev->data->nb_tx_queues) {
1187 PMD_DRV_LOG(ERR, "TX queue id is out of range: tx_queue_id=%u, nb_tx_queues=%u\n",
1188 tx_queue_id, eth_dev->data->nb_tx_queues);
1192 /* allocate a queue object */
1193 txq = rte_zmalloc_socket("ethdev TX queue", sizeof(struct avp_queue),
1194 RTE_CACHE_LINE_SIZE, socket_id);
1196 PMD_DRV_LOG(ERR, "Failed to allocate new Tx queue object\n");
1200 /* only the configured set of transmit queues are used */
1201 txq->queue_id = tx_queue_id;
1202 txq->queue_base = tx_queue_id;
1203 txq->queue_limit = tx_queue_id;
1205 /* save back pointers to AVP and Ethernet devices */
1207 txq->dev_data = eth_dev->data;
1208 eth_dev->data->tx_queues[tx_queue_id] = (void *)txq;
1210 PMD_DRV_LOG(DEBUG, "Tx queue %u setup at %p\n", tx_queue_id, txq);
1218 _avp_cmp_ether_addr(struct ether_addr *a, struct ether_addr *b)
1220 uint16_t *_a = (uint16_t *)&a->addr_bytes[0];
1221 uint16_t *_b = (uint16_t *)&b->addr_bytes[0];
1222 return (_a[0] ^ _b[0]) | (_a[1] ^ _b[1]) | (_a[2] ^ _b[2]);
1226 _avp_mac_filter(struct avp_dev *avp, struct rte_mbuf *m)
1228 struct ether_hdr *eth = rte_pktmbuf_mtod(m, struct ether_hdr *);
1230 if (likely(_avp_cmp_ether_addr(&avp->ethaddr, ð->d_addr) == 0)) {
1231 /* allow all packets destined to our address */
1235 if (likely(is_broadcast_ether_addr(ð->d_addr))) {
1236 /* allow all broadcast packets */
1240 if (likely(is_multicast_ether_addr(ð->d_addr))) {
1241 /* allow all multicast packets */
1245 if (avp->flags & AVP_F_PROMISC) {
1246 /* allow all packets when in promiscuous mode */
1253 #ifdef RTE_LIBRTE_AVP_DEBUG_BUFFERS
1255 __avp_dev_buffer_sanity_check(struct avp_dev *avp, struct rte_avp_desc *buf)
1257 struct rte_avp_desc *first_buf;
1258 struct rte_avp_desc *pkt_buf;
1259 unsigned int pkt_len;
1260 unsigned int nb_segs;
1264 first_buf = avp_dev_translate_buffer(avp, buf);
1268 nb_segs = first_buf->nb_segs;
1270 /* Adjust pointers for guest addressing */
1271 pkt_buf = avp_dev_translate_buffer(avp, buf);
1272 if (pkt_buf == NULL)
1273 rte_panic("bad buffer: segment %u has an invalid address %p\n",
1275 pkt_data = avp_dev_translate_buffer(avp, pkt_buf->data);
1276 if (pkt_data == NULL)
1277 rte_panic("bad buffer: segment %u has a NULL data pointer\n",
1279 if (pkt_buf->data_len == 0)
1280 rte_panic("bad buffer: segment %u has 0 data length\n",
1282 pkt_len += pkt_buf->data_len;
1286 } while (nb_segs && (buf = pkt_buf->next) != NULL);
1289 rte_panic("bad buffer: expected %u segments found %u\n",
1290 first_buf->nb_segs, (first_buf->nb_segs - nb_segs));
1291 if (pkt_len != first_buf->pkt_len)
1292 rte_panic("bad buffer: expected length %u found %u\n",
1293 first_buf->pkt_len, pkt_len);
1296 #define avp_dev_buffer_sanity_check(a, b) \
1297 __avp_dev_buffer_sanity_check((a), (b))
1299 #else /* RTE_LIBRTE_AVP_DEBUG_BUFFERS */
1301 #define avp_dev_buffer_sanity_check(a, b) do {} while (0)
1306 * Copy a host buffer chain to a set of mbufs. This function assumes that
1307 * there exactly the required number of mbufs to copy all source bytes.
1309 static inline struct rte_mbuf *
1310 avp_dev_copy_from_buffers(struct avp_dev *avp,
1311 struct rte_avp_desc *buf,
1312 struct rte_mbuf **mbufs,
1315 struct rte_mbuf *m_previous = NULL;
1316 struct rte_avp_desc *pkt_buf;
1317 unsigned int total_length = 0;
1318 unsigned int copy_length;
1319 unsigned int src_offset;
1326 avp_dev_buffer_sanity_check(avp, buf);
1328 /* setup the first source buffer */
1329 pkt_buf = avp_dev_translate_buffer(avp, buf);
1330 pkt_data = avp_dev_translate_buffer(avp, pkt_buf->data);
1331 total_length = pkt_buf->pkt_len;
1334 if (pkt_buf->ol_flags & RTE_AVP_RX_VLAN_PKT) {
1335 ol_flags = PKT_RX_VLAN;
1336 vlan_tci = pkt_buf->vlan_tci;
1342 for (i = 0; (i < count) && (buf != NULL); i++) {
1343 /* fill each destination buffer */
1346 if (m_previous != NULL)
1347 m_previous->next = m;
1353 * Copy as many source buffers as will fit in the
1354 * destination buffer.
1356 copy_length = RTE_MIN((avp->guest_mbuf_size -
1357 rte_pktmbuf_data_len(m)),
1358 (pkt_buf->data_len -
1360 rte_memcpy(RTE_PTR_ADD(rte_pktmbuf_mtod(m, void *),
1361 rte_pktmbuf_data_len(m)),
1362 RTE_PTR_ADD(pkt_data, src_offset),
1364 rte_pktmbuf_data_len(m) += copy_length;
1365 src_offset += copy_length;
1367 if (likely(src_offset == pkt_buf->data_len)) {
1368 /* need a new source buffer */
1369 buf = pkt_buf->next;
1371 pkt_buf = avp_dev_translate_buffer(
1373 pkt_data = avp_dev_translate_buffer(
1374 avp, pkt_buf->data);
1379 if (unlikely(rte_pktmbuf_data_len(m) ==
1380 avp->guest_mbuf_size)) {
1381 /* need a new destination mbuf */
1385 } while (buf != NULL);
1389 m->ol_flags = ol_flags;
1391 rte_pktmbuf_pkt_len(m) = total_length;
1392 m->vlan_tci = vlan_tci;
1394 __rte_mbuf_sanity_check(m, 1);
1400 avp_recv_scattered_pkts(void *rx_queue,
1401 struct rte_mbuf **rx_pkts,
1404 struct avp_queue *rxq = (struct avp_queue *)rx_queue;
1405 struct rte_avp_desc *avp_bufs[AVP_MAX_RX_BURST];
1406 struct rte_mbuf *mbufs[RTE_AVP_MAX_MBUF_SEGMENTS];
1407 struct avp_dev *avp = rxq->avp;
1408 struct rte_avp_desc *pkt_buf;
1409 struct rte_avp_fifo *free_q;
1410 struct rte_avp_fifo *rx_q;
1411 struct rte_avp_desc *buf;
1412 unsigned int count, avail, n;
1413 unsigned int guest_mbuf_size;
1415 unsigned int required;
1416 unsigned int buf_len;
1417 unsigned int port_id;
1420 if (unlikely(avp->flags & AVP_F_DETACHED)) {
1421 /* VM live migration in progress */
1425 guest_mbuf_size = avp->guest_mbuf_size;
1426 port_id = avp->port_id;
1427 rx_q = avp->rx_q[rxq->queue_id];
1428 free_q = avp->free_q[rxq->queue_id];
1430 /* setup next queue to service */
1431 rxq->queue_id = (rxq->queue_id < rxq->queue_limit) ?
1432 (rxq->queue_id + 1) : rxq->queue_base;
1434 /* determine how many slots are available in the free queue */
1435 count = avp_fifo_free_count(free_q);
1437 /* determine how many packets are available in the rx queue */
1438 avail = avp_fifo_count(rx_q);
1440 /* determine how many packets can be received */
1441 count = RTE_MIN(count, avail);
1442 count = RTE_MIN(count, nb_pkts);
1443 count = RTE_MIN(count, (unsigned int)AVP_MAX_RX_BURST);
1445 if (unlikely(count == 0)) {
1446 /* no free buffers, or no buffers on the rx queue */
1450 /* retrieve pending packets */
1451 n = avp_fifo_get(rx_q, (void **)&avp_bufs, count);
1452 PMD_RX_LOG(DEBUG, "Receiving %u packets from Rx queue at %p\n",
1456 for (i = 0; i < n; i++) {
1457 /* prefetch next entry while processing current one */
1459 pkt_buf = avp_dev_translate_buffer(avp,
1461 rte_prefetch0(pkt_buf);
1465 /* Peek into the first buffer to determine the total length */
1466 pkt_buf = avp_dev_translate_buffer(avp, buf);
1467 buf_len = pkt_buf->pkt_len;
1469 /* Allocate enough mbufs to receive the entire packet */
1470 required = (buf_len + guest_mbuf_size - 1) / guest_mbuf_size;
1471 if (rte_pktmbuf_alloc_bulk(avp->pool, mbufs, required)) {
1472 rxq->dev_data->rx_mbuf_alloc_failed++;
1476 /* Copy the data from the buffers to our mbufs */
1477 m = avp_dev_copy_from_buffers(avp, buf, mbufs, required);
1482 if (_avp_mac_filter(avp, m) != 0) {
1483 /* silently discard packets not destined to our MAC */
1484 rte_pktmbuf_free(m);
1488 /* return new mbuf to caller */
1489 rx_pkts[count++] = m;
1490 rxq->bytes += buf_len;
1493 rxq->packets += count;
1495 /* return the buffers to the free queue */
1496 avp_fifo_put(free_q, (void **)&avp_bufs[0], n);
1503 avp_recv_pkts(void *rx_queue,
1504 struct rte_mbuf **rx_pkts,
1507 struct avp_queue *rxq = (struct avp_queue *)rx_queue;
1508 struct rte_avp_desc *avp_bufs[AVP_MAX_RX_BURST];
1509 struct avp_dev *avp = rxq->avp;
1510 struct rte_avp_desc *pkt_buf;
1511 struct rte_avp_fifo *free_q;
1512 struct rte_avp_fifo *rx_q;
1513 unsigned int count, avail, n;
1514 unsigned int pkt_len;
1519 if (unlikely(avp->flags & AVP_F_DETACHED)) {
1520 /* VM live migration in progress */
1524 rx_q = avp->rx_q[rxq->queue_id];
1525 free_q = avp->free_q[rxq->queue_id];
1527 /* setup next queue to service */
1528 rxq->queue_id = (rxq->queue_id < rxq->queue_limit) ?
1529 (rxq->queue_id + 1) : rxq->queue_base;
1531 /* determine how many slots are available in the free queue */
1532 count = avp_fifo_free_count(free_q);
1534 /* determine how many packets are available in the rx queue */
1535 avail = avp_fifo_count(rx_q);
1537 /* determine how many packets can be received */
1538 count = RTE_MIN(count, avail);
1539 count = RTE_MIN(count, nb_pkts);
1540 count = RTE_MIN(count, (unsigned int)AVP_MAX_RX_BURST);
1542 if (unlikely(count == 0)) {
1543 /* no free buffers, or no buffers on the rx queue */
1547 /* retrieve pending packets */
1548 n = avp_fifo_get(rx_q, (void **)&avp_bufs, count);
1549 PMD_RX_LOG(DEBUG, "Receiving %u packets from Rx queue at %p\n",
1553 for (i = 0; i < n; i++) {
1554 /* prefetch next entry while processing current one */
1556 pkt_buf = avp_dev_translate_buffer(avp,
1558 rte_prefetch0(pkt_buf);
1561 /* Adjust host pointers for guest addressing */
1562 pkt_buf = avp_dev_translate_buffer(avp, avp_bufs[i]);
1563 pkt_data = avp_dev_translate_buffer(avp, pkt_buf->data);
1564 pkt_len = pkt_buf->pkt_len;
1566 if (unlikely((pkt_len > avp->guest_mbuf_size) ||
1567 (pkt_buf->nb_segs > 1))) {
1569 * application should be using the scattered receive
1576 /* process each packet to be transmitted */
1577 m = rte_pktmbuf_alloc(avp->pool);
1578 if (unlikely(m == NULL)) {
1579 rxq->dev_data->rx_mbuf_alloc_failed++;
1583 /* copy data out of the host buffer to our buffer */
1584 m->data_off = RTE_PKTMBUF_HEADROOM;
1585 rte_memcpy(rte_pktmbuf_mtod(m, void *), pkt_data, pkt_len);
1587 /* initialize the local mbuf */
1588 rte_pktmbuf_data_len(m) = pkt_len;
1589 rte_pktmbuf_pkt_len(m) = pkt_len;
1590 m->port = avp->port_id;
1592 if (pkt_buf->ol_flags & RTE_AVP_RX_VLAN_PKT) {
1593 m->ol_flags = PKT_RX_VLAN;
1594 m->vlan_tci = pkt_buf->vlan_tci;
1597 if (_avp_mac_filter(avp, m) != 0) {
1598 /* silently discard packets not destined to our MAC */
1599 rte_pktmbuf_free(m);
1603 /* return new mbuf to caller */
1604 rx_pkts[count++] = m;
1605 rxq->bytes += pkt_len;
1608 rxq->packets += count;
1610 /* return the buffers to the free queue */
1611 avp_fifo_put(free_q, (void **)&avp_bufs[0], n);
1617 * Copy a chained mbuf to a set of host buffers. This function assumes that
1618 * there are sufficient destination buffers to contain the entire source
1621 static inline uint16_t
1622 avp_dev_copy_to_buffers(struct avp_dev *avp,
1623 struct rte_mbuf *mbuf,
1624 struct rte_avp_desc **buffers,
1627 struct rte_avp_desc *previous_buf = NULL;
1628 struct rte_avp_desc *first_buf = NULL;
1629 struct rte_avp_desc *pkt_buf;
1630 struct rte_avp_desc *buf;
1631 size_t total_length;
1638 __rte_mbuf_sanity_check(mbuf, 1);
1642 total_length = rte_pktmbuf_pkt_len(m);
1643 for (i = 0; (i < count) && (m != NULL); i++) {
1644 /* fill each destination buffer */
1647 if (i < count - 1) {
1648 /* prefetch next entry while processing this one */
1649 pkt_buf = avp_dev_translate_buffer(avp, buffers[i + 1]);
1650 rte_prefetch0(pkt_buf);
1653 /* Adjust pointers for guest addressing */
1654 pkt_buf = avp_dev_translate_buffer(avp, buf);
1655 pkt_data = avp_dev_translate_buffer(avp, pkt_buf->data);
1657 /* setup the buffer chain */
1658 if (previous_buf != NULL)
1659 previous_buf->next = buf;
1661 first_buf = pkt_buf;
1663 previous_buf = pkt_buf;
1667 * copy as many source mbuf segments as will fit in the
1668 * destination buffer.
1670 copy_length = RTE_MIN((avp->host_mbuf_size -
1672 (rte_pktmbuf_data_len(m) -
1674 rte_memcpy(RTE_PTR_ADD(pkt_data, pkt_buf->data_len),
1675 RTE_PTR_ADD(rte_pktmbuf_mtod(m, void *),
1678 pkt_buf->data_len += copy_length;
1679 src_offset += copy_length;
1681 if (likely(src_offset == rte_pktmbuf_data_len(m))) {
1682 /* need a new source buffer */
1687 if (unlikely(pkt_buf->data_len ==
1688 avp->host_mbuf_size)) {
1689 /* need a new destination buffer */
1693 } while (m != NULL);
1696 first_buf->nb_segs = count;
1697 first_buf->pkt_len = total_length;
1699 if (mbuf->ol_flags & PKT_TX_VLAN_PKT) {
1700 first_buf->ol_flags |= RTE_AVP_TX_VLAN_PKT;
1701 first_buf->vlan_tci = mbuf->vlan_tci;
1704 avp_dev_buffer_sanity_check(avp, buffers[0]);
1706 return total_length;
1711 avp_xmit_scattered_pkts(void *tx_queue,
1712 struct rte_mbuf **tx_pkts,
1715 struct rte_avp_desc *avp_bufs[(AVP_MAX_TX_BURST *
1716 RTE_AVP_MAX_MBUF_SEGMENTS)];
1717 struct avp_queue *txq = (struct avp_queue *)tx_queue;
1718 struct rte_avp_desc *tx_bufs[AVP_MAX_TX_BURST];
1719 struct avp_dev *avp = txq->avp;
1720 struct rte_avp_fifo *alloc_q;
1721 struct rte_avp_fifo *tx_q;
1722 unsigned int count, avail, n;
1723 unsigned int orig_nb_pkts;
1725 unsigned int required;
1726 unsigned int segments;
1727 unsigned int tx_bytes;
1730 orig_nb_pkts = nb_pkts;
1731 if (unlikely(avp->flags & AVP_F_DETACHED)) {
1732 /* VM live migration in progress */
1733 /* TODO ... buffer for X packets then drop? */
1734 txq->errors += nb_pkts;
1738 tx_q = avp->tx_q[txq->queue_id];
1739 alloc_q = avp->alloc_q[txq->queue_id];
1741 /* limit the number of transmitted packets to the max burst size */
1742 if (unlikely(nb_pkts > AVP_MAX_TX_BURST))
1743 nb_pkts = AVP_MAX_TX_BURST;
1745 /* determine how many buffers are available to copy into */
1746 avail = avp_fifo_count(alloc_q);
1747 if (unlikely(avail > (AVP_MAX_TX_BURST *
1748 RTE_AVP_MAX_MBUF_SEGMENTS)))
1749 avail = AVP_MAX_TX_BURST * RTE_AVP_MAX_MBUF_SEGMENTS;
1751 /* determine how many slots are available in the transmit queue */
1752 count = avp_fifo_free_count(tx_q);
1754 /* determine how many packets can be sent */
1755 nb_pkts = RTE_MIN(count, nb_pkts);
1757 /* determine how many packets will fit in the available buffers */
1760 for (i = 0; i < nb_pkts; i++) {
1762 if (likely(i < (unsigned int)nb_pkts - 1)) {
1763 /* prefetch next entry while processing this one */
1764 rte_prefetch0(tx_pkts[i + 1]);
1766 required = (rte_pktmbuf_pkt_len(m) + avp->host_mbuf_size - 1) /
1767 avp->host_mbuf_size;
1769 if (unlikely((required == 0) ||
1770 (required > RTE_AVP_MAX_MBUF_SEGMENTS)))
1772 else if (unlikely(required + segments > avail))
1774 segments += required;
1779 if (unlikely(nb_pkts == 0)) {
1780 /* no available buffers, or no space on the tx queue */
1781 txq->errors += orig_nb_pkts;
1785 PMD_TX_LOG(DEBUG, "Sending %u packets on Tx queue at %p\n",
1788 /* retrieve sufficient send buffers */
1789 n = avp_fifo_get(alloc_q, (void **)&avp_bufs, segments);
1790 if (unlikely(n != segments)) {
1791 PMD_TX_LOG(DEBUG, "Failed to allocate buffers "
1792 "n=%u, segments=%u, orig=%u\n",
1793 n, segments, orig_nb_pkts);
1794 txq->errors += orig_nb_pkts;
1800 for (i = 0; i < nb_pkts; i++) {
1801 /* process each packet to be transmitted */
1804 /* determine how many buffers are required for this packet */
1805 required = (rte_pktmbuf_pkt_len(m) + avp->host_mbuf_size - 1) /
1806 avp->host_mbuf_size;
1808 tx_bytes += avp_dev_copy_to_buffers(avp, m,
1809 &avp_bufs[count], required);
1810 tx_bufs[i] = avp_bufs[count];
1813 /* free the original mbuf */
1814 rte_pktmbuf_free(m);
1817 txq->packets += nb_pkts;
1818 txq->bytes += tx_bytes;
1820 #ifdef RTE_LIBRTE_AVP_DEBUG_BUFFERS
1821 for (i = 0; i < nb_pkts; i++)
1822 avp_dev_buffer_sanity_check(avp, tx_bufs[i]);
1825 /* send the packets */
1826 n = avp_fifo_put(tx_q, (void **)&tx_bufs[0], nb_pkts);
1827 if (unlikely(n != orig_nb_pkts))
1828 txq->errors += (orig_nb_pkts - n);
1835 avp_xmit_pkts(void *tx_queue, struct rte_mbuf **tx_pkts, uint16_t nb_pkts)
1837 struct avp_queue *txq = (struct avp_queue *)tx_queue;
1838 struct rte_avp_desc *avp_bufs[AVP_MAX_TX_BURST];
1839 struct avp_dev *avp = txq->avp;
1840 struct rte_avp_desc *pkt_buf;
1841 struct rte_avp_fifo *alloc_q;
1842 struct rte_avp_fifo *tx_q;
1843 unsigned int count, avail, n;
1845 unsigned int pkt_len;
1846 unsigned int tx_bytes;
1850 if (unlikely(avp->flags & AVP_F_DETACHED)) {
1851 /* VM live migration in progress */
1852 /* TODO ... buffer for X packets then drop?! */
1857 tx_q = avp->tx_q[txq->queue_id];
1858 alloc_q = avp->alloc_q[txq->queue_id];
1860 /* limit the number of transmitted packets to the max burst size */
1861 if (unlikely(nb_pkts > AVP_MAX_TX_BURST))
1862 nb_pkts = AVP_MAX_TX_BURST;
1864 /* determine how many buffers are available to copy into */
1865 avail = avp_fifo_count(alloc_q);
1867 /* determine how many slots are available in the transmit queue */
1868 count = avp_fifo_free_count(tx_q);
1870 /* determine how many packets can be sent */
1871 count = RTE_MIN(count, avail);
1872 count = RTE_MIN(count, nb_pkts);
1874 if (unlikely(count == 0)) {
1875 /* no available buffers, or no space on the tx queue */
1876 txq->errors += nb_pkts;
1880 PMD_TX_LOG(DEBUG, "Sending %u packets on Tx queue at %p\n",
1883 /* retrieve sufficient send buffers */
1884 n = avp_fifo_get(alloc_q, (void **)&avp_bufs, count);
1885 if (unlikely(n != count)) {
1891 for (i = 0; i < count; i++) {
1892 /* prefetch next entry while processing the current one */
1893 if (i < count - 1) {
1894 pkt_buf = avp_dev_translate_buffer(avp,
1896 rte_prefetch0(pkt_buf);
1899 /* process each packet to be transmitted */
1902 /* Adjust pointers for guest addressing */
1903 pkt_buf = avp_dev_translate_buffer(avp, avp_bufs[i]);
1904 pkt_data = avp_dev_translate_buffer(avp, pkt_buf->data);
1905 pkt_len = rte_pktmbuf_pkt_len(m);
1907 if (unlikely((pkt_len > avp->guest_mbuf_size) ||
1908 (pkt_len > avp->host_mbuf_size))) {
1910 * application should be using the scattered transmit
1911 * function; send it truncated to avoid the performance
1912 * hit of having to manage returning the already
1913 * allocated buffer to the free list. This should not
1914 * happen since the application should have set the
1915 * max_rx_pkt_len based on its MTU and it should be
1916 * policing its own packet sizes.
1919 pkt_len = RTE_MIN(avp->guest_mbuf_size,
1920 avp->host_mbuf_size);
1923 /* copy data out of our mbuf and into the AVP buffer */
1924 rte_memcpy(pkt_data, rte_pktmbuf_mtod(m, void *), pkt_len);
1925 pkt_buf->pkt_len = pkt_len;
1926 pkt_buf->data_len = pkt_len;
1927 pkt_buf->nb_segs = 1;
1928 pkt_buf->next = NULL;
1930 if (m->ol_flags & PKT_TX_VLAN_PKT) {
1931 pkt_buf->ol_flags |= RTE_AVP_TX_VLAN_PKT;
1932 pkt_buf->vlan_tci = m->vlan_tci;
1935 tx_bytes += pkt_len;
1937 /* free the original mbuf */
1938 rte_pktmbuf_free(m);
1941 txq->packets += count;
1942 txq->bytes += tx_bytes;
1944 /* send the packets */
1945 n = avp_fifo_put(tx_q, (void **)&avp_bufs[0], count);
1951 avp_dev_rx_queue_release(void *rx_queue)
1953 struct avp_queue *rxq = (struct avp_queue *)rx_queue;
1954 struct avp_dev *avp = rxq->avp;
1955 struct rte_eth_dev_data *data = avp->dev_data;
1958 for (i = 0; i < avp->num_rx_queues; i++) {
1959 if (data->rx_queues[i] == rxq)
1960 data->rx_queues[i] = NULL;
1965 avp_dev_tx_queue_release(void *tx_queue)
1967 struct avp_queue *txq = (struct avp_queue *)tx_queue;
1968 struct avp_dev *avp = txq->avp;
1969 struct rte_eth_dev_data *data = avp->dev_data;
1972 for (i = 0; i < avp->num_tx_queues; i++) {
1973 if (data->tx_queues[i] == txq)
1974 data->tx_queues[i] = NULL;
1979 avp_dev_configure(struct rte_eth_dev *eth_dev)
1981 struct rte_pci_device *pci_dev = RTE_ETH_DEV_TO_PCI(eth_dev);
1982 struct avp_dev *avp = AVP_DEV_PRIVATE_TO_HW(eth_dev->data->dev_private);
1983 struct rte_avp_device_info *host_info;
1984 struct rte_avp_device_config config;
1989 rte_spinlock_lock(&avp->lock);
1990 if (avp->flags & AVP_F_DETACHED) {
1991 PMD_DRV_LOG(ERR, "Operation not supported during VM live migration\n");
1996 addr = pci_dev->mem_resource[RTE_AVP_PCI_DEVICE_BAR].addr;
1997 host_info = (struct rte_avp_device_info *)addr;
1999 /* Setup required number of queues */
2000 _avp_set_queue_counts(eth_dev);
2002 mask = (ETH_VLAN_STRIP_MASK |
2003 ETH_VLAN_FILTER_MASK |
2004 ETH_VLAN_EXTEND_MASK);
2005 ret = avp_vlan_offload_set(eth_dev, mask);
2007 PMD_DRV_LOG(ERR, "VLAN offload set failed by host, ret=%d\n",
2012 /* update device config */
2013 memset(&config, 0, sizeof(config));
2014 config.device_id = host_info->device_id;
2015 config.driver_type = RTE_AVP_DRIVER_TYPE_DPDK;
2016 config.driver_version = AVP_DPDK_DRIVER_VERSION;
2017 config.features = avp->features;
2018 config.num_tx_queues = avp->num_tx_queues;
2019 config.num_rx_queues = avp->num_rx_queues;
2021 ret = avp_dev_ctrl_set_config(eth_dev, &config);
2023 PMD_DRV_LOG(ERR, "Config request failed by host, ret=%d\n",
2028 avp->flags |= AVP_F_CONFIGURED;
2032 rte_spinlock_unlock(&avp->lock);
2037 avp_dev_start(struct rte_eth_dev *eth_dev)
2039 struct avp_dev *avp = AVP_DEV_PRIVATE_TO_HW(eth_dev->data->dev_private);
2042 rte_spinlock_lock(&avp->lock);
2043 if (avp->flags & AVP_F_DETACHED) {
2044 PMD_DRV_LOG(ERR, "Operation not supported during VM live migration\n");
2049 /* update link state */
2050 ret = avp_dev_ctrl_set_link_state(eth_dev, 1);
2052 PMD_DRV_LOG(ERR, "Link state change failed by host, ret=%d\n",
2057 /* remember current link state */
2058 avp->flags |= AVP_F_LINKUP;
2063 rte_spinlock_unlock(&avp->lock);
2068 avp_dev_stop(struct rte_eth_dev *eth_dev)
2070 struct avp_dev *avp = AVP_DEV_PRIVATE_TO_HW(eth_dev->data->dev_private);
2073 rte_spinlock_lock(&avp->lock);
2074 if (avp->flags & AVP_F_DETACHED) {
2075 PMD_DRV_LOG(ERR, "Operation not supported during VM live migration\n");
2079 /* remember current link state */
2080 avp->flags &= ~AVP_F_LINKUP;
2082 /* update link state */
2083 ret = avp_dev_ctrl_set_link_state(eth_dev, 0);
2085 PMD_DRV_LOG(ERR, "Link state change failed by host, ret=%d\n",
2090 rte_spinlock_unlock(&avp->lock);
2094 avp_dev_close(struct rte_eth_dev *eth_dev)
2096 struct avp_dev *avp = AVP_DEV_PRIVATE_TO_HW(eth_dev->data->dev_private);
2099 rte_spinlock_lock(&avp->lock);
2100 if (avp->flags & AVP_F_DETACHED) {
2101 PMD_DRV_LOG(ERR, "Operation not supported during VM live migration\n");
2105 /* remember current link state */
2106 avp->flags &= ~AVP_F_LINKUP;
2107 avp->flags &= ~AVP_F_CONFIGURED;
2109 ret = avp_dev_disable_interrupts(eth_dev);
2111 PMD_DRV_LOG(ERR, "Failed to disable interrupts\n");
2115 /* update device state */
2116 ret = avp_dev_ctrl_shutdown(eth_dev);
2118 PMD_DRV_LOG(ERR, "Device shutdown failed by host, ret=%d\n",
2124 rte_spinlock_unlock(&avp->lock);
2128 avp_dev_link_update(struct rte_eth_dev *eth_dev,
2129 __rte_unused int wait_to_complete)
2131 struct avp_dev *avp = AVP_DEV_PRIVATE_TO_HW(eth_dev->data->dev_private);
2132 struct rte_eth_link *link = ð_dev->data->dev_link;
2134 link->link_speed = ETH_SPEED_NUM_10G;
2135 link->link_duplex = ETH_LINK_FULL_DUPLEX;
2136 link->link_status = !!(avp->flags & AVP_F_LINKUP);
2142 avp_dev_promiscuous_enable(struct rte_eth_dev *eth_dev)
2144 struct avp_dev *avp = AVP_DEV_PRIVATE_TO_HW(eth_dev->data->dev_private);
2146 rte_spinlock_lock(&avp->lock);
2147 if ((avp->flags & AVP_F_PROMISC) == 0) {
2148 avp->flags |= AVP_F_PROMISC;
2149 PMD_DRV_LOG(DEBUG, "Promiscuous mode enabled on %u\n",
2150 eth_dev->data->port_id);
2152 rte_spinlock_unlock(&avp->lock);
2156 avp_dev_promiscuous_disable(struct rte_eth_dev *eth_dev)
2158 struct avp_dev *avp = AVP_DEV_PRIVATE_TO_HW(eth_dev->data->dev_private);
2160 rte_spinlock_lock(&avp->lock);
2161 if ((avp->flags & AVP_F_PROMISC) != 0) {
2162 avp->flags &= ~AVP_F_PROMISC;
2163 PMD_DRV_LOG(DEBUG, "Promiscuous mode disabled on %u\n",
2164 eth_dev->data->port_id);
2166 rte_spinlock_unlock(&avp->lock);
2170 avp_dev_info_get(struct rte_eth_dev *eth_dev,
2171 struct rte_eth_dev_info *dev_info)
2173 struct avp_dev *avp = AVP_DEV_PRIVATE_TO_HW(eth_dev->data->dev_private);
2175 dev_info->max_rx_queues = avp->max_rx_queues;
2176 dev_info->max_tx_queues = avp->max_tx_queues;
2177 dev_info->min_rx_bufsize = AVP_MIN_RX_BUFSIZE;
2178 dev_info->max_rx_pktlen = avp->max_rx_pkt_len;
2179 dev_info->max_mac_addrs = AVP_MAX_MAC_ADDRS;
2180 if (avp->host_features & RTE_AVP_FEATURE_VLAN_OFFLOAD) {
2181 dev_info->rx_offload_capa = DEV_RX_OFFLOAD_VLAN_STRIP;
2182 dev_info->tx_offload_capa = DEV_TX_OFFLOAD_VLAN_INSERT;
2187 avp_vlan_offload_set(struct rte_eth_dev *eth_dev, int mask)
2189 struct avp_dev *avp = AVP_DEV_PRIVATE_TO_HW(eth_dev->data->dev_private);
2190 struct rte_eth_conf *dev_conf = ð_dev->data->dev_conf;
2191 uint64_t offloads = dev_conf->rxmode.offloads;
2193 if (mask & ETH_VLAN_STRIP_MASK) {
2194 if (avp->host_features & RTE_AVP_FEATURE_VLAN_OFFLOAD) {
2195 if (offloads & DEV_RX_OFFLOAD_VLAN_STRIP)
2196 avp->features |= RTE_AVP_FEATURE_VLAN_OFFLOAD;
2198 avp->features &= ~RTE_AVP_FEATURE_VLAN_OFFLOAD;
2200 PMD_DRV_LOG(ERR, "VLAN strip offload not supported\n");
2204 if (mask & ETH_VLAN_FILTER_MASK) {
2205 if (offloads & DEV_RX_OFFLOAD_VLAN_FILTER)
2206 PMD_DRV_LOG(ERR, "VLAN filter offload not supported\n");
2209 if (mask & ETH_VLAN_EXTEND_MASK) {
2210 if (offloads & DEV_RX_OFFLOAD_VLAN_EXTEND)
2211 PMD_DRV_LOG(ERR, "VLAN extend offload not supported\n");
2218 avp_dev_stats_get(struct rte_eth_dev *eth_dev, struct rte_eth_stats *stats)
2220 struct avp_dev *avp = AVP_DEV_PRIVATE_TO_HW(eth_dev->data->dev_private);
2223 for (i = 0; i < avp->num_rx_queues; i++) {
2224 struct avp_queue *rxq = avp->dev_data->rx_queues[i];
2227 stats->ipackets += rxq->packets;
2228 stats->ibytes += rxq->bytes;
2229 stats->ierrors += rxq->errors;
2231 stats->q_ipackets[i] += rxq->packets;
2232 stats->q_ibytes[i] += rxq->bytes;
2233 stats->q_errors[i] += rxq->errors;
2237 for (i = 0; i < avp->num_tx_queues; i++) {
2238 struct avp_queue *txq = avp->dev_data->tx_queues[i];
2241 stats->opackets += txq->packets;
2242 stats->obytes += txq->bytes;
2243 stats->oerrors += txq->errors;
2245 stats->q_opackets[i] += txq->packets;
2246 stats->q_obytes[i] += txq->bytes;
2247 stats->q_errors[i] += txq->errors;
2255 avp_dev_stats_reset(struct rte_eth_dev *eth_dev)
2257 struct avp_dev *avp = AVP_DEV_PRIVATE_TO_HW(eth_dev->data->dev_private);
2260 for (i = 0; i < avp->num_rx_queues; i++) {
2261 struct avp_queue *rxq = avp->dev_data->rx_queues[i];
2270 for (i = 0; i < avp->num_tx_queues; i++) {
2271 struct avp_queue *txq = avp->dev_data->tx_queues[i];
2281 RTE_PMD_REGISTER_PCI(net_avp, rte_avp_pmd);
2282 RTE_PMD_REGISTER_PCI_TABLE(net_avp, pci_id_avp_map);
2284 RTE_INIT(avp_init_log);
2288 avp_logtype_driver = rte_log_register("pmd.net.avp.driver");
2289 if (avp_logtype_driver >= 0)
2290 rte_log_set_level(avp_logtype_driver, RTE_LOG_NOTICE);