-/*
- * Copyright (c) 1989 The Regents of the University of California.
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms are permitted
- * provided that the above copyright notice and this paragraph are
- * duplicated in all such forms and that any documentation,
- * advertising materials, and other materials related to such
- * distribution and use acknowledge that the software was developed
- * by the University of California, Berkeley. The name of the
- * University may not be used to endorse or promote products derived
- * from this software without specific prior written permission.
- * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
- * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
- * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
- *
- * @(#)if_vba.c 1.2 (Berkeley) 4/22/89
- */
-
-#ifdef notdef
-#include "param.h"
-#include "systm.h"
-#include "mbuf.h"
-#include "buf.h"
-#include "cmap.h"
-#include "vmmac.h"
-#include "socket.h"
-
-#include "../tahoe/mtpr.h"
-#include "../tahoe/pte.h"
-
-#include "../tahoevba/vbavar.h"
-
-#include "../net/if.h"
-#include "../netinet/in.h"
-#include "../netinet/if_ether.h"
-#endif
-
-static
-if_vbareserve(ifvba0, n, bufsize, extra, extrasize)
-struct ifvba *ifvba0;
-register int n;
-int bufsize;
-caddr_t *extra;
-int extrasize;
-{
- register caddr_t cp;
- register struct pte *pte;
- register struct ifvba *ifvba = ifvba0;
- struct ifvba *vlim = ifvba + n;
-
- n = roundup(extrasize + (n * bufsize), NBPG);
- cp = (caddr_t)malloc((u_long)n, M_DEVBUF, M_NOWAIT);
- if ((n + kvtophys(cp)) > VB_MAXADDR24) {
- free(cp, M_DEVBUF);
- cp = 0;
- }
- if (cp == 0) {
- printf("No memory for device buffer(s)\n");
- return (0);
- }
- /*
- * Make raw buffer pages uncacheable.
- */
- pte = kvtopte(cp);
- for (n = btoc(n); n--; pte++)
- pte->pg_nc = 1;
- mtpr(TBIA, 0);
- if (extra) {
- *extra = cp;
- cp += extrasize;
- }
- for (; ifvba < vlim; ifvba++) {
- ifvba->iff_buffer = cp;
- ifvba->iff_physaddr = kvtophys(cp);
- cp += bufsize;
- }
- return (1);
-}
-/*
- * Routine to copy from VERSAbus memory into mbufs.
- *
- * Warning: This makes the fairly safe assumption that
- * mbufs have even lengths.
- */
-static struct mbuf *
-if_vbaget(rxbuf, totlen, off0, ifp)
- u_char *rxbuf;
- int totlen, off0;
- struct ifnet *ifp;
-{
- register u_char *cp, *mcp;
- register struct mbuf *m;
- struct mbuf *top = 0, **mp = ⊤
- int len, off = off0;
-
- cp = rxbuf + sizeof (struct ether_header);
- while (totlen > 0) {
- MGET(m, M_DONTWAIT, MT_DATA);
- if (m == 0)
- goto bad;
- if (off) {
- len = totlen - off;
- cp = rxbuf + sizeof (struct ether_header) + off;
- } else
- len = totlen;
- if (len >= NBPG) {
- MCLGET(m);
- if (m->m_len == CLBYTES)
- m->m_len = len = MIN(len, CLBYTES);
- else
- m->m_len = len = MIN(MLEN, len);
- } else {
- m->m_len = len = MIN(MLEN, len);
- m->m_off = MMINOFF;
- }
- mcp = mtod(m, u_char *);
- if (ifp) {
- /*
- * Prepend interface pointer to first mbuf.
- */
- *(mtod(m, struct ifnet **)) = ifp;
- mcp += sizeof (ifp);
- len -= sizeof (ifp);
- ifp = (struct ifnet *)0;
- }
- bcopy(cp, mcp, (u_int)len);
- cp += len;
- *mp = m;
- mp = &m->m_next;
- if (off == 0) {
- totlen -= len;
- continue;
- }
- off += len;
- if (off == totlen) {
- cp = rxbuf + sizeof (struct ether_header);
- off = 0;
- totlen = off0;
- }
- }
- return (top);
-bad:
- m_freem(top);
- return (0);
-}
-
-static
-if_vbaput(ifu, m0)
-caddr_t ifu;
-struct mbuf *m0;
-{
- register struct mbuf *m = m0;
- register caddr_t cp = ifu;
-
- while (m) {
- bcopy(mtod(m, caddr_t), cp, (u_int)m->m_len);
- cp += m->m_len;
- MFREE(m, m0);
- m = m0;
- }
- if ((int)cp & 1)
- *cp++ = 0;
- return (cp - ifu);
-}