blob: 57380b1b3b60839e48650374217d582004ed878f [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 Ailus5eeabf52008-12-16 15:24:05 -0800171 *
Sakari Ailusc659c382011-01-21 10:59:30 +0000172 ******************************************************************************/
Linus Torvalds1da177e2005-04-16 15:20:36 -0700173
174#include <linux/module.h>
175#include <linux/init.h>
176#include <linux/ioport.h>
177#include <linux/eisa.h>
178#include <linux/pci.h>
Domen Puncer1e7f0bd2005-06-26 18:22:14 -0400179#include <linux/dma-mapping.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -0700180#include <linux/netdevice.h>
181#include <linux/etherdevice.h>
182#include <linux/delay.h>
183#include <linux/spinlock.h>
184#include <linux/workqueue.h>
185#include <linux/mii.h>
186
187#include "tlan.h"
188
Linus Torvalds1da177e2005-04-16 15:20:36 -0700189
190/* For removing EISA devices */
Sakari Ailusc659c382011-01-21 10:59:30 +0000191static struct net_device *tlan_eisa_devices;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700192
Sakari Ailusc659c382011-01-21 10:59:30 +0000193static int tlan_devices_installed;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700194
195/* Set speed, duplex and aui settings */
196static int aui[MAX_TLAN_BOARDS];
197static int duplex[MAX_TLAN_BOARDS];
198static int speed[MAX_TLAN_BOARDS];
199static int boards_found;
Stephen Hemminger15efa9b2005-05-04 15:33:11 -0700200module_param_array(aui, int, NULL, 0);
201module_param_array(duplex, int, NULL, 0);
202module_param_array(speed, int, NULL, 0);
203MODULE_PARM_DESC(aui, "ThunderLAN use AUI port(s) (0-1)");
Sakari Ailusc659c382011-01-21 10:59:30 +0000204MODULE_PARM_DESC(duplex,
205 "ThunderLAN duplex setting(s) (0-default, 1-half, 2-full)");
Stephen Hemminger15efa9b2005-05-04 15:33:11 -0700206MODULE_PARM_DESC(speed, "ThunderLAN port speen setting(s) (0,10,100)");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700207
208MODULE_AUTHOR("Maintainer: Samuel Chessman <chessman@tux.org>");
209MODULE_DESCRIPTION("Driver for TI ThunderLAN based ethernet PCI adapters");
210MODULE_LICENSE("GPL");
211
212
213/* Define this to enable Link beat monitoring */
214#undef MONITOR
215
216/* Turn on debugging. See Documentation/networking/tlan.txt for details */
217static int debug;
Stephen Hemminger15efa9b2005-05-04 15:33:11 -0700218module_param(debug, int, 0);
219MODULE_PARM_DESC(debug, "ThunderLAN debug mask");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700220
Sakari Ailusc659c382011-01-21 10:59:30 +0000221static const char tlan_signature[] = "TLAN";
222static const char tlan_banner[] = "ThunderLAN driver v1.16\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -0700223static int tlan_have_pci;
224static int tlan_have_eisa;
225
Sakari Ailusc659c382011-01-21 10:59:30 +0000226static const char * const media[] = {
227 "10BaseT-HD", "10BaseT-FD", "100baseTx-HD",
228 "100BaseTx-FD", "100BaseT4", NULL
Linus Torvalds1da177e2005-04-16 15:20:36 -0700229};
230
231static struct board {
Sakari Ailusc659c382011-01-21 10:59:30 +0000232 const char *device_label;
233 u32 flags;
234 u16 addr_ofs;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700235} board_info[] = {
236 { "Compaq Netelligent 10 T PCI UTP", TLAN_ADAPTER_ACTIVITY_LED, 0x83 },
Sakari Ailusc659c382011-01-21 10:59:30 +0000237 { "Compaq Netelligent 10/100 TX PCI UTP",
238 TLAN_ADAPTER_ACTIVITY_LED, 0x83 },
Linus Torvalds1da177e2005-04-16 15:20:36 -0700239 { "Compaq Integrated NetFlex-3/P", TLAN_ADAPTER_NONE, 0x83 },
Stephen Hemmingerdfc2c0a2008-05-30 09:49:58 -0700240 { "Compaq NetFlex-3/P",
241 TLAN_ADAPTER_UNMANAGED_PHY | TLAN_ADAPTER_BIT_RATE_PHY, 0x83 },
Linus Torvalds1da177e2005-04-16 15:20:36 -0700242 { "Compaq NetFlex-3/P", TLAN_ADAPTER_NONE, 0x83 },
Stephen Hemmingerdfc2c0a2008-05-30 09:49:58 -0700243 { "Compaq Netelligent Integrated 10/100 TX UTP",
244 TLAN_ADAPTER_ACTIVITY_LED, 0x83 },
Sakari Ailusc659c382011-01-21 10:59:30 +0000245 { "Compaq Netelligent Dual 10/100 TX PCI UTP",
246 TLAN_ADAPTER_NONE, 0x83 },
247 { "Compaq Netelligent 10/100 TX Embedded UTP",
248 TLAN_ADAPTER_NONE, 0x83 },
Linus Torvalds1da177e2005-04-16 15:20:36 -0700249 { "Olicom OC-2183/2185", TLAN_ADAPTER_USE_INTERN_10, 0x83 },
Sakari Ailusc659c382011-01-21 10:59:30 +0000250 { "Olicom OC-2325", TLAN_ADAPTER_UNMANAGED_PHY, 0xf8 },
251 { "Olicom OC-2326", TLAN_ADAPTER_USE_INTERN_10, 0xf8 },
Linus Torvalds1da177e2005-04-16 15:20:36 -0700252 { "Compaq Netelligent 10/100 TX UTP", TLAN_ADAPTER_ACTIVITY_LED, 0x83 },
Sakari Ailusc659c382011-01-21 10:59:30 +0000253 { "Compaq Netelligent 10 T/2 PCI UTP/coax", TLAN_ADAPTER_NONE, 0x83 },
Stephen Hemmingerdfc2c0a2008-05-30 09:49:58 -0700254 { "Compaq NetFlex-3/E",
Sakari Ailusc659c382011-01-21 10:59:30 +0000255 TLAN_ADAPTER_ACTIVITY_LED | /* EISA card */
Stephen Hemmingerdfc2c0a2008-05-30 09:49:58 -0700256 TLAN_ADAPTER_UNMANAGED_PHY | TLAN_ADAPTER_BIT_RATE_PHY, 0x83 },
Sakari Ailusc659c382011-01-21 10:59:30 +0000257 { "Compaq NetFlex-3/E",
258 TLAN_ADAPTER_ACTIVITY_LED, 0x83 }, /* EISA card */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700259};
260
Alexey Dobriyana3aa1882010-01-07 11:58:11 +0000261static DEFINE_PCI_DEVICE_TABLE(tlan_pci_tbl) = {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700262 { PCI_VENDOR_ID_COMPAQ, PCI_DEVICE_ID_COMPAQ_NETEL10,
Sakari Ailusc659c382011-01-21 10:59:30 +0000263 PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0 },
Linus Torvalds1da177e2005-04-16 15:20:36 -0700264 { PCI_VENDOR_ID_COMPAQ, PCI_DEVICE_ID_COMPAQ_NETEL100,
Sakari Ailusc659c382011-01-21 10:59:30 +0000265 PCI_ANY_ID, PCI_ANY_ID, 0, 0, 1 },
Linus Torvalds1da177e2005-04-16 15:20:36 -0700266 { PCI_VENDOR_ID_COMPAQ, PCI_DEVICE_ID_COMPAQ_NETFLEX3I,
Sakari Ailusc659c382011-01-21 10:59:30 +0000267 PCI_ANY_ID, PCI_ANY_ID, 0, 0, 2 },
Linus Torvalds1da177e2005-04-16 15:20:36 -0700268 { PCI_VENDOR_ID_COMPAQ, PCI_DEVICE_ID_COMPAQ_THUNDER,
Sakari Ailusc659c382011-01-21 10:59:30 +0000269 PCI_ANY_ID, PCI_ANY_ID, 0, 0, 3 },
Linus Torvalds1da177e2005-04-16 15:20:36 -0700270 { PCI_VENDOR_ID_COMPAQ, PCI_DEVICE_ID_COMPAQ_NETFLEX3B,
Sakari Ailusc659c382011-01-21 10:59:30 +0000271 PCI_ANY_ID, PCI_ANY_ID, 0, 0, 4 },
Linus Torvalds1da177e2005-04-16 15:20:36 -0700272 { PCI_VENDOR_ID_COMPAQ, PCI_DEVICE_ID_COMPAQ_NETEL100PI,
Sakari Ailusc659c382011-01-21 10:59:30 +0000273 PCI_ANY_ID, PCI_ANY_ID, 0, 0, 5 },
Linus Torvalds1da177e2005-04-16 15:20:36 -0700274 { PCI_VENDOR_ID_COMPAQ, PCI_DEVICE_ID_COMPAQ_NETEL100D,
Sakari Ailusc659c382011-01-21 10:59:30 +0000275 PCI_ANY_ID, PCI_ANY_ID, 0, 0, 6 },
Linus Torvalds1da177e2005-04-16 15:20:36 -0700276 { PCI_VENDOR_ID_COMPAQ, PCI_DEVICE_ID_COMPAQ_NETEL100I,
Sakari Ailusc659c382011-01-21 10:59:30 +0000277 PCI_ANY_ID, PCI_ANY_ID, 0, 0, 7 },
Linus Torvalds1da177e2005-04-16 15:20:36 -0700278 { PCI_VENDOR_ID_OLICOM, PCI_DEVICE_ID_OLICOM_OC2183,
Sakari Ailusc659c382011-01-21 10:59:30 +0000279 PCI_ANY_ID, PCI_ANY_ID, 0, 0, 8 },
Linus Torvalds1da177e2005-04-16 15:20:36 -0700280 { PCI_VENDOR_ID_OLICOM, PCI_DEVICE_ID_OLICOM_OC2325,
Sakari Ailusc659c382011-01-21 10:59:30 +0000281 PCI_ANY_ID, PCI_ANY_ID, 0, 0, 9 },
Linus Torvalds1da177e2005-04-16 15:20:36 -0700282 { PCI_VENDOR_ID_OLICOM, PCI_DEVICE_ID_OLICOM_OC2326,
Sakari Ailusc659c382011-01-21 10:59:30 +0000283 PCI_ANY_ID, PCI_ANY_ID, 0, 0, 10 },
Linus Torvalds1da177e2005-04-16 15:20:36 -0700284 { PCI_VENDOR_ID_COMPAQ, PCI_DEVICE_ID_NETELLIGENT_10_100_WS_5100,
Sakari Ailusc659c382011-01-21 10:59:30 +0000285 PCI_ANY_ID, PCI_ANY_ID, 0, 0, 11 },
Linus Torvalds1da177e2005-04-16 15:20:36 -0700286 { PCI_VENDOR_ID_COMPAQ, PCI_DEVICE_ID_NETELLIGENT_10_T2,
Sakari Ailusc659c382011-01-21 10:59:30 +0000287 PCI_ANY_ID, PCI_ANY_ID, 0, 0, 12 },
Linus Torvalds1da177e2005-04-16 15:20:36 -0700288 { 0,}
289};
Jeff Garzik6aa20a22006-09-13 13:24:59 -0400290MODULE_DEVICE_TABLE(pci, tlan_pci_tbl);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700291
Sakari Ailusc659c382011-01-21 10:59:30 +0000292static void tlan_eisa_probe(void);
293static void tlan_eisa_cleanup(void);
294static int tlan_init(struct net_device *);
295static int tlan_open(struct net_device *dev);
296static netdev_tx_t tlan_start_tx(struct sk_buff *, struct net_device *);
297static irqreturn_t tlan_handle_interrupt(int, void *);
298static int tlan_close(struct net_device *);
299static struct net_device_stats *tlan_get_stats(struct net_device *);
300static void tlan_set_multicast_list(struct net_device *);
301static int tlan_ioctl(struct net_device *dev, struct ifreq *rq, int cmd);
302static int tlan_probe1(struct pci_dev *pdev, long ioaddr,
303 int irq, int rev, const struct pci_device_id *ent);
304static void tlan_tx_timeout(struct net_device *dev);
305static void tlan_tx_timeout_work(struct work_struct *work);
306static int tlan_init_one(struct pci_dev *pdev,
307 const struct pci_device_id *ent);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700308
Sakari Ailusc659c382011-01-21 10:59:30 +0000309static u32 tlan_handle_tx_eof(struct net_device *, u16);
310static u32 tlan_handle_stat_overflow(struct net_device *, u16);
311static u32 tlan_handle_rx_eof(struct net_device *, u16);
312static u32 tlan_handle_dummy(struct net_device *, u16);
313static u32 tlan_handle_tx_eoc(struct net_device *, u16);
314static u32 tlan_handle_status_check(struct net_device *, u16);
315static u32 tlan_handle_rx_eoc(struct net_device *, u16);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700316
Sakari Ailusc659c382011-01-21 10:59:30 +0000317static void tlan_timer(unsigned long);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700318
Sakari Ailusc659c382011-01-21 10:59:30 +0000319static void tlan_reset_lists(struct net_device *);
320static void tlan_free_lists(struct net_device *);
321static void tlan_print_dio(u16);
322static void tlan_print_list(struct tlan_list *, char *, int);
323static void tlan_read_and_clear_stats(struct net_device *, int);
324static void tlan_reset_adapter(struct net_device *);
325static void tlan_finish_reset(struct net_device *);
326static void tlan_set_mac(struct net_device *, int areg, char *mac);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700327
Sakari Ailusc659c382011-01-21 10:59:30 +0000328static void tlan_phy_print(struct net_device *);
329static void tlan_phy_detect(struct net_device *);
330static void tlan_phy_power_down(struct net_device *);
331static void tlan_phy_power_up(struct net_device *);
332static void tlan_phy_reset(struct net_device *);
333static void tlan_phy_start_link(struct net_device *);
334static void tlan_phy_finish_auto_neg(struct net_device *);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700335#ifdef MONITOR
Sakari Ailusc659c382011-01-21 10:59:30 +0000336static void tlan_phy_monitor(struct net_device *);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700337#endif
338
339/*
Sakari Ailusc659c382011-01-21 10:59:30 +0000340 static int tlan_phy_nop(struct net_device *);
341 static int tlan_phy_internal_check(struct net_device *);
342 static int tlan_phy_internal_service(struct net_device *);
343 static int tlan_phy_dp83840a_check(struct net_device *);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700344*/
345
Sakari Ailusc659c382011-01-21 10:59:30 +0000346static bool tlan_mii_read_reg(struct net_device *, u16, u16, u16 *);
347static void tlan_mii_send_data(u16, u32, unsigned);
348static void tlan_mii_sync(u16);
349static void tlan_mii_write_reg(struct net_device *, u16, u16, u16);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700350
Sakari Ailusc659c382011-01-21 10:59:30 +0000351static void tlan_ee_send_start(u16);
352static int tlan_ee_send_byte(u16, u8, int);
353static void tlan_ee_receive_byte(u16, u8 *, int);
354static int tlan_ee_read_byte(struct net_device *, u8, u8 *);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700355
356
Stephen Hemminger93e16842008-05-30 09:49:55 -0700357static inline void
Sakari Ailusc659c382011-01-21 10:59:30 +0000358tlan_store_skb(struct tlan_list *tag, struct sk_buff *skb)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700359{
360 unsigned long addr = (unsigned long)skb;
Stephen Hemminger93e16842008-05-30 09:49:55 -0700361 tag->buffer[9].address = addr;
362 tag->buffer[8].address = upper_32_bits(addr);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700363}
364
Stephen Hemminger93e16842008-05-30 09:49:55 -0700365static inline struct sk_buff *
Sakari Ailusc659c382011-01-21 10:59:30 +0000366tlan_get_skb(const struct tlan_list *tag)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700367{
Stephen Hemminger93e16842008-05-30 09:49:55 -0700368 unsigned long addr;
369
Robert Fitzsimons0d63bea2008-08-09 17:54:02 +0100370 addr = tag->buffer[9].address;
371 addr |= (tag->buffer[8].address << 16) << 16;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700372 return (struct sk_buff *) addr;
373}
374
Sakari Ailusc659c382011-01-21 10:59:30 +0000375static u32
376(*tlan_int_vector[TLAN_INT_NUMBER_OF_INTS])(struct net_device *, u16) = {
Stephen Hemmingera3ccc782008-05-30 09:49:57 -0700377 NULL,
Sakari Ailusc659c382011-01-21 10:59:30 +0000378 tlan_handle_tx_eof,
379 tlan_handle_stat_overflow,
380 tlan_handle_rx_eof,
381 tlan_handle_dummy,
382 tlan_handle_tx_eoc,
383 tlan_handle_status_check,
384 tlan_handle_rx_eoc
Linus Torvalds1da177e2005-04-16 15:20:36 -0700385};
386
387static inline void
Sakari Ailusc659c382011-01-21 10:59:30 +0000388tlan_set_timer(struct net_device *dev, u32 ticks, u32 type)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700389{
Sakari Ailusc659c382011-01-21 10:59:30 +0000390 struct tlan_priv *priv = netdev_priv(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700391 unsigned long flags = 0;
Jeff Garzik6aa20a22006-09-13 13:24:59 -0400392
Linus Torvalds1da177e2005-04-16 15:20:36 -0700393 if (!in_irq())
394 spin_lock_irqsave(&priv->lock, flags);
Sakari Ailusc659c382011-01-21 10:59:30 +0000395 if (priv->timer.function != NULL &&
396 priv->timer_type != TLAN_TIMER_ACTIVITY) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700397 if (!in_irq())
398 spin_unlock_irqrestore(&priv->lock, flags);
399 return;
400 }
Sakari Ailusc659c382011-01-21 10:59:30 +0000401 priv->timer.function = tlan_timer;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700402 if (!in_irq())
403 spin_unlock_irqrestore(&priv->lock, flags);
404
405 priv->timer.data = (unsigned long) dev;
Sakari Ailusc659c382011-01-21 10:59:30 +0000406 priv->timer_set_at = jiffies;
407 priv->timer_type = type;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700408 mod_timer(&priv->timer, jiffies + ticks);
Jeff Garzik6aa20a22006-09-13 13:24:59 -0400409
Sakari Ailusc659c382011-01-21 10:59:30 +0000410}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700411
412
413/*****************************************************************************
414******************************************************************************
415
Sakari Ailusc659c382011-01-21 10:59:30 +0000416ThunderLAN driver primary functions
Linus Torvalds1da177e2005-04-16 15:20:36 -0700417
Sakari Ailusc659c382011-01-21 10:59:30 +0000418these functions are more or less common to all linux network drivers.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700419
420******************************************************************************
421*****************************************************************************/
422
423
424
425
426
Sakari Ailusc659c382011-01-21 10:59:30 +0000427/***************************************************************
428 * tlan_remove_one
429 *
430 * Returns:
431 * Nothing
432 * Parms:
433 * None
434 *
435 * Goes through the TLanDevices list and frees the device
436 * structs and memory associated with each device (lists
437 * and buffers). It also ureserves the IO port regions
438 * associated with this device.
439 *
440 **************************************************************/
Linus Torvalds1da177e2005-04-16 15:20:36 -0700441
442
Sakari Ailusc659c382011-01-21 10:59:30 +0000443static void __devexit tlan_remove_one(struct pci_dev *pdev)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700444{
Sakari Ailusc659c382011-01-21 10:59:30 +0000445 struct net_device *dev = pci_get_drvdata(pdev);
446 struct tlan_priv *priv = netdev_priv(dev);
Jeff Garzik6aa20a22006-09-13 13:24:59 -0400447
Sakari Ailusc659c382011-01-21 10:59:30 +0000448 unregister_netdev(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700449
Sakari Ailusc659c382011-01-21 10:59:30 +0000450 if (priv->dma_storage) {
451 pci_free_consistent(priv->pci_dev,
452 priv->dma_size, priv->dma_storage,
453 priv->dma_storage_dma);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700454 }
455
456#ifdef CONFIG_PCI
457 pci_release_regions(pdev);
458#endif
Jeff Garzik6aa20a22006-09-13 13:24:59 -0400459
Sakari Ailusc659c382011-01-21 10:59:30 +0000460 free_netdev(dev);
Jeff Garzik6aa20a22006-09-13 13:24:59 -0400461
Sakari Ailusc659c382011-01-21 10:59:30 +0000462 pci_set_drvdata(pdev, NULL);
Jeff Garzik6aa20a22006-09-13 13:24:59 -0400463}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700464
465static struct pci_driver tlan_driver = {
466 .name = "tlan",
467 .id_table = tlan_pci_tbl,
468 .probe = tlan_init_one,
Jeff Garzik6aa20a22006-09-13 13:24:59 -0400469 .remove = __devexit_p(tlan_remove_one),
Linus Torvalds1da177e2005-04-16 15:20:36 -0700470};
471
472static int __init tlan_probe(void)
473{
Leonardo Potenza6c04a512008-02-04 23:47:16 -0800474 int rc = -ENODEV;
Jeff Garzik6aa20a22006-09-13 13:24:59 -0400475
Linus Torvalds1da177e2005-04-16 15:20:36 -0700476 printk(KERN_INFO "%s", tlan_banner);
Jeff Garzik6aa20a22006-09-13 13:24:59 -0400477
Linus Torvalds1da177e2005-04-16 15:20:36 -0700478 TLAN_DBG(TLAN_DEBUG_PROBE, "Starting PCI Probe....\n");
Jeff Garzik6aa20a22006-09-13 13:24:59 -0400479
Linus Torvalds1da177e2005-04-16 15:20:36 -0700480 /* Use new style PCI probing. Now the kernel will
481 do most of this for us */
Leonardo Potenza6c04a512008-02-04 23:47:16 -0800482 rc = pci_register_driver(&tlan_driver);
483
484 if (rc != 0) {
485 printk(KERN_ERR "TLAN: Could not register pci driver.\n");
486 goto err_out_pci_free;
487 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700488
489 TLAN_DBG(TLAN_DEBUG_PROBE, "Starting EISA Probe....\n");
Sakari Ailusc659c382011-01-21 10:59:30 +0000490 tlan_eisa_probe();
Jeff Garzik6aa20a22006-09-13 13:24:59 -0400491
492 printk(KERN_INFO "TLAN: %d device%s installed, PCI: %d EISA: %d\n",
Sakari Ailusc659c382011-01-21 10:59:30 +0000493 tlan_devices_installed, tlan_devices_installed == 1 ? "" : "s",
494 tlan_have_pci, tlan_have_eisa);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700495
Sakari Ailusc659c382011-01-21 10:59:30 +0000496 if (tlan_devices_installed == 0) {
Leonardo Potenza6c04a512008-02-04 23:47:16 -0800497 rc = -ENODEV;
498 goto err_out_pci_unreg;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700499 }
500 return 0;
Leonardo Potenza6c04a512008-02-04 23:47:16 -0800501
502err_out_pci_unreg:
503 pci_unregister_driver(&tlan_driver);
504err_out_pci_free:
Leonardo Potenza6c04a512008-02-04 23:47:16 -0800505 return rc;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700506}
Jeff Garzik6aa20a22006-09-13 13:24:59 -0400507
Linus Torvalds1da177e2005-04-16 15:20:36 -0700508
Sakari Ailusc659c382011-01-21 10:59:30 +0000509static int __devinit tlan_init_one(struct pci_dev *pdev,
510 const struct pci_device_id *ent)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700511{
Sakari Ailusc659c382011-01-21 10:59:30 +0000512 return tlan_probe1(pdev, -1, -1, 0, ent);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700513}
514
515
516/*
Sakari Ailusc659c382011-01-21 10:59:30 +0000517***************************************************************
518* tlan_probe1
519*
520* Returns:
521* 0 on success, error code on error
522* Parms:
523* none
524*
525* The name is lower case to fit in with all the rest of
526* the netcard_probe names. This function looks for
527* another TLan based adapter, setting it up with the
528* allocated device struct if one is found.
529* tlan_probe has been ported to the new net API and
530* now allocates its own device structure. This function
531* is also used by modules.
532*
533**************************************************************/
Linus Torvalds1da177e2005-04-16 15:20:36 -0700534
Sakari Ailusc659c382011-01-21 10:59:30 +0000535static int __devinit tlan_probe1(struct pci_dev *pdev,
Stephen Hemmingerdfc2c0a2008-05-30 09:49:58 -0700536 long ioaddr, int irq, int rev,
Sakari Ailusc659c382011-01-21 10:59:30 +0000537 const struct pci_device_id *ent)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700538{
539
540 struct net_device *dev;
Sakari Ailusc659c382011-01-21 10:59:30 +0000541 struct tlan_priv *priv;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700542 u16 device_id;
543 int reg, rc = -ENODEV;
544
Adrian Bunkad9f6712006-02-05 00:37:47 +0100545#ifdef CONFIG_PCI
Linus Torvalds1da177e2005-04-16 15:20:36 -0700546 if (pdev) {
547 rc = pci_enable_device(pdev);
548 if (rc)
549 return rc;
550
Sakari Ailusc659c382011-01-21 10:59:30 +0000551 rc = pci_request_regions(pdev, tlan_signature);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700552 if (rc) {
553 printk(KERN_ERR "TLAN: Could not reserve IO regions\n");
554 goto err_out;
555 }
556 }
Adrian Bunkad9f6712006-02-05 00:37:47 +0100557#endif /* CONFIG_PCI */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700558
Sakari Ailusc659c382011-01-21 10:59:30 +0000559 dev = alloc_etherdev(sizeof(struct tlan_priv));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700560 if (dev == NULL) {
561 printk(KERN_ERR "TLAN: Could not allocate memory for device.\n");
562 rc = -ENOMEM;
563 goto err_out_regions;
564 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700565 SET_NETDEV_DEV(dev, &pdev->dev);
Jeff Garzik6aa20a22006-09-13 13:24:59 -0400566
Linus Torvalds1da177e2005-04-16 15:20:36 -0700567 priv = netdev_priv(dev);
568
Sakari Ailusc659c382011-01-21 10:59:30 +0000569 priv->pci_dev = pdev;
David Howellsc4028952006-11-22 14:57:56 +0000570 priv->dev = dev;
Jeff Garzik6aa20a22006-09-13 13:24:59 -0400571
Linus Torvalds1da177e2005-04-16 15:20:36 -0700572 /* Is this a PCI device? */
573 if (pdev) {
Sakari Ailusc659c382011-01-21 10:59:30 +0000574 u32 pci_io_base = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700575
576 priv->adapter = &board_info[ent->driver_data];
577
Yang Hongyang284901a2009-04-06 19:01:15 -0700578 rc = pci_set_dma_mask(pdev, DMA_BIT_MASK(32));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700579 if (rc) {
Sakari Ailusc659c382011-01-21 10:59:30 +0000580 printk(KERN_ERR
581 "TLAN: No suitable PCI mapping available.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700582 goto err_out_free_dev;
583 }
584
Sakari Ailusc659c382011-01-21 10:59:30 +0000585 for (reg = 0; reg <= 5; reg++) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700586 if (pci_resource_flags(pdev, reg) & IORESOURCE_IO) {
587 pci_io_base = pci_resource_start(pdev, reg);
Sakari Ailusc659c382011-01-21 10:59:30 +0000588 TLAN_DBG(TLAN_DEBUG_GNRL,
589 "IO mapping is available at %x.\n",
590 pci_io_base);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700591 break;
592 }
593 }
594 if (!pci_io_base) {
595 printk(KERN_ERR "TLAN: No IO mappings available\n");
596 rc = -EIO;
597 goto err_out_free_dev;
598 }
Jeff Garzik6aa20a22006-09-13 13:24:59 -0400599
Linus Torvalds1da177e2005-04-16 15:20:36 -0700600 dev->base_addr = pci_io_base;
601 dev->irq = pdev->irq;
Sakari Ailusc659c382011-01-21 10:59:30 +0000602 priv->adapter_rev = pdev->revision;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700603 pci_set_master(pdev);
604 pci_set_drvdata(pdev, dev);
605
606 } else { /* EISA card */
607 /* This is a hack. We need to know which board structure
608 * is suited for this adapter */
609 device_id = inw(ioaddr + EISA_ID2);
610 priv->is_eisa = 1;
611 if (device_id == 0x20F1) {
Sakari Ailusc659c382011-01-21 10:59:30 +0000612 priv->adapter = &board_info[13]; /* NetFlex-3/E */
613 priv->adapter_rev = 23; /* TLAN 2.3 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700614 } else {
615 priv->adapter = &board_info[14];
Sakari Ailusc659c382011-01-21 10:59:30 +0000616 priv->adapter_rev = 10; /* TLAN 1.0 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700617 }
618 dev->base_addr = ioaddr;
619 dev->irq = irq;
620 }
621
622 /* Kernel parameters */
623 if (dev->mem_start) {
624 priv->aui = dev->mem_start & 0x01;
Stephen Hemmingerdfc2c0a2008-05-30 09:49:58 -0700625 priv->duplex = ((dev->mem_start & 0x06) == 0x06) ? 0
626 : (dev->mem_start & 0x06) >> 1;
627 priv->speed = ((dev->mem_start & 0x18) == 0x18) ? 0
628 : (dev->mem_start & 0x18) >> 3;
Jeff Garzik6aa20a22006-09-13 13:24:59 -0400629
Sakari Ailusc659c382011-01-21 10:59:30 +0000630 if (priv->speed == 0x1)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700631 priv->speed = TLAN_SPEED_10;
Sakari Ailusc659c382011-01-21 10:59:30 +0000632 else if (priv->speed == 0x2)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700633 priv->speed = TLAN_SPEED_100;
Sakari Ailusc659c382011-01-21 10:59:30 +0000634
Linus Torvalds1da177e2005-04-16 15:20:36 -0700635 debug = priv->debug = dev->mem_end;
636 } else {
637 priv->aui = aui[boards_found];
638 priv->speed = speed[boards_found];
639 priv->duplex = duplex[boards_found];
640 priv->debug = debug;
641 }
Jeff Garzik6aa20a22006-09-13 13:24:59 -0400642
Linus Torvalds1da177e2005-04-16 15:20:36 -0700643 /* This will be used when we get an adapter error from
644 * within our irq handler */
Sakari Ailusc659c382011-01-21 10:59:30 +0000645 INIT_WORK(&priv->tlan_tqueue, tlan_tx_timeout_work);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700646
647 spin_lock_init(&priv->lock);
Jeff Garzik6aa20a22006-09-13 13:24:59 -0400648
Sakari Ailusc659c382011-01-21 10:59:30 +0000649 rc = tlan_init(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700650 if (rc) {
651 printk(KERN_ERR "TLAN: Could not set up device.\n");
652 goto err_out_free_dev;
653 }
654
655 rc = register_netdev(dev);
656 if (rc) {
657 printk(KERN_ERR "TLAN: Could not register device.\n");
658 goto err_out_uninit;
659 }
660
Jeff Garzik6aa20a22006-09-13 13:24:59 -0400661
Sakari Ailusc659c382011-01-21 10:59:30 +0000662 tlan_devices_installed++;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700663 boards_found++;
Jeff Garzik6aa20a22006-09-13 13:24:59 -0400664
Linus Torvalds1da177e2005-04-16 15:20:36 -0700665 /* pdev is NULL if this is an EISA device */
666 if (pdev)
667 tlan_have_pci++;
668 else {
Sakari Ailusc659c382011-01-21 10:59:30 +0000669 priv->next_device = tlan_eisa_devices;
670 tlan_eisa_devices = dev;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700671 tlan_have_eisa++;
672 }
Jeff Garzik6aa20a22006-09-13 13:24:59 -0400673
Linus Torvalds1da177e2005-04-16 15:20:36 -0700674 printk(KERN_INFO "TLAN: %s irq=%2d, io=%04x, %s, Rev. %d\n",
Sakari Ailusc659c382011-01-21 10:59:30 +0000675 dev->name,
676 (int) dev->irq,
677 (int) dev->base_addr,
678 priv->adapter->device_label,
679 priv->adapter_rev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700680 return 0;
681
682err_out_uninit:
Sakari Ailusc659c382011-01-21 10:59:30 +0000683 pci_free_consistent(priv->pci_dev, priv->dma_size, priv->dma_storage,
684 priv->dma_storage_dma);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700685err_out_free_dev:
686 free_netdev(dev);
687err_out_regions:
688#ifdef CONFIG_PCI
689 if (pdev)
690 pci_release_regions(pdev);
691#endif
692err_out:
693 if (pdev)
694 pci_disable_device(pdev);
695 return rc;
696}
697
698
Sakari Ailusc659c382011-01-21 10:59:30 +0000699static void tlan_eisa_cleanup(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700700{
701 struct net_device *dev;
Sakari Ailusc659c382011-01-21 10:59:30 +0000702 struct tlan_priv *priv;
Jeff Garzik6aa20a22006-09-13 13:24:59 -0400703
Sakari Ailusc659c382011-01-21 10:59:30 +0000704 while (tlan_have_eisa) {
705 dev = tlan_eisa_devices;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700706 priv = netdev_priv(dev);
Sakari Ailusc659c382011-01-21 10:59:30 +0000707 if (priv->dma_storage) {
708 pci_free_consistent(priv->pci_dev, priv->dma_size,
709 priv->dma_storage,
710 priv->dma_storage_dma);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700711 }
Sakari Ailusc659c382011-01-21 10:59:30 +0000712 release_region(dev->base_addr, 0x10);
713 unregister_netdev(dev);
714 tlan_eisa_devices = priv->next_device;
715 free_netdev(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700716 tlan_have_eisa--;
717 }
718}
Jeff Garzik6aa20a22006-09-13 13:24:59 -0400719
720
Linus Torvalds1da177e2005-04-16 15:20:36 -0700721static void __exit tlan_exit(void)
722{
723 pci_unregister_driver(&tlan_driver);
724
725 if (tlan_have_eisa)
Sakari Ailusc659c382011-01-21 10:59:30 +0000726 tlan_eisa_cleanup();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700727
Linus Torvalds1da177e2005-04-16 15:20:36 -0700728}
729
730
731/* Module loading/unloading */
732module_init(tlan_probe);
733module_exit(tlan_exit);
734
735
736
Sakari Ailusc659c382011-01-21 10:59:30 +0000737/**************************************************************
738 * tlan_eisa_probe
739 *
740 * Returns: 0 on success, 1 otherwise
741 *
742 * Parms: None
743 *
744 *
745 * This functions probes for EISA devices and calls
746 * TLan_probe1 when one is found.
747 *
748 *************************************************************/
Linus Torvalds1da177e2005-04-16 15:20:36 -0700749
Sakari Ailusc659c382011-01-21 10:59:30 +0000750static void __init tlan_eisa_probe(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700751{
Sakari Ailusc659c382011-01-21 10:59:30 +0000752 long ioaddr;
753 int rc = -ENODEV;
754 int irq;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700755 u16 device_id;
756
Jeff Garzik6aa20a22006-09-13 13:24:59 -0400757 if (!EISA_bus) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700758 TLAN_DBG(TLAN_DEBUG_PROBE, "No EISA bus present\n");
759 return;
760 }
Jeff Garzik6aa20a22006-09-13 13:24:59 -0400761
Linus Torvalds1da177e2005-04-16 15:20:36 -0700762 /* Loop through all slots of the EISA bus */
763 for (ioaddr = 0x1000; ioaddr < 0x9000; ioaddr += 0x1000) {
Jeff Garzik6aa20a22006-09-13 13:24:59 -0400764
Sakari Ailusc659c382011-01-21 10:59:30 +0000765 TLAN_DBG(TLAN_DEBUG_PROBE, "EISA_ID 0x%4x: 0x%4x\n",
766 (int) ioaddr + 0xc80, inw(ioaddr + EISA_ID));
767 TLAN_DBG(TLAN_DEBUG_PROBE, "EISA_ID 0x%4x: 0x%4x\n",
768 (int) ioaddr + 0xc82, inw(ioaddr + EISA_ID2));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700769
770
Sakari Ailusc659c382011-01-21 10:59:30 +0000771 TLAN_DBG(TLAN_DEBUG_PROBE,
772 "Probing for EISA adapter at IO: 0x%4x : ",
773 (int) ioaddr);
774 if (request_region(ioaddr, 0x10, tlan_signature) == NULL)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700775 goto out;
776
Jeff Garzik6aa20a22006-09-13 13:24:59 -0400777 if (inw(ioaddr + EISA_ID) != 0x110E) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700778 release_region(ioaddr, 0x10);
779 goto out;
780 }
Jeff Garzik6aa20a22006-09-13 13:24:59 -0400781
Linus Torvalds1da177e2005-04-16 15:20:36 -0700782 device_id = inw(ioaddr + EISA_ID2);
Jeff Garzik6aa20a22006-09-13 13:24:59 -0400783 if (device_id != 0x20F1 && device_id != 0x40F1) {
Sakari Ailusc659c382011-01-21 10:59:30 +0000784 release_region(ioaddr, 0x10);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700785 goto out;
786 }
Jeff Garzik6aa20a22006-09-13 13:24:59 -0400787
Sakari Ailusc659c382011-01-21 10:59:30 +0000788 /* check if adapter is enabled */
789 if (inb(ioaddr + EISA_CR) != 0x1) {
790 release_region(ioaddr, 0x10);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700791 goto out2;
792 }
Jeff Garzik6aa20a22006-09-13 13:24:59 -0400793
794 if (debug == 0x10)
Sakari Ailusc659c382011-01-21 10:59:30 +0000795 printk(KERN_INFO "Found one\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700796
797
798 /* Get irq from board */
Sakari Ailusc659c382011-01-21 10:59:30 +0000799 switch (inb(ioaddr + 0xcc0)) {
800 case(0x10):
801 irq = 5;
802 break;
803 case(0x20):
804 irq = 9;
805 break;
806 case(0x40):
807 irq = 10;
808 break;
809 case(0x80):
810 irq = 11;
811 break;
812 default:
813 goto out;
Jeff Garzik6aa20a22006-09-13 13:24:59 -0400814 }
815
816
Linus Torvalds1da177e2005-04-16 15:20:36 -0700817 /* Setup the newly found eisa adapter */
Sakari Ailusc659c382011-01-21 10:59:30 +0000818 rc = tlan_probe1(NULL, ioaddr, irq,
819 12, NULL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700820 continue;
Jeff Garzik6aa20a22006-09-13 13:24:59 -0400821
Sakari Ailusc659c382011-01-21 10:59:30 +0000822out:
823 if (debug == 0x10)
824 printk(KERN_INFO "None found\n");
825 continue;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700826
Sakari Ailusc659c382011-01-21 10:59:30 +0000827out2:
828 if (debug == 0x10)
829 printk(KERN_INFO "Card found but it is not enabled, skipping\n");
830 continue;
Jeff Garzik6aa20a22006-09-13 13:24:59 -0400831
Linus Torvalds1da177e2005-04-16 15:20:36 -0700832 }
833
Sakari Ailusc659c382011-01-21 10:59:30 +0000834}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700835
836#ifdef CONFIG_NET_POLL_CONTROLLER
Sakari Ailusc659c382011-01-21 10:59:30 +0000837static void tlan_poll(struct net_device *dev)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700838{
839 disable_irq(dev->irq);
Sakari Ailusc659c382011-01-21 10:59:30 +0000840 tlan_handle_interrupt(dev->irq, dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700841 enable_irq(dev->irq);
842}
843#endif
844
Sakari Ailusc659c382011-01-21 10:59:30 +0000845static const struct net_device_ops tlan_netdev_ops = {
846 .ndo_open = tlan_open,
847 .ndo_stop = tlan_close,
848 .ndo_start_xmit = tlan_start_tx,
849 .ndo_tx_timeout = tlan_tx_timeout,
850 .ndo_get_stats = tlan_get_stats,
851 .ndo_set_multicast_list = tlan_set_multicast_list,
852 .ndo_do_ioctl = tlan_ioctl,
Stephen Hemminger391c5e62009-01-07 17:27:15 -0800853 .ndo_change_mtu = eth_change_mtu,
Sakari Ailusc659c382011-01-21 10:59:30 +0000854 .ndo_set_mac_address = eth_mac_addr,
Stephen Hemminger391c5e62009-01-07 17:27:15 -0800855 .ndo_validate_addr = eth_validate_addr,
856#ifdef CONFIG_NET_POLL_CONTROLLER
Sakari Ailusc659c382011-01-21 10:59:30 +0000857 .ndo_poll_controller = tlan_poll,
Stephen Hemminger391c5e62009-01-07 17:27:15 -0800858#endif
859};
Jeff Garzik6aa20a22006-09-13 13:24:59 -0400860
Linus Torvalds1da177e2005-04-16 15:20:36 -0700861
862
Sakari Ailusc659c382011-01-21 10:59:30 +0000863/***************************************************************
864 * tlan_init
865 *
866 * Returns:
867 * 0 on success, error code otherwise.
868 * Parms:
869 * dev The structure of the device to be
870 * init'ed.
871 *
872 * This function completes the initialization of the
873 * device structure and driver. It reserves the IO
874 * addresses, allocates memory for the lists and bounce
875 * buffers, retrieves the MAC address from the eeprom
876 * and assignes the device's methods.
877 *
878 **************************************************************/
Linus Torvalds1da177e2005-04-16 15:20:36 -0700879
Sakari Ailusc659c382011-01-21 10:59:30 +0000880static int tlan_init(struct net_device *dev)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700881{
882 int dma_size;
Sakari Ailusc659c382011-01-21 10:59:30 +0000883 int err;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700884 int i;
Sakari Ailusc659c382011-01-21 10:59:30 +0000885 struct tlan_priv *priv;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700886
887 priv = netdev_priv(dev);
Jeff Garzik6aa20a22006-09-13 13:24:59 -0400888
Sakari Ailusc659c382011-01-21 10:59:30 +0000889 dma_size = (TLAN_NUM_RX_LISTS + TLAN_NUM_TX_LISTS)
890 * (sizeof(struct tlan_list));
891 priv->dma_storage = pci_alloc_consistent(priv->pci_dev,
892 dma_size,
893 &priv->dma_storage_dma);
894 priv->dma_size = dma_size;
Jeff Garzik6aa20a22006-09-13 13:24:59 -0400895
Sakari Ailusc659c382011-01-21 10:59:30 +0000896 if (priv->dma_storage == NULL) {
897 printk(KERN_ERR
898 "TLAN: Could not allocate lists and buffers for %s.\n",
899 dev->name);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700900 return -ENOMEM;
901 }
Sakari Ailusc659c382011-01-21 10:59:30 +0000902 memset(priv->dma_storage, 0, dma_size);
903 priv->rx_list = (struct tlan_list *)
904 ALIGN((unsigned long)priv->dma_storage, 8);
905 priv->rx_list_dma = ALIGN(priv->dma_storage_dma, 8);
906 priv->tx_list = priv->rx_list + TLAN_NUM_RX_LISTS;
907 priv->tx_list_dma =
908 priv->rx_list_dma + sizeof(struct tlan_list)*TLAN_NUM_RX_LISTS;
Stephen Hemminger93e16842008-05-30 09:49:55 -0700909
Linus Torvalds1da177e2005-04-16 15:20:36 -0700910 err = 0;
Sakari Ailusc659c382011-01-21 10:59:30 +0000911 for (i = 0; i < 6 ; i++)
912 err |= tlan_ee_read_byte(dev,
913 (u8) priv->adapter->addr_ofs + i,
914 (u8 *) &dev->dev_addr[i]);
915 if (err) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700916 printk(KERN_ERR "TLAN: %s: Error reading MAC from eeprom: %d\n",
Sakari Ailusc659c382011-01-21 10:59:30 +0000917 dev->name,
918 err);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700919 }
920 dev->addr_len = 6;
921
922 netif_carrier_off(dev);
923
924 /* Device methods */
Sakari Ailusc659c382011-01-21 10:59:30 +0000925 dev->netdev_ops = &tlan_netdev_ops;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700926 dev->watchdog_timeo = TX_TIMEOUT;
927
928 return 0;
929
Sakari Ailusc659c382011-01-21 10:59:30 +0000930}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700931
932
933
934
Sakari Ailusc659c382011-01-21 10:59:30 +0000935/***************************************************************
936 * tlan_open
937 *
938 * Returns:
939 * 0 on success, error code otherwise.
940 * Parms:
941 * dev Structure of device to be opened.
942 *
943 * This routine puts the driver and TLAN adapter in a
944 * state where it is ready to send and receive packets.
945 * It allocates the IRQ, resets and brings the adapter
946 * out of reset, and allows interrupts. It also delays
947 * the startup for autonegotiation or sends a Rx GO
948 * command to the adapter, as appropriate.
949 *
950 **************************************************************/
Linus Torvalds1da177e2005-04-16 15:20:36 -0700951
Sakari Ailusc659c382011-01-21 10:59:30 +0000952static int tlan_open(struct net_device *dev)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700953{
Sakari Ailusc659c382011-01-21 10:59:30 +0000954 struct tlan_priv *priv = netdev_priv(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700955 int err;
Jeff Garzik6aa20a22006-09-13 13:24:59 -0400956
Sakari Ailusc659c382011-01-21 10:59:30 +0000957 priv->tlan_rev = tlan_dio_read8(dev->base_addr, TLAN_DEF_REVISION);
958 err = request_irq(dev->irq, tlan_handle_interrupt, IRQF_SHARED,
959 dev->name, dev);
Jeff Garzik6aa20a22006-09-13 13:24:59 -0400960
Sakari Ailusc659c382011-01-21 10:59:30 +0000961 if (err) {
Stephen Hemmingerdfc2c0a2008-05-30 09:49:58 -0700962 pr_err("TLAN: Cannot open %s because IRQ %d is already in use.\n",
Sakari Ailusc659c382011-01-21 10:59:30 +0000963 dev->name, dev->irq);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700964 return err;
965 }
Jeff Garzik6aa20a22006-09-13 13:24:59 -0400966
Linus Torvalds1da177e2005-04-16 15:20:36 -0700967 init_timer(&priv->timer);
968 netif_start_queue(dev);
Jeff Garzik6aa20a22006-09-13 13:24:59 -0400969
Linus Torvalds1da177e2005-04-16 15:20:36 -0700970 /* NOTE: It might not be necessary to read the stats before a
Sakari Ailusc659c382011-01-21 10:59:30 +0000971 reset if you don't care what the values are.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700972 */
Sakari Ailusc659c382011-01-21 10:59:30 +0000973 tlan_reset_lists(dev);
974 tlan_read_and_clear_stats(dev, TLAN_IGNORE);
975 tlan_reset_adapter(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700976
Sakari Ailusc659c382011-01-21 10:59:30 +0000977 TLAN_DBG(TLAN_DEBUG_GNRL, "%s: Opened. TLAN Chip Rev: %x\n",
978 dev->name, priv->tlan_rev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700979
980 return 0;
981
Sakari Ailusc659c382011-01-21 10:59:30 +0000982}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700983
984
985
Sakari Ailusc659c382011-01-21 10:59:30 +0000986/**************************************************************
987 * tlan_ioctl
988 *
989 * Returns:
990 * 0 on success, error code otherwise
991 * Params:
992 * dev structure of device to receive ioctl.
993 *
994 * rq ifreq structure to hold userspace data.
995 *
996 * cmd ioctl command.
997 *
998 *
999 *************************************************************/
Linus Torvalds1da177e2005-04-16 15:20:36 -07001000
Sakari Ailusc659c382011-01-21 10:59:30 +00001001static int tlan_ioctl(struct net_device *dev, struct ifreq *rq, int cmd)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001002{
Sakari Ailusc659c382011-01-21 10:59:30 +00001003 struct tlan_priv *priv = netdev_priv(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001004 struct mii_ioctl_data *data = if_mii(rq);
Sakari Ailusc659c382011-01-21 10:59:30 +00001005 u32 phy = priv->phy[priv->phy_num];
Jeff Garzik6aa20a22006-09-13 13:24:59 -04001006
Sakari Ailusc659c382011-01-21 10:59:30 +00001007 if (!priv->phy_online)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001008 return -EAGAIN;
1009
Sakari Ailusc659c382011-01-21 10:59:30 +00001010 switch (cmd) {
1011 case SIOCGMIIPHY: /* get address of MII PHY in use. */
1012 data->phy_id = phy;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001013
1014
Sakari Ailusc659c382011-01-21 10:59:30 +00001015 case SIOCGMIIREG: /* read MII PHY register. */
1016 tlan_mii_read_reg(dev, data->phy_id & 0x1f,
1017 data->reg_num & 0x1f, &data->val_out);
1018 return 0;
Jeff Garzik6aa20a22006-09-13 13:24:59 -04001019
Linus Torvalds1da177e2005-04-16 15:20:36 -07001020
Sakari Ailusc659c382011-01-21 10:59:30 +00001021 case SIOCSMIIREG: /* write MII PHY register. */
1022 tlan_mii_write_reg(dev, data->phy_id & 0x1f,
1023 data->reg_num & 0x1f, data->val_in);
1024 return 0;
1025 default:
1026 return -EOPNOTSUPP;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001027 }
Sakari Ailusc659c382011-01-21 10:59:30 +00001028}
Linus Torvalds1da177e2005-04-16 15:20:36 -07001029
1030
Sakari Ailusc659c382011-01-21 10:59:30 +00001031/***************************************************************
1032 * tlan_tx_timeout
1033 *
1034 * Returns: nothing
1035 *
1036 * Params:
1037 * dev structure of device which timed out
1038 * during transmit.
1039 *
1040 **************************************************************/
Linus Torvalds1da177e2005-04-16 15:20:36 -07001041
Sakari Ailusc659c382011-01-21 10:59:30 +00001042static void tlan_tx_timeout(struct net_device *dev)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001043{
Jeff Garzik6aa20a22006-09-13 13:24:59 -04001044
Sakari Ailusc659c382011-01-21 10:59:30 +00001045 TLAN_DBG(TLAN_DEBUG_GNRL, "%s: Transmit timed out.\n", dev->name);
Jeff Garzik6aa20a22006-09-13 13:24:59 -04001046
Linus Torvalds1da177e2005-04-16 15:20:36 -07001047 /* Ok so we timed out, lets see what we can do about it...*/
Sakari Ailusc659c382011-01-21 10:59:30 +00001048 tlan_free_lists(dev);
1049 tlan_reset_lists(dev);
1050 tlan_read_and_clear_stats(dev, TLAN_IGNORE);
1051 tlan_reset_adapter(dev);
Eric Dumazet1ae5dc32010-05-10 05:01:31 -07001052 dev->trans_start = jiffies; /* prevent tx timeout */
Sakari Ailusc659c382011-01-21 10:59:30 +00001053 netif_wake_queue(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001054
1055}
Jeff Garzik6aa20a22006-09-13 13:24:59 -04001056
Linus Torvalds1da177e2005-04-16 15:20:36 -07001057
Sakari Ailusc659c382011-01-21 10:59:30 +00001058/***************************************************************
1059 * tlan_tx_timeout_work
1060 *
1061 * Returns: nothing
1062 *
1063 * Params:
1064 * work work item of device which timed out
1065 *
1066 **************************************************************/
David Howellsc4028952006-11-22 14:57:56 +00001067
Sakari Ailusc659c382011-01-21 10:59:30 +00001068static void tlan_tx_timeout_work(struct work_struct *work)
David Howellsc4028952006-11-22 14:57:56 +00001069{
Sakari Ailusc659c382011-01-21 10:59:30 +00001070 struct tlan_priv *priv =
1071 container_of(work, struct tlan_priv, tlan_tqueue);
David Howellsc4028952006-11-22 14:57:56 +00001072
Sakari Ailusc659c382011-01-21 10:59:30 +00001073 tlan_tx_timeout(priv->dev);
David Howellsc4028952006-11-22 14:57:56 +00001074}
1075
1076
Linus Torvalds1da177e2005-04-16 15:20:36 -07001077
Sakari Ailusc659c382011-01-21 10:59:30 +00001078/***************************************************************
1079 * tlan_start_tx
1080 *
1081 * Returns:
1082 * 0 on success, non-zero on failure.
1083 * Parms:
1084 * skb A pointer to the sk_buff containing the
1085 * frame to be sent.
1086 * dev The device to send the data on.
1087 *
1088 * This function adds a frame to the Tx list to be sent
1089 * ASAP. First it verifies that the adapter is ready and
1090 * there is room in the queue. Then it sets up the next
1091 * available list, copies the frame to the corresponding
1092 * buffer. If the adapter Tx channel is idle, it gives
1093 * the adapter a Tx Go command on the list, otherwise it
1094 * sets the forward address of the previous list to point
1095 * to this one. Then it frees the sk_buff.
1096 *
1097 **************************************************************/
Linus Torvalds1da177e2005-04-16 15:20:36 -07001098
Sakari Ailusc659c382011-01-21 10:59:30 +00001099static netdev_tx_t tlan_start_tx(struct sk_buff *skb, struct net_device *dev)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001100{
Sakari Ailusc659c382011-01-21 10:59:30 +00001101 struct tlan_priv *priv = netdev_priv(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001102 dma_addr_t tail_list_phys;
Sakari Ailusc659c382011-01-21 10:59:30 +00001103 struct tlan_list *tail_list;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001104 unsigned long flags;
Sakari Ailus8953f122008-12-16 01:44:05 -08001105 unsigned int txlen;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001106
Sakari Ailusc659c382011-01-21 10:59:30 +00001107 if (!priv->phy_online) {
1108 TLAN_DBG(TLAN_DEBUG_TX, "TRANSMIT: %s PHY is not ready\n",
1109 dev->name);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001110 dev_kfree_skb_any(skb);
Patrick McHardy6ed10652009-06-23 06:03:08 +00001111 return NETDEV_TX_OK;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001112 }
1113
Stephen Hemminger41873e92008-05-30 09:49:52 -07001114 if (skb_padto(skb, TLAN_MIN_FRAME_SIZE))
Patrick McHardy6ed10652009-06-23 06:03:08 +00001115 return NETDEV_TX_OK;
Sakari Ailus8953f122008-12-16 01:44:05 -08001116 txlen = max(skb->len, (unsigned int)TLAN_MIN_FRAME_SIZE);
Stephen Hemminger41873e92008-05-30 09:49:52 -07001117
Sakari Ailusc659c382011-01-21 10:59:30 +00001118 tail_list = priv->tx_list + priv->tx_tail;
1119 tail_list_phys =
1120 priv->tx_list_dma + sizeof(struct tlan_list)*priv->tx_tail;
Jeff Garzik6aa20a22006-09-13 13:24:59 -04001121
Sakari Ailusc659c382011-01-21 10:59:30 +00001122 if (tail_list->c_stat != TLAN_CSTAT_UNUSED) {
1123 TLAN_DBG(TLAN_DEBUG_TX,
1124 "TRANSMIT: %s is busy (Head=%d Tail=%d)\n",
1125 dev->name, priv->tx_head, priv->tx_tail);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001126 netif_stop_queue(dev);
Sakari Ailusc659c382011-01-21 10:59:30 +00001127 priv->tx_busy_count++;
Patrick McHardy5b548142009-06-12 06:22:29 +00001128 return NETDEV_TX_BUSY;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001129 }
1130
1131 tail_list->forward = 0;
1132
Sakari Ailusc659c382011-01-21 10:59:30 +00001133 tail_list->buffer[0].address = pci_map_single(priv->pci_dev,
Sakari Ailus5eeabf52008-12-16 15:24:05 -08001134 skb->data, txlen,
1135 PCI_DMA_TODEVICE);
Sakari Ailusc659c382011-01-21 10:59:30 +00001136 tlan_store_skb(tail_list, skb);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001137
Sakari Ailusc659c382011-01-21 10:59:30 +00001138 tail_list->frame_size = (u16) txlen;
Sakari Ailus8953f122008-12-16 01:44:05 -08001139 tail_list->buffer[0].count = TLAN_LAST_BUFFER | (u32) txlen;
Stephen Hemminger41873e92008-05-30 09:49:52 -07001140 tail_list->buffer[1].count = 0;
1141 tail_list->buffer[1].address = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001142
1143 spin_lock_irqsave(&priv->lock, flags);
Sakari Ailusc659c382011-01-21 10:59:30 +00001144 tail_list->c_stat = TLAN_CSTAT_READY;
1145 if (!priv->tx_in_progress) {
1146 priv->tx_in_progress = 1;
1147 TLAN_DBG(TLAN_DEBUG_TX,
1148 "TRANSMIT: Starting TX on buffer %d\n",
1149 priv->tx_tail);
1150 outl(tail_list_phys, dev->base_addr + TLAN_CH_PARM);
1151 outl(TLAN_HC_GO, dev->base_addr + TLAN_HOST_CMD);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001152 } else {
Sakari Ailusc659c382011-01-21 10:59:30 +00001153 TLAN_DBG(TLAN_DEBUG_TX,
1154 "TRANSMIT: Adding buffer %d to TX channel\n",
1155 priv->tx_tail);
1156 if (priv->tx_tail == 0) {
1157 (priv->tx_list + (TLAN_NUM_TX_LISTS - 1))->forward
Stephen Hemmingerdfc2c0a2008-05-30 09:49:58 -07001158 = tail_list_phys;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001159 } else {
Sakari Ailusc659c382011-01-21 10:59:30 +00001160 (priv->tx_list + (priv->tx_tail - 1))->forward
Stephen Hemmingerdfc2c0a2008-05-30 09:49:58 -07001161 = tail_list_phys;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001162 }
1163 }
1164 spin_unlock_irqrestore(&priv->lock, flags);
1165
Sakari Ailusc659c382011-01-21 10:59:30 +00001166 CIRC_INC(priv->tx_tail, TLAN_NUM_TX_LISTS);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001167
Patrick McHardy6ed10652009-06-23 06:03:08 +00001168 return NETDEV_TX_OK;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001169
Sakari Ailusc659c382011-01-21 10:59:30 +00001170}
Linus Torvalds1da177e2005-04-16 15:20:36 -07001171
1172
1173
1174
Sakari Ailusc659c382011-01-21 10:59:30 +00001175/***************************************************************
1176 * tlan_handle_interrupt
1177 *
1178 * Returns:
1179 * Nothing
1180 * Parms:
1181 * irq The line on which the interrupt
1182 * occurred.
1183 * dev_id A pointer to the device assigned to
1184 * this irq line.
1185 *
1186 * This function handles an interrupt generated by its
1187 * assigned TLAN adapter. The function deactivates
1188 * interrupts on its adapter, records the type of
1189 * interrupt, executes the appropriate subhandler, and
1190 * acknowdges the interrupt to the adapter (thus
1191 * re-enabling adapter interrupts.
1192 *
1193 **************************************************************/
Linus Torvalds1da177e2005-04-16 15:20:36 -07001194
Sakari Ailusc659c382011-01-21 10:59:30 +00001195static irqreturn_t tlan_handle_interrupt(int irq, void *dev_id)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001196{
Stephen Hemmingera3ccc782008-05-30 09:49:57 -07001197 struct net_device *dev = dev_id;
Sakari Ailusc659c382011-01-21 10:59:30 +00001198 struct tlan_priv *priv = netdev_priv(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001199 u16 host_int;
Stephen Hemmingera3ccc782008-05-30 09:49:57 -07001200 u16 type;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001201
1202 spin_lock(&priv->lock);
1203
Sakari Ailusc659c382011-01-21 10:59:30 +00001204 host_int = inw(dev->base_addr + TLAN_HOST_INT);
1205 type = (host_int & TLAN_HI_IT_MASK) >> 2;
1206 if (type) {
Stephen Hemmingera3ccc782008-05-30 09:49:57 -07001207 u32 ack;
1208 u32 host_cmd;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001209
Sakari Ailusc659c382011-01-21 10:59:30 +00001210 outw(host_int, dev->base_addr + TLAN_HOST_INT);
1211 ack = tlan_int_vector[type](dev, host_int);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001212
Sakari Ailusc659c382011-01-21 10:59:30 +00001213 if (ack) {
1214 host_cmd = TLAN_HC_ACK | ack | (type << 18);
1215 outl(host_cmd, dev->base_addr + TLAN_HOST_CMD);
Stephen Hemmingera3ccc782008-05-30 09:49:57 -07001216 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001217 }
1218
1219 spin_unlock(&priv->lock);
1220
Stephen Hemmingera3ccc782008-05-30 09:49:57 -07001221 return IRQ_RETVAL(type);
Sakari Ailusc659c382011-01-21 10:59:30 +00001222}
Linus Torvalds1da177e2005-04-16 15:20:36 -07001223
1224
1225
1226
Sakari Ailusc659c382011-01-21 10:59:30 +00001227/***************************************************************
1228 * tlan_close
1229 *
1230 * Returns:
1231 * An error code.
1232 * Parms:
1233 * dev The device structure of the device to
1234 * close.
1235 *
1236 * This function shuts down the adapter. It records any
1237 * stats, puts the adapter into reset state, deactivates
1238 * its time as needed, and frees the irq it is using.
1239 *
1240 **************************************************************/
Linus Torvalds1da177e2005-04-16 15:20:36 -07001241
Sakari Ailusc659c382011-01-21 10:59:30 +00001242static int tlan_close(struct net_device *dev)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001243{
Sakari Ailusc659c382011-01-21 10:59:30 +00001244 struct tlan_priv *priv = netdev_priv(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001245
1246 netif_stop_queue(dev);
1247 priv->neg_be_verbose = 0;
1248
Sakari Ailusc659c382011-01-21 10:59:30 +00001249 tlan_read_and_clear_stats(dev, TLAN_RECORD);
1250 outl(TLAN_HC_AD_RST, dev->base_addr + TLAN_HOST_CMD);
1251 if (priv->timer.function != NULL) {
1252 del_timer_sync(&priv->timer);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001253 priv->timer.function = NULL;
1254 }
Jeff Garzik6aa20a22006-09-13 13:24:59 -04001255
Sakari Ailusc659c382011-01-21 10:59:30 +00001256 free_irq(dev->irq, dev);
1257 tlan_free_lists(dev);
1258 TLAN_DBG(TLAN_DEBUG_GNRL, "Device %s closed.\n", dev->name);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001259
1260 return 0;
1261
Sakari Ailusc659c382011-01-21 10:59:30 +00001262}
Linus Torvalds1da177e2005-04-16 15:20:36 -07001263
1264
1265
1266
Sakari Ailusc659c382011-01-21 10:59:30 +00001267/***************************************************************
1268 * tlan_get_stats
1269 *
1270 * Returns:
1271 * A pointer to the device's statistics structure.
1272 * Parms:
1273 * dev The device structure to return the
1274 * stats for.
1275 *
1276 * This function updates the devices statistics by reading
1277 * the TLAN chip's onboard registers. Then it returns the
1278 * address of the statistics structure.
1279 *
1280 **************************************************************/
Linus Torvalds1da177e2005-04-16 15:20:36 -07001281
Sakari Ailusc659c382011-01-21 10:59:30 +00001282static struct net_device_stats *tlan_get_stats(struct net_device *dev)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001283{
Sakari Ailusc659c382011-01-21 10:59:30 +00001284 struct tlan_priv *priv = netdev_priv(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001285 int i;
1286
1287 /* Should only read stats if open ? */
Sakari Ailusc659c382011-01-21 10:59:30 +00001288 tlan_read_and_clear_stats(dev, TLAN_RECORD);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001289
Sakari Ailusc659c382011-01-21 10:59:30 +00001290 TLAN_DBG(TLAN_DEBUG_RX, "RECEIVE: %s EOC count = %d\n", dev->name,
1291 priv->rx_eoc_count);
1292 TLAN_DBG(TLAN_DEBUG_TX, "TRANSMIT: %s Busy count = %d\n", dev->name,
1293 priv->tx_busy_count);
1294 if (debug & TLAN_DEBUG_GNRL) {
1295 tlan_print_dio(dev->base_addr);
1296 tlan_phy_print(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001297 }
Sakari Ailusc659c382011-01-21 10:59:30 +00001298 if (debug & TLAN_DEBUG_LIST) {
1299 for (i = 0; i < TLAN_NUM_RX_LISTS; i++)
1300 tlan_print_list(priv->rx_list + i, "RX", i);
1301 for (i = 0; i < TLAN_NUM_TX_LISTS; i++)
1302 tlan_print_list(priv->tx_list + i, "TX", i);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001303 }
Jeff Garzik6aa20a22006-09-13 13:24:59 -04001304
Stephen Hemmingerf8f31542008-05-30 09:49:53 -07001305 return &dev->stats;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001306
Sakari Ailusc659c382011-01-21 10:59:30 +00001307}
Linus Torvalds1da177e2005-04-16 15:20:36 -07001308
1309
1310
1311
Sakari Ailusc659c382011-01-21 10:59:30 +00001312/***************************************************************
1313 * tlan_set_multicast_list
1314 *
1315 * Returns:
1316 * Nothing
1317 * Parms:
1318 * dev The device structure to set the
1319 * multicast list for.
1320 *
1321 * This function sets the TLAN adaptor to various receive
1322 * modes. If the IFF_PROMISC flag is set, promiscuous
1323 * mode is acitviated. Otherwise, promiscuous mode is
1324 * turned off. If the IFF_ALLMULTI flag is set, then
1325 * the hash table is set to receive all group addresses.
1326 * Otherwise, the first three multicast addresses are
1327 * stored in AREG_1-3, and the rest are selected via the
1328 * hash table, as necessary.
1329 *
1330 **************************************************************/
Linus Torvalds1da177e2005-04-16 15:20:36 -07001331
Sakari Ailusc659c382011-01-21 10:59:30 +00001332static void tlan_set_multicast_list(struct net_device *dev)
Jeff Garzik6aa20a22006-09-13 13:24:59 -04001333{
Jiri Pirko22bedad32010-04-01 21:22:57 +00001334 struct netdev_hw_addr *ha;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001335 u32 hash1 = 0;
1336 u32 hash2 = 0;
1337 int i;
1338 u32 offset;
1339 u8 tmp;
1340
Sakari Ailusc659c382011-01-21 10:59:30 +00001341 if (dev->flags & IFF_PROMISC) {
1342 tmp = tlan_dio_read8(dev->base_addr, TLAN_NET_CMD);
1343 tlan_dio_write8(dev->base_addr,
1344 TLAN_NET_CMD, tmp | TLAN_NET_CMD_CAF);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001345 } else {
Sakari Ailusc659c382011-01-21 10:59:30 +00001346 tmp = tlan_dio_read8(dev->base_addr, TLAN_NET_CMD);
1347 tlan_dio_write8(dev->base_addr,
1348 TLAN_NET_CMD, tmp & ~TLAN_NET_CMD_CAF);
1349 if (dev->flags & IFF_ALLMULTI) {
1350 for (i = 0; i < 3; i++)
1351 tlan_set_mac(dev, i + 1, NULL);
1352 tlan_dio_write32(dev->base_addr, TLAN_HASH_1,
1353 0xffffffff);
1354 tlan_dio_write32(dev->base_addr, TLAN_HASH_2,
1355 0xffffffff);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001356 } else {
Jiri Pirko567ec872010-02-23 23:17:07 +00001357 i = 0;
Jiri Pirko22bedad32010-04-01 21:22:57 +00001358 netdev_for_each_mc_addr(ha, dev) {
Sakari Ailusc659c382011-01-21 10:59:30 +00001359 if (i < 3) {
1360 tlan_set_mac(dev, i + 1,
Jiri Pirko22bedad32010-04-01 21:22:57 +00001361 (char *) &ha->addr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001362 } else {
Sakari Ailusc659c382011-01-21 10:59:30 +00001363 offset =
1364 tlan_hash_func((u8 *)&ha->addr);
1365 if (offset < 32)
1366 hash1 |= (1 << offset);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001367 else
Sakari Ailusc659c382011-01-21 10:59:30 +00001368 hash2 |= (1 << (offset - 32));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001369 }
Jiri Pirko567ec872010-02-23 23:17:07 +00001370 i++;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001371 }
Sakari Ailusc659c382011-01-21 10:59:30 +00001372 for ( ; i < 3; i++)
1373 tlan_set_mac(dev, i + 1, NULL);
1374 tlan_dio_write32(dev->base_addr, TLAN_HASH_1, hash1);
1375 tlan_dio_write32(dev->base_addr, TLAN_HASH_2, hash2);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001376 }
1377 }
1378
Sakari Ailusc659c382011-01-21 10:59:30 +00001379}
Linus Torvalds1da177e2005-04-16 15:20:36 -07001380
1381
1382
1383/*****************************************************************************
1384******************************************************************************
1385
Sakari Ailusc659c382011-01-21 10:59:30 +00001386ThunderLAN driver interrupt vectors and table
Linus Torvalds1da177e2005-04-16 15:20:36 -07001387
Sakari Ailusc659c382011-01-21 10:59:30 +00001388please see chap. 4, "Interrupt Handling" of the "ThunderLAN
1389Programmer's Guide" for more informations on handling interrupts
1390generated by TLAN based adapters.
Linus Torvalds1da177e2005-04-16 15:20:36 -07001391
1392******************************************************************************
1393*****************************************************************************/
1394
1395
Linus Torvalds1da177e2005-04-16 15:20:36 -07001396
1397
Sakari Ailusc659c382011-01-21 10:59:30 +00001398/***************************************************************
1399 * tlan_handle_tx_eof
1400 *
1401 * Returns:
1402 * 1
1403 * Parms:
1404 * dev Device assigned the IRQ that was
1405 * raised.
1406 * host_int The contents of the HOST_INT
1407 * port.
1408 *
1409 * This function handles Tx EOF interrupts which are raised
1410 * by the adapter when it has completed sending the
1411 * contents of a buffer. If detemines which list/buffer
1412 * was completed and resets it. If the buffer was the last
1413 * in the channel (EOC), then the function checks to see if
1414 * another buffer is ready to send, and if so, sends a Tx
1415 * Go command. Finally, the driver activates/continues the
1416 * activity LED.
1417 *
1418 **************************************************************/
Linus Torvalds1da177e2005-04-16 15:20:36 -07001419
Sakari Ailusc659c382011-01-21 10:59:30 +00001420static u32 tlan_handle_tx_eof(struct net_device *dev, u16 host_int)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001421{
Sakari Ailusc659c382011-01-21 10:59:30 +00001422 struct tlan_priv *priv = netdev_priv(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001423 int eoc = 0;
Sakari Ailusc659c382011-01-21 10:59:30 +00001424 struct tlan_list *head_list;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001425 dma_addr_t head_list_phys;
1426 u32 ack = 0;
Sakari Ailusc659c382011-01-21 10:59:30 +00001427 u16 tmp_c_stat;
Jeff Garzik6aa20a22006-09-13 13:24:59 -04001428
Sakari Ailusc659c382011-01-21 10:59:30 +00001429 TLAN_DBG(TLAN_DEBUG_TX,
1430 "TRANSMIT: Handling TX EOF (Head=%d Tail=%d)\n",
1431 priv->tx_head, priv->tx_tail);
1432 head_list = priv->tx_list + priv->tx_head;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001433
Sakari Ailusc659c382011-01-21 10:59:30 +00001434 while (((tmp_c_stat = head_list->c_stat) & TLAN_CSTAT_FRM_CMP)
1435 && (ack < 255)) {
1436 struct sk_buff *skb = tlan_get_skb(head_list);
Sakari Ailus5eeabf52008-12-16 15:24:05 -08001437
Linus Torvalds1da177e2005-04-16 15:20:36 -07001438 ack++;
Sakari Ailusc659c382011-01-21 10:59:30 +00001439 pci_unmap_single(priv->pci_dev, head_list->buffer[0].address,
Sakari Ailus5eeabf52008-12-16 15:24:05 -08001440 max(skb->len,
1441 (unsigned int)TLAN_MIN_FRAME_SIZE),
1442 PCI_DMA_TODEVICE);
1443 dev_kfree_skb_any(skb);
1444 head_list->buffer[8].address = 0;
1445 head_list->buffer[9].address = 0;
Jeff Garzik6aa20a22006-09-13 13:24:59 -04001446
Sakari Ailusc659c382011-01-21 10:59:30 +00001447 if (tmp_c_stat & TLAN_CSTAT_EOC)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001448 eoc = 1;
Jeff Garzik6aa20a22006-09-13 13:24:59 -04001449
Sakari Ailusc659c382011-01-21 10:59:30 +00001450 dev->stats.tx_bytes += head_list->frame_size;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001451
Sakari Ailusc659c382011-01-21 10:59:30 +00001452 head_list->c_stat = TLAN_CSTAT_UNUSED;
Jeff Garzik6aa20a22006-09-13 13:24:59 -04001453 netif_start_queue(dev);
Sakari Ailusc659c382011-01-21 10:59:30 +00001454 CIRC_INC(priv->tx_head, TLAN_NUM_TX_LISTS);
1455 head_list = priv->tx_list + priv->tx_head;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001456 }
1457
1458 if (!ack)
Sakari Ailusc659c382011-01-21 10:59:30 +00001459 printk(KERN_INFO
1460 "TLAN: Received interrupt for uncompleted TX frame.\n");
Jeff Garzik6aa20a22006-09-13 13:24:59 -04001461
Sakari Ailusc659c382011-01-21 10:59:30 +00001462 if (eoc) {
1463 TLAN_DBG(TLAN_DEBUG_TX,
1464 "TRANSMIT: handling TX EOC (Head=%d Tail=%d)\n",
1465 priv->tx_head, priv->tx_tail);
1466 head_list = priv->tx_list + priv->tx_head;
1467 head_list_phys = priv->tx_list_dma
1468 + sizeof(struct tlan_list)*priv->tx_head;
1469 if (head_list->c_stat & TLAN_CSTAT_READY) {
1470 outl(head_list_phys, dev->base_addr + TLAN_CH_PARM);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001471 ack |= TLAN_HC_GO;
1472 } else {
Sakari Ailusc659c382011-01-21 10:59:30 +00001473 priv->tx_in_progress = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001474 }
1475 }
Jeff Garzik6aa20a22006-09-13 13:24:59 -04001476
Sakari Ailusc659c382011-01-21 10:59:30 +00001477 if (priv->adapter->flags & TLAN_ADAPTER_ACTIVITY_LED) {
1478 tlan_dio_write8(dev->base_addr,
1479 TLAN_LED_REG, TLAN_LED_LINK | TLAN_LED_ACT);
1480 if (priv->timer.function == NULL) {
1481 priv->timer.function = tlan_timer;
1482 priv->timer.data = (unsigned long) dev;
1483 priv->timer.expires = jiffies + TLAN_TIMER_ACT_DELAY;
1484 priv->timer_set_at = jiffies;
1485 priv->timer_type = TLAN_TIMER_ACTIVITY;
1486 add_timer(&priv->timer);
1487 } else if (priv->timer_type == TLAN_TIMER_ACTIVITY) {
1488 priv->timer_set_at = jiffies;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001489 }
1490 }
1491
1492 return ack;
1493
Sakari Ailusc659c382011-01-21 10:59:30 +00001494}
Linus Torvalds1da177e2005-04-16 15:20:36 -07001495
1496
1497
1498
Sakari Ailusc659c382011-01-21 10:59:30 +00001499/***************************************************************
1500 * TLan_HandleStatOverflow
1501 *
1502 * Returns:
1503 * 1
1504 * Parms:
1505 * dev Device assigned the IRQ that was
1506 * raised.
1507 * host_int The contents of the HOST_INT
1508 * port.
1509 *
1510 * This function handles the Statistics Overflow interrupt
1511 * which means that one or more of the TLAN statistics
1512 * registers has reached 1/2 capacity and needs to be read.
1513 *
1514 **************************************************************/
Linus Torvalds1da177e2005-04-16 15:20:36 -07001515
Sakari Ailusc659c382011-01-21 10:59:30 +00001516static u32 tlan_handle_stat_overflow(struct net_device *dev, u16 host_int)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001517{
Sakari Ailusc659c382011-01-21 10:59:30 +00001518 tlan_read_and_clear_stats(dev, TLAN_RECORD);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001519
1520 return 1;
1521
Sakari Ailusc659c382011-01-21 10:59:30 +00001522}
Linus Torvalds1da177e2005-04-16 15:20:36 -07001523
1524
1525
1526
Sakari Ailusc659c382011-01-21 10:59:30 +00001527/***************************************************************
1528 * TLan_HandleRxEOF
1529 *
1530 * Returns:
1531 * 1
1532 * Parms:
1533 * dev Device assigned the IRQ that was
1534 * raised.
1535 * host_int The contents of the HOST_INT
1536 * port.
1537 *
1538 * This function handles the Rx EOF interrupt which
1539 * indicates a frame has been received by the adapter from
1540 * the net and the frame has been transferred to memory.
1541 * The function determines the bounce buffer the frame has
1542 * been loaded into, creates a new sk_buff big enough to
1543 * hold the frame, and sends it to protocol stack. It
1544 * then resets the used buffer and appends it to the end
1545 * of the list. If the frame was the last in the Rx
1546 * channel (EOC), the function restarts the receive channel
1547 * by sending an Rx Go command to the adapter. Then it
1548 * activates/continues the activity LED.
1549 *
1550 **************************************************************/
Linus Torvalds1da177e2005-04-16 15:20:36 -07001551
Sakari Ailusc659c382011-01-21 10:59:30 +00001552static u32 tlan_handle_rx_eof(struct net_device *dev, u16 host_int)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001553{
Sakari Ailusc659c382011-01-21 10:59:30 +00001554 struct tlan_priv *priv = netdev_priv(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001555 u32 ack = 0;
1556 int eoc = 0;
Sakari Ailusc659c382011-01-21 10:59:30 +00001557 struct tlan_list *head_list;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001558 struct sk_buff *skb;
Sakari Ailusc659c382011-01-21 10:59:30 +00001559 struct tlan_list *tail_list;
1560 u16 tmp_c_stat;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001561 dma_addr_t head_list_phys;
1562
Sakari Ailusc659c382011-01-21 10:59:30 +00001563 TLAN_DBG(TLAN_DEBUG_RX, "RECEIVE: handling RX EOF (Head=%d Tail=%d)\n",
1564 priv->rx_head, priv->rx_tail);
1565 head_list = priv->rx_list + priv->rx_head;
1566 head_list_phys =
1567 priv->rx_list_dma + sizeof(struct tlan_list)*priv->rx_head;
Jeff Garzik6aa20a22006-09-13 13:24:59 -04001568
Sakari Ailusc659c382011-01-21 10:59:30 +00001569 while (((tmp_c_stat = head_list->c_stat) & TLAN_CSTAT_FRM_CMP)
1570 && (ack < 255)) {
1571 dma_addr_t frame_dma = head_list->buffer[0].address;
1572 u32 frame_size = head_list->frame_size;
Sakari Ailus5eeabf52008-12-16 15:24:05 -08001573 struct sk_buff *new_skb;
1574
Linus Torvalds1da177e2005-04-16 15:20:36 -07001575 ack++;
Sakari Ailusc659c382011-01-21 10:59:30 +00001576 if (tmp_c_stat & TLAN_CSTAT_EOC)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001577 eoc = 1;
Jeff Garzik6aa20a22006-09-13 13:24:59 -04001578
Eric Dumazet89d71a62009-10-13 05:34:20 +00001579 new_skb = netdev_alloc_skb_ip_align(dev,
1580 TLAN_MAX_FRAME_SIZE + 5);
Sakari Ailusc659c382011-01-21 10:59:30 +00001581 if (!new_skb)
Sakari Ailus5eeabf52008-12-16 15:24:05 -08001582 goto drop_and_reuse;
Jeff Garzik6aa20a22006-09-13 13:24:59 -04001583
Sakari Ailusc659c382011-01-21 10:59:30 +00001584 skb = tlan_get_skb(head_list);
1585 pci_unmap_single(priv->pci_dev, frame_dma,
Sakari Ailus5eeabf52008-12-16 15:24:05 -08001586 TLAN_MAX_FRAME_SIZE, PCI_DMA_FROMDEVICE);
Sakari Ailusc659c382011-01-21 10:59:30 +00001587 skb_put(skb, frame_size);
Stephen Hemmingerdfc2c0a2008-05-30 09:49:58 -07001588
Sakari Ailusc659c382011-01-21 10:59:30 +00001589 dev->stats.rx_bytes += frame_size;
Jeff Garzik6aa20a22006-09-13 13:24:59 -04001590
Sakari Ailusc659c382011-01-21 10:59:30 +00001591 skb->protocol = eth_type_trans(skb, dev);
1592 netif_rx(skb);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001593
Sakari Ailusc659c382011-01-21 10:59:30 +00001594 head_list->buffer[0].address =
1595 pci_map_single(priv->pci_dev, new_skb->data,
1596 TLAN_MAX_FRAME_SIZE, PCI_DMA_FROMDEVICE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001597
Sakari Ailusc659c382011-01-21 10:59:30 +00001598 tlan_store_skb(head_list, new_skb);
Stephen Hemmingerdfc2c0a2008-05-30 09:49:58 -07001599drop_and_reuse:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001600 head_list->forward = 0;
Sakari Ailusc659c382011-01-21 10:59:30 +00001601 head_list->c_stat = 0;
1602 tail_list = priv->rx_list + priv->rx_tail;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001603 tail_list->forward = head_list_phys;
1604
Sakari Ailusc659c382011-01-21 10:59:30 +00001605 CIRC_INC(priv->rx_head, TLAN_NUM_RX_LISTS);
1606 CIRC_INC(priv->rx_tail, TLAN_NUM_RX_LISTS);
1607 head_list = priv->rx_list + priv->rx_head;
1608 head_list_phys = priv->rx_list_dma
1609 + sizeof(struct tlan_list)*priv->rx_head;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001610 }
1611
1612 if (!ack)
Sakari Ailusc659c382011-01-21 10:59:30 +00001613 printk(KERN_INFO
1614 "TLAN: Received interrupt for uncompleted RX frame.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001615
1616
Sakari Ailusc659c382011-01-21 10:59:30 +00001617 if (eoc) {
1618 TLAN_DBG(TLAN_DEBUG_RX,
1619 "RECEIVE: handling RX EOC (Head=%d Tail=%d)\n",
1620 priv->rx_head, priv->rx_tail);
1621 head_list = priv->rx_list + priv->rx_head;
1622 head_list_phys = priv->rx_list_dma
1623 + sizeof(struct tlan_list)*priv->rx_head;
1624 outl(head_list_phys, dev->base_addr + TLAN_CH_PARM);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001625 ack |= TLAN_HC_GO | TLAN_HC_RT;
Sakari Ailusc659c382011-01-21 10:59:30 +00001626 priv->rx_eoc_count++;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001627 }
1628
Sakari Ailusc659c382011-01-21 10:59:30 +00001629 if (priv->adapter->flags & TLAN_ADAPTER_ACTIVITY_LED) {
1630 tlan_dio_write8(dev->base_addr,
1631 TLAN_LED_REG, TLAN_LED_LINK | TLAN_LED_ACT);
1632 if (priv->timer.function == NULL) {
1633 priv->timer.function = tlan_timer;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001634 priv->timer.data = (unsigned long) dev;
1635 priv->timer.expires = jiffies + TLAN_TIMER_ACT_DELAY;
Sakari Ailusc659c382011-01-21 10:59:30 +00001636 priv->timer_set_at = jiffies;
1637 priv->timer_type = TLAN_TIMER_ACTIVITY;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001638 add_timer(&priv->timer);
Sakari Ailusc659c382011-01-21 10:59:30 +00001639 } else if (priv->timer_type == TLAN_TIMER_ACTIVITY) {
1640 priv->timer_set_at = jiffies;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001641 }
1642 }
1643
Linus Torvalds1da177e2005-04-16 15:20:36 -07001644 return ack;
1645
Sakari Ailusc659c382011-01-21 10:59:30 +00001646}
Linus Torvalds1da177e2005-04-16 15:20:36 -07001647
1648
1649
1650
Sakari Ailusc659c382011-01-21 10:59:30 +00001651/***************************************************************
1652 * tlan_handle_dummy
1653 *
1654 * Returns:
1655 * 1
1656 * Parms:
1657 * dev Device assigned the IRQ that was
1658 * raised.
1659 * host_int The contents of the HOST_INT
1660 * port.
1661 *
1662 * This function handles the Dummy interrupt, which is
1663 * raised whenever a test interrupt is generated by setting
1664 * the Req_Int bit of HOST_CMD to 1.
1665 *
1666 **************************************************************/
Linus Torvalds1da177e2005-04-16 15:20:36 -07001667
Sakari Ailusc659c382011-01-21 10:59:30 +00001668static u32 tlan_handle_dummy(struct net_device *dev, u16 host_int)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001669{
Sakari Ailusc659c382011-01-21 10:59:30 +00001670 pr_info("TLAN: Test interrupt on %s.\n", dev->name);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001671 return 1;
1672
Sakari Ailusc659c382011-01-21 10:59:30 +00001673}
Linus Torvalds1da177e2005-04-16 15:20:36 -07001674
1675
1676
1677
Sakari Ailusc659c382011-01-21 10:59:30 +00001678/***************************************************************
1679 * tlan_handle_tx_eoc
1680 *
1681 * Returns:
1682 * 1
1683 * Parms:
1684 * dev Device assigned the IRQ that was
1685 * raised.
1686 * host_int The contents of the HOST_INT
1687 * port.
1688 *
1689 * This driver is structured to determine EOC occurrences by
1690 * reading the CSTAT member of the list structure. Tx EOC
1691 * interrupts are disabled via the DIO INTDIS register.
1692 * However, TLAN chips before revision 3.0 didn't have this
1693 * functionality, so process EOC events if this is the
1694 * case.
1695 *
1696 **************************************************************/
Linus Torvalds1da177e2005-04-16 15:20:36 -07001697
Sakari Ailusc659c382011-01-21 10:59:30 +00001698static u32 tlan_handle_tx_eoc(struct net_device *dev, u16 host_int)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001699{
Sakari Ailusc659c382011-01-21 10:59:30 +00001700 struct tlan_priv *priv = netdev_priv(dev);
1701 struct tlan_list *head_list;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001702 dma_addr_t head_list_phys;
1703 u32 ack = 1;
Jeff Garzik6aa20a22006-09-13 13:24:59 -04001704
Linus Torvalds1da177e2005-04-16 15:20:36 -07001705 host_int = 0;
Sakari Ailusc659c382011-01-21 10:59:30 +00001706 if (priv->tlan_rev < 0x30) {
1707 TLAN_DBG(TLAN_DEBUG_TX,
1708 "TRANSMIT: handling TX EOC (Head=%d Tail=%d) -- IRQ\n",
1709 priv->tx_head, priv->tx_tail);
1710 head_list = priv->tx_list + priv->tx_head;
1711 head_list_phys = priv->tx_list_dma
1712 + sizeof(struct tlan_list)*priv->tx_head;
1713 if (head_list->c_stat & TLAN_CSTAT_READY) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001714 netif_stop_queue(dev);
Sakari Ailusc659c382011-01-21 10:59:30 +00001715 outl(head_list_phys, dev->base_addr + TLAN_CH_PARM);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001716 ack |= TLAN_HC_GO;
1717 } else {
Sakari Ailusc659c382011-01-21 10:59:30 +00001718 priv->tx_in_progress = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001719 }
1720 }
1721
1722 return ack;
1723
Sakari Ailusc659c382011-01-21 10:59:30 +00001724}
Linus Torvalds1da177e2005-04-16 15:20:36 -07001725
1726
1727
1728
Sakari Ailusc659c382011-01-21 10:59:30 +00001729/***************************************************************
1730 * tlan_handle_status_check
1731 *
1732 * Returns:
1733 * 0 if Adapter check, 1 if Network Status check.
1734 * Parms:
1735 * dev Device assigned the IRQ that was
1736 * raised.
1737 * host_int The contents of the HOST_INT
1738 * port.
1739 *
1740 * This function handles Adapter Check/Network Status
1741 * interrupts generated by the adapter. It checks the
1742 * vector in the HOST_INT register to determine if it is
1743 * an Adapter Check interrupt. If so, it resets the
1744 * adapter. Otherwise it clears the status registers
1745 * and services the PHY.
1746 *
1747 **************************************************************/
Linus Torvalds1da177e2005-04-16 15:20:36 -07001748
Sakari Ailusc659c382011-01-21 10:59:30 +00001749static u32 tlan_handle_status_check(struct net_device *dev, u16 host_int)
Jeff Garzik6aa20a22006-09-13 13:24:59 -04001750{
Sakari Ailusc659c382011-01-21 10:59:30 +00001751 struct tlan_priv *priv = netdev_priv(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001752 u32 ack;
1753 u32 error;
1754 u8 net_sts;
1755 u32 phy;
1756 u16 tlphy_ctl;
1757 u16 tlphy_sts;
Jeff Garzik6aa20a22006-09-13 13:24:59 -04001758
Linus Torvalds1da177e2005-04-16 15:20:36 -07001759 ack = 1;
Sakari Ailusc659c382011-01-21 10:59:30 +00001760 if (host_int & TLAN_HI_IV_MASK) {
1761 netif_stop_queue(dev);
1762 error = inl(dev->base_addr + TLAN_CH_PARM);
1763 pr_info("TLAN: %s: Adaptor Error = 0x%x\n", dev->name, error);
1764 tlan_read_and_clear_stats(dev, TLAN_RECORD);
1765 outl(TLAN_HC_AD_RST, dev->base_addr + TLAN_HOST_CMD);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001766
1767 schedule_work(&priv->tlan_tqueue);
1768
1769 netif_wake_queue(dev);
1770 ack = 0;
1771 } else {
Sakari Ailusc659c382011-01-21 10:59:30 +00001772 TLAN_DBG(TLAN_DEBUG_GNRL, "%s: Status Check\n", dev->name);
1773 phy = priv->phy[priv->phy_num];
Linus Torvalds1da177e2005-04-16 15:20:36 -07001774
Sakari Ailusc659c382011-01-21 10:59:30 +00001775 net_sts = tlan_dio_read8(dev->base_addr, TLAN_NET_STS);
1776 if (net_sts) {
1777 tlan_dio_write8(dev->base_addr, TLAN_NET_STS, net_sts);
1778 TLAN_DBG(TLAN_DEBUG_GNRL, "%s: Net_Sts = %x\n",
1779 dev->name, (unsigned) net_sts);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001780 }
Sakari Ailusc659c382011-01-21 10:59:30 +00001781 if ((net_sts & TLAN_NET_STS_MIRQ) && (priv->phy_num == 0)) {
1782 tlan_mii_read_reg(dev, phy, TLAN_TLPHY_STS, &tlphy_sts);
1783 tlan_mii_read_reg(dev, phy, TLAN_TLPHY_CTL, &tlphy_ctl);
1784 if (!(tlphy_sts & TLAN_TS_POLOK) &&
1785 !(tlphy_ctl & TLAN_TC_SWAPOL)) {
1786 tlphy_ctl |= TLAN_TC_SWAPOL;
1787 tlan_mii_write_reg(dev, phy, TLAN_TLPHY_CTL,
1788 tlphy_ctl);
1789 } else if ((tlphy_sts & TLAN_TS_POLOK) &&
1790 (tlphy_ctl & TLAN_TC_SWAPOL)) {
1791 tlphy_ctl &= ~TLAN_TC_SWAPOL;
1792 tlan_mii_write_reg(dev, phy, TLAN_TLPHY_CTL,
1793 tlphy_ctl);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001794 }
Sakari Ailusc659c382011-01-21 10:59:30 +00001795
1796 if (debug)
1797 tlan_phy_print(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001798 }
1799 }
1800
1801 return ack;
1802
Sakari Ailusc659c382011-01-21 10:59:30 +00001803}
Linus Torvalds1da177e2005-04-16 15:20:36 -07001804
1805
1806
1807
Sakari Ailusc659c382011-01-21 10:59:30 +00001808/***************************************************************
1809 * tlan_handle_rx_eoc
1810 *
1811 * Returns:
1812 * 1
1813 * Parms:
1814 * dev Device assigned the IRQ that was
1815 * raised.
1816 * host_int The contents of the HOST_INT
1817 * port.
1818 *
1819 * This driver is structured to determine EOC occurrences by
1820 * reading the CSTAT member of the list structure. Rx EOC
1821 * interrupts are disabled via the DIO INTDIS register.
1822 * However, TLAN chips before revision 3.0 didn't have this
1823 * CSTAT member or a INTDIS register, so if this chip is
1824 * pre-3.0, process EOC interrupts normally.
1825 *
1826 **************************************************************/
Linus Torvalds1da177e2005-04-16 15:20:36 -07001827
Sakari Ailusc659c382011-01-21 10:59:30 +00001828static u32 tlan_handle_rx_eoc(struct net_device *dev, u16 host_int)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001829{
Sakari Ailusc659c382011-01-21 10:59:30 +00001830 struct tlan_priv *priv = netdev_priv(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001831 dma_addr_t head_list_phys;
1832 u32 ack = 1;
1833
Sakari Ailusc659c382011-01-21 10:59:30 +00001834 if (priv->tlan_rev < 0x30) {
1835 TLAN_DBG(TLAN_DEBUG_RX,
1836 "RECEIVE: Handling RX EOC (head=%d tail=%d) -- IRQ\n",
1837 priv->rx_head, priv->rx_tail);
1838 head_list_phys = priv->rx_list_dma
1839 + sizeof(struct tlan_list)*priv->rx_head;
1840 outl(head_list_phys, dev->base_addr + TLAN_CH_PARM);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001841 ack |= TLAN_HC_GO | TLAN_HC_RT;
Sakari Ailusc659c382011-01-21 10:59:30 +00001842 priv->rx_eoc_count++;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001843 }
1844
1845 return ack;
1846
Sakari Ailusc659c382011-01-21 10:59:30 +00001847}
Linus Torvalds1da177e2005-04-16 15:20:36 -07001848
1849
1850
1851
1852/*****************************************************************************
1853******************************************************************************
1854
Sakari Ailusc659c382011-01-21 10:59:30 +00001855ThunderLAN driver timer function
Linus Torvalds1da177e2005-04-16 15:20:36 -07001856
1857******************************************************************************
1858*****************************************************************************/
1859
1860
Sakari Ailusc659c382011-01-21 10:59:30 +00001861/***************************************************************
1862 * tlan_timer
1863 *
1864 * Returns:
1865 * Nothing
1866 * Parms:
1867 * data A value given to add timer when
1868 * add_timer was called.
1869 *
1870 * This function handles timed functionality for the
1871 * TLAN driver. The two current timer uses are for
1872 * delaying for autonegotionation and driving the ACT LED.
1873 * - Autonegotiation requires being allowed about
1874 * 2 1/2 seconds before attempting to transmit a
1875 * packet. It would be a very bad thing to hang
1876 * the kernel this long, so the driver doesn't
1877 * allow transmission 'til after this time, for
1878 * certain PHYs. It would be much nicer if all
1879 * PHYs were interrupt-capable like the internal
1880 * PHY.
1881 * - The ACT LED, which shows adapter activity, is
1882 * driven by the driver, and so must be left on
1883 * for a short period to power up the LED so it
1884 * can be seen. This delay can be changed by
1885 * changing the TLAN_TIMER_ACT_DELAY in tlan.h,
1886 * if desired. 100 ms produces a slightly
1887 * sluggish response.
1888 *
1889 **************************************************************/
Linus Torvalds1da177e2005-04-16 15:20:36 -07001890
Sakari Ailusc659c382011-01-21 10:59:30 +00001891static void tlan_timer(unsigned long data)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001892{
1893 struct net_device *dev = (struct net_device *) data;
Sakari Ailusc659c382011-01-21 10:59:30 +00001894 struct tlan_priv *priv = netdev_priv(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001895 u32 elapsed;
1896 unsigned long flags = 0;
1897
1898 priv->timer.function = NULL;
1899
Sakari Ailusc659c382011-01-21 10:59:30 +00001900 switch (priv->timer_type) {
Jeff Garzik6aa20a22006-09-13 13:24:59 -04001901#ifdef MONITOR
Sakari Ailusc659c382011-01-21 10:59:30 +00001902 case TLAN_TIMER_LINK_BEAT:
1903 tlan_phy_monitor(dev);
1904 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001905#endif
Sakari Ailusc659c382011-01-21 10:59:30 +00001906 case TLAN_TIMER_PHY_PDOWN:
1907 tlan_phy_power_down(dev);
1908 break;
1909 case TLAN_TIMER_PHY_PUP:
1910 tlan_phy_power_up(dev);
1911 break;
1912 case TLAN_TIMER_PHY_RESET:
1913 tlan_phy_reset(dev);
1914 break;
1915 case TLAN_TIMER_PHY_START_LINK:
1916 tlan_phy_start_link(dev);
1917 break;
1918 case TLAN_TIMER_PHY_FINISH_AN:
1919 tlan_phy_finish_auto_neg(dev);
1920 break;
1921 case TLAN_TIMER_FINISH_RESET:
1922 tlan_finish_reset(dev);
1923 break;
1924 case TLAN_TIMER_ACTIVITY:
1925 spin_lock_irqsave(&priv->lock, flags);
1926 if (priv->timer.function == NULL) {
1927 elapsed = jiffies - priv->timer_set_at;
1928 if (elapsed >= TLAN_TIMER_ACT_DELAY) {
1929 tlan_dio_write8(dev->base_addr,
1930 TLAN_LED_REG, TLAN_LED_LINK);
1931 } else {
1932 priv->timer.function = tlan_timer;
1933 priv->timer.expires = priv->timer_set_at
1934 + TLAN_TIMER_ACT_DELAY;
1935 spin_unlock_irqrestore(&priv->lock, flags);
1936 add_timer(&priv->timer);
1937 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001938 }
Sakari Ailusc659c382011-01-21 10:59:30 +00001939 }
1940 spin_unlock_irqrestore(&priv->lock, flags);
1941 break;
1942 default:
1943 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001944 }
1945
Sakari Ailusc659c382011-01-21 10:59:30 +00001946}
Linus Torvalds1da177e2005-04-16 15:20:36 -07001947
1948
1949
1950
1951/*****************************************************************************
1952******************************************************************************
1953
Sakari Ailusc659c382011-01-21 10:59:30 +00001954ThunderLAN driver adapter related routines
Linus Torvalds1da177e2005-04-16 15:20:36 -07001955
1956******************************************************************************
1957*****************************************************************************/
1958
1959
Sakari Ailusc659c382011-01-21 10:59:30 +00001960/***************************************************************
1961 * tlan_reset_lists
1962 *
1963 * Returns:
1964 * Nothing
1965 * Parms:
1966 * dev The device structure with the list
1967 * stuctures to be reset.
1968 *
1969 * This routine sets the variables associated with managing
1970 * the TLAN lists to their initial values.
1971 *
1972 **************************************************************/
Linus Torvalds1da177e2005-04-16 15:20:36 -07001973
Sakari Ailusc659c382011-01-21 10:59:30 +00001974static void tlan_reset_lists(struct net_device *dev)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001975{
Sakari Ailusc659c382011-01-21 10:59:30 +00001976 struct tlan_priv *priv = netdev_priv(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001977 int i;
Sakari Ailusc659c382011-01-21 10:59:30 +00001978 struct tlan_list *list;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001979 dma_addr_t list_phys;
1980 struct sk_buff *skb;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001981
Sakari Ailusc659c382011-01-21 10:59:30 +00001982 priv->tx_head = 0;
1983 priv->tx_tail = 0;
1984 for (i = 0; i < TLAN_NUM_TX_LISTS; i++) {
1985 list = priv->tx_list + i;
1986 list->c_stat = TLAN_CSTAT_UNUSED;
Sakari Ailus5eeabf52008-12-16 15:24:05 -08001987 list->buffer[0].address = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001988 list->buffer[2].count = 0;
1989 list->buffer[2].address = 0;
1990 list->buffer[8].address = 0;
1991 list->buffer[9].address = 0;
1992 }
1993
Sakari Ailusc659c382011-01-21 10:59:30 +00001994 priv->rx_head = 0;
1995 priv->rx_tail = TLAN_NUM_RX_LISTS - 1;
1996 for (i = 0; i < TLAN_NUM_RX_LISTS; i++) {
1997 list = priv->rx_list + i;
1998 list_phys = priv->rx_list_dma + sizeof(struct tlan_list)*i;
1999 list->c_stat = TLAN_CSTAT_READY;
2000 list->frame_size = TLAN_MAX_FRAME_SIZE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002001 list->buffer[0].count = TLAN_MAX_FRAME_SIZE | TLAN_LAST_BUFFER;
Eric Dumazet89d71a62009-10-13 05:34:20 +00002002 skb = netdev_alloc_skb_ip_align(dev, TLAN_MAX_FRAME_SIZE + 5);
Sakari Ailusc659c382011-01-21 10:59:30 +00002003 if (!skb) {
2004 pr_err("TLAN: out of memory for received data.\n");
Sakari Ailus5eeabf52008-12-16 15:24:05 -08002005 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002006 }
Sakari Ailus5eeabf52008-12-16 15:24:05 -08002007
Sakari Ailusc659c382011-01-21 10:59:30 +00002008 list->buffer[0].address = pci_map_single(priv->pci_dev,
Sakari Ailus5eeabf52008-12-16 15:24:05 -08002009 skb->data,
2010 TLAN_MAX_FRAME_SIZE,
2011 PCI_DMA_FROMDEVICE);
Sakari Ailusc659c382011-01-21 10:59:30 +00002012 tlan_store_skb(list, skb);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002013 list->buffer[1].count = 0;
2014 list->buffer[1].address = 0;
Sakari Ailusc659c382011-01-21 10:59:30 +00002015 list->forward = list_phys + sizeof(struct tlan_list);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002016 }
2017
Stephen Hemminger9ded65a2008-05-30 09:49:56 -07002018 /* in case ran out of memory early, clear bits */
2019 while (i < TLAN_NUM_RX_LISTS) {
Sakari Ailusc659c382011-01-21 10:59:30 +00002020 tlan_store_skb(priv->rx_list + i, NULL);
Stephen Hemminger9ded65a2008-05-30 09:49:56 -07002021 ++i;
2022 }
2023 list->forward = 0;
2024
Sakari Ailusc659c382011-01-21 10:59:30 +00002025}
Linus Torvalds1da177e2005-04-16 15:20:36 -07002026
2027
Sakari Ailusc659c382011-01-21 10:59:30 +00002028static void tlan_free_lists(struct net_device *dev)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002029{
Sakari Ailusc659c382011-01-21 10:59:30 +00002030 struct tlan_priv *priv = netdev_priv(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002031 int i;
Sakari Ailusc659c382011-01-21 10:59:30 +00002032 struct tlan_list *list;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002033 struct sk_buff *skb;
2034
Sakari Ailusc659c382011-01-21 10:59:30 +00002035 for (i = 0; i < TLAN_NUM_TX_LISTS; i++) {
2036 list = priv->tx_list + i;
2037 skb = tlan_get_skb(list);
2038 if (skb) {
Sakari Ailus5eeabf52008-12-16 15:24:05 -08002039 pci_unmap_single(
Sakari Ailusc659c382011-01-21 10:59:30 +00002040 priv->pci_dev,
Sakari Ailus5eeabf52008-12-16 15:24:05 -08002041 list->buffer[0].address,
2042 max(skb->len,
2043 (unsigned int)TLAN_MIN_FRAME_SIZE),
2044 PCI_DMA_TODEVICE);
Sakari Ailusc659c382011-01-21 10:59:30 +00002045 dev_kfree_skb_any(skb);
Sakari Ailus5eeabf52008-12-16 15:24:05 -08002046 list->buffer[8].address = 0;
2047 list->buffer[9].address = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002048 }
Sakari Ailus5eeabf52008-12-16 15:24:05 -08002049 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002050
Sakari Ailusc659c382011-01-21 10:59:30 +00002051 for (i = 0; i < TLAN_NUM_RX_LISTS; i++) {
2052 list = priv->rx_list + i;
2053 skb = tlan_get_skb(list);
2054 if (skb) {
2055 pci_unmap_single(priv->pci_dev,
Sakari Ailus5eeabf52008-12-16 15:24:05 -08002056 list->buffer[0].address,
2057 TLAN_MAX_FRAME_SIZE,
2058 PCI_DMA_FROMDEVICE);
Sakari Ailusc659c382011-01-21 10:59:30 +00002059 dev_kfree_skb_any(skb);
Sakari Ailus5eeabf52008-12-16 15:24:05 -08002060 list->buffer[8].address = 0;
2061 list->buffer[9].address = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002062 }
2063 }
Sakari Ailusc659c382011-01-21 10:59:30 +00002064}
Linus Torvalds1da177e2005-04-16 15:20:36 -07002065
2066
2067
2068
Sakari Ailusc659c382011-01-21 10:59:30 +00002069/***************************************************************
2070 * tlan_print_dio
2071 *
2072 * Returns:
2073 * Nothing
2074 * Parms:
2075 * io_base Base IO port of the device of
2076 * which to print DIO registers.
2077 *
2078 * This function prints out all the internal (DIO)
2079 * registers of a TLAN chip.
2080 *
2081 **************************************************************/
Linus Torvalds1da177e2005-04-16 15:20:36 -07002082
Sakari Ailusc659c382011-01-21 10:59:30 +00002083static void tlan_print_dio(u16 io_base)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002084{
2085 u32 data0, data1;
2086 int i;
2087
Sakari Ailusc659c382011-01-21 10:59:30 +00002088 pr_info("TLAN: Contents of internal registers for io base 0x%04hx.\n",
2089 io_base);
2090 pr_info("TLAN: Off. +0 +4\n");
2091 for (i = 0; i < 0x4C; i += 8) {
2092 data0 = tlan_dio_read32(io_base, i);
2093 data1 = tlan_dio_read32(io_base, i + 0x4);
2094 pr_info("TLAN: 0x%02x 0x%08x 0x%08x\n", i, data0, data1);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002095 }
2096
Sakari Ailusc659c382011-01-21 10:59:30 +00002097}
Linus Torvalds1da177e2005-04-16 15:20:36 -07002098
2099
2100
2101
Sakari Ailusc659c382011-01-21 10:59:30 +00002102/***************************************************************
2103 * TLan_PrintList
2104 *
2105 * Returns:
2106 * Nothing
2107 * Parms:
2108 * list A pointer to the struct tlan_list structure to
2109 * be printed.
2110 * type A string to designate type of list,
2111 * "Rx" or "Tx".
2112 * num The index of the list.
2113 *
2114 * This function prints out the contents of the list
2115 * pointed to by the list parameter.
2116 *
2117 **************************************************************/
Linus Torvalds1da177e2005-04-16 15:20:36 -07002118
Sakari Ailusc659c382011-01-21 10:59:30 +00002119static void tlan_print_list(struct tlan_list *list, char *type, int num)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002120{
2121 int i;
2122
Sakari Ailusc659c382011-01-21 10:59:30 +00002123 pr_info("TLAN: %s List %d at %p\n", type, num, list);
2124 pr_info("TLAN: Forward = 0x%08x\n", list->forward);
2125 pr_info("TLAN: CSTAT = 0x%04hx\n", list->c_stat);
2126 pr_info("TLAN: Frame Size = 0x%04hx\n", list->frame_size);
2127 /* for (i = 0; i < 10; i++) { */
2128 for (i = 0; i < 2; i++) {
2129 pr_info("TLAN: Buffer[%d].count, addr = 0x%08x, 0x%08x\n",
2130 i, list->buffer[i].count, list->buffer[i].address);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002131 }
2132
Sakari Ailusc659c382011-01-21 10:59:30 +00002133}
Linus Torvalds1da177e2005-04-16 15:20:36 -07002134
2135
2136
2137
Sakari Ailusc659c382011-01-21 10:59:30 +00002138/***************************************************************
2139 * tlan_read_and_clear_stats
2140 *
2141 * Returns:
2142 * Nothing
2143 * Parms:
2144 * dev Pointer to device structure of adapter
2145 * to which to read stats.
2146 * record Flag indicating whether to add
2147 *
2148 * This functions reads all the internal status registers
2149 * of the TLAN chip, which clears them as a side effect.
2150 * It then either adds the values to the device's status
2151 * struct, or discards them, depending on whether record
2152 * is TLAN_RECORD (!=0) or TLAN_IGNORE (==0).
2153 *
2154 **************************************************************/
Linus Torvalds1da177e2005-04-16 15:20:36 -07002155
Sakari Ailusc659c382011-01-21 10:59:30 +00002156static void tlan_read_and_clear_stats(struct net_device *dev, int record)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002157{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002158 u32 tx_good, tx_under;
2159 u32 rx_good, rx_over;
2160 u32 def_tx, crc, code;
2161 u32 multi_col, single_col;
2162 u32 excess_col, late_col, loss;
2163
Sakari Ailusc659c382011-01-21 10:59:30 +00002164 outw(TLAN_GOOD_TX_FRMS, dev->base_addr + TLAN_DIO_ADR);
2165 tx_good = inb(dev->base_addr + TLAN_DIO_DATA);
2166 tx_good += inb(dev->base_addr + TLAN_DIO_DATA + 1) << 8;
2167 tx_good += inb(dev->base_addr + TLAN_DIO_DATA + 2) << 16;
2168 tx_under = inb(dev->base_addr + TLAN_DIO_DATA + 3);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002169
Sakari Ailusc659c382011-01-21 10:59:30 +00002170 outw(TLAN_GOOD_RX_FRMS, dev->base_addr + TLAN_DIO_ADR);
2171 rx_good = inb(dev->base_addr + TLAN_DIO_DATA);
2172 rx_good += inb(dev->base_addr + TLAN_DIO_DATA + 1) << 8;
2173 rx_good += inb(dev->base_addr + TLAN_DIO_DATA + 2) << 16;
2174 rx_over = inb(dev->base_addr + TLAN_DIO_DATA + 3);
Jeff Garzik6aa20a22006-09-13 13:24:59 -04002175
Sakari Ailusc659c382011-01-21 10:59:30 +00002176 outw(TLAN_DEFERRED_TX, dev->base_addr + TLAN_DIO_ADR);
2177 def_tx = inb(dev->base_addr + TLAN_DIO_DATA);
2178 def_tx += inb(dev->base_addr + TLAN_DIO_DATA + 1) << 8;
2179 crc = inb(dev->base_addr + TLAN_DIO_DATA + 2);
2180 code = inb(dev->base_addr + TLAN_DIO_DATA + 3);
Jeff Garzik6aa20a22006-09-13 13:24:59 -04002181
Sakari Ailusc659c382011-01-21 10:59:30 +00002182 outw(TLAN_MULTICOL_FRMS, dev->base_addr + TLAN_DIO_ADR);
2183 multi_col = inb(dev->base_addr + TLAN_DIO_DATA);
2184 multi_col += inb(dev->base_addr + TLAN_DIO_DATA + 1) << 8;
2185 single_col = inb(dev->base_addr + TLAN_DIO_DATA + 2);
2186 single_col += inb(dev->base_addr + TLAN_DIO_DATA + 3) << 8;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002187
Sakari Ailusc659c382011-01-21 10:59:30 +00002188 outw(TLAN_EXCESSCOL_FRMS, dev->base_addr + TLAN_DIO_ADR);
2189 excess_col = inb(dev->base_addr + TLAN_DIO_DATA);
2190 late_col = inb(dev->base_addr + TLAN_DIO_DATA + 1);
2191 loss = inb(dev->base_addr + TLAN_DIO_DATA + 2);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002192
Sakari Ailusc659c382011-01-21 10:59:30 +00002193 if (record) {
Stephen Hemmingerf8f31542008-05-30 09:49:53 -07002194 dev->stats.rx_packets += rx_good;
2195 dev->stats.rx_errors += rx_over + crc + code;
2196 dev->stats.tx_packets += tx_good;
2197 dev->stats.tx_errors += tx_under + loss;
Sakari Ailusc659c382011-01-21 10:59:30 +00002198 dev->stats.collisions += multi_col
2199 + single_col + excess_col + late_col;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002200
Stephen Hemmingerf8f31542008-05-30 09:49:53 -07002201 dev->stats.rx_over_errors += rx_over;
2202 dev->stats.rx_crc_errors += crc;
2203 dev->stats.rx_frame_errors += code;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002204
Stephen Hemmingerf8f31542008-05-30 09:49:53 -07002205 dev->stats.tx_aborted_errors += tx_under;
2206 dev->stats.tx_carrier_errors += loss;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002207 }
Jeff Garzik6aa20a22006-09-13 13:24:59 -04002208
Sakari Ailusc659c382011-01-21 10:59:30 +00002209}
Linus Torvalds1da177e2005-04-16 15:20:36 -07002210
2211
2212
2213
Sakari Ailusc659c382011-01-21 10:59:30 +00002214/***************************************************************
2215 * TLan_Reset
2216 *
2217 * Returns:
2218 * 0
2219 * Parms:
2220 * dev Pointer to device structure of adapter
2221 * to be reset.
2222 *
2223 * This function resets the adapter and it's physical
2224 * device. See Chap. 3, pp. 9-10 of the "ThunderLAN
2225 * Programmer's Guide" for details. The routine tries to
2226 * implement what is detailed there, though adjustments
2227 * have been made.
2228 *
2229 **************************************************************/
Linus Torvalds1da177e2005-04-16 15:20:36 -07002230
Harvey Harrison98e0f522008-02-18 10:04:38 -08002231static void
Sakari Ailusc659c382011-01-21 10:59:30 +00002232tlan_reset_adapter(struct net_device *dev)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002233{
Sakari Ailusc659c382011-01-21 10:59:30 +00002234 struct tlan_priv *priv = netdev_priv(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002235 int i;
2236 u32 addr;
2237 u32 data;
2238 u8 data8;
2239
Sakari Ailusc659c382011-01-21 10:59:30 +00002240 priv->tlan_full_duplex = false;
2241 priv->phy_online = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002242 netif_carrier_off(dev);
2243
2244/* 1. Assert reset bit. */
2245
2246 data = inl(dev->base_addr + TLAN_HOST_CMD);
2247 data |= TLAN_HC_AD_RST;
2248 outl(data, dev->base_addr + TLAN_HOST_CMD);
Jeff Garzik6aa20a22006-09-13 13:24:59 -04002249
Linus Torvalds1da177e2005-04-16 15:20:36 -07002250 udelay(1000);
2251
Sakari Ailusc659c382011-01-21 10:59:30 +00002252/* 2. Turn off interrupts. (Probably isn't necessary) */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002253
2254 data = inl(dev->base_addr + TLAN_HOST_CMD);
2255 data |= TLAN_HC_INT_OFF;
2256 outl(data, dev->base_addr + TLAN_HOST_CMD);
2257
2258/* 3. Clear AREGs and HASHs. */
2259
Sakari Ailusc659c382011-01-21 10:59:30 +00002260 for (i = TLAN_AREG_0; i <= TLAN_HASH_2; i += 4)
2261 tlan_dio_write32(dev->base_addr, (u16) i, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002262
2263/* 4. Setup NetConfig register. */
2264
2265 data = TLAN_NET_CFG_1FRAG | TLAN_NET_CFG_1CHAN | TLAN_NET_CFG_PHY_EN;
Sakari Ailusc659c382011-01-21 10:59:30 +00002266 tlan_dio_write16(dev->base_addr, TLAN_NET_CONFIG, (u16) data);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002267
2268/* 5. Load Ld_Tmr and Ld_Thr in HOST_CMD. */
2269
Sakari Ailusc659c382011-01-21 10:59:30 +00002270 outl(TLAN_HC_LD_TMR | 0x3f, dev->base_addr + TLAN_HOST_CMD);
2271 outl(TLAN_HC_LD_THR | 0x9, dev->base_addr + TLAN_HOST_CMD);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002272
2273/* 6. Unreset the MII by setting NMRST (in NetSio) to 1. */
2274
Sakari Ailusc659c382011-01-21 10:59:30 +00002275 outw(TLAN_NET_SIO, dev->base_addr + TLAN_DIO_ADR);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002276 addr = dev->base_addr + TLAN_DIO_DATA + TLAN_NET_SIO;
Sakari Ailusc659c382011-01-21 10:59:30 +00002277 tlan_set_bit(TLAN_NET_SIO_NMRST, addr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002278
2279/* 7. Setup the remaining registers. */
2280
Sakari Ailusc659c382011-01-21 10:59:30 +00002281 if (priv->tlan_rev >= 0x30) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002282 data8 = TLAN_ID_TX_EOC | TLAN_ID_RX_EOC;
Sakari Ailusc659c382011-01-21 10:59:30 +00002283 tlan_dio_write8(dev->base_addr, TLAN_INT_DIS, data8);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002284 }
Sakari Ailusc659c382011-01-21 10:59:30 +00002285 tlan_phy_detect(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002286 data = TLAN_NET_CFG_1FRAG | TLAN_NET_CFG_1CHAN;
Jeff Garzik6aa20a22006-09-13 13:24:59 -04002287
Sakari Ailusc659c382011-01-21 10:59:30 +00002288 if (priv->adapter->flags & TLAN_ADAPTER_BIT_RATE_PHY) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002289 data |= TLAN_NET_CFG_BIT;
Sakari Ailusc659c382011-01-21 10:59:30 +00002290 if (priv->aui == 1) {
2291 tlan_dio_write8(dev->base_addr, TLAN_ACOMMIT, 0x0a);
2292 } else if (priv->duplex == TLAN_DUPLEX_FULL) {
2293 tlan_dio_write8(dev->base_addr, TLAN_ACOMMIT, 0x00);
2294 priv->tlan_full_duplex = true;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002295 } else {
Sakari Ailusc659c382011-01-21 10:59:30 +00002296 tlan_dio_write8(dev->base_addr, TLAN_ACOMMIT, 0x08);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002297 }
2298 }
2299
Sakari Ailusc659c382011-01-21 10:59:30 +00002300 if (priv->phy_num == 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002301 data |= TLAN_NET_CFG_PHY_EN;
Sakari Ailusc659c382011-01-21 10:59:30 +00002302 tlan_dio_write16(dev->base_addr, TLAN_NET_CONFIG, (u16) data);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002303
Sakari Ailusc659c382011-01-21 10:59:30 +00002304 if (priv->adapter->flags & TLAN_ADAPTER_UNMANAGED_PHY)
2305 tlan_finish_reset(dev);
2306 else
2307 tlan_phy_power_down(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002308
Sakari Ailusc659c382011-01-21 10:59:30 +00002309}
Linus Torvalds1da177e2005-04-16 15:20:36 -07002310
2311
2312
2313
Harvey Harrison98e0f522008-02-18 10:04:38 -08002314static void
Sakari Ailusc659c382011-01-21 10:59:30 +00002315tlan_finish_reset(struct net_device *dev)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002316{
Sakari Ailusc659c382011-01-21 10:59:30 +00002317 struct tlan_priv *priv = netdev_priv(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002318 u8 data;
2319 u32 phy;
2320 u8 sio;
2321 u16 status;
2322 u16 partner;
2323 u16 tlphy_ctl;
Sakari Ailusc659c382011-01-21 10:59:30 +00002324 u16 tlphy_par;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002325 u16 tlphy_id1, tlphy_id2;
Sakari Ailusc659c382011-01-21 10:59:30 +00002326 int i;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002327
Sakari Ailusc659c382011-01-21 10:59:30 +00002328 phy = priv->phy[priv->phy_num];
Linus Torvalds1da177e2005-04-16 15:20:36 -07002329
2330 data = TLAN_NET_CMD_NRESET | TLAN_NET_CMD_NWRAP;
Sakari Ailusc659c382011-01-21 10:59:30 +00002331 if (priv->tlan_full_duplex)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002332 data |= TLAN_NET_CMD_DUPLEX;
Sakari Ailusc659c382011-01-21 10:59:30 +00002333 tlan_dio_write8(dev->base_addr, TLAN_NET_CMD, data);
Jeff Garzik6aa20a22006-09-13 13:24:59 -04002334 data = TLAN_NET_MASK_MASK4 | TLAN_NET_MASK_MASK5;
Sakari Ailusc659c382011-01-21 10:59:30 +00002335 if (priv->phy_num == 0)
Jeff Garzik6aa20a22006-09-13 13:24:59 -04002336 data |= TLAN_NET_MASK_MASK7;
Sakari Ailusc659c382011-01-21 10:59:30 +00002337 tlan_dio_write8(dev->base_addr, TLAN_NET_MASK, data);
2338 tlan_dio_write16(dev->base_addr, TLAN_MAX_RX, ((1536)+7)&~7);
2339 tlan_mii_read_reg(dev, phy, MII_GEN_ID_HI, &tlphy_id1);
2340 tlan_mii_read_reg(dev, phy, MII_GEN_ID_LO, &tlphy_id2);
Jeff Garzik6aa20a22006-09-13 13:24:59 -04002341
Sakari Ailusc659c382011-01-21 10:59:30 +00002342 if ((priv->adapter->flags & TLAN_ADAPTER_UNMANAGED_PHY) ||
2343 (priv->aui)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002344 status = MII_GS_LINK;
Sakari Ailusc659c382011-01-21 10:59:30 +00002345 pr_info("TLAN: %s: Link forced.\n", dev->name);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002346 } else {
Sakari Ailusc659c382011-01-21 10:59:30 +00002347 tlan_mii_read_reg(dev, phy, MII_GEN_STS, &status);
2348 udelay(1000);
2349 tlan_mii_read_reg(dev, phy, MII_GEN_STS, &status);
2350 if ((status & MII_GS_LINK) &&
2351 /* We only support link info on Nat.Sem. PHY's */
2352 (tlphy_id1 == NAT_SEM_ID1) &&
2353 (tlphy_id2 == NAT_SEM_ID2)) {
2354 tlan_mii_read_reg(dev, phy, MII_AN_LPA, &partner);
2355 tlan_mii_read_reg(dev, phy, TLAN_TLPHY_PAR, &tlphy_par);
Jeff Garzik6aa20a22006-09-13 13:24:59 -04002356
Sakari Ailusc659c382011-01-21 10:59:30 +00002357 pr_info("TLAN: %s: Link active with ", dev->name);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002358 if (!(tlphy_par & TLAN_PHY_AN_EN_STAT)) {
Sakari Ailusc659c382011-01-21 10:59:30 +00002359 pr_info("forced 10%sMbps %s-Duplex\n",
2360 tlphy_par & TLAN_PHY_SPEED_100
2361 ? "" : "0",
2362 tlphy_par & TLAN_PHY_DUPLEX_FULL
2363 ? "Full" : "Half");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002364 } else {
Sakari Ailusc659c382011-01-21 10:59:30 +00002365 pr_info("Autonegotiation enabled, at 10%sMbps %s-Duplex\n",
2366 tlphy_par & TLAN_PHY_SPEED_100
2367 ? "" : "0",
2368 tlphy_par & TLAN_PHY_DUPLEX_FULL
2369 ? "Full" : "half");
2370 pr_info("TLAN: Partner capability: ");
2371 for (i = 5; i <= 10; i++)
2372 if (partner & (1<<i))
2373 printk("%s", media[i-5]);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002374 printk("\n");
2375 }
2376
Sakari Ailusc659c382011-01-21 10:59:30 +00002377 tlan_dio_write8(dev->base_addr, TLAN_LED_REG,
2378 TLAN_LED_LINK);
Jeff Garzik6aa20a22006-09-13 13:24:59 -04002379#ifdef MONITOR
Linus Torvalds1da177e2005-04-16 15:20:36 -07002380 /* We have link beat..for now anyway */
Sakari Ailusc659c382011-01-21 10:59:30 +00002381 priv->link = 1;
2382 /*Enabling link beat monitoring */
2383 tlan_set_timer(dev, (10*HZ), TLAN_TIMER_LINK_BEAT);
Jeff Garzik6aa20a22006-09-13 13:24:59 -04002384#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -07002385 } else if (status & MII_GS_LINK) {
Sakari Ailusc659c382011-01-21 10:59:30 +00002386 pr_info("TLAN: %s: Link active\n", dev->name);
2387 tlan_dio_write8(dev->base_addr, TLAN_LED_REG,
2388 TLAN_LED_LINK);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002389 }
2390 }
2391
Sakari Ailusc659c382011-01-21 10:59:30 +00002392 if (priv->phy_num == 0) {
2393 tlan_mii_read_reg(dev, phy, TLAN_TLPHY_CTL, &tlphy_ctl);
2394 tlphy_ctl |= TLAN_TC_INTEN;
2395 tlan_mii_write_reg(dev, phy, TLAN_TLPHY_CTL, tlphy_ctl);
2396 sio = tlan_dio_read8(dev->base_addr, TLAN_NET_SIO);
2397 sio |= TLAN_NET_SIO_MINTEN;
2398 tlan_dio_write8(dev->base_addr, TLAN_NET_SIO, sio);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002399 }
2400
Sakari Ailusc659c382011-01-21 10:59:30 +00002401 if (status & MII_GS_LINK) {
2402 tlan_set_mac(dev, 0, dev->dev_addr);
2403 priv->phy_online = 1;
2404 outb((TLAN_HC_INT_ON >> 8), dev->base_addr + TLAN_HOST_CMD + 1);
2405 if (debug >= 1 && debug != TLAN_DEBUG_PROBE)
2406 outb((TLAN_HC_REQ_INT >> 8),
2407 dev->base_addr + TLAN_HOST_CMD + 1);
2408 outl(priv->rx_list_dma, dev->base_addr + TLAN_CH_PARM);
2409 outl(TLAN_HC_GO | TLAN_HC_RT, dev->base_addr + TLAN_HOST_CMD);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002410 netif_carrier_on(dev);
2411 } else {
Sakari Ailusc659c382011-01-21 10:59:30 +00002412 pr_info("TLAN: %s: Link inactive, will retry in 10 secs...\n",
2413 dev->name);
2414 tlan_set_timer(dev, (10*HZ), TLAN_TIMER_FINISH_RESET);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002415 return;
2416 }
Sakari Ailusc659c382011-01-21 10:59:30 +00002417 tlan_set_multicast_list(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002418
Sakari Ailusc659c382011-01-21 10:59:30 +00002419}
Linus Torvalds1da177e2005-04-16 15:20:36 -07002420
2421
2422
2423
Sakari Ailusc659c382011-01-21 10:59:30 +00002424/***************************************************************
2425 * tlan_set_mac
2426 *
2427 * Returns:
2428 * Nothing
2429 * Parms:
2430 * dev Pointer to device structure of adapter
2431 * on which to change the AREG.
2432 * areg The AREG to set the address in (0 - 3).
2433 * mac A pointer to an array of chars. Each
2434 * element stores one byte of the address.
2435 * IE, it isn't in ascii.
2436 *
2437 * This function transfers a MAC address to one of the
2438 * TLAN AREGs (address registers). The TLAN chip locks
2439 * the register on writing to offset 0 and unlocks the
2440 * register after writing to offset 5. If NULL is passed
2441 * in mac, then the AREG is filled with 0's.
2442 *
2443 **************************************************************/
Linus Torvalds1da177e2005-04-16 15:20:36 -07002444
Sakari Ailusc659c382011-01-21 10:59:30 +00002445static void tlan_set_mac(struct net_device *dev, int areg, char *mac)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002446{
2447 int i;
Jeff Garzik6aa20a22006-09-13 13:24:59 -04002448
Linus Torvalds1da177e2005-04-16 15:20:36 -07002449 areg *= 6;
2450
Sakari Ailusc659c382011-01-21 10:59:30 +00002451 if (mac != NULL) {
2452 for (i = 0; i < 6; i++)
2453 tlan_dio_write8(dev->base_addr,
2454 TLAN_AREG_0 + areg + i, mac[i]);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002455 } else {
Sakari Ailusc659c382011-01-21 10:59:30 +00002456 for (i = 0; i < 6; i++)
2457 tlan_dio_write8(dev->base_addr,
2458 TLAN_AREG_0 + areg + i, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002459 }
2460
Sakari Ailusc659c382011-01-21 10:59:30 +00002461}
Linus Torvalds1da177e2005-04-16 15:20:36 -07002462
2463
2464
2465
2466/*****************************************************************************
2467******************************************************************************
2468
Sakari Ailusc659c382011-01-21 10:59:30 +00002469ThunderLAN driver PHY layer routines
Linus Torvalds1da177e2005-04-16 15:20:36 -07002470
2471******************************************************************************
2472*****************************************************************************/
2473
2474
2475
Sakari Ailusc659c382011-01-21 10:59:30 +00002476/*********************************************************************
2477 * tlan_phy_print
2478 *
2479 * Returns:
2480 * Nothing
2481 * Parms:
2482 * dev A pointer to the device structure of the
2483 * TLAN device having the PHYs to be detailed.
2484 *
2485 * This function prints the registers a PHY (aka transceiver).
2486 *
2487 ********************************************************************/
Linus Torvalds1da177e2005-04-16 15:20:36 -07002488
Sakari Ailusc659c382011-01-21 10:59:30 +00002489static void tlan_phy_print(struct net_device *dev)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002490{
Sakari Ailusc659c382011-01-21 10:59:30 +00002491 struct tlan_priv *priv = netdev_priv(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002492 u16 i, data0, data1, data2, data3, phy;
2493
Sakari Ailusc659c382011-01-21 10:59:30 +00002494 phy = priv->phy[priv->phy_num];
Linus Torvalds1da177e2005-04-16 15:20:36 -07002495
Sakari Ailusc659c382011-01-21 10:59:30 +00002496 if (priv->adapter->flags & TLAN_ADAPTER_UNMANAGED_PHY) {
2497 pr_info("TLAN: Device %s, Unmanaged PHY.\n", dev->name);
2498 } else if (phy <= TLAN_PHY_MAX_ADDR) {
2499 pr_info("TLAN: Device %s, PHY 0x%02x.\n", dev->name, phy);
2500 pr_info("TLAN: Off. +0 +1 +2 +3\n");
2501 for (i = 0; i < 0x20; i += 4) {
2502 pr_info("TLAN: 0x%02x", i);
2503 tlan_mii_read_reg(dev, phy, i, &data0);
2504 printk(" 0x%04hx", data0);
2505 tlan_mii_read_reg(dev, phy, i + 1, &data1);
2506 printk(" 0x%04hx", data1);
2507 tlan_mii_read_reg(dev, phy, i + 2, &data2);
2508 printk(" 0x%04hx", data2);
2509 tlan_mii_read_reg(dev, phy, i + 3, &data3);
2510 printk(" 0x%04hx\n", data3);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002511 }
2512 } else {
Sakari Ailusc659c382011-01-21 10:59:30 +00002513 pr_info("TLAN: Device %s, Invalid PHY.\n", dev->name);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002514 }
2515
Sakari Ailusc659c382011-01-21 10:59:30 +00002516}
Linus Torvalds1da177e2005-04-16 15:20:36 -07002517
2518
2519
2520
Sakari Ailusc659c382011-01-21 10:59:30 +00002521/*********************************************************************
2522 * tlan_phy_detect
2523 *
2524 * Returns:
2525 * Nothing
2526 * Parms:
2527 * dev A pointer to the device structure of the adapter
2528 * for which the PHY needs determined.
2529 *
2530 * So far I've found that adapters which have external PHYs
2531 * may also use the internal PHY for part of the functionality.
2532 * (eg, AUI/Thinnet). This function finds out if this TLAN
2533 * chip has an internal PHY, and then finds the first external
2534 * PHY (starting from address 0) if it exists).
2535 *
2536 ********************************************************************/
Linus Torvalds1da177e2005-04-16 15:20:36 -07002537
Sakari Ailusc659c382011-01-21 10:59:30 +00002538static void tlan_phy_detect(struct net_device *dev)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002539{
Sakari Ailusc659c382011-01-21 10:59:30 +00002540 struct tlan_priv *priv = netdev_priv(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002541 u16 control;
2542 u16 hi;
2543 u16 lo;
2544 u32 phy;
2545
Sakari Ailusc659c382011-01-21 10:59:30 +00002546 if (priv->adapter->flags & TLAN_ADAPTER_UNMANAGED_PHY) {
2547 priv->phy_num = 0xffff;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002548 return;
2549 }
2550
Sakari Ailusc659c382011-01-21 10:59:30 +00002551 tlan_mii_read_reg(dev, TLAN_PHY_MAX_ADDR, MII_GEN_ID_HI, &hi);
Jeff Garzik6aa20a22006-09-13 13:24:59 -04002552
Sakari Ailusc659c382011-01-21 10:59:30 +00002553 if (hi != 0xffff)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002554 priv->phy[0] = TLAN_PHY_MAX_ADDR;
Sakari Ailusc659c382011-01-21 10:59:30 +00002555 else
Linus Torvalds1da177e2005-04-16 15:20:36 -07002556 priv->phy[0] = TLAN_PHY_NONE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002557
2558 priv->phy[1] = TLAN_PHY_NONE;
Sakari Ailusc659c382011-01-21 10:59:30 +00002559 for (phy = 0; phy <= TLAN_PHY_MAX_ADDR; phy++) {
2560 tlan_mii_read_reg(dev, phy, MII_GEN_CTL, &control);
2561 tlan_mii_read_reg(dev, phy, MII_GEN_ID_HI, &hi);
2562 tlan_mii_read_reg(dev, phy, MII_GEN_ID_LO, &lo);
2563 if ((control != 0xffff) ||
2564 (hi != 0xffff) || (lo != 0xffff)) {
2565 TLAN_DBG(TLAN_DEBUG_GNRL,
2566 "PHY found at %02x %04x %04x %04x\n",
2567 phy, control, hi, lo);
2568 if ((priv->phy[1] == TLAN_PHY_NONE) &&
2569 (phy != TLAN_PHY_MAX_ADDR)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002570 priv->phy[1] = phy;
2571 }
2572 }
2573 }
2574
Sakari Ailusc659c382011-01-21 10:59:30 +00002575 if (priv->phy[1] != TLAN_PHY_NONE)
2576 priv->phy_num = 1;
2577 else if (priv->phy[0] != TLAN_PHY_NONE)
2578 priv->phy_num = 0;
2579 else
2580 pr_info("TLAN: Cannot initialize device, no PHY was found!\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002581
Sakari Ailusc659c382011-01-21 10:59:30 +00002582}
Linus Torvalds1da177e2005-04-16 15:20:36 -07002583
2584
2585
2586
Sakari Ailusc659c382011-01-21 10:59:30 +00002587static void tlan_phy_power_down(struct net_device *dev)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002588{
Sakari Ailusc659c382011-01-21 10:59:30 +00002589 struct tlan_priv *priv = netdev_priv(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002590 u16 value;
2591
Sakari Ailusc659c382011-01-21 10:59:30 +00002592 TLAN_DBG(TLAN_DEBUG_GNRL, "%s: Powering down PHY(s).\n", dev->name);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002593 value = MII_GC_PDOWN | MII_GC_LOOPBK | MII_GC_ISOLATE;
Sakari Ailusc659c382011-01-21 10:59:30 +00002594 tlan_mii_sync(dev->base_addr);
2595 tlan_mii_write_reg(dev, priv->phy[priv->phy_num], MII_GEN_CTL, value);
2596 if ((priv->phy_num == 0) &&
2597 (priv->phy[1] != TLAN_PHY_NONE) &&
2598 (!(priv->adapter->flags & TLAN_ADAPTER_USE_INTERN_10))) {
2599 tlan_mii_sync(dev->base_addr);
2600 tlan_mii_write_reg(dev, priv->phy[1], MII_GEN_CTL, value);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002601 }
2602
2603 /* Wait for 50 ms and powerup
2604 * This is abitrary. It is intended to make sure the
2605 * transceiver settles.
2606 */
Sakari Ailusc659c382011-01-21 10:59:30 +00002607 tlan_set_timer(dev, (HZ/20), TLAN_TIMER_PHY_PUP);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002608
Sakari Ailusc659c382011-01-21 10:59:30 +00002609}
Linus Torvalds1da177e2005-04-16 15:20:36 -07002610
2611
2612
2613
Sakari Ailusc659c382011-01-21 10:59:30 +00002614static void tlan_phy_power_up(struct net_device *dev)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002615{
Sakari Ailusc659c382011-01-21 10:59:30 +00002616 struct tlan_priv *priv = netdev_priv(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002617 u16 value;
2618
Sakari Ailusc659c382011-01-21 10:59:30 +00002619 TLAN_DBG(TLAN_DEBUG_GNRL, "%s: Powering up PHY.\n", dev->name);
2620 tlan_mii_sync(dev->base_addr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002621 value = MII_GC_LOOPBK;
Sakari Ailusc659c382011-01-21 10:59:30 +00002622 tlan_mii_write_reg(dev, priv->phy[priv->phy_num], MII_GEN_CTL, value);
2623 tlan_mii_sync(dev->base_addr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002624 /* Wait for 500 ms and reset the
2625 * transceiver. The TLAN docs say both 50 ms and
2626 * 500 ms, so do the longer, just in case.
2627 */
Sakari Ailusc659c382011-01-21 10:59:30 +00002628 tlan_set_timer(dev, (HZ/20), TLAN_TIMER_PHY_RESET);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002629
Sakari Ailusc659c382011-01-21 10:59:30 +00002630}
Linus Torvalds1da177e2005-04-16 15:20:36 -07002631
2632
2633
2634
Sakari Ailusc659c382011-01-21 10:59:30 +00002635static void tlan_phy_reset(struct net_device *dev)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002636{
Sakari Ailusc659c382011-01-21 10:59:30 +00002637 struct tlan_priv *priv = netdev_priv(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002638 u16 phy;
2639 u16 value;
2640
Sakari Ailusc659c382011-01-21 10:59:30 +00002641 phy = priv->phy[priv->phy_num];
Linus Torvalds1da177e2005-04-16 15:20:36 -07002642
Sakari Ailusc659c382011-01-21 10:59:30 +00002643 TLAN_DBG(TLAN_DEBUG_GNRL, "%s: Reseting PHY.\n", dev->name);
2644 tlan_mii_sync(dev->base_addr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002645 value = MII_GC_LOOPBK | MII_GC_RESET;
Sakari Ailusc659c382011-01-21 10:59:30 +00002646 tlan_mii_write_reg(dev, phy, MII_GEN_CTL, value);
2647 tlan_mii_read_reg(dev, phy, MII_GEN_CTL, &value);
2648 while (value & MII_GC_RESET)
2649 tlan_mii_read_reg(dev, phy, MII_GEN_CTL, &value);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002650
2651 /* Wait for 500 ms and initialize.
2652 * I don't remember why I wait this long.
2653 * I've changed this to 50ms, as it seems long enough.
2654 */
Sakari Ailusc659c382011-01-21 10:59:30 +00002655 tlan_set_timer(dev, (HZ/20), TLAN_TIMER_PHY_START_LINK);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002656
Sakari Ailusc659c382011-01-21 10:59:30 +00002657}
Linus Torvalds1da177e2005-04-16 15:20:36 -07002658
2659
2660
2661
Sakari Ailusc659c382011-01-21 10:59:30 +00002662static void tlan_phy_start_link(struct net_device *dev)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002663{
Sakari Ailusc659c382011-01-21 10:59:30 +00002664 struct tlan_priv *priv = netdev_priv(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002665 u16 ability;
2666 u16 control;
2667 u16 data;
2668 u16 phy;
2669 u16 status;
2670 u16 tctl;
2671
Sakari Ailusc659c382011-01-21 10:59:30 +00002672 phy = priv->phy[priv->phy_num];
2673 TLAN_DBG(TLAN_DEBUG_GNRL, "%s: Trying to activate link.\n", dev->name);
2674 tlan_mii_read_reg(dev, phy, MII_GEN_STS, &status);
2675 tlan_mii_read_reg(dev, phy, MII_GEN_STS, &ability);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002676
Sakari Ailusc659c382011-01-21 10:59:30 +00002677 if ((status & MII_GS_AUTONEG) &&
2678 (!priv->aui)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002679 ability = status >> 11;
Sakari Ailusc659c382011-01-21 10:59:30 +00002680 if (priv->speed == TLAN_SPEED_10 &&
2681 priv->duplex == TLAN_DUPLEX_HALF) {
2682 tlan_mii_write_reg(dev, phy, MII_GEN_CTL, 0x0000);
2683 } else if (priv->speed == TLAN_SPEED_10 &&
2684 priv->duplex == TLAN_DUPLEX_FULL) {
2685 priv->tlan_full_duplex = true;
2686 tlan_mii_write_reg(dev, phy, MII_GEN_CTL, 0x0100);
2687 } else if (priv->speed == TLAN_SPEED_100 &&
2688 priv->duplex == TLAN_DUPLEX_HALF) {
2689 tlan_mii_write_reg(dev, phy, MII_GEN_CTL, 0x2000);
2690 } else if (priv->speed == TLAN_SPEED_100 &&
2691 priv->duplex == TLAN_DUPLEX_FULL) {
2692 priv->tlan_full_duplex = true;
2693 tlan_mii_write_reg(dev, phy, MII_GEN_CTL, 0x2100);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002694 } else {
Jeff Garzik6aa20a22006-09-13 13:24:59 -04002695
Linus Torvalds1da177e2005-04-16 15:20:36 -07002696 /* Set Auto-Neg advertisement */
Sakari Ailusc659c382011-01-21 10:59:30 +00002697 tlan_mii_write_reg(dev, phy, MII_AN_ADV,
2698 (ability << 5) | 1);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002699 /* Enablee Auto-Neg */
Sakari Ailusc659c382011-01-21 10:59:30 +00002700 tlan_mii_write_reg(dev, phy, MII_GEN_CTL, 0x1000);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002701 /* Restart Auto-Neg */
Sakari Ailusc659c382011-01-21 10:59:30 +00002702 tlan_mii_write_reg(dev, phy, MII_GEN_CTL, 0x1200);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002703 /* Wait for 4 sec for autonegotiation
Sakari Ailusc659c382011-01-21 10:59:30 +00002704 * to complete. The max spec time is less than this
2705 * but the card need additional time to start AN.
2706 * .5 sec should be plenty extra.
2707 */
2708 pr_info("TLAN: %s: Starting autonegotiation.\n",
2709 dev->name);
2710 tlan_set_timer(dev, (2*HZ), TLAN_TIMER_PHY_FINISH_AN);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002711 return;
2712 }
Jeff Garzik6aa20a22006-09-13 13:24:59 -04002713
2714 }
2715
Sakari Ailusc659c382011-01-21 10:59:30 +00002716 if ((priv->aui) && (priv->phy_num != 0)) {
2717 priv->phy_num = 0;
2718 data = TLAN_NET_CFG_1FRAG | TLAN_NET_CFG_1CHAN
2719 | TLAN_NET_CFG_PHY_EN;
2720 tlan_dio_write16(dev->base_addr, TLAN_NET_CONFIG, data);
2721 tlan_set_timer(dev, (40*HZ/1000), TLAN_TIMER_PHY_PDOWN);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002722 return;
Sakari Ailusc659c382011-01-21 10:59:30 +00002723 } else if (priv->phy_num == 0) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002724 control = 0;
Sakari Ailusc659c382011-01-21 10:59:30 +00002725 tlan_mii_read_reg(dev, phy, TLAN_TLPHY_CTL, &tctl);
2726 if (priv->aui) {
2727 tctl |= TLAN_TC_AUISEL;
Jeff Garzik6aa20a22006-09-13 13:24:59 -04002728 } else {
Sakari Ailusc659c382011-01-21 10:59:30 +00002729 tctl &= ~TLAN_TC_AUISEL;
2730 if (priv->duplex == TLAN_DUPLEX_FULL) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002731 control |= MII_GC_DUPLEX;
Sakari Ailusc659c382011-01-21 10:59:30 +00002732 priv->tlan_full_duplex = true;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002733 }
Sakari Ailusc659c382011-01-21 10:59:30 +00002734 if (priv->speed == TLAN_SPEED_100)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002735 control |= MII_GC_SPEEDSEL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002736 }
Sakari Ailusc659c382011-01-21 10:59:30 +00002737 tlan_mii_write_reg(dev, phy, MII_GEN_CTL, control);
2738 tlan_mii_write_reg(dev, phy, TLAN_TLPHY_CTL, tctl);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002739 }
2740
2741 /* Wait for 2 sec to give the transceiver time
2742 * to establish link.
2743 */
Sakari Ailusc659c382011-01-21 10:59:30 +00002744 tlan_set_timer(dev, (4*HZ), TLAN_TIMER_FINISH_RESET);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002745
Sakari Ailusc659c382011-01-21 10:59:30 +00002746}
Linus Torvalds1da177e2005-04-16 15:20:36 -07002747
2748
2749
2750
Sakari Ailusc659c382011-01-21 10:59:30 +00002751static void tlan_phy_finish_auto_neg(struct net_device *dev)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002752{
Sakari Ailusc659c382011-01-21 10:59:30 +00002753 struct tlan_priv *priv = netdev_priv(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002754 u16 an_adv;
2755 u16 an_lpa;
2756 u16 data;
2757 u16 mode;
2758 u16 phy;
2759 u16 status;
Jeff Garzik6aa20a22006-09-13 13:24:59 -04002760
Sakari Ailusc659c382011-01-21 10:59:30 +00002761 phy = priv->phy[priv->phy_num];
Linus Torvalds1da177e2005-04-16 15:20:36 -07002762
Sakari Ailusc659c382011-01-21 10:59:30 +00002763 tlan_mii_read_reg(dev, phy, MII_GEN_STS, &status);
2764 udelay(1000);
2765 tlan_mii_read_reg(dev, phy, MII_GEN_STS, &status);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002766
Sakari Ailusc659c382011-01-21 10:59:30 +00002767 if (!(status & MII_GS_AUTOCMPLT)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002768 /* Wait for 8 sec to give the process
2769 * more time. Perhaps we should fail after a while.
2770 */
Sakari Ailusc659c382011-01-21 10:59:30 +00002771 if (!priv->neg_be_verbose++) {
2772 pr_info("TLAN: Giving autonegotiation more time.\n");
2773 pr_info("TLAN: Please check that your adapter has\n");
2774 pr_info("TLAN: been properly connected to a HUB or Switch.\n");
2775 pr_info("TLAN: Trying to establish link in the background...\n");
2776 }
2777 tlan_set_timer(dev, (8*HZ), TLAN_TIMER_PHY_FINISH_AN);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002778 return;
2779 }
2780
Sakari Ailusc659c382011-01-21 10:59:30 +00002781 pr_info("TLAN: %s: Autonegotiation complete.\n", dev->name);
2782 tlan_mii_read_reg(dev, phy, MII_AN_ADV, &an_adv);
2783 tlan_mii_read_reg(dev, phy, MII_AN_LPA, &an_lpa);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002784 mode = an_adv & an_lpa & 0x03E0;
Sakari Ailusc659c382011-01-21 10:59:30 +00002785 if (mode & 0x0100)
2786 priv->tlan_full_duplex = true;
2787 else if (!(mode & 0x0080) && (mode & 0x0040))
2788 priv->tlan_full_duplex = true;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002789
Sakari Ailusc659c382011-01-21 10:59:30 +00002790 if ((!(mode & 0x0180)) &&
2791 (priv->adapter->flags & TLAN_ADAPTER_USE_INTERN_10) &&
2792 (priv->phy_num != 0)) {
2793 priv->phy_num = 0;
2794 data = TLAN_NET_CFG_1FRAG | TLAN_NET_CFG_1CHAN
2795 | TLAN_NET_CFG_PHY_EN;
2796 tlan_dio_write16(dev->base_addr, TLAN_NET_CONFIG, data);
2797 tlan_set_timer(dev, (400*HZ/1000), TLAN_TIMER_PHY_PDOWN);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002798 return;
2799 }
2800
Sakari Ailusc659c382011-01-21 10:59:30 +00002801 if (priv->phy_num == 0) {
2802 if ((priv->duplex == TLAN_DUPLEX_FULL) ||
2803 (an_adv & an_lpa & 0x0040)) {
2804 tlan_mii_write_reg(dev, phy, MII_GEN_CTL,
2805 MII_GC_AUTOENB | MII_GC_DUPLEX);
2806 pr_info("TLAN: Starting internal PHY with FULL-DUPLEX\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002807 } else {
Sakari Ailusc659c382011-01-21 10:59:30 +00002808 tlan_mii_write_reg(dev, phy, MII_GEN_CTL,
2809 MII_GC_AUTOENB);
2810 pr_info("TLAN: Starting internal PHY with HALF-DUPLEX\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002811 }
2812 }
2813
2814 /* Wait for 100 ms. No reason in partiticular.
2815 */
Sakari Ailusc659c382011-01-21 10:59:30 +00002816 tlan_set_timer(dev, (HZ/10), TLAN_TIMER_FINISH_RESET);
Jeff Garzik6aa20a22006-09-13 13:24:59 -04002817
Sakari Ailusc659c382011-01-21 10:59:30 +00002818}
Linus Torvalds1da177e2005-04-16 15:20:36 -07002819
2820#ifdef MONITOR
2821
Sakari Ailusc659c382011-01-21 10:59:30 +00002822/*********************************************************************
2823 *
2824 * tlan_phy_monitor
2825 *
2826 * Returns:
2827 * None
2828 *
2829 * Params:
2830 * dev The device structure of this device.
2831 *
2832 *
2833 * This function monitors PHY condition by reading the status
2834 * register via the MII bus. This can be used to give info
2835 * about link changes (up/down), and possible switch to alternate
2836 * media.
2837 *
2838 *******************************************************************/
Linus Torvalds1da177e2005-04-16 15:20:36 -07002839
Sakari Ailusc659c382011-01-21 10:59:30 +00002840void tlan_phy_monitor(struct net_device *dev)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002841{
Sakari Ailusc659c382011-01-21 10:59:30 +00002842 struct tlan_priv *priv = netdev_priv(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002843 u16 phy;
2844 u16 phy_status;
2845
Sakari Ailusc659c382011-01-21 10:59:30 +00002846 phy = priv->phy[priv->phy_num];
Linus Torvalds1da177e2005-04-16 15:20:36 -07002847
Sakari Ailusc659c382011-01-21 10:59:30 +00002848 /* Get PHY status register */
2849 tlan_mii_read_reg(dev, phy, MII_GEN_STS, &phy_status);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002850
Sakari Ailusc659c382011-01-21 10:59:30 +00002851 /* Check if link has been lost */
2852 if (!(phy_status & MII_GS_LINK)) {
2853 if (priv->link) {
2854 priv->link = 0;
2855 printk(KERN_DEBUG "TLAN: %s has lost link\n",
2856 dev->name);
2857 netif_carrier_off(dev);
2858 tlan_set_timer(dev, (2*HZ), TLAN_TIMER_LINK_BEAT);
2859 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002860 }
2861 }
2862
Sakari Ailusc659c382011-01-21 10:59:30 +00002863 /* Link restablished? */
2864 if ((phy_status & MII_GS_LINK) && !priv->link) {
2865 priv->link = 1;
2866 printk(KERN_DEBUG "TLAN: %s has reestablished link\n",
2867 dev->name);
7d17c1d2005-05-12 19:45:25 -04002868 netif_carrier_on(dev);
Sakari Ailusc659c382011-01-21 10:59:30 +00002869 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002870
2871 /* Setup a new monitor */
Sakari Ailusc659c382011-01-21 10:59:30 +00002872 tlan_set_timer(dev, (2*HZ), TLAN_TIMER_LINK_BEAT);
Jeff Garzik6aa20a22006-09-13 13:24:59 -04002873}
Linus Torvalds1da177e2005-04-16 15:20:36 -07002874
2875#endif /* MONITOR */
2876
2877
2878/*****************************************************************************
2879******************************************************************************
2880
Sakari Ailusc659c382011-01-21 10:59:30 +00002881ThunderLAN driver MII routines
Linus Torvalds1da177e2005-04-16 15:20:36 -07002882
Sakari Ailusc659c382011-01-21 10:59:30 +00002883these routines are based on the information in chap. 2 of the
2884"ThunderLAN Programmer's Guide", pp. 15-24.
Linus Torvalds1da177e2005-04-16 15:20:36 -07002885
2886******************************************************************************
2887*****************************************************************************/
2888
2889
Sakari Ailusc659c382011-01-21 10:59:30 +00002890/***************************************************************
2891 * tlan_mii_read_reg
2892 *
2893 * Returns:
2894 * false if ack received ok
2895 * true if no ack received or other error
2896 *
2897 * Parms:
2898 * dev The device structure containing
2899 * The io address and interrupt count
2900 * for this device.
2901 * phy The address of the PHY to be queried.
2902 * reg The register whose contents are to be
2903 * retrieved.
2904 * val A pointer to a variable to store the
2905 * retrieved value.
2906 *
2907 * This function uses the TLAN's MII bus to retrieve the contents
2908 * of a given register on a PHY. It sends the appropriate info
2909 * and then reads the 16-bit register value from the MII bus via
2910 * the TLAN SIO register.
2911 *
2912 **************************************************************/
Linus Torvalds1da177e2005-04-16 15:20:36 -07002913
Sakari Ailusc659c382011-01-21 10:59:30 +00002914static bool
2915tlan_mii_read_reg(struct net_device *dev, u16 phy, u16 reg, u16 *val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002916{
2917 u8 nack;
2918 u16 sio, tmp;
Sakari Ailusc659c382011-01-21 10:59:30 +00002919 u32 i;
Joe Perches37fce432010-01-12 20:59:13 +00002920 bool err;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002921 int minten;
Sakari Ailusc659c382011-01-21 10:59:30 +00002922 struct tlan_priv *priv = netdev_priv(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002923 unsigned long flags = 0;
2924
Joe Perches37fce432010-01-12 20:59:13 +00002925 err = false;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002926 outw(TLAN_NET_SIO, dev->base_addr + TLAN_DIO_ADR);
2927 sio = dev->base_addr + TLAN_DIO_DATA + TLAN_NET_SIO;
Jeff Garzik6aa20a22006-09-13 13:24:59 -04002928
Linus Torvalds1da177e2005-04-16 15:20:36 -07002929 if (!in_irq())
2930 spin_lock_irqsave(&priv->lock, flags);
2931
Sakari Ailusc659c382011-01-21 10:59:30 +00002932 tlan_mii_sync(dev->base_addr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002933
Sakari Ailusc659c382011-01-21 10:59:30 +00002934 minten = tlan_get_bit(TLAN_NET_SIO_MINTEN, sio);
2935 if (minten)
2936 tlan_clear_bit(TLAN_NET_SIO_MINTEN, sio);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002937
Sakari Ailusc659c382011-01-21 10:59:30 +00002938 tlan_mii_send_data(dev->base_addr, 0x1, 2); /* start (01b) */
2939 tlan_mii_send_data(dev->base_addr, 0x2, 2); /* read (10b) */
2940 tlan_mii_send_data(dev->base_addr, phy, 5); /* device # */
2941 tlan_mii_send_data(dev->base_addr, reg, 5); /* register # */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002942
2943
Sakari Ailusc659c382011-01-21 10:59:30 +00002944 tlan_clear_bit(TLAN_NET_SIO_MTXEN, sio); /* change direction */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002945
Sakari Ailusc659c382011-01-21 10:59:30 +00002946 tlan_clear_bit(TLAN_NET_SIO_MCLK, sio); /* clock idle bit */
2947 tlan_set_bit(TLAN_NET_SIO_MCLK, sio);
2948 tlan_clear_bit(TLAN_NET_SIO_MCLK, sio); /* wait 300ns */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002949
Sakari Ailusc659c382011-01-21 10:59:30 +00002950 nack = tlan_get_bit(TLAN_NET_SIO_MDATA, sio); /* check for ACK */
2951 tlan_set_bit(TLAN_NET_SIO_MCLK, sio); /* finish ACK */
2952 if (nack) { /* no ACK, so fake it */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002953 for (i = 0; i < 16; i++) {
Sakari Ailusc659c382011-01-21 10:59:30 +00002954 tlan_clear_bit(TLAN_NET_SIO_MCLK, sio);
2955 tlan_set_bit(TLAN_NET_SIO_MCLK, sio);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002956 }
2957 tmp = 0xffff;
Joe Perches37fce432010-01-12 20:59:13 +00002958 err = true;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002959 } else { /* ACK, so read data */
2960 for (tmp = 0, i = 0x8000; i; i >>= 1) {
Sakari Ailusc659c382011-01-21 10:59:30 +00002961 tlan_clear_bit(TLAN_NET_SIO_MCLK, sio);
2962 if (tlan_get_bit(TLAN_NET_SIO_MDATA, sio))
Linus Torvalds1da177e2005-04-16 15:20:36 -07002963 tmp |= i;
Sakari Ailusc659c382011-01-21 10:59:30 +00002964 tlan_set_bit(TLAN_NET_SIO_MCLK, sio);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002965 }
2966 }
2967
2968
Sakari Ailusc659c382011-01-21 10:59:30 +00002969 tlan_clear_bit(TLAN_NET_SIO_MCLK, sio); /* idle cycle */
2970 tlan_set_bit(TLAN_NET_SIO_MCLK, sio);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002971
Sakari Ailusc659c382011-01-21 10:59:30 +00002972 if (minten)
2973 tlan_set_bit(TLAN_NET_SIO_MINTEN, sio);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002974
2975 *val = tmp;
Jeff Garzik6aa20a22006-09-13 13:24:59 -04002976
Linus Torvalds1da177e2005-04-16 15:20:36 -07002977 if (!in_irq())
2978 spin_unlock_irqrestore(&priv->lock, flags);
2979
2980 return err;
2981
Sakari Ailusc659c382011-01-21 10:59:30 +00002982}
Linus Torvalds1da177e2005-04-16 15:20:36 -07002983
2984
2985
2986
Sakari Ailusc659c382011-01-21 10:59:30 +00002987/***************************************************************
2988 * tlan_mii_send_data
2989 *
2990 * Returns:
2991 * Nothing
2992 * Parms:
2993 * base_port The base IO port of the adapter in
2994 * question.
2995 * dev The address of the PHY to be queried.
2996 * data The value to be placed on the MII bus.
2997 * num_bits The number of bits in data that are to
2998 * be placed on the MII bus.
2999 *
3000 * This function sends on sequence of bits on the MII
3001 * configuration bus.
3002 *
3003 **************************************************************/
Linus Torvalds1da177e2005-04-16 15:20:36 -07003004
Sakari Ailusc659c382011-01-21 10:59:30 +00003005static void tlan_mii_send_data(u16 base_port, u32 data, unsigned num_bits)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003006{
3007 u16 sio;
3008 u32 i;
3009
Sakari Ailusc659c382011-01-21 10:59:30 +00003010 if (num_bits == 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003011 return;
3012
Sakari Ailusc659c382011-01-21 10:59:30 +00003013 outw(TLAN_NET_SIO, base_port + TLAN_DIO_ADR);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003014 sio = base_port + TLAN_DIO_DATA + TLAN_NET_SIO;
Sakari Ailusc659c382011-01-21 10:59:30 +00003015 tlan_set_bit(TLAN_NET_SIO_MTXEN, sio);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003016
Sakari Ailusc659c382011-01-21 10:59:30 +00003017 for (i = (0x1 << (num_bits - 1)); i; i >>= 1) {
3018 tlan_clear_bit(TLAN_NET_SIO_MCLK, sio);
3019 (void) tlan_get_bit(TLAN_NET_SIO_MCLK, sio);
3020 if (data & i)
3021 tlan_set_bit(TLAN_NET_SIO_MDATA, sio);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003022 else
Sakari Ailusc659c382011-01-21 10:59:30 +00003023 tlan_clear_bit(TLAN_NET_SIO_MDATA, sio);
3024 tlan_set_bit(TLAN_NET_SIO_MCLK, sio);
3025 (void) tlan_get_bit(TLAN_NET_SIO_MCLK, sio);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003026 }
3027
Sakari Ailusc659c382011-01-21 10:59:30 +00003028}
Linus Torvalds1da177e2005-04-16 15:20:36 -07003029
3030
3031
3032
Sakari Ailusc659c382011-01-21 10:59:30 +00003033/***************************************************************
3034 * TLan_MiiSync
3035 *
3036 * Returns:
3037 * Nothing
3038 * Parms:
3039 * base_port The base IO port of the adapter in
3040 * question.
3041 *
3042 * This functions syncs all PHYs in terms of the MII configuration
3043 * bus.
3044 *
3045 **************************************************************/
Linus Torvalds1da177e2005-04-16 15:20:36 -07003046
Sakari Ailusc659c382011-01-21 10:59:30 +00003047static void tlan_mii_sync(u16 base_port)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003048{
3049 int i;
3050 u16 sio;
3051
Sakari Ailusc659c382011-01-21 10:59:30 +00003052 outw(TLAN_NET_SIO, base_port + TLAN_DIO_ADR);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003053 sio = base_port + TLAN_DIO_DATA + TLAN_NET_SIO;
3054
Sakari Ailusc659c382011-01-21 10:59:30 +00003055 tlan_clear_bit(TLAN_NET_SIO_MTXEN, sio);
3056 for (i = 0; i < 32; i++) {
3057 tlan_clear_bit(TLAN_NET_SIO_MCLK, sio);
3058 tlan_set_bit(TLAN_NET_SIO_MCLK, sio);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003059 }
3060
Sakari Ailusc659c382011-01-21 10:59:30 +00003061}
Linus Torvalds1da177e2005-04-16 15:20:36 -07003062
3063
3064
3065
Sakari Ailusc659c382011-01-21 10:59:30 +00003066/***************************************************************
3067 * tlan_mii_write_reg
3068 *
3069 * Returns:
3070 * Nothing
3071 * Parms:
3072 * dev The device structure for the device
3073 * to write to.
3074 * phy The address of the PHY to be written to.
3075 * reg The register whose contents are to be
3076 * written.
3077 * val The value to be written to the register.
3078 *
3079 * This function uses the TLAN's MII bus to write the contents of a
3080 * given register on a PHY. It sends the appropriate info and then
3081 * writes the 16-bit register value from the MII configuration bus
3082 * via the TLAN SIO register.
3083 *
3084 **************************************************************/
Linus Torvalds1da177e2005-04-16 15:20:36 -07003085
Sakari Ailusc659c382011-01-21 10:59:30 +00003086static void
3087tlan_mii_write_reg(struct net_device *dev, u16 phy, u16 reg, u16 val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003088{
3089 u16 sio;
3090 int minten;
3091 unsigned long flags = 0;
Sakari Ailusc659c382011-01-21 10:59:30 +00003092 struct tlan_priv *priv = netdev_priv(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003093
3094 outw(TLAN_NET_SIO, dev->base_addr + TLAN_DIO_ADR);
3095 sio = dev->base_addr + TLAN_DIO_DATA + TLAN_NET_SIO;
Jeff Garzik6aa20a22006-09-13 13:24:59 -04003096
Linus Torvalds1da177e2005-04-16 15:20:36 -07003097 if (!in_irq())
3098 spin_lock_irqsave(&priv->lock, flags);
3099
Sakari Ailusc659c382011-01-21 10:59:30 +00003100 tlan_mii_sync(dev->base_addr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003101
Sakari Ailusc659c382011-01-21 10:59:30 +00003102 minten = tlan_get_bit(TLAN_NET_SIO_MINTEN, sio);
3103 if (minten)
3104 tlan_clear_bit(TLAN_NET_SIO_MINTEN, sio);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003105
Sakari Ailusc659c382011-01-21 10:59:30 +00003106 tlan_mii_send_data(dev->base_addr, 0x1, 2); /* start (01b) */
3107 tlan_mii_send_data(dev->base_addr, 0x1, 2); /* write (01b) */
3108 tlan_mii_send_data(dev->base_addr, phy, 5); /* device # */
3109 tlan_mii_send_data(dev->base_addr, reg, 5); /* register # */
Linus Torvalds1da177e2005-04-16 15:20:36 -07003110
Sakari Ailusc659c382011-01-21 10:59:30 +00003111 tlan_mii_send_data(dev->base_addr, 0x2, 2); /* send ACK */
3112 tlan_mii_send_data(dev->base_addr, val, 16); /* send data */
Linus Torvalds1da177e2005-04-16 15:20:36 -07003113
Sakari Ailusc659c382011-01-21 10:59:30 +00003114 tlan_clear_bit(TLAN_NET_SIO_MCLK, sio); /* idle cycle */
3115 tlan_set_bit(TLAN_NET_SIO_MCLK, sio);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003116
Sakari Ailusc659c382011-01-21 10:59:30 +00003117 if (minten)
3118 tlan_set_bit(TLAN_NET_SIO_MINTEN, sio);
Jeff Garzik6aa20a22006-09-13 13:24:59 -04003119
Linus Torvalds1da177e2005-04-16 15:20:36 -07003120 if (!in_irq())
3121 spin_unlock_irqrestore(&priv->lock, flags);
3122
Sakari Ailusc659c382011-01-21 10:59:30 +00003123}
Linus Torvalds1da177e2005-04-16 15:20:36 -07003124
3125
3126
3127
3128/*****************************************************************************
3129******************************************************************************
3130
Sakari Ailusc659c382011-01-21 10:59:30 +00003131ThunderLAN driver eeprom routines
Linus Torvalds1da177e2005-04-16 15:20:36 -07003132
Sakari Ailusc659c382011-01-21 10:59:30 +00003133the Compaq netelligent 10 and 10/100 cards use a microchip 24C02A
3134EEPROM. these functions are based on information in microchip's
3135data sheet. I don't know how well this functions will work with
3136other Eeproms.
Linus Torvalds1da177e2005-04-16 15:20:36 -07003137
3138******************************************************************************
3139*****************************************************************************/
3140
3141
Sakari Ailusc659c382011-01-21 10:59:30 +00003142/***************************************************************
3143 * tlan_ee_send_start
3144 *
3145 * Returns:
3146 * Nothing
3147 * Parms:
3148 * io_base The IO port base address for the
3149 * TLAN device with the EEPROM to
3150 * use.
3151 *
3152 * This function sends a start cycle to an EEPROM attached
3153 * to a TLAN chip.
3154 *
3155 **************************************************************/
Linus Torvalds1da177e2005-04-16 15:20:36 -07003156
Sakari Ailusc659c382011-01-21 10:59:30 +00003157static void tlan_ee_send_start(u16 io_base)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003158{
3159 u16 sio;
3160
Sakari Ailusc659c382011-01-21 10:59:30 +00003161 outw(TLAN_NET_SIO, io_base + TLAN_DIO_ADR);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003162 sio = io_base + TLAN_DIO_DATA + TLAN_NET_SIO;
3163
Sakari Ailusc659c382011-01-21 10:59:30 +00003164 tlan_set_bit(TLAN_NET_SIO_ECLOK, sio);
3165 tlan_set_bit(TLAN_NET_SIO_EDATA, sio);
3166 tlan_set_bit(TLAN_NET_SIO_ETXEN, sio);
3167 tlan_clear_bit(TLAN_NET_SIO_EDATA, sio);
3168 tlan_clear_bit(TLAN_NET_SIO_ECLOK, sio);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003169
Sakari Ailusc659c382011-01-21 10:59:30 +00003170}
Linus Torvalds1da177e2005-04-16 15:20:36 -07003171
3172
3173
3174
Sakari Ailusc659c382011-01-21 10:59:30 +00003175/***************************************************************
3176 * tlan_ee_send_byte
3177 *
3178 * Returns:
3179 * If the correct ack was received, 0, otherwise 1
3180 * Parms: io_base The IO port base address for the
3181 * TLAN device with the EEPROM to
3182 * use.
3183 * data The 8 bits of information to
3184 * send to the EEPROM.
3185 * stop If TLAN_EEPROM_STOP is passed, a
3186 * stop cycle is sent after the
3187 * byte is sent after the ack is
3188 * read.
3189 *
3190 * This function sends a byte on the serial EEPROM line,
3191 * driving the clock to send each bit. The function then
3192 * reverses transmission direction and reads an acknowledge
3193 * bit.
3194 *
3195 **************************************************************/
Linus Torvalds1da177e2005-04-16 15:20:36 -07003196
Sakari Ailusc659c382011-01-21 10:59:30 +00003197static int tlan_ee_send_byte(u16 io_base, u8 data, int stop)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003198{
3199 int err;
3200 u8 place;
3201 u16 sio;
3202
Sakari Ailusc659c382011-01-21 10:59:30 +00003203 outw(TLAN_NET_SIO, io_base + TLAN_DIO_ADR);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003204 sio = io_base + TLAN_DIO_DATA + TLAN_NET_SIO;
3205
3206 /* Assume clock is low, tx is enabled; */
Sakari Ailusc659c382011-01-21 10:59:30 +00003207 for (place = 0x80; place != 0; place >>= 1) {
3208 if (place & data)
3209 tlan_set_bit(TLAN_NET_SIO_EDATA, sio);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003210 else
Sakari Ailusc659c382011-01-21 10:59:30 +00003211 tlan_clear_bit(TLAN_NET_SIO_EDATA, sio);
3212 tlan_set_bit(TLAN_NET_SIO_ECLOK, sio);
3213 tlan_clear_bit(TLAN_NET_SIO_ECLOK, sio);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003214 }
Sakari Ailusc659c382011-01-21 10:59:30 +00003215 tlan_clear_bit(TLAN_NET_SIO_ETXEN, sio);
3216 tlan_set_bit(TLAN_NET_SIO_ECLOK, sio);
3217 err = tlan_get_bit(TLAN_NET_SIO_EDATA, sio);
3218 tlan_clear_bit(TLAN_NET_SIO_ECLOK, sio);
3219 tlan_set_bit(TLAN_NET_SIO_ETXEN, sio);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003220
Sakari Ailusc659c382011-01-21 10:59:30 +00003221 if ((!err) && stop) {
Stephen Hemmingerdfc2c0a2008-05-30 09:49:58 -07003222 /* STOP, raise data while clock is high */
Sakari Ailusc659c382011-01-21 10:59:30 +00003223 tlan_clear_bit(TLAN_NET_SIO_EDATA, sio);
3224 tlan_set_bit(TLAN_NET_SIO_ECLOK, sio);
3225 tlan_set_bit(TLAN_NET_SIO_EDATA, sio);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003226 }
3227
Eric Dumazet807540b2010-09-23 05:40:09 +00003228 return err;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003229
Sakari Ailusc659c382011-01-21 10:59:30 +00003230}
Linus Torvalds1da177e2005-04-16 15:20:36 -07003231
3232
3233
3234
Sakari Ailusc659c382011-01-21 10:59:30 +00003235/***************************************************************
3236 * tlan_ee_receive_byte
3237 *
3238 * Returns:
3239 * Nothing
3240 * Parms:
3241 * io_base The IO port base address for the
3242 * TLAN device with the EEPROM to
3243 * use.
3244 * data An address to a char to hold the
3245 * data sent from the EEPROM.
3246 * stop If TLAN_EEPROM_STOP is passed, a
3247 * stop cycle is sent after the
3248 * byte is received, and no ack is
3249 * sent.
3250 *
3251 * This function receives 8 bits of data from the EEPROM
3252 * over the serial link. It then sends and ack bit, or no
3253 * ack and a stop bit. This function is used to retrieve
3254 * data after the address of a byte in the EEPROM has been
3255 * sent.
3256 *
3257 **************************************************************/
Linus Torvalds1da177e2005-04-16 15:20:36 -07003258
Sakari Ailusc659c382011-01-21 10:59:30 +00003259static void tlan_ee_receive_byte(u16 io_base, u8 *data, int stop)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003260{
3261 u8 place;
3262 u16 sio;
3263
Sakari Ailusc659c382011-01-21 10:59:30 +00003264 outw(TLAN_NET_SIO, io_base + TLAN_DIO_ADR);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003265 sio = io_base + TLAN_DIO_DATA + TLAN_NET_SIO;
3266 *data = 0;
3267
3268 /* Assume clock is low, tx is enabled; */
Sakari Ailusc659c382011-01-21 10:59:30 +00003269 tlan_clear_bit(TLAN_NET_SIO_ETXEN, sio);
3270 for (place = 0x80; place; place >>= 1) {
3271 tlan_set_bit(TLAN_NET_SIO_ECLOK, sio);
3272 if (tlan_get_bit(TLAN_NET_SIO_EDATA, sio))
Linus Torvalds1da177e2005-04-16 15:20:36 -07003273 *data |= place;
Sakari Ailusc659c382011-01-21 10:59:30 +00003274 tlan_clear_bit(TLAN_NET_SIO_ECLOK, sio);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003275 }
3276
Sakari Ailusc659c382011-01-21 10:59:30 +00003277 tlan_set_bit(TLAN_NET_SIO_ETXEN, sio);
3278 if (!stop) {
3279 tlan_clear_bit(TLAN_NET_SIO_EDATA, sio); /* ack = 0 */
3280 tlan_set_bit(TLAN_NET_SIO_ECLOK, sio);
3281 tlan_clear_bit(TLAN_NET_SIO_ECLOK, sio);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003282 } else {
Sakari Ailusc659c382011-01-21 10:59:30 +00003283 tlan_set_bit(TLAN_NET_SIO_EDATA, sio); /* no ack = 1 (?) */
3284 tlan_set_bit(TLAN_NET_SIO_ECLOK, sio);
3285 tlan_clear_bit(TLAN_NET_SIO_ECLOK, sio);
Stephen Hemmingerdfc2c0a2008-05-30 09:49:58 -07003286 /* STOP, raise data while clock is high */
Sakari Ailusc659c382011-01-21 10:59:30 +00003287 tlan_clear_bit(TLAN_NET_SIO_EDATA, sio);
3288 tlan_set_bit(TLAN_NET_SIO_ECLOK, sio);
3289 tlan_set_bit(TLAN_NET_SIO_EDATA, sio);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003290 }
3291
Sakari Ailusc659c382011-01-21 10:59:30 +00003292}
Linus Torvalds1da177e2005-04-16 15:20:36 -07003293
3294
3295
3296
Sakari Ailusc659c382011-01-21 10:59:30 +00003297/***************************************************************
3298 * tlan_ee_read_byte
3299 *
3300 * Returns:
3301 * No error = 0, else, the stage at which the error
3302 * occurred.
3303 * Parms:
3304 * io_base The IO port base address for the
3305 * TLAN device with the EEPROM to
3306 * use.
3307 * ee_addr The address of the byte in the
3308 * EEPROM whose contents are to be
3309 * retrieved.
3310 * data An address to a char to hold the
3311 * data obtained from the EEPROM.
3312 *
3313 * This function reads a byte of information from an byte
3314 * cell in the EEPROM.
3315 *
3316 **************************************************************/
Linus Torvalds1da177e2005-04-16 15:20:36 -07003317
Sakari Ailusc659c382011-01-21 10:59:30 +00003318static int tlan_ee_read_byte(struct net_device *dev, u8 ee_addr, u8 *data)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003319{
3320 int err;
Sakari Ailusc659c382011-01-21 10:59:30 +00003321 struct tlan_priv *priv = netdev_priv(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003322 unsigned long flags = 0;
Sakari Ailusc659c382011-01-21 10:59:30 +00003323 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003324
3325 spin_lock_irqsave(&priv->lock, flags);
3326
Sakari Ailusc659c382011-01-21 10:59:30 +00003327 tlan_ee_send_start(dev->base_addr);
3328 err = tlan_ee_send_byte(dev->base_addr, 0xa0, TLAN_EEPROM_ACK);
3329 if (err) {
3330 ret = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003331 goto fail;
3332 }
Sakari Ailusc659c382011-01-21 10:59:30 +00003333 err = tlan_ee_send_byte(dev->base_addr, ee_addr, TLAN_EEPROM_ACK);
3334 if (err) {
3335 ret = 2;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003336 goto fail;
3337 }
Sakari Ailusc659c382011-01-21 10:59:30 +00003338 tlan_ee_send_start(dev->base_addr);
3339 err = tlan_ee_send_byte(dev->base_addr, 0xa1, TLAN_EEPROM_ACK);
3340 if (err) {
3341 ret = 3;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003342 goto fail;
3343 }
Sakari Ailusc659c382011-01-21 10:59:30 +00003344 tlan_ee_receive_byte(dev->base_addr, data, TLAN_EEPROM_STOP);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003345fail:
3346 spin_unlock_irqrestore(&priv->lock, flags);
3347
3348 return ret;
3349
Sakari Ailusc659c382011-01-21 10:59:30 +00003350}
Linus Torvalds1da177e2005-04-16 15:20:36 -07003351
3352
3353