From owner-svn-soc-all@freebsd.org Sun Jun 26 10:27:18 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 E000DA79A8D for ; Sun, 26 Jun 2016 10:27:18 +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 D3AA31B24 for ; Sun, 26 Jun 2016 10:27:18 +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 u5QARI63070639 for ; Sun, 26 Jun 2016 10:27:18 GMT (envelope-from iateaca@FreeBSD.org) Received: (from www@localhost) by socsvn.freebsd.org (8.15.2/8.15.2/Submit) id u5QARID9070636 for svn-soc-all@FreeBSD.org; Sun, 26 Jun 2016 10:27:18 GMT (envelope-from iateaca@FreeBSD.org) Date: Sun, 26 Jun 2016 10:27:18 GMT Message-Id: <201606261027.u5QARID9070636@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: r305555 - 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, 26 Jun 2016 10:27:19 -0000 Author: iateaca Date: Sun Jun 26 10:27:17 2016 New Revision: 305555 URL: http://svnweb.FreeBSD.org/socsvn/?view=rev&rev=305555 Log: check the audio context is initialized when try to start it M bhyve/hda_codec.c Modified: soc2016/iateaca/bhyve-hda-head/usr.sbin/bhyve/hda_codec.c Modified: soc2016/iateaca/bhyve-hda-head/usr.sbin/bhyve/hda_codec.c ============================================================================== --- soc2016/iateaca/bhyve-hda-head/usr.sbin/bhyve/hda_codec.c Sun Jun 26 00:53:31 2016 (r305554) +++ soc2016/iateaca/bhyve-hda-head/usr.sbin/bhyve/hda_codec.c Sun Jun 26 10:27:17 2016 (r305555) @@ -78,6 +78,7 @@ typedef int (*setup_func_t)(void *arg); struct hda_audio_ctxt { + uint8_t started; char name[64]; uint8_t run; pthread_t tid; @@ -389,6 +390,8 @@ { uint8_t div = 0; + assert(params); + /* Compute the Sample Rate */ params->rate = (fmt & HDA_CODEC_FMT_BASE_MASK) ? 44100 : 48000; @@ -568,6 +571,8 @@ pthread_set_name_np(actx->tid, tname); assert(!err); + actx->started = 1; + return 0; } @@ -576,6 +581,9 @@ { int err = 0; + assert(actx); + assert(actx->started); + /* The stream is supposed to be stopped */ if (actx->run) return -1; From owner-svn-soc-all@freebsd.org Sun Jun 26 17:01:24 2016 Return-Path: Delivered-To: svn-soc-all@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id C44D6B816AD for ; Sun, 26 Jun 2016 17:01:24 +0000 (UTC) (envelope-from iateaca@FreeBSD.org) Received: from socsvn.freebsd.org (socsvn.freebsd.org [IPv6:2001:1900:2254:206a::50:2]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mx1.freebsd.org (Postfix) with ESMTPS id A8D3E2AF4 for ; Sun, 26 Jun 2016 17:01:24 +0000 (UTC) (envelope-from iateaca@FreeBSD.org) Received: from socsvn.freebsd.org ([127.0.1.124]) by socsvn.freebsd.org (8.15.2/8.15.2) with ESMTP id u5QH1OMO001644 for ; Sun, 26 Jun 2016 17:01:24 GMT (envelope-from iateaca@FreeBSD.org) Received: (from www@localhost) by socsvn.freebsd.org (8.15.2/8.15.2/Submit) id u5QH1Ma7000832 for svn-soc-all@FreeBSD.org; Sun, 26 Jun 2016 17:01:22 GMT (envelope-from iateaca@FreeBSD.org) Date: Sun, 26 Jun 2016 17:01:22 GMT Message-Id: <201606261701.u5QH1Ma7000832@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: r305562 - 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, 26 Jun 2016 17:01:24 -0000 Author: iateaca Date: Sun Jun 26 17:01:21 2016 New Revision: 305562 URL: http://svnweb.FreeBSD.org/socsvn/?view=rev&rev=305562 Log: implement the hda_transfer function in order to transfer the samples between the guest system memory and the sound device TODO this function is called from the codec context and must be synchronized with the hda context using a mutex M bhyve/audio.c M bhyve/audio.h M bhyve/hda_codec.c M bhyve/pci_hda.c M bhyve/pci_hda.h Modified: soc2016/iateaca/bhyve-hda-head/usr.sbin/bhyve/audio.c soc2016/iateaca/bhyve-hda-head/usr.sbin/bhyve/audio.h soc2016/iateaca/bhyve-hda-head/usr.sbin/bhyve/hda_codec.c soc2016/iateaca/bhyve-hda-head/usr.sbin/bhyve/pci_hda.c soc2016/iateaca/bhyve-hda-head/usr.sbin/bhyve/pci_hda.h Modified: soc2016/iateaca/bhyve-hda-head/usr.sbin/bhyve/audio.c ============================================================================== --- soc2016/iateaca/bhyve-hda-head/usr.sbin/bhyve/audio.c Sun Jun 26 16:38:42 2016 (r305561) +++ soc2016/iateaca/bhyve-hda-head/usr.sbin/bhyve/audio.c Sun Jun 26 17:01:21 2016 (r305562) @@ -135,7 +135,7 @@ * @buf - the buffer containing the samples * @count - the number of bytes in buffer */ -ssize_t audio_playback(struct audio *aud, const void *buf, size_t count) +int audio_playback(struct audio *aud, const void *buf, size_t count) { int audio_fd = -1; ssize_t len = 0, total = 0; Modified: soc2016/iateaca/bhyve-hda-head/usr.sbin/bhyve/audio.h ============================================================================== --- soc2016/iateaca/bhyve-hda-head/usr.sbin/bhyve/audio.h Sun Jun 26 16:38:42 2016 (r305561) +++ soc2016/iateaca/bhyve-hda-head/usr.sbin/bhyve/audio.h Sun Jun 26 17:01:21 2016 (r305562) @@ -25,6 +25,7 @@ * audio_init - initialize an instance of audio player * @dev_name - the backend sound device used to play / capture * @dir - dir = 1 for write mode, dir = 0 for read mode + * Returns NULL on error and the address of the audio player instance */ struct audio *audio_init(const char *dev_name, uint8_t dir); @@ -32,6 +33,7 @@ * audio_set_params - reset the sound device and set the audio params * @aud - the audio player to be configured * @params - the audio parameters to be set + * Returns -1 on error and 0 on success */ int audio_set_params(struct audio *aud, struct audio_params *params); @@ -40,7 +42,8 @@ * @aud - the audio player used to play the samples * @buf - the buffer containing the samples * @count - the number of bytes in buffer + * Returns -1 on error and 0 on success */ -ssize_t audio_playback(struct audio *aud, const void *buf, size_t count); +int audio_playback(struct audio *aud, const void *buf, size_t count); #endif /* _AUDIO_EMUL_H_ */ Modified: soc2016/iateaca/bhyve-hda-head/usr.sbin/bhyve/hda_codec.c ============================================================================== --- soc2016/iateaca/bhyve-hda-head/usr.sbin/bhyve/hda_codec.c Sun Jun 26 16:38:42 2016 (r305561) +++ soc2016/iateaca/bhyve-hda-head/usr.sbin/bhyve/hda_codec.c Sun Jun 26 17:01:21 2016 (r305562) @@ -121,6 +121,7 @@ }; struct hda_codec_softc { + struct hda_codec_inst *hci; uint32_t subsystem_id; uint32_t no_nodes; const uint32_t (*get_parameters)[HDA_CODEC_PARAMS_COUNT]; @@ -258,6 +259,7 @@ return -1; } + sc->hci = hci; hci->priv = sc; return 0; @@ -462,21 +464,28 @@ hda_codec_audio_output_do_transfer(void *arg) { struct hda_codec_softc *sc = (struct hda_codec_softc *)arg; + struct hda_codec_inst *hci = NULL; + struct hda_ops *hops = NULL; struct hda_codec_stream *st = NULL; struct audio *aud = NULL; int err; + hci = sc->hci; + assert(hci); + + hops = hci->hops; + assert(hops); + st = &sc->streams[HDA_CODEC_STREAM_OUTPUT]; aud = st->aud; - memset(st->buf, 0x31, sizeof(st->buf)); + err = hops->transfer(hci, st->stream, 1, st->buf, sizeof(st->buf)); + if (err) + return; err = audio_playback(aud, st->buf, sizeof(st->buf)); assert(!err); - usleep(20 * 1000); - - DPRINTF("\n"); return; } Modified: soc2016/iateaca/bhyve-hda-head/usr.sbin/bhyve/pci_hda.c ============================================================================== --- soc2016/iateaca/bhyve-hda-head/usr.sbin/bhyve/pci_hda.c Sun Jun 26 16:38:42 2016 (r305561) +++ soc2016/iateaca/bhyve-hda-head/usr.sbin/bhyve/pci_hda.c Sun Jun 26 17:01:21 2016 (r305562) @@ -22,6 +22,7 @@ #define HDA_STREAM_REGS_BASE 0x80 #define HDA_STREAM_REGS_LEN 0x20 +#define HDA_DMA_ACCESS_LEN (sizeof(uint32_t)) #define HDA_BDL_MAX_LEN 0x0100 /* @@ -59,6 +60,11 @@ uint8_t run; uint8_t dir; + /* bp is the no. of bytes transferred in the current bdle */ + uint32_t bp; + /* be is the no. of bdles transferred in the bdl */ + uint32_t be; + struct hda_bdle_desc bdl[HDA_BDL_MAX_LEN]; uint32_t bdl_cnt; }; @@ -156,6 +162,9 @@ hda_signal_state_change(struct hda_codec_inst *hci); static int hda_response(struct hda_codec_inst *hci, uint32_t response, uint8_t unsol); +static int +hda_transfer(struct hda_codec_inst *hci, uint8_t stream, uint8_t dir, void *buf, size_t count); + /* * PCI HDA function declarations @@ -218,6 +227,7 @@ static struct hda_ops hops = { .signal = hda_signal_state_change, .response = hda_response, + .transfer = hda_transfer, }; struct pci_devemu pci_de_hda = { @@ -542,6 +552,8 @@ bdle = (struct hda_bdle *)bdl_vaddr; for (i = 0; i < bdl_cnt; i++, bdle++) { bdle_sz = bdle->len; + assert(!(bdle_sz % HDA_DMA_ACCESS_LEN)); + bdle_addrl = bdle->addrl; bdle_addrh = bdle->addrh; @@ -567,6 +579,11 @@ sc->stream_map[strm] = stream_ind; st->stream = strm; st->dir = dir; + st->bp = 0; + st->be = 0; + hda_set_reg_by_offset(sc, off + HDAC_SDLPIB, 0); + + st->run = 1; err = hda_notify_codecs(sc, 1, strm, dir); assert(!err); @@ -584,6 +601,8 @@ DPRINTF("stream: 0x%x, strm: 0x%x, dir: 0x%x\n", stream_ind, strm, dir); + st->run = 0; + err = hda_notify_codecs(sc, 0, strm, dir); assert(!err); @@ -925,6 +944,84 @@ return 0; } +static int +hda_transfer(struct hda_codec_inst *hci, uint8_t stream, uint8_t dir, void *buf, size_t count) +{ + struct hda_softc *sc = NULL; + struct hda_stream_desc *st = NULL; + struct hda_bdle_desc *bdl = NULL; + struct hda_bdle_desc *bdle_desc = NULL; + uint8_t stream_ind = 0; + uint32_t lpib = 0; + uint32_t off = 0; + size_t left = 0; + uint8_t irq = 0; + + assert(hci); + assert(hci->hda); + assert(buf); + assert(!(count % HDA_DMA_ACCESS_LEN)); + + sc = hci->hda; + + assert(stream < HDA_STREAM_TAGS_CNT); + stream_ind = sc->stream_map[stream]; + + st = &sc->streams[stream_ind]; + if (!st->run) { + DPRINTF("Stream 0x%x stopped\n", stream); + return -1; + } + + assert(st->stream == stream); + assert(st->dir == dir); + + off = hda_get_offset_stream(stream_ind); + + lpib = hda_get_reg_by_offset(sc, off + HDAC_SDLPIB); + + bdl = st->bdl; + + assert(st->be < st->bdl_cnt); + assert(st->bp < bdl[st->be].len); + + left = count; + while (left) { + bdle_desc = &bdl[st->be]; + + if (dir) + *(uint32_t *)buf = hda_dma_ld_dword(bdle_desc->addr + st->bp); + else + hda_dma_st_dword(bdle_desc->addr + st->bp, *(uint32_t *)buf); + + buf += HDA_DMA_ACCESS_LEN; + st->bp += HDA_DMA_ACCESS_LEN; + lpib += HDA_DMA_ACCESS_LEN; + left -= HDA_DMA_ACCESS_LEN; + + if (st->bp == bdle_desc->len) { + st->bp = 0; + if (bdle_desc->ioc) + irq = 1; + st->be++; + if (st->be == st->bdl_cnt) { + st->be = 0; + lpib = 0; + } + bdle_desc = &bdl[st->be]; + } + } + + hda_set_reg_by_offset(sc, off + HDAC_SDLPIB, lpib); + + if (irq) { + hda_set_field_by_offset(sc, off + HDAC_SDSTS, HDAC_SDSTS_BCIS, HDAC_SDSTS_BCIS); + hda_update_intr(sc); + } + + return 0; +} + /* * PCI HDA function definitions */ Modified: soc2016/iateaca/bhyve-hda-head/usr.sbin/bhyve/pci_hda.h ============================================================================== --- soc2016/iateaca/bhyve-hda-head/usr.sbin/bhyve/pci_hda.h Sun Jun 26 16:38:42 2016 (r305561) +++ soc2016/iateaca/bhyve-hda-head/usr.sbin/bhyve/pci_hda.h Sun Jun 26 17:01:21 2016 (r305562) @@ -49,6 +49,7 @@ struct hda_ops { int (*signal)(struct hda_codec_inst *hci); int (*response)(struct hda_codec_inst *hci, uint32_t response, uint8_t unsol); + int (*transfer)(struct hda_codec_inst *hci, uint8_t stream, uint8_t dir, void *buf, size_t count); }; #define HDA_EMUL_SET(x) DATA_SET(hda_codec_class_set, x); From owner-svn-soc-all@freebsd.org Mon Jun 27 09:33:06 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 6221EB84ECA for ; Mon, 27 Jun 2016 09:33:06 +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 3D8962072 for ; Mon, 27 Jun 2016 09:33:06 +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 u5R9X6IP025515 for ; Mon, 27 Jun 2016 09:33:06 GMT (envelope-from vincenzo@FreeBSD.org) Received: (from www@localhost) by socsvn.freebsd.org (8.15.2/8.15.2/Submit) id u5R9X5Pg025499 for svn-soc-all@FreeBSD.org; Mon, 27 Jun 2016 09:33:05 GMT (envelope-from vincenzo@FreeBSD.org) Date: Mon, 27 Jun 2016 09:33:05 GMT Message-Id: <201606270933.u5R9X5Pg025499@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: r305573 - 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, 27 Jun 2016 09:33:06 -0000 Author: vincenzo Date: Mon Jun 27 09:33:05 2016 New Revision: 305573 URL: http://svnweb.FreeBSD.org/socsvn/?view=rev&rev=305573 Log: freebsd: ptnet_transmit: start using drbr 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 Jun 27 06:41:11 2016 (r305572) +++ soc2016/vincenzo/head/sys/dev/netmap/if_ptnet.c Mon Jun 27 09:33:05 2016 (r305573) @@ -802,13 +802,34 @@ 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 (unlikely(err)) { + device_printf(sc->dev, "%s: drbr_enqueue() failed %d\n", + __func__, err); + return err; + } + } + + if (!PTNET_Q_TRYLOCK(pq)) { + /* We failed to acquire the lock, schedule the taskqueue. */ + RD(1, "Deferring TX work"); + taskqueue_enqueue(pq->taskq, &pq->task); + + return 0; + } + ptring = pq->ptring; kring = na->tx_rings + pq->kring_id; ring = kring->ring; lim = kring->nkr_num_slots - 1; - PTNET_Q_LOCK(pq); - /* Update hwcur and hwtail (completed TX slots) as known by the host, * by reading from CSB. */ ptnet_sync_tail(ptring, kring); @@ -818,14 +839,21 @@ nmbuf = NMB(na, slot); nmbuf_bytes = 0; + m = drbr_peek(ifp, pq->bufring); + if (!m) { + device_printf(sc->dev, "%s: Empty drbr\n", __func__); + goto out; + } + if (head == ring->tail) { device_printf(sc->dev, "%s: Drop, no free slots\n", __func__); - m_freem(m); + drbr_putback(ifp, pq->bufring, m); ptring->guest_need_kick = 1; - - return 0; + goto out; } + drbr_advance(ifp, pq->bufring); + for (mf = m; mf; mf = mf->m_next) { uint8_t *mdata = mf->m_data; int mlen = mf->m_len; @@ -879,7 +907,7 @@ if (0) { ptring->guest_need_kick = 1; } - +out: PTNET_Q_UNLOCK(pq); return 0; From owner-svn-soc-all@freebsd.org Mon Jun 27 09:33:18 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 EC6A5B84EED for ; Mon, 27 Jun 2016 09:33:18 +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 E00E8213D for ; Mon, 27 Jun 2016 09:33:18 +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 u5R9XITV025907 for ; Mon, 27 Jun 2016 09:33:18 GMT (envelope-from vincenzo@FreeBSD.org) Received: (from www@localhost) by socsvn.freebsd.org (8.15.2/8.15.2/Submit) id u5R9XILq025874 for svn-soc-all@FreeBSD.org; Mon, 27 Jun 2016 09:33:18 GMT (envelope-from vincenzo@FreeBSD.org) Date: Mon, 27 Jun 2016 09:33:18 GMT Message-Id: <201606270933.u5R9XILq025874@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: r305574 - 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, 27 Jun 2016 09:33:19 -0000 Author: vincenzo Date: Mon Jun 27 09:33:17 2016 New Revision: 305574 URL: http://svnweb.FreeBSD.org/socsvn/?view=rev&rev=305574 Log: freebsd: ptnet_transmit: handle multiple mbufs 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 Jun 27 09:33:05 2016 (r305573) +++ soc2016/vincenzo/head/sys/dev/netmap/if_ptnet.c Mon Jun 27 09:33:17 2016 (r305574) @@ -793,6 +793,7 @@ struct netmap_ring *ring; struct netmap_slot *slot; struct ptnet_queue *pq; + unsigned int prev_head; unsigned int head; unsigned int lim; struct mbuf *mf; @@ -839,75 +840,88 @@ nmbuf = NMB(na, slot); nmbuf_bytes = 0; - m = drbr_peek(ifp, pq->bufring); - if (!m) { - device_printf(sc->dev, "%s: Empty drbr\n", __func__); - goto out; - } + while (head != ring->tail) { + m = drbr_peek(ifp, pq->bufring); + if (!m) { + break; + } - if (head == ring->tail) { - device_printf(sc->dev, "%s: Drop, no free slots\n", __func__); - drbr_putback(ifp, pq->bufring, m); - ptring->guest_need_kick = 1; - goto out; - } + for (prev_head = head, mf = m; mf; mf = mf->m_next) { + uint8_t *mdata = mf->m_data; + int mlen = mf->m_len; - drbr_advance(ifp, pq->bufring); + for (;;) { + int copy = NETMAP_BUF_SIZE(na) - nmbuf_bytes; - for (mf = m; mf; mf = mf->m_next) { - uint8_t *mdata = mf->m_data; - int mlen = mf->m_len; + if (mlen < copy) { + copy = mlen; + } + memcpy(nmbuf, mdata, copy); - for (;;) { - int copy = NETMAP_BUF_SIZE(na) - nmbuf_bytes; + mdata += copy; + mlen -= copy; + nmbuf += copy; + nmbuf_bytes += copy; - if (mlen < copy) { - copy = mlen; - } - memcpy(nmbuf, mdata, copy); + if (!mlen) { + break; + } - mdata += copy; - mlen -= copy; - nmbuf += copy; - nmbuf_bytes += copy; + slot->len = nmbuf_bytes; + slot->flags = NS_MOREFRAG; - if (!mlen) { - break; + 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. */ + device_printf(sc->dev, "%s: Drop, " + " no free slots\n", + __func__); + head = prev_head; + drbr_putback(ifp, pq->bufring, m); + goto escape; + } + slot = ring->slot + head; + nmbuf = NMB(na, slot); + nmbuf_bytes = 0; } - - slot->len = nmbuf_bytes; - slot->flags = NS_MOREFRAG; - head = nm_next(head, lim); - slot = ring->slot + head; - nmbuf = NMB(na, slot); - nmbuf_bytes = 0; } - } - m_freem(m); + /* Complete last slot and update head. */ + slot->len = nmbuf_bytes; + slot->flags = 0; + head = nm_next(head, lim); - /* Complete last slot and update head. */ - slot->len = nmbuf_bytes; - slot->flags = 0; - ring->head = ring->cur = nm_next(head, lim); + /* Consume the packet just processed. */ + drbr_advance(ifp, pq->bufring); + m_freem(m); + } +escape: + if (head != ring->head) { + /* Some packets have been pushed to the netmap ring. We have + * to tell the host to process the new packets, updating cur + * and head in the CSB. */ + ring->head = ring->cur = head; - /* nm_txsync_prologue */ - kring->rcur = kring->rhead = ring->head; + /* nm_txsync_prologue */ + kring->rcur = kring->rhead = ring->head; - /* Tell the host to process the new packets, updating cur and - * head in the CSB. */ - ptnetmap_guest_write_kring_csb(ptring, kring->rcur, kring->rhead); + ptnetmap_guest_write_kring_csb(ptring, kring->rcur, kring->rhead); - /* Kick the host if needed. */ - if (NM_ACCESS_ONCE(ptring->host_need_kick)) { - ptring->sync_flags = NAF_FORCE_RECLAIM; - bus_write_4(sc->iomem, pq->kick, 0); + /* Kick the host if needed. */ + if (NM_ACCESS_ONCE(ptring->host_need_kick)) { + ptring->sync_flags = NAF_FORCE_RECLAIM; + bus_write_4(sc->iomem, pq->kick, 0); + } } - if (0) { + if (head == ring->tail) { + /* Reactivate the interrupts so that we can be notified + * when some netmap slots are made available by the host. */ ptring->guest_need_kick = 1; } -out: + PTNET_Q_UNLOCK(pq); return 0; From owner-svn-soc-all@freebsd.org Mon Jun 27 09:33: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 6C690B84F0E for ; Mon, 27 Jun 2016 09:33: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 60151215C for ; Mon, 27 Jun 2016 09:33: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 u5R9Xtim027112 for ; Mon, 27 Jun 2016 09:33:55 GMT (envelope-from vincenzo@FreeBSD.org) Received: (from www@localhost) by socsvn.freebsd.org (8.15.2/8.15.2/Submit) id u5R9XsJo027106 for svn-soc-all@FreeBSD.org; Mon, 27 Jun 2016 09:33:54 GMT (envelope-from vincenzo@FreeBSD.org) Date: Mon, 27 Jun 2016 09:33:54 GMT Message-Id: <201606270933.u5R9XsJo027106@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: r305575 - 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, 27 Jun 2016 09:33:55 -0000 Author: vincenzo Date: Mon Jun 27 09:33:54 2016 New Revision: 305575 URL: http://svnweb.FreeBSD.org/socsvn/?view=rev&rev=305575 Log: freebsd: ptnet_transmit: limit TX batching 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 Jun 27 09:33:17 2016 (r305574) +++ soc2016/vincenzo/head/sys/dev/netmap/if_ptnet.c Mon Jun 27 09:33:54 2016 (r305575) @@ -218,6 +218,9 @@ extern int netmap_initialized; #define PTNET_BUF_RING_SIZE 4096 +#define PTNET_RX_BUDGET 512 +#define PTNET_TX_BATCH 64 + static int ptnet_attach(device_t dev) @@ -783,11 +786,36 @@ ring->tail = kring->rtail = kring->nr_hwtail; } +static void +ptnet_ring_update(struct ptnet_queue *pq, struct netmap_kring *kring, + unsigned int head) +{ + struct netmap_ring *ring = kring->ring; + struct ptnet_ring *ptring = pq->ptring; + + /* Some packets have been pushed to the netmap ring. We have + * to tell the host to process the new packets, updating cur + * and head in the CSB. */ + ring->head = ring->cur = head; + + /* nm_txsync_prologue */ + kring->rcur = kring->rhead = ring->head; + + ptnetmap_guest_write_kring_csb(ptring, kring->rcur, kring->rhead); + + /* Kick the host if needed. */ + if (NM_ACCESS_ONCE(ptring->host_need_kick)) { + ptring->sync_flags = NAF_FORCE_RECLAIM; + bus_write_4(pq->sc->iomem, pq->kick, 0); + } +} + static int ptnet_transmit(struct ifnet *ifp, struct mbuf *m) { struct ptnet_softc *sc = ifp->if_softc; struct netmap_adapter *na = &sc->ptna_dr.hwup.up; + unsigned int batch_count = 0; struct ptnet_ring *ptring; struct netmap_kring *kring; struct netmap_ring *ring; @@ -896,25 +924,16 @@ /* Consume the packet just processed. */ drbr_advance(ifp, pq->bufring); m_freem(m); - } -escape: - if (head != ring->head) { - /* Some packets have been pushed to the netmap ring. We have - * to tell the host to process the new packets, updating cur - * and head in the CSB. */ - ring->head = ring->cur = head; - - /* nm_txsync_prologue */ - kring->rcur = kring->rhead = ring->head; - ptnetmap_guest_write_kring_csb(ptring, kring->rcur, kring->rhead); - - /* Kick the host if needed. */ - if (NM_ACCESS_ONCE(ptring->host_need_kick)) { - ptring->sync_flags = NAF_FORCE_RECLAIM; - bus_write_4(sc->iomem, pq->kick, 0); + if (++batch_count == PTNET_TX_BATCH) { + batch_count = 0; + ptnet_ring_update(pq, kring, head); } } +escape: + if (batch_count) { + ptnet_ring_update(pq, kring, head); + } if (head == ring->tail) { /* Reactivate the interrupts so that we can be notified @@ -1254,8 +1273,6 @@ ptnet_rx_eof(pq); } -#define RX_BUDGET 512 - static int ptnet_rx_eof(struct ptnet_queue *pq) { @@ -1265,7 +1282,7 @@ struct netmap_kring *kring = na->rx_rings + pq->kring_id; struct netmap_ring *ring = kring->ring; unsigned int const lim = kring->nkr_num_slots - 1; - unsigned int budget = RX_BUDGET; + unsigned int budget = PTNET_RX_BUDGET; unsigned int head = ring->head; struct ifnet *ifp = sc->ifp; unsigned int more; @@ -1323,7 +1340,7 @@ * before issuing the last interrupt. */ ptring->guest_need_kick = 1; - if (budget != RX_BUDGET) { + if (budget != PTNET_RX_BUDGET) { /* Some packets have been pushed to the network stack. * We need to update the CSB to tell the host about the new * ring->cur and ring->head (RX buffer refill). */ From owner-svn-soc-all@freebsd.org Mon Jun 27 09:34: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 6135AB84F29 for ; Mon, 27 Jun 2016 09:34: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 54D542171 for ; Mon, 27 Jun 2016 09:34: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 u5R9Y483027354 for ; Mon, 27 Jun 2016 09:34:04 GMT (envelope-from vincenzo@FreeBSD.org) Received: (from www@localhost) by socsvn.freebsd.org (8.15.2/8.15.2/Submit) id u5R9Y39C027352 for svn-soc-all@FreeBSD.org; Mon, 27 Jun 2016 09:34:03 GMT (envelope-from vincenzo@FreeBSD.org) Date: Mon, 27 Jun 2016 09:34:03 GMT Message-Id: <201606270934.u5R9Y39C027352@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: r305576 - 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, 27 Jun 2016 09:34:04 -0000 Author: vincenzo Date: Mon Jun 27 09:34:03 2016 New Revision: 305576 URL: http://svnweb.FreeBSD.org/socsvn/?view=rev&rev=305576 Log: freebsd: ptnet_transmit: add doublecheck with rescheduling 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 Jun 27 09:33:54 2016 (r305575) +++ soc2016/vincenzo/head/sys/dev/netmap/if_ptnet.c Mon Jun 27 09:34:03 2016 (r305576) @@ -937,8 +937,20 @@ if (head == ring->tail) { /* Reactivate the interrupts so that we can be notified - * when some netmap slots are made available by the host. */ + * 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, "Doublecheck finds more slots"); + /* 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); From owner-svn-soc-all@freebsd.org Mon Jun 27 09:34: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 6F244B84F3E for ; Mon, 27 Jun 2016 09:34: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 62C84218C for ; Mon, 27 Jun 2016 09:34: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 u5R9YDfU027672 for ; Mon, 27 Jun 2016 09:34:13 GMT (envelope-from vincenzo@FreeBSD.org) Received: (from www@localhost) by socsvn.freebsd.org (8.15.2/8.15.2/Submit) id u5R9YCTn027612 for svn-soc-all@FreeBSD.org; Mon, 27 Jun 2016 09:34:12 GMT (envelope-from vincenzo@FreeBSD.org) Date: Mon, 27 Jun 2016 09:34:12 GMT Message-Id: <201606270934.u5R9YCTn027612@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: r305577 - 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, 27 Jun 2016 09:34:13 -0000 Author: vincenzo Date: Mon Jun 27 09:34:12 2016 New Revision: 305577 URL: http://svnweb.FreeBSD.org/socsvn/?view=rev&rev=305577 Log: freebsd: ptnet_detach: drain taskqueue before detaching the interface 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 Jun 27 09:34:03 2016 (r305576) +++ soc2016/vincenzo/head/sys/dev/netmap/if_ptnet.c Mon Jun 27 09:34:12 2016 (r305577) @@ -417,6 +417,18 @@ ptnet_detach(device_t dev) { struct ptnet_softc *sc = device_get_softc(dev); + int i; + + if (sc->queues) { + /* Drain taskqueues before calling if_detach. */ + for (i = 0; i < sc->num_rings; i++) { + struct ptnet_queue *pq = sc->queues + i; + + if (pq->taskq) { + taskqueue_drain(pq->taskq, &pq->task); + } + } + } if (sc->ifp) { ether_ifdetach(sc->ifp); @@ -441,8 +453,6 @@ } if (sc->queues) { - int i; - for (i = 0; i < sc->num_rings; i++) { struct ptnet_queue *pq = sc->queues + i; @@ -943,7 +953,7 @@ /* Double check. */ ptnet_sync_tail(ptring, kring); if (unlikely(head != ring->tail)) { - RD(1, "Doublecheck finds more slots"); + RD(1, "Found more slots by doublecheck"); /* More slots were freed before reactivating * the interrupts. */ ptring->guest_need_kick = 0; From owner-svn-soc-all@freebsd.org Mon Jun 27 09:34: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 C6463B84F59 for ; Mon, 27 Jun 2016 09:34: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 B9EDB21A0 for ; Mon, 27 Jun 2016 09:34: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 u5R9YN7E027928 for ; Mon, 27 Jun 2016 09:34:23 GMT (envelope-from vincenzo@FreeBSD.org) Received: (from www@localhost) by socsvn.freebsd.org (8.15.2/8.15.2/Submit) id u5R9YNci027905 for svn-soc-all@FreeBSD.org; Mon, 27 Jun 2016 09:34:23 GMT (envelope-from vincenzo@FreeBSD.org) Date: Mon, 27 Jun 2016 09:34:23 GMT Message-Id: <201606270934.u5R9YNci027905@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: r305578 - 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, 27 Jun 2016 09:34:23 -0000 Author: vincenzo Date: Mon Jun 27 09:34:22 2016 New Revision: 305578 URL: http://svnweb.FreeBSD.org/socsvn/?view=rev&rev=305578 Log: freebsd: ptnet_qflush: flush ring buffers 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 Jun 27 09:34:12 2016 (r305577) +++ soc2016/vincenzo/head/sys/dev/netmap/if_ptnet.c Mon Jun 27 09:34:22 2016 (r305578) @@ -971,6 +971,24 @@ static void ptnet_qflush(struct ifnet *ifp) { + struct ptnet_softc *sc = ifp->if_softc; + int i; + + /* Flush all ring buffers and do the interface flush. */ + for (i = 0; i < sc->num_rings; i++) { + struct ptnet_queue *pq = sc->queues + i; + struct mbuf *m; + + PTNET_Q_LOCK(pq); + if (pq->bufring) { + while ((m = buf_ring_dequeue_sc(pq->bufring))) { + m_freem(m); + } + } + PTNET_Q_UNLOCK(pq); + } + + if_qflush(ifp); } static int From owner-svn-soc-all@freebsd.org Mon Jun 27 09:34: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 D09F4B84F71 for ; Mon, 27 Jun 2016 09:34: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 C456D21BE for ; Mon, 27 Jun 2016 09:34: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 u5R9Yetv028409 for ; Mon, 27 Jun 2016 09:34:40 GMT (envelope-from vincenzo@FreeBSD.org) Received: (from www@localhost) by socsvn.freebsd.org (8.15.2/8.15.2/Submit) id u5R9YeBR028394 for svn-soc-all@FreeBSD.org; Mon, 27 Jun 2016 09:34:40 GMT (envelope-from vincenzo@FreeBSD.org) Date: Mon, 27 Jun 2016 09:34:40 GMT Message-Id: <201606270934.u5R9YeBR028394@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: r305579 - 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, 27 Jun 2016 09:34:40 -0000 Author: vincenzo Date: Mon Jun 27 09:34:39 2016 New Revision: 305579 URL: http://svnweb.FreeBSD.org/socsvn/?view=rev&rev=305579 Log: freebsd: ptnet_media_status: ptnet media is always active 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 Jun 27 09:34:22 2016 (r305578) +++ soc2016/vincenzo/head/sys/dev/netmap/if_ptnet.c Mon Jun 27 09:34:39 2016 (r305579) @@ -974,7 +974,7 @@ struct ptnet_softc *sc = ifp->if_softc; int i; - /* Flush all ring buffers and do the interface flush. */ + /* Flush all the bufrings and do the interface flush. */ for (i = 0; i < sc->num_rings; i++) { struct ptnet_queue *pq = sc->queues + i; struct mbuf *m; @@ -1008,15 +1008,10 @@ static void ptnet_media_status(struct ifnet *ifp, struct ifmediareq *ifmr) { - ifmr->ifm_status = IFM_AVALID; - ifmr->ifm_active = IFM_ETHER; - - if (1) { - ifmr->ifm_status |= IFM_ACTIVE; - ifmr->ifm_active |= IFM_10G_T | IFM_FDX; - } else { - ifmr->ifm_active |= IFM_NONE; - } + /* We are always active, as the backend netmap port is + * always open in netmap mode. */ + ifmr->ifm_status = IFM_AVALID | IFM_ACTIVE; + ifmr->ifm_active = IFM_ETHER | IFM_10G_T | IFM_FDX; } static uint32_t From owner-svn-soc-all@freebsd.org Mon Jun 27 09:34:50 2016 Return-Path: Delivered-To: svn-soc-all@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id 46002B84F8A for ; Mon, 27 Jun 2016 09:34:50 +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 39B9C21D9 for ; Mon, 27 Jun 2016 09:34:50 +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 u5R9YoIq028720 for ; Mon, 27 Jun 2016 09:34:50 GMT (envelope-from vincenzo@FreeBSD.org) Received: (from www@localhost) by socsvn.freebsd.org (8.15.2/8.15.2/Submit) id u5R9Ynfj028703 for svn-soc-all@FreeBSD.org; Mon, 27 Jun 2016 09:34:49 GMT (envelope-from vincenzo@FreeBSD.org) Date: Mon, 27 Jun 2016 09:34:49 GMT Message-Id: <201606270934.u5R9Ynfj028703@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: r305580 - 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, 27 Jun 2016 09:34:50 -0000 Author: vincenzo Date: Mon Jun 27 09:34:49 2016 New Revision: 305580 URL: http://svnweb.FreeBSD.org/socsvn/?view=rev&rev=305580 Log: freebsd: ptnet_transmit: check for IFF_DRV_RUNNING bit 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 Jun 27 09:34:39 2016 (r305579) +++ soc2016/vincenzo/head/sys/dev/netmap/if_ptnet.c Mon Jun 27 09:34:49 2016 (r305580) @@ -856,6 +856,11 @@ } } + if (unlikely(!(ifp->if_drv_flags & IFF_DRV_RUNNING))) { + RD(1, "Interface is down"); + return ENETDOWN; + } + if (!PTNET_Q_TRYLOCK(pq)) { /* We failed to acquire the lock, schedule the taskqueue. */ RD(1, "Deferring TX work"); @@ -998,10 +1003,10 @@ struct ifmedia *ifm = &sc->media; if (IFM_TYPE(ifm->ifm_media) != IFM_ETHER) { - return (EINVAL); + return EINVAL; } - return (0); + return 0; } From owner-svn-soc-all@freebsd.org Mon Jun 27 09:34: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 4A54CB84FA3 for ; Mon, 27 Jun 2016 09:34: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 3E06C21F1 for ; Mon, 27 Jun 2016 09:34: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 u5R9YxFc028955 for ; Mon, 27 Jun 2016 09:34:59 GMT (envelope-from vincenzo@FreeBSD.org) Received: (from www@localhost) by socsvn.freebsd.org (8.15.2/8.15.2/Submit) id u5R9YwFb028932 for svn-soc-all@FreeBSD.org; Mon, 27 Jun 2016 09:34:58 GMT (envelope-from vincenzo@FreeBSD.org) Date: Mon, 27 Jun 2016 09:34:58 GMT Message-Id: <201606270934.u5R9YwFb028932@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: r305581 - 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, 27 Jun 2016 09:34:59 -0000 Author: vincenzo Date: Mon Jun 27 09:34:58 2016 New Revision: 305581 URL: http://svnweb.FreeBSD.org/socsvn/?view=rev&rev=305581 Log: freebsd: ptnet_tx_intr: schedule taskqueue to process transmissions 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 Jun 27 09:34:49 2016 (r305580) +++ soc2016/vincenzo/head/sys/dev/netmap/if_ptnet.c Mon Jun 27 09:34:58 2016 (r305581) @@ -1276,7 +1276,6 @@ { struct ptnet_queue *pq = opaque; struct ptnet_softc *sc = pq->sc; - struct netmap_adapter *na_dr = &sc->ptna_dr.hwup.up; DBG(device_printf(sc->dev, "Tx interrupt #%d\n", pq->kring_id)); @@ -1288,9 +1287,8 @@ return; } - PTNET_Q_LOCK(pq); - ptnet_sync_tail(pq->ptring, na_dr->tx_rings + pq->kring_id); - PTNET_Q_UNLOCK(pq); + /* Schedule the tasqueue to flush process transmissions requests. */ + taskqueue_enqueue(pq->taskq, &pq->task); } static void From owner-svn-soc-all@freebsd.org Mon Jun 27 09:35:08 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 213B6B84FC7 for ; Mon, 27 Jun 2016 09:35:08 +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 14D612205 for ; Mon, 27 Jun 2016 09:35:08 +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 u5R9Z7C3029221 for ; Mon, 27 Jun 2016 09:35:07 GMT (envelope-from vincenzo@FreeBSD.org) Received: (from www@localhost) by socsvn.freebsd.org (8.15.2/8.15.2/Submit) id u5R9Z7th029213 for svn-soc-all@FreeBSD.org; Mon, 27 Jun 2016 09:35:07 GMT (envelope-from vincenzo@FreeBSD.org) Date: Mon, 27 Jun 2016 09:35:07 GMT Message-Id: <201606270935.u5R9Z7th029213@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: r305582 - 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, 27 Jun 2016 09:35:08 -0000 Author: vincenzo Date: Mon Jun 27 09:35:06 2016 New Revision: 305582 URL: http://svnweb.FreeBSD.org/socsvn/?view=rev&rev=305582 Log: freebsd: ptnet_tx_intr: add comment 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 Jun 27 09:34:58 2016 (r305581) +++ soc2016/vincenzo/head/sys/dev/netmap/if_ptnet.c Mon Jun 27 09:35:06 2016 (r305582) @@ -1287,7 +1287,10 @@ return; } - /* Schedule the tasqueue to flush process transmissions requests. */ + /* Schedule the tasqueue to flush process transmissions requests. + * However, vtnet, if_em and if_igb just call ptnet_transmit() here, + * at least when using MSI-X interrupts. The if_em driver, instead + * schedule taskqueue when using legacy interrupts. */ taskqueue_enqueue(pq->taskq, &pq->task); } From owner-svn-soc-all@freebsd.org Mon Jun 27 09:35:17 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 F21C3B84FFC for ; Mon, 27 Jun 2016 09:35:17 +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 CD6722218 for ; Mon, 27 Jun 2016 09:35:17 +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 u5R9ZHbR029514 for ; Mon, 27 Jun 2016 09:35:17 GMT (envelope-from vincenzo@FreeBSD.org) Received: (from www@localhost) by socsvn.freebsd.org (8.15.2/8.15.2/Submit) id u5R9ZHDh029512 for svn-soc-all@FreeBSD.org; Mon, 27 Jun 2016 09:35:17 GMT (envelope-from vincenzo@FreeBSD.org) Date: Mon, 27 Jun 2016 09:35:17 GMT Message-Id: <201606270935.u5R9ZHDh029512@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: r305583 - 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, 27 Jun 2016 09:35:18 -0000 Author: vincenzo Date: Mon Jun 27 09:35:16 2016 New Revision: 305583 URL: http://svnweb.FreeBSD.org/socsvn/?view=rev&rev=305583 Log: freebsd: ptnet_rx_eof: add double-check with rescheduling 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 Jun 27 09:35:06 2016 (r305582) +++ soc2016/vincenzo/head/sys/dev/netmap/if_ptnet.c Mon Jun 27 09:35:16 2016 (r305583) @@ -955,7 +955,7 @@ * when some free slots are made available by the host. */ ptring->guest_need_kick = 1; - /* Double check. */ + /* Double-check. */ ptnet_sync_tail(ptring, kring); if (unlikely(head != ring->tail)) { RD(1, "Found more slots by doublecheck"); @@ -1326,7 +1326,6 @@ unsigned int budget = PTNET_RX_BUDGET; unsigned int head = ring->head; struct ifnet *ifp = sc->ifp; - unsigned int more; PTNET_Q_LOCK(pq); @@ -1377,10 +1376,6 @@ budget--; } - /* Reactivate interrupts as they were disabled by the host thread right - * before issuing the last interrupt. */ - ptring->guest_need_kick = 1; - if (budget != PTNET_RX_BUDGET) { /* Some packets have been pushed to the network stack. * We need to update the CSB to tell the host about the new @@ -1401,17 +1396,30 @@ } } - more = (head != ring->tail); + if (head == ring->tail) { + /* No more slots to process. Reactivate interrupts as they + * were disabled by the host thread right before issuing the + * last interrupt. */ + ptring->guest_need_kick = 1; - PTNET_Q_UNLOCK(pq); + /* Double-check. */ + ptnet_sync_tail(ptring, kring); + if (unlikely(head != ring->tail)) { + ptring->guest_need_kick = 0; + } + } - if (more) { + if (head != ring->tail) { + /* If we ran out of budget or the double-check found new + * slots to process, schedule the taskqueue. */ device_printf(sc->dev, "%s: resched: budget %u h %u " "t %u\n", __func__, budget, ring->head, ring->tail); taskqueue_enqueue(pq->taskq, &pq->task); } + PTNET_Q_UNLOCK(pq); + return 0; } From owner-svn-soc-all@freebsd.org Mon Jun 27 09:35: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 BBA32B81020 for ; Mon, 27 Jun 2016 09:35: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 AF0EB2234 for ; Mon, 27 Jun 2016 09:35: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 u5R9ZbOh029981 for ; Mon, 27 Jun 2016 09:35:37 GMT (envelope-from vincenzo@FreeBSD.org) Received: (from www@localhost) by socsvn.freebsd.org (8.15.2/8.15.2/Submit) id u5R9ZbeE029972 for svn-soc-all@FreeBSD.org; Mon, 27 Jun 2016 09:35:37 GMT (envelope-from vincenzo@FreeBSD.org) Date: Mon, 27 Jun 2016 09:35:37 GMT Message-Id: <201606270935.u5R9ZbeE029972@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: r305584 - 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, 27 Jun 2016 09:35:37 -0000 Author: vincenzo Date: Mon Jun 27 09:35:36 2016 New Revision: 305584 URL: http://svnweb.FreeBSD.org/socsvn/?view=rev&rev=305584 Log: freebsd: ptnet: move transmit functionality at the bottom 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 Jun 27 09:35:16 2016 (r305583) +++ soc2016/vincenzo/head/sys/dev/netmap/if_ptnet.c Mon Jun 27 09:35:36 2016 (r305584) @@ -784,195 +784,6 @@ return 0; } -static inline void -ptnet_sync_tail(struct ptnet_ring *ptring, struct netmap_kring *kring) -{ - struct netmap_ring *ring = kring->ring; - - /* Update hwcur and hwtail as known by the host. */ - ptnetmap_guest_read_kring_csb(ptring, kring); - - /* nm_sync_finalize */ - ring->tail = kring->rtail = kring->nr_hwtail; -} - -static void -ptnet_ring_update(struct ptnet_queue *pq, struct netmap_kring *kring, - unsigned int head) -{ - struct netmap_ring *ring = kring->ring; - struct ptnet_ring *ptring = pq->ptring; - - /* Some packets have been pushed to the netmap ring. We have - * to tell the host to process the new packets, updating cur - * and head in the CSB. */ - ring->head = ring->cur = head; - - /* nm_txsync_prologue */ - kring->rcur = kring->rhead = ring->head; - - ptnetmap_guest_write_kring_csb(ptring, kring->rcur, kring->rhead); - - /* Kick the host if needed. */ - if (NM_ACCESS_ONCE(ptring->host_need_kick)) { - ptring->sync_flags = NAF_FORCE_RECLAIM; - bus_write_4(pq->sc->iomem, pq->kick, 0); - } -} - -static int -ptnet_transmit(struct ifnet *ifp, struct mbuf *m) -{ - struct ptnet_softc *sc = ifp->if_softc; - struct netmap_adapter *na = &sc->ptna_dr.hwup.up; - 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 prev_head; - unsigned int head; - unsigned int lim; - 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 (unlikely(err)) { - device_printf(sc->dev, "%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; - } - - if (!PTNET_Q_TRYLOCK(pq)) { - /* We failed to acquire the lock, schedule the taskqueue. */ - RD(1, "Deferring TX work"); - taskqueue_enqueue(pq->taskq, &pq->task); - - return 0; - } - - ptring = pq->ptring; - kring = na->tx_rings + pq->kring_id; - ring = kring->ring; - lim = kring->nkr_num_slots - 1; - - /* Update hwcur and hwtail (completed TX slots) as known by the host, - * by reading from CSB. */ - ptnet_sync_tail(ptring, kring); - - head = ring->head; - slot = ring->slot + head; - nmbuf = NMB(na, slot); - nmbuf_bytes = 0; - - while (head != ring->tail) { - m = drbr_peek(ifp, pq->bufring); - if (!m) { - break; - } - - for (prev_head = head, mf = m; mf; mf = mf->m_next) { - uint8_t *mdata = mf->m_data; - int mlen = mf->m_len; - - for (;;) { - int copy = NETMAP_BUF_SIZE(na) - nmbuf_bytes; - - if (mlen < copy) { - copy = mlen; - } - memcpy(nmbuf, mdata, copy); - - mdata += copy; - mlen -= copy; - nmbuf += copy; - nmbuf_bytes += copy; - - if (!mlen) { - break; - } - - slot->len = nmbuf_bytes; - 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. */ - device_printf(sc->dev, "%s: Drop, " - " no free slots\n", - __func__); - head = prev_head; - drbr_putback(ifp, pq->bufring, m); - goto escape; - } - slot = ring->slot + head; - nmbuf = NMB(na, slot); - nmbuf_bytes = 0; - } - } - - /* Complete last slot and update head. */ - slot->len = nmbuf_bytes; - slot->flags = 0; - head = nm_next(head, lim); - - /* Consume the packet just processed. */ - drbr_advance(ifp, pq->bufring); - m_freem(m); - - if (++batch_count == PTNET_TX_BATCH) { - batch_count = 0; - ptnet_ring_update(pq, kring, head); - } - } -escape: - if (batch_count) { - 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; -} - static void ptnet_qflush(struct ifnet *ifp) { @@ -1314,6 +1125,195 @@ ptnet_rx_eof(pq); } +static inline void +ptnet_sync_tail(struct ptnet_ring *ptring, struct netmap_kring *kring) +{ + struct netmap_ring *ring = kring->ring; + + /* Update hwcur and hwtail as known by the host. */ + ptnetmap_guest_read_kring_csb(ptring, kring); + + /* nm_sync_finalize */ + ring->tail = kring->rtail = kring->nr_hwtail; +} + +static void +ptnet_ring_update(struct ptnet_queue *pq, struct netmap_kring *kring, + unsigned int head) +{ + struct netmap_ring *ring = kring->ring; + struct ptnet_ring *ptring = pq->ptring; + + /* Some packets have been pushed to the netmap ring. We have + * to tell the host to process the new packets, updating cur + * and head in the CSB. */ + ring->head = ring->cur = head; + + /* nm_txsync_prologue */ + kring->rcur = kring->rhead = ring->head; + + ptnetmap_guest_write_kring_csb(ptring, kring->rcur, kring->rhead); + + /* Kick the host if needed. */ + if (NM_ACCESS_ONCE(ptring->host_need_kick)) { + ptring->sync_flags = NAF_FORCE_RECLAIM; + bus_write_4(pq->sc->iomem, pq->kick, 0); + } +} + +static int +ptnet_transmit(struct ifnet *ifp, struct mbuf *m) +{ + struct ptnet_softc *sc = ifp->if_softc; + struct netmap_adapter *na = &sc->ptna_dr.hwup.up; + 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 prev_head; + unsigned int head; + unsigned int lim; + 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 (unlikely(err)) { + device_printf(sc->dev, "%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; + } + + if (!PTNET_Q_TRYLOCK(pq)) { + /* We failed to acquire the lock, schedule the taskqueue. */ + RD(1, "Deferring TX work"); + taskqueue_enqueue(pq->taskq, &pq->task); + + return 0; + } + + ptring = pq->ptring; + kring = na->tx_rings + pq->kring_id; + ring = kring->ring; + lim = kring->nkr_num_slots - 1; + + /* Update hwcur and hwtail (completed TX slots) as known by the host, + * by reading from CSB. */ + ptnet_sync_tail(ptring, kring); + + head = ring->head; + slot = ring->slot + head; + nmbuf = NMB(na, slot); + nmbuf_bytes = 0; + + while (head != ring->tail) { + m = drbr_peek(ifp, pq->bufring); + if (!m) { + break; + } + + for (prev_head = head, mf = m; mf; mf = mf->m_next) { + uint8_t *mdata = mf->m_data; + int mlen = mf->m_len; + + for (;;) { + int copy = NETMAP_BUF_SIZE(na) - nmbuf_bytes; + + if (mlen < copy) { + copy = mlen; + } + memcpy(nmbuf, mdata, copy); + + mdata += copy; + mlen -= copy; + nmbuf += copy; + nmbuf_bytes += copy; + + if (!mlen) { + break; + } + + slot->len = nmbuf_bytes; + 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. */ + device_printf(sc->dev, "%s: Drop, " + " no free slots\n", + __func__); + head = prev_head; + drbr_putback(ifp, pq->bufring, m); + goto escape; + } + slot = ring->slot + head; + nmbuf = NMB(na, slot); + nmbuf_bytes = 0; + } + } + + /* Complete last slot and update head. */ + slot->len = nmbuf_bytes; + slot->flags = 0; + head = nm_next(head, lim); + + /* Consume the packet just processed. */ + drbr_advance(ifp, pq->bufring); + m_freem(m); + + if (++batch_count == PTNET_TX_BATCH) { + batch_count = 0; + ptnet_ring_update(pq, kring, head); + } + } +escape: + if (batch_count) { + 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; +} + static int ptnet_rx_eof(struct ptnet_queue *pq) { From owner-svn-soc-all@freebsd.org Mon Jun 27 09:39: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 69434B810FB for ; Mon, 27 Jun 2016 09:39: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 5CEDB242F for ; Mon, 27 Jun 2016 09:39: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 u5R9dKYb035481 for ; Mon, 27 Jun 2016 09:39:20 GMT (envelope-from vincenzo@FreeBSD.org) Received: (from www@localhost) by socsvn.freebsd.org (8.15.2/8.15.2/Submit) id u5R9dJEO035478 for svn-soc-all@FreeBSD.org; Mon, 27 Jun 2016 09:39:19 GMT (envelope-from vincenzo@FreeBSD.org) Date: Mon, 27 Jun 2016 09:39:19 GMT Message-Id: <201606270939.u5R9dJEO035478@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: r305585 - 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, 27 Jun 2016 09:39:20 -0000 Author: vincenzo Date: Mon Jun 27 09:39:19 2016 New Revision: 305585 URL: http://svnweb.FreeBSD.org/socsvn/?view=rev&rev=305585 Log: freebsd: ptnet_rx_eof: use for construct to avoid goto 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 Jun 27 09:35:36 2016 (r305584) +++ soc2016/vincenzo/head/sys/dev/netmap/if_ptnet.c Mon Jun 27 09:39:19 2016 (r305585) @@ -1323,9 +1323,8 @@ struct netmap_kring *kring = na->rx_rings + pq->kring_id; struct netmap_ring *ring = kring->ring; unsigned int const lim = kring->nkr_num_slots - 1; - unsigned int budget = PTNET_RX_BUDGET; - unsigned int head = ring->head; struct ifnet *ifp = sc->ifp; + unsigned int budget, head; PTNET_Q_LOCK(pq); @@ -1335,7 +1334,9 @@ kring->nr_kflags &= ~NKR_PENDINTR; - while (head != ring->tail && budget) { + for (head = ring->head, budget = PTNET_RX_BUDGET; + head != ring->tail && budget; + head = nm_next(head, lim), budget--) { struct netmap_slot *slot = ring->slot + head; unsigned int nmbuf_len = slot->len; uint8_t *nmbuf = NMB(na, slot); @@ -1344,7 +1345,7 @@ if (unlikely(nmbuf_len > MCLBYTES)) { RD(1, "Dropping long frame: len %u > %u", nmbuf_len, MCLBYTES); - goto next; + continue; } DBG(device_printf(sc->dev, "%s: h %u t %u rcv frame len %u\n", @@ -1371,9 +1372,6 @@ PTNET_Q_UNLOCK(pq); (*ifp->if_input)(ifp, m); PTNET_Q_LOCK(pq); -next: - head = nm_next(head, lim); - budget--; } if (budget != PTNET_RX_BUDGET) { From owner-svn-soc-all@freebsd.org Mon Jun 27 09:42:14 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 E9BF3B813DC for ; Mon, 27 Jun 2016 09:42:14 +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 DD70A26C2 for ; Mon, 27 Jun 2016 09:42:14 +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 u5R9gEDR045260 for ; Mon, 27 Jun 2016 09:42:14 GMT (envelope-from vincenzo@FreeBSD.org) Received: (from www@localhost) by socsvn.freebsd.org (8.15.2/8.15.2/Submit) id u5R9gEkl044837 for svn-soc-all@FreeBSD.org; Mon, 27 Jun 2016 09:42:14 GMT (envelope-from vincenzo@FreeBSD.org) Date: Mon, 27 Jun 2016 09:42:14 GMT Message-Id: <201606270942.u5R9gEkl044837@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: r305586 - 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, 27 Jun 2016 09:42:15 -0000 Author: vincenzo Date: Mon Jun 27 09:42:13 2016 New Revision: 305586 URL: http://svnweb.FreeBSD.org/socsvn/?view=rev&rev=305586 Log: freebsd: ptnet taskqueues: use RD() macro rather device_printf 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 Jun 27 09:39:19 2016 (r305585) +++ soc2016/vincenzo/head/sys/dev/netmap/if_ptnet.c Mon Jun 27 09:42:13 2016 (r305586) @@ -1122,6 +1122,9 @@ return; } + /* Like vtnet, if_igb and if_em drivers when using MSI-X interrupts, + * receive-side processing is executed directly in the interrupt + * service routine. Alternatively, we may schedule the taskqueue. */ ptnet_rx_eof(pq); } @@ -1410,8 +1413,8 @@ if (head != ring->tail) { /* If we ran out of budget or the double-check found new * slots to process, schedule the taskqueue. */ - device_printf(sc->dev, "%s: resched: budget %u h %u " - "t %u\n", __func__, budget, ring->head, + RD(1, "%s: resched: budget %u h %u t %u\n", __func__, + budget, ring->head, ring->tail); taskqueue_enqueue(pq->taskq, &pq->task); } @@ -1426,7 +1429,7 @@ { struct ptnet_queue *pq = context; - device_printf(pq->sc->dev, "%s: pq #%u\n", __func__, pq->kring_id); + RD(1, "%s: pq #%u\n", __func__, pq->kring_id); ptnet_rx_eof(pq); } @@ -1435,7 +1438,7 @@ { struct ptnet_queue *pq = context; - device_printf(pq->sc->dev, "%s: pq #%u\n", __func__, pq->kring_id); + RD(1, "%s: pq #%u\n", __func__, pq->kring_id); ptnet_transmit(pq->sc->ifp, NULL); } From owner-svn-soc-all@freebsd.org Mon Jun 27 12:48: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 54AD0B72B4F for ; Mon, 27 Jun 2016 12:48: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 413F02220 for ; Mon, 27 Jun 2016 12:48: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 u5RCmkLc081078 for ; Mon, 27 Jun 2016 12:48:46 GMT (envelope-from vincenzo@FreeBSD.org) Received: (from www@localhost) by socsvn.freebsd.org (8.15.2/8.15.2/Submit) id u5RCmjoP081076 for svn-soc-all@FreeBSD.org; Mon, 27 Jun 2016 12:48:45 GMT (envelope-from vincenzo@FreeBSD.org) Date: Mon, 27 Jun 2016 12:48:45 GMT Message-Id: <201606271248.u5RCmjoP081076@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: r305587 - 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, 27 Jun 2016 12:48:46 -0000 Author: vincenzo Date: Mon Jun 27 12:48:45 2016 New Revision: 305587 URL: http://svnweb.FreeBSD.org/socsvn/?view=rev&rev=305587 Log: freebsd: ptnet_transmit: turn more device_printf() into RD() 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 Jun 27 09:42:13 2016 (r305586) +++ soc2016/vincenzo/head/sys/dev/netmap/if_ptnet.c Mon Jun 27 12:48:45 2016 (r305587) @@ -1193,9 +1193,10 @@ * by the taskqueue thread. */ err = drbr_enqueue(ifp, pq->bufring, m); m = NULL; /* just to stay safe */ - if (unlikely(err)) { - device_printf(sc->dev, "%s: drbr_enqueue() failed %d\n", - __func__, err); + if (err) { + /* ENOBUFS when the bufring is full */ + RD(1, "%s: drbr_enqueue() failed %d\n", + __func__, err); return err; } } @@ -1262,9 +1263,8 @@ /* Run out of slots while processing * a packet. Reset head to the previous * position and requeue the mbuf. */ - device_printf(sc->dev, "%s: Drop, " - " no free slots\n", - __func__); + RD(1, "%s: Drop, no free slots\n", + __func__); head = prev_head; drbr_putback(ifp, pq->bufring, m); goto escape; From owner-svn-soc-all@freebsd.org Mon Jun 27 12:48:56 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 84CFCB72B6A for ; Mon, 27 Jun 2016 12:48:56 +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 7876B2234 for ; Mon, 27 Jun 2016 12:48:56 +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 u5RCmutF081318 for ; Mon, 27 Jun 2016 12:48:56 GMT (envelope-from vincenzo@FreeBSD.org) Received: (from www@localhost) by socsvn.freebsd.org (8.15.2/8.15.2/Submit) id u5RCmtCT081316 for svn-soc-all@FreeBSD.org; Mon, 27 Jun 2016 12:48:55 GMT (envelope-from vincenzo@FreeBSD.org) Date: Mon, 27 Jun 2016 12:48:55 GMT Message-Id: <201606271248.u5RCmtCT081316@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: r305588 - 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, 27 Jun 2016 12:48:56 -0000 Author: vincenzo Date: Mon Jun 27 12:48:55 2016 New Revision: 305588 URL: http://svnweb.FreeBSD.org/socsvn/?view=rev&rev=305588 Log: freebsd: ptnet_transmit: ptnet_sync_tail when running out of slots 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 Jun 27 12:48:45 2016 (r305587) +++ soc2016/vincenzo/head/sys/dev/netmap/if_ptnet.c Mon Jun 27 12:48:55 2016 (r305588) @@ -1219,16 +1219,26 @@ ring = kring->ring; lim = kring->nkr_num_slots - 1; - /* Update hwcur and hwtail (completed TX slots) as known by the host, - * by reading from CSB. */ - ptnet_sync_tail(ptring, kring); - + /* Initialize transmission state variables. */ head = ring->head; slot = ring->slot + head; nmbuf = NMB(na, slot); nmbuf_bytes = 0; - while (head != ring->tail) { + for (;;) { + if (head == ring->tail) { + /* 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) { + /* Still no slots available, let's stop and wait + * for interrupts. */ + break; + } + m = drbr_peek(ifp, pq->bufring); if (!m) { break; From owner-svn-soc-all@freebsd.org Mon Jun 27 12:49: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 8ECD8B72B85 for ; Mon, 27 Jun 2016 12:49: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 827A72254 for ; Mon, 27 Jun 2016 12:49: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 u5RCnDVY081675 for ; Mon, 27 Jun 2016 12:49:13 GMT (envelope-from vincenzo@FreeBSD.org) Received: (from www@localhost) by socsvn.freebsd.org (8.15.2/8.15.2/Submit) id u5RCnC5J081673 for svn-soc-all@FreeBSD.org; Mon, 27 Jun 2016 12:49:12 GMT (envelope-from vincenzo@FreeBSD.org) Date: Mon, 27 Jun 2016 12:49:12 GMT Message-Id: <201606271249.u5RCnC5J081673@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: r305589 - 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, 27 Jun 2016 12:49:13 -0000 Author: vincenzo Date: Mon Jun 27 12:49:12 2016 New Revision: 305589 URL: http://svnweb.FreeBSD.org/socsvn/?view=rev&rev=305589 Log: freebsd: ptnet_transmit: recheck ring->tail only when necessary 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 Jun 27 12:48:55 2016 (r305588) +++ soc2016/vincenzo/head/sys/dev/netmap/if_ptnet.c Mon Jun 27 12:49:12 2016 (r305589) @@ -1231,12 +1231,12 @@ * freed up some, by reading hwcur and hwtail from * the CSB. */ ptnet_sync_tail(ptring, kring); - } - if (head == ring->tail) { - /* Still no slots available, let's stop and wait - * for interrupts. */ - break; + if (head == ring->tail) { + /* Still no slots available, let's stop and + * wait for interrupts. */ + break; + } } m = drbr_peek(ifp, pq->bufring); From owner-svn-soc-all@freebsd.org Mon Jun 27 12:49: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 6E866B72B9E for ; Mon, 27 Jun 2016 12:49: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 6230C226C for ; Mon, 27 Jun 2016 12:49: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 u5RCnNN8081924 for ; Mon, 27 Jun 2016 12:49:23 GMT (envelope-from vincenzo@FreeBSD.org) Received: (from www@localhost) by socsvn.freebsd.org (8.15.2/8.15.2/Submit) id u5RCnMLF081858 for svn-soc-all@FreeBSD.org; Mon, 27 Jun 2016 12:49:22 GMT (envelope-from vincenzo@FreeBSD.org) Date: Mon, 27 Jun 2016 12:49:22 GMT Message-Id: <201606271249.u5RCnMLF081858@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: r305590 - 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, 27 Jun 2016 12:49:23 -0000 Author: vincenzo Date: Mon Jun 27 12:49:22 2016 New Revision: 305590 URL: http://svnweb.FreeBSD.org/socsvn/?view=rev&rev=305590 Log: freebsd: ptnet_rx_eof: fix check for CSB update 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 Jun 27 12:49:12 2016 (r305589) +++ soc2016/vincenzo/head/sys/dev/netmap/if_ptnet.c Mon Jun 27 12:49:22 2016 (r305590) @@ -1387,7 +1387,7 @@ PTNET_Q_LOCK(pq); } - if (budget != PTNET_RX_BUDGET) { + 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 * ring->cur and ring->head (RX buffer refill). */ From owner-svn-soc-all@freebsd.org Mon Jun 27 12:55: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 DA75BB72D99 for ; Mon, 27 Jun 2016 12:55: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 CE1542700 for ; Mon, 27 Jun 2016 12:55: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 u5RCtP91098490 for ; Mon, 27 Jun 2016 12:55:25 GMT (envelope-from vincenzo@FreeBSD.org) Received: (from www@localhost) by socsvn.freebsd.org (8.15.2/8.15.2/Submit) id u5RCtPmC098438 for svn-soc-all@FreeBSD.org; Mon, 27 Jun 2016 12:55:25 GMT (envelope-from vincenzo@FreeBSD.org) Date: Mon, 27 Jun 2016 12:55:25 GMT Message-Id: <201606271255.u5RCtPmC098438@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: r305591 - 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, 27 Jun 2016 12:55:25 -0000 Author: vincenzo Date: Mon Jun 27 12:55:24 2016 New Revision: 305591 URL: http://svnweb.FreeBSD.org/socsvn/?view=rev&rev=305591 Log: freebsd: ptnet_rx_eof: lazy syncing (read) from CSB 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 Jun 27 12:49:22 2016 (r305590) +++ soc2016/vincenzo/head/sys/dev/netmap/if_ptnet.c Mon Jun 27 12:55:24 2016 (r305591) @@ -1336,24 +1336,49 @@ struct netmap_kring *kring = na->rx_rings + pq->kring_id; struct netmap_ring *ring = kring->ring; unsigned int const lim = kring->nkr_num_slots - 1; + unsigned int budget = PTNET_RX_BUDGET; + unsigned int head = ring->head; struct ifnet *ifp = sc->ifp; - unsigned int budget, head; PTNET_Q_LOCK(pq); - /* Update hwtail, rtail, tail and hwcur to what is known from the host, - * reading from CSB. */ - ptnet_sync_tail(ptring, kring); - kring->nr_kflags &= ~NKR_PENDINTR; - for (head = ring->head, budget = PTNET_RX_BUDGET; - head != ring->tail && budget; - head = nm_next(head, lim), budget--) { + for (;;) { struct netmap_slot *slot = ring->slot + head; - unsigned int nmbuf_len = slot->len; - uint8_t *nmbuf = NMB(na, slot); + unsigned int nmbuf_len; struct mbuf *m; + uint8_t *nmbuf; + + 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 + * the CSB. */ + ptnet_sync_tail(ptring, kring); + + if (head == ring->tail) { + /* Still no slots available. Reactivate + * interrupts as they were disabled by the + * host thread right before issuing the + * last interrupt. */ + ptring->guest_need_kick = 1; + + /* Double-check. */ + ptnet_sync_tail(ptring, kring); + if (likely(head == ring->tail)) { + break; + } + ptring->guest_need_kick = 0; + } + } + + nmbuf_len = slot->len; + nmbuf = NMB(na, slot); if (unlikely(nmbuf_len > MCLBYTES)) { RD(1, "Dropping long frame: len %u > %u", @@ -1385,6 +1410,9 @@ PTNET_Q_UNLOCK(pq); (*ifp->if_input)(ifp, m); PTNET_Q_LOCK(pq); + + head = nm_next(head, lim); + budget--; } if (head != ring->head) { @@ -1405,30 +1433,16 @@ ptring->sync_flags = NAF_FORCE_READ; bus_write_4(sc->iomem, pq->kick, 0); } - } - if (head == ring->tail) { - /* No more slots to process. Reactivate interrupts as they - * were disabled by the host thread right before issuing the - * last interrupt. */ - ptring->guest_need_kick = 1; - - /* Double-check. */ - ptnet_sync_tail(ptring, kring); - if (unlikely(head != ring->tail)) { - ptring->guest_need_kick = 0; + 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); + taskqueue_enqueue(pq->taskq, &pq->task); } } - if (head != ring->tail) { - /* 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, ring->head, - ring->tail); - taskqueue_enqueue(pq->taskq, &pq->task); - } - PTNET_Q_UNLOCK(pq); return 0;