blob: c41d68761364550ebe2d2d8376f2a8c293b5d799 [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
66 * network cleanup in 2.3.43pre7 (Tigran & myself)
67 * - Minor stuff.
68 *
69 * v1.5 March 22, 2000 - Fixed another timer bug that would hang the driver
70 * if no cable/link were present.
71 * - Cosmetic changes.
72 * - TODO: Port completely to new PCI/DMA API
73 * Auto-Neg fallback.
74 *
75 * v1.6 April 04, 2000 - Fixed driver support for kernel-parameters. Haven't
Jeff Garzik6aa20a22006-09-13 13:24:59 -040076 * tested it though, as the kernel support is currently
Linus Torvalds1da177e2005-04-16 15:20:36 -070077 * broken (2.3.99p4p3).
78 * - Updated tlan.txt accordingly.
79 * - Adjusted minimum/maximum frame length.
Jeff Garzik6aa20a22006-09-13 13:24:59 -040080 * - There is now a TLAN website up at
Linus Torvalds1da177e2005-04-16 15:20:36 -070081 * http://tlan.kernel.dk
82 *
83 * v1.7 April 07, 2000 - Started to implement custom ioctls. Driver now
84 * reports PHY information when used with Donald
85 * Beckers userspace MII diagnostics utility.
86 *
87 * v1.8 April 23, 2000 - Fixed support for forced speed/duplex settings.
88 * - Added link information to Auto-Neg and forced
89 * modes. When NIC operates with auto-neg the driver
90 * will report Link speed & duplex modes as well as
91 * link partner abilities. When forced link is used,
92 * the driver will report status of the established
93 * link.
Jeff Garzik6aa20a22006-09-13 13:24:59 -040094 * Please read tlan.txt for additional information.
95 * - Removed call to check_region(), and used
Linus Torvalds1da177e2005-04-16 15:20:36 -070096 * 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.
101 * - Updated with timer fixes from Andrew Morton.
102 * - Fixed module race in TLan_Open.
103 * - Added routine to monitor PHY status.
104 * - Added activity led support for Proliant devices.
105 *
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.
Jeff Garzik6aa20a22006-09-13 13:24:59 -0400114 * - Fixed bug that would cause general debug information
115 * 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 *
139 * v1.13 Nov 28, 2000 - Stop flooding console with auto-neg issues
140 * when link can't be established.
141 * - Added the bbuf option as a kernel parameter.
142 * - Fixed ioaddr probe bug.
143 * - Fixed stupid deadlock with MII interrupts.
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 *
150 * v1.14 Dec 16, 2000 - Added support for servicing multiple frames per.
151 * interrupt. Thanks goes to
152 * Adam Keys <adam@ti.com>
153 * Denis Beaudoin <dbeaudoin@ti.com>
154 * for providing the patch.
155 * - Fixed auto-neg output when using multiple
156 * adapters.
157 * - Converted to use new taskq interface.
158 *
159 * v1.14a Jan 6, 2001 - Minor adjustments (spinlocks, etc.)
160 *
161 * Samuel Chessman <chessman@tux.org> New Maintainer!
162 *
163 * v1.15 Apr 4, 2002 - Correct operation when aui=1 to be
164 * 10T half duplex no loopback
165 * Thanks to Gunnar Eikman
166 *******************************************************************************/
167
168#include <linux/module.h>
169#include <linux/init.h>
170#include <linux/ioport.h>
171#include <linux/eisa.h>
172#include <linux/pci.h>
Domen Puncer1e7f0bd2005-06-26 18:22:14 -0400173#include <linux/dma-mapping.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -0700174#include <linux/netdevice.h>
175#include <linux/etherdevice.h>
176#include <linux/delay.h>
177#include <linux/spinlock.h>
178#include <linux/workqueue.h>
179#include <linux/mii.h>
180
181#include "tlan.h"
182
183typedef u32 (TLanIntVectorFunc)( struct net_device *, u16 );
184
185
186/* For removing EISA devices */
187static struct net_device *TLan_Eisa_Devices;
188
189static int TLanDevicesInstalled;
190
191/* Set speed, duplex and aui settings */
192static int aui[MAX_TLAN_BOARDS];
193static int duplex[MAX_TLAN_BOARDS];
194static int speed[MAX_TLAN_BOARDS];
195static int boards_found;
Stephen Hemminger15efa9b2005-05-04 15:33:11 -0700196module_param_array(aui, int, NULL, 0);
197module_param_array(duplex, int, NULL, 0);
198module_param_array(speed, int, NULL, 0);
199MODULE_PARM_DESC(aui, "ThunderLAN use AUI port(s) (0-1)");
200MODULE_PARM_DESC(duplex, "ThunderLAN duplex setting(s) (0-default, 1-half, 2-full)");
201MODULE_PARM_DESC(speed, "ThunderLAN port speen setting(s) (0,10,100)");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700202
203MODULE_AUTHOR("Maintainer: Samuel Chessman <chessman@tux.org>");
204MODULE_DESCRIPTION("Driver for TI ThunderLAN based ethernet PCI adapters");
205MODULE_LICENSE("GPL");
206
207
208/* Define this to enable Link beat monitoring */
209#undef MONITOR
210
211/* Turn on debugging. See Documentation/networking/tlan.txt for details */
212static int debug;
Stephen Hemminger15efa9b2005-05-04 15:33:11 -0700213module_param(debug, int, 0);
214MODULE_PARM_DESC(debug, "ThunderLAN debug mask");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700215
216static int bbuf;
Stephen Hemminger15efa9b2005-05-04 15:33:11 -0700217module_param(bbuf, int, 0);
218MODULE_PARM_DESC(bbuf, "ThunderLAN use big buffer (0-1)");
219
Stephen Hemmingera3ccc782008-05-30 09:49:57 -0700220static const char TLanSignature[] = "TLAN";
Linus Torvalds1da177e2005-04-16 15:20:36 -0700221static const char tlan_banner[] = "ThunderLAN driver v1.15\n";
222static int tlan_have_pci;
223static int tlan_have_eisa;
224
225static const char *media[] = {
Jeff Garzik6aa20a22006-09-13 13:24:59 -0400226 "10BaseT-HD ", "10BaseT-FD ","100baseTx-HD ",
Linus Torvalds1da177e2005-04-16 15:20:36 -0700227 "100baseTx-FD", "100baseT4", NULL
228};
229
230static struct board {
231 const char *deviceLabel;
232 u32 flags;
233 u16 addrOfs;
234} board_info[] = {
235 { "Compaq Netelligent 10 T PCI UTP", TLAN_ADAPTER_ACTIVITY_LED, 0x83 },
236 { "Compaq Netelligent 10/100 TX PCI UTP", TLAN_ADAPTER_ACTIVITY_LED, 0x83 },
237 { "Compaq Integrated NetFlex-3/P", TLAN_ADAPTER_NONE, 0x83 },
Stephen Hemmingerdfc2c0a2008-05-30 09:49:58 -0700238 { "Compaq NetFlex-3/P",
239 TLAN_ADAPTER_UNMANAGED_PHY | TLAN_ADAPTER_BIT_RATE_PHY, 0x83 },
Linus Torvalds1da177e2005-04-16 15:20:36 -0700240 { "Compaq NetFlex-3/P", TLAN_ADAPTER_NONE, 0x83 },
Stephen Hemmingerdfc2c0a2008-05-30 09:49:58 -0700241 { "Compaq Netelligent Integrated 10/100 TX UTP",
242 TLAN_ADAPTER_ACTIVITY_LED, 0x83 },
Linus Torvalds1da177e2005-04-16 15:20:36 -0700243 { "Compaq Netelligent Dual 10/100 TX PCI UTP", TLAN_ADAPTER_NONE, 0x83 },
244 { "Compaq Netelligent 10/100 TX Embedded UTP", TLAN_ADAPTER_NONE, 0x83 },
245 { "Olicom OC-2183/2185", TLAN_ADAPTER_USE_INTERN_10, 0x83 },
246 { "Olicom OC-2325", TLAN_ADAPTER_UNMANAGED_PHY, 0xF8 },
247 { "Olicom OC-2326", TLAN_ADAPTER_USE_INTERN_10, 0xF8 },
248 { "Compaq Netelligent 10/100 TX UTP", TLAN_ADAPTER_ACTIVITY_LED, 0x83 },
249 { "Compaq Netelligent 10 T/2 PCI UTP/Coax", TLAN_ADAPTER_NONE, 0x83 },
Stephen Hemmingerdfc2c0a2008-05-30 09:49:58 -0700250 { "Compaq NetFlex-3/E",
251 TLAN_ADAPTER_ACTIVITY_LED | /* EISA card */
252 TLAN_ADAPTER_UNMANAGED_PHY | TLAN_ADAPTER_BIT_RATE_PHY, 0x83 },
Linus Torvalds1da177e2005-04-16 15:20:36 -0700253 { "Compaq NetFlex-3/E", TLAN_ADAPTER_ACTIVITY_LED, 0x83 }, /* EISA card */
254};
255
256static struct pci_device_id tlan_pci_tbl[] = {
257 { PCI_VENDOR_ID_COMPAQ, PCI_DEVICE_ID_COMPAQ_NETEL10,
258 PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0 },
259 { PCI_VENDOR_ID_COMPAQ, PCI_DEVICE_ID_COMPAQ_NETEL100,
260 PCI_ANY_ID, PCI_ANY_ID, 0, 0, 1 },
261 { PCI_VENDOR_ID_COMPAQ, PCI_DEVICE_ID_COMPAQ_NETFLEX3I,
262 PCI_ANY_ID, PCI_ANY_ID, 0, 0, 2 },
263 { PCI_VENDOR_ID_COMPAQ, PCI_DEVICE_ID_COMPAQ_THUNDER,
264 PCI_ANY_ID, PCI_ANY_ID, 0, 0, 3 },
265 { PCI_VENDOR_ID_COMPAQ, PCI_DEVICE_ID_COMPAQ_NETFLEX3B,
266 PCI_ANY_ID, PCI_ANY_ID, 0, 0, 4 },
267 { PCI_VENDOR_ID_COMPAQ, PCI_DEVICE_ID_COMPAQ_NETEL100PI,
268 PCI_ANY_ID, PCI_ANY_ID, 0, 0, 5 },
269 { PCI_VENDOR_ID_COMPAQ, PCI_DEVICE_ID_COMPAQ_NETEL100D,
270 PCI_ANY_ID, PCI_ANY_ID, 0, 0, 6 },
271 { PCI_VENDOR_ID_COMPAQ, PCI_DEVICE_ID_COMPAQ_NETEL100I,
272 PCI_ANY_ID, PCI_ANY_ID, 0, 0, 7 },
273 { PCI_VENDOR_ID_OLICOM, PCI_DEVICE_ID_OLICOM_OC2183,
274 PCI_ANY_ID, PCI_ANY_ID, 0, 0, 8 },
275 { PCI_VENDOR_ID_OLICOM, PCI_DEVICE_ID_OLICOM_OC2325,
276 PCI_ANY_ID, PCI_ANY_ID, 0, 0, 9 },
277 { PCI_VENDOR_ID_OLICOM, PCI_DEVICE_ID_OLICOM_OC2326,
278 PCI_ANY_ID, PCI_ANY_ID, 0, 0, 10 },
279 { PCI_VENDOR_ID_COMPAQ, PCI_DEVICE_ID_NETELLIGENT_10_100_WS_5100,
280 PCI_ANY_ID, PCI_ANY_ID, 0, 0, 11 },
281 { PCI_VENDOR_ID_COMPAQ, PCI_DEVICE_ID_NETELLIGENT_10_T2,
282 PCI_ANY_ID, PCI_ANY_ID, 0, 0, 12 },
283 { 0,}
284};
Jeff Garzik6aa20a22006-09-13 13:24:59 -0400285MODULE_DEVICE_TABLE(pci, tlan_pci_tbl);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700286
287static void TLan_EisaProbe( void );
288static void TLan_Eisa_Cleanup( void );
289static int TLan_Init( struct net_device * );
290static int TLan_Open( struct net_device *dev );
291static int TLan_StartTx( struct sk_buff *, struct net_device *);
David Howells7d12e782006-10-05 14:55:46 +0100292static irqreturn_t TLan_HandleInterrupt( int, void *);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700293static int TLan_Close( struct net_device *);
294static struct net_device_stats *TLan_GetStats( struct net_device *);
295static void TLan_SetMulticastList( struct net_device *);
296static int TLan_ioctl( struct net_device *dev, struct ifreq *rq, int cmd);
Stephen Hemmingerdfc2c0a2008-05-30 09:49:58 -0700297static int TLan_probe1( struct pci_dev *pdev, long ioaddr,
298 int irq, int rev, const struct pci_device_id *ent);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700299static void TLan_tx_timeout( struct net_device *dev);
David Howellsc4028952006-11-22 14:57:56 +0000300static void TLan_tx_timeout_work(struct work_struct *work);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700301static int tlan_init_one( struct pci_dev *pdev, const struct pci_device_id *ent);
302
Linus Torvalds1da177e2005-04-16 15:20:36 -0700303static u32 TLan_HandleTxEOF( struct net_device *, u16 );
304static u32 TLan_HandleStatOverflow( struct net_device *, u16 );
305static u32 TLan_HandleRxEOF( struct net_device *, u16 );
306static u32 TLan_HandleDummy( struct net_device *, u16 );
307static u32 TLan_HandleTxEOC( struct net_device *, u16 );
308static u32 TLan_HandleStatusCheck( struct net_device *, u16 );
309static u32 TLan_HandleRxEOC( struct net_device *, u16 );
310
311static void TLan_Timer( unsigned long );
312
313static void TLan_ResetLists( struct net_device * );
314static void TLan_FreeLists( struct net_device * );
315static void TLan_PrintDio( u16 );
316static void TLan_PrintList( TLanList *, char *, int );
317static void TLan_ReadAndClearStats( struct net_device *, int );
318static void TLan_ResetAdapter( struct net_device * );
319static void TLan_FinishReset( struct net_device * );
320static void TLan_SetMac( struct net_device *, int areg, char *mac );
321
322static void TLan_PhyPrint( struct net_device * );
323static void TLan_PhyDetect( struct net_device * );
324static void TLan_PhyPowerDown( struct net_device * );
325static void TLan_PhyPowerUp( struct net_device * );
326static void TLan_PhyReset( struct net_device * );
327static void TLan_PhyStartLink( struct net_device * );
328static void TLan_PhyFinishAutoNeg( struct net_device * );
329#ifdef MONITOR
330static void TLan_PhyMonitor( struct net_device * );
331#endif
332
333/*
334static int TLan_PhyNop( struct net_device * );
335static int TLan_PhyInternalCheck( struct net_device * );
336static int TLan_PhyInternalService( struct net_device * );
337static int TLan_PhyDp83840aCheck( struct net_device * );
338*/
339
340static int TLan_MiiReadReg( struct net_device *, u16, u16, u16 * );
341static void TLan_MiiSendData( u16, u32, unsigned );
342static void TLan_MiiSync( u16 );
343static void TLan_MiiWriteReg( struct net_device *, u16, u16, u16 );
344
345static void TLan_EeSendStart( u16 );
346static int TLan_EeSendByte( u16, u8, int );
347static void TLan_EeReceiveByte( u16, u8 *, int );
348static int TLan_EeReadByte( struct net_device *, u8, u8 * );
349
350
Stephen Hemminger93e16842008-05-30 09:49:55 -0700351static inline void
Linus Torvalds1da177e2005-04-16 15:20:36 -0700352TLan_StoreSKB( struct tlan_list_tag *tag, struct sk_buff *skb)
353{
354 unsigned long addr = (unsigned long)skb;
Stephen Hemminger93e16842008-05-30 09:49:55 -0700355 tag->buffer[9].address = addr;
356 tag->buffer[8].address = upper_32_bits(addr);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700357}
358
Stephen Hemminger93e16842008-05-30 09:49:55 -0700359static inline struct sk_buff *
360TLan_GetSKB( const struct tlan_list_tag *tag)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700361{
Stephen Hemminger93e16842008-05-30 09:49:55 -0700362 unsigned long addr;
363
Robert Fitzsimons0d63bea2008-08-09 17:54:02 +0100364 addr = tag->buffer[9].address;
365 addr |= (tag->buffer[8].address << 16) << 16;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700366 return (struct sk_buff *) addr;
367}
368
369
370static TLanIntVectorFunc *TLanIntVector[TLAN_INT_NUMBER_OF_INTS] = {
Stephen Hemmingera3ccc782008-05-30 09:49:57 -0700371 NULL,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700372 TLan_HandleTxEOF,
373 TLan_HandleStatOverflow,
374 TLan_HandleRxEOF,
375 TLan_HandleDummy,
376 TLan_HandleTxEOC,
377 TLan_HandleStatusCheck,
378 TLan_HandleRxEOC
379};
380
381static inline void
382TLan_SetTimer( struct net_device *dev, u32 ticks, u32 type )
383{
384 TLanPrivateInfo *priv = netdev_priv(dev);
385 unsigned long flags = 0;
Jeff Garzik6aa20a22006-09-13 13:24:59 -0400386
Linus Torvalds1da177e2005-04-16 15:20:36 -0700387 if (!in_irq())
388 spin_lock_irqsave(&priv->lock, flags);
389 if ( priv->timer.function != NULL &&
Jeff Garzik6aa20a22006-09-13 13:24:59 -0400390 priv->timerType != TLAN_TIMER_ACTIVITY ) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700391 if (!in_irq())
392 spin_unlock_irqrestore(&priv->lock, flags);
393 return;
394 }
395 priv->timer.function = &TLan_Timer;
396 if (!in_irq())
397 spin_unlock_irqrestore(&priv->lock, flags);
398
399 priv->timer.data = (unsigned long) dev;
400 priv->timerSetAt = jiffies;
401 priv->timerType = type;
402 mod_timer(&priv->timer, jiffies + ticks);
Jeff Garzik6aa20a22006-09-13 13:24:59 -0400403
Linus Torvalds1da177e2005-04-16 15:20:36 -0700404} /* TLan_SetTimer */
405
406
407/*****************************************************************************
408******************************************************************************
409
410 ThunderLAN Driver Primary Functions
411
412 These functions are more or less common to all Linux network drivers.
413
414******************************************************************************
415*****************************************************************************/
416
417
418
419
420
421 /***************************************************************
422 * tlan_remove_one
423 *
424 * Returns:
425 * Nothing
426 * Parms:
427 * None
428 *
429 * Goes through the TLanDevices list and frees the device
430 * structs and memory associated with each device (lists
431 * and buffers). It also ureserves the IO port regions
432 * associated with this device.
433 *
434 **************************************************************/
435
436
437static void __devexit tlan_remove_one( struct pci_dev *pdev)
438{
439 struct net_device *dev = pci_get_drvdata( pdev );
440 TLanPrivateInfo *priv = netdev_priv(dev);
Jeff Garzik6aa20a22006-09-13 13:24:59 -0400441
Linus Torvalds1da177e2005-04-16 15:20:36 -0700442 unregister_netdev( dev );
443
444 if ( priv->dmaStorage ) {
Stephen Hemmingerdfc2c0a2008-05-30 09:49:58 -0700445 pci_free_consistent(priv->pciDev,
446 priv->dmaSize, priv->dmaStorage,
447 priv->dmaStorageDMA );
Linus Torvalds1da177e2005-04-16 15:20:36 -0700448 }
449
450#ifdef CONFIG_PCI
451 pci_release_regions(pdev);
452#endif
Jeff Garzik6aa20a22006-09-13 13:24:59 -0400453
Linus Torvalds1da177e2005-04-16 15:20:36 -0700454 free_netdev( dev );
Jeff Garzik6aa20a22006-09-13 13:24:59 -0400455
Linus Torvalds1da177e2005-04-16 15:20:36 -0700456 pci_set_drvdata( pdev, NULL );
Jeff Garzik6aa20a22006-09-13 13:24:59 -0400457}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700458
459static struct pci_driver tlan_driver = {
460 .name = "tlan",
461 .id_table = tlan_pci_tbl,
462 .probe = tlan_init_one,
Jeff Garzik6aa20a22006-09-13 13:24:59 -0400463 .remove = __devexit_p(tlan_remove_one),
Linus Torvalds1da177e2005-04-16 15:20:36 -0700464};
465
466static int __init tlan_probe(void)
467{
Leonardo Potenza6c04a512008-02-04 23:47:16 -0800468 int rc = -ENODEV;
Jeff Garzik6aa20a22006-09-13 13:24:59 -0400469
Linus Torvalds1da177e2005-04-16 15:20:36 -0700470 printk(KERN_INFO "%s", tlan_banner);
Jeff Garzik6aa20a22006-09-13 13:24:59 -0400471
Linus Torvalds1da177e2005-04-16 15:20:36 -0700472 TLAN_DBG(TLAN_DEBUG_PROBE, "Starting PCI Probe....\n");
Jeff Garzik6aa20a22006-09-13 13:24:59 -0400473
Linus Torvalds1da177e2005-04-16 15:20:36 -0700474 /* Use new style PCI probing. Now the kernel will
475 do most of this for us */
Leonardo Potenza6c04a512008-02-04 23:47:16 -0800476 rc = pci_register_driver(&tlan_driver);
477
478 if (rc != 0) {
479 printk(KERN_ERR "TLAN: Could not register pci driver.\n");
480 goto err_out_pci_free;
481 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700482
483 TLAN_DBG(TLAN_DEBUG_PROBE, "Starting EISA Probe....\n");
484 TLan_EisaProbe();
Jeff Garzik6aa20a22006-09-13 13:24:59 -0400485
486 printk(KERN_INFO "TLAN: %d device%s installed, PCI: %d EISA: %d\n",
Linus Torvalds1da177e2005-04-16 15:20:36 -0700487 TLanDevicesInstalled, TLanDevicesInstalled == 1 ? "" : "s",
488 tlan_have_pci, tlan_have_eisa);
489
490 if (TLanDevicesInstalled == 0) {
Leonardo Potenza6c04a512008-02-04 23:47:16 -0800491 rc = -ENODEV;
492 goto err_out_pci_unreg;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700493 }
494 return 0;
Leonardo Potenza6c04a512008-02-04 23:47:16 -0800495
496err_out_pci_unreg:
497 pci_unregister_driver(&tlan_driver);
498err_out_pci_free:
Leonardo Potenza6c04a512008-02-04 23:47:16 -0800499 return rc;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700500}
Jeff Garzik6aa20a22006-09-13 13:24:59 -0400501
Linus Torvalds1da177e2005-04-16 15:20:36 -0700502
503static int __devinit tlan_init_one( struct pci_dev *pdev,
504 const struct pci_device_id *ent)
505{
506 return TLan_probe1( pdev, -1, -1, 0, ent);
507}
508
509
510/*
511 ***************************************************************
512 * tlan_probe1
513 *
514 * Returns:
515 * 0 on success, error code on error
Jeff Garzik6aa20a22006-09-13 13:24:59 -0400516 * Parms:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700517 * none
518 *
519 * The name is lower case to fit in with all the rest of
Jeff Garzik6aa20a22006-09-13 13:24:59 -0400520 * the netcard_probe names. This function looks for
Linus Torvalds1da177e2005-04-16 15:20:36 -0700521 * another TLan based adapter, setting it up with the
522 * allocated device struct if one is found.
523 * tlan_probe has been ported to the new net API and
524 * now allocates its own device structure. This function
525 * is also used by modules.
526 *
527 **************************************************************/
528
Jeff Garzik6aa20a22006-09-13 13:24:59 -0400529static int __devinit TLan_probe1(struct pci_dev *pdev,
Stephen Hemmingerdfc2c0a2008-05-30 09:49:58 -0700530 long ioaddr, int irq, int rev,
531 const struct pci_device_id *ent )
Linus Torvalds1da177e2005-04-16 15:20:36 -0700532{
533
534 struct net_device *dev;
535 TLanPrivateInfo *priv;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700536 u16 device_id;
537 int reg, rc = -ENODEV;
538
Adrian Bunkad9f6712006-02-05 00:37:47 +0100539#ifdef CONFIG_PCI
Linus Torvalds1da177e2005-04-16 15:20:36 -0700540 if (pdev) {
541 rc = pci_enable_device(pdev);
542 if (rc)
543 return rc;
544
545 rc = pci_request_regions(pdev, TLanSignature);
546 if (rc) {
547 printk(KERN_ERR "TLAN: Could not reserve IO regions\n");
548 goto err_out;
549 }
550 }
Adrian Bunkad9f6712006-02-05 00:37:47 +0100551#endif /* CONFIG_PCI */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700552
553 dev = alloc_etherdev(sizeof(TLanPrivateInfo));
554 if (dev == NULL) {
555 printk(KERN_ERR "TLAN: Could not allocate memory for device.\n");
556 rc = -ENOMEM;
557 goto err_out_regions;
558 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700559 SET_NETDEV_DEV(dev, &pdev->dev);
Jeff Garzik6aa20a22006-09-13 13:24:59 -0400560
Linus Torvalds1da177e2005-04-16 15:20:36 -0700561 priv = netdev_priv(dev);
562
563 priv->pciDev = pdev;
David Howellsc4028952006-11-22 14:57:56 +0000564 priv->dev = dev;
Jeff Garzik6aa20a22006-09-13 13:24:59 -0400565
Linus Torvalds1da177e2005-04-16 15:20:36 -0700566 /* Is this a PCI device? */
567 if (pdev) {
568 u32 pci_io_base = 0;
569
570 priv->adapter = &board_info[ent->driver_data];
571
Domen Puncer1e7f0bd2005-06-26 18:22:14 -0400572 rc = pci_set_dma_mask(pdev, DMA_32BIT_MASK);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700573 if (rc) {
574 printk(KERN_ERR "TLAN: No suitable PCI mapping available.\n");
575 goto err_out_free_dev;
576 }
577
Linus Torvalds1da177e2005-04-16 15:20:36 -0700578 for ( reg= 0; reg <= 5; reg ++ ) {
579 if (pci_resource_flags(pdev, reg) & IORESOURCE_IO) {
580 pci_io_base = pci_resource_start(pdev, reg);
581 TLAN_DBG( TLAN_DEBUG_GNRL, "IO mapping is available at %x.\n",
582 pci_io_base);
583 break;
584 }
585 }
586 if (!pci_io_base) {
587 printk(KERN_ERR "TLAN: No IO mappings available\n");
588 rc = -EIO;
589 goto err_out_free_dev;
590 }
Jeff Garzik6aa20a22006-09-13 13:24:59 -0400591
Linus Torvalds1da177e2005-04-16 15:20:36 -0700592 dev->base_addr = pci_io_base;
593 dev->irq = pdev->irq;
Auke Kok44c10132007-06-08 15:46:36 -0700594 priv->adapterRev = pdev->revision;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700595 pci_set_master(pdev);
596 pci_set_drvdata(pdev, dev);
597
598 } else { /* EISA card */
599 /* This is a hack. We need to know which board structure
600 * is suited for this adapter */
601 device_id = inw(ioaddr + EISA_ID2);
602 priv->is_eisa = 1;
603 if (device_id == 0x20F1) {
604 priv->adapter = &board_info[13]; /* NetFlex-3/E */
605 priv->adapterRev = 23; /* TLAN 2.3 */
606 } else {
607 priv->adapter = &board_info[14];
608 priv->adapterRev = 10; /* TLAN 1.0 */
609 }
610 dev->base_addr = ioaddr;
611 dev->irq = irq;
612 }
613
614 /* Kernel parameters */
615 if (dev->mem_start) {
616 priv->aui = dev->mem_start & 0x01;
Stephen Hemmingerdfc2c0a2008-05-30 09:49:58 -0700617 priv->duplex = ((dev->mem_start & 0x06) == 0x06) ? 0
618 : (dev->mem_start & 0x06) >> 1;
619 priv->speed = ((dev->mem_start & 0x18) == 0x18) ? 0
620 : (dev->mem_start & 0x18) >> 3;
Jeff Garzik6aa20a22006-09-13 13:24:59 -0400621
Linus Torvalds1da177e2005-04-16 15:20:36 -0700622 if (priv->speed == 0x1) {
623 priv->speed = TLAN_SPEED_10;
624 } else if (priv->speed == 0x2) {
625 priv->speed = TLAN_SPEED_100;
626 }
627 debug = priv->debug = dev->mem_end;
628 } else {
629 priv->aui = aui[boards_found];
630 priv->speed = speed[boards_found];
631 priv->duplex = duplex[boards_found];
632 priv->debug = debug;
633 }
Jeff Garzik6aa20a22006-09-13 13:24:59 -0400634
Linus Torvalds1da177e2005-04-16 15:20:36 -0700635 /* This will be used when we get an adapter error from
636 * within our irq handler */
David Howellsc4028952006-11-22 14:57:56 +0000637 INIT_WORK(&priv->tlan_tqueue, TLan_tx_timeout_work);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700638
639 spin_lock_init(&priv->lock);
Jeff Garzik6aa20a22006-09-13 13:24:59 -0400640
Linus Torvalds1da177e2005-04-16 15:20:36 -0700641 rc = TLan_Init(dev);
642 if (rc) {
643 printk(KERN_ERR "TLAN: Could not set up device.\n");
644 goto err_out_free_dev;
645 }
646
647 rc = register_netdev(dev);
648 if (rc) {
649 printk(KERN_ERR "TLAN: Could not register device.\n");
650 goto err_out_uninit;
651 }
652
Jeff Garzik6aa20a22006-09-13 13:24:59 -0400653
Linus Torvalds1da177e2005-04-16 15:20:36 -0700654 TLanDevicesInstalled++;
655 boards_found++;
Jeff Garzik6aa20a22006-09-13 13:24:59 -0400656
Linus Torvalds1da177e2005-04-16 15:20:36 -0700657 /* pdev is NULL if this is an EISA device */
658 if (pdev)
659 tlan_have_pci++;
660 else {
661 priv->nextDevice = TLan_Eisa_Devices;
662 TLan_Eisa_Devices = dev;
663 tlan_have_eisa++;
664 }
Jeff Garzik6aa20a22006-09-13 13:24:59 -0400665
Linus Torvalds1da177e2005-04-16 15:20:36 -0700666 printk(KERN_INFO "TLAN: %s irq=%2d, io=%04x, %s, Rev. %d\n",
667 dev->name,
668 (int) dev->irq,
669 (int) dev->base_addr,
670 priv->adapter->deviceLabel,
671 priv->adapterRev);
672 return 0;
673
674err_out_uninit:
675 pci_free_consistent(priv->pciDev, priv->dmaSize, priv->dmaStorage,
676 priv->dmaStorageDMA );
677err_out_free_dev:
678 free_netdev(dev);
679err_out_regions:
680#ifdef CONFIG_PCI
681 if (pdev)
682 pci_release_regions(pdev);
683#endif
684err_out:
685 if (pdev)
686 pci_disable_device(pdev);
687 return rc;
688}
689
690
691static void TLan_Eisa_Cleanup(void)
692{
693 struct net_device *dev;
694 TLanPrivateInfo *priv;
Jeff Garzik6aa20a22006-09-13 13:24:59 -0400695
Linus Torvalds1da177e2005-04-16 15:20:36 -0700696 while( tlan_have_eisa ) {
697 dev = TLan_Eisa_Devices;
698 priv = netdev_priv(dev);
699 if (priv->dmaStorage) {
Stephen Hemmingerdfc2c0a2008-05-30 09:49:58 -0700700 pci_free_consistent(priv->pciDev, priv->dmaSize,
701 priv->dmaStorage, priv->dmaStorageDMA );
Linus Torvalds1da177e2005-04-16 15:20:36 -0700702 }
703 release_region( dev->base_addr, 0x10);
704 unregister_netdev( dev );
705 TLan_Eisa_Devices = priv->nextDevice;
706 free_netdev( dev );
707 tlan_have_eisa--;
708 }
709}
Jeff Garzik6aa20a22006-09-13 13:24:59 -0400710
711
Linus Torvalds1da177e2005-04-16 15:20:36 -0700712static void __exit tlan_exit(void)
713{
714 pci_unregister_driver(&tlan_driver);
715
716 if (tlan_have_eisa)
717 TLan_Eisa_Cleanup();
718
Linus Torvalds1da177e2005-04-16 15:20:36 -0700719}
720
721
722/* Module loading/unloading */
723module_init(tlan_probe);
724module_exit(tlan_exit);
725
726
727
728 /**************************************************************
729 * TLan_EisaProbe
730 *
731 * Returns: 0 on success, 1 otherwise
732 *
733 * Parms: None
734 *
735 *
Jeff Garzik6aa20a22006-09-13 13:24:59 -0400736 * This functions probes for EISA devices and calls
737 * TLan_probe1 when one is found.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700738 *
739 *************************************************************/
740
Jeff Garzik6aa20a22006-09-13 13:24:59 -0400741static void __init TLan_EisaProbe (void)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700742{
743 long ioaddr;
744 int rc = -ENODEV;
745 int irq;
746 u16 device_id;
747
Jeff Garzik6aa20a22006-09-13 13:24:59 -0400748 if (!EISA_bus) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700749 TLAN_DBG(TLAN_DEBUG_PROBE, "No EISA bus present\n");
750 return;
751 }
Jeff Garzik6aa20a22006-09-13 13:24:59 -0400752
Linus Torvalds1da177e2005-04-16 15:20:36 -0700753 /* Loop through all slots of the EISA bus */
754 for (ioaddr = 0x1000; ioaddr < 0x9000; ioaddr += 0x1000) {
Jeff Garzik6aa20a22006-09-13 13:24:59 -0400755
Stephen Hemmingerdfc2c0a2008-05-30 09:49:58 -0700756 TLAN_DBG(TLAN_DEBUG_PROBE,"EISA_ID 0x%4x: 0x%4x\n",
757 (int) ioaddr + 0xC80, inw(ioaddr + EISA_ID));
758 TLAN_DBG(TLAN_DEBUG_PROBE,"EISA_ID 0x%4x: 0x%4x\n",
759 (int) ioaddr + 0xC82, inw(ioaddr + EISA_ID2));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700760
761
762 TLAN_DBG(TLAN_DEBUG_PROBE, "Probing for EISA adapter at IO: 0x%4x : ",
763 (int) ioaddr);
Jeff Garzik6aa20a22006-09-13 13:24:59 -0400764 if (request_region(ioaddr, 0x10, TLanSignature) == NULL)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700765 goto out;
766
Jeff Garzik6aa20a22006-09-13 13:24:59 -0400767 if (inw(ioaddr + EISA_ID) != 0x110E) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700768 release_region(ioaddr, 0x10);
769 goto out;
770 }
Jeff Garzik6aa20a22006-09-13 13:24:59 -0400771
Linus Torvalds1da177e2005-04-16 15:20:36 -0700772 device_id = inw(ioaddr + EISA_ID2);
Jeff Garzik6aa20a22006-09-13 13:24:59 -0400773 if (device_id != 0x20F1 && device_id != 0x40F1) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700774 release_region (ioaddr, 0x10);
775 goto out;
776 }
Jeff Garzik6aa20a22006-09-13 13:24:59 -0400777
Linus Torvalds1da177e2005-04-16 15:20:36 -0700778 if (inb(ioaddr + EISA_CR) != 0x1) { /* Check if adapter is enabled */
779 release_region (ioaddr, 0x10);
780 goto out2;
781 }
Jeff Garzik6aa20a22006-09-13 13:24:59 -0400782
783 if (debug == 0x10)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700784 printk("Found one\n");
785
786
787 /* Get irq from board */
788 switch (inb(ioaddr + 0xCC0)) {
789 case(0x10):
790 irq=5;
791 break;
792 case(0x20):
793 irq=9;
794 break;
795 case(0x40):
796 irq=10;
797 break;
798 case(0x80):
799 irq=11;
800 break;
801 default:
802 goto out;
Jeff Garzik6aa20a22006-09-13 13:24:59 -0400803 }
804
805
Linus Torvalds1da177e2005-04-16 15:20:36 -0700806 /* Setup the newly found eisa adapter */
807 rc = TLan_probe1( NULL, ioaddr, irq,
808 12, NULL);
809 continue;
Jeff Garzik6aa20a22006-09-13 13:24:59 -0400810
Linus Torvalds1da177e2005-04-16 15:20:36 -0700811 out:
812 if (debug == 0x10)
813 printk("None found\n");
814 continue;
815
816 out2: if (debug == 0x10)
817 printk("Card found but it is not enabled, skipping\n");
818 continue;
Jeff Garzik6aa20a22006-09-13 13:24:59 -0400819
Linus Torvalds1da177e2005-04-16 15:20:36 -0700820 }
821
822} /* TLan_EisaProbe */
823
824#ifdef CONFIG_NET_POLL_CONTROLLER
825static void TLan_Poll(struct net_device *dev)
826{
827 disable_irq(dev->irq);
David Howells7d12e782006-10-05 14:55:46 +0100828 TLan_HandleInterrupt(dev->irq, dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700829 enable_irq(dev->irq);
830}
831#endif
832
Jeff Garzik6aa20a22006-09-13 13:24:59 -0400833
Linus Torvalds1da177e2005-04-16 15:20:36 -0700834
835
836 /***************************************************************
837 * TLan_Init
838 *
839 * Returns:
840 * 0 on success, error code otherwise.
841 * Parms:
842 * dev The structure of the device to be
843 * init'ed.
844 *
845 * This function completes the initialization of the
846 * device structure and driver. It reserves the IO
847 * addresses, allocates memory for the lists and bounce
848 * buffers, retrieves the MAC address from the eeprom
849 * and assignes the device's methods.
Jeff Garzik6aa20a22006-09-13 13:24:59 -0400850 *
Linus Torvalds1da177e2005-04-16 15:20:36 -0700851 **************************************************************/
852
853static int TLan_Init( struct net_device *dev )
854{
855 int dma_size;
856 int err;
857 int i;
858 TLanPrivateInfo *priv;
859
860 priv = netdev_priv(dev);
Jeff Garzik6aa20a22006-09-13 13:24:59 -0400861
Linus Torvalds1da177e2005-04-16 15:20:36 -0700862 if ( bbuf ) {
863 dma_size = ( TLAN_NUM_RX_LISTS + TLAN_NUM_TX_LISTS )
864 * ( sizeof(TLanList) + TLAN_MAX_FRAME_SIZE );
865 } else {
866 dma_size = ( TLAN_NUM_RX_LISTS + TLAN_NUM_TX_LISTS )
867 * ( sizeof(TLanList) );
868 }
Stephen Hemminger93e16842008-05-30 09:49:55 -0700869 priv->dmaStorage = pci_alloc_consistent(priv->pciDev,
870 dma_size, &priv->dmaStorageDMA);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700871 priv->dmaSize = dma_size;
Jeff Garzik6aa20a22006-09-13 13:24:59 -0400872
Linus Torvalds1da177e2005-04-16 15:20:36 -0700873 if ( priv->dmaStorage == NULL ) {
874 printk(KERN_ERR "TLAN: Could not allocate lists and buffers for %s.\n",
875 dev->name );
876 return -ENOMEM;
877 }
878 memset( priv->dmaStorage, 0, dma_size );
Stephen Hemminger93e16842008-05-30 09:49:55 -0700879 priv->rxList = (TLanList *) ALIGN((unsigned long)priv->dmaStorage, 8);
880 priv->rxListDMA = ALIGN(priv->dmaStorageDMA, 8);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700881 priv->txList = priv->rxList + TLAN_NUM_RX_LISTS;
882 priv->txListDMA = priv->rxListDMA + sizeof(TLanList) * TLAN_NUM_RX_LISTS;
Stephen Hemminger93e16842008-05-30 09:49:55 -0700883
Linus Torvalds1da177e2005-04-16 15:20:36 -0700884 if ( bbuf ) {
885 priv->rxBuffer = (u8 *) ( priv->txList + TLAN_NUM_TX_LISTS );
Stephen Hemmingerdfc2c0a2008-05-30 09:49:58 -0700886 priv->rxBufferDMA =priv->txListDMA
887 + sizeof(TLanList) * TLAN_NUM_TX_LISTS;
888 priv->txBuffer = priv->rxBuffer
889 + ( TLAN_NUM_RX_LISTS * TLAN_MAX_FRAME_SIZE );
890 priv->txBufferDMA = priv->rxBufferDMA
891 + ( TLAN_NUM_RX_LISTS * TLAN_MAX_FRAME_SIZE );
Linus Torvalds1da177e2005-04-16 15:20:36 -0700892 }
893
894 err = 0;
895 for ( i = 0; i < 6 ; i++ )
896 err |= TLan_EeReadByte( dev,
897 (u8) priv->adapter->addrOfs + i,
898 (u8 *) &dev->dev_addr[i] );
899 if ( err ) {
900 printk(KERN_ERR "TLAN: %s: Error reading MAC from eeprom: %d\n",
901 dev->name,
902 err );
903 }
904 dev->addr_len = 6;
905
906 netif_carrier_off(dev);
907
908 /* Device methods */
909 dev->open = &TLan_Open;
910 dev->hard_start_xmit = &TLan_StartTx;
911 dev->stop = &TLan_Close;
912 dev->get_stats = &TLan_GetStats;
913 dev->set_multicast_list = &TLan_SetMulticastList;
914 dev->do_ioctl = &TLan_ioctl;
915#ifdef CONFIG_NET_POLL_CONTROLLER
916 dev->poll_controller = &TLan_Poll;
917#endif
918 dev->tx_timeout = &TLan_tx_timeout;
919 dev->watchdog_timeo = TX_TIMEOUT;
920
921 return 0;
922
923} /* TLan_Init */
924
925
926
927
928 /***************************************************************
929 * TLan_Open
930 *
931 * Returns:
932 * 0 on success, error code otherwise.
933 * Parms:
934 * dev Structure of device to be opened.
935 *
936 * This routine puts the driver and TLAN adapter in a
937 * state where it is ready to send and receive packets.
938 * It allocates the IRQ, resets and brings the adapter
939 * out of reset, and allows interrupts. It also delays
940 * the startup for autonegotiation or sends a Rx GO
941 * command to the adapter, as appropriate.
942 *
943 **************************************************************/
944
945static int TLan_Open( struct net_device *dev )
946{
947 TLanPrivateInfo *priv = netdev_priv(dev);
948 int err;
Jeff Garzik6aa20a22006-09-13 13:24:59 -0400949
Linus Torvalds1da177e2005-04-16 15:20:36 -0700950 priv->tlanRev = TLan_DioRead8( dev->base_addr, TLAN_DEF_REVISION );
Stephen Hemmingera3ccc782008-05-30 09:49:57 -0700951 err = request_irq( dev->irq, TLan_HandleInterrupt, IRQF_SHARED,
952 dev->name, dev );
Jeff Garzik6aa20a22006-09-13 13:24:59 -0400953
Linus Torvalds1da177e2005-04-16 15:20:36 -0700954 if ( err ) {
Stephen Hemmingerdfc2c0a2008-05-30 09:49:58 -0700955 pr_err("TLAN: Cannot open %s because IRQ %d is already in use.\n",
956 dev->name, dev->irq );
Linus Torvalds1da177e2005-04-16 15:20:36 -0700957 return err;
958 }
Jeff Garzik6aa20a22006-09-13 13:24:59 -0400959
Linus Torvalds1da177e2005-04-16 15:20:36 -0700960 init_timer(&priv->timer);
961 netif_start_queue(dev);
Jeff Garzik6aa20a22006-09-13 13:24:59 -0400962
Linus Torvalds1da177e2005-04-16 15:20:36 -0700963 /* NOTE: It might not be necessary to read the stats before a
964 reset if you don't care what the values are.
965 */
966 TLan_ResetLists( dev );
967 TLan_ReadAndClearStats( dev, TLAN_IGNORE );
968 TLan_ResetAdapter( dev );
969
Stephen Hemmingerdfc2c0a2008-05-30 09:49:58 -0700970 TLAN_DBG( TLAN_DEBUG_GNRL, "%s: Opened. TLAN Chip Rev: %x\n",
971 dev->name, priv->tlanRev );
Linus Torvalds1da177e2005-04-16 15:20:36 -0700972
973 return 0;
974
975} /* TLan_Open */
976
977
978
979 /**************************************************************
980 * TLan_ioctl
Jeff Garzik6aa20a22006-09-13 13:24:59 -0400981 *
Linus Torvalds1da177e2005-04-16 15:20:36 -0700982 * Returns:
983 * 0 on success, error code otherwise
984 * Params:
985 * dev structure of device to receive ioctl.
Jeff Garzik6aa20a22006-09-13 13:24:59 -0400986 *
Linus Torvalds1da177e2005-04-16 15:20:36 -0700987 * rq ifreq structure to hold userspace data.
988 *
989 * cmd ioctl command.
990 *
991 *
992 *************************************************************/
993
994static int TLan_ioctl(struct net_device *dev, struct ifreq *rq, int cmd)
995{
996 TLanPrivateInfo *priv = netdev_priv(dev);
997 struct mii_ioctl_data *data = if_mii(rq);
998 u32 phy = priv->phy[priv->phyNum];
Jeff Garzik6aa20a22006-09-13 13:24:59 -0400999
Linus Torvalds1da177e2005-04-16 15:20:36 -07001000 if (!priv->phyOnline)
1001 return -EAGAIN;
1002
1003 switch(cmd) {
1004 case SIOCGMIIPHY: /* Get address of MII PHY in use. */
1005 data->phy_id = phy;
1006
1007
1008 case SIOCGMIIREG: /* Read MII PHY register. */
Stephen Hemmingerdfc2c0a2008-05-30 09:49:58 -07001009 TLan_MiiReadReg(dev, data->phy_id & 0x1f,
1010 data->reg_num & 0x1f, &data->val_out);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001011 return 0;
Jeff Garzik6aa20a22006-09-13 13:24:59 -04001012
Linus Torvalds1da177e2005-04-16 15:20:36 -07001013
1014 case SIOCSMIIREG: /* Write MII PHY register. */
1015 if (!capable(CAP_NET_ADMIN))
1016 return -EPERM;
Stephen Hemmingerdfc2c0a2008-05-30 09:49:58 -07001017 TLan_MiiWriteReg(dev, data->phy_id & 0x1f,
1018 data->reg_num & 0x1f, data->val_in);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001019 return 0;
1020 default:
1021 return -EOPNOTSUPP;
1022 }
1023} /* tlan_ioctl */
1024
1025
1026 /***************************************************************
1027 * TLan_tx_timeout
1028 *
1029 * Returns: nothing
1030 *
1031 * Params:
Jeff Garzik6aa20a22006-09-13 13:24:59 -04001032 * dev structure of device which timed out
Linus Torvalds1da177e2005-04-16 15:20:36 -07001033 * during transmit.
1034 *
1035 **************************************************************/
1036
1037static void TLan_tx_timeout(struct net_device *dev)
1038{
Jeff Garzik6aa20a22006-09-13 13:24:59 -04001039
Linus Torvalds1da177e2005-04-16 15:20:36 -07001040 TLAN_DBG( TLAN_DEBUG_GNRL, "%s: Transmit timed out.\n", dev->name);
Jeff Garzik6aa20a22006-09-13 13:24:59 -04001041
Linus Torvalds1da177e2005-04-16 15:20:36 -07001042 /* Ok so we timed out, lets see what we can do about it...*/
1043 TLan_FreeLists( dev );
Jeff Garzik6aa20a22006-09-13 13:24:59 -04001044 TLan_ResetLists( dev );
Linus Torvalds1da177e2005-04-16 15:20:36 -07001045 TLan_ReadAndClearStats( dev, TLAN_IGNORE );
1046 TLan_ResetAdapter( dev );
1047 dev->trans_start = jiffies;
Jeff Garzik6aa20a22006-09-13 13:24:59 -04001048 netif_wake_queue( dev );
Linus Torvalds1da177e2005-04-16 15:20:36 -07001049
1050}
Jeff Garzik6aa20a22006-09-13 13:24:59 -04001051
Linus Torvalds1da177e2005-04-16 15:20:36 -07001052
David Howellsc4028952006-11-22 14:57:56 +00001053 /***************************************************************
1054 * TLan_tx_timeout_work
1055 *
1056 * Returns: nothing
1057 *
1058 * Params:
1059 * work work item of device which timed out
1060 *
1061 **************************************************************/
1062
1063static void TLan_tx_timeout_work(struct work_struct *work)
1064{
1065 TLanPrivateInfo *priv =
1066 container_of(work, TLanPrivateInfo, tlan_tqueue);
1067
1068 TLan_tx_timeout(priv->dev);
1069}
1070
1071
Linus Torvalds1da177e2005-04-16 15:20:36 -07001072
1073 /***************************************************************
1074 * TLan_StartTx
Jeff Garzik6aa20a22006-09-13 13:24:59 -04001075 *
Linus Torvalds1da177e2005-04-16 15:20:36 -07001076 * Returns:
1077 * 0 on success, non-zero on failure.
1078 * Parms:
1079 * skb A pointer to the sk_buff containing the
1080 * frame to be sent.
1081 * dev The device to send the data on.
1082 *
1083 * This function adds a frame to the Tx list to be sent
1084 * ASAP. First it verifies that the adapter is ready and
1085 * there is room in the queue. Then it sets up the next
1086 * available list, copies the frame to the corresponding
1087 * buffer. If the adapter Tx channel is idle, it gives
1088 * the adapter a Tx Go command on the list, otherwise it
1089 * sets the forward address of the previous list to point
1090 * to this one. Then it frees the sk_buff.
1091 *
1092 **************************************************************/
1093
1094static int TLan_StartTx( struct sk_buff *skb, struct net_device *dev )
1095{
1096 TLanPrivateInfo *priv = netdev_priv(dev);
1097 TLanList *tail_list;
1098 dma_addr_t tail_list_phys;
1099 u8 *tail_buffer;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001100 unsigned long flags;
1101
1102 if ( ! priv->phyOnline ) {
Stephen Hemmingerdfc2c0a2008-05-30 09:49:58 -07001103 TLAN_DBG( TLAN_DEBUG_TX, "TRANSMIT: %s PHY is not ready\n",
1104 dev->name );
Linus Torvalds1da177e2005-04-16 15:20:36 -07001105 dev_kfree_skb_any(skb);
1106 return 0;
1107 }
1108
Stephen Hemminger41873e92008-05-30 09:49:52 -07001109 if (skb_padto(skb, TLAN_MIN_FRAME_SIZE))
1110 return 0;
1111
Linus Torvalds1da177e2005-04-16 15:20:36 -07001112 tail_list = priv->txList + priv->txTail;
1113 tail_list_phys = priv->txListDMA + sizeof(TLanList) * priv->txTail;
Jeff Garzik6aa20a22006-09-13 13:24:59 -04001114
Linus Torvalds1da177e2005-04-16 15:20:36 -07001115 if ( tail_list->cStat != TLAN_CSTAT_UNUSED ) {
Stephen Hemmingerdfc2c0a2008-05-30 09:49:58 -07001116 TLAN_DBG( TLAN_DEBUG_TX,
1117 "TRANSMIT: %s is busy (Head=%d Tail=%d)\n",
1118 dev->name, priv->txHead, priv->txTail );
Linus Torvalds1da177e2005-04-16 15:20:36 -07001119 netif_stop_queue(dev);
1120 priv->txBusyCount++;
1121 return 1;
1122 }
1123
1124 tail_list->forward = 0;
1125
1126 if ( bbuf ) {
1127 tail_buffer = priv->txBuffer + ( priv->txTail * TLAN_MAX_FRAME_SIZE );
Arnaldo Carvalho de Melod626f622007-03-27 18:55:52 -03001128 skb_copy_from_linear_data(skb, tail_buffer, skb->len);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001129 } else {
Stephen Hemmingerdfc2c0a2008-05-30 09:49:58 -07001130 tail_list->buffer[0].address = pci_map_single(priv->pciDev,
1131 skb->data, skb->len,
1132 PCI_DMA_TODEVICE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001133 TLan_StoreSKB(tail_list, skb);
1134 }
1135
Stephen Hemminger41873e92008-05-30 09:49:52 -07001136 tail_list->frameSize = (u16) skb->len;
1137 tail_list->buffer[0].count = TLAN_LAST_BUFFER | (u32) skb->len;
1138 tail_list->buffer[1].count = 0;
1139 tail_list->buffer[1].address = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001140
1141 spin_lock_irqsave(&priv->lock, flags);
1142 tail_list->cStat = TLAN_CSTAT_READY;
1143 if ( ! priv->txInProgress ) {
1144 priv->txInProgress = 1;
Stephen Hemmingerdfc2c0a2008-05-30 09:49:58 -07001145 TLAN_DBG( TLAN_DEBUG_TX,
1146 "TRANSMIT: Starting TX on buffer %d\n", priv->txTail );
Linus Torvalds1da177e2005-04-16 15:20:36 -07001147 outl( tail_list_phys, dev->base_addr + TLAN_CH_PARM );
1148 outl( TLAN_HC_GO, dev->base_addr + TLAN_HOST_CMD );
1149 } else {
Stephen Hemmingerdfc2c0a2008-05-30 09:49:58 -07001150 TLAN_DBG( TLAN_DEBUG_TX, "TRANSMIT: Adding buffer %d to TX channel\n",
1151 priv->txTail );
Linus Torvalds1da177e2005-04-16 15:20:36 -07001152 if ( priv->txTail == 0 ) {
Stephen Hemmingerdfc2c0a2008-05-30 09:49:58 -07001153 ( priv->txList + ( TLAN_NUM_TX_LISTS - 1 ) )->forward
1154 = tail_list_phys;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001155 } else {
Stephen Hemmingerdfc2c0a2008-05-30 09:49:58 -07001156 ( priv->txList + ( priv->txTail - 1 ) )->forward
1157 = tail_list_phys;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001158 }
1159 }
1160 spin_unlock_irqrestore(&priv->lock, flags);
1161
1162 CIRC_INC( priv->txTail, TLAN_NUM_TX_LISTS );
1163
1164 if ( bbuf )
1165 dev_kfree_skb_any(skb);
Jeff Garzik6aa20a22006-09-13 13:24:59 -04001166
Linus Torvalds1da177e2005-04-16 15:20:36 -07001167 dev->trans_start = jiffies;
1168 return 0;
1169
1170} /* TLan_StartTx */
1171
1172
1173
1174
1175 /***************************************************************
1176 * TLan_HandleInterrupt
Jeff Garzik6aa20a22006-09-13 13:24:59 -04001177 *
1178 * Returns:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001179 * 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.
Linus Torvalds1da177e2005-04-16 15:20:36 -07001185 *
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 **************************************************************/
1194
David Howells7d12e782006-10-05 14:55:46 +01001195static irqreturn_t TLan_HandleInterrupt(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;
1198 TLanPrivateInfo *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
1204 host_int = inw( dev->base_addr + TLAN_HOST_INT );
Linus Torvalds1da177e2005-04-16 15:20:36 -07001205 type = ( host_int & TLAN_HI_IT_MASK ) >> 2;
Stephen Hemmingera3ccc782008-05-30 09:49:57 -07001206 if ( type ) {
1207 u32 ack;
1208 u32 host_cmd;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001209
Stephen Hemmingera3ccc782008-05-30 09:49:57 -07001210 outw( host_int, dev->base_addr + TLAN_HOST_INT );
1211 ack = TLanIntVector[type]( dev, host_int );
Linus Torvalds1da177e2005-04-16 15:20:36 -07001212
Stephen Hemmingera3ccc782008-05-30 09:49:57 -07001213 if ( ack ) {
1214 host_cmd = TLAN_HC_ACK | ack | ( type << 18 );
1215 outl( host_cmd, dev->base_addr + TLAN_HOST_CMD );
1216 }
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);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001222} /* TLan_HandleInterrupts */
1223
1224
1225
1226
1227 /***************************************************************
1228 * TLan_Close
Jeff Garzik6aa20a22006-09-13 13:24:59 -04001229 *
Linus Torvalds1da177e2005-04-16 15:20:36 -07001230 * 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 **************************************************************/
1241
1242static int TLan_Close(struct net_device *dev)
1243{
1244 TLanPrivateInfo *priv = netdev_priv(dev);
1245
1246 netif_stop_queue(dev);
1247 priv->neg_be_verbose = 0;
1248
1249 TLan_ReadAndClearStats( dev, TLAN_RECORD );
1250 outl( TLAN_HC_AD_RST, dev->base_addr + TLAN_HOST_CMD );
1251 if ( priv->timer.function != NULL ) {
1252 del_timer_sync( &priv->timer );
1253 priv->timer.function = NULL;
1254 }
Jeff Garzik6aa20a22006-09-13 13:24:59 -04001255
Linus Torvalds1da177e2005-04-16 15:20:36 -07001256 free_irq( dev->irq, dev );
1257 TLan_FreeLists( dev );
1258 TLAN_DBG( TLAN_DEBUG_GNRL, "Device %s closed.\n", dev->name );
1259
1260 return 0;
1261
1262} /* TLan_Close */
1263
1264
1265
1266
1267 /***************************************************************
1268 * TLan_GetStats
Jeff Garzik6aa20a22006-09-13 13:24:59 -04001269 *
Linus Torvalds1da177e2005-04-16 15:20:36 -07001270 * 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 **************************************************************/
1281
1282static struct net_device_stats *TLan_GetStats( struct net_device *dev )
1283{
1284 TLanPrivateInfo *priv = netdev_priv(dev);
1285 int i;
1286
1287 /* Should only read stats if open ? */
1288 TLan_ReadAndClearStats( dev, TLAN_RECORD );
1289
Stephen Hemmingerdfc2c0a2008-05-30 09:49:58 -07001290 TLAN_DBG( TLAN_DEBUG_RX, "RECEIVE: %s EOC count = %d\n", dev->name,
1291 priv->rxEocCount );
1292 TLAN_DBG( TLAN_DEBUG_TX, "TRANSMIT: %s Busy count = %d\n", dev->name,
1293 priv->txBusyCount );
Linus Torvalds1da177e2005-04-16 15:20:36 -07001294 if ( debug & TLAN_DEBUG_GNRL ) {
1295 TLan_PrintDio( dev->base_addr );
Jeff Garzik6aa20a22006-09-13 13:24:59 -04001296 TLan_PhyPrint( dev );
Linus Torvalds1da177e2005-04-16 15:20:36 -07001297 }
1298 if ( debug & TLAN_DEBUG_LIST ) {
1299 for ( i = 0; i < TLAN_NUM_RX_LISTS; i++ )
1300 TLan_PrintList( priv->rxList + i, "RX", i );
1301 for ( i = 0; i < TLAN_NUM_TX_LISTS; i++ )
1302 TLan_PrintList( priv->txList + i, "TX", i );
1303 }
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
1307} /* TLan_GetStats */
1308
1309
1310
1311
1312 /***************************************************************
1313 * TLan_SetMulticastList
Jeff Garzik6aa20a22006-09-13 13:24:59 -04001314 *
Linus Torvalds1da177e2005-04-16 15:20:36 -07001315 * 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 **************************************************************/
1331
1332static void TLan_SetMulticastList( struct net_device *dev )
Jeff Garzik6aa20a22006-09-13 13:24:59 -04001333{
Linus Torvalds1da177e2005-04-16 15:20:36 -07001334 struct dev_mc_list *dmi = dev->mc_list;
1335 u32 hash1 = 0;
1336 u32 hash2 = 0;
1337 int i;
1338 u32 offset;
1339 u8 tmp;
1340
1341 if ( dev->flags & IFF_PROMISC ) {
1342 tmp = TLan_DioRead8( dev->base_addr, TLAN_NET_CMD );
Stephen Hemmingerdfc2c0a2008-05-30 09:49:58 -07001343 TLan_DioWrite8( dev->base_addr,
1344 TLAN_NET_CMD, tmp | TLAN_NET_CMD_CAF );
Linus Torvalds1da177e2005-04-16 15:20:36 -07001345 } else {
1346 tmp = TLan_DioRead8( dev->base_addr, TLAN_NET_CMD );
Stephen Hemmingerdfc2c0a2008-05-30 09:49:58 -07001347 TLan_DioWrite8( dev->base_addr,
1348 TLAN_NET_CMD, tmp & ~TLAN_NET_CMD_CAF );
Linus Torvalds1da177e2005-04-16 15:20:36 -07001349 if ( dev->flags & IFF_ALLMULTI ) {
Jeff Garzik6aa20a22006-09-13 13:24:59 -04001350 for ( i = 0; i < 3; i++ )
Linus Torvalds1da177e2005-04-16 15:20:36 -07001351 TLan_SetMac( dev, i + 1, NULL );
1352 TLan_DioWrite32( dev->base_addr, TLAN_HASH_1, 0xFFFFFFFF );
1353 TLan_DioWrite32( dev->base_addr, TLAN_HASH_2, 0xFFFFFFFF );
1354 } else {
1355 for ( i = 0; i < dev->mc_count; i++ ) {
1356 if ( i < 3 ) {
Stephen Hemmingerdfc2c0a2008-05-30 09:49:58 -07001357 TLan_SetMac( dev, i + 1,
1358 (char *) &dmi->dmi_addr );
Linus Torvalds1da177e2005-04-16 15:20:36 -07001359 } else {
1360 offset = TLan_HashFunc( (u8 *) &dmi->dmi_addr );
Jeff Garzik6aa20a22006-09-13 13:24:59 -04001361 if ( offset < 32 )
Linus Torvalds1da177e2005-04-16 15:20:36 -07001362 hash1 |= ( 1 << offset );
1363 else
1364 hash2 |= ( 1 << ( offset - 32 ) );
1365 }
1366 dmi = dmi->next;
1367 }
Jeff Garzik6aa20a22006-09-13 13:24:59 -04001368 for ( ; i < 3; i++ )
Linus Torvalds1da177e2005-04-16 15:20:36 -07001369 TLan_SetMac( dev, i + 1, NULL );
1370 TLan_DioWrite32( dev->base_addr, TLAN_HASH_1, hash1 );
1371 TLan_DioWrite32( dev->base_addr, TLAN_HASH_2, hash2 );
1372 }
1373 }
1374
1375} /* TLan_SetMulticastList */
1376
1377
1378
1379/*****************************************************************************
1380******************************************************************************
1381
1382 ThunderLAN Driver Interrupt Vectors and Table
1383
1384 Please see Chap. 4, "Interrupt Handling" of the "ThunderLAN
1385 Programmer's Guide" for more informations on handling interrupts
Jeff Garzik6aa20a22006-09-13 13:24:59 -04001386 generated by TLAN based adapters.
Linus Torvalds1da177e2005-04-16 15:20:36 -07001387
1388******************************************************************************
1389*****************************************************************************/
1390
1391
Linus Torvalds1da177e2005-04-16 15:20:36 -07001392
1393
1394 /***************************************************************
1395 * TLan_HandleTxEOF
1396 *
1397 * Returns:
1398 * 1
1399 * Parms:
1400 * dev Device assigned the IRQ that was
1401 * raised.
1402 * host_int The contents of the HOST_INT
1403 * port.
1404 *
1405 * This function handles Tx EOF interrupts which are raised
1406 * by the adapter when it has completed sending the
1407 * contents of a buffer. If detemines which list/buffer
1408 * was completed and resets it. If the buffer was the last
1409 * in the channel (EOC), then the function checks to see if
1410 * another buffer is ready to send, and if so, sends a Tx
1411 * Go command. Finally, the driver activates/continues the
1412 * activity LED.
1413 *
1414 **************************************************************/
1415
Harvey Harrison98e0f522008-02-18 10:04:38 -08001416static u32 TLan_HandleTxEOF( struct net_device *dev, u16 host_int )
Linus Torvalds1da177e2005-04-16 15:20:36 -07001417{
1418 TLanPrivateInfo *priv = netdev_priv(dev);
1419 int eoc = 0;
1420 TLanList *head_list;
1421 dma_addr_t head_list_phys;
1422 u32 ack = 0;
1423 u16 tmpCStat;
Jeff Garzik6aa20a22006-09-13 13:24:59 -04001424
Stephen Hemmingerdfc2c0a2008-05-30 09:49:58 -07001425 TLAN_DBG( TLAN_DEBUG_TX, "TRANSMIT: Handling TX EOF (Head=%d Tail=%d)\n",
1426 priv->txHead, priv->txTail );
Linus Torvalds1da177e2005-04-16 15:20:36 -07001427 head_list = priv->txList + priv->txHead;
1428
1429 while (((tmpCStat = head_list->cStat ) & TLAN_CSTAT_FRM_CMP) && (ack < 255)) {
1430 ack++;
1431 if ( ! bbuf ) {
1432 struct sk_buff *skb = TLan_GetSKB(head_list);
Stephen Hemmingerdfc2c0a2008-05-30 09:49:58 -07001433 pci_unmap_single(priv->pciDev, head_list->buffer[0].address,
1434 skb->len, PCI_DMA_TODEVICE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001435 dev_kfree_skb_any(skb);
1436 head_list->buffer[8].address = 0;
1437 head_list->buffer[9].address = 0;
1438 }
Jeff Garzik6aa20a22006-09-13 13:24:59 -04001439
Linus Torvalds1da177e2005-04-16 15:20:36 -07001440 if ( tmpCStat & TLAN_CSTAT_EOC )
1441 eoc = 1;
Jeff Garzik6aa20a22006-09-13 13:24:59 -04001442
Stephen Hemmingerf8f31542008-05-30 09:49:53 -07001443 dev->stats.tx_bytes += head_list->frameSize;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001444
1445 head_list->cStat = TLAN_CSTAT_UNUSED;
Jeff Garzik6aa20a22006-09-13 13:24:59 -04001446 netif_start_queue(dev);
1447 CIRC_INC( priv->txHead, TLAN_NUM_TX_LISTS );
Linus Torvalds1da177e2005-04-16 15:20:36 -07001448 head_list = priv->txList + priv->txHead;
1449 }
1450
1451 if (!ack)
1452 printk(KERN_INFO "TLAN: Received interrupt for uncompleted TX frame.\n");
Jeff Garzik6aa20a22006-09-13 13:24:59 -04001453
Linus Torvalds1da177e2005-04-16 15:20:36 -07001454 if ( eoc ) {
Stephen Hemmingerdfc2c0a2008-05-30 09:49:58 -07001455 TLAN_DBG( TLAN_DEBUG_TX,
1456 "TRANSMIT: Handling TX EOC (Head=%d Tail=%d)\n",
1457 priv->txHead, priv->txTail );
Linus Torvalds1da177e2005-04-16 15:20:36 -07001458 head_list = priv->txList + priv->txHead;
1459 head_list_phys = priv->txListDMA + sizeof(TLanList) * priv->txHead;
1460 if ( ( head_list->cStat & TLAN_CSTAT_READY ) == TLAN_CSTAT_READY ) {
1461 outl(head_list_phys, dev->base_addr + TLAN_CH_PARM );
1462 ack |= TLAN_HC_GO;
1463 } else {
1464 priv->txInProgress = 0;
1465 }
1466 }
Jeff Garzik6aa20a22006-09-13 13:24:59 -04001467
Linus Torvalds1da177e2005-04-16 15:20:36 -07001468 if ( priv->adapter->flags & TLAN_ADAPTER_ACTIVITY_LED ) {
Stephen Hemmingerdfc2c0a2008-05-30 09:49:58 -07001469 TLan_DioWrite8( dev->base_addr,
1470 TLAN_LED_REG, TLAN_LED_LINK | TLAN_LED_ACT );
Linus Torvalds1da177e2005-04-16 15:20:36 -07001471 if ( priv->timer.function == NULL ) {
1472 priv->timer.function = &TLan_Timer;
1473 priv->timer.data = (unsigned long) dev;
1474 priv->timer.expires = jiffies + TLAN_TIMER_ACT_DELAY;
1475 priv->timerSetAt = jiffies;
1476 priv->timerType = TLAN_TIMER_ACTIVITY;
1477 add_timer(&priv->timer);
1478 } else if ( priv->timerType == TLAN_TIMER_ACTIVITY ) {
1479 priv->timerSetAt = jiffies;
1480 }
1481 }
1482
1483 return ack;
1484
1485} /* TLan_HandleTxEOF */
1486
1487
1488
1489
1490 /***************************************************************
1491 * TLan_HandleStatOverflow
1492 *
1493 * Returns:
1494 * 1
1495 * Parms:
1496 * dev Device assigned the IRQ that was
1497 * raised.
1498 * host_int The contents of the HOST_INT
1499 * port.
1500 *
1501 * This function handles the Statistics Overflow interrupt
1502 * which means that one or more of the TLAN statistics
1503 * registers has reached 1/2 capacity and needs to be read.
1504 *
1505 **************************************************************/
1506
Harvey Harrison98e0f522008-02-18 10:04:38 -08001507static u32 TLan_HandleStatOverflow( struct net_device *dev, u16 host_int )
Linus Torvalds1da177e2005-04-16 15:20:36 -07001508{
1509 TLan_ReadAndClearStats( dev, TLAN_RECORD );
1510
1511 return 1;
1512
1513} /* TLan_HandleStatOverflow */
1514
1515
1516
1517
1518 /***************************************************************
1519 * TLan_HandleRxEOF
1520 *
1521 * Returns:
1522 * 1
1523 * Parms:
1524 * dev Device assigned the IRQ that was
1525 * raised.
1526 * host_int The contents of the HOST_INT
1527 * port.
1528 *
1529 * This function handles the Rx EOF interrupt which
1530 * indicates a frame has been received by the adapter from
1531 * the net and the frame has been transferred to memory.
1532 * The function determines the bounce buffer the frame has
1533 * been loaded into, creates a new sk_buff big enough to
1534 * hold the frame, and sends it to protocol stack. It
1535 * then resets the used buffer and appends it to the end
1536 * of the list. If the frame was the last in the Rx
1537 * channel (EOC), the function restarts the receive channel
1538 * by sending an Rx Go command to the adapter. Then it
1539 * activates/continues the activity LED.
1540 *
1541 **************************************************************/
1542
Harvey Harrison98e0f522008-02-18 10:04:38 -08001543static u32 TLan_HandleRxEOF( struct net_device *dev, u16 host_int )
Linus Torvalds1da177e2005-04-16 15:20:36 -07001544{
1545 TLanPrivateInfo *priv = netdev_priv(dev);
1546 u32 ack = 0;
1547 int eoc = 0;
1548 u8 *head_buffer;
1549 TLanList *head_list;
1550 struct sk_buff *skb;
1551 TLanList *tail_list;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001552 u16 tmpCStat;
1553 dma_addr_t head_list_phys;
1554
Stephen Hemmingerdfc2c0a2008-05-30 09:49:58 -07001555 TLAN_DBG( TLAN_DEBUG_RX, "RECEIVE: Handling RX EOF (Head=%d Tail=%d)\n",
1556 priv->rxHead, priv->rxTail );
Linus Torvalds1da177e2005-04-16 15:20:36 -07001557 head_list = priv->rxList + priv->rxHead;
1558 head_list_phys = priv->rxListDMA + sizeof(TLanList) * priv->rxHead;
Jeff Garzik6aa20a22006-09-13 13:24:59 -04001559
Linus Torvalds1da177e2005-04-16 15:20:36 -07001560 while (((tmpCStat = head_list->cStat) & TLAN_CSTAT_FRM_CMP) && (ack < 255)) {
Stephen Hemminger9ded65a2008-05-30 09:49:56 -07001561 dma_addr_t frameDma = head_list->buffer[0].address;
1562 u32 frameSize = head_list->frameSize;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001563 ack++;
1564 if (tmpCStat & TLAN_CSTAT_EOC)
1565 eoc = 1;
Jeff Garzik6aa20a22006-09-13 13:24:59 -04001566
Linus Torvalds1da177e2005-04-16 15:20:36 -07001567 if (bbuf) {
Stephen Hemminger9ded65a2008-05-30 09:49:56 -07001568 skb = netdev_alloc_skb(dev, frameSize + 7);
Stephen Hemmingerdfc2c0a2008-05-30 09:49:58 -07001569 if ( !skb )
1570 goto drop_and_reuse;
Jeff Garzik6aa20a22006-09-13 13:24:59 -04001571
Stephen Hemmingerdfc2c0a2008-05-30 09:49:58 -07001572 head_buffer = priv->rxBuffer
1573 + (priv->rxHead * TLAN_MAX_FRAME_SIZE);
1574 skb_reserve(skb, 2);
1575 pci_dma_sync_single_for_cpu(priv->pciDev,
1576 frameDma, frameSize,
1577 PCI_DMA_FROMDEVICE);
1578 skb_copy_from_linear_data(skb, head_buffer, frameSize);
1579 skb_put(skb, frameSize);
1580 dev->stats.rx_bytes += frameSize;
1581
1582 skb->protocol = eth_type_trans( skb, dev );
1583 netif_rx( skb );
Linus Torvalds1da177e2005-04-16 15:20:36 -07001584 } else {
1585 struct sk_buff *new_skb;
Jeff Garzik6aa20a22006-09-13 13:24:59 -04001586
Stephen Hemminger9ded65a2008-05-30 09:49:56 -07001587 new_skb = netdev_alloc_skb(dev, TLAN_MAX_FRAME_SIZE + 7 );
Stephen Hemmingerdfc2c0a2008-05-30 09:49:58 -07001588 if ( !new_skb )
1589 goto drop_and_reuse;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001590
Stephen Hemmingerdfc2c0a2008-05-30 09:49:58 -07001591 skb = TLan_GetSKB(head_list);
1592 pci_unmap_single(priv->pciDev, frameDma,
1593 TLAN_MAX_FRAME_SIZE, PCI_DMA_FROMDEVICE);
1594 skb_put( skb, frameSize );
Linus Torvalds1da177e2005-04-16 15:20:36 -07001595
Stephen Hemmingerdfc2c0a2008-05-30 09:49:58 -07001596 dev->stats.rx_bytes += frameSize;
Jeff Garzik6aa20a22006-09-13 13:24:59 -04001597
Stephen Hemmingerdfc2c0a2008-05-30 09:49:58 -07001598 skb->protocol = eth_type_trans( skb, dev );
1599 netif_rx( skb );
Stephen Hemminger93e16842008-05-30 09:49:55 -07001600
Stephen Hemmingerdfc2c0a2008-05-30 09:49:58 -07001601 skb_reserve( new_skb, NET_IP_ALIGN );
1602 head_list->buffer[0].address = pci_map_single(priv->pciDev,
1603 new_skb->data,
1604 TLAN_MAX_FRAME_SIZE,
1605 PCI_DMA_FROMDEVICE);
1606
1607 TLan_StoreSKB(head_list, new_skb);
Stephen Hemminger9ded65a2008-05-30 09:49:56 -07001608
Linus Torvalds1da177e2005-04-16 15:20:36 -07001609 }
Stephen Hemmingerdfc2c0a2008-05-30 09:49:58 -07001610drop_and_reuse:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001611 head_list->forward = 0;
1612 head_list->cStat = 0;
1613 tail_list = priv->rxList + priv->rxTail;
1614 tail_list->forward = head_list_phys;
1615
1616 CIRC_INC( priv->rxHead, TLAN_NUM_RX_LISTS );
1617 CIRC_INC( priv->rxTail, TLAN_NUM_RX_LISTS );
1618 head_list = priv->rxList + priv->rxHead;
1619 head_list_phys = priv->rxListDMA + sizeof(TLanList) * priv->rxHead;
1620 }
1621
1622 if (!ack)
1623 printk(KERN_INFO "TLAN: Received interrupt for uncompleted RX frame.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001624
1625
Jeff Garzik6aa20a22006-09-13 13:24:59 -04001626 if ( eoc ) {
Stephen Hemmingerdfc2c0a2008-05-30 09:49:58 -07001627 TLAN_DBG( TLAN_DEBUG_RX,
1628 "RECEIVE: Handling RX EOC (Head=%d Tail=%d)\n",
1629 priv->rxHead, priv->rxTail );
Linus Torvalds1da177e2005-04-16 15:20:36 -07001630 head_list = priv->rxList + priv->rxHead;
1631 head_list_phys = priv->rxListDMA + sizeof(TLanList) * priv->rxHead;
1632 outl(head_list_phys, dev->base_addr + TLAN_CH_PARM );
1633 ack |= TLAN_HC_GO | TLAN_HC_RT;
1634 priv->rxEocCount++;
1635 }
1636
1637 if ( priv->adapter->flags & TLAN_ADAPTER_ACTIVITY_LED ) {
Stephen Hemmingerdfc2c0a2008-05-30 09:49:58 -07001638 TLan_DioWrite8( dev->base_addr,
1639 TLAN_LED_REG, TLAN_LED_LINK | TLAN_LED_ACT );
Linus Torvalds1da177e2005-04-16 15:20:36 -07001640 if ( priv->timer.function == NULL ) {
1641 priv->timer.function = &TLan_Timer;
1642 priv->timer.data = (unsigned long) dev;
1643 priv->timer.expires = jiffies + TLAN_TIMER_ACT_DELAY;
1644 priv->timerSetAt = jiffies;
1645 priv->timerType = TLAN_TIMER_ACTIVITY;
1646 add_timer(&priv->timer);
1647 } else if ( priv->timerType == TLAN_TIMER_ACTIVITY ) {
1648 priv->timerSetAt = jiffies;
1649 }
1650 }
1651
1652 dev->last_rx = jiffies;
Jeff Garzik6aa20a22006-09-13 13:24:59 -04001653
Linus Torvalds1da177e2005-04-16 15:20:36 -07001654 return ack;
1655
1656} /* TLan_HandleRxEOF */
1657
1658
1659
1660
1661 /***************************************************************
1662 * TLan_HandleDummy
1663 *
1664 * Returns:
1665 * 1
1666 * Parms:
1667 * dev Device assigned the IRQ that was
1668 * raised.
1669 * host_int The contents of the HOST_INT
1670 * port.
1671 *
1672 * This function handles the Dummy interrupt, which is
1673 * raised whenever a test interrupt is generated by setting
1674 * the Req_Int bit of HOST_CMD to 1.
1675 *
1676 **************************************************************/
1677
Harvey Harrison98e0f522008-02-18 10:04:38 -08001678static u32 TLan_HandleDummy( struct net_device *dev, u16 host_int )
Linus Torvalds1da177e2005-04-16 15:20:36 -07001679{
1680 printk( "TLAN: Test interrupt on %s.\n", dev->name );
1681 return 1;
1682
1683} /* TLan_HandleDummy */
1684
1685
1686
1687
1688 /***************************************************************
1689 * TLan_HandleTxEOC
1690 *
1691 * Returns:
1692 * 1
1693 * Parms:
1694 * dev Device assigned the IRQ that was
1695 * raised.
1696 * host_int The contents of the HOST_INT
1697 * port.
1698 *
1699 * This driver is structured to determine EOC occurrences by
1700 * reading the CSTAT member of the list structure. Tx EOC
1701 * interrupts are disabled via the DIO INTDIS register.
1702 * However, TLAN chips before revision 3.0 didn't have this
1703 * functionality, so process EOC events if this is the
1704 * case.
1705 *
1706 **************************************************************/
1707
Harvey Harrison98e0f522008-02-18 10:04:38 -08001708static u32 TLan_HandleTxEOC( struct net_device *dev, u16 host_int )
Linus Torvalds1da177e2005-04-16 15:20:36 -07001709{
1710 TLanPrivateInfo *priv = netdev_priv(dev);
1711 TLanList *head_list;
1712 dma_addr_t head_list_phys;
1713 u32 ack = 1;
Jeff Garzik6aa20a22006-09-13 13:24:59 -04001714
Linus Torvalds1da177e2005-04-16 15:20:36 -07001715 host_int = 0;
1716 if ( priv->tlanRev < 0x30 ) {
Stephen Hemmingerdfc2c0a2008-05-30 09:49:58 -07001717 TLAN_DBG( TLAN_DEBUG_TX,
1718 "TRANSMIT: Handling TX EOC (Head=%d Tail=%d) -- IRQ\n",
1719 priv->txHead, priv->txTail );
Linus Torvalds1da177e2005-04-16 15:20:36 -07001720 head_list = priv->txList + priv->txHead;
1721 head_list_phys = priv->txListDMA + sizeof(TLanList) * priv->txHead;
1722 if ( ( head_list->cStat & TLAN_CSTAT_READY ) == TLAN_CSTAT_READY ) {
1723 netif_stop_queue(dev);
1724 outl( head_list_phys, dev->base_addr + TLAN_CH_PARM );
1725 ack |= TLAN_HC_GO;
1726 } else {
1727 priv->txInProgress = 0;
1728 }
1729 }
1730
1731 return ack;
1732
1733} /* TLan_HandleTxEOC */
1734
1735
1736
1737
1738 /***************************************************************
1739 * TLan_HandleStatusCheck
1740 *
1741 * Returns:
1742 * 0 if Adapter check, 1 if Network Status check.
1743 * Parms:
1744 * dev Device assigned the IRQ that was
1745 * raised.
1746 * host_int The contents of the HOST_INT
1747 * port.
1748 *
1749 * This function handles Adapter Check/Network Status
1750 * interrupts generated by the adapter. It checks the
1751 * vector in the HOST_INT register to determine if it is
1752 * an Adapter Check interrupt. If so, it resets the
1753 * adapter. Otherwise it clears the status registers
1754 * and services the PHY.
1755 *
1756 **************************************************************/
1757
Harvey Harrison98e0f522008-02-18 10:04:38 -08001758static u32 TLan_HandleStatusCheck( struct net_device *dev, u16 host_int )
Jeff Garzik6aa20a22006-09-13 13:24:59 -04001759{
Linus Torvalds1da177e2005-04-16 15:20:36 -07001760 TLanPrivateInfo *priv = netdev_priv(dev);
1761 u32 ack;
1762 u32 error;
1763 u8 net_sts;
1764 u32 phy;
1765 u16 tlphy_ctl;
1766 u16 tlphy_sts;
Jeff Garzik6aa20a22006-09-13 13:24:59 -04001767
Linus Torvalds1da177e2005-04-16 15:20:36 -07001768 ack = 1;
1769 if ( host_int & TLAN_HI_IV_MASK ) {
1770 netif_stop_queue( dev );
1771 error = inl( dev->base_addr + TLAN_CH_PARM );
1772 printk( "TLAN: %s: Adaptor Error = 0x%x\n", dev->name, error );
1773 TLan_ReadAndClearStats( dev, TLAN_RECORD );
1774 outl( TLAN_HC_AD_RST, dev->base_addr + TLAN_HOST_CMD );
1775
1776 schedule_work(&priv->tlan_tqueue);
1777
1778 netif_wake_queue(dev);
1779 ack = 0;
1780 } else {
1781 TLAN_DBG( TLAN_DEBUG_GNRL, "%s: Status Check\n", dev->name );
1782 phy = priv->phy[priv->phyNum];
1783
1784 net_sts = TLan_DioRead8( dev->base_addr, TLAN_NET_STS );
1785 if ( net_sts ) {
1786 TLan_DioWrite8( dev->base_addr, TLAN_NET_STS, net_sts );
Stephen Hemmingerdfc2c0a2008-05-30 09:49:58 -07001787 TLAN_DBG( TLAN_DEBUG_GNRL, "%s: Net_Sts = %x\n",
1788 dev->name, (unsigned) net_sts );
Linus Torvalds1da177e2005-04-16 15:20:36 -07001789 }
1790 if ( ( net_sts & TLAN_NET_STS_MIRQ ) && ( priv->phyNum == 0 ) ) {
1791 TLan_MiiReadReg( dev, phy, TLAN_TLPHY_STS, &tlphy_sts );
1792 TLan_MiiReadReg( dev, phy, TLAN_TLPHY_CTL, &tlphy_ctl );
Stephen Hemmingerdfc2c0a2008-05-30 09:49:58 -07001793 if ( ! ( tlphy_sts & TLAN_TS_POLOK ) &&
1794 ! ( tlphy_ctl & TLAN_TC_SWAPOL ) ) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001795 tlphy_ctl |= TLAN_TC_SWAPOL;
1796 TLan_MiiWriteReg( dev, phy, TLAN_TLPHY_CTL, tlphy_ctl);
Stephen Hemmingerdfc2c0a2008-05-30 09:49:58 -07001797 } else if ( ( tlphy_sts & TLAN_TS_POLOK )
1798 && ( tlphy_ctl & TLAN_TC_SWAPOL ) ) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001799 tlphy_ctl &= ~TLAN_TC_SWAPOL;
1800 TLan_MiiWriteReg( dev, phy, TLAN_TLPHY_CTL, tlphy_ctl);
1801 }
1802
1803 if (debug) {
Jeff Garzik6aa20a22006-09-13 13:24:59 -04001804 TLan_PhyPrint( dev );
Linus Torvalds1da177e2005-04-16 15:20:36 -07001805 }
1806 }
1807 }
1808
1809 return ack;
1810
1811} /* TLan_HandleStatusCheck */
1812
1813
1814
1815
1816 /***************************************************************
1817 * TLan_HandleRxEOC
1818 *
1819 * Returns:
1820 * 1
1821 * Parms:
1822 * dev Device assigned the IRQ that was
1823 * raised.
1824 * host_int The contents of the HOST_INT
1825 * port.
1826 *
1827 * This driver is structured to determine EOC occurrences by
1828 * reading the CSTAT member of the list structure. Rx EOC
1829 * interrupts are disabled via the DIO INTDIS register.
1830 * However, TLAN chips before revision 3.0 didn't have this
1831 * CSTAT member or a INTDIS register, so if this chip is
1832 * pre-3.0, process EOC interrupts normally.
1833 *
1834 **************************************************************/
1835
Harvey Harrison98e0f522008-02-18 10:04:38 -08001836static u32 TLan_HandleRxEOC( struct net_device *dev, u16 host_int )
Linus Torvalds1da177e2005-04-16 15:20:36 -07001837{
1838 TLanPrivateInfo *priv = netdev_priv(dev);
1839 dma_addr_t head_list_phys;
1840 u32 ack = 1;
1841
1842 if ( priv->tlanRev < 0x30 ) {
Stephen Hemmingerdfc2c0a2008-05-30 09:49:58 -07001843 TLAN_DBG( TLAN_DEBUG_RX,
1844 "RECEIVE: Handling RX EOC (Head=%d Tail=%d) -- IRQ\n",
1845 priv->rxHead, priv->rxTail );
Linus Torvalds1da177e2005-04-16 15:20:36 -07001846 head_list_phys = priv->rxListDMA + sizeof(TLanList) * priv->rxHead;
1847 outl( head_list_phys, dev->base_addr + TLAN_CH_PARM );
1848 ack |= TLAN_HC_GO | TLAN_HC_RT;
1849 priv->rxEocCount++;
1850 }
1851
1852 return ack;
1853
1854} /* TLan_HandleRxEOC */
1855
1856
1857
1858
1859/*****************************************************************************
1860******************************************************************************
1861
1862 ThunderLAN Driver Timer Function
1863
1864******************************************************************************
1865*****************************************************************************/
1866
1867
1868 /***************************************************************
1869 * TLan_Timer
1870 *
1871 * Returns:
1872 * Nothing
1873 * Parms:
1874 * data A value given to add timer when
1875 * add_timer was called.
1876 *
1877 * This function handles timed functionality for the
1878 * TLAN driver. The two current timer uses are for
1879 * delaying for autonegotionation and driving the ACT LED.
1880 * - Autonegotiation requires being allowed about
1881 * 2 1/2 seconds before attempting to transmit a
1882 * packet. It would be a very bad thing to hang
1883 * the kernel this long, so the driver doesn't
1884 * allow transmission 'til after this time, for
1885 * certain PHYs. It would be much nicer if all
1886 * PHYs were interrupt-capable like the internal
1887 * PHY.
1888 * - The ACT LED, which shows adapter activity, is
1889 * driven by the driver, and so must be left on
1890 * for a short period to power up the LED so it
1891 * can be seen. This delay can be changed by
1892 * changing the TLAN_TIMER_ACT_DELAY in tlan.h,
1893 * if desired. 100 ms produces a slightly
1894 * sluggish response.
1895 *
1896 **************************************************************/
1897
Harvey Harrison98e0f522008-02-18 10:04:38 -08001898static void TLan_Timer( unsigned long data )
Linus Torvalds1da177e2005-04-16 15:20:36 -07001899{
1900 struct net_device *dev = (struct net_device *) data;
1901 TLanPrivateInfo *priv = netdev_priv(dev);
1902 u32 elapsed;
1903 unsigned long flags = 0;
1904
1905 priv->timer.function = NULL;
1906
1907 switch ( priv->timerType ) {
Jeff Garzik6aa20a22006-09-13 13:24:59 -04001908#ifdef MONITOR
Linus Torvalds1da177e2005-04-16 15:20:36 -07001909 case TLAN_TIMER_LINK_BEAT:
1910 TLan_PhyMonitor( dev );
1911 break;
1912#endif
1913 case TLAN_TIMER_PHY_PDOWN:
1914 TLan_PhyPowerDown( dev );
1915 break;
1916 case TLAN_TIMER_PHY_PUP:
1917 TLan_PhyPowerUp( dev );
1918 break;
1919 case TLAN_TIMER_PHY_RESET:
1920 TLan_PhyReset( dev );
1921 break;
1922 case TLAN_TIMER_PHY_START_LINK:
1923 TLan_PhyStartLink( dev );
1924 break;
1925 case TLAN_TIMER_PHY_FINISH_AN:
1926 TLan_PhyFinishAutoNeg( dev );
1927 break;
1928 case TLAN_TIMER_FINISH_RESET:
1929 TLan_FinishReset( dev );
1930 break;
1931 case TLAN_TIMER_ACTIVITY:
1932 spin_lock_irqsave(&priv->lock, flags);
1933 if ( priv->timer.function == NULL ) {
1934 elapsed = jiffies - priv->timerSetAt;
1935 if ( elapsed >= TLAN_TIMER_ACT_DELAY ) {
Stephen Hemmingerdfc2c0a2008-05-30 09:49:58 -07001936 TLan_DioWrite8( dev->base_addr,
1937 TLAN_LED_REG, TLAN_LED_LINK );
Linus Torvalds1da177e2005-04-16 15:20:36 -07001938 } else {
1939 priv->timer.function = &TLan_Timer;
Stephen Hemmingerdfc2c0a2008-05-30 09:49:58 -07001940 priv->timer.expires = priv->timerSetAt
1941 + TLAN_TIMER_ACT_DELAY;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001942 spin_unlock_irqrestore(&priv->lock, flags);
1943 add_timer( &priv->timer );
1944 break;
1945 }
1946 }
1947 spin_unlock_irqrestore(&priv->lock, flags);
1948 break;
1949 default:
1950 break;
1951 }
1952
1953} /* TLan_Timer */
1954
1955
1956
1957
1958/*****************************************************************************
1959******************************************************************************
1960
1961 ThunderLAN Driver Adapter Related Routines
1962
1963******************************************************************************
1964*****************************************************************************/
1965
1966
1967 /***************************************************************
1968 * TLan_ResetLists
Jeff Garzik6aa20a22006-09-13 13:24:59 -04001969 *
Linus Torvalds1da177e2005-04-16 15:20:36 -07001970 * Returns:
1971 * Nothing
1972 * Parms:
1973 * dev The device structure with the list
1974 * stuctures to be reset.
1975 *
1976 * This routine sets the variables associated with managing
1977 * the TLAN lists to their initial values.
1978 *
1979 **************************************************************/
1980
Harvey Harrison98e0f522008-02-18 10:04:38 -08001981static void TLan_ResetLists( struct net_device *dev )
Linus Torvalds1da177e2005-04-16 15:20:36 -07001982{
1983 TLanPrivateInfo *priv = netdev_priv(dev);
1984 int i;
1985 TLanList *list;
1986 dma_addr_t list_phys;
1987 struct sk_buff *skb;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001988
1989 priv->txHead = 0;
1990 priv->txTail = 0;
1991 for ( i = 0; i < TLAN_NUM_TX_LISTS; i++ ) {
1992 list = priv->txList + i;
1993 list->cStat = TLAN_CSTAT_UNUSED;
1994 if ( bbuf ) {
Stephen Hemmingerdfc2c0a2008-05-30 09:49:58 -07001995 list->buffer[0].address = priv->txBufferDMA
1996 + ( i * TLAN_MAX_FRAME_SIZE );
Linus Torvalds1da177e2005-04-16 15:20:36 -07001997 } else {
1998 list->buffer[0].address = 0;
1999 }
2000 list->buffer[2].count = 0;
2001 list->buffer[2].address = 0;
2002 list->buffer[8].address = 0;
2003 list->buffer[9].address = 0;
2004 }
2005
2006 priv->rxHead = 0;
2007 priv->rxTail = TLAN_NUM_RX_LISTS - 1;
2008 for ( i = 0; i < TLAN_NUM_RX_LISTS; i++ ) {
2009 list = priv->rxList + i;
2010 list_phys = priv->rxListDMA + sizeof(TLanList) * i;
2011 list->cStat = TLAN_CSTAT_READY;
2012 list->frameSize = TLAN_MAX_FRAME_SIZE;
2013 list->buffer[0].count = TLAN_MAX_FRAME_SIZE | TLAN_LAST_BUFFER;
2014 if ( bbuf ) {
Stephen Hemmingerdfc2c0a2008-05-30 09:49:58 -07002015 list->buffer[0].address = priv->rxBufferDMA
2016 + ( i * TLAN_MAX_FRAME_SIZE );
Linus Torvalds1da177e2005-04-16 15:20:36 -07002017 } else {
Stephen Hemminger9ded65a2008-05-30 09:49:56 -07002018 skb = netdev_alloc_skb(dev, TLAN_MAX_FRAME_SIZE + 7 );
2019 if ( !skb ) {
Stephen Hemmingerdfc2c0a2008-05-30 09:49:58 -07002020 pr_err("TLAN: out of memory for received data.\n" );
Stephen Hemminger9ded65a2008-05-30 09:49:56 -07002021 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002022 }
Stephen Hemminger9ded65a2008-05-30 09:49:56 -07002023
2024 skb_reserve( skb, NET_IP_ALIGN );
Robert Fitzsimons0d63bea2008-08-09 17:54:02 +01002025 list->buffer[0].address = pci_map_single(priv->pciDev,
2026 skb->data,
Stephen Hemmingerdfc2c0a2008-05-30 09:49:58 -07002027 TLAN_MAX_FRAME_SIZE,
2028 PCI_DMA_FROMDEVICE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002029 TLan_StoreSKB(list, skb);
2030 }
2031 list->buffer[1].count = 0;
2032 list->buffer[1].address = 0;
Stephen Hemminger9ded65a2008-05-30 09:49:56 -07002033 list->forward = list_phys + sizeof(TLanList);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002034 }
2035
Stephen Hemminger9ded65a2008-05-30 09:49:56 -07002036 /* in case ran out of memory early, clear bits */
2037 while (i < TLAN_NUM_RX_LISTS) {
2038 TLan_StoreSKB(priv->rxList + i, NULL);
2039 ++i;
2040 }
2041 list->forward = 0;
2042
Linus Torvalds1da177e2005-04-16 15:20:36 -07002043} /* TLan_ResetLists */
2044
2045
Harvey Harrison98e0f522008-02-18 10:04:38 -08002046static void TLan_FreeLists( struct net_device *dev )
Linus Torvalds1da177e2005-04-16 15:20:36 -07002047{
2048 TLanPrivateInfo *priv = netdev_priv(dev);
2049 int i;
2050 TLanList *list;
2051 struct sk_buff *skb;
2052
2053 if ( ! bbuf ) {
2054 for ( i = 0; i < TLAN_NUM_TX_LISTS; i++ ) {
2055 list = priv->txList + i;
2056 skb = TLan_GetSKB(list);
2057 if ( skb ) {
Stephen Hemmingerdfc2c0a2008-05-30 09:49:58 -07002058 pci_unmap_single(priv->pciDev,
2059 list->buffer[0].address, skb->len,
2060 PCI_DMA_TODEVICE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002061 dev_kfree_skb_any( skb );
2062 list->buffer[8].address = 0;
2063 list->buffer[9].address = 0;
2064 }
2065 }
2066
2067 for ( i = 0; i < TLAN_NUM_RX_LISTS; i++ ) {
2068 list = priv->rxList + i;
2069 skb = TLan_GetSKB(list);
2070 if ( skb ) {
Stephen Hemmingerdfc2c0a2008-05-30 09:49:58 -07002071 pci_unmap_single(priv->pciDev,
2072 list->buffer[0].address,
2073 TLAN_MAX_FRAME_SIZE,
2074 PCI_DMA_FROMDEVICE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002075 dev_kfree_skb_any( skb );
2076 list->buffer[8].address = 0;
2077 list->buffer[9].address = 0;
2078 }
2079 }
2080 }
2081} /* TLan_FreeLists */
2082
2083
2084
2085
2086 /***************************************************************
2087 * TLan_PrintDio
Jeff Garzik6aa20a22006-09-13 13:24:59 -04002088 *
Linus Torvalds1da177e2005-04-16 15:20:36 -07002089 * Returns:
2090 * Nothing
2091 * Parms:
2092 * io_base Base IO port of the device of
2093 * which to print DIO registers.
2094 *
2095 * This function prints out all the internal (DIO)
2096 * registers of a TLAN chip.
2097 *
2098 **************************************************************/
2099
Harvey Harrison98e0f522008-02-18 10:04:38 -08002100static void TLan_PrintDio( u16 io_base )
Linus Torvalds1da177e2005-04-16 15:20:36 -07002101{
2102 u32 data0, data1;
2103 int i;
2104
Stephen Hemmingerdfc2c0a2008-05-30 09:49:58 -07002105 printk( "TLAN: Contents of internal registers for io base 0x%04hx.\n",
2106 io_base );
Linus Torvalds1da177e2005-04-16 15:20:36 -07002107 printk( "TLAN: Off. +0 +4\n" );
2108 for ( i = 0; i < 0x4C; i+= 8 ) {
2109 data0 = TLan_DioRead32( io_base, i );
2110 data1 = TLan_DioRead32( io_base, i + 0x4 );
2111 printk( "TLAN: 0x%02x 0x%08x 0x%08x\n", i, data0, data1 );
2112 }
2113
2114} /* TLan_PrintDio */
2115
2116
2117
2118
2119 /***************************************************************
2120 * TLan_PrintList
Jeff Garzik6aa20a22006-09-13 13:24:59 -04002121 *
Linus Torvalds1da177e2005-04-16 15:20:36 -07002122 * Returns:
2123 * Nothing
2124 * Parms:
2125 * list A pointer to the TLanList structure to
2126 * be printed.
2127 * type A string to designate type of list,
2128 * "Rx" or "Tx".
2129 * num The index of the list.
2130 *
2131 * This function prints out the contents of the list
2132 * pointed to by the list parameter.
2133 *
2134 **************************************************************/
2135
Harvey Harrison98e0f522008-02-18 10:04:38 -08002136static void TLan_PrintList( TLanList *list, char *type, int num)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002137{
2138 int i;
2139
Stephen Hemminger93e16842008-05-30 09:49:55 -07002140 printk( "TLAN: %s List %d at %p\n", type, num, list );
Linus Torvalds1da177e2005-04-16 15:20:36 -07002141 printk( "TLAN: Forward = 0x%08x\n", list->forward );
2142 printk( "TLAN: CSTAT = 0x%04hx\n", list->cStat );
2143 printk( "TLAN: Frame Size = 0x%04hx\n", list->frameSize );
2144 /* for ( i = 0; i < 10; i++ ) { */
2145 for ( i = 0; i < 2; i++ ) {
Stephen Hemmingerdfc2c0a2008-05-30 09:49:58 -07002146 printk( "TLAN: Buffer[%d].count, addr = 0x%08x, 0x%08x\n",
2147 i, list->buffer[i].count, list->buffer[i].address );
Linus Torvalds1da177e2005-04-16 15:20:36 -07002148 }
2149
2150} /* TLan_PrintList */
2151
2152
2153
2154
2155 /***************************************************************
2156 * TLan_ReadAndClearStats
2157 *
2158 * Returns:
2159 * Nothing
2160 * Parms:
2161 * dev Pointer to device structure of adapter
2162 * to which to read stats.
Jeff Garzik6aa20a22006-09-13 13:24:59 -04002163 * record Flag indicating whether to add
Linus Torvalds1da177e2005-04-16 15:20:36 -07002164 *
2165 * This functions reads all the internal status registers
2166 * of the TLAN chip, which clears them as a side effect.
2167 * It then either adds the values to the device's status
2168 * struct, or discards them, depending on whether record
2169 * is TLAN_RECORD (!=0) or TLAN_IGNORE (==0).
2170 *
2171 **************************************************************/
2172
Harvey Harrison98e0f522008-02-18 10:04:38 -08002173static void TLan_ReadAndClearStats( struct net_device *dev, int record )
Linus Torvalds1da177e2005-04-16 15:20:36 -07002174{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002175 u32 tx_good, tx_under;
2176 u32 rx_good, rx_over;
2177 u32 def_tx, crc, code;
2178 u32 multi_col, single_col;
2179 u32 excess_col, late_col, loss;
2180
2181 outw( TLAN_GOOD_TX_FRMS, dev->base_addr + TLAN_DIO_ADR );
2182 tx_good = inb( dev->base_addr + TLAN_DIO_DATA );
2183 tx_good += inb( dev->base_addr + TLAN_DIO_DATA + 1 ) << 8;
2184 tx_good += inb( dev->base_addr + TLAN_DIO_DATA + 2 ) << 16;
2185 tx_under = inb( dev->base_addr + TLAN_DIO_DATA + 3 );
2186
2187 outw( TLAN_GOOD_RX_FRMS, dev->base_addr + TLAN_DIO_ADR );
2188 rx_good = inb( dev->base_addr + TLAN_DIO_DATA );
2189 rx_good += inb( dev->base_addr + TLAN_DIO_DATA + 1 ) << 8;
2190 rx_good += inb( dev->base_addr + TLAN_DIO_DATA + 2 ) << 16;
2191 rx_over = inb( dev->base_addr + TLAN_DIO_DATA + 3 );
Jeff Garzik6aa20a22006-09-13 13:24:59 -04002192
Linus Torvalds1da177e2005-04-16 15:20:36 -07002193 outw( TLAN_DEFERRED_TX, dev->base_addr + TLAN_DIO_ADR );
2194 def_tx = inb( dev->base_addr + TLAN_DIO_DATA );
2195 def_tx += inb( dev->base_addr + TLAN_DIO_DATA + 1 ) << 8;
2196 crc = inb( dev->base_addr + TLAN_DIO_DATA + 2 );
2197 code = inb( dev->base_addr + TLAN_DIO_DATA + 3 );
Jeff Garzik6aa20a22006-09-13 13:24:59 -04002198
Linus Torvalds1da177e2005-04-16 15:20:36 -07002199 outw( TLAN_MULTICOL_FRMS, dev->base_addr + TLAN_DIO_ADR );
2200 multi_col = inb( dev->base_addr + TLAN_DIO_DATA );
2201 multi_col += inb( dev->base_addr + TLAN_DIO_DATA + 1 ) << 8;
2202 single_col = inb( dev->base_addr + TLAN_DIO_DATA + 2 );
2203 single_col += inb( dev->base_addr + TLAN_DIO_DATA + 3 ) << 8;
2204
2205 outw( TLAN_EXCESSCOL_FRMS, dev->base_addr + TLAN_DIO_ADR );
2206 excess_col = inb( dev->base_addr + TLAN_DIO_DATA );
2207 late_col = inb( dev->base_addr + TLAN_DIO_DATA + 1 );
2208 loss = inb( dev->base_addr + TLAN_DIO_DATA + 2 );
2209
2210 if ( record ) {
Stephen Hemmingerf8f31542008-05-30 09:49:53 -07002211 dev->stats.rx_packets += rx_good;
2212 dev->stats.rx_errors += rx_over + crc + code;
2213 dev->stats.tx_packets += tx_good;
2214 dev->stats.tx_errors += tx_under + loss;
2215 dev->stats.collisions += multi_col + single_col + excess_col + late_col;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002216
Stephen Hemmingerf8f31542008-05-30 09:49:53 -07002217 dev->stats.rx_over_errors += rx_over;
2218 dev->stats.rx_crc_errors += crc;
2219 dev->stats.rx_frame_errors += code;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002220
Stephen Hemmingerf8f31542008-05-30 09:49:53 -07002221 dev->stats.tx_aborted_errors += tx_under;
2222 dev->stats.tx_carrier_errors += loss;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002223 }
Jeff Garzik6aa20a22006-09-13 13:24:59 -04002224
Linus Torvalds1da177e2005-04-16 15:20:36 -07002225} /* TLan_ReadAndClearStats */
2226
2227
2228
2229
2230 /***************************************************************
2231 * TLan_Reset
2232 *
2233 * Returns:
2234 * 0
2235 * Parms:
2236 * dev Pointer to device structure of adapter
2237 * to be reset.
2238 *
2239 * This function resets the adapter and it's physical
2240 * device. See Chap. 3, pp. 9-10 of the "ThunderLAN
2241 * Programmer's Guide" for details. The routine tries to
2242 * implement what is detailed there, though adjustments
2243 * have been made.
2244 *
2245 **************************************************************/
2246
Harvey Harrison98e0f522008-02-18 10:04:38 -08002247static void
Linus Torvalds1da177e2005-04-16 15:20:36 -07002248TLan_ResetAdapter( struct net_device *dev )
2249{
2250 TLanPrivateInfo *priv = netdev_priv(dev);
2251 int i;
2252 u32 addr;
2253 u32 data;
2254 u8 data8;
2255
2256 priv->tlanFullDuplex = FALSE;
2257 priv->phyOnline=0;
2258 netif_carrier_off(dev);
2259
2260/* 1. Assert reset bit. */
2261
2262 data = inl(dev->base_addr + TLAN_HOST_CMD);
2263 data |= TLAN_HC_AD_RST;
2264 outl(data, dev->base_addr + TLAN_HOST_CMD);
Jeff Garzik6aa20a22006-09-13 13:24:59 -04002265
Linus Torvalds1da177e2005-04-16 15:20:36 -07002266 udelay(1000);
2267
2268/* 2. Turn off interrupts. ( Probably isn't necessary ) */
2269
2270 data = inl(dev->base_addr + TLAN_HOST_CMD);
2271 data |= TLAN_HC_INT_OFF;
2272 outl(data, dev->base_addr + TLAN_HOST_CMD);
2273
2274/* 3. Clear AREGs and HASHs. */
2275
2276 for ( i = TLAN_AREG_0; i <= TLAN_HASH_2; i += 4 ) {
2277 TLan_DioWrite32( dev->base_addr, (u16) i, 0 );
2278 }
2279
2280/* 4. Setup NetConfig register. */
2281
2282 data = TLAN_NET_CFG_1FRAG | TLAN_NET_CFG_1CHAN | TLAN_NET_CFG_PHY_EN;
2283 TLan_DioWrite16( dev->base_addr, TLAN_NET_CONFIG, (u16) data );
2284
2285/* 5. Load Ld_Tmr and Ld_Thr in HOST_CMD. */
2286
2287 outl( TLAN_HC_LD_TMR | 0x3f, dev->base_addr + TLAN_HOST_CMD );
2288 outl( TLAN_HC_LD_THR | 0x9, dev->base_addr + TLAN_HOST_CMD );
2289
2290/* 6. Unreset the MII by setting NMRST (in NetSio) to 1. */
2291
2292 outw( TLAN_NET_SIO, dev->base_addr + TLAN_DIO_ADR );
2293 addr = dev->base_addr + TLAN_DIO_DATA + TLAN_NET_SIO;
2294 TLan_SetBit( TLAN_NET_SIO_NMRST, addr );
2295
2296/* 7. Setup the remaining registers. */
2297
2298 if ( priv->tlanRev >= 0x30 ) {
2299 data8 = TLAN_ID_TX_EOC | TLAN_ID_RX_EOC;
2300 TLan_DioWrite8( dev->base_addr, TLAN_INT_DIS, data8 );
2301 }
2302 TLan_PhyDetect( dev );
2303 data = TLAN_NET_CFG_1FRAG | TLAN_NET_CFG_1CHAN;
Jeff Garzik6aa20a22006-09-13 13:24:59 -04002304
Linus Torvalds1da177e2005-04-16 15:20:36 -07002305 if ( priv->adapter->flags & TLAN_ADAPTER_BIT_RATE_PHY ) {
2306 data |= TLAN_NET_CFG_BIT;
2307 if ( priv->aui == 1 ) {
2308 TLan_DioWrite8( dev->base_addr, TLAN_ACOMMIT, 0x0a );
2309 } else if ( priv->duplex == TLAN_DUPLEX_FULL ) {
2310 TLan_DioWrite8( dev->base_addr, TLAN_ACOMMIT, 0x00 );
2311 priv->tlanFullDuplex = TRUE;
2312 } else {
2313 TLan_DioWrite8( dev->base_addr, TLAN_ACOMMIT, 0x08 );
2314 }
2315 }
2316
2317 if ( priv->phyNum == 0 ) {
2318 data |= TLAN_NET_CFG_PHY_EN;
2319 }
2320 TLan_DioWrite16( dev->base_addr, TLAN_NET_CONFIG, (u16) data );
2321
2322 if ( priv->adapter->flags & TLAN_ADAPTER_UNMANAGED_PHY ) {
2323 TLan_FinishReset( dev );
2324 } else {
2325 TLan_PhyPowerDown( dev );
2326 }
2327
2328} /* TLan_ResetAdapter */
2329
2330
2331
2332
Harvey Harrison98e0f522008-02-18 10:04:38 -08002333static void
Linus Torvalds1da177e2005-04-16 15:20:36 -07002334TLan_FinishReset( struct net_device *dev )
2335{
2336 TLanPrivateInfo *priv = netdev_priv(dev);
2337 u8 data;
2338 u32 phy;
2339 u8 sio;
2340 u16 status;
2341 u16 partner;
2342 u16 tlphy_ctl;
2343 u16 tlphy_par;
2344 u16 tlphy_id1, tlphy_id2;
2345 int i;
2346
2347 phy = priv->phy[priv->phyNum];
2348
2349 data = TLAN_NET_CMD_NRESET | TLAN_NET_CMD_NWRAP;
2350 if ( priv->tlanFullDuplex ) {
2351 data |= TLAN_NET_CMD_DUPLEX;
2352 }
2353 TLan_DioWrite8( dev->base_addr, TLAN_NET_CMD, data );
Jeff Garzik6aa20a22006-09-13 13:24:59 -04002354 data = TLAN_NET_MASK_MASK4 | TLAN_NET_MASK_MASK5;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002355 if ( priv->phyNum == 0 ) {
Jeff Garzik6aa20a22006-09-13 13:24:59 -04002356 data |= TLAN_NET_MASK_MASK7;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002357 }
2358 TLan_DioWrite8( dev->base_addr, TLAN_NET_MASK, data );
2359 TLan_DioWrite16( dev->base_addr, TLAN_MAX_RX, ((1536)+7)&~7 );
2360 TLan_MiiReadReg( dev, phy, MII_GEN_ID_HI, &tlphy_id1 );
2361 TLan_MiiReadReg( dev, phy, MII_GEN_ID_LO, &tlphy_id2 );
Jeff Garzik6aa20a22006-09-13 13:24:59 -04002362
Stephen Hemmingerdfc2c0a2008-05-30 09:49:58 -07002363 if ( ( priv->adapter->flags & TLAN_ADAPTER_UNMANAGED_PHY ) ||
2364 ( priv->aui ) ) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002365 status = MII_GS_LINK;
2366 printk( "TLAN: %s: Link forced.\n", dev->name );
2367 } else {
2368 TLan_MiiReadReg( dev, phy, MII_GEN_STS, &status );
2369 udelay( 1000 );
2370 TLan_MiiReadReg( dev, phy, MII_GEN_STS, &status );
Stephen Hemmingerdfc2c0a2008-05-30 09:49:58 -07002371 if ( (status & MII_GS_LINK) &&
2372 /* We only support link info on Nat.Sem. PHY's */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002373 (tlphy_id1 == NAT_SEM_ID1) &&
2374 (tlphy_id2 == NAT_SEM_ID2) ) {
2375 TLan_MiiReadReg( dev, phy, MII_AN_LPA, &partner );
2376 TLan_MiiReadReg( dev, phy, TLAN_TLPHY_PAR, &tlphy_par );
Jeff Garzik6aa20a22006-09-13 13:24:59 -04002377
Linus Torvalds1da177e2005-04-16 15:20:36 -07002378 printk( "TLAN: %s: Link active with ", dev->name );
2379 if (!(tlphy_par & TLAN_PHY_AN_EN_STAT)) {
Jeff Garzik6aa20a22006-09-13 13:24:59 -04002380 printk( "forced 10%sMbps %s-Duplex\n",
Stephen Hemmingerdfc2c0a2008-05-30 09:49:58 -07002381 tlphy_par & TLAN_PHY_SPEED_100 ? "" : "0",
2382 tlphy_par & TLAN_PHY_DUPLEX_FULL ? "Full" : "Half");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002383 } else {
2384 printk( "AutoNegotiation enabled, at 10%sMbps %s-Duplex\n",
Stephen Hemmingerdfc2c0a2008-05-30 09:49:58 -07002385 tlphy_par & TLAN_PHY_SPEED_100 ? "" : "0",
2386 tlphy_par & TLAN_PHY_DUPLEX_FULL ? "Full" : "Half");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002387 printk("TLAN: Partner capability: ");
2388 for (i = 5; i <= 10; i++)
2389 if (partner & (1<<i))
2390 printk("%s",media[i-5]);
2391 printk("\n");
2392 }
2393
2394 TLan_DioWrite8( dev->base_addr, TLAN_LED_REG, TLAN_LED_LINK );
Jeff Garzik6aa20a22006-09-13 13:24:59 -04002395#ifdef MONITOR
Linus Torvalds1da177e2005-04-16 15:20:36 -07002396 /* We have link beat..for now anyway */
2397 priv->link = 1;
2398 /*Enabling link beat monitoring */
2399 TLan_SetTimer( dev, (10*HZ), TLAN_TIMER_LINK_BEAT );
Jeff Garzik6aa20a22006-09-13 13:24:59 -04002400#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -07002401 } else if (status & MII_GS_LINK) {
2402 printk( "TLAN: %s: Link active\n", dev->name );
2403 TLan_DioWrite8( dev->base_addr, TLAN_LED_REG, TLAN_LED_LINK );
2404 }
2405 }
2406
2407 if ( priv->phyNum == 0 ) {
2408 TLan_MiiReadReg( dev, phy, TLAN_TLPHY_CTL, &tlphy_ctl );
2409 tlphy_ctl |= TLAN_TC_INTEN;
2410 TLan_MiiWriteReg( dev, phy, TLAN_TLPHY_CTL, tlphy_ctl );
2411 sio = TLan_DioRead8( dev->base_addr, TLAN_NET_SIO );
2412 sio |= TLAN_NET_SIO_MINTEN;
2413 TLan_DioWrite8( dev->base_addr, TLAN_NET_SIO, sio );
2414 }
2415
2416 if ( status & MII_GS_LINK ) {
2417 TLan_SetMac( dev, 0, dev->dev_addr );
2418 priv->phyOnline = 1;
2419 outb( ( TLAN_HC_INT_ON >> 8 ), dev->base_addr + TLAN_HOST_CMD + 1 );
2420 if ( debug >= 1 && debug != TLAN_DEBUG_PROBE ) {
2421 outb( ( TLAN_HC_REQ_INT >> 8 ), dev->base_addr + TLAN_HOST_CMD + 1 );
2422 }
2423 outl( priv->rxListDMA, dev->base_addr + TLAN_CH_PARM );
2424 outl( TLAN_HC_GO | TLAN_HC_RT, dev->base_addr + TLAN_HOST_CMD );
2425 netif_carrier_on(dev);
2426 } else {
Stephen Hemmingerdfc2c0a2008-05-30 09:49:58 -07002427 printk( "TLAN: %s: Link inactive, will retry in 10 secs...\n",
2428 dev->name );
Linus Torvalds1da177e2005-04-16 15:20:36 -07002429 TLan_SetTimer( dev, (10*HZ), TLAN_TIMER_FINISH_RESET );
2430 return;
2431 }
James Harper562faf42005-05-05 15:14:18 -07002432 TLan_SetMulticastList(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002433
2434} /* TLan_FinishReset */
2435
2436
2437
2438
2439 /***************************************************************
2440 * TLan_SetMac
2441 *
2442 * Returns:
2443 * Nothing
2444 * Parms:
2445 * dev Pointer to device structure of adapter
2446 * on which to change the AREG.
2447 * areg The AREG to set the address in (0 - 3).
2448 * mac A pointer to an array of chars. Each
2449 * element stores one byte of the address.
2450 * IE, it isn't in ascii.
2451 *
2452 * This function transfers a MAC address to one of the
2453 * TLAN AREGs (address registers). The TLAN chip locks
2454 * the register on writing to offset 0 and unlocks the
2455 * register after writing to offset 5. If NULL is passed
2456 * in mac, then the AREG is filled with 0's.
2457 *
2458 **************************************************************/
2459
Harvey Harrison98e0f522008-02-18 10:04:38 -08002460static void TLan_SetMac( struct net_device *dev, int areg, char *mac )
Linus Torvalds1da177e2005-04-16 15:20:36 -07002461{
2462 int i;
Jeff Garzik6aa20a22006-09-13 13:24:59 -04002463
Linus Torvalds1da177e2005-04-16 15:20:36 -07002464 areg *= 6;
2465
2466 if ( mac != NULL ) {
2467 for ( i = 0; i < 6; i++ )
Stephen Hemmingerdfc2c0a2008-05-30 09:49:58 -07002468 TLan_DioWrite8( dev->base_addr,
2469 TLAN_AREG_0 + areg + i, mac[i] );
Linus Torvalds1da177e2005-04-16 15:20:36 -07002470 } else {
2471 for ( i = 0; i < 6; i++ )
Stephen Hemmingerdfc2c0a2008-05-30 09:49:58 -07002472 TLan_DioWrite8( dev->base_addr,
2473 TLAN_AREG_0 + areg + i, 0 );
Linus Torvalds1da177e2005-04-16 15:20:36 -07002474 }
2475
2476} /* TLan_SetMac */
2477
2478
2479
2480
2481/*****************************************************************************
2482******************************************************************************
2483
2484 ThunderLAN Driver PHY Layer Routines
2485
2486******************************************************************************
2487*****************************************************************************/
2488
2489
2490
2491 /*********************************************************************
2492 * TLan_PhyPrint
2493 *
2494 * Returns:
2495 * Nothing
2496 * Parms:
2497 * dev A pointer to the device structure of the
2498 * TLAN device having the PHYs to be detailed.
Jeff Garzik6aa20a22006-09-13 13:24:59 -04002499 *
Linus Torvalds1da177e2005-04-16 15:20:36 -07002500 * This function prints the registers a PHY (aka transceiver).
2501 *
2502 ********************************************************************/
2503
Harvey Harrison98e0f522008-02-18 10:04:38 -08002504static void TLan_PhyPrint( struct net_device *dev )
Linus Torvalds1da177e2005-04-16 15:20:36 -07002505{
2506 TLanPrivateInfo *priv = netdev_priv(dev);
2507 u16 i, data0, data1, data2, data3, phy;
2508
2509 phy = priv->phy[priv->phyNum];
2510
2511 if ( priv->adapter->flags & TLAN_ADAPTER_UNMANAGED_PHY ) {
2512 printk( "TLAN: Device %s, Unmanaged PHY.\n", dev->name );
2513 } else if ( phy <= TLAN_PHY_MAX_ADDR ) {
2514 printk( "TLAN: Device %s, PHY 0x%02x.\n", dev->name, phy );
2515 printk( "TLAN: Off. +0 +1 +2 +3 \n" );
2516 for ( i = 0; i < 0x20; i+= 4 ) {
2517 printk( "TLAN: 0x%02x", i );
2518 TLan_MiiReadReg( dev, phy, i, &data0 );
2519 printk( " 0x%04hx", data0 );
2520 TLan_MiiReadReg( dev, phy, i + 1, &data1 );
2521 printk( " 0x%04hx", data1 );
2522 TLan_MiiReadReg( dev, phy, i + 2, &data2 );
2523 printk( " 0x%04hx", data2 );
2524 TLan_MiiReadReg( dev, phy, i + 3, &data3 );
2525 printk( " 0x%04hx\n", data3 );
2526 }
2527 } else {
2528 printk( "TLAN: Device %s, Invalid PHY.\n", dev->name );
2529 }
2530
2531} /* TLan_PhyPrint */
2532
2533
2534
2535
2536 /*********************************************************************
2537 * TLan_PhyDetect
2538 *
2539 * Returns:
2540 * Nothing
2541 * Parms:
2542 * dev A pointer to the device structure of the adapter
2543 * for which the PHY needs determined.
2544 *
2545 * So far I've found that adapters which have external PHYs
2546 * may also use the internal PHY for part of the functionality.
2547 * (eg, AUI/Thinnet). This function finds out if this TLAN
2548 * chip has an internal PHY, and then finds the first external
2549 * PHY (starting from address 0) if it exists).
2550 *
2551 ********************************************************************/
2552
Harvey Harrison98e0f522008-02-18 10:04:38 -08002553static void TLan_PhyDetect( struct net_device *dev )
Linus Torvalds1da177e2005-04-16 15:20:36 -07002554{
2555 TLanPrivateInfo *priv = netdev_priv(dev);
2556 u16 control;
2557 u16 hi;
2558 u16 lo;
2559 u32 phy;
2560
2561 if ( priv->adapter->flags & TLAN_ADAPTER_UNMANAGED_PHY ) {
2562 priv->phyNum = 0xFFFF;
2563 return;
2564 }
2565
2566 TLan_MiiReadReg( dev, TLAN_PHY_MAX_ADDR, MII_GEN_ID_HI, &hi );
Jeff Garzik6aa20a22006-09-13 13:24:59 -04002567
Linus Torvalds1da177e2005-04-16 15:20:36 -07002568 if ( hi != 0xFFFF ) {
2569 priv->phy[0] = TLAN_PHY_MAX_ADDR;
2570 } else {
2571 priv->phy[0] = TLAN_PHY_NONE;
2572 }
2573
2574 priv->phy[1] = TLAN_PHY_NONE;
2575 for ( phy = 0; phy <= TLAN_PHY_MAX_ADDR; phy++ ) {
2576 TLan_MiiReadReg( dev, phy, MII_GEN_CTL, &control );
2577 TLan_MiiReadReg( dev, phy, MII_GEN_ID_HI, &hi );
2578 TLan_MiiReadReg( dev, phy, MII_GEN_ID_LO, &lo );
Stephen Hemmingerdfc2c0a2008-05-30 09:49:58 -07002579 if ( ( control != 0xFFFF ) ||
2580 ( hi != 0xFFFF ) || ( lo != 0xFFFF ) ) {
2581 TLAN_DBG( TLAN_DEBUG_GNRL,
2582 "PHY found at %02x %04x %04x %04x\n",
2583 phy, control, hi, lo );
2584 if ( ( priv->phy[1] == TLAN_PHY_NONE ) &&
2585 ( phy != TLAN_PHY_MAX_ADDR ) ) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002586 priv->phy[1] = phy;
2587 }
2588 }
2589 }
2590
2591 if ( priv->phy[1] != TLAN_PHY_NONE ) {
2592 priv->phyNum = 1;
2593 } else if ( priv->phy[0] != TLAN_PHY_NONE ) {
2594 priv->phyNum = 0;
2595 } else {
2596 printk( "TLAN: Cannot initialize device, no PHY was found!\n" );
2597 }
2598
2599} /* TLan_PhyDetect */
2600
2601
2602
2603
Harvey Harrison98e0f522008-02-18 10:04:38 -08002604static void TLan_PhyPowerDown( struct net_device *dev )
Linus Torvalds1da177e2005-04-16 15:20:36 -07002605{
2606 TLanPrivateInfo *priv = netdev_priv(dev);
2607 u16 value;
2608
2609 TLAN_DBG( TLAN_DEBUG_GNRL, "%s: Powering down PHY(s).\n", dev->name );
2610 value = MII_GC_PDOWN | MII_GC_LOOPBK | MII_GC_ISOLATE;
2611 TLan_MiiSync( dev->base_addr );
2612 TLan_MiiWriteReg( dev, priv->phy[priv->phyNum], MII_GEN_CTL, value );
Stephen Hemmingerdfc2c0a2008-05-30 09:49:58 -07002613 if ( ( priv->phyNum == 0 ) &&
2614 ( priv->phy[1] != TLAN_PHY_NONE ) &&
2615 ( ! ( priv->adapter->flags & TLAN_ADAPTER_USE_INTERN_10 ) ) ) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002616 TLan_MiiSync( dev->base_addr );
2617 TLan_MiiWriteReg( dev, priv->phy[1], MII_GEN_CTL, value );
2618 }
2619
2620 /* Wait for 50 ms and powerup
2621 * This is abitrary. It is intended to make sure the
2622 * transceiver settles.
2623 */
2624 TLan_SetTimer( dev, (HZ/20), TLAN_TIMER_PHY_PUP );
2625
2626} /* TLan_PhyPowerDown */
2627
2628
2629
2630
Harvey Harrison98e0f522008-02-18 10:04:38 -08002631static void TLan_PhyPowerUp( struct net_device *dev )
Linus Torvalds1da177e2005-04-16 15:20:36 -07002632{
2633 TLanPrivateInfo *priv = netdev_priv(dev);
2634 u16 value;
2635
2636 TLAN_DBG( TLAN_DEBUG_GNRL, "%s: Powering up PHY.\n", dev->name );
2637 TLan_MiiSync( dev->base_addr );
2638 value = MII_GC_LOOPBK;
2639 TLan_MiiWriteReg( dev, priv->phy[priv->phyNum], MII_GEN_CTL, value );
2640 TLan_MiiSync(dev->base_addr);
2641 /* Wait for 500 ms and reset the
2642 * transceiver. The TLAN docs say both 50 ms and
2643 * 500 ms, so do the longer, just in case.
2644 */
2645 TLan_SetTimer( dev, (HZ/20), TLAN_TIMER_PHY_RESET );
2646
2647} /* TLan_PhyPowerUp */
2648
2649
2650
2651
Harvey Harrison98e0f522008-02-18 10:04:38 -08002652static void TLan_PhyReset( struct net_device *dev )
Linus Torvalds1da177e2005-04-16 15:20:36 -07002653{
2654 TLanPrivateInfo *priv = netdev_priv(dev);
2655 u16 phy;
2656 u16 value;
2657
2658 phy = priv->phy[priv->phyNum];
2659
2660 TLAN_DBG( TLAN_DEBUG_GNRL, "%s: Reseting PHY.\n", dev->name );
2661 TLan_MiiSync( dev->base_addr );
2662 value = MII_GC_LOOPBK | MII_GC_RESET;
2663 TLan_MiiWriteReg( dev, phy, MII_GEN_CTL, value );
2664 TLan_MiiReadReg( dev, phy, MII_GEN_CTL, &value );
2665 while ( value & MII_GC_RESET ) {
2666 TLan_MiiReadReg( dev, phy, MII_GEN_CTL, &value );
2667 }
2668
2669 /* Wait for 500 ms and initialize.
2670 * I don't remember why I wait this long.
2671 * I've changed this to 50ms, as it seems long enough.
2672 */
2673 TLan_SetTimer( dev, (HZ/20), TLAN_TIMER_PHY_START_LINK );
2674
2675} /* TLan_PhyReset */
2676
2677
2678
2679
Harvey Harrison98e0f522008-02-18 10:04:38 -08002680static void TLan_PhyStartLink( struct net_device *dev )
Linus Torvalds1da177e2005-04-16 15:20:36 -07002681{
2682 TLanPrivateInfo *priv = netdev_priv(dev);
2683 u16 ability;
2684 u16 control;
2685 u16 data;
2686 u16 phy;
2687 u16 status;
2688 u16 tctl;
2689
2690 phy = priv->phy[priv->phyNum];
2691 TLAN_DBG( TLAN_DEBUG_GNRL, "%s: Trying to activate link.\n", dev->name );
2692 TLan_MiiReadReg( dev, phy, MII_GEN_STS, &status );
2693 TLan_MiiReadReg( dev, phy, MII_GEN_STS, &ability );
2694
Jeff Garzik6aa20a22006-09-13 13:24:59 -04002695 if ( ( status & MII_GS_AUTONEG ) &&
Linus Torvalds1da177e2005-04-16 15:20:36 -07002696 ( ! priv->aui ) ) {
2697 ability = status >> 11;
Jeff Garzik6aa20a22006-09-13 13:24:59 -04002698 if ( priv->speed == TLAN_SPEED_10 &&
Linus Torvalds1da177e2005-04-16 15:20:36 -07002699 priv->duplex == TLAN_DUPLEX_HALF) {
2700 TLan_MiiWriteReg( dev, phy, MII_GEN_CTL, 0x0000);
2701 } else if ( priv->speed == TLAN_SPEED_10 &&
2702 priv->duplex == TLAN_DUPLEX_FULL) {
2703 priv->tlanFullDuplex = TRUE;
2704 TLan_MiiWriteReg( dev, phy, MII_GEN_CTL, 0x0100);
2705 } else if ( priv->speed == TLAN_SPEED_100 &&
2706 priv->duplex == TLAN_DUPLEX_HALF) {
2707 TLan_MiiWriteReg( dev, phy, MII_GEN_CTL, 0x2000);
2708 } else if ( priv->speed == TLAN_SPEED_100 &&
2709 priv->duplex == TLAN_DUPLEX_FULL) {
2710 priv->tlanFullDuplex = TRUE;
2711 TLan_MiiWriteReg( dev, phy, MII_GEN_CTL, 0x2100);
2712 } else {
Jeff Garzik6aa20a22006-09-13 13:24:59 -04002713
Linus Torvalds1da177e2005-04-16 15:20:36 -07002714 /* Set Auto-Neg advertisement */
2715 TLan_MiiWriteReg( dev, phy, MII_AN_ADV, (ability << 5) | 1);
2716 /* Enablee Auto-Neg */
2717 TLan_MiiWriteReg( dev, phy, MII_GEN_CTL, 0x1000 );
2718 /* Restart Auto-Neg */
2719 TLan_MiiWriteReg( dev, phy, MII_GEN_CTL, 0x1200 );
2720 /* Wait for 4 sec for autonegotiation
2721 * to complete. The max spec time is less than this
2722 * but the card need additional time to start AN.
2723 * .5 sec should be plenty extra.
2724 */
2725 printk( "TLAN: %s: Starting autonegotiation.\n", dev->name );
2726 TLan_SetTimer( dev, (2*HZ), TLAN_TIMER_PHY_FINISH_AN );
2727 return;
2728 }
Jeff Garzik6aa20a22006-09-13 13:24:59 -04002729
2730 }
2731
Linus Torvalds1da177e2005-04-16 15:20:36 -07002732 if ( ( priv->aui ) && ( priv->phyNum != 0 ) ) {
2733 priv->phyNum = 0;
2734 data = TLAN_NET_CFG_1FRAG | TLAN_NET_CFG_1CHAN | TLAN_NET_CFG_PHY_EN;
2735 TLan_DioWrite16( dev->base_addr, TLAN_NET_CONFIG, data );
2736 TLan_SetTimer( dev, (40*HZ/1000), TLAN_TIMER_PHY_PDOWN );
2737 return;
2738 } else if ( priv->phyNum == 0 ) {
2739 control = 0;
2740 TLan_MiiReadReg( dev, phy, TLAN_TLPHY_CTL, &tctl );
2741 if ( priv->aui ) {
2742 tctl |= TLAN_TC_AUISEL;
Jeff Garzik6aa20a22006-09-13 13:24:59 -04002743 } else {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002744 tctl &= ~TLAN_TC_AUISEL;
2745 if ( priv->duplex == TLAN_DUPLEX_FULL ) {
2746 control |= MII_GC_DUPLEX;
2747 priv->tlanFullDuplex = TRUE;
2748 }
2749 if ( priv->speed == TLAN_SPEED_100 ) {
2750 control |= MII_GC_SPEEDSEL;
2751 }
2752 }
2753 TLan_MiiWriteReg( dev, phy, MII_GEN_CTL, control );
2754 TLan_MiiWriteReg( dev, phy, TLAN_TLPHY_CTL, tctl );
2755 }
2756
2757 /* Wait for 2 sec to give the transceiver time
2758 * to establish link.
2759 */
2760 TLan_SetTimer( dev, (4*HZ), TLAN_TIMER_FINISH_RESET );
2761
2762} /* TLan_PhyStartLink */
2763
2764
2765
2766
Harvey Harrison98e0f522008-02-18 10:04:38 -08002767static void TLan_PhyFinishAutoNeg( struct net_device *dev )
Linus Torvalds1da177e2005-04-16 15:20:36 -07002768{
2769 TLanPrivateInfo *priv = netdev_priv(dev);
2770 u16 an_adv;
2771 u16 an_lpa;
2772 u16 data;
2773 u16 mode;
2774 u16 phy;
2775 u16 status;
Jeff Garzik6aa20a22006-09-13 13:24:59 -04002776
Linus Torvalds1da177e2005-04-16 15:20:36 -07002777 phy = priv->phy[priv->phyNum];
2778
2779 TLan_MiiReadReg( dev, phy, MII_GEN_STS, &status );
2780 udelay( 1000 );
2781 TLan_MiiReadReg( dev, phy, MII_GEN_STS, &status );
2782
2783 if ( ! ( status & MII_GS_AUTOCMPLT ) ) {
2784 /* Wait for 8 sec to give the process
2785 * more time. Perhaps we should fail after a while.
2786 */
2787 if (!priv->neg_be_verbose++) {
Stephen Hemmingerdfc2c0a2008-05-30 09:49:58 -07002788 pr_info("TLAN: Giving autonegotiation more time.\n");
2789 pr_info("TLAN: Please check that your adapter has\n");
2790 pr_info("TLAN: been properly connected to a HUB or Switch.\n");
2791 pr_info("TLAN: Trying to establish link in the background...\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002792 }
2793 TLan_SetTimer( dev, (8*HZ), TLAN_TIMER_PHY_FINISH_AN );
2794 return;
2795 }
2796
2797 printk( "TLAN: %s: Autonegotiation complete.\n", dev->name );
2798 TLan_MiiReadReg( dev, phy, MII_AN_ADV, &an_adv );
2799 TLan_MiiReadReg( dev, phy, MII_AN_LPA, &an_lpa );
2800 mode = an_adv & an_lpa & 0x03E0;
2801 if ( mode & 0x0100 ) {
2802 priv->tlanFullDuplex = TRUE;
2803 } else if ( ! ( mode & 0x0080 ) && ( mode & 0x0040 ) ) {
2804 priv->tlanFullDuplex = TRUE;
2805 }
2806
Stephen Hemmingerdfc2c0a2008-05-30 09:49:58 -07002807 if ( ( ! ( mode & 0x0180 ) ) &&
2808 ( priv->adapter->flags & TLAN_ADAPTER_USE_INTERN_10 ) &&
2809 ( priv->phyNum != 0 ) ) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002810 priv->phyNum = 0;
2811 data = TLAN_NET_CFG_1FRAG | TLAN_NET_CFG_1CHAN | TLAN_NET_CFG_PHY_EN;
2812 TLan_DioWrite16( dev->base_addr, TLAN_NET_CONFIG, data );
2813 TLan_SetTimer( dev, (400*HZ/1000), TLAN_TIMER_PHY_PDOWN );
2814 return;
2815 }
2816
2817 if ( priv->phyNum == 0 ) {
Stephen Hemmingerdfc2c0a2008-05-30 09:49:58 -07002818 if ( ( priv->duplex == TLAN_DUPLEX_FULL ) ||
2819 ( an_adv & an_lpa & 0x0040 ) ) {
2820 TLan_MiiWriteReg( dev, phy, MII_GEN_CTL,
2821 MII_GC_AUTOENB | MII_GC_DUPLEX );
2822 pr_info("TLAN: Starting internal PHY with FULL-DUPLEX\n" );
Linus Torvalds1da177e2005-04-16 15:20:36 -07002823 } else {
2824 TLan_MiiWriteReg( dev, phy, MII_GEN_CTL, MII_GC_AUTOENB );
Stephen Hemmingerdfc2c0a2008-05-30 09:49:58 -07002825 pr_info( "TLAN: Starting internal PHY with HALF-DUPLEX\n" );
Linus Torvalds1da177e2005-04-16 15:20:36 -07002826 }
2827 }
2828
2829 /* Wait for 100 ms. No reason in partiticular.
2830 */
2831 TLan_SetTimer( dev, (HZ/10), TLAN_TIMER_FINISH_RESET );
Jeff Garzik6aa20a22006-09-13 13:24:59 -04002832
Linus Torvalds1da177e2005-04-16 15:20:36 -07002833} /* TLan_PhyFinishAutoNeg */
2834
2835#ifdef MONITOR
2836
2837 /*********************************************************************
2838 *
2839 * TLan_phyMonitor
2840 *
Jeff Garzik6aa20a22006-09-13 13:24:59 -04002841 * Returns:
Linus Torvalds1da177e2005-04-16 15:20:36 -07002842 * None
2843 *
2844 * Params:
2845 * dev The device structure of this device.
2846 *
Jeff Garzik6aa20a22006-09-13 13:24:59 -04002847 *
Linus Torvalds1da177e2005-04-16 15:20:36 -07002848 * This function monitors PHY condition by reading the status
2849 * register via the MII bus. This can be used to give info
2850 * about link changes (up/down), and possible switch to alternate
2851 * media.
2852 *
2853 * ******************************************************************/
2854
2855void TLan_PhyMonitor( struct net_device *dev )
2856{
2857 TLanPrivateInfo *priv = netdev_priv(dev);
2858 u16 phy;
2859 u16 phy_status;
2860
2861 phy = priv->phy[priv->phyNum];
2862
2863 /* Get PHY status register */
2864 TLan_MiiReadReg( dev, phy, MII_GEN_STS, &phy_status );
2865
2866 /* Check if link has been lost */
Jeff Garzik6aa20a22006-09-13 13:24:59 -04002867 if (!(phy_status & MII_GS_LINK)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002868 if (priv->link) {
2869 priv->link = 0;
2870 printk(KERN_DEBUG "TLAN: %s has lost link\n", dev->name);
7d17c1d2005-05-12 19:45:25 -04002871 netif_carrier_off(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002872 TLan_SetTimer( dev, (2*HZ), TLAN_TIMER_LINK_BEAT );
2873 return;
2874 }
2875 }
2876
2877 /* Link restablished? */
2878 if ((phy_status & MII_GS_LINK) && !priv->link) {
2879 priv->link = 1;
2880 printk(KERN_DEBUG "TLAN: %s has reestablished link\n", dev->name);
7d17c1d2005-05-12 19:45:25 -04002881 netif_carrier_on(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002882 }
2883
2884 /* Setup a new monitor */
2885 TLan_SetTimer( dev, (2*HZ), TLAN_TIMER_LINK_BEAT );
Jeff Garzik6aa20a22006-09-13 13:24:59 -04002886}
Linus Torvalds1da177e2005-04-16 15:20:36 -07002887
2888#endif /* MONITOR */
2889
2890
2891/*****************************************************************************
2892******************************************************************************
2893
2894 ThunderLAN Driver MII Routines
2895
2896 These routines are based on the information in Chap. 2 of the
2897 "ThunderLAN Programmer's Guide", pp. 15-24.
2898
2899******************************************************************************
2900*****************************************************************************/
2901
2902
2903 /***************************************************************
2904 * TLan_MiiReadReg
2905 *
2906 * Returns:
2907 * 0 if ack received ok
2908 * 1 otherwise.
2909 *
2910 * Parms:
2911 * dev The device structure containing
2912 * The io address and interrupt count
2913 * for this device.
2914 * phy The address of the PHY to be queried.
2915 * reg The register whose contents are to be
Matt Mackall4a4efbd2006-01-03 13:27:11 +01002916 * retrieved.
Linus Torvalds1da177e2005-04-16 15:20:36 -07002917 * val A pointer to a variable to store the
2918 * retrieved value.
2919 *
Matt Mackall4a4efbd2006-01-03 13:27:11 +01002920 * This function uses the TLAN's MII bus to retrieve the contents
Linus Torvalds1da177e2005-04-16 15:20:36 -07002921 * of a given register on a PHY. It sends the appropriate info
2922 * and then reads the 16-bit register value from the MII bus via
2923 * the TLAN SIO register.
2924 *
2925 **************************************************************/
2926
Harvey Harrison98e0f522008-02-18 10:04:38 -08002927static int TLan_MiiReadReg( struct net_device *dev, u16 phy, u16 reg, u16 *val )
Linus Torvalds1da177e2005-04-16 15:20:36 -07002928{
2929 u8 nack;
2930 u16 sio, tmp;
2931 u32 i;
2932 int err;
2933 int minten;
2934 TLanPrivateInfo *priv = netdev_priv(dev);
2935 unsigned long flags = 0;
2936
2937 err = FALSE;
2938 outw(TLAN_NET_SIO, dev->base_addr + TLAN_DIO_ADR);
2939 sio = dev->base_addr + TLAN_DIO_DATA + TLAN_NET_SIO;
Jeff Garzik6aa20a22006-09-13 13:24:59 -04002940
Linus Torvalds1da177e2005-04-16 15:20:36 -07002941 if (!in_irq())
2942 spin_lock_irqsave(&priv->lock, flags);
2943
2944 TLan_MiiSync(dev->base_addr);
2945
2946 minten = TLan_GetBit( TLAN_NET_SIO_MINTEN, sio );
2947 if ( minten )
2948 TLan_ClearBit(TLAN_NET_SIO_MINTEN, sio);
2949
2950 TLan_MiiSendData( dev->base_addr, 0x1, 2 ); /* Start ( 01b ) */
2951 TLan_MiiSendData( dev->base_addr, 0x2, 2 ); /* Read ( 10b ) */
2952 TLan_MiiSendData( dev->base_addr, phy, 5 ); /* Device # */
2953 TLan_MiiSendData( dev->base_addr, reg, 5 ); /* Register # */
2954
2955
2956 TLan_ClearBit(TLAN_NET_SIO_MTXEN, sio); /* Change direction */
2957
2958 TLan_ClearBit(TLAN_NET_SIO_MCLK, sio); /* Clock Idle bit */
2959 TLan_SetBit(TLAN_NET_SIO_MCLK, sio);
2960 TLan_ClearBit(TLAN_NET_SIO_MCLK, sio); /* Wait 300ns */
2961
2962 nack = TLan_GetBit(TLAN_NET_SIO_MDATA, sio); /* Check for ACK */
2963 TLan_SetBit(TLAN_NET_SIO_MCLK, sio); /* Finish ACK */
2964 if (nack) { /* No ACK, so fake it */
2965 for (i = 0; i < 16; i++) {
2966 TLan_ClearBit(TLAN_NET_SIO_MCLK, sio);
2967 TLan_SetBit(TLAN_NET_SIO_MCLK, sio);
2968 }
2969 tmp = 0xffff;
2970 err = TRUE;
2971 } else { /* ACK, so read data */
2972 for (tmp = 0, i = 0x8000; i; i >>= 1) {
2973 TLan_ClearBit(TLAN_NET_SIO_MCLK, sio);
2974 if (TLan_GetBit(TLAN_NET_SIO_MDATA, sio))
2975 tmp |= i;
2976 TLan_SetBit(TLAN_NET_SIO_MCLK, sio);
2977 }
2978 }
2979
2980
2981 TLan_ClearBit(TLAN_NET_SIO_MCLK, sio); /* Idle cycle */
2982 TLan_SetBit(TLAN_NET_SIO_MCLK, sio);
2983
2984 if ( minten )
2985 TLan_SetBit(TLAN_NET_SIO_MINTEN, sio);
2986
2987 *val = tmp;
Jeff Garzik6aa20a22006-09-13 13:24:59 -04002988
Linus Torvalds1da177e2005-04-16 15:20:36 -07002989 if (!in_irq())
2990 spin_unlock_irqrestore(&priv->lock, flags);
2991
2992 return err;
2993
2994} /* TLan_MiiReadReg */
2995
2996
2997
2998
2999 /***************************************************************
3000 * TLan_MiiSendData
3001 *
3002 * Returns:
3003 * Nothing
3004 * Parms:
3005 * base_port The base IO port of the adapter in
3006 * question.
3007 * dev The address of the PHY to be queried.
3008 * data The value to be placed on the MII bus.
3009 * num_bits The number of bits in data that are to
3010 * be placed on the MII bus.
3011 *
3012 * This function sends on sequence of bits on the MII
3013 * configuration bus.
3014 *
3015 **************************************************************/
3016
Harvey Harrison98e0f522008-02-18 10:04:38 -08003017static void TLan_MiiSendData( u16 base_port, u32 data, unsigned num_bits )
Linus Torvalds1da177e2005-04-16 15:20:36 -07003018{
3019 u16 sio;
3020 u32 i;
3021
3022 if ( num_bits == 0 )
3023 return;
3024
3025 outw( TLAN_NET_SIO, base_port + TLAN_DIO_ADR );
3026 sio = base_port + TLAN_DIO_DATA + TLAN_NET_SIO;
3027 TLan_SetBit( TLAN_NET_SIO_MTXEN, sio );
3028
3029 for ( i = ( 0x1 << ( num_bits - 1 ) ); i; i >>= 1 ) {
3030 TLan_ClearBit( TLAN_NET_SIO_MCLK, sio );
3031 (void) TLan_GetBit( TLAN_NET_SIO_MCLK, sio );
3032 if ( data & i )
3033 TLan_SetBit( TLAN_NET_SIO_MDATA, sio );
3034 else
3035 TLan_ClearBit( TLAN_NET_SIO_MDATA, sio );
3036 TLan_SetBit( TLAN_NET_SIO_MCLK, sio );
3037 (void) TLan_GetBit( TLAN_NET_SIO_MCLK, sio );
3038 }
3039
3040} /* TLan_MiiSendData */
3041
3042
3043
3044
3045 /***************************************************************
3046 * TLan_MiiSync
3047 *
3048 * Returns:
3049 * Nothing
3050 * Parms:
3051 * base_port The base IO port of the adapter in
3052 * question.
3053 *
3054 * This functions syncs all PHYs in terms of the MII configuration
3055 * bus.
3056 *
3057 **************************************************************/
3058
Harvey Harrison98e0f522008-02-18 10:04:38 -08003059static void TLan_MiiSync( u16 base_port )
Linus Torvalds1da177e2005-04-16 15:20:36 -07003060{
3061 int i;
3062 u16 sio;
3063
3064 outw( TLAN_NET_SIO, base_port + TLAN_DIO_ADR );
3065 sio = base_port + TLAN_DIO_DATA + TLAN_NET_SIO;
3066
3067 TLan_ClearBit( TLAN_NET_SIO_MTXEN, sio );
3068 for ( i = 0; i < 32; i++ ) {
3069 TLan_ClearBit( TLAN_NET_SIO_MCLK, sio );
3070 TLan_SetBit( TLAN_NET_SIO_MCLK, sio );
3071 }
3072
3073} /* TLan_MiiSync */
3074
3075
3076
3077
3078 /***************************************************************
3079 * TLan_MiiWriteReg
3080 *
3081 * Returns:
3082 * Nothing
3083 * Parms:
3084 * dev The device structure for the device
3085 * to write to.
3086 * phy The address of the PHY to be written to.
3087 * reg The register whose contents are to be
3088 * written.
3089 * val The value to be written to the register.
3090 *
3091 * This function uses the TLAN's MII bus to write the contents of a
3092 * given register on a PHY. It sends the appropriate info and then
3093 * writes the 16-bit register value from the MII configuration bus
3094 * via the TLAN SIO register.
3095 *
3096 **************************************************************/
3097
Harvey Harrison98e0f522008-02-18 10:04:38 -08003098static void TLan_MiiWriteReg( struct net_device *dev, u16 phy, u16 reg, u16 val )
Linus Torvalds1da177e2005-04-16 15:20:36 -07003099{
3100 u16 sio;
3101 int minten;
3102 unsigned long flags = 0;
3103 TLanPrivateInfo *priv = netdev_priv(dev);
3104
3105 outw(TLAN_NET_SIO, dev->base_addr + TLAN_DIO_ADR);
3106 sio = dev->base_addr + TLAN_DIO_DATA + TLAN_NET_SIO;
Jeff Garzik6aa20a22006-09-13 13:24:59 -04003107
Linus Torvalds1da177e2005-04-16 15:20:36 -07003108 if (!in_irq())
3109 spin_lock_irqsave(&priv->lock, flags);
3110
3111 TLan_MiiSync( dev->base_addr );
3112
3113 minten = TLan_GetBit( TLAN_NET_SIO_MINTEN, sio );
3114 if ( minten )
3115 TLan_ClearBit( TLAN_NET_SIO_MINTEN, sio );
3116
3117 TLan_MiiSendData( dev->base_addr, 0x1, 2 ); /* Start ( 01b ) */
3118 TLan_MiiSendData( dev->base_addr, 0x1, 2 ); /* Write ( 01b ) */
3119 TLan_MiiSendData( dev->base_addr, phy, 5 ); /* Device # */
3120 TLan_MiiSendData( dev->base_addr, reg, 5 ); /* Register # */
3121
3122 TLan_MiiSendData( dev->base_addr, 0x2, 2 ); /* Send ACK */
3123 TLan_MiiSendData( dev->base_addr, val, 16 ); /* Send Data */
3124
3125 TLan_ClearBit( TLAN_NET_SIO_MCLK, sio ); /* Idle cycle */
3126 TLan_SetBit( TLAN_NET_SIO_MCLK, sio );
3127
3128 if ( minten )
3129 TLan_SetBit( TLAN_NET_SIO_MINTEN, sio );
Jeff Garzik6aa20a22006-09-13 13:24:59 -04003130
Linus Torvalds1da177e2005-04-16 15:20:36 -07003131 if (!in_irq())
3132 spin_unlock_irqrestore(&priv->lock, flags);
3133
3134} /* TLan_MiiWriteReg */
3135
3136
3137
3138
3139/*****************************************************************************
3140******************************************************************************
3141
3142 ThunderLAN Driver Eeprom routines
3143
3144 The Compaq Netelligent 10 and 10/100 cards use a Microchip 24C02A
3145 EEPROM. These functions are based on information in Microchip's
3146 data sheet. I don't know how well this functions will work with
3147 other EEPROMs.
3148
3149******************************************************************************
3150*****************************************************************************/
3151
3152
3153 /***************************************************************
3154 * TLan_EeSendStart
3155 *
3156 * Returns:
3157 * Nothing
Jeff Garzik6aa20a22006-09-13 13:24:59 -04003158 * Parms:
Linus Torvalds1da177e2005-04-16 15:20:36 -07003159 * io_base The IO port base address for the
3160 * TLAN device with the EEPROM to
3161 * use.
3162 *
3163 * This function sends a start cycle to an EEPROM attached
3164 * to a TLAN chip.
3165 *
3166 **************************************************************/
3167
Harvey Harrison98e0f522008-02-18 10:04:38 -08003168static void TLan_EeSendStart( u16 io_base )
Linus Torvalds1da177e2005-04-16 15:20:36 -07003169{
3170 u16 sio;
3171
3172 outw( TLAN_NET_SIO, io_base + TLAN_DIO_ADR );
3173 sio = io_base + TLAN_DIO_DATA + TLAN_NET_SIO;
3174
3175 TLan_SetBit( TLAN_NET_SIO_ECLOK, sio );
3176 TLan_SetBit( TLAN_NET_SIO_EDATA, sio );
3177 TLan_SetBit( TLAN_NET_SIO_ETXEN, sio );
3178 TLan_ClearBit( TLAN_NET_SIO_EDATA, sio );
3179 TLan_ClearBit( TLAN_NET_SIO_ECLOK, sio );
3180
3181} /* TLan_EeSendStart */
3182
3183
3184
3185
3186 /***************************************************************
3187 * TLan_EeSendByte
3188 *
3189 * Returns:
3190 * If the correct ack was received, 0, otherwise 1
3191 * Parms: io_base The IO port base address for the
3192 * TLAN device with the EEPROM to
3193 * use.
3194 * data The 8 bits of information to
3195 * send to the EEPROM.
3196 * stop If TLAN_EEPROM_STOP is passed, a
3197 * stop cycle is sent after the
3198 * byte is sent after the ack is
3199 * read.
3200 *
3201 * This function sends a byte on the serial EEPROM line,
3202 * driving the clock to send each bit. The function then
3203 * reverses transmission direction and reads an acknowledge
3204 * bit.
3205 *
3206 **************************************************************/
3207
Harvey Harrison98e0f522008-02-18 10:04:38 -08003208static int TLan_EeSendByte( u16 io_base, u8 data, int stop )
Linus Torvalds1da177e2005-04-16 15:20:36 -07003209{
3210 int err;
3211 u8 place;
3212 u16 sio;
3213
3214 outw( TLAN_NET_SIO, io_base + TLAN_DIO_ADR );
3215 sio = io_base + TLAN_DIO_DATA + TLAN_NET_SIO;
3216
3217 /* Assume clock is low, tx is enabled; */
3218 for ( place = 0x80; place != 0; place >>= 1 ) {
3219 if ( place & data )
3220 TLan_SetBit( TLAN_NET_SIO_EDATA, sio );
3221 else
3222 TLan_ClearBit( TLAN_NET_SIO_EDATA, sio );
3223 TLan_SetBit( TLAN_NET_SIO_ECLOK, sio );
3224 TLan_ClearBit( TLAN_NET_SIO_ECLOK, sio );
3225 }
3226 TLan_ClearBit( TLAN_NET_SIO_ETXEN, sio );
3227 TLan_SetBit( TLAN_NET_SIO_ECLOK, sio );
3228 err = TLan_GetBit( TLAN_NET_SIO_EDATA, sio );
3229 TLan_ClearBit( TLAN_NET_SIO_ECLOK, sio );
3230 TLan_SetBit( TLAN_NET_SIO_ETXEN, sio );
3231
3232 if ( ( ! err ) && stop ) {
Stephen Hemmingerdfc2c0a2008-05-30 09:49:58 -07003233 /* STOP, raise data while clock is high */
3234 TLan_ClearBit( TLAN_NET_SIO_EDATA, sio );
Linus Torvalds1da177e2005-04-16 15:20:36 -07003235 TLan_SetBit( TLAN_NET_SIO_ECLOK, sio );
3236 TLan_SetBit( TLAN_NET_SIO_EDATA, sio );
3237 }
3238
3239 return ( err );
3240
3241} /* TLan_EeSendByte */
3242
3243
3244
3245
3246 /***************************************************************
3247 * TLan_EeReceiveByte
3248 *
3249 * Returns:
3250 * Nothing
3251 * Parms:
3252 * io_base The IO port base address for the
3253 * TLAN device with the EEPROM to
3254 * use.
3255 * data An address to a char to hold the
3256 * data sent from the EEPROM.
3257 * stop If TLAN_EEPROM_STOP is passed, a
3258 * stop cycle is sent after the
3259 * byte is received, and no ack is
3260 * sent.
3261 *
3262 * This function receives 8 bits of data from the EEPROM
3263 * over the serial link. It then sends and ack bit, or no
3264 * ack and a stop bit. This function is used to retrieve
3265 * data after the address of a byte in the EEPROM has been
3266 * sent.
3267 *
3268 **************************************************************/
3269
Harvey Harrison98e0f522008-02-18 10:04:38 -08003270static void TLan_EeReceiveByte( u16 io_base, u8 *data, int stop )
Linus Torvalds1da177e2005-04-16 15:20:36 -07003271{
3272 u8 place;
3273 u16 sio;
3274
3275 outw( TLAN_NET_SIO, io_base + TLAN_DIO_ADR );
3276 sio = io_base + TLAN_DIO_DATA + TLAN_NET_SIO;
3277 *data = 0;
3278
3279 /* Assume clock is low, tx is enabled; */
3280 TLan_ClearBit( TLAN_NET_SIO_ETXEN, sio );
3281 for ( place = 0x80; place; place >>= 1 ) {
3282 TLan_SetBit( TLAN_NET_SIO_ECLOK, sio );
3283 if ( TLan_GetBit( TLAN_NET_SIO_EDATA, sio ) )
3284 *data |= place;
3285 TLan_ClearBit( TLAN_NET_SIO_ECLOK, sio );
3286 }
3287
3288 TLan_SetBit( TLAN_NET_SIO_ETXEN, sio );
3289 if ( ! stop ) {
3290 TLan_ClearBit( TLAN_NET_SIO_EDATA, sio ); /* Ack = 0 */
3291 TLan_SetBit( TLAN_NET_SIO_ECLOK, sio );
3292 TLan_ClearBit( TLAN_NET_SIO_ECLOK, sio );
3293 } else {
3294 TLan_SetBit( TLAN_NET_SIO_EDATA, sio ); /* No ack = 1 (?) */
3295 TLan_SetBit( TLAN_NET_SIO_ECLOK, sio );
3296 TLan_ClearBit( TLAN_NET_SIO_ECLOK, sio );
Stephen Hemmingerdfc2c0a2008-05-30 09:49:58 -07003297 /* STOP, raise data while clock is high */
3298 TLan_ClearBit( TLAN_NET_SIO_EDATA, sio );
Linus Torvalds1da177e2005-04-16 15:20:36 -07003299 TLan_SetBit( TLAN_NET_SIO_ECLOK, sio );
3300 TLan_SetBit( TLAN_NET_SIO_EDATA, sio );
3301 }
3302
3303} /* TLan_EeReceiveByte */
3304
3305
3306
3307
3308 /***************************************************************
3309 * TLan_EeReadByte
3310 *
3311 * Returns:
3312 * No error = 0, else, the stage at which the error
3313 * occurred.
3314 * Parms:
3315 * io_base The IO port base address for the
3316 * TLAN device with the EEPROM to
3317 * use.
3318 * ee_addr The address of the byte in the
3319 * EEPROM whose contents are to be
3320 * retrieved.
3321 * data An address to a char to hold the
3322 * data obtained from the EEPROM.
3323 *
3324 * This function reads a byte of information from an byte
3325 * cell in the EEPROM.
3326 *
3327 **************************************************************/
3328
Harvey Harrison98e0f522008-02-18 10:04:38 -08003329static int TLan_EeReadByte( struct net_device *dev, u8 ee_addr, u8 *data )
Linus Torvalds1da177e2005-04-16 15:20:36 -07003330{
3331 int err;
3332 TLanPrivateInfo *priv = netdev_priv(dev);
3333 unsigned long flags = 0;
3334 int ret=0;
3335
3336 spin_lock_irqsave(&priv->lock, flags);
3337
3338 TLan_EeSendStart( dev->base_addr );
3339 err = TLan_EeSendByte( dev->base_addr, 0xA0, TLAN_EEPROM_ACK );
3340 if (err)
3341 {
3342 ret=1;
3343 goto fail;
3344 }
3345 err = TLan_EeSendByte( dev->base_addr, ee_addr, TLAN_EEPROM_ACK );
3346 if (err)
3347 {
3348 ret=2;
3349 goto fail;
3350 }
3351 TLan_EeSendStart( dev->base_addr );
3352 err = TLan_EeSendByte( dev->base_addr, 0xA1, TLAN_EEPROM_ACK );
3353 if (err)
3354 {
3355 ret=3;
3356 goto fail;
3357 }
3358 TLan_EeReceiveByte( dev->base_addr, data, TLAN_EEPROM_STOP );
3359fail:
3360 spin_unlock_irqrestore(&priv->lock, flags);
3361
3362 return ret;
3363
3364} /* TLan_EeReadByte */
3365
3366
3367