00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045
00046
00047
00048
00049
00050
00051 static const char *version =
00052 "eepro100.c:v1.09j-t 9/29/99 Donald Becker http://cesdis.gsfc.nasa.gov/linux/drivers/eepro100.html\n"
00053 "eepro100.c: $Revision: 1.20.2.10 $ 2000/05/31 Modified by Andrey V. Savochkin <saw@saw.sw.com.sg> and others\n"
00054 "eepro100.c: VA Linux custom, Dragan Stancevic <visitor@valinux.com> 2000/11/15\n";
00055
00056
00057
00058
00059 static int congenb = 0;
00060 static int txfifo = 0;
00061 static int rxfifo = 0xF;
00062
00063 static int txdmacount = 128;
00064 static int rxdmacount = 0;
00065
00066
00067
00068 #if defined(__alpha__) || defined(__sparc__)
00069
00070 static int rx_copybreak = 1518;
00071 #else
00072 static int rx_copybreak = 200;
00073 #endif
00074
00075
00076 static int max_interrupt_work = 200;
00077
00078
00079 static int multicast_filter_limit = 64;
00080
00081
00082
00083 static int full_duplex[] = {-1, -1, -1, -1, -1, -1, -1, -1};
00084 static int options[] = {-1, -1, -1, -1, -1, -1, -1, -1};
00085 #ifdef MODULE
00086 static int debug = -1;
00087 #endif
00088
00089
00090
00091 #define TX_RING_SIZE 64
00092 #define RX_RING_SIZE 64
00093
00094
00095 #define TX_MULTICAST_SIZE 2
00096 #define TX_MULTICAST_RESERV (TX_MULTICAST_SIZE*2)
00097
00098
00099 #define TX_QUEUE_LIMIT (TX_RING_SIZE-TX_MULTICAST_RESERV)
00100
00101 #define TX_QUEUE_UNFULL (TX_QUEUE_LIMIT-4)
00102
00103
00104
00105
00106 #define TX_TIMEOUT (2*HZ)
00107
00108 #define PKT_BUF_SZ 1536
00109
00110 #if !defined(__OPTIMIZE__) || !defined(__KERNEL__)
00111 #warning You must compile this file with the correct options!
00112 #warning See the last lines of the source file.
00113 #error You must compile this driver with "-O".
00114 #endif
00115
00116 #include <linux/version.h>
00117 #include <linux/module.h>
00118 #if defined(MODVERSIONS)
00119 #include <linux/modversions.h>
00120 #endif
00121
00122 #include <linux/kernel.h>
00123 #include <linux/string.h>
00124 #include <linux/timer.h>
00125 #include <linux/errno.h>
00126 #include <linux/ioport.h>
00127 #include <linux/malloc.h>
00128 #include <linux/interrupt.h>
00129 #include <linux/pci.h>
00130 #include <asm/spinlock.h>
00131
00132 #include <asm/bitops.h>
00133 #include <asm/io.h>
00134
00135 #include <linux/netdevice.h>
00136 #include <linux/etherdevice.h>
00137 #include <linux/skbuff.h>
00138 #include <linux/delay.h>
00139
00140 #if defined(MODULE)
00141 MODULE_AUTHOR("Maintainer: Andrey V. Savochkin <saw@saw.sw.com.sg>");
00142 MODULE_DESCRIPTION("Intel i82557/i82558 PCI EtherExpressPro driver");
00143 MODULE_PARM(debug, "i");
00144 MODULE_PARM(options, "1-" __MODULE_STRING(8) "i");
00145 MODULE_PARM(full_duplex, "1-" __MODULE_STRING(8) "i");
00146 MODULE_PARM(congenb, "i");
00147 MODULE_PARM(txfifo, "i");
00148 MODULE_PARM(rxfifo, "i");
00149 MODULE_PARM(txdmacount, "i");
00150 MODULE_PARM(rxdmacount, "i");
00151 MODULE_PARM(rx_copybreak, "i");
00152 MODULE_PARM(max_interrupt_work, "i");
00153 MODULE_PARM(multicast_filter_limit, "i");
00154 #endif
00155
00156 #define RUN_AT(x) (jiffies + (x))
00157
00158 #define virt_to_le32desc(addr) cpu_to_le32(virt_to_bus(addr))
00159 #define le32desc_to_virt(addr) bus_to_virt(le32_to_cpu(addr))
00160
00161 #define net_device device
00162 #define pci_base_address(p, n) (p)->base_address[n]
00163
00164 #define dev_free_skb(skb) dev_kfree_skb(skb);
00165 #define netif_wake_queue(dev) do { \
00166 clear_bit(0, (void*)&dev->tbusy); \
00167 mark_bh(NET_BH); \
00168 } while(0)
00169 #define netif_start_queue(dev) clear_bit(0, (void*)&dev->tbusy)
00170 #define netif_stop_queue(dev) set_bit(0, (void*)&dev->tbusy)
00171 #ifndef PCI_DEVICE_ID_INTEL_82559ER
00172 #define PCI_DEVICE_ID_INTEL_82559ER 0x1209
00173 #endif
00174 #ifndef PCI_DEVICE_ID_INTEL_ID1029
00175 #define PCI_DEVICE_ID_INTEL_ID1029 0x1029
00176 #endif
00177 #ifndef PCI_DEVICE_ID_INTEL_ID1030
00178 #define PCI_DEVICE_ID_INTEL_ID1030 0x1030
00179 #endif
00180 #ifndef PCI_DEVICE_ID_INTEL_ID1031
00181 #define PCI_DEVICE_ID_INTEL_ID1031 0x1031
00182 #endif
00183 #ifndef PCI_DEVICE_ID_INTEL_ID2449
00184 #define PCI_DEVICE_ID_INTEL_ID2449 0x2449
00185 #endif
00186
00187
00188
00189 #define SPEEDO3_TOTAL_SIZE 0x20
00190
00191 int speedo_debug = 1;
00192
00193
00194
00195
00196
00197
00198
00199
00200
00201
00202
00203
00204
00205
00206
00207
00208
00209
00210
00211
00212
00213
00214
00215
00216
00217
00218
00219
00220
00221
00222
00223
00224
00225
00226
00227
00228
00229
00230
00231
00232
00233
00234
00235
00236
00237
00238
00239
00240
00241
00242
00243
00244
00245
00246
00247
00248
00249
00250
00251
00252
00253
00254
00255
00256
00257
00258
00259
00260
00261
00262
00263
00264
00265
00266
00267
00268
00269
00270
00271
00272
00273
00274
00275
00276
00277
00278
00279
00280
00281
00282
00283
00284
00285
00286
00287
00288
00289
00290
00291
00292
00293
00294
00295
00296
00297
00298
00299
00300
00301
00302
00303
00304
00305
00306
00307
00308 static struct net_device *speedo_found1(struct pci_dev *pdev, int pci_bus,
00309 int pci_devfn, long ioaddr,
00310 int chip_idx, int card_idx);
00311
00312 #ifdef USE_IO
00313 #define SPEEDO_IOTYPE PCI_USES_MASTER|PCI_USES_IO|PCI_ADDR1
00314 #define SPEEDO_SIZE 32
00315 #else
00316 #define SPEEDO_IOTYPE PCI_USES_MASTER|PCI_USES_MEM|PCI_ADDR0
00317 #define SPEEDO_SIZE 0x1000
00318 #endif
00319
00320 enum pci_flags_bit {
00321 PCI_USES_IO=1, PCI_USES_MEM=2, PCI_USES_MASTER=4,
00322 PCI_ADDR0=0x10<<0, PCI_ADDR1=0x10<<1, PCI_ADDR2=0x10<<2, PCI_ADDR3=0x10<<3,
00323 };
00324 struct pci_id_info {
00325 const char *name;
00326 u16 vendor_id, device_id;
00327 int pci_index;
00328 } static pci_tbl[] = {
00329 { "Intel PCI EtherExpress Pro100 82557",
00330 PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82557,
00331 0
00332 },
00333 { "Intel PCI EtherExpress Pro100 82559ER",
00334 PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82559ER,
00335 0
00336 },
00337 { "Intel PCI EtherExpress Pro100 ID1029",
00338 PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_ID1029,
00339 0
00340 },
00341 { "Intel Corporation 82559 InBusiness 10/100",
00342 PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_ID1030,
00343 0
00344 },
00345 { "Intel Pro/100 VE",
00346 PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_ID1031,
00347 0
00348 },
00349 { "Intel PCI EtherExpress Pro100 82562EM",
00350 PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_ID2449,
00351 0
00352 },
00353 {0,}
00354 };
00355
00356 static inline unsigned int io_inw(unsigned long port)
00357 {
00358 return inw(port);
00359 }
00360 static inline void io_outw(unsigned int val, unsigned long port)
00361 {
00362 outw(val, port);
00363 }
00364
00365 #ifndef USE_IO
00366 #undef inb
00367 #undef inw
00368 #undef inl
00369 #undef outb
00370 #undef outw
00371 #undef outl
00372 #define inb readb
00373 #define inw readw
00374 #define inl readl
00375 #define outb writeb
00376 #define outw writew
00377 #define outl writel
00378 #endif
00379
00380
00381
00382 static inline void wait_for_cmd_done(long cmd_ioaddr)
00383 {
00384 int wait = 20000;
00385 char cmd_reg1, cmd_reg2;
00386 do ;
00387 while((cmd_reg1 = inb(cmd_ioaddr)) && (--wait >= 0));
00388
00389
00390 if (wait < 0){
00391 cmd_reg2 = inb(cmd_ioaddr);
00392 if(cmd_reg2){
00393 printk(KERN_ALERT "eepro100: cmd_wait for(%#2.2x) timedout with(%#2.2x)!\n",
00394 cmd_reg1, cmd_reg2);
00395
00396 }
00397 }
00398
00399 }
00400
00401
00402
00403 enum speedo_offsets {
00404 SCBStatus = 0, SCBCmd = 2,
00405 SCBPointer = 4,
00406 SCBPort = 8,
00407 SCBflash = 12, SCBeeprom = 14,
00408 SCBCtrlMDI = 16,
00409 SCBEarlyRx = 20,
00410 };
00411
00412 enum commands {
00413 CmdNOp = 0, CmdIASetup = 0x10000, CmdConfigure = 0x20000,
00414 CmdMulticastList = 0x30000, CmdTx = 0x40000, CmdTDR = 0x50000,
00415 CmdDump = 0x60000, CmdDiagnose = 0x70000,
00416 CmdSuspend = 0x40000000,
00417 CmdIntr = 0x20000000,
00418 CmdTxFlex = 0x00080000,
00419 };
00420
00421
00422
00423
00424 #if defined(__LITTLE_ENDIAN)
00425 #define clear_suspend(cmd) ((__u16 *)&(cmd)->cmd_status)[1] &= ~0x4000
00426 #elif defined(__BIG_ENDIAN)
00427 #define clear_suspend(cmd) ((__u16 *)&(cmd)->cmd_status)[1] &= ~0x0040
00428 #else
00429 #error Unsupported byteorder
00430 #endif
00431
00432 enum SCBCmdBits {
00433 SCBMaskCmdDone=0x8000, SCBMaskRxDone=0x4000, SCBMaskCmdIdle=0x2000,
00434 SCBMaskRxSuspend=0x1000, SCBMaskEarlyRx=0x0800, SCBMaskFlowCtl=0x0400,
00435 SCBTriggerIntr=0x0200, SCBMaskAll=0x0100,
00436
00437 CUStart=0x0010, CUResume=0x0020, CUStatsAddr=0x0040, CUShowStats=0x0050,
00438 CUCmdBase=0x0060,
00439 CUDumpStats=0x0070,
00440 RxStart=0x0001, RxResume=0x0002, RxAbort=0x0004, RxAddrLoad=0x0006,
00441 RxResumeNoResources=0x0007,
00442 };
00443
00444 enum SCBPort_cmds {
00445 PortReset=0, PortSelfTest=1, PortPartialReset=2, PortDump=3,
00446 };
00447
00448
00449 struct descriptor {
00450 s32 cmd_status;
00451 u32 link;
00452 unsigned char params[0];
00453 };
00454
00455
00456 struct RxFD {
00457 s32 status;
00458 u32 link;
00459 u32 rx_buf_addr;
00460 u32 count;
00461 };
00462
00463
00464 enum RxFD_bits {
00465 RxComplete=0x8000, RxOK=0x2000,
00466 RxErrCRC=0x0800, RxErrAlign=0x0400, RxErrTooBig=0x0200, RxErrSymbol=0x0010,
00467 RxEth2Type=0x0020, RxNoMatch=0x0004, RxNoIAMatch=0x0002,
00468 TxUnderrun=0x1000, StatusComplete=0x8000,
00469 };
00470
00471 struct TxFD {
00472 s32 status;
00473 u32 link;
00474 u32 tx_desc_addr;
00475 s32 count;
00476
00477 u32 tx_buf_addr0;
00478 s32 tx_buf_size0;
00479 u32 tx_buf_addr1;
00480 s32 tx_buf_size1;
00481 };
00482
00483
00484 struct speedo_mc_block {
00485 struct speedo_mc_block *next;
00486 unsigned int tx;
00487 struct descriptor frame __attribute__ ((__aligned__(16)));
00488 };
00489
00490
00491 struct speedo_stats {
00492 u32 tx_good_frames;
00493 u32 tx_coll16_errs;
00494 u32 tx_late_colls;
00495 u32 tx_underruns;
00496 u32 tx_lost_carrier;
00497 u32 tx_deferred;
00498 u32 tx_one_colls;
00499 u32 tx_multi_colls;
00500 u32 tx_total_colls;
00501 u32 rx_good_frames;
00502 u32 rx_crc_errs;
00503 u32 rx_align_errs;
00504 u32 rx_resource_errs;
00505 u32 rx_overrun_errs;
00506 u32 rx_colls_errs;
00507 u32 rx_runt_errs;
00508 u32 done_marker;
00509 };
00510
00511 enum Rx_ring_state_bits {
00512 RrNoMem=1, RrPostponed=2, RrNoResources=4, RrOOMReported=8,
00513 };
00514
00515
00516
00517 struct speedo_private {
00518 struct TxFD tx_ring[TX_RING_SIZE];
00519 struct RxFD *rx_ringp[RX_RING_SIZE];
00520
00521 struct sk_buff* tx_skbuff[TX_RING_SIZE];
00522 struct sk_buff* rx_skbuff[RX_RING_SIZE];
00523 struct descriptor *last_cmd;
00524 unsigned int cur_tx, dirty_tx;
00525 spinlock_t lock;
00526 u32 tx_threshold;
00527 struct RxFD *last_rxf;
00528 unsigned int cur_rx, dirty_rx;
00529 long last_rx_time;
00530 const char *product_name;
00531 struct net_device *next_module;
00532 void *priv_addr;
00533 struct enet_statistics stats;
00534 struct speedo_stats lstats;
00535 int chip_id;
00536 unsigned char pci_bus, pci_devfn, acpi_pwr;
00537 struct timer_list timer;
00538 struct speedo_mc_block *mc_setup_head;
00539 struct speedo_mc_block *mc_setup_tail;
00540 int in_interrupt;
00541 char rx_mode;
00542 unsigned int tx_full:1;
00543 unsigned int full_duplex:1;
00544 unsigned int flow_ctrl:1;
00545 unsigned int rx_bug:1;
00546 unsigned int rx_bug10:1;
00547 unsigned int rx_bug100:1;
00548 unsigned char default_port:8;
00549 unsigned char rx_ring_state;
00550 unsigned short phy[2];
00551 unsigned short advertising;
00552 unsigned short partner;
00553 };
00554
00555
00556
00557
00558 const char i82557_config_cmd[22] = {
00559 22, 0x08, 0, 0, 0, 0, 0x32, 0x03, 1,
00560 0, 0x2E, 0, 0x60, 0,
00561 0xf2, 0x48, 0, 0x40, 0xf2, 0x80,
00562 0x3f, 0x05, };
00563 const char i82558_config_cmd[22] = {
00564 22, 0x08, 0, 1, 0, 0, 0x22, 0x03, 1,
00565 0, 0x2E, 0, 0x60, 0x08, 0x88,
00566 0x68, 0, 0x40, 0xf2, 0x84,
00567 0x31, 0x05, };
00568
00569
00570 static const char *phys[] = {
00571 "None", "i82553-A/B", "i82553-C", "i82503",
00572 "DP83840", "80c240", "80c24", "i82555",
00573 "unknown-8", "unknown-9", "DP83840A", "unknown-11",
00574 "unknown-12", "unknown-13", "unknown-14", "unknown-15", };
00575 enum phy_chips { NonSuchPhy=0, I82553AB, I82553C, I82503, DP83840, S80C240,
00576 S80C24, I82555, DP83840A=10, };
00577 static const char is_mii[] = { 0, 1, 1, 0, 1, 1, 0, 1 };
00578 #define EE_READ_CMD (6)
00579
00580 static int do_eeprom_cmd(long ioaddr, int cmd, int cmd_len);
00581 static int mdio_read(long ioaddr, int phy_id, int location);
00582 static int mdio_write(long ioaddr, int phy_id, int location, int value);
00583 static int speedo_open(struct net_device *dev);
00584 static void speedo_resume(struct net_device *dev);
00585 static void speedo_timer(unsigned long data);
00586 static void speedo_init_rx_ring(struct net_device *dev);
00587 static void speedo_tx_timeout(struct net_device *dev);
00588 static int speedo_start_xmit(struct sk_buff *skb, struct net_device *dev);
00589 static void speedo_refill_rx_buffers(struct net_device *dev, int force);
00590 static int speedo_rx(struct net_device *dev);
00591 static void speedo_tx_buffer_gc(struct net_device *dev);
00592 static void speedo_interrupt(int irq, void *dev_instance, struct pt_regs *regs);
00593 static int speedo_close(struct net_device *dev);
00594 static struct enet_statistics *speedo_get_stats(struct net_device *dev);
00595 static int speedo_ioctl(struct net_device *dev, struct ifreq *rq, int cmd);
00596 static void set_rx_mode(struct net_device *dev);
00597 static void speedo_show_state(struct net_device *dev);
00598
00599
00600
00601 #ifdef honor_default_port
00602
00603
00604 static int mii_ctrl[8] = { 0x3300, 0x3100, 0x0000, 0x0100,
00605 0x2000, 0x2100, 0x0400, 0x3100};
00606 #endif
00607
00608
00609 static struct net_device *root_speedo_dev = NULL;
00610
00611 int eepro100_init(void)
00612 {
00613 int cards_found = 0;
00614 int chip_idx;
00615 struct pci_dev *pdev;
00616
00617 if (! pcibios_present())
00618 return cards_found;
00619
00620 for (chip_idx = 0; pci_tbl[chip_idx].name; chip_idx++) {
00621 for (; pci_tbl[chip_idx].pci_index < 8; pci_tbl[chip_idx].pci_index++) {
00622 unsigned char pci_bus, pci_device_fn, pci_latency;
00623 unsigned long pciaddr;
00624 long ioaddr;
00625 int irq;
00626
00627 u16 pci_command, new_command;
00628
00629 if (pcibios_find_device(pci_tbl[chip_idx].vendor_id,
00630 pci_tbl[chip_idx].device_id,
00631 pci_tbl[chip_idx].pci_index, &pci_bus,
00632 &pci_device_fn))
00633 break;
00634 {
00635 pdev = pci_find_slot(pci_bus, pci_device_fn);
00636 #ifdef USE_IO
00637 pciaddr = pci_base_address(pdev, 1);
00638 #else
00639 pciaddr = pci_base_address(pdev, 0);
00640 #endif
00641 irq = pdev->irq;
00642 }
00643
00644 if (pciaddr & 1) {
00645 ioaddr = pciaddr & ~3UL;
00646 if (check_region(ioaddr, 32))
00647 continue;
00648 } else {
00649 #ifdef __sparc__
00650
00651 ioaddr = pciaddr & ~0xfUL;
00652 #else
00653 if ((ioaddr = (long)ioremap(pciaddr & ~0xfUL, 0x1000)) == 0) {
00654 printk(KERN_INFO "Failed to map PCI address %#lx.\n",
00655 pciaddr);
00656 continue;
00657 }
00658 #endif
00659 }
00660 if (speedo_debug > 2)
00661 printk("Found Intel i82557 PCI Speedo at I/O %#lx, IRQ %d.\n",
00662 ioaddr, irq);
00663
00664
00665 pcibios_read_config_word(pci_bus, pci_device_fn,
00666 PCI_COMMAND, &pci_command);
00667 new_command = pci_command | PCI_COMMAND_MASTER|PCI_COMMAND_IO;
00668 if (pci_command != new_command) {
00669 printk(KERN_INFO " The PCI BIOS has not enabled this"
00670 " device! Updating PCI command %4.4x->%4.4x.\n",
00671 pci_command, new_command);
00672 pcibios_write_config_word(pci_bus, pci_device_fn,
00673 PCI_COMMAND, new_command);
00674 }
00675 pcibios_read_config_byte(pci_bus, pci_device_fn,
00676 PCI_LATENCY_TIMER, &pci_latency);
00677 if (pci_latency < 32) {
00678 printk(" PCI latency timer (CFLT) is unreasonably low at %d."
00679 " Setting to 32 clocks.\n", pci_latency);
00680 pcibios_write_config_byte(pci_bus, pci_device_fn,
00681 PCI_LATENCY_TIMER, 32);
00682 } else if (speedo_debug > 1)
00683 printk(" PCI latency timer (CFLT) is %#x.\n", pci_latency);
00684
00685 if (speedo_found1(pdev, pci_bus, pci_device_fn, ioaddr, chip_idx, cards_found))
00686 cards_found++;
00687 }
00688 }
00689
00690 return cards_found;
00691 }
00692
00693 static struct net_device *speedo_found1(struct pci_dev *pdev, int pci_bus,
00694 int pci_devfn, long ioaddr,
00695 int chip_idx, int card_idx)
00696 {
00697 struct net_device *dev;
00698 struct speedo_private *sp;
00699 const char *product;
00700 int i, option;
00701 u16 eeprom[0x100];
00702 int acpi_idle_state = 0;
00703 #ifndef MODULE
00704 static int did_version = 0;
00705 if (speedo_debug > 0 && did_version++ == 0)
00706 printk(version);
00707 #endif
00708
00709 dev = init_etherdev(NULL, sizeof(struct speedo_private));
00710
00711 if (dev == NULL) {
00712 printk(KERN_ERR "eepro100: Unable to allocate net_device structure!\n");
00713 return NULL;
00714 }
00715
00716 if (dev->mem_start > 0)
00717 option = dev->mem_start;
00718 else if (card_idx >= 0 && options[card_idx] >= 0)
00719 option = options[card_idx];
00720 else
00721 option = 0;
00722
00723
00724
00725
00726
00727
00728 {
00729 unsigned long iobase;
00730 int read_cmd, ee_size;
00731 u16 sum;
00732 int j;
00733
00734
00735
00736 iobase = pci_base_address(pdev, 1) & ~3UL;
00737 if ((do_eeprom_cmd(iobase, EE_READ_CMD << 24, 27) & 0xffe0000)
00738 == 0xffe0000) {
00739 ee_size = 0x100;
00740 read_cmd = EE_READ_CMD << 24;
00741 } else {
00742 ee_size = 0x40;
00743 read_cmd = EE_READ_CMD << 22;
00744 }
00745
00746 for (j = 0, i = 0, sum = 0; i < ee_size; i++) {
00747 u16 value = do_eeprom_cmd(iobase, read_cmd | (i << 16), 27);
00748 eeprom[i] = value;
00749 sum += value;
00750 if (i < 3) {
00751 dev->dev_addr[j++] = value;
00752 dev->dev_addr[j++] = value >> 8;
00753 }
00754 }
00755 if (sum != 0xBABA)
00756 printk(KERN_WARNING "%s: Invalid EEPROM checksum %#4.4x, "
00757 "check settings before activating this device!\n",
00758 dev->name, sum);
00759
00760
00761
00762 }
00763
00764
00765
00766
00767 outl(PortReset, ioaddr + SCBPort);
00768 inl(ioaddr + SCBPort);
00769
00770 udelay(10);
00771
00772 if (eeprom[3] & 0x0100)
00773 product = "OEM i82557/i82558 10/100 Ethernet";
00774 else
00775 product = pci_tbl[chip_idx].name;
00776
00777 printk(KERN_INFO "%s: %s, ", dev->name, product);
00778
00779 for (i = 0; i < 5; i++)
00780 printk("%2.2X:", dev->dev_addr[i]);
00781 printk("%2.2X, ", dev->dev_addr[i]);
00782 #ifdef USE_IO
00783 printk("I/O at %#3lx, ", ioaddr);
00784 #endif
00785 printk("IRQ %d.\n", pdev->irq);
00786
00787 #if 1 || defined(kernel_bloat)
00788
00789
00790
00791 {
00792 const char *connectors[] = {" RJ45", " BNC", " AUI", " MII"};
00793
00794 s32 str[6], *volatile self_test_results;
00795 int boguscnt = 16000;
00796 if ((eeprom[3] & 0x03) != 0x03)
00797 printk(KERN_INFO " Receiver lock-up bug exists -- enabling"
00798 " work-around.\n");
00799 printk(KERN_INFO " Board assembly %4.4x%2.2x-%3.3d, Physical"
00800 " connectors present:",
00801 eeprom[8], eeprom[9]>>8, eeprom[9] & 0xff);
00802 for (i = 0; i < 4; i++)
00803 if (eeprom[5] & (1<<i))
00804 printk(connectors[i]);
00805 printk("\n"KERN_INFO" Primary interface chip %s PHY #%d.\n",
00806 phys[(eeprom[6]>>8)&15], eeprom[6] & 0x1f);
00807 if (eeprom[7] & 0x0700)
00808 printk(KERN_INFO " Secondary interface chip %s.\n",
00809 phys[(eeprom[7]>>8)&7]);
00810 if (((eeprom[6]>>8) & 0x3f) == DP83840
00811 || ((eeprom[6]>>8) & 0x3f) == DP83840A) {
00812 int mdi_reg23 = mdio_read(ioaddr, eeprom[6] & 0x1f, 23) | 0x0422;
00813 if (congenb)
00814 mdi_reg23 |= 0x0100;
00815 printk(KERN_INFO" DP83840 specific setup, setting register 23 to %4.4x.\n",
00816 mdi_reg23);
00817 mdio_write(ioaddr, eeprom[6] & 0x1f, 23, mdi_reg23);
00818 }
00819 if ((option >= 0) && (option & 0x70)) {
00820 printk(KERN_INFO " Forcing %dMbs %s-duplex operation.\n",
00821 (option & 0x20 ? 100 : 10),
00822 (option & 0x10 ? "full" : "half"));
00823 mdio_write(ioaddr, eeprom[6] & 0x1f, 0,
00824 ((option & 0x20) ? 0x2000 : 0) |
00825 ((option & 0x10) ? 0x0100 : 0));
00826 }
00827
00828
00829 self_test_results = (s32*) ((((long) str) + 15) & ~0xf);
00830 self_test_results[0] = 0;
00831 self_test_results[1] = -1;
00832 outl(virt_to_bus(self_test_results) | PortSelfTest, ioaddr + SCBPort);
00833 do {
00834 udelay(10);
00835 } while (self_test_results[1] == -1 && --boguscnt >= 0);
00836
00837 if (boguscnt < 0) {
00838 printk(KERN_ERR "Self test failed, status %8.8x:\n"
00839 KERN_ERR " Failure to initialize the i82557.\n"
00840 KERN_ERR " Verify that the card is a bus-master"
00841 " capable slot.\n",
00842 self_test_results[1]);
00843 } else
00844 printk(KERN_INFO " General self-test: %s.\n"
00845 KERN_INFO " Serial sub-system self-test: %s.\n"
00846 KERN_INFO " Internal registers self-test: %s.\n"
00847 KERN_INFO " ROM checksum self-test: %s (%#8.8x).\n",
00848 self_test_results[1] & 0x1000 ? "failed" : "passed",
00849 self_test_results[1] & 0x0020 ? "failed" : "passed",
00850 self_test_results[1] & 0x0008 ? "failed" : "passed",
00851 self_test_results[1] & 0x0004 ? "failed" : "passed",
00852 self_test_results[0]);
00853 }
00854 #endif
00855
00856 outl(PortReset, ioaddr + SCBPort);
00857 inl(ioaddr + SCBPort);
00858
00859 udelay(10);
00860
00861
00862 request_region(ioaddr, SPEEDO3_TOTAL_SIZE, "Intel Speedo3 Ethernet");
00863
00864 dev->base_addr = ioaddr;
00865 dev->irq = pdev->irq;
00866
00867 sp = dev->priv;
00868 if (dev->priv == NULL) {
00869 void *mem = kmalloc(sizeof(*sp), GFP_KERNEL);
00870 dev->priv = sp = mem;
00871 sp->priv_addr = mem;
00872 }
00873 memset(sp, 0, sizeof(*sp));
00874 sp->next_module = root_speedo_dev;
00875 root_speedo_dev = dev;
00876
00877 sp->pci_bus = pci_bus;
00878 sp->pci_devfn = pci_devfn;
00879 sp->chip_id = chip_idx;
00880 sp->acpi_pwr = acpi_idle_state;
00881
00882 sp->full_duplex = option >= 0 && (option & 0x10) ? 1 : 0;
00883 if (card_idx >= 0) {
00884 if (full_duplex[card_idx] >= 0)
00885 sp->full_duplex = full_duplex[card_idx];
00886 }
00887 sp->default_port = option >= 0 ? (option & 0x0f) : 0;
00888
00889 sp->phy[0] = eeprom[6];
00890 sp->phy[1] = eeprom[7];
00891 sp->rx_bug = (eeprom[3] & 0x03) == 3 ? 0 : 1;
00892
00893 if (sp->rx_bug)
00894 printk(KERN_INFO " Receiver lock-up workaround activated.\n");
00895
00896
00897 dev->open = &speedo_open;
00898 dev->hard_start_xmit = &speedo_start_xmit;
00899 #if defined(HAS_NETIF_QUEUE)
00900 dev->tx_timeout = &speedo_tx_timeout;
00901 dev->watchdog_timeo = TX_TIMEOUT;
00902 #endif
00903 dev->stop = &speedo_close;
00904 dev->get_stats = &speedo_get_stats;
00905 dev->set_multicast_list = &set_rx_mode;
00906 dev->do_ioctl = &speedo_ioctl;
00907
00908 return dev;
00909 }
00910
00911
00912
00913
00914 #define EE_SHIFT_CLK 0x01
00915 #define EE_CS 0x02
00916 #define EE_DATA_WRITE 0x04
00917 #define EE_DATA_READ 0x08
00918 #define EE_ENB (0x4800 | EE_CS)
00919 #define EE_WRITE_0 0x4802
00920 #define EE_WRITE_1 0x4806
00921 #define EE_OFFSET SCBeeprom
00922
00923
00924
00925
00926
00927
00928
00929
00930 static int do_eeprom_cmd(long ioaddr, int cmd, int cmd_len)
00931 {
00932 unsigned retval = 0;
00933 long ee_addr = ioaddr + SCBeeprom;
00934
00935 io_outw(EE_ENB, ee_addr); udelay(2);
00936 io_outw(EE_ENB | EE_SHIFT_CLK, ee_addr); udelay(2);
00937
00938
00939 do {
00940 short dataval = (cmd & (1 << cmd_len)) ? EE_WRITE_1 : EE_WRITE_0;
00941 io_outw(dataval, ee_addr); udelay(2);
00942 io_outw(dataval | EE_SHIFT_CLK, ee_addr); udelay(2);
00943 retval = (retval << 1) | ((io_inw(ee_addr) & EE_DATA_READ) ? 1 : 0);
00944 } while (--cmd_len >= 0);
00945 io_outw(EE_ENB, ee_addr); udelay(2);
00946
00947
00948 io_outw(EE_ENB & ~EE_CS, ee_addr);
00949 return retval;
00950 }
00951
00952 static int mdio_read(long ioaddr, int phy_id, int location)
00953 {
00954 int val, boguscnt = 64*10;
00955 outl(0x08000000 | (location<<16) | (phy_id<<21), ioaddr + SCBCtrlMDI);
00956 do {
00957 val = inl(ioaddr + SCBCtrlMDI);
00958 if (--boguscnt < 0) {
00959 printk(KERN_ERR " mdio_read() timed out with val = %8.8x.\n", val);
00960 break;
00961 }
00962 } while (! (val & 0x10000000));
00963 return val & 0xffff;
00964 }
00965
00966 static int mdio_write(long ioaddr, int phy_id, int location, int value)
00967 {
00968 int val, boguscnt = 64*10;
00969 outl(0x04000000 | (location<<16) | (phy_id<<21) | value,
00970 ioaddr + SCBCtrlMDI);
00971 do {
00972 val = inl(ioaddr + SCBCtrlMDI);
00973 if (--boguscnt < 0) {
00974 printk(KERN_ERR" mdio_write() timed out with val = %8.8x.\n", val);
00975 break;
00976 }
00977 } while (! (val & 0x10000000));
00978 return val & 0xffff;
00979 }
00980
00981
00982 static int
00983 speedo_open(struct net_device *dev)
00984 {
00985 struct speedo_private *sp = (struct speedo_private *)dev->priv;
00986 long ioaddr = dev->base_addr;
00987
00988 if (speedo_debug > 1)
00989 printk(KERN_DEBUG "%s: speedo_open() irq %d.\n", dev->name, dev->irq);
00990
00991 MOD_INC_USE_COUNT;
00992
00993
00994 sp->cur_tx = 0;
00995 sp->dirty_tx = 0;
00996 sp->last_cmd = 0;
00997 sp->tx_full = 0;
00998 sp->lock = (spinlock_t) SPIN_LOCK_UNLOCKED;
00999 sp->in_interrupt = 0;
01000
01001
01002 if (request_irq(dev->irq, &speedo_interrupt, SA_SHIRQ, dev->name, dev)) {
01003 MOD_DEC_USE_COUNT;
01004 return -EAGAIN;
01005 }
01006
01007 dev->if_port = sp->default_port;
01008
01009 #ifdef oh_no_you_dont_unless_you_honour_the_options_passed_in_to_us
01010
01011 if ((sp->phy[0] & 0x8000) == 0) {
01012 int phy_addr = sp->phy[0] & 0x1f ;
01013
01014
01015
01016
01017
01018
01019 #ifdef honor_default_port
01020 mdio_write(ioaddr, phy_addr, 0, mii_ctrl[dev->default_port & 7]);
01021 #else
01022 mdio_write(ioaddr, phy_addr, 0, 0x3300);
01023 #endif
01024 }
01025 #endif
01026
01027 speedo_init_rx_ring(dev);
01028
01029
01030 outw(SCBMaskAll, ioaddr + SCBCmd);
01031 speedo_resume(dev);
01032
01033 dev->interrupt = 0;
01034 dev->start = 1;
01035 netif_start_queue(dev);
01036
01037
01038 sp->mc_setup_head = NULL;
01039 sp->mc_setup_tail = NULL;
01040 sp->flow_ctrl = sp->partner = 0;
01041 sp->rx_mode = -1;
01042 set_rx_mode(dev);
01043 if ((sp->phy[0] & 0x8000) == 0)
01044 sp->advertising = mdio_read(ioaddr, sp->phy[0] & 0x1f, 4);
01045
01046 if (speedo_debug > 2) {
01047 printk(KERN_DEBUG "%s: Done speedo_open(), status %8.8x.\n",
01048 dev->name, inw(ioaddr + SCBStatus));
01049 }
01050
01051
01052
01053
01054
01055
01056 init_timer(&sp->timer);
01057 sp->timer.expires = RUN_AT((24*HZ)/10);
01058 sp->timer.data = (unsigned long)dev;
01059 sp->timer.function = &speedo_timer;
01060 add_timer(&sp->timer);
01061
01062
01063 if ((sp->phy[0] & 0x8000) == 0)
01064 mdio_read(ioaddr, sp->phy[0] & 0x1f, 0);
01065
01066 return 0;
01067 }
01068
01069
01070 static void speedo_resume(<