From owner-svn-soc-all@freebsd.org Sun Jul 3 16:46:48 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 BB0CDB909DF for ; Sun, 3 Jul 2016 16:46:48 +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 953352108 for ; Sun, 3 Jul 2016 16:46:48 +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 u63Gkmst073674 for ; Sun, 3 Jul 2016 16:46:48 GMT (envelope-from iateaca@FreeBSD.org) Received: (from www@localhost) by socsvn.freebsd.org (8.15.2/8.15.2/Submit) id u63GkmNY073672 for svn-soc-all@FreeBSD.org; Sun, 3 Jul 2016 16:46:48 GMT (envelope-from iateaca@FreeBSD.org) Date: Sun, 3 Jul 2016 16:46:48 GMT Message-Id: <201607031646.u63GkmNY073672@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: r305694 - 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: Sun, 03 Jul 2016 16:46:48 -0000 Author: iateaca Date: Sun Jul 3 16:46:47 2016 New Revision: 305694 URL: http://svnweb.FreeBSD.org/socsvn/?view=rev&rev=305694 Log: fix the hda_write_reg: for one offset allow writes of sizes 1, 2, 3, 4 bytes M bhyve/pci_hda.c 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 Sun Jul 3 15:00:12 2016 (r305693) +++ soc2016/iateaca/bhyve-hda-head/usr.sbin/bhyve/pci_hda.c Sun Jul 3 16:46:47 2016 (r305694) @@ -120,7 +120,7 @@ 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); +hda_write(struct hda_softc *sc, uint32_t offset, uint8_t size, uint32_t value); static void hda_print_cmd_ctl_data(struct hda_codec_cmd_ctl *p); @@ -616,12 +616,13 @@ } static int -hda_write(struct hda_softc *sc, uint32_t offset, uint32_t value) +hda_write(struct hda_softc *sc, uint32_t offset, uint8_t size, uint32_t value) { uint32_t old = hda_get_reg_by_offset(sc, offset); + uint32_t masks[] = {0x00000000, 0x000000ff, 0x0000ffff, 0x00ffffff, 0xffffffff}; hda_set_reg_handler set_reg_handler = hda_set_reg_table[offset]; - hda_set_reg_by_offset(sc, offset, value); + hda_set_field_by_offset(sc, offset, masks[size], value); if (set_reg_handler) set_reg_handler(sc, offset, old); @@ -853,8 +854,6 @@ DPRINTF("stream_ind: 0x%x old: 0x%x value: 0x%x\n", stream_ind, old, value); - hda_set_field_by_offset(sc, offset, 0x00ffff00, old); - if (value & HDAC_SDCTL_SRST) { hda_stream_reset(sc, stream_ind); } @@ -1069,7 +1068,7 @@ DPRINTF("offset: 0x%lx value: 0x%lx\n", offset, value); - err = hda_write(sc, offset, value); + err = hda_write(sc, offset, size, value); assert(!err); return; From owner-svn-soc-all@freebsd.org Sun Jul 3 19:00: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 4FBD1B90ADF for ; Sun, 3 Jul 2016 19:00:27 +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 349DE2565 for ; Sun, 3 Jul 2016 19:00:27 +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 u63J0R0L089392 for ; Sun, 3 Jul 2016 19:00:27 GMT (envelope-from iateaca@FreeBSD.org) Received: (from www@localhost) by socsvn.freebsd.org (8.15.2/8.15.2/Submit) id u63J0Qdl089099 for svn-soc-all@FreeBSD.org; Sun, 3 Jul 2016 19:00:26 GMT (envelope-from iateaca@FreeBSD.org) Date: Sun, 3 Jul 2016 19:00:26 GMT Message-Id: <201607031900.u63J0Qdl089099@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: r305701 - 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: Sun, 03 Jul 2016 19:00:27 -0000 Author: iateaca Date: Sun Jul 3 19:00:26 2016 New Revision: 305701 URL: http://svnweb.FreeBSD.org/socsvn/?view=rev&rev=305701 Log: implement the hda_set_rirbsts function in order to clear the corresponding bits written by the software implement the hda_get_clock_ns function in order to get the time in ns using the clock_gettime(CLOCK_MONOTONIC) update the WALL CLOCK register on read using the hda_get_clock_ns function set the HDAC_SDSTS_FIFORDY bit in the SDSTS register on stream reset M bhyve/pci_hda.c 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 Sun Jul 3 18:27:00 2016 (r305700) +++ soc2016/iateaca/bhyve-hda-head/usr.sbin/bhyve/pci_hda.c Sun Jul 3 19:00:26 2016 (r305701) @@ -1,4 +1,6 @@ +#include + #include "pci_hda.h" #include "bhyverun.h" #include "pci_emul.h" @@ -25,6 +27,11 @@ #define HDA_DMA_ACCESS_LEN (sizeof(uint32_t)) #define HDA_BDL_MAX_LEN 0x0100 +#define HDAC_SDSTS_FIFORDY (1 << 5) + +#define HDA_RIRBSTS_IRQ_MASK (HDAC_RIRBSTS_RINTFL | HDAC_RIRBSTS_RIRBOIS) +#define HDA_SDSTS_IRQ_MASK (HDAC_SDSTS_DESE | HDAC_SDSTS_FIFOE | HDAC_SDSTS_BCIS) + /* * HDA data structures */ @@ -74,6 +81,7 @@ uint32_t regs[HDA_LAST_OFFSET]; uint8_t lintr; + uint64_t wall_clock_start; struct hda_codec_cmd_ctl corb; struct hda_codec_cmd_ctl rirb; @@ -152,6 +160,8 @@ static void hda_set_rirbctl(struct hda_softc *sc, uint32_t offset, uint32_t old); static void +hda_set_rirbsts(struct hda_softc *sc, uint32_t offset, uint32_t old); +static void hda_set_sdctl(struct hda_softc *sc, uint32_t offset, uint32_t old); static void hda_set_sdctl2(struct hda_softc *sc, uint32_t offset, uint32_t old); @@ -165,6 +175,7 @@ static int hda_transfer(struct hda_codec_inst *hci, uint8_t stream, uint8_t dir, void *buf, size_t count); +static uint64_t hda_get_clock_ns(void); /* * PCI HDA function declarations @@ -186,6 +197,7 @@ [HDAC_CORBWP] = hda_set_corbwp, [HDAC_CORBCTL] = hda_set_corbctl, [HDAC_RIRBCTL] = hda_set_rirbctl, + [HDAC_RIRBSTS] = hda_set_rirbsts, #define HDAC_ISTREAM(n, iss, oss) \ [_HDAC_ISDCTL(n, iss, oss)] = hda_set_sdctl, \ @@ -465,6 +477,8 @@ codec->reset(hci); } + sc->wall_clock_start = hda_get_clock_ns(); + return; } @@ -500,6 +514,7 @@ /* Reset the Stream Descriptor */ memset(st, 0, sizeof(*st)); + hda_set_field_by_offset(sc, off + HDAC_SDSTS, HDAC_SDSTS_FIFORDY, HDAC_SDSTS_FIFORDY); hda_set_field_by_offset(sc, off + HDAC_SDCTL0, HDAC_SDCTL_SRST, HDAC_SDCTL_SRST); return; @@ -568,6 +583,8 @@ bdle_desc->addr = bdle_vaddr; bdle_desc->len = bdle_sz; bdle_desc->ioc = bdle->ioc; + + DPRINTF("bdle: 0x%x bdle_sz: 0x%x\n", i, bdle_sz); } sdctl = hda_get_reg_by_offset(sc, off + HDAC_SDCTL0); @@ -612,6 +629,9 @@ static uint32_t hda_read(struct hda_softc *sc, uint32_t offset) { + if (offset == HDAC_WALCLK) + return (24 * (hda_get_clock_ns() - sc->wall_clock_start) / 1000); + return hda_get_reg_by_offset(sc, offset); } @@ -846,6 +866,21 @@ } static void +hda_set_rirbsts(struct hda_softc *sc, uint32_t offset, uint32_t old) +{ + uint32_t value = hda_get_reg_by_offset(sc, offset); + + hda_set_reg_by_offset(sc, offset, old); + + /* clear the corresponding bits written by the software (guest) */ + hda_set_field_by_offset(sc, offset, value & HDA_RIRBSTS_IRQ_MASK, 0); + + hda_update_intr(sc); + + return; +} + +static void hda_set_sdctl(struct hda_softc *sc, uint32_t offset, uint32_t old) { uint8_t stream_ind = hda_get_stream_by_offsets(offset, HDAC_SDCTL0); @@ -886,8 +921,10 @@ { uint32_t value = hda_get_reg_by_offset(sc, offset); + hda_set_reg_by_offset(sc, offset, old); + /* clear the corresponding bits written by the software (guest) */ - hda_set_field_by_offset(sc, offset, value, 0); + hda_set_field_by_offset(sc, offset, value & HDA_SDSTS_IRQ_MASK, 0); hda_update_intr(sc); @@ -966,6 +1003,11 @@ assert(stream < HDA_STREAM_TAGS_CNT); stream_ind = sc->stream_map[stream]; + if (!dir) + assert(stream_ind < HDA_ISS_NO); + else + assert(stream_ind >= HDA_ISS_NO && stream_ind < HDA_IOSS_NO); + st = &sc->streams[stream_ind]; if (!st->run) { DPRINTF("Stream 0x%x stopped\n", stream); @@ -973,7 +1015,6 @@ } assert(st->stream == stream); - assert(st->dir == dir); off = hda_get_offset_stream(stream_ind); @@ -1021,6 +1062,17 @@ return 0; } +static uint64_t hda_get_clock_ns(void) +{ + struct timespec ts; + int err; + + err = clock_gettime(CLOCK_MONOTONIC, &ts); + assert(!err); + + return ts.tv_sec * 1000000000LL + ts.tv_nsec; +} + /* * PCI HDA function definitions */ From owner-svn-soc-all@freebsd.org Mon Jul 4 07:42:07 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 90EC9B91A3F for ; Mon, 4 Jul 2016 07:42:07 +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 8489F24A4 for ; Mon, 4 Jul 2016 07:42:07 +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 u647g7BI047920 for ; Mon, 4 Jul 2016 07:42:07 GMT (envelope-from vincenzo@FreeBSD.org) Received: (from www@localhost) by socsvn.freebsd.org (8.15.2/8.15.2/Submit) id u647g6vA047898 for svn-soc-all@FreeBSD.org; Mon, 4 Jul 2016 07:42:06 GMT (envelope-from vincenzo@FreeBSD.org) Date: Mon, 4 Jul 2016 07:42:06 GMT Message-Id: <201607040742.u647g6vA047898@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: r305704 - 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: Mon, 04 Jul 2016 07:42:07 -0000 Author: vincenzo Date: Mon Jul 4 07:42:06 2016 New Revision: 305704 URL: http://svnweb.FreeBSD.org/socsvn/?view=rev&rev=305704 Log: freebsd: ptnet_transmit: update state variables at each iteration 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 Mon Jul 4 03:19:06 2016 (r305703) +++ soc2016/vincenzo/head/sys/dev/netmap/if_ptnet.c Mon Jul 4 07:42:06 2016 (r305704) @@ -1218,12 +1218,7 @@ kring = na->tx_rings + pq->kring_id; ring = kring->ring; lim = kring->nkr_num_slots - 1; - - /* Initialize transmission state variables. */ head = ring->head; - slot = ring->slot + head; - nmbuf = NMB(na, slot); - nmbuf_bytes = 0; for (;;) { if (head == ring->tail) { @@ -1244,6 +1239,11 @@ break; } + /* Initialize transmission state variables. */ + slot = ring->slot + head; + nmbuf = NMB(na, slot); + nmbuf_bytes = 0; + for (prev_head = head, mf = m; mf; mf = mf->m_next) { uint8_t *mdata = mf->m_data; int mlen = mf->m_len; From owner-svn-soc-all@freebsd.org Mon Jul 4 07:42: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 759A9B91B13 for ; Mon, 4 Jul 2016 07:42:21 +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 695562538 for ; Mon, 4 Jul 2016 07:42:21 +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 u647gLBl048244 for ; Mon, 4 Jul 2016 07:42:21 GMT (envelope-from vincenzo@FreeBSD.org) Received: (from www@localhost) by socsvn.freebsd.org (8.15.2/8.15.2/Submit) id u647gKgg048223 for svn-soc-all@FreeBSD.org; Mon, 4 Jul 2016 07:42:20 GMT (envelope-from vincenzo@FreeBSD.org) Date: Mon, 4 Jul 2016 07:42:20 GMT Message-Id: <201607040742.u647gKgg048223@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: r305705 - 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: Mon, 04 Jul 2016 07:42:21 -0000 Author: vincenzo Date: Mon Jul 4 07:42:20 2016 New Revision: 305705 URL: http://svnweb.FreeBSD.org/socsvn/?view=rev&rev=305705 Log: freebsd: ptnet: obfuscate email 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 Mon Jul 4 07:42:06 2016 (r305704) +++ soc2016/vincenzo/head/sys/dev/netmap/if_ptnet.c Mon Jul 4 07:42:20 2016 (r305705) @@ -1,5 +1,5 @@ /*- - * Copyright (c) 2016, Vincenzo Maffione + * Copyright (c) 2016, Vincenzo Maffione * All rights reserved. * * Redistribution and use in source and binary forms, with or without From owner-svn-soc-all@freebsd.org Mon Jul 4 07:42:32 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 28843B91C21 for ; Mon, 4 Jul 2016 07:42:32 +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 1C49A2576 for ; Mon, 4 Jul 2016 07:42:32 +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 u647gVSC049013 for ; Mon, 4 Jul 2016 07:42:31 GMT (envelope-from vincenzo@FreeBSD.org) Received: (from www@localhost) by socsvn.freebsd.org (8.15.2/8.15.2/Submit) id u647gV3J048973 for svn-soc-all@FreeBSD.org; Mon, 4 Jul 2016 07:42:31 GMT (envelope-from vincenzo@FreeBSD.org) Date: Mon, 4 Jul 2016 07:42:31 GMT Message-Id: <201607040742.u647gV3J048973@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: r305706 - 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: Mon, 04 Jul 2016 07:42:32 -0000 Author: vincenzo Date: Mon Jul 4 07:42:30 2016 New Revision: 305706 URL: http://svnweb.FreeBSD.org/socsvn/?view=rev&rev=305706 Log: freebsd: ptnet_transmit: move doublecheck code in the for loop 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 Mon Jul 4 07:42:20 2016 (r305705) +++ soc2016/vincenzo/head/sys/dev/netmap/if_ptnet.c Mon Jul 4 07:42:30 2016 (r305706) @@ -1228,9 +1228,22 @@ ptnet_sync_tail(ptring, kring); if (head == ring->tail) { - /* Still no slots available, let's stop and - * wait for interrupts. */ - break; + /* Still no slots available. Reactivate the + * interrupts so that we can be notified + * when some free slots are made available by + * the host. */ + ptring->guest_need_kick = 1; + + /* Double-check. */ + ptnet_sync_tail(ptring, kring); + if (likely(head == ring->tail)) { + break; + } + + RD(1, "Found more slots by doublecheck"); + /* More slots were freed before reactivating + * the interrupts. */ + ptring->guest_need_kick = 0; } } @@ -1304,24 +1317,6 @@ ptnet_ring_update(pq, kring, head); } - if (head == ring->tail) { - /* Reactivate the interrupts so that we can be notified - * when some free slots are made available by the host. */ - ptring->guest_need_kick = 1; - - /* Double-check. */ - ptnet_sync_tail(ptring, kring); - if (unlikely(head != ring->tail)) { - RD(1, "Found more slots by doublecheck"); - /* More slots were freed before reactivating - * the interrupts. */ - ptring->guest_need_kick = 0; - if (!drbr_empty(ifp, pq->bufring)) { - taskqueue_enqueue(pq->taskq, &pq->task); - } - } - } - PTNET_Q_UNLOCK(pq); return 0; From owner-svn-soc-all@freebsd.org Mon Jul 4 07:42:40 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 9755EB91C4B for ; Mon, 4 Jul 2016 07:42:40 +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 8ABBA258F for ; Mon, 4 Jul 2016 07:42:40 +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 u647geaq049147 for ; Mon, 4 Jul 2016 07:42:40 GMT (envelope-from vincenzo@FreeBSD.org) Received: (from www@localhost) by socsvn.freebsd.org (8.15.2/8.15.2/Submit) id u647geDi049145 for svn-soc-all@FreeBSD.org; Mon, 4 Jul 2016 07:42:40 GMT (envelope-from vincenzo@FreeBSD.org) Date: Mon, 4 Jul 2016 07:42:40 GMT Message-Id: <201607040742.u647geDi049145@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: r305707 - 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: Mon, 04 Jul 2016 07:42:40 -0000 Author: vincenzo Date: Mon Jul 4 07:42:39 2016 New Revision: 305707 URL: http://svnweb.FreeBSD.org/socsvn/?view=rev&rev=305707 Log: freebsd: introduce PTNET_TX_NOSPACE 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 Mon Jul 4 07:42:30 2016 (r305706) +++ soc2016/vincenzo/head/sys/dev/netmap/if_ptnet.c Mon Jul 4 07:42:39 2016 (r305707) @@ -1164,6 +1164,13 @@ } } +/* This should be computed as MAX_FRAME_SIZE / NETMAP_BUF_SIZE */ +#define PTNET_TX_MIN_SLOTS 33 + +#define PTNET_TX_NOSPACE(h, k) \ + ((((h) < (k)->rtail) ? 0 : (k)->nkr_num_slots) + \ + (k)->rtail - (h)) < PTNET_TX_MIN_SLOTS + static int ptnet_transmit(struct ifnet *ifp, struct mbuf *m) { @@ -1221,13 +1228,13 @@ head = ring->head; for (;;) { - if (head == ring->tail) { + if (PTNET_TX_NOSPACE(head, kring)) { /* We ran out of slot, let's see if the host has * freed up some, by reading hwcur and hwtail from * the CSB. */ ptnet_sync_tail(ptring, kring); - if (head == ring->tail) { + if (PTNET_TX_NOSPACE(head, kring)) { /* Still no slots available. Reactivate the * interrupts so that we can be notified * when some free slots are made available by @@ -1236,7 +1243,7 @@ /* Double-check. */ ptnet_sync_tail(ptring, kring); - if (likely(head == ring->tail)) { + if (likely(PTNET_TX_NOSPACE(head, kring))) { break; } From owner-svn-soc-all@freebsd.org Mon Jul 4 07:43:13 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 F2DF7B91C90 for ; Mon, 4 Jul 2016 07:43:13 +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 D793B25C4 for ; Mon, 4 Jul 2016 07:43:13 +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 u647hDD8049845 for ; Mon, 4 Jul 2016 07:43:13 GMT (envelope-from vincenzo@FreeBSD.org) Received: (from www@localhost) by socsvn.freebsd.org (8.15.2/8.15.2/Submit) id u647hDcY049827 for svn-soc-all@FreeBSD.org; Mon, 4 Jul 2016 07:43:13 GMT (envelope-from vincenzo@FreeBSD.org) Date: Mon, 4 Jul 2016 07:43:13 GMT Message-Id: <201607040743.u647hDcY049827@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: r305708 - 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: Mon, 04 Jul 2016 07:43:14 -0000 Author: vincenzo Date: Mon Jul 4 07:43:12 2016 New Revision: 305708 URL: http://svnweb.FreeBSD.org/socsvn/?view=rev&rev=305708 Log: freebsd: run-time computation of min_tx_space 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 Mon Jul 4 07:42:39 2016 (r305707) +++ soc2016/vincenzo/head/sys/dev/netmap/if_ptnet.c Mon Jul 4 07:43:12 2016 (r305708) @@ -136,6 +136,8 @@ struct ptnet_queue *rxqueues; struct ptnet_csb *csb; + unsigned int min_tx_space; + struct netmap_pt_guest_adapter *ptna_nm; struct netmap_pt_guest_adapter ptna_dr; /* XXX we should move ptna_dr and backend_regifs inside struct @@ -321,6 +323,8 @@ } } + sc->min_tx_space = 64; /* Safe initial value. */ + err = ptnet_irqs_init(sc); if (err) { goto err_path; @@ -698,6 +702,7 @@ { struct ifnet *ifp = sc->ifp; struct netmap_adapter *na_dr = &sc->ptna_dr.hwup.up; + unsigned int nm_buf_size; int ret; if (ifp->if_drv_flags & IFF_DRV_RUNNING) { @@ -742,6 +747,13 @@ goto err_register; } + nm_buf_size = NETMAP_BUF_SIZE(na_dr); + + KASSERT(nm_buf_size > 0, "Invalid netmap buffer size"); + sc->min_tx_space = 65536 / nm_buf_size + 2; + device_printf(sc->dev, "%s: min_tx_space = %u\n", __func__, + sc->min_tx_space); + ifp->if_drv_flags |= IFF_DRV_RUNNING; return 0; @@ -1164,12 +1176,9 @@ } } -/* This should be computed as MAX_FRAME_SIZE / NETMAP_BUF_SIZE */ -#define PTNET_TX_MIN_SLOTS 33 - -#define PTNET_TX_NOSPACE(h, k) \ - ((((h) < (k)->rtail) ? 0 : (k)->nkr_num_slots) + \ - (k)->rtail - (h)) < PTNET_TX_MIN_SLOTS +#define PTNET_TX_NOSPACE(_h, _k, _min) \ + ((((_h) < (_k)->rtail) ? 0 : (_k)->nkr_num_slots) + \ + (_k)->rtail - (_h)) < (_min) static int ptnet_transmit(struct ifnet *ifp, struct mbuf *m) @@ -1183,6 +1192,7 @@ struct netmap_slot *slot; struct ptnet_queue *pq; unsigned int prev_head; + unsigned int minspace; unsigned int head; unsigned int lim; struct mbuf *mf; @@ -1226,15 +1236,16 @@ ring = kring->ring; lim = kring->nkr_num_slots - 1; head = ring->head; + minspace = sc->min_tx_space; for (;;) { - if (PTNET_TX_NOSPACE(head, kring)) { + if (PTNET_TX_NOSPACE(head, kring, minspace)) { /* We ran out of slot, let's see if the host has * freed up some, by reading hwcur and hwtail from * the CSB. */ ptnet_sync_tail(ptring, kring); - if (PTNET_TX_NOSPACE(head, kring)) { + if (PTNET_TX_NOSPACE(head, kring, minspace)) { /* Still no slots available. Reactivate the * interrupts so that we can be notified * when some free slots are made available by @@ -1243,7 +1254,8 @@ /* Double-check. */ ptnet_sync_tail(ptring, kring); - if (likely(PTNET_TX_NOSPACE(head, kring))) { + if (likely(PTNET_TX_NOSPACE(head, kring, + minspace))) { break; } From owner-svn-soc-all@freebsd.org Mon Jul 4 07:43:23 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 2D86BB91CBA for ; Mon, 4 Jul 2016 07:43:23 +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 213C925D6 for ; Mon, 4 Jul 2016 07:43:23 +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 u647hM3p050052 for ; Mon, 4 Jul 2016 07:43:23 GMT (envelope-from vincenzo@FreeBSD.org) Received: (from www@localhost) by socsvn.freebsd.org (8.15.2/8.15.2/Submit) id u647hMcp050050 for svn-soc-all@FreeBSD.org; Mon, 4 Jul 2016 07:43:22 GMT (envelope-from vincenzo@FreeBSD.org) Date: Mon, 4 Jul 2016 07:43:22 GMT Message-Id: <201607040743.u647hMcp050050@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: r305709 - 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: Mon, 04 Jul 2016 07:43:23 -0000 Author: vincenzo Date: Mon Jul 4 07:43:22 2016 New Revision: 305709 URL: http://svnweb.FreeBSD.org/socsvn/?view=rev&rev=305709 Log: freebsd: ptnet_transmit: assert we cannot run out of slots while transmitting 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 Mon Jul 4 07:43:12 2016 (r305708) +++ soc2016/vincenzo/head/sys/dev/netmap/if_ptnet.c Mon Jul 4 07:43:22 2016 (r305709) @@ -1301,16 +1301,8 @@ slot->flags = NS_MOREFRAG; head = nm_next(head, lim); - if (head == ring->tail) { - /* Run out of slots while processing - * a packet. Reset head to the previous - * position and requeue the mbuf. */ - RD(1, "%s: Drop, no free slots\n", - __func__); - head = prev_head; - drbr_putback(ifp, pq->bufring, m); - goto escape; - } + KASSERT(head != rina->tail, + "Unexpectedly run out of TX space"); slot = ring->slot + head; nmbuf = NMB(na, slot); nmbuf_bytes = 0; @@ -1331,7 +1323,7 @@ ptnet_ring_update(pq, kring, head); } } -escape: + if (batch_count) { ptnet_ring_update(pq, kring, head); } From owner-svn-soc-all@freebsd.org Mon Jul 4 07:43:31 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 E2447B91CD5 for ; Mon, 4 Jul 2016 07:43:31 +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 D5EE025E7 for ; Mon, 4 Jul 2016 07:43:31 +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 u647hVaE050235 for ; Mon, 4 Jul 2016 07:43:31 GMT (envelope-from vincenzo@FreeBSD.org) Received: (from www@localhost) by socsvn.freebsd.org (8.15.2/8.15.2/Submit) id u647hVIb050208 for svn-soc-all@FreeBSD.org; Mon, 4 Jul 2016 07:43:31 GMT (envelope-from vincenzo@FreeBSD.org) Date: Mon, 4 Jul 2016 07:43:31 GMT Message-Id: <201607040743.u647hVIb050208@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: r305710 - 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: Mon, 04 Jul 2016 07:43:32 -0000 Author: vincenzo Date: Mon Jul 4 07:43:30 2016 New Revision: 305710 URL: http://svnweb.FreeBSD.org/socsvn/?view=rev&rev=305710 Log: freebsd: ptnet_transmit: remove obsolete prev_head variable 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 Mon Jul 4 07:43:22 2016 (r305709) +++ soc2016/vincenzo/head/sys/dev/netmap/if_ptnet.c Mon Jul 4 07:43:30 2016 (r305710) @@ -1191,7 +1191,6 @@ struct netmap_ring *ring; struct netmap_slot *slot; struct ptnet_queue *pq; - unsigned int prev_head; unsigned int minspace; unsigned int head; unsigned int lim; @@ -1276,7 +1275,7 @@ nmbuf = NMB(na, slot); nmbuf_bytes = 0; - for (prev_head = head, mf = m; mf; mf = mf->m_next) { + for (mf = m; mf; mf = mf->m_next) { uint8_t *mdata = mf->m_data; int mlen = mf->m_len; From owner-svn-soc-all@freebsd.org Mon Jul 4 07:43:41 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 38B66B91CF2 for ; Mon, 4 Jul 2016 07:43:41 +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 2C6AD2600 for ; Mon, 4 Jul 2016 07:43:41 +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 u647hf4A050425 for ; Mon, 4 Jul 2016 07:43:41 GMT (envelope-from vincenzo@FreeBSD.org) Received: (from www@localhost) by socsvn.freebsd.org (8.15.2/8.15.2/Submit) id u647heah050422 for svn-soc-all@FreeBSD.org; Mon, 4 Jul 2016 07:43:40 GMT (envelope-from vincenzo@FreeBSD.org) Date: Mon, 4 Jul 2016 07:43:40 GMT Message-Id: <201607040743.u647heah050422@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: r305711 - 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: Mon, 04 Jul 2016 07:43:41 -0000 Author: vincenzo Date: Mon Jul 4 07:43:40 2016 New Revision: 305711 URL: http://svnweb.FreeBSD.org/socsvn/?view=rev&rev=305711 Log: freebsd: introduce ptnet_drain_transmit_queue 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 Mon Jul 4 07:43:30 2016 (r305710) +++ soc2016/vincenzo/head/sys/dev/netmap/if_ptnet.c Mon Jul 4 07:43:40 2016 (r305711) @@ -159,6 +159,7 @@ static int ptnet_init_locked(struct ptnet_softc *sc); static int ptnet_stop(struct ptnet_softc *sc); static int ptnet_transmit(struct ifnet *ifp, struct mbuf *m); +static int ptnet_drain_transmit_queue(struct ptnet_queue *pq); static void ptnet_qflush(struct ifnet *ifp); static void ptnet_tx_task(void *context, int pending); @@ -1181,47 +1182,32 @@ (_k)->rtail - (_h)) < (_min) static int -ptnet_transmit(struct ifnet *ifp, struct mbuf *m) +ptnet_drain_transmit_queue(struct ptnet_queue *pq) { - struct ptnet_softc *sc = ifp->if_softc; + struct ptnet_softc *sc = pq->sc; struct netmap_adapter *na = &sc->ptna_dr.hwup.up; + struct ifnet *ifp = sc->ifp; unsigned int batch_count = 0; struct ptnet_ring *ptring; struct netmap_kring *kring; struct netmap_ring *ring; struct netmap_slot *slot; - struct ptnet_queue *pq; unsigned int minspace; unsigned int head; unsigned int lim; + struct mbuf *mhead; struct mbuf *mf; int nmbuf_bytes; uint8_t *nmbuf; - DBG(device_printf(sc->dev, "transmit %p\n", m)); - - pq = sc->queues + 0; - - if (m) { - int err; - - /* Here we are called by the network stack, and not by - * by the taskqueue thread. */ - err = drbr_enqueue(ifp, pq->bufring, m); - m = NULL; /* just to stay safe */ - if (err) { - /* ENOBUFS when the bufring is full */ - RD(1, "%s: drbr_enqueue() failed %d\n", - __func__, err); - return err; - } - } - if (unlikely(!(ifp->if_drv_flags & IFF_DRV_RUNNING))) { RD(1, "Interface is down"); return ENETDOWN; } + /* Here we may be called by the network stack, or by + * by the taskqueue thread. */ + if (!PTNET_Q_TRYLOCK(pq)) { /* We failed to acquire the lock, schedule the taskqueue. */ RD(1, "Deferring TX work"); @@ -1265,8 +1251,8 @@ } } - m = drbr_peek(ifp, pq->bufring); - if (!m) { + mhead = drbr_peek(ifp, pq->bufring); + if (!mhead) { break; } @@ -1275,7 +1261,7 @@ nmbuf = NMB(na, slot); nmbuf_bytes = 0; - for (mf = m; mf; mf = mf->m_next) { + for (mf = mhead; mf; mf = mf->m_next) { uint8_t *mdata = mf->m_data; int mlen = mf->m_len; @@ -1315,7 +1301,7 @@ /* Consume the packet just processed. */ drbr_advance(ifp, pq->bufring); - m_freem(m); + m_freem(mhead); if (++batch_count == PTNET_TX_BATCH) { batch_count = 0; @@ -1333,6 +1319,28 @@ } static int +ptnet_transmit(struct ifnet *ifp, struct mbuf *m) +{ + struct ptnet_softc *sc = ifp->if_softc; + struct ptnet_queue *pq; + int err; + + DBG(device_printf(sc->dev, "transmit %p\n", m)); + + pq = sc->queues + 0; + + err = drbr_enqueue(ifp, pq->bufring, m); + if (err) { + /* ENOBUFS when the bufring is full */ + RD(1, "%s: drbr_enqueue() failed %d\n", + __func__, err); + return err; + } + + return ptnet_drain_transmit_queue(pq); +} + +static int ptnet_rx_eof(struct ptnet_queue *pq) { struct ptnet_softc *sc = pq->sc; @@ -1468,6 +1476,6 @@ struct ptnet_queue *pq = context; RD(1, "%s: pq #%u\n", __func__, pq->kring_id); - ptnet_transmit(pq->sc->ifp, NULL); + ptnet_drain_transmit_queue(pq); } From owner-svn-soc-all@freebsd.org Mon Jul 4 07:43:55 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 93A69B91D08 for ; Mon, 4 Jul 2016 07:43:55 +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 6EF07261B for ; Mon, 4 Jul 2016 07:43:55 +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 u647htw6050727 for ; Mon, 4 Jul 2016 07:43:55 GMT (envelope-from vincenzo@FreeBSD.org) Received: (from www@localhost) by socsvn.freebsd.org (8.15.2/8.15.2/Submit) id u647hsot050724 for svn-soc-all@FreeBSD.org; Mon, 4 Jul 2016 07:43:54 GMT (envelope-from vincenzo@FreeBSD.org) Date: Mon, 4 Jul 2016 07:43:54 GMT Message-Id: <201607040743.u647hsot050724@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: r305712 - 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: Mon, 04 Jul 2016 07:43:55 -0000 Author: vincenzo Date: Mon Jul 4 07:43:54 2016 New Revision: 305712 URL: http://svnweb.FreeBSD.org/socsvn/?view=rev&rev=305712 Log: freebsd: ptnet_transmit: add support for multi-queue 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 Mon Jul 4 07:43:40 2016 (r305711) +++ soc2016/vincenzo/head/sys/dev/netmap/if_ptnet.c Mon Jul 4 07:43:54 2016 (r305712) @@ -132,6 +132,7 @@ struct resource *msix_mem; unsigned int num_rings; + unsigned int num_tx_rings; struct ptnet_queue *queues; struct ptnet_queue *rxqueues; struct ptnet_csb *csb; @@ -290,6 +291,7 @@ num_tx_rings = bus_read_4(sc->iomem, PTNET_IO_NUM_TX_RINGS); num_rx_rings = bus_read_4(sc->iomem, PTNET_IO_NUM_RX_RINGS); sc->num_rings = num_tx_rings + num_rx_rings; + sc->num_tx_rings = num_tx_rings; /* Allocate and initialize per-queue data structures. */ sc->queues = malloc(sizeof(struct ptnet_queue) * sc->num_rings, @@ -522,14 +524,11 @@ { 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 cpu_cur; int i; - num_tx_rings = bus_read_4(sc->iomem, PTNET_IO_NUM_TX_RINGS); - if (pci_find_cap(dev, PCIY_MSIX, NULL) != 0) { device_printf(dev, "Could not find MSI-X capability\n"); return (ENXIO); @@ -572,7 +571,7 @@ struct ptnet_queue *pq = sc->queues + i; void (*handler)(void *) = ptnet_tx_intr; - if (i >= num_tx_rings) { + if (i >= sc->num_tx_rings) { handler = ptnet_rx_intr; } err = bus_setup_intr(dev, pq->irq, INTR_TYPE_NET | INTR_MPSAFE, @@ -598,7 +597,7 @@ struct ptnet_queue *pq = sc->queues + i; static void (*handler)(void *context, int pending); - handler = (i < num_tx_rings) ? ptnet_tx_task : ptnet_rx_task; + handler = (i < sc->num_tx_rings) ? ptnet_tx_task : ptnet_rx_task; TASK_INIT(&pq->task, 0, handler, pq); pq->taskq = taskqueue_create_fast("ptnet_queue", M_NOWAIT, @@ -1323,11 +1322,20 @@ { struct ptnet_softc *sc = ifp->if_softc; struct ptnet_queue *pq; + unsigned int queue_idx; int err; DBG(device_printf(sc->dev, "transmit %p\n", m)); - pq = sc->queues + 0; + /* Get the flow-id if available. */ + queue_idx = (M_HASHTYPE_GET(m) != M_HASHTYPE_NONE) ? + m->m_pkthdr.flowid : curcpu; + + if (unlikely(queue_idx >= sc->num_tx_rings)) { + queue_idx %= sc->num_tx_rings; + } + + pq = sc->queues + queue_idx; err = drbr_enqueue(ifp, pq->bufring, m); if (err) { From owner-svn-soc-all@freebsd.org Mon Jul 4 07:44:04 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 E081FB91D1D for ; Mon, 4 Jul 2016 07:44:04 +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 CBB06262E for ; Mon, 4 Jul 2016 07:44:04 +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 u647i4f7051043 for ; Mon, 4 Jul 2016 07:44:04 GMT (envelope-from vincenzo@FreeBSD.org) Received: (from www@localhost) by socsvn.freebsd.org (8.15.2/8.15.2/Submit) id u647i4nH051010 for svn-soc-all@FreeBSD.org; Mon, 4 Jul 2016 07:44:04 GMT (envelope-from vincenzo@FreeBSD.org) Date: Mon, 4 Jul 2016 07:44:04 GMT Message-Id: <201607040744.u647i4nH051010@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: r305713 - 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: Mon, 04 Jul 2016 07:44:05 -0000 Author: vincenzo Date: Mon Jul 4 07:44:03 2016 New Revision: 305713 URL: http://svnweb.FreeBSD.org/socsvn/?view=rev&rev=305713 Log: freebsd: ptnet_transmit: support VLAN encapsulation 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 Mon Jul 4 07:43:54 2016 (r305712) +++ soc2016/vincenzo/head/sys/dev/netmap/if_ptnet.c Mon Jul 4 07:44:03 2016 (r305713) @@ -1327,6 +1327,15 @@ DBG(device_printf(sc->dev, "transmit %p\n", m)); + /* Insert 802.1Q header if needed. */ + if (m->m_flags & M_VLANTAG) { + m = ether_vlanencap(m, m->m_pkthdr.ether_vtag); + if (m == NULL) { + return ENOBUFS; + } + m->m_flags &= ~M_VLANTAG; + } + /* Get the flow-id if available. */ queue_idx = (M_HASHTYPE_GET(m) != M_HASHTYPE_NONE) ? m->m_pkthdr.flowid : curcpu; From owner-svn-soc-all@freebsd.org Fri Jul 8 15:42:41 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 6464DB82421 for ; Fri, 8 Jul 2016 15:42:41 +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 578F31EAD for ; Fri, 8 Jul 2016 15:42:41 +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 u68Fgf1q005957 for ; Fri, 8 Jul 2016 15:42:41 GMT (envelope-from vincenzo@FreeBSD.org) Received: (from www@localhost) by socsvn.freebsd.org (8.15.2/8.15.2/Submit) id u68Fge5j005917 for svn-soc-all@FreeBSD.org; Fri, 8 Jul 2016 15:42:40 GMT (envelope-from vincenzo@FreeBSD.org) Date: Fri, 8 Jul 2016 15:42:40 GMT Message-Id: <201607081542.u68Fge5j005917@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: r305818 - 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: Fri, 08 Jul 2016 15:42:41 -0000 Author: vincenzo Date: Fri Jul 8 15:42:40 2016 New Revision: 305818 URL: http://svnweb.FreeBSD.org/socsvn/?view=rev&rev=305818 Log: freebsd: ptnet_drain_transmit_queue: add virtio-net-header support 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 Fri Jul 8 13:29:47 2016 (r305817) +++ soc2016/vincenzo/head/sys/dev/netmap/if_ptnet.c Fri Jul 8 15:42:40 2016 (r305818) @@ -80,6 +80,7 @@ #include #include #include +#include #ifndef PTNET_CSB_ALLOC #error "No support for on-device CSB" @@ -224,7 +225,12 @@ #define PTNET_BUF_RING_SIZE 4096 #define PTNET_RX_BUDGET 512 #define PTNET_TX_BATCH 64 +#define PTNET_HDR_SIZE sizeof(struct virtio_net_hdr_mrg_rxbuf) +#define PTNET_CSUM_OFFLOAD (CSUM_TCP | CSUM_UDP | CSUM_SCTP) +#define PTNET_CSUM_OFFLOAD_IPV6 (CSUM_TCP_IPV6 | CSUM_UDP_IPV6 |\ + CSUM_SCTP_IPV6) +#define PTNET_ALL_OFFLOAD (CSUM_TSO | PTNET_CSUM_OFFLOAD | CSUM_TSO) static int ptnet_attach(device_t dev) @@ -1140,6 +1146,150 @@ ptnet_rx_eof(pq); } +/* The following three functions are taken from the virtio-net driver, but + * the same functionality applies to the ptnet driver. + * As a temporary solution, I copied this code from virtio-net and I started + * to generalize it (taking away driver-specific statistic accounting), + * making as little modifications as possible. + * In the future we need to share these functions between virtio-net and ptnet. + */ +static int +ptnet_tx_offload_ctx(struct mbuf *m, int *etype, int *proto, int *start) +{ + struct ether_vlan_header *evh; + int offset; + + evh = mtod(m, struct ether_vlan_header *); + if (evh->evl_encap_proto == htons(ETHERTYPE_VLAN)) { + /* BMV: We should handle nested VLAN tags too. */ + *etype = ntohs(evh->evl_proto); + offset = sizeof(struct ether_vlan_header); + } else { + *etype = ntohs(evh->evl_encap_proto); + offset = sizeof(struct ether_header); + } + + switch (*etype) { +#if defined(INET) + case ETHERTYPE_IP: { + struct ip *ip, iphdr; + if (__predict_false(m->m_len < offset + sizeof(struct ip))) { + m_copydata(m, offset, sizeof(struct ip), + (caddr_t) &iphdr); + ip = &iphdr; + } else + ip = (struct ip *)(m->m_data + offset); + *proto = ip->ip_p; + *start = offset + (ip->ip_hl << 2); + break; + } +#endif +#if defined(INET6) + case ETHERTYPE_IPV6: + *proto = -1; + *start = ip6_lasthdr(m, offset, IPPROTO_IPV6, proto); + /* Assert the network stack sent us a valid packet. */ + KASSERT(*start > offset, + ("%s: mbuf %p start %d offset %d proto %d", __func__, m, + *start, offset, *proto)); + break; +#endif + default: + /* Here we should increment the tx_csum_bad_ethtype counter. */ + return (EINVAL); + } + + return (0); +} + +static int +ptnet_tx_offload_tso(struct ifnet *ifp, struct mbuf *m, int eth_type, + int offset, bool allow_ecn, struct virtio_net_hdr *hdr) +{ + static struct timeval lastecn; + static int curecn; + struct tcphdr *tcp, tcphdr; + + if (__predict_false(m->m_len < offset + sizeof(struct tcphdr))) { + m_copydata(m, offset, sizeof(struct tcphdr), (caddr_t) &tcphdr); + tcp = &tcphdr; + } else + tcp = (struct tcphdr *)(m->m_data + offset); + + hdr->hdr_len = offset + (tcp->th_off << 2); + hdr->gso_size = m->m_pkthdr.tso_segsz; + hdr->gso_type = eth_type == ETHERTYPE_IP ? VIRTIO_NET_HDR_GSO_TCPV4 : + VIRTIO_NET_HDR_GSO_TCPV6; + + if (tcp->th_flags & TH_CWR) { + /* + * Drop if VIRTIO_NET_F_HOST_ECN was not negotiated. In FreeBSD, + * ECN support is not on a per-interface basis, but globally via + * the net.inet.tcp.ecn.enable sysctl knob. The default is off. + */ + if (!allow_ecn) { + if (ppsratecheck(&lastecn, &curecn, 1)) + if_printf(ifp, + "TSO with ECN not negotiated with host\n"); + return (ENOTSUP); + } + hdr->gso_type |= VIRTIO_NET_HDR_GSO_ECN; + } + + /* Here we should increment tx_tso counter. */ + + return (0); +} + +static struct mbuf * +ptnet_tx_offload(struct ifnet *ifp, struct mbuf *m, bool allow_ecn, + struct virtio_net_hdr *hdr) +{ + int flags, etype, csum_start, proto, error; + + flags = m->m_pkthdr.csum_flags; + + error = ptnet_tx_offload_ctx(m, &etype, &proto, &csum_start); + if (error) + goto drop; + + if ((etype == ETHERTYPE_IP && flags & PTNET_CSUM_OFFLOAD) || + (etype == ETHERTYPE_IPV6 && flags & PTNET_CSUM_OFFLOAD_IPV6)) { + /* + * We could compare the IP protocol vs the CSUM_ flag too, + * but that really should not be necessary. + */ + hdr->flags |= VIRTIO_NET_HDR_F_NEEDS_CSUM; + hdr->csum_start = csum_start; + hdr->csum_offset = m->m_pkthdr.csum_data; + /* Here we should increment the tx_csum counter. */ + } + + if (flags & CSUM_TSO) { + if (__predict_false(proto != IPPROTO_TCP)) { + /* Likely failed to correctly parse the mbuf. + * Here we should increment the tx_tso_not_tcp + * counter. */ + goto drop; + } + + KASSERT(hdr->flags & VIRTIO_NET_HDR_F_NEEDS_CSUM, + ("%s: mbuf %p TSO without checksum offload %#x", + __func__, m, flags)); + + error = ptnet_tx_offload_tso(ifp, m, etype, csum_start, + allow_ecn, hdr); + if (error) + goto drop; + } + + return (m); + +drop: + m_freem(m); + return (NULL); +} + static inline void ptnet_sync_tail(struct ptnet_ring *ptring, struct netmap_kring *kring) { @@ -1260,6 +1410,29 @@ nmbuf = NMB(na, slot); nmbuf_bytes = 0; + /* If needed, prepare the virtio-net header at the beginning + * of the first slot. */ + if (sc->ptfeatures & NET_PTN_FEATURES_VNET_HDR) { + /* For performance, we could replace this memset() with + * two 8-bytes-wide writes. */ + memset(nmbuf, 0, PTNET_HDR_SIZE); + if (mhead->m_pkthdr.csum_flags & PTNET_ALL_OFFLOAD) { + mhead = ptnet_tx_offload(ifp, mhead, false, + (struct virtio_net_hdr *)nmbuf); + if (unlikely(!mhead)) { + /* Packet dropped because errors + * occurred while preparing the vnet + * header. Let's go ahead with the next + * packet. */ + drbr_advance(ifp, pq->bufring); + continue; + } + } + + nmbuf += PTNET_HDR_SIZE; + nmbuf_bytes += PTNET_HDR_SIZE; + } + for (mf = mhead; mf; mf = mf->m_next) { uint8_t *mdata = mf->m_data; int mlen = mf->m_len; From owner-svn-soc-all@freebsd.org Fri Jul 8 15:42:51 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 25BA9B8244C for ; Fri, 8 Jul 2016 15:42:51 +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 194B61EC7 for ; Fri, 8 Jul 2016 15:42:51 +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 u68Fgoev006177 for ; Fri, 8 Jul 2016 15:42:50 GMT (envelope-from vincenzo@FreeBSD.org) Received: (from www@localhost) by socsvn.freebsd.org (8.15.2/8.15.2/Submit) id u68Fgogs006175 for svn-soc-all@FreeBSD.org; Fri, 8 Jul 2016 15:42:50 GMT (envelope-from vincenzo@FreeBSD.org) Date: Fri, 8 Jul 2016 15:42:50 GMT Message-Id: <201607081542.u68Fgogs006175@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: r305819 - 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: Fri, 08 Jul 2016 15:42:51 -0000 Author: vincenzo Date: Fri Jul 8 15:42:49 2016 New Revision: 305819 URL: http://svnweb.FreeBSD.org/socsvn/?view=rev&rev=305819 Log: freebsd: ptnet_stop: comment about an issue to be addressed 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 Fri Jul 8 15:42:40 2016 (r305818) +++ soc2016/vincenzo/head/sys/dev/netmap/if_ptnet.c Fri Jul 8 15:42:49 2016 (r305819) @@ -789,6 +789,8 @@ return 0; /* nothing to do */ } + /* XXX Here we should wait for all TX and RX worker to finish. */ + ptnet_nm_register(na_dr, 0 /* off */); if (sc->backend_regifs == 0) { From owner-svn-soc-all@freebsd.org Fri Jul 8 15:43:00 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 5E14FB82485 for ; Fri, 8 Jul 2016 15:43:00 +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 516941002 for ; Fri, 8 Jul 2016 15:43:00 +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 u68Fh0mr006473 for ; Fri, 8 Jul 2016 15:43:00 GMT (envelope-from vincenzo@FreeBSD.org) Received: (from www@localhost) by socsvn.freebsd.org (8.15.2/8.15.2/Submit) id u68FgxXZ006407 for svn-soc-all@FreeBSD.org; Fri, 8 Jul 2016 15:42:59 GMT (envelope-from vincenzo@FreeBSD.org) Date: Fri, 8 Jul 2016 15:42:59 GMT Message-Id: <201607081542.u68FgxXZ006407@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: r305820 - 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: Fri, 08 Jul 2016 15:43:00 -0000 Author: vincenzo Date: Fri Jul 8 15:42:59 2016 New Revision: 305820 URL: http://svnweb.FreeBSD.org/socsvn/?view=rev&rev=305820 Log: freebsd: ptnet_rx_eof: set flowid using the queue idx 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 Fri Jul 8 15:42:49 2016 (r305819) +++ soc2016/vincenzo/head/sys/dev/netmap/if_ptnet.c Fri Jul 8 15:42:59 2016 (r305820) @@ -1612,6 +1612,10 @@ memcpy(mtod(m, void *), nmbuf, nmbuf_len); + /* Store the queue idx in the packet header. */ + m->m_pkthdr.flowid = pq->kring_id; + M_HASHTYPE_SET(m, M_HASHTYPE_OPAQUE); + PTNET_Q_UNLOCK(pq); (*ifp->if_input)(ifp, m); PTNET_Q_LOCK(pq); From owner-svn-soc-all@freebsd.org Fri Jul 8 15:43:11 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 A173AB824A8 for ; Fri, 8 Jul 2016 15:43:11 +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 94D1F1137 for ; Fri, 8 Jul 2016 15:43:11 +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 u68FhBbJ006697 for ; Fri, 8 Jul 2016 15:43:11 GMT (envelope-from vincenzo@FreeBSD.org) Received: (from www@localhost) by socsvn.freebsd.org (8.15.2/8.15.2/Submit) id u68FhAIm006637 for svn-soc-all@FreeBSD.org; Fri, 8 Jul 2016 15:43:10 GMT (envelope-from vincenzo@FreeBSD.org) Date: Fri, 8 Jul 2016 15:43:10 GMT Message-Id: <201607081543.u68FhAIm006637@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: r305821 - 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: Fri, 08 Jul 2016 15:43:11 -0000 Author: vincenzo Date: Fri Jul 8 15:43:10 2016 New Revision: 305821 URL: http://svnweb.FreeBSD.org/socsvn/?view=rev&rev=305821 Log: freebsd: ptnet_rx_eof: handle mbuf chains 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 Fri Jul 8 15:42:59 2016 (r305820) +++ soc2016/vincenzo/head/sys/dev/netmap/if_ptnet.c Fri Jul 8 15:43:10 2016 (r305821) @@ -1550,10 +1550,10 @@ kring->nr_kflags &= ~NKR_PENDINTR; for (;;) { - struct netmap_slot *slot = ring->slot + head; + struct netmap_slot *slot; unsigned int nmbuf_len; - struct mbuf *m; - uint8_t *nmbuf; + struct mbuf *mhead, *mtail; + uint8_t *nmbuf, *mdata; if (budget == 0) { RD(1, "Run out of budget h %u t %u", head, ring->tail); @@ -1582,45 +1582,79 @@ } } - nmbuf_len = slot->len; - nmbuf = NMB(na, slot); - - if (unlikely(nmbuf_len > MCLBYTES)) { - RD(1, "Dropping long frame: len %u > %u", - nmbuf_len, MCLBYTES); - continue; - } - - DBG(device_printf(sc->dev, "%s: h %u t %u rcv frame len %u\n", - __func__, head, ring->tail, nmbuf_len)); - - /* We use m_getcl() to allocate an mbuf with standard - * cluster size (MCLBYTES). In the future we could use m_getjcl() + /* We use m_getcl() to allocate an mbuf with standard cluster + * size (MCLBYTES). In the future we could use m_getjcl() * to choose different sizes. */ - m = m_getcl(M_NOWAIT, MT_DATA, M_PKTHDR); - if (unlikely(m == NULL)) { - device_printf(sc->dev, "%s: failed to allocate mbuf" - "(len=%d)\n", __func__, nmbuf_len); + mhead = mtail = m_getcl(M_NOWAIT, MT_DATA, M_PKTHDR); + if (unlikely(mhead == NULL)) { + device_printf(sc->dev, "%s: failed to allocate mbuf\n", + __func__); break; } - m->m_pkthdr.rcvif = ifp; - m->m_len = m->m_pkthdr.len = nmbuf_len; + mhead->m_pkthdr.rcvif = ifp; + mhead->m_pkthdr.len = 0; /* No support for checksum offloading for now. */ - m->m_pkthdr.csum_flags = 0; - - memcpy(mtod(m, void *), nmbuf, nmbuf_len); + mhead->m_pkthdr.csum_flags = 0; /* Store the queue idx in the packet header. */ - m->m_pkthdr.flowid = pq->kring_id; - M_HASHTYPE_SET(m, M_HASHTYPE_OPAQUE); + mhead->m_pkthdr.flowid = pq->kring_id; + M_HASHTYPE_SET(mhead, M_HASHTYPE_OPAQUE); + + /* Initialize state variables. */ + mdata = mtod(mtail, uint8_t *); + mtail->m_len = 0; + + do { + slot = ring->slot + head; + nmbuf_len = slot->len; + nmbuf = NMB(na, slot); + + mhead->m_pkthdr.len += nmbuf_len; + + DBG(device_printf(sc->dev, "%s: h %u t %u rcv frag " + "len %u, flags %u\n", __func__, + head, ring->tail, nmbuf_len, + slot->flags)); + + do { + unsigned int copy; + + if (mtail->m_len == MCLBYTES) { + struct mbuf *mf; + + mf = m_getcl(M_NOWAIT, MT_DATA, 0); + if (!mf) { + /* XXX handle error */ + break; + } + mtail->m_next = mf; + mtail = mf; + mdata = mtod(mtail, uint8_t *); + mtail->m_len = 0; + } + + copy = MCLBYTES - mtail->m_len; + if (nmbuf_len < copy) { + copy = nmbuf_len; + } + + memcpy(mdata, nmbuf, copy); + + nmbuf += copy; + nmbuf_len -= copy; + mdata += copy; + mtail->m_len += copy; + } while (nmbuf_len); + + head = nm_next(head, lim); + } while (slot->flags & NS_MOREFRAG); PTNET_Q_UNLOCK(pq); - (*ifp->if_input)(ifp, m); + (*ifp->if_input)(ifp, mhead); PTNET_Q_LOCK(pq); - head = nm_next(head, lim); budget--; } From owner-svn-soc-all@freebsd.org Fri Jul 8 15:43:20 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 5E41DB824BE for ; Fri, 8 Jul 2016 15:43:20 +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 4377D114B for ; Fri, 8 Jul 2016 15:43:20 +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 u68FhKfC006933 for ; Fri, 8 Jul 2016 15:43:20 GMT (envelope-from vincenzo@FreeBSD.org) Received: (from www@localhost) by socsvn.freebsd.org (8.15.2/8.15.2/Submit) id u68FhJlj006863 for svn-soc-all@FreeBSD.org; Fri, 8 Jul 2016 15:43:19 GMT (envelope-from vincenzo@FreeBSD.org) Date: Fri, 8 Jul 2016 15:43:19 GMT Message-Id: <201607081543.u68FhJlj006863@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: r305822 - 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: Fri, 08 Jul 2016 15:43:20 -0000 Author: vincenzo Date: Fri Jul 8 15:43:19 2016 New Revision: 305822 URL: http://svnweb.FreeBSD.org/socsvn/?view=rev&rev=305822 Log: freebsd: ptnet_rx_eof: handle errors 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 Fri Jul 8 15:43:10 2016 (r305821) +++ soc2016/vincenzo/head/sys/dev/netmap/if_ptnet.c Fri Jul 8 15:43:19 2016 (r305822) @@ -1550,9 +1550,10 @@ kring->nr_kflags &= ~NKR_PENDINTR; for (;;) { + unsigned int prev_head = head; + struct mbuf *mhead, *mtail; struct netmap_slot *slot; unsigned int nmbuf_len; - struct mbuf *mhead, *mtail; uint8_t *nmbuf, *mdata; if (budget == 0) { @@ -1582,7 +1583,8 @@ } } - /* We use m_getcl() to allocate an mbuf with standard cluster + /* Allocate the head of an mbuf chain. + * We use m_getcl() to allocate an mbuf with standard cluster * size (MCLBYTES). In the future we could use m_getjcl() * to choose different sizes. */ mhead = mtail = m_getcl(M_NOWAIT, MT_DATA, M_PKTHDR); @@ -1606,7 +1608,7 @@ mdata = mtod(mtail, uint8_t *); mtail->m_len = 0; - do { + for (;;) { slot = ring->slot + head; nmbuf_len = slot->len; nmbuf = NMB(na, slot); @@ -1625,10 +1627,22 @@ struct mbuf *mf; mf = m_getcl(M_NOWAIT, MT_DATA, 0); - if (!mf) { - /* XXX handle error */ - break; + if (unlikely(!mf)) { + /* Ouch. We ran out of memory + * while processing a packet. + * We have to restore the + * previous head position, + * free the mbuf chain, and + * schedule the taskqueue to + * give the packet another + * chance. */ + head = prev_head; + m_freem(mhead); + taskqueue_enqueue(pq->taskq, + &pq->task); + goto escape; } + mtail->m_next = mf; mtail = mf; mdata = mtod(mtail, uint8_t *); @@ -1649,7 +1663,20 @@ } while (nmbuf_len); head = nm_next(head, lim); - } while (slot->flags & NS_MOREFRAG); + + if (!(slot->flags & NS_MOREFRAG)) { + break; + } + + if (unlikely(head == ring->tail)) { + /* The very last slot prepared by the host has + * the NS_MOREFRAG set. This is an error that + * we handle by accepting the truncated packet, + * and let the network stack drop it. */ + RD(1, "Warning: Truncating incomplete packet"); + break; + } + } PTNET_Q_UNLOCK(pq); (*ifp->if_input)(ifp, mhead); @@ -1657,7 +1684,7 @@ budget--; } - +escape: if (head != ring->head) { /* Some packets have been pushed to the network stack. * We need to update the CSB to tell the host about the new From owner-svn-soc-all@freebsd.org Fri Jul 8 15:43:28 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 CA26BB824D8 for ; Fri, 8 Jul 2016 15:43:28 +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 BDAF81166 for ; Fri, 8 Jul 2016 15:43:28 +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 u68FhSK0007126 for ; Fri, 8 Jul 2016 15:43:28 GMT (envelope-from vincenzo@FreeBSD.org) Received: (from www@localhost) by socsvn.freebsd.org (8.15.2/8.15.2/Submit) id u68FhS5a007068 for svn-soc-all@FreeBSD.org; Fri, 8 Jul 2016 15:43:28 GMT (envelope-from vincenzo@FreeBSD.org) Date: Fri, 8 Jul 2016 15:43:28 GMT Message-Id: <201607081543.u68FhS5a007068@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: r305823 - 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: Fri, 08 Jul 2016 15:43:28 -0000 Author: vincenzo Date: Fri Jul 8 15:43:27 2016 New Revision: 305823 URL: http://svnweb.FreeBSD.org/socsvn/?view=rev&rev=305823 Log: freebsd: ptnet_rx_eof: simplify budget management and debug prints 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 Fri Jul 8 15:43:19 2016 (r305822) +++ soc2016/vincenzo/head/sys/dev/netmap/if_ptnet.c Fri Jul 8 15:43:27 2016 (r305823) @@ -1549,18 +1549,13 @@ kring->nr_kflags &= ~NKR_PENDINTR; - for (;;) { + do { unsigned int prev_head = head; struct mbuf *mhead, *mtail; struct netmap_slot *slot; unsigned int nmbuf_len; uint8_t *nmbuf, *mdata; - if (budget == 0) { - RD(1, "Run out of budget h %u t %u", head, ring->tail); - break; - } - if (head == ring->tail) { /* We ran out of slot, let's see if the host has * added some, by reading hwcur and hwtail from @@ -1682,8 +1677,7 @@ (*ifp->if_input)(ifp, mhead); PTNET_Q_LOCK(pq); - budget--; - } + } while (--budget); escape: if (head != ring->head) { /* Some packets have been pushed to the network stack. @@ -1707,8 +1701,8 @@ if (!budget) { /* If we ran out of budget or the double-check found new * slots to process, schedule the taskqueue. */ - RD(1, "%s: resched: budget %u h %u t %u\n", __func__, - budget, head, ring->tail); + RD(1, "out of budget: resched h %u t %u\n", + head, ring->tail); taskqueue_enqueue(pq->taskq, &pq->task); } } From owner-svn-soc-all@freebsd.org Fri Jul 8 15:43:37 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 7284EB824ED for ; Fri, 8 Jul 2016 15:43:37 +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 578CD1184 for ; Fri, 8 Jul 2016 15:43:37 +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 u68FhbRt007281 for ; Fri, 8 Jul 2016 15:43:37 GMT (envelope-from vincenzo@FreeBSD.org) Received: (from www@localhost) by socsvn.freebsd.org (8.15.2/8.15.2/Submit) id u68FhaWE007278 for svn-soc-all@FreeBSD.org; Fri, 8 Jul 2016 15:43:36 GMT (envelope-from vincenzo@FreeBSD.org) Date: Fri, 8 Jul 2016 15:43:36 GMT Message-Id: <201607081543.u68FhaWE007278@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: r305824 - 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: Fri, 08 Jul 2016 15:43:37 -0000 Author: vincenzo Date: Fri Jul 8 15:43:36 2016 New Revision: 305824 URL: http://svnweb.FreeBSD.org/socsvn/?view=rev&rev=305824 Log: freebsd: ptnet_rx_eof: introduce ptnet_rx_slot() to improve readability 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 Fri Jul 8 15:43:27 2016 (r305823) +++ soc2016/vincenzo/head/sys/dev/netmap/if_ptnet.c Fri Jul 8 15:43:36 2016 (r305824) @@ -1532,6 +1532,43 @@ return ptnet_drain_transmit_queue(pq); } +static inline int +ptnet_rx_slot(uint8_t *nmbuf, unsigned int nmbuf_len, struct mbuf **mtail, + uint8_t **mdata) +{ + do { + unsigned int copy; + + if ((*mtail)->m_len == MCLBYTES) { + struct mbuf *mf; + + mf = m_getcl(M_NOWAIT, MT_DATA, 0); + if (unlikely(!mf)) { + return ENOMEM; + } + + (*mtail)->m_next = mf; + (*mtail) = mf; + *mdata = mtod(*mtail, uint8_t *); + (*mtail)->m_len = 0; + } + + copy = MCLBYTES - (*mtail)->m_len; + if (nmbuf_len < copy) { + copy = nmbuf_len; + } + + memcpy(*mdata, nmbuf, copy); + + nmbuf += copy; + nmbuf_len -= copy; + *mdata += copy; + (*mtail)->m_len += copy; + } while (nmbuf_len); + + return 0; +} + static int ptnet_rx_eof(struct ptnet_queue *pq) { @@ -1604,6 +1641,8 @@ mtail->m_len = 0; for (;;) { + int err; + slot = ring->slot + head; nmbuf_len = slot->len; nmbuf = NMB(na, slot); @@ -1615,48 +1654,22 @@ head, ring->tail, nmbuf_len, slot->flags)); - do { - unsigned int copy; - - if (mtail->m_len == MCLBYTES) { - struct mbuf *mf; - - mf = m_getcl(M_NOWAIT, MT_DATA, 0); - if (unlikely(!mf)) { - /* Ouch. We ran out of memory - * while processing a packet. - * We have to restore the - * previous head position, - * free the mbuf chain, and - * schedule the taskqueue to - * give the packet another - * chance. */ - head = prev_head; - m_freem(mhead); - taskqueue_enqueue(pq->taskq, - &pq->task); - goto escape; - } - - mtail->m_next = mf; - mtail = mf; - mdata = mtod(mtail, uint8_t *); - mtail->m_len = 0; - } - - copy = MCLBYTES - mtail->m_len; - if (nmbuf_len < copy) { - copy = nmbuf_len; - } - - memcpy(mdata, nmbuf, copy); - - nmbuf += copy; - nmbuf_len -= copy; - mdata += copy; - mtail->m_len += copy; - } while (nmbuf_len); - + err = ptnet_rx_slot(nmbuf, nmbuf_len, &mtail, &mdata); + if (unlikely(err)) { + /* Ouch. We ran out of memory + * while processing a packet. + * We have to restore the + * previous head position, + * free the mbuf chain, and + * schedule the taskqueue to + * give the packet another + * chance. */ + head = prev_head; + m_freem(mhead); + taskqueue_enqueue(pq->taskq, + &pq->task); + goto escape; + } head = nm_next(head, lim); if (!(slot->flags & NS_MOREFRAG)) { From owner-svn-soc-all@freebsd.org Fri Jul 8 15:43:45 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 7DC6FB824FF for ; Fri, 8 Jul 2016 15:43:45 +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 574B3119B for ; Fri, 8 Jul 2016 15:43:45 +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 u68Fhju2007434 for ; Fri, 8 Jul 2016 15:43:45 GMT (envelope-from vincenzo@FreeBSD.org) Received: (from www@localhost) by socsvn.freebsd.org (8.15.2/8.15.2/Submit) id u68FhiOj007409 for svn-soc-all@FreeBSD.org; Fri, 8 Jul 2016 15:43:44 GMT (envelope-from vincenzo@FreeBSD.org) Date: Fri, 8 Jul 2016 15:43:44 GMT Message-Id: <201607081543.u68FhiOj007409@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: r305825 - 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: Fri, 08 Jul 2016 15:43:45 -0000 Author: vincenzo Date: Fri Jul 8 15:43:44 2016 New Revision: 305825 URL: http://svnweb.FreeBSD.org/socsvn/?view=rev&rev=305825 Log: freebsd: ptnet_rx_eof: remove redundant local variables 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 Fri Jul 8 15:43:36 2016 (r305824) +++ soc2016/vincenzo/head/sys/dev/netmap/if_ptnet.c Fri Jul 8 15:43:44 2016 (r305825) @@ -1590,8 +1590,7 @@ unsigned int prev_head = head; struct mbuf *mhead, *mtail; struct netmap_slot *slot; - unsigned int nmbuf_len; - uint8_t *nmbuf, *mdata; + uint8_t *mdata; if (head == ring->tail) { /* We ran out of slot, let's see if the host has @@ -1615,14 +1614,14 @@ } } - /* Allocate the head of an mbuf chain. + /* Allocate the head of a new mbuf chain. * We use m_getcl() to allocate an mbuf with standard cluster * size (MCLBYTES). In the future we could use m_getjcl() * to choose different sizes. */ mhead = mtail = m_getcl(M_NOWAIT, MT_DATA, M_PKTHDR); if (unlikely(mhead == NULL)) { - device_printf(sc->dev, "%s: failed to allocate mbuf\n", - __func__); + device_printf(sc->dev, "%s: failed to allocate mbuf " + "head\n", __func__); break; } @@ -1640,30 +1639,29 @@ mdata = mtod(mtail, uint8_t *); mtail->m_len = 0; + /* Scan all the netmap slots containing the current packet. */ for (;;) { int err; slot = ring->slot + head; - nmbuf_len = slot->len; - nmbuf = NMB(na, slot); - - mhead->m_pkthdr.len += nmbuf_len; + mhead->m_pkthdr.len += slot->len; DBG(device_printf(sc->dev, "%s: h %u t %u rcv frag " "len %u, flags %u\n", __func__, - head, ring->tail, nmbuf_len, + head, ring->tail, slot->len, slot->flags)); - err = ptnet_rx_slot(nmbuf, nmbuf_len, &mtail, &mdata); + err = ptnet_rx_slot(NMB(na, slot), slot->len, + &mtail, &mdata); if (unlikely(err)) { - /* Ouch. We ran out of memory - * while processing a packet. - * We have to restore the - * previous head position, - * free the mbuf chain, and - * schedule the taskqueue to - * give the packet another - * chance. */ + /* Ouch. We ran out of memory while processing + * a packet. We have to restore the previous + * head position, free the mbuf chain, and + * schedule the taskqueue to give the packet + * another chance. */ + device_printf(sc->dev, "%s: failed to allocate" + " mbuf frag, reset head %u --> %u\n", + __func__, head, prev_head); head = prev_head; m_freem(mhead); taskqueue_enqueue(pq->taskq, From owner-svn-soc-all@freebsd.org Fri Jul 8 15:43:54 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 00088B82520 for ; Fri, 8 Jul 2016 15:43:53 +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 CF88B11B1 for ; Fri, 8 Jul 2016 15:43:53 +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 u68Fhrks007631 for ; Fri, 8 Jul 2016 15:43:53 GMT (envelope-from vincenzo@FreeBSD.org) Received: (from www@localhost) by socsvn.freebsd.org (8.15.2/8.15.2/Submit) id u68Fhrke007628 for svn-soc-all@FreeBSD.org; Fri, 8 Jul 2016 15:43:53 GMT (envelope-from vincenzo@FreeBSD.org) Date: Fri, 8 Jul 2016 15:43:53 GMT Message-Id: <201607081543.u68Fhrke007628@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: r305826 - 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: Fri, 08 Jul 2016 15:43:54 -0000 Author: vincenzo Date: Fri Jul 8 15:43:52 2016 New Revision: 305826 URL: http://svnweb.FreeBSD.org/socsvn/?view=rev&rev=305826 Log: freebsd: ptnet_rx_slot: remove argument and cache pointers 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 Fri Jul 8 15:43:44 2016 (r305825) +++ soc2016/vincenzo/head/sys/dev/netmap/if_ptnet.c Fri Jul 8 15:43:52 2016 (r305826) @@ -1533,13 +1533,15 @@ } static inline int -ptnet_rx_slot(uint8_t *nmbuf, unsigned int nmbuf_len, struct mbuf **mtail, - uint8_t **mdata) +ptnet_rx_slot(uint8_t *nmbuf, unsigned int nmbuf_len, struct mbuf **mtail_p) { + struct mbuf *mtail = *mtail_p; + uint8_t *mdata = mtod(mtail, uint8_t *) + mtail->m_len; + do { unsigned int copy; - if ((*mtail)->m_len == MCLBYTES) { + if (mtail->m_len == MCLBYTES) { struct mbuf *mf; mf = m_getcl(M_NOWAIT, MT_DATA, 0); @@ -1547,23 +1549,23 @@ return ENOMEM; } - (*mtail)->m_next = mf; - (*mtail) = mf; - *mdata = mtod(*mtail, uint8_t *); - (*mtail)->m_len = 0; + mtail->m_next = mf; + mtail = *mtail_p = mf; + mdata = mtod(mtail, uint8_t *); + mtail->m_len = 0; } - copy = MCLBYTES - (*mtail)->m_len; + copy = MCLBYTES - mtail->m_len; if (nmbuf_len < copy) { copy = nmbuf_len; } - memcpy(*mdata, nmbuf, copy); + memcpy(mdata, nmbuf, copy); nmbuf += copy; nmbuf_len -= copy; - *mdata += copy; - (*mtail)->m_len += copy; + mdata += copy; + mtail->m_len += copy; } while (nmbuf_len); return 0; @@ -1590,7 +1592,6 @@ unsigned int prev_head = head; struct mbuf *mhead, *mtail; struct netmap_slot *slot; - uint8_t *mdata; if (head == ring->tail) { /* We ran out of slot, let's see if the host has @@ -1636,7 +1637,6 @@ M_HASHTYPE_SET(mhead, M_HASHTYPE_OPAQUE); /* Initialize state variables. */ - mdata = mtod(mtail, uint8_t *); mtail->m_len = 0; /* Scan all the netmap slots containing the current packet. */ @@ -1651,8 +1651,7 @@ head, ring->tail, slot->len, slot->flags)); - err = ptnet_rx_slot(NMB(na, slot), slot->len, - &mtail, &mdata); + err = ptnet_rx_slot(NMB(na, slot), slot->len, &mtail); if (unlikely(err)) { /* Ouch. We ran out of memory while processing * a packet. We have to restore the previous From owner-svn-soc-all@freebsd.org Fri Jul 8 15:44:04 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 6E5D6B8255F for ; Fri, 8 Jul 2016 15:44:04 +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 47D4611F5 for ; Fri, 8 Jul 2016 15:44:04 +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 u68Fi4s8007906 for ; Fri, 8 Jul 2016 15:44:04 GMT (envelope-from vincenzo@FreeBSD.org) Received: (from www@localhost) by socsvn.freebsd.org (8.15.2/8.15.2/Submit) id u68Fi3F0007876 for svn-soc-all@FreeBSD.org; Fri, 8 Jul 2016 15:44:03 GMT (envelope-from vincenzo@FreeBSD.org) Date: Fri, 8 Jul 2016 15:44:03 GMT Message-Id: <201607081544.u68Fi3F0007876@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: r305827 - 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: Fri, 08 Jul 2016 15:44:04 -0000 Author: vincenzo Date: Fri Jul 8 15:44:03 2016 New Revision: 305827 URL: http://svnweb.FreeBSD.org/socsvn/?view=rev&rev=305827 Log: freebsd: ptnet_rx_slot: remove mtail_p argument, use return value 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 Fri Jul 8 15:43:52 2016 (r305826) +++ soc2016/vincenzo/head/sys/dev/netmap/if_ptnet.c Fri Jul 8 15:44:03 2016 (r305827) @@ -1532,10 +1532,9 @@ return ptnet_drain_transmit_queue(pq); } -static inline int -ptnet_rx_slot(uint8_t *nmbuf, unsigned int nmbuf_len, struct mbuf **mtail_p) +static inline struct mbuf * +ptnet_rx_slot(struct mbuf *mtail, uint8_t *nmbuf, unsigned int nmbuf_len) { - struct mbuf *mtail = *mtail_p; uint8_t *mdata = mtod(mtail, uint8_t *) + mtail->m_len; do { @@ -1546,11 +1545,11 @@ mf = m_getcl(M_NOWAIT, MT_DATA, 0); if (unlikely(!mf)) { - return ENOMEM; + return NULL; } mtail->m_next = mf; - mtail = *mtail_p = mf; + mtail = mf; mdata = mtod(mtail, uint8_t *); mtail->m_len = 0; } @@ -1568,7 +1567,7 @@ mtail->m_len += copy; } while (nmbuf_len); - return 0; + return mtail; } static int @@ -1641,8 +1640,6 @@ /* Scan all the netmap slots containing the current packet. */ for (;;) { - int err; - slot = ring->slot + head; mhead->m_pkthdr.len += slot->len; @@ -1651,8 +1648,8 @@ head, ring->tail, slot->len, slot->flags)); - err = ptnet_rx_slot(NMB(na, slot), slot->len, &mtail); - if (unlikely(err)) { + mtail = ptnet_rx_slot(mtail, NMB(na, slot), slot->len); + if (unlikely(!mtail)) { /* Ouch. We ran out of memory while processing * a packet. We have to restore the previous * head position, free the mbuf chain, and From owner-svn-soc-all@freebsd.org Fri Jul 8 15:44:20 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 23251B82579 for ; Fri, 8 Jul 2016 15:44:20 +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 162B5120C for ; Fri, 8 Jul 2016 15:44:20 +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 u68FiJSK008208 for ; Fri, 8 Jul 2016 15:44:19 GMT (envelope-from vincenzo@FreeBSD.org) Received: (from www@localhost) by socsvn.freebsd.org (8.15.2/8.15.2/Submit) id u68FiJcW008128 for svn-soc-all@FreeBSD.org; Fri, 8 Jul 2016 15:44:19 GMT (envelope-from vincenzo@FreeBSD.org) Date: Fri, 8 Jul 2016 15:44:19 GMT Message-Id: <201607081544.u68FiJcW008128@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: r305828 - 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: Fri, 08 Jul 2016 15:44:20 -0000 Author: vincenzo Date: Fri Jul 8 15:44:18 2016 New Revision: 305828 URL: http://svnweb.FreeBSD.org/socsvn/?view=rev&rev=305828 Log: freebsd: ptnet_rx_eof: move mhead initialization close to if_input 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 Fri Jul 8 15:44:03 2016 (r305827) +++ soc2016/vincenzo/head/sys/dev/netmap/if_ptnet.c Fri Jul 8 15:44:18 2016 (r305828) @@ -1625,17 +1625,8 @@ break; } - mhead->m_pkthdr.rcvif = ifp; - mhead->m_pkthdr.len = 0; - - /* No support for checksum offloading for now. */ - mhead->m_pkthdr.csum_flags = 0; - - /* Store the queue idx in the packet header. */ - mhead->m_pkthdr.flowid = pq->kring_id; - M_HASHTYPE_SET(mhead, M_HASHTYPE_OPAQUE); - /* Initialize state variables. */ + mhead->m_pkthdr.len = 0; mtail->m_len = 0; /* Scan all the netmap slots containing the current packet. */ @@ -1680,6 +1671,15 @@ } } + mhead->m_pkthdr.rcvif = ifp; + + /* No support for checksum offloading for now. */ + mhead->m_pkthdr.csum_flags = 0; + + /* Store the queue idx in the packet header. */ + mhead->m_pkthdr.flowid = pq->kring_id; + M_HASHTYPE_SET(mhead, M_HASHTYPE_OPAQUE); + PTNET_Q_UNLOCK(pq); (*ifp->if_input)(ifp, mhead); PTNET_Q_LOCK(pq); From owner-svn-soc-all@freebsd.org Fri Jul 8 15:44:29 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 4A435B8258D for ; Fri, 8 Jul 2016 15:44:29 +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 3DC381220 for ; Fri, 8 Jul 2016 15:44:29 +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 u68FiTNp008336 for ; Fri, 8 Jul 2016 15:44:29 GMT (envelope-from vincenzo@FreeBSD.org) Received: (from www@localhost) by socsvn.freebsd.org (8.15.2/8.15.2/Submit) id u68FiSF9008332 for svn-soc-all@FreeBSD.org; Fri, 8 Jul 2016 15:44:28 GMT (envelope-from vincenzo@FreeBSD.org) Date: Fri, 8 Jul 2016 15:44:28 GMT Message-Id: <201607081544.u68FiSF9008332@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: r305829 - 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: Fri, 08 Jul 2016 15:44:29 -0000 Author: vincenzo Date: Fri Jul 8 15:44:28 2016 New Revision: 305829 URL: http://svnweb.FreeBSD.org/socsvn/?view=rev&rev=305829 Log: freebsd: ptnet_drain_transmit_queue: cache VNET_HDR flag 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 Fri Jul 8 15:44:18 2016 (r305828) +++ soc2016/vincenzo/head/sys/dev/netmap/if_ptnet.c Fri Jul 8 15:44:28 2016 (r305829) @@ -1336,6 +1336,7 @@ ptnet_drain_transmit_queue(struct ptnet_queue *pq) { struct ptnet_softc *sc = pq->sc; + bool use_vnet_hdr = (sc->ptfeatures & NET_PTN_FEATURES_VNET_HDR); struct netmap_adapter *na = &sc->ptna_dr.hwup.up; struct ifnet *ifp = sc->ifp; unsigned int batch_count = 0; @@ -1414,7 +1415,7 @@ /* If needed, prepare the virtio-net header at the beginning * of the first slot. */ - if (sc->ptfeatures & NET_PTN_FEATURES_VNET_HDR) { + if (use_vnet_hdr) { /* For performance, we could replace this memset() with * two 8-bytes-wide writes. */ memset(nmbuf, 0, PTNET_HDR_SIZE); From owner-svn-soc-all@freebsd.org Fri Jul 8 15:44:38 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 06B78B825A5 for ; Fri, 8 Jul 2016 15:44:38 +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 DFC3A123D for ; Fri, 8 Jul 2016 15:44:37 +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 u68Fibgt008539 for ; Fri, 8 Jul 2016 15:44:37 GMT (envelope-from vincenzo@FreeBSD.org) Received: (from www@localhost) by socsvn.freebsd.org (8.15.2/8.15.2/Submit) id u68FibOd008520 for svn-soc-all@FreeBSD.org; Fri, 8 Jul 2016 15:44:37 GMT (envelope-from vincenzo@FreeBSD.org) Date: Fri, 8 Jul 2016 15:44:37 GMT Message-Id: <201607081544.u68FibOd008520@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: r305830 - 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: Fri, 08 Jul 2016 15:44:38 -0000 Author: vincenzo Date: Fri Jul 8 15:44:36 2016 New Revision: 305830 URL: http://svnweb.FreeBSD.org/socsvn/?view=rev&rev=305830 Log: freebsd: ptnet_rx_eof: strip virtio-net header if needed 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 Fri Jul 8 15:44:28 2016 (r305829) +++ soc2016/vincenzo/head/sys/dev/netmap/if_ptnet.c Fri Jul 8 15:44:36 2016 (r305830) @@ -184,6 +184,8 @@ static void ptnet_tx_intr(void *opaque); static void ptnet_rx_intr(void *opaque); +static unsigned ptnet_rx_discard(struct netmap_kring *kring, + unsigned int head); static int ptnet_rx_eof(struct ptnet_queue *pq); static void ptnet_rx_task(void *context, int pending); @@ -1336,7 +1338,7 @@ ptnet_drain_transmit_queue(struct ptnet_queue *pq) { struct ptnet_softc *sc = pq->sc; - bool use_vnet_hdr = (sc->ptfeatures & NET_PTN_FEATURES_VNET_HDR); + bool have_vnet_hdr = (sc->ptfeatures & NET_PTN_FEATURES_VNET_HDR); struct netmap_adapter *na = &sc->ptna_dr.hwup.up; struct ifnet *ifp = sc->ifp; unsigned int batch_count = 0; @@ -1415,7 +1417,7 @@ /* If needed, prepare the virtio-net header at the beginning * of the first slot. */ - if (use_vnet_hdr) { + if (have_vnet_hdr) { /* For performance, we could replace this memset() with * two 8-bytes-wide writes. */ memset(nmbuf, 0, PTNET_HDR_SIZE); @@ -1533,6 +1535,23 @@ return ptnet_drain_transmit_queue(pq); } +static unsigned int +ptnet_rx_discard(struct netmap_kring *kring, unsigned int head) +{ + struct netmap_ring *ring = kring->ring; + struct netmap_slot *slot = ring->slot + head; + + for (;;) { + head = nm_next(head, kring->nkr_num_slots - 1); + if (!(slot->flags & NS_MOREFRAG) || head == ring->tail) { + break; + } + slot = ring->slot + head; + } + + return head; +} + static inline struct mbuf * ptnet_rx_slot(struct mbuf *mtail, uint8_t *nmbuf, unsigned int nmbuf_len) { @@ -1575,6 +1594,7 @@ ptnet_rx_eof(struct ptnet_queue *pq) { struct ptnet_softc *sc = pq->sc; + bool have_vnet_hdr = (sc->ptfeatures & NET_PTN_FEATURES_VNET_HDR); struct ptnet_ring *ptring = pq->ptring; struct netmap_adapter *na = &sc->ptna_dr.hwup.up; struct netmap_kring *kring = na->rx_rings + pq->kring_id; @@ -1591,7 +1611,10 @@ do { unsigned int prev_head = head; struct mbuf *mhead, *mtail; + struct virtio_net_hdr *vh; struct netmap_slot *slot; + unsigned int nmbuf_len; + uint8_t *nmbuf; if (head == ring->tail) { /* We ran out of slot, let's see if the host has @@ -1615,6 +1638,30 @@ } } + /* Initialize ring state variables, possibly grabbing the + * virtio-net header. */ + slot = ring->slot + head; + nmbuf = NMB(na, slot); + nmbuf_len = slot->len; + + vh = (struct virtio_net_hdr *)nmbuf; + if (have_vnet_hdr) { + if (unlikely(nmbuf_len < PTNET_HDR_SIZE)) { + /* There is no good reason why host should + * put the header in multiple netmap slots. + * If this is the case, discard. */ + head = ptnet_rx_discard(kring, head); + continue; + } + RD(1, "%s: vnet hdr: flags %x csum_start %u " + "csum_ofs %u hdr_len = %u gso_size %u " + "gso_type %x", __func__, vh->flags, + vh->csum_start, vh->csum_offset, vh->hdr_len, + vh->gso_size, vh->gso_type); + nmbuf += PTNET_HDR_SIZE; + nmbuf_len -= PTNET_HDR_SIZE; + } + /* Allocate the head of a new mbuf chain. * We use m_getcl() to allocate an mbuf with standard cluster * size (MCLBYTES). In the future we could use m_getjcl() @@ -1626,21 +1673,18 @@ break; } - /* Initialize state variables. */ - mhead->m_pkthdr.len = 0; + /* Initialize the mbuf state variables. */ + mhead->m_pkthdr.len = nmbuf_len; mtail->m_len = 0; /* Scan all the netmap slots containing the current packet. */ for (;;) { - slot = ring->slot + head; - mhead->m_pkthdr.len += slot->len; - DBG(device_printf(sc->dev, "%s: h %u t %u rcv frag " "len %u, flags %u\n", __func__, head, ring->tail, slot->len, slot->flags)); - mtail = ptnet_rx_slot(mtail, NMB(na, slot), slot->len); + mtail = ptnet_rx_slot(mtail, nmbuf, nmbuf_len); if (unlikely(!mtail)) { /* Ouch. We ran out of memory while processing * a packet. We have to restore the previous @@ -1656,6 +1700,9 @@ &pq->task); goto escape; } + + /* We have to increment head irrespective of the + * NS_MOREFRAG being set or not. */ head = nm_next(head, lim); if (!(slot->flags & NS_MOREFRAG)) { @@ -1670,6 +1717,11 @@ RD(1, "Warning: Truncating incomplete packet"); break; } + + slot = ring->slot + head; + nmbuf = NMB(na, slot); + nmbuf_len = slot->len; + mhead->m_pkthdr.len += nmbuf_len; } mhead->m_pkthdr.rcvif = ifp; From owner-svn-soc-all@freebsd.org Fri Jul 8 15:44: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 C9B5EB825BB for ; Fri, 8 Jul 2016 15:44:46 +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 BD2BD1256 for ; Fri, 8 Jul 2016 15:44:46 +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 u68FiksK008651 for ; Fri, 8 Jul 2016 15:44:46 GMT (envelope-from vincenzo@FreeBSD.org) Received: (from www@localhost) by socsvn.freebsd.org (8.15.2/8.15.2/Submit) id u68Fikd8008648 for svn-soc-all@FreeBSD.org; Fri, 8 Jul 2016 15:44:46 GMT (envelope-from vincenzo@FreeBSD.org) Date: Fri, 8 Jul 2016 15:44:46 GMT Message-Id: <201607081544.u68Fikd8008648@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: r305831 - 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: Fri, 08 Jul 2016 15:44:46 -0000 Author: vincenzo Date: Fri Jul 8 15:44:45 2016 New Revision: 305831 URL: http://svnweb.FreeBSD.org/socsvn/?view=rev&rev=305831 Log: freebsd: ptnet_rx_eof: support VLAN decapsulation 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 Fri Jul 8 15:44:36 2016 (r305830) +++ soc2016/vincenzo/head/sys/dev/netmap/if_ptnet.c Fri Jul 8 15:44:45 2016 (r305831) @@ -1495,6 +1495,22 @@ return 0; } +/* This function should be shared with the virtio-net driver. */ +static void +ptnet_vlan_tag_remove(struct mbuf *m) +{ + struct ether_vlan_header *evh; + + evh = mtod(m, struct ether_vlan_header *); + m->m_pkthdr.ether_vtag = ntohs(evh->evl_tag); + m->m_flags |= M_VLANTAG; + + /* Strip the 802.1Q header. */ + bcopy((char *) evh, (char *) evh + ETHER_VLAN_ENCAP_LEN, + ETHER_HDR_LEN - ETHER_TYPE_LEN); + m_adj(m, ETHER_VLAN_ENCAP_LEN); +} + static int ptnet_transmit(struct ifnet *ifp, struct mbuf *m) { @@ -1733,6 +1749,21 @@ mhead->m_pkthdr.flowid = pq->kring_id; M_HASHTYPE_SET(mhead, M_HASHTYPE_OPAQUE); + if (ifp->if_capenable & IFCAP_VLAN_HWTAGGING) { + struct ether_header *eh; + + eh = mtod(mhead, struct ether_header *); + if (eh->ether_type == htons(ETHERTYPE_VLAN)) { + ptnet_vlan_tag_remove(mhead); + /* + * With the 802.1Q header removed, update the + * checksum starting location accordingly. + */ + if (vh->flags & VIRTIO_NET_HDR_F_NEEDS_CSUM) + vh->csum_start -= ETHER_VLAN_ENCAP_LEN; + } + } + PTNET_Q_UNLOCK(pq); (*ifp->if_input)(ifp, mhead); PTNET_Q_LOCK(pq); From owner-svn-soc-all@freebsd.org Fri Jul 8 15:44:55 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 84837B825D7 for ; Fri, 8 Jul 2016 15:44:55 +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 77D351270 for ; Fri, 8 Jul 2016 15:44:55 +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 u68Fito5008868 for ; Fri, 8 Jul 2016 15:44:55 GMT (envelope-from vincenzo@FreeBSD.org) Received: (from www@localhost) by socsvn.freebsd.org (8.15.2/8.15.2/Submit) id u68FisbQ008863 for svn-soc-all@FreeBSD.org; Fri, 8 Jul 2016 15:44:54 GMT (envelope-from vincenzo@FreeBSD.org) Date: Fri, 8 Jul 2016 15:44:54 GMT Message-Id: <201607081544.u68FisbQ008863@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: r305832 - 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: Fri, 08 Jul 2016 15:44:55 -0000 Author: vincenzo Date: Fri Jul 8 15:44:54 2016 New Revision: 305832 URL: http://svnweb.FreeBSD.org/socsvn/?view=rev&rev=305832 Log: freebsd: ptnet_rx_eof: process checksumming offloadings 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 Fri Jul 8 15:44:45 2016 (r305831) +++ soc2016/vincenzo/head/sys/dev/netmap/if_ptnet.c Fri Jul 8 15:44:54 2016 (r305832) @@ -63,6 +63,7 @@ #include #include #include +#include #include #include @@ -1495,22 +1496,6 @@ return 0; } -/* This function should be shared with the virtio-net driver. */ -static void -ptnet_vlan_tag_remove(struct mbuf *m) -{ - struct ether_vlan_header *evh; - - evh = mtod(m, struct ether_vlan_header *); - m->m_pkthdr.ether_vtag = ntohs(evh->evl_tag); - m->m_flags |= M_VLANTAG; - - /* Strip the 802.1Q header. */ - bcopy((char *) evh, (char *) evh + ETHER_VLAN_ENCAP_LEN, - ETHER_HDR_LEN - ETHER_TYPE_LEN); - m_adj(m, ETHER_VLAN_ENCAP_LEN); -} - static int ptnet_transmit(struct ifnet *ifp, struct mbuf *m) { @@ -1551,6 +1536,180 @@ return ptnet_drain_transmit_queue(pq); } +/* This function should be shared with the virtio-net driver. */ +static void +ptnet_vlan_tag_remove(struct mbuf *m) +{ + struct ether_vlan_header *evh; + + evh = mtod(m, struct ether_vlan_header *); + m->m_pkthdr.ether_vtag = ntohs(evh->evl_tag); + m->m_flags |= M_VLANTAG; + + /* Strip the 802.1Q header. */ + bcopy((char *) evh, (char *) evh + ETHER_VLAN_ENCAP_LEN, + ETHER_HDR_LEN - ETHER_TYPE_LEN); + m_adj(m, ETHER_VLAN_ENCAP_LEN); +} + +/* + * Use the checksum offset in the VirtIO header to set the + * correct CSUM_* flags. + */ +static int +ptnet_rx_csum_by_offset(struct mbuf *m, uint16_t eth_type, int ip_start, + struct virtio_net_hdr *hdr) +{ +#if defined(INET) || defined(INET6) + int offset = hdr->csum_start + hdr->csum_offset; +#endif + + /* Only do a basic sanity check on the offset. */ + switch (eth_type) { +#if defined(INET) + case ETHERTYPE_IP: + if (__predict_false(offset < ip_start + sizeof(struct ip))) + return (1); + break; +#endif +#if defined(INET6) + case ETHERTYPE_IPV6: + if (__predict_false(offset < ip_start + sizeof(struct ip6_hdr))) + return (1); + break; +#endif + default: + /* Here we should increment the rx_csum_bad_ethtype counter. */ + return (1); + } + + /* + * Use the offset to determine the appropriate CSUM_* flags. This is + * a bit dirty, but we can get by with it since the checksum offsets + * happen to be different. We assume the host host does not do IPv4 + * header checksum offloading. + */ + switch (hdr->csum_offset) { + case offsetof(struct udphdr, uh_sum): + case offsetof(struct tcphdr, th_sum): + m->m_pkthdr.csum_flags |= CSUM_DATA_VALID | CSUM_PSEUDO_HDR; + m->m_pkthdr.csum_data = 0xFFFF; + break; + case offsetof(struct sctphdr, checksum): + m->m_pkthdr.csum_flags |= CSUM_SCTP_VALID; + break; + default: + /* Here we should increment the rx_csum_bad_offset counter. */ + return (1); + } + + return (0); +} + +static int +ptnet_rx_csum_by_parse(struct mbuf *m, uint16_t eth_type, int ip_start, + struct virtio_net_hdr *hdr) +{ + int offset, proto; + + switch (eth_type) { +#if defined(INET) + case ETHERTYPE_IP: { + struct ip *ip; + if (__predict_false(m->m_len < ip_start + sizeof(struct ip))) + return (1); + ip = (struct ip *)(m->m_data + ip_start); + proto = ip->ip_p; + offset = ip_start + (ip->ip_hl << 2); + break; + } +#endif +#if defined(INET6) + case ETHERTYPE_IPV6: + if (__predict_false(m->m_len < ip_start + + sizeof(struct ip6_hdr))) + return (1); + offset = ip6_lasthdr(m, ip_start, IPPROTO_IPV6, &proto); + if (__predict_false(offset < 0)) + return (1); + break; +#endif + default: + /* Here we should increment the rx_csum_bad_ethtype counter. */ + return (1); + } + + switch (proto) { + case IPPROTO_TCP: + if (__predict_false(m->m_len < offset + sizeof(struct tcphdr))) + return (1); + m->m_pkthdr.csum_flags |= CSUM_DATA_VALID | CSUM_PSEUDO_HDR; + m->m_pkthdr.csum_data = 0xFFFF; + break; + case IPPROTO_UDP: + if (__predict_false(m->m_len < offset + sizeof(struct udphdr))) + return (1); + m->m_pkthdr.csum_flags |= CSUM_DATA_VALID | CSUM_PSEUDO_HDR; + m->m_pkthdr.csum_data = 0xFFFF; + break; + case IPPROTO_SCTP: + if (__predict_false(m->m_len < offset + sizeof(struct sctphdr))) + return (1); + m->m_pkthdr.csum_flags |= CSUM_SCTP_VALID; + break; + default: + /* + * For the remaining protocols, FreeBSD does not support + * checksum offloading, so the checksum will be recomputed. + */ +#if 0 + if_printf(ifp, "cksum offload of unsupported " + "protocol eth_type=%#x proto=%d csum_start=%d " + "csum_offset=%d\n", __func__, eth_type, proto, + hdr->csum_start, hdr->csum_offset); +#endif + break; + } + + return (0); +} + +/* + * Set the appropriate CSUM_* flags. Unfortunately, the information + * provided is not directly useful to us. The VirtIO header gives the + * offset of the checksum, which is all Linux needs, but this is not + * how FreeBSD does things. We are forced to peek inside the packet + * a bit. + * + * It would be nice if VirtIO gave us the L4 protocol or if FreeBSD + * could accept the offsets and let the stack figure it out. + */ +static int +ptnet_rx_csum(struct mbuf *m, struct virtio_net_hdr *hdr) +{ + struct ether_header *eh; + struct ether_vlan_header *evh; + uint16_t eth_type; + int offset, error; + + eh = mtod(m, struct ether_header *); + eth_type = ntohs(eh->ether_type); + if (eth_type == ETHERTYPE_VLAN) { + /* BMV: We should handle nested VLAN tags too. */ + evh = mtod(m, struct ether_vlan_header *); + eth_type = ntohs(evh->evl_proto); + offset = sizeof(struct ether_vlan_header); + } else + offset = sizeof(struct ether_header); + + if (hdr->flags & VIRTIO_NET_HDR_F_NEEDS_CSUM) + error = ptnet_rx_csum_by_offset(m, eth_type, offset, hdr); + else + error = ptnet_rx_csum_by_parse(m, eth_type, offset, hdr); + + return (error); +} + static unsigned int ptnet_rx_discard(struct netmap_kring *kring, unsigned int head) { @@ -1764,6 +1923,11 @@ } } + if (have_vnet_hdr && (vh->flags & (VIRTIO_NET_HDR_F_NEEDS_CSUM + | VIRTIO_NET_HDR_F_DATA_VALID))) { + ptnet_rx_csum(mhead, vh); + } + PTNET_Q_UNLOCK(pq); (*ifp->if_input)(ifp, mhead); PTNET_Q_LOCK(pq); From owner-svn-soc-all@freebsd.org Fri Jul 8 15:45:03 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 8516AB825EE for ; Fri, 8 Jul 2016 15:45:03 +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 6B8161285 for ; Fri, 8 Jul 2016 15:45:03 +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 u68Fj3PD009064 for ; Fri, 8 Jul 2016 15:45:03 GMT (envelope-from vincenzo@FreeBSD.org) Received: (from www@localhost) by socsvn.freebsd.org (8.15.2/8.15.2/Submit) id u68Fj2UL009061 for svn-soc-all@FreeBSD.org; Fri, 8 Jul 2016 15:45:02 GMT (envelope-from vincenzo@FreeBSD.org) Date: Fri, 8 Jul 2016 15:45:02 GMT Message-Id: <201607081545.u68Fj2UL009061@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: r305833 - 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: Fri, 08 Jul 2016 15:45:03 -0000 Author: vincenzo Date: Fri Jul 8 15:45:02 2016 New Revision: 305833 URL: http://svnweb.FreeBSD.org/socsvn/?view=rev&rev=305833 Log: freebsd: put offloadings-related functions together 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 Fri Jul 8 15:44:54 2016 (r305832) +++ soc2016/vincenzo/head/sys/dev/netmap/if_ptnet.c Fri Jul 8 15:45:02 2016 (r305833) @@ -1151,8 +1151,8 @@ ptnet_rx_eof(pq); } -/* The following three functions are taken from the virtio-net driver, but - * the same functionality applies to the ptnet driver. +/* The following offloadings-related functions are taken from the virtio-net + * driver, but the same functionality is required for the ptnet driver. * As a temporary solution, I copied this code from virtio-net and I started * to generalize it (taking away driver-specific statistic accounting), * making as little modifications as possible. @@ -1295,6 +1295,180 @@ return (NULL); } +static void +ptnet_vlan_tag_remove(struct mbuf *m) +{ + struct ether_vlan_header *evh; + + evh = mtod(m, struct ether_vlan_header *); + m->m_pkthdr.ether_vtag = ntohs(evh->evl_tag); + m->m_flags |= M_VLANTAG; + + /* Strip the 802.1Q header. */ + bcopy((char *) evh, (char *) evh + ETHER_VLAN_ENCAP_LEN, + ETHER_HDR_LEN - ETHER_TYPE_LEN); + m_adj(m, ETHER_VLAN_ENCAP_LEN); +} + +/* + * Use the checksum offset in the VirtIO header to set the + * correct CSUM_* flags. + */ +static int +ptnet_rx_csum_by_offset(struct mbuf *m, uint16_t eth_type, int ip_start, + struct virtio_net_hdr *hdr) +{ +#if defined(INET) || defined(INET6) + int offset = hdr->csum_start + hdr->csum_offset; +#endif + + /* Only do a basic sanity check on the offset. */ + switch (eth_type) { +#if defined(INET) + case ETHERTYPE_IP: + if (__predict_false(offset < ip_start + sizeof(struct ip))) + return (1); + break; +#endif +#if defined(INET6) + case ETHERTYPE_IPV6: + if (__predict_false(offset < ip_start + sizeof(struct ip6_hdr))) + return (1); + break; +#endif + default: + /* Here we should increment the rx_csum_bad_ethtype counter. */ + return (1); + } + + /* + * Use the offset to determine the appropriate CSUM_* flags. This is + * a bit dirty, but we can get by with it since the checksum offsets + * happen to be different. We assume the host host does not do IPv4 + * header checksum offloading. + */ + switch (hdr->csum_offset) { + case offsetof(struct udphdr, uh_sum): + case offsetof(struct tcphdr, th_sum): + m->m_pkthdr.csum_flags |= CSUM_DATA_VALID | CSUM_PSEUDO_HDR; + m->m_pkthdr.csum_data = 0xFFFF; + break; + case offsetof(struct sctphdr, checksum): + m->m_pkthdr.csum_flags |= CSUM_SCTP_VALID; + break; + default: + /* Here we should increment the rx_csum_bad_offset counter. */ + return (1); + } + + return (0); +} + +static int +ptnet_rx_csum_by_parse(struct mbuf *m, uint16_t eth_type, int ip_start, + struct virtio_net_hdr *hdr) +{ + int offset, proto; + + switch (eth_type) { +#if defined(INET) + case ETHERTYPE_IP: { + struct ip *ip; + if (__predict_false(m->m_len < ip_start + sizeof(struct ip))) + return (1); + ip = (struct ip *)(m->m_data + ip_start); + proto = ip->ip_p; + offset = ip_start + (ip->ip_hl << 2); + break; + } +#endif +#if defined(INET6) + case ETHERTYPE_IPV6: + if (__predict_false(m->m_len < ip_start + + sizeof(struct ip6_hdr))) + return (1); + offset = ip6_lasthdr(m, ip_start, IPPROTO_IPV6, &proto); + if (__predict_false(offset < 0)) + return (1); + break; +#endif + default: + /* Here we should increment the rx_csum_bad_ethtype counter. */ + return (1); + } + + switch (proto) { + case IPPROTO_TCP: + if (__predict_false(m->m_len < offset + sizeof(struct tcphdr))) + return (1); + m->m_pkthdr.csum_flags |= CSUM_DATA_VALID | CSUM_PSEUDO_HDR; + m->m_pkthdr.csum_data = 0xFFFF; + break; + case IPPROTO_UDP: + if (__predict_false(m->m_len < offset + sizeof(struct udphdr))) + return (1); + m->m_pkthdr.csum_flags |= CSUM_DATA_VALID | CSUM_PSEUDO_HDR; + m->m_pkthdr.csum_data = 0xFFFF; + break; + case IPPROTO_SCTP: + if (__predict_false(m->m_len < offset + sizeof(struct sctphdr))) + return (1); + m->m_pkthdr.csum_flags |= CSUM_SCTP_VALID; + break; + default: + /* + * For the remaining protocols, FreeBSD does not support + * checksum offloading, so the checksum will be recomputed. + */ +#if 0 + if_printf(ifp, "cksum offload of unsupported " + "protocol eth_type=%#x proto=%d csum_start=%d " + "csum_offset=%d\n", __func__, eth_type, proto, + hdr->csum_start, hdr->csum_offset); +#endif + break; + } + + return (0); +} + +/* + * Set the appropriate CSUM_* flags. Unfortunately, the information + * provided is not directly useful to us. The VirtIO header gives the + * offset of the checksum, which is all Linux needs, but this is not + * how FreeBSD does things. We are forced to peek inside the packet + * a bit. + * + * It would be nice if VirtIO gave us the L4 protocol or if FreeBSD + * could accept the offsets and let the stack figure it out. + */ +static int +ptnet_rx_csum(struct mbuf *m, struct virtio_net_hdr *hdr) +{ + struct ether_header *eh; + struct ether_vlan_header *evh; + uint16_t eth_type; + int offset, error; + + eh = mtod(m, struct ether_header *); + eth_type = ntohs(eh->ether_type); + if (eth_type == ETHERTYPE_VLAN) { + /* BMV: We should handle nested VLAN tags too. */ + evh = mtod(m, struct ether_vlan_header *); + eth_type = ntohs(evh->evl_proto); + offset = sizeof(struct ether_vlan_header); + } else + offset = sizeof(struct ether_header); + + if (hdr->flags & VIRTIO_NET_HDR_F_NEEDS_CSUM) + error = ptnet_rx_csum_by_offset(m, eth_type, offset, hdr); + else + error = ptnet_rx_csum_by_parse(m, eth_type, offset, hdr); + + return (error); +} +/* End of offloading-related functions to be shared with virtio-net. */ + static inline void ptnet_sync_tail(struct ptnet_ring *ptring, struct netmap_kring *kring) { @@ -1536,180 +1710,6 @@ return ptnet_drain_transmit_queue(pq); } -/* This function should be shared with the virtio-net driver. */ -static void -ptnet_vlan_tag_remove(struct mbuf *m) -{ - struct ether_vlan_header *evh; - - evh = mtod(m, struct ether_vlan_header *); - m->m_pkthdr.ether_vtag = ntohs(evh->evl_tag); - m->m_flags |= M_VLANTAG; - - /* Strip the 802.1Q header. */ - bcopy((char *) evh, (char *) evh + ETHER_VLAN_ENCAP_LEN, - ETHER_HDR_LEN - ETHER_TYPE_LEN); - m_adj(m, ETHER_VLAN_ENCAP_LEN); -} - -/* - * Use the checksum offset in the VirtIO header to set the - * correct CSUM_* flags. - */ -static int -ptnet_rx_csum_by_offset(struct mbuf *m, uint16_t eth_type, int ip_start, - struct virtio_net_hdr *hdr) -{ -#if defined(INET) || defined(INET6) - int offset = hdr->csum_start + hdr->csum_offset; -#endif - - /* Only do a basic sanity check on the offset. */ - switch (eth_type) { -#if defined(INET) - case ETHERTYPE_IP: - if (__predict_false(offset < ip_start + sizeof(struct ip))) - return (1); - break; -#endif -#if defined(INET6) - case ETHERTYPE_IPV6: - if (__predict_false(offset < ip_start + sizeof(struct ip6_hdr))) - return (1); - break; -#endif - default: - /* Here we should increment the rx_csum_bad_ethtype counter. */ - return (1); - } - - /* - * Use the offset to determine the appropriate CSUM_* flags. This is - * a bit dirty, but we can get by with it since the checksum offsets - * happen to be different. We assume the host host does not do IPv4 - * header checksum offloading. - */ - switch (hdr->csum_offset) { - case offsetof(struct udphdr, uh_sum): - case offsetof(struct tcphdr, th_sum): - m->m_pkthdr.csum_flags |= CSUM_DATA_VALID | CSUM_PSEUDO_HDR; - m->m_pkthdr.csum_data = 0xFFFF; - break; - case offsetof(struct sctphdr, checksum): - m->m_pkthdr.csum_flags |= CSUM_SCTP_VALID; - break; - default: - /* Here we should increment the rx_csum_bad_offset counter. */ - return (1); - } - - return (0); -} - -static int -ptnet_rx_csum_by_parse(struct mbuf *m, uint16_t eth_type, int ip_start, - struct virtio_net_hdr *hdr) -{ - int offset, proto; - - switch (eth_type) { -#if defined(INET) - case ETHERTYPE_IP: { - struct ip *ip; - if (__predict_false(m->m_len < ip_start + sizeof(struct ip))) - return (1); - ip = (struct ip *)(m->m_data + ip_start); - proto = ip->ip_p; - offset = ip_start + (ip->ip_hl << 2); - break; - } -#endif -#if defined(INET6) - case ETHERTYPE_IPV6: - if (__predict_false(m->m_len < ip_start + - sizeof(struct ip6_hdr))) - return (1); - offset = ip6_lasthdr(m, ip_start, IPPROTO_IPV6, &proto); - if (__predict_false(offset < 0)) - return (1); - break; -#endif - default: - /* Here we should increment the rx_csum_bad_ethtype counter. */ - return (1); - } - - switch (proto) { - case IPPROTO_TCP: - if (__predict_false(m->m_len < offset + sizeof(struct tcphdr))) - return (1); - m->m_pkthdr.csum_flags |= CSUM_DATA_VALID | CSUM_PSEUDO_HDR; - m->m_pkthdr.csum_data = 0xFFFF; - break; - case IPPROTO_UDP: - if (__predict_false(m->m_len < offset + sizeof(struct udphdr))) - return (1); - m->m_pkthdr.csum_flags |= CSUM_DATA_VALID | CSUM_PSEUDO_HDR; - m->m_pkthdr.csum_data = 0xFFFF; - break; - case IPPROTO_SCTP: - if (__predict_false(m->m_len < offset + sizeof(struct sctphdr))) - return (1); - m->m_pkthdr.csum_flags |= CSUM_SCTP_VALID; - break; - default: - /* - * For the remaining protocols, FreeBSD does not support - * checksum offloading, so the checksum will be recomputed. - */ -#if 0 - if_printf(ifp, "cksum offload of unsupported " - "protocol eth_type=%#x proto=%d csum_start=%d " - "csum_offset=%d\n", __func__, eth_type, proto, - hdr->csum_start, hdr->csum_offset); -#endif - break; - } - - return (0); -} - -/* - * Set the appropriate CSUM_* flags. Unfortunately, the information - * provided is not directly useful to us. The VirtIO header gives the - * offset of the checksum, which is all Linux needs, but this is not - * how FreeBSD does things. We are forced to peek inside the packet - * a bit. - * - * It would be nice if VirtIO gave us the L4 protocol or if FreeBSD - * could accept the offsets and let the stack figure it out. - */ -static int -ptnet_rx_csum(struct mbuf *m, struct virtio_net_hdr *hdr) -{ - struct ether_header *eh; - struct ether_vlan_header *evh; - uint16_t eth_type; - int offset, error; - - eh = mtod(m, struct ether_header *); - eth_type = ntohs(eh->ether_type); - if (eth_type == ETHERTYPE_VLAN) { - /* BMV: We should handle nested VLAN tags too. */ - evh = mtod(m, struct ether_vlan_header *); - eth_type = ntohs(evh->evl_proto); - offset = sizeof(struct ether_vlan_header); - } else - offset = sizeof(struct ether_header); - - if (hdr->flags & VIRTIO_NET_HDR_F_NEEDS_CSUM) - error = ptnet_rx_csum_by_offset(m, eth_type, offset, hdr); - else - error = ptnet_rx_csum_by_parse(m, eth_type, offset, hdr); - - return (error); -} - static unsigned int ptnet_rx_discard(struct netmap_kring *kring, unsigned int head) { From owner-svn-soc-all@freebsd.org Fri Jul 8 15:45:16 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 25EB5B8260A for ; Fri, 8 Jul 2016 15:45:16 +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 1987012A1 for ; Fri, 8 Jul 2016 15:45:16 +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 u68FjFOl009333 for ; Fri, 8 Jul 2016 15:45:15 GMT (envelope-from vincenzo@FreeBSD.org) Received: (from www@localhost) by socsvn.freebsd.org (8.15.2/8.15.2/Submit) id u68FjFvA009321 for svn-soc-all@FreeBSD.org; Fri, 8 Jul 2016 15:45:15 GMT (envelope-from vincenzo@FreeBSD.org) Date: Fri, 8 Jul 2016 15:45:15 GMT Message-Id: <201607081545.u68FjFvA009321@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: r305834 - 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: Fri, 08 Jul 2016 15:45:16 -0000 Author: vincenzo Date: Fri Jul 8 15:45:14 2016 New Revision: 305834 URL: http://svnweb.FreeBSD.org/socsvn/?view=rev&rev=305834 Log: freebsd: ptnet_attach: add optional virtio-net header negotiation 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 Fri Jul 8 15:45:02 2016 (r305833) +++ soc2016/vincenzo/head/sys/dev/netmap/if_ptnet.c Fri Jul 8 15:45:14 2016 (r305834) @@ -94,6 +94,9 @@ #define DBG(x) #endif /* !DEBUG */ +/* Tunable parameters. */ +static bool ptnet_vnet_hdr = false; + struct ptnet_softc; struct ptnet_queue { @@ -269,6 +272,9 @@ /* Check if we are supported by the hypervisor. If not, * bail out immediately. */ + if (ptnet_vnet_hdr) { + ptfeatures |= NET_PTN_FEATURES_VNET_HDR; + } bus_write_4(sc->iomem, PTNET_IO_PTFEAT, ptfeatures); /* wanted */ ptfeatures = bus_read_4(sc->iomem, PTNET_IO_PTFEAT); /* acked */ if (!(ptfeatures & NET_PTN_FEATURES_BASE)) { @@ -410,6 +416,13 @@ sc->ptna_nm = (struct netmap_pt_guest_adapter *)NA(ifp); sc->ptna_nm->csb = sc->csb; + /* If virtio-net header was negotiated, set the virt_hdr_len field in + * the netmap adapter, to inform users that this netmap adapter requires + * the application to deal with the headers. */ + if (sc->ptfeatures & NET_PTN_FEATURES_VNET_HDR) { + sc->ptna_nm->hwup.up.virt_hdr_len = PTNET_HDR_SIZE; + } + /* Initialize a separate pass-through netmap adapter that is going to * be used by this driver only, and so never exposed to netmap. We * only need a subset of the available fields. */ From owner-svn-soc-all@freebsd.org Fri Jul 8 15:45:25 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 0D573B82623 for ; Fri, 8 Jul 2016 15:45:25 +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 00C8812B5 for ; Fri, 8 Jul 2016 15:45:25 +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 u68FjOvA009709 for ; Fri, 8 Jul 2016 15:45:24 GMT (envelope-from vincenzo@FreeBSD.org) Received: (from www@localhost) by socsvn.freebsd.org (8.15.2/8.15.2/Submit) id u68FjOjX009657 for svn-soc-all@FreeBSD.org; Fri, 8 Jul 2016 15:45:24 GMT (envelope-from vincenzo@FreeBSD.org) Date: Fri, 8 Jul 2016 15:45:24 GMT Message-Id: <201607081545.u68FjOjX009657@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: r305835 - 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: Fri, 08 Jul 2016 15:45:25 -0000 Author: vincenzo Date: Fri Jul 8 15:45:23 2016 New Revision: 305835 URL: http://svnweb.FreeBSD.org/socsvn/?view=rev&rev=305835 Log: freebsd: ptnet_attach: set offloadings flags in if_capabilities 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 Fri Jul 8 15:45:14 2016 (r305834) +++ soc2016/vincenzo/head/sys/dev/netmap/if_ptnet.c Fri Jul 8 15:45:23 2016 (r305835) @@ -384,6 +384,18 @@ ifp->if_data.ifi_hdrlen = sizeof(struct ether_vlan_header); ifp->if_capabilities |= IFCAP_JUMBO_MTU | IFCAP_VLAN_MTU; + if (sc->ptfeatures & NET_PTN_FEATURES_VNET_HDR) { + /* Similarly to what the vtnet driver does, we can emulate + * VLAN offloadings by inserting and removing the 802.1Q + * header during transmit and receive. We are then able + * to do checksum offloading of VLAN frames. */ + ifp->if_capabilities |= IFCAP_HWCSUM | IFCAP_HWCSUM_IPV6 + | IFCAP_VLAN_HWCSUM + | IFCAP_TSO | IFCAP_LRO + | IFCAP_VLAN_HWTSO + | IFCAP_VLAN_HWTAGGING; + } + ifp->if_capenable = ifp->if_capabilities; snprintf(sc->lock_name, sizeof(sc->lock_name), @@ -1913,8 +1925,6 @@ } mhead->m_pkthdr.rcvif = ifp; - - /* No support for checksum offloading for now. */ mhead->m_pkthdr.csum_flags = 0; /* Store the queue idx in the packet header. */ From owner-svn-soc-all@freebsd.org Fri Jul 8 15:45:33 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 B483BB8263B for ; Fri, 8 Jul 2016 15:45:33 +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 A803E12CB for ; Fri, 8 Jul 2016 15:45:33 +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 u68FjXb6009870 for ; Fri, 8 Jul 2016 15:45:33 GMT (envelope-from vincenzo@FreeBSD.org) Received: (from www@localhost) by socsvn.freebsd.org (8.15.2/8.15.2/Submit) id u68FjXSc009853 for svn-soc-all@FreeBSD.org; Fri, 8 Jul 2016 15:45:33 GMT (envelope-from vincenzo@FreeBSD.org) Date: Fri, 8 Jul 2016 15:45:33 GMT Message-Id: <201607081545.u68FjXSc009853@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: r305836 - 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: Fri, 08 Jul 2016 15:45:33 -0000 Author: vincenzo Date: Fri Jul 8 15:45:32 2016 New Revision: 305836 URL: http://svnweb.FreeBSD.org/socsvn/?view=rev&rev=305836 Log: freebsd: ptnet: small fixes in some comments 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 Fri Jul 8 15:45:23 2016 (r305835) +++ soc2016/vincenzo/head/sys/dev/netmap/if_ptnet.c Fri Jul 8 15:45:32 2016 (r305836) @@ -1176,12 +1176,12 @@ ptnet_rx_eof(pq); } -/* The following offloadings-related functions are taken from the virtio-net +/* The following offloadings-related functions are taken from the vtnet * driver, but the same functionality is required for the ptnet driver. - * As a temporary solution, I copied this code from virtio-net and I started + * As a temporary solution, I copied this code from vtnet and I started * to generalize it (taking away driver-specific statistic accounting), * making as little modifications as possible. - * In the future we need to share these functions between virtio-net and ptnet. + * In the future we need to share these functions between vtnet and ptnet. */ static int ptnet_tx_offload_ctx(struct mbuf *m, int *etype, int *proto, int *start) @@ -1492,7 +1492,7 @@ return (error); } -/* End of offloading-related functions to be shared with virtio-net. */ +/* End of offloading-related functions to be shared with vtnet. */ static inline void ptnet_sync_tail(struct ptnet_ring *ptring, struct netmap_kring *kring) From owner-svn-soc-all@freebsd.org Fri Jul 8 15:45: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 6CA06B82652 for ; Fri, 8 Jul 2016 15:45: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 47A0412DF for ; Fri, 8 Jul 2016 15:45: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 u68Fjgx1010040 for ; Fri, 8 Jul 2016 15:45:42 GMT (envelope-from vincenzo@FreeBSD.org) Received: (from www@localhost) by socsvn.freebsd.org (8.15.2/8.15.2/Submit) id u68FjfJS010022 for svn-soc-all@FreeBSD.org; Fri, 8 Jul 2016 15:45:41 GMT (envelope-from vincenzo@FreeBSD.org) Date: Fri, 8 Jul 2016 15:45:41 GMT Message-Id: <201607081545.u68FjfJS010022@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: r305837 - 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: Fri, 08 Jul 2016 15:45:42 -0000 Author: vincenzo Date: Fri Jul 8 15:45:41 2016 New Revision: 305837 URL: http://svnweb.FreeBSD.org/socsvn/?view=rev&rev=305837 Log: freebsd: fix PTNET_ALL_OFFLOAD macro 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 Fri Jul 8 15:45:32 2016 (r305836) +++ soc2016/vincenzo/head/sys/dev/netmap/if_ptnet.c Fri Jul 8 15:45:41 2016 (r305837) @@ -236,7 +236,8 @@ #define PTNET_CSUM_OFFLOAD (CSUM_TCP | CSUM_UDP | CSUM_SCTP) #define PTNET_CSUM_OFFLOAD_IPV6 (CSUM_TCP_IPV6 | CSUM_UDP_IPV6 |\ CSUM_SCTP_IPV6) -#define PTNET_ALL_OFFLOAD (CSUM_TSO | PTNET_CSUM_OFFLOAD | CSUM_TSO) +#define PTNET_ALL_OFFLOAD (CSUM_TSO | PTNET_CSUM_OFFLOAD |\ + PTNET_CSUM_OFFLOAD_IPV6) static int ptnet_attach(device_t dev) @@ -1054,7 +1055,7 @@ } /* If not native, don't call nm_set_native_flags, since we don't want - * to replace ndo_start_xmit method, nor set NAF_NETMAP_ON */ + * to replace if_transmit method, nor set NAF_NETMAP_ON */ if (native) { for_rx_tx(t) { for (i=0; im_pkthdr.csum_flags & PTNET_ALL_OFFLOAD) { mhead = ptnet_tx_offload(ifp, mhead, false, - (struct virtio_net_hdr *)nmbuf); + vh); if (unlikely(!mhead)) { /* Packet dropped because errors * occurred while preparing the vnet @@ -1633,6 +1637,12 @@ continue; } } + RD(1, "%s: [csum_flags %lX] vnet hdr: flags %x " + "csum_start %u csum_ofs %u hdr_len = %u " + "gso_size %u gso_type %x", __func__, + mhead->m_pkthdr.csum_flags, vh->flags, + vh->csum_start, vh->csum_offset, vh->hdr_len, + vh->gso_size, vh->gso_type); nmbuf += PTNET_HDR_SIZE; nmbuf_bytes += PTNET_HDR_SIZE; From owner-svn-soc-all@freebsd.org Fri Jul 8 15:45:54 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 756B0B8266C for ; Fri, 8 Jul 2016 15:45:54 +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 68ECF12F4 for ; Fri, 8 Jul 2016 15:45:54 +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 u68FjsUo010329 for ; Fri, 8 Jul 2016 15:45:54 GMT (envelope-from vincenzo@FreeBSD.org) Received: (from www@localhost) by socsvn.freebsd.org (8.15.2/8.15.2/Submit) id u68FjrNl010327 for svn-soc-all@FreeBSD.org; Fri, 8 Jul 2016 15:45:53 GMT (envelope-from vincenzo@FreeBSD.org) Date: Fri, 8 Jul 2016 15:45:53 GMT Message-Id: <201607081545.u68FjrNl010327@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: r305838 - 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: Fri, 08 Jul 2016 15:45:54 -0000 Author: vincenzo Date: Fri Jul 8 15:45:53 2016 New Revision: 305838 URL: http://svnweb.FreeBSD.org/socsvn/?view=rev&rev=305838 Log: freebsd: ptnet_ioctl: add SIOCSIFCAP stub implementation 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 Fri Jul 8 15:45:41 2016 (r305837) +++ soc2016/vincenzo/head/sys/dev/netmap/if_ptnet.c Fri Jul 8 15:45:53 2016 (r305838) @@ -706,6 +706,7 @@ { struct ptnet_softc *sc = ifp->if_softc; device_t dev = sc->dev; + struct ifreq *ifr = (struct ifreq *)data; int err = 0; switch (cmd) { @@ -724,6 +725,14 @@ PTNET_CORE_UNLOCK(sc); break; + case SIOCSIFCAP: + device_printf(dev, "SIOCSIFCAP %x %x\n", + ifr->ifr_reqcap, ifp->if_capenable); + PTNET_CORE_LOCK(sc); + ifp->if_capenable = ifr->ifr_reqcap; + PTNET_CORE_UNLOCK(sc); + break; + default: err = ether_ioctl(ifp, cmd, data); break; From owner-svn-soc-all@freebsd.org Fri Jul 8 15:46: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 6EEDAB826BE for ; Fri, 8 Jul 2016 15:46: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 53EDC13E5 for ; Fri, 8 Jul 2016 15:46: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 u68FkZib011099 for ; Fri, 8 Jul 2016 15:46:35 GMT (envelope-from vincenzo@FreeBSD.org) Received: (from www@localhost) by socsvn.freebsd.org (8.15.2/8.15.2/Submit) id u68FkYQf011083 for svn-soc-all@FreeBSD.org; Fri, 8 Jul 2016 15:46:34 GMT (envelope-from vincenzo@FreeBSD.org) Date: Fri, 8 Jul 2016 15:46:34 GMT Message-Id: <201607081546.u68FkYQf011083@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: r305839 - 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: Fri, 08 Jul 2016 15:46:35 -0000 Author: vincenzo Date: Fri Jul 8 15:46:34 2016 New Revision: 305839 URL: http://svnweb.FreeBSD.org/socsvn/?view=rev&rev=305839 Log: freebsd: ptnet_ioctl: support SIOCSIFMTU 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 Fri Jul 8 15:45:53 2016 (r305838) +++ soc2016/vincenzo/head/sys/dev/netmap/if_ptnet.c Fri Jul 8 15:46:34 2016 (r305839) @@ -232,6 +232,7 @@ #define PTNET_RX_BUDGET 512 #define PTNET_TX_BATCH 64 #define PTNET_HDR_SIZE sizeof(struct virtio_net_hdr_mrg_rxbuf) +#define PTNET_MAX_PKT_SIZE 65536 #define PTNET_CSUM_OFFLOAD (CSUM_TCP | CSUM_UDP | CSUM_SCTP) #define PTNET_CSUM_OFFLOAD_IPV6 (CSUM_TCP_IPV6 | CSUM_UDP_IPV6 |\ @@ -710,32 +711,44 @@ int err = 0; switch (cmd) { - case SIOCSIFFLAGS: - device_printf(dev, "SIOCSIFFLAGS %x\n", ifp->if_flags); - PTNET_CORE_LOCK(sc); - if (ifp->if_flags & IFF_UP) { - /* Network stack wants the iff to be up. */ - err = ptnet_init_locked(sc); - } else { - /* Network stack wants the iff to be down. */ - err = ptnet_stop(sc); - } - /* We don't need to do nothing to support IFF_PROMISC, - * since that is managed by the backend port. */ - PTNET_CORE_UNLOCK(sc); - break; + case SIOCSIFFLAGS: + device_printf(dev, "SIOCSIFFLAGS %x\n", ifp->if_flags); + PTNET_CORE_LOCK(sc); + if (ifp->if_flags & IFF_UP) { + /* Network stack wants the iff to be up. */ + err = ptnet_init_locked(sc); + } else { + /* Network stack wants the iff to be down. */ + err = ptnet_stop(sc); + } + /* We don't need to do nothing to support IFF_PROMISC, + * since that is managed by the backend port. */ + PTNET_CORE_UNLOCK(sc); + break; + + case SIOCSIFCAP: + device_printf(dev, "SIOCSIFCAP %x %x\n", + ifr->ifr_reqcap, ifp->if_capenable); + PTNET_CORE_LOCK(sc); + ifp->if_capenable = ifr->ifr_reqcap; + PTNET_CORE_UNLOCK(sc); + break; - case SIOCSIFCAP: - device_printf(dev, "SIOCSIFCAP %x %x\n", - ifr->ifr_reqcap, ifp->if_capenable); + case SIOCSIFMTU: + /* We support any reasonable MTU. */ + if (ifr->ifr_mtu < ETHERMIN || + ifr->ifr_mtu > PTNET_MAX_PKT_SIZE) { + err = EINVAL; + } else { PTNET_CORE_LOCK(sc); - ifp->if_capenable = ifr->ifr_reqcap; + ifp->if_mtu = ifr->ifr_mtu; PTNET_CORE_UNLOCK(sc); - break; + } + break; - default: - err = ether_ioctl(ifp, cmd, data); - break; + default: + err = ether_ioctl(ifp, cmd, data); + break; } return err; @@ -794,7 +807,7 @@ nm_buf_size = NETMAP_BUF_SIZE(na_dr); KASSERT(nm_buf_size > 0, "Invalid netmap buffer size"); - sc->min_tx_space = 65536 / nm_buf_size + 2; + sc->min_tx_space = PTNET_MAX_PKT_SIZE / nm_buf_size + 2; device_printf(sc->dev, "%s: min_tx_space = %u\n", __func__, sc->min_tx_space); From owner-svn-soc-all@freebsd.org Fri Jul 8 15:46: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 95C1DB826D4 for ; Fri, 8 Jul 2016 15:46:46 +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 894D4143F for ; Fri, 8 Jul 2016 15:46:46 +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 u68FkkAt011309 for ; Fri, 8 Jul 2016 15:46:46 GMT (envelope-from vincenzo@FreeBSD.org) Received: (from www@localhost) by socsvn.freebsd.org (8.15.2/8.15.2/Submit) id u68FkkSX011307 for svn-soc-all@FreeBSD.org; Fri, 8 Jul 2016 15:46:46 GMT (envelope-from vincenzo@FreeBSD.org) Date: Fri, 8 Jul 2016 15:46:46 GMT Message-Id: <201607081546.u68FkkSX011307@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: r305840 - 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: Fri, 08 Jul 2016 15:46:46 -0000 Author: vincenzo Date: Fri Jul 8 15:46:45 2016 New Revision: 305840 URL: http://svnweb.FreeBSD.org/socsvn/?view=rev&rev=305840 Log: freebsd: ptnet_ioctl: support SIOCSIFMEDIA and SIOCGIFMEDIA 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 Fri Jul 8 15:46:34 2016 (r305839) +++ soc2016/vincenzo/head/sys/dev/netmap/if_ptnet.c Fri Jul 8 15:46:45 2016 (r305840) @@ -746,6 +746,11 @@ } break; + case SIOCSIFMEDIA: + case SIOCGIFMEDIA: + err = ifmedia_ioctl(ifp, ifr, &sc->media, cmd); + break; + default: err = ether_ioctl(ifp, cmd, data); break; From owner-svn-soc-all@freebsd.org Fri Jul 8 15:46:59 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 A8A11B82721 for ; Fri, 8 Jul 2016 15:46:59 +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 9C284146A for ; Fri, 8 Jul 2016 15:46:59 +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 u68Fkxb2011591 for ; Fri, 8 Jul 2016 15:46:59 GMT (envelope-from vincenzo@FreeBSD.org) Received: (from www@localhost) by socsvn.freebsd.org (8.15.2/8.15.2/Submit) id u68Fkxw0011524 for svn-soc-all@FreeBSD.org; Fri, 8 Jul 2016 15:46:59 GMT (envelope-from vincenzo@FreeBSD.org) Date: Fri, 8 Jul 2016 15:46:59 GMT Message-Id: <201607081546.u68Fkxw0011524@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: r305841 - 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: Fri, 08 Jul 2016 15:46:59 -0000 Author: vincenzo Date: Fri Jul 8 15:46:58 2016 New Revision: 305841 URL: http://svnweb.FreeBSD.org/socsvn/?view=rev&rev=305841 Log: freebsd: ptnet_init: translate if_capenable into if_hwassist 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 Fri Jul 8 15:46:45 2016 (r305840) +++ soc2016/vincenzo/head/sys/dev/netmap/if_ptnet.c Fri Jul 8 15:46:58 2016 (r305841) @@ -773,6 +773,20 @@ device_printf(sc->dev, "%s\n", __func__); + /* Translate offload capabilities according to if_capenable. */ + ifp->if_hwassist = 0; + if (ifp->if_capenable & IFCAP_TXCSUM) + ifp->if_hwassist |= PTNET_CSUM_OFFLOAD; + if (ifp->if_capenable & IFCAP_TXCSUM_IPV6) + ifp->if_hwassist |= PTNET_CSUM_OFFLOAD_IPV6; + if (ifp->if_capenable & IFCAP_TSO4) + ifp->if_hwassist |= CSUM_IP_TSO; + if (ifp->if_capenable & IFCAP_TSO6) + ifp->if_hwassist |= CSUM_IP6_TSO; + + /* + * Prepare the interface for netmap mode access. + */ netmap_update_config(na_dr); ret = netmap_mem_finalize(na_dr->nm_mem, na_dr); From owner-svn-soc-all@freebsd.org Sat Jul 9 13:51:23 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 1BD32B82F8D for ; Sat, 9 Jul 2016 13:51:23 +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 E9F591A53 for ; Sat, 9 Jul 2016 13:51:22 +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 u69DpMnT067057 for ; Sat, 9 Jul 2016 13:51:22 GMT (envelope-from iateaca@FreeBSD.org) Received: (from www@localhost) by socsvn.freebsd.org (8.15.2/8.15.2/Submit) id u69DpMTx067055 for svn-soc-all@FreeBSD.org; Sat, 9 Jul 2016 13:51:22 GMT (envelope-from iateaca@FreeBSD.org) Date: Sat, 9 Jul 2016 13:51:22 GMT Message-Id: <201607091351.u69DpMTx067055@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: r305903 - 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, 09 Jul 2016 13:51:23 -0000 Author: iateaca Date: Sat Jul 9 13:51:21 2016 New Revision: 305903 URL: http://svnweb.FreeBSD.org/socsvn/?view=rev&rev=305903 Log: implement the RIRB interrupts M bhyve/pci_hda.c 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 Jul 9 12:17:01 2016 (r305902) +++ soc2016/iateaca/bhyve-hda-head/usr.sbin/bhyve/pci_hda.c Sat Jul 9 13:51:21 2016 (r305903) @@ -81,6 +81,7 @@ uint32_t regs[HDA_LAST_OFFSET]; uint8_t lintr; + uint8_t rirb_cnt; uint64_t wall_clock_start; struct hda_codec_cmd_ctl corb; @@ -106,6 +107,8 @@ static struct hda_softc *hda_init(const char *opts); static void hda_update_intr(struct hda_softc *sc); +static void +hda_response_interrupt(struct hda_softc *sc); static int hda_codec_constructor(struct hda_softc *sc, struct hda_codec_class *codec); static struct hda_codec_class * @@ -330,11 +333,16 @@ uint32_t intctl = hda_get_reg_by_offset(sc, HDAC_INTCTL); uint32_t intsts = 0; uint32_t sdsts = 0; + uint32_t rirbsts = 0; uint32_t off = 0; int i; /* TODO update the CIS bits */ + rirbsts = hda_get_reg_by_offset(sc, HDAC_RIRBSTS); + if (rirbsts & (HDAC_RIRBSTS_RINTFL | HDAC_RIRBSTS_RIRBOIS)) + intsts |= HDAC_INTSTS_CIS; + /* update the SIS bits */ for (i = 0; i < HDA_IOSS_NO; i++) { off = hda_get_offset_stream(i); @@ -364,6 +372,20 @@ return; } +static void +hda_response_interrupt(struct hda_softc *sc) +{ + uint8_t rirbctl = hda_get_reg_by_offset(sc, HDAC_RIRBCTL); + + if ((rirbctl & HDAC_RIRBCTL_RINTCTL) && sc->rirb_cnt) { + sc->rirb_cnt = 0; + hda_set_field_by_offset(sc, HDAC_RIRBSTS, HDAC_RIRBSTS_RINTFL, HDAC_RIRBSTS_RINTFL); + hda_update_intr(sc); + } + + return; +} + static int hda_codec_constructor(struct hda_softc *sc, struct hda_codec_class *codec) { @@ -725,6 +747,9 @@ hda_set_reg_by_offset(sc, HDAC_CORBRP, corb->rp); + if (corb->run) + hda_response_interrupt(sc); + return 0; } @@ -956,6 +981,7 @@ struct hda_softc *sc = NULL; struct hda_codec_cmd_ctl *rirb = NULL; uint32_t response_ex = 0; + uint8_t rintcnt = 0; assert(hci); assert(hci->cad <= HDA_CODEC_MAX); @@ -975,8 +1001,14 @@ hda_dma_st_dword(rirb->dma_vaddr + HDA_RIRB_ENTRY_LEN * rirb->wp + 0x04, response_ex); hda_set_reg_by_offset(sc, HDAC_RIRBWP, rirb->wp); + + sc->rirb_cnt++; } + rintcnt = hda_get_reg_by_offset(sc, HDAC_RINTCNT); + if (sc->rirb_cnt == rintcnt) + hda_response_interrupt(sc); + return 0; } From owner-svn-soc-all@freebsd.org Sat Jul 9 15:33:49 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 EBF8CB84790 for ; Sat, 9 Jul 2016 15:33:49 +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 C57B3162A for ; Sat, 9 Jul 2016 15:33:49 +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 u69FXnT6015721 for ; Sat, 9 Jul 2016 15:33:49 GMT (envelope-from iateaca@FreeBSD.org) Received: (from www@localhost) by socsvn.freebsd.org (8.15.2/8.15.2/Submit) id u69FXneJ015719 for svn-soc-all@FreeBSD.org; Sat, 9 Jul 2016 15:33:49 GMT (envelope-from iateaca@FreeBSD.org) Date: Sat, 9 Jul 2016 15:33:49 GMT Message-Id: <201607091533.u69FXneJ015719@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: r305906 - 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, 09 Jul 2016 15:33:50 -0000 Author: iateaca Date: Sat Jul 9 15:33:48 2016 New Revision: 305906 URL: http://svnweb.FreeBSD.org/socsvn/?view=rev&rev=305906 Log: implement the statests interrupts M bhyve/pci_hda.c 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 Jul 9 14:59:16 2016 (r305905) +++ soc2016/iateaca/bhyve-hda-head/usr.sbin/bhyve/pci_hda.c Sat Jul 9 15:33:48 2016 (r305906) @@ -30,6 +30,7 @@ #define HDAC_SDSTS_FIFORDY (1 << 5) #define HDA_RIRBSTS_IRQ_MASK (HDAC_RIRBSTS_RINTFL | HDAC_RIRBSTS_RIRBOIS) +#define HDA_STATESTS_IRQ_MASK ((1 << HDA_CODEC_MAX) - 1) #define HDA_SDSTS_IRQ_MASK (HDAC_SDSTS_DESE | HDAC_SDSTS_FIFOE | HDAC_SDSTS_BCIS) /* @@ -157,6 +158,8 @@ static void hda_set_gctl(struct hda_softc *sc, uint32_t offset, uint32_t old); static void +hda_set_statests(struct hda_softc *sc, uint32_t offset, uint32_t old); +static void hda_set_corbwp(struct hda_softc *sc, uint32_t offset, uint32_t old); static void hda_set_corbctl(struct hda_softc *sc, uint32_t offset, uint32_t old); @@ -197,6 +200,7 @@ static const hda_set_reg_handler hda_set_reg_table[] = { [HDAC_GCTL] = hda_set_gctl, + [HDAC_STATESTS] = hda_set_statests, [HDAC_CORBWP] = hda_set_corbwp, [HDAC_CORBCTL] = hda_set_corbctl, [HDAC_RIRBCTL] = hda_set_rirbctl, @@ -334,15 +338,21 @@ uint32_t intsts = 0; uint32_t sdsts = 0; uint32_t rirbsts = 0; + uint32_t wakeen = 0; + uint32_t statests = 0; uint32_t off = 0; int i; - /* TODO update the CIS bits */ - + /* update the CIS bits */ rirbsts = hda_get_reg_by_offset(sc, HDAC_RIRBSTS); if (rirbsts & (HDAC_RIRBSTS_RINTFL | HDAC_RIRBSTS_RIRBOIS)) intsts |= HDAC_INTSTS_CIS; + wakeen = hda_get_reg_by_offset(sc, HDAC_WAKEEN); + statests = hda_get_reg_by_offset(sc, HDAC_STATESTS); + if (statests & wakeen) + intsts |= HDAC_INTSTS_CIS; + /* update the SIS bits */ for (i = 0; i < HDA_IOSS_NO; i++) { off = hda_get_offset_stream(i); @@ -847,6 +857,21 @@ } static void +hda_set_statests(struct hda_softc *sc, uint32_t offset, uint32_t old) +{ + uint32_t value = hda_get_reg_by_offset(sc, offset); + + hda_set_reg_by_offset(sc, offset, old); + + /* clear the corresponding bits written by the software (guest) */ + hda_set_field_by_offset(sc, offset, value & HDA_STATESTS_IRQ_MASK, 0); + + hda_update_intr(sc); + + return; +} + +static void hda_set_corbwp(struct hda_softc *sc, uint32_t offset, uint32_t old) { hda_corb_run(sc); @@ -971,6 +996,7 @@ sdiwake = 1 << hci->cad; hda_set_field_by_offset(sc, HDAC_STATESTS, sdiwake, sdiwake); + hda_update_intr(sc); return 0; } From owner-svn-soc-all@freebsd.org Sat Jul 9 18:46:32 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 BAB09B84AFD for ; Sat, 9 Jul 2016 18:46:32 +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 AE14D16CA for ; Sat, 9 Jul 2016 18:46:32 +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 u69IkWnB093603 for ; Sat, 9 Jul 2016 18:46:32 GMT (envelope-from iateaca@FreeBSD.org) Received: (from www@localhost) by socsvn.freebsd.org (8.15.2/8.15.2/Submit) id u69IkWxX093600 for svn-soc-all@FreeBSD.org; Sat, 9 Jul 2016 18:46:32 GMT (envelope-from iateaca@FreeBSD.org) Date: Sat, 9 Jul 2016 18:46:32 GMT Message-Id: <201607091846.u69IkWxX093600@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: r305909 - 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, 09 Jul 2016 18:46:32 -0000 Author: iateaca Date: Sat Jul 9 18:46:31 2016 New Revision: 305909 URL: http://svnweb.FreeBSD.org/socsvn/?view=rev&rev=305909 Log: implement the DMA Position in Buffer mechanism in order to allow the guest to read the position in buffer of each stream M bhyve/pci_hda.c 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 Jul 9 17:48:45 2016 (r305908) +++ soc2016/iateaca/bhyve-hda-head/usr.sbin/bhyve/pci_hda.c Sat Jul 9 18:46:31 2016 (r305909) @@ -20,6 +20,7 @@ #define HDA_CORB_ENTRY_LEN 0x04 #define HDA_RIRB_ENTRY_LEN 0x08 #define HDA_BDL_ENTRY_LEN 0x10 +#define HDA_DMA_PIB_ENTRY_LEN 0x08 #define HDA_STREAM_TAGS_CNT 0x10 #define HDA_STREAM_REGS_BASE 0x80 #define HDA_STREAM_REGS_LEN 0x20 @@ -91,6 +92,9 @@ struct hda_codec_inst *codecs[HDA_CODEC_MAX]; uint8_t codecs_no; + /* Base Address of the DMA Position Buffer */ + void *dma_pib_vaddr; + struct hda_stream_desc streams[HDA_IOSS_NO]; uint8_t stream_map[HDA_STREAM_TAGS_CNT]; }; @@ -168,6 +172,8 @@ static void hda_set_rirbsts(struct hda_softc *sc, uint32_t offset, uint32_t old); static void +hda_set_dpiblbase(struct hda_softc *sc, uint32_t offset, uint32_t old); +static void hda_set_sdctl(struct hda_softc *sc, uint32_t offset, uint32_t old); static void hda_set_sdctl2(struct hda_softc *sc, uint32_t offset, uint32_t old); @@ -205,6 +211,7 @@ [HDAC_CORBCTL] = hda_set_corbctl, [HDAC_RIRBCTL] = hda_set_rirbctl, [HDAC_RIRBSTS] = hda_set_rirbsts, + [HDAC_DPIBLBASE] = hda_set_dpiblbase, #define HDAC_ISTREAM(n, iss, oss) \ [_HDAC_ISDCTL(n, iss, oss)] = hda_set_sdctl, \ @@ -631,6 +638,8 @@ st->bp = 0; st->be = 0; hda_set_reg_by_offset(sc, off + HDAC_SDLPIB, 0); + if (sc->dma_pib_vaddr) + *(uint32_t *)(sc->dma_pib_vaddr + stream_ind * HDA_DMA_PIB_ENTRY_LEN) = 0; st->run = 1; @@ -931,6 +940,36 @@ } static void +hda_set_dpiblbase(struct hda_softc *sc, uint32_t offset, uint32_t old) +{ + uint32_t value = hda_get_reg_by_offset(sc, offset); + uint64_t dpiblbase = 0; + uint64_t dpibubase = 0; + uint64_t dpibpaddr = 0; + + if ((value & HDAC_DPLBASE_DPLBASE_DMAPBE) != (old & HDAC_DPLBASE_DPLBASE_DMAPBE)) { + if (value & HDAC_DPLBASE_DPLBASE_DMAPBE) { + dpiblbase = value & HDAC_DPLBASE_DPLBASE_MASK; + dpibubase = hda_get_reg_by_offset(sc, HDAC_DPIBUBASE); + + dpibpaddr = dpiblbase | (dpibubase << 32); + DPRINTF("DMA Position In Buffer dma_paddr: %p\n", (void *)dpibpaddr); + + sc->dma_pib_vaddr = hda_dma_get_vaddr(sc, dpibpaddr, HDA_DMA_PIB_ENTRY_LEN * HDA_IOSS_NO); + if (!sc->dma_pib_vaddr) { + DPRINTF("Fail to get the guest virtual address\n"); + assert(0); + } + } else { + DPRINTF("DMA Position In Buffer Reset\n"); + sc->dma_pib_vaddr = NULL; + } + } + + return; +} + +static void hda_set_sdctl(struct hda_softc *sc, uint32_t offset, uint32_t old) { uint8_t stream_ind = hda_get_stream_by_offsets(offset, HDAC_SDCTL0); @@ -1111,6 +1150,8 @@ } hda_set_reg_by_offset(sc, off + HDAC_SDLPIB, lpib); + if (sc->dma_pib_vaddr) + *(uint32_t *)(sc->dma_pib_vaddr + stream_ind * HDA_DMA_PIB_ENTRY_LEN) = lpib; if (irq) { hda_set_field_by_offset(sc, off + HDAC_SDSTS, HDAC_SDSTS_BCIS, HDAC_SDSTS_BCIS);