blob: 00ec926084ea03e188c91f75207865833e780755 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*******************************************************************************
2 *
3 * Linux ThunderLAN Driver
4 *
5 * tlan.c
6 * by James Banks
7 *
8 * (C) 1997-1998 Caldera, Inc.
9 * (C) 1998 James Banks
10 * (C) 1999-2001 Torben Mathiasen
11 * (C) 2002 Samuel Chessman
12 *
13 * This software may be used and distributed according to the terms
14 * of the GNU General Public License, incorporated herein by reference.
15 *
Linus Torvalds1da177e2005-04-16 15:20:36 -070016 ** Useful (if not required) reading:
17 *
18 * Texas Instruments, ThunderLAN Programmer's Guide,
19 * TI Literature Number SPWU013A
20 * available in PDF format from www.ti.com
21 * Level One, LXT901 and LXT970 Data Sheets
22 * available in PDF format from www.level1.com
23 * National Semiconductor, DP83840A Data Sheet
24 * available in PDF format from www.national.com
25 * Microchip Technology, 24C01A/02A/04A Data Sheet
26 * available in PDF format from www.microchip.com
27 *
Sakari Ailusc659c382011-01-21 10:59:30 +000028 ******************************************************************************/
Linus Torvalds1da177e2005-04-16 15:20:36 -070029
Joe Perches50624aa2011-03-01 06:56:33 +000030#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
31
Alexey Dobriyana6b7a402011-06-06 10:43:46 +000032#include <linux/hardirq.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070033#include <linux/module.h>
34#include <linux/init.h>
Alexey Dobriyana6b7a402011-06-06 10:43:46 +000035#include <linux/interrupt.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070036#include <linux/ioport.h>
37#include <linux/eisa.h>
38#include <linux/pci.h>
Domen Puncer1e7f0bd2005-06-26 18:22:14 -040039#include <linux/dma-mapping.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070040#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 Torvalds1da177e2005-04-16 15:20:36 -070049
50/* For removing EISA devices */
Sakari Ailusc659c382011-01-21 10:59:30 +000051static struct net_device *tlan_eisa_devices;
Linus Torvalds1da177e2005-04-16 15:20:36 -070052
Sakari Ailusc659c382011-01-21 10:59:30 +000053static int tlan_devices_installed;
Linus Torvalds1da177e2005-04-16 15:20:36 -070054
55/* Set speed, duplex and aui settings */
56static int aui[MAX_TLAN_BOARDS];
57static int duplex[MAX_TLAN_BOARDS];
58static int speed[MAX_TLAN_BOARDS];
59static int boards_found;
Stephen Hemminger15efa9b2005-05-04 15:33:11 -070060module_param_array(aui, int, NULL, 0);
61module_param_array(duplex, int, NULL, 0);
62module_param_array(speed, int, NULL, 0);
63MODULE_PARM_DESC(aui, "ThunderLAN use AUI port(s) (0-1)");
Sakari Ailusc659c382011-01-21 10:59:30 +000064MODULE_PARM_DESC(duplex,
65 "ThunderLAN duplex setting(s) (0-default, 1-half, 2-full)");
Joe Perches50624aa2011-03-01 06:56:33 +000066MODULE_PARM_DESC(speed, "ThunderLAN port speed setting(s) (0,10,100)");
Linus Torvalds1da177e2005-04-16 15:20:36 -070067
68MODULE_AUTHOR("Maintainer: Samuel Chessman <chessman@tux.org>");
69MODULE_DESCRIPTION("Driver for TI ThunderLAN based ethernet PCI adapters");
70MODULE_LICENSE("GPL");
71
Linus Torvalds1da177e2005-04-16 15:20:36 -070072/* Turn on debugging. See Documentation/networking/tlan.txt for details */
73static int debug;
Stephen Hemminger15efa9b2005-05-04 15:33:11 -070074module_param(debug, int, 0);
75MODULE_PARM_DESC(debug, "ThunderLAN debug mask");
Linus Torvalds1da177e2005-04-16 15:20:36 -070076
Sakari Ailusc659c382011-01-21 10:59:30 +000077static const char tlan_signature[] = "TLAN";
Sakari Ailusfa6d5d42011-01-21 10:59:31 +000078static const char tlan_banner[] = "ThunderLAN driver v1.17\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -070079static int tlan_have_pci;
80static int tlan_have_eisa;
81
Sakari Ailusc659c382011-01-21 10:59:30 +000082static const char * const media[] = {
83 "10BaseT-HD", "10BaseT-FD", "100baseTx-HD",
84 "100BaseTx-FD", "100BaseT4", NULL
Linus Torvalds1da177e2005-04-16 15:20:36 -070085};
86
87static struct board {
Sakari Ailusc659c382011-01-21 10:59:30 +000088 const char *device_label;
89 u32 flags;
90 u16 addr_ofs;
Linus Torvalds1da177e2005-04-16 15:20:36 -070091} board_info[] = {
92 { "Compaq Netelligent 10 T PCI UTP", TLAN_ADAPTER_ACTIVITY_LED, 0x83 },
Sakari Ailusc659c382011-01-21 10:59:30 +000093 { "Compaq Netelligent 10/100 TX PCI UTP",
94 TLAN_ADAPTER_ACTIVITY_LED, 0x83 },
Linus Torvalds1da177e2005-04-16 15:20:36 -070095 { "Compaq Integrated NetFlex-3/P", TLAN_ADAPTER_NONE, 0x83 },
Stephen Hemmingerdfc2c0a2008-05-30 09:49:58 -070096 { "Compaq NetFlex-3/P",
97 TLAN_ADAPTER_UNMANAGED_PHY | TLAN_ADAPTER_BIT_RATE_PHY, 0x83 },
Linus Torvalds1da177e2005-04-16 15:20:36 -070098 { "Compaq NetFlex-3/P", TLAN_ADAPTER_NONE, 0x83 },
Stephen Hemmingerdfc2c0a2008-05-30 09:49:58 -070099 { "Compaq Netelligent Integrated 10/100 TX UTP",
100 TLAN_ADAPTER_ACTIVITY_LED, 0x83 },
Sakari Ailusc659c382011-01-21 10:59:30 +0000101 { "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 Torvalds1da177e2005-04-16 15:20:36 -0700105 { "Olicom OC-2183/2185", TLAN_ADAPTER_USE_INTERN_10, 0x83 },
Ondrej Zaryeb522bb2014-06-30 18:38:27 +0200106 { "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 Torvalds1da177e2005-04-16 15:20:36 -0700110 { "Compaq Netelligent 10/100 TX UTP", TLAN_ADAPTER_ACTIVITY_LED, 0x83 },
Sakari Ailusc659c382011-01-21 10:59:30 +0000111 { "Compaq Netelligent 10 T/2 PCI UTP/coax", TLAN_ADAPTER_NONE, 0x83 },
Stephen Hemmingerdfc2c0a2008-05-30 09:49:58 -0700112 { "Compaq NetFlex-3/E",
Sakari Ailusc659c382011-01-21 10:59:30 +0000113 TLAN_ADAPTER_ACTIVITY_LED | /* EISA card */
Stephen Hemmingerdfc2c0a2008-05-30 09:49:58 -0700114 TLAN_ADAPTER_UNMANAGED_PHY | TLAN_ADAPTER_BIT_RATE_PHY, 0x83 },
Sakari Ailusc659c382011-01-21 10:59:30 +0000115 { "Compaq NetFlex-3/E",
116 TLAN_ADAPTER_ACTIVITY_LED, 0x83 }, /* EISA card */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700117};
118
Alexey Dobriyana3aa1882010-01-07 11:58:11 +0000119static DEFINE_PCI_DEVICE_TABLE(tlan_pci_tbl) = {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700120 { PCI_VENDOR_ID_COMPAQ, PCI_DEVICE_ID_COMPAQ_NETEL10,
Sakari Ailusc659c382011-01-21 10:59:30 +0000121 PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0 },
Linus Torvalds1da177e2005-04-16 15:20:36 -0700122 { PCI_VENDOR_ID_COMPAQ, PCI_DEVICE_ID_COMPAQ_NETEL100,
Sakari Ailusc659c382011-01-21 10:59:30 +0000123 PCI_ANY_ID, PCI_ANY_ID, 0, 0, 1 },
Linus Torvalds1da177e2005-04-16 15:20:36 -0700124 { PCI_VENDOR_ID_COMPAQ, PCI_DEVICE_ID_COMPAQ_NETFLEX3I,
Sakari Ailusc659c382011-01-21 10:59:30 +0000125 PCI_ANY_ID, PCI_ANY_ID, 0, 0, 2 },
Linus Torvalds1da177e2005-04-16 15:20:36 -0700126 { PCI_VENDOR_ID_COMPAQ, PCI_DEVICE_ID_COMPAQ_THUNDER,
Sakari Ailusc659c382011-01-21 10:59:30 +0000127 PCI_ANY_ID, PCI_ANY_ID, 0, 0, 3 },
Linus Torvalds1da177e2005-04-16 15:20:36 -0700128 { PCI_VENDOR_ID_COMPAQ, PCI_DEVICE_ID_COMPAQ_NETFLEX3B,
Sakari Ailusc659c382011-01-21 10:59:30 +0000129 PCI_ANY_ID, PCI_ANY_ID, 0, 0, 4 },
Linus Torvalds1da177e2005-04-16 15:20:36 -0700130 { PCI_VENDOR_ID_COMPAQ, PCI_DEVICE_ID_COMPAQ_NETEL100PI,
Sakari Ailusc659c382011-01-21 10:59:30 +0000131 PCI_ANY_ID, PCI_ANY_ID, 0, 0, 5 },
Linus Torvalds1da177e2005-04-16 15:20:36 -0700132 { PCI_VENDOR_ID_COMPAQ, PCI_DEVICE_ID_COMPAQ_NETEL100D,
Sakari Ailusc659c382011-01-21 10:59:30 +0000133 PCI_ANY_ID, PCI_ANY_ID, 0, 0, 6 },
Linus Torvalds1da177e2005-04-16 15:20:36 -0700134 { PCI_VENDOR_ID_COMPAQ, PCI_DEVICE_ID_COMPAQ_NETEL100I,
Sakari Ailusc659c382011-01-21 10:59:30 +0000135 PCI_ANY_ID, PCI_ANY_ID, 0, 0, 7 },
Linus Torvalds1da177e2005-04-16 15:20:36 -0700136 { PCI_VENDOR_ID_OLICOM, PCI_DEVICE_ID_OLICOM_OC2183,
Sakari Ailusc659c382011-01-21 10:59:30 +0000137 PCI_ANY_ID, PCI_ANY_ID, 0, 0, 8 },
Linus Torvalds1da177e2005-04-16 15:20:36 -0700138 { PCI_VENDOR_ID_OLICOM, PCI_DEVICE_ID_OLICOM_OC2325,
Sakari Ailusc659c382011-01-21 10:59:30 +0000139 PCI_ANY_ID, PCI_ANY_ID, 0, 0, 9 },
Linus Torvalds1da177e2005-04-16 15:20:36 -0700140 { PCI_VENDOR_ID_OLICOM, PCI_DEVICE_ID_OLICOM_OC2326,
Sakari Ailusc659c382011-01-21 10:59:30 +0000141 PCI_ANY_ID, PCI_ANY_ID, 0, 0, 10 },
Linus Torvalds1da177e2005-04-16 15:20:36 -0700142 { PCI_VENDOR_ID_COMPAQ, PCI_DEVICE_ID_NETELLIGENT_10_100_WS_5100,
Sakari Ailusc659c382011-01-21 10:59:30 +0000143 PCI_ANY_ID, PCI_ANY_ID, 0, 0, 11 },
Linus Torvalds1da177e2005-04-16 15:20:36 -0700144 { PCI_VENDOR_ID_COMPAQ, PCI_DEVICE_ID_NETELLIGENT_10_T2,
Sakari Ailusc659c382011-01-21 10:59:30 +0000145 PCI_ANY_ID, PCI_ANY_ID, 0, 0, 12 },
Linus Torvalds1da177e2005-04-16 15:20:36 -0700146 { 0,}
147};
Jeff Garzik6aa20a22006-09-13 13:24:59 -0400148MODULE_DEVICE_TABLE(pci, tlan_pci_tbl);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700149
Sakari Ailusc659c382011-01-21 10:59:30 +0000150static void tlan_eisa_probe(void);
151static void tlan_eisa_cleanup(void);
152static int tlan_init(struct net_device *);
153static int tlan_open(struct net_device *dev);
154static netdev_tx_t tlan_start_tx(struct sk_buff *, struct net_device *);
155static irqreturn_t tlan_handle_interrupt(int, void *);
156static int tlan_close(struct net_device *);
157static struct net_device_stats *tlan_get_stats(struct net_device *);
158static void tlan_set_multicast_list(struct net_device *);
159static int tlan_ioctl(struct net_device *dev, struct ifreq *rq, int cmd);
160static int tlan_probe1(struct pci_dev *pdev, long ioaddr,
161 int irq, int rev, const struct pci_device_id *ent);
162static void tlan_tx_timeout(struct net_device *dev);
163static void tlan_tx_timeout_work(struct work_struct *work);
164static int tlan_init_one(struct pci_dev *pdev,
165 const struct pci_device_id *ent);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700166
Sakari Ailusc659c382011-01-21 10:59:30 +0000167static u32 tlan_handle_tx_eof(struct net_device *, u16);
168static u32 tlan_handle_stat_overflow(struct net_device *, u16);
169static u32 tlan_handle_rx_eof(struct net_device *, u16);
170static u32 tlan_handle_dummy(struct net_device *, u16);
171static u32 tlan_handle_tx_eoc(struct net_device *, u16);
172static u32 tlan_handle_status_check(struct net_device *, u16);
173static u32 tlan_handle_rx_eoc(struct net_device *, u16);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700174
Sakari Ailusc659c382011-01-21 10:59:30 +0000175static void tlan_timer(unsigned long);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700176
Sakari Ailusc659c382011-01-21 10:59:30 +0000177static void tlan_reset_lists(struct net_device *);
178static void tlan_free_lists(struct net_device *);
179static void tlan_print_dio(u16);
180static void tlan_print_list(struct tlan_list *, char *, int);
181static void tlan_read_and_clear_stats(struct net_device *, int);
182static void tlan_reset_adapter(struct net_device *);
183static void tlan_finish_reset(struct net_device *);
184static void tlan_set_mac(struct net_device *, int areg, char *mac);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700185
Sakari Ailusc659c382011-01-21 10:59:30 +0000186static void tlan_phy_print(struct net_device *);
187static void tlan_phy_detect(struct net_device *);
188static void tlan_phy_power_down(struct net_device *);
189static void tlan_phy_power_up(struct net_device *);
190static void tlan_phy_reset(struct net_device *);
191static void tlan_phy_start_link(struct net_device *);
192static void tlan_phy_finish_auto_neg(struct net_device *);
Ondrej Zaryc0a87c22014-06-30 18:38:28 +0200193static void tlan_phy_monitor(unsigned long);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700194
195/*
Sakari Ailusc659c382011-01-21 10:59:30 +0000196 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 Torvalds1da177e2005-04-16 15:20:36 -0700200*/
201
Sakari Ailusc659c382011-01-21 10:59:30 +0000202static bool tlan_mii_read_reg(struct net_device *, u16, u16, u16 *);
203static void tlan_mii_send_data(u16, u32, unsigned);
204static void tlan_mii_sync(u16);
205static void tlan_mii_write_reg(struct net_device *, u16, u16, u16);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700206
Sakari Ailusc659c382011-01-21 10:59:30 +0000207static void tlan_ee_send_start(u16);
208static int tlan_ee_send_byte(u16, u8, int);
209static void tlan_ee_receive_byte(u16, u8 *, int);
210static int tlan_ee_read_byte(struct net_device *, u8, u8 *);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700211
212
Stephen Hemminger93e16842008-05-30 09:49:55 -0700213static inline void
Sakari Ailusc659c382011-01-21 10:59:30 +0000214tlan_store_skb(struct tlan_list *tag, struct sk_buff *skb)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700215{
216 unsigned long addr = (unsigned long)skb;
Stephen Hemminger93e16842008-05-30 09:49:55 -0700217 tag->buffer[9].address = addr;
218 tag->buffer[8].address = upper_32_bits(addr);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700219}
220
Stephen Hemminger93e16842008-05-30 09:49:55 -0700221static inline struct sk_buff *
Sakari Ailusc659c382011-01-21 10:59:30 +0000222tlan_get_skb(const struct tlan_list *tag)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700223{
Stephen Hemminger93e16842008-05-30 09:49:55 -0700224 unsigned long addr;
225
Robert Fitzsimons0d63bea2008-08-09 17:54:02 +0100226 addr = tag->buffer[9].address;
Benjamin Poirierda3a9e92012-04-25 04:49:20 +0000227 addr |= ((unsigned long) tag->buffer[8].address << 16) << 16;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700228 return (struct sk_buff *) addr;
229}
230
Sakari Ailusc659c382011-01-21 10:59:30 +0000231static u32
232(*tlan_int_vector[TLAN_INT_NUMBER_OF_INTS])(struct net_device *, u16) = {
Stephen Hemmingera3ccc782008-05-30 09:49:57 -0700233 NULL,
Sakari Ailusc659c382011-01-21 10:59:30 +0000234 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 Torvalds1da177e2005-04-16 15:20:36 -0700241};
242
243static inline void
Sakari Ailusc659c382011-01-21 10:59:30 +0000244tlan_set_timer(struct net_device *dev, u32 ticks, u32 type)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700245{
Sakari Ailusc659c382011-01-21 10:59:30 +0000246 struct tlan_priv *priv = netdev_priv(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700247 unsigned long flags = 0;
Jeff Garzik6aa20a22006-09-13 13:24:59 -0400248
Linus Torvalds1da177e2005-04-16 15:20:36 -0700249 if (!in_irq())
250 spin_lock_irqsave(&priv->lock, flags);
Sakari Ailusc659c382011-01-21 10:59:30 +0000251 if (priv->timer.function != NULL &&
252 priv->timer_type != TLAN_TIMER_ACTIVITY) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700253 if (!in_irq())
254 spin_unlock_irqrestore(&priv->lock, flags);
255 return;
256 }
Sakari Ailusc659c382011-01-21 10:59:30 +0000257 priv->timer.function = tlan_timer;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700258 if (!in_irq())
259 spin_unlock_irqrestore(&priv->lock, flags);
260
261 priv->timer.data = (unsigned long) dev;
Sakari Ailusc659c382011-01-21 10:59:30 +0000262 priv->timer_set_at = jiffies;
263 priv->timer_type = type;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700264 mod_timer(&priv->timer, jiffies + ticks);
Jeff Garzik6aa20a22006-09-13 13:24:59 -0400265
Sakari Ailusc659c382011-01-21 10:59:30 +0000266}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700267
268
269/*****************************************************************************
270******************************************************************************
271
Sakari Ailusc659c382011-01-21 10:59:30 +0000272ThunderLAN driver primary functions
Linus Torvalds1da177e2005-04-16 15:20:36 -0700273
Sakari Ailusc659c382011-01-21 10:59:30 +0000274these functions are more or less common to all linux network drivers.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700275
276******************************************************************************
277*****************************************************************************/
278
279
280
281
282
Sakari Ailusc659c382011-01-21 10:59:30 +0000283/***************************************************************
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 Torvalds1da177e2005-04-16 15:20:36 -0700297
298
Bill Pemberton36915872012-12-03 09:23:44 -0500299static void tlan_remove_one(struct pci_dev *pdev)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700300{
Sakari Ailusc659c382011-01-21 10:59:30 +0000301 struct net_device *dev = pci_get_drvdata(pdev);
302 struct tlan_priv *priv = netdev_priv(dev);
Jeff Garzik6aa20a22006-09-13 13:24:59 -0400303
Sakari Ailusc659c382011-01-21 10:59:30 +0000304 unregister_netdev(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700305
Sakari Ailusc659c382011-01-21 10:59:30 +0000306 if (priv->dma_storage) {
307 pci_free_consistent(priv->pci_dev,
308 priv->dma_size, priv->dma_storage,
309 priv->dma_storage_dma);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700310 }
311
312#ifdef CONFIG_PCI
313 pci_release_regions(pdev);
314#endif
Jeff Garzik6aa20a22006-09-13 13:24:59 -0400315
Sakari Ailusc659c382011-01-21 10:59:30 +0000316 free_netdev(dev);
Jeff Garzik6aa20a22006-09-13 13:24:59 -0400317
Devendra Naga1e0a8b12013-04-16 01:30:38 +0000318 cancel_work_sync(&priv->tlan_tqueue);
Jeff Garzik6aa20a22006-09-13 13:24:59 -0400319}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700320
Sakari Ailusfa6d5d42011-01-21 10:59:31 +0000321static 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
332static void tlan_stop(struct net_device *dev)
333{
334 struct tlan_priv *priv = netdev_priv(dev);
335
Ondrej Zaryc0a87c22014-06-30 18:38:28 +0200336 del_timer_sync(&priv->media_timer);
Sakari Ailusfa6d5d42011-01-21 10:59:31 +0000337 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
349static 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
365static 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 Wang1ca01512013-06-27 20:53:42 +0800371 pci_enable_wake(pdev, PCI_D0, 0);
Sakari Ailusfa6d5d42011-01-21 10:59:31 +0000372 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 Torvalds1da177e2005-04-16 15:20:36 -0700388static struct pci_driver tlan_driver = {
389 .name = "tlan",
390 .id_table = tlan_pci_tbl,
391 .probe = tlan_init_one,
Bill Pemberton36915872012-12-03 09:23:44 -0500392 .remove = tlan_remove_one,
Sakari Ailusfa6d5d42011-01-21 10:59:31 +0000393 .suspend = tlan_suspend,
394 .resume = tlan_resume,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700395};
396
397static int __init tlan_probe(void)
398{
Leonardo Potenza6c04a512008-02-04 23:47:16 -0800399 int rc = -ENODEV;
Jeff Garzik6aa20a22006-09-13 13:24:59 -0400400
Joe Perches50624aa2011-03-01 06:56:33 +0000401 pr_info("%s", tlan_banner);
Jeff Garzik6aa20a22006-09-13 13:24:59 -0400402
Linus Torvalds1da177e2005-04-16 15:20:36 -0700403 TLAN_DBG(TLAN_DEBUG_PROBE, "Starting PCI Probe....\n");
Jeff Garzik6aa20a22006-09-13 13:24:59 -0400404
Linus Torvalds1da177e2005-04-16 15:20:36 -0700405 /* Use new style PCI probing. Now the kernel will
406 do most of this for us */
Leonardo Potenza6c04a512008-02-04 23:47:16 -0800407 rc = pci_register_driver(&tlan_driver);
408
409 if (rc != 0) {
Joe Perches50624aa2011-03-01 06:56:33 +0000410 pr_err("Could not register pci driver\n");
Leonardo Potenza6c04a512008-02-04 23:47:16 -0800411 goto err_out_pci_free;
412 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700413
414 TLAN_DBG(TLAN_DEBUG_PROBE, "Starting EISA Probe....\n");
Sakari Ailusc659c382011-01-21 10:59:30 +0000415 tlan_eisa_probe();
Jeff Garzik6aa20a22006-09-13 13:24:59 -0400416
Joe Perches50624aa2011-03-01 06:56:33 +0000417 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 Torvalds1da177e2005-04-16 15:20:36 -0700420
Sakari Ailusc659c382011-01-21 10:59:30 +0000421 if (tlan_devices_installed == 0) {
Leonardo Potenza6c04a512008-02-04 23:47:16 -0800422 rc = -ENODEV;
423 goto err_out_pci_unreg;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700424 }
425 return 0;
Leonardo Potenza6c04a512008-02-04 23:47:16 -0800426
427err_out_pci_unreg:
428 pci_unregister_driver(&tlan_driver);
429err_out_pci_free:
Leonardo Potenza6c04a512008-02-04 23:47:16 -0800430 return rc;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700431}
Jeff Garzik6aa20a22006-09-13 13:24:59 -0400432
Linus Torvalds1da177e2005-04-16 15:20:36 -0700433
Bill Pemberton36915872012-12-03 09:23:44 -0500434static int tlan_init_one(struct pci_dev *pdev,
Sakari Ailusc659c382011-01-21 10:59:30 +0000435 const struct pci_device_id *ent)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700436{
Sakari Ailusc659c382011-01-21 10:59:30 +0000437 return tlan_probe1(pdev, -1, -1, 0, ent);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700438}
439
440
441/*
Sakari Ailusc659c382011-01-21 10:59:30 +0000442***************************************************************
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 Torvalds1da177e2005-04-16 15:20:36 -0700459
Greg Kroah-Hartman1dd06ae2012-12-06 14:30:56 +0000460static int tlan_probe1(struct pci_dev *pdev, long ioaddr, int irq, int rev,
461 const struct pci_device_id *ent)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700462{
463
464 struct net_device *dev;
Sakari Ailusc659c382011-01-21 10:59:30 +0000465 struct tlan_priv *priv;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700466 u16 device_id;
467 int reg, rc = -ENODEV;
468
Adrian Bunkad9f6712006-02-05 00:37:47 +0100469#ifdef CONFIG_PCI
Linus Torvalds1da177e2005-04-16 15:20:36 -0700470 if (pdev) {
471 rc = pci_enable_device(pdev);
472 if (rc)
473 return rc;
474
Sakari Ailusc659c382011-01-21 10:59:30 +0000475 rc = pci_request_regions(pdev, tlan_signature);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700476 if (rc) {
Joe Perches50624aa2011-03-01 06:56:33 +0000477 pr_err("Could not reserve IO regions\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700478 goto err_out;
479 }
480 }
Adrian Bunkad9f6712006-02-05 00:37:47 +0100481#endif /* CONFIG_PCI */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700482
Sakari Ailusc659c382011-01-21 10:59:30 +0000483 dev = alloc_etherdev(sizeof(struct tlan_priv));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700484 if (dev == NULL) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700485 rc = -ENOMEM;
486 goto err_out_regions;
487 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700488 SET_NETDEV_DEV(dev, &pdev->dev);
Jeff Garzik6aa20a22006-09-13 13:24:59 -0400489
Linus Torvalds1da177e2005-04-16 15:20:36 -0700490 priv = netdev_priv(dev);
491
Sakari Ailusc659c382011-01-21 10:59:30 +0000492 priv->pci_dev = pdev;
David Howellsc4028952006-11-22 14:57:56 +0000493 priv->dev = dev;
Jeff Garzik6aa20a22006-09-13 13:24:59 -0400494
Linus Torvalds1da177e2005-04-16 15:20:36 -0700495 /* Is this a PCI device? */
496 if (pdev) {
Sakari Ailusc659c382011-01-21 10:59:30 +0000497 u32 pci_io_base = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700498
499 priv->adapter = &board_info[ent->driver_data];
500
Yang Hongyang284901a2009-04-06 19:01:15 -0700501 rc = pci_set_dma_mask(pdev, DMA_BIT_MASK(32));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700502 if (rc) {
Joe Perches50624aa2011-03-01 06:56:33 +0000503 pr_err("No suitable PCI mapping available\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700504 goto err_out_free_dev;
505 }
506
Sakari Ailusc659c382011-01-21 10:59:30 +0000507 for (reg = 0; reg <= 5; reg++) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700508 if (pci_resource_flags(pdev, reg) & IORESOURCE_IO) {
509 pci_io_base = pci_resource_start(pdev, reg);
Sakari Ailusc659c382011-01-21 10:59:30 +0000510 TLAN_DBG(TLAN_DEBUG_GNRL,
511 "IO mapping is available at %x.\n",
512 pci_io_base);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700513 break;
514 }
515 }
516 if (!pci_io_base) {
Joe Perches50624aa2011-03-01 06:56:33 +0000517 pr_err("No IO mappings available\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700518 rc = -EIO;
519 goto err_out_free_dev;
520 }
Jeff Garzik6aa20a22006-09-13 13:24:59 -0400521
Linus Torvalds1da177e2005-04-16 15:20:36 -0700522 dev->base_addr = pci_io_base;
523 dev->irq = pdev->irq;
Sakari Ailusc659c382011-01-21 10:59:30 +0000524 priv->adapter_rev = pdev->revision;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700525 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 Torvalds1da177e2005-04-16 15:20:36 -0700532 if (device_id == 0x20F1) {
Sakari Ailusc659c382011-01-21 10:59:30 +0000533 priv->adapter = &board_info[13]; /* NetFlex-3/E */
534 priv->adapter_rev = 23; /* TLAN 2.3 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700535 } else {
536 priv->adapter = &board_info[14];
Sakari Ailusc659c382011-01-21 10:59:30 +0000537 priv->adapter_rev = 10; /* TLAN 1.0 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700538 }
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 Hemmingerdfc2c0a2008-05-30 09:49:58 -0700546 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 Garzik6aa20a22006-09-13 13:24:59 -0400550
Sakari Ailusc659c382011-01-21 10:59:30 +0000551 if (priv->speed == 0x1)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700552 priv->speed = TLAN_SPEED_10;
Sakari Ailusc659c382011-01-21 10:59:30 +0000553 else if (priv->speed == 0x2)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700554 priv->speed = TLAN_SPEED_100;
Sakari Ailusc659c382011-01-21 10:59:30 +0000555
Linus Torvalds1da177e2005-04-16 15:20:36 -0700556 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 Garzik6aa20a22006-09-13 13:24:59 -0400563
Linus Torvalds1da177e2005-04-16 15:20:36 -0700564 /* This will be used when we get an adapter error from
565 * within our irq handler */
Sakari Ailusc659c382011-01-21 10:59:30 +0000566 INIT_WORK(&priv->tlan_tqueue, tlan_tx_timeout_work);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700567
568 spin_lock_init(&priv->lock);
Jeff Garzik6aa20a22006-09-13 13:24:59 -0400569
Sakari Ailusc659c382011-01-21 10:59:30 +0000570 rc = tlan_init(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700571 if (rc) {
Joe Perches50624aa2011-03-01 06:56:33 +0000572 pr_err("Could not set up device\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700573 goto err_out_free_dev;
574 }
575
576 rc = register_netdev(dev);
577 if (rc) {
Joe Perches50624aa2011-03-01 06:56:33 +0000578 pr_err("Could not register device\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700579 goto err_out_uninit;
580 }
581
Jeff Garzik6aa20a22006-09-13 13:24:59 -0400582
Sakari Ailusc659c382011-01-21 10:59:30 +0000583 tlan_devices_installed++;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700584 boards_found++;
Jeff Garzik6aa20a22006-09-13 13:24:59 -0400585
Linus Torvalds1da177e2005-04-16 15:20:36 -0700586 /* pdev is NULL if this is an EISA device */
587 if (pdev)
588 tlan_have_pci++;
589 else {
Sakari Ailusc659c382011-01-21 10:59:30 +0000590 priv->next_device = tlan_eisa_devices;
591 tlan_eisa_devices = dev;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700592 tlan_have_eisa++;
593 }
Jeff Garzik6aa20a22006-09-13 13:24:59 -0400594
Joe Perches50624aa2011-03-01 06:56:33 +0000595 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 Torvalds1da177e2005-04-16 15:20:36 -0700600 return 0;
601
602err_out_uninit:
Sakari Ailusc659c382011-01-21 10:59:30 +0000603 pci_free_consistent(priv->pci_dev, priv->dma_size, priv->dma_storage,
604 priv->dma_storage_dma);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700605err_out_free_dev:
606 free_netdev(dev);
607err_out_regions:
608#ifdef CONFIG_PCI
609 if (pdev)
610 pci_release_regions(pdev);
611#endif
612err_out:
613 if (pdev)
614 pci_disable_device(pdev);
615 return rc;
616}
617
618
Sakari Ailusc659c382011-01-21 10:59:30 +0000619static void tlan_eisa_cleanup(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700620{
621 struct net_device *dev;
Sakari Ailusc659c382011-01-21 10:59:30 +0000622 struct tlan_priv *priv;
Jeff Garzik6aa20a22006-09-13 13:24:59 -0400623
Sakari Ailusc659c382011-01-21 10:59:30 +0000624 while (tlan_have_eisa) {
625 dev = tlan_eisa_devices;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700626 priv = netdev_priv(dev);
Sakari Ailusc659c382011-01-21 10:59:30 +0000627 if (priv->dma_storage) {
628 pci_free_consistent(priv->pci_dev, priv->dma_size,
629 priv->dma_storage,
630 priv->dma_storage_dma);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700631 }
Sakari Ailusc659c382011-01-21 10:59:30 +0000632 release_region(dev->base_addr, 0x10);
633 unregister_netdev(dev);
634 tlan_eisa_devices = priv->next_device;
635 free_netdev(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700636 tlan_have_eisa--;
637 }
638}
Jeff Garzik6aa20a22006-09-13 13:24:59 -0400639
640
Linus Torvalds1da177e2005-04-16 15:20:36 -0700641static void __exit tlan_exit(void)
642{
643 pci_unregister_driver(&tlan_driver);
644
645 if (tlan_have_eisa)
Sakari Ailusc659c382011-01-21 10:59:30 +0000646 tlan_eisa_cleanup();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700647
Linus Torvalds1da177e2005-04-16 15:20:36 -0700648}
649
650
651/* Module loading/unloading */
652module_init(tlan_probe);
653module_exit(tlan_exit);
654
655
656
Sakari Ailusc659c382011-01-21 10:59:30 +0000657/**************************************************************
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 Torvalds1da177e2005-04-16 15:20:36 -0700669
Sakari Ailusc659c382011-01-21 10:59:30 +0000670static void __init tlan_eisa_probe(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700671{
Sakari Ailusc659c382011-01-21 10:59:30 +0000672 long ioaddr;
673 int rc = -ENODEV;
674 int irq;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700675 u16 device_id;
676
Jeff Garzik6aa20a22006-09-13 13:24:59 -0400677 if (!EISA_bus) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700678 TLAN_DBG(TLAN_DEBUG_PROBE, "No EISA bus present\n");
679 return;
680 }
Jeff Garzik6aa20a22006-09-13 13:24:59 -0400681
Linus Torvalds1da177e2005-04-16 15:20:36 -0700682 /* Loop through all slots of the EISA bus */
683 for (ioaddr = 0x1000; ioaddr < 0x9000; ioaddr += 0x1000) {
Jeff Garzik6aa20a22006-09-13 13:24:59 -0400684
Sakari Ailusc659c382011-01-21 10:59:30 +0000685 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 Torvalds1da177e2005-04-16 15:20:36 -0700689
690
Sakari Ailusc659c382011-01-21 10:59:30 +0000691 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 Torvalds1da177e2005-04-16 15:20:36 -0700695 goto out;
696
Jeff Garzik6aa20a22006-09-13 13:24:59 -0400697 if (inw(ioaddr + EISA_ID) != 0x110E) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700698 release_region(ioaddr, 0x10);
699 goto out;
700 }
Jeff Garzik6aa20a22006-09-13 13:24:59 -0400701
Linus Torvalds1da177e2005-04-16 15:20:36 -0700702 device_id = inw(ioaddr + EISA_ID2);
Jeff Garzik6aa20a22006-09-13 13:24:59 -0400703 if (device_id != 0x20F1 && device_id != 0x40F1) {
Sakari Ailusc659c382011-01-21 10:59:30 +0000704 release_region(ioaddr, 0x10);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700705 goto out;
706 }
Jeff Garzik6aa20a22006-09-13 13:24:59 -0400707
Sakari Ailusc659c382011-01-21 10:59:30 +0000708 /* check if adapter is enabled */
709 if (inb(ioaddr + EISA_CR) != 0x1) {
710 release_region(ioaddr, 0x10);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700711 goto out2;
712 }
Jeff Garzik6aa20a22006-09-13 13:24:59 -0400713
714 if (debug == 0x10)
Joe Perches50624aa2011-03-01 06:56:33 +0000715 pr_info("Found one\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700716
717
718 /* Get irq from board */
Sakari Ailusc659c382011-01-21 10:59:30 +0000719 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 Garzik6aa20a22006-09-13 13:24:59 -0400734 }
735
736
Linus Torvalds1da177e2005-04-16 15:20:36 -0700737 /* Setup the newly found eisa adapter */
Sakari Ailusc659c382011-01-21 10:59:30 +0000738 rc = tlan_probe1(NULL, ioaddr, irq,
739 12, NULL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700740 continue;
Jeff Garzik6aa20a22006-09-13 13:24:59 -0400741
Sakari Ailusc659c382011-01-21 10:59:30 +0000742out:
743 if (debug == 0x10)
Joe Perches50624aa2011-03-01 06:56:33 +0000744 pr_info("None found\n");
Sakari Ailusc659c382011-01-21 10:59:30 +0000745 continue;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700746
Sakari Ailusc659c382011-01-21 10:59:30 +0000747out2:
748 if (debug == 0x10)
Joe Perches50624aa2011-03-01 06:56:33 +0000749 pr_info("Card found but it is not enabled, skipping\n");
Sakari Ailusc659c382011-01-21 10:59:30 +0000750 continue;
Jeff Garzik6aa20a22006-09-13 13:24:59 -0400751
Linus Torvalds1da177e2005-04-16 15:20:36 -0700752 }
753
Sakari Ailusc659c382011-01-21 10:59:30 +0000754}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700755
756#ifdef CONFIG_NET_POLL_CONTROLLER
Sakari Ailusc659c382011-01-21 10:59:30 +0000757static void tlan_poll(struct net_device *dev)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700758{
759 disable_irq(dev->irq);
Sakari Ailusc659c382011-01-21 10:59:30 +0000760 tlan_handle_interrupt(dev->irq, dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700761 enable_irq(dev->irq);
762}
763#endif
764
Sakari Ailusc659c382011-01-21 10:59:30 +0000765static 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 Pirkoafc4b132011-08-16 06:29:01 +0000771 .ndo_set_rx_mode = tlan_set_multicast_list,
Sakari Ailusc659c382011-01-21 10:59:30 +0000772 .ndo_do_ioctl = tlan_ioctl,
Stephen Hemminger391c5e62009-01-07 17:27:15 -0800773 .ndo_change_mtu = eth_change_mtu,
Sakari Ailusc659c382011-01-21 10:59:30 +0000774 .ndo_set_mac_address = eth_mac_addr,
Stephen Hemminger391c5e62009-01-07 17:27:15 -0800775 .ndo_validate_addr = eth_validate_addr,
776#ifdef CONFIG_NET_POLL_CONTROLLER
Sakari Ailusc659c382011-01-21 10:59:30 +0000777 .ndo_poll_controller = tlan_poll,
Stephen Hemminger391c5e62009-01-07 17:27:15 -0800778#endif
779};
Jeff Garzik6aa20a22006-09-13 13:24:59 -0400780
Ondrej Zarye36124d2014-06-30 18:38:29 +0200781static void tlan_get_drvinfo(struct net_device *dev,
782 struct ethtool_drvinfo *info)
783{
784 struct tlan_priv *priv = netdev_priv(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700785
Ondrej Zarye36124d2014-06-30 18:38:29 +0200786 strlcpy(info->driver, KBUILD_MODNAME, sizeof(info->driver));
787 if (priv->pci_dev)
788 strlcpy(info->bus_info, pci_name(priv->pci_dev),
789 sizeof(info->bus_info));
790 else
791 strlcpy(info->bus_info, "EISA", sizeof(info->bus_info));
792 info->eedump_len = TLAN_EEPROM_SIZE;
793}
794
795static int tlan_get_eeprom_len(struct net_device *dev)
796{
797 return TLAN_EEPROM_SIZE;
798}
799
800static int tlan_get_eeprom(struct net_device *dev,
801 struct ethtool_eeprom *eeprom, u8 *data)
802{
803 int i;
804
805 for (i = 0; i < TLAN_EEPROM_SIZE; i++)
806 if (tlan_ee_read_byte(dev, i, &data[i]))
807 return -EIO;
808
809 return 0;
810}
811
812static const struct ethtool_ops tlan_ethtool_ops = {
813 .get_drvinfo = tlan_get_drvinfo,
814 .get_link = ethtool_op_get_link,
815 .get_eeprom_len = tlan_get_eeprom_len,
816 .get_eeprom = tlan_get_eeprom,
817};
Linus Torvalds1da177e2005-04-16 15:20:36 -0700818
Sakari Ailusc659c382011-01-21 10:59:30 +0000819/***************************************************************
820 * tlan_init
821 *
822 * Returns:
823 * 0 on success, error code otherwise.
824 * Parms:
825 * dev The structure of the device to be
826 * init'ed.
827 *
828 * This function completes the initialization of the
829 * device structure and driver. It reserves the IO
830 * addresses, allocates memory for the lists and bounce
831 * buffers, retrieves the MAC address from the eeprom
832 * and assignes the device's methods.
833 *
834 **************************************************************/
Linus Torvalds1da177e2005-04-16 15:20:36 -0700835
Sakari Ailusc659c382011-01-21 10:59:30 +0000836static int tlan_init(struct net_device *dev)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700837{
838 int dma_size;
Sakari Ailusc659c382011-01-21 10:59:30 +0000839 int err;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700840 int i;
Sakari Ailusc659c382011-01-21 10:59:30 +0000841 struct tlan_priv *priv;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700842
843 priv = netdev_priv(dev);
Jeff Garzik6aa20a22006-09-13 13:24:59 -0400844
Sakari Ailusc659c382011-01-21 10:59:30 +0000845 dma_size = (TLAN_NUM_RX_LISTS + TLAN_NUM_TX_LISTS)
846 * (sizeof(struct tlan_list));
847 priv->dma_storage = pci_alloc_consistent(priv->pci_dev,
848 dma_size,
849 &priv->dma_storage_dma);
850 priv->dma_size = dma_size;
Jeff Garzik6aa20a22006-09-13 13:24:59 -0400851
Sakari Ailusc659c382011-01-21 10:59:30 +0000852 if (priv->dma_storage == NULL) {
Joe Perches50624aa2011-03-01 06:56:33 +0000853 pr_err("Could not allocate lists and buffers for %s\n",
Sakari Ailusc659c382011-01-21 10:59:30 +0000854 dev->name);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700855 return -ENOMEM;
856 }
Sakari Ailusc659c382011-01-21 10:59:30 +0000857 memset(priv->dma_storage, 0, dma_size);
858 priv->rx_list = (struct tlan_list *)
859 ALIGN((unsigned long)priv->dma_storage, 8);
860 priv->rx_list_dma = ALIGN(priv->dma_storage_dma, 8);
861 priv->tx_list = priv->rx_list + TLAN_NUM_RX_LISTS;
862 priv->tx_list_dma =
863 priv->rx_list_dma + sizeof(struct tlan_list)*TLAN_NUM_RX_LISTS;
Stephen Hemminger93e16842008-05-30 09:49:55 -0700864
Linus Torvalds1da177e2005-04-16 15:20:36 -0700865 err = 0;
Sakari Ailusc659c382011-01-21 10:59:30 +0000866 for (i = 0; i < 6 ; i++)
867 err |= tlan_ee_read_byte(dev,
868 (u8) priv->adapter->addr_ofs + i,
869 (u8 *) &dev->dev_addr[i]);
870 if (err) {
Joe Perches50624aa2011-03-01 06:56:33 +0000871 pr_err("%s: Error reading MAC from eeprom: %d\n",
872 dev->name, err);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700873 }
874 dev->addr_len = 6;
875
876 netif_carrier_off(dev);
877
878 /* Device methods */
Sakari Ailusc659c382011-01-21 10:59:30 +0000879 dev->netdev_ops = &tlan_netdev_ops;
Ondrej Zarye36124d2014-06-30 18:38:29 +0200880 dev->ethtool_ops = &tlan_ethtool_ops;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700881 dev->watchdog_timeo = TX_TIMEOUT;
882
883 return 0;
884
Sakari Ailusc659c382011-01-21 10:59:30 +0000885}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700886
887
888
889
Sakari Ailusc659c382011-01-21 10:59:30 +0000890/***************************************************************
891 * tlan_open
892 *
893 * Returns:
894 * 0 on success, error code otherwise.
895 * Parms:
896 * dev Structure of device to be opened.
897 *
898 * This routine puts the driver and TLAN adapter in a
899 * state where it is ready to send and receive packets.
900 * It allocates the IRQ, resets and brings the adapter
901 * out of reset, and allows interrupts. It also delays
902 * the startup for autonegotiation or sends a Rx GO
903 * command to the adapter, as appropriate.
904 *
905 **************************************************************/
Linus Torvalds1da177e2005-04-16 15:20:36 -0700906
Sakari Ailusc659c382011-01-21 10:59:30 +0000907static int tlan_open(struct net_device *dev)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700908{
Sakari Ailusc659c382011-01-21 10:59:30 +0000909 struct tlan_priv *priv = netdev_priv(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700910 int err;
Jeff Garzik6aa20a22006-09-13 13:24:59 -0400911
Sakari Ailusc659c382011-01-21 10:59:30 +0000912 priv->tlan_rev = tlan_dio_read8(dev->base_addr, TLAN_DEF_REVISION);
913 err = request_irq(dev->irq, tlan_handle_interrupt, IRQF_SHARED,
914 dev->name, dev);
Jeff Garzik6aa20a22006-09-13 13:24:59 -0400915
Sakari Ailusc659c382011-01-21 10:59:30 +0000916 if (err) {
Joe Perches50624aa2011-03-01 06:56:33 +0000917 netdev_err(dev, "Cannot open because IRQ %d is already in use\n",
918 dev->irq);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700919 return err;
920 }
Jeff Garzik6aa20a22006-09-13 13:24:59 -0400921
Linus Torvalds1da177e2005-04-16 15:20:36 -0700922 init_timer(&priv->timer);
Ondrej Zaryc0a87c22014-06-30 18:38:28 +0200923 init_timer(&priv->media_timer);
Jeff Garzik6aa20a22006-09-13 13:24:59 -0400924
Sakari Ailusfa6d5d42011-01-21 10:59:31 +0000925 tlan_start(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700926
Sakari Ailusc659c382011-01-21 10:59:30 +0000927 TLAN_DBG(TLAN_DEBUG_GNRL, "%s: Opened. TLAN Chip Rev: %x\n",
928 dev->name, priv->tlan_rev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700929
930 return 0;
931
Sakari Ailusc659c382011-01-21 10:59:30 +0000932}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700933
934
935
Sakari Ailusc659c382011-01-21 10:59:30 +0000936/**************************************************************
937 * tlan_ioctl
938 *
939 * Returns:
940 * 0 on success, error code otherwise
941 * Params:
942 * dev structure of device to receive ioctl.
943 *
944 * rq ifreq structure to hold userspace data.
945 *
946 * cmd ioctl command.
947 *
948 *
949 *************************************************************/
Linus Torvalds1da177e2005-04-16 15:20:36 -0700950
Sakari Ailusc659c382011-01-21 10:59:30 +0000951static int tlan_ioctl(struct net_device *dev, struct ifreq *rq, int cmd)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700952{
Sakari Ailusc659c382011-01-21 10:59:30 +0000953 struct tlan_priv *priv = netdev_priv(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700954 struct mii_ioctl_data *data = if_mii(rq);
Sakari Ailusc659c382011-01-21 10:59:30 +0000955 u32 phy = priv->phy[priv->phy_num];
Jeff Garzik6aa20a22006-09-13 13:24:59 -0400956
Sakari Ailusc659c382011-01-21 10:59:30 +0000957 if (!priv->phy_online)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700958 return -EAGAIN;
959
Sakari Ailusc659c382011-01-21 10:59:30 +0000960 switch (cmd) {
961 case SIOCGMIIPHY: /* get address of MII PHY in use. */
962 data->phy_id = phy;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700963
964
Sakari Ailusc659c382011-01-21 10:59:30 +0000965 case SIOCGMIIREG: /* read MII PHY register. */
966 tlan_mii_read_reg(dev, data->phy_id & 0x1f,
967 data->reg_num & 0x1f, &data->val_out);
968 return 0;
Jeff Garzik6aa20a22006-09-13 13:24:59 -0400969
Linus Torvalds1da177e2005-04-16 15:20:36 -0700970
Sakari Ailusc659c382011-01-21 10:59:30 +0000971 case SIOCSMIIREG: /* write MII PHY register. */
972 tlan_mii_write_reg(dev, data->phy_id & 0x1f,
973 data->reg_num & 0x1f, data->val_in);
974 return 0;
975 default:
976 return -EOPNOTSUPP;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700977 }
Sakari Ailusc659c382011-01-21 10:59:30 +0000978}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700979
980
Sakari Ailusc659c382011-01-21 10:59:30 +0000981/***************************************************************
982 * tlan_tx_timeout
983 *
984 * Returns: nothing
985 *
986 * Params:
987 * dev structure of device which timed out
988 * during transmit.
989 *
990 **************************************************************/
Linus Torvalds1da177e2005-04-16 15:20:36 -0700991
Sakari Ailusc659c382011-01-21 10:59:30 +0000992static void tlan_tx_timeout(struct net_device *dev)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700993{
Jeff Garzik6aa20a22006-09-13 13:24:59 -0400994
Sakari Ailusc659c382011-01-21 10:59:30 +0000995 TLAN_DBG(TLAN_DEBUG_GNRL, "%s: Transmit timed out.\n", dev->name);
Jeff Garzik6aa20a22006-09-13 13:24:59 -0400996
Linus Torvalds1da177e2005-04-16 15:20:36 -0700997 /* Ok so we timed out, lets see what we can do about it...*/
Sakari Ailusc659c382011-01-21 10:59:30 +0000998 tlan_free_lists(dev);
999 tlan_reset_lists(dev);
1000 tlan_read_and_clear_stats(dev, TLAN_IGNORE);
1001 tlan_reset_adapter(dev);
Eric Dumazet1ae5dc32010-05-10 05:01:31 -07001002 dev->trans_start = jiffies; /* prevent tx timeout */
Sakari Ailusc659c382011-01-21 10:59:30 +00001003 netif_wake_queue(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001004
1005}
Jeff Garzik6aa20a22006-09-13 13:24:59 -04001006
Linus Torvalds1da177e2005-04-16 15:20:36 -07001007
Sakari Ailusc659c382011-01-21 10:59:30 +00001008/***************************************************************
1009 * tlan_tx_timeout_work
1010 *
1011 * Returns: nothing
1012 *
1013 * Params:
1014 * work work item of device which timed out
1015 *
1016 **************************************************************/
David Howellsc4028952006-11-22 14:57:56 +00001017
Sakari Ailusc659c382011-01-21 10:59:30 +00001018static void tlan_tx_timeout_work(struct work_struct *work)
David Howellsc4028952006-11-22 14:57:56 +00001019{
Sakari Ailusc659c382011-01-21 10:59:30 +00001020 struct tlan_priv *priv =
1021 container_of(work, struct tlan_priv, tlan_tqueue);
David Howellsc4028952006-11-22 14:57:56 +00001022
Sakari Ailusc659c382011-01-21 10:59:30 +00001023 tlan_tx_timeout(priv->dev);
David Howellsc4028952006-11-22 14:57:56 +00001024}
1025
1026
Linus Torvalds1da177e2005-04-16 15:20:36 -07001027
Sakari Ailusc659c382011-01-21 10:59:30 +00001028/***************************************************************
1029 * tlan_start_tx
1030 *
1031 * Returns:
1032 * 0 on success, non-zero on failure.
1033 * Parms:
1034 * skb A pointer to the sk_buff containing the
1035 * frame to be sent.
1036 * dev The device to send the data on.
1037 *
1038 * This function adds a frame to the Tx list to be sent
1039 * ASAP. First it verifies that the adapter is ready and
1040 * there is room in the queue. Then it sets up the next
1041 * available list, copies the frame to the corresponding
1042 * buffer. If the adapter Tx channel is idle, it gives
1043 * the adapter a Tx Go command on the list, otherwise it
1044 * sets the forward address of the previous list to point
1045 * to this one. Then it frees the sk_buff.
1046 *
1047 **************************************************************/
Linus Torvalds1da177e2005-04-16 15:20:36 -07001048
Sakari Ailusc659c382011-01-21 10:59:30 +00001049static netdev_tx_t tlan_start_tx(struct sk_buff *skb, struct net_device *dev)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001050{
Sakari Ailusc659c382011-01-21 10:59:30 +00001051 struct tlan_priv *priv = netdev_priv(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001052 dma_addr_t tail_list_phys;
Sakari Ailusc659c382011-01-21 10:59:30 +00001053 struct tlan_list *tail_list;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001054 unsigned long flags;
Sakari Ailus8953f122008-12-16 01:44:05 -08001055 unsigned int txlen;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001056
Sakari Ailusc659c382011-01-21 10:59:30 +00001057 if (!priv->phy_online) {
1058 TLAN_DBG(TLAN_DEBUG_TX, "TRANSMIT: %s PHY is not ready\n",
1059 dev->name);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001060 dev_kfree_skb_any(skb);
Patrick McHardy6ed10652009-06-23 06:03:08 +00001061 return NETDEV_TX_OK;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001062 }
1063
Stephen Hemminger41873e92008-05-30 09:49:52 -07001064 if (skb_padto(skb, TLAN_MIN_FRAME_SIZE))
Patrick McHardy6ed10652009-06-23 06:03:08 +00001065 return NETDEV_TX_OK;
Sakari Ailus8953f122008-12-16 01:44:05 -08001066 txlen = max(skb->len, (unsigned int)TLAN_MIN_FRAME_SIZE);
Stephen Hemminger41873e92008-05-30 09:49:52 -07001067
Sakari Ailusc659c382011-01-21 10:59:30 +00001068 tail_list = priv->tx_list + priv->tx_tail;
1069 tail_list_phys =
1070 priv->tx_list_dma + sizeof(struct tlan_list)*priv->tx_tail;
Jeff Garzik6aa20a22006-09-13 13:24:59 -04001071
Sakari Ailusc659c382011-01-21 10:59:30 +00001072 if (tail_list->c_stat != TLAN_CSTAT_UNUSED) {
1073 TLAN_DBG(TLAN_DEBUG_TX,
1074 "TRANSMIT: %s is busy (Head=%d Tail=%d)\n",
1075 dev->name, priv->tx_head, priv->tx_tail);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001076 netif_stop_queue(dev);
Sakari Ailusc659c382011-01-21 10:59:30 +00001077 priv->tx_busy_count++;
Patrick McHardy5b548142009-06-12 06:22:29 +00001078 return NETDEV_TX_BUSY;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001079 }
1080
1081 tail_list->forward = 0;
1082
Sakari Ailusc659c382011-01-21 10:59:30 +00001083 tail_list->buffer[0].address = pci_map_single(priv->pci_dev,
Sakari Ailus5eeabf52008-12-16 15:24:05 -08001084 skb->data, txlen,
1085 PCI_DMA_TODEVICE);
Sakari Ailusc659c382011-01-21 10:59:30 +00001086 tlan_store_skb(tail_list, skb);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001087
Sakari Ailusc659c382011-01-21 10:59:30 +00001088 tail_list->frame_size = (u16) txlen;
Sakari Ailus8953f122008-12-16 01:44:05 -08001089 tail_list->buffer[0].count = TLAN_LAST_BUFFER | (u32) txlen;
Stephen Hemminger41873e92008-05-30 09:49:52 -07001090 tail_list->buffer[1].count = 0;
1091 tail_list->buffer[1].address = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001092
1093 spin_lock_irqsave(&priv->lock, flags);
Sakari Ailusc659c382011-01-21 10:59:30 +00001094 tail_list->c_stat = TLAN_CSTAT_READY;
1095 if (!priv->tx_in_progress) {
1096 priv->tx_in_progress = 1;
1097 TLAN_DBG(TLAN_DEBUG_TX,
1098 "TRANSMIT: Starting TX on buffer %d\n",
1099 priv->tx_tail);
1100 outl(tail_list_phys, dev->base_addr + TLAN_CH_PARM);
1101 outl(TLAN_HC_GO, dev->base_addr + TLAN_HOST_CMD);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001102 } else {
Sakari Ailusc659c382011-01-21 10:59:30 +00001103 TLAN_DBG(TLAN_DEBUG_TX,
1104 "TRANSMIT: Adding buffer %d to TX channel\n",
1105 priv->tx_tail);
1106 if (priv->tx_tail == 0) {
1107 (priv->tx_list + (TLAN_NUM_TX_LISTS - 1))->forward
Stephen Hemmingerdfc2c0a2008-05-30 09:49:58 -07001108 = tail_list_phys;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001109 } else {
Sakari Ailusc659c382011-01-21 10:59:30 +00001110 (priv->tx_list + (priv->tx_tail - 1))->forward
Stephen Hemmingerdfc2c0a2008-05-30 09:49:58 -07001111 = tail_list_phys;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001112 }
1113 }
1114 spin_unlock_irqrestore(&priv->lock, flags);
1115
Sakari Ailusc659c382011-01-21 10:59:30 +00001116 CIRC_INC(priv->tx_tail, TLAN_NUM_TX_LISTS);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001117
Patrick McHardy6ed10652009-06-23 06:03:08 +00001118 return NETDEV_TX_OK;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001119
Sakari Ailusc659c382011-01-21 10:59:30 +00001120}
Linus Torvalds1da177e2005-04-16 15:20:36 -07001121
1122
1123
1124
Sakari Ailusc659c382011-01-21 10:59:30 +00001125/***************************************************************
1126 * tlan_handle_interrupt
1127 *
1128 * Returns:
1129 * Nothing
1130 * Parms:
1131 * irq The line on which the interrupt
1132 * occurred.
1133 * dev_id A pointer to the device assigned to
1134 * this irq line.
1135 *
1136 * This function handles an interrupt generated by its
1137 * assigned TLAN adapter. The function deactivates
1138 * interrupts on its adapter, records the type of
1139 * interrupt, executes the appropriate subhandler, and
1140 * acknowdges the interrupt to the adapter (thus
1141 * re-enabling adapter interrupts.
1142 *
1143 **************************************************************/
Linus Torvalds1da177e2005-04-16 15:20:36 -07001144
Sakari Ailusc659c382011-01-21 10:59:30 +00001145static irqreturn_t tlan_handle_interrupt(int irq, void *dev_id)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001146{
Stephen Hemmingera3ccc782008-05-30 09:49:57 -07001147 struct net_device *dev = dev_id;
Sakari Ailusc659c382011-01-21 10:59:30 +00001148 struct tlan_priv *priv = netdev_priv(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001149 u16 host_int;
Stephen Hemmingera3ccc782008-05-30 09:49:57 -07001150 u16 type;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001151
1152 spin_lock(&priv->lock);
1153
Sakari Ailusc659c382011-01-21 10:59:30 +00001154 host_int = inw(dev->base_addr + TLAN_HOST_INT);
1155 type = (host_int & TLAN_HI_IT_MASK) >> 2;
1156 if (type) {
Stephen Hemmingera3ccc782008-05-30 09:49:57 -07001157 u32 ack;
1158 u32 host_cmd;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001159
Sakari Ailusc659c382011-01-21 10:59:30 +00001160 outw(host_int, dev->base_addr + TLAN_HOST_INT);
1161 ack = tlan_int_vector[type](dev, host_int);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001162
Sakari Ailusc659c382011-01-21 10:59:30 +00001163 if (ack) {
1164 host_cmd = TLAN_HC_ACK | ack | (type << 18);
1165 outl(host_cmd, dev->base_addr + TLAN_HOST_CMD);
Stephen Hemmingera3ccc782008-05-30 09:49:57 -07001166 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001167 }
1168
1169 spin_unlock(&priv->lock);
1170
Stephen Hemmingera3ccc782008-05-30 09:49:57 -07001171 return IRQ_RETVAL(type);
Sakari Ailusc659c382011-01-21 10:59:30 +00001172}
Linus Torvalds1da177e2005-04-16 15:20:36 -07001173
1174
1175
1176
Sakari Ailusc659c382011-01-21 10:59:30 +00001177/***************************************************************
1178 * tlan_close
1179 *
1180 * Returns:
1181 * An error code.
1182 * Parms:
1183 * dev The device structure of the device to
1184 * close.
1185 *
1186 * This function shuts down the adapter. It records any
1187 * stats, puts the adapter into reset state, deactivates
1188 * its time as needed, and frees the irq it is using.
1189 *
1190 **************************************************************/
Linus Torvalds1da177e2005-04-16 15:20:36 -07001191
Sakari Ailusc659c382011-01-21 10:59:30 +00001192static int tlan_close(struct net_device *dev)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001193{
Sakari Ailusc659c382011-01-21 10:59:30 +00001194 struct tlan_priv *priv = netdev_priv(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001195
Linus Torvalds1da177e2005-04-16 15:20:36 -07001196 priv->neg_be_verbose = 0;
Sakari Ailusfa6d5d42011-01-21 10:59:31 +00001197 tlan_stop(dev);
Jeff Garzik6aa20a22006-09-13 13:24:59 -04001198
Sakari Ailusc659c382011-01-21 10:59:30 +00001199 free_irq(dev->irq, dev);
1200 tlan_free_lists(dev);
1201 TLAN_DBG(TLAN_DEBUG_GNRL, "Device %s closed.\n", dev->name);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001202
1203 return 0;
1204
Sakari Ailusc659c382011-01-21 10:59:30 +00001205}
Linus Torvalds1da177e2005-04-16 15:20:36 -07001206
1207
1208
1209
Sakari Ailusc659c382011-01-21 10:59:30 +00001210/***************************************************************
1211 * tlan_get_stats
1212 *
1213 * Returns:
1214 * A pointer to the device's statistics structure.
1215 * Parms:
1216 * dev The device structure to return the
1217 * stats for.
1218 *
1219 * This function updates the devices statistics by reading
1220 * the TLAN chip's onboard registers. Then it returns the
1221 * address of the statistics structure.
1222 *
1223 **************************************************************/
Linus Torvalds1da177e2005-04-16 15:20:36 -07001224
Sakari Ailusc659c382011-01-21 10:59:30 +00001225static struct net_device_stats *tlan_get_stats(struct net_device *dev)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001226{
Sakari Ailusc659c382011-01-21 10:59:30 +00001227 struct tlan_priv *priv = netdev_priv(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001228 int i;
1229
1230 /* Should only read stats if open ? */
Sakari Ailusc659c382011-01-21 10:59:30 +00001231 tlan_read_and_clear_stats(dev, TLAN_RECORD);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001232
Sakari Ailusc659c382011-01-21 10:59:30 +00001233 TLAN_DBG(TLAN_DEBUG_RX, "RECEIVE: %s EOC count = %d\n", dev->name,
1234 priv->rx_eoc_count);
1235 TLAN_DBG(TLAN_DEBUG_TX, "TRANSMIT: %s Busy count = %d\n", dev->name,
1236 priv->tx_busy_count);
1237 if (debug & TLAN_DEBUG_GNRL) {
1238 tlan_print_dio(dev->base_addr);
1239 tlan_phy_print(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001240 }
Sakari Ailusc659c382011-01-21 10:59:30 +00001241 if (debug & TLAN_DEBUG_LIST) {
1242 for (i = 0; i < TLAN_NUM_RX_LISTS; i++)
1243 tlan_print_list(priv->rx_list + i, "RX", i);
1244 for (i = 0; i < TLAN_NUM_TX_LISTS; i++)
1245 tlan_print_list(priv->tx_list + i, "TX", i);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001246 }
Jeff Garzik6aa20a22006-09-13 13:24:59 -04001247
Stephen Hemmingerf8f31542008-05-30 09:49:53 -07001248 return &dev->stats;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001249
Sakari Ailusc659c382011-01-21 10:59:30 +00001250}
Linus Torvalds1da177e2005-04-16 15:20:36 -07001251
1252
1253
1254
Sakari Ailusc659c382011-01-21 10:59:30 +00001255/***************************************************************
1256 * tlan_set_multicast_list
1257 *
1258 * Returns:
1259 * Nothing
1260 * Parms:
1261 * dev The device structure to set the
1262 * multicast list for.
1263 *
1264 * This function sets the TLAN adaptor to various receive
1265 * modes. If the IFF_PROMISC flag is set, promiscuous
1266 * mode is acitviated. Otherwise, promiscuous mode is
1267 * turned off. If the IFF_ALLMULTI flag is set, then
1268 * the hash table is set to receive all group addresses.
1269 * Otherwise, the first three multicast addresses are
1270 * stored in AREG_1-3, and the rest are selected via the
1271 * hash table, as necessary.
1272 *
1273 **************************************************************/
Linus Torvalds1da177e2005-04-16 15:20:36 -07001274
Sakari Ailusc659c382011-01-21 10:59:30 +00001275static void tlan_set_multicast_list(struct net_device *dev)
Jeff Garzik6aa20a22006-09-13 13:24:59 -04001276{
Jiri Pirko22bedad32010-04-01 21:22:57 +00001277 struct netdev_hw_addr *ha;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001278 u32 hash1 = 0;
1279 u32 hash2 = 0;
1280 int i;
1281 u32 offset;
1282 u8 tmp;
1283
Sakari Ailusc659c382011-01-21 10:59:30 +00001284 if (dev->flags & IFF_PROMISC) {
1285 tmp = tlan_dio_read8(dev->base_addr, TLAN_NET_CMD);
1286 tlan_dio_write8(dev->base_addr,
1287 TLAN_NET_CMD, tmp | TLAN_NET_CMD_CAF);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001288 } else {
Sakari Ailusc659c382011-01-21 10:59:30 +00001289 tmp = tlan_dio_read8(dev->base_addr, TLAN_NET_CMD);
1290 tlan_dio_write8(dev->base_addr,
1291 TLAN_NET_CMD, tmp & ~TLAN_NET_CMD_CAF);
1292 if (dev->flags & IFF_ALLMULTI) {
1293 for (i = 0; i < 3; i++)
1294 tlan_set_mac(dev, i + 1, NULL);
1295 tlan_dio_write32(dev->base_addr, TLAN_HASH_1,
1296 0xffffffff);
1297 tlan_dio_write32(dev->base_addr, TLAN_HASH_2,
1298 0xffffffff);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001299 } else {
Jiri Pirko567ec872010-02-23 23:17:07 +00001300 i = 0;
Jiri Pirko22bedad32010-04-01 21:22:57 +00001301 netdev_for_each_mc_addr(ha, dev) {
Sakari Ailusc659c382011-01-21 10:59:30 +00001302 if (i < 3) {
1303 tlan_set_mac(dev, i + 1,
Jiri Pirko22bedad32010-04-01 21:22:57 +00001304 (char *) &ha->addr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001305 } else {
Sakari Ailusc659c382011-01-21 10:59:30 +00001306 offset =
1307 tlan_hash_func((u8 *)&ha->addr);
1308 if (offset < 32)
1309 hash1 |= (1 << offset);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001310 else
Sakari Ailusc659c382011-01-21 10:59:30 +00001311 hash2 |= (1 << (offset - 32));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001312 }
Jiri Pirko567ec872010-02-23 23:17:07 +00001313 i++;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001314 }
Sakari Ailusc659c382011-01-21 10:59:30 +00001315 for ( ; i < 3; i++)
1316 tlan_set_mac(dev, i + 1, NULL);
1317 tlan_dio_write32(dev->base_addr, TLAN_HASH_1, hash1);
1318 tlan_dio_write32(dev->base_addr, TLAN_HASH_2, hash2);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001319 }
1320 }
1321
Sakari Ailusc659c382011-01-21 10:59:30 +00001322}
Linus Torvalds1da177e2005-04-16 15:20:36 -07001323
1324
1325
1326/*****************************************************************************
1327******************************************************************************
1328
Sakari Ailusc659c382011-01-21 10:59:30 +00001329ThunderLAN driver interrupt vectors and table
Linus Torvalds1da177e2005-04-16 15:20:36 -07001330
Sakari Ailusc659c382011-01-21 10:59:30 +00001331please see chap. 4, "Interrupt Handling" of the "ThunderLAN
1332Programmer's Guide" for more informations on handling interrupts
1333generated by TLAN based adapters.
Linus Torvalds1da177e2005-04-16 15:20:36 -07001334
1335******************************************************************************
1336*****************************************************************************/
1337
1338
Linus Torvalds1da177e2005-04-16 15:20:36 -07001339
1340
Sakari Ailusc659c382011-01-21 10:59:30 +00001341/***************************************************************
1342 * tlan_handle_tx_eof
1343 *
1344 * Returns:
1345 * 1
1346 * Parms:
1347 * dev Device assigned the IRQ that was
1348 * raised.
1349 * host_int The contents of the HOST_INT
1350 * port.
1351 *
1352 * This function handles Tx EOF interrupts which are raised
1353 * by the adapter when it has completed sending the
1354 * contents of a buffer. If detemines which list/buffer
1355 * was completed and resets it. If the buffer was the last
1356 * in the channel (EOC), then the function checks to see if
1357 * another buffer is ready to send, and if so, sends a Tx
1358 * Go command. Finally, the driver activates/continues the
1359 * activity LED.
1360 *
1361 **************************************************************/
Linus Torvalds1da177e2005-04-16 15:20:36 -07001362
Sakari Ailusc659c382011-01-21 10:59:30 +00001363static u32 tlan_handle_tx_eof(struct net_device *dev, u16 host_int)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001364{
Sakari Ailusc659c382011-01-21 10:59:30 +00001365 struct tlan_priv *priv = netdev_priv(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001366 int eoc = 0;
Sakari Ailusc659c382011-01-21 10:59:30 +00001367 struct tlan_list *head_list;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001368 dma_addr_t head_list_phys;
1369 u32 ack = 0;
Sakari Ailusc659c382011-01-21 10:59:30 +00001370 u16 tmp_c_stat;
Jeff Garzik6aa20a22006-09-13 13:24:59 -04001371
Sakari Ailusc659c382011-01-21 10:59:30 +00001372 TLAN_DBG(TLAN_DEBUG_TX,
1373 "TRANSMIT: Handling TX EOF (Head=%d Tail=%d)\n",
1374 priv->tx_head, priv->tx_tail);
1375 head_list = priv->tx_list + priv->tx_head;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001376
Sakari Ailusc659c382011-01-21 10:59:30 +00001377 while (((tmp_c_stat = head_list->c_stat) & TLAN_CSTAT_FRM_CMP)
1378 && (ack < 255)) {
1379 struct sk_buff *skb = tlan_get_skb(head_list);
Sakari Ailus5eeabf52008-12-16 15:24:05 -08001380
Linus Torvalds1da177e2005-04-16 15:20:36 -07001381 ack++;
Sakari Ailusc659c382011-01-21 10:59:30 +00001382 pci_unmap_single(priv->pci_dev, head_list->buffer[0].address,
Sakari Ailus5eeabf52008-12-16 15:24:05 -08001383 max(skb->len,
1384 (unsigned int)TLAN_MIN_FRAME_SIZE),
1385 PCI_DMA_TODEVICE);
1386 dev_kfree_skb_any(skb);
1387 head_list->buffer[8].address = 0;
1388 head_list->buffer[9].address = 0;
Jeff Garzik6aa20a22006-09-13 13:24:59 -04001389
Sakari Ailusc659c382011-01-21 10:59:30 +00001390 if (tmp_c_stat & TLAN_CSTAT_EOC)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001391 eoc = 1;
Jeff Garzik6aa20a22006-09-13 13:24:59 -04001392
Sakari Ailusc659c382011-01-21 10:59:30 +00001393 dev->stats.tx_bytes += head_list->frame_size;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001394
Sakari Ailusc659c382011-01-21 10:59:30 +00001395 head_list->c_stat = TLAN_CSTAT_UNUSED;
Jeff Garzik6aa20a22006-09-13 13:24:59 -04001396 netif_start_queue(dev);
Sakari Ailusc659c382011-01-21 10:59:30 +00001397 CIRC_INC(priv->tx_head, TLAN_NUM_TX_LISTS);
1398 head_list = priv->tx_list + priv->tx_head;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001399 }
1400
1401 if (!ack)
Joe Perches50624aa2011-03-01 06:56:33 +00001402 netdev_info(dev,
1403 "Received interrupt for uncompleted TX frame\n");
Jeff Garzik6aa20a22006-09-13 13:24:59 -04001404
Sakari Ailusc659c382011-01-21 10:59:30 +00001405 if (eoc) {
1406 TLAN_DBG(TLAN_DEBUG_TX,
1407 "TRANSMIT: handling TX EOC (Head=%d Tail=%d)\n",
1408 priv->tx_head, priv->tx_tail);
1409 head_list = priv->tx_list + priv->tx_head;
1410 head_list_phys = priv->tx_list_dma
1411 + sizeof(struct tlan_list)*priv->tx_head;
Sakari Ailusf45437e2011-02-09 10:25:06 +00001412 if ((head_list->c_stat & TLAN_CSTAT_READY)
1413 == TLAN_CSTAT_READY) {
Sakari Ailusc659c382011-01-21 10:59:30 +00001414 outl(head_list_phys, dev->base_addr + TLAN_CH_PARM);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001415 ack |= TLAN_HC_GO;
1416 } else {
Sakari Ailusc659c382011-01-21 10:59:30 +00001417 priv->tx_in_progress = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001418 }
1419 }
Jeff Garzik6aa20a22006-09-13 13:24:59 -04001420
Sakari Ailusc659c382011-01-21 10:59:30 +00001421 if (priv->adapter->flags & TLAN_ADAPTER_ACTIVITY_LED) {
1422 tlan_dio_write8(dev->base_addr,
1423 TLAN_LED_REG, TLAN_LED_LINK | TLAN_LED_ACT);
1424 if (priv->timer.function == NULL) {
1425 priv->timer.function = tlan_timer;
1426 priv->timer.data = (unsigned long) dev;
1427 priv->timer.expires = jiffies + TLAN_TIMER_ACT_DELAY;
1428 priv->timer_set_at = jiffies;
1429 priv->timer_type = TLAN_TIMER_ACTIVITY;
1430 add_timer(&priv->timer);
1431 } else if (priv->timer_type == TLAN_TIMER_ACTIVITY) {
1432 priv->timer_set_at = jiffies;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001433 }
1434 }
1435
1436 return ack;
1437
Sakari Ailusc659c382011-01-21 10:59:30 +00001438}
Linus Torvalds1da177e2005-04-16 15:20:36 -07001439
1440
1441
1442
Sakari Ailusc659c382011-01-21 10:59:30 +00001443/***************************************************************
1444 * TLan_HandleStatOverflow
1445 *
1446 * Returns:
1447 * 1
1448 * Parms:
1449 * dev Device assigned the IRQ that was
1450 * raised.
1451 * host_int The contents of the HOST_INT
1452 * port.
1453 *
1454 * This function handles the Statistics Overflow interrupt
1455 * which means that one or more of the TLAN statistics
1456 * registers has reached 1/2 capacity and needs to be read.
1457 *
1458 **************************************************************/
Linus Torvalds1da177e2005-04-16 15:20:36 -07001459
Sakari Ailusc659c382011-01-21 10:59:30 +00001460static u32 tlan_handle_stat_overflow(struct net_device *dev, u16 host_int)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001461{
Sakari Ailusc659c382011-01-21 10:59:30 +00001462 tlan_read_and_clear_stats(dev, TLAN_RECORD);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001463
1464 return 1;
1465
Sakari Ailusc659c382011-01-21 10:59:30 +00001466}
Linus Torvalds1da177e2005-04-16 15:20:36 -07001467
1468
1469
1470
Sakari Ailusc659c382011-01-21 10:59:30 +00001471/***************************************************************
1472 * TLan_HandleRxEOF
1473 *
1474 * Returns:
1475 * 1
1476 * Parms:
1477 * dev Device assigned the IRQ that was
1478 * raised.
1479 * host_int The contents of the HOST_INT
1480 * port.
1481 *
1482 * This function handles the Rx EOF interrupt which
1483 * indicates a frame has been received by the adapter from
1484 * the net and the frame has been transferred to memory.
1485 * The function determines the bounce buffer the frame has
1486 * been loaded into, creates a new sk_buff big enough to
1487 * hold the frame, and sends it to protocol stack. It
1488 * then resets the used buffer and appends it to the end
1489 * of the list. If the frame was the last in the Rx
1490 * channel (EOC), the function restarts the receive channel
1491 * by sending an Rx Go command to the adapter. Then it
1492 * activates/continues the activity LED.
1493 *
1494 **************************************************************/
Linus Torvalds1da177e2005-04-16 15:20:36 -07001495
Sakari Ailusc659c382011-01-21 10:59:30 +00001496static u32 tlan_handle_rx_eof(struct net_device *dev, u16 host_int)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001497{
Sakari Ailusc659c382011-01-21 10:59:30 +00001498 struct tlan_priv *priv = netdev_priv(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001499 u32 ack = 0;
1500 int eoc = 0;
Sakari Ailusc659c382011-01-21 10:59:30 +00001501 struct tlan_list *head_list;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001502 struct sk_buff *skb;
Sakari Ailusc659c382011-01-21 10:59:30 +00001503 struct tlan_list *tail_list;
1504 u16 tmp_c_stat;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001505 dma_addr_t head_list_phys;
1506
Sakari Ailusc659c382011-01-21 10:59:30 +00001507 TLAN_DBG(TLAN_DEBUG_RX, "RECEIVE: handling RX EOF (Head=%d Tail=%d)\n",
1508 priv->rx_head, priv->rx_tail);
1509 head_list = priv->rx_list + priv->rx_head;
1510 head_list_phys =
1511 priv->rx_list_dma + sizeof(struct tlan_list)*priv->rx_head;
Jeff Garzik6aa20a22006-09-13 13:24:59 -04001512
Sakari Ailusc659c382011-01-21 10:59:30 +00001513 while (((tmp_c_stat = head_list->c_stat) & TLAN_CSTAT_FRM_CMP)
1514 && (ack < 255)) {
1515 dma_addr_t frame_dma = head_list->buffer[0].address;
1516 u32 frame_size = head_list->frame_size;
Sakari Ailus5eeabf52008-12-16 15:24:05 -08001517 struct sk_buff *new_skb;
1518
Linus Torvalds1da177e2005-04-16 15:20:36 -07001519 ack++;
Sakari Ailusc659c382011-01-21 10:59:30 +00001520 if (tmp_c_stat & TLAN_CSTAT_EOC)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001521 eoc = 1;
Jeff Garzik6aa20a22006-09-13 13:24:59 -04001522
Eric Dumazet89d71a62009-10-13 05:34:20 +00001523 new_skb = netdev_alloc_skb_ip_align(dev,
1524 TLAN_MAX_FRAME_SIZE + 5);
Sakari Ailusc659c382011-01-21 10:59:30 +00001525 if (!new_skb)
Sakari Ailus5eeabf52008-12-16 15:24:05 -08001526 goto drop_and_reuse;
Jeff Garzik6aa20a22006-09-13 13:24:59 -04001527
Sakari Ailusc659c382011-01-21 10:59:30 +00001528 skb = tlan_get_skb(head_list);
1529 pci_unmap_single(priv->pci_dev, frame_dma,
Sakari Ailus5eeabf52008-12-16 15:24:05 -08001530 TLAN_MAX_FRAME_SIZE, PCI_DMA_FROMDEVICE);
Sakari Ailusc659c382011-01-21 10:59:30 +00001531 skb_put(skb, frame_size);
Stephen Hemmingerdfc2c0a2008-05-30 09:49:58 -07001532
Sakari Ailusc659c382011-01-21 10:59:30 +00001533 dev->stats.rx_bytes += frame_size;
Jeff Garzik6aa20a22006-09-13 13:24:59 -04001534
Sakari Ailusc659c382011-01-21 10:59:30 +00001535 skb->protocol = eth_type_trans(skb, dev);
1536 netif_rx(skb);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001537
Sakari Ailusc659c382011-01-21 10:59:30 +00001538 head_list->buffer[0].address =
1539 pci_map_single(priv->pci_dev, new_skb->data,
1540 TLAN_MAX_FRAME_SIZE, PCI_DMA_FROMDEVICE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001541
Sakari Ailusc659c382011-01-21 10:59:30 +00001542 tlan_store_skb(head_list, new_skb);
Stephen Hemmingerdfc2c0a2008-05-30 09:49:58 -07001543drop_and_reuse:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001544 head_list->forward = 0;
Sakari Ailusc659c382011-01-21 10:59:30 +00001545 head_list->c_stat = 0;
1546 tail_list = priv->rx_list + priv->rx_tail;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001547 tail_list->forward = head_list_phys;
1548
Sakari Ailusc659c382011-01-21 10:59:30 +00001549 CIRC_INC(priv->rx_head, TLAN_NUM_RX_LISTS);
1550 CIRC_INC(priv->rx_tail, TLAN_NUM_RX_LISTS);
1551 head_list = priv->rx_list + priv->rx_head;
1552 head_list_phys = priv->rx_list_dma
1553 + sizeof(struct tlan_list)*priv->rx_head;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001554 }
1555
1556 if (!ack)
Joe Perches50624aa2011-03-01 06:56:33 +00001557 netdev_info(dev,
1558 "Received interrupt for uncompleted RX frame\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001559
1560
Sakari Ailusc659c382011-01-21 10:59:30 +00001561 if (eoc) {
1562 TLAN_DBG(TLAN_DEBUG_RX,
1563 "RECEIVE: handling RX EOC (Head=%d Tail=%d)\n",
1564 priv->rx_head, priv->rx_tail);
1565 head_list = priv->rx_list + priv->rx_head;
1566 head_list_phys = priv->rx_list_dma
1567 + sizeof(struct tlan_list)*priv->rx_head;
1568 outl(head_list_phys, dev->base_addr + TLAN_CH_PARM);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001569 ack |= TLAN_HC_GO | TLAN_HC_RT;
Sakari Ailusc659c382011-01-21 10:59:30 +00001570 priv->rx_eoc_count++;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001571 }
1572
Sakari Ailusc659c382011-01-21 10:59:30 +00001573 if (priv->adapter->flags & TLAN_ADAPTER_ACTIVITY_LED) {
1574 tlan_dio_write8(dev->base_addr,
1575 TLAN_LED_REG, TLAN_LED_LINK | TLAN_LED_ACT);
1576 if (priv->timer.function == NULL) {
1577 priv->timer.function = tlan_timer;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001578 priv->timer.data = (unsigned long) dev;
1579 priv->timer.expires = jiffies + TLAN_TIMER_ACT_DELAY;
Sakari Ailusc659c382011-01-21 10:59:30 +00001580 priv->timer_set_at = jiffies;
1581 priv->timer_type = TLAN_TIMER_ACTIVITY;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001582 add_timer(&priv->timer);
Sakari Ailusc659c382011-01-21 10:59:30 +00001583 } else if (priv->timer_type == TLAN_TIMER_ACTIVITY) {
1584 priv->timer_set_at = jiffies;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001585 }
1586 }
1587
Linus Torvalds1da177e2005-04-16 15:20:36 -07001588 return ack;
1589
Sakari Ailusc659c382011-01-21 10:59:30 +00001590}
Linus Torvalds1da177e2005-04-16 15:20:36 -07001591
1592
1593
1594
Sakari Ailusc659c382011-01-21 10:59:30 +00001595/***************************************************************
1596 * tlan_handle_dummy
1597 *
1598 * Returns:
1599 * 1
1600 * Parms:
1601 * dev Device assigned the IRQ that was
1602 * raised.
1603 * host_int The contents of the HOST_INT
1604 * port.
1605 *
1606 * This function handles the Dummy interrupt, which is
1607 * raised whenever a test interrupt is generated by setting
1608 * the Req_Int bit of HOST_CMD to 1.
1609 *
1610 **************************************************************/
Linus Torvalds1da177e2005-04-16 15:20:36 -07001611
Sakari Ailusc659c382011-01-21 10:59:30 +00001612static u32 tlan_handle_dummy(struct net_device *dev, u16 host_int)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001613{
Joe Perches50624aa2011-03-01 06:56:33 +00001614 netdev_info(dev, "Test interrupt\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001615 return 1;
1616
Sakari Ailusc659c382011-01-21 10:59:30 +00001617}
Linus Torvalds1da177e2005-04-16 15:20:36 -07001618
1619
1620
1621
Sakari Ailusc659c382011-01-21 10:59:30 +00001622/***************************************************************
1623 * tlan_handle_tx_eoc
1624 *
1625 * Returns:
1626 * 1
1627 * Parms:
1628 * dev Device assigned the IRQ that was
1629 * raised.
1630 * host_int The contents of the HOST_INT
1631 * port.
1632 *
1633 * This driver is structured to determine EOC occurrences by
1634 * reading the CSTAT member of the list structure. Tx EOC
1635 * interrupts are disabled via the DIO INTDIS register.
1636 * However, TLAN chips before revision 3.0 didn't have this
1637 * functionality, so process EOC events if this is the
1638 * case.
1639 *
1640 **************************************************************/
Linus Torvalds1da177e2005-04-16 15:20:36 -07001641
Sakari Ailusc659c382011-01-21 10:59:30 +00001642static u32 tlan_handle_tx_eoc(struct net_device *dev, u16 host_int)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001643{
Sakari Ailusc659c382011-01-21 10:59:30 +00001644 struct tlan_priv *priv = netdev_priv(dev);
1645 struct tlan_list *head_list;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001646 dma_addr_t head_list_phys;
1647 u32 ack = 1;
Jeff Garzik6aa20a22006-09-13 13:24:59 -04001648
Linus Torvalds1da177e2005-04-16 15:20:36 -07001649 host_int = 0;
Sakari Ailusc659c382011-01-21 10:59:30 +00001650 if (priv->tlan_rev < 0x30) {
1651 TLAN_DBG(TLAN_DEBUG_TX,
1652 "TRANSMIT: handling TX EOC (Head=%d Tail=%d) -- IRQ\n",
1653 priv->tx_head, priv->tx_tail);
1654 head_list = priv->tx_list + priv->tx_head;
1655 head_list_phys = priv->tx_list_dma
1656 + sizeof(struct tlan_list)*priv->tx_head;
Sakari Ailusf45437e2011-02-09 10:25:06 +00001657 if ((head_list->c_stat & TLAN_CSTAT_READY)
1658 == TLAN_CSTAT_READY) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001659 netif_stop_queue(dev);
Sakari Ailusc659c382011-01-21 10:59:30 +00001660 outl(head_list_phys, dev->base_addr + TLAN_CH_PARM);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001661 ack |= TLAN_HC_GO;
1662 } else {
Sakari Ailusc659c382011-01-21 10:59:30 +00001663 priv->tx_in_progress = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001664 }
1665 }
1666
1667 return ack;
1668
Sakari Ailusc659c382011-01-21 10:59:30 +00001669}
Linus Torvalds1da177e2005-04-16 15:20:36 -07001670
1671
1672
1673
Sakari Ailusc659c382011-01-21 10:59:30 +00001674/***************************************************************
1675 * tlan_handle_status_check
1676 *
1677 * Returns:
1678 * 0 if Adapter check, 1 if Network Status check.
1679 * Parms:
1680 * dev Device assigned the IRQ that was
1681 * raised.
1682 * host_int The contents of the HOST_INT
1683 * port.
1684 *
1685 * This function handles Adapter Check/Network Status
1686 * interrupts generated by the adapter. It checks the
1687 * vector in the HOST_INT register to determine if it is
1688 * an Adapter Check interrupt. If so, it resets the
1689 * adapter. Otherwise it clears the status registers
1690 * and services the PHY.
1691 *
1692 **************************************************************/
Linus Torvalds1da177e2005-04-16 15:20:36 -07001693
Sakari Ailusc659c382011-01-21 10:59:30 +00001694static u32 tlan_handle_status_check(struct net_device *dev, u16 host_int)
Jeff Garzik6aa20a22006-09-13 13:24:59 -04001695{
Sakari Ailusc659c382011-01-21 10:59:30 +00001696 struct tlan_priv *priv = netdev_priv(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001697 u32 ack;
1698 u32 error;
1699 u8 net_sts;
1700 u32 phy;
1701 u16 tlphy_ctl;
1702 u16 tlphy_sts;
Jeff Garzik6aa20a22006-09-13 13:24:59 -04001703
Linus Torvalds1da177e2005-04-16 15:20:36 -07001704 ack = 1;
Sakari Ailusc659c382011-01-21 10:59:30 +00001705 if (host_int & TLAN_HI_IV_MASK) {
1706 netif_stop_queue(dev);
1707 error = inl(dev->base_addr + TLAN_CH_PARM);
Joe Perches50624aa2011-03-01 06:56:33 +00001708 netdev_info(dev, "Adaptor Error = 0x%x\n", error);
Sakari Ailusc659c382011-01-21 10:59:30 +00001709 tlan_read_and_clear_stats(dev, TLAN_RECORD);
1710 outl(TLAN_HC_AD_RST, dev->base_addr + TLAN_HOST_CMD);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001711
1712 schedule_work(&priv->tlan_tqueue);
1713
1714 netif_wake_queue(dev);
1715 ack = 0;
1716 } else {
Sakari Ailusc659c382011-01-21 10:59:30 +00001717 TLAN_DBG(TLAN_DEBUG_GNRL, "%s: Status Check\n", dev->name);
1718 phy = priv->phy[priv->phy_num];
Linus Torvalds1da177e2005-04-16 15:20:36 -07001719
Sakari Ailusc659c382011-01-21 10:59:30 +00001720 net_sts = tlan_dio_read8(dev->base_addr, TLAN_NET_STS);
1721 if (net_sts) {
1722 tlan_dio_write8(dev->base_addr, TLAN_NET_STS, net_sts);
1723 TLAN_DBG(TLAN_DEBUG_GNRL, "%s: Net_Sts = %x\n",
1724 dev->name, (unsigned) net_sts);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001725 }
Sakari Ailusc659c382011-01-21 10:59:30 +00001726 if ((net_sts & TLAN_NET_STS_MIRQ) && (priv->phy_num == 0)) {
1727 tlan_mii_read_reg(dev, phy, TLAN_TLPHY_STS, &tlphy_sts);
1728 tlan_mii_read_reg(dev, phy, TLAN_TLPHY_CTL, &tlphy_ctl);
1729 if (!(tlphy_sts & TLAN_TS_POLOK) &&
1730 !(tlphy_ctl & TLAN_TC_SWAPOL)) {
1731 tlphy_ctl |= TLAN_TC_SWAPOL;
1732 tlan_mii_write_reg(dev, phy, TLAN_TLPHY_CTL,
1733 tlphy_ctl);
1734 } else if ((tlphy_sts & TLAN_TS_POLOK) &&
1735 (tlphy_ctl & TLAN_TC_SWAPOL)) {
1736 tlphy_ctl &= ~TLAN_TC_SWAPOL;
1737 tlan_mii_write_reg(dev, phy, TLAN_TLPHY_CTL,
1738 tlphy_ctl);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001739 }
Sakari Ailusc659c382011-01-21 10:59:30 +00001740
1741 if (debug)
1742 tlan_phy_print(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001743 }
1744 }
1745
1746 return ack;
1747
Sakari Ailusc659c382011-01-21 10:59:30 +00001748}
Linus Torvalds1da177e2005-04-16 15:20:36 -07001749
1750
1751
1752
Sakari Ailusc659c382011-01-21 10:59:30 +00001753/***************************************************************
1754 * tlan_handle_rx_eoc
1755 *
1756 * Returns:
1757 * 1
1758 * Parms:
1759 * dev Device assigned the IRQ that was
1760 * raised.
1761 * host_int The contents of the HOST_INT
1762 * port.
1763 *
1764 * This driver is structured to determine EOC occurrences by
1765 * reading the CSTAT member of the list structure. Rx EOC
1766 * interrupts are disabled via the DIO INTDIS register.
1767 * However, TLAN chips before revision 3.0 didn't have this
1768 * CSTAT member or a INTDIS register, so if this chip is
1769 * pre-3.0, process EOC interrupts normally.
1770 *
1771 **************************************************************/
Linus Torvalds1da177e2005-04-16 15:20:36 -07001772
Sakari Ailusc659c382011-01-21 10:59:30 +00001773static u32 tlan_handle_rx_eoc(struct net_device *dev, u16 host_int)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001774{
Sakari Ailusc659c382011-01-21 10:59:30 +00001775 struct tlan_priv *priv = netdev_priv(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001776 dma_addr_t head_list_phys;
1777 u32 ack = 1;
1778
Sakari Ailusc659c382011-01-21 10:59:30 +00001779 if (priv->tlan_rev < 0x30) {
1780 TLAN_DBG(TLAN_DEBUG_RX,
1781 "RECEIVE: Handling RX EOC (head=%d tail=%d) -- IRQ\n",
1782 priv->rx_head, priv->rx_tail);
1783 head_list_phys = priv->rx_list_dma
1784 + sizeof(struct tlan_list)*priv->rx_head;
1785 outl(head_list_phys, dev->base_addr + TLAN_CH_PARM);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001786 ack |= TLAN_HC_GO | TLAN_HC_RT;
Sakari Ailusc659c382011-01-21 10:59:30 +00001787 priv->rx_eoc_count++;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001788 }
1789
1790 return ack;
1791
Sakari Ailusc659c382011-01-21 10:59:30 +00001792}
Linus Torvalds1da177e2005-04-16 15:20:36 -07001793
1794
1795
1796
1797/*****************************************************************************
1798******************************************************************************
1799
Sakari Ailusc659c382011-01-21 10:59:30 +00001800ThunderLAN driver timer function
Linus Torvalds1da177e2005-04-16 15:20:36 -07001801
1802******************************************************************************
1803*****************************************************************************/
1804
1805
Sakari Ailusc659c382011-01-21 10:59:30 +00001806/***************************************************************
1807 * tlan_timer
1808 *
1809 * Returns:
1810 * Nothing
1811 * Parms:
1812 * data A value given to add timer when
1813 * add_timer was called.
1814 *
1815 * This function handles timed functionality for the
1816 * TLAN driver. The two current timer uses are for
1817 * delaying for autonegotionation and driving the ACT LED.
1818 * - Autonegotiation requires being allowed about
1819 * 2 1/2 seconds before attempting to transmit a
1820 * packet. It would be a very bad thing to hang
1821 * the kernel this long, so the driver doesn't
1822 * allow transmission 'til after this time, for
1823 * certain PHYs. It would be much nicer if all
1824 * PHYs were interrupt-capable like the internal
1825 * PHY.
1826 * - The ACT LED, which shows adapter activity, is
1827 * driven by the driver, and so must be left on
1828 * for a short period to power up the LED so it
1829 * can be seen. This delay can be changed by
1830 * changing the TLAN_TIMER_ACT_DELAY in tlan.h,
1831 * if desired. 100 ms produces a slightly
1832 * sluggish response.
1833 *
1834 **************************************************************/
Linus Torvalds1da177e2005-04-16 15:20:36 -07001835
Sakari Ailusc659c382011-01-21 10:59:30 +00001836static void tlan_timer(unsigned long data)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001837{
1838 struct net_device *dev = (struct net_device *) data;
Sakari Ailusc659c382011-01-21 10:59:30 +00001839 struct tlan_priv *priv = netdev_priv(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001840 u32 elapsed;
1841 unsigned long flags = 0;
1842
1843 priv->timer.function = NULL;
1844
Sakari Ailusc659c382011-01-21 10:59:30 +00001845 switch (priv->timer_type) {
Sakari Ailusc659c382011-01-21 10:59:30 +00001846 case TLAN_TIMER_PHY_PDOWN:
1847 tlan_phy_power_down(dev);
1848 break;
1849 case TLAN_TIMER_PHY_PUP:
1850 tlan_phy_power_up(dev);
1851 break;
1852 case TLAN_TIMER_PHY_RESET:
1853 tlan_phy_reset(dev);
1854 break;
1855 case TLAN_TIMER_PHY_START_LINK:
1856 tlan_phy_start_link(dev);
1857 break;
1858 case TLAN_TIMER_PHY_FINISH_AN:
1859 tlan_phy_finish_auto_neg(dev);
1860 break;
1861 case TLAN_TIMER_FINISH_RESET:
1862 tlan_finish_reset(dev);
1863 break;
1864 case TLAN_TIMER_ACTIVITY:
1865 spin_lock_irqsave(&priv->lock, flags);
1866 if (priv->timer.function == NULL) {
1867 elapsed = jiffies - priv->timer_set_at;
1868 if (elapsed >= TLAN_TIMER_ACT_DELAY) {
1869 tlan_dio_write8(dev->base_addr,
1870 TLAN_LED_REG, TLAN_LED_LINK);
1871 } else {
1872 priv->timer.function = tlan_timer;
1873 priv->timer.expires = priv->timer_set_at
1874 + TLAN_TIMER_ACT_DELAY;
1875 spin_unlock_irqrestore(&priv->lock, flags);
1876 add_timer(&priv->timer);
1877 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001878 }
Sakari Ailusc659c382011-01-21 10:59:30 +00001879 }
1880 spin_unlock_irqrestore(&priv->lock, flags);
1881 break;
1882 default:
1883 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001884 }
1885
Sakari Ailusc659c382011-01-21 10:59:30 +00001886}
Linus Torvalds1da177e2005-04-16 15:20:36 -07001887
1888
Linus Torvalds1da177e2005-04-16 15:20:36 -07001889/*****************************************************************************
1890******************************************************************************
1891
Sakari Ailusc659c382011-01-21 10:59:30 +00001892ThunderLAN driver adapter related routines
Linus Torvalds1da177e2005-04-16 15:20:36 -07001893
1894******************************************************************************
1895*****************************************************************************/
1896
1897
Sakari Ailusc659c382011-01-21 10:59:30 +00001898/***************************************************************
1899 * tlan_reset_lists
1900 *
1901 * Returns:
1902 * Nothing
1903 * Parms:
1904 * dev The device structure with the list
1905 * stuctures to be reset.
1906 *
1907 * This routine sets the variables associated with managing
1908 * the TLAN lists to their initial values.
1909 *
1910 **************************************************************/
Linus Torvalds1da177e2005-04-16 15:20:36 -07001911
Sakari Ailusc659c382011-01-21 10:59:30 +00001912static void tlan_reset_lists(struct net_device *dev)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001913{
Sakari Ailusc659c382011-01-21 10:59:30 +00001914 struct tlan_priv *priv = netdev_priv(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001915 int i;
Sakari Ailusc659c382011-01-21 10:59:30 +00001916 struct tlan_list *list;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001917 dma_addr_t list_phys;
1918 struct sk_buff *skb;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001919
Sakari Ailusc659c382011-01-21 10:59:30 +00001920 priv->tx_head = 0;
1921 priv->tx_tail = 0;
1922 for (i = 0; i < TLAN_NUM_TX_LISTS; i++) {
1923 list = priv->tx_list + i;
1924 list->c_stat = TLAN_CSTAT_UNUSED;
Sakari Ailus5eeabf52008-12-16 15:24:05 -08001925 list->buffer[0].address = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001926 list->buffer[2].count = 0;
1927 list->buffer[2].address = 0;
1928 list->buffer[8].address = 0;
1929 list->buffer[9].address = 0;
1930 }
1931
Sakari Ailusc659c382011-01-21 10:59:30 +00001932 priv->rx_head = 0;
1933 priv->rx_tail = TLAN_NUM_RX_LISTS - 1;
1934 for (i = 0; i < TLAN_NUM_RX_LISTS; i++) {
1935 list = priv->rx_list + i;
1936 list_phys = priv->rx_list_dma + sizeof(struct tlan_list)*i;
1937 list->c_stat = TLAN_CSTAT_READY;
1938 list->frame_size = TLAN_MAX_FRAME_SIZE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001939 list->buffer[0].count = TLAN_MAX_FRAME_SIZE | TLAN_LAST_BUFFER;
Eric Dumazet89d71a62009-10-13 05:34:20 +00001940 skb = netdev_alloc_skb_ip_align(dev, TLAN_MAX_FRAME_SIZE + 5);
Joe Perches720a43e2013-03-08 15:03:25 +00001941 if (!skb)
Sakari Ailus5eeabf52008-12-16 15:24:05 -08001942 break;
Sakari Ailus5eeabf52008-12-16 15:24:05 -08001943
Sakari Ailusc659c382011-01-21 10:59:30 +00001944 list->buffer[0].address = pci_map_single(priv->pci_dev,
Sakari Ailus5eeabf52008-12-16 15:24:05 -08001945 skb->data,
1946 TLAN_MAX_FRAME_SIZE,
1947 PCI_DMA_FROMDEVICE);
Sakari Ailusc659c382011-01-21 10:59:30 +00001948 tlan_store_skb(list, skb);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001949 list->buffer[1].count = 0;
1950 list->buffer[1].address = 0;
Sakari Ailusc659c382011-01-21 10:59:30 +00001951 list->forward = list_phys + sizeof(struct tlan_list);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001952 }
1953
Stephen Hemminger9ded65a2008-05-30 09:49:56 -07001954 /* in case ran out of memory early, clear bits */
1955 while (i < TLAN_NUM_RX_LISTS) {
Sakari Ailusc659c382011-01-21 10:59:30 +00001956 tlan_store_skb(priv->rx_list + i, NULL);
Stephen Hemminger9ded65a2008-05-30 09:49:56 -07001957 ++i;
1958 }
1959 list->forward = 0;
1960
Sakari Ailusc659c382011-01-21 10:59:30 +00001961}
Linus Torvalds1da177e2005-04-16 15:20:36 -07001962
1963
Sakari Ailusc659c382011-01-21 10:59:30 +00001964static void tlan_free_lists(struct net_device *dev)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001965{
Sakari Ailusc659c382011-01-21 10:59:30 +00001966 struct tlan_priv *priv = netdev_priv(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001967 int i;
Sakari Ailusc659c382011-01-21 10:59:30 +00001968 struct tlan_list *list;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001969 struct sk_buff *skb;
1970
Sakari Ailusc659c382011-01-21 10:59:30 +00001971 for (i = 0; i < TLAN_NUM_TX_LISTS; i++) {
1972 list = priv->tx_list + i;
1973 skb = tlan_get_skb(list);
1974 if (skb) {
Sakari Ailus5eeabf52008-12-16 15:24:05 -08001975 pci_unmap_single(
Sakari Ailusc659c382011-01-21 10:59:30 +00001976 priv->pci_dev,
Sakari Ailus5eeabf52008-12-16 15:24:05 -08001977 list->buffer[0].address,
1978 max(skb->len,
1979 (unsigned int)TLAN_MIN_FRAME_SIZE),
1980 PCI_DMA_TODEVICE);
Sakari Ailusc659c382011-01-21 10:59:30 +00001981 dev_kfree_skb_any(skb);
Sakari Ailus5eeabf52008-12-16 15:24:05 -08001982 list->buffer[8].address = 0;
1983 list->buffer[9].address = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001984 }
Sakari Ailus5eeabf52008-12-16 15:24:05 -08001985 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001986
Sakari Ailusc659c382011-01-21 10:59:30 +00001987 for (i = 0; i < TLAN_NUM_RX_LISTS; i++) {
1988 list = priv->rx_list + i;
1989 skb = tlan_get_skb(list);
1990 if (skb) {
1991 pci_unmap_single(priv->pci_dev,
Sakari Ailus5eeabf52008-12-16 15:24:05 -08001992 list->buffer[0].address,
1993 TLAN_MAX_FRAME_SIZE,
1994 PCI_DMA_FROMDEVICE);
Sakari Ailusc659c382011-01-21 10:59:30 +00001995 dev_kfree_skb_any(skb);
Sakari Ailus5eeabf52008-12-16 15:24:05 -08001996 list->buffer[8].address = 0;
1997 list->buffer[9].address = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001998 }
1999 }
Sakari Ailusc659c382011-01-21 10:59:30 +00002000}
Linus Torvalds1da177e2005-04-16 15:20:36 -07002001
2002
2003
2004
Sakari Ailusc659c382011-01-21 10:59:30 +00002005/***************************************************************
2006 * tlan_print_dio
2007 *
2008 * Returns:
2009 * Nothing
2010 * Parms:
2011 * io_base Base IO port of the device of
2012 * which to print DIO registers.
2013 *
2014 * This function prints out all the internal (DIO)
2015 * registers of a TLAN chip.
2016 *
2017 **************************************************************/
Linus Torvalds1da177e2005-04-16 15:20:36 -07002018
Sakari Ailusc659c382011-01-21 10:59:30 +00002019static void tlan_print_dio(u16 io_base)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002020{
2021 u32 data0, data1;
2022 int i;
2023
Joe Perches50624aa2011-03-01 06:56:33 +00002024 pr_info("Contents of internal registers for io base 0x%04hx\n",
2025 io_base);
2026 pr_info("Off. +0 +4\n");
Sakari Ailusc659c382011-01-21 10:59:30 +00002027 for (i = 0; i < 0x4C; i += 8) {
2028 data0 = tlan_dio_read32(io_base, i);
2029 data1 = tlan_dio_read32(io_base, i + 0x4);
Joe Perches50624aa2011-03-01 06:56:33 +00002030 pr_info("0x%02x 0x%08x 0x%08x\n", i, data0, data1);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002031 }
2032
Sakari Ailusc659c382011-01-21 10:59:30 +00002033}
Linus Torvalds1da177e2005-04-16 15:20:36 -07002034
2035
2036
2037
Sakari Ailusc659c382011-01-21 10:59:30 +00002038/***************************************************************
2039 * TLan_PrintList
2040 *
2041 * Returns:
2042 * Nothing
2043 * Parms:
2044 * list A pointer to the struct tlan_list structure to
2045 * be printed.
2046 * type A string to designate type of list,
2047 * "Rx" or "Tx".
2048 * num The index of the list.
2049 *
2050 * This function prints out the contents of the list
2051 * pointed to by the list parameter.
2052 *
2053 **************************************************************/
Linus Torvalds1da177e2005-04-16 15:20:36 -07002054
Sakari Ailusc659c382011-01-21 10:59:30 +00002055static void tlan_print_list(struct tlan_list *list, char *type, int num)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002056{
2057 int i;
2058
Joe Perches50624aa2011-03-01 06:56:33 +00002059 pr_info("%s List %d at %p\n", type, num, list);
2060 pr_info(" Forward = 0x%08x\n", list->forward);
2061 pr_info(" CSTAT = 0x%04hx\n", list->c_stat);
2062 pr_info(" Frame Size = 0x%04hx\n", list->frame_size);
Sakari Ailusc659c382011-01-21 10:59:30 +00002063 /* for (i = 0; i < 10; i++) { */
2064 for (i = 0; i < 2; i++) {
Joe Perches50624aa2011-03-01 06:56:33 +00002065 pr_info(" Buffer[%d].count, addr = 0x%08x, 0x%08x\n",
2066 i, list->buffer[i].count, list->buffer[i].address);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002067 }
2068
Sakari Ailusc659c382011-01-21 10:59:30 +00002069}
Linus Torvalds1da177e2005-04-16 15:20:36 -07002070
2071
2072
2073
Sakari Ailusc659c382011-01-21 10:59:30 +00002074/***************************************************************
2075 * tlan_read_and_clear_stats
2076 *
2077 * Returns:
2078 * Nothing
2079 * Parms:
2080 * dev Pointer to device structure of adapter
2081 * to which to read stats.
2082 * record Flag indicating whether to add
2083 *
2084 * This functions reads all the internal status registers
2085 * of the TLAN chip, which clears them as a side effect.
2086 * It then either adds the values to the device's status
2087 * struct, or discards them, depending on whether record
2088 * is TLAN_RECORD (!=0) or TLAN_IGNORE (==0).
2089 *
2090 **************************************************************/
Linus Torvalds1da177e2005-04-16 15:20:36 -07002091
Sakari Ailusc659c382011-01-21 10:59:30 +00002092static void tlan_read_and_clear_stats(struct net_device *dev, int record)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002093{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002094 u32 tx_good, tx_under;
2095 u32 rx_good, rx_over;
2096 u32 def_tx, crc, code;
2097 u32 multi_col, single_col;
2098 u32 excess_col, late_col, loss;
2099
Sakari Ailusc659c382011-01-21 10:59:30 +00002100 outw(TLAN_GOOD_TX_FRMS, dev->base_addr + TLAN_DIO_ADR);
2101 tx_good = inb(dev->base_addr + TLAN_DIO_DATA);
2102 tx_good += inb(dev->base_addr + TLAN_DIO_DATA + 1) << 8;
2103 tx_good += inb(dev->base_addr + TLAN_DIO_DATA + 2) << 16;
2104 tx_under = inb(dev->base_addr + TLAN_DIO_DATA + 3);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002105
Sakari Ailusc659c382011-01-21 10:59:30 +00002106 outw(TLAN_GOOD_RX_FRMS, dev->base_addr + TLAN_DIO_ADR);
2107 rx_good = inb(dev->base_addr + TLAN_DIO_DATA);
2108 rx_good += inb(dev->base_addr + TLAN_DIO_DATA + 1) << 8;
2109 rx_good += inb(dev->base_addr + TLAN_DIO_DATA + 2) << 16;
2110 rx_over = inb(dev->base_addr + TLAN_DIO_DATA + 3);
Jeff Garzik6aa20a22006-09-13 13:24:59 -04002111
Sakari Ailusc659c382011-01-21 10:59:30 +00002112 outw(TLAN_DEFERRED_TX, dev->base_addr + TLAN_DIO_ADR);
2113 def_tx = inb(dev->base_addr + TLAN_DIO_DATA);
2114 def_tx += inb(dev->base_addr + TLAN_DIO_DATA + 1) << 8;
2115 crc = inb(dev->base_addr + TLAN_DIO_DATA + 2);
2116 code = inb(dev->base_addr + TLAN_DIO_DATA + 3);
Jeff Garzik6aa20a22006-09-13 13:24:59 -04002117
Sakari Ailusc659c382011-01-21 10:59:30 +00002118 outw(TLAN_MULTICOL_FRMS, dev->base_addr + TLAN_DIO_ADR);
2119 multi_col = inb(dev->base_addr + TLAN_DIO_DATA);
2120 multi_col += inb(dev->base_addr + TLAN_DIO_DATA + 1) << 8;
2121 single_col = inb(dev->base_addr + TLAN_DIO_DATA + 2);
2122 single_col += inb(dev->base_addr + TLAN_DIO_DATA + 3) << 8;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002123
Sakari Ailusc659c382011-01-21 10:59:30 +00002124 outw(TLAN_EXCESSCOL_FRMS, dev->base_addr + TLAN_DIO_ADR);
2125 excess_col = inb(dev->base_addr + TLAN_DIO_DATA);
2126 late_col = inb(dev->base_addr + TLAN_DIO_DATA + 1);
2127 loss = inb(dev->base_addr + TLAN_DIO_DATA + 2);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002128
Sakari Ailusc659c382011-01-21 10:59:30 +00002129 if (record) {
Stephen Hemmingerf8f31542008-05-30 09:49:53 -07002130 dev->stats.rx_packets += rx_good;
2131 dev->stats.rx_errors += rx_over + crc + code;
2132 dev->stats.tx_packets += tx_good;
2133 dev->stats.tx_errors += tx_under + loss;
Sakari Ailusc659c382011-01-21 10:59:30 +00002134 dev->stats.collisions += multi_col
2135 + single_col + excess_col + late_col;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002136
Stephen Hemmingerf8f31542008-05-30 09:49:53 -07002137 dev->stats.rx_over_errors += rx_over;
2138 dev->stats.rx_crc_errors += crc;
2139 dev->stats.rx_frame_errors += code;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002140
Stephen Hemmingerf8f31542008-05-30 09:49:53 -07002141 dev->stats.tx_aborted_errors += tx_under;
2142 dev->stats.tx_carrier_errors += loss;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002143 }
Jeff Garzik6aa20a22006-09-13 13:24:59 -04002144
Sakari Ailusc659c382011-01-21 10:59:30 +00002145}
Linus Torvalds1da177e2005-04-16 15:20:36 -07002146
2147
2148
2149
Sakari Ailusc659c382011-01-21 10:59:30 +00002150/***************************************************************
2151 * TLan_Reset
2152 *
2153 * Returns:
2154 * 0
2155 * Parms:
2156 * dev Pointer to device structure of adapter
2157 * to be reset.
2158 *
2159 * This function resets the adapter and it's physical
2160 * device. See Chap. 3, pp. 9-10 of the "ThunderLAN
2161 * Programmer's Guide" for details. The routine tries to
2162 * implement what is detailed there, though adjustments
2163 * have been made.
2164 *
2165 **************************************************************/
Linus Torvalds1da177e2005-04-16 15:20:36 -07002166
Harvey Harrison98e0f522008-02-18 10:04:38 -08002167static void
Sakari Ailusc659c382011-01-21 10:59:30 +00002168tlan_reset_adapter(struct net_device *dev)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002169{
Sakari Ailusc659c382011-01-21 10:59:30 +00002170 struct tlan_priv *priv = netdev_priv(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002171 int i;
2172 u32 addr;
2173 u32 data;
2174 u8 data8;
2175
Sakari Ailusc659c382011-01-21 10:59:30 +00002176 priv->tlan_full_duplex = false;
2177 priv->phy_online = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002178 netif_carrier_off(dev);
2179
2180/* 1. Assert reset bit. */
2181
2182 data = inl(dev->base_addr + TLAN_HOST_CMD);
2183 data |= TLAN_HC_AD_RST;
2184 outl(data, dev->base_addr + TLAN_HOST_CMD);
Jeff Garzik6aa20a22006-09-13 13:24:59 -04002185
Linus Torvalds1da177e2005-04-16 15:20:36 -07002186 udelay(1000);
2187
Sakari Ailusc659c382011-01-21 10:59:30 +00002188/* 2. Turn off interrupts. (Probably isn't necessary) */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002189
2190 data = inl(dev->base_addr + TLAN_HOST_CMD);
2191 data |= TLAN_HC_INT_OFF;
2192 outl(data, dev->base_addr + TLAN_HOST_CMD);
2193
2194/* 3. Clear AREGs and HASHs. */
2195
Sakari Ailusc659c382011-01-21 10:59:30 +00002196 for (i = TLAN_AREG_0; i <= TLAN_HASH_2; i += 4)
2197 tlan_dio_write32(dev->base_addr, (u16) i, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002198
2199/* 4. Setup NetConfig register. */
2200
2201 data = TLAN_NET_CFG_1FRAG | TLAN_NET_CFG_1CHAN | TLAN_NET_CFG_PHY_EN;
Sakari Ailusc659c382011-01-21 10:59:30 +00002202 tlan_dio_write16(dev->base_addr, TLAN_NET_CONFIG, (u16) data);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002203
2204/* 5. Load Ld_Tmr and Ld_Thr in HOST_CMD. */
2205
Sakari Ailusc659c382011-01-21 10:59:30 +00002206 outl(TLAN_HC_LD_TMR | 0x3f, dev->base_addr + TLAN_HOST_CMD);
2207 outl(TLAN_HC_LD_THR | 0x9, dev->base_addr + TLAN_HOST_CMD);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002208
2209/* 6. Unreset the MII by setting NMRST (in NetSio) to 1. */
2210
Sakari Ailusc659c382011-01-21 10:59:30 +00002211 outw(TLAN_NET_SIO, dev->base_addr + TLAN_DIO_ADR);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002212 addr = dev->base_addr + TLAN_DIO_DATA + TLAN_NET_SIO;
Sakari Ailusc659c382011-01-21 10:59:30 +00002213 tlan_set_bit(TLAN_NET_SIO_NMRST, addr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002214
2215/* 7. Setup the remaining registers. */
2216
Sakari Ailusc659c382011-01-21 10:59:30 +00002217 if (priv->tlan_rev >= 0x30) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002218 data8 = TLAN_ID_TX_EOC | TLAN_ID_RX_EOC;
Sakari Ailusc659c382011-01-21 10:59:30 +00002219 tlan_dio_write8(dev->base_addr, TLAN_INT_DIS, data8);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002220 }
Sakari Ailusc659c382011-01-21 10:59:30 +00002221 tlan_phy_detect(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002222 data = TLAN_NET_CFG_1FRAG | TLAN_NET_CFG_1CHAN;
Jeff Garzik6aa20a22006-09-13 13:24:59 -04002223
Sakari Ailusc659c382011-01-21 10:59:30 +00002224 if (priv->adapter->flags & TLAN_ADAPTER_BIT_RATE_PHY) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002225 data |= TLAN_NET_CFG_BIT;
Sakari Ailusc659c382011-01-21 10:59:30 +00002226 if (priv->aui == 1) {
2227 tlan_dio_write8(dev->base_addr, TLAN_ACOMMIT, 0x0a);
2228 } else if (priv->duplex == TLAN_DUPLEX_FULL) {
2229 tlan_dio_write8(dev->base_addr, TLAN_ACOMMIT, 0x00);
2230 priv->tlan_full_duplex = true;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002231 } else {
Sakari Ailusc659c382011-01-21 10:59:30 +00002232 tlan_dio_write8(dev->base_addr, TLAN_ACOMMIT, 0x08);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002233 }
2234 }
2235
Sakari Ailusc659c382011-01-21 10:59:30 +00002236 if (priv->phy_num == 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002237 data |= TLAN_NET_CFG_PHY_EN;
Sakari Ailusc659c382011-01-21 10:59:30 +00002238 tlan_dio_write16(dev->base_addr, TLAN_NET_CONFIG, (u16) data);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002239
Sakari Ailusc659c382011-01-21 10:59:30 +00002240 if (priv->adapter->flags & TLAN_ADAPTER_UNMANAGED_PHY)
2241 tlan_finish_reset(dev);
2242 else
2243 tlan_phy_power_down(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002244
Sakari Ailusc659c382011-01-21 10:59:30 +00002245}
Linus Torvalds1da177e2005-04-16 15:20:36 -07002246
2247
2248
2249
Harvey Harrison98e0f522008-02-18 10:04:38 -08002250static void
Sakari Ailusc659c382011-01-21 10:59:30 +00002251tlan_finish_reset(struct net_device *dev)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002252{
Sakari Ailusc659c382011-01-21 10:59:30 +00002253 struct tlan_priv *priv = netdev_priv(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002254 u8 data;
2255 u32 phy;
2256 u8 sio;
2257 u16 status;
2258 u16 partner;
2259 u16 tlphy_ctl;
Sakari Ailusc659c382011-01-21 10:59:30 +00002260 u16 tlphy_par;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002261 u16 tlphy_id1, tlphy_id2;
Sakari Ailusc659c382011-01-21 10:59:30 +00002262 int i;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002263
Sakari Ailusc659c382011-01-21 10:59:30 +00002264 phy = priv->phy[priv->phy_num];
Linus Torvalds1da177e2005-04-16 15:20:36 -07002265
2266 data = TLAN_NET_CMD_NRESET | TLAN_NET_CMD_NWRAP;
Sakari Ailusc659c382011-01-21 10:59:30 +00002267 if (priv->tlan_full_duplex)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002268 data |= TLAN_NET_CMD_DUPLEX;
Sakari Ailusc659c382011-01-21 10:59:30 +00002269 tlan_dio_write8(dev->base_addr, TLAN_NET_CMD, data);
Jeff Garzik6aa20a22006-09-13 13:24:59 -04002270 data = TLAN_NET_MASK_MASK4 | TLAN_NET_MASK_MASK5;
Sakari Ailusc659c382011-01-21 10:59:30 +00002271 if (priv->phy_num == 0)
Jeff Garzik6aa20a22006-09-13 13:24:59 -04002272 data |= TLAN_NET_MASK_MASK7;
Sakari Ailusc659c382011-01-21 10:59:30 +00002273 tlan_dio_write8(dev->base_addr, TLAN_NET_MASK, data);
2274 tlan_dio_write16(dev->base_addr, TLAN_MAX_RX, ((1536)+7)&~7);
2275 tlan_mii_read_reg(dev, phy, MII_GEN_ID_HI, &tlphy_id1);
2276 tlan_mii_read_reg(dev, phy, MII_GEN_ID_LO, &tlphy_id2);
Jeff Garzik6aa20a22006-09-13 13:24:59 -04002277
Sakari Ailusc659c382011-01-21 10:59:30 +00002278 if ((priv->adapter->flags & TLAN_ADAPTER_UNMANAGED_PHY) ||
2279 (priv->aui)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002280 status = MII_GS_LINK;
Joe Perches50624aa2011-03-01 06:56:33 +00002281 netdev_info(dev, "Link forced\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002282 } else {
Sakari Ailusc659c382011-01-21 10:59:30 +00002283 tlan_mii_read_reg(dev, phy, MII_GEN_STS, &status);
2284 udelay(1000);
2285 tlan_mii_read_reg(dev, phy, MII_GEN_STS, &status);
Ondrej Zaryc0a87c22014-06-30 18:38:28 +02002286 if (status & MII_GS_LINK) {
2287 /* We only support link info on Nat.Sem. PHY's */
2288 if ((tlphy_id1 == NAT_SEM_ID1) &&
2289 (tlphy_id2 == NAT_SEM_ID2)) {
2290 tlan_mii_read_reg(dev, phy, MII_AN_LPA,
2291 &partner);
2292 tlan_mii_read_reg(dev, phy, TLAN_TLPHY_PAR,
2293 &tlphy_par);
Jeff Garzik6aa20a22006-09-13 13:24:59 -04002294
Ondrej Zaryc0a87c22014-06-30 18:38:28 +02002295 netdev_info(dev,
2296 "Link active, %s %uMbps %s-Duplex\n",
2297 !(tlphy_par & TLAN_PHY_AN_EN_STAT)
2298 ? "forced" : "Autonegotiation enabled,",
2299 tlphy_par & TLAN_PHY_SPEED_100
2300 ? 100 : 10,
2301 tlphy_par & TLAN_PHY_DUPLEX_FULL
2302 ? "Full" : "Half");
Joe Perches50624aa2011-03-01 06:56:33 +00002303
Ondrej Zaryc0a87c22014-06-30 18:38:28 +02002304 if (tlphy_par & TLAN_PHY_AN_EN_STAT) {
2305 netdev_info(dev, "Partner capability:");
2306 for (i = 5; i < 10; i++)
2307 if (partner & (1 << i))
2308 pr_cont(" %s",
2309 media[i-5]);
2310 pr_cont("\n");
2311 }
2312 } else
2313 netdev_info(dev, "Link active\n");
2314 /* Enabling link beat monitoring */
2315 priv->media_timer.function = tlan_phy_monitor;
2316 priv->media_timer.data = (unsigned long) dev;
2317 priv->media_timer.expires = jiffies + HZ;
2318 add_timer(&priv->media_timer);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002319 }
2320 }
2321
Sakari Ailusc659c382011-01-21 10:59:30 +00002322 if (priv->phy_num == 0) {
2323 tlan_mii_read_reg(dev, phy, TLAN_TLPHY_CTL, &tlphy_ctl);
2324 tlphy_ctl |= TLAN_TC_INTEN;
2325 tlan_mii_write_reg(dev, phy, TLAN_TLPHY_CTL, tlphy_ctl);
2326 sio = tlan_dio_read8(dev->base_addr, TLAN_NET_SIO);
2327 sio |= TLAN_NET_SIO_MINTEN;
2328 tlan_dio_write8(dev->base_addr, TLAN_NET_SIO, sio);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002329 }
2330
Sakari Ailusc659c382011-01-21 10:59:30 +00002331 if (status & MII_GS_LINK) {
2332 tlan_set_mac(dev, 0, dev->dev_addr);
2333 priv->phy_online = 1;
2334 outb((TLAN_HC_INT_ON >> 8), dev->base_addr + TLAN_HOST_CMD + 1);
2335 if (debug >= 1 && debug != TLAN_DEBUG_PROBE)
2336 outb((TLAN_HC_REQ_INT >> 8),
2337 dev->base_addr + TLAN_HOST_CMD + 1);
2338 outl(priv->rx_list_dma, dev->base_addr + TLAN_CH_PARM);
2339 outl(TLAN_HC_GO | TLAN_HC_RT, dev->base_addr + TLAN_HOST_CMD);
Ondrej Zaryc0a87c22014-06-30 18:38:28 +02002340 tlan_dio_write8(dev->base_addr, TLAN_LED_REG, TLAN_LED_LINK);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002341 netif_carrier_on(dev);
2342 } else {
Joe Perches50624aa2011-03-01 06:56:33 +00002343 netdev_info(dev, "Link inactive, will retry in 10 secs...\n");
Sakari Ailusc659c382011-01-21 10:59:30 +00002344 tlan_set_timer(dev, (10*HZ), TLAN_TIMER_FINISH_RESET);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002345 return;
2346 }
Sakari Ailusc659c382011-01-21 10:59:30 +00002347 tlan_set_multicast_list(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002348
Sakari Ailusc659c382011-01-21 10:59:30 +00002349}
Linus Torvalds1da177e2005-04-16 15:20:36 -07002350
2351
2352
2353
Sakari Ailusc659c382011-01-21 10:59:30 +00002354/***************************************************************
2355 * tlan_set_mac
2356 *
2357 * Returns:
2358 * Nothing
2359 * Parms:
2360 * dev Pointer to device structure of adapter
2361 * on which to change the AREG.
2362 * areg The AREG to set the address in (0 - 3).
2363 * mac A pointer to an array of chars. Each
2364 * element stores one byte of the address.
2365 * IE, it isn't in ascii.
2366 *
2367 * This function transfers a MAC address to one of the
2368 * TLAN AREGs (address registers). The TLAN chip locks
2369 * the register on writing to offset 0 and unlocks the
2370 * register after writing to offset 5. If NULL is passed
2371 * in mac, then the AREG is filled with 0's.
2372 *
2373 **************************************************************/
Linus Torvalds1da177e2005-04-16 15:20:36 -07002374
Sakari Ailusc659c382011-01-21 10:59:30 +00002375static void tlan_set_mac(struct net_device *dev, int areg, char *mac)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002376{
2377 int i;
Jeff Garzik6aa20a22006-09-13 13:24:59 -04002378
Linus Torvalds1da177e2005-04-16 15:20:36 -07002379 areg *= 6;
2380
Sakari Ailusc659c382011-01-21 10:59:30 +00002381 if (mac != NULL) {
2382 for (i = 0; i < 6; i++)
2383 tlan_dio_write8(dev->base_addr,
2384 TLAN_AREG_0 + areg + i, mac[i]);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002385 } else {
Sakari Ailusc659c382011-01-21 10:59:30 +00002386 for (i = 0; i < 6; i++)
2387 tlan_dio_write8(dev->base_addr,
2388 TLAN_AREG_0 + areg + i, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002389 }
2390
Sakari Ailusc659c382011-01-21 10:59:30 +00002391}
Linus Torvalds1da177e2005-04-16 15:20:36 -07002392
2393
2394
2395
2396/*****************************************************************************
2397******************************************************************************
2398
Sakari Ailusc659c382011-01-21 10:59:30 +00002399ThunderLAN driver PHY layer routines
Linus Torvalds1da177e2005-04-16 15:20:36 -07002400
2401******************************************************************************
2402*****************************************************************************/
2403
2404
2405
Sakari Ailusc659c382011-01-21 10:59:30 +00002406/*********************************************************************
2407 * tlan_phy_print
2408 *
2409 * Returns:
2410 * Nothing
2411 * Parms:
2412 * dev A pointer to the device structure of the
2413 * TLAN device having the PHYs to be detailed.
2414 *
2415 * This function prints the registers a PHY (aka transceiver).
2416 *
2417 ********************************************************************/
Linus Torvalds1da177e2005-04-16 15:20:36 -07002418
Sakari Ailusc659c382011-01-21 10:59:30 +00002419static void tlan_phy_print(struct net_device *dev)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002420{
Sakari Ailusc659c382011-01-21 10:59:30 +00002421 struct tlan_priv *priv = netdev_priv(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002422 u16 i, data0, data1, data2, data3, phy;
2423
Sakari Ailusc659c382011-01-21 10:59:30 +00002424 phy = priv->phy[priv->phy_num];
Linus Torvalds1da177e2005-04-16 15:20:36 -07002425
Sakari Ailusc659c382011-01-21 10:59:30 +00002426 if (priv->adapter->flags & TLAN_ADAPTER_UNMANAGED_PHY) {
Joe Perches50624aa2011-03-01 06:56:33 +00002427 netdev_info(dev, "Unmanaged PHY\n");
Sakari Ailusc659c382011-01-21 10:59:30 +00002428 } else if (phy <= TLAN_PHY_MAX_ADDR) {
Joe Perches50624aa2011-03-01 06:56:33 +00002429 netdev_info(dev, "PHY 0x%02x\n", phy);
2430 pr_info(" Off. +0 +1 +2 +3\n");
Sakari Ailusc659c382011-01-21 10:59:30 +00002431 for (i = 0; i < 0x20; i += 4) {
Sakari Ailusc659c382011-01-21 10:59:30 +00002432 tlan_mii_read_reg(dev, phy, i, &data0);
Sakari Ailusc659c382011-01-21 10:59:30 +00002433 tlan_mii_read_reg(dev, phy, i + 1, &data1);
Sakari Ailusc659c382011-01-21 10:59:30 +00002434 tlan_mii_read_reg(dev, phy, i + 2, &data2);
Sakari Ailusc659c382011-01-21 10:59:30 +00002435 tlan_mii_read_reg(dev, phy, i + 3, &data3);
Joe Perches50624aa2011-03-01 06:56:33 +00002436 pr_info(" 0x%02x 0x%04hx 0x%04hx 0x%04hx 0x%04hx\n",
2437 i, data0, data1, data2, data3);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002438 }
2439 } else {
Joe Perches50624aa2011-03-01 06:56:33 +00002440 netdev_info(dev, "Invalid PHY\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002441 }
2442
Sakari Ailusc659c382011-01-21 10:59:30 +00002443}
Linus Torvalds1da177e2005-04-16 15:20:36 -07002444
2445
2446
2447
Sakari Ailusc659c382011-01-21 10:59:30 +00002448/*********************************************************************
2449 * tlan_phy_detect
2450 *
2451 * Returns:
2452 * Nothing
2453 * Parms:
2454 * dev A pointer to the device structure of the adapter
2455 * for which the PHY needs determined.
2456 *
2457 * So far I've found that adapters which have external PHYs
2458 * may also use the internal PHY for part of the functionality.
2459 * (eg, AUI/Thinnet). This function finds out if this TLAN
2460 * chip has an internal PHY, and then finds the first external
2461 * PHY (starting from address 0) if it exists).
2462 *
2463 ********************************************************************/
Linus Torvalds1da177e2005-04-16 15:20:36 -07002464
Sakari Ailusc659c382011-01-21 10:59:30 +00002465static void tlan_phy_detect(struct net_device *dev)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002466{
Sakari Ailusc659c382011-01-21 10:59:30 +00002467 struct tlan_priv *priv = netdev_priv(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002468 u16 control;
2469 u16 hi;
2470 u16 lo;
2471 u32 phy;
2472
Sakari Ailusc659c382011-01-21 10:59:30 +00002473 if (priv->adapter->flags & TLAN_ADAPTER_UNMANAGED_PHY) {
2474 priv->phy_num = 0xffff;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002475 return;
2476 }
2477
Sakari Ailusc659c382011-01-21 10:59:30 +00002478 tlan_mii_read_reg(dev, TLAN_PHY_MAX_ADDR, MII_GEN_ID_HI, &hi);
Jeff Garzik6aa20a22006-09-13 13:24:59 -04002479
Sakari Ailusc659c382011-01-21 10:59:30 +00002480 if (hi != 0xffff)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002481 priv->phy[0] = TLAN_PHY_MAX_ADDR;
Sakari Ailusc659c382011-01-21 10:59:30 +00002482 else
Linus Torvalds1da177e2005-04-16 15:20:36 -07002483 priv->phy[0] = TLAN_PHY_NONE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002484
2485 priv->phy[1] = TLAN_PHY_NONE;
Sakari Ailusc659c382011-01-21 10:59:30 +00002486 for (phy = 0; phy <= TLAN_PHY_MAX_ADDR; phy++) {
2487 tlan_mii_read_reg(dev, phy, MII_GEN_CTL, &control);
2488 tlan_mii_read_reg(dev, phy, MII_GEN_ID_HI, &hi);
2489 tlan_mii_read_reg(dev, phy, MII_GEN_ID_LO, &lo);
2490 if ((control != 0xffff) ||
2491 (hi != 0xffff) || (lo != 0xffff)) {
2492 TLAN_DBG(TLAN_DEBUG_GNRL,
2493 "PHY found at %02x %04x %04x %04x\n",
2494 phy, control, hi, lo);
2495 if ((priv->phy[1] == TLAN_PHY_NONE) &&
2496 (phy != TLAN_PHY_MAX_ADDR)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002497 priv->phy[1] = phy;
2498 }
2499 }
2500 }
2501
Sakari Ailusc659c382011-01-21 10:59:30 +00002502 if (priv->phy[1] != TLAN_PHY_NONE)
2503 priv->phy_num = 1;
2504 else if (priv->phy[0] != TLAN_PHY_NONE)
2505 priv->phy_num = 0;
2506 else
Joe Perches50624aa2011-03-01 06:56:33 +00002507 netdev_info(dev, "Cannot initialize device, no PHY was found!\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002508
Sakari Ailusc659c382011-01-21 10:59:30 +00002509}
Linus Torvalds1da177e2005-04-16 15:20:36 -07002510
2511
2512
2513
Sakari Ailusc659c382011-01-21 10:59:30 +00002514static void tlan_phy_power_down(struct net_device *dev)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002515{
Sakari Ailusc659c382011-01-21 10:59:30 +00002516 struct tlan_priv *priv = netdev_priv(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002517 u16 value;
2518
Sakari Ailusc659c382011-01-21 10:59:30 +00002519 TLAN_DBG(TLAN_DEBUG_GNRL, "%s: Powering down PHY(s).\n", dev->name);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002520 value = MII_GC_PDOWN | MII_GC_LOOPBK | MII_GC_ISOLATE;
Sakari Ailusc659c382011-01-21 10:59:30 +00002521 tlan_mii_sync(dev->base_addr);
2522 tlan_mii_write_reg(dev, priv->phy[priv->phy_num], MII_GEN_CTL, value);
2523 if ((priv->phy_num == 0) &&
2524 (priv->phy[1] != TLAN_PHY_NONE) &&
2525 (!(priv->adapter->flags & TLAN_ADAPTER_USE_INTERN_10))) {
2526 tlan_mii_sync(dev->base_addr);
2527 tlan_mii_write_reg(dev, priv->phy[1], MII_GEN_CTL, value);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002528 }
2529
2530 /* Wait for 50 ms and powerup
2531 * This is abitrary. It is intended to make sure the
2532 * transceiver settles.
2533 */
Sakari Ailusc659c382011-01-21 10:59:30 +00002534 tlan_set_timer(dev, (HZ/20), TLAN_TIMER_PHY_PUP);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002535
Sakari Ailusc659c382011-01-21 10:59:30 +00002536}
Linus Torvalds1da177e2005-04-16 15:20:36 -07002537
2538
2539
2540
Sakari Ailusc659c382011-01-21 10:59:30 +00002541static void tlan_phy_power_up(struct net_device *dev)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002542{
Sakari Ailusc659c382011-01-21 10:59:30 +00002543 struct tlan_priv *priv = netdev_priv(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002544 u16 value;
2545
Sakari Ailusc659c382011-01-21 10:59:30 +00002546 TLAN_DBG(TLAN_DEBUG_GNRL, "%s: Powering up PHY.\n", dev->name);
2547 tlan_mii_sync(dev->base_addr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002548 value = MII_GC_LOOPBK;
Sakari Ailusc659c382011-01-21 10:59:30 +00002549 tlan_mii_write_reg(dev, priv->phy[priv->phy_num], MII_GEN_CTL, value);
2550 tlan_mii_sync(dev->base_addr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002551 /* Wait for 500 ms and reset the
2552 * transceiver. The TLAN docs say both 50 ms and
2553 * 500 ms, so do the longer, just in case.
2554 */
Sakari Ailusc659c382011-01-21 10:59:30 +00002555 tlan_set_timer(dev, (HZ/20), TLAN_TIMER_PHY_RESET);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002556
Sakari Ailusc659c382011-01-21 10:59:30 +00002557}
Linus Torvalds1da177e2005-04-16 15:20:36 -07002558
2559
2560
2561
Sakari Ailusc659c382011-01-21 10:59:30 +00002562static void tlan_phy_reset(struct net_device *dev)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002563{
Sakari Ailusc659c382011-01-21 10:59:30 +00002564 struct tlan_priv *priv = netdev_priv(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002565 u16 phy;
2566 u16 value;
2567
Sakari Ailusc659c382011-01-21 10:59:30 +00002568 phy = priv->phy[priv->phy_num];
Linus Torvalds1da177e2005-04-16 15:20:36 -07002569
Masanari Iidafd9071e2012-04-13 04:33:20 +00002570 TLAN_DBG(TLAN_DEBUG_GNRL, "%s: Resetting PHY.\n", dev->name);
Sakari Ailusc659c382011-01-21 10:59:30 +00002571 tlan_mii_sync(dev->base_addr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002572 value = MII_GC_LOOPBK | MII_GC_RESET;
Sakari Ailusc659c382011-01-21 10:59:30 +00002573 tlan_mii_write_reg(dev, phy, MII_GEN_CTL, value);
2574 tlan_mii_read_reg(dev, phy, MII_GEN_CTL, &value);
2575 while (value & MII_GC_RESET)
2576 tlan_mii_read_reg(dev, phy, MII_GEN_CTL, &value);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002577
2578 /* Wait for 500 ms and initialize.
2579 * I don't remember why I wait this long.
2580 * I've changed this to 50ms, as it seems long enough.
2581 */
Sakari Ailusc659c382011-01-21 10:59:30 +00002582 tlan_set_timer(dev, (HZ/20), TLAN_TIMER_PHY_START_LINK);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002583
Sakari Ailusc659c382011-01-21 10:59:30 +00002584}
Linus Torvalds1da177e2005-04-16 15:20:36 -07002585
2586
2587
2588
Sakari Ailusc659c382011-01-21 10:59:30 +00002589static void tlan_phy_start_link(struct net_device *dev)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002590{
Sakari Ailusc659c382011-01-21 10:59:30 +00002591 struct tlan_priv *priv = netdev_priv(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002592 u16 ability;
2593 u16 control;
2594 u16 data;
2595 u16 phy;
2596 u16 status;
2597 u16 tctl;
2598
Sakari Ailusc659c382011-01-21 10:59:30 +00002599 phy = priv->phy[priv->phy_num];
2600 TLAN_DBG(TLAN_DEBUG_GNRL, "%s: Trying to activate link.\n", dev->name);
2601 tlan_mii_read_reg(dev, phy, MII_GEN_STS, &status);
2602 tlan_mii_read_reg(dev, phy, MII_GEN_STS, &ability);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002603
Sakari Ailusc659c382011-01-21 10:59:30 +00002604 if ((status & MII_GS_AUTONEG) &&
2605 (!priv->aui)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002606 ability = status >> 11;
Sakari Ailusc659c382011-01-21 10:59:30 +00002607 if (priv->speed == TLAN_SPEED_10 &&
2608 priv->duplex == TLAN_DUPLEX_HALF) {
2609 tlan_mii_write_reg(dev, phy, MII_GEN_CTL, 0x0000);
2610 } else if (priv->speed == TLAN_SPEED_10 &&
2611 priv->duplex == TLAN_DUPLEX_FULL) {
2612 priv->tlan_full_duplex = true;
2613 tlan_mii_write_reg(dev, phy, MII_GEN_CTL, 0x0100);
2614 } else if (priv->speed == TLAN_SPEED_100 &&
2615 priv->duplex == TLAN_DUPLEX_HALF) {
2616 tlan_mii_write_reg(dev, phy, MII_GEN_CTL, 0x2000);
2617 } else if (priv->speed == TLAN_SPEED_100 &&
2618 priv->duplex == TLAN_DUPLEX_FULL) {
2619 priv->tlan_full_duplex = true;
2620 tlan_mii_write_reg(dev, phy, MII_GEN_CTL, 0x2100);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002621 } else {
Jeff Garzik6aa20a22006-09-13 13:24:59 -04002622
Linus Torvalds1da177e2005-04-16 15:20:36 -07002623 /* Set Auto-Neg advertisement */
Sakari Ailusc659c382011-01-21 10:59:30 +00002624 tlan_mii_write_reg(dev, phy, MII_AN_ADV,
2625 (ability << 5) | 1);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002626 /* Enablee Auto-Neg */
Sakari Ailusc659c382011-01-21 10:59:30 +00002627 tlan_mii_write_reg(dev, phy, MII_GEN_CTL, 0x1000);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002628 /* Restart Auto-Neg */
Sakari Ailusc659c382011-01-21 10:59:30 +00002629 tlan_mii_write_reg(dev, phy, MII_GEN_CTL, 0x1200);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002630 /* Wait for 4 sec for autonegotiation
Sakari Ailusc659c382011-01-21 10:59:30 +00002631 * to complete. The max spec time is less than this
2632 * but the card need additional time to start AN.
2633 * .5 sec should be plenty extra.
2634 */
Joe Perches50624aa2011-03-01 06:56:33 +00002635 netdev_info(dev, "Starting autonegotiation\n");
Sakari Ailusc659c382011-01-21 10:59:30 +00002636 tlan_set_timer(dev, (2*HZ), TLAN_TIMER_PHY_FINISH_AN);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002637 return;
2638 }
Jeff Garzik6aa20a22006-09-13 13:24:59 -04002639
2640 }
2641
Sakari Ailusc659c382011-01-21 10:59:30 +00002642 if ((priv->aui) && (priv->phy_num != 0)) {
2643 priv->phy_num = 0;
2644 data = TLAN_NET_CFG_1FRAG | TLAN_NET_CFG_1CHAN
2645 | TLAN_NET_CFG_PHY_EN;
2646 tlan_dio_write16(dev->base_addr, TLAN_NET_CONFIG, data);
2647 tlan_set_timer(dev, (40*HZ/1000), TLAN_TIMER_PHY_PDOWN);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002648 return;
Sakari Ailusc659c382011-01-21 10:59:30 +00002649 } else if (priv->phy_num == 0) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002650 control = 0;
Sakari Ailusc659c382011-01-21 10:59:30 +00002651 tlan_mii_read_reg(dev, phy, TLAN_TLPHY_CTL, &tctl);
2652 if (priv->aui) {
2653 tctl |= TLAN_TC_AUISEL;
Jeff Garzik6aa20a22006-09-13 13:24:59 -04002654 } else {
Sakari Ailusc659c382011-01-21 10:59:30 +00002655 tctl &= ~TLAN_TC_AUISEL;
2656 if (priv->duplex == TLAN_DUPLEX_FULL) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002657 control |= MII_GC_DUPLEX;
Sakari Ailusc659c382011-01-21 10:59:30 +00002658 priv->tlan_full_duplex = true;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002659 }
Sakari Ailusc659c382011-01-21 10:59:30 +00002660 if (priv->speed == TLAN_SPEED_100)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002661 control |= MII_GC_SPEEDSEL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002662 }
Sakari Ailusc659c382011-01-21 10:59:30 +00002663 tlan_mii_write_reg(dev, phy, MII_GEN_CTL, control);
2664 tlan_mii_write_reg(dev, phy, TLAN_TLPHY_CTL, tctl);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002665 }
2666
2667 /* Wait for 2 sec to give the transceiver time
2668 * to establish link.
2669 */
Sakari Ailusc659c382011-01-21 10:59:30 +00002670 tlan_set_timer(dev, (4*HZ), TLAN_TIMER_FINISH_RESET);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002671
Sakari Ailusc659c382011-01-21 10:59:30 +00002672}
Linus Torvalds1da177e2005-04-16 15:20:36 -07002673
2674
2675
2676
Sakari Ailusc659c382011-01-21 10:59:30 +00002677static void tlan_phy_finish_auto_neg(struct net_device *dev)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002678{
Sakari Ailusc659c382011-01-21 10:59:30 +00002679 struct tlan_priv *priv = netdev_priv(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002680 u16 an_adv;
2681 u16 an_lpa;
2682 u16 data;
2683 u16 mode;
2684 u16 phy;
2685 u16 status;
Jeff Garzik6aa20a22006-09-13 13:24:59 -04002686
Sakari Ailusc659c382011-01-21 10:59:30 +00002687 phy = priv->phy[priv->phy_num];
Linus Torvalds1da177e2005-04-16 15:20:36 -07002688
Sakari Ailusc659c382011-01-21 10:59:30 +00002689 tlan_mii_read_reg(dev, phy, MII_GEN_STS, &status);
2690 udelay(1000);
2691 tlan_mii_read_reg(dev, phy, MII_GEN_STS, &status);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002692
Sakari Ailusc659c382011-01-21 10:59:30 +00002693 if (!(status & MII_GS_AUTOCMPLT)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002694 /* Wait for 8 sec to give the process
2695 * more time. Perhaps we should fail after a while.
2696 */
Sakari Ailusc659c382011-01-21 10:59:30 +00002697 if (!priv->neg_be_verbose++) {
Joe Perches50624aa2011-03-01 06:56:33 +00002698 pr_info("Giving autonegotiation more time.\n");
2699 pr_info("Please check that your adapter has\n");
2700 pr_info("been properly connected to a HUB or Switch.\n");
2701 pr_info("Trying to establish link in the background...\n");
Sakari Ailusc659c382011-01-21 10:59:30 +00002702 }
2703 tlan_set_timer(dev, (8*HZ), TLAN_TIMER_PHY_FINISH_AN);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002704 return;
2705 }
2706
Joe Perches50624aa2011-03-01 06:56:33 +00002707 netdev_info(dev, "Autonegotiation complete\n");
Sakari Ailusc659c382011-01-21 10:59:30 +00002708 tlan_mii_read_reg(dev, phy, MII_AN_ADV, &an_adv);
2709 tlan_mii_read_reg(dev, phy, MII_AN_LPA, &an_lpa);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002710 mode = an_adv & an_lpa & 0x03E0;
Sakari Ailusc659c382011-01-21 10:59:30 +00002711 if (mode & 0x0100)
2712 priv->tlan_full_duplex = true;
2713 else if (!(mode & 0x0080) && (mode & 0x0040))
2714 priv->tlan_full_duplex = true;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002715
Sakari Ailusc659c382011-01-21 10:59:30 +00002716 if ((!(mode & 0x0180)) &&
2717 (priv->adapter->flags & TLAN_ADAPTER_USE_INTERN_10) &&
2718 (priv->phy_num != 0)) {
2719 priv->phy_num = 0;
2720 data = TLAN_NET_CFG_1FRAG | TLAN_NET_CFG_1CHAN
2721 | TLAN_NET_CFG_PHY_EN;
2722 tlan_dio_write16(dev->base_addr, TLAN_NET_CONFIG, data);
2723 tlan_set_timer(dev, (400*HZ/1000), TLAN_TIMER_PHY_PDOWN);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002724 return;
2725 }
2726
Sakari Ailusc659c382011-01-21 10:59:30 +00002727 if (priv->phy_num == 0) {
2728 if ((priv->duplex == TLAN_DUPLEX_FULL) ||
2729 (an_adv & an_lpa & 0x0040)) {
2730 tlan_mii_write_reg(dev, phy, MII_GEN_CTL,
2731 MII_GC_AUTOENB | MII_GC_DUPLEX);
Joe Perches50624aa2011-03-01 06:56:33 +00002732 netdev_info(dev, "Starting internal PHY with FULL-DUPLEX\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002733 } else {
Sakari Ailusc659c382011-01-21 10:59:30 +00002734 tlan_mii_write_reg(dev, phy, MII_GEN_CTL,
2735 MII_GC_AUTOENB);
Joe Perches50624aa2011-03-01 06:56:33 +00002736 netdev_info(dev, "Starting internal PHY with HALF-DUPLEX\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002737 }
2738 }
2739
2740 /* Wait for 100 ms. No reason in partiticular.
2741 */
Sakari Ailusc659c382011-01-21 10:59:30 +00002742 tlan_set_timer(dev, (HZ/10), TLAN_TIMER_FINISH_RESET);
Jeff Garzik6aa20a22006-09-13 13:24:59 -04002743
Sakari Ailusc659c382011-01-21 10:59:30 +00002744}
Linus Torvalds1da177e2005-04-16 15:20:36 -07002745
Linus Torvalds1da177e2005-04-16 15:20:36 -07002746
Sakari Ailusc659c382011-01-21 10:59:30 +00002747/*********************************************************************
2748 *
2749 * tlan_phy_monitor
2750 *
2751 * Returns:
2752 * None
2753 *
2754 * Params:
Ondrej Zaryc0a87c22014-06-30 18:38:28 +02002755 * data The device structure of this device.
Sakari Ailusc659c382011-01-21 10:59:30 +00002756 *
2757 *
2758 * This function monitors PHY condition by reading the status
Ondrej Zaryc0a87c22014-06-30 18:38:28 +02002759 * register via the MII bus, controls LINK LED and notifies the
2760 * kernel about link state.
Sakari Ailusc659c382011-01-21 10:59:30 +00002761 *
2762 *******************************************************************/
Linus Torvalds1da177e2005-04-16 15:20:36 -07002763
Ondrej Zaryc0a87c22014-06-30 18:38:28 +02002764static void tlan_phy_monitor(unsigned long data)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002765{
Ondrej Zaryc0a87c22014-06-30 18:38:28 +02002766 struct net_device *dev = (struct net_device *) data;
Sakari Ailusc659c382011-01-21 10:59:30 +00002767 struct tlan_priv *priv = netdev_priv(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002768 u16 phy;
2769 u16 phy_status;
2770
Sakari Ailusc659c382011-01-21 10:59:30 +00002771 phy = priv->phy[priv->phy_num];
Linus Torvalds1da177e2005-04-16 15:20:36 -07002772
Sakari Ailusc659c382011-01-21 10:59:30 +00002773 /* Get PHY status register */
2774 tlan_mii_read_reg(dev, phy, MII_GEN_STS, &phy_status);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002775
Sakari Ailusc659c382011-01-21 10:59:30 +00002776 /* Check if link has been lost */
2777 if (!(phy_status & MII_GS_LINK)) {
Ondrej Zaryc0a87c22014-06-30 18:38:28 +02002778 if (netif_carrier_ok(dev)) {
Sakari Ailusc659c382011-01-21 10:59:30 +00002779 printk(KERN_DEBUG "TLAN: %s has lost link\n",
2780 dev->name);
Ondrej Zaryc0a87c22014-06-30 18:38:28 +02002781 tlan_dio_write8(dev->base_addr, TLAN_LED_REG, 0);
Sakari Ailusc659c382011-01-21 10:59:30 +00002782 netif_carrier_off(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002783 }
2784 }
2785
Sakari Ailusc659c382011-01-21 10:59:30 +00002786 /* Link restablished? */
Ondrej Zaryc0a87c22014-06-30 18:38:28 +02002787 if ((phy_status & MII_GS_LINK) && !netif_carrier_ok(dev)) {
2788 tlan_dio_write8(dev->base_addr, TLAN_LED_REG, TLAN_LED_LINK);
Sakari Ailusc659c382011-01-21 10:59:30 +00002789 printk(KERN_DEBUG "TLAN: %s has reestablished link\n",
2790 dev->name);
7d17c1d2005-05-12 19:45:25 -04002791 netif_carrier_on(dev);
Sakari Ailusc659c382011-01-21 10:59:30 +00002792 }
Ondrej Zaryc0a87c22014-06-30 18:38:28 +02002793 priv->media_timer.expires = jiffies + HZ;
2794 add_timer(&priv->media_timer);
Jeff Garzik6aa20a22006-09-13 13:24:59 -04002795}
Linus Torvalds1da177e2005-04-16 15:20:36 -07002796
Linus Torvalds1da177e2005-04-16 15:20:36 -07002797
2798/*****************************************************************************
2799******************************************************************************
2800
Sakari Ailusc659c382011-01-21 10:59:30 +00002801ThunderLAN driver MII routines
Linus Torvalds1da177e2005-04-16 15:20:36 -07002802
Sakari Ailusc659c382011-01-21 10:59:30 +00002803these routines are based on the information in chap. 2 of the
2804"ThunderLAN Programmer's Guide", pp. 15-24.
Linus Torvalds1da177e2005-04-16 15:20:36 -07002805
2806******************************************************************************
2807*****************************************************************************/
2808
2809
Sakari Ailusc659c382011-01-21 10:59:30 +00002810/***************************************************************
2811 * tlan_mii_read_reg
2812 *
2813 * Returns:
2814 * false if ack received ok
2815 * true if no ack received or other error
2816 *
2817 * Parms:
2818 * dev The device structure containing
2819 * The io address and interrupt count
2820 * for this device.
2821 * phy The address of the PHY to be queried.
2822 * reg The register whose contents are to be
2823 * retrieved.
2824 * val A pointer to a variable to store the
2825 * retrieved value.
2826 *
2827 * This function uses the TLAN's MII bus to retrieve the contents
2828 * of a given register on a PHY. It sends the appropriate info
2829 * and then reads the 16-bit register value from the MII bus via
2830 * the TLAN SIO register.
2831 *
2832 **************************************************************/
Linus Torvalds1da177e2005-04-16 15:20:36 -07002833
Sakari Ailusc659c382011-01-21 10:59:30 +00002834static bool
2835tlan_mii_read_reg(struct net_device *dev, u16 phy, u16 reg, u16 *val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002836{
2837 u8 nack;
2838 u16 sio, tmp;
Sakari Ailusc659c382011-01-21 10:59:30 +00002839 u32 i;
Joe Perches37fce432010-01-12 20:59:13 +00002840 bool err;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002841 int minten;
Sakari Ailusc659c382011-01-21 10:59:30 +00002842 struct tlan_priv *priv = netdev_priv(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002843 unsigned long flags = 0;
2844
Joe Perches37fce432010-01-12 20:59:13 +00002845 err = false;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002846 outw(TLAN_NET_SIO, dev->base_addr + TLAN_DIO_ADR);
2847 sio = dev->base_addr + TLAN_DIO_DATA + TLAN_NET_SIO;
Jeff Garzik6aa20a22006-09-13 13:24:59 -04002848
Linus Torvalds1da177e2005-04-16 15:20:36 -07002849 if (!in_irq())
2850 spin_lock_irqsave(&priv->lock, flags);
2851
Sakari Ailusc659c382011-01-21 10:59:30 +00002852 tlan_mii_sync(dev->base_addr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002853
Sakari Ailusc659c382011-01-21 10:59:30 +00002854 minten = tlan_get_bit(TLAN_NET_SIO_MINTEN, sio);
2855 if (minten)
2856 tlan_clear_bit(TLAN_NET_SIO_MINTEN, sio);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002857
Sakari Ailusc659c382011-01-21 10:59:30 +00002858 tlan_mii_send_data(dev->base_addr, 0x1, 2); /* start (01b) */
2859 tlan_mii_send_data(dev->base_addr, 0x2, 2); /* read (10b) */
2860 tlan_mii_send_data(dev->base_addr, phy, 5); /* device # */
2861 tlan_mii_send_data(dev->base_addr, reg, 5); /* register # */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002862
2863
Sakari Ailusc659c382011-01-21 10:59:30 +00002864 tlan_clear_bit(TLAN_NET_SIO_MTXEN, sio); /* change direction */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002865
Sakari Ailusc659c382011-01-21 10:59:30 +00002866 tlan_clear_bit(TLAN_NET_SIO_MCLK, sio); /* clock idle bit */
2867 tlan_set_bit(TLAN_NET_SIO_MCLK, sio);
2868 tlan_clear_bit(TLAN_NET_SIO_MCLK, sio); /* wait 300ns */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002869
Sakari Ailusc659c382011-01-21 10:59:30 +00002870 nack = tlan_get_bit(TLAN_NET_SIO_MDATA, sio); /* check for ACK */
2871 tlan_set_bit(TLAN_NET_SIO_MCLK, sio); /* finish ACK */
2872 if (nack) { /* no ACK, so fake it */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002873 for (i = 0; i < 16; i++) {
Sakari Ailusc659c382011-01-21 10:59:30 +00002874 tlan_clear_bit(TLAN_NET_SIO_MCLK, sio);
2875 tlan_set_bit(TLAN_NET_SIO_MCLK, sio);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002876 }
2877 tmp = 0xffff;
Joe Perches37fce432010-01-12 20:59:13 +00002878 err = true;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002879 } else { /* ACK, so read data */
2880 for (tmp = 0, i = 0x8000; i; i >>= 1) {
Sakari Ailusc659c382011-01-21 10:59:30 +00002881 tlan_clear_bit(TLAN_NET_SIO_MCLK, sio);
2882 if (tlan_get_bit(TLAN_NET_SIO_MDATA, sio))
Linus Torvalds1da177e2005-04-16 15:20:36 -07002883 tmp |= i;
Sakari Ailusc659c382011-01-21 10:59:30 +00002884 tlan_set_bit(TLAN_NET_SIO_MCLK, sio);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002885 }
2886 }
2887
2888
Sakari Ailusc659c382011-01-21 10:59:30 +00002889 tlan_clear_bit(TLAN_NET_SIO_MCLK, sio); /* idle cycle */
2890 tlan_set_bit(TLAN_NET_SIO_MCLK, sio);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002891
Sakari Ailusc659c382011-01-21 10:59:30 +00002892 if (minten)
2893 tlan_set_bit(TLAN_NET_SIO_MINTEN, sio);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002894
2895 *val = tmp;
Jeff Garzik6aa20a22006-09-13 13:24:59 -04002896
Linus Torvalds1da177e2005-04-16 15:20:36 -07002897 if (!in_irq())
2898 spin_unlock_irqrestore(&priv->lock, flags);
2899
2900 return err;
2901
Sakari Ailusc659c382011-01-21 10:59:30 +00002902}
Linus Torvalds1da177e2005-04-16 15:20:36 -07002903
2904
2905
2906
Sakari Ailusc659c382011-01-21 10:59:30 +00002907/***************************************************************
2908 * tlan_mii_send_data
2909 *
2910 * Returns:
2911 * Nothing
2912 * Parms:
2913 * base_port The base IO port of the adapter in
2914 * question.
2915 * dev The address of the PHY to be queried.
2916 * data The value to be placed on the MII bus.
2917 * num_bits The number of bits in data that are to
2918 * be placed on the MII bus.
2919 *
2920 * This function sends on sequence of bits on the MII
2921 * configuration bus.
2922 *
2923 **************************************************************/
Linus Torvalds1da177e2005-04-16 15:20:36 -07002924
Sakari Ailusc659c382011-01-21 10:59:30 +00002925static void tlan_mii_send_data(u16 base_port, u32 data, unsigned num_bits)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002926{
2927 u16 sio;
2928 u32 i;
2929
Sakari Ailusc659c382011-01-21 10:59:30 +00002930 if (num_bits == 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002931 return;
2932
Sakari Ailusc659c382011-01-21 10:59:30 +00002933 outw(TLAN_NET_SIO, base_port + TLAN_DIO_ADR);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002934 sio = base_port + TLAN_DIO_DATA + TLAN_NET_SIO;
Sakari Ailusc659c382011-01-21 10:59:30 +00002935 tlan_set_bit(TLAN_NET_SIO_MTXEN, sio);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002936
Sakari Ailusc659c382011-01-21 10:59:30 +00002937 for (i = (0x1 << (num_bits - 1)); i; i >>= 1) {
2938 tlan_clear_bit(TLAN_NET_SIO_MCLK, sio);
2939 (void) tlan_get_bit(TLAN_NET_SIO_MCLK, sio);
2940 if (data & i)
2941 tlan_set_bit(TLAN_NET_SIO_MDATA, sio);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002942 else
Sakari Ailusc659c382011-01-21 10:59:30 +00002943 tlan_clear_bit(TLAN_NET_SIO_MDATA, sio);
2944 tlan_set_bit(TLAN_NET_SIO_MCLK, sio);
2945 (void) tlan_get_bit(TLAN_NET_SIO_MCLK, sio);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002946 }
2947
Sakari Ailusc659c382011-01-21 10:59:30 +00002948}
Linus Torvalds1da177e2005-04-16 15:20:36 -07002949
2950
2951
2952
Sakari Ailusc659c382011-01-21 10:59:30 +00002953/***************************************************************
2954 * TLan_MiiSync
2955 *
2956 * Returns:
2957 * Nothing
2958 * Parms:
2959 * base_port The base IO port of the adapter in
2960 * question.
2961 *
2962 * This functions syncs all PHYs in terms of the MII configuration
2963 * bus.
2964 *
2965 **************************************************************/
Linus Torvalds1da177e2005-04-16 15:20:36 -07002966
Sakari Ailusc659c382011-01-21 10:59:30 +00002967static void tlan_mii_sync(u16 base_port)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002968{
2969 int i;
2970 u16 sio;
2971
Sakari Ailusc659c382011-01-21 10:59:30 +00002972 outw(TLAN_NET_SIO, base_port + TLAN_DIO_ADR);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002973 sio = base_port + TLAN_DIO_DATA + TLAN_NET_SIO;
2974
Sakari Ailusc659c382011-01-21 10:59:30 +00002975 tlan_clear_bit(TLAN_NET_SIO_MTXEN, sio);
2976 for (i = 0; i < 32; i++) {
2977 tlan_clear_bit(TLAN_NET_SIO_MCLK, sio);
2978 tlan_set_bit(TLAN_NET_SIO_MCLK, sio);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002979 }
2980
Sakari Ailusc659c382011-01-21 10:59:30 +00002981}
Linus Torvalds1da177e2005-04-16 15:20:36 -07002982
2983
2984
2985
Sakari Ailusc659c382011-01-21 10:59:30 +00002986/***************************************************************
2987 * tlan_mii_write_reg
2988 *
2989 * Returns:
2990 * Nothing
2991 * Parms:
2992 * dev The device structure for the device
2993 * to write to.
2994 * phy The address of the PHY to be written to.
2995 * reg The register whose contents are to be
2996 * written.
2997 * val The value to be written to the register.
2998 *
2999 * This function uses the TLAN's MII bus to write the contents of a
3000 * given register on a PHY. It sends the appropriate info and then
3001 * writes the 16-bit register value from the MII configuration bus
3002 * via the TLAN SIO register.
3003 *
3004 **************************************************************/
Linus Torvalds1da177e2005-04-16 15:20:36 -07003005
Sakari Ailusc659c382011-01-21 10:59:30 +00003006static void
3007tlan_mii_write_reg(struct net_device *dev, u16 phy, u16 reg, u16 val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003008{
3009 u16 sio;
3010 int minten;
3011 unsigned long flags = 0;
Sakari Ailusc659c382011-01-21 10:59:30 +00003012 struct tlan_priv *priv = netdev_priv(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003013
3014 outw(TLAN_NET_SIO, dev->base_addr + TLAN_DIO_ADR);
3015 sio = dev->base_addr + TLAN_DIO_DATA + TLAN_NET_SIO;
Jeff Garzik6aa20a22006-09-13 13:24:59 -04003016
Linus Torvalds1da177e2005-04-16 15:20:36 -07003017 if (!in_irq())
3018 spin_lock_irqsave(&priv->lock, flags);
3019
Sakari Ailusc659c382011-01-21 10:59:30 +00003020 tlan_mii_sync(dev->base_addr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003021
Sakari Ailusc659c382011-01-21 10:59:30 +00003022 minten = tlan_get_bit(TLAN_NET_SIO_MINTEN, sio);
3023 if (minten)
3024 tlan_clear_bit(TLAN_NET_SIO_MINTEN, sio);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003025
Sakari Ailusc659c382011-01-21 10:59:30 +00003026 tlan_mii_send_data(dev->base_addr, 0x1, 2); /* start (01b) */
3027 tlan_mii_send_data(dev->base_addr, 0x1, 2); /* write (01b) */
3028 tlan_mii_send_data(dev->base_addr, phy, 5); /* device # */
3029 tlan_mii_send_data(dev->base_addr, reg, 5); /* register # */
Linus Torvalds1da177e2005-04-16 15:20:36 -07003030
Sakari Ailusc659c382011-01-21 10:59:30 +00003031 tlan_mii_send_data(dev->base_addr, 0x2, 2); /* send ACK */
3032 tlan_mii_send_data(dev->base_addr, val, 16); /* send data */
Linus Torvalds1da177e2005-04-16 15:20:36 -07003033
Sakari Ailusc659c382011-01-21 10:59:30 +00003034 tlan_clear_bit(TLAN_NET_SIO_MCLK, sio); /* idle cycle */
3035 tlan_set_bit(TLAN_NET_SIO_MCLK, sio);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003036
Sakari Ailusc659c382011-01-21 10:59:30 +00003037 if (minten)
3038 tlan_set_bit(TLAN_NET_SIO_MINTEN, sio);
Jeff Garzik6aa20a22006-09-13 13:24:59 -04003039
Linus Torvalds1da177e2005-04-16 15:20:36 -07003040 if (!in_irq())
3041 spin_unlock_irqrestore(&priv->lock, flags);
3042
Sakari Ailusc659c382011-01-21 10:59:30 +00003043}
Linus Torvalds1da177e2005-04-16 15:20:36 -07003044
3045
3046
3047
3048/*****************************************************************************
3049******************************************************************************
3050
Sakari Ailusc659c382011-01-21 10:59:30 +00003051ThunderLAN driver eeprom routines
Linus Torvalds1da177e2005-04-16 15:20:36 -07003052
Sakari Ailusc659c382011-01-21 10:59:30 +00003053the Compaq netelligent 10 and 10/100 cards use a microchip 24C02A
3054EEPROM. these functions are based on information in microchip's
3055data sheet. I don't know how well this functions will work with
3056other Eeproms.
Linus Torvalds1da177e2005-04-16 15:20:36 -07003057
3058******************************************************************************
3059*****************************************************************************/
3060
3061
Sakari Ailusc659c382011-01-21 10:59:30 +00003062/***************************************************************
3063 * tlan_ee_send_start
3064 *
3065 * Returns:
3066 * Nothing
3067 * Parms:
3068 * io_base The IO port base address for the
3069 * TLAN device with the EEPROM to
3070 * use.
3071 *
3072 * This function sends a start cycle to an EEPROM attached
3073 * to a TLAN chip.
3074 *
3075 **************************************************************/
Linus Torvalds1da177e2005-04-16 15:20:36 -07003076
Sakari Ailusc659c382011-01-21 10:59:30 +00003077static void tlan_ee_send_start(u16 io_base)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003078{
3079 u16 sio;
3080
Sakari Ailusc659c382011-01-21 10:59:30 +00003081 outw(TLAN_NET_SIO, io_base + TLAN_DIO_ADR);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003082 sio = io_base + TLAN_DIO_DATA + TLAN_NET_SIO;
3083
Sakari Ailusc659c382011-01-21 10:59:30 +00003084 tlan_set_bit(TLAN_NET_SIO_ECLOK, sio);
3085 tlan_set_bit(TLAN_NET_SIO_EDATA, sio);
3086 tlan_set_bit(TLAN_NET_SIO_ETXEN, sio);
3087 tlan_clear_bit(TLAN_NET_SIO_EDATA, sio);
3088 tlan_clear_bit(TLAN_NET_SIO_ECLOK, sio);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003089
Sakari Ailusc659c382011-01-21 10:59:30 +00003090}
Linus Torvalds1da177e2005-04-16 15:20:36 -07003091
3092
3093
3094
Sakari Ailusc659c382011-01-21 10:59:30 +00003095/***************************************************************
3096 * tlan_ee_send_byte
3097 *
3098 * Returns:
3099 * If the correct ack was received, 0, otherwise 1
3100 * Parms: io_base The IO port base address for the
3101 * TLAN device with the EEPROM to
3102 * use.
3103 * data The 8 bits of information to
3104 * send to the EEPROM.
3105 * stop If TLAN_EEPROM_STOP is passed, a
3106 * stop cycle is sent after the
3107 * byte is sent after the ack is
3108 * read.
3109 *
3110 * This function sends a byte on the serial EEPROM line,
3111 * driving the clock to send each bit. The function then
3112 * reverses transmission direction and reads an acknowledge
3113 * bit.
3114 *
3115 **************************************************************/
Linus Torvalds1da177e2005-04-16 15:20:36 -07003116
Sakari Ailusc659c382011-01-21 10:59:30 +00003117static int tlan_ee_send_byte(u16 io_base, u8 data, int stop)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003118{
3119 int err;
3120 u8 place;
3121 u16 sio;
3122
Sakari Ailusc659c382011-01-21 10:59:30 +00003123 outw(TLAN_NET_SIO, io_base + TLAN_DIO_ADR);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003124 sio = io_base + TLAN_DIO_DATA + TLAN_NET_SIO;
3125
3126 /* Assume clock is low, tx is enabled; */
Sakari Ailusc659c382011-01-21 10:59:30 +00003127 for (place = 0x80; place != 0; place >>= 1) {
3128 if (place & data)
3129 tlan_set_bit(TLAN_NET_SIO_EDATA, sio);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003130 else
Sakari Ailusc659c382011-01-21 10:59:30 +00003131 tlan_clear_bit(TLAN_NET_SIO_EDATA, sio);
3132 tlan_set_bit(TLAN_NET_SIO_ECLOK, sio);
3133 tlan_clear_bit(TLAN_NET_SIO_ECLOK, sio);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003134 }
Sakari Ailusc659c382011-01-21 10:59:30 +00003135 tlan_clear_bit(TLAN_NET_SIO_ETXEN, sio);
3136 tlan_set_bit(TLAN_NET_SIO_ECLOK, sio);
3137 err = tlan_get_bit(TLAN_NET_SIO_EDATA, sio);
3138 tlan_clear_bit(TLAN_NET_SIO_ECLOK, sio);
3139 tlan_set_bit(TLAN_NET_SIO_ETXEN, sio);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003140
Sakari Ailusc659c382011-01-21 10:59:30 +00003141 if ((!err) && stop) {
Stephen Hemmingerdfc2c0a2008-05-30 09:49:58 -07003142 /* STOP, raise data while clock is high */
Sakari Ailusc659c382011-01-21 10:59:30 +00003143 tlan_clear_bit(TLAN_NET_SIO_EDATA, sio);
3144 tlan_set_bit(TLAN_NET_SIO_ECLOK, sio);
3145 tlan_set_bit(TLAN_NET_SIO_EDATA, sio);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003146 }
3147
Eric Dumazet807540b2010-09-23 05:40:09 +00003148 return err;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003149
Sakari Ailusc659c382011-01-21 10:59:30 +00003150}
Linus Torvalds1da177e2005-04-16 15:20:36 -07003151
3152
3153
3154
Sakari Ailusc659c382011-01-21 10:59:30 +00003155/***************************************************************
3156 * tlan_ee_receive_byte
3157 *
3158 * Returns:
3159 * Nothing
3160 * Parms:
3161 * io_base The IO port base address for the
3162 * TLAN device with the EEPROM to
3163 * use.
3164 * data An address to a char to hold the
3165 * data sent from the EEPROM.
3166 * stop If TLAN_EEPROM_STOP is passed, a
3167 * stop cycle is sent after the
3168 * byte is received, and no ack is
3169 * sent.
3170 *
3171 * This function receives 8 bits of data from the EEPROM
3172 * over the serial link. It then sends and ack bit, or no
3173 * ack and a stop bit. This function is used to retrieve
3174 * data after the address of a byte in the EEPROM has been
3175 * sent.
3176 *
3177 **************************************************************/
Linus Torvalds1da177e2005-04-16 15:20:36 -07003178
Sakari Ailusc659c382011-01-21 10:59:30 +00003179static void tlan_ee_receive_byte(u16 io_base, u8 *data, int stop)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003180{
3181 u8 place;
3182 u16 sio;
3183
Sakari Ailusc659c382011-01-21 10:59:30 +00003184 outw(TLAN_NET_SIO, io_base + TLAN_DIO_ADR);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003185 sio = io_base + TLAN_DIO_DATA + TLAN_NET_SIO;
3186 *data = 0;
3187
3188 /* Assume clock is low, tx is enabled; */
Sakari Ailusc659c382011-01-21 10:59:30 +00003189 tlan_clear_bit(TLAN_NET_SIO_ETXEN, sio);
3190 for (place = 0x80; place; place >>= 1) {
3191 tlan_set_bit(TLAN_NET_SIO_ECLOK, sio);
3192 if (tlan_get_bit(TLAN_NET_SIO_EDATA, sio))
Linus Torvalds1da177e2005-04-16 15:20:36 -07003193 *data |= place;
Sakari Ailusc659c382011-01-21 10:59:30 +00003194 tlan_clear_bit(TLAN_NET_SIO_ECLOK, sio);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003195 }
3196
Sakari Ailusc659c382011-01-21 10:59:30 +00003197 tlan_set_bit(TLAN_NET_SIO_ETXEN, sio);
3198 if (!stop) {
3199 tlan_clear_bit(TLAN_NET_SIO_EDATA, sio); /* ack = 0 */
3200 tlan_set_bit(TLAN_NET_SIO_ECLOK, sio);
3201 tlan_clear_bit(TLAN_NET_SIO_ECLOK, sio);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003202 } else {
Sakari Ailusc659c382011-01-21 10:59:30 +00003203 tlan_set_bit(TLAN_NET_SIO_EDATA, sio); /* no ack = 1 (?) */
3204 tlan_set_bit(TLAN_NET_SIO_ECLOK, sio);
3205 tlan_clear_bit(TLAN_NET_SIO_ECLOK, sio);
Stephen Hemmingerdfc2c0a2008-05-30 09:49:58 -07003206 /* STOP, raise data while clock is high */
Sakari Ailusc659c382011-01-21 10:59:30 +00003207 tlan_clear_bit(TLAN_NET_SIO_EDATA, sio);
3208 tlan_set_bit(TLAN_NET_SIO_ECLOK, sio);
3209 tlan_set_bit(TLAN_NET_SIO_EDATA, sio);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003210 }
3211
Sakari Ailusc659c382011-01-21 10:59:30 +00003212}
Linus Torvalds1da177e2005-04-16 15:20:36 -07003213
3214
3215
3216
Sakari Ailusc659c382011-01-21 10:59:30 +00003217/***************************************************************
3218 * tlan_ee_read_byte
3219 *
3220 * Returns:
3221 * No error = 0, else, the stage at which the error
3222 * occurred.
3223 * Parms:
3224 * io_base The IO port base address for the
3225 * TLAN device with the EEPROM to
3226 * use.
3227 * ee_addr The address of the byte in the
3228 * EEPROM whose contents are to be
3229 * retrieved.
3230 * data An address to a char to hold the
3231 * data obtained from the EEPROM.
3232 *
3233 * This function reads a byte of information from an byte
3234 * cell in the EEPROM.
3235 *
3236 **************************************************************/
Linus Torvalds1da177e2005-04-16 15:20:36 -07003237
Sakari Ailusc659c382011-01-21 10:59:30 +00003238static int tlan_ee_read_byte(struct net_device *dev, u8 ee_addr, u8 *data)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003239{
3240 int err;
Sakari Ailusc659c382011-01-21 10:59:30 +00003241 struct tlan_priv *priv = netdev_priv(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003242 unsigned long flags = 0;
Sakari Ailusc659c382011-01-21 10:59:30 +00003243 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003244
3245 spin_lock_irqsave(&priv->lock, flags);
3246
Sakari Ailusc659c382011-01-21 10:59:30 +00003247 tlan_ee_send_start(dev->base_addr);
3248 err = tlan_ee_send_byte(dev->base_addr, 0xa0, TLAN_EEPROM_ACK);
3249 if (err) {
3250 ret = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003251 goto fail;
3252 }
Sakari Ailusc659c382011-01-21 10:59:30 +00003253 err = tlan_ee_send_byte(dev->base_addr, ee_addr, TLAN_EEPROM_ACK);
3254 if (err) {
3255 ret = 2;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003256 goto fail;
3257 }
Sakari Ailusc659c382011-01-21 10:59:30 +00003258 tlan_ee_send_start(dev->base_addr);
3259 err = tlan_ee_send_byte(dev->base_addr, 0xa1, TLAN_EEPROM_ACK);
3260 if (err) {
3261 ret = 3;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003262 goto fail;
3263 }
Sakari Ailusc659c382011-01-21 10:59:30 +00003264 tlan_ee_receive_byte(dev->base_addr, data, TLAN_EEPROM_STOP);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003265fail:
3266 spin_unlock_irqrestore(&priv->lock, flags);
3267
3268 return ret;
3269
Sakari Ailusc659c382011-01-21 10:59:30 +00003270}
Linus Torvalds1da177e2005-04-16 15:20:36 -07003271
3272
3273