-/* if_en.c 4.2 81/10/31 */
+/* if_en.c 4.11 81/11/20 */
#include "en.h"
/*
#include "../h/param.h"
#include "../h/systm.h"
#include "../h/mbuf.h"
-#include "../inet/inet.h"
-#include "../inet/inet_systm.h"
-#include "../inet/imp.h"
-#include "../inet/ip.h"
-#include "../inet/tcp.h" /* ### */
+#include "../net/inet.h"
+#include "../net/inet_pcb.h"
+#include "../net/inet_systm.h"
+#include "../net/imp.h"
+#include "../net/ip.h"
+#include "../net/ip_var.h"
+#include "../net/tcp.h" /* XXX */
+#include "../net/tcp_var.h"
#include "../h/map.h"
#include "../h/pte.h"
#include "../h/buf.h"
#include "../h/cpu.h"
#include "../h/cmap.h"
-int enrswaps, enwswaps;
+int enrswaps;
+/* int enwswaps; */
int enprobe(), enattach(), enrint(), enxint(), encollide();
struct uba_device *eninfo[NEN];
u_short enstd[] = { 0 };
struct en_packet *xpkt, *rpkt;
struct en_prefix {
struct en_header enp_h;
- struct th enp_th;
+ struct tcpiphdr enp_th;
};
struct uba_regs *enuba;
struct pte *enrmr, *enxmr;
#ifdef lint
br = 0; cvec = br; br = cvec;
+ enrint(0); enxint(0); encollide(0);
#endif
addr->en_istat = 0;
addr->en_ostat = 0;
addr->en_owc = -1;
addr->en_oba = 0;
- addr->en_ostat = IEN|GO;
+ addr->en_ostat = EN_IEN|EN_GO;
DELAY(100000);
addr->en_ostat = 0;
printf("ethernet address %d\n", ~addr->en_addr&0xff);
return (1);
}
+/*ARGSUSED*/
enattach(ui)
struct uba_device *ui;
{
reenter = 1;
n = 10;
k = n<<1;
- i = rmalloc(netmap, n*2);
+ i = rmalloc(mbmap, n*2);
if (i == 0)
panic("eninit");
j = i << 1;
cp = (char *)pftom(i);
- if (memall(&Netmap[j], k, proc, CSYS) == 0)
- return (0);
- vmaccess(&Netmap[j], (caddr_t)cp, k);
+ if (memall(&Mbmap[j], k, proc, CSYS) == 0)
+ panic("eninit");
+ vmaccess(&Mbmap[j], (caddr_t)cp, k);
rpkt = (struct en_packet *)
(cp + 1024 - sizeof (struct en_prefix));
xpkt = (struct en_packet *)
#endif
}
+#if 0
enreset(uban)
int uban;
{
if (ui == 0 || ui->ui_ubanum != uban || ui->ui_alive == 0)
continue;
if (imp_stat.iaddr)
- ubarelse(uban, imp_stat.iaddr);
+ ubarelse(uban, &imp_stat.iaddr);
if (imp_stat.oaddr)
- ubarelse(uban, imp_stat.oaddr);
+ ubarelse(uban, &imp_stat.oaddr);
eninit(unit);
printf("en%d ", unit);
}
}
+#endif
+int enlastdel = 25;
+int enlastx = 0;
enstart(dev)
dev_t dev;
{
register caddr_t cp, top;
int unit;
register int len;
- u_short uaddr;
struct uba_device *ui;
int enxswapnow = 0;
COUNT(ENSTART);
}
dp = mtod(m, char *);
if (((int)cp&0x3ff)==0 && ((int)dp&0x3ff)==0) {
- struct pte *pte = &Netmap[mtopf(dp)*2];
+ struct pte *pte = &Mbmap[mtopf(dp)*2];
*(int *)enxmr = enwproto | pte++->pg_pfnum;
*(int *)(enxmr+1) = enwproto | pte->pg_pfnum;
enxswapd = enxswapnow = 1;
} else
- bcopy((int)m + m->m_off, cp, m->m_len);
+ bcopy(mtod(m, caddr_t), cp,
+ (unsigned)m->m_len);
cp += m->m_len;
/* too soon! */
MFREE(m, mp);
m = mp;
}
+ if (enxswapnow == 0 && enxswapd) {
+ enxmr[0] = enxmap[0];
+ enxmr[1] = enxmap[1];
+ }
+ if (enlastx && enlastx == xpkt->Header.en_dhost)
+ imp_stat.endelay = enlastdel;
+ else
+ enlastx = xpkt->Header.en_dhost;
}
- if (enxswapnow == 0 && enxswapd) {
- enxmr[0] = enxmap[0];
- enxmr[1] = enxmap[1];
- }
- len = ntohs(((struct ip *)((int)xpkt + L1822))->ip_len) + L1822;
+ len = ntohs((u_short)(((struct ip *)((int)xpkt + L1822))->ip_len)) +
+ L1822;
if (len > sizeof(struct en_packet)) {
printf("imp_output: ridiculous IP length %d\n", len);
return;
printf("en%d: sending packet (%d bytes)\n", unit, len);
prt_byte(xpkt, len);
#endif
- addr->en_ostat = IEN|GO;
-}
-
-/*
- * Setup for a read
- */
-ensetup(dev)
- dev_t dev;
-{
- register struct endevice *addr;
- register struct uba_device *ui;
- register unsigned ubaddr;
- register int sps;
-COUNT(ENSETUP);
-
- ui = eninfo[ENUNIT(dev)];
- if (ui == 0 || ui->ui_alive == 0) {
- printf("en%d (imp_read): not alive\n", ENUNIT(dev));
- return;
- }
- addr = (struct endevice *)ui->ui_addr;
- addr->en_iba = imp_stat.iaddr;
- addr->en_iwc = -600; /* a little extra to avoid hardware bugs */
- addr->en_istat = IEN|GO;
+ addr->en_ostat = EN_IEN|EN_GO;
}
/*
}
imp_stat.endelay = 0;
imp_stat.enmask = ~0;
- if (addr->en_ostat&ERROR)
+ if (addr->en_ostat&EN_OERROR)
printf("en%d: output error ostat=%b\n", unit,
addr->en_ostat, EN_BITS);
imp_stat.outactive = 0;
if (imp_stat.outq_head)
enstart(unit);
+ else
+ enlastx = 0;
}
+int collisions;
encollide(unit)
int unit;
{
register struct uba_device *ui;
COUNT(ENCOLLIDE);
+ collisions++;
ui = eninfo[unit];
addr = (struct endevice *)ui->ui_addr;
addr->en_ostat, EN_BITS);
} else {
imp_stat.enmask <<= 1;
- imp_stat.endelay = time & ~imp_stat.enmask;
+ imp_stat.endelay = mfpr(ICR) & ~imp_stat.enmask;
}
enstart(unit);
}
register caddr_t cp;
struct mbuf *p, *top = 0;
struct ip *ip;
- int j, hlen;
+ u_int hlen;
COUNT(ENRINT);
ui = eninfo[unit];
#endif
if (imp_stat.flush)
goto flush;
- if (addr->en_istat&ERROR) {
+ if (addr->en_istat&EN_IERROR) {
#ifdef notdef
printf("en%d: input error istat=%b\n", unit,
addr->en_istat, EN_BITS);
}
#endif
ip = (struct ip *)((int)rpkt + L1822);
- len = ntohs(ip->ip_len) + L1822;
+ len = ntohs((u_short *)ip->ip_len) + L1822;
if (len > sizeof(struct en_packet) || len < sizeof (struct ip)) {
printf("enrint: bad ip length %d\n", len);
goto flush;
hlen = L1822 + sizeof (struct ip);
switch (ip->ip_p) {
- case TCPROTO:
- hlen += ((struct th *)ip)->t_off * 4;
+ case IPPROTO_TCP:
+ hlen += ((struct tcpiphdr *)ip)->ti_off << 2;
break;
}
MGET(m, 0);
top = m;
m->m_off = MMINOFF;
m->m_len = hlen;
- bcopy(rpkt, mtod(m, caddr_t), hlen);
+ bcopy((caddr_t)rpkt, mtod(m, caddr_t), hlen);
len -= hlen;
cp = (caddr_t)rpkt + hlen;
mp = m;
m->m_len = PGSIZE;
m->m_off = (int)p - (int)m;
if (((int)cp & 0x3ff) == 0) {
- struct pte *cpte = &Netmap[mtopf(cp)*2];
- struct pte *ppte = &Netmap[mtopf(p)*2];
+ struct pte *cpte = &Mbmap[mtopf(cp)*2];
+ struct pte *ppte = &Mbmap[mtopf(p)*2];
struct pte t;
enrswaps++;
t = *ppte; *ppte++ = *cpte; *cpte++ = t;
m->m_len = MIN(MLEN, len);
m->m_off = MMINOFF;
}
- bcopy(cp, (int)m + m->m_off, m->m_len);
+ bcopy(cp, mtod(m, caddr_t), (unsigned)m->m_len);
nocopy:
cp += m->m_len;
len -= m->m_len;
setup:
addr->en_iba = imp_stat.iaddr;
addr->en_iwc = -600;
- addr->en_istat = IEN|GO;
+ addr->en_istat = EN_IEN|EN_GO;
}
#ifdef IMPDEBUG