From owner-dev-commits-src-branches@freebsd.org Sun Jan 31 08:53:12 2021 Return-Path: Delivered-To: dev-commits-src-branches@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 24B8E4E8027; Sun, 31 Jan 2021 08:53:12 +0000 (UTC) (envelope-from git@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 "R3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4DT4bp5rvxz4m2g; Sun, 31 Jan 2021 08:53:10 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) (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 did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 89D682591A; Sun, 31 Jan 2021 08:53:09 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.16.1/8.16.1) with ESMTP id 10V8r9Cs017985; Sun, 31 Jan 2021 08:53:09 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 10V8r9h5017984; Sun, 31 Jan 2021 08:53:09 GMT (envelope-from git) Date: Sun, 31 Jan 2021 08:53:09 GMT Message-Id: <202101310853.10V8r9h5017984@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org From: Vincenzo Maffione Subject: git: e4c81e46acc0 - stable/13 - netmap: simplify parameter passing MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: vmaffione X-Git-Repository: src X-Git-Refname: refs/heads/stable/13 X-Git-Reftype: branch X-Git-Commit: e4c81e46acc0dc34fa6a680ad06f9b003675f86d Auto-Submitted: auto-generated X-BeenThere: dev-commits-src-branches@freebsd.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: Commits to the stable branches of the FreeBSD src repository List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sun, 31 Jan 2021 08:53:12 -0000 The branch stable/13 has been updated by vmaffione: URL: https://cgit.FreeBSD.org/src/commit/?id=e4c81e46acc0dc34fa6a680ad06f9b003675f86d commit e4c81e46acc0dc34fa6a680ad06f9b003675f86d Author: Vincenzo Maffione AuthorDate: 2021-01-24 21:59:02 +0000 Commit: Vincenzo Maffione CommitDate: 2021-01-31 08:53:06 +0000 netmap: simplify parameter passing Changes imported from the netmap github. (cherry picked from commit ee0005f11f2b38a714bc66b7d79832108f6fee77) --- sys/dev/netmap/netmap.c | 78 ++++++++++++++++++++++------------------- sys/dev/netmap/netmap_bdg.c | 3 +- sys/dev/netmap/netmap_kern.h | 5 ++- sys/dev/netmap/netmap_monitor.c | 3 +- 4 files changed, 45 insertions(+), 44 deletions(-) diff --git a/sys/dev/netmap/netmap.c b/sys/dev/netmap/netmap.c index 62d00f0bffc7..b711e0d2497e 100644 --- a/sys/dev/netmap/netmap.c +++ b/sys/dev/netmap/netmap.c @@ -1843,13 +1843,15 @@ netmap_ring_reinit(struct netmap_kring *kring) * */ int -netmap_interp_ringid(struct netmap_priv_d *priv, uint32_t nr_mode, - uint16_t nr_ringid, uint64_t nr_flags) +netmap_interp_ringid(struct netmap_priv_d *priv, struct nmreq_header *hdr) { struct netmap_adapter *na = priv->np_na; + struct nmreq_register *reg = (struct nmreq_register *)hdr->nr_body; int excluded_direction[] = { NR_TX_RINGS_ONLY, NR_RX_RINGS_ONLY }; enum txrx t; u_int j; + u_int nr_flags = reg->nr_flags, nr_mode = reg->nr_mode, + nr_ringid = reg->nr_ringid; for_rx_tx(t) { if (nr_flags & excluded_direction[t]) { @@ -1943,19 +1945,19 @@ netmap_interp_ringid(struct netmap_priv_d *priv, uint32_t nr_mode, * for all rings is the same as a single ring. */ static int -netmap_set_ringid(struct netmap_priv_d *priv, uint32_t nr_mode, - uint16_t nr_ringid, uint64_t nr_flags) +netmap_set_ringid(struct netmap_priv_d *priv, struct nmreq_header *hdr) { struct netmap_adapter *na = priv->np_na; + struct nmreq_register *reg = (struct nmreq_register *)hdr->nr_body; int error; enum txrx t; - error = netmap_interp_ringid(priv, nr_mode, nr_ringid, nr_flags); + error = netmap_interp_ringid(priv, hdr); if (error) { return error; } - priv->np_txpoll = (nr_flags & NR_NO_TX_POLL) ? 0 : 1; + priv->np_txpoll = (reg->nr_flags & NR_NO_TX_POLL) ? 0 : 1; /* optimization: count the users registered for more than * one ring, which are the ones sleeping on the global queue. @@ -1985,6 +1987,19 @@ netmap_unset_ringid(struct netmap_priv_d *priv) priv->np_kloop_state = 0; } +#define within_sel(p_, t_, i_) \ + ((i_) < (p_)->np_qlast[(t_)]) +#define nonempty_sel(p_, t_) \ + (within_sel((p_), (t_), (p_)->np_qfirst[(t_)])) +#define foreach_selected_ring(p_, t_, i_, kring_) \ + for ((t_) = nonempty_sel((p_), NR_RX) ? NR_RX : NR_TX, \ + (i_) = (p_)->np_qfirst[(t_)]; \ + (t_ == NR_RX || \ + (t == NR_TX && within_sel((p_), (t_), (i_)))) && \ + ((kring_) = NMR((p_)->np_na, (t_))[(i_)]); \ + (i_) = within_sel((p_), (t_), (i_) + 1) ? (i_) + 1 : \ + (++(t_) < NR_TXRX ? (p_)->np_qfirst[(t_)] : (i_))) + /* Set the nr_pending_mode for the requested rings. * If requested, also try to get exclusive access to the rings, provided @@ -2011,29 +2026,23 @@ netmap_krings_get(struct netmap_priv_d *priv) * are neither alread exclusively owned, nor we * want exclusive ownership when they are already in use */ - for_rx_tx(t) { - for (i = priv->np_qfirst[t]; i < priv->np_qlast[t]; i++) { - kring = NMR(na, t)[i]; - if ((kring->nr_kflags & NKR_EXCLUSIVE) || - (kring->users && excl)) - { - nm_prdis("ring %s busy", kring->name); - return EBUSY; - } + foreach_selected_ring(priv, t, i, kring) { + if ((kring->nr_kflags & NKR_EXCLUSIVE) || + (kring->users && excl)) + { + nm_prdis("ring %s busy", kring->name); + return EBUSY; } } /* second round: increment usage count (possibly marking them * as exclusive) and set the nr_pending_mode */ - for_rx_tx(t) { - for (i = priv->np_qfirst[t]; i < priv->np_qlast[t]; i++) { - kring = NMR(na, t)[i]; - kring->users++; - if (excl) - kring->nr_kflags |= NKR_EXCLUSIVE; - kring->nr_pending_mode = NKR_NETMAP_ON; - } + foreach_selected_ring(priv, t, i, kring) { + kring->users++; + if (excl) + kring->nr_kflags |= NKR_EXCLUSIVE; + kring->nr_pending_mode = NKR_NETMAP_ON; } return 0; @@ -2046,7 +2055,6 @@ netmap_krings_get(struct netmap_priv_d *priv) static void netmap_krings_put(struct netmap_priv_d *priv) { - struct netmap_adapter *na = priv->np_na; u_int i; struct netmap_kring *kring; int excl = (priv->np_flags & NR_EXCLUSIVE); @@ -2059,15 +2067,12 @@ netmap_krings_put(struct netmap_priv_d *priv) priv->np_qfirst[NR_RX], priv->np_qlast[MR_RX]); - for_rx_tx(t) { - for (i = priv->np_qfirst[t]; i < priv->np_qlast[t]; i++) { - kring = NMR(na, t)[i]; - if (excl) - kring->nr_kflags &= ~NKR_EXCLUSIVE; - kring->users--; - if (kring->users == 0) - kring->nr_pending_mode = NKR_NETMAP_OFF; - } + foreach_selected_ring(priv, t, i, kring) { + if (excl) + kring->nr_kflags &= ~NKR_EXCLUSIVE; + kring->users--; + if (kring->users == 0) + kring->nr_pending_mode = NKR_NETMAP_OFF; } } @@ -2300,7 +2305,7 @@ netmap_buf_size_validate(const struct netmap_adapter *na, unsigned mtu) { */ int netmap_do_regif(struct netmap_priv_d *priv, struct netmap_adapter *na, - uint32_t nr_mode, uint16_t nr_ringid, uint64_t nr_flags) + struct nmreq_header *hdr) { struct netmap_if *nifp = NULL; int error; @@ -2325,7 +2330,7 @@ netmap_do_regif(struct netmap_priv_d *priv, struct netmap_adapter *na, } /* compute the range of tx and rx rings to monitor */ - error = netmap_set_ringid(priv, nr_mode, nr_ringid, nr_flags); + error = netmap_set_ringid(priv, hdr); if (error) goto err_put_lut; @@ -2566,8 +2571,7 @@ netmap_ioctl(struct netmap_priv_d *priv, u_long cmd, caddr_t data, break; } - error = netmap_do_regif(priv, na, req->nr_mode, - req->nr_ringid, req->nr_flags); + error = netmap_do_regif(priv, na, hdr); if (error) { /* reg. failed, release priv and ref */ break; } diff --git a/sys/dev/netmap/netmap_bdg.c b/sys/dev/netmap/netmap_bdg.c index 96d6deedb768..4d18859e2091 100644 --- a/sys/dev/netmap/netmap_bdg.c +++ b/sys/dev/netmap/netmap_bdg.c @@ -1477,8 +1477,7 @@ netmap_bwrap_bdg_ctl(struct nmreq_header *hdr, struct netmap_adapter *na) if (npriv == NULL) return ENOMEM; npriv->np_ifp = na->ifp; /* let the priv destructor release the ref */ - error = netmap_do_regif(npriv, na, req->reg.nr_mode, - req->reg.nr_ringid, req->reg.nr_flags); + error = netmap_do_regif(npriv, na, hdr); if (error) { netmap_priv_delete(npriv); return error; diff --git a/sys/dev/netmap/netmap_kern.h b/sys/dev/netmap/netmap_kern.h index 3786826d8e38..fd9db5842df3 100644 --- a/sys/dev/netmap/netmap_kern.h +++ b/sys/dev/netmap/netmap_kern.h @@ -1449,8 +1449,7 @@ int netmap_attach_common(struct netmap_adapter *); /* fill priv->np_[tr]xq{first,last} using the ringid and flags information * coming from a struct nmreq_register */ -int netmap_interp_ringid(struct netmap_priv_d *priv, uint32_t nr_mode, - uint16_t nr_ringid, uint64_t nr_flags); +int netmap_interp_ringid(struct netmap_priv_d *priv, struct nmreq_header *hdr); /* update the ring parameters (number and size of tx and rx rings). * It calls the nm_config callback, if available. */ @@ -1485,7 +1484,7 @@ void netmap_enable_all_rings(struct ifnet *); int netmap_buf_size_validate(const struct netmap_adapter *na, unsigned mtu); int netmap_do_regif(struct netmap_priv_d *priv, struct netmap_adapter *na, - uint32_t nr_mode, uint16_t nr_ringid, uint64_t nr_flags); + struct nmreq_header *); void netmap_do_unregif(struct netmap_priv_d *priv); u_int nm_bound_var(u_int *v, u_int dflt, u_int lo, u_int hi, const char *msg); diff --git a/sys/dev/netmap/netmap_monitor.c b/sys/dev/netmap/netmap_monitor.c index f30abcc4b39a..1f5ff65b3b81 100644 --- a/sys/dev/netmap/netmap_monitor.c +++ b/sys/dev/netmap/netmap_monitor.c @@ -950,8 +950,7 @@ netmap_get_monitor_na(struct nmreq_header *hdr, struct netmap_adapter **na, mna->priv.np_na = pna; /* grab all the rings we need in the parent */ - error = netmap_interp_ringid(&mna->priv, req->nr_mode, req->nr_ringid, - req->nr_flags); + error = netmap_interp_ringid(&mna->priv, hdr); if (error) { nm_prerr("ringid error"); goto free_out;