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