summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorderaadt <deraadt@openbsd.org>2000-04-19 00:10:35 +0000
committerderaadt <deraadt@openbsd.org>2000-04-19 00:10:35 +0000
commit5f95c991b212cd77c6ab74f53a735548c0826c95 (patch)
tree7c489138e0fc1abd380f53fedeb97993d60d4003
parentFavor BIOS geometry over physical. This should fix MANY problems with (diff)
downloadwireguard-openbsd-5f95c991b212cd77c6ab74f53a735548c0826c95.tar.xz
wireguard-openbsd-5f95c991b212cd77c6ab74f53a735548c0826c95.zip
split out mbuf scatter gather function
-rw-r--r--sys/conf/files3
-rw-r--r--sys/crypto/crypto.h3
-rw-r--r--sys/crypto/mbuf.c110
-rw-r--r--sys/dev/pci/hifn7751.c75
4 files changed, 118 insertions, 73 deletions
diff --git a/sys/conf/files b/sys/conf/files
index 68fe3ed8bcb..11d11efdf8a 100644
--- a/sys/conf/files
+++ b/sys/conf/files
@@ -1,4 +1,4 @@
-# $OpenBSD: files,v 1.159 2000/04/18 19:35:28 jason Exp $
+# $OpenBSD: files,v 1.160 2000/04/19 00:10:35 deraadt Exp $
# $NetBSD: files,v 1.87 1996/05/19 17:17:50 jonathan Exp $
# @(#)files.newconf 7.5 (Berkeley) 5/10/93
@@ -534,6 +534,7 @@ file crypto/set_key.c (inet & ipsec) | crypto
file crypto/ecb3_enc.c (inet & ipsec) | crypto
file crypto/crypto.c (inet & ipsec) | crypto
file crypto/cryptosoft.c (inet & ipsec) | crypto
+file crypto/mbuf.c (inet & ipsec) | crypto
file crypto/xform.c (inet & ipsec) | crypto
file netatalk/aarp.c netatalk
file netatalk/at_control.c netatalk
diff --git a/sys/crypto/crypto.h b/sys/crypto/crypto.h
index f4515fb6abb..9e3d688acab 100644
--- a/sys/crypto/crypto.h
+++ b/sys/crypto/crypto.h
@@ -157,6 +157,9 @@ extern int crypto_register(u_int32_t, int, void *, void *, void *);
extern int crypto_unregister(u_int32_t, int);
extern int32_t crypto_get_driverid(void);
+struct mbuf;
+int mbuf2pages(struct mbuf *, int *, long *, int *, int, int *);
+
extern struct cryptop *crypto_getreq(int);
extern void crypto_freereq(struct cryptop *);
#endif /* _KERNEL */
diff --git a/sys/crypto/mbuf.c b/sys/crypto/mbuf.c
new file mode 100644
index 00000000000..3ac7ebcc405
--- /dev/null
+++ b/sys/crypto/mbuf.c
@@ -0,0 +1,110 @@
+/* $OpenBSD: mbuf.c,v 1.1 2000/04/19 00:10:35 deraadt Exp $ */
+
+/*
+ * Copyright (c) 1999 Theo de Raadt
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. The name of the author may not be used to endorse or promote products
+ * derived from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+ * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include <sys/param.h>
+#include <sys/systm.h>
+#include <sys/proc.h>
+#include <sys/errno.h>
+#include <sys/malloc.h>
+#include <sys/kernel.h>
+#include <sys/mbuf.h>
+#include <vm/vm.h>
+#include <vm/vm_extern.h>
+#include <vm/pmap.h>
+#include <machine/pmap.h>
+
+#include <crypto/crypto.h>
+
+int
+mbuf2pages(m, np, pp, lp, maxp, nicep)
+ struct mbuf *m;
+ int *np;
+ long *pp;
+ int *lp;
+ int maxp;
+ int *nicep;
+{
+ struct mbuf *m0;
+ int npa = 0, tlen = 0;
+
+ /* generate a [pa,len] array from an mbuf */
+ for (m0 = m; m; m = m->m_next) {
+ void *va;
+ long pg, npg;
+ int len, off;
+
+ if (m->m_len == 0)
+ continue;
+ len = m->m_len;
+ tlen += len;
+ va = m->m_data;
+
+ lp[npa] = len;
+ pp[npa] = vtophys(va);
+ pg = pp[npa] & ~PAGE_MASK;
+ off = (long)va & PAGE_MASK;
+
+ while (len + off > PAGE_SIZE) {
+ va = va + PAGE_SIZE - off;
+ npg = vtophys(va);
+ if (npg != pg) {
+ /* FUCKED UP condition */
+ if (++npa > maxp)
+ return (0);
+ continue;
+ }
+ lp[npa] = PAGE_SIZE - off;
+ off = 0;
+
+ if (++npa > maxp)
+ return (0);
+
+ lp[npa] = len - (PAGE_SIZE - off);
+ len -= lp[npa];
+ pp[npa] = vtophys(va);
+ }
+
+ if (++npa == maxp)
+ return (0);
+ }
+
+ if (nicep) {
+ int nice = 1;
+ int i;
+
+ /* see if each [pa,len] entry is long-word aligned */
+ for (i = 0; i < npa; i++)
+ if ((lp[i] & 3) || (pp[i] & 3))
+ nice = 0;
+ *nicep = nice;
+ }
+
+ *np = npa;
+ return (tlen);
+}
diff --git a/sys/dev/pci/hifn7751.c b/sys/dev/pci/hifn7751.c
index 1c1caecbc45..780f3fcce8a 100644
--- a/sys/dev/pci/hifn7751.c
+++ b/sys/dev/pci/hifn7751.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: hifn7751.c,v 1.32 2000/04/13 22:34:08 jason Exp $ */
+/* $OpenBSD: hifn7751.c,v 1.33 2000/04/19 00:10:35 deraadt Exp $ */
/*
* Invertex AEON / Hi/fn 7751 driver
@@ -88,7 +88,6 @@ int hifn_checkramaddr __P((struct hifn_softc *, int));
void hifn_sessions __P((struct hifn_softc *));
int hifn_intr __P((void *));
u_int hifn_write_command __P((struct hifn_command *, u_int8_t *));
-int hifn_mbuf __P((struct mbuf *, int *, long *, int *, int, int *));
u_int32_t hifn_next_signature __P((u_int a, u_int cnt));
int hifn_newsession __P((u_int32_t *, struct cryptoini *));
int hifn_freesession __P((u_int32_t));
@@ -757,74 +756,6 @@ hifn_write_command(cmd, buf)
return (buf_pos - buf);
}
-int
-hifn_mbuf(m, np, pp, lp, maxp, nicep)
- struct mbuf *m;
- int *np;
- long *pp;
- int *lp;
- int maxp;
- int *nicep;
-{
- struct mbuf *m0;
- int npa = 0, tlen = 0;
-
- /* generate a [pa,len] array from an mbuf */
- for (m0 = m; m; m = m->m_next) {
- void *va;
- long pg, npg;
- int len, off;
-
- if (m->m_len == 0)
- continue;
- len = m->m_len;
- tlen += len;
- va = m->m_data;
-
- lp[npa] = len;
- pp[npa] = vtophys(va);
- pg = pp[npa] & ~PAGE_MASK;
- off = (long)va & PAGE_MASK;
-
- while (len + off > PAGE_SIZE) {
- va = va + PAGE_SIZE - off;
- npg = vtophys(va);
- if (npg != pg) {
- /* FUCKED UP condition */
- if (++npa > maxp)
- return (0);
- continue;
- }
- lp[npa] = PAGE_SIZE - off;
- off = 0;
-
- if (++npa > maxp)
- return (0);
-
- lp[npa] = len - (PAGE_SIZE - off);
- len -= lp[npa];
- pp[npa] = vtophys(va);
- }
-
- if (++npa == maxp)
- return (0);
- }
-
- if (nicep) {
- int nice = 1;
- int i;
-
- /* see if each [pa,len] entry is long-word aligned */
- for (i = 0; i < npa; i++)
- if ((lp[i] & 3) || (pp[i] & 3))
- nice = 0;
- *nicep = nice;
- }
-
- *np = npa;
- return (tlen);
-}
-
int
hifn_crypto(sc, cmd)
struct hifn_softc *sc;
@@ -836,7 +767,7 @@ hifn_crypto(sc, cmd)
int s, i;
if (cmd->src_npa == 0 && cmd->src_m)
- cmd->src_l = hifn_mbuf(cmd->src_m, &cmd->src_npa,
+ cmd->src_l = mbuf2pages(cmd->src_m, &cmd->src_npa,
cmd->src_packp, cmd->src_packl, MAX_SCATTER, &nicealign);
if (cmd->src_l == 0)
return (-1);
@@ -883,7 +814,7 @@ hifn_crypto(sc, cmd)
else
cmd->dst_m = cmd->src_m;
- cmd->dst_l = hifn_mbuf(cmd->dst_m, &cmd->dst_npa,
+ cmd->dst_l = mbuf2pages(cmd->dst_m, &cmd->dst_npa,
cmd->dst_packp, cmd->dst_packl, MAX_SCATTER, NULL);
if (cmd->dst_l == 0)
return (-1);