blob: 151312342243d3c784613ed07e2dd2f7aec2ac1f [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{
145 struct net_device_stats stats;
146 unsigned long base;
147 char *memtop;
148 long int lock;
149 int reseted;
150 volatile struct rfd_struct *rfd_last,*rfd_top,*rfd_first;
151 volatile struct scp_struct *scp; /* volatile is important */
152 volatile struct iscp_struct *iscp; /* volatile is important */
153 volatile struct scb_struct *scb; /* volatile is important */
154 volatile struct tbd_struct *xmit_buffs[NUM_XMIT_BUFFS];
155 volatile struct transmit_cmd_struct *xmit_cmds[NUM_XMIT_BUFFS];
156#if (NUM_XMIT_BUFFS == 1)
157 volatile struct nop_cmd_struct *nop_cmds[2];
158#else
159 volatile struct nop_cmd_struct *nop_cmds[NUM_XMIT_BUFFS];
160#endif
161 volatile int nop_point,num_recv_buffs;
162 volatile char *xmit_cbuffs[NUM_XMIT_BUFFS];
163 volatile int xmit_count,xmit_last;
164};
165
166/**********************************************
167 * close device
168 */
169static int sun3_82586_close(struct net_device *dev)
170{
171 free_irq(dev->irq, dev);
172
173 sun3_reset586(); /* the hard way to stop the receiver */
174
175 netif_stop_queue(dev);
176
177 return 0;
178}
179
180/**********************************************
181 * open device
182 */
183static int sun3_82586_open(struct net_device *dev)
184{
185 int ret;
186
187 sun3_disint();
188 alloc586(dev);
189 init586(dev);
190 startrecv586(dev);
191 sun3_enaint();
192
Joe Perchesa0607fd2009-11-18 23:29:17 -0800193 ret = request_irq(dev->irq, sun3_82586_interrupt,0,dev->name,dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700194 if (ret)
195 {
196 sun3_reset586();
197 return ret;
198 }
199
200 netif_start_queue(dev);
201
202 return 0; /* most done by init */
203}
204
205/**********************************************
206 * Check to see if there's an 82586 out there.
207 */
208static int check586(struct net_device *dev,char *where,unsigned size)
209{
210 struct priv pb;
Wang Chenb74ca3a2008-12-08 01:14:16 -0800211 struct priv *p = &pb;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700212 char *iscp_addr;
213 int i;
214
215 p->base = (unsigned long) dvma_btov(0);
216 p->memtop = (char *)dvma_btov((unsigned long)where);
217 p->scp = (struct scp_struct *)(p->base + SCP_DEFAULT_ADDRESS);
218 memset((char *)p->scp,0, sizeof(struct scp_struct));
219 for(i=0;i<sizeof(struct scp_struct);i++) /* memory was writeable? */
220 if(((char *)p->scp)[i])
221 return 0;
222 p->scp->sysbus = SYSBUSVAL; /* 1 = 8Bit-Bus, 0 = 16 Bit */
223 if(p->scp->sysbus != SYSBUSVAL)
224 return 0;
225
226 iscp_addr = (char *)dvma_btov((unsigned long)where);
Jeff Garzik6aa20a22006-09-13 13:24:59 -0400227
Linus Torvalds1da177e2005-04-16 15:20:36 -0700228 p->iscp = (struct iscp_struct *) iscp_addr;
229 memset((char *)p->iscp,0, sizeof(struct iscp_struct));
230
231 p->scp->iscp = make24(p->iscp);
232 p->iscp->busy = 1;
233
234 sun3_reset586();
235 sun3_attn586();
236 DELAY(1); /* wait a while... */
Jeff Garzik6aa20a22006-09-13 13:24:59 -0400237
Linus Torvalds1da177e2005-04-16 15:20:36 -0700238 if(p->iscp->busy) /* i82586 clears 'busy' after successful init */
239 return 0;
240
241 return 1;
242}
243
244/******************************************************************
245 * set iscp at the right place, called by sun3_82586_probe1 and open586.
246 */
247static void alloc586(struct net_device *dev)
248{
Wang Chen8f15ea42008-11-12 23:38:36 -0800249 struct priv *p = netdev_priv(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700250
251 sun3_reset586();
252 DELAY(1);
253
254 p->scp = (struct scp_struct *) (p->base + SCP_DEFAULT_ADDRESS);
255 p->iscp = (struct iscp_struct *) dvma_btov(dev->mem_start);
256 p->scb = (struct scb_struct *) ((char *)p->iscp + sizeof(struct iscp_struct));
257
258 memset((char *) p->iscp,0,sizeof(struct iscp_struct));
259 memset((char *) p->scp ,0,sizeof(struct scp_struct));
260
261 p->scp->iscp = make24(p->iscp);
262 p->scp->sysbus = SYSBUSVAL;
263 p->iscp->scb_offset = make16(p->scb);
264 p->iscp->scb_base = make24(dvma_btov(dev->mem_start));
265
266 p->iscp->busy = 1;
267 sun3_reset586();
268 sun3_attn586();
269
270 DELAY(1);
271
272 if(p->iscp->busy)
273 printk("%s: Init-Problems (alloc).\n",dev->name);
274
275 p->reseted = 0;
276
277 memset((char *)p->scb,0,sizeof(struct scb_struct));
278}
279
280struct net_device * __init sun3_82586_probe(int unit)
281{
282 struct net_device *dev;
283 unsigned long ioaddr;
284 static int found = 0;
285 int err = -ENOMEM;
Jeff Garzik6aa20a22006-09-13 13:24:59 -0400286
Linus Torvalds1da177e2005-04-16 15:20:36 -0700287 /* check that this machine has an onboard 82586 */
288 switch(idprom->id_machtype) {
289 case SM_SUN3|SM_3_160:
290 case SM_SUN3|SM_3_260:
291 /* these machines have 82586 */
292 break;
293
294 default:
295 return ERR_PTR(-ENODEV);
296 }
297
298 if (found)
299 return ERR_PTR(-ENODEV);
Jeff Garzik6aa20a22006-09-13 13:24:59 -0400300
Linus Torvalds1da177e2005-04-16 15:20:36 -0700301 ioaddr = (unsigned long)ioremap(IE_OBIO, SUN3_82586_TOTAL_SIZE);
302 if (!ioaddr)
303 return ERR_PTR(-ENOMEM);
304 found = 1;
Jeff Garzik6aa20a22006-09-13 13:24:59 -0400305
Linus Torvalds1da177e2005-04-16 15:20:36 -0700306 dev = alloc_etherdev(sizeof(struct priv));
307 if (!dev)
308 goto out;
309 if (unit >= 0) {
310 sprintf(dev->name, "eth%d", unit);
311 netdev_boot_setup_check(dev);
312 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700313
314 dev->irq = IE_IRQ;
315 dev->base_addr = ioaddr;
316 err = sun3_82586_probe1(dev, ioaddr);
317 if (err)
318 goto out1;
319 err = register_netdev(dev);
320 if (err)
321 goto out2;
322 return dev;
323
324out2:
325 release_region(ioaddr, SUN3_82586_TOTAL_SIZE);
326out1:
327 free_netdev(dev);
328out:
Al Viro437111c2006-10-11 17:28:17 +0100329 iounmap((void __iomem *)ioaddr);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700330 return ERR_PTR(err);
331}
332
Alexander Beregalov7e4fdcb2009-04-11 07:39:58 +0000333static const struct net_device_ops sun3_82586_netdev_ops = {
334 .ndo_open = sun3_82586_open,
335 .ndo_stop = sun3_82586_close,
336 .ndo_start_xmit = sun3_82586_send_packet,
337 .ndo_set_multicast_list = set_multicast_list,
338 .ndo_tx_timeout = sun3_82586_timeout,
339 .ndo_get_stats = sun3_82586_get_stats,
340 .ndo_validate_addr = eth_validate_addr,
341 .ndo_set_mac_address = eth_mac_addr,
342 .ndo_change_mtu = eth_change_mtu,
343};
344
Linus Torvalds1da177e2005-04-16 15:20:36 -0700345static int __init sun3_82586_probe1(struct net_device *dev,int ioaddr)
346{
347 int i, size, retval;
348
349 if (!request_region(ioaddr, SUN3_82586_TOTAL_SIZE, DRV_NAME))
350 return -EBUSY;
351
352 /* copy in the ethernet address from the prom */
353 for(i = 0; i < 6 ; i++)
354 dev->dev_addr[i] = idprom->id_ethaddr[i];
355
356 printk("%s: SUN3 Intel 82586 found at %lx, ",dev->name,dev->base_addr);
357
358 /*
359 * check (or search) IO-Memory, 32K
360 */
361 size = 0x8000;
362
363 dev->mem_start = (unsigned long)dvma_malloc_align(0x8000, 0x1000);
364 dev->mem_end = dev->mem_start + size;
365
366 if(size != 0x2000 && size != 0x4000 && size != 0x8000) {
367 printk("\n%s: Illegal memory size %d. Allowed is 0x2000 or 0x4000 or 0x8000 bytes.\n",dev->name,size);
368 retval = -ENODEV;
369 goto out;
370 }
371 if(!check586(dev,(char *) dev->mem_start,size)) {
372 printk("?memcheck, Can't find memory at 0x%lx with size %d!\n",dev->mem_start,size);
373 retval = -ENODEV;
374 goto out;
375 }
376
Wang Chen8f15ea42008-11-12 23:38:36 -0800377 ((struct priv *)netdev_priv(dev))->memtop =
378 (char *)dvma_btov(dev->mem_start);
379 ((struct priv *)netdev_priv(dev))->base = (unsigned long) dvma_btov(0);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700380 alloc586(dev);
381
382 /* set number of receive-buffs according to memsize */
383 if(size == 0x2000)
Wang Chen8f15ea42008-11-12 23:38:36 -0800384 ((struct priv *)netdev_priv(dev))->num_recv_buffs =
385 NUM_RECV_BUFFS_8;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700386 else if(size == 0x4000)
Wang Chen8f15ea42008-11-12 23:38:36 -0800387 ((struct priv *)netdev_priv(dev))->num_recv_buffs =
388 NUM_RECV_BUFFS_16;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700389 else
Wang Chen8f15ea42008-11-12 23:38:36 -0800390 ((struct priv *)netdev_priv(dev))->num_recv_buffs =
391 NUM_RECV_BUFFS_32;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700392
393 printk("Memaddr: 0x%lx, Memsize: %d, IRQ %d\n",dev->mem_start,size, dev->irq);
Jeff Garzik6aa20a22006-09-13 13:24:59 -0400394
Alexander Beregalov7e4fdcb2009-04-11 07:39:58 +0000395 dev->netdev_ops = &sun3_82586_netdev_ops;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700396 dev->watchdog_timeo = HZ/20;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700397
398 dev->if_port = 0;
399 return 0;
400out:
401 release_region(ioaddr, SUN3_82586_TOTAL_SIZE);
402 return retval;
403}
404
405
406static int init586(struct net_device *dev)
407{
408 void *ptr;
409 int i,result=0;
Wang Chen8f15ea42008-11-12 23:38:36 -0800410 struct priv *p = netdev_priv(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700411 volatile struct configure_cmd_struct *cfg_cmd;
412 volatile struct iasetup_cmd_struct *ias_cmd;
413 volatile struct tdr_cmd_struct *tdr_cmd;
414 volatile struct mcsetup_cmd_struct *mc_cmd;
Jiri Pirko22bedad32010-04-01 21:22:57 +0000415 struct netdev_hw_addr *ha;
Jiri Pirko4cd24ea2010-02-08 04:30:35 +0000416 int num_addrs=netdev_mc_count(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700417
418 ptr = (void *) ((char *)p->scb + sizeof(struct scb_struct));
419
420 cfg_cmd = (struct configure_cmd_struct *)ptr; /* configure-command */
421 cfg_cmd->cmd_status = 0;
422 cfg_cmd->cmd_cmd = swab16(CMD_CONFIGURE | CMD_LAST);
423 cfg_cmd->cmd_link = 0xffff;
424
425 cfg_cmd->byte_cnt = 0x0a; /* number of cfg bytes */
426 cfg_cmd->fifo = fifo; /* fifo-limit (8=tx:32/rx:64) */
427 cfg_cmd->sav_bf = 0x40; /* hold or discard bad recv frames (bit 7) */
428 cfg_cmd->adr_len = 0x2e; /* addr_len |!src_insert |pre-len |loopback */
429 cfg_cmd->priority = 0x00;
430 cfg_cmd->ifs = 0x60;
431 cfg_cmd->time_low = 0x00;
432 cfg_cmd->time_high = 0xf2;
433 cfg_cmd->promisc = 0;
434 if(dev->flags & IFF_ALLMULTI) {
435 int len = ((char *) p->iscp - (char *) ptr - 8) / 6;
436 if(num_addrs > len) {
437 printk("%s: switching to promisc. mode\n",dev->name);
Wang Chenc16d1182008-07-22 13:13:12 +0800438 cfg_cmd->promisc = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700439 }
440 }
441 if(dev->flags&IFF_PROMISC)
Wang Chenc16d1182008-07-22 13:13:12 +0800442 cfg_cmd->promisc = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700443 cfg_cmd->carr_coll = 0x00;
444
445 p->scb->cbl_offset = make16(cfg_cmd);
446 p->scb->cmd_ruc = 0;
447
448 p->scb->cmd_cuc = CUC_START; /* cmd.-unit start */
449 sun3_attn586();
450
451 WAIT_4_STAT_COMPL(cfg_cmd);
452
453 if((swab16(cfg_cmd->cmd_status) & (STAT_OK|STAT_COMPL)) != (STAT_COMPL|STAT_OK))
454 {
455 printk("%s: configure command failed: %x\n",dev->name,swab16(cfg_cmd->cmd_status));
456 return 1;
457 }
458
459 /*
460 * individual address setup
461 */
462
463 ias_cmd = (struct iasetup_cmd_struct *)ptr;
464
465 ias_cmd->cmd_status = 0;
466 ias_cmd->cmd_cmd = swab16(CMD_IASETUP | CMD_LAST);
467 ias_cmd->cmd_link = 0xffff;
468
469 memcpy((char *)&ias_cmd->iaddr,(char *) dev->dev_addr,ETH_ALEN);
470
471 p->scb->cbl_offset = make16(ias_cmd);
472
473 p->scb->cmd_cuc = CUC_START; /* cmd.-unit start */
474 sun3_attn586();
475
476 WAIT_4_STAT_COMPL(ias_cmd);
477
478 if((swab16(ias_cmd->cmd_status) & (STAT_OK|STAT_COMPL)) != (STAT_OK|STAT_COMPL)) {
479 printk("%s (82586): individual address setup command failed: %04x\n",dev->name,swab16(ias_cmd->cmd_status));
480 return 1;
481 }
482
483 /*
484 * TDR, wire check .. e.g. no resistor e.t.c
485 */
Jeff Garzik6aa20a22006-09-13 13:24:59 -0400486
Linus Torvalds1da177e2005-04-16 15:20:36 -0700487 tdr_cmd = (struct tdr_cmd_struct *)ptr;
488
489 tdr_cmd->cmd_status = 0;
490 tdr_cmd->cmd_cmd = swab16(CMD_TDR | CMD_LAST);
491 tdr_cmd->cmd_link = 0xffff;
492 tdr_cmd->status = 0;
493
494 p->scb->cbl_offset = make16(tdr_cmd);
495 p->scb->cmd_cuc = CUC_START; /* cmd.-unit start */
496 sun3_attn586();
497
498 WAIT_4_STAT_COMPL(tdr_cmd);
499
500 if(!(swab16(tdr_cmd->cmd_status) & STAT_COMPL))
501 {
502 printk("%s: Problems while running the TDR.\n",dev->name);
503 }
504 else
505 {
506 DELAY_16(); /* wait for result */
507 result = swab16(tdr_cmd->status);
508
509 p->scb->cmd_cuc = p->scb->cus & STAT_MASK;
510 sun3_attn586(); /* ack the interrupts */
511
512 if(result & TDR_LNK_OK)
513 ;
514 else if(result & TDR_XCVR_PRB)
515 printk("%s: TDR: Transceiver problem. Check the cable(s)!\n",dev->name);
516 else if(result & TDR_ET_OPN)
517 printk("%s: TDR: No correct termination %d clocks away.\n",dev->name,result & TDR_TIMEMASK);
518 else if(result & TDR_ET_SRT)
519 {
520 if (result & TDR_TIMEMASK) /* time == 0 -> strange :-) */
521 printk("%s: TDR: Detected a short circuit %d clocks away.\n",dev->name,result & TDR_TIMEMASK);
522 }
523 else
524 printk("%s: TDR: Unknown status %04x\n",dev->name,result);
525 }
526
527 /*
528 * Multicast setup
529 */
530 if(num_addrs && !(dev->flags & IFF_PROMISC) )
531 {
532 mc_cmd = (struct mcsetup_cmd_struct *) ptr;
533 mc_cmd->cmd_status = 0;
534 mc_cmd->cmd_cmd = swab16(CMD_MCSETUP | CMD_LAST);
535 mc_cmd->cmd_link = 0xffff;
536 mc_cmd->mc_cnt = swab16(num_addrs * 6);
537
Jiri Pirko55085902010-02-18 00:42:54 +0000538 i = 0;
Jiri Pirko22bedad32010-04-01 21:22:57 +0000539 netdev_for_each_mc_addr(ha, dev)
Jiri Pirko55085902010-02-18 00:42:54 +0000540 memcpy((char *) mc_cmd->mc_list[i++],
Jiri Pirko22bedad32010-04-01 21:22:57 +0000541 ha->addr, ETH_ALEN);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700542
543 p->scb->cbl_offset = make16(mc_cmd);
544 p->scb->cmd_cuc = CUC_START;
545 sun3_attn586();
546
547 WAIT_4_STAT_COMPL(mc_cmd);
548
549 if( (swab16(mc_cmd->cmd_status) & (STAT_COMPL|STAT_OK)) != (STAT_COMPL|STAT_OK) )
550 printk("%s: Can't apply multicast-address-list.\n",dev->name);
551 }
552
553 /*
554 * alloc nop/xmit-cmds
555 */
556#if (NUM_XMIT_BUFFS == 1)
557 for(i=0;i<2;i++)
558 {
559 p->nop_cmds[i] = (struct nop_cmd_struct *)ptr;
560 p->nop_cmds[i]->cmd_cmd = swab16(CMD_NOP);
561 p->nop_cmds[i]->cmd_status = 0;
562 p->nop_cmds[i]->cmd_link = make16((p->nop_cmds[i]));
563 ptr = (char *) ptr + sizeof(struct nop_cmd_struct);
564 }
565#else
566 for(i=0;i<NUM_XMIT_BUFFS;i++)
567 {
568 p->nop_cmds[i] = (struct nop_cmd_struct *)ptr;
569 p->nop_cmds[i]->cmd_cmd = swab16(CMD_NOP);
570 p->nop_cmds[i]->cmd_status = 0;
571 p->nop_cmds[i]->cmd_link = make16((p->nop_cmds[i]));
572 ptr = (char *) ptr + sizeof(struct nop_cmd_struct);
573 }
574#endif
575
576 ptr = alloc_rfa(dev,(void *)ptr); /* init receive-frame-area */
577
578 /*
579 * alloc xmit-buffs / init xmit_cmds
580 */
581 for(i=0;i<NUM_XMIT_BUFFS;i++)
582 {
583 p->xmit_cmds[i] = (struct transmit_cmd_struct *)ptr; /*transmit cmd/buff 0*/
584 ptr = (char *) ptr + sizeof(struct transmit_cmd_struct);
585 p->xmit_cbuffs[i] = (char *)ptr; /* char-buffs */
586 ptr = (char *) ptr + XMIT_BUFF_SIZE;
587 p->xmit_buffs[i] = (struct tbd_struct *)ptr; /* TBD */
588 ptr = (char *) ptr + sizeof(struct tbd_struct);
589 if((void *)ptr > (void *)dev->mem_end)
590 {
591 printk("%s: not enough shared-mem for your configuration!\n",dev->name);
592 return 1;
593 }
594 memset((char *)(p->xmit_cmds[i]) ,0, sizeof(struct transmit_cmd_struct));
595 memset((char *)(p->xmit_buffs[i]),0, sizeof(struct tbd_struct));
596 p->xmit_cmds[i]->cmd_link = make16(p->nop_cmds[(i+1)%NUM_XMIT_BUFFS]);
597 p->xmit_cmds[i]->cmd_status = swab16(STAT_COMPL);
598 p->xmit_cmds[i]->cmd_cmd = swab16(CMD_XMIT | CMD_INT);
599 p->xmit_cmds[i]->tbd_offset = make16((p->xmit_buffs[i]));
600 p->xmit_buffs[i]->next = 0xffff;
601 p->xmit_buffs[i]->buffer = make24((p->xmit_cbuffs[i]));
602 }
603
604 p->xmit_count = 0;
605 p->xmit_last = 0;
606#ifndef NO_NOPCOMMANDS
607 p->nop_point = 0;
608#endif
609
610 /*
611 * 'start transmitter'
612 */
613#ifndef NO_NOPCOMMANDS
614 p->scb->cbl_offset = make16(p->nop_cmds[0]);
615 p->scb->cmd_cuc = CUC_START;
616 sun3_attn586();
617 WAIT_4_SCB_CMD();
618#else
619 p->xmit_cmds[0]->cmd_link = make16(p->xmit_cmds[0]);
620 p->xmit_cmds[0]->cmd_cmd = swab16(CMD_XMIT | CMD_SUSPEND | CMD_INT);
621#endif
622
623 /*
624 * ack. interrupts
625 */
626 p->scb->cmd_cuc = p->scb->cus & STAT_MASK;
627 sun3_attn586();
628 DELAY_16();
629
630 sun3_enaint();
631 sun3_active();
632
633 return 0;
634}
635
636/******************************************************
637 * This is a helper routine for sun3_82586_rnr_int() and init586().
638 * It sets up the Receive Frame Area (RFA).
639 */
640
641static void *alloc_rfa(struct net_device *dev,void *ptr)
642{
643 volatile struct rfd_struct *rfd = (struct rfd_struct *)ptr;
644 volatile struct rbd_struct *rbd;
645 int i;
Wang Chen8f15ea42008-11-12 23:38:36 -0800646 struct priv *p = netdev_priv(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700647
648 memset((char *) rfd,0,sizeof(struct rfd_struct)*(p->num_recv_buffs+rfdadd));
649 p->rfd_first = rfd;
650
651 for(i = 0; i < (p->num_recv_buffs+rfdadd); i++) {
652 rfd[i].next = make16(rfd + (i+1) % (p->num_recv_buffs+rfdadd) );
653 rfd[i].rbd_offset = 0xffff;
654 }
655 rfd[p->num_recv_buffs-1+rfdadd].last = RFD_SUSP; /* RU suspend */
656
657 ptr = (void *) (rfd + (p->num_recv_buffs + rfdadd) );
658
659 rbd = (struct rbd_struct *) ptr;
660 ptr = (void *) (rbd + p->num_recv_buffs);
661
662 /* clr descriptors */
663 memset((char *) rbd,0,sizeof(struct rbd_struct)*(p->num_recv_buffs));
664
665 for(i=0;i<p->num_recv_buffs;i++)
666 {
667 rbd[i].next = make16((rbd + (i+1) % p->num_recv_buffs));
668 rbd[i].size = swab16(RECV_BUFF_SIZE);
669 rbd[i].buffer = make24(ptr);
670 ptr = (char *) ptr + RECV_BUFF_SIZE;
671 }
672
673 p->rfd_top = p->rfd_first;
674 p->rfd_last = p->rfd_first + (p->num_recv_buffs - 1 + rfdadd);
675
676 p->scb->rfa_offset = make16(p->rfd_first);
677 p->rfd_first->rbd_offset = make16(rbd);
678
679 return ptr;
680}
681
682
683/**************************************************
684 * Interrupt Handler ...
685 */
686
David Howells7d12e782006-10-05 14:55:46 +0100687static irqreturn_t sun3_82586_interrupt(int irq,void *dev_id)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700688{
689 struct net_device *dev = dev_id;
690 unsigned short stat;
691 int cnt=0;
692 struct priv *p;
693
694 if (!dev) {
695 printk ("sun3_82586-interrupt: irq %d for unknown device.\n",irq);
696 return IRQ_NONE;
697 }
Wang Chen8f15ea42008-11-12 23:38:36 -0800698 p = netdev_priv(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700699
700 if(debuglevel > 1)
701 printk("I");
702
703 WAIT_4_SCB_CMD(); /* wait for last command */
704
705 while((stat=p->scb->cus & STAT_MASK))
706 {
707 p->scb->cmd_cuc = stat;
708 sun3_attn586();
709
710 if(stat & STAT_FR) /* received a frame */
711 sun3_82586_rcv_int(dev);
712
713 if(stat & STAT_RNR) /* RU went 'not ready' */
714 {
715 printk("(R)");
716 if(p->scb->rus & RU_SUSPEND) /* special case: RU_SUSPEND */
717 {
718 WAIT_4_SCB_CMD();
719 p->scb->cmd_ruc = RUC_RESUME;
720 sun3_attn586();
721 WAIT_4_SCB_CMD_RUC();
722 }
723 else
724 {
725 printk("%s: Receiver-Unit went 'NOT READY': %04x/%02x.\n",dev->name,(int) stat,(int) p->scb->rus);
726 sun3_82586_rnr_int(dev);
727 }
728 }
729
730 if(stat & STAT_CX) /* command with I-bit set complete */
731 sun3_82586_xmt_int(dev);
732
733#ifndef NO_NOPCOMMANDS
734 if(stat & STAT_CNA) /* CU went 'not ready' */
735 {
736 if(netif_running(dev))
737 printk("%s: oops! CU has left active state. stat: %04x/%02x.\n",dev->name,(int) stat,(int) p->scb->cus);
738 }
739#endif
740
741 if(debuglevel > 1)
742 printk("%d",cnt++);
743
744 WAIT_4_SCB_CMD(); /* wait for ack. (sun3_82586_xmt_int can be faster than ack!!) */
745 if(p->scb->cmd_cuc) /* timed out? */
746 {
747 printk("%s: Acknowledge timed out.\n",dev->name);
748 sun3_disint();
749 break;
750 }
751 }
752
753 if(debuglevel > 1)
754 printk("i");
755 return IRQ_HANDLED;
756}
757
758/*******************************************************
759 * receive-interrupt
760 */
761
762static void sun3_82586_rcv_int(struct net_device *dev)
763{
764 int status,cnt=0;
765 unsigned short totlen;
766 struct sk_buff *skb;
767 struct rbd_struct *rbd;
Wang Chen8f15ea42008-11-12 23:38:36 -0800768 struct priv *p = netdev_priv(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700769
770 if(debuglevel > 0)
771 printk("R");
772
773 for(;(status = p->rfd_top->stat_high) & RFD_COMPL;)
774 {
775 rbd = (struct rbd_struct *) make32(p->rfd_top->rbd_offset);
776
777 if(status & RFD_OK) /* frame received without error? */
778 {
779 if( (totlen = swab16(rbd->status)) & RBD_LAST) /* the first and the last buffer? */
780 {
781 totlen &= RBD_MASK; /* length of this frame */
782 rbd->status = 0;
783 skb = (struct sk_buff *) dev_alloc_skb(totlen+2);
784 if(skb != NULL)
785 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700786 skb_reserve(skb,2);
787 skb_put(skb,totlen);
David S. Miller8c7b7fa2007-07-10 22:08:12 -0700788 skb_copy_to_linear_data(skb,(char *) p->base+swab32((unsigned long) rbd->buffer),totlen);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700789 skb->protocol=eth_type_trans(skb,dev);
790 netif_rx(skb);
791 p->stats.rx_packets++;
792 }
793 else
794 p->stats.rx_dropped++;
795 }
796 else
797 {
798 int rstat;
799 /* free all RBD's until RBD_LAST is set */
800 totlen = 0;
801 while(!((rstat=swab16(rbd->status)) & RBD_LAST))
802 {
803 totlen += rstat & RBD_MASK;
804 if(!rstat)
805 {
806 printk("%s: Whoops .. no end mark in RBD list\n",dev->name);
807 break;
808 }
809 rbd->status = 0;
810 rbd = (struct rbd_struct *) make32(rbd->next);
811 }
812 totlen += rstat & RBD_MASK;
813 rbd->status = 0;
814 printk("%s: received oversized frame! length: %d\n",dev->name,totlen);
815 p->stats.rx_dropped++;
816 }
817 }
818 else /* frame !(ok), only with 'save-bad-frames' */
819 {
820 printk("%s: oops! rfd-error-status: %04x\n",dev->name,status);
821 p->stats.rx_errors++;
822 }
823 p->rfd_top->stat_high = 0;
824 p->rfd_top->last = RFD_SUSP; /* maybe exchange by RFD_LAST */
825 p->rfd_top->rbd_offset = 0xffff;
826 p->rfd_last->last = 0; /* delete RFD_SUSP */
827 p->rfd_last = p->rfd_top;
828 p->rfd_top = (struct rfd_struct *) make32(p->rfd_top->next); /* step to next RFD */
829 p->scb->rfa_offset = make16(p->rfd_top);
830
831 if(debuglevel > 0)
832 printk("%d",cnt++);
833 }
834
835 if(automatic_resume)
836 {
837 WAIT_4_SCB_CMD();
838 p->scb->cmd_ruc = RUC_RESUME;
839 sun3_attn586();
840 WAIT_4_SCB_CMD_RUC();
841 }
842
843#ifdef WAIT_4_BUSY
844 {
845 int i;
846 for(i=0;i<1024;i++)
847 {
848 if(p->rfd_top->status)
849 break;
850 DELAY_16();
851 if(i == 1023)
852 printk("%s: RU hasn't fetched next RFD (not busy/complete)\n",dev->name);
853 }
854 }
855#endif
856
857#if 0
858 if(!at_least_one)
859 {
860 int i;
861 volatile struct rfd_struct *rfds=p->rfd_top;
862 volatile struct rbd_struct *rbds;
863 printk("%s: received a FC intr. without having a frame: %04x %d\n",dev->name,status,old_at_least);
864 for(i=0;i< (p->num_recv_buffs+4);i++)
865 {
866 rbds = (struct rbd_struct *) make32(rfds->rbd_offset);
867 printk("%04x:%04x ",rfds->status,rbds->status);
868 rfds = (struct rfd_struct *) make32(rfds->next);
869 }
870 printk("\nerrs: %04x %04x stat: %04x\n",(int)p->scb->rsc_errs,(int)p->scb->ovrn_errs,(int)p->scb->status);
871 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);
872 }
873 old_at_least = at_least_one;
874#endif
875
876 if(debuglevel > 0)
877 printk("r");
878}
879
880/**********************************************************
881 * handle 'Receiver went not ready'.
882 */
883
884static void sun3_82586_rnr_int(struct net_device *dev)
885{
Wang Chen8f15ea42008-11-12 23:38:36 -0800886 struct priv *p = netdev_priv(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700887
888 p->stats.rx_errors++;
889
890 WAIT_4_SCB_CMD(); /* wait for the last cmd, WAIT_4_FULLSTAT?? */
891 p->scb->cmd_ruc = RUC_ABORT; /* usually the RU is in the 'no resource'-state .. abort it now. */
892 sun3_attn586();
893 WAIT_4_SCB_CMD_RUC(); /* wait for accept cmd. */
894
895 alloc_rfa(dev,(char *)p->rfd_first);
896/* maybe add a check here, before restarting the RU */
897 startrecv586(dev); /* restart RU */
898
899 printk("%s: Receive-Unit restarted. Status: %04x\n",dev->name,p->scb->rus);
900
901}
902
903/**********************************************************
904 * handle xmit - interrupt
905 */
906
907static void sun3_82586_xmt_int(struct net_device *dev)
908{
909 int status;
Wang Chen8f15ea42008-11-12 23:38:36 -0800910 struct priv *p = netdev_priv(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700911
912 if(debuglevel > 0)
913 printk("X");
914
915 status = swab16(p->xmit_cmds[p->xmit_last]->cmd_status);
916 if(!(status & STAT_COMPL))
917 printk("%s: strange .. xmit-int without a 'COMPLETE'\n",dev->name);
918
919 if(status & STAT_OK)
920 {
921 p->stats.tx_packets++;
922 p->stats.collisions += (status & TCMD_MAXCOLLMASK);
923 }
924 else
925 {
926 p->stats.tx_errors++;
927 if(status & TCMD_LATECOLL) {
928 printk("%s: late collision detected.\n",dev->name);
929 p->stats.collisions++;
930 }
931 else if(status & TCMD_NOCARRIER) {
932 p->stats.tx_carrier_errors++;
933 printk("%s: no carrier detected.\n",dev->name);
934 }
935 else if(status & TCMD_LOSTCTS)
936 printk("%s: loss of CTS detected.\n",dev->name);
937 else if(status & TCMD_UNDERRUN) {
938 p->stats.tx_fifo_errors++;
939 printk("%s: DMA underrun detected.\n",dev->name);
940 }
941 else if(status & TCMD_MAXCOLL) {
942 printk("%s: Max. collisions exceeded.\n",dev->name);
943 p->stats.collisions += 16;
944 }
945 }
946
947#if (NUM_XMIT_BUFFS > 1)
948 if( (++p->xmit_last) == NUM_XMIT_BUFFS)
949 p->xmit_last = 0;
950#endif
951 netif_wake_queue(dev);
952}
953
954/***********************************************************
955 * (re)start the receiver
956 */
957
958static void startrecv586(struct net_device *dev)
959{
Wang Chen8f15ea42008-11-12 23:38:36 -0800960 struct priv *p = netdev_priv(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700961
962 WAIT_4_SCB_CMD();
963 WAIT_4_SCB_CMD_RUC();
964 p->scb->rfa_offset = make16(p->rfd_first);
965 p->scb->cmd_ruc = RUC_START;
966 sun3_attn586(); /* start cmd. */
967 WAIT_4_SCB_CMD_RUC(); /* wait for accept cmd. (no timeout!!) */
968}
969
970static void sun3_82586_timeout(struct net_device *dev)
971{
Wang Chen8f15ea42008-11-12 23:38:36 -0800972 struct priv *p = netdev_priv(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700973#ifndef NO_NOPCOMMANDS
974 if(p->scb->cus & CU_ACTIVE) /* COMMAND-UNIT active? */
975 {
976 netif_wake_queue(dev);
977#ifdef DEBUG
978 printk("%s: strange ... timeout with CU active?!?\n",dev->name);
979 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);
980#endif
981 p->scb->cmd_cuc = CUC_ABORT;
982 sun3_attn586();
983 WAIT_4_SCB_CMD();
984 p->scb->cbl_offset = make16(p->nop_cmds[p->nop_point]);
985 p->scb->cmd_cuc = CUC_START;
986 sun3_attn586();
987 WAIT_4_SCB_CMD();
Eric Dumazet1ae5dc32010-05-10 05:01:31 -0700988 dev->trans_start = jiffies; /* prevent tx timeout */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700989 return 0;
990 }
991#endif
992 {
993#ifdef DEBUG
994 printk("%s: xmitter timed out, try to restart! stat: %02x\n",dev->name,p->scb->cus);
995 printk("%s: command-stats: %04x %04x\n",dev->name,swab16(p->xmit_cmds[0]->cmd_status),swab16(p->xmit_cmds[1]->cmd_status));
996 printk("%s: check, whether you set the right interrupt number!\n",dev->name);
997#endif
998 sun3_82586_close(dev);
999 sun3_82586_open(dev);
1000 }
Eric Dumazet1ae5dc32010-05-10 05:01:31 -07001001 dev->trans_start = jiffies; /* prevent tx timeout */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001002}
1003
1004/******************************************************
1005 * send frame
1006 */
1007
1008static int sun3_82586_send_packet(struct sk_buff *skb, struct net_device *dev)
1009{
1010 int len,i;
1011#ifndef NO_NOPCOMMANDS
1012 int next_nop;
1013#endif
Wang Chen8f15ea42008-11-12 23:38:36 -08001014 struct priv *p = netdev_priv(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001015
1016 if(skb->len > XMIT_BUFF_SIZE)
1017 {
1018 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 +00001019 return NETDEV_TX_OK;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001020 }
1021
1022 netif_stop_queue(dev);
1023
1024#if(NUM_XMIT_BUFFS > 1)
1025 if(test_and_set_bit(0,(void *) &p->lock)) {
1026 printk("%s: Queue was locked\n",dev->name);
Patrick McHardy5b548142009-06-12 06:22:29 +00001027 return NETDEV_TX_BUSY;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001028 }
1029 else
1030#endif
1031 {
1032 len = skb->len;
1033 if (len < ETH_ZLEN) {
Geert Uytterhoevencfa08bb2007-05-01 22:33:05 +02001034 memset((void *)p->xmit_cbuffs[p->xmit_count], 0,
1035 ETH_ZLEN);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001036 len = ETH_ZLEN;
1037 }
Geert Uytterhoevencfa08bb2007-05-01 22:33:05 +02001038 skb_copy_from_linear_data(skb, (void *)p->xmit_cbuffs[p->xmit_count], skb->len);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001039
1040#if (NUM_XMIT_BUFFS == 1)
1041# ifdef NO_NOPCOMMANDS
1042
1043#ifdef DEBUG
1044 if(p->scb->cus & CU_ACTIVE)
1045 {
1046 printk("%s: Hmmm .. CU is still running and we wanna send a new packet.\n",dev->name);
1047 printk("%s: stat: %04x %04x\n",dev->name,p->scb->cus,swab16(p->xmit_cmds[0]->cmd_status));
1048 }
1049#endif
1050
1051 p->xmit_buffs[0]->size = swab16(TBD_LAST | len);
1052 for(i=0;i<16;i++)
1053 {
1054 p->xmit_cmds[0]->cmd_status = 0;
1055 WAIT_4_SCB_CMD();
1056 if( (p->scb->cus & CU_STATUS) == CU_SUSPEND)
1057 p->scb->cmd_cuc = CUC_RESUME;
1058 else
1059 {
1060 p->scb->cbl_offset = make16(p->xmit_cmds[0]);
1061 p->scb->cmd_cuc = CUC_START;
1062 }
1063
1064 sun3_attn586();
Linus Torvalds1da177e2005-04-16 15:20:36 -07001065 if(!i)
1066 dev_kfree_skb(skb);
1067 WAIT_4_SCB_CMD();
1068 if( (p->scb->cus & CU_ACTIVE)) /* test it, because CU sometimes doesn't start immediately */
1069 break;
1070 if(p->xmit_cmds[0]->cmd_status)
1071 break;
1072 if(i==15)
1073 printk("%s: Can't start transmit-command.\n",dev->name);
1074 }
1075# else
1076 next_nop = (p->nop_point + 1) & 0x1;
1077 p->xmit_buffs[0]->size = swab16(TBD_LAST | len);
1078
1079 p->xmit_cmds[0]->cmd_link = p->nop_cmds[next_nop]->cmd_link
1080 = make16((p->nop_cmds[next_nop]));
1081 p->xmit_cmds[0]->cmd_status = p->nop_cmds[next_nop]->cmd_status = 0;
1082
1083 p->nop_cmds[p->nop_point]->cmd_link = make16((p->xmit_cmds[0]));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001084 p->nop_point = next_nop;
1085 dev_kfree_skb(skb);
1086# endif
1087#else
1088 p->xmit_buffs[p->xmit_count]->size = swab16(TBD_LAST | len);
1089 if( (next_nop = p->xmit_count + 1) == NUM_XMIT_BUFFS )
1090 next_nop = 0;
1091
1092 p->xmit_cmds[p->xmit_count]->cmd_status = 0;
1093 /* linkpointer of xmit-command already points to next nop cmd */
1094 p->nop_cmds[next_nop]->cmd_link = make16((p->nop_cmds[next_nop]));
1095 p->nop_cmds[next_nop]->cmd_status = 0;
1096
1097 p->nop_cmds[p->xmit_count]->cmd_link = make16((p->xmit_cmds[p->xmit_count]));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001098 p->xmit_count = next_nop;
1099
1100 {
1101 unsigned long flags;
1102 local_irq_save(flags);
1103 if(p->xmit_count != p->xmit_last)
1104 netif_wake_queue(dev);
1105 p->lock = 0;
1106 local_irq_restore(flags);
1107 }
1108 dev_kfree_skb(skb);
1109#endif
1110 }
Patrick McHardy6ed10652009-06-23 06:03:08 +00001111 return NETDEV_TX_OK;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001112}
1113
1114/*******************************************
1115 * Someone wanna have the statistics
1116 */
1117
1118static struct net_device_stats *sun3_82586_get_stats(struct net_device *dev)
1119{
Wang Chen8f15ea42008-11-12 23:38:36 -08001120 struct priv *p = netdev_priv(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001121 unsigned short crc,aln,rsc,ovrn;
1122
1123 crc = swab16(p->scb->crc_errs); /* get error-statistic from the ni82586 */
1124 p->scb->crc_errs = 0;
1125 aln = swab16(p->scb->aln_errs);
1126 p->scb->aln_errs = 0;
1127 rsc = swab16(p->scb->rsc_errs);
1128 p->scb->rsc_errs = 0;
1129 ovrn = swab16(p->scb->ovrn_errs);
1130 p->scb->ovrn_errs = 0;
1131
1132 p->stats.rx_crc_errors += crc;
1133 p->stats.rx_fifo_errors += ovrn;
1134 p->stats.rx_frame_errors += aln;
1135 p->stats.rx_dropped += rsc;
1136
1137 return &p->stats;
1138}
1139
1140/********************************************************
1141 * Set MC list ..
1142 */
1143
1144static void set_multicast_list(struct net_device *dev)
1145{
1146 netif_stop_queue(dev);
1147 sun3_disint();
1148 alloc586(dev);
1149 init586(dev);
1150 startrecv586(dev);
1151 sun3_enaint();
1152 netif_wake_queue(dev);
1153}
1154
1155#ifdef MODULE
1156#error This code is not currently supported as a module
1157static struct net_device *dev_sun3_82586;
1158
1159int init_module(void)
1160{
1161 dev_sun3_82586 = sun3_82586_probe(-1);
1162 if (IS_ERR(dev_sun3_82586))
1163 return PTR_ERR(dev_sun3_82586);
1164 return 0;
1165}
1166
1167void cleanup_module(void)
1168{
1169 unsigned long ioaddr = dev_sun3_82586->base_addr;
1170 unregister_netdev(dev_sun3_82586);
1171 release_region(ioaddr, SUN3_82586_TOTAL_SIZE);
1172 iounmap((void *)ioaddr);
1173 free_netdev(dev_sun3_82586);
1174}
1175#endif /* MODULE */
1176
1177#if 0
1178/*
1179 * DUMP .. we expect a not running CMD unit and enough space
1180 */
1181void sun3_82586_dump(struct net_device *dev,void *ptr)
1182{
Wang Chen8f15ea42008-11-12 23:38:36 -08001183 struct priv *p = netdev_priv(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001184 struct dump_cmd_struct *dump_cmd = (struct dump_cmd_struct *) ptr;
1185 int i;
1186
1187 p->scb->cmd_cuc = CUC_ABORT;
1188 sun3_attn586();
1189 WAIT_4_SCB_CMD();
1190 WAIT_4_SCB_CMD_RUC();
1191
1192 dump_cmd->cmd_status = 0;
1193 dump_cmd->cmd_cmd = CMD_DUMP | CMD_LAST;
1194 dump_cmd->dump_offset = make16((dump_cmd + 1));
1195 dump_cmd->cmd_link = 0xffff;
1196
1197 p->scb->cbl_offset = make16(dump_cmd);
1198 p->scb->cmd_cuc = CUC_START;
1199 sun3_attn586();
1200 WAIT_4_STAT_COMPL(dump_cmd);
1201
1202 if( (dump_cmd->cmd_status & (STAT_COMPL|STAT_OK)) != (STAT_COMPL|STAT_OK) )
1203 printk("%s: Can't get dump information.\n",dev->name);
1204
1205 for(i=0;i<170;i++) {
1206 printk("%02x ",(int) ((unsigned char *) (dump_cmd + 1))[i]);
1207 if(i % 24 == 23)
1208 printk("\n");
1209 }
1210 printk("\n");
1211}
1212#endif
1213
1214MODULE_LICENSE("GPL");