diff options
Diffstat (limited to 'drivers/net/dm9000.c')
-rw-r--r-- | drivers/net/dm9000.c | 654 |
1 files changed, 425 insertions, 229 deletions
diff --git a/drivers/net/dm9000.c b/drivers/net/dm9000.c index 6a20a5491a96..1fe305ca2cf0 100644 --- a/drivers/net/dm9000.c +++ b/drivers/net/dm9000.c | |||
@@ -1,7 +1,5 @@ | |||
1 | /* | 1 | /* |
2 | * dm9000.c: Version 1.2 03/18/2003 | 2 | * Davicom DM9000 Fast Ethernet driver for Linux. |
3 | * | ||
4 | * A Davicom DM9000 ISA NIC fast Ethernet driver for Linux. | ||
5 | * Copyright (C) 1997 Sten Wang | 3 | * Copyright (C) 1997 Sten Wang |
6 | * | 4 | * |
7 | * This program is free software; you can redistribute it and/or | 5 | * This program is free software; you can redistribute it and/or |
@@ -14,44 +12,11 @@ | |||
14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
15 | * GNU General Public License for more details. | 13 | * GNU General Public License for more details. |
16 | * | 14 | * |
17 | * (C)Copyright 1997-1998 DAVICOM Semiconductor,Inc. All Rights Reserved. | 15 | * (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 | ||
51 | * | 16 | * |
52 | * 01-Jul-2005 Ben Dooks <ben@simtec.co.uk> | 17 | * Additional updates, Copyright: |
53 | * * fixed spinlock call without pointer | 18 | * Ben Dooks <ben@simtec.co.uk> |
54 | * * ensure spinlock is initialised | 19 | * Sascha Hauer <s.hauer@pengutronix.de> |
55 | */ | 20 | */ |
56 | 21 | ||
57 | #include <linux/module.h> | 22 | #include <linux/module.h> |
@@ -63,6 +28,7 @@ | |||
63 | #include <linux/spinlock.h> | 28 | #include <linux/spinlock.h> |
64 | #include <linux/crc32.h> | 29 | #include <linux/crc32.h> |
65 | #include <linux/mii.h> | 30 | #include <linux/mii.h> |
31 | #include <linux/ethtool.h> | ||
66 | #include <linux/dm9000.h> | 32 | #include <linux/dm9000.h> |
67 | #include <linux/delay.h> | 33 | #include <linux/delay.h> |
68 | #include <linux/platform_device.h> | 34 | #include <linux/platform_device.h> |
@@ -80,30 +46,7 @@ | |||
80 | 46 | ||
81 | #define CARDNAME "dm9000" | 47 | #define CARDNAME "dm9000" |
82 | #define PFX CARDNAME ": " | 48 | #define PFX CARDNAME ": " |
83 | 49 | #define DRV_VERSION "1.30" | |
84 | #define DM9000_TIMER_WUT jiffies+(HZ*2) /* timer wakeup time : 2 second */ | ||
85 | |||
86 | #define DM9000_DEBUG 0 | ||
87 | |||
88 | #if DM9000_DEBUG > 2 | ||
89 | #define PRINTK3(args...) printk(CARDNAME ": " args) | ||
90 | #else | ||
91 | #define PRINTK3(args...) do { } while(0) | ||
92 | #endif | ||
93 | |||
94 | #if DM9000_DEBUG > 1 | ||
95 | #define PRINTK2(args...) printk(CARDNAME ": " args) | ||
96 | #else | ||
97 | #define PRINTK2(args...) do { } while(0) | ||
98 | #endif | ||
99 | |||
100 | #if DM9000_DEBUG > 0 | ||
101 | #define PRINTK1(args...) printk(CARDNAME ": " args) | ||
102 | #define PRINTK(args...) printk(CARDNAME ": " args) | ||
103 | #else | ||
104 | #define PRINTK1(args...) do { } while(0) | ||
105 | #define PRINTK(args...) printk(KERN_DEBUG args) | ||
106 | #endif | ||
107 | 50 | ||
108 | #ifdef CONFIG_BLACKFIN | 51 | #ifdef CONFIG_BLACKFIN |
109 | #define readsb insb | 52 | #define readsb insb |
@@ -112,9 +55,9 @@ | |||
112 | #define writesb outsb | 55 | #define writesb outsb |
113 | #define writesw outsw | 56 | #define writesw outsw |
114 | #define writesl outsl | 57 | #define writesl outsl |
115 | #define DM9000_IRQ_FLAGS (IRQF_SHARED | IRQF_TRIGGER_HIGH) | 58 | #define DEFAULT_TRIGGER IRQF_TRIGGER_HIGH |
116 | #else | 59 | #else |
117 | #define DM9000_IRQ_FLAGS (IRQF_SHARED | IRQT_RISING) | 60 | #define DEFAULT_TRIGGER (0) |
118 | #endif | 61 | #endif |
119 | 62 | ||
120 | /* | 63 | /* |
@@ -124,6 +67,24 @@ static int watchdog = 5000; | |||
124 | module_param(watchdog, int, 0400); | 67 | module_param(watchdog, int, 0400); |
125 | MODULE_PARM_DESC(watchdog, "transmit timeout in milliseconds"); | 68 | MODULE_PARM_DESC(watchdog, "transmit timeout in milliseconds"); |
126 | 69 | ||
70 | /* DM9000 register address locking. | ||
71 | * | ||
72 | * The DM9000 uses an address register to control where data written | ||
73 | * to the data register goes. This means that the address register | ||
74 | * must be preserved over interrupts or similar calls. | ||
75 | * | ||
76 | * During interrupt and other critical calls, a spinlock is used to | ||
77 | * protect the system, but the calls themselves save the address | ||
78 | * in the address register in case they are interrupting another | ||
79 | * access to the device. | ||
80 | * | ||
81 | * For general accesses a lock is provided so that calls which are | ||
82 | * allowed to sleep are serialised so that the address register does | ||
83 | * not need to be saved. This lock also serves to serialise access | ||
84 | * to the EEPROM and PHY access registers which are shared between | ||
85 | * these two devices. | ||
86 | */ | ||
87 | |||
127 | /* Structure/enum declaration ------------------------------- */ | 88 | /* Structure/enum declaration ------------------------------- */ |
128 | typedef struct board_info { | 89 | typedef struct board_info { |
129 | 90 | ||
@@ -137,33 +98,52 @@ typedef struct board_info { | |||
137 | u16 dbug_cnt; | 98 | u16 dbug_cnt; |
138 | u8 io_mode; /* 0:word, 2:byte */ | 99 | u8 io_mode; /* 0:word, 2:byte */ |
139 | u8 phy_addr; | 100 | u8 phy_addr; |
101 | unsigned int flags; | ||
102 | unsigned int in_suspend :1; | ||
103 | |||
104 | int debug_level; | ||
140 | 105 | ||
141 | void (*inblk)(void __iomem *port, void *data, int length); | 106 | void (*inblk)(void __iomem *port, void *data, int length); |
142 | void (*outblk)(void __iomem *port, void *data, int length); | 107 | void (*outblk)(void __iomem *port, void *data, int length); |
143 | void (*dumpblk)(void __iomem *port, int length); | 108 | void (*dumpblk)(void __iomem *port, int length); |
144 | 109 | ||
110 | struct device *dev; /* parent device */ | ||
111 | |||
145 | struct resource *addr_res; /* resources found */ | 112 | struct resource *addr_res; /* resources found */ |
146 | struct resource *data_res; | 113 | struct resource *data_res; |
147 | struct resource *addr_req; /* resources requested */ | 114 | struct resource *addr_req; /* resources requested */ |
148 | struct resource *data_req; | 115 | struct resource *data_req; |
149 | struct resource *irq_res; | 116 | struct resource *irq_res; |
150 | 117 | ||
151 | struct timer_list timer; | 118 | struct mutex addr_lock; /* phy and eeprom access lock */ |
152 | unsigned char srom[128]; | 119 | |
153 | spinlock_t lock; | 120 | spinlock_t lock; |
154 | 121 | ||
155 | struct mii_if_info mii; | 122 | struct mii_if_info mii; |
156 | u32 msg_enable; | 123 | u32 msg_enable; |
157 | } board_info_t; | 124 | } board_info_t; |
158 | 125 | ||
126 | /* debug code */ | ||
127 | |||
128 | #define dm9000_dbg(db, lev, msg...) do { \ | ||
129 | if ((lev) < CONFIG_DM9000_DEBUGLEVEL && \ | ||
130 | (lev) < db->debug_level) { \ | ||
131 | dev_dbg(db->dev, msg); \ | ||
132 | } \ | ||
133 | } while (0) | ||
134 | |||
135 | static inline board_info_t *to_dm9000_board(struct net_device *dev) | ||
136 | { | ||
137 | return dev->priv; | ||
138 | } | ||
139 | |||
159 | /* function declaration ------------------------------------- */ | 140 | /* function declaration ------------------------------------- */ |
160 | static int dm9000_probe(struct platform_device *); | 141 | static int dm9000_probe(struct platform_device *); |
161 | static int dm9000_open(struct net_device *); | 142 | static int dm9000_open(struct net_device *); |
162 | static int dm9000_start_xmit(struct sk_buff *, struct net_device *); | 143 | static int dm9000_start_xmit(struct sk_buff *, struct net_device *); |
163 | static int dm9000_stop(struct net_device *); | 144 | static int dm9000_stop(struct net_device *); |
145 | static int dm9000_ioctl(struct net_device *dev, struct ifreq *req, int cmd); | ||
164 | 146 | ||
165 | |||
166 | static void dm9000_timer(unsigned long); | ||
167 | static void dm9000_init_dm9000(struct net_device *); | 147 | static void dm9000_init_dm9000(struct net_device *); |
168 | 148 | ||
169 | static irqreturn_t dm9000_interrupt(int, void *); | 149 | static irqreturn_t dm9000_interrupt(int, void *); |
@@ -171,20 +151,19 @@ static irqreturn_t dm9000_interrupt(int, void *); | |||
171 | static int dm9000_phy_read(struct net_device *dev, int phyaddr_unsused, int reg); | 151 | static int dm9000_phy_read(struct net_device *dev, int phyaddr_unsused, int reg); |
172 | static void dm9000_phy_write(struct net_device *dev, int phyaddr_unused, int reg, | 152 | static void dm9000_phy_write(struct net_device *dev, int phyaddr_unused, int reg, |
173 | int value); | 153 | int value); |
174 | static u16 read_srom_word(board_info_t *, int); | 154 | |
155 | static void dm9000_read_eeprom(board_info_t *, int addr, u8 *to); | ||
156 | static void dm9000_write_eeprom(board_info_t *, int addr, u8 *dp); | ||
175 | static void dm9000_rx(struct net_device *); | 157 | static void dm9000_rx(struct net_device *); |
176 | static void dm9000_hash_table(struct net_device *); | 158 | static void dm9000_hash_table(struct net_device *); |
177 | 159 | ||
178 | //#define DM9000_PROGRAM_EEPROM | ||
179 | #ifdef DM9000_PROGRAM_EEPROM | ||
180 | static void program_eeprom(board_info_t * db); | ||
181 | #endif | ||
182 | /* DM9000 network board routine ---------------------------- */ | 160 | /* DM9000 network board routine ---------------------------- */ |
183 | 161 | ||
184 | static void | 162 | static void |
185 | dm9000_reset(board_info_t * db) | 163 | dm9000_reset(board_info_t * db) |
186 | { | 164 | { |
187 | PRINTK1("dm9000x: resetting\n"); | 165 | dev_dbg(db->dev, "resetting device\n"); |
166 | |||
188 | /* RESET device */ | 167 | /* RESET device */ |
189 | writeb(DM9000_NCR, db->io_addr); | 168 | writeb(DM9000_NCR, db->io_addr); |
190 | udelay(200); | 169 | udelay(200); |
@@ -300,14 +279,10 @@ static void dm9000_set_io(struct board_info *db, int byte_width) | |||
300 | db->inblk = dm9000_inblk_8bit; | 279 | db->inblk = dm9000_inblk_8bit; |
301 | break; | 280 | break; |
302 | 281 | ||
303 | case 2: | ||
304 | db->dumpblk = dm9000_dumpblk_16bit; | ||
305 | db->outblk = dm9000_outblk_16bit; | ||
306 | db->inblk = dm9000_inblk_16bit; | ||
307 | break; | ||
308 | 282 | ||
309 | case 3: | 283 | case 3: |
310 | printk(KERN_ERR PFX ": 3 byte IO, falling back to 16bit\n"); | 284 | dev_dbg(db->dev, ": 3 byte IO, falling back to 16bit\n"); |
285 | case 2: | ||
311 | db->dumpblk = dm9000_dumpblk_16bit; | 286 | db->dumpblk = dm9000_dumpblk_16bit; |
312 | db->outblk = dm9000_outblk_16bit; | 287 | db->outblk = dm9000_outblk_16bit; |
313 | db->inblk = dm9000_inblk_16bit; | 288 | db->inblk = dm9000_inblk_16bit; |
@@ -358,6 +333,139 @@ static void dm9000_poll_controller(struct net_device *dev) | |||
358 | } | 333 | } |
359 | #endif | 334 | #endif |
360 | 335 | ||
336 | static int dm9000_ioctl(struct net_device *dev, struct ifreq *req, int cmd) | ||
337 | { | ||
338 | board_info_t *dm = to_dm9000_board(dev); | ||
339 | |||
340 | if (!netif_running(dev)) | ||
341 | return -EINVAL; | ||
342 | |||
343 | return generic_mii_ioctl(&dm->mii, if_mii(req), cmd, NULL); | ||
344 | } | ||
345 | |||
346 | /* ethtool ops */ | ||
347 | |||
348 | static void dm9000_get_drvinfo(struct net_device *dev, | ||
349 | struct ethtool_drvinfo *info) | ||
350 | { | ||
351 | board_info_t *dm = to_dm9000_board(dev); | ||
352 | |||
353 | strcpy(info->driver, CARDNAME); | ||
354 | strcpy(info->version, DRV_VERSION); | ||
355 | strcpy(info->bus_info, to_platform_device(dm->dev)->name); | ||
356 | } | ||
357 | |||
358 | static u32 dm9000_get_msglevel(struct net_device *dev) | ||
359 | { | ||
360 | board_info_t *dm = to_dm9000_board(dev); | ||
361 | |||
362 | return dm->msg_enable; | ||
363 | } | ||
364 | |||
365 | static void dm9000_set_msglevel(struct net_device *dev, u32 value) | ||
366 | { | ||
367 | board_info_t *dm = to_dm9000_board(dev); | ||
368 | |||
369 | dm->msg_enable = value; | ||
370 | } | ||
371 | |||
372 | static int dm9000_get_settings(struct net_device *dev, struct ethtool_cmd *cmd) | ||
373 | { | ||
374 | board_info_t *dm = to_dm9000_board(dev); | ||
375 | |||
376 | mii_ethtool_gset(&dm->mii, cmd); | ||
377 | return 0; | ||
378 | } | ||
379 | |||
380 | static int dm9000_set_settings(struct net_device *dev, struct ethtool_cmd *cmd) | ||
381 | { | ||
382 | board_info_t *dm = to_dm9000_board(dev); | ||
383 | |||
384 | return mii_ethtool_sset(&dm->mii, cmd); | ||
385 | } | ||
386 | |||
387 | static int dm9000_nway_reset(struct net_device *dev) | ||
388 | { | ||
389 | board_info_t *dm = to_dm9000_board(dev); | ||
390 | return mii_nway_restart(&dm->mii); | ||
391 | } | ||
392 | |||
393 | static u32 dm9000_get_link(struct net_device *dev) | ||
394 | { | ||
395 | board_info_t *dm = to_dm9000_board(dev); | ||
396 | return mii_link_ok(&dm->mii); | ||
397 | } | ||
398 | |||
399 | #define DM_EEPROM_MAGIC (0x444D394B) | ||
400 | |||
401 | static int dm9000_get_eeprom_len(struct net_device *dev) | ||
402 | { | ||
403 | return 128; | ||
404 | } | ||
405 | |||
406 | static int dm9000_get_eeprom(struct net_device *dev, | ||
407 | struct ethtool_eeprom *ee, u8 *data) | ||
408 | { | ||
409 | board_info_t *dm = to_dm9000_board(dev); | ||
410 | int offset = ee->offset; | ||
411 | int len = ee->len; | ||
412 | int i; | ||
413 | |||
414 | /* EEPROM access is aligned to two bytes */ | ||
415 | |||
416 | if ((len & 1) != 0 || (offset & 1) != 0) | ||
417 | return -EINVAL; | ||
418 | |||
419 | if (dm->flags & DM9000_PLATF_NO_EEPROM) | ||
420 | return -ENOENT; | ||
421 | |||
422 | ee->magic = DM_EEPROM_MAGIC; | ||
423 | |||
424 | for (i = 0; i < len; i += 2) | ||
425 | dm9000_read_eeprom(dm, (offset + i) / 2, data + i); | ||
426 | |||
427 | return 0; | ||
428 | } | ||
429 | |||
430 | static int dm9000_set_eeprom(struct net_device *dev, | ||
431 | struct ethtool_eeprom *ee, u8 *data) | ||
432 | { | ||
433 | board_info_t *dm = to_dm9000_board(dev); | ||
434 | int offset = ee->offset; | ||
435 | int len = ee->len; | ||
436 | int i; | ||
437 | |||
438 | /* EEPROM access is aligned to two bytes */ | ||
439 | |||
440 | if ((len & 1) != 0 || (offset & 1) != 0) | ||
441 | return -EINVAL; | ||
442 | |||
443 | if (dm->flags & DM9000_PLATF_NO_EEPROM) | ||
444 | return -ENOENT; | ||
445 | |||
446 | if (ee->magic != DM_EEPROM_MAGIC) | ||
447 | return -EINVAL; | ||
448 | |||
449 | for (i = 0; i < len; i += 2) | ||
450 | dm9000_write_eeprom(dm, (offset + i) / 2, data + i); | ||
451 | |||
452 | return 0; | ||
453 | } | ||
454 | |||
455 | static const struct ethtool_ops dm9000_ethtool_ops = { | ||
456 | .get_drvinfo = dm9000_get_drvinfo, | ||
457 | .get_settings = dm9000_get_settings, | ||
458 | .set_settings = dm9000_set_settings, | ||
459 | .get_msglevel = dm9000_get_msglevel, | ||
460 | .set_msglevel = dm9000_set_msglevel, | ||
461 | .nway_reset = dm9000_nway_reset, | ||
462 | .get_link = dm9000_get_link, | ||
463 | .get_eeprom_len = dm9000_get_eeprom_len, | ||
464 | .get_eeprom = dm9000_get_eeprom, | ||
465 | .set_eeprom = dm9000_set_eeprom, | ||
466 | }; | ||
467 | |||
468 | |||
361 | /* dm9000_release_board | 469 | /* dm9000_release_board |
362 | * | 470 | * |
363 | * release a board, and any mapped resources | 471 | * release a board, and any mapped resources |
@@ -401,6 +509,7 @@ dm9000_probe(struct platform_device *pdev) | |||
401 | struct dm9000_plat_data *pdata = pdev->dev.platform_data; | 509 | struct dm9000_plat_data *pdata = pdev->dev.platform_data; |
402 | struct board_info *db; /* Point a board information structure */ | 510 | struct board_info *db; /* Point a board information structure */ |
403 | struct net_device *ndev; | 511 | struct net_device *ndev; |
512 | const unsigned char *mac_src; | ||
404 | unsigned long base; | 513 | unsigned long base; |
405 | int ret = 0; | 514 | int ret = 0; |
406 | int iosize; | 515 | int iosize; |
@@ -410,19 +519,22 @@ dm9000_probe(struct platform_device *pdev) | |||
410 | /* Init network device */ | 519 | /* Init network device */ |
411 | ndev = alloc_etherdev(sizeof (struct board_info)); | 520 | ndev = alloc_etherdev(sizeof (struct board_info)); |
412 | if (!ndev) { | 521 | if (!ndev) { |
413 | printk("%s: could not allocate device.\n", CARDNAME); | 522 | dev_err(&pdev->dev, "could not allocate device.\n"); |
414 | return -ENOMEM; | 523 | return -ENOMEM; |
415 | } | 524 | } |
416 | 525 | ||
417 | SET_NETDEV_DEV(ndev, &pdev->dev); | 526 | SET_NETDEV_DEV(ndev, &pdev->dev); |
418 | 527 | ||
419 | PRINTK2("dm9000_probe()"); | 528 | dev_dbg(&pdev->dev, "dm9000_probe()"); |
420 | 529 | ||
421 | /* setup board info structure */ | 530 | /* setup board info structure */ |
422 | db = (struct board_info *) ndev->priv; | 531 | db = (struct board_info *) ndev->priv; |
423 | memset(db, 0, sizeof (*db)); | 532 | memset(db, 0, sizeof (*db)); |
424 | 533 | ||
534 | db->dev = &pdev->dev; | ||
535 | |||
425 | spin_lock_init(&db->lock); | 536 | spin_lock_init(&db->lock); |
537 | mutex_init(&db->addr_lock); | ||
426 | 538 | ||
427 | if (pdev->num_resources < 2) { | 539 | if (pdev->num_resources < 2) { |
428 | ret = -ENODEV; | 540 | ret = -ENODEV; |
@@ -450,7 +562,7 @@ dm9000_probe(struct platform_device *pdev) | |||
450 | 562 | ||
451 | if (db->addr_res == NULL || db->data_res == NULL || | 563 | if (db->addr_res == NULL || db->data_res == NULL || |
452 | db->irq_res == NULL) { | 564 | db->irq_res == NULL) { |
453 | printk(KERN_ERR PFX "insufficient resources\n"); | 565 | dev_err(db->dev, "insufficient resources\n"); |
454 | ret = -ENOENT; | 566 | ret = -ENOENT; |
455 | goto out; | 567 | goto out; |
456 | } | 568 | } |
@@ -460,7 +572,7 @@ dm9000_probe(struct platform_device *pdev) | |||
460 | pdev->name); | 572 | pdev->name); |
461 | 573 | ||
462 | if (db->addr_req == NULL) { | 574 | if (db->addr_req == NULL) { |
463 | printk(KERN_ERR PFX "cannot claim address reg area\n"); | 575 | dev_err(db->dev, "cannot claim address reg area\n"); |
464 | ret = -EIO; | 576 | ret = -EIO; |
465 | goto out; | 577 | goto out; |
466 | } | 578 | } |
@@ -468,7 +580,7 @@ dm9000_probe(struct platform_device *pdev) | |||
468 | db->io_addr = ioremap(db->addr_res->start, i); | 580 | db->io_addr = ioremap(db->addr_res->start, i); |
469 | 581 | ||
470 | if (db->io_addr == NULL) { | 582 | if (db->io_addr == NULL) { |
471 | printk(KERN_ERR "failed to ioremap address reg\n"); | 583 | dev_err(db->dev, "failed to ioremap address reg\n"); |
472 | ret = -EINVAL; | 584 | ret = -EINVAL; |
473 | goto out; | 585 | goto out; |
474 | } | 586 | } |
@@ -478,7 +590,7 @@ dm9000_probe(struct platform_device *pdev) | |||
478 | pdev->name); | 590 | pdev->name); |
479 | 591 | ||
480 | if (db->data_req == NULL) { | 592 | if (db->data_req == NULL) { |
481 | printk(KERN_ERR PFX "cannot claim data reg area\n"); | 593 | dev_err(db->dev, "cannot claim data reg area\n"); |
482 | ret = -EIO; | 594 | ret = -EIO; |
483 | goto out; | 595 | goto out; |
484 | } | 596 | } |
@@ -486,7 +598,7 @@ dm9000_probe(struct platform_device *pdev) | |||
486 | db->io_data = ioremap(db->data_res->start, iosize); | 598 | db->io_data = ioremap(db->data_res->start, iosize); |
487 | 599 | ||
488 | if (db->io_data == NULL) { | 600 | if (db->io_data == NULL) { |
489 | printk(KERN_ERR "failed to ioremap data reg\n"); | 601 | dev_err(db->dev,"failed to ioremap data reg\n"); |
490 | ret = -EINVAL; | 602 | ret = -EINVAL; |
491 | goto out; | 603 | goto out; |
492 | } | 604 | } |
@@ -525,12 +637,14 @@ dm9000_probe(struct platform_device *pdev) | |||
525 | 637 | ||
526 | if (pdata->dumpblk != NULL) | 638 | if (pdata->dumpblk != NULL) |
527 | db->dumpblk = pdata->dumpblk; | 639 | db->dumpblk = pdata->dumpblk; |
640 | |||
641 | db->flags = pdata->flags; | ||
528 | } | 642 | } |
529 | 643 | ||
530 | dm9000_reset(db); | 644 | dm9000_reset(db); |
531 | 645 | ||
532 | /* try two times, DM9000 sometimes gets the first read wrong */ | 646 | /* try two times, DM9000 sometimes gets the first read wrong */ |
533 | for (i = 0; i < 2; i++) { | 647 | for (i = 0; i < 8; i++) { |
534 | id_val = ior(db, DM9000_VIDL); | 648 | id_val = ior(db, DM9000_VIDL); |
535 | id_val |= (u32)ior(db, DM9000_VIDH) << 8; | 649 | id_val |= (u32)ior(db, DM9000_VIDH) << 8; |
536 | id_val |= (u32)ior(db, DM9000_PIDL) << 16; | 650 | id_val |= (u32)ior(db, DM9000_PIDL) << 16; |
@@ -538,11 +652,11 @@ dm9000_probe(struct platform_device *pdev) | |||
538 | 652 | ||
539 | if (id_val == DM9000_ID) | 653 | if (id_val == DM9000_ID) |
540 | break; | 654 | break; |
541 | printk("%s: read wrong id 0x%08x\n", CARDNAME, id_val); | 655 | dev_err(db->dev, "read wrong id 0x%08x\n", id_val); |
542 | } | 656 | } |
543 | 657 | ||
544 | if (id_val != DM9000_ID) { | 658 | if (id_val != DM9000_ID) { |
545 | printk("%s: wrong id: 0x%08x\n", CARDNAME, id_val); | 659 | dev_err(db->dev, "wrong id: 0x%08x\n", id_val); |
546 | ret = -ENODEV; | 660 | ret = -ENODEV; |
547 | goto out; | 661 | goto out; |
548 | } | 662 | } |
@@ -558,13 +672,13 @@ dm9000_probe(struct platform_device *pdev) | |||
558 | ndev->watchdog_timeo = msecs_to_jiffies(watchdog); | 672 | ndev->watchdog_timeo = msecs_to_jiffies(watchdog); |
559 | ndev->stop = &dm9000_stop; | 673 | ndev->stop = &dm9000_stop; |
560 | ndev->set_multicast_list = &dm9000_hash_table; | 674 | ndev->set_multicast_list = &dm9000_hash_table; |
675 | ndev->ethtool_ops = &dm9000_ethtool_ops; | ||
676 | ndev->do_ioctl = &dm9000_ioctl; | ||
677 | |||
561 | #ifdef CONFIG_NET_POLL_CONTROLLER | 678 | #ifdef CONFIG_NET_POLL_CONTROLLER |
562 | ndev->poll_controller = &dm9000_poll_controller; | 679 | ndev->poll_controller = &dm9000_poll_controller; |
563 | #endif | 680 | #endif |
564 | 681 | ||
565 | #ifdef DM9000_PROGRAM_EEPROM | ||
566 | program_eeprom(db); | ||
567 | #endif | ||
568 | db->msg_enable = NETIF_MSG_LINK; | 682 | db->msg_enable = NETIF_MSG_LINK; |
569 | db->mii.phy_id_mask = 0x1f; | 683 | db->mii.phy_id_mask = 0x1f; |
570 | db->mii.reg_num_mask = 0x1f; | 684 | db->mii.reg_num_mask = 0x1f; |
@@ -574,38 +688,37 @@ dm9000_probe(struct platform_device *pdev) | |||
574 | db->mii.mdio_read = dm9000_phy_read; | 688 | db->mii.mdio_read = dm9000_phy_read; |
575 | db->mii.mdio_write = dm9000_phy_write; | 689 | db->mii.mdio_write = dm9000_phy_write; |
576 | 690 | ||
577 | /* Read SROM content */ | 691 | mac_src = "eeprom"; |
578 | for (i = 0; i < 64; i++) | ||
579 | ((u16 *) db->srom)[i] = read_srom_word(db, i); | ||
580 | 692 | ||
581 | /* Set Node Address */ | 693 | /* try reading the node address from the attached EEPROM */ |
582 | for (i = 0; i < 6; i++) | 694 | for (i = 0; i < 6; i += 2) |
583 | ndev->dev_addr[i] = db->srom[i]; | 695 | dm9000_read_eeprom(db, i / 2, ndev->dev_addr+i); |
584 | 696 | ||
585 | if (!is_valid_ether_addr(ndev->dev_addr)) { | 697 | if (!is_valid_ether_addr(ndev->dev_addr)) { |
586 | /* try reading from mac */ | 698 | /* try reading from mac */ |
587 | 699 | ||
700 | mac_src = "chip"; | ||
588 | for (i = 0; i < 6; i++) | 701 | for (i = 0; i < 6; i++) |
589 | ndev->dev_addr[i] = ior(db, i+DM9000_PAR); | 702 | ndev->dev_addr[i] = ior(db, i+DM9000_PAR); |
590 | } | 703 | } |
591 | 704 | ||
592 | if (!is_valid_ether_addr(ndev->dev_addr)) | 705 | if (!is_valid_ether_addr(ndev->dev_addr)) |
593 | printk("%s: Invalid ethernet MAC address. Please " | 706 | dev_warn(db->dev, "%s: Invalid ethernet MAC address. Please " |
594 | "set using ifconfig\n", ndev->name); | 707 | "set using ifconfig\n", ndev->name); |
595 | 708 | ||
596 | platform_set_drvdata(pdev, ndev); | 709 | platform_set_drvdata(pdev, ndev); |
597 | ret = register_netdev(ndev); | 710 | ret = register_netdev(ndev); |
598 | 711 | ||
599 | if (ret == 0) { | 712 | if (ret == 0) { |
600 | DECLARE_MAC_BUF(mac); | 713 | DECLARE_MAC_BUF(mac); |
601 | printk("%s: dm9000 at %p,%p IRQ %d MAC: %s\n", | 714 | printk("%s: dm9000 at %p,%p IRQ %d MAC: %s (%s)\n", |
602 | ndev->name, db->io_addr, db->io_data, ndev->irq, | 715 | ndev->name, db->io_addr, db->io_data, ndev->irq, |
603 | print_mac(mac, ndev->dev_addr)); | 716 | print_mac(mac, ndev->dev_addr), mac_src); |
604 | } | 717 | } |
605 | return 0; | 718 | return 0; |
606 | 719 | ||
607 | out: | 720 | out: |
608 | printk("%s: not found (%d).\n", CARDNAME, ret); | 721 | dev_err(db->dev, "not found (%d).\n", ret); |
609 | 722 | ||
610 | dm9000_release_board(pdev, db); | 723 | dm9000_release_board(pdev, db); |
611 | free_netdev(ndev); | 724 | free_netdev(ndev); |
@@ -621,10 +734,22 @@ static int | |||
621 | dm9000_open(struct net_device *dev) | 734 | dm9000_open(struct net_device *dev) |
622 | { | 735 | { |
623 | board_info_t *db = (board_info_t *) dev->priv; | 736 | board_info_t *db = (board_info_t *) dev->priv; |
737 | unsigned long irqflags = db->irq_res->flags & IRQF_TRIGGER_MASK; | ||
624 | 738 | ||
625 | PRINTK2("entering dm9000_open\n"); | 739 | if (netif_msg_ifup(db)) |
740 | dev_dbg(db->dev, "enabling %s\n", dev->name); | ||
626 | 741 | ||
627 | if (request_irq(dev->irq, &dm9000_interrupt, DM9000_IRQ_FLAGS, dev->name, dev)) | 742 | /* If there is no IRQ type specified, default to something that |
743 | * may work, and tell the user that this is a problem */ | ||
744 | |||
745 | if (irqflags == IRQF_TRIGGER_NONE) { | ||
746 | dev_warn(db->dev, "WARNING: no IRQ resource flags set.\n"); | ||
747 | irqflags = DEFAULT_TRIGGER; | ||
748 | } | ||
749 | |||
750 | irqflags |= IRQF_SHARED; | ||
751 | |||
752 | if (request_irq(dev->irq, &dm9000_interrupt, irqflags, dev->name, dev)) | ||
628 | return -EAGAIN; | 753 | return -EAGAIN; |
629 | 754 | ||
630 | /* Initialize DM9000 board */ | 755 | /* Initialize DM9000 board */ |
@@ -634,13 +759,6 @@ dm9000_open(struct net_device *dev) | |||
634 | /* Init driver variable */ | 759 | /* Init driver variable */ |
635 | db->dbug_cnt = 0; | 760 | db->dbug_cnt = 0; |
636 | 761 | ||
637 | /* set and active a timer process */ | ||
638 | init_timer(&db->timer); | ||
639 | db->timer.expires = DM9000_TIMER_WUT; | ||
640 | db->timer.data = (unsigned long) dev; | ||
641 | db->timer.function = &dm9000_timer; | ||
642 | add_timer(&db->timer); | ||
643 | |||
644 | mii_check_media(&db->mii, netif_msg_link(db), 1); | 762 | mii_check_media(&db->mii, netif_msg_link(db), 1); |
645 | netif_start_queue(dev); | 763 | netif_start_queue(dev); |
646 | 764 | ||
@@ -655,7 +773,7 @@ dm9000_init_dm9000(struct net_device *dev) | |||
655 | { | 773 | { |
656 | board_info_t *db = (board_info_t *) dev->priv; | 774 | board_info_t *db = (board_info_t *) dev->priv; |
657 | 775 | ||
658 | PRINTK1("entering %s\n",__FUNCTION__); | 776 | dm9000_dbg(db, 1, "entering %s\n", __func__); |
659 | 777 | ||
660 | /* I/O mode */ | 778 | /* I/O mode */ |
661 | db->io_mode = ior(db, DM9000_ISR) >> 6; /* ISR bit7:6 keeps I/O mode */ | 779 | db->io_mode = ior(db, DM9000_ISR) >> 6; /* ISR bit7:6 keeps I/O mode */ |
@@ -665,6 +783,9 @@ dm9000_init_dm9000(struct net_device *dev) | |||
665 | iow(db, DM9000_GPCR, GPCR_GEP_CNTL); /* Let GPIO0 output */ | 783 | iow(db, DM9000_GPCR, GPCR_GEP_CNTL); /* Let GPIO0 output */ |
666 | iow(db, DM9000_GPR, 0); /* Enable PHY */ | 784 | iow(db, DM9000_GPR, 0); /* Enable PHY */ |
667 | 785 | ||
786 | if (db->flags & DM9000_PLATF_EXT_PHY) | ||
787 | iow(db, DM9000_NCR, NCR_EXT_PHY); | ||
788 | |||
668 | /* Program operating register */ | 789 | /* Program operating register */ |
669 | iow(db, DM9000_TCR, 0); /* TX Polling clear */ | 790 | iow(db, DM9000_TCR, 0); /* TX Polling clear */ |
670 | iow(db, DM9000_BPTR, 0x3f); /* Less 3Kb, 200us */ | 791 | iow(db, DM9000_BPTR, 0x3f); /* Less 3Kb, 200us */ |
@@ -698,7 +819,7 @@ dm9000_start_xmit(struct sk_buff *skb, struct net_device *dev) | |||
698 | unsigned long flags; | 819 | unsigned long flags; |
699 | board_info_t *db = (board_info_t *) dev->priv; | 820 | board_info_t *db = (board_info_t *) dev->priv; |
700 | 821 | ||
701 | PRINTK3("dm9000_start_xmit\n"); | 822 | dm9000_dbg(db, 3, "%s:\n", __func__); |
702 | 823 | ||
703 | if (db->tx_pkt_cnt > 1) | 824 | if (db->tx_pkt_cnt > 1) |
704 | return 1; | 825 | return 1; |
@@ -715,8 +836,8 @@ dm9000_start_xmit(struct sk_buff *skb, struct net_device *dev) | |||
715 | /* TX control: First packet immediately send, second packet queue */ | 836 | /* TX control: First packet immediately send, second packet queue */ |
716 | if (db->tx_pkt_cnt == 1) { | 837 | if (db->tx_pkt_cnt == 1) { |
717 | /* Set TX length to DM9000 */ | 838 | /* Set TX length to DM9000 */ |
718 | iow(db, DM9000_TXPLL, skb->len & 0xff); | 839 | iow(db, DM9000_TXPLL, skb->len); |
719 | iow(db, DM9000_TXPLH, (skb->len >> 8) & 0xff); | 840 | iow(db, DM9000_TXPLH, skb->len >> 8); |
720 | 841 | ||
721 | /* Issue TX polling command */ | 842 | /* Issue TX polling command */ |
722 | iow(db, DM9000_TCR, TCR_TXREQ); /* Cleared after TX complete */ | 843 | iow(db, DM9000_TCR, TCR_TXREQ); /* Cleared after TX complete */ |
@@ -757,10 +878,8 @@ dm9000_stop(struct net_device *ndev) | |||
757 | { | 878 | { |
758 | board_info_t *db = (board_info_t *) ndev->priv; | 879 | board_info_t *db = (board_info_t *) ndev->priv; |
759 | 880 | ||
760 | PRINTK1("entering %s\n",__FUNCTION__); | 881 | if (netif_msg_ifdown(db)) |
761 | 882 | dev_dbg(db->dev, "shutting down %s\n", ndev->name); | |
762 | /* deleted timer */ | ||
763 | del_timer(&db->timer); | ||
764 | 883 | ||
765 | netif_stop_queue(ndev); | 884 | netif_stop_queue(ndev); |
766 | netif_carrier_off(ndev); | 885 | netif_carrier_off(ndev); |
@@ -788,10 +907,13 @@ dm9000_tx_done(struct net_device *dev, board_info_t * db) | |||
788 | db->tx_pkt_cnt--; | 907 | db->tx_pkt_cnt--; |
789 | dev->stats.tx_packets++; | 908 | dev->stats.tx_packets++; |
790 | 909 | ||
910 | if (netif_msg_tx_done(db)) | ||
911 | dev_dbg(db->dev, "tx done, NSR %02x\n", tx_status); | ||
912 | |||
791 | /* Queue packet check & send */ | 913 | /* Queue packet check & send */ |
792 | if (db->tx_pkt_cnt > 0) { | 914 | if (db->tx_pkt_cnt > 0) { |
793 | iow(db, DM9000_TXPLL, db->queue_pkt_len & 0xff); | 915 | iow(db, DM9000_TXPLL, db->queue_pkt_len); |
794 | iow(db, DM9000_TXPLH, (db->queue_pkt_len >> 8) & 0xff); | 916 | iow(db, DM9000_TXPLH, db->queue_pkt_len >> 8); |
795 | iow(db, DM9000_TCR, TCR_TXREQ); | 917 | iow(db, DM9000_TCR, TCR_TXREQ); |
796 | dev->trans_start = jiffies; | 918 | dev->trans_start = jiffies; |
797 | } | 919 | } |
@@ -803,19 +925,14 @@ static irqreturn_t | |||
803 | dm9000_interrupt(int irq, void *dev_id) | 925 | dm9000_interrupt(int irq, void *dev_id) |
804 | { | 926 | { |
805 | struct net_device *dev = dev_id; | 927 | struct net_device *dev = dev_id; |
806 | board_info_t *db; | 928 | board_info_t *db = (board_info_t *) dev->priv; |
807 | int int_status; | 929 | int int_status; |
808 | u8 reg_save; | 930 | u8 reg_save; |
809 | 931 | ||
810 | PRINTK3("entering %s\n",__FUNCTION__); | 932 | dm9000_dbg(db, 3, "entering %s\n", __func__); |
811 | |||
812 | if (!dev) { | ||
813 | PRINTK1("dm9000_interrupt() without DEVICE arg\n"); | ||
814 | return IRQ_HANDLED; | ||
815 | } | ||
816 | 933 | ||
817 | /* A real interrupt coming */ | 934 | /* A real interrupt coming */ |
818 | db = (board_info_t *) dev->priv; | 935 | |
819 | spin_lock(&db->lock); | 936 | spin_lock(&db->lock); |
820 | 937 | ||
821 | /* Save previous register address */ | 938 | /* Save previous register address */ |
@@ -828,6 +945,9 @@ dm9000_interrupt(int irq, void *dev_id) | |||
828 | int_status = ior(db, DM9000_ISR); /* Got ISR */ | 945 | int_status = ior(db, DM9000_ISR); /* Got ISR */ |
829 | iow(db, DM9000_ISR, int_status); /* Clear ISR status */ | 946 | iow(db, DM9000_ISR, int_status); /* Clear ISR status */ |
830 | 947 | ||
948 | if (netif_msg_intr(db)) | ||
949 | dev_dbg(db->dev, "interrupt status %02x\n", int_status); | ||
950 | |||
831 | /* Received the coming packet */ | 951 | /* Received the coming packet */ |
832 | if (int_status & ISR_PRS) | 952 | if (int_status & ISR_PRS) |
833 | dm9000_rx(dev); | 953 | dm9000_rx(dev); |
@@ -847,27 +967,9 @@ dm9000_interrupt(int irq, void *dev_id) | |||
847 | return IRQ_HANDLED; | 967 | return IRQ_HANDLED; |
848 | } | 968 | } |
849 | 969 | ||
850 | /* | ||
851 | * A periodic timer routine | ||
852 | * Dynamic media sense, allocated Rx buffer... | ||
853 | */ | ||
854 | static void | ||
855 | dm9000_timer(unsigned long data) | ||
856 | { | ||
857 | struct net_device *dev = (struct net_device *) data; | ||
858 | board_info_t *db = (board_info_t *) dev->priv; | ||
859 | |||
860 | PRINTK3("dm9000_timer()\n"); | ||
861 | |||
862 | mii_check_media(&db->mii, netif_msg_link(db), 0); | ||
863 | |||
864 | /* Set timer again */ | ||
865 | db->timer.expires = DM9000_TIMER_WUT; | ||
866 | add_timer(&db->timer); | ||
867 | } | ||
868 | |||
869 | struct dm9000_rxhdr { | 970 | struct dm9000_rxhdr { |
870 | u16 RxStatus; | 971 | u8 RxPktReady; |
972 | u8 RxStatus; | ||
871 | u16 RxLen; | 973 | u16 RxLen; |
872 | } __attribute__((__packed__)); | 974 | } __attribute__((__packed__)); |
873 | 975 | ||
@@ -893,7 +995,7 @@ dm9000_rx(struct net_device *dev) | |||
893 | 995 | ||
894 | /* Status check: this byte must be 0 or 1 */ | 996 | /* Status check: this byte must be 0 or 1 */ |
895 | if (rxbyte > DM9000_PKT_RDY) { | 997 | if (rxbyte > DM9000_PKT_RDY) { |
896 | printk("status check failed: %d\n", rxbyte); | 998 | dev_warn(db->dev, "status check fail: %d\n", rxbyte); |
897 | iow(db, DM9000_RCR, 0x00); /* Stop Device */ | 999 | iow(db, DM9000_RCR, 0x00); /* Stop Device */ |
898 | iow(db, DM9000_ISR, IMR_PAR); /* Stop INT request */ | 1000 | iow(db, DM9000_ISR, IMR_PAR); /* Stop INT request */ |
899 | return; | 1001 | return; |
@@ -908,30 +1010,38 @@ dm9000_rx(struct net_device *dev) | |||
908 | 1010 | ||
909 | (db->inblk)(db->io_data, &rxhdr, sizeof(rxhdr)); | 1011 | (db->inblk)(db->io_data, &rxhdr, sizeof(rxhdr)); |
910 | 1012 | ||
911 | RxLen = rxhdr.RxLen; | 1013 | RxLen = le16_to_cpu(rxhdr.RxLen); |
1014 | |||
1015 | if (netif_msg_rx_status(db)) | ||
1016 | dev_dbg(db->dev, "RX: status %02x, length %04x\n", | ||
1017 | rxhdr.RxStatus, RxLen); | ||
912 | 1018 | ||
913 | /* Packet Status check */ | 1019 | /* Packet Status check */ |
914 | if (RxLen < 0x40) { | 1020 | if (RxLen < 0x40) { |
915 | GoodPacket = false; | 1021 | GoodPacket = false; |
916 | PRINTK1("Bad Packet received (runt)\n"); | 1022 | if (netif_msg_rx_err(db)) |
1023 | dev_dbg(db->dev, "RX: Bad Packet (runt)\n"); | ||
917 | } | 1024 | } |
918 | 1025 | ||
919 | if (RxLen > DM9000_PKT_MAX) { | 1026 | if (RxLen > DM9000_PKT_MAX) { |
920 | PRINTK1("RST: RX Len:%x\n", RxLen); | 1027 | dev_dbg(db->dev, "RST: RX Len:%x\n", RxLen); |
921 | } | 1028 | } |
922 | 1029 | ||
923 | if (rxhdr.RxStatus & 0xbf00) { | 1030 | if (rxhdr.RxStatus & 0xbf) { |
924 | GoodPacket = false; | 1031 | GoodPacket = false; |
925 | if (rxhdr.RxStatus & 0x100) { | 1032 | if (rxhdr.RxStatus & 0x01) { |
926 | PRINTK1("fifo error\n"); | 1033 | if (netif_msg_rx_err(db)) |
1034 | dev_dbg(db->dev, "fifo error\n"); | ||
927 | dev->stats.rx_fifo_errors++; | 1035 | dev->stats.rx_fifo_errors++; |
928 | } | 1036 | } |
929 | if (rxhdr.RxStatus & 0x200) { | 1037 | if (rxhdr.RxStatus & 0x02) { |
930 | PRINTK1("crc error\n"); | 1038 | if (netif_msg_rx_err(db)) |
1039 | dev_dbg(db->dev, "crc error\n"); | ||
931 | dev->stats.rx_crc_errors++; | 1040 | dev->stats.rx_crc_errors++; |
932 | } | 1041 | } |
933 | if (rxhdr.RxStatus & 0x8000) { | 1042 | if (rxhdr.RxStatus & 0x80) { |
934 | PRINTK1("length error\n"); | 1043 | if (netif_msg_rx_err(db)) |
1044 | dev_dbg(db->dev, "length error\n"); | ||
935 | dev->stats.rx_length_errors++; | 1045 | dev->stats.rx_length_errors++; |
936 | } | 1046 | } |
937 | } | 1047 | } |
@@ -960,72 +1070,119 @@ dm9000_rx(struct net_device *dev) | |||
960 | } while (rxbyte == DM9000_PKT_RDY); | 1070 | } while (rxbyte == DM9000_PKT_RDY); |
961 | } | 1071 | } |
962 | 1072 | ||
963 | /* | 1073 | static unsigned int |
964 | * Read a word data from SROM | 1074 | dm9000_read_locked(board_info_t *db, int reg) |
965 | */ | ||
966 | static u16 | ||
967 | read_srom_word(board_info_t * db, int offset) | ||
968 | { | 1075 | { |
969 | iow(db, DM9000_EPAR, offset); | 1076 | unsigned long flags; |
970 | iow(db, DM9000_EPCR, EPCR_ERPRR); | 1077 | unsigned int ret; |
971 | mdelay(8); /* according to the datasheet 200us should be enough, | 1078 | |
972 | but it doesn't work */ | 1079 | spin_lock_irqsave(&db->lock, flags); |
973 | iow(db, DM9000_EPCR, 0x0); | 1080 | ret = ior(db, reg); |
974 | return (ior(db, DM9000_EPDRL) + (ior(db, DM9000_EPDRH) << 8)); | 1081 | spin_unlock_irqrestore(&db->lock, flags); |
1082 | |||
1083 | return ret; | ||
1084 | } | ||
1085 | |||
1086 | static int dm9000_wait_eeprom(board_info_t *db) | ||
1087 | { | ||
1088 | unsigned int status; | ||
1089 | int timeout = 8; /* wait max 8msec */ | ||
1090 | |||
1091 | /* The DM9000 data sheets say we should be able to | ||
1092 | * poll the ERRE bit in EPCR to wait for the EEPROM | ||
1093 | * operation. From testing several chips, this bit | ||
1094 | * does not seem to work. | ||
1095 | * | ||
1096 | * We attempt to use the bit, but fall back to the | ||
1097 | * timeout (which is why we do not return an error | ||
1098 | * on expiry) to say that the EEPROM operation has | ||
1099 | * completed. | ||
1100 | */ | ||
1101 | |||
1102 | while (1) { | ||
1103 | status = dm9000_read_locked(db, DM9000_EPCR); | ||
1104 | |||
1105 | if ((status & EPCR_ERRE) == 0) | ||
1106 | break; | ||
1107 | |||
1108 | if (timeout-- < 0) { | ||
1109 | dev_dbg(db->dev, "timeout waiting EEPROM\n"); | ||
1110 | break; | ||
1111 | } | ||
1112 | } | ||
1113 | |||
1114 | return 0; | ||
975 | } | 1115 | } |
976 | 1116 | ||
977 | #ifdef DM9000_PROGRAM_EEPROM | ||
978 | /* | 1117 | /* |
979 | * Write a word data to SROM | 1118 | * Read a word data from EEPROM |
980 | */ | 1119 | */ |
981 | static void | 1120 | static void |
982 | write_srom_word(board_info_t * db, int offset, u16 val) | 1121 | dm9000_read_eeprom(board_info_t *db, int offset, u8 *to) |
983 | { | 1122 | { |
1123 | unsigned long flags; | ||
1124 | |||
1125 | if (db->flags & DM9000_PLATF_NO_EEPROM) { | ||
1126 | to[0] = 0xff; | ||
1127 | to[1] = 0xff; | ||
1128 | return; | ||
1129 | } | ||
1130 | |||
1131 | mutex_lock(&db->addr_lock); | ||
1132 | |||
1133 | spin_lock_irqsave(&db->lock, flags); | ||
1134 | |||
984 | iow(db, DM9000_EPAR, offset); | 1135 | iow(db, DM9000_EPAR, offset); |
985 | iow(db, DM9000_EPDRH, ((val >> 8) & 0xff)); | 1136 | iow(db, DM9000_EPCR, EPCR_ERPRR); |
986 | iow(db, DM9000_EPDRL, (val & 0xff)); | 1137 | |
987 | iow(db, DM9000_EPCR, EPCR_WEP | EPCR_ERPRW); | 1138 | spin_unlock_irqrestore(&db->lock, flags); |
988 | mdelay(8); /* same shit */ | 1139 | |
989 | iow(db, DM9000_EPCR, 0); | 1140 | dm9000_wait_eeprom(db); |
1141 | |||
1142 | /* delay for at-least 150uS */ | ||
1143 | msleep(1); | ||
1144 | |||
1145 | spin_lock_irqsave(&db->lock, flags); | ||
1146 | |||
1147 | iow(db, DM9000_EPCR, 0x0); | ||
1148 | |||
1149 | to[0] = ior(db, DM9000_EPDRL); | ||
1150 | to[1] = ior(db, DM9000_EPDRH); | ||
1151 | |||
1152 | spin_unlock_irqrestore(&db->lock, flags); | ||
1153 | |||
1154 | mutex_unlock(&db->addr_lock); | ||
990 | } | 1155 | } |
991 | 1156 | ||
992 | /* | 1157 | /* |
993 | * Only for development: | 1158 | * Write a word data to SROM |
994 | * Here we write static data to the eeprom in case | ||
995 | * we don't have valid content on a new board | ||
996 | */ | 1159 | */ |
997 | static void | 1160 | static void |
998 | program_eeprom(board_info_t * db) | 1161 | dm9000_write_eeprom(board_info_t *db, int offset, u8 *data) |
999 | { | 1162 | { |
1000 | u16 eeprom[] = { 0x0c00, 0x007f, 0x1300, /* MAC Address */ | 1163 | unsigned long flags; |
1001 | 0x0000, /* Autoload: accept nothing */ | ||
1002 | 0x0a46, 0x9000, /* Vendor / Product ID */ | ||
1003 | 0x0000, /* pin control */ | ||
1004 | 0x0000, | ||
1005 | }; /* Wake-up mode control */ | ||
1006 | int i; | ||
1007 | for (i = 0; i < 8; i++) | ||
1008 | write_srom_word(db, i, eeprom[i]); | ||
1009 | } | ||
1010 | #endif | ||
1011 | 1164 | ||
1165 | if (db->flags & DM9000_PLATF_NO_EEPROM) | ||
1166 | return; | ||
1012 | 1167 | ||
1013 | /* | 1168 | mutex_lock(&db->addr_lock); |
1014 | * Calculate the CRC valude of the Rx packet | ||
1015 | * flag = 1 : return the reverse CRC (for the received packet CRC) | ||
1016 | * 0 : return the normal CRC (for Hash Table index) | ||
1017 | */ | ||
1018 | 1169 | ||
1019 | static unsigned long | 1170 | spin_lock_irqsave(&db->lock, flags); |
1020 | cal_CRC(unsigned char *Data, unsigned int Len, u8 flag) | 1171 | iow(db, DM9000_EPAR, offset); |
1021 | { | 1172 | iow(db, DM9000_EPDRH, data[1]); |
1173 | iow(db, DM9000_EPDRL, data[0]); | ||
1174 | iow(db, DM9000_EPCR, EPCR_WEP | EPCR_ERPRW); | ||
1175 | spin_unlock_irqrestore(&db->lock, flags); | ||
1176 | |||
1177 | dm9000_wait_eeprom(db); | ||
1022 | 1178 | ||
1023 | u32 crc = ether_crc_le(Len, Data); | 1179 | mdelay(1); /* wait at least 150uS to clear */ |
1024 | 1180 | ||
1025 | if (flag) | 1181 | spin_lock_irqsave(&db->lock, flags); |
1026 | return ~crc; | 1182 | iow(db, DM9000_EPCR, 0); |
1183 | spin_unlock_irqrestore(&db->lock, flags); | ||
1027 | 1184 | ||
1028 | return crc; | 1185 | mutex_unlock(&db->addr_lock); |
1029 | } | 1186 | } |
1030 | 1187 | ||
1031 | /* | 1188 | /* |
@@ -1037,15 +1194,16 @@ dm9000_hash_table(struct net_device *dev) | |||
1037 | board_info_t *db = (board_info_t *) dev->priv; | 1194 | board_info_t *db = (board_info_t *) dev->priv; |
1038 | struct dev_mc_list *mcptr = dev->mc_list; | 1195 | struct dev_mc_list *mcptr = dev->mc_list; |
1039 | int mc_cnt = dev->mc_count; | 1196 | int mc_cnt = dev->mc_count; |
1197 | int i, oft; | ||
1040 | u32 hash_val; | 1198 | u32 hash_val; |
1041 | u16 i, oft, hash_table[4]; | 1199 | u16 hash_table[4]; |
1042 | unsigned long flags; | 1200 | unsigned long flags; |
1043 | 1201 | ||
1044 | PRINTK2("dm9000_hash_table()\n"); | 1202 | dm9000_dbg(db, 1, "entering %s\n", __func__); |
1045 | 1203 | ||
1046 | spin_lock_irqsave(&db->lock,flags); | 1204 | spin_lock_irqsave(&db->lock, flags); |
1047 | 1205 | ||
1048 | for (i = 0, oft = 0x10; i < 6; i++, oft++) | 1206 | for (i = 0, oft = DM9000_PAR; i < 6; i++, oft++) |
1049 | iow(db, oft, dev->dev_addr[i]); | 1207 | iow(db, oft, dev->dev_addr[i]); |
1050 | 1208 | ||
1051 | /* Clear Hash Table */ | 1209 | /* Clear Hash Table */ |
@@ -1057,21 +1215,33 @@ dm9000_hash_table(struct net_device *dev) | |||
1057 | 1215 | ||
1058 | /* the multicast address in Hash Table : 64 bits */ | 1216 | /* the multicast address in Hash Table : 64 bits */ |
1059 | for (i = 0; i < mc_cnt; i++, mcptr = mcptr->next) { | 1217 | for (i = 0; i < mc_cnt; i++, mcptr = mcptr->next) { |
1060 | hash_val = cal_CRC((char *) mcptr->dmi_addr, 6, 0) & 0x3f; | 1218 | hash_val = ether_crc_le(6, mcptr->dmi_addr) & 0x3f; |
1061 | hash_table[hash_val / 16] |= (u16) 1 << (hash_val % 16); | 1219 | hash_table[hash_val / 16] |= (u16) 1 << (hash_val % 16); |
1062 | } | 1220 | } |
1063 | 1221 | ||
1064 | /* Write the hash table to MAC MD table */ | 1222 | /* Write the hash table to MAC MD table */ |
1065 | for (i = 0, oft = 0x16; i < 4; i++) { | 1223 | for (i = 0, oft = DM9000_MAR; i < 4; i++) { |
1066 | iow(db, oft++, hash_table[i] & 0xff); | 1224 | iow(db, oft++, hash_table[i]); |
1067 | iow(db, oft++, (hash_table[i] >> 8) & 0xff); | 1225 | iow(db, oft++, hash_table[i] >> 8); |
1068 | } | 1226 | } |
1069 | 1227 | ||
1070 | spin_unlock_irqrestore(&db->lock,flags); | 1228 | spin_unlock_irqrestore(&db->lock, flags); |
1071 | } | 1229 | } |
1072 | 1230 | ||
1073 | 1231 | ||
1074 | /* | 1232 | /* |
1233 | * Sleep, either by using msleep() or if we are suspending, then | ||
1234 | * use mdelay() to sleep. | ||
1235 | */ | ||
1236 | static void dm9000_msleep(board_info_t *db, unsigned int ms) | ||
1237 | { | ||
1238 | if (db->in_suspend) | ||
1239 | mdelay(ms); | ||
1240 | else | ||
1241 | msleep(ms); | ||
1242 | } | ||
1243 | |||
1244 | /* | ||
1075 | * Read a word from phyxcer | 1245 | * Read a word from phyxcer |
1076 | */ | 1246 | */ |
1077 | static int | 1247 | static int |
@@ -1082,6 +1252,8 @@ dm9000_phy_read(struct net_device *dev, int phy_reg_unused, int reg) | |||
1082 | unsigned int reg_save; | 1252 | unsigned int reg_save; |
1083 | int ret; | 1253 | int ret; |
1084 | 1254 | ||
1255 | mutex_lock(&db->addr_lock); | ||
1256 | |||
1085 | spin_lock_irqsave(&db->lock,flags); | 1257 | spin_lock_irqsave(&db->lock,flags); |
1086 | 1258 | ||
1087 | /* Save previous register address */ | 1259 | /* Save previous register address */ |
@@ -1091,7 +1263,15 @@ dm9000_phy_read(struct net_device *dev, int phy_reg_unused, int reg) | |||
1091 | iow(db, DM9000_EPAR, DM9000_PHY | reg); | 1263 | iow(db, DM9000_EPAR, DM9000_PHY | reg); |
1092 | 1264 | ||
1093 | iow(db, DM9000_EPCR, 0xc); /* Issue phyxcer read command */ | 1265 | iow(db, DM9000_EPCR, 0xc); /* Issue phyxcer read command */ |
1094 | udelay(100); /* Wait read complete */ | 1266 | |
1267 | writeb(reg_save, db->io_addr); | ||
1268 | spin_unlock_irqrestore(&db->lock,flags); | ||
1269 | |||
1270 | dm9000_msleep(db, 1); /* Wait read complete */ | ||
1271 | |||
1272 | spin_lock_irqsave(&db->lock,flags); | ||
1273 | reg_save = readb(db->io_addr); | ||
1274 | |||
1095 | iow(db, DM9000_EPCR, 0x0); /* Clear phyxcer read command */ | 1275 | iow(db, DM9000_EPCR, 0x0); /* Clear phyxcer read command */ |
1096 | 1276 | ||
1097 | /* The read data keeps on REG_0D & REG_0E */ | 1277 | /* The read data keeps on REG_0D & REG_0E */ |
@@ -1099,9 +1279,9 @@ dm9000_phy_read(struct net_device *dev, int phy_reg_unused, int reg) | |||
1099 | 1279 | ||
1100 | /* restore the previous address */ | 1280 | /* restore the previous address */ |
1101 | writeb(reg_save, db->io_addr); | 1281 | writeb(reg_save, db->io_addr); |
1102 | |||
1103 | spin_unlock_irqrestore(&db->lock,flags); | 1282 | spin_unlock_irqrestore(&db->lock,flags); |
1104 | 1283 | ||
1284 | mutex_unlock(&db->addr_lock); | ||
1105 | return ret; | 1285 | return ret; |
1106 | } | 1286 | } |
1107 | 1287 | ||
@@ -1115,6 +1295,8 @@ dm9000_phy_write(struct net_device *dev, int phyaddr_unused, int reg, int value) | |||
1115 | unsigned long flags; | 1295 | unsigned long flags; |
1116 | unsigned long reg_save; | 1296 | unsigned long reg_save; |
1117 | 1297 | ||
1298 | mutex_lock(&db->addr_lock); | ||
1299 | |||
1118 | spin_lock_irqsave(&db->lock,flags); | 1300 | spin_lock_irqsave(&db->lock,flags); |
1119 | 1301 | ||
1120 | /* Save previous register address */ | 1302 | /* Save previous register address */ |
@@ -1124,25 +1306,38 @@ dm9000_phy_write(struct net_device *dev, int phyaddr_unused, int reg, int value) | |||
1124 | iow(db, DM9000_EPAR, DM9000_PHY | reg); | 1306 | iow(db, DM9000_EPAR, DM9000_PHY | reg); |
1125 | 1307 | ||
1126 | /* Fill the written data into REG_0D & REG_0E */ | 1308 | /* Fill the written data into REG_0D & REG_0E */ |
1127 | iow(db, DM9000_EPDRL, (value & 0xff)); | 1309 | iow(db, DM9000_EPDRL, value); |
1128 | iow(db, DM9000_EPDRH, ((value >> 8) & 0xff)); | 1310 | iow(db, DM9000_EPDRH, value >> 8); |
1129 | 1311 | ||
1130 | iow(db, DM9000_EPCR, 0xa); /* Issue phyxcer write command */ | 1312 | iow(db, DM9000_EPCR, 0xa); /* Issue phyxcer write command */ |
1131 | udelay(500); /* Wait write complete */ | 1313 | |
1314 | writeb(reg_save, db->io_addr); | ||
1315 | spin_unlock_irqrestore(&db->lock, flags); | ||
1316 | |||
1317 | dm9000_msleep(db, 1); /* Wait write complete */ | ||
1318 | |||
1319 | spin_lock_irqsave(&db->lock,flags); | ||
1320 | reg_save = readb(db->io_addr); | ||
1321 | |||
1132 | iow(db, DM9000_EPCR, 0x0); /* Clear phyxcer write command */ | 1322 | iow(db, DM9000_EPCR, 0x0); /* Clear phyxcer write command */ |
1133 | 1323 | ||
1134 | /* restore the previous address */ | 1324 | /* restore the previous address */ |
1135 | writeb(reg_save, db->io_addr); | 1325 | writeb(reg_save, db->io_addr); |
1136 | 1326 | ||
1137 | spin_unlock_irqrestore(&db->lock,flags); | 1327 | spin_unlock_irqrestore(&db->lock, flags); |
1328 | mutex_unlock(&db->addr_lock); | ||
1138 | } | 1329 | } |
1139 | 1330 | ||
1140 | static int | 1331 | static int |
1141 | dm9000_drv_suspend(struct platform_device *dev, pm_message_t state) | 1332 | dm9000_drv_suspend(struct platform_device *dev, pm_message_t state) |
1142 | { | 1333 | { |
1143 | struct net_device *ndev = platform_get_drvdata(dev); | 1334 | struct net_device *ndev = platform_get_drvdata(dev); |
1335 | board_info_t *db; | ||
1144 | 1336 | ||
1145 | if (ndev) { | 1337 | if (ndev) { |
1338 | db = (board_info_t *) ndev->priv; | ||
1339 | db->in_suspend = 1; | ||
1340 | |||
1146 | if (netif_running(ndev)) { | 1341 | if (netif_running(ndev)) { |
1147 | netif_device_detach(ndev); | 1342 | netif_device_detach(ndev); |
1148 | dm9000_shutdown(ndev); | 1343 | dm9000_shutdown(ndev); |
@@ -1165,6 +1360,8 @@ dm9000_drv_resume(struct platform_device *dev) | |||
1165 | 1360 | ||
1166 | netif_device_attach(ndev); | 1361 | netif_device_attach(ndev); |
1167 | } | 1362 | } |
1363 | |||
1364 | db->in_suspend = 0; | ||
1168 | } | 1365 | } |
1169 | return 0; | 1366 | return 0; |
1170 | } | 1367 | } |
@@ -1180,8 +1377,7 @@ dm9000_drv_remove(struct platform_device *pdev) | |||
1180 | dm9000_release_board(pdev, (board_info_t *) ndev->priv); | 1377 | dm9000_release_board(pdev, (board_info_t *) ndev->priv); |
1181 | free_netdev(ndev); /* free device structure */ | 1378 | free_netdev(ndev); /* free device structure */ |
1182 | 1379 | ||
1183 | PRINTK1("clean_module() exit\n"); | 1380 | dev_dbg(&pdev->dev, "released and freed device\n"); |
1184 | |||
1185 | return 0; | 1381 | return 0; |
1186 | } | 1382 | } |
1187 | 1383 | ||
@@ -1199,7 +1395,7 @@ static struct platform_driver dm9000_driver = { | |||
1199 | static int __init | 1395 | static int __init |
1200 | dm9000_init(void) | 1396 | dm9000_init(void) |
1201 | { | 1397 | { |
1202 | printk(KERN_INFO "%s Ethernet Driver\n", CARDNAME); | 1398 | printk(KERN_INFO "%s Ethernet Driver, V%s\n", CARDNAME, DRV_VERSION); |
1203 | 1399 | ||
1204 | return platform_driver_register(&dm9000_driver); /* search board and register */ | 1400 | return platform_driver_register(&dm9000_driver); /* search board and register */ |
1205 | } | 1401 | } |