Source-Changes-HG archive

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

[src/trunk]: src/sys/dev/pci Intermediate changes to make it fur...



details:   https://anonhg.NetBSD.org/src/rev/6f2dc468be8e
branches:  trunk
changeset: 319159:6f2dc468be8e
user:      jdolecek <jdolecek%NetBSD.org@localhost>
date:      Sat May 19 09:32:55 2018 +0000

description:
Intermediate changes to make it further into actually at least compile, not nearly yet
complete. Committed so that others can possibly pick it off, as discussed
on tech-userlevel@ with Martin

diffstat:

 sys/dev/pci/if_ena.c    |  475 ++++++++++++++++++++++-------------------------
 sys/dev/pci/if_enavar.h |  110 +++++-----
 2 files changed, 282 insertions(+), 303 deletions(-)

diffs (truncated from 1353 to 300 lines):

diff -r 0cdd3a50f589 -r 6f2dc468be8e sys/dev/pci/if_ena.c
--- a/sys/dev/pci/if_ena.c      Sat May 19 09:27:09 2018 +0000
+++ b/sys/dev/pci/if_ena.c      Sat May 19 09:32:55 2018 +0000
@@ -28,7 +28,10 @@
  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  */
 #include <sys/cdefs.h>
+#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.2 2018/05/19 09:32:55 jdolecek Exp $");
 
 #include <sys/param.h>
 #include <sys/systm.h>
@@ -39,56 +42,27 @@
 #include <sys/malloc.h>
 #include <sys/mbuf.h>
 #include <sys/module.h>
-#include <sys/rman.h>
-#include <sys/smp.h>
 #include <sys/socket.h>
 #include <sys/sockio.h>
 #include <sys/sysctl.h>
-#include <sys/taskqueue.h>
 #include <sys/time.h>
-#include <sys/eventhandler.h>
-
-#include <machine/bus.h>
-#include <machine/resource.h>
-#include <machine/in_cksum.h>
-
-#include <net/bpf.h>
-#include <net/ethernet.h>
-#include <net/if.h>
-#include <net/if_var.h>
-#include <net/if_arp.h>
-#include <net/if_dl.h>
-#include <net/if_media.h>
-#include <net/rss_config.h>
-#include <net/if_types.h>
-#include <net/if_vlan_var.h>
-
-#include <netinet/in_rss.h>
-#include <netinet/in_systm.h>
-#include <netinet/in.h>
-#include <netinet/if_ether.h>
-#include <netinet/ip.h>
-#include <netinet/ip6.h>
-#include <netinet/tcp.h>
-#include <netinet/udp.h>
-
-#include <dev/pci/pcivar.h>
-#include <dev/pci/pcireg.h>
-
-#include "ena.h"
-#include "ena_sysctl.h"
+#include <sys/workqueue.h>
+
+#include <sys/bus.h>
+
+#include <dev/pci/if_enavar.h>
 
 /*********************************************************
  *  Function prototypes
  *********************************************************/
-static int     ena_probe(device_t);
+static int     ena_probe(device_t, cfdata_t, void *);
 static void    ena_intr_msix_mgmnt(void *);
 static int     ena_allocate_pci_resources(struct ena_adapter*);
 static void    ena_free_pci_resources(struct ena_adapter *);
-static int     ena_change_mtu(if_t, int);
-static inline void ena_alloc_counters(counter_u64_t *, int);
-static inline void ena_free_counters(counter_u64_t *, int);
-static inline void ena_reset_counters(counter_u64_t *, int);
+static int     ena_change_mtu(struct ifnet *, int);
+static inline void ena_alloc_counters(struct evcnt *, int);
+static inline void ena_free_counters(struct evcnt *, int);
+static inline void ena_reset_counters(struct evcnt *, int);
 static void    ena_init_io_rings_common(struct ena_adapter *,
     struct ena_ring *, uint16_t);
 static void    ena_init_io_rings(struct ena_adapter *);
@@ -146,13 +120,15 @@
 static int     ena_up_complete(struct ena_adapter *);
 static int     ena_up(struct ena_adapter *);
 static void    ena_down(struct ena_adapter *);
-static uint64_t        ena_get_counter(if_t, ift_counter);
-static int     ena_media_change(if_t);
-static void    ena_media_status(if_t, struct ifmediareq *);
+#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 void    ena_init(void *);
-static int     ena_ioctl(if_t, u_long, caddr_t);
+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 *, if_t);
+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 *);
@@ -161,9 +137,9 @@
     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(if_t, struct mbuf *);
