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 static int avp_dev_create(struct rte_pci_device *pci_dev,
36 struct rte_eth_dev *eth_dev);
38 static int avp_dev_configure(struct rte_eth_dev *dev);
39 static int avp_dev_start(struct rte_eth_dev *dev);
40 static void avp_dev_stop(struct rte_eth_dev *dev);
41 static int avp_dev_close(struct rte_eth_dev *dev);
42 static int avp_dev_info_get(struct rte_eth_dev *dev,
43 struct rte_eth_dev_info *dev_info);
44 static int avp_vlan_offload_set(struct rte_eth_dev *dev, int mask);
45 static int avp_dev_link_update(struct rte_eth_dev *dev, int wait_to_complete);
46 static int avp_dev_promiscuous_enable(struct rte_eth_dev *dev);
47 static int avp_dev_promiscuous_disable(struct rte_eth_dev *dev);
49 static int avp_dev_rx_queue_setup(struct rte_eth_dev *dev,
52 unsigned int socket_id,
53 const struct rte_eth_rxconf *rx_conf,
54 struct rte_mempool *pool);
56 static int avp_dev_tx_queue_setup(struct rte_eth_dev *dev,
59 unsigned int socket_id,
60 const struct rte_eth_txconf *tx_conf);
62 static uint16_t avp_recv_scattered_pkts(void *rx_queue,
63 struct rte_mbuf **rx_pkts,
66 static uint16_t avp_recv_pkts(void *rx_queue,
67 struct rte_mbuf **rx_pkts,
70 static uint16_t avp_xmit_scattered_pkts(void *tx_queue,
71 struct rte_mbuf **tx_pkts,
74 static uint16_t avp_xmit_pkts(void *tx_queue,
75 struct rte_mbuf **tx_pkts,
78 static void avp_dev_rx_queue_release(void *rxq);
79 static void avp_dev_tx_queue_release(void *txq);
81 static int avp_dev_stats_get(struct rte_eth_dev *dev,
82 struct rte_eth_stats *stats);
83 static int avp_dev_stats_reset(struct rte_eth_dev *dev);
86 #define AVP_MAX_RX_BURST 64
87 #define AVP_MAX_TX_BURST 64
88 #define AVP_MAX_MAC_ADDRS 1
89 #define AVP_MIN_RX_BUFSIZE RTE_ETHER_MIN_LEN
93 * Defines the number of microseconds to wait before checking the response
94 * queue for completion.
96 #define AVP_REQUEST_DELAY_USECS (5000)
99 * Defines the number times to check the response queue for completion before
100 * declaring a timeout.
102 #define AVP_MAX_REQUEST_RETRY (100)
104 /* Defines the current PCI driver version number */
105 #define AVP_DPDK_DRIVER_VERSION RTE_AVP_CURRENT_GUEST_VERSION
108 * The set of PCI devices this driver supports
110 static const struct rte_pci_id pci_id_avp_map[] = {
111 { .vendor_id = RTE_AVP_PCI_VENDOR_ID,
112 .device_id = RTE_AVP_PCI_DEVICE_ID,
113 .subsystem_vendor_id = RTE_AVP_PCI_SUB_VENDOR_ID,
114 .subsystem_device_id = RTE_AVP_PCI_SUB_DEVICE_ID,
115 .class_id = RTE_CLASS_ANY_ID,
118 { .vendor_id = 0, /* sentinel */
123 * dev_ops for avp, bare necessities for basic operation
125 static const struct eth_dev_ops avp_eth_dev_ops = {
126 .dev_configure = avp_dev_configure,
127 .dev_start = avp_dev_start,
128 .dev_stop = avp_dev_stop,
129 .dev_close = avp_dev_close,
130 .dev_infos_get = avp_dev_info_get,
131 .vlan_offload_set = avp_vlan_offload_set,
132 .stats_get = avp_dev_stats_get,
133 .stats_reset = avp_dev_stats_reset,
134 .link_update = avp_dev_link_update,
135 .promiscuous_enable = avp_dev_promiscuous_enable,
136 .promiscuous_disable = avp_dev_promiscuous_disable,
137 .rx_queue_setup = avp_dev_rx_queue_setup,
138 .rx_queue_release = avp_dev_rx_queue_release,
139 .tx_queue_setup = avp_dev_tx_queue_setup,
140 .tx_queue_release = avp_dev_tx_queue_release,
143 /**@{ AVP device flags */
144 #define AVP_F_PROMISC (1 << 1)
145 #define AVP_F_CONFIGURED (1 << 2)
146 #define AVP_F_LINKUP (1 << 3)
147 #define AVP_F_DETACHED (1 << 4)
150 /* Ethernet device validation marker */
151 #define AVP_ETHDEV_MAGIC 0x92972862
154 * Defines the AVP device attributes which are attached to an RTE ethernet
158 uint32_t magic; /**< Memory validation marker */
159 uint64_t device_id; /**< Unique system identifier */
160 struct rte_ether_addr ethaddr; /**< Host specified MAC address */
161 struct rte_eth_dev_data *dev_data;
162 /**< Back pointer to ethernet device data */
163 volatile uint32_t flags; /**< Device operational flags */
164 uint16_t port_id; /**< Ethernet port identifier */
165 struct rte_mempool *pool; /**< pkt mbuf mempool */
166 unsigned int guest_mbuf_size; /**< local pool mbuf size */
167 unsigned int host_mbuf_size; /**< host mbuf size */
168 unsigned int max_rx_pkt_len; /**< maximum receive unit */
169 uint32_t host_features; /**< Supported feature bitmap */
170 uint32_t features; /**< Enabled feature bitmap */
171 unsigned int num_tx_queues; /**< Negotiated number of transmit queues */
172 unsigned int max_tx_queues; /**< Maximum number of transmit queues */
173 unsigned int num_rx_queues; /**< Negotiated number of receive queues */
174 unsigned int max_rx_queues; /**< Maximum number of receive queues */
176 struct rte_avp_fifo *tx_q[RTE_AVP_MAX_QUEUES]; /**< TX queue */
177 struct rte_avp_fifo *rx_q[RTE_AVP_MAX_QUEUES]; /**< RX queue */
178 struct rte_avp_fifo *alloc_q[RTE_AVP_MAX_QUEUES];
179 /**< Allocated mbufs queue */
180 struct rte_avp_fifo *free_q[RTE_AVP_MAX_QUEUES];
181 /**< To be freed mbufs queue */
183 /* mutual exclusion over the 'flag' and 'resp_q/req_q' fields */
186 /* For request & response */
187 struct rte_avp_fifo *req_q; /**< Request queue */
188 struct rte_avp_fifo *resp_q; /**< Response queue */
189 void *host_sync_addr; /**< (host) Req/Resp Mem address */
190 void *sync_addr; /**< Req/Resp Mem address */
191 void *host_mbuf_addr; /**< (host) MBUF pool start address */
192 void *mbuf_addr; /**< MBUF pool start address */
193 } __rte_cache_aligned;
195 /* RTE ethernet private data */
198 } __rte_cache_aligned;
201 /* 32-bit MMIO register write */
202 #define AVP_WRITE32(_value, _addr) rte_write32_relaxed((_value), (_addr))
204 /* 32-bit MMIO register read */
205 #define AVP_READ32(_addr) rte_read32_relaxed((_addr))
207 /* Macro to cast the ethernet device private data to a AVP object */
208 #define AVP_DEV_PRIVATE_TO_HW(adapter) \
209 (&((struct avp_adapter *)adapter)->avp)
212 * Defines the structure of a AVP device queue for the purpose of handling the
213 * receive and transmit burst callback functions
216 struct rte_eth_dev_data *dev_data;
217 /**< Backpointer to ethernet device data */
218 struct avp_dev *avp; /**< Backpointer to AVP device */
220 /**< Queue identifier used for indexing current queue */
222 /**< Base queue identifier for queue servicing */
223 uint16_t queue_limit;
224 /**< Maximum queue identifier for queue servicing */
231 /* send a request and wait for a response
233 * @warning must be called while holding the avp->lock spinlock.
236 avp_dev_process_request(struct avp_dev *avp, struct rte_avp_request *request)
238 unsigned int retry = AVP_MAX_REQUEST_RETRY;
239 void *resp_addr = NULL;
243 PMD_DRV_LOG(DEBUG, "Sending request %u to host\n", request->req_id);
245 request->result = -ENOTSUP;
247 /* Discard any stale responses before starting a new request */
248 while (avp_fifo_get(avp->resp_q, (void **)&resp_addr, 1))
249 PMD_DRV_LOG(DEBUG, "Discarding stale response\n");
251 rte_memcpy(avp->sync_addr, request, sizeof(*request));
252 count = avp_fifo_put(avp->req_q, &avp->host_sync_addr, 1);
254 PMD_DRV_LOG(ERR, "Cannot send request %u to host\n",
261 /* wait for a response */
262 usleep(AVP_REQUEST_DELAY_USECS);
264 count = avp_fifo_count(avp->resp_q);
266 /* response received */
270 if ((count < 1) && (retry == 0)) {
271 PMD_DRV_LOG(ERR, "Timeout while waiting for a response for %u\n",
278 /* retrieve the response */
279 count = avp_fifo_get(avp->resp_q, (void **)&resp_addr, 1);
280 if ((count != 1) || (resp_addr != avp->host_sync_addr)) {
281 PMD_DRV_LOG(ERR, "Invalid response from host, count=%u resp=%p host_sync_addr=%p\n",
282 count, resp_addr, avp->host_sync_addr);
287 /* copy to user buffer */
288 rte_memcpy(request, avp->sync_addr, sizeof(*request));
291 PMD_DRV_LOG(DEBUG, "Result %d received for request %u\n",
292 request->result, request->req_id);
299 avp_dev_ctrl_set_link_state(struct rte_eth_dev *eth_dev, unsigned int state)
301 struct avp_dev *avp = AVP_DEV_PRIVATE_TO_HW(eth_dev->data->dev_private);
302 struct rte_avp_request request;
305 /* setup a link state change request */
306 memset(&request, 0, sizeof(request));
307 request.req_id = RTE_AVP_REQ_CFG_NETWORK_IF;
308 request.if_up = state;
310 ret = avp_dev_process_request(avp, &request);
312 return ret == 0 ? request.result : ret;
316 avp_dev_ctrl_set_config(struct rte_eth_dev *eth_dev,
317 struct rte_avp_device_config *config)
319 struct avp_dev *avp = AVP_DEV_PRIVATE_TO_HW(eth_dev->data->dev_private);
320 struct rte_avp_request request;
323 /* setup a configure request */
324 memset(&request, 0, sizeof(request));
325 request.req_id = RTE_AVP_REQ_CFG_DEVICE;
326 memcpy(&request.config, config, sizeof(request.config));
328 ret = avp_dev_process_request(avp, &request);
330 return ret == 0 ? request.result : ret;
334 avp_dev_ctrl_shutdown(struct rte_eth_dev *eth_dev)
336 struct avp_dev *avp = AVP_DEV_PRIVATE_TO_HW(eth_dev->data->dev_private);
337 struct rte_avp_request request;
340 /* setup a shutdown request */
341 memset(&request, 0, sizeof(request));
342 request.req_id = RTE_AVP_REQ_SHUTDOWN_DEVICE;
344 ret = avp_dev_process_request(avp, &request);
346 return ret == 0 ? request.result : ret;
349 /* translate from host mbuf virtual address to guest virtual address */
351 avp_dev_translate_buffer(struct avp_dev *avp, void *host_mbuf_address)
353 return RTE_PTR_ADD(RTE_PTR_SUB(host_mbuf_address,
354 (uintptr_t)avp->host_mbuf_addr),
355 (uintptr_t)avp->mbuf_addr);
358 /* translate from host physical address to guest virtual address */
360 avp_dev_translate_address(struct rte_eth_dev *eth_dev,
361 rte_iova_t host_phys_addr)
363 struct rte_pci_device *pci_dev = RTE_ETH_DEV_TO_PCI(eth_dev);
364 struct rte_mem_resource *resource;
365 struct rte_avp_memmap_info *info;
366 struct rte_avp_memmap *map;
371 addr = pci_dev->mem_resource[RTE_AVP_PCI_MEMORY_BAR].addr;
372 resource = &pci_dev->mem_resource[RTE_AVP_PCI_MEMMAP_BAR];
373 info = (struct rte_avp_memmap_info *)resource->addr;
376 for (i = 0; i < info->nb_maps; i++) {
377 /* search all segments looking for a matching address */
378 map = &info->maps[i];
380 if ((host_phys_addr >= map->phys_addr) &&
381 (host_phys_addr < (map->phys_addr + map->length))) {
382 /* address is within this segment */
383 offset += (host_phys_addr - map->phys_addr);
384 addr = RTE_PTR_ADD(addr, (uintptr_t)offset);
386 PMD_DRV_LOG(DEBUG, "Translating host physical 0x%" PRIx64 " to guest virtual 0x%p\n",
387 host_phys_addr, addr);
391 offset += map->length;
397 /* verify that the incoming device version is compatible with our version */
399 avp_dev_version_check(uint32_t version)
401 uint32_t driver = RTE_AVP_STRIP_MINOR_VERSION(AVP_DPDK_DRIVER_VERSION);
402 uint32_t device = RTE_AVP_STRIP_MINOR_VERSION(version);
404 if (device <= driver) {
405 /* the host driver version is less than or equal to ours */
412 /* verify that memory regions have expected version and validation markers */
414 avp_dev_check_regions(struct rte_eth_dev *eth_dev)
416 struct rte_pci_device *pci_dev = RTE_ETH_DEV_TO_PCI(eth_dev);
417 struct rte_avp_memmap_info *memmap;
418 struct rte_avp_device_info *info;
419 struct rte_mem_resource *resource;
422 /* Dump resource info for debug */
423 for (i = 0; i < PCI_MAX_RESOURCE; i++) {
424 resource = &pci_dev->mem_resource[i];
425 if ((resource->phys_addr == 0) || (resource->len == 0))
428 PMD_DRV_LOG(DEBUG, "resource[%u]: phys=0x%" PRIx64 " len=%" PRIu64 " addr=%p\n",
429 i, resource->phys_addr,
430 resource->len, resource->addr);
433 case RTE_AVP_PCI_MEMMAP_BAR:
434 memmap = (struct rte_avp_memmap_info *)resource->addr;
435 if ((memmap->magic != RTE_AVP_MEMMAP_MAGIC) ||
436 (memmap->version != RTE_AVP_MEMMAP_VERSION)) {
437 PMD_DRV_LOG(ERR, "Invalid memmap magic 0x%08x and version %u\n",
438 memmap->magic, memmap->version);
443 case RTE_AVP_PCI_DEVICE_BAR:
444 info = (struct rte_avp_device_info *)resource->addr;
445 if ((info->magic != RTE_AVP_DEVICE_MAGIC) ||
446 avp_dev_version_check(info->version)) {
447 PMD_DRV_LOG(ERR, "Invalid device info magic 0x%08x or version 0x%08x > 0x%08x\n",
448 info->magic, info->version,
449 AVP_DPDK_DRIVER_VERSION);
454 case RTE_AVP_PCI_MEMORY_BAR:
455 case RTE_AVP_PCI_MMIO_BAR:
456 if (resource->addr == NULL) {
457 PMD_DRV_LOG(ERR, "Missing address space for BAR%u\n",
463 case RTE_AVP_PCI_MSIX_BAR:
465 /* no validation required */
474 avp_dev_detach(struct rte_eth_dev *eth_dev)
476 struct avp_dev *avp = AVP_DEV_PRIVATE_TO_HW(eth_dev->data->dev_private);
479 PMD_DRV_LOG(NOTICE, "Detaching port %u from AVP device 0x%" PRIx64 "\n",
480 eth_dev->data->port_id, avp->device_id);
482 rte_spinlock_lock(&avp->lock);
484 if (avp->flags & AVP_F_DETACHED) {
485 PMD_DRV_LOG(NOTICE, "port %u already detached\n",
486 eth_dev->data->port_id);
491 /* shutdown the device first so the host stops sending us packets. */
492 ret = avp_dev_ctrl_shutdown(eth_dev);
494 PMD_DRV_LOG(ERR, "Failed to send/recv shutdown to host, ret=%d\n",
496 avp->flags &= ~AVP_F_DETACHED;
500 avp->flags |= AVP_F_DETACHED;
503 /* wait for queues to acknowledge the presence of the detach flag */
509 rte_spinlock_unlock(&avp->lock);
514 _avp_set_rx_queue_mappings(struct rte_eth_dev *eth_dev, uint16_t rx_queue_id)
516 struct avp_dev *avp =
517 AVP_DEV_PRIVATE_TO_HW(eth_dev->data->dev_private);
518 struct avp_queue *rxq;
519 uint16_t queue_count;
522 rxq = (struct avp_queue *)eth_dev->data->rx_queues[rx_queue_id];
525 * Must map all AVP fifos as evenly as possible between the configured
526 * device queues. Each device queue will service a subset of the AVP
527 * fifos. If there is an odd number of device queues the first set of
528 * device queues will get the extra AVP fifos.
530 queue_count = avp->num_rx_queues / eth_dev->data->nb_rx_queues;
531 remainder = avp->num_rx_queues % eth_dev->data->nb_rx_queues;
532 if (rx_queue_id < remainder) {
533 /* these queues must service one extra FIFO */
534 rxq->queue_base = rx_queue_id * (queue_count + 1);
535 rxq->queue_limit = rxq->queue_base + (queue_count + 1) - 1;
537 /* these queues service the regular number of FIFO */
538 rxq->queue_base = ((remainder * (queue_count + 1)) +
539 ((rx_queue_id - remainder) * queue_count));
540 rxq->queue_limit = rxq->queue_base + queue_count - 1;
543 PMD_DRV_LOG(DEBUG, "rxq %u at %p base %u limit %u\n",
544 rx_queue_id, rxq, rxq->queue_base, rxq->queue_limit);
546 rxq->queue_id = rxq->queue_base;
550 _avp_set_queue_counts(struct rte_eth_dev *eth_dev)
552 struct rte_pci_device *pci_dev = RTE_ETH_DEV_TO_PCI(eth_dev);
553 struct avp_dev *avp = AVP_DEV_PRIVATE_TO_HW(eth_dev->data->dev_private);
554 struct rte_avp_device_info *host_info;
557 addr = pci_dev->mem_resource[RTE_AVP_PCI_DEVICE_BAR].addr;
558 host_info = (struct rte_avp_device_info *)addr;
561 * the transmit direction is not negotiated beyond respecting the max
562 * number of queues because the host can handle arbitrary guest tx
563 * queues (host rx queues).
565 avp->num_tx_queues = eth_dev->data->nb_tx_queues;
568 * the receive direction is more restrictive. The host requires a
569 * minimum number of guest rx queues (host tx queues) therefore
570 * negotiate a value that is at least as large as the host minimum
571 * requirement. If the host and guest values are not identical then a
572 * mapping will be established in the receive_queue_setup function.
574 avp->num_rx_queues = RTE_MAX(host_info->min_rx_queues,
575 eth_dev->data->nb_rx_queues);
577 PMD_DRV_LOG(DEBUG, "Requesting %u Tx and %u Rx queues from host\n",
578 avp->num_tx_queues, avp->num_rx_queues);
582 avp_dev_attach(struct rte_eth_dev *eth_dev)
584 struct avp_dev *avp = AVP_DEV_PRIVATE_TO_HW(eth_dev->data->dev_private);
585 struct rte_avp_device_config config;
589 PMD_DRV_LOG(NOTICE, "Attaching port %u to AVP device 0x%" PRIx64 "\n",
590 eth_dev->data->port_id, avp->device_id);
592 rte_spinlock_lock(&avp->lock);
594 if (!(avp->flags & AVP_F_DETACHED)) {
595 PMD_DRV_LOG(NOTICE, "port %u already attached\n",
596 eth_dev->data->port_id);
602 * make sure that the detached flag is set prior to reconfiguring the
605 avp->flags |= AVP_F_DETACHED;
609 * re-run the device create utility which will parse the new host info
610 * and setup the AVP device queue pointers.
612 ret = avp_dev_create(RTE_ETH_DEV_TO_PCI(eth_dev), eth_dev);
614 PMD_DRV_LOG(ERR, "Failed to re-create AVP device, ret=%d\n",
619 if (avp->flags & AVP_F_CONFIGURED) {
621 * Update the receive queue mapping to handle cases where the
622 * source and destination hosts have different queue
623 * requirements. As long as the DETACHED flag is asserted the
624 * queue table should not be referenced so it should be safe to
627 _avp_set_queue_counts(eth_dev);
628 for (i = 0; i < eth_dev->data->nb_rx_queues; i++)
629 _avp_set_rx_queue_mappings(eth_dev, i);
632 * Update the host with our config details so that it knows the
635 memset(&config, 0, sizeof(config));
636 config.device_id = avp->device_id;
637 config.driver_type = RTE_AVP_DRIVER_TYPE_DPDK;
638 config.driver_version = AVP_DPDK_DRIVER_VERSION;
639 config.features = avp->features;
640 config.num_tx_queues = avp->num_tx_queues;
641 config.num_rx_queues = avp->num_rx_queues;
642 config.if_up = !!(avp->flags & AVP_F_LINKUP);
644 ret = avp_dev_ctrl_set_config(eth_dev, &config);
646 PMD_DRV_LOG(ERR, "Config request failed by host, ret=%d\n",
653 avp->flags &= ~AVP_F_DETACHED;
658 rte_spinlock_unlock(&avp->lock);
663 avp_dev_interrupt_handler(void *data)
665 struct rte_eth_dev *eth_dev = data;
666 struct rte_pci_device *pci_dev = RTE_ETH_DEV_TO_PCI(eth_dev);
667 void *registers = pci_dev->mem_resource[RTE_AVP_PCI_MMIO_BAR].addr;
668 uint32_t status, value;
671 if (registers == NULL)
672 rte_panic("no mapped MMIO register space\n");
674 /* read the interrupt status register
675 * note: this register clears on read so all raised interrupts must be
676 * handled or remembered for later processing
679 RTE_PTR_ADD(registers,
680 RTE_AVP_INTERRUPT_STATUS_OFFSET));
682 if (status & RTE_AVP_MIGRATION_INTERRUPT_MASK) {
683 /* handle interrupt based on current status */
685 RTE_PTR_ADD(registers,
686 RTE_AVP_MIGRATION_STATUS_OFFSET));
688 case RTE_AVP_MIGRATION_DETACHED:
689 ret = avp_dev_detach(eth_dev);
691 case RTE_AVP_MIGRATION_ATTACHED:
692 ret = avp_dev_attach(eth_dev);
695 PMD_DRV_LOG(ERR, "unexpected migration status, status=%u\n",
700 /* acknowledge the request by writing out our current status */
701 value = (ret == 0 ? value : RTE_AVP_MIGRATION_ERROR);
703 RTE_PTR_ADD(registers,
704 RTE_AVP_MIGRATION_ACK_OFFSET));
706 PMD_DRV_LOG(NOTICE, "AVP migration interrupt handled\n");
709 if (status & ~RTE_AVP_MIGRATION_INTERRUPT_MASK)
710 PMD_DRV_LOG(WARNING, "AVP unexpected interrupt, status=0x%08x\n",
713 /* re-enable UIO interrupt handling */
714 ret = rte_intr_ack(&pci_dev->intr_handle);
716 PMD_DRV_LOG(ERR, "Failed to re-enable UIO interrupts, ret=%d\n",
723 avp_dev_enable_interrupts(struct rte_eth_dev *eth_dev)
725 struct rte_pci_device *pci_dev = RTE_ETH_DEV_TO_PCI(eth_dev);
726 void *registers = pci_dev->mem_resource[RTE_AVP_PCI_MMIO_BAR].addr;
729 if (registers == NULL)
732 /* enable UIO interrupt handling */
733 ret = rte_intr_enable(&pci_dev->intr_handle);
735 PMD_DRV_LOG(ERR, "Failed to enable UIO interrupts, ret=%d\n",
740 /* inform the device that all interrupts are enabled */
741 AVP_WRITE32(RTE_AVP_APP_INTERRUPTS_MASK,
742 RTE_PTR_ADD(registers, RTE_AVP_INTERRUPT_MASK_OFFSET));
748 avp_dev_disable_interrupts(struct rte_eth_dev *eth_dev)
750 struct rte_pci_device *pci_dev = RTE_ETH_DEV_TO_PCI(eth_dev);
751 void *registers = pci_dev->mem_resource[RTE_AVP_PCI_MMIO_BAR].addr;
754 if (registers == NULL)
757 /* inform the device that all interrupts are disabled */
758 AVP_WRITE32(RTE_AVP_NO_INTERRUPTS_MASK,
759 RTE_PTR_ADD(registers, RTE_AVP_INTERRUPT_MASK_OFFSET));
761 /* enable UIO interrupt handling */
762 ret = rte_intr_disable(&pci_dev->intr_handle);
764 PMD_DRV_LOG(ERR, "Failed to disable UIO interrupts, ret=%d\n",
773 avp_dev_setup_interrupts(struct rte_eth_dev *eth_dev)
775 struct rte_pci_device *pci_dev = RTE_ETH_DEV_TO_PCI(eth_dev);
778 /* register a callback handler with UIO for interrupt notifications */
779 ret = rte_intr_callback_register(&pci_dev->intr_handle,
780 avp_dev_interrupt_handler,
783 PMD_DRV_LOG(ERR, "Failed to register UIO interrupt callback, ret=%d\n",
788 /* enable interrupt processing */
789 return avp_dev_enable_interrupts(eth_dev);
793 avp_dev_migration_pending(struct rte_eth_dev *eth_dev)
795 struct rte_pci_device *pci_dev = RTE_ETH_DEV_TO_PCI(eth_dev);
796 void *registers = pci_dev->mem_resource[RTE_AVP_PCI_MMIO_BAR].addr;
799 if (registers == NULL)
802 value = AVP_READ32(RTE_PTR_ADD(registers,
803 RTE_AVP_MIGRATION_STATUS_OFFSET));
804 if (value == RTE_AVP_MIGRATION_DETACHED) {
805 /* migration is in progress; ack it if we have not already */
807 RTE_PTR_ADD(registers,
808 RTE_AVP_MIGRATION_ACK_OFFSET));
815 * create a AVP device using the supplied device info by first translating it
816 * to guest address space(s).
819 avp_dev_create(struct rte_pci_device *pci_dev,
820 struct rte_eth_dev *eth_dev)
822 struct avp_dev *avp = AVP_DEV_PRIVATE_TO_HW(eth_dev->data->dev_private);
823 struct rte_avp_device_info *host_info;
824 struct rte_mem_resource *resource;
827 resource = &pci_dev->mem_resource[RTE_AVP_PCI_DEVICE_BAR];
828 if (resource->addr == NULL) {
829 PMD_DRV_LOG(ERR, "BAR%u is not mapped\n",
830 RTE_AVP_PCI_DEVICE_BAR);
833 host_info = (struct rte_avp_device_info *)resource->addr;
835 if ((host_info->magic != RTE_AVP_DEVICE_MAGIC) ||
836 avp_dev_version_check(host_info->version)) {
837 PMD_DRV_LOG(ERR, "Invalid AVP PCI device, magic 0x%08x version 0x%08x > 0x%08x\n",
838 host_info->magic, host_info->version,
839 AVP_DPDK_DRIVER_VERSION);
843 PMD_DRV_LOG(DEBUG, "AVP host device is v%u.%u.%u\n",
844 RTE_AVP_GET_RELEASE_VERSION(host_info->version),
845 RTE_AVP_GET_MAJOR_VERSION(host_info->version),
846 RTE_AVP_GET_MINOR_VERSION(host_info->version));
848 PMD_DRV_LOG(DEBUG, "AVP host supports %u to %u TX queue(s)\n",
849 host_info->min_tx_queues, host_info->max_tx_queues);
850 PMD_DRV_LOG(DEBUG, "AVP host supports %u to %u RX queue(s)\n",
851 host_info->min_rx_queues, host_info->max_rx_queues);
852 PMD_DRV_LOG(DEBUG, "AVP host supports features 0x%08x\n",
853 host_info->features);
855 if (avp->magic != AVP_ETHDEV_MAGIC) {
857 * First time initialization (i.e., not during a VM
860 memset(avp, 0, sizeof(*avp));
861 avp->magic = AVP_ETHDEV_MAGIC;
862 avp->dev_data = eth_dev->data;
863 avp->port_id = eth_dev->data->port_id;
864 avp->host_mbuf_size = host_info->mbuf_size;
865 avp->host_features = host_info->features;
866 rte_spinlock_init(&avp->lock);
867 memcpy(&avp->ethaddr.addr_bytes[0],
868 host_info->ethaddr, RTE_ETHER_ADDR_LEN);
869 /* adjust max values to not exceed our max */
871 RTE_MIN(host_info->max_tx_queues, RTE_AVP_MAX_QUEUES);
873 RTE_MIN(host_info->max_rx_queues, RTE_AVP_MAX_QUEUES);
875 /* Re-attaching during migration */
877 /* TODO... requires validation of host values */
878 if ((host_info->features & avp->features) != avp->features) {
879 PMD_DRV_LOG(ERR, "AVP host features mismatched; 0x%08x, host=0x%08x\n",
880 avp->features, host_info->features);
881 /* this should not be possible; continue for now */
885 /* the device id is allowed to change over migrations */
886 avp->device_id = host_info->device_id;
888 /* translate incoming host addresses to guest address space */
889 PMD_DRV_LOG(DEBUG, "AVP first host tx queue at 0x%" PRIx64 "\n",
891 PMD_DRV_LOG(DEBUG, "AVP first host alloc queue at 0x%" PRIx64 "\n",
892 host_info->alloc_phys);
893 for (i = 0; i < avp->max_tx_queues; i++) {
894 avp->tx_q[i] = avp_dev_translate_address(eth_dev,
895 host_info->tx_phys + (i * host_info->tx_size));
897 avp->alloc_q[i] = avp_dev_translate_address(eth_dev,
898 host_info->alloc_phys + (i * host_info->alloc_size));
901 PMD_DRV_LOG(DEBUG, "AVP first host rx queue at 0x%" PRIx64 "\n",
903 PMD_DRV_LOG(DEBUG, "AVP first host free queue at 0x%" PRIx64 "\n",
904 host_info->free_phys);
905 for (i = 0; i < avp->max_rx_queues; i++) {
906 avp->rx_q[i] = avp_dev_translate_address(eth_dev,
907 host_info->rx_phys + (i * host_info->rx_size));
908 avp->free_q[i] = avp_dev_translate_address(eth_dev,
909 host_info->free_phys + (i * host_info->free_size));
912 PMD_DRV_LOG(DEBUG, "AVP host request queue at 0x%" PRIx64 "\n",
913 host_info->req_phys);
914 PMD_DRV_LOG(DEBUG, "AVP host response queue at 0x%" PRIx64 "\n",
915 host_info->resp_phys);
916 PMD_DRV_LOG(DEBUG, "AVP host sync address at 0x%" PRIx64 "\n",
917 host_info->sync_phys);
918 PMD_DRV_LOG(DEBUG, "AVP host mbuf address at 0x%" PRIx64 "\n",
919 host_info->mbuf_phys);
920 avp->req_q = avp_dev_translate_address(eth_dev, host_info->req_phys);
921 avp->resp_q = avp_dev_translate_address(eth_dev, host_info->resp_phys);
923 avp_dev_translate_address(eth_dev, host_info->sync_phys);
925 avp_dev_translate_address(eth_dev, host_info->mbuf_phys);
928 * store the host mbuf virtual address so that we can calculate
929 * relative offsets for each mbuf as they are processed
931 avp->host_mbuf_addr = host_info->mbuf_va;
932 avp->host_sync_addr = host_info->sync_va;
935 * store the maximum packet length that is supported by the host.
937 avp->max_rx_pkt_len = host_info->max_rx_pkt_len;
938 PMD_DRV_LOG(DEBUG, "AVP host max receive packet length is %u\n",
939 host_info->max_rx_pkt_len);
945 * This function is based on probe() function in avp_pci.c
946 * It returns 0 on success.
949 eth_avp_dev_init(struct rte_eth_dev *eth_dev)
951 struct avp_dev *avp =
952 AVP_DEV_PRIVATE_TO_HW(eth_dev->data->dev_private);
953 struct rte_pci_device *pci_dev;
956 pci_dev = RTE_ETH_DEV_TO_PCI(eth_dev);
957 eth_dev->dev_ops = &avp_eth_dev_ops;
958 eth_dev->rx_pkt_burst = &avp_recv_pkts;
959 eth_dev->tx_pkt_burst = &avp_xmit_pkts;
961 if (rte_eal_process_type() != RTE_PROC_PRIMARY) {
963 * no setup required on secondary processes. All data is saved
964 * in dev_private by the primary process. All resource should
965 * be mapped to the same virtual address so all pointers should
968 if (eth_dev->data->scattered_rx) {
969 PMD_DRV_LOG(NOTICE, "AVP device configured for chained mbufs\n");
970 eth_dev->rx_pkt_burst = avp_recv_scattered_pkts;
971 eth_dev->tx_pkt_burst = avp_xmit_scattered_pkts;
976 rte_eth_copy_pci_info(eth_dev, pci_dev);
978 /* Check current migration status */
979 if (avp_dev_migration_pending(eth_dev)) {
980 PMD_DRV_LOG(ERR, "VM live migration operation in progress\n");
984 /* Check BAR resources */
985 ret = avp_dev_check_regions(eth_dev);
987 PMD_DRV_LOG(ERR, "Failed to validate BAR resources, ret=%d\n",
992 /* Enable interrupts */
993 ret = avp_dev_setup_interrupts(eth_dev);
995 PMD_DRV_LOG(ERR, "Failed to enable interrupts, ret=%d\n", ret);
999 /* Handle each subtype */
1000 ret = avp_dev_create(pci_dev, eth_dev);
1002 PMD_DRV_LOG(ERR, "Failed to create device, ret=%d\n", ret);
1006 /* Allocate memory for storing MAC addresses */
1007 eth_dev->data->mac_addrs = rte_zmalloc("avp_ethdev",
1008 RTE_ETHER_ADDR_LEN, 0);
1009 if (eth_dev->data->mac_addrs == NULL) {
1010 PMD_DRV_LOG(ERR, "Failed to allocate %d bytes needed to store MAC addresses\n",
1011 RTE_ETHER_ADDR_LEN);
1015 /* Get a mac from device config */
1016 rte_ether_addr_copy(&avp->ethaddr, ð_dev->data->mac_addrs[0]);
1022 eth_avp_dev_uninit(struct rte_eth_dev *eth_dev)
1024 if (rte_eal_process_type() != RTE_PROC_PRIMARY)
1027 if (eth_dev->data == NULL)
1030 avp_dev_close(eth_dev);
1036 eth_avp_pci_probe(struct rte_pci_driver *pci_drv __rte_unused,
1037 struct rte_pci_device *pci_dev)
1039 return rte_eth_dev_pci_generic_probe(pci_dev, sizeof(struct avp_adapter),
1044 eth_avp_pci_remove(struct rte_pci_device *pci_dev)
1046 return rte_eth_dev_pci_generic_remove(pci_dev,
1047 eth_avp_dev_uninit);
1050 static struct rte_pci_driver rte_avp_pmd = {
1051 .id_table = pci_id_avp_map,
1052 .drv_flags = RTE_PCI_DRV_NEED_MAPPING,
1053 .probe = eth_avp_pci_probe,
1054 .remove = eth_avp_pci_remove,
1058 avp_dev_enable_scattered(struct rte_eth_dev *eth_dev,
1059 struct avp_dev *avp)
1061 unsigned int max_rx_pkt_len;
1063 max_rx_pkt_len = eth_dev->data->dev_conf.rxmode.max_rx_pkt_len;
1065 if ((max_rx_pkt_len > avp->guest_mbuf_size) ||
1066 (max_rx_pkt_len > avp->host_mbuf_size)) {
1068 * If the guest MTU is greater than either the host or guest
1069 * buffers then chained mbufs have to be enabled in the TX
1070 * direction. It is assumed that the application will not need
1071 * to send packets larger than their max_rx_pkt_len (MRU).
1076 if ((avp->max_rx_pkt_len > avp->guest_mbuf_size) ||
1077 (avp->max_rx_pkt_len > avp->host_mbuf_size)) {
1079 * If the host MRU is greater than its own mbuf size or the
1080 * guest mbuf size then chained mbufs have to be enabled in the
1090 avp_dev_rx_queue_setup(struct rte_eth_dev *eth_dev,
1091 uint16_t rx_queue_id,
1092 uint16_t nb_rx_desc,
1093 unsigned int socket_id,
1094 const struct rte_eth_rxconf *rx_conf,
1095 struct rte_mempool *pool)
1097 struct avp_dev *avp = AVP_DEV_PRIVATE_TO_HW(eth_dev->data->dev_private);
1098 struct rte_pktmbuf_pool_private *mbp_priv;
1099 struct avp_queue *rxq;
1101 if (rx_queue_id >= eth_dev->data->nb_rx_queues) {
1102 PMD_DRV_LOG(ERR, "RX queue id is out of range: rx_queue_id=%u, nb_rx_queues=%u\n",
1103 rx_queue_id, eth_dev->data->nb_rx_queues);
1107 /* Save mbuf pool pointer */
1110 /* Save the local mbuf size */
1111 mbp_priv = rte_mempool_get_priv(pool);
1112 avp->guest_mbuf_size = (uint16_t)(mbp_priv->mbuf_data_room_size);
1113 avp->guest_mbuf_size -= RTE_PKTMBUF_HEADROOM;
1115 if (avp_dev_enable_scattered(eth_dev, avp)) {
1116 if (!eth_dev->data->scattered_rx) {
1117 PMD_DRV_LOG(NOTICE, "AVP device configured for chained mbufs\n");
1118 eth_dev->data->scattered_rx = 1;
1119 eth_dev->rx_pkt_burst = avp_recv_scattered_pkts;
1120 eth_dev->tx_pkt_burst = avp_xmit_scattered_pkts;
1124 PMD_DRV_LOG(DEBUG, "AVP max_rx_pkt_len=(%u,%u) mbuf_size=(%u,%u)\n",
1125 avp->max_rx_pkt_len,
1126 eth_dev->data->dev_conf.rxmode.max_rx_pkt_len,
1127 avp->host_mbuf_size,
1128 avp->guest_mbuf_size);
1130 /* allocate a queue object */
1131 rxq = rte_zmalloc_socket("ethdev RX queue", sizeof(struct avp_queue),
1132 RTE_CACHE_LINE_SIZE, socket_id);
1134 PMD_DRV_LOG(ERR, "Failed to allocate new Rx queue object\n");
1138 /* save back pointers to AVP and Ethernet devices */
1140 rxq->dev_data = eth_dev->data;
1141 eth_dev->data->rx_queues[rx_queue_id] = (void *)rxq;
1143 /* setup the queue receive mapping for the current queue. */
1144 _avp_set_rx_queue_mappings(eth_dev, rx_queue_id);
1146 PMD_DRV_LOG(DEBUG, "Rx queue %u setup at %p\n", rx_queue_id, rxq);
1154 avp_dev_tx_queue_setup(struct rte_eth_dev *eth_dev,
1155 uint16_t tx_queue_id,
1156 uint16_t nb_tx_desc,
1157 unsigned int socket_id,
1158 const struct rte_eth_txconf *tx_conf)
1160 struct avp_dev *avp = AVP_DEV_PRIVATE_TO_HW(eth_dev->data->dev_private);
1161 struct avp_queue *txq;
1163 if (tx_queue_id >= eth_dev->data->nb_tx_queues) {
1164 PMD_DRV_LOG(ERR, "TX queue id is out of range: tx_queue_id=%u, nb_tx_queues=%u\n",
1165 tx_queue_id, eth_dev->data->nb_tx_queues);
1169 /* allocate a queue object */
1170 txq = rte_zmalloc_socket("ethdev TX queue", sizeof(struct avp_queue),
1171 RTE_CACHE_LINE_SIZE, socket_id);
1173 PMD_DRV_LOG(ERR, "Failed to allocate new Tx queue object\n");
1177 /* only the configured set of transmit queues are used */
1178 txq->queue_id = tx_queue_id;
1179 txq->queue_base = tx_queue_id;
1180 txq->queue_limit = tx_queue_id;
1182 /* save back pointers to AVP and Ethernet devices */
1184 txq->dev_data = eth_dev->data;
1185 eth_dev->data->tx_queues[tx_queue_id] = (void *)txq;
1187 PMD_DRV_LOG(DEBUG, "Tx queue %u setup at %p\n", tx_queue_id, txq);
1195 _avp_cmp_ether_addr(struct rte_ether_addr *a, struct rte_ether_addr *b)
1197 uint16_t *_a = (uint16_t *)&a->addr_bytes[0];
1198 uint16_t *_b = (uint16_t *)&b->addr_bytes[0];
1199 return (_a[0] ^ _b[0]) | (_a[1] ^ _b[1]) | (_a[2] ^ _b[2]);
1203 _avp_mac_filter(struct avp_dev *avp, struct rte_mbuf *m)
1205 struct rte_ether_hdr *eth = rte_pktmbuf_mtod(m, struct rte_ether_hdr *);
1207 if (likely(_avp_cmp_ether_addr(&avp->ethaddr, ð->d_addr) == 0)) {
1208 /* allow all packets destined to our address */
1212 if (likely(rte_is_broadcast_ether_addr(ð->d_addr))) {
1213 /* allow all broadcast packets */
1217 if (likely(rte_is_multicast_ether_addr(ð->d_addr))) {
1218 /* allow all multicast packets */
1222 if (avp->flags & AVP_F_PROMISC) {
1223 /* allow all packets when in promiscuous mode */
1230 #ifdef RTE_LIBRTE_AVP_DEBUG_BUFFERS
1232 __avp_dev_buffer_sanity_check(struct avp_dev *avp, struct rte_avp_desc *buf)
1234 struct rte_avp_desc *first_buf;
1235 struct rte_avp_desc *pkt_buf;
1236 unsigned int pkt_len;
1237 unsigned int nb_segs;
1241 first_buf = avp_dev_translate_buffer(avp, buf);
1245 nb_segs = first_buf->nb_segs;
1247 /* Adjust pointers for guest addressing */
1248 pkt_buf = avp_dev_translate_buffer(avp, buf);
1249 if (pkt_buf == NULL)
1250 rte_panic("bad buffer: segment %u has an invalid address %p\n",
1252 pkt_data = avp_dev_translate_buffer(avp, pkt_buf->data);
1253 if (pkt_data == NULL)
1254 rte_panic("bad buffer: segment %u has a NULL data pointer\n",
1256 if (pkt_buf->data_len == 0)
1257 rte_panic("bad buffer: segment %u has 0 data length\n",
1259 pkt_len += pkt_buf->data_len;
1263 } while (nb_segs && (buf = pkt_buf->next) != NULL);
1266 rte_panic("bad buffer: expected %u segments found %u\n",
1267 first_buf->nb_segs, (first_buf->nb_segs - nb_segs));
1268 if (pkt_len != first_buf->pkt_len)
1269 rte_panic("bad buffer: expected length %u found %u\n",
1270 first_buf->pkt_len, pkt_len);
1273 #define avp_dev_buffer_sanity_check(a, b) \
1274 __avp_dev_buffer_sanity_check((a), (b))
1276 #else /* RTE_LIBRTE_AVP_DEBUG_BUFFERS */
1278 #define avp_dev_buffer_sanity_check(a, b) do {} while (0)
1283 * Copy a host buffer chain to a set of mbufs. This function assumes that
1284 * there exactly the required number of mbufs to copy all source bytes.
1286 static inline struct rte_mbuf *
1287 avp_dev_copy_from_buffers(struct avp_dev *avp,
1288 struct rte_avp_desc *buf,
1289 struct rte_mbuf **mbufs,
1292 struct rte_mbuf *m_previous = NULL;
1293 struct rte_avp_desc *pkt_buf;
1294 unsigned int total_length = 0;
1295 unsigned int copy_length;
1296 unsigned int src_offset;
1303 avp_dev_buffer_sanity_check(avp, buf);
1305 /* setup the first source buffer */
1306 pkt_buf = avp_dev_translate_buffer(avp, buf);
1307 pkt_data = avp_dev_translate_buffer(avp, pkt_buf->data);
1308 total_length = pkt_buf->pkt_len;
1311 if (pkt_buf->ol_flags & RTE_AVP_RX_VLAN_PKT) {
1312 ol_flags = PKT_RX_VLAN;
1313 vlan_tci = pkt_buf->vlan_tci;
1319 for (i = 0; (i < count) && (buf != NULL); i++) {
1320 /* fill each destination buffer */
1323 if (m_previous != NULL)
1324 m_previous->next = m;
1330 * Copy as many source buffers as will fit in the
1331 * destination buffer.
1333 copy_length = RTE_MIN((avp->guest_mbuf_size -
1334 rte_pktmbuf_data_len(m)),
1335 (pkt_buf->data_len -
1337 rte_memcpy(RTE_PTR_ADD(rte_pktmbuf_mtod(m, void *),
1338 rte_pktmbuf_data_len(m)),
1339 RTE_PTR_ADD(pkt_data, src_offset),
1341 rte_pktmbuf_data_len(m) += copy_length;
1342 src_offset += copy_length;
1344 if (likely(src_offset == pkt_buf->data_len)) {
1345 /* need a new source buffer */
1346 buf = pkt_buf->next;
1348 pkt_buf = avp_dev_translate_buffer(
1350 pkt_data = avp_dev_translate_buffer(
1351 avp, pkt_buf->data);
1356 if (unlikely(rte_pktmbuf_data_len(m) ==
1357 avp->guest_mbuf_size)) {
1358 /* need a new destination mbuf */
1362 } while (buf != NULL);
1366 m->ol_flags = ol_flags;
1368 rte_pktmbuf_pkt_len(m) = total_length;
1369 m->vlan_tci = vlan_tci;
1371 __rte_mbuf_sanity_check(m, 1);
1377 avp_recv_scattered_pkts(void *rx_queue,
1378 struct rte_mbuf **rx_pkts,
1381 struct avp_queue *rxq = (struct avp_queue *)rx_queue;
1382 struct rte_avp_desc *avp_bufs[AVP_MAX_RX_BURST];
1383 struct rte_mbuf *mbufs[RTE_AVP_MAX_MBUF_SEGMENTS];
1384 struct avp_dev *avp = rxq->avp;
1385 struct rte_avp_desc *pkt_buf;
1386 struct rte_avp_fifo *free_q;
1387 struct rte_avp_fifo *rx_q;
1388 struct rte_avp_desc *buf;
1389 unsigned int count, avail, n;
1390 unsigned int guest_mbuf_size;
1392 unsigned int required;
1393 unsigned int buf_len;
1394 unsigned int port_id;
1397 if (unlikely(avp->flags & AVP_F_DETACHED)) {
1398 /* VM live migration in progress */
1402 guest_mbuf_size = avp->guest_mbuf_size;
1403 port_id = avp->port_id;
1404 rx_q = avp->rx_q[rxq->queue_id];
1405 free_q = avp->free_q[rxq->queue_id];
1407 /* setup next queue to service */
1408 rxq->queue_id = (rxq->queue_id < rxq->queue_limit) ?
1409 (rxq->queue_id + 1) : rxq->queue_base;
1411 /* determine how many slots are available in the free queue */
1412 count = avp_fifo_free_count(free_q);
1414 /* determine how many packets are available in the rx queue */
1415 avail = avp_fifo_count(rx_q);
1417 /* determine how many packets can be received */
1418 count = RTE_MIN(count, avail);
1419 count = RTE_MIN(count, nb_pkts);
1420 count = RTE_MIN(count, (unsigned int)AVP_MAX_RX_BURST);
1422 if (unlikely(count == 0)) {
1423 /* no free buffers, or no buffers on the rx queue */
1427 /* retrieve pending packets */
1428 n = avp_fifo_get(rx_q, (void **)&avp_bufs, count);
1429 PMD_RX_LOG(DEBUG, "Receiving %u packets from Rx queue at %p\n",
1433 for (i = 0; i < n; i++) {
1434 /* prefetch next entry while processing current one */
1436 pkt_buf = avp_dev_translate_buffer(avp,
1438 rte_prefetch0(pkt_buf);
1442 /* Peek into the first buffer to determine the total length */
1443 pkt_buf = avp_dev_translate_buffer(avp, buf);
1444 buf_len = pkt_buf->pkt_len;
1446 /* Allocate enough mbufs to receive the entire packet */
1447 required = (buf_len + guest_mbuf_size - 1) / guest_mbuf_size;
1448 if (rte_pktmbuf_alloc_bulk(avp->pool, mbufs, required)) {
1449 rxq->dev_data->rx_mbuf_alloc_failed++;
1453 /* Copy the data from the buffers to our mbufs */
1454 m = avp_dev_copy_from_buffers(avp, buf, mbufs, required);
1459 if (_avp_mac_filter(avp, m) != 0) {
1460 /* silently discard packets not destined to our MAC */
1461 rte_pktmbuf_free(m);
1465 /* return new mbuf to caller */
1466 rx_pkts[count++] = m;
1467 rxq->bytes += buf_len;
1470 rxq->packets += count;
1472 /* return the buffers to the free queue */
1473 avp_fifo_put(free_q, (void **)&avp_bufs[0], n);
1480 avp_recv_pkts(void *rx_queue,
1481 struct rte_mbuf **rx_pkts,
1484 struct avp_queue *rxq = (struct avp_queue *)rx_queue;
1485 struct rte_avp_desc *avp_bufs[AVP_MAX_RX_BURST];
1486 struct avp_dev *avp = rxq->avp;
1487 struct rte_avp_desc *pkt_buf;
1488 struct rte_avp_fifo *free_q;
1489 struct rte_avp_fifo *rx_q;
1490 unsigned int count, avail, n;
1491 unsigned int pkt_len;
1496 if (unlikely(avp->flags & AVP_F_DETACHED)) {
1497 /* VM live migration in progress */
1501 rx_q = avp->rx_q[rxq->queue_id];
1502 free_q = avp->free_q[rxq->queue_id];
1504 /* setup next queue to service */
1505 rxq->queue_id = (rxq->queue_id < rxq->queue_limit) ?
1506 (rxq->queue_id + 1) : rxq->queue_base;
1508 /* determine how many slots are available in the free queue */
1509 count = avp_fifo_free_count(free_q);
1511 /* determine how many packets are available in the rx queue */
1512 avail = avp_fifo_count(rx_q);
1514 /* determine how many packets can be received */
1515 count = RTE_MIN(count, avail);
1516 count = RTE_MIN(count, nb_pkts);
1517 count = RTE_MIN(count, (unsigned int)AVP_MAX_RX_BURST);
1519 if (unlikely(count == 0)) {
1520 /* no free buffers, or no buffers on the rx queue */
1524 /* retrieve pending packets */
1525 n = avp_fifo_get(rx_q, (void **)&avp_bufs, count);
1526 PMD_RX_LOG(DEBUG, "Receiving %u packets from Rx queue at %p\n",
1530 for (i = 0; i < n; i++) {
1531 /* prefetch next entry while processing current one */
1533 pkt_buf = avp_dev_translate_buffer(avp,
1535 rte_prefetch0(pkt_buf);
1538 /* Adjust host pointers for guest addressing */
1539 pkt_buf = avp_dev_translate_buffer(avp, avp_bufs[i]);
1540 pkt_data = avp_dev_translate_buffer(avp, pkt_buf->data);
1541 pkt_len = pkt_buf->pkt_len;
1543 if (unlikely((pkt_len > avp->guest_mbuf_size) ||
1544 (pkt_buf->nb_segs > 1))) {
1546 * application should be using the scattered receive
1553 /* process each packet to be transmitted */
1554 m = rte_pktmbuf_alloc(avp->pool);
1555 if (unlikely(m == NULL)) {
1556 rxq->dev_data->rx_mbuf_alloc_failed++;
1560 /* copy data out of the host buffer to our buffer */
1561 m->data_off = RTE_PKTMBUF_HEADROOM;
1562 rte_memcpy(rte_pktmbuf_mtod(m, void *), pkt_data, pkt_len);
1564 /* initialize the local mbuf */
1565 rte_pktmbuf_data_len(m) = pkt_len;
1566 rte_pktmbuf_pkt_len(m) = pkt_len;
1567 m->port = avp->port_id;
1569 if (pkt_buf->ol_flags & RTE_AVP_RX_VLAN_PKT) {
1570 m->ol_flags = PKT_RX_VLAN;
1571 m->vlan_tci = pkt_buf->vlan_tci;
1574 if (_avp_mac_filter(avp, m) != 0) {
1575 /* silently discard packets not destined to our MAC */
1576 rte_pktmbuf_free(m);
1580 /* return new mbuf to caller */
1581 rx_pkts[count++] = m;
1582 rxq->bytes += pkt_len;
1585 rxq->packets += count;
1587 /* return the buffers to the free queue */
1588 avp_fifo_put(free_q, (void **)&avp_bufs[0], n);
1594 * Copy a chained mbuf to a set of host buffers. This function assumes that
1595 * there are sufficient destination buffers to contain the entire source
1598 static inline uint16_t
1599 avp_dev_copy_to_buffers(struct avp_dev *avp,
1600 struct rte_mbuf *mbuf,
1601 struct rte_avp_desc **buffers,
1604 struct rte_avp_desc *previous_buf = NULL;
1605 struct rte_avp_desc *first_buf = NULL;
1606 struct rte_avp_desc *pkt_buf;
1607 struct rte_avp_desc *buf;
1608 size_t total_length;
1615 __rte_mbuf_sanity_check(mbuf, 1);
1619 total_length = rte_pktmbuf_pkt_len(m);
1620 for (i = 0; (i < count) && (m != NULL); i++) {
1621 /* fill each destination buffer */
1624 if (i < count - 1) {
1625 /* prefetch next entry while processing this one */
1626 pkt_buf = avp_dev_translate_buffer(avp, buffers[i + 1]);
1627 rte_prefetch0(pkt_buf);
1630 /* Adjust pointers for guest addressing */
1631 pkt_buf = avp_dev_translate_buffer(avp, buf);
1632 pkt_data = avp_dev_translate_buffer(avp, pkt_buf->data);
1634 /* setup the buffer chain */
1635 if (previous_buf != NULL)
1636 previous_buf->next = buf;
1638 first_buf = pkt_buf;
1640 previous_buf = pkt_buf;
1644 * copy as many source mbuf segments as will fit in the
1645 * destination buffer.
1647 copy_length = RTE_MIN((avp->host_mbuf_size -
1649 (rte_pktmbuf_data_len(m) -
1651 rte_memcpy(RTE_PTR_ADD(pkt_data, pkt_buf->data_len),
1652 RTE_PTR_ADD(rte_pktmbuf_mtod(m, void *),
1655 pkt_buf->data_len += copy_length;
1656 src_offset += copy_length;
1658 if (likely(src_offset == rte_pktmbuf_data_len(m))) {
1659 /* need a new source buffer */
1664 if (unlikely(pkt_buf->data_len ==
1665 avp->host_mbuf_size)) {
1666 /* need a new destination buffer */
1670 } while (m != NULL);
1673 first_buf->nb_segs = count;
1674 first_buf->pkt_len = total_length;
1676 if (mbuf->ol_flags & PKT_TX_VLAN_PKT) {
1677 first_buf->ol_flags |= RTE_AVP_TX_VLAN_PKT;
1678 first_buf->vlan_tci = mbuf->vlan_tci;
1681 avp_dev_buffer_sanity_check(avp, buffers[0]);
1683 return total_length;
1688 avp_xmit_scattered_pkts(void *tx_queue,
1689 struct rte_mbuf **tx_pkts,
1692 struct rte_avp_desc *avp_bufs[(AVP_MAX_TX_BURST *
1693 RTE_AVP_MAX_MBUF_SEGMENTS)] = {};
1694 struct avp_queue *txq = (struct avp_queue *)tx_queue;
1695 struct rte_avp_desc *tx_bufs[AVP_MAX_TX_BURST];
1696 struct avp_dev *avp = txq->avp;
1697 struct rte_avp_fifo *alloc_q;
1698 struct rte_avp_fifo *tx_q;
1699 unsigned int count, avail, n;
1700 unsigned int orig_nb_pkts;
1702 unsigned int required;
1703 unsigned int segments;
1704 unsigned int tx_bytes;
1707 orig_nb_pkts = nb_pkts;
1708 if (unlikely(avp->flags & AVP_F_DETACHED)) {
1709 /* VM live migration in progress */
1710 /* TODO ... buffer for X packets then drop? */
1711 txq->errors += nb_pkts;
1715 tx_q = avp->tx_q[txq->queue_id];
1716 alloc_q = avp->alloc_q[txq->queue_id];
1718 /* limit the number of transmitted packets to the max burst size */
1719 if (unlikely(nb_pkts > AVP_MAX_TX_BURST))
1720 nb_pkts = AVP_MAX_TX_BURST;
1722 /* determine how many buffers are available to copy into */
1723 avail = avp_fifo_count(alloc_q);
1724 if (unlikely(avail > (AVP_MAX_TX_BURST *
1725 RTE_AVP_MAX_MBUF_SEGMENTS)))
1726 avail = AVP_MAX_TX_BURST * RTE_AVP_MAX_MBUF_SEGMENTS;
1728 /* determine how many slots are available in the transmit queue */
1729 count = avp_fifo_free_count(tx_q);
1731 /* determine how many packets can be sent */
1732 nb_pkts = RTE_MIN(count, nb_pkts);
1734 /* determine how many packets will fit in the available buffers */
1737 for (i = 0; i < nb_pkts; i++) {
1739 if (likely(i < (unsigned int)nb_pkts - 1)) {
1740 /* prefetch next entry while processing this one */
1741 rte_prefetch0(tx_pkts[i + 1]);
1743 required = (rte_pktmbuf_pkt_len(m) + avp->host_mbuf_size - 1) /
1744 avp->host_mbuf_size;
1746 if (unlikely((required == 0) ||
1747 (required > RTE_AVP_MAX_MBUF_SEGMENTS)))
1749 else if (unlikely(required + segments > avail))
1751 segments += required;
1756 if (unlikely(nb_pkts == 0)) {
1757 /* no available buffers, or no space on the tx queue */
1758 txq->errors += orig_nb_pkts;
1762 PMD_TX_LOG(DEBUG, "Sending %u packets on Tx queue at %p\n",
1765 /* retrieve sufficient send buffers */
1766 n = avp_fifo_get(alloc_q, (void **)&avp_bufs, segments);
1767 if (unlikely(n != segments)) {
1768 PMD_TX_LOG(DEBUG, "Failed to allocate buffers "
1769 "n=%u, segments=%u, orig=%u\n",
1770 n, segments, orig_nb_pkts);
1771 txq->errors += orig_nb_pkts;
1777 for (i = 0; i < nb_pkts; i++) {
1778 /* process each packet to be transmitted */
1781 /* determine how many buffers are required for this packet */
1782 required = (rte_pktmbuf_pkt_len(m) + avp->host_mbuf_size - 1) /
1783 avp->host_mbuf_size;
1785 tx_bytes += avp_dev_copy_to_buffers(avp, m,
1786 &avp_bufs[count], required);
1787 tx_bufs[i] = avp_bufs[count];
1790 /* free the original mbuf */
1791 rte_pktmbuf_free(m);
1794 txq->packets += nb_pkts;
1795 txq->bytes += tx_bytes;
1797 #ifdef RTE_LIBRTE_AVP_DEBUG_BUFFERS
1798 for (i = 0; i < nb_pkts; i++)
1799 avp_dev_buffer_sanity_check(avp, tx_bufs[i]);
1802 /* send the packets */
1803 n = avp_fifo_put(tx_q, (void **)&tx_bufs[0], nb_pkts);
1804 if (unlikely(n != orig_nb_pkts))
1805 txq->errors += (orig_nb_pkts - n);
1812 avp_xmit_pkts(void *tx_queue, struct rte_mbuf **tx_pkts, uint16_t nb_pkts)
1814 struct avp_queue *txq = (struct avp_queue *)tx_queue;
1815 struct rte_avp_desc *avp_bufs[AVP_MAX_TX_BURST];
1816 struct avp_dev *avp = txq->avp;
1817 struct rte_avp_desc *pkt_buf;
1818 struct rte_avp_fifo *alloc_q;
1819 struct rte_avp_fifo *tx_q;
1820 unsigned int count, avail, n;
1822 unsigned int pkt_len;
1823 unsigned int tx_bytes;
1827 if (unlikely(avp->flags & AVP_F_DETACHED)) {
1828 /* VM live migration in progress */
1829 /* TODO ... buffer for X packets then drop?! */
1834 tx_q = avp->tx_q[txq->queue_id];
1835 alloc_q = avp->alloc_q[txq->queue_id];
1837 /* limit the number of transmitted packets to the max burst size */
1838 if (unlikely(nb_pkts > AVP_MAX_TX_BURST))
1839 nb_pkts = AVP_MAX_TX_BURST;
1841 /* determine how many buffers are available to copy into */
1842 avail = avp_fifo_count(alloc_q);
1844 /* determine how many slots are available in the transmit queue */
1845 count = avp_fifo_free_count(tx_q);
1847 /* determine how many packets can be sent */
1848 count = RTE_MIN(count, avail);
1849 count = RTE_MIN(count, nb_pkts);
1851 if (unlikely(count == 0)) {
1852 /* no available buffers, or no space on the tx queue */
1853 txq->errors += nb_pkts;
1857 PMD_TX_LOG(DEBUG, "Sending %u packets on Tx queue at %p\n",
1860 /* retrieve sufficient send buffers */
1861 n = avp_fifo_get(alloc_q, (void **)&avp_bufs, count);
1862 if (unlikely(n != count)) {
1868 for (i = 0; i < count; i++) {
1869 /* prefetch next entry while processing the current one */
1870 if (i < count - 1) {
1871 pkt_buf = avp_dev_translate_buffer(avp,
1873 rte_prefetch0(pkt_buf);
1876 /* process each packet to be transmitted */
1879 /* Adjust pointers for guest addressing */
1880 pkt_buf = avp_dev_translate_buffer(avp, avp_bufs[i]);
1881 pkt_data = avp_dev_translate_buffer(avp, pkt_buf->data);
1882 pkt_len = rte_pktmbuf_pkt_len(m);
1884 if (unlikely((pkt_len > avp->guest_mbuf_size) ||
1885 (pkt_len > avp->host_mbuf_size))) {
1887 * application should be using the scattered transmit
1888 * function; send it truncated to avoid the performance
1889 * hit of having to manage returning the already
1890 * allocated buffer to the free list. This should not
1891 * happen since the application should have set the
1892 * max_rx_pkt_len based on its MTU and it should be
1893 * policing its own packet sizes.
1896 pkt_len = RTE_MIN(avp->guest_mbuf_size,
1897 avp->host_mbuf_size);
1900 /* copy data out of our mbuf and into the AVP buffer */
1901 rte_memcpy(pkt_data, rte_pktmbuf_mtod(m, void *), pkt_len);
1902 pkt_buf->pkt_len = pkt_len;
1903 pkt_buf->data_len = pkt_len;
1904 pkt_buf->nb_segs = 1;
1905 pkt_buf->next = NULL;
1907 if (m->ol_flags & PKT_TX_VLAN_PKT) {
1908 pkt_buf->ol_flags |= RTE_AVP_TX_VLAN_PKT;
1909 pkt_buf->vlan_tci = m->vlan_tci;
1912 tx_bytes += pkt_len;
1914 /* free the original mbuf */
1915 rte_pktmbuf_free(m);
1918 txq->packets += count;
1919 txq->bytes += tx_bytes;
1921 /* send the packets */
1922 n = avp_fifo_put(tx_q, (void **)&avp_bufs[0], count);
1928 avp_dev_rx_queue_release(void *rx_queue)
1930 struct avp_queue *rxq = (struct avp_queue *)rx_queue;
1931 struct avp_dev *avp = rxq->avp;
1932 struct rte_eth_dev_data *data = avp->dev_data;
1935 for (i = 0; i < avp->num_rx_queues; i++) {
1936 if (data->rx_queues[i] == rxq) {
1937 rte_free(data->rx_queues[i]);
1938 data->rx_queues[i] = NULL;
1944 avp_dev_rx_queue_release_all(struct rte_eth_dev *eth_dev)
1946 struct avp_dev *avp = AVP_DEV_PRIVATE_TO_HW(eth_dev->data->dev_private);
1947 struct rte_eth_dev_data *data = avp->dev_data;
1950 for (i = 0; i < avp->num_rx_queues; i++) {
1951 if (data->rx_queues[i]) {
1952 rte_free(data->rx_queues[i]);
1953 data->rx_queues[i] = NULL;
1959 avp_dev_tx_queue_release(void *tx_queue)
1961 struct avp_queue *txq = (struct avp_queue *)tx_queue;
1962 struct avp_dev *avp = txq->avp;
1963 struct rte_eth_dev_data *data = avp->dev_data;
1966 for (i = 0; i < avp->num_tx_queues; i++) {
1967 if (data->tx_queues[i] == txq) {
1968 rte_free(data->tx_queues[i]);
1969 data->tx_queues[i] = NULL;
1975 avp_dev_tx_queue_release_all(struct rte_eth_dev *eth_dev)
1977 struct avp_dev *avp = AVP_DEV_PRIVATE_TO_HW(eth_dev->data->dev_private);
1978 struct rte_eth_dev_data *data = avp->dev_data;
1981 for (i = 0; i < avp->num_tx_queues; i++) {
1982 if (data->tx_queues[i]) {
1983 rte_free(data->tx_queues[i]);
1984 data->tx_queues[i] = NULL;
1990 avp_dev_configure(struct rte_eth_dev *eth_dev)
1992 struct rte_pci_device *pci_dev = RTE_ETH_DEV_TO_PCI(eth_dev);
1993 struct avp_dev *avp = AVP_DEV_PRIVATE_TO_HW(eth_dev->data->dev_private);
1994 struct rte_avp_device_info *host_info;
1995 struct rte_avp_device_config config;
2000 rte_spinlock_lock(&avp->lock);
2001 if (avp->flags & AVP_F_DETACHED) {
2002 PMD_DRV_LOG(ERR, "Operation not supported during VM live migration\n");
2007 addr = pci_dev->mem_resource[RTE_AVP_PCI_DEVICE_BAR].addr;
2008 host_info = (struct rte_avp_device_info *)addr;
2010 /* Setup required number of queues */
2011 _avp_set_queue_counts(eth_dev);
2013 mask = (ETH_VLAN_STRIP_MASK |
2014 ETH_VLAN_FILTER_MASK |
2015 ETH_VLAN_EXTEND_MASK);
2016 ret = avp_vlan_offload_set(eth_dev, mask);
2018 PMD_DRV_LOG(ERR, "VLAN offload set failed by host, ret=%d\n",
2023 /* update device config */
2024 memset(&config, 0, sizeof(config));
2025 config.device_id = host_info->device_id;
2026 config.driver_type = RTE_AVP_DRIVER_TYPE_DPDK;
2027 config.driver_version = AVP_DPDK_DRIVER_VERSION;
2028 config.features = avp->features;
2029 config.num_tx_queues = avp->num_tx_queues;
2030 config.num_rx_queues = avp->num_rx_queues;
2032 ret = avp_dev_ctrl_set_config(eth_dev, &config);
2034 PMD_DRV_LOG(ERR, "Config request failed by host, ret=%d\n",
2039 avp->flags |= AVP_F_CONFIGURED;
2043 rte_spinlock_unlock(&avp->lock);
2048 avp_dev_start(struct rte_eth_dev *eth_dev)
2050 struct avp_dev *avp = AVP_DEV_PRIVATE_TO_HW(eth_dev->data->dev_private);
2053 rte_spinlock_lock(&avp->lock);
2054 if (avp->flags & AVP_F_DETACHED) {
2055 PMD_DRV_LOG(ERR, "Operation not supported during VM live migration\n");
2060 /* update link state */
2061 ret = avp_dev_ctrl_set_link_state(eth_dev, 1);
2063 PMD_DRV_LOG(ERR, "Link state change failed by host, ret=%d\n",
2068 /* remember current link state */
2069 avp->flags |= AVP_F_LINKUP;
2074 rte_spinlock_unlock(&avp->lock);
2079 avp_dev_stop(struct rte_eth_dev *eth_dev)
2081 struct avp_dev *avp = AVP_DEV_PRIVATE_TO_HW(eth_dev->data->dev_private);
2084 rte_spinlock_lock(&avp->lock);
2085 if (avp->flags & AVP_F_DETACHED) {
2086 PMD_DRV_LOG(ERR, "Operation not supported during VM live migration\n");
2090 /* remember current link state */
2091 avp->flags &= ~AVP_F_LINKUP;
2093 /* update link state */
2094 ret = avp_dev_ctrl_set_link_state(eth_dev, 0);
2096 PMD_DRV_LOG(ERR, "Link state change failed by host, ret=%d\n",
2101 rte_spinlock_unlock(&avp->lock);
2105 avp_dev_close(struct rte_eth_dev *eth_dev)
2107 struct avp_dev *avp = AVP_DEV_PRIVATE_TO_HW(eth_dev->data->dev_private);
2110 if (rte_eal_process_type() != RTE_PROC_PRIMARY)
2113 rte_spinlock_lock(&avp->lock);
2114 if (avp->flags & AVP_F_DETACHED) {
2115 PMD_DRV_LOG(ERR, "Operation not supported during VM live migration\n");
2119 /* remember current link state */
2120 avp->flags &= ~AVP_F_LINKUP;
2121 avp->flags &= ~AVP_F_CONFIGURED;
2123 ret = avp_dev_disable_interrupts(eth_dev);
2125 PMD_DRV_LOG(ERR, "Failed to disable interrupts\n");
2129 /* update device state */
2130 ret = avp_dev_ctrl_shutdown(eth_dev);
2132 PMD_DRV_LOG(ERR, "Device shutdown failed by host, ret=%d\n",
2137 /* release dynamic storage for rx/tx queues */
2138 avp_dev_rx_queue_release_all(eth_dev);
2139 avp_dev_tx_queue_release_all(eth_dev);
2142 rte_spinlock_unlock(&avp->lock);
2147 avp_dev_link_update(struct rte_eth_dev *eth_dev,
2148 __rte_unused int wait_to_complete)
2150 struct avp_dev *avp = AVP_DEV_PRIVATE_TO_HW(eth_dev->data->dev_private);
2151 struct rte_eth_link *link = ð_dev->data->dev_link;
2153 link->link_speed = ETH_SPEED_NUM_10G;
2154 link->link_duplex = ETH_LINK_FULL_DUPLEX;
2155 link->link_status = !!(avp->flags & AVP_F_LINKUP);
2161 avp_dev_promiscuous_enable(struct rte_eth_dev *eth_dev)
2163 struct avp_dev *avp = AVP_DEV_PRIVATE_TO_HW(eth_dev->data->dev_private);
2165 rte_spinlock_lock(&avp->lock);
2166 if ((avp->flags & AVP_F_PROMISC) == 0) {
2167 avp->flags |= AVP_F_PROMISC;
2168 PMD_DRV_LOG(DEBUG, "Promiscuous mode enabled on %u\n",
2169 eth_dev->data->port_id);
2171 rte_spinlock_unlock(&avp->lock);
2177 avp_dev_promiscuous_disable(struct rte_eth_dev *eth_dev)
2179 struct avp_dev *avp = AVP_DEV_PRIVATE_TO_HW(eth_dev->data->dev_private);
2181 rte_spinlock_lock(&avp->lock);
2182 if ((avp->flags & AVP_F_PROMISC) != 0) {
2183 avp->flags &= ~AVP_F_PROMISC;
2184 PMD_DRV_LOG(DEBUG, "Promiscuous mode disabled on %u\n",
2185 eth_dev->data->port_id);
2187 rte_spinlock_unlock(&avp->lock);
2193 avp_dev_info_get(struct rte_eth_dev *eth_dev,
2194 struct rte_eth_dev_info *dev_info)
2196 struct avp_dev *avp = AVP_DEV_PRIVATE_TO_HW(eth_dev->data->dev_private);
2198 dev_info->max_rx_queues = avp->max_rx_queues;
2199 dev_info->max_tx_queues = avp->max_tx_queues;
2200 dev_info->min_rx_bufsize = AVP_MIN_RX_BUFSIZE;
2201 dev_info->max_rx_pktlen = avp->max_rx_pkt_len;
2202 dev_info->max_mac_addrs = AVP_MAX_MAC_ADDRS;
2203 if (avp->host_features & RTE_AVP_FEATURE_VLAN_OFFLOAD) {
2204 dev_info->rx_offload_capa = DEV_RX_OFFLOAD_VLAN_STRIP;
2205 dev_info->tx_offload_capa = DEV_TX_OFFLOAD_VLAN_INSERT;
2212 avp_vlan_offload_set(struct rte_eth_dev *eth_dev, int mask)
2214 struct avp_dev *avp = AVP_DEV_PRIVATE_TO_HW(eth_dev->data->dev_private);
2215 struct rte_eth_conf *dev_conf = ð_dev->data->dev_conf;
2216 uint64_t offloads = dev_conf->rxmode.offloads;
2218 if (mask & ETH_VLAN_STRIP_MASK) {
2219 if (avp->host_features & RTE_AVP_FEATURE_VLAN_OFFLOAD) {
2220 if (offloads & DEV_RX_OFFLOAD_VLAN_STRIP)
2221 avp->features |= RTE_AVP_FEATURE_VLAN_OFFLOAD;
2223 avp->features &= ~RTE_AVP_FEATURE_VLAN_OFFLOAD;
2225 PMD_DRV_LOG(ERR, "VLAN strip offload not supported\n");
2229 if (mask & ETH_VLAN_FILTER_MASK) {
2230 if (offloads & DEV_RX_OFFLOAD_VLAN_FILTER)
2231 PMD_DRV_LOG(ERR, "VLAN filter offload not supported\n");
2234 if (mask & ETH_VLAN_EXTEND_MASK) {
2235 if (offloads & DEV_RX_OFFLOAD_VLAN_EXTEND)
2236 PMD_DRV_LOG(ERR, "VLAN extend offload not supported\n");
2243 avp_dev_stats_get(struct rte_eth_dev *eth_dev, struct rte_eth_stats *stats)
2245 struct avp_dev *avp = AVP_DEV_PRIVATE_TO_HW(eth_dev->data->dev_private);
2248 for (i = 0; i < avp->num_rx_queues; i++) {
2249 struct avp_queue *rxq = avp->dev_data->rx_queues[i];
2252 stats->ipackets += rxq->packets;
2253 stats->ibytes += rxq->bytes;
2254 stats->ierrors += rxq->errors;
2256 stats->q_ipackets[i] += rxq->packets;
2257 stats->q_ibytes[i] += rxq->bytes;
2258 stats->q_errors[i] += rxq->errors;
2262 for (i = 0; i < avp->num_tx_queues; i++) {
2263 struct avp_queue *txq = avp->dev_data->tx_queues[i];
2266 stats->opackets += txq->packets;
2267 stats->obytes += txq->bytes;
2268 stats->oerrors += txq->errors;
2270 stats->q_opackets[i] += txq->packets;
2271 stats->q_obytes[i] += txq->bytes;
2279 avp_dev_stats_reset(struct rte_eth_dev *eth_dev)
2281 struct avp_dev *avp = AVP_DEV_PRIVATE_TO_HW(eth_dev->data->dev_private);
2284 for (i = 0; i < avp->num_rx_queues; i++) {
2285 struct avp_queue *rxq = avp->dev_data->rx_queues[i];
2294 for (i = 0; i < avp->num_tx_queues; i++) {
2295 struct avp_queue *txq = avp->dev_data->tx_queues[i];
2307 RTE_PMD_REGISTER_PCI(net_avp, rte_avp_pmd);
2308 RTE_PMD_REGISTER_PCI_TABLE(net_avp, pci_id_avp_map);
2309 RTE_LOG_REGISTER(avp_logtype_driver, pmd.net.avp.driver, NOTICE);