blob: 60c400f6d01ff540b6a2e132c3520972336adb1a [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
72
73/* Define this to enable Link beat monitoring */
74#undef MONITOR
75
76/* Turn on debugging. See Documentation/networking/tlan.txt for details */
77static int debug;
Stephen Hemminger15efa9b2005-05-04 15:33:11 -070078module_param(debug, int, 0);
79MODULE_PARM_DESC(debug, "ThunderLAN debug mask");
Linus Torvalds1da177e2005-04-16 15:20:36 -070080
Sakari Ailusc659c382011-01-21 10:59:30 +000081static const char tlan_signature[] = "TLAN";
Sakari Ailusfa6d5d42011-01-21 10:59:31 +000082static const char tlan_banner[] = "ThunderLAN driver v1.17\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -070083static int tlan_have_pci;
84static int tlan_have_eisa;
85
Sakari Ailusc659c382011-01-21 10:59:30 +000086static const char * const media[] = {
87 "10BaseT-HD", "10BaseT-FD", "100baseTx-HD",
88 "100BaseTx-FD", "100BaseT4", NULL
Linus Torvalds1da177e2005-04-16 15:20:36 -070089};
90
91static struct board {
Sakari Ailusc659c382011-01-21 10:59:30 +000092 const char *device_label;
93 u32 flags;
94 u16 addr_ofs;
Linus Torvalds1da177e2005-04-16 15:20:36 -070095} board_info[] = {
96 { "Compaq Netelligent 10 T PCI UTP", TLAN_ADAPTER_ACTIVITY_LED, 0x83 },
Sakari Ailusc659c382011-01-21 10:59:30 +000097 { "Compaq Netelligent 10/100 TX PCI UTP",
98 TLAN_ADAPTER_ACTIVITY_LED, 0x83 },
Linus Torvalds1da177e2005-04-16 15:20:36 -070099 { "Compaq Integrated NetFlex-3/P", TLAN_ADAPTER_NONE, 0x83 },
Stephen Hemmingerdfc2c0a2008-05-30 09:49:58 -0700100 { "Compaq NetFlex-3/P",
101 TLAN_ADAPTER_UNMANAGED_PHY | TLAN_ADAPTER_BIT_RATE_PHY, 0x83 },
Linus Torvalds1da177e2005-04-16 15:20:36 -0700102 { "Compaq NetFlex-3/P", TLAN_ADAPTER_NONE, 0x83 },
Stephen Hemmingerdfc2c0a2008-05-30 09:49:58 -0700103 { "Compaq Netelligent Integrated 10/100 TX UTP",
104 TLAN_ADAPTER_ACTIVITY_LED, 0x83 },
Sakari Ailusc659c382011-01-21 10:59:30 +0000105 { "Compaq Netelligent Dual 10/100 TX PCI UTP",
106 TLAN_ADAPTER_NONE, 0x83 },
107 { "Compaq Netelligent 10/100 TX Embedded UTP",
108 TLAN_ADAPTER_NONE, 0x83 },
Linus Torvalds1da177e2005-04-16 15:20:36 -0700109 { "Olicom OC-2183/2185", TLAN_ADAPTER_USE_INTERN_10, 0x83 },
Sakari Ailusc659c382011-01-21 10:59:30 +0000110 { "Olicom OC-2325", TLAN_ADAPTER_UNMANAGED_PHY, 0xf8 },
111 { "Olicom OC-2326", TLAN_ADAPTER_USE_INTERN_10, 0xf8 },
Linus Torvalds1da177e2005-04-16 15:20:36 -0700112 { "Compaq Netelligent 10/100 TX UTP", TLAN_ADAPTER_ACTIVITY_LED, 0x83 },
Sakari Ailusc659c382011-01-21 10:59:30 +0000113 { "Compaq Netelligent 10 T/2 PCI UTP/coax", TLAN_ADAPTER_NONE, 0x83 },
Stephen Hemmingerdfc2c0a2008-05-30 09:49:58 -0700114 { "Compaq NetFlex-3/E",
Sakari Ailusc659c382011-01-21 10:59:30 +0000115 TLAN_ADAPTER_ACTIVITY_LED | /* EISA card */
Stephen Hemmingerdfc2c0a2008-05-30 09:49:58 -0700116 TLAN_ADAPTER_UNMANAGED_PHY | TLAN_ADAPTER_BIT_RATE_PHY, 0x83 },
Sakari Ailusc659c382011-01-21 10:59:30 +0000117 { "Compaq NetFlex-3/E",
118 TLAN_ADAPTER_ACTIVITY_LED, 0x83 }, /* EISA card */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700119};
120
Alexey Dobriyana3aa1882010-01-07 11:58:11 +0000121static DEFINE_PCI_DEVICE_TABLE(tlan_pci_tbl) = {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700122 { PCI_VENDOR_ID_COMPAQ, PCI_DEVICE_ID_COMPAQ_NETEL10,
Sakari Ailusc659c382011-01-21 10:59:30 +0000123 PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0 },
Linus Torvalds1da177e2005-04-16 15:20:36 -0700124 { PCI_VENDOR_ID_COMPAQ, PCI_DEVICE_ID_COMPAQ_NETEL100,
Sakari Ailusc659c382011-01-21 10:59:30 +0000125 PCI_ANY_ID, PCI_ANY_ID, 0, 0, 1 },
Linus Torvalds1da177e2005-04-16 15:20:36 -0700126 { PCI_VENDOR_ID_COMPAQ, PCI_DEVICE_ID_COMPAQ_NETFLEX3I,
Sakari Ailusc659c382011-01-21 10:59:30 +0000127 PCI_ANY_ID, PCI_ANY_ID, 0, 0, 2 },
Linus Torvalds1da177e2005-04-16 15:20:36 -0700128 { PCI_VENDOR_ID_COMPAQ, PCI_DEVICE_ID_COMPAQ_THUNDER,
Sakari Ailusc659c382011-01-21 10:59:30 +0000129 PCI_ANY_ID, PCI_ANY_ID, 0, 0, 3 },
Linus Torvalds1da177e2005-04-16 15:20:36 -0700130 { PCI_VENDOR_ID_COMPAQ, PCI_DEVICE_ID_COMPAQ_NETFLEX3B,
Sakari Ailusc659c382011-01-21 10:59:30 +0000131 PCI_ANY_ID, PCI_ANY_ID, 0, 0, 4 },
Linus Torvalds1da177e2005-04-16 15:20:36 -0700132 { PCI_VENDOR_ID_COMPAQ, PCI_DEVICE_ID_COMPAQ_NETEL100PI,
Sakari Ailusc659c382011-01-21 10:59:30 +0000133 PCI_ANY_ID, PCI_ANY_ID, 0, 0, 5 },
Linus Torvalds1da177e2005-04-16 15:20:36 -0700134 { PCI_VENDOR_ID_COMPAQ, PCI_DEVICE_ID_COMPAQ_NETEL100D,
Sakari Ailusc659c382011-01-21 10:59:30 +0000135 PCI_ANY_ID, PCI_ANY_ID, 0, 0, 6 },
Linus Torvalds1da177e2005-04-16 15:20:36 -0700136 { PCI_VENDOR_ID_COMPAQ, PCI_DEVICE_ID_COMPAQ_NETEL100I,
Sakari Ailusc659c382011-01-21 10:59:30 +0000137 PCI_ANY_ID, PCI_ANY_ID, 0, 0, 7 },
Linus Torvalds1da177e2005-04-16 15:20:36 -0700138 { PCI_VENDOR_ID_OLICOM, PCI_DEVICE_ID_OLICOM_OC2183,
Sakari Ailusc659c382011-01-21 10:59:30 +0000139 PCI_ANY_ID, PCI_ANY_ID, 0, 0, 8 },
Linus Torvalds1da177e2005-04-16 15:20:36 -0700140 { PCI_VENDOR_ID_OLICOM, PCI_DEVICE_ID_OLICOM_OC2325,
Sakari Ailusc659c382011-01-21 10:59:30 +0000141 PCI_ANY_ID, PCI_ANY_ID, 0, 0, 9 },
Linus Torvalds1da177e2005-04-16 15:20:36 -0700142 { PCI_VENDOR_ID_OLICOM, PCI_DEVICE_ID_OLICOM_OC2326,
Sakari Ailusc659c382011-01-21 10:59:30 +0000143 PCI_ANY_ID, PCI_ANY_ID, 0, 0, 10 },
Linus Torvalds1da177e2005-04-16 15:20:36 -0700144 { PCI_VENDOR_ID_COMPAQ, PCI_DEVICE_ID_NETELLIGENT_10_100_WS_5100,
Sakari Ailusc659c382011-01-21 10:59:30 +0000145 PCI_ANY_ID, PCI_ANY_ID, 0, 0, 11 },
Linus Torvalds1da177e2005-04-16 15:20:36 -0700146 { PCI_VENDOR_ID_COMPAQ, PCI_DEVICE_ID_NETELLIGENT_10_T2,
Sakari Ailusc659c382011-01-21 10:59:30 +0000147 PCI_ANY_ID, PCI_ANY_ID, 0, 0, 12 },
Linus Torvalds1da177e2005-04-16 15:20:36 -0700148 { 0,}
149};
Jeff Garzik6aa20a22006-09-13 13:24:59 -0400150MODULE_DEVICE_TABLE(pci, tlan_pci_tbl);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700151
Sakari Ailusc659c382011-01-21 10:59:30 +0000152static void tlan_eisa_probe(void);
153static void tlan_eisa_cleanup(void);
154static int tlan_init(struct net_device *);
155static int tlan_open(struct net_device *dev);
156static netdev_tx_t tlan_start_tx(struct sk_buff *, struct net_device *);
157static irqreturn_t tlan_handle_interrupt(int, void *);
158static int tlan_close(struct net_device *);
159static struct net_device_stats *tlan_get_stats(struct net_device *);
160static void tlan_set_multicast_list(struct net_device *);
161static int tlan_ioctl(struct net_device *dev, struct ifreq *rq, int cmd);
162static int tlan_probe1(struct pci_dev *pdev, long ioaddr,
163 int irq, int rev, const struct pci_device_id *ent);
164static void tlan_tx_timeout(struct net_device *dev);
165static void tlan_tx_timeout_work(struct work_struct *work);
166static int tlan_init_one(struct pci_dev *pdev,
167 const struct pci_device_id *ent);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700168
Sakari Ailusc659c382011-01-21 10:59:30 +0000169static u32 tlan_handle_tx_eof(struct net_device *, u16);
170static u32 tlan_handle_stat_overflow(struct net_device *, u16);
171static u32 tlan_handle_rx_eof(struct net_device *, u16);
172static u32 tlan_handle_dummy(struct net_device *, u16);
173static u32 tlan_handle_tx_eoc(struct net_device *, u16);
174static u32 tlan_handle_status_check(struct net_device *, u16);
175static u32 tlan_handle_rx_eoc(struct net_device *, u16);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700176
Sakari Ailusc659c382011-01-21 10:59:30 +0000177static void tlan_timer(unsigned long);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700178
Sakari Ailusc659c382011-01-21 10:59:30 +0000179static void tlan_reset_lists(struct net_device *);
180static void tlan_free_lists(struct net_device *);
181static void tlan_print_dio(u16);
182static void tlan_print_list(struct tlan_list *, char *, int);
183static void tlan_read_and_clear_stats(struct net_device *, int);
184static void tlan_reset_adapter(struct net_device *);
185static void tlan_finish_reset(struct net_device *);
186static void tlan_set_mac(struct net_device *, int areg, char *mac);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700187
Sakari Ailusc659c382011-01-21 10:59:30 +0000188static void tlan_phy_print(struct net_device *);
189static void tlan_phy_detect(struct net_device *);
190static void tlan_phy_power_down(struct net_device *);
191static void tlan_phy_power_up(struct net_device *);
192static void tlan_phy_reset(struct net_device *);
193static void tlan_phy_start_link(struct net_device *);
194static void tlan_phy_finish_auto_neg(struct net_device *);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700195#ifdef MONITOR
Sakari Ailusc659c382011-01-21 10:59:30 +0000196static void tlan_phy_monitor(struct net_device *);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700197#endif
198
199/*
Sakari Ailusc659c382011-01-21 10:59:30 +0000200 static int tlan_phy_nop(struct net_device *);
201 static int tlan_phy_internal_check(struct net_device *);
202 static int tlan_phy_internal_service(struct net_device *);
203 static int tlan_phy_dp83840a_check(struct net_device *);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700204*/
205
Sakari Ailusc659c382011-01-21 10:59:30 +0000206static bool tlan_mii_read_reg(struct net_device *, u16, u16, u16 *);
207static void tlan_mii_send_data(u16, u32, unsigned);
208static void tlan_mii_sync(u16);
209static void tlan_mii_write_reg(struct net_device *, u16, u16, u16);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700210
Sakari Ailusc659c382011-01-21 10:59:30 +0000211static void tlan_ee_send_start(u16);
212static int tlan_ee_send_byte(u16, u8, int);
213static void tlan_ee_receive_byte(u16, u8 *, int);
214static int tlan_ee_read_byte(struct net_device *, u8, u8 *);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700215
216
Stephen Hemminger93e16842008-05-30 09:49:55 -0700217static inline void
Sakari Ailusc659c382011-01-21 10:59:30 +0000218tlan_store_skb(struct tlan_list *tag, struct sk_buff *skb)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700219{
220 unsigned long addr = (unsigned long)skb;
Stephen Hemminger93e16842008-05-30 09:49:55 -0700221 tag->buffer[9].address = addr;
222 tag->buffer[8].address = upper_32_bits(addr);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700223}
224
Stephen Hemminger93e16842008-05-30 09:49:55 -0700225static inline struct sk_buff *
Sakari Ailusc659c382011-01-21 10:59:30 +0000226tlan_get_skb(const struct tlan_list *tag)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700227{
Stephen Hemminger93e16842008-05-30 09:49:55 -0700228 unsigned long addr;
229
Robert Fitzsimons0d63bea2008-08-09 17:54:02 +0100230 addr = tag->buffer[9].address;
Benjamin Poirierda3a9e92012-04-25 04:49:20 +0000231 addr |= ((unsigned long) tag->buffer[8].address << 16) << 16;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700232 return (struct sk_buff *) addr;
233}
234
Sakari Ailusc659c382011-01-21 10:59:30 +0000235static u32
236(*tlan_int_vector[TLAN_INT_NUMBER_OF_INTS])(struct net_device *, u16) = {
Stephen Hemmingera3ccc782008-05-30 09:49:57 -0700237 NULL,
Sakari Ailusc659c382011-01-21 10:59:30 +0000238 tlan_handle_tx_eof,
239 tlan_handle_stat_overflow,
240 tlan_handle_rx_eof,
241 tlan_handle_dummy,
242 tlan_handle_tx_eoc,
243 tlan_handle_status_check,
244 tlan_handle_rx_eoc
Linus Torvalds1da177e2005-04-16 15:20:36 -0700245};
246
247static inline void
Sakari Ailusc659c382011-01-21 10:59:30 +0000248tlan_set_timer(struct net_device *dev, u32 ticks, u32 type)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700249{
Sakari Ailusc659c382011-01-21 10:59:30 +0000250 struct tlan_priv *priv = netdev_priv(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700251 unsigned long flags = 0;
Jeff Garzik6aa20a22006-09-13 13:24:59 -0400252
Linus Torvalds1da177e2005-04-16 15:20:36 -0700253 if (!in_irq())
254 spin_lock_irqsave(&priv->lock, flags);
Sakari Ailusc659c382011-01-21 10:59:30 +0000255 if (priv->timer.function != NULL &&
256 priv->timer_type != TLAN_TIMER_ACTIVITY) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700257 if (!in_irq())
258 spin_unlock_irqrestore(&priv->lock, flags);
259 return;
260 }
Sakari Ailusc659c382011-01-21 10:59:30 +0000261 priv->timer.function = tlan_timer;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700262 if (!in_irq())
263 spin_unlock_irqrestore(&priv->lock, flags);
264
265 priv->timer.data = (unsigned long) dev;
Sakari Ailusc659c382011-01-21 10:59:30 +0000266 priv->timer_set_at = jiffies;
267 priv->timer_type = type;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700268 mod_timer(&priv->timer, jiffies + ticks);
Jeff Garzik6aa20a22006-09-13 13:24:59 -0400269
Sakari Ailusc659c382011-01-21 10:59:30 +0000270}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700271
272
273/*****************************************************************************
274******************************************************************************
275
Sakari Ailusc659c382011-01-21 10:59:30 +0000276ThunderLAN driver primary functions
Linus Torvalds1da177e2005-04-16 15:20:36 -0700277
Sakari Ailusc659c382011-01-21 10:59:30 +0000278these functions are more or less common to all linux network drivers.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700279
280******************************************************************************
281*****************************************************************************/
282
283
284
285
286
Sakari Ailusc659c382011-01-21 10:59:30 +0000287/***************************************************************
288 * tlan_remove_one
289 *
290 * Returns:
291 * Nothing
292 * Parms:
293 * None
294 *
295 * Goes through the TLanDevices list and frees the device
296 * structs and memory associated with each device (lists
297 * and buffers). It also ureserves the IO port regions
298 * associated with this device.
299 *
300 **************************************************************/
Linus Torvalds1da177e2005-04-16 15:20:36 -0700301
302
Bill Pemberton36915872012-12-03 09:23:44 -0500303static void tlan_remove_one(struct pci_dev *pdev)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700304{
Sakari Ailusc659c382011-01-21 10:59:30 +0000305 struct net_device *dev = pci_get_drvdata(pdev);
306 struct tlan_priv *priv = netdev_priv(dev);
Jeff Garzik6aa20a22006-09-13 13:24:59 -0400307
Sakari Ailusc659c382011-01-21 10:59:30 +0000308 unregister_netdev(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700309
Sakari Ailusc659c382011-01-21 10:59:30 +0000310 if (priv->dma_storage) {
311 pci_free_consistent(priv->pci_dev,
312 priv->dma_size, priv->dma_storage,
313 priv->dma_storage_dma);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700314 }
315
316#ifdef CONFIG_PCI
317 pci_release_regions(pdev);
318#endif
Jeff Garzik6aa20a22006-09-13 13:24:59 -0400319
Sakari Ailusc659c382011-01-21 10:59:30 +0000320 free_netdev(dev);
Jeff Garzik6aa20a22006-09-13 13:24:59 -0400321
Sakari Ailusc659c382011-01-21 10:59:30 +0000322 pci_set_drvdata(pdev, NULL);
Devendra Naga1e0a8b12013-04-16 01:30:38 +0000323 cancel_work_sync(&priv->tlan_tqueue);
Jeff Garzik6aa20a22006-09-13 13:24:59 -0400324}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700325
Sakari Ailusfa6d5d42011-01-21 10:59:31 +0000326static void tlan_start(struct net_device *dev)
327{
328 tlan_reset_lists(dev);
329 /* NOTE: It might not be necessary to read the stats before a
330 reset if you don't care what the values are.
331 */
332 tlan_read_and_clear_stats(dev, TLAN_IGNORE);
333 tlan_reset_adapter(dev);
334 netif_wake_queue(dev);
335}
336
337static void tlan_stop(struct net_device *dev)
338{
339 struct tlan_priv *priv = netdev_priv(dev);
340
341 tlan_read_and_clear_stats(dev, TLAN_RECORD);
342 outl(TLAN_HC_AD_RST, dev->base_addr + TLAN_HOST_CMD);
343 /* Reset and power down phy */
344 tlan_reset_adapter(dev);
345 if (priv->timer.function != NULL) {
346 del_timer_sync(&priv->timer);
347 priv->timer.function = NULL;
348 }
349}
350
351#ifdef CONFIG_PM
352
353static int tlan_suspend(struct pci_dev *pdev, pm_message_t state)
354{
355 struct net_device *dev = pci_get_drvdata(pdev);
356
357 if (netif_running(dev))
358 tlan_stop(dev);
359
360 netif_device_detach(dev);
361 pci_save_state(pdev);
362 pci_disable_device(pdev);
363 pci_wake_from_d3(pdev, false);
364 pci_set_power_state(pdev, PCI_D3hot);
365
366 return 0;
367}
368
369static int tlan_resume(struct pci_dev *pdev)
370{
371 struct net_device *dev = pci_get_drvdata(pdev);
372
373 pci_set_power_state(pdev, PCI_D0);
374 pci_restore_state(pdev);
375 pci_enable_wake(pdev, 0, 0);
376 netif_device_attach(dev);
377
378 if (netif_running(dev))
379 tlan_start(dev);
380
381 return 0;
382}
383
384#else /* CONFIG_PM */
385
386#define tlan_suspend NULL
387#define tlan_resume NULL
388
389#endif /* CONFIG_PM */
390
391
Linus Torvalds1da177e2005-04-16 15:20:36 -0700392static struct pci_driver tlan_driver = {
393 .name = "tlan",
394 .id_table = tlan_pci_tbl,
395 .probe = tlan_init_one,
Bill Pemberton36915872012-12-03 09:23:44 -0500396 .remove = tlan_remove_one,
Sakari Ailusfa6d5d42011-01-21 10:59:31 +0000397 .suspend = tlan_suspend,
398 .resume = tlan_resume,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700399};
400
401static int __init tlan_probe(void)
402{
Leonardo Potenza6c04a512008-02-04 23:47:16 -0800403 int rc = -ENODEV;
Jeff Garzik6aa20a22006-09-13 13:24:59 -0400404
Joe Perches50624aa2011-03-01 06:56:33 +0000405 pr_info("%s", tlan_banner);
Jeff Garzik6aa20a22006-09-13 13:24:59 -0400406
Linus Torvalds1da177e2005-04-16 15:20:36 -0700407 TLAN_DBG(TLAN_DEBUG_PROBE, "Starting PCI Probe....\n");
Jeff Garzik6aa20a22006-09-13 13:24:59 -0400408
Linus Torvalds1da177e2005-04-16 15:20:36 -0700409 /* Use new style PCI probing. Now the kernel will
410 do most of this for us */
Leonardo Potenza6c04a512008-02-04 23:47:16 -0800411 rc = pci_register_driver(&tlan_driver);
412
413 if (rc != 0) {
Joe Perches50624aa2011-03-01 06:56:33 +0000414 pr_err("Could not register pci driver\n");
Leonardo Potenza6c04a512008-02-04 23:47:16 -0800415 goto err_out_pci_free;
416 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700417
418 TLAN_DBG(TLAN_DEBUG_PROBE, "Starting EISA Probe....\n");
Sakari Ailusc659c382011-01-21 10:59:30 +0000419 tlan_eisa_probe();
Jeff Garzik6aa20a22006-09-13 13:24:59 -0400420
Joe Perches50624aa2011-03-01 06:56:33 +0000421 pr_info("%d device%s installed, PCI: %d EISA: %d\n",
422 tlan_devices_installed, tlan_devices_installed == 1 ? "" : "s",
423 tlan_have_pci, tlan_have_eisa);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700424
Sakari Ailusc659c382011-01-21 10:59:30 +0000425 if (tlan_devices_installed == 0) {
Leonardo Potenza6c04a512008-02-04 23:47:16 -0800426 rc = -ENODEV;
427 goto err_out_pci_unreg;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700428 }
429 return 0;
Leonardo Potenza6c04a512008-02-04 23:47:16 -0800430
431err_out_pci_unreg:
432 pci_unregister_driver(&tlan_driver);
433err_out_pci_free:
Leonardo Potenza6c04a512008-02-04 23:47:16 -0800434 return rc;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700435}
Jeff Garzik6aa20a22006-09-13 13:24:59 -0400436
Linus Torvalds1da177e2005-04-16 15:20:36 -0700437
Bill Pemberton36915872012-12-03 09:23:44 -0500438static int tlan_init_one(struct pci_dev *pdev,
Sakari Ailusc659c382011-01-21 10:59:30 +0000439 const struct pci_device_id *ent)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700440{
Sakari Ailusc659c382011-01-21 10:59:30 +0000441 return tlan_probe1(pdev, -1, -1, 0, ent);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700442}
443
444
445/*
Sakari Ailusc659c382011-01-21 10:59:30 +0000446***************************************************************
447* tlan_probe1
448*
449* Returns:
450* 0 on success, error code on error
451* Parms:
452* none
453*
454* The name is lower case to fit in with all the rest of
455* the netcard_probe names. This function looks for
456* another TLan based adapter, setting it up with the
457* allocated device struct if one is found.
458* tlan_probe has been ported to the new net API and
459* now allocates its own device structure. This function
460* is also used by modules.
461*
462**************************************************************/
Linus Torvalds1da177e2005-04-16 15:20:36 -0700463
Greg Kroah-Hartman1dd06ae2012-12-06 14:30:56 +0000464static int tlan_probe1(struct pci_dev *pdev, long ioaddr, int irq, int rev,
465 const struct pci_device_id *ent)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700466{
467
468 struct net_device *dev;
Sakari Ailusc659c382011-01-21 10:59:30 +0000469 struct tlan_priv *priv;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700470 u16 device_id;
471 int reg, rc = -ENODEV;
472
Adrian Bunkad9f6712006-02-05 00:37:47 +0100473#ifdef CONFIG_PCI
Linus Torvalds1da177e2005-04-16 15:20:36 -0700474 if (pdev) {
475 rc = pci_enable_device(pdev);
476 if (rc)
477 return rc;
478
Sakari Ailusc659c382011-01-21 10:59:30 +0000479 rc = pci_request_regions(pdev, tlan_signature);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700480 if (rc) {
Joe Perches50624aa2011-03-01 06:56:33 +0000481 pr_err("Could not reserve IO regions\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700482 goto err_out;
483 }
484 }
Adrian Bunkad9f6712006-02-05 00:37:47 +0100485#endif /* CONFIG_PCI */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700486
Sakari Ailusc659c382011-01-21 10:59:30 +0000487 dev = alloc_etherdev(sizeof(struct tlan_priv));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700488 if (dev == NULL) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700489 rc = -ENOMEM;
490 goto err_out_regions;
491 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700492 SET_NETDEV_DEV(dev, &pdev->dev);
Jeff Garzik6aa20a22006-09-13 13:24:59 -0400493
Linus Torvalds1da177e2005-04-16 15:20:36 -0700494 priv = netdev_priv(dev);
495
Sakari Ailusc659c382011-01-21 10:59:30 +0000496 priv->pci_dev = pdev;
David Howellsc4028952006-11-22 14:57:56 +0000497 priv->dev = dev;
Jeff Garzik6aa20a22006-09-13 13:24:59 -0400498
Linus Torvalds1da177e2005-04-16 15:20:36 -0700499 /* Is this a PCI device? */
500 if (pdev) {
Sakari Ailusc659c382011-01-21 10:59:30 +0000501 u32 pci_io_base = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700502
503 priv->adapter = &board_info[ent->driver_data];
504
Yang Hongyang284901a2009-04-06 19:01:15 -0700505 rc = pci_set_dma_mask(pdev, DMA_BIT_MASK(32));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700506 if (rc) {
Joe Perches50624aa2011-03-01 06:56:33 +0000507 pr_err("No suitable PCI mapping available\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700508 goto err_out_free_dev;
509 }
510
Sakari Ailusc659c382011-01-21 10:59:30 +0000511 for (reg = 0; reg <= 5; reg++) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700512 if (pci_resource_flags(pdev, reg) & IORESOURCE_IO) {
513 pci_io_base = pci_resource_start(pdev, reg);
Sakari Ailusc659c382011-01-21 10:59:30 +0000514 TLAN_DBG(TLAN_DEBUG_GNRL,
515 "IO mapping is available at %x.\n",
516 pci_io_base);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700517 break;
518 }
519 }
520 if (!pci_io_base) {
Joe Perches50624aa2011-03-01 06:56:33 +0000521 pr_err("No IO mappings available\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700522 rc = -EIO;
523 goto err_out_free_dev;
524 }
Jeff Garzik6aa20a22006-09-13 13:24:59 -0400525
Linus Torvalds1da177e2005-04-16 15:20:36 -0700526 dev->base_addr = pci_io_base;
527 dev->irq = pdev->irq;
Sakari Ailusc659c382011-01-21 10:59:30 +0000528 priv->adapter_rev = pdev->revision;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700529 pci_set_master(pdev);
530 pci_set_drvdata(pdev, dev);
531
532 } else { /* EISA card */
533 /* This is a hack. We need to know which board structure
534 * is suited for this adapter */
535 device_id = inw(ioaddr + EISA_ID2);
536 priv->is_eisa = 1;
537 if (device_id == 0x20F1) {
Sakari Ailusc659c382011-01-21 10:59:30 +0000538 priv->adapter = &board_info[13]; /* NetFlex-3/E */
539 priv->adapter_rev = 23; /* TLAN 2.3 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700540 } else {
541 priv->adapter = &board_info[14];
Sakari Ailusc659c382011-01-21 10:59:30 +0000542 priv->adapter_rev = 10; /* TLAN 1.0 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700543 }
544 dev->base_addr = ioaddr;
545 dev->irq = irq;
546 }
547
548 /* Kernel parameters */
549 if (dev->mem_start) {
550 priv->aui = dev->mem_start & 0x01;
Stephen Hemmingerdfc2c0a2008-05-30 09:49:58 -0700551 priv->duplex = ((dev->mem_start & 0x06) == 0x06) ? 0
552 : (dev->mem_start & 0x06) >> 1;
553 priv->speed = ((dev->mem_start & 0x18) == 0x18) ? 0
554 : (dev->mem_start & 0x18) >> 3;
Jeff Garzik6aa20a22006-09-13 13:24:59 -0400555
Sakari Ailusc659c382011-01-21 10:59:30 +0000556 if (priv->speed == 0x1)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700557 priv->speed = TLAN_SPEED_10;
Sakari Ailusc659c382011-01-21 10:59:30 +0000558 else if (priv->speed == 0x2)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700559 priv->speed = TLAN_SPEED_100;
Sakari Ailusc659c382011-01-21 10:59:30 +0000560
Linus Torvalds1da177e2005-04-16 15:20:36 -0700561 debug = priv->debug = dev->mem_end;
562 } else {
563 priv->aui = aui[boards_found];
564 priv->speed = speed[boards_found];
565 priv->duplex = duplex[boards_found];
566 priv->debug = debug;
567 }
Jeff Garzik6aa20a22006-09-13 13:24:59 -0400568
Linus Torvalds1da177e2005-04-16 15:20:36 -0700569 /* This will be used when we get an adapter error from
570 * within our irq handler */
Sakari Ailusc659c382011-01-21 10:59:30 +0000571 INIT_WORK(&priv->tlan_tqueue, tlan_tx_timeout_work);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700572
573 spin_lock_init(&priv->lock);
Jeff Garzik6aa20a22006-09-13 13:24:59 -0400574
Sakari Ailusc659c382011-01-21 10:59:30 +0000575 rc = tlan_init(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700576 if (rc) {
Joe Perches50624aa2011-03-01 06:56:33 +0000577 pr_err("Could not set up device\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700578 goto err_out_free_dev;
579 }
580
581 rc = register_netdev(dev);
582 if (rc) {
Joe Perches50624aa2011-03-01 06:56:33 +0000583 pr_err("Could not register device\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700584 goto err_out_uninit;
585 }
586
Jeff Garzik6aa20a22006-09-13 13:24:59 -0400587
Sakari Ailusc659c382011-01-21 10:59:30 +0000588 tlan_devices_installed++;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700589 boards_found++;
Jeff Garzik6aa20a22006-09-13 13:24:59 -0400590
Linus Torvalds1da177e2005-04-16 15:20:36 -0700591 /* pdev is NULL if this is an EISA device */
592 if (pdev)
593 tlan_have_pci++;
594 else {
Sakari Ailusc659c382011-01-21 10:59:30 +0000595 priv->next_device = tlan_eisa_devices;
596 tlan_eisa_devices = dev;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700597 tlan_have_eisa++;
598 }
Jeff Garzik6aa20a22006-09-13 13:24:59 -0400599
Joe Perches50624aa2011-03-01 06:56:33 +0000600 netdev_info(dev, "irq=%2d, io=%04x, %s, Rev. %d\n",
601 (int)dev->irq,
602 (int)dev->base_addr,
603 priv->adapter->device_label,
604 priv->adapter_rev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700605 return 0;
606
607err_out_uninit:
Sakari Ailusc659c382011-01-21 10:59:30 +0000608 pci_free_consistent(priv->pci_dev, priv->dma_size, priv->dma_storage,
609 priv->dma_storage_dma);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700610err_out_free_dev:
611 free_netdev(dev);
612err_out_regions:
613#ifdef CONFIG_PCI
614 if (pdev)
615 pci_release_regions(pdev);
616#endif
617err_out:
618 if (pdev)
619 pci_disable_device(pdev);
620 return rc;
621}
622
623
Sakari Ailusc659c382011-01-21 10:59:30 +0000624static void tlan_eisa_cleanup(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700625{
626 struct net_device *dev;
Sakari Ailusc659c382011-01-21 10:59:30 +0000627 struct tlan_priv *priv;
Jeff Garzik6aa20a22006-09-13 13:24:59 -0400628
Sakari Ailusc659c382011-01-21 10:59:30 +0000629 while (tlan_have_eisa) {
630 dev = tlan_eisa_devices;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700631 priv = netdev_priv(dev);
Sakari Ailusc659c382011-01-21 10:59:30 +0000632 if (priv->dma_storage) {
633 pci_free_consistent(priv->pci_dev, priv->dma_size,
634 priv->dma_storage,
635 priv->dma_storage_dma);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700636 }
Sakari Ailusc659c382011-01-21 10:59:30 +0000637 release_region(dev->base_addr, 0x10);
638 unregister_netdev(dev);
639 tlan_eisa_devices = priv->next_device;
640 free_netdev(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700641 tlan_have_eisa--;
642 }
643}
Jeff Garzik6aa20a22006-09-13 13:24:59 -0400644
645
Linus Torvalds1da177e2005-04-16 15:20:36 -0700646static void __exit tlan_exit(void)
647{
648 pci_unregister_driver(&tlan_driver);
649
650 if (tlan_have_eisa)
Sakari Ailusc659c382011-01-21 10:59:30 +0000651 tlan_eisa_cleanup();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700652
Linus Torvalds1da177e2005-04-16 15:20:36 -0700653}
654
655
656/* Module loading/unloading */
657module_init(tlan_probe);
658module_exit(tlan_exit);
659
660
661
Sakari Ailusc659c382011-01-21 10:59:30 +0000662/**************************************************************
663 * tlan_eisa_probe
664 *
665 * Returns: 0 on success, 1 otherwise
666 *
667 * Parms: None
668 *
669 *
670 * This functions probes for EISA devices and calls
671 * TLan_probe1 when one is found.
672 *
673 *************************************************************/
Linus Torvalds1da177e2005-04-16 15:20:36 -0700674
Sakari Ailusc659c382011-01-21 10:59:30 +0000675static void __init tlan_eisa_probe(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700676{
Sakari Ailusc659c382011-01-21 10:59:30 +0000677 long ioaddr;
678 int rc = -ENODEV;
679 int irq;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700680 u16 device_id;
681
Jeff Garzik6aa20a22006-09-13 13:24:59 -0400682 if (!EISA_bus) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700683 TLAN_DBG(TLAN_DEBUG_PROBE, "No EISA bus present\n");
684 return;
685 }
Jeff Garzik6aa20a22006-09-13 13:24:59 -0400686
Linus Torvalds1da177e2005-04-16 15:20:36 -0700687 /* Loop through all slots of the EISA bus */
688 for (ioaddr = 0x1000; ioaddr < 0x9000; ioaddr += 0x1000) {
Jeff Garzik6aa20a22006-09-13 13:24:59 -0400689
Sakari Ailusc659c382011-01-21 10:59:30 +0000690 TLAN_DBG(TLAN_DEBUG_PROBE, "EISA_ID 0x%4x: 0x%4x\n",
691 (int) ioaddr + 0xc80, inw(ioaddr + EISA_ID));
692 TLAN_DBG(TLAN_DEBUG_PROBE, "EISA_ID 0x%4x: 0x%4x\n",
693 (int) ioaddr + 0xc82, inw(ioaddr + EISA_ID2));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700694
695
Sakari Ailusc659c382011-01-21 10:59:30 +0000696 TLAN_DBG(TLAN_DEBUG_PROBE,
697 "Probing for EISA adapter at IO: 0x%4x : ",
698 (int) ioaddr);
699 if (request_region(ioaddr, 0x10, tlan_signature) == NULL)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700700 goto out;
701
Jeff Garzik6aa20a22006-09-13 13:24:59 -0400702 if (inw(ioaddr + EISA_ID) != 0x110E) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700703 release_region(ioaddr, 0x10);
704 goto out;
705 }
Jeff Garzik6aa20a22006-09-13 13:24:59 -0400706
Linus Torvalds1da177e2005-04-16 15:20:36 -0700707 device_id = inw(ioaddr + EISA_ID2);
Jeff Garzik6aa20a22006-09-13 13:24:59 -0400708 if (device_id != 0x20F1 && device_id != 0x40F1) {
Sakari Ailusc659c382011-01-21 10:59:30 +0000709 release_region(ioaddr, 0x10);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700710 goto out;
711 }
Jeff Garzik6aa20a22006-09-13 13:24:59 -0400712
Sakari Ailusc659c382011-01-21 10:59:30 +0000713 /* check if adapter is enabled */
714 if (inb(ioaddr + EISA_CR) != 0x1) {
715 release_region(ioaddr, 0x10);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700716 goto out2;
717 }
Jeff Garzik6aa20a22006-09-13 13:24:59 -0400718
719 if (debug == 0x10)
Joe Perches50624aa2011-03-01 06:56:33 +0000720 pr_info("Found one\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700721
722
723 /* Get irq from board */
Sakari Ailusc659c382011-01-21 10:59:30 +0000724 switch (inb(ioaddr + 0xcc0)) {
725 case(0x10):
726 irq = 5;
727 break;
728 case(0x20):
729 irq = 9;
730 break;
731 case(0x40):
732 irq = 10;
733 break;
734 case(0x80):
735 irq = 11;
736 break;
737 default:
738 goto out;
Jeff Garzik6aa20a22006-09-13 13:24:59 -0400739 }
740
741
Linus Torvalds1da177e2005-04-16 15:20:36 -0700742 /* Setup the newly found eisa adapter */
Sakari Ailusc659c382011-01-21 10:59:30 +0000743 rc = tlan_probe1(NULL, ioaddr, irq,
744 12, NULL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700745 continue;
Jeff Garzik6aa20a22006-09-13 13:24:59 -0400746
Sakari Ailusc659c382011-01-21 10:59:30 +0000747out:
748 if (debug == 0x10)
Joe Perches50624aa2011-03-01 06:56:33 +0000749 pr_info("None found\n");
Sakari Ailusc659c382011-01-21 10:59:30 +0000750 continue;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700751
Sakari Ailusc659c382011-01-21 10:59:30 +0000752out2:
753 if (debug == 0x10)
Joe Perches50624aa2011-03-01 06:56:33 +0000754 pr_info("Card found but it is not enabled, skipping\n");
Sakari Ailusc659c382011-01-21 10:59:30 +0000755 continue;
Jeff Garzik6aa20a22006-09-13 13:24:59 -0400756
Linus Torvalds1da177e2005-04-16 15:20:36 -0700757 }
758
Sakari Ailusc659c382011-01-21 10:59:30 +0000759}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700760
761#ifdef CONFIG_NET_POLL_CONTROLLER
Sakari Ailusc659c382011-01-21 10:59:30 +0000762static void tlan_poll(struct net_device *dev)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700763{
764 disable_irq(dev->irq);
Sakari Ailusc659c382011-01-21 10:59:30 +0000765 tlan_handle_interrupt(dev->irq, dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700766 enable_irq(dev->irq);
767}
768#endif
769
Sakari Ailusc659c382011-01-21 10:59:30 +0000770static const struct net_device_ops tlan_netdev_ops = {
771 .ndo_open = tlan_open,
772 .ndo_stop = tlan_close,
773 .ndo_start_xmit = tlan_start_tx,
774 .ndo_tx_timeout = tlan_tx_timeout,
775 .ndo_get_stats = tlan_get_stats,
Jiri Pirkoafc4b132011-08-16 06:29:01 +0000776 .ndo_set_rx_mode = tlan_set_multicast_list,
Sakari Ailusc659c382011-01-21 10:59:30 +0000777 .ndo_do_ioctl = tlan_ioctl,
Stephen Hemminger391c5e62009-01-07 17:27:15 -0800778 .ndo_change_mtu = eth_change_mtu,
Sakari Ailusc659c382011-01-21 10:59:30 +0000779 .ndo_set_mac_address = eth_mac_addr,
Stephen Hemminger391c5e62009-01-07 17:27:15 -0800780 .ndo_validate_addr = eth_validate_addr,
781#ifdef CONFIG_NET_POLL_CONTROLLER
Sakari Ailusc659c382011-01-21 10:59:30 +0000782 .ndo_poll_controller = tlan_poll,
Stephen Hemminger391c5e62009-01-07 17:27:15 -0800783#endif
784};
Jeff Garzik6aa20a22006-09-13 13:24:59 -0400785
Linus Torvalds1da177e2005-04-16 15:20:36 -0700786
787
Sakari Ailusc659c382011-01-21 10:59:30 +0000788/***************************************************************
789 * tlan_init
790 *
791 * Returns:
792 * 0 on success, error code otherwise.
793 * Parms:
794 * dev The structure of the device to be
795 * init'ed.
796 *
797 * This function completes the initialization of the
798 * device structure and driver. It reserves the IO
799 * addresses, allocates memory for the lists and bounce
800 * buffers, retrieves the MAC address from the eeprom
801 * and assignes the device's methods.
802 *
803 **************************************************************/
Linus Torvalds1da177e2005-04-16 15:20:36 -0700804
Sakari Ailusc659c382011-01-21 10:59:30 +0000805static int tlan_init(struct net_device *dev)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700806{
807 int dma_size;
Sakari Ailusc659c382011-01-21 10:59:30 +0000808 int err;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700809 int i;
Sakari Ailusc659c382011-01-21 10:59:30 +0000810 struct tlan_priv *priv;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700811
812 priv = netdev_priv(dev);
Jeff Garzik6aa20a22006-09-13 13:24:59 -0400813
Sakari Ailusc659c382011-01-21 10:59:30 +0000814 dma_size = (TLAN_NUM_RX_LISTS + TLAN_NUM_TX_LISTS)
815 * (sizeof(struct tlan_list));
816 priv->dma_storage = pci_alloc_consistent(priv->pci_dev,
817 dma_size,
818 &priv->dma_storage_dma);
819 priv->dma_size = dma_size;
Jeff Garzik6aa20a22006-09-13 13:24:59 -0400820
Sakari Ailusc659c382011-01-21 10:59:30 +0000821 if (priv->dma_storage == NULL) {
Joe Perches50624aa2011-03-01 06:56:33 +0000822 pr_err("Could not allocate lists and buffers for %s\n",
Sakari Ailusc659c382011-01-21 10:59:30 +0000823 dev->name);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700824 return -ENOMEM;
825 }
Sakari Ailusc659c382011-01-21 10:59:30 +0000826 memset(priv->dma_storage, 0, dma_size);
827 priv->rx_list = (struct tlan_list *)
828 ALIGN((unsigned long)priv->dma_storage, 8);
829 priv->rx_list_dma = ALIGN(priv->dma_storage_dma, 8);
830 priv->tx_list = priv->rx_list + TLAN_NUM_RX_LISTS;
831 priv->tx_list_dma =
832 priv->rx_list_dma + sizeof(struct tlan_list)*TLAN_NUM_RX_LISTS;
Stephen Hemminger93e16842008-05-30 09:49:55 -0700833
Linus Torvalds1da177e2005-04-16 15:20:36 -0700834 err = 0;
Sakari Ailusc659c382011-01-21 10:59:30 +0000835 for (i = 0; i < 6 ; i++)
836 err |= tlan_ee_read_byte(dev,
837 (u8) priv->adapter->addr_ofs + i,
838 (u8 *) &dev->dev_addr[i]);
839 if (err) {
Joe Perches50624aa2011-03-01 06:56:33 +0000840 pr_err("%s: Error reading MAC from eeprom: %d\n",
841 dev->name, err);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700842 }
843 dev->addr_len = 6;
844
845 netif_carrier_off(dev);
846
847 /* Device methods */
Sakari Ailusc659c382011-01-21 10:59:30 +0000848 dev->netdev_ops = &tlan_netdev_ops;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700849 dev->watchdog_timeo = TX_TIMEOUT;
850
851 return 0;
852
Sakari Ailusc659c382011-01-21 10:59:30 +0000853}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700854
855
856
857
Sakari Ailusc659c382011-01-21 10:59:30 +0000858/***************************************************************
859 * tlan_open
860 *
861 * Returns:
862 * 0 on success, error code otherwise.
863 * Parms:
864 * dev Structure of device to be opened.
865 *
866 * This routine puts the driver and TLAN adapter in a
867 * state where it is ready to send and receive packets.
868 * It allocates the IRQ, resets and brings the adapter
869 * out of reset, and allows interrupts. It also delays
870 * the startup for autonegotiation or sends a Rx GO
871 * command to the adapter, as appropriate.
872 *
873 **************************************************************/
Linus Torvalds1da177e2005-04-16 15:20:36 -0700874
Sakari Ailusc659c382011-01-21 10:59:30 +0000875static int tlan_open(struct net_device *dev)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700876{
Sakari Ailusc659c382011-01-21 10:59:30 +0000877 struct tlan_priv *priv = netdev_priv(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700878 int err;
Jeff Garzik6aa20a22006-09-13 13:24:59 -0400879
Sakari Ailusc659c382011-01-21 10:59:30 +0000880 priv->tlan_rev = tlan_dio_read8(dev->base_addr, TLAN_DEF_REVISION);
881 err = request_irq(dev->irq, tlan_handle_interrupt, IRQF_SHARED,
882 dev->name, dev);
Jeff Garzik6aa20a22006-09-13 13:24:59 -0400883
Sakari Ailusc659c382011-01-21 10:59:30 +0000884 if (err) {
Joe Perches50624aa2011-03-01 06:56:33 +0000885 netdev_err(dev, "Cannot open because IRQ %d is already in use\n",
886 dev->irq);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700887 return err;
888 }
Jeff Garzik6aa20a22006-09-13 13:24:59 -0400889
Linus Torvalds1da177e2005-04-16 15:20:36 -0700890 init_timer(&priv->timer);
Jeff Garzik6aa20a22006-09-13 13:24:59 -0400891
Sakari Ailusfa6d5d42011-01-21 10:59:31 +0000892 tlan_start(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700893
Sakari Ailusc659c382011-01-21 10:59:30 +0000894 TLAN_DBG(TLAN_DEBUG_GNRL, "%s: Opened. TLAN Chip Rev: %x\n",
895 dev->name, priv->tlan_rev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700896
897 return 0;
898
Sakari Ailusc659c382011-01-21 10:59:30 +0000899}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700900
901
902
Sakari Ailusc659c382011-01-21 10:59:30 +0000903/**************************************************************
904 * tlan_ioctl
905 *
906 * Returns:
907 * 0 on success, error code otherwise
908 * Params:
909 * dev structure of device to receive ioctl.
910 *
911 * rq ifreq structure to hold userspace data.
912 *
913 * cmd ioctl command.
914 *
915 *
916 *************************************************************/
Linus Torvalds1da177e2005-04-16 15:20:36 -0700917
Sakari Ailusc659c382011-01-21 10:59:30 +0000918static int tlan_ioctl(struct net_device *dev, struct ifreq *rq, int cmd)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700919{
Sakari Ailusc659c382011-01-21 10:59:30 +0000920 struct tlan_priv *priv = netdev_priv(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700921 struct mii_ioctl_data *data = if_mii(rq);
Sakari Ailusc659c382011-01-21 10:59:30 +0000922 u32 phy = priv->phy[priv->phy_num];
Jeff Garzik6aa20a22006-09-13 13:24:59 -0400923
Sakari Ailusc659c382011-01-21 10:59:30 +0000924 if (!priv->phy_online)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700925 return -EAGAIN;
926
Sakari Ailusc659c382011-01-21 10:59:30 +0000927 switch (cmd) {
928 case SIOCGMIIPHY: /* get address of MII PHY in use. */
929 data->phy_id = phy;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700930
931
Sakari Ailusc659c382011-01-21 10:59:30 +0000932 case SIOCGMIIREG: /* read MII PHY register. */
933 tlan_mii_read_reg(dev, data->phy_id & 0x1f,
934 data->reg_num & 0x1f, &data->val_out);
935 return 0;
Jeff Garzik6aa20a22006-09-13 13:24:59 -0400936
Linus Torvalds1da177e2005-04-16 15:20:36 -0700937
Sakari Ailusc659c382011-01-21 10:59:30 +0000938 case SIOCSMIIREG: /* write MII PHY register. */
939 tlan_mii_write_reg(dev, data->phy_id & 0x1f,
940 data->reg_num & 0x1f, data->val_in);
941 return 0;
942 default:
943 return -EOPNOTSUPP;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700944 }
Sakari Ailusc659c382011-01-21 10:59:30 +0000945}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700946
947
Sakari Ailusc659c382011-01-21 10:59:30 +0000948/***************************************************************
949 * tlan_tx_timeout
950 *
951 * Returns: nothing
952 *
953 * Params:
954 * dev structure of device which timed out
955 * during transmit.
956 *
957 **************************************************************/
Linus Torvalds1da177e2005-04-16 15:20:36 -0700958
Sakari Ailusc659c382011-01-21 10:59:30 +0000959static void tlan_tx_timeout(struct net_device *dev)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700960{
Jeff Garzik6aa20a22006-09-13 13:24:59 -0400961
Sakari Ailusc659c382011-01-21 10:59:30 +0000962 TLAN_DBG(TLAN_DEBUG_GNRL, "%s: Transmit timed out.\n", dev->name);
Jeff Garzik6aa20a22006-09-13 13:24:59 -0400963
Linus Torvalds1da177e2005-04-16 15:20:36 -0700964 /* Ok so we timed out, lets see what we can do about it...*/
Sakari Ailusc659c382011-01-21 10:59:30 +0000965 tlan_free_lists(dev);
966 tlan_reset_lists(dev);
967 tlan_read_and_clear_stats(dev, TLAN_IGNORE);
968 tlan_reset_adapter(dev);
Eric Dumazet1ae5dc32010-05-10 05:01:31 -0700969 dev->trans_start = jiffies; /* prevent tx timeout */
Sakari Ailusc659c382011-01-21 10:59:30 +0000970 netif_wake_queue(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700971
972}
Jeff Garzik6aa20a22006-09-13 13:24:59 -0400973
Linus Torvalds1da177e2005-04-16 15:20:36 -0700974
Sakari Ailusc659c382011-01-21 10:59:30 +0000975/***************************************************************
976 * tlan_tx_timeout_work
977 *
978 * Returns: nothing
979 *
980 * Params:
981 * work work item of device which timed out
982 *
983 **************************************************************/
David Howellsc4028952006-11-22 14:57:56 +0000984
Sakari Ailusc659c382011-01-21 10:59:30 +0000985static void tlan_tx_timeout_work(struct work_struct *work)
David Howellsc4028952006-11-22 14:57:56 +0000986{
Sakari Ailusc659c382011-01-21 10:59:30 +0000987 struct tlan_priv *priv =
988 container_of(work, struct tlan_priv, tlan_tqueue);
David Howellsc4028952006-11-22 14:57:56 +0000989
Sakari Ailusc659c382011-01-21 10:59:30 +0000990 tlan_tx_timeout(priv->dev);
David Howellsc4028952006-11-22 14:57:56 +0000991}
992
993
Linus Torvalds1da177e2005-04-16 15:20:36 -0700994
Sakari Ailusc659c382011-01-21 10:59:30 +0000995/***************************************************************
996 * tlan_start_tx
997 *
998 * Returns:
999 * 0 on success, non-zero on failure.
1000 * Parms:
1001 * skb A pointer to the sk_buff containing the
1002 * frame to be sent.
1003 * dev The device to send the data on.
1004 *
1005 * This function adds a frame to the Tx list to be sent
1006 * ASAP. First it verifies that the adapter is ready and
1007 * there is room in the queue. Then it sets up the next
1008 * available list, copies the frame to the corresponding
1009 * buffer. If the adapter Tx channel is idle, it gives
1010 * the adapter a Tx Go command on the list, otherwise it
1011 * sets the forward address of the previous list to point
1012 * to this one. Then it frees the sk_buff.
1013 *
1014 **************************************************************/
Linus Torvalds1da177e2005-04-16 15:20:36 -07001015
Sakari Ailusc659c382011-01-21 10:59:30 +00001016static netdev_tx_t tlan_start_tx(struct sk_buff *skb, struct net_device *dev)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001017{
Sakari Ailusc659c382011-01-21 10:59:30 +00001018 struct tlan_priv *priv = netdev_priv(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001019 dma_addr_t tail_list_phys;
Sakari Ailusc659c382011-01-21 10:59:30 +00001020 struct tlan_list *tail_list;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001021 unsigned long flags;
Sakari Ailus8953f122008-12-16 01:44:05 -08001022 unsigned int txlen;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001023
Sakari Ailusc659c382011-01-21 10:59:30 +00001024 if (!priv->phy_online) {
1025 TLAN_DBG(TLAN_DEBUG_TX, "TRANSMIT: %s PHY is not ready\n",
1026 dev->name);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001027 dev_kfree_skb_any(skb);
Patrick McHardy6ed10652009-06-23 06:03:08 +00001028 return NETDEV_TX_OK;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001029 }
1030
Stephen Hemminger41873e92008-05-30 09:49:52 -07001031 if (skb_padto(skb, TLAN_MIN_FRAME_SIZE))
Patrick McHardy6ed10652009-06-23 06:03:08 +00001032 return NETDEV_TX_OK;
Sakari Ailus8953f122008-12-16 01:44:05 -08001033 txlen = max(skb->len, (unsigned int)TLAN_MIN_FRAME_SIZE);
Stephen Hemminger41873e92008-05-30 09:49:52 -07001034
Sakari Ailusc659c382011-01-21 10:59:30 +00001035 tail_list = priv->tx_list + priv->tx_tail;
1036 tail_list_phys =
1037 priv->tx_list_dma + sizeof(struct tlan_list)*priv->tx_tail;
Jeff Garzik6aa20a22006-09-13 13:24:59 -04001038
Sakari Ailusc659c382011-01-21 10:59:30 +00001039 if (tail_list->c_stat != TLAN_CSTAT_UNUSED) {
1040 TLAN_DBG(TLAN_DEBUG_TX,
1041 "TRANSMIT: %s is busy (Head=%d Tail=%d)\n",
1042 dev->name, priv->tx_head, priv->tx_tail);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001043 netif_stop_queue(dev);
Sakari Ailusc659c382011-01-21 10:59:30 +00001044 priv->tx_busy_count++;
Patrick McHardy5b548142009-06-12 06:22:29 +00001045 return NETDEV_TX_BUSY;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001046 }
1047
1048 tail_list->forward = 0;
1049
Sakari Ailusc659c382011-01-21 10:59:30 +00001050 tail_list->buffer[0].address = pci_map_single(priv->pci_dev,
Sakari Ailus5eeabf52008-12-16 15:24:05 -08001051 skb->data, txlen,
1052 PCI_DMA_TODEVICE);
Sakari Ailusc659c382011-01-21 10:59:30 +00001053 tlan_store_skb(tail_list, skb);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001054
Sakari Ailusc659c382011-01-21 10:59:30 +00001055 tail_list->frame_size = (u16) txlen;
Sakari Ailus8953f122008-12-16 01:44:05 -08001056 tail_list->buffer[0].count = TLAN_LAST_BUFFER | (u32) txlen;
Stephen Hemminger41873e92008-05-30 09:49:52 -07001057 tail_list->buffer[1].count = 0;
1058 tail_list->buffer[1].address = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001059
1060 spin_lock_irqsave(&priv->lock, flags);
Sakari Ailusc659c382011-01-21 10:59:30 +00001061 tail_list->c_stat = TLAN_CSTAT_READY;
1062 if (!priv->tx_in_progress) {
1063 priv->tx_in_progress = 1;
1064 TLAN_DBG(TLAN_DEBUG_TX,
1065 "TRANSMIT: Starting TX on buffer %d\n",
1066 priv->tx_tail);
1067 outl(tail_list_phys, dev->base_addr + TLAN_CH_PARM);
1068 outl(TLAN_HC_GO, dev->base_addr + TLAN_HOST_CMD);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001069 } else {
Sakari Ailusc659c382011-01-21 10:59:30 +00001070 TLAN_DBG(TLAN_DEBUG_TX,
1071 "TRANSMIT: Adding buffer %d to TX channel\n",
1072 priv->tx_tail);
1073 if (priv->tx_tail == 0) {
1074 (priv->tx_list + (TLAN_NUM_TX_LISTS - 1))->forward
Stephen Hemmingerdfc2c0a2008-05-30 09:49:58 -07001075 = tail_list_phys;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001076 } else {
Sakari Ailusc659c382011-01-21 10:59:30 +00001077 (priv->tx_list + (priv->tx_tail - 1))->forward
Stephen Hemmingerdfc2c0a2008-05-30 09:49:58 -07001078 = tail_list_phys;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001079 }
1080 }
1081 spin_unlock_irqrestore(&priv->lock, flags);
1082
Sakari Ailusc659c382011-01-21 10:59:30 +00001083 CIRC_INC(priv->tx_tail, TLAN_NUM_TX_LISTS);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001084
Patrick McHardy6ed10652009-06-23 06:03:08 +00001085 return NETDEV_TX_OK;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001086
Sakari Ailusc659c382011-01-21 10:59:30 +00001087}
Linus Torvalds1da177e2005-04-16 15:20:36 -07001088
1089
1090
1091
Sakari Ailusc659c382011-01-21 10:59:30 +00001092/***************************************************************
1093 * tlan_handle_interrupt
1094 *
1095 * Returns:
1096 * Nothing
1097 * Parms:
1098 * irq The line on which the interrupt
1099 * occurred.
1100 * dev_id A pointer to the device assigned to
1101 * this irq line.
1102 *
1103 * This function handles an interrupt generated by its
1104 * assigned TLAN adapter. The function deactivates
1105 * interrupts on its adapter, records the type of
1106 * interrupt, executes the appropriate subhandler, and
1107 * acknowdges the interrupt to the adapter (thus
1108 * re-enabling adapter interrupts.
1109 *
1110 **************************************************************/
Linus Torvalds1da177e2005-04-16 15:20:36 -07001111
Sakari Ailusc659c382011-01-21 10:59:30 +00001112static irqreturn_t tlan_handle_interrupt(int irq, void *dev_id)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001113{
Stephen Hemmingera3ccc782008-05-30 09:49:57 -07001114 struct net_device *dev = dev_id;
Sakari Ailusc659c382011-01-21 10:59:30 +00001115 struct tlan_priv *priv = netdev_priv(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001116 u16 host_int;
Stephen Hemmingera3ccc782008-05-30 09:49:57 -07001117 u16 type;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001118
1119 spin_lock(&priv->lock);
1120
Sakari Ailusc659c382011-01-21 10:59:30 +00001121 host_int = inw(dev->base_addr + TLAN_HOST_INT);
1122 type = (host_int & TLAN_HI_IT_MASK) >> 2;
1123 if (type) {
Stephen Hemmingera3ccc782008-05-30 09:49:57 -07001124 u32 ack;
1125 u32 host_cmd;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001126
Sakari Ailusc659c382011-01-21 10:59:30 +00001127 outw(host_int, dev->base_addr + TLAN_HOST_INT);
1128 ack = tlan_int_vector[type](dev, host_int);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001129
Sakari Ailusc659c382011-01-21 10:59:30 +00001130 if (ack) {
1131 host_cmd = TLAN_HC_ACK | ack | (type << 18);
1132 outl(host_cmd, dev->base_addr + TLAN_HOST_CMD);
Stephen Hemmingera3ccc782008-05-30 09:49:57 -07001133 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001134 }
1135
1136 spin_unlock(&priv->lock);
1137
Stephen Hemmingera3ccc782008-05-30 09:49:57 -07001138 return IRQ_RETVAL(type);
Sakari Ailusc659c382011-01-21 10:59:30 +00001139}
Linus Torvalds1da177e2005-04-16 15:20:36 -07001140
1141
1142
1143
Sakari Ailusc659c382011-01-21 10:59:30 +00001144/***************************************************************
1145 * tlan_close
1146 *
1147 * Returns:
1148 * An error code.
1149 * Parms:
1150 * dev The device structure of the device to
1151 * close.
1152 *
1153 * This function shuts down the adapter. It records any
1154 * stats, puts the adapter into reset state, deactivates
1155 * its time as needed, and frees the irq it is using.
1156 *
1157 **************************************************************/
Linus Torvalds1da177e2005-04-16 15:20:36 -07001158
Sakari Ailusc659c382011-01-21 10:59:30 +00001159static int tlan_close(struct net_device *dev)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001160{
Sakari Ailusc659c382011-01-21 10:59:30 +00001161 struct tlan_priv *priv = netdev_priv(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001162
Linus Torvalds1da177e2005-04-16 15:20:36 -07001163 priv->neg_be_verbose = 0;
Sakari Ailusfa6d5d42011-01-21 10:59:31 +00001164 tlan_stop(dev);
Jeff Garzik6aa20a22006-09-13 13:24:59 -04001165
Sakari Ailusc659c382011-01-21 10:59:30 +00001166 free_irq(dev->irq, dev);
1167 tlan_free_lists(dev);
1168 TLAN_DBG(TLAN_DEBUG_GNRL, "Device %s closed.\n", dev->name);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001169
1170 return 0;
1171
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_get_stats
1179 *
1180 * Returns:
1181 * A pointer to the device's statistics structure.
1182 * Parms:
1183 * dev The device structure to return the
1184 * stats for.
1185 *
1186 * This function updates the devices statistics by reading
1187 * the TLAN chip's onboard registers. Then it returns the
1188 * address of the statistics structure.
1189 *
1190 **************************************************************/
Linus Torvalds1da177e2005-04-16 15:20:36 -07001191
Sakari Ailusc659c382011-01-21 10:59:30 +00001192static struct net_device_stats *tlan_get_stats(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 int i;
1196
1197 /* Should only read stats if open ? */
Sakari Ailusc659c382011-01-21 10:59:30 +00001198 tlan_read_and_clear_stats(dev, TLAN_RECORD);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001199
Sakari Ailusc659c382011-01-21 10:59:30 +00001200 TLAN_DBG(TLAN_DEBUG_RX, "RECEIVE: %s EOC count = %d\n", dev->name,
1201 priv->rx_eoc_count);
1202 TLAN_DBG(TLAN_DEBUG_TX, "TRANSMIT: %s Busy count = %d\n", dev->name,
1203 priv->tx_busy_count);
1204 if (debug & TLAN_DEBUG_GNRL) {
1205 tlan_print_dio(dev->base_addr);
1206 tlan_phy_print(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001207 }
Sakari Ailusc659c382011-01-21 10:59:30 +00001208 if (debug & TLAN_DEBUG_LIST) {
1209 for (i = 0; i < TLAN_NUM_RX_LISTS; i++)
1210 tlan_print_list(priv->rx_list + i, "RX", i);
1211 for (i = 0; i < TLAN_NUM_TX_LISTS; i++)
1212 tlan_print_list(priv->tx_list + i, "TX", i);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001213 }
Jeff Garzik6aa20a22006-09-13 13:24:59 -04001214
Stephen Hemmingerf8f31542008-05-30 09:49:53 -07001215 return &dev->stats;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001216
Sakari Ailusc659c382011-01-21 10:59:30 +00001217}
Linus Torvalds1da177e2005-04-16 15:20:36 -07001218
1219
1220
1221
Sakari Ailusc659c382011-01-21 10:59:30 +00001222/***************************************************************
1223 * tlan_set_multicast_list
1224 *
1225 * Returns:
1226 * Nothing
1227 * Parms:
1228 * dev The device structure to set the
1229 * multicast list for.
1230 *
1231 * This function sets the TLAN adaptor to various receive
1232 * modes. If the IFF_PROMISC flag is set, promiscuous
1233 * mode is acitviated. Otherwise, promiscuous mode is
1234 * turned off. If the IFF_ALLMULTI flag is set, then
1235 * the hash table is set to receive all group addresses.
1236 * Otherwise, the first three multicast addresses are
1237 * stored in AREG_1-3, and the rest are selected via the
1238 * hash table, as necessary.
1239 *
1240 **************************************************************/
Linus Torvalds1da177e2005-04-16 15:20:36 -07001241
Sakari Ailusc659c382011-01-21 10:59:30 +00001242static void tlan_set_multicast_list(struct net_device *dev)
Jeff Garzik6aa20a22006-09-13 13:24:59 -04001243{
Jiri Pirko22bedad32010-04-01 21:22:57 +00001244 struct netdev_hw_addr *ha;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001245 u32 hash1 = 0;
1246 u32 hash2 = 0;
1247 int i;
1248 u32 offset;
1249 u8 tmp;
1250
Sakari Ailusc659c382011-01-21 10:59:30 +00001251 if (dev->flags & IFF_PROMISC) {
1252 tmp = tlan_dio_read8(dev->base_addr, TLAN_NET_CMD);
1253 tlan_dio_write8(dev->base_addr,
1254 TLAN_NET_CMD, tmp | TLAN_NET_CMD_CAF);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001255 } else {
Sakari Ailusc659c382011-01-21 10:59:30 +00001256 tmp = tlan_dio_read8(dev->base_addr, TLAN_NET_CMD);
1257 tlan_dio_write8(dev->base_addr,
1258 TLAN_NET_CMD, tmp & ~TLAN_NET_CMD_CAF);
1259 if (dev->flags & IFF_ALLMULTI) {
1260 for (i = 0; i < 3; i++)
1261 tlan_set_mac(dev, i + 1, NULL);
1262 tlan_dio_write32(dev->base_addr, TLAN_HASH_1,
1263 0xffffffff);
1264 tlan_dio_write32(dev->base_addr, TLAN_HASH_2,
1265 0xffffffff);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001266 } else {
Jiri Pirko567ec872010-02-23 23:17:07 +00001267 i = 0;
Jiri Pirko22bedad32010-04-01 21:22:57 +00001268 netdev_for_each_mc_addr(ha, dev) {
Sakari Ailusc659c382011-01-21 10:59:30 +00001269 if (i < 3) {
1270 tlan_set_mac(dev, i + 1,
Jiri Pirko22bedad32010-04-01 21:22:57 +00001271 (char *) &ha->addr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001272 } else {
Sakari Ailusc659c382011-01-21 10:59:30 +00001273 offset =
1274 tlan_hash_func((u8 *)&ha->addr);
1275 if (offset < 32)
1276 hash1 |= (1 << offset);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001277 else
Sakari Ailusc659c382011-01-21 10:59:30 +00001278 hash2 |= (1 << (offset - 32));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001279 }
Jiri Pirko567ec872010-02-23 23:17:07 +00001280 i++;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001281 }
Sakari Ailusc659c382011-01-21 10:59:30 +00001282 for ( ; i < 3; i++)
1283 tlan_set_mac(dev, i + 1, NULL);
1284 tlan_dio_write32(dev->base_addr, TLAN_HASH_1, hash1);
1285 tlan_dio_write32(dev->base_addr, TLAN_HASH_2, hash2);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001286 }
1287 }
1288
Sakari Ailusc659c382011-01-21 10:59:30 +00001289}
Linus Torvalds1da177e2005-04-16 15:20:36 -07001290
1291
1292
1293/*****************************************************************************
1294******************************************************************************
1295
Sakari Ailusc659c382011-01-21 10:59:30 +00001296ThunderLAN driver interrupt vectors and table
Linus Torvalds1da177e2005-04-16 15:20:36 -07001297
Sakari Ailusc659c382011-01-21 10:59:30 +00001298please see chap. 4, "Interrupt Handling" of the "ThunderLAN
1299Programmer's Guide" for more informations on handling interrupts
1300generated by TLAN based adapters.
Linus Torvalds1da177e2005-04-16 15:20:36 -07001301
1302******************************************************************************
1303*****************************************************************************/
1304
1305
Linus Torvalds1da177e2005-04-16 15:20:36 -07001306
1307
Sakari Ailusc659c382011-01-21 10:59:30 +00001308/***************************************************************
1309 * tlan_handle_tx_eof
1310 *
1311 * Returns:
1312 * 1
1313 * Parms:
1314 * dev Device assigned the IRQ that was
1315 * raised.
1316 * host_int The contents of the HOST_INT
1317 * port.
1318 *
1319 * This function handles Tx EOF interrupts which are raised
1320 * by the adapter when it has completed sending the
1321 * contents of a buffer. If detemines which list/buffer
1322 * was completed and resets it. If the buffer was the last
1323 * in the channel (EOC), then the function checks to see if
1324 * another buffer is ready to send, and if so, sends a Tx
1325 * Go command. Finally, the driver activates/continues the
1326 * activity LED.
1327 *
1328 **************************************************************/
Linus Torvalds1da177e2005-04-16 15:20:36 -07001329
Sakari Ailusc659c382011-01-21 10:59:30 +00001330static u32 tlan_handle_tx_eof(struct net_device *dev, u16 host_int)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001331{
Sakari Ailusc659c382011-01-21 10:59:30 +00001332 struct tlan_priv *priv = netdev_priv(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001333 int eoc = 0;
Sakari Ailusc659c382011-01-21 10:59:30 +00001334 struct tlan_list *head_list;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001335 dma_addr_t head_list_phys;
1336 u32 ack = 0;
Sakari Ailusc659c382011-01-21 10:59:30 +00001337 u16 tmp_c_stat;
Jeff Garzik6aa20a22006-09-13 13:24:59 -04001338
Sakari Ailusc659c382011-01-21 10:59:30 +00001339 TLAN_DBG(TLAN_DEBUG_TX,
1340 "TRANSMIT: Handling TX EOF (Head=%d Tail=%d)\n",
1341 priv->tx_head, priv->tx_tail);
1342 head_list = priv->tx_list + priv->tx_head;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001343
Sakari Ailusc659c382011-01-21 10:59:30 +00001344 while (((tmp_c_stat = head_list->c_stat) & TLAN_CSTAT_FRM_CMP)
1345 && (ack < 255)) {
1346 struct sk_buff *skb = tlan_get_skb(head_list);
Sakari Ailus5eeabf52008-12-16 15:24:05 -08001347
Linus Torvalds1da177e2005-04-16 15:20:36 -07001348 ack++;
Sakari Ailusc659c382011-01-21 10:59:30 +00001349 pci_unmap_single(priv->pci_dev, head_list->buffer[0].address,
Sakari Ailus5eeabf52008-12-16 15:24:05 -08001350 max(skb->len,
1351 (unsigned int)TLAN_MIN_FRAME_SIZE),
1352 PCI_DMA_TODEVICE);
1353 dev_kfree_skb_any(skb);
1354 head_list->buffer[8].address = 0;
1355 head_list->buffer[9].address = 0;
Jeff Garzik6aa20a22006-09-13 13:24:59 -04001356
Sakari Ailusc659c382011-01-21 10:59:30 +00001357 if (tmp_c_stat & TLAN_CSTAT_EOC)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001358 eoc = 1;
Jeff Garzik6aa20a22006-09-13 13:24:59 -04001359
Sakari Ailusc659c382011-01-21 10:59:30 +00001360 dev->stats.tx_bytes += head_list->frame_size;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001361
Sakari Ailusc659c382011-01-21 10:59:30 +00001362 head_list->c_stat = TLAN_CSTAT_UNUSED;
Jeff Garzik6aa20a22006-09-13 13:24:59 -04001363 netif_start_queue(dev);
Sakari Ailusc659c382011-01-21 10:59:30 +00001364 CIRC_INC(priv->tx_head, TLAN_NUM_TX_LISTS);
1365 head_list = priv->tx_list + priv->tx_head;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001366 }
1367
1368 if (!ack)
Joe Perches50624aa2011-03-01 06:56:33 +00001369 netdev_info(dev,
1370 "Received interrupt for uncompleted TX frame\n");
Jeff Garzik6aa20a22006-09-13 13:24:59 -04001371
Sakari Ailusc659c382011-01-21 10:59:30 +00001372 if (eoc) {
1373 TLAN_DBG(TLAN_DEBUG_TX,
1374 "TRANSMIT: handling TX EOC (Head=%d Tail=%d)\n",
1375 priv->tx_head, priv->tx_tail);
1376 head_list = priv->tx_list + priv->tx_head;
1377 head_list_phys = priv->tx_list_dma
1378 + sizeof(struct tlan_list)*priv->tx_head;
Sakari Ailusf45437e2011-02-09 10:25:06 +00001379 if ((head_list->c_stat & TLAN_CSTAT_READY)
1380 == TLAN_CSTAT_READY) {
Sakari Ailusc659c382011-01-21 10:59:30 +00001381 outl(head_list_phys, dev->base_addr + TLAN_CH_PARM);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001382 ack |= TLAN_HC_GO;
1383 } else {
Sakari Ailusc659c382011-01-21 10:59:30 +00001384 priv->tx_in_progress = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001385 }
1386 }
Jeff Garzik6aa20a22006-09-13 13:24:59 -04001387
Sakari Ailusc659c382011-01-21 10:59:30 +00001388 if (priv->adapter->flags & TLAN_ADAPTER_ACTIVITY_LED) {
1389 tlan_dio_write8(dev->base_addr,
1390 TLAN_LED_REG, TLAN_LED_LINK | TLAN_LED_ACT);
1391 if (priv->timer.function == NULL) {
1392 priv->timer.function = tlan_timer;
1393 priv->timer.data = (unsigned long) dev;
1394 priv->timer.expires = jiffies + TLAN_TIMER_ACT_DELAY;
1395 priv->timer_set_at = jiffies;
1396 priv->timer_type = TLAN_TIMER_ACTIVITY;
1397 add_timer(&priv->timer);
1398 } else if (priv->timer_type == TLAN_TIMER_ACTIVITY) {
1399 priv->timer_set_at = jiffies;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001400 }
1401 }
1402
1403 return ack;
1404
Sakari Ailusc659c382011-01-21 10:59:30 +00001405}
Linus Torvalds1da177e2005-04-16 15:20:36 -07001406
1407
1408
1409
Sakari Ailusc659c382011-01-21 10:59:30 +00001410/***************************************************************
1411 * TLan_HandleStatOverflow
1412 *
1413 * Returns:
1414 * 1
1415 * Parms:
1416 * dev Device assigned the IRQ that was
1417 * raised.
1418 * host_int The contents of the HOST_INT
1419 * port.
1420 *
1421 * This function handles the Statistics Overflow interrupt
1422 * which means that one or more of the TLAN statistics
1423 * registers has reached 1/2 capacity and needs to be read.
1424 *
1425 **************************************************************/
Linus Torvalds1da177e2005-04-16 15:20:36 -07001426
Sakari Ailusc659c382011-01-21 10:59:30 +00001427static u32 tlan_handle_stat_overflow(struct net_device *dev, u16 host_int)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001428{
Sakari Ailusc659c382011-01-21 10:59:30 +00001429 tlan_read_and_clear_stats(dev, TLAN_RECORD);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001430
1431 return 1;
1432
Sakari Ailusc659c382011-01-21 10:59:30 +00001433}
Linus Torvalds1da177e2005-04-16 15:20:36 -07001434
1435
1436
1437
Sakari Ailusc659c382011-01-21 10:59:30 +00001438/***************************************************************
1439 * TLan_HandleRxEOF
1440 *
1441 * Returns:
1442 * 1
1443 * Parms:
1444 * dev Device assigned the IRQ that was
1445 * raised.
1446 * host_int The contents of the HOST_INT
1447 * port.
1448 *
1449 * This function handles the Rx EOF interrupt which
1450 * indicates a frame has been received by the adapter from
1451 * the net and the frame has been transferred to memory.
1452 * The function determines the bounce buffer the frame has
1453 * been loaded into, creates a new sk_buff big enough to
1454 * hold the frame, and sends it to protocol stack. It
1455 * then resets the used buffer and appends it to the end
1456 * of the list. If the frame was the last in the Rx
1457 * channel (EOC), the function restarts the receive channel
1458 * by sending an Rx Go command to the adapter. Then it
1459 * activates/continues the activity LED.
1460 *
1461 **************************************************************/
Linus Torvalds1da177e2005-04-16 15:20:36 -07001462
Sakari Ailusc659c382011-01-21 10:59:30 +00001463static u32 tlan_handle_rx_eof(struct net_device *dev, u16 host_int)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001464{
Sakari Ailusc659c382011-01-21 10:59:30 +00001465 struct tlan_priv *priv = netdev_priv(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001466 u32 ack = 0;
1467 int eoc = 0;
Sakari Ailusc659c382011-01-21 10:59:30 +00001468 struct tlan_list *head_list;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001469 struct sk_buff *skb;
Sakari Ailusc659c382011-01-21 10:59:30 +00001470 struct tlan_list *tail_list;
1471 u16 tmp_c_stat;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001472 dma_addr_t head_list_phys;
1473
Sakari Ailusc659c382011-01-21 10:59:30 +00001474 TLAN_DBG(TLAN_DEBUG_RX, "RECEIVE: handling RX EOF (Head=%d Tail=%d)\n",
1475 priv->rx_head, priv->rx_tail);
1476 head_list = priv->rx_list + priv->rx_head;
1477 head_list_phys =
1478 priv->rx_list_dma + sizeof(struct tlan_list)*priv->rx_head;
Jeff Garzik6aa20a22006-09-13 13:24:59 -04001479
Sakari Ailusc659c382011-01-21 10:59:30 +00001480 while (((tmp_c_stat = head_list->c_stat) & TLAN_CSTAT_FRM_CMP)
1481 && (ack < 255)) {
1482 dma_addr_t frame_dma = head_list->buffer[0].address;
1483 u32 frame_size = head_list->frame_size;
Sakari Ailus5eeabf52008-12-16 15:24:05 -08001484 struct sk_buff *new_skb;
1485
Linus Torvalds1da177e2005-04-16 15:20:36 -07001486 ack++;
Sakari Ailusc659c382011-01-21 10:59:30 +00001487 if (tmp_c_stat & TLAN_CSTAT_EOC)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001488 eoc = 1;
Jeff Garzik6aa20a22006-09-13 13:24:59 -04001489
Eric Dumazet89d71a62009-10-13 05:34:20 +00001490 new_skb = netdev_alloc_skb_ip_align(dev,
1491 TLAN_MAX_FRAME_SIZE + 5);
Sakari Ailusc659c382011-01-21 10:59:30 +00001492 if (!new_skb)
Sakari Ailus5eeabf52008-12-16 15:24:05 -08001493 goto drop_and_reuse;
Jeff Garzik6aa20a22006-09-13 13:24:59 -04001494
Sakari Ailusc659c382011-01-21 10:59:30 +00001495 skb = tlan_get_skb(head_list);
1496 pci_unmap_single(priv->pci_dev, frame_dma,
Sakari Ailus5eeabf52008-12-16 15:24:05 -08001497 TLAN_MAX_FRAME_SIZE, PCI_DMA_FROMDEVICE);
Sakari Ailusc659c382011-01-21 10:59:30 +00001498 skb_put(skb, frame_size);
Stephen Hemmingerdfc2c0a2008-05-30 09:49:58 -07001499
Sakari Ailusc659c382011-01-21 10:59:30 +00001500 dev->stats.rx_bytes += frame_size;
Jeff Garzik6aa20a22006-09-13 13:24:59 -04001501
Sakari Ailusc659c382011-01-21 10:59:30 +00001502 skb->protocol = eth_type_trans(skb, dev);
1503 netif_rx(skb);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001504
Sakari Ailusc659c382011-01-21 10:59:30 +00001505 head_list->buffer[0].address =
1506 pci_map_single(priv->pci_dev, new_skb->data,
1507 TLAN_MAX_FRAME_SIZE, PCI_DMA_FROMDEVICE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001508
Sakari Ailusc659c382011-01-21 10:59:30 +00001509 tlan_store_skb(head_list, new_skb);
Stephen Hemmingerdfc2c0a2008-05-30 09:49:58 -07001510drop_and_reuse:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001511 head_list->forward = 0;
Sakari Ailusc659c382011-01-21 10:59:30 +00001512 head_list->c_stat = 0;
1513 tail_list = priv->rx_list + priv->rx_tail;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001514 tail_list->forward = head_list_phys;
1515
Sakari Ailusc659c382011-01-21 10:59:30 +00001516 CIRC_INC(priv->rx_head, TLAN_NUM_RX_LISTS);
1517 CIRC_INC(priv->rx_tail, TLAN_NUM_RX_LISTS);
1518 head_list = priv->rx_list + priv->rx_head;
1519 head_list_phys = priv->rx_list_dma
1520 + sizeof(struct tlan_list)*priv->rx_head;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001521 }
1522
1523 if (!ack)
Joe Perches50624aa2011-03-01 06:56:33 +00001524 netdev_info(dev,
1525 "Received interrupt for uncompleted RX frame\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001526
1527
Sakari Ailusc659c382011-01-21 10:59:30 +00001528 if (eoc) {
1529 TLAN_DBG(TLAN_DEBUG_RX,
1530 "RECEIVE: handling RX EOC (Head=%d Tail=%d)\n",
1531 priv->rx_head, priv->rx_tail);
1532 head_list = priv->rx_list + priv->rx_head;
1533 head_list_phys = priv->rx_list_dma
1534 + sizeof(struct tlan_list)*priv->rx_head;
1535 outl(head_list_phys, dev->base_addr + TLAN_CH_PARM);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001536 ack |= TLAN_HC_GO | TLAN_HC_RT;
Sakari Ailusc659c382011-01-21 10:59:30 +00001537 priv->rx_eoc_count++;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001538 }
1539
Sakari Ailusc659c382011-01-21 10:59:30 +00001540 if (priv->adapter->flags & TLAN_ADAPTER_ACTIVITY_LED) {
1541 tlan_dio_write8(dev->base_addr,
1542 TLAN_LED_REG, TLAN_LED_LINK | TLAN_LED_ACT);
1543 if (priv->timer.function == NULL) {
1544 priv->timer.function = tlan_timer;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001545 priv->timer.data = (unsigned long) dev;
1546 priv->timer.expires = jiffies + TLAN_TIMER_ACT_DELAY;
Sakari Ailusc659c382011-01-21 10:59:30 +00001547 priv->timer_set_at = jiffies;
1548 priv->timer_type = TLAN_TIMER_ACTIVITY;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001549 add_timer(&priv->timer);
Sakari Ailusc659c382011-01-21 10:59:30 +00001550 } else if (priv->timer_type == TLAN_TIMER_ACTIVITY) {
1551 priv->timer_set_at = jiffies;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001552 }
1553 }
1554
Linus Torvalds1da177e2005-04-16 15:20:36 -07001555 return ack;
1556
Sakari Ailusc659c382011-01-21 10:59:30 +00001557}
Linus Torvalds1da177e2005-04-16 15:20:36 -07001558
1559
1560
1561
Sakari Ailusc659c382011-01-21 10:59:30 +00001562/***************************************************************
1563 * tlan_handle_dummy
1564 *
1565 * Returns:
1566 * 1
1567 * Parms:
1568 * dev Device assigned the IRQ that was
1569 * raised.
1570 * host_int The contents of the HOST_INT
1571 * port.
1572 *
1573 * This function handles the Dummy interrupt, which is
1574 * raised whenever a test interrupt is generated by setting
1575 * the Req_Int bit of HOST_CMD to 1.
1576 *
1577 **************************************************************/
Linus Torvalds1da177e2005-04-16 15:20:36 -07001578
Sakari Ailusc659c382011-01-21 10:59:30 +00001579static u32 tlan_handle_dummy(struct net_device *dev, u16 host_int)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001580{
Joe Perches50624aa2011-03-01 06:56:33 +00001581 netdev_info(dev, "Test interrupt\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001582 return 1;
1583
Sakari Ailusc659c382011-01-21 10:59:30 +00001584}
Linus Torvalds1da177e2005-04-16 15:20:36 -07001585
1586
1587
1588
Sakari Ailusc659c382011-01-21 10:59:30 +00001589/***************************************************************
1590 * tlan_handle_tx_eoc
1591 *
1592 * Returns:
1593 * 1
1594 * Parms:
1595 * dev Device assigned the IRQ that was
1596 * raised.
1597 * host_int The contents of the HOST_INT
1598 * port.
1599 *
1600 * This driver is structured to determine EOC occurrences by
1601 * reading the CSTAT member of the list structure. Tx EOC
1602 * interrupts are disabled via the DIO INTDIS register.
1603 * However, TLAN chips before revision 3.0 didn't have this
1604 * functionality, so process EOC events if this is the
1605 * case.
1606 *
1607 **************************************************************/
Linus Torvalds1da177e2005-04-16 15:20:36 -07001608
Sakari Ailusc659c382011-01-21 10:59:30 +00001609static u32 tlan_handle_tx_eoc(struct net_device *dev, u16 host_int)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001610{
Sakari Ailusc659c382011-01-21 10:59:30 +00001611 struct tlan_priv *priv = netdev_priv(dev);
1612 struct tlan_list *head_list;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001613 dma_addr_t head_list_phys;
1614 u32 ack = 1;
Jeff Garzik6aa20a22006-09-13 13:24:59 -04001615
Linus Torvalds1da177e2005-04-16 15:20:36 -07001616 host_int = 0;
Sakari Ailusc659c382011-01-21 10:59:30 +00001617 if (priv->tlan_rev < 0x30) {
1618 TLAN_DBG(TLAN_DEBUG_TX,
1619 "TRANSMIT: handling TX EOC (Head=%d Tail=%d) -- IRQ\n",
1620 priv->tx_head, priv->tx_tail);
1621 head_list = priv->tx_list + priv->tx_head;
1622 head_list_phys = priv->tx_list_dma
1623 + sizeof(struct tlan_list)*priv->tx_head;
Sakari Ailusf45437e2011-02-09 10:25:06 +00001624 if ((head_list->c_stat & TLAN_CSTAT_READY)
1625 == TLAN_CSTAT_READY) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001626 netif_stop_queue(dev);
Sakari Ailusc659c382011-01-21 10:59:30 +00001627 outl(head_list_phys, dev->base_addr + TLAN_CH_PARM);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001628 ack |= TLAN_HC_GO;
1629 } else {
Sakari Ailusc659c382011-01-21 10:59:30 +00001630 priv->tx_in_progress = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001631 }
1632 }
1633
1634 return ack;
1635
Sakari Ailusc659c382011-01-21 10:59:30 +00001636}
Linus Torvalds1da177e2005-04-16 15:20:36 -07001637
1638
1639
1640
Sakari Ailusc659c382011-01-21 10:59:30 +00001641/***************************************************************
1642 * tlan_handle_status_check
1643 *
1644 * Returns:
1645 * 0 if Adapter check, 1 if Network Status check.
1646 * Parms:
1647 * dev Device assigned the IRQ that was
1648 * raised.
1649 * host_int The contents of the HOST_INT
1650 * port.
1651 *
1652 * This function handles Adapter Check/Network Status
1653 * interrupts generated by the adapter. It checks the
1654 * vector in the HOST_INT register to determine if it is
1655 * an Adapter Check interrupt. If so, it resets the
1656 * adapter. Otherwise it clears the status registers
1657 * and services the PHY.
1658 *
1659 **************************************************************/
Linus Torvalds1da177e2005-04-16 15:20:36 -07001660
Sakari Ailusc659c382011-01-21 10:59:30 +00001661static u32 tlan_handle_status_check(struct net_device *dev, u16 host_int)
Jeff Garzik6aa20a22006-09-13 13:24:59 -04001662{
Sakari Ailusc659c382011-01-21 10:59:30 +00001663 struct tlan_priv *priv = netdev_priv(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001664 u32 ack;
1665 u32 error;
1666 u8 net_sts;
1667 u32 phy;
1668 u16 tlphy_ctl;
1669 u16 tlphy_sts;
Jeff Garzik6aa20a22006-09-13 13:24:59 -04001670
Linus Torvalds1da177e2005-04-16 15:20:36 -07001671 ack = 1;
Sakari Ailusc659c382011-01-21 10:59:30 +00001672 if (host_int & TLAN_HI_IV_MASK) {
1673 netif_stop_queue(dev);
1674 error = inl(dev->base_addr + TLAN_CH_PARM);
Joe Perches50624aa2011-03-01 06:56:33 +00001675 netdev_info(dev, "Adaptor Error = 0x%x\n", error);
Sakari Ailusc659c382011-01-21 10:59:30 +00001676 tlan_read_and_clear_stats(dev, TLAN_RECORD);
1677 outl(TLAN_HC_AD_RST, dev->base_addr + TLAN_HOST_CMD);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001678
1679 schedule_work(&priv->tlan_tqueue);
1680
1681 netif_wake_queue(dev);
1682 ack = 0;
1683 } else {
Sakari Ailusc659c382011-01-21 10:59:30 +00001684 TLAN_DBG(TLAN_DEBUG_GNRL, "%s: Status Check\n", dev->name);
1685 phy = priv->phy[priv->phy_num];
Linus Torvalds1da177e2005-04-16 15:20:36 -07001686
Sakari Ailusc659c382011-01-21 10:59:30 +00001687 net_sts = tlan_dio_read8(dev->base_addr, TLAN_NET_STS);
1688 if (net_sts) {
1689 tlan_dio_write8(dev->base_addr, TLAN_NET_STS, net_sts);
1690 TLAN_DBG(TLAN_DEBUG_GNRL, "%s: Net_Sts = %x\n",
1691 dev->name, (unsigned) net_sts);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001692 }
Sakari Ailusc659c382011-01-21 10:59:30 +00001693 if ((net_sts & TLAN_NET_STS_MIRQ) && (priv->phy_num == 0)) {
1694 tlan_mii_read_reg(dev, phy, TLAN_TLPHY_STS, &tlphy_sts);
1695 tlan_mii_read_reg(dev, phy, TLAN_TLPHY_CTL, &tlphy_ctl);
1696 if (!(tlphy_sts & TLAN_TS_POLOK) &&
1697 !(tlphy_ctl & TLAN_TC_SWAPOL)) {
1698 tlphy_ctl |= TLAN_TC_SWAPOL;
1699 tlan_mii_write_reg(dev, phy, TLAN_TLPHY_CTL,
1700 tlphy_ctl);
1701 } else if ((tlphy_sts & TLAN_TS_POLOK) &&
1702 (tlphy_ctl & TLAN_TC_SWAPOL)) {
1703 tlphy_ctl &= ~TLAN_TC_SWAPOL;
1704 tlan_mii_write_reg(dev, phy, TLAN_TLPHY_CTL,
1705 tlphy_ctl);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001706 }
Sakari Ailusc659c382011-01-21 10:59:30 +00001707
1708 if (debug)
1709 tlan_phy_print(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001710 }
1711 }
1712
1713 return ack;
1714
Sakari Ailusc659c382011-01-21 10:59:30 +00001715}
Linus Torvalds1da177e2005-04-16 15:20:36 -07001716
1717
1718
1719
Sakari Ailusc659c382011-01-21 10:59:30 +00001720/***************************************************************
1721 * tlan_handle_rx_eoc
1722 *
1723 * Returns:
1724 * 1
1725 * Parms:
1726 * dev Device assigned the IRQ that was
1727 * raised.
1728 * host_int The contents of the HOST_INT
1729 * port.
1730 *
1731 * This driver is structured to determine EOC occurrences by
1732 * reading the CSTAT member of the list structure. Rx EOC
1733 * interrupts are disabled via the DIO INTDIS register.
1734 * However, TLAN chips before revision 3.0 didn't have this
1735 * CSTAT member or a INTDIS register, so if this chip is
1736 * pre-3.0, process EOC interrupts normally.
1737 *
1738 **************************************************************/
Linus Torvalds1da177e2005-04-16 15:20:36 -07001739
Sakari Ailusc659c382011-01-21 10:59:30 +00001740static u32 tlan_handle_rx_eoc(struct net_device *dev, u16 host_int)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001741{
Sakari Ailusc659c382011-01-21 10:59:30 +00001742 struct tlan_priv *priv = netdev_priv(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001743 dma_addr_t head_list_phys;
1744 u32 ack = 1;
1745
Sakari Ailusc659c382011-01-21 10:59:30 +00001746 if (priv->tlan_rev < 0x30) {
1747 TLAN_DBG(TLAN_DEBUG_RX,
1748 "RECEIVE: Handling RX EOC (head=%d tail=%d) -- IRQ\n",
1749 priv->rx_head, priv->rx_tail);
1750 head_list_phys = priv->rx_list_dma
1751 + sizeof(struct tlan_list)*priv->rx_head;
1752 outl(head_list_phys, dev->base_addr + TLAN_CH_PARM);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001753 ack |= TLAN_HC_GO | TLAN_HC_RT;
Sakari Ailusc659c382011-01-21 10:59:30 +00001754 priv->rx_eoc_count++;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001755 }
1756
1757 return ack;
1758
Sakari Ailusc659c382011-01-21 10:59:30 +00001759}
Linus Torvalds1da177e2005-04-16 15:20:36 -07001760
1761
1762
1763
1764/*****************************************************************************
1765******************************************************************************
1766
Sakari Ailusc659c382011-01-21 10:59:30 +00001767ThunderLAN driver timer function
Linus Torvalds1da177e2005-04-16 15:20:36 -07001768
1769******************************************************************************
1770*****************************************************************************/
1771
1772
Sakari Ailusc659c382011-01-21 10:59:30 +00001773/***************************************************************
1774 * tlan_timer
1775 *
1776 * Returns:
1777 * Nothing
1778 * Parms:
1779 * data A value given to add timer when
1780 * add_timer was called.
1781 *
1782 * This function handles timed functionality for the
1783 * TLAN driver. The two current timer uses are for
1784 * delaying for autonegotionation and driving the ACT LED.
1785 * - Autonegotiation requires being allowed about
1786 * 2 1/2 seconds before attempting to transmit a
1787 * packet. It would be a very bad thing to hang
1788 * the kernel this long, so the driver doesn't
1789 * allow transmission 'til after this time, for
1790 * certain PHYs. It would be much nicer if all
1791 * PHYs were interrupt-capable like the internal
1792 * PHY.
1793 * - The ACT LED, which shows adapter activity, is
1794 * driven by the driver, and so must be left on
1795 * for a short period to power up the LED so it
1796 * can be seen. This delay can be changed by
1797 * changing the TLAN_TIMER_ACT_DELAY in tlan.h,
1798 * if desired. 100 ms produces a slightly
1799 * sluggish response.
1800 *
1801 **************************************************************/
Linus Torvalds1da177e2005-04-16 15:20:36 -07001802
Sakari Ailusc659c382011-01-21 10:59:30 +00001803static void tlan_timer(unsigned long data)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001804{
1805 struct net_device *dev = (struct net_device *) data;
Sakari Ailusc659c382011-01-21 10:59:30 +00001806 struct tlan_priv *priv = netdev_priv(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001807 u32 elapsed;
1808 unsigned long flags = 0;
1809
1810 priv->timer.function = NULL;
1811
Sakari Ailusc659c382011-01-21 10:59:30 +00001812 switch (priv->timer_type) {
Jeff Garzik6aa20a22006-09-13 13:24:59 -04001813#ifdef MONITOR
Sakari Ailusc659c382011-01-21 10:59:30 +00001814 case TLAN_TIMER_LINK_BEAT:
1815 tlan_phy_monitor(dev);
1816 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001817#endif
Sakari Ailusc659c382011-01-21 10:59:30 +00001818 case TLAN_TIMER_PHY_PDOWN:
1819 tlan_phy_power_down(dev);
1820 break;
1821 case TLAN_TIMER_PHY_PUP:
1822 tlan_phy_power_up(dev);
1823 break;
1824 case TLAN_TIMER_PHY_RESET:
1825 tlan_phy_reset(dev);
1826 break;
1827 case TLAN_TIMER_PHY_START_LINK:
1828 tlan_phy_start_link(dev);
1829 break;
1830 case TLAN_TIMER_PHY_FINISH_AN:
1831 tlan_phy_finish_auto_neg(dev);
1832 break;
1833 case TLAN_TIMER_FINISH_RESET:
1834 tlan_finish_reset(dev);
1835 break;
1836 case TLAN_TIMER_ACTIVITY:
1837 spin_lock_irqsave(&priv->lock, flags);
1838 if (priv->timer.function == NULL) {
1839 elapsed = jiffies - priv->timer_set_at;
1840 if (elapsed >= TLAN_TIMER_ACT_DELAY) {
1841 tlan_dio_write8(dev->base_addr,
1842 TLAN_LED_REG, TLAN_LED_LINK);
1843 } else {
1844 priv->timer.function = tlan_timer;
1845 priv->timer.expires = priv->timer_set_at
1846 + TLAN_TIMER_ACT_DELAY;
1847 spin_unlock_irqrestore(&priv->lock, flags);
1848 add_timer(&priv->timer);
1849 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001850 }
Sakari Ailusc659c382011-01-21 10:59:30 +00001851 }
1852 spin_unlock_irqrestore(&priv->lock, flags);
1853 break;
1854 default:
1855 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001856 }
1857
Sakari Ailusc659c382011-01-21 10:59:30 +00001858}
Linus Torvalds1da177e2005-04-16 15:20:36 -07001859
1860
1861
1862
1863/*****************************************************************************
1864******************************************************************************
1865
Sakari Ailusc659c382011-01-21 10:59:30 +00001866ThunderLAN driver adapter related routines
Linus Torvalds1da177e2005-04-16 15:20:36 -07001867
1868******************************************************************************
1869*****************************************************************************/
1870
1871
Sakari Ailusc659c382011-01-21 10:59:30 +00001872/***************************************************************
1873 * tlan_reset_lists
1874 *
1875 * Returns:
1876 * Nothing
1877 * Parms:
1878 * dev The device structure with the list
1879 * stuctures to be reset.
1880 *
1881 * This routine sets the variables associated with managing
1882 * the TLAN lists to their initial values.
1883 *
1884 **************************************************************/
Linus Torvalds1da177e2005-04-16 15:20:36 -07001885
Sakari Ailusc659c382011-01-21 10:59:30 +00001886static void tlan_reset_lists(struct net_device *dev)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001887{
Sakari Ailusc659c382011-01-21 10:59:30 +00001888 struct tlan_priv *priv = netdev_priv(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001889 int i;
Sakari Ailusc659c382011-01-21 10:59:30 +00001890 struct tlan_list *list;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001891 dma_addr_t list_phys;
1892 struct sk_buff *skb;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001893
Sakari Ailusc659c382011-01-21 10:59:30 +00001894 priv->tx_head = 0;
1895 priv->tx_tail = 0;
1896 for (i = 0; i < TLAN_NUM_TX_LISTS; i++) {
1897 list = priv->tx_list + i;
1898 list->c_stat = TLAN_CSTAT_UNUSED;
Sakari Ailus5eeabf52008-12-16 15:24:05 -08001899 list->buffer[0].address = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001900 list->buffer[2].count = 0;
1901 list->buffer[2].address = 0;
1902 list->buffer[8].address = 0;
1903 list->buffer[9].address = 0;
1904 }
1905
Sakari Ailusc659c382011-01-21 10:59:30 +00001906 priv->rx_head = 0;
1907 priv->rx_tail = TLAN_NUM_RX_LISTS - 1;
1908 for (i = 0; i < TLAN_NUM_RX_LISTS; i++) {
1909 list = priv->rx_list + i;
1910 list_phys = priv->rx_list_dma + sizeof(struct tlan_list)*i;
1911 list->c_stat = TLAN_CSTAT_READY;
1912 list->frame_size = TLAN_MAX_FRAME_SIZE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001913 list->buffer[0].count = TLAN_MAX_FRAME_SIZE | TLAN_LAST_BUFFER;
Eric Dumazet89d71a62009-10-13 05:34:20 +00001914 skb = netdev_alloc_skb_ip_align(dev, TLAN_MAX_FRAME_SIZE + 5);
Joe Perches720a43e2013-03-08 15:03:25 +00001915 if (!skb)
Sakari Ailus5eeabf52008-12-16 15:24:05 -08001916 break;
Sakari Ailus5eeabf52008-12-16 15:24:05 -08001917
Sakari Ailusc659c382011-01-21 10:59:30 +00001918 list->buffer[0].address = pci_map_single(priv->pci_dev,
Sakari Ailus5eeabf52008-12-16 15:24:05 -08001919 skb->data,
1920 TLAN_MAX_FRAME_SIZE,
1921 PCI_DMA_FROMDEVICE);
Sakari Ailusc659c382011-01-21 10:59:30 +00001922 tlan_store_skb(list, skb);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001923 list->buffer[1].count = 0;
1924 list->buffer[1].address = 0;
Sakari Ailusc659c382011-01-21 10:59:30 +00001925 list->forward = list_phys + sizeof(struct tlan_list);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001926 }
1927
Stephen Hemminger9ded65a2008-05-30 09:49:56 -07001928 /* in case ran out of memory early, clear bits */
1929 while (i < TLAN_NUM_RX_LISTS) {
Sakari Ailusc659c382011-01-21 10:59:30 +00001930 tlan_store_skb(priv->rx_list + i, NULL);
Stephen Hemminger9ded65a2008-05-30 09:49:56 -07001931 ++i;
1932 }
1933 list->forward = 0;
1934
Sakari Ailusc659c382011-01-21 10:59:30 +00001935}
Linus Torvalds1da177e2005-04-16 15:20:36 -07001936
1937
Sakari Ailusc659c382011-01-21 10:59:30 +00001938static void tlan_free_lists(struct net_device *dev)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001939{
Sakari Ailusc659c382011-01-21 10:59:30 +00001940 struct tlan_priv *priv = netdev_priv(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001941 int i;
Sakari Ailusc659c382011-01-21 10:59:30 +00001942 struct tlan_list *list;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001943 struct sk_buff *skb;
1944
Sakari Ailusc659c382011-01-21 10:59:30 +00001945 for (i = 0; i < TLAN_NUM_TX_LISTS; i++) {
1946 list = priv->tx_list + i;
1947 skb = tlan_get_skb(list);
1948 if (skb) {
Sakari Ailus5eeabf52008-12-16 15:24:05 -08001949 pci_unmap_single(
Sakari Ailusc659c382011-01-21 10:59:30 +00001950 priv->pci_dev,
Sakari Ailus5eeabf52008-12-16 15:24:05 -08001951 list->buffer[0].address,
1952 max(skb->len,
1953 (unsigned int)TLAN_MIN_FRAME_SIZE),
1954 PCI_DMA_TODEVICE);
Sakari Ailusc659c382011-01-21 10:59:30 +00001955 dev_kfree_skb_any(skb);
Sakari Ailus5eeabf52008-12-16 15:24:05 -08001956 list->buffer[8].address = 0;
1957 list->buffer[9].address = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001958 }
Sakari Ailus5eeabf52008-12-16 15:24:05 -08001959 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001960
Sakari Ailusc659c382011-01-21 10:59:30 +00001961 for (i = 0; i < TLAN_NUM_RX_LISTS; i++) {
1962 list = priv->rx_list + i;
1963 skb = tlan_get_skb(list);
1964 if (skb) {
1965 pci_unmap_single(priv->pci_dev,
Sakari Ailus5eeabf52008-12-16 15:24:05 -08001966 list->buffer[0].address,
1967 TLAN_MAX_FRAME_SIZE,
1968 PCI_DMA_FROMDEVICE);
Sakari Ailusc659c382011-01-21 10:59:30 +00001969 dev_kfree_skb_any(skb);
Sakari Ailus5eeabf52008-12-16 15:24:05 -08001970 list->buffer[8].address = 0;
1971 list->buffer[9].address = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001972 }
1973 }
Sakari Ailusc659c382011-01-21 10:59:30 +00001974}
Linus Torvalds1da177e2005-04-16 15:20:36 -07001975
1976
1977
1978
Sakari Ailusc659c382011-01-21 10:59:30 +00001979/***************************************************************
1980 * tlan_print_dio
1981 *
1982 * Returns:
1983 * Nothing
1984 * Parms:
1985 * io_base Base IO port of the device of
1986 * which to print DIO registers.
1987 *
1988 * This function prints out all the internal (DIO)
1989 * registers of a TLAN chip.
1990 *
1991 **************************************************************/
Linus Torvalds1da177e2005-04-16 15:20:36 -07001992
Sakari Ailusc659c382011-01-21 10:59:30 +00001993static void tlan_print_dio(u16 io_base)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001994{
1995 u32 data0, data1;
1996 int i;
1997
Joe Perches50624aa2011-03-01 06:56:33 +00001998 pr_info("Contents of internal registers for io base 0x%04hx\n",
1999 io_base);
2000 pr_info("Off. +0 +4\n");
Sakari Ailusc659c382011-01-21 10:59:30 +00002001 for (i = 0; i < 0x4C; i += 8) {
2002 data0 = tlan_dio_read32(io_base, i);
2003 data1 = tlan_dio_read32(io_base, i + 0x4);
Joe Perches50624aa2011-03-01 06:56:33 +00002004 pr_info("0x%02x 0x%08x 0x%08x\n", i, data0, data1);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002005 }
2006
Sakari Ailusc659c382011-01-21 10:59:30 +00002007}
Linus Torvalds1da177e2005-04-16 15:20:36 -07002008
2009
2010
2011
Sakari Ailusc659c382011-01-21 10:59:30 +00002012/***************************************************************
2013 * TLan_PrintList
2014 *
2015 * Returns:
2016 * Nothing
2017 * Parms:
2018 * list A pointer to the struct tlan_list structure to
2019 * be printed.
2020 * type A string to designate type of list,
2021 * "Rx" or "Tx".
2022 * num The index of the list.
2023 *
2024 * This function prints out the contents of the list
2025 * pointed to by the list parameter.
2026 *
2027 **************************************************************/
Linus Torvalds1da177e2005-04-16 15:20:36 -07002028
Sakari Ailusc659c382011-01-21 10:59:30 +00002029static void tlan_print_list(struct tlan_list *list, char *type, int num)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002030{
2031 int i;
2032
Joe Perches50624aa2011-03-01 06:56:33 +00002033 pr_info("%s List %d at %p\n", type, num, list);
2034 pr_info(" Forward = 0x%08x\n", list->forward);
2035 pr_info(" CSTAT = 0x%04hx\n", list->c_stat);
2036 pr_info(" Frame Size = 0x%04hx\n", list->frame_size);
Sakari Ailusc659c382011-01-21 10:59:30 +00002037 /* for (i = 0; i < 10; i++) { */
2038 for (i = 0; i < 2; i++) {
Joe Perches50624aa2011-03-01 06:56:33 +00002039 pr_info(" Buffer[%d].count, addr = 0x%08x, 0x%08x\n",
2040 i, list->buffer[i].count, list->buffer[i].address);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002041 }
2042
Sakari Ailusc659c382011-01-21 10:59:30 +00002043}
Linus Torvalds1da177e2005-04-16 15:20:36 -07002044
2045
2046
2047
Sakari Ailusc659c382011-01-21 10:59:30 +00002048/***************************************************************
2049 * tlan_read_and_clear_stats
2050 *
2051 * Returns:
2052 * Nothing
2053 * Parms:
2054 * dev Pointer to device structure of adapter
2055 * to which to read stats.
2056 * record Flag indicating whether to add
2057 *
2058 * This functions reads all the internal status registers
2059 * of the TLAN chip, which clears them as a side effect.
2060 * It then either adds the values to the device's status
2061 * struct, or discards them, depending on whether record
2062 * is TLAN_RECORD (!=0) or TLAN_IGNORE (==0).
2063 *
2064 **************************************************************/
Linus Torvalds1da177e2005-04-16 15:20:36 -07002065
Sakari Ailusc659c382011-01-21 10:59:30 +00002066static void tlan_read_and_clear_stats(struct net_device *dev, int record)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002067{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002068 u32 tx_good, tx_under;
2069 u32 rx_good, rx_over;
2070 u32 def_tx, crc, code;
2071 u32 multi_col, single_col;
2072 u32 excess_col, late_col, loss;
2073
Sakari Ailusc659c382011-01-21 10:59:30 +00002074 outw(TLAN_GOOD_TX_FRMS, dev->base_addr + TLAN_DIO_ADR);
2075 tx_good = inb(dev->base_addr + TLAN_DIO_DATA);
2076 tx_good += inb(dev->base_addr + TLAN_DIO_DATA + 1) << 8;
2077 tx_good += inb(dev->base_addr + TLAN_DIO_DATA + 2) << 16;
2078 tx_under = inb(dev->base_addr + TLAN_DIO_DATA + 3);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002079
Sakari Ailusc659c382011-01-21 10:59:30 +00002080 outw(TLAN_GOOD_RX_FRMS, dev->base_addr + TLAN_DIO_ADR);
2081 rx_good = inb(dev->base_addr + TLAN_DIO_DATA);
2082 rx_good += inb(dev->base_addr + TLAN_DIO_DATA + 1) << 8;
2083 rx_good += inb(dev->base_addr + TLAN_DIO_DATA + 2) << 16;
2084 rx_over = inb(dev->base_addr + TLAN_DIO_DATA + 3);
Jeff Garzik6aa20a22006-09-13 13:24:59 -04002085
Sakari Ailusc659c382011-01-21 10:59:30 +00002086 outw(TLAN_DEFERRED_TX, dev->base_addr + TLAN_DIO_ADR);
2087 def_tx = inb(dev->base_addr + TLAN_DIO_DATA);
2088 def_tx += inb(dev->base_addr + TLAN_DIO_DATA + 1) << 8;
2089 crc = inb(dev->base_addr + TLAN_DIO_DATA + 2);
2090 code = inb(dev->base_addr + TLAN_DIO_DATA + 3);
Jeff Garzik6aa20a22006-09-13 13:24:59 -04002091
Sakari Ailusc659c382011-01-21 10:59:30 +00002092 outw(TLAN_MULTICOL_FRMS, dev->base_addr + TLAN_DIO_ADR);
2093 multi_col = inb(dev->base_addr + TLAN_DIO_DATA);
2094 multi_col += inb(dev->base_addr + TLAN_DIO_DATA + 1) << 8;
2095 single_col = inb(dev->base_addr + TLAN_DIO_DATA + 2);
2096 single_col += inb(dev->base_addr + TLAN_DIO_DATA + 3) << 8;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002097
Sakari Ailusc659c382011-01-21 10:59:30 +00002098 outw(TLAN_EXCESSCOL_FRMS, dev->base_addr + TLAN_DIO_ADR);
2099 excess_col = inb(dev->base_addr + TLAN_DIO_DATA);
2100 late_col = inb(dev->base_addr + TLAN_DIO_DATA + 1);
2101 loss = inb(dev->base_addr + TLAN_DIO_DATA + 2);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002102
Sakari Ailusc659c382011-01-21 10:59:30 +00002103 if (record) {
Stephen Hemmingerf8f31542008-05-30 09:49:53 -07002104 dev->stats.rx_packets += rx_good;
2105 dev->stats.rx_errors += rx_over + crc + code;
2106 dev->stats.tx_packets += tx_good;
2107 dev->stats.tx_errors += tx_under + loss;
Sakari Ailusc659c382011-01-21 10:59:30 +00002108 dev->stats.collisions += multi_col
2109 + single_col + excess_col + late_col;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002110
Stephen Hemmingerf8f31542008-05-30 09:49:53 -07002111 dev->stats.rx_over_errors += rx_over;
2112 dev->stats.rx_crc_errors += crc;
2113 dev->stats.rx_frame_errors += code;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002114
Stephen Hemmingerf8f31542008-05-30 09:49:53 -07002115 dev->stats.tx_aborted_errors += tx_under;
2116 dev->stats.tx_carrier_errors += loss;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002117 }
Jeff Garzik6aa20a22006-09-13 13:24:59 -04002118
Sakari Ailusc659c382011-01-21 10:59:30 +00002119}
Linus Torvalds1da177e2005-04-16 15:20:36 -07002120
2121
2122
2123
Sakari Ailusc659c382011-01-21 10:59:30 +00002124/***************************************************************
2125 * TLan_Reset
2126 *
2127 * Returns:
2128 * 0
2129 * Parms:
2130 * dev Pointer to device structure of adapter
2131 * to be reset.
2132 *
2133 * This function resets the adapter and it's physical
2134 * device. See Chap. 3, pp. 9-10 of the "ThunderLAN
2135 * Programmer's Guide" for details. The routine tries to
2136 * implement what is detailed there, though adjustments
2137 * have been made.
2138 *
2139 **************************************************************/
Linus Torvalds1da177e2005-04-16 15:20:36 -07002140
Harvey Harrison98e0f522008-02-18 10:04:38 -08002141static void
Sakari Ailusc659c382011-01-21 10:59:30 +00002142tlan_reset_adapter(struct net_device *dev)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002143{
Sakari Ailusc659c382011-01-21 10:59:30 +00002144 struct tlan_priv *priv = netdev_priv(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002145 int i;
2146 u32 addr;
2147 u32 data;
2148 u8 data8;
2149
Sakari Ailusc659c382011-01-21 10:59:30 +00002150 priv->tlan_full_duplex = false;
2151 priv->phy_online = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002152 netif_carrier_off(dev);
2153
2154/* 1. Assert reset bit. */
2155
2156 data = inl(dev->base_addr + TLAN_HOST_CMD);
2157 data |= TLAN_HC_AD_RST;
2158 outl(data, dev->base_addr + TLAN_HOST_CMD);
Jeff Garzik6aa20a22006-09-13 13:24:59 -04002159
Linus Torvalds1da177e2005-04-16 15:20:36 -07002160 udelay(1000);
2161
Sakari Ailusc659c382011-01-21 10:59:30 +00002162/* 2. Turn off interrupts. (Probably isn't necessary) */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002163
2164 data = inl(dev->base_addr + TLAN_HOST_CMD);
2165 data |= TLAN_HC_INT_OFF;
2166 outl(data, dev->base_addr + TLAN_HOST_CMD);
2167
2168/* 3. Clear AREGs and HASHs. */
2169
Sakari Ailusc659c382011-01-21 10:59:30 +00002170 for (i = TLAN_AREG_0; i <= TLAN_HASH_2; i += 4)
2171 tlan_dio_write32(dev->base_addr, (u16) i, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002172
2173/* 4. Setup NetConfig register. */
2174
2175 data = TLAN_NET_CFG_1FRAG | TLAN_NET_CFG_1CHAN | TLAN_NET_CFG_PHY_EN;
Sakari Ailusc659c382011-01-21 10:59:30 +00002176 tlan_dio_write16(dev->base_addr, TLAN_NET_CONFIG, (u16) data);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002177
2178/* 5. Load Ld_Tmr and Ld_Thr in HOST_CMD. */
2179
Sakari Ailusc659c382011-01-21 10:59:30 +00002180 outl(TLAN_HC_LD_TMR | 0x3f, dev->base_addr + TLAN_HOST_CMD);
2181 outl(TLAN_HC_LD_THR | 0x9, dev->base_addr + TLAN_HOST_CMD);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002182
2183/* 6. Unreset the MII by setting NMRST (in NetSio) to 1. */
2184
Sakari Ailusc659c382011-01-21 10:59:30 +00002185 outw(TLAN_NET_SIO, dev->base_addr + TLAN_DIO_ADR);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002186 addr = dev->base_addr + TLAN_DIO_DATA + TLAN_NET_SIO;
Sakari Ailusc659c382011-01-21 10:59:30 +00002187 tlan_set_bit(TLAN_NET_SIO_NMRST, addr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002188
2189/* 7. Setup the remaining registers. */
2190
Sakari Ailusc659c382011-01-21 10:59:30 +00002191 if (priv->tlan_rev >= 0x30) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002192 data8 = TLAN_ID_TX_EOC | TLAN_ID_RX_EOC;
Sakari Ailusc659c382011-01-21 10:59:30 +00002193 tlan_dio_write8(dev->base_addr, TLAN_INT_DIS, data8);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002194 }
Sakari Ailusc659c382011-01-21 10:59:30 +00002195 tlan_phy_detect(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002196 data = TLAN_NET_CFG_1FRAG | TLAN_NET_CFG_1CHAN;
Jeff Garzik6aa20a22006-09-13 13:24:59 -04002197
Sakari Ailusc659c382011-01-21 10:59:30 +00002198 if (priv->adapter->flags & TLAN_ADAPTER_BIT_RATE_PHY) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002199 data |= TLAN_NET_CFG_BIT;
Sakari Ailusc659c382011-01-21 10:59:30 +00002200 if (priv->aui == 1) {
2201 tlan_dio_write8(dev->base_addr, TLAN_ACOMMIT, 0x0a);
2202 } else if (priv->duplex == TLAN_DUPLEX_FULL) {
2203 tlan_dio_write8(dev->base_addr, TLAN_ACOMMIT, 0x00);
2204 priv->tlan_full_duplex = true;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002205 } else {
Sakari Ailusc659c382011-01-21 10:59:30 +00002206 tlan_dio_write8(dev->base_addr, TLAN_ACOMMIT, 0x08);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002207 }
2208 }
2209
Sakari Ailusc659c382011-01-21 10:59:30 +00002210 if (priv->phy_num == 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002211 data |= TLAN_NET_CFG_PHY_EN;
Sakari Ailusc659c382011-01-21 10:59:30 +00002212 tlan_dio_write16(dev->base_addr, TLAN_NET_CONFIG, (u16) data);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002213
Sakari Ailusc659c382011-01-21 10:59:30 +00002214 if (priv->adapter->flags & TLAN_ADAPTER_UNMANAGED_PHY)
2215 tlan_finish_reset(dev);
2216 else
2217 tlan_phy_power_down(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002218
Sakari Ailusc659c382011-01-21 10:59:30 +00002219}
Linus Torvalds1da177e2005-04-16 15:20:36 -07002220
2221
2222
2223
Harvey Harrison98e0f522008-02-18 10:04:38 -08002224static void
Sakari Ailusc659c382011-01-21 10:59:30 +00002225tlan_finish_reset(struct net_device *dev)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002226{
Sakari Ailusc659c382011-01-21 10:59:30 +00002227 struct tlan_priv *priv = netdev_priv(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002228 u8 data;
2229 u32 phy;
2230 u8 sio;
2231 u16 status;
2232 u16 partner;
2233 u16 tlphy_ctl;
Sakari Ailusc659c382011-01-21 10:59:30 +00002234 u16 tlphy_par;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002235 u16 tlphy_id1, tlphy_id2;
Sakari Ailusc659c382011-01-21 10:59:30 +00002236 int i;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002237
Sakari Ailusc659c382011-01-21 10:59:30 +00002238 phy = priv->phy[priv->phy_num];
Linus Torvalds1da177e2005-04-16 15:20:36 -07002239
2240 data = TLAN_NET_CMD_NRESET | TLAN_NET_CMD_NWRAP;
Sakari Ailusc659c382011-01-21 10:59:30 +00002241 if (priv->tlan_full_duplex)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002242 data |= TLAN_NET_CMD_DUPLEX;
Sakari Ailusc659c382011-01-21 10:59:30 +00002243 tlan_dio_write8(dev->base_addr, TLAN_NET_CMD, data);
Jeff Garzik6aa20a22006-09-13 13:24:59 -04002244 data = TLAN_NET_MASK_MASK4 | TLAN_NET_MASK_MASK5;
Sakari Ailusc659c382011-01-21 10:59:30 +00002245 if (priv->phy_num == 0)
Jeff Garzik6aa20a22006-09-13 13:24:59 -04002246 data |= TLAN_NET_MASK_MASK7;
Sakari Ailusc659c382011-01-21 10:59:30 +00002247 tlan_dio_write8(dev->base_addr, TLAN_NET_MASK, data);
2248 tlan_dio_write16(dev->base_addr, TLAN_MAX_RX, ((1536)+7)&~7);
2249 tlan_mii_read_reg(dev, phy, MII_GEN_ID_HI, &tlphy_id1);
2250 tlan_mii_read_reg(dev, phy, MII_GEN_ID_LO, &tlphy_id2);
Jeff Garzik6aa20a22006-09-13 13:24:59 -04002251
Sakari Ailusc659c382011-01-21 10:59:30 +00002252 if ((priv->adapter->flags & TLAN_ADAPTER_UNMANAGED_PHY) ||
2253 (priv->aui)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002254 status = MII_GS_LINK;
Joe Perches50624aa2011-03-01 06:56:33 +00002255 netdev_info(dev, "Link forced\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002256 } else {
Sakari Ailusc659c382011-01-21 10:59:30 +00002257 tlan_mii_read_reg(dev, phy, MII_GEN_STS, &status);
2258 udelay(1000);
2259 tlan_mii_read_reg(dev, phy, MII_GEN_STS, &status);
2260 if ((status & MII_GS_LINK) &&
2261 /* We only support link info on Nat.Sem. PHY's */
2262 (tlphy_id1 == NAT_SEM_ID1) &&
2263 (tlphy_id2 == NAT_SEM_ID2)) {
2264 tlan_mii_read_reg(dev, phy, MII_AN_LPA, &partner);
2265 tlan_mii_read_reg(dev, phy, TLAN_TLPHY_PAR, &tlphy_par);
Jeff Garzik6aa20a22006-09-13 13:24:59 -04002266
Joe Perches50624aa2011-03-01 06:56:33 +00002267 netdev_info(dev,
2268 "Link active with %s %uMbps %s-Duplex\n",
2269 !(tlphy_par & TLAN_PHY_AN_EN_STAT)
2270 ? "forced" : "Autonegotiation enabled,",
2271 tlphy_par & TLAN_PHY_SPEED_100
2272 ? 100 : 10,
2273 tlphy_par & TLAN_PHY_DUPLEX_FULL
2274 ? "Full" : "Half");
2275
2276 if (tlphy_par & TLAN_PHY_AN_EN_STAT) {
2277 netdev_info(dev, "Partner capability:");
2278 for (i = 5; i < 10; i++)
2279 if (partner & (1 << i))
2280 pr_cont(" %s", media[i-5]);
2281 pr_cont("\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002282 }
2283
Sakari Ailusc659c382011-01-21 10:59:30 +00002284 tlan_dio_write8(dev->base_addr, TLAN_LED_REG,
2285 TLAN_LED_LINK);
Jeff Garzik6aa20a22006-09-13 13:24:59 -04002286#ifdef MONITOR
Linus Torvalds1da177e2005-04-16 15:20:36 -07002287 /* We have link beat..for now anyway */
Sakari Ailusc659c382011-01-21 10:59:30 +00002288 priv->link = 1;
2289 /*Enabling link beat monitoring */
2290 tlan_set_timer(dev, (10*HZ), TLAN_TIMER_LINK_BEAT);
Jeff Garzik6aa20a22006-09-13 13:24:59 -04002291#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -07002292 } else if (status & MII_GS_LINK) {
Joe Perches50624aa2011-03-01 06:56:33 +00002293 netdev_info(dev, "Link active\n");
Sakari Ailusc659c382011-01-21 10:59:30 +00002294 tlan_dio_write8(dev->base_addr, TLAN_LED_REG,
2295 TLAN_LED_LINK);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002296 }
2297 }
2298
Sakari Ailusc659c382011-01-21 10:59:30 +00002299 if (priv->phy_num == 0) {
2300 tlan_mii_read_reg(dev, phy, TLAN_TLPHY_CTL, &tlphy_ctl);
2301 tlphy_ctl |= TLAN_TC_INTEN;
2302 tlan_mii_write_reg(dev, phy, TLAN_TLPHY_CTL, tlphy_ctl);
2303 sio = tlan_dio_read8(dev->base_addr, TLAN_NET_SIO);
2304 sio |= TLAN_NET_SIO_MINTEN;
2305 tlan_dio_write8(dev->base_addr, TLAN_NET_SIO, sio);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002306 }
2307
Sakari Ailusc659c382011-01-21 10:59:30 +00002308 if (status & MII_GS_LINK) {
2309 tlan_set_mac(dev, 0, dev->dev_addr);
2310 priv->phy_online = 1;
2311 outb((TLAN_HC_INT_ON >> 8), dev->base_addr + TLAN_HOST_CMD + 1);
2312 if (debug >= 1 && debug != TLAN_DEBUG_PROBE)
2313 outb((TLAN_HC_REQ_INT >> 8),
2314 dev->base_addr + TLAN_HOST_CMD + 1);
2315 outl(priv->rx_list_dma, dev->base_addr + TLAN_CH_PARM);
2316 outl(TLAN_HC_GO | TLAN_HC_RT, dev->base_addr + TLAN_HOST_CMD);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002317 netif_carrier_on(dev);
2318 } else {
Joe Perches50624aa2011-03-01 06:56:33 +00002319 netdev_info(dev, "Link inactive, will retry in 10 secs...\n");
Sakari Ailusc659c382011-01-21 10:59:30 +00002320 tlan_set_timer(dev, (10*HZ), TLAN_TIMER_FINISH_RESET);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002321 return;
2322 }
Sakari Ailusc659c382011-01-21 10:59:30 +00002323 tlan_set_multicast_list(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002324
Sakari Ailusc659c382011-01-21 10:59:30 +00002325}
Linus Torvalds1da177e2005-04-16 15:20:36 -07002326
2327
2328
2329
Sakari Ailusc659c382011-01-21 10:59:30 +00002330/***************************************************************
2331 * tlan_set_mac
2332 *
2333 * Returns:
2334 * Nothing
2335 * Parms:
2336 * dev Pointer to device structure of adapter
2337 * on which to change the AREG.
2338 * areg The AREG to set the address in (0 - 3).
2339 * mac A pointer to an array of chars. Each
2340 * element stores one byte of the address.
2341 * IE, it isn't in ascii.
2342 *
2343 * This function transfers a MAC address to one of the
2344 * TLAN AREGs (address registers). The TLAN chip locks
2345 * the register on writing to offset 0 and unlocks the
2346 * register after writing to offset 5. If NULL is passed
2347 * in mac, then the AREG is filled with 0's.
2348 *
2349 **************************************************************/
Linus Torvalds1da177e2005-04-16 15:20:36 -07002350
Sakari Ailusc659c382011-01-21 10:59:30 +00002351static void tlan_set_mac(struct net_device *dev, int areg, char *mac)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002352{
2353 int i;
Jeff Garzik6aa20a22006-09-13 13:24:59 -04002354
Linus Torvalds1da177e2005-04-16 15:20:36 -07002355 areg *= 6;
2356
Sakari Ailusc659c382011-01-21 10:59:30 +00002357 if (mac != NULL) {
2358 for (i = 0; i < 6; i++)
2359 tlan_dio_write8(dev->base_addr,
2360 TLAN_AREG_0 + areg + i, mac[i]);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002361 } else {
Sakari Ailusc659c382011-01-21 10:59:30 +00002362 for (i = 0; i < 6; i++)
2363 tlan_dio_write8(dev->base_addr,
2364 TLAN_AREG_0 + areg + i, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002365 }
2366
Sakari Ailusc659c382011-01-21 10:59:30 +00002367}
Linus Torvalds1da177e2005-04-16 15:20:36 -07002368
2369
2370
2371
2372/*****************************************************************************
2373******************************************************************************
2374
Sakari Ailusc659c382011-01-21 10:59:30 +00002375ThunderLAN driver PHY layer routines
Linus Torvalds1da177e2005-04-16 15:20:36 -07002376
2377******************************************************************************
2378*****************************************************************************/
2379
2380
2381
Sakari Ailusc659c382011-01-21 10:59:30 +00002382/*********************************************************************
2383 * tlan_phy_print
2384 *
2385 * Returns:
2386 * Nothing
2387 * Parms:
2388 * dev A pointer to the device structure of the
2389 * TLAN device having the PHYs to be detailed.
2390 *
2391 * This function prints the registers a PHY (aka transceiver).
2392 *
2393 ********************************************************************/
Linus Torvalds1da177e2005-04-16 15:20:36 -07002394
Sakari Ailusc659c382011-01-21 10:59:30 +00002395static void tlan_phy_print(struct net_device *dev)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002396{
Sakari Ailusc659c382011-01-21 10:59:30 +00002397 struct tlan_priv *priv = netdev_priv(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002398 u16 i, data0, data1, data2, data3, phy;
2399
Sakari Ailusc659c382011-01-21 10:59:30 +00002400 phy = priv->phy[priv->phy_num];
Linus Torvalds1da177e2005-04-16 15:20:36 -07002401
Sakari Ailusc659c382011-01-21 10:59:30 +00002402 if (priv->adapter->flags & TLAN_ADAPTER_UNMANAGED_PHY) {
Joe Perches50624aa2011-03-01 06:56:33 +00002403 netdev_info(dev, "Unmanaged PHY\n");
Sakari Ailusc659c382011-01-21 10:59:30 +00002404 } else if (phy <= TLAN_PHY_MAX_ADDR) {
Joe Perches50624aa2011-03-01 06:56:33 +00002405 netdev_info(dev, "PHY 0x%02x\n", phy);
2406 pr_info(" Off. +0 +1 +2 +3\n");
Sakari Ailusc659c382011-01-21 10:59:30 +00002407 for (i = 0; i < 0x20; i += 4) {
Sakari Ailusc659c382011-01-21 10:59:30 +00002408 tlan_mii_read_reg(dev, phy, i, &data0);
Sakari Ailusc659c382011-01-21 10:59:30 +00002409 tlan_mii_read_reg(dev, phy, i + 1, &data1);
Sakari Ailusc659c382011-01-21 10:59:30 +00002410 tlan_mii_read_reg(dev, phy, i + 2, &data2);
Sakari Ailusc659c382011-01-21 10:59:30 +00002411 tlan_mii_read_reg(dev, phy, i + 3, &data3);
Joe Perches50624aa2011-03-01 06:56:33 +00002412 pr_info(" 0x%02x 0x%04hx 0x%04hx 0x%04hx 0x%04hx\n",
2413 i, data0, data1, data2, data3);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002414 }
2415 } else {
Joe Perches50624aa2011-03-01 06:56:33 +00002416 netdev_info(dev, "Invalid PHY\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002417 }
2418
Sakari Ailusc659c382011-01-21 10:59:30 +00002419}
Linus Torvalds1da177e2005-04-16 15:20:36 -07002420
2421
2422
2423
Sakari Ailusc659c382011-01-21 10:59:30 +00002424/*********************************************************************
2425 * tlan_phy_detect
2426 *
2427 * Returns:
2428 * Nothing
2429 * Parms:
2430 * dev A pointer to the device structure of the adapter
2431 * for which the PHY needs determined.
2432 *
2433 * So far I've found that adapters which have external PHYs
2434 * may also use the internal PHY for part of the functionality.
2435 * (eg, AUI/Thinnet). This function finds out if this TLAN
2436 * chip has an internal PHY, and then finds the first external
2437 * PHY (starting from address 0) if it exists).
2438 *
2439 ********************************************************************/
Linus Torvalds1da177e2005-04-16 15:20:36 -07002440
Sakari Ailusc659c382011-01-21 10:59:30 +00002441static void tlan_phy_detect(struct net_device *dev)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002442{
Sakari Ailusc659c382011-01-21 10:59:30 +00002443 struct tlan_priv *priv = netdev_priv(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002444 u16 control;
2445 u16 hi;
2446 u16 lo;
2447 u32 phy;
2448
Sakari Ailusc659c382011-01-21 10:59:30 +00002449 if (priv->adapter->flags & TLAN_ADAPTER_UNMANAGED_PHY) {
2450 priv->phy_num = 0xffff;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002451 return;
2452 }
2453
Sakari Ailusc659c382011-01-21 10:59:30 +00002454 tlan_mii_read_reg(dev, TLAN_PHY_MAX_ADDR, MII_GEN_ID_HI, &hi);
Jeff Garzik6aa20a22006-09-13 13:24:59 -04002455
Sakari Ailusc659c382011-01-21 10:59:30 +00002456 if (hi != 0xffff)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002457 priv->phy[0] = TLAN_PHY_MAX_ADDR;
Sakari Ailusc659c382011-01-21 10:59:30 +00002458 else
Linus Torvalds1da177e2005-04-16 15:20:36 -07002459 priv->phy[0] = TLAN_PHY_NONE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002460
2461 priv->phy[1] = TLAN_PHY_NONE;
Sakari Ailusc659c382011-01-21 10:59:30 +00002462 for (phy = 0; phy <= TLAN_PHY_MAX_ADDR; phy++) {
2463 tlan_mii_read_reg(dev, phy, MII_GEN_CTL, &control);
2464 tlan_mii_read_reg(dev, phy, MII_GEN_ID_HI, &hi);
2465 tlan_mii_read_reg(dev, phy, MII_GEN_ID_LO, &lo);
2466 if ((control != 0xffff) ||
2467 (hi != 0xffff) || (lo != 0xffff)) {
2468 TLAN_DBG(TLAN_DEBUG_GNRL,
2469 "PHY found at %02x %04x %04x %04x\n",
2470 phy, control, hi, lo);
2471 if ((priv->phy[1] == TLAN_PHY_NONE) &&
2472 (phy != TLAN_PHY_MAX_ADDR)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002473 priv->phy[1] = phy;
2474 }
2475 }
2476 }
2477
Sakari Ailusc659c382011-01-21 10:59:30 +00002478 if (priv->phy[1] != TLAN_PHY_NONE)
2479 priv->phy_num = 1;
2480 else if (priv->phy[0] != TLAN_PHY_NONE)
2481 priv->phy_num = 0;
2482 else
Joe Perches50624aa2011-03-01 06:56:33 +00002483 netdev_info(dev, "Cannot initialize device, no PHY was found!\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002484
Sakari Ailusc659c382011-01-21 10:59:30 +00002485}
Linus Torvalds1da177e2005-04-16 15:20:36 -07002486
2487
2488
2489
Sakari Ailusc659c382011-01-21 10:59:30 +00002490static void tlan_phy_power_down(struct net_device *dev)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002491{
Sakari Ailusc659c382011-01-21 10:59:30 +00002492 struct tlan_priv *priv = netdev_priv(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002493 u16 value;
2494
Sakari Ailusc659c382011-01-21 10:59:30 +00002495 TLAN_DBG(TLAN_DEBUG_GNRL, "%s: Powering down PHY(s).\n", dev->name);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002496 value = MII_GC_PDOWN | MII_GC_LOOPBK | MII_GC_ISOLATE;
Sakari Ailusc659c382011-01-21 10:59:30 +00002497 tlan_mii_sync(dev->base_addr);
2498 tlan_mii_write_reg(dev, priv->phy[priv->phy_num], MII_GEN_CTL, value);
2499 if ((priv->phy_num == 0) &&
2500 (priv->phy[1] != TLAN_PHY_NONE) &&
2501 (!(priv->adapter->flags & TLAN_ADAPTER_USE_INTERN_10))) {
2502 tlan_mii_sync(dev->base_addr);
2503 tlan_mii_write_reg(dev, priv->phy[1], MII_GEN_CTL, value);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002504 }
2505
2506 /* Wait for 50 ms and powerup
2507 * This is abitrary. It is intended to make sure the
2508 * transceiver settles.
2509 */
Sakari Ailusc659c382011-01-21 10:59:30 +00002510 tlan_set_timer(dev, (HZ/20), TLAN_TIMER_PHY_PUP);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002511
Sakari Ailusc659c382011-01-21 10:59:30 +00002512}
Linus Torvalds1da177e2005-04-16 15:20:36 -07002513
2514
2515
2516
Sakari Ailusc659c382011-01-21 10:59:30 +00002517static void tlan_phy_power_up(struct net_device *dev)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002518{
Sakari Ailusc659c382011-01-21 10:59:30 +00002519 struct tlan_priv *priv = netdev_priv(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002520 u16 value;
2521
Sakari Ailusc659c382011-01-21 10:59:30 +00002522 TLAN_DBG(TLAN_DEBUG_GNRL, "%s: Powering up PHY.\n", dev->name);
2523 tlan_mii_sync(dev->base_addr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002524 value = MII_GC_LOOPBK;
Sakari Ailusc659c382011-01-21 10:59:30 +00002525 tlan_mii_write_reg(dev, priv->phy[priv->phy_num], MII_GEN_CTL, value);
2526 tlan_mii_sync(dev->base_addr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002527 /* Wait for 500 ms and reset the
2528 * transceiver. The TLAN docs say both 50 ms and
2529 * 500 ms, so do the longer, just in case.
2530 */
Sakari Ailusc659c382011-01-21 10:59:30 +00002531 tlan_set_timer(dev, (HZ/20), TLAN_TIMER_PHY_RESET);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002532
Sakari Ailusc659c382011-01-21 10:59:30 +00002533}
Linus Torvalds1da177e2005-04-16 15:20:36 -07002534
2535
2536
2537
Sakari Ailusc659c382011-01-21 10:59:30 +00002538static void tlan_phy_reset(struct net_device *dev)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002539{
Sakari Ailusc659c382011-01-21 10:59:30 +00002540 struct tlan_priv *priv = netdev_priv(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002541 u16 phy;
2542 u16 value;
2543
Sakari Ailusc659c382011-01-21 10:59:30 +00002544 phy = priv->phy[priv->phy_num];
Linus Torvalds1da177e2005-04-16 15:20:36 -07002545
Masanari Iidafd9071e2012-04-13 04:33:20 +00002546 TLAN_DBG(TLAN_DEBUG_GNRL, "%s: Resetting PHY.\n", dev->name);
Sakari Ailusc659c382011-01-21 10:59:30 +00002547 tlan_mii_sync(dev->base_addr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002548 value = MII_GC_LOOPBK | MII_GC_RESET;
Sakari Ailusc659c382011-01-21 10:59:30 +00002549 tlan_mii_write_reg(dev, phy, MII_GEN_CTL, value);
2550 tlan_mii_read_reg(dev, phy, MII_GEN_CTL, &value);
2551 while (value & MII_GC_RESET)
2552 tlan_mii_read_reg(dev, phy, MII_GEN_CTL, &value);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002553
2554 /* Wait for 500 ms and initialize.
2555 * I don't remember why I wait this long.
2556 * I've changed this to 50ms, as it seems long enough.
2557 */
Sakari Ailusc659c382011-01-21 10:59:30 +00002558 tlan_set_timer(dev, (HZ/20), TLAN_TIMER_PHY_START_LINK);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002559
Sakari Ailusc659c382011-01-21 10:59:30 +00002560}
Linus Torvalds1da177e2005-04-16 15:20:36 -07002561
2562
2563
2564
Sakari Ailusc659c382011-01-21 10:59:30 +00002565static void tlan_phy_start_link(struct net_device *dev)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002566{
Sakari Ailusc659c382011-01-21 10:59:30 +00002567 struct tlan_priv *priv = netdev_priv(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002568 u16 ability;
2569 u16 control;
2570 u16 data;
2571 u16 phy;
2572 u16 status;
2573 u16 tctl;
2574
Sakari Ailusc659c382011-01-21 10:59:30 +00002575 phy = priv->phy[priv->phy_num];
2576 TLAN_DBG(TLAN_DEBUG_GNRL, "%s: Trying to activate link.\n", dev->name);
2577 tlan_mii_read_reg(dev, phy, MII_GEN_STS, &status);
2578 tlan_mii_read_reg(dev, phy, MII_GEN_STS, &ability);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002579
Sakari Ailusc659c382011-01-21 10:59:30 +00002580 if ((status & MII_GS_AUTONEG) &&
2581 (!priv->aui)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002582 ability = status >> 11;
Sakari Ailusc659c382011-01-21 10:59:30 +00002583 if (priv->speed == TLAN_SPEED_10 &&
2584 priv->duplex == TLAN_DUPLEX_HALF) {
2585 tlan_mii_write_reg(dev, phy, MII_GEN_CTL, 0x0000);
2586 } else if (priv->speed == TLAN_SPEED_10 &&
2587 priv->duplex == TLAN_DUPLEX_FULL) {
2588 priv->tlan_full_duplex = true;
2589 tlan_mii_write_reg(dev, phy, MII_GEN_CTL, 0x0100);
2590 } else if (priv->speed == TLAN_SPEED_100 &&
2591 priv->duplex == TLAN_DUPLEX_HALF) {
2592 tlan_mii_write_reg(dev, phy, MII_GEN_CTL, 0x2000);
2593 } else if (priv->speed == TLAN_SPEED_100 &&
2594 priv->duplex == TLAN_DUPLEX_FULL) {
2595 priv->tlan_full_duplex = true;
2596 tlan_mii_write_reg(dev, phy, MII_GEN_CTL, 0x2100);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002597 } else {
Jeff Garzik6aa20a22006-09-13 13:24:59 -04002598
Linus Torvalds1da177e2005-04-16 15:20:36 -07002599 /* Set Auto-Neg advertisement */
Sakari Ailusc659c382011-01-21 10:59:30 +00002600 tlan_mii_write_reg(dev, phy, MII_AN_ADV,
2601 (ability << 5) | 1);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002602 /* Enablee Auto-Neg */
Sakari Ailusc659c382011-01-21 10:59:30 +00002603 tlan_mii_write_reg(dev, phy, MII_GEN_CTL, 0x1000);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002604 /* Restart Auto-Neg */
Sakari Ailusc659c382011-01-21 10:59:30 +00002605 tlan_mii_write_reg(dev, phy, MII_GEN_CTL, 0x1200);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002606 /* Wait for 4 sec for autonegotiation
Sakari Ailusc659c382011-01-21 10:59:30 +00002607 * to complete. The max spec time is less than this
2608 * but the card need additional time to start AN.
2609 * .5 sec should be plenty extra.
2610 */
Joe Perches50624aa2011-03-01 06:56:33 +00002611 netdev_info(dev, "Starting autonegotiation\n");
Sakari Ailusc659c382011-01-21 10:59:30 +00002612 tlan_set_timer(dev, (2*HZ), TLAN_TIMER_PHY_FINISH_AN);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002613 return;
2614 }
Jeff Garzik6aa20a22006-09-13 13:24:59 -04002615
2616 }
2617
Sakari Ailusc659c382011-01-21 10:59:30 +00002618 if ((priv->aui) && (priv->phy_num != 0)) {
2619 priv->phy_num = 0;
2620 data = TLAN_NET_CFG_1FRAG | TLAN_NET_CFG_1CHAN
2621 | TLAN_NET_CFG_PHY_EN;
2622 tlan_dio_write16(dev->base_addr, TLAN_NET_CONFIG, data);
2623 tlan_set_timer(dev, (40*HZ/1000), TLAN_TIMER_PHY_PDOWN);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002624 return;
Sakari Ailusc659c382011-01-21 10:59:30 +00002625 } else if (priv->phy_num == 0) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002626 control = 0;
Sakari Ailusc659c382011-01-21 10:59:30 +00002627 tlan_mii_read_reg(dev, phy, TLAN_TLPHY_CTL, &tctl);
2628 if (priv->aui) {
2629 tctl |= TLAN_TC_AUISEL;
Jeff Garzik6aa20a22006-09-13 13:24:59 -04002630 } else {
Sakari Ailusc659c382011-01-21 10:59:30 +00002631 tctl &= ~TLAN_TC_AUISEL;
2632 if (priv->duplex == TLAN_DUPLEX_FULL) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002633 control |= MII_GC_DUPLEX;
Sakari Ailusc659c382011-01-21 10:59:30 +00002634 priv->tlan_full_duplex = true;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002635 }
Sakari Ailusc659c382011-01-21 10:59:30 +00002636 if (priv->speed == TLAN_SPEED_100)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002637 control |= MII_GC_SPEEDSEL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002638 }
Sakari Ailusc659c382011-01-21 10:59:30 +00002639 tlan_mii_write_reg(dev, phy, MII_GEN_CTL, control);
2640 tlan_mii_write_reg(dev, phy, TLAN_TLPHY_CTL, tctl);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002641 }
2642
2643 /* Wait for 2 sec to give the transceiver time
2644 * to establish link.
2645 */
Sakari Ailusc659c382011-01-21 10:59:30 +00002646 tlan_set_timer(dev, (4*HZ), TLAN_TIMER_FINISH_RESET);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002647
Sakari Ailusc659c382011-01-21 10:59:30 +00002648}
Linus Torvalds1da177e2005-04-16 15:20:36 -07002649
2650
2651
2652
Sakari Ailusc659c382011-01-21 10:59:30 +00002653static void tlan_phy_finish_auto_neg(struct net_device *dev)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002654{
Sakari Ailusc659c382011-01-21 10:59:30 +00002655 struct tlan_priv *priv = netdev_priv(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002656 u16 an_adv;
2657 u16 an_lpa;
2658 u16 data;
2659 u16 mode;
2660 u16 phy;
2661 u16 status;
Jeff Garzik6aa20a22006-09-13 13:24:59 -04002662
Sakari Ailusc659c382011-01-21 10:59:30 +00002663 phy = priv->phy[priv->phy_num];
Linus Torvalds1da177e2005-04-16 15:20:36 -07002664
Sakari Ailusc659c382011-01-21 10:59:30 +00002665 tlan_mii_read_reg(dev, phy, MII_GEN_STS, &status);
2666 udelay(1000);
2667 tlan_mii_read_reg(dev, phy, MII_GEN_STS, &status);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002668
Sakari Ailusc659c382011-01-21 10:59:30 +00002669 if (!(status & MII_GS_AUTOCMPLT)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002670 /* Wait for 8 sec to give the process
2671 * more time. Perhaps we should fail after a while.
2672 */
Sakari Ailusc659c382011-01-21 10:59:30 +00002673 if (!priv->neg_be_verbose++) {
Joe Perches50624aa2011-03-01 06:56:33 +00002674 pr_info("Giving autonegotiation more time.\n");
2675 pr_info("Please check that your adapter has\n");
2676 pr_info("been properly connected to a HUB or Switch.\n");
2677 pr_info("Trying to establish link in the background...\n");
Sakari Ailusc659c382011-01-21 10:59:30 +00002678 }
2679 tlan_set_timer(dev, (8*HZ), TLAN_TIMER_PHY_FINISH_AN);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002680 return;
2681 }
2682
Joe Perches50624aa2011-03-01 06:56:33 +00002683 netdev_info(dev, "Autonegotiation complete\n");
Sakari Ailusc659c382011-01-21 10:59:30 +00002684 tlan_mii_read_reg(dev, phy, MII_AN_ADV, &an_adv);
2685 tlan_mii_read_reg(dev, phy, MII_AN_LPA, &an_lpa);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002686 mode = an_adv & an_lpa & 0x03E0;
Sakari Ailusc659c382011-01-21 10:59:30 +00002687 if (mode & 0x0100)
2688 priv->tlan_full_duplex = true;
2689 else if (!(mode & 0x0080) && (mode & 0x0040))
2690 priv->tlan_full_duplex = true;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002691
Sakari Ailusc659c382011-01-21 10:59:30 +00002692 if ((!(mode & 0x0180)) &&
2693 (priv->adapter->flags & TLAN_ADAPTER_USE_INTERN_10) &&
2694 (priv->phy_num != 0)) {
2695 priv->phy_num = 0;
2696 data = TLAN_NET_CFG_1FRAG | TLAN_NET_CFG_1CHAN
2697 | TLAN_NET_CFG_PHY_EN;
2698 tlan_dio_write16(dev->base_addr, TLAN_NET_CONFIG, data);
2699 tlan_set_timer(dev, (400*HZ/1000), TLAN_TIMER_PHY_PDOWN);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002700 return;
2701 }
2702
Sakari Ailusc659c382011-01-21 10:59:30 +00002703 if (priv->phy_num == 0) {
2704 if ((priv->duplex == TLAN_DUPLEX_FULL) ||
2705 (an_adv & an_lpa & 0x0040)) {
2706 tlan_mii_write_reg(dev, phy, MII_GEN_CTL,
2707 MII_GC_AUTOENB | MII_GC_DUPLEX);
Joe Perches50624aa2011-03-01 06:56:33 +00002708 netdev_info(dev, "Starting internal PHY with FULL-DUPLEX\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002709 } else {
Sakari Ailusc659c382011-01-21 10:59:30 +00002710 tlan_mii_write_reg(dev, phy, MII_GEN_CTL,
2711 MII_GC_AUTOENB);
Joe Perches50624aa2011-03-01 06:56:33 +00002712 netdev_info(dev, "Starting internal PHY with HALF-DUPLEX\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002713 }
2714 }
2715
2716 /* Wait for 100 ms. No reason in partiticular.
2717 */
Sakari Ailusc659c382011-01-21 10:59:30 +00002718 tlan_set_timer(dev, (HZ/10), TLAN_TIMER_FINISH_RESET);
Jeff Garzik6aa20a22006-09-13 13:24:59 -04002719
Sakari Ailusc659c382011-01-21 10:59:30 +00002720}
Linus Torvalds1da177e2005-04-16 15:20:36 -07002721
2722#ifdef MONITOR
2723
Sakari Ailusc659c382011-01-21 10:59:30 +00002724/*********************************************************************
2725 *
2726 * tlan_phy_monitor
2727 *
2728 * Returns:
2729 * None
2730 *
2731 * Params:
2732 * dev The device structure of this device.
2733 *
2734 *
2735 * This function monitors PHY condition by reading the status
2736 * register via the MII bus. This can be used to give info
2737 * about link changes (up/down), and possible switch to alternate
2738 * media.
2739 *
2740 *******************************************************************/
Linus Torvalds1da177e2005-04-16 15:20:36 -07002741
Sakari Ailusc659c382011-01-21 10:59:30 +00002742void tlan_phy_monitor(struct net_device *dev)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002743{
Sakari Ailusc659c382011-01-21 10:59:30 +00002744 struct tlan_priv *priv = netdev_priv(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002745 u16 phy;
2746 u16 phy_status;
2747
Sakari Ailusc659c382011-01-21 10:59:30 +00002748 phy = priv->phy[priv->phy_num];
Linus Torvalds1da177e2005-04-16 15:20:36 -07002749
Sakari Ailusc659c382011-01-21 10:59:30 +00002750 /* Get PHY status register */
2751 tlan_mii_read_reg(dev, phy, MII_GEN_STS, &phy_status);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002752
Sakari Ailusc659c382011-01-21 10:59:30 +00002753 /* Check if link has been lost */
2754 if (!(phy_status & MII_GS_LINK)) {
2755 if (priv->link) {
2756 priv->link = 0;
2757 printk(KERN_DEBUG "TLAN: %s has lost link\n",
2758 dev->name);
2759 netif_carrier_off(dev);
2760 tlan_set_timer(dev, (2*HZ), TLAN_TIMER_LINK_BEAT);
2761 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002762 }
2763 }
2764
Sakari Ailusc659c382011-01-21 10:59:30 +00002765 /* Link restablished? */
2766 if ((phy_status & MII_GS_LINK) && !priv->link) {
2767 priv->link = 1;
2768 printk(KERN_DEBUG "TLAN: %s has reestablished link\n",
2769 dev->name);
7d17c1d2005-05-12 19:45:25 -04002770 netif_carrier_on(dev);
Sakari Ailusc659c382011-01-21 10:59:30 +00002771 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002772
2773 /* Setup a new monitor */
Sakari Ailusc659c382011-01-21 10:59:30 +00002774 tlan_set_timer(dev, (2*HZ), TLAN_TIMER_LINK_BEAT);
Jeff Garzik6aa20a22006-09-13 13:24:59 -04002775}
Linus Torvalds1da177e2005-04-16 15:20:36 -07002776
2777#endif /* MONITOR */
2778
2779
2780/*****************************************************************************
2781******************************************************************************
2782
Sakari Ailusc659c382011-01-21 10:59:30 +00002783ThunderLAN driver MII routines
Linus Torvalds1da177e2005-04-16 15:20:36 -07002784
Sakari Ailusc659c382011-01-21 10:59:30 +00002785these routines are based on the information in chap. 2 of the
2786"ThunderLAN Programmer's Guide", pp. 15-24.
Linus Torvalds1da177e2005-04-16 15:20:36 -07002787
2788******************************************************************************
2789*****************************************************************************/
2790
2791
Sakari Ailusc659c382011-01-21 10:59:30 +00002792/***************************************************************
2793 * tlan_mii_read_reg
2794 *
2795 * Returns:
2796 * false if ack received ok
2797 * true if no ack received or other error
2798 *
2799 * Parms:
2800 * dev The device structure containing
2801 * The io address and interrupt count
2802 * for this device.
2803 * phy The address of the PHY to be queried.
2804 * reg The register whose contents are to be
2805 * retrieved.
2806 * val A pointer to a variable to store the
2807 * retrieved value.
2808 *
2809 * This function uses the TLAN's MII bus to retrieve the contents
2810 * of a given register on a PHY. It sends the appropriate info
2811 * and then reads the 16-bit register value from the MII bus via
2812 * the TLAN SIO register.
2813 *
2814 **************************************************************/
Linus Torvalds1da177e2005-04-16 15:20:36 -07002815
Sakari Ailusc659c382011-01-21 10:59:30 +00002816static bool
2817tlan_mii_read_reg(struct net_device *dev, u16 phy, u16 reg, u16 *val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002818{
2819 u8 nack;
2820 u16 sio, tmp;
Sakari Ailusc659c382011-01-21 10:59:30 +00002821 u32 i;
Joe Perches37fce432010-01-12 20:59:13 +00002822 bool err;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002823 int minten;
Sakari Ailusc659c382011-01-21 10:59:30 +00002824 struct tlan_priv *priv = netdev_priv(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002825 unsigned long flags = 0;
2826
Joe Perches37fce432010-01-12 20:59:13 +00002827 err = false;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002828 outw(TLAN_NET_SIO, dev->base_addr + TLAN_DIO_ADR);
2829 sio = dev->base_addr + TLAN_DIO_DATA + TLAN_NET_SIO;
Jeff Garzik6aa20a22006-09-13 13:24:59 -04002830
Linus Torvalds1da177e2005-04-16 15:20:36 -07002831 if (!in_irq())
2832 spin_lock_irqsave(&priv->lock, flags);
2833
Sakari Ailusc659c382011-01-21 10:59:30 +00002834 tlan_mii_sync(dev->base_addr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002835
Sakari Ailusc659c382011-01-21 10:59:30 +00002836 minten = tlan_get_bit(TLAN_NET_SIO_MINTEN, sio);
2837 if (minten)
2838 tlan_clear_bit(TLAN_NET_SIO_MINTEN, sio);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002839
Sakari Ailusc659c382011-01-21 10:59:30 +00002840 tlan_mii_send_data(dev->base_addr, 0x1, 2); /* start (01b) */
2841 tlan_mii_send_data(dev->base_addr, 0x2, 2); /* read (10b) */
2842 tlan_mii_send_data(dev->base_addr, phy, 5); /* device # */
2843 tlan_mii_send_data(dev->base_addr, reg, 5); /* register # */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002844
2845
Sakari Ailusc659c382011-01-21 10:59:30 +00002846 tlan_clear_bit(TLAN_NET_SIO_MTXEN, sio); /* change direction */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002847
Sakari Ailusc659c382011-01-21 10:59:30 +00002848 tlan_clear_bit(TLAN_NET_SIO_MCLK, sio); /* clock idle bit */
2849 tlan_set_bit(TLAN_NET_SIO_MCLK, sio);
2850 tlan_clear_bit(TLAN_NET_SIO_MCLK, sio); /* wait 300ns */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002851
Sakari Ailusc659c382011-01-21 10:59:30 +00002852 nack = tlan_get_bit(TLAN_NET_SIO_MDATA, sio); /* check for ACK */
2853 tlan_set_bit(TLAN_NET_SIO_MCLK, sio); /* finish ACK */
2854 if (nack) { /* no ACK, so fake it */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002855 for (i = 0; i < 16; i++) {
Sakari Ailusc659c382011-01-21 10:59:30 +00002856 tlan_clear_bit(TLAN_NET_SIO_MCLK, sio);
2857 tlan_set_bit(TLAN_NET_SIO_MCLK, sio);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002858 }
2859 tmp = 0xffff;
Joe Perches37fce432010-01-12 20:59:13 +00002860 err = true;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002861 } else { /* ACK, so read data */
2862 for (tmp = 0, i = 0x8000; i; i >>= 1) {
Sakari Ailusc659c382011-01-21 10:59:30 +00002863 tlan_clear_bit(TLAN_NET_SIO_MCLK, sio);
2864 if (tlan_get_bit(TLAN_NET_SIO_MDATA, sio))
Linus Torvalds1da177e2005-04-16 15:20:36 -07002865 tmp |= i;
Sakari Ailusc659c382011-01-21 10:59:30 +00002866 tlan_set_bit(TLAN_NET_SIO_MCLK, sio);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002867 }
2868 }
2869
2870
Sakari Ailusc659c382011-01-21 10:59:30 +00002871 tlan_clear_bit(TLAN_NET_SIO_MCLK, sio); /* idle cycle */
2872 tlan_set_bit(TLAN_NET_SIO_MCLK, sio);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002873
Sakari Ailusc659c382011-01-21 10:59:30 +00002874 if (minten)
2875 tlan_set_bit(TLAN_NET_SIO_MINTEN, sio);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002876
2877 *val = tmp;
Jeff Garzik6aa20a22006-09-13 13:24:59 -04002878
Linus Torvalds1da177e2005-04-16 15:20:36 -07002879 if (!in_irq())
2880 spin_unlock_irqrestore(&priv->lock, flags);
2881
2882 return err;
2883
Sakari Ailusc659c382011-01-21 10:59:30 +00002884}
Linus Torvalds1da177e2005-04-16 15:20:36 -07002885
2886
2887
2888
Sakari Ailusc659c382011-01-21 10:59:30 +00002889/***************************************************************
2890 * tlan_mii_send_data
2891 *
2892 * Returns:
2893 * Nothing
2894 * Parms:
2895 * base_port The base IO port of the adapter in
2896 * question.
2897 * dev The address of the PHY to be queried.
2898 * data The value to be placed on the MII bus.
2899 * num_bits The number of bits in data that are to
2900 * be placed on the MII bus.
2901 *
2902 * This function sends on sequence of bits on the MII
2903 * configuration bus.
2904 *
2905 **************************************************************/
Linus Torvalds1da177e2005-04-16 15:20:36 -07002906
Sakari Ailusc659c382011-01-21 10:59:30 +00002907static void tlan_mii_send_data(u16 base_port, u32 data, unsigned num_bits)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002908{
2909 u16 sio;
2910 u32 i;
2911
Sakari Ailusc659c382011-01-21 10:59:30 +00002912 if (num_bits == 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002913 return;
2914
Sakari Ailusc659c382011-01-21 10:59:30 +00002915 outw(TLAN_NET_SIO, base_port + TLAN_DIO_ADR);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002916 sio = base_port + TLAN_DIO_DATA + TLAN_NET_SIO;
Sakari Ailusc659c382011-01-21 10:59:30 +00002917 tlan_set_bit(TLAN_NET_SIO_MTXEN, sio);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002918
Sakari Ailusc659c382011-01-21 10:59:30 +00002919 for (i = (0x1 << (num_bits - 1)); i; i >>= 1) {
2920 tlan_clear_bit(TLAN_NET_SIO_MCLK, sio);
2921 (void) tlan_get_bit(TLAN_NET_SIO_MCLK, sio);
2922 if (data & i)
2923 tlan_set_bit(TLAN_NET_SIO_MDATA, sio);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002924 else
Sakari Ailusc659c382011-01-21 10:59:30 +00002925 tlan_clear_bit(TLAN_NET_SIO_MDATA, sio);
2926 tlan_set_bit(TLAN_NET_SIO_MCLK, sio);
2927 (void) tlan_get_bit(TLAN_NET_SIO_MCLK, sio);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002928 }
2929
Sakari Ailusc659c382011-01-21 10:59:30 +00002930}
Linus Torvalds1da177e2005-04-16 15:20:36 -07002931
2932
2933
2934
Sakari Ailusc659c382011-01-21 10:59:30 +00002935/***************************************************************
2936 * TLan_MiiSync
2937 *
2938 * Returns:
2939 * Nothing
2940 * Parms:
2941 * base_port The base IO port of the adapter in
2942 * question.
2943 *
2944 * This functions syncs all PHYs in terms of the MII configuration
2945 * bus.
2946 *
2947 **************************************************************/
Linus Torvalds1da177e2005-04-16 15:20:36 -07002948
Sakari Ailusc659c382011-01-21 10:59:30 +00002949static void tlan_mii_sync(u16 base_port)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002950{
2951 int i;
2952 u16 sio;
2953
Sakari Ailusc659c382011-01-21 10:59:30 +00002954 outw(TLAN_NET_SIO, base_port + TLAN_DIO_ADR);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002955 sio = base_port + TLAN_DIO_DATA + TLAN_NET_SIO;
2956
Sakari Ailusc659c382011-01-21 10:59:30 +00002957 tlan_clear_bit(TLAN_NET_SIO_MTXEN, sio);
2958 for (i = 0; i < 32; i++) {
2959 tlan_clear_bit(TLAN_NET_SIO_MCLK, sio);
2960 tlan_set_bit(TLAN_NET_SIO_MCLK, sio);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002961 }
2962
Sakari Ailusc659c382011-01-21 10:59:30 +00002963}
Linus Torvalds1da177e2005-04-16 15:20:36 -07002964
2965
2966
2967
Sakari Ailusc659c382011-01-21 10:59:30 +00002968/***************************************************************
2969 * tlan_mii_write_reg
2970 *
2971 * Returns:
2972 * Nothing
2973 * Parms:
2974 * dev The device structure for the device
2975 * to write to.
2976 * phy The address of the PHY to be written to.
2977 * reg The register whose contents are to be
2978 * written.
2979 * val The value to be written to the register.
2980 *
2981 * This function uses the TLAN's MII bus to write the contents of a
2982 * given register on a PHY. It sends the appropriate info and then
2983 * writes the 16-bit register value from the MII configuration bus
2984 * via the TLAN SIO register.
2985 *
2986 **************************************************************/
Linus Torvalds1da177e2005-04-16 15:20:36 -07002987
Sakari Ailusc659c382011-01-21 10:59:30 +00002988static void
2989tlan_mii_write_reg(struct net_device *dev, u16 phy, u16 reg, u16 val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002990{
2991 u16 sio;
2992 int minten;
2993 unsigned long flags = 0;
Sakari Ailusc659c382011-01-21 10:59:30 +00002994 struct tlan_priv *priv = netdev_priv(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002995
2996 outw(TLAN_NET_SIO, dev->base_addr + TLAN_DIO_ADR);
2997 sio = dev->base_addr + TLAN_DIO_DATA + TLAN_NET_SIO;
Jeff Garzik6aa20a22006-09-13 13:24:59 -04002998
Linus Torvalds1da177e2005-04-16 15:20:36 -07002999 if (!in_irq())
3000 spin_lock_irqsave(&priv->lock, flags);
3001
Sakari Ailusc659c382011-01-21 10:59:30 +00003002 tlan_mii_sync(dev->base_addr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003003
Sakari Ailusc659c382011-01-21 10:59:30 +00003004 minten = tlan_get_bit(TLAN_NET_SIO_MINTEN, sio);
3005 if (minten)
3006 tlan_clear_bit(TLAN_NET_SIO_MINTEN, sio);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003007
Sakari Ailusc659c382011-01-21 10:59:30 +00003008 tlan_mii_send_data(dev->base_addr, 0x1, 2); /* start (01b) */
3009 tlan_mii_send_data(dev->base_addr, 0x1, 2); /* write (01b) */
3010 tlan_mii_send_data(dev->base_addr, phy, 5); /* device # */
3011 tlan_mii_send_data(dev->base_addr, reg, 5); /* register # */
Linus Torvalds1da177e2005-04-16 15:20:36 -07003012
Sakari Ailusc659c382011-01-21 10:59:30 +00003013 tlan_mii_send_data(dev->base_addr, 0x2, 2); /* send ACK */
3014 tlan_mii_send_data(dev->base_addr, val, 16); /* send data */
Linus Torvalds1da177e2005-04-16 15:20:36 -07003015
Sakari Ailusc659c382011-01-21 10:59:30 +00003016 tlan_clear_bit(TLAN_NET_SIO_MCLK, sio); /* idle cycle */
3017 tlan_set_bit(TLAN_NET_SIO_MCLK, sio);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003018
Sakari Ailusc659c382011-01-21 10:59:30 +00003019 if (minten)
3020 tlan_set_bit(TLAN_NET_SIO_MINTEN, sio);
Jeff Garzik6aa20a22006-09-13 13:24:59 -04003021
Linus Torvalds1da177e2005-04-16 15:20:36 -07003022 if (!in_irq())
3023 spin_unlock_irqrestore(&priv->lock, flags);
3024
Sakari Ailusc659c382011-01-21 10:59:30 +00003025}
Linus Torvalds1da177e2005-04-16 15:20:36 -07003026
3027
3028
3029
3030/*****************************************************************************
3031******************************************************************************
3032
Sakari Ailusc659c382011-01-21 10:59:30 +00003033ThunderLAN driver eeprom routines
Linus Torvalds1da177e2005-04-16 15:20:36 -07003034
Sakari Ailusc659c382011-01-21 10:59:30 +00003035the Compaq netelligent 10 and 10/100 cards use a microchip 24C02A
3036EEPROM. these functions are based on information in microchip's
3037data sheet. I don't know how well this functions will work with
3038other Eeproms.
Linus Torvalds1da177e2005-04-16 15:20:36 -07003039
3040******************************************************************************
3041*****************************************************************************/
3042
3043
Sakari Ailusc659c382011-01-21 10:59:30 +00003044/***************************************************************
3045 * tlan_ee_send_start
3046 *
3047 * Returns:
3048 * Nothing
3049 * Parms:
3050 * io_base The IO port base address for the
3051 * TLAN device with the EEPROM to
3052 * use.
3053 *
3054 * This function sends a start cycle to an EEPROM attached
3055 * to a TLAN chip.
3056 *
3057 **************************************************************/
Linus Torvalds1da177e2005-04-16 15:20:36 -07003058
Sakari Ailusc659c382011-01-21 10:59:30 +00003059static void tlan_ee_send_start(u16 io_base)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003060{
3061 u16 sio;
3062
Sakari Ailusc659c382011-01-21 10:59:30 +00003063 outw(TLAN_NET_SIO, io_base + TLAN_DIO_ADR);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003064 sio = io_base + TLAN_DIO_DATA + TLAN_NET_SIO;
3065
Sakari Ailusc659c382011-01-21 10:59:30 +00003066 tlan_set_bit(TLAN_NET_SIO_ECLOK, sio);
3067 tlan_set_bit(TLAN_NET_SIO_EDATA, sio);
3068 tlan_set_bit(TLAN_NET_SIO_ETXEN, sio);
3069 tlan_clear_bit(TLAN_NET_SIO_EDATA, sio);
3070 tlan_clear_bit(TLAN_NET_SIO_ECLOK, sio);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003071
Sakari Ailusc659c382011-01-21 10:59:30 +00003072}
Linus Torvalds1da177e2005-04-16 15:20:36 -07003073
3074
3075
3076
Sakari Ailusc659c382011-01-21 10:59:30 +00003077/***************************************************************
3078 * tlan_ee_send_byte
3079 *
3080 * Returns:
3081 * If the correct ack was received, 0, otherwise 1
3082 * Parms: io_base The IO port base address for the
3083 * TLAN device with the EEPROM to
3084 * use.
3085 * data The 8 bits of information to
3086 * send to the EEPROM.
3087 * stop If TLAN_EEPROM_STOP is passed, a
3088 * stop cycle is sent after the
3089 * byte is sent after the ack is
3090 * read.
3091 *
3092 * This function sends a byte on the serial EEPROM line,
3093 * driving the clock to send each bit. The function then
3094 * reverses transmission direction and reads an acknowledge
3095 * bit.
3096 *
3097 **************************************************************/
Linus Torvalds1da177e2005-04-16 15:20:36 -07003098
Sakari Ailusc659c382011-01-21 10:59:30 +00003099static int tlan_ee_send_byte(u16 io_base, u8 data, int stop)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003100{
3101 int err;
3102 u8 place;
3103 u16 sio;
3104
Sakari Ailusc659c382011-01-21 10:59:30 +00003105 outw(TLAN_NET_SIO, io_base + TLAN_DIO_ADR);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003106 sio = io_base + TLAN_DIO_DATA + TLAN_NET_SIO;
3107
3108 /* Assume clock is low, tx is enabled; */
Sakari Ailusc659c382011-01-21 10:59:30 +00003109 for (place = 0x80; place != 0; place >>= 1) {
3110 if (place & data)
3111 tlan_set_bit(TLAN_NET_SIO_EDATA, sio);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003112 else
Sakari Ailusc659c382011-01-21 10:59:30 +00003113 tlan_clear_bit(TLAN_NET_SIO_EDATA, sio);
3114 tlan_set_bit(TLAN_NET_SIO_ECLOK, sio);
3115 tlan_clear_bit(TLAN_NET_SIO_ECLOK, sio);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003116 }
Sakari Ailusc659c382011-01-21 10:59:30 +00003117 tlan_clear_bit(TLAN_NET_SIO_ETXEN, sio);
3118 tlan_set_bit(TLAN_NET_SIO_ECLOK, sio);
3119 err = tlan_get_bit(TLAN_NET_SIO_EDATA, sio);
3120 tlan_clear_bit(TLAN_NET_SIO_ECLOK, sio);
3121 tlan_set_bit(TLAN_NET_SIO_ETXEN, sio);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003122
Sakari Ailusc659c382011-01-21 10:59:30 +00003123 if ((!err) && stop) {
Stephen Hemmingerdfc2c0a2008-05-30 09:49:58 -07003124 /* STOP, raise data while clock is high */
Sakari Ailusc659c382011-01-21 10:59:30 +00003125 tlan_clear_bit(TLAN_NET_SIO_EDATA, sio);
3126 tlan_set_bit(TLAN_NET_SIO_ECLOK, sio);
3127 tlan_set_bit(TLAN_NET_SIO_EDATA, sio);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003128 }
3129
Eric Dumazet807540b2010-09-23 05:40:09 +00003130 return err;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003131
Sakari Ailusc659c382011-01-21 10:59:30 +00003132}
Linus Torvalds1da177e2005-04-16 15:20:36 -07003133
3134
3135
3136
Sakari Ailusc659c382011-01-21 10:59:30 +00003137/***************************************************************
3138 * tlan_ee_receive_byte
3139 *
3140 * Returns:
3141 * Nothing
3142 * Parms:
3143 * io_base The IO port base address for the
3144 * TLAN device with the EEPROM to
3145 * use.
3146 * data An address to a char to hold the
3147 * data sent from the EEPROM.
3148 * stop If TLAN_EEPROM_STOP is passed, a
3149 * stop cycle is sent after the
3150 * byte is received, and no ack is
3151 * sent.
3152 *
3153 * This function receives 8 bits of data from the EEPROM
3154 * over the serial link. It then sends and ack bit, or no
3155 * ack and a stop bit. This function is used to retrieve
3156 * data after the address of a byte in the EEPROM has been
3157 * sent.
3158 *
3159 **************************************************************/
Linus Torvalds1da177e2005-04-16 15:20:36 -07003160
Sakari Ailusc659c382011-01-21 10:59:30 +00003161static void tlan_ee_receive_byte(u16 io_base, u8 *data, int stop)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003162{
3163 u8 place;
3164 u16 sio;
3165
Sakari Ailusc659c382011-01-21 10:59:30 +00003166 outw(TLAN_NET_SIO, io_base + TLAN_DIO_ADR);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003167 sio = io_base + TLAN_DIO_DATA + TLAN_NET_SIO;
3168 *data = 0;
3169
3170 /* Assume clock is low, tx is enabled; */
Sakari Ailusc659c382011-01-21 10:59:30 +00003171 tlan_clear_bit(TLAN_NET_SIO_ETXEN, sio);
3172 for (place = 0x80; place; place >>= 1) {
3173 tlan_set_bit(TLAN_NET_SIO_ECLOK, sio);
3174 if (tlan_get_bit(TLAN_NET_SIO_EDATA, sio))
Linus Torvalds1da177e2005-04-16 15:20:36 -07003175 *data |= place;
Sakari Ailusc659c382011-01-21 10:59:30 +00003176 tlan_clear_bit(TLAN_NET_SIO_ECLOK, sio);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003177 }
3178
Sakari Ailusc659c382011-01-21 10:59:30 +00003179 tlan_set_bit(TLAN_NET_SIO_ETXEN, sio);
3180 if (!stop) {
3181 tlan_clear_bit(TLAN_NET_SIO_EDATA, sio); /* ack = 0 */
3182 tlan_set_bit(TLAN_NET_SIO_ECLOK, sio);
3183 tlan_clear_bit(TLAN_NET_SIO_ECLOK, sio);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003184 } else {
Sakari Ailusc659c382011-01-21 10:59:30 +00003185 tlan_set_bit(TLAN_NET_SIO_EDATA, sio); /* no ack = 1 (?) */
3186 tlan_set_bit(TLAN_NET_SIO_ECLOK, sio);
3187 tlan_clear_bit(TLAN_NET_SIO_ECLOK, sio);
Stephen Hemmingerdfc2c0a2008-05-30 09:49:58 -07003188 /* STOP, raise data while clock is high */
Sakari Ailusc659c382011-01-21 10:59:30 +00003189 tlan_clear_bit(TLAN_NET_SIO_EDATA, sio);
3190 tlan_set_bit(TLAN_NET_SIO_ECLOK, sio);
3191 tlan_set_bit(TLAN_NET_SIO_EDATA, sio);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003192 }
3193
Sakari Ailusc659c382011-01-21 10:59:30 +00003194}
Linus Torvalds1da177e2005-04-16 15:20:36 -07003195
3196
3197
3198
Sakari Ailusc659c382011-01-21 10:59:30 +00003199/***************************************************************
3200 * tlan_ee_read_byte
3201 *
3202 * Returns:
3203 * No error = 0, else, the stage at which the error
3204 * occurred.
3205 * Parms:
3206 * io_base The IO port base address for the
3207 * TLAN device with the EEPROM to
3208 * use.
3209 * ee_addr The address of the byte in the
3210 * EEPROM whose contents are to be
3211 * retrieved.
3212 * data An address to a char to hold the
3213 * data obtained from the EEPROM.
3214 *
3215 * This function reads a byte of information from an byte
3216 * cell in the EEPROM.
3217 *
3218 **************************************************************/
Linus Torvalds1da177e2005-04-16 15:20:36 -07003219
Sakari Ailusc659c382011-01-21 10:59:30 +00003220static int tlan_ee_read_byte(struct net_device *dev, u8 ee_addr, u8 *data)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003221{
3222 int err;
Sakari Ailusc659c382011-01-21 10:59:30 +00003223 struct tlan_priv *priv = netdev_priv(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003224 unsigned long flags = 0;
Sakari Ailusc659c382011-01-21 10:59:30 +00003225 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003226
3227 spin_lock_irqsave(&priv->lock, flags);
3228
Sakari Ailusc659c382011-01-21 10:59:30 +00003229 tlan_ee_send_start(dev->base_addr);
3230 err = tlan_ee_send_byte(dev->base_addr, 0xa0, TLAN_EEPROM_ACK);
3231 if (err) {
3232 ret = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003233 goto fail;
3234 }
Sakari Ailusc659c382011-01-21 10:59:30 +00003235 err = tlan_ee_send_byte(dev->base_addr, ee_addr, TLAN_EEPROM_ACK);
3236 if (err) {
3237 ret = 2;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003238 goto fail;
3239 }
Sakari Ailusc659c382011-01-21 10:59:30 +00003240 tlan_ee_send_start(dev->base_addr);
3241 err = tlan_ee_send_byte(dev->base_addr, 0xa1, TLAN_EEPROM_ACK);
3242 if (err) {
3243 ret = 3;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003244 goto fail;
3245 }
Sakari Ailusc659c382011-01-21 10:59:30 +00003246 tlan_ee_receive_byte(dev->base_addr, data, TLAN_EEPROM_STOP);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003247fail:
3248 spin_unlock_irqrestore(&priv->lock, flags);
3249
3250 return ret;
3251
Sakari Ailusc659c382011-01-21 10:59:30 +00003252}
Linus Torvalds1da177e2005-04-16 15:20:36 -07003253
3254
3255