blob: b6ae53bada7500a92a18a7ebe3ec5b07ebed2c1c [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
2 * Sun3 i82586 Ethernet driver
3 *
4 * Cloned from ni52.c for the Sun3 by Sam Creasey (sammy@sammy.net)
5 *
6 * Original copyright follows:
7 * --------------------------
8 *
9 * net-3-driver for the NI5210 card (i82586 Ethernet chip)
10 *
11 * This is an extension to the Linux operating system, and is covered by the
12 * same Gnu Public License that covers that work.
13 *
14 * Alphacode 0.82 (96/09/29) for Linux 2.0.0 (or later)
15 * Copyrights (c) 1994,1995,1996 by M.Hipp (hippm@informatik.uni-tuebingen.de)
16 * --------------------------
Jeff Garzik6aa20a22006-09-13 13:24:59 -040017 *
Linus Torvalds1da177e2005-04-16 15:20:36 -070018 * Consult ni52.c for further notes from the original driver.
19 *
Jeff Garzik6aa20a22006-09-13 13:24:59 -040020 * This incarnation currently supports the OBIO version of the i82586 chip
Linus Torvalds1da177e2005-04-16 15:20:36 -070021 * used in certain sun3 models. It should be fairly doable to expand this
22 * to support VME if I should every acquire such a board.
23 *
24 */
25
26static int debuglevel = 0; /* debug-printk 0: off 1: a few 2: more */
27static int automatic_resume = 0; /* experimental .. better should be zero */
28static int rfdadd = 0; /* rfdadd=1 may be better for 8K MEM cards */
29static int fifo=0x8; /* don't change */
30
Linus Torvalds1da177e2005-04-16 15:20:36 -070031#include <linux/module.h>
32#include <linux/kernel.h>
33#include <linux/string.h>
34#include <linux/errno.h>
35#include <linux/ioport.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070036#include <linux/interrupt.h>
37#include <linux/delay.h>
38#include <linux/init.h>
39#include <linux/bitops.h>
40#include <asm/io.h>
41#include <asm/idprom.h>
42#include <asm/machines.h>
43#include <asm/sun3mmu.h>
44#include <asm/dvma.h>
45#include <asm/byteorder.h>
46
47#include <linux/netdevice.h>
48#include <linux/etherdevice.h>
49#include <linux/skbuff.h>
50
51#include "sun3_82586.h"
52
53#define DRV_NAME "sun3_82586"
54
55#define DEBUG /* debug on */
56#define SYSBUSVAL 0 /* 16 Bit */
57#define SUN3_82586_TOTAL_SIZE PAGE_SIZE
58
59#define sun3_attn586() {*(volatile unsigned char *)(dev->base_addr) |= IEOB_ATTEN; *(volatile unsigned char *)(dev->base_addr) &= ~IEOB_ATTEN;}
60#define sun3_reset586() {*(volatile unsigned char *)(dev->base_addr) = 0; udelay(100); *(volatile unsigned char *)(dev->base_addr) = IEOB_NORSET;}
61#define sun3_disint() {*(volatile unsigned char *)(dev->base_addr) &= ~IEOB_IENAB;}
62#define sun3_enaint() {*(volatile unsigned char *)(dev->base_addr) |= IEOB_IENAB;}
63#define sun3_active() {*(volatile unsigned char *)(dev->base_addr) |= (IEOB_IENAB|IEOB_ONAIR|IEOB_NORSET);}
64
65#define make32(ptr16) (p->memtop + (swab16((unsigned short) (ptr16))) )
66#define make24(ptr32) (char *)swab32(( ((unsigned long) (ptr32)) - p->base))
67#define make16(ptr32) (swab16((unsigned short) ((unsigned long)(ptr32) - (unsigned long) p->memtop )))
68
69/******************* how to calculate the buffers *****************************
70
71 * IMPORTANT NOTE: if you configure only one NUM_XMIT_BUFFS, the driver works
72 * --------------- in a different (more stable?) mode. Only in this mode it's
73 * possible to configure the driver with 'NO_NOPCOMMANDS'
74
75sizeof(scp)=12; sizeof(scb)=16; sizeof(iscp)=8;
76sizeof(scp)+sizeof(iscp)+sizeof(scb) = 36 = INIT
77sizeof(rfd) = 24; sizeof(rbd) = 12;
78sizeof(tbd) = 8; sizeof(transmit_cmd) = 16;
79sizeof(nop_cmd) = 8;
80
81 * if you don't know the driver, better do not change these values: */
82
83#define RECV_BUFF_SIZE 1536 /* slightly oversized */
84#define XMIT_BUFF_SIZE 1536 /* slightly oversized */
85#define NUM_XMIT_BUFFS 1 /* config for 32K shmem */
86#define NUM_RECV_BUFFS_8 4 /* config for 32K shared mem */
87#define NUM_RECV_BUFFS_16 9 /* config for 32K shared mem */
88#define NUM_RECV_BUFFS_32 16 /* config for 32K shared mem */
89#define NO_NOPCOMMANDS /* only possible with NUM_XMIT_BUFFS=1 */
90
91/**************************************************************************/
92
93/* different DELAYs */
94#define DELAY(x) mdelay(32 * x);
95#define DELAY_16(); { udelay(16); }
96#define DELAY_18(); { udelay(4); }
97
98/* wait for command with timeout: */
99#define WAIT_4_SCB_CMD() \
100{ int i; \
101 for(i=0;i<16384;i++) { \
102 if(!p->scb->cmd_cuc) break; \
103 DELAY_18(); \
104 if(i == 16383) { \
105 printk("%s: scb_cmd timed out: %04x,%04x .. disabling i82586!!\n",dev->name,p->scb->cmd_cuc,p->scb->cus); \
106 if(!p->reseted) { p->reseted = 1; sun3_reset586(); } } } }
107
108#define WAIT_4_SCB_CMD_RUC() { int i; \
109 for(i=0;i<16384;i++) { \
110 if(!p->scb->cmd_ruc) break; \
111 DELAY_18(); \
112 if(i == 16383) { \
113 printk("%s: scb_cmd (ruc) timed out: %04x,%04x .. disabling i82586!!\n",dev->name,p->scb->cmd_ruc,p->scb->rus); \
114 if(!p->reseted) { p->reseted = 1; sun3_reset586(); } } } }
115
116#define WAIT_4_STAT_COMPL(addr) { int i; \
117 for(i=0;i<32767;i++) { \
118 if(swab16((addr)->cmd_status) & STAT_COMPL) break; \
119 DELAY_16(); DELAY_16(); } }
120
121static int sun3_82586_probe1(struct net_device *dev,int ioaddr);
David Howells7d12e782006-10-05 14:55:46 +0100122static irqreturn_t sun3_82586_interrupt(int irq,void *dev_id);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700123static int sun3_82586_open(struct net_device *dev);
124static int sun3_82586_close(struct net_device *dev);
125static int sun3_82586_send_packet(struct sk_buff *,struct net_device *);
126static struct net_device_stats *sun3_82586_get_stats(struct net_device *dev);
127static void set_multicast_list(struct net_device *dev);
128static void sun3_82586_timeout(struct net_device *dev);
129#if 0
130static void sun3_82586_dump(struct net_device *,void *);
131#endif
132
133/* helper-functions */
134static int init586(struct net_device *dev);
135static int check586(struct net_device *dev,char *where,unsigned size);
136static void alloc586(struct net_device *dev);
137static void startrecv586(struct net_device *dev);
138static void *alloc_rfa(struct net_device *dev,void *ptr);
139static void sun3_82586_rcv_int(struct net_device *dev);
140static void sun3_82586_xmt_int(struct net_device *dev);
141static void sun3_82586_rnr_int(struct net_device *dev);
142
143struct priv
144{
Linus Torvalds1da177e2005-04-16 15:20:36 -0700145 unsigned long base;
146 char *memtop;
147 long int lock;
148 int reseted;
149 volatile struct rfd_struct *rfd_last,*rfd_top,*rfd_first;
150 volatile struct scp_struct *scp; /* volatile is important */
151 volatile struct iscp_struct *iscp; /* volatile is important */
152 volatile struct scb_struct *scb; /* volatile is important */
153 volatile struct tbd_struct *xmit_buffs[NUM_XMIT_BUFFS];
154 volatile struct transmit_cmd_struct *xmit_cmds[NUM_XMIT_BUFFS];
155#if (NUM_XMIT_BUFFS == 1)
156 volatile struct nop_cmd_struct *nop_cmds[2];
157#else
158 volatile struct nop_cmd_struct *nop_cmds[NUM_XMIT_BUFFS];
159#endif
160 volatile int nop_point,num_recv_buffs;
161 volatile char *xmit_cbuffs[NUM_XMIT_BUFFS];
162 volatile int xmit_count,xmit_last;
163};
164
165/**********************************************
166 * close device
167 */
168static int sun3_82586_close(struct net_device *dev)
169{
170 free_irq(dev->irq, dev);
171
172 sun3_reset586(); /* the hard way to stop the receiver */
173
174 netif_stop_queue(dev);
175
176 return 0;
177}
178
179/**********************************************
180 * open device
181 */
182static int sun3_82586_open(struct net_device *dev)
183{
184 int ret;
185
186 sun3_disint();
187 alloc586(dev);
188 init586(dev);
189 startrecv586(dev);
190 sun3_enaint();
191
Joe Perchesa0607fd2009-11-18 23:29:17 -0800192 ret = request_irq(dev->irq, sun3_82586_interrupt,0,dev->name,dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700193 if (ret)
194 {
195 sun3_reset586();
196 return ret;
197 }
198
199 netif_start_queue(dev);
200
201 return 0; /* most done by init */
202}
203
204/**********************************************
205 * Check to see if there's an 82586 out there.
206 */
207static int check586(struct net_device *dev,char *where,unsigned size)
208{
209 struct priv pb;
Wang Chenb74ca3a2008-12-08 01:14:16 -0800210 struct priv *p = &pb;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700211 char *iscp_addr;
212 int i;
213
214 p->base = (unsigned long) dvma_btov(0);
215 p->memtop = (char *)dvma_btov((unsigned long)where);
216 p->scp = (struct scp_struct *)(p->base + SCP_DEFAULT_ADDRESS);
217 memset((char *)p->scp,0, sizeof(struct scp_struct));
218 for(i=0;i<sizeof(struct scp_struct);i++) /* memory was writeable? */
219 if(((char *)p->scp)[i])
220 return 0;
221 p->scp->sysbus = SYSBUSVAL; /* 1 = 8Bit-Bus, 0 = 16 Bit */
222 if(p->scp->sysbus != SYSBUSVAL)
223 return 0;
224
225 iscp_addr = (char *)dvma_btov((unsigned long)where);
Jeff Garzik6aa20a22006-09-13 13:24:59 -0400226
Linus Torvalds1da177e2005-04-16 15:20:36 -0700227 p->iscp = (struct iscp_struct *) iscp_addr;
228 memset((char *)p->iscp,0, sizeof(struct iscp_struct));
229
230 p->scp->iscp = make24(p->iscp);
231 p->iscp->busy = 1;
232
233 sun3_reset586();
234 sun3_attn586();
235 DELAY(1); /* wait a while... */
Jeff Garzik6aa20a22006-09-13 13:24:59 -0400236
Linus Torvalds1da177e2005-04-16 15:20:36 -0700237 if(p->iscp->busy) /* i82586 clears 'busy' after successful init */
238 return 0;
239
240 return 1;
241}
242
243/******************************************************************
244 * set iscp at the right place, called by sun3_82586_probe1 and open586.
245 */
246static void alloc586(struct net_device *dev)
247{
Wang Chen8f15ea42008-11-12 23:38:36 -0800248 struct priv *p = netdev_priv(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700249
250 sun3_reset586();
251 DELAY(1);
252
253 p->scp = (struct scp_struct *) (p->base + SCP_DEFAULT_ADDRESS);
254 p->iscp = (struct iscp_struct *) dvma_btov(dev->mem_start);
255 p->scb = (struct scb_struct *) ((char *)p->iscp + sizeof(struct iscp_struct));
256
257 memset((char *) p->iscp,0,sizeof(struct iscp_struct));
258 memset((char *) p->scp ,0,sizeof(struct scp_struct));
259
260 p->scp->iscp = make24(p->iscp);
261 p->scp->sysbus = SYSBUSVAL;
262 p->iscp->scb_offset = make16(p->scb);
263 p->iscp->scb_base = make24(dvma_btov(dev->mem_start));
264
265 p->iscp->busy = 1;
266 sun3_reset586();
267 sun3_attn586();
268
269 DELAY(1);
270
271 if(p->iscp->busy)
272 printk("%s: Init-Problems (alloc).\n",dev->name);
273
274 p->reseted = 0;
275
276 memset((char *)p->scb,0,sizeof(struct scb_struct));
277}
278
279struct net_device * __init sun3_82586_probe(int unit)
280{
281 struct net_device *dev;
282 unsigned long ioaddr;
283 static int found = 0;
284 int err = -ENOMEM;
Jeff Garzik6aa20a22006-09-13 13:24:59 -0400285
Linus Torvalds1da177e2005-04-16 15:20:36 -0700286 /* check that this machine has an onboard 82586 */
287 switch(idprom->id_machtype) {
288 case SM_SUN3|SM_3_160:
289 case SM_SUN3|SM_3_260:
290 /* these machines have 82586 */
291 break;
292
293 default:
294 return ERR_PTR(-ENODEV);
295 }
296
297 if (found)
298 return ERR_PTR(-ENODEV);
Jeff Garzik6aa20a22006-09-13 13:24:59 -0400299
Linus Torvalds1da177e2005-04-16 15:20:36 -0700300 ioaddr = (unsigned long)ioremap(IE_OBIO, SUN3_82586_TOTAL_SIZE);
301 if (!ioaddr)
302 return ERR_PTR(-ENOMEM);
303 found = 1;
Jeff Garzik6aa20a22006-09-13 13:24:59 -0400304
Linus Torvalds1da177e2005-04-16 15:20:36 -0700305 dev = alloc_etherdev(sizeof(struct priv));
306 if (!dev)
307 goto out;
308 if (unit >= 0) {
309 sprintf(dev->name, "eth%d", unit);
310 netdev_boot_setup_check(dev);
311 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700312
313 dev->irq = IE_IRQ;
314 dev->base_addr = ioaddr;
315 err = sun3_82586_probe1(dev, ioaddr);
316 if (err)
317 goto out1;
318 err = register_netdev(dev);
319 if (err)
320 goto out2;
321 return dev;
322
323out2:
324 release_region(ioaddr, SUN3_82586_TOTAL_SIZE);
325out1:
326 free_netdev(dev);
327out:
Al Viro437111c2006-10-11 17:28:17 +0100328 iounmap((void __iomem *)ioaddr);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700329 return ERR_PTR(err);
330}
331
Alexander Beregalov7e4fdcb2009-04-11 07:39:58 +0000332static const struct net_device_ops sun3_82586_netdev_ops = {
333 .ndo_open = sun3_82586_open,
334 .ndo_stop = sun3_82586_close,
335 .ndo_start_xmit = sun3_82586_send_packet,
336 .ndo_set_multicast_list = set_multicast_list,
337 .ndo_tx_timeout = sun3_82586_timeout,
338 .ndo_get_stats = sun3_82586_get_stats,
339 .ndo_validate_addr = eth_validate_addr,
340 .ndo_set_mac_address = eth_mac_addr,
341 .ndo_change_mtu = eth_change_mtu,
342};
343
Linus Torvalds1da177e2005-04-16 15:20:36 -0700344static int __init sun3_82586_probe1(struct net_device *dev,int ioaddr)
345{
346 int i, size, retval;
347
348 if (!request_region(ioaddr, SUN3_82586_TOTAL_SIZE, DRV_NAME))
349 return -EBUSY;
350
351 /* copy in the ethernet address from the prom */
352 for(i = 0; i < 6 ; i++)
353 dev->dev_addr[i] = idprom->id_ethaddr[i];
354
355 printk("%s: SUN3 Intel 82586 found at %lx, ",dev->name,dev->base_addr);
356
357 /*
358 * check (or search) IO-Memory, 32K
359 */
360 size = 0x8000;
361
362 dev->mem_start = (unsigned long)dvma_malloc_align(0x8000, 0x1000);
363 dev->mem_end = dev->mem_start + size;
364
365 if(size != 0x2000 && size != 0x4000 && size != 0x8000) {
366 printk("\n%s: Illegal memory size %d. Allowed is 0x2000 or 0x4000 or 0x8000 bytes.\n",dev->name,size);
367 retval = -ENODEV;
368 goto out;
369 }
370 if(!check586(dev,(char *) dev->mem_start,size)) {
371 printk("?memcheck, Can't find memory at 0x%lx with size %d!\n",dev->mem_start,size);
372 retval = -ENODEV;
373 goto out;
374 }
375
Wang Chen8f15ea42008-11-12 23:38:36 -0800376 ((struct priv *)netdev_priv(dev))->memtop =
377 (char *)dvma_btov(dev->mem_start);
378 ((struct priv *)netdev_priv(dev))->base = (unsigned long) dvma_btov(0);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700379 alloc586(dev);
380
381 /* set number of receive-buffs according to memsize */
382 if(size == 0x2000)
Wang Chen8f15ea42008-11-12 23:38:36 -0800383 ((struct priv *)netdev_priv(dev))->num_recv_buffs =
384 NUM_RECV_BUFFS_8;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700385 else if(size == 0x4000)
Wang Chen8f15ea42008-11-12 23:38:36 -0800386 ((struct priv *)netdev_priv(dev))->num_recv_buffs =
387 NUM_RECV_BUFFS_16;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700388 else
Wang Chen8f15ea42008-11-12 23:38:36 -0800389 ((struct priv *)netdev_priv(dev))->num_recv_buffs =
390 NUM_RECV_BUFFS_32;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700391
392 printk("Memaddr: 0x%lx, Memsize: %d, IRQ %d\n",dev->mem_start,size, dev->irq);
Jeff Garzik6aa20a22006-09-13 13:24:59 -0400393
Alexander Beregalov7e4fdcb2009-04-11 07:39:58 +0000394 dev->netdev_ops = &sun3_82586_netdev_ops;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700395 dev->watchdog_timeo = HZ/20;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700396
397 dev->if_port = 0;
398 return 0;
399out:
400 release_region(ioaddr, SUN3_82586_TOTAL_SIZE);
401 return retval;
402}
403
404
405static int init586(struct net_device *dev)
406{
407 void *ptr;
408 int i,result=0;
Wang Chen8f15ea42008-11-12 23:38:36 -0800409 struct priv *p = netdev_priv(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700410 volatile struct configure_cmd_struct *cfg_cmd;
411 volatile struct iasetup_cmd_struct *ias_cmd;
412 volatile struct tdr_cmd_struct *tdr_cmd;
413 volatile struct mcsetup_cmd_struct *mc_cmd;
Jiri Pirko22bedad32010-04-01 21:22:57 +0000414 struct netdev_hw_addr *ha;
Jiri Pirko4cd24ea2010-02-08 04:30:35 +0000415 int num_addrs=netdev_mc_count(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700416
417 ptr = (void *) ((char *)p->scb + sizeof(struct scb_struct));
418
419 cfg_cmd = (struct configure_cmd_struct *)ptr; /* configure-command */
420 cfg_cmd->cmd_status = 0;
421 cfg_cmd->cmd_cmd = swab16(CMD_CONFIGURE | CMD_LAST);
422 cfg_cmd->cmd_link = 0xffff;
423
424 cfg_cmd->byte_cnt = 0x0a; /* number of cfg bytes */
425 cfg_cmd->fifo = fifo; /* fifo-limit (8=tx:32/rx:64) */
426 cfg_cmd->sav_bf = 0x40; /* hold or discard bad recv frames (bit 7) */
427 cfg_cmd->adr_len = 0x2e; /* addr_len |!src_insert |pre-len |loopback */
428 cfg_cmd->priority = 0x00;
429 cfg_cmd->ifs = 0x60;
430 cfg_cmd->time_low = 0x00;
431 cfg_cmd->time_high = 0xf2;
432 cfg_cmd->promisc = 0;
433 if(dev->flags & IFF_ALLMULTI) {
434 int len = ((char *) p->iscp - (char *) ptr - 8) / 6;
435 if(num_addrs > len) {
436 printk("%s: switching to promisc. mode\n",dev->name);
Wang Chenc16d1182008-07-22 13:13:12 +0800437 cfg_cmd->promisc = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700438 }
439 }
440 if(dev->flags&IFF_PROMISC)
Wang Chenc16d1182008-07-22 13:13:12 +0800441 cfg_cmd->promisc = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700442 cfg_cmd->carr_coll = 0x00;
443
444 p->scb->cbl_offset = make16(cfg_cmd);
445 p->scb->cmd_ruc = 0;
446
447 p->scb->cmd_cuc = CUC_START; /* cmd.-unit start */
448 sun3_attn586();
449
450 WAIT_4_STAT_COMPL(cfg_cmd);
451
452 if((swab16(cfg_cmd->cmd_status) & (STAT_OK|STAT_COMPL)) != (STAT_COMPL|STAT_OK))
453 {
454 printk("%s: configure command failed: %x\n",dev->name,swab16(cfg_cmd->cmd_status));
455 return 1;
456 }
457
458 /*
459 * individual address setup
460 */
461
462 ias_cmd = (struct iasetup_cmd_struct *)ptr;
463
464 ias_cmd->cmd_status = 0;
465 ias_cmd->cmd_cmd = swab16(CMD_IASETUP | CMD_LAST);
466 ias_cmd->cmd_link = 0xffff;
467
468 memcpy((char *)&ias_cmd->iaddr,(char *) dev->dev_addr,ETH_ALEN);
469
470 p->scb->cbl_offset = make16(ias_cmd);
471
472 p->scb->cmd_cuc = CUC_START; /* cmd.-unit start */
473 sun3_attn586();
474
475 WAIT_4_STAT_COMPL(ias_cmd);
476
477 if((swab16(ias_cmd->cmd_status) & (STAT_OK|STAT_COMPL)) != (STAT_OK|STAT_COMPL)) {
478 printk("%s (82586): individual address setup command failed: %04x\n",dev->name,swab16(ias_cmd->cmd_status));
479 return 1;
480 }
481
482 /*
483 * TDR, wire check .. e.g. no resistor e.t.c
484 */
Jeff Garzik6aa20a22006-09-13 13:24:59 -0400485
Linus Torvalds1da177e2005-04-16 15:20:36 -0700486 tdr_cmd = (struct tdr_cmd_struct *)ptr;
487
488 tdr_cmd->cmd_status = 0;
489 tdr_cmd->cmd_cmd = swab16(CMD_TDR | CMD_LAST);
490 tdr_cmd->cmd_link = 0xffff;
491 tdr_cmd->status = 0;
492
493 p->scb->cbl_offset = make16(tdr_cmd);
494 p->scb->cmd_cuc = CUC_START; /* cmd.-unit start */
495 sun3_attn586();
496
497 WAIT_4_STAT_COMPL(tdr_cmd);
498
499 if(!(swab16(tdr_cmd->cmd_status) & STAT_COMPL))
500 {
501 printk("%s: Problems while running the TDR.\n",dev->name);
502 }
503 else
504 {
505 DELAY_16(); /* wait for result */
506 result = swab16(tdr_cmd->status);
507
508 p->scb->cmd_cuc = p->scb->cus & STAT_MASK;
509 sun3_attn586(); /* ack the interrupts */
510
511 if(result & TDR_LNK_OK)
512 ;
513 else if(result & TDR_XCVR_PRB)
514 printk("%s: TDR: Transceiver problem. Check the cable(s)!\n",dev->name);
515 else if(result & TDR_ET_OPN)
516 printk("%s: TDR: No correct termination %d clocks away.\n",dev->name,result & TDR_TIMEMASK);
517 else if(result & TDR_ET_SRT)
518 {
519 if (result & TDR_TIMEMASK) /* time == 0 -> strange :-) */
520 printk("%s: TDR: Detected a short circuit %d clocks away.\n",dev->name,result & TDR_TIMEMASK);
521 }
522 else
523 printk("%s: TDR: Unknown status %04x\n",dev->name,result);
524 }
525
526 /*
527 * Multicast setup
528 */
529 if(num_addrs && !(dev->flags & IFF_PROMISC) )
530 {
531 mc_cmd = (struct mcsetup_cmd_struct *) ptr;
532 mc_cmd->cmd_status = 0;
533 mc_cmd->cmd_cmd = swab16(CMD_MCSETUP | CMD_LAST);
534 mc_cmd->cmd_link = 0xffff;
535 mc_cmd->mc_cnt = swab16(num_addrs * 6);
536
Jiri Pirko55085902010-02-18 00:42:54 +0000537 i = 0;
Jiri Pirko22bedad32010-04-01 21:22:57 +0000538 netdev_for_each_mc_addr(ha, dev)
Jiri Pirko55085902010-02-18 00:42:54 +0000539 memcpy((char *) mc_cmd->mc_list[i++],
Jiri Pirko22bedad32010-04-01 21:22:57 +0000540 ha->addr, ETH_ALEN);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700541
542 p->scb->cbl_offset = make16(mc_cmd);
543 p->scb->cmd_cuc = CUC_START;
544 sun3_attn586();
545
546 WAIT_4_STAT_COMPL(mc_cmd);
547
548 if( (swab16(mc_cmd->cmd_status) & (STAT_COMPL|STAT_OK)) != (STAT_COMPL|STAT_OK) )
549 printk("%s: Can't apply multicast-address-list.\n",dev->name);
550 }
551
552 /*
553 * alloc nop/xmit-cmds
554 */
555#if (NUM_XMIT_BUFFS == 1)
556 for(i=0;i<2;i++)
557 {
558 p->nop_cmds[i] = (struct nop_cmd_struct *)ptr;
559 p->nop_cmds[i]->cmd_cmd = swab16(CMD_NOP);
560 p->nop_cmds[i]->cmd_status = 0;
561 p->nop_cmds[i]->cmd_link = make16((p->nop_cmds[i]));
562 ptr = (char *) ptr + sizeof(struct nop_cmd_struct);
563 }
564#else
565 for(i=0;i<NUM_XMIT_BUFFS;i++)
566 {
567 p->nop_cmds[i] = (struct nop_cmd_struct *)ptr;
568 p->nop_cmds[i]->cmd_cmd = swab16(CMD_NOP);
569 p->nop_cmds[i]->cmd_status = 0;
570 p->nop_cmds[i]->cmd_link = make16((p->nop_cmds[i]));
571 ptr = (char *) ptr + sizeof(struct nop_cmd_struct);
572 }
573#endif
574
575 ptr = alloc_rfa(dev,(void *)ptr); /* init receive-frame-area */
576
577 /*
578 * alloc xmit-buffs / init xmit_cmds
579 */
580 for(i=0;i<NUM_XMIT_BUFFS;i++)
581 {
582 p->xmit_cmds[i] = (struct transmit_cmd_struct *)ptr; /*transmit cmd/buff 0*/
583 ptr = (char *) ptr + sizeof(struct transmit_cmd_struct);
584 p->xmit_cbuffs[i] = (char *)ptr; /* char-buffs */
585 ptr = (char *) ptr + XMIT_BUFF_SIZE;
586 p->xmit_buffs[i] = (struct tbd_struct *)ptr; /* TBD */
587 ptr = (char *) ptr + sizeof(struct tbd_struct);
588 if((void *)ptr > (void *)dev->mem_end)
589 {
590 printk("%s: not enough shared-mem for your configuration!\n",dev->name);
591 return 1;
592 }
593 memset((char *)(p->xmit_cmds[i]) ,0, sizeof(struct transmit_cmd_struct));
594 memset((char *)(p->xmit_buffs[i]),0, sizeof(struct tbd_struct));
595 p->xmit_cmds[i]->cmd_link = make16(p->nop_cmds[(i+1)%NUM_XMIT_BUFFS]);
596 p->xmit_cmds[i]->cmd_status = swab16(STAT_COMPL);
597 p->xmit_cmds[i]->cmd_cmd = swab16(CMD_XMIT | CMD_INT);
598 p->xmit_cmds[i]->tbd_offset = make16((p->xmit_buffs[i]));
599 p->xmit_buffs[i]->next = 0xffff;
600 p->xmit_buffs[i]->buffer = make24((p->xmit_cbuffs[i]));
601 }
602
603 p->xmit_count = 0;
604 p->xmit_last = 0;
605#ifndef NO_NOPCOMMANDS
606 p->nop_point = 0;
607#endif
608
609 /*
610 * 'start transmitter'
611 */
612#ifndef NO_NOPCOMMANDS
613 p->scb->cbl_offset = make16(p->nop_cmds[0]);
614 p->scb->cmd_cuc = CUC_START;
615 sun3_attn586();
616 WAIT_4_SCB_CMD();
617#else
618 p->xmit_cmds[0]->cmd_link = make16(p->xmit_cmds[0]);
619 p->xmit_cmds[0]->cmd_cmd = swab16(CMD_XMIT | CMD_SUSPEND | CMD_INT);
620#endif
621
622 /*
623 * ack. interrupts
624 */
625 p->scb->cmd_cuc = p->scb->cus & STAT_MASK;
626 sun3_attn586();
627 DELAY_16();
628
629 sun3_enaint();
630 sun3_active();
631
632 return 0;
633}
634
635/******************************************************
636 * This is a helper routine for sun3_82586_rnr_int() and init586().
637 * It sets up the Receive Frame Area (RFA).
638 */
639
640static void *alloc_rfa(struct net_device *dev,void *ptr)
641{
642 volatile struct rfd_struct *rfd = (struct rfd_struct *)ptr;
643 volatile struct rbd_struct *rbd;
644 int i;
Wang Chen8f15ea42008-11-12 23:38:36 -0800645 struct priv *p = netdev_priv(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700646
647 memset((char *) rfd,0,sizeof(struct rfd_struct)*(p->num_recv_buffs+rfdadd));
648 p->rfd_first = rfd;
649
650 for(i = 0; i < (p->num_recv_buffs+rfdadd); i++) {
651 rfd[i].next = make16(rfd + (i+1) % (p->num_recv_buffs+rfdadd) );
652 rfd[i].rbd_offset = 0xffff;
653 }
654 rfd[p->num_recv_buffs-1+rfdadd].last = RFD_SUSP; /* RU suspend */
655
656 ptr = (void *) (rfd + (p->num_recv_buffs + rfdadd) );
657
658 rbd = (struct rbd_struct *) ptr;
659 ptr = (void *) (rbd + p->num_recv_buffs);
660
661 /* clr descriptors */
662 memset((char *) rbd,0,sizeof(struct rbd_struct)*(p->num_recv_buffs));
663
664 for(i=0;i<p->num_recv_buffs;i++)
665 {
666 rbd[i].next = make16((rbd + (i+1) % p->num_recv_buffs));
667 rbd[i].size = swab16(RECV_BUFF_SIZE);
668 rbd[i].buffer = make24(ptr);
669 ptr = (char *) ptr + RECV_BUFF_SIZE;
670 }
671
672 p->rfd_top = p->rfd_first;
673 p->rfd_last = p->rfd_first + (p->num_recv_buffs - 1 + rfdadd);
674
675 p->scb->rfa_offset = make16(p->rfd_first);
676 p->rfd_first->rbd_offset = make16(rbd);
677
678 return ptr;
679}
680
681
682/**************************************************
683 * Interrupt Handler ...
684 */
685
David Howells7d12e782006-10-05 14:55:46 +0100686static irqreturn_t sun3_82586_interrupt(int irq,void *dev_id)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700687{
688 struct net_device *dev = dev_id;
689 unsigned short stat;
690 int cnt=0;
691 struct priv *p;
692
693 if (!dev) {
694 printk ("sun3_82586-interrupt: irq %d for unknown device.\n",irq);
695 return IRQ_NONE;
696 }
Wang Chen8f15ea42008-11-12 23:38:36 -0800697 p = netdev_priv(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700698
699 if(debuglevel > 1)
700 printk("I");
701
702 WAIT_4_SCB_CMD(); /* wait for last command */
703
704 while((stat=p->scb->cus & STAT_MASK))
705 {
706 p->scb->cmd_cuc = stat;
707 sun3_attn586();
708
709 if(stat & STAT_FR) /* received a frame */
710 sun3_82586_rcv_int(dev);
711
712 if(stat & STAT_RNR) /* RU went 'not ready' */
713 {
714 printk("(R)");
715 if(p->scb->rus & RU_SUSPEND) /* special case: RU_SUSPEND */
716 {
717 WAIT_4_SCB_CMD();
718 p->scb->cmd_ruc = RUC_RESUME;
719 sun3_attn586();
720 WAIT_4_SCB_CMD_RUC();
721 }
722 else
723 {
724 printk("%s: Receiver-Unit went 'NOT READY': %04x/%02x.\n",dev->name,(int) stat,(int) p->scb->rus);
725 sun3_82586_rnr_int(dev);
726 }
727 }
728
729 if(stat & STAT_CX) /* command with I-bit set complete */
730 sun3_82586_xmt_int(dev);
731
732#ifndef NO_NOPCOMMANDS
733 if(stat & STAT_CNA) /* CU went 'not ready' */
734 {
735 if(netif_running(dev))
736 printk("%s: oops! CU has left active state. stat: %04x/%02x.\n",dev->name,(int) stat,(int) p->scb->cus);
737 }
738#endif
739
740 if(debuglevel > 1)
741 printk("%d",cnt++);
742
743 WAIT_4_SCB_CMD(); /* wait for ack. (sun3_82586_xmt_int can be faster than ack!!) */
744 if(p->scb->cmd_cuc) /* timed out? */
745 {
746 printk("%s: Acknowledge timed out.\n",dev->name);
747 sun3_disint();
748 break;
749 }
750 }
751
752 if(debuglevel > 1)
753 printk("i");
754 return IRQ_HANDLED;
755}
756
757/*******************************************************
758 * receive-interrupt
759 */
760
761static void sun3_82586_rcv_int(struct net_device *dev)
762{
763 int status,cnt=0;
764 unsigned short totlen;
765 struct sk_buff *skb;
766 struct rbd_struct *rbd;
Wang Chen8f15ea42008-11-12 23:38:36 -0800767 struct priv *p = netdev_priv(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700768
769 if(debuglevel > 0)
770 printk("R");
771
772 for(;(status = p->rfd_top->stat_high) & RFD_COMPL;)
773 {
774 rbd = (struct rbd_struct *) make32(p->rfd_top->rbd_offset);
775
776 if(status & RFD_OK) /* frame received without error? */
777 {
778 if( (totlen = swab16(rbd->status)) & RBD_LAST) /* the first and the last buffer? */
779 {
780 totlen &= RBD_MASK; /* length of this frame */
781 rbd->status = 0;
782 skb = (struct sk_buff *) dev_alloc_skb(totlen+2);
783 if(skb != NULL)
784 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700785 skb_reserve(skb,2);
786 skb_put(skb,totlen);
David S. Miller8c7b7fa2007-07-10 22:08:12 -0700787 skb_copy_to_linear_data(skb,(char *) p->base+swab32((unsigned long) rbd->buffer),totlen);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700788 skb->protocol=eth_type_trans(skb,dev);
789 netif_rx(skb);
Kulikov Vasiliy4e922722010-07-05 02:13:10 +0000790 dev->stats.rx_packets++;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700791 }
792 else
Kulikov Vasiliy4e922722010-07-05 02:13:10 +0000793 dev->stats.rx_dropped++;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700794 }
795 else
796 {
797 int rstat;
798 /* free all RBD's until RBD_LAST is set */
799 totlen = 0;
800 while(!((rstat=swab16(rbd->status)) & RBD_LAST))
801 {
802 totlen += rstat & RBD_MASK;
803 if(!rstat)
804 {
805 printk("%s: Whoops .. no end mark in RBD list\n",dev->name);
806 break;
807 }
808 rbd->status = 0;
809 rbd = (struct rbd_struct *) make32(rbd->next);
810 }
811 totlen += rstat & RBD_MASK;
812 rbd->status = 0;
813 printk("%s: received oversized frame! length: %d\n",dev->name,totlen);
Kulikov Vasiliy4e922722010-07-05 02:13:10 +0000814 dev->stats.rx_dropped++;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700815 }
816 }
817 else /* frame !(ok), only with 'save-bad-frames' */
818 {
819 printk("%s: oops! rfd-error-status: %04x\n",dev->name,status);
Kulikov Vasiliy4e922722010-07-05 02:13:10 +0000820 dev->stats.rx_errors++;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700821 }
822 p->rfd_top->stat_high = 0;
823 p->rfd_top->last = RFD_SUSP; /* maybe exchange by RFD_LAST */
824 p->rfd_top->rbd_offset = 0xffff;
825 p->rfd_last->last = 0; /* delete RFD_SUSP */
826 p->rfd_last = p->rfd_top;
827 p->rfd_top = (struct rfd_struct *) make32(p->rfd_top->next); /* step to next RFD */
828 p->scb->rfa_offset = make16(p->rfd_top);
829
830 if(debuglevel > 0)
831 printk("%d",cnt++);
832 }
833
834 if(automatic_resume)
835 {
836 WAIT_4_SCB_CMD();
837 p->scb->cmd_ruc = RUC_RESUME;
838 sun3_attn586();
839 WAIT_4_SCB_CMD_RUC();
840 }
841
842#ifdef WAIT_4_BUSY
843 {
844 int i;
845 for(i=0;i<1024;i++)
846 {
847 if(p->rfd_top->status)
848 break;
849 DELAY_16();
850 if(i == 1023)
851 printk("%s: RU hasn't fetched next RFD (not busy/complete)\n",dev->name);
852 }
853 }
854#endif
855
856#if 0
857 if(!at_least_one)
858 {
859 int i;
860 volatile struct rfd_struct *rfds=p->rfd_top;
861 volatile struct rbd_struct *rbds;
862 printk("%s: received a FC intr. without having a frame: %04x %d\n",dev->name,status,old_at_least);
863 for(i=0;i< (p->num_recv_buffs+4);i++)
864 {
865 rbds = (struct rbd_struct *) make32(rfds->rbd_offset);
866 printk("%04x:%04x ",rfds->status,rbds->status);
867 rfds = (struct rfd_struct *) make32(rfds->next);
868 }
869 printk("\nerrs: %04x %04x stat: %04x\n",(int)p->scb->rsc_errs,(int)p->scb->ovrn_errs,(int)p->scb->status);
870 printk("\nerrs: %04x %04x rus: %02x, cus: %02x\n",(int)p->scb->rsc_errs,(int)p->scb->ovrn_errs,(int)p->scb->rus,(int)p->scb->cus);
871 }
872 old_at_least = at_least_one;
873#endif
874
875 if(debuglevel > 0)
876 printk("r");
877}
878
879/**********************************************************
880 * handle 'Receiver went not ready'.
881 */
882
883static void sun3_82586_rnr_int(struct net_device *dev)
884{
Wang Chen8f15ea42008-11-12 23:38:36 -0800885 struct priv *p = netdev_priv(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700886
Kulikov Vasiliy4e922722010-07-05 02:13:10 +0000887 dev->stats.rx_errors++;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700888
889 WAIT_4_SCB_CMD(); /* wait for the last cmd, WAIT_4_FULLSTAT?? */
890 p->scb->cmd_ruc = RUC_ABORT; /* usually the RU is in the 'no resource'-state .. abort it now. */
891 sun3_attn586();
892 WAIT_4_SCB_CMD_RUC(); /* wait for accept cmd. */
893
894 alloc_rfa(dev,(char *)p->rfd_first);
895/* maybe add a check here, before restarting the RU */
896 startrecv586(dev); /* restart RU */
897
898 printk("%s: Receive-Unit restarted. Status: %04x\n",dev->name,p->scb->rus);
899
900}
901
902/**********************************************************
903 * handle xmit - interrupt
904 */
905
906static void sun3_82586_xmt_int(struct net_device *dev)
907{
908 int status;
Wang Chen8f15ea42008-11-12 23:38:36 -0800909 struct priv *p = netdev_priv(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700910
911 if(debuglevel > 0)
912 printk("X");
913
914 status = swab16(p->xmit_cmds[p->xmit_last]->cmd_status);
915 if(!(status & STAT_COMPL))
916 printk("%s: strange .. xmit-int without a 'COMPLETE'\n",dev->name);
917
918 if(status & STAT_OK)
919 {
Kulikov Vasiliy4e922722010-07-05 02:13:10 +0000920 dev->stats.tx_packets++;
921 dev->stats.collisions += (status & TCMD_MAXCOLLMASK);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700922 }
923 else
924 {
Kulikov Vasiliy4e922722010-07-05 02:13:10 +0000925 dev->stats.tx_errors++;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700926 if(status & TCMD_LATECOLL) {
927 printk("%s: late collision detected.\n",dev->name);
Kulikov Vasiliy4e922722010-07-05 02:13:10 +0000928 dev->stats.collisions++;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700929 }
930 else if(status & TCMD_NOCARRIER) {
Kulikov Vasiliy4e922722010-07-05 02:13:10 +0000931 dev->stats.tx_carrier_errors++;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700932 printk("%s: no carrier detected.\n",dev->name);
933 }
934 else if(status & TCMD_LOSTCTS)
935 printk("%s: loss of CTS detected.\n",dev->name);
936 else if(status & TCMD_UNDERRUN) {
Kulikov Vasiliy4e922722010-07-05 02:13:10 +0000937 dev->stats.tx_fifo_errors++;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700938 printk("%s: DMA underrun detected.\n",dev->name);
939 }
940 else if(status & TCMD_MAXCOLL) {
941 printk("%s: Max. collisions exceeded.\n",dev->name);
Kulikov Vasiliy4e922722010-07-05 02:13:10 +0000942 dev->stats.collisions += 16;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700943 }
944 }
945
946#if (NUM_XMIT_BUFFS > 1)
947 if( (++p->xmit_last) == NUM_XMIT_BUFFS)
948 p->xmit_last = 0;
949#endif
950 netif_wake_queue(dev);
951}
952
953/***********************************************************
954 * (re)start the receiver
955 */
956
957static void startrecv586(struct net_device *dev)
958{
Wang Chen8f15ea42008-11-12 23:38:36 -0800959 struct priv *p = netdev_priv(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700960
961 WAIT_4_SCB_CMD();
962 WAIT_4_SCB_CMD_RUC();
963 p->scb->rfa_offset = make16(p->rfd_first);
964 p->scb->cmd_ruc = RUC_START;
965 sun3_attn586(); /* start cmd. */
966 WAIT_4_SCB_CMD_RUC(); /* wait for accept cmd. (no timeout!!) */
967}
968
969static void sun3_82586_timeout(struct net_device *dev)
970{
Wang Chen8f15ea42008-11-12 23:38:36 -0800971 struct priv *p = netdev_priv(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700972#ifndef NO_NOPCOMMANDS
973 if(p->scb->cus & CU_ACTIVE) /* COMMAND-UNIT active? */
974 {
975 netif_wake_queue(dev);
976#ifdef DEBUG
977 printk("%s: strange ... timeout with CU active?!?\n",dev->name);
978 printk("%s: X0: %04x N0: %04x N1: %04x %d\n",dev->name,(int)swab16(p->xmit_cmds[0]->cmd_status),(int)swab16(p->nop_cmds[0]->cmd_status),(int)swab16(p->nop_cmds[1]->cmd_status),(int)p->nop_point);
979#endif
980 p->scb->cmd_cuc = CUC_ABORT;
981 sun3_attn586();
982 WAIT_4_SCB_CMD();
983 p->scb->cbl_offset = make16(p->nop_cmds[p->nop_point]);
984 p->scb->cmd_cuc = CUC_START;
985 sun3_attn586();
986 WAIT_4_SCB_CMD();
Eric Dumazet1ae5dc32010-05-10 05:01:31 -0700987 dev->trans_start = jiffies; /* prevent tx timeout */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700988 return 0;
989 }
990#endif
991 {
992#ifdef DEBUG
993 printk("%s: xmitter timed out, try to restart! stat: %02x\n",dev->name,p->scb->cus);
994 printk("%s: command-stats: %04x %04x\n",dev->name,swab16(p->xmit_cmds[0]->cmd_status),swab16(p->xmit_cmds[1]->cmd_status));
995 printk("%s: check, whether you set the right interrupt number!\n",dev->name);
996#endif
997 sun3_82586_close(dev);
998 sun3_82586_open(dev);
999 }
Eric Dumazet1ae5dc32010-05-10 05:01:31 -07001000 dev->trans_start = jiffies; /* prevent tx timeout */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001001}
1002
1003/******************************************************
1004 * send frame
1005 */
1006
1007static int sun3_82586_send_packet(struct sk_buff *skb, struct net_device *dev)
1008{
1009 int len,i;
1010#ifndef NO_NOPCOMMANDS
1011 int next_nop;
1012#endif
Wang Chen8f15ea42008-11-12 23:38:36 -08001013 struct priv *p = netdev_priv(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001014
1015 if(skb->len > XMIT_BUFF_SIZE)
1016 {
1017 printk("%s: Sorry, max. framelength is %d bytes. The length of your frame is %d bytes.\n",dev->name,XMIT_BUFF_SIZE,skb->len);
Patrick McHardy6ed10652009-06-23 06:03:08 +00001018 return NETDEV_TX_OK;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001019 }
1020
1021 netif_stop_queue(dev);
1022
1023#if(NUM_XMIT_BUFFS > 1)
1024 if(test_and_set_bit(0,(void *) &p->lock)) {
1025 printk("%s: Queue was locked\n",dev->name);
Patrick McHardy5b548142009-06-12 06:22:29 +00001026 return NETDEV_TX_BUSY;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001027 }
1028 else
1029#endif
1030 {
1031 len = skb->len;
1032 if (len < ETH_ZLEN) {
Geert Uytterhoevencfa08bb2007-05-01 22:33:05 +02001033 memset((void *)p->xmit_cbuffs[p->xmit_count], 0,
1034 ETH_ZLEN);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001035 len = ETH_ZLEN;
1036 }
Geert Uytterhoevencfa08bb2007-05-01 22:33:05 +02001037 skb_copy_from_linear_data(skb, (void *)p->xmit_cbuffs[p->xmit_count], skb->len);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001038
1039#if (NUM_XMIT_BUFFS == 1)
1040# ifdef NO_NOPCOMMANDS
1041
1042#ifdef DEBUG
1043 if(p->scb->cus & CU_ACTIVE)
1044 {
1045 printk("%s: Hmmm .. CU is still running and we wanna send a new packet.\n",dev->name);
1046 printk("%s: stat: %04x %04x\n",dev->name,p->scb->cus,swab16(p->xmit_cmds[0]->cmd_status));
1047 }
1048#endif
1049
1050 p->xmit_buffs[0]->size = swab16(TBD_LAST | len);
1051 for(i=0;i<16;i++)
1052 {
1053 p->xmit_cmds[0]->cmd_status = 0;
1054 WAIT_4_SCB_CMD();
1055 if( (p->scb->cus & CU_STATUS) == CU_SUSPEND)
1056 p->scb->cmd_cuc = CUC_RESUME;
1057 else
1058 {
1059 p->scb->cbl_offset = make16(p->xmit_cmds[0]);
1060 p->scb->cmd_cuc = CUC_START;
1061 }
1062
1063 sun3_attn586();
Linus Torvalds1da177e2005-04-16 15:20:36 -07001064 if(!i)
1065 dev_kfree_skb(skb);
1066 WAIT_4_SCB_CMD();
1067 if( (p->scb->cus & CU_ACTIVE)) /* test it, because CU sometimes doesn't start immediately */
1068 break;
1069 if(p->xmit_cmds[0]->cmd_status)
1070 break;
1071 if(i==15)
1072 printk("%s: Can't start transmit-command.\n",dev->name);
1073 }
1074# else
1075 next_nop = (p->nop_point + 1) & 0x1;
1076 p->xmit_buffs[0]->size = swab16(TBD_LAST | len);
1077
1078 p->xmit_cmds[0]->cmd_link = p->nop_cmds[next_nop]->cmd_link
1079 = make16((p->nop_cmds[next_nop]));
1080 p->xmit_cmds[0]->cmd_status = p->nop_cmds[next_nop]->cmd_status = 0;
1081
1082 p->nop_cmds[p->nop_point]->cmd_link = make16((p->xmit_cmds[0]));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001083 p->nop_point = next_nop;
1084 dev_kfree_skb(skb);
1085# endif
1086#else
1087 p->xmit_buffs[p->xmit_count]->size = swab16(TBD_LAST | len);
1088 if( (next_nop = p->xmit_count + 1) == NUM_XMIT_BUFFS )
1089 next_nop = 0;
1090
1091 p->xmit_cmds[p->xmit_count]->cmd_status = 0;
1092 /* linkpointer of xmit-command already points to next nop cmd */
1093 p->nop_cmds[next_nop]->cmd_link = make16((p->nop_cmds[next_nop]));
1094 p->nop_cmds[next_nop]->cmd_status = 0;
1095
1096 p->nop_cmds[p->xmit_count]->cmd_link = make16((p->xmit_cmds[p->xmit_count]));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001097 p->xmit_count = next_nop;
1098
1099 {
1100 unsigned long flags;
1101 local_irq_save(flags);
1102 if(p->xmit_count != p->xmit_last)
1103 netif_wake_queue(dev);
1104 p->lock = 0;
1105 local_irq_restore(flags);
1106 }
1107 dev_kfree_skb(skb);
1108#endif
1109 }
Patrick McHardy6ed10652009-06-23 06:03:08 +00001110 return NETDEV_TX_OK;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001111}
1112
1113/*******************************************
1114 * Someone wanna have the statistics
1115 */
1116
1117static struct net_device_stats *sun3_82586_get_stats(struct net_device *dev)
1118{
Wang Chen8f15ea42008-11-12 23:38:36 -08001119 struct priv *p = netdev_priv(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001120 unsigned short crc,aln,rsc,ovrn;
1121
1122 crc = swab16(p->scb->crc_errs); /* get error-statistic from the ni82586 */
1123 p->scb->crc_errs = 0;
1124 aln = swab16(p->scb->aln_errs);
1125 p->scb->aln_errs = 0;
1126 rsc = swab16(p->scb->rsc_errs);
1127 p->scb->rsc_errs = 0;
1128 ovrn = swab16(p->scb->ovrn_errs);
1129 p->scb->ovrn_errs = 0;
1130
Kulikov Vasiliy4e922722010-07-05 02:13:10 +00001131 dev->stats.rx_crc_errors += crc;
1132 dev->stats.rx_fifo_errors += ovrn;
1133 dev->stats.rx_frame_errors += aln;
1134 dev->stats.rx_dropped += rsc;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001135
Kulikov Vasiliy4e922722010-07-05 02:13:10 +00001136 return &dev->stats;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001137}
1138
1139/********************************************************
1140 * Set MC list ..
1141 */
1142
1143static void set_multicast_list(struct net_device *dev)
1144{
1145 netif_stop_queue(dev);
1146 sun3_disint();
1147 alloc586(dev);
1148 init586(dev);
1149 startrecv586(dev);
1150 sun3_enaint();
1151 netif_wake_queue(dev);
1152}
1153
1154#ifdef MODULE
1155#error This code is not currently supported as a module
1156static struct net_device *dev_sun3_82586;
1157
1158int init_module(void)
1159{
1160 dev_sun3_82586 = sun3_82586_probe(-1);
1161 if (IS_ERR(dev_sun3_82586))
1162 return PTR_ERR(dev_sun3_82586);
1163 return 0;
1164}
1165
1166void cleanup_module(void)
1167{
1168 unsigned long ioaddr = dev_sun3_82586->base_addr;
1169 unregister_netdev(dev_sun3_82586);
1170 release_region(ioaddr, SUN3_82586_TOTAL_SIZE);
1171 iounmap((void *)ioaddr);
1172 free_netdev(dev_sun3_82586);
1173}
1174#endif /* MODULE */
1175
1176#if 0
1177/*
1178 * DUMP .. we expect a not running CMD unit and enough space
1179 */
1180void sun3_82586_dump(struct net_device *dev,void *ptr)
1181{
Wang Chen8f15ea42008-11-12 23:38:36 -08001182 struct priv *p = netdev_priv(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001183 struct dump_cmd_struct *dump_cmd = (struct dump_cmd_struct *) ptr;
1184 int i;
1185
1186 p->scb->cmd_cuc = CUC_ABORT;
1187 sun3_attn586();
1188 WAIT_4_SCB_CMD();
1189 WAIT_4_SCB_CMD_RUC();
1190
1191 dump_cmd->cmd_status = 0;
1192 dump_cmd->cmd_cmd = CMD_DUMP | CMD_LAST;
1193 dump_cmd->dump_offset = make16((dump_cmd + 1));
1194 dump_cmd->cmd_link = 0xffff;
1195
1196 p->scb->cbl_offset = make16(dump_cmd);
1197 p->scb->cmd_cuc = CUC_START;
1198 sun3_attn586();
1199 WAIT_4_STAT_COMPL(dump_cmd);
1200
1201 if( (dump_cmd->cmd_status & (STAT_COMPL|STAT_OK)) != (STAT_COMPL|STAT_OK) )
1202 printk("%s: Can't get dump information.\n",dev->name);
1203
1204 for(i=0;i<170;i++) {
1205 printk("%02x ",(int) ((unsigned char *) (dump_cmd + 1))[i]);
1206 if(i % 24 == 23)
1207 printk("\n");
1208 }
1209 printk("\n");
1210}
1211#endif
1212
1213MODULE_LICENSE("GPL");