1 /* EtherLinkXL.c: A 3Com EtherLink PCI III/XL ethernet driver for linux. */ 3 Written 1996-1998 by Donald Becker. 5 This software may be used and distributed according to the terms 6 of the GNU Public License, incorporated herein by reference. 8 This driver is for the 3Com "Vortex" and "Boomerang" series ethercards. 9 Members of the series include Fast EtherLink 3c590/3c592/3c595/3c597 10 and the EtherLink XL 3c900 and 3c905 cards. 12 The author may be reached as becker@CESDIS.gsfc.nasa.gov, or C/O 13 Center of Excellence in Space Data and Information Sciences 14 Code 930.5, Goddard Space Flight Center, Greenbelt MD 20771 18 "3c59x.c:v0.99F 8/7/98 Donald Becker http://cesdis.gsfc.nasa.gov/linux/drivers/vortex.html\n"; 20 /* "Knobs" that adjust features and parameters. */ 21 /* Set the copy breakpoint for the copy-only-tiny-frames scheme. 22 Setting to > 1512 effectively disables this feature. */ 23 static const int rx_copybreak
=200; 24 /* Allow setting MTU to a larger size, bypassing the normal ethernet setup. */ 25 static const int mtu
=1500; 26 /* Maximum events (Rx packets, etc.) to handle at each interrupt. */ 27 static int max_interrupt_work
=20; 29 /* Put out somewhat more debugging messages. (0: no msg, 1 minimal .. 6). */ 31 static int vortex_debug
= VORTEX_DEBUG
; 33 static int vortex_debug
=1; 36 /* Some values here only for performance evaluation and path-coverage 38 static int rx_nocopy
=0, rx_copy
=0, queued_packet
=0, rx_csumhits
; 40 /* Allow the use of fragment bus master transfers instead of only 41 programmed-I/O for Vortex cards. Full-bus-master transfers are always 42 enabled by default on Boomerang cards. If VORTEX_BUS_MASTER is defined, 43 the feature may be turned on using 'options'. */ 44 #define VORTEX_BUS_MASTER 46 /* A few values that may be tweaked. */ 47 /* Time in jiffies before concluding the transmitter is hung. */ 48 #define TX_TIMEOUT ((400*HZ)/1000) 50 /* Keep the ring sizes a power of two for efficiency. */ 51 #define TX_RING_SIZE 16 52 #define RX_RING_SIZE 32 53 #define PKT_BUF_SZ 1536/* Size of each temporary Rx buffer.*/ 55 #include <linux/config.h> 58 #include <linux/modversions.h> 60 #include <linux/module.h> 61 #include <linux/version.h> 63 #define MOD_INC_USE_COUNT 64 #define MOD_DEC_USE_COUNT 67 #include <linux/kernel.h> 68 #include <linux/sched.h> 69 #include <linux/string.h> 70 #include <linux/ptrace.h> 71 #include <linux/errno.h> 73 #include <linux/ioport.h> 74 #include <linux/malloc.h> 75 #include <linux/interrupt.h> 76 #include <linux/pci.h> 77 #if LINUX_VERSION_CODE < 0x20155 || defined(CARDBUS) 78 #include <linux/bios32.h> 80 #include <linux/timer.h> 81 #include <asm/irq.h>/* For NR_IRQS only. */ 82 #include <asm/bitops.h> 85 #include <linux/netdevice.h> 86 #include <linux/etherdevice.h> 87 #include <linux/skbuff.h> 89 /* Kernel compatibility defines, common to David Hind's PCMCIA package. 90 This is only in the support-all-kernels source code. */ 91 #ifndef LINUX_VERSION_CODE 92 #include <linux/version.h>/* Redundant above, here for easy clean-up. */ 94 #if LINUX_VERSION_CODE < 0x10300 95 #define RUN_AT(x) (x)/* What to put in timer->expires. */ 96 #define DEV_ALLOC_SKB(len) alloc_skb(len, GFP_ATOMIC) 98 #error"The Alpha architecture is only support with kernel version 2.0." 100 #define virt_to_bus(addr) ((unsigned long)addr) 101 #define bus_to_virt(addr) ((void*)addr) 103 #else/* 1.3.0 and later */ 104 #define RUN_AT(x) (jiffies + (x)) 105 #define DEV_ALLOC_SKB(len) dev_alloc_skb(len) 109 #define FREE_IRQ(irqnum, dev) free_irq(irqnum, dev) 110 #define REQUEST_IRQ(i,h,f,n, instance) request_irq(i,h,f,n, instance) 111 #define IRQ(irq, dev_id, pt_regs) (irq, dev_id, pt_regs) 113 #define FREE_IRQ(irqnum, dev) free_irq(irqnum) 114 #define REQUEST_IRQ(i,h,f,n, instance) request_irq(i,h,f,n) 115 #define IRQ(irq, dev_id, pt_regs) (irq, pt_regs) 118 #if (LINUX_VERSION_CODE >= 0x10344) 119 #define NEW_MULTICAST 120 #include <linux/delay.h> 122 #define udelay(microsec) do { int _i = 4*microsec; while (--_i > 0) { __SLOW_DOWN_IO; }} while (0) 125 #if LINUX_VERSION_CODE <= 0x20139 126 #define net_device_stats enet_statistics 127 #define NETSTATS_VER2 129 #if LINUX_VERSION_CODE < 0x20138 130 #define test_and_set_bit(val, addr) set_bit(val, addr) 131 #define le32_to_cpu(val) (val) 132 #define cpu_to_le32(val) (val) 134 #if LINUX_VERSION_CODE < 0x20155 135 #define PCI_SUPPORT_VER1 137 #define PCI_SUPPORT_VER2 139 #if LINUX_VERSION_CODE < 0x20159 140 #define DEV_FREE_SKB(skb) dev_kfree_skb (skb, FREE_WRITE); 141 #else/* Grrr, unneeded incompatible change. */ 142 #define DEV_FREE_SKB(skb) dev_kfree_skb(skb); 146 #if defined(MODULE) && (LINUX_VERSION_CODE >= 0x20115) 147 MODULE_AUTHOR("Donald Becker <becker@cesdis.gsfc.nasa.gov>"); 148 MODULE_DESCRIPTION("3Com 3c590/3c900 series Vortex/Boomerang driver"); 149 MODULE_PARM(debug
,"i"); 150 MODULE_PARM(options
,"1-"__MODULE_STRING(8)"i"); 151 MODULE_PARM(full_duplex
,"1-"__MODULE_STRING(8)"i"); 152 MODULE_PARM(rx_copybreak
,"i"); 153 MODULE_PARM(max_interrupt_work
,"i"); 154 MODULE_PARM(compaq_ioaddr
,"i"); 155 MODULE_PARM(compaq_irq
,"i"); 156 MODULE_PARM(compaq_device_id
,"i"); 159 /* Operational parameter that usually are not changed. */ 161 /* The Vortex size is twice that of the original EtherLinkIII series: the 162 runtime register window, window 1, is now always mapped in. 163 The Boomerang size is twice as large as the Vortex -- it has additional 164 bus master control registers. */ 165 #define VORTEX_TOTAL_SIZE 0x20 166 #define BOOMERANG_TOTAL_SIZE 0x40 169 struct netdev_entry tc59x_drv
= 170 {"Vortex", vortex_pci_probe
, VORTEX_TOTAL_SIZE
, NULL
}; 173 /* Set iff a MII transceiver on any interface requires mdio preamble. 174 This only set with the original DP83840 on older 3c905 boards, so the extra 175 code size of a per-interface flag is not worthwhile. */ 176 static char mii_preamble_required
=0; 178 /* Caution! These entries must be consistent. */ 179 static const int product_ids
[] = { 180 0x5900,0x5920,0x5970,0x5950,0x5951,0x5952,0x9000,0x9001, 181 0x9050,0x9051,0x9055,0x5057,0x5175,0}; 182 static const char*product_names
[] = { 183 "3c590 Vortex 10Mbps", 184 "3c592 EISA 10mbps Demon/Vortex", 185 "3c597 EISA Fast Demon/Vortex", 186 "3c595 Vortex 100baseTX", 187 "3c595 Vortex 100baseT4", 188 "3c595 Vortex 100base-MII", 189 "3c900 Boomerang 10baseT", 190 "3c900 Boomerang 10Mbps/Combo", 191 "3c905 Boomerang 100baseTx", 192 "3c905 Boomerang 100baseT4", 193 "3c905B Cyclone 100baseTx", 194 "3c575",/* Cardbus Boomerang */ 195 "3CCFE575",/* Cardbus ?Cyclone? */ 201 I. Board Compatibility 203 This device driver is designed for the 3Com FastEtherLink and FastEtherLink 204 XL, 3Com's PCI to 10/100baseT adapters. It also works with the 10Mbs 205 versions of the FastEtherLink cards. The supported product IDs are 206 3c590, 3c592, 3c595, 3c597, 3c900, 3c905 208 The related ISA 3c515 is supported with a separate driver, 3c515.c, included 209 with the kernel source or available from 210 cesdis.gsfc.nasa.gov:/pub/linux/drivers/3c515.html 212 II. Board-specific settings 214 PCI bus devices are configured by the system at boot time, so no jumpers 215 need to be set on the board. The system BIOS should be set to assign the 216 PCI INTA signal to an otherwise unused system IRQ line. Note: The 1.2.* 217 kernels did not support PCI interrupt sharing. 219 III. Driver operation 221 The 3c59x series use an interface that's very similar to the previous 3c5x9 222 series. The primary interface is two programmed-I/O FIFOs, with an 223 alternate single-contiguous-region bus-master transfer (see next). 225 The 3c900 "Boomerang" series uses a full-bus-master interface with separate 226 lists of transmit and receive descriptors, similar to the AMD LANCE/PCnet, 227 DEC Tulip and Intel Speedo3. The first chip version retains a compatible 228 programmed-I/O interface that has been removed in 'B' and subsequent board 231 One extension that is advertised in a very large font is that the adapters 232 are capable of being bus masters. On the Vortex chip this capability was 233 only for a single contiguous region making it far less useful than the full 234 bus master capability. There is a significant performance impact of taking 235 an extra interrupt or polling for the completion of each transfer, as well 236 as difficulty sharing the single transfer engine between the transmit and 237 receive threads. Using DMA transfers is a win only with large blocks or 238 with the flawed versions of the Intel Orion motherboard PCI controller. 240 The Boomerang chip's full-bus-master interface is useful, and has the 241 currently-unused advantages over other similar chips that queued transmit 242 packets may be reordered and receive buffer groups are associated with a 245 With full-bus-master support, this driver uses a "RX_COPYBREAK" scheme. 246 Rather than a fixed intermediate receive buffer, this scheme allocates 247 full-sized skbuffs as receive buffers. The value RX_COPYBREAK is used as 248 the copying breakpoint: it is chosen to trade-off the memory wasted by 249 passing the full-sized skbuff to the queue layer for all frames vs. the 250 copying cost of copying a frame to a correctly-sized skbuff. 253 IIIC. Synchronization 254 The driver runs as two independent, single-threaded flows of control. One 255 is the send-packet routine, which enforces single-threaded use by the 256 dev->tbusy flag. The other thread is the interrupt handler, which is single 257 threaded by the hardware and other software. 261 Thanks to Cameron Spitzer and Terry Murphy of 3Com for providing development 262 3c590, 3c595, and 3c900 boards. 263 The name "Vortex" is the internal 3Com project name for the PCI ASIC, and 264 the EISA version is called "Demon". According to Terry these names come 265 from rides at the local amusement park. 267 The new chips support both ethernet (1.5K) and FDDI (4.5K) packet sizes! 268 This driver only supports ethernet packets because of the skbuff allocation 272 #define TCOM_VENDOR_ID 0x10B7/* 3Com's manufacturer's ID. */ 274 /* Operational definitions. 275 These are not used by other compilation units and thus are not 276 exported in a ".h" file. 278 First the windows. There are eight register windows, with the command 279 and status registers available in each. 281 #define EL3WINDOW(win_num) outw(SelectWindow + (win_num), ioaddr + EL3_CMD) 283 #define EL3_STATUS 0x0e 285 /* The top five bits written to EL3_CMD are a command, the lower 286 11 bits are the parameter, if applicable. 287 Note that 11 parameters bits was fine for ethernet, but the new chip 288 can handle FDDI length frames (~4500 octets) and now parameters count 289 32-bit 'Dwords' rather than octets. */ 292 TotalReset
=0<<11, SelectWindow
=1<<11, StartCoax
=2<<11, 293 RxDisable
=3<<11, RxEnable
=4<<11, RxReset
=5<<11, 294 UpStall
=6<<11, UpUnstall
= (6<<11)+1, 295 DownStall
= (6<<11)+2, DownUnstall
= (6<<11)+3, 296 RxDiscard
=8<<11, TxEnable
=9<<11, TxDisable
=10<<11, TxReset
=11<<11, 297 FakeIntr
=12<<11, AckIntr
=13<<11, SetIntrEnb
=14<<11, 298 SetStatusEnb
=15<<11, SetRxFilter
=16<<11, SetRxThreshold
=17<<11, 299 SetTxThreshold
=18<<11, SetTxStart
=19<<11, 300 StartDMAUp
=20<<11, StartDMADown
= (20<<11)+1, StatsEnable
=21<<11, 301 StatsDisable
=22<<11, StopCoax
=23<<11,}; 303 /* The SetRxFilter command accepts the following classes: */ 305 RxStation
=1, RxMulticast
=2, RxBroadcast
=4, RxProm
=8}; 307 /* Bits in the general status register. */ 309 IntLatch
=0x0001, HostError
=0x0002, TxComplete
=0x0004, 310 TxAvailable
=0x0008, RxComplete
=0x0010, RxEarly
=0x0020, 311 IntReq
=0x0040, StatsFull
=0x0080, 312 DMADone
=1<<8, DownComplete
=1<<9, UpComplete
=1<<10, 313 DMAInProgress
=1<<11,/* DMA controller is still busy.*/ 314 CmdInProgress
=1<<12,/* EL3_CMD is still busy.*/ 317 /* Register window 1 offsets, the window used in normal operation. 318 On the Vortex this window is always mapped at offsets 0x10-0x1f. */ 320 TX_FIFO
=0x10, RX_FIFO
=0x10, RxErrors
=0x14, 321 RxStatus
=0x18, Timer
=0x1A, TxStatus
=0x1B, 322 TxFree
=0x1C,/* Remaining free bytes in Tx buffer. */ 325 Wn0EepromCmd
=10,/* Window 0: EEPROM command register. */ 326 Wn0EepromData
=12,/* Window 0: EEPROM results register. */ 327 IntrStatus
=0x0E,/* Valid in all windows. */ 329 enum Win0_EEPROM_bits
{ 330 EEPROM_Read
=0x80, EEPROM_WRITE
=0x40, EEPROM_ERASE
=0xC0, 331 EEPROM_EWENB
=0x30,/* Enable erasing/writing for 10 msec. */ 332 EEPROM_EWDIS
=0x00,/* Disable EWENB before 10 msec timeout. */ 334 /* EEPROM locations. */ 336 PhysAddr01
=0, PhysAddr23
=1, PhysAddr45
=2, ModelID
=3, 337 EtherLink3ID
=7, IFXcvrIO
=8, IRQLine
=9, 338 NodeAddr01
=10, NodeAddr23
=11, NodeAddr45
=12, 339 DriverTune
=13, Checksum
=15}; 341 enum Window3
{/* Window 3: MAC/config bits. */ 342 Wn3_Config
=0, Wn3_MAC_Ctrl
=6, Wn3_Options
=8, 346 struct w3_config_fields
{ 347 unsigned int ram_size
:3, ram_width
:1, ram_speed
:2, rom_size
:2; 349 unsigned int ram_split
:2, pad18
:2, xcvr
:4, autoselect
:1; 354 enum Window4
{/* Window 4: Xcvr/media bits. */ 355 Wn4_FIFODiag
=4, Wn4_NetDiag
=6, Wn4_PhysicalMgmt
=8, Wn4_Media
=10, 357 enum Win4_Media_bits
{ 358 Media_SQE
=0x0008,/* Enable SQE error counting for AUI. */ 359 Media_10TP
=0x00C0,/* Enable link beat and jabber for 10baseT. */ 360 Media_Lnk
=0x0080,/* Enable just link beat for 100TX/100FX. */ 361 Media_LnkBeat
=0x0800, 363 enum Window7
{/* Window 7: Bus Master control. */ 364 Wn7_MasterAddr
=0, Wn7_MasterLen
=6, Wn7_MasterStatus
=12, 366 /* Boomerang bus master control registers. */ 368 PktStatus
=0x20, DownListPtr
=0x24, FragAddr
=0x28, FragLen
=0x2c, 369 TxFreeThreshold
=0x2f, UpPktStatus
=0x30, UpListPtr
=0x38, 372 /* The Rx and Tx descriptor lists. 373 Caution Alpha hackers: these types are 32 bits! Note also the 8 byte 374 alignment contraint on tx_ring[] and rx_ring[]. */ 375 #define LAST_FRAG 0x80000000/* Last Addr/Len pair in descriptor. */ 376 struct boom_rx_desc
{ 377 u32 next
;/* Last entry points to 0. */ 379 u32 addr
;/* Up to 63 addr/len pairs possible. */ 380 s32 length
;/* Set LAST_FRAG to indicate last pair. */ 382 /* Values for the Rx status entry. */ 383 enum rx_desc_status
{ 384 RxDComplete
=0x00008000, RxDError
=0x4000, 385 /* See boomerang_rx() for actual error bits */ 386 IPChksumErr
=1<<25, TCPChksumErr
=1<<26, UDPChksumErr
=1<<27, 387 IPChksumValid
=1<<29, TCPChksumValid
=1<<30, UDPChksumValid
=1<<31, 390 struct boom_tx_desc
{ 391 u32 next
;/* Last entry points to 0. */ 392 s32 status
;/* bits 0:12 length, others see below. */ 397 /* Values for the Tx status entry. */ 398 enum tx_desc_status
{ 399 CRCDisable
=0x2000, TxDComplete
=0x8000, 400 AddIPChksum
=0x02000000, AddTCPChksum
=0x04000000, AddUDPChksum
=0x08000000, 401 TxIntrUploaded
=0x80000000,/* IRQ when in FIFO, but maybe not sent. */ 404 /* Chip features we care about in vp->capabilities, read from the EEPROM. */ 405 enum ChipCaps
{ CapBusMaster
=0x20}; 407 struct vortex_private
{ 408 char devname
[8];/* "ethN" string, also for kernel debug. */ 409 const char*product_name
; 410 struct device
*next_module
; 411 /* The Rx and Tx rings are here to keep them quad-word-aligned. */ 412 struct boom_rx_desc rx_ring
[RX_RING_SIZE
]; 413 struct boom_tx_desc tx_ring
[TX_RING_SIZE
]; 414 /* The addresses of transmit- and receive-in-place skbuffs. */ 415 struct sk_buff
* rx_skbuff
[RX_RING_SIZE
]; 416 struct sk_buff
* tx_skbuff
[TX_RING_SIZE
]; 417 unsigned int cur_rx
, cur_tx
;/* The next free ring entry */ 418 unsigned int dirty_rx
, dirty_tx
;/* The ring entries to be free()ed. */ 419 struct net_device_stats stats
; 420 struct sk_buff
*tx_skb
;/* Packet being eaten by bus master ctrl. */ 422 /* PCI configuration space information. */ 423 u8 pci_bus
, pci_dev_fn
;/* PCI bus location, for power management. */ 426 /* The remainder are related to chip state, mostly media selection. */ 427 unsigned long in_interrupt
; 428 struct timer_list timer
;/* Media selection timer. */ 429 int options
;/* User-settable misc. driver options. */ 430 unsigned int media_override
:3,/* Passed-in media type. */ 431 default_media
:4,/* Read from the EEPROM/Wn3_Config. */ 432 full_duplex
:1, force_fd
:1, autoselect
:1, 433 bus_master
:1,/* Vortex can only do a fragment bus-m. */ 434 full_bus_master_tx
:1, full_bus_master_rx
:2,/* Boomerang */ 435 hw_csums
:1,/* Has hardware checksums. */ 438 u16 available_media
;/* From Wn3_Options. */ 439 u16 capabilities
, info1
, info2
;/* Various, from EEPROM. */ 440 u16 advertising
;/* NWay media advertisement */ 441 unsigned char phys
[2];/* MII device addresses. */ 444 /* The action to take with a media selection timer tick. 445 Note that we deviate from the 3Com order by checking 10base2 before AUI. 448 XCVR_10baseT
=0, XCVR_AUI
, XCVR_10baseTOnly
, XCVR_10base2
, XCVR_100baseTx
, 449 XCVR_100baseFx
, XCVR_MII
=6, XCVR_NWAY
=8, XCVR_ExtMII
=9, XCVR_Default
=10, 452 static struct media_table
{ 454 unsigned int media_bits
:16,/* Bits to set in Wn4_Media register. */ 455 mask
:8,/* The transceiver-present bit in Wn3_Config.*/ 456 next
:8;/* The media type to try next. */ 457 int wait
;/* Time before we check media status. */ 459 {"10baseT", Media_10TP
,0x08, XCVR_10base2
, (14*HZ
)/10}, 460 {"10Mbs AUI", Media_SQE
,0x20, XCVR_Default
, (1*HZ
)/10}, 461 {"undefined",0,0x80, XCVR_10baseT
,10000}, 462 {"10base2",0,0x10, XCVR_AUI
, (1*HZ
)/10}, 463 {"100baseTX", Media_Lnk
,0x02, XCVR_100baseFx
, (14*HZ
)/10}, 464 {"100baseFX", Media_Lnk
,0x04, XCVR_MII
, (14*HZ
)/10}, 465 {"MII",0,0x41, XCVR_10baseT
,3*HZ
}, 466 {"undefined",0,0x01, XCVR_10baseT
,10000}, 467 {"Autonegotiate",0,0x41, XCVR_10baseT
,3*HZ
}, 468 {"MII-External",0,0x41, XCVR_10baseT
,3*HZ
}, 469 {"Default",0,0xFF, XCVR_10baseT
,10000}, 472 static intvortex_scan(struct device
*dev
); 473 static struct device
*vortex_found_device(struct device
*dev
,long ioaddr
, 474 int irq
,int device_id
, 475 int options
,int card_idx
); 476 static intvortex_probe1(struct device
*dev
); 477 static intvortex_open(struct device
*dev
); 478 static voidmdio_sync(long ioaddr
,int bits
); 479 static intmdio_read(long ioaddr
,int phy_id
,int location
); 480 #ifdef HAVE_PRIVATE_IOCTL 481 static voidmdio_write(long ioaddr
,int phy_id
,int location
,int value
); 483 static voidvortex_timer(unsigned long arg
); 484 static intvortex_start_xmit(struct sk_buff
*skb
,struct device
*dev
); 485 static intboomerang_start_xmit(struct sk_buff
*skb
,struct device
*dev
); 486 static intvortex_rx(struct device
*dev
); 487 static intboomerang_rx(struct device
*dev
); 488 static void vortex_interrupt
IRQ(int irq
,void*dev_id
,struct pt_regs
*regs
); 489 static intvortex_close(struct device
*dev
); 490 static voidupdate_stats(long ioaddr
,struct device
*dev
); 491 static struct net_device_stats
*vortex_get_stats(struct device
*dev
); 492 static voidset_rx_mode(struct device
*dev
); 493 #ifdef HAVE_PRIVATE_IOCTL 494 static intvortex_ioctl(struct device
*dev
,struct ifreq
*rq
,int cmd
); 496 #ifndef NEW_MULTICAST 497 static voidset_multicast_list(struct device
*dev
,int num_addrs
,void*addrs
); 501 /* Unlike the other PCI cards the 59x cards don't need a large contiguous 502 memory region, so making the driver a loadable module is feasible. 504 Unfortunately maximizing the shared code between the integrated and 505 module version of the driver results in a complicated set of initialization 507 init_module() -- modules / tc59x_init() -- built-in 508 The wrappers for vortex_scan() 509 vortex_scan() The common routine that scans for PCI and EISA cards 510 vortex_found_device() Allocate a device structure when we find a card. 511 Different versions exist for modules and built-in. 512 vortex_probe1() Fill in the device structure -- this is separated 513 so that the modules code can put it in dev->init. 515 /* This driver uses 'options' to pass the media type, full-duplex flag, etc. */ 516 /* Note: this is the only limit on the number of cards supported!! */ 517 static int options
[8] = { -1, -1, -1, -1, -1, -1, -1, -1,}; 518 static int full_duplex
[8] = {-1, -1, -1, -1, -1, -1, -1, -1}; 519 /* A list of all installed Vortex devices, for removing the driver module. */ 520 static struct device
*root_vortex_dev
= NULL
; 523 /* Variables to work-around the Compaq PCI BIOS32 problem. */ 524 static int compaq_ioaddr
=0, compaq_irq
=0, compaq_device_id
=0x5900; 526 static int debug
= -1; 530 #include <pcmcia/driver_ops.h> 532 static dev_node_t
*vortex_attach(dev_locator_t
*loc
) 539 if(loc
->bus
!= LOC_PCI
)return NULL
; 540 bus
= loc
->b
.pci
.bus
; devfn
= loc
->b
.pci
.devfn
; 541 printk(KERN_INFO
"vortex_attach(bus %d, function %d)\n", bus
, devfn
); 542 pcibios_read_config_dword(bus
, devfn
, PCI_BASE_ADDRESS_0
, &io
); 543 pcibios_read_config_byte(bus
, devfn
, PCI_INTERRUPT_LINE
, &irq
); 544 pcibios_read_config_word(bus
, devfn
, PCI_DEVICE_ID
, &dev_id
); 546 dev
=vortex_found_device(NULL
, io
, irq
, dev_id
,0, -1); 548 dev_node_t
*node
=kmalloc(sizeof(dev_node_t
), GFP_KERNEL
); 549 strcpy(node
->dev_name
, dev
->name
); 550 node
->major
= node
->minor
=0; 558 static voidvortex_detach(dev_node_t
*node
) 560 struct device
**devp
, **next
; 561 printk(KERN_INFO
"vortex_detach(%s)\n", node
->dev_name
); 562 for(devp
= &root_vortex_dev
; *devp
; devp
= next
) { 563 next
= &((struct vortex_private
*)(*devp
)->priv
)->next_module
; 564 if(strcmp((*devp
)->name
, node
->dev_name
) ==0)break; 567 struct device
*dev
= *devp
; 568 if(dev
->flags
& IFF_UP
) 570 dev
->flags
&= ~(IFF_UP
|IFF_RUNNING
); 571 unregister_netdev(dev
); 579 struct driver_operations vortex_ops
= { 580 "3c59x_cb", vortex_attach
, NULL
, NULL
, vortex_detach
583 #endif/* Cardbus support */ 590 vortex_debug
= debug
; 594 root_vortex_dev
= NULL
; 596 register_driver(&vortex_ops
); 600 int cards_found
=vortex_scan(0); 602 printk("No 3Com Vortex/Boomerang cards found.\n"); 603 return cards_found
?0: -ENODEV
; 609 inttc59x_probe(struct device
*dev
) 613 cards_found
=vortex_scan(dev
); 615 if(vortex_debug
>0&& cards_found
) 618 return cards_found
?0: -ENODEV
; 620 #endif/* not MODULE */ 622 static intvortex_scan(struct device
*dev
) 626 /* Allow an EISA-only driver. */ 627 #if defined(CONFIG_PCI) || (defined(MODULE) && !defined(NO_PCI)) 628 /* Ideally we would detect all cards in slot order. That would 629 be best done a central PCI probe dispatch, which wouldn't work 630 well with the current structure. So instead we detect 3Com cards 632 if(pcibios_present()) { 633 static int pci_index
=0; 634 unsigned char pci_bus
, pci_device_fn
; 636 for(;pci_index
<0xff; pci_index
++) { 638 u16 pci_command
, new_command
, vendor
, device
; 642 if(pcibios_find_class(PCI_CLASS_NETWORK_ETHERNET
<<8, 643 pci_index
, &pci_bus
, &pci_device_fn
) 644 != PCIBIOS_SUCCESSFUL
) 646 pcibios_read_config_word(pci_bus
, pci_device_fn
, 647 PCI_VENDOR_ID
, &vendor
); 648 pcibios_read_config_word(pci_bus
, pci_device_fn
, 649 PCI_DEVICE_ID
, &device
); 650 pcibios_read_config_word(pci_bus
, pci_device_fn
, 651 PCI_COMMAND
, &pci_command
); 653 #if LINUX_VERSION_CODE >= 0x20155 654 struct pci_dev
*pdev
=pci_find_slot(pci_bus
, pci_device_fn
); 655 ioaddr
= pdev
->base_address
[0]; 660 pcibios_read_config_byte(pci_bus
, pci_device_fn
, 661 PCI_INTERRUPT_LINE
, &pci_irq_line
); 662 pcibios_read_config_dword(pci_bus
, pci_device_fn
, 663 PCI_BASE_ADDRESS_0
, &pci_ioaddr
); 668 /* Remove I/O space marker in bit 0. */ 671 if(vendor
!= TCOM_VENDOR_ID
) 674 /* Power-up the card. */ 675 pcibios_read_config_word(pci_bus
, pci_device_fn
, 677 if(pci_command
&0x3) { 678 /* Save the ioaddr and IRQ info! */ 679 printk(KERN_INFO
" A 3Com network adapter is powered down!" 680 " Setting the power state %4.4x->%4.4x.\n", 681 pci_command
, pci_command
& ~3); 682 pcibios_write_config_word(pci_bus
, pci_device_fn
, 683 0xe0, pci_command
& ~3); 684 printk(KERN_INFO
" Setting the IRQ to %d, IOADDR to %#lx.\n", 686 pcibios_write_config_byte(pci_bus
, pci_device_fn
, 687 PCI_INTERRUPT_LINE
, irq
); 688 pcibios_write_config_dword(pci_bus
, pci_device_fn
, 689 PCI_BASE_ADDRESS_0
, ioaddr
); 693 printk(KERN_WARNING
" A 3Com network adapter has been found, " 694 "however it has not been assigned an I/O address.\n" 695 " You may need to power-cycle the machine for this " 696 "device to work!\n"); 700 if(check_region(ioaddr
, VORTEX_TOTAL_SIZE
)) 703 /* Activate the card. */ 704 new_command
= pci_command
| PCI_COMMAND_MASTER
|PCI_COMMAND_IO
; 705 if(pci_command
!= new_command
) { 706 printk(KERN_INFO
" The PCI BIOS has not enabled this" 707 " device! Updating PCI command %4.4x->%4.4x.\n", 708 pci_command
, new_command
); 709 pcibios_write_config_word(pci_bus
, pci_device_fn
, 710 PCI_COMMAND
, new_command
); 713 dev
=vortex_found_device(dev
, ioaddr
, irq
, 714 device
, dev
&& dev
->mem_start
715 ? dev
->mem_start
: options
[cards_found
], 719 struct vortex_private
*vp
= (struct vortex_private
*)dev
->priv
; 720 /* Get and check the latency values. On the 3c590 series 721 the latency timer must be set to the maximum value to avoid 722 data corruption that occurs when the timer expires during 723 a transfer -- a bug in the Vortex chip only. */ 724 u8 new_latency
= (device
&0xff00) ==0x5900?248:32; 725 vp
->pci_bus
= pci_bus
; 726 vp
->pci_dev_fn
= pci_device_fn
; 727 vp
->pci_device_id
= device
; 729 pcibios_read_config_byte(pci_bus
, pci_device_fn
, 730 PCI_LATENCY_TIMER
, &pci_latency
); 731 if(pci_latency
< new_latency
) { 732 printk(KERN_INFO
"%s: Overriding PCI latency" 733 " timer (CFLT) setting of %d, new value is %d.\n", 734 dev
->name
, pci_latency
, new_latency
); 735 pcibios_write_config_byte(pci_bus
, pci_device_fn
, 736 PCI_LATENCY_TIMER
, new_latency
); 745 /* Now check all slots of the EISA bus. */ 747 static long ioaddr
=0x1000; 748 for( ; ioaddr
<0x9000; ioaddr
+=0x1000) { 750 if(check_region(ioaddr
, VORTEX_TOTAL_SIZE
)) 752 /* Check the standard EISA ID register for an encoded '3Com'. */ 753 if(inw(ioaddr
+0xC80) !=0x6d50) 755 /* Check for a product that we support, 3c59{2,7} any rev. */ 756 device_id
= (inb(ioaddr
+0xC82)<<8) +inb(ioaddr
+0xC83); 757 if((device_id
&0xFF00) !=0x5900) 759 vortex_found_device(dev
, ioaddr
,inw(ioaddr
+0xC88) >>12, 760 device_id
, dev
&& dev
->mem_start
761 ? dev
->mem_start
: options
[cards_found
], 769 /* Special code to work-around the Compaq PCI BIOS32 problem. */ 771 vortex_found_device(dev
, compaq_ioaddr
, compaq_irq
, compaq_device_id
, 772 dev
&& dev
->mem_start
? dev
->mem_start
773 : options
[cards_found
], cards_found
); 779 /* 3c515 cards are now supported by the 3c515.c driver. */ 784 static struct device
* 785 vortex_found_device(struct device
*dev
,long ioaddr
,int irq
, 786 int device_id
,int option
,int card_idx
) 788 struct vortex_private
*vp
; 789 const char*product_name
; 792 for(board_index
=0; product_ids
[board_index
]; board_index
++) { 793 if(device_id
== product_ids
[board_index
]) 796 /* Handle products we don't recognize, but might still work with. */ 797 if(product_ids
[board_index
]) 798 product_name
= product_names
[board_index
]; 799 else if((device_id
&0xff00) ==0x5900) 800 product_name
="3c590 Vortex"; 801 else if((device_id
&0xfff0) ==0x9000) 802 product_name
="3c900"; 803 else if((device_id
&0xfff0) ==0x9050) 804 product_name
="3c905"; 806 printk(KERN_WARNING
"Unknown 3Com PCI ethernet adapter type %4.4x detected:" 807 " not configured.\n", device_id
); 812 /* Allocate and fill new device structure. */ 814 int dev_size
=sizeof(struct device
) + 815 sizeof(struct vortex_private
) +15;/* Pad for alignment */ 817 dev
= (struct device
*)kmalloc(dev_size
, GFP_KERNEL
); 818 memset(dev
,0, dev_size
); 820 /* Align the Rx and Tx ring entries. */ 821 dev
->priv
= (void*)(((long)dev
+sizeof(struct device
) +15) & ~15); 822 vp
= (struct vortex_private
*)dev
->priv
; 823 dev
->name
= vp
->devname
;/* An empty string. */ 824 dev
->base_addr
= ioaddr
; 826 dev
->init
= vortex_probe1
; 827 vp
->product_name
= product_name
; 828 vp
->options
= option
; 830 if(full_duplex
[card_idx
] >=0) 831 vp
->full_duplex
= full_duplex
[card_idx
]; 833 vp
->full_duplex
= (option
>0&& (option
&0x10) ?1:0); 836 vp
->media_override
= ((option
&7) == XCVR_10baseTOnly
) ? 837 XCVR_10baseT
: option
&7; 838 vp
->bus_master
= (option
&16) ?1:0; 840 vp
->media_override
=7; 844 vp
->next_module
= root_vortex_dev
; 845 root_vortex_dev
= dev
; 846 if(register_netdev(dev
) !=0) 848 #else/* not a MODULE */ 850 /* Caution: quad-word alignment required for rings! */ 851 dev
->priv
=kmalloc(sizeof(struct vortex_private
), GFP_KERNEL
); 852 memset(dev
->priv
,0,sizeof(struct vortex_private
)); 854 dev
=init_etherdev(dev
,sizeof(struct vortex_private
)); 855 dev
->base_addr
= ioaddr
; 859 vp
= (struct vortex_private
*)dev
->priv
; 860 vp
->product_name
= product_name
; 861 vp
->options
= option
; 863 vp
->media_override
= ((option
&7) ==2) ?0: option
&7; 864 vp
->full_duplex
= (option
&8) ?1:0; 865 vp
->bus_master
= (option
&16) ?1:0; 867 vp
->media_override
=7; 871 vp
->force_fd
= vp
->full_duplex
; 878 static intvortex_probe1(struct device
*dev
) 880 long ioaddr
= dev
->base_addr
; 881 struct vortex_private
*vp
= (struct vortex_private
*)dev
->priv
; 882 u16
*ether_addr
= (u16
*)dev
->dev_addr
; 883 unsigned int eeprom
[0x40], checksum
=0;/* EEPROM contents */ 886 printk(KERN_INFO
"%s: 3Com %s at %#3lx,", 887 dev
->name
, vp
->product_name
, ioaddr
); 889 /* Read the station address from the EEPROM. */ 891 for(i
=0; i
<0x40; i
++) { 894 outw(0x230+ i
, ioaddr
+ Wn0EepromCmd
); 896 outw(EEPROM_Read
+ i
, ioaddr
+ Wn0EepromCmd
); 898 /* Pause for at least 162 us. for the read to take place. */ 899 for(timer
=10; timer
>=0; timer
--) { 901 if((inw(ioaddr
+ Wn0EepromCmd
) &0x8000) ==0) 904 eeprom
[i
] =inw(ioaddr
+ Wn0EepromData
); 906 for(i
=0; i
<0x18; i
++) 907 checksum
^= eeprom
[i
]; 908 checksum
= (checksum
^ (checksum
>>8)) &0xff; 909 if(checksum
!=0x00) {/* Grrr, needless incompatible change 3Com. */ 911 checksum
^= eeprom
[i
++]; 912 checksum
= (checksum
^ (checksum
>>8)) &0xff; 915 printk(" ***INVALID CHECKSUM %4.4x*** ", checksum
); 918 ether_addr
[i
] =htons(eeprom
[i
+10]); 920 printk("%c%2.2x", i
?':':' ', dev
->dev_addr
[i
]); 922 printk(", IRQ %s\n",__irq_itoa(dev
->irq
)); 924 printk(", IRQ %d\n", dev
->irq
); 925 /* Tell them about an invalid IRQ. */ 926 if(vortex_debug
&& (dev
->irq
<=0|| dev
->irq
>= NR_IRQS
)) 927 printk(KERN_WARNING
" *** Warning: IRQ %d is unlikely to work! ***\n", 931 /* Extract our information from the EEPROM data. */ 932 vp
->info1
= eeprom
[13]; 933 vp
->info2
= eeprom
[15]; 934 vp
->capabilities
= eeprom
[16]; 936 if(vp
->info1
&0x8000) 940 char*ram_split
[] = {"5:3","3:1","1:1","3:5"}; 941 union wn3_config config
; 943 vp
->available_media
=inw(ioaddr
+ Wn3_Options
); 944 if((vp
->available_media
&0xff) ==0)/* Broken 3c916 */ 945 vp
->available_media
=0x40; 946 config
.i
=inl(ioaddr
+ Wn3_Config
); 948 printk(KERN_DEBUG
" Internal config register is %4.4x, " 949 "transceivers %#x.\n", config
.i
,inw(ioaddr
+ Wn3_Options
)); 950 printk(KERN_INFO
" %dK %s-wide RAM %s Rx:Tx split, %s%s interface.\n", 951 8<< config
.u
.ram_size
, 952 config
.u
.ram_width
?"word":"byte", 953 ram_split
[config
.u
.ram_split
], 954 config
.u
.autoselect
?"autoselect/":"", 955 config
.u
.xcvr
> XCVR_ExtMII
?"<invalid transceiver>": 956 media_tbl
[config
.u
.xcvr
].name
); 957 vp
->default_media
= config
.u
.xcvr
; 958 vp
->autoselect
= config
.u
.autoselect
; 961 if(vp
->media_override
!=7) { 962 printk(KERN_INFO
" Media override to transceiver type %d (%s).\n", 963 vp
->media_override
, media_tbl
[vp
->media_override
].name
); 964 dev
->if_port
= vp
->media_override
; 966 dev
->if_port
= vp
->default_media
; 968 if(dev
->if_port
== XCVR_MII
|| dev
->if_port
== XCVR_NWAY
) { 971 for(phy
=0; phy
<32&& phy_idx
<sizeof(vp
->phys
); phy
++) { 973 mdio_sync(ioaddr
,32); 974 mii_status
=mdio_read(ioaddr
, phy
,1); 975 if(mii_status
&& mii_status
!=0xffff) { 976 vp
->phys
[phy_idx
++] = phy
; 977 printk(KERN_INFO
" MII transceiver found at address %d, status %4x.\n", 979 mdio_sync(ioaddr
,32); 980 if((mdio_read(ioaddr
, phy
,1) &0x0040) ==0) 981 mii_preamble_required
=1; 985 printk(KERN_WARNING
" ***WARNING*** No MII transceivers found!\n"); 988 vp
->advertising
=mdio_read(ioaddr
, vp
->phys
[0],4); 989 if(vp
->full_duplex
) { 990 /* Only advertise the FD media types. */ 991 vp
->advertising
&=0x015F; 992 mdio_write(ioaddr
, vp
->phys
[0],4, vp
->advertising
); 997 if(vp
->capabilities
& CapBusMaster
) { 998 vp
->full_bus_master_tx
=1; 999 printk(KERN_INFO
" Enabling bus-master transmits and %s receives.\n", 1000 (vp
->info2
&1) ?"early":"whole-frame"); 1001 vp
->full_bus_master_rx
= (vp
->info2
&1) ?1:2; 1004 /* We do a request_region() to register /proc/ioports info. */ 1005 request_region(ioaddr
, VORTEX_TOTAL_SIZE
, vp
->product_name
); 1007 /* The 3c59x-specific entries in the device structure. */ 1008 dev
->open
= &vortex_open
; 1009 dev
->hard_start_xmit
= &vortex_start_xmit
; 1010 dev
->stop
= &vortex_close
; 1011 dev
->get_stats
= &vortex_get_stats
; 1012 #ifdef HAVE_PRIVATE_IOCTL 1013 dev
->do_ioctl
= &vortex_ioctl
; 1015 #ifdef NEW_MULTICAST 1016 dev
->set_multicast_list
= &set_rx_mode
; 1018 dev
->set_multicast_list
= &set_multicast_list
; 1026 vortex_open(struct device
*dev
) 1028 long ioaddr
= dev
->base_addr
; 1029 struct vortex_private
*vp
= (struct vortex_private
*)dev
->priv
; 1030 union wn3_config config
; 1033 /* Before initializing select the active media port. */ 1035 config
.i
=inl(ioaddr
+ Wn3_Config
); 1037 if(vp
->media_override
!=7) { 1039 printk(KERN_INFO
"%s: Media override to transceiver %d (%s).\n", 1040 dev
->name
, vp
->media_override
, 1041 media_tbl
[vp
->media_override
].name
); 1042 dev
->if_port
= vp
->media_override
; 1043 }else if(vp
->autoselect
) { 1044 /* Find first available media type, starting with 100baseTx. */ 1045 dev
->if_port
= XCVR_100baseTx
; 1046 while(! (vp
->available_media
& media_tbl
[dev
->if_port
].mask
)) 1047 dev
->if_port
= media_tbl
[dev
->if_port
].next
; 1049 dev
->if_port
= XCVR_NWAY
; 1052 printk(KERN_DEBUG
"%s: Initial media type %s.\n", 1053 dev
->name
, media_tbl
[dev
->if_port
].name
); 1055 init_timer(&vp
->timer
); 1056 vp
->timer
.expires
=RUN_AT(media_tbl
[dev
->if_port
].wait
); 1057 vp
->timer
.data
= (unsigned long)dev
; 1058 vp
->timer
.function
= &vortex_timer
;/* timer handler */ 1059 add_timer(&vp
->timer
); 1061 dev
->if_port
= vp
->default_media
; 1063 vp
->full_duplex
= vp
->force_fd
; 1064 config
.u
.xcvr
= dev
->if_port
; 1065 outl(config
.i
, ioaddr
+ Wn3_Config
); 1067 if(dev
->if_port
== XCVR_MII
|| dev
->if_port
== XCVR_NWAY
) { 1068 int mii_reg1
, mii_reg5
; 1070 /* Read BMSR (reg1) only to clear old status. */ 1071 mii_reg1
=mdio_read(ioaddr
, vp
->phys
[0],1); 1072 mii_reg5
=mdio_read(ioaddr
, vp
->phys
[0],5); 1073 if(mii_reg5
==0xffff|| mii_reg5
==0x0000) 1074 ;/* No MII device or no link partner report */ 1075 else if((mii_reg5
&0x0100) !=0/* 100baseTx-FD */ 1076 || (mii_reg5
&0x00C0) ==0x0040)/* 10T-FD, but not 100-HD */ 1079 printk(KERN_INFO
"%s: MII #%d status %4.4x, link partner capability %4.4x," 1080 " setting %s-duplex.\n", dev
->name
, vp
->phys
[0], 1081 mii_reg1
, mii_reg5
, vp
->full_duplex
?"full":"half"); 1085 /* Set the full-duplex bit. */ 1086 outb(((vp
->info1
&0x8000) || vp
->full_duplex
?0x20:0) | 1087 (dev
->mtu
>1500?0x40:0), ioaddr
+ Wn3_MAC_Ctrl
); 1089 if(vortex_debug
>1) { 1090 printk(KERN_DEBUG
"%s: vortex_open() InternalConfig %8.8x.\n", 1091 dev
->name
, config
.i
); 1094 outw(TxReset
, ioaddr
+ EL3_CMD
); 1095 for(i
=2000; i
>=0; i
--) 1096 if( ! (inw(ioaddr
+ EL3_STATUS
) & CmdInProgress
)) 1099 outw(RxReset
, ioaddr
+ EL3_CMD
); 1100 /* Wait a few ticks for the RxReset command to complete. */ 1101 for(i
=2000; i
>=0; i
--) 1102 if( ! (inw(ioaddr
+ EL3_STATUS
) & CmdInProgress
)) 1105 outw(SetStatusEnb
|0x00, ioaddr
+ EL3_CMD
); 1108 /* Use the now-standard shared IRQ implementation. */ 1109 if(request_irq(dev
->irq
, &vortex_interrupt
, SA_SHIRQ
, dev
->name
, dev
)) { 1113 if(dev
->irq
==0|| irq2dev_map
[dev
->irq
] != NULL
) 1115 irq2dev_map
[dev
->irq
] = dev
; 1116 if(request_irq(dev
->irq
, &vortex_interrupt
,0, vp
->product_name
)) { 1117 irq2dev_map
[dev
->irq
] = NULL
; 1122 if(vortex_debug
>1) { 1124 printk(KERN_DEBUG
"%s: vortex_open() irq %d media status %4.4x.\n", 1125 dev
->name
, dev
->irq
,inw(ioaddr
+ Wn4_Media
)); 1128 /* Set the station address and mask in window 2 each time opened. */ 1130 for(i
=0; i
<6; i
++) 1131 outb(dev
->dev_addr
[i
], ioaddr
+ i
); 1133 outw(0, ioaddr
+ i
); 1135 if(dev
->if_port
== XCVR_10base2
) 1136 /* Start the thinnet transceiver. We should really wait 50ms...*/ 1137 outw(StartCoax
, ioaddr
+ EL3_CMD
); 1139 outw((inw(ioaddr
+ Wn4_Media
) & ~(Media_10TP
|Media_SQE
)) | 1140 media_tbl
[dev
->if_port
].media_bits
, ioaddr
+ Wn4_Media
); 1142 /* Switch to the stats window, and clear all stats by reading. */ 1143 outw(StatsDisable
, ioaddr
+ EL3_CMD
); 1145 for(i
=0; i
<10; i
++) 1149 /* New: On the Vortex we must also clear the BadSSD counter. */ 1152 /* ..and on the Boomerang we enable the extra statistics bits. */ 1153 outw(0x0040, ioaddr
+ Wn4_NetDiag
); 1155 /* Switch to register set 7 for normal use. */ 1158 if(vp
->full_bus_master_rx
) {/* Boomerang bus master. */ 1159 vp
->cur_rx
= vp
->dirty_rx
=0; 1160 /* Initialize the RxEarly register as recommended. */ 1161 outw(SetRxThreshold
+ (1536>>2), ioaddr
+ EL3_CMD
); 1162 outl(0x0020, ioaddr
+ PktStatus
); 1164 printk(KERN_DEBUG
"%s: Filling in the Rx ring.\n", dev
->name
); 1165 for(i
=0; i
< RX_RING_SIZE
; i
++) { 1166 struct sk_buff
*skb
; 1167 vp
->rx_ring
[i
].next
=cpu_to_le32(virt_to_bus(&vp
->rx_ring
[i
+1])); 1168 vp
->rx_ring
[i
].status
=0;/* Clear complete bit. */ 1169 vp
->rx_ring
[i
].length
=cpu_to_le32(PKT_BUF_SZ
| LAST_FRAG
); 1170 skb
=DEV_ALLOC_SKB(PKT_BUF_SZ
); 1171 vp
->rx_skbuff
[i
] = skb
; 1173 break;/* Bad news! */ 1174 skb
->dev
= dev
;/* Mark as being used by this device. */ 1175 #if LINUX_VERSION_CODE >= 0x10300 1176 skb_reserve(skb
,2);/* Align IP on 16 byte boundaries */ 1177 vp
->rx_ring
[i
].addr
=cpu_to_le32(virt_to_bus(skb
->tail
)); 1179 vp
->rx_ring
[i
].addr
=virt_to_bus(skb
->data
); 1182 /* Wrap the ring. */ 1183 vp
->rx_ring
[i
-1].next
=cpu_to_le32(virt_to_bus(&vp
->rx_ring
[0])); 1184 outl(virt_to_bus(&vp
->rx_ring
[0]), ioaddr
+ UpListPtr
); 1186 if(vp
->full_bus_master_tx
) {/* Boomerang bus master Tx. */ 1187 dev
->hard_start_xmit
= &boomerang_start_xmit
; 1188 vp
->cur_tx
= vp
->dirty_tx
=0; 1189 outb(PKT_BUF_SZ
>>8, ioaddr
+ TxFreeThreshold
);/* Room for a packet. */ 1190 /* Clear the Tx ring. */ 1191 for(i
=0; i
< TX_RING_SIZE
; i
++) 1192 vp
->tx_skbuff
[i
] =0; 1193 outl(0, ioaddr
+ DownListPtr
); 1195 /* Set reciever mode: presumably accept b-case and phys addr only. */ 1197 outw(StatsEnable
, ioaddr
+ EL3_CMD
);/* Turn on statistics. */ 1199 vp
->in_interrupt
=0; 1204 outw(RxEnable
, ioaddr
+ EL3_CMD
);/* Enable the receiver. */ 1205 outw(TxEnable
, ioaddr
+ EL3_CMD
);/* Enable transmitter. */ 1206 /* Allow status bits to be seen. */ 1207 vp
->status_enable
= SetStatusEnb
| HostError
|IntReq
|StatsFull
|TxComplete
| 1208 (vp
->full_bus_master_tx
? DownComplete
: TxAvailable
) | 1209 (vp
->full_bus_master_rx
? UpComplete
: RxComplete
) | 1210 (vp
->bus_master
? DMADone
:0); 1211 outw(vp
->status_enable
, ioaddr
+ EL3_CMD
); 1212 /* Ack all pending events, and set active indicator mask. */ 1213 outw(AckIntr
| IntLatch
| TxAvailable
| RxEarly
| IntReq
, 1215 outw(SetIntrEnb
| IntLatch
| TxAvailable
| RxComplete
| StatsFull
1216 | HostError
| TxComplete
1217 | (vp
->bus_master
? DMADone
:0) | UpComplete
| DownComplete
, 1225 static voidvortex_timer(unsigned long data
) 1227 struct device
*dev
= (struct device
*)data
; 1228 struct vortex_private
*vp
= (struct vortex_private
*)dev
->priv
; 1229 long ioaddr
= dev
->base_addr
; 1230 unsigned long flags
; 1233 int media_status
, old_window
; 1236 printk(KERN_DEBUG
"%s: Media selection timer tick happened, %s.\n", 1237 dev
->name
, media_tbl
[dev
->if_port
].name
); 1241 old_window
=inw(ioaddr
+ EL3_CMD
) >>13; 1243 media_status
=inw(ioaddr
+ Wn4_Media
); 1244 switch(dev
->if_port
) { 1245 case XCVR_10baseT
:case XCVR_100baseTx
:case XCVR_100baseFx
: 1246 if(media_status
& Media_LnkBeat
) { 1249 printk(KERN_DEBUG
"%s: Media %s has link beat, %x.\n", 1250 dev
->name
, media_tbl
[dev
->if_port
].name
, media_status
); 1251 }else if(vortex_debug
>1) 1252 printk(KERN_DEBUG
"%s: Media %s is has no link beat, %x.\n", 1253 dev
->name
, media_tbl
[dev
->if_port
].name
, media_status
); 1255 case XCVR_MII
:case XCVR_NWAY
: 1256 if(mdio_read(ioaddr
, vp
->phys
[0],1) &0x0004) { 1257 int mii_reg5
=mdio_read(ioaddr
, vp
->phys
[0],5); 1259 if(! vp
->force_fd
&& mii_reg5
!=0xffff) { 1260 int duplex
= (mii_reg5
&0x0100) || 1261 (mii_reg5
&0x01C0) ==0x0040; 1262 if(vp
->full_duplex
!= duplex
) { 1263 vp
->full_duplex
= duplex
; 1264 printk(KERN_INFO
"%s: Setting %s-duplex based on MII " 1265 "#%d link partner capability of %4.4x.\n", 1266 dev
->name
, vp
->full_duplex
?"full":"half", 1267 vp
->phys
[0], mii_reg5
); 1268 /* Set the full-duplex bit. */ 1269 outb((vp
->full_duplex
?0x20:0) | 1270 (dev
->mtu
>1500?0x40:0), 1271 ioaddr
+ Wn3_MAC_Ctrl
); 1277 default:/* Other media types handled by Tx timeouts. */ 1279 printk(KERN_DEBUG
"%s: Media %s is has no indication, %x.\n", 1280 dev
->name
, media_tbl
[dev
->if_port
].name
, media_status
); 1284 union wn3_config config
; 1287 dev
->if_port
= media_tbl
[dev
->if_port
].next
; 1288 }while( ! (vp
->available_media
& media_tbl
[dev
->if_port
].mask
)); 1289 if(dev
->if_port
== XCVR_Default
) {/* Go back to default. */ 1290 dev
->if_port
= vp
->default_media
; 1292 printk(KERN_DEBUG
"%s: Media selection failing, using default " 1294 dev
->name
, media_tbl
[dev
->if_port
].name
); 1297 printk(KERN_DEBUG
"%s: Media selection failed, now trying " 1299 dev
->name
, media_tbl
[dev
->if_port
].name
); 1300 next_tick
=RUN_AT(media_tbl
[dev
->if_port
].wait
); 1302 outw((media_status
& ~(Media_10TP
|Media_SQE
)) | 1303 media_tbl
[dev
->if_port
].media_bits
, ioaddr
+ Wn4_Media
); 1306 config
.i
=inl(ioaddr
+ Wn3_Config
); 1307 config
.u
.xcvr
= dev
->if_port
; 1308 outl(config
.i
, ioaddr
+ Wn3_Config
); 1310 outw(dev
->if_port
== XCVR_10base2
? StartCoax
: StopCoax
, 1313 EL3WINDOW(old_window
); 1314 restore_flags(flags
); 1317 printk(KERN_DEBUG
"%s: Media selection timer finished, %s.\n", 1318 dev
->name
, media_tbl
[dev
->if_port
].name
); 1321 vp
->timer
.expires
=RUN_AT(next_tick
); 1322 add_timer(&vp
->timer
); 1327 static voidvortex_tx_timeout(struct device
*dev
) 1329 struct vortex_private
*vp
= (struct vortex_private
*)dev
->priv
; 1330 long ioaddr
= dev
->base_addr
; 1333 printk(KERN_ERR
"%s: transmit timed out, tx_status %2.2x status %4.4x.\n", 1334 dev
->name
,inb(ioaddr
+ TxStatus
), 1335 inw(ioaddr
+ EL3_STATUS
)); 1336 /* Slight code bloat to be user friendly. */ 1337 if((inb(ioaddr
+ TxStatus
) &0x88) ==0x88) 1338 printk(KERN_ERR
"%s: Transmitter encountered 16 collisions --" 1339 " network cable problem?\n", dev
->name
); 1340 if(inw(ioaddr
+ EL3_STATUS
) & IntLatch
) { 1341 printk(KERN_ERR
"%s: Interrupt posted but not delivered --" 1342 " IRQ blocked by another device?\n", dev
->name
); 1343 /* Bad idea here.. but we might as well handle a few events. */ 1344 vortex_interrupt
IRQ(dev
->irq
, dev
,0); 1346 outw(TxReset
, ioaddr
+ EL3_CMD
); 1347 for(j
=200; j
>=0; j
--) 1348 if( ! (inw(ioaddr
+ EL3_STATUS
) & CmdInProgress
)) 1351 #if ! defined(final_version) && LINUX_VERSION_CODE >= 0x10300 1352 if(vp
->full_bus_master_tx
) { 1354 printk(KERN_DEBUG
" Flags; bus-master %d, full %d; dirty %d " 1356 vp
->full_bus_master_tx
, vp
->tx_full
, vp
->dirty_tx
, vp
->cur_tx
); 1357 printk(KERN_DEBUG
" Transmit list %8.8x vs. %p.\n", 1358 inl(ioaddr
+ DownListPtr
), 1359 &vp
->tx_ring
[vp
->dirty_tx
% TX_RING_SIZE
]); 1360 for(i
=0; i
< TX_RING_SIZE
; i
++) { 1361 printk(KERN_DEBUG
" %d: @%p length %8.8x status %8.8x\n", i
, 1363 le32_to_cpu(vp
->tx_ring
[i
].length
), 1364 le32_to_cpu(vp
->tx_ring
[i
].status
)); 1368 vp
->stats
.tx_errors
++; 1369 if(vp
->full_bus_master_tx
) { 1371 printk(KERN_DEBUG
"%s: Resetting the Tx ring pointer.\n", 1373 if(vp
->cur_tx
- vp
->dirty_tx
>0&&inl(ioaddr
+ DownListPtr
) ==0) 1374 outl(virt_to_bus(&vp
->tx_ring
[vp
->dirty_tx
% TX_RING_SIZE
]), 1375 ioaddr
+ DownListPtr
); 1376 if(vp
->tx_full
&& (vp
->cur_tx
- vp
->dirty_tx
<= TX_RING_SIZE
-1)) { 1378 clear_bit(0, (void*)&dev
->tbusy
); 1380 outb(PKT_BUF_SZ
>>8, ioaddr
+ TxFreeThreshold
); 1381 outw(DownUnstall
, ioaddr
+ EL3_CMD
); 1383 vp
->stats
.tx_dropped
++; 1385 /* Issue Tx Enable */ 1386 outw(TxEnable
, ioaddr
+ EL3_CMD
); 1387 dev
->trans_start
= jiffies
; 1389 /* Switch to register set 7 for normal use. */ 1394 * Handle uncommon interrupt sources. This is a separate routine to minimize 1398 vortex_error(struct device
*dev
,int status
) 1400 struct vortex_private
*vp
= (struct vortex_private
*)dev
->priv
; 1401 long ioaddr
= dev
->base_addr
; 1405 if(status
& TxComplete
) {/* Really "TxError" for us. */ 1406 unsigned char tx_status
=inb(ioaddr
+ TxStatus
); 1407 /* Presumably a tx-timeout. We must merely re-enable. */ 1409 || (tx_status
!=0x88&& vortex_debug
>0)) 1410 printk(KERN_DEBUG
"%s: Transmit error, Tx status register %2.2x.\n", 1411 dev
->name
, tx_status
); 1412 if(tx_status
&0x14) vp
->stats
.tx_fifo_errors
++; 1413 if(tx_status
&0x38) vp
->stats
.tx_aborted_errors
++; 1414 outb(0, ioaddr
+ TxStatus
); 1417 else/* Merely re-enable the transmitter. */ 1418 outw(TxEnable
, ioaddr
+ EL3_CMD
); 1420 if(status
& RxEarly
) {/* Rx early is unused. */ 1422 outw(AckIntr
| RxEarly
, ioaddr
+ EL3_CMD
); 1424 if(status
& StatsFull
) {/* Empty statistics. */ 1425 static int DoneDidThat
=0; 1427 printk(KERN_DEBUG
"%s: Updating stats.\n", dev
->name
); 1428 update_stats(ioaddr
, dev
); 1429 /* HACK: Disable statistics as an interrupt source. */ 1430 /* This occurs when we have the wrong media type! */ 1431 if(DoneDidThat
==0&& 1432 inw(ioaddr
+ EL3_STATUS
) & StatsFull
) { 1433 printk(KERN_WARNING
"%s: Updating statistics failed, disabling " 1434 "stats as an interrupt source.\n", dev
->name
); 1436 outw(SetIntrEnb
| (inw(ioaddr
+10) & ~StatsFull
), ioaddr
+ EL3_CMD
); 1441 if(status
& IntReq
)/* Restore all interrupt sources. */ 1442 outw(ioaddr
+ EL3_CMD
, vp
->status_enable
); 1443 if(status
& HostError
) { 1446 fifo_diag
=inw(ioaddr
+ Wn4_FIFODiag
); 1448 printk(KERN_ERR
"%s: Host error, FIFO diagnostic register %4.4x.\n", 1449 dev
->name
, fifo_diag
); 1450 /* Adapter failure requires Tx/Rx reset and reinit. */ 1451 if(vp
->full_bus_master_tx
) { 1452 outw(TotalReset
|0xff, ioaddr
+ EL3_CMD
); 1453 for(i
=2000; i
>=0; i
--) 1454 if( ! (inw(ioaddr
+ EL3_STATUS
) & CmdInProgress
)) 1456 /* Re-enable the receiver. */ 1457 outw(RxEnable
, ioaddr
+ EL3_CMD
); 1458 outw(TxEnable
, ioaddr
+ EL3_CMD
); 1459 }else if(fifo_diag
&0x0400) 1461 if(fifo_diag
&0x3000) { 1462 outw(RxReset
, ioaddr
+ EL3_CMD
); 1463 for(i
=2000; i
>=0; i
--) 1464 if( ! (inw(ioaddr
+ EL3_STATUS
) & CmdInProgress
)) 1466 /* Set the Rx filter to the current state. */ 1468 outw(RxEnable
, ioaddr
+ EL3_CMD
);/* Re-enable the receiver. */ 1469 outw(AckIntr
| HostError
, ioaddr
+ EL3_CMD
); 1474 outw(TxReset
, ioaddr
+ EL3_CMD
); 1475 for(j
=200; j
>=0; j
--) 1476 if( ! (inw(ioaddr
+ EL3_STATUS
) & CmdInProgress
)) 1478 outw(TxEnable
, ioaddr
+ EL3_CMD
); 1485 vortex_start_xmit(struct sk_buff
*skb
,struct device
*dev
) 1487 struct vortex_private
*vp
= (struct vortex_private
*)dev
->priv
; 1488 long ioaddr
= dev
->base_addr
; 1490 if(test_and_set_bit(0, (void*)&dev
->tbusy
) !=0) { 1491 if(jiffies
- dev
->trans_start
>= TX_TIMEOUT
) 1492 vortex_tx_timeout(dev
); 1496 /* Put out the doubleword header... */ 1497 outl(skb
->len
, ioaddr
+ TX_FIFO
); 1498 #ifdef VORTEX_BUS_MASTER 1499 if(vp
->bus_master
) { 1500 /* Set the bus-master controller to transfer the packet. */ 1501 outl(virt_to_bus(skb
->data
), ioaddr
+ Wn7_MasterAddr
); 1502 outw((skb
->len
+3) & ~3, ioaddr
+ Wn7_MasterLen
); 1504 outw(StartDMADown
, ioaddr
+ EL3_CMD
); 1505 /* dev->tbusy will be cleared at the DMADone interrupt. */ 1507 /* ... and the packet rounded to a doubleword. */ 1508 outsl(ioaddr
+ TX_FIFO
, skb
->data
, (skb
->len
+3) >>2); 1510 if(inw(ioaddr
+ TxFree
) >1536) { 1511 clear_bit(0, (void*)&dev
->tbusy
); 1513 /* Interrupt us when the FIFO has room for max-sized packet. */ 1514 outw(SetTxThreshold
+ (1536>>2), ioaddr
+ EL3_CMD
); 1517 /* ... and the packet rounded to a doubleword. */ 1518 outsl(ioaddr
+ TX_FIFO
, skb
->data
, (skb
->len
+3) >>2); 1520 if(inw(ioaddr
+ TxFree
) >1536) { 1521 clear_bit(0, (void*)&dev
->tbusy
); 1523 /* Interrupt us when the FIFO has room for max-sized packet. */ 1524 outw(SetTxThreshold
+ (1536>>2), ioaddr
+ EL3_CMD
); 1525 #endif/* bus master */ 1527 dev
->trans_start
= jiffies
; 1529 /* Clear the Tx status stack. */ 1534 while(--i
>0&& (tx_status
=inb(ioaddr
+ TxStatus
)) >0) { 1535 if(tx_status
&0x3C) {/* A Tx-disabling error occurred. */ 1537 printk(KERN_DEBUG
"%s: Tx error, status %2.2x.\n", 1538 dev
->name
, tx_status
); 1539 if(tx_status
&0x04) vp
->stats
.tx_fifo_errors
++; 1540 if(tx_status
&0x38) vp
->stats
.tx_aborted_errors
++; 1541 if(tx_status
&0x30) { 1543 outw(TxReset
, ioaddr
+ EL3_CMD
); 1544 for(j
=200; j
>=0; j
--) 1545 if( ! (inw(ioaddr
+ EL3_STATUS
) & CmdInProgress
)) 1548 outw(TxEnable
, ioaddr
+ EL3_CMD
); 1550 outb(0x00, ioaddr
+ TxStatus
);/* Pop the status stack. */ 1557 boomerang_start_xmit(struct sk_buff
*skb
,struct device
*dev
) 1559 struct vortex_private
*vp
= (struct vortex_private
*)dev
->priv
; 1560 long ioaddr
= dev
->base_addr
; 1562 if(test_and_set_bit(0, (void*)&dev
->tbusy
) !=0) { 1563 if(jiffies
- dev
->trans_start
>= TX_TIMEOUT
) 1564 vortex_tx_timeout(dev
); 1567 /* Calculate the next Tx descriptor entry. */ 1568 int entry
= vp
->cur_tx
% TX_RING_SIZE
; 1569 struct boom_tx_desc
*prev_entry
= 1570 &vp
->tx_ring
[(vp
->cur_tx
-1) % TX_RING_SIZE
]; 1571 unsigned long flags
; 1575 printk(KERN_DEBUG
"%s: Trying to send a packet, Tx index %d.\n", 1576 dev
->name
, vp
->cur_tx
); 1579 printk(KERN_WARNING
"%s: Tx Ring full, refusing to send buffer.\n", 1583 /* end change 06/25/97 M. Sievers */ 1584 vp
->tx_skbuff
[entry
] = skb
; 1585 vp
->tx_ring
[entry
].next
=0; 1586 vp
->tx_ring
[entry
].addr
=cpu_to_le32(virt_to_bus(skb
->data
)); 1587 vp
->tx_ring
[entry
].length
=cpu_to_le32(skb
->len
| LAST_FRAG
); 1588 vp
->tx_ring
[entry
].status
=cpu_to_le32(skb
->len
| TxIntrUploaded
); 1592 outw(DownStall
, ioaddr
+ EL3_CMD
); 1593 /* Wait for the stall to complete. */ 1594 for(i
=600; i
>=0; i
--) 1595 if( (inw(ioaddr
+ EL3_STATUS
) & CmdInProgress
) ==0) 1597 prev_entry
->next
=cpu_to_le32(virt_to_bus(&vp
->tx_ring
[entry
])); 1598 if(inl(ioaddr
+ DownListPtr
) ==0) { 1599 outl(virt_to_bus(&vp
->tx_ring
[entry
]), ioaddr
+ DownListPtr
); 1602 outw(DownUnstall
, ioaddr
+ EL3_CMD
); 1603 restore_flags(flags
); 1606 if(vp
->cur_tx
- vp
->dirty_tx
> TX_RING_SIZE
-1) 1608 else{/* Clear previous interrupt enable. */ 1609 prev_entry
->status
&=cpu_to_le32(~TxIntrUploaded
); 1610 clear_bit(0, (void*)&dev
->tbusy
); 1612 dev
->trans_start
= jiffies
; 1617 /* The interrupt handler does all of the Rx thread work and cleans up 1618 after the Tx thread. */ 1619 static void vortex_interrupt
IRQ(int irq
,void*dev_id
,struct pt_regs
*regs
) 1621 #ifdef SA_SHIRQ/* Use the now-standard shared IRQ implementation. */ 1622 struct device
*dev
= dev_id
; 1624 struct device
*dev
= (struct device
*)(irq2dev_map
[irq
]); 1626 struct vortex_private
*vp
; 1628 int latency
, status
; 1629 int work_done
= max_interrupt_work
; 1631 vp
= (struct vortex_private
*)dev
->priv
; 1632 if(test_and_set_bit(0, (void*)&vp
->in_interrupt
)) { 1633 printk(KERN_ERR
"%s: Re-entering the interrupt handler.\n", dev
->name
); 1638 ioaddr
= dev
->base_addr
; 1639 latency
=inb(ioaddr
+ Timer
); 1640 status
=inw(ioaddr
+ EL3_STATUS
); 1643 printk(KERN_DEBUG
"%s: interrupt, status %4.4x, latency %d ticks.\n", 1644 dev
->name
, status
, latency
); 1647 printk(KERN_DEBUG
"%s: In interrupt loop, status %4.4x.\n", 1649 if(status
& RxComplete
) 1651 if(status
& UpComplete
) { 1652 outw(AckIntr
| UpComplete
, ioaddr
+ EL3_CMD
); 1656 if(status
& TxAvailable
) { 1658 printk(KERN_DEBUG
" TX room bit was handled.\n"); 1659 /* There's room in the FIFO for a full-sized packet. */ 1660 outw(AckIntr
| TxAvailable
, ioaddr
+ EL3_CMD
); 1661 clear_bit(0, (void*)&dev
->tbusy
); 1665 if(status
& DownComplete
) { 1666 unsigned int dirty_tx
= vp
->dirty_tx
; 1668 while(vp
->cur_tx
- dirty_tx
>0) { 1669 int entry
= dirty_tx
% TX_RING_SIZE
; 1670 if(inl(ioaddr
+ DownListPtr
) == 1671 virt_to_bus(&vp
->tx_ring
[entry
])) 1672 break;/* It still hasn't been processed. */ 1673 if(vp
->tx_skbuff
[entry
]) { 1674 DEV_FREE_SKB(vp
->tx_skbuff
[entry
]); 1675 vp
->tx_skbuff
[entry
] =0; 1677 /* vp->stats.tx_packets++; Counted below. */ 1680 vp
->dirty_tx
= dirty_tx
; 1681 outw(AckIntr
| DownComplete
, ioaddr
+ EL3_CMD
); 1682 if(vp
->tx_full
&& (vp
->cur_tx
- dirty_tx
<= TX_RING_SIZE
-1)) { 1684 clear_bit(0, (void*)&dev
->tbusy
); 1688 #ifdef VORTEX_BUS_MASTER 1689 if(status
& DMADone
) { 1690 outw(0x1000, ioaddr
+ Wn7_MasterStatus
);/* Ack the event. */ 1691 clear_bit(0, (void*)&dev
->tbusy
); 1692 DEV_FREE_SKB(vp
->tx_skb
);/* Release the transfered buffer */ 1696 /* Check for all uncommon interrupts at once. */ 1697 if(status
& (HostError
| RxEarly
| StatsFull
| TxComplete
| IntReq
)) 1698 vortex_error(dev
, status
); 1700 if(--work_done
<0) { 1701 if((status
& (0x7fe- (UpComplete
| DownComplete
))) ==0) { 1702 /* Just ack these and return. */ 1703 outw(AckIntr
| UpComplete
| DownComplete
, ioaddr
+ EL3_CMD
); 1705 printk(KERN_WARNING
"%s: Too much work in interrupt, status " 1706 "%4.4x. Temporarily disabling functions (%4.4x).\n", 1707 dev
->name
, status
, SetStatusEnb
| ((~status
) &0x7FE)); 1708 /* Disable all pending interrupts. */ 1709 outw(SetStatusEnb
| ((~status
) &0x7FE), ioaddr
+ EL3_CMD
); 1710 outw(AckIntr
|0x7FF, ioaddr
+ EL3_CMD
); 1711 /* Set a timer to reenable interrupts. */ 1716 /* Acknowledge the IRQ. */ 1717 outw(AckIntr
| IntReq
| IntLatch
, ioaddr
+ EL3_CMD
); 1719 }while((status
=inw(ioaddr
+ EL3_STATUS
)) & (IntLatch
| RxComplete
)); 1722 printk(KERN_DEBUG
"%s: exiting interrupt, status %4.4x.\n", 1726 clear_bit(0, (void*)&vp
->in_interrupt
); 1731 vortex_rx(struct device
*dev
) 1733 struct vortex_private
*vp
= (struct vortex_private
*)dev
->priv
; 1734 long ioaddr
= dev
->base_addr
; 1739 printk(KERN_DEBUG
" In rx_packet(), status %4.4x, rx_status %4.4x.\n", 1740 inw(ioaddr
+EL3_STATUS
),inw(ioaddr
+RxStatus
)); 1741 while((rx_status
=inw(ioaddr
+ RxStatus
)) >0) { 1742 if(rx_status
&0x4000) {/* Error, update stats. */ 1743 unsigned char rx_error
=inb(ioaddr
+ RxErrors
); 1745 printk(KERN_DEBUG
" Rx error: status %2.2x.\n", rx_error
); 1746 vp
->stats
.rx_errors
++; 1747 if(rx_error
&0x01) vp
->stats
.rx_over_errors
++; 1748 if(rx_error
&0x02) vp
->stats
.rx_length_errors
++; 1749 if(rx_error
&0x04) vp
->stats
.rx_frame_errors
++; 1750 if(rx_error
&0x08) vp
->stats
.rx_crc_errors
++; 1751 if(rx_error
&0x10) vp
->stats
.rx_length_errors
++; 1753 /* The packet length: up to 4.5K!. */ 1754 int pkt_len
= rx_status
&0x1fff; 1755 struct sk_buff
*skb
; 1757 skb
=DEV_ALLOC_SKB(pkt_len
+5); 1759 printk(KERN_DEBUG
"Receiving packet size %d status %4.4x.\n", 1760 pkt_len
, rx_status
); 1763 #if LINUX_VERSION_CODE >= 0x10300 1764 skb_reserve(skb
,2);/* Align IP on 16 byte boundaries */ 1765 /* 'skb_put()' points to the start of sk_buff data area. */ 1766 insl(ioaddr
+ RX_FIFO
,skb_put(skb
, pkt_len
), 1768 outw(RxDiscard
, ioaddr
+ EL3_CMD
);/* Pop top Rx packet. */ 1769 skb
->protocol
=eth_type_trans(skb
, dev
); 1772 /* 'skb->data' points to the start of sk_buff data area. */ 1773 insl(ioaddr
+ RX_FIFO
, skb
->data
, (pkt_len
+3) >>2); 1774 outw(RxDiscard
, ioaddr
+ EL3_CMD
);/* Pop top Rx packet. */ 1775 #endif/* KERNEL_1_3_0 */ 1777 dev
->last_rx
= jiffies
; 1778 vp
->stats
.rx_packets
++; 1779 /* Wait a limited time to go to next packet. */ 1780 for(i
=200; i
>=0; i
--) 1781 if( ! (inw(ioaddr
+ EL3_STATUS
) & CmdInProgress
)) 1784 }else if(vortex_debug
) 1785 printk(KERN_NOTICE
"%s: No memory to allocate a sk_buff of " 1786 "size %d.\n", dev
->name
, pkt_len
); 1788 outw(RxDiscard
, ioaddr
+ EL3_CMD
); 1789 vp
->stats
.rx_dropped
++; 1790 /* Wait a limited time to skip this packet. */ 1791 for(i
=200; i
>=0; i
--) 1792 if( ! (inw(ioaddr
+ EL3_STATUS
) & CmdInProgress
)) 1800 boomerang_rx(struct device
*dev
) 1802 struct vortex_private
*vp
= (struct vortex_private
*)dev
->priv
; 1803 int entry
= vp
->cur_rx
% RX_RING_SIZE
; 1804 long ioaddr
= dev
->base_addr
; 1806 int rx_work_limit
= vp
->dirty_rx
+ RX_RING_SIZE
- vp
->cur_rx
; 1809 printk(KERN_DEBUG
" In boomerang_rx(), status %4.4x, rx_status " 1811 inw(ioaddr
+EL3_STATUS
),inw(ioaddr
+RxStatus
)); 1812 while((rx_status
=le32_to_cpu(vp
->rx_ring
[entry
].status
)) & RxDComplete
) { 1813 if(rx_status
& RxDError
) {/* Error, update stats. */ 1814 unsigned char rx_error
= rx_status
>>16; 1816 printk(KERN_DEBUG
" Rx error: status %2.2x.\n", rx_error
); 1817 vp
->stats
.rx_errors
++; 1818 if(rx_error
&0x01) vp
->stats
.rx_over_errors
++; 1819 if(rx_error
&0x02) vp
->stats
.rx_length_errors
++; 1820 if(rx_error
&0x04) vp
->stats
.rx_frame_errors
++; 1821 if(rx_error
&0x08) vp
->stats
.rx_crc_errors
++; 1822 if(rx_error
&0x10) vp
->stats
.rx_length_errors
++; 1824 /* The packet length: up to 4.5K!. */ 1825 int pkt_len
= rx_status
&0x1fff; 1826 struct sk_buff
*skb
; 1829 printk(KERN_DEBUG
"Receiving packet size %d status %4.4x.\n", 1830 pkt_len
, rx_status
); 1832 /* Check if the packet is long enough to just accept without 1833 copying to a properly sized skbuff. */ 1834 if(pkt_len
< rx_copybreak
1835 && (skb
=DEV_ALLOC_SKB(pkt_len
+2)) !=0) { 1837 #if LINUX_VERSION_CODE >= 0x10300 1838 skb_reserve(skb
,2);/* Align IP on 16 byte boundaries */ 1839 /* 'skb_put()' points to the start of sk_buff data area. */ 1840 memcpy(skb_put(skb
, pkt_len
), 1841 bus_to_virt(le32_to_cpu(vp
->rx_ring
[entry
].addr
)), 1844 memcpy(skb
->data
,bus_to_virt(vp
->rx_ring
[entry
].addr
), 1851 /* Pass up the skbuff already on the Rx ring. */ 1852 skb
= vp
->rx_skbuff
[entry
]; 1853 vp
->rx_skbuff
[entry
] = NULL
; 1854 #if LINUX_VERSION_CODE >= 0x10300 1855 temp
=skb_put(skb
, pkt_len
); 1859 /* Remove this checking code for final release. */ 1860 if(bus_to_virt(le32_to_cpu(vp
->rx_ring
[entry
].addr
)) != temp
) 1861 printk(KERN_ERR
"%s: Warning -- the skbuff addresses do not match" 1862 " in boomerang_rx: %p vs. %p.\n", dev
->name
, 1863 bus_to_virt(le32_to_cpu(vp
->rx_ring
[entry
].addr
)), 1867 #if LINUX_VERSION_CODE > 0x10300 1868 skb
->protocol
=eth_type_trans(skb
, dev
); 1869 {/* Use hardware checksum info. */ 1870 int csum_bits
= rx_status
&0xee000000; 1872 (csum_bits
== (IPChksumValid
| TCPChksumValid
) || 1873 csum_bits
== (IPChksumValid
| UDPChksumValid
))) { 1874 skb
->ip_summed
= CHECKSUM_UNNECESSARY
; 1882 dev
->last_rx
= jiffies
; 1883 vp
->stats
.rx_packets
++; 1885 entry
= (++vp
->cur_rx
) % RX_RING_SIZE
; 1886 if(--rx_work_limit
<0) 1889 /* Refill the Rx ring buffers. */ 1890 for(; vp
->dirty_rx
< vp
->cur_rx
; vp
->dirty_rx
++) { 1891 struct sk_buff
*skb
; 1892 entry
= vp
->dirty_rx
% RX_RING_SIZE
; 1893 if(vp
->rx_skbuff
[entry
] == NULL
) { 1894 skb
=DEV_ALLOC_SKB(PKT_BUF_SZ
); 1896 break;/* Bad news! */ 1897 skb
->dev
= dev
;/* Mark as being used by this device. */ 1898 #if LINUX_VERSION_CODE > 0x10300 1899 skb_reserve(skb
,2);/* Align IP on 16 byte boundaries */ 1900 vp
->rx_ring
[entry
].addr
=cpu_to_le32(virt_to_bus(skb
->tail
)); 1902 vp
->rx_ring
[entry
].addr
=virt_to_bus(skb
->data
); 1904 vp
->rx_skbuff
[entry
] = skb
; 1906 vp
->rx_ring
[entry
].status
=0;/* Clear complete bit. */ 1907 outw(UpUnstall
, ioaddr
+ EL3_CMD
); 1913 vortex_close(struct device
*dev
) 1915 struct vortex_private
*vp
= (struct vortex_private
*)dev
->priv
; 1916 long ioaddr
= dev
->base_addr
; 1922 if(vortex_debug
>1) { 1923 printk(KERN_DEBUG
"%s: vortex_close() status %4.4x, Tx status %2.2x.\n", 1924 dev
->name
,inw(ioaddr
+ EL3_STATUS
),inb(ioaddr
+ TxStatus
)); 1925 printk(KERN_DEBUG
"%s: vortex close stats: rx_nocopy %d rx_copy %d" 1926 " tx_queued %d Rx pre-checksummed %d.\n", 1927 dev
->name
, rx_nocopy
, rx_copy
, queued_packet
, rx_csumhits
); 1930 del_timer(&vp
->timer
); 1932 /* Turn off statistics ASAP. We update vp->stats below. */ 1933 outw(StatsDisable
, ioaddr
+ EL3_CMD
); 1935 /* Disable the receiver and transmitter. */ 1936 outw(RxDisable
, ioaddr
+ EL3_CMD
); 1937 outw(TxDisable
, ioaddr
+ EL3_CMD
); 1939 if(dev
->if_port
== XCVR_10base2
) 1940 /* Turn off thinnet power. Green! */ 1941 outw(StopCoax
, ioaddr
+ EL3_CMD
); 1944 free_irq(dev
->irq
, dev
); 1947 irq2dev_map
[dev
->irq
] =0; 1950 outw(SetIntrEnb
|0x0000, ioaddr
+ EL3_CMD
); 1952 update_stats(ioaddr
, dev
); 1953 if(vp
->full_bus_master_rx
) {/* Free Boomerang bus master Rx buffers. */ 1954 outl(0, ioaddr
+ UpListPtr
); 1955 for(i
=0; i
< RX_RING_SIZE
; i
++) 1956 if(vp
->rx_skbuff
[i
]) { 1957 #if LINUX_VERSION_CODE < 0x20100 1958 vp
->rx_skbuff
[i
]->free
=1; 1960 DEV_FREE_SKB(vp
->rx_skbuff
[i
]); 1961 vp
->rx_skbuff
[i
] =0; 1964 if(vp
->full_bus_master_tx
) {/* Free Boomerang bus master Tx buffers. */ 1965 outl(0, ioaddr
+ DownListPtr
); 1966 for(i
=0; i
< TX_RING_SIZE
; i
++) 1967 if(vp
->tx_skbuff
[i
]) { 1968 DEV_FREE_SKB(vp
->tx_skbuff
[i
]); 1969 vp
->tx_skbuff
[i
] =0; 1978 static struct net_device_stats
*vortex_get_stats(struct device
*dev
) 1980 struct vortex_private
*vp
= (struct vortex_private
*)dev
->priv
; 1981 unsigned long flags
; 1986 update_stats(dev
->base_addr
, dev
); 1987 restore_flags(flags
); 1992 /* Update statistics. 1993 Unlike with the EL3 we need not worry about interrupts changing 1994 the window setting from underneath us, but we must still guard 1995 against a race condition with a StatsUpdate interrupt updating the 1996 table. This is done by checking that the ASM (!) code generated uses 1997 atomic updates with '+='. 1999 static voidupdate_stats(long ioaddr
,struct device
*dev
) 2001 struct vortex_private
*vp
= (struct vortex_private
*)dev
->priv
; 2003 /* Unlike the 3c5x9 we need not turn off stats updates while reading. */ 2004 /* Switch to the stats window, and read everything. */ 2006 vp
->stats
.tx_carrier_errors
+=inb(ioaddr
+0); 2007 vp
->stats
.tx_heartbeat_errors
+=inb(ioaddr
+1); 2008 /* Multiple collisions. */inb(ioaddr
+2); 2009 vp
->stats
.collisions
+=inb(ioaddr
+3); 2010 vp
->stats
.tx_window_errors
+=inb(ioaddr
+4); 2011 vp
->stats
.rx_fifo_errors
+=inb(ioaddr
+5); 2012 vp
->stats
.tx_packets
+=inb(ioaddr
+6); 2013 vp
->stats
.tx_packets
+= (inb(ioaddr
+9)&0x30) <<4; 2014 /* Rx packets */inb(ioaddr
+7);/* Must read to clear */ 2015 /* Tx deferrals */inb(ioaddr
+8); 2016 /* Don't bother with register 9, an extension of registers 6&7. 2017 If we do use the 6&7 values the atomic update assumption above 2019 inw(ioaddr
+10);/* Total Rx and Tx octets. */ 2021 /* New: On the Vortex we must also clear the BadSSD counter. */ 2025 /* We change back to window 7 (not 1) with the Vortex. */ 2030 #ifdef HAVE_PRIVATE_IOCTL 2031 static intvortex_ioctl(struct device
*dev
,struct ifreq
*rq
,int cmd
) 2033 struct vortex_private
*vp
= (struct vortex_private
*)dev
->priv
; 2034 long ioaddr
= dev
->base_addr
; 2035 u16
*data
= (u16
*)&rq
->ifr_data
; 2036 int phy
= vp
->phys
[0] &0x1f; 2039 printk(KERN_DEBUG
"%s: In ioct(%-.6s, %#4.4x) %4.4x %4.4x %4.4x %4.4x.\n", 2040 dev
->name
, rq
->ifr_ifrn
.ifrn_name
, cmd
, 2041 data
[0], data
[1], data
[2], data
[3]); 2044 case SIOCDEVPRIVATE
:/* Get the address of the PHY in use. */ 2046 case SIOCDEVPRIVATE
+1:/* Read the specified MII register. */ 2048 data
[3] =mdio_read(ioaddr
, data
[0] &0x1f, data
[1] &0x1f); 2050 case SIOCDEVPRIVATE
+2:/* Write the specified MII register */ 2053 mdio_write(ioaddr
, data
[0] &0x1f, data
[1] &0x1f, data
[2]); 2059 #endif/* HAVE_PRIVATE_IOCTL */ 2061 /* This new version of set_rx_mode() supports v1.4 kernels. 2062 The Vortex chip has no documented multicast filter, so the only 2063 multicast setting is to receive all multicast frames. At least 2064 the chip has a very clean way to set the mode, unlike many others. */ 2066 set_rx_mode(struct device
*dev
) 2068 long ioaddr
= dev
->base_addr
; 2071 if(dev
->flags
& IFF_PROMISC
) { 2073 printk(KERN_NOTICE
"%s: Setting promiscuous mode.\n", dev
->name
); 2074 new_mode
= SetRxFilter
|RxStation
|RxMulticast
|RxBroadcast
|RxProm
; 2075 }else if((dev
->mc_list
) || (dev
->flags
& IFF_ALLMULTI
)) { 2076 new_mode
= SetRxFilter
|RxStation
|RxMulticast
|RxBroadcast
; 2078 new_mode
= SetRxFilter
| RxStation
| RxBroadcast
; 2080 outw(new_mode
, ioaddr
+ EL3_CMD
); 2082 #ifndef NEW_MULTICAST 2083 /* The old interface to set the Rx mode. */ 2085 set_multicast_list(struct device
*dev
,int num_addrs
,void*addrs
) 2092 /* MII transceiver control section. 2093 Read and write the MII registers using software-generated serial 2094 MDIO protocol. See the MII specifications or DP83840A data sheet 2097 /* The maximum data clock rate is 2.5 Mhz. The minimum timing is usually 2098 met by back-to-back PCI I/O cycles, but we insert a delay to avoid 2099 "overclocking" issues. */ 2100 #define mdio_delay() udelay(1) 2102 #define MDIO_SHIFT_CLK 0x01 2103 #define MDIO_DIR_WRITE 0x04 2104 #define MDIO_DATA_WRITE0 (0x00 | MDIO_DIR_WRITE) 2105 #define MDIO_DATA_WRITE1 (0x02 | MDIO_DIR_WRITE) 2106 #define MDIO_DATA_READ 0x02 2107 #define MDIO_ENB_IN 0x00 2109 /* Generate the preamble required for initial synchronization and 2110 a few older transceivers. */ 2111 static voidmdio_sync(long ioaddr
,int bits
) 2113 long mdio_addr
= ioaddr
+ Wn4_PhysicalMgmt
; 2115 /* Establish sync by sending at least 32 logic ones. */ 2116 while(-- bits
>=0) { 2117 outw(MDIO_DATA_WRITE1
, mdio_addr
); 2119 outw(MDIO_DATA_WRITE1
| MDIO_SHIFT_CLK
, mdio_addr
); 2124 static intmdio_read(long ioaddr
,int phy_id
,int location
) 2127 int read_cmd
= (0xf6<<10) | (phy_id
<<5) | location
; 2128 unsigned int retval
=0; 2129 long mdio_addr
= ioaddr
+ Wn4_PhysicalMgmt
; 2131 if(mii_preamble_required
) 2132 mdio_sync(ioaddr
,32); 2134 /* Shift the read command bits out. */ 2135 for(i
=14; i
>=0; i
--) { 2136 int dataval
= (read_cmd
&(1<<i
)) ? MDIO_DATA_WRITE1
: MDIO_DATA_WRITE0
; 2137 outw(dataval
, mdio_addr
); 2139 outw(dataval
| MDIO_SHIFT_CLK
, mdio_addr
); 2142 /* Read the two transition, 16 data, and wire-idle bits. */ 2143 for(i
=19; i
>0; i
--) { 2144 outw(MDIO_ENB_IN
, mdio_addr
); 2146 retval
= (retval
<<1) | ((inw(mdio_addr
) & MDIO_DATA_READ
) ?1:0); 2147 outw(MDIO_ENB_IN
| MDIO_SHIFT_CLK
, mdio_addr
); 2150 return retval
>>1&0xffff; 2153 static voidmdio_write(long ioaddr
,int phy_id
,int location
,int value
) 2155 int write_cmd
=0x50020000| (phy_id
<<23) | (location
<<18) | value
; 2156 long mdio_addr
= ioaddr
+ Wn4_PhysicalMgmt
; 2159 if(mii_preamble_required
) 2160 mdio_sync(ioaddr
,32); 2162 /* Shift the command bits out. */ 2163 for(i
=31; i
>=0; i
--) { 2164 int dataval
= (write_cmd
&(1<<i
)) ? MDIO_DATA_WRITE1
: MDIO_DATA_WRITE0
; 2165 outw(dataval
, mdio_addr
); 2167 outw(dataval
| MDIO_SHIFT_CLK
, mdio_addr
); 2170 /* Leave the interface idle. */ 2171 for(i
=1; i
>=0; i
--) { 2172 outw(MDIO_ENB_IN
, mdio_addr
); 2174 outw(MDIO_ENB_IN
| MDIO_SHIFT_CLK
, mdio_addr
); 2184 cleanup_module(void) 2186 struct device
*next_dev
; 2189 unregister_driver(&vortex_ops
); 2192 /* No need to check MOD_IN_USE, as sys_delete_module() checks. */ 2193 while(root_vortex_dev
) { 2194 next_dev
= ((struct vortex_private
*)root_vortex_dev
->priv
)->next_module
; 2195 unregister_netdev(root_vortex_dev
); 2196 outw(TotalReset
, root_vortex_dev
->base_addr
+ EL3_CMD
); 2197 release_region(root_vortex_dev
->base_addr
, VORTEX_TOTAL_SIZE
); 2198 kfree(root_vortex_dev
); 2199 root_vortex_dev
= next_dev
; 2207 * compile-command: "gcc -DMODULE -D__KERNEL__ -Wall -Wstrict-prototypes -O6 -c 3c59x.c `[ -f /usr/include/linux/modversions.h ] && echo -DMODVERSIONS`" 2208 * SMP-compile-command: "gcc -D__SMP__ -DMODULE -D__KERNEL__ -Wall -Wstrict-prototypes -O6 -c 3c59x.c" 2209 * cardbus-compile-command: "gcc -DCARDBUS -DMODULE -D__KERNEL__ -Wall -Wstrict-prototypes -O6 -c 3c59x.c -o 3c575_cb.o -I/usr/src/pcmcia-cs-3.0.5/include/"