aboutsummaryrefslogtreecommitdiff
path: root/sys
diff options
context:
space:
mode:
authorPaul Richards <paul@FreeBSD.org>1993-10-24 04:27:00 +0000
committerPaul Richards <paul@FreeBSD.org>1993-10-24 04:27:00 +0000
commit568eb51a2666e512cfe1cc666502305345e72d69 (patch)
tree2c63e8d984986b95f993e271bd593a40586224ca /sys
parente597e9115dd80412d3660732097874e8d0aaa042 (diff)
downloadsrc-568eb51a2666e512cfe1cc666502305345e72d69.tar.gz
src-568eb51a2666e512cfe1cc666502305345e72d69.zip
Moved allocation of memory into is_attach so that malloc gets
called once when card is attached. Solved problem with driver getting hosed when a reset takes place. Removed init_block array -- now part of malloced memory. No more static declarations left. Added code so that debug ioctl actually does something. ifconfig is0 debug will now switch on debugging code. Other general cleanups.
Notes
Notes: svn path=/head/; revision=664
Diffstat (limited to 'sys')
-rw-r--r--sys/i386/isa/if_is.c166
-rw-r--r--sys/i386/isa/if_isreg.h12
2 files changed, 102 insertions, 76 deletions
diff --git a/sys/i386/isa/if_is.c b/sys/i386/isa/if_is.c
index ceb840119fba..1fdcd91a2668 100644
--- a/sys/i386/isa/if_is.c
+++ b/sys/i386/isa/if_is.c
@@ -1,3 +1,4 @@
+#define ISDEBUG
/*
* Isolan AT 4141-0 Ethernet driver
* Isolink 4110
@@ -24,8 +25,6 @@
#include "is.h"
#if NIS > 0
-#include "bpfilter.h"
-
#include "param.h"
#include "systm.h"
#include "errno.h"
@@ -53,6 +52,7 @@
#endif
#if NBPFILTER > 0
+#include "bpfilter.h"
#include "net/bpf.h"
#include "net/bpfdesc.h"
#endif
@@ -63,8 +63,6 @@
#include "vm/vm.h"
-
-
#define ETHER_MIN_LEN 64
#define ETHER_MAX_LEN 1518
#define ETHER_ADDR_LEN 6
@@ -80,7 +78,7 @@
struct is_softc {
struct arpcom arpcom; /* Ethernet common part */
int iobase; /* IO base address of card */
- void *lance_mem; /* Base of memory allocated to card */
+ struct init_block *init_block; /* Lance initialisation block */
struct mds *rd;
struct mds *td;
unsigned char *rbuf;
@@ -92,7 +90,7 @@ struct is_softc {
} is_softc[NIS] ;
-struct init_block init_block[NIS];
+int is_debug;
/* Function prototypes */
int is_probe(),is_attach(),is_watchdog();
@@ -141,7 +139,7 @@ is_probe(isa_dev)
is->iobase = isa_dev->id_iobase;
- /* Stop the lance chip, put it known state */
+ /* Stop the lance chip, put it in known state */
iswrcsr(unit,0,STOP);
DELAY(100);
@@ -173,10 +171,8 @@ is_reset(int unit)
if (unit >= NIS)
return;
- s = splnet();
printf("is%d: reset\n", unit);
is_init(unit);
- (void) splx(s);
}
/*
@@ -205,14 +201,36 @@ is_attach(isa_dev)
ifp->if_reset = is_reset;
ifp->if_watchdog = is_watchdog;
+ /*
+ * XXX -- not sure this is right place to do this
+ * Allocate memory for use by Lance
+ * Memory allocated for:
+ * initialisation block,
+ * ring descriptors,
+ * transmit and receive buffers.
+ */
+
+ /*
+ * XXX - hopefully have better way to get dma'able memory later,
+ * this code assumes that the physical memory address returned
+ * from malloc will be below 16Mb. The Lance's address registers
+ * are only 16 bits wide!
+ */
+
+#define MAXMEM ((NRBUF+NTBUF)*(BUFSIZE) + (NRBUF+NTBUF)*sizeof(struct mds) \
+ + sizeof(struct init_block) + 8)
+ is->init_block = (struct init_block *)malloc(MAXMEM,M_TEMP,M_NOWAIT);
+ if (!is->init_block) {
+ printf("is%d : Couldn't allocate memory for card\n",unit);
+ }
/*
- * XXX - Set is->lance_mem to NULL so first pass
- * through init_mem it won't try and free memory
- * This is getting messy and needs redoing.
- * Yes, I know NULL != 0 but it does what I want :-)
+ * XXX -- should take corrective action if not
+ * quadword alilgned, the 8 byte slew factor in MAXMEM
+ * allows for this.
*/
- is->lance_mem = NULL;
+ if ((u_long)is->init_block & 0x3)
+ printf("is%d: memory allocated not quadword aligned\n");
/* Set up DMA */
isa_dmacascade(isa_dev->id_drq);
@@ -269,49 +287,42 @@ init_mem(unit)
int unit;
{
int i;
- u_long temp;
+ void *temp;
struct is_softc *is = &is_softc[unit];
- /* Allocate memory */
-
/*
- * XXX - hopefully have better way to get dma'able memory later,
- * this code assumes that the physical memory address returned
- * from malloc will be below 16Mb. The Lance's address registers
- * are only 16 bits wide!
+ * At this point we assume that the
+ * memory allocated to the Lance is
+ * quadword aligned. If it isn't
+ * then the initialisation is going
+ * fail later on.
*/
-#define MAXMEM ((NRBUF+NTBUF)*(BUFSIZE) + (NRBUF+NTBUF)*sizeof(struct mds) + 8)
/*
- * XXX - If we've been here before then free
- * the previously allocated memory
+ * Set up lance initialisation block
*/
- if (is->lance_mem)
- free(is->lance_mem,M_TEMP);
- is->lance_mem = malloc(MAXMEM,M_TEMP,M_NOWAIT);
- if (!is->lance_mem) {
- printf("is%d : Couldn't allocate memory for card\n",unit);
- return;
- }
- temp = (u_long) is->lance_mem;
-
- /* Align message descriptors on quad word boundary
- (this is essential) */
-
- temp = (temp+8) - (temp%8);
+ temp = (void *)is->init_block;
+ temp += sizeof(struct init_block);
is->rd = (struct mds *) temp;
is->td = (struct mds *) (temp + (NRBUF*sizeof(struct mds)));
temp += (NRBUF+NTBUF) * sizeof(struct mds);
- init_block[unit].mode = 0;
- init_block[unit].rdra = kvtop(is->rd);
- init_block[unit].rlen = ((kvtop(is->rd) >> 16) & 0xff) | (RLEN<<13);
- init_block[unit].tdra = kvtop(is->td);
- init_block[unit].tlen = ((kvtop(is->td) >> 16) & 0xff) | (TLEN<<13);
+ is->init_block->mode = 0;
+ for (i=0; i<ETHER_ADDR_LEN; i++)
+ is->init_block->padr[i] = is->arpcom.ac_enaddr[i];
+ for (i = 0; i < 8; ++i)
+ is->init_block->ladrf[i] = MULTI_INIT_ADDR;
+ is->init_block->rdra = kvtop(is->rd);
+ is->init_block->rlen = ((kvtop(is->rd) >> 16) & 0xff) | (RLEN<<13);
+ is->init_block->tdra = kvtop(is->td);
+ is->init_block->tlen = ((kvtop(is->td) >> 16) & 0xff) | (TLEN<<13);
- /* Set up receive ring descriptors */
+
+ /*
+ * Set up receive ring descriptors
+ */
is->rbuf = (unsigned char *)temp;
for (i=0; i<NRBUF; i++) {
@@ -322,7 +333,9 @@ init_mem(unit)
temp += BUFSIZE;
}
- /* Set up transmit ring descriptors */
+ /*
+ * Set up transmit ring descriptors
+ */
is->tbuf = (unsigned char *)temp;
for (i=0; i<NTBUF; i++) {
@@ -339,6 +352,7 @@ init_mem(unit)
* Initialization of interface; set up initialization block
* and transmit/receive descriptor rings.
*/
+
is_init(unit)
int unit;
{
@@ -351,34 +365,25 @@ is_init(unit)
if (ifp->if_addrlist == (struct ifaddr *)0) return;
s = splnet();
- is->last_rd = is->last_td = is->no_td = 0;
- /* Set up lance's memory area */
- init_mem(unit);
-
- /* Stop Lance to get access to other registers */
+ /*
+ * Lance must be stopped
+ * to access registers.
+ */
+
iswrcsr(unit,0,STOP);
- /* Get ethernet address */
- for (i=0; i<ETHER_ADDR_LEN; i++)
- init_block[unit].padr[i] = is->arpcom.ac_enaddr[i];
-
-#if NBPFILTER > 0
- /*
- * Initialize multicast address hashing registers to accept
- * all multicasts (only used when in promiscuous mode)
- */
- for (i = 0; i < 8; ++i)
- init_block[unit].ladrf[i] = 0xff;
-#endif
+ is->last_rd = is->last_td = is->no_td = 0;
+ /* Set up lance's memory area */
+ init_mem(unit);
/* No byte swapping etc */
iswrcsr(unit,3,0);
/* Give lance the physical address of its memory area */
- iswrcsr(unit,1,kvtop(&init_block[unit]));
- iswrcsr(unit,2,(kvtop(&init_block[unit]) >> 16) & 0xff);
+ iswrcsr(unit,1,kvtop(is->init_block));
+ iswrcsr(unit,2,(kvtop(is->init_block) >> 16) & 0xff);
/* OK, let's try and initialise the Lance */
iswrcsr(unit,0,INIT);
@@ -521,8 +526,9 @@ is_start(ifp)
cdm->flags |= (OWN|STP|ENP);
cdm->bcnt = -len;
cdm->mcnt = 0;
-#if ISDEBUG > 3
- xmit_print(unit,is->last_td);
+#ifdef ISDEBUG
+ if (is_debug)
+ xmit_print(unit,is->last_td);
#endif
iswrcsr(unit,0,TDMD|INEA);
@@ -531,8 +537,9 @@ is_start(ifp)
}while(++is->no_td < NTBUF);
is->no_td = NTBUF;
is->arpcom.ac_if.if_flags |= IFF_OACTIVE;
-#if ISDEBUG >4
- printf("no_td = %x, last_td = %x\n",is->no_td, is->last_td);
+#ifdef ISDEBUG
+ if (is_debug)
+ printf("no_td = %x, last_td = %x\n",is->no_td, is->last_td);
#endif
return(0);
}
@@ -604,8 +611,9 @@ istint(unit)
if ((i=is->last_td - is->no_td) < 0)
i+=NTBUF;
cdm = (is->td+i);
-#if ISDEBUG >4
- printf("Trans cdm = %x\n",cdm);
+#ifdef ISDEBUG
+ if (is_debug)
+ printf("Trans cdm = %x\n",cdm);
#endif
if (cdm->flags&OWN) {
if (loopcount)
@@ -666,8 +674,9 @@ static inline void is_rint(int unit)
}
}else
{
-#if ISDEBUG >2
- recv_print(unit,is->last_rd);
+#ifdef ISDEBUG
+ if (is_debug)
+ recv_print(unit,is->last_rd);
#endif
isread(is,is->rbuf+(BUFSIZE*rmd),(int)cdm->mcnt);
is->arpcom.ac_if.if_ipackets++;
@@ -676,8 +685,9 @@ static inline void is_rint(int unit)
cdm->flags |= OWN;
cdm->mcnt = 0;
NEXTRDS;
-#if ISDEBUG >4
- printf("is->last_rd = %x, cdm = %x\n",is->last_rd,cdm);
+#ifdef ISDEBUG
+ if (is_debug)
+ printf("is->last_rd = %x, cdm = %x\n",is->last_rd,cdm);
#endif
} /* while */
is->last_rd = rmd;
@@ -921,7 +931,13 @@ is_ioctl(ifp, cmd, data)
if ((ifp->if_flags & IFF_UP) &&
(ifp->if_flags & IFF_RUNNING) == 0)
is_init(ifp->if_unit);
- }
+ }
+#ifdef ISDEBUG
+ if (ifp->if_flags & IFF_DEBUG)
+ is_debug = 1;
+ else
+ is_debug = 0;
+#endif
#if NBPFILTER > 0
if (ifp->if_flags & IFF_PROMISC) {
/*
@@ -931,7 +947,7 @@ is_ioctl(ifp, cmd, data)
* hashing array. For now we assume that
* this was done in is_init().
*/
- init_block[unit].mode = PROM;
+ is->init_block->mode = PROM;
} else
/*
* XXX - for multicasts to work, we would need to
diff --git a/sys/i386/isa/if_isreg.h b/sys/i386/isa/if_isreg.h
index 5e69064d9bfb..4dbca17e44d9 100644
--- a/sys/i386/isa/if_isreg.h
+++ b/sys/i386/isa/if_isreg.h
@@ -11,9 +11,19 @@
* of this software, nor does the author assume any responsibility
* for damages incurred with its use.
*
- * $Id$
+ * $Id: if_isreg.h,v 1.2 1993/10/16 13:45:55 rgrimes Exp $
*/
+/*
+ * Initialize multicast address hashing registers to accept
+ * all multicasts (only used when in promiscuous mode)
+ */
+#if NBPFILTER > 0
+#define MULTI_INIT_ADDR 0xff
+#else
+#define MULTI_INIT_ADDR 0
+#endif
+
/* Declarations specific to this driver */
#define NTBUF 2
#define TLEN 1