From owner-svn-soc-all@freebsd.org Tue May 31 10:26:42 2016 Return-Path: Delivered-To: svn-soc-all@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id 33513B54EE1 for ; Tue, 31 May 2016 10:26:42 +0000 (UTC) (envelope-from vincenzo@FreeBSD.org) Received: from socsvn.freebsd.org (socsvn.freebsd.org [IPv6:2001:1900:2254:206a::50:2]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mx1.freebsd.org (Postfix) with ESMTPS id 26E941648 for ; Tue, 31 May 2016 10:26:42 +0000 (UTC) (envelope-from vincenzo@FreeBSD.org) Received: from socsvn.freebsd.org ([127.0.1.124]) by socsvn.freebsd.org (8.15.2/8.15.2) with ESMTP id u4VAQgCG072839 for ; Tue, 31 May 2016 10:26:42 GMT (envelope-from vincenzo@FreeBSD.org) Received: (from www@localhost) by socsvn.freebsd.org (8.15.2/8.15.2/Submit) id u4VAQf3F072837 for svn-soc-all@FreeBSD.org; Tue, 31 May 2016 10:26:41 GMT (envelope-from vincenzo@FreeBSD.org) Date: Tue, 31 May 2016 10:26:41 GMT Message-Id: <201605311026.u4VAQf3F072837@socsvn.freebsd.org> X-Authentication-Warning: socsvn.freebsd.org: www set sender to vincenzo@FreeBSD.org using -f From: vincenzo@FreeBSD.org To: svn-soc-all@FreeBSD.org Subject: socsvn commit: r304244 - soc2016/vincenzo/head/sys/dev/netmap MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-soc-all@freebsd.org X-Mailman-Version: 2.1.22 Precedence: list List-Id: SVN commit messages for the entire Summer of Code repository List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 31 May 2016 10:26:42 -0000 Author: vincenzo Date: Tue May 31 10:26:41 2016 New Revision: 304244 URL: http://svnweb.FreeBSD.org/socsvn/?view=rev&rev=304244 Log: freebsd: ptnet: MSI-X interrupt setup Modified: soc2016/vincenzo/head/sys/dev/netmap/if_ptnet.c Modified: soc2016/vincenzo/head/sys/dev/netmap/if_ptnet.c ============================================================================== --- soc2016/vincenzo/head/sys/dev/netmap/if_ptnet.c Tue May 31 10:22:27 2016 (r304243) +++ soc2016/vincenzo/head/sys/dev/netmap/if_ptnet.c Tue May 31 10:26:41 2016 (r304244) @@ -93,9 +93,10 @@ struct ptnet_softc; struct ptnet_queue { - struct ptnet_softc *sc; - struct resource *irq; - int kring_id; + struct ptnet_softc *sc; + struct resource *irq; + void *cookie; + int kring_id; }; struct ptnet_softc { @@ -146,6 +147,9 @@ static int ptnet_irqs_init(struct ptnet_softc *sc); static void ptnet_irqs_fini(struct ptnet_softc *sc); +static void ptnet_tx_intr(void *opaque); +static void ptnet_rx_intr(void *opaque); + static device_method_t ptnet_methods[] = { DEVMETHOD(device_probe, ptnet_probe), DEVMETHOD(device_attach, ptnet_attach), @@ -391,27 +395,60 @@ { int rid = PCIR_BAR(PTNETMAP_MSIX_PCI_BAR); int nvecs = sc->num_rings; + unsigned int num_tx_rings; + device_t dev = sc->dev; int err = ENOSPC; + int i; + + num_tx_rings = bus_read_4(sc->iomem, PTNET_IO_NUM_TX_RINGS); - sc->msix_mem = bus_alloc_resource_any(sc->dev, SYS_RES_MEMORY, + sc->msix_mem = bus_alloc_resource_any(dev, SYS_RES_MEMORY, &rid, RF_ACTIVE); if (sc->msix_mem == NULL) { - device_printf(sc->dev, "Failed to allocate MSIX PCI BAR\n"); + device_printf(dev, "Failed to allocate MSIX PCI BAR\n"); return (ENXIO); } - if (pci_msix_count(sc->dev) < nvecs) { - device_printf(sc->dev, "Not enough MSI-X vectors\n"); + if (pci_msix_count(dev) < nvecs) { + device_printf(dev, "Not enough MSI-X vectors\n"); goto err_path; } - err = pci_alloc_msix(sc->dev, &nvecs); + err = pci_alloc_msix(dev, &nvecs); if (err) { - device_printf(sc->dev, "Failed to allocate MSI-X vectors\n"); + device_printf(dev, "Failed to allocate MSI-X vectors\n"); goto err_path; } - device_printf(sc->dev, "Allocated %d MSI-X vectors\n", nvecs); + for (i = 0; i < nvecs; i++) { + struct ptnet_queue *pq = sc->queues + i; + void (*handler)(void *) = ptnet_tx_intr; + int rid = i + i; + + if (i > num_tx_rings) { + handler = ptnet_rx_intr; + } + pq->irq = bus_alloc_resource_any(dev, SYS_RES_IRQ, &rid, + RF_ACTIVE); + if (pq->irq == NULL) { + device_printf(dev, "Failed to allocate interrupt" + "for queue #%d\n", i); + goto err_path; + } + + err = bus_setup_intr(dev, pq->irq, INTR_TYPE_NET | INTR_MPSAFE, + NULL, handler, pq, &pq->cookie); + if (err) { + device_printf(dev, "Failed to register intr handler " + "for queue #%d\n", i); + goto err_path; + } + + bus_describe_intr(dev, pq->irq, pq->cookie, "q%d", i); + //bus_bind_intr(); /* bind intr to CPU */ + } + + device_printf(dev, "Allocated %d MSI-X vectors\n", nvecs); return 0; err_path: @@ -422,15 +459,31 @@ static void ptnet_irqs_fini(struct ptnet_softc *sc) { - if (sc->msix_mem == NULL) { - return; + device_t dev = sc->dev; + int i; + + for (i = 0; i < sc->num_rings; i++) { + struct ptnet_queue *pq = sc->queues + i; + + if (pq->cookie) { + bus_teardown_intr(dev, pq->irq, pq->cookie); + pq->cookie = NULL; + } + + if (pq->irq) { + bus_release_resource(dev, SYS_RES_IRQ, i + i, pq->irq); + pq->irq = NULL; + } } - pci_release_msi(sc->dev); + if (sc->msix_mem) { + pci_release_msi(dev); - bus_release_resource(sc->dev, SYS_RES_MEMORY, - PCIR_BAR(PTNETMAP_MSIX_PCI_BAR), sc->msix_mem); - sc->msix_mem = NULL; + bus_release_resource(dev, SYS_RES_MEMORY, + PCIR_BAR(PTNETMAP_MSIX_PCI_BAR), + sc->msix_mem); + sc->msix_mem = NULL; + } } static void @@ -472,3 +525,13 @@ ifmr->ifm_active |= IFM_NONE; } } + +static void +ptnet_tx_intr(void *opaque) +{ +} + +static void +ptnet_rx_intr(void *opaque) +{ +}