Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/sys Various ena(4) bug fixes, from KUSABA Takeshi <t-kusaba@...



details:   https://anonhg.NetBSD.org/src/rev/d7cfb587111a
branches:  trunk
changeset: 984724:d7cfb587111a
user:      jmcneill <jmcneill%NetBSD.org@localhost>
date:      Mon Jul 19 21:16:33 2021 +0000

description:
Various ena(4) bug fixes, from KUSABA Takeshi <t-kusaba%iij.ad.jp@localhost>:

[PATCH 01/32] include device_xname for evcnt group.
[PATCH 02/32] fix improper NULL check.
[PATCH 03/32] add tx drop counter
[PATCH 04/32] remove unimplemented m_getjcl
[PATCH 05/32] make ENA_MEM_{ALLOC,FREE}_COHERENT symmetric.
[PATCH 06/32] disestablish the correct interrupt.
[PATCH 07/32] fix null check target.
[PATCH 08/32] use if_initialize() and if_register() instead of
[PATCH 09/32] free all pci-related resource.
[PATCH 10/32] no need to call if_free(), but to call if_detach
[PATCH 11/32] add some locking assertions.
[PATCH 12/32] use bus_size_t for bus_dma instead of uint32_t.
[PATCH 13/32] no need to pass interlock, ena_timer_service does not
[PATCH 14/32] enable ena(4) to down I/F
[PATCH 15/32] destroy I/O queues before disestablishing msix
[PATCH 16/32] count input/output packet stats.
[PATCH 17/32] fix missing #ifdef LRO, NetBSD does not support LRO
[PATCH 18/32] MP-ify TX, allocate mbuf queue to each TX ring.
[PATCH 19/32] down the interface first when to detach, to prevent
[PATCH 20/32] default link speed should be unknown.
[PATCH 21/32] protect ena_adapter members only by "global_mtx".
[PATCH 22/32] lower global_mtx interrupt level
[PATCH 23/32] reorder function declaration
[PATCH 24/32] add locking notes and some marking.
[PATCH 25/32] process RX in workqueue context, as same as FreeBSD
[PATCH 26/32] count rx_drops correctly.
[PATCH 27/32] no need to lock when attach/detach, down/up
[PATCH 28/32] fix memory leak.
[PATCH 29/32] add "stopping" flag to ena_ring.
[PATCH 30/32] make the flags atomic.
[PATCH 31/32] do not schedule timer when device is down.
[PATCH 32/32] no need to start timer if I/F is down.

diffstat:

 sys/dev/pci/if_ena.c                |  693 ++++++++++++++++++++---------------
 sys/dev/pci/if_enavar.h             |   70 +++-
 sys/external/bsd/ena-com/ena_plat.h |    6 +-
 3 files changed, 465 insertions(+), 304 deletions(-)

diffs (truncated from 1606 to 300 lines):

diff -r 1dd44bf04827 -r d7cfb587111a sys/dev/pci/if_ena.c
--- a/sys/dev/pci/if_ena.c      Mon Jul 19 21:04:39 2021 +0000
+++ b/sys/dev/pci/if_ena.c      Mon Jul 19 21:16:33 2021 +0000
@@ -36,7 +36,7 @@
 #if 0
 __FBSDID("$FreeBSD: head/sys/dev/ena/ena.c 333456 2018-05-10 09:37:54Z mw $");
 #endif
-__KERNEL_RCSID(0, "$NetBSD: if_ena.c,v 1.28 2021/07/01 17:22:10 jmcneill Exp $");
+__KERNEL_RCSID(0, "$NetBSD: if_ena.c,v 1.29 2021/07/19 21:16:33 jmcneill Exp $");
 
 #include <sys/param.h>
 #include <sys/systm.h>
@@ -72,112 +72,154 @@
 /*********************************************************
  *  Function prototypes
  *********************************************************/
+/* cfattach interface functions */
 static int     ena_probe(device_t, cfdata_t, void *);
