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