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