-static int     ena_intr_msix_mgmnt(void *);
+static void    ena_attach(device_t, device_t, void *);
+static int     ena_detach(device_t, int);
+
+/* ifnet interface functions */
+static int     ena_init(struct ifnet *);
+static void    ena_stop(struct ifnet *, int);
+static int     ena_ioctl(struct ifnet *, u_long, void *);
+static int     ena_media_change(struct ifnet *);
+static void    ena_media_status(struct ifnet *, struct ifmediareq *);
+static int     ena_mq_start(struct ifnet *, struct mbuf *);
+
+/* attach or detach */
+static int     ena_calc_io_queue_num(struct pci_attach_args *,
+                   struct ena_adapter *,
+                   struct ena_com_dev_get_features_ctx *);
+static int     ena_calc_queue_size(struct ena_adapter *, uint16_t *,
+                   uint16_t *, struct ena_com_dev_get_features_ctx *);
+
 static int     ena_allocate_pci_resources(struct pci_attach_args *,
                    struct ena_adapter *);
 static void    ena_free_pci_resources(struct ena_adapter *);
-static int     ena_change_mtu(struct ifnet *, int);
+static void    ena_free_irqs(struct ena_adapter*);
+
 static void    ena_init_io_rings_common(struct ena_adapter *,
-    struct ena_ring *, uint16_t);
+                                            struct ena_ring *, uint16_t);
 static void    ena_init_io_rings(struct ena_adapter *);
 static void    ena_free_io_ring_resources(struct ena_adapter *, unsigned int);
 static void    ena_free_all_io_rings_resources(struct ena_adapter *);