+static int     ena_mq_start(struct ifnet *, struct mbuf *);
 static void    ena_deferred_mq_start(void *, int);
-static void    ena_qflush(if_t);
+static void    ena_qflush(struct ifnet *);
 static int     ena_calc_io_queue_num(struct ena_adapter *,
     struct ena_com_dev_get_features_ctx *);
 static int     ena_calc_queue_size(struct ena_adapter *, uint16_t *,
@@ -171,7 +147,7 @@
 static int     ena_rss_init_default(struct ena_adapter *);
 static void    ena_rss_init_default_deferred(void *);
 static void    ena_config_host_info(struct ena_com_dev *);
-static int     ena_attach(device_t);
+static int     ena_attach(device_t parent, device_t self, void *aux);
 static int     ena_detach(device_t);
 static int     ena_device_init(struct ena_adapter *, device_t,
     struct ena_com_dev_get_features_ctx *, int *);
@@ -182,25 +158,32 @@
     struct ena_admin_aenq_entry *);
 static void    ena_timer_service(void *);
 
-static char ena_version[] = DEVICE_NAME DRV_MODULE_NAME " v" DRV_MODULE_VERSION;
-
+static const char ena_version[] =
+    DEVICE_NAME DRV_MODULE_NAME " v" DRV_MODULE_VERSION;
+
+#if 0
 static SYSCTL_NODE(_hw, OID_AUTO, ena, CTLFLAG_RD, 0, "ENA driver parameters");
+#endif
 
 /*
  * Tuneable number of buffers in the buf-ring (drbr)
  */
 static int ena_buf_ring_size = 4096;
+#if 0
 SYSCTL_INT(_hw_ena, OID_AUTO, buf_ring_size, CTLFLAG_RWTUN,
     &ena_buf_ring_size, 0, "Size of the bufring");
+#endif
 
 /*
  * Logging level for changing verbosity of the output
  */
 int ena_log_level = ENA_ALERT | ENA_WARNING;
+#if 0
 SYSCTL_INT(_hw_ena, OID_AUTO, log_level, CTLFLAG_RWTUN,
     &ena_log_level, 0, "Logging level indicating verbosity of the logs");
