Sascha Hauer | a136527 | 2005-05-05 15:14:15 -0700 | [diff] [blame] | 1 | /* |
Ben Dooks | 41c340f | 2008-02-05 00:02:15 +0000 | [diff] [blame] | 2 | * Davicom DM9000 Fast Ethernet driver for Linux. |
Sascha Hauer | a136527 | 2005-05-05 15:14:15 -0700 | [diff] [blame] | 3 | * Copyright (C) 1997 Sten Wang |
| 4 | * |
| 5 | * This program is free software; you can redistribute it and/or |
| 6 | * modify it under the terms of the GNU General Public License |
| 7 | * as published by the Free Software Foundation; either version 2 |
| 8 | * of the License, or (at your option) any later version. |
| 9 | * |
| 10 | * This program is distributed in the hope that it will be useful, |
| 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 13 | * GNU General Public License for more details. |
| 14 | * |
Ben Dooks | 41c340f | 2008-02-05 00:02:15 +0000 | [diff] [blame] | 15 | * (C) Copyright 1997-1998 DAVICOM Semiconductor,Inc. All Rights Reserved. |
Sascha Hauer | a136527 | 2005-05-05 15:14:15 -0700 | [diff] [blame] | 16 | * |
Ben Dooks | 41c340f | 2008-02-05 00:02:15 +0000 | [diff] [blame] | 17 | * Additional updates, Copyright: |
| 18 | * Ben Dooks <ben@simtec.co.uk> |
| 19 | * Sascha Hauer <s.hauer@pengutronix.de> |
Sascha Hauer | a136527 | 2005-05-05 15:14:15 -0700 | [diff] [blame] | 20 | */ |
| 21 | |
| 22 | #include <linux/module.h> |
| 23 | #include <linux/ioport.h> |
| 24 | #include <linux/netdevice.h> |
| 25 | #include <linux/etherdevice.h> |
| 26 | #include <linux/init.h> |
| 27 | #include <linux/skbuff.h> |
Sascha Hauer | a136527 | 2005-05-05 15:14:15 -0700 | [diff] [blame] | 28 | #include <linux/spinlock.h> |
| 29 | #include <linux/crc32.h> |
| 30 | #include <linux/mii.h> |
Ben Dooks | 7da9985 | 2008-02-05 00:02:06 +0000 | [diff] [blame] | 31 | #include <linux/ethtool.h> |
Sascha Hauer | a136527 | 2005-05-05 15:14:15 -0700 | [diff] [blame] | 32 | #include <linux/dm9000.h> |
| 33 | #include <linux/delay.h> |
Russell King | d052d1b | 2005-10-29 19:07:23 +0100 | [diff] [blame] | 34 | #include <linux/platform_device.h> |
Daniel Mack | 4e4fc05 | 2008-01-23 14:54:50 +0100 | [diff] [blame] | 35 | #include <linux/irq.h> |
Sascha Hauer | a136527 | 2005-05-05 15:14:15 -0700 | [diff] [blame] | 36 | |
| 37 | #include <asm/delay.h> |
| 38 | #include <asm/irq.h> |
| 39 | #include <asm/io.h> |
| 40 | |
| 41 | #include "dm9000.h" |
| 42 | |
| 43 | /* Board/System/Debug information/definition ---------------- */ |
| 44 | |
| 45 | #define DM9000_PHY 0x40 /* PHY address 0x01 */ |
| 46 | |
Ben Dooks | 59eae1f | 2008-06-24 22:16:01 +0100 | [diff] [blame] | 47 | #define CARDNAME "dm9000" |
| 48 | #define DRV_VERSION "1.31" |
Sascha Hauer | a136527 | 2005-05-05 15:14:15 -0700 | [diff] [blame] | 49 | |
Sascha Hauer | a136527 | 2005-05-05 15:14:15 -0700 | [diff] [blame] | 50 | /* |
| 51 | * Transmit timeout, default 5 seconds. |
| 52 | */ |
| 53 | static int watchdog = 5000; |
| 54 | module_param(watchdog, int, 0400); |
| 55 | MODULE_PARM_DESC(watchdog, "transmit timeout in milliseconds"); |
| 56 | |
Ben Dooks | 9a2f037 | 2008-02-05 00:02:10 +0000 | [diff] [blame] | 57 | /* DM9000 register address locking. |
| 58 | * |
| 59 | * The DM9000 uses an address register to control where data written |
| 60 | * to the data register goes. This means that the address register |
| 61 | * must be preserved over interrupts or similar calls. |
| 62 | * |
| 63 | * During interrupt and other critical calls, a spinlock is used to |
| 64 | * protect the system, but the calls themselves save the address |
| 65 | * in the address register in case they are interrupting another |
| 66 | * access to the device. |
| 67 | * |
| 68 | * For general accesses a lock is provided so that calls which are |
| 69 | * allowed to sleep are serialised so that the address register does |
| 70 | * not need to be saved. This lock also serves to serialise access |
| 71 | * to the EEPROM and PHY access registers which are shared between |
| 72 | * these two devices. |
| 73 | */ |
| 74 | |
Ben Dooks | 6d406b3 | 2008-06-24 22:15:59 +0100 | [diff] [blame] | 75 | /* The driver supports the original DM9000E, and now the two newer |
| 76 | * devices, DM9000A and DM9000B. |
| 77 | */ |
| 78 | |
| 79 | enum dm9000_type { |
| 80 | TYPE_DM9000E, /* original DM9000 */ |
| 81 | TYPE_DM9000A, |
| 82 | TYPE_DM9000B |
| 83 | }; |
| 84 | |
Sascha Hauer | a136527 | 2005-05-05 15:14:15 -0700 | [diff] [blame] | 85 | /* Structure/enum declaration ------------------------------- */ |
| 86 | typedef struct board_info { |
| 87 | |
Ben Dooks | 59eae1f | 2008-06-24 22:16:01 +0100 | [diff] [blame] | 88 | void __iomem *io_addr; /* Register I/O base address */ |
| 89 | void __iomem *io_data; /* Data I/O address */ |
| 90 | u16 irq; /* IRQ */ |
Sascha Hauer | a136527 | 2005-05-05 15:14:15 -0700 | [diff] [blame] | 91 | |
Ben Dooks | 59eae1f | 2008-06-24 22:16:01 +0100 | [diff] [blame] | 92 | u16 tx_pkt_cnt; |
| 93 | u16 queue_pkt_len; |
| 94 | u16 queue_start_addr; |
Yeasah Pell | 5dcc60b | 2009-07-06 18:12:33 -0700 | [diff] [blame] | 95 | u16 queue_ip_summed; |
Ben Dooks | 59eae1f | 2008-06-24 22:16:01 +0100 | [diff] [blame] | 96 | u16 dbug_cnt; |
| 97 | u8 io_mode; /* 0:word, 2:byte */ |
| 98 | u8 phy_addr; |
| 99 | u8 imr_all; |
| 100 | |
| 101 | unsigned int flags; |
| 102 | unsigned int in_suspend :1; |
Ben Dooks | c029f44 | 2009-11-10 07:22:24 +0000 | [diff] [blame] | 103 | unsigned int wake_supported :1; |
Ben Dooks | 59eae1f | 2008-06-24 22:16:01 +0100 | [diff] [blame] | 104 | int debug_level; |
Sascha Hauer | a136527 | 2005-05-05 15:14:15 -0700 | [diff] [blame] | 105 | |
Ben Dooks | 6d406b3 | 2008-06-24 22:15:59 +0100 | [diff] [blame] | 106 | enum dm9000_type type; |
Ben Dooks | 5b2b4ff | 2008-02-05 00:02:03 +0000 | [diff] [blame] | 107 | |
Sascha Hauer | a136527 | 2005-05-05 15:14:15 -0700 | [diff] [blame] | 108 | void (*inblk)(void __iomem *port, void *data, int length); |
| 109 | void (*outblk)(void __iomem *port, void *data, int length); |
| 110 | void (*dumpblk)(void __iomem *port, int length); |
| 111 | |
Ben Dooks | a76836f | 2008-02-05 00:02:02 +0000 | [diff] [blame] | 112 | struct device *dev; /* parent device */ |
| 113 | |
Sascha Hauer | a136527 | 2005-05-05 15:14:15 -0700 | [diff] [blame] | 114 | struct resource *addr_res; /* resources found */ |
| 115 | struct resource *data_res; |
| 116 | struct resource *addr_req; /* resources requested */ |
| 117 | struct resource *data_req; |
| 118 | struct resource *irq_res; |
| 119 | |
Ben Dooks | c029f44 | 2009-11-10 07:22:24 +0000 | [diff] [blame] | 120 | int irq_wake; |
| 121 | |
Ben Dooks | 9a2f037 | 2008-02-05 00:02:10 +0000 | [diff] [blame] | 122 | struct mutex addr_lock; /* phy and eeprom access lock */ |
| 123 | |
Ben Dooks | 8f5bf5f2 | 2008-05-08 11:36:42 +0100 | [diff] [blame] | 124 | struct delayed_work phy_poll; |
| 125 | struct net_device *ndev; |
| 126 | |
Ben Dooks | 59eae1f | 2008-06-24 22:16:01 +0100 | [diff] [blame] | 127 | spinlock_t lock; |
Sascha Hauer | a136527 | 2005-05-05 15:14:15 -0700 | [diff] [blame] | 128 | |
| 129 | struct mii_if_info mii; |
Ben Dooks | 59eae1f | 2008-06-24 22:16:01 +0100 | [diff] [blame] | 130 | u32 msg_enable; |
Ben Dooks | c029f44 | 2009-11-10 07:22:24 +0000 | [diff] [blame] | 131 | u32 wake_state; |
Yeasah Pell | 5dcc60b | 2009-07-06 18:12:33 -0700 | [diff] [blame] | 132 | |
| 133 | int rx_csum; |
| 134 | int can_csum; |
| 135 | int ip_summed; |
Sascha Hauer | a136527 | 2005-05-05 15:14:15 -0700 | [diff] [blame] | 136 | } board_info_t; |
| 137 | |
Ben Dooks | 5b2b4ff | 2008-02-05 00:02:03 +0000 | [diff] [blame] | 138 | /* debug code */ |
| 139 | |
| 140 | #define dm9000_dbg(db, lev, msg...) do { \ |
| 141 | if ((lev) < CONFIG_DM9000_DEBUGLEVEL && \ |
| 142 | (lev) < db->debug_level) { \ |
| 143 | dev_dbg(db->dev, msg); \ |
| 144 | } \ |
| 145 | } while (0) |
| 146 | |
Ben Dooks | 7da9985 | 2008-02-05 00:02:06 +0000 | [diff] [blame] | 147 | static inline board_info_t *to_dm9000_board(struct net_device *dev) |
| 148 | { |
Wang Chen | 4cf1653 | 2008-11-12 23:38:14 -0800 | [diff] [blame] | 149 | return netdev_priv(dev); |
Ben Dooks | 7da9985 | 2008-02-05 00:02:06 +0000 | [diff] [blame] | 150 | } |
| 151 | |
Sascha Hauer | a136527 | 2005-05-05 15:14:15 -0700 | [diff] [blame] | 152 | /* DM9000 network board routine ---------------------------- */ |
| 153 | |
| 154 | static void |
| 155 | dm9000_reset(board_info_t * db) |
| 156 | { |
Ben Dooks | a76836f | 2008-02-05 00:02:02 +0000 | [diff] [blame] | 157 | dev_dbg(db->dev, "resetting device\n"); |
| 158 | |
Sascha Hauer | a136527 | 2005-05-05 15:14:15 -0700 | [diff] [blame] | 159 | /* RESET device */ |
| 160 | writeb(DM9000_NCR, db->io_addr); |
| 161 | udelay(200); |
| 162 | writeb(NCR_RST, db->io_data); |
| 163 | udelay(200); |
| 164 | } |
| 165 | |
| 166 | /* |
| 167 | * Read a byte from I/O port |
| 168 | */ |
| 169 | static u8 |
| 170 | ior(board_info_t * db, int reg) |
| 171 | { |
| 172 | writeb(reg, db->io_addr); |
| 173 | return readb(db->io_data); |
| 174 | } |
| 175 | |
| 176 | /* |
| 177 | * Write a byte to I/O port |
| 178 | */ |
| 179 | |
| 180 | static void |
| 181 | iow(board_info_t * db, int reg, int value) |
| 182 | { |
| 183 | writeb(reg, db->io_addr); |
| 184 | writeb(value, db->io_data); |
| 185 | } |
| 186 | |
| 187 | /* routines for sending block to chip */ |
| 188 | |
| 189 | static void dm9000_outblk_8bit(void __iomem *reg, void *data, int count) |
| 190 | { |
| 191 | writesb(reg, data, count); |
| 192 | } |
| 193 | |
| 194 | static void dm9000_outblk_16bit(void __iomem *reg, void *data, int count) |
| 195 | { |
| 196 | writesw(reg, data, (count+1) >> 1); |
| 197 | } |
| 198 | |
| 199 | static void dm9000_outblk_32bit(void __iomem *reg, void *data, int count) |
| 200 | { |
| 201 | writesl(reg, data, (count+3) >> 2); |
| 202 | } |
| 203 | |
| 204 | /* input block from chip to memory */ |
| 205 | |
| 206 | static void dm9000_inblk_8bit(void __iomem *reg, void *data, int count) |
| 207 | { |
Sascha Hauer | 5f6b551 | 2005-06-20 15:32:51 -0700 | [diff] [blame] | 208 | readsb(reg, data, count); |
Sascha Hauer | a136527 | 2005-05-05 15:14:15 -0700 | [diff] [blame] | 209 | } |
| 210 | |
| 211 | |
| 212 | static void dm9000_inblk_16bit(void __iomem *reg, void *data, int count) |
| 213 | { |
| 214 | readsw(reg, data, (count+1) >> 1); |
| 215 | } |
| 216 | |
| 217 | static void dm9000_inblk_32bit(void __iomem *reg, void *data, int count) |
| 218 | { |
| 219 | readsl(reg, data, (count+3) >> 2); |
| 220 | } |
| 221 | |
| 222 | /* dump block from chip to null */ |
| 223 | |
| 224 | static void dm9000_dumpblk_8bit(void __iomem *reg, int count) |
| 225 | { |
| 226 | int i; |
| 227 | int tmp; |
| 228 | |
| 229 | for (i = 0; i < count; i++) |
| 230 | tmp = readb(reg); |
| 231 | } |
| 232 | |
| 233 | static void dm9000_dumpblk_16bit(void __iomem *reg, int count) |
| 234 | { |
| 235 | int i; |
| 236 | int tmp; |
| 237 | |
| 238 | count = (count + 1) >> 1; |
| 239 | |
| 240 | for (i = 0; i < count; i++) |
| 241 | tmp = readw(reg); |
| 242 | } |
| 243 | |
| 244 | static void dm9000_dumpblk_32bit(void __iomem *reg, int count) |
| 245 | { |
| 246 | int i; |
| 247 | int tmp; |
| 248 | |
| 249 | count = (count + 3) >> 2; |
| 250 | |
| 251 | for (i = 0; i < count; i++) |
| 252 | tmp = readl(reg); |
| 253 | } |
| 254 | |
| 255 | /* dm9000_set_io |
| 256 | * |
| 257 | * select the specified set of io routines to use with the |
| 258 | * device |
| 259 | */ |
| 260 | |
| 261 | static void dm9000_set_io(struct board_info *db, int byte_width) |
| 262 | { |
| 263 | /* use the size of the data resource to work out what IO |
| 264 | * routines we want to use |
| 265 | */ |
| 266 | |
| 267 | switch (byte_width) { |
| 268 | case 1: |
| 269 | db->dumpblk = dm9000_dumpblk_8bit; |
| 270 | db->outblk = dm9000_outblk_8bit; |
| 271 | db->inblk = dm9000_inblk_8bit; |
| 272 | break; |
| 273 | |
Sascha Hauer | a136527 | 2005-05-05 15:14:15 -0700 | [diff] [blame] | 274 | |
| 275 | case 3: |
Ben Dooks | a76836f | 2008-02-05 00:02:02 +0000 | [diff] [blame] | 276 | dev_dbg(db->dev, ": 3 byte IO, falling back to 16bit\n"); |
| 277 | case 2: |
Sascha Hauer | a136527 | 2005-05-05 15:14:15 -0700 | [diff] [blame] | 278 | db->dumpblk = dm9000_dumpblk_16bit; |
| 279 | db->outblk = dm9000_outblk_16bit; |
| 280 | db->inblk = dm9000_inblk_16bit; |
| 281 | break; |
| 282 | |
| 283 | case 4: |
| 284 | default: |
| 285 | db->dumpblk = dm9000_dumpblk_32bit; |
| 286 | db->outblk = dm9000_outblk_32bit; |
| 287 | db->inblk = dm9000_inblk_32bit; |
| 288 | break; |
| 289 | } |
| 290 | } |
| 291 | |
Ben Dooks | 8f5bf5f2 | 2008-05-08 11:36:42 +0100 | [diff] [blame] | 292 | static void dm9000_schedule_poll(board_info_t *db) |
| 293 | { |
Ben Dooks | 6d406b3 | 2008-06-24 22:15:59 +0100 | [diff] [blame] | 294 | if (db->type == TYPE_DM9000E) |
| 295 | schedule_delayed_work(&db->phy_poll, HZ * 2); |
Ben Dooks | 8f5bf5f2 | 2008-05-08 11:36:42 +0100 | [diff] [blame] | 296 | } |
Sascha Hauer | a136527 | 2005-05-05 15:14:15 -0700 | [diff] [blame] | 297 | |
Ben Dooks | f42d8ae | 2008-02-05 00:02:21 +0000 | [diff] [blame] | 298 | static int dm9000_ioctl(struct net_device *dev, struct ifreq *req, int cmd) |
| 299 | { |
| 300 | board_info_t *dm = to_dm9000_board(dev); |
| 301 | |
| 302 | if (!netif_running(dev)) |
| 303 | return -EINVAL; |
| 304 | |
| 305 | return generic_mii_ioctl(&dm->mii, if_mii(req), cmd, NULL); |
| 306 | } |
| 307 | |
Ben Dooks | f8d79e7 | 2008-06-24 22:16:02 +0100 | [diff] [blame] | 308 | static unsigned int |
| 309 | dm9000_read_locked(board_info_t *db, int reg) |
| 310 | { |
| 311 | unsigned long flags; |
| 312 | unsigned int ret; |
| 313 | |
| 314 | spin_lock_irqsave(&db->lock, flags); |
| 315 | ret = ior(db, reg); |
| 316 | spin_unlock_irqrestore(&db->lock, flags); |
| 317 | |
| 318 | return ret; |
| 319 | } |
| 320 | |
| 321 | static int dm9000_wait_eeprom(board_info_t *db) |
| 322 | { |
| 323 | unsigned int status; |
| 324 | int timeout = 8; /* wait max 8msec */ |
| 325 | |
| 326 | /* The DM9000 data sheets say we should be able to |
| 327 | * poll the ERRE bit in EPCR to wait for the EEPROM |
| 328 | * operation. From testing several chips, this bit |
| 329 | * does not seem to work. |
| 330 | * |
| 331 | * We attempt to use the bit, but fall back to the |
| 332 | * timeout (which is why we do not return an error |
| 333 | * on expiry) to say that the EEPROM operation has |
| 334 | * completed. |
| 335 | */ |
| 336 | |
| 337 | while (1) { |
| 338 | status = dm9000_read_locked(db, DM9000_EPCR); |
| 339 | |
| 340 | if ((status & EPCR_ERRE) == 0) |
| 341 | break; |
| 342 | |
Ben Dooks | 2fcf06c | 2008-06-24 22:16:05 +0100 | [diff] [blame] | 343 | msleep(1); |
| 344 | |
Ben Dooks | f8d79e7 | 2008-06-24 22:16:02 +0100 | [diff] [blame] | 345 | if (timeout-- < 0) { |
| 346 | dev_dbg(db->dev, "timeout waiting EEPROM\n"); |
| 347 | break; |
| 348 | } |
| 349 | } |
| 350 | |
| 351 | return 0; |
| 352 | } |
| 353 | |
| 354 | /* |
| 355 | * Read a word data from EEPROM |
| 356 | */ |
| 357 | static void |
| 358 | dm9000_read_eeprom(board_info_t *db, int offset, u8 *to) |
| 359 | { |
| 360 | unsigned long flags; |
| 361 | |
| 362 | if (db->flags & DM9000_PLATF_NO_EEPROM) { |
| 363 | to[0] = 0xff; |
| 364 | to[1] = 0xff; |
| 365 | return; |
| 366 | } |
| 367 | |
| 368 | mutex_lock(&db->addr_lock); |
| 369 | |
| 370 | spin_lock_irqsave(&db->lock, flags); |
| 371 | |
| 372 | iow(db, DM9000_EPAR, offset); |
| 373 | iow(db, DM9000_EPCR, EPCR_ERPRR); |
| 374 | |
| 375 | spin_unlock_irqrestore(&db->lock, flags); |
| 376 | |
| 377 | dm9000_wait_eeprom(db); |
| 378 | |
| 379 | /* delay for at-least 150uS */ |
| 380 | msleep(1); |
| 381 | |
| 382 | spin_lock_irqsave(&db->lock, flags); |
| 383 | |
| 384 | iow(db, DM9000_EPCR, 0x0); |
| 385 | |
| 386 | to[0] = ior(db, DM9000_EPDRL); |
| 387 | to[1] = ior(db, DM9000_EPDRH); |
| 388 | |
| 389 | spin_unlock_irqrestore(&db->lock, flags); |
| 390 | |
| 391 | mutex_unlock(&db->addr_lock); |
| 392 | } |
| 393 | |
| 394 | /* |
| 395 | * Write a word data to SROM |
| 396 | */ |
| 397 | static void |
| 398 | dm9000_write_eeprom(board_info_t *db, int offset, u8 *data) |
| 399 | { |
| 400 | unsigned long flags; |
| 401 | |
| 402 | if (db->flags & DM9000_PLATF_NO_EEPROM) |
| 403 | return; |
| 404 | |
| 405 | mutex_lock(&db->addr_lock); |
| 406 | |
| 407 | spin_lock_irqsave(&db->lock, flags); |
| 408 | iow(db, DM9000_EPAR, offset); |
| 409 | iow(db, DM9000_EPDRH, data[1]); |
| 410 | iow(db, DM9000_EPDRL, data[0]); |
| 411 | iow(db, DM9000_EPCR, EPCR_WEP | EPCR_ERPRW); |
| 412 | spin_unlock_irqrestore(&db->lock, flags); |
| 413 | |
| 414 | dm9000_wait_eeprom(db); |
| 415 | |
| 416 | mdelay(1); /* wait at least 150uS to clear */ |
| 417 | |
| 418 | spin_lock_irqsave(&db->lock, flags); |
| 419 | iow(db, DM9000_EPCR, 0); |
| 420 | spin_unlock_irqrestore(&db->lock, flags); |
| 421 | |
| 422 | mutex_unlock(&db->addr_lock); |
| 423 | } |
| 424 | |
Ben Dooks | 7da9985 | 2008-02-05 00:02:06 +0000 | [diff] [blame] | 425 | /* ethtool ops */ |
| 426 | |
| 427 | static void dm9000_get_drvinfo(struct net_device *dev, |
| 428 | struct ethtool_drvinfo *info) |
| 429 | { |
| 430 | board_info_t *dm = to_dm9000_board(dev); |
| 431 | |
| 432 | strcpy(info->driver, CARDNAME); |
| 433 | strcpy(info->version, DRV_VERSION); |
| 434 | strcpy(info->bus_info, to_platform_device(dm->dev)->name); |
| 435 | } |
| 436 | |
Ben Dooks | e662ee0 | 2008-02-05 00:02:12 +0000 | [diff] [blame] | 437 | static u32 dm9000_get_msglevel(struct net_device *dev) |
| 438 | { |
| 439 | board_info_t *dm = to_dm9000_board(dev); |
| 440 | |
| 441 | return dm->msg_enable; |
| 442 | } |
| 443 | |
| 444 | static void dm9000_set_msglevel(struct net_device *dev, u32 value) |
| 445 | { |
| 446 | board_info_t *dm = to_dm9000_board(dev); |
| 447 | |
| 448 | dm->msg_enable = value; |
| 449 | } |
| 450 | |
Ben Dooks | 7da9985 | 2008-02-05 00:02:06 +0000 | [diff] [blame] | 451 | static int dm9000_get_settings(struct net_device *dev, struct ethtool_cmd *cmd) |
| 452 | { |
| 453 | board_info_t *dm = to_dm9000_board(dev); |
Ben Dooks | 7da9985 | 2008-02-05 00:02:06 +0000 | [diff] [blame] | 454 | |
Ben Dooks | 7da9985 | 2008-02-05 00:02:06 +0000 | [diff] [blame] | 455 | mii_ethtool_gset(&dm->mii, cmd); |
Ben Dooks | 7da9985 | 2008-02-05 00:02:06 +0000 | [diff] [blame] | 456 | return 0; |
| 457 | } |
| 458 | |
| 459 | static int dm9000_set_settings(struct net_device *dev, struct ethtool_cmd *cmd) |
| 460 | { |
| 461 | board_info_t *dm = to_dm9000_board(dev); |
Ben Dooks | 7da9985 | 2008-02-05 00:02:06 +0000 | [diff] [blame] | 462 | |
Ben Dooks | 9a2f037 | 2008-02-05 00:02:10 +0000 | [diff] [blame] | 463 | return mii_ethtool_sset(&dm->mii, cmd); |
Ben Dooks | 7da9985 | 2008-02-05 00:02:06 +0000 | [diff] [blame] | 464 | } |
| 465 | |
| 466 | static int dm9000_nway_reset(struct net_device *dev) |
| 467 | { |
| 468 | board_info_t *dm = to_dm9000_board(dev); |
| 469 | return mii_nway_restart(&dm->mii); |
| 470 | } |
| 471 | |
Yeasah Pell | 5dcc60b | 2009-07-06 18:12:33 -0700 | [diff] [blame] | 472 | static uint32_t dm9000_get_rx_csum(struct net_device *dev) |
| 473 | { |
| 474 | board_info_t *dm = to_dm9000_board(dev); |
| 475 | return dm->rx_csum; |
| 476 | } |
| 477 | |
| 478 | static int dm9000_set_rx_csum(struct net_device *dev, uint32_t data) |
| 479 | { |
| 480 | board_info_t *dm = to_dm9000_board(dev); |
| 481 | unsigned long flags; |
| 482 | |
| 483 | if (dm->can_csum) { |
| 484 | dm->rx_csum = data; |
| 485 | |
| 486 | spin_lock_irqsave(&dm->lock, flags); |
| 487 | iow(dm, DM9000_RCSR, dm->rx_csum ? RCSR_CSUM : 0); |
| 488 | spin_unlock_irqrestore(&dm->lock, flags); |
| 489 | |
| 490 | return 0; |
| 491 | } |
| 492 | |
| 493 | return -EOPNOTSUPP; |
| 494 | } |
| 495 | |
| 496 | static int dm9000_set_tx_csum(struct net_device *dev, uint32_t data) |
| 497 | { |
| 498 | board_info_t *dm = to_dm9000_board(dev); |
| 499 | int ret = -EOPNOTSUPP; |
| 500 | |
| 501 | if (dm->can_csum) |
| 502 | ret = ethtool_op_set_tx_csum(dev, data); |
| 503 | return ret; |
| 504 | } |
| 505 | |
Ben Dooks | 7da9985 | 2008-02-05 00:02:06 +0000 | [diff] [blame] | 506 | static u32 dm9000_get_link(struct net_device *dev) |
| 507 | { |
| 508 | board_info_t *dm = to_dm9000_board(dev); |
Ben Dooks | aa1eb45 | 2008-06-24 22:16:03 +0100 | [diff] [blame] | 509 | u32 ret; |
| 510 | |
| 511 | if (dm->flags & DM9000_PLATF_EXT_PHY) |
| 512 | ret = mii_link_ok(&dm->mii); |
| 513 | else |
| 514 | ret = dm9000_read_locked(dm, DM9000_NSR) & NSR_LINKST ? 1 : 0; |
| 515 | |
| 516 | return ret; |
Ben Dooks | 7da9985 | 2008-02-05 00:02:06 +0000 | [diff] [blame] | 517 | } |
| 518 | |
Ben Dooks | 29d52e5 | 2008-02-05 00:02:11 +0000 | [diff] [blame] | 519 | #define DM_EEPROM_MAGIC (0x444D394B) |
| 520 | |
| 521 | static int dm9000_get_eeprom_len(struct net_device *dev) |
| 522 | { |
| 523 | return 128; |
| 524 | } |
| 525 | |
| 526 | static int dm9000_get_eeprom(struct net_device *dev, |
| 527 | struct ethtool_eeprom *ee, u8 *data) |
| 528 | { |
| 529 | board_info_t *dm = to_dm9000_board(dev); |
| 530 | int offset = ee->offset; |
| 531 | int len = ee->len; |
| 532 | int i; |
| 533 | |
| 534 | /* EEPROM access is aligned to two bytes */ |
| 535 | |
| 536 | if ((len & 1) != 0 || (offset & 1) != 0) |
| 537 | return -EINVAL; |
| 538 | |
Ben Dooks | bb44fb70 | 2008-02-05 00:02:20 +0000 | [diff] [blame] | 539 | if (dm->flags & DM9000_PLATF_NO_EEPROM) |
| 540 | return -ENOENT; |
| 541 | |
Ben Dooks | 29d52e5 | 2008-02-05 00:02:11 +0000 | [diff] [blame] | 542 | ee->magic = DM_EEPROM_MAGIC; |
| 543 | |
| 544 | for (i = 0; i < len; i += 2) |
| 545 | dm9000_read_eeprom(dm, (offset + i) / 2, data + i); |
| 546 | |
| 547 | return 0; |
| 548 | } |
| 549 | |
| 550 | static int dm9000_set_eeprom(struct net_device *dev, |
| 551 | struct ethtool_eeprom *ee, u8 *data) |
| 552 | { |
| 553 | board_info_t *dm = to_dm9000_board(dev); |
| 554 | int offset = ee->offset; |
| 555 | int len = ee->len; |
| 556 | int i; |
| 557 | |
| 558 | /* EEPROM access is aligned to two bytes */ |
| 559 | |
| 560 | if ((len & 1) != 0 || (offset & 1) != 0) |
| 561 | return -EINVAL; |
| 562 | |
Ben Dooks | bb44fb70 | 2008-02-05 00:02:20 +0000 | [diff] [blame] | 563 | if (dm->flags & DM9000_PLATF_NO_EEPROM) |
| 564 | return -ENOENT; |
| 565 | |
Ben Dooks | 29d52e5 | 2008-02-05 00:02:11 +0000 | [diff] [blame] | 566 | if (ee->magic != DM_EEPROM_MAGIC) |
| 567 | return -EINVAL; |
| 568 | |
| 569 | for (i = 0; i < len; i += 2) |
| 570 | dm9000_write_eeprom(dm, (offset + i) / 2, data + i); |
| 571 | |
| 572 | return 0; |
| 573 | } |
| 574 | |
Ben Dooks | c029f44 | 2009-11-10 07:22:24 +0000 | [diff] [blame] | 575 | static void dm9000_get_wol(struct net_device *dev, struct ethtool_wolinfo *w) |
| 576 | { |
| 577 | board_info_t *dm = to_dm9000_board(dev); |
| 578 | |
| 579 | memset(w, 0, sizeof(struct ethtool_wolinfo)); |
| 580 | |
| 581 | /* note, we could probably support wake-phy too */ |
| 582 | w->supported = dm->wake_supported ? WAKE_MAGIC : 0; |
| 583 | w->wolopts = dm->wake_state; |
| 584 | } |
| 585 | |
| 586 | static int dm9000_set_wol(struct net_device *dev, struct ethtool_wolinfo *w) |
| 587 | { |
| 588 | board_info_t *dm = to_dm9000_board(dev); |
| 589 | unsigned long flags; |
| 590 | u32 opts = w->wolopts; |
| 591 | u32 wcr = 0; |
| 592 | |
| 593 | if (!dm->wake_supported) |
| 594 | return -EOPNOTSUPP; |
| 595 | |
| 596 | if (opts & ~WAKE_MAGIC) |
| 597 | return -EINVAL; |
| 598 | |
| 599 | if (opts & WAKE_MAGIC) |
| 600 | wcr |= WCR_MAGICEN; |
| 601 | |
| 602 | mutex_lock(&dm->addr_lock); |
| 603 | |
| 604 | spin_lock_irqsave(&dm->lock, flags); |
| 605 | iow(dm, DM9000_WCR, wcr); |
| 606 | spin_unlock_irqrestore(&dm->lock, flags); |
| 607 | |
| 608 | mutex_unlock(&dm->addr_lock); |
| 609 | |
| 610 | if (dm->wake_state != opts) { |
| 611 | /* change in wol state, update IRQ state */ |
| 612 | |
| 613 | if (!dm->wake_state) |
| 614 | set_irq_wake(dm->irq_wake, 1); |
| 615 | else if (dm->wake_state & !opts) |
| 616 | set_irq_wake(dm->irq_wake, 0); |
| 617 | } |
| 618 | |
| 619 | dm->wake_state = opts; |
| 620 | return 0; |
| 621 | } |
| 622 | |
Ben Dooks | 7da9985 | 2008-02-05 00:02:06 +0000 | [diff] [blame] | 623 | static const struct ethtool_ops dm9000_ethtool_ops = { |
| 624 | .get_drvinfo = dm9000_get_drvinfo, |
| 625 | .get_settings = dm9000_get_settings, |
| 626 | .set_settings = dm9000_set_settings, |
Ben Dooks | e662ee0 | 2008-02-05 00:02:12 +0000 | [diff] [blame] | 627 | .get_msglevel = dm9000_get_msglevel, |
| 628 | .set_msglevel = dm9000_set_msglevel, |
Ben Dooks | 7da9985 | 2008-02-05 00:02:06 +0000 | [diff] [blame] | 629 | .nway_reset = dm9000_nway_reset, |
| 630 | .get_link = dm9000_get_link, |
Ben Dooks | c029f44 | 2009-11-10 07:22:24 +0000 | [diff] [blame] | 631 | .get_wol = dm9000_get_wol, |
| 632 | .set_wol = dm9000_set_wol, |
Ben Dooks | 29d52e5 | 2008-02-05 00:02:11 +0000 | [diff] [blame] | 633 | .get_eeprom_len = dm9000_get_eeprom_len, |
| 634 | .get_eeprom = dm9000_get_eeprom, |
| 635 | .set_eeprom = dm9000_set_eeprom, |
Yeasah Pell | 5dcc60b | 2009-07-06 18:12:33 -0700 | [diff] [blame] | 636 | .get_rx_csum = dm9000_get_rx_csum, |
| 637 | .set_rx_csum = dm9000_set_rx_csum, |
| 638 | .get_tx_csum = ethtool_op_get_tx_csum, |
| 639 | .set_tx_csum = dm9000_set_tx_csum, |
Ben Dooks | 7da9985 | 2008-02-05 00:02:06 +0000 | [diff] [blame] | 640 | }; |
| 641 | |
Ben Dooks | f8dd0ec | 2008-06-24 22:16:04 +0100 | [diff] [blame] | 642 | static void dm9000_show_carrier(board_info_t *db, |
| 643 | unsigned carrier, unsigned nsr) |
| 644 | { |
| 645 | struct net_device *ndev = db->ndev; |
| 646 | unsigned ncr = dm9000_read_locked(db, DM9000_NCR); |
| 647 | |
| 648 | if (carrier) |
| 649 | dev_info(db->dev, "%s: link up, %dMbps, %s-duplex, no LPA\n", |
| 650 | ndev->name, (nsr & NSR_SPEED) ? 10 : 100, |
| 651 | (ncr & NCR_FDX) ? "full" : "half"); |
| 652 | else |
| 653 | dev_info(db->dev, "%s: link down\n", ndev->name); |
| 654 | } |
| 655 | |
Ben Dooks | 8f5bf5f2 | 2008-05-08 11:36:42 +0100 | [diff] [blame] | 656 | static void |
| 657 | dm9000_poll_work(struct work_struct *w) |
| 658 | { |
Jean Delvare | bf6aede | 2009-04-02 16:56:54 -0700 | [diff] [blame] | 659 | struct delayed_work *dw = to_delayed_work(w); |
Ben Dooks | 8f5bf5f2 | 2008-05-08 11:36:42 +0100 | [diff] [blame] | 660 | board_info_t *db = container_of(dw, board_info_t, phy_poll); |
Ben Dooks | f8dd0ec | 2008-06-24 22:16:04 +0100 | [diff] [blame] | 661 | struct net_device *ndev = db->ndev; |
Ben Dooks | 8f5bf5f2 | 2008-05-08 11:36:42 +0100 | [diff] [blame] | 662 | |
Ben Dooks | f8dd0ec | 2008-06-24 22:16:04 +0100 | [diff] [blame] | 663 | if (db->flags & DM9000_PLATF_SIMPLE_PHY && |
| 664 | !(db->flags & DM9000_PLATF_EXT_PHY)) { |
| 665 | unsigned nsr = dm9000_read_locked(db, DM9000_NSR); |
| 666 | unsigned old_carrier = netif_carrier_ok(ndev) ? 1 : 0; |
| 667 | unsigned new_carrier; |
| 668 | |
| 669 | new_carrier = (nsr & NSR_LINKST) ? 1 : 0; |
| 670 | |
| 671 | if (old_carrier != new_carrier) { |
| 672 | if (netif_msg_link(db)) |
| 673 | dm9000_show_carrier(db, new_carrier, nsr); |
| 674 | |
| 675 | if (!new_carrier) |
| 676 | netif_carrier_off(ndev); |
| 677 | else |
| 678 | netif_carrier_on(ndev); |
| 679 | } |
| 680 | } else |
| 681 | mii_check_media(&db->mii, netif_msg_link(db), 0); |
Ben Dooks | 8f5bf5f2 | 2008-05-08 11:36:42 +0100 | [diff] [blame] | 682 | |
Ben Dooks | f8dd0ec | 2008-06-24 22:16:04 +0100 | [diff] [blame] | 683 | if (netif_running(ndev)) |
Ben Dooks | 8f5bf5f2 | 2008-05-08 11:36:42 +0100 | [diff] [blame] | 684 | dm9000_schedule_poll(db); |
| 685 | } |
Ben Dooks | 7da9985 | 2008-02-05 00:02:06 +0000 | [diff] [blame] | 686 | |
Sascha Hauer | a136527 | 2005-05-05 15:14:15 -0700 | [diff] [blame] | 687 | /* dm9000_release_board |
| 688 | * |
| 689 | * release a board, and any mapped resources |
| 690 | */ |
| 691 | |
| 692 | static void |
| 693 | dm9000_release_board(struct platform_device *pdev, struct board_info *db) |
| 694 | { |
Sascha Hauer | a136527 | 2005-05-05 15:14:15 -0700 | [diff] [blame] | 695 | /* unmap our resources */ |
| 696 | |
| 697 | iounmap(db->io_addr); |
| 698 | iounmap(db->io_data); |
| 699 | |
| 700 | /* release the resources */ |
| 701 | |
Ben Dooks | 9088fa4f | 2008-06-24 22:16:00 +0100 | [diff] [blame] | 702 | release_resource(db->data_req); |
| 703 | kfree(db->data_req); |
Sascha Hauer | a136527 | 2005-05-05 15:14:15 -0700 | [diff] [blame] | 704 | |
Ben Dooks | 9088fa4f | 2008-06-24 22:16:00 +0100 | [diff] [blame] | 705 | release_resource(db->addr_req); |
| 706 | kfree(db->addr_req); |
Sascha Hauer | a136527 | 2005-05-05 15:14:15 -0700 | [diff] [blame] | 707 | } |
| 708 | |
Ben Dooks | 6d406b3 | 2008-06-24 22:15:59 +0100 | [diff] [blame] | 709 | static unsigned char dm9000_type_to_char(enum dm9000_type type) |
| 710 | { |
| 711 | switch (type) { |
| 712 | case TYPE_DM9000E: return 'e'; |
| 713 | case TYPE_DM9000A: return 'a'; |
| 714 | case TYPE_DM9000B: return 'b'; |
| 715 | } |
| 716 | |
| 717 | return '?'; |
| 718 | } |
| 719 | |
Ben Dooks | f8d79e7 | 2008-06-24 22:16:02 +0100 | [diff] [blame] | 720 | /* |
| 721 | * Set DM9000 multicast address |
| 722 | */ |
| 723 | static void |
| 724 | dm9000_hash_table(struct net_device *dev) |
| 725 | { |
Wang Chen | 4cf1653 | 2008-11-12 23:38:14 -0800 | [diff] [blame] | 726 | board_info_t *db = netdev_priv(dev); |
Jiri Pirko | e1d4447 | 2010-02-17 11:09:31 +0000 | [diff] [blame] | 727 | struct dev_mc_list *mcptr; |
Ben Dooks | f8d79e7 | 2008-06-24 22:16:02 +0100 | [diff] [blame] | 728 | int i, oft; |
| 729 | u32 hash_val; |
| 730 | u16 hash_table[4]; |
| 731 | u8 rcr = RCR_DIS_LONG | RCR_DIS_CRC | RCR_RXEN; |
| 732 | unsigned long flags; |
| 733 | |
| 734 | dm9000_dbg(db, 1, "entering %s\n", __func__); |
| 735 | |
| 736 | spin_lock_irqsave(&db->lock, flags); |
| 737 | |
| 738 | for (i = 0, oft = DM9000_PAR; i < 6; i++, oft++) |
| 739 | iow(db, oft, dev->dev_addr[i]); |
| 740 | |
| 741 | /* Clear Hash Table */ |
| 742 | for (i = 0; i < 4; i++) |
| 743 | hash_table[i] = 0x0; |
| 744 | |
| 745 | /* broadcast address */ |
| 746 | hash_table[3] = 0x8000; |
| 747 | |
| 748 | if (dev->flags & IFF_PROMISC) |
| 749 | rcr |= RCR_PRMSC; |
| 750 | |
| 751 | if (dev->flags & IFF_ALLMULTI) |
| 752 | rcr |= RCR_ALL; |
| 753 | |
| 754 | /* the multicast address in Hash Table : 64 bits */ |
Jiri Pirko | e1d4447 | 2010-02-17 11:09:31 +0000 | [diff] [blame] | 755 | netdev_for_each_mc_addr(mcptr, dev) { |
Ben Dooks | f8d79e7 | 2008-06-24 22:16:02 +0100 | [diff] [blame] | 756 | hash_val = ether_crc_le(6, mcptr->dmi_addr) & 0x3f; |
| 757 | hash_table[hash_val / 16] |= (u16) 1 << (hash_val % 16); |
| 758 | } |
| 759 | |
| 760 | /* Write the hash table to MAC MD table */ |
| 761 | for (i = 0, oft = DM9000_MAR; i < 4; i++) { |
| 762 | iow(db, oft++, hash_table[i]); |
| 763 | iow(db, oft++, hash_table[i] >> 8); |
| 764 | } |
| 765 | |
| 766 | iow(db, DM9000_RCR, rcr); |
| 767 | spin_unlock_irqrestore(&db->lock, flags); |
| 768 | } |
| 769 | |
| 770 | /* |
| 771 | * Initilize dm9000 board |
| 772 | */ |
| 773 | static void |
| 774 | dm9000_init_dm9000(struct net_device *dev) |
| 775 | { |
Wang Chen | 4cf1653 | 2008-11-12 23:38:14 -0800 | [diff] [blame] | 776 | board_info_t *db = netdev_priv(dev); |
Ben Dooks | f8d79e7 | 2008-06-24 22:16:02 +0100 | [diff] [blame] | 777 | unsigned int imr; |
Ben Dooks | c029f44 | 2009-11-10 07:22:24 +0000 | [diff] [blame] | 778 | unsigned int ncr; |
Ben Dooks | f8d79e7 | 2008-06-24 22:16:02 +0100 | [diff] [blame] | 779 | |
| 780 | dm9000_dbg(db, 1, "entering %s\n", __func__); |
| 781 | |
| 782 | /* I/O mode */ |
| 783 | db->io_mode = ior(db, DM9000_ISR) >> 6; /* ISR bit7:6 keeps I/O mode */ |
| 784 | |
Yeasah Pell | 5dcc60b | 2009-07-06 18:12:33 -0700 | [diff] [blame] | 785 | /* Checksum mode */ |
| 786 | dm9000_set_rx_csum(dev, db->rx_csum); |
| 787 | |
Ben Dooks | f8d79e7 | 2008-06-24 22:16:02 +0100 | [diff] [blame] | 788 | /* GPIO0 on pre-activate PHY */ |
| 789 | iow(db, DM9000_GPR, 0); /* REG_1F bit0 activate phyxcer */ |
| 790 | iow(db, DM9000_GPCR, GPCR_GEP_CNTL); /* Let GPIO0 output */ |
| 791 | iow(db, DM9000_GPR, 0); /* Enable PHY */ |
| 792 | |
Ben Dooks | c029f44 | 2009-11-10 07:22:24 +0000 | [diff] [blame] | 793 | ncr = (db->flags & DM9000_PLATF_EXT_PHY) ? NCR_EXT_PHY : 0; |
| 794 | |
| 795 | /* if wol is needed, then always set NCR_WAKEEN otherwise we end |
| 796 | * up dumping the wake events if we disable this. There is already |
| 797 | * a wake-mask in DM9000_WCR */ |
| 798 | if (db->wake_supported) |
| 799 | ncr |= NCR_WAKEEN; |
| 800 | |
| 801 | iow(db, DM9000_NCR, ncr); |
Ben Dooks | f8d79e7 | 2008-06-24 22:16:02 +0100 | [diff] [blame] | 802 | |
| 803 | /* Program operating register */ |
| 804 | iow(db, DM9000_TCR, 0); /* TX Polling clear */ |
| 805 | iow(db, DM9000_BPTR, 0x3f); /* Less 3Kb, 200us */ |
| 806 | iow(db, DM9000_FCR, 0xff); /* Flow Control */ |
| 807 | iow(db, DM9000_SMCR, 0); /* Special Mode */ |
| 808 | /* clear TX status */ |
| 809 | iow(db, DM9000_NSR, NSR_WAKEST | NSR_TX2END | NSR_TX1END); |
| 810 | iow(db, DM9000_ISR, ISR_CLR_STATUS); /* Clear interrupt status */ |
| 811 | |
| 812 | /* Set address filter table */ |
| 813 | dm9000_hash_table(dev); |
| 814 | |
| 815 | imr = IMR_PAR | IMR_PTM | IMR_PRM; |
| 816 | if (db->type != TYPE_DM9000E) |
| 817 | imr |= IMR_LNKCHNG; |
| 818 | |
| 819 | db->imr_all = imr; |
| 820 | |
| 821 | /* Enable TX/RX interrupt mask */ |
| 822 | iow(db, DM9000_IMR, imr); |
| 823 | |
| 824 | /* Init Driver variable */ |
| 825 | db->tx_pkt_cnt = 0; |
| 826 | db->queue_pkt_len = 0; |
| 827 | dev->trans_start = 0; |
| 828 | } |
| 829 | |
| 830 | /* Our watchdog timed out. Called by the networking layer */ |
| 831 | static void dm9000_timeout(struct net_device *dev) |
| 832 | { |
Wang Chen | 4cf1653 | 2008-11-12 23:38:14 -0800 | [diff] [blame] | 833 | board_info_t *db = netdev_priv(dev); |
Ben Dooks | f8d79e7 | 2008-06-24 22:16:02 +0100 | [diff] [blame] | 834 | u8 reg_save; |
| 835 | unsigned long flags; |
| 836 | |
| 837 | /* Save previous register address */ |
| 838 | reg_save = readb(db->io_addr); |
| 839 | spin_lock_irqsave(&db->lock, flags); |
| 840 | |
| 841 | netif_stop_queue(dev); |
| 842 | dm9000_reset(db); |
| 843 | dm9000_init_dm9000(dev); |
| 844 | /* We can accept TX packets again */ |
| 845 | dev->trans_start = jiffies; |
| 846 | netif_wake_queue(dev); |
| 847 | |
| 848 | /* Restore previous register address */ |
| 849 | writeb(reg_save, db->io_addr); |
| 850 | spin_unlock_irqrestore(&db->lock, flags); |
| 851 | } |
| 852 | |
Yeasah Pell | 5dcc60b | 2009-07-06 18:12:33 -0700 | [diff] [blame] | 853 | static void dm9000_send_packet(struct net_device *dev, |
| 854 | int ip_summed, |
| 855 | u16 pkt_len) |
| 856 | { |
| 857 | board_info_t *dm = to_dm9000_board(dev); |
| 858 | |
| 859 | /* The DM9000 is not smart enough to leave fragmented packets alone. */ |
| 860 | if (dm->ip_summed != ip_summed) { |
| 861 | if (ip_summed == CHECKSUM_NONE) |
| 862 | iow(dm, DM9000_TCCR, 0); |
| 863 | else |
| 864 | iow(dm, DM9000_TCCR, TCCR_IP | TCCR_UDP | TCCR_TCP); |
| 865 | dm->ip_summed = ip_summed; |
| 866 | } |
| 867 | |
| 868 | /* Set TX length to DM9000 */ |
| 869 | iow(dm, DM9000_TXPLL, pkt_len); |
| 870 | iow(dm, DM9000_TXPLH, pkt_len >> 8); |
| 871 | |
| 872 | /* Issue TX polling command */ |
| 873 | iow(dm, DM9000_TCR, TCR_TXREQ); /* Cleared after TX complete */ |
| 874 | } |
| 875 | |
Ben Dooks | f8d79e7 | 2008-06-24 22:16:02 +0100 | [diff] [blame] | 876 | /* |
| 877 | * Hardware start transmission. |
| 878 | * Send a packet to media from the upper layer. |
| 879 | */ |
| 880 | static int |
| 881 | dm9000_start_xmit(struct sk_buff *skb, struct net_device *dev) |
| 882 | { |
| 883 | unsigned long flags; |
Wang Chen | 4cf1653 | 2008-11-12 23:38:14 -0800 | [diff] [blame] | 884 | board_info_t *db = netdev_priv(dev); |
Ben Dooks | f8d79e7 | 2008-06-24 22:16:02 +0100 | [diff] [blame] | 885 | |
| 886 | dm9000_dbg(db, 3, "%s:\n", __func__); |
| 887 | |
| 888 | if (db->tx_pkt_cnt > 1) |
Patrick McHardy | 5b54814 | 2009-06-12 06:22:29 +0000 | [diff] [blame] | 889 | return NETDEV_TX_BUSY; |
Ben Dooks | f8d79e7 | 2008-06-24 22:16:02 +0100 | [diff] [blame] | 890 | |
| 891 | spin_lock_irqsave(&db->lock, flags); |
| 892 | |
| 893 | /* Move data to DM9000 TX RAM */ |
| 894 | writeb(DM9000_MWCMD, db->io_addr); |
| 895 | |
| 896 | (db->outblk)(db->io_data, skb->data, skb->len); |
| 897 | dev->stats.tx_bytes += skb->len; |
| 898 | |
| 899 | db->tx_pkt_cnt++; |
| 900 | /* TX control: First packet immediately send, second packet queue */ |
| 901 | if (db->tx_pkt_cnt == 1) { |
Yeasah Pell | 5dcc60b | 2009-07-06 18:12:33 -0700 | [diff] [blame] | 902 | dm9000_send_packet(dev, skb->ip_summed, skb->len); |
Ben Dooks | f8d79e7 | 2008-06-24 22:16:02 +0100 | [diff] [blame] | 903 | } else { |
| 904 | /* Second packet */ |
| 905 | db->queue_pkt_len = skb->len; |
Yeasah Pell | 5dcc60b | 2009-07-06 18:12:33 -0700 | [diff] [blame] | 906 | db->queue_ip_summed = skb->ip_summed; |
Ben Dooks | f8d79e7 | 2008-06-24 22:16:02 +0100 | [diff] [blame] | 907 | netif_stop_queue(dev); |
| 908 | } |
| 909 | |
| 910 | spin_unlock_irqrestore(&db->lock, flags); |
| 911 | |
| 912 | /* free this SKB */ |
| 913 | dev_kfree_skb(skb); |
| 914 | |
Patrick McHardy | 6ed1065 | 2009-06-23 06:03:08 +0000 | [diff] [blame] | 915 | return NETDEV_TX_OK; |
Ben Dooks | f8d79e7 | 2008-06-24 22:16:02 +0100 | [diff] [blame] | 916 | } |
| 917 | |
| 918 | /* |
| 919 | * DM9000 interrupt handler |
| 920 | * receive the packet to upper layer, free the transmitted packet |
| 921 | */ |
| 922 | |
| 923 | static void dm9000_tx_done(struct net_device *dev, board_info_t *db) |
| 924 | { |
| 925 | int tx_status = ior(db, DM9000_NSR); /* Got TX status */ |
| 926 | |
| 927 | if (tx_status & (NSR_TX2END | NSR_TX1END)) { |
| 928 | /* One packet sent complete */ |
| 929 | db->tx_pkt_cnt--; |
| 930 | dev->stats.tx_packets++; |
| 931 | |
| 932 | if (netif_msg_tx_done(db)) |
| 933 | dev_dbg(db->dev, "tx done, NSR %02x\n", tx_status); |
| 934 | |
| 935 | /* Queue packet check & send */ |
Yeasah Pell | 5dcc60b | 2009-07-06 18:12:33 -0700 | [diff] [blame] | 936 | if (db->tx_pkt_cnt > 0) |
| 937 | dm9000_send_packet(dev, db->queue_ip_summed, |
| 938 | db->queue_pkt_len); |
Ben Dooks | f8d79e7 | 2008-06-24 22:16:02 +0100 | [diff] [blame] | 939 | netif_wake_queue(dev); |
| 940 | } |
| 941 | } |
| 942 | |
| 943 | struct dm9000_rxhdr { |
| 944 | u8 RxPktReady; |
| 945 | u8 RxStatus; |
| 946 | __le16 RxLen; |
| 947 | } __attribute__((__packed__)); |
| 948 | |
| 949 | /* |
| 950 | * Received a packet and pass to upper layer |
| 951 | */ |
| 952 | static void |
| 953 | dm9000_rx(struct net_device *dev) |
| 954 | { |
Wang Chen | 4cf1653 | 2008-11-12 23:38:14 -0800 | [diff] [blame] | 955 | board_info_t *db = netdev_priv(dev); |
Ben Dooks | f8d79e7 | 2008-06-24 22:16:02 +0100 | [diff] [blame] | 956 | struct dm9000_rxhdr rxhdr; |
| 957 | struct sk_buff *skb; |
| 958 | u8 rxbyte, *rdptr; |
| 959 | bool GoodPacket; |
| 960 | int RxLen; |
| 961 | |
| 962 | /* Check packet ready or not */ |
| 963 | do { |
| 964 | ior(db, DM9000_MRCMDX); /* Dummy read */ |
| 965 | |
| 966 | /* Get most updated data */ |
| 967 | rxbyte = readb(db->io_data); |
| 968 | |
| 969 | /* Status check: this byte must be 0 or 1 */ |
Yeasah Pell | 5dcc60b | 2009-07-06 18:12:33 -0700 | [diff] [blame] | 970 | if (rxbyte & DM9000_PKT_ERR) { |
Ben Dooks | f8d79e7 | 2008-06-24 22:16:02 +0100 | [diff] [blame] | 971 | dev_warn(db->dev, "status check fail: %d\n", rxbyte); |
| 972 | iow(db, DM9000_RCR, 0x00); /* Stop Device */ |
| 973 | iow(db, DM9000_ISR, IMR_PAR); /* Stop INT request */ |
| 974 | return; |
| 975 | } |
| 976 | |
Yeasah Pell | 5dcc60b | 2009-07-06 18:12:33 -0700 | [diff] [blame] | 977 | if (!(rxbyte & DM9000_PKT_RDY)) |
Ben Dooks | f8d79e7 | 2008-06-24 22:16:02 +0100 | [diff] [blame] | 978 | return; |
| 979 | |
| 980 | /* A packet ready now & Get status/length */ |
| 981 | GoodPacket = true; |
| 982 | writeb(DM9000_MRCMD, db->io_addr); |
| 983 | |
| 984 | (db->inblk)(db->io_data, &rxhdr, sizeof(rxhdr)); |
| 985 | |
| 986 | RxLen = le16_to_cpu(rxhdr.RxLen); |
| 987 | |
| 988 | if (netif_msg_rx_status(db)) |
| 989 | dev_dbg(db->dev, "RX: status %02x, length %04x\n", |
| 990 | rxhdr.RxStatus, RxLen); |
| 991 | |
| 992 | /* Packet Status check */ |
| 993 | if (RxLen < 0x40) { |
| 994 | GoodPacket = false; |
| 995 | if (netif_msg_rx_err(db)) |
| 996 | dev_dbg(db->dev, "RX: Bad Packet (runt)\n"); |
| 997 | } |
| 998 | |
| 999 | if (RxLen > DM9000_PKT_MAX) { |
| 1000 | dev_dbg(db->dev, "RST: RX Len:%x\n", RxLen); |
| 1001 | } |
| 1002 | |
Ben Dooks | f8e5e77 | 2008-07-17 20:29:13 +0100 | [diff] [blame] | 1003 | /* rxhdr.RxStatus is identical to RSR register. */ |
| 1004 | if (rxhdr.RxStatus & (RSR_FOE | RSR_CE | RSR_AE | |
| 1005 | RSR_PLE | RSR_RWTO | |
| 1006 | RSR_LCS | RSR_RF)) { |
Ben Dooks | f8d79e7 | 2008-06-24 22:16:02 +0100 | [diff] [blame] | 1007 | GoodPacket = false; |
Ben Dooks | f8e5e77 | 2008-07-17 20:29:13 +0100 | [diff] [blame] | 1008 | if (rxhdr.RxStatus & RSR_FOE) { |
Ben Dooks | f8d79e7 | 2008-06-24 22:16:02 +0100 | [diff] [blame] | 1009 | if (netif_msg_rx_err(db)) |
| 1010 | dev_dbg(db->dev, "fifo error\n"); |
| 1011 | dev->stats.rx_fifo_errors++; |
| 1012 | } |
Ben Dooks | f8e5e77 | 2008-07-17 20:29:13 +0100 | [diff] [blame] | 1013 | if (rxhdr.RxStatus & RSR_CE) { |
Ben Dooks | f8d79e7 | 2008-06-24 22:16:02 +0100 | [diff] [blame] | 1014 | if (netif_msg_rx_err(db)) |
| 1015 | dev_dbg(db->dev, "crc error\n"); |
| 1016 | dev->stats.rx_crc_errors++; |
| 1017 | } |
Ben Dooks | f8e5e77 | 2008-07-17 20:29:13 +0100 | [diff] [blame] | 1018 | if (rxhdr.RxStatus & RSR_RF) { |
Ben Dooks | f8d79e7 | 2008-06-24 22:16:02 +0100 | [diff] [blame] | 1019 | if (netif_msg_rx_err(db)) |
| 1020 | dev_dbg(db->dev, "length error\n"); |
| 1021 | dev->stats.rx_length_errors++; |
| 1022 | } |
| 1023 | } |
| 1024 | |
| 1025 | /* Move data from DM9000 */ |
Joe Perches | 8e95a20 | 2009-12-03 07:58:21 +0000 | [diff] [blame] | 1026 | if (GoodPacket && |
| 1027 | ((skb = dev_alloc_skb(RxLen + 4)) != NULL)) { |
Ben Dooks | f8d79e7 | 2008-06-24 22:16:02 +0100 | [diff] [blame] | 1028 | skb_reserve(skb, 2); |
| 1029 | rdptr = (u8 *) skb_put(skb, RxLen - 4); |
| 1030 | |
| 1031 | /* Read received packet from RX SRAM */ |
| 1032 | |
| 1033 | (db->inblk)(db->io_data, rdptr, RxLen); |
| 1034 | dev->stats.rx_bytes += RxLen; |
| 1035 | |
| 1036 | /* Pass to upper layer */ |
| 1037 | skb->protocol = eth_type_trans(skb, dev); |
Yeasah Pell | 5dcc60b | 2009-07-06 18:12:33 -0700 | [diff] [blame] | 1038 | if (db->rx_csum) { |
| 1039 | if ((((rxbyte & 0x1c) << 3) & rxbyte) == 0) |
| 1040 | skb->ip_summed = CHECKSUM_UNNECESSARY; |
| 1041 | else |
| 1042 | skb->ip_summed = CHECKSUM_NONE; |
| 1043 | } |
Ben Dooks | f8d79e7 | 2008-06-24 22:16:02 +0100 | [diff] [blame] | 1044 | netif_rx(skb); |
| 1045 | dev->stats.rx_packets++; |
| 1046 | |
| 1047 | } else { |
| 1048 | /* need to dump the packet's data */ |
| 1049 | |
| 1050 | (db->dumpblk)(db->io_data, RxLen); |
| 1051 | } |
Yeasah Pell | 5dcc60b | 2009-07-06 18:12:33 -0700 | [diff] [blame] | 1052 | } while (rxbyte & DM9000_PKT_RDY); |
Ben Dooks | f8d79e7 | 2008-06-24 22:16:02 +0100 | [diff] [blame] | 1053 | } |
| 1054 | |
| 1055 | static irqreturn_t dm9000_interrupt(int irq, void *dev_id) |
| 1056 | { |
| 1057 | struct net_device *dev = dev_id; |
Wang Chen | 4cf1653 | 2008-11-12 23:38:14 -0800 | [diff] [blame] | 1058 | board_info_t *db = netdev_priv(dev); |
Ben Dooks | f8d79e7 | 2008-06-24 22:16:02 +0100 | [diff] [blame] | 1059 | int int_status; |
David Brownell | e3162d3 | 2009-03-22 21:28:39 -0700 | [diff] [blame] | 1060 | unsigned long flags; |
Ben Dooks | f8d79e7 | 2008-06-24 22:16:02 +0100 | [diff] [blame] | 1061 | u8 reg_save; |
| 1062 | |
| 1063 | dm9000_dbg(db, 3, "entering %s\n", __func__); |
| 1064 | |
| 1065 | /* A real interrupt coming */ |
| 1066 | |
David Brownell | e3162d3 | 2009-03-22 21:28:39 -0700 | [diff] [blame] | 1067 | /* holders of db->lock must always block IRQs */ |
| 1068 | spin_lock_irqsave(&db->lock, flags); |
Ben Dooks | f8d79e7 | 2008-06-24 22:16:02 +0100 | [diff] [blame] | 1069 | |
| 1070 | /* Save previous register address */ |
| 1071 | reg_save = readb(db->io_addr); |
| 1072 | |
| 1073 | /* Disable all interrupts */ |
| 1074 | iow(db, DM9000_IMR, IMR_PAR); |
| 1075 | |
| 1076 | /* Got DM9000 interrupt status */ |
| 1077 | int_status = ior(db, DM9000_ISR); /* Got ISR */ |
| 1078 | iow(db, DM9000_ISR, int_status); /* Clear ISR status */ |
| 1079 | |
| 1080 | if (netif_msg_intr(db)) |
| 1081 | dev_dbg(db->dev, "interrupt status %02x\n", int_status); |
| 1082 | |
| 1083 | /* Received the coming packet */ |
| 1084 | if (int_status & ISR_PRS) |
| 1085 | dm9000_rx(dev); |
| 1086 | |
| 1087 | /* Trnasmit Interrupt check */ |
| 1088 | if (int_status & ISR_PTS) |
| 1089 | dm9000_tx_done(dev, db); |
| 1090 | |
| 1091 | if (db->type != TYPE_DM9000E) { |
| 1092 | if (int_status & ISR_LNKCHNG) { |
| 1093 | /* fire a link-change request */ |
| 1094 | schedule_delayed_work(&db->phy_poll, 1); |
| 1095 | } |
| 1096 | } |
| 1097 | |
| 1098 | /* Re-enable interrupt mask */ |
| 1099 | iow(db, DM9000_IMR, db->imr_all); |
| 1100 | |
| 1101 | /* Restore previous register address */ |
| 1102 | writeb(reg_save, db->io_addr); |
| 1103 | |
David Brownell | e3162d3 | 2009-03-22 21:28:39 -0700 | [diff] [blame] | 1104 | spin_unlock_irqrestore(&db->lock, flags); |
Ben Dooks | f8d79e7 | 2008-06-24 22:16:02 +0100 | [diff] [blame] | 1105 | |
| 1106 | return IRQ_HANDLED; |
| 1107 | } |
| 1108 | |
Ben Dooks | c029f44 | 2009-11-10 07:22:24 +0000 | [diff] [blame] | 1109 | static irqreturn_t dm9000_wol_interrupt(int irq, void *dev_id) |
| 1110 | { |
| 1111 | struct net_device *dev = dev_id; |
| 1112 | board_info_t *db = netdev_priv(dev); |
| 1113 | unsigned long flags; |
| 1114 | unsigned nsr, wcr; |
| 1115 | |
| 1116 | spin_lock_irqsave(&db->lock, flags); |
| 1117 | |
| 1118 | nsr = ior(db, DM9000_NSR); |
| 1119 | wcr = ior(db, DM9000_WCR); |
| 1120 | |
| 1121 | dev_dbg(db->dev, "%s: NSR=0x%02x, WCR=0x%02x\n", __func__, nsr, wcr); |
| 1122 | |
| 1123 | if (nsr & NSR_WAKEST) { |
| 1124 | /* clear, so we can avoid */ |
| 1125 | iow(db, DM9000_NSR, NSR_WAKEST); |
| 1126 | |
| 1127 | if (wcr & WCR_LINKST) |
| 1128 | dev_info(db->dev, "wake by link status change\n"); |
| 1129 | if (wcr & WCR_SAMPLEST) |
| 1130 | dev_info(db->dev, "wake by sample packet\n"); |
| 1131 | if (wcr & WCR_MAGICST ) |
| 1132 | dev_info(db->dev, "wake by magic packet\n"); |
| 1133 | if (!(wcr & (WCR_LINKST | WCR_SAMPLEST | WCR_MAGICST))) |
| 1134 | dev_err(db->dev, "wake signalled with no reason? " |
| 1135 | "NSR=0x%02x, WSR=0x%02x\n", nsr, wcr); |
| 1136 | |
| 1137 | } |
| 1138 | |
| 1139 | spin_unlock_irqrestore(&db->lock, flags); |
| 1140 | |
| 1141 | return (nsr & NSR_WAKEST) ? IRQ_HANDLED : IRQ_NONE; |
| 1142 | } |
| 1143 | |
Ben Dooks | f8d79e7 | 2008-06-24 22:16:02 +0100 | [diff] [blame] | 1144 | #ifdef CONFIG_NET_POLL_CONTROLLER |
| 1145 | /* |
| 1146 | *Used by netconsole |
| 1147 | */ |
| 1148 | static void dm9000_poll_controller(struct net_device *dev) |
| 1149 | { |
| 1150 | disable_irq(dev->irq); |
| 1151 | dm9000_interrupt(dev->irq, dev); |
| 1152 | enable_irq(dev->irq); |
| 1153 | } |
| 1154 | #endif |
| 1155 | |
| 1156 | /* |
| 1157 | * Open the interface. |
| 1158 | * The interface is opened whenever "ifconfig" actives it. |
| 1159 | */ |
| 1160 | static int |
| 1161 | dm9000_open(struct net_device *dev) |
| 1162 | { |
Wang Chen | 4cf1653 | 2008-11-12 23:38:14 -0800 | [diff] [blame] | 1163 | board_info_t *db = netdev_priv(dev); |
Ben Dooks | f8d79e7 | 2008-06-24 22:16:02 +0100 | [diff] [blame] | 1164 | unsigned long irqflags = db->irq_res->flags & IRQF_TRIGGER_MASK; |
| 1165 | |
| 1166 | if (netif_msg_ifup(db)) |
| 1167 | dev_dbg(db->dev, "enabling %s\n", dev->name); |
| 1168 | |
| 1169 | /* If there is no IRQ type specified, default to something that |
| 1170 | * may work, and tell the user that this is a problem */ |
| 1171 | |
Ben Dooks | 6ff4ff0 | 2008-06-24 22:16:07 +0100 | [diff] [blame] | 1172 | if (irqflags == IRQF_TRIGGER_NONE) |
Ben Dooks | f8d79e7 | 2008-06-24 22:16:02 +0100 | [diff] [blame] | 1173 | dev_warn(db->dev, "WARNING: no IRQ resource flags set.\n"); |
Ben Dooks | 6ff4ff0 | 2008-06-24 22:16:07 +0100 | [diff] [blame] | 1174 | |
Ben Dooks | f8d79e7 | 2008-06-24 22:16:02 +0100 | [diff] [blame] | 1175 | irqflags |= IRQF_SHARED; |
| 1176 | |
Joe Perches | a0607fd | 2009-11-18 23:29:17 -0800 | [diff] [blame] | 1177 | if (request_irq(dev->irq, dm9000_interrupt, irqflags, dev->name, dev)) |
Ben Dooks | f8d79e7 | 2008-06-24 22:16:02 +0100 | [diff] [blame] | 1178 | return -EAGAIN; |
| 1179 | |
| 1180 | /* Initialize DM9000 board */ |
| 1181 | dm9000_reset(db); |
| 1182 | dm9000_init_dm9000(dev); |
| 1183 | |
| 1184 | /* Init driver variable */ |
| 1185 | db->dbug_cnt = 0; |
| 1186 | |
| 1187 | mii_check_media(&db->mii, netif_msg_link(db), 1); |
| 1188 | netif_start_queue(dev); |
| 1189 | |
| 1190 | dm9000_schedule_poll(db); |
| 1191 | |
| 1192 | return 0; |
| 1193 | } |
| 1194 | |
| 1195 | /* |
| 1196 | * Sleep, either by using msleep() or if we are suspending, then |
| 1197 | * use mdelay() to sleep. |
| 1198 | */ |
| 1199 | static void dm9000_msleep(board_info_t *db, unsigned int ms) |
| 1200 | { |
| 1201 | if (db->in_suspend) |
| 1202 | mdelay(ms); |
| 1203 | else |
| 1204 | msleep(ms); |
| 1205 | } |
| 1206 | |
| 1207 | /* |
| 1208 | * Read a word from phyxcer |
| 1209 | */ |
| 1210 | static int |
| 1211 | dm9000_phy_read(struct net_device *dev, int phy_reg_unused, int reg) |
| 1212 | { |
Wang Chen | 4cf1653 | 2008-11-12 23:38:14 -0800 | [diff] [blame] | 1213 | board_info_t *db = netdev_priv(dev); |
Ben Dooks | f8d79e7 | 2008-06-24 22:16:02 +0100 | [diff] [blame] | 1214 | unsigned long flags; |
| 1215 | unsigned int reg_save; |
| 1216 | int ret; |
| 1217 | |
| 1218 | mutex_lock(&db->addr_lock); |
| 1219 | |
| 1220 | spin_lock_irqsave(&db->lock,flags); |
| 1221 | |
| 1222 | /* Save previous register address */ |
| 1223 | reg_save = readb(db->io_addr); |
| 1224 | |
| 1225 | /* Fill the phyxcer register into REG_0C */ |
| 1226 | iow(db, DM9000_EPAR, DM9000_PHY | reg); |
| 1227 | |
Ben Dooks | f8e5e77 | 2008-07-17 20:29:13 +0100 | [diff] [blame] | 1228 | iow(db, DM9000_EPCR, EPCR_ERPRR | EPCR_EPOS); /* Issue phyxcer read command */ |
Ben Dooks | f8d79e7 | 2008-06-24 22:16:02 +0100 | [diff] [blame] | 1229 | |
| 1230 | writeb(reg_save, db->io_addr); |
| 1231 | spin_unlock_irqrestore(&db->lock,flags); |
| 1232 | |
| 1233 | dm9000_msleep(db, 1); /* Wait read complete */ |
| 1234 | |
| 1235 | spin_lock_irqsave(&db->lock,flags); |
| 1236 | reg_save = readb(db->io_addr); |
| 1237 | |
| 1238 | iow(db, DM9000_EPCR, 0x0); /* Clear phyxcer read command */ |
| 1239 | |
| 1240 | /* The read data keeps on REG_0D & REG_0E */ |
| 1241 | ret = (ior(db, DM9000_EPDRH) << 8) | ior(db, DM9000_EPDRL); |
| 1242 | |
| 1243 | /* restore the previous address */ |
| 1244 | writeb(reg_save, db->io_addr); |
| 1245 | spin_unlock_irqrestore(&db->lock,flags); |
| 1246 | |
| 1247 | mutex_unlock(&db->addr_lock); |
| 1248 | |
| 1249 | dm9000_dbg(db, 5, "phy_read[%02x] -> %04x\n", reg, ret); |
| 1250 | return ret; |
| 1251 | } |
| 1252 | |
| 1253 | /* |
| 1254 | * Write a word to phyxcer |
| 1255 | */ |
| 1256 | static void |
| 1257 | dm9000_phy_write(struct net_device *dev, |
| 1258 | int phyaddr_unused, int reg, int value) |
| 1259 | { |
Wang Chen | 4cf1653 | 2008-11-12 23:38:14 -0800 | [diff] [blame] | 1260 | board_info_t *db = netdev_priv(dev); |
Ben Dooks | f8d79e7 | 2008-06-24 22:16:02 +0100 | [diff] [blame] | 1261 | unsigned long flags; |
| 1262 | unsigned long reg_save; |
| 1263 | |
| 1264 | dm9000_dbg(db, 5, "phy_write[%02x] = %04x\n", reg, value); |
| 1265 | mutex_lock(&db->addr_lock); |
| 1266 | |
| 1267 | spin_lock_irqsave(&db->lock,flags); |
| 1268 | |
| 1269 | /* Save previous register address */ |
| 1270 | reg_save = readb(db->io_addr); |
| 1271 | |
| 1272 | /* Fill the phyxcer register into REG_0C */ |
| 1273 | iow(db, DM9000_EPAR, DM9000_PHY | reg); |
| 1274 | |
| 1275 | /* Fill the written data into REG_0D & REG_0E */ |
| 1276 | iow(db, DM9000_EPDRL, value); |
| 1277 | iow(db, DM9000_EPDRH, value >> 8); |
| 1278 | |
Ben Dooks | f8e5e77 | 2008-07-17 20:29:13 +0100 | [diff] [blame] | 1279 | iow(db, DM9000_EPCR, EPCR_EPOS | EPCR_ERPRW); /* Issue phyxcer write command */ |
Ben Dooks | f8d79e7 | 2008-06-24 22:16:02 +0100 | [diff] [blame] | 1280 | |
| 1281 | writeb(reg_save, db->io_addr); |
| 1282 | spin_unlock_irqrestore(&db->lock, flags); |
| 1283 | |
| 1284 | dm9000_msleep(db, 1); /* Wait write complete */ |
| 1285 | |
| 1286 | spin_lock_irqsave(&db->lock,flags); |
| 1287 | reg_save = readb(db->io_addr); |
| 1288 | |
| 1289 | iow(db, DM9000_EPCR, 0x0); /* Clear phyxcer write command */ |
| 1290 | |
| 1291 | /* restore the previous address */ |
| 1292 | writeb(reg_save, db->io_addr); |
| 1293 | |
| 1294 | spin_unlock_irqrestore(&db->lock, flags); |
| 1295 | mutex_unlock(&db->addr_lock); |
| 1296 | } |
| 1297 | |
| 1298 | static void |
| 1299 | dm9000_shutdown(struct net_device *dev) |
| 1300 | { |
Wang Chen | 4cf1653 | 2008-11-12 23:38:14 -0800 | [diff] [blame] | 1301 | board_info_t *db = netdev_priv(dev); |
Ben Dooks | f8d79e7 | 2008-06-24 22:16:02 +0100 | [diff] [blame] | 1302 | |
| 1303 | /* RESET device */ |
| 1304 | dm9000_phy_write(dev, 0, MII_BMCR, BMCR_RESET); /* PHY RESET */ |
| 1305 | iow(db, DM9000_GPR, 0x01); /* Power-Down PHY */ |
| 1306 | iow(db, DM9000_IMR, IMR_PAR); /* Disable all interrupt */ |
| 1307 | iow(db, DM9000_RCR, 0x00); /* Disable RX */ |
| 1308 | } |
| 1309 | |
| 1310 | /* |
| 1311 | * Stop the interface. |
| 1312 | * The interface is stopped when it is brought. |
| 1313 | */ |
| 1314 | static int |
| 1315 | dm9000_stop(struct net_device *ndev) |
| 1316 | { |
Wang Chen | 4cf1653 | 2008-11-12 23:38:14 -0800 | [diff] [blame] | 1317 | board_info_t *db = netdev_priv(ndev); |
Ben Dooks | f8d79e7 | 2008-06-24 22:16:02 +0100 | [diff] [blame] | 1318 | |
| 1319 | if (netif_msg_ifdown(db)) |
| 1320 | dev_dbg(db->dev, "shutting down %s\n", ndev->name); |
| 1321 | |
| 1322 | cancel_delayed_work_sync(&db->phy_poll); |
| 1323 | |
| 1324 | netif_stop_queue(ndev); |
| 1325 | netif_carrier_off(ndev); |
| 1326 | |
| 1327 | /* free interrupt */ |
| 1328 | free_irq(ndev->irq, ndev); |
| 1329 | |
| 1330 | dm9000_shutdown(ndev); |
| 1331 | |
| 1332 | return 0; |
| 1333 | } |
| 1334 | |
Alexander Beregalov | d88106b | 2009-04-15 12:52:37 +0000 | [diff] [blame] | 1335 | static const struct net_device_ops dm9000_netdev_ops = { |
| 1336 | .ndo_open = dm9000_open, |
| 1337 | .ndo_stop = dm9000_stop, |
| 1338 | .ndo_start_xmit = dm9000_start_xmit, |
| 1339 | .ndo_tx_timeout = dm9000_timeout, |
| 1340 | .ndo_set_multicast_list = dm9000_hash_table, |
| 1341 | .ndo_do_ioctl = dm9000_ioctl, |
| 1342 | .ndo_change_mtu = eth_change_mtu, |
| 1343 | .ndo_validate_addr = eth_validate_addr, |
| 1344 | .ndo_set_mac_address = eth_mac_addr, |
| 1345 | #ifdef CONFIG_NET_POLL_CONTROLLER |
| 1346 | .ndo_poll_controller = dm9000_poll_controller, |
| 1347 | #endif |
| 1348 | }; |
| 1349 | |
Sascha Hauer | a136527 | 2005-05-05 15:14:15 -0700 | [diff] [blame] | 1350 | /* |
| 1351 | * Search DM9000 board, allocate space and register it |
| 1352 | */ |
Enrico Scholz | e21fd4f | 2008-05-08 11:33:03 +0100 | [diff] [blame] | 1353 | static int __devinit |
Russell King | 3ae5eae | 2005-11-09 22:32:44 +0000 | [diff] [blame] | 1354 | dm9000_probe(struct platform_device *pdev) |
Sascha Hauer | a136527 | 2005-05-05 15:14:15 -0700 | [diff] [blame] | 1355 | { |
Sascha Hauer | a136527 | 2005-05-05 15:14:15 -0700 | [diff] [blame] | 1356 | struct dm9000_plat_data *pdata = pdev->dev.platform_data; |
| 1357 | struct board_info *db; /* Point a board information structure */ |
| 1358 | struct net_device *ndev; |
Ben Dooks | 179c743 | 2008-02-05 00:02:23 +0000 | [diff] [blame] | 1359 | const unsigned char *mac_src; |
Sascha Hauer | a136527 | 2005-05-05 15:14:15 -0700 | [diff] [blame] | 1360 | int ret = 0; |
| 1361 | int iosize; |
| 1362 | int i; |
| 1363 | u32 id_val; |
| 1364 | |
Sascha Hauer | a136527 | 2005-05-05 15:14:15 -0700 | [diff] [blame] | 1365 | /* Init network device */ |
Ben Dooks | f8d79e7 | 2008-06-24 22:16:02 +0100 | [diff] [blame] | 1366 | ndev = alloc_etherdev(sizeof(struct board_info)); |
Sascha Hauer | a136527 | 2005-05-05 15:14:15 -0700 | [diff] [blame] | 1367 | if (!ndev) { |
Ben Dooks | a76836f | 2008-02-05 00:02:02 +0000 | [diff] [blame] | 1368 | dev_err(&pdev->dev, "could not allocate device.\n"); |
Sascha Hauer | a136527 | 2005-05-05 15:14:15 -0700 | [diff] [blame] | 1369 | return -ENOMEM; |
| 1370 | } |
| 1371 | |
Russell King | 3ae5eae | 2005-11-09 22:32:44 +0000 | [diff] [blame] | 1372 | SET_NETDEV_DEV(ndev, &pdev->dev); |
Sascha Hauer | a136527 | 2005-05-05 15:14:15 -0700 | [diff] [blame] | 1373 | |
Enrico Scholz | 37d5dca | 2008-05-08 11:35:13 +0100 | [diff] [blame] | 1374 | dev_dbg(&pdev->dev, "dm9000_probe()\n"); |
Sascha Hauer | a136527 | 2005-05-05 15:14:15 -0700 | [diff] [blame] | 1375 | |
| 1376 | /* setup board info structure */ |
Wang Chen | 4cf1653 | 2008-11-12 23:38:14 -0800 | [diff] [blame] | 1377 | db = netdev_priv(ndev); |
Sascha Hauer | a136527 | 2005-05-05 15:14:15 -0700 | [diff] [blame] | 1378 | |
Ben Dooks | a76836f | 2008-02-05 00:02:02 +0000 | [diff] [blame] | 1379 | db->dev = &pdev->dev; |
Ben Dooks | 8f5bf5f2 | 2008-05-08 11:36:42 +0100 | [diff] [blame] | 1380 | db->ndev = ndev; |
Ben Dooks | a76836f | 2008-02-05 00:02:02 +0000 | [diff] [blame] | 1381 | |
Ben Dooks | 9ef9ac5 | 2005-07-23 17:25:18 +0100 | [diff] [blame] | 1382 | spin_lock_init(&db->lock); |
Ben Dooks | 9a2f037 | 2008-02-05 00:02:10 +0000 | [diff] [blame] | 1383 | mutex_init(&db->addr_lock); |
Ben Dooks | 9ef9ac5 | 2005-07-23 17:25:18 +0100 | [diff] [blame] | 1384 | |
Ben Dooks | 8f5bf5f2 | 2008-05-08 11:36:42 +0100 | [diff] [blame] | 1385 | INIT_DELAYED_WORK(&db->phy_poll, dm9000_poll_work); |
| 1386 | |
Laurent Pinchart | 08c3f57 | 2008-06-24 22:15:57 +0100 | [diff] [blame] | 1387 | db->addr_res = platform_get_resource(pdev, IORESOURCE_MEM, 0); |
| 1388 | db->data_res = platform_get_resource(pdev, IORESOURCE_MEM, 1); |
| 1389 | db->irq_res = platform_get_resource(pdev, IORESOURCE_IRQ, 0); |
| 1390 | |
| 1391 | if (db->addr_res == NULL || db->data_res == NULL || |
| 1392 | db->irq_res == NULL) { |
| 1393 | dev_err(db->dev, "insufficient resources\n"); |
| 1394 | ret = -ENOENT; |
| 1395 | goto out; |
| 1396 | } |
| 1397 | |
Ben Dooks | c029f44 | 2009-11-10 07:22:24 +0000 | [diff] [blame] | 1398 | db->irq_wake = platform_get_irq(pdev, 1); |
| 1399 | if (db->irq_wake >= 0) { |
| 1400 | dev_dbg(db->dev, "wakeup irq %d\n", db->irq_wake); |
| 1401 | |
| 1402 | ret = request_irq(db->irq_wake, dm9000_wol_interrupt, |
| 1403 | IRQF_SHARED, dev_name(db->dev), ndev); |
| 1404 | if (ret) { |
| 1405 | dev_err(db->dev, "cannot get wakeup irq (%d)\n", ret); |
| 1406 | } else { |
| 1407 | |
| 1408 | /* test to see if irq is really wakeup capable */ |
| 1409 | ret = set_irq_wake(db->irq_wake, 1); |
| 1410 | if (ret) { |
| 1411 | dev_err(db->dev, "irq %d cannot set wakeup (%d)\n", |
| 1412 | db->irq_wake, ret); |
| 1413 | ret = 0; |
| 1414 | } else { |
| 1415 | set_irq_wake(db->irq_wake, 0); |
| 1416 | db->wake_supported = 1; |
| 1417 | } |
| 1418 | } |
| 1419 | } |
| 1420 | |
Tobias Klauser | ec282e9 | 2009-09-09 01:07:43 +0000 | [diff] [blame] | 1421 | iosize = resource_size(db->addr_res); |
Laurent Pinchart | 08c3f57 | 2008-06-24 22:15:57 +0100 | [diff] [blame] | 1422 | db->addr_req = request_mem_region(db->addr_res->start, iosize, |
| 1423 | pdev->name); |
| 1424 | |
| 1425 | if (db->addr_req == NULL) { |
| 1426 | dev_err(db->dev, "cannot claim address reg area\n"); |
| 1427 | ret = -EIO; |
| 1428 | goto out; |
| 1429 | } |
| 1430 | |
| 1431 | db->io_addr = ioremap(db->addr_res->start, iosize); |
| 1432 | |
| 1433 | if (db->io_addr == NULL) { |
| 1434 | dev_err(db->dev, "failed to ioremap address reg\n"); |
| 1435 | ret = -EINVAL; |
| 1436 | goto out; |
| 1437 | } |
| 1438 | |
Tobias Klauser | ec282e9 | 2009-09-09 01:07:43 +0000 | [diff] [blame] | 1439 | iosize = resource_size(db->data_res); |
Laurent Pinchart | 08c3f57 | 2008-06-24 22:15:57 +0100 | [diff] [blame] | 1440 | db->data_req = request_mem_region(db->data_res->start, iosize, |
| 1441 | pdev->name); |
| 1442 | |
| 1443 | if (db->data_req == NULL) { |
| 1444 | dev_err(db->dev, "cannot claim data reg area\n"); |
| 1445 | ret = -EIO; |
| 1446 | goto out; |
| 1447 | } |
| 1448 | |
| 1449 | db->io_data = ioremap(db->data_res->start, iosize); |
| 1450 | |
| 1451 | if (db->io_data == NULL) { |
| 1452 | dev_err(db->dev, "failed to ioremap data reg\n"); |
| 1453 | ret = -EINVAL; |
| 1454 | goto out; |
| 1455 | } |
| 1456 | |
| 1457 | /* fill in parameters for net-dev structure */ |
| 1458 | ndev->base_addr = (unsigned long)db->io_addr; |
| 1459 | ndev->irq = db->irq_res->start; |
| 1460 | |
| 1461 | /* ensure at least we have a default set of IO routines */ |
| 1462 | dm9000_set_io(db, iosize); |
| 1463 | |
Sascha Hauer | a136527 | 2005-05-05 15:14:15 -0700 | [diff] [blame] | 1464 | /* check to see if anything is being over-ridden */ |
| 1465 | if (pdata != NULL) { |
| 1466 | /* check to see if the driver wants to over-ride the |
| 1467 | * default IO width */ |
| 1468 | |
| 1469 | if (pdata->flags & DM9000_PLATF_8BITONLY) |
| 1470 | dm9000_set_io(db, 1); |
| 1471 | |
| 1472 | if (pdata->flags & DM9000_PLATF_16BITONLY) |
| 1473 | dm9000_set_io(db, 2); |
| 1474 | |
| 1475 | if (pdata->flags & DM9000_PLATF_32BITONLY) |
| 1476 | dm9000_set_io(db, 4); |
| 1477 | |
| 1478 | /* check to see if there are any IO routine |
| 1479 | * over-rides */ |
| 1480 | |
| 1481 | if (pdata->inblk != NULL) |
| 1482 | db->inblk = pdata->inblk; |
| 1483 | |
| 1484 | if (pdata->outblk != NULL) |
| 1485 | db->outblk = pdata->outblk; |
| 1486 | |
| 1487 | if (pdata->dumpblk != NULL) |
| 1488 | db->dumpblk = pdata->dumpblk; |
Ben Dooks | 33ba509 | 2008-02-05 00:02:01 +0000 | [diff] [blame] | 1489 | |
| 1490 | db->flags = pdata->flags; |
Sascha Hauer | a136527 | 2005-05-05 15:14:15 -0700 | [diff] [blame] | 1491 | } |
| 1492 | |
Ben Dooks | f8dd0ec | 2008-06-24 22:16:04 +0100 | [diff] [blame] | 1493 | #ifdef CONFIG_DM9000_FORCE_SIMPLE_PHY_POLL |
| 1494 | db->flags |= DM9000_PLATF_SIMPLE_PHY; |
| 1495 | #endif |
| 1496 | |
Sascha Hauer | a136527 | 2005-05-05 15:14:15 -0700 | [diff] [blame] | 1497 | dm9000_reset(db); |
| 1498 | |
Ben Dooks | 59eae1f | 2008-06-24 22:16:01 +0100 | [diff] [blame] | 1499 | /* try multiple times, DM9000 sometimes gets the read wrong */ |
Ben Dooks | 513b6be | 2008-02-05 00:02:22 +0000 | [diff] [blame] | 1500 | for (i = 0; i < 8; i++) { |
Sascha Hauer | a136527 | 2005-05-05 15:14:15 -0700 | [diff] [blame] | 1501 | id_val = ior(db, DM9000_VIDL); |
| 1502 | id_val |= (u32)ior(db, DM9000_VIDH) << 8; |
| 1503 | id_val |= (u32)ior(db, DM9000_PIDL) << 16; |
| 1504 | id_val |= (u32)ior(db, DM9000_PIDH) << 24; |
| 1505 | |
| 1506 | if (id_val == DM9000_ID) |
| 1507 | break; |
Ben Dooks | a76836f | 2008-02-05 00:02:02 +0000 | [diff] [blame] | 1508 | dev_err(db->dev, "read wrong id 0x%08x\n", id_val); |
Sascha Hauer | a136527 | 2005-05-05 15:14:15 -0700 | [diff] [blame] | 1509 | } |
| 1510 | |
| 1511 | if (id_val != DM9000_ID) { |
Ben Dooks | a76836f | 2008-02-05 00:02:02 +0000 | [diff] [blame] | 1512 | dev_err(db->dev, "wrong id: 0x%08x\n", id_val); |
Mike Rapoport | 418d6f8 | 2007-10-18 09:23:11 +0200 | [diff] [blame] | 1513 | ret = -ENODEV; |
| 1514 | goto out; |
Sascha Hauer | a136527 | 2005-05-05 15:14:15 -0700 | [diff] [blame] | 1515 | } |
| 1516 | |
Ben Dooks | 6d406b3 | 2008-06-24 22:15:59 +0100 | [diff] [blame] | 1517 | /* Identify what type of DM9000 we are working on */ |
| 1518 | |
| 1519 | id_val = ior(db, DM9000_CHIPR); |
| 1520 | dev_dbg(db->dev, "dm9000 revision 0x%02x\n", id_val); |
| 1521 | |
| 1522 | switch (id_val) { |
| 1523 | case CHIPR_DM9000A: |
| 1524 | db->type = TYPE_DM9000A; |
| 1525 | break; |
| 1526 | case CHIPR_DM9000B: |
| 1527 | db->type = TYPE_DM9000B; |
| 1528 | break; |
| 1529 | default: |
| 1530 | dev_dbg(db->dev, "ID %02x => defaulting to DM9000E\n", id_val); |
| 1531 | db->type = TYPE_DM9000E; |
| 1532 | } |
| 1533 | |
Yeasah Pell | 5dcc60b | 2009-07-06 18:12:33 -0700 | [diff] [blame] | 1534 | /* dm9000a/b are capable of hardware checksum offload */ |
| 1535 | if (db->type == TYPE_DM9000A || db->type == TYPE_DM9000B) { |
| 1536 | db->can_csum = 1; |
| 1537 | db->rx_csum = 1; |
| 1538 | ndev->features |= NETIF_F_IP_CSUM; |
| 1539 | } |
| 1540 | |
Sascha Hauer | a136527 | 2005-05-05 15:14:15 -0700 | [diff] [blame] | 1541 | /* from this point we assume that we have found a DM9000 */ |
| 1542 | |
| 1543 | /* driver system function */ |
| 1544 | ether_setup(ndev); |
| 1545 | |
Alexander Beregalov | d88106b | 2009-04-15 12:52:37 +0000 | [diff] [blame] | 1546 | ndev->netdev_ops = &dm9000_netdev_ops; |
| 1547 | ndev->watchdog_timeo = msecs_to_jiffies(watchdog); |
| 1548 | ndev->ethtool_ops = &dm9000_ethtool_ops; |
Sascha Hauer | a136527 | 2005-05-05 15:14:15 -0700 | [diff] [blame] | 1549 | |
Sascha Hauer | a136527 | 2005-05-05 15:14:15 -0700 | [diff] [blame] | 1550 | db->msg_enable = NETIF_MSG_LINK; |
| 1551 | db->mii.phy_id_mask = 0x1f; |
| 1552 | db->mii.reg_num_mask = 0x1f; |
| 1553 | db->mii.force_media = 0; |
| 1554 | db->mii.full_duplex = 0; |
| 1555 | db->mii.dev = ndev; |
| 1556 | db->mii.mdio_read = dm9000_phy_read; |
| 1557 | db->mii.mdio_write = dm9000_phy_write; |
| 1558 | |
Ben Dooks | 179c743 | 2008-02-05 00:02:23 +0000 | [diff] [blame] | 1559 | mac_src = "eeprom"; |
| 1560 | |
Ben Dooks | 86c62fa | 2008-02-05 00:02:09 +0000 | [diff] [blame] | 1561 | /* try reading the node address from the attached EEPROM */ |
| 1562 | for (i = 0; i < 6; i += 2) |
| 1563 | dm9000_read_eeprom(db, i / 2, ndev->dev_addr+i); |
Sascha Hauer | a136527 | 2005-05-05 15:14:15 -0700 | [diff] [blame] | 1564 | |
Laurent Pinchart | fe41424 | 2008-07-23 17:41:52 +0200 | [diff] [blame] | 1565 | if (!is_valid_ether_addr(ndev->dev_addr) && pdata != NULL) { |
| 1566 | mac_src = "platform data"; |
| 1567 | memcpy(ndev->dev_addr, pdata->dev_addr, 6); |
| 1568 | } |
| 1569 | |
Ben Dooks | 5b55dda | 2006-06-13 23:50:15 +0100 | [diff] [blame] | 1570 | if (!is_valid_ether_addr(ndev->dev_addr)) { |
| 1571 | /* try reading from mac */ |
Ben Dooks | f8d79e7 | 2008-06-24 22:16:02 +0100 | [diff] [blame] | 1572 | |
Ben Dooks | 179c743 | 2008-02-05 00:02:23 +0000 | [diff] [blame] | 1573 | mac_src = "chip"; |
Ben Dooks | 5b55dda | 2006-06-13 23:50:15 +0100 | [diff] [blame] | 1574 | for (i = 0; i < 6; i++) |
| 1575 | ndev->dev_addr[i] = ior(db, i+DM9000_PAR); |
| 1576 | } |
| 1577 | |
Sascha Hauer | a136527 | 2005-05-05 15:14:15 -0700 | [diff] [blame] | 1578 | if (!is_valid_ether_addr(ndev->dev_addr)) |
Ben Dooks | a76836f | 2008-02-05 00:02:02 +0000 | [diff] [blame] | 1579 | dev_warn(db->dev, "%s: Invalid ethernet MAC address. Please " |
| 1580 | "set using ifconfig\n", ndev->name); |
Sascha Hauer | a136527 | 2005-05-05 15:14:15 -0700 | [diff] [blame] | 1581 | |
Russell King | 3ae5eae | 2005-11-09 22:32:44 +0000 | [diff] [blame] | 1582 | platform_set_drvdata(pdev, ndev); |
Sascha Hauer | a136527 | 2005-05-05 15:14:15 -0700 | [diff] [blame] | 1583 | ret = register_netdev(ndev); |
| 1584 | |
Johannes Berg | e174961 | 2008-10-27 15:59:26 -0700 | [diff] [blame] | 1585 | if (ret == 0) |
| 1586 | printk(KERN_INFO "%s: dm9000%c at %p,%p IRQ %d MAC: %pM (%s)\n", |
Ben Dooks | 6d406b3 | 2008-06-24 22:15:59 +0100 | [diff] [blame] | 1587 | ndev->name, dm9000_type_to_char(db->type), |
| 1588 | db->io_addr, db->io_data, ndev->irq, |
Johannes Berg | e174961 | 2008-10-27 15:59:26 -0700 | [diff] [blame] | 1589 | ndev->dev_addr, mac_src); |
Sascha Hauer | a136527 | 2005-05-05 15:14:15 -0700 | [diff] [blame] | 1590 | return 0; |
| 1591 | |
Mike Rapoport | 418d6f8 | 2007-10-18 09:23:11 +0200 | [diff] [blame] | 1592 | out: |
Ben Dooks | a76836f | 2008-02-05 00:02:02 +0000 | [diff] [blame] | 1593 | dev_err(db->dev, "not found (%d).\n", ret); |
Sascha Hauer | a136527 | 2005-05-05 15:14:15 -0700 | [diff] [blame] | 1594 | |
| 1595 | dm9000_release_board(pdev, db); |
Ben Dooks | 9fd9f9b | 2007-05-07 11:13:25 +0000 | [diff] [blame] | 1596 | free_netdev(ndev); |
Sascha Hauer | a136527 | 2005-05-05 15:14:15 -0700 | [diff] [blame] | 1597 | |
| 1598 | return ret; |
| 1599 | } |
| 1600 | |
Sascha Hauer | a136527 | 2005-05-05 15:14:15 -0700 | [diff] [blame] | 1601 | static int |
Mike Rapoport | 69222e2 | 2009-07-21 12:37:18 -0700 | [diff] [blame] | 1602 | dm9000_drv_suspend(struct device *dev) |
Sascha Hauer | a136527 | 2005-05-05 15:14:15 -0700 | [diff] [blame] | 1603 | { |
Mike Rapoport | 69222e2 | 2009-07-21 12:37:18 -0700 | [diff] [blame] | 1604 | struct platform_device *pdev = to_platform_device(dev); |
| 1605 | struct net_device *ndev = platform_get_drvdata(pdev); |
Ben Dooks | 321f69a | 2008-02-05 00:02:08 +0000 | [diff] [blame] | 1606 | board_info_t *db; |
Sascha Hauer | a136527 | 2005-05-05 15:14:15 -0700 | [diff] [blame] | 1607 | |
Russell King | 9480e30 | 2005-10-28 09:52:56 -0700 | [diff] [blame] | 1608 | if (ndev) { |
Wang Chen | 4cf1653 | 2008-11-12 23:38:14 -0800 | [diff] [blame] | 1609 | db = netdev_priv(ndev); |
Ben Dooks | 321f69a | 2008-02-05 00:02:08 +0000 | [diff] [blame] | 1610 | db->in_suspend = 1; |
| 1611 | |
Ben Dooks | c029f44 | 2009-11-10 07:22:24 +0000 | [diff] [blame] | 1612 | if (!netif_running(ndev)) |
| 1613 | return 0; |
| 1614 | |
| 1615 | netif_device_detach(ndev); |
| 1616 | |
| 1617 | /* only shutdown if not using WoL */ |
| 1618 | if (!db->wake_state) |
Sascha Hauer | a136527 | 2005-05-05 15:14:15 -0700 | [diff] [blame] | 1619 | dm9000_shutdown(ndev); |
Sascha Hauer | a136527 | 2005-05-05 15:14:15 -0700 | [diff] [blame] | 1620 | } |
| 1621 | return 0; |
| 1622 | } |
| 1623 | |
| 1624 | static int |
Mike Rapoport | 69222e2 | 2009-07-21 12:37:18 -0700 | [diff] [blame] | 1625 | dm9000_drv_resume(struct device *dev) |
Sascha Hauer | a136527 | 2005-05-05 15:14:15 -0700 | [diff] [blame] | 1626 | { |
Mike Rapoport | 69222e2 | 2009-07-21 12:37:18 -0700 | [diff] [blame] | 1627 | struct platform_device *pdev = to_platform_device(dev); |
| 1628 | struct net_device *ndev = platform_get_drvdata(pdev); |
Wang Chen | 4cf1653 | 2008-11-12 23:38:14 -0800 | [diff] [blame] | 1629 | board_info_t *db = netdev_priv(ndev); |
Sascha Hauer | a136527 | 2005-05-05 15:14:15 -0700 | [diff] [blame] | 1630 | |
Russell King | 9480e30 | 2005-10-28 09:52:56 -0700 | [diff] [blame] | 1631 | if (ndev) { |
Sascha Hauer | a136527 | 2005-05-05 15:14:15 -0700 | [diff] [blame] | 1632 | if (netif_running(ndev)) { |
Ben Dooks | c029f44 | 2009-11-10 07:22:24 +0000 | [diff] [blame] | 1633 | /* reset if we were not in wake mode to ensure if |
| 1634 | * the device was powered off it is in a known state */ |
| 1635 | if (!db->wake_state) { |
| 1636 | dm9000_reset(db); |
| 1637 | dm9000_init_dm9000(ndev); |
| 1638 | } |
Sascha Hauer | a136527 | 2005-05-05 15:14:15 -0700 | [diff] [blame] | 1639 | |
| 1640 | netif_device_attach(ndev); |
| 1641 | } |
Ben Dooks | 321f69a | 2008-02-05 00:02:08 +0000 | [diff] [blame] | 1642 | |
| 1643 | db->in_suspend = 0; |
Sascha Hauer | a136527 | 2005-05-05 15:14:15 -0700 | [diff] [blame] | 1644 | } |
| 1645 | return 0; |
| 1646 | } |
| 1647 | |
Alexey Dobriyan | 4714521 | 2009-12-14 18:00:08 -0800 | [diff] [blame] | 1648 | static const struct dev_pm_ops dm9000_drv_pm_ops = { |
Mike Rapoport | 69222e2 | 2009-07-21 12:37:18 -0700 | [diff] [blame] | 1649 | .suspend = dm9000_drv_suspend, |
| 1650 | .resume = dm9000_drv_resume, |
| 1651 | }; |
| 1652 | |
Enrico Scholz | e21fd4f | 2008-05-08 11:33:03 +0100 | [diff] [blame] | 1653 | static int __devexit |
Russell King | 3ae5eae | 2005-11-09 22:32:44 +0000 | [diff] [blame] | 1654 | dm9000_drv_remove(struct platform_device *pdev) |
Sascha Hauer | a136527 | 2005-05-05 15:14:15 -0700 | [diff] [blame] | 1655 | { |
Russell King | 3ae5eae | 2005-11-09 22:32:44 +0000 | [diff] [blame] | 1656 | struct net_device *ndev = platform_get_drvdata(pdev); |
Sascha Hauer | a136527 | 2005-05-05 15:14:15 -0700 | [diff] [blame] | 1657 | |
Russell King | 3ae5eae | 2005-11-09 22:32:44 +0000 | [diff] [blame] | 1658 | platform_set_drvdata(pdev, NULL); |
Sascha Hauer | a136527 | 2005-05-05 15:14:15 -0700 | [diff] [blame] | 1659 | |
| 1660 | unregister_netdev(ndev); |
David S. Miller | 6817ba2 | 2008-11-16 12:41:35 -0800 | [diff] [blame] | 1661 | dm9000_release_board(pdev, (board_info_t *) netdev_priv(ndev)); |
Ben Dooks | 9fd9f9b | 2007-05-07 11:13:25 +0000 | [diff] [blame] | 1662 | free_netdev(ndev); /* free device structure */ |
Sascha Hauer | a136527 | 2005-05-05 15:14:15 -0700 | [diff] [blame] | 1663 | |
Ben Dooks | a76836f | 2008-02-05 00:02:02 +0000 | [diff] [blame] | 1664 | dev_dbg(&pdev->dev, "released and freed device\n"); |
Sascha Hauer | a136527 | 2005-05-05 15:14:15 -0700 | [diff] [blame] | 1665 | return 0; |
| 1666 | } |
| 1667 | |
Russell King | 3ae5eae | 2005-11-09 22:32:44 +0000 | [diff] [blame] | 1668 | static struct platform_driver dm9000_driver = { |
Ben Dooks | 5d22a31 | 2006-06-14 00:09:17 +0100 | [diff] [blame] | 1669 | .driver = { |
| 1670 | .name = "dm9000", |
| 1671 | .owner = THIS_MODULE, |
Mike Rapoport | 69222e2 | 2009-07-21 12:37:18 -0700 | [diff] [blame] | 1672 | .pm = &dm9000_drv_pm_ops, |
Ben Dooks | 5d22a31 | 2006-06-14 00:09:17 +0100 | [diff] [blame] | 1673 | }, |
Sascha Hauer | a136527 | 2005-05-05 15:14:15 -0700 | [diff] [blame] | 1674 | .probe = dm9000_probe, |
Enrico Scholz | e21fd4f | 2008-05-08 11:33:03 +0100 | [diff] [blame] | 1675 | .remove = __devexit_p(dm9000_drv_remove), |
Sascha Hauer | a136527 | 2005-05-05 15:14:15 -0700 | [diff] [blame] | 1676 | }; |
| 1677 | |
| 1678 | static int __init |
| 1679 | dm9000_init(void) |
| 1680 | { |
Ben Dooks | 7da9985 | 2008-02-05 00:02:06 +0000 | [diff] [blame] | 1681 | printk(KERN_INFO "%s Ethernet Driver, V%s\n", CARDNAME, DRV_VERSION); |
Ben Dooks | 2ae2d77 | 2005-07-23 17:29:38 +0100 | [diff] [blame] | 1682 | |
Ben Dooks | 59eae1f | 2008-06-24 22:16:01 +0100 | [diff] [blame] | 1683 | return platform_driver_register(&dm9000_driver); |
Sascha Hauer | a136527 | 2005-05-05 15:14:15 -0700 | [diff] [blame] | 1684 | } |
| 1685 | |
| 1686 | static void __exit |
| 1687 | dm9000_cleanup(void) |
| 1688 | { |
Russell King | 3ae5eae | 2005-11-09 22:32:44 +0000 | [diff] [blame] | 1689 | platform_driver_unregister(&dm9000_driver); |
Sascha Hauer | a136527 | 2005-05-05 15:14:15 -0700 | [diff] [blame] | 1690 | } |
| 1691 | |
| 1692 | module_init(dm9000_init); |
| 1693 | module_exit(dm9000_cleanup); |
| 1694 | |
| 1695 | MODULE_AUTHOR("Sascha Hauer, Ben Dooks"); |
| 1696 | MODULE_DESCRIPTION("Davicom DM9000 network driver"); |
| 1697 | MODULE_LICENSE("GPL"); |
Kay Sievers | 72abb46 | 2008-04-18 13:50:44 -0700 | [diff] [blame] | 1698 | MODULE_ALIAS("platform:dm9000"); |