+
+static int     ena_get_dev_offloads(struct ena_com_dev_get_features_ctx *);
+static int     ena_setup_ifnet(device_t, struct ena_adapter *,
+                   struct ena_com_dev_get_features_ctx *);
+
+static inline void     ena_alloc_counters_rx(struct ena_adapter *,
+                           struct ena_stats_rx *, int);
+static inline void     ena_alloc_counters_tx(struct ena_adapter *,
+                           struct ena_stats_tx *, int);
+static inline void     ena_alloc_counters_dev(struct ena_adapter *,
+                           struct ena_stats_dev *, int);
+static inline void     ena_alloc_counters_hwstats(struct ena_adapter *,
+                           struct ena_hw_stats *, int);
+static inline void     ena_free_counters(struct evcnt *, int, int);
+
+/* attach or detach or ena_reset_task() */
+static void    ena_reset_task(struct work *, void *);
+
+static void    ena_free_mgmnt_irq(struct ena_adapter *);
+static void    ena_disable_msix(struct ena_adapter *);
+static void    ena_config_host_info(struct ena_com_dev *);
+static int     ena_device_init(struct ena_adapter *, device_t,
+                   struct ena_com_dev_get_features_ctx *, int *);
+static int     ena_enable_msix_and_set_admin_interrupts(struct ena_adapter *,
+                   int);
+static int     ena_enable_msix(struct ena_adapter *);
+static int     ena_request_mgmnt_irq(struct ena_adapter *);
+
+/* I/F up or down */
+static int     ena_up_complete(struct ena_adapter *);
+static int     ena_up(struct ena_adapter *);
+static void    ena_down(struct ena_adapter *);
+static void    ena_set_stopping_flag(struct ena_adapter *, bool);
+
+static int     ena_setup_rx_resources(struct ena_adapter *, unsigned int);
+static int     ena_setup_all_rx_resources(struct ena_adapter *);
+static void    ena_free_rx_resources(struct ena_adapter *, unsigned int);
+static void    ena_free_all_rx_resources(struct ena_adapter *);
+static void    ena_free_rx_mbuf(struct ena_adapter *, struct ena_ring *,
+                   struct ena_rx_buffer *);
+static void    ena_free_rx_bufs(struct ena_adapter *, unsigned int);
+static void    ena_free_all_rx_bufs(struct ena_adapter *);
+
+static int     ena_setup_tx_resources(struct ena_adapter *, int);
+static int     ena_setup_all_tx_resources(struct ena_adapter *);
+static void    ena_free_tx_resources(struct ena_adapter *, int);
+static void    ena_free_all_tx_resources(struct ena_adapter *);
+static void    ena_free_tx_bufs(struct ena_adapter *, unsigned int);
+static void    ena_free_all_tx_bufs(struct ena_adapter *);
+
+static int     ena_request_io_irq(struct ena_adapter *);
+static void    ena_free_io_irq(struct ena_adapter *);
+static int     ena_create_io_queues(struct ena_adapter *);
+static void    ena_destroy_all_tx_queues(struct ena_adapter *);
+static void    ena_destroy_all_rx_queues(struct ena_adapter *);
+static void    ena_destroy_all_io_queues(struct ena_adapter *);
+
+static void    ena_update_hwassist(struct ena_adapter *);
+static int     ena_rss_configure(struct ena_adapter *);
+static void    ena_unmask_all_io_irqs(struct ena_adapter *);
+static inline void     ena_reset_counters(struct evcnt *, int, int);
+
+/* other hardware interrupt, workqueue, softint context */
+static int     ena_intr_msix_mgmnt(void *);
+static void    ena_update_on_link_change(void *,
+                   struct ena_admin_aenq_entry *);
+static void    ena_keep_alive_wd(void *,
+                   struct ena_admin_aenq_entry *);
+static void    unimplemented_aenq_handler(void *,
+                   struct ena_admin_aenq_entry *);
+
+static int     ena_handle_msix(void *);
+static void    ena_cleanup(struct work *, void *);
+static inline int      validate_rx_req_id(struct ena_ring *, uint16_t);
+static inline int      ena_alloc_rx_mbuf(struct ena_adapter *,
+                           struct ena_ring *, struct ena_rx_buffer *);
+static int     ena_refill_rx_bufs(struct ena_ring *, uint32_t);
+static void    ena_refill_all_rx_bufs(struct ena_adapter *);
+static int     ena_rx_cleanup(struct ena_ring *);
+static struct mbuf*    ena_rx_mbuf(struct ena_ring *,
+                           struct ena_com_rx_buf_info *,
+                           struct ena_com_rx_ctx *, uint16_t *);
+static inline void     ena_rx_checksum(struct ena_ring *,
+                           struct ena_com_rx_ctx *, struct mbuf *);
+
+static int     ena_check_and_collapse_mbuf(struct ena_ring *tx_ring,
+                   struct mbuf **mbuf);
+static int     ena_xmit_mbuf(struct ena_ring *, struct mbuf **);
+static void    ena_start_xmit(struct ena_ring *);
+static void    ena_deferred_mq_start(struct work *, void *);
+static int     ena_tx_cleanup(struct ena_ring *);
+static void    ena_tx_csum(struct ena_com_tx_ctx *, struct mbuf *);
+static inline int      validate_tx_req_id(struct ena_ring *, uint16_t);
+
+/* other */
+static int     ena_change_mtu(struct ifnet *, int);
+
+static void    ena_timer_service(void *);
+static void    check_for_missing_keep_alive(struct ena_adapter *);
+static void    check_for_admin_com_state(struct ena_adapter *);
+static int     check_missing_comp_in_queue(struct ena_adapter *, struct ena_ring*);
+static void    check_for_missing_tx_completions(struct ena_adapter *);
+static void    check_for_empty_rx_ring(struct ena_adapter *);
+static void    ena_update_host_info(struct ena_admin_host_info *,
+                   struct ifnet *);
+
 #if 0
 static int     ena_setup_tx_dma_tag(struct ena_adapter *);
 static int     ena_free_tx_dma_tag(struct ena_adapter *);
 static int     ena_setup_rx_dma_tag(struct ena_adapter *);
 static int     ena_free_rx_dma_tag(struct ena_adapter *);
