4 * Copyright (c) 2013-2017, Wind River Systems, Inc.
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions are met:
9 * 1) Redistributions of source code must retain the above copyright notice,
10 * this list of conditions and the following disclaimer.
12 * 2) Redistributions in binary form must reproduce the above copyright notice,
13 * this list of conditions and the following disclaimer in the documentation
14 * and/or other materials provided with the distribution.
16 * 3) Neither the name of Wind River Systems nor the names of its contributors
17 * may be used to endorse or promote products derived from this software
18 * without specific prior written permission.
20 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
21 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
23 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
24 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
25 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
26 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
27 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
28 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
29 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
30 * POSSIBILITY OF SUCH DAMAGE.
39 #include <rte_ethdev.h>
40 #include <rte_memcpy.h>
41 #include <rte_string_fns.h>
42 #include <rte_memzone.h>
43 #include <rte_malloc.h>
44 #include <rte_atomic.h>
45 #include <rte_branch_prediction.h>
47 #include <rte_ether.h>
48 #include <rte_common.h>
49 #include <rte_cycles.h>
50 #include <rte_byteorder.h>
52 #include <rte_memory.h>
56 #include "rte_avp_common.h"
57 #include "rte_avp_fifo.h"
63 static int avp_dev_configure(struct rte_eth_dev *dev);
64 static void avp_dev_info_get(struct rte_eth_dev *dev,
65 struct rte_eth_dev_info *dev_info);
66 static void avp_vlan_offload_set(struct rte_eth_dev *dev, int mask);
67 static int avp_dev_link_update(struct rte_eth_dev *dev,
68 __rte_unused int wait_to_complete);
69 static int avp_dev_rx_queue_setup(struct rte_eth_dev *dev,
72 unsigned int socket_id,
73 const struct rte_eth_rxconf *rx_conf,
74 struct rte_mempool *pool);
76 static int avp_dev_tx_queue_setup(struct rte_eth_dev *dev,
79 unsigned int socket_id,
80 const struct rte_eth_txconf *tx_conf);
82 static void avp_dev_rx_queue_release(void *rxq);
83 static void avp_dev_tx_queue_release(void *txq);
84 #define AVP_DEV_TO_PCI(eth_dev) RTE_DEV_TO_PCI((eth_dev)->device)
87 #define AVP_MAX_MAC_ADDRS 1
88 #define AVP_MIN_RX_BUFSIZE ETHER_MIN_LEN
92 * Defines the number of microseconds to wait before checking the response
93 * queue for completion.
95 #define AVP_REQUEST_DELAY_USECS (5000)
98 * Defines the number times to check the response queue for completion before
99 * declaring a timeout.
101 #define AVP_MAX_REQUEST_RETRY (100)
103 /* Defines the current PCI driver version number */
104 #define AVP_DPDK_DRIVER_VERSION RTE_AVP_CURRENT_GUEST_VERSION
107 * The set of PCI devices this driver supports
109 static const struct rte_pci_id pci_id_avp_map[] = {
110 { .vendor_id = RTE_AVP_PCI_VENDOR_ID,
111 .device_id = RTE_AVP_PCI_DEVICE_ID,
112 .subsystem_vendor_id = RTE_AVP_PCI_SUB_VENDOR_ID,
113 .subsystem_device_id = RTE_AVP_PCI_SUB_DEVICE_ID,
114 .class_id = RTE_CLASS_ANY_ID,
117 { .vendor_id = 0, /* sentinel */
122 * dev_ops for avp, bare necessities for basic operation
124 static const struct eth_dev_ops avp_eth_dev_ops = {
125 .dev_configure = avp_dev_configure,
126 .dev_infos_get = avp_dev_info_get,
127 .vlan_offload_set = avp_vlan_offload_set,
128 .link_update = avp_dev_link_update,
129 .rx_queue_setup = avp_dev_rx_queue_setup,
130 .rx_queue_release = avp_dev_rx_queue_release,
131 .tx_queue_setup = avp_dev_tx_queue_setup,
132 .tx_queue_release = avp_dev_tx_queue_release,
135 /**@{ AVP device flags */
136 #define AVP_F_PROMISC (1 << 1)
137 #define AVP_F_CONFIGURED (1 << 2)
138 #define AVP_F_LINKUP (1 << 3)
141 /* Ethernet device validation marker */
142 #define AVP_ETHDEV_MAGIC 0x92972862
145 * Defines the AVP device attributes which are attached to an RTE ethernet
149 uint32_t magic; /**< Memory validation marker */
150 uint64_t device_id; /**< Unique system identifier */
151 struct ether_addr ethaddr; /**< Host specified MAC address */
152 struct rte_eth_dev_data *dev_data;
153 /**< Back pointer to ethernet device data */
154 volatile uint32_t flags; /**< Device operational flags */
155 uint8_t port_id; /**< Ethernet port identifier */
156 struct rte_mempool *pool; /**< pkt mbuf mempool */
157 unsigned int guest_mbuf_size; /**< local pool mbuf size */
158 unsigned int host_mbuf_size; /**< host mbuf size */
159 unsigned int max_rx_pkt_len; /**< maximum receive unit */
160 uint32_t host_features; /**< Supported feature bitmap */
161 uint32_t features; /**< Enabled feature bitmap */
162 unsigned int num_tx_queues; /**< Negotiated number of transmit queues */
163 unsigned int max_tx_queues; /**< Maximum number of transmit queues */
164 unsigned int num_rx_queues; /**< Negotiated number of receive queues */
165 unsigned int max_rx_queues; /**< Maximum number of receive queues */
167 struct rte_avp_fifo *tx_q[RTE_AVP_MAX_QUEUES]; /**< TX queue */
168 struct rte_avp_fifo *rx_q[RTE_AVP_MAX_QUEUES]; /**< RX queue */
169 struct rte_avp_fifo *alloc_q[RTE_AVP_MAX_QUEUES];
170 /**< Allocated mbufs queue */
171 struct rte_avp_fifo *free_q[RTE_AVP_MAX_QUEUES];
172 /**< To be freed mbufs queue */
174 /* For request & response */
175 struct rte_avp_fifo *req_q; /**< Request queue */
176 struct rte_avp_fifo *resp_q; /**< Response queue */
177 void *host_sync_addr; /**< (host) Req/Resp Mem address */
178 void *sync_addr; /**< Req/Resp Mem address */
179 void *host_mbuf_addr; /**< (host) MBUF pool start address */
180 void *mbuf_addr; /**< MBUF pool start address */
181 } __rte_cache_aligned;
183 /* RTE ethernet private data */
186 } __rte_cache_aligned;
189 /* 32-bit MMIO register write */
190 #define AVP_WRITE32(_value, _addr) rte_write32_relaxed((_value), (_addr))
192 /* 32-bit MMIO register read */
193 #define AVP_READ32(_addr) rte_read32_relaxed((_addr))
195 /* Macro to cast the ethernet device private data to a AVP object */
196 #define AVP_DEV_PRIVATE_TO_HW(adapter) \
197 (&((struct avp_adapter *)adapter)->avp)
200 * Defines the structure of a AVP device queue for the purpose of handling the
201 * receive and transmit burst callback functions
204 struct rte_eth_dev_data *dev_data;
205 /**< Backpointer to ethernet device data */
206 struct avp_dev *avp; /**< Backpointer to AVP device */
208 /**< Queue identifier used for indexing current queue */
210 /**< Base queue identifier for queue servicing */
211 uint16_t queue_limit;
212 /**< Maximum queue identifier for queue servicing */
219 /* send a request and wait for a response
221 * @warning must be called while holding the avp->lock spinlock.
224 avp_dev_process_request(struct avp_dev *avp, struct rte_avp_request *request)
226 unsigned int retry = AVP_MAX_REQUEST_RETRY;
227 void *resp_addr = NULL;
231 PMD_DRV_LOG(DEBUG, "Sending request %u to host\n", request->req_id);
233 request->result = -ENOTSUP;
235 /* Discard any stale responses before starting a new request */
236 while (avp_fifo_get(avp->resp_q, (void **)&resp_addr, 1))
237 PMD_DRV_LOG(DEBUG, "Discarding stale response\n");
239 rte_memcpy(avp->sync_addr, request, sizeof(*request));
240 count = avp_fifo_put(avp->req_q, &avp->host_sync_addr, 1);
242 PMD_DRV_LOG(ERR, "Cannot send request %u to host\n",
249 /* wait for a response */
250 usleep(AVP_REQUEST_DELAY_USECS);
252 count = avp_fifo_count(avp->resp_q);
254 /* response received */
258 if ((count < 1) && (retry == 0)) {
259 PMD_DRV_LOG(ERR, "Timeout while waiting for a response for %u\n",
266 /* retrieve the response */
267 count = avp_fifo_get(avp->resp_q, (void **)&resp_addr, 1);
268 if ((count != 1) || (resp_addr != avp->host_sync_addr)) {
269 PMD_DRV_LOG(ERR, "Invalid response from host, count=%u resp=%p host_sync_addr=%p\n",
270 count, resp_addr, avp->host_sync_addr);
275 /* copy to user buffer */
276 rte_memcpy(request, avp->sync_addr, sizeof(*request));
279 PMD_DRV_LOG(DEBUG, "Result %d received for request %u\n",
280 request->result, request->req_id);
287 avp_dev_ctrl_set_config(struct rte_eth_dev *eth_dev,
288 struct rte_avp_device_config *config)
290 struct avp_dev *avp = AVP_DEV_PRIVATE_TO_HW(eth_dev->data->dev_private);
291 struct rte_avp_request request;
294 /* setup a configure request */
295 memset(&request, 0, sizeof(request));
296 request.req_id = RTE_AVP_REQ_CFG_DEVICE;
297 memcpy(&request.config, config, sizeof(request.config));
299 ret = avp_dev_process_request(avp, &request);
301 return ret == 0 ? request.result : ret;
304 /* translate from host physical address to guest virtual address */
306 avp_dev_translate_address(struct rte_eth_dev *eth_dev,
307 phys_addr_t host_phys_addr)
309 struct rte_pci_device *pci_dev = AVP_DEV_TO_PCI(eth_dev);
310 struct rte_mem_resource *resource;
311 struct rte_avp_memmap_info *info;
312 struct rte_avp_memmap *map;
317 addr = pci_dev->mem_resource[RTE_AVP_PCI_MEMORY_BAR].addr;
318 resource = &pci_dev->mem_resource[RTE_AVP_PCI_MEMMAP_BAR];
319 info = (struct rte_avp_memmap_info *)resource->addr;
322 for (i = 0; i < info->nb_maps; i++) {
323 /* search all segments looking for a matching address */
324 map = &info->maps[i];
326 if ((host_phys_addr >= map->phys_addr) &&
327 (host_phys_addr < (map->phys_addr + map->length))) {
328 /* address is within this segment */
329 offset += (host_phys_addr - map->phys_addr);
330 addr = RTE_PTR_ADD(addr, offset);
332 PMD_DRV_LOG(DEBUG, "Translating host physical 0x%" PRIx64 " to guest virtual 0x%p\n",
333 host_phys_addr, addr);
337 offset += map->length;
343 /* verify that the incoming device version is compatible with our version */
345 avp_dev_version_check(uint32_t version)
347 uint32_t driver = RTE_AVP_STRIP_MINOR_VERSION(AVP_DPDK_DRIVER_VERSION);
348 uint32_t device = RTE_AVP_STRIP_MINOR_VERSION(version);
350 if (device <= driver) {
351 /* the host driver version is less than or equal to ours */
358 /* verify that memory regions have expected version and validation markers */
360 avp_dev_check_regions(struct rte_eth_dev *eth_dev)
362 struct rte_pci_device *pci_dev = AVP_DEV_TO_PCI(eth_dev);
363 struct rte_avp_memmap_info *memmap;
364 struct rte_avp_device_info *info;
365 struct rte_mem_resource *resource;
368 /* Dump resource info for debug */
369 for (i = 0; i < PCI_MAX_RESOURCE; i++) {
370 resource = &pci_dev->mem_resource[i];
371 if ((resource->phys_addr == 0) || (resource->len == 0))
374 PMD_DRV_LOG(DEBUG, "resource[%u]: phys=0x%" PRIx64 " len=%" PRIu64 " addr=%p\n",
375 i, resource->phys_addr,
376 resource->len, resource->addr);
379 case RTE_AVP_PCI_MEMMAP_BAR:
380 memmap = (struct rte_avp_memmap_info *)resource->addr;
381 if ((memmap->magic != RTE_AVP_MEMMAP_MAGIC) ||
382 (memmap->version != RTE_AVP_MEMMAP_VERSION)) {
383 PMD_DRV_LOG(ERR, "Invalid memmap magic 0x%08x and version %u\n",
384 memmap->magic, memmap->version);
389 case RTE_AVP_PCI_DEVICE_BAR:
390 info = (struct rte_avp_device_info *)resource->addr;
391 if ((info->magic != RTE_AVP_DEVICE_MAGIC) ||
392 avp_dev_version_check(info->version)) {
393 PMD_DRV_LOG(ERR, "Invalid device info magic 0x%08x or version 0x%08x > 0x%08x\n",
394 info->magic, info->version,
395 AVP_DPDK_DRIVER_VERSION);
400 case RTE_AVP_PCI_MEMORY_BAR:
401 case RTE_AVP_PCI_MMIO_BAR:
402 if (resource->addr == NULL) {
403 PMD_DRV_LOG(ERR, "Missing address space for BAR%u\n",
409 case RTE_AVP_PCI_MSIX_BAR:
411 /* no validation required */
420 _avp_set_rx_queue_mappings(struct rte_eth_dev *eth_dev, uint16_t rx_queue_id)
422 struct avp_dev *avp =
423 AVP_DEV_PRIVATE_TO_HW(eth_dev->data->dev_private);
424 struct avp_queue *rxq;
425 uint16_t queue_count;
428 rxq = (struct avp_queue *)eth_dev->data->rx_queues[rx_queue_id];
431 * Must map all AVP fifos as evenly as possible between the configured
432 * device queues. Each device queue will service a subset of the AVP
433 * fifos. If there is an odd number of device queues the first set of
434 * device queues will get the extra AVP fifos.
436 queue_count = avp->num_rx_queues / eth_dev->data->nb_rx_queues;
437 remainder = avp->num_rx_queues % eth_dev->data->nb_rx_queues;
438 if (rx_queue_id < remainder) {
439 /* these queues must service one extra FIFO */
440 rxq->queue_base = rx_queue_id * (queue_count + 1);
441 rxq->queue_limit = rxq->queue_base + (queue_count + 1) - 1;
443 /* these queues service the regular number of FIFO */
444 rxq->queue_base = ((remainder * (queue_count + 1)) +
445 ((rx_queue_id - remainder) * queue_count));
446 rxq->queue_limit = rxq->queue_base + queue_count - 1;
449 PMD_DRV_LOG(DEBUG, "rxq %u at %p base %u limit %u\n",
450 rx_queue_id, rxq, rxq->queue_base, rxq->queue_limit);
452 rxq->queue_id = rxq->queue_base;
456 _avp_set_queue_counts(struct rte_eth_dev *eth_dev)
458 struct rte_pci_device *pci_dev = AVP_DEV_TO_PCI(eth_dev);
459 struct avp_dev *avp = AVP_DEV_PRIVATE_TO_HW(eth_dev->data->dev_private);
460 struct rte_avp_device_info *host_info;
463 addr = pci_dev->mem_resource[RTE_AVP_PCI_DEVICE_BAR].addr;
464 host_info = (struct rte_avp_device_info *)addr;
467 * the transmit direction is not negotiated beyond respecting the max
468 * number of queues because the host can handle arbitrary guest tx
469 * queues (host rx queues).
471 avp->num_tx_queues = eth_dev->data->nb_tx_queues;
474 * the receive direction is more restrictive. The host requires a
475 * minimum number of guest rx queues (host tx queues) therefore
476 * negotiate a value that is at least as large as the host minimum
477 * requirement. If the host and guest values are not identical then a
478 * mapping will be established in the receive_queue_setup function.
480 avp->num_rx_queues = RTE_MAX(host_info->min_rx_queues,
481 eth_dev->data->nb_rx_queues);
483 PMD_DRV_LOG(DEBUG, "Requesting %u Tx and %u Rx queues from host\n",
484 avp->num_tx_queues, avp->num_rx_queues);
488 * create a AVP device using the supplied device info by first translating it
489 * to guest address space(s).
492 avp_dev_create(struct rte_pci_device *pci_dev,
493 struct rte_eth_dev *eth_dev)
495 struct avp_dev *avp = AVP_DEV_PRIVATE_TO_HW(eth_dev->data->dev_private);
496 struct rte_avp_device_info *host_info;
497 struct rte_mem_resource *resource;
500 resource = &pci_dev->mem_resource[RTE_AVP_PCI_DEVICE_BAR];
501 if (resource->addr == NULL) {
502 PMD_DRV_LOG(ERR, "BAR%u is not mapped\n",
503 RTE_AVP_PCI_DEVICE_BAR);
506 host_info = (struct rte_avp_device_info *)resource->addr;
508 if ((host_info->magic != RTE_AVP_DEVICE_MAGIC) ||
509 avp_dev_version_check(host_info->version)) {
510 PMD_DRV_LOG(ERR, "Invalid AVP PCI device, magic 0x%08x version 0x%08x > 0x%08x\n",
511 host_info->magic, host_info->version,
512 AVP_DPDK_DRIVER_VERSION);
516 PMD_DRV_LOG(DEBUG, "AVP host device is v%u.%u.%u\n",
517 RTE_AVP_GET_RELEASE_VERSION(host_info->version),
518 RTE_AVP_GET_MAJOR_VERSION(host_info->version),
519 RTE_AVP_GET_MINOR_VERSION(host_info->version));
521 PMD_DRV_LOG(DEBUG, "AVP host supports %u to %u TX queue(s)\n",
522 host_info->min_tx_queues, host_info->max_tx_queues);
523 PMD_DRV_LOG(DEBUG, "AVP host supports %u to %u RX queue(s)\n",
524 host_info->min_rx_queues, host_info->max_rx_queues);
525 PMD_DRV_LOG(DEBUG, "AVP host supports features 0x%08x\n",
526 host_info->features);
528 if (avp->magic != AVP_ETHDEV_MAGIC) {
530 * First time initialization (i.e., not during a VM
533 memset(avp, 0, sizeof(*avp));
534 avp->magic = AVP_ETHDEV_MAGIC;
535 avp->dev_data = eth_dev->data;
536 avp->port_id = eth_dev->data->port_id;
537 avp->host_mbuf_size = host_info->mbuf_size;
538 avp->host_features = host_info->features;
539 memcpy(&avp->ethaddr.addr_bytes[0],
540 host_info->ethaddr, ETHER_ADDR_LEN);
541 /* adjust max values to not exceed our max */
543 RTE_MIN(host_info->max_tx_queues, RTE_AVP_MAX_QUEUES);
545 RTE_MIN(host_info->max_rx_queues, RTE_AVP_MAX_QUEUES);
547 /* Re-attaching during migration */
549 /* TODO... requires validation of host values */
550 if ((host_info->features & avp->features) != avp->features) {
551 PMD_DRV_LOG(ERR, "AVP host features mismatched; 0x%08x, host=0x%08x\n",
552 avp->features, host_info->features);
553 /* this should not be possible; continue for now */
557 /* the device id is allowed to change over migrations */
558 avp->device_id = host_info->device_id;
560 /* translate incoming host addresses to guest address space */
561 PMD_DRV_LOG(DEBUG, "AVP first host tx queue at 0x%" PRIx64 "\n",
563 PMD_DRV_LOG(DEBUG, "AVP first host alloc queue at 0x%" PRIx64 "\n",
564 host_info->alloc_phys);
565 for (i = 0; i < avp->max_tx_queues; i++) {
566 avp->tx_q[i] = avp_dev_translate_address(eth_dev,
567 host_info->tx_phys + (i * host_info->tx_size));
569 avp->alloc_q[i] = avp_dev_translate_address(eth_dev,
570 host_info->alloc_phys + (i * host_info->alloc_size));
573 PMD_DRV_LOG(DEBUG, "AVP first host rx queue at 0x%" PRIx64 "\n",
575 PMD_DRV_LOG(DEBUG, "AVP first host free queue at 0x%" PRIx64 "\n",
576 host_info->free_phys);
577 for (i = 0; i < avp->max_rx_queues; i++) {
578 avp->rx_q[i] = avp_dev_translate_address(eth_dev,
579 host_info->rx_phys + (i * host_info->rx_size));
580 avp->free_q[i] = avp_dev_translate_address(eth_dev,
581 host_info->free_phys + (i * host_info->free_size));
584 PMD_DRV_LOG(DEBUG, "AVP host request queue at 0x%" PRIx64 "\n",
585 host_info->req_phys);
586 PMD_DRV_LOG(DEBUG, "AVP host response queue at 0x%" PRIx64 "\n",
587 host_info->resp_phys);
588 PMD_DRV_LOG(DEBUG, "AVP host sync address at 0x%" PRIx64 "\n",
589 host_info->sync_phys);
590 PMD_DRV_LOG(DEBUG, "AVP host mbuf address at 0x%" PRIx64 "\n",
591 host_info->mbuf_phys);
592 avp->req_q = avp_dev_translate_address(eth_dev, host_info->req_phys);
593 avp->resp_q = avp_dev_translate_address(eth_dev, host_info->resp_phys);
595 avp_dev_translate_address(eth_dev, host_info->sync_phys);
597 avp_dev_translate_address(eth_dev, host_info->mbuf_phys);
600 * store the host mbuf virtual address so that we can calculate
601 * relative offsets for each mbuf as they are processed
603 avp->host_mbuf_addr = host_info->mbuf_va;
604 avp->host_sync_addr = host_info->sync_va;
607 * store the maximum packet length that is supported by the host.
609 avp->max_rx_pkt_len = host_info->max_rx_pkt_len;
610 PMD_DRV_LOG(DEBUG, "AVP host max receive packet length is %u\n",
611 host_info->max_rx_pkt_len);
617 * This function is based on probe() function in avp_pci.c
618 * It returns 0 on success.
621 eth_avp_dev_init(struct rte_eth_dev *eth_dev)
623 struct avp_dev *avp =
624 AVP_DEV_PRIVATE_TO_HW(eth_dev->data->dev_private);
625 struct rte_pci_device *pci_dev;
628 pci_dev = AVP_DEV_TO_PCI(eth_dev);
629 eth_dev->dev_ops = &avp_eth_dev_ops;
631 if (rte_eal_process_type() != RTE_PROC_PRIMARY) {
633 * no setup required on secondary processes. All data is saved
634 * in dev_private by the primary process. All resource should
635 * be mapped to the same virtual address so all pointers should
641 rte_eth_copy_pci_info(eth_dev, pci_dev);
643 eth_dev->data->dev_flags |= RTE_ETH_DEV_DETACHABLE;
645 /* Check BAR resources */
646 ret = avp_dev_check_regions(eth_dev);
648 PMD_DRV_LOG(ERR, "Failed to validate BAR resources, ret=%d\n",
653 /* Handle each subtype */
654 ret = avp_dev_create(pci_dev, eth_dev);
656 PMD_DRV_LOG(ERR, "Failed to create device, ret=%d\n", ret);
660 /* Allocate memory for storing MAC addresses */
661 eth_dev->data->mac_addrs = rte_zmalloc("avp_ethdev", ETHER_ADDR_LEN, 0);
662 if (eth_dev->data->mac_addrs == NULL) {
663 PMD_DRV_LOG(ERR, "Failed to allocate %d bytes needed to store MAC addresses\n",
668 /* Get a mac from device config */
669 ether_addr_copy(&avp->ethaddr, ð_dev->data->mac_addrs[0]);
675 eth_avp_dev_uninit(struct rte_eth_dev *eth_dev)
677 if (rte_eal_process_type() != RTE_PROC_PRIMARY)
680 if (eth_dev->data == NULL)
683 if (eth_dev->data->mac_addrs != NULL) {
684 rte_free(eth_dev->data->mac_addrs);
685 eth_dev->data->mac_addrs = NULL;
692 static struct eth_driver rte_avp_pmd = {
694 .id_table = pci_id_avp_map,
695 .drv_flags = RTE_PCI_DRV_NEED_MAPPING,
696 .probe = rte_eth_dev_pci_probe,
697 .remove = rte_eth_dev_pci_remove,
699 .eth_dev_init = eth_avp_dev_init,
700 .eth_dev_uninit = eth_avp_dev_uninit,
701 .dev_private_size = sizeof(struct avp_adapter),
705 avp_dev_rx_queue_setup(struct rte_eth_dev *eth_dev,
706 uint16_t rx_queue_id,
708 unsigned int socket_id,
709 const struct rte_eth_rxconf *rx_conf,
710 struct rte_mempool *pool)
712 struct avp_dev *avp = AVP_DEV_PRIVATE_TO_HW(eth_dev->data->dev_private);
713 struct rte_pktmbuf_pool_private *mbp_priv;
714 struct avp_queue *rxq;
716 if (rx_queue_id >= eth_dev->data->nb_rx_queues) {
717 PMD_DRV_LOG(ERR, "RX queue id is out of range: rx_queue_id=%u, nb_rx_queues=%u\n",
718 rx_queue_id, eth_dev->data->nb_rx_queues);
722 /* Save mbuf pool pointer */
725 /* Save the local mbuf size */
726 mbp_priv = rte_mempool_get_priv(pool);
727 avp->guest_mbuf_size = (uint16_t)(mbp_priv->mbuf_data_room_size);
728 avp->guest_mbuf_size -= RTE_PKTMBUF_HEADROOM;
730 PMD_DRV_LOG(DEBUG, "AVP max_rx_pkt_len=(%u,%u) mbuf_size=(%u,%u)\n",
732 eth_dev->data->dev_conf.rxmode.max_rx_pkt_len,
734 avp->guest_mbuf_size);
736 /* allocate a queue object */
737 rxq = rte_zmalloc_socket("ethdev RX queue", sizeof(struct avp_queue),
738 RTE_CACHE_LINE_SIZE, socket_id);
740 PMD_DRV_LOG(ERR, "Failed to allocate new Rx queue object\n");
744 /* save back pointers to AVP and Ethernet devices */
746 rxq->dev_data = eth_dev->data;
747 eth_dev->data->rx_queues[rx_queue_id] = (void *)rxq;
749 /* setup the queue receive mapping for the current queue. */
750 _avp_set_rx_queue_mappings(eth_dev, rx_queue_id);
752 PMD_DRV_LOG(DEBUG, "Rx queue %u setup at %p\n", rx_queue_id, rxq);
760 avp_dev_tx_queue_setup(struct rte_eth_dev *eth_dev,
761 uint16_t tx_queue_id,
763 unsigned int socket_id,
764 const struct rte_eth_txconf *tx_conf)
766 struct avp_dev *avp = AVP_DEV_PRIVATE_TO_HW(eth_dev->data->dev_private);
767 struct avp_queue *txq;
769 if (tx_queue_id >= eth_dev->data->nb_tx_queues) {
770 PMD_DRV_LOG(ERR, "TX queue id is out of range: tx_queue_id=%u, nb_tx_queues=%u\n",
771 tx_queue_id, eth_dev->data->nb_tx_queues);
775 /* allocate a queue object */
776 txq = rte_zmalloc_socket("ethdev TX queue", sizeof(struct avp_queue),
777 RTE_CACHE_LINE_SIZE, socket_id);
779 PMD_DRV_LOG(ERR, "Failed to allocate new Tx queue object\n");
783 /* only the configured set of transmit queues are used */
784 txq->queue_id = tx_queue_id;
785 txq->queue_base = tx_queue_id;
786 txq->queue_limit = tx_queue_id;
788 /* save back pointers to AVP and Ethernet devices */
790 txq->dev_data = eth_dev->data;
791 eth_dev->data->tx_queues[tx_queue_id] = (void *)txq;
793 PMD_DRV_LOG(DEBUG, "Tx queue %u setup at %p\n", tx_queue_id, txq);
801 avp_dev_rx_queue_release(void *rx_queue)
803 struct avp_queue *rxq = (struct avp_queue *)rx_queue;
804 struct avp_dev *avp = rxq->avp;
805 struct rte_eth_dev_data *data = avp->dev_data;
808 for (i = 0; i < avp->num_rx_queues; i++) {
809 if (data->rx_queues[i] == rxq)
810 data->rx_queues[i] = NULL;
815 avp_dev_tx_queue_release(void *tx_queue)
817 struct avp_queue *txq = (struct avp_queue *)tx_queue;
818 struct avp_dev *avp = txq->avp;
819 struct rte_eth_dev_data *data = avp->dev_data;
822 for (i = 0; i < avp->num_tx_queues; i++) {
823 if (data->tx_queues[i] == txq)
824 data->tx_queues[i] = NULL;
829 avp_dev_configure(struct rte_eth_dev *eth_dev)
831 struct rte_pci_device *pci_dev = AVP_DEV_TO_PCI(eth_dev);
832 struct avp_dev *avp = AVP_DEV_PRIVATE_TO_HW(eth_dev->data->dev_private);
833 struct rte_avp_device_info *host_info;
834 struct rte_avp_device_config config;
839 addr = pci_dev->mem_resource[RTE_AVP_PCI_DEVICE_BAR].addr;
840 host_info = (struct rte_avp_device_info *)addr;
842 /* Setup required number of queues */
843 _avp_set_queue_counts(eth_dev);
845 mask = (ETH_VLAN_STRIP_MASK |
846 ETH_VLAN_FILTER_MASK |
847 ETH_VLAN_EXTEND_MASK);
848 avp_vlan_offload_set(eth_dev, mask);
850 /* update device config */
851 memset(&config, 0, sizeof(config));
852 config.device_id = host_info->device_id;
853 config.driver_type = RTE_AVP_DRIVER_TYPE_DPDK;
854 config.driver_version = AVP_DPDK_DRIVER_VERSION;
855 config.features = avp->features;
856 config.num_tx_queues = avp->num_tx_queues;
857 config.num_rx_queues = avp->num_rx_queues;
859 ret = avp_dev_ctrl_set_config(eth_dev, &config);
861 PMD_DRV_LOG(ERR, "Config request failed by host, ret=%d\n",
866 avp->flags |= AVP_F_CONFIGURED;
875 avp_dev_link_update(struct rte_eth_dev *eth_dev,
876 __rte_unused int wait_to_complete)
878 struct avp_dev *avp = AVP_DEV_PRIVATE_TO_HW(eth_dev->data->dev_private);
879 struct rte_eth_link *link = ð_dev->data->dev_link;
881 link->link_speed = ETH_SPEED_NUM_10G;
882 link->link_duplex = ETH_LINK_FULL_DUPLEX;
883 link->link_status = !!(avp->flags & AVP_F_LINKUP);
890 avp_dev_info_get(struct rte_eth_dev *eth_dev,
891 struct rte_eth_dev_info *dev_info)
893 struct avp_dev *avp = AVP_DEV_PRIVATE_TO_HW(eth_dev->data->dev_private);
895 dev_info->driver_name = "rte_avp_pmd";
896 dev_info->pci_dev = RTE_DEV_TO_PCI(eth_dev->device);
897 dev_info->max_rx_queues = avp->max_rx_queues;
898 dev_info->max_tx_queues = avp->max_tx_queues;
899 dev_info->min_rx_bufsize = AVP_MIN_RX_BUFSIZE;
900 dev_info->max_rx_pktlen = avp->max_rx_pkt_len;
901 dev_info->max_mac_addrs = AVP_MAX_MAC_ADDRS;
902 if (avp->host_features & RTE_AVP_FEATURE_VLAN_OFFLOAD) {
903 dev_info->rx_offload_capa = DEV_RX_OFFLOAD_VLAN_STRIP;
904 dev_info->tx_offload_capa = DEV_TX_OFFLOAD_VLAN_INSERT;
909 avp_vlan_offload_set(struct rte_eth_dev *eth_dev, int mask)
911 struct avp_dev *avp = AVP_DEV_PRIVATE_TO_HW(eth_dev->data->dev_private);
913 if (mask & ETH_VLAN_STRIP_MASK) {
914 if (avp->host_features & RTE_AVP_FEATURE_VLAN_OFFLOAD) {
915 if (eth_dev->data->dev_conf.rxmode.hw_vlan_strip)
916 avp->features |= RTE_AVP_FEATURE_VLAN_OFFLOAD;
918 avp->features &= ~RTE_AVP_FEATURE_VLAN_OFFLOAD;
920 PMD_DRV_LOG(ERR, "VLAN strip offload not supported\n");
924 if (mask & ETH_VLAN_FILTER_MASK) {
925 if (eth_dev->data->dev_conf.rxmode.hw_vlan_filter)
926 PMD_DRV_LOG(ERR, "VLAN filter offload not supported\n");
929 if (mask & ETH_VLAN_EXTEND_MASK) {
930 if (eth_dev->data->dev_conf.rxmode.hw_vlan_extend)
931 PMD_DRV_LOG(ERR, "VLAN extend offload not supported\n");
935 RTE_PMD_REGISTER_PCI(net_avp, rte_avp_pmd.pci_drv);
936 RTE_PMD_REGISTER_PCI_TABLE(net_avp, pci_id_avp_map);