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