-
-static ena_vendor_info_t ena_vendor_info_array[] = {
+#endif
+
+static const ena_vendor_info_t ena_vendor_info_array[] = {
     { PCI_VENDOR_ID_AMAZON, PCI_DEV_ID_ENA_PF, 0},
     { PCI_VENDOR_ID_AMAZON, PCI_DEV_ID_ENA_LLQ_PF, 0},
     { PCI_VENDOR_ID_AMAZON, PCI_DEV_ID_ENA_VF, 0},
@@ -214,71 +197,67 @@
  */
 static struct ena_aenq_handlers aenq_handlers;
 
-void
-ena_dmamap_callback(void *arg, bus_dma_segment_t *segs, int nseg, int error)
-{
-       if (error != 0)
-               return;
-       *(bus_addr_t *) arg = segs[0].ds_addr;
-}
-
 int
 ena_dma_alloc(device_t dmadev, bus_size_t size,
     ena_mem_handle_t *dma , int mapflags)
 {
-       struct ena_adapter* adapter = device_get_softc(dmadev);
+       struct ena_adapter *adapter = device_private(dmadev);
        uint32_t maxsize;
-       uint64_t dma_space_addr;
-       int error;
+       bus_dma_segment_t seg;
+       int error, nsegs;
 
        maxsize = ((size - 1) / PAGE_SIZE + 1) * PAGE_SIZE;
 
+#if 0
+       /* XXX what is this needed for ? */
        dma_space_addr = ENA_DMA_BIT_MASK(adapter->dma_width);
        if (unlikely(dma_space_addr == 0))
                dma_space_addr = BUS_SPACE_MAXADDR;
-
-       error = bus_dma_tag_create(bus_get_dma_tag(dmadev), /* parent */
-           8, 0,             /* alignment, bounds              */
-           dma_space_addr,   /* lowaddr of exclusion window    */
-           BUS_SPACE_MAXADDR,/* highaddr of exclusion window   */
-           NULL, NULL,       /* filter, filterarg              */
-           maxsize,          /* maxsize                        */
-           1,                /* nsegments                      */
-           maxsize,          /* maxsegsize                     */
-           BUS_DMA_ALLOCNOW, /* flags                          */
-           NULL,             /* lockfunc                       */
-           NULL,             /* lockarg                        */
-           &dma->tag);
-       if (unlikely(error != 0)) {
-               ena_trace(ENA_ALERT, "bus_dma_tag_create failed: %d\n", error);
-               goto fail_tag;
+#endif
+
+       dma->tag = adapter->sc_dmat;
+
+        if (bus_dmamap_create(dma->tag, maxsize, 1, maxsize, 0,
+            BUS_DMA_WAITOK | BUS_DMA_ALLOCNOW, &dma->map) != 0) {
+               ena_trace(ENA_ALERT, "bus_dmamap_create(%ju) failed: %d\n",
+                   (uintmax_t)maxsize, error);
+                goto fail_create;
+       }
+
+       error = bus_dmamem_alloc(dma->tag, maxsize, 8, 0, &seg, 1, &nsegs,
+           BUS_DMA_ALLOCNOW);
+       if (error) {
+               ena_trace(ENA_ALERT, "bus_dmamem_alloc(%ju) failed: %d\n",
+                   (uintmax_t)maxsize, error);
+               goto fail_alloc;
        }
 
-       error = bus_dmamem_alloc(dma->tag, (void**) &dma->vaddr,
-           BUS_DMA_COHERENT | BUS_DMA_ZERO, &dma->map);
-       if (unlikely(error != 0)) {
-               ena_trace(ENA_ALERT, "bus_dmamem_alloc(%ju) failed: %d\n",
-                   (uintmax_t)size, error);
-               goto fail_map_create;
+       error = bus_dmamem_map(dma->tag, &seg, nsegs, maxsize,
+           &dma->vaddr, BUS_DMA_COHERENT);
+       if (error) {
+               ena_trace(ENA_ALERT, "bus_dmamem_map(%ju) failed: %d\n",
+                   (uintmax_t)maxsize, error);
+               goto fail_map;
        }
-
-       dma->paddr = 0;
+       memset(dma->vaddr, 0, maxsize);
+
        error = bus_dmamap_load(dma->tag, dma->map, dma->vaddr,
-           size, ena_dmamap_callback, &dma->paddr, mapflags);
-       if (unlikely((error != 0) || (dma->paddr == 0))) {
+           maxsize, NULL, mapflags);
+       if (error) {
                ena_trace(ENA_ALERT, ": bus_dmamap_load failed: %d\n", error);
-               goto fail_map_load;
+               goto fail_load;
        }
+       dma->paddr = dma->map->dm_segs[0].ds_addr;
 
        return (0);
 
-fail_map_load:
-       bus_dmamem_free(dma->tag, dma->vaddr, dma->map);
-fail_map_create:
-       bus_dma_tag_destroy(dma->tag);
-fail_tag:
-       dma->tag = NULL;
-
+fail_load:
+       bus_dmamem_unmap(dma->tag, dma->vaddr, maxsize);
+fail_map:
+       bus_dmamem_free(dma->tag, &seg, nsegs);
+fail_alloc:
+       bus_dmamap_destroy(adapter->sc_dmat, dma->map);
+fail_create:
        return (error);
 }
 
@@ -318,37 +297,25 @@
 }
 
 static int
-ena_probe(device_t dev)
+ena_probe(device_t parent, cfdata_t match, void *aux)
 {
-       ena_vendor_info_t *ent;
-       char            adapter_name[60];
-       uint16_t        pci_vendor_id = 0;
-       uint16_t        pci_device_id = 0;
-
-       pci_vendor_id = pci_get_vendor(dev);
-       pci_device_id = pci_get_device(dev);
-
-       ent = ena_vendor_info_array;
-       while (ent->vendor_id != 0) {
-               if ((pci_vendor_id == ent->vendor_id) &&
-                   (pci_device_id == ent->device_id)) {
-                       ena_trace(ENA_DBG, "vendor=%x device=%x ",
-                           pci_vendor_id, pci_device_id);
-
-                       sprintf(adapter_name, DEVICE_DESC);
-                       device_set_desc_copy(dev, adapter_name);
-                       return (BUS_PROBE_DEFAULT);
+       struct pci_attach_args *pa = aux;
+       const ena_vendor_info_t *ent;



Home | Main Index | Thread Index | Old Index