1 /* 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 * -------------------------- 17 * 18 * Consult ni52.c for further notes from the original driver. 19 * 20 * This incarnation currently supports the OBIO version of the i82586 chip 21 * 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 26 static int debuglevel = 0; /* debug-printk 0: off 1: a few 2: more */ 27 static int automatic_resume = 0; /* experimental .. better should be zero */ 28 static int rfdadd = 0; /* rfdadd=1 may be better for 8K MEM cards */ 29 static int fifo=0x8; /* don't change */ 30 31 #include <linux/kernel.h> 32 #include <linux/module.h> 33 #include <linux/string.h> 34 #include <linux/errno.h> 35 #include <linux/ioport.h> 36 #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 75 sizeof(scp)=12; sizeof(scb)=16; sizeof(iscp)=8; 76 sizeof(scp)+sizeof(iscp)+sizeof(scb) = 36 = INIT 77 sizeof(rfd) = 24; sizeof(rbd) = 12; 78 sizeof(tbd) = 8; sizeof(transmit_cmd) = 16; 79 sizeof(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 121 static int sun3_82586_probe1(struct net_device *dev,int ioaddr); 122 static irqreturn_t sun3_82586_interrupt(int irq,void *dev_id); 123 static int sun3_82586_open(struct net_device *dev); 124 static int sun3_82586_close(struct net_device *dev); 125 static netdev_tx_t sun3_82586_send_packet(struct sk_buff *, 126 struct net_device *); 127 static struct net_device_stats *sun3_82586_get_stats(struct net_device *dev); 128 static void set_multicast_list(struct net_device *dev); 129 static void sun3_82586_timeout(struct net_device *dev, unsigned int txqueue); 130 #if 0 131 static void sun3_82586_dump(struct net_device *,void *); 132 #endif 133 134 /* helper-functions */ 135 static int init586(struct net_device *dev); 136 static int check586(struct net_device *dev,char *where,unsigned size); 137 static void alloc586(struct net_device *dev); 138 static void startrecv586(struct net_device *dev); 139 static void *alloc_rfa(struct net_device *dev,void *ptr); 140 static void sun3_82586_rcv_int(struct net_device *dev); 141 static void sun3_82586_xmt_int(struct net_device *dev); 142 static void sun3_82586_rnr_int(struct net_device *dev); 143 144 struct priv 145 { 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 */ 169 static 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 */ 183 static 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 193 ret = request_irq(dev->irq, sun3_82586_interrupt,0,dev->name,dev); 194 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 */ 208 static int check586(struct net_device *dev,char *where,unsigned size) 209 { 210 struct priv pb; 211 struct priv *p = &pb; 212 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); 227 228 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... */ 237 238 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 */ 247 static void alloc586(struct net_device *dev) 248 { 249 struct priv *p = netdev_priv(dev); 250 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 280 static int __init sun3_82586_probe(void) 281 { 282 struct net_device *dev; 283 unsigned long ioaddr; 284 static int found = 0; 285 int err = -ENOMEM; 286 287 /* 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 -ENODEV; 296 } 297 298 if (found) 299 return -ENODEV; 300 301 ioaddr = (unsigned long)ioremap(IE_OBIO, SUN3_82586_TOTAL_SIZE); 302 if (!ioaddr) 303 return -ENOMEM; 304 found = 1; 305 306 dev = alloc_etherdev(sizeof(struct priv)); 307 if (!dev) 308 goto out; 309 dev->irq = IE_IRQ; 310 dev->base_addr = ioaddr; 311 err = sun3_82586_probe1(dev, ioaddr); 312 if (err) 313 goto out1; 314 err = register_netdev(dev); 315 if (err) 316 goto out2; 317 return 0; 318 319 out2: 320 release_region(ioaddr, SUN3_82586_TOTAL_SIZE); 321 out1: 322 free_netdev(dev); 323 out: 324 iounmap((void __iomem *)ioaddr); 325 return err; 326 } 327 module_init(sun3_82586_probe); 328 329 static const struct net_device_ops sun3_82586_netdev_ops = { 330 .ndo_open = sun3_82586_open, 331 .ndo_stop = sun3_82586_close, 332 .ndo_start_xmit = sun3_82586_send_packet, 333 .ndo_set_rx_mode = set_multicast_list, 334 .ndo_tx_timeout = sun3_82586_timeout, 335 .ndo_get_stats = sun3_82586_get_stats, 336 .ndo_validate_addr = eth_validate_addr, 337 .ndo_set_mac_address = eth_mac_addr, 338 }; 339 340 static int __init sun3_82586_probe1(struct net_device *dev,int ioaddr) 341 { 342 int i, size, retval; 343 344 if (!request_region(ioaddr, SUN3_82586_TOTAL_SIZE, DRV_NAME)) 345 return -EBUSY; 346 347 /* copy in the ethernet address from the prom */ 348 for(i = 0; i < 6 ; i++) 349 dev->dev_addr[i] = idprom->id_ethaddr[i]; 350 351 printk("%s: SUN3 Intel 82586 found at %lx, ",dev->name,dev->base_addr); 352 353 /* 354 * check (or search) IO-Memory, 32K 355 */ 356 size = 0x8000; 357 358 dev->mem_start = (unsigned long)dvma_malloc_align(0x8000, 0x1000); 359 dev->mem_end = dev->mem_start + size; 360 361 if(size != 0x2000 && size != 0x4000 && size != 0x8000) { 362 printk("\n%s: Illegal memory size %d. Allowed is 0x2000 or 0x4000 or 0x8000 bytes.\n",dev->name,size); 363 retval = -ENODEV; 364 goto out; 365 } 366 if(!check586(dev,(char *) dev->mem_start,size)) { 367 printk("?memcheck, Can't find memory at 0x%lx with size %d!\n",dev->mem_start,size); 368 retval = -ENODEV; 369 goto out; 370 } 371 372 ((struct priv *)netdev_priv(dev))->memtop = 373 (char *)dvma_btov(dev->mem_start); 374 ((struct priv *)netdev_priv(dev))->base = (unsigned long) dvma_btov(0); 375 alloc586(dev); 376 377 /* set number of receive-buffs according to memsize */ 378 if(size == 0x2000) 379 ((struct priv *)netdev_priv(dev))->num_recv_buffs = 380 NUM_RECV_BUFFS_8; 381 else if(size == 0x4000) 382 ((struct priv *)netdev_priv(dev))->num_recv_buffs = 383 NUM_RECV_BUFFS_16; 384 else 385 ((struct priv *)netdev_priv(dev))->num_recv_buffs = 386 NUM_RECV_BUFFS_32; 387 388 printk("Memaddr: 0x%lx, Memsize: %d, IRQ %d\n",dev->mem_start,size, dev->irq); 389 390 dev->netdev_ops = &sun3_82586_netdev_ops; 391 dev->watchdog_timeo = HZ/20; 392 393 dev->if_port = 0; 394 return 0; 395 out: 396 release_region(ioaddr, SUN3_82586_TOTAL_SIZE); 397 return retval; 398 } 399 400 401 static int init586(struct net_device *dev) 402 { 403 void *ptr; 404 int i,result=0; 405 struct priv *p = netdev_priv(dev); 406 volatile struct configure_cmd_struct *cfg_cmd; 407 volatile struct iasetup_cmd_struct *ias_cmd; 408 volatile struct tdr_cmd_struct *tdr_cmd; 409 volatile struct mcsetup_cmd_struct *mc_cmd; 410 struct netdev_hw_addr *ha; 411 int num_addrs=netdev_mc_count(dev); 412 413 ptr = (void *) ((char *)p->scb + sizeof(struct scb_struct)); 414 415 cfg_cmd = (struct configure_cmd_struct *)ptr; /* configure-command */ 416 cfg_cmd->cmd_status = 0; 417 cfg_cmd->cmd_cmd = swab16(CMD_CONFIGURE | CMD_LAST); 418 cfg_cmd->cmd_link = 0xffff; 419 420 cfg_cmd->byte_cnt = 0x0a; /* number of cfg bytes */ 421 cfg_cmd->fifo = fifo; /* fifo-limit (8=tx:32/rx:64) */ 422 cfg_cmd->sav_bf = 0x40; /* hold or discard bad recv frames (bit 7) */ 423 cfg_cmd->adr_len = 0x2e; /* addr_len |!src_insert |pre-len |loopback */ 424 cfg_cmd->priority = 0x00; 425 cfg_cmd->ifs = 0x60; 426 cfg_cmd->time_low = 0x00; 427 cfg_cmd->time_high = 0xf2; 428 cfg_cmd->promisc = 0; 429 if(dev->flags & IFF_ALLMULTI) { 430 int len = ((char *) p->iscp - (char *) ptr - 8) / 6; 431 if(num_addrs > len) { 432 printk("%s: switching to promisc. mode\n",dev->name); 433 cfg_cmd->promisc = 1; 434 } 435 } 436 if(dev->flags&IFF_PROMISC) 437 cfg_cmd->promisc = 1; 438 cfg_cmd->carr_coll = 0x00; 439 440 p->scb->cbl_offset = make16(cfg_cmd); 441 p->scb->cmd_ruc = 0; 442 443 p->scb->cmd_cuc = CUC_START; /* cmd.-unit start */ 444 sun3_attn586(); 445 446 WAIT_4_STAT_COMPL(cfg_cmd); 447 448 if((swab16(cfg_cmd->cmd_status) & (STAT_OK|STAT_COMPL)) != (STAT_COMPL|STAT_OK)) 449 { 450 printk("%s: configure command failed: %x\n",dev->name,swab16(cfg_cmd->cmd_status)); 451 return 1; 452 } 453 454 /* 455 * individual address setup 456 */ 457 458 ias_cmd = (struct iasetup_cmd_struct *)ptr; 459 460 ias_cmd->cmd_status = 0; 461 ias_cmd->cmd_cmd = swab16(CMD_IASETUP | CMD_LAST); 462 ias_cmd->cmd_link = 0xffff; 463 464 memcpy((char *)&ias_cmd->iaddr,(char *) dev->dev_addr,ETH_ALEN); 465 466 p->scb->cbl_offset = make16(ias_cmd); 467 468 p->scb->cmd_cuc = CUC_START; /* cmd.-unit start */ 469 sun3_attn586(); 470 471 WAIT_4_STAT_COMPL(ias_cmd); 472 473 if((swab16(ias_cmd->cmd_status) & (STAT_OK|STAT_COMPL)) != (STAT_OK|STAT_COMPL)) { 474 printk("%s (82586): individual address setup command failed: %04x\n",dev->name,swab16(ias_cmd->cmd_status)); 475 return 1; 476 } 477 478 /* 479 * TDR, wire check .. e.g. no resistor e.t.c 480 */ 481 482 tdr_cmd = (struct tdr_cmd_struct *)ptr; 483 484 tdr_cmd->cmd_status = 0; 485 tdr_cmd->cmd_cmd = swab16(CMD_TDR | CMD_LAST); 486 tdr_cmd->cmd_link = 0xffff; 487 tdr_cmd->status = 0; 488 489 p->scb->cbl_offset = make16(tdr_cmd); 490 p->scb->cmd_cuc = CUC_START; /* cmd.-unit start */ 491 sun3_attn586(); 492 493 WAIT_4_STAT_COMPL(tdr_cmd); 494 495 if(!(swab16(tdr_cmd->cmd_status) & STAT_COMPL)) 496 { 497 printk("%s: Problems while running the TDR.\n",dev->name); 498 } 499 else 500 { 501 DELAY_16(); /* wait for result */ 502 result = swab16(tdr_cmd->status); 503 504 p->scb->cmd_cuc = p->scb->cus & STAT_MASK; 505 sun3_attn586(); /* ack the interrupts */ 506 507 if(result & TDR_LNK_OK) 508 ; 509 else if(result & TDR_XCVR_PRB) 510 printk("%s: TDR: Transceiver problem. Check the cable(s)!\n",dev->name); 511 else if(result & TDR_ET_OPN) 512 printk("%s: TDR: No correct termination %d clocks away.\n",dev->name,result & TDR_TIMEMASK); 513 else if(result & TDR_ET_SRT) 514 { 515 if (result & TDR_TIMEMASK) /* time == 0 -> strange :-) */ 516 printk("%s: TDR: Detected a short circuit %d clocks away.\n",dev->name,result & TDR_TIMEMASK); 517 } 518 else 519 printk("%s: TDR: Unknown status %04x\n",dev->name,result); 520 } 521 522 /* 523 * Multicast setup 524 */ 525 if(num_addrs && !(dev->flags & IFF_PROMISC) ) 526 { 527 mc_cmd = (struct mcsetup_cmd_struct *) ptr; 528 mc_cmd->cmd_status = 0; 529 mc_cmd->cmd_cmd = swab16(CMD_MCSETUP | CMD_LAST); 530 mc_cmd->cmd_link = 0xffff; 531 mc_cmd->mc_cnt = swab16(num_addrs * 6); 532 533 i = 0; 534 netdev_for_each_mc_addr(ha, dev) 535 memcpy((char *) mc_cmd->mc_list[i++], 536 ha->addr, ETH_ALEN); 537 538 p->scb->cbl_offset = make16(mc_cmd); 539 p->scb->cmd_cuc = CUC_START; 540 sun3_attn586(); 541 542 WAIT_4_STAT_COMPL(mc_cmd); 543 544 if( (swab16(mc_cmd->cmd_status) & (STAT_COMPL|STAT_OK)) != (STAT_COMPL|STAT_OK) ) 545 printk("%s: Can't apply multicast-address-list.\n",dev->name); 546 } 547 548 /* 549 * alloc nop/xmit-cmds 550 */ 551 #if (NUM_XMIT_BUFFS == 1) 552 for(i=0;i<2;i++) 553 { 554 p->nop_cmds[i] = (struct nop_cmd_struct *)ptr; 555 p->nop_cmds[i]->cmd_cmd = swab16(CMD_NOP); 556 p->nop_cmds[i]->cmd_status = 0; 557 p->nop_cmds[i]->cmd_link = make16((p->nop_cmds[i])); 558 ptr = (char *) ptr + sizeof(struct nop_cmd_struct); 559 } 560 #else 561 for(i=0;i<NUM_XMIT_BUFFS;i++) 562 { 563 p->nop_cmds[i] = (struct nop_cmd_struct *)ptr; 564 p->nop_cmds[i]->cmd_cmd = swab16(CMD_NOP); 565 p->nop_cmds[i]->cmd_status = 0; 566 p->nop_cmds[i]->cmd_link = make16((p->nop_cmds[i])); 567 ptr = (char *) ptr + sizeof(struct nop_cmd_struct); 568 } 569 #endif 570 571 ptr = alloc_rfa(dev,ptr); /* init receive-frame-area */ 572 573 /* 574 * alloc xmit-buffs / init xmit_cmds 575 */ 576 for(i=0;i<NUM_XMIT_BUFFS;i++) 577 { 578 p->xmit_cmds[i] = (struct transmit_cmd_struct *)ptr; /*transmit cmd/buff 0*/ 579 ptr = (char *) ptr + sizeof(struct transmit_cmd_struct); 580 p->xmit_cbuffs[i] = (char *)ptr; /* char-buffs */ 581 ptr = (char *) ptr + XMIT_BUFF_SIZE; 582 p->xmit_buffs[i] = (struct tbd_struct *)ptr; /* TBD */ 583 ptr = (char *) ptr + sizeof(struct tbd_struct); 584 if(ptr > (void *)dev->mem_end) 585 { 586 printk("%s: not enough shared-mem for your configuration!\n",dev->name); 587 return 1; 588 } 589 memset((char *)(p->xmit_cmds[i]) ,0, sizeof(struct transmit_cmd_struct)); 590 memset((char *)(p->xmit_buffs[i]),0, sizeof(struct tbd_struct)); 591 p->xmit_cmds[i]->cmd_link = make16(p->nop_cmds[(i+1)%NUM_XMIT_BUFFS]); 592 p->xmit_cmds[i]->cmd_status = swab16(STAT_COMPL); 593 p->xmit_cmds[i]->cmd_cmd = swab16(CMD_XMIT | CMD_INT); 594 p->xmit_cmds[i]->tbd_offset = make16((p->xmit_buffs[i])); 595 p->xmit_buffs[i]->next = 0xffff; 596 p->xmit_buffs[i]->buffer = make24((p->xmit_cbuffs[i])); 597 } 598 599 p->xmit_count = 0; 600 p->xmit_last = 0; 601 #ifndef NO_NOPCOMMANDS 602 p->nop_point = 0; 603 #endif 604 605 /* 606 * 'start transmitter' 607 */ 608 #ifndef NO_NOPCOMMANDS 609 p->scb->cbl_offset = make16(p->nop_cmds[0]); 610 p->scb->cmd_cuc = CUC_START; 611 sun3_attn586(); 612 WAIT_4_SCB_CMD(); 613 #else 614 p->xmit_cmds[0]->cmd_link = make16(p->xmit_cmds[0]); 615 p->xmit_cmds[0]->cmd_cmd = swab16(CMD_XMIT | CMD_SUSPEND | CMD_INT); 616 #endif 617 618 /* 619 * ack. interrupts 620 */ 621 p->scb->cmd_cuc = p->scb->cus & STAT_MASK; 622 sun3_attn586(); 623 DELAY_16(); 624 625 sun3_enaint(); 626 sun3_active(); 627 628 return 0; 629 } 630 631 /****************************************************** 632 * This is a helper routine for sun3_82586_rnr_int() and init586(). 633 * It sets up the Receive Frame Area (RFA). 634 */ 635 636 static void *alloc_rfa(struct net_device *dev,void *ptr) 637 { 638 volatile struct rfd_struct *rfd = (struct rfd_struct *)ptr; 639 volatile struct rbd_struct *rbd; 640 int i; 641 struct priv *p = netdev_priv(dev); 642 643 memset((char *) rfd,0,sizeof(struct rfd_struct)*(p->num_recv_buffs+rfdadd)); 644 p->rfd_first = rfd; 645 646 for(i = 0; i < (p->num_recv_buffs+rfdadd); i++) { 647 rfd[i].next = make16(rfd + (i+1) % (p->num_recv_buffs+rfdadd) ); 648 rfd[i].rbd_offset = 0xffff; 649 } 650 rfd[p->num_recv_buffs-1+rfdadd].last = RFD_SUSP; /* RU suspend */ 651 652 ptr = (void *) (rfd + (p->num_recv_buffs + rfdadd) ); 653 654 rbd = (struct rbd_struct *) ptr; 655 ptr = (void *) (rbd + p->num_recv_buffs); 656 657 /* clr descriptors */ 658 memset((char *) rbd,0,sizeof(struct rbd_struct)*(p->num_recv_buffs)); 659 660 for(i=0;i<p->num_recv_buffs;i++) 661 { 662 rbd[i].next = make16((rbd + (i+1) % p->num_recv_buffs)); 663 rbd[i].size = swab16(RECV_BUFF_SIZE); 664 rbd[i].buffer = make24(ptr); 665 ptr = (char *) ptr + RECV_BUFF_SIZE; 666 } 667 668 p->rfd_top = p->rfd_first; 669 p->rfd_last = p->rfd_first + (p->num_recv_buffs - 1 + rfdadd); 670 671 p->scb->rfa_offset = make16(p->rfd_first); 672 p->rfd_first->rbd_offset = make16(rbd); 673 674 return ptr; 675 } 676 677 678 /************************************************** 679 * Interrupt Handler ... 680 */ 681 682 static irqreturn_t sun3_82586_interrupt(int irq,void *dev_id) 683 { 684 struct net_device *dev = dev_id; 685 unsigned short stat; 686 int cnt=0; 687 struct priv *p; 688 689 if (!dev) { 690 printk ("sun3_82586-interrupt: irq %d for unknown device.\n",irq); 691 return IRQ_NONE; 692 } 693 p = netdev_priv(dev); 694 695 if(debuglevel > 1) 696 printk("I"); 697 698 WAIT_4_SCB_CMD(); /* wait for last command */ 699 700 while((stat=p->scb->cus & STAT_MASK)) 701 { 702 p->scb->cmd_cuc = stat; 703 sun3_attn586(); 704 705 if(stat & STAT_FR) /* received a frame */ 706 sun3_82586_rcv_int(dev); 707 708 if(stat & STAT_RNR) /* RU went 'not ready' */ 709 { 710 printk("(R)"); 711 if(p->scb->rus & RU_SUSPEND) /* special case: RU_SUSPEND */ 712 { 713 WAIT_4_SCB_CMD(); 714 p->scb->cmd_ruc = RUC_RESUME; 715 sun3_attn586(); 716 WAIT_4_SCB_CMD_RUC(); 717 } 718 else 719 { 720 printk("%s: Receiver-Unit went 'NOT READY': %04x/%02x.\n",dev->name,(int) stat,(int) p->scb->rus); 721 sun3_82586_rnr_int(dev); 722 } 723 } 724 725 if(stat & STAT_CX) /* command with I-bit set complete */ 726 sun3_82586_xmt_int(dev); 727 728 #ifndef NO_NOPCOMMANDS 729 if(stat & STAT_CNA) /* CU went 'not ready' */ 730 { 731 if(netif_running(dev)) 732 printk("%s: oops! CU has left active state. stat: %04x/%02x.\n",dev->name,(int) stat,(int) p->scb->cus); 733 } 734 #endif 735 736 if(debuglevel > 1) 737 printk("%d",cnt++); 738 739 WAIT_4_SCB_CMD(); /* wait for ack. (sun3_82586_xmt_int can be faster than ack!!) */ 740 if(p->scb->cmd_cuc) /* timed out? */ 741 { 742 printk("%s: Acknowledge timed out.\n",dev->name); 743 sun3_disint(); 744 break; 745 } 746 } 747 748 if(debuglevel > 1) 749 printk("i"); 750 return IRQ_HANDLED; 751 } 752 753 /******************************************************* 754 * receive-interrupt 755 */ 756 757 static void sun3_82586_rcv_int(struct net_device *dev) 758 { 759 int status,cnt=0; 760 unsigned short totlen; 761 struct sk_buff *skb; 762 struct rbd_struct *rbd; 763 struct priv *p = netdev_priv(dev); 764 765 if(debuglevel > 0) 766 printk("R"); 767 768 for(;(status = p->rfd_top->stat_high) & RFD_COMPL;) 769 { 770 rbd = (struct rbd_struct *) make32(p->rfd_top->rbd_offset); 771 772 if(status & RFD_OK) /* frame received without error? */ 773 { 774 if( (totlen = swab16(rbd->status)) & RBD_LAST) /* the first and the last buffer? */ 775 { 776 totlen &= RBD_MASK; /* length of this frame */ 777 rbd->status = 0; 778 skb = netdev_alloc_skb(dev, totlen + 2); 779 if(skb != NULL) 780 { 781 skb_reserve(skb,2); 782 skb_put(skb,totlen); 783 skb_copy_to_linear_data(skb,(char *) p->base+swab32((unsigned long) rbd->buffer),totlen); 784 skb->protocol=eth_type_trans(skb,dev); 785 netif_rx(skb); 786 dev->stats.rx_packets++; 787 } 788 else 789 dev->stats.rx_dropped++; 790 } 791 else 792 { 793 int rstat; 794 /* free all RBD's until RBD_LAST is set */ 795 totlen = 0; 796 while(!((rstat=swab16(rbd->status)) & RBD_LAST)) 797 { 798 totlen += rstat & RBD_MASK; 799 if(!rstat) 800 { 801 printk("%s: Whoops .. no end mark in RBD list\n",dev->name); 802 break; 803 } 804 rbd->status = 0; 805 rbd = (struct rbd_struct *) make32(rbd->next); 806 } 807 totlen += rstat & RBD_MASK; 808 rbd->status = 0; 809 printk("%s: received oversized frame! length: %d\n",dev->name,totlen); 810 dev->stats.rx_dropped++; 811 } 812 } 813 else /* frame !(ok), only with 'save-bad-frames' */ 814 { 815 printk("%s: oops! rfd-error-status: %04x\n",dev->name,status); 816 dev->stats.rx_errors++; 817 } 818 p->rfd_top->stat_high = 0; 819 p->rfd_top->last = RFD_SUSP; /* maybe exchange by RFD_LAST */ 820 p->rfd_top->rbd_offset = 0xffff; 821 p->rfd_last->last = 0; /* delete RFD_SUSP */ 822 p->rfd_last = p->rfd_top; 823 p->rfd_top = (struct rfd_struct *) make32(p->rfd_top->next); /* step to next RFD */ 824 p->scb->rfa_offset = make16(p->rfd_top); 825 826 if(debuglevel > 0) 827 printk("%d",cnt++); 828 } 829 830 if(automatic_resume) 831 { 832 WAIT_4_SCB_CMD(); 833 p->scb->cmd_ruc = RUC_RESUME; 834 sun3_attn586(); 835 WAIT_4_SCB_CMD_RUC(); 836 } 837 838 #ifdef WAIT_4_BUSY 839 { 840 int i; 841 for(i=0;i<1024;i++) 842 { 843 if(p->rfd_top->status) 844 break; 845 DELAY_16(); 846 if(i == 1023) 847 printk("%s: RU hasn't fetched next RFD (not busy/complete)\n",dev->name); 848 } 849 } 850 #endif 851 852 #if 0 853 if(!at_least_one) 854 { 855 int i; 856 volatile struct rfd_struct *rfds=p->rfd_top; 857 volatile struct rbd_struct *rbds; 858 printk("%s: received a FC intr. without having a frame: %04x %d\n",dev->name,status,old_at_least); 859 for(i=0;i< (p->num_recv_buffs+4);i++) 860 { 861 rbds = (struct rbd_struct *) make32(rfds->rbd_offset); 862 printk("%04x:%04x ",rfds->status,rbds->status); 863 rfds = (struct rfd_struct *) make32(rfds->next); 864 } 865 printk("\nerrs: %04x %04x stat: %04x\n",(int)p->scb->rsc_errs,(int)p->scb->ovrn_errs,(int)p->scb->status); 866 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); 867 } 868 old_at_least = at_least_one; 869 #endif 870 871 if(debuglevel > 0) 872 printk("r"); 873 } 874 875 /********************************************************** 876 * handle 'Receiver went not ready'. 877 */ 878 879 static void sun3_82586_rnr_int(struct net_device *dev) 880 { 881 struct priv *p = netdev_priv(dev); 882 883 dev->stats.rx_errors++; 884 885 WAIT_4_SCB_CMD(); /* wait for the last cmd, WAIT_4_FULLSTAT?? */ 886 p->scb->cmd_ruc = RUC_ABORT; /* usually the RU is in the 'no resource'-state .. abort it now. */ 887 sun3_attn586(); 888 WAIT_4_SCB_CMD_RUC(); /* wait for accept cmd. */ 889 890 alloc_rfa(dev,(char *)p->rfd_first); 891 /* maybe add a check here, before restarting the RU */ 892 startrecv586(dev); /* restart RU */ 893 894 printk("%s: Receive-Unit restarted. Status: %04x\n",dev->name,p->scb->rus); 895 896 } 897 898 /********************************************************** 899 * handle xmit - interrupt 900 */ 901 902 static void sun3_82586_xmt_int(struct net_device *dev) 903 { 904 int status; 905 struct priv *p = netdev_priv(dev); 906 907 if(debuglevel > 0) 908 printk("X"); 909 910 status = swab16(p->xmit_cmds[p->xmit_last]->cmd_status); 911 if(!(status & STAT_COMPL)) 912 printk("%s: strange .. xmit-int without a 'COMPLETE'\n",dev->name); 913 914 if(status & STAT_OK) 915 { 916 dev->stats.tx_packets++; 917 dev->stats.collisions += (status & TCMD_MAXCOLLMASK); 918 } 919 else 920 { 921 dev->stats.tx_errors++; 922 if(status & TCMD_LATECOLL) { 923 printk("%s: late collision detected.\n",dev->name); 924 dev->stats.collisions++; 925 } 926 else if(status & TCMD_NOCARRIER) { 927 dev->stats.tx_carrier_errors++; 928 printk("%s: no carrier detected.\n",dev->name); 929 } 930 else if(status & TCMD_LOSTCTS) 931 printk("%s: loss of CTS detected.\n",dev->name); 932 else if(status & TCMD_UNDERRUN) { 933 dev->stats.tx_fifo_errors++; 934 printk("%s: DMA underrun detected.\n",dev->name); 935 } 936 else if(status & TCMD_MAXCOLL) { 937 printk("%s: Max. collisions exceeded.\n",dev->name); 938 dev->stats.collisions += 16; 939 } 940 } 941 942 #if (NUM_XMIT_BUFFS > 1) 943 if( (++p->xmit_last) == NUM_XMIT_BUFFS) 944 p->xmit_last = 0; 945 #endif 946 netif_wake_queue(dev); 947 } 948 949 /*********************************************************** 950 * (re)start the receiver 951 */ 952 953 static void startrecv586(struct net_device *dev) 954 { 955 struct priv *p = netdev_priv(dev); 956 957 WAIT_4_SCB_CMD(); 958 WAIT_4_SCB_CMD_RUC(); 959 p->scb->rfa_offset = make16(p->rfd_first); 960 p->scb->cmd_ruc = RUC_START; 961 sun3_attn586(); /* start cmd. */ 962 WAIT_4_SCB_CMD_RUC(); /* wait for accept cmd. (no timeout!!) */ 963 } 964 965 static void sun3_82586_timeout(struct net_device *dev, unsigned int txqueue) 966 { 967 struct priv *p = netdev_priv(dev); 968 #ifndef NO_NOPCOMMANDS 969 if(p->scb->cus & CU_ACTIVE) /* COMMAND-UNIT active? */ 970 { 971 netif_wake_queue(dev); 972 #ifdef DEBUG 973 printk("%s: strange ... timeout with CU active?!?\n",dev->name); 974 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); 975 #endif 976 p->scb->cmd_cuc = CUC_ABORT; 977 sun3_attn586(); 978 WAIT_4_SCB_CMD(); 979 p->scb->cbl_offset = make16(p->nop_cmds[p->nop_point]); 980 p->scb->cmd_cuc = CUC_START; 981 sun3_attn586(); 982 WAIT_4_SCB_CMD(); 983 netif_trans_update(dev); /* prevent tx timeout */ 984 return 0; 985 } 986 #endif 987 { 988 #ifdef DEBUG 989 printk("%s: xmitter timed out, try to restart! stat: %02x\n",dev->name,p->scb->cus); 990 printk("%s: command-stats: %04x %04x\n",dev->name,swab16(p->xmit_cmds[0]->cmd_status),swab16(p->xmit_cmds[1]->cmd_status)); 991 printk("%s: check, whether you set the right interrupt number!\n",dev->name); 992 #endif 993 sun3_82586_close(dev); 994 sun3_82586_open(dev); 995 } 996 netif_trans_update(dev); /* prevent tx timeout */ 997 } 998 999 /****************************************************** 1000 * send frame 1001 */ 1002 1003 static netdev_tx_t 1004 sun3_82586_send_packet(struct sk_buff *skb, struct net_device *dev) 1005 { 1006 int len,i; 1007 #ifndef NO_NOPCOMMANDS 1008 int next_nop; 1009 #endif 1010 struct priv *p = netdev_priv(dev); 1011 1012 if(skb->len > XMIT_BUFF_SIZE) 1013 { 1014 printk("%s: Sorry, max. framelength is %d bytes. The length of your frame is %d bytes.\n",dev->name,XMIT_BUFF_SIZE,skb->len); 1015 return NETDEV_TX_OK; 1016 } 1017 1018 netif_stop_queue(dev); 1019 1020 #if(NUM_XMIT_BUFFS > 1) 1021 if(test_and_set_bit(0,(void *) &p->lock)) { 1022 printk("%s: Queue was locked\n",dev->name); 1023 return NETDEV_TX_BUSY; 1024 } 1025 else 1026 #endif 1027 { 1028 len = skb->len; 1029 if (len < ETH_ZLEN) { 1030 memset((void *)p->xmit_cbuffs[p->xmit_count], 0, 1031 ETH_ZLEN); 1032 len = ETH_ZLEN; 1033 } 1034 skb_copy_from_linear_data(skb, (void *)p->xmit_cbuffs[p->xmit_count], skb->len); 1035 1036 #if (NUM_XMIT_BUFFS == 1) 1037 # ifdef NO_NOPCOMMANDS 1038 1039 #ifdef DEBUG 1040 if(p->scb->cus & CU_ACTIVE) 1041 { 1042 printk("%s: Hmmm .. CU is still running and we wanna send a new packet.\n",dev->name); 1043 printk("%s: stat: %04x %04x\n",dev->name,p->scb->cus,swab16(p->xmit_cmds[0]->cmd_status)); 1044 } 1045 #endif 1046 1047 p->xmit_buffs[0]->size = swab16(TBD_LAST | len); 1048 for(i=0;i<16;i++) 1049 { 1050 p->xmit_cmds[0]->cmd_status = 0; 1051 WAIT_4_SCB_CMD(); 1052 if( (p->scb->cus & CU_STATUS) == CU_SUSPEND) 1053 p->scb->cmd_cuc = CUC_RESUME; 1054 else 1055 { 1056 p->scb->cbl_offset = make16(p->xmit_cmds[0]); 1057 p->scb->cmd_cuc = CUC_START; 1058 } 1059 1060 sun3_attn586(); 1061 if(!i) 1062 dev_kfree_skb(skb); 1063 WAIT_4_SCB_CMD(); 1064 if( (p->scb->cus & CU_ACTIVE)) /* test it, because CU sometimes doesn't start immediately */ 1065 break; 1066 if(p->xmit_cmds[0]->cmd_status) 1067 break; 1068 if(i==15) 1069 printk("%s: Can't start transmit-command.\n",dev->name); 1070 } 1071 # else 1072 next_nop = (p->nop_point + 1) & 0x1; 1073 p->xmit_buffs[0]->size = swab16(TBD_LAST | len); 1074 1075 p->xmit_cmds[0]->cmd_link = p->nop_cmds[next_nop]->cmd_link 1076 = make16((p->nop_cmds[next_nop])); 1077 p->xmit_cmds[0]->cmd_status = p->nop_cmds[next_nop]->cmd_status = 0; 1078 1079 p->nop_cmds[p->nop_point]->cmd_link = make16((p->xmit_cmds[0])); 1080 p->nop_point = next_nop; 1081 dev_kfree_skb(skb); 1082 # endif 1083 #else 1084 p->xmit_buffs[p->xmit_count]->size = swab16(TBD_LAST | len); 1085 if( (next_nop = p->xmit_count + 1) == NUM_XMIT_BUFFS ) 1086 next_nop = 0; 1087 1088 p->xmit_cmds[p->xmit_count]->cmd_status = 0; 1089 /* linkpointer of xmit-command already points to next nop cmd */ 1090 p->nop_cmds[next_nop]->cmd_link = make16((p->nop_cmds[next_nop])); 1091 p->nop_cmds[next_nop]->cmd_status = 0; 1092 1093 p->nop_cmds[p->xmit_count]->cmd_link = make16((p->xmit_cmds[p->xmit_count])); 1094 p->xmit_count = next_nop; 1095 1096 { 1097 unsigned long flags; 1098 local_irq_save(flags); 1099 if(p->xmit_count != p->xmit_last) 1100 netif_wake_queue(dev); 1101 p->lock = 0; 1102 local_irq_restore(flags); 1103 } 1104 dev_kfree_skb(skb); 1105 #endif 1106 } 1107 return NETDEV_TX_OK; 1108 } 1109 1110 /******************************************* 1111 * Someone wanna have the statistics 1112 */ 1113 1114 static struct net_device_stats *sun3_82586_get_stats(struct net_device *dev) 1115 { 1116 struct priv *p = netdev_priv(dev); 1117 unsigned short crc,aln,rsc,ovrn; 1118 1119 crc = swab16(p->scb->crc_errs); /* get error-statistic from the ni82586 */ 1120 p->scb->crc_errs = 0; 1121 aln = swab16(p->scb->aln_errs); 1122 p->scb->aln_errs = 0; 1123 rsc = swab16(p->scb->rsc_errs); 1124 p->scb->rsc_errs = 0; 1125 ovrn = swab16(p->scb->ovrn_errs); 1126 p->scb->ovrn_errs = 0; 1127 1128 dev->stats.rx_crc_errors += crc; 1129 dev->stats.rx_fifo_errors += ovrn; 1130 dev->stats.rx_frame_errors += aln; 1131 dev->stats.rx_dropped += rsc; 1132 1133 return &dev->stats; 1134 } 1135 1136 /******************************************************** 1137 * Set MC list .. 1138 */ 1139 1140 static void set_multicast_list(struct net_device *dev) 1141 { 1142 netif_stop_queue(dev); 1143 sun3_disint(); 1144 alloc586(dev); 1145 init586(dev); 1146 startrecv586(dev); 1147 sun3_enaint(); 1148 netif_wake_queue(dev); 1149 } 1150 1151 #if 0 1152 /* 1153 * DUMP .. we expect a not running CMD unit and enough space 1154 */ 1155 void sun3_82586_dump(struct net_device *dev,void *ptr) 1156 { 1157 struct priv *p = netdev_priv(dev); 1158 struct dump_cmd_struct *dump_cmd = (struct dump_cmd_struct *) ptr; 1159 int i; 1160 1161 p->scb->cmd_cuc = CUC_ABORT; 1162 sun3_attn586(); 1163 WAIT_4_SCB_CMD(); 1164 WAIT_4_SCB_CMD_RUC(); 1165 1166 dump_cmd->cmd_status = 0; 1167 dump_cmd->cmd_cmd = CMD_DUMP | CMD_LAST; 1168 dump_cmd->dump_offset = make16((dump_cmd + 1)); 1169 dump_cmd->cmd_link = 0xffff; 1170 1171 p->scb->cbl_offset = make16(dump_cmd); 1172 p->scb->cmd_cuc = CUC_START; 1173 sun3_attn586(); 1174 WAIT_4_STAT_COMPL(dump_cmd); 1175 1176 if( (dump_cmd->cmd_status & (STAT_COMPL|STAT_OK)) != (STAT_COMPL|STAT_OK) ) 1177 printk("%s: Can't get dump information.\n",dev->name); 1178 1179 for(i=0;i<170;i++) { 1180 printk("%02x ",(int) ((unsigned char *) (dump_cmd + 1))[i]); 1181 if(i % 24 == 23) 1182 printk("\n"); 1183 } 1184 printk("\n"); 1185 } 1186 #endif 1187