Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* de2104x.c: A Linux PCI Ethernet driver for Intel/Digital 21040/1 chips. */ |
| 2 | /* |
| 3 | Copyright 2001,2003 Jeff Garzik <jgarzik@pobox.com> |
| 4 | |
| 5 | Copyright 1994, 1995 Digital Equipment Corporation. [de4x5.c] |
| 6 | Written/copyright 1994-2001 by Donald Becker. [tulip.c] |
| 7 | |
| 8 | This software may be used and distributed according to the terms of |
| 9 | the GNU General Public License (GPL), incorporated herein by reference. |
| 10 | Drivers based on or derived from this code fall under the GPL and must |
| 11 | retain the authorship, copyright and license notice. This file is not |
| 12 | a complete program and may only be used when the entire operating |
| 13 | system is licensed under the GPL. |
| 14 | |
| 15 | See the file COPYING in this distribution for more information. |
| 16 | |
| 17 | TODO, in rough priority order: |
| 18 | * Support forcing media type with a module parameter, |
| 19 | like dl2k.c/sundance.c |
| 20 | * Constants (module parms?) for Rx work limit |
| 21 | * Complete reset on PciErr |
| 22 | * Jumbo frames / dev->change_mtu |
| 23 | * Adjust Rx FIFO threshold and Max Rx DMA burst on Rx FIFO error |
| 24 | * Adjust Tx FIFO threshold and Max Tx DMA burst on Tx FIFO error |
| 25 | * Implement Tx software interrupt mitigation via |
| 26 | Tx descriptor bit |
| 27 | |
| 28 | */ |
| 29 | |
| 30 | #define DRV_NAME "de2104x" |
| 31 | #define DRV_VERSION "0.7" |
| 32 | #define DRV_RELDATE "Mar 17, 2004" |
| 33 | |
| 34 | #include <linux/config.h> |
| 35 | #include <linux/module.h> |
| 36 | #include <linux/kernel.h> |
| 37 | #include <linux/netdevice.h> |
| 38 | #include <linux/etherdevice.h> |
| 39 | #include <linux/init.h> |
| 40 | #include <linux/pci.h> |
| 41 | #include <linux/delay.h> |
| 42 | #include <linux/ethtool.h> |
| 43 | #include <linux/compiler.h> |
| 44 | #include <linux/rtnetlink.h> |
| 45 | #include <linux/crc32.h> |
| 46 | |
| 47 | #include <asm/io.h> |
| 48 | #include <asm/irq.h> |
| 49 | #include <asm/uaccess.h> |
| 50 | #include <asm/unaligned.h> |
| 51 | |
| 52 | /* These identify the driver base version and may not be removed. */ |
| 53 | static char version[] = |
| 54 | KERN_INFO DRV_NAME " PCI Ethernet driver v" DRV_VERSION " (" DRV_RELDATE ")\n"; |
| 55 | |
| 56 | MODULE_AUTHOR("Jeff Garzik <jgarzik@pobox.com>"); |
| 57 | MODULE_DESCRIPTION("Intel/Digital 21040/1 series PCI Ethernet driver"); |
| 58 | MODULE_LICENSE("GPL"); |
| 59 | MODULE_VERSION(DRV_VERSION); |
| 60 | |
| 61 | static int debug = -1; |
| 62 | module_param (debug, int, 0); |
| 63 | MODULE_PARM_DESC (debug, "de2104x bitmapped message enable number"); |
| 64 | |
| 65 | /* Set the copy breakpoint for the copy-only-tiny-buffer Rx structure. */ |
| 66 | #if defined(__alpha__) || defined(__arm__) || defined(__hppa__) \ |
| 67 | || defined(__sparc_) || defined(__ia64__) \ |
| 68 | || defined(__sh__) || defined(__mips__) |
| 69 | static int rx_copybreak = 1518; |
| 70 | #else |
| 71 | static int rx_copybreak = 100; |
| 72 | #endif |
| 73 | module_param (rx_copybreak, int, 0); |
| 74 | MODULE_PARM_DESC (rx_copybreak, "de2104x Breakpoint at which Rx packets are copied"); |
| 75 | |
| 76 | #define PFX DRV_NAME ": " |
| 77 | |
| 78 | #define DE_DEF_MSG_ENABLE (NETIF_MSG_DRV | \ |
| 79 | NETIF_MSG_PROBE | \ |
| 80 | NETIF_MSG_LINK | \ |
| 81 | NETIF_MSG_IFDOWN | \ |
| 82 | NETIF_MSG_IFUP | \ |
| 83 | NETIF_MSG_RX_ERR | \ |
| 84 | NETIF_MSG_TX_ERR) |
| 85 | |
| 86 | #define DE_RX_RING_SIZE 64 |
| 87 | #define DE_TX_RING_SIZE 64 |
| 88 | #define DE_RING_BYTES \ |
| 89 | ((sizeof(struct de_desc) * DE_RX_RING_SIZE) + \ |
| 90 | (sizeof(struct de_desc) * DE_TX_RING_SIZE)) |
| 91 | #define NEXT_TX(N) (((N) + 1) & (DE_TX_RING_SIZE - 1)) |
| 92 | #define NEXT_RX(N) (((N) + 1) & (DE_RX_RING_SIZE - 1)) |
| 93 | #define TX_BUFFS_AVAIL(CP) \ |
| 94 | (((CP)->tx_tail <= (CP)->tx_head) ? \ |
| 95 | (CP)->tx_tail + (DE_TX_RING_SIZE - 1) - (CP)->tx_head : \ |
| 96 | (CP)->tx_tail - (CP)->tx_head - 1) |
| 97 | |
| 98 | #define PKT_BUF_SZ 1536 /* Size of each temporary Rx buffer.*/ |
| 99 | #define RX_OFFSET 2 |
| 100 | |
| 101 | #define DE_SETUP_SKB ((struct sk_buff *) 1) |
| 102 | #define DE_DUMMY_SKB ((struct sk_buff *) 2) |
| 103 | #define DE_SETUP_FRAME_WORDS 96 |
| 104 | #define DE_EEPROM_WORDS 256 |
| 105 | #define DE_EEPROM_SIZE (DE_EEPROM_WORDS * sizeof(u16)) |
| 106 | #define DE_MAX_MEDIA 5 |
| 107 | |
| 108 | #define DE_MEDIA_TP_AUTO 0 |
| 109 | #define DE_MEDIA_BNC 1 |
| 110 | #define DE_MEDIA_AUI 2 |
| 111 | #define DE_MEDIA_TP 3 |
| 112 | #define DE_MEDIA_TP_FD 4 |
| 113 | #define DE_MEDIA_INVALID DE_MAX_MEDIA |
| 114 | #define DE_MEDIA_FIRST 0 |
| 115 | #define DE_MEDIA_LAST (DE_MAX_MEDIA - 1) |
| 116 | #define DE_AUI_BNC (SUPPORTED_AUI | SUPPORTED_BNC) |
| 117 | |
| 118 | #define DE_TIMER_LINK (60 * HZ) |
| 119 | #define DE_TIMER_NO_LINK (5 * HZ) |
| 120 | |
| 121 | #define DE_NUM_REGS 16 |
| 122 | #define DE_REGS_SIZE (DE_NUM_REGS * sizeof(u32)) |
| 123 | #define DE_REGS_VER 1 |
| 124 | |
| 125 | /* Time in jiffies before concluding the transmitter is hung. */ |
| 126 | #define TX_TIMEOUT (6*HZ) |
| 127 | |
| 128 | #define DE_UNALIGNED_16(a) (u16)(get_unaligned((u16 *)(a))) |
| 129 | |
| 130 | /* This is a mysterious value that can be written to CSR11 in the 21040 (only) |
| 131 | to support a pre-NWay full-duplex signaling mechanism using short frames. |
| 132 | No one knows what it should be, but if left at its default value some |
| 133 | 10base2(!) packets trigger a full-duplex-request interrupt. */ |
| 134 | #define FULL_DUPLEX_MAGIC 0x6969 |
| 135 | |
| 136 | enum { |
| 137 | /* NIC registers */ |
| 138 | BusMode = 0x00, |
| 139 | TxPoll = 0x08, |
| 140 | RxPoll = 0x10, |
| 141 | RxRingAddr = 0x18, |
| 142 | TxRingAddr = 0x20, |
| 143 | MacStatus = 0x28, |
| 144 | MacMode = 0x30, |
| 145 | IntrMask = 0x38, |
| 146 | RxMissed = 0x40, |
| 147 | ROMCmd = 0x48, |
| 148 | CSR11 = 0x58, |
| 149 | SIAStatus = 0x60, |
| 150 | CSR13 = 0x68, |
| 151 | CSR14 = 0x70, |
| 152 | CSR15 = 0x78, |
| 153 | PCIPM = 0x40, |
| 154 | |
| 155 | /* BusMode bits */ |
| 156 | CmdReset = (1 << 0), |
| 157 | CacheAlign16 = 0x00008000, |
| 158 | BurstLen4 = 0x00000400, |
| 159 | |
| 160 | /* Rx/TxPoll bits */ |
| 161 | NormalTxPoll = (1 << 0), |
| 162 | NormalRxPoll = (1 << 0), |
| 163 | |
| 164 | /* Tx/Rx descriptor status bits */ |
| 165 | DescOwn = (1 << 31), |
| 166 | RxError = (1 << 15), |
| 167 | RxErrLong = (1 << 7), |
| 168 | RxErrCRC = (1 << 1), |
| 169 | RxErrFIFO = (1 << 0), |
| 170 | RxErrRunt = (1 << 11), |
| 171 | RxErrFrame = (1 << 14), |
| 172 | RingEnd = (1 << 25), |
| 173 | FirstFrag = (1 << 29), |
| 174 | LastFrag = (1 << 30), |
| 175 | TxError = (1 << 15), |
| 176 | TxFIFOUnder = (1 << 1), |
| 177 | TxLinkFail = (1 << 2) | (1 << 10) | (1 << 11), |
| 178 | TxMaxCol = (1 << 8), |
| 179 | TxOWC = (1 << 9), |
| 180 | TxJabber = (1 << 14), |
| 181 | SetupFrame = (1 << 27), |
| 182 | TxSwInt = (1 << 31), |
| 183 | |
| 184 | /* MacStatus bits */ |
| 185 | IntrOK = (1 << 16), |
| 186 | IntrErr = (1 << 15), |
| 187 | RxIntr = (1 << 6), |
| 188 | RxEmpty = (1 << 7), |
| 189 | TxIntr = (1 << 0), |
| 190 | TxEmpty = (1 << 2), |
| 191 | PciErr = (1 << 13), |
| 192 | TxState = (1 << 22) | (1 << 21) | (1 << 20), |
| 193 | RxState = (1 << 19) | (1 << 18) | (1 << 17), |
| 194 | LinkFail = (1 << 12), |
| 195 | LinkPass = (1 << 4), |
| 196 | RxStopped = (1 << 8), |
| 197 | TxStopped = (1 << 1), |
| 198 | |
| 199 | /* MacMode bits */ |
| 200 | TxEnable = (1 << 13), |
| 201 | RxEnable = (1 << 1), |
| 202 | RxTx = TxEnable | RxEnable, |
| 203 | FullDuplex = (1 << 9), |
| 204 | AcceptAllMulticast = (1 << 7), |
| 205 | AcceptAllPhys = (1 << 6), |
| 206 | BOCnt = (1 << 5), |
| 207 | MacModeClear = (1<<12) | (1<<11) | (1<<10) | (1<<8) | (1<<3) | |
| 208 | RxTx | BOCnt | AcceptAllPhys | AcceptAllMulticast, |
| 209 | |
| 210 | /* ROMCmd bits */ |
| 211 | EE_SHIFT_CLK = 0x02, /* EEPROM shift clock. */ |
| 212 | EE_CS = 0x01, /* EEPROM chip select. */ |
| 213 | EE_DATA_WRITE = 0x04, /* Data from the Tulip to EEPROM. */ |
| 214 | EE_WRITE_0 = 0x01, |
| 215 | EE_WRITE_1 = 0x05, |
| 216 | EE_DATA_READ = 0x08, /* Data from the EEPROM chip. */ |
| 217 | EE_ENB = (0x4800 | EE_CS), |
| 218 | |
| 219 | /* The EEPROM commands include the alway-set leading bit. */ |
| 220 | EE_READ_CMD = 6, |
| 221 | |
| 222 | /* RxMissed bits */ |
| 223 | RxMissedOver = (1 << 16), |
| 224 | RxMissedMask = 0xffff, |
| 225 | |
| 226 | /* SROM-related bits */ |
| 227 | SROMC0InfoLeaf = 27, |
| 228 | MediaBlockMask = 0x3f, |
| 229 | MediaCustomCSRs = (1 << 6), |
| 230 | |
| 231 | /* PCIPM bits */ |
| 232 | PM_Sleep = (1 << 31), |
| 233 | PM_Snooze = (1 << 30), |
| 234 | PM_Mask = PM_Sleep | PM_Snooze, |
| 235 | |
| 236 | /* SIAStatus bits */ |
| 237 | NWayState = (1 << 14) | (1 << 13) | (1 << 12), |
| 238 | NWayRestart = (1 << 12), |
| 239 | NonselPortActive = (1 << 9), |
| 240 | LinkFailStatus = (1 << 2), |
| 241 | NetCxnErr = (1 << 1), |
| 242 | }; |
| 243 | |
| 244 | static const u32 de_intr_mask = |
| 245 | IntrOK | IntrErr | RxIntr | RxEmpty | TxIntr | TxEmpty | |
| 246 | LinkPass | LinkFail | PciErr; |
| 247 | |
| 248 | /* |
| 249 | * Set the programmable burst length to 4 longwords for all: |
| 250 | * DMA errors result without these values. Cache align 16 long. |
| 251 | */ |
| 252 | static const u32 de_bus_mode = CacheAlign16 | BurstLen4; |
| 253 | |
| 254 | struct de_srom_media_block { |
| 255 | u8 opts; |
| 256 | u16 csr13; |
| 257 | u16 csr14; |
| 258 | u16 csr15; |
| 259 | } __attribute__((packed)); |
| 260 | |
| 261 | struct de_srom_info_leaf { |
| 262 | u16 default_media; |
| 263 | u8 n_blocks; |
| 264 | u8 unused; |
| 265 | } __attribute__((packed)); |
| 266 | |
| 267 | struct de_desc { |
| 268 | u32 opts1; |
| 269 | u32 opts2; |
| 270 | u32 addr1; |
| 271 | u32 addr2; |
| 272 | }; |
| 273 | |
| 274 | struct media_info { |
| 275 | u16 type; /* DE_MEDIA_xxx */ |
| 276 | u16 csr13; |
| 277 | u16 csr14; |
| 278 | u16 csr15; |
| 279 | }; |
| 280 | |
| 281 | struct ring_info { |
| 282 | struct sk_buff *skb; |
| 283 | dma_addr_t mapping; |
| 284 | }; |
| 285 | |
| 286 | struct de_private { |
| 287 | unsigned tx_head; |
| 288 | unsigned tx_tail; |
| 289 | unsigned rx_tail; |
| 290 | |
| 291 | void __iomem *regs; |
| 292 | struct net_device *dev; |
| 293 | spinlock_t lock; |
| 294 | |
| 295 | struct de_desc *rx_ring; |
| 296 | struct de_desc *tx_ring; |
| 297 | struct ring_info tx_skb[DE_TX_RING_SIZE]; |
| 298 | struct ring_info rx_skb[DE_RX_RING_SIZE]; |
| 299 | unsigned rx_buf_sz; |
| 300 | dma_addr_t ring_dma; |
| 301 | |
| 302 | u32 msg_enable; |
| 303 | |
| 304 | struct net_device_stats net_stats; |
| 305 | |
| 306 | struct pci_dev *pdev; |
| 307 | |
| 308 | u16 setup_frame[DE_SETUP_FRAME_WORDS]; |
| 309 | |
| 310 | u32 media_type; |
| 311 | u32 media_supported; |
| 312 | u32 media_advertise; |
| 313 | struct media_info media[DE_MAX_MEDIA]; |
| 314 | struct timer_list media_timer; |
| 315 | |
| 316 | u8 *ee_data; |
| 317 | unsigned board_idx; |
| 318 | unsigned de21040 : 1; |
| 319 | unsigned media_lock : 1; |
| 320 | }; |
| 321 | |
| 322 | |
| 323 | static void de_set_rx_mode (struct net_device *dev); |
| 324 | static void de_tx (struct de_private *de); |
| 325 | static void de_clean_rings (struct de_private *de); |
| 326 | static void de_media_interrupt (struct de_private *de, u32 status); |
| 327 | static void de21040_media_timer (unsigned long data); |
| 328 | static void de21041_media_timer (unsigned long data); |
| 329 | static unsigned int de_ok_to_advertise (struct de_private *de, u32 new_media); |
| 330 | |
| 331 | |
| 332 | static struct pci_device_id de_pci_tbl[] = { |
| 333 | { PCI_VENDOR_ID_DEC, PCI_DEVICE_ID_DEC_TULIP, |
| 334 | PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0 }, |
| 335 | { PCI_VENDOR_ID_DEC, PCI_DEVICE_ID_DEC_TULIP_PLUS, |
| 336 | PCI_ANY_ID, PCI_ANY_ID, 0, 0, 1 }, |
| 337 | { }, |
| 338 | }; |
| 339 | MODULE_DEVICE_TABLE(pci, de_pci_tbl); |
| 340 | |
| 341 | static const char * const media_name[DE_MAX_MEDIA] = { |
| 342 | "10baseT auto", |
| 343 | "BNC", |
| 344 | "AUI", |
| 345 | "10baseT-HD", |
| 346 | "10baseT-FD" |
| 347 | }; |
| 348 | |
| 349 | /* 21040 transceiver register settings: |
| 350 | * TP AUTO(unused), BNC(unused), AUI, TP, TP FD*/ |
| 351 | static u16 t21040_csr13[] = { 0, 0, 0x8F09, 0x8F01, 0x8F01, }; |
| 352 | static u16 t21040_csr14[] = { 0, 0, 0x0705, 0xFFFF, 0xFFFD, }; |
| 353 | static u16 t21040_csr15[] = { 0, 0, 0x0006, 0x0000, 0x0000, }; |
| 354 | |
| 355 | /* 21041 transceiver register settings: TP AUTO, BNC, AUI, TP, TP FD*/ |
| 356 | static u16 t21041_csr13[] = { 0xEF01, 0xEF09, 0xEF09, 0xEF01, 0xEF09, }; |
| 357 | static u16 t21041_csr14[] = { 0xFFFF, 0xF7FD, 0xF7FD, 0x6F3F, 0x6F3D, }; |
| 358 | static u16 t21041_csr15[] = { 0x0008, 0x0006, 0x000E, 0x0008, 0x0008, }; |
| 359 | |
| 360 | |
| 361 | #define dr32(reg) readl(de->regs + (reg)) |
| 362 | #define dw32(reg,val) writel((val), de->regs + (reg)) |
| 363 | |
| 364 | |
| 365 | static void de_rx_err_acct (struct de_private *de, unsigned rx_tail, |
| 366 | u32 status, u32 len) |
| 367 | { |
| 368 | if (netif_msg_rx_err (de)) |
| 369 | printk (KERN_DEBUG |
| 370 | "%s: rx err, slot %d status 0x%x len %d\n", |
| 371 | de->dev->name, rx_tail, status, len); |
| 372 | |
| 373 | if ((status & 0x38000300) != 0x0300) { |
| 374 | /* Ingore earlier buffers. */ |
| 375 | if ((status & 0xffff) != 0x7fff) { |
| 376 | if (netif_msg_rx_err(de)) |
| 377 | printk(KERN_WARNING "%s: Oversized Ethernet frame " |
| 378 | "spanned multiple buffers, status %8.8x!\n", |
| 379 | de->dev->name, status); |
| 380 | de->net_stats.rx_length_errors++; |
| 381 | } |
| 382 | } else if (status & RxError) { |
| 383 | /* There was a fatal error. */ |
| 384 | de->net_stats.rx_errors++; /* end of a packet.*/ |
| 385 | if (status & 0x0890) de->net_stats.rx_length_errors++; |
| 386 | if (status & RxErrCRC) de->net_stats.rx_crc_errors++; |
| 387 | if (status & RxErrFIFO) de->net_stats.rx_fifo_errors++; |
| 388 | } |
| 389 | } |
| 390 | |
| 391 | static void de_rx (struct de_private *de) |
| 392 | { |
| 393 | unsigned rx_tail = de->rx_tail; |
| 394 | unsigned rx_work = DE_RX_RING_SIZE; |
| 395 | unsigned drop = 0; |
| 396 | int rc; |
| 397 | |
| 398 | while (rx_work--) { |
| 399 | u32 status, len; |
| 400 | dma_addr_t mapping; |
| 401 | struct sk_buff *skb, *copy_skb; |
| 402 | unsigned copying_skb, buflen; |
| 403 | |
| 404 | skb = de->rx_skb[rx_tail].skb; |
Eric Sesterhenn / snakebyte | 7e0b58f | 2006-01-26 22:02:43 +0100 | [diff] [blame^] | 405 | BUG_ON(!skb); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 406 | rmb(); |
| 407 | status = le32_to_cpu(de->rx_ring[rx_tail].opts1); |
| 408 | if (status & DescOwn) |
| 409 | break; |
| 410 | |
| 411 | len = ((status >> 16) & 0x7ff) - 4; |
| 412 | mapping = de->rx_skb[rx_tail].mapping; |
| 413 | |
| 414 | if (unlikely(drop)) { |
| 415 | de->net_stats.rx_dropped++; |
| 416 | goto rx_next; |
| 417 | } |
| 418 | |
| 419 | if (unlikely((status & 0x38008300) != 0x0300)) { |
| 420 | de_rx_err_acct(de, rx_tail, status, len); |
| 421 | goto rx_next; |
| 422 | } |
| 423 | |
| 424 | copying_skb = (len <= rx_copybreak); |
| 425 | |
| 426 | if (unlikely(netif_msg_rx_status(de))) |
| 427 | printk(KERN_DEBUG "%s: rx slot %d status 0x%x len %d copying? %d\n", |
| 428 | de->dev->name, rx_tail, status, len, |
| 429 | copying_skb); |
| 430 | |
| 431 | buflen = copying_skb ? (len + RX_OFFSET) : de->rx_buf_sz; |
| 432 | copy_skb = dev_alloc_skb (buflen); |
| 433 | if (unlikely(!copy_skb)) { |
| 434 | de->net_stats.rx_dropped++; |
| 435 | drop = 1; |
| 436 | rx_work = 100; |
| 437 | goto rx_next; |
| 438 | } |
| 439 | copy_skb->dev = de->dev; |
| 440 | |
| 441 | if (!copying_skb) { |
| 442 | pci_unmap_single(de->pdev, mapping, |
| 443 | buflen, PCI_DMA_FROMDEVICE); |
| 444 | skb_put(skb, len); |
| 445 | |
| 446 | mapping = |
| 447 | de->rx_skb[rx_tail].mapping = |
David S. Miller | 689be43 | 2005-06-28 15:25:31 -0700 | [diff] [blame] | 448 | pci_map_single(de->pdev, copy_skb->data, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 449 | buflen, PCI_DMA_FROMDEVICE); |
| 450 | de->rx_skb[rx_tail].skb = copy_skb; |
| 451 | } else { |
| 452 | pci_dma_sync_single_for_cpu(de->pdev, mapping, len, PCI_DMA_FROMDEVICE); |
| 453 | skb_reserve(copy_skb, RX_OFFSET); |
David S. Miller | 689be43 | 2005-06-28 15:25:31 -0700 | [diff] [blame] | 454 | memcpy(skb_put(copy_skb, len), skb->data, len); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 455 | |
| 456 | pci_dma_sync_single_for_device(de->pdev, mapping, len, PCI_DMA_FROMDEVICE); |
| 457 | |
| 458 | /* We'll reuse the original ring buffer. */ |
| 459 | skb = copy_skb; |
| 460 | } |
| 461 | |
| 462 | skb->protocol = eth_type_trans (skb, de->dev); |
| 463 | |
| 464 | de->net_stats.rx_packets++; |
| 465 | de->net_stats.rx_bytes += skb->len; |
| 466 | de->dev->last_rx = jiffies; |
| 467 | rc = netif_rx (skb); |
| 468 | if (rc == NET_RX_DROP) |
| 469 | drop = 1; |
| 470 | |
| 471 | rx_next: |
| 472 | de->rx_ring[rx_tail].opts1 = cpu_to_le32(DescOwn); |
| 473 | if (rx_tail == (DE_RX_RING_SIZE - 1)) |
| 474 | de->rx_ring[rx_tail].opts2 = |
| 475 | cpu_to_le32(RingEnd | de->rx_buf_sz); |
| 476 | else |
| 477 | de->rx_ring[rx_tail].opts2 = cpu_to_le32(de->rx_buf_sz); |
| 478 | de->rx_ring[rx_tail].addr1 = cpu_to_le32(mapping); |
| 479 | rx_tail = NEXT_RX(rx_tail); |
| 480 | } |
| 481 | |
| 482 | if (!rx_work) |
| 483 | printk(KERN_WARNING "%s: rx work limit reached\n", de->dev->name); |
| 484 | |
| 485 | de->rx_tail = rx_tail; |
| 486 | } |
| 487 | |
| 488 | static irqreturn_t de_interrupt (int irq, void *dev_instance, struct pt_regs *regs) |
| 489 | { |
| 490 | struct net_device *dev = dev_instance; |
| 491 | struct de_private *de = dev->priv; |
| 492 | u32 status; |
| 493 | |
| 494 | status = dr32(MacStatus); |
| 495 | if ((!(status & (IntrOK|IntrErr))) || (status == 0xFFFF)) |
| 496 | return IRQ_NONE; |
| 497 | |
| 498 | if (netif_msg_intr(de)) |
| 499 | printk(KERN_DEBUG "%s: intr, status %08x mode %08x desc %u/%u/%u\n", |
| 500 | dev->name, status, dr32(MacMode), de->rx_tail, de->tx_head, de->tx_tail); |
| 501 | |
| 502 | dw32(MacStatus, status); |
| 503 | |
| 504 | if (status & (RxIntr | RxEmpty)) { |
| 505 | de_rx(de); |
| 506 | if (status & RxEmpty) |
| 507 | dw32(RxPoll, NormalRxPoll); |
| 508 | } |
| 509 | |
| 510 | spin_lock(&de->lock); |
| 511 | |
| 512 | if (status & (TxIntr | TxEmpty)) |
| 513 | de_tx(de); |
| 514 | |
| 515 | if (status & (LinkPass | LinkFail)) |
| 516 | de_media_interrupt(de, status); |
| 517 | |
| 518 | spin_unlock(&de->lock); |
| 519 | |
| 520 | if (status & PciErr) { |
| 521 | u16 pci_status; |
| 522 | |
| 523 | pci_read_config_word(de->pdev, PCI_STATUS, &pci_status); |
| 524 | pci_write_config_word(de->pdev, PCI_STATUS, pci_status); |
| 525 | printk(KERN_ERR "%s: PCI bus error, status=%08x, PCI status=%04x\n", |
| 526 | dev->name, status, pci_status); |
| 527 | } |
| 528 | |
| 529 | return IRQ_HANDLED; |
| 530 | } |
| 531 | |
| 532 | static void de_tx (struct de_private *de) |
| 533 | { |
| 534 | unsigned tx_head = de->tx_head; |
| 535 | unsigned tx_tail = de->tx_tail; |
| 536 | |
| 537 | while (tx_tail != tx_head) { |
| 538 | struct sk_buff *skb; |
| 539 | u32 status; |
| 540 | |
| 541 | rmb(); |
| 542 | status = le32_to_cpu(de->tx_ring[tx_tail].opts1); |
| 543 | if (status & DescOwn) |
| 544 | break; |
| 545 | |
| 546 | skb = de->tx_skb[tx_tail].skb; |
Eric Sesterhenn / snakebyte | 7e0b58f | 2006-01-26 22:02:43 +0100 | [diff] [blame^] | 547 | BUG_ON(!skb); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 548 | if (unlikely(skb == DE_DUMMY_SKB)) |
| 549 | goto next; |
| 550 | |
| 551 | if (unlikely(skb == DE_SETUP_SKB)) { |
| 552 | pci_unmap_single(de->pdev, de->tx_skb[tx_tail].mapping, |
| 553 | sizeof(de->setup_frame), PCI_DMA_TODEVICE); |
| 554 | goto next; |
| 555 | } |
| 556 | |
| 557 | pci_unmap_single(de->pdev, de->tx_skb[tx_tail].mapping, |
| 558 | skb->len, PCI_DMA_TODEVICE); |
| 559 | |
| 560 | if (status & LastFrag) { |
| 561 | if (status & TxError) { |
| 562 | if (netif_msg_tx_err(de)) |
| 563 | printk(KERN_DEBUG "%s: tx err, status 0x%x\n", |
| 564 | de->dev->name, status); |
| 565 | de->net_stats.tx_errors++; |
| 566 | if (status & TxOWC) |
| 567 | de->net_stats.tx_window_errors++; |
| 568 | if (status & TxMaxCol) |
| 569 | de->net_stats.tx_aborted_errors++; |
| 570 | if (status & TxLinkFail) |
| 571 | de->net_stats.tx_carrier_errors++; |
| 572 | if (status & TxFIFOUnder) |
| 573 | de->net_stats.tx_fifo_errors++; |
| 574 | } else { |
| 575 | de->net_stats.tx_packets++; |
| 576 | de->net_stats.tx_bytes += skb->len; |
| 577 | if (netif_msg_tx_done(de)) |
| 578 | printk(KERN_DEBUG "%s: tx done, slot %d\n", de->dev->name, tx_tail); |
| 579 | } |
| 580 | dev_kfree_skb_irq(skb); |
| 581 | } |
| 582 | |
| 583 | next: |
| 584 | de->tx_skb[tx_tail].skb = NULL; |
| 585 | |
| 586 | tx_tail = NEXT_TX(tx_tail); |
| 587 | } |
| 588 | |
| 589 | de->tx_tail = tx_tail; |
| 590 | |
| 591 | if (netif_queue_stopped(de->dev) && (TX_BUFFS_AVAIL(de) > (DE_TX_RING_SIZE / 4))) |
| 592 | netif_wake_queue(de->dev); |
| 593 | } |
| 594 | |
| 595 | static int de_start_xmit (struct sk_buff *skb, struct net_device *dev) |
| 596 | { |
| 597 | struct de_private *de = dev->priv; |
| 598 | unsigned int entry, tx_free; |
| 599 | u32 mapping, len, flags = FirstFrag | LastFrag; |
| 600 | struct de_desc *txd; |
| 601 | |
| 602 | spin_lock_irq(&de->lock); |
| 603 | |
| 604 | tx_free = TX_BUFFS_AVAIL(de); |
| 605 | if (tx_free == 0) { |
| 606 | netif_stop_queue(dev); |
| 607 | spin_unlock_irq(&de->lock); |
| 608 | return 1; |
| 609 | } |
| 610 | tx_free--; |
| 611 | |
| 612 | entry = de->tx_head; |
| 613 | |
| 614 | txd = &de->tx_ring[entry]; |
| 615 | |
| 616 | len = skb->len; |
| 617 | mapping = pci_map_single(de->pdev, skb->data, len, PCI_DMA_TODEVICE); |
| 618 | if (entry == (DE_TX_RING_SIZE - 1)) |
| 619 | flags |= RingEnd; |
| 620 | if (!tx_free || (tx_free == (DE_TX_RING_SIZE / 2))) |
| 621 | flags |= TxSwInt; |
| 622 | flags |= len; |
| 623 | txd->opts2 = cpu_to_le32(flags); |
| 624 | txd->addr1 = cpu_to_le32(mapping); |
| 625 | |
| 626 | de->tx_skb[entry].skb = skb; |
| 627 | de->tx_skb[entry].mapping = mapping; |
| 628 | wmb(); |
| 629 | |
| 630 | txd->opts1 = cpu_to_le32(DescOwn); |
| 631 | wmb(); |
| 632 | |
| 633 | de->tx_head = NEXT_TX(entry); |
| 634 | if (netif_msg_tx_queued(de)) |
| 635 | printk(KERN_DEBUG "%s: tx queued, slot %d, skblen %d\n", |
| 636 | dev->name, entry, skb->len); |
| 637 | |
| 638 | if (tx_free == 0) |
| 639 | netif_stop_queue(dev); |
| 640 | |
| 641 | spin_unlock_irq(&de->lock); |
| 642 | |
| 643 | /* Trigger an immediate transmit demand. */ |
| 644 | dw32(TxPoll, NormalTxPoll); |
| 645 | dev->trans_start = jiffies; |
| 646 | |
| 647 | return 0; |
| 648 | } |
| 649 | |
| 650 | /* Set or clear the multicast filter for this adaptor. |
| 651 | Note that we only use exclusion around actually queueing the |
| 652 | new frame, not around filling de->setup_frame. This is non-deterministic |
| 653 | when re-entered but still correct. */ |
| 654 | |
| 655 | #undef set_bit_le |
| 656 | #define set_bit_le(i,p) do { ((char *)(p))[(i)/8] |= (1<<((i)%8)); } while(0) |
| 657 | |
| 658 | static void build_setup_frame_hash(u16 *setup_frm, struct net_device *dev) |
| 659 | { |
| 660 | struct de_private *de = dev->priv; |
| 661 | u16 hash_table[32]; |
| 662 | struct dev_mc_list *mclist; |
| 663 | int i; |
| 664 | u16 *eaddrs; |
| 665 | |
| 666 | memset(hash_table, 0, sizeof(hash_table)); |
| 667 | set_bit_le(255, hash_table); /* Broadcast entry */ |
| 668 | /* This should work on big-endian machines as well. */ |
| 669 | for (i = 0, mclist = dev->mc_list; mclist && i < dev->mc_count; |
| 670 | i++, mclist = mclist->next) { |
| 671 | int index = ether_crc_le(ETH_ALEN, mclist->dmi_addr) & 0x1ff; |
| 672 | |
| 673 | set_bit_le(index, hash_table); |
| 674 | |
| 675 | for (i = 0; i < 32; i++) { |
| 676 | *setup_frm++ = hash_table[i]; |
| 677 | *setup_frm++ = hash_table[i]; |
| 678 | } |
| 679 | setup_frm = &de->setup_frame[13*6]; |
| 680 | } |
| 681 | |
| 682 | /* Fill the final entry with our physical address. */ |
| 683 | eaddrs = (u16 *)dev->dev_addr; |
| 684 | *setup_frm++ = eaddrs[0]; *setup_frm++ = eaddrs[0]; |
| 685 | *setup_frm++ = eaddrs[1]; *setup_frm++ = eaddrs[1]; |
| 686 | *setup_frm++ = eaddrs[2]; *setup_frm++ = eaddrs[2]; |
| 687 | } |
| 688 | |
| 689 | static void build_setup_frame_perfect(u16 *setup_frm, struct net_device *dev) |
| 690 | { |
| 691 | struct de_private *de = dev->priv; |
| 692 | struct dev_mc_list *mclist; |
| 693 | int i; |
| 694 | u16 *eaddrs; |
| 695 | |
| 696 | /* We have <= 14 addresses so we can use the wonderful |
| 697 | 16 address perfect filtering of the Tulip. */ |
| 698 | for (i = 0, mclist = dev->mc_list; i < dev->mc_count; |
| 699 | i++, mclist = mclist->next) { |
| 700 | eaddrs = (u16 *)mclist->dmi_addr; |
| 701 | *setup_frm++ = *eaddrs; *setup_frm++ = *eaddrs++; |
| 702 | *setup_frm++ = *eaddrs; *setup_frm++ = *eaddrs++; |
| 703 | *setup_frm++ = *eaddrs; *setup_frm++ = *eaddrs++; |
| 704 | } |
| 705 | /* Fill the unused entries with the broadcast address. */ |
| 706 | memset(setup_frm, 0xff, (15-i)*12); |
| 707 | setup_frm = &de->setup_frame[15*6]; |
| 708 | |
| 709 | /* Fill the final entry with our physical address. */ |
| 710 | eaddrs = (u16 *)dev->dev_addr; |
| 711 | *setup_frm++ = eaddrs[0]; *setup_frm++ = eaddrs[0]; |
| 712 | *setup_frm++ = eaddrs[1]; *setup_frm++ = eaddrs[1]; |
| 713 | *setup_frm++ = eaddrs[2]; *setup_frm++ = eaddrs[2]; |
| 714 | } |
| 715 | |
| 716 | |
| 717 | static void __de_set_rx_mode (struct net_device *dev) |
| 718 | { |
| 719 | struct de_private *de = dev->priv; |
| 720 | u32 macmode; |
| 721 | unsigned int entry; |
| 722 | u32 mapping; |
| 723 | struct de_desc *txd; |
| 724 | struct de_desc *dummy_txd = NULL; |
| 725 | |
| 726 | macmode = dr32(MacMode) & ~(AcceptAllMulticast | AcceptAllPhys); |
| 727 | |
| 728 | if (dev->flags & IFF_PROMISC) { /* Set promiscuous. */ |
| 729 | macmode |= AcceptAllMulticast | AcceptAllPhys; |
| 730 | goto out; |
| 731 | } |
| 732 | |
| 733 | if ((dev->mc_count > 1000) || (dev->flags & IFF_ALLMULTI)) { |
| 734 | /* Too many to filter well -- accept all multicasts. */ |
| 735 | macmode |= AcceptAllMulticast; |
| 736 | goto out; |
| 737 | } |
| 738 | |
| 739 | /* Note that only the low-address shortword of setup_frame is valid! |
| 740 | The values are doubled for big-endian architectures. */ |
| 741 | if (dev->mc_count > 14) /* Must use a multicast hash table. */ |
| 742 | build_setup_frame_hash (de->setup_frame, dev); |
| 743 | else |
| 744 | build_setup_frame_perfect (de->setup_frame, dev); |
| 745 | |
| 746 | /* |
| 747 | * Now add this frame to the Tx list. |
| 748 | */ |
| 749 | |
| 750 | entry = de->tx_head; |
| 751 | |
| 752 | /* Avoid a chip errata by prefixing a dummy entry. */ |
| 753 | if (entry != 0) { |
| 754 | de->tx_skb[entry].skb = DE_DUMMY_SKB; |
| 755 | |
| 756 | dummy_txd = &de->tx_ring[entry]; |
| 757 | dummy_txd->opts2 = (entry == (DE_TX_RING_SIZE - 1)) ? |
| 758 | cpu_to_le32(RingEnd) : 0; |
| 759 | dummy_txd->addr1 = 0; |
| 760 | |
| 761 | /* Must set DescOwned later to avoid race with chip */ |
| 762 | |
| 763 | entry = NEXT_TX(entry); |
| 764 | } |
| 765 | |
| 766 | de->tx_skb[entry].skb = DE_SETUP_SKB; |
| 767 | de->tx_skb[entry].mapping = mapping = |
| 768 | pci_map_single (de->pdev, de->setup_frame, |
| 769 | sizeof (de->setup_frame), PCI_DMA_TODEVICE); |
| 770 | |
| 771 | /* Put the setup frame on the Tx list. */ |
| 772 | txd = &de->tx_ring[entry]; |
| 773 | if (entry == (DE_TX_RING_SIZE - 1)) |
| 774 | txd->opts2 = cpu_to_le32(SetupFrame | RingEnd | sizeof (de->setup_frame)); |
| 775 | else |
| 776 | txd->opts2 = cpu_to_le32(SetupFrame | sizeof (de->setup_frame)); |
| 777 | txd->addr1 = cpu_to_le32(mapping); |
| 778 | wmb(); |
| 779 | |
| 780 | txd->opts1 = cpu_to_le32(DescOwn); |
| 781 | wmb(); |
| 782 | |
| 783 | if (dummy_txd) { |
| 784 | dummy_txd->opts1 = cpu_to_le32(DescOwn); |
| 785 | wmb(); |
| 786 | } |
| 787 | |
| 788 | de->tx_head = NEXT_TX(entry); |
| 789 | |
Eric Sesterhenn / snakebyte | 7e0b58f | 2006-01-26 22:02:43 +0100 | [diff] [blame^] | 790 | BUG_ON(TX_BUFFS_AVAIL(de) < 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 791 | if (TX_BUFFS_AVAIL(de) == 0) |
| 792 | netif_stop_queue(dev); |
| 793 | |
| 794 | /* Trigger an immediate transmit demand. */ |
| 795 | dw32(TxPoll, NormalTxPoll); |
| 796 | |
| 797 | out: |
| 798 | if (macmode != dr32(MacMode)) |
| 799 | dw32(MacMode, macmode); |
| 800 | } |
| 801 | |
| 802 | static void de_set_rx_mode (struct net_device *dev) |
| 803 | { |
| 804 | unsigned long flags; |
| 805 | struct de_private *de = dev->priv; |
| 806 | |
| 807 | spin_lock_irqsave (&de->lock, flags); |
| 808 | __de_set_rx_mode(dev); |
| 809 | spin_unlock_irqrestore (&de->lock, flags); |
| 810 | } |
| 811 | |
| 812 | static inline void de_rx_missed(struct de_private *de, u32 rx_missed) |
| 813 | { |
| 814 | if (unlikely(rx_missed & RxMissedOver)) |
| 815 | de->net_stats.rx_missed_errors += RxMissedMask; |
| 816 | else |
| 817 | de->net_stats.rx_missed_errors += (rx_missed & RxMissedMask); |
| 818 | } |
| 819 | |
| 820 | static void __de_get_stats(struct de_private *de) |
| 821 | { |
| 822 | u32 tmp = dr32(RxMissed); /* self-clearing */ |
| 823 | |
| 824 | de_rx_missed(de, tmp); |
| 825 | } |
| 826 | |
| 827 | static struct net_device_stats *de_get_stats(struct net_device *dev) |
| 828 | { |
| 829 | struct de_private *de = dev->priv; |
| 830 | |
| 831 | /* The chip only need report frame silently dropped. */ |
| 832 | spin_lock_irq(&de->lock); |
| 833 | if (netif_running(dev) && netif_device_present(dev)) |
| 834 | __de_get_stats(de); |
| 835 | spin_unlock_irq(&de->lock); |
| 836 | |
| 837 | return &de->net_stats; |
| 838 | } |
| 839 | |
| 840 | static inline int de_is_running (struct de_private *de) |
| 841 | { |
| 842 | return (dr32(MacStatus) & (RxState | TxState)) ? 1 : 0; |
| 843 | } |
| 844 | |
| 845 | static void de_stop_rxtx (struct de_private *de) |
| 846 | { |
| 847 | u32 macmode; |
| 848 | unsigned int work = 1000; |
| 849 | |
| 850 | macmode = dr32(MacMode); |
| 851 | if (macmode & RxTx) { |
| 852 | dw32(MacMode, macmode & ~RxTx); |
| 853 | dr32(MacMode); |
| 854 | } |
| 855 | |
| 856 | while (--work > 0) { |
| 857 | if (!de_is_running(de)) |
| 858 | return; |
| 859 | cpu_relax(); |
| 860 | } |
| 861 | |
| 862 | printk(KERN_WARNING "%s: timeout expired stopping DMA\n", de->dev->name); |
| 863 | } |
| 864 | |
| 865 | static inline void de_start_rxtx (struct de_private *de) |
| 866 | { |
| 867 | u32 macmode; |
| 868 | |
| 869 | macmode = dr32(MacMode); |
| 870 | if ((macmode & RxTx) != RxTx) { |
| 871 | dw32(MacMode, macmode | RxTx); |
| 872 | dr32(MacMode); |
| 873 | } |
| 874 | } |
| 875 | |
| 876 | static void de_stop_hw (struct de_private *de) |
| 877 | { |
| 878 | |
| 879 | udelay(5); |
| 880 | dw32(IntrMask, 0); |
| 881 | |
| 882 | de_stop_rxtx(de); |
| 883 | |
| 884 | dw32(MacStatus, dr32(MacStatus)); |
| 885 | |
| 886 | udelay(10); |
| 887 | |
| 888 | de->rx_tail = 0; |
| 889 | de->tx_head = de->tx_tail = 0; |
| 890 | } |
| 891 | |
| 892 | static void de_link_up(struct de_private *de) |
| 893 | { |
| 894 | if (!netif_carrier_ok(de->dev)) { |
| 895 | netif_carrier_on(de->dev); |
| 896 | if (netif_msg_link(de)) |
| 897 | printk(KERN_INFO "%s: link up, media %s\n", |
| 898 | de->dev->name, media_name[de->media_type]); |
| 899 | } |
| 900 | } |
| 901 | |
| 902 | static void de_link_down(struct de_private *de) |
| 903 | { |
| 904 | if (netif_carrier_ok(de->dev)) { |
| 905 | netif_carrier_off(de->dev); |
| 906 | if (netif_msg_link(de)) |
| 907 | printk(KERN_INFO "%s: link down\n", de->dev->name); |
| 908 | } |
| 909 | } |
| 910 | |
| 911 | static void de_set_media (struct de_private *de) |
| 912 | { |
| 913 | unsigned media = de->media_type; |
| 914 | u32 macmode = dr32(MacMode); |
| 915 | |
Eric Sesterhenn / snakebyte | 7e0b58f | 2006-01-26 22:02:43 +0100 | [diff] [blame^] | 916 | BUG_ON(de_is_running(de)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 917 | |
| 918 | if (de->de21040) |
| 919 | dw32(CSR11, FULL_DUPLEX_MAGIC); |
| 920 | dw32(CSR13, 0); /* Reset phy */ |
| 921 | dw32(CSR14, de->media[media].csr14); |
| 922 | dw32(CSR15, de->media[media].csr15); |
| 923 | dw32(CSR13, de->media[media].csr13); |
| 924 | |
| 925 | /* must delay 10ms before writing to other registers, |
| 926 | * especially CSR6 |
| 927 | */ |
| 928 | mdelay(10); |
| 929 | |
| 930 | if (media == DE_MEDIA_TP_FD) |
| 931 | macmode |= FullDuplex; |
| 932 | else |
| 933 | macmode &= ~FullDuplex; |
| 934 | |
| 935 | if (netif_msg_link(de)) { |
| 936 | printk(KERN_INFO "%s: set link %s\n" |
| 937 | KERN_INFO "%s: mode 0x%x, sia 0x%x,0x%x,0x%x,0x%x\n" |
| 938 | KERN_INFO "%s: set mode 0x%x, set sia 0x%x,0x%x,0x%x\n", |
| 939 | de->dev->name, media_name[media], |
| 940 | de->dev->name, dr32(MacMode), dr32(SIAStatus), |
| 941 | dr32(CSR13), dr32(CSR14), dr32(CSR15), |
| 942 | de->dev->name, macmode, de->media[media].csr13, |
| 943 | de->media[media].csr14, de->media[media].csr15); |
| 944 | } |
| 945 | if (macmode != dr32(MacMode)) |
| 946 | dw32(MacMode, macmode); |
| 947 | } |
| 948 | |
| 949 | static void de_next_media (struct de_private *de, u32 *media, |
| 950 | unsigned int n_media) |
| 951 | { |
| 952 | unsigned int i; |
| 953 | |
| 954 | for (i = 0; i < n_media; i++) { |
| 955 | if (de_ok_to_advertise(de, media[i])) { |
| 956 | de->media_type = media[i]; |
| 957 | return; |
| 958 | } |
| 959 | } |
| 960 | } |
| 961 | |
| 962 | static void de21040_media_timer (unsigned long data) |
| 963 | { |
| 964 | struct de_private *de = (struct de_private *) data; |
| 965 | struct net_device *dev = de->dev; |
| 966 | u32 status = dr32(SIAStatus); |
| 967 | unsigned int carrier; |
| 968 | unsigned long flags; |
| 969 | |
| 970 | carrier = (status & NetCxnErr) ? 0 : 1; |
| 971 | |
| 972 | if (carrier) { |
| 973 | if (de->media_type != DE_MEDIA_AUI && (status & LinkFailStatus)) |
| 974 | goto no_link_yet; |
| 975 | |
| 976 | de->media_timer.expires = jiffies + DE_TIMER_LINK; |
| 977 | add_timer(&de->media_timer); |
| 978 | if (!netif_carrier_ok(dev)) |
| 979 | de_link_up(de); |
| 980 | else |
| 981 | if (netif_msg_timer(de)) |
| 982 | printk(KERN_INFO "%s: %s link ok, status %x\n", |
| 983 | dev->name, media_name[de->media_type], |
| 984 | status); |
| 985 | return; |
| 986 | } |
| 987 | |
| 988 | de_link_down(de); |
| 989 | |
| 990 | if (de->media_lock) |
| 991 | return; |
| 992 | |
| 993 | if (de->media_type == DE_MEDIA_AUI) { |
| 994 | u32 next_state = DE_MEDIA_TP; |
| 995 | de_next_media(de, &next_state, 1); |
| 996 | } else { |
| 997 | u32 next_state = DE_MEDIA_AUI; |
| 998 | de_next_media(de, &next_state, 1); |
| 999 | } |
| 1000 | |
| 1001 | spin_lock_irqsave(&de->lock, flags); |
| 1002 | de_stop_rxtx(de); |
| 1003 | spin_unlock_irqrestore(&de->lock, flags); |
| 1004 | de_set_media(de); |
| 1005 | de_start_rxtx(de); |
| 1006 | |
| 1007 | no_link_yet: |
| 1008 | de->media_timer.expires = jiffies + DE_TIMER_NO_LINK; |
| 1009 | add_timer(&de->media_timer); |
| 1010 | |
| 1011 | if (netif_msg_timer(de)) |
| 1012 | printk(KERN_INFO "%s: no link, trying media %s, status %x\n", |
| 1013 | dev->name, media_name[de->media_type], status); |
| 1014 | } |
| 1015 | |
| 1016 | static unsigned int de_ok_to_advertise (struct de_private *de, u32 new_media) |
| 1017 | { |
| 1018 | switch (new_media) { |
| 1019 | case DE_MEDIA_TP_AUTO: |
| 1020 | if (!(de->media_advertise & ADVERTISED_Autoneg)) |
| 1021 | return 0; |
| 1022 | if (!(de->media_advertise & (ADVERTISED_10baseT_Half | ADVERTISED_10baseT_Full))) |
| 1023 | return 0; |
| 1024 | break; |
| 1025 | case DE_MEDIA_BNC: |
| 1026 | if (!(de->media_advertise & ADVERTISED_BNC)) |
| 1027 | return 0; |
| 1028 | break; |
| 1029 | case DE_MEDIA_AUI: |
| 1030 | if (!(de->media_advertise & ADVERTISED_AUI)) |
| 1031 | return 0; |
| 1032 | break; |
| 1033 | case DE_MEDIA_TP: |
| 1034 | if (!(de->media_advertise & ADVERTISED_10baseT_Half)) |
| 1035 | return 0; |
| 1036 | break; |
| 1037 | case DE_MEDIA_TP_FD: |
| 1038 | if (!(de->media_advertise & ADVERTISED_10baseT_Full)) |
| 1039 | return 0; |
| 1040 | break; |
| 1041 | } |
| 1042 | |
| 1043 | return 1; |
| 1044 | } |
| 1045 | |
| 1046 | static void de21041_media_timer (unsigned long data) |
| 1047 | { |
| 1048 | struct de_private *de = (struct de_private *) data; |
| 1049 | struct net_device *dev = de->dev; |
| 1050 | u32 status = dr32(SIAStatus); |
| 1051 | unsigned int carrier; |
| 1052 | unsigned long flags; |
| 1053 | |
| 1054 | carrier = (status & NetCxnErr) ? 0 : 1; |
| 1055 | |
| 1056 | if (carrier) { |
| 1057 | if ((de->media_type == DE_MEDIA_TP_AUTO || |
| 1058 | de->media_type == DE_MEDIA_TP || |
| 1059 | de->media_type == DE_MEDIA_TP_FD) && |
| 1060 | (status & LinkFailStatus)) |
| 1061 | goto no_link_yet; |
| 1062 | |
| 1063 | de->media_timer.expires = jiffies + DE_TIMER_LINK; |
| 1064 | add_timer(&de->media_timer); |
| 1065 | if (!netif_carrier_ok(dev)) |
| 1066 | de_link_up(de); |
| 1067 | else |
| 1068 | if (netif_msg_timer(de)) |
| 1069 | printk(KERN_INFO "%s: %s link ok, mode %x status %x\n", |
| 1070 | dev->name, media_name[de->media_type], |
| 1071 | dr32(MacMode), status); |
| 1072 | return; |
| 1073 | } |
| 1074 | |
| 1075 | de_link_down(de); |
| 1076 | |
| 1077 | /* if media type locked, don't switch media */ |
| 1078 | if (de->media_lock) |
| 1079 | goto set_media; |
| 1080 | |
| 1081 | /* if activity detected, use that as hint for new media type */ |
| 1082 | if (status & NonselPortActive) { |
| 1083 | unsigned int have_media = 1; |
| 1084 | |
| 1085 | /* if AUI/BNC selected, then activity is on TP port */ |
| 1086 | if (de->media_type == DE_MEDIA_AUI || |
| 1087 | de->media_type == DE_MEDIA_BNC) { |
| 1088 | if (de_ok_to_advertise(de, DE_MEDIA_TP_AUTO)) |
| 1089 | de->media_type = DE_MEDIA_TP_AUTO; |
| 1090 | else |
| 1091 | have_media = 0; |
| 1092 | } |
| 1093 | |
| 1094 | /* TP selected. If there is only TP and BNC, then it's BNC */ |
| 1095 | else if (((de->media_supported & DE_AUI_BNC) == SUPPORTED_BNC) && |
| 1096 | de_ok_to_advertise(de, DE_MEDIA_BNC)) |
| 1097 | de->media_type = DE_MEDIA_BNC; |
| 1098 | |
| 1099 | /* TP selected. If there is only TP and AUI, then it's AUI */ |
| 1100 | else if (((de->media_supported & DE_AUI_BNC) == SUPPORTED_AUI) && |
| 1101 | de_ok_to_advertise(de, DE_MEDIA_AUI)) |
| 1102 | de->media_type = DE_MEDIA_AUI; |
| 1103 | |
| 1104 | /* otherwise, ignore the hint */ |
| 1105 | else |
| 1106 | have_media = 0; |
| 1107 | |
| 1108 | if (have_media) |
| 1109 | goto set_media; |
| 1110 | } |
| 1111 | |
| 1112 | /* |
| 1113 | * Absent or ambiguous activity hint, move to next advertised |
| 1114 | * media state. If de->media_type is left unchanged, this |
| 1115 | * simply resets the PHY and reloads the current media settings. |
| 1116 | */ |
| 1117 | if (de->media_type == DE_MEDIA_AUI) { |
| 1118 | u32 next_states[] = { DE_MEDIA_BNC, DE_MEDIA_TP_AUTO }; |
| 1119 | de_next_media(de, next_states, ARRAY_SIZE(next_states)); |
| 1120 | } else if (de->media_type == DE_MEDIA_BNC) { |
| 1121 | u32 next_states[] = { DE_MEDIA_TP_AUTO, DE_MEDIA_AUI }; |
| 1122 | de_next_media(de, next_states, ARRAY_SIZE(next_states)); |
| 1123 | } else { |
| 1124 | u32 next_states[] = { DE_MEDIA_AUI, DE_MEDIA_BNC, DE_MEDIA_TP_AUTO }; |
| 1125 | de_next_media(de, next_states, ARRAY_SIZE(next_states)); |
| 1126 | } |
| 1127 | |
| 1128 | set_media: |
| 1129 | spin_lock_irqsave(&de->lock, flags); |
| 1130 | de_stop_rxtx(de); |
| 1131 | spin_unlock_irqrestore(&de->lock, flags); |
| 1132 | de_set_media(de); |
| 1133 | de_start_rxtx(de); |
| 1134 | |
| 1135 | no_link_yet: |
| 1136 | de->media_timer.expires = jiffies + DE_TIMER_NO_LINK; |
| 1137 | add_timer(&de->media_timer); |
| 1138 | |
| 1139 | if (netif_msg_timer(de)) |
| 1140 | printk(KERN_INFO "%s: no link, trying media %s, status %x\n", |
| 1141 | dev->name, media_name[de->media_type], status); |
| 1142 | } |
| 1143 | |
| 1144 | static void de_media_interrupt (struct de_private *de, u32 status) |
| 1145 | { |
| 1146 | if (status & LinkPass) { |
| 1147 | de_link_up(de); |
| 1148 | mod_timer(&de->media_timer, jiffies + DE_TIMER_LINK); |
| 1149 | return; |
| 1150 | } |
| 1151 | |
Eric Sesterhenn / snakebyte | 7e0b58f | 2006-01-26 22:02:43 +0100 | [diff] [blame^] | 1152 | BUG_ON(!(status & LinkFail)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1153 | |
| 1154 | if (netif_carrier_ok(de->dev)) { |
| 1155 | de_link_down(de); |
| 1156 | mod_timer(&de->media_timer, jiffies + DE_TIMER_NO_LINK); |
| 1157 | } |
| 1158 | } |
| 1159 | |
| 1160 | static int de_reset_mac (struct de_private *de) |
| 1161 | { |
| 1162 | u32 status, tmp; |
| 1163 | |
| 1164 | /* |
| 1165 | * Reset MAC. de4x5.c and tulip.c examined for "advice" |
| 1166 | * in this area. |
| 1167 | */ |
| 1168 | |
| 1169 | if (dr32(BusMode) == 0xffffffff) |
| 1170 | return -EBUSY; |
| 1171 | |
| 1172 | /* Reset the chip, holding bit 0 set at least 50 PCI cycles. */ |
| 1173 | dw32 (BusMode, CmdReset); |
| 1174 | mdelay (1); |
| 1175 | |
| 1176 | dw32 (BusMode, de_bus_mode); |
| 1177 | mdelay (1); |
| 1178 | |
| 1179 | for (tmp = 0; tmp < 5; tmp++) { |
| 1180 | dr32 (BusMode); |
| 1181 | mdelay (1); |
| 1182 | } |
| 1183 | |
| 1184 | mdelay (1); |
| 1185 | |
| 1186 | status = dr32(MacStatus); |
| 1187 | if (status & (RxState | TxState)) |
| 1188 | return -EBUSY; |
| 1189 | if (status == 0xffffffff) |
| 1190 | return -ENODEV; |
| 1191 | return 0; |
| 1192 | } |
| 1193 | |
| 1194 | static void de_adapter_wake (struct de_private *de) |
| 1195 | { |
| 1196 | u32 pmctl; |
| 1197 | |
| 1198 | if (de->de21040) |
| 1199 | return; |
| 1200 | |
| 1201 | pci_read_config_dword(de->pdev, PCIPM, &pmctl); |
| 1202 | if (pmctl & PM_Mask) { |
| 1203 | pmctl &= ~PM_Mask; |
| 1204 | pci_write_config_dword(de->pdev, PCIPM, pmctl); |
| 1205 | |
| 1206 | /* de4x5.c delays, so we do too */ |
| 1207 | msleep(10); |
| 1208 | } |
| 1209 | } |
| 1210 | |
| 1211 | static void de_adapter_sleep (struct de_private *de) |
| 1212 | { |
| 1213 | u32 pmctl; |
| 1214 | |
| 1215 | if (de->de21040) |
| 1216 | return; |
| 1217 | |
| 1218 | pci_read_config_dword(de->pdev, PCIPM, &pmctl); |
| 1219 | pmctl |= PM_Sleep; |
| 1220 | pci_write_config_dword(de->pdev, PCIPM, pmctl); |
| 1221 | } |
| 1222 | |
| 1223 | static int de_init_hw (struct de_private *de) |
| 1224 | { |
| 1225 | struct net_device *dev = de->dev; |
| 1226 | u32 macmode; |
| 1227 | int rc; |
| 1228 | |
| 1229 | de_adapter_wake(de); |
| 1230 | |
| 1231 | macmode = dr32(MacMode) & ~MacModeClear; |
| 1232 | |
| 1233 | rc = de_reset_mac(de); |
| 1234 | if (rc) |
| 1235 | return rc; |
| 1236 | |
| 1237 | de_set_media(de); /* reset phy */ |
| 1238 | |
| 1239 | dw32(RxRingAddr, de->ring_dma); |
| 1240 | dw32(TxRingAddr, de->ring_dma + (sizeof(struct de_desc) * DE_RX_RING_SIZE)); |
| 1241 | |
| 1242 | dw32(MacMode, RxTx | macmode); |
| 1243 | |
| 1244 | dr32(RxMissed); /* self-clearing */ |
| 1245 | |
| 1246 | dw32(IntrMask, de_intr_mask); |
| 1247 | |
| 1248 | de_set_rx_mode(dev); |
| 1249 | |
| 1250 | return 0; |
| 1251 | } |
| 1252 | |
| 1253 | static int de_refill_rx (struct de_private *de) |
| 1254 | { |
| 1255 | unsigned i; |
| 1256 | |
| 1257 | for (i = 0; i < DE_RX_RING_SIZE; i++) { |
| 1258 | struct sk_buff *skb; |
| 1259 | |
| 1260 | skb = dev_alloc_skb(de->rx_buf_sz); |
| 1261 | if (!skb) |
| 1262 | goto err_out; |
| 1263 | |
| 1264 | skb->dev = de->dev; |
| 1265 | |
| 1266 | de->rx_skb[i].mapping = pci_map_single(de->pdev, |
David S. Miller | 689be43 | 2005-06-28 15:25:31 -0700 | [diff] [blame] | 1267 | skb->data, de->rx_buf_sz, PCI_DMA_FROMDEVICE); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1268 | de->rx_skb[i].skb = skb; |
| 1269 | |
| 1270 | de->rx_ring[i].opts1 = cpu_to_le32(DescOwn); |
| 1271 | if (i == (DE_RX_RING_SIZE - 1)) |
| 1272 | de->rx_ring[i].opts2 = |
| 1273 | cpu_to_le32(RingEnd | de->rx_buf_sz); |
| 1274 | else |
| 1275 | de->rx_ring[i].opts2 = cpu_to_le32(de->rx_buf_sz); |
| 1276 | de->rx_ring[i].addr1 = cpu_to_le32(de->rx_skb[i].mapping); |
| 1277 | de->rx_ring[i].addr2 = 0; |
| 1278 | } |
| 1279 | |
| 1280 | return 0; |
| 1281 | |
| 1282 | err_out: |
| 1283 | de_clean_rings(de); |
| 1284 | return -ENOMEM; |
| 1285 | } |
| 1286 | |
| 1287 | static int de_init_rings (struct de_private *de) |
| 1288 | { |
| 1289 | memset(de->tx_ring, 0, sizeof(struct de_desc) * DE_TX_RING_SIZE); |
| 1290 | de->tx_ring[DE_TX_RING_SIZE - 1].opts2 = cpu_to_le32(RingEnd); |
| 1291 | |
| 1292 | de->rx_tail = 0; |
| 1293 | de->tx_head = de->tx_tail = 0; |
| 1294 | |
| 1295 | return de_refill_rx (de); |
| 1296 | } |
| 1297 | |
| 1298 | static int de_alloc_rings (struct de_private *de) |
| 1299 | { |
| 1300 | de->rx_ring = pci_alloc_consistent(de->pdev, DE_RING_BYTES, &de->ring_dma); |
| 1301 | if (!de->rx_ring) |
| 1302 | return -ENOMEM; |
| 1303 | de->tx_ring = &de->rx_ring[DE_RX_RING_SIZE]; |
| 1304 | return de_init_rings(de); |
| 1305 | } |
| 1306 | |
| 1307 | static void de_clean_rings (struct de_private *de) |
| 1308 | { |
| 1309 | unsigned i; |
| 1310 | |
| 1311 | memset(de->rx_ring, 0, sizeof(struct de_desc) * DE_RX_RING_SIZE); |
| 1312 | de->rx_ring[DE_RX_RING_SIZE - 1].opts2 = cpu_to_le32(RingEnd); |
| 1313 | wmb(); |
| 1314 | memset(de->tx_ring, 0, sizeof(struct de_desc) * DE_TX_RING_SIZE); |
| 1315 | de->tx_ring[DE_TX_RING_SIZE - 1].opts2 = cpu_to_le32(RingEnd); |
| 1316 | wmb(); |
| 1317 | |
| 1318 | for (i = 0; i < DE_RX_RING_SIZE; i++) { |
| 1319 | if (de->rx_skb[i].skb) { |
| 1320 | pci_unmap_single(de->pdev, de->rx_skb[i].mapping, |
| 1321 | de->rx_buf_sz, PCI_DMA_FROMDEVICE); |
| 1322 | dev_kfree_skb(de->rx_skb[i].skb); |
| 1323 | } |
| 1324 | } |
| 1325 | |
| 1326 | for (i = 0; i < DE_TX_RING_SIZE; i++) { |
| 1327 | struct sk_buff *skb = de->tx_skb[i].skb; |
| 1328 | if ((skb) && (skb != DE_DUMMY_SKB)) { |
| 1329 | if (skb != DE_SETUP_SKB) { |
| 1330 | dev_kfree_skb(skb); |
| 1331 | de->net_stats.tx_dropped++; |
| 1332 | pci_unmap_single(de->pdev, |
| 1333 | de->tx_skb[i].mapping, |
| 1334 | skb->len, PCI_DMA_TODEVICE); |
| 1335 | } else { |
| 1336 | pci_unmap_single(de->pdev, |
| 1337 | de->tx_skb[i].mapping, |
| 1338 | sizeof(de->setup_frame), |
| 1339 | PCI_DMA_TODEVICE); |
| 1340 | } |
| 1341 | } |
| 1342 | } |
| 1343 | |
| 1344 | memset(&de->rx_skb, 0, sizeof(struct ring_info) * DE_RX_RING_SIZE); |
| 1345 | memset(&de->tx_skb, 0, sizeof(struct ring_info) * DE_TX_RING_SIZE); |
| 1346 | } |
| 1347 | |
| 1348 | static void de_free_rings (struct de_private *de) |
| 1349 | { |
| 1350 | de_clean_rings(de); |
| 1351 | pci_free_consistent(de->pdev, DE_RING_BYTES, de->rx_ring, de->ring_dma); |
| 1352 | de->rx_ring = NULL; |
| 1353 | de->tx_ring = NULL; |
| 1354 | } |
| 1355 | |
| 1356 | static int de_open (struct net_device *dev) |
| 1357 | { |
| 1358 | struct de_private *de = dev->priv; |
| 1359 | int rc; |
| 1360 | unsigned long flags; |
| 1361 | |
| 1362 | if (netif_msg_ifup(de)) |
| 1363 | printk(KERN_DEBUG "%s: enabling interface\n", dev->name); |
| 1364 | |
| 1365 | de->rx_buf_sz = (dev->mtu <= 1500 ? PKT_BUF_SZ : dev->mtu + 32); |
| 1366 | |
| 1367 | rc = de_alloc_rings(de); |
| 1368 | if (rc) { |
| 1369 | printk(KERN_ERR "%s: ring allocation failure, err=%d\n", |
| 1370 | dev->name, rc); |
| 1371 | return rc; |
| 1372 | } |
| 1373 | |
| 1374 | rc = de_init_hw(de); |
| 1375 | if (rc) { |
| 1376 | printk(KERN_ERR "%s: h/w init failure, err=%d\n", |
| 1377 | dev->name, rc); |
| 1378 | goto err_out_free; |
| 1379 | } |
| 1380 | |
| 1381 | rc = request_irq(dev->irq, de_interrupt, SA_SHIRQ, dev->name, dev); |
| 1382 | if (rc) { |
| 1383 | printk(KERN_ERR "%s: IRQ %d request failure, err=%d\n", |
| 1384 | dev->name, dev->irq, rc); |
| 1385 | goto err_out_hw; |
| 1386 | } |
| 1387 | |
| 1388 | netif_start_queue(dev); |
| 1389 | mod_timer(&de->media_timer, jiffies + DE_TIMER_NO_LINK); |
| 1390 | |
| 1391 | return 0; |
| 1392 | |
| 1393 | err_out_hw: |
| 1394 | spin_lock_irqsave(&de->lock, flags); |
| 1395 | de_stop_hw(de); |
| 1396 | spin_unlock_irqrestore(&de->lock, flags); |
| 1397 | |
| 1398 | err_out_free: |
| 1399 | de_free_rings(de); |
| 1400 | return rc; |
| 1401 | } |
| 1402 | |
| 1403 | static int de_close (struct net_device *dev) |
| 1404 | { |
| 1405 | struct de_private *de = dev->priv; |
| 1406 | unsigned long flags; |
| 1407 | |
| 1408 | if (netif_msg_ifdown(de)) |
| 1409 | printk(KERN_DEBUG "%s: disabling interface\n", dev->name); |
| 1410 | |
| 1411 | del_timer_sync(&de->media_timer); |
| 1412 | |
| 1413 | spin_lock_irqsave(&de->lock, flags); |
| 1414 | de_stop_hw(de); |
| 1415 | netif_stop_queue(dev); |
| 1416 | netif_carrier_off(dev); |
| 1417 | spin_unlock_irqrestore(&de->lock, flags); |
| 1418 | |
| 1419 | free_irq(dev->irq, dev); |
| 1420 | |
| 1421 | de_free_rings(de); |
| 1422 | de_adapter_sleep(de); |
| 1423 | pci_disable_device(de->pdev); |
| 1424 | return 0; |
| 1425 | } |
| 1426 | |
| 1427 | static void de_tx_timeout (struct net_device *dev) |
| 1428 | { |
| 1429 | struct de_private *de = dev->priv; |
| 1430 | |
| 1431 | printk(KERN_DEBUG "%s: NIC status %08x mode %08x sia %08x desc %u/%u/%u\n", |
| 1432 | dev->name, dr32(MacStatus), dr32(MacMode), dr32(SIAStatus), |
| 1433 | de->rx_tail, de->tx_head, de->tx_tail); |
| 1434 | |
| 1435 | del_timer_sync(&de->media_timer); |
| 1436 | |
| 1437 | disable_irq(dev->irq); |
| 1438 | spin_lock_irq(&de->lock); |
| 1439 | |
| 1440 | de_stop_hw(de); |
| 1441 | netif_stop_queue(dev); |
| 1442 | netif_carrier_off(dev); |
| 1443 | |
| 1444 | spin_unlock_irq(&de->lock); |
| 1445 | enable_irq(dev->irq); |
| 1446 | |
| 1447 | /* Update the error counts. */ |
| 1448 | __de_get_stats(de); |
| 1449 | |
| 1450 | synchronize_irq(dev->irq); |
| 1451 | de_clean_rings(de); |
| 1452 | |
| 1453 | de_init_hw(de); |
| 1454 | |
| 1455 | netif_wake_queue(dev); |
| 1456 | } |
| 1457 | |
| 1458 | static void __de_get_regs(struct de_private *de, u8 *buf) |
| 1459 | { |
| 1460 | int i; |
| 1461 | u32 *rbuf = (u32 *)buf; |
| 1462 | |
| 1463 | /* read all CSRs */ |
| 1464 | for (i = 0; i < DE_NUM_REGS; i++) |
| 1465 | rbuf[i] = dr32(i * 8); |
| 1466 | |
| 1467 | /* handle self-clearing RxMissed counter, CSR8 */ |
| 1468 | de_rx_missed(de, rbuf[8]); |
| 1469 | } |
| 1470 | |
| 1471 | static int __de_get_settings(struct de_private *de, struct ethtool_cmd *ecmd) |
| 1472 | { |
| 1473 | ecmd->supported = de->media_supported; |
| 1474 | ecmd->transceiver = XCVR_INTERNAL; |
| 1475 | ecmd->phy_address = 0; |
| 1476 | ecmd->advertising = de->media_advertise; |
| 1477 | |
| 1478 | switch (de->media_type) { |
| 1479 | case DE_MEDIA_AUI: |
| 1480 | ecmd->port = PORT_AUI; |
| 1481 | ecmd->speed = 5; |
| 1482 | break; |
| 1483 | case DE_MEDIA_BNC: |
| 1484 | ecmd->port = PORT_BNC; |
| 1485 | ecmd->speed = 2; |
| 1486 | break; |
| 1487 | default: |
| 1488 | ecmd->port = PORT_TP; |
| 1489 | ecmd->speed = SPEED_10; |
| 1490 | break; |
| 1491 | } |
| 1492 | |
| 1493 | if (dr32(MacMode) & FullDuplex) |
| 1494 | ecmd->duplex = DUPLEX_FULL; |
| 1495 | else |
| 1496 | ecmd->duplex = DUPLEX_HALF; |
| 1497 | |
| 1498 | if (de->media_lock) |
| 1499 | ecmd->autoneg = AUTONEG_DISABLE; |
| 1500 | else |
| 1501 | ecmd->autoneg = AUTONEG_ENABLE; |
| 1502 | |
| 1503 | /* ignore maxtxpkt, maxrxpkt for now */ |
| 1504 | |
| 1505 | return 0; |
| 1506 | } |
| 1507 | |
| 1508 | static int __de_set_settings(struct de_private *de, struct ethtool_cmd *ecmd) |
| 1509 | { |
| 1510 | u32 new_media; |
| 1511 | unsigned int media_lock; |
| 1512 | |
| 1513 | if (ecmd->speed != SPEED_10 && ecmd->speed != 5 && ecmd->speed != 2) |
| 1514 | return -EINVAL; |
| 1515 | if (de->de21040 && ecmd->speed == 2) |
| 1516 | return -EINVAL; |
| 1517 | if (ecmd->duplex != DUPLEX_HALF && ecmd->duplex != DUPLEX_FULL) |
| 1518 | return -EINVAL; |
| 1519 | if (ecmd->port != PORT_TP && ecmd->port != PORT_AUI && ecmd->port != PORT_BNC) |
| 1520 | return -EINVAL; |
| 1521 | if (de->de21040 && ecmd->port == PORT_BNC) |
| 1522 | return -EINVAL; |
| 1523 | if (ecmd->transceiver != XCVR_INTERNAL) |
| 1524 | return -EINVAL; |
| 1525 | if (ecmd->autoneg != AUTONEG_DISABLE && ecmd->autoneg != AUTONEG_ENABLE) |
| 1526 | return -EINVAL; |
| 1527 | if (ecmd->advertising & ~de->media_supported) |
| 1528 | return -EINVAL; |
| 1529 | if (ecmd->autoneg == AUTONEG_ENABLE && |
| 1530 | (!(ecmd->advertising & ADVERTISED_Autoneg))) |
| 1531 | return -EINVAL; |
| 1532 | |
| 1533 | switch (ecmd->port) { |
| 1534 | case PORT_AUI: |
| 1535 | new_media = DE_MEDIA_AUI; |
| 1536 | if (!(ecmd->advertising & ADVERTISED_AUI)) |
| 1537 | return -EINVAL; |
| 1538 | break; |
| 1539 | case PORT_BNC: |
| 1540 | new_media = DE_MEDIA_BNC; |
| 1541 | if (!(ecmd->advertising & ADVERTISED_BNC)) |
| 1542 | return -EINVAL; |
| 1543 | break; |
| 1544 | default: |
| 1545 | if (ecmd->autoneg == AUTONEG_ENABLE) |
| 1546 | new_media = DE_MEDIA_TP_AUTO; |
| 1547 | else if (ecmd->duplex == DUPLEX_FULL) |
| 1548 | new_media = DE_MEDIA_TP_FD; |
| 1549 | else |
| 1550 | new_media = DE_MEDIA_TP; |
| 1551 | if (!(ecmd->advertising & ADVERTISED_TP)) |
| 1552 | return -EINVAL; |
| 1553 | if (!(ecmd->advertising & (ADVERTISED_10baseT_Full | ADVERTISED_10baseT_Half))) |
| 1554 | return -EINVAL; |
| 1555 | break; |
| 1556 | } |
| 1557 | |
| 1558 | media_lock = (ecmd->autoneg == AUTONEG_ENABLE) ? 0 : 1; |
| 1559 | |
| 1560 | if ((new_media == de->media_type) && |
| 1561 | (media_lock == de->media_lock) && |
| 1562 | (ecmd->advertising == de->media_advertise)) |
| 1563 | return 0; /* nothing to change */ |
| 1564 | |
| 1565 | de_link_down(de); |
| 1566 | de_stop_rxtx(de); |
| 1567 | |
| 1568 | de->media_type = new_media; |
| 1569 | de->media_lock = media_lock; |
| 1570 | de->media_advertise = ecmd->advertising; |
| 1571 | de_set_media(de); |
| 1572 | |
| 1573 | return 0; |
| 1574 | } |
| 1575 | |
| 1576 | static void de_get_drvinfo (struct net_device *dev,struct ethtool_drvinfo *info) |
| 1577 | { |
| 1578 | struct de_private *de = dev->priv; |
| 1579 | |
| 1580 | strcpy (info->driver, DRV_NAME); |
| 1581 | strcpy (info->version, DRV_VERSION); |
| 1582 | strcpy (info->bus_info, pci_name(de->pdev)); |
| 1583 | info->eedump_len = DE_EEPROM_SIZE; |
| 1584 | } |
| 1585 | |
| 1586 | static int de_get_regs_len(struct net_device *dev) |
| 1587 | { |
| 1588 | return DE_REGS_SIZE; |
| 1589 | } |
| 1590 | |
| 1591 | static int de_get_settings(struct net_device *dev, struct ethtool_cmd *ecmd) |
| 1592 | { |
| 1593 | struct de_private *de = dev->priv; |
| 1594 | int rc; |
| 1595 | |
| 1596 | spin_lock_irq(&de->lock); |
| 1597 | rc = __de_get_settings(de, ecmd); |
| 1598 | spin_unlock_irq(&de->lock); |
| 1599 | |
| 1600 | return rc; |
| 1601 | } |
| 1602 | |
| 1603 | static int de_set_settings(struct net_device *dev, struct ethtool_cmd *ecmd) |
| 1604 | { |
| 1605 | struct de_private *de = dev->priv; |
| 1606 | int rc; |
| 1607 | |
| 1608 | spin_lock_irq(&de->lock); |
| 1609 | rc = __de_set_settings(de, ecmd); |
| 1610 | spin_unlock_irq(&de->lock); |
| 1611 | |
| 1612 | return rc; |
| 1613 | } |
| 1614 | |
| 1615 | static u32 de_get_msglevel(struct net_device *dev) |
| 1616 | { |
| 1617 | struct de_private *de = dev->priv; |
| 1618 | |
| 1619 | return de->msg_enable; |
| 1620 | } |
| 1621 | |
| 1622 | static void de_set_msglevel(struct net_device *dev, u32 msglvl) |
| 1623 | { |
| 1624 | struct de_private *de = dev->priv; |
| 1625 | |
| 1626 | de->msg_enable = msglvl; |
| 1627 | } |
| 1628 | |
| 1629 | static int de_get_eeprom(struct net_device *dev, |
| 1630 | struct ethtool_eeprom *eeprom, u8 *data) |
| 1631 | { |
| 1632 | struct de_private *de = dev->priv; |
| 1633 | |
| 1634 | if (!de->ee_data) |
| 1635 | return -EOPNOTSUPP; |
| 1636 | if ((eeprom->offset != 0) || (eeprom->magic != 0) || |
| 1637 | (eeprom->len != DE_EEPROM_SIZE)) |
| 1638 | return -EINVAL; |
| 1639 | memcpy(data, de->ee_data, eeprom->len); |
| 1640 | |
| 1641 | return 0; |
| 1642 | } |
| 1643 | |
| 1644 | static int de_nway_reset(struct net_device *dev) |
| 1645 | { |
| 1646 | struct de_private *de = dev->priv; |
| 1647 | u32 status; |
| 1648 | |
| 1649 | if (de->media_type != DE_MEDIA_TP_AUTO) |
| 1650 | return -EINVAL; |
| 1651 | if (netif_carrier_ok(de->dev)) |
| 1652 | de_link_down(de); |
| 1653 | |
| 1654 | status = dr32(SIAStatus); |
| 1655 | dw32(SIAStatus, (status & ~NWayState) | NWayRestart); |
| 1656 | if (netif_msg_link(de)) |
| 1657 | printk(KERN_INFO "%s: link nway restart, status %x,%x\n", |
| 1658 | de->dev->name, status, dr32(SIAStatus)); |
| 1659 | return 0; |
| 1660 | } |
| 1661 | |
| 1662 | static void de_get_regs(struct net_device *dev, struct ethtool_regs *regs, |
| 1663 | void *data) |
| 1664 | { |
| 1665 | struct de_private *de = dev->priv; |
| 1666 | |
| 1667 | regs->version = (DE_REGS_VER << 2) | de->de21040; |
| 1668 | |
| 1669 | spin_lock_irq(&de->lock); |
| 1670 | __de_get_regs(de, data); |
| 1671 | spin_unlock_irq(&de->lock); |
| 1672 | } |
| 1673 | |
| 1674 | static struct ethtool_ops de_ethtool_ops = { |
| 1675 | .get_link = ethtool_op_get_link, |
| 1676 | .get_tx_csum = ethtool_op_get_tx_csum, |
| 1677 | .get_sg = ethtool_op_get_sg, |
| 1678 | .get_drvinfo = de_get_drvinfo, |
| 1679 | .get_regs_len = de_get_regs_len, |
| 1680 | .get_settings = de_get_settings, |
| 1681 | .set_settings = de_set_settings, |
| 1682 | .get_msglevel = de_get_msglevel, |
| 1683 | .set_msglevel = de_set_msglevel, |
| 1684 | .get_eeprom = de_get_eeprom, |
| 1685 | .nway_reset = de_nway_reset, |
| 1686 | .get_regs = de_get_regs, |
| 1687 | }; |
| 1688 | |
| 1689 | static void __init de21040_get_mac_address (struct de_private *de) |
| 1690 | { |
| 1691 | unsigned i; |
| 1692 | |
| 1693 | dw32 (ROMCmd, 0); /* Reset the pointer with a dummy write. */ |
| 1694 | |
| 1695 | for (i = 0; i < 6; i++) { |
| 1696 | int value, boguscnt = 100000; |
| 1697 | do |
| 1698 | value = dr32(ROMCmd); |
| 1699 | while (value < 0 && --boguscnt > 0); |
| 1700 | de->dev->dev_addr[i] = value; |
| 1701 | udelay(1); |
| 1702 | if (boguscnt <= 0) |
| 1703 | printk(KERN_WARNING PFX "timeout reading 21040 MAC address byte %u\n", i); |
| 1704 | } |
| 1705 | } |
| 1706 | |
| 1707 | static void __init de21040_get_media_info(struct de_private *de) |
| 1708 | { |
| 1709 | unsigned int i; |
| 1710 | |
| 1711 | de->media_type = DE_MEDIA_TP; |
| 1712 | de->media_supported |= SUPPORTED_TP | SUPPORTED_10baseT_Full | |
| 1713 | SUPPORTED_10baseT_Half | SUPPORTED_AUI; |
| 1714 | de->media_advertise = de->media_supported; |
| 1715 | |
| 1716 | for (i = 0; i < DE_MAX_MEDIA; i++) { |
| 1717 | switch (i) { |
| 1718 | case DE_MEDIA_AUI: |
| 1719 | case DE_MEDIA_TP: |
| 1720 | case DE_MEDIA_TP_FD: |
| 1721 | de->media[i].type = i; |
| 1722 | de->media[i].csr13 = t21040_csr13[i]; |
| 1723 | de->media[i].csr14 = t21040_csr14[i]; |
| 1724 | de->media[i].csr15 = t21040_csr15[i]; |
| 1725 | break; |
| 1726 | default: |
| 1727 | de->media[i].type = DE_MEDIA_INVALID; |
| 1728 | break; |
| 1729 | } |
| 1730 | } |
| 1731 | } |
| 1732 | |
| 1733 | /* Note: this routine returns extra data bits for size detection. */ |
| 1734 | static unsigned __init tulip_read_eeprom(void __iomem *regs, int location, int addr_len) |
| 1735 | { |
| 1736 | int i; |
| 1737 | unsigned retval = 0; |
| 1738 | void __iomem *ee_addr = regs + ROMCmd; |
| 1739 | int read_cmd = location | (EE_READ_CMD << addr_len); |
| 1740 | |
| 1741 | writel(EE_ENB & ~EE_CS, ee_addr); |
| 1742 | writel(EE_ENB, ee_addr); |
| 1743 | |
| 1744 | /* Shift the read command bits out. */ |
| 1745 | for (i = 4 + addr_len; i >= 0; i--) { |
| 1746 | short dataval = (read_cmd & (1 << i)) ? EE_DATA_WRITE : 0; |
| 1747 | writel(EE_ENB | dataval, ee_addr); |
| 1748 | readl(ee_addr); |
| 1749 | writel(EE_ENB | dataval | EE_SHIFT_CLK, ee_addr); |
| 1750 | readl(ee_addr); |
| 1751 | retval = (retval << 1) | ((readl(ee_addr) & EE_DATA_READ) ? 1 : 0); |
| 1752 | } |
| 1753 | writel(EE_ENB, ee_addr); |
| 1754 | readl(ee_addr); |
| 1755 | |
| 1756 | for (i = 16; i > 0; i--) { |
| 1757 | writel(EE_ENB | EE_SHIFT_CLK, ee_addr); |
| 1758 | readl(ee_addr); |
| 1759 | retval = (retval << 1) | ((readl(ee_addr) & EE_DATA_READ) ? 1 : 0); |
| 1760 | writel(EE_ENB, ee_addr); |
| 1761 | readl(ee_addr); |
| 1762 | } |
| 1763 | |
| 1764 | /* Terminate the EEPROM access. */ |
| 1765 | writel(EE_ENB & ~EE_CS, ee_addr); |
| 1766 | return retval; |
| 1767 | } |
| 1768 | |
| 1769 | static void __init de21041_get_srom_info (struct de_private *de) |
| 1770 | { |
| 1771 | unsigned i, sa_offset = 0, ofs; |
| 1772 | u8 ee_data[DE_EEPROM_SIZE + 6] = {}; |
| 1773 | unsigned ee_addr_size = tulip_read_eeprom(de->regs, 0xff, 8) & 0x40000 ? 8 : 6; |
| 1774 | struct de_srom_info_leaf *il; |
| 1775 | void *bufp; |
| 1776 | |
| 1777 | /* download entire eeprom */ |
| 1778 | for (i = 0; i < DE_EEPROM_WORDS; i++) |
| 1779 | ((u16 *)ee_data)[i] = |
| 1780 | le16_to_cpu(tulip_read_eeprom(de->regs, i, ee_addr_size)); |
| 1781 | |
| 1782 | /* DEC now has a specification but early board makers |
| 1783 | just put the address in the first EEPROM locations. */ |
| 1784 | /* This does memcmp(eedata, eedata+16, 8) */ |
Ralf Baechle | bc053d4 | 2005-10-10 14:50:46 +0100 | [diff] [blame] | 1785 | |
| 1786 | #ifndef CONFIG_MIPS_COBALT |
| 1787 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1788 | for (i = 0; i < 8; i ++) |
| 1789 | if (ee_data[i] != ee_data[16+i]) |
| 1790 | sa_offset = 20; |
| 1791 | |
Ralf Baechle | bc053d4 | 2005-10-10 14:50:46 +0100 | [diff] [blame] | 1792 | #endif |
| 1793 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1794 | /* store MAC address */ |
| 1795 | for (i = 0; i < 6; i ++) |
| 1796 | de->dev->dev_addr[i] = ee_data[i + sa_offset]; |
| 1797 | |
| 1798 | /* get offset of controller 0 info leaf. ignore 2nd byte. */ |
| 1799 | ofs = ee_data[SROMC0InfoLeaf]; |
| 1800 | if (ofs >= (sizeof(ee_data) - sizeof(struct de_srom_info_leaf) - sizeof(struct de_srom_media_block))) |
| 1801 | goto bad_srom; |
| 1802 | |
| 1803 | /* get pointer to info leaf */ |
| 1804 | il = (struct de_srom_info_leaf *) &ee_data[ofs]; |
| 1805 | |
| 1806 | /* paranoia checks */ |
| 1807 | if (il->n_blocks == 0) |
| 1808 | goto bad_srom; |
| 1809 | if ((sizeof(ee_data) - ofs) < |
| 1810 | (sizeof(struct de_srom_info_leaf) + (sizeof(struct de_srom_media_block) * il->n_blocks))) |
| 1811 | goto bad_srom; |
| 1812 | |
| 1813 | /* get default media type */ |
| 1814 | switch (DE_UNALIGNED_16(&il->default_media)) { |
| 1815 | case 0x0001: de->media_type = DE_MEDIA_BNC; break; |
| 1816 | case 0x0002: de->media_type = DE_MEDIA_AUI; break; |
| 1817 | case 0x0204: de->media_type = DE_MEDIA_TP_FD; break; |
| 1818 | default: de->media_type = DE_MEDIA_TP_AUTO; break; |
| 1819 | } |
| 1820 | |
| 1821 | if (netif_msg_probe(de)) |
| 1822 | printk(KERN_INFO "de%d: SROM leaf offset %u, default media %s\n", |
| 1823 | de->board_idx, ofs, |
| 1824 | media_name[de->media_type]); |
| 1825 | |
| 1826 | /* init SIA register values to defaults */ |
| 1827 | for (i = 0; i < DE_MAX_MEDIA; i++) { |
| 1828 | de->media[i].type = DE_MEDIA_INVALID; |
| 1829 | de->media[i].csr13 = 0xffff; |
| 1830 | de->media[i].csr14 = 0xffff; |
| 1831 | de->media[i].csr15 = 0xffff; |
| 1832 | } |
| 1833 | |
| 1834 | /* parse media blocks to see what medias are supported, |
| 1835 | * and if any custom CSR values are provided |
| 1836 | */ |
| 1837 | bufp = ((void *)il) + sizeof(*il); |
| 1838 | for (i = 0; i < il->n_blocks; i++) { |
| 1839 | struct de_srom_media_block *ib = bufp; |
| 1840 | unsigned idx; |
| 1841 | |
| 1842 | /* index based on media type in media block */ |
| 1843 | switch(ib->opts & MediaBlockMask) { |
| 1844 | case 0: /* 10baseT */ |
| 1845 | de->media_supported |= SUPPORTED_TP | SUPPORTED_10baseT_Half |
| 1846 | | SUPPORTED_Autoneg; |
| 1847 | idx = DE_MEDIA_TP; |
| 1848 | de->media[DE_MEDIA_TP_AUTO].type = DE_MEDIA_TP_AUTO; |
| 1849 | break; |
| 1850 | case 1: /* BNC */ |
| 1851 | de->media_supported |= SUPPORTED_BNC; |
| 1852 | idx = DE_MEDIA_BNC; |
| 1853 | break; |
| 1854 | case 2: /* AUI */ |
| 1855 | de->media_supported |= SUPPORTED_AUI; |
| 1856 | idx = DE_MEDIA_AUI; |
| 1857 | break; |
| 1858 | case 4: /* 10baseT-FD */ |
| 1859 | de->media_supported |= SUPPORTED_TP | SUPPORTED_10baseT_Full |
| 1860 | | SUPPORTED_Autoneg; |
| 1861 | idx = DE_MEDIA_TP_FD; |
| 1862 | de->media[DE_MEDIA_TP_AUTO].type = DE_MEDIA_TP_AUTO; |
| 1863 | break; |
| 1864 | default: |
| 1865 | goto bad_srom; |
| 1866 | } |
| 1867 | |
| 1868 | de->media[idx].type = idx; |
| 1869 | |
| 1870 | if (netif_msg_probe(de)) |
| 1871 | printk(KERN_INFO "de%d: media block #%u: %s", |
| 1872 | de->board_idx, i, |
| 1873 | media_name[de->media[idx].type]); |
| 1874 | |
| 1875 | bufp += sizeof (ib->opts); |
| 1876 | |
| 1877 | if (ib->opts & MediaCustomCSRs) { |
| 1878 | de->media[idx].csr13 = DE_UNALIGNED_16(&ib->csr13); |
| 1879 | de->media[idx].csr14 = DE_UNALIGNED_16(&ib->csr14); |
| 1880 | de->media[idx].csr15 = DE_UNALIGNED_16(&ib->csr15); |
| 1881 | bufp += sizeof(ib->csr13) + sizeof(ib->csr14) + |
| 1882 | sizeof(ib->csr15); |
| 1883 | |
| 1884 | if (netif_msg_probe(de)) |
| 1885 | printk(" (%x,%x,%x)\n", |
| 1886 | de->media[idx].csr13, |
| 1887 | de->media[idx].csr14, |
| 1888 | de->media[idx].csr15); |
| 1889 | |
| 1890 | } else if (netif_msg_probe(de)) |
| 1891 | printk("\n"); |
| 1892 | |
| 1893 | if (bufp > ((void *)&ee_data[DE_EEPROM_SIZE - 3])) |
| 1894 | break; |
| 1895 | } |
| 1896 | |
| 1897 | de->media_advertise = de->media_supported; |
| 1898 | |
| 1899 | fill_defaults: |
| 1900 | /* fill in defaults, for cases where custom CSRs not used */ |
| 1901 | for (i = 0; i < DE_MAX_MEDIA; i++) { |
| 1902 | if (de->media[i].csr13 == 0xffff) |
| 1903 | de->media[i].csr13 = t21041_csr13[i]; |
| 1904 | if (de->media[i].csr14 == 0xffff) |
| 1905 | de->media[i].csr14 = t21041_csr14[i]; |
| 1906 | if (de->media[i].csr15 == 0xffff) |
| 1907 | de->media[i].csr15 = t21041_csr15[i]; |
| 1908 | } |
| 1909 | |
| 1910 | de->ee_data = kmalloc(DE_EEPROM_SIZE, GFP_KERNEL); |
| 1911 | if (de->ee_data) |
| 1912 | memcpy(de->ee_data, &ee_data[0], DE_EEPROM_SIZE); |
| 1913 | |
| 1914 | return; |
| 1915 | |
| 1916 | bad_srom: |
| 1917 | /* for error cases, it's ok to assume we support all these */ |
| 1918 | for (i = 0; i < DE_MAX_MEDIA; i++) |
| 1919 | de->media[i].type = i; |
| 1920 | de->media_supported = |
| 1921 | SUPPORTED_10baseT_Half | |
| 1922 | SUPPORTED_10baseT_Full | |
| 1923 | SUPPORTED_Autoneg | |
| 1924 | SUPPORTED_TP | |
| 1925 | SUPPORTED_AUI | |
| 1926 | SUPPORTED_BNC; |
| 1927 | goto fill_defaults; |
| 1928 | } |
| 1929 | |
| 1930 | static int __init de_init_one (struct pci_dev *pdev, |
| 1931 | const struct pci_device_id *ent) |
| 1932 | { |
| 1933 | struct net_device *dev; |
| 1934 | struct de_private *de; |
| 1935 | int rc; |
| 1936 | void __iomem *regs; |
Jeff Garzik | afc7097 | 2005-08-31 06:11:16 -0400 | [diff] [blame] | 1937 | unsigned long pciaddr; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1938 | static int board_idx = -1; |
| 1939 | |
| 1940 | board_idx++; |
| 1941 | |
| 1942 | #ifndef MODULE |
| 1943 | if (board_idx == 0) |
| 1944 | printk("%s", version); |
| 1945 | #endif |
| 1946 | |
| 1947 | /* allocate a new ethernet device structure, and fill in defaults */ |
| 1948 | dev = alloc_etherdev(sizeof(struct de_private)); |
| 1949 | if (!dev) |
| 1950 | return -ENOMEM; |
| 1951 | |
| 1952 | SET_MODULE_OWNER(dev); |
| 1953 | SET_NETDEV_DEV(dev, &pdev->dev); |
| 1954 | dev->open = de_open; |
| 1955 | dev->stop = de_close; |
| 1956 | dev->set_multicast_list = de_set_rx_mode; |
| 1957 | dev->hard_start_xmit = de_start_xmit; |
| 1958 | dev->get_stats = de_get_stats; |
| 1959 | dev->ethtool_ops = &de_ethtool_ops; |
| 1960 | dev->tx_timeout = de_tx_timeout; |
| 1961 | dev->watchdog_timeo = TX_TIMEOUT; |
| 1962 | |
| 1963 | de = dev->priv; |
| 1964 | de->de21040 = ent->driver_data == 0 ? 1 : 0; |
| 1965 | de->pdev = pdev; |
| 1966 | de->dev = dev; |
| 1967 | de->msg_enable = (debug < 0 ? DE_DEF_MSG_ENABLE : debug); |
| 1968 | de->board_idx = board_idx; |
| 1969 | spin_lock_init (&de->lock); |
| 1970 | init_timer(&de->media_timer); |
| 1971 | if (de->de21040) |
| 1972 | de->media_timer.function = de21040_media_timer; |
| 1973 | else |
| 1974 | de->media_timer.function = de21041_media_timer; |
| 1975 | de->media_timer.data = (unsigned long) de; |
| 1976 | |
| 1977 | netif_carrier_off(dev); |
| 1978 | netif_stop_queue(dev); |
| 1979 | |
| 1980 | /* wake up device, assign resources */ |
| 1981 | rc = pci_enable_device(pdev); |
| 1982 | if (rc) |
| 1983 | goto err_out_free; |
| 1984 | |
| 1985 | /* reserve PCI resources to ensure driver atomicity */ |
| 1986 | rc = pci_request_regions(pdev, DRV_NAME); |
| 1987 | if (rc) |
| 1988 | goto err_out_disable; |
| 1989 | |
| 1990 | /* check for invalid IRQ value */ |
| 1991 | if (pdev->irq < 2) { |
| 1992 | rc = -EIO; |
| 1993 | printk(KERN_ERR PFX "invalid irq (%d) for pci dev %s\n", |
| 1994 | pdev->irq, pci_name(pdev)); |
| 1995 | goto err_out_res; |
| 1996 | } |
| 1997 | |
| 1998 | dev->irq = pdev->irq; |
| 1999 | |
| 2000 | /* obtain and check validity of PCI I/O address */ |
| 2001 | pciaddr = pci_resource_start(pdev, 1); |
| 2002 | if (!pciaddr) { |
| 2003 | rc = -EIO; |
| 2004 | printk(KERN_ERR PFX "no MMIO resource for pci dev %s\n", |
| 2005 | pci_name(pdev)); |
| 2006 | goto err_out_res; |
| 2007 | } |
| 2008 | if (pci_resource_len(pdev, 1) < DE_REGS_SIZE) { |
| 2009 | rc = -EIO; |
| 2010 | printk(KERN_ERR PFX "MMIO resource (%lx) too small on pci dev %s\n", |
| 2011 | pci_resource_len(pdev, 1), pci_name(pdev)); |
| 2012 | goto err_out_res; |
| 2013 | } |
| 2014 | |
| 2015 | /* remap CSR registers */ |
| 2016 | regs = ioremap_nocache(pciaddr, DE_REGS_SIZE); |
| 2017 | if (!regs) { |
| 2018 | rc = -EIO; |
| 2019 | printk(KERN_ERR PFX "Cannot map PCI MMIO (%lx@%lx) on pci dev %s\n", |
| 2020 | pci_resource_len(pdev, 1), pciaddr, pci_name(pdev)); |
| 2021 | goto err_out_res; |
| 2022 | } |
| 2023 | dev->base_addr = (unsigned long) regs; |
| 2024 | de->regs = regs; |
| 2025 | |
| 2026 | de_adapter_wake(de); |
| 2027 | |
| 2028 | /* make sure hardware is not running */ |
| 2029 | rc = de_reset_mac(de); |
| 2030 | if (rc) { |
| 2031 | printk(KERN_ERR PFX "Cannot reset MAC, pci dev %s\n", |
| 2032 | pci_name(pdev)); |
| 2033 | goto err_out_iomap; |
| 2034 | } |
| 2035 | |
| 2036 | /* get MAC address, initialize default media type and |
| 2037 | * get list of supported media |
| 2038 | */ |
| 2039 | if (de->de21040) { |
| 2040 | de21040_get_mac_address(de); |
| 2041 | de21040_get_media_info(de); |
| 2042 | } else { |
| 2043 | de21041_get_srom_info(de); |
| 2044 | } |
| 2045 | |
| 2046 | /* register new network interface with kernel */ |
| 2047 | rc = register_netdev(dev); |
| 2048 | if (rc) |
| 2049 | goto err_out_iomap; |
| 2050 | |
| 2051 | /* print info about board and interface just registered */ |
| 2052 | printk (KERN_INFO "%s: %s at 0x%lx, " |
| 2053 | "%02x:%02x:%02x:%02x:%02x:%02x, " |
| 2054 | "IRQ %d\n", |
| 2055 | dev->name, |
| 2056 | de->de21040 ? "21040" : "21041", |
| 2057 | dev->base_addr, |
| 2058 | dev->dev_addr[0], dev->dev_addr[1], |
| 2059 | dev->dev_addr[2], dev->dev_addr[3], |
| 2060 | dev->dev_addr[4], dev->dev_addr[5], |
| 2061 | dev->irq); |
| 2062 | |
| 2063 | pci_set_drvdata(pdev, dev); |
| 2064 | |
| 2065 | /* enable busmastering */ |
| 2066 | pci_set_master(pdev); |
| 2067 | |
| 2068 | /* put adapter to sleep */ |
| 2069 | de_adapter_sleep(de); |
| 2070 | |
| 2071 | return 0; |
| 2072 | |
| 2073 | err_out_iomap: |
Jesper Juhl | b4558ea | 2005-10-28 16:53:13 -0400 | [diff] [blame] | 2074 | kfree(de->ee_data); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2075 | iounmap(regs); |
| 2076 | err_out_res: |
| 2077 | pci_release_regions(pdev); |
| 2078 | err_out_disable: |
| 2079 | pci_disable_device(pdev); |
| 2080 | err_out_free: |
| 2081 | free_netdev(dev); |
| 2082 | return rc; |
| 2083 | } |
| 2084 | |
| 2085 | static void __exit de_remove_one (struct pci_dev *pdev) |
| 2086 | { |
| 2087 | struct net_device *dev = pci_get_drvdata(pdev); |
| 2088 | struct de_private *de = dev->priv; |
| 2089 | |
Eric Sesterhenn / snakebyte | 7e0b58f | 2006-01-26 22:02:43 +0100 | [diff] [blame^] | 2090 | BUG_ON(!dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2091 | unregister_netdev(dev); |
Jesper Juhl | b4558ea | 2005-10-28 16:53:13 -0400 | [diff] [blame] | 2092 | kfree(de->ee_data); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2093 | iounmap(de->regs); |
| 2094 | pci_release_regions(pdev); |
| 2095 | pci_disable_device(pdev); |
| 2096 | pci_set_drvdata(pdev, NULL); |
| 2097 | free_netdev(dev); |
| 2098 | } |
| 2099 | |
| 2100 | #ifdef CONFIG_PM |
| 2101 | |
Pavel Machek | 05adc3b | 2005-04-16 15:25:25 -0700 | [diff] [blame] | 2102 | static int de_suspend (struct pci_dev *pdev, pm_message_t state) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2103 | { |
| 2104 | struct net_device *dev = pci_get_drvdata (pdev); |
| 2105 | struct de_private *de = dev->priv; |
| 2106 | |
| 2107 | rtnl_lock(); |
| 2108 | if (netif_running (dev)) { |
| 2109 | del_timer_sync(&de->media_timer); |
| 2110 | |
| 2111 | disable_irq(dev->irq); |
| 2112 | spin_lock_irq(&de->lock); |
| 2113 | |
| 2114 | de_stop_hw(de); |
| 2115 | netif_stop_queue(dev); |
| 2116 | netif_device_detach(dev); |
| 2117 | netif_carrier_off(dev); |
| 2118 | |
| 2119 | spin_unlock_irq(&de->lock); |
| 2120 | enable_irq(dev->irq); |
| 2121 | |
| 2122 | /* Update the error counts. */ |
| 2123 | __de_get_stats(de); |
| 2124 | |
| 2125 | synchronize_irq(dev->irq); |
| 2126 | de_clean_rings(de); |
| 2127 | |
| 2128 | de_adapter_sleep(de); |
| 2129 | pci_disable_device(pdev); |
| 2130 | } else { |
| 2131 | netif_device_detach(dev); |
| 2132 | } |
| 2133 | rtnl_unlock(); |
| 2134 | return 0; |
| 2135 | } |
| 2136 | |
| 2137 | static int de_resume (struct pci_dev *pdev) |
| 2138 | { |
| 2139 | struct net_device *dev = pci_get_drvdata (pdev); |
| 2140 | struct de_private *de = dev->priv; |
| 2141 | |
| 2142 | rtnl_lock(); |
| 2143 | if (netif_device_present(dev)) |
| 2144 | goto out; |
| 2145 | if (netif_running(dev)) { |
| 2146 | pci_enable_device(pdev); |
| 2147 | de_init_hw(de); |
| 2148 | netif_device_attach(dev); |
| 2149 | } else { |
| 2150 | netif_device_attach(dev); |
| 2151 | } |
| 2152 | out: |
| 2153 | rtnl_unlock(); |
| 2154 | return 0; |
| 2155 | } |
| 2156 | |
| 2157 | #endif /* CONFIG_PM */ |
| 2158 | |
| 2159 | static struct pci_driver de_driver = { |
| 2160 | .name = DRV_NAME, |
| 2161 | .id_table = de_pci_tbl, |
| 2162 | .probe = de_init_one, |
| 2163 | .remove = __exit_p(de_remove_one), |
| 2164 | #ifdef CONFIG_PM |
| 2165 | .suspend = de_suspend, |
| 2166 | .resume = de_resume, |
| 2167 | #endif |
| 2168 | }; |
| 2169 | |
| 2170 | static int __init de_init (void) |
| 2171 | { |
| 2172 | #ifdef MODULE |
| 2173 | printk("%s", version); |
| 2174 | #endif |
| 2175 | return pci_module_init (&de_driver); |
| 2176 | } |
| 2177 | |
| 2178 | static void __exit de_exit (void) |
| 2179 | { |
| 2180 | pci_unregister_driver (&de_driver); |
| 2181 | } |
| 2182 | |
| 2183 | module_init(de_init); |
| 2184 | module_exit(de_exit); |