Sascha Hauer | a136527 | 2005-05-05 15:14:15 -0700 | [diff] [blame] | 1 | /* |
| 2 | * dm9000.c: Version 1.2 03/18/2003 |
| 3 | * |
| 4 | * A Davicom DM9000 ISA NIC fast Ethernet driver for Linux. |
| 5 | * Copyright (C) 1997 Sten Wang |
| 6 | * |
| 7 | * This program is free software; you can redistribute it and/or |
| 8 | * modify it under the terms of the GNU General Public License |
| 9 | * as published by the Free Software Foundation; either version 2 |
| 10 | * of the License, or (at your option) any later version. |
| 11 | * |
| 12 | * This program is distributed in the hope that it will be useful, |
| 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 15 | * GNU General Public License for more details. |
| 16 | * |
| 17 | * (C)Copyright 1997-1998 DAVICOM Semiconductor,Inc. All Rights Reserved. |
| 18 | * |
| 19 | * V0.11 06/20/2001 REG_0A bit3=1, default enable BP with DA match |
| 20 | * 06/22/2001 Support DM9801 progrmming |
| 21 | * E3: R25 = ((R24 + NF) & 0x00ff) | 0xf000 |
| 22 | * E4: R25 = ((R24 + NF) & 0x00ff) | 0xc200 |
| 23 | * R17 = (R17 & 0xfff0) | NF + 3 |
| 24 | * E5: R25 = ((R24 + NF - 3) & 0x00ff) | 0xc200 |
| 25 | * R17 = (R17 & 0xfff0) | NF |
| 26 | * |
| 27 | * v1.00 modify by simon 2001.9.5 |
| 28 | * change for kernel 2.4.x |
| 29 | * |
| 30 | * v1.1 11/09/2001 fix force mode bug |
| 31 | * |
| 32 | * v1.2 03/18/2003 Weilun Huang <weilun_huang@davicom.com.tw>: |
| 33 | * Fixed phy reset. |
| 34 | * Added tx/rx 32 bit mode. |
| 35 | * Cleaned up for kernel merge. |
| 36 | * |
| 37 | * 03/03/2004 Sascha Hauer <s.hauer@pengutronix.de> |
| 38 | * Port to 2.6 kernel |
| 39 | * |
| 40 | * 24-Sep-2004 Ben Dooks <ben@simtec.co.uk> |
| 41 | * Cleanup of code to remove ifdefs |
| 42 | * Allowed platform device data to influence access width |
| 43 | * Reformatting areas of code |
| 44 | * |
| 45 | * 17-Mar-2005 Sascha Hauer <s.hauer@pengutronix.de> |
| 46 | * * removed 2.4 style module parameters |
| 47 | * * removed removed unused stat counter and fixed |
| 48 | * net_device_stats |
| 49 | * * introduced tx_timeout function |
| 50 | * * reworked locking |
Ben Dooks | 9ef9ac5 | 2005-07-23 17:25:18 +0100 | [diff] [blame] | 51 | * |
| 52 | * 01-Jul-2005 Ben Dooks <ben@simtec.co.uk> |
| 53 | * * fixed spinlock call without pointer |
| 54 | * * ensure spinlock is initialised |
Sascha Hauer | a136527 | 2005-05-05 15:14:15 -0700 | [diff] [blame] | 55 | */ |
| 56 | |
| 57 | #include <linux/module.h> |
| 58 | #include <linux/ioport.h> |
| 59 | #include <linux/netdevice.h> |
| 60 | #include <linux/etherdevice.h> |
| 61 | #include <linux/init.h> |
| 62 | #include <linux/skbuff.h> |
Sascha Hauer | a136527 | 2005-05-05 15:14:15 -0700 | [diff] [blame] | 63 | #include <linux/spinlock.h> |
| 64 | #include <linux/crc32.h> |
| 65 | #include <linux/mii.h> |
Ben Dooks | 7da9985 | 2008-02-05 00:02:06 +0000 | [diff] [blame] | 66 | #include <linux/ethtool.h> |
Sascha Hauer | a136527 | 2005-05-05 15:14:15 -0700 | [diff] [blame] | 67 | #include <linux/dm9000.h> |
| 68 | #include <linux/delay.h> |
Russell King | d052d1b | 2005-10-29 19:07:23 +0100 | [diff] [blame] | 69 | #include <linux/platform_device.h> |
Daniel Mack | 4e4fc05 | 2008-01-23 14:54:50 +0100 | [diff] [blame] | 70 | #include <linux/irq.h> |
Sascha Hauer | a136527 | 2005-05-05 15:14:15 -0700 | [diff] [blame] | 71 | |
| 72 | #include <asm/delay.h> |
| 73 | #include <asm/irq.h> |
| 74 | #include <asm/io.h> |
| 75 | |
| 76 | #include "dm9000.h" |
| 77 | |
| 78 | /* Board/System/Debug information/definition ---------------- */ |
| 79 | |
| 80 | #define DM9000_PHY 0x40 /* PHY address 0x01 */ |
| 81 | |
Sascha Hauer | a136527 | 2005-05-05 15:14:15 -0700 | [diff] [blame] | 82 | #define CARDNAME "dm9000" |
| 83 | #define PFX CARDNAME ": " |
Ben Dooks | 7da9985 | 2008-02-05 00:02:06 +0000 | [diff] [blame] | 84 | #define DRV_VERSION "1.30" |
Sascha Hauer | a136527 | 2005-05-05 15:14:15 -0700 | [diff] [blame] | 85 | |
Alex Landau | f40d24d | 2007-07-12 12:11:48 +0800 | [diff] [blame] | 86 | #ifdef CONFIG_BLACKFIN |
| 87 | #define readsb insb |
| 88 | #define readsw insw |
| 89 | #define readsl insl |
| 90 | #define writesb outsb |
| 91 | #define writesw outsw |
| 92 | #define writesl outsl |
Ben Dooks | 1a5f1c4 | 2008-02-05 00:02:04 +0000 | [diff] [blame] | 93 | #define DEFAULT_TRIGGER IRQF_TRIGGER_HIGH |
Alex Landau | f40d24d | 2007-07-12 12:11:48 +0800 | [diff] [blame] | 94 | #else |
Ben Dooks | 1a5f1c4 | 2008-02-05 00:02:04 +0000 | [diff] [blame] | 95 | #define DEFAULT_TRIGGER (0) |
Alex Landau | f40d24d | 2007-07-12 12:11:48 +0800 | [diff] [blame] | 96 | #endif |
| 97 | |
Sascha Hauer | a136527 | 2005-05-05 15:14:15 -0700 | [diff] [blame] | 98 | /* |
| 99 | * Transmit timeout, default 5 seconds. |
| 100 | */ |
| 101 | static int watchdog = 5000; |
| 102 | module_param(watchdog, int, 0400); |
| 103 | MODULE_PARM_DESC(watchdog, "transmit timeout in milliseconds"); |
| 104 | |
| 105 | /* Structure/enum declaration ------------------------------- */ |
| 106 | typedef struct board_info { |
| 107 | |
| 108 | void __iomem *io_addr; /* Register I/O base address */ |
| 109 | void __iomem *io_data; /* Data I/O address */ |
| 110 | u16 irq; /* IRQ */ |
| 111 | |
| 112 | u16 tx_pkt_cnt; |
| 113 | u16 queue_pkt_len; |
| 114 | u16 queue_start_addr; |
| 115 | u16 dbug_cnt; |
| 116 | u8 io_mode; /* 0:word, 2:byte */ |
| 117 | u8 phy_addr; |
Ben Dooks | 33ba509 | 2008-02-05 00:02:01 +0000 | [diff] [blame] | 118 | unsigned int flags; |
Ben Dooks | 321f69a | 2008-02-05 00:02:08 +0000 | [diff] [blame] | 119 | unsigned int in_suspend :1; |
Sascha Hauer | a136527 | 2005-05-05 15:14:15 -0700 | [diff] [blame] | 120 | |
Ben Dooks | 5b2b4ff | 2008-02-05 00:02:03 +0000 | [diff] [blame] | 121 | int debug_level; |
| 122 | |
Sascha Hauer | a136527 | 2005-05-05 15:14:15 -0700 | [diff] [blame] | 123 | void (*inblk)(void __iomem *port, void *data, int length); |
| 124 | void (*outblk)(void __iomem *port, void *data, int length); |
| 125 | void (*dumpblk)(void __iomem *port, int length); |
| 126 | |
Ben Dooks | a76836f | 2008-02-05 00:02:02 +0000 | [diff] [blame] | 127 | struct device *dev; /* parent device */ |
| 128 | |
Sascha Hauer | a136527 | 2005-05-05 15:14:15 -0700 | [diff] [blame] | 129 | struct resource *addr_res; /* resources found */ |
| 130 | struct resource *data_res; |
| 131 | struct resource *addr_req; /* resources requested */ |
| 132 | struct resource *data_req; |
| 133 | struct resource *irq_res; |
| 134 | |
Sascha Hauer | a136527 | 2005-05-05 15:14:15 -0700 | [diff] [blame] | 135 | spinlock_t lock; |
| 136 | |
| 137 | struct mii_if_info mii; |
| 138 | u32 msg_enable; |
| 139 | } board_info_t; |
| 140 | |
Ben Dooks | 5b2b4ff | 2008-02-05 00:02:03 +0000 | [diff] [blame] | 141 | /* debug code */ |
| 142 | |
| 143 | #define dm9000_dbg(db, lev, msg...) do { \ |
| 144 | if ((lev) < CONFIG_DM9000_DEBUGLEVEL && \ |
| 145 | (lev) < db->debug_level) { \ |
| 146 | dev_dbg(db->dev, msg); \ |
| 147 | } \ |
| 148 | } while (0) |
| 149 | |
Ben Dooks | 7da9985 | 2008-02-05 00:02:06 +0000 | [diff] [blame] | 150 | static inline board_info_t *to_dm9000_board(struct net_device *dev) |
| 151 | { |
| 152 | return dev->priv; |
| 153 | } |
| 154 | |
Sascha Hauer | a136527 | 2005-05-05 15:14:15 -0700 | [diff] [blame] | 155 | /* function declaration ------------------------------------- */ |
Russell King | 3ae5eae | 2005-11-09 22:32:44 +0000 | [diff] [blame] | 156 | static int dm9000_probe(struct platform_device *); |
Sascha Hauer | a136527 | 2005-05-05 15:14:15 -0700 | [diff] [blame] | 157 | static int dm9000_open(struct net_device *); |
| 158 | static int dm9000_start_xmit(struct sk_buff *, struct net_device *); |
| 159 | static int dm9000_stop(struct net_device *); |
Sascha Hauer | a136527 | 2005-05-05 15:14:15 -0700 | [diff] [blame] | 160 | |
Sascha Hauer | a136527 | 2005-05-05 15:14:15 -0700 | [diff] [blame] | 161 | static void dm9000_init_dm9000(struct net_device *); |
| 162 | |
David Howells | 7d12e78 | 2006-10-05 14:55:46 +0100 | [diff] [blame] | 163 | static irqreturn_t dm9000_interrupt(int, void *); |
Sascha Hauer | a136527 | 2005-05-05 15:14:15 -0700 | [diff] [blame] | 164 | |
| 165 | static int dm9000_phy_read(struct net_device *dev, int phyaddr_unsused, int reg); |
| 166 | static void dm9000_phy_write(struct net_device *dev, int phyaddr_unused, int reg, |
| 167 | int value); |
Ben Dooks | 86c62fa | 2008-02-05 00:02:09 +0000 | [diff] [blame^] | 168 | |
| 169 | static void dm9000_read_eeprom(board_info_t *, int addr, unsigned char *to); |
Sascha Hauer | a136527 | 2005-05-05 15:14:15 -0700 | [diff] [blame] | 170 | static void dm9000_rx(struct net_device *); |
| 171 | static void dm9000_hash_table(struct net_device *); |
| 172 | |
| 173 | //#define DM9000_PROGRAM_EEPROM |
| 174 | #ifdef DM9000_PROGRAM_EEPROM |
| 175 | static void program_eeprom(board_info_t * db); |
| 176 | #endif |
| 177 | /* DM9000 network board routine ---------------------------- */ |
| 178 | |
| 179 | static void |
| 180 | dm9000_reset(board_info_t * db) |
| 181 | { |
Ben Dooks | a76836f | 2008-02-05 00:02:02 +0000 | [diff] [blame] | 182 | dev_dbg(db->dev, "resetting device\n"); |
| 183 | |
Sascha Hauer | a136527 | 2005-05-05 15:14:15 -0700 | [diff] [blame] | 184 | /* RESET device */ |
| 185 | writeb(DM9000_NCR, db->io_addr); |
| 186 | udelay(200); |
| 187 | writeb(NCR_RST, db->io_data); |
| 188 | udelay(200); |
| 189 | } |
| 190 | |
| 191 | /* |
| 192 | * Read a byte from I/O port |
| 193 | */ |
| 194 | static u8 |
| 195 | ior(board_info_t * db, int reg) |
| 196 | { |
| 197 | writeb(reg, db->io_addr); |
| 198 | return readb(db->io_data); |
| 199 | } |
| 200 | |
| 201 | /* |
| 202 | * Write a byte to I/O port |
| 203 | */ |
| 204 | |
| 205 | static void |
| 206 | iow(board_info_t * db, int reg, int value) |
| 207 | { |
| 208 | writeb(reg, db->io_addr); |
| 209 | writeb(value, db->io_data); |
| 210 | } |
| 211 | |
| 212 | /* routines for sending block to chip */ |
| 213 | |
| 214 | static void dm9000_outblk_8bit(void __iomem *reg, void *data, int count) |
| 215 | { |
| 216 | writesb(reg, data, count); |
| 217 | } |
| 218 | |
| 219 | static void dm9000_outblk_16bit(void __iomem *reg, void *data, int count) |
| 220 | { |
| 221 | writesw(reg, data, (count+1) >> 1); |
| 222 | } |
| 223 | |
| 224 | static void dm9000_outblk_32bit(void __iomem *reg, void *data, int count) |
| 225 | { |
| 226 | writesl(reg, data, (count+3) >> 2); |
| 227 | } |
| 228 | |
| 229 | /* input block from chip to memory */ |
| 230 | |
| 231 | static void dm9000_inblk_8bit(void __iomem *reg, void *data, int count) |
| 232 | { |
Sascha Hauer | 5f6b551 | 2005-06-20 15:32:51 -0700 | [diff] [blame] | 233 | readsb(reg, data, count); |
Sascha Hauer | a136527 | 2005-05-05 15:14:15 -0700 | [diff] [blame] | 234 | } |
| 235 | |
| 236 | |
| 237 | static void dm9000_inblk_16bit(void __iomem *reg, void *data, int count) |
| 238 | { |
| 239 | readsw(reg, data, (count+1) >> 1); |
| 240 | } |
| 241 | |
| 242 | static void dm9000_inblk_32bit(void __iomem *reg, void *data, int count) |
| 243 | { |
| 244 | readsl(reg, data, (count+3) >> 2); |
| 245 | } |
| 246 | |
| 247 | /* dump block from chip to null */ |
| 248 | |
| 249 | static void dm9000_dumpblk_8bit(void __iomem *reg, int count) |
| 250 | { |
| 251 | int i; |
| 252 | int tmp; |
| 253 | |
| 254 | for (i = 0; i < count; i++) |
| 255 | tmp = readb(reg); |
| 256 | } |
| 257 | |
| 258 | static void dm9000_dumpblk_16bit(void __iomem *reg, int count) |
| 259 | { |
| 260 | int i; |
| 261 | int tmp; |
| 262 | |
| 263 | count = (count + 1) >> 1; |
| 264 | |
| 265 | for (i = 0; i < count; i++) |
| 266 | tmp = readw(reg); |
| 267 | } |
| 268 | |
| 269 | static void dm9000_dumpblk_32bit(void __iomem *reg, int count) |
| 270 | { |
| 271 | int i; |
| 272 | int tmp; |
| 273 | |
| 274 | count = (count + 3) >> 2; |
| 275 | |
| 276 | for (i = 0; i < count; i++) |
| 277 | tmp = readl(reg); |
| 278 | } |
| 279 | |
| 280 | /* dm9000_set_io |
| 281 | * |
| 282 | * select the specified set of io routines to use with the |
| 283 | * device |
| 284 | */ |
| 285 | |
| 286 | static void dm9000_set_io(struct board_info *db, int byte_width) |
| 287 | { |
| 288 | /* use the size of the data resource to work out what IO |
| 289 | * routines we want to use |
| 290 | */ |
| 291 | |
| 292 | switch (byte_width) { |
| 293 | case 1: |
| 294 | db->dumpblk = dm9000_dumpblk_8bit; |
| 295 | db->outblk = dm9000_outblk_8bit; |
| 296 | db->inblk = dm9000_inblk_8bit; |
| 297 | break; |
| 298 | |
Sascha Hauer | a136527 | 2005-05-05 15:14:15 -0700 | [diff] [blame] | 299 | |
| 300 | case 3: |
Ben Dooks | a76836f | 2008-02-05 00:02:02 +0000 | [diff] [blame] | 301 | dev_dbg(db->dev, ": 3 byte IO, falling back to 16bit\n"); |
| 302 | case 2: |
Sascha Hauer | a136527 | 2005-05-05 15:14:15 -0700 | [diff] [blame] | 303 | db->dumpblk = dm9000_dumpblk_16bit; |
| 304 | db->outblk = dm9000_outblk_16bit; |
| 305 | db->inblk = dm9000_inblk_16bit; |
| 306 | break; |
| 307 | |
| 308 | case 4: |
| 309 | default: |
| 310 | db->dumpblk = dm9000_dumpblk_32bit; |
| 311 | db->outblk = dm9000_outblk_32bit; |
| 312 | db->inblk = dm9000_inblk_32bit; |
| 313 | break; |
| 314 | } |
| 315 | } |
| 316 | |
| 317 | |
| 318 | /* Our watchdog timed out. Called by the networking layer */ |
| 319 | static void dm9000_timeout(struct net_device *dev) |
| 320 | { |
| 321 | board_info_t *db = (board_info_t *) dev->priv; |
| 322 | u8 reg_save; |
| 323 | unsigned long flags; |
| 324 | |
| 325 | /* Save previous register address */ |
| 326 | reg_save = readb(db->io_addr); |
Ben Dooks | 9ef9ac5 | 2005-07-23 17:25:18 +0100 | [diff] [blame] | 327 | spin_lock_irqsave(&db->lock,flags); |
Sascha Hauer | a136527 | 2005-05-05 15:14:15 -0700 | [diff] [blame] | 328 | |
| 329 | netif_stop_queue(dev); |
| 330 | dm9000_reset(db); |
| 331 | dm9000_init_dm9000(dev); |
| 332 | /* We can accept TX packets again */ |
| 333 | dev->trans_start = jiffies; |
| 334 | netif_wake_queue(dev); |
| 335 | |
| 336 | /* Restore previous register address */ |
| 337 | writeb(reg_save, db->io_addr); |
Ben Dooks | 9ef9ac5 | 2005-07-23 17:25:18 +0100 | [diff] [blame] | 338 | spin_unlock_irqrestore(&db->lock,flags); |
Sascha Hauer | a136527 | 2005-05-05 15:14:15 -0700 | [diff] [blame] | 339 | } |
| 340 | |
Kevin Hao | 2fd0e33 | 2006-08-14 23:00:15 -0700 | [diff] [blame] | 341 | #ifdef CONFIG_NET_POLL_CONTROLLER |
| 342 | /* |
| 343 | *Used by netconsole |
| 344 | */ |
| 345 | static void dm9000_poll_controller(struct net_device *dev) |
| 346 | { |
| 347 | disable_irq(dev->irq); |
Al Viro | 2843114 | 2006-10-08 15:00:12 +0100 | [diff] [blame] | 348 | dm9000_interrupt(dev->irq,dev); |
Kevin Hao | 2fd0e33 | 2006-08-14 23:00:15 -0700 | [diff] [blame] | 349 | enable_irq(dev->irq); |
| 350 | } |
| 351 | #endif |
Sascha Hauer | a136527 | 2005-05-05 15:14:15 -0700 | [diff] [blame] | 352 | |
Ben Dooks | 7da9985 | 2008-02-05 00:02:06 +0000 | [diff] [blame] | 353 | /* ethtool ops */ |
| 354 | |
| 355 | static void dm9000_get_drvinfo(struct net_device *dev, |
| 356 | struct ethtool_drvinfo *info) |
| 357 | { |
| 358 | board_info_t *dm = to_dm9000_board(dev); |
| 359 | |
| 360 | strcpy(info->driver, CARDNAME); |
| 361 | strcpy(info->version, DRV_VERSION); |
| 362 | strcpy(info->bus_info, to_platform_device(dm->dev)->name); |
| 363 | } |
| 364 | |
| 365 | static int dm9000_get_settings(struct net_device *dev, struct ethtool_cmd *cmd) |
| 366 | { |
| 367 | board_info_t *dm = to_dm9000_board(dev); |
| 368 | unsigned long flags; |
| 369 | |
| 370 | spin_lock_irqsave(&dm->lock, flags); |
| 371 | mii_ethtool_gset(&dm->mii, cmd); |
| 372 | spin_lock_irqsave(&dm->lock, flags); |
| 373 | |
| 374 | return 0; |
| 375 | } |
| 376 | |
| 377 | static int dm9000_set_settings(struct net_device *dev, struct ethtool_cmd *cmd) |
| 378 | { |
| 379 | board_info_t *dm = to_dm9000_board(dev); |
| 380 | unsigned long flags; |
| 381 | int rc; |
| 382 | |
| 383 | spin_lock_irqsave(&dm->lock, flags); |
| 384 | rc = mii_ethtool_sset(&dm->mii, cmd); |
| 385 | spin_lock_irqsave(&dm->lock, flags); |
| 386 | |
| 387 | return rc; |
| 388 | } |
| 389 | |
| 390 | static int dm9000_nway_reset(struct net_device *dev) |
| 391 | { |
| 392 | board_info_t *dm = to_dm9000_board(dev); |
| 393 | return mii_nway_restart(&dm->mii); |
| 394 | } |
| 395 | |
| 396 | static u32 dm9000_get_link(struct net_device *dev) |
| 397 | { |
| 398 | board_info_t *dm = to_dm9000_board(dev); |
| 399 | return mii_link_ok(&dm->mii); |
| 400 | } |
| 401 | |
| 402 | static const struct ethtool_ops dm9000_ethtool_ops = { |
| 403 | .get_drvinfo = dm9000_get_drvinfo, |
| 404 | .get_settings = dm9000_get_settings, |
| 405 | .set_settings = dm9000_set_settings, |
| 406 | .nway_reset = dm9000_nway_reset, |
| 407 | .get_link = dm9000_get_link, |
| 408 | }; |
| 409 | |
| 410 | |
Sascha Hauer | a136527 | 2005-05-05 15:14:15 -0700 | [diff] [blame] | 411 | /* dm9000_release_board |
| 412 | * |
| 413 | * release a board, and any mapped resources |
| 414 | */ |
| 415 | |
| 416 | static void |
| 417 | dm9000_release_board(struct platform_device *pdev, struct board_info *db) |
| 418 | { |
| 419 | if (db->data_res == NULL) { |
| 420 | if (db->addr_res != NULL) |
| 421 | release_mem_region((unsigned long)db->io_addr, 4); |
| 422 | return; |
| 423 | } |
| 424 | |
| 425 | /* unmap our resources */ |
| 426 | |
| 427 | iounmap(db->io_addr); |
| 428 | iounmap(db->io_data); |
| 429 | |
| 430 | /* release the resources */ |
| 431 | |
| 432 | if (db->data_req != NULL) { |
| 433 | release_resource(db->data_req); |
| 434 | kfree(db->data_req); |
| 435 | } |
| 436 | |
Dirk Opfer | 5198548 | 2006-09-06 19:53:32 +0200 | [diff] [blame] | 437 | if (db->addr_req != NULL) { |
| 438 | release_resource(db->addr_req); |
Sascha Hauer | a136527 | 2005-05-05 15:14:15 -0700 | [diff] [blame] | 439 | kfree(db->addr_req); |
| 440 | } |
| 441 | } |
| 442 | |
| 443 | #define res_size(_r) (((_r)->end - (_r)->start) + 1) |
| 444 | |
| 445 | /* |
| 446 | * Search DM9000 board, allocate space and register it |
| 447 | */ |
| 448 | static int |
Russell King | 3ae5eae | 2005-11-09 22:32:44 +0000 | [diff] [blame] | 449 | dm9000_probe(struct platform_device *pdev) |
Sascha Hauer | a136527 | 2005-05-05 15:14:15 -0700 | [diff] [blame] | 450 | { |
Sascha Hauer | a136527 | 2005-05-05 15:14:15 -0700 | [diff] [blame] | 451 | struct dm9000_plat_data *pdata = pdev->dev.platform_data; |
| 452 | struct board_info *db; /* Point a board information structure */ |
| 453 | struct net_device *ndev; |
| 454 | unsigned long base; |
| 455 | int ret = 0; |
| 456 | int iosize; |
| 457 | int i; |
| 458 | u32 id_val; |
| 459 | |
Sascha Hauer | a136527 | 2005-05-05 15:14:15 -0700 | [diff] [blame] | 460 | /* Init network device */ |
| 461 | ndev = alloc_etherdev(sizeof (struct board_info)); |
| 462 | if (!ndev) { |
Ben Dooks | a76836f | 2008-02-05 00:02:02 +0000 | [diff] [blame] | 463 | dev_err(&pdev->dev, "could not allocate device.\n"); |
Sascha Hauer | a136527 | 2005-05-05 15:14:15 -0700 | [diff] [blame] | 464 | return -ENOMEM; |
| 465 | } |
| 466 | |
Russell King | 3ae5eae | 2005-11-09 22:32:44 +0000 | [diff] [blame] | 467 | SET_NETDEV_DEV(ndev, &pdev->dev); |
Sascha Hauer | a136527 | 2005-05-05 15:14:15 -0700 | [diff] [blame] | 468 | |
Ben Dooks | a76836f | 2008-02-05 00:02:02 +0000 | [diff] [blame] | 469 | dev_dbg(&pdev->dev, "dm9000_probe()"); |
Sascha Hauer | a136527 | 2005-05-05 15:14:15 -0700 | [diff] [blame] | 470 | |
| 471 | /* setup board info structure */ |
| 472 | db = (struct board_info *) ndev->priv; |
| 473 | memset(db, 0, sizeof (*db)); |
| 474 | |
Ben Dooks | a76836f | 2008-02-05 00:02:02 +0000 | [diff] [blame] | 475 | db->dev = &pdev->dev; |
| 476 | |
Ben Dooks | 9ef9ac5 | 2005-07-23 17:25:18 +0100 | [diff] [blame] | 477 | spin_lock_init(&db->lock); |
| 478 | |
Sascha Hauer | a136527 | 2005-05-05 15:14:15 -0700 | [diff] [blame] | 479 | if (pdev->num_resources < 2) { |
| 480 | ret = -ENODEV; |
| 481 | goto out; |
Ben Dooks | b4ed03f | 2006-06-13 23:47:19 +0100 | [diff] [blame] | 482 | } else if (pdev->num_resources == 2) { |
Sascha Hauer | a136527 | 2005-05-05 15:14:15 -0700 | [diff] [blame] | 483 | base = pdev->resource[0].start; |
| 484 | |
| 485 | if (!request_mem_region(base, 4, ndev->name)) { |
| 486 | ret = -EBUSY; |
| 487 | goto out; |
| 488 | } |
| 489 | |
| 490 | ndev->base_addr = base; |
| 491 | ndev->irq = pdev->resource[1].start; |
Ben Dooks | b4ed03f | 2006-06-13 23:47:19 +0100 | [diff] [blame] | 492 | db->io_addr = (void __iomem *)base; |
| 493 | db->io_data = (void __iomem *)(base + 4); |
Sascha Hauer | a136527 | 2005-05-05 15:14:15 -0700 | [diff] [blame] | 494 | |
Alex Landau | f40d24d | 2007-07-12 12:11:48 +0800 | [diff] [blame] | 495 | /* ensure at least we have a default set of IO routines */ |
| 496 | dm9000_set_io(db, 2); |
| 497 | |
Ben Dooks | b4ed03f | 2006-06-13 23:47:19 +0100 | [diff] [blame] | 498 | } else { |
Sascha Hauer | a136527 | 2005-05-05 15:14:15 -0700 | [diff] [blame] | 499 | db->addr_res = platform_get_resource(pdev, IORESOURCE_MEM, 0); |
| 500 | db->data_res = platform_get_resource(pdev, IORESOURCE_MEM, 1); |
| 501 | db->irq_res = platform_get_resource(pdev, IORESOURCE_IRQ, 0); |
| 502 | |
Ben Dooks | b4ed03f | 2006-06-13 23:47:19 +0100 | [diff] [blame] | 503 | if (db->addr_res == NULL || db->data_res == NULL || |
| 504 | db->irq_res == NULL) { |
Ben Dooks | a76836f | 2008-02-05 00:02:02 +0000 | [diff] [blame] | 505 | dev_err(db->dev, "insufficient resources\n"); |
Sascha Hauer | a136527 | 2005-05-05 15:14:15 -0700 | [diff] [blame] | 506 | ret = -ENOENT; |
| 507 | goto out; |
| 508 | } |
| 509 | |
| 510 | i = res_size(db->addr_res); |
| 511 | db->addr_req = request_mem_region(db->addr_res->start, i, |
| 512 | pdev->name); |
| 513 | |
| 514 | if (db->addr_req == NULL) { |
Ben Dooks | a76836f | 2008-02-05 00:02:02 +0000 | [diff] [blame] | 515 | dev_err(db->dev, "cannot claim address reg area\n"); |
Sascha Hauer | a136527 | 2005-05-05 15:14:15 -0700 | [diff] [blame] | 516 | ret = -EIO; |
| 517 | goto out; |
| 518 | } |
| 519 | |
| 520 | db->io_addr = ioremap(db->addr_res->start, i); |
| 521 | |
| 522 | if (db->io_addr == NULL) { |
Ben Dooks | a76836f | 2008-02-05 00:02:02 +0000 | [diff] [blame] | 523 | dev_err(db->dev, "failed to ioremap address reg\n"); |
Sascha Hauer | a136527 | 2005-05-05 15:14:15 -0700 | [diff] [blame] | 524 | ret = -EINVAL; |
| 525 | goto out; |
| 526 | } |
| 527 | |
| 528 | iosize = res_size(db->data_res); |
| 529 | db->data_req = request_mem_region(db->data_res->start, iosize, |
| 530 | pdev->name); |
| 531 | |
| 532 | if (db->data_req == NULL) { |
Ben Dooks | a76836f | 2008-02-05 00:02:02 +0000 | [diff] [blame] | 533 | dev_err(db->dev, "cannot claim data reg area\n"); |
Sascha Hauer | a136527 | 2005-05-05 15:14:15 -0700 | [diff] [blame] | 534 | ret = -EIO; |
| 535 | goto out; |
| 536 | } |
| 537 | |
| 538 | db->io_data = ioremap(db->data_res->start, iosize); |
| 539 | |
| 540 | if (db->io_data == NULL) { |
Ben Dooks | a76836f | 2008-02-05 00:02:02 +0000 | [diff] [blame] | 541 | dev_err(db->dev,"failed to ioremap data reg\n"); |
Sascha Hauer | a136527 | 2005-05-05 15:14:15 -0700 | [diff] [blame] | 542 | ret = -EINVAL; |
| 543 | goto out; |
| 544 | } |
| 545 | |
| 546 | /* fill in parameters for net-dev structure */ |
| 547 | |
| 548 | ndev->base_addr = (unsigned long)db->io_addr; |
| 549 | ndev->irq = db->irq_res->start; |
| 550 | |
| 551 | /* ensure at least we have a default set of IO routines */ |
| 552 | dm9000_set_io(db, iosize); |
Sascha Hauer | a136527 | 2005-05-05 15:14:15 -0700 | [diff] [blame] | 553 | } |
| 554 | |
| 555 | /* check to see if anything is being over-ridden */ |
| 556 | if (pdata != NULL) { |
| 557 | /* check to see if the driver wants to over-ride the |
| 558 | * default IO width */ |
| 559 | |
| 560 | if (pdata->flags & DM9000_PLATF_8BITONLY) |
| 561 | dm9000_set_io(db, 1); |
| 562 | |
| 563 | if (pdata->flags & DM9000_PLATF_16BITONLY) |
| 564 | dm9000_set_io(db, 2); |
| 565 | |
| 566 | if (pdata->flags & DM9000_PLATF_32BITONLY) |
| 567 | dm9000_set_io(db, 4); |
| 568 | |
| 569 | /* check to see if there are any IO routine |
| 570 | * over-rides */ |
| 571 | |
| 572 | if (pdata->inblk != NULL) |
| 573 | db->inblk = pdata->inblk; |
| 574 | |
| 575 | if (pdata->outblk != NULL) |
| 576 | db->outblk = pdata->outblk; |
| 577 | |
| 578 | if (pdata->dumpblk != NULL) |
| 579 | db->dumpblk = pdata->dumpblk; |
Ben Dooks | 33ba509 | 2008-02-05 00:02:01 +0000 | [diff] [blame] | 580 | |
| 581 | db->flags = pdata->flags; |
Sascha Hauer | a136527 | 2005-05-05 15:14:15 -0700 | [diff] [blame] | 582 | } |
| 583 | |
| 584 | dm9000_reset(db); |
| 585 | |
| 586 | /* try two times, DM9000 sometimes gets the first read wrong */ |
| 587 | for (i = 0; i < 2; i++) { |
| 588 | id_val = ior(db, DM9000_VIDL); |
| 589 | id_val |= (u32)ior(db, DM9000_VIDH) << 8; |
| 590 | id_val |= (u32)ior(db, DM9000_PIDL) << 16; |
| 591 | id_val |= (u32)ior(db, DM9000_PIDH) << 24; |
| 592 | |
| 593 | if (id_val == DM9000_ID) |
| 594 | break; |
Ben Dooks | a76836f | 2008-02-05 00:02:02 +0000 | [diff] [blame] | 595 | dev_err(db->dev, "read wrong id 0x%08x\n", id_val); |
Sascha Hauer | a136527 | 2005-05-05 15:14:15 -0700 | [diff] [blame] | 596 | } |
| 597 | |
| 598 | if (id_val != DM9000_ID) { |
Ben Dooks | a76836f | 2008-02-05 00:02:02 +0000 | [diff] [blame] | 599 | dev_err(db->dev, "wrong id: 0x%08x\n", id_val); |
Mike Rapoport | 418d6f8 | 2007-10-18 09:23:11 +0200 | [diff] [blame] | 600 | ret = -ENODEV; |
| 601 | goto out; |
Sascha Hauer | a136527 | 2005-05-05 15:14:15 -0700 | [diff] [blame] | 602 | } |
| 603 | |
| 604 | /* from this point we assume that we have found a DM9000 */ |
| 605 | |
| 606 | /* driver system function */ |
| 607 | ether_setup(ndev); |
| 608 | |
| 609 | ndev->open = &dm9000_open; |
| 610 | ndev->hard_start_xmit = &dm9000_start_xmit; |
| 611 | ndev->tx_timeout = &dm9000_timeout; |
| 612 | ndev->watchdog_timeo = msecs_to_jiffies(watchdog); |
| 613 | ndev->stop = &dm9000_stop; |
Sascha Hauer | a136527 | 2005-05-05 15:14:15 -0700 | [diff] [blame] | 614 | ndev->set_multicast_list = &dm9000_hash_table; |
Ben Dooks | 7da9985 | 2008-02-05 00:02:06 +0000 | [diff] [blame] | 615 | ndev->ethtool_ops = &dm9000_ethtool_ops; |
| 616 | |
Kevin Hao | 2fd0e33 | 2006-08-14 23:00:15 -0700 | [diff] [blame] | 617 | #ifdef CONFIG_NET_POLL_CONTROLLER |
| 618 | ndev->poll_controller = &dm9000_poll_controller; |
| 619 | #endif |
Sascha Hauer | a136527 | 2005-05-05 15:14:15 -0700 | [diff] [blame] | 620 | |
| 621 | #ifdef DM9000_PROGRAM_EEPROM |
| 622 | program_eeprom(db); |
| 623 | #endif |
| 624 | db->msg_enable = NETIF_MSG_LINK; |
| 625 | db->mii.phy_id_mask = 0x1f; |
| 626 | db->mii.reg_num_mask = 0x1f; |
| 627 | db->mii.force_media = 0; |
| 628 | db->mii.full_duplex = 0; |
| 629 | db->mii.dev = ndev; |
| 630 | db->mii.mdio_read = dm9000_phy_read; |
| 631 | db->mii.mdio_write = dm9000_phy_write; |
| 632 | |
Ben Dooks | 86c62fa | 2008-02-05 00:02:09 +0000 | [diff] [blame^] | 633 | /* try reading the node address from the attached EEPROM */ |
| 634 | for (i = 0; i < 6; i += 2) |
| 635 | dm9000_read_eeprom(db, i / 2, ndev->dev_addr+i); |
Sascha Hauer | a136527 | 2005-05-05 15:14:15 -0700 | [diff] [blame] | 636 | |
Ben Dooks | 5b55dda | 2006-06-13 23:50:15 +0100 | [diff] [blame] | 637 | if (!is_valid_ether_addr(ndev->dev_addr)) { |
| 638 | /* try reading from mac */ |
| 639 | |
| 640 | for (i = 0; i < 6; i++) |
| 641 | ndev->dev_addr[i] = ior(db, i+DM9000_PAR); |
| 642 | } |
| 643 | |
Sascha Hauer | a136527 | 2005-05-05 15:14:15 -0700 | [diff] [blame] | 644 | if (!is_valid_ether_addr(ndev->dev_addr)) |
Ben Dooks | a76836f | 2008-02-05 00:02:02 +0000 | [diff] [blame] | 645 | dev_warn(db->dev, "%s: Invalid ethernet MAC address. Please " |
| 646 | "set using ifconfig\n", ndev->name); |
Sascha Hauer | a136527 | 2005-05-05 15:14:15 -0700 | [diff] [blame] | 647 | |
Russell King | 3ae5eae | 2005-11-09 22:32:44 +0000 | [diff] [blame] | 648 | platform_set_drvdata(pdev, ndev); |
Sascha Hauer | a136527 | 2005-05-05 15:14:15 -0700 | [diff] [blame] | 649 | ret = register_netdev(ndev); |
| 650 | |
| 651 | if (ret == 0) { |
Joe Perches | 0795af5 | 2007-10-03 17:59:30 -0700 | [diff] [blame] | 652 | DECLARE_MAC_BUF(mac); |
| 653 | printk("%s: dm9000 at %p,%p IRQ %d MAC: %s\n", |
| 654 | ndev->name, db->io_addr, db->io_data, ndev->irq, |
| 655 | print_mac(mac, ndev->dev_addr)); |
Sascha Hauer | a136527 | 2005-05-05 15:14:15 -0700 | [diff] [blame] | 656 | } |
| 657 | return 0; |
| 658 | |
Mike Rapoport | 418d6f8 | 2007-10-18 09:23:11 +0200 | [diff] [blame] | 659 | out: |
Ben Dooks | a76836f | 2008-02-05 00:02:02 +0000 | [diff] [blame] | 660 | dev_err(db->dev, "not found (%d).\n", ret); |
Sascha Hauer | a136527 | 2005-05-05 15:14:15 -0700 | [diff] [blame] | 661 | |
| 662 | dm9000_release_board(pdev, db); |
Ben Dooks | 9fd9f9b | 2007-05-07 11:13:25 +0000 | [diff] [blame] | 663 | free_netdev(ndev); |
Sascha Hauer | a136527 | 2005-05-05 15:14:15 -0700 | [diff] [blame] | 664 | |
| 665 | return ret; |
| 666 | } |
| 667 | |
| 668 | /* |
| 669 | * Open the interface. |
| 670 | * The interface is opened whenever "ifconfig" actives it. |
| 671 | */ |
| 672 | static int |
| 673 | dm9000_open(struct net_device *dev) |
| 674 | { |
| 675 | board_info_t *db = (board_info_t *) dev->priv; |
Ben Dooks | 1a5f1c4 | 2008-02-05 00:02:04 +0000 | [diff] [blame] | 676 | unsigned long irqflags = db->irq_res->flags & IRQF_TRIGGER_MASK; |
Sascha Hauer | a136527 | 2005-05-05 15:14:15 -0700 | [diff] [blame] | 677 | |
Ben Dooks | a76836f | 2008-02-05 00:02:02 +0000 | [diff] [blame] | 678 | dev_dbg(db->dev, "entering %s\n", __func__); |
Sascha Hauer | a136527 | 2005-05-05 15:14:15 -0700 | [diff] [blame] | 679 | |
Ben Dooks | 1a5f1c4 | 2008-02-05 00:02:04 +0000 | [diff] [blame] | 680 | /* If there is no IRQ type specified, default to something that |
| 681 | * may work, and tell the user that this is a problem */ |
| 682 | |
| 683 | if (irqflags == IRQF_TRIGGER_NONE) { |
| 684 | dev_warn(db->dev, "WARNING: no IRQ resource flags set.\n"); |
| 685 | irqflags = DEFAULT_TRIGGER; |
| 686 | } |
| 687 | |
| 688 | irqflags |= IRQF_SHARED; |
| 689 | |
| 690 | if (request_irq(dev->irq, &dm9000_interrupt, irqflags, dev->name, dev)) |
Sascha Hauer | a136527 | 2005-05-05 15:14:15 -0700 | [diff] [blame] | 691 | return -EAGAIN; |
| 692 | |
| 693 | /* Initialize DM9000 board */ |
| 694 | dm9000_reset(db); |
| 695 | dm9000_init_dm9000(dev); |
| 696 | |
| 697 | /* Init driver variable */ |
| 698 | db->dbug_cnt = 0; |
| 699 | |
Sascha Hauer | a136527 | 2005-05-05 15:14:15 -0700 | [diff] [blame] | 700 | mii_check_media(&db->mii, netif_msg_link(db), 1); |
| 701 | netif_start_queue(dev); |
| 702 | |
| 703 | return 0; |
| 704 | } |
| 705 | |
| 706 | /* |
| 707 | * Initilize dm9000 board |
| 708 | */ |
| 709 | static void |
| 710 | dm9000_init_dm9000(struct net_device *dev) |
| 711 | { |
| 712 | board_info_t *db = (board_info_t *) dev->priv; |
| 713 | |
Ben Dooks | 5b2b4ff | 2008-02-05 00:02:03 +0000 | [diff] [blame] | 714 | dm9000_dbg(db, 1, "entering %s\n", __func__); |
Sascha Hauer | a136527 | 2005-05-05 15:14:15 -0700 | [diff] [blame] | 715 | |
| 716 | /* I/O mode */ |
| 717 | db->io_mode = ior(db, DM9000_ISR) >> 6; /* ISR bit7:6 keeps I/O mode */ |
| 718 | |
| 719 | /* GPIO0 on pre-activate PHY */ |
| 720 | iow(db, DM9000_GPR, 0); /* REG_1F bit0 activate phyxcer */ |
| 721 | iow(db, DM9000_GPCR, GPCR_GEP_CNTL); /* Let GPIO0 output */ |
| 722 | iow(db, DM9000_GPR, 0); /* Enable PHY */ |
| 723 | |
Ben Dooks | 33ba509 | 2008-02-05 00:02:01 +0000 | [diff] [blame] | 724 | if (db->flags & DM9000_PLATF_EXT_PHY) |
| 725 | iow(db, DM9000_NCR, NCR_EXT_PHY); |
| 726 | |
Sascha Hauer | a136527 | 2005-05-05 15:14:15 -0700 | [diff] [blame] | 727 | /* Program operating register */ |
| 728 | iow(db, DM9000_TCR, 0); /* TX Polling clear */ |
| 729 | iow(db, DM9000_BPTR, 0x3f); /* Less 3Kb, 200us */ |
| 730 | iow(db, DM9000_FCR, 0xff); /* Flow Control */ |
| 731 | iow(db, DM9000_SMCR, 0); /* Special Mode */ |
| 732 | /* clear TX status */ |
| 733 | iow(db, DM9000_NSR, NSR_WAKEST | NSR_TX2END | NSR_TX1END); |
| 734 | iow(db, DM9000_ISR, ISR_CLR_STATUS); /* Clear interrupt status */ |
| 735 | |
| 736 | /* Set address filter table */ |
| 737 | dm9000_hash_table(dev); |
| 738 | |
| 739 | /* Activate DM9000 */ |
| 740 | iow(db, DM9000_RCR, RCR_DIS_LONG | RCR_DIS_CRC | RCR_RXEN); |
| 741 | /* Enable TX/RX interrupt mask */ |
| 742 | iow(db, DM9000_IMR, IMR_PAR | IMR_PTM | IMR_PRM); |
| 743 | |
| 744 | /* Init Driver variable */ |
| 745 | db->tx_pkt_cnt = 0; |
| 746 | db->queue_pkt_len = 0; |
| 747 | dev->trans_start = 0; |
Sascha Hauer | a136527 | 2005-05-05 15:14:15 -0700 | [diff] [blame] | 748 | } |
| 749 | |
| 750 | /* |
| 751 | * Hardware start transmission. |
| 752 | * Send a packet to media from the upper layer. |
| 753 | */ |
| 754 | static int |
| 755 | dm9000_start_xmit(struct sk_buff *skb, struct net_device *dev) |
| 756 | { |
Florian Westphal | c46ac94 | 2007-08-21 01:33:42 +0200 | [diff] [blame] | 757 | unsigned long flags; |
Sascha Hauer | a136527 | 2005-05-05 15:14:15 -0700 | [diff] [blame] | 758 | board_info_t *db = (board_info_t *) dev->priv; |
| 759 | |
Ben Dooks | 5b2b4ff | 2008-02-05 00:02:03 +0000 | [diff] [blame] | 760 | dm9000_dbg(db, 3, "%s:\n", __func__); |
Sascha Hauer | a136527 | 2005-05-05 15:14:15 -0700 | [diff] [blame] | 761 | |
| 762 | if (db->tx_pkt_cnt > 1) |
| 763 | return 1; |
| 764 | |
Florian Westphal | c46ac94 | 2007-08-21 01:33:42 +0200 | [diff] [blame] | 765 | spin_lock_irqsave(&db->lock, flags); |
Sascha Hauer | a136527 | 2005-05-05 15:14:15 -0700 | [diff] [blame] | 766 | |
| 767 | /* Move data to DM9000 TX RAM */ |
| 768 | writeb(DM9000_MWCMD, db->io_addr); |
| 769 | |
| 770 | (db->outblk)(db->io_data, skb->data, skb->len); |
Jeff Garzik | 09f75cd | 2007-10-03 17:41:50 -0700 | [diff] [blame] | 771 | dev->stats.tx_bytes += skb->len; |
Sascha Hauer | a136527 | 2005-05-05 15:14:15 -0700 | [diff] [blame] | 772 | |
Florian Westphal | c46ac94 | 2007-08-21 01:33:42 +0200 | [diff] [blame] | 773 | db->tx_pkt_cnt++; |
Sascha Hauer | a136527 | 2005-05-05 15:14:15 -0700 | [diff] [blame] | 774 | /* TX control: First packet immediately send, second packet queue */ |
Florian Westphal | c46ac94 | 2007-08-21 01:33:42 +0200 | [diff] [blame] | 775 | if (db->tx_pkt_cnt == 1) { |
Sascha Hauer | a136527 | 2005-05-05 15:14:15 -0700 | [diff] [blame] | 776 | /* Set TX length to DM9000 */ |
| 777 | iow(db, DM9000_TXPLL, skb->len & 0xff); |
| 778 | iow(db, DM9000_TXPLH, (skb->len >> 8) & 0xff); |
| 779 | |
| 780 | /* Issue TX polling command */ |
| 781 | iow(db, DM9000_TCR, TCR_TXREQ); /* Cleared after TX complete */ |
| 782 | |
| 783 | dev->trans_start = jiffies; /* save the time stamp */ |
Sascha Hauer | a136527 | 2005-05-05 15:14:15 -0700 | [diff] [blame] | 784 | } else { |
| 785 | /* Second packet */ |
Sascha Hauer | a136527 | 2005-05-05 15:14:15 -0700 | [diff] [blame] | 786 | db->queue_pkt_len = skb->len; |
Florian Westphal | c46ac94 | 2007-08-21 01:33:42 +0200 | [diff] [blame] | 787 | netif_stop_queue(dev); |
Sascha Hauer | a136527 | 2005-05-05 15:14:15 -0700 | [diff] [blame] | 788 | } |
| 789 | |
Florian Westphal | c46ac94 | 2007-08-21 01:33:42 +0200 | [diff] [blame] | 790 | spin_unlock_irqrestore(&db->lock, flags); |
| 791 | |
Sascha Hauer | a136527 | 2005-05-05 15:14:15 -0700 | [diff] [blame] | 792 | /* free this SKB */ |
| 793 | dev_kfree_skb(skb); |
| 794 | |
Sascha Hauer | a136527 | 2005-05-05 15:14:15 -0700 | [diff] [blame] | 795 | return 0; |
| 796 | } |
| 797 | |
| 798 | static void |
| 799 | dm9000_shutdown(struct net_device *dev) |
| 800 | { |
| 801 | board_info_t *db = (board_info_t *) dev->priv; |
| 802 | |
| 803 | /* RESET device */ |
| 804 | dm9000_phy_write(dev, 0, MII_BMCR, BMCR_RESET); /* PHY RESET */ |
| 805 | iow(db, DM9000_GPR, 0x01); /* Power-Down PHY */ |
| 806 | iow(db, DM9000_IMR, IMR_PAR); /* Disable all interrupt */ |
| 807 | iow(db, DM9000_RCR, 0x00); /* Disable RX */ |
| 808 | } |
| 809 | |
| 810 | /* |
| 811 | * Stop the interface. |
| 812 | * The interface is stopped when it is brought. |
| 813 | */ |
| 814 | static int |
| 815 | dm9000_stop(struct net_device *ndev) |
| 816 | { |
| 817 | board_info_t *db = (board_info_t *) ndev->priv; |
| 818 | |
Ben Dooks | 5b2b4ff | 2008-02-05 00:02:03 +0000 | [diff] [blame] | 819 | dm9000_dbg(db, 1, "entering %s\n", __func__); |
Sascha Hauer | a136527 | 2005-05-05 15:14:15 -0700 | [diff] [blame] | 820 | |
Sascha Hauer | a136527 | 2005-05-05 15:14:15 -0700 | [diff] [blame] | 821 | netif_stop_queue(ndev); |
| 822 | netif_carrier_off(ndev); |
| 823 | |
| 824 | /* free interrupt */ |
| 825 | free_irq(ndev->irq, ndev); |
| 826 | |
| 827 | dm9000_shutdown(ndev); |
| 828 | |
| 829 | return 0; |
| 830 | } |
| 831 | |
| 832 | /* |
| 833 | * DM9000 interrupt handler |
| 834 | * receive the packet to upper layer, free the transmitted packet |
| 835 | */ |
| 836 | |
Ben Dooks | 5d22a31 | 2006-06-14 00:09:17 +0100 | [diff] [blame] | 837 | static void |
Sascha Hauer | a136527 | 2005-05-05 15:14:15 -0700 | [diff] [blame] | 838 | dm9000_tx_done(struct net_device *dev, board_info_t * db) |
| 839 | { |
| 840 | int tx_status = ior(db, DM9000_NSR); /* Got TX status */ |
| 841 | |
| 842 | if (tx_status & (NSR_TX2END | NSR_TX1END)) { |
| 843 | /* One packet sent complete */ |
| 844 | db->tx_pkt_cnt--; |
Jeff Garzik | 09f75cd | 2007-10-03 17:41:50 -0700 | [diff] [blame] | 845 | dev->stats.tx_packets++; |
Sascha Hauer | a136527 | 2005-05-05 15:14:15 -0700 | [diff] [blame] | 846 | |
| 847 | /* Queue packet check & send */ |
| 848 | if (db->tx_pkt_cnt > 0) { |
| 849 | iow(db, DM9000_TXPLL, db->queue_pkt_len & 0xff); |
| 850 | iow(db, DM9000_TXPLH, (db->queue_pkt_len >> 8) & 0xff); |
| 851 | iow(db, DM9000_TCR, TCR_TXREQ); |
| 852 | dev->trans_start = jiffies; |
| 853 | } |
| 854 | netif_wake_queue(dev); |
| 855 | } |
| 856 | } |
| 857 | |
| 858 | static irqreturn_t |
David Howells | 7d12e78 | 2006-10-05 14:55:46 +0100 | [diff] [blame] | 859 | dm9000_interrupt(int irq, void *dev_id) |
Sascha Hauer | a136527 | 2005-05-05 15:14:15 -0700 | [diff] [blame] | 860 | { |
| 861 | struct net_device *dev = dev_id; |
Ben Dooks | 5b2b4ff | 2008-02-05 00:02:03 +0000 | [diff] [blame] | 862 | board_info_t *db = (board_info_t *) dev->priv; |
Sascha Hauer | a136527 | 2005-05-05 15:14:15 -0700 | [diff] [blame] | 863 | int int_status; |
| 864 | u8 reg_save; |
| 865 | |
Ben Dooks | 5b2b4ff | 2008-02-05 00:02:03 +0000 | [diff] [blame] | 866 | dm9000_dbg(db, 3, "entering %s\n", __func__); |
Sascha Hauer | a136527 | 2005-05-05 15:14:15 -0700 | [diff] [blame] | 867 | |
| 868 | /* A real interrupt coming */ |
Ben Dooks | 5b2b4ff | 2008-02-05 00:02:03 +0000 | [diff] [blame] | 869 | |
Sascha Hauer | a136527 | 2005-05-05 15:14:15 -0700 | [diff] [blame] | 870 | spin_lock(&db->lock); |
| 871 | |
| 872 | /* Save previous register address */ |
| 873 | reg_save = readb(db->io_addr); |
| 874 | |
| 875 | /* Disable all interrupts */ |
| 876 | iow(db, DM9000_IMR, IMR_PAR); |
| 877 | |
| 878 | /* Got DM9000 interrupt status */ |
| 879 | int_status = ior(db, DM9000_ISR); /* Got ISR */ |
| 880 | iow(db, DM9000_ISR, int_status); /* Clear ISR status */ |
| 881 | |
| 882 | /* Received the coming packet */ |
| 883 | if (int_status & ISR_PRS) |
| 884 | dm9000_rx(dev); |
| 885 | |
| 886 | /* Trnasmit Interrupt check */ |
| 887 | if (int_status & ISR_PTS) |
| 888 | dm9000_tx_done(dev, db); |
| 889 | |
| 890 | /* Re-enable interrupt mask */ |
| 891 | iow(db, DM9000_IMR, IMR_PAR | IMR_PTM | IMR_PRM); |
| 892 | |
| 893 | /* Restore previous register address */ |
| 894 | writeb(reg_save, db->io_addr); |
| 895 | |
| 896 | spin_unlock(&db->lock); |
| 897 | |
| 898 | return IRQ_HANDLED; |
| 899 | } |
| 900 | |
Sascha Hauer | a136527 | 2005-05-05 15:14:15 -0700 | [diff] [blame] | 901 | struct dm9000_rxhdr { |
Ben Dooks | 9311657 | 2008-02-05 00:02:00 +0000 | [diff] [blame] | 902 | u8 RxPktReady; |
| 903 | u8 RxStatus; |
Sascha Hauer | a136527 | 2005-05-05 15:14:15 -0700 | [diff] [blame] | 904 | u16 RxLen; |
| 905 | } __attribute__((__packed__)); |
| 906 | |
| 907 | /* |
| 908 | * Received a packet and pass to upper layer |
| 909 | */ |
| 910 | static void |
| 911 | dm9000_rx(struct net_device *dev) |
| 912 | { |
| 913 | board_info_t *db = (board_info_t *) dev->priv; |
| 914 | struct dm9000_rxhdr rxhdr; |
| 915 | struct sk_buff *skb; |
| 916 | u8 rxbyte, *rdptr; |
Richard Knutsson | 6478fac | 2007-05-01 18:43:27 +0200 | [diff] [blame] | 917 | bool GoodPacket; |
Sascha Hauer | a136527 | 2005-05-05 15:14:15 -0700 | [diff] [blame] | 918 | int RxLen; |
| 919 | |
| 920 | /* Check packet ready or not */ |
| 921 | do { |
| 922 | ior(db, DM9000_MRCMDX); /* Dummy read */ |
| 923 | |
| 924 | /* Get most updated data */ |
| 925 | rxbyte = readb(db->io_data); |
| 926 | |
| 927 | /* Status check: this byte must be 0 or 1 */ |
| 928 | if (rxbyte > DM9000_PKT_RDY) { |
Ben Dooks | a76836f | 2008-02-05 00:02:02 +0000 | [diff] [blame] | 929 | dev_warn(db->dev, "status check fail: %d\n", rxbyte); |
Sascha Hauer | a136527 | 2005-05-05 15:14:15 -0700 | [diff] [blame] | 930 | iow(db, DM9000_RCR, 0x00); /* Stop Device */ |
| 931 | iow(db, DM9000_ISR, IMR_PAR); /* Stop INT request */ |
| 932 | return; |
| 933 | } |
| 934 | |
| 935 | if (rxbyte != DM9000_PKT_RDY) |
| 936 | return; |
| 937 | |
| 938 | /* A packet ready now & Get status/length */ |
Richard Knutsson | 6478fac | 2007-05-01 18:43:27 +0200 | [diff] [blame] | 939 | GoodPacket = true; |
Sascha Hauer | a136527 | 2005-05-05 15:14:15 -0700 | [diff] [blame] | 940 | writeb(DM9000_MRCMD, db->io_addr); |
| 941 | |
| 942 | (db->inblk)(db->io_data, &rxhdr, sizeof(rxhdr)); |
| 943 | |
Ben Dooks | 9311657 | 2008-02-05 00:02:00 +0000 | [diff] [blame] | 944 | RxLen = le16_to_cpu(rxhdr.RxLen); |
Sascha Hauer | a136527 | 2005-05-05 15:14:15 -0700 | [diff] [blame] | 945 | |
| 946 | /* Packet Status check */ |
| 947 | if (RxLen < 0x40) { |
Richard Knutsson | 6478fac | 2007-05-01 18:43:27 +0200 | [diff] [blame] | 948 | GoodPacket = false; |
Ben Dooks | a76836f | 2008-02-05 00:02:02 +0000 | [diff] [blame] | 949 | dev_dbg(db->dev, "Bad Packet received (runt)\n"); |
Sascha Hauer | a136527 | 2005-05-05 15:14:15 -0700 | [diff] [blame] | 950 | } |
| 951 | |
| 952 | if (RxLen > DM9000_PKT_MAX) { |
Ben Dooks | a76836f | 2008-02-05 00:02:02 +0000 | [diff] [blame] | 953 | dev_dbg(db->dev, "RST: RX Len:%x\n", RxLen); |
Sascha Hauer | a136527 | 2005-05-05 15:14:15 -0700 | [diff] [blame] | 954 | } |
| 955 | |
Ben Dooks | 9311657 | 2008-02-05 00:02:00 +0000 | [diff] [blame] | 956 | if (rxhdr.RxStatus & 0xbf) { |
Richard Knutsson | 6478fac | 2007-05-01 18:43:27 +0200 | [diff] [blame] | 957 | GoodPacket = false; |
Ben Dooks | 9311657 | 2008-02-05 00:02:00 +0000 | [diff] [blame] | 958 | if (rxhdr.RxStatus & 0x01) { |
Ben Dooks | a76836f | 2008-02-05 00:02:02 +0000 | [diff] [blame] | 959 | dev_dbg(db->dev, "fifo error\n"); |
Jeff Garzik | 09f75cd | 2007-10-03 17:41:50 -0700 | [diff] [blame] | 960 | dev->stats.rx_fifo_errors++; |
Sascha Hauer | a136527 | 2005-05-05 15:14:15 -0700 | [diff] [blame] | 961 | } |
Ben Dooks | 9311657 | 2008-02-05 00:02:00 +0000 | [diff] [blame] | 962 | if (rxhdr.RxStatus & 0x02) { |
Ben Dooks | a76836f | 2008-02-05 00:02:02 +0000 | [diff] [blame] | 963 | dev_dbg(db->dev, "crc error\n"); |
Jeff Garzik | 09f75cd | 2007-10-03 17:41:50 -0700 | [diff] [blame] | 964 | dev->stats.rx_crc_errors++; |
Sascha Hauer | a136527 | 2005-05-05 15:14:15 -0700 | [diff] [blame] | 965 | } |
Ben Dooks | 9311657 | 2008-02-05 00:02:00 +0000 | [diff] [blame] | 966 | if (rxhdr.RxStatus & 0x80) { |
Ben Dooks | a76836f | 2008-02-05 00:02:02 +0000 | [diff] [blame] | 967 | dev_dbg(db->dev, "length error\n"); |
Jeff Garzik | 09f75cd | 2007-10-03 17:41:50 -0700 | [diff] [blame] | 968 | dev->stats.rx_length_errors++; |
Sascha Hauer | a136527 | 2005-05-05 15:14:15 -0700 | [diff] [blame] | 969 | } |
| 970 | } |
| 971 | |
| 972 | /* Move data from DM9000 */ |
| 973 | if (GoodPacket |
| 974 | && ((skb = dev_alloc_skb(RxLen + 4)) != NULL)) { |
Sascha Hauer | a136527 | 2005-05-05 15:14:15 -0700 | [diff] [blame] | 975 | skb_reserve(skb, 2); |
| 976 | rdptr = (u8 *) skb_put(skb, RxLen - 4); |
| 977 | |
| 978 | /* Read received packet from RX SRAM */ |
| 979 | |
| 980 | (db->inblk)(db->io_data, rdptr, RxLen); |
Jeff Garzik | 09f75cd | 2007-10-03 17:41:50 -0700 | [diff] [blame] | 981 | dev->stats.rx_bytes += RxLen; |
Sascha Hauer | a136527 | 2005-05-05 15:14:15 -0700 | [diff] [blame] | 982 | |
| 983 | /* Pass to upper layer */ |
| 984 | skb->protocol = eth_type_trans(skb, dev); |
| 985 | netif_rx(skb); |
Jeff Garzik | 09f75cd | 2007-10-03 17:41:50 -0700 | [diff] [blame] | 986 | dev->stats.rx_packets++; |
Sascha Hauer | a136527 | 2005-05-05 15:14:15 -0700 | [diff] [blame] | 987 | |
| 988 | } else { |
| 989 | /* need to dump the packet's data */ |
| 990 | |
| 991 | (db->dumpblk)(db->io_data, RxLen); |
| 992 | } |
| 993 | } while (rxbyte == DM9000_PKT_RDY); |
| 994 | } |
| 995 | |
| 996 | /* |
Ben Dooks | 86c62fa | 2008-02-05 00:02:09 +0000 | [diff] [blame^] | 997 | * Read a word data from EEPROM |
Sascha Hauer | a136527 | 2005-05-05 15:14:15 -0700 | [diff] [blame] | 998 | */ |
Ben Dooks | 86c62fa | 2008-02-05 00:02:09 +0000 | [diff] [blame^] | 999 | static void |
| 1000 | dm9000_read_eeprom(board_info_t * db, int offset, unsigned char *to) |
Sascha Hauer | a136527 | 2005-05-05 15:14:15 -0700 | [diff] [blame] | 1001 | { |
| 1002 | iow(db, DM9000_EPAR, offset); |
| 1003 | iow(db, DM9000_EPCR, EPCR_ERPRR); |
| 1004 | mdelay(8); /* according to the datasheet 200us should be enough, |
| 1005 | but it doesn't work */ |
| 1006 | iow(db, DM9000_EPCR, 0x0); |
Ben Dooks | 86c62fa | 2008-02-05 00:02:09 +0000 | [diff] [blame^] | 1007 | |
| 1008 | to[0] = ior(db, DM9000_EPDRL); |
| 1009 | to[1] = ior(db, DM9000_EPDRH); |
Sascha Hauer | a136527 | 2005-05-05 15:14:15 -0700 | [diff] [blame] | 1010 | } |
| 1011 | |
| 1012 | #ifdef DM9000_PROGRAM_EEPROM |
| 1013 | /* |
| 1014 | * Write a word data to SROM |
| 1015 | */ |
| 1016 | static void |
| 1017 | write_srom_word(board_info_t * db, int offset, u16 val) |
| 1018 | { |
| 1019 | iow(db, DM9000_EPAR, offset); |
| 1020 | iow(db, DM9000_EPDRH, ((val >> 8) & 0xff)); |
| 1021 | iow(db, DM9000_EPDRL, (val & 0xff)); |
| 1022 | iow(db, DM9000_EPCR, EPCR_WEP | EPCR_ERPRW); |
| 1023 | mdelay(8); /* same shit */ |
| 1024 | iow(db, DM9000_EPCR, 0); |
| 1025 | } |
| 1026 | |
| 1027 | /* |
| 1028 | * Only for development: |
| 1029 | * Here we write static data to the eeprom in case |
| 1030 | * we don't have valid content on a new board |
| 1031 | */ |
| 1032 | static void |
| 1033 | program_eeprom(board_info_t * db) |
| 1034 | { |
| 1035 | u16 eeprom[] = { 0x0c00, 0x007f, 0x1300, /* MAC Address */ |
| 1036 | 0x0000, /* Autoload: accept nothing */ |
| 1037 | 0x0a46, 0x9000, /* Vendor / Product ID */ |
| 1038 | 0x0000, /* pin control */ |
| 1039 | 0x0000, |
| 1040 | }; /* Wake-up mode control */ |
| 1041 | int i; |
| 1042 | for (i = 0; i < 8; i++) |
| 1043 | write_srom_word(db, i, eeprom[i]); |
| 1044 | } |
| 1045 | #endif |
| 1046 | |
| 1047 | |
| 1048 | /* |
| 1049 | * Calculate the CRC valude of the Rx packet |
| 1050 | * flag = 1 : return the reverse CRC (for the received packet CRC) |
| 1051 | * 0 : return the normal CRC (for Hash Table index) |
| 1052 | */ |
| 1053 | |
| 1054 | static unsigned long |
| 1055 | cal_CRC(unsigned char *Data, unsigned int Len, u8 flag) |
| 1056 | { |
| 1057 | |
| 1058 | u32 crc = ether_crc_le(Len, Data); |
| 1059 | |
| 1060 | if (flag) |
| 1061 | return ~crc; |
| 1062 | |
| 1063 | return crc; |
| 1064 | } |
| 1065 | |
| 1066 | /* |
| 1067 | * Set DM9000 multicast address |
| 1068 | */ |
| 1069 | static void |
| 1070 | dm9000_hash_table(struct net_device *dev) |
| 1071 | { |
| 1072 | board_info_t *db = (board_info_t *) dev->priv; |
| 1073 | struct dev_mc_list *mcptr = dev->mc_list; |
| 1074 | int mc_cnt = dev->mc_count; |
| 1075 | u32 hash_val; |
| 1076 | u16 i, oft, hash_table[4]; |
| 1077 | unsigned long flags; |
| 1078 | |
Ben Dooks | 5b2b4ff | 2008-02-05 00:02:03 +0000 | [diff] [blame] | 1079 | dm9000_dbg(db, 1, "entering %s\n", __func__); |
Sascha Hauer | a136527 | 2005-05-05 15:14:15 -0700 | [diff] [blame] | 1080 | |
| 1081 | spin_lock_irqsave(&db->lock,flags); |
| 1082 | |
| 1083 | for (i = 0, oft = 0x10; i < 6; i++, oft++) |
| 1084 | iow(db, oft, dev->dev_addr[i]); |
| 1085 | |
| 1086 | /* Clear Hash Table */ |
| 1087 | for (i = 0; i < 4; i++) |
| 1088 | hash_table[i] = 0x0; |
| 1089 | |
| 1090 | /* broadcast address */ |
| 1091 | hash_table[3] = 0x8000; |
| 1092 | |
| 1093 | /* the multicast address in Hash Table : 64 bits */ |
| 1094 | for (i = 0; i < mc_cnt; i++, mcptr = mcptr->next) { |
| 1095 | hash_val = cal_CRC((char *) mcptr->dmi_addr, 6, 0) & 0x3f; |
| 1096 | hash_table[hash_val / 16] |= (u16) 1 << (hash_val % 16); |
| 1097 | } |
| 1098 | |
| 1099 | /* Write the hash table to MAC MD table */ |
| 1100 | for (i = 0, oft = 0x16; i < 4; i++) { |
| 1101 | iow(db, oft++, hash_table[i] & 0xff); |
| 1102 | iow(db, oft++, (hash_table[i] >> 8) & 0xff); |
| 1103 | } |
| 1104 | |
| 1105 | spin_unlock_irqrestore(&db->lock,flags); |
| 1106 | } |
| 1107 | |
| 1108 | |
| 1109 | /* |
Ben Dooks | 321f69a | 2008-02-05 00:02:08 +0000 | [diff] [blame] | 1110 | * Sleep, either by using msleep() or if we are suspending, then |
| 1111 | * use mdelay() to sleep. |
| 1112 | */ |
| 1113 | static void dm9000_msleep(board_info_t *db, unsigned int ms) |
| 1114 | { |
| 1115 | if (db->in_suspend) |
| 1116 | mdelay(ms); |
| 1117 | else |
| 1118 | msleep(ms); |
| 1119 | } |
| 1120 | |
| 1121 | /* |
Sascha Hauer | a136527 | 2005-05-05 15:14:15 -0700 | [diff] [blame] | 1122 | * Read a word from phyxcer |
| 1123 | */ |
| 1124 | static int |
| 1125 | dm9000_phy_read(struct net_device *dev, int phy_reg_unused, int reg) |
| 1126 | { |
| 1127 | board_info_t *db = (board_info_t *) dev->priv; |
| 1128 | unsigned long flags; |
Ben Dooks | 9ef9ac5 | 2005-07-23 17:25:18 +0100 | [diff] [blame] | 1129 | unsigned int reg_save; |
Sascha Hauer | a136527 | 2005-05-05 15:14:15 -0700 | [diff] [blame] | 1130 | int ret; |
| 1131 | |
| 1132 | spin_lock_irqsave(&db->lock,flags); |
Ben Dooks | 9ef9ac5 | 2005-07-23 17:25:18 +0100 | [diff] [blame] | 1133 | |
| 1134 | /* Save previous register address */ |
| 1135 | reg_save = readb(db->io_addr); |
| 1136 | |
Sascha Hauer | a136527 | 2005-05-05 15:14:15 -0700 | [diff] [blame] | 1137 | /* Fill the phyxcer register into REG_0C */ |
| 1138 | iow(db, DM9000_EPAR, DM9000_PHY | reg); |
| 1139 | |
| 1140 | iow(db, DM9000_EPCR, 0xc); /* Issue phyxcer read command */ |
Ben Dooks | 89c8b0e | 2008-02-05 00:02:07 +0000 | [diff] [blame] | 1141 | |
| 1142 | writeb(reg_save, db->io_addr); |
| 1143 | spin_unlock_irqrestore(&db->lock,flags); |
| 1144 | |
Ben Dooks | 321f69a | 2008-02-05 00:02:08 +0000 | [diff] [blame] | 1145 | dm9000_msleep(db, 1); /* Wait read complete */ |
Ben Dooks | 89c8b0e | 2008-02-05 00:02:07 +0000 | [diff] [blame] | 1146 | |
| 1147 | spin_lock_irqsave(&db->lock,flags); |
| 1148 | reg_save = readb(db->io_addr); |
| 1149 | |
Sascha Hauer | a136527 | 2005-05-05 15:14:15 -0700 | [diff] [blame] | 1150 | iow(db, DM9000_EPCR, 0x0); /* Clear phyxcer read command */ |
| 1151 | |
| 1152 | /* The read data keeps on REG_0D & REG_0E */ |
| 1153 | ret = (ior(db, DM9000_EPDRH) << 8) | ior(db, DM9000_EPDRL); |
| 1154 | |
Ben Dooks | 9ef9ac5 | 2005-07-23 17:25:18 +0100 | [diff] [blame] | 1155 | /* restore the previous address */ |
| 1156 | writeb(reg_save, db->io_addr); |
Sascha Hauer | a136527 | 2005-05-05 15:14:15 -0700 | [diff] [blame] | 1157 | spin_unlock_irqrestore(&db->lock,flags); |
| 1158 | |
| 1159 | return ret; |
| 1160 | } |
| 1161 | |
| 1162 | /* |
| 1163 | * Write a word to phyxcer |
| 1164 | */ |
| 1165 | static void |
| 1166 | dm9000_phy_write(struct net_device *dev, int phyaddr_unused, int reg, int value) |
| 1167 | { |
| 1168 | board_info_t *db = (board_info_t *) dev->priv; |
| 1169 | unsigned long flags; |
Ben Dooks | 9ef9ac5 | 2005-07-23 17:25:18 +0100 | [diff] [blame] | 1170 | unsigned long reg_save; |
Sascha Hauer | a136527 | 2005-05-05 15:14:15 -0700 | [diff] [blame] | 1171 | |
| 1172 | spin_lock_irqsave(&db->lock,flags); |
| 1173 | |
Ben Dooks | 9ef9ac5 | 2005-07-23 17:25:18 +0100 | [diff] [blame] | 1174 | /* Save previous register address */ |
| 1175 | reg_save = readb(db->io_addr); |
| 1176 | |
Sascha Hauer | a136527 | 2005-05-05 15:14:15 -0700 | [diff] [blame] | 1177 | /* Fill the phyxcer register into REG_0C */ |
| 1178 | iow(db, DM9000_EPAR, DM9000_PHY | reg); |
| 1179 | |
| 1180 | /* Fill the written data into REG_0D & REG_0E */ |
| 1181 | iow(db, DM9000_EPDRL, (value & 0xff)); |
| 1182 | iow(db, DM9000_EPDRH, ((value >> 8) & 0xff)); |
| 1183 | |
| 1184 | iow(db, DM9000_EPCR, 0xa); /* Issue phyxcer write command */ |
Ben Dooks | 89c8b0e | 2008-02-05 00:02:07 +0000 | [diff] [blame] | 1185 | |
| 1186 | writeb(reg_save, db->io_addr); |
| 1187 | spin_unlock_irqrestore(&db->lock,flags); |
| 1188 | |
Ben Dooks | 321f69a | 2008-02-05 00:02:08 +0000 | [diff] [blame] | 1189 | dm9000_msleep(db, 1); /* Wait write complete */ |
Ben Dooks | 89c8b0e | 2008-02-05 00:02:07 +0000 | [diff] [blame] | 1190 | |
| 1191 | spin_lock_irqsave(&db->lock,flags); |
| 1192 | reg_save = readb(db->io_addr); |
| 1193 | |
Sascha Hauer | a136527 | 2005-05-05 15:14:15 -0700 | [diff] [blame] | 1194 | iow(db, DM9000_EPCR, 0x0); /* Clear phyxcer write command */ |
| 1195 | |
Ben Dooks | 9ef9ac5 | 2005-07-23 17:25:18 +0100 | [diff] [blame] | 1196 | /* restore the previous address */ |
| 1197 | writeb(reg_save, db->io_addr); |
| 1198 | |
Sascha Hauer | a136527 | 2005-05-05 15:14:15 -0700 | [diff] [blame] | 1199 | spin_unlock_irqrestore(&db->lock,flags); |
| 1200 | } |
| 1201 | |
| 1202 | static int |
Russell King | 3ae5eae | 2005-11-09 22:32:44 +0000 | [diff] [blame] | 1203 | dm9000_drv_suspend(struct platform_device *dev, pm_message_t state) |
Sascha Hauer | a136527 | 2005-05-05 15:14:15 -0700 | [diff] [blame] | 1204 | { |
Russell King | 3ae5eae | 2005-11-09 22:32:44 +0000 | [diff] [blame] | 1205 | struct net_device *ndev = platform_get_drvdata(dev); |
Ben Dooks | 321f69a | 2008-02-05 00:02:08 +0000 | [diff] [blame] | 1206 | board_info_t *db; |
Sascha Hauer | a136527 | 2005-05-05 15:14:15 -0700 | [diff] [blame] | 1207 | |
Russell King | 9480e30 | 2005-10-28 09:52:56 -0700 | [diff] [blame] | 1208 | if (ndev) { |
Ben Dooks | 321f69a | 2008-02-05 00:02:08 +0000 | [diff] [blame] | 1209 | db = (board_info_t *) ndev->priv; |
| 1210 | db->in_suspend = 1; |
| 1211 | |
Sascha Hauer | a136527 | 2005-05-05 15:14:15 -0700 | [diff] [blame] | 1212 | if (netif_running(ndev)) { |
| 1213 | netif_device_detach(ndev); |
| 1214 | dm9000_shutdown(ndev); |
| 1215 | } |
| 1216 | } |
| 1217 | return 0; |
| 1218 | } |
| 1219 | |
| 1220 | static int |
Russell King | 3ae5eae | 2005-11-09 22:32:44 +0000 | [diff] [blame] | 1221 | dm9000_drv_resume(struct platform_device *dev) |
Sascha Hauer | a136527 | 2005-05-05 15:14:15 -0700 | [diff] [blame] | 1222 | { |
Russell King | 3ae5eae | 2005-11-09 22:32:44 +0000 | [diff] [blame] | 1223 | struct net_device *ndev = platform_get_drvdata(dev); |
Sascha Hauer | a136527 | 2005-05-05 15:14:15 -0700 | [diff] [blame] | 1224 | board_info_t *db = (board_info_t *) ndev->priv; |
| 1225 | |
Russell King | 9480e30 | 2005-10-28 09:52:56 -0700 | [diff] [blame] | 1226 | if (ndev) { |
Sascha Hauer | a136527 | 2005-05-05 15:14:15 -0700 | [diff] [blame] | 1227 | |
| 1228 | if (netif_running(ndev)) { |
| 1229 | dm9000_reset(db); |
| 1230 | dm9000_init_dm9000(ndev); |
| 1231 | |
| 1232 | netif_device_attach(ndev); |
| 1233 | } |
Ben Dooks | 321f69a | 2008-02-05 00:02:08 +0000 | [diff] [blame] | 1234 | |
| 1235 | db->in_suspend = 0; |
Sascha Hauer | a136527 | 2005-05-05 15:14:15 -0700 | [diff] [blame] | 1236 | } |
| 1237 | return 0; |
| 1238 | } |
| 1239 | |
| 1240 | static int |
Russell King | 3ae5eae | 2005-11-09 22:32:44 +0000 | [diff] [blame] | 1241 | dm9000_drv_remove(struct platform_device *pdev) |
Sascha Hauer | a136527 | 2005-05-05 15:14:15 -0700 | [diff] [blame] | 1242 | { |
Russell King | 3ae5eae | 2005-11-09 22:32:44 +0000 | [diff] [blame] | 1243 | struct net_device *ndev = platform_get_drvdata(pdev); |
Sascha Hauer | a136527 | 2005-05-05 15:14:15 -0700 | [diff] [blame] | 1244 | |
Russell King | 3ae5eae | 2005-11-09 22:32:44 +0000 | [diff] [blame] | 1245 | platform_set_drvdata(pdev, NULL); |
Sascha Hauer | a136527 | 2005-05-05 15:14:15 -0700 | [diff] [blame] | 1246 | |
| 1247 | unregister_netdev(ndev); |
| 1248 | dm9000_release_board(pdev, (board_info_t *) ndev->priv); |
Ben Dooks | 9fd9f9b | 2007-05-07 11:13:25 +0000 | [diff] [blame] | 1249 | free_netdev(ndev); /* free device structure */ |
Sascha Hauer | a136527 | 2005-05-05 15:14:15 -0700 | [diff] [blame] | 1250 | |
Ben Dooks | a76836f | 2008-02-05 00:02:02 +0000 | [diff] [blame] | 1251 | dev_dbg(&pdev->dev, "released and freed device\n"); |
Sascha Hauer | a136527 | 2005-05-05 15:14:15 -0700 | [diff] [blame] | 1252 | return 0; |
| 1253 | } |
| 1254 | |
Russell King | 3ae5eae | 2005-11-09 22:32:44 +0000 | [diff] [blame] | 1255 | static struct platform_driver dm9000_driver = { |
Ben Dooks | 5d22a31 | 2006-06-14 00:09:17 +0100 | [diff] [blame] | 1256 | .driver = { |
| 1257 | .name = "dm9000", |
| 1258 | .owner = THIS_MODULE, |
| 1259 | }, |
Sascha Hauer | a136527 | 2005-05-05 15:14:15 -0700 | [diff] [blame] | 1260 | .probe = dm9000_probe, |
| 1261 | .remove = dm9000_drv_remove, |
| 1262 | .suspend = dm9000_drv_suspend, |
| 1263 | .resume = dm9000_drv_resume, |
| 1264 | }; |
| 1265 | |
| 1266 | static int __init |
| 1267 | dm9000_init(void) |
| 1268 | { |
Ben Dooks | 7da9985 | 2008-02-05 00:02:06 +0000 | [diff] [blame] | 1269 | printk(KERN_INFO "%s Ethernet Driver, V%s\n", CARDNAME, DRV_VERSION); |
Ben Dooks | 2ae2d77 | 2005-07-23 17:29:38 +0100 | [diff] [blame] | 1270 | |
Russell King | 3ae5eae | 2005-11-09 22:32:44 +0000 | [diff] [blame] | 1271 | return platform_driver_register(&dm9000_driver); /* search board and register */ |
Sascha Hauer | a136527 | 2005-05-05 15:14:15 -0700 | [diff] [blame] | 1272 | } |
| 1273 | |
| 1274 | static void __exit |
| 1275 | dm9000_cleanup(void) |
| 1276 | { |
Russell King | 3ae5eae | 2005-11-09 22:32:44 +0000 | [diff] [blame] | 1277 | platform_driver_unregister(&dm9000_driver); |
Sascha Hauer | a136527 | 2005-05-05 15:14:15 -0700 | [diff] [blame] | 1278 | } |
| 1279 | |
| 1280 | module_init(dm9000_init); |
| 1281 | module_exit(dm9000_cleanup); |
| 1282 | |
| 1283 | MODULE_AUTHOR("Sascha Hauer, Ben Dooks"); |
| 1284 | MODULE_DESCRIPTION("Davicom DM9000 network driver"); |
| 1285 | MODULE_LICENSE("GPL"); |