4 * Copyright (c) 2015-2019 Amazon.com, Inc. or its affiliates.
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
11 * 1. Redistributions of source code must retain the above copyright
12 * notice, this list of conditions and the following disclaimer.
14 * 2. Redistributions in binary form must reproduce the above copyright
15 * notice, this list of conditions and the following disclaimer in the
16 * documentation and/or other materials provided with the distribution.
18 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
19 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
20 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
21 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
22 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
23 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30 #include <sys/cdefs.h>
31 __FBSDID("$FreeBSD$");
33 #include <sys/param.h>
34 #include <sys/systm.h>
36 #include <sys/endian.h>
37 #include <sys/kernel.h>
38 #include <sys/kthread.h>
39 #include <sys/malloc.h>
41 #include <sys/module.h>
44 #include <sys/socket.h>
45 #include <sys/sockio.h>
46 #include <sys/sysctl.h>
47 #include <sys/taskqueue.h>
49 #include <sys/eventhandler.h>
51 #include <machine/bus.h>
52 #include <machine/resource.h>
53 #include <machine/in_cksum.h>
56 #include <net/ethernet.h>
58 #include <net/if_var.h>
59 #include <net/if_arp.h>
60 #include <net/if_dl.h>
61 #include <net/if_media.h>
62 #include <net/if_types.h>
63 #include <net/if_vlan_var.h>
65 #include <netinet/in_systm.h>
66 #include <netinet/in.h>
67 #include <netinet/if_ether.h>
68 #include <netinet/ip.h>
69 #include <netinet/ip6.h>
70 #include <netinet/tcp.h>
71 #include <netinet/udp.h>
73 #include <dev/pci/pcivar.h>
74 #include <dev/pci/pcireg.h>
79 #include "ena_datapath.h"
81 #include "ena_sysctl.h"
84 #include "ena_netmap.h"
85 #endif /* DEV_NETMAP */
87 /*********************************************************
89 *********************************************************/
90 static int ena_probe(device_t);
91 static void ena_intr_msix_mgmnt(void *);
92 static void ena_free_pci_resources(struct ena_adapter *);
93 static int ena_change_mtu(if_t, int);
94 static inline void ena_alloc_counters(counter_u64_t *, int);
95 static inline void ena_free_counters(counter_u64_t *, int);
96 static inline void ena_reset_counters(counter_u64_t *, int);
97 static void ena_init_io_rings_common(struct ena_adapter *,
98 struct ena_ring *, uint16_t);
99 static void ena_init_io_rings(struct ena_adapter *);
100 static void ena_free_io_ring_resources(struct ena_adapter *, unsigned int);
101 static void ena_free_all_io_rings_resources(struct ena_adapter *);
102 static int ena_setup_tx_dma_tag(struct ena_adapter *);
103 static int ena_free_tx_dma_tag(struct ena_adapter *);
104 static int ena_setup_rx_dma_tag(struct ena_adapter *);
105 static int ena_free_rx_dma_tag(struct ena_adapter *);
106 static void ena_release_all_tx_dmamap(struct ena_ring *);
107 static int ena_setup_tx_resources(struct ena_adapter *, int);
108 static void ena_free_tx_resources(struct ena_adapter *, int);
109 static int ena_setup_all_tx_resources(struct ena_adapter *);
110 static void ena_free_all_tx_resources(struct ena_adapter *);
111 static int ena_setup_rx_resources(struct ena_adapter *, unsigned int);
112 static void ena_free_rx_resources(struct ena_adapter *, unsigned int);
113 static int ena_setup_all_rx_resources(struct ena_adapter *);
114 static void ena_free_all_rx_resources(struct ena_adapter *);
115 static inline int ena_alloc_rx_mbuf(struct ena_adapter *, struct ena_ring *,
116 struct ena_rx_buffer *);
117 static void ena_free_rx_mbuf(struct ena_adapter *, struct ena_ring *,
118 struct ena_rx_buffer *);
119 static void ena_free_rx_bufs(struct ena_adapter *, unsigned int);
120 static void ena_refill_all_rx_bufs(struct ena_adapter *);
121 static void ena_free_all_rx_bufs(struct ena_adapter *);
122 static void ena_free_tx_bufs(struct ena_adapter *, unsigned int);
123 static void ena_free_all_tx_bufs(struct ena_adapter *);
124 static void ena_destroy_all_tx_queues(struct ena_adapter *);
125 static void ena_destroy_all_rx_queues(struct ena_adapter *);
126 static void ena_destroy_all_io_queues(struct ena_adapter *);
127 static int ena_create_io_queues(struct ena_adapter *);
128 static int ena_handle_msix(void *);
129 static int ena_enable_msix(struct ena_adapter *);
130 static void ena_setup_mgmnt_intr(struct ena_adapter *);
131 static int ena_setup_io_intr(struct ena_adapter *);
132 static int ena_request_mgmnt_irq(struct ena_adapter *);
133 static int ena_request_io_irq(struct ena_adapter *);
134 static void ena_free_mgmnt_irq(struct ena_adapter *);
135 static void ena_free_io_irq(struct ena_adapter *);
136 static void ena_free_irqs(struct ena_adapter*);
137 static void ena_disable_msix(struct ena_adapter *);
138 static void ena_unmask_all_io_irqs(struct ena_adapter *);
139 static int ena_rss_configure(struct ena_adapter *);
140 static int ena_up_complete(struct ena_adapter *);
141 static uint64_t ena_get_counter(if_t, ift_counter);
142 static int ena_media_change(if_t);
143 static void ena_media_status(if_t, struct ifmediareq *);
144 static void ena_init(void *);
145 static int ena_ioctl(if_t, u_long, caddr_t);
146 static int ena_get_dev_offloads(struct ena_com_dev_get_features_ctx *);
147 static void ena_update_host_info(struct ena_admin_host_info *, if_t);
148 static void ena_update_hwassist(struct ena_adapter *);
149 static int ena_setup_ifnet(device_t, struct ena_adapter *,
150 struct ena_com_dev_get_features_ctx *);
151 static int ena_enable_wc(struct resource *);
152 static int ena_set_queues_placement_policy(device_t, struct ena_com_dev *,
153 struct ena_admin_feature_llq_desc *, struct ena_llq_configurations *);
154 static int ena_calc_io_queue_num(struct ena_adapter *,
155 struct ena_com_dev_get_features_ctx *);
156 static int ena_calc_queue_size(struct ena_adapter *,
157 struct ena_calc_queue_size_ctx *);
158 static int ena_handle_updated_queues(struct ena_adapter *,
159 struct ena_com_dev_get_features_ctx *);
160 static int ena_rss_init_default(struct ena_adapter *);
161 static void ena_rss_init_default_deferred(void *);
162 static void ena_config_host_info(struct ena_com_dev *, device_t);
163 static int ena_attach(device_t);
164 static int ena_detach(device_t);
165 static int ena_device_init(struct ena_adapter *, device_t,
166 struct ena_com_dev_get_features_ctx *, int *);
167 static int ena_enable_msix_and_set_admin_interrupts(struct ena_adapter *,
169 static void ena_update_on_link_change(void *, struct ena_admin_aenq_entry *);
170 static void unimplemented_aenq_handler(void *,
171 struct ena_admin_aenq_entry *);
172 static void ena_timer_service(void *);
174 static char ena_version[] = DEVICE_NAME DRV_MODULE_NAME " v" DRV_MODULE_VERSION;
176 static ena_vendor_info_t ena_vendor_info_array[] = {
177 { PCI_VENDOR_ID_AMAZON, PCI_DEV_ID_ENA_PF, 0},
178 { PCI_VENDOR_ID_AMAZON, PCI_DEV_ID_ENA_LLQ_PF, 0},
179 { PCI_VENDOR_ID_AMAZON, PCI_DEV_ID_ENA_VF, 0},
180 { PCI_VENDOR_ID_AMAZON, PCI_DEV_ID_ENA_LLQ_VF, 0},
186 * Contains pointers to event handlers, e.g. link state chage.
188 static struct ena_aenq_handlers aenq_handlers;
191 ena_dmamap_callback(void *arg, bus_dma_segment_t *segs, int nseg, int error)
195 *(bus_addr_t *) arg = segs[0].ds_addr;
199 ena_dma_alloc(device_t dmadev, bus_size_t size,
200 ena_mem_handle_t *dma , int mapflags)
202 struct ena_adapter* adapter = device_get_softc(dmadev);
204 uint64_t dma_space_addr;
207 maxsize = ((size - 1) / PAGE_SIZE + 1) * PAGE_SIZE;
209 dma_space_addr = ENA_DMA_BIT_MASK(adapter->dma_width);
210 if (unlikely(dma_space_addr == 0))
211 dma_space_addr = BUS_SPACE_MAXADDR;
213 error = bus_dma_tag_create(bus_get_dma_tag(dmadev), /* parent */
214 8, 0, /* alignment, bounds */
215 dma_space_addr, /* lowaddr of exclusion window */
216 BUS_SPACE_MAXADDR,/* highaddr of exclusion window */
217 NULL, NULL, /* filter, filterarg */
218 maxsize, /* maxsize */
220 maxsize, /* maxsegsize */
221 BUS_DMA_ALLOCNOW, /* flags */
225 if (unlikely(error != 0)) {
226 ena_trace(ENA_ALERT, "bus_dma_tag_create failed: %d\n", error);
230 error = bus_dmamem_alloc(dma->tag, (void**) &dma->vaddr,
231 BUS_DMA_COHERENT | BUS_DMA_ZERO, &dma->map);
232 if (unlikely(error != 0)) {
233 ena_trace(ENA_ALERT, "bus_dmamem_alloc(%ju) failed: %d\n",
234 (uintmax_t)size, error);
235 goto fail_map_create;
239 error = bus_dmamap_load(dma->tag, dma->map, dma->vaddr,
240 size, ena_dmamap_callback, &dma->paddr, mapflags);
241 if (unlikely((error != 0) || (dma->paddr == 0))) {
242 ena_trace(ENA_ALERT, ": bus_dmamap_load failed: %d\n", error);
246 bus_dmamap_sync(dma->tag, dma->map,
247 BUS_DMASYNC_PREREAD | BUS_DMASYNC_PREWRITE);
252 bus_dmamem_free(dma->tag, dma->vaddr, dma->map);
254 bus_dma_tag_destroy(dma->tag);
264 ena_free_pci_resources(struct ena_adapter *adapter)
266 device_t pdev = adapter->pdev;
268 if (adapter->memory != NULL) {
269 bus_release_resource(pdev, SYS_RES_MEMORY,
270 PCIR_BAR(ENA_MEM_BAR), adapter->memory);
273 if (adapter->registers != NULL) {
274 bus_release_resource(pdev, SYS_RES_MEMORY,
275 PCIR_BAR(ENA_REG_BAR), adapter->registers);
280 ena_probe(device_t dev)
282 ena_vendor_info_t *ent;
283 char adapter_name[60];
284 uint16_t pci_vendor_id = 0;
285 uint16_t pci_device_id = 0;
287 pci_vendor_id = pci_get_vendor(dev);
288 pci_device_id = pci_get_device(dev);
290 ent = ena_vendor_info_array;
291 while (ent->vendor_id != 0) {
292 if ((pci_vendor_id == ent->vendor_id) &&
293 (pci_device_id == ent->device_id)) {
294 ena_trace(ENA_DBG, "vendor=%x device=%x\n",
295 pci_vendor_id, pci_device_id);
297 sprintf(adapter_name, DEVICE_DESC);
298 device_set_desc_copy(dev, adapter_name);
299 return (BUS_PROBE_DEFAULT);
310 ena_change_mtu(if_t ifp, int new_mtu)
312 struct ena_adapter *adapter = if_getsoftc(ifp);
315 if ((new_mtu > adapter->max_mtu) || (new_mtu < ENA_MIN_MTU)) {
316 device_printf(adapter->pdev, "Invalid MTU setting. "
317 "new_mtu: %d max mtu: %d min mtu: %d\n",
318 new_mtu, adapter->max_mtu, ENA_MIN_MTU);
322 rc = ena_com_set_dev_mtu(adapter->ena_dev, new_mtu);
323 if (likely(rc == 0)) {
324 ena_trace(ENA_DBG, "set MTU to %d\n", new_mtu);
325 if_setmtu(ifp, new_mtu);
327 device_printf(adapter->pdev, "Failed to set MTU to %d\n",
335 ena_alloc_counters(counter_u64_t *begin, int size)
337 counter_u64_t *end = (counter_u64_t *)((char *)begin + size);
339 for (; begin < end; ++begin)
340 *begin = counter_u64_alloc(M_WAITOK);
344 ena_free_counters(counter_u64_t *begin, int size)
346 counter_u64_t *end = (counter_u64_t *)((char *)begin + size);
348 for (; begin < end; ++begin)
349 counter_u64_free(*begin);
353 ena_reset_counters(counter_u64_t *begin, int size)
355 counter_u64_t *end = (counter_u64_t *)((char *)begin + size);
357 for (; begin < end; ++begin)
358 counter_u64_zero(*begin);
362 ena_init_io_rings_common(struct ena_adapter *adapter, struct ena_ring *ring,
367 ring->adapter = adapter;
368 ring->ena_dev = adapter->ena_dev;
369 ring->first_interrupt = false;
370 ring->no_interrupt_event_cnt = 0;
374 ena_init_io_rings(struct ena_adapter *adapter)
376 struct ena_com_dev *ena_dev;
377 struct ena_ring *txr, *rxr;
381 ena_dev = adapter->ena_dev;
383 for (i = 0; i < adapter->num_queues; i++) {
384 txr = &adapter->tx_ring[i];
385 rxr = &adapter->rx_ring[i];
387 /* TX/RX common ring state */
388 ena_init_io_rings_common(adapter, txr, i);
389 ena_init_io_rings_common(adapter, rxr, i);
391 /* TX specific ring state */
392 txr->ring_size = adapter->tx_ring_size;
393 txr->tx_max_header_size = ena_dev->tx_max_header_size;
394 txr->tx_mem_queue_type = ena_dev->tx_mem_queue_type;
395 txr->smoothed_interval =
396 ena_com_get_nonadaptive_moderation_interval_tx(ena_dev);
398 /* Allocate a buf ring */
399 txr->buf_ring_size = adapter->buf_ring_size;
400 txr->br = buf_ring_alloc(txr->buf_ring_size, M_DEVBUF,
401 M_WAITOK, &txr->ring_mtx);
403 /* Alloc TX statistics. */
404 ena_alloc_counters((counter_u64_t *)&txr->tx_stats,
405 sizeof(txr->tx_stats));
407 /* RX specific ring state */
408 rxr->ring_size = adapter->rx_ring_size;
409 rxr->smoothed_interval =
410 ena_com_get_nonadaptive_moderation_interval_rx(ena_dev);
412 /* Alloc RX statistics. */
413 ena_alloc_counters((counter_u64_t *)&rxr->rx_stats,
414 sizeof(rxr->rx_stats));
416 /* Initialize locks */
417 snprintf(txr->mtx_name, nitems(txr->mtx_name), "%s:tx(%d)",
418 device_get_nameunit(adapter->pdev), i);
419 snprintf(rxr->mtx_name, nitems(rxr->mtx_name), "%s:rx(%d)",
420 device_get_nameunit(adapter->pdev), i);
422 mtx_init(&txr->ring_mtx, txr->mtx_name, NULL, MTX_DEF);
424 que = &adapter->que[i];
425 que->adapter = adapter;
433 rxr->empty_rx_queue = 0;
438 ena_free_io_ring_resources(struct ena_adapter *adapter, unsigned int qid)
440 struct ena_ring *txr = &adapter->tx_ring[qid];
441 struct ena_ring *rxr = &adapter->rx_ring[qid];
443 ena_free_counters((counter_u64_t *)&txr->tx_stats,
444 sizeof(txr->tx_stats));
445 ena_free_counters((counter_u64_t *)&rxr->rx_stats,
446 sizeof(rxr->rx_stats));
448 ENA_RING_MTX_LOCK(txr);
449 drbr_free(txr->br, M_DEVBUF);
450 ENA_RING_MTX_UNLOCK(txr);
452 mtx_destroy(&txr->ring_mtx);
456 ena_free_all_io_rings_resources(struct ena_adapter *adapter)
460 for (i = 0; i < adapter->num_queues; i++)
461 ena_free_io_ring_resources(adapter, i);
466 ena_setup_tx_dma_tag(struct ena_adapter *adapter)
470 /* Create DMA tag for Tx buffers */
471 ret = bus_dma_tag_create(bus_get_dma_tag(adapter->pdev),
472 1, 0, /* alignment, bounds */
473 ENA_DMA_BIT_MASK(adapter->dma_width), /* lowaddr of excl window */
474 BUS_SPACE_MAXADDR, /* highaddr of excl window */
475 NULL, NULL, /* filter, filterarg */
476 ENA_TSO_MAXSIZE, /* maxsize */
477 adapter->max_tx_sgl_size - 1, /* nsegments */
478 ENA_TSO_MAXSIZE, /* maxsegsize */
481 NULL, /* lockfuncarg */
482 &adapter->tx_buf_tag);
488 ena_free_tx_dma_tag(struct ena_adapter *adapter)
492 ret = bus_dma_tag_destroy(adapter->tx_buf_tag);
494 if (likely(ret == 0))
495 adapter->tx_buf_tag = NULL;
501 ena_setup_rx_dma_tag(struct ena_adapter *adapter)
505 /* Create DMA tag for Rx buffers*/
506 ret = bus_dma_tag_create(bus_get_dma_tag(adapter->pdev), /* parent */
507 1, 0, /* alignment, bounds */
508 ENA_DMA_BIT_MASK(adapter->dma_width), /* lowaddr of excl window */
509 BUS_SPACE_MAXADDR, /* highaddr of excl window */
510 NULL, NULL, /* filter, filterarg */
511 MJUM16BYTES, /* maxsize */
512 adapter->max_rx_sgl_size, /* nsegments */
513 MJUM16BYTES, /* maxsegsize */
517 &adapter->rx_buf_tag);
523 ena_free_rx_dma_tag(struct ena_adapter *adapter)
527 ret = bus_dma_tag_destroy(adapter->rx_buf_tag);
529 if (likely(ret == 0))
530 adapter->rx_buf_tag = NULL;
536 ena_release_all_tx_dmamap(struct ena_ring *tx_ring)
538 struct ena_adapter *adapter = tx_ring->adapter;
539 struct ena_tx_buffer *tx_info;
540 bus_dma_tag_t tx_tag = adapter->tx_buf_tag;;
543 struct ena_netmap_tx_info *nm_info;
545 #endif /* DEV_NETMAP */
547 for (i = 0; i < tx_ring->ring_size; ++i) {
548 tx_info = &tx_ring->tx_buffer_info[i];
550 if (adapter->ifp->if_capenable & IFCAP_NETMAP) {
551 nm_info = &tx_info->nm_info;
552 for (j = 0; j < ENA_PKT_MAX_BUFS; ++j) {
553 if (nm_info->map_seg[j] != NULL) {
554 bus_dmamap_destroy(tx_tag,
555 nm_info->map_seg[j]);
556 nm_info->map_seg[j] = NULL;
560 #endif /* DEV_NETMAP */
561 if (tx_info->dmamap != NULL) {
562 bus_dmamap_destroy(tx_tag, tx_info->dmamap);
563 tx_info->dmamap = NULL;
569 * ena_setup_tx_resources - allocate Tx resources (Descriptors)
570 * @adapter: network interface device structure
573 * Returns 0 on success, otherwise on failure.
576 ena_setup_tx_resources(struct ena_adapter *adapter, int qid)
578 struct ena_que *que = &adapter->que[qid];
579 struct ena_ring *tx_ring = que->tx_ring;
585 ena_netmap_reset_tx_ring(adapter, qid);
586 #endif /* DEV_NETMAP */
588 size = sizeof(struct ena_tx_buffer) * tx_ring->ring_size;
590 tx_ring->tx_buffer_info = malloc(size, M_DEVBUF, M_NOWAIT | M_ZERO);
591 if (unlikely(tx_ring->tx_buffer_info == NULL))
594 size = sizeof(uint16_t) * tx_ring->ring_size;
595 tx_ring->free_tx_ids = malloc(size, M_DEVBUF, M_NOWAIT | M_ZERO);
596 if (unlikely(tx_ring->free_tx_ids == NULL))
597 goto err_buf_info_free;
599 size = tx_ring->tx_max_header_size;
600 tx_ring->push_buf_intermediate_buf = malloc(size, M_DEVBUF,
602 if (unlikely(tx_ring->push_buf_intermediate_buf == NULL))
603 goto err_tx_ids_free;
605 /* Req id stack for TX OOO completions */
606 for (i = 0; i < tx_ring->ring_size; i++)
607 tx_ring->free_tx_ids[i] = i;
609 /* Reset TX statistics. */
610 ena_reset_counters((counter_u64_t *)&tx_ring->tx_stats,
611 sizeof(tx_ring->tx_stats));
613 tx_ring->next_to_use = 0;
614 tx_ring->next_to_clean = 0;
615 tx_ring->acum_pkts = 0;
617 /* Make sure that drbr is empty */
618 ENA_RING_MTX_LOCK(tx_ring);
619 drbr_flush(adapter->ifp, tx_ring->br);
620 ENA_RING_MTX_UNLOCK(tx_ring);
622 /* ... and create the buffer DMA maps */
623 for (i = 0; i < tx_ring->ring_size; i++) {
624 err = bus_dmamap_create(adapter->tx_buf_tag, 0,
625 &tx_ring->tx_buffer_info[i].dmamap);
626 if (unlikely(err != 0)) {
628 "Unable to create Tx DMA map for buffer %d\n",
630 goto err_map_release;
634 if (adapter->ifp->if_capenable & IFCAP_NETMAP) {
635 map = tx_ring->tx_buffer_info[i].nm_info.map_seg;
636 for (j = 0; j < ENA_PKT_MAX_BUFS; j++) {
637 err = bus_dmamap_create(adapter->tx_buf_tag, 0,
639 if (unlikely(err != 0)) {
640 ena_trace(ENA_ALERT, "Unable to create "
641 "Tx DMA for buffer %d %d\n", i, j);
642 goto err_map_release;
646 #endif /* DEV_NETMAP */
649 /* Allocate taskqueues */
650 TASK_INIT(&tx_ring->enqueue_task, 0, ena_deferred_mq_start, tx_ring);
651 tx_ring->enqueue_tq = taskqueue_create_fast("ena_tx_enque", M_NOWAIT,
652 taskqueue_thread_enqueue, &tx_ring->enqueue_tq);
653 if (unlikely(tx_ring->enqueue_tq == NULL)) {
655 "Unable to create taskqueue for enqueue task\n");
656 i = tx_ring->ring_size;
657 goto err_map_release;
660 tx_ring->running = true;
662 taskqueue_start_threads(&tx_ring->enqueue_tq, 1, PI_NET,
663 "%s txeq %d", device_get_nameunit(adapter->pdev), que->cpu);
668 ena_release_all_tx_dmamap(tx_ring);
670 free(tx_ring->free_tx_ids, M_DEVBUF);
671 tx_ring->free_tx_ids = NULL;
673 free(tx_ring->tx_buffer_info, M_DEVBUF);
674 tx_ring->tx_buffer_info = NULL;
680 * ena_free_tx_resources - Free Tx Resources per Queue
681 * @adapter: network interface device structure
684 * Free all transmit software resources
687 ena_free_tx_resources(struct ena_adapter *adapter, int qid)
689 struct ena_ring *tx_ring = &adapter->tx_ring[qid];
691 struct ena_netmap_tx_info *nm_info;
693 #endif /* DEV_NETMAP */
695 while (taskqueue_cancel(tx_ring->enqueue_tq, &tx_ring->enqueue_task,
697 taskqueue_drain(tx_ring->enqueue_tq, &tx_ring->enqueue_task);
699 taskqueue_free(tx_ring->enqueue_tq);
701 ENA_RING_MTX_LOCK(tx_ring);
702 /* Flush buffer ring, */
703 drbr_flush(adapter->ifp, tx_ring->br);
705 /* Free buffer DMA maps, */
706 for (int i = 0; i < tx_ring->ring_size; i++) {
707 bus_dmamap_sync(adapter->tx_buf_tag,
708 tx_ring->tx_buffer_info[i].dmamap, BUS_DMASYNC_POSTWRITE);
709 bus_dmamap_unload(adapter->tx_buf_tag,
710 tx_ring->tx_buffer_info[i].dmamap);
711 bus_dmamap_destroy(adapter->tx_buf_tag,
712 tx_ring->tx_buffer_info[i].dmamap);
715 if (adapter->ifp->if_capenable & IFCAP_NETMAP) {
716 nm_info = &tx_ring->tx_buffer_info[i].nm_info;
717 for (j = 0; j < ENA_PKT_MAX_BUFS; j++) {
718 if (nm_info->socket_buf_idx[j] != 0) {
719 bus_dmamap_sync(adapter->tx_buf_tag,
721 BUS_DMASYNC_POSTWRITE);
722 ena_netmap_unload(adapter,
723 nm_info->map_seg[j]);
725 bus_dmamap_destroy(adapter->tx_buf_tag,
726 nm_info->map_seg[j]);
727 nm_info->socket_buf_idx[j] = 0;
730 #endif /* DEV_NETMAP */
732 m_freem(tx_ring->tx_buffer_info[i].mbuf);
733 tx_ring->tx_buffer_info[i].mbuf = NULL;
735 ENA_RING_MTX_UNLOCK(tx_ring);
737 /* And free allocated memory. */
738 free(tx_ring->tx_buffer_info, M_DEVBUF);
739 tx_ring->tx_buffer_info = NULL;
741 free(tx_ring->free_tx_ids, M_DEVBUF);
742 tx_ring->free_tx_ids = NULL;
744 ENA_MEM_FREE(adapter->ena_dev->dmadev,
745 tx_ring->push_buf_intermediate_buf);
746 tx_ring->push_buf_intermediate_buf = NULL;
750 * ena_setup_all_tx_resources - allocate all queues Tx resources
751 * @adapter: network interface device structure
753 * Returns 0 on success, otherwise on failure.
756 ena_setup_all_tx_resources(struct ena_adapter *adapter)
760 for (i = 0; i < adapter->num_queues; i++) {
761 rc = ena_setup_tx_resources(adapter, i);
763 device_printf(adapter->pdev,
764 "Allocation for Tx Queue %u failed\n", i);
772 /* Rewind the index freeing the rings as we go */
774 ena_free_tx_resources(adapter, i);
779 * ena_free_all_tx_resources - Free Tx Resources for All Queues
780 * @adapter: network interface device structure
782 * Free all transmit software resources
785 ena_free_all_tx_resources(struct ena_adapter *adapter)
789 for (i = 0; i < adapter->num_queues; i++)
790 ena_free_tx_resources(adapter, i);
794 * ena_setup_rx_resources - allocate Rx resources (Descriptors)
795 * @adapter: network interface device structure
798 * Returns 0 on success, otherwise on failure.
801 ena_setup_rx_resources(struct ena_adapter *adapter, unsigned int qid)
803 struct ena_que *que = &adapter->que[qid];
804 struct ena_ring *rx_ring = que->rx_ring;
807 size = sizeof(struct ena_rx_buffer) * rx_ring->ring_size;
810 ena_netmap_reset_rx_ring(adapter, qid);
811 rx_ring->initialized = false;
812 #endif /* DEV_NETMAP */
815 * Alloc extra element so in rx path
816 * we can always prefetch rx_info + 1
818 size += sizeof(struct ena_rx_buffer);
820 rx_ring->rx_buffer_info = malloc(size, M_DEVBUF, M_WAITOK | M_ZERO);
822 size = sizeof(uint16_t) * rx_ring->ring_size;
823 rx_ring->free_rx_ids = malloc(size, M_DEVBUF, M_WAITOK);
825 for (i = 0; i < rx_ring->ring_size; i++)
826 rx_ring->free_rx_ids[i] = i;
828 /* Reset RX statistics. */
829 ena_reset_counters((counter_u64_t *)&rx_ring->rx_stats,
830 sizeof(rx_ring->rx_stats));
832 rx_ring->next_to_clean = 0;
833 rx_ring->next_to_use = 0;
835 /* ... and create the buffer DMA maps */
836 for (i = 0; i < rx_ring->ring_size; i++) {
837 err = bus_dmamap_create(adapter->rx_buf_tag, 0,
838 &(rx_ring->rx_buffer_info[i].map));
841 "Unable to create Rx DMA map for buffer %d\n", i);
842 goto err_buf_info_unmap;
846 /* Create LRO for the ring */
847 if ((adapter->ifp->if_capenable & IFCAP_LRO) != 0) {
848 int err = tcp_lro_init(&rx_ring->lro);
850 device_printf(adapter->pdev,
851 "LRO[%d] Initialization failed!\n", qid);
854 "RX Soft LRO[%d] Initialized\n", qid);
855 rx_ring->lro.ifp = adapter->ifp;
863 bus_dmamap_destroy(adapter->rx_buf_tag,
864 rx_ring->rx_buffer_info[i].map);
867 free(rx_ring->free_rx_ids, M_DEVBUF);
868 rx_ring->free_rx_ids = NULL;
869 free(rx_ring->rx_buffer_info, M_DEVBUF);
870 rx_ring->rx_buffer_info = NULL;
875 * ena_free_rx_resources - Free Rx Resources
876 * @adapter: network interface device structure
879 * Free all receive software resources
882 ena_free_rx_resources(struct ena_adapter *adapter, unsigned int qid)
884 struct ena_ring *rx_ring = &adapter->rx_ring[qid];
886 /* Free buffer DMA maps, */
887 for (int i = 0; i < rx_ring->ring_size; i++) {
888 bus_dmamap_sync(adapter->rx_buf_tag,
889 rx_ring->rx_buffer_info[i].map, BUS_DMASYNC_POSTREAD);
890 m_freem(rx_ring->rx_buffer_info[i].mbuf);
891 rx_ring->rx_buffer_info[i].mbuf = NULL;
892 bus_dmamap_unload(adapter->rx_buf_tag,
893 rx_ring->rx_buffer_info[i].map);
894 bus_dmamap_destroy(adapter->rx_buf_tag,
895 rx_ring->rx_buffer_info[i].map);
898 /* free LRO resources, */
899 tcp_lro_free(&rx_ring->lro);
901 /* free allocated memory */
902 free(rx_ring->rx_buffer_info, M_DEVBUF);
903 rx_ring->rx_buffer_info = NULL;
905 free(rx_ring->free_rx_ids, M_DEVBUF);
906 rx_ring->free_rx_ids = NULL;
910 * ena_setup_all_rx_resources - allocate all queues Rx resources
911 * @adapter: network interface device structure
913 * Returns 0 on success, otherwise on failure.
916 ena_setup_all_rx_resources(struct ena_adapter *adapter)
920 for (i = 0; i < adapter->num_queues; i++) {
921 rc = ena_setup_rx_resources(adapter, i);
923 device_printf(adapter->pdev,
924 "Allocation for Rx Queue %u failed\n", i);
931 /* rewind the index freeing the rings as we go */
933 ena_free_rx_resources(adapter, i);
938 * ena_free_all_rx_resources - Free Rx resources for all queues
939 * @adapter: network interface device structure
941 * Free all receive software resources
944 ena_free_all_rx_resources(struct ena_adapter *adapter)
948 for (i = 0; i < adapter->num_queues; i++)
949 ena_free_rx_resources(adapter, i);
953 ena_alloc_rx_mbuf(struct ena_adapter *adapter,
954 struct ena_ring *rx_ring, struct ena_rx_buffer *rx_info)
956 struct ena_com_buf *ena_buf;
957 bus_dma_segment_t segs[1];
961 /* if previous allocated frag is not used */
962 if (unlikely(rx_info->mbuf != NULL))
965 /* Get mbuf using UMA allocator */
966 rx_info->mbuf = m_getjcl(M_NOWAIT, MT_DATA, M_PKTHDR, MJUM16BYTES);
968 if (unlikely(rx_info->mbuf == NULL)) {
969 counter_u64_add(rx_ring->rx_stats.mjum_alloc_fail, 1);
970 rx_info->mbuf = m_getcl(M_NOWAIT, MT_DATA, M_PKTHDR);
971 if (unlikely(rx_info->mbuf == NULL)) {
972 counter_u64_add(rx_ring->rx_stats.mbuf_alloc_fail, 1);
980 rx_info->mbuf->m_pkthdr.len = rx_info->mbuf->m_len = mlen;
982 /* Map packets for DMA */
983 ena_trace(ENA_DBG | ENA_RSC | ENA_RXPTH,
984 "Using tag %p for buffers' DMA mapping, mbuf %p len: %d\n",
985 adapter->rx_buf_tag,rx_info->mbuf, rx_info->mbuf->m_len);
986 error = bus_dmamap_load_mbuf_sg(adapter->rx_buf_tag, rx_info->map,
987 rx_info->mbuf, segs, &nsegs, BUS_DMA_NOWAIT);
988 if (unlikely((error != 0) || (nsegs != 1))) {
989 ena_trace(ENA_WARNING, "failed to map mbuf, error: %d, "
990 "nsegs: %d\n", error, nsegs);
991 counter_u64_add(rx_ring->rx_stats.dma_mapping_err, 1);
996 bus_dmamap_sync(adapter->rx_buf_tag, rx_info->map, BUS_DMASYNC_PREREAD);
998 ena_buf = &rx_info->ena_buf;
999 ena_buf->paddr = segs[0].ds_addr;
1000 ena_buf->len = mlen;
1002 ena_trace(ENA_DBG | ENA_RSC | ENA_RXPTH,
1003 "ALLOC RX BUF: mbuf %p, rx_info %p, len %d, paddr %#jx\n",
1004 rx_info->mbuf, rx_info,ena_buf->len, (uintmax_t)ena_buf->paddr);
1009 m_freem(rx_info->mbuf);
1010 rx_info->mbuf = NULL;
1015 ena_free_rx_mbuf(struct ena_adapter *adapter, struct ena_ring *rx_ring,
1016 struct ena_rx_buffer *rx_info)
1019 if (rx_info->mbuf == NULL) {
1020 ena_trace(ENA_WARNING, "Trying to free unallocated buffer\n");
1024 bus_dmamap_sync(adapter->rx_buf_tag, rx_info->map,
1025 BUS_DMASYNC_POSTREAD);
1026 bus_dmamap_unload(adapter->rx_buf_tag, rx_info->map);
1027 m_freem(rx_info->mbuf);
1028 rx_info->mbuf = NULL;
1032 * ena_refill_rx_bufs - Refills ring with descriptors
1033 * @rx_ring: the ring which we want to feed with free descriptors
1034 * @num: number of descriptors to refill
1035 * Refills the ring with newly allocated DMA-mapped mbufs for receiving
1038 ena_refill_rx_bufs(struct ena_ring *rx_ring, uint32_t num)
1040 struct ena_adapter *adapter = rx_ring->adapter;
1041 uint16_t next_to_use, req_id;
1045 ena_trace(ENA_DBG | ENA_RXPTH | ENA_RSC, "refill qid: %d\n",
1048 next_to_use = rx_ring->next_to_use;
1050 for (i = 0; i < num; i++) {
1051 struct ena_rx_buffer *rx_info;
1053 ena_trace(ENA_DBG | ENA_RXPTH | ENA_RSC,
1054 "RX buffer - next to use: %d\n", next_to_use);
1056 req_id = rx_ring->free_rx_ids[next_to_use];
1057 rx_info = &rx_ring->rx_buffer_info[req_id];
1059 if (ena_rx_ring_in_netmap(adapter, rx_ring->qid))
1060 rc = ena_netmap_alloc_rx_slot(adapter, rx_ring, rx_info);
1062 #endif /* DEV_NETMAP */
1063 rc = ena_alloc_rx_mbuf(adapter, rx_ring, rx_info);
1064 if (unlikely(rc != 0)) {
1065 ena_trace(ENA_WARNING,
1066 "failed to alloc buffer for rx queue %d\n",
1070 rc = ena_com_add_single_rx_desc(rx_ring->ena_com_io_sq,
1071 &rx_info->ena_buf, req_id);
1072 if (unlikely(rc != 0)) {
1073 ena_trace(ENA_WARNING,
1074 "failed to add buffer for rx queue %d\n",
1078 next_to_use = ENA_RX_RING_IDX_NEXT(next_to_use,
1079 rx_ring->ring_size);
1082 if (unlikely(i < num)) {
1083 counter_u64_add(rx_ring->rx_stats.refil_partial, 1);
1084 ena_trace(ENA_WARNING,
1085 "refilled rx qid %d with only %d mbufs (from %d)\n",
1086 rx_ring->qid, i, num);
1089 if (likely(i != 0)) {
1091 ena_com_write_sq_doorbell(rx_ring->ena_com_io_sq);
1093 rx_ring->next_to_use = next_to_use;
1098 ena_free_rx_bufs(struct ena_adapter *adapter, unsigned int qid)
1100 struct ena_ring *rx_ring = &adapter->rx_ring[qid];
1103 for (i = 0; i < rx_ring->ring_size; i++) {
1104 struct ena_rx_buffer *rx_info = &rx_ring->rx_buffer_info[i];
1106 if (rx_info->mbuf != NULL)
1107 ena_free_rx_mbuf(adapter, rx_ring, rx_info);
1109 if (((if_getflags(adapter->ifp) & IFF_DYING) == 0) &&
1110 (adapter->ifp->if_capenable & IFCAP_NETMAP)) {
1111 if (rx_info->netmap_buf_idx != 0)
1112 ena_netmap_free_rx_slot(adapter, rx_ring,
1115 #endif /* DEV_NETMAP */
1120 * ena_refill_all_rx_bufs - allocate all queues Rx buffers
1121 * @adapter: network interface device structure
1125 ena_refill_all_rx_bufs(struct ena_adapter *adapter)
1127 struct ena_ring *rx_ring;
1128 int i, rc, bufs_num;
1130 for (i = 0; i < adapter->num_queues; i++) {
1131 rx_ring = &adapter->rx_ring[i];
1132 bufs_num = rx_ring->ring_size - 1;
1133 rc = ena_refill_rx_bufs(rx_ring, bufs_num);
1134 if (unlikely(rc != bufs_num))
1135 ena_trace(ENA_WARNING, "refilling Queue %d failed. "
1136 "Allocated %d buffers from: %d\n", i, rc, bufs_num);
1138 rx_ring->initialized = true;
1139 #endif /* DEV_NETMAP */
1144 ena_free_all_rx_bufs(struct ena_adapter *adapter)
1148 for (i = 0; i < adapter->num_queues; i++)
1149 ena_free_rx_bufs(adapter, i);
1153 * ena_free_tx_bufs - Free Tx Buffers per Queue
1154 * @adapter: network interface device structure
1158 ena_free_tx_bufs(struct ena_adapter *adapter, unsigned int qid)
1160 bool print_once = true;
1161 struct ena_ring *tx_ring = &adapter->tx_ring[qid];
1163 ENA_RING_MTX_LOCK(tx_ring);
1164 for (int i = 0; i < tx_ring->ring_size; i++) {
1165 struct ena_tx_buffer *tx_info = &tx_ring->tx_buffer_info[i];
1167 if (tx_info->mbuf == NULL)
1171 device_printf(adapter->pdev,
1172 "free uncompleted tx mbuf qid %d idx 0x%x\n",
1177 "free uncompleted tx mbuf qid %d idx 0x%x\n",
1181 bus_dmamap_sync(adapter->tx_buf_tag, tx_info->dmamap,
1182 BUS_DMASYNC_POSTWRITE);
1183 bus_dmamap_unload(adapter->tx_buf_tag, tx_info->dmamap);
1185 m_free(tx_info->mbuf);
1186 tx_info->mbuf = NULL;
1188 ENA_RING_MTX_UNLOCK(tx_ring);
1192 ena_free_all_tx_bufs(struct ena_adapter *adapter)
1195 for (int i = 0; i < adapter->num_queues; i++)
1196 ena_free_tx_bufs(adapter, i);
1200 ena_destroy_all_tx_queues(struct ena_adapter *adapter)
1205 for (i = 0; i < adapter->num_queues; i++) {
1206 ena_qid = ENA_IO_TXQ_IDX(i);
1207 ena_com_destroy_io_queue(adapter->ena_dev, ena_qid);
1212 ena_destroy_all_rx_queues(struct ena_adapter *adapter)
1217 for (i = 0; i < adapter->num_queues; i++) {
1218 ena_qid = ENA_IO_RXQ_IDX(i);
1219 ena_com_destroy_io_queue(adapter->ena_dev, ena_qid);
1224 ena_destroy_all_io_queues(struct ena_adapter *adapter)
1226 struct ena_que *queue;
1229 for (i = 0; i < adapter->num_queues; i++) {
1230 queue = &adapter->que[i];
1231 while (taskqueue_cancel(queue->cleanup_tq,
1232 &queue->cleanup_task, NULL))
1233 taskqueue_drain(queue->cleanup_tq,
1234 &queue->cleanup_task);
1235 taskqueue_free(queue->cleanup_tq);
1238 ena_destroy_all_tx_queues(adapter);
1239 ena_destroy_all_rx_queues(adapter);
1243 ena_create_io_queues(struct ena_adapter *adapter)
1245 struct ena_com_dev *ena_dev = adapter->ena_dev;
1246 struct ena_com_create_io_ctx ctx;
1247 struct ena_ring *ring;
1248 struct ena_que *queue;
1250 uint32_t msix_vector;
1253 /* Create TX queues */
1254 for (i = 0; i < adapter->num_queues; i++) {
1255 msix_vector = ENA_IO_IRQ_IDX(i);
1256 ena_qid = ENA_IO_TXQ_IDX(i);
1257 ctx.mem_queue_type = ena_dev->tx_mem_queue_type;
1258 ctx.direction = ENA_COM_IO_QUEUE_DIRECTION_TX;
1259 ctx.queue_size = adapter->tx_ring_size;
1260 ctx.msix_vector = msix_vector;
1262 rc = ena_com_create_io_queue(ena_dev, &ctx);
1264 device_printf(adapter->pdev,
1265 "Failed to create io TX queue #%d rc: %d\n", i, rc);
1268 ring = &adapter->tx_ring[i];
1269 rc = ena_com_get_io_handlers(ena_dev, ena_qid,
1270 &ring->ena_com_io_sq,
1271 &ring->ena_com_io_cq);
1273 device_printf(adapter->pdev,
1274 "Failed to get TX queue handlers. TX queue num"
1275 " %d rc: %d\n", i, rc);
1276 ena_com_destroy_io_queue(ena_dev, ena_qid);
1281 /* Create RX queues */
1282 for (i = 0; i < adapter->num_queues; i++) {
1283 msix_vector = ENA_IO_IRQ_IDX(i);
1284 ena_qid = ENA_IO_RXQ_IDX(i);
1285 ctx.mem_queue_type = ENA_ADMIN_PLACEMENT_POLICY_HOST;
1286 ctx.direction = ENA_COM_IO_QUEUE_DIRECTION_RX;
1287 ctx.queue_size = adapter->rx_ring_size;
1288 ctx.msix_vector = msix_vector;
1290 rc = ena_com_create_io_queue(ena_dev, &ctx);
1291 if (unlikely(rc != 0)) {
1292 device_printf(adapter->pdev,
1293 "Failed to create io RX queue[%d] rc: %d\n", i, rc);
1297 ring = &adapter->rx_ring[i];
1298 rc = ena_com_get_io_handlers(ena_dev, ena_qid,
1299 &ring->ena_com_io_sq,
1300 &ring->ena_com_io_cq);
1301 if (unlikely(rc != 0)) {
1302 device_printf(adapter->pdev,
1303 "Failed to get RX queue handlers. RX queue num"
1304 " %d rc: %d\n", i, rc);
1305 ena_com_destroy_io_queue(ena_dev, ena_qid);
1310 for (i = 0; i < adapter->num_queues; i++) {
1311 queue = &adapter->que[i];
1313 NET_TASK_INIT(&queue->cleanup_task, 0, ena_cleanup, queue);
1314 queue->cleanup_tq = taskqueue_create_fast("ena cleanup",
1315 M_WAITOK, taskqueue_thread_enqueue, &queue->cleanup_tq);
1317 taskqueue_start_threads(&queue->cleanup_tq, 1, PI_NET,
1318 "%s queue %d cleanup",
1319 device_get_nameunit(adapter->pdev), i);
1326 ena_com_destroy_io_queue(ena_dev, ENA_IO_RXQ_IDX(i));
1327 i = adapter->num_queues;
1330 ena_com_destroy_io_queue(ena_dev, ENA_IO_TXQ_IDX(i));
1335 /*********************************************************************
1337 * MSIX & Interrupt Service routine
1339 **********************************************************************/
1342 * ena_handle_msix - MSIX Interrupt Handler for admin/async queue
1343 * @arg: interrupt number
1346 ena_intr_msix_mgmnt(void *arg)
1348 struct ena_adapter *adapter = (struct ena_adapter *)arg;
1350 ena_com_admin_q_comp_intr_handler(adapter->ena_dev);
1351 if (likely(ENA_FLAG_ISSET(ENA_FLAG_DEVICE_RUNNING, adapter)))
1352 ena_com_aenq_intr_handler(adapter->ena_dev, arg);
1356 * ena_handle_msix - MSIX Interrupt Handler for Tx/Rx
1360 ena_handle_msix(void *arg)
1362 struct ena_que *queue = arg;
1363 struct ena_adapter *adapter = queue->adapter;
1364 if_t ifp = adapter->ifp;
1366 if (unlikely((if_getdrvflags(ifp) & IFF_DRV_RUNNING) == 0))
1367 return (FILTER_STRAY);
1369 taskqueue_enqueue(queue->cleanup_tq, &queue->cleanup_task);
1371 return (FILTER_HANDLED);
1375 ena_enable_msix(struct ena_adapter *adapter)
1377 device_t dev = adapter->pdev;
1378 int msix_vecs, msix_req;
1381 if (ENA_FLAG_ISSET(ENA_FLAG_MSIX_ENABLED, adapter)) {
1382 device_printf(dev, "Error, MSI-X is already enabled\n");
1386 /* Reserved the max msix vectors we might need */
1387 msix_vecs = ENA_MAX_MSIX_VEC(adapter->num_queues);
1389 adapter->msix_entries = malloc(msix_vecs * sizeof(struct msix_entry),
1390 M_DEVBUF, M_WAITOK | M_ZERO);
1392 ena_trace(ENA_DBG, "trying to enable MSI-X, vectors: %d\n", msix_vecs);
1394 for (i = 0; i < msix_vecs; i++) {
1395 adapter->msix_entries[i].entry = i;
1396 /* Vectors must start from 1 */
1397 adapter->msix_entries[i].vector = i + 1;
1400 msix_req = msix_vecs;
1401 rc = pci_alloc_msix(dev, &msix_vecs);
1402 if (unlikely(rc != 0)) {
1404 "Failed to enable MSIX, vectors %d rc %d\n", msix_vecs, rc);
1410 if (msix_vecs != msix_req) {
1411 if (msix_vecs == ENA_ADMIN_MSIX_VEC) {
1413 "Not enough number of MSI-x allocated: %d\n",
1415 pci_release_msi(dev);
1419 device_printf(dev, "Enable only %d MSI-x (out of %d), reduce "
1420 "the number of queues\n", msix_vecs, msix_req);
1421 adapter->num_queues = msix_vecs - ENA_ADMIN_MSIX_VEC;
1424 adapter->msix_vecs = msix_vecs;
1425 ENA_FLAG_SET_ATOMIC(ENA_FLAG_MSIX_ENABLED, adapter);
1430 free(adapter->msix_entries, M_DEVBUF);
1431 adapter->msix_entries = NULL;
1437 ena_setup_mgmnt_intr(struct ena_adapter *adapter)
1440 snprintf(adapter->irq_tbl[ENA_MGMNT_IRQ_IDX].name,
1441 ENA_IRQNAME_SIZE, "ena-mgmnt@pci:%s",
1442 device_get_nameunit(adapter->pdev));
1444 * Handler is NULL on purpose, it will be set
1445 * when mgmnt interrupt is acquired
1447 adapter->irq_tbl[ENA_MGMNT_IRQ_IDX].handler = NULL;
1448 adapter->irq_tbl[ENA_MGMNT_IRQ_IDX].data = adapter;
1449 adapter->irq_tbl[ENA_MGMNT_IRQ_IDX].vector =
1450 adapter->msix_entries[ENA_MGMNT_IRQ_IDX].vector;
1454 ena_setup_io_intr(struct ena_adapter *adapter)
1456 static int last_bind_cpu = -1;
1459 if (adapter->msix_entries == NULL)
1462 for (int i = 0; i < adapter->num_queues; i++) {
1463 irq_idx = ENA_IO_IRQ_IDX(i);
1465 snprintf(adapter->irq_tbl[irq_idx].name, ENA_IRQNAME_SIZE,
1466 "%s-TxRx-%d", device_get_nameunit(adapter->pdev), i);
1467 adapter->irq_tbl[irq_idx].handler = ena_handle_msix;
1468 adapter->irq_tbl[irq_idx].data = &adapter->que[i];
1469 adapter->irq_tbl[irq_idx].vector =
1470 adapter->msix_entries[irq_idx].vector;
1471 ena_trace(ENA_INFO | ENA_IOQ, "ena_setup_io_intr vector: %d\n",
1472 adapter->msix_entries[irq_idx].vector);
1475 * We want to bind rings to the corresponding cpu
1476 * using something similar to the RSS round-robin technique.
1478 if (unlikely(last_bind_cpu < 0))
1479 last_bind_cpu = CPU_FIRST();
1480 adapter->que[i].cpu = adapter->irq_tbl[irq_idx].cpu =
1482 last_bind_cpu = CPU_NEXT(last_bind_cpu);
1489 ena_request_mgmnt_irq(struct ena_adapter *adapter)
1491 struct ena_irq *irq;
1492 unsigned long flags;
1495 flags = RF_ACTIVE | RF_SHAREABLE;
1497 irq = &adapter->irq_tbl[ENA_MGMNT_IRQ_IDX];
1498 irq->res = bus_alloc_resource_any(adapter->pdev, SYS_RES_IRQ,
1499 &irq->vector, flags);
1501 if (unlikely(irq->res == NULL)) {
1502 device_printf(adapter->pdev, "could not allocate "
1503 "irq vector: %d\n", irq->vector);
1507 rc = bus_setup_intr(adapter->pdev, irq->res,
1508 INTR_TYPE_NET | INTR_MPSAFE, NULL, ena_intr_msix_mgmnt,
1509 irq->data, &irq->cookie);
1510 if (unlikely(rc != 0)) {
1511 device_printf(adapter->pdev, "failed to register "
1512 "interrupt handler for irq %ju: %d\n",
1513 rman_get_start(irq->res), rc);
1516 irq->requested = true;
1521 ena_trace(ENA_INFO | ENA_ADMQ, "releasing resource for irq %d\n",
1523 rcc = bus_release_resource(adapter->pdev, SYS_RES_IRQ,
1524 irq->vector, irq->res);
1525 if (unlikely(rcc != 0))
1526 device_printf(adapter->pdev, "dev has no parent while "
1527 "releasing res for irq: %d\n", irq->vector);
1534 ena_request_io_irq(struct ena_adapter *adapter)
1536 struct ena_irq *irq;
1537 unsigned long flags = 0;
1540 if (unlikely(!ENA_FLAG_ISSET(ENA_FLAG_MSIX_ENABLED, adapter))) {
1541 device_printf(adapter->pdev,
1542 "failed to request I/O IRQ: MSI-X is not enabled\n");
1545 flags = RF_ACTIVE | RF_SHAREABLE;
1548 for (i = ENA_IO_IRQ_FIRST_IDX; i < adapter->msix_vecs; i++) {
1549 irq = &adapter->irq_tbl[i];
1551 if (unlikely(irq->requested))
1554 irq->res = bus_alloc_resource_any(adapter->pdev, SYS_RES_IRQ,
1555 &irq->vector, flags);
1556 if (unlikely(irq->res == NULL)) {
1558 device_printf(adapter->pdev, "could not allocate "
1559 "irq vector: %d\n", irq->vector);
1563 rc = bus_setup_intr(adapter->pdev, irq->res,
1564 INTR_TYPE_NET | INTR_MPSAFE, irq->handler, NULL,
1565 irq->data, &irq->cookie);
1566 if (unlikely(rc != 0)) {
1567 device_printf(adapter->pdev, "failed to register "
1568 "interrupt handler for irq %ju: %d\n",
1569 rman_get_start(irq->res), rc);
1572 irq->requested = true;
1574 ena_trace(ENA_INFO, "queue %d - cpu %d\n",
1575 i - ENA_IO_IRQ_FIRST_IDX, irq->cpu);
1582 for (; i >= ENA_IO_IRQ_FIRST_IDX; i--) {
1583 irq = &adapter->irq_tbl[i];
1586 /* Once we entered err: section and irq->requested is true we
1587 free both intr and resources */
1589 rcc = bus_teardown_intr(adapter->pdev, irq->res, irq->cookie);
1590 if (unlikely(rcc != 0))
1591 device_printf(adapter->pdev, "could not release"
1592 " irq: %d, error: %d\n", irq->vector, rcc);
1594 /* If we entred err: section without irq->requested set we know
1595 it was bus_alloc_resource_any() that needs cleanup, provided
1596 res is not NULL. In case res is NULL no work in needed in
1599 if (irq->res != NULL) {
1600 rcc = bus_release_resource(adapter->pdev, SYS_RES_IRQ,
1601 irq->vector, irq->res);
1603 if (unlikely(rcc != 0))
1604 device_printf(adapter->pdev, "dev has no parent while "
1605 "releasing res for irq: %d\n", irq->vector);
1606 irq->requested = false;
1614 ena_free_mgmnt_irq(struct ena_adapter *adapter)
1616 struct ena_irq *irq;
1619 irq = &adapter->irq_tbl[ENA_MGMNT_IRQ_IDX];
1620 if (irq->requested) {
1621 ena_trace(ENA_INFO | ENA_ADMQ, "tear down irq: %d\n",
1623 rc = bus_teardown_intr(adapter->pdev, irq->res, irq->cookie);
1624 if (unlikely(rc != 0))
1625 device_printf(adapter->pdev, "failed to tear "
1626 "down irq: %d\n", irq->vector);
1630 if (irq->res != NULL) {
1631 ena_trace(ENA_INFO | ENA_ADMQ, "release resource irq: %d\n",
1633 rc = bus_release_resource(adapter->pdev, SYS_RES_IRQ,
1634 irq->vector, irq->res);
1636 if (unlikely(rc != 0))
1637 device_printf(adapter->pdev, "dev has no parent while "
1638 "releasing res for irq: %d\n", irq->vector);
1643 ena_free_io_irq(struct ena_adapter *adapter)
1645 struct ena_irq *irq;
1648 for (int i = ENA_IO_IRQ_FIRST_IDX; i < adapter->msix_vecs; i++) {
1649 irq = &adapter->irq_tbl[i];
1650 if (irq->requested) {
1651 ena_trace(ENA_INFO | ENA_IOQ, "tear down irq: %d\n",
1653 rc = bus_teardown_intr(adapter->pdev, irq->res,
1655 if (unlikely(rc != 0)) {
1656 device_printf(adapter->pdev, "failed to tear "
1657 "down irq: %d\n", irq->vector);
1662 if (irq->res != NULL) {
1663 ena_trace(ENA_INFO | ENA_IOQ, "release resource irq: %d\n",
1665 rc = bus_release_resource(adapter->pdev, SYS_RES_IRQ,
1666 irq->vector, irq->res);
1668 if (unlikely(rc != 0)) {
1669 device_printf(adapter->pdev, "dev has no parent"
1670 " while releasing res for irq: %d\n",
1678 ena_free_irqs(struct ena_adapter* adapter)
1681 ena_free_io_irq(adapter);
1682 ena_free_mgmnt_irq(adapter);
1683 ena_disable_msix(adapter);
1687 ena_disable_msix(struct ena_adapter *adapter)
1690 if (ENA_FLAG_ISSET(ENA_FLAG_MSIX_ENABLED, adapter)) {
1691 ENA_FLAG_CLEAR_ATOMIC(ENA_FLAG_MSIX_ENABLED, adapter);
1692 pci_release_msi(adapter->pdev);
1695 adapter->msix_vecs = 0;
1696 if (adapter->msix_entries != NULL)
1697 free(adapter->msix_entries, M_DEVBUF);
1698 adapter->msix_entries = NULL;
1702 ena_unmask_all_io_irqs(struct ena_adapter *adapter)
1704 struct ena_com_io_cq* io_cq;
1705 struct ena_eth_io_intr_reg intr_reg;
1709 /* Unmask interrupts for all queues */
1710 for (i = 0; i < adapter->num_queues; i++) {
1711 ena_qid = ENA_IO_TXQ_IDX(i);
1712 io_cq = &adapter->ena_dev->io_cq_queues[ena_qid];
1713 ena_com_update_intr_reg(&intr_reg, 0, 0, true);
1714 ena_com_unmask_intr(io_cq, &intr_reg);
1718 /* Configure the Rx forwarding */
1720 ena_rss_configure(struct ena_adapter *adapter)
1722 struct ena_com_dev *ena_dev = adapter->ena_dev;
1725 /* Set indirect table */
1726 rc = ena_com_indirect_table_set(ena_dev);
1727 if (unlikely((rc != 0) && (rc != EOPNOTSUPP)))
1730 /* Configure hash function (if supported) */
1731 rc = ena_com_set_hash_function(ena_dev);
1732 if (unlikely((rc != 0) && (rc != EOPNOTSUPP)))
1735 /* Configure hash inputs (if supported) */
1736 rc = ena_com_set_hash_ctrl(ena_dev);
1737 if (unlikely((rc != 0) && (rc != EOPNOTSUPP)))
1744 ena_up_complete(struct ena_adapter *adapter)
1748 if (likely(ENA_FLAG_ISSET(ENA_FLAG_RSS_ACTIVE, adapter))) {
1749 rc = ena_rss_configure(adapter);
1754 rc = ena_change_mtu(adapter->ifp, adapter->ifp->if_mtu);
1755 if (unlikely(rc != 0))
1758 ena_refill_all_rx_bufs(adapter);
1759 ena_reset_counters((counter_u64_t *)&adapter->hw_stats,
1760 sizeof(adapter->hw_stats));
1766 ena_up(struct ena_adapter *adapter)
1770 if (unlikely(device_is_attached(adapter->pdev) == 0)) {
1771 device_printf(adapter->pdev, "device is not attached!\n");
1775 if (!ENA_FLAG_ISSET(ENA_FLAG_DEV_UP, adapter)) {
1776 device_printf(adapter->pdev, "device is going UP\n");
1778 /* setup interrupts for IO queues */
1779 rc = ena_setup_io_intr(adapter);
1780 if (unlikely(rc != 0)) {
1781 ena_trace(ENA_ALERT, "error setting up IO interrupt\n");
1784 rc = ena_request_io_irq(adapter);
1785 if (unlikely(rc != 0)) {
1786 ena_trace(ENA_ALERT, "err_req_irq\n");
1790 /* allocate transmit descriptors */
1791 rc = ena_setup_all_tx_resources(adapter);
1792 if (unlikely(rc != 0)) {
1793 ena_trace(ENA_ALERT, "err_setup_tx\n");
1797 /* allocate receive descriptors */
1798 rc = ena_setup_all_rx_resources(adapter);
1799 if (unlikely(rc != 0)) {
1800 ena_trace(ENA_ALERT, "err_setup_rx\n");
1804 /* create IO queues for Rx & Tx */
1805 rc = ena_create_io_queues(adapter);
1806 if (unlikely(rc != 0)) {
1807 ena_trace(ENA_ALERT,
1808 "create IO queues failed\n");
1812 if (ENA_FLAG_ISSET(ENA_FLAG_LINK_UP, adapter))
1813 if_link_state_change(adapter->ifp, LINK_STATE_UP);
1815 rc = ena_up_complete(adapter);
1816 if (unlikely(rc != 0))
1817 goto err_up_complete;
1819 counter_u64_add(adapter->dev_stats.interface_up, 1);
1821 ena_update_hwassist(adapter);
1823 if_setdrvflagbits(adapter->ifp, IFF_DRV_RUNNING,
1826 /* Activate timer service only if the device is running.
1827 * If this flag is not set, it means that the driver is being
1828 * reset and timer service will be activated afterwards.
1830 if (ENA_FLAG_ISSET(ENA_FLAG_DEVICE_RUNNING, adapter)) {
1831 callout_reset_sbt(&adapter->timer_service, SBT_1S,
1832 SBT_1S, ena_timer_service, (void *)adapter, 0);
1835 ENA_FLAG_SET_ATOMIC(ENA_FLAG_DEV_UP, adapter);
1837 ena_unmask_all_io_irqs(adapter);
1843 ena_destroy_all_io_queues(adapter);
1845 ena_free_all_rx_resources(adapter);
1847 ena_free_all_tx_resources(adapter);
1849 ena_free_io_irq(adapter);
1855 ena_get_counter(if_t ifp, ift_counter cnt)
1857 struct ena_adapter *adapter;
1858 struct ena_hw_stats *stats;
1860 adapter = if_getsoftc(ifp);
1861 stats = &adapter->hw_stats;
1864 case IFCOUNTER_IPACKETS:
1865 return (counter_u64_fetch(stats->rx_packets));
1866 case IFCOUNTER_OPACKETS:
1867 return (counter_u64_fetch(stats->tx_packets));
1868 case IFCOUNTER_IBYTES:
1869 return (counter_u64_fetch(stats->rx_bytes));
1870 case IFCOUNTER_OBYTES:
1871 return (counter_u64_fetch(stats->tx_bytes));
1872 case IFCOUNTER_IQDROPS:
1873 return (counter_u64_fetch(stats->rx_drops));
1875 return (if_get_counter_default(ifp, cnt));
1880 ena_media_change(if_t ifp)
1882 /* Media Change is not supported by firmware */
1887 ena_media_status(if_t ifp, struct ifmediareq *ifmr)
1889 struct ena_adapter *adapter = if_getsoftc(ifp);
1890 ena_trace(ENA_DBG, "enter\n");
1892 mtx_lock(&adapter->global_mtx);
1894 ifmr->ifm_status = IFM_AVALID;
1895 ifmr->ifm_active = IFM_ETHER;
1897 if (!ENA_FLAG_ISSET(ENA_FLAG_LINK_UP, adapter)) {
1898 mtx_unlock(&adapter->global_mtx);
1899 ena_trace(ENA_INFO, "Link is down\n");
1903 ifmr->ifm_status |= IFM_ACTIVE;
1904 ifmr->ifm_active |= IFM_UNKNOWN | IFM_FDX;
1906 mtx_unlock(&adapter->global_mtx);
1912 struct ena_adapter *adapter = (struct ena_adapter *)arg;
1914 if (!ENA_FLAG_ISSET(ENA_FLAG_DEV_UP, adapter)) {
1915 sx_xlock(&adapter->ioctl_sx);
1917 sx_unlock(&adapter->ioctl_sx);
1922 ena_ioctl(if_t ifp, u_long command, caddr_t data)
1924 struct ena_adapter *adapter;
1928 adapter = ifp->if_softc;
1929 ifr = (struct ifreq *)data;
1932 * Acquiring lock to prevent from running up and down routines parallel.
1937 if (ifp->if_mtu == ifr->ifr_mtu)
1939 sx_xlock(&adapter->ioctl_sx);
1942 ena_change_mtu(ifp, ifr->ifr_mtu);
1944 rc = ena_up(adapter);
1945 sx_unlock(&adapter->ioctl_sx);
1949 if ((ifp->if_flags & IFF_UP) != 0) {
1950 if ((if_getdrvflags(ifp) & IFF_DRV_RUNNING) != 0) {
1951 if ((ifp->if_flags & (IFF_PROMISC |
1952 IFF_ALLMULTI)) != 0) {
1953 device_printf(adapter->pdev,
1954 "ioctl promisc/allmulti\n");
1957 sx_xlock(&adapter->ioctl_sx);
1958 rc = ena_up(adapter);
1959 sx_unlock(&adapter->ioctl_sx);
1962 if ((if_getdrvflags(ifp) & IFF_DRV_RUNNING) != 0) {
1963 sx_xlock(&adapter->ioctl_sx);
1965 sx_unlock(&adapter->ioctl_sx);
1976 rc = ifmedia_ioctl(ifp, ifr, &adapter->media, command);
1983 if (ifr->ifr_reqcap != ifp->if_capenable) {
1984 ifp->if_capenable = ifr->ifr_reqcap;
1988 if ((reinit != 0) &&
1989 ((if_getdrvflags(ifp) & IFF_DRV_RUNNING) != 0)) {
1990 sx_xlock(&adapter->ioctl_sx);
1992 rc = ena_up(adapter);
1993 sx_unlock(&adapter->ioctl_sx);
1999 rc = ether_ioctl(ifp, command, data);
2007 ena_get_dev_offloads(struct ena_com_dev_get_features_ctx *feat)
2011 if ((feat->offload.tx &
2012 (ENA_ADMIN_FEATURE_OFFLOAD_DESC_TX_L4_IPV4_CSUM_FULL_MASK |
2013 ENA_ADMIN_FEATURE_OFFLOAD_DESC_TX_L4_IPV4_CSUM_PART_MASK |
2014 ENA_ADMIN_FEATURE_OFFLOAD_DESC_TX_L3_CSUM_IPV4_MASK)) != 0)
2015 caps |= IFCAP_TXCSUM;
2017 if ((feat->offload.tx &
2018 (ENA_ADMIN_FEATURE_OFFLOAD_DESC_TX_L4_IPV6_CSUM_FULL_MASK |
2019 ENA_ADMIN_FEATURE_OFFLOAD_DESC_TX_L4_IPV6_CSUM_PART_MASK)) != 0)
2020 caps |= IFCAP_TXCSUM_IPV6;
2022 if ((feat->offload.tx &
2023 ENA_ADMIN_FEATURE_OFFLOAD_DESC_TSO_IPV4_MASK) != 0)
2026 if ((feat->offload.tx &
2027 ENA_ADMIN_FEATURE_OFFLOAD_DESC_TSO_IPV6_MASK) != 0)
2030 if ((feat->offload.rx_supported &
2031 (ENA_ADMIN_FEATURE_OFFLOAD_DESC_RX_L4_IPV4_CSUM_MASK |
2032 ENA_ADMIN_FEATURE_OFFLOAD_DESC_RX_L3_CSUM_IPV4_MASK)) != 0)
2033 caps |= IFCAP_RXCSUM;
2035 if ((feat->offload.rx_supported &
2036 ENA_ADMIN_FEATURE_OFFLOAD_DESC_RX_L4_IPV6_CSUM_MASK) != 0)
2037 caps |= IFCAP_RXCSUM_IPV6;
2039 caps |= IFCAP_LRO | IFCAP_JUMBO_MTU;
2045 ena_update_host_info(struct ena_admin_host_info *host_info, if_t ifp)
2048 host_info->supported_network_features[0] =
2049 (uint32_t)if_getcapabilities(ifp);
2053 ena_update_hwassist(struct ena_adapter *adapter)
2055 if_t ifp = adapter->ifp;
2056 uint32_t feat = adapter->tx_offload_cap;
2057 int cap = if_getcapenable(ifp);
2060 if_clearhwassist(ifp);
2062 if ((cap & IFCAP_TXCSUM) != 0) {
2064 ENA_ADMIN_FEATURE_OFFLOAD_DESC_TX_L3_CSUM_IPV4_MASK) != 0)
2067 (ENA_ADMIN_FEATURE_OFFLOAD_DESC_TX_L4_IPV4_CSUM_FULL_MASK |
2068 ENA_ADMIN_FEATURE_OFFLOAD_DESC_TX_L4_IPV4_CSUM_PART_MASK)) != 0)
2069 flags |= CSUM_IP_UDP | CSUM_IP_TCP;
2072 if ((cap & IFCAP_TXCSUM_IPV6) != 0)
2073 flags |= CSUM_IP6_UDP | CSUM_IP6_TCP;
2075 if ((cap & IFCAP_TSO4) != 0)
2076 flags |= CSUM_IP_TSO;
2078 if ((cap & IFCAP_TSO6) != 0)
2079 flags |= CSUM_IP6_TSO;
2081 if_sethwassistbits(ifp, flags, 0);
2085 ena_setup_ifnet(device_t pdev, struct ena_adapter *adapter,
2086 struct ena_com_dev_get_features_ctx *feat)
2091 ifp = adapter->ifp = if_gethandle(IFT_ETHER);
2092 if (unlikely(ifp == NULL)) {
2093 ena_trace(ENA_ALERT, "can not allocate ifnet structure\n");
2096 if_initname(ifp, device_get_name(pdev), device_get_unit(pdev));
2097 if_setdev(ifp, pdev);
2098 if_setsoftc(ifp, adapter);
2100 if_setflags(ifp, IFF_BROADCAST | IFF_SIMPLEX | IFF_MULTICAST);
2101 if_setinitfn(ifp, ena_init);
2102 if_settransmitfn(ifp, ena_mq_start);
2103 if_setqflushfn(ifp, ena_qflush);
2104 if_setioctlfn(ifp, ena_ioctl);
2105 if_setgetcounterfn(ifp, ena_get_counter);
2107 if_setsendqlen(ifp, adapter->tx_ring_size);
2108 if_setsendqready(ifp);
2109 if_setmtu(ifp, ETHERMTU);
2110 if_setbaudrate(ifp, 0);
2111 /* Zeroize capabilities... */
2112 if_setcapabilities(ifp, 0);
2113 if_setcapenable(ifp, 0);
2114 /* check hardware support */
2115 caps = ena_get_dev_offloads(feat);
2116 /* ... and set them */
2117 if_setcapabilitiesbit(ifp, caps, 0);
2119 /* TSO parameters */
2120 ifp->if_hw_tsomax = ENA_TSO_MAXSIZE -
2121 (ETHER_HDR_LEN + ETHER_VLAN_ENCAP_LEN);
2122 ifp->if_hw_tsomaxsegcount = adapter->max_tx_sgl_size - 1;
2123 ifp->if_hw_tsomaxsegsize = ENA_TSO_MAXSIZE;
2125 if_setifheaderlen(ifp, sizeof(struct ether_vlan_header));
2126 if_setcapenable(ifp, if_getcapabilities(ifp));
2129 * Specify the media types supported by this adapter and register
2130 * callbacks to update media and link information
2132 ifmedia_init(&adapter->media, IFM_IMASK,
2133 ena_media_change, ena_media_status);
2134 ifmedia_add(&adapter->media, IFM_ETHER | IFM_AUTO, 0, NULL);
2135 ifmedia_set(&adapter->media, IFM_ETHER | IFM_AUTO);
2137 ether_ifattach(ifp, adapter->mac_addr);
2143 ena_down(struct ena_adapter *adapter)
2147 if (ENA_FLAG_ISSET(ENA_FLAG_DEV_UP, adapter)) {
2148 device_printf(adapter->pdev, "device is going DOWN\n");
2150 callout_drain(&adapter->timer_service);
2152 ENA_FLAG_CLEAR_ATOMIC(ENA_FLAG_DEV_UP, adapter);
2153 if_setdrvflagbits(adapter->ifp, IFF_DRV_OACTIVE,
2156 ena_free_io_irq(adapter);
2158 if (ENA_FLAG_ISSET(ENA_FLAG_TRIGGER_RESET, adapter)) {
2159 rc = ena_com_dev_reset(adapter->ena_dev,
2160 adapter->reset_reason);
2161 if (unlikely(rc != 0))
2162 device_printf(adapter->pdev,
2163 "Device reset failed\n");
2166 ena_destroy_all_io_queues(adapter);
2168 ena_free_all_tx_bufs(adapter);
2169 ena_free_all_rx_bufs(adapter);
2170 ena_free_all_tx_resources(adapter);
2171 ena_free_all_rx_resources(adapter);
2173 counter_u64_add(adapter->dev_stats.interface_down, 1);
2178 ena_calc_io_queue_num(struct ena_adapter *adapter,
2179 struct ena_com_dev_get_features_ctx *get_feat_ctx)
2181 struct ena_com_dev *ena_dev = adapter->ena_dev;
2182 int io_tx_sq_num, io_tx_cq_num, io_rx_num, io_queue_num;
2184 /* Regular queues capabilities */
2185 if (ena_dev->supported_features & BIT(ENA_ADMIN_MAX_QUEUES_EXT)) {
2186 struct ena_admin_queue_ext_feature_fields *max_queue_ext =
2187 &get_feat_ctx->max_queue_ext.max_queue_ext;
2188 io_rx_num = min_t(int, max_queue_ext->max_rx_sq_num,
2189 max_queue_ext->max_rx_cq_num);
2191 io_tx_sq_num = max_queue_ext->max_tx_sq_num;
2192 io_tx_cq_num = max_queue_ext->max_tx_cq_num;
2194 struct ena_admin_queue_feature_desc *max_queues =
2195 &get_feat_ctx->max_queues;
2196 io_tx_sq_num = max_queues->max_sq_num;
2197 io_tx_cq_num = max_queues->max_cq_num;
2198 io_rx_num = min_t(int, io_tx_sq_num, io_tx_cq_num);
2201 /* In case of LLQ use the llq fields for the tx SQ/CQ */
2202 if (ena_dev->tx_mem_queue_type == ENA_ADMIN_PLACEMENT_POLICY_DEV)
2203 io_tx_sq_num = get_feat_ctx->llq.max_llq_num;
2205 io_queue_num = min_t(int, mp_ncpus, ENA_MAX_NUM_IO_QUEUES);
2206 io_queue_num = min_t(int, io_queue_num, io_rx_num);
2207 io_queue_num = min_t(int, io_queue_num, io_tx_sq_num);
2208 io_queue_num = min_t(int, io_queue_num, io_tx_cq_num);
2209 /* 1 IRQ for for mgmnt and 1 IRQ for each TX/RX pair */
2210 io_queue_num = min_t(int, io_queue_num,
2211 pci_msix_count(adapter->pdev) - 1);
2213 return (io_queue_num);
2217 ena_enable_wc(struct resource *res)
2219 #if defined(__i386) || defined(__amd64) || defined(__aarch64__)
2224 va = (vm_offset_t)rman_get_virtual(res);
2225 len = rman_get_size(res);
2226 /* Enable write combining */
2227 rc = pmap_change_attr(va, len, VM_MEMATTR_WRITE_COMBINING);
2228 if (unlikely(rc != 0)) {
2229 ena_trace(ENA_ALERT, "pmap_change_attr failed, %d\n", rc);
2235 return (EOPNOTSUPP);
2239 ena_set_queues_placement_policy(device_t pdev, struct ena_com_dev *ena_dev,
2240 struct ena_admin_feature_llq_desc *llq,
2241 struct ena_llq_configurations *llq_default_configurations)
2243 struct ena_adapter *adapter = device_get_softc(pdev);
2245 uint32_t llq_feature_mask;
2247 llq_feature_mask = 1 << ENA_ADMIN_LLQ;
2248 if (!(ena_dev->supported_features & llq_feature_mask)) {
2250 "LLQ is not supported. Fallback to host mode policy.\n");
2251 ena_dev->tx_mem_queue_type = ENA_ADMIN_PLACEMENT_POLICY_HOST;
2255 rc = ena_com_config_dev_mode(ena_dev, llq, llq_default_configurations);
2256 if (unlikely(rc != 0)) {
2257 device_printf(pdev, "Failed to configure the device mode. "
2258 "Fallback to host mode policy.\n");
2259 ena_dev->tx_mem_queue_type = ENA_ADMIN_PLACEMENT_POLICY_HOST;
2263 /* Nothing to config, exit */
2264 if (ena_dev->tx_mem_queue_type == ENA_ADMIN_PLACEMENT_POLICY_HOST)
2267 /* Try to allocate resources for LLQ bar */
2268 rid = PCIR_BAR(ENA_MEM_BAR);
2269 adapter->memory = bus_alloc_resource_any(pdev, SYS_RES_MEMORY,
2271 if (unlikely(adapter->memory == NULL)) {
2272 device_printf(pdev, "unable to allocate LLQ bar resource. "
2273 "Fallback to host mode policy.\n");
2274 ena_dev->tx_mem_queue_type = ENA_ADMIN_PLACEMENT_POLICY_HOST;
2278 /* Enable write combining for better LLQ performance */
2279 rc = ena_enable_wc(adapter->memory);
2280 if (unlikely(rc != 0)) {
2281 device_printf(pdev, "failed to enable write combining.\n");
2286 * Save virtual address of the device's memory region
2287 * for the ena_com layer.
2289 ena_dev->mem_bar = rman_get_virtual(adapter->memory);
2295 void set_default_llq_configurations(struct ena_llq_configurations *llq_config)
2297 llq_config->llq_header_location = ENA_ADMIN_INLINE_HEADER;
2298 llq_config->llq_ring_entry_size = ENA_ADMIN_LIST_ENTRY_SIZE_128B;
2299 llq_config->llq_stride_ctrl = ENA_ADMIN_MULTIPLE_DESCS_PER_ENTRY;
2300 llq_config->llq_num_decs_before_header =
2301 ENA_ADMIN_LLQ_NUM_DESCS_BEFORE_HEADER_2;
2302 llq_config->llq_ring_entry_size_value = 128;
2306 ena_calc_queue_size(struct ena_adapter *adapter,
2307 struct ena_calc_queue_size_ctx *ctx)
2309 struct ena_admin_feature_llq_desc *llq = &ctx->get_feat_ctx->llq;
2310 struct ena_com_dev *ena_dev = ctx->ena_dev;
2311 uint32_t tx_queue_size = ENA_DEFAULT_RING_SIZE;
2312 uint32_t rx_queue_size = adapter->rx_ring_size;
2314 if (ena_dev->supported_features & BIT(ENA_ADMIN_MAX_QUEUES_EXT)) {
2315 struct ena_admin_queue_ext_feature_fields *max_queue_ext =
2316 &ctx->get_feat_ctx->max_queue_ext.max_queue_ext;
2317 rx_queue_size = min_t(uint32_t, rx_queue_size,
2318 max_queue_ext->max_rx_cq_depth);
2319 rx_queue_size = min_t(uint32_t, rx_queue_size,
2320 max_queue_ext->max_rx_sq_depth);
2321 tx_queue_size = min_t(uint32_t, tx_queue_size,
2322 max_queue_ext->max_tx_cq_depth);
2324 if (ena_dev->tx_mem_queue_type ==
2325 ENA_ADMIN_PLACEMENT_POLICY_DEV)
2326 tx_queue_size = min_t(uint32_t, tx_queue_size,
2327 llq->max_llq_depth);
2329 tx_queue_size = min_t(uint32_t, tx_queue_size,
2330 max_queue_ext->max_tx_sq_depth);
2332 ctx->max_rx_sgl_size = min_t(uint16_t, ENA_PKT_MAX_BUFS,
2333 max_queue_ext->max_per_packet_rx_descs);
2334 ctx->max_tx_sgl_size = min_t(uint16_t, ENA_PKT_MAX_BUFS,
2335 max_queue_ext->max_per_packet_tx_descs);
2337 struct ena_admin_queue_feature_desc *max_queues =
2338 &ctx->get_feat_ctx->max_queues;
2339 rx_queue_size = min_t(uint32_t, rx_queue_size,
2340 max_queues->max_cq_depth);
2341 rx_queue_size = min_t(uint32_t, rx_queue_size,
2342 max_queues->max_sq_depth);
2343 tx_queue_size = min_t(uint32_t, tx_queue_size,
2344 max_queues->max_cq_depth);
2346 if (ena_dev->tx_mem_queue_type ==
2347 ENA_ADMIN_PLACEMENT_POLICY_DEV)
2348 tx_queue_size = min_t(uint32_t, tx_queue_size,
2349 llq->max_llq_depth);
2351 tx_queue_size = min_t(uint32_t, tx_queue_size,
2352 max_queues->max_sq_depth);
2354 ctx->max_rx_sgl_size = min_t(uint16_t, ENA_PKT_MAX_BUFS,
2355 max_queues->max_packet_tx_descs);
2356 ctx->max_tx_sgl_size = min_t(uint16_t, ENA_PKT_MAX_BUFS,
2357 max_queues->max_packet_rx_descs);
2360 /* round down to the nearest power of 2 */
2361 rx_queue_size = 1 << (fls(rx_queue_size) - 1);
2362 tx_queue_size = 1 << (fls(tx_queue_size) - 1);
2364 if (unlikely(rx_queue_size == 0 || tx_queue_size == 0)) {
2365 device_printf(ctx->pdev, "Invalid queue size\n");
2369 ctx->rx_queue_size = rx_queue_size;
2370 ctx->tx_queue_size = tx_queue_size;
2376 ena_handle_updated_queues(struct ena_adapter *adapter,
2377 struct ena_com_dev_get_features_ctx *get_feat_ctx)
2379 struct ena_com_dev *ena_dev = adapter->ena_dev;
2380 struct ena_calc_queue_size_ctx calc_queue_ctx = { 0 };
2381 device_t pdev = adapter->pdev;
2382 bool are_queues_changed = false;
2383 int io_queue_num, rc;
2385 calc_queue_ctx.ena_dev = ena_dev;
2386 calc_queue_ctx.get_feat_ctx = get_feat_ctx;
2387 calc_queue_ctx.pdev = pdev;
2389 io_queue_num = ena_calc_io_queue_num(adapter, get_feat_ctx);
2390 rc = ena_calc_queue_size(adapter, &calc_queue_ctx);
2391 if (unlikely(rc != 0 || io_queue_num <= 0))
2394 if (adapter->tx_ring->buf_ring_size != adapter->buf_ring_size)
2395 are_queues_changed = true;
2397 if (unlikely(adapter->tx_ring_size > calc_queue_ctx.tx_queue_size ||
2398 adapter->rx_ring_size > calc_queue_ctx.rx_queue_size)) {
2400 "Not enough resources to allocate requested queue sizes "
2401 "(TX,RX)=(%d,%d), falling back to queue sizes "
2402 "(TX,RX)=(%d,%d)\n",
2403 adapter->tx_ring_size,
2404 adapter->rx_ring_size,
2405 calc_queue_ctx.tx_queue_size,
2406 calc_queue_ctx.rx_queue_size);
2407 adapter->tx_ring_size = calc_queue_ctx.tx_queue_size;
2408 adapter->rx_ring_size = calc_queue_ctx.rx_queue_size;
2409 adapter->max_tx_sgl_size = calc_queue_ctx.max_tx_sgl_size;
2410 adapter->max_rx_sgl_size = calc_queue_ctx.max_rx_sgl_size;
2411 are_queues_changed = true;
2414 if (unlikely(adapter->num_queues > io_queue_num)) {
2416 "Not enough resources to allocate %d queues, "
2417 "falling back to %d queues\n",
2418 adapter->num_queues, io_queue_num);
2419 adapter->num_queues = io_queue_num;
2420 if (ENA_FLAG_ISSET(ENA_FLAG_RSS_ACTIVE, adapter)) {
2421 ena_com_rss_destroy(ena_dev);
2422 rc = ena_rss_init_default(adapter);
2423 if (unlikely(rc != 0) && (rc != EOPNOTSUPP)) {
2424 device_printf(pdev, "Cannot init RSS rc: %d\n",
2429 are_queues_changed = true;
2432 if (unlikely(are_queues_changed)) {
2433 ena_free_all_io_rings_resources(adapter);
2434 ena_init_io_rings(adapter);
2441 ena_rss_init_default(struct ena_adapter *adapter)
2443 struct ena_com_dev *ena_dev = adapter->ena_dev;
2444 device_t dev = adapter->pdev;
2447 rc = ena_com_rss_init(ena_dev, ENA_RX_RSS_TABLE_LOG_SIZE);
2448 if (unlikely(rc != 0)) {
2449 device_printf(dev, "Cannot init indirect table\n");
2453 for (i = 0; i < ENA_RX_RSS_TABLE_SIZE; i++) {
2454 qid = i % adapter->num_queues;
2455 rc = ena_com_indirect_table_fill_entry(ena_dev, i,
2456 ENA_IO_RXQ_IDX(qid));
2457 if (unlikely((rc != 0) && (rc != EOPNOTSUPP))) {
2458 device_printf(dev, "Cannot fill indirect table\n");
2459 goto err_rss_destroy;
2463 rc = ena_com_fill_hash_function(ena_dev, ENA_ADMIN_CRC32, NULL,
2464 ENA_HASH_KEY_SIZE, 0xFFFFFFFF);
2465 if (unlikely((rc != 0) && (rc != EOPNOTSUPP))) {
2466 device_printf(dev, "Cannot fill hash function\n");
2467 goto err_rss_destroy;
2470 rc = ena_com_set_default_hash_ctrl(ena_dev);
2471 if (unlikely((rc != 0) && (rc != EOPNOTSUPP))) {
2472 device_printf(dev, "Cannot fill hash control\n");
2473 goto err_rss_destroy;
2479 ena_com_rss_destroy(ena_dev);
2484 ena_rss_init_default_deferred(void *arg)
2486 struct ena_adapter *adapter;
2491 dc = devclass_find("ena");
2492 if (unlikely(dc == NULL)) {
2493 ena_trace(ENA_ALERT, "No devclass ena\n");
2497 max = devclass_get_maxunit(dc);
2498 while (max-- >= 0) {
2499 adapter = devclass_get_softc(dc, max);
2500 if (adapter != NULL) {
2501 rc = ena_rss_init_default(adapter);
2502 ENA_FLAG_SET_ATOMIC(ENA_FLAG_RSS_ACTIVE, adapter);
2503 if (unlikely(rc != 0)) {
2504 device_printf(adapter->pdev,
2505 "WARNING: RSS was not properly initialized,"
2506 " it will affect bandwidth\n");
2507 ENA_FLAG_CLEAR_ATOMIC(ENA_FLAG_RSS_ACTIVE, adapter);
2512 SYSINIT(ena_rss_init, SI_SUB_KICK_SCHEDULER, SI_ORDER_SECOND, ena_rss_init_default_deferred, NULL);
2515 ena_config_host_info(struct ena_com_dev *ena_dev, device_t dev)
2517 struct ena_admin_host_info *host_info;
2521 /* Allocate only the host info */
2522 rc = ena_com_allocate_host_info(ena_dev);
2523 if (unlikely(rc != 0)) {
2524 ena_trace(ENA_ALERT, "Cannot allocate host info\n");
2528 host_info = ena_dev->host_attr.host_info;
2530 if (pci_get_id(dev, PCI_ID_RID, &rid) == 0)
2531 host_info->bdf = rid;
2532 host_info->os_type = ENA_ADMIN_OS_FREEBSD;
2533 host_info->kernel_ver = osreldate;
2535 sprintf(host_info->kernel_ver_str, "%d", osreldate);
2536 host_info->os_dist = 0;
2537 strncpy(host_info->os_dist_str, osrelease,
2538 sizeof(host_info->os_dist_str) - 1);
2540 host_info->driver_version =
2541 (DRV_MODULE_VER_MAJOR) |
2542 (DRV_MODULE_VER_MINOR << ENA_ADMIN_HOST_INFO_MINOR_SHIFT) |
2543 (DRV_MODULE_VER_SUBMINOR << ENA_ADMIN_HOST_INFO_SUB_MINOR_SHIFT);
2544 host_info->num_cpus = mp_ncpus;
2546 rc = ena_com_set_host_attributes(ena_dev);
2547 if (unlikely(rc != 0)) {
2548 if (rc == EOPNOTSUPP)
2549 ena_trace(ENA_WARNING, "Cannot set host attributes\n");
2551 ena_trace(ENA_ALERT, "Cannot set host attributes\n");
2559 ena_com_delete_host_info(ena_dev);
2563 ena_device_init(struct ena_adapter *adapter, device_t pdev,
2564 struct ena_com_dev_get_features_ctx *get_feat_ctx, int *wd_active)
2566 struct ena_com_dev* ena_dev = adapter->ena_dev;
2567 bool readless_supported;
2568 uint32_t aenq_groups;
2572 rc = ena_com_mmio_reg_read_request_init(ena_dev);
2573 if (unlikely(rc != 0)) {
2574 device_printf(pdev, "failed to init mmio read less\n");
2579 * The PCIe configuration space revision id indicate if mmio reg
2582 readless_supported = !(pci_get_revid(pdev) & ENA_MMIO_DISABLE_REG_READ);
2583 ena_com_set_mmio_read_mode(ena_dev, readless_supported);
2585 rc = ena_com_dev_reset(ena_dev, ENA_REGS_RESET_NORMAL);
2586 if (unlikely(rc != 0)) {
2587 device_printf(pdev, "Can not reset device\n");
2588 goto err_mmio_read_less;
2591 rc = ena_com_validate_version(ena_dev);
2592 if (unlikely(rc != 0)) {
2593 device_printf(pdev, "device version is too low\n");
2594 goto err_mmio_read_less;
2597 dma_width = ena_com_get_dma_width(ena_dev);
2598 if (unlikely(dma_width < 0)) {
2599 device_printf(pdev, "Invalid dma width value %d", dma_width);
2601 goto err_mmio_read_less;
2603 adapter->dma_width = dma_width;
2605 /* ENA admin level init */
2606 rc = ena_com_admin_init(ena_dev, &aenq_handlers);
2607 if (unlikely(rc != 0)) {
2609 "Can not initialize ena admin queue with device\n");
2610 goto err_mmio_read_less;
2614 * To enable the msix interrupts the driver needs to know the number
2615 * of queues. So the driver uses polling mode to retrieve this
2618 ena_com_set_admin_polling_mode(ena_dev, true);
2620 ena_config_host_info(ena_dev, pdev);
2622 /* Get Device Attributes */
2623 rc = ena_com_get_dev_attr_feat(ena_dev, get_feat_ctx);
2624 if (unlikely(rc != 0)) {
2626 "Cannot get attribute for ena device rc: %d\n", rc);
2627 goto err_admin_init;
2630 aenq_groups = BIT(ENA_ADMIN_LINK_CHANGE) |
2631 BIT(ENA_ADMIN_FATAL_ERROR) |
2632 BIT(ENA_ADMIN_WARNING) |
2633 BIT(ENA_ADMIN_NOTIFICATION) |
2634 BIT(ENA_ADMIN_KEEP_ALIVE);
2636 aenq_groups &= get_feat_ctx->aenq.supported_groups;
2637 rc = ena_com_set_aenq_config(ena_dev, aenq_groups);
2638 if (unlikely(rc != 0)) {
2639 device_printf(pdev, "Cannot configure aenq groups rc: %d\n", rc);
2640 goto err_admin_init;
2643 *wd_active = !!(aenq_groups & BIT(ENA_ADMIN_KEEP_ALIVE));
2648 ena_com_delete_host_info(ena_dev);
2649 ena_com_admin_destroy(ena_dev);
2651 ena_com_mmio_reg_read_request_destroy(ena_dev);
2656 static int ena_enable_msix_and_set_admin_interrupts(struct ena_adapter *adapter,
2659 struct ena_com_dev *ena_dev = adapter->ena_dev;
2662 rc = ena_enable_msix(adapter);
2663 if (unlikely(rc != 0)) {
2664 device_printf(adapter->pdev, "Error with MSI-X enablement\n");
2668 ena_setup_mgmnt_intr(adapter);
2670 rc = ena_request_mgmnt_irq(adapter);
2671 if (unlikely(rc != 0)) {
2672 device_printf(adapter->pdev, "Cannot setup mgmnt queue intr\n");
2673 goto err_disable_msix;
2676 ena_com_set_admin_polling_mode(ena_dev, false);
2678 ena_com_admin_aenq_enable(ena_dev);
2683 ena_disable_msix(adapter);
2688 /* Function called on ENA_ADMIN_KEEP_ALIVE event */
2689 static void ena_keep_alive_wd(void *adapter_data,
2690 struct ena_admin_aenq_entry *aenq_e)
2692 struct ena_adapter *adapter = (struct ena_adapter *)adapter_data;
2693 struct ena_admin_aenq_keep_alive_desc *desc;
2697 desc = (struct ena_admin_aenq_keep_alive_desc *)aenq_e;
2699 rx_drops = ((uint64_t)desc->rx_drops_high << 32) | desc->rx_drops_low;
2700 counter_u64_zero(adapter->hw_stats.rx_drops);
2701 counter_u64_add(adapter->hw_stats.rx_drops, rx_drops);
2703 stime = getsbinuptime();
2704 atomic_store_rel_64(&adapter->keep_alive_timestamp, stime);
2707 /* Check for keep alive expiration */
2708 static void check_for_missing_keep_alive(struct ena_adapter *adapter)
2710 sbintime_t timestamp, time;
2712 if (adapter->wd_active == 0)
2715 if (adapter->keep_alive_timeout == ENA_HW_HINTS_NO_TIMEOUT)
2718 timestamp = atomic_load_acq_64(&adapter->keep_alive_timestamp);
2719 time = getsbinuptime() - timestamp;
2720 if (unlikely(time > adapter->keep_alive_timeout)) {
2721 device_printf(adapter->pdev,
2722 "Keep alive watchdog timeout.\n");
2723 counter_u64_add(adapter->dev_stats.wd_expired, 1);
2724 if (likely(!ENA_FLAG_ISSET(ENA_FLAG_TRIGGER_RESET, adapter))) {
2725 adapter->reset_reason = ENA_REGS_RESET_KEEP_ALIVE_TO;
2726 ENA_FLAG_SET_ATOMIC(ENA_FLAG_TRIGGER_RESET, adapter);
2731 /* Check if admin queue is enabled */
2732 static void check_for_admin_com_state(struct ena_adapter *adapter)
2734 if (unlikely(ena_com_get_admin_running_state(adapter->ena_dev) ==
2736 device_printf(adapter->pdev,
2737 "ENA admin queue is not in running state!\n");
2738 counter_u64_add(adapter->dev_stats.admin_q_pause, 1);
2739 if (likely(!ENA_FLAG_ISSET(ENA_FLAG_TRIGGER_RESET, adapter))) {
2740 adapter->reset_reason = ENA_REGS_RESET_ADMIN_TO;
2741 ENA_FLAG_SET_ATOMIC(ENA_FLAG_TRIGGER_RESET, adapter);
2747 check_for_rx_interrupt_queue(struct ena_adapter *adapter,
2748 struct ena_ring *rx_ring)
2750 if (likely(rx_ring->first_interrupt))
2753 if (ena_com_cq_empty(rx_ring->ena_com_io_cq))
2756 rx_ring->no_interrupt_event_cnt++;
2758 if (rx_ring->no_interrupt_event_cnt == ENA_MAX_NO_INTERRUPT_ITERATIONS) {
2759 device_printf(adapter->pdev, "Potential MSIX issue on Rx side "
2760 "Queue = %d. Reset the device\n", rx_ring->qid);
2761 if (likely(!ENA_FLAG_ISSET(ENA_FLAG_TRIGGER_RESET, adapter))) {
2762 adapter->reset_reason = ENA_REGS_RESET_MISS_INTERRUPT;
2763 ENA_FLAG_SET_ATOMIC(ENA_FLAG_TRIGGER_RESET, adapter);
2772 check_missing_comp_in_tx_queue(struct ena_adapter *adapter,
2773 struct ena_ring *tx_ring)
2775 struct bintime curtime, time;
2776 struct ena_tx_buffer *tx_buf;
2777 sbintime_t time_offset;
2778 uint32_t missed_tx = 0;
2781 getbinuptime(&curtime);
2783 for (i = 0; i < tx_ring->ring_size; i++) {
2784 tx_buf = &tx_ring->tx_buffer_info[i];
2786 if (bintime_isset(&tx_buf->timestamp) == 0)
2790 bintime_sub(&time, &tx_buf->timestamp);
2791 time_offset = bttosbt(time);
2793 if (unlikely(!tx_ring->first_interrupt &&
2794 time_offset > 2 * adapter->missing_tx_timeout)) {
2796 * If after graceful period interrupt is still not
2797 * received, we schedule a reset.
2799 device_printf(adapter->pdev,
2800 "Potential MSIX issue on Tx side Queue = %d. "
2801 "Reset the device\n", tx_ring->qid);
2802 if (likely(!ENA_FLAG_ISSET(ENA_FLAG_TRIGGER_RESET,
2804 adapter->reset_reason =
2805 ENA_REGS_RESET_MISS_INTERRUPT;
2806 ENA_FLAG_SET_ATOMIC(ENA_FLAG_TRIGGER_RESET,
2812 /* Check again if packet is still waiting */
2813 if (unlikely(time_offset > adapter->missing_tx_timeout)) {
2815 if (!tx_buf->print_once)
2816 ena_trace(ENA_WARNING, "Found a Tx that wasn't "
2817 "completed on time, qid %d, index %d.\n",
2820 tx_buf->print_once = true;
2825 if (unlikely(missed_tx > adapter->missing_tx_threshold)) {
2826 device_printf(adapter->pdev,
2827 "The number of lost tx completion is above the threshold "
2828 "(%d > %d). Reset the device\n",
2829 missed_tx, adapter->missing_tx_threshold);
2830 if (likely(!ENA_FLAG_ISSET(ENA_FLAG_TRIGGER_RESET, adapter))) {
2831 adapter->reset_reason = ENA_REGS_RESET_MISS_TX_CMPL;
2832 ENA_FLAG_SET_ATOMIC(ENA_FLAG_TRIGGER_RESET, adapter);
2837 counter_u64_add(tx_ring->tx_stats.missing_tx_comp, missed_tx);
2843 * Check for TX which were not completed on time.
2844 * Timeout is defined by "missing_tx_timeout".
2845 * Reset will be performed if number of incompleted
2846 * transactions exceeds "missing_tx_threshold".
2849 check_for_missing_completions(struct ena_adapter *adapter)
2851 struct ena_ring *tx_ring;
2852 struct ena_ring *rx_ring;
2855 /* Make sure the driver doesn't turn the device in other process */
2858 if (!ENA_FLAG_ISSET(ENA_FLAG_DEV_UP, adapter))
2861 if (ENA_FLAG_ISSET(ENA_FLAG_TRIGGER_RESET, adapter))
2864 if (adapter->missing_tx_timeout == ENA_HW_HINTS_NO_TIMEOUT)
2867 budget = adapter->missing_tx_max_queues;
2869 for (i = adapter->next_monitored_tx_qid; i < adapter->num_queues; i++) {
2870 tx_ring = &adapter->tx_ring[i];
2871 rx_ring = &adapter->rx_ring[i];
2873 rc = check_missing_comp_in_tx_queue(adapter, tx_ring);
2874 if (unlikely(rc != 0))
2877 rc = check_for_rx_interrupt_queue(adapter, rx_ring);
2878 if (unlikely(rc != 0))
2888 adapter->next_monitored_tx_qid = i % adapter->num_queues;
2891 /* trigger rx cleanup after 2 consecutive detections */
2892 #define EMPTY_RX_REFILL 2
2893 /* For the rare case where the device runs out of Rx descriptors and the
2894 * msix handler failed to refill new Rx descriptors (due to a lack of memory
2896 * This case will lead to a deadlock:
2897 * The device won't send interrupts since all the new Rx packets will be dropped
2898 * The msix handler won't allocate new Rx descriptors so the device won't be
2899 * able to send new packets.
2901 * When such a situation is detected - execute rx cleanup task in another thread
2904 check_for_empty_rx_ring(struct ena_adapter *adapter)
2906 struct ena_ring *rx_ring;
2907 int i, refill_required;
2909 if (!ENA_FLAG_ISSET(ENA_FLAG_DEV_UP, adapter))
2912 if (ENA_FLAG_ISSET(ENA_FLAG_TRIGGER_RESET, adapter))
2915 for (i = 0; i < adapter->num_queues; i++) {
2916 rx_ring = &adapter->rx_ring[i];
2918 refill_required = ena_com_free_desc(rx_ring->ena_com_io_sq);
2919 if (unlikely(refill_required == (rx_ring->ring_size - 1))) {
2920 rx_ring->empty_rx_queue++;
2922 if (rx_ring->empty_rx_queue >= EMPTY_RX_REFILL) {
2923 counter_u64_add(rx_ring->rx_stats.empty_rx_ring,
2926 device_printf(adapter->pdev,
2927 "trigger refill for ring %d\n", i);
2929 taskqueue_enqueue(rx_ring->que->cleanup_tq,
2930 &rx_ring->que->cleanup_task);
2931 rx_ring->empty_rx_queue = 0;
2934 rx_ring->empty_rx_queue = 0;
2939 static void ena_update_hints(struct ena_adapter *adapter,
2940 struct ena_admin_ena_hw_hints *hints)
2942 struct ena_com_dev *ena_dev = adapter->ena_dev;
2944 if (hints->admin_completion_tx_timeout)
2945 ena_dev->admin_queue.completion_timeout =
2946 hints->admin_completion_tx_timeout * 1000;
2948 if (hints->mmio_read_timeout)
2949 /* convert to usec */
2950 ena_dev->mmio_read.reg_read_to =
2951 hints->mmio_read_timeout * 1000;
2953 if (hints->missed_tx_completion_count_threshold_to_reset)
2954 adapter->missing_tx_threshold =
2955 hints->missed_tx_completion_count_threshold_to_reset;
2957 if (hints->missing_tx_completion_timeout) {
2958 if (hints->missing_tx_completion_timeout ==
2959 ENA_HW_HINTS_NO_TIMEOUT)
2960 adapter->missing_tx_timeout = ENA_HW_HINTS_NO_TIMEOUT;
2962 adapter->missing_tx_timeout =
2963 SBT_1MS * hints->missing_tx_completion_timeout;
2966 if (hints->driver_watchdog_timeout) {
2967 if (hints->driver_watchdog_timeout == ENA_HW_HINTS_NO_TIMEOUT)
2968 adapter->keep_alive_timeout = ENA_HW_HINTS_NO_TIMEOUT;
2970 adapter->keep_alive_timeout =
2971 SBT_1MS * hints->driver_watchdog_timeout;
2976 ena_timer_service(void *data)
2978 struct ena_adapter *adapter = (struct ena_adapter *)data;
2979 struct ena_admin_host_info *host_info =
2980 adapter->ena_dev->host_attr.host_info;
2982 check_for_missing_keep_alive(adapter);
2984 check_for_admin_com_state(adapter);
2986 check_for_missing_completions(adapter);
2988 check_for_empty_rx_ring(adapter);
2990 if (host_info != NULL)
2991 ena_update_host_info(host_info, adapter->ifp);
2993 if (unlikely(ENA_FLAG_ISSET(ENA_FLAG_TRIGGER_RESET, adapter))) {
2994 device_printf(adapter->pdev, "Trigger reset is on\n");
2995 taskqueue_enqueue(adapter->reset_tq, &adapter->reset_task);
3000 * Schedule another timeout one second from now.
3002 callout_schedule_sbt(&adapter->timer_service, SBT_1S, SBT_1S, 0);
3006 ena_destroy_device(struct ena_adapter *adapter, bool graceful)
3008 if_t ifp = adapter->ifp;
3009 struct ena_com_dev *ena_dev = adapter->ena_dev;
3012 if (!ENA_FLAG_ISSET(ENA_FLAG_DEVICE_RUNNING, adapter))
3015 if_link_state_change(ifp, LINK_STATE_DOWN);
3017 callout_drain(&adapter->timer_service);
3019 dev_up = ENA_FLAG_ISSET(ENA_FLAG_DEV_UP, adapter);
3021 ENA_FLAG_SET_ATOMIC(ENA_FLAG_DEV_UP_BEFORE_RESET, adapter);
3023 ENA_FLAG_CLEAR_ATOMIC(ENA_FLAG_DEV_UP_BEFORE_RESET, adapter);
3026 ena_com_set_admin_running_state(ena_dev, false);
3028 if (ENA_FLAG_ISSET(ENA_FLAG_DEV_UP, adapter))
3032 * Stop the device from sending AENQ events (if the device was up, and
3033 * the trigger reset was on, ena_down already performs device reset)
3035 if (!(ENA_FLAG_ISSET(ENA_FLAG_TRIGGER_RESET, adapter) && dev_up))
3036 ena_com_dev_reset(adapter->ena_dev, adapter->reset_reason);
3038 ena_free_mgmnt_irq(adapter);
3040 ena_disable_msix(adapter);
3042 ena_com_abort_admin_commands(ena_dev);
3044 ena_com_wait_for_abort_completion(ena_dev);
3046 ena_com_admin_destroy(ena_dev);
3048 ena_com_mmio_reg_read_request_destroy(ena_dev);
3050 adapter->reset_reason = ENA_REGS_RESET_NORMAL;
3052 ENA_FLAG_CLEAR_ATOMIC(ENA_FLAG_TRIGGER_RESET, adapter);
3053 ENA_FLAG_CLEAR_ATOMIC(ENA_FLAG_DEVICE_RUNNING, adapter);
3057 ena_device_validate_params(struct ena_adapter *adapter,
3058 struct ena_com_dev_get_features_ctx *get_feat_ctx)
3061 if (memcmp(get_feat_ctx->dev_attr.mac_addr, adapter->mac_addr,
3062 ETHER_ADDR_LEN) != 0) {
3063 device_printf(adapter->pdev,
3064 "Error, mac address are different\n");
3068 if (get_feat_ctx->dev_attr.max_mtu < if_getmtu(adapter->ifp)) {
3069 device_printf(adapter->pdev,
3070 "Error, device max mtu is smaller than ifp MTU\n");
3078 ena_restore_device(struct ena_adapter *adapter)
3080 struct ena_com_dev_get_features_ctx get_feat_ctx;
3081 struct ena_com_dev *ena_dev = adapter->ena_dev;
3082 if_t ifp = adapter->ifp;
3083 device_t dev = adapter->pdev;
3087 ENA_FLAG_SET_ATOMIC(ENA_FLAG_ONGOING_RESET, adapter);
3089 rc = ena_device_init(adapter, dev, &get_feat_ctx, &wd_active);
3091 device_printf(dev, "Cannot initialize device\n");
3095 * Only enable WD if it was enabled before reset, so it won't override
3096 * value set by the user by the sysctl.
3098 if (adapter->wd_active != 0)
3099 adapter->wd_active = wd_active;
3101 rc = ena_device_validate_params(adapter, &get_feat_ctx);
3103 device_printf(dev, "Validation of device parameters failed\n");
3104 goto err_device_destroy;
3107 rc = ena_handle_updated_queues(adapter, &get_feat_ctx);
3109 goto err_device_destroy;
3111 ENA_FLAG_CLEAR_ATOMIC(ENA_FLAG_ONGOING_RESET, adapter);
3112 /* Make sure we don't have a race with AENQ Links state handler */
3113 if (ENA_FLAG_ISSET(ENA_FLAG_LINK_UP, adapter))
3114 if_link_state_change(ifp, LINK_STATE_UP);
3116 rc = ena_enable_msix_and_set_admin_interrupts(adapter,
3117 adapter->num_queues);
3119 device_printf(dev, "Enable MSI-X failed\n");
3120 goto err_device_destroy;
3123 /* If the interface was up before the reset bring it up */
3124 if (ENA_FLAG_ISSET(ENA_FLAG_DEV_UP_BEFORE_RESET, adapter)) {
3125 rc = ena_up(adapter);
3127 device_printf(dev, "Failed to create I/O queues\n");
3128 goto err_disable_msix;
3132 /* Indicate that device is running again and ready to work */
3133 ENA_FLAG_SET_ATOMIC(ENA_FLAG_DEVICE_RUNNING, adapter);
3135 if (ENA_FLAG_ISSET(ENA_FLAG_DEV_UP_BEFORE_RESET, adapter)) {
3137 * As the AENQ handlers weren't executed during reset because
3138 * the flag ENA_FLAG_DEVICE_RUNNING was turned off, the
3139 * timestamp must be updated again That will prevent next reset
3140 * caused by missing keep alive.
3142 adapter->keep_alive_timestamp = getsbinuptime();
3143 callout_reset_sbt(&adapter->timer_service, SBT_1S, SBT_1S,
3144 ena_timer_service, (void *)adapter, 0);
3148 "Device reset completed successfully, Driver info: %s\n", ena_version);
3153 ena_free_mgmnt_irq(adapter);
3154 ena_disable_msix(adapter);
3156 ena_com_abort_admin_commands(ena_dev);
3157 ena_com_wait_for_abort_completion(ena_dev);
3158 ena_com_admin_destroy(ena_dev);
3159 ena_com_dev_reset(ena_dev, ENA_REGS_RESET_DRIVER_INVALID_STATE);
3160 ena_com_mmio_reg_read_request_destroy(ena_dev);
3162 ENA_FLAG_CLEAR_ATOMIC(ENA_FLAG_DEVICE_RUNNING, adapter);
3163 ENA_FLAG_CLEAR_ATOMIC(ENA_FLAG_ONGOING_RESET, adapter);
3164 device_printf(dev, "Reset attempt failed. Can not reset the device\n");
3170 ena_reset_task(void *arg, int pending)
3172 struct ena_adapter *adapter = (struct ena_adapter *)arg;
3174 if (unlikely(!ENA_FLAG_ISSET(ENA_FLAG_TRIGGER_RESET, adapter))) {
3175 device_printf(adapter->pdev,
3176 "device reset scheduled but trigger_reset is off\n");
3180 sx_xlock(&adapter->ioctl_sx);
3181 ena_destroy_device(adapter, false);
3182 ena_restore_device(adapter);
3183 sx_unlock(&adapter->ioctl_sx);
3187 * ena_attach - Device Initialization Routine
3188 * @pdev: device information struct
3190 * Returns 0 on success, otherwise on failure.
3192 * ena_attach initializes an adapter identified by a device structure.
3193 * The OS initialization, configuring of the adapter private structure,
3194 * and a hardware reset occur.
3197 ena_attach(device_t pdev)
3199 struct ena_com_dev_get_features_ctx get_feat_ctx;
3200 struct ena_llq_configurations llq_config;
3201 struct ena_calc_queue_size_ctx calc_queue_ctx = { 0 };
3202 static int version_printed;
3203 struct ena_adapter *adapter;
3204 struct ena_com_dev *ena_dev = NULL;
3205 const char *queue_type_str;
3209 adapter = device_get_softc(pdev);
3210 adapter->pdev = pdev;
3212 mtx_init(&adapter->global_mtx, "ENA global mtx", NULL, MTX_DEF);
3213 sx_init(&adapter->ioctl_sx, "ENA ioctl sx");
3215 /* Set up the timer service */
3216 callout_init_mtx(&adapter->timer_service, &adapter->global_mtx, 0);
3217 adapter->keep_alive_timeout = DEFAULT_KEEP_ALIVE_TO;
3218 adapter->missing_tx_timeout = DEFAULT_TX_CMP_TO;
3219 adapter->missing_tx_max_queues = DEFAULT_TX_MONITORED_QUEUES;
3220 adapter->missing_tx_threshold = DEFAULT_TX_CMP_THRESHOLD;
3222 if (version_printed++ == 0)
3223 device_printf(pdev, "%s\n", ena_version);
3225 /* Allocate memory for ena_dev structure */
3226 ena_dev = malloc(sizeof(struct ena_com_dev), M_DEVBUF,
3229 adapter->ena_dev = ena_dev;
3230 ena_dev->dmadev = pdev;
3232 rid = PCIR_BAR(ENA_REG_BAR);
3233 adapter->memory = NULL;
3234 adapter->registers = bus_alloc_resource_any(pdev, SYS_RES_MEMORY,
3236 if (unlikely(adapter->registers == NULL)) {
3238 "unable to allocate bus resource: registers!\n");
3243 ena_dev->bus = malloc(sizeof(struct ena_bus), M_DEVBUF,
3246 /* Store register resources */
3247 ((struct ena_bus*)(ena_dev->bus))->reg_bar_t =
3248 rman_get_bustag(adapter->registers);
3249 ((struct ena_bus*)(ena_dev->bus))->reg_bar_h =
3250 rman_get_bushandle(adapter->registers);
3252 if (unlikely(((struct ena_bus*)(ena_dev->bus))->reg_bar_h == 0)) {
3253 device_printf(pdev, "failed to pmap registers bar\n");
3258 ena_dev->tx_mem_queue_type = ENA_ADMIN_PLACEMENT_POLICY_HOST;
3260 /* Initially clear all the flags */
3261 ENA_FLAG_ZERO(adapter);
3263 /* Device initialization */
3264 rc = ena_device_init(adapter, pdev, &get_feat_ctx, &adapter->wd_active);
3265 if (unlikely(rc != 0)) {
3266 device_printf(pdev, "ENA device init failed! (err: %d)\n", rc);
3271 set_default_llq_configurations(&llq_config);
3273 rc = ena_set_queues_placement_policy(pdev, ena_dev, &get_feat_ctx.llq,
3275 if (unlikely(rc != 0)) {
3276 device_printf(pdev, "failed to set placement policy\n");
3280 if (ena_dev->tx_mem_queue_type == ENA_ADMIN_PLACEMENT_POLICY_HOST)
3281 queue_type_str = "Regular";
3283 queue_type_str = "Low Latency";
3284 device_printf(pdev, "Placement policy: %s\n", queue_type_str);
3286 adapter->keep_alive_timestamp = getsbinuptime();
3288 adapter->tx_offload_cap = get_feat_ctx.offload.tx;
3290 memcpy(adapter->mac_addr, get_feat_ctx.dev_attr.mac_addr,
3293 calc_queue_ctx.ena_dev = ena_dev;
3294 calc_queue_ctx.get_feat_ctx = &get_feat_ctx;
3295 calc_queue_ctx.pdev = pdev;
3297 /* calculate IO queue number to create */
3298 io_queue_num = ena_calc_io_queue_num(adapter, &get_feat_ctx);
3300 ENA_ASSERT(io_queue_num > 0, "Invalid queue number: %d\n",
3302 adapter->num_queues = io_queue_num;
3304 adapter->max_mtu = get_feat_ctx.dev_attr.max_mtu;
3305 // Set the requested Rx ring size
3306 adapter->rx_ring_size = ENA_DEFAULT_RING_SIZE;
3307 /* calculatre ring sizes */
3308 rc = ena_calc_queue_size(adapter, &calc_queue_ctx);
3309 if (unlikely((rc != 0) || (io_queue_num <= 0))) {
3314 adapter->reset_reason = ENA_REGS_RESET_NORMAL;
3316 adapter->tx_ring_size = calc_queue_ctx.tx_queue_size;
3317 adapter->rx_ring_size = calc_queue_ctx.rx_queue_size;
3319 adapter->max_tx_sgl_size = calc_queue_ctx.max_tx_sgl_size;
3320 adapter->max_rx_sgl_size = calc_queue_ctx.max_rx_sgl_size;
3322 adapter->buf_ring_size = ENA_DEFAULT_BUF_RING_SIZE;
3324 /* set up dma tags for rx and tx buffers */
3325 rc = ena_setup_tx_dma_tag(adapter);
3326 if (unlikely(rc != 0)) {
3327 device_printf(pdev, "Failed to create TX DMA tag\n");
3331 rc = ena_setup_rx_dma_tag(adapter);
3332 if (unlikely(rc != 0)) {
3333 device_printf(pdev, "Failed to create RX DMA tag\n");
3334 goto err_tx_tag_free;
3337 /* initialize rings basic information */
3339 "Creating %d io queues. Rx queue size: %d, Tx queue size: %d\n",
3341 calc_queue_ctx.rx_queue_size,
3342 calc_queue_ctx.tx_queue_size);
3343 ena_init_io_rings(adapter);
3345 rc = ena_enable_msix_and_set_admin_interrupts(adapter, io_queue_num);
3346 if (unlikely(rc != 0)) {
3348 "Failed to enable and set the admin interrupts\n");
3352 /* setup network interface */
3353 rc = ena_setup_ifnet(pdev, adapter, &get_feat_ctx);
3354 if (unlikely(rc != 0)) {
3355 device_printf(pdev, "Error with network interface setup\n");
3359 /* Initialize reset task queue */
3360 TASK_INIT(&adapter->reset_task, 0, ena_reset_task, adapter);
3361 adapter->reset_tq = taskqueue_create("ena_reset_enqueue",
3362 M_WAITOK | M_ZERO, taskqueue_thread_enqueue, &adapter->reset_tq);
3363 taskqueue_start_threads(&adapter->reset_tq, 1, PI_NET,
3364 "%s rstq", device_get_nameunit(adapter->pdev));
3366 /* Initialize statistics */
3367 ena_alloc_counters((counter_u64_t *)&adapter->dev_stats,
3368 sizeof(struct ena_stats_dev));
3369 ena_alloc_counters((counter_u64_t *)&adapter->hw_stats,
3370 sizeof(struct ena_hw_stats));
3371 ena_sysctl_add_nodes(adapter);
3374 rc = ena_netmap_attach(adapter);
3376 device_printf(pdev, "netmap attach failed: %d\n", rc);
3379 #endif /* DEV_NETMAP */
3381 /* Tell the stack that the interface is not active */
3382 if_setdrvflagbits(adapter->ifp, IFF_DRV_OACTIVE, IFF_DRV_RUNNING);
3383 ENA_FLAG_SET_ATOMIC(ENA_FLAG_DEVICE_RUNNING, adapter);
3389 ether_ifdetach(adapter->ifp);
3390 #endif /* DEV_NETMAP */
3392 ena_com_dev_reset(adapter->ena_dev, ENA_REGS_RESET_INIT_ERR);
3393 ena_free_mgmnt_irq(adapter);
3394 ena_disable_msix(adapter);
3396 ena_free_all_io_rings_resources(adapter);
3397 ena_free_rx_dma_tag(adapter);
3399 ena_free_tx_dma_tag(adapter);
3401 ena_com_admin_destroy(ena_dev);
3402 ena_com_delete_host_info(ena_dev);
3403 ena_com_mmio_reg_read_request_destroy(ena_dev);
3405 free(ena_dev->bus, M_DEVBUF);
3406 ena_free_pci_resources(adapter);
3408 free(ena_dev, M_DEVBUF);
3414 * ena_detach - Device Removal Routine
3415 * @pdev: device information struct
3417 * ena_detach is called by the device subsystem to alert the driver
3418 * that it should release a PCI device.
3421 ena_detach(device_t pdev)
3423 struct ena_adapter *adapter = device_get_softc(pdev);
3424 struct ena_com_dev *ena_dev = adapter->ena_dev;
3427 /* Make sure VLANS are not using driver */
3428 if (adapter->ifp->if_vlantrunk != NULL) {
3429 device_printf(adapter->pdev ,"VLAN is in use, detach first\n");
3433 ether_ifdetach(adapter->ifp);
3435 /* Free reset task and callout */
3436 callout_drain(&adapter->timer_service);
3437 while (taskqueue_cancel(adapter->reset_tq, &adapter->reset_task, NULL))
3438 taskqueue_drain(adapter->reset_tq, &adapter->reset_task);
3439 taskqueue_free(adapter->reset_tq);
3441 sx_xlock(&adapter->ioctl_sx);
3443 ena_destroy_device(adapter, true);
3444 sx_unlock(&adapter->ioctl_sx);
3447 netmap_detach(adapter->ifp);
3448 #endif /* DEV_NETMAP */
3450 ena_free_all_io_rings_resources(adapter);
3452 ena_free_counters((counter_u64_t *)&adapter->hw_stats,
3453 sizeof(struct ena_hw_stats));
3454 ena_free_counters((counter_u64_t *)&adapter->dev_stats,
3455 sizeof(struct ena_stats_dev));
3457 rc = ena_free_rx_dma_tag(adapter);
3458 if (unlikely(rc != 0))
3459 device_printf(adapter->pdev,
3460 "Unmapped RX DMA tag associations\n");
3462 rc = ena_free_tx_dma_tag(adapter);
3463 if (unlikely(rc != 0))
3464 device_printf(adapter->pdev,
3465 "Unmapped TX DMA tag associations\n");
3467 ena_free_irqs(adapter);
3469 ena_free_pci_resources(adapter);
3471 if (likely(ENA_FLAG_ISSET(ENA_FLAG_RSS_ACTIVE, adapter)))
3472 ena_com_rss_destroy(ena_dev);
3474 ena_com_delete_host_info(ena_dev);
3476 mtx_destroy(&adapter->global_mtx);
3477 sx_destroy(&adapter->ioctl_sx);
3479 if_free(adapter->ifp);
3481 if (ena_dev->bus != NULL)
3482 free(ena_dev->bus, M_DEVBUF);
3484 if (ena_dev != NULL)
3485 free(ena_dev, M_DEVBUF);
3487 return (bus_generic_detach(pdev));
3490 /******************************************************************************
3491 ******************************** AENQ Handlers *******************************
3492 *****************************************************************************/
3494 * ena_update_on_link_change:
3495 * Notify the network interface about the change in link status
3498 ena_update_on_link_change(void *adapter_data,
3499 struct ena_admin_aenq_entry *aenq_e)
3501 struct ena_adapter *adapter = (struct ena_adapter *)adapter_data;
3502 struct ena_admin_aenq_link_change_desc *aenq_desc;
3506 aenq_desc = (struct ena_admin_aenq_link_change_desc *)aenq_e;
3508 status = aenq_desc->flags &
3509 ENA_ADMIN_AENQ_LINK_CHANGE_DESC_LINK_STATUS_MASK;
3512 device_printf(adapter->pdev, "link is UP\n");
3513 ENA_FLAG_SET_ATOMIC(ENA_FLAG_LINK_UP, adapter);
3514 if (!ENA_FLAG_ISSET(ENA_FLAG_ONGOING_RESET, adapter))
3515 if_link_state_change(ifp, LINK_STATE_UP);
3517 device_printf(adapter->pdev, "link is DOWN\n");
3518 if_link_state_change(ifp, LINK_STATE_DOWN);
3519 ENA_FLAG_CLEAR_ATOMIC(ENA_FLAG_LINK_UP, adapter);
3523 static void ena_notification(void *adapter_data,
3524 struct ena_admin_aenq_entry *aenq_e)
3526 struct ena_adapter *adapter = (struct ena_adapter *)adapter_data;
3527 struct ena_admin_ena_hw_hints *hints;
3529 ENA_WARN(aenq_e->aenq_common_desc.group != ENA_ADMIN_NOTIFICATION,
3530 "Invalid group(%x) expected %x\n", aenq_e->aenq_common_desc.group,
3531 ENA_ADMIN_NOTIFICATION);
3533 switch (aenq_e->aenq_common_desc.syndrom) {
3534 case ENA_ADMIN_UPDATE_HINTS:
3536 (struct ena_admin_ena_hw_hints *)(&aenq_e->inline_data_w4);
3537 ena_update_hints(adapter, hints);
3540 device_printf(adapter->pdev,
3541 "Invalid aenq notification link state %d\n",
3542 aenq_e->aenq_common_desc.syndrom);
3547 * This handler will called for unknown event group or unimplemented handlers
3550 unimplemented_aenq_handler(void *adapter_data,
3551 struct ena_admin_aenq_entry *aenq_e)
3553 struct ena_adapter *adapter = (struct ena_adapter *)adapter_data;
3555 device_printf(adapter->pdev,
3556 "Unknown event was received or event with unimplemented handler\n");
3559 static struct ena_aenq_handlers aenq_handlers = {
3561 [ENA_ADMIN_LINK_CHANGE] = ena_update_on_link_change,
3562 [ENA_ADMIN_NOTIFICATION] = ena_notification,
3563 [ENA_ADMIN_KEEP_ALIVE] = ena_keep_alive_wd,
3565 .unimplemented_handler = unimplemented_aenq_handler
3568 /*********************************************************************
3569 * FreeBSD Device Interface Entry Points
3570 *********************************************************************/
3572 static device_method_t ena_methods[] = {
3573 /* Device interface */
3574 DEVMETHOD(device_probe, ena_probe),
3575 DEVMETHOD(device_attach, ena_attach),
3576 DEVMETHOD(device_detach, ena_detach),
3580 static driver_t ena_driver = {
3581 "ena", ena_methods, sizeof(struct ena_adapter),
3584 devclass_t ena_devclass;
3585 DRIVER_MODULE(ena, pci, ena_driver, ena_devclass, 0, 0);
3586 MODULE_PNP_INFO("U16:vendor;U16:device", pci, ena, ena_vendor_info_array,
3587 nitems(ena_vendor_info_array) - 1);
3588 MODULE_DEPEND(ena, pci, 1, 1, 1);
3589 MODULE_DEPEND(ena, ether, 1, 1, 1);
3591 MODULE_DEPEND(ena, netmap, 1, 1, 1);
3592 #endif /* DEV_NETMAP */
3594 /*********************************************************************/