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