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