Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

[PATCH] macsonic/jazzsonic network drivers update

The purpose of this patch:

- Adopt the DMA API (jazzsonic, macsonic & core driver).

- Adopt the driver model (macsonic).

This part was cribbed from jazzsonic. As a consequence, macsonic once
again works as a module. Driver model is also used by the DMA calls.

- Support 16 bit cards (macsonic & core driver, also affects jazzsonic)

This code was adapted from the mac68k linux 2.2 kernel, where it has
languished for a long time.

- Support more 32-bit mac cards (macsonic)

Also from mac68k repo.

- Zero-copy buffer handling (core driver)

Provides a nice performance improvement. The new algorithm incidentally
helped to replace the old Jazz DMA code.

The patch was tested on a variety of macs (several 32-bit quadra built-in
NICs, a 16-bit LC PDS NIC and a 16-bit comm-slot NIC), and also on MIPS
Jazz.

Signed-off-by: Finn Thain <fthain@telegraphics.com.au>
Acked-by: Thomas Bogendoerfer <tsbogend@alpha.franken.de>
Signed-off-by: Jeff Garzik <jgarzik@pobox.com>

authored by

Finn Thain and committed by
Jeff Garzik
efcce839 26006360

+970 -890
-4
drivers/net/Space.c
··· 87 87 extern struct net_device *tc515_probe(int unit); 88 88 extern struct net_device *lance_probe(int unit); 89 89 extern struct net_device *mace_probe(int unit); 90 - extern struct net_device *macsonic_probe(int unit); 91 90 extern struct net_device *mac8390_probe(int unit); 92 91 extern struct net_device *mac89x0_probe(int unit); 93 92 extern struct net_device *mc32_probe(int unit); ··· 282 283 #endif 283 284 #ifdef CONFIG_MACMACE /* Mac 68k Quadra AV builtin Ethernet */ 284 285 {mace_probe, 0}, 285 - #endif 286 - #ifdef CONFIG_MACSONIC /* Mac SONIC-based Ethernet of all sorts */ 287 - {macsonic_probe, 0}, 288 286 #endif 289 287 #ifdef CONFIG_MAC8390 /* NuBus NS8390-based cards */ 290 288 {mac8390_probe, 0},
+75 -113
drivers/net/jazzsonic.c
··· 1 1 /* 2 - * sonic.c 2 + * jazzsonic.c 3 + * 4 + * (C) 2005 Finn Thain 5 + * 6 + * Converted to DMA API, and (from the mac68k project) introduced 7 + * dhd's support for 16-bit cards. 3 8 * 4 9 * (C) 1996,1998 by Thomas Bogendoerfer (tsbogend@alpha.franken.de) 5 10 * ··· 33 28 #include <linux/netdevice.h> 34 29 #include <linux/etherdevice.h> 35 30 #include <linux/skbuff.h> 36 - #include <linux/bitops.h> 37 31 #include <linux/device.h> 32 + #include <linux/dma-mapping.h> 38 33 39 34 #include <asm/bootinfo.h> 40 35 #include <asm/system.h> ··· 49 44 50 45 #define SONIC_MEM_SIZE 0x100 51 46 52 - #define SREGS_PAD(n) u16 n; 53 - 54 47 #include "sonic.h" 55 48 56 49 /* 57 50 * Macros to access SONIC registers 58 51 */ 59 - #define SONIC_READ(reg) (*((volatile unsigned int *)base_addr+reg)) 52 + #define SONIC_READ(reg) (*((volatile unsigned int *)dev->base_addr+reg)) 60 53 61 54 #define SONIC_WRITE(reg,val) \ 62 55 do { \ 63 - *((volatile unsigned int *)base_addr+(reg)) = (val); \ 56 + *((volatile unsigned int *)dev->base_addr+(reg)) = (val); \ 64 57 } while (0) 65 58 66 59 67 - /* use 0 for production, 1 for verification, >2 for debug */ 60 + /* use 0 for production, 1 for verification, >1 for debug */ 68 61 #ifdef SONIC_DEBUG 69 62 static unsigned int sonic_debug = SONIC_DEBUG; 70 63 #else ··· 88 85 0xffff /* end of list */ 89 86 }; 90 87 91 - static int __init sonic_probe1(struct net_device *dev, unsigned long base_addr, 92 - unsigned int irq) 88 + static int __init sonic_probe1(struct net_device *dev) 93 89 { 94 90 static unsigned version_printed; 95 91 unsigned int silicon_revision; 96 92 unsigned int val; 97 - struct sonic_local *lp; 93 + struct sonic_local *lp = netdev_priv(dev); 98 94 int err = -ENODEV; 99 95 int i; 100 96 101 - if (!request_mem_region(base_addr, SONIC_MEM_SIZE, jazz_sonic_string)) 97 + if (!request_mem_region(dev->base_addr, SONIC_MEM_SIZE, jazz_sonic_string)) 102 98 return -EBUSY; 99 + 103 100 /* 104 101 * get the Silicon Revision ID. If this is one of the known 105 102 * one assume that we found a SONIC ethernet controller at ··· 123 120 if (sonic_debug && version_printed++ == 0) 124 121 printk(version); 125 122 126 - printk("%s: Sonic ethernet found at 0x%08lx, ", dev->name, base_addr); 127 - 128 - /* Fill in the 'dev' fields. */ 129 - dev->base_addr = base_addr; 130 - dev->irq = irq; 123 + printk(KERN_INFO "%s: Sonic ethernet found at 0x%08lx, ", lp->device->bus_id, dev->base_addr); 131 124 132 125 /* 133 126 * Put the sonic into software reset, then ··· 137 138 dev->dev_addr[i*2+1] = val >> 8; 138 139 } 139 140 140 - printk("HW Address "); 141 - for (i = 0; i < 6; i++) { 142 - printk("%2.2x", dev->dev_addr[i]); 143 - if (i<5) 144 - printk(":"); 145 - } 146 - 147 - printk(" IRQ %d\n", irq); 148 - 149 141 err = -ENOMEM; 150 142 151 143 /* Initialize the device structure. */ 152 - if (dev->priv == NULL) { 153 - /* 154 - * the memory be located in the same 64kb segment 155 - */ 156 - lp = NULL; 157 - i = 0; 158 - do { 159 - lp = kmalloc(sizeof(*lp), GFP_KERNEL); 160 - if ((unsigned long) lp >> 16 161 - != ((unsigned long)lp + sizeof(*lp) ) >> 16) { 162 - /* FIXME, free the memory later */ 163 - kfree(lp); 164 - lp = NULL; 165 - } 166 - } while (lp == NULL && i++ < 20); 167 144 168 - if (lp == NULL) { 169 - printk("%s: couldn't allocate memory for descriptors\n", 170 - dev->name); 171 - goto out; 172 - } 145 + lp->dma_bitmode = SONIC_BITMODE32; 173 146 174 - memset(lp, 0, sizeof(struct sonic_local)); 175 - 176 - /* get the virtual dma address */ 177 - lp->cda_laddr = vdma_alloc(CPHYSADDR(lp),sizeof(*lp)); 178 - if (lp->cda_laddr == ~0UL) { 179 - printk("%s: couldn't get DMA page entry for " 180 - "descriptors\n", dev->name); 181 - goto out1; 182 - } 183 - 184 - lp->tda_laddr = lp->cda_laddr + sizeof (lp->cda); 185 - lp->rra_laddr = lp->tda_laddr + sizeof (lp->tda); 186 - lp->rda_laddr = lp->rra_laddr + sizeof (lp->rra); 187 - 188 - /* allocate receive buffer area */ 189 - /* FIXME, maybe we should use skbs */ 190 - lp->rba = kmalloc(SONIC_NUM_RRS * SONIC_RBSIZE, GFP_KERNEL); 191 - if (!lp->rba) { 192 - printk("%s: couldn't allocate receive buffers\n", 193 - dev->name); 194 - goto out2; 195 - } 196 - 197 - /* get virtual dma address */ 198 - lp->rba_laddr = vdma_alloc(CPHYSADDR(lp->rba), 199 - SONIC_NUM_RRS * SONIC_RBSIZE); 200 - if (lp->rba_laddr == ~0UL) { 201 - printk("%s: couldn't get DMA page entry for receive " 202 - "buffers\n",dev->name); 203 - goto out3; 204 - } 205 - 206 - /* now convert pointer to KSEG1 pointer */ 207 - lp->rba = (char *)KSEG1ADDR(lp->rba); 208 - flush_cache_all(); 209 - dev->priv = (struct sonic_local *)KSEG1ADDR(lp); 147 + /* Allocate the entire chunk of memory for the descriptors. 148 + Note that this cannot cross a 64K boundary. */ 149 + if ((lp->descriptors = dma_alloc_coherent(lp->device, 150 + SIZEOF_SONIC_DESC * SONIC_BUS_SCALE(lp->dma_bitmode), 151 + &lp->descriptors_laddr, GFP_KERNEL)) == NULL) { 152 + printk(KERN_ERR "%s: couldn't alloc DMA memory for descriptors.\n", lp->device->bus_id); 153 + goto out; 210 154 } 211 155 212 - lp = (struct sonic_local *)dev->priv; 156 + /* Now set up the pointers to point to the appropriate places */ 157 + lp->cda = lp->descriptors; 158 + lp->tda = lp->cda + (SIZEOF_SONIC_CDA 159 + * SONIC_BUS_SCALE(lp->dma_bitmode)); 160 + lp->rda = lp->tda + (SIZEOF_SONIC_TD * SONIC_NUM_TDS 161 + * SONIC_BUS_SCALE(lp->dma_bitmode)); 162 + lp->rra = lp->rda + (SIZEOF_SONIC_RD * SONIC_NUM_RDS 163 + * SONIC_BUS_SCALE(lp->dma_bitmode)); 164 + 165 + lp->cda_laddr = lp->descriptors_laddr; 166 + lp->tda_laddr = lp->cda_laddr + (SIZEOF_SONIC_CDA 167 + * SONIC_BUS_SCALE(lp->dma_bitmode)); 168 + lp->rda_laddr = lp->tda_laddr + (SIZEOF_SONIC_TD * SONIC_NUM_TDS 169 + * SONIC_BUS_SCALE(lp->dma_bitmode)); 170 + lp->rra_laddr = lp->rda_laddr + (SIZEOF_SONIC_RD * SONIC_NUM_RDS 171 + * SONIC_BUS_SCALE(lp->dma_bitmode)); 172 + 213 173 dev->open = sonic_open; 214 174 dev->stop = sonic_close; 215 175 dev->hard_start_xmit = sonic_send_packet; 216 - dev->get_stats = sonic_get_stats; 176 + dev->get_stats = sonic_get_stats; 217 177 dev->set_multicast_list = &sonic_multicast_list; 178 + dev->tx_timeout = sonic_tx_timeout; 218 179 dev->watchdog_timeo = TX_TIMEOUT; 219 180 220 181 /* ··· 185 226 SONIC_WRITE(SONIC_MPT,0xffff); 186 227 187 228 return 0; 188 - out3: 189 - kfree(lp->rba); 190 - out2: 191 - vdma_free(lp->cda_laddr); 192 - out1: 193 - kfree(lp); 194 229 out: 195 - release_region(base_addr, SONIC_MEM_SIZE); 230 + release_region(dev->base_addr, SONIC_MEM_SIZE); 196 231 return err; 197 232 } 198 233 ··· 198 245 { 199 246 struct net_device *dev; 200 247 struct sonic_local *lp; 201 - unsigned long base_addr; 202 248 int err = 0; 203 249 int i; 204 250 ··· 207 255 if (mips_machgroup != MACH_GROUP_JAZZ) 208 256 return -ENODEV; 209 257 210 - dev = alloc_etherdev(0); 258 + dev = alloc_etherdev(sizeof(struct sonic_local)); 211 259 if (!dev) 212 260 return -ENOMEM; 213 261 214 - netdev_boot_setup_check(dev); 215 - base_addr = dev->base_addr; 262 + lp = netdev_priv(dev); 263 + lp->device = device; 264 + SET_NETDEV_DEV(dev, device); 265 + SET_MODULE_OWNER(dev); 216 266 217 - if (base_addr >= KSEG0) { /* Check a single specified location. */ 218 - err = sonic_probe1(dev, base_addr, dev->irq); 219 - } else if (base_addr != 0) { /* Don't probe at all. */ 267 + netdev_boot_setup_check(dev); 268 + 269 + if (dev->base_addr >= KSEG0) { /* Check a single specified location. */ 270 + err = sonic_probe1(dev); 271 + } else if (dev->base_addr != 0) { /* Don't probe at all. */ 220 272 err = -ENXIO; 221 273 } else { 222 274 for (i = 0; sonic_portlist[i].port; i++) { 223 - int io = sonic_portlist[i].port; 224 - if (sonic_probe1(dev, io, sonic_portlist[i].irq) == 0) 275 + dev->base_addr = sonic_portlist[i].port; 276 + dev->irq = sonic_portlist[i].irq; 277 + if (sonic_probe1(dev) == 0) 225 278 break; 226 279 } 227 280 if (!sonic_portlist[i].port) ··· 238 281 if (err) 239 282 goto out1; 240 283 284 + printk("%s: MAC ", dev->name); 285 + for (i = 0; i < 6; i++) { 286 + printk("%2.2x", dev->dev_addr[i]); 287 + if (i < 5) 288 + printk(":"); 289 + } 290 + printk(" IRQ %d\n", dev->irq); 291 + 241 292 return 0; 242 293 243 294 out1: 244 - lp = dev->priv; 245 - vdma_free(lp->rba_laddr); 246 - kfree(lp->rba); 247 - vdma_free(lp->cda_laddr); 248 - kfree(lp); 249 295 release_region(dev->base_addr, SONIC_MEM_SIZE); 250 296 out: 251 297 free_netdev(dev); ··· 256 296 return err; 257 297 } 258 298 259 - /* 260 - * SONIC uses a normal IRQ 261 - */ 262 - #define sonic_request_irq request_irq 263 - #define sonic_free_irq free_irq 299 + MODULE_DESCRIPTION("Jazz SONIC ethernet driver"); 300 + module_param(sonic_debug, int, 0); 301 + MODULE_PARM_DESC(sonic_debug, "jazzsonic debug level (1-4)"); 264 302 265 - #define sonic_chiptomem(x) KSEG1ADDR(vdma_log2phys(x)) 303 + #define SONIC_IRQ_FLAG SA_INTERRUPT 266 304 267 305 #include "sonic.c" 268 306 269 307 static int __devexit jazz_sonic_device_remove (struct device *device) 270 308 { 271 309 struct net_device *dev = device->driver_data; 310 + struct sonic_local* lp = netdev_priv(dev); 272 311 273 312 unregister_netdev (dev); 313 + dma_free_coherent(lp->device, SIZEOF_SONIC_DESC * SONIC_BUS_SCALE(lp->dma_bitmode), 314 + lp->descriptors, lp->descriptors_laddr); 274 315 release_region (dev->base_addr, SONIC_MEM_SIZE); 275 316 free_netdev (dev); 276 317 ··· 284 323 .probe = jazz_sonic_probe, 285 324 .remove = __devexit_p(jazz_sonic_device_remove), 286 325 }; 287 - 326 + 288 327 static void jazz_sonic_platform_release (struct device *device) 289 328 { 290 329 struct platform_device *pldev; ··· 297 336 static int __init jazz_sonic_init_module(void) 298 337 { 299 338 struct platform_device *pldev; 339 + int err; 300 340 301 - if (driver_register(&jazz_sonic_driver)) { 341 + if ((err = driver_register(&jazz_sonic_driver))) { 302 342 printk(KERN_ERR "Driver registration failed\n"); 303 - return -ENOMEM; 343 + return err; 304 344 } 305 345 306 346 jazz_sonic_device = NULL;
+275 -275
drivers/net/macsonic.c
··· 1 1 /* 2 2 * macsonic.c 3 3 * 4 + * (C) 2005 Finn Thain 5 + * 6 + * Converted to DMA API, converted to unified driver model, made it work as 7 + * a module again, and from the mac68k project, introduced more 32-bit cards 8 + * and dhd's support for 16-bit cards. 9 + * 4 10 * (C) 1998 Alan Cox 5 11 * 6 12 * Debugging Andreas Ehliar, Michael Schmitz ··· 32 26 */ 33 27 34 28 #include <linux/kernel.h> 29 + #include <linux/module.h> 35 30 #include <linux/types.h> 36 - #include <linux/ctype.h> 37 31 #include <linux/fcntl.h> 38 32 #include <linux/interrupt.h> 39 33 #include <linux/init.h> ··· 47 41 #include <linux/netdevice.h> 48 42 #include <linux/etherdevice.h> 49 43 #include <linux/skbuff.h> 50 - #include <linux/module.h> 51 - #include <linux/bitops.h> 44 + #include <linux/device.h> 45 + #include <linux/dma-mapping.h> 52 46 53 47 #include <asm/bootinfo.h> 54 48 #include <asm/system.h> ··· 60 54 #include <asm/macints.h> 61 55 #include <asm/mac_via.h> 62 56 63 - #define SREGS_PAD(n) u16 n; 57 + static char mac_sonic_string[] = "macsonic"; 58 + static struct platform_device *mac_sonic_device; 64 59 65 60 #include "sonic.h" 66 61 67 - #define SONIC_READ(reg) \ 68 - nubus_readl(base_addr+(reg)) 69 - #define SONIC_WRITE(reg,val) \ 70 - nubus_writel((val), base_addr+(reg)) 71 - #define sonic_read(dev, reg) \ 72 - nubus_readl((dev)->base_addr+(reg)) 73 - #define sonic_write(dev, reg, val) \ 74 - nubus_writel((val), (dev)->base_addr+(reg)) 62 + /* These should basically be bus-size and endian independent (since 63 + the SONIC is at least smart enough that it uses the same endianness 64 + as the host, unlike certain less enlightened Macintosh NICs) */ 65 + #define SONIC_READ(reg) (nubus_readw(dev->base_addr + (reg * 4) \ 66 + + lp->reg_offset)) 67 + #define SONIC_WRITE(reg,val) (nubus_writew(val, dev->base_addr + (reg * 4) \ 68 + + lp->reg_offset)) 75 69 70 + /* use 0 for production, 1 for verification, >1 for debug */ 71 + #ifdef SONIC_DEBUG 72 + static unsigned int sonic_debug = SONIC_DEBUG; 73 + #else 74 + static unsigned int sonic_debug = 1; 75 + #endif 76 76 77 - static int sonic_debug; 78 77 static int sonic_version_printed; 79 - 80 - static int reg_offset; 81 78 82 79 extern int mac_onboard_sonic_probe(struct net_device* dev); 83 80 extern int mac_nubus_sonic_probe(struct net_device* dev); ··· 117 108 118 109 #define SONIC_READ_PROM(addr) nubus_readb(prom_addr+addr) 119 110 120 - struct net_device * __init macsonic_probe(int unit) 121 - { 122 - struct net_device *dev = alloc_etherdev(0); 123 - int err; 124 - 125 - if (!dev) 126 - return ERR_PTR(-ENOMEM); 127 - 128 - if (unit >= 0) 129 - sprintf(dev->name, "eth%d", unit); 130 - 131 - SET_MODULE_OWNER(dev); 132 - 133 - /* This will catch fatal stuff like -ENOMEM as well as success */ 134 - err = mac_onboard_sonic_probe(dev); 135 - if (err == 0) 136 - goto found; 137 - if (err != -ENODEV) 138 - goto out; 139 - err = mac_nubus_sonic_probe(dev); 140 - if (err) 141 - goto out; 142 - found: 143 - err = register_netdev(dev); 144 - if (err) 145 - goto out1; 146 - return dev; 147 - out1: 148 - kfree(dev->priv); 149 - out: 150 - free_netdev(dev); 151 - return ERR_PTR(err); 152 - } 153 - 154 111 /* 155 112 * For reversing the PROM address 156 113 */ ··· 135 160 136 161 int __init macsonic_init(struct net_device* dev) 137 162 { 138 - struct sonic_local* lp = NULL; 139 - int i; 163 + struct sonic_local* lp = netdev_priv(dev); 140 164 141 165 /* Allocate the entire chunk of memory for the descriptors. 142 166 Note that this cannot cross a 64K boundary. */ 143 - for (i = 0; i < 20; i++) { 144 - unsigned long desc_base, desc_top; 145 - if((lp = kmalloc(sizeof(struct sonic_local), GFP_KERNEL | GFP_DMA)) == NULL) { 146 - printk(KERN_ERR "%s: couldn't allocate descriptor buffers\n", dev->name); 147 - return -ENOMEM; 148 - } 149 - 150 - desc_base = (unsigned long) lp; 151 - desc_top = desc_base + sizeof(struct sonic_local); 152 - if ((desc_top & 0xffff) >= (desc_base & 0xffff)) 153 - break; 154 - /* Hmm. try again (FIXME: does this actually work?) */ 155 - kfree(lp); 156 - printk(KERN_DEBUG 157 - "%s: didn't get continguous chunk [%08lx - %08lx], trying again\n", 158 - dev->name, desc_base, desc_top); 159 - } 160 - 161 - if (lp == NULL) { 162 - printk(KERN_ERR "%s: tried 20 times to allocate descriptor buffers, giving up.\n", 163 - dev->name); 167 + if ((lp->descriptors = dma_alloc_coherent(lp->device, 168 + SIZEOF_SONIC_DESC * SONIC_BUS_SCALE(lp->dma_bitmode), 169 + &lp->descriptors_laddr, GFP_KERNEL)) == NULL) { 170 + printk(KERN_ERR "%s: couldn't alloc DMA memory for descriptors.\n", lp->device->bus_id); 164 171 return -ENOMEM; 165 - } 166 - 167 - dev->priv = lp; 168 - 169 - #if 0 170 - /* this code is only here as a curiousity... mainly, where the 171 - fuck did SONIC_BUS_SCALE come from, and what was it supposed 172 - to do? the normal allocation works great for 32 bit stuffs.. */ 172 + } 173 173 174 174 /* Now set up the pointers to point to the appropriate places */ 175 - lp->cda = lp->sonic_desc; 176 - lp->tda = lp->cda + (SIZEOF_SONIC_CDA * SONIC_BUS_SCALE(lp->dma_bitmode)); 175 + lp->cda = lp->descriptors; 176 + lp->tda = lp->cda + (SIZEOF_SONIC_CDA 177 + * SONIC_BUS_SCALE(lp->dma_bitmode)); 177 178 lp->rda = lp->tda + (SIZEOF_SONIC_TD * SONIC_NUM_TDS 178 - * SONIC_BUS_SCALE(lp->dma_bitmode)); 179 + * SONIC_BUS_SCALE(lp->dma_bitmode)); 179 180 lp->rra = lp->rda + (SIZEOF_SONIC_RD * SONIC_NUM_RDS 180 - * SONIC_BUS_SCALE(lp->dma_bitmode)); 181 + * SONIC_BUS_SCALE(lp->dma_bitmode)); 181 182 182 - #endif 183 - 184 - memset(lp, 0, sizeof(struct sonic_local)); 185 - 186 - lp->cda_laddr = (unsigned int)&(lp->cda); 187 - lp->tda_laddr = (unsigned int)lp->tda; 188 - lp->rra_laddr = (unsigned int)lp->rra; 189 - lp->rda_laddr = (unsigned int)lp->rda; 190 - 191 - /* FIXME, maybe we should use skbs */ 192 - if ((lp->rba = (char *) 193 - kmalloc(SONIC_NUM_RRS * SONIC_RBSIZE, GFP_KERNEL | GFP_DMA)) == NULL) { 194 - printk(KERN_ERR "%s: couldn't allocate receive buffers\n", dev->name); 195 - dev->priv = NULL; 196 - kfree(lp); 197 - return -ENOMEM; 198 - } 199 - 200 - lp->rba_laddr = (unsigned int)lp->rba; 201 - 202 - { 203 - int rs, ds; 204 - 205 - /* almost always 12*4096, but let's not take chances */ 206 - rs = ((SONIC_NUM_RRS * SONIC_RBSIZE + 4095) / 4096) * 4096; 207 - /* almost always under a page, but let's not take chances */ 208 - ds = ((sizeof(struct sonic_local) + 4095) / 4096) * 4096; 209 - kernel_set_cachemode(lp->rba, rs, IOMAP_NOCACHE_SER); 210 - kernel_set_cachemode(lp, ds, IOMAP_NOCACHE_SER); 211 - } 212 - 213 - #if 0 214 - flush_cache_all(); 215 - #endif 183 + lp->cda_laddr = lp->descriptors_laddr; 184 + lp->tda_laddr = lp->cda_laddr + (SIZEOF_SONIC_CDA 185 + * SONIC_BUS_SCALE(lp->dma_bitmode)); 186 + lp->rda_laddr = lp->tda_laddr + (SIZEOF_SONIC_TD * SONIC_NUM_TDS 187 + * SONIC_BUS_SCALE(lp->dma_bitmode)); 188 + lp->rra_laddr = lp->rda_laddr + (SIZEOF_SONIC_RD * SONIC_NUM_RDS 189 + * SONIC_BUS_SCALE(lp->dma_bitmode)); 216 190 217 191 dev->open = sonic_open; 218 192 dev->stop = sonic_close; 219 193 dev->hard_start_xmit = sonic_send_packet; 220 194 dev->get_stats = sonic_get_stats; 221 195 dev->set_multicast_list = &sonic_multicast_list; 196 + dev->tx_timeout = sonic_tx_timeout; 197 + dev->watchdog_timeo = TX_TIMEOUT; 222 198 223 199 /* 224 200 * clear tally counter 225 201 */ 226 - sonic_write(dev, SONIC_CRCT, 0xffff); 227 - sonic_write(dev, SONIC_FAET, 0xffff); 228 - sonic_write(dev, SONIC_MPT, 0xffff); 202 + SONIC_WRITE(SONIC_CRCT, 0xffff); 203 + SONIC_WRITE(SONIC_FAET, 0xffff); 204 + SONIC_WRITE(SONIC_MPT, 0xffff); 229 205 230 206 return 0; 231 207 } 232 208 233 209 int __init mac_onboard_sonic_ethernet_addr(struct net_device* dev) 234 210 { 211 + struct sonic_local *lp = netdev_priv(dev); 235 212 const int prom_addr = ONBOARD_SONIC_PROM_BASE; 236 213 int i; 237 214 ··· 197 270 why this is so. */ 198 271 if (memcmp(dev->dev_addr, "\x08\x00\x07", 3) && 199 272 memcmp(dev->dev_addr, "\x00\xA0\x40", 3) && 273 + memcmp(dev->dev_addr, "\x00\x80\x19", 3) && 200 274 memcmp(dev->dev_addr, "\x00\x05\x02", 3)) 201 275 bit_reverse_addr(dev->dev_addr); 202 276 else ··· 209 281 the card... */ 210 282 if (memcmp(dev->dev_addr, "\x08\x00\x07", 3) && 211 283 memcmp(dev->dev_addr, "\x00\xA0\x40", 3) && 284 + memcmp(dev->dev_addr, "\x00\x80\x19", 3) && 212 285 memcmp(dev->dev_addr, "\x00\x05\x02", 3)) 213 286 { 214 287 unsigned short val; 215 288 216 289 printk(KERN_INFO "macsonic: PROM seems to be wrong, trying CAM entry 15\n"); 217 290 218 - sonic_write(dev, SONIC_CMD, SONIC_CR_RST); 219 - sonic_write(dev, SONIC_CEP, 15); 291 + SONIC_WRITE(SONIC_CMD, SONIC_CR_RST); 292 + SONIC_WRITE(SONIC_CEP, 15); 220 293 221 - val = sonic_read(dev, SONIC_CAP2); 294 + val = SONIC_READ(SONIC_CAP2); 222 295 dev->dev_addr[5] = val >> 8; 223 296 dev->dev_addr[4] = val & 0xff; 224 - val = sonic_read(dev, SONIC_CAP1); 297 + val = SONIC_READ(SONIC_CAP1); 225 298 dev->dev_addr[3] = val >> 8; 226 299 dev->dev_addr[2] = val & 0xff; 227 - val = sonic_read(dev, SONIC_CAP0); 300 + val = SONIC_READ(SONIC_CAP0); 228 301 dev->dev_addr[1] = val >> 8; 229 302 dev->dev_addr[0] = val & 0xff; 230 303 ··· 240 311 241 312 if (memcmp(dev->dev_addr, "\x08\x00\x07", 3) && 242 313 memcmp(dev->dev_addr, "\x00\xA0\x40", 3) && 314 + memcmp(dev->dev_addr, "\x00\x80\x19", 3) && 243 315 memcmp(dev->dev_addr, "\x00\x05\x02", 3)) 244 316 { 245 317 /* ··· 255 325 { 256 326 /* Bwahahaha */ 257 327 static int once_is_more_than_enough; 258 - int i; 259 - int dma_bitmode; 328 + struct sonic_local* lp = netdev_priv(dev); 329 + int sr; 330 + int commslot = 0; 260 331 261 332 if (once_is_more_than_enough) 262 333 return -ENODEV; ··· 266 335 if (!MACH_IS_MAC) 267 336 return -ENODEV; 268 337 269 - printk(KERN_INFO "Checking for internal Macintosh ethernet (SONIC).. "); 270 - 271 338 if (macintosh_config->ether_type != MAC_ETHER_SONIC) 272 - { 273 - printk("none.\n"); 274 339 return -ENODEV; 275 - } 276 - 340 + 341 + printk(KERN_INFO "Checking for internal Macintosh ethernet (SONIC).. "); 342 + 277 343 /* Bogus probing, on the models which may or may not have 278 344 Ethernet (BTW, the Ethernet *is* always at the same 279 345 address, and nothing else lives there, at least if Apple's 280 346 documentation is to be believed) */ 281 347 if (macintosh_config->ident == MAC_MODEL_Q630 || 282 348 macintosh_config->ident == MAC_MODEL_P588 || 349 + macintosh_config->ident == MAC_MODEL_P575 || 283 350 macintosh_config->ident == MAC_MODEL_C610) { 284 351 unsigned long flags; 285 352 int card_present; ··· 290 361 printk("none.\n"); 291 362 return -ENODEV; 292 363 } 364 + commslot = 1; 293 365 } 294 366 295 367 printk("yes\n"); 296 368 297 - /* Danger! My arms are flailing wildly! You *must* set this 298 - before using sonic_read() */ 299 - 369 + /* Danger! My arms are flailing wildly! You *must* set lp->reg_offset 370 + * and dev->base_addr before using SONIC_READ() or SONIC_WRITE() */ 300 371 dev->base_addr = ONBOARD_SONIC_REGISTERS; 301 372 if (via_alt_mapping) 302 373 dev->irq = IRQ_AUTO_3; ··· 308 379 sonic_version_printed = 1; 309 380 } 310 381 printk(KERN_INFO "%s: onboard / comm-slot SONIC at 0x%08lx\n", 311 - dev->name, dev->base_addr); 312 - 313 - /* Now do a song and dance routine in an attempt to determine 314 - the bus width */ 382 + lp->device->bus_id, dev->base_addr); 315 383 316 384 /* The PowerBook's SONIC is 16 bit always. */ 317 385 if (macintosh_config->ident == MAC_MODEL_PB520) { 318 - reg_offset = 0; 319 - dma_bitmode = 0; 320 - } else if (macintosh_config->ident == MAC_MODEL_C610) { 321 - reg_offset = 0; 322 - dma_bitmode = 1; 323 - } else { 386 + lp->reg_offset = 0; 387 + lp->dma_bitmode = SONIC_BITMODE16; 388 + sr = SONIC_READ(SONIC_SR); 389 + } else if (commslot) { 324 390 /* Some of the comm-slot cards are 16 bit. But some 325 - of them are not. The 32-bit cards use offset 2 and 326 - pad with zeroes or sometimes ones (I think...) 327 - Therefore, if we try offset 0 and get a silicon 328 - revision of 0, we assume 16 bit. */ 329 - int sr; 391 + of them are not. The 32-bit cards use offset 2 and 392 + have known revisions, we try reading the revision 393 + register at offset 2, if we don't get a known revision 394 + we assume 16 bit at offset 0. */ 395 + lp->reg_offset = 2; 396 + lp->dma_bitmode = SONIC_BITMODE16; 330 397 331 - /* Technically this is not necessary since we zeroed 332 - it above */ 333 - reg_offset = 0; 334 - dma_bitmode = 0; 335 - sr = sonic_read(dev, SONIC_SR); 336 - if (sr == 0 || sr == 0xffff) { 337 - reg_offset = 2; 338 - /* 83932 is 0x0004, 83934 is 0x0100 or 0x0101 */ 339 - sr = sonic_read(dev, SONIC_SR); 340 - dma_bitmode = 1; 341 - 398 + sr = SONIC_READ(SONIC_SR); 399 + if (sr == 0x0004 || sr == 0x0006 || sr == 0x0100 || sr == 0x0101) 400 + /* 83932 is 0x0004 or 0x0006, 83934 is 0x0100 or 0x0101 */ 401 + lp->dma_bitmode = SONIC_BITMODE32; 402 + else { 403 + lp->dma_bitmode = SONIC_BITMODE16; 404 + lp->reg_offset = 0; 405 + sr = SONIC_READ(SONIC_SR); 342 406 } 343 - printk(KERN_INFO 344 - "%s: revision 0x%04x, using %d bit DMA and register offset %d\n", 345 - dev->name, sr, dma_bitmode?32:16, reg_offset); 407 + } else { 408 + /* All onboard cards are at offset 2 with 32 bit DMA. */ 409 + lp->reg_offset = 2; 410 + lp->dma_bitmode = SONIC_BITMODE32; 411 + sr = SONIC_READ(SONIC_SR); 346 412 } 347 - 413 + printk(KERN_INFO 414 + "%s: revision 0x%04x, using %d bit DMA and register offset %d\n", 415 + lp->device->bus_id, sr, lp->dma_bitmode?32:16, lp->reg_offset); 348 416 349 - /* this carries my sincere apologies -- by the time I got to updating 350 - the driver, support for "reg_offsets" appeares nowhere in the sonic 351 - code, going back for over a year. Fortunately, my Mac does't seem 352 - to use whatever this was. 417 + #if 0 /* This is sometimes useful to find out how MacOS configured the card. */ 418 + printk(KERN_INFO "%s: DCR: 0x%04x, DCR2: 0x%04x\n", lp->device->bus_id, 419 + SONIC_READ(SONIC_DCR) & 0xffff, SONIC_READ(SONIC_DCR2) & 0xffff); 420 + #endif 353 421 354 - If you know how this is supposed to be implemented, either fix it, 355 - or contact me (sammy@oh.verio.com) to explain what it is. --Sam */ 356 - 357 - if(reg_offset) { 358 - printk("%s: register offset unsupported. please fix this if you know what it is.\n", dev->name); 359 - return -ENODEV; 360 - } 361 - 362 422 /* Software reset, then initialize control registers. */ 363 - sonic_write(dev, SONIC_CMD, SONIC_CR_RST); 364 - sonic_write(dev, SONIC_DCR, SONIC_DCR_BMS | 365 - SONIC_DCR_RFT1 | SONIC_DCR_TFT0 | SONIC_DCR_EXBUS | 366 - (dma_bitmode ? SONIC_DCR_DW : 0)); 423 + SONIC_WRITE(SONIC_CMD, SONIC_CR_RST); 424 + 425 + SONIC_WRITE(SONIC_DCR, SONIC_DCR_EXBUS | SONIC_DCR_BMS | 426 + SONIC_DCR_RFT1 | SONIC_DCR_TFT0 | 427 + (lp->dma_bitmode ? SONIC_DCR_DW : 0)); 367 428 368 429 /* This *must* be written back to in order to restore the 369 - extended programmable output bits */ 370 - sonic_write(dev, SONIC_DCR2, 0); 430 + * extended programmable output bits, as it may not have been 431 + * initialised since the hardware reset. */ 432 + SONIC_WRITE(SONIC_DCR2, 0); 371 433 372 434 /* Clear *and* disable interrupts to be on the safe side */ 373 - sonic_write(dev, SONIC_ISR,0x7fff); 374 - sonic_write(dev, SONIC_IMR,0); 435 + SONIC_WRITE(SONIC_IMR, 0); 436 + SONIC_WRITE(SONIC_ISR, 0x7fff); 375 437 376 438 /* Now look for the MAC address. */ 377 439 if (mac_onboard_sonic_ethernet_addr(dev) != 0) 378 440 return -ENODEV; 379 - 380 - printk(KERN_INFO "MAC "); 381 - for (i = 0; i < 6; i++) { 382 - printk("%2.2x", dev->dev_addr[i]); 383 - if (i < 5) 384 - printk(":"); 385 - } 386 - 387 - printk(" IRQ %d\n", dev->irq); 388 441 389 442 /* Shared init code */ 390 443 return macsonic_init(dev); ··· 379 468 int i; 380 469 for(i = 0; i < 6; i++) 381 470 dev->dev_addr[i] = SONIC_READ_PROM(i); 382 - /* For now we are going to assume that they're all bit-reversed */ 383 - bit_reverse_addr(dev->dev_addr); 471 + 472 + /* Some of the addresses are bit-reversed */ 473 + if (id != MACSONIC_DAYNA) 474 + bit_reverse_addr(dev->dev_addr); 384 475 385 476 return 0; 386 477 } ··· 400 487 else 401 488 return MACSONIC_APPLE; 402 489 } 490 + 491 + if (ndev->dr_hw == NUBUS_DRHW_SMC9194 && 492 + ndev->dr_sw == NUBUS_DRSW_DAYNA) 493 + return MACSONIC_DAYNA; 494 + 495 + if (ndev->dr_hw == NUBUS_DRHW_SONIC_LC && 496 + ndev->dr_sw == 0) { /* huh? */ 497 + return MACSONIC_APPLE16; 498 + } 403 499 return -1; 404 500 } 405 501 ··· 416 494 { 417 495 static int slots; 418 496 struct nubus_dev* ndev = NULL; 497 + struct sonic_local* lp = netdev_priv(dev); 419 498 unsigned long base_addr, prom_addr; 420 499 u16 sonic_dcr; 421 - int id; 422 - int i; 423 - int dma_bitmode; 424 - 500 + int id = -1; 501 + int reg_offset, dma_bitmode; 502 + 425 503 /* Find the first SONIC that hasn't been initialized already */ 426 504 while ((ndev = nubus_find_type(NUBUS_CAT_NETWORK, 427 505 NUBUS_TYPE_ETHERNET, ndev)) != NULL) ··· 443 521 case MACSONIC_DUODOCK: 444 522 base_addr = ndev->board->slot_addr + DUODOCK_SONIC_REGISTERS; 445 523 prom_addr = ndev->board->slot_addr + DUODOCK_SONIC_PROM_BASE; 446 - sonic_dcr = SONIC_DCR_EXBUS | SONIC_DCR_RFT0 | SONIC_DCR_RFT1 447 - | SONIC_DCR_TFT0; 524 + sonic_dcr = SONIC_DCR_EXBUS | SONIC_DCR_RFT0 | SONIC_DCR_RFT1 | 525 + SONIC_DCR_TFT0; 448 526 reg_offset = 2; 449 - dma_bitmode = 1; 527 + dma_bitmode = SONIC_BITMODE32; 450 528 break; 451 529 case MACSONIC_APPLE: 452 530 base_addr = ndev->board->slot_addr + APPLE_SONIC_REGISTERS; 453 531 prom_addr = ndev->board->slot_addr + APPLE_SONIC_PROM_BASE; 454 532 sonic_dcr = SONIC_DCR_BMS | SONIC_DCR_RFT1 | SONIC_DCR_TFT0; 455 533 reg_offset = 0; 456 - dma_bitmode = 1; 534 + dma_bitmode = SONIC_BITMODE32; 457 535 break; 458 536 case MACSONIC_APPLE16: 459 537 base_addr = ndev->board->slot_addr + APPLE_SONIC_REGISTERS; 460 538 prom_addr = ndev->board->slot_addr + APPLE_SONIC_PROM_BASE; 461 - sonic_dcr = SONIC_DCR_EXBUS 462 - | SONIC_DCR_RFT1 | SONIC_DCR_TFT0 463 - | SONIC_DCR_PO1 | SONIC_DCR_BMS; 539 + sonic_dcr = SONIC_DCR_EXBUS | SONIC_DCR_RFT1 | SONIC_DCR_TFT0 | 540 + SONIC_DCR_PO1 | SONIC_DCR_BMS; 464 541 reg_offset = 0; 465 - dma_bitmode = 0; 542 + dma_bitmode = SONIC_BITMODE16; 466 543 break; 467 544 case MACSONIC_DAYNALINK: 468 545 base_addr = ndev->board->slot_addr + APPLE_SONIC_REGISTERS; 469 546 prom_addr = ndev->board->slot_addr + DAYNALINK_PROM_BASE; 470 - sonic_dcr = SONIC_DCR_RFT1 | SONIC_DCR_TFT0 471 - | SONIC_DCR_PO1 | SONIC_DCR_BMS; 547 + sonic_dcr = SONIC_DCR_RFT1 | SONIC_DCR_TFT0 | 548 + SONIC_DCR_PO1 | SONIC_DCR_BMS; 472 549 reg_offset = 0; 473 - dma_bitmode = 0; 550 + dma_bitmode = SONIC_BITMODE16; 474 551 break; 475 552 case MACSONIC_DAYNA: 476 553 base_addr = ndev->board->slot_addr + DAYNA_SONIC_REGISTERS; 477 554 prom_addr = ndev->board->slot_addr + DAYNA_SONIC_MAC_ADDR; 478 - sonic_dcr = SONIC_DCR_BMS 479 - | SONIC_DCR_RFT1 | SONIC_DCR_TFT0 | SONIC_DCR_PO1; 555 + sonic_dcr = SONIC_DCR_BMS | 556 + SONIC_DCR_RFT1 | SONIC_DCR_TFT0 | SONIC_DCR_PO1; 480 557 reg_offset = 0; 481 - dma_bitmode = 0; 558 + dma_bitmode = SONIC_BITMODE16; 482 559 break; 483 560 default: 484 561 printk(KERN_ERR "macsonic: WTF, id is %d\n", id); 485 562 return -ENODEV; 486 563 } 487 564 488 - /* Danger! My arms are flailing wildly! You *must* set this 489 - before using sonic_read() */ 565 + /* Danger! My arms are flailing wildly! You *must* set lp->reg_offset 566 + * and dev->base_addr before using SONIC_READ() or SONIC_WRITE() */ 490 567 dev->base_addr = base_addr; 568 + lp->reg_offset = reg_offset; 569 + lp->dma_bitmode = dma_bitmode; 491 570 dev->irq = SLOT2IRQ(ndev->board->slot); 492 571 493 572 if (!sonic_version_printed) { ··· 496 573 sonic_version_printed = 1; 497 574 } 498 575 printk(KERN_INFO "%s: %s in slot %X\n", 499 - dev->name, ndev->board->name, ndev->board->slot); 576 + lp->device->bus_id, ndev->board->name, ndev->board->slot); 500 577 printk(KERN_INFO "%s: revision 0x%04x, using %d bit DMA and register offset %d\n", 501 - dev->name, sonic_read(dev, SONIC_SR), dma_bitmode?32:16, reg_offset); 578 + lp->device->bus_id, SONIC_READ(SONIC_SR), dma_bitmode?32:16, reg_offset); 502 579 503 - if(reg_offset) { 504 - printk("%s: register offset unsupported. please fix this if you know what it is.\n", dev->name); 505 - return -ENODEV; 506 - } 580 + #if 0 /* This is sometimes useful to find out how MacOS configured the card. */ 581 + printk(KERN_INFO "%s: DCR: 0x%04x, DCR2: 0x%04x\n", lp->device->bus_id, 582 + SONIC_READ(SONIC_DCR) & 0xffff, SONIC_READ(SONIC_DCR2) & 0xffff); 583 + #endif 507 584 508 585 /* Software reset, then initialize control registers. */ 509 - sonic_write(dev, SONIC_CMD, SONIC_CR_RST); 510 - sonic_write(dev, SONIC_DCR, sonic_dcr 511 - | (dma_bitmode ? SONIC_DCR_DW : 0)); 586 + SONIC_WRITE(SONIC_CMD, SONIC_CR_RST); 587 + SONIC_WRITE(SONIC_DCR, sonic_dcr | (dma_bitmode ? SONIC_DCR_DW : 0)); 588 + /* This *must* be written back to in order to restore the 589 + * extended programmable output bits, since it may not have been 590 + * initialised since the hardware reset. */ 591 + SONIC_WRITE(SONIC_DCR2, 0); 512 592 513 593 /* Clear *and* disable interrupts to be on the safe side */ 514 - sonic_write(dev, SONIC_ISR,0x7fff); 515 - sonic_write(dev, SONIC_IMR,0); 594 + SONIC_WRITE(SONIC_IMR, 0); 595 + SONIC_WRITE(SONIC_ISR, 0x7fff); 516 596 517 597 /* Now look for the MAC address. */ 518 598 if (mac_nubus_sonic_ethernet_addr(dev, prom_addr, id) != 0) 519 599 return -ENODEV; 520 600 521 - printk(KERN_INFO "MAC "); 601 + /* Shared init code */ 602 + return macsonic_init(dev); 603 + } 604 + 605 + static int __init mac_sonic_probe(struct device *device) 606 + { 607 + struct net_device *dev; 608 + struct sonic_local *lp; 609 + int err; 610 + int i; 611 + 612 + dev = alloc_etherdev(sizeof(struct sonic_local)); 613 + if (!dev) 614 + return -ENOMEM; 615 + 616 + lp = netdev_priv(dev); 617 + lp->device = device; 618 + SET_NETDEV_DEV(dev, device); 619 + SET_MODULE_OWNER(dev); 620 + 621 + /* This will catch fatal stuff like -ENOMEM as well as success */ 622 + err = mac_onboard_sonic_probe(dev); 623 + if (err == 0) 624 + goto found; 625 + if (err != -ENODEV) 626 + goto out; 627 + err = mac_nubus_sonic_probe(dev); 628 + if (err) 629 + goto out; 630 + found: 631 + err = register_netdev(dev); 632 + if (err) 633 + goto out; 634 + 635 + printk("%s: MAC ", dev->name); 522 636 for (i = 0; i < 6; i++) { 523 637 printk("%2.2x", dev->dev_addr[i]); 524 638 if (i < 5) ··· 563 603 } 564 604 printk(" IRQ %d\n", dev->irq); 565 605 566 - /* Shared init code */ 567 - return macsonic_init(dev); 606 + return 0; 607 + 608 + out: 609 + free_netdev(dev); 610 + 611 + return err; 568 612 } 569 613 570 - #ifdef MODULE 571 - static struct net_device *dev_macsonic; 572 - 573 - MODULE_PARM(sonic_debug, "i"); 614 + MODULE_DESCRIPTION("Macintosh SONIC ethernet driver"); 615 + module_param(sonic_debug, int, 0); 574 616 MODULE_PARM_DESC(sonic_debug, "macsonic debug level (1-4)"); 575 617 576 - int 577 - init_module(void) 578 - { 579 - dev_macsonic = macsonic_probe(-1); 580 - if (IS_ERR(dev_macsonic)) { 581 - printk(KERN_WARNING "macsonic.c: No card found\n"); 582 - return PTR_ERR(dev_macsonic); 583 - } 584 - return 0; 585 - } 586 - 587 - void 588 - cleanup_module(void) 589 - { 590 - unregister_netdev(dev_macsonic); 591 - kfree(dev_macsonic->priv); 592 - free_netdev(dev_macsonic); 593 - } 594 - #endif /* MODULE */ 595 - 596 - 597 - #define vdma_alloc(foo, bar) ((u32)foo) 598 - #define vdma_free(baz) 599 - #define sonic_chiptomem(bat) (bat) 600 - #define PHYSADDR(quux) (quux) 601 - #define CPHYSADDR(quux) (quux) 602 - 603 - #define sonic_request_irq request_irq 604 - #define sonic_free_irq free_irq 618 + #define SONIC_IRQ_FLAG IRQ_FLG_FAST 605 619 606 620 #include "sonic.c" 607 621 608 - /* 609 - * Local variables: 610 - * compile-command: "m68k-linux-gcc -D__KERNEL__ -I../../include -Wall -Wstrict-prototypes -O2 -fomit-frame-pointer -pipe -fno-strength-reduce -ffixed-a2 -DMODULE -DMODVERSIONS -include ../../include/linux/modversions.h -c -o macsonic.o macsonic.c" 611 - * version-control: t 612 - * kept-new-versions: 5 613 - * c-indent-level: 8 614 - * tab-width: 8 615 - * End: 616 - * 617 - */ 622 + static int __devexit mac_sonic_device_remove (struct device *device) 623 + { 624 + struct net_device *dev = device->driver_data; 625 + struct sonic_local* lp = netdev_priv(dev); 626 + 627 + unregister_netdev (dev); 628 + dma_free_coherent(lp->device, SIZEOF_SONIC_DESC * SONIC_BUS_SCALE(lp->dma_bitmode), 629 + lp->descriptors, lp->descriptors_laddr); 630 + free_netdev (dev); 631 + 632 + return 0; 633 + } 634 + 635 + static struct device_driver mac_sonic_driver = { 636 + .name = mac_sonic_string, 637 + .bus = &platform_bus_type, 638 + .probe = mac_sonic_probe, 639 + .remove = __devexit_p(mac_sonic_device_remove), 640 + }; 641 + 642 + static void mac_sonic_platform_release(struct device *device) 643 + { 644 + struct platform_device *pldev; 645 + 646 + /* free device */ 647 + pldev = to_platform_device (device); 648 + kfree (pldev); 649 + } 650 + 651 + static int __init mac_sonic_init_module(void) 652 + { 653 + struct platform_device *pldev; 654 + int err; 655 + 656 + if ((err = driver_register(&mac_sonic_driver))) { 657 + printk(KERN_ERR "Driver registration failed\n"); 658 + return err; 659 + } 660 + 661 + mac_sonic_device = NULL; 662 + 663 + if (!(pldev = kmalloc (sizeof (*pldev), GFP_KERNEL))) { 664 + goto out_unregister; 665 + } 666 + 667 + memset(pldev, 0, sizeof (*pldev)); 668 + pldev->name = mac_sonic_string; 669 + pldev->id = 0; 670 + pldev->dev.release = mac_sonic_platform_release; 671 + mac_sonic_device = pldev; 672 + 673 + if (platform_device_register (pldev)) { 674 + kfree(pldev); 675 + mac_sonic_device = NULL; 676 + } 677 + 678 + return 0; 679 + 680 + out_unregister: 681 + platform_device_unregister(pldev); 682 + 683 + return -ENOMEM; 684 + } 685 + 686 + static void __exit mac_sonic_cleanup_module(void) 687 + { 688 + driver_unregister(&mac_sonic_driver); 689 + 690 + if (mac_sonic_device) { 691 + platform_device_unregister(mac_sonic_device); 692 + mac_sonic_device = NULL; 693 + } 694 + } 695 + 696 + module_init(mac_sonic_init_module); 697 + module_exit(mac_sonic_cleanup_module);
+411 -257
drivers/net/sonic.c
··· 1 1 /* 2 2 * sonic.c 3 3 * 4 + * (C) 2005 Finn Thain 5 + * 6 + * Converted to DMA API, added zero-copy buffer handling, and 7 + * (from the mac68k project) introduced dhd's support for 16-bit cards. 8 + * 4 9 * (C) 1996,1998 by Thomas Bogendoerfer (tsbogend@alpha.franken.de) 5 10 * 6 11 * This driver is based on work from Andreas Busse, but most of ··· 14 9 * (C) 1995 by Andreas Busse (andy@waldorf-gmbh.de) 15 10 * 16 11 * Core code included by system sonic drivers 12 + * 13 + * And... partially rewritten again by David Huggins-Daines in order 14 + * to cope with screwed up Macintosh NICs that may or may not use 15 + * 16-bit DMA. 16 + * 17 + * (C) 1999 David Huggins-Daines <dhd@debian.org> 18 + * 17 19 */ 18 20 19 21 /* 20 22 * Sources: Olivetti M700-10 Risc Personal Computer hardware handbook, 21 23 * National Semiconductors data sheet for the DP83932B Sonic Ethernet 22 24 * controller, and the files "8390.c" and "skeleton.c" in this directory. 25 + * 26 + * Additional sources: Nat Semi data sheet for the DP83932C and Nat Semi 27 + * Application Note AN-746, the files "lance.c" and "ibmlana.c". See also 28 + * the NetBSD file "sys/arch/mac68k/dev/if_sn.c". 23 29 */ 24 30 25 31 ··· 44 28 */ 45 29 static int sonic_open(struct net_device *dev) 46 30 { 31 + struct sonic_local *lp = netdev_priv(dev); 32 + int i; 33 + 47 34 if (sonic_debug > 2) 48 35 printk("sonic_open: initializing sonic driver.\n"); 49 36 ··· 59 40 * This means that during execution of the handler interrupt are disabled 60 41 * covering another bug otherwise corrupting data. This doesn't mean 61 42 * this glue works ok under all situations. 43 + * 44 + * Note (dhd): this also appears to prevent lockups on the Macintrash 45 + * when more than one Ethernet card is installed (knock on wood) 46 + * 47 + * Note (fthain): whether the above is still true is anyones guess. Certainly 48 + * the buffer handling algorithms will not tolerate re-entrance without some 49 + * mutual exclusion added. Anyway, the memcpy has now been eliminated from the 50 + * rx code to make this a faster "fast interrupt". 62 51 */ 63 - // if (sonic_request_irq(dev->irq, &sonic_interrupt, 0, "sonic", dev)) { 64 - if (sonic_request_irq(dev->irq, &sonic_interrupt, SA_INTERRUPT, 65 - "sonic", dev)) { 66 - printk("\n%s: unable to get IRQ %d .\n", dev->name, dev->irq); 52 + if (request_irq(dev->irq, &sonic_interrupt, SONIC_IRQ_FLAG, "sonic", dev)) { 53 + printk(KERN_ERR "\n%s: unable to get IRQ %d .\n", dev->name, dev->irq); 67 54 return -EAGAIN; 55 + } 56 + 57 + for (i = 0; i < SONIC_NUM_RRS; i++) { 58 + struct sk_buff *skb = dev_alloc_skb(SONIC_RBSIZE + 2); 59 + if (skb == NULL) { 60 + while(i > 0) { /* free any that were allocated successfully */ 61 + i--; 62 + dev_kfree_skb(lp->rx_skb[i]); 63 + lp->rx_skb[i] = NULL; 64 + } 65 + printk(KERN_ERR "%s: couldn't allocate receive buffers\n", 66 + dev->name); 67 + return -ENOMEM; 68 + } 69 + skb->dev = dev; 70 + /* align IP header unless DMA requires otherwise */ 71 + if (SONIC_BUS_SCALE(lp->dma_bitmode) == 2) 72 + skb_reserve(skb, 2); 73 + lp->rx_skb[i] = skb; 74 + } 75 + 76 + for (i = 0; i < SONIC_NUM_RRS; i++) { 77 + dma_addr_t laddr = dma_map_single(lp->device, skb_put(lp->rx_skb[i], SONIC_RBSIZE), 78 + SONIC_RBSIZE, DMA_FROM_DEVICE); 79 + if (!laddr) { 80 + while(i > 0) { /* free any that were mapped successfully */ 81 + i--; 82 + dma_unmap_single(lp->device, lp->rx_laddr[i], SONIC_RBSIZE, DMA_FROM_DEVICE); 83 + lp->rx_laddr[i] = (dma_addr_t)0; 84 + } 85 + for (i = 0; i < SONIC_NUM_RRS; i++) { 86 + dev_kfree_skb(lp->rx_skb[i]); 87 + lp->rx_skb[i] = NULL; 88 + } 89 + printk(KERN_ERR "%s: couldn't map rx DMA buffers\n", 90 + dev->name); 91 + return -ENOMEM; 92 + } 93 + lp->rx_laddr[i] = laddr; 68 94 } 69 95 70 96 /* ··· 131 67 */ 132 68 static int sonic_close(struct net_device *dev) 133 69 { 134 - unsigned int base_addr = dev->base_addr; 70 + struct sonic_local *lp = netdev_priv(dev); 71 + int i; 135 72 136 73 if (sonic_debug > 2) 137 74 printk("sonic_close\n"); ··· 142 77 /* 143 78 * stop the SONIC, disable interrupts 144 79 */ 145 - SONIC_WRITE(SONIC_ISR, 0x7fff); 146 80 SONIC_WRITE(SONIC_IMR, 0); 81 + SONIC_WRITE(SONIC_ISR, 0x7fff); 147 82 SONIC_WRITE(SONIC_CMD, SONIC_CR_RST); 148 83 149 - sonic_free_irq(dev->irq, dev); /* release the IRQ */ 84 + /* unmap and free skbs that haven't been transmitted */ 85 + for (i = 0; i < SONIC_NUM_TDS; i++) { 86 + if(lp->tx_laddr[i]) { 87 + dma_unmap_single(lp->device, lp->tx_laddr[i], lp->tx_len[i], DMA_TO_DEVICE); 88 + lp->tx_laddr[i] = (dma_addr_t)0; 89 + } 90 + if(lp->tx_skb[i]) { 91 + dev_kfree_skb(lp->tx_skb[i]); 92 + lp->tx_skb[i] = NULL; 93 + } 94 + } 95 + 96 + /* unmap and free the receive buffers */ 97 + for (i = 0; i < SONIC_NUM_RRS; i++) { 98 + if(lp->rx_laddr[i]) { 99 + dma_unmap_single(lp->device, lp->rx_laddr[i], SONIC_RBSIZE, DMA_FROM_DEVICE); 100 + lp->rx_laddr[i] = (dma_addr_t)0; 101 + } 102 + if(lp->rx_skb[i]) { 103 + dev_kfree_skb(lp->rx_skb[i]); 104 + lp->rx_skb[i] = NULL; 105 + } 106 + } 107 + 108 + free_irq(dev->irq, dev); /* release the IRQ */ 150 109 151 110 return 0; 152 111 } 153 112 154 113 static void sonic_tx_timeout(struct net_device *dev) 155 114 { 156 - struct sonic_local *lp = (struct sonic_local *) dev->priv; 157 - printk("%s: transmit timed out.\n", dev->name); 158 - 115 + struct sonic_local *lp = netdev_priv(dev); 116 + int i; 117 + /* Stop the interrupts for this */ 118 + SONIC_WRITE(SONIC_IMR, 0); 119 + /* We could resend the original skbs. Easier to re-initialise. */ 120 + for (i = 0; i < SONIC_NUM_TDS; i++) { 121 + if(lp->tx_laddr[i]) { 122 + dma_unmap_single(lp->device, lp->tx_laddr[i], lp->tx_len[i], DMA_TO_DEVICE); 123 + lp->tx_laddr[i] = (dma_addr_t)0; 124 + } 125 + if(lp->tx_skb[i]) { 126 + dev_kfree_skb(lp->tx_skb[i]); 127 + lp->tx_skb[i] = NULL; 128 + } 129 + } 159 130 /* Try to restart the adaptor. */ 160 131 sonic_init(dev); 161 132 lp->stats.tx_errors++; ··· 201 100 202 101 /* 203 102 * transmit packet 103 + * 104 + * Appends new TD during transmission thus avoiding any TX interrupts 105 + * until we run out of TDs. 106 + * This routine interacts closely with the ISR in that it may, 107 + * set tx_skb[i] 108 + * reset the status flags of the new TD 109 + * set and reset EOL flags 110 + * stop the tx queue 111 + * The ISR interacts with this routine in various ways. It may, 112 + * reset tx_skb[i] 113 + * test the EOL and status flags of the TDs 114 + * wake the tx queue 115 + * Concurrently with all of this, the SONIC is potentially writing to 116 + * the status flags of the TDs. 117 + * Until some mutual exclusion is added, this code will not work with SMP. However, 118 + * MIPS Jazz machines and m68k Macs were all uni-processor machines. 204 119 */ 120 + 205 121 static int sonic_send_packet(struct sk_buff *skb, struct net_device *dev) 206 122 { 207 - struct sonic_local *lp = (struct sonic_local *) dev->priv; 208 - unsigned int base_addr = dev->base_addr; 209 - unsigned int laddr; 210 - int entry, length; 211 - 212 - netif_stop_queue(dev); 123 + struct sonic_local *lp = netdev_priv(dev); 124 + dma_addr_t laddr; 125 + int length; 126 + int entry = lp->next_tx; 213 127 214 128 if (sonic_debug > 2) 215 129 printk("sonic_send_packet: skb=%p, dev=%p\n", skb, dev); 216 130 131 + length = skb->len; 132 + if (length < ETH_ZLEN) { 133 + skb = skb_padto(skb, ETH_ZLEN); 134 + if (skb == NULL) 135 + return 0; 136 + length = ETH_ZLEN; 137 + } 138 + 217 139 /* 218 140 * Map the packet data into the logical DMA address space 219 141 */ 220 - if ((laddr = vdma_alloc(CPHYSADDR(skb->data), skb->len)) == ~0UL) { 221 - printk("%s: no VDMA entry for transmit available.\n", 222 - dev->name); 142 + 143 + laddr = dma_map_single(lp->device, skb->data, length, DMA_TO_DEVICE); 144 + if (!laddr) { 145 + printk(KERN_ERR "%s: failed to map tx DMA buffer.\n", dev->name); 223 146 dev_kfree_skb(skb); 224 - netif_start_queue(dev); 225 147 return 1; 226 148 } 227 - entry = lp->cur_tx & SONIC_TDS_MASK; 149 + 150 + sonic_tda_put(dev, entry, SONIC_TD_STATUS, 0); /* clear status */ 151 + sonic_tda_put(dev, entry, SONIC_TD_FRAG_COUNT, 1); /* single fragment */ 152 + sonic_tda_put(dev, entry, SONIC_TD_PKTSIZE, length); /* length of packet */ 153 + sonic_tda_put(dev, entry, SONIC_TD_FRAG_PTR_L, laddr & 0xffff); 154 + sonic_tda_put(dev, entry, SONIC_TD_FRAG_PTR_H, laddr >> 16); 155 + sonic_tda_put(dev, entry, SONIC_TD_FRAG_SIZE, length); 156 + sonic_tda_put(dev, entry, SONIC_TD_LINK, 157 + sonic_tda_get(dev, entry, SONIC_TD_LINK) | SONIC_EOL); 158 + 159 + /* 160 + * Must set tx_skb[entry] only after clearing status, and 161 + * before clearing EOL and before stopping queue 162 + */ 163 + wmb(); 164 + lp->tx_len[entry] = length; 228 165 lp->tx_laddr[entry] = laddr; 229 166 lp->tx_skb[entry] = skb; 230 167 231 - length = (skb->len < ETH_ZLEN) ? ETH_ZLEN : skb->len; 232 - flush_cache_all(); 168 + wmb(); 169 + sonic_tda_put(dev, lp->eol_tx, SONIC_TD_LINK, 170 + sonic_tda_get(dev, lp->eol_tx, SONIC_TD_LINK) & ~SONIC_EOL); 171 + lp->eol_tx = entry; 233 172 234 - /* 235 - * Setup the transmit descriptor and issue the transmit command. 236 - */ 237 - lp->tda[entry].tx_status = 0; /* clear status */ 238 - lp->tda[entry].tx_frag_count = 1; /* single fragment */ 239 - lp->tda[entry].tx_pktsize = length; /* length of packet */ 240 - lp->tda[entry].tx_frag_ptr_l = laddr & 0xffff; 241 - lp->tda[entry].tx_frag_ptr_h = laddr >> 16; 242 - lp->tda[entry].tx_frag_size = length; 243 - lp->cur_tx++; 244 - lp->stats.tx_bytes += length; 173 + lp->next_tx = (entry + 1) & SONIC_TDS_MASK; 174 + if (lp->tx_skb[lp->next_tx] != NULL) { 175 + /* The ring is full, the ISR has yet to process the next TD. */ 176 + if (sonic_debug > 3) 177 + printk("%s: stopping queue\n", dev->name); 178 + netif_stop_queue(dev); 179 + /* after this packet, wait for ISR to free up some TDAs */ 180 + } else netif_start_queue(dev); 245 181 246 182 if (sonic_debug > 2) 247 - printk("sonic_send_packet: issueing Tx command\n"); 183 + printk("sonic_send_packet: issuing Tx command\n"); 248 184 249 185 SONIC_WRITE(SONIC_CMD, SONIC_CR_TXP); 250 186 251 187 dev->trans_start = jiffies; 252 - 253 - if (lp->cur_tx < lp->dirty_tx + SONIC_NUM_TDS) 254 - netif_start_queue(dev); 255 - else 256 - lp->tx_full = 1; 257 188 258 189 return 0; 259 190 } ··· 297 164 static irqreturn_t sonic_interrupt(int irq, void *dev_id, struct pt_regs *regs) 298 165 { 299 166 struct net_device *dev = (struct net_device *) dev_id; 300 - unsigned int base_addr = dev->base_addr; 301 - struct sonic_local *lp; 167 + struct sonic_local *lp = netdev_priv(dev); 302 168 int status; 303 169 304 170 if (dev == NULL) { 305 - printk("sonic_interrupt: irq %d for unknown device.\n", irq); 171 + printk(KERN_ERR "sonic_interrupt: irq %d for unknown device.\n", irq); 306 172 return IRQ_NONE; 307 173 } 308 174 309 - lp = (struct sonic_local *) dev->priv; 175 + if (!(status = SONIC_READ(SONIC_ISR) & SONIC_IMR_DEFAULT)) 176 + return IRQ_NONE; 310 177 311 - status = SONIC_READ(SONIC_ISR); 312 - SONIC_WRITE(SONIC_ISR, 0x7fff); /* clear all bits */ 178 + do { 179 + if (status & SONIC_INT_PKTRX) { 180 + if (sonic_debug > 2) 181 + printk("%s: packet rx\n", dev->name); 182 + sonic_rx(dev); /* got packet(s) */ 183 + SONIC_WRITE(SONIC_ISR, SONIC_INT_PKTRX); /* clear the interrupt */ 184 + } 313 185 314 - if (sonic_debug > 2) 315 - printk("sonic_interrupt: ISR=%x\n", status); 186 + if (status & SONIC_INT_TXDN) { 187 + int entry = lp->cur_tx; 188 + int td_status; 189 + int freed_some = 0; 316 190 317 - if (status & SONIC_INT_PKTRX) { 318 - sonic_rx(dev); /* got packet(s) */ 319 - } 191 + /* At this point, cur_tx is the index of a TD that is one of: 192 + * unallocated/freed (status set & tx_skb[entry] clear) 193 + * allocated and sent (status set & tx_skb[entry] set ) 194 + * allocated and not yet sent (status clear & tx_skb[entry] set ) 195 + * still being allocated by sonic_send_packet (status clear & tx_skb[entry] clear) 196 + */ 320 197 321 - if (status & SONIC_INT_TXDN) { 322 - int dirty_tx = lp->dirty_tx; 198 + if (sonic_debug > 2) 199 + printk("%s: tx done\n", dev->name); 323 200 324 - while (dirty_tx < lp->cur_tx) { 325 - int entry = dirty_tx & SONIC_TDS_MASK; 326 - int status = lp->tda[entry].tx_status; 201 + while (lp->tx_skb[entry] != NULL) { 202 + if ((td_status = sonic_tda_get(dev, entry, SONIC_TD_STATUS)) == 0) 203 + break; 327 204 328 - if (sonic_debug > 3) 329 - printk 330 - ("sonic_interrupt: status %d, cur_tx %d, dirty_tx %d\n", 331 - status, lp->cur_tx, lp->dirty_tx); 205 + if (td_status & 0x0001) { 206 + lp->stats.tx_packets++; 207 + lp->stats.tx_bytes += sonic_tda_get(dev, entry, SONIC_TD_PKTSIZE); 208 + } else { 209 + lp->stats.tx_errors++; 210 + if (td_status & 0x0642) 211 + lp->stats.tx_aborted_errors++; 212 + if (td_status & 0x0180) 213 + lp->stats.tx_carrier_errors++; 214 + if (td_status & 0x0020) 215 + lp->stats.tx_window_errors++; 216 + if (td_status & 0x0004) 217 + lp->stats.tx_fifo_errors++; 218 + } 332 219 333 - if (status == 0) { 334 - /* It still hasn't been Txed, kick the sonic again */ 335 - SONIC_WRITE(SONIC_CMD, SONIC_CR_TXP); 336 - break; 337 - } 338 - 339 - /* put back EOL and free descriptor */ 340 - lp->tda[entry].tx_frag_count = 0; 341 - lp->tda[entry].tx_status = 0; 342 - 343 - if (status & 0x0001) 344 - lp->stats.tx_packets++; 345 - else { 346 - lp->stats.tx_errors++; 347 - if (status & 0x0642) 348 - lp->stats.tx_aborted_errors++; 349 - if (status & 0x0180) 350 - lp->stats.tx_carrier_errors++; 351 - if (status & 0x0020) 352 - lp->stats.tx_window_errors++; 353 - if (status & 0x0004) 354 - lp->stats.tx_fifo_errors++; 355 - } 356 - 357 - /* We must free the original skb */ 358 - if (lp->tx_skb[entry]) { 220 + /* We must free the original skb */ 359 221 dev_kfree_skb_irq(lp->tx_skb[entry]); 360 - lp->tx_skb[entry] = 0; 222 + lp->tx_skb[entry] = NULL; 223 + /* and unmap DMA buffer */ 224 + dma_unmap_single(lp->device, lp->tx_laddr[entry], lp->tx_len[entry], DMA_TO_DEVICE); 225 + lp->tx_laddr[entry] = (dma_addr_t)0; 226 + freed_some = 1; 227 + 228 + if (sonic_tda_get(dev, entry, SONIC_TD_LINK) & SONIC_EOL) { 229 + entry = (entry + 1) & SONIC_TDS_MASK; 230 + break; 231 + } 232 + entry = (entry + 1) & SONIC_TDS_MASK; 361 233 } 362 - /* and the VDMA address */ 363 - vdma_free(lp->tx_laddr[entry]); 364 - dirty_tx++; 234 + 235 + if (freed_some || lp->tx_skb[entry] == NULL) 236 + netif_wake_queue(dev); /* The ring is no longer full */ 237 + lp->cur_tx = entry; 238 + SONIC_WRITE(SONIC_ISR, SONIC_INT_TXDN); /* clear the interrupt */ 365 239 } 366 240 367 - if (lp->tx_full 368 - && dirty_tx + SONIC_NUM_TDS > lp->cur_tx + 2) { 369 - /* The ring is no longer full, clear tbusy. */ 370 - lp->tx_full = 0; 371 - netif_wake_queue(dev); 241 + /* 242 + * check error conditions 243 + */ 244 + if (status & SONIC_INT_RFO) { 245 + if (sonic_debug > 1) 246 + printk("%s: rx fifo overrun\n", dev->name); 247 + lp->stats.rx_fifo_errors++; 248 + SONIC_WRITE(SONIC_ISR, SONIC_INT_RFO); /* clear the interrupt */ 249 + } 250 + if (status & SONIC_INT_RDE) { 251 + if (sonic_debug > 1) 252 + printk("%s: rx descriptors exhausted\n", dev->name); 253 + lp->stats.rx_dropped++; 254 + SONIC_WRITE(SONIC_ISR, SONIC_INT_RDE); /* clear the interrupt */ 255 + } 256 + if (status & SONIC_INT_RBAE) { 257 + if (sonic_debug > 1) 258 + printk("%s: rx buffer area exceeded\n", dev->name); 259 + lp->stats.rx_dropped++; 260 + SONIC_WRITE(SONIC_ISR, SONIC_INT_RBAE); /* clear the interrupt */ 372 261 } 373 262 374 - lp->dirty_tx = dirty_tx; 375 - } 263 + /* counter overruns; all counters are 16bit wide */ 264 + if (status & SONIC_INT_FAE) { 265 + lp->stats.rx_frame_errors += 65536; 266 + SONIC_WRITE(SONIC_ISR, SONIC_INT_FAE); /* clear the interrupt */ 267 + } 268 + if (status & SONIC_INT_CRC) { 269 + lp->stats.rx_crc_errors += 65536; 270 + SONIC_WRITE(SONIC_ISR, SONIC_INT_CRC); /* clear the interrupt */ 271 + } 272 + if (status & SONIC_INT_MP) { 273 + lp->stats.rx_missed_errors += 65536; 274 + SONIC_WRITE(SONIC_ISR, SONIC_INT_MP); /* clear the interrupt */ 275 + } 376 276 377 - /* 378 - * check error conditions 379 - */ 380 - if (status & SONIC_INT_RFO) { 381 - printk("%s: receive fifo underrun\n", dev->name); 382 - lp->stats.rx_fifo_errors++; 383 - } 384 - if (status & SONIC_INT_RDE) { 385 - printk("%s: receive descriptors exhausted\n", dev->name); 386 - lp->stats.rx_dropped++; 387 - } 388 - if (status & SONIC_INT_RBE) { 389 - printk("%s: receive buffer exhausted\n", dev->name); 390 - lp->stats.rx_dropped++; 391 - } 392 - if (status & SONIC_INT_RBAE) { 393 - printk("%s: receive buffer area exhausted\n", dev->name); 394 - lp->stats.rx_dropped++; 395 - } 277 + /* transmit error */ 278 + if (status & SONIC_INT_TXER) { 279 + if ((SONIC_READ(SONIC_TCR) & SONIC_TCR_FU) && (sonic_debug > 2)) 280 + printk(KERN_ERR "%s: tx fifo underrun\n", dev->name); 281 + SONIC_WRITE(SONIC_ISR, SONIC_INT_TXER); /* clear the interrupt */ 282 + } 396 283 397 - /* counter overruns; all counters are 16bit wide */ 398 - if (status & SONIC_INT_FAE) 399 - lp->stats.rx_frame_errors += 65536; 400 - if (status & SONIC_INT_CRC) 401 - lp->stats.rx_crc_errors += 65536; 402 - if (status & SONIC_INT_MP) 403 - lp->stats.rx_missed_errors += 65536; 284 + /* bus retry */ 285 + if (status & SONIC_INT_BR) { 286 + printk(KERN_ERR "%s: Bus retry occurred! Device interrupt disabled.\n", 287 + dev->name); 288 + /* ... to help debug DMA problems causing endless interrupts. */ 289 + /* Bounce the eth interface to turn on the interrupt again. */ 290 + SONIC_WRITE(SONIC_IMR, 0); 291 + SONIC_WRITE(SONIC_ISR, SONIC_INT_BR); /* clear the interrupt */ 292 + } 404 293 405 - /* transmit error */ 406 - if (status & SONIC_INT_TXER) 407 - lp->stats.tx_errors++; 408 - 409 - /* 410 - * clear interrupt bits and return 411 - */ 412 - SONIC_WRITE(SONIC_ISR, status); 294 + /* load CAM done */ 295 + if (status & SONIC_INT_LCD) 296 + SONIC_WRITE(SONIC_ISR, SONIC_INT_LCD); /* clear the interrupt */ 297 + } while((status = SONIC_READ(SONIC_ISR) & SONIC_IMR_DEFAULT)); 413 298 return IRQ_HANDLED; 414 299 } 415 300 416 301 /* 417 - * We have a good packet(s), get it/them out of the buffers. 302 + * We have a good packet(s), pass it/them up the network stack. 418 303 */ 419 304 static void sonic_rx(struct net_device *dev) 420 305 { 421 - unsigned int base_addr = dev->base_addr; 422 - struct sonic_local *lp = (struct sonic_local *) dev->priv; 423 - sonic_rd_t *rd = &lp->rda[lp->cur_rx & SONIC_RDS_MASK]; 306 + struct sonic_local *lp = netdev_priv(dev); 424 307 int status; 308 + int entry = lp->cur_rx; 425 309 426 - while (rd->in_use == 0) { 427 - struct sk_buff *skb; 310 + while (sonic_rda_get(dev, entry, SONIC_RD_IN_USE) == 0) { 311 + struct sk_buff *used_skb; 312 + struct sk_buff *new_skb; 313 + dma_addr_t new_laddr; 314 + u16 bufadr_l; 315 + u16 bufadr_h; 428 316 int pkt_len; 429 - unsigned char *pkt_ptr; 430 317 431 - status = rd->rx_status; 432 - if (sonic_debug > 3) 433 - printk("status %x, cur_rx %d, cur_rra %x\n", 434 - status, lp->cur_rx, lp->cur_rra); 318 + status = sonic_rda_get(dev, entry, SONIC_RD_STATUS); 435 319 if (status & SONIC_RCR_PRX) { 436 - pkt_len = rd->rx_pktlen; 437 - pkt_ptr = 438 - (char *) 439 - sonic_chiptomem((rd->rx_pktptr_h << 16) + 440 - rd->rx_pktptr_l); 441 - 442 - if (sonic_debug > 3) 443 - printk 444 - ("pktptr %p (rba %p) h:%x l:%x, bsize h:%x l:%x\n", 445 - pkt_ptr, lp->rba, rd->rx_pktptr_h, 446 - rd->rx_pktptr_l, 447 - SONIC_READ(SONIC_RBWC1), 448 - SONIC_READ(SONIC_RBWC0)); 449 - 450 320 /* Malloc up new buffer. */ 451 - skb = dev_alloc_skb(pkt_len + 2); 452 - if (skb == NULL) { 453 - printk 454 - ("%s: Memory squeeze, dropping packet.\n", 455 - dev->name); 321 + new_skb = dev_alloc_skb(SONIC_RBSIZE + 2); 322 + if (new_skb == NULL) { 323 + printk(KERN_ERR "%s: Memory squeeze, dropping packet.\n", dev->name); 456 324 lp->stats.rx_dropped++; 457 325 break; 458 326 } 459 - skb->dev = dev; 460 - skb_reserve(skb, 2); /* 16 byte align */ 461 - skb_put(skb, pkt_len); /* Make room */ 462 - eth_copy_and_sum(skb, pkt_ptr, pkt_len, 0); 463 - skb->protocol = eth_type_trans(skb, dev); 464 - netif_rx(skb); /* pass the packet to upper layers */ 327 + new_skb->dev = dev; 328 + /* provide 16 byte IP header alignment unless DMA requires otherwise */ 329 + if(SONIC_BUS_SCALE(lp->dma_bitmode) == 2) 330 + skb_reserve(new_skb, 2); 331 + 332 + new_laddr = dma_map_single(lp->device, skb_put(new_skb, SONIC_RBSIZE), 333 + SONIC_RBSIZE, DMA_FROM_DEVICE); 334 + if (!new_laddr) { 335 + dev_kfree_skb(new_skb); 336 + printk(KERN_ERR "%s: Failed to map rx buffer, dropping packet.\n", dev->name); 337 + lp->stats.rx_dropped++; 338 + break; 339 + } 340 + 341 + /* now we have a new skb to replace it, pass the used one up the stack */ 342 + dma_unmap_single(lp->device, lp->rx_laddr[entry], SONIC_RBSIZE, DMA_FROM_DEVICE); 343 + used_skb = lp->rx_skb[entry]; 344 + pkt_len = sonic_rda_get(dev, entry, SONIC_RD_PKTLEN); 345 + skb_trim(used_skb, pkt_len); 346 + used_skb->protocol = eth_type_trans(used_skb, dev); 347 + netif_rx(used_skb); 465 348 dev->last_rx = jiffies; 466 349 lp->stats.rx_packets++; 467 350 lp->stats.rx_bytes += pkt_len; 468 351 352 + /* and insert the new skb */ 353 + lp->rx_laddr[entry] = new_laddr; 354 + lp->rx_skb[entry] = new_skb; 355 + 356 + bufadr_l = (unsigned long)new_laddr & 0xffff; 357 + bufadr_h = (unsigned long)new_laddr >> 16; 358 + sonic_rra_put(dev, entry, SONIC_RR_BUFADR_L, bufadr_l); 359 + sonic_rra_put(dev, entry, SONIC_RR_BUFADR_H, bufadr_h); 469 360 } else { 470 361 /* This should only happen, if we enable accepting broken packets. */ 471 362 lp->stats.rx_errors++; ··· 498 341 if (status & SONIC_RCR_CRCR) 499 342 lp->stats.rx_crc_errors++; 500 343 } 501 - 502 - rd->in_use = 1; 503 - rd = &lp->rda[(++lp->cur_rx) & SONIC_RDS_MASK]; 504 - /* now give back the buffer to the receive buffer area */ 505 344 if (status & SONIC_RCR_LPKT) { 506 345 /* 507 - * this was the last packet out of the current receice buffer 346 + * this was the last packet out of the current receive buffer 508 347 * give the buffer back to the SONIC 509 348 */ 510 - lp->cur_rra += sizeof(sonic_rr_t); 511 - if (lp->cur_rra > 512 - (lp->rra_laddr + 513 - (SONIC_NUM_RRS - 514 - 1) * sizeof(sonic_rr_t))) lp->cur_rra = 515 - lp->rra_laddr; 516 - SONIC_WRITE(SONIC_RWP, lp->cur_rra & 0xffff); 349 + lp->cur_rwp += SIZEOF_SONIC_RR * SONIC_BUS_SCALE(lp->dma_bitmode); 350 + if (lp->cur_rwp >= lp->rra_end) lp->cur_rwp = lp->rra_laddr & 0xffff; 351 + SONIC_WRITE(SONIC_RWP, lp->cur_rwp); 352 + if (SONIC_READ(SONIC_ISR) & SONIC_INT_RBE) { 353 + if (sonic_debug > 2) 354 + printk("%s: rx buffer exhausted\n", dev->name); 355 + SONIC_WRITE(SONIC_ISR, SONIC_INT_RBE); /* clear the flag */ 356 + } 517 357 } else 518 - printk 519 - ("%s: rx desc without RCR_LPKT. Shouldn't happen !?\n", 358 + printk(KERN_ERR "%s: rx desc without RCR_LPKT. Shouldn't happen !?\n", 520 359 dev->name); 360 + /* 361 + * give back the descriptor 362 + */ 363 + sonic_rda_put(dev, entry, SONIC_RD_LINK, 364 + sonic_rda_get(dev, entry, SONIC_RD_LINK) | SONIC_EOL); 365 + sonic_rda_put(dev, entry, SONIC_RD_IN_USE, 1); 366 + sonic_rda_put(dev, lp->eol_rx, SONIC_RD_LINK, 367 + sonic_rda_get(dev, lp->eol_rx, SONIC_RD_LINK) & ~SONIC_EOL); 368 + lp->eol_rx = entry; 369 + lp->cur_rx = entry = (entry + 1) & SONIC_RDS_MASK; 521 370 } 522 371 /* 523 - * If any worth-while packets have been received, dev_rint() 372 + * If any worth-while packets have been received, netif_rx() 524 373 * has done a mark_bh(NET_BH) for us and will work on them 525 374 * when we get to the bottom-half routine. 526 375 */ ··· 539 376 */ 540 377 static struct net_device_stats *sonic_get_stats(struct net_device *dev) 541 378 { 542 - struct sonic_local *lp = (struct sonic_local *) dev->priv; 543 - unsigned int base_addr = dev->base_addr; 379 + struct sonic_local *lp = netdev_priv(dev); 544 380 545 381 /* read the tally counter from the SONIC and reset them */ 546 382 lp->stats.rx_crc_errors += SONIC_READ(SONIC_CRCT); ··· 558 396 */ 559 397 static void sonic_multicast_list(struct net_device *dev) 560 398 { 561 - struct sonic_local *lp = (struct sonic_local *) dev->priv; 562 - unsigned int base_addr = dev->base_addr; 399 + struct sonic_local *lp = netdev_priv(dev); 563 400 unsigned int rcr; 564 401 struct dev_mc_list *dmi = dev->mc_list; 565 402 unsigned char *addr; ··· 574 413 rcr |= SONIC_RCR_AMC; 575 414 } else { 576 415 if (sonic_debug > 2) 577 - printk 578 - ("sonic_multicast_list: mc_count %d\n", 579 - dev->mc_count); 580 - lp->cda.cam_enable = 1; /* always enable our own address */ 416 + printk("sonic_multicast_list: mc_count %d\n", dev->mc_count); 417 + sonic_set_cam_enable(dev, 1); /* always enable our own address */ 581 418 for (i = 1; i <= dev->mc_count; i++) { 582 419 addr = dmi->dmi_addr; 583 420 dmi = dmi->next; 584 - lp->cda.cam_desc[i].cam_cap0 = 585 - addr[1] << 8 | addr[0]; 586 - lp->cda.cam_desc[i].cam_cap1 = 587 - addr[3] << 8 | addr[2]; 588 - lp->cda.cam_desc[i].cam_cap2 = 589 - addr[5] << 8 | addr[4]; 590 - lp->cda.cam_enable |= (1 << i); 421 + sonic_cda_put(dev, i, SONIC_CD_CAP0, addr[1] << 8 | addr[0]); 422 + sonic_cda_put(dev, i, SONIC_CD_CAP1, addr[3] << 8 | addr[2]); 423 + sonic_cda_put(dev, i, SONIC_CD_CAP2, addr[5] << 8 | addr[4]); 424 + sonic_set_cam_enable(dev, sonic_get_cam_enable(dev) | (1 << i)); 591 425 } 592 426 SONIC_WRITE(SONIC_CDC, 16); 593 427 /* issue Load CAM command */ ··· 603 447 */ 604 448 static int sonic_init(struct net_device *dev) 605 449 { 606 - unsigned int base_addr = dev->base_addr; 607 450 unsigned int cmd; 608 - struct sonic_local *lp = (struct sonic_local *) dev->priv; 609 - unsigned int rra_start; 610 - unsigned int rra_end; 451 + struct sonic_local *lp = netdev_priv(dev); 611 452 int i; 612 453 613 454 /* 614 455 * put the Sonic into software-reset mode and 615 456 * disable all interrupts 616 457 */ 617 - SONIC_WRITE(SONIC_ISR, 0x7fff); 618 458 SONIC_WRITE(SONIC_IMR, 0); 459 + SONIC_WRITE(SONIC_ISR, 0x7fff); 619 460 SONIC_WRITE(SONIC_CMD, SONIC_CR_RST); 620 461 621 462 /* ··· 628 475 if (sonic_debug > 2) 629 476 printk("sonic_init: initialize receive resource area\n"); 630 477 631 - rra_start = lp->rra_laddr & 0xffff; 632 - rra_end = 633 - (rra_start + (SONIC_NUM_RRS * sizeof(sonic_rr_t))) & 0xffff; 634 - 635 478 for (i = 0; i < SONIC_NUM_RRS; i++) { 636 - lp->rra[i].rx_bufadr_l = 637 - (lp->rba_laddr + i * SONIC_RBSIZE) & 0xffff; 638 - lp->rra[i].rx_bufadr_h = 639 - (lp->rba_laddr + i * SONIC_RBSIZE) >> 16; 640 - lp->rra[i].rx_bufsize_l = SONIC_RBSIZE >> 1; 641 - lp->rra[i].rx_bufsize_h = 0; 479 + u16 bufadr_l = (unsigned long)lp->rx_laddr[i] & 0xffff; 480 + u16 bufadr_h = (unsigned long)lp->rx_laddr[i] >> 16; 481 + sonic_rra_put(dev, i, SONIC_RR_BUFADR_L, bufadr_l); 482 + sonic_rra_put(dev, i, SONIC_RR_BUFADR_H, bufadr_h); 483 + sonic_rra_put(dev, i, SONIC_RR_BUFSIZE_L, SONIC_RBSIZE >> 1); 484 + sonic_rra_put(dev, i, SONIC_RR_BUFSIZE_H, 0); 642 485 } 643 486 644 487 /* initialize all RRA registers */ 645 - SONIC_WRITE(SONIC_RSA, rra_start); 646 - SONIC_WRITE(SONIC_REA, rra_end); 647 - SONIC_WRITE(SONIC_RRP, rra_start); 648 - SONIC_WRITE(SONIC_RWP, rra_end); 488 + lp->rra_end = (lp->rra_laddr + SONIC_NUM_RRS * SIZEOF_SONIC_RR * 489 + SONIC_BUS_SCALE(lp->dma_bitmode)) & 0xffff; 490 + lp->cur_rwp = (lp->rra_laddr + (SONIC_NUM_RRS - 1) * SIZEOF_SONIC_RR * 491 + SONIC_BUS_SCALE(lp->dma_bitmode)) & 0xffff; 492 + 493 + SONIC_WRITE(SONIC_RSA, lp->rra_laddr & 0xffff); 494 + SONIC_WRITE(SONIC_REA, lp->rra_end); 495 + SONIC_WRITE(SONIC_RRP, lp->rra_laddr & 0xffff); 496 + SONIC_WRITE(SONIC_RWP, lp->cur_rwp); 649 497 SONIC_WRITE(SONIC_URRA, lp->rra_laddr >> 16); 650 - SONIC_WRITE(SONIC_EOBC, (SONIC_RBSIZE - 2) >> 1); 651 - 652 - lp->cur_rra = 653 - lp->rra_laddr + (SONIC_NUM_RRS - 1) * sizeof(sonic_rr_t); 498 + SONIC_WRITE(SONIC_EOBC, (SONIC_RBSIZE >> 1) - (lp->dma_bitmode ? 2 : 1)); 654 499 655 500 /* load the resource pointers */ 656 501 if (sonic_debug > 3) 657 - printk("sonic_init: issueing RRRA command\n"); 658 - 502 + printk("sonic_init: issuing RRRA command\n"); 503 + 659 504 SONIC_WRITE(SONIC_CMD, SONIC_CR_RRRA); 660 505 i = 0; 661 506 while (i++ < 100) { ··· 662 511 } 663 512 664 513 if (sonic_debug > 2) 665 - printk("sonic_init: status=%x\n", SONIC_READ(SONIC_CMD)); 666 - 514 + printk("sonic_init: status=%x i=%d\n", SONIC_READ(SONIC_CMD), i); 515 + 667 516 /* 668 517 * Initialize the receive descriptors so that they 669 518 * become a circular linked list, ie. let the last 670 519 * descriptor point to the first again. 671 520 */ 672 521 if (sonic_debug > 2) 673 - printk("sonic_init: initialize receive descriptors\n"); 674 - for (i = 0; i < SONIC_NUM_RDS; i++) { 675 - lp->rda[i].rx_status = 0; 676 - lp->rda[i].rx_pktlen = 0; 677 - lp->rda[i].rx_pktptr_l = 0; 678 - lp->rda[i].rx_pktptr_h = 0; 679 - lp->rda[i].rx_seqno = 0; 680 - lp->rda[i].in_use = 1; 681 - lp->rda[i].link = 682 - lp->rda_laddr + (i + 1) * sizeof(sonic_rd_t); 522 + printk("sonic_init: initialize receive descriptors\n"); 523 + for (i=0; i<SONIC_NUM_RDS; i++) { 524 + sonic_rda_put(dev, i, SONIC_RD_STATUS, 0); 525 + sonic_rda_put(dev, i, SONIC_RD_PKTLEN, 0); 526 + sonic_rda_put(dev, i, SONIC_RD_PKTPTR_L, 0); 527 + sonic_rda_put(dev, i, SONIC_RD_PKTPTR_H, 0); 528 + sonic_rda_put(dev, i, SONIC_RD_SEQNO, 0); 529 + sonic_rda_put(dev, i, SONIC_RD_IN_USE, 1); 530 + sonic_rda_put(dev, i, SONIC_RD_LINK, 531 + lp->rda_laddr + 532 + ((i+1) * SIZEOF_SONIC_RD * SONIC_BUS_SCALE(lp->dma_bitmode))); 683 533 } 684 534 /* fix last descriptor */ 685 - lp->rda[SONIC_NUM_RDS - 1].link = lp->rda_laddr; 535 + sonic_rda_put(dev, SONIC_NUM_RDS - 1, SONIC_RD_LINK, 536 + (lp->rda_laddr & 0xffff) | SONIC_EOL); 537 + lp->eol_rx = SONIC_NUM_RDS - 1; 686 538 lp->cur_rx = 0; 687 539 SONIC_WRITE(SONIC_URDA, lp->rda_laddr >> 16); 688 540 SONIC_WRITE(SONIC_CRDA, lp->rda_laddr & 0xffff); ··· 696 542 if (sonic_debug > 2) 697 543 printk("sonic_init: initialize transmit descriptors\n"); 698 544 for (i = 0; i < SONIC_NUM_TDS; i++) { 699 - lp->tda[i].tx_status = 0; 700 - lp->tda[i].tx_config = 0; 701 - lp->tda[i].tx_pktsize = 0; 702 - lp->tda[i].tx_frag_count = 0; 703 - lp->tda[i].link = 704 - (lp->tda_laddr + 705 - (i + 1) * sizeof(sonic_td_t)) | SONIC_END_OF_LINKS; 545 + sonic_tda_put(dev, i, SONIC_TD_STATUS, 0); 546 + sonic_tda_put(dev, i, SONIC_TD_CONFIG, 0); 547 + sonic_tda_put(dev, i, SONIC_TD_PKTSIZE, 0); 548 + sonic_tda_put(dev, i, SONIC_TD_FRAG_COUNT, 0); 549 + sonic_tda_put(dev, i, SONIC_TD_LINK, 550 + (lp->tda_laddr & 0xffff) + 551 + (i + 1) * SIZEOF_SONIC_TD * SONIC_BUS_SCALE(lp->dma_bitmode)); 552 + lp->tx_skb[i] = NULL; 706 553 } 707 - lp->tda[SONIC_NUM_TDS - 1].link = 708 - (lp->tda_laddr & 0xffff) | SONIC_END_OF_LINKS; 554 + /* fix last descriptor */ 555 + sonic_tda_put(dev, SONIC_NUM_TDS - 1, SONIC_TD_LINK, 556 + (lp->tda_laddr & 0xffff)); 709 557 710 558 SONIC_WRITE(SONIC_UTDA, lp->tda_laddr >> 16); 711 559 SONIC_WRITE(SONIC_CTDA, lp->tda_laddr & 0xffff); 712 - lp->cur_tx = lp->dirty_tx = 0; 713 - 560 + lp->cur_tx = lp->next_tx = 0; 561 + lp->eol_tx = SONIC_NUM_TDS - 1; 562 + 714 563 /* 715 564 * put our own address to CAM desc[0] 716 565 */ 717 - lp->cda.cam_desc[0].cam_cap0 = 718 - dev->dev_addr[1] << 8 | dev->dev_addr[0]; 719 - lp->cda.cam_desc[0].cam_cap1 = 720 - dev->dev_addr[3] << 8 | dev->dev_addr[2]; 721 - lp->cda.cam_desc[0].cam_cap2 = 722 - dev->dev_addr[5] << 8 | dev->dev_addr[4]; 723 - lp->cda.cam_enable = 1; 566 + sonic_cda_put(dev, 0, SONIC_CD_CAP0, dev->dev_addr[1] << 8 | dev->dev_addr[0]); 567 + sonic_cda_put(dev, 0, SONIC_CD_CAP1, dev->dev_addr[3] << 8 | dev->dev_addr[2]); 568 + sonic_cda_put(dev, 0, SONIC_CD_CAP2, dev->dev_addr[5] << 8 | dev->dev_addr[4]); 569 + sonic_set_cam_enable(dev, 1); 724 570 725 571 for (i = 0; i < 16; i++) 726 - lp->cda.cam_desc[i].cam_entry_pointer = i; 572 + sonic_cda_put(dev, i, SONIC_CD_ENTRY_POINTER, i); 727 573 728 574 /* 729 575 * initialize CAM registers ··· 742 588 break; 743 589 } 744 590 if (sonic_debug > 2) { 745 - printk("sonic_init: CMD=%x, ISR=%x\n", 746 - SONIC_READ(SONIC_CMD), SONIC_READ(SONIC_ISR)); 591 + printk("sonic_init: CMD=%x, ISR=%x\n, i=%d", 592 + SONIC_READ(SONIC_CMD), SONIC_READ(SONIC_ISR), i); 747 593 } 748 594 749 595 /* ··· 758 604 759 605 cmd = SONIC_READ(SONIC_CMD); 760 606 if ((cmd & SONIC_CR_RXEN) == 0 || (cmd & SONIC_CR_STP) == 0) 761 - printk("sonic_init: failed, status=%x\n", cmd); 607 + printk(KERN_ERR "sonic_init: failed, status=%x\n", cmd); 762 608 763 609 if (sonic_debug > 2) 764 610 printk("sonic_init: new status=%x\n",
+209 -241
drivers/net/sonic.h
··· 1 1 /* 2 - * Helpfile for sonic.c 2 + * Header file for sonic.c 3 3 * 4 4 * (C) Waldorf Electronics, Germany 5 5 * Written by Andreas Busse ··· 9 9 * and pad structure members must be exchanged. Also, the structures 10 10 * need to be changed accordingly to the bus size. 11 11 * 12 - * 981229 MSch: did just that for the 68k Mac port (32 bit, big endian), 13 - * see CONFIG_MACSONIC branch below. 12 + * 981229 MSch: did just that for the 68k Mac port (32 bit, big endian) 14 13 * 14 + * 990611 David Huggins-Daines <dhd@debian.org>: This machine abstraction 15 + * does not cope with 16-bit bus sizes very well. Therefore I have 16 + * rewritten it with ugly macros and evil inlines. 17 + * 18 + * 050625 Finn Thain: introduced more 32-bit cards and dhd's support 19 + * for 16-bit cards (from the mac68k project). 15 20 */ 21 + 16 22 #ifndef SONIC_H 17 23 #define SONIC_H 18 24 ··· 89 83 /* 90 84 * Error counters 91 85 */ 86 + 92 87 #define SONIC_CRCT 0x2c 93 88 #define SONIC_FAET 0x2d 94 89 #define SONIC_MPT 0x2e ··· 189 182 190 183 #define SONIC_INT_BR 0x4000 191 184 #define SONIC_INT_HBL 0x2000 192 - #define SONIC_INT_LCD 0x1000 193 - #define SONIC_INT_PINT 0x0800 194 - #define SONIC_INT_PKTRX 0x0400 195 - #define SONIC_INT_TXDN 0x0200 196 - #define SONIC_INT_TXER 0x0100 197 - #define SONIC_INT_TC 0x0080 198 - #define SONIC_INT_RDE 0x0040 199 - #define SONIC_INT_RBE 0x0020 185 + #define SONIC_INT_LCD 0x1000 186 + #define SONIC_INT_PINT 0x0800 187 + #define SONIC_INT_PKTRX 0x0400 188 + #define SONIC_INT_TXDN 0x0200 189 + #define SONIC_INT_TXER 0x0100 190 + #define SONIC_INT_TC 0x0080 191 + #define SONIC_INT_RDE 0x0040 192 + #define SONIC_INT_RBE 0x0020 200 193 #define SONIC_INT_RBAE 0x0010 201 194 #define SONIC_INT_CRC 0x0008 202 195 #define SONIC_INT_FAE 0x0004 ··· 208 201 * The interrupts we allow. 209 202 */ 210 203 211 - #define SONIC_IMR_DEFAULT (SONIC_INT_BR | \ 212 - SONIC_INT_LCD | \ 213 - SONIC_INT_PINT | \ 204 + #define SONIC_IMR_DEFAULT ( SONIC_INT_BR | \ 205 + SONIC_INT_LCD | \ 206 + SONIC_INT_RFO | \ 214 207 SONIC_INT_PKTRX | \ 215 208 SONIC_INT_TXDN | \ 216 209 SONIC_INT_TXER | \ 217 210 SONIC_INT_RDE | \ 218 - SONIC_INT_RBE | \ 219 211 SONIC_INT_RBAE | \ 220 212 SONIC_INT_CRC | \ 221 213 SONIC_INT_FAE | \ 222 214 SONIC_INT_MP) 223 215 224 216 225 - #define SONIC_END_OF_LINKS 0x0001 226 - 227 - 228 - #ifdef CONFIG_MACSONIC 229 - /* 230 - * Big endian like structures on 680x0 Macs 231 - */ 232 - 233 - typedef struct { 234 - u32 rx_bufadr_l; /* receive buffer ptr */ 235 - u32 rx_bufadr_h; 236 - 237 - u32 rx_bufsize_l; /* no. of words in the receive buffer */ 238 - u32 rx_bufsize_h; 239 - } sonic_rr_t; 240 - 241 - /* 242 - * Sonic receive descriptor. Receive descriptors are 243 - * kept in a linked list of these structures. 244 - */ 245 - 246 - typedef struct { 247 - SREGS_PAD(pad0); 248 - u16 rx_status; /* status after reception of a packet */ 249 - SREGS_PAD(pad1); 250 - u16 rx_pktlen; /* length of the packet incl. CRC */ 251 - 252 - /* 253 - * Pointers to the location in the receive buffer area (RBA) 254 - * where the packet resides. A packet is always received into 255 - * a contiguous piece of memory. 256 - */ 257 - SREGS_PAD(pad2); 258 - u16 rx_pktptr_l; 259 - SREGS_PAD(pad3); 260 - u16 rx_pktptr_h; 261 - 262 - SREGS_PAD(pad4); 263 - u16 rx_seqno; /* sequence no. */ 264 - 265 - SREGS_PAD(pad5); 266 - u16 link; /* link to next RDD (end if EOL bit set) */ 267 - 268 - /* 269 - * Owner of this descriptor, 0= driver, 1=sonic 270 - */ 271 - 272 - SREGS_PAD(pad6); 273 - u16 in_use; 274 - 275 - caddr_t rda_next; /* pointer to next RD */ 276 - } sonic_rd_t; 277 - 278 - 279 - /* 280 - * Describes a Transmit Descriptor 281 - */ 282 - typedef struct { 283 - SREGS_PAD(pad0); 284 - u16 tx_status; /* status after transmission of a packet */ 285 - SREGS_PAD(pad1); 286 - u16 tx_config; /* transmit configuration for this packet */ 287 - SREGS_PAD(pad2); 288 - u16 tx_pktsize; /* size of the packet to be transmitted */ 289 - SREGS_PAD(pad3); 290 - u16 tx_frag_count; /* no. of fragments */ 291 - 292 - SREGS_PAD(pad4); 293 - u16 tx_frag_ptr_l; 294 - SREGS_PAD(pad5); 295 - u16 tx_frag_ptr_h; 296 - SREGS_PAD(pad6); 297 - u16 tx_frag_size; 298 - 299 - SREGS_PAD(pad7); 300 - u16 link; /* ptr to next descriptor */ 301 - } sonic_td_t; 302 - 303 - 304 - /* 305 - * Describes an entry in the CAM Descriptor Area. 306 - */ 307 - 308 - typedef struct { 309 - SREGS_PAD(pad0); 310 - u16 cam_entry_pointer; 311 - SREGS_PAD(pad1); 312 - u16 cam_cap0; 313 - SREGS_PAD(pad2); 314 - u16 cam_cap1; 315 - SREGS_PAD(pad3); 316 - u16 cam_cap2; 317 - } sonic_cd_t; 318 - 217 + #define SONIC_EOL 0x0001 319 218 #define CAM_DESCRIPTORS 16 320 219 220 + /* Offsets in the various DMA buffers accessed by the SONIC */ 321 221 322 - typedef struct { 323 - sonic_cd_t cam_desc[CAM_DESCRIPTORS]; 324 - SREGS_PAD(pad); 325 - u16 cam_enable; 326 - } sonic_cda_t; 222 + #define SONIC_BITMODE16 0 223 + #define SONIC_BITMODE32 1 224 + #define SONIC_BUS_SCALE(bitmode) ((bitmode) ? 4 : 2) 225 + /* Note! These are all measured in bus-size units, so use SONIC_BUS_SCALE */ 226 + #define SIZEOF_SONIC_RR 4 227 + #define SONIC_RR_BUFADR_L 0 228 + #define SONIC_RR_BUFADR_H 1 229 + #define SONIC_RR_BUFSIZE_L 2 230 + #define SONIC_RR_BUFSIZE_H 3 327 231 328 - #else /* original declarations, little endian 32 bit */ 232 + #define SIZEOF_SONIC_RD 7 233 + #define SONIC_RD_STATUS 0 234 + #define SONIC_RD_PKTLEN 1 235 + #define SONIC_RD_PKTPTR_L 2 236 + #define SONIC_RD_PKTPTR_H 3 237 + #define SONIC_RD_SEQNO 4 238 + #define SONIC_RD_LINK 5 239 + #define SONIC_RD_IN_USE 6 329 240 330 - /* 331 - * structure definitions 332 - */ 241 + #define SIZEOF_SONIC_TD 8 242 + #define SONIC_TD_STATUS 0 243 + #define SONIC_TD_CONFIG 1 244 + #define SONIC_TD_PKTSIZE 2 245 + #define SONIC_TD_FRAG_COUNT 3 246 + #define SONIC_TD_FRAG_PTR_L 4 247 + #define SONIC_TD_FRAG_PTR_H 5 248 + #define SONIC_TD_FRAG_SIZE 6 249 + #define SONIC_TD_LINK 7 333 250 334 - typedef struct { 335 - u32 rx_bufadr_l; /* receive buffer ptr */ 336 - u32 rx_bufadr_h; 251 + #define SIZEOF_SONIC_CD 4 252 + #define SONIC_CD_ENTRY_POINTER 0 253 + #define SONIC_CD_CAP0 1 254 + #define SONIC_CD_CAP1 2 255 + #define SONIC_CD_CAP2 3 337 256 338 - u32 rx_bufsize_l; /* no. of words in the receive buffer */ 339 - u32 rx_bufsize_h; 340 - } sonic_rr_t; 341 - 342 - /* 343 - * Sonic receive descriptor. Receive descriptors are 344 - * kept in a linked list of these structures. 345 - */ 346 - 347 - typedef struct { 348 - u16 rx_status; /* status after reception of a packet */ 349 - SREGS_PAD(pad0); 350 - u16 rx_pktlen; /* length of the packet incl. CRC */ 351 - SREGS_PAD(pad1); 352 - 353 - /* 354 - * Pointers to the location in the receive buffer area (RBA) 355 - * where the packet resides. A packet is always received into 356 - * a contiguous piece of memory. 357 - */ 358 - u16 rx_pktptr_l; 359 - SREGS_PAD(pad2); 360 - u16 rx_pktptr_h; 361 - SREGS_PAD(pad3); 362 - 363 - u16 rx_seqno; /* sequence no. */ 364 - SREGS_PAD(pad4); 365 - 366 - u16 link; /* link to next RDD (end if EOL bit set) */ 367 - SREGS_PAD(pad5); 368 - 369 - /* 370 - * Owner of this descriptor, 0= driver, 1=sonic 371 - */ 372 - 373 - u16 in_use; 374 - SREGS_PAD(pad6); 375 - 376 - caddr_t rda_next; /* pointer to next RD */ 377 - } sonic_rd_t; 378 - 379 - 380 - /* 381 - * Describes a Transmit Descriptor 382 - */ 383 - typedef struct { 384 - u16 tx_status; /* status after transmission of a packet */ 385 - SREGS_PAD(pad0); 386 - u16 tx_config; /* transmit configuration for this packet */ 387 - SREGS_PAD(pad1); 388 - u16 tx_pktsize; /* size of the packet to be transmitted */ 389 - SREGS_PAD(pad2); 390 - u16 tx_frag_count; /* no. of fragments */ 391 - SREGS_PAD(pad3); 392 - 393 - u16 tx_frag_ptr_l; 394 - SREGS_PAD(pad4); 395 - u16 tx_frag_ptr_h; 396 - SREGS_PAD(pad5); 397 - u16 tx_frag_size; 398 - SREGS_PAD(pad6); 399 - 400 - u16 link; /* ptr to next descriptor */ 401 - SREGS_PAD(pad7); 402 - } sonic_td_t; 403 - 404 - 405 - /* 406 - * Describes an entry in the CAM Descriptor Area. 407 - */ 408 - 409 - typedef struct { 410 - u16 cam_entry_pointer; 411 - SREGS_PAD(pad0); 412 - u16 cam_cap0; 413 - SREGS_PAD(pad1); 414 - u16 cam_cap1; 415 - SREGS_PAD(pad2); 416 - u16 cam_cap2; 417 - SREGS_PAD(pad3); 418 - } sonic_cd_t; 419 - 420 - #define CAM_DESCRIPTORS 16 421 - 422 - 423 - typedef struct { 424 - sonic_cd_t cam_desc[CAM_DESCRIPTORS]; 425 - u16 cam_enable; 426 - SREGS_PAD(pad); 427 - } sonic_cda_t; 428 - #endif /* endianness */ 257 + #define SIZEOF_SONIC_CDA ((CAM_DESCRIPTORS * SIZEOF_SONIC_CD) + 1) 258 + #define SONIC_CDA_CAM_ENABLE (CAM_DESCRIPTORS * SIZEOF_SONIC_CD) 429 259 430 260 /* 431 261 * Some tunables for the buffer areas. Power of 2 is required ··· 270 426 * 271 427 * MSch: use more buffer space for the slow m68k Macs! 272 428 */ 273 - #ifdef CONFIG_MACSONIC 274 - #define SONIC_NUM_RRS 32 /* number of receive resources */ 275 - #define SONIC_NUM_RDS SONIC_NUM_RRS /* number of receive descriptors */ 276 - #define SONIC_NUM_TDS 32 /* number of transmit descriptors */ 277 - #else 278 - #define SONIC_NUM_RRS 16 /* number of receive resources */ 279 - #define SONIC_NUM_RDS SONIC_NUM_RRS /* number of receive descriptors */ 280 - #define SONIC_NUM_TDS 16 /* number of transmit descriptors */ 281 - #endif 282 - #define SONIC_RBSIZE 1520 /* size of one resource buffer */ 429 + #define SONIC_NUM_RRS 16 /* number of receive resources */ 430 + #define SONIC_NUM_RDS SONIC_NUM_RRS /* number of receive descriptors */ 431 + #define SONIC_NUM_TDS 16 /* number of transmit descriptors */ 283 432 284 - #define SONIC_RDS_MASK (SONIC_NUM_RDS-1) 285 - #define SONIC_TDS_MASK (SONIC_NUM_TDS-1) 433 + #define SONIC_RDS_MASK (SONIC_NUM_RDS-1) 434 + #define SONIC_TDS_MASK (SONIC_NUM_TDS-1) 286 435 436 + #define SONIC_RBSIZE 1520 /* size of one resource buffer */ 437 + 438 + /* Again, measured in bus size units! */ 439 + #define SIZEOF_SONIC_DESC (SIZEOF_SONIC_CDA \ 440 + + (SIZEOF_SONIC_TD * SONIC_NUM_TDS) \ 441 + + (SIZEOF_SONIC_RD * SONIC_NUM_RDS) \ 442 + + (SIZEOF_SONIC_RR * SONIC_NUM_RRS)) 287 443 288 444 /* Information that need to be kept for each board. */ 289 445 struct sonic_local { 290 - sonic_cda_t cda; /* virtual CPU address of CDA */ 291 - sonic_td_t tda[SONIC_NUM_TDS]; /* transmit descriptor area */ 292 - sonic_rr_t rra[SONIC_NUM_RRS]; /* receive resource area */ 293 - sonic_rd_t rda[SONIC_NUM_RDS]; /* receive descriptor area */ 294 - struct sk_buff *tx_skb[SONIC_NUM_TDS]; /* skbuffs for packets to transmit */ 295 - unsigned int tx_laddr[SONIC_NUM_TDS]; /* logical DMA address fro skbuffs */ 296 - unsigned char *rba; /* start of receive buffer areas */ 297 - unsigned int cda_laddr; /* logical DMA address of CDA */ 298 - unsigned int tda_laddr; /* logical DMA address of TDA */ 299 - unsigned int rra_laddr; /* logical DMA address of RRA */ 300 - unsigned int rda_laddr; /* logical DMA address of RDA */ 301 - unsigned int rba_laddr; /* logical DMA address of RBA */ 302 - unsigned int cur_rra; /* current indexes to resource areas */ 446 + /* Bus size. 0 == 16 bits, 1 == 32 bits. */ 447 + int dma_bitmode; 448 + /* Register offset within the longword (independent of endianness, 449 + and varies from one type of Macintosh SONIC to another 450 + (Aarrgh)) */ 451 + int reg_offset; 452 + void *descriptors; 453 + /* Crud. These areas have to be within the same 64K. Therefore 454 + we allocate a desriptors page, and point these to places within it. */ 455 + void *cda; /* CAM descriptor area */ 456 + void *tda; /* Transmit descriptor area */ 457 + void *rra; /* Receive resource area */ 458 + void *rda; /* Receive descriptor area */ 459 + struct sk_buff* volatile rx_skb[SONIC_NUM_RRS]; /* packets to be received */ 460 + struct sk_buff* volatile tx_skb[SONIC_NUM_TDS]; /* packets to be transmitted */ 461 + unsigned int tx_len[SONIC_NUM_TDS]; /* lengths of tx DMA mappings */ 462 + /* Logical DMA addresses on MIPS, bus addresses on m68k 463 + * (so "laddr" is a bit misleading) */ 464 + dma_addr_t descriptors_laddr; 465 + u32 cda_laddr; /* logical DMA address of CDA */ 466 + u32 tda_laddr; /* logical DMA address of TDA */ 467 + u32 rra_laddr; /* logical DMA address of RRA */ 468 + u32 rda_laddr; /* logical DMA address of RDA */ 469 + dma_addr_t rx_laddr[SONIC_NUM_RRS]; /* logical DMA addresses of rx skbuffs */ 470 + dma_addr_t tx_laddr[SONIC_NUM_TDS]; /* logical DMA addresses of tx skbuffs */ 471 + unsigned int rra_end; 472 + unsigned int cur_rwp; 303 473 unsigned int cur_rx; 304 - unsigned int cur_tx; 305 - unsigned int dirty_tx; /* last unacked transmit packet */ 306 - char tx_full; 474 + unsigned int cur_tx; /* first unacked transmit packet */ 475 + unsigned int eol_rx; 476 + unsigned int eol_tx; /* last unacked transmit packet */ 477 + unsigned int next_tx; /* next free TD */ 478 + struct device *device; /* generic device */ 307 479 struct net_device_stats stats; 308 480 }; 309 481 310 - #define TX_TIMEOUT 6 482 + #define TX_TIMEOUT (3 * HZ) 311 483 312 484 /* Index to functions, as function prototypes. */ 313 485 ··· 336 476 static void sonic_multicast_list(struct net_device *dev); 337 477 static int sonic_init(struct net_device *dev); 338 478 static void sonic_tx_timeout(struct net_device *dev); 479 + 480 + /* Internal inlines for reading/writing DMA buffers. Note that bus 481 + size and endianness matter here, whereas they don't for registers, 482 + as far as we can tell. */ 483 + /* OpenBSD calls this "SWO". I'd like to think that sonic_buf_put() 484 + is a much better name. */ 485 + static inline void sonic_buf_put(void* base, int bitmode, 486 + int offset, __u16 val) 487 + { 488 + if (bitmode) 489 + #ifdef __BIG_ENDIAN 490 + ((__u16 *) base + (offset*2))[1] = val; 491 + #else 492 + ((__u16 *) base + (offset*2))[0] = val; 493 + #endif 494 + else 495 + ((__u16 *) base)[offset] = val; 496 + } 497 + 498 + static inline __u16 sonic_buf_get(void* base, int bitmode, 499 + int offset) 500 + { 501 + if (bitmode) 502 + #ifdef __BIG_ENDIAN 503 + return ((volatile __u16 *) base + (offset*2))[1]; 504 + #else 505 + return ((volatile __u16 *) base + (offset*2))[0]; 506 + #endif 507 + else 508 + return ((volatile __u16 *) base)[offset]; 509 + } 510 + 511 + /* Inlines that you should actually use for reading/writing DMA buffers */ 512 + static inline void sonic_cda_put(struct net_device* dev, int entry, 513 + int offset, __u16 val) 514 + { 515 + struct sonic_local* lp = (struct sonic_local *) dev->priv; 516 + sonic_buf_put(lp->cda, lp->dma_bitmode, 517 + (entry * SIZEOF_SONIC_CD) + offset, val); 518 + } 519 + 520 + static inline __u16 sonic_cda_get(struct net_device* dev, int entry, 521 + int offset) 522 + { 523 + struct sonic_local* lp = (struct sonic_local *) dev->priv; 524 + return sonic_buf_get(lp->cda, lp->dma_bitmode, 525 + (entry * SIZEOF_SONIC_CD) + offset); 526 + } 527 + 528 + static inline void sonic_set_cam_enable(struct net_device* dev, __u16 val) 529 + { 530 + struct sonic_local* lp = (struct sonic_local *) dev->priv; 531 + sonic_buf_put(lp->cda, lp->dma_bitmode, SONIC_CDA_CAM_ENABLE, val); 532 + } 533 + 534 + static inline __u16 sonic_get_cam_enable(struct net_device* dev) 535 + { 536 + struct sonic_local* lp = (struct sonic_local *) dev->priv; 537 + return sonic_buf_get(lp->cda, lp->dma_bitmode, SONIC_CDA_CAM_ENABLE); 538 + } 539 + 540 + static inline void sonic_tda_put(struct net_device* dev, int entry, 541 + int offset, __u16 val) 542 + { 543 + struct sonic_local* lp = (struct sonic_local *) dev->priv; 544 + sonic_buf_put(lp->tda, lp->dma_bitmode, 545 + (entry * SIZEOF_SONIC_TD) + offset, val); 546 + } 547 + 548 + static inline __u16 sonic_tda_get(struct net_device* dev, int entry, 549 + int offset) 550 + { 551 + struct sonic_local* lp = (struct sonic_local *) dev->priv; 552 + return sonic_buf_get(lp->tda, lp->dma_bitmode, 553 + (entry * SIZEOF_SONIC_TD) + offset); 554 + } 555 + 556 + static inline void sonic_rda_put(struct net_device* dev, int entry, 557 + int offset, __u16 val) 558 + { 559 + struct sonic_local* lp = (struct sonic_local *) dev->priv; 560 + sonic_buf_put(lp->rda, lp->dma_bitmode, 561 + (entry * SIZEOF_SONIC_RD) + offset, val); 562 + } 563 + 564 + static inline __u16 sonic_rda_get(struct net_device* dev, int entry, 565 + int offset) 566 + { 567 + struct sonic_local* lp = (struct sonic_local *) dev->priv; 568 + return sonic_buf_get(lp->rda, lp->dma_bitmode, 569 + (entry * SIZEOF_SONIC_RD) + offset); 570 + } 571 + 572 + static inline void sonic_rra_put(struct net_device* dev, int entry, 573 + int offset, __u16 val) 574 + { 575 + struct sonic_local* lp = (struct sonic_local *) dev->priv; 576 + sonic_buf_put(lp->rra, lp->dma_bitmode, 577 + (entry * SIZEOF_SONIC_RR) + offset, val); 578 + } 579 + 580 + static inline __u16 sonic_rra_get(struct net_device* dev, int entry, 581 + int offset) 582 + { 583 + struct sonic_local* lp = (struct sonic_local *) dev->priv; 584 + return sonic_buf_get(lp->rra, lp->dma_bitmode, 585 + (entry * SIZEOF_SONIC_RR) + offset); 586 + } 339 587 340 588 static const char *version = 341 589 "sonic.c:v0.92 20.9.98 tsbogend@alpha.franken.de\n";