patch-2.4.19 linux-2.4.19/drivers/net/macsonic.c
Next file: linux-2.4.19/drivers/net/mii.c
Previous file: linux-2.4.19/drivers/net/macmace.c
Back to the patch index
Back to the overall index
- Lines: 246
- Date:
Fri Aug 2 17:39:44 2002
- Orig file:
linux-2.4.18/drivers/net/macsonic.c
- Orig date:
Tue Oct 16 21:56:29 2001
diff -urN linux-2.4.18/drivers/net/macsonic.c linux-2.4.19/drivers/net/macsonic.c
@@ -20,6 +20,9 @@
* and duplicating packets. Needs more testing.
*
* 99/01/03 MSch: upgraded to version 0.92 of the core driver, fixed.
+ *
+ * 00/10/31 sammy@sammy.net: Updated driver for 2.4 kernels, fixed problems
+ * on centris.
*/
#include <linux/kernel.h>
@@ -47,6 +50,7 @@
#include <asm/macintosh.h>
#include <asm/macints.h>
#include <asm/mac_via.h>
+#include <asm/pgalloc.h>
#include <linux/errno.h>
@@ -126,36 +130,42 @@
int __init macsonic_init(struct net_device* dev)
{
- struct sonic_local* lp = (struct sonic_local *)dev->priv;
+ struct sonic_local* lp;
int i;
/* Allocate the entire chunk of memory for the descriptors.
Note that this cannot cross a 64K boundary. */
for (i = 0; i < 20; i++) {
unsigned long desc_base, desc_top;
- if ((lp->sonic_desc =
- kmalloc(SIZEOF_SONIC_DESC
- * SONIC_BUS_SCALE(lp->dma_bitmode), GFP_KERNEL | GFP_DMA)) == NULL) {
+ if((lp = kmalloc(sizeof(struct sonic_local), GFP_KERNEL | GFP_DMA)) == NULL) {
printk(KERN_ERR "%s: couldn't allocate descriptor buffers\n", dev->name);
return -ENOMEM;
}
- desc_base = (unsigned long) lp->sonic_desc;
- desc_top = desc_base + SIZEOF_SONIC_DESC * SONIC_BUS_SCALE(lp->dma_bitmode);
+
+ desc_base = (unsigned long) lp;
+ desc_top = desc_base + sizeof(struct sonic_local);
if ((desc_top & 0xffff) >= (desc_base & 0xffff))
break;
/* Hmm. try again (FIXME: does this actually work?) */
- kfree(lp->sonic_desc);
+ kfree(lp);
printk(KERN_DEBUG
"%s: didn't get continguous chunk [%08lx - %08lx], trying again\n",
dev->name, desc_base, desc_top);
}
- if (lp->sonic_desc == NULL) {
+ if (lp == NULL) {
printk(KERN_ERR "%s: tried 20 times to allocate descriptor buffers, giving up.\n",
dev->name);
return -ENOMEM;
}
+ dev->priv = lp;
+
+#if 0
+ /* this code is only here as a curiousity... mainly, where the
+ fuck did SONIC_BUS_SCALE come from, and what was it supposed
+ to do? the normal allocation works great for 32 bit stuffs.. */
+
/* Now set up the pointers to point to the appropriate places */
lp->cda = lp->sonic_desc;
lp->tda = lp->cda + (SIZEOF_SONIC_CDA * SONIC_BUS_SCALE(lp->dma_bitmode));
@@ -164,6 +174,15 @@
lp->rra = lp->rda + (SIZEOF_SONIC_RD * SONIC_NUM_RDS
* SONIC_BUS_SCALE(lp->dma_bitmode));
+#endif
+
+ memset(lp, 0, sizeof(struct sonic_local));
+
+ lp->cda_laddr = (unsigned int)&(lp->cda);
+ lp->tda_laddr = (unsigned int)lp->tda;
+ lp->rra_laddr = (unsigned int)lp->rra;
+ lp->rda_laddr = (unsigned int)lp->rda;
+
/* FIXME, maybe we should use skbs */
if ((lp->rba = (char *)
kmalloc(SONIC_NUM_RRS * SONIC_RBSIZE, GFP_KERNEL | GFP_DMA)) == NULL) {
@@ -173,15 +192,17 @@
return -ENOMEM;
}
+ lp->rba_laddr = (unsigned int)lp->rba;
+
{
int rs, ds;
/* almost always 12*4096, but let's not take chances */
rs = ((SONIC_NUM_RRS * SONIC_RBSIZE + 4095) / 4096) * 4096;
/* almost always under a page, but let's not take chances */
- ds = ((SIZEOF_SONIC_DESC + 4095) / 4096) * 4096;
+ ds = ((sizeof(struct sonic_local) + 4095) / 4096) * 4096;
kernel_set_cachemode(lp->rba, rs, IOMAP_NOCACHE_SER);
- kernel_set_cachemode(lp->sonic_desc, ds, IOMAP_NOCACHE_SER);
+ kernel_set_cachemode(lp, ds, IOMAP_NOCACHE_SER);
}
#if 0
@@ -278,6 +299,7 @@
static int once_is_more_than_enough;
struct sonic_local* lp;
int i;
+ int dma_bitmode;
if (once_is_more_than_enough)
return -ENODEV;
@@ -317,7 +339,7 @@
printk("yes\n");
- if (dev) {
+ if (dev)
dev = init_etherdev(dev, sizeof(struct sonic_local));
if (!dev)
return -ENOMEM;
@@ -329,13 +351,17 @@
}
} else {
dev = init_etherdev(NULL, sizeof(struct sonic_local));
- }
if (dev == NULL)
return -ENOMEM;
- lp = (struct sonic_local*) dev->priv;
- memset(lp, 0, sizeof(struct sonic_local));
+ if(dev->priv) {
+ printk("%s: warning! sonic entering with priv already allocated!\n",
+ dev->name);
+ printk("%s: discarding, will attempt to reallocate\n", dev->name);
+ dev->priv = NULL;
+ }
+
/* Danger! My arms are flailing wildly! You *must* set this
before using sonic_read() */
@@ -357,8 +383,11 @@
/* The PowerBook's SONIC is 16 bit always. */
if (macintosh_config->ident == MAC_MODEL_PB520) {
- lp->reg_offset = 0;
- lp->dma_bitmode = 0;
+ reg_offset = 0;
+ dma_bitmode = 0;
+ } else if (macintosh_config->ident == MAC_MODEL_C610) {
+ reg_offset = 0;
+ dma_bitmode = 1;
} else {
/* Some of the comm-slot cards are 16 bit. But some
of them are not. The 32-bit cards use offset 2 and
@@ -369,27 +398,41 @@
/* Technically this is not necessary since we zeroed
it above */
- lp->reg_offset = 0;
- lp->dma_bitmode = 0;
+ reg_offset = 0;
+ dma_bitmode = 0;
sr = sonic_read(dev, SONIC_SR);
if (sr == 0 || sr == 0xffff) {
- lp->reg_offset = 2;
+ reg_offset = 2;
/* 83932 is 0x0004, 83934 is 0x0100 or 0x0101 */
sr = sonic_read(dev, SONIC_SR);
- lp->dma_bitmode = 1;
+ dma_bitmode = 1;
}
printk(KERN_INFO
"%s: revision 0x%04x, using %d bit DMA and register offset %d\n",
- dev->name, sr, lp->dma_bitmode?32:16, lp->reg_offset);
+ dev->name, sr, dma_bitmode?32:16, reg_offset);
}
+
-
+ /* this carries my sincere apologies -- by the time I got to updating
+ the driver, support for "reg_offsets" appeares nowhere in the sonic
+ code, going back for over a year. Fortunately, my Mac does't seem
+ to use whatever this was.
+
+ If you know how this is supposed to be implemented, either fix it,
+ or contact me (sammy@sammy.net) to explain what it is. --Sam */
+
+ if(reg_offset) {
+ printk("%s: register offset unsupported. please fix this if you know what it is.\n", dev->name);
+ return -ENODEV;
+ }
+
/* Software reset, then initialize control registers. */
sonic_write(dev, SONIC_CMD, SONIC_CR_RST);
sonic_write(dev, SONIC_DCR, SONIC_DCR_BMS |
SONIC_DCR_RFT1 | SONIC_DCR_TFT0 | SONIC_DCR_EXBUS |
- (lp->dma_bitmode ? SONIC_DCR_DW : 0));
+ (dma_bitmode ? SONIC_DCR_DW : 0));
+
/* This *must* be written back to in order to restore the
extended programmable output bits */
sonic_write(dev, SONIC_DCR2, 0);
@@ -453,7 +496,7 @@
u16 sonic_dcr;
int id;
int i;
- int reg_offset, dma_bitmode;
+ int dma_bitmode;
/* Find the first SONIC that hasn't been initialized already */
while ((ndev = nubus_find_type(NUBUS_CAT_NETWORK,
@@ -539,8 +582,6 @@
memset(lp, 0, sizeof(struct sonic_local));
/* Danger! My arms are flailing wildly! You *must* set this
before using sonic_read() */
- lp->reg_offset = reg_offset;
- lp->dma_bitmode = dma_bitmode;
dev->base_addr = base_addr;
dev->irq = SLOT2IRQ(ndev->board->slot);
@@ -553,6 +594,11 @@
printk(KERN_INFO "%s: revision 0x%04x, using %d bit DMA and register offset %d\n",
dev->name, sonic_read(dev, SONIC_SR), dma_bitmode?32:16, reg_offset);
+ if(reg_offset) {
+ printk("%s: register offset unsupported. please fix this if you know what it is.\n", dev->name);
+ return -ENODEV;
+ }
+
/* Software reset, then initialize control registers. */
sonic_write(dev, SONIC_CMD, SONIC_CR_RST);
sonic_write(dev, SONIC_DCR, sonic_dcr
@@ -618,6 +664,9 @@
#define sonic_chiptomem(bat) (bat)
#define PHYSADDR(quux) (quux)
+#define sonic_request_irq request_irq
+#define sonic_free_irq free_irq
+
#include "sonic.c"
/*
FUNET's LINUX-ADM group, linux-adm@nic.funet.fi
TCL-scripts by Sam Shen (who was at: slshen@lbl.gov)