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.
171 * v1.17 Jan 6 2011 - Add suspend/resume support.
173 ******************************************************************************/
175 #include <linux/module.h>
176 #include <linux/init.h>
177 #include <linux/ioport.h>
178 #include <linux/eisa.h>
179 #include <linux/pci.h>
180 #include <linux/dma-mapping.h>
181 #include <linux/netdevice.h>
182 #include <linux/etherdevice.h>
183 #include <linux/delay.h>
184 #include <linux/spinlock.h>
185 #include <linux/workqueue.h>
186 #include <linux/mii.h>
191 /* For removing EISA devices */
192 static struct net_device *tlan_eisa_devices;
194 static int tlan_devices_installed;
196 /* Set speed, duplex and aui settings */
197 static int aui[MAX_TLAN_BOARDS];
198 static int duplex[MAX_TLAN_BOARDS];
199 static int speed[MAX_TLAN_BOARDS];
200 static int boards_found;
201 module_param_array(aui, int, NULL, 0);
202 module_param_array(duplex, int, NULL, 0);
203 module_param_array(speed, int, NULL, 0);
204 MODULE_PARM_DESC(aui, "ThunderLAN use AUI port(s) (0-1)");
205 MODULE_PARM_DESC(duplex,
206 "ThunderLAN duplex setting(s) (0-default, 1-half, 2-full)");
207 MODULE_PARM_DESC(speed, "ThunderLAN port speen setting(s) (0,10,100)");
209 MODULE_AUTHOR("Maintainer: Samuel Chessman <chessman@tux.org>");
210 MODULE_DESCRIPTION("Driver for TI ThunderLAN based ethernet PCI adapters");
211 MODULE_LICENSE("GPL");
214 /* Define this to enable Link beat monitoring */
217 /* Turn on debugging. See Documentation/networking/tlan.txt for details */
219 module_param(debug, int, 0);
220 MODULE_PARM_DESC(debug, "ThunderLAN debug mask");
222 static const char tlan_signature[] = "TLAN";
223 static const char tlan_banner[] = "ThunderLAN driver v1.17\n";
224 static int tlan_have_pci;
225 static int tlan_have_eisa;
227 static const char * const media[] = {
228 "10BaseT-HD", "10BaseT-FD", "100baseTx-HD",
229 "100BaseTx-FD", "100BaseT4", NULL
232 static struct board {
233 const char *device_label;
237 { "Compaq Netelligent 10 T PCI UTP", TLAN_ADAPTER_ACTIVITY_LED, 0x83 },
238 { "Compaq Netelligent 10/100 TX PCI UTP",
239 TLAN_ADAPTER_ACTIVITY_LED, 0x83 },
240 { "Compaq Integrated NetFlex-3/P", TLAN_ADAPTER_NONE, 0x83 },
241 { "Compaq NetFlex-3/P",
242 TLAN_ADAPTER_UNMANAGED_PHY | TLAN_ADAPTER_BIT_RATE_PHY, 0x83 },
243 { "Compaq NetFlex-3/P", TLAN_ADAPTER_NONE, 0x83 },
244 { "Compaq Netelligent Integrated 10/100 TX UTP",
245 TLAN_ADAPTER_ACTIVITY_LED, 0x83 },
246 { "Compaq Netelligent Dual 10/100 TX PCI UTP",
247 TLAN_ADAPTER_NONE, 0x83 },
248 { "Compaq Netelligent 10/100 TX Embedded UTP",
249 TLAN_ADAPTER_NONE, 0x83 },
250 { "Olicom OC-2183/2185", TLAN_ADAPTER_USE_INTERN_10, 0x83 },
251 { "Olicom OC-2325", TLAN_ADAPTER_UNMANAGED_PHY, 0xf8 },
252 { "Olicom OC-2326", TLAN_ADAPTER_USE_INTERN_10, 0xf8 },
253 { "Compaq Netelligent 10/100 TX UTP", TLAN_ADAPTER_ACTIVITY_LED, 0x83 },
254 { "Compaq Netelligent 10 T/2 PCI UTP/coax", TLAN_ADAPTER_NONE, 0x83 },
255 { "Compaq NetFlex-3/E",
256 TLAN_ADAPTER_ACTIVITY_LED | /* EISA card */
257 TLAN_ADAPTER_UNMANAGED_PHY | TLAN_ADAPTER_BIT_RATE_PHY, 0x83 },
258 { "Compaq NetFlex-3/E",
259 TLAN_ADAPTER_ACTIVITY_LED, 0x83 }, /* EISA card */
262 static DEFINE_PCI_DEVICE_TABLE(tlan_pci_tbl) = {
263 { PCI_VENDOR_ID_COMPAQ, PCI_DEVICE_ID_COMPAQ_NETEL10,
264 PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0 },
265 { PCI_VENDOR_ID_COMPAQ, PCI_DEVICE_ID_COMPAQ_NETEL100,
266 PCI_ANY_ID, PCI_ANY_ID, 0, 0, 1 },
267 { PCI_VENDOR_ID_COMPAQ, PCI_DEVICE_ID_COMPAQ_NETFLEX3I,
268 PCI_ANY_ID, PCI_ANY_ID, 0, 0, 2 },
269 { PCI_VENDOR_ID_COMPAQ, PCI_DEVICE_ID_COMPAQ_THUNDER,
270 PCI_ANY_ID, PCI_ANY_ID, 0, 0, 3 },
271 { PCI_VENDOR_ID_COMPAQ, PCI_DEVICE_ID_COMPAQ_NETFLEX3B,
272 PCI_ANY_ID, PCI_ANY_ID, 0, 0, 4 },
273 { PCI_VENDOR_ID_COMPAQ, PCI_DEVICE_ID_COMPAQ_NETEL100PI,
274 PCI_ANY_ID, PCI_ANY_ID, 0, 0, 5 },
275 { PCI_VENDOR_ID_COMPAQ, PCI_DEVICE_ID_COMPAQ_NETEL100D,
276 PCI_ANY_ID, PCI_ANY_ID, 0, 0, 6 },
277 { PCI_VENDOR_ID_COMPAQ, PCI_DEVICE_ID_COMPAQ_NETEL100I,
278 PCI_ANY_ID, PCI_ANY_ID, 0, 0, 7 },
279 { PCI_VENDOR_ID_OLICOM, PCI_DEVICE_ID_OLICOM_OC2183,
280 PCI_ANY_ID, PCI_ANY_ID, 0, 0, 8 },
281 { PCI_VENDOR_ID_OLICOM, PCI_DEVICE_ID_OLICOM_OC2325,
282 PCI_ANY_ID, PCI_ANY_ID, 0, 0, 9 },
283 { PCI_VENDOR_ID_OLICOM, PCI_DEVICE_ID_OLICOM_OC2326,
284 PCI_ANY_ID, PCI_ANY_ID, 0, 0, 10 },
285 { PCI_VENDOR_ID_COMPAQ, PCI_DEVICE_ID_NETELLIGENT_10_100_WS_5100,
286 PCI_ANY_ID, PCI_ANY_ID, 0, 0, 11 },
287 { PCI_VENDOR_ID_COMPAQ, PCI_DEVICE_ID_NETELLIGENT_10_T2,
288 PCI_ANY_ID, PCI_ANY_ID, 0, 0, 12 },
291 MODULE_DEVICE_TABLE(pci, tlan_pci_tbl);
293 static void tlan_eisa_probe(void);
294 static void tlan_eisa_cleanup(void);
295 static int tlan_init(struct net_device *);
296 static int tlan_open(struct net_device *dev);
297 static netdev_tx_t tlan_start_tx(struct sk_buff *, struct net_device *);
298 static irqreturn_t tlan_handle_interrupt(int, void *);
299 static int tlan_close(struct net_device *);
300 static struct net_device_stats *tlan_get_stats(struct net_device *);
301 static void tlan_set_multicast_list(struct net_device *);
302 static int tlan_ioctl(struct net_device *dev, struct ifreq *rq, int cmd);
303 static int tlan_probe1(struct pci_dev *pdev, long ioaddr,
304 int irq, int rev, const struct pci_device_id *ent);
305 static void tlan_tx_timeout(struct net_device *dev);
306 static void tlan_tx_timeout_work(struct work_struct *work);
307 static int tlan_init_one(struct pci_dev *pdev,
308 const struct pci_device_id *ent);
310 static u32 tlan_handle_tx_eof(struct net_device *, u16);
311 static u32 tlan_handle_stat_overflow(struct net_device *, u16);
312 static u32 tlan_handle_rx_eof(struct net_device *, u16);
313 static u32 tlan_handle_dummy(struct net_device *, u16);
314 static u32 tlan_handle_tx_eoc(struct net_device *, u16);
315 static u32 tlan_handle_status_check(struct net_device *, u16);
316 static u32 tlan_handle_rx_eoc(struct net_device *, u16);
318 static void tlan_timer(unsigned long);
320 static void tlan_reset_lists(struct net_device *);
321 static void tlan_free_lists(struct net_device *);
322 static void tlan_print_dio(u16);
323 static void tlan_print_list(struct tlan_list *, char *, int);
324 static void tlan_read_and_clear_stats(struct net_device *, int);
325 static void tlan_reset_adapter(struct net_device *);
326 static void tlan_finish_reset(struct net_device *);
327 static void tlan_set_mac(struct net_device *, int areg, char *mac);
329 static void tlan_phy_print(struct net_device *);
330 static void tlan_phy_detect(struct net_device *);
331 static void tlan_phy_power_down(struct net_device *);
332 static void tlan_phy_power_up(struct net_device *);
333 static void tlan_phy_reset(struct net_device *);
334 static void tlan_phy_start_link(struct net_device *);
335 static void tlan_phy_finish_auto_neg(struct net_device *);
337 static void tlan_phy_monitor(struct net_device *);
341 static int tlan_phy_nop(struct net_device *);
342 static int tlan_phy_internal_check(struct net_device *);
343 static int tlan_phy_internal_service(struct net_device *);
344 static int tlan_phy_dp83840a_check(struct net_device *);
347 static bool tlan_mii_read_reg(struct net_device *, u16, u16, u16 *);
348 static void tlan_mii_send_data(u16, u32, unsigned);
349 static void tlan_mii_sync(u16);
350 static void tlan_mii_write_reg(struct net_device *, u16, u16, u16);
352 static void tlan_ee_send_start(u16);
353 static int tlan_ee_send_byte(u16, u8, int);
354 static void tlan_ee_receive_byte(u16, u8 *, int);
355 static int tlan_ee_read_byte(struct net_device *, u8, u8 *);
359 tlan_store_skb(struct tlan_list *tag, struct sk_buff *skb)
361 unsigned long addr = (unsigned long)skb;
362 tag->buffer[9].address = addr;
363 tag->buffer[8].address = upper_32_bits(addr);
366 static inline struct sk_buff *
367 tlan_get_skb(const struct tlan_list *tag)
371 addr = tag->buffer[9].address;
372 addr |= (tag->buffer[8].address << 16) << 16;
373 return (struct sk_buff *) addr;
377 (*tlan_int_vector[TLAN_INT_NUMBER_OF_INTS])(struct net_device *, u16) = {
380 tlan_handle_stat_overflow,
384 tlan_handle_status_check,
389 tlan_set_timer(struct net_device *dev, u32 ticks, u32 type)
391 struct tlan_priv *priv = netdev_priv(dev);
392 unsigned long flags = 0;
395 spin_lock_irqsave(&priv->lock, flags);
396 if (priv->timer.function != NULL &&
397 priv->timer_type != TLAN_TIMER_ACTIVITY) {
399 spin_unlock_irqrestore(&priv->lock, flags);
402 priv->timer.function = tlan_timer;
404 spin_unlock_irqrestore(&priv->lock, flags);
406 priv->timer.data = (unsigned long) dev;
407 priv->timer_set_at = jiffies;
408 priv->timer_type = type;
409 mod_timer(&priv->timer, jiffies + ticks);
414 /*****************************************************************************
415 ******************************************************************************
417 ThunderLAN driver primary functions
419 these functions are more or less common to all linux network drivers.
421 ******************************************************************************
422 *****************************************************************************/
428 /***************************************************************
436 * Goes through the TLanDevices list and frees the device
437 * structs and memory associated with each device (lists
438 * and buffers). It also ureserves the IO port regions
439 * associated with this device.
441 **************************************************************/
444 static void __devexit tlan_remove_one(struct pci_dev *pdev)
446 struct net_device *dev = pci_get_drvdata(pdev);
447 struct tlan_priv *priv = netdev_priv(dev);
449 unregister_netdev(dev);
451 if (priv->dma_storage) {
452 pci_free_consistent(priv->pci_dev,
453 priv->dma_size, priv->dma_storage,
454 priv->dma_storage_dma);
458 pci_release_regions(pdev);
463 pci_set_drvdata(pdev, NULL);
466 static void tlan_start(struct net_device *dev)
468 tlan_reset_lists(dev);
469 /* NOTE: It might not be necessary to read the stats before a
470 reset if you don't care what the values are.
472 tlan_read_and_clear_stats(dev, TLAN_IGNORE);
473 tlan_reset_adapter(dev);
474 netif_wake_queue(dev);
477 static void tlan_stop(struct net_device *dev)
479 struct tlan_priv *priv = netdev_priv(dev);
481 tlan_read_and_clear_stats(dev, TLAN_RECORD);
482 outl(TLAN_HC_AD_RST, dev->base_addr + TLAN_HOST_CMD);
483 /* Reset and power down phy */
484 tlan_reset_adapter(dev);
485 if (priv->timer.function != NULL) {
486 del_timer_sync(&priv->timer);
487 priv->timer.function = NULL;
493 static int tlan_suspend(struct pci_dev *pdev, pm_message_t state)
495 struct net_device *dev = pci_get_drvdata(pdev);
497 if (netif_running(dev))
500 netif_device_detach(dev);
501 pci_save_state(pdev);
502 pci_disable_device(pdev);
503 pci_wake_from_d3(pdev, false);
504 pci_set_power_state(pdev, PCI_D3hot);
509 static int tlan_resume(struct pci_dev *pdev)
511 struct net_device *dev = pci_get_drvdata(pdev);
513 pci_set_power_state(pdev, PCI_D0);
514 pci_restore_state(pdev);
515 pci_enable_wake(pdev, 0, 0);
516 netif_device_attach(dev);
518 if (netif_running(dev))
524 #else /* CONFIG_PM */
526 #define tlan_suspend NULL
527 #define tlan_resume NULL
529 #endif /* CONFIG_PM */
532 static struct pci_driver tlan_driver = {
534 .id_table = tlan_pci_tbl,
535 .probe = tlan_init_one,
536 .remove = __devexit_p(tlan_remove_one),
537 .suspend = tlan_suspend,
538 .resume = tlan_resume,
541 static int __init tlan_probe(void)
545 printk(KERN_INFO "%s", tlan_banner);
547 TLAN_DBG(TLAN_DEBUG_PROBE, "Starting PCI Probe....\n");
549 /* Use new style PCI probing. Now the kernel will
550 do most of this for us */
551 rc = pci_register_driver(&tlan_driver);
554 printk(KERN_ERR "TLAN: Could not register pci driver.\n");
555 goto err_out_pci_free;
558 TLAN_DBG(TLAN_DEBUG_PROBE, "Starting EISA Probe....\n");
561 printk(KERN_INFO "TLAN: %d device%s installed, PCI: %d EISA: %d\n",
562 tlan_devices_installed, tlan_devices_installed == 1 ? "" : "s",
563 tlan_have_pci, tlan_have_eisa);
565 if (tlan_devices_installed == 0) {
567 goto err_out_pci_unreg;
572 pci_unregister_driver(&tlan_driver);
578 static int __devinit tlan_init_one(struct pci_dev *pdev,
579 const struct pci_device_id *ent)
581 return tlan_probe1(pdev, -1, -1, 0, ent);
586 ***************************************************************
590 * 0 on success, error code on error
594 * The name is lower case to fit in with all the rest of
595 * the netcard_probe names. This function looks for
596 * another TLan based adapter, setting it up with the
597 * allocated device struct if one is found.
598 * tlan_probe has been ported to the new net API and
599 * now allocates its own device structure. This function
600 * is also used by modules.
602 **************************************************************/
604 static int __devinit tlan_probe1(struct pci_dev *pdev,
605 long ioaddr, int irq, int rev,
606 const struct pci_device_id *ent)
609 struct net_device *dev;
610 struct tlan_priv *priv;
612 int reg, rc = -ENODEV;
616 rc = pci_enable_device(pdev);
620 rc = pci_request_regions(pdev, tlan_signature);
622 printk(KERN_ERR "TLAN: Could not reserve IO regions\n");
626 #endif /* CONFIG_PCI */
628 dev = alloc_etherdev(sizeof(struct tlan_priv));
630 printk(KERN_ERR "TLAN: Could not allocate memory for device.\n");
632 goto err_out_regions;
634 SET_NETDEV_DEV(dev, &pdev->dev);
636 priv = netdev_priv(dev);
638 priv->pci_dev = pdev;
641 /* Is this a PCI device? */
645 priv->adapter = &board_info[ent->driver_data];
647 rc = pci_set_dma_mask(pdev, DMA_BIT_MASK(32));
650 "TLAN: No suitable PCI mapping available.\n");
651 goto err_out_free_dev;
654 for (reg = 0; reg <= 5; reg++) {
655 if (pci_resource_flags(pdev, reg) & IORESOURCE_IO) {
656 pci_io_base = pci_resource_start(pdev, reg);
657 TLAN_DBG(TLAN_DEBUG_GNRL,
658 "IO mapping is available at %x.\n",
664 printk(KERN_ERR "TLAN: No IO mappings available\n");
666 goto err_out_free_dev;
669 dev->base_addr = pci_io_base;
670 dev->irq = pdev->irq;
671 priv->adapter_rev = pdev->revision;
672 pci_set_master(pdev);
673 pci_set_drvdata(pdev, dev);
675 } else { /* EISA card */
676 /* This is a hack. We need to know which board structure
677 * is suited for this adapter */
678 device_id = inw(ioaddr + EISA_ID2);
680 if (device_id == 0x20F1) {
681 priv->adapter = &board_info[13]; /* NetFlex-3/E */
682 priv->adapter_rev = 23; /* TLAN 2.3 */
684 priv->adapter = &board_info[14];
685 priv->adapter_rev = 10; /* TLAN 1.0 */
687 dev->base_addr = ioaddr;
691 /* Kernel parameters */
692 if (dev->mem_start) {
693 priv->aui = dev->mem_start & 0x01;
694 priv->duplex = ((dev->mem_start & 0x06) == 0x06) ? 0
695 : (dev->mem_start & 0x06) >> 1;
696 priv->speed = ((dev->mem_start & 0x18) == 0x18) ? 0
697 : (dev->mem_start & 0x18) >> 3;
699 if (priv->speed == 0x1)
700 priv->speed = TLAN_SPEED_10;
701 else if (priv->speed == 0x2)
702 priv->speed = TLAN_SPEED_100;
704 debug = priv->debug = dev->mem_end;
706 priv->aui = aui[boards_found];
707 priv->speed = speed[boards_found];
708 priv->duplex = duplex[boards_found];
712 /* This will be used when we get an adapter error from
713 * within our irq handler */
714 INIT_WORK(&priv->tlan_tqueue, tlan_tx_timeout_work);
716 spin_lock_init(&priv->lock);
720 printk(KERN_ERR "TLAN: Could not set up device.\n");
721 goto err_out_free_dev;
724 rc = register_netdev(dev);
726 printk(KERN_ERR "TLAN: Could not register device.\n");
731 tlan_devices_installed++;
734 /* pdev is NULL if this is an EISA device */
738 priv->next_device = tlan_eisa_devices;
739 tlan_eisa_devices = dev;
743 printk(KERN_INFO "TLAN: %s irq=%2d, io=%04x, %s, Rev. %d\n",
746 (int) dev->base_addr,
747 priv->adapter->device_label,
752 pci_free_consistent(priv->pci_dev, priv->dma_size, priv->dma_storage,
753 priv->dma_storage_dma);
759 pci_release_regions(pdev);
763 pci_disable_device(pdev);
768 static void tlan_eisa_cleanup(void)
770 struct net_device *dev;
771 struct tlan_priv *priv;
773 while (tlan_have_eisa) {
774 dev = tlan_eisa_devices;
775 priv = netdev_priv(dev);
776 if (priv->dma_storage) {
777 pci_free_consistent(priv->pci_dev, priv->dma_size,
779 priv->dma_storage_dma);
781 release_region(dev->base_addr, 0x10);
782 unregister_netdev(dev);
783 tlan_eisa_devices = priv->next_device;
790 static void __exit tlan_exit(void)
792 pci_unregister_driver(&tlan_driver);
800 /* Module loading/unloading */
801 module_init(tlan_probe);
802 module_exit(tlan_exit);
806 /**************************************************************
809 * Returns: 0 on success, 1 otherwise
814 * This functions probes for EISA devices and calls
815 * TLan_probe1 when one is found.
817 *************************************************************/
819 static void __init tlan_eisa_probe(void)
827 TLAN_DBG(TLAN_DEBUG_PROBE, "No EISA bus present\n");
831 /* Loop through all slots of the EISA bus */
832 for (ioaddr = 0x1000; ioaddr < 0x9000; ioaddr += 0x1000) {
834 TLAN_DBG(TLAN_DEBUG_PROBE, "EISA_ID 0x%4x: 0x%4x\n",
835 (int) ioaddr + 0xc80, inw(ioaddr + EISA_ID));
836 TLAN_DBG(TLAN_DEBUG_PROBE, "EISA_ID 0x%4x: 0x%4x\n",
837 (int) ioaddr + 0xc82, inw(ioaddr + EISA_ID2));
840 TLAN_DBG(TLAN_DEBUG_PROBE,
841 "Probing for EISA adapter at IO: 0x%4x : ",
843 if (request_region(ioaddr, 0x10, tlan_signature) == NULL)
846 if (inw(ioaddr + EISA_ID) != 0x110E) {
847 release_region(ioaddr, 0x10);
851 device_id = inw(ioaddr + EISA_ID2);
852 if (device_id != 0x20F1 && device_id != 0x40F1) {
853 release_region(ioaddr, 0x10);
857 /* check if adapter is enabled */
858 if (inb(ioaddr + EISA_CR) != 0x1) {
859 release_region(ioaddr, 0x10);
864 printk(KERN_INFO "Found one\n");
867 /* Get irq from board */
868 switch (inb(ioaddr + 0xcc0)) {
886 /* Setup the newly found eisa adapter */
887 rc = tlan_probe1(NULL, ioaddr, irq,
893 printk(KERN_INFO "None found\n");
898 printk(KERN_INFO "Card found but it is not enabled, skipping\n");
905 #ifdef CONFIG_NET_POLL_CONTROLLER
906 static void tlan_poll(struct net_device *dev)
908 disable_irq(dev->irq);
909 tlan_handle_interrupt(dev->irq, dev);
910 enable_irq(dev->irq);
914 static const struct net_device_ops tlan_netdev_ops = {
915 .ndo_open = tlan_open,
916 .ndo_stop = tlan_close,
917 .ndo_start_xmit = tlan_start_tx,
918 .ndo_tx_timeout = tlan_tx_timeout,
919 .ndo_get_stats = tlan_get_stats,
920 .ndo_set_multicast_list = tlan_set_multicast_list,
921 .ndo_do_ioctl = tlan_ioctl,
922 .ndo_change_mtu = eth_change_mtu,
923 .ndo_set_mac_address = eth_mac_addr,
924 .ndo_validate_addr = eth_validate_addr,
925 #ifdef CONFIG_NET_POLL_CONTROLLER
926 .ndo_poll_controller = tlan_poll,
932 /***************************************************************
936 * 0 on success, error code otherwise.
938 * dev The structure of the device to be
941 * This function completes the initialization of the
942 * device structure and driver. It reserves the IO
943 * addresses, allocates memory for the lists and bounce
944 * buffers, retrieves the MAC address from the eeprom
945 * and assignes the device's methods.
947 **************************************************************/
949 static int tlan_init(struct net_device *dev)
954 struct tlan_priv *priv;
956 priv = netdev_priv(dev);
958 dma_size = (TLAN_NUM_RX_LISTS + TLAN_NUM_TX_LISTS)
959 * (sizeof(struct tlan_list));
960 priv->dma_storage = pci_alloc_consistent(priv->pci_dev,
962 &priv->dma_storage_dma);
963 priv->dma_size = dma_size;
965 if (priv->dma_storage == NULL) {
967 "TLAN: Could not allocate lists and buffers for %s.\n",
971 memset(priv->dma_storage, 0, dma_size);
972 priv->rx_list = (struct tlan_list *)
973 ALIGN((unsigned long)priv->dma_storage, 8);
974 priv->rx_list_dma = ALIGN(priv->dma_storage_dma, 8);
975 priv->tx_list = priv->rx_list + TLAN_NUM_RX_LISTS;
977 priv->rx_list_dma + sizeof(struct tlan_list)*TLAN_NUM_RX_LISTS;
980 for (i = 0; i < 6 ; i++)
981 err |= tlan_ee_read_byte(dev,
982 (u8) priv->adapter->addr_ofs + i,
983 (u8 *) &dev->dev_addr[i]);
985 printk(KERN_ERR "TLAN: %s: Error reading MAC from eeprom: %d\n",
991 netif_carrier_off(dev);
994 dev->netdev_ops = &tlan_netdev_ops;
995 dev->watchdog_timeo = TX_TIMEOUT;
1004 /***************************************************************
1008 * 0 on success, error code otherwise.
1010 * dev Structure of device to be opened.
1012 * This routine puts the driver and TLAN adapter in a
1013 * state where it is ready to send and receive packets.
1014 * It allocates the IRQ, resets and brings the adapter
1015 * out of reset, and allows interrupts. It also delays
1016 * the startup for autonegotiation or sends a Rx GO
1017 * command to the adapter, as appropriate.
1019 **************************************************************/
1021 static int tlan_open(struct net_device *dev)
1023 struct tlan_priv *priv = netdev_priv(dev);
1026 priv->tlan_rev = tlan_dio_read8(dev->base_addr, TLAN_DEF_REVISION);
1027 err = request_irq(dev->irq, tlan_handle_interrupt, IRQF_SHARED,
1031 pr_err("TLAN: Cannot open %s because IRQ %d is already in use.\n",
1032 dev->name, dev->irq);
1036 init_timer(&priv->timer);
1040 TLAN_DBG(TLAN_DEBUG_GNRL, "%s: Opened. TLAN Chip Rev: %x\n",
1041 dev->name, priv->tlan_rev);
1049 /**************************************************************
1053 * 0 on success, error code otherwise
1055 * dev structure of device to receive ioctl.
1057 * rq ifreq structure to hold userspace data.
1059 * cmd ioctl command.
1062 *************************************************************/
1064 static int tlan_ioctl(struct net_device *dev, struct ifreq *rq, int cmd)
1066 struct tlan_priv *priv = netdev_priv(dev);
1067 struct mii_ioctl_data *data = if_mii(rq);
1068 u32 phy = priv->phy[priv->phy_num];
1070 if (!priv->phy_online)
1074 case SIOCGMIIPHY: /* get address of MII PHY in use. */
1078 case SIOCGMIIREG: /* read MII PHY register. */
1079 tlan_mii_read_reg(dev, data->phy_id & 0x1f,
1080 data->reg_num & 0x1f, &data->val_out);
1084 case SIOCSMIIREG: /* write MII PHY register. */
1085 tlan_mii_write_reg(dev, data->phy_id & 0x1f,
1086 data->reg_num & 0x1f, data->val_in);
1094 /***************************************************************
1100 * dev structure of device which timed out
1103 **************************************************************/
1105 static void tlan_tx_timeout(struct net_device *dev)
1108 TLAN_DBG(TLAN_DEBUG_GNRL, "%s: Transmit timed out.\n", dev->name);
1110 /* Ok so we timed out, lets see what we can do about it...*/
1111 tlan_free_lists(dev);
1112 tlan_reset_lists(dev);
1113 tlan_read_and_clear_stats(dev, TLAN_IGNORE);
1114 tlan_reset_adapter(dev);
1115 dev->trans_start = jiffies; /* prevent tx timeout */
1116 netif_wake_queue(dev);
1121 /***************************************************************
1122 * tlan_tx_timeout_work
1127 * work work item of device which timed out
1129 **************************************************************/
1131 static void tlan_tx_timeout_work(struct work_struct *work)
1133 struct tlan_priv *priv =
1134 container_of(work, struct tlan_priv, tlan_tqueue);
1136 tlan_tx_timeout(priv->dev);
1141 /***************************************************************
1145 * 0 on success, non-zero on failure.
1147 * skb A pointer to the sk_buff containing the
1149 * dev The device to send the data on.
1151 * This function adds a frame to the Tx list to be sent
1152 * ASAP. First it verifies that the adapter is ready and
1153 * there is room in the queue. Then it sets up the next
1154 * available list, copies the frame to the corresponding
1155 * buffer. If the adapter Tx channel is idle, it gives
1156 * the adapter a Tx Go command on the list, otherwise it
1157 * sets the forward address of the previous list to point
1158 * to this one. Then it frees the sk_buff.
1160 **************************************************************/
1162 static netdev_tx_t tlan_start_tx(struct sk_buff *skb, struct net_device *dev)
1164 struct tlan_priv *priv = netdev_priv(dev);
1165 dma_addr_t tail_list_phys;
1166 struct tlan_list *tail_list;
1167 unsigned long flags;
1170 if (!priv->phy_online) {
1171 TLAN_DBG(TLAN_DEBUG_TX, "TRANSMIT: %s PHY is not ready\n",
1173 dev_kfree_skb_any(skb);
1174 return NETDEV_TX_OK;
1177 if (skb_padto(skb, TLAN_MIN_FRAME_SIZE))
1178 return NETDEV_TX_OK;
1179 txlen = max(skb->len, (unsigned int)TLAN_MIN_FRAME_SIZE);
1181 tail_list = priv->tx_list + priv->tx_tail;
1183 priv->tx_list_dma + sizeof(struct tlan_list)*priv->tx_tail;
1185 if (tail_list->c_stat != TLAN_CSTAT_UNUSED) {
1186 TLAN_DBG(TLAN_DEBUG_TX,
1187 "TRANSMIT: %s is busy (Head=%d Tail=%d)\n",
1188 dev->name, priv->tx_head, priv->tx_tail);
1189 netif_stop_queue(dev);
1190 priv->tx_busy_count++;
1191 return NETDEV_TX_BUSY;
1194 tail_list->forward = 0;
1196 tail_list->buffer[0].address = pci_map_single(priv->pci_dev,
1199 tlan_store_skb(tail_list, skb);
1201 tail_list->frame_size = (u16) txlen;
1202 tail_list->buffer[0].count = TLAN_LAST_BUFFER | (u32) txlen;
1203 tail_list->buffer[1].count = 0;
1204 tail_list->buffer[1].address = 0;
1206 spin_lock_irqsave(&priv->lock, flags);
1207 tail_list->c_stat = TLAN_CSTAT_READY;
1208 if (!priv->tx_in_progress) {
1209 priv->tx_in_progress = 1;
1210 TLAN_DBG(TLAN_DEBUG_TX,
1211 "TRANSMIT: Starting TX on buffer %d\n",
1213 outl(tail_list_phys, dev->base_addr + TLAN_CH_PARM);
1214 outl(TLAN_HC_GO, dev->base_addr + TLAN_HOST_CMD);
1216 TLAN_DBG(TLAN_DEBUG_TX,
1217 "TRANSMIT: Adding buffer %d to TX channel\n",
1219 if (priv->tx_tail == 0) {
1220 (priv->tx_list + (TLAN_NUM_TX_LISTS - 1))->forward
1223 (priv->tx_list + (priv->tx_tail - 1))->forward
1227 spin_unlock_irqrestore(&priv->lock, flags);
1229 CIRC_INC(priv->tx_tail, TLAN_NUM_TX_LISTS);
1231 return NETDEV_TX_OK;
1238 /***************************************************************
1239 * tlan_handle_interrupt
1244 * irq The line on which the interrupt
1246 * dev_id A pointer to the device assigned to
1249 * This function handles an interrupt generated by its
1250 * assigned TLAN adapter. The function deactivates
1251 * interrupts on its adapter, records the type of
1252 * interrupt, executes the appropriate subhandler, and
1253 * acknowdges the interrupt to the adapter (thus
1254 * re-enabling adapter interrupts.
1256 **************************************************************/
1258 static irqreturn_t tlan_handle_interrupt(int irq, void *dev_id)
1260 struct net_device *dev = dev_id;
1261 struct tlan_priv *priv = netdev_priv(dev);
1265 spin_lock(&priv->lock);
1267 host_int = inw(dev->base_addr + TLAN_HOST_INT);
1268 type = (host_int & TLAN_HI_IT_MASK) >> 2;
1273 outw(host_int, dev->base_addr + TLAN_HOST_INT);
1274 ack = tlan_int_vector[type](dev, host_int);
1277 host_cmd = TLAN_HC_ACK | ack | (type << 18);
1278 outl(host_cmd, dev->base_addr + TLAN_HOST_CMD);
1282 spin_unlock(&priv->lock);
1284 return IRQ_RETVAL(type);
1290 /***************************************************************
1296 * dev The device structure of the device to
1299 * This function shuts down the adapter. It records any
1300 * stats, puts the adapter into reset state, deactivates
1301 * its time as needed, and frees the irq it is using.
1303 **************************************************************/
1305 static int tlan_close(struct net_device *dev)
1307 struct tlan_priv *priv = netdev_priv(dev);
1309 priv->neg_be_verbose = 0;
1312 free_irq(dev->irq, dev);
1313 tlan_free_lists(dev);
1314 TLAN_DBG(TLAN_DEBUG_GNRL, "Device %s closed.\n", dev->name);
1323 /***************************************************************
1327 * A pointer to the device's statistics structure.
1329 * dev The device structure to return the
1332 * This function updates the devices statistics by reading
1333 * the TLAN chip's onboard registers. Then it returns the
1334 * address of the statistics structure.
1336 **************************************************************/
1338 static struct net_device_stats *tlan_get_stats(struct net_device *dev)
1340 struct tlan_priv *priv = netdev_priv(dev);
1343 /* Should only read stats if open ? */
1344 tlan_read_and_clear_stats(dev, TLAN_RECORD);
1346 TLAN_DBG(TLAN_DEBUG_RX, "RECEIVE: %s EOC count = %d\n", dev->name,
1347 priv->rx_eoc_count);
1348 TLAN_DBG(TLAN_DEBUG_TX, "TRANSMIT: %s Busy count = %d\n", dev->name,
1349 priv->tx_busy_count);
1350 if (debug & TLAN_DEBUG_GNRL) {
1351 tlan_print_dio(dev->base_addr);
1352 tlan_phy_print(dev);
1354 if (debug & TLAN_DEBUG_LIST) {
1355 for (i = 0; i < TLAN_NUM_RX_LISTS; i++)
1356 tlan_print_list(priv->rx_list + i, "RX", i);
1357 for (i = 0; i < TLAN_NUM_TX_LISTS; i++)
1358 tlan_print_list(priv->tx_list + i, "TX", i);
1368 /***************************************************************
1369 * tlan_set_multicast_list
1374 * dev The device structure to set the
1375 * multicast list for.
1377 * This function sets the TLAN adaptor to various receive
1378 * modes. If the IFF_PROMISC flag is set, promiscuous
1379 * mode is acitviated. Otherwise, promiscuous mode is
1380 * turned off. If the IFF_ALLMULTI flag is set, then
1381 * the hash table is set to receive all group addresses.
1382 * Otherwise, the first three multicast addresses are
1383 * stored in AREG_1-3, and the rest are selected via the
1384 * hash table, as necessary.
1386 **************************************************************/
1388 static void tlan_set_multicast_list(struct net_device *dev)
1390 struct netdev_hw_addr *ha;
1397 if (dev->flags & IFF_PROMISC) {
1398 tmp = tlan_dio_read8(dev->base_addr, TLAN_NET_CMD);
1399 tlan_dio_write8(dev->base_addr,
1400 TLAN_NET_CMD, tmp | TLAN_NET_CMD_CAF);
1402 tmp = tlan_dio_read8(dev->base_addr, TLAN_NET_CMD);
1403 tlan_dio_write8(dev->base_addr,
1404 TLAN_NET_CMD, tmp & ~TLAN_NET_CMD_CAF);
1405 if (dev->flags & IFF_ALLMULTI) {
1406 for (i = 0; i < 3; i++)
1407 tlan_set_mac(dev, i + 1, NULL);
1408 tlan_dio_write32(dev->base_addr, TLAN_HASH_1,
1410 tlan_dio_write32(dev->base_addr, TLAN_HASH_2,
1414 netdev_for_each_mc_addr(ha, dev) {
1416 tlan_set_mac(dev, i + 1,
1417 (char *) &ha->addr);
1420 tlan_hash_func((u8 *)&ha->addr);
1422 hash1 |= (1 << offset);
1424 hash2 |= (1 << (offset - 32));
1429 tlan_set_mac(dev, i + 1, NULL);
1430 tlan_dio_write32(dev->base_addr, TLAN_HASH_1, hash1);
1431 tlan_dio_write32(dev->base_addr, TLAN_HASH_2, hash2);
1439 /*****************************************************************************
1440 ******************************************************************************
1442 ThunderLAN driver interrupt vectors and table
1444 please see chap. 4, "Interrupt Handling" of the "ThunderLAN
1445 Programmer's Guide" for more informations on handling interrupts
1446 generated by TLAN based adapters.
1448 ******************************************************************************
1449 *****************************************************************************/
1454 /***************************************************************
1455 * tlan_handle_tx_eof
1460 * dev Device assigned the IRQ that was
1462 * host_int The contents of the HOST_INT
1465 * This function handles Tx EOF interrupts which are raised
1466 * by the adapter when it has completed sending the
1467 * contents of a buffer. If detemines which list/buffer
1468 * was completed and resets it. If the buffer was the last
1469 * in the channel (EOC), then the function checks to see if
1470 * another buffer is ready to send, and if so, sends a Tx
1471 * Go command. Finally, the driver activates/continues the
1474 **************************************************************/
1476 static u32 tlan_handle_tx_eof(struct net_device *dev, u16 host_int)
1478 struct tlan_priv *priv = netdev_priv(dev);
1480 struct tlan_list *head_list;
1481 dma_addr_t head_list_phys;
1485 TLAN_DBG(TLAN_DEBUG_TX,
1486 "TRANSMIT: Handling TX EOF (Head=%d Tail=%d)\n",
1487 priv->tx_head, priv->tx_tail);
1488 head_list = priv->tx_list + priv->tx_head;
1490 while (((tmp_c_stat = head_list->c_stat) & TLAN_CSTAT_FRM_CMP)
1492 struct sk_buff *skb = tlan_get_skb(head_list);
1495 pci_unmap_single(priv->pci_dev, head_list->buffer[0].address,
1497 (unsigned int)TLAN_MIN_FRAME_SIZE),
1499 dev_kfree_skb_any(skb);
1500 head_list->buffer[8].address = 0;
1501 head_list->buffer[9].address = 0;
1503 if (tmp_c_stat & TLAN_CSTAT_EOC)
1506 dev->stats.tx_bytes += head_list->frame_size;
1508 head_list->c_stat = TLAN_CSTAT_UNUSED;
1509 netif_start_queue(dev);
1510 CIRC_INC(priv->tx_head, TLAN_NUM_TX_LISTS);
1511 head_list = priv->tx_list + priv->tx_head;
1516 "TLAN: Received interrupt for uncompleted TX frame.\n");
1519 TLAN_DBG(TLAN_DEBUG_TX,
1520 "TRANSMIT: handling TX EOC (Head=%d Tail=%d)\n",
1521 priv->tx_head, priv->tx_tail);
1522 head_list = priv->tx_list + priv->tx_head;
1523 head_list_phys = priv->tx_list_dma
1524 + sizeof(struct tlan_list)*priv->tx_head;
1525 if ((head_list->c_stat & TLAN_CSTAT_READY)
1526 == TLAN_CSTAT_READY) {
1527 outl(head_list_phys, dev->base_addr + TLAN_CH_PARM);
1530 priv->tx_in_progress = 0;
1534 if (priv->adapter->flags & TLAN_ADAPTER_ACTIVITY_LED) {
1535 tlan_dio_write8(dev->base_addr,
1536 TLAN_LED_REG, TLAN_LED_LINK | TLAN_LED_ACT);
1537 if (priv->timer.function == NULL) {
1538 priv->timer.function = tlan_timer;
1539 priv->timer.data = (unsigned long) dev;
1540 priv->timer.expires = jiffies + TLAN_TIMER_ACT_DELAY;
1541 priv->timer_set_at = jiffies;
1542 priv->timer_type = TLAN_TIMER_ACTIVITY;
1543 add_timer(&priv->timer);
1544 } else if (priv->timer_type == TLAN_TIMER_ACTIVITY) {
1545 priv->timer_set_at = jiffies;
1556 /***************************************************************
1557 * TLan_HandleStatOverflow
1562 * dev Device assigned the IRQ that was
1564 * host_int The contents of the HOST_INT
1567 * This function handles the Statistics Overflow interrupt
1568 * which means that one or more of the TLAN statistics
1569 * registers has reached 1/2 capacity and needs to be read.
1571 **************************************************************/
1573 static u32 tlan_handle_stat_overflow(struct net_device *dev, u16 host_int)
1575 tlan_read_and_clear_stats(dev, TLAN_RECORD);
1584 /***************************************************************
1590 * dev Device assigned the IRQ that was
1592 * host_int The contents of the HOST_INT
1595 * This function handles the Rx EOF interrupt which
1596 * indicates a frame has been received by the adapter from
1597 * the net and the frame has been transferred to memory.
1598 * The function determines the bounce buffer the frame has
1599 * been loaded into, creates a new sk_buff big enough to
1600 * hold the frame, and sends it to protocol stack. It
1601 * then resets the used buffer and appends it to the end
1602 * of the list. If the frame was the last in the Rx
1603 * channel (EOC), the function restarts the receive channel
1604 * by sending an Rx Go command to the adapter. Then it
1605 * activates/continues the activity LED.
1607 **************************************************************/
1609 static u32 tlan_handle_rx_eof(struct net_device *dev, u16 host_int)
1611 struct tlan_priv *priv = netdev_priv(dev);
1614 struct tlan_list *head_list;
1615 struct sk_buff *skb;
1616 struct tlan_list *tail_list;
1618 dma_addr_t head_list_phys;
1620 TLAN_DBG(TLAN_DEBUG_RX, "RECEIVE: handling RX EOF (Head=%d Tail=%d)\n",
1621 priv->rx_head, priv->rx_tail);
1622 head_list = priv->rx_list + priv->rx_head;
1624 priv->rx_list_dma + sizeof(struct tlan_list)*priv->rx_head;
1626 while (((tmp_c_stat = head_list->c_stat) & TLAN_CSTAT_FRM_CMP)
1628 dma_addr_t frame_dma = head_list->buffer[0].address;
1629 u32 frame_size = head_list->frame_size;
1630 struct sk_buff *new_skb;
1633 if (tmp_c_stat & TLAN_CSTAT_EOC)
1636 new_skb = netdev_alloc_skb_ip_align(dev,
1637 TLAN_MAX_FRAME_SIZE + 5);
1639 goto drop_and_reuse;
1641 skb = tlan_get_skb(head_list);
1642 pci_unmap_single(priv->pci_dev, frame_dma,
1643 TLAN_MAX_FRAME_SIZE, PCI_DMA_FROMDEVICE);
1644 skb_put(skb, frame_size);
1646 dev->stats.rx_bytes += frame_size;
1648 skb->protocol = eth_type_trans(skb, dev);
1651 head_list->buffer[0].address =
1652 pci_map_single(priv->pci_dev, new_skb->data,
1653 TLAN_MAX_FRAME_SIZE, PCI_DMA_FROMDEVICE);
1655 tlan_store_skb(head_list, new_skb);
1657 head_list->forward = 0;
1658 head_list->c_stat = 0;
1659 tail_list = priv->rx_list + priv->rx_tail;
1660 tail_list->forward = head_list_phys;
1662 CIRC_INC(priv->rx_head, TLAN_NUM_RX_LISTS);
1663 CIRC_INC(priv->rx_tail, TLAN_NUM_RX_LISTS);
1664 head_list = priv->rx_list + priv->rx_head;
1665 head_list_phys = priv->rx_list_dma
1666 + sizeof(struct tlan_list)*priv->rx_head;
1671 "TLAN: Received interrupt for uncompleted RX frame.\n");
1675 TLAN_DBG(TLAN_DEBUG_RX,
1676 "RECEIVE: handling RX EOC (Head=%d Tail=%d)\n",
1677 priv->rx_head, priv->rx_tail);
1678 head_list = priv->rx_list + priv->rx_head;
1679 head_list_phys = priv->rx_list_dma
1680 + sizeof(struct tlan_list)*priv->rx_head;
1681 outl(head_list_phys, dev->base_addr + TLAN_CH_PARM);
1682 ack |= TLAN_HC_GO | TLAN_HC_RT;
1683 priv->rx_eoc_count++;
1686 if (priv->adapter->flags & TLAN_ADAPTER_ACTIVITY_LED) {
1687 tlan_dio_write8(dev->base_addr,
1688 TLAN_LED_REG, TLAN_LED_LINK | TLAN_LED_ACT);
1689 if (priv->timer.function == NULL) {
1690 priv->timer.function = tlan_timer;
1691 priv->timer.data = (unsigned long) dev;
1692 priv->timer.expires = jiffies + TLAN_TIMER_ACT_DELAY;
1693 priv->timer_set_at = jiffies;
1694 priv->timer_type = TLAN_TIMER_ACTIVITY;
1695 add_timer(&priv->timer);
1696 } else if (priv->timer_type == TLAN_TIMER_ACTIVITY) {
1697 priv->timer_set_at = jiffies;
1708 /***************************************************************
1714 * dev Device assigned the IRQ that was
1716 * host_int The contents of the HOST_INT
1719 * This function handles the Dummy interrupt, which is
1720 * raised whenever a test interrupt is generated by setting
1721 * the Req_Int bit of HOST_CMD to 1.
1723 **************************************************************/
1725 static u32 tlan_handle_dummy(struct net_device *dev, u16 host_int)
1727 pr_info("TLAN: Test interrupt on %s.\n", dev->name);
1735 /***************************************************************
1736 * tlan_handle_tx_eoc
1741 * dev Device assigned the IRQ that was
1743 * host_int The contents of the HOST_INT
1746 * This driver is structured to determine EOC occurrences by
1747 * reading the CSTAT member of the list structure. Tx EOC
1748 * interrupts are disabled via the DIO INTDIS register.
1749 * However, TLAN chips before revision 3.0 didn't have this
1750 * functionality, so process EOC events if this is the
1753 **************************************************************/
1755 static u32 tlan_handle_tx_eoc(struct net_device *dev, u16 host_int)
1757 struct tlan_priv *priv = netdev_priv(dev);
1758 struct tlan_list *head_list;
1759 dma_addr_t head_list_phys;
1763 if (priv->tlan_rev < 0x30) {
1764 TLAN_DBG(TLAN_DEBUG_TX,
1765 "TRANSMIT: handling TX EOC (Head=%d Tail=%d) -- IRQ\n",
1766 priv->tx_head, priv->tx_tail);
1767 head_list = priv->tx_list + priv->tx_head;
1768 head_list_phys = priv->tx_list_dma
1769 + sizeof(struct tlan_list)*priv->tx_head;
1770 if ((head_list->c_stat & TLAN_CSTAT_READY)
1771 == TLAN_CSTAT_READY) {
1772 netif_stop_queue(dev);
1773 outl(head_list_phys, dev->base_addr + TLAN_CH_PARM);
1776 priv->tx_in_progress = 0;
1787 /***************************************************************
1788 * tlan_handle_status_check
1791 * 0 if Adapter check, 1 if Network Status check.
1793 * dev Device assigned the IRQ that was
1795 * host_int The contents of the HOST_INT
1798 * This function handles Adapter Check/Network Status
1799 * interrupts generated by the adapter. It checks the
1800 * vector in the HOST_INT register to determine if it is
1801 * an Adapter Check interrupt. If so, it resets the
1802 * adapter. Otherwise it clears the status registers
1803 * and services the PHY.
1805 **************************************************************/
1807 static u32 tlan_handle_status_check(struct net_device *dev, u16 host_int)
1809 struct tlan_priv *priv = netdev_priv(dev);
1818 if (host_int & TLAN_HI_IV_MASK) {
1819 netif_stop_queue(dev);
1820 error = inl(dev->base_addr + TLAN_CH_PARM);
1821 pr_info("TLAN: %s: Adaptor Error = 0x%x\n", dev->name, error);
1822 tlan_read_and_clear_stats(dev, TLAN_RECORD);
1823 outl(TLAN_HC_AD_RST, dev->base_addr + TLAN_HOST_CMD);
1825 schedule_work(&priv->tlan_tqueue);
1827 netif_wake_queue(dev);
1830 TLAN_DBG(TLAN_DEBUG_GNRL, "%s: Status Check\n", dev->name);
1831 phy = priv->phy[priv->phy_num];
1833 net_sts = tlan_dio_read8(dev->base_addr, TLAN_NET_STS);
1835 tlan_dio_write8(dev->base_addr, TLAN_NET_STS, net_sts);
1836 TLAN_DBG(TLAN_DEBUG_GNRL, "%s: Net_Sts = %x\n",
1837 dev->name, (unsigned) net_sts);
1839 if ((net_sts & TLAN_NET_STS_MIRQ) && (priv->phy_num == 0)) {
1840 tlan_mii_read_reg(dev, phy, TLAN_TLPHY_STS, &tlphy_sts);
1841 tlan_mii_read_reg(dev, phy, TLAN_TLPHY_CTL, &tlphy_ctl);
1842 if (!(tlphy_sts & TLAN_TS_POLOK) &&
1843 !(tlphy_ctl & TLAN_TC_SWAPOL)) {
1844 tlphy_ctl |= TLAN_TC_SWAPOL;
1845 tlan_mii_write_reg(dev, phy, TLAN_TLPHY_CTL,
1847 } else if ((tlphy_sts & TLAN_TS_POLOK) &&
1848 (tlphy_ctl & TLAN_TC_SWAPOL)) {
1849 tlphy_ctl &= ~TLAN_TC_SWAPOL;
1850 tlan_mii_write_reg(dev, phy, TLAN_TLPHY_CTL,
1855 tlan_phy_print(dev);
1866 /***************************************************************
1867 * tlan_handle_rx_eoc
1872 * dev Device assigned the IRQ that was
1874 * host_int The contents of the HOST_INT
1877 * This driver is structured to determine EOC occurrences by
1878 * reading the CSTAT member of the list structure. Rx EOC
1879 * interrupts are disabled via the DIO INTDIS register.
1880 * However, TLAN chips before revision 3.0 didn't have this
1881 * CSTAT member or a INTDIS register, so if this chip is
1882 * pre-3.0, process EOC interrupts normally.
1884 **************************************************************/
1886 static u32 tlan_handle_rx_eoc(struct net_device *dev, u16 host_int)
1888 struct tlan_priv *priv = netdev_priv(dev);
1889 dma_addr_t head_list_phys;
1892 if (priv->tlan_rev < 0x30) {
1893 TLAN_DBG(TLAN_DEBUG_RX,
1894 "RECEIVE: Handling RX EOC (head=%d tail=%d) -- IRQ\n",
1895 priv->rx_head, priv->rx_tail);
1896 head_list_phys = priv->rx_list_dma
1897 + sizeof(struct tlan_list)*priv->rx_head;
1898 outl(head_list_phys, dev->base_addr + TLAN_CH_PARM);
1899 ack |= TLAN_HC_GO | TLAN_HC_RT;
1900 priv->rx_eoc_count++;
1910 /*****************************************************************************
1911 ******************************************************************************
1913 ThunderLAN driver timer function
1915 ******************************************************************************
1916 *****************************************************************************/
1919 /***************************************************************
1925 * data A value given to add timer when
1926 * add_timer was called.
1928 * This function handles timed functionality for the
1929 * TLAN driver. The two current timer uses are for
1930 * delaying for autonegotionation and driving the ACT LED.
1931 * - Autonegotiation requires being allowed about
1932 * 2 1/2 seconds before attempting to transmit a
1933 * packet. It would be a very bad thing to hang
1934 * the kernel this long, so the driver doesn't
1935 * allow transmission 'til after this time, for
1936 * certain PHYs. It would be much nicer if all
1937 * PHYs were interrupt-capable like the internal
1939 * - The ACT LED, which shows adapter activity, is
1940 * driven by the driver, and so must be left on
1941 * for a short period to power up the LED so it
1942 * can be seen. This delay can be changed by
1943 * changing the TLAN_TIMER_ACT_DELAY in tlan.h,
1944 * if desired. 100 ms produces a slightly
1945 * sluggish response.
1947 **************************************************************/
1949 static void tlan_timer(unsigned long data)
1951 struct net_device *dev = (struct net_device *) data;
1952 struct tlan_priv *priv = netdev_priv(dev);
1954 unsigned long flags = 0;
1956 priv->timer.function = NULL;
1958 switch (priv->timer_type) {
1960 case TLAN_TIMER_LINK_BEAT:
1961 tlan_phy_monitor(dev);
1964 case TLAN_TIMER_PHY_PDOWN:
1965 tlan_phy_power_down(dev);
1967 case TLAN_TIMER_PHY_PUP:
1968 tlan_phy_power_up(dev);
1970 case TLAN_TIMER_PHY_RESET:
1971 tlan_phy_reset(dev);
1973 case TLAN_TIMER_PHY_START_LINK:
1974 tlan_phy_start_link(dev);
1976 case TLAN_TIMER_PHY_FINISH_AN:
1977 tlan_phy_finish_auto_neg(dev);
1979 case TLAN_TIMER_FINISH_RESET:
1980 tlan_finish_reset(dev);
1982 case TLAN_TIMER_ACTIVITY:
1983 spin_lock_irqsave(&priv->lock, flags);
1984 if (priv->timer.function == NULL) {
1985 elapsed = jiffies - priv->timer_set_at;
1986 if (elapsed >= TLAN_TIMER_ACT_DELAY) {
1987 tlan_dio_write8(dev->base_addr,
1988 TLAN_LED_REG, TLAN_LED_LINK);
1990 priv->timer.function = tlan_timer;
1991 priv->timer.expires = priv->timer_set_at
1992 + TLAN_TIMER_ACT_DELAY;
1993 spin_unlock_irqrestore(&priv->lock, flags);
1994 add_timer(&priv->timer);
1998 spin_unlock_irqrestore(&priv->lock, flags);
2009 /*****************************************************************************
2010 ******************************************************************************
2012 ThunderLAN driver adapter related routines
2014 ******************************************************************************
2015 *****************************************************************************/
2018 /***************************************************************
2024 * dev The device structure with the list
2025 * stuctures to be reset.
2027 * This routine sets the variables associated with managing
2028 * the TLAN lists to their initial values.
2030 **************************************************************/
2032 static void tlan_reset_lists(struct net_device *dev)
2034 struct tlan_priv *priv = netdev_priv(dev);
2036 struct tlan_list *list;
2037 dma_addr_t list_phys;
2038 struct sk_buff *skb;
2042 for (i = 0; i < TLAN_NUM_TX_LISTS; i++) {
2043 list = priv->tx_list + i;
2044 list->c_stat = TLAN_CSTAT_UNUSED;
2045 list->buffer[0].address = 0;
2046 list->buffer[2].count = 0;
2047 list->buffer[2].address = 0;
2048 list->buffer[8].address = 0;
2049 list->buffer[9].address = 0;
2053 priv->rx_tail = TLAN_NUM_RX_LISTS - 1;
2054 for (i = 0; i < TLAN_NUM_RX_LISTS; i++) {
2055 list = priv->rx_list + i;
2056 list_phys = priv->rx_list_dma + sizeof(struct tlan_list)*i;
2057 list->c_stat = TLAN_CSTAT_READY;
2058 list->frame_size = TLAN_MAX_FRAME_SIZE;
2059 list->buffer[0].count = TLAN_MAX_FRAME_SIZE | TLAN_LAST_BUFFER;
2060 skb = netdev_alloc_skb_ip_align(dev, TLAN_MAX_FRAME_SIZE + 5);
2062 pr_err("TLAN: out of memory for received data.\n");
2066 list->buffer[0].address = pci_map_single(priv->pci_dev,
2068 TLAN_MAX_FRAME_SIZE,
2069 PCI_DMA_FROMDEVICE);
2070 tlan_store_skb(list, skb);
2071 list->buffer[1].count = 0;
2072 list->buffer[1].address = 0;
2073 list->forward = list_phys + sizeof(struct tlan_list);
2076 /* in case ran out of memory early, clear bits */
2077 while (i < TLAN_NUM_RX_LISTS) {
2078 tlan_store_skb(priv->rx_list + i, NULL);
2086 static void tlan_free_lists(struct net_device *dev)
2088 struct tlan_priv *priv = netdev_priv(dev);
2090 struct tlan_list *list;
2091 struct sk_buff *skb;
2093 for (i = 0; i < TLAN_NUM_TX_LISTS; i++) {
2094 list = priv->tx_list + i;
2095 skb = tlan_get_skb(list);
2099 list->buffer[0].address,
2101 (unsigned int)TLAN_MIN_FRAME_SIZE),
2103 dev_kfree_skb_any(skb);
2104 list->buffer[8].address = 0;
2105 list->buffer[9].address = 0;
2109 for (i = 0; i < TLAN_NUM_RX_LISTS; i++) {
2110 list = priv->rx_list + i;
2111 skb = tlan_get_skb(list);
2113 pci_unmap_single(priv->pci_dev,
2114 list->buffer[0].address,
2115 TLAN_MAX_FRAME_SIZE,
2116 PCI_DMA_FROMDEVICE);
2117 dev_kfree_skb_any(skb);
2118 list->buffer[8].address = 0;
2119 list->buffer[9].address = 0;
2127 /***************************************************************
2133 * io_base Base IO port of the device of
2134 * which to print DIO registers.
2136 * This function prints out all the internal (DIO)
2137 * registers of a TLAN chip.
2139 **************************************************************/
2141 static void tlan_print_dio(u16 io_base)
2146 pr_info("TLAN: Contents of internal registers for io base 0x%04hx.\n",
2148 pr_info("TLAN: Off. +0 +4\n");
2149 for (i = 0; i < 0x4C; i += 8) {
2150 data0 = tlan_dio_read32(io_base, i);
2151 data1 = tlan_dio_read32(io_base, i + 0x4);
2152 pr_info("TLAN: 0x%02x 0x%08x 0x%08x\n", i, data0, data1);
2160 /***************************************************************
2166 * list A pointer to the struct tlan_list structure to
2168 * type A string to designate type of list,
2170 * num The index of the list.
2172 * This function prints out the contents of the list
2173 * pointed to by the list parameter.
2175 **************************************************************/
2177 static void tlan_print_list(struct tlan_list *list, char *type, int num)
2181 pr_info("TLAN: %s List %d at %p\n", type, num, list);
2182 pr_info("TLAN: Forward = 0x%08x\n", list->forward);
2183 pr_info("TLAN: CSTAT = 0x%04hx\n", list->c_stat);
2184 pr_info("TLAN: Frame Size = 0x%04hx\n", list->frame_size);
2185 /* for (i = 0; i < 10; i++) { */
2186 for (i = 0; i < 2; i++) {
2187 pr_info("TLAN: Buffer[%d].count, addr = 0x%08x, 0x%08x\n",
2188 i, list->buffer[i].count, list->buffer[i].address);
2196 /***************************************************************
2197 * tlan_read_and_clear_stats
2202 * dev Pointer to device structure of adapter
2203 * to which to read stats.
2204 * record Flag indicating whether to add
2206 * This functions reads all the internal status registers
2207 * of the TLAN chip, which clears them as a side effect.
2208 * It then either adds the values to the device's status
2209 * struct, or discards them, depending on whether record
2210 * is TLAN_RECORD (!=0) or TLAN_IGNORE (==0).
2212 **************************************************************/
2214 static void tlan_read_and_clear_stats(struct net_device *dev, int record)
2216 u32 tx_good, tx_under;
2217 u32 rx_good, rx_over;
2218 u32 def_tx, crc, code;
2219 u32 multi_col, single_col;
2220 u32 excess_col, late_col, loss;
2222 outw(TLAN_GOOD_TX_FRMS, dev->base_addr + TLAN_DIO_ADR);
2223 tx_good = inb(dev->base_addr + TLAN_DIO_DATA);
2224 tx_good += inb(dev->base_addr + TLAN_DIO_DATA + 1) << 8;
2225 tx_good += inb(dev->base_addr + TLAN_DIO_DATA + 2) << 16;
2226 tx_under = inb(dev->base_addr + TLAN_DIO_DATA + 3);
2228 outw(TLAN_GOOD_RX_FRMS, dev->base_addr + TLAN_DIO_ADR);
2229 rx_good = inb(dev->base_addr + TLAN_DIO_DATA);
2230 rx_good += inb(dev->base_addr + TLAN_DIO_DATA + 1) << 8;
2231 rx_good += inb(dev->base_addr + TLAN_DIO_DATA + 2) << 16;
2232 rx_over = inb(dev->base_addr + TLAN_DIO_DATA + 3);
2234 outw(TLAN_DEFERRED_TX, dev->base_addr + TLAN_DIO_ADR);
2235 def_tx = inb(dev->base_addr + TLAN_DIO_DATA);
2236 def_tx += inb(dev->base_addr + TLAN_DIO_DATA + 1) << 8;
2237 crc = inb(dev->base_addr + TLAN_DIO_DATA + 2);
2238 code = inb(dev->base_addr + TLAN_DIO_DATA + 3);
2240 outw(TLAN_MULTICOL_FRMS, dev->base_addr + TLAN_DIO_ADR);
2241 multi_col = inb(dev->base_addr + TLAN_DIO_DATA);
2242 multi_col += inb(dev->base_addr + TLAN_DIO_DATA + 1) << 8;
2243 single_col = inb(dev->base_addr + TLAN_DIO_DATA + 2);
2244 single_col += inb(dev->base_addr + TLAN_DIO_DATA + 3) << 8;
2246 outw(TLAN_EXCESSCOL_FRMS, dev->base_addr + TLAN_DIO_ADR);
2247 excess_col = inb(dev->base_addr + TLAN_DIO_DATA);
2248 late_col = inb(dev->base_addr + TLAN_DIO_DATA + 1);
2249 loss = inb(dev->base_addr + TLAN_DIO_DATA + 2);
2252 dev->stats.rx_packets += rx_good;
2253 dev->stats.rx_errors += rx_over + crc + code;
2254 dev->stats.tx_packets += tx_good;
2255 dev->stats.tx_errors += tx_under + loss;
2256 dev->stats.collisions += multi_col
2257 + single_col + excess_col + late_col;
2259 dev->stats.rx_over_errors += rx_over;
2260 dev->stats.rx_crc_errors += crc;
2261 dev->stats.rx_frame_errors += code;
2263 dev->stats.tx_aborted_errors += tx_under;
2264 dev->stats.tx_carrier_errors += loss;
2272 /***************************************************************
2278 * dev Pointer to device structure of adapter
2281 * This function resets the adapter and it's physical
2282 * device. See Chap. 3, pp. 9-10 of the "ThunderLAN
2283 * Programmer's Guide" for details. The routine tries to
2284 * implement what is detailed there, though adjustments
2287 **************************************************************/
2290 tlan_reset_adapter(struct net_device *dev)
2292 struct tlan_priv *priv = netdev_priv(dev);
2298 priv->tlan_full_duplex = false;
2299 priv->phy_online = 0;
2300 netif_carrier_off(dev);
2302 /* 1. Assert reset bit. */
2304 data = inl(dev->base_addr + TLAN_HOST_CMD);
2305 data |= TLAN_HC_AD_RST;
2306 outl(data, dev->base_addr + TLAN_HOST_CMD);
2310 /* 2. Turn off interrupts. (Probably isn't necessary) */
2312 data = inl(dev->base_addr + TLAN_HOST_CMD);
2313 data |= TLAN_HC_INT_OFF;
2314 outl(data, dev->base_addr + TLAN_HOST_CMD);
2316 /* 3. Clear AREGs and HASHs. */
2318 for (i = TLAN_AREG_0; i <= TLAN_HASH_2; i += 4)
2319 tlan_dio_write32(dev->base_addr, (u16) i, 0);
2321 /* 4. Setup NetConfig register. */
2323 data = TLAN_NET_CFG_1FRAG | TLAN_NET_CFG_1CHAN | TLAN_NET_CFG_PHY_EN;
2324 tlan_dio_write16(dev->base_addr, TLAN_NET_CONFIG, (u16) data);
2326 /* 5. Load Ld_Tmr and Ld_Thr in HOST_CMD. */
2328 outl(TLAN_HC_LD_TMR | 0x3f, dev->base_addr + TLAN_HOST_CMD);
2329 outl(TLAN_HC_LD_THR | 0x9, dev->base_addr + TLAN_HOST_CMD);
2331 /* 6. Unreset the MII by setting NMRST (in NetSio) to 1. */
2333 outw(TLAN_NET_SIO, dev->base_addr + TLAN_DIO_ADR);
2334 addr = dev->base_addr + TLAN_DIO_DATA + TLAN_NET_SIO;
2335 tlan_set_bit(TLAN_NET_SIO_NMRST, addr);
2337 /* 7. Setup the remaining registers. */
2339 if (priv->tlan_rev >= 0x30) {
2340 data8 = TLAN_ID_TX_EOC | TLAN_ID_RX_EOC;
2341 tlan_dio_write8(dev->base_addr, TLAN_INT_DIS, data8);
2343 tlan_phy_detect(dev);
2344 data = TLAN_NET_CFG_1FRAG | TLAN_NET_CFG_1CHAN;
2346 if (priv->adapter->flags & TLAN_ADAPTER_BIT_RATE_PHY) {
2347 data |= TLAN_NET_CFG_BIT;
2348 if (priv->aui == 1) {
2349 tlan_dio_write8(dev->base_addr, TLAN_ACOMMIT, 0x0a);
2350 } else if (priv->duplex == TLAN_DUPLEX_FULL) {
2351 tlan_dio_write8(dev->base_addr, TLAN_ACOMMIT, 0x00);
2352 priv->tlan_full_duplex = true;
2354 tlan_dio_write8(dev->base_addr, TLAN_ACOMMIT, 0x08);
2358 if (priv->phy_num == 0)
2359 data |= TLAN_NET_CFG_PHY_EN;
2360 tlan_dio_write16(dev->base_addr, TLAN_NET_CONFIG, (u16) data);
2362 if (priv->adapter->flags & TLAN_ADAPTER_UNMANAGED_PHY)
2363 tlan_finish_reset(dev);
2365 tlan_phy_power_down(dev);
2373 tlan_finish_reset(struct net_device *dev)
2375 struct tlan_priv *priv = netdev_priv(dev);
2383 u16 tlphy_id1, tlphy_id2;
2386 phy = priv->phy[priv->phy_num];
2388 data = TLAN_NET_CMD_NRESET | TLAN_NET_CMD_NWRAP;
2389 if (priv->tlan_full_duplex)
2390 data |= TLAN_NET_CMD_DUPLEX;
2391 tlan_dio_write8(dev->base_addr, TLAN_NET_CMD, data);
2392 data = TLAN_NET_MASK_MASK4 | TLAN_NET_MASK_MASK5;
2393 if (priv->phy_num == 0)
2394 data |= TLAN_NET_MASK_MASK7;
2395 tlan_dio_write8(dev->base_addr, TLAN_NET_MASK, data);
2396 tlan_dio_write16(dev->base_addr, TLAN_MAX_RX, ((1536)+7)&~7);
2397 tlan_mii_read_reg(dev, phy, MII_GEN_ID_HI, &tlphy_id1);
2398 tlan_mii_read_reg(dev, phy, MII_GEN_ID_LO, &tlphy_id2);
2400 if ((priv->adapter->flags & TLAN_ADAPTER_UNMANAGED_PHY) ||
2402 status = MII_GS_LINK;
2403 pr_info("TLAN: %s: Link forced.\n", dev->name);
2405 tlan_mii_read_reg(dev, phy, MII_GEN_STS, &status);
2407 tlan_mii_read_reg(dev, phy, MII_GEN_STS, &status);
2408 if ((status & MII_GS_LINK) &&
2409 /* We only support link info on Nat.Sem. PHY's */
2410 (tlphy_id1 == NAT_SEM_ID1) &&
2411 (tlphy_id2 == NAT_SEM_ID2)) {
2412 tlan_mii_read_reg(dev, phy, MII_AN_LPA, &partner);
2413 tlan_mii_read_reg(dev, phy, TLAN_TLPHY_PAR, &tlphy_par);
2415 pr_info("TLAN: %s: Link active with ", dev->name);
2416 if (!(tlphy_par & TLAN_PHY_AN_EN_STAT)) {
2417 pr_info("forced 10%sMbps %s-Duplex\n",
2418 tlphy_par & TLAN_PHY_SPEED_100
2420 tlphy_par & TLAN_PHY_DUPLEX_FULL
2423 pr_info("Autonegotiation enabled, at 10%sMbps %s-Duplex\n",
2424 tlphy_par & TLAN_PHY_SPEED_100
2426 tlphy_par & TLAN_PHY_DUPLEX_FULL
2428 pr_info("TLAN: Partner capability: ");
2429 for (i = 5; i <= 10; i++)
2430 if (partner & (1<<i))
2431 printk("%s", media[i-5]);
2435 tlan_dio_write8(dev->base_addr, TLAN_LED_REG,
2438 /* We have link beat..for now anyway */
2440 /*Enabling link beat monitoring */
2441 tlan_set_timer(dev, (10*HZ), TLAN_TIMER_LINK_BEAT);
2443 } else if (status & MII_GS_LINK) {
2444 pr_info("TLAN: %s: Link active\n", dev->name);
2445 tlan_dio_write8(dev->base_addr, TLAN_LED_REG,
2450 if (priv->phy_num == 0) {
2451 tlan_mii_read_reg(dev, phy, TLAN_TLPHY_CTL, &tlphy_ctl);
2452 tlphy_ctl |= TLAN_TC_INTEN;
2453 tlan_mii_write_reg(dev, phy, TLAN_TLPHY_CTL, tlphy_ctl);
2454 sio = tlan_dio_read8(dev->base_addr, TLAN_NET_SIO);
2455 sio |= TLAN_NET_SIO_MINTEN;
2456 tlan_dio_write8(dev->base_addr, TLAN_NET_SIO, sio);
2459 if (status & MII_GS_LINK) {
2460 tlan_set_mac(dev, 0, dev->dev_addr);
2461 priv->phy_online = 1;
2462 outb((TLAN_HC_INT_ON >> 8), dev->base_addr + TLAN_HOST_CMD + 1);
2463 if (debug >= 1 && debug != TLAN_DEBUG_PROBE)
2464 outb((TLAN_HC_REQ_INT >> 8),
2465 dev->base_addr + TLAN_HOST_CMD + 1);
2466 outl(priv->rx_list_dma, dev->base_addr + TLAN_CH_PARM);
2467 outl(TLAN_HC_GO | TLAN_HC_RT, dev->base_addr + TLAN_HOST_CMD);
2468 netif_carrier_on(dev);
2470 pr_info("TLAN: %s: Link inactive, will retry in 10 secs...\n",
2472 tlan_set_timer(dev, (10*HZ), TLAN_TIMER_FINISH_RESET);
2475 tlan_set_multicast_list(dev);
2482 /***************************************************************
2488 * dev Pointer to device structure of adapter
2489 * on which to change the AREG.
2490 * areg The AREG to set the address in (0 - 3).
2491 * mac A pointer to an array of chars. Each
2492 * element stores one byte of the address.
2493 * IE, it isn't in ascii.
2495 * This function transfers a MAC address to one of the
2496 * TLAN AREGs (address registers). The TLAN chip locks
2497 * the register on writing to offset 0 and unlocks the
2498 * register after writing to offset 5. If NULL is passed
2499 * in mac, then the AREG is filled with 0's.
2501 **************************************************************/
2503 static void tlan_set_mac(struct net_device *dev, int areg, char *mac)
2510 for (i = 0; i < 6; i++)
2511 tlan_dio_write8(dev->base_addr,
2512 TLAN_AREG_0 + areg + i, mac[i]);
2514 for (i = 0; i < 6; i++)
2515 tlan_dio_write8(dev->base_addr,
2516 TLAN_AREG_0 + areg + i, 0);
2524 /*****************************************************************************
2525 ******************************************************************************
2527 ThunderLAN driver PHY layer routines
2529 ******************************************************************************
2530 *****************************************************************************/
2534 /*********************************************************************
2540 * dev A pointer to the device structure of the
2541 * TLAN device having the PHYs to be detailed.
2543 * This function prints the registers a PHY (aka transceiver).
2545 ********************************************************************/
2547 static void tlan_phy_print(struct net_device *dev)
2549 struct tlan_priv *priv = netdev_priv(dev);
2550 u16 i, data0, data1, data2, data3, phy;
2552 phy = priv->phy[priv->phy_num];
2554 if (priv->adapter->flags & TLAN_ADAPTER_UNMANAGED_PHY) {
2555 pr_info("TLAN: Device %s, Unmanaged PHY.\n", dev->name);
2556 } else if (phy <= TLAN_PHY_MAX_ADDR) {
2557 pr_info("TLAN: Device %s, PHY 0x%02x.\n", dev->name, phy);
2558 pr_info("TLAN: Off. +0 +1 +2 +3\n");
2559 for (i = 0; i < 0x20; i += 4) {
2560 pr_info("TLAN: 0x%02x", i);
2561 tlan_mii_read_reg(dev, phy, i, &data0);
2562 printk(" 0x%04hx", data0);
2563 tlan_mii_read_reg(dev, phy, i + 1, &data1);
2564 printk(" 0x%04hx", data1);
2565 tlan_mii_read_reg(dev, phy, i + 2, &data2);
2566 printk(" 0x%04hx", data2);
2567 tlan_mii_read_reg(dev, phy, i + 3, &data3);
2568 printk(" 0x%04hx\n", data3);
2571 pr_info("TLAN: Device %s, Invalid PHY.\n", dev->name);
2579 /*********************************************************************
2585 * dev A pointer to the device structure of the adapter
2586 * for which the PHY needs determined.
2588 * So far I've found that adapters which have external PHYs
2589 * may also use the internal PHY for part of the functionality.
2590 * (eg, AUI/Thinnet). This function finds out if this TLAN
2591 * chip has an internal PHY, and then finds the first external
2592 * PHY (starting from address 0) if it exists).
2594 ********************************************************************/
2596 static void tlan_phy_detect(struct net_device *dev)
2598 struct tlan_priv *priv = netdev_priv(dev);
2604 if (priv->adapter->flags & TLAN_ADAPTER_UNMANAGED_PHY) {
2605 priv->phy_num = 0xffff;
2609 tlan_mii_read_reg(dev, TLAN_PHY_MAX_ADDR, MII_GEN_ID_HI, &hi);
2612 priv->phy[0] = TLAN_PHY_MAX_ADDR;
2614 priv->phy[0] = TLAN_PHY_NONE;
2616 priv->phy[1] = TLAN_PHY_NONE;
2617 for (phy = 0; phy <= TLAN_PHY_MAX_ADDR; phy++) {
2618 tlan_mii_read_reg(dev, phy, MII_GEN_CTL, &control);
2619 tlan_mii_read_reg(dev, phy, MII_GEN_ID_HI, &hi);
2620 tlan_mii_read_reg(dev, phy, MII_GEN_ID_LO, &lo);
2621 if ((control != 0xffff) ||
2622 (hi != 0xffff) || (lo != 0xffff)) {
2623 TLAN_DBG(TLAN_DEBUG_GNRL,
2624 "PHY found at %02x %04x %04x %04x\n",
2625 phy, control, hi, lo);
2626 if ((priv->phy[1] == TLAN_PHY_NONE) &&
2627 (phy != TLAN_PHY_MAX_ADDR)) {
2633 if (priv->phy[1] != TLAN_PHY_NONE)
2635 else if (priv->phy[0] != TLAN_PHY_NONE)
2638 pr_info("TLAN: Cannot initialize device, no PHY was found!\n");
2645 static void tlan_phy_power_down(struct net_device *dev)
2647 struct tlan_priv *priv = netdev_priv(dev);
2650 TLAN_DBG(TLAN_DEBUG_GNRL, "%s: Powering down PHY(s).\n", dev->name);
2651 value = MII_GC_PDOWN | MII_GC_LOOPBK | MII_GC_ISOLATE;
2652 tlan_mii_sync(dev->base_addr);
2653 tlan_mii_write_reg(dev, priv->phy[priv->phy_num], MII_GEN_CTL, value);
2654 if ((priv->phy_num == 0) &&
2655 (priv->phy[1] != TLAN_PHY_NONE) &&
2656 (!(priv->adapter->flags & TLAN_ADAPTER_USE_INTERN_10))) {
2657 tlan_mii_sync(dev->base_addr);
2658 tlan_mii_write_reg(dev, priv->phy[1], MII_GEN_CTL, value);
2661 /* Wait for 50 ms and powerup
2662 * This is abitrary. It is intended to make sure the
2663 * transceiver settles.
2665 tlan_set_timer(dev, (HZ/20), TLAN_TIMER_PHY_PUP);
2672 static void tlan_phy_power_up(struct net_device *dev)
2674 struct tlan_priv *priv = netdev_priv(dev);
2677 TLAN_DBG(TLAN_DEBUG_GNRL, "%s: Powering up PHY.\n", dev->name);
2678 tlan_mii_sync(dev->base_addr);
2679 value = MII_GC_LOOPBK;
2680 tlan_mii_write_reg(dev, priv->phy[priv->phy_num], MII_GEN_CTL, value);
2681 tlan_mii_sync(dev->base_addr);
2682 /* Wait for 500 ms and reset the
2683 * transceiver. The TLAN docs say both 50 ms and
2684 * 500 ms, so do the longer, just in case.
2686 tlan_set_timer(dev, (HZ/20), TLAN_TIMER_PHY_RESET);
2693 static void tlan_phy_reset(struct net_device *dev)
2695 struct tlan_priv *priv = netdev_priv(dev);
2699 phy = priv->phy[priv->phy_num];
2701 TLAN_DBG(TLAN_DEBUG_GNRL, "%s: Reseting PHY.\n", dev->name);
2702 tlan_mii_sync(dev->base_addr);
2703 value = MII_GC_LOOPBK | MII_GC_RESET;
2704 tlan_mii_write_reg(dev, phy, MII_GEN_CTL, value);
2705 tlan_mii_read_reg(dev, phy, MII_GEN_CTL, &value);
2706 while (value & MII_GC_RESET)
2707 tlan_mii_read_reg(dev, phy, MII_GEN_CTL, &value);
2709 /* Wait for 500 ms and initialize.
2710 * I don't remember why I wait this long.
2711 * I've changed this to 50ms, as it seems long enough.
2713 tlan_set_timer(dev, (HZ/20), TLAN_TIMER_PHY_START_LINK);
2720 static void tlan_phy_start_link(struct net_device *dev)
2722 struct tlan_priv *priv = netdev_priv(dev);
2730 phy = priv->phy[priv->phy_num];
2731 TLAN_DBG(TLAN_DEBUG_GNRL, "%s: Trying to activate link.\n", dev->name);
2732 tlan_mii_read_reg(dev, phy, MII_GEN_STS, &status);
2733 tlan_mii_read_reg(dev, phy, MII_GEN_STS, &ability);
2735 if ((status & MII_GS_AUTONEG) &&
2737 ability = status >> 11;
2738 if (priv->speed == TLAN_SPEED_10 &&
2739 priv->duplex == TLAN_DUPLEX_HALF) {
2740 tlan_mii_write_reg(dev, phy, MII_GEN_CTL, 0x0000);
2741 } else if (priv->speed == TLAN_SPEED_10 &&
2742 priv->duplex == TLAN_DUPLEX_FULL) {
2743 priv->tlan_full_duplex = true;
2744 tlan_mii_write_reg(dev, phy, MII_GEN_CTL, 0x0100);
2745 } else if (priv->speed == TLAN_SPEED_100 &&
2746 priv->duplex == TLAN_DUPLEX_HALF) {
2747 tlan_mii_write_reg(dev, phy, MII_GEN_CTL, 0x2000);
2748 } else if (priv->speed == TLAN_SPEED_100 &&
2749 priv->duplex == TLAN_DUPLEX_FULL) {
2750 priv->tlan_full_duplex = true;
2751 tlan_mii_write_reg(dev, phy, MII_GEN_CTL, 0x2100);
2754 /* Set Auto-Neg advertisement */
2755 tlan_mii_write_reg(dev, phy, MII_AN_ADV,
2756 (ability << 5) | 1);
2757 /* Enablee Auto-Neg */
2758 tlan_mii_write_reg(dev, phy, MII_GEN_CTL, 0x1000);
2759 /* Restart Auto-Neg */
2760 tlan_mii_write_reg(dev, phy, MII_GEN_CTL, 0x1200);
2761 /* Wait for 4 sec for autonegotiation
2762 * to complete. The max spec time is less than this
2763 * but the card need additional time to start AN.
2764 * .5 sec should be plenty extra.
2766 pr_info("TLAN: %s: Starting autonegotiation.\n",
2768 tlan_set_timer(dev, (2*HZ), TLAN_TIMER_PHY_FINISH_AN);
2774 if ((priv->aui) && (priv->phy_num != 0)) {
2776 data = TLAN_NET_CFG_1FRAG | TLAN_NET_CFG_1CHAN
2777 | TLAN_NET_CFG_PHY_EN;
2778 tlan_dio_write16(dev->base_addr, TLAN_NET_CONFIG, data);
2779 tlan_set_timer(dev, (40*HZ/1000), TLAN_TIMER_PHY_PDOWN);
2781 } else if (priv->phy_num == 0) {
2783 tlan_mii_read_reg(dev, phy, TLAN_TLPHY_CTL, &tctl);
2785 tctl |= TLAN_TC_AUISEL;
2787 tctl &= ~TLAN_TC_AUISEL;
2788 if (priv->duplex == TLAN_DUPLEX_FULL) {
2789 control |= MII_GC_DUPLEX;
2790 priv->tlan_full_duplex = true;
2792 if (priv->speed == TLAN_SPEED_100)
2793 control |= MII_GC_SPEEDSEL;
2795 tlan_mii_write_reg(dev, phy, MII_GEN_CTL, control);
2796 tlan_mii_write_reg(dev, phy, TLAN_TLPHY_CTL, tctl);
2799 /* Wait for 2 sec to give the transceiver time
2800 * to establish link.
2802 tlan_set_timer(dev, (4*HZ), TLAN_TIMER_FINISH_RESET);
2809 static void tlan_phy_finish_auto_neg(struct net_device *dev)
2811 struct tlan_priv *priv = netdev_priv(dev);
2819 phy = priv->phy[priv->phy_num];
2821 tlan_mii_read_reg(dev, phy, MII_GEN_STS, &status);
2823 tlan_mii_read_reg(dev, phy, MII_GEN_STS, &status);
2825 if (!(status & MII_GS_AUTOCMPLT)) {
2826 /* Wait for 8 sec to give the process
2827 * more time. Perhaps we should fail after a while.
2829 if (!priv->neg_be_verbose++) {
2830 pr_info("TLAN: Giving autonegotiation more time.\n");
2831 pr_info("TLAN: Please check that your adapter has\n");
2832 pr_info("TLAN: been properly connected to a HUB or Switch.\n");
2833 pr_info("TLAN: Trying to establish link in the background...\n");
2835 tlan_set_timer(dev, (8*HZ), TLAN_TIMER_PHY_FINISH_AN);
2839 pr_info("TLAN: %s: Autonegotiation complete.\n", dev->name);
2840 tlan_mii_read_reg(dev, phy, MII_AN_ADV, &an_adv);
2841 tlan_mii_read_reg(dev, phy, MII_AN_LPA, &an_lpa);
2842 mode = an_adv & an_lpa & 0x03E0;
2844 priv->tlan_full_duplex = true;
2845 else if (!(mode & 0x0080) && (mode & 0x0040))
2846 priv->tlan_full_duplex = true;
2848 if ((!(mode & 0x0180)) &&
2849 (priv->adapter->flags & TLAN_ADAPTER_USE_INTERN_10) &&
2850 (priv->phy_num != 0)) {
2852 data = TLAN_NET_CFG_1FRAG | TLAN_NET_CFG_1CHAN
2853 | TLAN_NET_CFG_PHY_EN;
2854 tlan_dio_write16(dev->base_addr, TLAN_NET_CONFIG, data);
2855 tlan_set_timer(dev, (400*HZ/1000), TLAN_TIMER_PHY_PDOWN);
2859 if (priv->phy_num == 0) {
2860 if ((priv->duplex == TLAN_DUPLEX_FULL) ||
2861 (an_adv & an_lpa & 0x0040)) {
2862 tlan_mii_write_reg(dev, phy, MII_GEN_CTL,
2863 MII_GC_AUTOENB | MII_GC_DUPLEX);
2864 pr_info("TLAN: Starting internal PHY with FULL-DUPLEX\n");
2866 tlan_mii_write_reg(dev, phy, MII_GEN_CTL,
2868 pr_info("TLAN: Starting internal PHY with HALF-DUPLEX\n");
2872 /* Wait for 100 ms. No reason in partiticular.
2874 tlan_set_timer(dev, (HZ/10), TLAN_TIMER_FINISH_RESET);
2880 /*********************************************************************
2888 * dev The device structure of this device.
2891 * This function monitors PHY condition by reading the status
2892 * register via the MII bus. This can be used to give info
2893 * about link changes (up/down), and possible switch to alternate
2896 *******************************************************************/
2898 void tlan_phy_monitor(struct net_device *dev)
2900 struct tlan_priv *priv = netdev_priv(dev);
2904 phy = priv->phy[priv->phy_num];
2906 /* Get PHY status register */
2907 tlan_mii_read_reg(dev, phy, MII_GEN_STS, &phy_status);
2909 /* Check if link has been lost */
2910 if (!(phy_status & MII_GS_LINK)) {
2913 printk(KERN_DEBUG "TLAN: %s has lost link\n",
2915 netif_carrier_off(dev);
2916 tlan_set_timer(dev, (2*HZ), TLAN_TIMER_LINK_BEAT);
2921 /* Link restablished? */
2922 if ((phy_status & MII_GS_LINK) && !priv->link) {
2924 printk(KERN_DEBUG "TLAN: %s has reestablished link\n",
2926 netif_carrier_on(dev);
2929 /* Setup a new monitor */
2930 tlan_set_timer(dev, (2*HZ), TLAN_TIMER_LINK_BEAT);
2933 #endif /* MONITOR */
2936 /*****************************************************************************
2937 ******************************************************************************
2939 ThunderLAN driver MII routines
2941 these routines are based on the information in chap. 2 of the
2942 "ThunderLAN Programmer's Guide", pp. 15-24.
2944 ******************************************************************************
2945 *****************************************************************************/
2948 /***************************************************************
2952 * false if ack received ok
2953 * true if no ack received or other error
2956 * dev The device structure containing
2957 * The io address and interrupt count
2959 * phy The address of the PHY to be queried.
2960 * reg The register whose contents are to be
2962 * val A pointer to a variable to store the
2965 * This function uses the TLAN's MII bus to retrieve the contents
2966 * of a given register on a PHY. It sends the appropriate info
2967 * and then reads the 16-bit register value from the MII bus via
2968 * the TLAN SIO register.
2970 **************************************************************/
2973 tlan_mii_read_reg(struct net_device *dev, u16 phy, u16 reg, u16 *val)
2980 struct tlan_priv *priv = netdev_priv(dev);
2981 unsigned long flags = 0;
2984 outw(TLAN_NET_SIO, dev->base_addr + TLAN_DIO_ADR);
2985 sio = dev->base_addr + TLAN_DIO_DATA + TLAN_NET_SIO;
2988 spin_lock_irqsave(&priv->lock, flags);
2990 tlan_mii_sync(dev->base_addr);
2992 minten = tlan_get_bit(TLAN_NET_SIO_MINTEN, sio);
2994 tlan_clear_bit(TLAN_NET_SIO_MINTEN, sio);
2996 tlan_mii_send_data(dev->base_addr, 0x1, 2); /* start (01b) */
2997 tlan_mii_send_data(dev->base_addr, 0x2, 2); /* read (10b) */
2998 tlan_mii_send_data(dev->base_addr, phy, 5); /* device # */
2999 tlan_mii_send_data(dev->base_addr, reg, 5); /* register # */
3002 tlan_clear_bit(TLAN_NET_SIO_MTXEN, sio); /* change direction */
3004 tlan_clear_bit(TLAN_NET_SIO_MCLK, sio); /* clock idle bit */
3005 tlan_set_bit(TLAN_NET_SIO_MCLK, sio);
3006 tlan_clear_bit(TLAN_NET_SIO_MCLK, sio); /* wait 300ns */
3008 nack = tlan_get_bit(TLAN_NET_SIO_MDATA, sio); /* check for ACK */
3009 tlan_set_bit(TLAN_NET_SIO_MCLK, sio); /* finish ACK */
3010 if (nack) { /* no ACK, so fake it */
3011 for (i = 0; i < 16; i++) {
3012 tlan_clear_bit(TLAN_NET_SIO_MCLK, sio);
3013 tlan_set_bit(TLAN_NET_SIO_MCLK, sio);
3017 } else { /* ACK, so read data */
3018 for (tmp = 0, i = 0x8000; i; i >>= 1) {
3019 tlan_clear_bit(TLAN_NET_SIO_MCLK, sio);
3020 if (tlan_get_bit(TLAN_NET_SIO_MDATA, sio))
3022 tlan_set_bit(TLAN_NET_SIO_MCLK, sio);
3027 tlan_clear_bit(TLAN_NET_SIO_MCLK, sio); /* idle cycle */
3028 tlan_set_bit(TLAN_NET_SIO_MCLK, sio);
3031 tlan_set_bit(TLAN_NET_SIO_MINTEN, sio);
3036 spin_unlock_irqrestore(&priv->lock, flags);
3045 /***************************************************************
3046 * tlan_mii_send_data
3051 * base_port The base IO port of the adapter in
3053 * dev The address of the PHY to be queried.
3054 * data The value to be placed on the MII bus.
3055 * num_bits The number of bits in data that are to
3056 * be placed on the MII bus.
3058 * This function sends on sequence of bits on the MII
3059 * configuration bus.
3061 **************************************************************/
3063 static void tlan_mii_send_data(u16 base_port, u32 data, unsigned num_bits)
3071 outw(TLAN_NET_SIO, base_port + TLAN_DIO_ADR);
3072 sio = base_port + TLAN_DIO_DATA + TLAN_NET_SIO;
3073 tlan_set_bit(TLAN_NET_SIO_MTXEN, sio);
3075 for (i = (0x1 << (num_bits - 1)); i; i >>= 1) {
3076 tlan_clear_bit(TLAN_NET_SIO_MCLK, sio);
3077 (void) tlan_get_bit(TLAN_NET_SIO_MCLK, sio);
3079 tlan_set_bit(TLAN_NET_SIO_MDATA, sio);
3081 tlan_clear_bit(TLAN_NET_SIO_MDATA, sio);
3082 tlan_set_bit(TLAN_NET_SIO_MCLK, sio);
3083 (void) tlan_get_bit(TLAN_NET_SIO_MCLK, sio);
3091 /***************************************************************
3097 * base_port The base IO port of the adapter in
3100 * This functions syncs all PHYs in terms of the MII configuration
3103 **************************************************************/
3105 static void tlan_mii_sync(u16 base_port)
3110 outw(TLAN_NET_SIO, base_port + TLAN_DIO_ADR);
3111 sio = base_port + TLAN_DIO_DATA + TLAN_NET_SIO;
3113 tlan_clear_bit(TLAN_NET_SIO_MTXEN, sio);
3114 for (i = 0; i < 32; i++) {
3115 tlan_clear_bit(TLAN_NET_SIO_MCLK, sio);
3116 tlan_set_bit(TLAN_NET_SIO_MCLK, sio);
3124 /***************************************************************
3125 * tlan_mii_write_reg
3130 * dev The device structure for the device
3132 * phy The address of the PHY to be written to.
3133 * reg The register whose contents are to be
3135 * val The value to be written to the register.
3137 * This function uses the TLAN's MII bus to write the contents of a
3138 * given register on a PHY. It sends the appropriate info and then
3139 * writes the 16-bit register value from the MII configuration bus
3140 * via the TLAN SIO register.
3142 **************************************************************/
3145 tlan_mii_write_reg(struct net_device *dev, u16 phy, u16 reg, u16 val)
3149 unsigned long flags = 0;
3150 struct tlan_priv *priv = netdev_priv(dev);
3152 outw(TLAN_NET_SIO, dev->base_addr + TLAN_DIO_ADR);
3153 sio = dev->base_addr + TLAN_DIO_DATA + TLAN_NET_SIO;
3156 spin_lock_irqsave(&priv->lock, flags);
3158 tlan_mii_sync(dev->base_addr);
3160 minten = tlan_get_bit(TLAN_NET_SIO_MINTEN, sio);
3162 tlan_clear_bit(TLAN_NET_SIO_MINTEN, sio);
3164 tlan_mii_send_data(dev->base_addr, 0x1, 2); /* start (01b) */
3165 tlan_mii_send_data(dev->base_addr, 0x1, 2); /* write (01b) */
3166 tlan_mii_send_data(dev->base_addr, phy, 5); /* device # */
3167 tlan_mii_send_data(dev->base_addr, reg, 5); /* register # */
3169 tlan_mii_send_data(dev->base_addr, 0x2, 2); /* send ACK */
3170 tlan_mii_send_data(dev->base_addr, val, 16); /* send data */
3172 tlan_clear_bit(TLAN_NET_SIO_MCLK, sio); /* idle cycle */
3173 tlan_set_bit(TLAN_NET_SIO_MCLK, sio);
3176 tlan_set_bit(TLAN_NET_SIO_MINTEN, sio);
3179 spin_unlock_irqrestore(&priv->lock, flags);
3186 /*****************************************************************************
3187 ******************************************************************************
3189 ThunderLAN driver eeprom routines
3191 the Compaq netelligent 10 and 10/100 cards use a microchip 24C02A
3192 EEPROM. these functions are based on information in microchip's
3193 data sheet. I don't know how well this functions will work with
3196 ******************************************************************************
3197 *****************************************************************************/
3200 /***************************************************************
3201 * tlan_ee_send_start
3206 * io_base The IO port base address for the
3207 * TLAN device with the EEPROM to
3210 * This function sends a start cycle to an EEPROM attached
3213 **************************************************************/
3215 static void tlan_ee_send_start(u16 io_base)
3219 outw(TLAN_NET_SIO, io_base + TLAN_DIO_ADR);
3220 sio = io_base + TLAN_DIO_DATA + TLAN_NET_SIO;
3222 tlan_set_bit(TLAN_NET_SIO_ECLOK, sio);
3223 tlan_set_bit(TLAN_NET_SIO_EDATA, sio);
3224 tlan_set_bit(TLAN_NET_SIO_ETXEN, sio);
3225 tlan_clear_bit(TLAN_NET_SIO_EDATA, sio);
3226 tlan_clear_bit(TLAN_NET_SIO_ECLOK, sio);
3233 /***************************************************************
3237 * If the correct ack was received, 0, otherwise 1
3238 * Parms: io_base The IO port base address for the
3239 * TLAN device with the EEPROM to
3241 * data The 8 bits of information to
3242 * send to the EEPROM.
3243 * stop If TLAN_EEPROM_STOP is passed, a
3244 * stop cycle is sent after the
3245 * byte is sent after the ack is
3248 * This function sends a byte on the serial EEPROM line,
3249 * driving the clock to send each bit. The function then
3250 * reverses transmission direction and reads an acknowledge
3253 **************************************************************/
3255 static int tlan_ee_send_byte(u16 io_base, u8 data, int stop)
3261 outw(TLAN_NET_SIO, io_base + TLAN_DIO_ADR);
3262 sio = io_base + TLAN_DIO_DATA + TLAN_NET_SIO;
3264 /* Assume clock is low, tx is enabled; */
3265 for (place = 0x80; place != 0; place >>= 1) {
3267 tlan_set_bit(TLAN_NET_SIO_EDATA, sio);
3269 tlan_clear_bit(TLAN_NET_SIO_EDATA, sio);
3270 tlan_set_bit(TLAN_NET_SIO_ECLOK, sio);
3271 tlan_clear_bit(TLAN_NET_SIO_ECLOK, sio);
3273 tlan_clear_bit(TLAN_NET_SIO_ETXEN, sio);
3274 tlan_set_bit(TLAN_NET_SIO_ECLOK, sio);
3275 err = tlan_get_bit(TLAN_NET_SIO_EDATA, sio);
3276 tlan_clear_bit(TLAN_NET_SIO_ECLOK, sio);
3277 tlan_set_bit(TLAN_NET_SIO_ETXEN, sio);
3279 if ((!err) && stop) {
3280 /* STOP, raise data while clock is high */
3281 tlan_clear_bit(TLAN_NET_SIO_EDATA, sio);
3282 tlan_set_bit(TLAN_NET_SIO_ECLOK, sio);
3283 tlan_set_bit(TLAN_NET_SIO_EDATA, sio);
3293 /***************************************************************
3294 * tlan_ee_receive_byte
3299 * io_base The IO port base address for the
3300 * TLAN device with the EEPROM to
3302 * data An address to a char to hold the
3303 * data sent from the EEPROM.
3304 * stop If TLAN_EEPROM_STOP is passed, a
3305 * stop cycle is sent after the
3306 * byte is received, and no ack is
3309 * This function receives 8 bits of data from the EEPROM
3310 * over the serial link. It then sends and ack bit, or no
3311 * ack and a stop bit. This function is used to retrieve
3312 * data after the address of a byte in the EEPROM has been
3315 **************************************************************/
3317 static void tlan_ee_receive_byte(u16 io_base, u8 *data, int stop)
3322 outw(TLAN_NET_SIO, io_base + TLAN_DIO_ADR);
3323 sio = io_base + TLAN_DIO_DATA + TLAN_NET_SIO;
3326 /* Assume clock is low, tx is enabled; */
3327 tlan_clear_bit(TLAN_NET_SIO_ETXEN, sio);
3328 for (place = 0x80; place; place >>= 1) {
3329 tlan_set_bit(TLAN_NET_SIO_ECLOK, sio);
3330 if (tlan_get_bit(TLAN_NET_SIO_EDATA, sio))
3332 tlan_clear_bit(TLAN_NET_SIO_ECLOK, sio);
3335 tlan_set_bit(TLAN_NET_SIO_ETXEN, sio);
3337 tlan_clear_bit(TLAN_NET_SIO_EDATA, sio); /* ack = 0 */
3338 tlan_set_bit(TLAN_NET_SIO_ECLOK, sio);
3339 tlan_clear_bit(TLAN_NET_SIO_ECLOK, sio);
3341 tlan_set_bit(TLAN_NET_SIO_EDATA, sio); /* no ack = 1 (?) */
3342 tlan_set_bit(TLAN_NET_SIO_ECLOK, sio);
3343 tlan_clear_bit(TLAN_NET_SIO_ECLOK, sio);
3344 /* STOP, raise data while clock is high */
3345 tlan_clear_bit(TLAN_NET_SIO_EDATA, sio);
3346 tlan_set_bit(TLAN_NET_SIO_ECLOK, sio);
3347 tlan_set_bit(TLAN_NET_SIO_EDATA, sio);
3355 /***************************************************************
3359 * No error = 0, else, the stage at which the error
3362 * io_base The IO port base address for the
3363 * TLAN device with the EEPROM to
3365 * ee_addr The address of the byte in the
3366 * EEPROM whose contents are to be
3368 * data An address to a char to hold the
3369 * data obtained from the EEPROM.
3371 * This function reads a byte of information from an byte
3372 * cell in the EEPROM.
3374 **************************************************************/
3376 static int tlan_ee_read_byte(struct net_device *dev, u8 ee_addr, u8 *data)
3379 struct tlan_priv *priv = netdev_priv(dev);
3380 unsigned long flags = 0;
3383 spin_lock_irqsave(&priv->lock, flags);
3385 tlan_ee_send_start(dev->base_addr);
3386 err = tlan_ee_send_byte(dev->base_addr, 0xa0, TLAN_EEPROM_ACK);
3391 err = tlan_ee_send_byte(dev->base_addr, ee_addr, TLAN_EEPROM_ACK);
3396 tlan_ee_send_start(dev->base_addr);
3397 err = tlan_ee_send_byte(dev->base_addr, 0xa1, TLAN_EEPROM_ACK);
3402 tlan_ee_receive_byte(dev->base_addr, data, TLAN_EEPROM_STOP);
3404 spin_unlock_irqrestore(&priv->lock, flags);