Branch data Line data Source code
1 : : /* SPDX-License-Identifier: BSD-3-Clause
2 : : * Copyright(c) 2013-2017 Wind River Systems, Inc.
3 : : */
4 : :
5 : : #include <stdint.h>
6 : : #include <string.h>
7 : : #include <stdio.h>
8 : : #include <errno.h>
9 : : #include <unistd.h>
10 : :
11 : : #include <ethdev_driver.h>
12 : : #include <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>
18 : : #include <rte_pci.h>
19 : : #include <bus_pci_driver.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>
25 : : #include <dev_driver.h>
26 : : #include <rte_memory.h>
27 : : #include <rte_eal.h>
28 : : #include <rte_io.h>
29 : :
30 : : #include "rte_avp_common.h"
31 : : #include "rte_avp_fifo.h"
32 : :
33 : : #include "avp_logs.h"
34 : :
35 : : static int avp_dev_create(struct rte_pci_device *pci_dev,
36 : : struct rte_eth_dev *eth_dev);
37 : :
38 : : static int avp_dev_configure(struct rte_eth_dev *dev);
39 : : static int avp_dev_start(struct rte_eth_dev *dev);
40 : : static int 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);
48 : :
49 : : static int avp_dev_rx_queue_setup(struct rte_eth_dev *dev,
50 : : uint16_t rx_queue_id,
51 : : uint16_t nb_rx_desc,
52 : : unsigned int socket_id,
53 : : const struct rte_eth_rxconf *rx_conf,
54 : : struct rte_mempool *pool);
55 : :
56 : : static int avp_dev_tx_queue_setup(struct rte_eth_dev *dev,
57 : : uint16_t tx_queue_id,
58 : : uint16_t nb_tx_desc,
59 : : unsigned int socket_id,
60 : : const struct rte_eth_txconf *tx_conf);
61 : :
62 : : static uint16_t avp_recv_scattered_pkts(void *rx_queue,
63 : : struct rte_mbuf **rx_pkts,
64 : : uint16_t nb_pkts);
65 : :
66 : : static uint16_t avp_recv_pkts(void *rx_queue,
67 : : struct rte_mbuf **rx_pkts,
68 : : uint16_t nb_pkts);
69 : :
70 : : static uint16_t avp_xmit_scattered_pkts(void *tx_queue,
71 : : struct rte_mbuf **tx_pkts,
72 : : uint16_t nb_pkts);
73 : :
74 : : static uint16_t avp_xmit_pkts(void *tx_queue,
75 : : struct rte_mbuf **tx_pkts,
76 : : uint16_t nb_pkts);
77 : :
78 : : static void avp_dev_rx_queue_release(struct rte_eth_dev *dev, uint16_t qid);
79 : : static void avp_dev_tx_queue_release(struct rte_eth_dev *dev, uint16_t qid);
80 : :
81 : : static int avp_dev_stats_get(struct rte_eth_dev *dev,
82 : : struct rte_eth_stats *stats,
83 : : struct eth_queue_stats *qstats);
84 : : static int avp_dev_stats_reset(struct rte_eth_dev *dev);
85 : :
86 : :
87 : : #define AVP_MAX_RX_BURST 64
88 : : #define AVP_MAX_TX_BURST 64
89 : : #define AVP_MAX_MAC_ADDRS 1
90 : : #define AVP_MIN_RX_BUFSIZE RTE_ETHER_MIN_LEN
91 : :
92 : :
93 : : /*
94 : : * Defines the number of microseconds to wait before checking the response
95 : : * queue for completion.
96 : : */
97 : : #define AVP_REQUEST_DELAY_USECS (5000)
98 : :
99 : : /*
100 : : * Defines the number times to check the response queue for completion before
101 : : * declaring a timeout.
102 : : */
103 : : #define AVP_MAX_REQUEST_RETRY (100)
104 : :
105 : : /* Defines the current PCI driver version number */
106 : : #define AVP_DPDK_DRIVER_VERSION RTE_AVP_CURRENT_GUEST_VERSION
107 : :
108 : : /*
109 : : * The set of PCI devices this driver supports
110 : : */
111 : : static const struct rte_pci_id pci_id_avp_map[] = {
112 : : { .vendor_id = RTE_AVP_PCI_VENDOR_ID,
113 : : .device_id = RTE_AVP_PCI_DEVICE_ID,
114 : : .subsystem_vendor_id = RTE_AVP_PCI_SUB_VENDOR_ID,
115 : : .subsystem_device_id = RTE_AVP_PCI_SUB_DEVICE_ID,
116 : : .class_id = RTE_CLASS_ANY_ID,
117 : : },
118 : :
119 : : { .vendor_id = 0, /* sentinel */
120 : : },
121 : : };
122 : :
123 : : /*
124 : : * dev_ops for avp, bare necessities for basic operation
125 : : */
126 : : static const struct eth_dev_ops avp_eth_dev_ops = {
127 : : .dev_configure = avp_dev_configure,
128 : : .dev_start = avp_dev_start,
129 : : .dev_stop = avp_dev_stop,
130 : : .dev_close = avp_dev_close,
131 : : .dev_infos_get = avp_dev_info_get,
132 : : .vlan_offload_set = avp_vlan_offload_set,
133 : : .stats_get = avp_dev_stats_get,
134 : : .stats_reset = avp_dev_stats_reset,
135 : : .link_update = avp_dev_link_update,
136 : : .promiscuous_enable = avp_dev_promiscuous_enable,
137 : : .promiscuous_disable = avp_dev_promiscuous_disable,
138 : : .rx_queue_setup = avp_dev_rx_queue_setup,
139 : : .rx_queue_release = avp_dev_rx_queue_release,
140 : : .tx_queue_setup = avp_dev_tx_queue_setup,
141 : : .tx_queue_release = avp_dev_tx_queue_release,
142 : : };
143 : :
144 : : /**@{ AVP device flags */
145 : : #define AVP_F_PROMISC (1 << 1)
146 : : #define AVP_F_CONFIGURED (1 << 2)
147 : : #define AVP_F_LINKUP (1 << 3)
148 : : #define AVP_F_DETACHED (1 << 4)
149 : : /**@} */
150 : :
151 : : /* Ethernet device validation marker */
152 : : #define AVP_ETHDEV_MAGIC 0x92972862
153 : :
154 : : /*
155 : : * Defines the AVP device attributes which are attached to an RTE ethernet
156 : : * device
157 : : */
158 : : struct __rte_cache_aligned avp_dev {
159 : : uint32_t magic; /**< Memory validation marker */
160 : : uint64_t device_id; /**< Unique system identifier */
161 : : struct rte_ether_addr ethaddr; /**< Host specified MAC address */
162 : : struct rte_eth_dev_data *dev_data;
163 : : /**< Back pointer to ethernet device data */
164 : : volatile uint32_t flags; /**< Device operational flags */
165 : : uint16_t port_id; /**< Ethernet port identifier */
166 : : struct rte_mempool *pool; /**< pkt mbuf mempool */
167 : : unsigned int guest_mbuf_size; /**< local pool mbuf size */
168 : : unsigned int host_mbuf_size; /**< host mbuf size */
169 : : unsigned int max_rx_pkt_len; /**< maximum receive unit */
170 : : uint32_t host_features; /**< Supported feature bitmap */
171 : : uint32_t features; /**< Enabled feature bitmap */
172 : : unsigned int num_tx_queues; /**< Negotiated number of transmit queues */
173 : : unsigned int max_tx_queues; /**< Maximum number of transmit queues */
174 : : unsigned int num_rx_queues; /**< Negotiated number of receive queues */
175 : : unsigned int max_rx_queues; /**< Maximum number of receive queues */
176 : :
177 : : struct rte_avp_fifo *tx_q[RTE_AVP_MAX_QUEUES]; /**< TX queue */
178 : : struct rte_avp_fifo *rx_q[RTE_AVP_MAX_QUEUES]; /**< RX queue */
179 : : struct rte_avp_fifo *alloc_q[RTE_AVP_MAX_QUEUES];
180 : : /**< Allocated mbufs queue */
181 : : struct rte_avp_fifo *free_q[RTE_AVP_MAX_QUEUES];
182 : : /**< To be freed mbufs queue */
183 : :
184 : : /* mutual exclusion over the 'flag' and 'resp_q/req_q' fields */
185 : : rte_spinlock_t lock;
186 : :
187 : : /* For request & response */
188 : : struct rte_avp_fifo *req_q; /**< Request queue */
189 : : struct rte_avp_fifo *resp_q; /**< Response queue */
190 : : void *host_sync_addr; /**< (host) Req/Resp Mem address */
191 : : void *sync_addr; /**< Req/Resp Mem address */
192 : : void *host_mbuf_addr; /**< (host) MBUF pool start address */
193 : : void *mbuf_addr; /**< MBUF pool start address */
194 : : };
195 : :
196 : : /* RTE ethernet private data */
197 : : struct __rte_cache_aligned avp_adapter {
198 : : struct avp_dev avp;
199 : : };
200 : :
201 : :
202 : : /* 32-bit MMIO register write */
203 : : #define AVP_WRITE32(_value, _addr) rte_write32_relaxed((_value), (_addr))
204 : :
205 : : /* 32-bit MMIO register read */
206 : : #define AVP_READ32(_addr) rte_read32_relaxed((_addr))
207 : :
208 : : /* Macro to cast the ethernet device private data to a AVP object */
209 : : #define AVP_DEV_PRIVATE_TO_HW(adapter) \
210 : : (&((struct avp_adapter *)adapter)->avp)
211 : :
212 : : /*
213 : : * Defines the structure of a AVP device queue for the purpose of handling the
214 : : * receive and transmit burst callback functions
215 : : */
216 : : struct avp_queue {
217 : : struct rte_eth_dev_data *dev_data;
218 : : /**< Backpointer to ethernet device data */
219 : : struct avp_dev *avp; /**< Backpointer to AVP device */
220 : : uint16_t queue_id;
221 : : /**< Queue identifier used for indexing current queue */
222 : : uint16_t queue_base;
223 : : /**< Base queue identifier for queue servicing */
224 : : uint16_t queue_limit;
225 : : /**< Maximum queue identifier for queue servicing */
226 : :
227 : : uint64_t packets;
228 : : uint64_t bytes;
229 : : uint64_t errors;
230 : : };
231 : :
232 : : /* send a request and wait for a response
233 : : *
234 : : * @warning must be called while holding the avp->lock spinlock.
235 : : */
236 : : static int
237 : 0 : avp_dev_process_request(struct avp_dev *avp, struct rte_avp_request *request)
238 : : {
239 : : unsigned int retry = AVP_MAX_REQUEST_RETRY;
240 : 0 : void *resp_addr = NULL;
241 : : unsigned int count;
242 : : int ret;
243 : :
244 : 0 : PMD_DRV_LOG_LINE(DEBUG, "Sending request %u to host", request->req_id);
245 : :
246 : 0 : request->result = -ENOTSUP;
247 : :
248 : : /* Discard any stale responses before starting a new request */
249 [ # # # # ]: 0 : while (avp_fifo_get(avp->resp_q, (void **)&resp_addr, 1))
250 : 0 : PMD_DRV_LOG_LINE(DEBUG, "Discarding stale response");
251 : :
252 [ # # ]: 0 : rte_memcpy(avp->sync_addr, request, sizeof(*request));
253 : 0 : count = avp_fifo_put(avp->req_q, &avp->host_sync_addr, 1);
254 [ # # ]: 0 : if (count < 1) {
255 : 0 : PMD_DRV_LOG_LINE(ERR, "Cannot send request %u to host",
256 : : request->req_id);
257 : : ret = -EBUSY;
258 : 0 : goto done;
259 : : }
260 : :
261 : 0 : while (retry--) {
262 : : /* wait for a response */
263 : 0 : usleep(AVP_REQUEST_DELAY_USECS);
264 : :
265 [ # # ]: 0 : count = avp_fifo_count(avp->resp_q);
266 [ # # ]: 0 : if (count >= 1) {
267 : : /* response received */
268 : : break;
269 : : }
270 : :
271 [ # # ]: 0 : if (retry == 0) {
272 : 0 : PMD_DRV_LOG_LINE(ERR, "Timeout while waiting for a response for %u",
273 : : request->req_id);
274 : : ret = -ETIME;
275 : 0 : goto done;
276 : : }
277 : : }
278 : :
279 : : /* retrieve the response */
280 [ # # ]: 0 : count = avp_fifo_get(avp->resp_q, (void **)&resp_addr, 1);
281 [ # # # # ]: 0 : if ((count != 1) || (resp_addr != avp->host_sync_addr)) {
282 : 0 : PMD_DRV_LOG_LINE(ERR, "Invalid response from host, count=%u resp=%p host_sync_addr=%p",
283 : : count, resp_addr, avp->host_sync_addr);
284 : : ret = -ENODATA;
285 : 0 : goto done;
286 : : }
287 : :
288 : : /* copy to user buffer */
289 [ # # ]: 0 : rte_memcpy(request, avp->sync_addr, sizeof(*request));
290 : : ret = 0;
291 : :
292 : 0 : PMD_DRV_LOG_LINE(DEBUG, "Result %d received for request %u",
293 : : request->result, request->req_id);
294 : :
295 : 0 : done:
296 : 0 : return ret;
297 : : }
298 : :
299 : : static int
300 : 0 : avp_dev_ctrl_set_link_state(struct rte_eth_dev *eth_dev, unsigned int state)
301 : : {
302 : 0 : struct avp_dev *avp = AVP_DEV_PRIVATE_TO_HW(eth_dev->data->dev_private);
303 : : struct rte_avp_request request;
304 : : int ret;
305 : :
306 : : /* setup a link state change request */
307 : : memset(&request, 0, sizeof(request));
308 : 0 : request.req_id = RTE_AVP_REQ_CFG_NETWORK_IF;
309 : 0 : request.if_up = state;
310 : :
311 : 0 : ret = avp_dev_process_request(avp, &request);
312 : :
313 [ # # ]: 0 : return ret == 0 ? request.result : ret;
314 : : }
315 : :
316 : : static int
317 : 0 : avp_dev_ctrl_set_config(struct rte_eth_dev *eth_dev,
318 : : struct rte_avp_device_config *config)
319 : : {
320 : 0 : struct avp_dev *avp = AVP_DEV_PRIVATE_TO_HW(eth_dev->data->dev_private);
321 : : struct rte_avp_request request;
322 : : int ret;
323 : :
324 : : /* setup a configure request */
325 : : memset(&request, 0, sizeof(request));
326 : 0 : request.req_id = RTE_AVP_REQ_CFG_DEVICE;
327 : : memcpy(&request.config, config, sizeof(request.config));
328 : :
329 : 0 : ret = avp_dev_process_request(avp, &request);
330 : :
331 [ # # ]: 0 : return ret == 0 ? request.result : ret;
332 : : }
333 : :
334 : : static int
335 : 0 : avp_dev_ctrl_shutdown(struct rte_eth_dev *eth_dev)
336 : : {
337 : 0 : struct avp_dev *avp = AVP_DEV_PRIVATE_TO_HW(eth_dev->data->dev_private);
338 : : struct rte_avp_request request;
339 : : int ret;
340 : :
341 : : /* setup a shutdown request */
342 : : memset(&request, 0, sizeof(request));
343 : 0 : request.req_id = RTE_AVP_REQ_SHUTDOWN_DEVICE;
344 : :
345 : 0 : ret = avp_dev_process_request(avp, &request);
346 : :
347 [ # # ]: 0 : return ret == 0 ? request.result : ret;
348 : : }
349 : :
350 : : /* translate from host mbuf virtual address to guest virtual address */
351 : : static inline void *
352 : : avp_dev_translate_buffer(struct avp_dev *avp, void *host_mbuf_address)
353 : : {
354 : 0 : return RTE_PTR_ADD(RTE_PTR_SUB(host_mbuf_address,
355 : : (uintptr_t)avp->host_mbuf_addr),
356 : : (uintptr_t)avp->mbuf_addr);
357 : : }
358 : :
359 : : /* translate from host physical address to guest virtual address */
360 : : static void *
361 : 0 : avp_dev_translate_address(struct rte_eth_dev *eth_dev,
362 : : rte_iova_t host_phys_addr)
363 : : {
364 : 0 : struct rte_pci_device *pci_dev = RTE_ETH_DEV_TO_PCI(eth_dev);
365 : : struct rte_mem_resource *resource;
366 : : struct rte_avp_memmap_info *info;
367 : : struct rte_avp_memmap *map;
368 : : off_t offset;
369 : : void *addr;
370 : : unsigned int i;
371 : :
372 : 0 : addr = pci_dev->mem_resource[RTE_AVP_PCI_MEMORY_BAR].addr;
373 : : resource = &pci_dev->mem_resource[RTE_AVP_PCI_MEMMAP_BAR];
374 : 0 : info = (struct rte_avp_memmap_info *)resource->addr;
375 : :
376 : : offset = 0;
377 [ # # ]: 0 : for (i = 0; i < info->nb_maps; i++) {
378 : : /* search all segments looking for a matching address */
379 : : map = &info->maps[i];
380 : :
381 [ # # ]: 0 : if ((host_phys_addr >= map->phys_addr) &&
382 [ # # ]: 0 : (host_phys_addr < (map->phys_addr + map->length))) {
383 : : /* address is within this segment */
384 : 0 : offset += (host_phys_addr - map->phys_addr);
385 : 0 : addr = RTE_PTR_ADD(addr, (uintptr_t)offset);
386 : :
387 : 0 : PMD_DRV_LOG_LINE(DEBUG, "Translating host physical 0x%" PRIx64 " to guest virtual 0x%p",
388 : : host_phys_addr, addr);
389 : :
390 : 0 : return addr;
391 : : }
392 : 0 : offset += map->length;
393 : : }
394 : :
395 : : return NULL;
396 : : }
397 : :
398 : : /* verify that the incoming device version is compatible with our version */
399 : : static int
400 : : avp_dev_version_check(uint32_t version)
401 : : {
402 : : uint32_t driver = RTE_AVP_STRIP_MINOR_VERSION(AVP_DPDK_DRIVER_VERSION);
403 : 0 : uint32_t device = RTE_AVP_STRIP_MINOR_VERSION(version);
404 : :
405 : 0 : if (device <= driver) {
406 : : /* the host driver version is less than or equal to ours */
407 : : return 0;
408 : : }
409 : :
410 : : return 1;
411 : : }
412 : :
413 : : /* verify that memory regions have expected version and validation markers */
414 : : static int
415 : 0 : avp_dev_check_regions(struct rte_eth_dev *eth_dev)
416 : : {
417 : 0 : struct rte_pci_device *pci_dev = RTE_ETH_DEV_TO_PCI(eth_dev);
418 : : struct rte_avp_memmap_info *memmap;
419 : : struct rte_avp_device_info *info;
420 : : struct rte_mem_resource *resource;
421 : : unsigned int i;
422 : :
423 : : /* Dump resource info for debug */
424 [ # # ]: 0 : for (i = 0; i < PCI_MAX_RESOURCE; i++) {
425 : : resource = &pci_dev->mem_resource[i];
426 [ # # # # ]: 0 : if ((resource->phys_addr == 0) || (resource->len == 0))
427 : 0 : continue;
428 : :
429 : 0 : PMD_DRV_LOG_LINE(DEBUG, "resource[%u]: phys=0x%" PRIx64 " len=%" PRIu64 " addr=%p",
430 : : i, resource->phys_addr,
431 : : resource->len, resource->addr);
432 : :
433 [ # # # # ]: 0 : switch (i) {
434 : 0 : case RTE_AVP_PCI_MEMMAP_BAR:
435 : 0 : memmap = (struct rte_avp_memmap_info *)resource->addr;
436 [ # # ]: 0 : if ((memmap->magic != RTE_AVP_MEMMAP_MAGIC) ||
437 : : (memmap->version != RTE_AVP_MEMMAP_VERSION)) {
438 : 0 : PMD_DRV_LOG_LINE(ERR, "Invalid memmap magic 0x%08x and version %u",
439 : : memmap->magic, memmap->version);
440 : 0 : return -EINVAL;
441 : : }
442 : : break;
443 : :
444 : 0 : case RTE_AVP_PCI_DEVICE_BAR:
445 : 0 : info = (struct rte_avp_device_info *)resource->addr;
446 [ # # ]: 0 : if ((info->magic != RTE_AVP_DEVICE_MAGIC) ||
447 [ # # ]: 0 : avp_dev_version_check(info->version)) {
448 : 0 : PMD_DRV_LOG_LINE(ERR, "Invalid device info magic 0x%08x or version 0x%08x > 0x%08x",
449 : : info->magic, info->version,
450 : : AVP_DPDK_DRIVER_VERSION);
451 : 0 : return -EINVAL;
452 : : }
453 : : break;
454 : :
455 : 0 : case RTE_AVP_PCI_MEMORY_BAR:
456 : : case RTE_AVP_PCI_MMIO_BAR:
457 [ # # ]: 0 : if (resource->addr == NULL) {
458 : 0 : PMD_DRV_LOG_LINE(ERR, "Missing address space for BAR%u",
459 : : i);
460 : 0 : return -EINVAL;
461 : : }
462 : : break;
463 : :
464 : : case RTE_AVP_PCI_MSIX_BAR:
465 : : default:
466 : : /* no validation required */
467 : : break;
468 : : }
469 : : }
470 : :
471 : : return 0;
472 : : }
473 : :
474 : : static int
475 : 0 : avp_dev_detach(struct rte_eth_dev *eth_dev)
476 : : {
477 : 0 : struct avp_dev *avp = AVP_DEV_PRIVATE_TO_HW(eth_dev->data->dev_private);
478 : : int ret;
479 : :
480 : 0 : PMD_DRV_LOG_LINE(NOTICE, "Detaching port %u from AVP device 0x%" PRIx64 "",
481 : : eth_dev->data->port_id, avp->device_id);
482 : :
483 : 0 : rte_spinlock_lock(&avp->lock);
484 : :
485 [ # # ]: 0 : if (avp->flags & AVP_F_DETACHED) {
486 : 0 : PMD_DRV_LOG_LINE(NOTICE, "port %u already detached",
487 : : eth_dev->data->port_id);
488 : : ret = 0;
489 : 0 : goto unlock;
490 : : }
491 : :
492 : : /* shutdown the device first so the host stops sending us packets. */
493 : 0 : ret = avp_dev_ctrl_shutdown(eth_dev);
494 [ # # ]: 0 : if (ret < 0) {
495 : 0 : PMD_DRV_LOG_LINE(ERR, "Failed to send/recv shutdown to host, ret=%d",
496 : : ret);
497 : 0 : avp->flags &= ~AVP_F_DETACHED;
498 : 0 : goto unlock;
499 : : }
500 : :
501 : 0 : avp->flags |= AVP_F_DETACHED;
502 : : rte_wmb();
503 : :
504 : : /* wait for queues to acknowledge the presence of the detach flag */
505 : : rte_delay_ms(1);
506 : :
507 : : ret = 0;
508 : :
509 : 0 : unlock:
510 : : rte_spinlock_unlock(&avp->lock);
511 : 0 : return ret;
512 : : }
513 : :
514 : : static void
515 : 0 : _avp_set_rx_queue_mappings(struct rte_eth_dev *eth_dev, uint16_t rx_queue_id)
516 : : {
517 : : struct avp_dev *avp =
518 : 0 : AVP_DEV_PRIVATE_TO_HW(eth_dev->data->dev_private);
519 : : struct avp_queue *rxq;
520 : : uint16_t queue_count;
521 : : uint16_t remainder;
522 : :
523 : 0 : rxq = (struct avp_queue *)eth_dev->data->rx_queues[rx_queue_id];
524 : :
525 : : /*
526 : : * Must map all AVP fifos as evenly as possible between the configured
527 : : * device queues. Each device queue will service a subset of the AVP
528 : : * fifos. If there is an odd number of device queues the first set of
529 : : * device queues will get the extra AVP fifos.
530 : : */
531 : 0 : queue_count = avp->num_rx_queues / eth_dev->data->nb_rx_queues;
532 : 0 : remainder = avp->num_rx_queues % eth_dev->data->nb_rx_queues;
533 [ # # ]: 0 : if (rx_queue_id < remainder) {
534 : : /* these queues must service one extra FIFO */
535 : 0 : rxq->queue_base = rx_queue_id * (queue_count + 1);
536 : 0 : rxq->queue_limit = rxq->queue_base + (queue_count + 1) - 1;
537 : : } else {
538 : : /* these queues service the regular number of FIFO */
539 : 0 : rxq->queue_base = ((remainder * (queue_count + 1)) +
540 : : ((rx_queue_id - remainder) * queue_count));
541 : 0 : rxq->queue_limit = rxq->queue_base + queue_count - 1;
542 : : }
543 : :
544 : 0 : PMD_DRV_LOG_LINE(DEBUG, "rxq %u at %p base %u limit %u",
545 : : rx_queue_id, rxq, rxq->queue_base, rxq->queue_limit);
546 : :
547 : 0 : rxq->queue_id = rxq->queue_base;
548 : 0 : }
549 : :
550 : : static void
551 : 0 : _avp_set_queue_counts(struct rte_eth_dev *eth_dev)
552 : : {
553 : 0 : struct rte_pci_device *pci_dev = RTE_ETH_DEV_TO_PCI(eth_dev);
554 : 0 : struct avp_dev *avp = AVP_DEV_PRIVATE_TO_HW(eth_dev->data->dev_private);
555 : : struct rte_avp_device_info *host_info;
556 : : void *addr;
557 : :
558 : 0 : addr = pci_dev->mem_resource[RTE_AVP_PCI_DEVICE_BAR].addr;
559 : : host_info = (struct rte_avp_device_info *)addr;
560 : :
561 : : /*
562 : : * the transmit direction is not negotiated beyond respecting the max
563 : : * number of queues because the host can handle arbitrary guest tx
564 : : * queues (host rx queues).
565 : : */
566 : 0 : avp->num_tx_queues = eth_dev->data->nb_tx_queues;
567 : :
568 : : /*
569 : : * the receive direction is more restrictive. The host requires a
570 : : * minimum number of guest rx queues (host tx queues) therefore
571 : : * negotiate a value that is at least as large as the host minimum
572 : : * requirement. If the host and guest values are not identical then a
573 : : * mapping will be established in the receive_queue_setup function.
574 : : */
575 [ # # ]: 0 : avp->num_rx_queues = RTE_MAX(host_info->min_rx_queues,
576 : : eth_dev->data->nb_rx_queues);
577 : :
578 : 0 : PMD_DRV_LOG_LINE(DEBUG, "Requesting %u Tx and %u Rx queues from host",
579 : : avp->num_tx_queues, avp->num_rx_queues);
580 : 0 : }
581 : :
582 : : static int
583 : 0 : avp_dev_attach(struct rte_eth_dev *eth_dev)
584 : : {
585 : 0 : struct avp_dev *avp = AVP_DEV_PRIVATE_TO_HW(eth_dev->data->dev_private);
586 : : struct rte_avp_device_config config;
587 : : unsigned int i;
588 : : int ret;
589 : :
590 : 0 : PMD_DRV_LOG_LINE(NOTICE, "Attaching port %u to AVP device 0x%" PRIx64 "",
591 : : eth_dev->data->port_id, avp->device_id);
592 : :
593 : 0 : rte_spinlock_lock(&avp->lock);
594 : :
595 [ # # ]: 0 : if (!(avp->flags & AVP_F_DETACHED)) {
596 : 0 : PMD_DRV_LOG_LINE(NOTICE, "port %u already attached",
597 : : eth_dev->data->port_id);
598 : : ret = 0;
599 : 0 : goto unlock;
600 : : }
601 : :
602 : : /*
603 : : * make sure that the detached flag is set prior to reconfiguring the
604 : : * queues.
605 : : */
606 : 0 : avp->flags |= AVP_F_DETACHED;
607 : : rte_wmb();
608 : :
609 : : /*
610 : : * re-run the device create utility which will parse the new host info
611 : : * and setup the AVP device queue pointers.
612 : : */
613 : 0 : ret = avp_dev_create(RTE_ETH_DEV_TO_PCI(eth_dev), eth_dev);
614 [ # # ]: 0 : if (ret < 0) {
615 : 0 : PMD_DRV_LOG_LINE(ERR, "Failed to re-create AVP device, ret=%d",
616 : : ret);
617 : 0 : goto unlock;
618 : : }
619 : :
620 [ # # ]: 0 : if (avp->flags & AVP_F_CONFIGURED) {
621 : : /*
622 : : * Update the receive queue mapping to handle cases where the
623 : : * source and destination hosts have different queue
624 : : * requirements. As long as the DETACHED flag is asserted the
625 : : * queue table should not be referenced so it should be safe to
626 : : * update it.
627 : : */
628 : 0 : _avp_set_queue_counts(eth_dev);
629 [ # # ]: 0 : for (i = 0; i < eth_dev->data->nb_rx_queues; i++)
630 : 0 : _avp_set_rx_queue_mappings(eth_dev, i);
631 : :
632 : : /*
633 : : * Update the host with our config details so that it knows the
634 : : * device is active.
635 : : */
636 : : memset(&config, 0, sizeof(config));
637 : 0 : config.device_id = avp->device_id;
638 : 0 : config.driver_type = RTE_AVP_DRIVER_TYPE_DPDK;
639 : 0 : config.driver_version = AVP_DPDK_DRIVER_VERSION;
640 : 0 : config.features = avp->features;
641 : 0 : config.num_tx_queues = avp->num_tx_queues;
642 : 0 : config.num_rx_queues = avp->num_rx_queues;
643 : 0 : config.if_up = !!(avp->flags & AVP_F_LINKUP);
644 : :
645 : 0 : ret = avp_dev_ctrl_set_config(eth_dev, &config);
646 [ # # ]: 0 : if (ret < 0) {
647 : 0 : PMD_DRV_LOG_LINE(ERR, "Config request failed by host, ret=%d",
648 : : ret);
649 : 0 : goto unlock;
650 : : }
651 : : }
652 : :
653 : : rte_wmb();
654 : 0 : avp->flags &= ~AVP_F_DETACHED;
655 : :
656 : : ret = 0;
657 : :
658 : 0 : unlock:
659 : : rte_spinlock_unlock(&avp->lock);
660 : 0 : return ret;
661 : : }
662 : :
663 : : static void
664 : 0 : avp_dev_interrupt_handler(void *data)
665 : : {
666 : : struct rte_eth_dev *eth_dev = data;
667 : 0 : struct rte_pci_device *pci_dev = RTE_ETH_DEV_TO_PCI(eth_dev);
668 : 0 : void *registers = pci_dev->mem_resource[RTE_AVP_PCI_MMIO_BAR].addr;
669 : : uint32_t status, value;
670 : : int ret;
671 : :
672 [ # # ]: 0 : if (registers == NULL)
673 : 0 : rte_panic("no mapped MMIO register space\n");
674 : :
675 : : /* read the interrupt status register
676 : : * note: this register clears on read so all raised interrupts must be
677 : : * handled or remembered for later processing
678 : : */
679 [ # # ]: 0 : status = AVP_READ32(
680 : : RTE_PTR_ADD(registers,
681 : : RTE_AVP_INTERRUPT_STATUS_OFFSET));
682 : :
683 [ # # ]: 0 : if (status & RTE_AVP_MIGRATION_INTERRUPT_MASK) {
684 : : /* handle interrupt based on current status */
685 [ # # # ]: 0 : value = AVP_READ32(
686 : : RTE_PTR_ADD(registers,
687 : : RTE_AVP_MIGRATION_STATUS_OFFSET));
688 [ # # # ]: 0 : switch (value) {
689 : 0 : case RTE_AVP_MIGRATION_DETACHED:
690 : 0 : ret = avp_dev_detach(eth_dev);
691 : 0 : break;
692 : 0 : case RTE_AVP_MIGRATION_ATTACHED:
693 : 0 : ret = avp_dev_attach(eth_dev);
694 : 0 : break;
695 : 0 : default:
696 : 0 : PMD_DRV_LOG_LINE(ERR, "unexpected migration status, status=%u",
697 : : value);
698 : : ret = -EINVAL;
699 : : }
700 : :
701 : : /* acknowledge the request by writing out our current status */
702 [ # # ]: 0 : value = (ret == 0 ? value : RTE_AVP_MIGRATION_ERROR);
703 : 0 : AVP_WRITE32(value,
704 : : RTE_PTR_ADD(registers,
705 : : RTE_AVP_MIGRATION_ACK_OFFSET));
706 : :
707 : 0 : PMD_DRV_LOG_LINE(NOTICE, "AVP migration interrupt handled");
708 : : }
709 : :
710 [ # # ]: 0 : if (status & ~RTE_AVP_MIGRATION_INTERRUPT_MASK)
711 : 0 : PMD_DRV_LOG_LINE(WARNING, "AVP unexpected interrupt, status=0x%08x",
712 : : status);
713 : :
714 : : /* re-enable UIO interrupt handling */
715 : 0 : ret = rte_intr_ack(pci_dev->intr_handle);
716 [ # # ]: 0 : if (ret < 0) {
717 : 0 : PMD_DRV_LOG_LINE(ERR, "Failed to re-enable UIO interrupts, ret=%d",
718 : : ret);
719 : : /* continue */
720 : : }
721 : 0 : }
722 : :
723 : : static int
724 : 0 : avp_dev_enable_interrupts(struct rte_eth_dev *eth_dev)
725 : : {
726 : 0 : struct rte_pci_device *pci_dev = RTE_ETH_DEV_TO_PCI(eth_dev);
727 : 0 : void *registers = pci_dev->mem_resource[RTE_AVP_PCI_MMIO_BAR].addr;
728 : : int ret;
729 : :
730 [ # # ]: 0 : if (registers == NULL)
731 : : return -EINVAL;
732 : :
733 : : /* enable UIO interrupt handling */
734 : 0 : ret = rte_intr_enable(pci_dev->intr_handle);
735 [ # # ]: 0 : if (ret < 0) {
736 : 0 : PMD_DRV_LOG_LINE(ERR, "Failed to enable UIO interrupts, ret=%d",
737 : : ret);
738 : 0 : return ret;
739 : : }
740 : :
741 : : /* inform the device that all interrupts are enabled */
742 : : AVP_WRITE32(RTE_AVP_APP_INTERRUPTS_MASK,
743 : : RTE_PTR_ADD(registers, RTE_AVP_INTERRUPT_MASK_OFFSET));
744 : :
745 : 0 : return 0;
746 : : }
747 : :
748 : : static int
749 : 0 : avp_dev_disable_interrupts(struct rte_eth_dev *eth_dev)
750 : : {
751 : 0 : struct rte_pci_device *pci_dev = RTE_ETH_DEV_TO_PCI(eth_dev);
752 : 0 : void *registers = pci_dev->mem_resource[RTE_AVP_PCI_MMIO_BAR].addr;
753 : : int ret;
754 : :
755 [ # # ]: 0 : if (registers == NULL)
756 : : return 0;
757 : :
758 : : /* inform the device that all interrupts are disabled */
759 : : AVP_WRITE32(RTE_AVP_NO_INTERRUPTS_MASK,
760 : : RTE_PTR_ADD(registers, RTE_AVP_INTERRUPT_MASK_OFFSET));
761 : :
762 : : /* enable UIO interrupt handling */
763 : 0 : ret = rte_intr_disable(pci_dev->intr_handle);
764 [ # # ]: 0 : if (ret < 0) {
765 : 0 : PMD_DRV_LOG_LINE(ERR, "Failed to disable UIO interrupts, ret=%d",
766 : : ret);
767 : 0 : return ret;
768 : : }
769 : :
770 : : return 0;
771 : : }
772 : :
773 : : static int
774 : 0 : avp_dev_setup_interrupts(struct rte_eth_dev *eth_dev)
775 : : {
776 : 0 : struct rte_pci_device *pci_dev = RTE_ETH_DEV_TO_PCI(eth_dev);
777 : : int ret;
778 : :
779 : : /* register a callback handler with UIO for interrupt notifications */
780 : 0 : ret = rte_intr_callback_register(pci_dev->intr_handle,
781 : : avp_dev_interrupt_handler,
782 : : (void *)eth_dev);
783 [ # # ]: 0 : if (ret < 0) {
784 : 0 : PMD_DRV_LOG_LINE(ERR, "Failed to register UIO interrupt callback, ret=%d",
785 : : ret);
786 : 0 : return ret;
787 : : }
788 : :
789 : : /* enable interrupt processing */
790 : 0 : return avp_dev_enable_interrupts(eth_dev);
791 : : }
792 : :
793 : : static int
794 : : avp_dev_migration_pending(struct rte_eth_dev *eth_dev)
795 : : {
796 : 0 : struct rte_pci_device *pci_dev = RTE_ETH_DEV_TO_PCI(eth_dev);
797 : 0 : void *registers = pci_dev->mem_resource[RTE_AVP_PCI_MMIO_BAR].addr;
798 : : uint32_t value;
799 : :
800 : 0 : if (registers == NULL)
801 : : return 0;
802 : :
803 [ # # ]: 0 : value = AVP_READ32(RTE_PTR_ADD(registers,
804 : : RTE_AVP_MIGRATION_STATUS_OFFSET));
805 [ # # ]: 0 : if (value == RTE_AVP_MIGRATION_DETACHED) {
806 : : /* migration is in progress; ack it if we have not already */
807 : 0 : AVP_WRITE32(value,
808 : : RTE_PTR_ADD(registers,
809 : : RTE_AVP_MIGRATION_ACK_OFFSET));
810 : : return 1;
811 : : }
812 : : return 0;
813 : : }
814 : :
815 : : /*
816 : : * create a AVP device using the supplied device info by first translating it
817 : : * to guest address space(s).
818 : : */
819 : : static int
820 : 0 : avp_dev_create(struct rte_pci_device *pci_dev,
821 : : struct rte_eth_dev *eth_dev)
822 : : {
823 : 0 : struct avp_dev *avp = AVP_DEV_PRIVATE_TO_HW(eth_dev->data->dev_private);
824 : : struct rte_avp_device_info *host_info;
825 : : struct rte_mem_resource *resource;
826 : : unsigned int i;
827 : :
828 : : resource = &pci_dev->mem_resource[RTE_AVP_PCI_DEVICE_BAR];
829 [ # # ]: 0 : if (resource->addr == NULL) {
830 : 0 : PMD_DRV_LOG_LINE(ERR, "BAR%u is not mapped",
831 : : RTE_AVP_PCI_DEVICE_BAR);
832 : 0 : return -EFAULT;
833 : : }
834 : : host_info = (struct rte_avp_device_info *)resource->addr;
835 : :
836 [ # # ]: 0 : if ((host_info->magic != RTE_AVP_DEVICE_MAGIC) ||
837 [ # # ]: 0 : avp_dev_version_check(host_info->version)) {
838 : 0 : PMD_DRV_LOG_LINE(ERR, "Invalid AVP PCI device, magic 0x%08x version 0x%08x > 0x%08x",
839 : : host_info->magic, host_info->version,
840 : : AVP_DPDK_DRIVER_VERSION);
841 : 0 : return -EINVAL;
842 : : }
843 : :
844 : 0 : PMD_DRV_LOG_LINE(DEBUG, "AVP host device is v%u.%u.%u",
845 : : RTE_AVP_GET_RELEASE_VERSION(host_info->version),
846 : : RTE_AVP_GET_MAJOR_VERSION(host_info->version),
847 : : RTE_AVP_GET_MINOR_VERSION(host_info->version));
848 : :
849 : 0 : PMD_DRV_LOG_LINE(DEBUG, "AVP host supports %u to %u TX queue(s)",
850 : : host_info->min_tx_queues, host_info->max_tx_queues);
851 : 0 : PMD_DRV_LOG_LINE(DEBUG, "AVP host supports %u to %u RX queue(s)",
852 : : host_info->min_rx_queues, host_info->max_rx_queues);
853 : 0 : PMD_DRV_LOG_LINE(DEBUG, "AVP host supports features 0x%08x",
854 : : host_info->features);
855 : :
856 [ # # ]: 0 : if (avp->magic != AVP_ETHDEV_MAGIC) {
857 : : /*
858 : : * First time initialization (i.e., not during a VM
859 : : * migration)
860 : : */
861 : : memset(avp, 0, sizeof(*avp));
862 : 0 : avp->magic = AVP_ETHDEV_MAGIC;
863 : 0 : avp->dev_data = eth_dev->data;
864 : 0 : avp->port_id = eth_dev->data->port_id;
865 : 0 : avp->host_mbuf_size = host_info->mbuf_size;
866 : 0 : avp->host_features = host_info->features;
867 : : rte_spinlock_init(&avp->lock);
868 : 0 : memcpy(&avp->ethaddr.addr_bytes[0],
869 : 0 : host_info->ethaddr, RTE_ETHER_ADDR_LEN);
870 : : /* adjust max values to not exceed our max */
871 : 0 : avp->max_tx_queues =
872 : 0 : RTE_MIN(host_info->max_tx_queues, RTE_AVP_MAX_QUEUES);
873 : 0 : avp->max_rx_queues =
874 : 0 : RTE_MIN(host_info->max_rx_queues, RTE_AVP_MAX_QUEUES);
875 : : } else {
876 : : /* Re-attaching during migration */
877 : :
878 : : /* TODO... requires validation of host values */
879 [ # # ]: 0 : if ((host_info->features & avp->features) != avp->features) {
880 : 0 : PMD_DRV_LOG_LINE(ERR, "AVP host features mismatched; 0x%08x, host=0x%08x",
881 : : avp->features, host_info->features);
882 : : /* this should not be possible; continue for now */
883 : : }
884 : : }
885 : :
886 : : /* the device id is allowed to change over migrations */
887 : 0 : avp->device_id = host_info->device_id;
888 : :
889 : : /* translate incoming host addresses to guest address space */
890 : 0 : PMD_DRV_LOG_LINE(DEBUG, "AVP first host tx queue at 0x%" PRIx64 "",
891 : : host_info->tx_phys);
892 : 0 : PMD_DRV_LOG_LINE(DEBUG, "AVP first host alloc queue at 0x%" PRIx64 "",
893 : : host_info->alloc_phys);
894 [ # # ]: 0 : for (i = 0; i < avp->max_tx_queues; i++) {
895 : 0 : avp->tx_q[i] = avp_dev_translate_address(eth_dev,
896 : 0 : host_info->tx_phys + (i * host_info->tx_size));
897 : :
898 : 0 : avp->alloc_q[i] = avp_dev_translate_address(eth_dev,
899 : 0 : host_info->alloc_phys + (i * host_info->alloc_size));
900 : : }
901 : :
902 : 0 : PMD_DRV_LOG_LINE(DEBUG, "AVP first host rx queue at 0x%" PRIx64 "",
903 : : host_info->rx_phys);
904 : 0 : PMD_DRV_LOG_LINE(DEBUG, "AVP first host free queue at 0x%" PRIx64 "",
905 : : host_info->free_phys);
906 [ # # ]: 0 : for (i = 0; i < avp->max_rx_queues; i++) {
907 : 0 : avp->rx_q[i] = avp_dev_translate_address(eth_dev,
908 : 0 : host_info->rx_phys + (i * host_info->rx_size));
909 : 0 : avp->free_q[i] = avp_dev_translate_address(eth_dev,
910 : 0 : host_info->free_phys + (i * host_info->free_size));
911 : : }
912 : :
913 : 0 : PMD_DRV_LOG_LINE(DEBUG, "AVP host request queue at 0x%" PRIx64 "",
914 : : host_info->req_phys);
915 : 0 : PMD_DRV_LOG_LINE(DEBUG, "AVP host response queue at 0x%" PRIx64 "",
916 : : host_info->resp_phys);
917 : 0 : PMD_DRV_LOG_LINE(DEBUG, "AVP host sync address at 0x%" PRIx64 "",
918 : : host_info->sync_phys);
919 : 0 : PMD_DRV_LOG_LINE(DEBUG, "AVP host mbuf address at 0x%" PRIx64 "",
920 : : host_info->mbuf_phys);
921 : 0 : avp->req_q = avp_dev_translate_address(eth_dev, host_info->req_phys);
922 : 0 : avp->resp_q = avp_dev_translate_address(eth_dev, host_info->resp_phys);
923 : 0 : avp->sync_addr =
924 : 0 : avp_dev_translate_address(eth_dev, host_info->sync_phys);
925 : 0 : avp->mbuf_addr =
926 : 0 : avp_dev_translate_address(eth_dev, host_info->mbuf_phys);
927 : :
928 : : /*
929 : : * store the host mbuf virtual address so that we can calculate
930 : : * relative offsets for each mbuf as they are processed
931 : : */
932 : 0 : avp->host_mbuf_addr = host_info->mbuf_va;
933 : 0 : avp->host_sync_addr = host_info->sync_va;
934 : :
935 : : /*
936 : : * store the maximum packet length that is supported by the host.
937 : : */
938 : 0 : avp->max_rx_pkt_len = host_info->max_rx_pkt_len;
939 : 0 : PMD_DRV_LOG_LINE(DEBUG, "AVP host max receive packet length is %u",
940 : : host_info->max_rx_pkt_len);
941 : :
942 : 0 : return 0;
943 : : }
944 : :
945 : : /*
946 : : * This function is based on probe() function in avp_pci.c
947 : : * It returns 0 on success.
948 : : */
949 : : static int
950 : 0 : eth_avp_dev_init(struct rte_eth_dev *eth_dev)
951 : : {
952 : : struct avp_dev *avp =
953 : 0 : AVP_DEV_PRIVATE_TO_HW(eth_dev->data->dev_private);
954 : : struct rte_pci_device *pci_dev;
955 : : int ret;
956 : :
957 : 0 : pci_dev = RTE_ETH_DEV_TO_PCI(eth_dev);
958 : 0 : eth_dev->dev_ops = &avp_eth_dev_ops;
959 : 0 : eth_dev->rx_pkt_burst = &avp_recv_pkts;
960 : 0 : eth_dev->tx_pkt_burst = &avp_xmit_pkts;
961 : :
962 [ # # ]: 0 : if (rte_eal_process_type() != RTE_PROC_PRIMARY) {
963 : : /*
964 : : * no setup required on secondary processes. All data is saved
965 : : * in dev_private by the primary process. All resource should
966 : : * be mapped to the same virtual address so all pointers should
967 : : * be valid.
968 : : */
969 [ # # ]: 0 : if (eth_dev->data->scattered_rx) {
970 : 0 : PMD_DRV_LOG_LINE(NOTICE, "AVP device configured for chained mbufs");
971 : 0 : eth_dev->rx_pkt_burst = avp_recv_scattered_pkts;
972 : 0 : eth_dev->tx_pkt_burst = avp_xmit_scattered_pkts;
973 : : }
974 : 0 : return 0;
975 : : }
976 : :
977 : 0 : rte_eth_copy_pci_info(eth_dev, pci_dev);
978 [ # # ]: 0 : eth_dev->data->dev_flags |= RTE_ETH_DEV_AUTOFILL_QUEUE_XSTATS;
979 : :
980 : : /* Check current migration status */
981 : : if (avp_dev_migration_pending(eth_dev)) {
982 : 0 : PMD_DRV_LOG_LINE(ERR, "VM live migration operation in progress");
983 : 0 : return -EBUSY;
984 : : }
985 : :
986 : : /* Check BAR resources */
987 : 0 : ret = avp_dev_check_regions(eth_dev);
988 [ # # ]: 0 : if (ret < 0) {
989 : 0 : PMD_DRV_LOG_LINE(ERR, "Failed to validate BAR resources, ret=%d",
990 : : ret);
991 : 0 : return ret;
992 : : }
993 : :
994 : : /* Enable interrupts */
995 : 0 : ret = avp_dev_setup_interrupts(eth_dev);
996 [ # # ]: 0 : if (ret < 0) {
997 : 0 : PMD_DRV_LOG_LINE(ERR, "Failed to enable interrupts, ret=%d", ret);
998 : 0 : return ret;
999 : : }
1000 : :
1001 : : /* Handle each subtype */
1002 : 0 : ret = avp_dev_create(pci_dev, eth_dev);
1003 [ # # ]: 0 : if (ret < 0) {
1004 : 0 : PMD_DRV_LOG_LINE(ERR, "Failed to create device, ret=%d", ret);
1005 : 0 : return ret;
1006 : : }
1007 : :
1008 : : /* Allocate memory for storing MAC addresses */
1009 : 0 : eth_dev->data->mac_addrs = rte_zmalloc("avp_ethdev",
1010 : : RTE_ETHER_ADDR_LEN, 0);
1011 [ # # ]: 0 : if (eth_dev->data->mac_addrs == NULL) {
1012 : 0 : PMD_DRV_LOG_LINE(ERR, "Failed to allocate %d bytes needed to store MAC addresses",
1013 : : RTE_ETHER_ADDR_LEN);
1014 : 0 : return -ENOMEM;
1015 : : }
1016 : :
1017 : : /* Get a mac from device config */
1018 : : rte_ether_addr_copy(&avp->ethaddr, ð_dev->data->mac_addrs[0]);
1019 : :
1020 : 0 : return 0;
1021 : : }
1022 : :
1023 : : static int
1024 : 0 : eth_avp_dev_uninit(struct rte_eth_dev *eth_dev)
1025 : : {
1026 [ # # ]: 0 : if (rte_eal_process_type() != RTE_PROC_PRIMARY)
1027 : : return -EPERM;
1028 : :
1029 [ # # ]: 0 : if (eth_dev->data == NULL)
1030 : : return 0;
1031 : :
1032 : 0 : avp_dev_close(eth_dev);
1033 : :
1034 : 0 : return 0;
1035 : : }
1036 : :
1037 : : static int
1038 : 0 : eth_avp_pci_probe(struct rte_pci_driver *pci_drv __rte_unused,
1039 : : struct rte_pci_device *pci_dev)
1040 : : {
1041 : 0 : return rte_eth_dev_pci_generic_probe(pci_dev, sizeof(struct avp_adapter),
1042 : : eth_avp_dev_init);
1043 : : }
1044 : :
1045 : : static int
1046 : 0 : eth_avp_pci_remove(struct rte_pci_device *pci_dev)
1047 : : {
1048 : 0 : return rte_eth_dev_pci_generic_remove(pci_dev,
1049 : : eth_avp_dev_uninit);
1050 : : }
1051 : :
1052 : : static struct rte_pci_driver rte_avp_pmd = {
1053 : : .id_table = pci_id_avp_map,
1054 : : .drv_flags = RTE_PCI_DRV_NEED_MAPPING,
1055 : : .probe = eth_avp_pci_probe,
1056 : : .remove = eth_avp_pci_remove,
1057 : : };
1058 : :
1059 : : static int
1060 : : avp_dev_enable_scattered(struct rte_eth_dev *eth_dev,
1061 : : struct avp_dev *avp)
1062 : : {
1063 : : unsigned int max_rx_pktlen;
1064 : :
1065 : 0 : max_rx_pktlen = eth_dev->data->mtu + RTE_ETHER_HDR_LEN +
1066 : : RTE_ETHER_CRC_LEN;
1067 : :
1068 : 0 : if (max_rx_pktlen > avp->guest_mbuf_size ||
1069 [ # # ]: 0 : max_rx_pktlen > avp->host_mbuf_size) {
1070 : : /*
1071 : : * If the guest MTU is greater than either the host or guest
1072 : : * buffers then chained mbufs have to be enabled in the TX
1073 : : * direction. It is assumed that the application will not need
1074 : : * to send packets larger than their MTU.
1075 : : */
1076 : : return 1;
1077 : : }
1078 : :
1079 [ # # # # ]: 0 : if ((avp->max_rx_pkt_len > avp->guest_mbuf_size) ||
1080 : : (avp->max_rx_pkt_len > avp->host_mbuf_size)) {
1081 : : /*
1082 : : * If the host MRU is greater than its own mbuf size or the
1083 : : * guest mbuf size then chained mbufs have to be enabled in the
1084 : : * RX direction.
1085 : : */
1086 : : return 1;
1087 : : }
1088 : :
1089 : : return 0;
1090 : : }
1091 : :
1092 : : static int
1093 : 0 : avp_dev_rx_queue_setup(struct rte_eth_dev *eth_dev,
1094 : : uint16_t rx_queue_id,
1095 : : uint16_t nb_rx_desc,
1096 : : unsigned int socket_id,
1097 : : const struct rte_eth_rxconf *rx_conf,
1098 : : struct rte_mempool *pool)
1099 : : {
1100 : 0 : struct avp_dev *avp = AVP_DEV_PRIVATE_TO_HW(eth_dev->data->dev_private);
1101 : : struct rte_pktmbuf_pool_private *mbp_priv;
1102 : : struct avp_queue *rxq;
1103 : :
1104 [ # # ]: 0 : if (rx_queue_id >= eth_dev->data->nb_rx_queues) {
1105 : 0 : PMD_DRV_LOG_LINE(ERR, "RX queue id is out of range: rx_queue_id=%u, nb_rx_queues=%u",
1106 : : rx_queue_id, eth_dev->data->nb_rx_queues);
1107 : 0 : return -EINVAL;
1108 : : }
1109 : :
1110 : : /* Save mbuf pool pointer */
1111 [ # # ]: 0 : avp->pool = pool;
1112 : :
1113 : : /* Save the local mbuf size */
1114 : : mbp_priv = rte_mempool_get_priv(pool);
1115 : 0 : avp->guest_mbuf_size = (uint16_t)(mbp_priv->mbuf_data_room_size);
1116 [ # # ]: 0 : avp->guest_mbuf_size -= RTE_PKTMBUF_HEADROOM;
1117 : :
1118 : : if (avp_dev_enable_scattered(eth_dev, avp)) {
1119 [ # # ]: 0 : if (!eth_dev->data->scattered_rx) {
1120 : 0 : PMD_DRV_LOG_LINE(NOTICE, "AVP device configured for chained mbufs");
1121 : 0 : eth_dev->data->scattered_rx = 1;
1122 : 0 : eth_dev->rx_pkt_burst = avp_recv_scattered_pkts;
1123 : 0 : eth_dev->tx_pkt_burst = avp_xmit_scattered_pkts;
1124 : : }
1125 : : }
1126 : :
1127 : 0 : PMD_DRV_LOG_LINE(DEBUG, "AVP max_rx_pkt_len=(%u,%u) mbuf_size=(%u,%u)",
1128 : : avp->max_rx_pkt_len,
1129 : : eth_dev->data->mtu + RTE_ETHER_HDR_LEN + RTE_ETHER_CRC_LEN,
1130 : : avp->host_mbuf_size,
1131 : : avp->guest_mbuf_size);
1132 : :
1133 : : /* allocate a queue object */
1134 : 0 : rxq = rte_zmalloc_socket("ethdev RX queue", sizeof(struct avp_queue),
1135 : : RTE_CACHE_LINE_SIZE, socket_id);
1136 [ # # ]: 0 : if (rxq == NULL) {
1137 : 0 : PMD_DRV_LOG_LINE(ERR, "Failed to allocate new Rx queue object");
1138 : 0 : return -ENOMEM;
1139 : : }
1140 : :
1141 : : /* save back pointers to AVP and Ethernet devices */
1142 : 0 : rxq->avp = avp;
1143 : 0 : rxq->dev_data = eth_dev->data;
1144 : 0 : eth_dev->data->rx_queues[rx_queue_id] = (void *)rxq;
1145 : :
1146 : : /* setup the queue receive mapping for the current queue. */
1147 : 0 : _avp_set_rx_queue_mappings(eth_dev, rx_queue_id);
1148 : :
1149 : 0 : PMD_DRV_LOG_LINE(DEBUG, "Rx queue %u setup at %p", rx_queue_id, rxq);
1150 : :
1151 : : (void)nb_rx_desc;
1152 : : (void)rx_conf;
1153 : 0 : return 0;
1154 : : }
1155 : :
1156 : : static int
1157 : 0 : avp_dev_tx_queue_setup(struct rte_eth_dev *eth_dev,
1158 : : uint16_t tx_queue_id,
1159 : : uint16_t nb_tx_desc,
1160 : : unsigned int socket_id,
1161 : : const struct rte_eth_txconf *tx_conf)
1162 : : {
1163 : 0 : struct avp_dev *avp = AVP_DEV_PRIVATE_TO_HW(eth_dev->data->dev_private);
1164 : : struct avp_queue *txq;
1165 : :
1166 [ # # ]: 0 : if (tx_queue_id >= eth_dev->data->nb_tx_queues) {
1167 : 0 : PMD_DRV_LOG_LINE(ERR, "TX queue id is out of range: tx_queue_id=%u, nb_tx_queues=%u",
1168 : : tx_queue_id, eth_dev->data->nb_tx_queues);
1169 : 0 : return -EINVAL;
1170 : : }
1171 : :
1172 : : /* allocate a queue object */
1173 : 0 : txq = rte_zmalloc_socket("ethdev TX queue", sizeof(struct avp_queue),
1174 : : RTE_CACHE_LINE_SIZE, socket_id);
1175 [ # # ]: 0 : if (txq == NULL) {
1176 : 0 : PMD_DRV_LOG_LINE(ERR, "Failed to allocate new Tx queue object");
1177 : 0 : return -ENOMEM;
1178 : : }
1179 : :
1180 : : /* only the configured set of transmit queues are used */
1181 : 0 : txq->queue_id = tx_queue_id;
1182 : 0 : txq->queue_base = tx_queue_id;
1183 : 0 : txq->queue_limit = tx_queue_id;
1184 : :
1185 : : /* save back pointers to AVP and Ethernet devices */
1186 : 0 : txq->avp = avp;
1187 : 0 : txq->dev_data = eth_dev->data;
1188 : 0 : eth_dev->data->tx_queues[tx_queue_id] = (void *)txq;
1189 : :
1190 : 0 : PMD_DRV_LOG_LINE(DEBUG, "Tx queue %u setup at %p", tx_queue_id, txq);
1191 : :
1192 : : (void)nb_tx_desc;
1193 : : (void)tx_conf;
1194 : 0 : return 0;
1195 : : }
1196 : :
1197 : : static inline int
1198 : : _avp_cmp_ether_addr(struct rte_ether_addr *a, struct rte_ether_addr *b)
1199 : : {
1200 : : uint16_t *_a = (uint16_t *)&a->addr_bytes[0];
1201 : : uint16_t *_b = (uint16_t *)&b->addr_bytes[0];
1202 : 0 : return (_a[0] ^ _b[0]) | (_a[1] ^ _b[1]) | (_a[2] ^ _b[2]);
1203 : : }
1204 : :
1205 : : static inline int
1206 : 0 : _avp_mac_filter(struct avp_dev *avp, struct rte_mbuf *m)
1207 : : {
1208 : 0 : struct rte_ether_hdr *eth = rte_pktmbuf_mtod(m, struct rte_ether_hdr *);
1209 : :
1210 [ # # ]: 0 : if (likely(_avp_cmp_ether_addr(&avp->ethaddr, ð->dst_addr) == 0)) {
1211 : : /* allow all packets destined to our address */
1212 : : return 0;
1213 : : }
1214 : :
1215 [ # # ]: 0 : if (likely(rte_is_broadcast_ether_addr(ð->dst_addr))) {
1216 : : /* allow all broadcast packets */
1217 : : return 0;
1218 : : }
1219 : :
1220 [ # # ]: 0 : if (likely(rte_is_multicast_ether_addr(ð->dst_addr))) {
1221 : : /* allow all multicast packets */
1222 : : return 0;
1223 : : }
1224 : :
1225 [ # # ]: 0 : if (avp->flags & AVP_F_PROMISC) {
1226 : : /* allow all packets when in promiscuous mode */
1227 : 0 : return 0;
1228 : : }
1229 : :
1230 : : return -1;
1231 : : }
1232 : :
1233 : : #ifdef RTE_LIBRTE_AVP_DEBUG_BUFFERS
1234 : : static inline void
1235 : : __avp_dev_buffer_sanity_check(struct avp_dev *avp, struct rte_avp_desc *buf)
1236 : : {
1237 : : struct rte_avp_desc *first_buf;
1238 : : struct rte_avp_desc *pkt_buf;
1239 : : unsigned int pkt_len;
1240 : : unsigned int nb_segs;
1241 : : void *pkt_data;
1242 : : unsigned int i;
1243 : :
1244 : : first_buf = avp_dev_translate_buffer(avp, buf);
1245 : :
1246 : : i = 0;
1247 : : pkt_len = 0;
1248 : : nb_segs = first_buf->nb_segs;
1249 : : do {
1250 : : /* Adjust pointers for guest addressing */
1251 : : pkt_buf = avp_dev_translate_buffer(avp, buf);
1252 : : if (pkt_buf == NULL)
1253 : : rte_panic("bad buffer: segment %u has an invalid address %p\n",
1254 : : i, buf);
1255 : : pkt_data = avp_dev_translate_buffer(avp, pkt_buf->data);
1256 : : if (pkt_data == NULL)
1257 : : rte_panic("bad buffer: segment %u has a NULL data pointer\n",
1258 : : i);
1259 : : if (pkt_buf->data_len == 0)
1260 : : rte_panic("bad buffer: segment %u has 0 data length\n",
1261 : : i);
1262 : : pkt_len += pkt_buf->data_len;
1263 : : nb_segs--;
1264 : : i++;
1265 : :
1266 : : } while (nb_segs && (buf = pkt_buf->next) != NULL);
1267 : :
1268 : : if (nb_segs != 0)
1269 : : rte_panic("bad buffer: expected %u segments found %u\n",
1270 : : first_buf->nb_segs, (first_buf->nb_segs - nb_segs));
1271 : : if (pkt_len != first_buf->pkt_len)
1272 : : rte_panic("bad buffer: expected length %u found %u\n",
1273 : : first_buf->pkt_len, pkt_len);
1274 : : }
1275 : :
1276 : : #define avp_dev_buffer_sanity_check(a, b) \
1277 : : __avp_dev_buffer_sanity_check((a), (b))
1278 : :
1279 : : #else /* RTE_LIBRTE_AVP_DEBUG_BUFFERS */
1280 : :
1281 : : #define avp_dev_buffer_sanity_check(a, b) do {} while (0)
1282 : :
1283 : : #endif
1284 : :
1285 : : /*
1286 : : * Copy a host buffer chain to a set of mbufs. This function assumes that
1287 : : * there exactly the required number of mbufs to copy all source bytes.
1288 : : */
1289 : : static inline struct rte_mbuf *
1290 : 0 : avp_dev_copy_from_buffers(struct avp_dev *avp,
1291 : : struct rte_avp_desc *buf,
1292 : : struct rte_mbuf **mbufs,
1293 : : unsigned int count)
1294 : : {
1295 : : struct rte_mbuf *m_previous = NULL;
1296 : : struct rte_avp_desc *pkt_buf;
1297 : : unsigned int total_length = 0;
1298 : : unsigned int copy_length;
1299 : : unsigned int src_offset;
1300 : : struct rte_mbuf *m;
1301 : : uint16_t ol_flags;
1302 : : uint16_t vlan_tci;
1303 : : void *pkt_data;
1304 : : unsigned int i;
1305 : :
1306 : : avp_dev_buffer_sanity_check(avp, buf);
1307 : :
1308 : : /* setup the first source buffer */
1309 : : pkt_buf = avp_dev_translate_buffer(avp, buf);
1310 : 0 : pkt_data = avp_dev_translate_buffer(avp, pkt_buf->data);
1311 : 0 : total_length = pkt_buf->pkt_len;
1312 : : src_offset = 0;
1313 : :
1314 [ # # ]: 0 : if (pkt_buf->ol_flags & RTE_AVP_RX_VLAN_PKT) {
1315 : : ol_flags = RTE_MBUF_F_RX_VLAN;
1316 : 0 : vlan_tci = pkt_buf->vlan_tci;
1317 : : } else {
1318 : : ol_flags = 0;
1319 : : vlan_tci = 0;
1320 : : }
1321 : :
1322 [ # # ]: 0 : for (i = 0; (i < count) && (buf != NULL); i++) {
1323 : : /* fill each destination buffer */
1324 : 0 : m = mbufs[i];
1325 : :
1326 [ # # ]: 0 : if (m_previous != NULL)
1327 : 0 : m_previous->next = m;
1328 : :
1329 : : m_previous = m;
1330 : :
1331 : : do {
1332 : : /*
1333 : : * Copy as many source buffers as will fit in the
1334 : : * destination buffer.
1335 : : */
1336 : 0 : copy_length = RTE_MIN((avp->guest_mbuf_size -
1337 : : rte_pktmbuf_data_len(m)),
1338 : : (pkt_buf->data_len -
1339 : : src_offset));
1340 : 0 : rte_memcpy(RTE_PTR_ADD(rte_pktmbuf_mtod(m, void *),
1341 : : rte_pktmbuf_data_len(m)),
1342 [ # # ]: 0 : RTE_PTR_ADD(pkt_data, src_offset),
1343 : : copy_length);
1344 : 0 : rte_pktmbuf_data_len(m) += copy_length;
1345 : 0 : src_offset += copy_length;
1346 : :
1347 [ # # ]: 0 : if (likely(src_offset == pkt_buf->data_len)) {
1348 : : /* need a new source buffer */
1349 : 0 : buf = pkt_buf->next;
1350 [ # # ]: 0 : if (buf != NULL) {
1351 : : pkt_buf = avp_dev_translate_buffer(
1352 : : avp, buf);
1353 : 0 : pkt_data = avp_dev_translate_buffer(
1354 : : avp, pkt_buf->data);
1355 : : src_offset = 0;
1356 : : }
1357 : : }
1358 : :
1359 [ # # ]: 0 : if (unlikely(rte_pktmbuf_data_len(m) ==
1360 : : avp->guest_mbuf_size)) {
1361 : : /* need a new destination mbuf */
1362 : : break;
1363 : : }
1364 : :
1365 [ # # ]: 0 : } while (buf != NULL);
1366 : : }
1367 : :
1368 : 0 : m = mbufs[0];
1369 : 0 : m->ol_flags = ol_flags;
1370 : 0 : m->nb_segs = count;
1371 : 0 : rte_pktmbuf_pkt_len(m) = total_length;
1372 : 0 : m->vlan_tci = vlan_tci;
1373 : :
1374 : : __rte_mbuf_sanity_check(m, 1);
1375 : :
1376 : 0 : return m;
1377 : : }
1378 : :
1379 : : static uint16_t
1380 : 0 : avp_recv_scattered_pkts(void *rx_queue,
1381 : : struct rte_mbuf **rx_pkts,
1382 : : uint16_t nb_pkts)
1383 : : {
1384 : : struct avp_queue *rxq = (struct avp_queue *)rx_queue;
1385 : : struct rte_avp_desc *avp_bufs[AVP_MAX_RX_BURST];
1386 : : struct rte_mbuf *mbufs[RTE_AVP_MAX_MBUF_SEGMENTS];
1387 : 0 : struct avp_dev *avp = rxq->avp;
1388 : : struct rte_avp_desc *pkt_buf;
1389 : : struct rte_avp_fifo *free_q;
1390 : : struct rte_avp_fifo *rx_q;
1391 : : struct rte_avp_desc *buf;
1392 : : unsigned int count, avail, n;
1393 : : unsigned int guest_mbuf_size;
1394 : : struct rte_mbuf *m;
1395 : : unsigned int required;
1396 : : unsigned int buf_len;
1397 : : unsigned int port_id;
1398 : : unsigned int i;
1399 : :
1400 [ # # ]: 0 : if (unlikely(avp->flags & AVP_F_DETACHED)) {
1401 : : /* VM live migration in progress */
1402 : : return 0;
1403 : : }
1404 : :
1405 : 0 : guest_mbuf_size = avp->guest_mbuf_size;
1406 : 0 : port_id = avp->port_id;
1407 : 0 : rx_q = avp->rx_q[rxq->queue_id];
1408 : 0 : free_q = avp->free_q[rxq->queue_id];
1409 : :
1410 : : /* setup next queue to service */
1411 [ # # # # ]: 0 : rxq->queue_id = (rxq->queue_id < rxq->queue_limit) ?
1412 : : (rxq->queue_id + 1) : rxq->queue_base;
1413 : :
1414 : : /* determine how many slots are available in the free queue */
1415 : : count = avp_fifo_free_count(free_q);
1416 : :
1417 : : /* determine how many packets are available in the rx queue */
1418 : : avail = avp_fifo_count(rx_q);
1419 : :
1420 : : /* determine how many packets can be received */
1421 : 0 : count = RTE_MIN(count, avail);
1422 : 0 : count = RTE_MIN(count, nb_pkts);
1423 : 0 : count = RTE_MIN(count, (unsigned int)AVP_MAX_RX_BURST);
1424 : :
1425 [ # # ]: 0 : if (unlikely(count == 0)) {
1426 : : /* no free buffers, or no buffers on the rx queue */
1427 : : return 0;
1428 : : }
1429 : :
1430 : : /* retrieve pending packets */
1431 : : n = avp_fifo_get(rx_q, (void **)&avp_bufs, count);
1432 : : PMD_RX_LOG_LINE(DEBUG, "Receiving %u packets from Rx queue at %p",
1433 : : count, rx_q);
1434 : :
1435 : : count = 0;
1436 [ # # ]: 0 : for (i = 0; i < n; i++) {
1437 : : /* prefetch next entry while processing current one */
1438 [ # # ]: 0 : if (i + 1 < n) {
1439 : : pkt_buf = avp_dev_translate_buffer(avp,
1440 : 0 : avp_bufs[i + 1]);
1441 : : rte_prefetch0(pkt_buf);
1442 : : }
1443 : 0 : buf = avp_bufs[i];
1444 : :
1445 : : /* Peek into the first buffer to determine the total length */
1446 : : pkt_buf = avp_dev_translate_buffer(avp, buf);
1447 : 0 : buf_len = pkt_buf->pkt_len;
1448 : :
1449 : : /* Allocate enough mbufs to receive the entire packet */
1450 : 0 : required = (buf_len + guest_mbuf_size - 1) / guest_mbuf_size;
1451 [ # # ]: 0 : if (rte_pktmbuf_alloc_bulk(avp->pool, mbufs, required)) {
1452 : 0 : rxq->dev_data->rx_mbuf_alloc_failed++;
1453 : 0 : continue;
1454 : : }
1455 : :
1456 : : /* Copy the data from the buffers to our mbufs */
1457 : 0 : m = avp_dev_copy_from_buffers(avp, buf, mbufs, required);
1458 : :
1459 : : /* finalize mbuf */
1460 : 0 : m->port = port_id;
1461 : :
1462 [ # # ]: 0 : if (_avp_mac_filter(avp, m) != 0) {
1463 : : /* silently discard packets not destined to our MAC */
1464 : 0 : rte_pktmbuf_free(m);
1465 : 0 : continue;
1466 : : }
1467 : :
1468 : : /* return new mbuf to caller */
1469 : 0 : rx_pkts[count++] = m;
1470 : 0 : rxq->bytes += buf_len;
1471 : : }
1472 : :
1473 : 0 : rxq->packets += count;
1474 : :
1475 : : /* return the buffers to the free queue */
1476 : : avp_fifo_put(free_q, (void **)&avp_bufs[0], n);
1477 : :
1478 : 0 : return count;
1479 : : }
1480 : :
1481 : :
1482 : : static uint16_t
1483 : 0 : avp_recv_pkts(void *rx_queue,
1484 : : struct rte_mbuf **rx_pkts,
1485 : : uint16_t nb_pkts)
1486 : : {
1487 : : struct avp_queue *rxq = (struct avp_queue *)rx_queue;
1488 : : struct rte_avp_desc *avp_bufs[AVP_MAX_RX_BURST];
1489 : 0 : struct avp_dev *avp = rxq->avp;
1490 : : struct rte_avp_desc *pkt_buf;
1491 : : struct rte_avp_fifo *free_q;
1492 : : struct rte_avp_fifo *rx_q;
1493 : : unsigned int count, avail, n;
1494 : : unsigned int pkt_len;
1495 : : struct rte_mbuf *m;
1496 : : char *pkt_data;
1497 : : unsigned int i;
1498 : :
1499 [ # # ]: 0 : if (unlikely(avp->flags & AVP_F_DETACHED)) {
1500 : : /* VM live migration in progress */
1501 : : return 0;
1502 : : }
1503 : :
1504 : 0 : rx_q = avp->rx_q[rxq->queue_id];
1505 : 0 : free_q = avp->free_q[rxq->queue_id];
1506 : :
1507 : : /* setup next queue to service */
1508 [ # # # # ]: 0 : rxq->queue_id = (rxq->queue_id < rxq->queue_limit) ?
1509 : : (rxq->queue_id + 1) : rxq->queue_base;
1510 : :
1511 : : /* determine how many slots are available in the free queue */
1512 : : count = avp_fifo_free_count(free_q);
1513 : :
1514 : : /* determine how many packets are available in the rx queue */
1515 : : avail = avp_fifo_count(rx_q);
1516 : :
1517 : : /* determine how many packets can be received */
1518 : 0 : count = RTE_MIN(count, avail);
1519 : 0 : count = RTE_MIN(count, nb_pkts);
1520 : 0 : count = RTE_MIN(count, (unsigned int)AVP_MAX_RX_BURST);
1521 : :
1522 [ # # ]: 0 : if (unlikely(count == 0)) {
1523 : : /* no free buffers, or no buffers on the rx queue */
1524 : : return 0;
1525 : : }
1526 : :
1527 : : /* retrieve pending packets */
1528 : : n = avp_fifo_get(rx_q, (void **)&avp_bufs, count);
1529 : : PMD_RX_LOG_LINE(DEBUG, "Receiving %u packets from Rx queue at %p",
1530 : : count, rx_q);
1531 : :
1532 : : count = 0;
1533 [ # # ]: 0 : for (i = 0; i < n; i++) {
1534 : : /* prefetch next entry while processing current one */
1535 [ # # ]: 0 : if (i < n - 1) {
1536 : : pkt_buf = avp_dev_translate_buffer(avp,
1537 : 0 : avp_bufs[i + 1]);
1538 : : rte_prefetch0(pkt_buf);
1539 : : }
1540 : :
1541 : : /* Adjust host pointers for guest addressing */
1542 : 0 : pkt_buf = avp_dev_translate_buffer(avp, avp_bufs[i]);
1543 : 0 : pkt_data = avp_dev_translate_buffer(avp, pkt_buf->data);
1544 : 0 : pkt_len = pkt_buf->pkt_len;
1545 : :
1546 [ # # # # ]: 0 : if (unlikely((pkt_len > avp->guest_mbuf_size) ||
1547 : : (pkt_buf->nb_segs > 1))) {
1548 : : /*
1549 : : * application should be using the scattered receive
1550 : : * function
1551 : : */
1552 : 0 : rxq->errors++;
1553 : 0 : continue;
1554 : : }
1555 : :
1556 : : /* process each packet to be transmitted */
1557 : 0 : m = rte_pktmbuf_alloc(avp->pool);
1558 [ # # ]: 0 : if (unlikely(m == NULL)) {
1559 : 0 : rxq->dev_data->rx_mbuf_alloc_failed++;
1560 : 0 : continue;
1561 : : }
1562 : :
1563 : : /* copy data out of the host buffer to our buffer */
1564 : 0 : m->data_off = RTE_PKTMBUF_HEADROOM;
1565 [ # # ]: 0 : rte_memcpy(rte_pktmbuf_mtod(m, void *), pkt_data, pkt_len);
1566 : :
1567 : : /* initialize the local mbuf */
1568 : 0 : rte_pktmbuf_data_len(m) = pkt_len;
1569 : 0 : rte_pktmbuf_pkt_len(m) = pkt_len;
1570 : 0 : m->port = avp->port_id;
1571 : :
1572 [ # # ]: 0 : if (pkt_buf->ol_flags & RTE_AVP_RX_VLAN_PKT) {
1573 : 0 : m->ol_flags = RTE_MBUF_F_RX_VLAN;
1574 : 0 : m->vlan_tci = pkt_buf->vlan_tci;
1575 : : }
1576 : :
1577 [ # # ]: 0 : if (_avp_mac_filter(avp, m) != 0) {
1578 : : /* silently discard packets not destined to our MAC */
1579 : 0 : rte_pktmbuf_free(m);
1580 : 0 : continue;
1581 : : }
1582 : :
1583 : : /* return new mbuf to caller */
1584 : 0 : rx_pkts[count++] = m;
1585 : 0 : rxq->bytes += pkt_len;
1586 : : }
1587 : :
1588 : 0 : rxq->packets += count;
1589 : :
1590 : : /* return the buffers to the free queue */
1591 : : avp_fifo_put(free_q, (void **)&avp_bufs[0], n);
1592 : :
1593 : 0 : return count;
1594 : : }
1595 : :
1596 : : /*
1597 : : * Copy a chained mbuf to a set of host buffers. This function assumes that
1598 : : * there are sufficient destination buffers to contain the entire source
1599 : : * packet.
1600 : : */
1601 : : static inline uint16_t
1602 : 0 : avp_dev_copy_to_buffers(struct avp_dev *avp,
1603 : : struct rte_mbuf *mbuf,
1604 : : struct rte_avp_desc **buffers,
1605 : : unsigned int count)
1606 : : {
1607 : : struct rte_avp_desc *previous_buf = NULL;
1608 : : struct rte_avp_desc *first_buf = NULL;
1609 : : struct rte_avp_desc *pkt_buf;
1610 : : struct rte_avp_desc *buf;
1611 : : size_t total_length;
1612 : : struct rte_mbuf *m;
1613 : : size_t copy_length;
1614 : : size_t src_offset;
1615 : : char *pkt_data;
1616 : : unsigned int i;
1617 : :
1618 : : __rte_mbuf_sanity_check(mbuf, 1);
1619 : :
1620 : : m = mbuf;
1621 : : src_offset = 0;
1622 : 0 : total_length = rte_pktmbuf_pkt_len(m);
1623 [ # # ]: 0 : for (i = 0; (i < count) && (m != NULL); i++) {
1624 : : /* fill each destination buffer */
1625 : 0 : buf = buffers[i];
1626 : :
1627 [ # # ]: 0 : if (i < count - 1) {
1628 : : /* prefetch next entry while processing this one */
1629 : 0 : pkt_buf = avp_dev_translate_buffer(avp, buffers[i + 1]);
1630 : : rte_prefetch0(pkt_buf);
1631 : : }
1632 : :
1633 : : /* Adjust pointers for guest addressing */
1634 : : pkt_buf = avp_dev_translate_buffer(avp, buf);
1635 : 0 : pkt_data = avp_dev_translate_buffer(avp, pkt_buf->data);
1636 : :
1637 : : /* setup the buffer chain */
1638 [ # # ]: 0 : if (previous_buf != NULL)
1639 : 0 : previous_buf->next = buf;
1640 : : else
1641 : : first_buf = pkt_buf;
1642 : :
1643 : : previous_buf = pkt_buf;
1644 : :
1645 : : do {
1646 : : /*
1647 : : * copy as many source mbuf segments as will fit in the
1648 : : * destination buffer.
1649 : : */
1650 : 0 : copy_length = RTE_MIN((avp->host_mbuf_size -
1651 : : pkt_buf->data_len),
1652 : : (rte_pktmbuf_data_len(m) -
1653 : : src_offset));
1654 : 0 : rte_memcpy(RTE_PTR_ADD(pkt_data, pkt_buf->data_len),
1655 [ # # ]: 0 : RTE_PTR_ADD(rte_pktmbuf_mtod(m, void *),
1656 : : src_offset),
1657 : : copy_length);
1658 : 0 : pkt_buf->data_len += copy_length;
1659 : 0 : src_offset += copy_length;
1660 : :
1661 [ # # ]: 0 : if (likely(src_offset == rte_pktmbuf_data_len(m))) {
1662 : : /* need a new source buffer */
1663 : 0 : m = m->next;
1664 : : src_offset = 0;
1665 : : }
1666 : :
1667 [ # # ]: 0 : if (unlikely(pkt_buf->data_len ==
1668 : : avp->host_mbuf_size)) {
1669 : : /* need a new destination buffer */
1670 : : break;
1671 : : }
1672 : :
1673 [ # # ]: 0 : } while (m != NULL);
1674 : : }
1675 : :
1676 : 0 : first_buf->nb_segs = count;
1677 : 0 : first_buf->pkt_len = total_length;
1678 : :
1679 [ # # ]: 0 : if (mbuf->ol_flags & RTE_MBUF_F_TX_VLAN) {
1680 : 0 : first_buf->ol_flags |= RTE_AVP_TX_VLAN_PKT;
1681 : 0 : first_buf->vlan_tci = mbuf->vlan_tci;
1682 : : }
1683 : :
1684 : : avp_dev_buffer_sanity_check(avp, buffers[0]);
1685 : :
1686 : 0 : return total_length;
1687 : : }
1688 : :
1689 : :
1690 : : static uint16_t
1691 : 0 : avp_xmit_scattered_pkts(void *tx_queue,
1692 : : struct rte_mbuf **tx_pkts,
1693 : : uint16_t nb_pkts)
1694 : : {
1695 : 0 : struct rte_avp_desc *avp_bufs[(AVP_MAX_TX_BURST *
1696 : : RTE_AVP_MAX_MBUF_SEGMENTS)] = {};
1697 : : struct avp_queue *txq = (struct avp_queue *)tx_queue;
1698 : : struct rte_avp_desc *tx_bufs[AVP_MAX_TX_BURST];
1699 : 0 : struct avp_dev *avp = txq->avp;
1700 : : struct rte_avp_fifo *alloc_q;
1701 : : struct rte_avp_fifo *tx_q;
1702 : : unsigned int count, avail, n;
1703 : : unsigned int orig_nb_pkts;
1704 : : struct rte_mbuf *m;
1705 : : unsigned int required;
1706 : : unsigned int segments;
1707 : : unsigned int tx_bytes;
1708 : : unsigned int i;
1709 : :
1710 : 0 : orig_nb_pkts = nb_pkts;
1711 [ # # ]: 0 : if (unlikely(avp->flags & AVP_F_DETACHED)) {
1712 : : /* VM live migration in progress */
1713 : : /* TODO ... buffer for X packets then drop? */
1714 : 0 : txq->errors += nb_pkts;
1715 : 0 : return 0;
1716 : : }
1717 : :
1718 : 0 : tx_q = avp->tx_q[txq->queue_id];
1719 : 0 : alloc_q = avp->alloc_q[txq->queue_id];
1720 : :
1721 : : /* limit the number of transmitted packets to the max burst size */
1722 [ # # ]: 0 : if (unlikely(nb_pkts > AVP_MAX_TX_BURST))
1723 : : nb_pkts = AVP_MAX_TX_BURST;
1724 : :
1725 : : /* determine how many buffers are available to copy into */
1726 : : avail = avp_fifo_count(alloc_q);
1727 [ # # ]: 0 : if (unlikely(avail > (AVP_MAX_TX_BURST *
1728 : : RTE_AVP_MAX_MBUF_SEGMENTS)))
1729 : : avail = AVP_MAX_TX_BURST * RTE_AVP_MAX_MBUF_SEGMENTS;
1730 : :
1731 : : /* determine how many slots are available in the transmit queue */
1732 : : count = avp_fifo_free_count(tx_q);
1733 : :
1734 : : /* determine how many packets can be sent */
1735 : 0 : nb_pkts = RTE_MIN(count, nb_pkts);
1736 : :
1737 : : /* determine how many packets will fit in the available buffers */
1738 : : count = 0;
1739 : : segments = 0;
1740 [ # # ]: 0 : for (i = 0; i < nb_pkts; i++) {
1741 : 0 : m = tx_pkts[i];
1742 [ # # ]: 0 : if (likely(i < (unsigned int)nb_pkts - 1)) {
1743 : : /* prefetch next entry while processing this one */
1744 : 0 : rte_prefetch0(tx_pkts[i + 1]);
1745 : : }
1746 : 0 : required = (rte_pktmbuf_pkt_len(m) + avp->host_mbuf_size - 1) /
1747 : : avp->host_mbuf_size;
1748 : :
1749 [ # # ]: 0 : if (unlikely((required == 0) ||
1750 : : (required > RTE_AVP_MAX_MBUF_SEGMENTS)))
1751 : : break;
1752 [ # # ]: 0 : else if (unlikely(required + segments > avail))
1753 : : break;
1754 : : segments += required;
1755 : 0 : count++;
1756 : : }
1757 : 0 : nb_pkts = count;
1758 : :
1759 [ # # ]: 0 : if (unlikely(nb_pkts == 0)) {
1760 : : /* no available buffers, or no space on the tx queue */
1761 : 0 : txq->errors += orig_nb_pkts;
1762 : 0 : return 0;
1763 : : }
1764 : :
1765 : : PMD_TX_LOG_LINE(DEBUG, "Sending %u packets on Tx queue at %p",
1766 : : nb_pkts, tx_q);
1767 : :
1768 : : /* retrieve sufficient send buffers */
1769 : : n = avp_fifo_get(alloc_q, (void **)&avp_bufs, segments);
1770 [ # # ]: 0 : if (unlikely(n != segments)) {
1771 : : PMD_TX_LOG_LINE(DEBUG, "Failed to allocate buffers n=%u, segments=%u, orig=%u",
1772 : : n, segments, orig_nb_pkts);
1773 : 0 : txq->errors += orig_nb_pkts;
1774 : 0 : return 0;
1775 : : }
1776 : :
1777 : : tx_bytes = 0;
1778 : : count = 0;
1779 [ # # ]: 0 : for (i = 0; i < nb_pkts; i++) {
1780 : : /* process each packet to be transmitted */
1781 : 0 : m = tx_pkts[i];
1782 : :
1783 : : /* determine how many buffers are required for this packet */
1784 : 0 : required = (rte_pktmbuf_pkt_len(m) + avp->host_mbuf_size - 1) /
1785 : : avp->host_mbuf_size;
1786 : :
1787 : 0 : tx_bytes += avp_dev_copy_to_buffers(avp, m,
1788 : : &avp_bufs[count], required);
1789 : 0 : tx_bufs[i] = avp_bufs[count];
1790 : 0 : count += required;
1791 : :
1792 : : /* free the original mbuf */
1793 : 0 : rte_pktmbuf_free(m);
1794 : : }
1795 : :
1796 : 0 : txq->packets += nb_pkts;
1797 : 0 : txq->bytes += tx_bytes;
1798 : :
1799 : : #ifdef RTE_LIBRTE_AVP_DEBUG_BUFFERS
1800 : : for (i = 0; i < nb_pkts; i++)
1801 : : avp_dev_buffer_sanity_check(avp, tx_bufs[i]);
1802 : : #endif
1803 : :
1804 : : /* send the packets */
1805 : : n = avp_fifo_put(tx_q, (void **)&tx_bufs[0], nb_pkts);
1806 [ # # ]: 0 : if (unlikely(n != orig_nb_pkts))
1807 : 0 : txq->errors += (orig_nb_pkts - n);
1808 : :
1809 : 0 : return n;
1810 : : }
1811 : :
1812 : :
1813 : : static uint16_t
1814 : 0 : avp_xmit_pkts(void *tx_queue, struct rte_mbuf **tx_pkts, uint16_t nb_pkts)
1815 : : {
1816 : : struct avp_queue *txq = (struct avp_queue *)tx_queue;
1817 : : struct rte_avp_desc *avp_bufs[AVP_MAX_TX_BURST];
1818 : 0 : struct avp_dev *avp = txq->avp;
1819 : : struct rte_avp_desc *pkt_buf;
1820 : : struct rte_avp_fifo *alloc_q;
1821 : : struct rte_avp_fifo *tx_q;
1822 : : unsigned int count, avail, n;
1823 : : struct rte_mbuf *m;
1824 : : unsigned int pkt_len;
1825 : : unsigned int tx_bytes;
1826 : : char *pkt_data;
1827 : : unsigned int i;
1828 : :
1829 [ # # ]: 0 : if (unlikely(avp->flags & AVP_F_DETACHED)) {
1830 : : /* VM live migration in progress */
1831 : : /* TODO ... buffer for X packets then drop?! */
1832 : 0 : txq->errors++;
1833 : 0 : return 0;
1834 : : }
1835 : :
1836 : 0 : tx_q = avp->tx_q[txq->queue_id];
1837 : 0 : alloc_q = avp->alloc_q[txq->queue_id];
1838 : :
1839 : : /* limit the number of transmitted packets to the max burst size */
1840 [ # # ]: 0 : if (unlikely(nb_pkts > AVP_MAX_TX_BURST))
1841 : : nb_pkts = AVP_MAX_TX_BURST;
1842 : :
1843 : : /* determine how many buffers are available to copy into */
1844 : : avail = avp_fifo_count(alloc_q);
1845 : :
1846 : : /* determine how many slots are available in the transmit queue */
1847 : : count = avp_fifo_free_count(tx_q);
1848 : :
1849 : : /* determine how many packets can be sent */
1850 : 0 : count = RTE_MIN(count, avail);
1851 : 0 : count = RTE_MIN(count, nb_pkts);
1852 : :
1853 [ # # ]: 0 : if (unlikely(count == 0)) {
1854 : : /* no available buffers, or no space on the tx queue */
1855 : 0 : txq->errors += nb_pkts;
1856 : 0 : return 0;
1857 : : }
1858 : :
1859 : : PMD_TX_LOG_LINE(DEBUG, "Sending %u packets on Tx queue at %p",
1860 : : count, tx_q);
1861 : :
1862 : : /* retrieve sufficient send buffers */
1863 : : n = avp_fifo_get(alloc_q, (void **)&avp_bufs, count);
1864 [ # # ]: 0 : if (unlikely(n != count)) {
1865 : 0 : txq->errors++;
1866 : 0 : return 0;
1867 : : }
1868 : :
1869 : : tx_bytes = 0;
1870 [ # # ]: 0 : for (i = 0; i < count; i++) {
1871 : : /* prefetch next entry while processing the current one */
1872 [ # # ]: 0 : if (i < count - 1) {
1873 : : pkt_buf = avp_dev_translate_buffer(avp,
1874 : 0 : avp_bufs[i + 1]);
1875 : : rte_prefetch0(pkt_buf);
1876 : : }
1877 : :
1878 : : /* process each packet to be transmitted */
1879 : 0 : m = tx_pkts[i];
1880 : :
1881 : : /* Adjust pointers for guest addressing */
1882 : 0 : pkt_buf = avp_dev_translate_buffer(avp, avp_bufs[i]);
1883 : 0 : pkt_data = avp_dev_translate_buffer(avp, pkt_buf->data);
1884 : 0 : pkt_len = rte_pktmbuf_pkt_len(m);
1885 : :
1886 [ # # # # ]: 0 : if (unlikely((pkt_len > avp->guest_mbuf_size) ||
1887 : : (pkt_len > avp->host_mbuf_size))) {
1888 : : /*
1889 : : * application should be using the scattered transmit
1890 : : * function; send it truncated to avoid the performance
1891 : : * hit of having to manage returning the already
1892 : : * allocated buffer to the free list. This should not
1893 : : * happen since the application should have not send
1894 : : * packages larger than its MTU and it should be
1895 : : * policing its own packet sizes.
1896 : : */
1897 : 0 : txq->errors++;
1898 : 0 : pkt_len = RTE_MIN(avp->guest_mbuf_size,
1899 : : avp->host_mbuf_size);
1900 : : }
1901 : :
1902 : : /* copy data out of our mbuf and into the AVP buffer */
1903 [ # # ]: 0 : rte_memcpy(pkt_data, rte_pktmbuf_mtod(m, void *), pkt_len);
1904 : 0 : pkt_buf->pkt_len = pkt_len;
1905 : 0 : pkt_buf->data_len = pkt_len;
1906 : 0 : pkt_buf->nb_segs = 1;
1907 : 0 : pkt_buf->next = NULL;
1908 : :
1909 [ # # ]: 0 : if (m->ol_flags & RTE_MBUF_F_TX_VLAN) {
1910 : 0 : pkt_buf->ol_flags |= RTE_AVP_TX_VLAN_PKT;
1911 : 0 : pkt_buf->vlan_tci = m->vlan_tci;
1912 : : }
1913 : :
1914 : 0 : tx_bytes += pkt_len;
1915 : :
1916 : : /* free the original mbuf */
1917 : 0 : rte_pktmbuf_free(m);
1918 : : }
1919 : :
1920 : 0 : txq->packets += count;
1921 : 0 : txq->bytes += tx_bytes;
1922 : :
1923 : : /* send the packets */
1924 : : n = avp_fifo_put(tx_q, (void **)&avp_bufs[0], count);
1925 : :
1926 : 0 : return n;
1927 : : }
1928 : :
1929 : : static void
1930 : 0 : avp_dev_rx_queue_release(struct rte_eth_dev *eth_dev, uint16_t rx_queue_id)
1931 : : {
1932 [ # # ]: 0 : if (eth_dev->data->rx_queues[rx_queue_id] != NULL) {
1933 : 0 : rte_free(eth_dev->data->rx_queues[rx_queue_id]);
1934 : 0 : eth_dev->data->rx_queues[rx_queue_id] = NULL;
1935 : : }
1936 : 0 : }
1937 : :
1938 : : static void
1939 : 0 : avp_dev_rx_queue_release_all(struct rte_eth_dev *eth_dev)
1940 : : {
1941 : 0 : struct avp_dev *avp = AVP_DEV_PRIVATE_TO_HW(eth_dev->data->dev_private);
1942 : 0 : struct rte_eth_dev_data *data = avp->dev_data;
1943 : : unsigned int i;
1944 : :
1945 [ # # ]: 0 : for (i = 0; i < avp->num_rx_queues; i++) {
1946 [ # # ]: 0 : if (data->rx_queues[i]) {
1947 : 0 : rte_free(data->rx_queues[i]);
1948 : 0 : data->rx_queues[i] = NULL;
1949 : : }
1950 : : }
1951 : 0 : }
1952 : :
1953 : : static void
1954 : 0 : avp_dev_tx_queue_release(struct rte_eth_dev *eth_dev, uint16_t tx_queue_id)
1955 : : {
1956 [ # # ]: 0 : if (eth_dev->data->tx_queues[tx_queue_id] != NULL) {
1957 : 0 : rte_free(eth_dev->data->tx_queues[tx_queue_id]);
1958 : 0 : eth_dev->data->tx_queues[tx_queue_id] = NULL;
1959 : : }
1960 : 0 : }
1961 : :
1962 : : static void
1963 : 0 : avp_dev_tx_queue_release_all(struct rte_eth_dev *eth_dev)
1964 : : {
1965 : 0 : struct avp_dev *avp = AVP_DEV_PRIVATE_TO_HW(eth_dev->data->dev_private);
1966 : 0 : struct rte_eth_dev_data *data = avp->dev_data;
1967 : : unsigned int i;
1968 : :
1969 [ # # ]: 0 : for (i = 0; i < avp->num_tx_queues; i++) {
1970 [ # # ]: 0 : if (data->tx_queues[i]) {
1971 : 0 : rte_free(data->tx_queues[i]);
1972 : 0 : data->tx_queues[i] = NULL;
1973 : : }
1974 : : }
1975 : 0 : }
1976 : :
1977 : : static int
1978 : 0 : avp_dev_configure(struct rte_eth_dev *eth_dev)
1979 : : {
1980 : 0 : struct rte_pci_device *pci_dev = RTE_ETH_DEV_TO_PCI(eth_dev);
1981 : 0 : struct avp_dev *avp = AVP_DEV_PRIVATE_TO_HW(eth_dev->data->dev_private);
1982 : : struct rte_avp_device_info *host_info;
1983 : : struct rte_avp_device_config config;
1984 : : int mask = 0;
1985 : : void *addr;
1986 : : int ret;
1987 : :
1988 : 0 : rte_spinlock_lock(&avp->lock);
1989 [ # # ]: 0 : if (avp->flags & AVP_F_DETACHED) {
1990 : 0 : PMD_DRV_LOG_LINE(ERR, "Operation not supported during VM live migration");
1991 : : ret = -ENOTSUP;
1992 : 0 : goto unlock;
1993 : : }
1994 : :
1995 : 0 : addr = pci_dev->mem_resource[RTE_AVP_PCI_DEVICE_BAR].addr;
1996 : : host_info = (struct rte_avp_device_info *)addr;
1997 : :
1998 : : /* Setup required number of queues */
1999 : 0 : _avp_set_queue_counts(eth_dev);
2000 : :
2001 : : mask = (RTE_ETH_VLAN_STRIP_MASK |
2002 : : RTE_ETH_VLAN_FILTER_MASK |
2003 : : RTE_ETH_VLAN_EXTEND_MASK);
2004 : 0 : ret = avp_vlan_offload_set(eth_dev, mask);
2005 [ # # ]: 0 : if (ret < 0) {
2006 : 0 : PMD_DRV_LOG_LINE(ERR, "VLAN offload set failed by host, ret=%d",
2007 : : ret);
2008 : 0 : goto unlock;
2009 : : }
2010 : :
2011 : : /* update device config */
2012 : : memset(&config, 0, sizeof(config));
2013 : 0 : config.device_id = host_info->device_id;
2014 : 0 : config.driver_type = RTE_AVP_DRIVER_TYPE_DPDK;
2015 : 0 : config.driver_version = AVP_DPDK_DRIVER_VERSION;
2016 : 0 : config.features = avp->features;
2017 : 0 : config.num_tx_queues = avp->num_tx_queues;
2018 : 0 : config.num_rx_queues = avp->num_rx_queues;
2019 : :
2020 : 0 : ret = avp_dev_ctrl_set_config(eth_dev, &config);
2021 [ # # ]: 0 : if (ret < 0) {
2022 : 0 : PMD_DRV_LOG_LINE(ERR, "Config request failed by host, ret=%d",
2023 : : ret);
2024 : 0 : goto unlock;
2025 : : }
2026 : :
2027 : 0 : avp->flags |= AVP_F_CONFIGURED;
2028 : : ret = 0;
2029 : :
2030 : 0 : unlock:
2031 : : rte_spinlock_unlock(&avp->lock);
2032 : 0 : return ret;
2033 : : }
2034 : :
2035 : : static int
2036 : 0 : avp_dev_start(struct rte_eth_dev *eth_dev)
2037 : : {
2038 : 0 : struct avp_dev *avp = AVP_DEV_PRIVATE_TO_HW(eth_dev->data->dev_private);
2039 : : uint16_t i;
2040 : : int ret;
2041 : :
2042 : 0 : rte_spinlock_lock(&avp->lock);
2043 [ # # ]: 0 : if (avp->flags & AVP_F_DETACHED) {
2044 : 0 : PMD_DRV_LOG_LINE(ERR, "Operation not supported during VM live migration");
2045 : : ret = -ENOTSUP;
2046 : 0 : goto unlock;
2047 : : }
2048 : :
2049 : : /* update link state */
2050 : 0 : ret = avp_dev_ctrl_set_link_state(eth_dev, 1);
2051 [ # # ]: 0 : if (ret < 0) {
2052 : 0 : PMD_DRV_LOG_LINE(ERR, "Link state change failed by host, ret=%d",
2053 : : ret);
2054 : 0 : goto unlock;
2055 : : }
2056 : :
2057 : : /* remember current link state */
2058 : 0 : avp->flags |= AVP_F_LINKUP;
2059 : :
2060 [ # # ]: 0 : for (i = 0; i < avp->num_rx_queues; i++)
2061 : 0 : eth_dev->data->rx_queue_state[i] = RTE_ETH_QUEUE_STATE_STARTED;
2062 [ # # ]: 0 : for (i = 0; i < avp->num_tx_queues; i++)
2063 : 0 : eth_dev->data->tx_queue_state[i] = RTE_ETH_QUEUE_STATE_STARTED;
2064 : :
2065 : : ret = 0;
2066 : :
2067 : 0 : unlock:
2068 : : rte_spinlock_unlock(&avp->lock);
2069 : 0 : return ret;
2070 : : }
2071 : :
2072 : : static int
2073 : 0 : avp_dev_stop(struct rte_eth_dev *eth_dev)
2074 : : {
2075 : 0 : struct avp_dev *avp = AVP_DEV_PRIVATE_TO_HW(eth_dev->data->dev_private);
2076 : : uint16_t i;
2077 : : int ret;
2078 : :
2079 : 0 : rte_spinlock_lock(&avp->lock);
2080 [ # # ]: 0 : if (avp->flags & AVP_F_DETACHED) {
2081 : 0 : PMD_DRV_LOG_LINE(ERR, "Operation not supported during VM live migration");
2082 : : ret = -ENOTSUP;
2083 : 0 : goto unlock;
2084 : : }
2085 : :
2086 : : /* remember current link state */
2087 : 0 : avp->flags &= ~AVP_F_LINKUP;
2088 : :
2089 : : /* update link state */
2090 : 0 : ret = avp_dev_ctrl_set_link_state(eth_dev, 0);
2091 [ # # ]: 0 : if (ret < 0) {
2092 : 0 : PMD_DRV_LOG_LINE(ERR, "Link state change failed by host, ret=%d",
2093 : : ret);
2094 : : }
2095 : :
2096 [ # # ]: 0 : for (i = 0; i < avp->num_rx_queues; i++)
2097 : 0 : eth_dev->data->rx_queue_state[i] = RTE_ETH_QUEUE_STATE_STOPPED;
2098 [ # # ]: 0 : for (i = 0; i < avp->num_tx_queues; i++)
2099 : 0 : eth_dev->data->tx_queue_state[i] = RTE_ETH_QUEUE_STATE_STOPPED;
2100 : :
2101 : 0 : unlock:
2102 : : rte_spinlock_unlock(&avp->lock);
2103 : 0 : return ret;
2104 : : }
2105 : :
2106 : : static int
2107 : 0 : avp_dev_close(struct rte_eth_dev *eth_dev)
2108 : : {
2109 : 0 : struct avp_dev *avp = AVP_DEV_PRIVATE_TO_HW(eth_dev->data->dev_private);
2110 : : int ret;
2111 : :
2112 [ # # ]: 0 : if (rte_eal_process_type() != RTE_PROC_PRIMARY)
2113 : : return 0;
2114 : :
2115 : 0 : rte_spinlock_lock(&avp->lock);
2116 [ # # ]: 0 : if (avp->flags & AVP_F_DETACHED) {
2117 : 0 : PMD_DRV_LOG_LINE(ERR, "Operation not supported during VM live migration");
2118 : 0 : goto unlock;
2119 : : }
2120 : :
2121 : : /* remember current link state */
2122 : 0 : avp->flags &= ~AVP_F_LINKUP;
2123 : 0 : avp->flags &= ~AVP_F_CONFIGURED;
2124 : :
2125 : 0 : ret = avp_dev_disable_interrupts(eth_dev);
2126 [ # # ]: 0 : if (ret < 0) {
2127 : 0 : PMD_DRV_LOG_LINE(ERR, "Failed to disable interrupts");
2128 : : /* continue */
2129 : : }
2130 : :
2131 : : /* update device state */
2132 : 0 : ret = avp_dev_ctrl_shutdown(eth_dev);
2133 [ # # ]: 0 : if (ret < 0) {
2134 : 0 : PMD_DRV_LOG_LINE(ERR, "Device shutdown failed by host, ret=%d",
2135 : : ret);
2136 : : /* continue */
2137 : : }
2138 : :
2139 : : /* release dynamic storage for rx/tx queues */
2140 : 0 : avp_dev_rx_queue_release_all(eth_dev);
2141 : 0 : avp_dev_tx_queue_release_all(eth_dev);
2142 : :
2143 : 0 : unlock:
2144 : : rte_spinlock_unlock(&avp->lock);
2145 : 0 : return 0;
2146 : : }
2147 : :
2148 : : static int
2149 : 0 : avp_dev_link_update(struct rte_eth_dev *eth_dev,
2150 : : __rte_unused int wait_to_complete)
2151 : : {
2152 : 0 : struct avp_dev *avp = AVP_DEV_PRIVATE_TO_HW(eth_dev->data->dev_private);
2153 : : struct rte_eth_link *link = ð_dev->data->dev_link;
2154 : :
2155 : 0 : link->link_speed = RTE_ETH_SPEED_NUM_10G;
2156 : 0 : link->link_duplex = RTE_ETH_LINK_FULL_DUPLEX;
2157 : 0 : link->link_status = !!(avp->flags & AVP_F_LINKUP);
2158 : :
2159 : 0 : return -1;
2160 : : }
2161 : :
2162 : : static int
2163 : 0 : avp_dev_promiscuous_enable(struct rte_eth_dev *eth_dev)
2164 : : {
2165 : 0 : struct avp_dev *avp = AVP_DEV_PRIVATE_TO_HW(eth_dev->data->dev_private);
2166 : :
2167 : 0 : rte_spinlock_lock(&avp->lock);
2168 [ # # ]: 0 : if ((avp->flags & AVP_F_PROMISC) == 0) {
2169 : 0 : avp->flags |= AVP_F_PROMISC;
2170 : 0 : PMD_DRV_LOG_LINE(DEBUG, "Promiscuous mode enabled on %u",
2171 : : eth_dev->data->port_id);
2172 : : }
2173 : : rte_spinlock_unlock(&avp->lock);
2174 : :
2175 : 0 : return 0;
2176 : : }
2177 : :
2178 : : static int
2179 : 0 : avp_dev_promiscuous_disable(struct rte_eth_dev *eth_dev)
2180 : : {
2181 : 0 : struct avp_dev *avp = AVP_DEV_PRIVATE_TO_HW(eth_dev->data->dev_private);
2182 : :
2183 : 0 : rte_spinlock_lock(&avp->lock);
2184 [ # # ]: 0 : if ((avp->flags & AVP_F_PROMISC) != 0) {
2185 : 0 : avp->flags &= ~AVP_F_PROMISC;
2186 : 0 : PMD_DRV_LOG_LINE(DEBUG, "Promiscuous mode disabled on %u",
2187 : : eth_dev->data->port_id);
2188 : : }
2189 : : rte_spinlock_unlock(&avp->lock);
2190 : :
2191 : 0 : return 0;
2192 : : }
2193 : :
2194 : : static int
2195 : 0 : avp_dev_info_get(struct rte_eth_dev *eth_dev,
2196 : : struct rte_eth_dev_info *dev_info)
2197 : : {
2198 : 0 : struct avp_dev *avp = AVP_DEV_PRIVATE_TO_HW(eth_dev->data->dev_private);
2199 : :
2200 : 0 : dev_info->max_rx_queues = avp->max_rx_queues;
2201 : 0 : dev_info->max_tx_queues = avp->max_tx_queues;
2202 : 0 : dev_info->min_rx_bufsize = AVP_MIN_RX_BUFSIZE;
2203 : 0 : dev_info->max_rx_pktlen = avp->max_rx_pkt_len;
2204 : 0 : dev_info->max_mac_addrs = AVP_MAX_MAC_ADDRS;
2205 [ # # ]: 0 : if (avp->host_features & RTE_AVP_FEATURE_VLAN_OFFLOAD) {
2206 : 0 : dev_info->rx_offload_capa = RTE_ETH_RX_OFFLOAD_VLAN_STRIP;
2207 : 0 : dev_info->tx_offload_capa = RTE_ETH_TX_OFFLOAD_VLAN_INSERT;
2208 : : }
2209 : :
2210 : 0 : return 0;
2211 : : }
2212 : :
2213 : : static int
2214 : 0 : avp_vlan_offload_set(struct rte_eth_dev *eth_dev, int mask)
2215 : : {
2216 : 0 : struct avp_dev *avp = AVP_DEV_PRIVATE_TO_HW(eth_dev->data->dev_private);
2217 : : struct rte_eth_conf *dev_conf = ð_dev->data->dev_conf;
2218 : 0 : uint64_t offloads = dev_conf->rxmode.offloads;
2219 : :
2220 [ # # ]: 0 : if (mask & RTE_ETH_VLAN_STRIP_MASK) {
2221 [ # # ]: 0 : if (avp->host_features & RTE_AVP_FEATURE_VLAN_OFFLOAD) {
2222 [ # # ]: 0 : if (offloads & RTE_ETH_RX_OFFLOAD_VLAN_STRIP)
2223 : 0 : avp->features |= RTE_AVP_FEATURE_VLAN_OFFLOAD;
2224 : : else
2225 : 0 : avp->features &= ~RTE_AVP_FEATURE_VLAN_OFFLOAD;
2226 : : } else {
2227 : 0 : PMD_DRV_LOG_LINE(ERR, "VLAN strip offload not supported");
2228 : : }
2229 : : }
2230 : :
2231 [ # # ]: 0 : if (mask & RTE_ETH_VLAN_FILTER_MASK) {
2232 [ # # ]: 0 : if (offloads & RTE_ETH_RX_OFFLOAD_VLAN_FILTER)
2233 : 0 : PMD_DRV_LOG_LINE(ERR, "VLAN filter offload not supported");
2234 : : }
2235 : :
2236 [ # # ]: 0 : if (mask & RTE_ETH_VLAN_EXTEND_MASK) {
2237 [ # # ]: 0 : if (offloads & RTE_ETH_RX_OFFLOAD_VLAN_EXTEND)
2238 : 0 : PMD_DRV_LOG_LINE(ERR, "VLAN extend offload not supported");
2239 : : }
2240 : :
2241 : 0 : return 0;
2242 : : }
2243 : :
2244 : : static int
2245 : 0 : avp_dev_stats_get(struct rte_eth_dev *eth_dev, struct rte_eth_stats *stats,
2246 : : struct eth_queue_stats *qstats)
2247 : : {
2248 : 0 : struct avp_dev *avp = AVP_DEV_PRIVATE_TO_HW(eth_dev->data->dev_private);
2249 : : unsigned int i;
2250 : :
2251 [ # # ]: 0 : for (i = 0; i < avp->num_rx_queues; i++) {
2252 : 0 : struct avp_queue *rxq = avp->dev_data->rx_queues[i];
2253 : :
2254 [ # # ]: 0 : if (rxq) {
2255 : 0 : stats->ipackets += rxq->packets;
2256 : 0 : stats->ibytes += rxq->bytes;
2257 : 0 : stats->ierrors += rxq->errors;
2258 : :
2259 [ # # ]: 0 : if (qstats != NULL && i < RTE_ETHDEV_QUEUE_STAT_CNTRS) {
2260 : 0 : qstats->q_ipackets[i] += rxq->packets;
2261 : 0 : qstats->q_ibytes[i] += rxq->bytes;
2262 : 0 : qstats->q_errors[i] += rxq->errors;
2263 : : }
2264 : : }
2265 : : }
2266 : :
2267 [ # # ]: 0 : for (i = 0; i < avp->num_tx_queues; i++) {
2268 : 0 : struct avp_queue *txq = avp->dev_data->tx_queues[i];
2269 : :
2270 [ # # ]: 0 : if (txq) {
2271 : 0 : stats->opackets += txq->packets;
2272 : 0 : stats->obytes += txq->bytes;
2273 : 0 : stats->oerrors += txq->errors;
2274 : :
2275 [ # # ]: 0 : if (qstats != NULL && i < RTE_ETHDEV_QUEUE_STAT_CNTRS) {
2276 : 0 : qstats->q_opackets[i] += txq->packets;
2277 : 0 : qstats->q_obytes[i] += txq->bytes;
2278 : : }
2279 : : }
2280 : : }
2281 : :
2282 : 0 : return 0;
2283 : : }
2284 : :
2285 : : static int
2286 : 0 : avp_dev_stats_reset(struct rte_eth_dev *eth_dev)
2287 : : {
2288 : 0 : struct avp_dev *avp = AVP_DEV_PRIVATE_TO_HW(eth_dev->data->dev_private);
2289 : : unsigned int i;
2290 : :
2291 [ # # ]: 0 : for (i = 0; i < avp->num_rx_queues; i++) {
2292 : 0 : struct avp_queue *rxq = avp->dev_data->rx_queues[i];
2293 : :
2294 [ # # ]: 0 : if (rxq) {
2295 : 0 : rxq->bytes = 0;
2296 : 0 : rxq->packets = 0;
2297 : 0 : rxq->errors = 0;
2298 : : }
2299 : : }
2300 : :
2301 [ # # ]: 0 : for (i = 0; i < avp->num_tx_queues; i++) {
2302 : 0 : struct avp_queue *txq = avp->dev_data->tx_queues[i];
2303 : :
2304 [ # # ]: 0 : if (txq) {
2305 : 0 : txq->bytes = 0;
2306 : 0 : txq->packets = 0;
2307 : 0 : txq->errors = 0;
2308 : : }
2309 : : }
2310 : :
2311 : 0 : return 0;
2312 : : }
2313 : :
2314 : 253 : RTE_PMD_REGISTER_PCI(net_avp, rte_avp_pmd);
2315 : : RTE_PMD_REGISTER_PCI_TABLE(net_avp, pci_id_avp_map);
2316 [ - + ]: 253 : RTE_LOG_REGISTER_SUFFIX(avp_logtype_driver, driver, NOTICE);
|