-#endif
-static int     ena_setup_tx_resources(struct ena_adapter *, int);
-static void    ena_free_tx_resources(struct ena_adapter *, int);
-static int     ena_setup_all_tx_resources(struct ena_adapter *);
-static void    ena_free_all_tx_resources(struct ena_adapter *);
-static inline int validate_rx_req_id(struct ena_ring *, uint16_t);
-static int     ena_setup_rx_resources(struct ena_adapter *, unsigned int);
-static void    ena_free_rx_resources(struct ena_adapter *, unsigned int);
-static int     ena_setup_all_rx_resources(struct ena_adapter *);
-static void    ena_free_all_rx_resources(struct ena_adapter *);
-static inline int ena_alloc_rx_mbuf(struct ena_adapter *, struct ena_ring *,
-    struct ena_rx_buffer *);
-static void    ena_free_rx_mbuf(struct ena_adapter *, struct ena_ring *,
-    struct ena_rx_buffer *);
-static int     ena_refill_rx_bufs(struct ena_ring *, uint32_t);
-static void    ena_free_rx_bufs(struct ena_adapter *, unsigned int);
-static void    ena_refill_all_rx_bufs(struct ena_adapter *);
-static void    ena_free_all_rx_bufs(struct ena_adapter *);
-static void    ena_free_tx_bufs(struct ena_adapter *, unsigned int);
-static void    ena_free_all_tx_bufs(struct ena_adapter *);
-static void    ena_destroy_all_tx_queues(struct ena_adapter *);
-static void    ena_destroy_all_rx_queues(struct ena_adapter *);
-static void    ena_destroy_all_io_queues(struct ena_adapter *);
-static int     ena_create_io_queues(struct ena_adapter *);
-static int     ena_tx_cleanup(struct ena_ring *);
-static void    ena_deferred_rx_cleanup(struct work *, void *);
-static int     ena_rx_cleanup(struct ena_ring *);
-static inline int validate_tx_req_id(struct ena_ring *, uint16_t);
-#if 0
 static void    ena_rx_hash_mbuf(struct ena_ring *, struct ena_com_rx_ctx *,
     struct mbuf *);
-#endif
-static struct mbuf* ena_rx_mbuf(struct ena_ring *, struct ena_com_rx_buf_info *,
-    struct ena_com_rx_ctx *, uint16_t *);
-static inline void ena_rx_checksum(struct ena_ring *, struct ena_com_rx_ctx *,
-    struct mbuf *);
-static int     ena_handle_msix(void *);
-static int     ena_enable_msix(struct ena_adapter *);
-static int     ena_request_mgmnt_irq(struct ena_adapter *);
-static int     ena_request_io_irq(struct ena_adapter *);
-static void    ena_free_mgmnt_irq(struct ena_adapter *);
-static void    ena_free_io_irq(struct ena_adapter *);
-static void    ena_free_irqs(struct ena_adapter*);
-static void    ena_disable_msix(struct ena_adapter *);
-static void    ena_unmask_all_io_irqs(struct ena_adapter *);
-static int     ena_rss_configure(struct ena_adapter *);
-static int     ena_up_complete(struct ena_adapter *);
-static int     ena_up(struct ena_adapter *);
-static void    ena_down(struct ena_adapter *);
-#if 0
 static uint64_t        ena_get_counter(struct ifnet *, ift_counter);
