1/* Intel Professional Workstation/panther ethernet driver */ 2/* lp486e.c: A panther 82596 ethernet driver for linux. */ 3/* 4 History and copyrights: 5 6 Driver skeleton 7 Written 1993 by Donald Becker. 8 Copyright 1993 United States Government as represented by the Director, 9 National Security Agency. This software may only be used and 10 distributed according to the terms of the GNU General Public License 11 as modified by SRC, incorporated herein by reference. 12 13 The author may be reached as becker@scyld.com, or C/O 14 Scyld Computing Corporation 15 410 Severn Ave., Suite 210 16 Annapolis MD 21403 17 18 Apricot 19 Written 1994 by Mark Evans. 20 This driver is for the Apricot 82596 bus-master interface 21 22 Modularised 12/94 Mark Evans 23 24 Professional Workstation 25 Derived from apricot.c by Ard van Breemen 26 <ard@murphy.nl>|<ard@cstmel.hobby.nl>|<ard@cstmel.nl.eu.org> 27 28 Credits: 29 Thanks to Murphy Software BV for letting me write this in their time. 30 Well, actually, I get payed doing this... 31 (Also: see http://www.murphy.nl for murphy, and my homepage ~ard for 32 more information on the Professional Workstation) 33 34 Present version 35 aeb@cwi.nl 36*/ 37/* 38 There are currently two motherboards that I know of in the 39 professional workstation. The only one that I know is the 40 intel panther motherboard. -- ard 41*/ 42/* 43The pws is equipped with an intel 82596. This is a very intelligent controller 44which runs its own micro-code. Communication with the hostprocessor is done 45through linked lists of commands and buffers in the hostprocessors memory. 46A complete description of the 82596 is available from intel. Search for 47a file called "29021806.pdf". It is a complete description of the chip itself. 48To use it for the pws some additions are needed regarding generation of 49the PORT and CA signal, and the interrupt glue needed for a pc. 50I/O map: 51PORT SIZE ACTION MEANING 520xCB0 2 WRITE Lower 16 bits for PORT command 530xCB2 2 WRITE Upper 16 bits for PORT command, and issue of PORT command 540xCB4 1 WRITE Generation of CA signal 550xCB8 1 WRITE Clear interrupt glue 56All other communication is through memory! 57*/ 58 59#include <linux/module.h> 60#include <linux/init.h> 61#include <linux/delay.h> 62#include <linux/kernel.h> 63#include <linux/string.h> 64#include <linux/errno.h> 65#include <linux/ioport.h> 66#include <linux/slab.h> 67#include <linux/interrupt.h> 68#include <linux/netdevice.h> 69#include <linux/etherdevice.h> 70#include <linux/skbuff.h> 71#include <linux/bitops.h> 72 73#include <asm/io.h> 74#include <asm/dma.h> 75 76#define DRV_NAME "lp486e" 77 78/* debug print flags */ 79#define LOG_SRCDST 0x80000000 80#define LOG_STATINT 0x40000000 81#define LOG_STARTINT 0x20000000 82 83#define i596_debug debug 84 85static int i596_debug = 0; 86 87static const char * const medianame[] = { 88 "10baseT", "AUI", 89 "10baseT-FD", "AUI-FD", 90}; 91 92#define LP486E_TOTAL_SIZE 16 93 94#define I596_NULL (0xffffffff) 95 96#define CMD_EOL 0x8000 /* The last command of the list, stop. */ 97#define CMD_SUSP 0x4000 /* Suspend after doing cmd. */ 98#define CMD_INTR 0x2000 /* Interrupt after doing cmd. */ 99 100#define CMD_FLEX 0x0008 /* Enable flexible memory model */ 101 102enum commands { 103 CmdNOP = 0, 104 CmdIASetup = 1, 105 CmdConfigure = 2, 106 CmdMulticastList = 3, 107 CmdTx = 4, 108 CmdTDR = 5, 109 CmdDump = 6, 110 CmdDiagnose = 7 111}; 112 113 114/* Status word bits */ 115#define STAT_CX 0x8000 /* The CU finished executing a command 116 with the Interrupt bit set */ 117#define STAT_FR 0x4000 /* The RU finished receiving a frame */ 118#define STAT_CNA 0x2000 /* The CU left the active state */ 119#define STAT_RNR 0x1000 /* The RU left the active state */ 120#define STAT_ACK (STAT_CX | STAT_FR | STAT_CNA | STAT_RNR) 121#define STAT_CUS 0x0700 /* Status of CU: 0: idle, 1: suspended, 122 2: active, 3-7: unused */ 123#define STAT_RUS 0x00f0 /* Status of RU: 0: idle, 1: suspended, 124 2: no resources, 4: ready, 125 10: no resources due to no more RBDs, 126 12: no more RBDs, other: unused */ 127#define STAT_T 0x0008 /* Bus throttle timers loaded */ 128#define STAT_ZERO 0x0807 /* Always zero */ 129 130 131/* Command word bits */ 132#define ACK_CX 0x8000 133#define ACK_FR 0x4000 134#define ACK_CNA 0x2000 135#define ACK_RNR 0x1000 136 137#define CUC_START 0x0100 138#define CUC_RESUME 0x0200 139#define CUC_SUSPEND 0x0300 140#define CUC_ABORT 0x0400 141 142#define RX_START 0x0010 143#define RX_RESUME 0x0020 144#define RX_SUSPEND 0x0030 145#define RX_ABORT 0x0040 146 147typedef u32 phys_addr; 148 149static inline phys_addr 150va_to_pa(void *x) { 151 return x ? virt_to_bus(x) : I596_NULL; 152} 153 154static inline void * 155pa_to_va(phys_addr x) { 156 return (x == I596_NULL) ? NULL : bus_to_virt(x); 157} 158 159/* status bits for cmd */ 160#define CMD_STAT_C 0x8000 /* CU command complete */ 161#define CMD_STAT_B 0x4000 /* CU command in progress */ 162#define CMD_STAT_OK 0x2000 /* CU command completed without errors */ 163#define CMD_STAT_A 0x1000 /* CU command abnormally terminated */ 164 165struct i596_cmd { /* 8 bytes */ 166 unsigned short status; 167 unsigned short command; 168 phys_addr pa_next; /* va_to_pa(struct i596_cmd *next) */ 169}; 170 171#define EOF 0x8000 172#define SIZE_MASK 0x3fff 173 174struct i596_tbd { 175 unsigned short size; 176 unsigned short pad; 177 phys_addr pa_next; /* va_to_pa(struct i596_tbd *next) */ 178 phys_addr pa_data; /* va_to_pa(char *data) */ 179 struct sk_buff *skb; 180}; 181 182struct tx_cmd { 183 struct i596_cmd cmd; 184 phys_addr pa_tbd; /* va_to_pa(struct i596_tbd *tbd) */ 185 unsigned short size; 186 unsigned short pad; 187}; 188 189/* status bits for rfd */ 190#define RFD_STAT_C 0x8000 /* Frame reception complete */ 191#define RFD_STAT_B 0x4000 /* Frame reception in progress */ 192#define RFD_STAT_OK 0x2000 /* Frame received without errors */ 193#define RFD_STATUS 0x1fff 194#define RFD_LENGTH_ERR 0x1000 195#define RFD_CRC_ERR 0x0800 196#define RFD_ALIGN_ERR 0x0400 197#define RFD_NOBUFS_ERR 0x0200 198#define RFD_DMA_ERR 0x0100 /* DMA overrun failure to acquire system bus */ 199#define RFD_SHORT_FRAME_ERR 0x0080 200#define RFD_NOEOP_ERR 0x0040 201#define RFD_TRUNC_ERR 0x0020 202#define RFD_MULTICAST 0x0002 /* 0: destination had our address 203 1: destination was broadcast/multicast */ 204#define RFD_COLLISION 0x0001 205 206/* receive frame descriptor */ 207struct i596_rfd { 208 unsigned short stat; 209 unsigned short cmd; 210 phys_addr pa_next; /* va_to_pa(struct i596_rfd *next) */ 211 phys_addr pa_rbd; /* va_to_pa(struct i596_rbd *rbd) */ 212 unsigned short count; 213 unsigned short size; 214 char data[1532]; 215}; 216 217#define RBD_EL 0x8000 218#define RBD_P 0x4000 219#define RBD_SIZEMASK 0x3fff 220#define RBD_EOF 0x8000 221#define RBD_F 0x4000 222 223/* receive buffer descriptor */ 224struct i596_rbd { 225 unsigned short size; 226 unsigned short pad; 227 phys_addr pa_next; /* va_to_pa(struct i596_tbd *next) */ 228 phys_addr pa_data; /* va_to_pa(char *data) */ 229 phys_addr pa_prev; /* va_to_pa(struct i596_tbd *prev) */ 230 231 /* Driver private part */ 232 struct sk_buff *skb; 233}; 234 235#define RX_RING_SIZE 64 236#define RX_SKBSIZE (ETH_FRAME_LEN+10) 237#define RX_RBD_SIZE 32 238 239/* System Control Block - 40 bytes */ 240struct i596_scb { 241 u16 status; /* 0 */ 242 u16 command; /* 2 */ 243 phys_addr pa_cmd; /* 4 - va_to_pa(struct i596_cmd *cmd) */ 244 phys_addr pa_rfd; /* 8 - va_to_pa(struct i596_rfd *rfd) */ 245 u32 crc_err; /* 12 */ 246 u32 align_err; /* 16 */ 247 u32 resource_err; /* 20 */ 248 u32 over_err; /* 24 */ 249 u32 rcvdt_err; /* 28 */ 250 u32 short_err; /* 32 */ 251 u16 t_on; /* 36 */ 252 u16 t_off; /* 38 */ 253}; 254 255/* Intermediate System Configuration Pointer - 8 bytes */ 256struct i596_iscp { 257 u32 busy; /* 0 */ 258 phys_addr pa_scb; /* 4 - va_to_pa(struct i596_scb *scb) */ 259}; 260 261/* System Configuration Pointer - 12 bytes */ 262struct i596_scp { 263 u32 sysbus; /* 0 */ 264 u32 pad; /* 4 */ 265 phys_addr pa_iscp; /* 8 - va_to_pa(struct i596_iscp *iscp) */ 266}; 267 268/* Selftest and dump results - needs 16-byte alignment */ 269/* 270 * The size of the dump area is 304 bytes. When the dump is executed 271 * by the Port command an extra word will be appended to the dump area. 272 * The extra word is a copy of the Dump status word (containing the 273 * C, B, OK bits). [I find 0xa006, with a0 for C+OK and 6 for dump] 274 */ 275struct i596_dump { 276 u16 dump[153]; /* (304 = 130h) + 2 bytes */ 277}; 278 279struct i596_private { /* aligned to a 16-byte boundary */ 280 struct i596_scp scp; /* 0 - needs 16-byte alignment */ 281 struct i596_iscp iscp; /* 12 */ 282 struct i596_scb scb; /* 20 */ 283 u32 dummy; /* 60 */ 284 struct i596_dump dump; /* 64 - needs 16-byte alignment */ 285 286 struct i596_cmd set_add; 287 char eth_addr[8]; /* directly follows set_add */ 288 289 struct i596_cmd set_conf; 290 char i596_config[16]; /* directly follows set_conf */ 291 292 struct i596_cmd tdr; 293 unsigned long tdr_stat; /* directly follows tdr */ 294 295 int last_restart; 296 struct i596_rbd *rbd_list; 297 struct i596_rbd *rbd_tail; 298 struct i596_rfd *rx_tail; 299 struct i596_cmd *cmd_tail; 300 struct i596_cmd *cmd_head; 301 int cmd_backlog; 302 unsigned long last_cmd; 303 spinlock_t cmd_lock; 304}; 305 306static char init_setup[14] = { 307 0x8E, /* length 14 bytes, prefetch on */ 308 0xC8, /* default: fifo to 8, monitor off */ 309 0x40, /* default: don't save bad frames (apricot.c had 0x80) */ 310 0x2E, /* (default is 0x26) 311 No source address insertion, 8 byte preamble */ 312 0x00, /* default priority and backoff */ 313 0x60, /* default interframe spacing */ 314 0x00, /* default slot time LSB */ 315 0xf2, /* default slot time and nr of retries */ 316 0x00, /* default various bits 317 (0: promiscuous mode, 1: broadcast disable, 318 2: encoding mode, 3: transmit on no CRS, 319 4: no CRC insertion, 5: CRC type, 320 6: bit stuffing, 7: padding) */ 321 0x00, /* default carrier sense and collision detect */ 322 0x40, /* default minimum frame length */ 323 0xff, /* (default is 0xff, and that is what apricot.c has; 324 elp486.c has 0xfb: Enable crc append in memory.) */ 325 0x00, /* default: not full duplex */ 326 0x7f /* (default is 0x3f) multi IA */ 327}; 328 329static int i596_open(struct net_device *dev); 330static netdev_tx_t i596_start_xmit(struct sk_buff *skb, struct net_device *dev); 331static irqreturn_t i596_interrupt(int irq, void *dev_id); 332static int i596_close(struct net_device *dev); 333static void i596_add_cmd(struct net_device *dev, struct i596_cmd *cmd); 334static void print_eth(char *); 335static void set_multicast_list(struct net_device *dev); 336static void i596_tx_timeout(struct net_device *dev); 337 338static int 339i596_timeout(struct net_device *dev, char *msg, int ct) { 340 struct i596_private *lp; 341 int boguscnt = ct; 342 343 lp = netdev_priv(dev); 344 while (lp->scb.command) { 345 if (--boguscnt == 0) { 346 printk("%s: %s timed out - stat %4.4x, cmd %4.4x\n", 347 dev->name, msg, 348 lp->scb.status, lp->scb.command); 349 return 1; 350 } 351 udelay(5); 352 barrier(); 353 } 354 return 0; 355} 356 357static inline int 358init_rx_bufs(struct net_device *dev, int num) { 359 struct i596_private *lp; 360 struct i596_rfd *rfd; 361 int i; 362 // struct i596_rbd *rbd; 363 364 lp = netdev_priv(dev); 365 lp->scb.pa_rfd = I596_NULL; 366 367 for (i = 0; i < num; i++) { 368 rfd = kmalloc(sizeof(struct i596_rfd), GFP_KERNEL); 369 if (rfd == NULL) 370 break; 371 372 rfd->stat = 0; 373 rfd->pa_rbd = I596_NULL; 374 rfd->count = 0; 375 rfd->size = 1532; 376 if (i == 0) { 377 rfd->cmd = CMD_EOL; 378 lp->rx_tail = rfd; 379 } else { 380 rfd->cmd = 0; 381 } 382 rfd->pa_next = lp->scb.pa_rfd; 383 lp->scb.pa_rfd = va_to_pa(rfd); 384 lp->rx_tail->pa_next = lp->scb.pa_rfd; 385 } 386 387 return (i); 388} 389 390static inline void 391remove_rx_bufs(struct net_device *dev) { 392 struct i596_private *lp; 393 struct i596_rfd *rfd; 394 395 lp = netdev_priv(dev); 396 lp->rx_tail->pa_next = I596_NULL; 397 398 do { 399 rfd = pa_to_va(lp->scb.pa_rfd); 400 lp->scb.pa_rfd = rfd->pa_next; 401 kfree(rfd); 402 } while (rfd != lp->rx_tail); 403 404 lp->rx_tail = NULL; 405 406} 407 408#define PORT_RESET 0x00 /* reset 82596 */ 409#define PORT_SELFTEST 0x01 /* selftest */ 410#define PORT_ALTSCP 0x02 /* alternate SCB address */ 411#define PORT_DUMP 0x03 /* dump */ 412 413#define IOADDR 0xcb0 /* real constant */ 414#define IRQ 10 /* default IRQ - can be changed by ECU */ 415 416/* The 82596 requires two 16-bit write cycles for a port command */ 417static inline void 418PORT(phys_addr a, unsigned int cmd) { 419 if (a & 0xf) 420 printk("lp486e.c: PORT: address not aligned\n"); 421 outw(((a & 0xffff) | cmd), IOADDR); 422 outw(((a>>16) & 0xffff), IOADDR+2); 423} 424 425static inline void 426CA(void) { 427 outb(0, IOADDR+4); 428 udelay(8); 429} 430 431static inline void 432CLEAR_INT(void) { 433 outb(0, IOADDR+8); 434} 435 436 437static int 438i596_scp_setup(struct net_device *dev) { 439 struct i596_private *lp = netdev_priv(dev); 440 int boguscnt; 441 442 /* Setup SCP, ISCP, SCB */ 443 /* 444 * sysbus bits: 445 * only a single byte is significant - here 0x44 446 * 0x80: big endian mode (details depend on stepping) 447 * 0x40: 1 448 * 0x20: interrupt pin is active low 449 * 0x10: lock function disabled 450 * 0x08: external triggering of bus throttle timers 451 * 0x06: 00: 82586 compat mode, 01: segmented mode, 10: linear mode 452 * 0x01: unused 453 */ 454 lp->scp.sysbus = 0x00440000; /* linear mode */ 455 lp->scp.pad = 0; /* must be zero */ 456 lp->scp.pa_iscp = va_to_pa(&(lp->iscp)); 457 458 /* 459 * The CPU sets the ISCP to 1 before it gives the first CA() 460 */ 461 lp->iscp.busy = 0x0001; 462 lp->iscp.pa_scb = va_to_pa(&(lp->scb)); 463 464 lp->scb.command = 0; 465 lp->scb.status = 0; 466 lp->scb.pa_cmd = I596_NULL; 467 /* lp->scb.pa_rfd has been initialised already */ 468 469 lp->last_cmd = jiffies; 470 lp->cmd_backlog = 0; 471 lp->cmd_head = NULL; 472 473 /* 474 * Reset the 82596. 475 * We need to wait 10 systemclock cycles, and 476 * 5 serial clock cycles. 477 */ 478 PORT(0, PORT_RESET); /* address part ignored */ 479 udelay(100); 480 481 /* 482 * Before the CA signal is asserted, the default SCP address 483 * (0x00fffff4) can be changed to a 16-byte aligned value 484 */ 485 PORT(va_to_pa(&lp->scp), PORT_ALTSCP); /* change the scp address */ 486 487 /* 488 * The initialization procedure begins when a 489 * Channel Attention signal is asserted after a reset. 490 */ 491 492 CA(); 493 494 /* 495 * The ISCP busy is cleared by the 82596 after the SCB address is read. 496 */ 497 boguscnt = 100; 498 while (lp->iscp.busy) { 499 if (--boguscnt == 0) { 500 /* No i82596 present? */ 501 printk("%s: i82596 initialization timed out\n", 502 dev->name); 503 return 1; 504 } 505 udelay(5); 506 barrier(); 507 } 508 /* I find here boguscnt==100, so no delay was required. */ 509 510 return 0; 511} 512 513static int 514init_i596(struct net_device *dev) { 515 struct i596_private *lp; 516 517 if (i596_scp_setup(dev)) 518 return 1; 519 520 lp = netdev_priv(dev); 521 lp->scb.command = 0; 522 523 memcpy ((void *)lp->i596_config, init_setup, 14); 524 lp->set_conf.command = CmdConfigure; 525 i596_add_cmd(dev, (void *)&lp->set_conf); 526 527 memcpy ((void *)lp->eth_addr, dev->dev_addr, 6); 528 lp->set_add.command = CmdIASetup; 529 i596_add_cmd(dev, (struct i596_cmd *)&lp->set_add); 530 531 lp->tdr.command = CmdTDR; 532 i596_add_cmd(dev, (struct i596_cmd *)&lp->tdr); 533 534 if (lp->scb.command && i596_timeout(dev, "i82596 init", 200)) 535 return 1; 536 537 lp->scb.command = RX_START; 538 CA(); 539 540 barrier(); 541 542 if (lp->scb.command && i596_timeout(dev, "Receive Unit start", 100)) 543 return 1; 544 545 return 0; 546} 547 548/* Receive a single frame */ 549static inline int 550i596_rx_one(struct net_device *dev, struct i596_private *lp, 551 struct i596_rfd *rfd, int *frames) { 552 553 if (rfd->stat & RFD_STAT_OK) { 554 /* a good frame */ 555 int pkt_len = (rfd->count & 0x3fff); 556 struct sk_buff *skb = dev_alloc_skb(pkt_len); 557 558 (*frames)++; 559 560 if (rfd->cmd & CMD_EOL) 561 printk("Received on EOL\n"); 562 563 if (skb == NULL) { 564 printk ("%s: i596_rx Memory squeeze, " 565 "dropping packet.\n", dev->name); 566 dev->stats.rx_dropped++; 567 return 1; 568 } 569 570 memcpy(skb_put(skb,pkt_len), rfd->data, pkt_len); 571 572 skb->protocol = eth_type_trans(skb,dev); 573 netif_rx(skb); 574 dev->stats.rx_packets++; 575 } else { 576 dev->stats.rx_errors++; 577 if (rfd->stat & RFD_COLLISION) 578 dev->stats.collisions++; 579 if (rfd->stat & RFD_SHORT_FRAME_ERR) 580 dev->stats.rx_length_errors++; 581 if (rfd->stat & RFD_DMA_ERR) 582 dev->stats.rx_over_errors++; 583 if (rfd->stat & RFD_NOBUFS_ERR) 584 dev->stats.rx_fifo_errors++; 585 if (rfd->stat & RFD_ALIGN_ERR) 586 dev->stats.rx_frame_errors++; 587 if (rfd->stat & RFD_CRC_ERR) 588 dev->stats.rx_crc_errors++; 589 if (rfd->stat & RFD_LENGTH_ERR) 590 dev->stats.rx_length_errors++; 591 } 592 rfd->stat = rfd->count = 0; 593 return 0; 594} 595 596static int 597i596_rx(struct net_device *dev) { 598 struct i596_private *lp = netdev_priv(dev); 599 struct i596_rfd *rfd; 600 int frames = 0; 601 602 while (1) { 603 rfd = pa_to_va(lp->scb.pa_rfd); 604 if (!rfd) { 605 printk(KERN_ERR "i596_rx: NULL rfd?\n"); 606 return 0; 607 } 608 if (rfd->stat && !(rfd->stat & (RFD_STAT_C | RFD_STAT_B))) 609 printk("SF:%p-%04x\n", rfd, rfd->stat); 610 if (!(rfd->stat & RFD_STAT_C)) 611 break; /* next one not ready */ 612 if (i596_rx_one(dev, lp, rfd, &frames)) 613 break; /* out of memory */ 614 rfd->cmd = CMD_EOL; 615 lp->rx_tail->cmd = 0; 616 lp->rx_tail = rfd; 617 lp->scb.pa_rfd = rfd->pa_next; 618 barrier(); 619 } 620 621 return frames; 622} 623 624static void 625i596_cleanup_cmd(struct net_device *dev) { 626 struct i596_private *lp; 627 struct i596_cmd *cmd; 628 629 lp = netdev_priv(dev); 630 while (lp->cmd_head) { 631 cmd = (struct i596_cmd *)lp->cmd_head; 632 633 lp->cmd_head = pa_to_va(lp->cmd_head->pa_next); 634 lp->cmd_backlog--; 635 636 switch ((cmd->command) & 0x7) { 637 case CmdTx: { 638 struct tx_cmd *tx_cmd = (struct tx_cmd *) cmd; 639 struct i596_tbd * tx_cmd_tbd; 640 tx_cmd_tbd = pa_to_va(tx_cmd->pa_tbd); 641 642 dev_kfree_skb_any(tx_cmd_tbd->skb); 643 644 dev->stats.tx_errors++; 645 dev->stats.tx_aborted_errors++; 646 647 cmd->pa_next = I596_NULL; 648 kfree((unsigned char *)tx_cmd); 649 netif_wake_queue(dev); 650 break; 651 } 652 case CmdMulticastList: { 653 // unsigned short count = *((unsigned short *) (ptr + 1)); 654 655 cmd->pa_next = I596_NULL; 656 kfree((unsigned char *)cmd); 657 break; 658 } 659 default: { 660 cmd->pa_next = I596_NULL; 661 break; 662 } 663 } 664 barrier(); 665 } 666 667 if (lp->scb.command && i596_timeout(dev, "i596_cleanup_cmd", 100)) 668 ; 669 670 lp->scb.pa_cmd = va_to_pa(lp->cmd_head); 671} 672 673static void i596_reset(struct net_device *dev, struct i596_private *lp, int ioaddr) { 674 675 if (lp->scb.command && i596_timeout(dev, "i596_reset", 100)) 676 ; 677 678 netif_stop_queue(dev); 679 680 lp->scb.command = CUC_ABORT | RX_ABORT; 681 CA(); 682 barrier(); 683 684 /* wait for shutdown */ 685 if (lp->scb.command && i596_timeout(dev, "i596_reset(2)", 400)) 686 ; 687 688 i596_cleanup_cmd(dev); 689 i596_rx(dev); 690 691 netif_start_queue(dev); 692 /*dev_kfree_skb(skb, FREE_WRITE);*/ 693 init_i596(dev); 694} 695 696static void i596_add_cmd(struct net_device *dev, struct i596_cmd *cmd) { 697 struct i596_private *lp = netdev_priv(dev); 698 int ioaddr = dev->base_addr; 699 unsigned long flags; 700 701 cmd->status = 0; 702 cmd->command |= (CMD_EOL | CMD_INTR); 703 cmd->pa_next = I596_NULL; 704 705 spin_lock_irqsave(&lp->cmd_lock, flags); 706 707 if (lp->cmd_head) { 708 lp->cmd_tail->pa_next = va_to_pa(cmd); 709 } else { 710 lp->cmd_head = cmd; 711 if (lp->scb.command && i596_timeout(dev, "i596_add_cmd", 100)) 712 ; 713 lp->scb.pa_cmd = va_to_pa(cmd); 714 lp->scb.command = CUC_START; 715 CA(); 716 } 717 lp->cmd_tail = cmd; 718 lp->cmd_backlog++; 719 720 lp->cmd_head = pa_to_va(lp->scb.pa_cmd); 721 spin_unlock_irqrestore(&lp->cmd_lock, flags); 722 723 if (lp->cmd_backlog > 16) { 724 int tickssofar = jiffies - lp->last_cmd; 725 if (tickssofar < HZ/4) 726 return; 727 728 printk(KERN_WARNING "%s: command unit timed out, status resetting.\n", dev->name); 729 i596_reset(dev, lp, ioaddr); 730 } 731} 732 733static int i596_open(struct net_device *dev) 734{ 735 int i; 736 737 i = request_irq(dev->irq, i596_interrupt, IRQF_SHARED, dev->name, dev); 738 if (i) { 739 printk(KERN_ERR "%s: IRQ %d not free\n", dev->name, dev->irq); 740 return i; 741 } 742 743 if ((i = init_rx_bufs(dev, RX_RING_SIZE)) < RX_RING_SIZE) 744 printk(KERN_ERR "%s: only able to allocate %d receive buffers\n", dev->name, i); 745 746 if (i < 4) { 747 free_irq(dev->irq, dev); 748 return -EAGAIN; 749 } 750 netif_start_queue(dev); 751 init_i596(dev); 752 return 0; /* Always succeed */ 753} 754 755static netdev_tx_t i596_start_xmit (struct sk_buff *skb, struct net_device *dev) { 756 struct tx_cmd *tx_cmd; 757 short length; 758 759 length = skb->len; 760 761 if (length < ETH_ZLEN) { 762 if (skb_padto(skb, ETH_ZLEN)) 763 return NETDEV_TX_OK; 764 length = ETH_ZLEN; 765 } 766 767 tx_cmd = kmalloc((sizeof (struct tx_cmd) + sizeof (struct i596_tbd)), GFP_ATOMIC); 768 if (tx_cmd == NULL) { 769 printk(KERN_WARNING "%s: i596_xmit Memory squeeze, dropping packet.\n", dev->name); 770 dev->stats.tx_dropped++; 771 dev_kfree_skb (skb); 772 } else { 773 struct i596_tbd *tx_cmd_tbd; 774 tx_cmd_tbd = (struct i596_tbd *) (tx_cmd + 1); 775 tx_cmd->pa_tbd = va_to_pa (tx_cmd_tbd); 776 tx_cmd_tbd->pa_next = I596_NULL; 777 778 tx_cmd->cmd.command = (CMD_FLEX | CmdTx); 779 780 tx_cmd->pad = 0; 781 tx_cmd->size = 0; 782 tx_cmd_tbd->pad = 0; 783 tx_cmd_tbd->size = (EOF | length); 784 785 tx_cmd_tbd->pa_data = va_to_pa (skb->data); 786 tx_cmd_tbd->skb = skb; 787 788 if (i596_debug & LOG_SRCDST) 789 print_eth (skb->data); 790 791 i596_add_cmd (dev, (struct i596_cmd *) tx_cmd); 792 793 dev->stats.tx_packets++; 794 } 795 796 return NETDEV_TX_OK; 797} 798 799static void 800i596_tx_timeout (struct net_device *dev) { 801 struct i596_private *lp = netdev_priv(dev); 802 int ioaddr = dev->base_addr; 803 804 /* Transmitter timeout, serious problems. */ 805 printk(KERN_WARNING "%s: transmit timed out, status resetting.\n", dev->name); 806 dev->stats.tx_errors++; 807 808 /* Try to restart the adaptor */ 809 if (lp->last_restart == dev->stats.tx_packets) { 810 printk ("Resetting board.\n"); 811 812 /* Shutdown and restart */ 813 i596_reset (dev, lp, ioaddr); 814 } else { 815 /* Issue a channel attention signal */ 816 printk ("Kicking board.\n"); 817 lp->scb.command = (CUC_START | RX_START); 818 CA(); 819 lp->last_restart = dev->stats.tx_packets; 820 } 821 netif_wake_queue(dev); 822} 823 824static void print_eth(char *add) 825{ 826 int i; 827 828 printk ("Dest "); 829 for (i = 0; i < 6; i++) 830 printk(" %2.2X", (unsigned char) add[i]); 831 printk ("\n"); 832 833 printk ("Source"); 834 for (i = 0; i < 6; i++) 835 printk(" %2.2X", (unsigned char) add[i+6]); 836 printk ("\n"); 837 838 printk ("type %2.2X%2.2X\n", 839 (unsigned char) add[12], (unsigned char) add[13]); 840} 841 842static const struct net_device_ops i596_netdev_ops = { 843 .ndo_open = i596_open, 844 .ndo_stop = i596_close, 845 .ndo_start_xmit = i596_start_xmit, 846 .ndo_set_multicast_list = set_multicast_list, 847 .ndo_tx_timeout = i596_tx_timeout, 848 .ndo_change_mtu = eth_change_mtu, 849 .ndo_set_mac_address = eth_mac_addr, 850 .ndo_validate_addr = eth_validate_addr, 851}; 852 853static int __init lp486e_probe(struct net_device *dev) { 854 struct i596_private *lp; 855 unsigned char eth_addr[6] = { 0, 0xaa, 0, 0, 0, 0 }; 856 unsigned char *bios; 857 int i, j; 858 int ret = -ENOMEM; 859 static int probed; 860 861 if (probed) 862 return -ENODEV; 863 probed++; 864 865 if (!request_region(IOADDR, LP486E_TOTAL_SIZE, DRV_NAME)) { 866 printk(KERN_ERR "lp486e: IO address 0x%x in use\n", IOADDR); 867 return -EBUSY; 868 } 869 870 lp = netdev_priv(dev); 871 spin_lock_init(&lp->cmd_lock); 872 873 /* 874 * Do we really have this thing? 875 */ 876 if (i596_scp_setup(dev)) { 877 ret = -ENODEV; 878 goto err_out_kfree; 879 } 880 881 dev->base_addr = IOADDR; 882 dev->irq = IRQ; 883 884 885 /* 886 * How do we find the ethernet address? I don't know. 887 * One possibility is to look at the EISA configuration area 888 * [0xe8000-0xe9fff]. This contains the ethernet address 889 * but not at a fixed address - things depend on setup options. 890 * 891 * If we find no address, or the wrong address, use 892 * ifconfig eth0 hw ether a1:a2:a3:a4:a5:a6 893 * with the value found in the BIOS setup. 894 */ 895 bios = bus_to_virt(0xe8000); 896 for (j = 0; j < 0x2000; j++) { 897 if (bios[j] == 0 && bios[j+1] == 0xaa && bios[j+2] == 0) { 898 printk("%s: maybe address at BIOS 0x%x:", 899 dev->name, 0xe8000+j); 900 for (i = 0; i < 6; i++) { 901 eth_addr[i] = bios[i+j]; 902 printk(" %2.2X", eth_addr[i]); 903 } 904 printk("\n"); 905 } 906 } 907 908 printk("%s: lp486e 82596 at %#3lx, IRQ %d,", 909 dev->name, dev->base_addr, dev->irq); 910 for (i = 0; i < 6; i++) 911 printk(" %2.2X", dev->dev_addr[i] = eth_addr[i]); 912 printk("\n"); 913 914 /* The LP486E-specific entries in the device structure. */ 915 dev->netdev_ops = &i596_netdev_ops; 916 dev->watchdog_timeo = 5*HZ; 917 918 return 0; 919 920err_out_kfree: 921 release_region(IOADDR, LP486E_TOTAL_SIZE); 922 return ret; 923} 924 925static inline void 926i596_handle_CU_completion(struct net_device *dev, 927 struct i596_private *lp, 928 unsigned short status, 929 unsigned short *ack_cmdp) { 930 struct i596_cmd *cmd; 931 int frames_out = 0; 932 int commands_done = 0; 933 int cmd_val; 934 unsigned long flags; 935 936 spin_lock_irqsave(&lp->cmd_lock, flags); 937 cmd = lp->cmd_head; 938 939 while (lp->cmd_head && (lp->cmd_head->status & CMD_STAT_C)) { 940 cmd = lp->cmd_head; 941 942 lp->cmd_head = pa_to_va(lp->cmd_head->pa_next); 943 lp->cmd_backlog--; 944 945 commands_done++; 946 cmd_val = cmd->command & 0x7; 947 switch (cmd_val) { 948 case CmdTx: 949 { 950 struct tx_cmd *tx_cmd; 951 struct i596_tbd *tx_cmd_tbd; 952 953 tx_cmd = (struct tx_cmd *) cmd; 954 tx_cmd_tbd = pa_to_va(tx_cmd->pa_tbd); 955 956 frames_out++; 957 if (cmd->status & CMD_STAT_OK) { 958 if (i596_debug) 959 print_eth(pa_to_va(tx_cmd_tbd->pa_data)); 960 } else { 961 dev->stats.tx_errors++; 962 if (i596_debug) 963 printk("transmission failure:%04x\n", 964 cmd->status); 965 if (cmd->status & 0x0020) 966 dev->stats.collisions++; 967 if (!(cmd->status & 0x0040)) 968 dev->stats.tx_heartbeat_errors++; 969 if (cmd->status & 0x0400) 970 dev->stats.tx_carrier_errors++; 971 if (cmd->status & 0x0800) 972 dev->stats.collisions++; 973 if (cmd->status & 0x1000) 974 dev->stats.tx_aborted_errors++; 975 } 976 dev_kfree_skb_irq(tx_cmd_tbd->skb); 977 978 cmd->pa_next = I596_NULL; 979 kfree((unsigned char *)tx_cmd); 980 netif_wake_queue(dev); 981 break; 982 } 983 984 case CmdMulticastList: 985 cmd->pa_next = I596_NULL; 986 kfree((unsigned char *)cmd); 987 break; 988 989 case CmdTDR: 990 { 991 unsigned long status = *((unsigned long *) (cmd + 1)); 992 if (status & 0x8000) { 993 if (i596_debug) 994 printk("%s: link ok.\n", dev->name); 995 } else { 996 if (status & 0x4000) 997 printk("%s: Transceiver problem.\n", 998 dev->name); 999 if (status & 0x2000) 1000 printk("%s: Termination problem.\n", 1001 dev->name); 1002 if (status & 0x1000) 1003 printk("%s: Short circuit.\n", 1004 dev->name); 1005 printk("%s: Time %ld.\n", 1006 dev->name, status & 0x07ff); 1007 } 1008 } 1009 default: 1010 cmd->pa_next = I596_NULL; 1011 lp->last_cmd = jiffies; 1012 1013 } 1014 barrier(); 1015 } 1016 1017 cmd = lp->cmd_head; 1018 while (cmd && (cmd != lp->cmd_tail)) { 1019 cmd->command &= 0x1fff; 1020 cmd = pa_to_va(cmd->pa_next); 1021 barrier(); 1022 } 1023 1024 if (lp->cmd_head) 1025 *ack_cmdp |= CUC_START; 1026 lp->scb.pa_cmd = va_to_pa(lp->cmd_head); 1027 spin_unlock_irqrestore(&lp->cmd_lock, flags); 1028} 1029 1030static irqreturn_t 1031i596_interrupt(int irq, void *dev_instance) 1032{ 1033 struct net_device *dev = dev_instance; 1034 struct i596_private *lp = netdev_priv(dev); 1035 unsigned short status, ack_cmd = 0; 1036 int frames_in = 0; 1037 1038 /* 1039 * The 82596 examines the command, performs the required action, 1040 * and then clears the SCB command word. 1041 */ 1042 if (lp->scb.command && i596_timeout(dev, "interrupt", 40)) 1043 ; 1044 1045 /* 1046 * The status word indicates the status of the 82596. 1047 * It is modified only by the 82596. 1048 * 1049 * [So, we must not clear it. I find often status 0xffff, 1050 * which is not one of the values allowed by the docs.] 1051 */ 1052 status = lp->scb.status; 1053 /* Impossible, but it happens - perhaps when we get 1054 a receive interrupt but scb.pa_rfd is I596_NULL. */ 1055 if (status == 0xffff) { 1056 printk("%s: i596_interrupt: got status 0xffff\n", dev->name); 1057 goto out; 1058 } 1059 1060 ack_cmd = (status & STAT_ACK); 1061 1062 if (status & (STAT_CX | STAT_CNA)) 1063 i596_handle_CU_completion(dev, lp, status, &ack_cmd); 1064 1065 if (status & (STAT_FR | STAT_RNR)) { 1066 /* Restart the receive unit when it got inactive somehow */ 1067 if ((status & STAT_RNR) && netif_running(dev)) 1068 ack_cmd |= RX_START; 1069 1070 if (status & STAT_FR) { 1071 frames_in = i596_rx(dev); 1072 if (!frames_in) 1073 printk("receive frame reported, but no frames\n"); 1074 } 1075 } 1076 1077 /* acknowledge the interrupt */ 1078 /* 1079 if ((lp->scb.pa_cmd != I596_NULL) && netif_running(dev)) 1080 ack_cmd |= CUC_START; 1081 */ 1082 1083 if (lp->scb.command && i596_timeout(dev, "i596 interrupt", 100)) 1084 ; 1085 1086 lp->scb.command = ack_cmd; 1087 1088 CLEAR_INT(); 1089 CA(); 1090 1091 out: 1092 return IRQ_HANDLED; 1093} 1094 1095static int i596_close(struct net_device *dev) { 1096 struct i596_private *lp = netdev_priv(dev); 1097 1098 netif_stop_queue(dev); 1099 1100 if (i596_debug) 1101 printk("%s: Shutting down ethercard, status was %4.4x.\n", 1102 dev->name, lp->scb.status); 1103 1104 lp->scb.command = (CUC_ABORT | RX_ABORT); 1105 CA(); 1106 1107 i596_cleanup_cmd(dev); 1108 1109 if (lp->scb.command && i596_timeout(dev, "i596_close", 200)) 1110 ; 1111 1112 free_irq(dev->irq, dev); 1113 remove_rx_bufs(dev); 1114 1115 return 0; 1116} 1117 1118/* 1119* Set or clear the multicast filter for this adaptor. 1120*/ 1121 1122static void set_multicast_list(struct net_device *dev) { 1123 struct i596_private *lp = netdev_priv(dev); 1124 struct i596_cmd *cmd; 1125 1126 if (i596_debug > 1) 1127 printk ("%s: set multicast list %d\n", 1128 dev->name, netdev_mc_count(dev)); 1129 1130 if (!netdev_mc_empty(dev)) { 1131 struct netdev_hw_addr *ha; 1132 char *cp; 1133 cmd = kmalloc(sizeof(struct i596_cmd) + 2 + 1134 netdev_mc_count(dev) * 6, GFP_ATOMIC); 1135 if (cmd == NULL) { 1136 printk (KERN_ERR "%s: set_multicast Memory squeeze.\n", dev->name); 1137 return; 1138 } 1139 cmd->command = CmdMulticastList; 1140 *((unsigned short *) (cmd + 1)) = netdev_mc_count(dev) * 6; 1141 cp = ((char *)(cmd + 1))+2; 1142 netdev_for_each_mc_addr(ha, dev) { 1143 memcpy(cp, ha->addr, 6); 1144 cp += 6; 1145 } 1146 if (i596_debug & LOG_SRCDST) 1147 print_eth (((char *)(cmd + 1)) + 2); 1148 i596_add_cmd(dev, cmd); 1149 } else { 1150 if (lp->set_conf.pa_next != I596_NULL) { 1151 return; 1152 } 1153 if (netdev_mc_empty(dev) && 1154 !(dev->flags & (IFF_PROMISC | IFF_ALLMULTI))) { 1155 lp->i596_config[8] &= ~0x01; 1156 } else { 1157 lp->i596_config[8] |= 0x01; 1158 } 1159 1160 i596_add_cmd(dev, (struct i596_cmd *) &lp->set_conf); 1161 } 1162} 1163 1164MODULE_AUTHOR("Ard van Breemen <ard@cstmel.nl.eu.org>"); 1165MODULE_DESCRIPTION("Intel Panther onboard i82596 driver"); 1166MODULE_LICENSE("GPL"); 1167 1168static struct net_device *dev_lp486e; 1169static int full_duplex; 1170static int options; 1171static int io = IOADDR; 1172static int irq = IRQ; 1173 1174module_param(debug, int, 0); 1175//module_param(max_interrupt_work, int, 0); 1176//module_param(reverse_probe, int, 0); 1177//module_param(rx_copybreak, int, 0); 1178module_param(options, int, 0); 1179module_param(full_duplex, int, 0); 1180 1181static int __init lp486e_init_module(void) { 1182 int err; 1183 struct net_device *dev = alloc_etherdev(sizeof(struct i596_private)); 1184 if (!dev) 1185 return -ENOMEM; 1186 1187 dev->irq = irq; 1188 dev->base_addr = io; 1189 err = lp486e_probe(dev); 1190 if (err) { 1191 free_netdev(dev); 1192 return err; 1193 } 1194 err = register_netdev(dev); 1195 if (err) { 1196 release_region(dev->base_addr, LP486E_TOTAL_SIZE); 1197 free_netdev(dev); 1198 return err; 1199 } 1200 dev_lp486e = dev; 1201 full_duplex = 0; 1202 options = 0; 1203 return 0; 1204} 1205 1206static void __exit lp486e_cleanup_module(void) { 1207 unregister_netdev(dev_lp486e); 1208 release_region(dev_lp486e->base_addr, LP486E_TOTAL_SIZE); 1209 free_netdev(dev_lp486e); 1210} 1211 1212module_init(lp486e_init_module); 1213module_exit(lp486e_cleanup_module); 1214