blob: e48a808853432e5860d0f8fe27139704349dd279 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*******************************************************************************
2 *
3 * Linux ThunderLAN Driver
4 *
5 * tlan.c
6 * by James Banks
7 *
8 * (C) 1997-1998 Caldera, Inc.
9 * (C) 1998 James Banks
10 * (C) 1999-2001 Torben Mathiasen
11 * (C) 2002 Samuel Chessman
12 *
13 * This software may be used and distributed according to the terms
14 * of the GNU General Public License, incorporated herein by reference.
15 *
Linus Torvalds1da177e2005-04-16 15:20:36 -070016 ** Useful (if not required) reading:
17 *
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
27 *
28 * Change History
29 *
30 * Tigran Aivazian <tigran@sco.com>: TLan_PciProbe() now uses
31 * new PCI BIOS interface.
Alan Cox113aa832008-10-13 19:01:08 -070032 * Alan Cox <alan@lxorguk.ukuu.org.uk>:
33 * Fixed the out of memory
Linus Torvalds1da177e2005-04-16 15:20:36 -070034 * handling.
Jeff Garzik6aa20a22006-09-13 13:24:59 -040035 *
Linus Torvalds1da177e2005-04-16 15:20:36 -070036 * Torben Mathiasen <torben.mathiasen@compaq.com> New Maintainer!
37 *
38 * v1.1 Dec 20, 1999 - Removed linux version checking
Jeff Garzik6aa20a22006-09-13 13:24:59 -040039 * Patch from Tigran Aivazian.
Linus Torvalds1da177e2005-04-16 15:20:36 -070040 * - v1.1 includes Alan's SMP updates.
41 * - We still have problems on SMP though,
Jeff Garzik6aa20a22006-09-13 13:24:59 -040042 * but I'm looking into that.
43 *
Linus Torvalds1da177e2005-04-16 15:20:36 -070044 * v1.2 Jan 02, 2000 - Hopefully fixed the SMP deadlock.
45 * - Removed dependency of HZ being 100.
Jeff Garzik6aa20a22006-09-13 13:24:59 -040046 * - We now allow higher priority timers to
Linus Torvalds1da177e2005-04-16 15:20:36 -070047 * overwrite timers like TLAN_TIMER_ACTIVITY
48 * Patch from John Cagle <john.cagle@compaq.com>.
49 * - Fixed a few compiler warnings.
50 *
51 * v1.3 Feb 04, 2000 - Fixed the remaining HZ issues.
Jeff Garzik6aa20a22006-09-13 13:24:59 -040052 * - Removed call to pci_present().
Linus Torvalds1da177e2005-04-16 15:20:36 -070053 * - Removed SA_INTERRUPT flag from irq handler.
Jeff Garzik6aa20a22006-09-13 13:24:59 -040054 * - Added __init and __initdata to reduce resisdent
Linus Torvalds1da177e2005-04-16 15:20:36 -070055 * code size.
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.
Jeff Garzik6aa20a22006-09-13 13:24:59 -040060 * - Driver ported to new net API.
61 * - tlan.txt has been reworked to reflect current
Linus Torvalds1da177e2005-04-16 15:20:36 -070062 * driver (almost)
63 * - Other minor stuff
64 *
65 * v1.4 Feb 10, 2000 - Updated with more changes required after Dave's
Sakari Ailusc659c382011-01-21 10:59:30 +000066 * network cleanup in 2.3.43pre7 (Tigran & myself)
67 * - Minor stuff.
Linus Torvalds1da177e2005-04-16 15:20:36 -070068 *
Sakari Ailusc659c382011-01-21 10:59:30 +000069 * v1.5 March 22, 2000 - Fixed another timer bug that would hang the
70 * driver if no cable/link were present.
Linus Torvalds1da177e2005-04-16 15:20:36 -070071 * - Cosmetic changes.
72 * - TODO: Port completely to new PCI/DMA API
Sakari Ailusc659c382011-01-21 10:59:30 +000073 * Auto-Neg fallback.
Linus Torvalds1da177e2005-04-16 15:20:36 -070074 *
Sakari Ailusc659c382011-01-21 10:59:30 +000075 * 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/
Linus Torvalds1da177e2005-04-16 15:20:36 -070082 *
Sakari Ailusc659c382011-01-21 10:59:30 +000083 * 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.
Linus Torvalds1da177e2005-04-16 15:20:36 -070086 *
Sakari Ailusc659c382011-01-21 10:59:30 +000087 * 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
93 * link.
94 * Please read tlan.txt for additional information.
95 * - Removed call to check_region(), and used
96 * return value of request_region() instead.
Jeff Garzik6aa20a22006-09-13 13:24:59 -040097 *
Linus Torvalds1da177e2005-04-16 15:20:36 -070098 * v1.8a May 28, 2000 - Minor updates.
99 *
100 * v1.9 July 25, 2000 - Fixed a few remaining Full-Duplex issues.
Sakari Ailusc659c382011-01-21 10:59:30 +0000101 * - 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.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700105 *
Jeff Garzik6aa20a22006-09-13 13:24:59 -0400106 * v1.10 Aug 30, 2000 - Added support for EISA based tlan controllers
107 * like the Compaq NetFlex3/E.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700108 * - 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
Jeff Garzik6aa20a22006-09-13 13:24:59 -0400111 * hardware probe is done with kernel API and
Linus Torvalds1da177e2005-04-16 15:20:36 -0700112 * TLan_EisaProbe.
113 * - Adjusted debug information for probing.
Sakari Ailusc659c382011-01-21 10:59:30 +0000114 * - Fixed bug that would cause general debug
115 * information to be printed after driver removal.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700116 * - Added transmit timeout handling.
Jeff Garzik6aa20a22006-09-13 13:24:59 -0400117 * - Fixed OOM return values in tlan_probe.
118 * - Fixed possible mem leak in tlan_exit
Linus Torvalds1da177e2005-04-16 15:20:36 -0700119 * (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.
123 *
Jeff Garzik6aa20a22006-09-13 13:24:59 -0400124 * v1.11 Aug 31, 2000 - Do not try to register irq 0 if no irq line was
Linus Torvalds1da177e2005-04-16 15:20:36 -0700125 * 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.
136 *
137 * v1.12 Oct 12, 2000 - Minor fixes (memleak, init, etc.)
138 *
Sakari Ailusc659c382011-01-21 10:59:30 +0000139 * v1.13 Nov 28, 2000 - Stop flooding console with auto-neg issues
140 * when link can't be established.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700141 * - Added the bbuf option as a kernel parameter.
142 * - Fixed ioaddr probe bug.
143 * - Fixed stupid deadlock with MII interrupts.
Jeff Garzik6aa20a22006-09-13 13:24:59 -0400144 * - Added support for speed/duplex selection with
Linus Torvalds1da177e2005-04-16 15:20:36 -0700145 * multiple nics.
146 * - Added partly fix for TX Channel lockup with
147 * TLAN v1.0 silicon. This needs to be investigated
148 * further.
149 *
Sakari Ailusc659c382011-01-21 10:59:30 +0000150 * 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
156 * adapters.
157 * - Converted to use new taskq interface.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700158 *
Sakari Ailusc659c382011-01-21 10:59:30 +0000159 * v1.14a Jan 6, 2001 - Minor adjustments (spinlocks, etc.)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700160 *
161 * Samuel Chessman <chessman@tux.org> New Maintainer!
162 *
163 * v1.15 Apr 4, 2002 - Correct operation when aui=1 to be
Sakari Ailusc659c382011-01-21 10:59:30 +0000164 * 10T half duplex no loopback
165 * Thanks to Gunnar Eikman
Sakari Ailus5eeabf52008-12-16 15:24:05 -0800166 *
167 * Sakari Ailus <sakari.ailus@iki.fi>:
168 *
169 * v1.15a Dec 15 2008 - Remove bbuf support, it doesn't work anyway.
Sakari Ailusc659c382011-01-21 10:59:30 +0000170 * v1.16 Jan 6 2011 - Make checkpatch.pl happy.
Sakari Ailusfa6d5d42011-01-21 10:59:31 +0000171 * v1.17 Jan 6 2011 - Add suspend/resume support.
Sakari Ailus5eeabf52008-12-16 15:24:05 -0800172 *
Sakari Ailusc659c382011-01-21 10:59:30 +0000173 ******************************************************************************/
Linus Torvalds1da177e2005-04-16 15:20:36 -0700174
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>
Domen Puncer1e7f0bd2005-06-26 18:22:14 -0400180#include <linux/dma-mapping.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -0700181#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>
187
188#include "tlan.h"
189
Linus Torvalds1da177e2005-04-16 15:20:36 -0700190
191/* For removing EISA devices */
Sakari Ailusc659c382011-01-21 10:59:30 +0000192static struct net_device *tlan_eisa_devices;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700193
Sakari Ailusc659c382011-01-21 10:59:30 +0000194static int tlan_devices_installed;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700195
196/* Set speed, duplex and aui settings */
197static int aui[MAX_TLAN_BOARDS];
198static int duplex[MAX_TLAN_BOARDS];
199static int speed[MAX_TLAN_BOARDS];
200static int boards_found;
Stephen Hemminger15efa9b2005-05-04 15:33:11 -0700201module_param_array(aui, int, NULL, 0);
202module_param_array(duplex, int, NULL, 0);
203module_param_array(speed, int, NULL, 0);
204MODULE_PARM_DESC(aui, "ThunderLAN use AUI port(s) (0-1)");
Sakari Ailusc659c382011-01-21 10:59:30 +0000205MODULE_PARM_DESC(duplex,
206 "ThunderLAN duplex setting(s) (0-default, 1-half, 2-full)");
Stephen Hemminger15efa9b2005-05-04 15:33:11 -0700207MODULE_PARM_DESC(speed, "ThunderLAN port speen setting(s) (0,10,100)");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700208
209MODULE_AUTHOR("Maintainer: Samuel Chessman <chessman@tux.org>");
210MODULE_DESCRIPTION("Driver for TI ThunderLAN based ethernet PCI adapters");
211MODULE_LICENSE("GPL");
212
213
214/* Define this to enable Link beat monitoring */
215#undef MONITOR
216
217/* Turn on debugging. See Documentation/networking/tlan.txt for details */
218static int debug;
Stephen Hemminger15efa9b2005-05-04 15:33:11 -0700219module_param(debug, int, 0);
220MODULE_PARM_DESC(debug, "ThunderLAN debug mask");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700221
Sakari Ailusc659c382011-01-21 10:59:30 +0000222static const char tlan_signature[] = "TLAN";
Sakari Ailusfa6d5d42011-01-21 10:59:31 +0000223static const char tlan_banner[] = "ThunderLAN driver v1.17\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -0700224static int tlan_have_pci;
225static int tlan_have_eisa;
226
Sakari Ailusc659c382011-01-21 10:59:30 +0000227static const char * const media[] = {
228 "10BaseT-HD", "10BaseT-FD", "100baseTx-HD",
229 "100BaseTx-FD", "100BaseT4", NULL
Linus Torvalds1da177e2005-04-16 15:20:36 -0700230};
231
232static struct board {
Sakari Ailusc659c382011-01-21 10:59:30 +0000233 const char *device_label;
234 u32 flags;
235 u16 addr_ofs;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700236} board_info[] = {
237 { "Compaq Netelligent 10 T PCI UTP", TLAN_ADAPTER_ACTIVITY_LED, 0x83 },
Sakari Ailusc659c382011-01-21 10:59:30 +0000238 { "Compaq Netelligent 10/100 TX PCI UTP",
239 TLAN_ADAPTER_ACTIVITY_LED, 0x83 },
Linus Torvalds1da177e2005-04-16 15:20:36 -0700240 { "Compaq Integrated NetFlex-3/P", TLAN_ADAPTER_NONE, 0x83 },
Stephen Hemmingerdfc2c0a2008-05-30 09:49:58 -0700241 { "Compaq NetFlex-3/P",
242 TLAN_ADAPTER_UNMANAGED_PHY | TLAN_ADAPTER_BIT_RATE_PHY, 0x83 },
Linus Torvalds1da177e2005-04-16 15:20:36 -0700243 { "Compaq NetFlex-3/P", TLAN_ADAPTER_NONE, 0x83 },
Stephen Hemmingerdfc2c0a2008-05-30 09:49:58 -0700244 { "Compaq Netelligent Integrated 10/100 TX UTP",
245 TLAN_ADAPTER_ACTIVITY_LED, 0x83 },
Sakari Ailusc659c382011-01-21 10:59:30 +0000246 { "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 },
Linus Torvalds1da177e2005-04-16 15:20:36 -0700250 { "Olicom OC-2183/2185", TLAN_ADAPTER_USE_INTERN_10, 0x83 },
Sakari Ailusc659c382011-01-21 10:59:30 +0000251 { "Olicom OC-2325", TLAN_ADAPTER_UNMANAGED_PHY, 0xf8 },
252 { "Olicom OC-2326", TLAN_ADAPTER_USE_INTERN_10, 0xf8 },
Linus Torvalds1da177e2005-04-16 15:20:36 -0700253 { "Compaq Netelligent 10/100 TX UTP", TLAN_ADAPTER_ACTIVITY_LED, 0x83 },
Sakari Ailusc659c382011-01-21 10:59:30 +0000254 { "Compaq Netelligent 10 T/2 PCI UTP/coax", TLAN_ADAPTER_NONE, 0x83 },
Stephen Hemmingerdfc2c0a2008-05-30 09:49:58 -0700255 { "Compaq NetFlex-3/E",
Sakari Ailusc659c382011-01-21 10:59:30 +0000256 TLAN_ADAPTER_ACTIVITY_LED | /* EISA card */
Stephen Hemmingerdfc2c0a2008-05-30 09:49:58 -0700257 TLAN_ADAPTER_UNMANAGED_PHY | TLAN_ADAPTER_BIT_RATE_PHY, 0x83 },
Sakari Ailusc659c382011-01-21 10:59:30 +0000258 { "Compaq NetFlex-3/E",
259 TLAN_ADAPTER_ACTIVITY_LED, 0x83 }, /* EISA card */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700260};
261
Alexey Dobriyana3aa1882010-01-07 11:58:11 +0000262static DEFINE_PCI_DEVICE_TABLE(tlan_pci_tbl) = {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700263 { PCI_VENDOR_ID_COMPAQ, PCI_DEVICE_ID_COMPAQ_NETEL10,
Sakari Ailusc659c382011-01-21 10:59:30 +0000264 PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0 },
Linus Torvalds1da177e2005-04-16 15:20:36 -0700265 { PCI_VENDOR_ID_COMPAQ, PCI_DEVICE_ID_COMPAQ_NETEL100,
Sakari Ailusc659c382011-01-21 10:59:30 +0000266 PCI_ANY_ID, PCI_ANY_ID, 0, 0, 1 },
Linus Torvalds1da177e2005-04-16 15:20:36 -0700267 { PCI_VENDOR_ID_COMPAQ, PCI_DEVICE_ID_COMPAQ_NETFLEX3I,
Sakari Ailusc659c382011-01-21 10:59:30 +0000268 PCI_ANY_ID, PCI_ANY_ID, 0, 0, 2 },
Linus Torvalds1da177e2005-04-16 15:20:36 -0700269 { PCI_VENDOR_ID_COMPAQ, PCI_DEVICE_ID_COMPAQ_THUNDER,
Sakari Ailusc659c382011-01-21 10:59:30 +0000270 PCI_ANY_ID, PCI_ANY_ID, 0, 0, 3 },
Linus Torvalds1da177e2005-04-16 15:20:36 -0700271 { PCI_VENDOR_ID_COMPAQ, PCI_DEVICE_ID_COMPAQ_NETFLEX3B,
Sakari Ailusc659c382011-01-21 10:59:30 +0000272 PCI_ANY_ID, PCI_ANY_ID, 0, 0, 4 },
Linus Torvalds1da177e2005-04-16 15:20:36 -0700273 { PCI_VENDOR_ID_COMPAQ, PCI_DEVICE_ID_COMPAQ_NETEL100PI,
Sakari Ailusc659c382011-01-21 10:59:30 +0000274 PCI_ANY_ID, PCI_ANY_ID, 0, 0, 5 },
Linus Torvalds1da177e2005-04-16 15:20:36 -0700275 { PCI_VENDOR_ID_COMPAQ, PCI_DEVICE_ID_COMPAQ_NETEL100D,
Sakari Ailusc659c382011-01-21 10:59:30 +0000276 PCI_ANY_ID, PCI_ANY_ID, 0, 0, 6 },
Linus Torvalds1da177e2005-04-16 15:20:36 -0700277 { PCI_VENDOR_ID_COMPAQ, PCI_DEVICE_ID_COMPAQ_NETEL100I,
Sakari Ailusc659c382011-01-21 10:59:30 +0000278 PCI_ANY_ID, PCI_ANY_ID, 0, 0, 7 },
Linus Torvalds1da177e2005-04-16 15:20:36 -0700279 { PCI_VENDOR_ID_OLICOM, PCI_DEVICE_ID_OLICOM_OC2183,
Sakari Ailusc659c382011-01-21 10:59:30 +0000280 PCI_ANY_ID, PCI_ANY_ID, 0, 0, 8 },
Linus Torvalds1da177e2005-04-16 15:20:36 -0700281 { PCI_VENDOR_ID_OLICOM, PCI_DEVICE_ID_OLICOM_OC2325,
Sakari Ailusc659c382011-01-21 10:59:30 +0000282 PCI_ANY_ID, PCI_ANY_ID, 0, 0, 9 },
Linus Torvalds1da177e2005-04-16 15:20:36 -0700283 { PCI_VENDOR_ID_OLICOM, PCI_DEVICE_ID_OLICOM_OC2326,
Sakari Ailusc659c382011-01-21 10:59:30 +0000284 PCI_ANY_ID, PCI_ANY_ID, 0, 0, 10 },
Linus Torvalds1da177e2005-04-16 15:20:36 -0700285 { PCI_VENDOR_ID_COMPAQ, PCI_DEVICE_ID_NETELLIGENT_10_100_WS_5100,
Sakari Ailusc659c382011-01-21 10:59:30 +0000286 PCI_ANY_ID, PCI_ANY_ID, 0, 0, 11 },
Linus Torvalds1da177e2005-04-16 15:20:36 -0700287 { PCI_VENDOR_ID_COMPAQ, PCI_DEVICE_ID_NETELLIGENT_10_T2,
Sakari Ailusc659c382011-01-21 10:59:30 +0000288 PCI_ANY_ID, PCI_ANY_ID, 0, 0, 12 },
Linus Torvalds1da177e2005-04-16 15:20:36 -0700289 { 0,}
290};
Jeff Garzik6aa20a22006-09-13 13:24:59 -0400291MODULE_DEVICE_TABLE(pci, tlan_pci_tbl);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700292
Sakari Ailusc659c382011-01-21 10:59:30 +0000293static void tlan_eisa_probe(void);
294static void tlan_eisa_cleanup(void);
295static int tlan_init(struct net_device *);
296static int tlan_open(struct net_device *dev);
297static netdev_tx_t tlan_start_tx(struct sk_buff *, struct net_device *);
298static irqreturn_t tlan_handle_interrupt(int, void *);
299static int tlan_close(struct net_device *);
300static struct net_device_stats *tlan_get_stats(struct net_device *);
301static void tlan_set_multicast_list(struct net_device *);
302static int tlan_ioctl(struct net_device *dev, struct ifreq *rq, int cmd);
303static int tlan_probe1(struct pci_dev *pdev, long ioaddr,
304 int irq, int rev, const struct pci_device_id *ent);
305static void tlan_tx_timeout(struct net_device *dev);
306static void tlan_tx_timeout_work(struct work_struct *work);
307static int tlan_init_one(struct pci_dev *pdev,
308 const struct pci_device_id *ent);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700309
Sakari Ailusc659c382011-01-21 10:59:30 +0000310static u32 tlan_handle_tx_eof(struct net_device *, u16);
311static u32 tlan_handle_stat_overflow(struct net_device *, u16);
312static u32 tlan_handle_rx_eof(struct net_device *, u16);
313static u32 tlan_handle_dummy(struct net_device *, u16);
314static u32 tlan_handle_tx_eoc(struct net_device *, u16);
315static u32 tlan_handle_status_check(struct net_device *, u16);
316static u32 tlan_handle_rx_eoc(struct net_device *, u16);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700317
Sakari Ailusc659c382011-01-21 10:59:30 +0000318static void tlan_timer(unsigned long);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700319
Sakari Ailusc659c382011-01-21 10:59:30 +0000320static void tlan_reset_lists(struct net_device *);
321static void tlan_free_lists(struct net_device *);
322static void tlan_print_dio(u16);
323static void tlan_print_list(struct tlan_list *, char *, int);
324static void tlan_read_and_clear_stats(struct net_device *, int);
325static void tlan_reset_adapter(struct net_device *);
326static void tlan_finish_reset(struct net_device *);
327static void tlan_set_mac(struct net_device *, int areg, char *mac);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700328
Sakari Ailusc659c382011-01-21 10:59:30 +0000329static void tlan_phy_print(struct net_device *);
330static void tlan_phy_detect(struct net_device *);
331static void tlan_phy_power_down(struct net_device *);
332static void tlan_phy_power_up(struct net_device *);
333static void tlan_phy_reset(struct net_device *);
334static void tlan_phy_start_link(struct net_device *);
335static void tlan_phy_finish_auto_neg(struct net_device *);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700336#ifdef MONITOR
Sakari Ailusc659c382011-01-21 10:59:30 +0000337static void tlan_phy_monitor(struct net_device *);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700338#endif
339
340/*
Sakari Ailusc659c382011-01-21 10:59:30 +0000341 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 *);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700345*/
346
Sakari Ailusc659c382011-01-21 10:59:30 +0000347static bool tlan_mii_read_reg(struct net_device *, u16, u16, u16 *);
348static void tlan_mii_send_data(u16, u32, unsigned);
349static void tlan_mii_sync(u16);
350static void tlan_mii_write_reg(struct net_device *, u16, u16, u16);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700351
Sakari Ailusc659c382011-01-21 10:59:30 +0000352static void tlan_ee_send_start(u16);
353static int tlan_ee_send_byte(u16, u8, int);
354static void tlan_ee_receive_byte(u16, u8 *, int);
355static int tlan_ee_read_byte(struct net_device *, u8, u8 *);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700356
357
Stephen Hemminger93e16842008-05-30 09:49:55 -0700358static inline void
Sakari Ailusc659c382011-01-21 10:59:30 +0000359tlan_store_skb(struct tlan_list *tag, struct sk_buff *skb)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700360{
361 unsigned long addr = (unsigned long)skb;
Stephen Hemminger93e16842008-05-30 09:49:55 -0700362 tag->buffer[9].address = addr;
363 tag->buffer[8].address = upper_32_bits(addr);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700364}
365
Stephen Hemminger93e16842008-05-30 09:49:55 -0700366static inline struct sk_buff *
Sakari Ailusc659c382011-01-21 10:59:30 +0000367tlan_get_skb(const struct tlan_list *tag)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700368{
Stephen Hemminger93e16842008-05-30 09:49:55 -0700369 unsigned long addr;
370
Robert Fitzsimons0d63bea2008-08-09 17:54:02 +0100371 addr = tag->buffer[9].address;
372 addr |= (tag->buffer[8].address << 16) << 16;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700373 return (struct sk_buff *) addr;
374}
375
Sakari Ailusc659c382011-01-21 10:59:30 +0000376static u32
377(*tlan_int_vector[TLAN_INT_NUMBER_OF_INTS])(struct net_device *, u16) = {
Stephen Hemmingera3ccc782008-05-30 09:49:57 -0700378 NULL,
Sakari Ailusc659c382011-01-21 10:59:30 +0000379 tlan_handle_tx_eof,
380 tlan_handle_stat_overflow,
381 tlan_handle_rx_eof,
382 tlan_handle_dummy,
383 tlan_handle_tx_eoc,
384 tlan_handle_status_check,
385 tlan_handle_rx_eoc
Linus Torvalds1da177e2005-04-16 15:20:36 -0700386};
387
388static inline void
Sakari Ailusc659c382011-01-21 10:59:30 +0000389tlan_set_timer(struct net_device *dev, u32 ticks, u32 type)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700390{
Sakari Ailusc659c382011-01-21 10:59:30 +0000391 struct tlan_priv *priv = netdev_priv(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700392 unsigned long flags = 0;
Jeff Garzik6aa20a22006-09-13 13:24:59 -0400393
Linus Torvalds1da177e2005-04-16 15:20:36 -0700394 if (!in_irq())
395 spin_lock_irqsave(&priv->lock, flags);
Sakari Ailusc659c382011-01-21 10:59:30 +0000396 if (priv->timer.function != NULL &&
397 priv->timer_type != TLAN_TIMER_ACTIVITY) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700398 if (!in_irq())
399 spin_unlock_irqrestore(&priv->lock, flags);
400 return;
401 }
Sakari Ailusc659c382011-01-21 10:59:30 +0000402 priv->timer.function = tlan_timer;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700403 if (!in_irq())
404 spin_unlock_irqrestore(&priv->lock, flags);
405
406 priv->timer.data = (unsigned long) dev;
Sakari Ailusc659c382011-01-21 10:59:30 +0000407 priv->timer_set_at = jiffies;
408 priv->timer_type = type;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700409 mod_timer(&priv->timer, jiffies + ticks);
Jeff Garzik6aa20a22006-09-13 13:24:59 -0400410
Sakari Ailusc659c382011-01-21 10:59:30 +0000411}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700412
413
414/*****************************************************************************
415******************************************************************************
416
Sakari Ailusc659c382011-01-21 10:59:30 +0000417ThunderLAN driver primary functions
Linus Torvalds1da177e2005-04-16 15:20:36 -0700418
Sakari Ailusc659c382011-01-21 10:59:30 +0000419these functions are more or less common to all linux network drivers.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700420
421******************************************************************************
422*****************************************************************************/
423
424
425
426
427
Sakari Ailusc659c382011-01-21 10:59:30 +0000428/***************************************************************
429 * tlan_remove_one
430 *
431 * Returns:
432 * Nothing
433 * Parms:
434 * None
435 *
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.
440 *
441 **************************************************************/
Linus Torvalds1da177e2005-04-16 15:20:36 -0700442
443
Sakari Ailusc659c382011-01-21 10:59:30 +0000444static void __devexit tlan_remove_one(struct pci_dev *pdev)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700445{
Sakari Ailusc659c382011-01-21 10:59:30 +0000446 struct net_device *dev = pci_get_drvdata(pdev);
447 struct tlan_priv *priv = netdev_priv(dev);
Jeff Garzik6aa20a22006-09-13 13:24:59 -0400448
Sakari Ailusc659c382011-01-21 10:59:30 +0000449 unregister_netdev(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700450
Sakari Ailusc659c382011-01-21 10:59:30 +0000451 if (priv->dma_storage) {
452 pci_free_consistent(priv->pci_dev,
453 priv->dma_size, priv->dma_storage,
454 priv->dma_storage_dma);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700455 }
456
457#ifdef CONFIG_PCI
458 pci_release_regions(pdev);
459#endif
Jeff Garzik6aa20a22006-09-13 13:24:59 -0400460
Sakari Ailusc659c382011-01-21 10:59:30 +0000461 free_netdev(dev);
Jeff Garzik6aa20a22006-09-13 13:24:59 -0400462
Sakari Ailusc659c382011-01-21 10:59:30 +0000463 pci_set_drvdata(pdev, NULL);
Jeff Garzik6aa20a22006-09-13 13:24:59 -0400464}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700465
Sakari Ailusfa6d5d42011-01-21 10:59:31 +0000466static void tlan_start(struct net_device *dev)
467{
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.
471 */
472 tlan_read_and_clear_stats(dev, TLAN_IGNORE);
473 tlan_reset_adapter(dev);
474 netif_wake_queue(dev);
475}
476
477static void tlan_stop(struct net_device *dev)
478{
479 struct tlan_priv *priv = netdev_priv(dev);
480
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;
488 }
489}
490
491#ifdef CONFIG_PM
492
493static int tlan_suspend(struct pci_dev *pdev, pm_message_t state)
494{
495 struct net_device *dev = pci_get_drvdata(pdev);
496
497 if (netif_running(dev))
498 tlan_stop(dev);
499
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);
505
506 return 0;
507}
508
509static int tlan_resume(struct pci_dev *pdev)
510{
511 struct net_device *dev = pci_get_drvdata(pdev);
512
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);
517
518 if (netif_running(dev))
519 tlan_start(dev);
520
521 return 0;
522}
523
524#else /* CONFIG_PM */
525
526#define tlan_suspend NULL
527#define tlan_resume NULL
528
529#endif /* CONFIG_PM */
530
531
Linus Torvalds1da177e2005-04-16 15:20:36 -0700532static struct pci_driver tlan_driver = {
533 .name = "tlan",
534 .id_table = tlan_pci_tbl,
535 .probe = tlan_init_one,
Jeff Garzik6aa20a22006-09-13 13:24:59 -0400536 .remove = __devexit_p(tlan_remove_one),
Sakari Ailusfa6d5d42011-01-21 10:59:31 +0000537 .suspend = tlan_suspend,
538 .resume = tlan_resume,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700539};
540
541static int __init tlan_probe(void)
542{
Leonardo Potenza6c04a512008-02-04 23:47:16 -0800543 int rc = -ENODEV;
Jeff Garzik6aa20a22006-09-13 13:24:59 -0400544
Linus Torvalds1da177e2005-04-16 15:20:36 -0700545 printk(KERN_INFO "%s", tlan_banner);
Jeff Garzik6aa20a22006-09-13 13:24:59 -0400546
Linus Torvalds1da177e2005-04-16 15:20:36 -0700547 TLAN_DBG(TLAN_DEBUG_PROBE, "Starting PCI Probe....\n");
Jeff Garzik6aa20a22006-09-13 13:24:59 -0400548
Linus Torvalds1da177e2005-04-16 15:20:36 -0700549 /* Use new style PCI probing. Now the kernel will
550 do most of this for us */
Leonardo Potenza6c04a512008-02-04 23:47:16 -0800551 rc = pci_register_driver(&tlan_driver);
552
553 if (rc != 0) {
554 printk(KERN_ERR "TLAN: Could not register pci driver.\n");
555 goto err_out_pci_free;
556 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700557
558 TLAN_DBG(TLAN_DEBUG_PROBE, "Starting EISA Probe....\n");
Sakari Ailusc659c382011-01-21 10:59:30 +0000559 tlan_eisa_probe();
Jeff Garzik6aa20a22006-09-13 13:24:59 -0400560
561 printk(KERN_INFO "TLAN: %d device%s installed, PCI: %d EISA: %d\n",
Sakari Ailusc659c382011-01-21 10:59:30 +0000562 tlan_devices_installed, tlan_devices_installed == 1 ? "" : "s",
563 tlan_have_pci, tlan_have_eisa);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700564
Sakari Ailusc659c382011-01-21 10:59:30 +0000565 if (tlan_devices_installed == 0) {
Leonardo Potenza6c04a512008-02-04 23:47:16 -0800566 rc = -ENODEV;
567 goto err_out_pci_unreg;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700568 }
569 return 0;
Leonardo Potenza6c04a512008-02-04 23:47:16 -0800570
571err_out_pci_unreg:
572 pci_unregister_driver(&tlan_driver);
573err_out_pci_free:
Leonardo Potenza6c04a512008-02-04 23:47:16 -0800574 return rc;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700575}
Jeff Garzik6aa20a22006-09-13 13:24:59 -0400576
Linus Torvalds1da177e2005-04-16 15:20:36 -0700577
Sakari Ailusc659c382011-01-21 10:59:30 +0000578static int __devinit tlan_init_one(struct pci_dev *pdev,
579 const struct pci_device_id *ent)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700580{
Sakari Ailusc659c382011-01-21 10:59:30 +0000581 return tlan_probe1(pdev, -1, -1, 0, ent);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700582}
583
584
585/*
Sakari Ailusc659c382011-01-21 10:59:30 +0000586***************************************************************
587* tlan_probe1
588*
589* Returns:
590* 0 on success, error code on error
591* Parms:
592* none
593*
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.
601*
602**************************************************************/
Linus Torvalds1da177e2005-04-16 15:20:36 -0700603
Sakari Ailusc659c382011-01-21 10:59:30 +0000604static int __devinit tlan_probe1(struct pci_dev *pdev,
Stephen Hemmingerdfc2c0a2008-05-30 09:49:58 -0700605 long ioaddr, int irq, int rev,
Sakari Ailusc659c382011-01-21 10:59:30 +0000606 const struct pci_device_id *ent)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700607{
608
609 struct net_device *dev;
Sakari Ailusc659c382011-01-21 10:59:30 +0000610 struct tlan_priv *priv;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700611 u16 device_id;
612 int reg, rc = -ENODEV;
613
Adrian Bunkad9f6712006-02-05 00:37:47 +0100614#ifdef CONFIG_PCI
Linus Torvalds1da177e2005-04-16 15:20:36 -0700615 if (pdev) {
616 rc = pci_enable_device(pdev);
617 if (rc)
618 return rc;
619
Sakari Ailusc659c382011-01-21 10:59:30 +0000620 rc = pci_request_regions(pdev, tlan_signature);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700621 if (rc) {
622 printk(KERN_ERR "TLAN: Could not reserve IO regions\n");
623 goto err_out;
624 }
625 }
Adrian Bunkad9f6712006-02-05 00:37:47 +0100626#endif /* CONFIG_PCI */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700627
Sakari Ailusc659c382011-01-21 10:59:30 +0000628 dev = alloc_etherdev(sizeof(struct tlan_priv));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700629 if (dev == NULL) {
630 printk(KERN_ERR "TLAN: Could not allocate memory for device.\n");
631 rc = -ENOMEM;
632 goto err_out_regions;
633 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700634 SET_NETDEV_DEV(dev, &pdev->dev);
Jeff Garzik6aa20a22006-09-13 13:24:59 -0400635
Linus Torvalds1da177e2005-04-16 15:20:36 -0700636 priv = netdev_priv(dev);
637
Sakari Ailusc659c382011-01-21 10:59:30 +0000638 priv->pci_dev = pdev;
David Howellsc4028952006-11-22 14:57:56 +0000639 priv->dev = dev;
Jeff Garzik6aa20a22006-09-13 13:24:59 -0400640
Linus Torvalds1da177e2005-04-16 15:20:36 -0700641 /* Is this a PCI device? */
642 if (pdev) {
Sakari Ailusc659c382011-01-21 10:59:30 +0000643 u32 pci_io_base = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700644
645 priv->adapter = &board_info[ent->driver_data];
646
Yang Hongyang284901a2009-04-06 19:01:15 -0700647 rc = pci_set_dma_mask(pdev, DMA_BIT_MASK(32));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700648 if (rc) {
Sakari Ailusc659c382011-01-21 10:59:30 +0000649 printk(KERN_ERR
650 "TLAN: No suitable PCI mapping available.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700651 goto err_out_free_dev;
652 }
653
Sakari Ailusc659c382011-01-21 10:59:30 +0000654 for (reg = 0; reg <= 5; reg++) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700655 if (pci_resource_flags(pdev, reg) & IORESOURCE_IO) {
656 pci_io_base = pci_resource_start(pdev, reg);
Sakari Ailusc659c382011-01-21 10:59:30 +0000657 TLAN_DBG(TLAN_DEBUG_GNRL,
658 "IO mapping is available at %x.\n",
659 pci_io_base);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700660 break;
661 }
662 }
663 if (!pci_io_base) {
664 printk(KERN_ERR "TLAN: No IO mappings available\n");
665 rc = -EIO;
666 goto err_out_free_dev;
667 }
Jeff Garzik6aa20a22006-09-13 13:24:59 -0400668
Linus Torvalds1da177e2005-04-16 15:20:36 -0700669 dev->base_addr = pci_io_base;
670 dev->irq = pdev->irq;
Sakari Ailusc659c382011-01-21 10:59:30 +0000671 priv->adapter_rev = pdev->revision;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700672 pci_set_master(pdev);
673 pci_set_drvdata(pdev, dev);
674
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);
679 priv->is_eisa = 1;
680 if (device_id == 0x20F1) {
Sakari Ailusc659c382011-01-21 10:59:30 +0000681 priv->adapter = &board_info[13]; /* NetFlex-3/E */
682 priv->adapter_rev = 23; /* TLAN 2.3 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700683 } else {
684 priv->adapter = &board_info[14];
Sakari Ailusc659c382011-01-21 10:59:30 +0000685 priv->adapter_rev = 10; /* TLAN 1.0 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700686 }
687 dev->base_addr = ioaddr;
688 dev->irq = irq;
689 }
690
691 /* Kernel parameters */
692 if (dev->mem_start) {
693 priv->aui = dev->mem_start & 0x01;
Stephen Hemmingerdfc2c0a2008-05-30 09:49:58 -0700694 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;
Jeff Garzik6aa20a22006-09-13 13:24:59 -0400698
Sakari Ailusc659c382011-01-21 10:59:30 +0000699 if (priv->speed == 0x1)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700700 priv->speed = TLAN_SPEED_10;
Sakari Ailusc659c382011-01-21 10:59:30 +0000701 else if (priv->speed == 0x2)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700702 priv->speed = TLAN_SPEED_100;
Sakari Ailusc659c382011-01-21 10:59:30 +0000703
Linus Torvalds1da177e2005-04-16 15:20:36 -0700704 debug = priv->debug = dev->mem_end;
705 } else {
706 priv->aui = aui[boards_found];
707 priv->speed = speed[boards_found];
708 priv->duplex = duplex[boards_found];
709 priv->debug = debug;
710 }
Jeff Garzik6aa20a22006-09-13 13:24:59 -0400711
Linus Torvalds1da177e2005-04-16 15:20:36 -0700712 /* This will be used when we get an adapter error from
713 * within our irq handler */
Sakari Ailusc659c382011-01-21 10:59:30 +0000714 INIT_WORK(&priv->tlan_tqueue, tlan_tx_timeout_work);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700715
716 spin_lock_init(&priv->lock);
Jeff Garzik6aa20a22006-09-13 13:24:59 -0400717
Sakari Ailusc659c382011-01-21 10:59:30 +0000718 rc = tlan_init(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700719 if (rc) {
720 printk(KERN_ERR "TLAN: Could not set up device.\n");
721 goto err_out_free_dev;
722 }
723
724 rc = register_netdev(dev);
725 if (rc) {
726 printk(KERN_ERR "TLAN: Could not register device.\n");
727 goto err_out_uninit;
728 }
729
Jeff Garzik6aa20a22006-09-13 13:24:59 -0400730
Sakari Ailusc659c382011-01-21 10:59:30 +0000731 tlan_devices_installed++;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700732 boards_found++;
Jeff Garzik6aa20a22006-09-13 13:24:59 -0400733
Linus Torvalds1da177e2005-04-16 15:20:36 -0700734 /* pdev is NULL if this is an EISA device */
735 if (pdev)
736 tlan_have_pci++;
737 else {
Sakari Ailusc659c382011-01-21 10:59:30 +0000738 priv->next_device = tlan_eisa_devices;
739 tlan_eisa_devices = dev;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700740 tlan_have_eisa++;
741 }
Jeff Garzik6aa20a22006-09-13 13:24:59 -0400742
Linus Torvalds1da177e2005-04-16 15:20:36 -0700743 printk(KERN_INFO "TLAN: %s irq=%2d, io=%04x, %s, Rev. %d\n",
Sakari Ailusc659c382011-01-21 10:59:30 +0000744 dev->name,
745 (int) dev->irq,
746 (int) dev->base_addr,
747 priv->adapter->device_label,
748 priv->adapter_rev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700749 return 0;
750
751err_out_uninit:
Sakari Ailusc659c382011-01-21 10:59:30 +0000752 pci_free_consistent(priv->pci_dev, priv->dma_size, priv->dma_storage,
753 priv->dma_storage_dma);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700754err_out_free_dev:
755 free_netdev(dev);
756err_out_regions:
757#ifdef CONFIG_PCI
758 if (pdev)
759 pci_release_regions(pdev);
760#endif
761err_out:
762 if (pdev)
763 pci_disable_device(pdev);
764 return rc;
765}
766
767
Sakari Ailusc659c382011-01-21 10:59:30 +0000768static void tlan_eisa_cleanup(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700769{
770 struct net_device *dev;
Sakari Ailusc659c382011-01-21 10:59:30 +0000771 struct tlan_priv *priv;
Jeff Garzik6aa20a22006-09-13 13:24:59 -0400772
Sakari Ailusc659c382011-01-21 10:59:30 +0000773 while (tlan_have_eisa) {
774 dev = tlan_eisa_devices;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700775 priv = netdev_priv(dev);
Sakari Ailusc659c382011-01-21 10:59:30 +0000776 if (priv->dma_storage) {
777 pci_free_consistent(priv->pci_dev, priv->dma_size,
778 priv->dma_storage,
779 priv->dma_storage_dma);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700780 }
Sakari Ailusc659c382011-01-21 10:59:30 +0000781 release_region(dev->base_addr, 0x10);
782 unregister_netdev(dev);
783 tlan_eisa_devices = priv->next_device;
784 free_netdev(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700785 tlan_have_eisa--;
786 }
787}
Jeff Garzik6aa20a22006-09-13 13:24:59 -0400788
789
Linus Torvalds1da177e2005-04-16 15:20:36 -0700790static void __exit tlan_exit(void)
791{
792 pci_unregister_driver(&tlan_driver);
793
794 if (tlan_have_eisa)
Sakari Ailusc659c382011-01-21 10:59:30 +0000795 tlan_eisa_cleanup();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700796
Linus Torvalds1da177e2005-04-16 15:20:36 -0700797}
798
799
800/* Module loading/unloading */
801module_init(tlan_probe);
802module_exit(tlan_exit);
803
804
805
Sakari Ailusc659c382011-01-21 10:59:30 +0000806/**************************************************************
807 * tlan_eisa_probe
808 *
809 * Returns: 0 on success, 1 otherwise
810 *
811 * Parms: None
812 *
813 *
814 * This functions probes for EISA devices and calls
815 * TLan_probe1 when one is found.
816 *
817 *************************************************************/
Linus Torvalds1da177e2005-04-16 15:20:36 -0700818
Sakari Ailusc659c382011-01-21 10:59:30 +0000819static void __init tlan_eisa_probe(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700820{
Sakari Ailusc659c382011-01-21 10:59:30 +0000821 long ioaddr;
822 int rc = -ENODEV;
823 int irq;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700824 u16 device_id;
825
Jeff Garzik6aa20a22006-09-13 13:24:59 -0400826 if (!EISA_bus) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700827 TLAN_DBG(TLAN_DEBUG_PROBE, "No EISA bus present\n");
828 return;
829 }
Jeff Garzik6aa20a22006-09-13 13:24:59 -0400830
Linus Torvalds1da177e2005-04-16 15:20:36 -0700831 /* Loop through all slots of the EISA bus */
832 for (ioaddr = 0x1000; ioaddr < 0x9000; ioaddr += 0x1000) {
Jeff Garzik6aa20a22006-09-13 13:24:59 -0400833
Sakari Ailusc659c382011-01-21 10:59:30 +0000834 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));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700838
839
Sakari Ailusc659c382011-01-21 10:59:30 +0000840 TLAN_DBG(TLAN_DEBUG_PROBE,
841 "Probing for EISA adapter at IO: 0x%4x : ",
842 (int) ioaddr);
843 if (request_region(ioaddr, 0x10, tlan_signature) == NULL)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700844 goto out;
845
Jeff Garzik6aa20a22006-09-13 13:24:59 -0400846 if (inw(ioaddr + EISA_ID) != 0x110E) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700847 release_region(ioaddr, 0x10);
848 goto out;
849 }
Jeff Garzik6aa20a22006-09-13 13:24:59 -0400850
Linus Torvalds1da177e2005-04-16 15:20:36 -0700851 device_id = inw(ioaddr + EISA_ID2);
Jeff Garzik6aa20a22006-09-13 13:24:59 -0400852 if (device_id != 0x20F1 && device_id != 0x40F1) {
Sakari Ailusc659c382011-01-21 10:59:30 +0000853 release_region(ioaddr, 0x10);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700854 goto out;
855 }
Jeff Garzik6aa20a22006-09-13 13:24:59 -0400856
Sakari Ailusc659c382011-01-21 10:59:30 +0000857 /* check if adapter is enabled */
858 if (inb(ioaddr + EISA_CR) != 0x1) {
859 release_region(ioaddr, 0x10);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700860 goto out2;
861 }
Jeff Garzik6aa20a22006-09-13 13:24:59 -0400862
863 if (debug == 0x10)
Sakari Ailusc659c382011-01-21 10:59:30 +0000864 printk(KERN_INFO "Found one\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700865
866
867 /* Get irq from board */
Sakari Ailusc659c382011-01-21 10:59:30 +0000868 switch (inb(ioaddr + 0xcc0)) {
869 case(0x10):
870 irq = 5;
871 break;
872 case(0x20):
873 irq = 9;
874 break;
875 case(0x40):
876 irq = 10;
877 break;
878 case(0x80):
879 irq = 11;
880 break;
881 default:
882 goto out;
Jeff Garzik6aa20a22006-09-13 13:24:59 -0400883 }
884
885
Linus Torvalds1da177e2005-04-16 15:20:36 -0700886 /* Setup the newly found eisa adapter */
Sakari Ailusc659c382011-01-21 10:59:30 +0000887 rc = tlan_probe1(NULL, ioaddr, irq,
888 12, NULL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700889 continue;
Jeff Garzik6aa20a22006-09-13 13:24:59 -0400890
Sakari Ailusc659c382011-01-21 10:59:30 +0000891out:
892 if (debug == 0x10)
893 printk(KERN_INFO "None found\n");
894 continue;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700895
Sakari Ailusc659c382011-01-21 10:59:30 +0000896out2:
897 if (debug == 0x10)
898 printk(KERN_INFO "Card found but it is not enabled, skipping\n");
899 continue;
Jeff Garzik6aa20a22006-09-13 13:24:59 -0400900
Linus Torvalds1da177e2005-04-16 15:20:36 -0700901 }
902
Sakari Ailusc659c382011-01-21 10:59:30 +0000903}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700904
905#ifdef CONFIG_NET_POLL_CONTROLLER
Sakari Ailusc659c382011-01-21 10:59:30 +0000906static void tlan_poll(struct net_device *dev)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700907{
908 disable_irq(dev->irq);
Sakari Ailusc659c382011-01-21 10:59:30 +0000909 tlan_handle_interrupt(dev->irq, dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700910 enable_irq(dev->irq);
911}
912#endif
913
Sakari Ailusc659c382011-01-21 10:59:30 +0000914static 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,
Stephen Hemminger391c5e62009-01-07 17:27:15 -0800922 .ndo_change_mtu = eth_change_mtu,
Sakari Ailusc659c382011-01-21 10:59:30 +0000923 .ndo_set_mac_address = eth_mac_addr,
Stephen Hemminger391c5e62009-01-07 17:27:15 -0800924 .ndo_validate_addr = eth_validate_addr,
925#ifdef CONFIG_NET_POLL_CONTROLLER
Sakari Ailusc659c382011-01-21 10:59:30 +0000926 .ndo_poll_controller = tlan_poll,
Stephen Hemminger391c5e62009-01-07 17:27:15 -0800927#endif
928};
Jeff Garzik6aa20a22006-09-13 13:24:59 -0400929
Linus Torvalds1da177e2005-04-16 15:20:36 -0700930
931
Sakari Ailusc659c382011-01-21 10:59:30 +0000932/***************************************************************
933 * tlan_init
934 *
935 * Returns:
936 * 0 on success, error code otherwise.
937 * Parms:
938 * dev The structure of the device to be
939 * init'ed.
940 *
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.
946 *
947 **************************************************************/
Linus Torvalds1da177e2005-04-16 15:20:36 -0700948
Sakari Ailusc659c382011-01-21 10:59:30 +0000949static int tlan_init(struct net_device *dev)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700950{
951 int dma_size;
Sakari Ailusc659c382011-01-21 10:59:30 +0000952 int err;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700953 int i;
Sakari Ailusc659c382011-01-21 10:59:30 +0000954 struct tlan_priv *priv;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700955
956 priv = netdev_priv(dev);
Jeff Garzik6aa20a22006-09-13 13:24:59 -0400957
Sakari Ailusc659c382011-01-21 10:59:30 +0000958 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,
961 dma_size,
962 &priv->dma_storage_dma);
963 priv->dma_size = dma_size;
Jeff Garzik6aa20a22006-09-13 13:24:59 -0400964
Sakari Ailusc659c382011-01-21 10:59:30 +0000965 if (priv->dma_storage == NULL) {
966 printk(KERN_ERR
967 "TLAN: Could not allocate lists and buffers for %s.\n",
968 dev->name);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700969 return -ENOMEM;
970 }
Sakari Ailusc659c382011-01-21 10:59:30 +0000971 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;
976 priv->tx_list_dma =
977 priv->rx_list_dma + sizeof(struct tlan_list)*TLAN_NUM_RX_LISTS;
Stephen Hemminger93e16842008-05-30 09:49:55 -0700978
Linus Torvalds1da177e2005-04-16 15:20:36 -0700979 err = 0;
Sakari Ailusc659c382011-01-21 10:59:30 +0000980 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]);
984 if (err) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700985 printk(KERN_ERR "TLAN: %s: Error reading MAC from eeprom: %d\n",
Sakari Ailusc659c382011-01-21 10:59:30 +0000986 dev->name,
987 err);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700988 }
989 dev->addr_len = 6;
990
991 netif_carrier_off(dev);
992
993 /* Device methods */
Sakari Ailusc659c382011-01-21 10:59:30 +0000994 dev->netdev_ops = &tlan_netdev_ops;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700995 dev->watchdog_timeo = TX_TIMEOUT;
996
997 return 0;
998
Sakari Ailusc659c382011-01-21 10:59:30 +0000999}
Linus Torvalds1da177e2005-04-16 15:20:36 -07001000
1001
1002
1003
Sakari Ailusc659c382011-01-21 10:59:30 +00001004/***************************************************************
1005 * tlan_open
1006 *
1007 * Returns:
1008 * 0 on success, error code otherwise.
1009 * Parms:
1010 * dev Structure of device to be opened.
1011 *
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.
1018 *
1019 **************************************************************/
Linus Torvalds1da177e2005-04-16 15:20:36 -07001020
Sakari Ailusc659c382011-01-21 10:59:30 +00001021static int tlan_open(struct net_device *dev)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001022{
Sakari Ailusc659c382011-01-21 10:59:30 +00001023 struct tlan_priv *priv = netdev_priv(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001024 int err;
Jeff Garzik6aa20a22006-09-13 13:24:59 -04001025
Sakari Ailusc659c382011-01-21 10:59:30 +00001026 priv->tlan_rev = tlan_dio_read8(dev->base_addr, TLAN_DEF_REVISION);
1027 err = request_irq(dev->irq, tlan_handle_interrupt, IRQF_SHARED,
1028 dev->name, dev);
Jeff Garzik6aa20a22006-09-13 13:24:59 -04001029
Sakari Ailusc659c382011-01-21 10:59:30 +00001030 if (err) {
Stephen Hemmingerdfc2c0a2008-05-30 09:49:58 -07001031 pr_err("TLAN: Cannot open %s because IRQ %d is already in use.\n",
Sakari Ailusc659c382011-01-21 10:59:30 +00001032 dev->name, dev->irq);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001033 return err;
1034 }
Jeff Garzik6aa20a22006-09-13 13:24:59 -04001035
Linus Torvalds1da177e2005-04-16 15:20:36 -07001036 init_timer(&priv->timer);
Jeff Garzik6aa20a22006-09-13 13:24:59 -04001037
Sakari Ailusfa6d5d42011-01-21 10:59:31 +00001038 tlan_start(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001039
Sakari Ailusc659c382011-01-21 10:59:30 +00001040 TLAN_DBG(TLAN_DEBUG_GNRL, "%s: Opened. TLAN Chip Rev: %x\n",
1041 dev->name, priv->tlan_rev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001042
1043 return 0;
1044
Sakari Ailusc659c382011-01-21 10:59:30 +00001045}
Linus Torvalds1da177e2005-04-16 15:20:36 -07001046
1047
1048
Sakari Ailusc659c382011-01-21 10:59:30 +00001049/**************************************************************
1050 * tlan_ioctl
1051 *
1052 * Returns:
1053 * 0 on success, error code otherwise
1054 * Params:
1055 * dev structure of device to receive ioctl.
1056 *
1057 * rq ifreq structure to hold userspace data.
1058 *
1059 * cmd ioctl command.
1060 *
1061 *
1062 *************************************************************/
Linus Torvalds1da177e2005-04-16 15:20:36 -07001063
Sakari Ailusc659c382011-01-21 10:59:30 +00001064static int tlan_ioctl(struct net_device *dev, struct ifreq *rq, int cmd)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001065{
Sakari Ailusc659c382011-01-21 10:59:30 +00001066 struct tlan_priv *priv = netdev_priv(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001067 struct mii_ioctl_data *data = if_mii(rq);
Sakari Ailusc659c382011-01-21 10:59:30 +00001068 u32 phy = priv->phy[priv->phy_num];
Jeff Garzik6aa20a22006-09-13 13:24:59 -04001069
Sakari Ailusc659c382011-01-21 10:59:30 +00001070 if (!priv->phy_online)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001071 return -EAGAIN;
1072
Sakari Ailusc659c382011-01-21 10:59:30 +00001073 switch (cmd) {
1074 case SIOCGMIIPHY: /* get address of MII PHY in use. */
1075 data->phy_id = phy;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001076
1077
Sakari Ailusc659c382011-01-21 10:59:30 +00001078 case SIOCGMIIREG: /* read MII PHY register. */
1079 tlan_mii_read_reg(dev, data->phy_id & 0x1f,
1080 data->reg_num & 0x1f, &data->val_out);
1081 return 0;
Jeff Garzik6aa20a22006-09-13 13:24:59 -04001082
Linus Torvalds1da177e2005-04-16 15:20:36 -07001083
Sakari Ailusc659c382011-01-21 10:59:30 +00001084 case SIOCSMIIREG: /* write MII PHY register. */
1085 tlan_mii_write_reg(dev, data->phy_id & 0x1f,
1086 data->reg_num & 0x1f, data->val_in);
1087 return 0;
1088 default:
1089 return -EOPNOTSUPP;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001090 }
Sakari Ailusc659c382011-01-21 10:59:30 +00001091}
Linus Torvalds1da177e2005-04-16 15:20:36 -07001092
1093
Sakari Ailusc659c382011-01-21 10:59:30 +00001094/***************************************************************
1095 * tlan_tx_timeout
1096 *
1097 * Returns: nothing
1098 *
1099 * Params:
1100 * dev structure of device which timed out
1101 * during transmit.
1102 *
1103 **************************************************************/
Linus Torvalds1da177e2005-04-16 15:20:36 -07001104
Sakari Ailusc659c382011-01-21 10:59:30 +00001105static void tlan_tx_timeout(struct net_device *dev)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001106{
Jeff Garzik6aa20a22006-09-13 13:24:59 -04001107
Sakari Ailusc659c382011-01-21 10:59:30 +00001108 TLAN_DBG(TLAN_DEBUG_GNRL, "%s: Transmit timed out.\n", dev->name);
Jeff Garzik6aa20a22006-09-13 13:24:59 -04001109
Linus Torvalds1da177e2005-04-16 15:20:36 -07001110 /* Ok so we timed out, lets see what we can do about it...*/
Sakari Ailusc659c382011-01-21 10:59:30 +00001111 tlan_free_lists(dev);
1112 tlan_reset_lists(dev);
1113 tlan_read_and_clear_stats(dev, TLAN_IGNORE);
1114 tlan_reset_adapter(dev);
Eric Dumazet1ae5dc32010-05-10 05:01:31 -07001115 dev->trans_start = jiffies; /* prevent tx timeout */
Sakari Ailusc659c382011-01-21 10:59:30 +00001116 netif_wake_queue(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001117
1118}
Jeff Garzik6aa20a22006-09-13 13:24:59 -04001119
Linus Torvalds1da177e2005-04-16 15:20:36 -07001120
Sakari Ailusc659c382011-01-21 10:59:30 +00001121/***************************************************************
1122 * tlan_tx_timeout_work
1123 *
1124 * Returns: nothing
1125 *
1126 * Params:
1127 * work work item of device which timed out
1128 *
1129 **************************************************************/
David Howellsc4028952006-11-22 14:57:56 +00001130
Sakari Ailusc659c382011-01-21 10:59:30 +00001131static void tlan_tx_timeout_work(struct work_struct *work)
David Howellsc4028952006-11-22 14:57:56 +00001132{
Sakari Ailusc659c382011-01-21 10:59:30 +00001133 struct tlan_priv *priv =
1134 container_of(work, struct tlan_priv, tlan_tqueue);
David Howellsc4028952006-11-22 14:57:56 +00001135
Sakari Ailusc659c382011-01-21 10:59:30 +00001136 tlan_tx_timeout(priv->dev);
David Howellsc4028952006-11-22 14:57:56 +00001137}
1138
1139
Linus Torvalds1da177e2005-04-16 15:20:36 -07001140
Sakari Ailusc659c382011-01-21 10:59:30 +00001141/***************************************************************
1142 * tlan_start_tx
1143 *
1144 * Returns:
1145 * 0 on success, non-zero on failure.
1146 * Parms:
1147 * skb A pointer to the sk_buff containing the
1148 * frame to be sent.
1149 * dev The device to send the data on.
1150 *
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.
1159 *
1160 **************************************************************/
Linus Torvalds1da177e2005-04-16 15:20:36 -07001161
Sakari Ailusc659c382011-01-21 10:59:30 +00001162static netdev_tx_t tlan_start_tx(struct sk_buff *skb, struct net_device *dev)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001163{
Sakari Ailusc659c382011-01-21 10:59:30 +00001164 struct tlan_priv *priv = netdev_priv(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001165 dma_addr_t tail_list_phys;
Sakari Ailusc659c382011-01-21 10:59:30 +00001166 struct tlan_list *tail_list;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001167 unsigned long flags;
Sakari Ailus8953f122008-12-16 01:44:05 -08001168 unsigned int txlen;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001169
Sakari Ailusc659c382011-01-21 10:59:30 +00001170 if (!priv->phy_online) {
1171 TLAN_DBG(TLAN_DEBUG_TX, "TRANSMIT: %s PHY is not ready\n",
1172 dev->name);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001173 dev_kfree_skb_any(skb);
Patrick McHardy6ed10652009-06-23 06:03:08 +00001174 return NETDEV_TX_OK;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001175 }
1176
Stephen Hemminger41873e92008-05-30 09:49:52 -07001177 if (skb_padto(skb, TLAN_MIN_FRAME_SIZE))
Patrick McHardy6ed10652009-06-23 06:03:08 +00001178 return NETDEV_TX_OK;
Sakari Ailus8953f122008-12-16 01:44:05 -08001179 txlen = max(skb->len, (unsigned int)TLAN_MIN_FRAME_SIZE);
Stephen Hemminger41873e92008-05-30 09:49:52 -07001180
Sakari Ailusc659c382011-01-21 10:59:30 +00001181 tail_list = priv->tx_list + priv->tx_tail;
1182 tail_list_phys =
1183 priv->tx_list_dma + sizeof(struct tlan_list)*priv->tx_tail;
Jeff Garzik6aa20a22006-09-13 13:24:59 -04001184
Sakari Ailusc659c382011-01-21 10:59:30 +00001185 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);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001189 netif_stop_queue(dev);
Sakari Ailusc659c382011-01-21 10:59:30 +00001190 priv->tx_busy_count++;
Patrick McHardy5b548142009-06-12 06:22:29 +00001191 return NETDEV_TX_BUSY;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001192 }
1193
1194 tail_list->forward = 0;
1195
Sakari Ailusc659c382011-01-21 10:59:30 +00001196 tail_list->buffer[0].address = pci_map_single(priv->pci_dev,
Sakari Ailus5eeabf52008-12-16 15:24:05 -08001197 skb->data, txlen,
1198 PCI_DMA_TODEVICE);
Sakari Ailusc659c382011-01-21 10:59:30 +00001199 tlan_store_skb(tail_list, skb);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001200
Sakari Ailusc659c382011-01-21 10:59:30 +00001201 tail_list->frame_size = (u16) txlen;
Sakari Ailus8953f122008-12-16 01:44:05 -08001202 tail_list->buffer[0].count = TLAN_LAST_BUFFER | (u32) txlen;
Stephen Hemminger41873e92008-05-30 09:49:52 -07001203 tail_list->buffer[1].count = 0;
1204 tail_list->buffer[1].address = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001205
1206 spin_lock_irqsave(&priv->lock, flags);
Sakari Ailusc659c382011-01-21 10:59:30 +00001207 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",
1212 priv->tx_tail);
1213 outl(tail_list_phys, dev->base_addr + TLAN_CH_PARM);
1214 outl(TLAN_HC_GO, dev->base_addr + TLAN_HOST_CMD);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001215 } else {
Sakari Ailusc659c382011-01-21 10:59:30 +00001216 TLAN_DBG(TLAN_DEBUG_TX,
1217 "TRANSMIT: Adding buffer %d to TX channel\n",
1218 priv->tx_tail);
1219 if (priv->tx_tail == 0) {
1220 (priv->tx_list + (TLAN_NUM_TX_LISTS - 1))->forward
Stephen Hemmingerdfc2c0a2008-05-30 09:49:58 -07001221 = tail_list_phys;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001222 } else {
Sakari Ailusc659c382011-01-21 10:59:30 +00001223 (priv->tx_list + (priv->tx_tail - 1))->forward
Stephen Hemmingerdfc2c0a2008-05-30 09:49:58 -07001224 = tail_list_phys;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001225 }
1226 }
1227 spin_unlock_irqrestore(&priv->lock, flags);
1228
Sakari Ailusc659c382011-01-21 10:59:30 +00001229 CIRC_INC(priv->tx_tail, TLAN_NUM_TX_LISTS);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001230
Patrick McHardy6ed10652009-06-23 06:03:08 +00001231 return NETDEV_TX_OK;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001232
Sakari Ailusc659c382011-01-21 10:59:30 +00001233}
Linus Torvalds1da177e2005-04-16 15:20:36 -07001234
1235
1236
1237
Sakari Ailusc659c382011-01-21 10:59:30 +00001238/***************************************************************
1239 * tlan_handle_interrupt
1240 *
1241 * Returns:
1242 * Nothing
1243 * Parms:
1244 * irq The line on which the interrupt
1245 * occurred.
1246 * dev_id A pointer to the device assigned to
1247 * this irq line.
1248 *
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.
1255 *
1256 **************************************************************/
Linus Torvalds1da177e2005-04-16 15:20:36 -07001257
Sakari Ailusc659c382011-01-21 10:59:30 +00001258static irqreturn_t tlan_handle_interrupt(int irq, void *dev_id)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001259{
Stephen Hemmingera3ccc782008-05-30 09:49:57 -07001260 struct net_device *dev = dev_id;
Sakari Ailusc659c382011-01-21 10:59:30 +00001261 struct tlan_priv *priv = netdev_priv(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001262 u16 host_int;
Stephen Hemmingera3ccc782008-05-30 09:49:57 -07001263 u16 type;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001264
1265 spin_lock(&priv->lock);
1266
Sakari Ailusc659c382011-01-21 10:59:30 +00001267 host_int = inw(dev->base_addr + TLAN_HOST_INT);
1268 type = (host_int & TLAN_HI_IT_MASK) >> 2;
1269 if (type) {
Stephen Hemmingera3ccc782008-05-30 09:49:57 -07001270 u32 ack;
1271 u32 host_cmd;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001272
Sakari Ailusc659c382011-01-21 10:59:30 +00001273 outw(host_int, dev->base_addr + TLAN_HOST_INT);
1274 ack = tlan_int_vector[type](dev, host_int);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001275
Sakari Ailusc659c382011-01-21 10:59:30 +00001276 if (ack) {
1277 host_cmd = TLAN_HC_ACK | ack | (type << 18);
1278 outl(host_cmd, dev->base_addr + TLAN_HOST_CMD);
Stephen Hemmingera3ccc782008-05-30 09:49:57 -07001279 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001280 }
1281
1282 spin_unlock(&priv->lock);
1283
Stephen Hemmingera3ccc782008-05-30 09:49:57 -07001284 return IRQ_RETVAL(type);
Sakari Ailusc659c382011-01-21 10:59:30 +00001285}
Linus Torvalds1da177e2005-04-16 15:20:36 -07001286
1287
1288
1289
Sakari Ailusc659c382011-01-21 10:59:30 +00001290/***************************************************************
1291 * tlan_close
1292 *
1293 * Returns:
1294 * An error code.
1295 * Parms:
1296 * dev The device structure of the device to
1297 * close.
1298 *
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.
1302 *
1303 **************************************************************/
Linus Torvalds1da177e2005-04-16 15:20:36 -07001304
Sakari Ailusc659c382011-01-21 10:59:30 +00001305static int tlan_close(struct net_device *dev)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001306{
Sakari Ailusc659c382011-01-21 10:59:30 +00001307 struct tlan_priv *priv = netdev_priv(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001308
Linus Torvalds1da177e2005-04-16 15:20:36 -07001309 priv->neg_be_verbose = 0;
Sakari Ailusfa6d5d42011-01-21 10:59:31 +00001310 tlan_stop(dev);
Jeff Garzik6aa20a22006-09-13 13:24:59 -04001311
Sakari Ailusc659c382011-01-21 10:59:30 +00001312 free_irq(dev->irq, dev);
1313 tlan_free_lists(dev);
1314 TLAN_DBG(TLAN_DEBUG_GNRL, "Device %s closed.\n", dev->name);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001315
1316 return 0;
1317
Sakari Ailusc659c382011-01-21 10:59:30 +00001318}
Linus Torvalds1da177e2005-04-16 15:20:36 -07001319
1320
1321
1322
Sakari Ailusc659c382011-01-21 10:59:30 +00001323/***************************************************************
1324 * tlan_get_stats
1325 *
1326 * Returns:
1327 * A pointer to the device's statistics structure.
1328 * Parms:
1329 * dev The device structure to return the
1330 * stats for.
1331 *
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.
1335 *
1336 **************************************************************/
Linus Torvalds1da177e2005-04-16 15:20:36 -07001337
Sakari Ailusc659c382011-01-21 10:59:30 +00001338static struct net_device_stats *tlan_get_stats(struct net_device *dev)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001339{
Sakari Ailusc659c382011-01-21 10:59:30 +00001340 struct tlan_priv *priv = netdev_priv(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001341 int i;
1342
1343 /* Should only read stats if open ? */
Sakari Ailusc659c382011-01-21 10:59:30 +00001344 tlan_read_and_clear_stats(dev, TLAN_RECORD);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001345
Sakari Ailusc659c382011-01-21 10:59:30 +00001346 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);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001353 }
Sakari Ailusc659c382011-01-21 10:59:30 +00001354 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);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001359 }
Jeff Garzik6aa20a22006-09-13 13:24:59 -04001360
Stephen Hemmingerf8f31542008-05-30 09:49:53 -07001361 return &dev->stats;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001362
Sakari Ailusc659c382011-01-21 10:59:30 +00001363}
Linus Torvalds1da177e2005-04-16 15:20:36 -07001364
1365
1366
1367
Sakari Ailusc659c382011-01-21 10:59:30 +00001368/***************************************************************
1369 * tlan_set_multicast_list
1370 *
1371 * Returns:
1372 * Nothing
1373 * Parms:
1374 * dev The device structure to set the
1375 * multicast list for.
1376 *
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.
1385 *
1386 **************************************************************/
Linus Torvalds1da177e2005-04-16 15:20:36 -07001387
Sakari Ailusc659c382011-01-21 10:59:30 +00001388static void tlan_set_multicast_list(struct net_device *dev)
Jeff Garzik6aa20a22006-09-13 13:24:59 -04001389{
Jiri Pirko22bedad32010-04-01 21:22:57 +00001390 struct netdev_hw_addr *ha;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001391 u32 hash1 = 0;
1392 u32 hash2 = 0;
1393 int i;
1394 u32 offset;
1395 u8 tmp;
1396
Sakari Ailusc659c382011-01-21 10:59:30 +00001397 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);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001401 } else {
Sakari Ailusc659c382011-01-21 10:59:30 +00001402 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,
1409 0xffffffff);
1410 tlan_dio_write32(dev->base_addr, TLAN_HASH_2,
1411 0xffffffff);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001412 } else {
Jiri Pirko567ec872010-02-23 23:17:07 +00001413 i = 0;
Jiri Pirko22bedad32010-04-01 21:22:57 +00001414 netdev_for_each_mc_addr(ha, dev) {
Sakari Ailusc659c382011-01-21 10:59:30 +00001415 if (i < 3) {
1416 tlan_set_mac(dev, i + 1,
Jiri Pirko22bedad32010-04-01 21:22:57 +00001417 (char *) &ha->addr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001418 } else {
Sakari Ailusc659c382011-01-21 10:59:30 +00001419 offset =
1420 tlan_hash_func((u8 *)&ha->addr);
1421 if (offset < 32)
1422 hash1 |= (1 << offset);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001423 else
Sakari Ailusc659c382011-01-21 10:59:30 +00001424 hash2 |= (1 << (offset - 32));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001425 }
Jiri Pirko567ec872010-02-23 23:17:07 +00001426 i++;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001427 }
Sakari Ailusc659c382011-01-21 10:59:30 +00001428 for ( ; i < 3; i++)
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);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001432 }
1433 }
1434
Sakari Ailusc659c382011-01-21 10:59:30 +00001435}
Linus Torvalds1da177e2005-04-16 15:20:36 -07001436
1437
1438
1439/*****************************************************************************
1440******************************************************************************
1441
Sakari Ailusc659c382011-01-21 10:59:30 +00001442ThunderLAN driver interrupt vectors and table
Linus Torvalds1da177e2005-04-16 15:20:36 -07001443
Sakari Ailusc659c382011-01-21 10:59:30 +00001444please see chap. 4, "Interrupt Handling" of the "ThunderLAN
1445Programmer's Guide" for more informations on handling interrupts
1446generated by TLAN based adapters.
Linus Torvalds1da177e2005-04-16 15:20:36 -07001447
1448******************************************************************************
1449*****************************************************************************/
1450
1451
Linus Torvalds1da177e2005-04-16 15:20:36 -07001452
1453
Sakari Ailusc659c382011-01-21 10:59:30 +00001454/***************************************************************
1455 * tlan_handle_tx_eof
1456 *
1457 * Returns:
1458 * 1
1459 * Parms:
1460 * dev Device assigned the IRQ that was
1461 * raised.
1462 * host_int The contents of the HOST_INT
1463 * port.
1464 *
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
1472 * activity LED.
1473 *
1474 **************************************************************/
Linus Torvalds1da177e2005-04-16 15:20:36 -07001475
Sakari Ailusc659c382011-01-21 10:59:30 +00001476static u32 tlan_handle_tx_eof(struct net_device *dev, u16 host_int)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001477{
Sakari Ailusc659c382011-01-21 10:59:30 +00001478 struct tlan_priv *priv = netdev_priv(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001479 int eoc = 0;
Sakari Ailusc659c382011-01-21 10:59:30 +00001480 struct tlan_list *head_list;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001481 dma_addr_t head_list_phys;
1482 u32 ack = 0;
Sakari Ailusc659c382011-01-21 10:59:30 +00001483 u16 tmp_c_stat;
Jeff Garzik6aa20a22006-09-13 13:24:59 -04001484
Sakari Ailusc659c382011-01-21 10:59:30 +00001485 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;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001489
Sakari Ailusc659c382011-01-21 10:59:30 +00001490 while (((tmp_c_stat = head_list->c_stat) & TLAN_CSTAT_FRM_CMP)
1491 && (ack < 255)) {
1492 struct sk_buff *skb = tlan_get_skb(head_list);
Sakari Ailus5eeabf52008-12-16 15:24:05 -08001493
Linus Torvalds1da177e2005-04-16 15:20:36 -07001494 ack++;
Sakari Ailusc659c382011-01-21 10:59:30 +00001495 pci_unmap_single(priv->pci_dev, head_list->buffer[0].address,
Sakari Ailus5eeabf52008-12-16 15:24:05 -08001496 max(skb->len,
1497 (unsigned int)TLAN_MIN_FRAME_SIZE),
1498 PCI_DMA_TODEVICE);
1499 dev_kfree_skb_any(skb);
1500 head_list->buffer[8].address = 0;
1501 head_list->buffer[9].address = 0;
Jeff Garzik6aa20a22006-09-13 13:24:59 -04001502
Sakari Ailusc659c382011-01-21 10:59:30 +00001503 if (tmp_c_stat & TLAN_CSTAT_EOC)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001504 eoc = 1;
Jeff Garzik6aa20a22006-09-13 13:24:59 -04001505
Sakari Ailusc659c382011-01-21 10:59:30 +00001506 dev->stats.tx_bytes += head_list->frame_size;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001507
Sakari Ailusc659c382011-01-21 10:59:30 +00001508 head_list->c_stat = TLAN_CSTAT_UNUSED;
Jeff Garzik6aa20a22006-09-13 13:24:59 -04001509 netif_start_queue(dev);
Sakari Ailusc659c382011-01-21 10:59:30 +00001510 CIRC_INC(priv->tx_head, TLAN_NUM_TX_LISTS);
1511 head_list = priv->tx_list + priv->tx_head;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001512 }
1513
1514 if (!ack)
Sakari Ailusc659c382011-01-21 10:59:30 +00001515 printk(KERN_INFO
1516 "TLAN: Received interrupt for uncompleted TX frame.\n");
Jeff Garzik6aa20a22006-09-13 13:24:59 -04001517
Sakari Ailusc659c382011-01-21 10:59:30 +00001518 if (eoc) {
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;
Sakari Ailusf45437e2011-02-09 10:25:06 +00001525 if ((head_list->c_stat & TLAN_CSTAT_READY)
1526 == TLAN_CSTAT_READY) {
Sakari Ailusc659c382011-01-21 10:59:30 +00001527 outl(head_list_phys, dev->base_addr + TLAN_CH_PARM);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001528 ack |= TLAN_HC_GO;
1529 } else {
Sakari Ailusc659c382011-01-21 10:59:30 +00001530 priv->tx_in_progress = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001531 }
1532 }
Jeff Garzik6aa20a22006-09-13 13:24:59 -04001533
Sakari Ailusc659c382011-01-21 10:59:30 +00001534 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;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001546 }
1547 }
1548
1549 return ack;
1550
Sakari Ailusc659c382011-01-21 10:59:30 +00001551}
Linus Torvalds1da177e2005-04-16 15:20:36 -07001552
1553
1554
1555
Sakari Ailusc659c382011-01-21 10:59:30 +00001556/***************************************************************
1557 * TLan_HandleStatOverflow
1558 *
1559 * Returns:
1560 * 1
1561 * Parms:
1562 * dev Device assigned the IRQ that was
1563 * raised.
1564 * host_int The contents of the HOST_INT
1565 * port.
1566 *
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.
1570 *
1571 **************************************************************/
Linus Torvalds1da177e2005-04-16 15:20:36 -07001572
Sakari Ailusc659c382011-01-21 10:59:30 +00001573static u32 tlan_handle_stat_overflow(struct net_device *dev, u16 host_int)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001574{
Sakari Ailusc659c382011-01-21 10:59:30 +00001575 tlan_read_and_clear_stats(dev, TLAN_RECORD);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001576
1577 return 1;
1578
Sakari Ailusc659c382011-01-21 10:59:30 +00001579}
Linus Torvalds1da177e2005-04-16 15:20:36 -07001580
1581
1582
1583
Sakari Ailusc659c382011-01-21 10:59:30 +00001584/***************************************************************
1585 * TLan_HandleRxEOF
1586 *
1587 * Returns:
1588 * 1
1589 * Parms:
1590 * dev Device assigned the IRQ that was
1591 * raised.
1592 * host_int The contents of the HOST_INT
1593 * port.
1594 *
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.
1606 *
1607 **************************************************************/
Linus Torvalds1da177e2005-04-16 15:20:36 -07001608
Sakari Ailusc659c382011-01-21 10:59:30 +00001609static u32 tlan_handle_rx_eof(struct net_device *dev, u16 host_int)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001610{
Sakari Ailusc659c382011-01-21 10:59:30 +00001611 struct tlan_priv *priv = netdev_priv(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001612 u32 ack = 0;
1613 int eoc = 0;
Sakari Ailusc659c382011-01-21 10:59:30 +00001614 struct tlan_list *head_list;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001615 struct sk_buff *skb;
Sakari Ailusc659c382011-01-21 10:59:30 +00001616 struct tlan_list *tail_list;
1617 u16 tmp_c_stat;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001618 dma_addr_t head_list_phys;
1619
Sakari Ailusc659c382011-01-21 10:59:30 +00001620 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;
1623 head_list_phys =
1624 priv->rx_list_dma + sizeof(struct tlan_list)*priv->rx_head;
Jeff Garzik6aa20a22006-09-13 13:24:59 -04001625
Sakari Ailusc659c382011-01-21 10:59:30 +00001626 while (((tmp_c_stat = head_list->c_stat) & TLAN_CSTAT_FRM_CMP)
1627 && (ack < 255)) {
1628 dma_addr_t frame_dma = head_list->buffer[0].address;
1629 u32 frame_size = head_list->frame_size;
Sakari Ailus5eeabf52008-12-16 15:24:05 -08001630 struct sk_buff *new_skb;
1631
Linus Torvalds1da177e2005-04-16 15:20:36 -07001632 ack++;
Sakari Ailusc659c382011-01-21 10:59:30 +00001633 if (tmp_c_stat & TLAN_CSTAT_EOC)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001634 eoc = 1;
Jeff Garzik6aa20a22006-09-13 13:24:59 -04001635
Eric Dumazet89d71a62009-10-13 05:34:20 +00001636 new_skb = netdev_alloc_skb_ip_align(dev,
1637 TLAN_MAX_FRAME_SIZE + 5);
Sakari Ailusc659c382011-01-21 10:59:30 +00001638 if (!new_skb)
Sakari Ailus5eeabf52008-12-16 15:24:05 -08001639 goto drop_and_reuse;
Jeff Garzik6aa20a22006-09-13 13:24:59 -04001640
Sakari Ailusc659c382011-01-21 10:59:30 +00001641 skb = tlan_get_skb(head_list);
1642 pci_unmap_single(priv->pci_dev, frame_dma,
Sakari Ailus5eeabf52008-12-16 15:24:05 -08001643 TLAN_MAX_FRAME_SIZE, PCI_DMA_FROMDEVICE);
Sakari Ailusc659c382011-01-21 10:59:30 +00001644 skb_put(skb, frame_size);
Stephen Hemmingerdfc2c0a2008-05-30 09:49:58 -07001645
Sakari Ailusc659c382011-01-21 10:59:30 +00001646 dev->stats.rx_bytes += frame_size;
Jeff Garzik6aa20a22006-09-13 13:24:59 -04001647
Sakari Ailusc659c382011-01-21 10:59:30 +00001648 skb->protocol = eth_type_trans(skb, dev);
1649 netif_rx(skb);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001650
Sakari Ailusc659c382011-01-21 10:59:30 +00001651 head_list->buffer[0].address =
1652 pci_map_single(priv->pci_dev, new_skb->data,
1653 TLAN_MAX_FRAME_SIZE, PCI_DMA_FROMDEVICE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001654
Sakari Ailusc659c382011-01-21 10:59:30 +00001655 tlan_store_skb(head_list, new_skb);
Stephen Hemmingerdfc2c0a2008-05-30 09:49:58 -07001656drop_and_reuse:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001657 head_list->forward = 0;
Sakari Ailusc659c382011-01-21 10:59:30 +00001658 head_list->c_stat = 0;
1659 tail_list = priv->rx_list + priv->rx_tail;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001660 tail_list->forward = head_list_phys;
1661
Sakari Ailusc659c382011-01-21 10:59:30 +00001662 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;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001667 }
1668
1669 if (!ack)
Sakari Ailusc659c382011-01-21 10:59:30 +00001670 printk(KERN_INFO
1671 "TLAN: Received interrupt for uncompleted RX frame.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001672
1673
Sakari Ailusc659c382011-01-21 10:59:30 +00001674 if (eoc) {
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);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001682 ack |= TLAN_HC_GO | TLAN_HC_RT;
Sakari Ailusc659c382011-01-21 10:59:30 +00001683 priv->rx_eoc_count++;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001684 }
1685
Sakari Ailusc659c382011-01-21 10:59:30 +00001686 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;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001691 priv->timer.data = (unsigned long) dev;
1692 priv->timer.expires = jiffies + TLAN_TIMER_ACT_DELAY;
Sakari Ailusc659c382011-01-21 10:59:30 +00001693 priv->timer_set_at = jiffies;
1694 priv->timer_type = TLAN_TIMER_ACTIVITY;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001695 add_timer(&priv->timer);
Sakari Ailusc659c382011-01-21 10:59:30 +00001696 } else if (priv->timer_type == TLAN_TIMER_ACTIVITY) {
1697 priv->timer_set_at = jiffies;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001698 }
1699 }
1700
Linus Torvalds1da177e2005-04-16 15:20:36 -07001701 return ack;
1702
Sakari Ailusc659c382011-01-21 10:59:30 +00001703}
Linus Torvalds1da177e2005-04-16 15:20:36 -07001704
1705
1706
1707
Sakari Ailusc659c382011-01-21 10:59:30 +00001708/***************************************************************
1709 * tlan_handle_dummy
1710 *
1711 * Returns:
1712 * 1
1713 * Parms:
1714 * dev Device assigned the IRQ that was
1715 * raised.
1716 * host_int The contents of the HOST_INT
1717 * port.
1718 *
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.
1722 *
1723 **************************************************************/
Linus Torvalds1da177e2005-04-16 15:20:36 -07001724
Sakari Ailusc659c382011-01-21 10:59:30 +00001725static u32 tlan_handle_dummy(struct net_device *dev, u16 host_int)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001726{
Sakari Ailusc659c382011-01-21 10:59:30 +00001727 pr_info("TLAN: Test interrupt on %s.\n", dev->name);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001728 return 1;
1729
Sakari Ailusc659c382011-01-21 10:59:30 +00001730}
Linus Torvalds1da177e2005-04-16 15:20:36 -07001731
1732
1733
1734
Sakari Ailusc659c382011-01-21 10:59:30 +00001735/***************************************************************
1736 * tlan_handle_tx_eoc
1737 *
1738 * Returns:
1739 * 1
1740 * Parms:
1741 * dev Device assigned the IRQ that was
1742 * raised.
1743 * host_int The contents of the HOST_INT
1744 * port.
1745 *
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
1751 * case.
1752 *
1753 **************************************************************/
Linus Torvalds1da177e2005-04-16 15:20:36 -07001754
Sakari Ailusc659c382011-01-21 10:59:30 +00001755static u32 tlan_handle_tx_eoc(struct net_device *dev, u16 host_int)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001756{
Sakari Ailusc659c382011-01-21 10:59:30 +00001757 struct tlan_priv *priv = netdev_priv(dev);
1758 struct tlan_list *head_list;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001759 dma_addr_t head_list_phys;
1760 u32 ack = 1;
Jeff Garzik6aa20a22006-09-13 13:24:59 -04001761
Linus Torvalds1da177e2005-04-16 15:20:36 -07001762 host_int = 0;
Sakari Ailusc659c382011-01-21 10:59:30 +00001763 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;
Sakari Ailusf45437e2011-02-09 10:25:06 +00001770 if ((head_list->c_stat & TLAN_CSTAT_READY)
1771 == TLAN_CSTAT_READY) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001772 netif_stop_queue(dev);
Sakari Ailusc659c382011-01-21 10:59:30 +00001773 outl(head_list_phys, dev->base_addr + TLAN_CH_PARM);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001774 ack |= TLAN_HC_GO;
1775 } else {
Sakari Ailusc659c382011-01-21 10:59:30 +00001776 priv->tx_in_progress = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001777 }
1778 }
1779
1780 return ack;
1781
Sakari Ailusc659c382011-01-21 10:59:30 +00001782}
Linus Torvalds1da177e2005-04-16 15:20:36 -07001783
1784
1785
1786
Sakari Ailusc659c382011-01-21 10:59:30 +00001787/***************************************************************
1788 * tlan_handle_status_check
1789 *
1790 * Returns:
1791 * 0 if Adapter check, 1 if Network Status check.
1792 * Parms:
1793 * dev Device assigned the IRQ that was
1794 * raised.
1795 * host_int The contents of the HOST_INT
1796 * port.
1797 *
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.
1804 *
1805 **************************************************************/
Linus Torvalds1da177e2005-04-16 15:20:36 -07001806
Sakari Ailusc659c382011-01-21 10:59:30 +00001807static u32 tlan_handle_status_check(struct net_device *dev, u16 host_int)
Jeff Garzik6aa20a22006-09-13 13:24:59 -04001808{
Sakari Ailusc659c382011-01-21 10:59:30 +00001809 struct tlan_priv *priv = netdev_priv(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001810 u32 ack;
1811 u32 error;
1812 u8 net_sts;
1813 u32 phy;
1814 u16 tlphy_ctl;
1815 u16 tlphy_sts;
Jeff Garzik6aa20a22006-09-13 13:24:59 -04001816
Linus Torvalds1da177e2005-04-16 15:20:36 -07001817 ack = 1;
Sakari Ailusc659c382011-01-21 10:59:30 +00001818 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);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001824
1825 schedule_work(&priv->tlan_tqueue);
1826
1827 netif_wake_queue(dev);
1828 ack = 0;
1829 } else {
Sakari Ailusc659c382011-01-21 10:59:30 +00001830 TLAN_DBG(TLAN_DEBUG_GNRL, "%s: Status Check\n", dev->name);
1831 phy = priv->phy[priv->phy_num];
Linus Torvalds1da177e2005-04-16 15:20:36 -07001832
Sakari Ailusc659c382011-01-21 10:59:30 +00001833 net_sts = tlan_dio_read8(dev->base_addr, TLAN_NET_STS);
1834 if (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);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001838 }
Sakari Ailusc659c382011-01-21 10:59:30 +00001839 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,
1846 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,
1851 tlphy_ctl);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001852 }
Sakari Ailusc659c382011-01-21 10:59:30 +00001853
1854 if (debug)
1855 tlan_phy_print(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001856 }
1857 }
1858
1859 return ack;
1860
Sakari Ailusc659c382011-01-21 10:59:30 +00001861}
Linus Torvalds1da177e2005-04-16 15:20:36 -07001862
1863
1864
1865
Sakari Ailusc659c382011-01-21 10:59:30 +00001866/***************************************************************
1867 * tlan_handle_rx_eoc
1868 *
1869 * Returns:
1870 * 1
1871 * Parms:
1872 * dev Device assigned the IRQ that was
1873 * raised.
1874 * host_int The contents of the HOST_INT
1875 * port.
1876 *
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.
1883 *
1884 **************************************************************/
Linus Torvalds1da177e2005-04-16 15:20:36 -07001885
Sakari Ailusc659c382011-01-21 10:59:30 +00001886static u32 tlan_handle_rx_eoc(struct net_device *dev, u16 host_int)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001887{
Sakari Ailusc659c382011-01-21 10:59:30 +00001888 struct tlan_priv *priv = netdev_priv(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001889 dma_addr_t head_list_phys;
1890 u32 ack = 1;
1891
Sakari Ailusc659c382011-01-21 10:59:30 +00001892 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);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001899 ack |= TLAN_HC_GO | TLAN_HC_RT;
Sakari Ailusc659c382011-01-21 10:59:30 +00001900 priv->rx_eoc_count++;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001901 }
1902
1903 return ack;
1904
Sakari Ailusc659c382011-01-21 10:59:30 +00001905}
Linus Torvalds1da177e2005-04-16 15:20:36 -07001906
1907
1908
1909
1910/*****************************************************************************
1911******************************************************************************
1912
Sakari Ailusc659c382011-01-21 10:59:30 +00001913ThunderLAN driver timer function
Linus Torvalds1da177e2005-04-16 15:20:36 -07001914
1915******************************************************************************
1916*****************************************************************************/
1917
1918
Sakari Ailusc659c382011-01-21 10:59:30 +00001919/***************************************************************
1920 * tlan_timer
1921 *
1922 * Returns:
1923 * Nothing
1924 * Parms:
1925 * data A value given to add timer when
1926 * add_timer was called.
1927 *
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
1938 * PHY.
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.
1946 *
1947 **************************************************************/
Linus Torvalds1da177e2005-04-16 15:20:36 -07001948
Sakari Ailusc659c382011-01-21 10:59:30 +00001949static void tlan_timer(unsigned long data)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001950{
1951 struct net_device *dev = (struct net_device *) data;
Sakari Ailusc659c382011-01-21 10:59:30 +00001952 struct tlan_priv *priv = netdev_priv(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001953 u32 elapsed;
1954 unsigned long flags = 0;
1955
1956 priv->timer.function = NULL;
1957
Sakari Ailusc659c382011-01-21 10:59:30 +00001958 switch (priv->timer_type) {
Jeff Garzik6aa20a22006-09-13 13:24:59 -04001959#ifdef MONITOR
Sakari Ailusc659c382011-01-21 10:59:30 +00001960 case TLAN_TIMER_LINK_BEAT:
1961 tlan_phy_monitor(dev);
1962 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001963#endif
Sakari Ailusc659c382011-01-21 10:59:30 +00001964 case TLAN_TIMER_PHY_PDOWN:
1965 tlan_phy_power_down(dev);
1966 break;
1967 case TLAN_TIMER_PHY_PUP:
1968 tlan_phy_power_up(dev);
1969 break;
1970 case TLAN_TIMER_PHY_RESET:
1971 tlan_phy_reset(dev);
1972 break;
1973 case TLAN_TIMER_PHY_START_LINK:
1974 tlan_phy_start_link(dev);
1975 break;
1976 case TLAN_TIMER_PHY_FINISH_AN:
1977 tlan_phy_finish_auto_neg(dev);
1978 break;
1979 case TLAN_TIMER_FINISH_RESET:
1980 tlan_finish_reset(dev);
1981 break;
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);
1989 } else {
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);
1995 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001996 }
Sakari Ailusc659c382011-01-21 10:59:30 +00001997 }
1998 spin_unlock_irqrestore(&priv->lock, flags);
1999 break;
2000 default:
2001 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002002 }
2003
Sakari Ailusc659c382011-01-21 10:59:30 +00002004}
Linus Torvalds1da177e2005-04-16 15:20:36 -07002005
2006
2007
2008
2009/*****************************************************************************
2010******************************************************************************
2011
Sakari Ailusc659c382011-01-21 10:59:30 +00002012ThunderLAN driver adapter related routines
Linus Torvalds1da177e2005-04-16 15:20:36 -07002013
2014******************************************************************************
2015*****************************************************************************/
2016
2017
Sakari Ailusc659c382011-01-21 10:59:30 +00002018/***************************************************************
2019 * tlan_reset_lists
2020 *
2021 * Returns:
2022 * Nothing
2023 * Parms:
2024 * dev The device structure with the list
2025 * stuctures to be reset.
2026 *
2027 * This routine sets the variables associated with managing
2028 * the TLAN lists to their initial values.
2029 *
2030 **************************************************************/
Linus Torvalds1da177e2005-04-16 15:20:36 -07002031
Sakari Ailusc659c382011-01-21 10:59:30 +00002032static void tlan_reset_lists(struct net_device *dev)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002033{
Sakari Ailusc659c382011-01-21 10:59:30 +00002034 struct tlan_priv *priv = netdev_priv(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002035 int i;
Sakari Ailusc659c382011-01-21 10:59:30 +00002036 struct tlan_list *list;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002037 dma_addr_t list_phys;
2038 struct sk_buff *skb;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002039
Sakari Ailusc659c382011-01-21 10:59:30 +00002040 priv->tx_head = 0;
2041 priv->tx_tail = 0;
2042 for (i = 0; i < TLAN_NUM_TX_LISTS; i++) {
2043 list = priv->tx_list + i;
2044 list->c_stat = TLAN_CSTAT_UNUSED;
Sakari Ailus5eeabf52008-12-16 15:24:05 -08002045 list->buffer[0].address = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002046 list->buffer[2].count = 0;
2047 list->buffer[2].address = 0;
2048 list->buffer[8].address = 0;
2049 list->buffer[9].address = 0;
2050 }
2051
Sakari Ailusc659c382011-01-21 10:59:30 +00002052 priv->rx_head = 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;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002059 list->buffer[0].count = TLAN_MAX_FRAME_SIZE | TLAN_LAST_BUFFER;
Eric Dumazet89d71a62009-10-13 05:34:20 +00002060 skb = netdev_alloc_skb_ip_align(dev, TLAN_MAX_FRAME_SIZE + 5);
Sakari Ailusc659c382011-01-21 10:59:30 +00002061 if (!skb) {
2062 pr_err("TLAN: out of memory for received data.\n");
Sakari Ailus5eeabf52008-12-16 15:24:05 -08002063 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002064 }
Sakari Ailus5eeabf52008-12-16 15:24:05 -08002065
Sakari Ailusc659c382011-01-21 10:59:30 +00002066 list->buffer[0].address = pci_map_single(priv->pci_dev,
Sakari Ailus5eeabf52008-12-16 15:24:05 -08002067 skb->data,
2068 TLAN_MAX_FRAME_SIZE,
2069 PCI_DMA_FROMDEVICE);
Sakari Ailusc659c382011-01-21 10:59:30 +00002070 tlan_store_skb(list, skb);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002071 list->buffer[1].count = 0;
2072 list->buffer[1].address = 0;
Sakari Ailusc659c382011-01-21 10:59:30 +00002073 list->forward = list_phys + sizeof(struct tlan_list);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002074 }
2075
Stephen Hemminger9ded65a2008-05-30 09:49:56 -07002076 /* in case ran out of memory early, clear bits */
2077 while (i < TLAN_NUM_RX_LISTS) {
Sakari Ailusc659c382011-01-21 10:59:30 +00002078 tlan_store_skb(priv->rx_list + i, NULL);
Stephen Hemminger9ded65a2008-05-30 09:49:56 -07002079 ++i;
2080 }
2081 list->forward = 0;
2082
Sakari Ailusc659c382011-01-21 10:59:30 +00002083}
Linus Torvalds1da177e2005-04-16 15:20:36 -07002084
2085
Sakari Ailusc659c382011-01-21 10:59:30 +00002086static void tlan_free_lists(struct net_device *dev)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002087{
Sakari Ailusc659c382011-01-21 10:59:30 +00002088 struct tlan_priv *priv = netdev_priv(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002089 int i;
Sakari Ailusc659c382011-01-21 10:59:30 +00002090 struct tlan_list *list;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002091 struct sk_buff *skb;
2092
Sakari Ailusc659c382011-01-21 10:59:30 +00002093 for (i = 0; i < TLAN_NUM_TX_LISTS; i++) {
2094 list = priv->tx_list + i;
2095 skb = tlan_get_skb(list);
2096 if (skb) {
Sakari Ailus5eeabf52008-12-16 15:24:05 -08002097 pci_unmap_single(
Sakari Ailusc659c382011-01-21 10:59:30 +00002098 priv->pci_dev,
Sakari Ailus5eeabf52008-12-16 15:24:05 -08002099 list->buffer[0].address,
2100 max(skb->len,
2101 (unsigned int)TLAN_MIN_FRAME_SIZE),
2102 PCI_DMA_TODEVICE);
Sakari Ailusc659c382011-01-21 10:59:30 +00002103 dev_kfree_skb_any(skb);
Sakari Ailus5eeabf52008-12-16 15:24:05 -08002104 list->buffer[8].address = 0;
2105 list->buffer[9].address = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002106 }
Sakari Ailus5eeabf52008-12-16 15:24:05 -08002107 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002108
Sakari Ailusc659c382011-01-21 10:59:30 +00002109 for (i = 0; i < TLAN_NUM_RX_LISTS; i++) {
2110 list = priv->rx_list + i;
2111 skb = tlan_get_skb(list);
2112 if (skb) {
2113 pci_unmap_single(priv->pci_dev,
Sakari Ailus5eeabf52008-12-16 15:24:05 -08002114 list->buffer[0].address,
2115 TLAN_MAX_FRAME_SIZE,
2116 PCI_DMA_FROMDEVICE);
Sakari Ailusc659c382011-01-21 10:59:30 +00002117 dev_kfree_skb_any(skb);
Sakari Ailus5eeabf52008-12-16 15:24:05 -08002118 list->buffer[8].address = 0;
2119 list->buffer[9].address = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002120 }
2121 }
Sakari Ailusc659c382011-01-21 10:59:30 +00002122}
Linus Torvalds1da177e2005-04-16 15:20:36 -07002123
2124
2125
2126
Sakari Ailusc659c382011-01-21 10:59:30 +00002127/***************************************************************
2128 * tlan_print_dio
2129 *
2130 * Returns:
2131 * Nothing
2132 * Parms:
2133 * io_base Base IO port of the device of
2134 * which to print DIO registers.
2135 *
2136 * This function prints out all the internal (DIO)
2137 * registers of a TLAN chip.
2138 *
2139 **************************************************************/
Linus Torvalds1da177e2005-04-16 15:20:36 -07002140
Sakari Ailusc659c382011-01-21 10:59:30 +00002141static void tlan_print_dio(u16 io_base)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002142{
2143 u32 data0, data1;
2144 int i;
2145
Sakari Ailusc659c382011-01-21 10:59:30 +00002146 pr_info("TLAN: Contents of internal registers for io base 0x%04hx.\n",
2147 io_base);
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);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002153 }
2154
Sakari Ailusc659c382011-01-21 10:59:30 +00002155}
Linus Torvalds1da177e2005-04-16 15:20:36 -07002156
2157
2158
2159
Sakari Ailusc659c382011-01-21 10:59:30 +00002160/***************************************************************
2161 * TLan_PrintList
2162 *
2163 * Returns:
2164 * Nothing
2165 * Parms:
2166 * list A pointer to the struct tlan_list structure to
2167 * be printed.
2168 * type A string to designate type of list,
2169 * "Rx" or "Tx".
2170 * num The index of the list.
2171 *
2172 * This function prints out the contents of the list
2173 * pointed to by the list parameter.
2174 *
2175 **************************************************************/
Linus Torvalds1da177e2005-04-16 15:20:36 -07002176
Sakari Ailusc659c382011-01-21 10:59:30 +00002177static void tlan_print_list(struct tlan_list *list, char *type, int num)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002178{
2179 int i;
2180
Sakari Ailusc659c382011-01-21 10:59:30 +00002181 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);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002189 }
2190
Sakari Ailusc659c382011-01-21 10:59:30 +00002191}
Linus Torvalds1da177e2005-04-16 15:20:36 -07002192
2193
2194
2195
Sakari Ailusc659c382011-01-21 10:59:30 +00002196/***************************************************************
2197 * tlan_read_and_clear_stats
2198 *
2199 * Returns:
2200 * Nothing
2201 * Parms:
2202 * dev Pointer to device structure of adapter
2203 * to which to read stats.
2204 * record Flag indicating whether to add
2205 *
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).
2211 *
2212 **************************************************************/
Linus Torvalds1da177e2005-04-16 15:20:36 -07002213
Sakari Ailusc659c382011-01-21 10:59:30 +00002214static void tlan_read_and_clear_stats(struct net_device *dev, int record)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002215{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002216 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;
2221
Sakari Ailusc659c382011-01-21 10:59:30 +00002222 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);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002227
Sakari Ailusc659c382011-01-21 10:59:30 +00002228 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);
Jeff Garzik6aa20a22006-09-13 13:24:59 -04002233
Sakari Ailusc659c382011-01-21 10:59:30 +00002234 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);
Jeff Garzik6aa20a22006-09-13 13:24:59 -04002239
Sakari Ailusc659c382011-01-21 10:59:30 +00002240 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;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002245
Sakari Ailusc659c382011-01-21 10:59:30 +00002246 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);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002250
Sakari Ailusc659c382011-01-21 10:59:30 +00002251 if (record) {
Stephen Hemmingerf8f31542008-05-30 09:49:53 -07002252 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;
Sakari Ailusc659c382011-01-21 10:59:30 +00002256 dev->stats.collisions += multi_col
2257 + single_col + excess_col + late_col;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002258
Stephen Hemmingerf8f31542008-05-30 09:49:53 -07002259 dev->stats.rx_over_errors += rx_over;
2260 dev->stats.rx_crc_errors += crc;
2261 dev->stats.rx_frame_errors += code;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002262
Stephen Hemmingerf8f31542008-05-30 09:49:53 -07002263 dev->stats.tx_aborted_errors += tx_under;
2264 dev->stats.tx_carrier_errors += loss;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002265 }
Jeff Garzik6aa20a22006-09-13 13:24:59 -04002266
Sakari Ailusc659c382011-01-21 10:59:30 +00002267}
Linus Torvalds1da177e2005-04-16 15:20:36 -07002268
2269
2270
2271
Sakari Ailusc659c382011-01-21 10:59:30 +00002272/***************************************************************
2273 * TLan_Reset
2274 *
2275 * Returns:
2276 * 0
2277 * Parms:
2278 * dev Pointer to device structure of adapter
2279 * to be reset.
2280 *
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
2285 * have been made.
2286 *
2287 **************************************************************/
Linus Torvalds1da177e2005-04-16 15:20:36 -07002288
Harvey Harrison98e0f522008-02-18 10:04:38 -08002289static void
Sakari Ailusc659c382011-01-21 10:59:30 +00002290tlan_reset_adapter(struct net_device *dev)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002291{
Sakari Ailusc659c382011-01-21 10:59:30 +00002292 struct tlan_priv *priv = netdev_priv(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002293 int i;
2294 u32 addr;
2295 u32 data;
2296 u8 data8;
2297
Sakari Ailusc659c382011-01-21 10:59:30 +00002298 priv->tlan_full_duplex = false;
2299 priv->phy_online = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002300 netif_carrier_off(dev);
2301
2302/* 1. Assert reset bit. */
2303
2304 data = inl(dev->base_addr + TLAN_HOST_CMD);
2305 data |= TLAN_HC_AD_RST;
2306 outl(data, dev->base_addr + TLAN_HOST_CMD);
Jeff Garzik6aa20a22006-09-13 13:24:59 -04002307
Linus Torvalds1da177e2005-04-16 15:20:36 -07002308 udelay(1000);
2309
Sakari Ailusc659c382011-01-21 10:59:30 +00002310/* 2. Turn off interrupts. (Probably isn't necessary) */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002311
2312 data = inl(dev->base_addr + TLAN_HOST_CMD);
2313 data |= TLAN_HC_INT_OFF;
2314 outl(data, dev->base_addr + TLAN_HOST_CMD);
2315
2316/* 3. Clear AREGs and HASHs. */
2317
Sakari Ailusc659c382011-01-21 10:59:30 +00002318 for (i = TLAN_AREG_0; i <= TLAN_HASH_2; i += 4)
2319 tlan_dio_write32(dev->base_addr, (u16) i, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002320
2321/* 4. Setup NetConfig register. */
2322
2323 data = TLAN_NET_CFG_1FRAG | TLAN_NET_CFG_1CHAN | TLAN_NET_CFG_PHY_EN;
Sakari Ailusc659c382011-01-21 10:59:30 +00002324 tlan_dio_write16(dev->base_addr, TLAN_NET_CONFIG, (u16) data);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002325
2326/* 5. Load Ld_Tmr and Ld_Thr in HOST_CMD. */
2327
Sakari Ailusc659c382011-01-21 10:59:30 +00002328 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);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002330
2331/* 6. Unreset the MII by setting NMRST (in NetSio) to 1. */
2332
Sakari Ailusc659c382011-01-21 10:59:30 +00002333 outw(TLAN_NET_SIO, dev->base_addr + TLAN_DIO_ADR);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002334 addr = dev->base_addr + TLAN_DIO_DATA + TLAN_NET_SIO;
Sakari Ailusc659c382011-01-21 10:59:30 +00002335 tlan_set_bit(TLAN_NET_SIO_NMRST, addr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002336
2337/* 7. Setup the remaining registers. */
2338
Sakari Ailusc659c382011-01-21 10:59:30 +00002339 if (priv->tlan_rev >= 0x30) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002340 data8 = TLAN_ID_TX_EOC | TLAN_ID_RX_EOC;
Sakari Ailusc659c382011-01-21 10:59:30 +00002341 tlan_dio_write8(dev->base_addr, TLAN_INT_DIS, data8);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002342 }
Sakari Ailusc659c382011-01-21 10:59:30 +00002343 tlan_phy_detect(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002344 data = TLAN_NET_CFG_1FRAG | TLAN_NET_CFG_1CHAN;
Jeff Garzik6aa20a22006-09-13 13:24:59 -04002345
Sakari Ailusc659c382011-01-21 10:59:30 +00002346 if (priv->adapter->flags & TLAN_ADAPTER_BIT_RATE_PHY) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002347 data |= TLAN_NET_CFG_BIT;
Sakari Ailusc659c382011-01-21 10:59:30 +00002348 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;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002353 } else {
Sakari Ailusc659c382011-01-21 10:59:30 +00002354 tlan_dio_write8(dev->base_addr, TLAN_ACOMMIT, 0x08);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002355 }
2356 }
2357
Sakari Ailusc659c382011-01-21 10:59:30 +00002358 if (priv->phy_num == 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002359 data |= TLAN_NET_CFG_PHY_EN;
Sakari Ailusc659c382011-01-21 10:59:30 +00002360 tlan_dio_write16(dev->base_addr, TLAN_NET_CONFIG, (u16) data);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002361
Sakari Ailusc659c382011-01-21 10:59:30 +00002362 if (priv->adapter->flags & TLAN_ADAPTER_UNMANAGED_PHY)
2363 tlan_finish_reset(dev);
2364 else
2365 tlan_phy_power_down(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002366
Sakari Ailusc659c382011-01-21 10:59:30 +00002367}
Linus Torvalds1da177e2005-04-16 15:20:36 -07002368
2369
2370
2371
Harvey Harrison98e0f522008-02-18 10:04:38 -08002372static void
Sakari Ailusc659c382011-01-21 10:59:30 +00002373tlan_finish_reset(struct net_device *dev)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002374{
Sakari Ailusc659c382011-01-21 10:59:30 +00002375 struct tlan_priv *priv = netdev_priv(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002376 u8 data;
2377 u32 phy;
2378 u8 sio;
2379 u16 status;
2380 u16 partner;
2381 u16 tlphy_ctl;
Sakari Ailusc659c382011-01-21 10:59:30 +00002382 u16 tlphy_par;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002383 u16 tlphy_id1, tlphy_id2;
Sakari Ailusc659c382011-01-21 10:59:30 +00002384 int i;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002385
Sakari Ailusc659c382011-01-21 10:59:30 +00002386 phy = priv->phy[priv->phy_num];
Linus Torvalds1da177e2005-04-16 15:20:36 -07002387
2388 data = TLAN_NET_CMD_NRESET | TLAN_NET_CMD_NWRAP;
Sakari Ailusc659c382011-01-21 10:59:30 +00002389 if (priv->tlan_full_duplex)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002390 data |= TLAN_NET_CMD_DUPLEX;
Sakari Ailusc659c382011-01-21 10:59:30 +00002391 tlan_dio_write8(dev->base_addr, TLAN_NET_CMD, data);
Jeff Garzik6aa20a22006-09-13 13:24:59 -04002392 data = TLAN_NET_MASK_MASK4 | TLAN_NET_MASK_MASK5;
Sakari Ailusc659c382011-01-21 10:59:30 +00002393 if (priv->phy_num == 0)
Jeff Garzik6aa20a22006-09-13 13:24:59 -04002394 data |= TLAN_NET_MASK_MASK7;
Sakari Ailusc659c382011-01-21 10:59:30 +00002395 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);
Jeff Garzik6aa20a22006-09-13 13:24:59 -04002399
Sakari Ailusc659c382011-01-21 10:59:30 +00002400 if ((priv->adapter->flags & TLAN_ADAPTER_UNMANAGED_PHY) ||
2401 (priv->aui)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002402 status = MII_GS_LINK;
Sakari Ailusc659c382011-01-21 10:59:30 +00002403 pr_info("TLAN: %s: Link forced.\n", dev->name);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002404 } else {
Sakari Ailusc659c382011-01-21 10:59:30 +00002405 tlan_mii_read_reg(dev, phy, MII_GEN_STS, &status);
2406 udelay(1000);
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);
Jeff Garzik6aa20a22006-09-13 13:24:59 -04002414
Sakari Ailusc659c382011-01-21 10:59:30 +00002415 pr_info("TLAN: %s: Link active with ", dev->name);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002416 if (!(tlphy_par & TLAN_PHY_AN_EN_STAT)) {
Sakari Ailusc659c382011-01-21 10:59:30 +00002417 pr_info("forced 10%sMbps %s-Duplex\n",
2418 tlphy_par & TLAN_PHY_SPEED_100
2419 ? "" : "0",
2420 tlphy_par & TLAN_PHY_DUPLEX_FULL
2421 ? "Full" : "Half");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002422 } else {
Sakari Ailusc659c382011-01-21 10:59:30 +00002423 pr_info("Autonegotiation enabled, at 10%sMbps %s-Duplex\n",
2424 tlphy_par & TLAN_PHY_SPEED_100
2425 ? "" : "0",
2426 tlphy_par & TLAN_PHY_DUPLEX_FULL
2427 ? "Full" : "half");
2428 pr_info("TLAN: Partner capability: ");
2429 for (i = 5; i <= 10; i++)
2430 if (partner & (1<<i))
2431 printk("%s", media[i-5]);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002432 printk("\n");
2433 }
2434
Sakari Ailusc659c382011-01-21 10:59:30 +00002435 tlan_dio_write8(dev->base_addr, TLAN_LED_REG,
2436 TLAN_LED_LINK);
Jeff Garzik6aa20a22006-09-13 13:24:59 -04002437#ifdef MONITOR
Linus Torvalds1da177e2005-04-16 15:20:36 -07002438 /* We have link beat..for now anyway */
Sakari Ailusc659c382011-01-21 10:59:30 +00002439 priv->link = 1;
2440 /*Enabling link beat monitoring */
2441 tlan_set_timer(dev, (10*HZ), TLAN_TIMER_LINK_BEAT);
Jeff Garzik6aa20a22006-09-13 13:24:59 -04002442#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -07002443 } else if (status & MII_GS_LINK) {
Sakari Ailusc659c382011-01-21 10:59:30 +00002444 pr_info("TLAN: %s: Link active\n", dev->name);
2445 tlan_dio_write8(dev->base_addr, TLAN_LED_REG,
2446 TLAN_LED_LINK);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002447 }
2448 }
2449
Sakari Ailusc659c382011-01-21 10:59:30 +00002450 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);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002457 }
2458
Sakari Ailusc659c382011-01-21 10:59:30 +00002459 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);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002468 netif_carrier_on(dev);
2469 } else {
Sakari Ailusc659c382011-01-21 10:59:30 +00002470 pr_info("TLAN: %s: Link inactive, will retry in 10 secs...\n",
2471 dev->name);
2472 tlan_set_timer(dev, (10*HZ), TLAN_TIMER_FINISH_RESET);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002473 return;
2474 }
Sakari Ailusc659c382011-01-21 10:59:30 +00002475 tlan_set_multicast_list(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002476
Sakari Ailusc659c382011-01-21 10:59:30 +00002477}
Linus Torvalds1da177e2005-04-16 15:20:36 -07002478
2479
2480
2481
Sakari Ailusc659c382011-01-21 10:59:30 +00002482/***************************************************************
2483 * tlan_set_mac
2484 *
2485 * Returns:
2486 * Nothing
2487 * Parms:
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.
2494 *
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.
2500 *
2501 **************************************************************/
Linus Torvalds1da177e2005-04-16 15:20:36 -07002502
Sakari Ailusc659c382011-01-21 10:59:30 +00002503static void tlan_set_mac(struct net_device *dev, int areg, char *mac)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002504{
2505 int i;
Jeff Garzik6aa20a22006-09-13 13:24:59 -04002506
Linus Torvalds1da177e2005-04-16 15:20:36 -07002507 areg *= 6;
2508
Sakari Ailusc659c382011-01-21 10:59:30 +00002509 if (mac != NULL) {
2510 for (i = 0; i < 6; i++)
2511 tlan_dio_write8(dev->base_addr,
2512 TLAN_AREG_0 + areg + i, mac[i]);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002513 } else {
Sakari Ailusc659c382011-01-21 10:59:30 +00002514 for (i = 0; i < 6; i++)
2515 tlan_dio_write8(dev->base_addr,
2516 TLAN_AREG_0 + areg + i, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002517 }
2518
Sakari Ailusc659c382011-01-21 10:59:30 +00002519}
Linus Torvalds1da177e2005-04-16 15:20:36 -07002520
2521
2522
2523
2524/*****************************************************************************
2525******************************************************************************
2526
Sakari Ailusc659c382011-01-21 10:59:30 +00002527ThunderLAN driver PHY layer routines
Linus Torvalds1da177e2005-04-16 15:20:36 -07002528
2529******************************************************************************
2530*****************************************************************************/
2531
2532
2533
Sakari Ailusc659c382011-01-21 10:59:30 +00002534/*********************************************************************
2535 * tlan_phy_print
2536 *
2537 * Returns:
2538 * Nothing
2539 * Parms:
2540 * dev A pointer to the device structure of the
2541 * TLAN device having the PHYs to be detailed.
2542 *
2543 * This function prints the registers a PHY (aka transceiver).
2544 *
2545 ********************************************************************/
Linus Torvalds1da177e2005-04-16 15:20:36 -07002546
Sakari Ailusc659c382011-01-21 10:59:30 +00002547static void tlan_phy_print(struct net_device *dev)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002548{
Sakari Ailusc659c382011-01-21 10:59:30 +00002549 struct tlan_priv *priv = netdev_priv(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002550 u16 i, data0, data1, data2, data3, phy;
2551
Sakari Ailusc659c382011-01-21 10:59:30 +00002552 phy = priv->phy[priv->phy_num];
Linus Torvalds1da177e2005-04-16 15:20:36 -07002553
Sakari Ailusc659c382011-01-21 10:59:30 +00002554 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);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002569 }
2570 } else {
Sakari Ailusc659c382011-01-21 10:59:30 +00002571 pr_info("TLAN: Device %s, Invalid PHY.\n", dev->name);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002572 }
2573
Sakari Ailusc659c382011-01-21 10:59:30 +00002574}
Linus Torvalds1da177e2005-04-16 15:20:36 -07002575
2576
2577
2578
Sakari Ailusc659c382011-01-21 10:59:30 +00002579/*********************************************************************
2580 * tlan_phy_detect
2581 *
2582 * Returns:
2583 * Nothing
2584 * Parms:
2585 * dev A pointer to the device structure of the adapter
2586 * for which the PHY needs determined.
2587 *
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).
2593 *
2594 ********************************************************************/
Linus Torvalds1da177e2005-04-16 15:20:36 -07002595
Sakari Ailusc659c382011-01-21 10:59:30 +00002596static void tlan_phy_detect(struct net_device *dev)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002597{
Sakari Ailusc659c382011-01-21 10:59:30 +00002598 struct tlan_priv *priv = netdev_priv(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002599 u16 control;
2600 u16 hi;
2601 u16 lo;
2602 u32 phy;
2603
Sakari Ailusc659c382011-01-21 10:59:30 +00002604 if (priv->adapter->flags & TLAN_ADAPTER_UNMANAGED_PHY) {
2605 priv->phy_num = 0xffff;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002606 return;
2607 }
2608
Sakari Ailusc659c382011-01-21 10:59:30 +00002609 tlan_mii_read_reg(dev, TLAN_PHY_MAX_ADDR, MII_GEN_ID_HI, &hi);
Jeff Garzik6aa20a22006-09-13 13:24:59 -04002610
Sakari Ailusc659c382011-01-21 10:59:30 +00002611 if (hi != 0xffff)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002612 priv->phy[0] = TLAN_PHY_MAX_ADDR;
Sakari Ailusc659c382011-01-21 10:59:30 +00002613 else
Linus Torvalds1da177e2005-04-16 15:20:36 -07002614 priv->phy[0] = TLAN_PHY_NONE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002615
2616 priv->phy[1] = TLAN_PHY_NONE;
Sakari Ailusc659c382011-01-21 10:59:30 +00002617 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)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002628 priv->phy[1] = phy;
2629 }
2630 }
2631 }
2632
Sakari Ailusc659c382011-01-21 10:59:30 +00002633 if (priv->phy[1] != TLAN_PHY_NONE)
2634 priv->phy_num = 1;
2635 else if (priv->phy[0] != TLAN_PHY_NONE)
2636 priv->phy_num = 0;
2637 else
2638 pr_info("TLAN: Cannot initialize device, no PHY was found!\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002639
Sakari Ailusc659c382011-01-21 10:59:30 +00002640}
Linus Torvalds1da177e2005-04-16 15:20:36 -07002641
2642
2643
2644
Sakari Ailusc659c382011-01-21 10:59:30 +00002645static void tlan_phy_power_down(struct net_device *dev)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002646{
Sakari Ailusc659c382011-01-21 10:59:30 +00002647 struct tlan_priv *priv = netdev_priv(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002648 u16 value;
2649
Sakari Ailusc659c382011-01-21 10:59:30 +00002650 TLAN_DBG(TLAN_DEBUG_GNRL, "%s: Powering down PHY(s).\n", dev->name);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002651 value = MII_GC_PDOWN | MII_GC_LOOPBK | MII_GC_ISOLATE;
Sakari Ailusc659c382011-01-21 10:59:30 +00002652 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);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002659 }
2660
2661 /* Wait for 50 ms and powerup
2662 * This is abitrary. It is intended to make sure the
2663 * transceiver settles.
2664 */
Sakari Ailusc659c382011-01-21 10:59:30 +00002665 tlan_set_timer(dev, (HZ/20), TLAN_TIMER_PHY_PUP);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002666
Sakari Ailusc659c382011-01-21 10:59:30 +00002667}
Linus Torvalds1da177e2005-04-16 15:20:36 -07002668
2669
2670
2671
Sakari Ailusc659c382011-01-21 10:59:30 +00002672static void tlan_phy_power_up(struct net_device *dev)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002673{
Sakari Ailusc659c382011-01-21 10:59:30 +00002674 struct tlan_priv *priv = netdev_priv(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002675 u16 value;
2676
Sakari Ailusc659c382011-01-21 10:59:30 +00002677 TLAN_DBG(TLAN_DEBUG_GNRL, "%s: Powering up PHY.\n", dev->name);
2678 tlan_mii_sync(dev->base_addr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002679 value = MII_GC_LOOPBK;
Sakari Ailusc659c382011-01-21 10:59:30 +00002680 tlan_mii_write_reg(dev, priv->phy[priv->phy_num], MII_GEN_CTL, value);
2681 tlan_mii_sync(dev->base_addr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002682 /* 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.
2685 */
Sakari Ailusc659c382011-01-21 10:59:30 +00002686 tlan_set_timer(dev, (HZ/20), TLAN_TIMER_PHY_RESET);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002687
Sakari Ailusc659c382011-01-21 10:59:30 +00002688}
Linus Torvalds1da177e2005-04-16 15:20:36 -07002689
2690
2691
2692
Sakari Ailusc659c382011-01-21 10:59:30 +00002693static void tlan_phy_reset(struct net_device *dev)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002694{
Sakari Ailusc659c382011-01-21 10:59:30 +00002695 struct tlan_priv *priv = netdev_priv(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002696 u16 phy;
2697 u16 value;
2698
Sakari Ailusc659c382011-01-21 10:59:30 +00002699 phy = priv->phy[priv->phy_num];
Linus Torvalds1da177e2005-04-16 15:20:36 -07002700
Sakari Ailusc659c382011-01-21 10:59:30 +00002701 TLAN_DBG(TLAN_DEBUG_GNRL, "%s: Reseting PHY.\n", dev->name);
2702 tlan_mii_sync(dev->base_addr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002703 value = MII_GC_LOOPBK | MII_GC_RESET;
Sakari Ailusc659c382011-01-21 10:59:30 +00002704 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);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002708
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.
2712 */
Sakari Ailusc659c382011-01-21 10:59:30 +00002713 tlan_set_timer(dev, (HZ/20), TLAN_TIMER_PHY_START_LINK);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002714
Sakari Ailusc659c382011-01-21 10:59:30 +00002715}
Linus Torvalds1da177e2005-04-16 15:20:36 -07002716
2717
2718
2719
Sakari Ailusc659c382011-01-21 10:59:30 +00002720static void tlan_phy_start_link(struct net_device *dev)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002721{
Sakari Ailusc659c382011-01-21 10:59:30 +00002722 struct tlan_priv *priv = netdev_priv(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002723 u16 ability;
2724 u16 control;
2725 u16 data;
2726 u16 phy;
2727 u16 status;
2728 u16 tctl;
2729
Sakari Ailusc659c382011-01-21 10:59:30 +00002730 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);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002734
Sakari Ailusc659c382011-01-21 10:59:30 +00002735 if ((status & MII_GS_AUTONEG) &&
2736 (!priv->aui)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002737 ability = status >> 11;
Sakari Ailusc659c382011-01-21 10:59:30 +00002738 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);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002752 } else {
Jeff Garzik6aa20a22006-09-13 13:24:59 -04002753
Linus Torvalds1da177e2005-04-16 15:20:36 -07002754 /* Set Auto-Neg advertisement */
Sakari Ailusc659c382011-01-21 10:59:30 +00002755 tlan_mii_write_reg(dev, phy, MII_AN_ADV,
2756 (ability << 5) | 1);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002757 /* Enablee Auto-Neg */
Sakari Ailusc659c382011-01-21 10:59:30 +00002758 tlan_mii_write_reg(dev, phy, MII_GEN_CTL, 0x1000);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002759 /* Restart Auto-Neg */
Sakari Ailusc659c382011-01-21 10:59:30 +00002760 tlan_mii_write_reg(dev, phy, MII_GEN_CTL, 0x1200);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002761 /* Wait for 4 sec for autonegotiation
Sakari Ailusc659c382011-01-21 10:59:30 +00002762 * 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.
2765 */
2766 pr_info("TLAN: %s: Starting autonegotiation.\n",
2767 dev->name);
2768 tlan_set_timer(dev, (2*HZ), TLAN_TIMER_PHY_FINISH_AN);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002769 return;
2770 }
Jeff Garzik6aa20a22006-09-13 13:24:59 -04002771
2772 }
2773
Sakari Ailusc659c382011-01-21 10:59:30 +00002774 if ((priv->aui) && (priv->phy_num != 0)) {
2775 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);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002780 return;
Sakari Ailusc659c382011-01-21 10:59:30 +00002781 } else if (priv->phy_num == 0) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002782 control = 0;
Sakari Ailusc659c382011-01-21 10:59:30 +00002783 tlan_mii_read_reg(dev, phy, TLAN_TLPHY_CTL, &tctl);
2784 if (priv->aui) {
2785 tctl |= TLAN_TC_AUISEL;
Jeff Garzik6aa20a22006-09-13 13:24:59 -04002786 } else {
Sakari Ailusc659c382011-01-21 10:59:30 +00002787 tctl &= ~TLAN_TC_AUISEL;
2788 if (priv->duplex == TLAN_DUPLEX_FULL) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002789 control |= MII_GC_DUPLEX;
Sakari Ailusc659c382011-01-21 10:59:30 +00002790 priv->tlan_full_duplex = true;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002791 }
Sakari Ailusc659c382011-01-21 10:59:30 +00002792 if (priv->speed == TLAN_SPEED_100)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002793 control |= MII_GC_SPEEDSEL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002794 }
Sakari Ailusc659c382011-01-21 10:59:30 +00002795 tlan_mii_write_reg(dev, phy, MII_GEN_CTL, control);
2796 tlan_mii_write_reg(dev, phy, TLAN_TLPHY_CTL, tctl);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002797 }
2798
2799 /* Wait for 2 sec to give the transceiver time
2800 * to establish link.
2801 */
Sakari Ailusc659c382011-01-21 10:59:30 +00002802 tlan_set_timer(dev, (4*HZ), TLAN_TIMER_FINISH_RESET);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002803
Sakari Ailusc659c382011-01-21 10:59:30 +00002804}
Linus Torvalds1da177e2005-04-16 15:20:36 -07002805
2806
2807
2808
Sakari Ailusc659c382011-01-21 10:59:30 +00002809static void tlan_phy_finish_auto_neg(struct net_device *dev)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002810{
Sakari Ailusc659c382011-01-21 10:59:30 +00002811 struct tlan_priv *priv = netdev_priv(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002812 u16 an_adv;
2813 u16 an_lpa;
2814 u16 data;
2815 u16 mode;
2816 u16 phy;
2817 u16 status;
Jeff Garzik6aa20a22006-09-13 13:24:59 -04002818
Sakari Ailusc659c382011-01-21 10:59:30 +00002819 phy = priv->phy[priv->phy_num];
Linus Torvalds1da177e2005-04-16 15:20:36 -07002820
Sakari Ailusc659c382011-01-21 10:59:30 +00002821 tlan_mii_read_reg(dev, phy, MII_GEN_STS, &status);
2822 udelay(1000);
2823 tlan_mii_read_reg(dev, phy, MII_GEN_STS, &status);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002824
Sakari Ailusc659c382011-01-21 10:59:30 +00002825 if (!(status & MII_GS_AUTOCMPLT)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002826 /* Wait for 8 sec to give the process
2827 * more time. Perhaps we should fail after a while.
2828 */
Sakari Ailusc659c382011-01-21 10:59:30 +00002829 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");
2834 }
2835 tlan_set_timer(dev, (8*HZ), TLAN_TIMER_PHY_FINISH_AN);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002836 return;
2837 }
2838
Sakari Ailusc659c382011-01-21 10:59:30 +00002839 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);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002842 mode = an_adv & an_lpa & 0x03E0;
Sakari Ailusc659c382011-01-21 10:59:30 +00002843 if (mode & 0x0100)
2844 priv->tlan_full_duplex = true;
2845 else if (!(mode & 0x0080) && (mode & 0x0040))
2846 priv->tlan_full_duplex = true;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002847
Sakari Ailusc659c382011-01-21 10:59:30 +00002848 if ((!(mode & 0x0180)) &&
2849 (priv->adapter->flags & TLAN_ADAPTER_USE_INTERN_10) &&
2850 (priv->phy_num != 0)) {
2851 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);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002856 return;
2857 }
2858
Sakari Ailusc659c382011-01-21 10:59:30 +00002859 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");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002865 } else {
Sakari Ailusc659c382011-01-21 10:59:30 +00002866 tlan_mii_write_reg(dev, phy, MII_GEN_CTL,
2867 MII_GC_AUTOENB);
2868 pr_info("TLAN: Starting internal PHY with HALF-DUPLEX\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002869 }
2870 }
2871
2872 /* Wait for 100 ms. No reason in partiticular.
2873 */
Sakari Ailusc659c382011-01-21 10:59:30 +00002874 tlan_set_timer(dev, (HZ/10), TLAN_TIMER_FINISH_RESET);
Jeff Garzik6aa20a22006-09-13 13:24:59 -04002875
Sakari Ailusc659c382011-01-21 10:59:30 +00002876}
Linus Torvalds1da177e2005-04-16 15:20:36 -07002877
2878#ifdef MONITOR
2879
Sakari Ailusc659c382011-01-21 10:59:30 +00002880/*********************************************************************
2881 *
2882 * tlan_phy_monitor
2883 *
2884 * Returns:
2885 * None
2886 *
2887 * Params:
2888 * dev The device structure of this device.
2889 *
2890 *
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
2894 * media.
2895 *
2896 *******************************************************************/
Linus Torvalds1da177e2005-04-16 15:20:36 -07002897
Sakari Ailusc659c382011-01-21 10:59:30 +00002898void tlan_phy_monitor(struct net_device *dev)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002899{
Sakari Ailusc659c382011-01-21 10:59:30 +00002900 struct tlan_priv *priv = netdev_priv(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002901 u16 phy;
2902 u16 phy_status;
2903
Sakari Ailusc659c382011-01-21 10:59:30 +00002904 phy = priv->phy[priv->phy_num];
Linus Torvalds1da177e2005-04-16 15:20:36 -07002905
Sakari Ailusc659c382011-01-21 10:59:30 +00002906 /* Get PHY status register */
2907 tlan_mii_read_reg(dev, phy, MII_GEN_STS, &phy_status);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002908
Sakari Ailusc659c382011-01-21 10:59:30 +00002909 /* Check if link has been lost */
2910 if (!(phy_status & MII_GS_LINK)) {
2911 if (priv->link) {
2912 priv->link = 0;
2913 printk(KERN_DEBUG "TLAN: %s has lost link\n",
2914 dev->name);
2915 netif_carrier_off(dev);
2916 tlan_set_timer(dev, (2*HZ), TLAN_TIMER_LINK_BEAT);
2917 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002918 }
2919 }
2920
Sakari Ailusc659c382011-01-21 10:59:30 +00002921 /* Link restablished? */
2922 if ((phy_status & MII_GS_LINK) && !priv->link) {
2923 priv->link = 1;
2924 printk(KERN_DEBUG "TLAN: %s has reestablished link\n",
2925 dev->name);
7d17c1d2005-05-12 19:45:25 -04002926 netif_carrier_on(dev);
Sakari Ailusc659c382011-01-21 10:59:30 +00002927 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002928
2929 /* Setup a new monitor */
Sakari Ailusc659c382011-01-21 10:59:30 +00002930 tlan_set_timer(dev, (2*HZ), TLAN_TIMER_LINK_BEAT);
Jeff Garzik6aa20a22006-09-13 13:24:59 -04002931}
Linus Torvalds1da177e2005-04-16 15:20:36 -07002932
2933#endif /* MONITOR */
2934
2935
2936/*****************************************************************************
2937******************************************************************************
2938
Sakari Ailusc659c382011-01-21 10:59:30 +00002939ThunderLAN driver MII routines
Linus Torvalds1da177e2005-04-16 15:20:36 -07002940
Sakari Ailusc659c382011-01-21 10:59:30 +00002941these routines are based on the information in chap. 2 of the
2942"ThunderLAN Programmer's Guide", pp. 15-24.
Linus Torvalds1da177e2005-04-16 15:20:36 -07002943
2944******************************************************************************
2945*****************************************************************************/
2946
2947
Sakari Ailusc659c382011-01-21 10:59:30 +00002948/***************************************************************
2949 * tlan_mii_read_reg
2950 *
2951 * Returns:
2952 * false if ack received ok
2953 * true if no ack received or other error
2954 *
2955 * Parms:
2956 * dev The device structure containing
2957 * The io address and interrupt count
2958 * for this device.
2959 * phy The address of the PHY to be queried.
2960 * reg The register whose contents are to be
2961 * retrieved.
2962 * val A pointer to a variable to store the
2963 * retrieved value.
2964 *
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.
2969 *
2970 **************************************************************/
Linus Torvalds1da177e2005-04-16 15:20:36 -07002971
Sakari Ailusc659c382011-01-21 10:59:30 +00002972static bool
2973tlan_mii_read_reg(struct net_device *dev, u16 phy, u16 reg, u16 *val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002974{
2975 u8 nack;
2976 u16 sio, tmp;
Sakari Ailusc659c382011-01-21 10:59:30 +00002977 u32 i;
Joe Perches37fce432010-01-12 20:59:13 +00002978 bool err;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002979 int minten;
Sakari Ailusc659c382011-01-21 10:59:30 +00002980 struct tlan_priv *priv = netdev_priv(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002981 unsigned long flags = 0;
2982
Joe Perches37fce432010-01-12 20:59:13 +00002983 err = false;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002984 outw(TLAN_NET_SIO, dev->base_addr + TLAN_DIO_ADR);
2985 sio = dev->base_addr + TLAN_DIO_DATA + TLAN_NET_SIO;
Jeff Garzik6aa20a22006-09-13 13:24:59 -04002986
Linus Torvalds1da177e2005-04-16 15:20:36 -07002987 if (!in_irq())
2988 spin_lock_irqsave(&priv->lock, flags);
2989
Sakari Ailusc659c382011-01-21 10:59:30 +00002990 tlan_mii_sync(dev->base_addr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002991
Sakari Ailusc659c382011-01-21 10:59:30 +00002992 minten = tlan_get_bit(TLAN_NET_SIO_MINTEN, sio);
2993 if (minten)
2994 tlan_clear_bit(TLAN_NET_SIO_MINTEN, sio);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002995
Sakari Ailusc659c382011-01-21 10:59:30 +00002996 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 # */
Linus Torvalds1da177e2005-04-16 15:20:36 -07003000
3001
Sakari Ailusc659c382011-01-21 10:59:30 +00003002 tlan_clear_bit(TLAN_NET_SIO_MTXEN, sio); /* change direction */
Linus Torvalds1da177e2005-04-16 15:20:36 -07003003
Sakari Ailusc659c382011-01-21 10:59:30 +00003004 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 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07003007
Sakari Ailusc659c382011-01-21 10:59:30 +00003008 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 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07003011 for (i = 0; i < 16; i++) {
Sakari Ailusc659c382011-01-21 10:59:30 +00003012 tlan_clear_bit(TLAN_NET_SIO_MCLK, sio);
3013 tlan_set_bit(TLAN_NET_SIO_MCLK, sio);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003014 }
3015 tmp = 0xffff;
Joe Perches37fce432010-01-12 20:59:13 +00003016 err = true;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003017 } else { /* ACK, so read data */
3018 for (tmp = 0, i = 0x8000; i; i >>= 1) {
Sakari Ailusc659c382011-01-21 10:59:30 +00003019 tlan_clear_bit(TLAN_NET_SIO_MCLK, sio);
3020 if (tlan_get_bit(TLAN_NET_SIO_MDATA, sio))
Linus Torvalds1da177e2005-04-16 15:20:36 -07003021 tmp |= i;
Sakari Ailusc659c382011-01-21 10:59:30 +00003022 tlan_set_bit(TLAN_NET_SIO_MCLK, sio);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003023 }
3024 }
3025
3026
Sakari Ailusc659c382011-01-21 10:59:30 +00003027 tlan_clear_bit(TLAN_NET_SIO_MCLK, sio); /* idle cycle */
3028 tlan_set_bit(TLAN_NET_SIO_MCLK, sio);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003029
Sakari Ailusc659c382011-01-21 10:59:30 +00003030 if (minten)
3031 tlan_set_bit(TLAN_NET_SIO_MINTEN, sio);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003032
3033 *val = tmp;
Jeff Garzik6aa20a22006-09-13 13:24:59 -04003034
Linus Torvalds1da177e2005-04-16 15:20:36 -07003035 if (!in_irq())
3036 spin_unlock_irqrestore(&priv->lock, flags);
3037
3038 return err;
3039
Sakari Ailusc659c382011-01-21 10:59:30 +00003040}
Linus Torvalds1da177e2005-04-16 15:20:36 -07003041
3042
3043
3044
Sakari Ailusc659c382011-01-21 10:59:30 +00003045/***************************************************************
3046 * tlan_mii_send_data
3047 *
3048 * Returns:
3049 * Nothing
3050 * Parms:
3051 * base_port The base IO port of the adapter in
3052 * question.
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.
3057 *
3058 * This function sends on sequence of bits on the MII
3059 * configuration bus.
3060 *
3061 **************************************************************/
Linus Torvalds1da177e2005-04-16 15:20:36 -07003062
Sakari Ailusc659c382011-01-21 10:59:30 +00003063static void tlan_mii_send_data(u16 base_port, u32 data, unsigned num_bits)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003064{
3065 u16 sio;
3066 u32 i;
3067
Sakari Ailusc659c382011-01-21 10:59:30 +00003068 if (num_bits == 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003069 return;
3070
Sakari Ailusc659c382011-01-21 10:59:30 +00003071 outw(TLAN_NET_SIO, base_port + TLAN_DIO_ADR);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003072 sio = base_port + TLAN_DIO_DATA + TLAN_NET_SIO;
Sakari Ailusc659c382011-01-21 10:59:30 +00003073 tlan_set_bit(TLAN_NET_SIO_MTXEN, sio);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003074
Sakari Ailusc659c382011-01-21 10:59:30 +00003075 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);
3078 if (data & i)
3079 tlan_set_bit(TLAN_NET_SIO_MDATA, sio);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003080 else
Sakari Ailusc659c382011-01-21 10:59:30 +00003081 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);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003084 }
3085
Sakari Ailusc659c382011-01-21 10:59:30 +00003086}
Linus Torvalds1da177e2005-04-16 15:20:36 -07003087
3088
3089
3090
Sakari Ailusc659c382011-01-21 10:59:30 +00003091/***************************************************************
3092 * TLan_MiiSync
3093 *
3094 * Returns:
3095 * Nothing
3096 * Parms:
3097 * base_port The base IO port of the adapter in
3098 * question.
3099 *
3100 * This functions syncs all PHYs in terms of the MII configuration
3101 * bus.
3102 *
3103 **************************************************************/
Linus Torvalds1da177e2005-04-16 15:20:36 -07003104
Sakari Ailusc659c382011-01-21 10:59:30 +00003105static void tlan_mii_sync(u16 base_port)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003106{
3107 int i;
3108 u16 sio;
3109
Sakari Ailusc659c382011-01-21 10:59:30 +00003110 outw(TLAN_NET_SIO, base_port + TLAN_DIO_ADR);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003111 sio = base_port + TLAN_DIO_DATA + TLAN_NET_SIO;
3112
Sakari Ailusc659c382011-01-21 10:59:30 +00003113 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);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003117 }
3118
Sakari Ailusc659c382011-01-21 10:59:30 +00003119}
Linus Torvalds1da177e2005-04-16 15:20:36 -07003120
3121
3122
3123
Sakari Ailusc659c382011-01-21 10:59:30 +00003124/***************************************************************
3125 * tlan_mii_write_reg
3126 *
3127 * Returns:
3128 * Nothing
3129 * Parms:
3130 * dev The device structure for the device
3131 * to write to.
3132 * phy The address of the PHY to be written to.
3133 * reg The register whose contents are to be
3134 * written.
3135 * val The value to be written to the register.
3136 *
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.
3141 *
3142 **************************************************************/
Linus Torvalds1da177e2005-04-16 15:20:36 -07003143
Sakari Ailusc659c382011-01-21 10:59:30 +00003144static void
3145tlan_mii_write_reg(struct net_device *dev, u16 phy, u16 reg, u16 val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003146{
3147 u16 sio;
3148 int minten;
3149 unsigned long flags = 0;
Sakari Ailusc659c382011-01-21 10:59:30 +00003150 struct tlan_priv *priv = netdev_priv(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003151
3152 outw(TLAN_NET_SIO, dev->base_addr + TLAN_DIO_ADR);
3153 sio = dev->base_addr + TLAN_DIO_DATA + TLAN_NET_SIO;
Jeff Garzik6aa20a22006-09-13 13:24:59 -04003154
Linus Torvalds1da177e2005-04-16 15:20:36 -07003155 if (!in_irq())
3156 spin_lock_irqsave(&priv->lock, flags);
3157
Sakari Ailusc659c382011-01-21 10:59:30 +00003158 tlan_mii_sync(dev->base_addr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003159
Sakari Ailusc659c382011-01-21 10:59:30 +00003160 minten = tlan_get_bit(TLAN_NET_SIO_MINTEN, sio);
3161 if (minten)
3162 tlan_clear_bit(TLAN_NET_SIO_MINTEN, sio);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003163
Sakari Ailusc659c382011-01-21 10:59:30 +00003164 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 # */
Linus Torvalds1da177e2005-04-16 15:20:36 -07003168
Sakari Ailusc659c382011-01-21 10:59:30 +00003169 tlan_mii_send_data(dev->base_addr, 0x2, 2); /* send ACK */
3170 tlan_mii_send_data(dev->base_addr, val, 16); /* send data */
Linus Torvalds1da177e2005-04-16 15:20:36 -07003171
Sakari Ailusc659c382011-01-21 10:59:30 +00003172 tlan_clear_bit(TLAN_NET_SIO_MCLK, sio); /* idle cycle */
3173 tlan_set_bit(TLAN_NET_SIO_MCLK, sio);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003174
Sakari Ailusc659c382011-01-21 10:59:30 +00003175 if (minten)
3176 tlan_set_bit(TLAN_NET_SIO_MINTEN, sio);
Jeff Garzik6aa20a22006-09-13 13:24:59 -04003177
Linus Torvalds1da177e2005-04-16 15:20:36 -07003178 if (!in_irq())
3179 spin_unlock_irqrestore(&priv->lock, flags);
3180
Sakari Ailusc659c382011-01-21 10:59:30 +00003181}
Linus Torvalds1da177e2005-04-16 15:20:36 -07003182
3183
3184
3185
3186/*****************************************************************************
3187******************************************************************************
3188
Sakari Ailusc659c382011-01-21 10:59:30 +00003189ThunderLAN driver eeprom routines
Linus Torvalds1da177e2005-04-16 15:20:36 -07003190
Sakari Ailusc659c382011-01-21 10:59:30 +00003191the Compaq netelligent 10 and 10/100 cards use a microchip 24C02A
3192EEPROM. these functions are based on information in microchip's
3193data sheet. I don't know how well this functions will work with
3194other Eeproms.
Linus Torvalds1da177e2005-04-16 15:20:36 -07003195
3196******************************************************************************
3197*****************************************************************************/
3198
3199
Sakari Ailusc659c382011-01-21 10:59:30 +00003200/***************************************************************
3201 * tlan_ee_send_start
3202 *
3203 * Returns:
3204 * Nothing
3205 * Parms:
3206 * io_base The IO port base address for the
3207 * TLAN device with the EEPROM to
3208 * use.
3209 *
3210 * This function sends a start cycle to an EEPROM attached
3211 * to a TLAN chip.
3212 *
3213 **************************************************************/
Linus Torvalds1da177e2005-04-16 15:20:36 -07003214
Sakari Ailusc659c382011-01-21 10:59:30 +00003215static void tlan_ee_send_start(u16 io_base)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003216{
3217 u16 sio;
3218
Sakari Ailusc659c382011-01-21 10:59:30 +00003219 outw(TLAN_NET_SIO, io_base + TLAN_DIO_ADR);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003220 sio = io_base + TLAN_DIO_DATA + TLAN_NET_SIO;
3221
Sakari Ailusc659c382011-01-21 10:59:30 +00003222 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);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003227
Sakari Ailusc659c382011-01-21 10:59:30 +00003228}
Linus Torvalds1da177e2005-04-16 15:20:36 -07003229
3230
3231
3232
Sakari Ailusc659c382011-01-21 10:59:30 +00003233/***************************************************************
3234 * tlan_ee_send_byte
3235 *
3236 * Returns:
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
3240 * use.
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
3246 * read.
3247 *
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
3251 * bit.
3252 *
3253 **************************************************************/
Linus Torvalds1da177e2005-04-16 15:20:36 -07003254
Sakari Ailusc659c382011-01-21 10:59:30 +00003255static int tlan_ee_send_byte(u16 io_base, u8 data, int stop)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003256{
3257 int err;
3258 u8 place;
3259 u16 sio;
3260
Sakari Ailusc659c382011-01-21 10:59:30 +00003261 outw(TLAN_NET_SIO, io_base + TLAN_DIO_ADR);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003262 sio = io_base + TLAN_DIO_DATA + TLAN_NET_SIO;
3263
3264 /* Assume clock is low, tx is enabled; */
Sakari Ailusc659c382011-01-21 10:59:30 +00003265 for (place = 0x80; place != 0; place >>= 1) {
3266 if (place & data)
3267 tlan_set_bit(TLAN_NET_SIO_EDATA, sio);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003268 else
Sakari Ailusc659c382011-01-21 10:59:30 +00003269 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);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003272 }
Sakari Ailusc659c382011-01-21 10:59:30 +00003273 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);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003278
Sakari Ailusc659c382011-01-21 10:59:30 +00003279 if ((!err) && stop) {
Stephen Hemmingerdfc2c0a2008-05-30 09:49:58 -07003280 /* STOP, raise data while clock is high */
Sakari Ailusc659c382011-01-21 10:59:30 +00003281 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);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003284 }
3285
Eric Dumazet807540b2010-09-23 05:40:09 +00003286 return err;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003287
Sakari Ailusc659c382011-01-21 10:59:30 +00003288}
Linus Torvalds1da177e2005-04-16 15:20:36 -07003289
3290
3291
3292
Sakari Ailusc659c382011-01-21 10:59:30 +00003293/***************************************************************
3294 * tlan_ee_receive_byte
3295 *
3296 * Returns:
3297 * Nothing
3298 * Parms:
3299 * io_base The IO port base address for the
3300 * TLAN device with the EEPROM to
3301 * use.
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
3307 * sent.
3308 *
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
3313 * sent.
3314 *
3315 **************************************************************/
Linus Torvalds1da177e2005-04-16 15:20:36 -07003316
Sakari Ailusc659c382011-01-21 10:59:30 +00003317static void tlan_ee_receive_byte(u16 io_base, u8 *data, int stop)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003318{
3319 u8 place;
3320 u16 sio;
3321
Sakari Ailusc659c382011-01-21 10:59:30 +00003322 outw(TLAN_NET_SIO, io_base + TLAN_DIO_ADR);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003323 sio = io_base + TLAN_DIO_DATA + TLAN_NET_SIO;
3324 *data = 0;
3325
3326 /* Assume clock is low, tx is enabled; */
Sakari Ailusc659c382011-01-21 10:59:30 +00003327 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))
Linus Torvalds1da177e2005-04-16 15:20:36 -07003331 *data |= place;
Sakari Ailusc659c382011-01-21 10:59:30 +00003332 tlan_clear_bit(TLAN_NET_SIO_ECLOK, sio);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003333 }
3334
Sakari Ailusc659c382011-01-21 10:59:30 +00003335 tlan_set_bit(TLAN_NET_SIO_ETXEN, sio);
3336 if (!stop) {
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);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003340 } else {
Sakari Ailusc659c382011-01-21 10:59:30 +00003341 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);
Stephen Hemmingerdfc2c0a2008-05-30 09:49:58 -07003344 /* STOP, raise data while clock is high */
Sakari Ailusc659c382011-01-21 10:59:30 +00003345 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);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003348 }
3349
Sakari Ailusc659c382011-01-21 10:59:30 +00003350}
Linus Torvalds1da177e2005-04-16 15:20:36 -07003351
3352
3353
3354
Sakari Ailusc659c382011-01-21 10:59:30 +00003355/***************************************************************
3356 * tlan_ee_read_byte
3357 *
3358 * Returns:
3359 * No error = 0, else, the stage at which the error
3360 * occurred.
3361 * Parms:
3362 * io_base The IO port base address for the
3363 * TLAN device with the EEPROM to
3364 * use.
3365 * ee_addr The address of the byte in the
3366 * EEPROM whose contents are to be
3367 * retrieved.
3368 * data An address to a char to hold the
3369 * data obtained from the EEPROM.
3370 *
3371 * This function reads a byte of information from an byte
3372 * cell in the EEPROM.
3373 *
3374 **************************************************************/
Linus Torvalds1da177e2005-04-16 15:20:36 -07003375
Sakari Ailusc659c382011-01-21 10:59:30 +00003376static int tlan_ee_read_byte(struct net_device *dev, u8 ee_addr, u8 *data)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003377{
3378 int err;
Sakari Ailusc659c382011-01-21 10:59:30 +00003379 struct tlan_priv *priv = netdev_priv(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003380 unsigned long flags = 0;
Sakari Ailusc659c382011-01-21 10:59:30 +00003381 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003382
3383 spin_lock_irqsave(&priv->lock, flags);
3384
Sakari Ailusc659c382011-01-21 10:59:30 +00003385 tlan_ee_send_start(dev->base_addr);
3386 err = tlan_ee_send_byte(dev->base_addr, 0xa0, TLAN_EEPROM_ACK);
3387 if (err) {
3388 ret = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003389 goto fail;
3390 }
Sakari Ailusc659c382011-01-21 10:59:30 +00003391 err = tlan_ee_send_byte(dev->base_addr, ee_addr, TLAN_EEPROM_ACK);
3392 if (err) {
3393 ret = 2;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003394 goto fail;
3395 }
Sakari Ailusc659c382011-01-21 10:59:30 +00003396 tlan_ee_send_start(dev->base_addr);
3397 err = tlan_ee_send_byte(dev->base_addr, 0xa1, TLAN_EEPROM_ACK);
3398 if (err) {
3399 ret = 3;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003400 goto fail;
3401 }
Sakari Ailusc659c382011-01-21 10:59:30 +00003402 tlan_ee_receive_byte(dev->base_addr, data, TLAN_EEPROM_STOP);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003403fail:
3404 spin_unlock_irqrestore(&priv->lock, flags);
3405
3406 return ret;
3407
Sakari Ailusc659c382011-01-21 10:59:30 +00003408}
Linus Torvalds1da177e2005-04-16 15:20:36 -07003409
3410
3411