1 /*******************************************************************************
3 * Linux ThunderLAN Driver
8 * (C) 1997-1998 Caldera, Inc.
10 * (C) 1999-2001 Torben Mathiasen
11 * (C) 2002 Samuel Chessman
13 * This software may be used and distributed according to the terms
14 * of the GNU General Public License, incorporated herein by reference.
16 ** Useful (if not required) reading:
18 * Texas Instruments, ThunderLAN Programmer's Guide,
19 * TI Literature Number SPWU013A
20 * available in PDF format from www.ti.com
21 * Level One, LXT901 and LXT970 Data Sheets
22 * available in PDF format from www.level1.com
23 * National Semiconductor, DP83840A Data Sheet
24 * available in PDF format from www.national.com
25 * Microchip Technology, 24C01A/02A/04A Data Sheet
26 * available in PDF format from www.microchip.com
30 * Tigran Aivazian <tigran@sco.com>: TLan_PciProbe() now uses
31 * new PCI BIOS interface.
32 * Alan Cox <alan@lxorguk.ukuu.org.uk>:
33 * Fixed the out of memory
36 * Torben Mathiasen <torben.mathiasen@compaq.com> New Maintainer!
38 * v1.1 Dec 20, 1999 - Removed linux version checking
39 * Patch from Tigran Aivazian.
40 * - v1.1 includes Alan's SMP updates.
41 * - We still have problems on SMP though,
42 * but I'm looking into that.
44 * v1.2 Jan 02, 2000 - Hopefully fixed the SMP deadlock.
45 * - Removed dependency of HZ being 100.
46 * - We now allow higher priority timers to
47 * overwrite timers like TLAN_TIMER_ACTIVITY
48 * Patch from John Cagle <john.cagle@compaq.com>.
49 * - Fixed a few compiler warnings.
51 * v1.3 Feb 04, 2000 - Fixed the remaining HZ issues.
52 * - Removed call to pci_present().
53 * - Removed SA_INTERRUPT flag from irq handler.
54 * - Added __init and __initdata to reduce resisdent
56 * - Driver now uses module_init/module_exit.
57 * - Rewrote init_module and tlan_probe to
58 * share a lot more code. We now use tlan_probe
59 * with builtin and module driver.
60 * - Driver ported to new net API.
61 * - tlan.txt has been reworked to reflect current
65 * v1.4 Feb 10, 2000 - Updated with more changes required after Dave's
66 * network cleanup in 2.3.43pre7 (Tigran & myself)
69 * v1.5 March 22, 2000 - Fixed another timer bug that would hang the
70 * driver if no cable/link were present.
72 * - TODO: Port completely to new PCI/DMA API
75 * v1.6 April 04, 2000 - Fixed driver support for kernel-parameters.
76 * Haven't tested it though, as the kernel support
77 * is currently broken (2.3.99p4p3).
78 * - Updated tlan.txt accordingly.
79 * - Adjusted minimum/maximum frame length.
80 * - There is now a TLAN website up at
81 * http://hp.sourceforge.net/
83 * v1.7 April 07, 2000 - Started to implement custom ioctls. Driver now
84 * reports PHY information when used with Donald
85 * Beckers userspace MII diagnostics utility.
87 * v1.8 April 23, 2000 - Fixed support for forced speed/duplex settings.
88 * - Added link information to Auto-Neg and forced
89 * modes. When NIC operates with auto-neg the driver
90 * will report Link speed & duplex modes as well as
91 * link partner abilities. When forced link is used,
92 * the driver will report status of the established
94 * Please read tlan.txt for additional information.
95 * - Removed call to check_region(), and used
96 * return value of request_region() instead.
98 * v1.8a May 28, 2000 - Minor updates.
100 * v1.9 July 25, 2000 - Fixed a few remaining Full-Duplex issues.
101 * - Updated with timer fixes from Andrew Morton.
102 * - Fixed module race in TLan_Open.
103 * - Added routine to monitor PHY status.
104 * - Added activity led support for Proliant devices.
106 * v1.10 Aug 30, 2000 - Added support for EISA based tlan controllers
107 * like the Compaq NetFlex3/E.
108 * - Rewrote tlan_probe to better handle multiple
109 * bus probes. Probing and device setup is now
110 * done through TLan_Probe and TLan_init_one. Actual
111 * hardware probe is done with kernel API and
113 * - Adjusted debug information for probing.
114 * - Fixed bug that would cause general debug
115 * information to be printed after driver removal.
116 * - Added transmit timeout handling.
117 * - Fixed OOM return values in tlan_probe.
118 * - Fixed possible mem leak in tlan_exit
119 * (now tlan_remove_one).
120 * - Fixed timer bug in TLan_phyMonitor.
121 * - This driver version is alpha quality, please
122 * send me any bug issues you may encounter.
124 * v1.11 Aug 31, 2000 - Do not try to register irq 0 if no irq line was
125 * set for EISA cards.
126 * - Added support for NetFlex3/E with nibble-rate
127 * 10Base-T PHY. This is untestet as I haven't got
128 * one of these cards.
129 * - Fixed timer being added twice.
130 * - Disabled PhyMonitoring by default as this is
131 * work in progress. Define MONITOR to enable it.
132 * - Now we don't display link info with PHYs that
133 * doesn't support it (level1).
134 * - Incresed tx_timeout beacuse of auto-neg.
135 * - Adjusted timers for forced speeds.
137 * v1.12 Oct 12, 2000 - Minor fixes (memleak, init, etc.)
139 * v1.13 Nov 28, 2000 - Stop flooding console with auto-neg issues
140 * when link can't be established.
141 * - Added the bbuf option as a kernel parameter.
142 * - Fixed ioaddr probe bug.
143 * - Fixed stupid deadlock with MII interrupts.
144 * - Added support for speed/duplex selection with
146 * - Added partly fix for TX Channel lockup with
147 * TLAN v1.0 silicon. This needs to be investigated
150 * v1.14 Dec 16, 2000 - Added support for servicing multiple frames per.
151 * interrupt. Thanks goes to
152 * Adam Keys <adam@ti.com>
153 * Denis Beaudoin <dbeaudoin@ti.com>
154 * for providing the patch.
155 * - Fixed auto-neg output when using multiple
157 * - Converted to use new taskq interface.
159 * v1.14a Jan 6, 2001 - Minor adjustments (spinlocks, etc.)
161 * Samuel Chessman <chessman@tux.org> New Maintainer!
163 * v1.15 Apr 4, 2002 - Correct operation when aui=1 to be
164 * 10T half duplex no loopback
165 * Thanks to Gunnar Eikman
167 * Sakari Ailus <sakari.ailus@iki.fi>:
169 * v1.15a Dec 15 2008 - Remove bbuf support, it doesn't work anyway.
170 * v1.16 Jan 6 2011 - Make checkpatch.pl happy.
172 ******************************************************************************/
174 #include <linux/module.h>
175 #include <linux/init.h>
176 #include <linux/ioport.h>
177 #include <linux/eisa.h>
178 #include <linux/pci.h>
179 #include <linux/dma-mapping.h>
180 #include <linux/netdevice.h>
181 #include <linux/etherdevice.h>
182 #include <linux/delay.h>
183 #include <linux/spinlock.h>
184 #include <linux/workqueue.h>
185 #include <linux/mii.h>
190 /* For removing EISA devices */
191 static struct net_device *tlan_eisa_devices;
193 static int tlan_devices_installed;
195 /* Set speed, duplex and aui settings */
196 static int aui[MAX_TLAN_BOARDS];
197 static int duplex[MAX_TLAN_BOARDS];
198 static int speed[MAX_TLAN_BOARDS];
199 static int boards_found;
200 module_param_array(aui, int, NULL, 0);
201 module_param_array(duplex, int, NULL, 0);
202 module_param_array(speed, int, NULL, 0);
203 MODULE_PARM_DESC(aui, "ThunderLAN use AUI port(s) (0-1)");
204 MODULE_PARM_DESC(duplex,
205 "ThunderLAN duplex setting(s) (0-default, 1-half, 2-full)");
206 MODULE_PARM_DESC(speed, "ThunderLAN port speen setting(s) (0,10,100)");
208 MODULE_AUTHOR("Maintainer: Samuel Chessman <chessman@tux.org>");
209 MODULE_DESCRIPTION("Driver for TI ThunderLAN based ethernet PCI adapters");
210 MODULE_LICENSE("GPL");
213 /* Define this to enable Link beat monitoring */
216 /* Turn on debugging. See Documentation/networking/tlan.txt for details */
218 module_param(debug, int, 0);
219 MODULE_PARM_DESC(debug, "ThunderLAN debug mask");
221 static const char tlan_signature[] = "TLAN";
222 static const char tlan_banner[] = "ThunderLAN driver v1.16\n";
223 static int tlan_have_pci;
224 static int tlan_have_eisa;
226 static const char * const media[] = {
227 "10BaseT-HD", "10BaseT-FD", "100baseTx-HD",
228 "100BaseTx-FD", "100BaseT4", NULL
231 static struct board {
232 const char *device_label;
236 { "Compaq Netelligent 10 T PCI UTP", TLAN_ADAPTER_ACTIVITY_LED, 0x83 },
237 { "Compaq Netelligent 10/100 TX PCI UTP",
238 TLAN_ADAPTER_ACTIVITY_LED, 0x83 },
239 { "Compaq Integrated NetFlex-3/P", TLAN_ADAPTER_NONE, 0x83 },
240 { "Compaq NetFlex-3/P",
241 TLAN_ADAPTER_UNMANAGED_PHY | TLAN_ADAPTER_BIT_RATE_PHY, 0x83 },
242 { "Compaq NetFlex-3/P", TLAN_ADAPTER_NONE, 0x83 },
243 { "Compaq Netelligent Integrated 10/100 TX UTP",
244 TLAN_ADAPTER_ACTIVITY_LED, 0x83 },
245 { "Compaq Netelligent Dual 10/100 TX PCI UTP",
246 TLAN_ADAPTER_NONE, 0x83 },
247 { "Compaq Netelligent 10/100 TX Embedded UTP",
248 TLAN_ADAPTER_NONE, 0x83 },
249 { "Olicom OC-2183/2185", TLAN_ADAPTER_USE_INTERN_10, 0x83 },
250 { "Olicom OC-2325", TLAN_ADAPTER_UNMANAGED_PHY, 0xf8 },
251 { "Olicom OC-2326", TLAN_ADAPTER_USE_INTERN_10, 0xf8 },
252 { "Compaq Netelligent 10/100 TX UTP", TLAN_ADAPTER_ACTIVITY_LED, 0x83 },
253 { "Compaq Netelligent 10 T/2 PCI UTP/coax", TLAN_ADAPTER_NONE, 0x83 },
254 { "Compaq NetFlex-3/E",
255 TLAN_ADAPTER_ACTIVITY_LED | /* EISA card */
256 TLAN_ADAPTER_UNMANAGED_PHY | TLAN_ADAPTER_BIT_RATE_PHY, 0x83 },
257 { "Compaq NetFlex-3/E",
258 TLAN_ADAPTER_ACTIVITY_LED, 0x83 }, /* EISA card */
261 static DEFINE_PCI_DEVICE_TABLE(tlan_pci_tbl) = {
262 { PCI_VENDOR_ID_COMPAQ, PCI_DEVICE_ID_COMPAQ_NETEL10,
263 PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0 },
264 { PCI_VENDOR_ID_COMPAQ, PCI_DEVICE_ID_COMPAQ_NETEL100,
265 PCI_ANY_ID, PCI_ANY_ID, 0, 0, 1 },
266 { PCI_VENDOR_ID_COMPAQ, PCI_DEVICE_ID_COMPAQ_NETFLEX3I,
267 PCI_ANY_ID, PCI_ANY_ID, 0, 0, 2 },
268 { PCI_VENDOR_ID_COMPAQ, PCI_DEVICE_ID_COMPAQ_THUNDER,
269 PCI_ANY_ID, PCI_ANY_ID, 0, 0, 3 },
270 { PCI_VENDOR_ID_COMPAQ, PCI_DEVICE_ID_COMPAQ_NETFLEX3B,
271 PCI_ANY_ID, PCI_ANY_ID, 0, 0, 4 },
272 { PCI_VENDOR_ID_COMPAQ, PCI_DEVICE_ID_COMPAQ_NETEL100PI,
273 PCI_ANY_ID, PCI_ANY_ID, 0, 0, 5 },
274 { PCI_VENDOR_ID_COMPAQ, PCI_DEVICE_ID_COMPAQ_NETEL100D,
275 PCI_ANY_ID, PCI_ANY_ID, 0, 0, 6 },
276 { PCI_VENDOR_ID_COMPAQ, PCI_DEVICE_ID_COMPAQ_NETEL100I,
277 PCI_ANY_ID, PCI_ANY_ID, 0, 0, 7 },
278 { PCI_VENDOR_ID_OLICOM, PCI_DEVICE_ID_OLICOM_OC2183,
279 PCI_ANY_ID, PCI_ANY_ID, 0, 0, 8 },
280 { PCI_VENDOR_ID_OLICOM, PCI_DEVICE_ID_OLICOM_OC2325,
281 PCI_ANY_ID, PCI_ANY_ID, 0, 0, 9 },
282 { PCI_VENDOR_ID_OLICOM, PCI_DEVICE_ID_OLICOM_OC2326,
283 PCI_ANY_ID, PCI_ANY_ID, 0, 0, 10 },
284 { PCI_VENDOR_ID_COMPAQ, PCI_DEVICE_ID_NETELLIGENT_10_100_WS_5100,
285 PCI_ANY_ID, PCI_ANY_ID, 0, 0, 11 },
286 { PCI_VENDOR_ID_COMPAQ, PCI_DEVICE_ID_NETELLIGENT_10_T2,
287 PCI_ANY_ID, PCI_ANY_ID, 0, 0, 12 },
290 MODULE_DEVICE_TABLE(pci, tlan_pci_tbl);
292 static void tlan_eisa_probe(void);
293 static void tlan_eisa_cleanup(void);
294 static int tlan_init(struct net_device *);
295 static int tlan_open(struct net_device *dev);
296 static netdev_tx_t tlan_start_tx(struct sk_buff *, struct net_device *);
297 static irqreturn_t tlan_handle_interrupt(int, void *);
298 static int tlan_close(struct net_device *);
299 static struct net_device_stats *tlan_get_stats(struct net_device *);
300 static void tlan_set_multicast_list(struct net_device *);
301 static int tlan_ioctl(struct net_device *dev, struct ifreq *rq, int cmd);
302 static int tlan_probe1(struct pci_dev *pdev, long ioaddr,
303 int irq, int rev, const struct pci_device_id *ent);
304 static void tlan_tx_timeout(struct net_device *dev);
305 static void tlan_tx_timeout_work(struct work_struct *work);
306 static int tlan_init_one(struct pci_dev *pdev,
307 const struct pci_device_id *ent);
309 static u32 tlan_handle_tx_eof(struct net_device *, u16);
310 static u32 tlan_handle_stat_overflow(struct net_device *, u16);
311 static u32 tlan_handle_rx_eof(struct net_device *, u16);
312 static u32 tlan_handle_dummy(struct net_device *, u16);
313 static u32 tlan_handle_tx_eoc(struct net_device *, u16);
314 static u32 tlan_handle_status_check(struct net_device *, u16);
315 static u32 tlan_handle_rx_eoc(struct net_device *, u16);
317 static void tlan_timer(unsigned long);
319 static void tlan_reset_lists(struct net_device *);
320 static void tlan_free_lists(struct net_device *);
321 static void tlan_print_dio(u16);
322 static void tlan_print_list(struct tlan_list *, char *, int);
323 static void tlan_read_and_clear_stats(struct net_device *, int);
324 static void tlan_reset_adapter(struct net_device *);
325 static void tlan_finish_reset(struct net_device *);
326 static void tlan_set_mac(struct net_device *, int areg, char *mac);
328 static void tlan_phy_print(struct net_device *);
329 static void tlan_phy_detect(struct net_device *);
330 static void tlan_phy_power_down(struct net_device *);
331 static void tlan_phy_power_up(struct net_device *);
332 static void tlan_phy_reset(struct net_device *);
333 static void tlan_phy_start_link(struct net_device *);
334 static void tlan_phy_finish_auto_neg(struct net_device *);
336 static void tlan_phy_monitor(struct net_device *);
340 static int tlan_phy_nop(struct net_device *);
341 static int tlan_phy_internal_check(struct net_device *);
342 static int tlan_phy_internal_service(struct net_device *);
343 static int tlan_phy_dp83840a_check(struct net_device *);
346 static bool tlan_mii_read_reg(struct net_device *, u16, u16, u16 *);
347 static void tlan_mii_send_data(u16, u32, unsigned);
348 static void tlan_mii_sync(u16);
349 static void tlan_mii_write_reg(struct net_device *, u16, u16, u16);
351 static void tlan_ee_send_start(u16);
352 static int tlan_ee_send_byte(u16, u8, int);
353 static void tlan_ee_receive_byte(u16, u8 *, int);
354 static int tlan_ee_read_byte(struct net_device *, u8, u8 *);
358 tlan_store_skb(struct tlan_list *tag, struct sk_buff *skb)
360 unsigned long addr = (unsigned long)skb;
361 tag->buffer[9].address = addr;
362 tag->buffer[8].address = upper_32_bits(addr);
365 static inline struct sk_buff *
366 tlan_get_skb(const struct tlan_list *tag)
370 addr = tag->buffer[9].address;
371 addr |= (tag->buffer[8].address << 16) << 16;
372 return (struct sk_buff *) addr;
376 (*tlan_int_vector[TLAN_INT_NUMBER_OF_INTS])(struct net_device *, u16) = {
379 tlan_handle_stat_overflow,
383 tlan_handle_status_check,
388 tlan_set_timer(struct net_device *dev, u32 ticks, u32 type)
390 struct tlan_priv *priv = netdev_priv(dev);
391 unsigned long flags = 0;
394 spin_lock_irqsave(&priv->lock, flags);
395 if (priv->timer.function != NULL &&
396 priv->timer_type != TLAN_TIMER_ACTIVITY) {
398 spin_unlock_irqrestore(&priv->lock, flags);
401 priv->timer.function = tlan_timer;
403 spin_unlock_irqrestore(&priv->lock, flags);
405 priv->timer.data = (unsigned long) dev;
406 priv->timer_set_at = jiffies;
407 priv->timer_type = type;
408 mod_timer(&priv->timer, jiffies + ticks);
413 /*****************************************************************************
414 ******************************************************************************
416 ThunderLAN driver primary functions
418 these functions are more or less common to all linux network drivers.
420 ******************************************************************************
421 *****************************************************************************/
427 /***************************************************************
435 * Goes through the TLanDevices list and frees the device
436 * structs and memory associated with each device (lists
437 * and buffers). It also ureserves the IO port regions
438 * associated with this device.
440 **************************************************************/
443 static void __devexit tlan_remove_one(struct pci_dev *pdev)
445 struct net_device *dev = pci_get_drvdata(pdev);
446 struct tlan_priv *priv = netdev_priv(dev);
448 unregister_netdev(dev);
450 if (priv->dma_storage) {
451 pci_free_consistent(priv->pci_dev,
452 priv->dma_size, priv->dma_storage,
453 priv->dma_storage_dma);
457 pci_release_regions(pdev);
462 pci_set_drvdata(pdev, NULL);
465 static struct pci_driver tlan_driver = {
467 .id_table = tlan_pci_tbl,
468 .probe = tlan_init_one,
469 .remove = __devexit_p(tlan_remove_one),
472 static int __init tlan_probe(void)
476 printk(KERN_INFO "%s", tlan_banner);
478 TLAN_DBG(TLAN_DEBUG_PROBE, "Starting PCI Probe....\n");
480 /* Use new style PCI probing. Now the kernel will
481 do most of this for us */
482 rc = pci_register_driver(&tlan_driver);
485 printk(KERN_ERR "TLAN: Could not register pci driver.\n");
486 goto err_out_pci_free;
489 TLAN_DBG(TLAN_DEBUG_PROBE, "Starting EISA Probe....\n");
492 printk(KERN_INFO "TLAN: %d device%s installed, PCI: %d EISA: %d\n",
493 tlan_devices_installed, tlan_devices_installed == 1 ? "" : "s",
494 tlan_have_pci, tlan_have_eisa);
496 if (tlan_devices_installed == 0) {
498 goto err_out_pci_unreg;
503 pci_unregister_driver(&tlan_driver);
509 static int __devinit tlan_init_one(struct pci_dev *pdev,
510 const struct pci_device_id *ent)
512 return tlan_probe1(pdev, -1, -1, 0, ent);
517 ***************************************************************
521 * 0 on success, error code on error
525 * The name is lower case to fit in with all the rest of
526 * the netcard_probe names. This function looks for
527 * another TLan based adapter, setting it up with the
528 * allocated device struct if one is found.
529 * tlan_probe has been ported to the new net API and
530 * now allocates its own device structure. This function
531 * is also used by modules.
533 **************************************************************/
535 static int __devinit tlan_probe1(struct pci_dev *pdev,
536 long ioaddr, int irq, int rev,
537 const struct pci_device_id *ent)
540 struct net_device *dev;
541 struct tlan_priv *priv;
543 int reg, rc = -ENODEV;
547 rc = pci_enable_device(pdev);
551 rc = pci_request_regions(pdev, tlan_signature);
553 printk(KERN_ERR "TLAN: Could not reserve IO regions\n");
557 #endif /* CONFIG_PCI */
559 dev = alloc_etherdev(sizeof(struct tlan_priv));
561 printk(KERN_ERR "TLAN: Could not allocate memory for device.\n");
563 goto err_out_regions;
565 SET_NETDEV_DEV(dev, &pdev->dev);
567 priv = netdev_priv(dev);
569 priv->pci_dev = pdev;
572 /* Is this a PCI device? */
576 priv->adapter = &board_info[ent->driver_data];
578 rc = pci_set_dma_mask(pdev, DMA_BIT_MASK(32));
581 "TLAN: No suitable PCI mapping available.\n");
582 goto err_out_free_dev;
585 for (reg = 0; reg <= 5; reg++) {
586 if (pci_resource_flags(pdev, reg) & IORESOURCE_IO) {
587 pci_io_base = pci_resource_start(pdev, reg);
588 TLAN_DBG(TLAN_DEBUG_GNRL,
589 "IO mapping is available at %x.\n",
595 printk(KERN_ERR "TLAN: No IO mappings available\n");
597 goto err_out_free_dev;
600 dev->base_addr = pci_io_base;
601 dev->irq = pdev->irq;
602 priv->adapter_rev = pdev->revision;
603 pci_set_master(pdev);
604 pci_set_drvdata(pdev, dev);
606 } else { /* EISA card */
607 /* This is a hack. We need to know which board structure
608 * is suited for this adapter */
609 device_id = inw(ioaddr + EISA_ID2);
611 if (device_id == 0x20F1) {
612 priv->adapter = &board_info[13]; /* NetFlex-3/E */
613 priv->adapter_rev = 23; /* TLAN 2.3 */
615 priv->adapter = &board_info[14];
616 priv->adapter_rev = 10; /* TLAN 1.0 */
618 dev->base_addr = ioaddr;
622 /* Kernel parameters */
623 if (dev->mem_start) {
624 priv->aui = dev->mem_start & 0x01;
625 priv->duplex = ((dev->mem_start & 0x06) == 0x06) ? 0
626 : (dev->mem_start & 0x06) >> 1;
627 priv->speed = ((dev->mem_start & 0x18) == 0x18) ? 0
628 : (dev->mem_start & 0x18) >> 3;
630 if (priv->speed == 0x1)
631 priv->speed = TLAN_SPEED_10;
632 else if (priv->speed == 0x2)
633 priv->speed = TLAN_SPEED_100;
635 debug = priv->debug = dev->mem_end;
637 priv->aui = aui[boards_found];
638 priv->speed = speed[boards_found];
639 priv->duplex = duplex[boards_found];
643 /* This will be used when we get an adapter error from
644 * within our irq handler */
645 INIT_WORK(&priv->tlan_tqueue, tlan_tx_timeout_work);
647 spin_lock_init(&priv->lock);
651 printk(KERN_ERR "TLAN: Could not set up device.\n");
652 goto err_out_free_dev;
655 rc = register_netdev(dev);
657 printk(KERN_ERR "TLAN: Could not register device.\n");
662 tlan_devices_installed++;
665 /* pdev is NULL if this is an EISA device */
669 priv->next_device = tlan_eisa_devices;
670 tlan_eisa_devices = dev;
674 printk(KERN_INFO "TLAN: %s irq=%2d, io=%04x, %s, Rev. %d\n",
677 (int) dev->base_addr,
678 priv->adapter->device_label,
683 pci_free_consistent(priv->pci_dev, priv->dma_size, priv->dma_storage,
684 priv->dma_storage_dma);
690 pci_release_regions(pdev);
694 pci_disable_device(pdev);
699 static void tlan_eisa_cleanup(void)
701 struct net_device *dev;
702 struct tlan_priv *priv;
704 while (tlan_have_eisa) {
705 dev = tlan_eisa_devices;
706 priv = netdev_priv(dev);
707 if (priv->dma_storage) {
708 pci_free_consistent(priv->pci_dev, priv->dma_size,
710 priv->dma_storage_dma);
712 release_region(dev->base_addr, 0x10);
713 unregister_netdev(dev);
714 tlan_eisa_devices = priv->next_device;
721 static void __exit tlan_exit(void)
723 pci_unregister_driver(&tlan_driver);
731 /* Module loading/unloading */
732 module_init(tlan_probe);
733 module_exit(tlan_exit);
737 /**************************************************************
740 * Returns: 0 on success, 1 otherwise
745 * This functions probes for EISA devices and calls
746 * TLan_probe1 when one is found.
748 *************************************************************/
750 static void __init tlan_eisa_probe(void)
758 TLAN_DBG(TLAN_DEBUG_PROBE, "No EISA bus present\n");
762 /* Loop through all slots of the EISA bus */
763 for (ioaddr = 0x1000; ioaddr < 0x9000; ioaddr += 0x1000) {
765 TLAN_DBG(TLAN_DEBUG_PROBE, "EISA_ID 0x%4x: 0x%4x\n",
766 (int) ioaddr + 0xc80, inw(ioaddr + EISA_ID));
767 TLAN_DBG(TLAN_DEBUG_PROBE, "EISA_ID 0x%4x: 0x%4x\n",
768 (int) ioaddr + 0xc82, inw(ioaddr + EISA_ID2));
771 TLAN_DBG(TLAN_DEBUG_PROBE,
772 "Probing for EISA adapter at IO: 0x%4x : ",
774 if (request_region(ioaddr, 0x10, tlan_signature) == NULL)
777 if (inw(ioaddr + EISA_ID) != 0x110E) {
778 release_region(ioaddr, 0x10);
782 device_id = inw(ioaddr + EISA_ID2);
783 if (device_id != 0x20F1 && device_id != 0x40F1) {
784 release_region(ioaddr, 0x10);
788 /* check if adapter is enabled */
789 if (inb(ioaddr + EISA_CR) != 0x1) {
790 release_region(ioaddr, 0x10);
795 printk(KERN_INFO "Found one\n");
798 /* Get irq from board */
799 switch (inb(ioaddr + 0xcc0)) {
817 /* Setup the newly found eisa adapter */
818 rc = tlan_probe1(NULL, ioaddr, irq,
824 printk(KERN_INFO "None found\n");
829 printk(KERN_INFO "Card found but it is not enabled, skipping\n");
836 #ifdef CONFIG_NET_POLL_CONTROLLER
837 static void tlan_poll(struct net_device *dev)
839 disable_irq(dev->irq);
840 tlan_handle_interrupt(dev->irq, dev);
841 enable_irq(dev->irq);
845 static const struct net_device_ops tlan_netdev_ops = {
846 .ndo_open = tlan_open,
847 .ndo_stop = tlan_close,
848 .ndo_start_xmit = tlan_start_tx,
849 .ndo_tx_timeout = tlan_tx_timeout,
850 .ndo_get_stats = tlan_get_stats,
851 .ndo_set_multicast_list = tlan_set_multicast_list,
852 .ndo_do_ioctl = tlan_ioctl,
853 .ndo_change_mtu = eth_change_mtu,
854 .ndo_set_mac_address = eth_mac_addr,
855 .ndo_validate_addr = eth_validate_addr,
856 #ifdef CONFIG_NET_POLL_CONTROLLER
857 .ndo_poll_controller = tlan_poll,
863 /***************************************************************
867 * 0 on success, error code otherwise.
869 * dev The structure of the device to be
872 * This function completes the initialization of the
873 * device structure and driver. It reserves the IO
874 * addresses, allocates memory for the lists and bounce
875 * buffers, retrieves the MAC address from the eeprom
876 * and assignes the device's methods.
878 **************************************************************/
880 static int tlan_init(struct net_device *dev)
885 struct tlan_priv *priv;
887 priv = netdev_priv(dev);
889 dma_size = (TLAN_NUM_RX_LISTS + TLAN_NUM_TX_LISTS)
890 * (sizeof(struct tlan_list));
891 priv->dma_storage = pci_alloc_consistent(priv->pci_dev,
893 &priv->dma_storage_dma);
894 priv->dma_size = dma_size;
896 if (priv->dma_storage == NULL) {
898 "TLAN: Could not allocate lists and buffers for %s.\n",
902 memset(priv->dma_storage, 0, dma_size);
903 priv->rx_list = (struct tlan_list *)
904 ALIGN((unsigned long)priv->dma_storage, 8);
905 priv->rx_list_dma = ALIGN(priv->dma_storage_dma, 8);
906 priv->tx_list = priv->rx_list + TLAN_NUM_RX_LISTS;
908 priv->rx_list_dma + sizeof(struct tlan_list)*TLAN_NUM_RX_LISTS;
911 for (i = 0; i < 6 ; i++)
912 err |= tlan_ee_read_byte(dev,
913 (u8) priv->adapter->addr_ofs + i,
914 (u8 *) &dev->dev_addr[i]);
916 printk(KERN_ERR "TLAN: %s: Error reading MAC from eeprom: %d\n",
922 netif_carrier_off(dev);
925 dev->netdev_ops = &tlan_netdev_ops;
926 dev->watchdog_timeo = TX_TIMEOUT;
935 /***************************************************************
939 * 0 on success, error code otherwise.
941 * dev Structure of device to be opened.
943 * This routine puts the driver and TLAN adapter in a
944 * state where it is ready to send and receive packets.
945 * It allocates the IRQ, resets and brings the adapter
946 * out of reset, and allows interrupts. It also delays
947 * the startup for autonegotiation or sends a Rx GO
948 * command to the adapter, as appropriate.
950 **************************************************************/
952 static int tlan_open(struct net_device *dev)
954 struct tlan_priv *priv = netdev_priv(dev);
957 priv->tlan_rev = tlan_dio_read8(dev->base_addr, TLAN_DEF_REVISION);
958 err = request_irq(dev->irq, tlan_handle_interrupt, IRQF_SHARED,
962 pr_err("TLAN: Cannot open %s because IRQ %d is already in use.\n",
963 dev->name, dev->irq);
967 init_timer(&priv->timer);
968 netif_start_queue(dev);
970 /* NOTE: It might not be necessary to read the stats before a
971 reset if you don't care what the values are.
973 tlan_reset_lists(dev);
974 tlan_read_and_clear_stats(dev, TLAN_IGNORE);
975 tlan_reset_adapter(dev);
977 TLAN_DBG(TLAN_DEBUG_GNRL, "%s: Opened. TLAN Chip Rev: %x\n",
978 dev->name, priv->tlan_rev);
986 /**************************************************************
990 * 0 on success, error code otherwise
992 * dev structure of device to receive ioctl.
994 * rq ifreq structure to hold userspace data.
999 *************************************************************/
1001 static int tlan_ioctl(struct net_device *dev, struct ifreq *rq, int cmd)
1003 struct tlan_priv *priv = netdev_priv(dev);
1004 struct mii_ioctl_data *data = if_mii(rq);
1005 u32 phy = priv->phy[priv->phy_num];
1007 if (!priv->phy_online)
1011 case SIOCGMIIPHY: /* get address of MII PHY in use. */
1015 case SIOCGMIIREG: /* read MII PHY register. */
1016 tlan_mii_read_reg(dev, data->phy_id & 0x1f,
1017 data->reg_num & 0x1f, &data->val_out);
1021 case SIOCSMIIREG: /* write MII PHY register. */
1022 tlan_mii_write_reg(dev, data->phy_id & 0x1f,
1023 data->reg_num & 0x1f, data->val_in);
1031 /***************************************************************
1037 * dev structure of device which timed out
1040 **************************************************************/
1042 static void tlan_tx_timeout(struct net_device *dev)
1045 TLAN_DBG(TLAN_DEBUG_GNRL, "%s: Transmit timed out.\n", dev->name);
1047 /* Ok so we timed out, lets see what we can do about it...*/
1048 tlan_free_lists(dev);
1049 tlan_reset_lists(dev);
1050 tlan_read_and_clear_stats(dev, TLAN_IGNORE);
1051 tlan_reset_adapter(dev);
1052 dev->trans_start = jiffies; /* prevent tx timeout */
1053 netif_wake_queue(dev);
1058 /***************************************************************
1059 * tlan_tx_timeout_work
1064 * work work item of device which timed out
1066 **************************************************************/
1068 static void tlan_tx_timeout_work(struct work_struct *work)
1070 struct tlan_priv *priv =
1071 container_of(work, struct tlan_priv, tlan_tqueue);
1073 tlan_tx_timeout(priv->dev);
1078 /***************************************************************
1082 * 0 on success, non-zero on failure.
1084 * skb A pointer to the sk_buff containing the
1086 * dev The device to send the data on.
1088 * This function adds a frame to the Tx list to be sent
1089 * ASAP. First it verifies that the adapter is ready and
1090 * there is room in the queue. Then it sets up the next
1091 * available list, copies the frame to the corresponding
1092 * buffer. If the adapter Tx channel is idle, it gives
1093 * the adapter a Tx Go command on the list, otherwise it
1094 * sets the forward address of the previous list to point
1095 * to this one. Then it frees the sk_buff.
1097 **************************************************************/
1099 static netdev_tx_t tlan_start_tx(struct sk_buff *skb, struct net_device *dev)
1101 struct tlan_priv *priv = netdev_priv(dev);
1102 dma_addr_t tail_list_phys;
1103 struct tlan_list *tail_list;
1104 unsigned long flags;
1107 if (!priv->phy_online) {
1108 TLAN_DBG(TLAN_DEBUG_TX, "TRANSMIT: %s PHY is not ready\n",
1110 dev_kfree_skb_any(skb);
1111 return NETDEV_TX_OK;
1114 if (skb_padto(skb, TLAN_MIN_FRAME_SIZE))
1115 return NETDEV_TX_OK;
1116 txlen = max(skb->len, (unsigned int)TLAN_MIN_FRAME_SIZE);
1118 tail_list = priv->tx_list + priv->tx_tail;
1120 priv->tx_list_dma + sizeof(struct tlan_list)*priv->tx_tail;
1122 if (tail_list->c_stat != TLAN_CSTAT_UNUSED) {
1123 TLAN_DBG(TLAN_DEBUG_TX,
1124 "TRANSMIT: %s is busy (Head=%d Tail=%d)\n",
1125 dev->name, priv->tx_head, priv->tx_tail);
1126 netif_stop_queue(dev);
1127 priv->tx_busy_count++;
1128 return NETDEV_TX_BUSY;
1131 tail_list->forward = 0;
1133 tail_list->buffer[0].address = pci_map_single(priv->pci_dev,
1136 tlan_store_skb(tail_list, skb);
1138 tail_list->frame_size = (u16) txlen;
1139 tail_list->buffer[0].count = TLAN_LAST_BUFFER | (u32) txlen;
1140 tail_list->buffer[1].count = 0;
1141 tail_list->buffer[1].address = 0;
1143 spin_lock_irqsave(&priv->lock, flags);
1144 tail_list->c_stat = TLAN_CSTAT_READY;
1145 if (!priv->tx_in_progress) {
1146 priv->tx_in_progress = 1;
1147 TLAN_DBG(TLAN_DEBUG_TX,
1148 "TRANSMIT: Starting TX on buffer %d\n",
1150 outl(tail_list_phys, dev->base_addr + TLAN_CH_PARM);
1151 outl(TLAN_HC_GO, dev->base_addr + TLAN_HOST_CMD);
1153 TLAN_DBG(TLAN_DEBUG_TX,
1154 "TRANSMIT: Adding buffer %d to TX channel\n",
1156 if (priv->tx_tail == 0) {
1157 (priv->tx_list + (TLAN_NUM_TX_LISTS - 1))->forward
1160 (priv->tx_list + (priv->tx_tail - 1))->forward
1164 spin_unlock_irqrestore(&priv->lock, flags);
1166 CIRC_INC(priv->tx_tail, TLAN_NUM_TX_LISTS);
1168 return NETDEV_TX_OK;
1175 /***************************************************************
1176 * tlan_handle_interrupt
1181 * irq The line on which the interrupt
1183 * dev_id A pointer to the device assigned to
1186 * This function handles an interrupt generated by its
1187 * assigned TLAN adapter. The function deactivates
1188 * interrupts on its adapter, records the type of
1189 * interrupt, executes the appropriate subhandler, and
1190 * acknowdges the interrupt to the adapter (thus
1191 * re-enabling adapter interrupts.
1193 **************************************************************/
1195 static irqreturn_t tlan_handle_interrupt(int irq, void *dev_id)
1197 struct net_device *dev = dev_id;
1198 struct tlan_priv *priv = netdev_priv(dev);
1202 spin_lock(&priv->lock);
1204 host_int = inw(dev->base_addr + TLAN_HOST_INT);
1205 type = (host_int & TLAN_HI_IT_MASK) >> 2;
1210 outw(host_int, dev->base_addr + TLAN_HOST_INT);
1211 ack = tlan_int_vector[type](dev, host_int);
1214 host_cmd = TLAN_HC_ACK | ack | (type << 18);
1215 outl(host_cmd, dev->base_addr + TLAN_HOST_CMD);
1219 spin_unlock(&priv->lock);
1221 return IRQ_RETVAL(type);
1227 /***************************************************************
1233 * dev The device structure of the device to
1236 * This function shuts down the adapter. It records any
1237 * stats, puts the adapter into reset state, deactivates
1238 * its time as needed, and frees the irq it is using.
1240 **************************************************************/
1242 static int tlan_close(struct net_device *dev)
1244 struct tlan_priv *priv = netdev_priv(dev);
1246 netif_stop_queue(dev);
1247 priv->neg_be_verbose = 0;
1249 tlan_read_and_clear_stats(dev, TLAN_RECORD);
1250 outl(TLAN_HC_AD_RST, dev->base_addr + TLAN_HOST_CMD);
1251 if (priv->timer.function != NULL) {
1252 del_timer_sync(&priv->timer);
1253 priv->timer.function = NULL;
1256 free_irq(dev->irq, dev);
1257 tlan_free_lists(dev);
1258 TLAN_DBG(TLAN_DEBUG_GNRL, "Device %s closed.\n", dev->name);
1267 /***************************************************************
1271 * A pointer to the device's statistics structure.
1273 * dev The device structure to return the
1276 * This function updates the devices statistics by reading
1277 * the TLAN chip's onboard registers. Then it returns the
1278 * address of the statistics structure.
1280 **************************************************************/
1282 static struct net_device_stats *tlan_get_stats(struct net_device *dev)
1284 struct tlan_priv *priv = netdev_priv(dev);
1287 /* Should only read stats if open ? */
1288 tlan_read_and_clear_stats(dev, TLAN_RECORD);
1290 TLAN_DBG(TLAN_DEBUG_RX, "RECEIVE: %s EOC count = %d\n", dev->name,
1291 priv->rx_eoc_count);
1292 TLAN_DBG(TLAN_DEBUG_TX, "TRANSMIT: %s Busy count = %d\n", dev->name,
1293 priv->tx_busy_count);
1294 if (debug & TLAN_DEBUG_GNRL) {
1295 tlan_print_dio(dev->base_addr);
1296 tlan_phy_print(dev);
1298 if (debug & TLAN_DEBUG_LIST) {
1299 for (i = 0; i < TLAN_NUM_RX_LISTS; i++)
1300 tlan_print_list(priv->rx_list + i, "RX", i);
1301 for (i = 0; i < TLAN_NUM_TX_LISTS; i++)
1302 tlan_print_list(priv->tx_list + i, "TX", i);
1312 /***************************************************************
1313 * tlan_set_multicast_list
1318 * dev The device structure to set the
1319 * multicast list for.
1321 * This function sets the TLAN adaptor to various receive
1322 * modes. If the IFF_PROMISC flag is set, promiscuous
1323 * mode is acitviated. Otherwise, promiscuous mode is
1324 * turned off. If the IFF_ALLMULTI flag is set, then
1325 * the hash table is set to receive all group addresses.
1326 * Otherwise, the first three multicast addresses are
1327 * stored in AREG_1-3, and the rest are selected via the
1328 * hash table, as necessary.
1330 **************************************************************/
1332 static void tlan_set_multicast_list(struct net_device *dev)
1334 struct netdev_hw_addr *ha;
1341 if (dev->flags & IFF_PROMISC) {
1342 tmp = tlan_dio_read8(dev->base_addr, TLAN_NET_CMD);
1343 tlan_dio_write8(dev->base_addr,
1344 TLAN_NET_CMD, tmp | TLAN_NET_CMD_CAF);
1346 tmp = tlan_dio_read8(dev->base_addr, TLAN_NET_CMD);
1347 tlan_dio_write8(dev->base_addr,
1348 TLAN_NET_CMD, tmp & ~TLAN_NET_CMD_CAF);
1349 if (dev->flags & IFF_ALLMULTI) {
1350 for (i = 0; i < 3; i++)
1351 tlan_set_mac(dev, i + 1, NULL);
1352 tlan_dio_write32(dev->base_addr, TLAN_HASH_1,
1354 tlan_dio_write32(dev->base_addr, TLAN_HASH_2,
1358 netdev_for_each_mc_addr(ha, dev) {
1360 tlan_set_mac(dev, i + 1,
1361 (char *) &ha->addr);
1364 tlan_hash_func((u8 *)&ha->addr);
1366 hash1 |= (1 << offset);
1368 hash2 |= (1 << (offset - 32));
1373 tlan_set_mac(dev, i + 1, NULL);
1374 tlan_dio_write32(dev->base_addr, TLAN_HASH_1, hash1);
1375 tlan_dio_write32(dev->base_addr, TLAN_HASH_2, hash2);
1383 /*****************************************************************************
1384 ******************************************************************************
1386 ThunderLAN driver interrupt vectors and table
1388 please see chap. 4, "Interrupt Handling" of the "ThunderLAN
1389 Programmer's Guide" for more informations on handling interrupts
1390 generated by TLAN based adapters.
1392 ******************************************************************************
1393 *****************************************************************************/
1398 /***************************************************************
1399 * tlan_handle_tx_eof
1404 * dev Device assigned the IRQ that was
1406 * host_int The contents of the HOST_INT
1409 * This function handles Tx EOF interrupts which are raised
1410 * by the adapter when it has completed sending the
1411 * contents of a buffer. If detemines which list/buffer
1412 * was completed and resets it. If the buffer was the last
1413 * in the channel (EOC), then the function checks to see if
1414 * another buffer is ready to send, and if so, sends a Tx
1415 * Go command. Finally, the driver activates/continues the
1418 **************************************************************/
1420 static u32 tlan_handle_tx_eof(struct net_device *dev, u16 host_int)
1422 struct tlan_priv *priv = netdev_priv(dev);
1424 struct tlan_list *head_list;
1425 dma_addr_t head_list_phys;
1429 TLAN_DBG(TLAN_DEBUG_TX,
1430 "TRANSMIT: Handling TX EOF (Head=%d Tail=%d)\n",
1431 priv->tx_head, priv->tx_tail);
1432 head_list = priv->tx_list + priv->tx_head;
1434 while (((tmp_c_stat = head_list->c_stat) & TLAN_CSTAT_FRM_CMP)
1436 struct sk_buff *skb = tlan_get_skb(head_list);
1439 pci_unmap_single(priv->pci_dev, head_list->buffer[0].address,
1441 (unsigned int)TLAN_MIN_FRAME_SIZE),
1443 dev_kfree_skb_any(skb);
1444 head_list->buffer[8].address = 0;
1445 head_list->buffer[9].address = 0;
1447 if (tmp_c_stat & TLAN_CSTAT_EOC)
1450 dev->stats.tx_bytes += head_list->frame_size;
1452 head_list->c_stat = TLAN_CSTAT_UNUSED;
1453 netif_start_queue(dev);
1454 CIRC_INC(priv->tx_head, TLAN_NUM_TX_LISTS);
1455 head_list = priv->tx_list + priv->tx_head;
1460 "TLAN: Received interrupt for uncompleted TX frame.\n");
1463 TLAN_DBG(TLAN_DEBUG_TX,
1464 "TRANSMIT: handling TX EOC (Head=%d Tail=%d)\n",
1465 priv->tx_head, priv->tx_tail);
1466 head_list = priv->tx_list + priv->tx_head;
1467 head_list_phys = priv->tx_list_dma
1468 + sizeof(struct tlan_list)*priv->tx_head;
1469 if (head_list->c_stat & TLAN_CSTAT_READY) {
1470 outl(head_list_phys, dev->base_addr + TLAN_CH_PARM);
1473 priv->tx_in_progress = 0;
1477 if (priv->adapter->flags & TLAN_ADAPTER_ACTIVITY_LED) {
1478 tlan_dio_write8(dev->base_addr,
1479 TLAN_LED_REG, TLAN_LED_LINK | TLAN_LED_ACT);
1480 if (priv->timer.function == NULL) {
1481 priv->timer.function = tlan_timer;
1482 priv->timer.data = (unsigned long) dev;
1483 priv->timer.expires = jiffies + TLAN_TIMER_ACT_DELAY;
1484 priv->timer_set_at = jiffies;
1485 priv->timer_type = TLAN_TIMER_ACTIVITY;
1486 add_timer(&priv->timer);
1487 } else if (priv->timer_type == TLAN_TIMER_ACTIVITY) {
1488 priv->timer_set_at = jiffies;
1499 /***************************************************************
1500 * TLan_HandleStatOverflow
1505 * dev Device assigned the IRQ that was
1507 * host_int The contents of the HOST_INT
1510 * This function handles the Statistics Overflow interrupt
1511 * which means that one or more of the TLAN statistics
1512 * registers has reached 1/2 capacity and needs to be read.
1514 **************************************************************/
1516 static u32 tlan_handle_stat_overflow(struct net_device *dev, u16 host_int)
1518 tlan_read_and_clear_stats(dev, TLAN_RECORD);
1527 /***************************************************************
1533 * dev Device assigned the IRQ that was
1535 * host_int The contents of the HOST_INT
1538 * This function handles the Rx EOF interrupt which
1539 * indicates a frame has been received by the adapter from
1540 * the net and the frame has been transferred to memory.
1541 * The function determines the bounce buffer the frame has
1542 * been loaded into, creates a new sk_buff big enough to
1543 * hold the frame, and sends it to protocol stack. It
1544 * then resets the used buffer and appends it to the end
1545 * of the list. If the frame was the last in the Rx
1546 * channel (EOC), the function restarts the receive channel
1547 * by sending an Rx Go command to the adapter. Then it
1548 * activates/continues the activity LED.
1550 **************************************************************/
1552 static u32 tlan_handle_rx_eof(struct net_device *dev, u16 host_int)
1554 struct tlan_priv *priv = netdev_priv(dev);
1557 struct tlan_list *head_list;
1558 struct sk_buff *skb;
1559 struct tlan_list *tail_list;
1561 dma_addr_t head_list_phys;
1563 TLAN_DBG(TLAN_DEBUG_RX, "RECEIVE: handling RX EOF (Head=%d Tail=%d)\n",
1564 priv->rx_head, priv->rx_tail);
1565 head_list = priv->rx_list + priv->rx_head;
1567 priv->rx_list_dma + sizeof(struct tlan_list)*priv->rx_head;
1569 while (((tmp_c_stat = head_list->c_stat) & TLAN_CSTAT_FRM_CMP)
1571 dma_addr_t frame_dma = head_list->buffer[0].address;
1572 u32 frame_size = head_list->frame_size;
1573 struct sk_buff *new_skb;
1576 if (tmp_c_stat & TLAN_CSTAT_EOC)
1579 new_skb = netdev_alloc_skb_ip_align(dev,
1580 TLAN_MAX_FRAME_SIZE + 5);
1582 goto drop_and_reuse;
1584 skb = tlan_get_skb(head_list);
1585 pci_unmap_single(priv->pci_dev, frame_dma,
1586 TLAN_MAX_FRAME_SIZE, PCI_DMA_FROMDEVICE);
1587 skb_put(skb, frame_size);
1589 dev->stats.rx_bytes += frame_size;
1591 skb->protocol = eth_type_trans(skb, dev);
1594 head_list->buffer[0].address =
1595 pci_map_single(priv->pci_dev, new_skb->data,
1596 TLAN_MAX_FRAME_SIZE, PCI_DMA_FROMDEVICE);
1598 tlan_store_skb(head_list, new_skb);
1600 head_list->forward = 0;
1601 head_list->c_stat = 0;
1602 tail_list = priv->rx_list + priv->rx_tail;
1603 tail_list->forward = head_list_phys;
1605 CIRC_INC(priv->rx_head, TLAN_NUM_RX_LISTS);
1606 CIRC_INC(priv->rx_tail, TLAN_NUM_RX_LISTS);
1607 head_list = priv->rx_list + priv->rx_head;
1608 head_list_phys = priv->rx_list_dma
1609 + sizeof(struct tlan_list)*priv->rx_head;
1614 "TLAN: Received interrupt for uncompleted RX frame.\n");
1618 TLAN_DBG(TLAN_DEBUG_RX,
1619 "RECEIVE: handling RX EOC (Head=%d Tail=%d)\n",
1620 priv->rx_head, priv->rx_tail);
1621 head_list = priv->rx_list + priv->rx_head;
1622 head_list_phys = priv->rx_list_dma
1623 + sizeof(struct tlan_list)*priv->rx_head;
1624 outl(head_list_phys, dev->base_addr + TLAN_CH_PARM);
1625 ack |= TLAN_HC_GO | TLAN_HC_RT;
1626 priv->rx_eoc_count++;
1629 if (priv->adapter->flags & TLAN_ADAPTER_ACTIVITY_LED) {
1630 tlan_dio_write8(dev->base_addr,
1631 TLAN_LED_REG, TLAN_LED_LINK | TLAN_LED_ACT);
1632 if (priv->timer.function == NULL) {
1633 priv->timer.function = tlan_timer;
1634 priv->timer.data = (unsigned long) dev;
1635 priv->timer.expires = jiffies + TLAN_TIMER_ACT_DELAY;
1636 priv->timer_set_at = jiffies;
1637 priv->timer_type = TLAN_TIMER_ACTIVITY;
1638 add_timer(&priv->timer);
1639 } else if (priv->timer_type == TLAN_TIMER_ACTIVITY) {
1640 priv->timer_set_at = jiffies;
1651 /***************************************************************
1657 * dev Device assigned the IRQ that was
1659 * host_int The contents of the HOST_INT
1662 * This function handles the Dummy interrupt, which is
1663 * raised whenever a test interrupt is generated by setting
1664 * the Req_Int bit of HOST_CMD to 1.
1666 **************************************************************/
1668 static u32 tlan_handle_dummy(struct net_device *dev, u16 host_int)
1670 pr_info("TLAN: Test interrupt on %s.\n", dev->name);
1678 /***************************************************************
1679 * tlan_handle_tx_eoc
1684 * dev Device assigned the IRQ that was
1686 * host_int The contents of the HOST_INT
1689 * This driver is structured to determine EOC occurrences by
1690 * reading the CSTAT member of the list structure. Tx EOC
1691 * interrupts are disabled via the DIO INTDIS register.
1692 * However, TLAN chips before revision 3.0 didn't have this
1693 * functionality, so process EOC events if this is the
1696 **************************************************************/
1698 static u32 tlan_handle_tx_eoc(struct net_device *dev, u16 host_int)
1700 struct tlan_priv *priv = netdev_priv(dev);
1701 struct tlan_list *head_list;
1702 dma_addr_t head_list_phys;
1706 if (priv->tlan_rev < 0x30) {
1707 TLAN_DBG(TLAN_DEBUG_TX,
1708 "TRANSMIT: handling TX EOC (Head=%d Tail=%d) -- IRQ\n",
1709 priv->tx_head, priv->tx_tail);
1710 head_list = priv->tx_list + priv->tx_head;
1711 head_list_phys = priv->tx_list_dma
1712 + sizeof(struct tlan_list)*priv->tx_head;
1713 if (head_list->c_stat & TLAN_CSTAT_READY) {
1714 netif_stop_queue(dev);
1715 outl(head_list_phys, dev->base_addr + TLAN_CH_PARM);
1718 priv->tx_in_progress = 0;
1729 /***************************************************************
1730 * tlan_handle_status_check
1733 * 0 if Adapter check, 1 if Network Status check.
1735 * dev Device assigned the IRQ that was
1737 * host_int The contents of the HOST_INT
1740 * This function handles Adapter Check/Network Status
1741 * interrupts generated by the adapter. It checks the
1742 * vector in the HOST_INT register to determine if it is
1743 * an Adapter Check interrupt. If so, it resets the
1744 * adapter. Otherwise it clears the status registers
1745 * and services the PHY.
1747 **************************************************************/
1749 static u32 tlan_handle_status_check(struct net_device *dev, u16 host_int)
1751 struct tlan_priv *priv = netdev_priv(dev);
1760 if (host_int & TLAN_HI_IV_MASK) {
1761 netif_stop_queue(dev);
1762 error = inl(dev->base_addr + TLAN_CH_PARM);
1763 pr_info("TLAN: %s: Adaptor Error = 0x%x\n", dev->name, error);
1764 tlan_read_and_clear_stats(dev, TLAN_RECORD);
1765 outl(TLAN_HC_AD_RST, dev->base_addr + TLAN_HOST_CMD);
1767 schedule_work(&priv->tlan_tqueue);
1769 netif_wake_queue(dev);
1772 TLAN_DBG(TLAN_DEBUG_GNRL, "%s: Status Check\n", dev->name);
1773 phy = priv->phy[priv->phy_num];
1775 net_sts = tlan_dio_read8(dev->base_addr, TLAN_NET_STS);
1777 tlan_dio_write8(dev->base_addr, TLAN_NET_STS, net_sts);
1778 TLAN_DBG(TLAN_DEBUG_GNRL, "%s: Net_Sts = %x\n",
1779 dev->name, (unsigned) net_sts);
1781 if ((net_sts & TLAN_NET_STS_MIRQ) && (priv->phy_num == 0)) {
1782 tlan_mii_read_reg(dev, phy, TLAN_TLPHY_STS, &tlphy_sts);
1783 tlan_mii_read_reg(dev, phy, TLAN_TLPHY_CTL, &tlphy_ctl);
1784 if (!(tlphy_sts & TLAN_TS_POLOK) &&
1785 !(tlphy_ctl & TLAN_TC_SWAPOL)) {
1786 tlphy_ctl |= TLAN_TC_SWAPOL;
1787 tlan_mii_write_reg(dev, phy, TLAN_TLPHY_CTL,
1789 } else if ((tlphy_sts & TLAN_TS_POLOK) &&
1790 (tlphy_ctl & TLAN_TC_SWAPOL)) {
1791 tlphy_ctl &= ~TLAN_TC_SWAPOL;
1792 tlan_mii_write_reg(dev, phy, TLAN_TLPHY_CTL,
1797 tlan_phy_print(dev);
1808 /***************************************************************
1809 * tlan_handle_rx_eoc
1814 * dev Device assigned the IRQ that was
1816 * host_int The contents of the HOST_INT
1819 * This driver is structured to determine EOC occurrences by
1820 * reading the CSTAT member of the list structure. Rx EOC
1821 * interrupts are disabled via the DIO INTDIS register.
1822 * However, TLAN chips before revision 3.0 didn't have this
1823 * CSTAT member or a INTDIS register, so if this chip is
1824 * pre-3.0, process EOC interrupts normally.
1826 **************************************************************/
1828 static u32 tlan_handle_rx_eoc(struct net_device *dev, u16 host_int)
1830 struct tlan_priv *priv = netdev_priv(dev);
1831 dma_addr_t head_list_phys;
1834 if (priv->tlan_rev < 0x30) {
1835 TLAN_DBG(TLAN_DEBUG_RX,
1836 "RECEIVE: Handling RX EOC (head=%d tail=%d) -- IRQ\n",
1837 priv->rx_head, priv->rx_tail);
1838 head_list_phys = priv->rx_list_dma
1839 + sizeof(struct tlan_list)*priv->rx_head;
1840 outl(head_list_phys, dev->base_addr + TLAN_CH_PARM);
1841 ack |= TLAN_HC_GO | TLAN_HC_RT;
1842 priv->rx_eoc_count++;
1852 /*****************************************************************************
1853 ******************************************************************************
1855 ThunderLAN driver timer function
1857 ******************************************************************************
1858 *****************************************************************************/
1861 /***************************************************************
1867 * data A value given to add timer when
1868 * add_timer was called.
1870 * This function handles timed functionality for the
1871 * TLAN driver. The two current timer uses are for
1872 * delaying for autonegotionation and driving the ACT LED.
1873 * - Autonegotiation requires being allowed about
1874 * 2 1/2 seconds before attempting to transmit a
1875 * packet. It would be a very bad thing to hang
1876 * the kernel this long, so the driver doesn't
1877 * allow transmission 'til after this time, for
1878 * certain PHYs. It would be much nicer if all
1879 * PHYs were interrupt-capable like the internal
1881 * - The ACT LED, which shows adapter activity, is
1882 * driven by the driver, and so must be left on
1883 * for a short period to power up the LED so it
1884 * can be seen. This delay can be changed by
1885 * changing the TLAN_TIMER_ACT_DELAY in tlan.h,
1886 * if desired. 100 ms produces a slightly
1887 * sluggish response.
1889 **************************************************************/
1891 static void tlan_timer(unsigned long data)
1893 struct net_device *dev = (struct net_device *) data;
1894 struct tlan_priv *priv = netdev_priv(dev);
1896 unsigned long flags = 0;
1898 priv->timer.function = NULL;
1900 switch (priv->timer_type) {
1902 case TLAN_TIMER_LINK_BEAT:
1903 tlan_phy_monitor(dev);
1906 case TLAN_TIMER_PHY_PDOWN:
1907 tlan_phy_power_down(dev);
1909 case TLAN_TIMER_PHY_PUP:
1910 tlan_phy_power_up(dev);
1912 case TLAN_TIMER_PHY_RESET:
1913 tlan_phy_reset(dev);
1915 case TLAN_TIMER_PHY_START_LINK:
1916 tlan_phy_start_link(dev);
1918 case TLAN_TIMER_PHY_FINISH_AN:
1919 tlan_phy_finish_auto_neg(dev);
1921 case TLAN_TIMER_FINISH_RESET:
1922 tlan_finish_reset(dev);
1924 case TLAN_TIMER_ACTIVITY:
1925 spin_lock_irqsave(&priv->lock, flags);
1926 if (priv->timer.function == NULL) {
1927 elapsed = jiffies - priv->timer_set_at;
1928 if (elapsed >= TLAN_TIMER_ACT_DELAY) {
1929 tlan_dio_write8(dev->base_addr,
1930 TLAN_LED_REG, TLAN_LED_LINK);
1932 priv->timer.function = tlan_timer;
1933 priv->timer.expires = priv->timer_set_at
1934 + TLAN_TIMER_ACT_DELAY;
1935 spin_unlock_irqrestore(&priv->lock, flags);
1936 add_timer(&priv->timer);
1940 spin_unlock_irqrestore(&priv->lock, flags);
1951 /*****************************************************************************
1952 ******************************************************************************
1954 ThunderLAN driver adapter related routines
1956 ******************************************************************************
1957 *****************************************************************************/
1960 /***************************************************************
1966 * dev The device structure with the list
1967 * stuctures to be reset.
1969 * This routine sets the variables associated with managing
1970 * the TLAN lists to their initial values.
1972 **************************************************************/
1974 static void tlan_reset_lists(struct net_device *dev)
1976 struct tlan_priv *priv = netdev_priv(dev);
1978 struct tlan_list *list;
1979 dma_addr_t list_phys;
1980 struct sk_buff *skb;
1984 for (i = 0; i < TLAN_NUM_TX_LISTS; i++) {
1985 list = priv->tx_list + i;
1986 list->c_stat = TLAN_CSTAT_UNUSED;
1987 list->buffer[0].address = 0;
1988 list->buffer[2].count = 0;
1989 list->buffer[2].address = 0;
1990 list->buffer[8].address = 0;
1991 list->buffer[9].address = 0;
1995 priv->rx_tail = TLAN_NUM_RX_LISTS - 1;
1996 for (i = 0; i < TLAN_NUM_RX_LISTS; i++) {
1997 list = priv->rx_list + i;
1998 list_phys = priv->rx_list_dma + sizeof(struct tlan_list)*i;
1999 list->c_stat = TLAN_CSTAT_READY;
2000 list->frame_size = TLAN_MAX_FRAME_SIZE;
2001 list->buffer[0].count = TLAN_MAX_FRAME_SIZE | TLAN_LAST_BUFFER;
2002 skb = netdev_alloc_skb_ip_align(dev, TLAN_MAX_FRAME_SIZE + 5);
2004 pr_err("TLAN: out of memory for received data.\n");
2008 list->buffer[0].address = pci_map_single(priv->pci_dev,
2010 TLAN_MAX_FRAME_SIZE,
2011 PCI_DMA_FROMDEVICE);
2012 tlan_store_skb(list, skb);
2013 list->buffer[1].count = 0;
2014 list->buffer[1].address = 0;
2015 list->forward = list_phys + sizeof(struct tlan_list);
2018 /* in case ran out of memory early, clear bits */
2019 while (i < TLAN_NUM_RX_LISTS) {
2020 tlan_store_skb(priv->rx_list + i, NULL);
2028 static void tlan_free_lists(struct net_device *dev)
2030 struct tlan_priv *priv = netdev_priv(dev);
2032 struct tlan_list *list;
2033 struct sk_buff *skb;
2035 for (i = 0; i < TLAN_NUM_TX_LISTS; i++) {
2036 list = priv->tx_list + i;
2037 skb = tlan_get_skb(list);
2041 list->buffer[0].address,
2043 (unsigned int)TLAN_MIN_FRAME_SIZE),
2045 dev_kfree_skb_any(skb);
2046 list->buffer[8].address = 0;
2047 list->buffer[9].address = 0;
2051 for (i = 0; i < TLAN_NUM_RX_LISTS; i++) {
2052 list = priv->rx_list + i;
2053 skb = tlan_get_skb(list);
2055 pci_unmap_single(priv->pci_dev,
2056 list->buffer[0].address,
2057 TLAN_MAX_FRAME_SIZE,
2058 PCI_DMA_FROMDEVICE);
2059 dev_kfree_skb_any(skb);
2060 list->buffer[8].address = 0;
2061 list->buffer[9].address = 0;
2069 /***************************************************************
2075 * io_base Base IO port of the device of
2076 * which to print DIO registers.
2078 * This function prints out all the internal (DIO)
2079 * registers of a TLAN chip.
2081 **************************************************************/
2083 static void tlan_print_dio(u16 io_base)
2088 pr_info("TLAN: Contents of internal registers for io base 0x%04hx.\n",
2090 pr_info("TLAN: Off. +0 +4\n");
2091 for (i = 0; i < 0x4C; i += 8) {
2092 data0 = tlan_dio_read32(io_base, i);
2093 data1 = tlan_dio_read32(io_base, i + 0x4);
2094 pr_info("TLAN: 0x%02x 0x%08x 0x%08x\n", i, data0, data1);
2102 /***************************************************************
2108 * list A pointer to the struct tlan_list structure to
2110 * type A string to designate type of list,
2112 * num The index of the list.
2114 * This function prints out the contents of the list
2115 * pointed to by the list parameter.
2117 **************************************************************/
2119 static void tlan_print_list(struct tlan_list *list, char *type, int num)
2123 pr_info("TLAN: %s List %d at %p\n", type, num, list);
2124 pr_info("TLAN: Forward = 0x%08x\n", list->forward);
2125 pr_info("TLAN: CSTAT = 0x%04hx\n", list->c_stat);
2126 pr_info("TLAN: Frame Size = 0x%04hx\n", list->frame_size);
2127 /* for (i = 0; i < 10; i++) { */
2128 for (i = 0; i < 2; i++) {
2129 pr_info("TLAN: Buffer[%d].count, addr = 0x%08x, 0x%08x\n",
2130 i, list->buffer[i].count, list->buffer[i].address);
2138 /***************************************************************
2139 * tlan_read_and_clear_stats
2144 * dev Pointer to device structure of adapter
2145 * to which to read stats.
2146 * record Flag indicating whether to add
2148 * This functions reads all the internal status registers
2149 * of the TLAN chip, which clears them as a side effect.
2150 * It then either adds the values to the device's status
2151 * struct, or discards them, depending on whether record
2152 * is TLAN_RECORD (!=0) or TLAN_IGNORE (==0).
2154 **************************************************************/
2156 static void tlan_read_and_clear_stats(struct net_device *dev, int record)
2158 u32 tx_good, tx_under;
2159 u32 rx_good, rx_over;
2160 u32 def_tx, crc, code;
2161 u32 multi_col, single_col;
2162 u32 excess_col, late_col, loss;
2164 outw(TLAN_GOOD_TX_FRMS, dev->base_addr + TLAN_DIO_ADR);
2165 tx_good = inb(dev->base_addr + TLAN_DIO_DATA);
2166 tx_good += inb(dev->base_addr + TLAN_DIO_DATA + 1) << 8;
2167 tx_good += inb(dev->base_addr + TLAN_DIO_DATA + 2) << 16;
2168 tx_under = inb(dev->base_addr + TLAN_DIO_DATA + 3);
2170 outw(TLAN_GOOD_RX_FRMS, dev->base_addr + TLAN_DIO_ADR);
2171 rx_good = inb(dev->base_addr + TLAN_DIO_DATA);
2172 rx_good += inb(dev->base_addr + TLAN_DIO_DATA + 1) << 8;
2173 rx_good += inb(dev->base_addr + TLAN_DIO_DATA + 2) << 16;
2174 rx_over = inb(dev->base_addr + TLAN_DIO_DATA + 3);
2176 outw(TLAN_DEFERRED_TX, dev->base_addr + TLAN_DIO_ADR);
2177 def_tx = inb(dev->base_addr + TLAN_DIO_DATA);
2178 def_tx += inb(dev->base_addr + TLAN_DIO_DATA + 1) << 8;
2179 crc = inb(dev->base_addr + TLAN_DIO_DATA + 2);
2180 code = inb(dev->base_addr + TLAN_DIO_DATA + 3);
2182 outw(TLAN_MULTICOL_FRMS, dev->base_addr + TLAN_DIO_ADR);
2183 multi_col = inb(dev->base_addr + TLAN_DIO_DATA);
2184 multi_col += inb(dev->base_addr + TLAN_DIO_DATA + 1) << 8;
2185 single_col = inb(dev->base_addr + TLAN_DIO_DATA + 2);
2186 single_col += inb(dev->base_addr + TLAN_DIO_DATA + 3) << 8;
2188 outw(TLAN_EXCESSCOL_FRMS, dev->base_addr + TLAN_DIO_ADR);
2189 excess_col = inb(dev->base_addr + TLAN_DIO_DATA);
2190 late_col = inb(dev->base_addr + TLAN_DIO_DATA + 1);
2191 loss = inb(dev->base_addr + TLAN_DIO_DATA + 2);
2194 dev->stats.rx_packets += rx_good;
2195 dev->stats.rx_errors += rx_over + crc + code;
2196 dev->stats.tx_packets += tx_good;
2197 dev->stats.tx_errors += tx_under + loss;
2198 dev->stats.collisions += multi_col
2199 + single_col + excess_col + late_col;
2201 dev->stats.rx_over_errors += rx_over;
2202 dev->stats.rx_crc_errors += crc;
2203 dev->stats.rx_frame_errors += code;
2205 dev->stats.tx_aborted_errors += tx_under;
2206 dev->stats.tx_carrier_errors += loss;
2214 /***************************************************************
2220 * dev Pointer to device structure of adapter
2223 * This function resets the adapter and it's physical
2224 * device. See Chap. 3, pp. 9-10 of the "ThunderLAN
2225 * Programmer's Guide" for details. The routine tries to
2226 * implement what is detailed there, though adjustments
2229 **************************************************************/
2232 tlan_reset_adapter(struct net_device *dev)
2234 struct tlan_priv *priv = netdev_priv(dev);
2240 priv->tlan_full_duplex = false;
2241 priv->phy_online = 0;
2242 netif_carrier_off(dev);
2244 /* 1. Assert reset bit. */
2246 data = inl(dev->base_addr + TLAN_HOST_CMD);
2247 data |= TLAN_HC_AD_RST;
2248 outl(data, dev->base_addr + TLAN_HOST_CMD);
2252 /* 2. Turn off interrupts. (Probably isn't necessary) */
2254 data = inl(dev->base_addr + TLAN_HOST_CMD);
2255 data |= TLAN_HC_INT_OFF;
2256 outl(data, dev->base_addr + TLAN_HOST_CMD);
2258 /* 3. Clear AREGs and HASHs. */
2260 for (i = TLAN_AREG_0; i <= TLAN_HASH_2; i += 4)
2261 tlan_dio_write32(dev->base_addr, (u16) i, 0);
2263 /* 4. Setup NetConfig register. */
2265 data = TLAN_NET_CFG_1FRAG | TLAN_NET_CFG_1CHAN | TLAN_NET_CFG_PHY_EN;
2266 tlan_dio_write16(dev->base_addr, TLAN_NET_CONFIG, (u16) data);
2268 /* 5. Load Ld_Tmr and Ld_Thr in HOST_CMD. */
2270 outl(TLAN_HC_LD_TMR | 0x3f, dev->base_addr + TLAN_HOST_CMD);
2271 outl(TLAN_HC_LD_THR | 0x9, dev->base_addr + TLAN_HOST_CMD);
2273 /* 6. Unreset the MII by setting NMRST (in NetSio) to 1. */
2275 outw(TLAN_NET_SIO, dev->base_addr + TLAN_DIO_ADR);
2276 addr = dev->base_addr + TLAN_DIO_DATA + TLAN_NET_SIO;
2277 tlan_set_bit(TLAN_NET_SIO_NMRST, addr);
2279 /* 7. Setup the remaining registers. */
2281 if (priv->tlan_rev >= 0x30) {
2282 data8 = TLAN_ID_TX_EOC | TLAN_ID_RX_EOC;
2283 tlan_dio_write8(dev->base_addr, TLAN_INT_DIS, data8);
2285 tlan_phy_detect(dev);
2286 data = TLAN_NET_CFG_1FRAG | TLAN_NET_CFG_1CHAN;
2288 if (priv->adapter->flags & TLAN_ADAPTER_BIT_RATE_PHY) {
2289 data |= TLAN_NET_CFG_BIT;
2290 if (priv->aui == 1) {
2291 tlan_dio_write8(dev->base_addr, TLAN_ACOMMIT, 0x0a);
2292 } else if (priv->duplex == TLAN_DUPLEX_FULL) {
2293 tlan_dio_write8(dev->base_addr, TLAN_ACOMMIT, 0x00);
2294 priv->tlan_full_duplex = true;
2296 tlan_dio_write8(dev->base_addr, TLAN_ACOMMIT, 0x08);
2300 if (priv->phy_num == 0)
2301 data |= TLAN_NET_CFG_PHY_EN;
2302 tlan_dio_write16(dev->base_addr, TLAN_NET_CONFIG, (u16) data);
2304 if (priv->adapter->flags & TLAN_ADAPTER_UNMANAGED_PHY)
2305 tlan_finish_reset(dev);
2307 tlan_phy_power_down(dev);
2315 tlan_finish_reset(struct net_device *dev)
2317 struct tlan_priv *priv = netdev_priv(dev);
2325 u16 tlphy_id1, tlphy_id2;
2328 phy = priv->phy[priv->phy_num];
2330 data = TLAN_NET_CMD_NRESET | TLAN_NET_CMD_NWRAP;
2331 if (priv->tlan_full_duplex)
2332 data |= TLAN_NET_CMD_DUPLEX;
2333 tlan_dio_write8(dev->base_addr, TLAN_NET_CMD, data);
2334 data = TLAN_NET_MASK_MASK4 | TLAN_NET_MASK_MASK5;
2335 if (priv->phy_num == 0)
2336 data |= TLAN_NET_MASK_MASK7;
2337 tlan_dio_write8(dev->base_addr, TLAN_NET_MASK, data);
2338 tlan_dio_write16(dev->base_addr, TLAN_MAX_RX, ((1536)+7)&~7);
2339 tlan_mii_read_reg(dev, phy, MII_GEN_ID_HI, &tlphy_id1);
2340 tlan_mii_read_reg(dev, phy, MII_GEN_ID_LO, &tlphy_id2);
2342 if ((priv->adapter->flags & TLAN_ADAPTER_UNMANAGED_PHY) ||
2344 status = MII_GS_LINK;
2345 pr_info("TLAN: %s: Link forced.\n", dev->name);
2347 tlan_mii_read_reg(dev, phy, MII_GEN_STS, &status);
2349 tlan_mii_read_reg(dev, phy, MII_GEN_STS, &status);
2350 if ((status & MII_GS_LINK) &&
2351 /* We only support link info on Nat.Sem. PHY's */
2352 (tlphy_id1 == NAT_SEM_ID1) &&
2353 (tlphy_id2 == NAT_SEM_ID2)) {
2354 tlan_mii_read_reg(dev, phy, MII_AN_LPA, &partner);
2355 tlan_mii_read_reg(dev, phy, TLAN_TLPHY_PAR, &tlphy_par);
2357 pr_info("TLAN: %s: Link active with ", dev->name);
2358 if (!(tlphy_par & TLAN_PHY_AN_EN_STAT)) {
2359 pr_info("forced 10%sMbps %s-Duplex\n",
2360 tlphy_par & TLAN_PHY_SPEED_100
2362 tlphy_par & TLAN_PHY_DUPLEX_FULL
2365 pr_info("Autonegotiation enabled, at 10%sMbps %s-Duplex\n",
2366 tlphy_par & TLAN_PHY_SPEED_100
2368 tlphy_par & TLAN_PHY_DUPLEX_FULL
2370 pr_info("TLAN: Partner capability: ");
2371 for (i = 5; i <= 10; i++)
2372 if (partner & (1<<i))
2373 printk("%s", media[i-5]);
2377 tlan_dio_write8(dev->base_addr, TLAN_LED_REG,
2380 /* We have link beat..for now anyway */
2382 /*Enabling link beat monitoring */
2383 tlan_set_timer(dev, (10*HZ), TLAN_TIMER_LINK_BEAT);
2385 } else if (status & MII_GS_LINK) {
2386 pr_info("TLAN: %s: Link active\n", dev->name);
2387 tlan_dio_write8(dev->base_addr, TLAN_LED_REG,
2392 if (priv->phy_num == 0) {
2393 tlan_mii_read_reg(dev, phy, TLAN_TLPHY_CTL, &tlphy_ctl);
2394 tlphy_ctl |= TLAN_TC_INTEN;
2395 tlan_mii_write_reg(dev, phy, TLAN_TLPHY_CTL, tlphy_ctl);
2396 sio = tlan_dio_read8(dev->base_addr, TLAN_NET_SIO);
2397 sio |= TLAN_NET_SIO_MINTEN;
2398 tlan_dio_write8(dev->base_addr, TLAN_NET_SIO, sio);
2401 if (status & MII_GS_LINK) {
2402 tlan_set_mac(dev, 0, dev->dev_addr);
2403 priv->phy_online = 1;
2404 outb((TLAN_HC_INT_ON >> 8), dev->base_addr + TLAN_HOST_CMD + 1);
2405 if (debug >= 1 && debug != TLAN_DEBUG_PROBE)
2406 outb((TLAN_HC_REQ_INT >> 8),
2407 dev->base_addr + TLAN_HOST_CMD + 1);
2408 outl(priv->rx_list_dma, dev->base_addr + TLAN_CH_PARM);
2409 outl(TLAN_HC_GO | TLAN_HC_RT, dev->base_addr + TLAN_HOST_CMD);
2410 netif_carrier_on(dev);
2412 pr_info("TLAN: %s: Link inactive, will retry in 10 secs...\n",
2414 tlan_set_timer(dev, (10*HZ), TLAN_TIMER_FINISH_RESET);
2417 tlan_set_multicast_list(dev);
2424 /***************************************************************
2430 * dev Pointer to device structure of adapter
2431 * on which to change the AREG.
2432 * areg The AREG to set the address in (0 - 3).
2433 * mac A pointer to an array of chars. Each
2434 * element stores one byte of the address.
2435 * IE, it isn't in ascii.
2437 * This function transfers a MAC address to one of the
2438 * TLAN AREGs (address registers). The TLAN chip locks
2439 * the register on writing to offset 0 and unlocks the
2440 * register after writing to offset 5. If NULL is passed
2441 * in mac, then the AREG is filled with 0's.
2443 **************************************************************/
2445 static void tlan_set_mac(struct net_device *dev, int areg, char *mac)
2452 for (i = 0; i < 6; i++)
2453 tlan_dio_write8(dev->base_addr,
2454 TLAN_AREG_0 + areg + i, mac[i]);
2456 for (i = 0; i < 6; i++)
2457 tlan_dio_write8(dev->base_addr,
2458 TLAN_AREG_0 + areg + i, 0);
2466 /*****************************************************************************
2467 ******************************************************************************
2469 ThunderLAN driver PHY layer routines
2471 ******************************************************************************
2472 *****************************************************************************/
2476 /*********************************************************************
2482 * dev A pointer to the device structure of the
2483 * TLAN device having the PHYs to be detailed.
2485 * This function prints the registers a PHY (aka transceiver).
2487 ********************************************************************/
2489 static void tlan_phy_print(struct net_device *dev)
2491 struct tlan_priv *priv = netdev_priv(dev);
2492 u16 i, data0, data1, data2, data3, phy;
2494 phy = priv->phy[priv->phy_num];
2496 if (priv->adapter->flags & TLAN_ADAPTER_UNMANAGED_PHY) {
2497 pr_info("TLAN: Device %s, Unmanaged PHY.\n", dev->name);
2498 } else if (phy <= TLAN_PHY_MAX_ADDR) {
2499 pr_info("TLAN: Device %s, PHY 0x%02x.\n", dev->name, phy);
2500 pr_info("TLAN: Off. +0 +1 +2 +3\n");
2501 for (i = 0; i < 0x20; i += 4) {
2502 pr_info("TLAN: 0x%02x", i);
2503 tlan_mii_read_reg(dev, phy, i, &data0);
2504 printk(" 0x%04hx", data0);
2505 tlan_mii_read_reg(dev, phy, i + 1, &data1);
2506 printk(" 0x%04hx", data1);
2507 tlan_mii_read_reg(dev, phy, i + 2, &data2);
2508 printk(" 0x%04hx", data2);
2509 tlan_mii_read_reg(dev, phy, i + 3, &data3);
2510 printk(" 0x%04hx\n", data3);
2513 pr_info("TLAN: Device %s, Invalid PHY.\n", dev->name);
2521 /*********************************************************************
2527 * dev A pointer to the device structure of the adapter
2528 * for which the PHY needs determined.
2530 * So far I've found that adapters which have external PHYs
2531 * may also use the internal PHY for part of the functionality.
2532 * (eg, AUI/Thinnet). This function finds out if this TLAN
2533 * chip has an internal PHY, and then finds the first external
2534 * PHY (starting from address 0) if it exists).
2536 ********************************************************************/
2538 static void tlan_phy_detect(struct net_device *dev)
2540 struct tlan_priv *priv = netdev_priv(dev);
2546 if (priv->adapter->flags & TLAN_ADAPTER_UNMANAGED_PHY) {
2547 priv->phy_num = 0xffff;
2551 tlan_mii_read_reg(dev, TLAN_PHY_MAX_ADDR, MII_GEN_ID_HI, &hi);
2554 priv->phy[0] = TLAN_PHY_MAX_ADDR;
2556 priv->phy[0] = TLAN_PHY_NONE;
2558 priv->phy[1] = TLAN_PHY_NONE;
2559 for (phy = 0; phy <= TLAN_PHY_MAX_ADDR; phy++) {
2560 tlan_mii_read_reg(dev, phy, MII_GEN_CTL, &control);
2561 tlan_mii_read_reg(dev, phy, MII_GEN_ID_HI, &hi);
2562 tlan_mii_read_reg(dev, phy, MII_GEN_ID_LO, &lo);
2563 if ((control != 0xffff) ||
2564 (hi != 0xffff) || (lo != 0xffff)) {
2565 TLAN_DBG(TLAN_DEBUG_GNRL,
2566 "PHY found at %02x %04x %04x %04x\n",
2567 phy, control, hi, lo);
2568 if ((priv->phy[1] == TLAN_PHY_NONE) &&
2569 (phy != TLAN_PHY_MAX_ADDR)) {
2575 if (priv->phy[1] != TLAN_PHY_NONE)
2577 else if (priv->phy[0] != TLAN_PHY_NONE)
2580 pr_info("TLAN: Cannot initialize device, no PHY was found!\n");
2587 static void tlan_phy_power_down(struct net_device *dev)
2589 struct tlan_priv *priv = netdev_priv(dev);
2592 TLAN_DBG(TLAN_DEBUG_GNRL, "%s: Powering down PHY(s).\n", dev->name);
2593 value = MII_GC_PDOWN | MII_GC_LOOPBK | MII_GC_ISOLATE;
2594 tlan_mii_sync(dev->base_addr);
2595 tlan_mii_write_reg(dev, priv->phy[priv->phy_num], MII_GEN_CTL, value);
2596 if ((priv->phy_num == 0) &&
2597 (priv->phy[1] != TLAN_PHY_NONE) &&
2598 (!(priv->adapter->flags & TLAN_ADAPTER_USE_INTERN_10))) {
2599 tlan_mii_sync(dev->base_addr);
2600 tlan_mii_write_reg(dev, priv->phy[1], MII_GEN_CTL, value);
2603 /* Wait for 50 ms and powerup
2604 * This is abitrary. It is intended to make sure the
2605 * transceiver settles.
2607 tlan_set_timer(dev, (HZ/20), TLAN_TIMER_PHY_PUP);
2614 static void tlan_phy_power_up(struct net_device *dev)
2616 struct tlan_priv *priv = netdev_priv(dev);
2619 TLAN_DBG(TLAN_DEBUG_GNRL, "%s: Powering up PHY.\n", dev->name);
2620 tlan_mii_sync(dev->base_addr);
2621 value = MII_GC_LOOPBK;
2622 tlan_mii_write_reg(dev, priv->phy[priv->phy_num], MII_GEN_CTL, value);
2623 tlan_mii_sync(dev->base_addr);
2624 /* Wait for 500 ms and reset the
2625 * transceiver. The TLAN docs say both 50 ms and
2626 * 500 ms, so do the longer, just in case.
2628 tlan_set_timer(dev, (HZ/20), TLAN_TIMER_PHY_RESET);
2635 static void tlan_phy_reset(struct net_device *dev)
2637 struct tlan_priv *priv = netdev_priv(dev);
2641 phy = priv->phy[priv->phy_num];
2643 TLAN_DBG(TLAN_DEBUG_GNRL, "%s: Reseting PHY.\n", dev->name);
2644 tlan_mii_sync(dev->base_addr);
2645 value = MII_GC_LOOPBK | MII_GC_RESET;
2646 tlan_mii_write_reg(dev, phy, MII_GEN_CTL, value);
2647 tlan_mii_read_reg(dev, phy, MII_GEN_CTL, &value);
2648 while (value & MII_GC_RESET)
2649 tlan_mii_read_reg(dev, phy, MII_GEN_CTL, &value);
2651 /* Wait for 500 ms and initialize.
2652 * I don't remember why I wait this long.
2653 * I've changed this to 50ms, as it seems long enough.
2655 tlan_set_timer(dev, (HZ/20), TLAN_TIMER_PHY_START_LINK);
2662 static void tlan_phy_start_link(struct net_device *dev)
2664 struct tlan_priv *priv = netdev_priv(dev);
2672 phy = priv->phy[priv->phy_num];
2673 TLAN_DBG(TLAN_DEBUG_GNRL, "%s: Trying to activate link.\n", dev->name);
2674 tlan_mii_read_reg(dev, phy, MII_GEN_STS, &status);
2675 tlan_mii_read_reg(dev, phy, MII_GEN_STS, &ability);
2677 if ((status & MII_GS_AUTONEG) &&
2679 ability = status >> 11;
2680 if (priv->speed == TLAN_SPEED_10 &&
2681 priv->duplex == TLAN_DUPLEX_HALF) {
2682 tlan_mii_write_reg(dev, phy, MII_GEN_CTL, 0x0000);
2683 } else if (priv->speed == TLAN_SPEED_10 &&
2684 priv->duplex == TLAN_DUPLEX_FULL) {
2685 priv->tlan_full_duplex = true;
2686 tlan_mii_write_reg(dev, phy, MII_GEN_CTL, 0x0100);
2687 } else if (priv->speed == TLAN_SPEED_100 &&
2688 priv->duplex == TLAN_DUPLEX_HALF) {
2689 tlan_mii_write_reg(dev, phy, MII_GEN_CTL, 0x2000);
2690 } else if (priv->speed == TLAN_SPEED_100 &&
2691 priv->duplex == TLAN_DUPLEX_FULL) {
2692 priv->tlan_full_duplex = true;
2693 tlan_mii_write_reg(dev, phy, MII_GEN_CTL, 0x2100);
2696 /* Set Auto-Neg advertisement */
2697 tlan_mii_write_reg(dev, phy, MII_AN_ADV,
2698 (ability << 5) | 1);
2699 /* Enablee Auto-Neg */
2700 tlan_mii_write_reg(dev, phy, MII_GEN_CTL, 0x1000);
2701 /* Restart Auto-Neg */
2702 tlan_mii_write_reg(dev, phy, MII_GEN_CTL, 0x1200);
2703 /* Wait for 4 sec for autonegotiation
2704 * to complete. The max spec time is less than this
2705 * but the card need additional time to start AN.
2706 * .5 sec should be plenty extra.
2708 pr_info("TLAN: %s: Starting autonegotiation.\n",
2710 tlan_set_timer(dev, (2*HZ), TLAN_TIMER_PHY_FINISH_AN);
2716 if ((priv->aui) && (priv->phy_num != 0)) {
2718 data = TLAN_NET_CFG_1FRAG | TLAN_NET_CFG_1CHAN
2719 | TLAN_NET_CFG_PHY_EN;
2720 tlan_dio_write16(dev->base_addr, TLAN_NET_CONFIG, data);
2721 tlan_set_timer(dev, (40*HZ/1000), TLAN_TIMER_PHY_PDOWN);
2723 } else if (priv->phy_num == 0) {
2725 tlan_mii_read_reg(dev, phy, TLAN_TLPHY_CTL, &tctl);
2727 tctl |= TLAN_TC_AUISEL;
2729 tctl &= ~TLAN_TC_AUISEL;
2730 if (priv->duplex == TLAN_DUPLEX_FULL) {
2731 control |= MII_GC_DUPLEX;
2732 priv->tlan_full_duplex = true;
2734 if (priv->speed == TLAN_SPEED_100)
2735 control |= MII_GC_SPEEDSEL;
2737 tlan_mii_write_reg(dev, phy, MII_GEN_CTL, control);
2738 tlan_mii_write_reg(dev, phy, TLAN_TLPHY_CTL, tctl);
2741 /* Wait for 2 sec to give the transceiver time
2742 * to establish link.
2744 tlan_set_timer(dev, (4*HZ), TLAN_TIMER_FINISH_RESET);
2751 static void tlan_phy_finish_auto_neg(struct net_device *dev)
2753 struct tlan_priv *priv = netdev_priv(dev);
2761 phy = priv->phy[priv->phy_num];
2763 tlan_mii_read_reg(dev, phy, MII_GEN_STS, &status);
2765 tlan_mii_read_reg(dev, phy, MII_GEN_STS, &status);
2767 if (!(status & MII_GS_AUTOCMPLT)) {
2768 /* Wait for 8 sec to give the process
2769 * more time. Perhaps we should fail after a while.
2771 if (!priv->neg_be_verbose++) {
2772 pr_info("TLAN: Giving autonegotiation more time.\n");
2773 pr_info("TLAN: Please check that your adapter has\n");
2774 pr_info("TLAN: been properly connected to a HUB or Switch.\n");
2775 pr_info("TLAN: Trying to establish link in the background...\n");
2777 tlan_set_timer(dev, (8*HZ), TLAN_TIMER_PHY_FINISH_AN);
2781 pr_info("TLAN: %s: Autonegotiation complete.\n", dev->name);
2782 tlan_mii_read_reg(dev, phy, MII_AN_ADV, &an_adv);
2783 tlan_mii_read_reg(dev, phy, MII_AN_LPA, &an_lpa);
2784 mode = an_adv & an_lpa & 0x03E0;
2786 priv->tlan_full_duplex = true;
2787 else if (!(mode & 0x0080) && (mode & 0x0040))
2788 priv->tlan_full_duplex = true;
2790 if ((!(mode & 0x0180)) &&
2791 (priv->adapter->flags & TLAN_ADAPTER_USE_INTERN_10) &&
2792 (priv->phy_num != 0)) {
2794 data = TLAN_NET_CFG_1FRAG | TLAN_NET_CFG_1CHAN
2795 | TLAN_NET_CFG_PHY_EN;
2796 tlan_dio_write16(dev->base_addr, TLAN_NET_CONFIG, data);
2797 tlan_set_timer(dev, (400*HZ/1000), TLAN_TIMER_PHY_PDOWN);
2801 if (priv->phy_num == 0) {
2802 if ((priv->duplex == TLAN_DUPLEX_FULL) ||
2803 (an_adv & an_lpa & 0x0040)) {
2804 tlan_mii_write_reg(dev, phy, MII_GEN_CTL,
2805 MII_GC_AUTOENB | MII_GC_DUPLEX);
2806 pr_info("TLAN: Starting internal PHY with FULL-DUPLEX\n");
2808 tlan_mii_write_reg(dev, phy, MII_GEN_CTL,
2810 pr_info("TLAN: Starting internal PHY with HALF-DUPLEX\n");
2814 /* Wait for 100 ms. No reason in partiticular.
2816 tlan_set_timer(dev, (HZ/10), TLAN_TIMER_FINISH_RESET);
2822 /*********************************************************************
2830 * dev The device structure of this device.
2833 * This function monitors PHY condition by reading the status
2834 * register via the MII bus. This can be used to give info
2835 * about link changes (up/down), and possible switch to alternate
2838 *******************************************************************/
2840 void tlan_phy_monitor(struct net_device *dev)
2842 struct tlan_priv *priv = netdev_priv(dev);
2846 phy = priv->phy[priv->phy_num];
2848 /* Get PHY status register */
2849 tlan_mii_read_reg(dev, phy, MII_GEN_STS, &phy_status);
2851 /* Check if link has been lost */
2852 if (!(phy_status & MII_GS_LINK)) {
2855 printk(KERN_DEBUG "TLAN: %s has lost link\n",
2857 netif_carrier_off(dev);
2858 tlan_set_timer(dev, (2*HZ), TLAN_TIMER_LINK_BEAT);
2863 /* Link restablished? */
2864 if ((phy_status & MII_GS_LINK) && !priv->link) {
2866 printk(KERN_DEBUG "TLAN: %s has reestablished link\n",
2868 netif_carrier_on(dev);
2871 /* Setup a new monitor */
2872 tlan_set_timer(dev, (2*HZ), TLAN_TIMER_LINK_BEAT);
2875 #endif /* MONITOR */
2878 /*****************************************************************************
2879 ******************************************************************************
2881 ThunderLAN driver MII routines
2883 these routines are based on the information in chap. 2 of the
2884 "ThunderLAN Programmer's Guide", pp. 15-24.
2886 ******************************************************************************
2887 *****************************************************************************/
2890 /***************************************************************
2894 * false if ack received ok
2895 * true if no ack received or other error
2898 * dev The device structure containing
2899 * The io address and interrupt count
2901 * phy The address of the PHY to be queried.
2902 * reg The register whose contents are to be
2904 * val A pointer to a variable to store the
2907 * This function uses the TLAN's MII bus to retrieve the contents
2908 * of a given register on a PHY. It sends the appropriate info
2909 * and then reads the 16-bit register value from the MII bus via
2910 * the TLAN SIO register.
2912 **************************************************************/
2915 tlan_mii_read_reg(struct net_device *dev, u16 phy, u16 reg, u16 *val)
2922 struct tlan_priv *priv = netdev_priv(dev);
2923 unsigned long flags = 0;
2926 outw(TLAN_NET_SIO, dev->base_addr + TLAN_DIO_ADR);
2927 sio = dev->base_addr + TLAN_DIO_DATA + TLAN_NET_SIO;
2930 spin_lock_irqsave(&priv->lock, flags);
2932 tlan_mii_sync(dev->base_addr);
2934 minten = tlan_get_bit(TLAN_NET_SIO_MINTEN, sio);
2936 tlan_clear_bit(TLAN_NET_SIO_MINTEN, sio);
2938 tlan_mii_send_data(dev->base_addr, 0x1, 2); /* start (01b) */
2939 tlan_mii_send_data(dev->base_addr, 0x2, 2); /* read (10b) */
2940 tlan_mii_send_data(dev->base_addr, phy, 5); /* device # */
2941 tlan_mii_send_data(dev->base_addr, reg, 5); /* register # */
2944 tlan_clear_bit(TLAN_NET_SIO_MTXEN, sio); /* change direction */
2946 tlan_clear_bit(TLAN_NET_SIO_MCLK, sio); /* clock idle bit */
2947 tlan_set_bit(TLAN_NET_SIO_MCLK, sio);
2948 tlan_clear_bit(TLAN_NET_SIO_MCLK, sio); /* wait 300ns */
2950 nack = tlan_get_bit(TLAN_NET_SIO_MDATA, sio); /* check for ACK */
2951 tlan_set_bit(TLAN_NET_SIO_MCLK, sio); /* finish ACK */
2952 if (nack) { /* no ACK, so fake it */
2953 for (i = 0; i < 16; i++) {
2954 tlan_clear_bit(TLAN_NET_SIO_MCLK, sio);
2955 tlan_set_bit(TLAN_NET_SIO_MCLK, sio);
2959 } else { /* ACK, so read data */
2960 for (tmp = 0, i = 0x8000; i; i >>= 1) {
2961 tlan_clear_bit(TLAN_NET_SIO_MCLK, sio);
2962 if (tlan_get_bit(TLAN_NET_SIO_MDATA, sio))
2964 tlan_set_bit(TLAN_NET_SIO_MCLK, sio);
2969 tlan_clear_bit(TLAN_NET_SIO_MCLK, sio); /* idle cycle */
2970 tlan_set_bit(TLAN_NET_SIO_MCLK, sio);
2973 tlan_set_bit(TLAN_NET_SIO_MINTEN, sio);
2978 spin_unlock_irqrestore(&priv->lock, flags);
2987 /***************************************************************
2988 * tlan_mii_send_data
2993 * base_port The base IO port of the adapter in
2995 * dev The address of the PHY to be queried.
2996 * data The value to be placed on the MII bus.
2997 * num_bits The number of bits in data that are to
2998 * be placed on the MII bus.
3000 * This function sends on sequence of bits on the MII
3001 * configuration bus.
3003 **************************************************************/
3005 static void tlan_mii_send_data(u16 base_port, u32 data, unsigned num_bits)
3013 outw(TLAN_NET_SIO, base_port + TLAN_DIO_ADR);
3014 sio = base_port + TLAN_DIO_DATA + TLAN_NET_SIO;
3015 tlan_set_bit(TLAN_NET_SIO_MTXEN, sio);
3017 for (i = (0x1 << (num_bits - 1)); i; i >>= 1) {
3018 tlan_clear_bit(TLAN_NET_SIO_MCLK, sio);
3019 (void) tlan_get_bit(TLAN_NET_SIO_MCLK, sio);
3021 tlan_set_bit(TLAN_NET_SIO_MDATA, sio);
3023 tlan_clear_bit(TLAN_NET_SIO_MDATA, sio);
3024 tlan_set_bit(TLAN_NET_SIO_MCLK, sio);
3025 (void) tlan_get_bit(TLAN_NET_SIO_MCLK, sio);
3033 /***************************************************************
3039 * base_port The base IO port of the adapter in
3042 * This functions syncs all PHYs in terms of the MII configuration
3045 **************************************************************/
3047 static void tlan_mii_sync(u16 base_port)
3052 outw(TLAN_NET_SIO, base_port + TLAN_DIO_ADR);
3053 sio = base_port + TLAN_DIO_DATA + TLAN_NET_SIO;
3055 tlan_clear_bit(TLAN_NET_SIO_MTXEN, sio);
3056 for (i = 0; i < 32; i++) {
3057 tlan_clear_bit(TLAN_NET_SIO_MCLK, sio);
3058 tlan_set_bit(TLAN_NET_SIO_MCLK, sio);
3066 /***************************************************************
3067 * tlan_mii_write_reg
3072 * dev The device structure for the device
3074 * phy The address of the PHY to be written to.
3075 * reg The register whose contents are to be
3077 * val The value to be written to the register.
3079 * This function uses the TLAN's MII bus to write the contents of a
3080 * given register on a PHY. It sends the appropriate info and then
3081 * writes the 16-bit register value from the MII configuration bus
3082 * via the TLAN SIO register.
3084 **************************************************************/
3087 tlan_mii_write_reg(struct net_device *dev, u16 phy, u16 reg, u16 val)
3091 unsigned long flags = 0;
3092 struct tlan_priv *priv = netdev_priv(dev);
3094 outw(TLAN_NET_SIO, dev->base_addr + TLAN_DIO_ADR);
3095 sio = dev->base_addr + TLAN_DIO_DATA + TLAN_NET_SIO;
3098 spin_lock_irqsave(&priv->lock, flags);
3100 tlan_mii_sync(dev->base_addr);
3102 minten = tlan_get_bit(TLAN_NET_SIO_MINTEN, sio);
3104 tlan_clear_bit(TLAN_NET_SIO_MINTEN, sio);
3106 tlan_mii_send_data(dev->base_addr, 0x1, 2); /* start (01b) */
3107 tlan_mii_send_data(dev->base_addr, 0x1, 2); /* write (01b) */
3108 tlan_mii_send_data(dev->base_addr, phy, 5); /* device # */
3109 tlan_mii_send_data(dev->base_addr, reg, 5); /* register # */
3111 tlan_mii_send_data(dev->base_addr, 0x2, 2); /* send ACK */
3112 tlan_mii_send_data(dev->base_addr, val, 16); /* send data */
3114 tlan_clear_bit(TLAN_NET_SIO_MCLK, sio); /* idle cycle */
3115 tlan_set_bit(TLAN_NET_SIO_MCLK, sio);
3118 tlan_set_bit(TLAN_NET_SIO_MINTEN, sio);
3121 spin_unlock_irqrestore(&priv->lock, flags);
3128 /*****************************************************************************
3129 ******************************************************************************
3131 ThunderLAN driver eeprom routines
3133 the Compaq netelligent 10 and 10/100 cards use a microchip 24C02A
3134 EEPROM. these functions are based on information in microchip's
3135 data sheet. I don't know how well this functions will work with
3138 ******************************************************************************
3139 *****************************************************************************/
3142 /***************************************************************
3143 * tlan_ee_send_start
3148 * io_base The IO port base address for the
3149 * TLAN device with the EEPROM to
3152 * This function sends a start cycle to an EEPROM attached
3155 **************************************************************/
3157 static void tlan_ee_send_start(u16 io_base)
3161 outw(TLAN_NET_SIO, io_base + TLAN_DIO_ADR);
3162 sio = io_base + TLAN_DIO_DATA + TLAN_NET_SIO;
3164 tlan_set_bit(TLAN_NET_SIO_ECLOK, sio);
3165 tlan_set_bit(TLAN_NET_SIO_EDATA, sio);
3166 tlan_set_bit(TLAN_NET_SIO_ETXEN, sio);
3167 tlan_clear_bit(TLAN_NET_SIO_EDATA, sio);
3168 tlan_clear_bit(TLAN_NET_SIO_ECLOK, sio);
3175 /***************************************************************
3179 * If the correct ack was received, 0, otherwise 1
3180 * Parms: io_base The IO port base address for the
3181 * TLAN device with the EEPROM to
3183 * data The 8 bits of information to
3184 * send to the EEPROM.
3185 * stop If TLAN_EEPROM_STOP is passed, a
3186 * stop cycle is sent after the
3187 * byte is sent after the ack is
3190 * This function sends a byte on the serial EEPROM line,
3191 * driving the clock to send each bit. The function then
3192 * reverses transmission direction and reads an acknowledge
3195 **************************************************************/
3197 static int tlan_ee_send_byte(u16 io_base, u8 data, int stop)
3203 outw(TLAN_NET_SIO, io_base + TLAN_DIO_ADR);
3204 sio = io_base + TLAN_DIO_DATA + TLAN_NET_SIO;
3206 /* Assume clock is low, tx is enabled; */
3207 for (place = 0x80; place != 0; place >>= 1) {
3209 tlan_set_bit(TLAN_NET_SIO_EDATA, sio);
3211 tlan_clear_bit(TLAN_NET_SIO_EDATA, sio);
3212 tlan_set_bit(TLAN_NET_SIO_ECLOK, sio);
3213 tlan_clear_bit(TLAN_NET_SIO_ECLOK, sio);
3215 tlan_clear_bit(TLAN_NET_SIO_ETXEN, sio);
3216 tlan_set_bit(TLAN_NET_SIO_ECLOK, sio);
3217 err = tlan_get_bit(TLAN_NET_SIO_EDATA, sio);
3218 tlan_clear_bit(TLAN_NET_SIO_ECLOK, sio);
3219 tlan_set_bit(TLAN_NET_SIO_ETXEN, sio);
3221 if ((!err) && stop) {
3222 /* STOP, raise data while clock is high */
3223 tlan_clear_bit(TLAN_NET_SIO_EDATA, sio);
3224 tlan_set_bit(TLAN_NET_SIO_ECLOK, sio);
3225 tlan_set_bit(TLAN_NET_SIO_EDATA, sio);
3235 /***************************************************************
3236 * tlan_ee_receive_byte
3241 * io_base The IO port base address for the
3242 * TLAN device with the EEPROM to
3244 * data An address to a char to hold the
3245 * data sent from the EEPROM.
3246 * stop If TLAN_EEPROM_STOP is passed, a
3247 * stop cycle is sent after the
3248 * byte is received, and no ack is
3251 * This function receives 8 bits of data from the EEPROM
3252 * over the serial link. It then sends and ack bit, or no
3253 * ack and a stop bit. This function is used to retrieve
3254 * data after the address of a byte in the EEPROM has been
3257 **************************************************************/
3259 static void tlan_ee_receive_byte(u16 io_base, u8 *data, int stop)
3264 outw(TLAN_NET_SIO, io_base + TLAN_DIO_ADR);
3265 sio = io_base + TLAN_DIO_DATA + TLAN_NET_SIO;
3268 /* Assume clock is low, tx is enabled; */
3269 tlan_clear_bit(TLAN_NET_SIO_ETXEN, sio);
3270 for (place = 0x80; place; place >>= 1) {
3271 tlan_set_bit(TLAN_NET_SIO_ECLOK, sio);
3272 if (tlan_get_bit(TLAN_NET_SIO_EDATA, sio))
3274 tlan_clear_bit(TLAN_NET_SIO_ECLOK, sio);
3277 tlan_set_bit(TLAN_NET_SIO_ETXEN, sio);
3279 tlan_clear_bit(TLAN_NET_SIO_EDATA, sio); /* ack = 0 */
3280 tlan_set_bit(TLAN_NET_SIO_ECLOK, sio);
3281 tlan_clear_bit(TLAN_NET_SIO_ECLOK, sio);
3283 tlan_set_bit(TLAN_NET_SIO_EDATA, sio); /* no ack = 1 (?) */
3284 tlan_set_bit(TLAN_NET_SIO_ECLOK, sio);
3285 tlan_clear_bit(TLAN_NET_SIO_ECLOK, sio);
3286 /* STOP, raise data while clock is high */
3287 tlan_clear_bit(TLAN_NET_SIO_EDATA, sio);
3288 tlan_set_bit(TLAN_NET_SIO_ECLOK, sio);
3289 tlan_set_bit(TLAN_NET_SIO_EDATA, sio);
3297 /***************************************************************
3301 * No error = 0, else, the stage at which the error
3304 * io_base The IO port base address for the
3305 * TLAN device with the EEPROM to
3307 * ee_addr The address of the byte in the
3308 * EEPROM whose contents are to be
3310 * data An address to a char to hold the
3311 * data obtained from the EEPROM.
3313 * This function reads a byte of information from an byte
3314 * cell in the EEPROM.
3316 **************************************************************/
3318 static int tlan_ee_read_byte(struct net_device *dev, u8 ee_addr, u8 *data)
3321 struct tlan_priv *priv = netdev_priv(dev);
3322 unsigned long flags = 0;
3325 spin_lock_irqsave(&priv->lock, flags);
3327 tlan_ee_send_start(dev->base_addr);
3328 err = tlan_ee_send_byte(dev->base_addr, 0xa0, TLAN_EEPROM_ACK);
3333 err = tlan_ee_send_byte(dev->base_addr, ee_addr, TLAN_EEPROM_ACK);
3338 tlan_ee_send_start(dev->base_addr);
3339 err = tlan_ee_send_byte(dev->base_addr, 0xa1, TLAN_EEPROM_ACK);
3344 tlan_ee_receive_byte(dev->base_addr, data, TLAN_EEPROM_STOP);
3346 spin_unlock_irqrestore(&priv->lock, flags);