Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /******************************************************************************* |
| 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 Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 16 | ** 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 Cox | 113aa83 | 2008-10-13 19:01:08 -0700 | [diff] [blame] | 32 | * Alan Cox <alan@lxorguk.ukuu.org.uk>: |
| 33 | * Fixed the out of memory |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 34 | * handling. |
Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 35 | * |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 36 | * Torben Mathiasen <torben.mathiasen@compaq.com> New Maintainer! |
| 37 | * |
| 38 | * v1.1 Dec 20, 1999 - Removed linux version checking |
Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 39 | * Patch from Tigran Aivazian. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 40 | * - v1.1 includes Alan's SMP updates. |
| 41 | * - We still have problems on SMP though, |
Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 42 | * but I'm looking into that. |
| 43 | * |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 44 | * v1.2 Jan 02, 2000 - Hopefully fixed the SMP deadlock. |
| 45 | * - Removed dependency of HZ being 100. |
Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 46 | * - We now allow higher priority timers to |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 47 | * 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 Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 52 | * - Removed call to pci_present(). |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 53 | * - Removed SA_INTERRUPT flag from irq handler. |
Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 54 | * - Added __init and __initdata to reduce resisdent |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 55 | * 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 Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 60 | * - Driver ported to new net API. |
| 61 | * - tlan.txt has been reworked to reflect current |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 62 | * driver (almost) |
| 63 | * - Other minor stuff |
| 64 | * |
| 65 | * v1.4 Feb 10, 2000 - Updated with more changes required after Dave's |
Sakari Ailus | c659c38 | 2011-01-21 10:59:30 +0000 | [diff] [blame] | 66 | * network cleanup in 2.3.43pre7 (Tigran & myself) |
| 67 | * - Minor stuff. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 68 | * |
Sakari Ailus | c659c38 | 2011-01-21 10:59:30 +0000 | [diff] [blame] | 69 | * v1.5 March 22, 2000 - Fixed another timer bug that would hang the |
| 70 | * driver if no cable/link were present. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 71 | * - Cosmetic changes. |
| 72 | * - TODO: Port completely to new PCI/DMA API |
Sakari Ailus | c659c38 | 2011-01-21 10:59:30 +0000 | [diff] [blame] | 73 | * Auto-Neg fallback. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 74 | * |
Sakari Ailus | c659c38 | 2011-01-21 10:59:30 +0000 | [diff] [blame] | 75 | * v1.6 April 04, 2000 - Fixed driver support for kernel-parameters. |
| 76 | * Haven't tested it though, as the kernel support |
| 77 | * is currently broken (2.3.99p4p3). |
| 78 | * - Updated tlan.txt accordingly. |
| 79 | * - Adjusted minimum/maximum frame length. |
| 80 | * - There is now a TLAN website up at |
| 81 | * http://hp.sourceforge.net/ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 82 | * |
Sakari Ailus | c659c38 | 2011-01-21 10:59:30 +0000 | [diff] [blame] | 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. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 86 | * |
Sakari Ailus | c659c38 | 2011-01-21 10:59:30 +0000 | [diff] [blame] | 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. |
| 94 | * Please read tlan.txt for additional information. |
| 95 | * - Removed call to check_region(), and used |
| 96 | * return value of request_region() instead. |
Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 97 | * |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 98 | * v1.8a May 28, 2000 - Minor updates. |
| 99 | * |
| 100 | * v1.9 July 25, 2000 - Fixed a few remaining Full-Duplex issues. |
Sakari Ailus | c659c38 | 2011-01-21 10:59:30 +0000 | [diff] [blame] | 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. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 105 | * |
Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 106 | * v1.10 Aug 30, 2000 - Added support for EISA based tlan controllers |
| 107 | * like the Compaq NetFlex3/E. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 108 | * - Rewrote tlan_probe to better handle multiple |
| 109 | * bus probes. Probing and device setup is now |
| 110 | * done through TLan_Probe and TLan_init_one. Actual |
Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 111 | * hardware probe is done with kernel API and |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 112 | * TLan_EisaProbe. |
| 113 | * - Adjusted debug information for probing. |
Sakari Ailus | c659c38 | 2011-01-21 10:59:30 +0000 | [diff] [blame] | 114 | * - Fixed bug that would cause general debug |
| 115 | * information to be printed after driver removal. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 116 | * - Added transmit timeout handling. |
Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 117 | * - Fixed OOM return values in tlan_probe. |
| 118 | * - Fixed possible mem leak in tlan_exit |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 119 | * (now tlan_remove_one). |
| 120 | * - Fixed timer bug in TLan_phyMonitor. |
| 121 | * - This driver version is alpha quality, please |
| 122 | * send me any bug issues you may encounter. |
| 123 | * |
Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 124 | * v1.11 Aug 31, 2000 - Do not try to register irq 0 if no irq line was |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 125 | * set for EISA cards. |
| 126 | * - Added support for NetFlex3/E with nibble-rate |
| 127 | * 10Base-T PHY. This is untestet as I haven't got |
| 128 | * one of these cards. |
| 129 | * - Fixed timer being added twice. |
| 130 | * - Disabled PhyMonitoring by default as this is |
| 131 | * work in progress. Define MONITOR to enable it. |
| 132 | * - Now we don't display link info with PHYs that |
| 133 | * doesn't support it (level1). |
| 134 | * - Incresed tx_timeout beacuse of auto-neg. |
| 135 | * - Adjusted timers for forced speeds. |
| 136 | * |
| 137 | * v1.12 Oct 12, 2000 - Minor fixes (memleak, init, etc.) |
| 138 | * |
Sakari Ailus | c659c38 | 2011-01-21 10:59:30 +0000 | [diff] [blame] | 139 | * v1.13 Nov 28, 2000 - Stop flooding console with auto-neg issues |
| 140 | * when link can't be established. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 141 | * - Added the bbuf option as a kernel parameter. |
| 142 | * - Fixed ioaddr probe bug. |
| 143 | * - Fixed stupid deadlock with MII interrupts. |
Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 144 | * - Added support for speed/duplex selection with |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 145 | * multiple nics. |
| 146 | * - Added partly fix for TX Channel lockup with |
| 147 | * TLAN v1.0 silicon. This needs to be investigated |
| 148 | * further. |
| 149 | * |
Sakari Ailus | c659c38 | 2011-01-21 10:59:30 +0000 | [diff] [blame] | 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. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 158 | * |
Sakari Ailus | c659c38 | 2011-01-21 10:59:30 +0000 | [diff] [blame] | 159 | * v1.14a Jan 6, 2001 - Minor adjustments (spinlocks, etc.) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 160 | * |
| 161 | * Samuel Chessman <chessman@tux.org> New Maintainer! |
| 162 | * |
| 163 | * v1.15 Apr 4, 2002 - Correct operation when aui=1 to be |
Sakari Ailus | c659c38 | 2011-01-21 10:59:30 +0000 | [diff] [blame] | 164 | * 10T half duplex no loopback |
| 165 | * Thanks to Gunnar Eikman |
Sakari Ailus | 5eeabf5 | 2008-12-16 15:24:05 -0800 | [diff] [blame] | 166 | * |
| 167 | * Sakari Ailus <sakari.ailus@iki.fi>: |
| 168 | * |
| 169 | * v1.15a Dec 15 2008 - Remove bbuf support, it doesn't work anyway. |
Sakari Ailus | c659c38 | 2011-01-21 10:59:30 +0000 | [diff] [blame] | 170 | * v1.16 Jan 6 2011 - Make checkpatch.pl happy. |
Sakari Ailus | fa6d5d4 | 2011-01-21 10:59:31 +0000 | [diff] [blame] | 171 | * v1.17 Jan 6 2011 - Add suspend/resume support. |
Sakari Ailus | 5eeabf5 | 2008-12-16 15:24:05 -0800 | [diff] [blame] | 172 | * |
Sakari Ailus | c659c38 | 2011-01-21 10:59:30 +0000 | [diff] [blame] | 173 | ******************************************************************************/ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 174 | |
| 175 | #include <linux/module.h> |
| 176 | #include <linux/init.h> |
| 177 | #include <linux/ioport.h> |
| 178 | #include <linux/eisa.h> |
| 179 | #include <linux/pci.h> |
Domen Puncer | 1e7f0bd | 2005-06-26 18:22:14 -0400 | [diff] [blame] | 180 | #include <linux/dma-mapping.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 181 | #include <linux/netdevice.h> |
| 182 | #include <linux/etherdevice.h> |
| 183 | #include <linux/delay.h> |
| 184 | #include <linux/spinlock.h> |
| 185 | #include <linux/workqueue.h> |
| 186 | #include <linux/mii.h> |
| 187 | |
| 188 | #include "tlan.h" |
| 189 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 190 | |
| 191 | /* For removing EISA devices */ |
Sakari Ailus | c659c38 | 2011-01-21 10:59:30 +0000 | [diff] [blame] | 192 | static struct net_device *tlan_eisa_devices; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 193 | |
Sakari Ailus | c659c38 | 2011-01-21 10:59:30 +0000 | [diff] [blame] | 194 | static int tlan_devices_installed; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 195 | |
| 196 | /* Set speed, duplex and aui settings */ |
| 197 | static int aui[MAX_TLAN_BOARDS]; |
| 198 | static int duplex[MAX_TLAN_BOARDS]; |
| 199 | static int speed[MAX_TLAN_BOARDS]; |
| 200 | static int boards_found; |
Stephen Hemminger | 15efa9b | 2005-05-04 15:33:11 -0700 | [diff] [blame] | 201 | module_param_array(aui, int, NULL, 0); |
| 202 | module_param_array(duplex, int, NULL, 0); |
| 203 | module_param_array(speed, int, NULL, 0); |
| 204 | MODULE_PARM_DESC(aui, "ThunderLAN use AUI port(s) (0-1)"); |
Sakari Ailus | c659c38 | 2011-01-21 10:59:30 +0000 | [diff] [blame] | 205 | MODULE_PARM_DESC(duplex, |
| 206 | "ThunderLAN duplex setting(s) (0-default, 1-half, 2-full)"); |
Stephen Hemminger | 15efa9b | 2005-05-04 15:33:11 -0700 | [diff] [blame] | 207 | MODULE_PARM_DESC(speed, "ThunderLAN port speen setting(s) (0,10,100)"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 208 | |
| 209 | MODULE_AUTHOR("Maintainer: Samuel Chessman <chessman@tux.org>"); |
| 210 | MODULE_DESCRIPTION("Driver for TI ThunderLAN based ethernet PCI adapters"); |
| 211 | MODULE_LICENSE("GPL"); |
| 212 | |
| 213 | |
| 214 | /* Define this to enable Link beat monitoring */ |
| 215 | #undef MONITOR |
| 216 | |
| 217 | /* Turn on debugging. See Documentation/networking/tlan.txt for details */ |
| 218 | static int debug; |
Stephen Hemminger | 15efa9b | 2005-05-04 15:33:11 -0700 | [diff] [blame] | 219 | module_param(debug, int, 0); |
| 220 | MODULE_PARM_DESC(debug, "ThunderLAN debug mask"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 221 | |
Sakari Ailus | c659c38 | 2011-01-21 10:59:30 +0000 | [diff] [blame] | 222 | static const char tlan_signature[] = "TLAN"; |
Sakari Ailus | fa6d5d4 | 2011-01-21 10:59:31 +0000 | [diff] [blame] | 223 | static const char tlan_banner[] = "ThunderLAN driver v1.17\n"; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 224 | static int tlan_have_pci; |
| 225 | static int tlan_have_eisa; |
| 226 | |
Sakari Ailus | c659c38 | 2011-01-21 10:59:30 +0000 | [diff] [blame] | 227 | static const char * const media[] = { |
| 228 | "10BaseT-HD", "10BaseT-FD", "100baseTx-HD", |
| 229 | "100BaseTx-FD", "100BaseT4", NULL |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 230 | }; |
| 231 | |
| 232 | static struct board { |
Sakari Ailus | c659c38 | 2011-01-21 10:59:30 +0000 | [diff] [blame] | 233 | const char *device_label; |
| 234 | u32 flags; |
| 235 | u16 addr_ofs; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 236 | } board_info[] = { |
| 237 | { "Compaq Netelligent 10 T PCI UTP", TLAN_ADAPTER_ACTIVITY_LED, 0x83 }, |
Sakari Ailus | c659c38 | 2011-01-21 10:59:30 +0000 | [diff] [blame] | 238 | { "Compaq Netelligent 10/100 TX PCI UTP", |
| 239 | TLAN_ADAPTER_ACTIVITY_LED, 0x83 }, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 240 | { "Compaq Integrated NetFlex-3/P", TLAN_ADAPTER_NONE, 0x83 }, |
Stephen Hemminger | dfc2c0a | 2008-05-30 09:49:58 -0700 | [diff] [blame] | 241 | { "Compaq NetFlex-3/P", |
| 242 | TLAN_ADAPTER_UNMANAGED_PHY | TLAN_ADAPTER_BIT_RATE_PHY, 0x83 }, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 243 | { "Compaq NetFlex-3/P", TLAN_ADAPTER_NONE, 0x83 }, |
Stephen Hemminger | dfc2c0a | 2008-05-30 09:49:58 -0700 | [diff] [blame] | 244 | { "Compaq Netelligent Integrated 10/100 TX UTP", |
| 245 | TLAN_ADAPTER_ACTIVITY_LED, 0x83 }, |
Sakari Ailus | c659c38 | 2011-01-21 10:59:30 +0000 | [diff] [blame] | 246 | { "Compaq Netelligent Dual 10/100 TX PCI UTP", |
| 247 | TLAN_ADAPTER_NONE, 0x83 }, |
| 248 | { "Compaq Netelligent 10/100 TX Embedded UTP", |
| 249 | TLAN_ADAPTER_NONE, 0x83 }, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 250 | { "Olicom OC-2183/2185", TLAN_ADAPTER_USE_INTERN_10, 0x83 }, |
Sakari Ailus | c659c38 | 2011-01-21 10:59:30 +0000 | [diff] [blame] | 251 | { "Olicom OC-2325", TLAN_ADAPTER_UNMANAGED_PHY, 0xf8 }, |
| 252 | { "Olicom OC-2326", TLAN_ADAPTER_USE_INTERN_10, 0xf8 }, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 253 | { "Compaq Netelligent 10/100 TX UTP", TLAN_ADAPTER_ACTIVITY_LED, 0x83 }, |
Sakari Ailus | c659c38 | 2011-01-21 10:59:30 +0000 | [diff] [blame] | 254 | { "Compaq Netelligent 10 T/2 PCI UTP/coax", TLAN_ADAPTER_NONE, 0x83 }, |
Stephen Hemminger | dfc2c0a | 2008-05-30 09:49:58 -0700 | [diff] [blame] | 255 | { "Compaq NetFlex-3/E", |
Sakari Ailus | c659c38 | 2011-01-21 10:59:30 +0000 | [diff] [blame] | 256 | TLAN_ADAPTER_ACTIVITY_LED | /* EISA card */ |
Stephen Hemminger | dfc2c0a | 2008-05-30 09:49:58 -0700 | [diff] [blame] | 257 | TLAN_ADAPTER_UNMANAGED_PHY | TLAN_ADAPTER_BIT_RATE_PHY, 0x83 }, |
Sakari Ailus | c659c38 | 2011-01-21 10:59:30 +0000 | [diff] [blame] | 258 | { "Compaq NetFlex-3/E", |
| 259 | TLAN_ADAPTER_ACTIVITY_LED, 0x83 }, /* EISA card */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 260 | }; |
| 261 | |
Alexey Dobriyan | a3aa188 | 2010-01-07 11:58:11 +0000 | [diff] [blame] | 262 | static DEFINE_PCI_DEVICE_TABLE(tlan_pci_tbl) = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 263 | { PCI_VENDOR_ID_COMPAQ, PCI_DEVICE_ID_COMPAQ_NETEL10, |
Sakari Ailus | c659c38 | 2011-01-21 10:59:30 +0000 | [diff] [blame] | 264 | PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0 }, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 265 | { PCI_VENDOR_ID_COMPAQ, PCI_DEVICE_ID_COMPAQ_NETEL100, |
Sakari Ailus | c659c38 | 2011-01-21 10:59:30 +0000 | [diff] [blame] | 266 | PCI_ANY_ID, PCI_ANY_ID, 0, 0, 1 }, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 267 | { PCI_VENDOR_ID_COMPAQ, PCI_DEVICE_ID_COMPAQ_NETFLEX3I, |
Sakari Ailus | c659c38 | 2011-01-21 10:59:30 +0000 | [diff] [blame] | 268 | PCI_ANY_ID, PCI_ANY_ID, 0, 0, 2 }, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 269 | { PCI_VENDOR_ID_COMPAQ, PCI_DEVICE_ID_COMPAQ_THUNDER, |
Sakari Ailus | c659c38 | 2011-01-21 10:59:30 +0000 | [diff] [blame] | 270 | PCI_ANY_ID, PCI_ANY_ID, 0, 0, 3 }, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 271 | { PCI_VENDOR_ID_COMPAQ, PCI_DEVICE_ID_COMPAQ_NETFLEX3B, |
Sakari Ailus | c659c38 | 2011-01-21 10:59:30 +0000 | [diff] [blame] | 272 | PCI_ANY_ID, PCI_ANY_ID, 0, 0, 4 }, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 273 | { PCI_VENDOR_ID_COMPAQ, PCI_DEVICE_ID_COMPAQ_NETEL100PI, |
Sakari Ailus | c659c38 | 2011-01-21 10:59:30 +0000 | [diff] [blame] | 274 | PCI_ANY_ID, PCI_ANY_ID, 0, 0, 5 }, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 275 | { PCI_VENDOR_ID_COMPAQ, PCI_DEVICE_ID_COMPAQ_NETEL100D, |
Sakari Ailus | c659c38 | 2011-01-21 10:59:30 +0000 | [diff] [blame] | 276 | PCI_ANY_ID, PCI_ANY_ID, 0, 0, 6 }, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 277 | { PCI_VENDOR_ID_COMPAQ, PCI_DEVICE_ID_COMPAQ_NETEL100I, |
Sakari Ailus | c659c38 | 2011-01-21 10:59:30 +0000 | [diff] [blame] | 278 | PCI_ANY_ID, PCI_ANY_ID, 0, 0, 7 }, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 279 | { PCI_VENDOR_ID_OLICOM, PCI_DEVICE_ID_OLICOM_OC2183, |
Sakari Ailus | c659c38 | 2011-01-21 10:59:30 +0000 | [diff] [blame] | 280 | PCI_ANY_ID, PCI_ANY_ID, 0, 0, 8 }, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 281 | { PCI_VENDOR_ID_OLICOM, PCI_DEVICE_ID_OLICOM_OC2325, |
Sakari Ailus | c659c38 | 2011-01-21 10:59:30 +0000 | [diff] [blame] | 282 | PCI_ANY_ID, PCI_ANY_ID, 0, 0, 9 }, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 283 | { PCI_VENDOR_ID_OLICOM, PCI_DEVICE_ID_OLICOM_OC2326, |
Sakari Ailus | c659c38 | 2011-01-21 10:59:30 +0000 | [diff] [blame] | 284 | PCI_ANY_ID, PCI_ANY_ID, 0, 0, 10 }, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 285 | { PCI_VENDOR_ID_COMPAQ, PCI_DEVICE_ID_NETELLIGENT_10_100_WS_5100, |
Sakari Ailus | c659c38 | 2011-01-21 10:59:30 +0000 | [diff] [blame] | 286 | PCI_ANY_ID, PCI_ANY_ID, 0, 0, 11 }, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 287 | { PCI_VENDOR_ID_COMPAQ, PCI_DEVICE_ID_NETELLIGENT_10_T2, |
Sakari Ailus | c659c38 | 2011-01-21 10:59:30 +0000 | [diff] [blame] | 288 | PCI_ANY_ID, PCI_ANY_ID, 0, 0, 12 }, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 289 | { 0,} |
| 290 | }; |
Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 291 | MODULE_DEVICE_TABLE(pci, tlan_pci_tbl); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 292 | |
Sakari Ailus | c659c38 | 2011-01-21 10:59:30 +0000 | [diff] [blame] | 293 | static void tlan_eisa_probe(void); |
| 294 | static void tlan_eisa_cleanup(void); |
| 295 | static int tlan_init(struct net_device *); |
| 296 | static int tlan_open(struct net_device *dev); |
| 297 | static netdev_tx_t tlan_start_tx(struct sk_buff *, struct net_device *); |
| 298 | static irqreturn_t tlan_handle_interrupt(int, void *); |
| 299 | static int tlan_close(struct net_device *); |
| 300 | static struct net_device_stats *tlan_get_stats(struct net_device *); |
| 301 | static void tlan_set_multicast_list(struct net_device *); |
| 302 | static int tlan_ioctl(struct net_device *dev, struct ifreq *rq, int cmd); |
| 303 | static int tlan_probe1(struct pci_dev *pdev, long ioaddr, |
| 304 | int irq, int rev, const struct pci_device_id *ent); |
| 305 | static void tlan_tx_timeout(struct net_device *dev); |
| 306 | static void tlan_tx_timeout_work(struct work_struct *work); |
| 307 | static int tlan_init_one(struct pci_dev *pdev, |
| 308 | const struct pci_device_id *ent); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 309 | |
Sakari Ailus | c659c38 | 2011-01-21 10:59:30 +0000 | [diff] [blame] | 310 | static u32 tlan_handle_tx_eof(struct net_device *, u16); |
| 311 | static u32 tlan_handle_stat_overflow(struct net_device *, u16); |
| 312 | static u32 tlan_handle_rx_eof(struct net_device *, u16); |
| 313 | static u32 tlan_handle_dummy(struct net_device *, u16); |
| 314 | static u32 tlan_handle_tx_eoc(struct net_device *, u16); |
| 315 | static u32 tlan_handle_status_check(struct net_device *, u16); |
| 316 | static u32 tlan_handle_rx_eoc(struct net_device *, u16); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 317 | |
Sakari Ailus | c659c38 | 2011-01-21 10:59:30 +0000 | [diff] [blame] | 318 | static void tlan_timer(unsigned long); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 319 | |
Sakari Ailus | c659c38 | 2011-01-21 10:59:30 +0000 | [diff] [blame] | 320 | static void tlan_reset_lists(struct net_device *); |
| 321 | static void tlan_free_lists(struct net_device *); |
| 322 | static void tlan_print_dio(u16); |
| 323 | static void tlan_print_list(struct tlan_list *, char *, int); |
| 324 | static void tlan_read_and_clear_stats(struct net_device *, int); |
| 325 | static void tlan_reset_adapter(struct net_device *); |
| 326 | static void tlan_finish_reset(struct net_device *); |
| 327 | static void tlan_set_mac(struct net_device *, int areg, char *mac); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 328 | |
Sakari Ailus | c659c38 | 2011-01-21 10:59:30 +0000 | [diff] [blame] | 329 | static void tlan_phy_print(struct net_device *); |
| 330 | static void tlan_phy_detect(struct net_device *); |
| 331 | static void tlan_phy_power_down(struct net_device *); |
| 332 | static void tlan_phy_power_up(struct net_device *); |
| 333 | static void tlan_phy_reset(struct net_device *); |
| 334 | static void tlan_phy_start_link(struct net_device *); |
| 335 | static void tlan_phy_finish_auto_neg(struct net_device *); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 336 | #ifdef MONITOR |
Sakari Ailus | c659c38 | 2011-01-21 10:59:30 +0000 | [diff] [blame] | 337 | static void tlan_phy_monitor(struct net_device *); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 338 | #endif |
| 339 | |
| 340 | /* |
Sakari Ailus | c659c38 | 2011-01-21 10:59:30 +0000 | [diff] [blame] | 341 | static int tlan_phy_nop(struct net_device *); |
| 342 | static int tlan_phy_internal_check(struct net_device *); |
| 343 | static int tlan_phy_internal_service(struct net_device *); |
| 344 | static int tlan_phy_dp83840a_check(struct net_device *); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 345 | */ |
| 346 | |
Sakari Ailus | c659c38 | 2011-01-21 10:59:30 +0000 | [diff] [blame] | 347 | static bool tlan_mii_read_reg(struct net_device *, u16, u16, u16 *); |
| 348 | static void tlan_mii_send_data(u16, u32, unsigned); |
| 349 | static void tlan_mii_sync(u16); |
| 350 | static void tlan_mii_write_reg(struct net_device *, u16, u16, u16); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 351 | |
Sakari Ailus | c659c38 | 2011-01-21 10:59:30 +0000 | [diff] [blame] | 352 | static void tlan_ee_send_start(u16); |
| 353 | static int tlan_ee_send_byte(u16, u8, int); |
| 354 | static void tlan_ee_receive_byte(u16, u8 *, int); |
| 355 | static int tlan_ee_read_byte(struct net_device *, u8, u8 *); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 356 | |
| 357 | |
Stephen Hemminger | 93e1684 | 2008-05-30 09:49:55 -0700 | [diff] [blame] | 358 | static inline void |
Sakari Ailus | c659c38 | 2011-01-21 10:59:30 +0000 | [diff] [blame] | 359 | tlan_store_skb(struct tlan_list *tag, struct sk_buff *skb) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 360 | { |
| 361 | unsigned long addr = (unsigned long)skb; |
Stephen Hemminger | 93e1684 | 2008-05-30 09:49:55 -0700 | [diff] [blame] | 362 | tag->buffer[9].address = addr; |
| 363 | tag->buffer[8].address = upper_32_bits(addr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 364 | } |
| 365 | |
Stephen Hemminger | 93e1684 | 2008-05-30 09:49:55 -0700 | [diff] [blame] | 366 | static inline struct sk_buff * |
Sakari Ailus | c659c38 | 2011-01-21 10:59:30 +0000 | [diff] [blame] | 367 | tlan_get_skb(const struct tlan_list *tag) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 368 | { |
Stephen Hemminger | 93e1684 | 2008-05-30 09:49:55 -0700 | [diff] [blame] | 369 | unsigned long addr; |
| 370 | |
Robert Fitzsimons | 0d63bea | 2008-08-09 17:54:02 +0100 | [diff] [blame] | 371 | addr = tag->buffer[9].address; |
| 372 | addr |= (tag->buffer[8].address << 16) << 16; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 373 | return (struct sk_buff *) addr; |
| 374 | } |
| 375 | |
Sakari Ailus | c659c38 | 2011-01-21 10:59:30 +0000 | [diff] [blame] | 376 | static u32 |
| 377 | (*tlan_int_vector[TLAN_INT_NUMBER_OF_INTS])(struct net_device *, u16) = { |
Stephen Hemminger | a3ccc78 | 2008-05-30 09:49:57 -0700 | [diff] [blame] | 378 | NULL, |
Sakari Ailus | c659c38 | 2011-01-21 10:59:30 +0000 | [diff] [blame] | 379 | tlan_handle_tx_eof, |
| 380 | tlan_handle_stat_overflow, |
| 381 | tlan_handle_rx_eof, |
| 382 | tlan_handle_dummy, |
| 383 | tlan_handle_tx_eoc, |
| 384 | tlan_handle_status_check, |
| 385 | tlan_handle_rx_eoc |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 386 | }; |
| 387 | |
| 388 | static inline void |
Sakari Ailus | c659c38 | 2011-01-21 10:59:30 +0000 | [diff] [blame] | 389 | tlan_set_timer(struct net_device *dev, u32 ticks, u32 type) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 390 | { |
Sakari Ailus | c659c38 | 2011-01-21 10:59:30 +0000 | [diff] [blame] | 391 | struct tlan_priv *priv = netdev_priv(dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 392 | unsigned long flags = 0; |
Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 393 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 394 | if (!in_irq()) |
| 395 | spin_lock_irqsave(&priv->lock, flags); |
Sakari Ailus | c659c38 | 2011-01-21 10:59:30 +0000 | [diff] [blame] | 396 | if (priv->timer.function != NULL && |
| 397 | priv->timer_type != TLAN_TIMER_ACTIVITY) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 398 | if (!in_irq()) |
| 399 | spin_unlock_irqrestore(&priv->lock, flags); |
| 400 | return; |
| 401 | } |
Sakari Ailus | c659c38 | 2011-01-21 10:59:30 +0000 | [diff] [blame] | 402 | priv->timer.function = tlan_timer; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 403 | if (!in_irq()) |
| 404 | spin_unlock_irqrestore(&priv->lock, flags); |
| 405 | |
| 406 | priv->timer.data = (unsigned long) dev; |
Sakari Ailus | c659c38 | 2011-01-21 10:59:30 +0000 | [diff] [blame] | 407 | priv->timer_set_at = jiffies; |
| 408 | priv->timer_type = type; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 409 | mod_timer(&priv->timer, jiffies + ticks); |
Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 410 | |
Sakari Ailus | c659c38 | 2011-01-21 10:59:30 +0000 | [diff] [blame] | 411 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 412 | |
| 413 | |
| 414 | /***************************************************************************** |
| 415 | ****************************************************************************** |
| 416 | |
Sakari Ailus | c659c38 | 2011-01-21 10:59:30 +0000 | [diff] [blame] | 417 | ThunderLAN driver primary functions |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 418 | |
Sakari Ailus | c659c38 | 2011-01-21 10:59:30 +0000 | [diff] [blame] | 419 | these functions are more or less common to all linux network drivers. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 420 | |
| 421 | ****************************************************************************** |
| 422 | *****************************************************************************/ |
| 423 | |
| 424 | |
| 425 | |
| 426 | |
| 427 | |
Sakari Ailus | c659c38 | 2011-01-21 10:59:30 +0000 | [diff] [blame] | 428 | /*************************************************************** |
| 429 | * tlan_remove_one |
| 430 | * |
| 431 | * Returns: |
| 432 | * Nothing |
| 433 | * Parms: |
| 434 | * None |
| 435 | * |
| 436 | * Goes through the TLanDevices list and frees the device |
| 437 | * structs and memory associated with each device (lists |
| 438 | * and buffers). It also ureserves the IO port regions |
| 439 | * associated with this device. |
| 440 | * |
| 441 | **************************************************************/ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 442 | |
| 443 | |
Sakari Ailus | c659c38 | 2011-01-21 10:59:30 +0000 | [diff] [blame] | 444 | static void __devexit tlan_remove_one(struct pci_dev *pdev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 445 | { |
Sakari Ailus | c659c38 | 2011-01-21 10:59:30 +0000 | [diff] [blame] | 446 | struct net_device *dev = pci_get_drvdata(pdev); |
| 447 | struct tlan_priv *priv = netdev_priv(dev); |
Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 448 | |
Sakari Ailus | c659c38 | 2011-01-21 10:59:30 +0000 | [diff] [blame] | 449 | unregister_netdev(dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 450 | |
Sakari Ailus | c659c38 | 2011-01-21 10:59:30 +0000 | [diff] [blame] | 451 | if (priv->dma_storage) { |
| 452 | pci_free_consistent(priv->pci_dev, |
| 453 | priv->dma_size, priv->dma_storage, |
| 454 | priv->dma_storage_dma); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 455 | } |
| 456 | |
| 457 | #ifdef CONFIG_PCI |
| 458 | pci_release_regions(pdev); |
| 459 | #endif |
Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 460 | |
Sakari Ailus | c659c38 | 2011-01-21 10:59:30 +0000 | [diff] [blame] | 461 | free_netdev(dev); |
Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 462 | |
Sakari Ailus | c659c38 | 2011-01-21 10:59:30 +0000 | [diff] [blame] | 463 | pci_set_drvdata(pdev, NULL); |
Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 464 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 465 | |
Sakari Ailus | fa6d5d4 | 2011-01-21 10:59:31 +0000 | [diff] [blame] | 466 | static void tlan_start(struct net_device *dev) |
| 467 | { |
| 468 | tlan_reset_lists(dev); |
| 469 | /* NOTE: It might not be necessary to read the stats before a |
| 470 | reset if you don't care what the values are. |
| 471 | */ |
| 472 | tlan_read_and_clear_stats(dev, TLAN_IGNORE); |
| 473 | tlan_reset_adapter(dev); |
| 474 | netif_wake_queue(dev); |
| 475 | } |
| 476 | |
| 477 | static void tlan_stop(struct net_device *dev) |
| 478 | { |
| 479 | struct tlan_priv *priv = netdev_priv(dev); |
| 480 | |
| 481 | tlan_read_and_clear_stats(dev, TLAN_RECORD); |
| 482 | outl(TLAN_HC_AD_RST, dev->base_addr + TLAN_HOST_CMD); |
| 483 | /* Reset and power down phy */ |
| 484 | tlan_reset_adapter(dev); |
| 485 | if (priv->timer.function != NULL) { |
| 486 | del_timer_sync(&priv->timer); |
| 487 | priv->timer.function = NULL; |
| 488 | } |
| 489 | } |
| 490 | |
| 491 | #ifdef CONFIG_PM |
| 492 | |
| 493 | static int tlan_suspend(struct pci_dev *pdev, pm_message_t state) |
| 494 | { |
| 495 | struct net_device *dev = pci_get_drvdata(pdev); |
| 496 | |
| 497 | if (netif_running(dev)) |
| 498 | tlan_stop(dev); |
| 499 | |
| 500 | netif_device_detach(dev); |
| 501 | pci_save_state(pdev); |
| 502 | pci_disable_device(pdev); |
| 503 | pci_wake_from_d3(pdev, false); |
| 504 | pci_set_power_state(pdev, PCI_D3hot); |
| 505 | |
| 506 | return 0; |
| 507 | } |
| 508 | |
| 509 | static int tlan_resume(struct pci_dev *pdev) |
| 510 | { |
| 511 | struct net_device *dev = pci_get_drvdata(pdev); |
| 512 | |
| 513 | pci_set_power_state(pdev, PCI_D0); |
| 514 | pci_restore_state(pdev); |
| 515 | pci_enable_wake(pdev, 0, 0); |
| 516 | netif_device_attach(dev); |
| 517 | |
| 518 | if (netif_running(dev)) |
| 519 | tlan_start(dev); |
| 520 | |
| 521 | return 0; |
| 522 | } |
| 523 | |
| 524 | #else /* CONFIG_PM */ |
| 525 | |
| 526 | #define tlan_suspend NULL |
| 527 | #define tlan_resume NULL |
| 528 | |
| 529 | #endif /* CONFIG_PM */ |
| 530 | |
| 531 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 532 | static struct pci_driver tlan_driver = { |
| 533 | .name = "tlan", |
| 534 | .id_table = tlan_pci_tbl, |
| 535 | .probe = tlan_init_one, |
Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 536 | .remove = __devexit_p(tlan_remove_one), |
Sakari Ailus | fa6d5d4 | 2011-01-21 10:59:31 +0000 | [diff] [blame] | 537 | .suspend = tlan_suspend, |
| 538 | .resume = tlan_resume, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 539 | }; |
| 540 | |
| 541 | static int __init tlan_probe(void) |
| 542 | { |
Leonardo Potenza | 6c04a51 | 2008-02-04 23:47:16 -0800 | [diff] [blame] | 543 | int rc = -ENODEV; |
Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 544 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 545 | printk(KERN_INFO "%s", tlan_banner); |
Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 546 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 547 | TLAN_DBG(TLAN_DEBUG_PROBE, "Starting PCI Probe....\n"); |
Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 548 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 549 | /* Use new style PCI probing. Now the kernel will |
| 550 | do most of this for us */ |
Leonardo Potenza | 6c04a51 | 2008-02-04 23:47:16 -0800 | [diff] [blame] | 551 | rc = pci_register_driver(&tlan_driver); |
| 552 | |
| 553 | if (rc != 0) { |
| 554 | printk(KERN_ERR "TLAN: Could not register pci driver.\n"); |
| 555 | goto err_out_pci_free; |
| 556 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 557 | |
| 558 | TLAN_DBG(TLAN_DEBUG_PROBE, "Starting EISA Probe....\n"); |
Sakari Ailus | c659c38 | 2011-01-21 10:59:30 +0000 | [diff] [blame] | 559 | tlan_eisa_probe(); |
Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 560 | |
| 561 | printk(KERN_INFO "TLAN: %d device%s installed, PCI: %d EISA: %d\n", |
Sakari Ailus | c659c38 | 2011-01-21 10:59:30 +0000 | [diff] [blame] | 562 | tlan_devices_installed, tlan_devices_installed == 1 ? "" : "s", |
| 563 | tlan_have_pci, tlan_have_eisa); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 564 | |
Sakari Ailus | c659c38 | 2011-01-21 10:59:30 +0000 | [diff] [blame] | 565 | if (tlan_devices_installed == 0) { |
Leonardo Potenza | 6c04a51 | 2008-02-04 23:47:16 -0800 | [diff] [blame] | 566 | rc = -ENODEV; |
| 567 | goto err_out_pci_unreg; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 568 | } |
| 569 | return 0; |
Leonardo Potenza | 6c04a51 | 2008-02-04 23:47:16 -0800 | [diff] [blame] | 570 | |
| 571 | err_out_pci_unreg: |
| 572 | pci_unregister_driver(&tlan_driver); |
| 573 | err_out_pci_free: |
Leonardo Potenza | 6c04a51 | 2008-02-04 23:47:16 -0800 | [diff] [blame] | 574 | return rc; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 575 | } |
Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 576 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 577 | |
Sakari Ailus | c659c38 | 2011-01-21 10:59:30 +0000 | [diff] [blame] | 578 | static int __devinit tlan_init_one(struct pci_dev *pdev, |
| 579 | const struct pci_device_id *ent) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 580 | { |
Sakari Ailus | c659c38 | 2011-01-21 10:59:30 +0000 | [diff] [blame] | 581 | return tlan_probe1(pdev, -1, -1, 0, ent); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 582 | } |
| 583 | |
| 584 | |
| 585 | /* |
Sakari Ailus | c659c38 | 2011-01-21 10:59:30 +0000 | [diff] [blame] | 586 | *************************************************************** |
| 587 | * tlan_probe1 |
| 588 | * |
| 589 | * Returns: |
| 590 | * 0 on success, error code on error |
| 591 | * Parms: |
| 592 | * none |
| 593 | * |
| 594 | * The name is lower case to fit in with all the rest of |
| 595 | * the netcard_probe names. This function looks for |
| 596 | * another TLan based adapter, setting it up with the |
| 597 | * allocated device struct if one is found. |
| 598 | * tlan_probe has been ported to the new net API and |
| 599 | * now allocates its own device structure. This function |
| 600 | * is also used by modules. |
| 601 | * |
| 602 | **************************************************************/ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 603 | |
Sakari Ailus | c659c38 | 2011-01-21 10:59:30 +0000 | [diff] [blame] | 604 | static int __devinit tlan_probe1(struct pci_dev *pdev, |
Stephen Hemminger | dfc2c0a | 2008-05-30 09:49:58 -0700 | [diff] [blame] | 605 | long ioaddr, int irq, int rev, |
Sakari Ailus | c659c38 | 2011-01-21 10:59:30 +0000 | [diff] [blame] | 606 | const struct pci_device_id *ent) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 607 | { |
| 608 | |
| 609 | struct net_device *dev; |
Sakari Ailus | c659c38 | 2011-01-21 10:59:30 +0000 | [diff] [blame] | 610 | struct tlan_priv *priv; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 611 | u16 device_id; |
| 612 | int reg, rc = -ENODEV; |
| 613 | |
Adrian Bunk | ad9f671 | 2006-02-05 00:37:47 +0100 | [diff] [blame] | 614 | #ifdef CONFIG_PCI |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 615 | if (pdev) { |
| 616 | rc = pci_enable_device(pdev); |
| 617 | if (rc) |
| 618 | return rc; |
| 619 | |
Sakari Ailus | c659c38 | 2011-01-21 10:59:30 +0000 | [diff] [blame] | 620 | rc = pci_request_regions(pdev, tlan_signature); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 621 | if (rc) { |
| 622 | printk(KERN_ERR "TLAN: Could not reserve IO regions\n"); |
| 623 | goto err_out; |
| 624 | } |
| 625 | } |
Adrian Bunk | ad9f671 | 2006-02-05 00:37:47 +0100 | [diff] [blame] | 626 | #endif /* CONFIG_PCI */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 627 | |
Sakari Ailus | c659c38 | 2011-01-21 10:59:30 +0000 | [diff] [blame] | 628 | dev = alloc_etherdev(sizeof(struct tlan_priv)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 629 | if (dev == NULL) { |
| 630 | printk(KERN_ERR "TLAN: Could not allocate memory for device.\n"); |
| 631 | rc = -ENOMEM; |
| 632 | goto err_out_regions; |
| 633 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 634 | SET_NETDEV_DEV(dev, &pdev->dev); |
Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 635 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 636 | priv = netdev_priv(dev); |
| 637 | |
Sakari Ailus | c659c38 | 2011-01-21 10:59:30 +0000 | [diff] [blame] | 638 | priv->pci_dev = pdev; |
David Howells | c402895 | 2006-11-22 14:57:56 +0000 | [diff] [blame] | 639 | priv->dev = dev; |
Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 640 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 641 | /* Is this a PCI device? */ |
| 642 | if (pdev) { |
Sakari Ailus | c659c38 | 2011-01-21 10:59:30 +0000 | [diff] [blame] | 643 | u32 pci_io_base = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 644 | |
| 645 | priv->adapter = &board_info[ent->driver_data]; |
| 646 | |
Yang Hongyang | 284901a | 2009-04-06 19:01:15 -0700 | [diff] [blame] | 647 | rc = pci_set_dma_mask(pdev, DMA_BIT_MASK(32)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 648 | if (rc) { |
Sakari Ailus | c659c38 | 2011-01-21 10:59:30 +0000 | [diff] [blame] | 649 | printk(KERN_ERR |
| 650 | "TLAN: No suitable PCI mapping available.\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 651 | goto err_out_free_dev; |
| 652 | } |
| 653 | |
Sakari Ailus | c659c38 | 2011-01-21 10:59:30 +0000 | [diff] [blame] | 654 | for (reg = 0; reg <= 5; reg++) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 655 | if (pci_resource_flags(pdev, reg) & IORESOURCE_IO) { |
| 656 | pci_io_base = pci_resource_start(pdev, reg); |
Sakari Ailus | c659c38 | 2011-01-21 10:59:30 +0000 | [diff] [blame] | 657 | TLAN_DBG(TLAN_DEBUG_GNRL, |
| 658 | "IO mapping is available at %x.\n", |
| 659 | pci_io_base); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 660 | break; |
| 661 | } |
| 662 | } |
| 663 | if (!pci_io_base) { |
| 664 | printk(KERN_ERR "TLAN: No IO mappings available\n"); |
| 665 | rc = -EIO; |
| 666 | goto err_out_free_dev; |
| 667 | } |
Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 668 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 669 | dev->base_addr = pci_io_base; |
| 670 | dev->irq = pdev->irq; |
Sakari Ailus | c659c38 | 2011-01-21 10:59:30 +0000 | [diff] [blame] | 671 | priv->adapter_rev = pdev->revision; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 672 | pci_set_master(pdev); |
| 673 | pci_set_drvdata(pdev, dev); |
| 674 | |
| 675 | } else { /* EISA card */ |
| 676 | /* This is a hack. We need to know which board structure |
| 677 | * is suited for this adapter */ |
| 678 | device_id = inw(ioaddr + EISA_ID2); |
| 679 | priv->is_eisa = 1; |
| 680 | if (device_id == 0x20F1) { |
Sakari Ailus | c659c38 | 2011-01-21 10:59:30 +0000 | [diff] [blame] | 681 | priv->adapter = &board_info[13]; /* NetFlex-3/E */ |
| 682 | priv->adapter_rev = 23; /* TLAN 2.3 */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 683 | } else { |
| 684 | priv->adapter = &board_info[14]; |
Sakari Ailus | c659c38 | 2011-01-21 10:59:30 +0000 | [diff] [blame] | 685 | priv->adapter_rev = 10; /* TLAN 1.0 */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 686 | } |
| 687 | dev->base_addr = ioaddr; |
| 688 | dev->irq = irq; |
| 689 | } |
| 690 | |
| 691 | /* Kernel parameters */ |
| 692 | if (dev->mem_start) { |
| 693 | priv->aui = dev->mem_start & 0x01; |
Stephen Hemminger | dfc2c0a | 2008-05-30 09:49:58 -0700 | [diff] [blame] | 694 | priv->duplex = ((dev->mem_start & 0x06) == 0x06) ? 0 |
| 695 | : (dev->mem_start & 0x06) >> 1; |
| 696 | priv->speed = ((dev->mem_start & 0x18) == 0x18) ? 0 |
| 697 | : (dev->mem_start & 0x18) >> 3; |
Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 698 | |
Sakari Ailus | c659c38 | 2011-01-21 10:59:30 +0000 | [diff] [blame] | 699 | if (priv->speed == 0x1) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 700 | priv->speed = TLAN_SPEED_10; |
Sakari Ailus | c659c38 | 2011-01-21 10:59:30 +0000 | [diff] [blame] | 701 | else if (priv->speed == 0x2) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 702 | priv->speed = TLAN_SPEED_100; |
Sakari Ailus | c659c38 | 2011-01-21 10:59:30 +0000 | [diff] [blame] | 703 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 704 | debug = priv->debug = dev->mem_end; |
| 705 | } else { |
| 706 | priv->aui = aui[boards_found]; |
| 707 | priv->speed = speed[boards_found]; |
| 708 | priv->duplex = duplex[boards_found]; |
| 709 | priv->debug = debug; |
| 710 | } |
Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 711 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 712 | /* This will be used when we get an adapter error from |
| 713 | * within our irq handler */ |
Sakari Ailus | c659c38 | 2011-01-21 10:59:30 +0000 | [diff] [blame] | 714 | INIT_WORK(&priv->tlan_tqueue, tlan_tx_timeout_work); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 715 | |
| 716 | spin_lock_init(&priv->lock); |
Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 717 | |
Sakari Ailus | c659c38 | 2011-01-21 10:59:30 +0000 | [diff] [blame] | 718 | rc = tlan_init(dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 719 | if (rc) { |
| 720 | printk(KERN_ERR "TLAN: Could not set up device.\n"); |
| 721 | goto err_out_free_dev; |
| 722 | } |
| 723 | |
| 724 | rc = register_netdev(dev); |
| 725 | if (rc) { |
| 726 | printk(KERN_ERR "TLAN: Could not register device.\n"); |
| 727 | goto err_out_uninit; |
| 728 | } |
| 729 | |
Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 730 | |
Sakari Ailus | c659c38 | 2011-01-21 10:59:30 +0000 | [diff] [blame] | 731 | tlan_devices_installed++; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 732 | boards_found++; |
Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 733 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 734 | /* pdev is NULL if this is an EISA device */ |
| 735 | if (pdev) |
| 736 | tlan_have_pci++; |
| 737 | else { |
Sakari Ailus | c659c38 | 2011-01-21 10:59:30 +0000 | [diff] [blame] | 738 | priv->next_device = tlan_eisa_devices; |
| 739 | tlan_eisa_devices = dev; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 740 | tlan_have_eisa++; |
| 741 | } |
Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 742 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 743 | printk(KERN_INFO "TLAN: %s irq=%2d, io=%04x, %s, Rev. %d\n", |
Sakari Ailus | c659c38 | 2011-01-21 10:59:30 +0000 | [diff] [blame] | 744 | dev->name, |
| 745 | (int) dev->irq, |
| 746 | (int) dev->base_addr, |
| 747 | priv->adapter->device_label, |
| 748 | priv->adapter_rev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 749 | return 0; |
| 750 | |
| 751 | err_out_uninit: |
Sakari Ailus | c659c38 | 2011-01-21 10:59:30 +0000 | [diff] [blame] | 752 | pci_free_consistent(priv->pci_dev, priv->dma_size, priv->dma_storage, |
| 753 | priv->dma_storage_dma); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 754 | err_out_free_dev: |
| 755 | free_netdev(dev); |
| 756 | err_out_regions: |
| 757 | #ifdef CONFIG_PCI |
| 758 | if (pdev) |
| 759 | pci_release_regions(pdev); |
| 760 | #endif |
| 761 | err_out: |
| 762 | if (pdev) |
| 763 | pci_disable_device(pdev); |
| 764 | return rc; |
| 765 | } |
| 766 | |
| 767 | |
Sakari Ailus | c659c38 | 2011-01-21 10:59:30 +0000 | [diff] [blame] | 768 | static void tlan_eisa_cleanup(void) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 769 | { |
| 770 | struct net_device *dev; |
Sakari Ailus | c659c38 | 2011-01-21 10:59:30 +0000 | [diff] [blame] | 771 | struct tlan_priv *priv; |
Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 772 | |
Sakari Ailus | c659c38 | 2011-01-21 10:59:30 +0000 | [diff] [blame] | 773 | while (tlan_have_eisa) { |
| 774 | dev = tlan_eisa_devices; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 775 | priv = netdev_priv(dev); |
Sakari Ailus | c659c38 | 2011-01-21 10:59:30 +0000 | [diff] [blame] | 776 | if (priv->dma_storage) { |
| 777 | pci_free_consistent(priv->pci_dev, priv->dma_size, |
| 778 | priv->dma_storage, |
| 779 | priv->dma_storage_dma); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 780 | } |
Sakari Ailus | c659c38 | 2011-01-21 10:59:30 +0000 | [diff] [blame] | 781 | release_region(dev->base_addr, 0x10); |
| 782 | unregister_netdev(dev); |
| 783 | tlan_eisa_devices = priv->next_device; |
| 784 | free_netdev(dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 785 | tlan_have_eisa--; |
| 786 | } |
| 787 | } |
Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 788 | |
| 789 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 790 | static void __exit tlan_exit(void) |
| 791 | { |
| 792 | pci_unregister_driver(&tlan_driver); |
| 793 | |
| 794 | if (tlan_have_eisa) |
Sakari Ailus | c659c38 | 2011-01-21 10:59:30 +0000 | [diff] [blame] | 795 | tlan_eisa_cleanup(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 796 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 797 | } |
| 798 | |
| 799 | |
| 800 | /* Module loading/unloading */ |
| 801 | module_init(tlan_probe); |
| 802 | module_exit(tlan_exit); |
| 803 | |
| 804 | |
| 805 | |
Sakari Ailus | c659c38 | 2011-01-21 10:59:30 +0000 | [diff] [blame] | 806 | /************************************************************** |
| 807 | * tlan_eisa_probe |
| 808 | * |
| 809 | * Returns: 0 on success, 1 otherwise |
| 810 | * |
| 811 | * Parms: None |
| 812 | * |
| 813 | * |
| 814 | * This functions probes for EISA devices and calls |
| 815 | * TLan_probe1 when one is found. |
| 816 | * |
| 817 | *************************************************************/ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 818 | |
Sakari Ailus | c659c38 | 2011-01-21 10:59:30 +0000 | [diff] [blame] | 819 | static void __init tlan_eisa_probe(void) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 820 | { |
Sakari Ailus | c659c38 | 2011-01-21 10:59:30 +0000 | [diff] [blame] | 821 | long ioaddr; |
| 822 | int rc = -ENODEV; |
| 823 | int irq; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 824 | u16 device_id; |
| 825 | |
Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 826 | if (!EISA_bus) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 827 | TLAN_DBG(TLAN_DEBUG_PROBE, "No EISA bus present\n"); |
| 828 | return; |
| 829 | } |
Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 830 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 831 | /* Loop through all slots of the EISA bus */ |
| 832 | for (ioaddr = 0x1000; ioaddr < 0x9000; ioaddr += 0x1000) { |
Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 833 | |
Sakari Ailus | c659c38 | 2011-01-21 10:59:30 +0000 | [diff] [blame] | 834 | TLAN_DBG(TLAN_DEBUG_PROBE, "EISA_ID 0x%4x: 0x%4x\n", |
| 835 | (int) ioaddr + 0xc80, inw(ioaddr + EISA_ID)); |
| 836 | TLAN_DBG(TLAN_DEBUG_PROBE, "EISA_ID 0x%4x: 0x%4x\n", |
| 837 | (int) ioaddr + 0xc82, inw(ioaddr + EISA_ID2)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 838 | |
| 839 | |
Sakari Ailus | c659c38 | 2011-01-21 10:59:30 +0000 | [diff] [blame] | 840 | TLAN_DBG(TLAN_DEBUG_PROBE, |
| 841 | "Probing for EISA adapter at IO: 0x%4x : ", |
| 842 | (int) ioaddr); |
| 843 | if (request_region(ioaddr, 0x10, tlan_signature) == NULL) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 844 | goto out; |
| 845 | |
Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 846 | if (inw(ioaddr + EISA_ID) != 0x110E) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 847 | release_region(ioaddr, 0x10); |
| 848 | goto out; |
| 849 | } |
Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 850 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 851 | device_id = inw(ioaddr + EISA_ID2); |
Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 852 | if (device_id != 0x20F1 && device_id != 0x40F1) { |
Sakari Ailus | c659c38 | 2011-01-21 10:59:30 +0000 | [diff] [blame] | 853 | release_region(ioaddr, 0x10); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 854 | goto out; |
| 855 | } |
Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 856 | |
Sakari Ailus | c659c38 | 2011-01-21 10:59:30 +0000 | [diff] [blame] | 857 | /* check if adapter is enabled */ |
| 858 | if (inb(ioaddr + EISA_CR) != 0x1) { |
| 859 | release_region(ioaddr, 0x10); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 860 | goto out2; |
| 861 | } |
Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 862 | |
| 863 | if (debug == 0x10) |
Sakari Ailus | c659c38 | 2011-01-21 10:59:30 +0000 | [diff] [blame] | 864 | printk(KERN_INFO "Found one\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 865 | |
| 866 | |
| 867 | /* Get irq from board */ |
Sakari Ailus | c659c38 | 2011-01-21 10:59:30 +0000 | [diff] [blame] | 868 | switch (inb(ioaddr + 0xcc0)) { |
| 869 | case(0x10): |
| 870 | irq = 5; |
| 871 | break; |
| 872 | case(0x20): |
| 873 | irq = 9; |
| 874 | break; |
| 875 | case(0x40): |
| 876 | irq = 10; |
| 877 | break; |
| 878 | case(0x80): |
| 879 | irq = 11; |
| 880 | break; |
| 881 | default: |
| 882 | goto out; |
Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 883 | } |
| 884 | |
| 885 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 886 | /* Setup the newly found eisa adapter */ |
Sakari Ailus | c659c38 | 2011-01-21 10:59:30 +0000 | [diff] [blame] | 887 | rc = tlan_probe1(NULL, ioaddr, irq, |
| 888 | 12, NULL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 889 | continue; |
Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 890 | |
Sakari Ailus | c659c38 | 2011-01-21 10:59:30 +0000 | [diff] [blame] | 891 | out: |
| 892 | if (debug == 0x10) |
| 893 | printk(KERN_INFO "None found\n"); |
| 894 | continue; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 895 | |
Sakari Ailus | c659c38 | 2011-01-21 10:59:30 +0000 | [diff] [blame] | 896 | out2: |
| 897 | if (debug == 0x10) |
| 898 | printk(KERN_INFO "Card found but it is not enabled, skipping\n"); |
| 899 | continue; |
Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 900 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 901 | } |
| 902 | |
Sakari Ailus | c659c38 | 2011-01-21 10:59:30 +0000 | [diff] [blame] | 903 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 904 | |
| 905 | #ifdef CONFIG_NET_POLL_CONTROLLER |
Sakari Ailus | c659c38 | 2011-01-21 10:59:30 +0000 | [diff] [blame] | 906 | static void tlan_poll(struct net_device *dev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 907 | { |
| 908 | disable_irq(dev->irq); |
Sakari Ailus | c659c38 | 2011-01-21 10:59:30 +0000 | [diff] [blame] | 909 | tlan_handle_interrupt(dev->irq, dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 910 | enable_irq(dev->irq); |
| 911 | } |
| 912 | #endif |
| 913 | |
Sakari Ailus | c659c38 | 2011-01-21 10:59:30 +0000 | [diff] [blame] | 914 | static const struct net_device_ops tlan_netdev_ops = { |
| 915 | .ndo_open = tlan_open, |
| 916 | .ndo_stop = tlan_close, |
| 917 | .ndo_start_xmit = tlan_start_tx, |
| 918 | .ndo_tx_timeout = tlan_tx_timeout, |
| 919 | .ndo_get_stats = tlan_get_stats, |
| 920 | .ndo_set_multicast_list = tlan_set_multicast_list, |
| 921 | .ndo_do_ioctl = tlan_ioctl, |
Stephen Hemminger | 391c5e6 | 2009-01-07 17:27:15 -0800 | [diff] [blame] | 922 | .ndo_change_mtu = eth_change_mtu, |
Sakari Ailus | c659c38 | 2011-01-21 10:59:30 +0000 | [diff] [blame] | 923 | .ndo_set_mac_address = eth_mac_addr, |
Stephen Hemminger | 391c5e6 | 2009-01-07 17:27:15 -0800 | [diff] [blame] | 924 | .ndo_validate_addr = eth_validate_addr, |
| 925 | #ifdef CONFIG_NET_POLL_CONTROLLER |
Sakari Ailus | c659c38 | 2011-01-21 10:59:30 +0000 | [diff] [blame] | 926 | .ndo_poll_controller = tlan_poll, |
Stephen Hemminger | 391c5e6 | 2009-01-07 17:27:15 -0800 | [diff] [blame] | 927 | #endif |
| 928 | }; |
Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 929 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 930 | |
| 931 | |
Sakari Ailus | c659c38 | 2011-01-21 10:59:30 +0000 | [diff] [blame] | 932 | /*************************************************************** |
| 933 | * tlan_init |
| 934 | * |
| 935 | * Returns: |
| 936 | * 0 on success, error code otherwise. |
| 937 | * Parms: |
| 938 | * dev The structure of the device to be |
| 939 | * init'ed. |
| 940 | * |
| 941 | * This function completes the initialization of the |
| 942 | * device structure and driver. It reserves the IO |
| 943 | * addresses, allocates memory for the lists and bounce |
| 944 | * buffers, retrieves the MAC address from the eeprom |
| 945 | * and assignes the device's methods. |
| 946 | * |
| 947 | **************************************************************/ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 948 | |
Sakari Ailus | c659c38 | 2011-01-21 10:59:30 +0000 | [diff] [blame] | 949 | static int tlan_init(struct net_device *dev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 950 | { |
| 951 | int dma_size; |
Sakari Ailus | c659c38 | 2011-01-21 10:59:30 +0000 | [diff] [blame] | 952 | int err; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 953 | int i; |
Sakari Ailus | c659c38 | 2011-01-21 10:59:30 +0000 | [diff] [blame] | 954 | struct tlan_priv *priv; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 955 | |
| 956 | priv = netdev_priv(dev); |
Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 957 | |
Sakari Ailus | c659c38 | 2011-01-21 10:59:30 +0000 | [diff] [blame] | 958 | dma_size = (TLAN_NUM_RX_LISTS + TLAN_NUM_TX_LISTS) |
| 959 | * (sizeof(struct tlan_list)); |
| 960 | priv->dma_storage = pci_alloc_consistent(priv->pci_dev, |
| 961 | dma_size, |
| 962 | &priv->dma_storage_dma); |
| 963 | priv->dma_size = dma_size; |
Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 964 | |
Sakari Ailus | c659c38 | 2011-01-21 10:59:30 +0000 | [diff] [blame] | 965 | if (priv->dma_storage == NULL) { |
| 966 | printk(KERN_ERR |
| 967 | "TLAN: Could not allocate lists and buffers for %s.\n", |
| 968 | dev->name); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 969 | return -ENOMEM; |
| 970 | } |
Sakari Ailus | c659c38 | 2011-01-21 10:59:30 +0000 | [diff] [blame] | 971 | memset(priv->dma_storage, 0, dma_size); |
| 972 | priv->rx_list = (struct tlan_list *) |
| 973 | ALIGN((unsigned long)priv->dma_storage, 8); |
| 974 | priv->rx_list_dma = ALIGN(priv->dma_storage_dma, 8); |
| 975 | priv->tx_list = priv->rx_list + TLAN_NUM_RX_LISTS; |
| 976 | priv->tx_list_dma = |
| 977 | priv->rx_list_dma + sizeof(struct tlan_list)*TLAN_NUM_RX_LISTS; |
Stephen Hemminger | 93e1684 | 2008-05-30 09:49:55 -0700 | [diff] [blame] | 978 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 979 | err = 0; |
Sakari Ailus | c659c38 | 2011-01-21 10:59:30 +0000 | [diff] [blame] | 980 | for (i = 0; i < 6 ; i++) |
| 981 | err |= tlan_ee_read_byte(dev, |
| 982 | (u8) priv->adapter->addr_ofs + i, |
| 983 | (u8 *) &dev->dev_addr[i]); |
| 984 | if (err) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 985 | printk(KERN_ERR "TLAN: %s: Error reading MAC from eeprom: %d\n", |
Sakari Ailus | c659c38 | 2011-01-21 10:59:30 +0000 | [diff] [blame] | 986 | dev->name, |
| 987 | err); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 988 | } |
| 989 | dev->addr_len = 6; |
| 990 | |
| 991 | netif_carrier_off(dev); |
| 992 | |
| 993 | /* Device methods */ |
Sakari Ailus | c659c38 | 2011-01-21 10:59:30 +0000 | [diff] [blame] | 994 | dev->netdev_ops = &tlan_netdev_ops; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 995 | dev->watchdog_timeo = TX_TIMEOUT; |
| 996 | |
| 997 | return 0; |
| 998 | |
Sakari Ailus | c659c38 | 2011-01-21 10:59:30 +0000 | [diff] [blame] | 999 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1000 | |
| 1001 | |
| 1002 | |
| 1003 | |
Sakari Ailus | c659c38 | 2011-01-21 10:59:30 +0000 | [diff] [blame] | 1004 | /*************************************************************** |
| 1005 | * tlan_open |
| 1006 | * |
| 1007 | * Returns: |
| 1008 | * 0 on success, error code otherwise. |
| 1009 | * Parms: |
| 1010 | * dev Structure of device to be opened. |
| 1011 | * |
| 1012 | * This routine puts the driver and TLAN adapter in a |
| 1013 | * state where it is ready to send and receive packets. |
| 1014 | * It allocates the IRQ, resets and brings the adapter |
| 1015 | * out of reset, and allows interrupts. It also delays |
| 1016 | * the startup for autonegotiation or sends a Rx GO |
| 1017 | * command to the adapter, as appropriate. |
| 1018 | * |
| 1019 | **************************************************************/ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1020 | |
Sakari Ailus | c659c38 | 2011-01-21 10:59:30 +0000 | [diff] [blame] | 1021 | static int tlan_open(struct net_device *dev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1022 | { |
Sakari Ailus | c659c38 | 2011-01-21 10:59:30 +0000 | [diff] [blame] | 1023 | struct tlan_priv *priv = netdev_priv(dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1024 | int err; |
Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 1025 | |
Sakari Ailus | c659c38 | 2011-01-21 10:59:30 +0000 | [diff] [blame] | 1026 | priv->tlan_rev = tlan_dio_read8(dev->base_addr, TLAN_DEF_REVISION); |
| 1027 | err = request_irq(dev->irq, tlan_handle_interrupt, IRQF_SHARED, |
| 1028 | dev->name, dev); |
Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 1029 | |
Sakari Ailus | c659c38 | 2011-01-21 10:59:30 +0000 | [diff] [blame] | 1030 | if (err) { |
Stephen Hemminger | dfc2c0a | 2008-05-30 09:49:58 -0700 | [diff] [blame] | 1031 | pr_err("TLAN: Cannot open %s because IRQ %d is already in use.\n", |
Sakari Ailus | c659c38 | 2011-01-21 10:59:30 +0000 | [diff] [blame] | 1032 | dev->name, dev->irq); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1033 | return err; |
| 1034 | } |
Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 1035 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1036 | init_timer(&priv->timer); |
Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 1037 | |
Sakari Ailus | fa6d5d4 | 2011-01-21 10:59:31 +0000 | [diff] [blame] | 1038 | tlan_start(dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1039 | |
Sakari Ailus | c659c38 | 2011-01-21 10:59:30 +0000 | [diff] [blame] | 1040 | TLAN_DBG(TLAN_DEBUG_GNRL, "%s: Opened. TLAN Chip Rev: %x\n", |
| 1041 | dev->name, priv->tlan_rev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1042 | |
| 1043 | return 0; |
| 1044 | |
Sakari Ailus | c659c38 | 2011-01-21 10:59:30 +0000 | [diff] [blame] | 1045 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1046 | |
| 1047 | |
| 1048 | |
Sakari Ailus | c659c38 | 2011-01-21 10:59:30 +0000 | [diff] [blame] | 1049 | /************************************************************** |
| 1050 | * tlan_ioctl |
| 1051 | * |
| 1052 | * Returns: |
| 1053 | * 0 on success, error code otherwise |
| 1054 | * Params: |
| 1055 | * dev structure of device to receive ioctl. |
| 1056 | * |
| 1057 | * rq ifreq structure to hold userspace data. |
| 1058 | * |
| 1059 | * cmd ioctl command. |
| 1060 | * |
| 1061 | * |
| 1062 | *************************************************************/ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1063 | |
Sakari Ailus | c659c38 | 2011-01-21 10:59:30 +0000 | [diff] [blame] | 1064 | static int tlan_ioctl(struct net_device *dev, struct ifreq *rq, int cmd) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1065 | { |
Sakari Ailus | c659c38 | 2011-01-21 10:59:30 +0000 | [diff] [blame] | 1066 | struct tlan_priv *priv = netdev_priv(dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1067 | struct mii_ioctl_data *data = if_mii(rq); |
Sakari Ailus | c659c38 | 2011-01-21 10:59:30 +0000 | [diff] [blame] | 1068 | u32 phy = priv->phy[priv->phy_num]; |
Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 1069 | |
Sakari Ailus | c659c38 | 2011-01-21 10:59:30 +0000 | [diff] [blame] | 1070 | if (!priv->phy_online) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1071 | return -EAGAIN; |
| 1072 | |
Sakari Ailus | c659c38 | 2011-01-21 10:59:30 +0000 | [diff] [blame] | 1073 | switch (cmd) { |
| 1074 | case SIOCGMIIPHY: /* get address of MII PHY in use. */ |
| 1075 | data->phy_id = phy; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1076 | |
| 1077 | |
Sakari Ailus | c659c38 | 2011-01-21 10:59:30 +0000 | [diff] [blame] | 1078 | case SIOCGMIIREG: /* read MII PHY register. */ |
| 1079 | tlan_mii_read_reg(dev, data->phy_id & 0x1f, |
| 1080 | data->reg_num & 0x1f, &data->val_out); |
| 1081 | return 0; |
Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 1082 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1083 | |
Sakari Ailus | c659c38 | 2011-01-21 10:59:30 +0000 | [diff] [blame] | 1084 | case SIOCSMIIREG: /* write MII PHY register. */ |
| 1085 | tlan_mii_write_reg(dev, data->phy_id & 0x1f, |
| 1086 | data->reg_num & 0x1f, data->val_in); |
| 1087 | return 0; |
| 1088 | default: |
| 1089 | return -EOPNOTSUPP; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1090 | } |
Sakari Ailus | c659c38 | 2011-01-21 10:59:30 +0000 | [diff] [blame] | 1091 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1092 | |
| 1093 | |
Sakari Ailus | c659c38 | 2011-01-21 10:59:30 +0000 | [diff] [blame] | 1094 | /*************************************************************** |
| 1095 | * tlan_tx_timeout |
| 1096 | * |
| 1097 | * Returns: nothing |
| 1098 | * |
| 1099 | * Params: |
| 1100 | * dev structure of device which timed out |
| 1101 | * during transmit. |
| 1102 | * |
| 1103 | **************************************************************/ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1104 | |
Sakari Ailus | c659c38 | 2011-01-21 10:59:30 +0000 | [diff] [blame] | 1105 | static void tlan_tx_timeout(struct net_device *dev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1106 | { |
Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 1107 | |
Sakari Ailus | c659c38 | 2011-01-21 10:59:30 +0000 | [diff] [blame] | 1108 | TLAN_DBG(TLAN_DEBUG_GNRL, "%s: Transmit timed out.\n", dev->name); |
Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 1109 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1110 | /* Ok so we timed out, lets see what we can do about it...*/ |
Sakari Ailus | c659c38 | 2011-01-21 10:59:30 +0000 | [diff] [blame] | 1111 | tlan_free_lists(dev); |
| 1112 | tlan_reset_lists(dev); |
| 1113 | tlan_read_and_clear_stats(dev, TLAN_IGNORE); |
| 1114 | tlan_reset_adapter(dev); |
Eric Dumazet | 1ae5dc3 | 2010-05-10 05:01:31 -0700 | [diff] [blame] | 1115 | dev->trans_start = jiffies; /* prevent tx timeout */ |
Sakari Ailus | c659c38 | 2011-01-21 10:59:30 +0000 | [diff] [blame] | 1116 | netif_wake_queue(dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1117 | |
| 1118 | } |
Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 1119 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1120 | |
Sakari Ailus | c659c38 | 2011-01-21 10:59:30 +0000 | [diff] [blame] | 1121 | /*************************************************************** |
| 1122 | * tlan_tx_timeout_work |
| 1123 | * |
| 1124 | * Returns: nothing |
| 1125 | * |
| 1126 | * Params: |
| 1127 | * work work item of device which timed out |
| 1128 | * |
| 1129 | **************************************************************/ |
David Howells | c402895 | 2006-11-22 14:57:56 +0000 | [diff] [blame] | 1130 | |
Sakari Ailus | c659c38 | 2011-01-21 10:59:30 +0000 | [diff] [blame] | 1131 | static void tlan_tx_timeout_work(struct work_struct *work) |
David Howells | c402895 | 2006-11-22 14:57:56 +0000 | [diff] [blame] | 1132 | { |
Sakari Ailus | c659c38 | 2011-01-21 10:59:30 +0000 | [diff] [blame] | 1133 | struct tlan_priv *priv = |
| 1134 | container_of(work, struct tlan_priv, tlan_tqueue); |
David Howells | c402895 | 2006-11-22 14:57:56 +0000 | [diff] [blame] | 1135 | |
Sakari Ailus | c659c38 | 2011-01-21 10:59:30 +0000 | [diff] [blame] | 1136 | tlan_tx_timeout(priv->dev); |
David Howells | c402895 | 2006-11-22 14:57:56 +0000 | [diff] [blame] | 1137 | } |
| 1138 | |
| 1139 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1140 | |
Sakari Ailus | c659c38 | 2011-01-21 10:59:30 +0000 | [diff] [blame] | 1141 | /*************************************************************** |
| 1142 | * tlan_start_tx |
| 1143 | * |
| 1144 | * Returns: |
| 1145 | * 0 on success, non-zero on failure. |
| 1146 | * Parms: |
| 1147 | * skb A pointer to the sk_buff containing the |
| 1148 | * frame to be sent. |
| 1149 | * dev The device to send the data on. |
| 1150 | * |
| 1151 | * This function adds a frame to the Tx list to be sent |
| 1152 | * ASAP. First it verifies that the adapter is ready and |
| 1153 | * there is room in the queue. Then it sets up the next |
| 1154 | * available list, copies the frame to the corresponding |
| 1155 | * buffer. If the adapter Tx channel is idle, it gives |
| 1156 | * the adapter a Tx Go command on the list, otherwise it |
| 1157 | * sets the forward address of the previous list to point |
| 1158 | * to this one. Then it frees the sk_buff. |
| 1159 | * |
| 1160 | **************************************************************/ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1161 | |
Sakari Ailus | c659c38 | 2011-01-21 10:59:30 +0000 | [diff] [blame] | 1162 | static netdev_tx_t tlan_start_tx(struct sk_buff *skb, struct net_device *dev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1163 | { |
Sakari Ailus | c659c38 | 2011-01-21 10:59:30 +0000 | [diff] [blame] | 1164 | struct tlan_priv *priv = netdev_priv(dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1165 | dma_addr_t tail_list_phys; |
Sakari Ailus | c659c38 | 2011-01-21 10:59:30 +0000 | [diff] [blame] | 1166 | struct tlan_list *tail_list; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1167 | unsigned long flags; |
Sakari Ailus | 8953f12 | 2008-12-16 01:44:05 -0800 | [diff] [blame] | 1168 | unsigned int txlen; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1169 | |
Sakari Ailus | c659c38 | 2011-01-21 10:59:30 +0000 | [diff] [blame] | 1170 | if (!priv->phy_online) { |
| 1171 | TLAN_DBG(TLAN_DEBUG_TX, "TRANSMIT: %s PHY is not ready\n", |
| 1172 | dev->name); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1173 | dev_kfree_skb_any(skb); |
Patrick McHardy | 6ed1065 | 2009-06-23 06:03:08 +0000 | [diff] [blame] | 1174 | return NETDEV_TX_OK; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1175 | } |
| 1176 | |
Stephen Hemminger | 41873e9 | 2008-05-30 09:49:52 -0700 | [diff] [blame] | 1177 | if (skb_padto(skb, TLAN_MIN_FRAME_SIZE)) |
Patrick McHardy | 6ed1065 | 2009-06-23 06:03:08 +0000 | [diff] [blame] | 1178 | return NETDEV_TX_OK; |
Sakari Ailus | 8953f12 | 2008-12-16 01:44:05 -0800 | [diff] [blame] | 1179 | txlen = max(skb->len, (unsigned int)TLAN_MIN_FRAME_SIZE); |
Stephen Hemminger | 41873e9 | 2008-05-30 09:49:52 -0700 | [diff] [blame] | 1180 | |
Sakari Ailus | c659c38 | 2011-01-21 10:59:30 +0000 | [diff] [blame] | 1181 | tail_list = priv->tx_list + priv->tx_tail; |
| 1182 | tail_list_phys = |
| 1183 | priv->tx_list_dma + sizeof(struct tlan_list)*priv->tx_tail; |
Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 1184 | |
Sakari Ailus | c659c38 | 2011-01-21 10:59:30 +0000 | [diff] [blame] | 1185 | if (tail_list->c_stat != TLAN_CSTAT_UNUSED) { |
| 1186 | TLAN_DBG(TLAN_DEBUG_TX, |
| 1187 | "TRANSMIT: %s is busy (Head=%d Tail=%d)\n", |
| 1188 | dev->name, priv->tx_head, priv->tx_tail); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1189 | netif_stop_queue(dev); |
Sakari Ailus | c659c38 | 2011-01-21 10:59:30 +0000 | [diff] [blame] | 1190 | priv->tx_busy_count++; |
Patrick McHardy | 5b54814 | 2009-06-12 06:22:29 +0000 | [diff] [blame] | 1191 | return NETDEV_TX_BUSY; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1192 | } |
| 1193 | |
| 1194 | tail_list->forward = 0; |
| 1195 | |
Sakari Ailus | c659c38 | 2011-01-21 10:59:30 +0000 | [diff] [blame] | 1196 | tail_list->buffer[0].address = pci_map_single(priv->pci_dev, |
Sakari Ailus | 5eeabf5 | 2008-12-16 15:24:05 -0800 | [diff] [blame] | 1197 | skb->data, txlen, |
| 1198 | PCI_DMA_TODEVICE); |
Sakari Ailus | c659c38 | 2011-01-21 10:59:30 +0000 | [diff] [blame] | 1199 | tlan_store_skb(tail_list, skb); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1200 | |
Sakari Ailus | c659c38 | 2011-01-21 10:59:30 +0000 | [diff] [blame] | 1201 | tail_list->frame_size = (u16) txlen; |
Sakari Ailus | 8953f12 | 2008-12-16 01:44:05 -0800 | [diff] [blame] | 1202 | tail_list->buffer[0].count = TLAN_LAST_BUFFER | (u32) txlen; |
Stephen Hemminger | 41873e9 | 2008-05-30 09:49:52 -0700 | [diff] [blame] | 1203 | tail_list->buffer[1].count = 0; |
| 1204 | tail_list->buffer[1].address = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1205 | |
| 1206 | spin_lock_irqsave(&priv->lock, flags); |
Sakari Ailus | c659c38 | 2011-01-21 10:59:30 +0000 | [diff] [blame] | 1207 | tail_list->c_stat = TLAN_CSTAT_READY; |
| 1208 | if (!priv->tx_in_progress) { |
| 1209 | priv->tx_in_progress = 1; |
| 1210 | TLAN_DBG(TLAN_DEBUG_TX, |
| 1211 | "TRANSMIT: Starting TX on buffer %d\n", |
| 1212 | priv->tx_tail); |
| 1213 | outl(tail_list_phys, dev->base_addr + TLAN_CH_PARM); |
| 1214 | outl(TLAN_HC_GO, dev->base_addr + TLAN_HOST_CMD); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1215 | } else { |
Sakari Ailus | c659c38 | 2011-01-21 10:59:30 +0000 | [diff] [blame] | 1216 | TLAN_DBG(TLAN_DEBUG_TX, |
| 1217 | "TRANSMIT: Adding buffer %d to TX channel\n", |
| 1218 | priv->tx_tail); |
| 1219 | if (priv->tx_tail == 0) { |
| 1220 | (priv->tx_list + (TLAN_NUM_TX_LISTS - 1))->forward |
Stephen Hemminger | dfc2c0a | 2008-05-30 09:49:58 -0700 | [diff] [blame] | 1221 | = tail_list_phys; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1222 | } else { |
Sakari Ailus | c659c38 | 2011-01-21 10:59:30 +0000 | [diff] [blame] | 1223 | (priv->tx_list + (priv->tx_tail - 1))->forward |
Stephen Hemminger | dfc2c0a | 2008-05-30 09:49:58 -0700 | [diff] [blame] | 1224 | = tail_list_phys; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1225 | } |
| 1226 | } |
| 1227 | spin_unlock_irqrestore(&priv->lock, flags); |
| 1228 | |
Sakari Ailus | c659c38 | 2011-01-21 10:59:30 +0000 | [diff] [blame] | 1229 | CIRC_INC(priv->tx_tail, TLAN_NUM_TX_LISTS); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1230 | |
Patrick McHardy | 6ed1065 | 2009-06-23 06:03:08 +0000 | [diff] [blame] | 1231 | return NETDEV_TX_OK; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1232 | |
Sakari Ailus | c659c38 | 2011-01-21 10:59:30 +0000 | [diff] [blame] | 1233 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1234 | |
| 1235 | |
| 1236 | |
| 1237 | |
Sakari Ailus | c659c38 | 2011-01-21 10:59:30 +0000 | [diff] [blame] | 1238 | /*************************************************************** |
| 1239 | * tlan_handle_interrupt |
| 1240 | * |
| 1241 | * Returns: |
| 1242 | * Nothing |
| 1243 | * Parms: |
| 1244 | * irq The line on which the interrupt |
| 1245 | * occurred. |
| 1246 | * dev_id A pointer to the device assigned to |
| 1247 | * this irq line. |
| 1248 | * |
| 1249 | * This function handles an interrupt generated by its |
| 1250 | * assigned TLAN adapter. The function deactivates |
| 1251 | * interrupts on its adapter, records the type of |
| 1252 | * interrupt, executes the appropriate subhandler, and |
| 1253 | * acknowdges the interrupt to the adapter (thus |
| 1254 | * re-enabling adapter interrupts. |
| 1255 | * |
| 1256 | **************************************************************/ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1257 | |
Sakari Ailus | c659c38 | 2011-01-21 10:59:30 +0000 | [diff] [blame] | 1258 | static irqreturn_t tlan_handle_interrupt(int irq, void *dev_id) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1259 | { |
Stephen Hemminger | a3ccc78 | 2008-05-30 09:49:57 -0700 | [diff] [blame] | 1260 | struct net_device *dev = dev_id; |
Sakari Ailus | c659c38 | 2011-01-21 10:59:30 +0000 | [diff] [blame] | 1261 | struct tlan_priv *priv = netdev_priv(dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1262 | u16 host_int; |
Stephen Hemminger | a3ccc78 | 2008-05-30 09:49:57 -0700 | [diff] [blame] | 1263 | u16 type; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1264 | |
| 1265 | spin_lock(&priv->lock); |
| 1266 | |
Sakari Ailus | c659c38 | 2011-01-21 10:59:30 +0000 | [diff] [blame] | 1267 | host_int = inw(dev->base_addr + TLAN_HOST_INT); |
| 1268 | type = (host_int & TLAN_HI_IT_MASK) >> 2; |
| 1269 | if (type) { |
Stephen Hemminger | a3ccc78 | 2008-05-30 09:49:57 -0700 | [diff] [blame] | 1270 | u32 ack; |
| 1271 | u32 host_cmd; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1272 | |
Sakari Ailus | c659c38 | 2011-01-21 10:59:30 +0000 | [diff] [blame] | 1273 | outw(host_int, dev->base_addr + TLAN_HOST_INT); |
| 1274 | ack = tlan_int_vector[type](dev, host_int); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1275 | |
Sakari Ailus | c659c38 | 2011-01-21 10:59:30 +0000 | [diff] [blame] | 1276 | if (ack) { |
| 1277 | host_cmd = TLAN_HC_ACK | ack | (type << 18); |
| 1278 | outl(host_cmd, dev->base_addr + TLAN_HOST_CMD); |
Stephen Hemminger | a3ccc78 | 2008-05-30 09:49:57 -0700 | [diff] [blame] | 1279 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1280 | } |
| 1281 | |
| 1282 | spin_unlock(&priv->lock); |
| 1283 | |
Stephen Hemminger | a3ccc78 | 2008-05-30 09:49:57 -0700 | [diff] [blame] | 1284 | return IRQ_RETVAL(type); |
Sakari Ailus | c659c38 | 2011-01-21 10:59:30 +0000 | [diff] [blame] | 1285 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1286 | |
| 1287 | |
| 1288 | |
| 1289 | |
Sakari Ailus | c659c38 | 2011-01-21 10:59:30 +0000 | [diff] [blame] | 1290 | /*************************************************************** |
| 1291 | * tlan_close |
| 1292 | * |
| 1293 | * Returns: |
| 1294 | * An error code. |
| 1295 | * Parms: |
| 1296 | * dev The device structure of the device to |
| 1297 | * close. |
| 1298 | * |
| 1299 | * This function shuts down the adapter. It records any |
| 1300 | * stats, puts the adapter into reset state, deactivates |
| 1301 | * its time as needed, and frees the irq it is using. |
| 1302 | * |
| 1303 | **************************************************************/ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1304 | |
Sakari Ailus | c659c38 | 2011-01-21 10:59:30 +0000 | [diff] [blame] | 1305 | static int tlan_close(struct net_device *dev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1306 | { |
Sakari Ailus | c659c38 | 2011-01-21 10:59:30 +0000 | [diff] [blame] | 1307 | struct tlan_priv *priv = netdev_priv(dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1308 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1309 | priv->neg_be_verbose = 0; |
Sakari Ailus | fa6d5d4 | 2011-01-21 10:59:31 +0000 | [diff] [blame] | 1310 | tlan_stop(dev); |
Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 1311 | |
Sakari Ailus | c659c38 | 2011-01-21 10:59:30 +0000 | [diff] [blame] | 1312 | free_irq(dev->irq, dev); |
| 1313 | tlan_free_lists(dev); |
| 1314 | TLAN_DBG(TLAN_DEBUG_GNRL, "Device %s closed.\n", dev->name); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1315 | |
| 1316 | return 0; |
| 1317 | |
Sakari Ailus | c659c38 | 2011-01-21 10:59:30 +0000 | [diff] [blame] | 1318 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1319 | |
| 1320 | |
| 1321 | |
| 1322 | |
Sakari Ailus | c659c38 | 2011-01-21 10:59:30 +0000 | [diff] [blame] | 1323 | /*************************************************************** |
| 1324 | * tlan_get_stats |
| 1325 | * |
| 1326 | * Returns: |
| 1327 | * A pointer to the device's statistics structure. |
| 1328 | * Parms: |
| 1329 | * dev The device structure to return the |
| 1330 | * stats for. |
| 1331 | * |
| 1332 | * This function updates the devices statistics by reading |
| 1333 | * the TLAN chip's onboard registers. Then it returns the |
| 1334 | * address of the statistics structure. |
| 1335 | * |
| 1336 | **************************************************************/ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1337 | |
Sakari Ailus | c659c38 | 2011-01-21 10:59:30 +0000 | [diff] [blame] | 1338 | static struct net_device_stats *tlan_get_stats(struct net_device *dev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1339 | { |
Sakari Ailus | c659c38 | 2011-01-21 10:59:30 +0000 | [diff] [blame] | 1340 | struct tlan_priv *priv = netdev_priv(dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1341 | int i; |
| 1342 | |
| 1343 | /* Should only read stats if open ? */ |
Sakari Ailus | c659c38 | 2011-01-21 10:59:30 +0000 | [diff] [blame] | 1344 | tlan_read_and_clear_stats(dev, TLAN_RECORD); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1345 | |
Sakari Ailus | c659c38 | 2011-01-21 10:59:30 +0000 | [diff] [blame] | 1346 | TLAN_DBG(TLAN_DEBUG_RX, "RECEIVE: %s EOC count = %d\n", dev->name, |
| 1347 | priv->rx_eoc_count); |
| 1348 | TLAN_DBG(TLAN_DEBUG_TX, "TRANSMIT: %s Busy count = %d\n", dev->name, |
| 1349 | priv->tx_busy_count); |
| 1350 | if (debug & TLAN_DEBUG_GNRL) { |
| 1351 | tlan_print_dio(dev->base_addr); |
| 1352 | tlan_phy_print(dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1353 | } |
Sakari Ailus | c659c38 | 2011-01-21 10:59:30 +0000 | [diff] [blame] | 1354 | if (debug & TLAN_DEBUG_LIST) { |
| 1355 | for (i = 0; i < TLAN_NUM_RX_LISTS; i++) |
| 1356 | tlan_print_list(priv->rx_list + i, "RX", i); |
| 1357 | for (i = 0; i < TLAN_NUM_TX_LISTS; i++) |
| 1358 | tlan_print_list(priv->tx_list + i, "TX", i); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1359 | } |
Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 1360 | |
Stephen Hemminger | f8f3154 | 2008-05-30 09:49:53 -0700 | [diff] [blame] | 1361 | return &dev->stats; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1362 | |
Sakari Ailus | c659c38 | 2011-01-21 10:59:30 +0000 | [diff] [blame] | 1363 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1364 | |
| 1365 | |
| 1366 | |
| 1367 | |
Sakari Ailus | c659c38 | 2011-01-21 10:59:30 +0000 | [diff] [blame] | 1368 | /*************************************************************** |
| 1369 | * tlan_set_multicast_list |
| 1370 | * |
| 1371 | * Returns: |
| 1372 | * Nothing |
| 1373 | * Parms: |
| 1374 | * dev The device structure to set the |
| 1375 | * multicast list for. |
| 1376 | * |
| 1377 | * This function sets the TLAN adaptor to various receive |
| 1378 | * modes. If the IFF_PROMISC flag is set, promiscuous |
| 1379 | * mode is acitviated. Otherwise, promiscuous mode is |
| 1380 | * turned off. If the IFF_ALLMULTI flag is set, then |
| 1381 | * the hash table is set to receive all group addresses. |
| 1382 | * Otherwise, the first three multicast addresses are |
| 1383 | * stored in AREG_1-3, and the rest are selected via the |
| 1384 | * hash table, as necessary. |
| 1385 | * |
| 1386 | **************************************************************/ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1387 | |
Sakari Ailus | c659c38 | 2011-01-21 10:59:30 +0000 | [diff] [blame] | 1388 | static void tlan_set_multicast_list(struct net_device *dev) |
Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 1389 | { |
Jiri Pirko | 22bedad3 | 2010-04-01 21:22:57 +0000 | [diff] [blame] | 1390 | struct netdev_hw_addr *ha; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1391 | u32 hash1 = 0; |
| 1392 | u32 hash2 = 0; |
| 1393 | int i; |
| 1394 | u32 offset; |
| 1395 | u8 tmp; |
| 1396 | |
Sakari Ailus | c659c38 | 2011-01-21 10:59:30 +0000 | [diff] [blame] | 1397 | if (dev->flags & IFF_PROMISC) { |
| 1398 | tmp = tlan_dio_read8(dev->base_addr, TLAN_NET_CMD); |
| 1399 | tlan_dio_write8(dev->base_addr, |
| 1400 | TLAN_NET_CMD, tmp | TLAN_NET_CMD_CAF); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1401 | } else { |
Sakari Ailus | c659c38 | 2011-01-21 10:59:30 +0000 | [diff] [blame] | 1402 | tmp = tlan_dio_read8(dev->base_addr, TLAN_NET_CMD); |
| 1403 | tlan_dio_write8(dev->base_addr, |
| 1404 | TLAN_NET_CMD, tmp & ~TLAN_NET_CMD_CAF); |
| 1405 | if (dev->flags & IFF_ALLMULTI) { |
| 1406 | for (i = 0; i < 3; i++) |
| 1407 | tlan_set_mac(dev, i + 1, NULL); |
| 1408 | tlan_dio_write32(dev->base_addr, TLAN_HASH_1, |
| 1409 | 0xffffffff); |
| 1410 | tlan_dio_write32(dev->base_addr, TLAN_HASH_2, |
| 1411 | 0xffffffff); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1412 | } else { |
Jiri Pirko | 567ec87 | 2010-02-23 23:17:07 +0000 | [diff] [blame] | 1413 | i = 0; |
Jiri Pirko | 22bedad3 | 2010-04-01 21:22:57 +0000 | [diff] [blame] | 1414 | netdev_for_each_mc_addr(ha, dev) { |
Sakari Ailus | c659c38 | 2011-01-21 10:59:30 +0000 | [diff] [blame] | 1415 | if (i < 3) { |
| 1416 | tlan_set_mac(dev, i + 1, |
Jiri Pirko | 22bedad3 | 2010-04-01 21:22:57 +0000 | [diff] [blame] | 1417 | (char *) &ha->addr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1418 | } else { |
Sakari Ailus | c659c38 | 2011-01-21 10:59:30 +0000 | [diff] [blame] | 1419 | offset = |
| 1420 | tlan_hash_func((u8 *)&ha->addr); |
| 1421 | if (offset < 32) |
| 1422 | hash1 |= (1 << offset); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1423 | else |
Sakari Ailus | c659c38 | 2011-01-21 10:59:30 +0000 | [diff] [blame] | 1424 | hash2 |= (1 << (offset - 32)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1425 | } |
Jiri Pirko | 567ec87 | 2010-02-23 23:17:07 +0000 | [diff] [blame] | 1426 | i++; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1427 | } |
Sakari Ailus | c659c38 | 2011-01-21 10:59:30 +0000 | [diff] [blame] | 1428 | for ( ; i < 3; i++) |
| 1429 | tlan_set_mac(dev, i + 1, NULL); |
| 1430 | tlan_dio_write32(dev->base_addr, TLAN_HASH_1, hash1); |
| 1431 | tlan_dio_write32(dev->base_addr, TLAN_HASH_2, hash2); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1432 | } |
| 1433 | } |
| 1434 | |
Sakari Ailus | c659c38 | 2011-01-21 10:59:30 +0000 | [diff] [blame] | 1435 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1436 | |
| 1437 | |
| 1438 | |
| 1439 | /***************************************************************************** |
| 1440 | ****************************************************************************** |
| 1441 | |
Sakari Ailus | c659c38 | 2011-01-21 10:59:30 +0000 | [diff] [blame] | 1442 | ThunderLAN driver interrupt vectors and table |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1443 | |
Sakari Ailus | c659c38 | 2011-01-21 10:59:30 +0000 | [diff] [blame] | 1444 | please see chap. 4, "Interrupt Handling" of the "ThunderLAN |
| 1445 | Programmer's Guide" for more informations on handling interrupts |
| 1446 | generated by TLAN based adapters. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1447 | |
| 1448 | ****************************************************************************** |
| 1449 | *****************************************************************************/ |
| 1450 | |
| 1451 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1452 | |
| 1453 | |
Sakari Ailus | c659c38 | 2011-01-21 10:59:30 +0000 | [diff] [blame] | 1454 | /*************************************************************** |
| 1455 | * tlan_handle_tx_eof |
| 1456 | * |
| 1457 | * Returns: |
| 1458 | * 1 |
| 1459 | * Parms: |
| 1460 | * dev Device assigned the IRQ that was |
| 1461 | * raised. |
| 1462 | * host_int The contents of the HOST_INT |
| 1463 | * port. |
| 1464 | * |
| 1465 | * This function handles Tx EOF interrupts which are raised |
| 1466 | * by the adapter when it has completed sending the |
| 1467 | * contents of a buffer. If detemines which list/buffer |
| 1468 | * was completed and resets it. If the buffer was the last |
| 1469 | * in the channel (EOC), then the function checks to see if |
| 1470 | * another buffer is ready to send, and if so, sends a Tx |
| 1471 | * Go command. Finally, the driver activates/continues the |
| 1472 | * activity LED. |
| 1473 | * |
| 1474 | **************************************************************/ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1475 | |
Sakari Ailus | c659c38 | 2011-01-21 10:59:30 +0000 | [diff] [blame] | 1476 | static u32 tlan_handle_tx_eof(struct net_device *dev, u16 host_int) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1477 | { |
Sakari Ailus | c659c38 | 2011-01-21 10:59:30 +0000 | [diff] [blame] | 1478 | struct tlan_priv *priv = netdev_priv(dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1479 | int eoc = 0; |
Sakari Ailus | c659c38 | 2011-01-21 10:59:30 +0000 | [diff] [blame] | 1480 | struct tlan_list *head_list; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1481 | dma_addr_t head_list_phys; |
| 1482 | u32 ack = 0; |
Sakari Ailus | c659c38 | 2011-01-21 10:59:30 +0000 | [diff] [blame] | 1483 | u16 tmp_c_stat; |
Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 1484 | |
Sakari Ailus | c659c38 | 2011-01-21 10:59:30 +0000 | [diff] [blame] | 1485 | TLAN_DBG(TLAN_DEBUG_TX, |
| 1486 | "TRANSMIT: Handling TX EOF (Head=%d Tail=%d)\n", |
| 1487 | priv->tx_head, priv->tx_tail); |
| 1488 | head_list = priv->tx_list + priv->tx_head; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1489 | |
Sakari Ailus | c659c38 | 2011-01-21 10:59:30 +0000 | [diff] [blame] | 1490 | while (((tmp_c_stat = head_list->c_stat) & TLAN_CSTAT_FRM_CMP) |
| 1491 | && (ack < 255)) { |
| 1492 | struct sk_buff *skb = tlan_get_skb(head_list); |
Sakari Ailus | 5eeabf5 | 2008-12-16 15:24:05 -0800 | [diff] [blame] | 1493 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1494 | ack++; |
Sakari Ailus | c659c38 | 2011-01-21 10:59:30 +0000 | [diff] [blame] | 1495 | pci_unmap_single(priv->pci_dev, head_list->buffer[0].address, |
Sakari Ailus | 5eeabf5 | 2008-12-16 15:24:05 -0800 | [diff] [blame] | 1496 | max(skb->len, |
| 1497 | (unsigned int)TLAN_MIN_FRAME_SIZE), |
| 1498 | PCI_DMA_TODEVICE); |
| 1499 | dev_kfree_skb_any(skb); |
| 1500 | head_list->buffer[8].address = 0; |
| 1501 | head_list->buffer[9].address = 0; |
Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 1502 | |
Sakari Ailus | c659c38 | 2011-01-21 10:59:30 +0000 | [diff] [blame] | 1503 | if (tmp_c_stat & TLAN_CSTAT_EOC) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1504 | eoc = 1; |
Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 1505 | |
Sakari Ailus | c659c38 | 2011-01-21 10:59:30 +0000 | [diff] [blame] | 1506 | dev->stats.tx_bytes += head_list->frame_size; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1507 | |
Sakari Ailus | c659c38 | 2011-01-21 10:59:30 +0000 | [diff] [blame] | 1508 | head_list->c_stat = TLAN_CSTAT_UNUSED; |
Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 1509 | netif_start_queue(dev); |
Sakari Ailus | c659c38 | 2011-01-21 10:59:30 +0000 | [diff] [blame] | 1510 | CIRC_INC(priv->tx_head, TLAN_NUM_TX_LISTS); |
| 1511 | head_list = priv->tx_list + priv->tx_head; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1512 | } |
| 1513 | |
| 1514 | if (!ack) |
Sakari Ailus | c659c38 | 2011-01-21 10:59:30 +0000 | [diff] [blame] | 1515 | printk(KERN_INFO |
| 1516 | "TLAN: Received interrupt for uncompleted TX frame.\n"); |
Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 1517 | |
Sakari Ailus | c659c38 | 2011-01-21 10:59:30 +0000 | [diff] [blame] | 1518 | if (eoc) { |
| 1519 | TLAN_DBG(TLAN_DEBUG_TX, |
| 1520 | "TRANSMIT: handling TX EOC (Head=%d Tail=%d)\n", |
| 1521 | priv->tx_head, priv->tx_tail); |
| 1522 | head_list = priv->tx_list + priv->tx_head; |
| 1523 | head_list_phys = priv->tx_list_dma |
| 1524 | + sizeof(struct tlan_list)*priv->tx_head; |
| 1525 | if (head_list->c_stat & TLAN_CSTAT_READY) { |
| 1526 | outl(head_list_phys, dev->base_addr + TLAN_CH_PARM); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1527 | ack |= TLAN_HC_GO; |
| 1528 | } else { |
Sakari Ailus | c659c38 | 2011-01-21 10:59:30 +0000 | [diff] [blame] | 1529 | priv->tx_in_progress = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1530 | } |
| 1531 | } |
Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 1532 | |
Sakari Ailus | c659c38 | 2011-01-21 10:59:30 +0000 | [diff] [blame] | 1533 | if (priv->adapter->flags & TLAN_ADAPTER_ACTIVITY_LED) { |
| 1534 | tlan_dio_write8(dev->base_addr, |
| 1535 | TLAN_LED_REG, TLAN_LED_LINK | TLAN_LED_ACT); |
| 1536 | if (priv->timer.function == NULL) { |
| 1537 | priv->timer.function = tlan_timer; |
| 1538 | priv->timer.data = (unsigned long) dev; |
| 1539 | priv->timer.expires = jiffies + TLAN_TIMER_ACT_DELAY; |
| 1540 | priv->timer_set_at = jiffies; |
| 1541 | priv->timer_type = TLAN_TIMER_ACTIVITY; |
| 1542 | add_timer(&priv->timer); |
| 1543 | } else if (priv->timer_type == TLAN_TIMER_ACTIVITY) { |
| 1544 | priv->timer_set_at = jiffies; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1545 | } |
| 1546 | } |
| 1547 | |
| 1548 | return ack; |
| 1549 | |
Sakari Ailus | c659c38 | 2011-01-21 10:59:30 +0000 | [diff] [blame] | 1550 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1551 | |
| 1552 | |
| 1553 | |
| 1554 | |
Sakari Ailus | c659c38 | 2011-01-21 10:59:30 +0000 | [diff] [blame] | 1555 | /*************************************************************** |
| 1556 | * TLan_HandleStatOverflow |
| 1557 | * |
| 1558 | * Returns: |
| 1559 | * 1 |
| 1560 | * Parms: |
| 1561 | * dev Device assigned the IRQ that was |
| 1562 | * raised. |
| 1563 | * host_int The contents of the HOST_INT |
| 1564 | * port. |
| 1565 | * |
| 1566 | * This function handles the Statistics Overflow interrupt |
| 1567 | * which means that one or more of the TLAN statistics |
| 1568 | * registers has reached 1/2 capacity and needs to be read. |
| 1569 | * |
| 1570 | **************************************************************/ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1571 | |
Sakari Ailus | c659c38 | 2011-01-21 10:59:30 +0000 | [diff] [blame] | 1572 | static u32 tlan_handle_stat_overflow(struct net_device *dev, u16 host_int) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1573 | { |
Sakari Ailus | c659c38 | 2011-01-21 10:59:30 +0000 | [diff] [blame] | 1574 | tlan_read_and_clear_stats(dev, TLAN_RECORD); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1575 | |
| 1576 | return 1; |
| 1577 | |
Sakari Ailus | c659c38 | 2011-01-21 10:59:30 +0000 | [diff] [blame] | 1578 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1579 | |
| 1580 | |
| 1581 | |
| 1582 | |
Sakari Ailus | c659c38 | 2011-01-21 10:59:30 +0000 | [diff] [blame] | 1583 | /*************************************************************** |
| 1584 | * TLan_HandleRxEOF |
| 1585 | * |
| 1586 | * Returns: |
| 1587 | * 1 |
| 1588 | * Parms: |
| 1589 | * dev Device assigned the IRQ that was |
| 1590 | * raised. |
| 1591 | * host_int The contents of the HOST_INT |
| 1592 | * port. |
| 1593 | * |
| 1594 | * This function handles the Rx EOF interrupt which |
| 1595 | * indicates a frame has been received by the adapter from |
| 1596 | * the net and the frame has been transferred to memory. |
| 1597 | * The function determines the bounce buffer the frame has |
| 1598 | * been loaded into, creates a new sk_buff big enough to |
| 1599 | * hold the frame, and sends it to protocol stack. It |
| 1600 | * then resets the used buffer and appends it to the end |
| 1601 | * of the list. If the frame was the last in the Rx |
| 1602 | * channel (EOC), the function restarts the receive channel |
| 1603 | * by sending an Rx Go command to the adapter. Then it |
| 1604 | * activates/continues the activity LED. |
| 1605 | * |
| 1606 | **************************************************************/ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1607 | |
Sakari Ailus | c659c38 | 2011-01-21 10:59:30 +0000 | [diff] [blame] | 1608 | static u32 tlan_handle_rx_eof(struct net_device *dev, u16 host_int) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1609 | { |
Sakari Ailus | c659c38 | 2011-01-21 10:59:30 +0000 | [diff] [blame] | 1610 | struct tlan_priv *priv = netdev_priv(dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1611 | u32 ack = 0; |
| 1612 | int eoc = 0; |
Sakari Ailus | c659c38 | 2011-01-21 10:59:30 +0000 | [diff] [blame] | 1613 | struct tlan_list *head_list; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1614 | struct sk_buff *skb; |
Sakari Ailus | c659c38 | 2011-01-21 10:59:30 +0000 | [diff] [blame] | 1615 | struct tlan_list *tail_list; |
| 1616 | u16 tmp_c_stat; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1617 | dma_addr_t head_list_phys; |
| 1618 | |
Sakari Ailus | c659c38 | 2011-01-21 10:59:30 +0000 | [diff] [blame] | 1619 | TLAN_DBG(TLAN_DEBUG_RX, "RECEIVE: handling RX EOF (Head=%d Tail=%d)\n", |
| 1620 | priv->rx_head, priv->rx_tail); |
| 1621 | head_list = priv->rx_list + priv->rx_head; |
| 1622 | head_list_phys = |
| 1623 | priv->rx_list_dma + sizeof(struct tlan_list)*priv->rx_head; |
Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 1624 | |
Sakari Ailus | c659c38 | 2011-01-21 10:59:30 +0000 | [diff] [blame] | 1625 | while (((tmp_c_stat = head_list->c_stat) & TLAN_CSTAT_FRM_CMP) |
| 1626 | && (ack < 255)) { |
| 1627 | dma_addr_t frame_dma = head_list->buffer[0].address; |
| 1628 | u32 frame_size = head_list->frame_size; |
Sakari Ailus | 5eeabf5 | 2008-12-16 15:24:05 -0800 | [diff] [blame] | 1629 | struct sk_buff *new_skb; |
| 1630 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1631 | ack++; |
Sakari Ailus | c659c38 | 2011-01-21 10:59:30 +0000 | [diff] [blame] | 1632 | if (tmp_c_stat & TLAN_CSTAT_EOC) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1633 | eoc = 1; |
Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 1634 | |
Eric Dumazet | 89d71a6 | 2009-10-13 05:34:20 +0000 | [diff] [blame] | 1635 | new_skb = netdev_alloc_skb_ip_align(dev, |
| 1636 | TLAN_MAX_FRAME_SIZE + 5); |
Sakari Ailus | c659c38 | 2011-01-21 10:59:30 +0000 | [diff] [blame] | 1637 | if (!new_skb) |
Sakari Ailus | 5eeabf5 | 2008-12-16 15:24:05 -0800 | [diff] [blame] | 1638 | goto drop_and_reuse; |
Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 1639 | |
Sakari Ailus | c659c38 | 2011-01-21 10:59:30 +0000 | [diff] [blame] | 1640 | skb = tlan_get_skb(head_list); |
| 1641 | pci_unmap_single(priv->pci_dev, frame_dma, |
Sakari Ailus | 5eeabf5 | 2008-12-16 15:24:05 -0800 | [diff] [blame] | 1642 | TLAN_MAX_FRAME_SIZE, PCI_DMA_FROMDEVICE); |
Sakari Ailus | c659c38 | 2011-01-21 10:59:30 +0000 | [diff] [blame] | 1643 | skb_put(skb, frame_size); |
Stephen Hemminger | dfc2c0a | 2008-05-30 09:49:58 -0700 | [diff] [blame] | 1644 | |
Sakari Ailus | c659c38 | 2011-01-21 10:59:30 +0000 | [diff] [blame] | 1645 | dev->stats.rx_bytes += frame_size; |
Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 1646 | |
Sakari Ailus | c659c38 | 2011-01-21 10:59:30 +0000 | [diff] [blame] | 1647 | skb->protocol = eth_type_trans(skb, dev); |
| 1648 | netif_rx(skb); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1649 | |
Sakari Ailus | c659c38 | 2011-01-21 10:59:30 +0000 | [diff] [blame] | 1650 | head_list->buffer[0].address = |
| 1651 | pci_map_single(priv->pci_dev, new_skb->data, |
| 1652 | TLAN_MAX_FRAME_SIZE, PCI_DMA_FROMDEVICE); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1653 | |
Sakari Ailus | c659c38 | 2011-01-21 10:59:30 +0000 | [diff] [blame] | 1654 | tlan_store_skb(head_list, new_skb); |
Stephen Hemminger | dfc2c0a | 2008-05-30 09:49:58 -0700 | [diff] [blame] | 1655 | drop_and_reuse: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1656 | head_list->forward = 0; |
Sakari Ailus | c659c38 | 2011-01-21 10:59:30 +0000 | [diff] [blame] | 1657 | head_list->c_stat = 0; |
| 1658 | tail_list = priv->rx_list + priv->rx_tail; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1659 | tail_list->forward = head_list_phys; |
| 1660 | |
Sakari Ailus | c659c38 | 2011-01-21 10:59:30 +0000 | [diff] [blame] | 1661 | CIRC_INC(priv->rx_head, TLAN_NUM_RX_LISTS); |
| 1662 | CIRC_INC(priv->rx_tail, TLAN_NUM_RX_LISTS); |
| 1663 | head_list = priv->rx_list + priv->rx_head; |
| 1664 | head_list_phys = priv->rx_list_dma |
| 1665 | + sizeof(struct tlan_list)*priv->rx_head; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1666 | } |
| 1667 | |
| 1668 | if (!ack) |
Sakari Ailus | c659c38 | 2011-01-21 10:59:30 +0000 | [diff] [blame] | 1669 | printk(KERN_INFO |
| 1670 | "TLAN: Received interrupt for uncompleted RX frame.\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1671 | |
| 1672 | |
Sakari Ailus | c659c38 | 2011-01-21 10:59:30 +0000 | [diff] [blame] | 1673 | if (eoc) { |
| 1674 | TLAN_DBG(TLAN_DEBUG_RX, |
| 1675 | "RECEIVE: handling RX EOC (Head=%d Tail=%d)\n", |
| 1676 | priv->rx_head, priv->rx_tail); |
| 1677 | head_list = priv->rx_list + priv->rx_head; |
| 1678 | head_list_phys = priv->rx_list_dma |
| 1679 | + sizeof(struct tlan_list)*priv->rx_head; |
| 1680 | outl(head_list_phys, dev->base_addr + TLAN_CH_PARM); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1681 | ack |= TLAN_HC_GO | TLAN_HC_RT; |
Sakari Ailus | c659c38 | 2011-01-21 10:59:30 +0000 | [diff] [blame] | 1682 | priv->rx_eoc_count++; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1683 | } |
| 1684 | |
Sakari Ailus | c659c38 | 2011-01-21 10:59:30 +0000 | [diff] [blame] | 1685 | if (priv->adapter->flags & TLAN_ADAPTER_ACTIVITY_LED) { |
| 1686 | tlan_dio_write8(dev->base_addr, |
| 1687 | TLAN_LED_REG, TLAN_LED_LINK | TLAN_LED_ACT); |
| 1688 | if (priv->timer.function == NULL) { |
| 1689 | priv->timer.function = tlan_timer; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1690 | priv->timer.data = (unsigned long) dev; |
| 1691 | priv->timer.expires = jiffies + TLAN_TIMER_ACT_DELAY; |
Sakari Ailus | c659c38 | 2011-01-21 10:59:30 +0000 | [diff] [blame] | 1692 | priv->timer_set_at = jiffies; |
| 1693 | priv->timer_type = TLAN_TIMER_ACTIVITY; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1694 | add_timer(&priv->timer); |
Sakari Ailus | c659c38 | 2011-01-21 10:59:30 +0000 | [diff] [blame] | 1695 | } else if (priv->timer_type == TLAN_TIMER_ACTIVITY) { |
| 1696 | priv->timer_set_at = jiffies; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1697 | } |
| 1698 | } |
| 1699 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1700 | return ack; |
| 1701 | |
Sakari Ailus | c659c38 | 2011-01-21 10:59:30 +0000 | [diff] [blame] | 1702 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1703 | |
| 1704 | |
| 1705 | |
| 1706 | |
Sakari Ailus | c659c38 | 2011-01-21 10:59:30 +0000 | [diff] [blame] | 1707 | /*************************************************************** |
| 1708 | * tlan_handle_dummy |
| 1709 | * |
| 1710 | * Returns: |
| 1711 | * 1 |
| 1712 | * Parms: |
| 1713 | * dev Device assigned the IRQ that was |
| 1714 | * raised. |
| 1715 | * host_int The contents of the HOST_INT |
| 1716 | * port. |
| 1717 | * |
| 1718 | * This function handles the Dummy interrupt, which is |
| 1719 | * raised whenever a test interrupt is generated by setting |
| 1720 | * the Req_Int bit of HOST_CMD to 1. |
| 1721 | * |
| 1722 | **************************************************************/ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1723 | |
Sakari Ailus | c659c38 | 2011-01-21 10:59:30 +0000 | [diff] [blame] | 1724 | static u32 tlan_handle_dummy(struct net_device *dev, u16 host_int) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1725 | { |
Sakari Ailus | c659c38 | 2011-01-21 10:59:30 +0000 | [diff] [blame] | 1726 | pr_info("TLAN: Test interrupt on %s.\n", dev->name); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1727 | return 1; |
| 1728 | |
Sakari Ailus | c659c38 | 2011-01-21 10:59:30 +0000 | [diff] [blame] | 1729 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1730 | |
| 1731 | |
| 1732 | |
| 1733 | |
Sakari Ailus | c659c38 | 2011-01-21 10:59:30 +0000 | [diff] [blame] | 1734 | /*************************************************************** |
| 1735 | * tlan_handle_tx_eoc |
| 1736 | * |
| 1737 | * Returns: |
| 1738 | * 1 |
| 1739 | * Parms: |
| 1740 | * dev Device assigned the IRQ that was |
| 1741 | * raised. |
| 1742 | * host_int The contents of the HOST_INT |
| 1743 | * port. |
| 1744 | * |
| 1745 | * This driver is structured to determine EOC occurrences by |
| 1746 | * reading the CSTAT member of the list structure. Tx EOC |
| 1747 | * interrupts are disabled via the DIO INTDIS register. |
| 1748 | * However, TLAN chips before revision 3.0 didn't have this |
| 1749 | * functionality, so process EOC events if this is the |
| 1750 | * case. |
| 1751 | * |
| 1752 | **************************************************************/ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1753 | |
Sakari Ailus | c659c38 | 2011-01-21 10:59:30 +0000 | [diff] [blame] | 1754 | static u32 tlan_handle_tx_eoc(struct net_device *dev, u16 host_int) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1755 | { |
Sakari Ailus | c659c38 | 2011-01-21 10:59:30 +0000 | [diff] [blame] | 1756 | struct tlan_priv *priv = netdev_priv(dev); |
| 1757 | struct tlan_list *head_list; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1758 | dma_addr_t head_list_phys; |
| 1759 | u32 ack = 1; |
Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 1760 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1761 | host_int = 0; |
Sakari Ailus | c659c38 | 2011-01-21 10:59:30 +0000 | [diff] [blame] | 1762 | if (priv->tlan_rev < 0x30) { |
| 1763 | TLAN_DBG(TLAN_DEBUG_TX, |
| 1764 | "TRANSMIT: handling TX EOC (Head=%d Tail=%d) -- IRQ\n", |
| 1765 | priv->tx_head, priv->tx_tail); |
| 1766 | head_list = priv->tx_list + priv->tx_head; |
| 1767 | head_list_phys = priv->tx_list_dma |
| 1768 | + sizeof(struct tlan_list)*priv->tx_head; |
| 1769 | if (head_list->c_stat & TLAN_CSTAT_READY) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1770 | netif_stop_queue(dev); |
Sakari Ailus | c659c38 | 2011-01-21 10:59:30 +0000 | [diff] [blame] | 1771 | outl(head_list_phys, dev->base_addr + TLAN_CH_PARM); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1772 | ack |= TLAN_HC_GO; |
| 1773 | } else { |
Sakari Ailus | c659c38 | 2011-01-21 10:59:30 +0000 | [diff] [blame] | 1774 | priv->tx_in_progress = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1775 | } |
| 1776 | } |
| 1777 | |
| 1778 | return ack; |
| 1779 | |
Sakari Ailus | c659c38 | 2011-01-21 10:59:30 +0000 | [diff] [blame] | 1780 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1781 | |
| 1782 | |
| 1783 | |
| 1784 | |
Sakari Ailus | c659c38 | 2011-01-21 10:59:30 +0000 | [diff] [blame] | 1785 | /*************************************************************** |
| 1786 | * tlan_handle_status_check |
| 1787 | * |
| 1788 | * Returns: |
| 1789 | * 0 if Adapter check, 1 if Network Status check. |
| 1790 | * Parms: |
| 1791 | * dev Device assigned the IRQ that was |
| 1792 | * raised. |
| 1793 | * host_int The contents of the HOST_INT |
| 1794 | * port. |
| 1795 | * |
| 1796 | * This function handles Adapter Check/Network Status |
| 1797 | * interrupts generated by the adapter. It checks the |
| 1798 | * vector in the HOST_INT register to determine if it is |
| 1799 | * an Adapter Check interrupt. If so, it resets the |
| 1800 | * adapter. Otherwise it clears the status registers |
| 1801 | * and services the PHY. |
| 1802 | * |
| 1803 | **************************************************************/ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1804 | |
Sakari Ailus | c659c38 | 2011-01-21 10:59:30 +0000 | [diff] [blame] | 1805 | static u32 tlan_handle_status_check(struct net_device *dev, u16 host_int) |
Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 1806 | { |
Sakari Ailus | c659c38 | 2011-01-21 10:59:30 +0000 | [diff] [blame] | 1807 | struct tlan_priv *priv = netdev_priv(dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1808 | u32 ack; |
| 1809 | u32 error; |
| 1810 | u8 net_sts; |
| 1811 | u32 phy; |
| 1812 | u16 tlphy_ctl; |
| 1813 | u16 tlphy_sts; |
Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 1814 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1815 | ack = 1; |
Sakari Ailus | c659c38 | 2011-01-21 10:59:30 +0000 | [diff] [blame] | 1816 | if (host_int & TLAN_HI_IV_MASK) { |
| 1817 | netif_stop_queue(dev); |
| 1818 | error = inl(dev->base_addr + TLAN_CH_PARM); |
| 1819 | pr_info("TLAN: %s: Adaptor Error = 0x%x\n", dev->name, error); |
| 1820 | tlan_read_and_clear_stats(dev, TLAN_RECORD); |
| 1821 | outl(TLAN_HC_AD_RST, dev->base_addr + TLAN_HOST_CMD); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1822 | |
| 1823 | schedule_work(&priv->tlan_tqueue); |
| 1824 | |
| 1825 | netif_wake_queue(dev); |
| 1826 | ack = 0; |
| 1827 | } else { |
Sakari Ailus | c659c38 | 2011-01-21 10:59:30 +0000 | [diff] [blame] | 1828 | TLAN_DBG(TLAN_DEBUG_GNRL, "%s: Status Check\n", dev->name); |
| 1829 | phy = priv->phy[priv->phy_num]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1830 | |
Sakari Ailus | c659c38 | 2011-01-21 10:59:30 +0000 | [diff] [blame] | 1831 | net_sts = tlan_dio_read8(dev->base_addr, TLAN_NET_STS); |
| 1832 | if (net_sts) { |
| 1833 | tlan_dio_write8(dev->base_addr, TLAN_NET_STS, net_sts); |
| 1834 | TLAN_DBG(TLAN_DEBUG_GNRL, "%s: Net_Sts = %x\n", |
| 1835 | dev->name, (unsigned) net_sts); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1836 | } |
Sakari Ailus | c659c38 | 2011-01-21 10:59:30 +0000 | [diff] [blame] | 1837 | if ((net_sts & TLAN_NET_STS_MIRQ) && (priv->phy_num == 0)) { |
| 1838 | tlan_mii_read_reg(dev, phy, TLAN_TLPHY_STS, &tlphy_sts); |
| 1839 | tlan_mii_read_reg(dev, phy, TLAN_TLPHY_CTL, &tlphy_ctl); |
| 1840 | if (!(tlphy_sts & TLAN_TS_POLOK) && |
| 1841 | !(tlphy_ctl & TLAN_TC_SWAPOL)) { |
| 1842 | tlphy_ctl |= TLAN_TC_SWAPOL; |
| 1843 | tlan_mii_write_reg(dev, phy, TLAN_TLPHY_CTL, |
| 1844 | tlphy_ctl); |
| 1845 | } else if ((tlphy_sts & TLAN_TS_POLOK) && |
| 1846 | (tlphy_ctl & TLAN_TC_SWAPOL)) { |
| 1847 | tlphy_ctl &= ~TLAN_TC_SWAPOL; |
| 1848 | tlan_mii_write_reg(dev, phy, TLAN_TLPHY_CTL, |
| 1849 | tlphy_ctl); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1850 | } |
Sakari Ailus | c659c38 | 2011-01-21 10:59:30 +0000 | [diff] [blame] | 1851 | |
| 1852 | if (debug) |
| 1853 | tlan_phy_print(dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1854 | } |
| 1855 | } |
| 1856 | |
| 1857 | return ack; |
| 1858 | |
Sakari Ailus | c659c38 | 2011-01-21 10:59:30 +0000 | [diff] [blame] | 1859 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1860 | |
| 1861 | |
| 1862 | |
| 1863 | |
Sakari Ailus | c659c38 | 2011-01-21 10:59:30 +0000 | [diff] [blame] | 1864 | /*************************************************************** |
| 1865 | * tlan_handle_rx_eoc |
| 1866 | * |
| 1867 | * Returns: |
| 1868 | * 1 |
| 1869 | * Parms: |
| 1870 | * dev Device assigned the IRQ that was |
| 1871 | * raised. |
| 1872 | * host_int The contents of the HOST_INT |
| 1873 | * port. |
| 1874 | * |
| 1875 | * This driver is structured to determine EOC occurrences by |
| 1876 | * reading the CSTAT member of the list structure. Rx EOC |
| 1877 | * interrupts are disabled via the DIO INTDIS register. |
| 1878 | * However, TLAN chips before revision 3.0 didn't have this |
| 1879 | * CSTAT member or a INTDIS register, so if this chip is |
| 1880 | * pre-3.0, process EOC interrupts normally. |
| 1881 | * |
| 1882 | **************************************************************/ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1883 | |
Sakari Ailus | c659c38 | 2011-01-21 10:59:30 +0000 | [diff] [blame] | 1884 | static u32 tlan_handle_rx_eoc(struct net_device *dev, u16 host_int) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1885 | { |
Sakari Ailus | c659c38 | 2011-01-21 10:59:30 +0000 | [diff] [blame] | 1886 | struct tlan_priv *priv = netdev_priv(dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1887 | dma_addr_t head_list_phys; |
| 1888 | u32 ack = 1; |
| 1889 | |
Sakari Ailus | c659c38 | 2011-01-21 10:59:30 +0000 | [diff] [blame] | 1890 | if (priv->tlan_rev < 0x30) { |
| 1891 | TLAN_DBG(TLAN_DEBUG_RX, |
| 1892 | "RECEIVE: Handling RX EOC (head=%d tail=%d) -- IRQ\n", |
| 1893 | priv->rx_head, priv->rx_tail); |
| 1894 | head_list_phys = priv->rx_list_dma |
| 1895 | + sizeof(struct tlan_list)*priv->rx_head; |
| 1896 | outl(head_list_phys, dev->base_addr + TLAN_CH_PARM); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1897 | ack |= TLAN_HC_GO | TLAN_HC_RT; |
Sakari Ailus | c659c38 | 2011-01-21 10:59:30 +0000 | [diff] [blame] | 1898 | priv->rx_eoc_count++; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1899 | } |
| 1900 | |
| 1901 | return ack; |
| 1902 | |
Sakari Ailus | c659c38 | 2011-01-21 10:59:30 +0000 | [diff] [blame] | 1903 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1904 | |
| 1905 | |
| 1906 | |
| 1907 | |
| 1908 | /***************************************************************************** |
| 1909 | ****************************************************************************** |
| 1910 | |
Sakari Ailus | c659c38 | 2011-01-21 10:59:30 +0000 | [diff] [blame] | 1911 | ThunderLAN driver timer function |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1912 | |
| 1913 | ****************************************************************************** |
| 1914 | *****************************************************************************/ |
| 1915 | |
| 1916 | |
Sakari Ailus | c659c38 | 2011-01-21 10:59:30 +0000 | [diff] [blame] | 1917 | /*************************************************************** |
| 1918 | * tlan_timer |
| 1919 | * |
| 1920 | * Returns: |
| 1921 | * Nothing |
| 1922 | * Parms: |
| 1923 | * data A value given to add timer when |
| 1924 | * add_timer was called. |
| 1925 | * |
| 1926 | * This function handles timed functionality for the |
| 1927 | * TLAN driver. The two current timer uses are for |
| 1928 | * delaying for autonegotionation and driving the ACT LED. |
| 1929 | * - Autonegotiation requires being allowed about |
| 1930 | * 2 1/2 seconds before attempting to transmit a |
| 1931 | * packet. It would be a very bad thing to hang |
| 1932 | * the kernel this long, so the driver doesn't |
| 1933 | * allow transmission 'til after this time, for |
| 1934 | * certain PHYs. It would be much nicer if all |
| 1935 | * PHYs were interrupt-capable like the internal |
| 1936 | * PHY. |
| 1937 | * - The ACT LED, which shows adapter activity, is |
| 1938 | * driven by the driver, and so must be left on |
| 1939 | * for a short period to power up the LED so it |
| 1940 | * can be seen. This delay can be changed by |
| 1941 | * changing the TLAN_TIMER_ACT_DELAY in tlan.h, |
| 1942 | * if desired. 100 ms produces a slightly |
| 1943 | * sluggish response. |
| 1944 | * |
| 1945 | **************************************************************/ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1946 | |
Sakari Ailus | c659c38 | 2011-01-21 10:59:30 +0000 | [diff] [blame] | 1947 | static void tlan_timer(unsigned long data) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1948 | { |
| 1949 | struct net_device *dev = (struct net_device *) data; |
Sakari Ailus | c659c38 | 2011-01-21 10:59:30 +0000 | [diff] [blame] | 1950 | struct tlan_priv *priv = netdev_priv(dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1951 | u32 elapsed; |
| 1952 | unsigned long flags = 0; |
| 1953 | |
| 1954 | priv->timer.function = NULL; |
| 1955 | |
Sakari Ailus | c659c38 | 2011-01-21 10:59:30 +0000 | [diff] [blame] | 1956 | switch (priv->timer_type) { |
Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 1957 | #ifdef MONITOR |
Sakari Ailus | c659c38 | 2011-01-21 10:59:30 +0000 | [diff] [blame] | 1958 | case TLAN_TIMER_LINK_BEAT: |
| 1959 | tlan_phy_monitor(dev); |
| 1960 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1961 | #endif |
Sakari Ailus | c659c38 | 2011-01-21 10:59:30 +0000 | [diff] [blame] | 1962 | case TLAN_TIMER_PHY_PDOWN: |
| 1963 | tlan_phy_power_down(dev); |
| 1964 | break; |
| 1965 | case TLAN_TIMER_PHY_PUP: |
| 1966 | tlan_phy_power_up(dev); |
| 1967 | break; |
| 1968 | case TLAN_TIMER_PHY_RESET: |
| 1969 | tlan_phy_reset(dev); |
| 1970 | break; |
| 1971 | case TLAN_TIMER_PHY_START_LINK: |
| 1972 | tlan_phy_start_link(dev); |
| 1973 | break; |
| 1974 | case TLAN_TIMER_PHY_FINISH_AN: |
| 1975 | tlan_phy_finish_auto_neg(dev); |
| 1976 | break; |
| 1977 | case TLAN_TIMER_FINISH_RESET: |
| 1978 | tlan_finish_reset(dev); |
| 1979 | break; |
| 1980 | case TLAN_TIMER_ACTIVITY: |
| 1981 | spin_lock_irqsave(&priv->lock, flags); |
| 1982 | if (priv->timer.function == NULL) { |
| 1983 | elapsed = jiffies - priv->timer_set_at; |
| 1984 | if (elapsed >= TLAN_TIMER_ACT_DELAY) { |
| 1985 | tlan_dio_write8(dev->base_addr, |
| 1986 | TLAN_LED_REG, TLAN_LED_LINK); |
| 1987 | } else { |
| 1988 | priv->timer.function = tlan_timer; |
| 1989 | priv->timer.expires = priv->timer_set_at |
| 1990 | + TLAN_TIMER_ACT_DELAY; |
| 1991 | spin_unlock_irqrestore(&priv->lock, flags); |
| 1992 | add_timer(&priv->timer); |
| 1993 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1994 | } |
Sakari Ailus | c659c38 | 2011-01-21 10:59:30 +0000 | [diff] [blame] | 1995 | } |
| 1996 | spin_unlock_irqrestore(&priv->lock, flags); |
| 1997 | break; |
| 1998 | default: |
| 1999 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2000 | } |
| 2001 | |
Sakari Ailus | c659c38 | 2011-01-21 10:59:30 +0000 | [diff] [blame] | 2002 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2003 | |
| 2004 | |
| 2005 | |
| 2006 | |
| 2007 | /***************************************************************************** |
| 2008 | ****************************************************************************** |
| 2009 | |
Sakari Ailus | c659c38 | 2011-01-21 10:59:30 +0000 | [diff] [blame] | 2010 | ThunderLAN driver adapter related routines |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2011 | |
| 2012 | ****************************************************************************** |
| 2013 | *****************************************************************************/ |
| 2014 | |
| 2015 | |
Sakari Ailus | c659c38 | 2011-01-21 10:59:30 +0000 | [diff] [blame] | 2016 | /*************************************************************** |
| 2017 | * tlan_reset_lists |
| 2018 | * |
| 2019 | * Returns: |
| 2020 | * Nothing |
| 2021 | * Parms: |
| 2022 | * dev The device structure with the list |
| 2023 | * stuctures to be reset. |
| 2024 | * |
| 2025 | * This routine sets the variables associated with managing |
| 2026 | * the TLAN lists to their initial values. |
| 2027 | * |
| 2028 | **************************************************************/ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2029 | |
Sakari Ailus | c659c38 | 2011-01-21 10:59:30 +0000 | [diff] [blame] | 2030 | static void tlan_reset_lists(struct net_device *dev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2031 | { |
Sakari Ailus | c659c38 | 2011-01-21 10:59:30 +0000 | [diff] [blame] | 2032 | struct tlan_priv *priv = netdev_priv(dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2033 | int i; |
Sakari Ailus | c659c38 | 2011-01-21 10:59:30 +0000 | [diff] [blame] | 2034 | struct tlan_list *list; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2035 | dma_addr_t list_phys; |
| 2036 | struct sk_buff *skb; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2037 | |
Sakari Ailus | c659c38 | 2011-01-21 10:59:30 +0000 | [diff] [blame] | 2038 | priv->tx_head = 0; |
| 2039 | priv->tx_tail = 0; |
| 2040 | for (i = 0; i < TLAN_NUM_TX_LISTS; i++) { |
| 2041 | list = priv->tx_list + i; |
| 2042 | list->c_stat = TLAN_CSTAT_UNUSED; |
Sakari Ailus | 5eeabf5 | 2008-12-16 15:24:05 -0800 | [diff] [blame] | 2043 | list->buffer[0].address = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2044 | list->buffer[2].count = 0; |
| 2045 | list->buffer[2].address = 0; |
| 2046 | list->buffer[8].address = 0; |
| 2047 | list->buffer[9].address = 0; |
| 2048 | } |
| 2049 | |
Sakari Ailus | c659c38 | 2011-01-21 10:59:30 +0000 | [diff] [blame] | 2050 | priv->rx_head = 0; |
| 2051 | priv->rx_tail = TLAN_NUM_RX_LISTS - 1; |
| 2052 | for (i = 0; i < TLAN_NUM_RX_LISTS; i++) { |
| 2053 | list = priv->rx_list + i; |
| 2054 | list_phys = priv->rx_list_dma + sizeof(struct tlan_list)*i; |
| 2055 | list->c_stat = TLAN_CSTAT_READY; |
| 2056 | list->frame_size = TLAN_MAX_FRAME_SIZE; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2057 | list->buffer[0].count = TLAN_MAX_FRAME_SIZE | TLAN_LAST_BUFFER; |
Eric Dumazet | 89d71a6 | 2009-10-13 05:34:20 +0000 | [diff] [blame] | 2058 | skb = netdev_alloc_skb_ip_align(dev, TLAN_MAX_FRAME_SIZE + 5); |
Sakari Ailus | c659c38 | 2011-01-21 10:59:30 +0000 | [diff] [blame] | 2059 | if (!skb) { |
| 2060 | pr_err("TLAN: out of memory for received data.\n"); |
Sakari Ailus | 5eeabf5 | 2008-12-16 15:24:05 -0800 | [diff] [blame] | 2061 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2062 | } |
Sakari Ailus | 5eeabf5 | 2008-12-16 15:24:05 -0800 | [diff] [blame] | 2063 | |
Sakari Ailus | c659c38 | 2011-01-21 10:59:30 +0000 | [diff] [blame] | 2064 | list->buffer[0].address = pci_map_single(priv->pci_dev, |
Sakari Ailus | 5eeabf5 | 2008-12-16 15:24:05 -0800 | [diff] [blame] | 2065 | skb->data, |
| 2066 | TLAN_MAX_FRAME_SIZE, |
| 2067 | PCI_DMA_FROMDEVICE); |
Sakari Ailus | c659c38 | 2011-01-21 10:59:30 +0000 | [diff] [blame] | 2068 | tlan_store_skb(list, skb); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2069 | list->buffer[1].count = 0; |
| 2070 | list->buffer[1].address = 0; |
Sakari Ailus | c659c38 | 2011-01-21 10:59:30 +0000 | [diff] [blame] | 2071 | list->forward = list_phys + sizeof(struct tlan_list); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2072 | } |
| 2073 | |
Stephen Hemminger | 9ded65a | 2008-05-30 09:49:56 -0700 | [diff] [blame] | 2074 | /* in case ran out of memory early, clear bits */ |
| 2075 | while (i < TLAN_NUM_RX_LISTS) { |
Sakari Ailus | c659c38 | 2011-01-21 10:59:30 +0000 | [diff] [blame] | 2076 | tlan_store_skb(priv->rx_list + i, NULL); |
Stephen Hemminger | 9ded65a | 2008-05-30 09:49:56 -0700 | [diff] [blame] | 2077 | ++i; |
| 2078 | } |
| 2079 | list->forward = 0; |
| 2080 | |
Sakari Ailus | c659c38 | 2011-01-21 10:59:30 +0000 | [diff] [blame] | 2081 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2082 | |
| 2083 | |
Sakari Ailus | c659c38 | 2011-01-21 10:59:30 +0000 | [diff] [blame] | 2084 | static void tlan_free_lists(struct net_device *dev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2085 | { |
Sakari Ailus | c659c38 | 2011-01-21 10:59:30 +0000 | [diff] [blame] | 2086 | struct tlan_priv *priv = netdev_priv(dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2087 | int i; |
Sakari Ailus | c659c38 | 2011-01-21 10:59:30 +0000 | [diff] [blame] | 2088 | struct tlan_list *list; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2089 | struct sk_buff *skb; |
| 2090 | |
Sakari Ailus | c659c38 | 2011-01-21 10:59:30 +0000 | [diff] [blame] | 2091 | for (i = 0; i < TLAN_NUM_TX_LISTS; i++) { |
| 2092 | list = priv->tx_list + i; |
| 2093 | skb = tlan_get_skb(list); |
| 2094 | if (skb) { |
Sakari Ailus | 5eeabf5 | 2008-12-16 15:24:05 -0800 | [diff] [blame] | 2095 | pci_unmap_single( |
Sakari Ailus | c659c38 | 2011-01-21 10:59:30 +0000 | [diff] [blame] | 2096 | priv->pci_dev, |
Sakari Ailus | 5eeabf5 | 2008-12-16 15:24:05 -0800 | [diff] [blame] | 2097 | list->buffer[0].address, |
| 2098 | max(skb->len, |
| 2099 | (unsigned int)TLAN_MIN_FRAME_SIZE), |
| 2100 | PCI_DMA_TODEVICE); |
Sakari Ailus | c659c38 | 2011-01-21 10:59:30 +0000 | [diff] [blame] | 2101 | dev_kfree_skb_any(skb); |
Sakari Ailus | 5eeabf5 | 2008-12-16 15:24:05 -0800 | [diff] [blame] | 2102 | list->buffer[8].address = 0; |
| 2103 | list->buffer[9].address = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2104 | } |
Sakari Ailus | 5eeabf5 | 2008-12-16 15:24:05 -0800 | [diff] [blame] | 2105 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2106 | |
Sakari Ailus | c659c38 | 2011-01-21 10:59:30 +0000 | [diff] [blame] | 2107 | for (i = 0; i < TLAN_NUM_RX_LISTS; i++) { |
| 2108 | list = priv->rx_list + i; |
| 2109 | skb = tlan_get_skb(list); |
| 2110 | if (skb) { |
| 2111 | pci_unmap_single(priv->pci_dev, |
Sakari Ailus | 5eeabf5 | 2008-12-16 15:24:05 -0800 | [diff] [blame] | 2112 | list->buffer[0].address, |
| 2113 | TLAN_MAX_FRAME_SIZE, |
| 2114 | PCI_DMA_FROMDEVICE); |
Sakari Ailus | c659c38 | 2011-01-21 10:59:30 +0000 | [diff] [blame] | 2115 | dev_kfree_skb_any(skb); |
Sakari Ailus | 5eeabf5 | 2008-12-16 15:24:05 -0800 | [diff] [blame] | 2116 | list->buffer[8].address = 0; |
| 2117 | list->buffer[9].address = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2118 | } |
| 2119 | } |
Sakari Ailus | c659c38 | 2011-01-21 10:59:30 +0000 | [diff] [blame] | 2120 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2121 | |
| 2122 | |
| 2123 | |
| 2124 | |
Sakari Ailus | c659c38 | 2011-01-21 10:59:30 +0000 | [diff] [blame] | 2125 | /*************************************************************** |
| 2126 | * tlan_print_dio |
| 2127 | * |
| 2128 | * Returns: |
| 2129 | * Nothing |
| 2130 | * Parms: |
| 2131 | * io_base Base IO port of the device of |
| 2132 | * which to print DIO registers. |
| 2133 | * |
| 2134 | * This function prints out all the internal (DIO) |
| 2135 | * registers of a TLAN chip. |
| 2136 | * |
| 2137 | **************************************************************/ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2138 | |
Sakari Ailus | c659c38 | 2011-01-21 10:59:30 +0000 | [diff] [blame] | 2139 | static void tlan_print_dio(u16 io_base) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2140 | { |
| 2141 | u32 data0, data1; |
| 2142 | int i; |
| 2143 | |
Sakari Ailus | c659c38 | 2011-01-21 10:59:30 +0000 | [diff] [blame] | 2144 | pr_info("TLAN: Contents of internal registers for io base 0x%04hx.\n", |
| 2145 | io_base); |
| 2146 | pr_info("TLAN: Off. +0 +4\n"); |
| 2147 | for (i = 0; i < 0x4C; i += 8) { |
| 2148 | data0 = tlan_dio_read32(io_base, i); |
| 2149 | data1 = tlan_dio_read32(io_base, i + 0x4); |
| 2150 | pr_info("TLAN: 0x%02x 0x%08x 0x%08x\n", i, data0, data1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2151 | } |
| 2152 | |
Sakari Ailus | c659c38 | 2011-01-21 10:59:30 +0000 | [diff] [blame] | 2153 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2154 | |
| 2155 | |
| 2156 | |
| 2157 | |
Sakari Ailus | c659c38 | 2011-01-21 10:59:30 +0000 | [diff] [blame] | 2158 | /*************************************************************** |
| 2159 | * TLan_PrintList |
| 2160 | * |
| 2161 | * Returns: |
| 2162 | * Nothing |
| 2163 | * Parms: |
| 2164 | * list A pointer to the struct tlan_list structure to |
| 2165 | * be printed. |
| 2166 | * type A string to designate type of list, |
| 2167 | * "Rx" or "Tx". |
| 2168 | * num The index of the list. |
| 2169 | * |
| 2170 | * This function prints out the contents of the list |
| 2171 | * pointed to by the list parameter. |
| 2172 | * |
| 2173 | **************************************************************/ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2174 | |
Sakari Ailus | c659c38 | 2011-01-21 10:59:30 +0000 | [diff] [blame] | 2175 | static void tlan_print_list(struct tlan_list *list, char *type, int num) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2176 | { |
| 2177 | int i; |
| 2178 | |
Sakari Ailus | c659c38 | 2011-01-21 10:59:30 +0000 | [diff] [blame] | 2179 | pr_info("TLAN: %s List %d at %p\n", type, num, list); |
| 2180 | pr_info("TLAN: Forward = 0x%08x\n", list->forward); |
| 2181 | pr_info("TLAN: CSTAT = 0x%04hx\n", list->c_stat); |
| 2182 | pr_info("TLAN: Frame Size = 0x%04hx\n", list->frame_size); |
| 2183 | /* for (i = 0; i < 10; i++) { */ |
| 2184 | for (i = 0; i < 2; i++) { |
| 2185 | pr_info("TLAN: Buffer[%d].count, addr = 0x%08x, 0x%08x\n", |
| 2186 | i, list->buffer[i].count, list->buffer[i].address); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2187 | } |
| 2188 | |
Sakari Ailus | c659c38 | 2011-01-21 10:59:30 +0000 | [diff] [blame] | 2189 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2190 | |
| 2191 | |
| 2192 | |
| 2193 | |
Sakari Ailus | c659c38 | 2011-01-21 10:59:30 +0000 | [diff] [blame] | 2194 | /*************************************************************** |
| 2195 | * tlan_read_and_clear_stats |
| 2196 | * |
| 2197 | * Returns: |
| 2198 | * Nothing |
| 2199 | * Parms: |
| 2200 | * dev Pointer to device structure of adapter |
| 2201 | * to which to read stats. |
| 2202 | * record Flag indicating whether to add |
| 2203 | * |
| 2204 | * This functions reads all the internal status registers |
| 2205 | * of the TLAN chip, which clears them as a side effect. |
| 2206 | * It then either adds the values to the device's status |
| 2207 | * struct, or discards them, depending on whether record |
| 2208 | * is TLAN_RECORD (!=0) or TLAN_IGNORE (==0). |
| 2209 | * |
| 2210 | **************************************************************/ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2211 | |
Sakari Ailus | c659c38 | 2011-01-21 10:59:30 +0000 | [diff] [blame] | 2212 | static void tlan_read_and_clear_stats(struct net_device *dev, int record) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2213 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2214 | u32 tx_good, tx_under; |
| 2215 | u32 rx_good, rx_over; |
| 2216 | u32 def_tx, crc, code; |
| 2217 | u32 multi_col, single_col; |
| 2218 | u32 excess_col, late_col, loss; |
| 2219 | |
Sakari Ailus | c659c38 | 2011-01-21 10:59:30 +0000 | [diff] [blame] | 2220 | outw(TLAN_GOOD_TX_FRMS, dev->base_addr + TLAN_DIO_ADR); |
| 2221 | tx_good = inb(dev->base_addr + TLAN_DIO_DATA); |
| 2222 | tx_good += inb(dev->base_addr + TLAN_DIO_DATA + 1) << 8; |
| 2223 | tx_good += inb(dev->base_addr + TLAN_DIO_DATA + 2) << 16; |
| 2224 | tx_under = inb(dev->base_addr + TLAN_DIO_DATA + 3); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2225 | |
Sakari Ailus | c659c38 | 2011-01-21 10:59:30 +0000 | [diff] [blame] | 2226 | outw(TLAN_GOOD_RX_FRMS, dev->base_addr + TLAN_DIO_ADR); |
| 2227 | rx_good = inb(dev->base_addr + TLAN_DIO_DATA); |
| 2228 | rx_good += inb(dev->base_addr + TLAN_DIO_DATA + 1) << 8; |
| 2229 | rx_good += inb(dev->base_addr + TLAN_DIO_DATA + 2) << 16; |
| 2230 | rx_over = inb(dev->base_addr + TLAN_DIO_DATA + 3); |
Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 2231 | |
Sakari Ailus | c659c38 | 2011-01-21 10:59:30 +0000 | [diff] [blame] | 2232 | outw(TLAN_DEFERRED_TX, dev->base_addr + TLAN_DIO_ADR); |
| 2233 | def_tx = inb(dev->base_addr + TLAN_DIO_DATA); |
| 2234 | def_tx += inb(dev->base_addr + TLAN_DIO_DATA + 1) << 8; |
| 2235 | crc = inb(dev->base_addr + TLAN_DIO_DATA + 2); |
| 2236 | code = inb(dev->base_addr + TLAN_DIO_DATA + 3); |
Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 2237 | |
Sakari Ailus | c659c38 | 2011-01-21 10:59:30 +0000 | [diff] [blame] | 2238 | outw(TLAN_MULTICOL_FRMS, dev->base_addr + TLAN_DIO_ADR); |
| 2239 | multi_col = inb(dev->base_addr + TLAN_DIO_DATA); |
| 2240 | multi_col += inb(dev->base_addr + TLAN_DIO_DATA + 1) << 8; |
| 2241 | single_col = inb(dev->base_addr + TLAN_DIO_DATA + 2); |
| 2242 | single_col += inb(dev->base_addr + TLAN_DIO_DATA + 3) << 8; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2243 | |
Sakari Ailus | c659c38 | 2011-01-21 10:59:30 +0000 | [diff] [blame] | 2244 | outw(TLAN_EXCESSCOL_FRMS, dev->base_addr + TLAN_DIO_ADR); |
| 2245 | excess_col = inb(dev->base_addr + TLAN_DIO_DATA); |
| 2246 | late_col = inb(dev->base_addr + TLAN_DIO_DATA + 1); |
| 2247 | loss = inb(dev->base_addr + TLAN_DIO_DATA + 2); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2248 | |
Sakari Ailus | c659c38 | 2011-01-21 10:59:30 +0000 | [diff] [blame] | 2249 | if (record) { |
Stephen Hemminger | f8f3154 | 2008-05-30 09:49:53 -0700 | [diff] [blame] | 2250 | dev->stats.rx_packets += rx_good; |
| 2251 | dev->stats.rx_errors += rx_over + crc + code; |
| 2252 | dev->stats.tx_packets += tx_good; |
| 2253 | dev->stats.tx_errors += tx_under + loss; |
Sakari Ailus | c659c38 | 2011-01-21 10:59:30 +0000 | [diff] [blame] | 2254 | dev->stats.collisions += multi_col |
| 2255 | + single_col + excess_col + late_col; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2256 | |
Stephen Hemminger | f8f3154 | 2008-05-30 09:49:53 -0700 | [diff] [blame] | 2257 | dev->stats.rx_over_errors += rx_over; |
| 2258 | dev->stats.rx_crc_errors += crc; |
| 2259 | dev->stats.rx_frame_errors += code; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2260 | |
Stephen Hemminger | f8f3154 | 2008-05-30 09:49:53 -0700 | [diff] [blame] | 2261 | dev->stats.tx_aborted_errors += tx_under; |
| 2262 | dev->stats.tx_carrier_errors += loss; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2263 | } |
Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 2264 | |
Sakari Ailus | c659c38 | 2011-01-21 10:59:30 +0000 | [diff] [blame] | 2265 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2266 | |
| 2267 | |
| 2268 | |
| 2269 | |
Sakari Ailus | c659c38 | 2011-01-21 10:59:30 +0000 | [diff] [blame] | 2270 | /*************************************************************** |
| 2271 | * TLan_Reset |
| 2272 | * |
| 2273 | * Returns: |
| 2274 | * 0 |
| 2275 | * Parms: |
| 2276 | * dev Pointer to device structure of adapter |
| 2277 | * to be reset. |
| 2278 | * |
| 2279 | * This function resets the adapter and it's physical |
| 2280 | * device. See Chap. 3, pp. 9-10 of the "ThunderLAN |
| 2281 | * Programmer's Guide" for details. The routine tries to |
| 2282 | * implement what is detailed there, though adjustments |
| 2283 | * have been made. |
| 2284 | * |
| 2285 | **************************************************************/ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2286 | |
Harvey Harrison | 98e0f52 | 2008-02-18 10:04:38 -0800 | [diff] [blame] | 2287 | static void |
Sakari Ailus | c659c38 | 2011-01-21 10:59:30 +0000 | [diff] [blame] | 2288 | tlan_reset_adapter(struct net_device *dev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2289 | { |
Sakari Ailus | c659c38 | 2011-01-21 10:59:30 +0000 | [diff] [blame] | 2290 | struct tlan_priv *priv = netdev_priv(dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2291 | int i; |
| 2292 | u32 addr; |
| 2293 | u32 data; |
| 2294 | u8 data8; |
| 2295 | |
Sakari Ailus | c659c38 | 2011-01-21 10:59:30 +0000 | [diff] [blame] | 2296 | priv->tlan_full_duplex = false; |
| 2297 | priv->phy_online = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2298 | netif_carrier_off(dev); |
| 2299 | |
| 2300 | /* 1. Assert reset bit. */ |
| 2301 | |
| 2302 | data = inl(dev->base_addr + TLAN_HOST_CMD); |
| 2303 | data |= TLAN_HC_AD_RST; |
| 2304 | outl(data, dev->base_addr + TLAN_HOST_CMD); |
Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 2305 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2306 | udelay(1000); |
| 2307 | |
Sakari Ailus | c659c38 | 2011-01-21 10:59:30 +0000 | [diff] [blame] | 2308 | /* 2. Turn off interrupts. (Probably isn't necessary) */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2309 | |
| 2310 | data = inl(dev->base_addr + TLAN_HOST_CMD); |
| 2311 | data |= TLAN_HC_INT_OFF; |
| 2312 | outl(data, dev->base_addr + TLAN_HOST_CMD); |
| 2313 | |
| 2314 | /* 3. Clear AREGs and HASHs. */ |
| 2315 | |
Sakari Ailus | c659c38 | 2011-01-21 10:59:30 +0000 | [diff] [blame] | 2316 | for (i = TLAN_AREG_0; i <= TLAN_HASH_2; i += 4) |
| 2317 | tlan_dio_write32(dev->base_addr, (u16) i, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2318 | |
| 2319 | /* 4. Setup NetConfig register. */ |
| 2320 | |
| 2321 | data = TLAN_NET_CFG_1FRAG | TLAN_NET_CFG_1CHAN | TLAN_NET_CFG_PHY_EN; |
Sakari Ailus | c659c38 | 2011-01-21 10:59:30 +0000 | [diff] [blame] | 2322 | tlan_dio_write16(dev->base_addr, TLAN_NET_CONFIG, (u16) data); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2323 | |
| 2324 | /* 5. Load Ld_Tmr and Ld_Thr in HOST_CMD. */ |
| 2325 | |
Sakari Ailus | c659c38 | 2011-01-21 10:59:30 +0000 | [diff] [blame] | 2326 | outl(TLAN_HC_LD_TMR | 0x3f, dev->base_addr + TLAN_HOST_CMD); |
| 2327 | outl(TLAN_HC_LD_THR | 0x9, dev->base_addr + TLAN_HOST_CMD); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2328 | |
| 2329 | /* 6. Unreset the MII by setting NMRST (in NetSio) to 1. */ |
| 2330 | |
Sakari Ailus | c659c38 | 2011-01-21 10:59:30 +0000 | [diff] [blame] | 2331 | outw(TLAN_NET_SIO, dev->base_addr + TLAN_DIO_ADR); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2332 | addr = dev->base_addr + TLAN_DIO_DATA + TLAN_NET_SIO; |
Sakari Ailus | c659c38 | 2011-01-21 10:59:30 +0000 | [diff] [blame] | 2333 | tlan_set_bit(TLAN_NET_SIO_NMRST, addr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2334 | |
| 2335 | /* 7. Setup the remaining registers. */ |
| 2336 | |
Sakari Ailus | c659c38 | 2011-01-21 10:59:30 +0000 | [diff] [blame] | 2337 | if (priv->tlan_rev >= 0x30) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2338 | data8 = TLAN_ID_TX_EOC | TLAN_ID_RX_EOC; |
Sakari Ailus | c659c38 | 2011-01-21 10:59:30 +0000 | [diff] [blame] | 2339 | tlan_dio_write8(dev->base_addr, TLAN_INT_DIS, data8); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2340 | } |
Sakari Ailus | c659c38 | 2011-01-21 10:59:30 +0000 | [diff] [blame] | 2341 | tlan_phy_detect(dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2342 | data = TLAN_NET_CFG_1FRAG | TLAN_NET_CFG_1CHAN; |
Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 2343 | |
Sakari Ailus | c659c38 | 2011-01-21 10:59:30 +0000 | [diff] [blame] | 2344 | if (priv->adapter->flags & TLAN_ADAPTER_BIT_RATE_PHY) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2345 | data |= TLAN_NET_CFG_BIT; |
Sakari Ailus | c659c38 | 2011-01-21 10:59:30 +0000 | [diff] [blame] | 2346 | if (priv->aui == 1) { |
| 2347 | tlan_dio_write8(dev->base_addr, TLAN_ACOMMIT, 0x0a); |
| 2348 | } else if (priv->duplex == TLAN_DUPLEX_FULL) { |
| 2349 | tlan_dio_write8(dev->base_addr, TLAN_ACOMMIT, 0x00); |
| 2350 | priv->tlan_full_duplex = true; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2351 | } else { |
Sakari Ailus | c659c38 | 2011-01-21 10:59:30 +0000 | [diff] [blame] | 2352 | tlan_dio_write8(dev->base_addr, TLAN_ACOMMIT, 0x08); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2353 | } |
| 2354 | } |
| 2355 | |
Sakari Ailus | c659c38 | 2011-01-21 10:59:30 +0000 | [diff] [blame] | 2356 | if (priv->phy_num == 0) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2357 | data |= TLAN_NET_CFG_PHY_EN; |
Sakari Ailus | c659c38 | 2011-01-21 10:59:30 +0000 | [diff] [blame] | 2358 | tlan_dio_write16(dev->base_addr, TLAN_NET_CONFIG, (u16) data); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2359 | |
Sakari Ailus | c659c38 | 2011-01-21 10:59:30 +0000 | [diff] [blame] | 2360 | if (priv->adapter->flags & TLAN_ADAPTER_UNMANAGED_PHY) |
| 2361 | tlan_finish_reset(dev); |
| 2362 | else |
| 2363 | tlan_phy_power_down(dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2364 | |
Sakari Ailus | c659c38 | 2011-01-21 10:59:30 +0000 | [diff] [blame] | 2365 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2366 | |
| 2367 | |
| 2368 | |
| 2369 | |
Harvey Harrison | 98e0f52 | 2008-02-18 10:04:38 -0800 | [diff] [blame] | 2370 | static void |
Sakari Ailus | c659c38 | 2011-01-21 10:59:30 +0000 | [diff] [blame] | 2371 | tlan_finish_reset(struct net_device *dev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2372 | { |
Sakari Ailus | c659c38 | 2011-01-21 10:59:30 +0000 | [diff] [blame] | 2373 | struct tlan_priv *priv = netdev_priv(dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2374 | u8 data; |
| 2375 | u32 phy; |
| 2376 | u8 sio; |
| 2377 | u16 status; |
| 2378 | u16 partner; |
| 2379 | u16 tlphy_ctl; |
Sakari Ailus | c659c38 | 2011-01-21 10:59:30 +0000 | [diff] [blame] | 2380 | u16 tlphy_par; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2381 | u16 tlphy_id1, tlphy_id2; |
Sakari Ailus | c659c38 | 2011-01-21 10:59:30 +0000 | [diff] [blame] | 2382 | int i; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2383 | |
Sakari Ailus | c659c38 | 2011-01-21 10:59:30 +0000 | [diff] [blame] | 2384 | phy = priv->phy[priv->phy_num]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2385 | |
| 2386 | data = TLAN_NET_CMD_NRESET | TLAN_NET_CMD_NWRAP; |
Sakari Ailus | c659c38 | 2011-01-21 10:59:30 +0000 | [diff] [blame] | 2387 | if (priv->tlan_full_duplex) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2388 | data |= TLAN_NET_CMD_DUPLEX; |
Sakari Ailus | c659c38 | 2011-01-21 10:59:30 +0000 | [diff] [blame] | 2389 | tlan_dio_write8(dev->base_addr, TLAN_NET_CMD, data); |
Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 2390 | data = TLAN_NET_MASK_MASK4 | TLAN_NET_MASK_MASK5; |
Sakari Ailus | c659c38 | 2011-01-21 10:59:30 +0000 | [diff] [blame] | 2391 | if (priv->phy_num == 0) |
Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 2392 | data |= TLAN_NET_MASK_MASK7; |
Sakari Ailus | c659c38 | 2011-01-21 10:59:30 +0000 | [diff] [blame] | 2393 | tlan_dio_write8(dev->base_addr, TLAN_NET_MASK, data); |
| 2394 | tlan_dio_write16(dev->base_addr, TLAN_MAX_RX, ((1536)+7)&~7); |
| 2395 | tlan_mii_read_reg(dev, phy, MII_GEN_ID_HI, &tlphy_id1); |
| 2396 | tlan_mii_read_reg(dev, phy, MII_GEN_ID_LO, &tlphy_id2); |
Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 2397 | |
Sakari Ailus | c659c38 | 2011-01-21 10:59:30 +0000 | [diff] [blame] | 2398 | if ((priv->adapter->flags & TLAN_ADAPTER_UNMANAGED_PHY) || |
| 2399 | (priv->aui)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2400 | status = MII_GS_LINK; |
Sakari Ailus | c659c38 | 2011-01-21 10:59:30 +0000 | [diff] [blame] | 2401 | pr_info("TLAN: %s: Link forced.\n", dev->name); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2402 | } else { |
Sakari Ailus | c659c38 | 2011-01-21 10:59:30 +0000 | [diff] [blame] | 2403 | tlan_mii_read_reg(dev, phy, MII_GEN_STS, &status); |
| 2404 | udelay(1000); |
| 2405 | tlan_mii_read_reg(dev, phy, MII_GEN_STS, &status); |
| 2406 | if ((status & MII_GS_LINK) && |
| 2407 | /* We only support link info on Nat.Sem. PHY's */ |
| 2408 | (tlphy_id1 == NAT_SEM_ID1) && |
| 2409 | (tlphy_id2 == NAT_SEM_ID2)) { |
| 2410 | tlan_mii_read_reg(dev, phy, MII_AN_LPA, &partner); |
| 2411 | tlan_mii_read_reg(dev, phy, TLAN_TLPHY_PAR, &tlphy_par); |
Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 2412 | |
Sakari Ailus | c659c38 | 2011-01-21 10:59:30 +0000 | [diff] [blame] | 2413 | pr_info("TLAN: %s: Link active with ", dev->name); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2414 | if (!(tlphy_par & TLAN_PHY_AN_EN_STAT)) { |
Sakari Ailus | c659c38 | 2011-01-21 10:59:30 +0000 | [diff] [blame] | 2415 | pr_info("forced 10%sMbps %s-Duplex\n", |
| 2416 | tlphy_par & TLAN_PHY_SPEED_100 |
| 2417 | ? "" : "0", |
| 2418 | tlphy_par & TLAN_PHY_DUPLEX_FULL |
| 2419 | ? "Full" : "Half"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2420 | } else { |
Sakari Ailus | c659c38 | 2011-01-21 10:59:30 +0000 | [diff] [blame] | 2421 | pr_info("Autonegotiation enabled, at 10%sMbps %s-Duplex\n", |
| 2422 | tlphy_par & TLAN_PHY_SPEED_100 |
| 2423 | ? "" : "0", |
| 2424 | tlphy_par & TLAN_PHY_DUPLEX_FULL |
| 2425 | ? "Full" : "half"); |
| 2426 | pr_info("TLAN: Partner capability: "); |
| 2427 | for (i = 5; i <= 10; i++) |
| 2428 | if (partner & (1<<i)) |
| 2429 | printk("%s", media[i-5]); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2430 | printk("\n"); |
| 2431 | } |
| 2432 | |
Sakari Ailus | c659c38 | 2011-01-21 10:59:30 +0000 | [diff] [blame] | 2433 | tlan_dio_write8(dev->base_addr, TLAN_LED_REG, |
| 2434 | TLAN_LED_LINK); |
Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 2435 | #ifdef MONITOR |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2436 | /* We have link beat..for now anyway */ |
Sakari Ailus | c659c38 | 2011-01-21 10:59:30 +0000 | [diff] [blame] | 2437 | priv->link = 1; |
| 2438 | /*Enabling link beat monitoring */ |
| 2439 | tlan_set_timer(dev, (10*HZ), TLAN_TIMER_LINK_BEAT); |
Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 2440 | #endif |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2441 | } else if (status & MII_GS_LINK) { |
Sakari Ailus | c659c38 | 2011-01-21 10:59:30 +0000 | [diff] [blame] | 2442 | pr_info("TLAN: %s: Link active\n", dev->name); |
| 2443 | tlan_dio_write8(dev->base_addr, TLAN_LED_REG, |
| 2444 | TLAN_LED_LINK); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2445 | } |
| 2446 | } |
| 2447 | |
Sakari Ailus | c659c38 | 2011-01-21 10:59:30 +0000 | [diff] [blame] | 2448 | if (priv->phy_num == 0) { |
| 2449 | tlan_mii_read_reg(dev, phy, TLAN_TLPHY_CTL, &tlphy_ctl); |
| 2450 | tlphy_ctl |= TLAN_TC_INTEN; |
| 2451 | tlan_mii_write_reg(dev, phy, TLAN_TLPHY_CTL, tlphy_ctl); |
| 2452 | sio = tlan_dio_read8(dev->base_addr, TLAN_NET_SIO); |
| 2453 | sio |= TLAN_NET_SIO_MINTEN; |
| 2454 | tlan_dio_write8(dev->base_addr, TLAN_NET_SIO, sio); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2455 | } |
| 2456 | |
Sakari Ailus | c659c38 | 2011-01-21 10:59:30 +0000 | [diff] [blame] | 2457 | if (status & MII_GS_LINK) { |
| 2458 | tlan_set_mac(dev, 0, dev->dev_addr); |
| 2459 | priv->phy_online = 1; |
| 2460 | outb((TLAN_HC_INT_ON >> 8), dev->base_addr + TLAN_HOST_CMD + 1); |
| 2461 | if (debug >= 1 && debug != TLAN_DEBUG_PROBE) |
| 2462 | outb((TLAN_HC_REQ_INT >> 8), |
| 2463 | dev->base_addr + TLAN_HOST_CMD + 1); |
| 2464 | outl(priv->rx_list_dma, dev->base_addr + TLAN_CH_PARM); |
| 2465 | outl(TLAN_HC_GO | TLAN_HC_RT, dev->base_addr + TLAN_HOST_CMD); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2466 | netif_carrier_on(dev); |
| 2467 | } else { |
Sakari Ailus | c659c38 | 2011-01-21 10:59:30 +0000 | [diff] [blame] | 2468 | pr_info("TLAN: %s: Link inactive, will retry in 10 secs...\n", |
| 2469 | dev->name); |
| 2470 | tlan_set_timer(dev, (10*HZ), TLAN_TIMER_FINISH_RESET); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2471 | return; |
| 2472 | } |
Sakari Ailus | c659c38 | 2011-01-21 10:59:30 +0000 | [diff] [blame] | 2473 | tlan_set_multicast_list(dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2474 | |
Sakari Ailus | c659c38 | 2011-01-21 10:59:30 +0000 | [diff] [blame] | 2475 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2476 | |
| 2477 | |
| 2478 | |
| 2479 | |
Sakari Ailus | c659c38 | 2011-01-21 10:59:30 +0000 | [diff] [blame] | 2480 | /*************************************************************** |
| 2481 | * tlan_set_mac |
| 2482 | * |
| 2483 | * Returns: |
| 2484 | * Nothing |
| 2485 | * Parms: |
| 2486 | * dev Pointer to device structure of adapter |
| 2487 | * on which to change the AREG. |
| 2488 | * areg The AREG to set the address in (0 - 3). |
| 2489 | * mac A pointer to an array of chars. Each |
| 2490 | * element stores one byte of the address. |
| 2491 | * IE, it isn't in ascii. |
| 2492 | * |
| 2493 | * This function transfers a MAC address to one of the |
| 2494 | * TLAN AREGs (address registers). The TLAN chip locks |
| 2495 | * the register on writing to offset 0 and unlocks the |
| 2496 | * register after writing to offset 5. If NULL is passed |
| 2497 | * in mac, then the AREG is filled with 0's. |
| 2498 | * |
| 2499 | **************************************************************/ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2500 | |
Sakari Ailus | c659c38 | 2011-01-21 10:59:30 +0000 | [diff] [blame] | 2501 | static void tlan_set_mac(struct net_device *dev, int areg, char *mac) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2502 | { |
| 2503 | int i; |
Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 2504 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2505 | areg *= 6; |
| 2506 | |
Sakari Ailus | c659c38 | 2011-01-21 10:59:30 +0000 | [diff] [blame] | 2507 | if (mac != NULL) { |
| 2508 | for (i = 0; i < 6; i++) |
| 2509 | tlan_dio_write8(dev->base_addr, |
| 2510 | TLAN_AREG_0 + areg + i, mac[i]); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2511 | } else { |
Sakari Ailus | c659c38 | 2011-01-21 10:59:30 +0000 | [diff] [blame] | 2512 | for (i = 0; i < 6; i++) |
| 2513 | tlan_dio_write8(dev->base_addr, |
| 2514 | TLAN_AREG_0 + areg + i, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2515 | } |
| 2516 | |
Sakari Ailus | c659c38 | 2011-01-21 10:59:30 +0000 | [diff] [blame] | 2517 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2518 | |
| 2519 | |
| 2520 | |
| 2521 | |
| 2522 | /***************************************************************************** |
| 2523 | ****************************************************************************** |
| 2524 | |
Sakari Ailus | c659c38 | 2011-01-21 10:59:30 +0000 | [diff] [blame] | 2525 | ThunderLAN driver PHY layer routines |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2526 | |
| 2527 | ****************************************************************************** |
| 2528 | *****************************************************************************/ |
| 2529 | |
| 2530 | |
| 2531 | |
Sakari Ailus | c659c38 | 2011-01-21 10:59:30 +0000 | [diff] [blame] | 2532 | /********************************************************************* |
| 2533 | * tlan_phy_print |
| 2534 | * |
| 2535 | * Returns: |
| 2536 | * Nothing |
| 2537 | * Parms: |
| 2538 | * dev A pointer to the device structure of the |
| 2539 | * TLAN device having the PHYs to be detailed. |
| 2540 | * |
| 2541 | * This function prints the registers a PHY (aka transceiver). |
| 2542 | * |
| 2543 | ********************************************************************/ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2544 | |
Sakari Ailus | c659c38 | 2011-01-21 10:59:30 +0000 | [diff] [blame] | 2545 | static void tlan_phy_print(struct net_device *dev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2546 | { |
Sakari Ailus | c659c38 | 2011-01-21 10:59:30 +0000 | [diff] [blame] | 2547 | struct tlan_priv *priv = netdev_priv(dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2548 | u16 i, data0, data1, data2, data3, phy; |
| 2549 | |
Sakari Ailus | c659c38 | 2011-01-21 10:59:30 +0000 | [diff] [blame] | 2550 | phy = priv->phy[priv->phy_num]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2551 | |
Sakari Ailus | c659c38 | 2011-01-21 10:59:30 +0000 | [diff] [blame] | 2552 | if (priv->adapter->flags & TLAN_ADAPTER_UNMANAGED_PHY) { |
| 2553 | pr_info("TLAN: Device %s, Unmanaged PHY.\n", dev->name); |
| 2554 | } else if (phy <= TLAN_PHY_MAX_ADDR) { |
| 2555 | pr_info("TLAN: Device %s, PHY 0x%02x.\n", dev->name, phy); |
| 2556 | pr_info("TLAN: Off. +0 +1 +2 +3\n"); |
| 2557 | for (i = 0; i < 0x20; i += 4) { |
| 2558 | pr_info("TLAN: 0x%02x", i); |
| 2559 | tlan_mii_read_reg(dev, phy, i, &data0); |
| 2560 | printk(" 0x%04hx", data0); |
| 2561 | tlan_mii_read_reg(dev, phy, i + 1, &data1); |
| 2562 | printk(" 0x%04hx", data1); |
| 2563 | tlan_mii_read_reg(dev, phy, i + 2, &data2); |
| 2564 | printk(" 0x%04hx", data2); |
| 2565 | tlan_mii_read_reg(dev, phy, i + 3, &data3); |
| 2566 | printk(" 0x%04hx\n", data3); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2567 | } |
| 2568 | } else { |
Sakari Ailus | c659c38 | 2011-01-21 10:59:30 +0000 | [diff] [blame] | 2569 | pr_info("TLAN: Device %s, Invalid PHY.\n", dev->name); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2570 | } |
| 2571 | |
Sakari Ailus | c659c38 | 2011-01-21 10:59:30 +0000 | [diff] [blame] | 2572 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2573 | |
| 2574 | |
| 2575 | |
| 2576 | |
Sakari Ailus | c659c38 | 2011-01-21 10:59:30 +0000 | [diff] [blame] | 2577 | /********************************************************************* |
| 2578 | * tlan_phy_detect |
| 2579 | * |
| 2580 | * Returns: |
| 2581 | * Nothing |
| 2582 | * Parms: |
| 2583 | * dev A pointer to the device structure of the adapter |
| 2584 | * for which the PHY needs determined. |
| 2585 | * |
| 2586 | * So far I've found that adapters which have external PHYs |
| 2587 | * may also use the internal PHY for part of the functionality. |
| 2588 | * (eg, AUI/Thinnet). This function finds out if this TLAN |
| 2589 | * chip has an internal PHY, and then finds the first external |
| 2590 | * PHY (starting from address 0) if it exists). |
| 2591 | * |
| 2592 | ********************************************************************/ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2593 | |
Sakari Ailus | c659c38 | 2011-01-21 10:59:30 +0000 | [diff] [blame] | 2594 | static void tlan_phy_detect(struct net_device *dev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2595 | { |
Sakari Ailus | c659c38 | 2011-01-21 10:59:30 +0000 | [diff] [blame] | 2596 | struct tlan_priv *priv = netdev_priv(dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2597 | u16 control; |
| 2598 | u16 hi; |
| 2599 | u16 lo; |
| 2600 | u32 phy; |
| 2601 | |
Sakari Ailus | c659c38 | 2011-01-21 10:59:30 +0000 | [diff] [blame] | 2602 | if (priv->adapter->flags & TLAN_ADAPTER_UNMANAGED_PHY) { |
| 2603 | priv->phy_num = 0xffff; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2604 | return; |
| 2605 | } |
| 2606 | |
Sakari Ailus | c659c38 | 2011-01-21 10:59:30 +0000 | [diff] [blame] | 2607 | tlan_mii_read_reg(dev, TLAN_PHY_MAX_ADDR, MII_GEN_ID_HI, &hi); |
Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 2608 | |
Sakari Ailus | c659c38 | 2011-01-21 10:59:30 +0000 | [diff] [blame] | 2609 | if (hi != 0xffff) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2610 | priv->phy[0] = TLAN_PHY_MAX_ADDR; |
Sakari Ailus | c659c38 | 2011-01-21 10:59:30 +0000 | [diff] [blame] | 2611 | else |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2612 | priv->phy[0] = TLAN_PHY_NONE; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2613 | |
| 2614 | priv->phy[1] = TLAN_PHY_NONE; |
Sakari Ailus | c659c38 | 2011-01-21 10:59:30 +0000 | [diff] [blame] | 2615 | for (phy = 0; phy <= TLAN_PHY_MAX_ADDR; phy++) { |
| 2616 | tlan_mii_read_reg(dev, phy, MII_GEN_CTL, &control); |
| 2617 | tlan_mii_read_reg(dev, phy, MII_GEN_ID_HI, &hi); |
| 2618 | tlan_mii_read_reg(dev, phy, MII_GEN_ID_LO, &lo); |
| 2619 | if ((control != 0xffff) || |
| 2620 | (hi != 0xffff) || (lo != 0xffff)) { |
| 2621 | TLAN_DBG(TLAN_DEBUG_GNRL, |
| 2622 | "PHY found at %02x %04x %04x %04x\n", |
| 2623 | phy, control, hi, lo); |
| 2624 | if ((priv->phy[1] == TLAN_PHY_NONE) && |
| 2625 | (phy != TLAN_PHY_MAX_ADDR)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2626 | priv->phy[1] = phy; |
| 2627 | } |
| 2628 | } |
| 2629 | } |
| 2630 | |
Sakari Ailus | c659c38 | 2011-01-21 10:59:30 +0000 | [diff] [blame] | 2631 | if (priv->phy[1] != TLAN_PHY_NONE) |
| 2632 | priv->phy_num = 1; |
| 2633 | else if (priv->phy[0] != TLAN_PHY_NONE) |
| 2634 | priv->phy_num = 0; |
| 2635 | else |
| 2636 | pr_info("TLAN: Cannot initialize device, no PHY was found!\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2637 | |
Sakari Ailus | c659c38 | 2011-01-21 10:59:30 +0000 | [diff] [blame] | 2638 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2639 | |
| 2640 | |
| 2641 | |
| 2642 | |
Sakari Ailus | c659c38 | 2011-01-21 10:59:30 +0000 | [diff] [blame] | 2643 | static void tlan_phy_power_down(struct net_device *dev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2644 | { |
Sakari Ailus | c659c38 | 2011-01-21 10:59:30 +0000 | [diff] [blame] | 2645 | struct tlan_priv *priv = netdev_priv(dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2646 | u16 value; |
| 2647 | |
Sakari Ailus | c659c38 | 2011-01-21 10:59:30 +0000 | [diff] [blame] | 2648 | TLAN_DBG(TLAN_DEBUG_GNRL, "%s: Powering down PHY(s).\n", dev->name); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2649 | value = MII_GC_PDOWN | MII_GC_LOOPBK | MII_GC_ISOLATE; |
Sakari Ailus | c659c38 | 2011-01-21 10:59:30 +0000 | [diff] [blame] | 2650 | tlan_mii_sync(dev->base_addr); |
| 2651 | tlan_mii_write_reg(dev, priv->phy[priv->phy_num], MII_GEN_CTL, value); |
| 2652 | if ((priv->phy_num == 0) && |
| 2653 | (priv->phy[1] != TLAN_PHY_NONE) && |
| 2654 | (!(priv->adapter->flags & TLAN_ADAPTER_USE_INTERN_10))) { |
| 2655 | tlan_mii_sync(dev->base_addr); |
| 2656 | tlan_mii_write_reg(dev, priv->phy[1], MII_GEN_CTL, value); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2657 | } |
| 2658 | |
| 2659 | /* Wait for 50 ms and powerup |
| 2660 | * This is abitrary. It is intended to make sure the |
| 2661 | * transceiver settles. |
| 2662 | */ |
Sakari Ailus | c659c38 | 2011-01-21 10:59:30 +0000 | [diff] [blame] | 2663 | tlan_set_timer(dev, (HZ/20), TLAN_TIMER_PHY_PUP); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2664 | |
Sakari Ailus | c659c38 | 2011-01-21 10:59:30 +0000 | [diff] [blame] | 2665 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2666 | |
| 2667 | |
| 2668 | |
| 2669 | |
Sakari Ailus | c659c38 | 2011-01-21 10:59:30 +0000 | [diff] [blame] | 2670 | static void tlan_phy_power_up(struct net_device *dev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2671 | { |
Sakari Ailus | c659c38 | 2011-01-21 10:59:30 +0000 | [diff] [blame] | 2672 | struct tlan_priv *priv = netdev_priv(dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2673 | u16 value; |
| 2674 | |
Sakari Ailus | c659c38 | 2011-01-21 10:59:30 +0000 | [diff] [blame] | 2675 | TLAN_DBG(TLAN_DEBUG_GNRL, "%s: Powering up PHY.\n", dev->name); |
| 2676 | tlan_mii_sync(dev->base_addr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2677 | value = MII_GC_LOOPBK; |
Sakari Ailus | c659c38 | 2011-01-21 10:59:30 +0000 | [diff] [blame] | 2678 | tlan_mii_write_reg(dev, priv->phy[priv->phy_num], MII_GEN_CTL, value); |
| 2679 | tlan_mii_sync(dev->base_addr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2680 | /* Wait for 500 ms and reset the |
| 2681 | * transceiver. The TLAN docs say both 50 ms and |
| 2682 | * 500 ms, so do the longer, just in case. |
| 2683 | */ |
Sakari Ailus | c659c38 | 2011-01-21 10:59:30 +0000 | [diff] [blame] | 2684 | tlan_set_timer(dev, (HZ/20), TLAN_TIMER_PHY_RESET); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2685 | |
Sakari Ailus | c659c38 | 2011-01-21 10:59:30 +0000 | [diff] [blame] | 2686 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2687 | |
| 2688 | |
| 2689 | |
| 2690 | |
Sakari Ailus | c659c38 | 2011-01-21 10:59:30 +0000 | [diff] [blame] | 2691 | static void tlan_phy_reset(struct net_device *dev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2692 | { |
Sakari Ailus | c659c38 | 2011-01-21 10:59:30 +0000 | [diff] [blame] | 2693 | struct tlan_priv *priv = netdev_priv(dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2694 | u16 phy; |
| 2695 | u16 value; |
| 2696 | |
Sakari Ailus | c659c38 | 2011-01-21 10:59:30 +0000 | [diff] [blame] | 2697 | phy = priv->phy[priv->phy_num]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2698 | |
Sakari Ailus | c659c38 | 2011-01-21 10:59:30 +0000 | [diff] [blame] | 2699 | TLAN_DBG(TLAN_DEBUG_GNRL, "%s: Reseting PHY.\n", dev->name); |
| 2700 | tlan_mii_sync(dev->base_addr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2701 | value = MII_GC_LOOPBK | MII_GC_RESET; |
Sakari Ailus | c659c38 | 2011-01-21 10:59:30 +0000 | [diff] [blame] | 2702 | tlan_mii_write_reg(dev, phy, MII_GEN_CTL, value); |
| 2703 | tlan_mii_read_reg(dev, phy, MII_GEN_CTL, &value); |
| 2704 | while (value & MII_GC_RESET) |
| 2705 | tlan_mii_read_reg(dev, phy, MII_GEN_CTL, &value); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2706 | |
| 2707 | /* Wait for 500 ms and initialize. |
| 2708 | * I don't remember why I wait this long. |
| 2709 | * I've changed this to 50ms, as it seems long enough. |
| 2710 | */ |
Sakari Ailus | c659c38 | 2011-01-21 10:59:30 +0000 | [diff] [blame] | 2711 | tlan_set_timer(dev, (HZ/20), TLAN_TIMER_PHY_START_LINK); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2712 | |
Sakari Ailus | c659c38 | 2011-01-21 10:59:30 +0000 | [diff] [blame] | 2713 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2714 | |
| 2715 | |
| 2716 | |
| 2717 | |
Sakari Ailus | c659c38 | 2011-01-21 10:59:30 +0000 | [diff] [blame] | 2718 | static void tlan_phy_start_link(struct net_device *dev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2719 | { |
Sakari Ailus | c659c38 | 2011-01-21 10:59:30 +0000 | [diff] [blame] | 2720 | struct tlan_priv *priv = netdev_priv(dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2721 | u16 ability; |
| 2722 | u16 control; |
| 2723 | u16 data; |
| 2724 | u16 phy; |
| 2725 | u16 status; |
| 2726 | u16 tctl; |
| 2727 | |
Sakari Ailus | c659c38 | 2011-01-21 10:59:30 +0000 | [diff] [blame] | 2728 | phy = priv->phy[priv->phy_num]; |
| 2729 | TLAN_DBG(TLAN_DEBUG_GNRL, "%s: Trying to activate link.\n", dev->name); |
| 2730 | tlan_mii_read_reg(dev, phy, MII_GEN_STS, &status); |
| 2731 | tlan_mii_read_reg(dev, phy, MII_GEN_STS, &ability); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2732 | |
Sakari Ailus | c659c38 | 2011-01-21 10:59:30 +0000 | [diff] [blame] | 2733 | if ((status & MII_GS_AUTONEG) && |
| 2734 | (!priv->aui)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2735 | ability = status >> 11; |
Sakari Ailus | c659c38 | 2011-01-21 10:59:30 +0000 | [diff] [blame] | 2736 | if (priv->speed == TLAN_SPEED_10 && |
| 2737 | priv->duplex == TLAN_DUPLEX_HALF) { |
| 2738 | tlan_mii_write_reg(dev, phy, MII_GEN_CTL, 0x0000); |
| 2739 | } else if (priv->speed == TLAN_SPEED_10 && |
| 2740 | priv->duplex == TLAN_DUPLEX_FULL) { |
| 2741 | priv->tlan_full_duplex = true; |
| 2742 | tlan_mii_write_reg(dev, phy, MII_GEN_CTL, 0x0100); |
| 2743 | } else if (priv->speed == TLAN_SPEED_100 && |
| 2744 | priv->duplex == TLAN_DUPLEX_HALF) { |
| 2745 | tlan_mii_write_reg(dev, phy, MII_GEN_CTL, 0x2000); |
| 2746 | } else if (priv->speed == TLAN_SPEED_100 && |
| 2747 | priv->duplex == TLAN_DUPLEX_FULL) { |
| 2748 | priv->tlan_full_duplex = true; |
| 2749 | tlan_mii_write_reg(dev, phy, MII_GEN_CTL, 0x2100); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2750 | } else { |
Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 2751 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2752 | /* Set Auto-Neg advertisement */ |
Sakari Ailus | c659c38 | 2011-01-21 10:59:30 +0000 | [diff] [blame] | 2753 | tlan_mii_write_reg(dev, phy, MII_AN_ADV, |
| 2754 | (ability << 5) | 1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2755 | /* Enablee Auto-Neg */ |
Sakari Ailus | c659c38 | 2011-01-21 10:59:30 +0000 | [diff] [blame] | 2756 | tlan_mii_write_reg(dev, phy, MII_GEN_CTL, 0x1000); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2757 | /* Restart Auto-Neg */ |
Sakari Ailus | c659c38 | 2011-01-21 10:59:30 +0000 | [diff] [blame] | 2758 | tlan_mii_write_reg(dev, phy, MII_GEN_CTL, 0x1200); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2759 | /* Wait for 4 sec for autonegotiation |
Sakari Ailus | c659c38 | 2011-01-21 10:59:30 +0000 | [diff] [blame] | 2760 | * to complete. The max spec time is less than this |
| 2761 | * but the card need additional time to start AN. |
| 2762 | * .5 sec should be plenty extra. |
| 2763 | */ |
| 2764 | pr_info("TLAN: %s: Starting autonegotiation.\n", |
| 2765 | dev->name); |
| 2766 | tlan_set_timer(dev, (2*HZ), TLAN_TIMER_PHY_FINISH_AN); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2767 | return; |
| 2768 | } |
Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 2769 | |
| 2770 | } |
| 2771 | |
Sakari Ailus | c659c38 | 2011-01-21 10:59:30 +0000 | [diff] [blame] | 2772 | if ((priv->aui) && (priv->phy_num != 0)) { |
| 2773 | priv->phy_num = 0; |
| 2774 | data = TLAN_NET_CFG_1FRAG | TLAN_NET_CFG_1CHAN |
| 2775 | | TLAN_NET_CFG_PHY_EN; |
| 2776 | tlan_dio_write16(dev->base_addr, TLAN_NET_CONFIG, data); |
| 2777 | tlan_set_timer(dev, (40*HZ/1000), TLAN_TIMER_PHY_PDOWN); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2778 | return; |
Sakari Ailus | c659c38 | 2011-01-21 10:59:30 +0000 | [diff] [blame] | 2779 | } else if (priv->phy_num == 0) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2780 | control = 0; |
Sakari Ailus | c659c38 | 2011-01-21 10:59:30 +0000 | [diff] [blame] | 2781 | tlan_mii_read_reg(dev, phy, TLAN_TLPHY_CTL, &tctl); |
| 2782 | if (priv->aui) { |
| 2783 | tctl |= TLAN_TC_AUISEL; |
Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 2784 | } else { |
Sakari Ailus | c659c38 | 2011-01-21 10:59:30 +0000 | [diff] [blame] | 2785 | tctl &= ~TLAN_TC_AUISEL; |
| 2786 | if (priv->duplex == TLAN_DUPLEX_FULL) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2787 | control |= MII_GC_DUPLEX; |
Sakari Ailus | c659c38 | 2011-01-21 10:59:30 +0000 | [diff] [blame] | 2788 | priv->tlan_full_duplex = true; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2789 | } |
Sakari Ailus | c659c38 | 2011-01-21 10:59:30 +0000 | [diff] [blame] | 2790 | if (priv->speed == TLAN_SPEED_100) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2791 | control |= MII_GC_SPEEDSEL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2792 | } |
Sakari Ailus | c659c38 | 2011-01-21 10:59:30 +0000 | [diff] [blame] | 2793 | tlan_mii_write_reg(dev, phy, MII_GEN_CTL, control); |
| 2794 | tlan_mii_write_reg(dev, phy, TLAN_TLPHY_CTL, tctl); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2795 | } |
| 2796 | |
| 2797 | /* Wait for 2 sec to give the transceiver time |
| 2798 | * to establish link. |
| 2799 | */ |
Sakari Ailus | c659c38 | 2011-01-21 10:59:30 +0000 | [diff] [blame] | 2800 | tlan_set_timer(dev, (4*HZ), TLAN_TIMER_FINISH_RESET); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2801 | |
Sakari Ailus | c659c38 | 2011-01-21 10:59:30 +0000 | [diff] [blame] | 2802 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2803 | |
| 2804 | |
| 2805 | |
| 2806 | |
Sakari Ailus | c659c38 | 2011-01-21 10:59:30 +0000 | [diff] [blame] | 2807 | static void tlan_phy_finish_auto_neg(struct net_device *dev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2808 | { |
Sakari Ailus | c659c38 | 2011-01-21 10:59:30 +0000 | [diff] [blame] | 2809 | struct tlan_priv *priv = netdev_priv(dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2810 | u16 an_adv; |
| 2811 | u16 an_lpa; |
| 2812 | u16 data; |
| 2813 | u16 mode; |
| 2814 | u16 phy; |
| 2815 | u16 status; |
Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 2816 | |
Sakari Ailus | c659c38 | 2011-01-21 10:59:30 +0000 | [diff] [blame] | 2817 | phy = priv->phy[priv->phy_num]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2818 | |
Sakari Ailus | c659c38 | 2011-01-21 10:59:30 +0000 | [diff] [blame] | 2819 | tlan_mii_read_reg(dev, phy, MII_GEN_STS, &status); |
| 2820 | udelay(1000); |
| 2821 | tlan_mii_read_reg(dev, phy, MII_GEN_STS, &status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2822 | |
Sakari Ailus | c659c38 | 2011-01-21 10:59:30 +0000 | [diff] [blame] | 2823 | if (!(status & MII_GS_AUTOCMPLT)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2824 | /* Wait for 8 sec to give the process |
| 2825 | * more time. Perhaps we should fail after a while. |
| 2826 | */ |
Sakari Ailus | c659c38 | 2011-01-21 10:59:30 +0000 | [diff] [blame] | 2827 | if (!priv->neg_be_verbose++) { |
| 2828 | pr_info("TLAN: Giving autonegotiation more time.\n"); |
| 2829 | pr_info("TLAN: Please check that your adapter has\n"); |
| 2830 | pr_info("TLAN: been properly connected to a HUB or Switch.\n"); |
| 2831 | pr_info("TLAN: Trying to establish link in the background...\n"); |
| 2832 | } |
| 2833 | tlan_set_timer(dev, (8*HZ), TLAN_TIMER_PHY_FINISH_AN); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2834 | return; |
| 2835 | } |
| 2836 | |
Sakari Ailus | c659c38 | 2011-01-21 10:59:30 +0000 | [diff] [blame] | 2837 | pr_info("TLAN: %s: Autonegotiation complete.\n", dev->name); |
| 2838 | tlan_mii_read_reg(dev, phy, MII_AN_ADV, &an_adv); |
| 2839 | tlan_mii_read_reg(dev, phy, MII_AN_LPA, &an_lpa); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2840 | mode = an_adv & an_lpa & 0x03E0; |
Sakari Ailus | c659c38 | 2011-01-21 10:59:30 +0000 | [diff] [blame] | 2841 | if (mode & 0x0100) |
| 2842 | priv->tlan_full_duplex = true; |
| 2843 | else if (!(mode & 0x0080) && (mode & 0x0040)) |
| 2844 | priv->tlan_full_duplex = true; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2845 | |
Sakari Ailus | c659c38 | 2011-01-21 10:59:30 +0000 | [diff] [blame] | 2846 | if ((!(mode & 0x0180)) && |
| 2847 | (priv->adapter->flags & TLAN_ADAPTER_USE_INTERN_10) && |
| 2848 | (priv->phy_num != 0)) { |
| 2849 | priv->phy_num = 0; |
| 2850 | data = TLAN_NET_CFG_1FRAG | TLAN_NET_CFG_1CHAN |
| 2851 | | TLAN_NET_CFG_PHY_EN; |
| 2852 | tlan_dio_write16(dev->base_addr, TLAN_NET_CONFIG, data); |
| 2853 | tlan_set_timer(dev, (400*HZ/1000), TLAN_TIMER_PHY_PDOWN); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2854 | return; |
| 2855 | } |
| 2856 | |
Sakari Ailus | c659c38 | 2011-01-21 10:59:30 +0000 | [diff] [blame] | 2857 | if (priv->phy_num == 0) { |
| 2858 | if ((priv->duplex == TLAN_DUPLEX_FULL) || |
| 2859 | (an_adv & an_lpa & 0x0040)) { |
| 2860 | tlan_mii_write_reg(dev, phy, MII_GEN_CTL, |
| 2861 | MII_GC_AUTOENB | MII_GC_DUPLEX); |
| 2862 | pr_info("TLAN: Starting internal PHY with FULL-DUPLEX\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2863 | } else { |
Sakari Ailus | c659c38 | 2011-01-21 10:59:30 +0000 | [diff] [blame] | 2864 | tlan_mii_write_reg(dev, phy, MII_GEN_CTL, |
| 2865 | MII_GC_AUTOENB); |
| 2866 | pr_info("TLAN: Starting internal PHY with HALF-DUPLEX\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2867 | } |
| 2868 | } |
| 2869 | |
| 2870 | /* Wait for 100 ms. No reason in partiticular. |
| 2871 | */ |
Sakari Ailus | c659c38 | 2011-01-21 10:59:30 +0000 | [diff] [blame] | 2872 | tlan_set_timer(dev, (HZ/10), TLAN_TIMER_FINISH_RESET); |
Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 2873 | |
Sakari Ailus | c659c38 | 2011-01-21 10:59:30 +0000 | [diff] [blame] | 2874 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2875 | |
| 2876 | #ifdef MONITOR |
| 2877 | |
Sakari Ailus | c659c38 | 2011-01-21 10:59:30 +0000 | [diff] [blame] | 2878 | /********************************************************************* |
| 2879 | * |
| 2880 | * tlan_phy_monitor |
| 2881 | * |
| 2882 | * Returns: |
| 2883 | * None |
| 2884 | * |
| 2885 | * Params: |
| 2886 | * dev The device structure of this device. |
| 2887 | * |
| 2888 | * |
| 2889 | * This function monitors PHY condition by reading the status |
| 2890 | * register via the MII bus. This can be used to give info |
| 2891 | * about link changes (up/down), and possible switch to alternate |
| 2892 | * media. |
| 2893 | * |
| 2894 | *******************************************************************/ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2895 | |
Sakari Ailus | c659c38 | 2011-01-21 10:59:30 +0000 | [diff] [blame] | 2896 | void tlan_phy_monitor(struct net_device *dev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2897 | { |
Sakari Ailus | c659c38 | 2011-01-21 10:59:30 +0000 | [diff] [blame] | 2898 | struct tlan_priv *priv = netdev_priv(dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2899 | u16 phy; |
| 2900 | u16 phy_status; |
| 2901 | |
Sakari Ailus | c659c38 | 2011-01-21 10:59:30 +0000 | [diff] [blame] | 2902 | phy = priv->phy[priv->phy_num]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2903 | |
Sakari Ailus | c659c38 | 2011-01-21 10:59:30 +0000 | [diff] [blame] | 2904 | /* Get PHY status register */ |
| 2905 | tlan_mii_read_reg(dev, phy, MII_GEN_STS, &phy_status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2906 | |
Sakari Ailus | c659c38 | 2011-01-21 10:59:30 +0000 | [diff] [blame] | 2907 | /* Check if link has been lost */ |
| 2908 | if (!(phy_status & MII_GS_LINK)) { |
| 2909 | if (priv->link) { |
| 2910 | priv->link = 0; |
| 2911 | printk(KERN_DEBUG "TLAN: %s has lost link\n", |
| 2912 | dev->name); |
| 2913 | netif_carrier_off(dev); |
| 2914 | tlan_set_timer(dev, (2*HZ), TLAN_TIMER_LINK_BEAT); |
| 2915 | return; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2916 | } |
| 2917 | } |
| 2918 | |
Sakari Ailus | c659c38 | 2011-01-21 10:59:30 +0000 | [diff] [blame] | 2919 | /* Link restablished? */ |
| 2920 | if ((phy_status & MII_GS_LINK) && !priv->link) { |
| 2921 | priv->link = 1; |
| 2922 | printk(KERN_DEBUG "TLAN: %s has reestablished link\n", |
| 2923 | dev->name); |
| 7d17c1d | 2005-05-12 19:45:25 -0400 | [diff] [blame] | 2924 | netif_carrier_on(dev); |
Sakari Ailus | c659c38 | 2011-01-21 10:59:30 +0000 | [diff] [blame] | 2925 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2926 | |
| 2927 | /* Setup a new monitor */ |
Sakari Ailus | c659c38 | 2011-01-21 10:59:30 +0000 | [diff] [blame] | 2928 | tlan_set_timer(dev, (2*HZ), TLAN_TIMER_LINK_BEAT); |
Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 2929 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2930 | |
| 2931 | #endif /* MONITOR */ |
| 2932 | |
| 2933 | |
| 2934 | /***************************************************************************** |
| 2935 | ****************************************************************************** |
| 2936 | |
Sakari Ailus | c659c38 | 2011-01-21 10:59:30 +0000 | [diff] [blame] | 2937 | ThunderLAN driver MII routines |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2938 | |
Sakari Ailus | c659c38 | 2011-01-21 10:59:30 +0000 | [diff] [blame] | 2939 | these routines are based on the information in chap. 2 of the |
| 2940 | "ThunderLAN Programmer's Guide", pp. 15-24. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2941 | |
| 2942 | ****************************************************************************** |
| 2943 | *****************************************************************************/ |
| 2944 | |
| 2945 | |
Sakari Ailus | c659c38 | 2011-01-21 10:59:30 +0000 | [diff] [blame] | 2946 | /*************************************************************** |
| 2947 | * tlan_mii_read_reg |
| 2948 | * |
| 2949 | * Returns: |
| 2950 | * false if ack received ok |
| 2951 | * true if no ack received or other error |
| 2952 | * |
| 2953 | * Parms: |
| 2954 | * dev The device structure containing |
| 2955 | * The io address and interrupt count |
| 2956 | * for this device. |
| 2957 | * phy The address of the PHY to be queried. |
| 2958 | * reg The register whose contents are to be |
| 2959 | * retrieved. |
| 2960 | * val A pointer to a variable to store the |
| 2961 | * retrieved value. |
| 2962 | * |
| 2963 | * This function uses the TLAN's MII bus to retrieve the contents |
| 2964 | * of a given register on a PHY. It sends the appropriate info |
| 2965 | * and then reads the 16-bit register value from the MII bus via |
| 2966 | * the TLAN SIO register. |
| 2967 | * |
| 2968 | **************************************************************/ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2969 | |
Sakari Ailus | c659c38 | 2011-01-21 10:59:30 +0000 | [diff] [blame] | 2970 | static bool |
| 2971 | tlan_mii_read_reg(struct net_device *dev, u16 phy, u16 reg, u16 *val) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2972 | { |
| 2973 | u8 nack; |
| 2974 | u16 sio, tmp; |
Sakari Ailus | c659c38 | 2011-01-21 10:59:30 +0000 | [diff] [blame] | 2975 | u32 i; |
Joe Perches | 37fce43 | 2010-01-12 20:59:13 +0000 | [diff] [blame] | 2976 | bool err; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2977 | int minten; |
Sakari Ailus | c659c38 | 2011-01-21 10:59:30 +0000 | [diff] [blame] | 2978 | struct tlan_priv *priv = netdev_priv(dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2979 | unsigned long flags = 0; |
| 2980 | |
Joe Perches | 37fce43 | 2010-01-12 20:59:13 +0000 | [diff] [blame] | 2981 | err = false; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2982 | outw(TLAN_NET_SIO, dev->base_addr + TLAN_DIO_ADR); |
| 2983 | sio = dev->base_addr + TLAN_DIO_DATA + TLAN_NET_SIO; |
Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 2984 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2985 | if (!in_irq()) |
| 2986 | spin_lock_irqsave(&priv->lock, flags); |
| 2987 | |
Sakari Ailus | c659c38 | 2011-01-21 10:59:30 +0000 | [diff] [blame] | 2988 | tlan_mii_sync(dev->base_addr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2989 | |
Sakari Ailus | c659c38 | 2011-01-21 10:59:30 +0000 | [diff] [blame] | 2990 | minten = tlan_get_bit(TLAN_NET_SIO_MINTEN, sio); |
| 2991 | if (minten) |
| 2992 | tlan_clear_bit(TLAN_NET_SIO_MINTEN, sio); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2993 | |
Sakari Ailus | c659c38 | 2011-01-21 10:59:30 +0000 | [diff] [blame] | 2994 | tlan_mii_send_data(dev->base_addr, 0x1, 2); /* start (01b) */ |
| 2995 | tlan_mii_send_data(dev->base_addr, 0x2, 2); /* read (10b) */ |
| 2996 | tlan_mii_send_data(dev->base_addr, phy, 5); /* device # */ |
| 2997 | tlan_mii_send_data(dev->base_addr, reg, 5); /* register # */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2998 | |
| 2999 | |
Sakari Ailus | c659c38 | 2011-01-21 10:59:30 +0000 | [diff] [blame] | 3000 | tlan_clear_bit(TLAN_NET_SIO_MTXEN, sio); /* change direction */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3001 | |
Sakari Ailus | c659c38 | 2011-01-21 10:59:30 +0000 | [diff] [blame] | 3002 | tlan_clear_bit(TLAN_NET_SIO_MCLK, sio); /* clock idle bit */ |
| 3003 | tlan_set_bit(TLAN_NET_SIO_MCLK, sio); |
| 3004 | tlan_clear_bit(TLAN_NET_SIO_MCLK, sio); /* wait 300ns */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3005 | |
Sakari Ailus | c659c38 | 2011-01-21 10:59:30 +0000 | [diff] [blame] | 3006 | nack = tlan_get_bit(TLAN_NET_SIO_MDATA, sio); /* check for ACK */ |
| 3007 | tlan_set_bit(TLAN_NET_SIO_MCLK, sio); /* finish ACK */ |
| 3008 | if (nack) { /* no ACK, so fake it */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3009 | for (i = 0; i < 16; i++) { |
Sakari Ailus | c659c38 | 2011-01-21 10:59:30 +0000 | [diff] [blame] | 3010 | tlan_clear_bit(TLAN_NET_SIO_MCLK, sio); |
| 3011 | tlan_set_bit(TLAN_NET_SIO_MCLK, sio); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3012 | } |
| 3013 | tmp = 0xffff; |
Joe Perches | 37fce43 | 2010-01-12 20:59:13 +0000 | [diff] [blame] | 3014 | err = true; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3015 | } else { /* ACK, so read data */ |
| 3016 | for (tmp = 0, i = 0x8000; i; i >>= 1) { |
Sakari Ailus | c659c38 | 2011-01-21 10:59:30 +0000 | [diff] [blame] | 3017 | tlan_clear_bit(TLAN_NET_SIO_MCLK, sio); |
| 3018 | if (tlan_get_bit(TLAN_NET_SIO_MDATA, sio)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3019 | tmp |= i; |
Sakari Ailus | c659c38 | 2011-01-21 10:59:30 +0000 | [diff] [blame] | 3020 | tlan_set_bit(TLAN_NET_SIO_MCLK, sio); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3021 | } |
| 3022 | } |
| 3023 | |
| 3024 | |
Sakari Ailus | c659c38 | 2011-01-21 10:59:30 +0000 | [diff] [blame] | 3025 | tlan_clear_bit(TLAN_NET_SIO_MCLK, sio); /* idle cycle */ |
| 3026 | tlan_set_bit(TLAN_NET_SIO_MCLK, sio); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3027 | |
Sakari Ailus | c659c38 | 2011-01-21 10:59:30 +0000 | [diff] [blame] | 3028 | if (minten) |
| 3029 | tlan_set_bit(TLAN_NET_SIO_MINTEN, sio); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3030 | |
| 3031 | *val = tmp; |
Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 3032 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3033 | if (!in_irq()) |
| 3034 | spin_unlock_irqrestore(&priv->lock, flags); |
| 3035 | |
| 3036 | return err; |
| 3037 | |
Sakari Ailus | c659c38 | 2011-01-21 10:59:30 +0000 | [diff] [blame] | 3038 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3039 | |
| 3040 | |
| 3041 | |
| 3042 | |
Sakari Ailus | c659c38 | 2011-01-21 10:59:30 +0000 | [diff] [blame] | 3043 | /*************************************************************** |
| 3044 | * tlan_mii_send_data |
| 3045 | * |
| 3046 | * Returns: |
| 3047 | * Nothing |
| 3048 | * Parms: |
| 3049 | * base_port The base IO port of the adapter in |
| 3050 | * question. |
| 3051 | * dev The address of the PHY to be queried. |
| 3052 | * data The value to be placed on the MII bus. |
| 3053 | * num_bits The number of bits in data that are to |
| 3054 | * be placed on the MII bus. |
| 3055 | * |
| 3056 | * This function sends on sequence of bits on the MII |
| 3057 | * configuration bus. |
| 3058 | * |
| 3059 | **************************************************************/ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3060 | |
Sakari Ailus | c659c38 | 2011-01-21 10:59:30 +0000 | [diff] [blame] | 3061 | static void tlan_mii_send_data(u16 base_port, u32 data, unsigned num_bits) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3062 | { |
| 3063 | u16 sio; |
| 3064 | u32 i; |
| 3065 | |
Sakari Ailus | c659c38 | 2011-01-21 10:59:30 +0000 | [diff] [blame] | 3066 | if (num_bits == 0) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3067 | return; |
| 3068 | |
Sakari Ailus | c659c38 | 2011-01-21 10:59:30 +0000 | [diff] [blame] | 3069 | outw(TLAN_NET_SIO, base_port + TLAN_DIO_ADR); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3070 | sio = base_port + TLAN_DIO_DATA + TLAN_NET_SIO; |
Sakari Ailus | c659c38 | 2011-01-21 10:59:30 +0000 | [diff] [blame] | 3071 | tlan_set_bit(TLAN_NET_SIO_MTXEN, sio); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3072 | |
Sakari Ailus | c659c38 | 2011-01-21 10:59:30 +0000 | [diff] [blame] | 3073 | for (i = (0x1 << (num_bits - 1)); i; i >>= 1) { |
| 3074 | tlan_clear_bit(TLAN_NET_SIO_MCLK, sio); |
| 3075 | (void) tlan_get_bit(TLAN_NET_SIO_MCLK, sio); |
| 3076 | if (data & i) |
| 3077 | tlan_set_bit(TLAN_NET_SIO_MDATA, sio); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3078 | else |
Sakari Ailus | c659c38 | 2011-01-21 10:59:30 +0000 | [diff] [blame] | 3079 | tlan_clear_bit(TLAN_NET_SIO_MDATA, sio); |
| 3080 | tlan_set_bit(TLAN_NET_SIO_MCLK, sio); |
| 3081 | (void) tlan_get_bit(TLAN_NET_SIO_MCLK, sio); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3082 | } |
| 3083 | |
Sakari Ailus | c659c38 | 2011-01-21 10:59:30 +0000 | [diff] [blame] | 3084 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3085 | |
| 3086 | |
| 3087 | |
| 3088 | |
Sakari Ailus | c659c38 | 2011-01-21 10:59:30 +0000 | [diff] [blame] | 3089 | /*************************************************************** |
| 3090 | * TLan_MiiSync |
| 3091 | * |
| 3092 | * Returns: |
| 3093 | * Nothing |
| 3094 | * Parms: |
| 3095 | * base_port The base IO port of the adapter in |
| 3096 | * question. |
| 3097 | * |
| 3098 | * This functions syncs all PHYs in terms of the MII configuration |
| 3099 | * bus. |
| 3100 | * |
| 3101 | **************************************************************/ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3102 | |
Sakari Ailus | c659c38 | 2011-01-21 10:59:30 +0000 | [diff] [blame] | 3103 | static void tlan_mii_sync(u16 base_port) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3104 | { |
| 3105 | int i; |
| 3106 | u16 sio; |
| 3107 | |
Sakari Ailus | c659c38 | 2011-01-21 10:59:30 +0000 | [diff] [blame] | 3108 | outw(TLAN_NET_SIO, base_port + TLAN_DIO_ADR); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3109 | sio = base_port + TLAN_DIO_DATA + TLAN_NET_SIO; |
| 3110 | |
Sakari Ailus | c659c38 | 2011-01-21 10:59:30 +0000 | [diff] [blame] | 3111 | tlan_clear_bit(TLAN_NET_SIO_MTXEN, sio); |
| 3112 | for (i = 0; i < 32; i++) { |
| 3113 | tlan_clear_bit(TLAN_NET_SIO_MCLK, sio); |
| 3114 | tlan_set_bit(TLAN_NET_SIO_MCLK, sio); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3115 | } |
| 3116 | |
Sakari Ailus | c659c38 | 2011-01-21 10:59:30 +0000 | [diff] [blame] | 3117 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3118 | |
| 3119 | |
| 3120 | |
| 3121 | |
Sakari Ailus | c659c38 | 2011-01-21 10:59:30 +0000 | [diff] [blame] | 3122 | /*************************************************************** |
| 3123 | * tlan_mii_write_reg |
| 3124 | * |
| 3125 | * Returns: |
| 3126 | * Nothing |
| 3127 | * Parms: |
| 3128 | * dev The device structure for the device |
| 3129 | * to write to. |
| 3130 | * phy The address of the PHY to be written to. |
| 3131 | * reg The register whose contents are to be |
| 3132 | * written. |
| 3133 | * val The value to be written to the register. |
| 3134 | * |
| 3135 | * This function uses the TLAN's MII bus to write the contents of a |
| 3136 | * given register on a PHY. It sends the appropriate info and then |
| 3137 | * writes the 16-bit register value from the MII configuration bus |
| 3138 | * via the TLAN SIO register. |
| 3139 | * |
| 3140 | **************************************************************/ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3141 | |
Sakari Ailus | c659c38 | 2011-01-21 10:59:30 +0000 | [diff] [blame] | 3142 | static void |
| 3143 | tlan_mii_write_reg(struct net_device *dev, u16 phy, u16 reg, u16 val) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3144 | { |
| 3145 | u16 sio; |
| 3146 | int minten; |
| 3147 | unsigned long flags = 0; |
Sakari Ailus | c659c38 | 2011-01-21 10:59:30 +0000 | [diff] [blame] | 3148 | struct tlan_priv *priv = netdev_priv(dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3149 | |
| 3150 | outw(TLAN_NET_SIO, dev->base_addr + TLAN_DIO_ADR); |
| 3151 | sio = dev->base_addr + TLAN_DIO_DATA + TLAN_NET_SIO; |
Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 3152 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3153 | if (!in_irq()) |
| 3154 | spin_lock_irqsave(&priv->lock, flags); |
| 3155 | |
Sakari Ailus | c659c38 | 2011-01-21 10:59:30 +0000 | [diff] [blame] | 3156 | tlan_mii_sync(dev->base_addr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3157 | |
Sakari Ailus | c659c38 | 2011-01-21 10:59:30 +0000 | [diff] [blame] | 3158 | minten = tlan_get_bit(TLAN_NET_SIO_MINTEN, sio); |
| 3159 | if (minten) |
| 3160 | tlan_clear_bit(TLAN_NET_SIO_MINTEN, sio); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3161 | |
Sakari Ailus | c659c38 | 2011-01-21 10:59:30 +0000 | [diff] [blame] | 3162 | tlan_mii_send_data(dev->base_addr, 0x1, 2); /* start (01b) */ |
| 3163 | tlan_mii_send_data(dev->base_addr, 0x1, 2); /* write (01b) */ |
| 3164 | tlan_mii_send_data(dev->base_addr, phy, 5); /* device # */ |
| 3165 | tlan_mii_send_data(dev->base_addr, reg, 5); /* register # */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3166 | |
Sakari Ailus | c659c38 | 2011-01-21 10:59:30 +0000 | [diff] [blame] | 3167 | tlan_mii_send_data(dev->base_addr, 0x2, 2); /* send ACK */ |
| 3168 | tlan_mii_send_data(dev->base_addr, val, 16); /* send data */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3169 | |
Sakari Ailus | c659c38 | 2011-01-21 10:59:30 +0000 | [diff] [blame] | 3170 | tlan_clear_bit(TLAN_NET_SIO_MCLK, sio); /* idle cycle */ |
| 3171 | tlan_set_bit(TLAN_NET_SIO_MCLK, sio); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3172 | |
Sakari Ailus | c659c38 | 2011-01-21 10:59:30 +0000 | [diff] [blame] | 3173 | if (minten) |
| 3174 | tlan_set_bit(TLAN_NET_SIO_MINTEN, sio); |
Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 3175 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3176 | if (!in_irq()) |
| 3177 | spin_unlock_irqrestore(&priv->lock, flags); |
| 3178 | |
Sakari Ailus | c659c38 | 2011-01-21 10:59:30 +0000 | [diff] [blame] | 3179 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3180 | |
| 3181 | |
| 3182 | |
| 3183 | |
| 3184 | /***************************************************************************** |
| 3185 | ****************************************************************************** |
| 3186 | |
Sakari Ailus | c659c38 | 2011-01-21 10:59:30 +0000 | [diff] [blame] | 3187 | ThunderLAN driver eeprom routines |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3188 | |
Sakari Ailus | c659c38 | 2011-01-21 10:59:30 +0000 | [diff] [blame] | 3189 | the Compaq netelligent 10 and 10/100 cards use a microchip 24C02A |
| 3190 | EEPROM. these functions are based on information in microchip's |
| 3191 | data sheet. I don't know how well this functions will work with |
| 3192 | other Eeproms. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3193 | |
| 3194 | ****************************************************************************** |
| 3195 | *****************************************************************************/ |
| 3196 | |
| 3197 | |
Sakari Ailus | c659c38 | 2011-01-21 10:59:30 +0000 | [diff] [blame] | 3198 | /*************************************************************** |
| 3199 | * tlan_ee_send_start |
| 3200 | * |
| 3201 | * Returns: |
| 3202 | * Nothing |
| 3203 | * Parms: |
| 3204 | * io_base The IO port base address for the |
| 3205 | * TLAN device with the EEPROM to |
| 3206 | * use. |
| 3207 | * |
| 3208 | * This function sends a start cycle to an EEPROM attached |
| 3209 | * to a TLAN chip. |
| 3210 | * |
| 3211 | **************************************************************/ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3212 | |
Sakari Ailus | c659c38 | 2011-01-21 10:59:30 +0000 | [diff] [blame] | 3213 | static void tlan_ee_send_start(u16 io_base) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3214 | { |
| 3215 | u16 sio; |
| 3216 | |
Sakari Ailus | c659c38 | 2011-01-21 10:59:30 +0000 | [diff] [blame] | 3217 | outw(TLAN_NET_SIO, io_base + TLAN_DIO_ADR); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3218 | sio = io_base + TLAN_DIO_DATA + TLAN_NET_SIO; |
| 3219 | |
Sakari Ailus | c659c38 | 2011-01-21 10:59:30 +0000 | [diff] [blame] | 3220 | tlan_set_bit(TLAN_NET_SIO_ECLOK, sio); |
| 3221 | tlan_set_bit(TLAN_NET_SIO_EDATA, sio); |
| 3222 | tlan_set_bit(TLAN_NET_SIO_ETXEN, sio); |
| 3223 | tlan_clear_bit(TLAN_NET_SIO_EDATA, sio); |
| 3224 | tlan_clear_bit(TLAN_NET_SIO_ECLOK, sio); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3225 | |
Sakari Ailus | c659c38 | 2011-01-21 10:59:30 +0000 | [diff] [blame] | 3226 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3227 | |
| 3228 | |
| 3229 | |
| 3230 | |
Sakari Ailus | c659c38 | 2011-01-21 10:59:30 +0000 | [diff] [blame] | 3231 | /*************************************************************** |
| 3232 | * tlan_ee_send_byte |
| 3233 | * |
| 3234 | * Returns: |
| 3235 | * If the correct ack was received, 0, otherwise 1 |
| 3236 | * Parms: io_base The IO port base address for the |
| 3237 | * TLAN device with the EEPROM to |
| 3238 | * use. |
| 3239 | * data The 8 bits of information to |
| 3240 | * send to the EEPROM. |
| 3241 | * stop If TLAN_EEPROM_STOP is passed, a |
| 3242 | * stop cycle is sent after the |
| 3243 | * byte is sent after the ack is |
| 3244 | * read. |
| 3245 | * |
| 3246 | * This function sends a byte on the serial EEPROM line, |
| 3247 | * driving the clock to send each bit. The function then |
| 3248 | * reverses transmission direction and reads an acknowledge |
| 3249 | * bit. |
| 3250 | * |
| 3251 | **************************************************************/ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3252 | |
Sakari Ailus | c659c38 | 2011-01-21 10:59:30 +0000 | [diff] [blame] | 3253 | static int tlan_ee_send_byte(u16 io_base, u8 data, int stop) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3254 | { |
| 3255 | int err; |
| 3256 | u8 place; |
| 3257 | u16 sio; |
| 3258 | |
Sakari Ailus | c659c38 | 2011-01-21 10:59:30 +0000 | [diff] [blame] | 3259 | outw(TLAN_NET_SIO, io_base + TLAN_DIO_ADR); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3260 | sio = io_base + TLAN_DIO_DATA + TLAN_NET_SIO; |
| 3261 | |
| 3262 | /* Assume clock is low, tx is enabled; */ |
Sakari Ailus | c659c38 | 2011-01-21 10:59:30 +0000 | [diff] [blame] | 3263 | for (place = 0x80; place != 0; place >>= 1) { |
| 3264 | if (place & data) |
| 3265 | tlan_set_bit(TLAN_NET_SIO_EDATA, sio); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3266 | else |
Sakari Ailus | c659c38 | 2011-01-21 10:59:30 +0000 | [diff] [blame] | 3267 | tlan_clear_bit(TLAN_NET_SIO_EDATA, sio); |
| 3268 | tlan_set_bit(TLAN_NET_SIO_ECLOK, sio); |
| 3269 | tlan_clear_bit(TLAN_NET_SIO_ECLOK, sio); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3270 | } |
Sakari Ailus | c659c38 | 2011-01-21 10:59:30 +0000 | [diff] [blame] | 3271 | tlan_clear_bit(TLAN_NET_SIO_ETXEN, sio); |
| 3272 | tlan_set_bit(TLAN_NET_SIO_ECLOK, sio); |
| 3273 | err = tlan_get_bit(TLAN_NET_SIO_EDATA, sio); |
| 3274 | tlan_clear_bit(TLAN_NET_SIO_ECLOK, sio); |
| 3275 | tlan_set_bit(TLAN_NET_SIO_ETXEN, sio); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3276 | |
Sakari Ailus | c659c38 | 2011-01-21 10:59:30 +0000 | [diff] [blame] | 3277 | if ((!err) && stop) { |
Stephen Hemminger | dfc2c0a | 2008-05-30 09:49:58 -0700 | [diff] [blame] | 3278 | /* STOP, raise data while clock is high */ |
Sakari Ailus | c659c38 | 2011-01-21 10:59:30 +0000 | [diff] [blame] | 3279 | tlan_clear_bit(TLAN_NET_SIO_EDATA, sio); |
| 3280 | tlan_set_bit(TLAN_NET_SIO_ECLOK, sio); |
| 3281 | tlan_set_bit(TLAN_NET_SIO_EDATA, sio); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3282 | } |
| 3283 | |
Eric Dumazet | 807540b | 2010-09-23 05:40:09 +0000 | [diff] [blame] | 3284 | return err; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3285 | |
Sakari Ailus | c659c38 | 2011-01-21 10:59:30 +0000 | [diff] [blame] | 3286 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3287 | |
| 3288 | |
| 3289 | |
| 3290 | |
Sakari Ailus | c659c38 | 2011-01-21 10:59:30 +0000 | [diff] [blame] | 3291 | /*************************************************************** |
| 3292 | * tlan_ee_receive_byte |
| 3293 | * |
| 3294 | * Returns: |
| 3295 | * Nothing |
| 3296 | * Parms: |
| 3297 | * io_base The IO port base address for the |
| 3298 | * TLAN device with the EEPROM to |
| 3299 | * use. |
| 3300 | * data An address to a char to hold the |
| 3301 | * data sent from the EEPROM. |
| 3302 | * stop If TLAN_EEPROM_STOP is passed, a |
| 3303 | * stop cycle is sent after the |
| 3304 | * byte is received, and no ack is |
| 3305 | * sent. |
| 3306 | * |
| 3307 | * This function receives 8 bits of data from the EEPROM |
| 3308 | * over the serial link. It then sends and ack bit, or no |
| 3309 | * ack and a stop bit. This function is used to retrieve |
| 3310 | * data after the address of a byte in the EEPROM has been |
| 3311 | * sent. |
| 3312 | * |
| 3313 | **************************************************************/ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3314 | |
Sakari Ailus | c659c38 | 2011-01-21 10:59:30 +0000 | [diff] [blame] | 3315 | static void tlan_ee_receive_byte(u16 io_base, u8 *data, int stop) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3316 | { |
| 3317 | u8 place; |
| 3318 | u16 sio; |
| 3319 | |
Sakari Ailus | c659c38 | 2011-01-21 10:59:30 +0000 | [diff] [blame] | 3320 | outw(TLAN_NET_SIO, io_base + TLAN_DIO_ADR); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3321 | sio = io_base + TLAN_DIO_DATA + TLAN_NET_SIO; |
| 3322 | *data = 0; |
| 3323 | |
| 3324 | /* Assume clock is low, tx is enabled; */ |
Sakari Ailus | c659c38 | 2011-01-21 10:59:30 +0000 | [diff] [blame] | 3325 | tlan_clear_bit(TLAN_NET_SIO_ETXEN, sio); |
| 3326 | for (place = 0x80; place; place >>= 1) { |
| 3327 | tlan_set_bit(TLAN_NET_SIO_ECLOK, sio); |
| 3328 | if (tlan_get_bit(TLAN_NET_SIO_EDATA, sio)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3329 | *data |= place; |
Sakari Ailus | c659c38 | 2011-01-21 10:59:30 +0000 | [diff] [blame] | 3330 | tlan_clear_bit(TLAN_NET_SIO_ECLOK, sio); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3331 | } |
| 3332 | |
Sakari Ailus | c659c38 | 2011-01-21 10:59:30 +0000 | [diff] [blame] | 3333 | tlan_set_bit(TLAN_NET_SIO_ETXEN, sio); |
| 3334 | if (!stop) { |
| 3335 | tlan_clear_bit(TLAN_NET_SIO_EDATA, sio); /* ack = 0 */ |
| 3336 | tlan_set_bit(TLAN_NET_SIO_ECLOK, sio); |
| 3337 | tlan_clear_bit(TLAN_NET_SIO_ECLOK, sio); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3338 | } else { |
Sakari Ailus | c659c38 | 2011-01-21 10:59:30 +0000 | [diff] [blame] | 3339 | tlan_set_bit(TLAN_NET_SIO_EDATA, sio); /* no ack = 1 (?) */ |
| 3340 | tlan_set_bit(TLAN_NET_SIO_ECLOK, sio); |
| 3341 | tlan_clear_bit(TLAN_NET_SIO_ECLOK, sio); |
Stephen Hemminger | dfc2c0a | 2008-05-30 09:49:58 -0700 | [diff] [blame] | 3342 | /* STOP, raise data while clock is high */ |
Sakari Ailus | c659c38 | 2011-01-21 10:59:30 +0000 | [diff] [blame] | 3343 | tlan_clear_bit(TLAN_NET_SIO_EDATA, sio); |
| 3344 | tlan_set_bit(TLAN_NET_SIO_ECLOK, sio); |
| 3345 | tlan_set_bit(TLAN_NET_SIO_EDATA, sio); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3346 | } |
| 3347 | |
Sakari Ailus | c659c38 | 2011-01-21 10:59:30 +0000 | [diff] [blame] | 3348 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3349 | |
| 3350 | |
| 3351 | |
| 3352 | |
Sakari Ailus | c659c38 | 2011-01-21 10:59:30 +0000 | [diff] [blame] | 3353 | /*************************************************************** |
| 3354 | * tlan_ee_read_byte |
| 3355 | * |
| 3356 | * Returns: |
| 3357 | * No error = 0, else, the stage at which the error |
| 3358 | * occurred. |
| 3359 | * Parms: |
| 3360 | * io_base The IO port base address for the |
| 3361 | * TLAN device with the EEPROM to |
| 3362 | * use. |
| 3363 | * ee_addr The address of the byte in the |
| 3364 | * EEPROM whose contents are to be |
| 3365 | * retrieved. |
| 3366 | * data An address to a char to hold the |
| 3367 | * data obtained from the EEPROM. |
| 3368 | * |
| 3369 | * This function reads a byte of information from an byte |
| 3370 | * cell in the EEPROM. |
| 3371 | * |
| 3372 | **************************************************************/ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3373 | |
Sakari Ailus | c659c38 | 2011-01-21 10:59:30 +0000 | [diff] [blame] | 3374 | static int tlan_ee_read_byte(struct net_device *dev, u8 ee_addr, u8 *data) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3375 | { |
| 3376 | int err; |
Sakari Ailus | c659c38 | 2011-01-21 10:59:30 +0000 | [diff] [blame] | 3377 | struct tlan_priv *priv = netdev_priv(dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3378 | unsigned long flags = 0; |
Sakari Ailus | c659c38 | 2011-01-21 10:59:30 +0000 | [diff] [blame] | 3379 | int ret = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3380 | |
| 3381 | spin_lock_irqsave(&priv->lock, flags); |
| 3382 | |
Sakari Ailus | c659c38 | 2011-01-21 10:59:30 +0000 | [diff] [blame] | 3383 | tlan_ee_send_start(dev->base_addr); |
| 3384 | err = tlan_ee_send_byte(dev->base_addr, 0xa0, TLAN_EEPROM_ACK); |
| 3385 | if (err) { |
| 3386 | ret = 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3387 | goto fail; |
| 3388 | } |
Sakari Ailus | c659c38 | 2011-01-21 10:59:30 +0000 | [diff] [blame] | 3389 | err = tlan_ee_send_byte(dev->base_addr, ee_addr, TLAN_EEPROM_ACK); |
| 3390 | if (err) { |
| 3391 | ret = 2; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3392 | goto fail; |
| 3393 | } |
Sakari Ailus | c659c38 | 2011-01-21 10:59:30 +0000 | [diff] [blame] | 3394 | tlan_ee_send_start(dev->base_addr); |
| 3395 | err = tlan_ee_send_byte(dev->base_addr, 0xa1, TLAN_EEPROM_ACK); |
| 3396 | if (err) { |
| 3397 | ret = 3; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3398 | goto fail; |
| 3399 | } |
Sakari Ailus | c659c38 | 2011-01-21 10:59:30 +0000 | [diff] [blame] | 3400 | tlan_ee_receive_byte(dev->base_addr, data, TLAN_EEPROM_STOP); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3401 | fail: |
| 3402 | spin_unlock_irqrestore(&priv->lock, flags); |
| 3403 | |
| 3404 | return ret; |
| 3405 | |
Sakari Ailus | c659c38 | 2011-01-21 10:59:30 +0000 | [diff] [blame] | 3406 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3407 | |
| 3408 | |
| 3409 | |