From owner-dev-commits-src-all@freebsd.org Sun Jan 24 21:59:45 2021 Return-Path: Delivered-To: dev-commits-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 BC6E94DCB81; Sun, 24 Jan 2021 21:59:45 +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 4DP6Nd50ZDz4fnP; Sun, 24 Jan 2021 21:59:45 +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 9E88729FF; Sun, 24 Jan 2021 21:59:45 +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 10OLxj1O086784; Sun, 24 Jan 2021 21:59:45 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 10OLxj5V086783; Sun, 24 Jan 2021 21:59:45 GMT (envelope-from git) Date: Sun, 24 Jan 2021 21:59:45 GMT Message-Id: <202101242159.10OLxj5V086783@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: Vincenzo Maffione Subject: git: ee0005f11f2b - main - 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/main X-Git-Reftype: branch X-Git-Commit: ee0005f11f2b38a714bc66b7d79832108f6fee77 Auto-Submitted: auto-generated X-BeenThere: dev-commits-src-all@freebsd.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: Commit messages for all branches of the src repository List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sun, 24 Jan 2021 21:59:45 -0000 The branch main has been updated by vmaffione: URL: https://cgit.FreeBSD.org/src/commit/?id=ee0005f11f2b38a714bc66b7d79832108f6fee77 commit ee0005f11f2b38a714bc66b7d79832108f6fee77 Author: Vincenzo Maffione AuthorDate: 2021-01-24 21:59:02 +0000 Commit: Vincenzo Maffione CommitDate: 2021-01-24 21:59:02 +0000 netmap: simplify parameter passing Changes imported from the netmap github. --- 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;