From owner-svn-src-all@freebsd.org Thu Jun 11 20:35:29 2020 Return-Path: Delivered-To: svn-src-all@mailman.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.nyi.freebsd.org (Postfix) with ESMTP id 149EF3408DB; Thu, 11 Jun 2020 20:35:29 +0000 (UTC) (envelope-from vmaffione@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "Let's Encrypt Authority X3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 49jbG86m8Jz4MrQ; Thu, 11 Jun 2020 20:35:28 +0000 (UTC) (envelope-from vmaffione@FreeBSD.org) Received: from repo.freebsd.org (repo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id E1B781E40D; Thu, 11 Jun 2020 20:35:28 +0000 (UTC) (envelope-from vmaffione@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id 05BKZSaF048284; Thu, 11 Jun 2020 20:35:28 GMT (envelope-from vmaffione@FreeBSD.org) Received: (from vmaffione@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id 05BKZSRU048282; Thu, 11 Jun 2020 20:35:28 GMT (envelope-from vmaffione@FreeBSD.org) Message-Id: <202006112035.05BKZSRU048282@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: vmaffione set sender to vmaffione@FreeBSD.org using -f From: Vincenzo Maffione Date: Thu, 11 Jun 2020 20:35:28 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r362076 - in head/sys/dev: netmap virtio/network X-SVN-Group: head X-SVN-Commit-Author: vmaffione X-SVN-Commit-Paths: in head/sys/dev: netmap virtio/network X-SVN-Commit-Revision: 362076 X-SVN-Commit-Repository: base MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-all@freebsd.org X-Mailman-Version: 2.1.33 Precedence: list List-Id: "SVN commit messages for the entire src tree \(except for " user" and " projects" \)" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 11 Jun 2020 20:35:29 -0000 Author: vmaffione Date: Thu Jun 11 20:35:28 2020 New Revision: 362076 URL: https://svnweb.freebsd.org/changeset/base/362076 Log: netmap: introduce netmap_kring_on() This function returns NULL if the ring identified by queue id and direction is in netmap mode. Otherwise return the corresponding kring. Use this function to replace vtnet_netmap_queue_on(). MFC after: 1 week Modified: head/sys/dev/netmap/if_vtnet_netmap.h head/sys/dev/netmap/netmap_kern.h head/sys/dev/virtio/network/if_vtnet.c Modified: head/sys/dev/netmap/if_vtnet_netmap.h ============================================================================== --- head/sys/dev/netmap/if_vtnet_netmap.h Thu Jun 11 20:26:39 2020 (r362075) +++ head/sys/dev/netmap/if_vtnet_netmap.h Thu Jun 11 20:35:28 2020 (r362076) @@ -33,25 +33,6 @@ #include /* vtophys ? */ #include -/* - * Return 1 if the queue identified by 't' and 'idx' is in netmap mode. - */ -static int -vtnet_netmap_queue_on(struct vtnet_softc *sc, enum txrx t, int idx) -{ - struct netmap_adapter *na = NA(sc->vtnet_ifp); - - if (!nm_native_on(na)) - return 0; - - if (t == NR_RX) - return !!(idx < na->num_rx_rings && - na->rx_rings[idx]->nr_mode == NKR_NETMAP_ON); - - return !!(idx < na->num_tx_rings && - na->tx_rings[idx]->nr_mode == NKR_NETMAP_ON); -} - /* Register and unregister. */ static int vtnet_netmap_reg(struct netmap_adapter *na, int state) Modified: head/sys/dev/netmap/netmap_kern.h ============================================================================== --- head/sys/dev/netmap/netmap_kern.h Thu Jun 11 20:26:39 2020 (r362075) +++ head/sys/dev/netmap/netmap_kern.h Thu Jun 11 20:35:28 2020 (r362076) @@ -1353,6 +1353,24 @@ nm_native_on(struct netmap_adapter *na) return nm_netmap_on(na) && (na->na_flags & NAF_NATIVE); } +static inline struct netmap_kring * +netmap_kring_on(struct netmap_adapter *na, u_int q, enum txrx t) +{ + struct netmap_kring *kring = NULL; + + if (!nm_native_on(na)) + return NULL; + + if (t == NR_RX && q < na->num_rx_rings) + kring = na->rx_rings[q]; + else if (t == NR_TX && q < na->num_tx_rings) + kring = na->tx_rings[q]; + else + return NULL; + + return (kring->nr_mode == NKR_NETMAP_ON) ? kring : NULL; +} + static inline int nm_iszombie(struct netmap_adapter *na) { Modified: head/sys/dev/virtio/network/if_vtnet.c ============================================================================== --- head/sys/dev/virtio/network/if_vtnet.c Thu Jun 11 20:26:39 2020 (r362075) +++ head/sys/dev/virtio/network/if_vtnet.c Thu Jun 11 20:35:28 2020 (r362076) @@ -1249,17 +1249,17 @@ vtnet_rxq_free_mbufs(struct vtnet_rxq *rxq) struct mbuf *m; int last; #ifdef DEV_NETMAP - int netmap_bufs = vtnet_netmap_queue_on(rxq->vtnrx_sc, NR_RX, - rxq->vtnrx_id); + struct netmap_kring *kring = netmap_kring_on(NA(rxq->vtnrx_sc->vtnet_ifp), + rxq->vtnrx_id, NR_RX); #else /* !DEV_NETMAP */ - int netmap_bufs = 0; + void *kring = NULL; #endif /* !DEV_NETMAP */ vq = rxq->vtnrx_vq; last = 0; while ((m = virtqueue_drain(vq, &last)) != NULL) { - if (!netmap_bufs) + if (kring == NULL) m_freem(m); } @@ -2074,17 +2074,17 @@ vtnet_txq_free_mbufs(struct vtnet_txq *txq) struct vtnet_tx_header *txhdr; int last; #ifdef DEV_NETMAP - int netmap_bufs = vtnet_netmap_queue_on(txq->vtntx_sc, NR_TX, - txq->vtntx_id); + struct netmap_kring *kring = netmap_kring_on(NA(txq->vtntx_sc->vtnet_ifp), + txq->vtntx_id, NR_TX); #else /* !DEV_NETMAP */ - int netmap_bufs = 0; + void *kring = NULL; #endif /* !DEV_NETMAP */ vq = txq->vtntx_vq; last = 0; while ((txhdr = virtqueue_drain(vq, &last)) != NULL) { - if (!netmap_bufs) { + if (kring == NULL) { m_freem(txhdr->vth_mbuf); uma_zfree(vtnet_tx_header_zone, txhdr); }