-#endif
-static int     ena_media_change(struct ifnet *);
-static void    ena_media_status(struct ifnet *, struct ifmediareq *);
-static int     ena_init(struct ifnet *);
-static int     ena_ioctl(struct ifnet *, u_long, void *);
-static int     ena_get_dev_offloads(struct ena_com_dev_get_features_ctx *);
-static void    ena_update_host_info(struct ena_admin_host_info *, struct ifnet *);
-static void    ena_update_hwassist(struct ena_adapter *);
-static int     ena_setup_ifnet(device_t, struct ena_adapter *,
-    struct ena_com_dev_get_features_ctx *);
-static void    ena_tx_csum(struct ena_com_tx_ctx *, struct mbuf *);
-static int     ena_check_and_collapse_mbuf(struct ena_ring *tx_ring,
-    struct mbuf **mbuf);
-static int     ena_xmit_mbuf(struct ena_ring *, struct mbuf **);
-static void    ena_start_xmit(struct ena_ring *);
-static int     ena_mq_start(struct ifnet *, struct mbuf *);
-static void    ena_deferred_mq_start(struct work *, void *);
-#if 0
 static void    ena_qflush(struct ifnet *);
-#endif
-static int     ena_calc_io_queue_num(struct pci_attach_args *,
-    struct ena_adapter *, struct ena_com_dev_get_features_ctx *);
-static int     ena_calc_queue_size(struct ena_adapter *, uint16_t *,
-    uint16_t *, struct ena_com_dev_get_features_ctx *);
-#if 0
 static int     ena_rss_init_default(struct ena_adapter *);
 static void    ena_rss_init_default_deferred(void *);
 #endif
-static void    ena_config_host_info(struct ena_com_dev *);
-static void    ena_attach(device_t, device_t, void *);
-static int     ena_detach(device_t, int);
-static int     ena_device_init(struct ena_adapter *, device_t,
-    struct ena_com_dev_get_features_ctx *, int *);
-static int     ena_enable_msix_and_set_admin_interrupts(struct ena_adapter *,
-    int);
-static void ena_update_on_link_change(void *, struct ena_admin_aenq_entry *);
-static void    unimplemented_aenq_handler(void *,
-    struct ena_admin_aenq_entry *);
-static void    ena_timer_service(void *);
 
 static const char ena_version[] =
     DEVICE_NAME DRV_MODULE_NAME " v" DRV_MODULE_VERSION;
@@ -223,9 +265,8 @@
     ena_mem_handle_t *dma , int mapflags)
 {
        struct ena_adapter *adapter = device_private(dmadev);
-       uint32_t maxsize;
-       bus_dma_segment_t seg;
-       int error, nsegs;
+       bus_size_t maxsize;
+       int error;
 
        maxsize = ((size - 1) / PAGE_SIZE + 1) * PAGE_SIZE;
 
@@ -245,7 +286,7 @@
                 goto fail_create;
        }
 
-       error = bus_dmamem_alloc(dma->tag, maxsize, 8, 0, &seg, 1, &nsegs,
+       error = bus_dmamem_alloc(dma->tag, maxsize, 8, 0, &dma->seg, 1, &dma->nseg,
            BUS_DMA_ALLOCNOW);
        if (error) {
                ena_trace(ENA_ALERT, "bus_dmamem_alloc(%ju) failed: %d\n",
@@ -253,7 +294,7 @@
                goto fail_alloc;
        }
 
-       error = bus_dmamem_map(dma->tag, &seg, nsegs, maxsize,
+       error = bus_dmamem_map(dma->tag, &dma->seg, dma->nseg, maxsize,
            &dma->vaddr, BUS_DMA_COHERENT);
        if (error) {
                ena_trace(ENA_ALERT, "bus_dmamem_map(%ju) failed: %d\n",
@@ -275,7 +316,7 @@
 fail_load:
        bus_dmamem_unmap(dma->tag, dma->vaddr, maxsize);
 fail_map:
-       bus_dmamem_free(dma->tag, &seg, nsegs);
+       bus_dmamem_free(dma->tag, &dma->seg, dma->nseg);
 fail_alloc:
        bus_dmamap_destroy(adapter->sc_dmat, dma->map);
 fail_create:
@@ -287,8 +328,6 @@
     struct ena_adapter *adapter)
 {
        pcireg_t memtype, reg;
-       bus_addr_t memaddr;
-       bus_size_t mapsize;
        int flags, error;
        int msixoff;



Home | Main Index | Thread Index | Old Index