From owner-svn-soc-all@freebsd.org Sun May 8 14:36:47 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 3B017B32174 for ; Sun, 8 May 2016 14:36:47 +0000 (UTC) (envelope-from iateaca@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 21A5F1941 for ; Sun, 8 May 2016 14:36:47 +0000 (UTC) (envelope-from iateaca@FreeBSD.org) Received: from socsvn.freebsd.org ([127.0.1.124]) by socsvn.freebsd.org (8.15.2/8.15.2) with ESMTP id u48Ealgp014774 for ; Sun, 8 May 2016 14:36:47 GMT (envelope-from iateaca@FreeBSD.org) Received: (from www@localhost) by socsvn.freebsd.org (8.15.2/8.15.2/Submit) id u48EakAC014748 for svn-soc-all@FreeBSD.org; Sun, 8 May 2016 14:36:46 GMT (envelope-from iateaca@FreeBSD.org) Date: Sun, 8 May 2016 14:36:46 GMT Message-Id: <201605081436.u48EakAC014748@socsvn.freebsd.org> X-Authentication-Warning: socsvn.freebsd.org: www set sender to iateaca@FreeBSD.org using -f From: iateaca@FreeBSD.org To: svn-soc-all@FreeBSD.org Subject: socsvn commit: r302382 - soc2015/iateaca/bhyve-ne2000-head/usr.sbin/bhyve 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: Sun, 08 May 2016 14:36:47 -0000 Author: iateaca Date: Sun May 8 14:36:45 2016 New Revision: 302382 URL: http://svnweb.FreeBSD.org/socsvn/?view=rev&rev=302382 Log: add HDA Controller Register Set offsets Modified: soc2015/iateaca/bhyve-ne2000-head/usr.sbin/bhyve/pci_hda.c Modified: soc2015/iateaca/bhyve-ne2000-head/usr.sbin/bhyve/pci_hda.c ============================================================================== --- soc2015/iateaca/bhyve-ne2000-head/usr.sbin/bhyve/pci_hda.c Sun May 8 09:30:36 2016 (r302381) +++ soc2015/iateaca/bhyve-ne2000-head/usr.sbin/bhyve/pci_hda.c Sun May 8 14:36:45 2016 (r302382) @@ -24,6 +24,56 @@ #define HDA_INTEL_82801G 0x27d8 /* + * HDA Controller Register Offsets + */ +#define HDAC_GCAP 0x00 /* 2 - Global Capabilities*/ +#define HDAC_VMIN 0x02 /* 1 - Minor Version */ +#define HDAC_VMAJ 0x03 /* 1 - Major Version */ +#define HDAC_OUTPAY 0x04 /* 2 - Output Payload Capability */ +#define HDAC_INPAY 0x06 /* 2 - Input Payload Capability */ +#define HDAC_GCTL 0x08 /* 4 - Global Control */ +#define HDAC_WAKEEN 0x0c /* 2 - Wake Enable */ +#define HDAC_STATESTS 0x0e /* 2 - State Change Status */ +#define HDAC_GSTS 0x10 /* 2 - Global Status */ +#define HDAC_OUTSTRMPAY 0x18 /* 2 - Output Stream Payload Capability */ +#define HDAC_INSTRMPAY 0x1a /* 2 - Input Stream Payload Capability */ +#define HDAC_INTCTL 0x20 /* 4 - Interrupt Control */ +#define HDAC_INTSTS 0x24 /* 4 - Interrupt Status */ +#define HDAC_WALCLK 0x30 /* 4 - Wall Clock Counter */ +#define HDAC_SSYNC 0x38 /* 4 - Stream Synchronization */ +#define HDAC_CORBLBASE 0x40 /* 4 - CORB Lower Base Address */ +#define HDAC_CORBUBASE 0x44 /* 4 - CORB Upper Base Address */ +#define HDAC_CORBWP 0x48 /* 2 - CORB Write Pointer */ +#define HDAC_CORBRP 0x4a /* 2 - CORB Read Pointer */ +#define HDAC_CORBCTL 0x4c /* 1 - CORB Control */ +#define HDAC_CORBSTS 0x4d /* 1 - CORB Status */ +#define HDAC_CORBSIZE 0x4e /* 1 - CORB Size */ +#define HDAC_RIRBLBASE 0x50 /* 4 - RIRB Lower Base Address */ +#define HDAC_RIRBUBASE 0x54 /* 4 - RIRB Upper Base Address */ +#define HDAC_RIRBWP 0x58 /* 2 - RIRB Write Pointer */ +#define HDAC_RINTCNT 0x5a /* 2 - Response Interrupt Count */ +#define HDAC_RIRBCTL 0x5c /* 1 - RIRB Control */ +#define HDAC_RIRBSTS 0x5d /* 1 - RIRB Status */ +#define HDAC_RIRBSIZE 0x5e /* 1 - RIRB Size */ +#define HDAC_ICOI 0x60 /* 4 - Immediate Command Output Interface */ +#define HDAC_ICII 0x64 /* 4 - Immediate Command Input Interface */ +#define HDAC_ICIS 0x68 /* 2 - Immediate Command Status */ +#define HDAC_DPIBLBASE 0x70 /* 4 - DMA Position Buffer Lower Base */ +#define HDAC_DPIBUBASE 0x74 /* 4 - DMA Position Buffer Upper Base */ +#define HDAC_SDCTL0 0x80 /* 3 - Stream Descriptor Control */ +#define HDAC_SDCTL1 0x81 /* 3 - Stream Descriptor Control */ +#define HDAC_SDCTL2 0x82 /* 3 - Stream Descriptor Control */ +#define HDAC_SDSTS 0x83 /* 1 - Stream Descriptor Status */ +#define HDAC_SDLPIB 0x84 /* 4 - Link Position in Buffer */ +#define HDAC_SDCBL 0x88 /* 4 - Cyclic Buffer Length */ +#define HDAC_SDLVI 0x8C /* 2 - Last Valid Index */ +#define HDAC_SDFIFOS 0x90 /* 2 - FIFOS */ +#define HDAC_SDFMT 0x92 /* 2 - fmt */ +#define HDAC_SDBDPL 0x98 /* 4 - Buffer Descriptor Pointer Lower Base */ +#define HDAC_SDBDPU 0x9C /* 4 - Buffer Descriptor Pointer Upper Base */ + + +/* * HDA data structures */ From owner-svn-soc-all@freebsd.org Sun May 8 14:54:19 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 33EBBB326C1 for ; Sun, 8 May 2016 14:54:19 +0000 (UTC) (envelope-from iateaca@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 0D7961148 for ; Sun, 8 May 2016 14:54:19 +0000 (UTC) (envelope-from iateaca@FreeBSD.org) Received: from socsvn.freebsd.org ([127.0.1.124]) by socsvn.freebsd.org (8.15.2/8.15.2) with ESMTP id u48EsIsj055512 for ; Sun, 8 May 2016 14:54:18 GMT (envelope-from iateaca@FreeBSD.org) Received: (from www@localhost) by socsvn.freebsd.org (8.15.2/8.15.2/Submit) id u48EsIZ7055501 for svn-soc-all@FreeBSD.org; Sun, 8 May 2016 14:54:18 GMT (envelope-from iateaca@FreeBSD.org) Date: Sun, 8 May 2016 14:54:18 GMT Message-Id: <201605081454.u48EsIZ7055501@socsvn.freebsd.org> X-Authentication-Warning: socsvn.freebsd.org: www set sender to iateaca@FreeBSD.org using -f From: iateaca@FreeBSD.org To: svn-soc-all@FreeBSD.org Subject: socsvn commit: r302383 - soc2015/iateaca/bhyve-ne2000-head/usr.sbin/bhyve 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: Sun, 08 May 2016 14:54:19 -0000 Author: iateaca Date: Sun May 8 14:54:17 2016 New Revision: 302383 URL: http://svnweb.FreeBSD.org/socsvn/?view=rev&rev=302383 Log: add HDA controller stream in and out registers Modified: soc2015/iateaca/bhyve-ne2000-head/usr.sbin/bhyve/pci_hda.c Modified: soc2015/iateaca/bhyve-ne2000-head/usr.sbin/bhyve/pci_hda.c ============================================================================== --- soc2015/iateaca/bhyve-ne2000-head/usr.sbin/bhyve/pci_hda.c Sun May 8 14:36:45 2016 (r302382) +++ soc2015/iateaca/bhyve-ne2000-head/usr.sbin/bhyve/pci_hda.c Sun May 8 14:54:17 2016 (r302383) @@ -72,6 +72,28 @@ #define HDAC_SDBDPL 0x98 /* 4 - Buffer Descriptor Pointer Lower Base */ #define HDAC_SDBDPU 0x9C /* 4 - Buffer Descriptor Pointer Upper Base */ +#define _HDAC_ISDOFFSET(n, iss, oss) (0x80 + ((n) * 0x20)) +#define _HDAC_ISDCTL(n, iss, oss) (0x00 + _HDAC_ISDOFFSET(n, iss, oss)) +#define _HDAC_ISDSTS(n, iss, oss) (0x03 + _HDAC_ISDOFFSET(n, iss, oss)) +#define _HDAC_ISDPICB(n, iss, oss) (0x04 + _HDAC_ISDOFFSET(n, iss, oss)) +#define _HDAC_ISDCBL(n, iss, oss) (0x08 + _HDAC_ISDOFFSET(n, iss, oss)) +#define _HDAC_ISDLVI(n, iss, oss) (0x0c + _HDAC_ISDOFFSET(n, iss, oss)) +#define _HDAC_ISDFIFOD(n, iss, oss) (0x10 + _HDAC_ISDOFFSET(n, iss, oss)) +#define _HDAC_ISDFMT(n, iss, oss) (0x12 + _HDAC_ISDOFFSET(n, iss, oss)) +#define _HDAC_ISDBDPL(n, iss, oss) (0x18 + _HDAC_ISDOFFSET(n, iss, oss)) +#define _HDAC_ISDBDPU(n, iss, oss) (0x1c + _HDAC_ISDOFFSET(n, iss, oss)) + +#define _HDAC_OSDOFFSET(n, iss, oss) (0x80 + ((iss) * 0x20) + ((n) * 0x20)) +#define _HDAC_OSDCTL(n, iss, oss) (0x00 + _HDAC_OSDOFFSET(n, iss, oss)) +#define _HDAC_OSDSTS(n, iss, oss) (0x03 + _HDAC_OSDOFFSET(n, iss, oss)) +#define _HDAC_OSDPICB(n, iss, oss) (0x04 + _HDAC_OSDOFFSET(n, iss, oss)) +#define _HDAC_OSDCBL(n, iss, oss) (0x08 + _HDAC_OSDOFFSET(n, iss, oss)) +#define _HDAC_OSDLVI(n, iss, oss) (0x0c + _HDAC_OSDOFFSET(n, iss, oss)) +#define _HDAC_OSDFIFOD(n, iss, oss) (0x10 + _HDAC_OSDOFFSET(n, iss, oss)) +#define _HDAC_OSDFMT(n, iss, oss) (0x12 + _HDAC_OSDOFFSET(n, iss, oss)) +#define _HDAC_OSDBDPL(n, iss, oss) (0x18 + _HDAC_OSDOFFSET(n, iss, oss)) +#define _HDAC_OSDBDPU(n, iss, oss) (0x1c + _HDAC_OSDOFFSET(n, iss, oss)) + /* * HDA data structures From owner-svn-soc-all@freebsd.org Sun May 8 20:29:21 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 CB5F3B33342 for ; Sun, 8 May 2016 20:29:21 +0000 (UTC) (envelope-from iateaca@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 B01C2131F for ; Sun, 8 May 2016 20:29:21 +0000 (UTC) (envelope-from iateaca@FreeBSD.org) Received: from socsvn.freebsd.org ([127.0.1.124]) by socsvn.freebsd.org (8.15.2/8.15.2) with ESMTP id u48KTLac097647 for ; Sun, 8 May 2016 20:29:21 GMT (envelope-from iateaca@FreeBSD.org) Received: (from www@localhost) by socsvn.freebsd.org (8.15.2/8.15.2/Submit) id u48KTL1d097623 for svn-soc-all@FreeBSD.org; Sun, 8 May 2016 20:29:21 GMT (envelope-from iateaca@FreeBSD.org) Date: Sun, 8 May 2016 20:29:21 GMT Message-Id: <201605082029.u48KTL1d097623@socsvn.freebsd.org> X-Authentication-Warning: socsvn.freebsd.org: www set sender to iateaca@FreeBSD.org using -f From: iateaca@FreeBSD.org To: svn-soc-all@FreeBSD.org Subject: socsvn commit: r302391 - soc2015/iateaca/bhyve-ne2000-head/usr.sbin/bhyve 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: Sun, 08 May 2016 20:29:21 -0000 Author: iateaca Date: Sun May 8 20:29:20 2016 New Revision: 302391 URL: http://svnweb.FreeBSD.org/socsvn/?view=rev&rev=302391 Log: design the layout of registers, implement the read and write access to the registers Modified: soc2015/iateaca/bhyve-ne2000-head/usr.sbin/bhyve/pci_hda.c Modified: soc2015/iateaca/bhyve-ne2000-head/usr.sbin/bhyve/pci_hda.c ============================================================================== --- soc2015/iateaca/bhyve-ne2000-head/usr.sbin/bhyve/pci_hda.c Sun May 8 19:14:05 2016 (r302390) +++ soc2015/iateaca/bhyve-ne2000-head/usr.sbin/bhyve/pci_hda.c Sun May 8 20:29:20 2016 (r302391) @@ -1,6 +1,7 @@ #include #include +#include #include "pci_emul.h" @@ -23,6 +24,10 @@ #define INTEL_VENDORID 0x8086 #define HDA_INTEL_82801G 0x27d8 +#define HDA_OSS_NO 0x04 +#define HDA_ISS_NO 0x04 +#define HDA_LAST_OFFSET (0x80 + ((HDA_ISS_NO) * 0x20) + ((HDA_OSS_NO) * 0x20)) + /* * HDA Controller Register Offsets */ @@ -94,14 +99,34 @@ #define _HDAC_OSDBDPL(n, iss, oss) (0x18 + _HDAC_OSDOFFSET(n, iss, oss)) #define _HDAC_OSDBDPU(n, iss, oss) (0x1c + _HDAC_OSDOFFSET(n, iss, oss)) - /* * HDA data structures */ +struct hda_softc; + +typedef void (*hda_set_reg_handler)(struct hda_softc *sc, uint32_t old); + +struct hda_softc { + uint32_t regs[HDA_LAST_OFFSET]; +}; + /* * HDA module function declarations */ +static void +hda_set_reg_by_offset(struct hda_softc *sc, uint32_t offset, uint32_t value); +static uint32_t +hda_get_reg_by_offset(struct hda_softc *sc, uint32_t offset); +static void +hda_set_field_by_offset(struct hda_softc *sc, uint32_t offset, uint32_t mask, uint32_t value); + +static struct hda_softc *hda_init(const char *opts); +static void hda_reset_regs(struct hda_softc *sc); +static uint32_t +hda_read(struct hda_softc *sc, uint32_t offset); +static int +hda_write(struct hda_softc *sc, uint32_t offset, uint32_t value); /* * PCI HDA function declarations @@ -118,6 +143,10 @@ * HDA global data */ +static const hda_set_reg_handler hda_set_reg_table[] = { + [HDA_LAST_OFFSET] = NULL, +}; + struct pci_devemu pci_de_hda = { .pe_emu = "hda", .pe_init = pci_hda_init, @@ -131,21 +160,98 @@ * HDA module function definitions */ +static void +hda_set_reg_by_offset(struct hda_softc *sc, uint32_t offset, uint32_t value) +{ + assert(offset < HDA_LAST_OFFSET); + sc->regs[offset] = value; + + return; +} + +static uint32_t +hda_get_reg_by_offset(struct hda_softc *sc, uint32_t offset) +{ + assert(offset < HDA_LAST_OFFSET); + return sc->regs[offset]; +} + +static void +hda_set_field_by_offset(struct hda_softc *sc, uint32_t offset, uint32_t mask, uint32_t value) +{ + uint32_t reg_value = 0; + + reg_value = hda_get_reg_by_offset(sc, offset); + + reg_value &= ~mask; + reg_value |= value; + + hda_set_reg_by_offset(sc, offset, reg_value); + + return; +} + +static struct hda_softc *hda_init(const char *opts) +{ + struct hda_softc *sc = NULL; + +#if DEBUG_HDA == 1 + dbg = fopen("/tmp/bhyve_hda.log", "w+"); +#endif + + DPRINTF("opts: %s\n", opts); + + sc = calloc(1, sizeof(*sc)); + if (!sc) + return NULL; + + hda_reset_regs(sc); + + return sc; +} + +static void hda_reset_regs(struct hda_softc *sc) +{ + memset(sc->regs, 0, sizeof(sc->regs)); + + hda_set_reg_by_offset(sc, HDAC_GCAP, 0x4401); + hda_set_reg_by_offset(sc, HDAC_CORBSIZE, 0x42); + hda_set_reg_by_offset(sc, HDAC_RIRBSIZE, 0x42); + + return; +} + +static uint32_t +hda_read(struct hda_softc *sc, uint32_t offset) +{ + return hda_get_reg_by_offset(sc, offset); +} + +static int +hda_write(struct hda_softc *sc, uint32_t offset, uint32_t value) +{ + uint32_t old = hda_get_reg_by_offset(sc, offset); + hda_set_reg_handler set_reg_handler = hda_set_reg_table[offset]; + + hda_set_reg_by_offset(sc, offset, value); + + if (set_reg_handler) + set_reg_handler(sc, old); + + return 0; +} + /* * PCI HDA function definitions */ static int pci_hda_init(struct vmctx *ctx, struct pci_devinst *pi, char *opts) { + struct hda_softc *sc = NULL; + assert(ctx != NULL); assert(pi != NULL); -#if DEBUG_HDA == 1 - dbg = fopen("/tmp/bhyve_hda.log", "w+"); -#endif - - DPRINTF("PCI HDA\n"); - pci_set_cfgdata16(pi, PCIR_VENDOR, INTEL_VENDORID); pci_set_cfgdata16(pi, PCIR_DEVICE, HDA_INTEL_82801G); @@ -154,11 +260,17 @@ /* TODO check the right size */ /* allocate one BAR register for the Memory address offsets */ - pci_emul_alloc_bar(pi, 0, PCIBAR_MEM32, 0x0fff); + pci_emul_alloc_bar(pi, 0, PCIBAR_MEM32, 0x1000); /* allocate an IRQ pin for our slot */ pci_lintr_request(pi); + sc = hda_init(opts); + if (!sc) + return -1; + + pi->pi_arg = sc; + return 0; } @@ -166,9 +278,17 @@ pci_hda_write(struct vmctx *ctx, int vcpu, struct pci_devinst *pi, int baridx, uint64_t offset, int size, uint64_t value) { + struct hda_softc *sc = pi->pi_arg; + int err; + + assert(sc); assert(baridx == 0); + assert(size <= 4); - DPRINTF("offset: 0x%lx size: %d\n", offset, size); + DPRINTF("offset: 0x%lx value: 0x%lx\n", offset, value); + + err = hda_write(sc, offset, value); + assert(!err); return; } @@ -177,11 +297,18 @@ pci_hda_read(struct vmctx *ctx, int vcpu, struct pci_devinst *pi, int baridx, uint64_t offset, int size) { + struct hda_softc *sc = pi->pi_arg; + uint64_t value = 0; + + assert(sc); assert(baridx == 0); + assert(size <= 4); - DPRINTF("offset: 0x%lx size: %d\n", offset, size); + value = hda_read(sc, offset); - return 0; + DPRINTF("offset: 0x%lx value: 0x%lx\n", offset, value); + + return value; } From owner-svn-soc-all@freebsd.org Wed May 11 13:53:35 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 A1B37B36BA8 for ; Wed, 11 May 2016 13:53:35 +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 7DCA71C08 for ; Wed, 11 May 2016 13:53:35 +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 u4BDrZ3h089678 for ; Wed, 11 May 2016 13:53:35 GMT (envelope-from vincenzo@FreeBSD.org) Received: (from www@localhost) by socsvn.freebsd.org (8.15.2/8.15.2/Submit) id u4BDrZ7J089637 for svn-soc-all@FreeBSD.org; Wed, 11 May 2016 13:53:35 GMT (envelope-from vincenzo@FreeBSD.org) Date: Wed, 11 May 2016 13:53:35 GMT Message-Id: <201605111353.u4BDrZ7J089637@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: r302593 - soc2013/vincenzo 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: Wed, 11 May 2016 13:53:35 -0000 Author: vincenzo Date: Wed May 11 13:53:34 2016 New Revision: 302593 URL: http://svnweb.FreeBSD.org/socsvn/?view=rev&rev=302593 Log: First commit Added: soc2013/vincenzo/ From owner-svn-soc-all@freebsd.org Wed May 11 13:56:09 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 3C540B36C3E for ; Wed, 11 May 2016 13:56:09 +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 08F851DD8 for ; Wed, 11 May 2016 13:56:09 +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 u4BDu8Ke093514 for ; Wed, 11 May 2016 13:56:08 GMT (envelope-from vincenzo@FreeBSD.org) Received: (from www@localhost) by socsvn.freebsd.org (8.15.2/8.15.2/Submit) id u4BDu8Hp093487 for svn-soc-all@FreeBSD.org; Wed, 11 May 2016 13:56:08 GMT (envelope-from vincenzo@FreeBSD.org) Date: Wed, 11 May 2016 13:56:08 GMT Message-Id: <201605111356.u4BDu8Hp093487@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: r302594 - soc2013/vincenzo 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: Wed, 11 May 2016 13:56:09 -0000 Author: vincenzo Date: Wed May 11 13:56:08 2016 New Revision: 302594 URL: http://svnweb.FreeBSD.org/socsvn/?view=rev&rev=302594 Log: make up for mistake Deleted: soc2013/vincenzo/ From owner-svn-soc-all@freebsd.org Wed May 11 13:57:12 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 CE27DB36C62 for ; Wed, 11 May 2016 13:57:12 +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 A8F811E14 for ; Wed, 11 May 2016 13:57:12 +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 u4BDvC6n094947 for ; Wed, 11 May 2016 13:57:12 GMT (envelope-from vincenzo@FreeBSD.org) Received: (from www@localhost) by socsvn.freebsd.org (8.15.2/8.15.2/Submit) id u4BDvCBf094912 for svn-soc-all@FreeBSD.org; Wed, 11 May 2016 13:57:12 GMT (envelope-from vincenzo@FreeBSD.org) Date: Wed, 11 May 2016 13:57:12 GMT Message-Id: <201605111357.u4BDvCBf094912@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: r302595 - soc2016/vincenzo 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: Wed, 11 May 2016 13:57:12 -0000 Author: vincenzo Date: Wed May 11 13:57:12 2016 New Revision: 302595 URL: http://svnweb.FreeBSD.org/socsvn/?view=rev&rev=302595 Log: Create workspace for user vincenzo Added: soc2016/vincenzo/ From owner-svn-soc-all@freebsd.org Wed May 11 14:22:35 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 83B20B37232 for ; Wed, 11 May 2016 14:22:35 +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 5392B1AEF for ; Wed, 11 May 2016 14:22:35 +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 u4BEMZnx091850 for ; Wed, 11 May 2016 14:22:35 GMT (envelope-from vincenzo@FreeBSD.org) Received: (from www@localhost) by socsvn.freebsd.org (8.15.2/8.15.2/Submit) id u4BEMZmp091847 for svn-soc-all@FreeBSD.org; Wed, 11 May 2016 14:22:35 GMT (envelope-from vincenzo@FreeBSD.org) Date: Wed, 11 May 2016 14:22:35 GMT Message-Id: <201605111422.u4BEMZmp091847@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: r302608 - soc2016/vincenzo/head 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: Wed, 11 May 2016 14:22:35 -0000 Author: vincenzo Date: Wed May 11 14:22:34 2016 New Revision: 302608 URL: http://svnweb.FreeBSD.org/socsvn/?view=rev&rev=302608 Log: Import FreeBSD head code Added: soc2016/vincenzo/head/ (props changed) - copied from r302607, mirror/FreeBSD/head/ From owner-svn-soc-all@freebsd.org Wed May 11 15:23:27 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 83F83B36845 for ; Wed, 11 May 2016 15:23:27 +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 689471165 for ; Wed, 11 May 2016 15:23:27 +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 u4BFNRaA022141 for ; Wed, 11 May 2016 15:23:27 GMT (envelope-from vincenzo@FreeBSD.org) Received: (from www@localhost) by socsvn.freebsd.org (8.15.2/8.15.2/Submit) id u4BFNO9Z019859 for svn-soc-all@FreeBSD.org; Wed, 11 May 2016 15:23:24 GMT (envelope-from vincenzo@FreeBSD.org) Date: Wed, 11 May 2016 15:23:24 GMT Message-Id: <201605111523.u4BFNO9Z019859@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: r302612 - in soc2016/vincenzo/head/sys: dev/netmap modules/netmap net 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: Wed, 11 May 2016 15:23:27 -0000 Author: vincenzo Date: Wed May 11 15:23:23 2016 New Revision: 302612 URL: http://svnweb.FreeBSD.org/socsvn/?view=rev&rev=302612 Log: Update netmap sources to the github ones Added: soc2016/vincenzo/head/sys/dev/netmap/if_nfe_netmap.h soc2016/vincenzo/head/sys/dev/netmap/netmap_virt.h soc2016/vincenzo/head/sys/dev/netmap/ptnetmap.c Modified: soc2016/vincenzo/head/sys/dev/netmap/if_em_netmap.h soc2016/vincenzo/head/sys/dev/netmap/if_ixl_netmap.h soc2016/vincenzo/head/sys/dev/netmap/if_lem_netmap.h soc2016/vincenzo/head/sys/dev/netmap/if_vtnet_netmap.h soc2016/vincenzo/head/sys/dev/netmap/ixgbe_netmap.h soc2016/vincenzo/head/sys/dev/netmap/netmap.c soc2016/vincenzo/head/sys/dev/netmap/netmap_freebsd.c soc2016/vincenzo/head/sys/dev/netmap/netmap_generic.c soc2016/vincenzo/head/sys/dev/netmap/netmap_kern.h soc2016/vincenzo/head/sys/dev/netmap/netmap_mbq.c soc2016/vincenzo/head/sys/dev/netmap/netmap_mbq.h soc2016/vincenzo/head/sys/dev/netmap/netmap_mem2.c soc2016/vincenzo/head/sys/dev/netmap/netmap_mem2.h soc2016/vincenzo/head/sys/dev/netmap/netmap_monitor.c soc2016/vincenzo/head/sys/dev/netmap/netmap_offloadings.c soc2016/vincenzo/head/sys/dev/netmap/netmap_pipe.c soc2016/vincenzo/head/sys/dev/netmap/netmap_vale.c soc2016/vincenzo/head/sys/modules/netmap/Makefile soc2016/vincenzo/head/sys/net/netmap.h soc2016/vincenzo/head/sys/net/netmap_user.h Modified: soc2016/vincenzo/head/sys/dev/netmap/if_em_netmap.h ============================================================================== --- soc2016/vincenzo/head/sys/dev/netmap/if_em_netmap.h Wed May 11 14:59:54 2016 (r302611) +++ soc2016/vincenzo/head/sys/dev/netmap/if_em_netmap.h Wed May 11 15:23:23 2016 (r302612) @@ -148,7 +148,7 @@ /* device-specific */ struct e1000_tx_desc *curr = &txr->tx_base[nic_i]; - struct em_txbuffer *txbuf = &txr->tx_buffers[nic_i]; + struct em_buffer *txbuf = &txr->tx_buffers[nic_i]; int flags = (slot->flags & NS_REPORT || nic_i == 0 || nic_i == report_frequency) ? E1000_TXD_CMD_RS : 0; @@ -239,12 +239,12 @@ nm_i = netmap_idx_n2k(kring, nic_i); for (n = 0; ; n++) { // XXX no need to count - union e1000_rx_desc_extended *curr = &rxr->rx_base[nic_i]; - uint32_t staterr = le32toh(curr->wb.upper.status_error); + struct e1000_rx_desc *curr = &rxr->rx_base[nic_i]; + uint32_t staterr = le32toh(curr->status); if ((staterr & E1000_RXD_STAT_DD) == 0) break; - ring->slot[nm_i].len = le16toh(curr->wb.upper.length); + ring->slot[nm_i].len = le16toh(curr->length); ring->slot[nm_i].flags = slot_flags; bus_dmamap_sync(rxr->rxtag, rxr->rx_buffers[nic_i].map, BUS_DMASYNC_POSTREAD); @@ -271,19 +271,19 @@ uint64_t paddr; void *addr = PNMB(na, slot, &paddr); - union e1000_rx_desc_extended *curr = &rxr->rx_base[nic_i]; - struct em_rxbuffer *rxbuf = &rxr->rx_buffers[nic_i]; + struct e1000_rx_desc *curr = &rxr->rx_base[nic_i]; + struct em_buffer *rxbuf = &rxr->rx_buffers[nic_i]; if (addr == NETMAP_BUF_BASE(na)) /* bad buf */ goto ring_reset; if (slot->flags & NS_BUF_CHANGED) { /* buffer has changed, reload map */ - curr->read.buffer_addr = htole64(paddr); + curr->buffer_addr = htole64(paddr); netmap_reload_map(na, rxr->rxtag, rxbuf->map, addr); slot->flags &= ~NS_BUF_CHANGED; } - curr->wb.upper.status_error = 0; + curr->status = 0; bus_dmamap_sync(rxr->rxtag, rxbuf->map, BUS_DMASYNC_PREREAD); nm_i = nm_next(nm_i, lim); Modified: soc2016/vincenzo/head/sys/dev/netmap/if_ixl_netmap.h ============================================================================== --- soc2016/vincenzo/head/sys/dev/netmap/if_ixl_netmap.h Wed May 11 14:59:54 2016 (r302611) +++ soc2016/vincenzo/head/sys/dev/netmap/if_ixl_netmap.h Wed May 11 15:23:23 2016 (r302612) @@ -59,7 +59,7 @@ /* * device-specific sysctl variables: * - * ixl_crcstrip: 0: keep CRC in rx frames (default), 1: strip it. + * ixl_crcstrip: 0: NIC keeps CRC in rx frames (default), 1: NIC strips it. * During regular operations the CRC is stripped, but on some * hardware reception of frames not multiple of 64 is slower, * so using crcstrip=0 helps in benchmarks. @@ -74,7 +74,7 @@ int ixl_rx_miss, ixl_rx_miss_bufs, ixl_crcstrip = 1; #if 0 SYSCTL_INT(_dev_netmap, OID_AUTO, ixl_crcstrip, - CTLFLAG_RW, &ixl_crcstrip, 1, "strip CRC on rx frames"); + CTLFLAG_RW, &ixl_crcstrip, 1, "NIC strips CRC on rx frames"); #endif SYSCTL_INT(_dev_netmap, OID_AUTO, ixl_rx_miss, CTLFLAG_RW, &ixl_rx_miss, 0, "potentially missed rx intr"); Modified: soc2016/vincenzo/head/sys/dev/netmap/if_lem_netmap.h ============================================================================== --- soc2016/vincenzo/head/sys/dev/netmap/if_lem_netmap.h Wed May 11 14:59:54 2016 (r302611) +++ soc2016/vincenzo/head/sys/dev/netmap/if_lem_netmap.h Wed May 11 15:23:23 2016 (r302612) @@ -38,6 +38,10 @@ #include #include /* vtophys ? */ #include +#ifdef WITH_PTNETMAP_GUEST +#include +#endif +#include extern int netmap_adaptive_io; @@ -80,6 +84,20 @@ return (ifp->if_drv_flags & IFF_DRV_RUNNING ? 0 : 1); } +static void +lem_netmap_intr(struct netmap_adapter *na, int onoff) +{ + struct ifnet *ifp = na->ifp; + struct adapter *adapter = ifp->if_softc; + + EM_CORE_LOCK(adapter); + if (onoff) { + lem_enable_intr(adapter); + } else { + lem_disable_intr(adapter); + } + EM_CORE_UNLOCK(adapter); +} /* * Reconcile kernel and user view of the transmit ring. @@ -470,6 +488,176 @@ return netmap_ring_reinit(kring); } +#if defined (NIC_PTNETMAP) && defined (WITH_PTNETMAP_GUEST) +/* + * ptnetmap support for: lem (FreeBSD version) + * + * For details on ptnetmap support please see if_vtnet_netmap.h + */ +static uint32_t lem_ptnetmap_ptctl(struct ifnet *, uint32_t); + +/* Returns device configuration from the CSB */ +static int +lem_ptnetmap_config(struct netmap_adapter *na, + u_int *txr, u_int *txd, u_int *rxr, u_int *rxd) +{ + struct ifnet *ifp = na->ifp; + struct adapter *adapter = ifp->if_softc; + struct paravirt_csb *csb = adapter->csb; + int ret; + + if (csb == NULL) + return EINVAL; + + ret = lem_ptnetmap_ptctl(ifp, NET_PARAVIRT_PTCTL_CONFIG); + if (ret) + return ret; + + *txr = 1; //*txr = csb->num_tx_rings; + *rxr = 1; //*rxr = csb->num_rx_rings; + *txd = csb->num_tx_slots; + *rxd = csb->num_rx_slots; + + D("txr %u rxr %u txd %u rxd %u", + *txr, *rxr, *txd, *rxd); + + return 0; +} + +/* Reconcile host and guest view of the transmit ring. */ +static int +lem_ptnetmap_txsync(struct netmap_kring *kring, int flags) +{ + struct netmap_adapter *na = kring->na; + //u_int ring_nr = kring->ring_id; + struct ifnet *ifp = na->ifp; + struct adapter *adapter = ifp->if_softc; + bool notify; + + notify = netmap_pt_guest_txsync(&adapter->csb->tx_ring, kring, flags); + if (notify) + E1000_WRITE_REG(&adapter->hw, E1000_TDT(0), 0); + + return 0; +} + +/* Reconcile host and guest view of the receive ring. */ +static int +lem_ptnetmap_rxsync(struct netmap_kring *kring, int flags) +{ + struct netmap_adapter *na = kring->na; + //u_int ring_nr = kring->ring_id; + struct ifnet *ifp = na->ifp; + struct adapter *adapter = ifp->if_softc; + bool notify; + + notify = netmap_pt_guest_rxsync(&adapter->csb->rx_ring, kring, flags); + if (notify) + E1000_WRITE_REG(&adapter->hw, E1000_RDT(0), 0); + + return 0; +} + +/* Register/unregister. We are already under netmap lock. */ +static int +lem_ptnetmap_reg(struct netmap_adapter *na, int onoff) +{ + struct ifnet *ifp = na->ifp; + struct adapter *adapter = ifp->if_softc; + struct paravirt_csb *csb = adapter->csb; + struct netmap_kring *kring; + int ret; + + if (onoff) { + ret = lem_ptnetmap_ptctl(ifp, NET_PARAVIRT_PTCTL_REGIF); + if (ret) + return ret; + + na->na_flags |= NAF_NETMAP_ON; + adapter->ptnetmap_enabled = 1; + /* + * Init ring and kring pointers + * After PARAVIRT_PTCTL_REGIF, the csb contains a snapshot of a + * host kring pointers. + * XXX This initialization is required, because we don't close + * the host port on UNREGIF. + */ + + // Init rx ring + kring = na->rx_rings; + kring->rhead = kring->ring->head = csb->rx_ring.head; + kring->rcur = kring->ring->cur = csb->rx_ring.cur; + kring->nr_hwcur = csb->rx_ring.hwcur; + kring->nr_hwtail = kring->rtail = kring->ring->tail = + csb->rx_ring.hwtail; + + // Init tx ring + kring = na->tx_rings; + kring->rhead = kring->ring->head = csb->tx_ring.head; + kring->rcur = kring->ring->cur = csb->tx_ring.cur; + kring->nr_hwcur = csb->tx_ring.hwcur; + kring->nr_hwtail = kring->rtail = kring->ring->tail = + csb->tx_ring.hwtail; + } else { + na->na_flags &= ~NAF_NETMAP_ON; + adapter->ptnetmap_enabled = 0; + ret = lem_ptnetmap_ptctl(ifp, NET_PARAVIRT_PTCTL_UNREGIF); + } + + return lem_netmap_reg(na, onoff); +} + + +static int +lem_ptnetmap_bdg_attach(const char *bdg_name, struct netmap_adapter *na) +{ + return EOPNOTSUPP; +} + +/* Send command to the host through PTCTL register. */ +static uint32_t +lem_ptnetmap_ptctl(struct ifnet *ifp, uint32_t val) +{ + struct adapter *adapter = ifp->if_softc; + uint32_t ret; + + E1000_WRITE_REG(&adapter->hw, E1000_PTCTL, val); + ret = E1000_READ_REG(&adapter->hw, E1000_PTSTS); + D("PTSTS = %u", ret); + + return ret; +} + +/* Features negotiation with the host through PTFEAT */ +static uint32_t +lem_ptnetmap_features(struct adapter *adapter) +{ + uint32_t features; + /* tell the device the features we support */ + E1000_WRITE_REG(&adapter->hw, E1000_PTFEAT, NET_PTN_FEATURES_BASE); + /* get back the acknowledged features */ + features = E1000_READ_REG(&adapter->hw, E1000_PTFEAT); + device_printf(adapter->dev, "ptnetmap support: %s\n", + (features & NET_PTN_FEATURES_BASE) ? "base" : + "none"); + return features; +} + +static void +lem_ptnetmap_dtor(struct netmap_adapter *na) +{ + netmap_mem_pt_guest_ifp_del(na->nm_mem, na->ifp); +} + +/* XXX: these warning affect proper kernel compilation +#elif defined (NIC_PTNETMAP) +#warning "if_lem supports ptnetmap but netmap does not support it" +#warning "(configure netmap with ptnetmap support)" +#elif defined (WITH_PTNETMAP_GUEST) +#warning "netmap supports ptnetmap but e1000 does not support it" +#warning "(configure if_lem with ptnetmap support)" +*/ +#endif /* NIC_PTNETMAP && WITH_PTNETMAP_GUEST */ static void lem_netmap_attach(struct adapter *adapter) @@ -486,7 +674,34 @@ na.nm_rxsync = lem_netmap_rxsync; na.nm_register = lem_netmap_reg; na.num_tx_rings = na.num_rx_rings = 1; - netmap_attach(&na); + na.nm_intr = lem_netmap_intr; +#if defined (NIC_PTNETMAP) && defined (WITH_PTNETMAP_GUEST) + /* XXX: check if the device support ptnetmap (now we use PARA_SUBDEV) */ + if ((adapter->hw.subsystem_device_id == E1000_PARA_SUBDEV) && + (lem_ptnetmap_features(adapter) & NET_PTN_FEATURES_BASE)) { + int err; + + na.nm_config = lem_ptnetmap_config; + na.nm_register = lem_ptnetmap_reg; + na.nm_txsync = lem_ptnetmap_txsync; + na.nm_rxsync = lem_ptnetmap_rxsync; + na.nm_bdg_attach = lem_ptnetmap_bdg_attach; /* XXX */ + na.nm_dtor = lem_ptnetmap_dtor; + + /* Ask the device to fill in some configuration fields. Here we + * just need nifp_offset. */ + err = lem_ptnetmap_ptctl(na.ifp, NET_PARAVIRT_PTCTL_CONFIG); + if (err) { + D("Failed to get nifp_offset from passthrough device"); + return; + } + + netmap_pt_guest_attach(&na, adapter->csb, + adapter->csb->nifp_offset, + lem_ptnetmap_ptctl); + } else +#endif /* NIC_PTNETMAP && defined WITH_PTNETMAP_GUEST */ + netmap_attach(&na); } /* end of file */ Added: soc2016/vincenzo/head/sys/dev/netmap/if_nfe_netmap.h ============================================================================== --- /dev/null 00:00:00 1970 (empty, because file is newly added) +++ soc2016/vincenzo/head/sys/dev/netmap/if_nfe_netmap.h Wed May 11 15:23:23 2016 (r302612) @@ -0,0 +1,384 @@ +/* + * Copyright (C) 2011-2014 Luigi Rizzo. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ + +/* + * $FreeBSD: head/sys/dev/netmap/if_em_netmap.h 231881 2012-02-17 14:09:04Z luigi $ + * + * netmap support for: nfe XXX not yet tested. + * + * For more details on netmap support please see ixgbe_netmap.h + */ + + +#include +#include +#include +#include + +#include + + +static int +nfe_netmap_init_buffers(struct nfe_softc *sc) +{ + struct netmap_adapter *na = NA(sc->nfe_ifp); + struct netmap_slot *slot; + int i, l, n, max_avail; + struct nfe_desc32 *desc32 = NULL; + struct nfe_desc64 *desc64 = NULL; + void *addr; + uint64_t paddr; + + slot = netmap_reset(na, NR_TX, 0, 0); + if (!slot) + return 0; // not in native mode + // XXX init the tx ring + n = NFE_TX_RING_COUNT; + for (i = 0; i < n; i++) { + l = netmap_idx_n2k(&na->tx_rings[0], i); + addr = PNMB(na, slot + l, &paddr); + netmap_reload_map(sc->txq.tx_data_tag, + sc->txq.data[l].tx_data_map, addr); + slot[l].flags = 0; + if (sc->nfe_flags & NFE_40BIT_ADDR) { + desc64 = &sc->txq.desc64[l]; + desc64->physaddr[0] = htole32(NFE_ADDR_HI(paddr)); + desc64->physaddr[1] = htole32(NFE_ADDR_LO(paddr)); + desc64->vtag = 0; + desc64->length = htole16(0); + desc64->flags = htole16(0); + } else { + desc32 = &sc->txq.desc32[l]; + desc32->physaddr = htole32(NFE_ADDR_LO(paddr)); + desc32->length = htole16(0); + desc32->flags = htole16(0); + } + } + + slot = netmap_reset(na, NR_RX, 0, 0); + // XXX init the rx ring + /* + * preserve buffers still owned by the driver (and keep one empty). + */ + n = NFE_RX_RING_COUNT; + max_avail = n - 1 - nm_kr_rxspace(&na->rx_rings[0]); + for (i = 0; i < n; i++) { + uint16_t flags; + l = netmap_idx_n2k(&na->rx_rings[0], i); + addr = PNMB(na, slot + l, &paddr); + flags = (i < max_avail) ? NFE_RX_READY : 0; + if (sc->nfe_flags & NFE_40BIT_ADDR) { + desc64 = &sc->rxq.desc64[l]; + desc64->physaddr[0] = htole32(NFE_ADDR_HI(paddr)); + desc64->physaddr[1] = htole32(NFE_ADDR_LO(paddr)); + desc64->vtag = 0; + desc64->length = htole16(NETMAP_BUF_SIZE); + desc64->flags = htole16(NFE_RX_READY); + } else { + desc32 = &sc->rxq.desc32[l]; + desc32->physaddr = htole32(NFE_ADDR_LO(paddr)); + desc32->length = htole16(NETMAP_BUF_SIZE); + desc32->flags = htole16(NFE_RX_READY); + } + + netmap_reload_map(sc->rxq.rx_data_tag, + sc->rxq.data[l].rx_data_map, addr); + bus_dmamap_sync(sc->rxq.rx_data_tag, + sc->rxq.data[l].rx_data_map, BUS_DMASYNC_PREREAD); + } + + return 1; +} + + +/* + * Register/unregister. We are already under netmap lock. + */ +static int +nfe_netmap_reg(struct netmap_adapter *na, int onoff) +{ + struct ifnet *ifp = na->ifp; + struct nfe_softc *sc = ifp->if_softc; + + NFE_LOCK(sc); + nfe_stop(ifp); /* also clear IFF_DRV_RUNNING */ + if (onoff) { + nm_set_native_flags(na); + } else { + nm_clear_native_flags(na); + } + nfe_init_locked(sc); /* also enable intr */ + NFE_UNLOCK(sc); + return (0); +} + + +/* + * Reconcile kernel and user view of the transmit ring. + */ +static int +nfe_netmap_txsync(struct netmap_kring *kring, int flags) +{ + struct netmap_adapter *na = kring->na; + struct ifnet *ifp = na->ifp; + struct netmap_ring *ring = kring->ring; + u_int nm_i; /* index into the netmap ring */ + u_int nic_i; /* index into the NIC ring */ + u_int n; + u_int const lim = kring->nkr_num_slots - 1; + u_int const head = kring->rhead; + /* generate an interrupt approximately every half ring */ + u_int report_frequency = kring->nkr_num_slots >> 1; + + /* device-specific */ + struct nfe_softc *sc = ifp->if_softc; + struct nfe_desc32 *desc32 = NULL; + struct nfe_desc64 *desc64 = NULL; + + bus_dmamap_sync(sc->txq.tx_desc_tag, sc->txq.tx_desc_map, + BUS_DMASYNC_POSTREAD); + + /* + * First part: process new packets to send. + */ + + nm_i = kring->nr_hwcur; + if (nm_i != head) { /* we have new packets to send */ + nic_i = netmap_idx_k2n(kring, nm_i); + for (n = 0; nm_i != head; n++) { + /* slot is the current slot in the netmap ring */ + struct netmap_slot *slot = &ring->slot[nm_i]; + u_int len = slot->len; + uint64_t paddr; + void *addr = PNMB(na, slot, &paddr); + + NM_CHECK_ADDR_LEN(addr, len); + + if (slot->flags & NS_BUF_CHANGED) { + /* buffer has changed, reload map */ + netmap_reload_map(sc->txq.tx_data_tag, + sc->txq.data[l].tx_data_map, addr); + } + slot->flags &= ~(NS_REPORT | NS_BUF_CHANGED); + + if (sc->nfe_flags & NFE_40BIT_ADDR) { + desc64 = &sc->txq.desc64[l]; + desc64->physaddr[0] = htole32(NFE_ADDR_HI(paddr)); + desc64->physaddr[1] = htole32(NFE_ADDR_LO(paddr)); + desc64->vtag = 0; + desc64->length = htole16(len - 1); + desc64->flags = + htole16(NFE_TX_VALID | NFE_TX_LASTFRAG_V2); + } else { + desc32 = &sc->txq.desc32[l]; + desc32->physaddr = htole32(NFE_ADDR_LO(paddr)); + desc32->length = htole16(len - 1); + desc32->flags = + htole16(NFE_TX_VALID | NFE_TX_LASTFRAG_V1); + } + + bus_dmamap_sync(sc->txq.tx_data_tag, + sc->txq.data[l].tx_data_map, BUS_DMASYNC_PREWRITE); + nm_i = nm_next(nm_i, lim); + nic_i = nm_next(nic_i, lim); + } + kring->nr_hwcur = head; + sc->txq.cur = nic_i; + + bus_dmamap_sync(sc->txq.tx_desc_tag, sc->txq.tx_desc_map, + BUS_DMASYNC_PREREAD | BUS_DMASYNC_PREWRITE); + + /* XXX something missing ? where is the last pkt marker ? */ + NFE_WRITE(sc, NFE_RXTX_CTL, NFE_RXTX_KICKTX | sc->rxtxctl); + } + + /* + * Second part: reclaim buffers for completed transmissions. + */ + if (flags & NAF_FORCE_RECLAIM || nm_kr_txempty(kring)) { + u_int nic_cur = sc->txq.cur; + nic_i = sc->txq.next; + for (n = 0; nic_i != nic_cur; n++, NFE_INC(nic_i, NFE_TX_RING_COUNT)) { + uint16_t flags; + if (sc->nfe_flags & NFE_40BIT_ADDR) { + desc64 = &sc->txq.desc64[l]; + flags = le16toh(desc64->flags); + } else { + desc32 = &sc->txq.desc32[l]; + flags = le16toh(desc32->flags); + } + if (flags & NFE_TX_VALID) + break; + } + if (n > 0) { + sc->txq.next = nic_i; + kring->nr_hwtail = nm_prev(netmap_idx_n2k(kring, nic_i), lim); + } + } + + + return 0; +} + + +/* + * Reconcile kernel and user view of the receive ring. + */ +static int +nfe_netmap_rxsync(struct netmap_kring *kring, int flags) +{ + struct netmap_adapter *na = kring->na; + struct ifnet *ifp = na->ifp; + struct netmap_ring *ring = kring->ring; + u_int nm_i; /* index into the netmap ring */ + u_int nic_i; /* index into the NIC ring */ + u_int n; + u_int const lim = kring->nkr_num_slots - 1; + u_int const head = kring->rhead; + int force_update = (flags & NAF_FORCE_READ) || kring->nr_kflags & NKR_PENDINTR; + + /* device-specific */ + struct nfe_softc *sc = ifp->if_softc; + struct nfe_desc32 *desc32; + struct nfe_desc64 *desc64; + + if (head > lim) + return netmap_ring_reinit(kring); + + bus_dmamap_sync(sc->rxq.rx_desc_tag, sc->rxq.rx_desc_map, + BUS_DMASYNC_POSTREAD | BUS_DMASYNC_POSTWRITE); + + /* + * First part: import newly received packets. + */ + if (netmap_no_pendintr || force_update) { + uint16_t flags, len; + uint16_t slot_flags = kring->nkr_slot_flags; + + nic_i = sc->rxq.cur; + nm_i = netmap_idx_n2k(kring, nic_i); + for (n = 0; ; n++) { + if (sc->nfe_flags & NFE_40BIT_ADDR) { + desc64 = &sc->rxq.desc64[sc->rxq.cur]; + flags = le16toh(desc64->flags); + len = le16toh(desc64->length) & NFE_RX_LEN_MASK; + } else { + desc32 = &sc->rxq.desc32[sc->rxq.cur]; + flags = le16toh(desc32->flags); + len = le16toh(desc32->length) & NFE_RX_LEN_MASK; + } + + if (flags & NFE_RX_READY) + break; + + ring->slot[nm_i].len = len; + ring->slot[nm_i].flags = slot_flags; + bus_dmamap_sync(sc->rxq.rx_data_tag, + sc->rxq.data[nic_i].rx_data_map, + BUS_DMASYNC_POSTREAD); + nm_i = nm_next(nm_i, lim); + nic_i = nm_next(nic_i, lim); + } + if (n) { /* update the state variables */ + sc->rxq.cur = nic_i; + kring->nr_hwtail = nm_i; + } + kring->nr_kflags &= ~NKR_PENDINTR; + } + + /* + * Second part: skip past packets that userspace has released. + */ + nm_i = kring->nr_hwcur; + if (nm_i != head) { + nic_i = netmap_idx_k2n(kring, nm_i); + for (n = 0; nm_i != head; n++) { + struct netmap_slot *slot = &ring->slot[nm_i]; + uint64_t paddr; + void *addr = PNMB(na, slot, &paddr); + + if (addr == netmap_buffer_base) /* bad buf */ + goto ring_reset; + + if (slot->flags & NS_BUF_CHANGED) { + /* buffer has changed, reload map */ + netmap_reload_map(sc->rxq.rx_data_tag, + sc->rxq.data[l].rx_data_map, addr); + slot->flags &= ~NS_BUF_CHANGED; + } + if (sc->nfe_flags & NFE_40BIT_ADDR) { + desc64 = &sc->rxq.desc64[nic_i]; + desc64->physaddr[0] = + htole32(NFE_ADDR_HI(paddr)); + desc64->physaddr[1] = + htole32(NFE_ADDR_LO(paddr)); + desc64->length = htole16(NETMAP_BUF_SIZE); + desc64->flags = htole16(NFE_RX_READY); + } else { + desc32 = &sc->rxq.desc32[nic_i]; + desc32->physaddr = + htole32(NFE_ADDR_LO(paddr)); + desc32->length = htole16(NETMAP_BUF_SIZE); + desc32->flags = htole16(NFE_RX_READY); + } + + bus_dmamap_sync(sc->rxq.rx_data_tag, + sc->rxq.data[nic_i].rx_data_map, + BUS_DMASYNC_PREREAD); + nm_i = nm_next(nm_i, lim); + nic_i = nm_next(nic_i, lim); + } + kring->nr_hwcur = head; + bus_dmamap_sync(sc->rxq.rx_desc_tag, sc->rxq.rx_desc_map, + BUS_DMASYNC_PREREAD | BUS_DMASYNC_PREWRITE); + } + + + return 0; + +ring_reset: + return netmap_ring_reinit(kring); +} + + +static void +nfe_netmap_attach(struct nfe_softc *sc) +{ + struct netmap_adapter na; + + bzero(&na, sizeof(na)); + + na.ifp = sc->nfe_ifp; + na.na_flags = NAF_BDG_MAYSLEEP; + na.num_tx_desc = NFE_TX_RING_COUNT; + na.num_rx_desc = NFE_RX_RING_COUNT; + na.nm_txsync = nfe_netmap_txsync; + na.nm_rxsync = nfe_netmap_rxsync; + na.nm_register = nfe_netmap_reg; + na.num_tx_rings = na.num_rx_rings = 1; + netmap_attach(&na, 1); +} + +/* end of file */ Modified: soc2016/vincenzo/head/sys/dev/netmap/if_vtnet_netmap.h ============================================================================== --- soc2016/vincenzo/head/sys/dev/netmap/if_vtnet_netmap.h Wed May 11 14:59:54 2016 (r302611) +++ soc2016/vincenzo/head/sys/dev/netmap/if_vtnet_netmap.h Wed May 11 15:23:23 2016 (r302612) @@ -32,6 +32,15 @@ #include #include /* vtophys ? */ #include +#ifdef WITH_PTNETMAP_GUEST +#include +#include +static int vtnet_ptnetmap_txsync(struct netmap_kring *kring, int flags); +#define VTNET_PTNETMAP_ON(_na) \ + ((nm_netmap_on(_na)) && ((_na)->nm_txsync == vtnet_ptnetmap_txsync)) +#else /* !WITH_PTNETMAP_GUEST */ +#define VTNET_PTNETMAP_ON(_na) 0 +#endif /* WITH_PTNETMAP_GUEST */ #define SOFTC_T vtnet_softc @@ -353,6 +362,9 @@ struct netmap_adapter* na = NA(ifp); unsigned int r; + /* if ptnetmap is enabled we must not init netmap buffers */ + if (VTNET_PTNETMAP_ON(na)) + return 1; if (!nm_native_on(na)) return 0; for (r = 0; r < na->num_rx_rings; r++) { @@ -403,6 +415,331 @@ return 0; } +#ifdef WITH_PTNETMAP_GUEST +/* + * ptnetmap support for: virtio-net (FreeBSD version) + * + * this part od this file is meant to be a reference on how to implement + * ptnetmap support for a network driver. + * this file contains code but only static or inline functions used + * by a single driver. + */ + +/* + * virtio-specific macro and fucntions + */ +/* ptnetmap virtio register BASE */ +#define PTNETMAP_VIRTIO_IO_BASE sizeof(struct virtio_net_config) +#ifndef VIRTIO_NET_F_PTNETMAP +#define VIRTIO_NET_F_PTNETMAP 0x2000000 /* linux/qeum 25 */ +#endif /* VIRTIO_NET_F_PTNETMAP */ + +static void inline +vtnet_ptnetmap_iowrite4(device_t dev, uint32_t addr, uint32_t val) +{ + int i; + /* + * virtio_pci config_set use multiple iowrite8, we need to split the + * call and reverse the order + */ + for (i = 3; i >= 0; i--) { + virtio_write_dev_config_1(dev, PTNETMAP_VIRTIO_IO_BASE + addr + i, + *(((uint8_t *)&val) + i)); + } +} + +static uint32_t inline +vtnet_ptnetmap_ioread4(device_t dev, uint32_t addr) +{ + uint32_t val; + int i; + + for (i = 0; i <= 3; i++) { + *(((uint8_t *)&val) + i) = virtio_read_dev_config_1(dev, + PTNETMAP_VIRTIO_IO_BASE + addr + i); + } + return val; +} + +/* + * CSB (Communication Status Block) allocation. + * CSB is the shared memory used by the netmap instance running in the guest + * and the ptnetmap kthreads in the host. + * The CSBBAH/CSBBAL registers must be added to the virtio-net device. + * + * Only called after netmap_pt_guest_attach(). + */ +static struct paravirt_csb * +vtnet_ptnetmap_alloc_csb(struct SOFTC_T *sc) +{ + device_t dev = sc->vtnet_dev; + struct paravirt_csb *csb; + + vm_paddr_t csb_phyaddr; + + csb = contigmalloc(NET_PARAVIRT_CSB_SIZE, M_DEVBUF, + M_NOWAIT | M_ZERO, (size_t)0, -1UL, PAGE_SIZE, 0); + if (!csb) { + D("Communication Status Block allocation failed!"); + return NULL; + } + + csb_phyaddr = vtophys(csb); + + csb->guest_csb_on = 1; + + /* Tell the device the CSB physical address. */ + vtnet_ptnetmap_iowrite4(dev, PTNETMAP_VIRTIO_IO_CSBBAH, + (uint32_t)(csb_phyaddr >> 32)); + vtnet_ptnetmap_iowrite4(dev, PTNETMAP_VIRTIO_IO_CSBBAL, + (uint32_t)(csb_phyaddr)); + + return csb; +} + +/* + * CSB (Communication Status Block) deallocation. + */ +static void +vtnet_ptnetmap_free_csb(struct SOFTC_T *sc) +{ + device_t dev = sc->vtnet_dev; + struct ifnet *ifp = sc->vtnet_ifp; + struct netmap_pt_guest_adapter* ptna = + (struct netmap_pt_guest_adapter *)NA(ifp); + + if (ptna->csb) { + /* CSB deallocation protocol. */ + vtnet_ptnetmap_iowrite4(dev, PTNETMAP_VIRTIO_IO_CSBBAH, 0x0ULL); + vtnet_ptnetmap_iowrite4(dev, PTNETMAP_VIRTIO_IO_CSBBAL, 0x0ULL); + + contigfree(ptna->csb, NET_PARAVIRT_CSB_SIZE, M_DEVBUF); + ptna->csb = NULL; + } +} + +static uint32_t vtnet_ptnetmap_ptctl(struct ifnet *, uint32_t); + +/* + * Returns device configuration from the CSB, after sending the PTCTL_CONFIG + * command to the host (hypervisor virtio fronted). + * The host reads the configuration from the netmap port (opened in the host) + * and it stores the values in the CSB. + */ +static int +vtnet_ptnetmap_config(struct netmap_adapter *na, + u_int *txr, u_int *txd, u_int *rxr, u_int *rxd) +{ + struct netmap_pt_guest_adapter *ptna = + (struct netmap_pt_guest_adapter *)na; + struct paravirt_csb *csb = ptna->csb; + int ret; + + if (csb == NULL) + return EINVAL; + + ret = vtnet_ptnetmap_ptctl(na->ifp, NET_PARAVIRT_PTCTL_CONFIG); + if (ret) + return ret; + + *txr = 1; //*txr = csb->num_tx_rings; + *rxr = 1; //*rxr = csb->num_rx_rings; + *txd = csb->num_tx_slots; + *rxd = csb->num_rx_slots; + + ND("txr %u rxr %u txd %u rxd %u", + *txr, *rxr, *txd, *rxd); + return 0; +} + +/* + * Reconcile host and guest view of the transmit ring. + * Use generic netmap_pt_guest_txsync(). + * Only the notification to the host is device-specific. + */ +static int +vtnet_ptnetmap_txsync(struct netmap_kring *kring, int flags) +{ + struct netmap_adapter *na = kring->na; + struct netmap_pt_guest_adapter *ptna = + (struct netmap_pt_guest_adapter *)na; + struct paravirt_csb *csb = ptna->csb; + struct ifnet *ifp = na->ifp; + u_int ring_nr = kring->ring_id; + struct SOFTC_T *sc = ifp->if_softc; + struct virtqueue *vq = sc->vtnet_txqs[ring_nr].vtntx_vq; + bool notify; + + notify = netmap_pt_guest_txsync(&csb->tx_ring, kring, flags); + if (notify) + virtqueue_notify(vq); + + ND("TX - vq_index: %d", vq->index); + + return 0; +} + +/* + * Reconcile host and guest view of the receive ring. + * Use generic netmap_pt_guest_rxsync(). + * Only the notification to the host is device-specific. + */ +static int +vtnet_ptnetmap_rxsync(struct netmap_kring *kring, int flags) +{ + struct netmap_adapter *na = kring->na; + struct netmap_pt_guest_adapter *ptna = + (struct netmap_pt_guest_adapter *)na; + struct paravirt_csb *csb = ptna->csb; + struct ifnet *ifp = na->ifp; + u_int ring_nr = kring->ring_id; + struct SOFTC_T *sc = ifp->if_softc; + struct virtqueue *vq = sc->vtnet_rxqs[ring_nr].vtnrx_vq; + bool notify; + + notify = netmap_pt_guest_rxsync(&csb->rx_ring, kring, flags); + if (notify) + virtqueue_notify(vq); + + ND("RX - vq_index: %d", vq->index); + + return 0; +} + +/* + * Register/unregister. We are already under netmap lock. + * Only called on the first register or the last unregister. + */ +static int +vtnet_ptnetmap_reg(struct netmap_adapter *na, int onoff) +{ + struct netmap_pt_guest_adapter *ptna = + (struct netmap_pt_guest_adapter *)na; + + /* device-specific */ + struct ifnet *ifp = na->ifp; + struct SOFTC_T *sc = ifp->if_softc; + struct paravirt_csb *csb = ptna->csb; + struct netmap_kring *kring; + int ret = 0; + + if (na == NULL) + return EINVAL; + + VTNET_CORE_LOCK(sc); + /* enable or disable flags and callbacks in na and ifp */ + if (onoff) { + int i; + nm_set_native_flags(na); + /* push fake-elem in the tx queues to enable interrupts */ + for (i = 0; i < sc->vtnet_max_vq_pairs; i++) { + struct vtnet_txq *txq = &sc->vtnet_txqs[i]; + struct mbuf *m0; + m0 = m_gethdr(M_NOWAIT, MT_DATA); + m0->m_len = 64; + + if (m0) { + ret = vtnet_txq_encap(txq, &m0); + } + } + ret = vtnet_ptnetmap_ptctl(na->ifp, NET_PARAVIRT_PTCTL_REGIF); + if (ret) { + //na->na_flags &= ~NAF_NETMAP_ON; + nm_clear_native_flags(na); + goto out; + } + /* + * Init ring and kring pointers + * After PARAVIRT_PTCTL_REGIF, the csb contains a snapshot of a + * host kring pointers. + * XXX This initialization is required, because we don't close + * the host port on UNREGIF. + */ + // Init rx ring + kring = na->rx_rings; + kring->rhead = kring->ring->head = csb->rx_ring.head; + kring->rcur = kring->ring->cur = csb->rx_ring.cur; + kring->nr_hwcur = csb->rx_ring.hwcur; + kring->nr_hwtail = kring->rtail = kring->ring->tail = + csb->rx_ring.hwtail; + + // Init tx ring + kring = na->tx_rings; + kring->rhead = kring->ring->head = csb->tx_ring.head; + kring->rcur = kring->ring->cur = csb->tx_ring.cur; + kring->nr_hwcur = csb->tx_ring.hwcur; + kring->nr_hwtail = kring->rtail = kring->ring->tail = + csb->tx_ring.hwtail; + } else { + ifp->if_drv_flags &= ~(IFF_DRV_RUNNING | IFF_DRV_OACTIVE); + //na->na_flags &= ~NAF_NETMAP_ON; + nm_clear_native_flags(na); + ret = vtnet_ptnetmap_ptctl(na->ifp, NET_PARAVIRT_PTCTL_UNREGIF); + vtnet_init_locked(sc); /* also enable intr */ + } +out: *** DIFF OUTPUT TRUNCATED AT 1000 LINES *** From owner-svn-soc-all@freebsd.org Thu May 12 21:02:46 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 9AE19B39F27 for ; Thu, 12 May 2016 21:02:46 +0000 (UTC) (envelope-from iateaca@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 7588F1098 for ; Thu, 12 May 2016 21:02:46 +0000 (UTC) (envelope-from iateaca@FreeBSD.org) Received: from socsvn.freebsd.org ([127.0.1.124]) by socsvn.freebsd.org (8.15.2/8.15.2) with ESMTP id u4CL2k9h078765 for ; Thu, 12 May 2016 21:02:46 GMT (envelope-from iateaca@FreeBSD.org) Received: (from www@localhost) by socsvn.freebsd.org (8.15.2/8.15.2/Submit) id u4CL2km6078671 for svn-soc-all@FreeBSD.org; Thu, 12 May 2016 21:02:46 GMT (envelope-from iateaca@FreeBSD.org) Date: Thu, 12 May 2016 21:02:46 GMT Message-Id: <201605122102.u4CL2km6078671@socsvn.freebsd.org> X-Authentication-Warning: socsvn.freebsd.org: www set sender to iateaca@FreeBSD.org using -f From: iateaca@FreeBSD.org To: svn-soc-all@FreeBSD.org Subject: socsvn commit: r302726 - soc2016/iateaca 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: Thu, 12 May 2016 21:02:46 -0000 Author: iateaca Date: Thu May 12 21:02:45 2016 New Revision: 302726 URL: http://svnweb.FreeBSD.org/socsvn/?view=rev&rev=302726 Log: create soc2016/iateaca repo Added: soc2016/iateaca/ From owner-svn-soc-all@freebsd.org Thu May 12 21:04:24 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 DC462B39F4C for ; Thu, 12 May 2016 21:04:24 +0000 (UTC) (envelope-from iateaca@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 B6FDA10C7 for ; Thu, 12 May 2016 21:04:24 +0000 (UTC) (envelope-from iateaca@FreeBSD.org) Received: from socsvn.freebsd.org ([127.0.1.124]) by socsvn.freebsd.org (8.15.2/8.15.2) with ESMTP id u4CL4O6w007176 for ; Thu, 12 May 2016 21:04:24 GMT (envelope-from iateaca@FreeBSD.org) Received: (from www@localhost) by socsvn.freebsd.org (8.15.2/8.15.2/Submit) id u4CL4OPi007002 for svn-soc-all@FreeBSD.org; Thu, 12 May 2016 21:04:24 GMT (envelope-from iateaca@FreeBSD.org) Date: Thu, 12 May 2016 21:04:24 GMT Message-Id: <201605122104.u4CL4OPi007002@socsvn.freebsd.org> X-Authentication-Warning: socsvn.freebsd.org: www set sender to iateaca@FreeBSD.org using -f From: iateaca@FreeBSD.org To: svn-soc-all@FreeBSD.org Subject: socsvn commit: r302727 - soc2016/iateaca/bhyve-hda-head 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: Thu, 12 May 2016 21:04:25 -0000 Author: iateaca Date: Thu May 12 21:04:24 2016 New Revision: 302727 URL: http://svnweb.FreeBSD.org/socsvn/?view=rev&rev=302727 Log: clone the FreeBSD HEAD in the iateaca/bhyve-hda-head repo Added: soc2016/iateaca/bhyve-hda-head/ (props changed) - copied from r302726, mirror/FreeBSD/head/ From owner-svn-soc-all@freebsd.org Fri May 13 14:09:50 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 6C3DFB3A62B for ; Fri, 13 May 2016 14:09:50 +0000 (UTC) (envelope-from fabs@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 397501219 for ; Fri, 13 May 2016 14:09:50 +0000 (UTC) (envelope-from fabs@FreeBSD.org) Received: from socsvn.freebsd.org ([127.0.1.124]) by socsvn.freebsd.org (8.15.2/8.15.2) with ESMTP id u4DE9o5n084832 for ; Fri, 13 May 2016 14:09:50 GMT (envelope-from fabs@FreeBSD.org) Received: (from www@localhost) by socsvn.freebsd.org (8.15.2/8.15.2/Submit) id u4DE9o5q084831 for svn-soc-all@FreeBSD.org; Fri, 13 May 2016 14:09:50 GMT (envelope-from fabs@FreeBSD.org) Date: Fri, 13 May 2016 14:09:50 GMT Message-Id: <201605131409.u4DE9o5q084831@socsvn.freebsd.org> X-Authentication-Warning: socsvn.freebsd.org: www set sender to fabs@FreeBSD.org using -f From: fabs@FreeBSD.org To: svn-soc-all@FreeBSD.org Subject: socsvn commit: r302832 - soc2016/fabs 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: Fri, 13 May 2016 14:09:50 -0000 Author: fabs Date: Fri May 13 14:09:49 2016 New Revision: 302832 URL: http://svnweb.FreeBSD.org/socsvn/?view=rev&rev=302832 Log: Create my workspace Added: soc2016/fabs/ From owner-svn-soc-all@freebsd.org Sat May 14 13:53:43 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 4A720B39346 for ; Sat, 14 May 2016 13:53:43 +0000 (UTC) (envelope-from iateaca@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 27F691D5D for ; Sat, 14 May 2016 13:53:43 +0000 (UTC) (envelope-from iateaca@FreeBSD.org) Received: from socsvn.freebsd.org ([127.0.1.124]) by socsvn.freebsd.org (8.15.2/8.15.2) with ESMTP id u4EDrhjV064871 for ; Sat, 14 May 2016 13:53:43 GMT (envelope-from iateaca@FreeBSD.org) Received: (from www@localhost) by socsvn.freebsd.org (8.15.2/8.15.2/Submit) id u4EDrgFw064865 for svn-soc-all@FreeBSD.org; Sat, 14 May 2016 13:53:42 GMT (envelope-from iateaca@FreeBSD.org) Date: Sat, 14 May 2016 13:53:42 GMT Message-Id: <201605141353.u4EDrgFw064865@socsvn.freebsd.org> X-Authentication-Warning: socsvn.freebsd.org: www set sender to iateaca@FreeBSD.org using -f From: iateaca@FreeBSD.org To: svn-soc-all@FreeBSD.org Subject: socsvn commit: r302902 - soc2016/iateaca/bhyve-hda-head/usr.sbin/bhyve 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: Sat, 14 May 2016 13:53:43 -0000 Author: iateaca Date: Sat May 14 13:53:42 2016 New Revision: 302902 URL: http://svnweb.FreeBSD.org/socsvn/?view=rev&rev=302902 Log: add pci_hda in bhyve probe the HDA controller - set the PCI configuration space, allocate BAR0 memory addresses and request IRQ add HDA Controller Register Set offsets add HDA controller stream in and out registers design the layout of registers, implement the read and write access to the registers A bhyve/pci_hda.c Added: soc2016/iateaca/bhyve-hda-head/usr.sbin/bhyve/pci_hda.c Added: soc2016/iateaca/bhyve-hda-head/usr.sbin/bhyve/pci_hda.c ============================================================================== --- /dev/null 00:00:00 1970 (empty, because file is newly added) +++ soc2016/iateaca/bhyve-hda-head/usr.sbin/bhyve/pci_hda.c Sat May 14 13:53:42 2016 (r302902) @@ -0,0 +1,314 @@ + +#include +#include +#include + +#include "pci_emul.h" + +/* + * HDA Debug Log + */ +#define DEBUG_HDA 1 +#if DEBUG_HDA == 1 +static FILE *dbg; +#define DPRINTF(fmt, arg...) \ +do {fprintf(dbg, "%s-%d: " fmt, __func__, __LINE__, ##arg); \ +fflush(dbg); } while (0) +#else +#define DPRINTF(fmt, arg...) +#endif + +/* + * HDA defines + */ +#define INTEL_VENDORID 0x8086 +#define HDA_INTEL_82801G 0x27d8 + +#define HDA_OSS_NO 0x04 +#define HDA_ISS_NO 0x04 +#define HDA_LAST_OFFSET (0x80 + ((HDA_ISS_NO) * 0x20) + ((HDA_OSS_NO) * 0x20)) + +/* + * HDA Controller Register Offsets + */ +#define HDAC_GCAP 0x00 /* 2 - Global Capabilities*/ +#define HDAC_VMIN 0x02 /* 1 - Minor Version */ +#define HDAC_VMAJ 0x03 /* 1 - Major Version */ +#define HDAC_OUTPAY 0x04 /* 2 - Output Payload Capability */ +#define HDAC_INPAY 0x06 /* 2 - Input Payload Capability */ +#define HDAC_GCTL 0x08 /* 4 - Global Control */ +#define HDAC_WAKEEN 0x0c /* 2 - Wake Enable */ +#define HDAC_STATESTS 0x0e /* 2 - State Change Status */ +#define HDAC_GSTS 0x10 /* 2 - Global Status */ +#define HDAC_OUTSTRMPAY 0x18 /* 2 - Output Stream Payload Capability */ +#define HDAC_INSTRMPAY 0x1a /* 2 - Input Stream Payload Capability */ +#define HDAC_INTCTL 0x20 /* 4 - Interrupt Control */ +#define HDAC_INTSTS 0x24 /* 4 - Interrupt Status */ +#define HDAC_WALCLK 0x30 /* 4 - Wall Clock Counter */ +#define HDAC_SSYNC 0x38 /* 4 - Stream Synchronization */ +#define HDAC_CORBLBASE 0x40 /* 4 - CORB Lower Base Address */ +#define HDAC_CORBUBASE 0x44 /* 4 - CORB Upper Base Address */ +#define HDAC_CORBWP 0x48 /* 2 - CORB Write Pointer */ +#define HDAC_CORBRP 0x4a /* 2 - CORB Read Pointer */ +#define HDAC_CORBCTL 0x4c /* 1 - CORB Control */ +#define HDAC_CORBSTS 0x4d /* 1 - CORB Status */ +#define HDAC_CORBSIZE 0x4e /* 1 - CORB Size */ +#define HDAC_RIRBLBASE 0x50 /* 4 - RIRB Lower Base Address */ +#define HDAC_RIRBUBASE 0x54 /* 4 - RIRB Upper Base Address */ +#define HDAC_RIRBWP 0x58 /* 2 - RIRB Write Pointer */ +#define HDAC_RINTCNT 0x5a /* 2 - Response Interrupt Count */ +#define HDAC_RIRBCTL 0x5c /* 1 - RIRB Control */ +#define HDAC_RIRBSTS 0x5d /* 1 - RIRB Status */ +#define HDAC_RIRBSIZE 0x5e /* 1 - RIRB Size */ +#define HDAC_ICOI 0x60 /* 4 - Immediate Command Output Interface */ +#define HDAC_ICII 0x64 /* 4 - Immediate Command Input Interface */ +#define HDAC_ICIS 0x68 /* 2 - Immediate Command Status */ +#define HDAC_DPIBLBASE 0x70 /* 4 - DMA Position Buffer Lower Base */ +#define HDAC_DPIBUBASE 0x74 /* 4 - DMA Position Buffer Upper Base */ +#define HDAC_SDCTL0 0x80 /* 3 - Stream Descriptor Control */ +#define HDAC_SDCTL1 0x81 /* 3 - Stream Descriptor Control */ +#define HDAC_SDCTL2 0x82 /* 3 - Stream Descriptor Control */ +#define HDAC_SDSTS 0x83 /* 1 - Stream Descriptor Status */ +#define HDAC_SDLPIB 0x84 /* 4 - Link Position in Buffer */ +#define HDAC_SDCBL 0x88 /* 4 - Cyclic Buffer Length */ +#define HDAC_SDLVI 0x8C /* 2 - Last Valid Index */ +#define HDAC_SDFIFOS 0x90 /* 2 - FIFOS */ +#define HDAC_SDFMT 0x92 /* 2 - fmt */ +#define HDAC_SDBDPL 0x98 /* 4 - Buffer Descriptor Pointer Lower Base */ +#define HDAC_SDBDPU 0x9C /* 4 - Buffer Descriptor Pointer Upper Base */ + +#define _HDAC_ISDOFFSET(n, iss, oss) (0x80 + ((n) * 0x20)) +#define _HDAC_ISDCTL(n, iss, oss) (0x00 + _HDAC_ISDOFFSET(n, iss, oss)) +#define _HDAC_ISDSTS(n, iss, oss) (0x03 + _HDAC_ISDOFFSET(n, iss, oss)) +#define _HDAC_ISDPICB(n, iss, oss) (0x04 + _HDAC_ISDOFFSET(n, iss, oss)) +#define _HDAC_ISDCBL(n, iss, oss) (0x08 + _HDAC_ISDOFFSET(n, iss, oss)) +#define _HDAC_ISDLVI(n, iss, oss) (0x0c + _HDAC_ISDOFFSET(n, iss, oss)) +#define _HDAC_ISDFIFOD(n, iss, oss) (0x10 + _HDAC_ISDOFFSET(n, iss, oss)) +#define _HDAC_ISDFMT(n, iss, oss) (0x12 + _HDAC_ISDOFFSET(n, iss, oss)) +#define _HDAC_ISDBDPL(n, iss, oss) (0x18 + _HDAC_ISDOFFSET(n, iss, oss)) +#define _HDAC_ISDBDPU(n, iss, oss) (0x1c + _HDAC_ISDOFFSET(n, iss, oss)) + +#define _HDAC_OSDOFFSET(n, iss, oss) (0x80 + ((iss) * 0x20) + ((n) * 0x20)) +#define _HDAC_OSDCTL(n, iss, oss) (0x00 + _HDAC_OSDOFFSET(n, iss, oss)) +#define _HDAC_OSDSTS(n, iss, oss) (0x03 + _HDAC_OSDOFFSET(n, iss, oss)) +#define _HDAC_OSDPICB(n, iss, oss) (0x04 + _HDAC_OSDOFFSET(n, iss, oss)) +#define _HDAC_OSDCBL(n, iss, oss) (0x08 + _HDAC_OSDOFFSET(n, iss, oss)) +#define _HDAC_OSDLVI(n, iss, oss) (0x0c + _HDAC_OSDOFFSET(n, iss, oss)) +#define _HDAC_OSDFIFOD(n, iss, oss) (0x10 + _HDAC_OSDOFFSET(n, iss, oss)) +#define _HDAC_OSDFMT(n, iss, oss) (0x12 + _HDAC_OSDOFFSET(n, iss, oss)) +#define _HDAC_OSDBDPL(n, iss, oss) (0x18 + _HDAC_OSDOFFSET(n, iss, oss)) +#define _HDAC_OSDBDPU(n, iss, oss) (0x1c + _HDAC_OSDOFFSET(n, iss, oss)) + +/* + * HDA data structures + */ + +struct hda_softc; + +typedef void (*hda_set_reg_handler)(struct hda_softc *sc, uint32_t old); + +struct hda_softc { + uint32_t regs[HDA_LAST_OFFSET]; +}; + +/* + * HDA module function declarations + */ +static void +hda_set_reg_by_offset(struct hda_softc *sc, uint32_t offset, uint32_t value); +static uint32_t +hda_get_reg_by_offset(struct hda_softc *sc, uint32_t offset); +static void +hda_set_field_by_offset(struct hda_softc *sc, uint32_t offset, uint32_t mask, uint32_t value); + +static struct hda_softc *hda_init(const char *opts); +static void hda_reset_regs(struct hda_softc *sc); +static uint32_t +hda_read(struct hda_softc *sc, uint32_t offset); +static int +hda_write(struct hda_softc *sc, uint32_t offset, uint32_t value); + +/* + * PCI HDA function declarations + */ +static int +pci_hda_init(struct vmctx *ctx, struct pci_devinst *pi, char *opts); +static void +pci_hda_write(struct vmctx *ctx, int vcpu, struct pci_devinst *pi, + int baridx, uint64_t offset, int size, uint64_t value); +static uint64_t +pci_hda_read(struct vmctx *ctx, int vcpu, struct pci_devinst *pi, + int baridx, uint64_t offset, int size); +/* + * HDA global data + */ + +static const hda_set_reg_handler hda_set_reg_table[] = { + [HDA_LAST_OFFSET] = NULL, +}; + +struct pci_devemu pci_de_hda = { + .pe_emu = "hda", + .pe_init = pci_hda_init, + .pe_barwrite = pci_hda_write, + .pe_barread = pci_hda_read +}; + +PCI_EMUL_SET(pci_de_hda); + +/* + * HDA module function definitions + */ + +static void +hda_set_reg_by_offset(struct hda_softc *sc, uint32_t offset, uint32_t value) +{ + assert(offset < HDA_LAST_OFFSET); + sc->regs[offset] = value; + + return; +} + +static uint32_t +hda_get_reg_by_offset(struct hda_softc *sc, uint32_t offset) +{ + assert(offset < HDA_LAST_OFFSET); + return sc->regs[offset]; +} + +static void +hda_set_field_by_offset(struct hda_softc *sc, uint32_t offset, uint32_t mask, uint32_t value) +{ + uint32_t reg_value = 0; + + reg_value = hda_get_reg_by_offset(sc, offset); + + reg_value &= ~mask; + reg_value |= value; + + hda_set_reg_by_offset(sc, offset, reg_value); + + return; +} + +static struct hda_softc *hda_init(const char *opts) +{ + struct hda_softc *sc = NULL; + +#if DEBUG_HDA == 1 + dbg = fopen("/tmp/bhyve_hda.log", "w+"); +#endif + + DPRINTF("opts: %s\n", opts); + + sc = calloc(1, sizeof(*sc)); + if (!sc) + return NULL; + + hda_reset_regs(sc); + + return sc; +} + +static void hda_reset_regs(struct hda_softc *sc) +{ + memset(sc->regs, 0, sizeof(sc->regs)); + + hda_set_reg_by_offset(sc, HDAC_GCAP, 0x4401); + hda_set_reg_by_offset(sc, HDAC_CORBSIZE, 0x42); + hda_set_reg_by_offset(sc, HDAC_RIRBSIZE, 0x42); + + return; +} + +static uint32_t +hda_read(struct hda_softc *sc, uint32_t offset) +{ + return hda_get_reg_by_offset(sc, offset); +} + +static int +hda_write(struct hda_softc *sc, uint32_t offset, uint32_t value) +{ + uint32_t old = hda_get_reg_by_offset(sc, offset); + hda_set_reg_handler set_reg_handler = hda_set_reg_table[offset]; + + hda_set_reg_by_offset(sc, offset, value); + + if (set_reg_handler) + set_reg_handler(sc, old); + + return 0; +} + +/* + * PCI HDA function definitions + */ +static int +pci_hda_init(struct vmctx *ctx, struct pci_devinst *pi, char *opts) +{ + struct hda_softc *sc = NULL; + + assert(ctx != NULL); + assert(pi != NULL); + + pci_set_cfgdata16(pi, PCIR_VENDOR, INTEL_VENDORID); + pci_set_cfgdata16(pi, PCIR_DEVICE, HDA_INTEL_82801G); + + pci_set_cfgdata8(pi, PCIR_SUBCLASS, PCIS_MULTIMEDIA_HDA); + pci_set_cfgdata8(pi, PCIR_CLASS, PCIC_MULTIMEDIA); + + /* TODO check the right size */ + /* allocate one BAR register for the Memory address offsets */ + pci_emul_alloc_bar(pi, 0, PCIBAR_MEM32, 0x1000); + + /* allocate an IRQ pin for our slot */ + pci_lintr_request(pi); + + sc = hda_init(opts); + if (!sc) + return -1; + + pi->pi_arg = sc; + + return 0; +} + +static void +pci_hda_write(struct vmctx *ctx, int vcpu, struct pci_devinst *pi, + int baridx, uint64_t offset, int size, uint64_t value) +{ + struct hda_softc *sc = pi->pi_arg; + int err; + + assert(sc); + assert(baridx == 0); + assert(size <= 4); + + DPRINTF("offset: 0x%lx value: 0x%lx\n", offset, value); + + err = hda_write(sc, offset, value); + assert(!err); + + return; +} + +static uint64_t +pci_hda_read(struct vmctx *ctx, int vcpu, struct pci_devinst *pi, + int baridx, uint64_t offset, int size) +{ + struct hda_softc *sc = pi->pi_arg; + uint64_t value = 0; + + assert(sc); + assert(baridx == 0); + assert(size <= 4); + + value = hda_read(sc, offset); + + DPRINTF("offset: 0x%lx value: 0x%lx\n", offset, value); + + return value; +} + + From owner-svn-soc-all@freebsd.org Sat May 14 14:50:12 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 5901FB39FC4 for ; Sat, 14 May 2016 14:50:12 +0000 (UTC) (envelope-from iateaca@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 4D21512ED for ; Sat, 14 May 2016 14:50:12 +0000 (UTC) (envelope-from iateaca@FreeBSD.org) Received: from socsvn.freebsd.org ([127.0.1.124]) by socsvn.freebsd.org (8.15.2/8.15.2) with ESMTP id u4EEoCOR020508 for ; Sat, 14 May 2016 14:50:12 GMT (envelope-from iateaca@FreeBSD.org) Received: (from www@localhost) by socsvn.freebsd.org (8.15.2/8.15.2/Submit) id u4EEoBqF020478 for svn-soc-all@FreeBSD.org; Sat, 14 May 2016 14:50:11 GMT (envelope-from iateaca@FreeBSD.org) Date: Sat, 14 May 2016 14:50:11 GMT Message-Id: <201605141450.u4EEoBqF020478@socsvn.freebsd.org> X-Authentication-Warning: socsvn.freebsd.org: www set sender to iateaca@FreeBSD.org using -f From: iateaca@FreeBSD.org To: svn-soc-all@FreeBSD.org Subject: socsvn commit: r302904 - soc2016/iateaca/bhyve-hda-head/usr.sbin/bhyve 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: Sat, 14 May 2016 14:50:12 -0000 Author: iateaca Date: Sat May 14 14:50:11 2016 New Revision: 302904 URL: http://svnweb.FreeBSD.org/socsvn/?view=rev&rev=302904 Log: add pci_hda.c to Makefile Modified: soc2016/iateaca/bhyve-hda-head/usr.sbin/bhyve/Makefile Modified: soc2016/iateaca/bhyve-hda-head/usr.sbin/bhyve/Makefile ============================================================================== --- soc2016/iateaca/bhyve-hda-head/usr.sbin/bhyve/Makefile Sat May 14 13:44:49 2016 (r302903) +++ soc2016/iateaca/bhyve-hda-head/usr.sbin/bhyve/Makefile Sat May 14 14:50:11 2016 (r302904) @@ -27,6 +27,7 @@ mptbl.c \ pci_ahci.c \ pci_emul.c \ + pci_hda.c \ pci_hostbridge.c \ pci_irq.c \ pci_lpc.c \ From owner-svn-soc-all@freebsd.org Sat May 14 18:26:26 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 7C0EEB3B32C for ; Sat, 14 May 2016 18:26:26 +0000 (UTC) (envelope-from iateaca@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 622D11487 for ; Sat, 14 May 2016 18:26:26 +0000 (UTC) (envelope-from iateaca@FreeBSD.org) Received: from socsvn.freebsd.org ([127.0.1.124]) by socsvn.freebsd.org (8.15.2/8.15.2) with ESMTP id u4EIQQlk064230 for ; Sat, 14 May 2016 18:26:26 GMT (envelope-from iateaca@FreeBSD.org) Received: (from www@localhost) by socsvn.freebsd.org (8.15.2/8.15.2/Submit) id u4EIQPq1064198 for svn-soc-all@FreeBSD.org; Sat, 14 May 2016 18:26:25 GMT (envelope-from iateaca@FreeBSD.org) Date: Sat, 14 May 2016 18:26:25 GMT Message-Id: <201605141826.u4EIQPq1064198@socsvn.freebsd.org> X-Authentication-Warning: socsvn.freebsd.org: www set sender to iateaca@FreeBSD.org using -f From: iateaca@FreeBSD.org To: svn-soc-all@FreeBSD.org Subject: socsvn commit: r302905 - soc2016/iateaca/bhyve-hda-head/usr.sbin/bhyve 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: Sat, 14 May 2016 18:26:26 -0000 Author: iateaca Date: Sat May 14 18:26:25 2016 New Revision: 302905 URL: http://svnweb.FreeBSD.org/socsvn/?view=rev&rev=302905 Log: add inline to the set/get register functions Modified: soc2016/iateaca/bhyve-hda-head/usr.sbin/bhyve/pci_hda.c Modified: soc2016/iateaca/bhyve-hda-head/usr.sbin/bhyve/pci_hda.c ============================================================================== --- soc2016/iateaca/bhyve-hda-head/usr.sbin/bhyve/pci_hda.c Sat May 14 14:50:11 2016 (r302904) +++ soc2016/iateaca/bhyve-hda-head/usr.sbin/bhyve/pci_hda.c Sat May 14 18:26:25 2016 (r302905) @@ -114,11 +114,11 @@ /* * HDA module function declarations */ -static void +static inline void hda_set_reg_by_offset(struct hda_softc *sc, uint32_t offset, uint32_t value); -static uint32_t +static inline uint32_t hda_get_reg_by_offset(struct hda_softc *sc, uint32_t offset); -static void +static inline void hda_set_field_by_offset(struct hda_softc *sc, uint32_t offset, uint32_t mask, uint32_t value); static struct hda_softc *hda_init(const char *opts); @@ -160,7 +160,7 @@ * HDA module function definitions */ -static void +static inline void hda_set_reg_by_offset(struct hda_softc *sc, uint32_t offset, uint32_t value) { assert(offset < HDA_LAST_OFFSET); @@ -169,14 +169,14 @@ return; } -static uint32_t +static inline uint32_t hda_get_reg_by_offset(struct hda_softc *sc, uint32_t offset) { assert(offset < HDA_LAST_OFFSET); return sc->regs[offset]; } -static void +static inline void hda_set_field_by_offset(struct hda_softc *sc, uint32_t offset, uint32_t mask, uint32_t value) { uint32_t reg_value = 0;