blob: ccde7482d404991a4feb381ba5d167fdc3f71e7f [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*******************************************************************************
2 *
3 * Linux ThunderLAN Driver
4 *
5 * tlan.c
6 * by James Banks
7 *
8 * (C) 1997-1998 Caldera, Inc.
9 * (C) 1998 James Banks
10 * (C) 1999-2001 Torben Mathiasen
11 * (C) 2002 Samuel Chessman
12 *
13 * This software may be used and distributed according to the terms
14 * of the GNU General Public License, incorporated herein by reference.
15 *
Linus Torvalds1da177e2005-04-16 15:20:36 -070016 ** Useful (if not required) reading:
17 *
18 * Texas Instruments, ThunderLAN Programmer's Guide,
19 * TI Literature Number SPWU013A
20 * available in PDF format from www.ti.com
21 * Level One, LXT901 and LXT970 Data Sheets
22 * available in PDF format from www.level1.com
23 * National Semiconductor, DP83840A Data Sheet
24 * available in PDF format from www.national.com
25 * Microchip Technology, 24C01A/02A/04A Data Sheet
26 * available in PDF format from www.microchip.com
27 *
Sakari Ailusc659c382011-01-21 10:59:30 +000028 ******************************************************************************/
Linus Torvalds1da177e2005-04-16 15:20:36 -070029
Joe Perches50624aa2011-03-01 06:56:33 +000030#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
31
Alexey Dobriyana6b7a402011-06-06 10:43:46 +000032#include <linux/hardirq.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070033#include <linux/module.h>
34#include <linux/init.h>
Alexey Dobriyana6b7a402011-06-06 10:43:46 +000035#include <linux/interrupt.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070036#include <linux/ioport.h>
37#include <linux/eisa.h>
38#include <linux/pci.h>
Domen Puncer1e7f0bd2005-06-26 18:22:14 -040039#include <linux/dma-mapping.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070040#include <linux/netdevice.h>
41#include <linux/etherdevice.h>
42#include <linux/delay.h>
43#include <linux/spinlock.h>
44#include <linux/workqueue.h>
45#include <linux/mii.h>
46
47#include "tlan.h"
48
Linus Torvalds1da177e2005-04-16 15:20:36 -070049
50/* For removing EISA devices */
Sakari Ailusc659c382011-01-21 10:59:30 +000051static struct net_device *tlan_eisa_devices;
Linus Torvalds1da177e2005-04-16 15:20:36 -070052
Sakari Ailusc659c382011-01-21 10:59:30 +000053static int tlan_devices_installed;
Linus Torvalds1da177e2005-04-16 15:20:36 -070054
55/* Set speed, duplex and aui settings */
56static int aui[MAX_TLAN_BOARDS];
57static int duplex[MAX_TLAN_BOARDS];
58static int speed[MAX_TLAN_BOARDS];
59static int boards_found;
Stephen Hemminger15efa9b2005-05-04 15:33:11 -070060module_param_array(aui, int, NULL, 0);
61module_param_array(duplex, int, NULL, 0);
62module_param_array(speed, int, NULL, 0);
63MODULE_PARM_DESC(aui, "ThunderLAN use AUI port(s) (0-1)");
Sakari Ailusc659c382011-01-21 10:59:30 +000064MODULE_PARM_DESC(duplex,
65 "ThunderLAN duplex setting(s) (0-default, 1-half, 2-full)");
Joe Perches50624aa2011-03-01 06:56:33 +000066MODULE_PARM_DESC(speed, "ThunderLAN port speed setting(s) (0,10,100)");
Linus Torvalds1da177e2005-04-16 15:20:36 -070067
68MODULE_AUTHOR("Maintainer: Samuel Chessman <chessman@tux.org>");
69MODULE_DESCRIPTION("Driver for TI ThunderLAN based ethernet PCI adapters");
70MODULE_LICENSE("GPL");
71
Linus Torvalds1da177e2005-04-16 15:20:36 -070072/* Turn on debugging. See Documentation/networking/tlan.txt for details */
73static int debug;
Stephen Hemminger15efa9b2005-05-04 15:33:11 -070074module_param(debug, int, 0);
75MODULE_PARM_DESC(debug, "ThunderLAN debug mask");
Linus Torvalds1da177e2005-04-16 15:20:36 -070076
Sakari Ailusc659c382011-01-21 10:59:30 +000077static const char tlan_signature[] = "TLAN";
Sakari Ailusfa6d5d42011-01-21 10:59:31 +000078static const char tlan_banner[] = "ThunderLAN driver v1.17\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -070079static int tlan_have_pci;
80static int tlan_have_eisa;
81
Sakari Ailusc659c382011-01-21 10:59:30 +000082static const char * const media[] = {
83 "10BaseT-HD", "10BaseT-FD", "100baseTx-HD",
84 "100BaseTx-FD", "100BaseT4", NULL
Linus Torvalds1da177e2005-04-16 15:20:36 -070085};
86
87static struct board {
Sakari Ailusc659c382011-01-21 10:59:30 +000088 const char *device_label;
89 u32 flags;
90 u16 addr_ofs;
Linus Torvalds1da177e2005-04-16 15:20:36 -070091} board_info[] = {
92 { "Compaq Netelligent 10 T PCI UTP", TLAN_ADAPTER_ACTIVITY_LED, 0x83 },
Sakari Ailusc659c382011-01-21 10:59:30 +000093 { "Compaq Netelligent 10/100 TX PCI UTP",
94 TLAN_ADAPTER_ACTIVITY_LED, 0x83 },
Linus Torvalds1da177e2005-04-16 15:20:36 -070095 { "Compaq Integrated NetFlex-3/P", TLAN_ADAPTER_NONE, 0x83 },
Stephen Hemmingerdfc2c0a2008-05-30 09:49:58 -070096 { "Compaq NetFlex-3/P",
97 TLAN_ADAPTER_UNMANAGED_PHY | TLAN_ADAPTER_BIT_RATE_PHY, 0x83 },
Linus Torvalds1da177e2005-04-16 15:20:36 -070098 { "Compaq NetFlex-3/P", TLAN_ADAPTER_NONE, 0x83 },
Stephen Hemmingerdfc2c0a2008-05-30 09:49:58 -070099 { "Compaq Netelligent Integrated 10/100 TX UTP",
100 TLAN_ADAPTER_ACTIVITY_LED, 0x83 },
Sakari Ailusc659c382011-01-21 10:59:30 +0000101 { "Compaq Netelligent Dual 10/100 TX PCI UTP",
102 TLAN_ADAPTER_NONE, 0x83 },
103 { "Compaq Netelligent 10/100 TX Embedded UTP",
104 TLAN_ADAPTER_NONE, 0x83 },
Linus Torvalds1da177e2005-04-16 15:20:36 -0700105 { "Olicom OC-2183/2185", TLAN_ADAPTER_USE_INTERN_10, 0x83 },
Ondrej Zaryeb522bb2014-06-30 18:38:27 +0200106 { "Olicom OC-2325", TLAN_ADAPTER_ACTIVITY_LED |
107 TLAN_ADAPTER_UNMANAGED_PHY, 0xf8 },
108 { "Olicom OC-2326", TLAN_ADAPTER_ACTIVITY_LED |
109 TLAN_ADAPTER_USE_INTERN_10, 0xf8 },
Linus Torvalds1da177e2005-04-16 15:20:36 -0700110 { "Compaq Netelligent 10/100 TX UTP", TLAN_ADAPTER_ACTIVITY_LED, 0x83 },
Sakari Ailusc659c382011-01-21 10:59:30 +0000111 { "Compaq Netelligent 10 T/2 PCI UTP/coax", TLAN_ADAPTER_NONE, 0x83 },
Stephen Hemmingerdfc2c0a2008-05-30 09:49:58 -0700112 { "Compaq NetFlex-3/E",
Sakari Ailusc659c382011-01-21 10:59:30 +0000113 TLAN_ADAPTER_ACTIVITY_LED | /* EISA card */
Stephen Hemmingerdfc2c0a2008-05-30 09:49:58 -0700114 TLAN_ADAPTER_UNMANAGED_PHY | TLAN_ADAPTER_BIT_RATE_PHY, 0x83 },
Sakari Ailusc659c382011-01-21 10:59:30 +0000115 { "Compaq NetFlex-3/E",
116 TLAN_ADAPTER_ACTIVITY_LED, 0x83 }, /* EISA card */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700117};
118
Alexey Dobriyana3aa1882010-01-07 11:58:11 +0000119static DEFINE_PCI_DEVICE_TABLE(tlan_pci_tbl) = {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700120 { PCI_VENDOR_ID_COMPAQ, PCI_DEVICE_ID_COMPAQ_NETEL10,
Sakari Ailusc659c382011-01-21 10:59:30 +0000121 PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0 },
Linus Torvalds1da177e2005-04-16 15:20:36 -0700122 { PCI_VENDOR_ID_COMPAQ, PCI_DEVICE_ID_COMPAQ_NETEL100,
Sakari Ailusc659c382011-01-21 10:59:30 +0000123 PCI_ANY_ID, PCI_ANY_ID, 0, 0, 1 },
Linus Torvalds1da177e2005-04-16 15:20:36 -0700124 { PCI_VENDOR_ID_COMPAQ, PCI_DEVICE_ID_COMPAQ_NETFLEX3I,
Sakari Ailusc659c382011-01-21 10:59:30 +0000125 PCI_ANY_ID, PCI_ANY_ID, 0, 0, 2 },
Linus Torvalds1da177e2005-04-16 15:20:36 -0700126 { PCI_VENDOR_ID_COMPAQ, PCI_DEVICE_ID_COMPAQ_THUNDER,
Sakari Ailusc659c382011-01-21 10:59:30 +0000127 PCI_ANY_ID, PCI_ANY_ID, 0, 0, 3 },
Linus Torvalds1da177e2005-04-16 15:20:36 -0700128 { PCI_VENDOR_ID_COMPAQ, PCI_DEVICE_ID_COMPAQ_NETFLEX3B,
Sakari Ailusc659c382011-01-21 10:59:30 +0000129 PCI_ANY_ID, PCI_ANY_ID, 0, 0, 4 },
Linus Torvalds1da177e2005-04-16 15:20:36 -0700130 { PCI_VENDOR_ID_COMPAQ, PCI_DEVICE_ID_COMPAQ_NETEL100PI,
Sakari Ailusc659c382011-01-21 10:59:30 +0000131 PCI_ANY_ID, PCI_ANY_ID, 0, 0, 5 },
Linus Torvalds1da177e2005-04-16 15:20:36 -0700132 { PCI_VENDOR_ID_COMPAQ, PCI_DEVICE_ID_COMPAQ_NETEL100D,
Sakari Ailusc659c382011-01-21 10:59:30 +0000133 PCI_ANY_ID, PCI_ANY_ID, 0, 0, 6 },
Linus Torvalds1da177e2005-04-16 15:20:36 -0700134 { PCI_VENDOR_ID_COMPAQ, PCI_DEVICE_ID_COMPAQ_NETEL100I,
Sakari Ailusc659c382011-01-21 10:59:30 +0000135 PCI_ANY_ID, PCI_ANY_ID, 0, 0, 7 },
Linus Torvalds1da177e2005-04-16 15:20:36 -0700136 { PCI_VENDOR_ID_OLICOM, PCI_DEVICE_ID_OLICOM_OC2183,
Sakari Ailusc659c382011-01-21 10:59:30 +0000137 PCI_ANY_ID, PCI_ANY_ID, 0, 0, 8 },
Linus Torvalds1da177e2005-04-16 15:20:36 -0700138 { PCI_VENDOR_ID_OLICOM, PCI_DEVICE_ID_OLICOM_OC2325,
Sakari Ailusc659c382011-01-21 10:59:30 +0000139 PCI_ANY_ID, PCI_ANY_ID, 0, 0, 9 },
Linus Torvalds1da177e2005-04-16 15:20:36 -0700140 { PCI_VENDOR_ID_OLICOM, PCI_DEVICE_ID_OLICOM_OC2326,
Sakari Ailusc659c382011-01-21 10:59:30 +0000141 PCI_ANY_ID, PCI_ANY_ID, 0, 0, 10 },
Linus Torvalds1da177e2005-04-16 15:20:36 -0700142 { PCI_VENDOR_ID_COMPAQ, PCI_DEVICE_ID_NETELLIGENT_10_100_WS_5100,
Sakari Ailusc659c382011-01-21 10:59:30 +0000143 PCI_ANY_ID, PCI_ANY_ID, 0, 0, 11 },
Linus Torvalds1da177e2005-04-16 15:20:36 -0700144 { PCI_VENDOR_ID_COMPAQ, PCI_DEVICE_ID_NETELLIGENT_10_T2,
Sakari Ailusc659c382011-01-21 10:59:30 +0000145 PCI_ANY_ID, PCI_ANY_ID, 0, 0, 12 },
Linus Torvalds1da177e2005-04-16 15:20:36 -0700146 { 0,}
147};
Jeff Garzik6aa20a22006-09-13 13:24:59 -0400148MODULE_DEVICE_TABLE(pci, tlan_pci_tbl);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700149
Sakari Ailusc659c382011-01-21 10:59:30 +0000150static void tlan_eisa_probe(void);
151static void tlan_eisa_cleanup(void);
152static int tlan_init(struct net_device *);
153static int tlan_open(struct net_device *dev);
154static netdev_tx_t tlan_start_tx(struct sk_buff *, struct net_device *);
155static irqreturn_t tlan_handle_interrupt(int, void *);
156static int tlan_close(struct net_device *);
157static struct net_device_stats *tlan_get_stats(struct net_device *);
158static void tlan_set_multicast_list(struct net_device *);
159static int tlan_ioctl(struct net_device *dev, struct ifreq *rq, int cmd);
160static int tlan_probe1(struct pci_dev *pdev, long ioaddr,
161 int irq, int rev, const struct pci_device_id *ent);
162static void tlan_tx_timeout(struct net_device *dev);
163static void tlan_tx_timeout_work(struct work_struct *work);
164static int tlan_init_one(struct pci_dev *pdev,
165 const struct pci_device_id *ent);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700166
Sakari Ailusc659c382011-01-21 10:59:30 +0000167static u32 tlan_handle_tx_eof(struct net_device *, u16);
168static u32 tlan_handle_stat_overflow(struct net_device *, u16);
169static u32 tlan_handle_rx_eof(struct net_device *, u16);
170static u32 tlan_handle_dummy(struct net_device *, u16);
171static u32 tlan_handle_tx_eoc(struct net_device *, u16);
172static u32 tlan_handle_status_check(struct net_device *, u16);
173static u32 tlan_handle_rx_eoc(struct net_device *, u16);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700174
Sakari Ailusc659c382011-01-21 10:59:30 +0000175static void tlan_timer(unsigned long);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700176
Sakari Ailusc659c382011-01-21 10:59:30 +0000177static void tlan_reset_lists(struct net_device *);
178static void tlan_free_lists(struct net_device *);
179static void tlan_print_dio(u16);
180static void tlan_print_list(struct tlan_list *, char *, int);
181static void tlan_read_and_clear_stats(struct net_device *, int);
182static void tlan_reset_adapter(struct net_device *);
183static void tlan_finish_reset(struct net_device *);
184static void tlan_set_mac(struct net_device *, int areg, char *mac);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700185
Sakari Ailusc659c382011-01-21 10:59:30 +0000186static void tlan_phy_print(struct net_device *);
187static void tlan_phy_detect(struct net_device *);
188static void tlan_phy_power_down(struct net_device *);
189static void tlan_phy_power_up(struct net_device *);
190static void tlan_phy_reset(struct net_device *);
191static void tlan_phy_start_link(struct net_device *);
192static void tlan_phy_finish_auto_neg(struct net_device *);
Ondrej Zaryc0a87c22014-06-30 18:38:28 +0200193static void tlan_phy_monitor(unsigned long);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700194
195/*
Sakari Ailusc659c382011-01-21 10:59:30 +0000196 static int tlan_phy_nop(struct net_device *);
197 static int tlan_phy_internal_check(struct net_device *);
198 static int tlan_phy_internal_service(struct net_device *);
199 static int tlan_phy_dp83840a_check(struct net_device *);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700200*/
201
Sakari Ailusc659c382011-01-21 10:59:30 +0000202static bool tlan_mii_read_reg(struct net_device *, u16, u16, u16 *);
203static void tlan_mii_send_data(u16, u32, unsigned);
204static void tlan_mii_sync(u16);
205static void tlan_mii_write_reg(struct net_device *, u16, u16, u16);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700206
Sakari Ailusc659c382011-01-21 10:59:30 +0000207static void tlan_ee_send_start(u16);
208static int tlan_ee_send_byte(u16, u8, int);
209static void tlan_ee_receive_byte(u16, u8 *, int);
210static int tlan_ee_read_byte(struct net_device *, u8, u8 *);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700211
212
Stephen Hemminger93e16842008-05-30 09:49:55 -0700213static inline void
Sakari Ailusc659c382011-01-21 10:59:30 +0000214tlan_store_skb(struct tlan_list *tag, struct sk_buff *skb)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700215{
216 unsigned long addr = (unsigned long)skb;
Stephen Hemminger93e16842008-05-30 09:49:55 -0700217 tag->buffer[9].address = addr;
218 tag->buffer[8].address = upper_32_bits(addr);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700219}
220
Stephen Hemminger93e16842008-05-30 09:49:55 -0700221static inline struct sk_buff *
Sakari Ailusc659c382011-01-21 10:59:30 +0000222tlan_get_skb(const struct tlan_list *tag)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700223{
Stephen Hemminger93e16842008-05-30 09:49:55 -0700224 unsigned long addr;
225
Robert Fitzsimons0d63bea2008-08-09 17:54:02 +0100226 addr = tag->buffer[9].address;
Benjamin Poirierda3a9e92012-04-25 04:49:20 +0000227 addr |= ((unsigned long) tag->buffer[8].address << 16) << 16;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700228 return (struct sk_buff *) addr;
229}
230
Sakari Ailusc659c382011-01-21 10:59:30 +0000231static u32
232(*tlan_int_vector[TLAN_INT_NUMBER_OF_INTS])(struct net_device *, u16) = {
Stephen Hemmingera3ccc782008-05-30 09:49:57 -0700233 NULL,
Sakari Ailusc659c382011-01-21 10:59:30 +0000234 tlan_handle_tx_eof,
235 tlan_handle_stat_overflow,
236 tlan_handle_rx_eof,
237 tlan_handle_dummy,
238 tlan_handle_tx_eoc,
239 tlan_handle_status_check,
240 tlan_handle_rx_eoc
Linus Torvalds1da177e2005-04-16 15:20:36 -0700241};
242
243static inline void
Sakari Ailusc659c382011-01-21 10:59:30 +0000244tlan_set_timer(struct net_device *dev, u32 ticks, u32 type)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700245{
Sakari Ailusc659c382011-01-21 10:59:30 +0000246 struct tlan_priv *priv = netdev_priv(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700247 unsigned long flags = 0;
Jeff Garzik6aa20a22006-09-13 13:24:59 -0400248
Linus Torvalds1da177e2005-04-16 15:20:36 -0700249 if (!in_irq())
250 spin_lock_irqsave(&priv->lock, flags);
Sakari Ailusc659c382011-01-21 10:59:30 +0000251 if (priv->timer.function != NULL &&
252 priv->timer_type != TLAN_TIMER_ACTIVITY) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700253 if (!in_irq())
254 spin_unlock_irqrestore(&priv->lock, flags);
255 return;
256 }
Sakari Ailusc659c382011-01-21 10:59:30 +0000257 priv->timer.function = tlan_timer;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700258 if (!in_irq())
259 spin_unlock_irqrestore(&priv->lock, flags);
260
261 priv->timer.data = (unsigned long) dev;
Sakari Ailusc659c382011-01-21 10:59:30 +0000262 priv->timer_set_at = jiffies;
263 priv->timer_type = type;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700264 mod_timer(&priv->timer, jiffies + ticks);
Jeff Garzik6aa20a22006-09-13 13:24:59 -0400265
Sakari Ailusc659c382011-01-21 10:59:30 +0000266}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700267
268
269/*****************************************************************************
270******************************************************************************
271
Sakari Ailusc659c382011-01-21 10:59:30 +0000272ThunderLAN driver primary functions
Linus Torvalds1da177e2005-04-16 15:20:36 -0700273
Sakari Ailusc659c382011-01-21 10:59:30 +0000274these functions are more or less common to all linux network drivers.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700275
276******************************************************************************
277*****************************************************************************/
278
279
280
281
282
Sakari Ailusc659c382011-01-21 10:59:30 +0000283/***************************************************************
284 * tlan_remove_one
285 *
286 * Returns:
287 * Nothing
288 * Parms:
289 * None
290 *
291 * Goes through the TLanDevices list and frees the device
292 * structs and memory associated with each device (lists
293 * and buffers). It also ureserves the IO port regions
294 * associated with this device.
295 *
296 **************************************************************/
Linus Torvalds1da177e2005-04-16 15:20:36 -0700297
298
Bill Pemberton36915872012-12-03 09:23:44 -0500299static void tlan_remove_one(struct pci_dev *pdev)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700300{
Sakari Ailusc659c382011-01-21 10:59:30 +0000301 struct net_device *dev = pci_get_drvdata(pdev);
302 struct tlan_priv *priv = netdev_priv(dev);
Jeff Garzik6aa20a22006-09-13 13:24:59 -0400303
Sakari Ailusc659c382011-01-21 10:59:30 +0000304 unregister_netdev(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700305
Sakari Ailusc659c382011-01-21 10:59:30 +0000306 if (priv->dma_storage) {
307 pci_free_consistent(priv->pci_dev,
308 priv->dma_size, priv->dma_storage,
309 priv->dma_storage_dma);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700310 }
311
312#ifdef CONFIG_PCI
313 pci_release_regions(pdev);
314#endif
Jeff Garzik6aa20a22006-09-13 13:24:59 -0400315
Sakari Ailusc659c382011-01-21 10:59:30 +0000316 free_netdev(dev);
Jeff Garzik6aa20a22006-09-13 13:24:59 -0400317
Devendra Naga1e0a8b12013-04-16 01:30:38 +0000318 cancel_work_sync(&priv->tlan_tqueue);
Jeff Garzik6aa20a22006-09-13 13:24:59 -0400319}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700320
Sakari Ailusfa6d5d42011-01-21 10:59:31 +0000321static void tlan_start(struct net_device *dev)
322{
323 tlan_reset_lists(dev);
324 /* NOTE: It might not be necessary to read the stats before a
325 reset if you don't care what the values are.
326 */
327 tlan_read_and_clear_stats(dev, TLAN_IGNORE);
328 tlan_reset_adapter(dev);
329 netif_wake_queue(dev);
330}
331
332static void tlan_stop(struct net_device *dev)
333{
334 struct tlan_priv *priv = netdev_priv(dev);
335
Ondrej Zaryc0a87c22014-06-30 18:38:28 +0200336 del_timer_sync(&priv->media_timer);
Sakari Ailusfa6d5d42011-01-21 10:59:31 +0000337 tlan_read_and_clear_stats(dev, TLAN_RECORD);
338 outl(TLAN_HC_AD_RST, dev->base_addr + TLAN_HOST_CMD);
339 /* Reset and power down phy */
340 tlan_reset_adapter(dev);
341 if (priv->timer.function != NULL) {
342 del_timer_sync(&priv->timer);
343 priv->timer.function = NULL;
344 }
345}
346
347#ifdef CONFIG_PM
348
349static int tlan_suspend(struct pci_dev *pdev, pm_message_t state)
350{
351 struct net_device *dev = pci_get_drvdata(pdev);
352
353 if (netif_running(dev))
354 tlan_stop(dev);
355
356 netif_device_detach(dev);
357 pci_save_state(pdev);
358 pci_disable_device(pdev);
359 pci_wake_from_d3(pdev, false);
360 pci_set_power_state(pdev, PCI_D3hot);
361
362 return 0;
363}
364
365static int tlan_resume(struct pci_dev *pdev)
366{
367 struct net_device *dev = pci_get_drvdata(pdev);
368
369 pci_set_power_state(pdev, PCI_D0);
370 pci_restore_state(pdev);
Yijing Wang1ca01512013-06-27 20:53:42 +0800371 pci_enable_wake(pdev, PCI_D0, 0);
Sakari Ailusfa6d5d42011-01-21 10:59:31 +0000372 netif_device_attach(dev);
373
374 if (netif_running(dev))
375 tlan_start(dev);
376
377 return 0;
378}
379
380#else /* CONFIG_PM */
381
382#define tlan_suspend NULL
383#define tlan_resume NULL
384
385#endif /* CONFIG_PM */
386
387
Linus Torvalds1da177e2005-04-16 15:20:36 -0700388static struct pci_driver tlan_driver = {
389 .name = "tlan",
390 .id_table = tlan_pci_tbl,
391 .probe = tlan_init_one,
Bill Pemberton36915872012-12-03 09:23:44 -0500392 .remove = tlan_remove_one,
Sakari Ailusfa6d5d42011-01-21 10:59:31 +0000393 .suspend = tlan_suspend,
394 .resume = tlan_resume,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700395};
396
397static int __init tlan_probe(void)
398{
Leonardo Potenza6c04a512008-02-04 23:47:16 -0800399 int rc = -ENODEV;
Jeff Garzik6aa20a22006-09-13 13:24:59 -0400400
Joe Perches50624aa2011-03-01 06:56:33 +0000401 pr_info("%s", tlan_banner);
Jeff Garzik6aa20a22006-09-13 13:24:59 -0400402
Linus Torvalds1da177e2005-04-16 15:20:36 -0700403 TLAN_DBG(TLAN_DEBUG_PROBE, "Starting PCI Probe....\n");
Jeff Garzik6aa20a22006-09-13 13:24:59 -0400404
Linus Torvalds1da177e2005-04-16 15:20:36 -0700405 /* Use new style PCI probing. Now the kernel will
406 do most of this for us */
Leonardo Potenza6c04a512008-02-04 23:47:16 -0800407 rc = pci_register_driver(&tlan_driver);
408
409 if (rc != 0) {
Joe Perches50624aa2011-03-01 06:56:33 +0000410 pr_err("Could not register pci driver\n");
Leonardo Potenza6c04a512008-02-04 23:47:16 -0800411 goto err_out_pci_free;
412 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700413
414 TLAN_DBG(TLAN_DEBUG_PROBE, "Starting EISA Probe....\n");
Sakari Ailusc659c382011-01-21 10:59:30 +0000415 tlan_eisa_probe();
Jeff Garzik6aa20a22006-09-13 13:24:59 -0400416
Joe Perches50624aa2011-03-01 06:56:33 +0000417 pr_info("%d device%s installed, PCI: %d EISA: %d\n",
418 tlan_devices_installed, tlan_devices_installed == 1 ? "" : "s",
419 tlan_have_pci, tlan_have_eisa);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700420
Sakari Ailusc659c382011-01-21 10:59:30 +0000421 if (tlan_devices_installed == 0) {
Leonardo Potenza6c04a512008-02-04 23:47:16 -0800422 rc = -ENODEV;
423 goto err_out_pci_unreg;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700424 }
425 return 0;
Leonardo Potenza6c04a512008-02-04 23:47:16 -0800426
427err_out_pci_unreg:
428 pci_unregister_driver(&tlan_driver);
429err_out_pci_free:
Leonardo Potenza6c04a512008-02-04 23:47:16 -0800430 return rc;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700431}
Jeff Garzik6aa20a22006-09-13 13:24:59 -0400432
Linus Torvalds1da177e2005-04-16 15:20:36 -0700433
Bill Pemberton36915872012-12-03 09:23:44 -0500434static int tlan_init_one(struct pci_dev *pdev,
Sakari Ailusc659c382011-01-21 10:59:30 +0000435 const struct pci_device_id *ent)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700436{
Sakari Ailusc659c382011-01-21 10:59:30 +0000437 return tlan_probe1(pdev, -1, -1, 0, ent);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700438}
439
440
441/*
Sakari Ailusc659c382011-01-21 10:59:30 +0000442***************************************************************
443* tlan_probe1
444*
445* Returns:
446* 0 on success, error code on error
447* Parms:
448* none
449*
450* The name is lower case to fit in with all the rest of
451* the netcard_probe names. This function looks for
452* another TLan based adapter, setting it up with the
453* allocated device struct if one is found.
454* tlan_probe has been ported to the new net API and
455* now allocates its own device structure. This function
456* is also used by modules.
457*
458**************************************************************/
Linus Torvalds1da177e2005-04-16 15:20:36 -0700459
Greg Kroah-Hartman1dd06ae2012-12-06 14:30:56 +0000460static int tlan_probe1(struct pci_dev *pdev, long ioaddr, int irq, int rev,
461 const struct pci_device_id *ent)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700462{
463
464 struct net_device *dev;
Sakari Ailusc659c382011-01-21 10:59:30 +0000465 struct tlan_priv *priv;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700466 u16 device_id;
467 int reg, rc = -ENODEV;
468
Adrian Bunkad9f6712006-02-05 00:37:47 +0100469#ifdef CONFIG_PCI
Linus Torvalds1da177e2005-04-16 15:20:36 -0700470 if (pdev) {
471 rc = pci_enable_device(pdev);
472 if (rc)
473 return rc;
474
Sakari Ailusc659c382011-01-21 10:59:30 +0000475 rc = pci_request_regions(pdev, tlan_signature);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700476 if (rc) {
Joe Perches50624aa2011-03-01 06:56:33 +0000477 pr_err("Could not reserve IO regions\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700478 goto err_out;
479 }
480 }
Adrian Bunkad9f6712006-02-05 00:37:47 +0100481#endif /* CONFIG_PCI */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700482
Sakari Ailusc659c382011-01-21 10:59:30 +0000483 dev = alloc_etherdev(sizeof(struct tlan_priv));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700484 if (dev == NULL) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700485 rc = -ENOMEM;
486 goto err_out_regions;
487 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700488 SET_NETDEV_DEV(dev, &pdev->dev);
Jeff Garzik6aa20a22006-09-13 13:24:59 -0400489
Linus Torvalds1da177e2005-04-16 15:20:36 -0700490 priv = netdev_priv(dev);
491
Sakari Ailusc659c382011-01-21 10:59:30 +0000492 priv->pci_dev = pdev;
David Howellsc4028952006-11-22 14:57:56 +0000493 priv->dev = dev;
Jeff Garzik6aa20a22006-09-13 13:24:59 -0400494
Linus Torvalds1da177e2005-04-16 15:20:36 -0700495 /* Is this a PCI device? */
496 if (pdev) {
Sakari Ailusc659c382011-01-21 10:59:30 +0000497 u32 pci_io_base = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700498
499 priv->adapter = &board_info[ent->driver_data];
500
Yang Hongyang284901a2009-04-06 19:01:15 -0700501 rc = pci_set_dma_mask(pdev, DMA_BIT_MASK(32));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700502 if (rc) {
Joe Perches50624aa2011-03-01 06:56:33 +0000503 pr_err("No suitable PCI mapping available\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700504 goto err_out_free_dev;
505 }
506
Sakari Ailusc659c382011-01-21 10:59:30 +0000507 for (reg = 0; reg <= 5; reg++) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700508 if (pci_resource_flags(pdev, reg) & IORESOURCE_IO) {
509 pci_io_base = pci_resource_start(pdev, reg);
Sakari Ailusc659c382011-01-21 10:59:30 +0000510 TLAN_DBG(TLAN_DEBUG_GNRL,
511 "IO mapping is available at %x.\n",
512 pci_io_base);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700513 break;
514 }
515 }
516 if (!pci_io_base) {
Joe Perches50624aa2011-03-01 06:56:33 +0000517 pr_err("No IO mappings available\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700518 rc = -EIO;
519 goto err_out_free_dev;
520 }
Jeff Garzik6aa20a22006-09-13 13:24:59 -0400521
Linus Torvalds1da177e2005-04-16 15:20:36 -0700522 dev->base_addr = pci_io_base;
523 dev->irq = pdev->irq;
Sakari Ailusc659c382011-01-21 10:59:30 +0000524 priv->adapter_rev = pdev->revision;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700525 pci_set_master(pdev);
526 pci_set_drvdata(pdev, dev);
527
528 } else { /* EISA card */
529 /* This is a hack. We need to know which board structure
530 * is suited for this adapter */
531 device_id = inw(ioaddr + EISA_ID2);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700532 if (device_id == 0x20F1) {
Sakari Ailusc659c382011-01-21 10:59:30 +0000533 priv->adapter = &board_info[13]; /* NetFlex-3/E */
534 priv->adapter_rev = 23; /* TLAN 2.3 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700535 } else {
536 priv->adapter = &board_info[14];
Sakari Ailusc659c382011-01-21 10:59:30 +0000537 priv->adapter_rev = 10; /* TLAN 1.0 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700538 }
539 dev->base_addr = ioaddr;
540 dev->irq = irq;
541 }
542
543 /* Kernel parameters */
544 if (dev->mem_start) {
545 priv->aui = dev->mem_start & 0x01;
Stephen Hemmingerdfc2c0a2008-05-30 09:49:58 -0700546 priv->duplex = ((dev->mem_start & 0x06) == 0x06) ? 0
547 : (dev->mem_start & 0x06) >> 1;
548 priv->speed = ((dev->mem_start & 0x18) == 0x18) ? 0
549 : (dev->mem_start & 0x18) >> 3;
Jeff Garzik6aa20a22006-09-13 13:24:59 -0400550
Sakari Ailusc659c382011-01-21 10:59:30 +0000551 if (priv->speed == 0x1)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700552 priv->speed = TLAN_SPEED_10;
Sakari Ailusc659c382011-01-21 10:59:30 +0000553 else if (priv->speed == 0x2)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700554 priv->speed = TLAN_SPEED_100;
Sakari Ailusc659c382011-01-21 10:59:30 +0000555
Linus Torvalds1da177e2005-04-16 15:20:36 -0700556 debug = priv->debug = dev->mem_end;
557 } else {
558 priv->aui = aui[boards_found];
559 priv->speed = speed[boards_found];
560 priv->duplex = duplex[boards_found];
561 priv->debug = debug;
562 }
Jeff Garzik6aa20a22006-09-13 13:24:59 -0400563
Linus Torvalds1da177e2005-04-16 15:20:36 -0700564 /* This will be used when we get an adapter error from
565 * within our irq handler */
Sakari Ailusc659c382011-01-21 10:59:30 +0000566 INIT_WORK(&priv->tlan_tqueue, tlan_tx_timeout_work);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700567
568 spin_lock_init(&priv->lock);
Jeff Garzik6aa20a22006-09-13 13:24:59 -0400569
Sakari Ailusc659c382011-01-21 10:59:30 +0000570 rc = tlan_init(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700571 if (rc) {
Joe Perches50624aa2011-03-01 06:56:33 +0000572 pr_err("Could not set up device\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700573 goto err_out_free_dev;
574 }
575
576 rc = register_netdev(dev);
577 if (rc) {
Joe Perches50624aa2011-03-01 06:56:33 +0000578 pr_err("Could not register device\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700579 goto err_out_uninit;
580 }
581
Jeff Garzik6aa20a22006-09-13 13:24:59 -0400582
Sakari Ailusc659c382011-01-21 10:59:30 +0000583 tlan_devices_installed++;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700584 boards_found++;
Jeff Garzik6aa20a22006-09-13 13:24:59 -0400585
Linus Torvalds1da177e2005-04-16 15:20:36 -0700586 /* pdev is NULL if this is an EISA device */
587 if (pdev)
588 tlan_have_pci++;
589 else {
Sakari Ailusc659c382011-01-21 10:59:30 +0000590 priv->next_device = tlan_eisa_devices;
591 tlan_eisa_devices = dev;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700592 tlan_have_eisa++;
593 }
Jeff Garzik6aa20a22006-09-13 13:24:59 -0400594
Joe Perches50624aa2011-03-01 06:56:33 +0000595 netdev_info(dev, "irq=%2d, io=%04x, %s, Rev. %d\n",
596 (int)dev->irq,
597 (int)dev->base_addr,
598 priv->adapter->device_label,
599 priv->adapter_rev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700600 return 0;
601
602err_out_uninit:
Sakari Ailusc659c382011-01-21 10:59:30 +0000603 pci_free_consistent(priv->pci_dev, priv->dma_size, priv->dma_storage,
604 priv->dma_storage_dma);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700605err_out_free_dev:
606 free_netdev(dev);
607err_out_regions:
608#ifdef CONFIG_PCI
609 if (pdev)
610 pci_release_regions(pdev);
611#endif
612err_out:
613 if (pdev)
614 pci_disable_device(pdev);
615 return rc;
616}
617
618
Sakari Ailusc659c382011-01-21 10:59:30 +0000619static void tlan_eisa_cleanup(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700620{
621 struct net_device *dev;
Sakari Ailusc659c382011-01-21 10:59:30 +0000622 struct tlan_priv *priv;
Jeff Garzik6aa20a22006-09-13 13:24:59 -0400623
Sakari Ailusc659c382011-01-21 10:59:30 +0000624 while (tlan_have_eisa) {
625 dev = tlan_eisa_devices;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700626 priv = netdev_priv(dev);
Sakari Ailusc659c382011-01-21 10:59:30 +0000627 if (priv->dma_storage) {
628 pci_free_consistent(priv->pci_dev, priv->dma_size,
629 priv->dma_storage,
630 priv->dma_storage_dma);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700631 }
Sakari Ailusc659c382011-01-21 10:59:30 +0000632 release_region(dev->base_addr, 0x10);
633 unregister_netdev(dev);
634 tlan_eisa_devices = priv->next_device;
635 free_netdev(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700636 tlan_have_eisa--;
637 }
638}
Jeff Garzik6aa20a22006-09-13 13:24:59 -0400639
640
Linus Torvalds1da177e2005-04-16 15:20:36 -0700641static void __exit tlan_exit(void)
642{
643 pci_unregister_driver(&tlan_driver);
644
645 if (tlan_have_eisa)
Sakari Ailusc659c382011-01-21 10:59:30 +0000646 tlan_eisa_cleanup();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700647
Linus Torvalds1da177e2005-04-16 15:20:36 -0700648}
649
650
651/* Module loading/unloading */
652module_init(tlan_probe);
653module_exit(tlan_exit);
654
655
656
Sakari Ailusc659c382011-01-21 10:59:30 +0000657/**************************************************************
658 * tlan_eisa_probe
659 *
660 * Returns: 0 on success, 1 otherwise
661 *
662 * Parms: None
663 *
664 *
665 * This functions probes for EISA devices and calls
666 * TLan_probe1 when one is found.
667 *
668 *************************************************************/
Linus Torvalds1da177e2005-04-16 15:20:36 -0700669
Sakari Ailusc659c382011-01-21 10:59:30 +0000670static void __init tlan_eisa_probe(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700671{
Sakari Ailusc659c382011-01-21 10:59:30 +0000672 long ioaddr;
673 int rc = -ENODEV;
674 int irq;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700675 u16 device_id;
676
Jeff Garzik6aa20a22006-09-13 13:24:59 -0400677 if (!EISA_bus) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700678 TLAN_DBG(TLAN_DEBUG_PROBE, "No EISA bus present\n");
679 return;
680 }
Jeff Garzik6aa20a22006-09-13 13:24:59 -0400681
Linus Torvalds1da177e2005-04-16 15:20:36 -0700682 /* Loop through all slots of the EISA bus */
683 for (ioaddr = 0x1000; ioaddr < 0x9000; ioaddr += 0x1000) {
Jeff Garzik6aa20a22006-09-13 13:24:59 -0400684
Sakari Ailusc659c382011-01-21 10:59:30 +0000685 TLAN_DBG(TLAN_DEBUG_PROBE, "EISA_ID 0x%4x: 0x%4x\n",
686 (int) ioaddr + 0xc80, inw(ioaddr + EISA_ID));
687 TLAN_DBG(TLAN_DEBUG_PROBE, "EISA_ID 0x%4x: 0x%4x\n",
688 (int) ioaddr + 0xc82, inw(ioaddr + EISA_ID2));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700689
690
Sakari Ailusc659c382011-01-21 10:59:30 +0000691 TLAN_DBG(TLAN_DEBUG_PROBE,
692 "Probing for EISA adapter at IO: 0x%4x : ",
693 (int) ioaddr);
694 if (request_region(ioaddr, 0x10, tlan_signature) == NULL)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700695 goto out;
696
Jeff Garzik6aa20a22006-09-13 13:24:59 -0400697 if (inw(ioaddr + EISA_ID) != 0x110E) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700698 release_region(ioaddr, 0x10);
699 goto out;
700 }
Jeff Garzik6aa20a22006-09-13 13:24:59 -0400701
Linus Torvalds1da177e2005-04-16 15:20:36 -0700702 device_id = inw(ioaddr + EISA_ID2);
Jeff Garzik6aa20a22006-09-13 13:24:59 -0400703 if (device_id != 0x20F1 && device_id != 0x40F1) {
Sakari Ailusc659c382011-01-21 10:59:30 +0000704 release_region(ioaddr, 0x10);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700705 goto out;
706 }
Jeff Garzik6aa20a22006-09-13 13:24:59 -0400707
Sakari Ailusc659c382011-01-21 10:59:30 +0000708 /* check if adapter is enabled */
709 if (inb(ioaddr + EISA_CR) != 0x1) {
710 release_region(ioaddr, 0x10);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700711 goto out2;
712 }
Jeff Garzik6aa20a22006-09-13 13:24:59 -0400713
714 if (debug == 0x10)
Joe Perches50624aa2011-03-01 06:56:33 +0000715 pr_info("Found one\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700716
717
718 /* Get irq from board */
Sakari Ailusc659c382011-01-21 10:59:30 +0000719 switch (inb(ioaddr + 0xcc0)) {
720 case(0x10):
721 irq = 5;
722 break;
723 case(0x20):
724 irq = 9;
725 break;
726 case(0x40):
727 irq = 10;
728 break;
729 case(0x80):
730 irq = 11;
731 break;
732 default:
733 goto out;
Jeff Garzik6aa20a22006-09-13 13:24:59 -0400734 }
735
736
Linus Torvalds1da177e2005-04-16 15:20:36 -0700737 /* Setup the newly found eisa adapter */
Sakari Ailusc659c382011-01-21 10:59:30 +0000738 rc = tlan_probe1(NULL, ioaddr, irq,
739 12, NULL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700740 continue;
Jeff Garzik6aa20a22006-09-13 13:24:59 -0400741
Sakari Ailusc659c382011-01-21 10:59:30 +0000742out:
743 if (debug == 0x10)
Joe Perches50624aa2011-03-01 06:56:33 +0000744 pr_info("None found\n");
Sakari Ailusc659c382011-01-21 10:59:30 +0000745 continue;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700746
Sakari Ailusc659c382011-01-21 10:59:30 +0000747out2:
748 if (debug == 0x10)
Joe Perches50624aa2011-03-01 06:56:33 +0000749 pr_info("Card found but it is not enabled, skipping\n");
Sakari Ailusc659c382011-01-21 10:59:30 +0000750 continue;
Jeff Garzik6aa20a22006-09-13 13:24:59 -0400751
Linus Torvalds1da177e2005-04-16 15:20:36 -0700752 }
753
Sakari Ailusc659c382011-01-21 10:59:30 +0000754}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700755
756#ifdef CONFIG_NET_POLL_CONTROLLER
Sakari Ailusc659c382011-01-21 10:59:30 +0000757static void tlan_poll(struct net_device *dev)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700758{
759 disable_irq(dev->irq);
Sakari Ailusc659c382011-01-21 10:59:30 +0000760 tlan_handle_interrupt(dev->irq, dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700761 enable_irq(dev->irq);
762}
763#endif
764
Sakari Ailusc659c382011-01-21 10:59:30 +0000765static const struct net_device_ops tlan_netdev_ops = {
766 .ndo_open = tlan_open,
767 .ndo_stop = tlan_close,
768 .ndo_start_xmit = tlan_start_tx,
769 .ndo_tx_timeout = tlan_tx_timeout,
770 .ndo_get_stats = tlan_get_stats,
Jiri Pirkoafc4b132011-08-16 06:29:01 +0000771 .ndo_set_rx_mode = tlan_set_multicast_list,
Sakari Ailusc659c382011-01-21 10:59:30 +0000772 .ndo_do_ioctl = tlan_ioctl,
Stephen Hemminger391c5e62009-01-07 17:27:15 -0800773 .ndo_change_mtu = eth_change_mtu,
Sakari Ailusc659c382011-01-21 10:59:30 +0000774 .ndo_set_mac_address = eth_mac_addr,
Stephen Hemminger391c5e62009-01-07 17:27:15 -0800775 .ndo_validate_addr = eth_validate_addr,
776#ifdef CONFIG_NET_POLL_CONTROLLER
Sakari Ailusc659c382011-01-21 10:59:30 +0000777 .ndo_poll_controller = tlan_poll,
Stephen Hemminger391c5e62009-01-07 17:27:15 -0800778#endif
779};
Jeff Garzik6aa20a22006-09-13 13:24:59 -0400780
Linus Torvalds1da177e2005-04-16 15:20:36 -0700781
782
Sakari Ailusc659c382011-01-21 10:59:30 +0000783/***************************************************************
784 * tlan_init
785 *
786 * Returns:
787 * 0 on success, error code otherwise.
788 * Parms:
789 * dev The structure of the device to be
790 * init'ed.
791 *
792 * This function completes the initialization of the
793 * device structure and driver. It reserves the IO
794 * addresses, allocates memory for the lists and bounce
795 * buffers, retrieves the MAC address from the eeprom
796 * and assignes the device's methods.
797 *
798 **************************************************************/
Linus Torvalds1da177e2005-04-16 15:20:36 -0700799
Sakari Ailusc659c382011-01-21 10:59:30 +0000800static int tlan_init(struct net_device *dev)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700801{
802 int dma_size;
Sakari Ailusc659c382011-01-21 10:59:30 +0000803 int err;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700804 int i;
Sakari Ailusc659c382011-01-21 10:59:30 +0000805 struct tlan_priv *priv;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700806
807 priv = netdev_priv(dev);
Jeff Garzik6aa20a22006-09-13 13:24:59 -0400808
Sakari Ailusc659c382011-01-21 10:59:30 +0000809 dma_size = (TLAN_NUM_RX_LISTS + TLAN_NUM_TX_LISTS)
810 * (sizeof(struct tlan_list));
811 priv->dma_storage = pci_alloc_consistent(priv->pci_dev,
812 dma_size,
813 &priv->dma_storage_dma);
814 priv->dma_size = dma_size;
Jeff Garzik6aa20a22006-09-13 13:24:59 -0400815
Sakari Ailusc659c382011-01-21 10:59:30 +0000816 if (priv->dma_storage == NULL) {
Joe Perches50624aa2011-03-01 06:56:33 +0000817 pr_err("Could not allocate lists and buffers for %s\n",
Sakari Ailusc659c382011-01-21 10:59:30 +0000818 dev->name);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700819 return -ENOMEM;
820 }
Sakari Ailusc659c382011-01-21 10:59:30 +0000821 memset(priv->dma_storage, 0, dma_size);
822 priv->rx_list = (struct tlan_list *)
823 ALIGN((unsigned long)priv->dma_storage, 8);
824 priv->rx_list_dma = ALIGN(priv->dma_storage_dma, 8);
825 priv->tx_list = priv->rx_list + TLAN_NUM_RX_LISTS;
826 priv->tx_list_dma =
827 priv->rx_list_dma + sizeof(struct tlan_list)*TLAN_NUM_RX_LISTS;
Stephen Hemminger93e16842008-05-30 09:49:55 -0700828
Linus Torvalds1da177e2005-04-16 15:20:36 -0700829 err = 0;
Sakari Ailusc659c382011-01-21 10:59:30 +0000830 for (i = 0; i < 6 ; i++)
831 err |= tlan_ee_read_byte(dev,
832 (u8) priv->adapter->addr_ofs + i,
833 (u8 *) &dev->dev_addr[i]);
834 if (err) {
Joe Perches50624aa2011-03-01 06:56:33 +0000835 pr_err("%s: Error reading MAC from eeprom: %d\n",
836 dev->name, err);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700837 }
838 dev->addr_len = 6;
839
840 netif_carrier_off(dev);
841
842 /* Device methods */
Sakari Ailusc659c382011-01-21 10:59:30 +0000843 dev->netdev_ops = &tlan_netdev_ops;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700844 dev->watchdog_timeo = TX_TIMEOUT;
845
846 return 0;
847
Sakari Ailusc659c382011-01-21 10:59:30 +0000848}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700849
850
851
852
Sakari Ailusc659c382011-01-21 10:59:30 +0000853/***************************************************************
854 * tlan_open
855 *
856 * Returns:
857 * 0 on success, error code otherwise.
858 * Parms:
859 * dev Structure of device to be opened.
860 *
861 * This routine puts the driver and TLAN adapter in a
862 * state where it is ready to send and receive packets.
863 * It allocates the IRQ, resets and brings the adapter
864 * out of reset, and allows interrupts. It also delays
865 * the startup for autonegotiation or sends a Rx GO
866 * command to the adapter, as appropriate.
867 *
868 **************************************************************/
Linus Torvalds1da177e2005-04-16 15:20:36 -0700869
Sakari Ailusc659c382011-01-21 10:59:30 +0000870static int tlan_open(struct net_device *dev)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700871{
Sakari Ailusc659c382011-01-21 10:59:30 +0000872 struct tlan_priv *priv = netdev_priv(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700873 int err;
Jeff Garzik6aa20a22006-09-13 13:24:59 -0400874
Sakari Ailusc659c382011-01-21 10:59:30 +0000875 priv->tlan_rev = tlan_dio_read8(dev->base_addr, TLAN_DEF_REVISION);
876 err = request_irq(dev->irq, tlan_handle_interrupt, IRQF_SHARED,
877 dev->name, dev);
Jeff Garzik6aa20a22006-09-13 13:24:59 -0400878
Sakari Ailusc659c382011-01-21 10:59:30 +0000879 if (err) {
Joe Perches50624aa2011-03-01 06:56:33 +0000880 netdev_err(dev, "Cannot open because IRQ %d is already in use\n",
881 dev->irq);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700882 return err;
883 }
Jeff Garzik6aa20a22006-09-13 13:24:59 -0400884
Linus Torvalds1da177e2005-04-16 15:20:36 -0700885 init_timer(&priv->timer);
Ondrej Zaryc0a87c22014-06-30 18:38:28 +0200886 init_timer(&priv->media_timer);
Jeff Garzik6aa20a22006-09-13 13:24:59 -0400887
Sakari Ailusfa6d5d42011-01-21 10:59:31 +0000888 tlan_start(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700889
Sakari Ailusc659c382011-01-21 10:59:30 +0000890 TLAN_DBG(TLAN_DEBUG_GNRL, "%s: Opened. TLAN Chip Rev: %x\n",
891 dev->name, priv->tlan_rev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700892
893 return 0;
894
Sakari Ailusc659c382011-01-21 10:59:30 +0000895}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700896
897
898
Sakari Ailusc659c382011-01-21 10:59:30 +0000899/**************************************************************
900 * tlan_ioctl
901 *
902 * Returns:
903 * 0 on success, error code otherwise
904 * Params:
905 * dev structure of device to receive ioctl.
906 *
907 * rq ifreq structure to hold userspace data.
908 *
909 * cmd ioctl command.
910 *
911 *
912 *************************************************************/
Linus Torvalds1da177e2005-04-16 15:20:36 -0700913
Sakari Ailusc659c382011-01-21 10:59:30 +0000914static int tlan_ioctl(struct net_device *dev, struct ifreq *rq, int cmd)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700915{
Sakari Ailusc659c382011-01-21 10:59:30 +0000916 struct tlan_priv *priv = netdev_priv(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700917 struct mii_ioctl_data *data = if_mii(rq);
Sakari Ailusc659c382011-01-21 10:59:30 +0000918 u32 phy = priv->phy[priv->phy_num];
Jeff Garzik6aa20a22006-09-13 13:24:59 -0400919
Sakari Ailusc659c382011-01-21 10:59:30 +0000920 if (!priv->phy_online)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700921 return -EAGAIN;
922
Sakari Ailusc659c382011-01-21 10:59:30 +0000923 switch (cmd) {
924 case SIOCGMIIPHY: /* get address of MII PHY in use. */
925 data->phy_id = phy;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700926
927
Sakari Ailusc659c382011-01-21 10:59:30 +0000928 case SIOCGMIIREG: /* read MII PHY register. */
929 tlan_mii_read_reg(dev, data->phy_id & 0x1f,
930 data->reg_num & 0x1f, &data->val_out);
931 return 0;
Jeff Garzik6aa20a22006-09-13 13:24:59 -0400932
Linus Torvalds1da177e2005-04-16 15:20:36 -0700933
Sakari Ailusc659c382011-01-21 10:59:30 +0000934 case SIOCSMIIREG: /* write MII PHY register. */
935 tlan_mii_write_reg(dev, data->phy_id & 0x1f,
936 data->reg_num & 0x1f, data->val_in);
937 return 0;
938 default:
939 return -EOPNOTSUPP;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700940 }
Sakari Ailusc659c382011-01-21 10:59:30 +0000941}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700942
943
Sakari Ailusc659c382011-01-21 10:59:30 +0000944/***************************************************************
945 * tlan_tx_timeout
946 *
947 * Returns: nothing
948 *
949 * Params:
950 * dev structure of device which timed out
951 * during transmit.
952 *
953 **************************************************************/
Linus Torvalds1da177e2005-04-16 15:20:36 -0700954
Sakari Ailusc659c382011-01-21 10:59:30 +0000955static void tlan_tx_timeout(struct net_device *dev)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700956{
Jeff Garzik6aa20a22006-09-13 13:24:59 -0400957
Sakari Ailusc659c382011-01-21 10:59:30 +0000958 TLAN_DBG(TLAN_DEBUG_GNRL, "%s: Transmit timed out.\n", dev->name);
Jeff Garzik6aa20a22006-09-13 13:24:59 -0400959
Linus Torvalds1da177e2005-04-16 15:20:36 -0700960 /* Ok so we timed out, lets see what we can do about it...*/
Sakari Ailusc659c382011-01-21 10:59:30 +0000961 tlan_free_lists(dev);
962 tlan_reset_lists(dev);
963 tlan_read_and_clear_stats(dev, TLAN_IGNORE);
964 tlan_reset_adapter(dev);
Eric Dumazet1ae5dc32010-05-10 05:01:31 -0700965 dev->trans_start = jiffies; /* prevent tx timeout */
Sakari Ailusc659c382011-01-21 10:59:30 +0000966 netif_wake_queue(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700967
968}
Jeff Garzik6aa20a22006-09-13 13:24:59 -0400969
Linus Torvalds1da177e2005-04-16 15:20:36 -0700970
Sakari Ailusc659c382011-01-21 10:59:30 +0000971/***************************************************************
972 * tlan_tx_timeout_work
973 *
974 * Returns: nothing
975 *
976 * Params:
977 * work work item of device which timed out
978 *
979 **************************************************************/
David Howellsc4028952006-11-22 14:57:56 +0000980
Sakari Ailusc659c382011-01-21 10:59:30 +0000981static void tlan_tx_timeout_work(struct work_struct *work)
David Howellsc4028952006-11-22 14:57:56 +0000982{
Sakari Ailusc659c382011-01-21 10:59:30 +0000983 struct tlan_priv *priv =
984 container_of(work, struct tlan_priv, tlan_tqueue);
David Howellsc4028952006-11-22 14:57:56 +0000985
Sakari Ailusc659c382011-01-21 10:59:30 +0000986 tlan_tx_timeout(priv->dev);
David Howellsc4028952006-11-22 14:57:56 +0000987}
988
989
Linus Torvalds1da177e2005-04-16 15:20:36 -0700990
Sakari Ailusc659c382011-01-21 10:59:30 +0000991/***************************************************************
992 * tlan_start_tx
993 *
994 * Returns:
995 * 0 on success, non-zero on failure.
996 * Parms:
997 * skb A pointer to the sk_buff containing the
998 * frame to be sent.
999 * dev The device to send the data on.
1000 *
1001 * This function adds a frame to the Tx list to be sent
1002 * ASAP. First it verifies that the adapter is ready and
1003 * there is room in the queue. Then it sets up the next
1004 * available list, copies the frame to the corresponding
1005 * buffer. If the adapter Tx channel is idle, it gives
1006 * the adapter a Tx Go command on the list, otherwise it
1007 * sets the forward address of the previous list to point
1008 * to this one. Then it frees the sk_buff.
1009 *
1010 **************************************************************/
Linus Torvalds1da177e2005-04-16 15:20:36 -07001011
Sakari Ailusc659c382011-01-21 10:59:30 +00001012static netdev_tx_t tlan_start_tx(struct sk_buff *skb, struct net_device *dev)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001013{
Sakari Ailusc659c382011-01-21 10:59:30 +00001014 struct tlan_priv *priv = netdev_priv(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001015 dma_addr_t tail_list_phys;
Sakari Ailusc659c382011-01-21 10:59:30 +00001016 struct tlan_list *tail_list;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001017 unsigned long flags;
Sakari Ailus8953f122008-12-16 01:44:05 -08001018 unsigned int txlen;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001019
Sakari Ailusc659c382011-01-21 10:59:30 +00001020 if (!priv->phy_online) {
1021 TLAN_DBG(TLAN_DEBUG_TX, "TRANSMIT: %s PHY is not ready\n",
1022 dev->name);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001023 dev_kfree_skb_any(skb);
Patrick McHardy6ed10652009-06-23 06:03:08 +00001024 return NETDEV_TX_OK;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001025 }
1026
Stephen Hemminger41873e92008-05-30 09:49:52 -07001027 if (skb_padto(skb, TLAN_MIN_FRAME_SIZE))
Patrick McHardy6ed10652009-06-23 06:03:08 +00001028 return NETDEV_TX_OK;
Sakari Ailus8953f122008-12-16 01:44:05 -08001029 txlen = max(skb->len, (unsigned int)TLAN_MIN_FRAME_SIZE);
Stephen Hemminger41873e92008-05-30 09:49:52 -07001030
Sakari Ailusc659c382011-01-21 10:59:30 +00001031 tail_list = priv->tx_list + priv->tx_tail;
1032 tail_list_phys =
1033 priv->tx_list_dma + sizeof(struct tlan_list)*priv->tx_tail;
Jeff Garzik6aa20a22006-09-13 13:24:59 -04001034
Sakari Ailusc659c382011-01-21 10:59:30 +00001035 if (tail_list->c_stat != TLAN_CSTAT_UNUSED) {
1036 TLAN_DBG(TLAN_DEBUG_TX,
1037 "TRANSMIT: %s is busy (Head=%d Tail=%d)\n",
1038 dev->name, priv->tx_head, priv->tx_tail);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001039 netif_stop_queue(dev);
Sakari Ailusc659c382011-01-21 10:59:30 +00001040 priv->tx_busy_count++;
Patrick McHardy5b548142009-06-12 06:22:29 +00001041 return NETDEV_TX_BUSY;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001042 }
1043
1044 tail_list->forward = 0;
1045
Sakari Ailusc659c382011-01-21 10:59:30 +00001046 tail_list->buffer[0].address = pci_map_single(priv->pci_dev,
Sakari Ailus5eeabf52008-12-16 15:24:05 -08001047 skb->data, txlen,
1048 PCI_DMA_TODEVICE);
Sakari Ailusc659c382011-01-21 10:59:30 +00001049 tlan_store_skb(tail_list, skb);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001050
Sakari Ailusc659c382011-01-21 10:59:30 +00001051 tail_list->frame_size = (u16) txlen;
Sakari Ailus8953f122008-12-16 01:44:05 -08001052 tail_list->buffer[0].count = TLAN_LAST_BUFFER | (u32) txlen;
Stephen Hemminger41873e92008-05-30 09:49:52 -07001053 tail_list->buffer[1].count = 0;
1054 tail_list->buffer[1].address = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001055
1056 spin_lock_irqsave(&priv->lock, flags);
Sakari Ailusc659c382011-01-21 10:59:30 +00001057 tail_list->c_stat = TLAN_CSTAT_READY;
1058 if (!priv->tx_in_progress) {
1059 priv->tx_in_progress = 1;
1060 TLAN_DBG(TLAN_DEBUG_TX,
1061 "TRANSMIT: Starting TX on buffer %d\n",
1062 priv->tx_tail);
1063 outl(tail_list_phys, dev->base_addr + TLAN_CH_PARM);
1064 outl(TLAN_HC_GO, dev->base_addr + TLAN_HOST_CMD);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001065 } else {
Sakari Ailusc659c382011-01-21 10:59:30 +00001066 TLAN_DBG(TLAN_DEBUG_TX,
1067 "TRANSMIT: Adding buffer %d to TX channel\n",
1068 priv->tx_tail);
1069 if (priv->tx_tail == 0) {
1070 (priv->tx_list + (TLAN_NUM_TX_LISTS - 1))->forward
Stephen Hemmingerdfc2c0a2008-05-30 09:49:58 -07001071 = tail_list_phys;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001072 } else {
Sakari Ailusc659c382011-01-21 10:59:30 +00001073 (priv->tx_list + (priv->tx_tail - 1))->forward
Stephen Hemmingerdfc2c0a2008-05-30 09:49:58 -07001074 = tail_list_phys;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001075 }
1076 }
1077 spin_unlock_irqrestore(&priv->lock, flags);
1078
Sakari Ailusc659c382011-01-21 10:59:30 +00001079 CIRC_INC(priv->tx_tail, TLAN_NUM_TX_LISTS);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001080
Patrick McHardy6ed10652009-06-23 06:03:08 +00001081 return NETDEV_TX_OK;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001082
Sakari Ailusc659c382011-01-21 10:59:30 +00001083}
Linus Torvalds1da177e2005-04-16 15:20:36 -07001084
1085
1086
1087
Sakari Ailusc659c382011-01-21 10:59:30 +00001088/***************************************************************
1089 * tlan_handle_interrupt
1090 *
1091 * Returns:
1092 * Nothing
1093 * Parms:
1094 * irq The line on which the interrupt
1095 * occurred.
1096 * dev_id A pointer to the device assigned to
1097 * this irq line.
1098 *
1099 * This function handles an interrupt generated by its
1100 * assigned TLAN adapter. The function deactivates
1101 * interrupts on its adapter, records the type of
1102 * interrupt, executes the appropriate subhandler, and
1103 * acknowdges the interrupt to the adapter (thus
1104 * re-enabling adapter interrupts.
1105 *
1106 **************************************************************/
Linus Torvalds1da177e2005-04-16 15:20:36 -07001107
Sakari Ailusc659c382011-01-21 10:59:30 +00001108static irqreturn_t tlan_handle_interrupt(int irq, void *dev_id)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001109{
Stephen Hemmingera3ccc782008-05-30 09:49:57 -07001110 struct net_device *dev = dev_id;
Sakari Ailusc659c382011-01-21 10:59:30 +00001111 struct tlan_priv *priv = netdev_priv(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001112 u16 host_int;
Stephen Hemmingera3ccc782008-05-30 09:49:57 -07001113 u16 type;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001114
1115 spin_lock(&priv->lock);
1116
Sakari Ailusc659c382011-01-21 10:59:30 +00001117 host_int = inw(dev->base_addr + TLAN_HOST_INT);
1118 type = (host_int & TLAN_HI_IT_MASK) >> 2;
1119 if (type) {
Stephen Hemmingera3ccc782008-05-30 09:49:57 -07001120 u32 ack;
1121 u32 host_cmd;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001122
Sakari Ailusc659c382011-01-21 10:59:30 +00001123 outw(host_int, dev->base_addr + TLAN_HOST_INT);
1124 ack = tlan_int_vector[type](dev, host_int);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001125
Sakari Ailusc659c382011-01-21 10:59:30 +00001126 if (ack) {
1127 host_cmd = TLAN_HC_ACK | ack | (type << 18);
1128 outl(host_cmd, dev->base_addr + TLAN_HOST_CMD);
Stephen Hemmingera3ccc782008-05-30 09:49:57 -07001129 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001130 }
1131
1132 spin_unlock(&priv->lock);
1133
Stephen Hemmingera3ccc782008-05-30 09:49:57 -07001134 return IRQ_RETVAL(type);
Sakari Ailusc659c382011-01-21 10:59:30 +00001135}
Linus Torvalds1da177e2005-04-16 15:20:36 -07001136
1137
1138
1139
Sakari Ailusc659c382011-01-21 10:59:30 +00001140/***************************************************************
1141 * tlan_close
1142 *
1143 * Returns:
1144 * An error code.
1145 * Parms:
1146 * dev The device structure of the device to
1147 * close.
1148 *
1149 * This function shuts down the adapter. It records any
1150 * stats, puts the adapter into reset state, deactivates
1151 * its time as needed, and frees the irq it is using.
1152 *
1153 **************************************************************/
Linus Torvalds1da177e2005-04-16 15:20:36 -07001154
Sakari Ailusc659c382011-01-21 10:59:30 +00001155static int tlan_close(struct net_device *dev)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001156{
Sakari Ailusc659c382011-01-21 10:59:30 +00001157 struct tlan_priv *priv = netdev_priv(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001158
Linus Torvalds1da177e2005-04-16 15:20:36 -07001159 priv->neg_be_verbose = 0;
Sakari Ailusfa6d5d42011-01-21 10:59:31 +00001160 tlan_stop(dev);
Jeff Garzik6aa20a22006-09-13 13:24:59 -04001161
Sakari Ailusc659c382011-01-21 10:59:30 +00001162 free_irq(dev->irq, dev);
1163 tlan_free_lists(dev);
1164 TLAN_DBG(TLAN_DEBUG_GNRL, "Device %s closed.\n", dev->name);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001165
1166 return 0;
1167
Sakari Ailusc659c382011-01-21 10:59:30 +00001168}
Linus Torvalds1da177e2005-04-16 15:20:36 -07001169
1170
1171
1172
Sakari Ailusc659c382011-01-21 10:59:30 +00001173/***************************************************************
1174 * tlan_get_stats
1175 *
1176 * Returns:
1177 * A pointer to the device's statistics structure.
1178 * Parms:
1179 * dev The device structure to return the
1180 * stats for.
1181 *
1182 * This function updates the devices statistics by reading
1183 * the TLAN chip's onboard registers. Then it returns the
1184 * address of the statistics structure.
1185 *
1186 **************************************************************/
Linus Torvalds1da177e2005-04-16 15:20:36 -07001187
Sakari Ailusc659c382011-01-21 10:59:30 +00001188static struct net_device_stats *tlan_get_stats(struct net_device *dev)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001189{
Sakari Ailusc659c382011-01-21 10:59:30 +00001190 struct tlan_priv *priv = netdev_priv(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001191 int i;
1192
1193 /* Should only read stats if open ? */
Sakari Ailusc659c382011-01-21 10:59:30 +00001194 tlan_read_and_clear_stats(dev, TLAN_RECORD);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001195
Sakari Ailusc659c382011-01-21 10:59:30 +00001196 TLAN_DBG(TLAN_DEBUG_RX, "RECEIVE: %s EOC count = %d\n", dev->name,
1197 priv->rx_eoc_count);
1198 TLAN_DBG(TLAN_DEBUG_TX, "TRANSMIT: %s Busy count = %d\n", dev->name,
1199 priv->tx_busy_count);
1200 if (debug & TLAN_DEBUG_GNRL) {
1201 tlan_print_dio(dev->base_addr);
1202 tlan_phy_print(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001203 }
Sakari Ailusc659c382011-01-21 10:59:30 +00001204 if (debug & TLAN_DEBUG_LIST) {
1205 for (i = 0; i < TLAN_NUM_RX_LISTS; i++)
1206 tlan_print_list(priv->rx_list + i, "RX", i);
1207 for (i = 0; i < TLAN_NUM_TX_LISTS; i++)
1208 tlan_print_list(priv->tx_list + i, "TX", i);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001209 }
Jeff Garzik6aa20a22006-09-13 13:24:59 -04001210
Stephen Hemmingerf8f31542008-05-30 09:49:53 -07001211 return &dev->stats;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001212
Sakari Ailusc659c382011-01-21 10:59:30 +00001213}
Linus Torvalds1da177e2005-04-16 15:20:36 -07001214
1215
1216
1217
Sakari Ailusc659c382011-01-21 10:59:30 +00001218/***************************************************************
1219 * tlan_set_multicast_list
1220 *
1221 * Returns:
1222 * Nothing
1223 * Parms:
1224 * dev The device structure to set the
1225 * multicast list for.
1226 *
1227 * This function sets the TLAN adaptor to various receive
1228 * modes. If the IFF_PROMISC flag is set, promiscuous
1229 * mode is acitviated. Otherwise, promiscuous mode is
1230 * turned off. If the IFF_ALLMULTI flag is set, then
1231 * the hash table is set to receive all group addresses.
1232 * Otherwise, the first three multicast addresses are
1233 * stored in AREG_1-3, and the rest are selected via the
1234 * hash table, as necessary.
1235 *
1236 **************************************************************/
Linus Torvalds1da177e2005-04-16 15:20:36 -07001237
Sakari Ailusc659c382011-01-21 10:59:30 +00001238static void tlan_set_multicast_list(struct net_device *dev)
Jeff Garzik6aa20a22006-09-13 13:24:59 -04001239{
Jiri Pirko22bedad32010-04-01 21:22:57 +00001240 struct netdev_hw_addr *ha;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001241 u32 hash1 = 0;
1242 u32 hash2 = 0;
1243 int i;
1244 u32 offset;
1245 u8 tmp;
1246
Sakari Ailusc659c382011-01-21 10:59:30 +00001247 if (dev->flags & IFF_PROMISC) {
1248 tmp = tlan_dio_read8(dev->base_addr, TLAN_NET_CMD);
1249 tlan_dio_write8(dev->base_addr,
1250 TLAN_NET_CMD, tmp | TLAN_NET_CMD_CAF);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001251 } else {
Sakari Ailusc659c382011-01-21 10:59:30 +00001252 tmp = tlan_dio_read8(dev->base_addr, TLAN_NET_CMD);
1253 tlan_dio_write8(dev->base_addr,
1254 TLAN_NET_CMD, tmp & ~TLAN_NET_CMD_CAF);
1255 if (dev->flags & IFF_ALLMULTI) {
1256 for (i = 0; i < 3; i++)
1257 tlan_set_mac(dev, i + 1, NULL);
1258 tlan_dio_write32(dev->base_addr, TLAN_HASH_1,
1259 0xffffffff);
1260 tlan_dio_write32(dev->base_addr, TLAN_HASH_2,
1261 0xffffffff);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001262 } else {
Jiri Pirko567ec872010-02-23 23:17:07 +00001263 i = 0;
Jiri Pirko22bedad32010-04-01 21:22:57 +00001264 netdev_for_each_mc_addr(ha, dev) {
Sakari Ailusc659c382011-01-21 10:59:30 +00001265 if (i < 3) {
1266 tlan_set_mac(dev, i + 1,
Jiri Pirko22bedad32010-04-01 21:22:57 +00001267 (char *) &ha->addr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001268 } else {
Sakari Ailusc659c382011-01-21 10:59:30 +00001269 offset =
1270 tlan_hash_func((u8 *)&ha->addr);
1271 if (offset < 32)
1272 hash1 |= (1 << offset);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001273 else
Sakari Ailusc659c382011-01-21 10:59:30 +00001274 hash2 |= (1 << (offset - 32));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001275 }
Jiri Pirko567ec872010-02-23 23:17:07 +00001276 i++;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001277 }
Sakari Ailusc659c382011-01-21 10:59:30 +00001278 for ( ; i < 3; i++)
1279 tlan_set_mac(dev, i + 1, NULL);
1280 tlan_dio_write32(dev->base_addr, TLAN_HASH_1, hash1);
1281 tlan_dio_write32(dev->base_addr, TLAN_HASH_2, hash2);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001282 }
1283 }
1284
Sakari Ailusc659c382011-01-21 10:59:30 +00001285}
Linus Torvalds1da177e2005-04-16 15:20:36 -07001286
1287
1288
1289/*****************************************************************************
1290******************************************************************************
1291
Sakari Ailusc659c382011-01-21 10:59:30 +00001292ThunderLAN driver interrupt vectors and table
Linus Torvalds1da177e2005-04-16 15:20:36 -07001293
Sakari Ailusc659c382011-01-21 10:59:30 +00001294please see chap. 4, "Interrupt Handling" of the "ThunderLAN
1295Programmer's Guide" for more informations on handling interrupts
1296generated by TLAN based adapters.
Linus Torvalds1da177e2005-04-16 15:20:36 -07001297
1298******************************************************************************
1299*****************************************************************************/
1300
1301
Linus Torvalds1da177e2005-04-16 15:20:36 -07001302
1303
Sakari Ailusc659c382011-01-21 10:59:30 +00001304/***************************************************************
1305 * tlan_handle_tx_eof
1306 *
1307 * Returns:
1308 * 1
1309 * Parms:
1310 * dev Device assigned the IRQ that was
1311 * raised.
1312 * host_int The contents of the HOST_INT
1313 * port.
1314 *
1315 * This function handles Tx EOF interrupts which are raised
1316 * by the adapter when it has completed sending the
1317 * contents of a buffer. If detemines which list/buffer
1318 * was completed and resets it. If the buffer was the last
1319 * in the channel (EOC), then the function checks to see if
1320 * another buffer is ready to send, and if so, sends a Tx
1321 * Go command. Finally, the driver activates/continues the
1322 * activity LED.
1323 *
1324 **************************************************************/
Linus Torvalds1da177e2005-04-16 15:20:36 -07001325
Sakari Ailusc659c382011-01-21 10:59:30 +00001326static u32 tlan_handle_tx_eof(struct net_device *dev, u16 host_int)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001327{
Sakari Ailusc659c382011-01-21 10:59:30 +00001328 struct tlan_priv *priv = netdev_priv(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001329 int eoc = 0;
Sakari Ailusc659c382011-01-21 10:59:30 +00001330 struct tlan_list *head_list;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001331 dma_addr_t head_list_phys;
1332 u32 ack = 0;
Sakari Ailusc659c382011-01-21 10:59:30 +00001333 u16 tmp_c_stat;
Jeff Garzik6aa20a22006-09-13 13:24:59 -04001334
Sakari Ailusc659c382011-01-21 10:59:30 +00001335 TLAN_DBG(TLAN_DEBUG_TX,
1336 "TRANSMIT: Handling TX EOF (Head=%d Tail=%d)\n",
1337 priv->tx_head, priv->tx_tail);
1338 head_list = priv->tx_list + priv->tx_head;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001339
Sakari Ailusc659c382011-01-21 10:59:30 +00001340 while (((tmp_c_stat = head_list->c_stat) & TLAN_CSTAT_FRM_CMP)
1341 && (ack < 255)) {
1342 struct sk_buff *skb = tlan_get_skb(head_list);
Sakari Ailus5eeabf52008-12-16 15:24:05 -08001343
Linus Torvalds1da177e2005-04-16 15:20:36 -07001344 ack++;
Sakari Ailusc659c382011-01-21 10:59:30 +00001345 pci_unmap_single(priv->pci_dev, head_list->buffer[0].address,
Sakari Ailus5eeabf52008-12-16 15:24:05 -08001346 max(skb->len,
1347 (unsigned int)TLAN_MIN_FRAME_SIZE),
1348 PCI_DMA_TODEVICE);
1349 dev_kfree_skb_any(skb);
1350 head_list->buffer[8].address = 0;
1351 head_list->buffer[9].address = 0;
Jeff Garzik6aa20a22006-09-13 13:24:59 -04001352
Sakari Ailusc659c382011-01-21 10:59:30 +00001353 if (tmp_c_stat & TLAN_CSTAT_EOC)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001354 eoc = 1;
Jeff Garzik6aa20a22006-09-13 13:24:59 -04001355
Sakari Ailusc659c382011-01-21 10:59:30 +00001356 dev->stats.tx_bytes += head_list->frame_size;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001357
Sakari Ailusc659c382011-01-21 10:59:30 +00001358 head_list->c_stat = TLAN_CSTAT_UNUSED;
Jeff Garzik6aa20a22006-09-13 13:24:59 -04001359 netif_start_queue(dev);
Sakari Ailusc659c382011-01-21 10:59:30 +00001360 CIRC_INC(priv->tx_head, TLAN_NUM_TX_LISTS);
1361 head_list = priv->tx_list + priv->tx_head;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001362 }
1363
1364 if (!ack)
Joe Perches50624aa2011-03-01 06:56:33 +00001365 netdev_info(dev,
1366 "Received interrupt for uncompleted TX frame\n");
Jeff Garzik6aa20a22006-09-13 13:24:59 -04001367
Sakari Ailusc659c382011-01-21 10:59:30 +00001368 if (eoc) {
1369 TLAN_DBG(TLAN_DEBUG_TX,
1370 "TRANSMIT: handling TX EOC (Head=%d Tail=%d)\n",
1371 priv->tx_head, priv->tx_tail);
1372 head_list = priv->tx_list + priv->tx_head;
1373 head_list_phys = priv->tx_list_dma
1374 + sizeof(struct tlan_list)*priv->tx_head;
Sakari Ailusf45437e2011-02-09 10:25:06 +00001375 if ((head_list->c_stat & TLAN_CSTAT_READY)
1376 == TLAN_CSTAT_READY) {
Sakari Ailusc659c382011-01-21 10:59:30 +00001377 outl(head_list_phys, dev->base_addr + TLAN_CH_PARM);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001378 ack |= TLAN_HC_GO;
1379 } else {
Sakari Ailusc659c382011-01-21 10:59:30 +00001380 priv->tx_in_progress = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001381 }
1382 }
Jeff Garzik6aa20a22006-09-13 13:24:59 -04001383
Sakari Ailusc659c382011-01-21 10:59:30 +00001384 if (priv->adapter->flags & TLAN_ADAPTER_ACTIVITY_LED) {
1385 tlan_dio_write8(dev->base_addr,
1386 TLAN_LED_REG, TLAN_LED_LINK | TLAN_LED_ACT);
1387 if (priv->timer.function == NULL) {
1388 priv->timer.function = tlan_timer;
1389 priv->timer.data = (unsigned long) dev;
1390 priv->timer.expires = jiffies + TLAN_TIMER_ACT_DELAY;
1391 priv->timer_set_at = jiffies;
1392 priv->timer_type = TLAN_TIMER_ACTIVITY;
1393 add_timer(&priv->timer);
1394 } else if (priv->timer_type == TLAN_TIMER_ACTIVITY) {
1395 priv->timer_set_at = jiffies;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001396 }
1397 }
1398
1399 return ack;
1400
Sakari Ailusc659c382011-01-21 10:59:30 +00001401}
Linus Torvalds1da177e2005-04-16 15:20:36 -07001402
1403
1404
1405
Sakari Ailusc659c382011-01-21 10:59:30 +00001406/***************************************************************
1407 * TLan_HandleStatOverflow
1408 *
1409 * Returns:
1410 * 1
1411 * Parms:
1412 * dev Device assigned the IRQ that was
1413 * raised.
1414 * host_int The contents of the HOST_INT
1415 * port.
1416 *
1417 * This function handles the Statistics Overflow interrupt
1418 * which means that one or more of the TLAN statistics
1419 * registers has reached 1/2 capacity and needs to be read.
1420 *
1421 **************************************************************/
Linus Torvalds1da177e2005-04-16 15:20:36 -07001422
Sakari Ailusc659c382011-01-21 10:59:30 +00001423static u32 tlan_handle_stat_overflow(struct net_device *dev, u16 host_int)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001424{
Sakari Ailusc659c382011-01-21 10:59:30 +00001425 tlan_read_and_clear_stats(dev, TLAN_RECORD);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001426
1427 return 1;
1428
Sakari Ailusc659c382011-01-21 10:59:30 +00001429}
Linus Torvalds1da177e2005-04-16 15:20:36 -07001430
1431
1432
1433
Sakari Ailusc659c382011-01-21 10:59:30 +00001434/***************************************************************
1435 * TLan_HandleRxEOF
1436 *
1437 * Returns:
1438 * 1
1439 * Parms:
1440 * dev Device assigned the IRQ that was
1441 * raised.
1442 * host_int The contents of the HOST_INT
1443 * port.
1444 *
1445 * This function handles the Rx EOF interrupt which
1446 * indicates a frame has been received by the adapter from
1447 * the net and the frame has been transferred to memory.
1448 * The function determines the bounce buffer the frame has
1449 * been loaded into, creates a new sk_buff big enough to
1450 * hold the frame, and sends it to protocol stack. It
1451 * then resets the used buffer and appends it to the end
1452 * of the list. If the frame was the last in the Rx
1453 * channel (EOC), the function restarts the receive channel
1454 * by sending an Rx Go command to the adapter. Then it
1455 * activates/continues the activity LED.
1456 *
1457 **************************************************************/
Linus Torvalds1da177e2005-04-16 15:20:36 -07001458
Sakari Ailusc659c382011-01-21 10:59:30 +00001459static u32 tlan_handle_rx_eof(struct net_device *dev, u16 host_int)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001460{
Sakari Ailusc659c382011-01-21 10:59:30 +00001461 struct tlan_priv *priv = netdev_priv(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001462 u32 ack = 0;
1463 int eoc = 0;
Sakari Ailusc659c382011-01-21 10:59:30 +00001464 struct tlan_list *head_list;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001465 struct sk_buff *skb;
Sakari Ailusc659c382011-01-21 10:59:30 +00001466 struct tlan_list *tail_list;
1467 u16 tmp_c_stat;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001468 dma_addr_t head_list_phys;
1469
Sakari Ailusc659c382011-01-21 10:59:30 +00001470 TLAN_DBG(TLAN_DEBUG_RX, "RECEIVE: handling RX EOF (Head=%d Tail=%d)\n",
1471 priv->rx_head, priv->rx_tail);
1472 head_list = priv->rx_list + priv->rx_head;
1473 head_list_phys =
1474 priv->rx_list_dma + sizeof(struct tlan_list)*priv->rx_head;
Jeff Garzik6aa20a22006-09-13 13:24:59 -04001475
Sakari Ailusc659c382011-01-21 10:59:30 +00001476 while (((tmp_c_stat = head_list->c_stat) & TLAN_CSTAT_FRM_CMP)
1477 && (ack < 255)) {
1478 dma_addr_t frame_dma = head_list->buffer[0].address;
1479 u32 frame_size = head_list->frame_size;
Sakari Ailus5eeabf52008-12-16 15:24:05 -08001480 struct sk_buff *new_skb;
1481
Linus Torvalds1da177e2005-04-16 15:20:36 -07001482 ack++;
Sakari Ailusc659c382011-01-21 10:59:30 +00001483 if (tmp_c_stat & TLAN_CSTAT_EOC)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001484 eoc = 1;
Jeff Garzik6aa20a22006-09-13 13:24:59 -04001485
Eric Dumazet89d71a62009-10-13 05:34:20 +00001486 new_skb = netdev_alloc_skb_ip_align(dev,
1487 TLAN_MAX_FRAME_SIZE + 5);
Sakari Ailusc659c382011-01-21 10:59:30 +00001488 if (!new_skb)
Sakari Ailus5eeabf52008-12-16 15:24:05 -08001489 goto drop_and_reuse;
Jeff Garzik6aa20a22006-09-13 13:24:59 -04001490
Sakari Ailusc659c382011-01-21 10:59:30 +00001491 skb = tlan_get_skb(head_list);
1492 pci_unmap_single(priv->pci_dev, frame_dma,
Sakari Ailus5eeabf52008-12-16 15:24:05 -08001493 TLAN_MAX_FRAME_SIZE, PCI_DMA_FROMDEVICE);
Sakari Ailusc659c382011-01-21 10:59:30 +00001494 skb_put(skb, frame_size);
Stephen Hemmingerdfc2c0a2008-05-30 09:49:58 -07001495
Sakari Ailusc659c382011-01-21 10:59:30 +00001496 dev->stats.rx_bytes += frame_size;
Jeff Garzik6aa20a22006-09-13 13:24:59 -04001497
Sakari Ailusc659c382011-01-21 10:59:30 +00001498 skb->protocol = eth_type_trans(skb, dev);
1499 netif_rx(skb);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001500
Sakari Ailusc659c382011-01-21 10:59:30 +00001501 head_list->buffer[0].address =
1502 pci_map_single(priv->pci_dev, new_skb->data,
1503 TLAN_MAX_FRAME_SIZE, PCI_DMA_FROMDEVICE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001504
Sakari Ailusc659c382011-01-21 10:59:30 +00001505 tlan_store_skb(head_list, new_skb);
Stephen Hemmingerdfc2c0a2008-05-30 09:49:58 -07001506drop_and_reuse:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001507 head_list->forward = 0;
Sakari Ailusc659c382011-01-21 10:59:30 +00001508 head_list->c_stat = 0;
1509 tail_list = priv->rx_list + priv->rx_tail;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001510 tail_list->forward = head_list_phys;
1511
Sakari Ailusc659c382011-01-21 10:59:30 +00001512 CIRC_INC(priv->rx_head, TLAN_NUM_RX_LISTS);
1513 CIRC_INC(priv->rx_tail, TLAN_NUM_RX_LISTS);
1514 head_list = priv->rx_list + priv->rx_head;
1515 head_list_phys = priv->rx_list_dma
1516 + sizeof(struct tlan_list)*priv->rx_head;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001517 }
1518
1519 if (!ack)
Joe Perches50624aa2011-03-01 06:56:33 +00001520 netdev_info(dev,
1521 "Received interrupt for uncompleted RX frame\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001522
1523
Sakari Ailusc659c382011-01-21 10:59:30 +00001524 if (eoc) {
1525 TLAN_DBG(TLAN_DEBUG_RX,
1526 "RECEIVE: handling RX EOC (Head=%d Tail=%d)\n",
1527 priv->rx_head, priv->rx_tail);
1528 head_list = priv->rx_list + priv->rx_head;
1529 head_list_phys = priv->rx_list_dma
1530 + sizeof(struct tlan_list)*priv->rx_head;
1531 outl(head_list_phys, dev->base_addr + TLAN_CH_PARM);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001532 ack |= TLAN_HC_GO | TLAN_HC_RT;
Sakari Ailusc659c382011-01-21 10:59:30 +00001533 priv->rx_eoc_count++;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001534 }
1535
Sakari Ailusc659c382011-01-21 10:59:30 +00001536 if (priv->adapter->flags & TLAN_ADAPTER_ACTIVITY_LED) {
1537 tlan_dio_write8(dev->base_addr,
1538 TLAN_LED_REG, TLAN_LED_LINK | TLAN_LED_ACT);
1539 if (priv->timer.function == NULL) {
1540 priv->timer.function = tlan_timer;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001541 priv->timer.data = (unsigned long) dev;
1542 priv->timer.expires = jiffies + TLAN_TIMER_ACT_DELAY;
Sakari Ailusc659c382011-01-21 10:59:30 +00001543 priv->timer_set_at = jiffies;
1544 priv->timer_type = TLAN_TIMER_ACTIVITY;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001545 add_timer(&priv->timer);
Sakari Ailusc659c382011-01-21 10:59:30 +00001546 } else if (priv->timer_type == TLAN_TIMER_ACTIVITY) {
1547 priv->timer_set_at = jiffies;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001548 }
1549 }
1550
Linus Torvalds1da177e2005-04-16 15:20:36 -07001551 return ack;
1552
Sakari Ailusc659c382011-01-21 10:59:30 +00001553}
Linus Torvalds1da177e2005-04-16 15:20:36 -07001554
1555
1556
1557
Sakari Ailusc659c382011-01-21 10:59:30 +00001558/***************************************************************
1559 * tlan_handle_dummy
1560 *
1561 * Returns:
1562 * 1
1563 * Parms:
1564 * dev Device assigned the IRQ that was
1565 * raised.
1566 * host_int The contents of the HOST_INT
1567 * port.
1568 *
1569 * This function handles the Dummy interrupt, which is
1570 * raised whenever a test interrupt is generated by setting
1571 * the Req_Int bit of HOST_CMD to 1.
1572 *
1573 **************************************************************/
Linus Torvalds1da177e2005-04-16 15:20:36 -07001574
Sakari Ailusc659c382011-01-21 10:59:30 +00001575static u32 tlan_handle_dummy(struct net_device *dev, u16 host_int)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001576{
Joe Perches50624aa2011-03-01 06:56:33 +00001577 netdev_info(dev, "Test interrupt\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001578 return 1;
1579
Sakari Ailusc659c382011-01-21 10:59:30 +00001580}
Linus Torvalds1da177e2005-04-16 15:20:36 -07001581
1582
1583
1584
Sakari Ailusc659c382011-01-21 10:59:30 +00001585/***************************************************************
1586 * tlan_handle_tx_eoc
1587 *
1588 * Returns:
1589 * 1
1590 * Parms:
1591 * dev Device assigned the IRQ that was
1592 * raised.
1593 * host_int The contents of the HOST_INT
1594 * port.
1595 *
1596 * This driver is structured to determine EOC occurrences by
1597 * reading the CSTAT member of the list structure. Tx EOC
1598 * interrupts are disabled via the DIO INTDIS register.
1599 * However, TLAN chips before revision 3.0 didn't have this
1600 * functionality, so process EOC events if this is the
1601 * case.
1602 *
1603 **************************************************************/
Linus Torvalds1da177e2005-04-16 15:20:36 -07001604
Sakari Ailusc659c382011-01-21 10:59:30 +00001605static u32 tlan_handle_tx_eoc(struct net_device *dev, u16 host_int)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001606{
Sakari Ailusc659c382011-01-21 10:59:30 +00001607 struct tlan_priv *priv = netdev_priv(dev);
1608 struct tlan_list *head_list;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001609 dma_addr_t head_list_phys;
1610 u32 ack = 1;
Jeff Garzik6aa20a22006-09-13 13:24:59 -04001611
Linus Torvalds1da177e2005-04-16 15:20:36 -07001612 host_int = 0;
Sakari Ailusc659c382011-01-21 10:59:30 +00001613 if (priv->tlan_rev < 0x30) {
1614 TLAN_DBG(TLAN_DEBUG_TX,
1615 "TRANSMIT: handling TX EOC (Head=%d Tail=%d) -- IRQ\n",
1616 priv->tx_head, priv->tx_tail);
1617 head_list = priv->tx_list + priv->tx_head;
1618 head_list_phys = priv->tx_list_dma
1619 + sizeof(struct tlan_list)*priv->tx_head;
Sakari Ailusf45437e2011-02-09 10:25:06 +00001620 if ((head_list->c_stat & TLAN_CSTAT_READY)
1621 == TLAN_CSTAT_READY) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001622 netif_stop_queue(dev);
Sakari Ailusc659c382011-01-21 10:59:30 +00001623 outl(head_list_phys, dev->base_addr + TLAN_CH_PARM);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001624 ack |= TLAN_HC_GO;
1625 } else {
Sakari Ailusc659c382011-01-21 10:59:30 +00001626 priv->tx_in_progress = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001627 }
1628 }
1629
1630 return ack;
1631
Sakari Ailusc659c382011-01-21 10:59:30 +00001632}
Linus Torvalds1da177e2005-04-16 15:20:36 -07001633
1634
1635
1636
Sakari Ailusc659c382011-01-21 10:59:30 +00001637/***************************************************************
1638 * tlan_handle_status_check
1639 *
1640 * Returns:
1641 * 0 if Adapter check, 1 if Network Status check.
1642 * Parms:
1643 * dev Device assigned the IRQ that was
1644 * raised.
1645 * host_int The contents of the HOST_INT
1646 * port.
1647 *
1648 * This function handles Adapter Check/Network Status
1649 * interrupts generated by the adapter. It checks the
1650 * vector in the HOST_INT register to determine if it is
1651 * an Adapter Check interrupt. If so, it resets the
1652 * adapter. Otherwise it clears the status registers
1653 * and services the PHY.
1654 *
1655 **************************************************************/
Linus Torvalds1da177e2005-04-16 15:20:36 -07001656
Sakari Ailusc659c382011-01-21 10:59:30 +00001657static u32 tlan_handle_status_check(struct net_device *dev, u16 host_int)
Jeff Garzik6aa20a22006-09-13 13:24:59 -04001658{
Sakari Ailusc659c382011-01-21 10:59:30 +00001659 struct tlan_priv *priv = netdev_priv(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001660 u32 ack;
1661 u32 error;
1662 u8 net_sts;
1663 u32 phy;
1664 u16 tlphy_ctl;
1665 u16 tlphy_sts;
Jeff Garzik6aa20a22006-09-13 13:24:59 -04001666
Linus Torvalds1da177e2005-04-16 15:20:36 -07001667 ack = 1;
Sakari Ailusc659c382011-01-21 10:59:30 +00001668 if (host_int & TLAN_HI_IV_MASK) {
1669 netif_stop_queue(dev);
1670 error = inl(dev->base_addr + TLAN_CH_PARM);
Joe Perches50624aa2011-03-01 06:56:33 +00001671 netdev_info(dev, "Adaptor Error = 0x%x\n", error);
Sakari Ailusc659c382011-01-21 10:59:30 +00001672 tlan_read_and_clear_stats(dev, TLAN_RECORD);
1673 outl(TLAN_HC_AD_RST, dev->base_addr + TLAN_HOST_CMD);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001674
1675 schedule_work(&priv->tlan_tqueue);
1676
1677 netif_wake_queue(dev);
1678 ack = 0;
1679 } else {
Sakari Ailusc659c382011-01-21 10:59:30 +00001680 TLAN_DBG(TLAN_DEBUG_GNRL, "%s: Status Check\n", dev->name);
1681 phy = priv->phy[priv->phy_num];
Linus Torvalds1da177e2005-04-16 15:20:36 -07001682
Sakari Ailusc659c382011-01-21 10:59:30 +00001683 net_sts = tlan_dio_read8(dev->base_addr, TLAN_NET_STS);
1684 if (net_sts) {
1685 tlan_dio_write8(dev->base_addr, TLAN_NET_STS, net_sts);
1686 TLAN_DBG(TLAN_DEBUG_GNRL, "%s: Net_Sts = %x\n",
1687 dev->name, (unsigned) net_sts);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001688 }
Sakari Ailusc659c382011-01-21 10:59:30 +00001689 if ((net_sts & TLAN_NET_STS_MIRQ) && (priv->phy_num == 0)) {
1690 tlan_mii_read_reg(dev, phy, TLAN_TLPHY_STS, &tlphy_sts);
1691 tlan_mii_read_reg(dev, phy, TLAN_TLPHY_CTL, &tlphy_ctl);
1692 if (!(tlphy_sts & TLAN_TS_POLOK) &&
1693 !(tlphy_ctl & TLAN_TC_SWAPOL)) {
1694 tlphy_ctl |= TLAN_TC_SWAPOL;
1695 tlan_mii_write_reg(dev, phy, TLAN_TLPHY_CTL,
1696 tlphy_ctl);
1697 } else if ((tlphy_sts & TLAN_TS_POLOK) &&
1698 (tlphy_ctl & TLAN_TC_SWAPOL)) {
1699 tlphy_ctl &= ~TLAN_TC_SWAPOL;
1700 tlan_mii_write_reg(dev, phy, TLAN_TLPHY_CTL,
1701 tlphy_ctl);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001702 }
Sakari Ailusc659c382011-01-21 10:59:30 +00001703
1704 if (debug)
1705 tlan_phy_print(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001706 }
1707 }
1708
1709 return ack;
1710
Sakari Ailusc659c382011-01-21 10:59:30 +00001711}
Linus Torvalds1da177e2005-04-16 15:20:36 -07001712
1713
1714
1715
Sakari Ailusc659c382011-01-21 10:59:30 +00001716/***************************************************************
1717 * tlan_handle_rx_eoc
1718 *
1719 * Returns:
1720 * 1
1721 * Parms:
1722 * dev Device assigned the IRQ that was
1723 * raised.
1724 * host_int The contents of the HOST_INT
1725 * port.
1726 *
1727 * This driver is structured to determine EOC occurrences by
1728 * reading the CSTAT member of the list structure. Rx EOC
1729 * interrupts are disabled via the DIO INTDIS register.
1730 * However, TLAN chips before revision 3.0 didn't have this
1731 * CSTAT member or a INTDIS register, so if this chip is
1732 * pre-3.0, process EOC interrupts normally.
1733 *
1734 **************************************************************/
Linus Torvalds1da177e2005-04-16 15:20:36 -07001735
Sakari Ailusc659c382011-01-21 10:59:30 +00001736static u32 tlan_handle_rx_eoc(struct net_device *dev, u16 host_int)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001737{
Sakari Ailusc659c382011-01-21 10:59:30 +00001738 struct tlan_priv *priv = netdev_priv(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001739 dma_addr_t head_list_phys;
1740 u32 ack = 1;
1741
Sakari Ailusc659c382011-01-21 10:59:30 +00001742 if (priv->tlan_rev < 0x30) {
1743 TLAN_DBG(TLAN_DEBUG_RX,
1744 "RECEIVE: Handling RX EOC (head=%d tail=%d) -- IRQ\n",
1745 priv->rx_head, priv->rx_tail);
1746 head_list_phys = priv->rx_list_dma
1747 + sizeof(struct tlan_list)*priv->rx_head;
1748 outl(head_list_phys, dev->base_addr + TLAN_CH_PARM);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001749 ack |= TLAN_HC_GO | TLAN_HC_RT;
Sakari Ailusc659c382011-01-21 10:59:30 +00001750 priv->rx_eoc_count++;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001751 }
1752
1753 return ack;
1754
Sakari Ailusc659c382011-01-21 10:59:30 +00001755}
Linus Torvalds1da177e2005-04-16 15:20:36 -07001756
1757
1758
1759
1760/*****************************************************************************
1761******************************************************************************
1762
Sakari Ailusc659c382011-01-21 10:59:30 +00001763ThunderLAN driver timer function
Linus Torvalds1da177e2005-04-16 15:20:36 -07001764
1765******************************************************************************
1766*****************************************************************************/
1767
1768
Sakari Ailusc659c382011-01-21 10:59:30 +00001769/***************************************************************
1770 * tlan_timer
1771 *
1772 * Returns:
1773 * Nothing
1774 * Parms:
1775 * data A value given to add timer when
1776 * add_timer was called.
1777 *
1778 * This function handles timed functionality for the
1779 * TLAN driver. The two current timer uses are for
1780 * delaying for autonegotionation and driving the ACT LED.
1781 * - Autonegotiation requires being allowed about
1782 * 2 1/2 seconds before attempting to transmit a
1783 * packet. It would be a very bad thing to hang
1784 * the kernel this long, so the driver doesn't
1785 * allow transmission 'til after this time, for
1786 * certain PHYs. It would be much nicer if all
1787 * PHYs were interrupt-capable like the internal
1788 * PHY.
1789 * - The ACT LED, which shows adapter activity, is
1790 * driven by the driver, and so must be left on
1791 * for a short period to power up the LED so it
1792 * can be seen. This delay can be changed by
1793 * changing the TLAN_TIMER_ACT_DELAY in tlan.h,
1794 * if desired. 100 ms produces a slightly
1795 * sluggish response.
1796 *
1797 **************************************************************/
Linus Torvalds1da177e2005-04-16 15:20:36 -07001798
Sakari Ailusc659c382011-01-21 10:59:30 +00001799static void tlan_timer(unsigned long data)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001800{
1801 struct net_device *dev = (struct net_device *) data;
Sakari Ailusc659c382011-01-21 10:59:30 +00001802 struct tlan_priv *priv = netdev_priv(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001803 u32 elapsed;
1804 unsigned long flags = 0;
1805
1806 priv->timer.function = NULL;
1807
Sakari Ailusc659c382011-01-21 10:59:30 +00001808 switch (priv->timer_type) {
Sakari Ailusc659c382011-01-21 10:59:30 +00001809 case TLAN_TIMER_PHY_PDOWN:
1810 tlan_phy_power_down(dev);
1811 break;
1812 case TLAN_TIMER_PHY_PUP:
1813 tlan_phy_power_up(dev);
1814 break;
1815 case TLAN_TIMER_PHY_RESET:
1816 tlan_phy_reset(dev);
1817 break;
1818 case TLAN_TIMER_PHY_START_LINK:
1819 tlan_phy_start_link(dev);
1820 break;
1821 case TLAN_TIMER_PHY_FINISH_AN:
1822 tlan_phy_finish_auto_neg(dev);
1823 break;
1824 case TLAN_TIMER_FINISH_RESET:
1825 tlan_finish_reset(dev);
1826 break;
1827 case TLAN_TIMER_ACTIVITY:
1828 spin_lock_irqsave(&priv->lock, flags);
1829 if (priv->timer.function == NULL) {
1830 elapsed = jiffies - priv->timer_set_at;
1831 if (elapsed >= TLAN_TIMER_ACT_DELAY) {
1832 tlan_dio_write8(dev->base_addr,
1833 TLAN_LED_REG, TLAN_LED_LINK);
1834 } else {
1835 priv->timer.function = tlan_timer;
1836 priv->timer.expires = priv->timer_set_at
1837 + TLAN_TIMER_ACT_DELAY;
1838 spin_unlock_irqrestore(&priv->lock, flags);
1839 add_timer(&priv->timer);
1840 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001841 }
Sakari Ailusc659c382011-01-21 10:59:30 +00001842 }
1843 spin_unlock_irqrestore(&priv->lock, flags);
1844 break;
1845 default:
1846 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001847 }
1848
Sakari Ailusc659c382011-01-21 10:59:30 +00001849}
Linus Torvalds1da177e2005-04-16 15:20:36 -07001850
1851
Linus Torvalds1da177e2005-04-16 15:20:36 -07001852/*****************************************************************************
1853******************************************************************************
1854
Sakari Ailusc659c382011-01-21 10:59:30 +00001855ThunderLAN driver adapter related routines
Linus Torvalds1da177e2005-04-16 15:20:36 -07001856
1857******************************************************************************
1858*****************************************************************************/
1859
1860
Sakari Ailusc659c382011-01-21 10:59:30 +00001861/***************************************************************
1862 * tlan_reset_lists
1863 *
1864 * Returns:
1865 * Nothing
1866 * Parms:
1867 * dev The device structure with the list
1868 * stuctures to be reset.
1869 *
1870 * This routine sets the variables associated with managing
1871 * the TLAN lists to their initial values.
1872 *
1873 **************************************************************/
Linus Torvalds1da177e2005-04-16 15:20:36 -07001874
Sakari Ailusc659c382011-01-21 10:59:30 +00001875static void tlan_reset_lists(struct net_device *dev)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001876{
Sakari Ailusc659c382011-01-21 10:59:30 +00001877 struct tlan_priv *priv = netdev_priv(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001878 int i;
Sakari Ailusc659c382011-01-21 10:59:30 +00001879 struct tlan_list *list;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001880 dma_addr_t list_phys;
1881 struct sk_buff *skb;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001882
Sakari Ailusc659c382011-01-21 10:59:30 +00001883 priv->tx_head = 0;
1884 priv->tx_tail = 0;
1885 for (i = 0; i < TLAN_NUM_TX_LISTS; i++) {
1886 list = priv->tx_list + i;
1887 list->c_stat = TLAN_CSTAT_UNUSED;
Sakari Ailus5eeabf52008-12-16 15:24:05 -08001888 list->buffer[0].address = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001889 list->buffer[2].count = 0;
1890 list->buffer[2].address = 0;
1891 list->buffer[8].address = 0;
1892 list->buffer[9].address = 0;
1893 }
1894
Sakari Ailusc659c382011-01-21 10:59:30 +00001895 priv->rx_head = 0;
1896 priv->rx_tail = TLAN_NUM_RX_LISTS - 1;
1897 for (i = 0; i < TLAN_NUM_RX_LISTS; i++) {
1898 list = priv->rx_list + i;
1899 list_phys = priv->rx_list_dma + sizeof(struct tlan_list)*i;
1900 list->c_stat = TLAN_CSTAT_READY;
1901 list->frame_size = TLAN_MAX_FRAME_SIZE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001902 list->buffer[0].count = TLAN_MAX_FRAME_SIZE | TLAN_LAST_BUFFER;
Eric Dumazet89d71a62009-10-13 05:34:20 +00001903 skb = netdev_alloc_skb_ip_align(dev, TLAN_MAX_FRAME_SIZE + 5);
Joe Perches720a43e2013-03-08 15:03:25 +00001904 if (!skb)
Sakari Ailus5eeabf52008-12-16 15:24:05 -08001905 break;
Sakari Ailus5eeabf52008-12-16 15:24:05 -08001906
Sakari Ailusc659c382011-01-21 10:59:30 +00001907 list->buffer[0].address = pci_map_single(priv->pci_dev,
Sakari Ailus5eeabf52008-12-16 15:24:05 -08001908 skb->data,
1909 TLAN_MAX_FRAME_SIZE,
1910 PCI_DMA_FROMDEVICE);
Sakari Ailusc659c382011-01-21 10:59:30 +00001911 tlan_store_skb(list, skb);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001912 list->buffer[1].count = 0;
1913 list->buffer[1].address = 0;
Sakari Ailusc659c382011-01-21 10:59:30 +00001914 list->forward = list_phys + sizeof(struct tlan_list);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001915 }
1916
Stephen Hemminger9ded65a2008-05-30 09:49:56 -07001917 /* in case ran out of memory early, clear bits */
1918 while (i < TLAN_NUM_RX_LISTS) {
Sakari Ailusc659c382011-01-21 10:59:30 +00001919 tlan_store_skb(priv->rx_list + i, NULL);
Stephen Hemminger9ded65a2008-05-30 09:49:56 -07001920 ++i;
1921 }
1922 list->forward = 0;
1923
Sakari Ailusc659c382011-01-21 10:59:30 +00001924}
Linus Torvalds1da177e2005-04-16 15:20:36 -07001925
1926
Sakari Ailusc659c382011-01-21 10:59:30 +00001927static void tlan_free_lists(struct net_device *dev)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001928{
Sakari Ailusc659c382011-01-21 10:59:30 +00001929 struct tlan_priv *priv = netdev_priv(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001930 int i;
Sakari Ailusc659c382011-01-21 10:59:30 +00001931 struct tlan_list *list;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001932 struct sk_buff *skb;
1933
Sakari Ailusc659c382011-01-21 10:59:30 +00001934 for (i = 0; i < TLAN_NUM_TX_LISTS; i++) {
1935 list = priv->tx_list + i;
1936 skb = tlan_get_skb(list);
1937 if (skb) {
Sakari Ailus5eeabf52008-12-16 15:24:05 -08001938 pci_unmap_single(
Sakari Ailusc659c382011-01-21 10:59:30 +00001939 priv->pci_dev,
Sakari Ailus5eeabf52008-12-16 15:24:05 -08001940 list->buffer[0].address,
1941 max(skb->len,
1942 (unsigned int)TLAN_MIN_FRAME_SIZE),
1943 PCI_DMA_TODEVICE);
Sakari Ailusc659c382011-01-21 10:59:30 +00001944 dev_kfree_skb_any(skb);
Sakari Ailus5eeabf52008-12-16 15:24:05 -08001945 list->buffer[8].address = 0;
1946 list->buffer[9].address = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001947 }
Sakari Ailus5eeabf52008-12-16 15:24:05 -08001948 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001949
Sakari Ailusc659c382011-01-21 10:59:30 +00001950 for (i = 0; i < TLAN_NUM_RX_LISTS; i++) {
1951 list = priv->rx_list + i;
1952 skb = tlan_get_skb(list);
1953 if (skb) {
1954 pci_unmap_single(priv->pci_dev,
Sakari Ailus5eeabf52008-12-16 15:24:05 -08001955 list->buffer[0].address,
1956 TLAN_MAX_FRAME_SIZE,
1957 PCI_DMA_FROMDEVICE);
Sakari Ailusc659c382011-01-21 10:59:30 +00001958 dev_kfree_skb_any(skb);
Sakari Ailus5eeabf52008-12-16 15:24:05 -08001959 list->buffer[8].address = 0;
1960 list->buffer[9].address = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001961 }
1962 }
Sakari Ailusc659c382011-01-21 10:59:30 +00001963}
Linus Torvalds1da177e2005-04-16 15:20:36 -07001964
1965
1966
1967
Sakari Ailusc659c382011-01-21 10:59:30 +00001968/***************************************************************
1969 * tlan_print_dio
1970 *
1971 * Returns:
1972 * Nothing
1973 * Parms:
1974 * io_base Base IO port of the device of
1975 * which to print DIO registers.
1976 *
1977 * This function prints out all the internal (DIO)
1978 * registers of a TLAN chip.
1979 *
1980 **************************************************************/
Linus Torvalds1da177e2005-04-16 15:20:36 -07001981
Sakari Ailusc659c382011-01-21 10:59:30 +00001982static void tlan_print_dio(u16 io_base)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001983{
1984 u32 data0, data1;
1985 int i;
1986
Joe Perches50624aa2011-03-01 06:56:33 +00001987 pr_info("Contents of internal registers for io base 0x%04hx\n",
1988 io_base);
1989 pr_info("Off. +0 +4\n");
Sakari Ailusc659c382011-01-21 10:59:30 +00001990 for (i = 0; i < 0x4C; i += 8) {
1991 data0 = tlan_dio_read32(io_base, i);
1992 data1 = tlan_dio_read32(io_base, i + 0x4);
Joe Perches50624aa2011-03-01 06:56:33 +00001993 pr_info("0x%02x 0x%08x 0x%08x\n", i, data0, data1);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001994 }
1995
Sakari Ailusc659c382011-01-21 10:59:30 +00001996}
Linus Torvalds1da177e2005-04-16 15:20:36 -07001997
1998
1999
2000
Sakari Ailusc659c382011-01-21 10:59:30 +00002001/***************************************************************
2002 * TLan_PrintList
2003 *
2004 * Returns:
2005 * Nothing
2006 * Parms:
2007 * list A pointer to the struct tlan_list structure to
2008 * be printed.
2009 * type A string to designate type of list,
2010 * "Rx" or "Tx".
2011 * num The index of the list.
2012 *
2013 * This function prints out the contents of the list
2014 * pointed to by the list parameter.
2015 *
2016 **************************************************************/
Linus Torvalds1da177e2005-04-16 15:20:36 -07002017
Sakari Ailusc659c382011-01-21 10:59:30 +00002018static void tlan_print_list(struct tlan_list *list, char *type, int num)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002019{
2020 int i;
2021
Joe Perches50624aa2011-03-01 06:56:33 +00002022 pr_info("%s List %d at %p\n", type, num, list);
2023 pr_info(" Forward = 0x%08x\n", list->forward);
2024 pr_info(" CSTAT = 0x%04hx\n", list->c_stat);
2025 pr_info(" Frame Size = 0x%04hx\n", list->frame_size);
Sakari Ailusc659c382011-01-21 10:59:30 +00002026 /* for (i = 0; i < 10; i++) { */
2027 for (i = 0; i < 2; i++) {
Joe Perches50624aa2011-03-01 06:56:33 +00002028 pr_info(" Buffer[%d].count, addr = 0x%08x, 0x%08x\n",
2029 i, list->buffer[i].count, list->buffer[i].address);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002030 }
2031
Sakari Ailusc659c382011-01-21 10:59:30 +00002032}
Linus Torvalds1da177e2005-04-16 15:20:36 -07002033
2034
2035
2036
Sakari Ailusc659c382011-01-21 10:59:30 +00002037/***************************************************************
2038 * tlan_read_and_clear_stats
2039 *
2040 * Returns:
2041 * Nothing
2042 * Parms:
2043 * dev Pointer to device structure of adapter
2044 * to which to read stats.
2045 * record Flag indicating whether to add
2046 *
2047 * This functions reads all the internal status registers
2048 * of the TLAN chip, which clears them as a side effect.
2049 * It then either adds the values to the device's status
2050 * struct, or discards them, depending on whether record
2051 * is TLAN_RECORD (!=0) or TLAN_IGNORE (==0).
2052 *
2053 **************************************************************/
Linus Torvalds1da177e2005-04-16 15:20:36 -07002054
Sakari Ailusc659c382011-01-21 10:59:30 +00002055static void tlan_read_and_clear_stats(struct net_device *dev, int record)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002056{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002057 u32 tx_good, tx_under;
2058 u32 rx_good, rx_over;
2059 u32 def_tx, crc, code;
2060 u32 multi_col, single_col;
2061 u32 excess_col, late_col, loss;
2062
Sakari Ailusc659c382011-01-21 10:59:30 +00002063 outw(TLAN_GOOD_TX_FRMS, dev->base_addr + TLAN_DIO_ADR);
2064 tx_good = inb(dev->base_addr + TLAN_DIO_DATA);
2065 tx_good += inb(dev->base_addr + TLAN_DIO_DATA + 1) << 8;
2066 tx_good += inb(dev->base_addr + TLAN_DIO_DATA + 2) << 16;
2067 tx_under = inb(dev->base_addr + TLAN_DIO_DATA + 3);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002068
Sakari Ailusc659c382011-01-21 10:59:30 +00002069 outw(TLAN_GOOD_RX_FRMS, dev->base_addr + TLAN_DIO_ADR);
2070 rx_good = inb(dev->base_addr + TLAN_DIO_DATA);
2071 rx_good += inb(dev->base_addr + TLAN_DIO_DATA + 1) << 8;
2072 rx_good += inb(dev->base_addr + TLAN_DIO_DATA + 2) << 16;
2073 rx_over = inb(dev->base_addr + TLAN_DIO_DATA + 3);
Jeff Garzik6aa20a22006-09-13 13:24:59 -04002074
Sakari Ailusc659c382011-01-21 10:59:30 +00002075 outw(TLAN_DEFERRED_TX, dev->base_addr + TLAN_DIO_ADR);
2076 def_tx = inb(dev->base_addr + TLAN_DIO_DATA);
2077 def_tx += inb(dev->base_addr + TLAN_DIO_DATA + 1) << 8;
2078 crc = inb(dev->base_addr + TLAN_DIO_DATA + 2);
2079 code = inb(dev->base_addr + TLAN_DIO_DATA + 3);
Jeff Garzik6aa20a22006-09-13 13:24:59 -04002080
Sakari Ailusc659c382011-01-21 10:59:30 +00002081 outw(TLAN_MULTICOL_FRMS, dev->base_addr + TLAN_DIO_ADR);
2082 multi_col = inb(dev->base_addr + TLAN_DIO_DATA);
2083 multi_col += inb(dev->base_addr + TLAN_DIO_DATA + 1) << 8;
2084 single_col = inb(dev->base_addr + TLAN_DIO_DATA + 2);
2085 single_col += inb(dev->base_addr + TLAN_DIO_DATA + 3) << 8;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002086
Sakari Ailusc659c382011-01-21 10:59:30 +00002087 outw(TLAN_EXCESSCOL_FRMS, dev->base_addr + TLAN_DIO_ADR);
2088 excess_col = inb(dev->base_addr + TLAN_DIO_DATA);
2089 late_col = inb(dev->base_addr + TLAN_DIO_DATA + 1);
2090 loss = inb(dev->base_addr + TLAN_DIO_DATA + 2);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002091
Sakari Ailusc659c382011-01-21 10:59:30 +00002092 if (record) {
Stephen Hemmingerf8f31542008-05-30 09:49:53 -07002093 dev->stats.rx_packets += rx_good;
2094 dev->stats.rx_errors += rx_over + crc + code;
2095 dev->stats.tx_packets += tx_good;
2096 dev->stats.tx_errors += tx_under + loss;
Sakari Ailusc659c382011-01-21 10:59:30 +00002097 dev->stats.collisions += multi_col
2098 + single_col + excess_col + late_col;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002099
Stephen Hemmingerf8f31542008-05-30 09:49:53 -07002100 dev->stats.rx_over_errors += rx_over;
2101 dev->stats.rx_crc_errors += crc;
2102 dev->stats.rx_frame_errors += code;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002103
Stephen Hemmingerf8f31542008-05-30 09:49:53 -07002104 dev->stats.tx_aborted_errors += tx_under;
2105 dev->stats.tx_carrier_errors += loss;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002106 }
Jeff Garzik6aa20a22006-09-13 13:24:59 -04002107
Sakari Ailusc659c382011-01-21 10:59:30 +00002108}
Linus Torvalds1da177e2005-04-16 15:20:36 -07002109
2110
2111
2112
Sakari Ailusc659c382011-01-21 10:59:30 +00002113/***************************************************************
2114 * TLan_Reset
2115 *
2116 * Returns:
2117 * 0
2118 * Parms:
2119 * dev Pointer to device structure of adapter
2120 * to be reset.
2121 *
2122 * This function resets the adapter and it's physical
2123 * device. See Chap. 3, pp. 9-10 of the "ThunderLAN
2124 * Programmer's Guide" for details. The routine tries to
2125 * implement what is detailed there, though adjustments
2126 * have been made.
2127 *
2128 **************************************************************/
Linus Torvalds1da177e2005-04-16 15:20:36 -07002129
Harvey Harrison98e0f522008-02-18 10:04:38 -08002130static void
Sakari Ailusc659c382011-01-21 10:59:30 +00002131tlan_reset_adapter(struct net_device *dev)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002132{
Sakari Ailusc659c382011-01-21 10:59:30 +00002133 struct tlan_priv *priv = netdev_priv(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002134 int i;
2135 u32 addr;
2136 u32 data;
2137 u8 data8;
2138
Sakari Ailusc659c382011-01-21 10:59:30 +00002139 priv->tlan_full_duplex = false;
2140 priv->phy_online = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002141 netif_carrier_off(dev);
2142
2143/* 1. Assert reset bit. */
2144
2145 data = inl(dev->base_addr + TLAN_HOST_CMD);
2146 data |= TLAN_HC_AD_RST;
2147 outl(data, dev->base_addr + TLAN_HOST_CMD);
Jeff Garzik6aa20a22006-09-13 13:24:59 -04002148
Linus Torvalds1da177e2005-04-16 15:20:36 -07002149 udelay(1000);
2150
Sakari Ailusc659c382011-01-21 10:59:30 +00002151/* 2. Turn off interrupts. (Probably isn't necessary) */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002152
2153 data = inl(dev->base_addr + TLAN_HOST_CMD);
2154 data |= TLAN_HC_INT_OFF;
2155 outl(data, dev->base_addr + TLAN_HOST_CMD);
2156
2157/* 3. Clear AREGs and HASHs. */
2158
Sakari Ailusc659c382011-01-21 10:59:30 +00002159 for (i = TLAN_AREG_0; i <= TLAN_HASH_2; i += 4)
2160 tlan_dio_write32(dev->base_addr, (u16) i, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002161
2162/* 4. Setup NetConfig register. */
2163
2164 data = TLAN_NET_CFG_1FRAG | TLAN_NET_CFG_1CHAN | TLAN_NET_CFG_PHY_EN;
Sakari Ailusc659c382011-01-21 10:59:30 +00002165 tlan_dio_write16(dev->base_addr, TLAN_NET_CONFIG, (u16) data);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002166
2167/* 5. Load Ld_Tmr and Ld_Thr in HOST_CMD. */
2168
Sakari Ailusc659c382011-01-21 10:59:30 +00002169 outl(TLAN_HC_LD_TMR | 0x3f, dev->base_addr + TLAN_HOST_CMD);
2170 outl(TLAN_HC_LD_THR | 0x9, dev->base_addr + TLAN_HOST_CMD);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002171
2172/* 6. Unreset the MII by setting NMRST (in NetSio) to 1. */
2173
Sakari Ailusc659c382011-01-21 10:59:30 +00002174 outw(TLAN_NET_SIO, dev->base_addr + TLAN_DIO_ADR);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002175 addr = dev->base_addr + TLAN_DIO_DATA + TLAN_NET_SIO;
Sakari Ailusc659c382011-01-21 10:59:30 +00002176 tlan_set_bit(TLAN_NET_SIO_NMRST, addr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002177
2178/* 7. Setup the remaining registers. */
2179
Sakari Ailusc659c382011-01-21 10:59:30 +00002180 if (priv->tlan_rev >= 0x30) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002181 data8 = TLAN_ID_TX_EOC | TLAN_ID_RX_EOC;
Sakari Ailusc659c382011-01-21 10:59:30 +00002182 tlan_dio_write8(dev->base_addr, TLAN_INT_DIS, data8);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002183 }
Sakari Ailusc659c382011-01-21 10:59:30 +00002184 tlan_phy_detect(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002185 data = TLAN_NET_CFG_1FRAG | TLAN_NET_CFG_1CHAN;
Jeff Garzik6aa20a22006-09-13 13:24:59 -04002186
Sakari Ailusc659c382011-01-21 10:59:30 +00002187 if (priv->adapter->flags & TLAN_ADAPTER_BIT_RATE_PHY) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002188 data |= TLAN_NET_CFG_BIT;
Sakari Ailusc659c382011-01-21 10:59:30 +00002189 if (priv->aui == 1) {
2190 tlan_dio_write8(dev->base_addr, TLAN_ACOMMIT, 0x0a);
2191 } else if (priv->duplex == TLAN_DUPLEX_FULL) {
2192 tlan_dio_write8(dev->base_addr, TLAN_ACOMMIT, 0x00);
2193 priv->tlan_full_duplex = true;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002194 } else {
Sakari Ailusc659c382011-01-21 10:59:30 +00002195 tlan_dio_write8(dev->base_addr, TLAN_ACOMMIT, 0x08);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002196 }
2197 }
2198
Sakari Ailusc659c382011-01-21 10:59:30 +00002199 if (priv->phy_num == 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002200 data |= TLAN_NET_CFG_PHY_EN;
Sakari Ailusc659c382011-01-21 10:59:30 +00002201 tlan_dio_write16(dev->base_addr, TLAN_NET_CONFIG, (u16) data);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002202
Sakari Ailusc659c382011-01-21 10:59:30 +00002203 if (priv->adapter->flags & TLAN_ADAPTER_UNMANAGED_PHY)
2204 tlan_finish_reset(dev);
2205 else
2206 tlan_phy_power_down(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002207
Sakari Ailusc659c382011-01-21 10:59:30 +00002208}
Linus Torvalds1da177e2005-04-16 15:20:36 -07002209
2210
2211
2212
Harvey Harrison98e0f522008-02-18 10:04:38 -08002213static void
Sakari Ailusc659c382011-01-21 10:59:30 +00002214tlan_finish_reset(struct net_device *dev)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002215{
Sakari Ailusc659c382011-01-21 10:59:30 +00002216 struct tlan_priv *priv = netdev_priv(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002217 u8 data;
2218 u32 phy;
2219 u8 sio;
2220 u16 status;
2221 u16 partner;
2222 u16 tlphy_ctl;
Sakari Ailusc659c382011-01-21 10:59:30 +00002223 u16 tlphy_par;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002224 u16 tlphy_id1, tlphy_id2;
Sakari Ailusc659c382011-01-21 10:59:30 +00002225 int i;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002226
Sakari Ailusc659c382011-01-21 10:59:30 +00002227 phy = priv->phy[priv->phy_num];
Linus Torvalds1da177e2005-04-16 15:20:36 -07002228
2229 data = TLAN_NET_CMD_NRESET | TLAN_NET_CMD_NWRAP;
Sakari Ailusc659c382011-01-21 10:59:30 +00002230 if (priv->tlan_full_duplex)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002231 data |= TLAN_NET_CMD_DUPLEX;
Sakari Ailusc659c382011-01-21 10:59:30 +00002232 tlan_dio_write8(dev->base_addr, TLAN_NET_CMD, data);
Jeff Garzik6aa20a22006-09-13 13:24:59 -04002233 data = TLAN_NET_MASK_MASK4 | TLAN_NET_MASK_MASK5;
Sakari Ailusc659c382011-01-21 10:59:30 +00002234 if (priv->phy_num == 0)
Jeff Garzik6aa20a22006-09-13 13:24:59 -04002235 data |= TLAN_NET_MASK_MASK7;
Sakari Ailusc659c382011-01-21 10:59:30 +00002236 tlan_dio_write8(dev->base_addr, TLAN_NET_MASK, data);
2237 tlan_dio_write16(dev->base_addr, TLAN_MAX_RX, ((1536)+7)&~7);
2238 tlan_mii_read_reg(dev, phy, MII_GEN_ID_HI, &tlphy_id1);
2239 tlan_mii_read_reg(dev, phy, MII_GEN_ID_LO, &tlphy_id2);
Jeff Garzik6aa20a22006-09-13 13:24:59 -04002240
Sakari Ailusc659c382011-01-21 10:59:30 +00002241 if ((priv->adapter->flags & TLAN_ADAPTER_UNMANAGED_PHY) ||
2242 (priv->aui)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002243 status = MII_GS_LINK;
Joe Perches50624aa2011-03-01 06:56:33 +00002244 netdev_info(dev, "Link forced\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002245 } else {
Sakari Ailusc659c382011-01-21 10:59:30 +00002246 tlan_mii_read_reg(dev, phy, MII_GEN_STS, &status);
2247 udelay(1000);
2248 tlan_mii_read_reg(dev, phy, MII_GEN_STS, &status);
Ondrej Zaryc0a87c22014-06-30 18:38:28 +02002249 if (status & MII_GS_LINK) {
2250 /* We only support link info on Nat.Sem. PHY's */
2251 if ((tlphy_id1 == NAT_SEM_ID1) &&
2252 (tlphy_id2 == NAT_SEM_ID2)) {
2253 tlan_mii_read_reg(dev, phy, MII_AN_LPA,
2254 &partner);
2255 tlan_mii_read_reg(dev, phy, TLAN_TLPHY_PAR,
2256 &tlphy_par);
Jeff Garzik6aa20a22006-09-13 13:24:59 -04002257
Ondrej Zaryc0a87c22014-06-30 18:38:28 +02002258 netdev_info(dev,
2259 "Link active, %s %uMbps %s-Duplex\n",
2260 !(tlphy_par & TLAN_PHY_AN_EN_STAT)
2261 ? "forced" : "Autonegotiation enabled,",
2262 tlphy_par & TLAN_PHY_SPEED_100
2263 ? 100 : 10,
2264 tlphy_par & TLAN_PHY_DUPLEX_FULL
2265 ? "Full" : "Half");
Joe Perches50624aa2011-03-01 06:56:33 +00002266
Ondrej Zaryc0a87c22014-06-30 18:38:28 +02002267 if (tlphy_par & TLAN_PHY_AN_EN_STAT) {
2268 netdev_info(dev, "Partner capability:");
2269 for (i = 5; i < 10; i++)
2270 if (partner & (1 << i))
2271 pr_cont(" %s",
2272 media[i-5]);
2273 pr_cont("\n");
2274 }
2275 } else
2276 netdev_info(dev, "Link active\n");
2277 /* Enabling link beat monitoring */
2278 priv->media_timer.function = tlan_phy_monitor;
2279 priv->media_timer.data = (unsigned long) dev;
2280 priv->media_timer.expires = jiffies + HZ;
2281 add_timer(&priv->media_timer);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002282 }
2283 }
2284
Sakari Ailusc659c382011-01-21 10:59:30 +00002285 if (priv->phy_num == 0) {
2286 tlan_mii_read_reg(dev, phy, TLAN_TLPHY_CTL, &tlphy_ctl);
2287 tlphy_ctl |= TLAN_TC_INTEN;
2288 tlan_mii_write_reg(dev, phy, TLAN_TLPHY_CTL, tlphy_ctl);
2289 sio = tlan_dio_read8(dev->base_addr, TLAN_NET_SIO);
2290 sio |= TLAN_NET_SIO_MINTEN;
2291 tlan_dio_write8(dev->base_addr, TLAN_NET_SIO, sio);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002292 }
2293
Sakari Ailusc659c382011-01-21 10:59:30 +00002294 if (status & MII_GS_LINK) {
2295 tlan_set_mac(dev, 0, dev->dev_addr);
2296 priv->phy_online = 1;
2297 outb((TLAN_HC_INT_ON >> 8), dev->base_addr + TLAN_HOST_CMD + 1);
2298 if (debug >= 1 && debug != TLAN_DEBUG_PROBE)
2299 outb((TLAN_HC_REQ_INT >> 8),
2300 dev->base_addr + TLAN_HOST_CMD + 1);
2301 outl(priv->rx_list_dma, dev->base_addr + TLAN_CH_PARM);
2302 outl(TLAN_HC_GO | TLAN_HC_RT, dev->base_addr + TLAN_HOST_CMD);
Ondrej Zaryc0a87c22014-06-30 18:38:28 +02002303 tlan_dio_write8(dev->base_addr, TLAN_LED_REG, TLAN_LED_LINK);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002304 netif_carrier_on(dev);
2305 } else {
Joe Perches50624aa2011-03-01 06:56:33 +00002306 netdev_info(dev, "Link inactive, will retry in 10 secs...\n");
Sakari Ailusc659c382011-01-21 10:59:30 +00002307 tlan_set_timer(dev, (10*HZ), TLAN_TIMER_FINISH_RESET);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002308 return;
2309 }
Sakari Ailusc659c382011-01-21 10:59:30 +00002310 tlan_set_multicast_list(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002311
Sakari Ailusc659c382011-01-21 10:59:30 +00002312}
Linus Torvalds1da177e2005-04-16 15:20:36 -07002313
2314
2315
2316
Sakari Ailusc659c382011-01-21 10:59:30 +00002317/***************************************************************
2318 * tlan_set_mac
2319 *
2320 * Returns:
2321 * Nothing
2322 * Parms:
2323 * dev Pointer to device structure of adapter
2324 * on which to change the AREG.
2325 * areg The AREG to set the address in (0 - 3).
2326 * mac A pointer to an array of chars. Each
2327 * element stores one byte of the address.
2328 * IE, it isn't in ascii.
2329 *
2330 * This function transfers a MAC address to one of the
2331 * TLAN AREGs (address registers). The TLAN chip locks
2332 * the register on writing to offset 0 and unlocks the
2333 * register after writing to offset 5. If NULL is passed
2334 * in mac, then the AREG is filled with 0's.
2335 *
2336 **************************************************************/
Linus Torvalds1da177e2005-04-16 15:20:36 -07002337
Sakari Ailusc659c382011-01-21 10:59:30 +00002338static void tlan_set_mac(struct net_device *dev, int areg, char *mac)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002339{
2340 int i;
Jeff Garzik6aa20a22006-09-13 13:24:59 -04002341
Linus Torvalds1da177e2005-04-16 15:20:36 -07002342 areg *= 6;
2343
Sakari Ailusc659c382011-01-21 10:59:30 +00002344 if (mac != NULL) {
2345 for (i = 0; i < 6; i++)
2346 tlan_dio_write8(dev->base_addr,
2347 TLAN_AREG_0 + areg + i, mac[i]);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002348 } else {
Sakari Ailusc659c382011-01-21 10:59:30 +00002349 for (i = 0; i < 6; i++)
2350 tlan_dio_write8(dev->base_addr,
2351 TLAN_AREG_0 + areg + i, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002352 }
2353
Sakari Ailusc659c382011-01-21 10:59:30 +00002354}
Linus Torvalds1da177e2005-04-16 15:20:36 -07002355
2356
2357
2358
2359/*****************************************************************************
2360******************************************************************************
2361
Sakari Ailusc659c382011-01-21 10:59:30 +00002362ThunderLAN driver PHY layer routines
Linus Torvalds1da177e2005-04-16 15:20:36 -07002363
2364******************************************************************************
2365*****************************************************************************/
2366
2367
2368
Sakari Ailusc659c382011-01-21 10:59:30 +00002369/*********************************************************************
2370 * tlan_phy_print
2371 *
2372 * Returns:
2373 * Nothing
2374 * Parms:
2375 * dev A pointer to the device structure of the
2376 * TLAN device having the PHYs to be detailed.
2377 *
2378 * This function prints the registers a PHY (aka transceiver).
2379 *
2380 ********************************************************************/
Linus Torvalds1da177e2005-04-16 15:20:36 -07002381
Sakari Ailusc659c382011-01-21 10:59:30 +00002382static void tlan_phy_print(struct net_device *dev)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002383{
Sakari Ailusc659c382011-01-21 10:59:30 +00002384 struct tlan_priv *priv = netdev_priv(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002385 u16 i, data0, data1, data2, data3, phy;
2386
Sakari Ailusc659c382011-01-21 10:59:30 +00002387 phy = priv->phy[priv->phy_num];
Linus Torvalds1da177e2005-04-16 15:20:36 -07002388
Sakari Ailusc659c382011-01-21 10:59:30 +00002389 if (priv->adapter->flags & TLAN_ADAPTER_UNMANAGED_PHY) {
Joe Perches50624aa2011-03-01 06:56:33 +00002390 netdev_info(dev, "Unmanaged PHY\n");
Sakari Ailusc659c382011-01-21 10:59:30 +00002391 } else if (phy <= TLAN_PHY_MAX_ADDR) {
Joe Perches50624aa2011-03-01 06:56:33 +00002392 netdev_info(dev, "PHY 0x%02x\n", phy);
2393 pr_info(" Off. +0 +1 +2 +3\n");
Sakari Ailusc659c382011-01-21 10:59:30 +00002394 for (i = 0; i < 0x20; i += 4) {
Sakari Ailusc659c382011-01-21 10:59:30 +00002395 tlan_mii_read_reg(dev, phy, i, &data0);
Sakari Ailusc659c382011-01-21 10:59:30 +00002396 tlan_mii_read_reg(dev, phy, i + 1, &data1);
Sakari Ailusc659c382011-01-21 10:59:30 +00002397 tlan_mii_read_reg(dev, phy, i + 2, &data2);
Sakari Ailusc659c382011-01-21 10:59:30 +00002398 tlan_mii_read_reg(dev, phy, i + 3, &data3);
Joe Perches50624aa2011-03-01 06:56:33 +00002399 pr_info(" 0x%02x 0x%04hx 0x%04hx 0x%04hx 0x%04hx\n",
2400 i, data0, data1, data2, data3);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002401 }
2402 } else {
Joe Perches50624aa2011-03-01 06:56:33 +00002403 netdev_info(dev, "Invalid PHY\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002404 }
2405
Sakari Ailusc659c382011-01-21 10:59:30 +00002406}
Linus Torvalds1da177e2005-04-16 15:20:36 -07002407
2408
2409
2410
Sakari Ailusc659c382011-01-21 10:59:30 +00002411/*********************************************************************
2412 * tlan_phy_detect
2413 *
2414 * Returns:
2415 * Nothing
2416 * Parms:
2417 * dev A pointer to the device structure of the adapter
2418 * for which the PHY needs determined.
2419 *
2420 * So far I've found that adapters which have external PHYs
2421 * may also use the internal PHY for part of the functionality.
2422 * (eg, AUI/Thinnet). This function finds out if this TLAN
2423 * chip has an internal PHY, and then finds the first external
2424 * PHY (starting from address 0) if it exists).
2425 *
2426 ********************************************************************/
Linus Torvalds1da177e2005-04-16 15:20:36 -07002427
Sakari Ailusc659c382011-01-21 10:59:30 +00002428static void tlan_phy_detect(struct net_device *dev)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002429{
Sakari Ailusc659c382011-01-21 10:59:30 +00002430 struct tlan_priv *priv = netdev_priv(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002431 u16 control;
2432 u16 hi;
2433 u16 lo;
2434 u32 phy;
2435
Sakari Ailusc659c382011-01-21 10:59:30 +00002436 if (priv->adapter->flags & TLAN_ADAPTER_UNMANAGED_PHY) {
2437 priv->phy_num = 0xffff;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002438 return;
2439 }
2440
Sakari Ailusc659c382011-01-21 10:59:30 +00002441 tlan_mii_read_reg(dev, TLAN_PHY_MAX_ADDR, MII_GEN_ID_HI, &hi);
Jeff Garzik6aa20a22006-09-13 13:24:59 -04002442
Sakari Ailusc659c382011-01-21 10:59:30 +00002443 if (hi != 0xffff)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002444 priv->phy[0] = TLAN_PHY_MAX_ADDR;
Sakari Ailusc659c382011-01-21 10:59:30 +00002445 else
Linus Torvalds1da177e2005-04-16 15:20:36 -07002446 priv->phy[0] = TLAN_PHY_NONE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002447
2448 priv->phy[1] = TLAN_PHY_NONE;
Sakari Ailusc659c382011-01-21 10:59:30 +00002449 for (phy = 0; phy <= TLAN_PHY_MAX_ADDR; phy++) {
2450 tlan_mii_read_reg(dev, phy, MII_GEN_CTL, &control);
2451 tlan_mii_read_reg(dev, phy, MII_GEN_ID_HI, &hi);
2452 tlan_mii_read_reg(dev, phy, MII_GEN_ID_LO, &lo);
2453 if ((control != 0xffff) ||
2454 (hi != 0xffff) || (lo != 0xffff)) {
2455 TLAN_DBG(TLAN_DEBUG_GNRL,
2456 "PHY found at %02x %04x %04x %04x\n",
2457 phy, control, hi, lo);
2458 if ((priv->phy[1] == TLAN_PHY_NONE) &&
2459 (phy != TLAN_PHY_MAX_ADDR)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002460 priv->phy[1] = phy;
2461 }
2462 }
2463 }
2464
Sakari Ailusc659c382011-01-21 10:59:30 +00002465 if (priv->phy[1] != TLAN_PHY_NONE)
2466 priv->phy_num = 1;
2467 else if (priv->phy[0] != TLAN_PHY_NONE)
2468 priv->phy_num = 0;
2469 else
Joe Perches50624aa2011-03-01 06:56:33 +00002470 netdev_info(dev, "Cannot initialize device, no PHY was found!\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002471
Sakari Ailusc659c382011-01-21 10:59:30 +00002472}
Linus Torvalds1da177e2005-04-16 15:20:36 -07002473
2474
2475
2476
Sakari Ailusc659c382011-01-21 10:59:30 +00002477static void tlan_phy_power_down(struct net_device *dev)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002478{
Sakari Ailusc659c382011-01-21 10:59:30 +00002479 struct tlan_priv *priv = netdev_priv(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002480 u16 value;
2481
Sakari Ailusc659c382011-01-21 10:59:30 +00002482 TLAN_DBG(TLAN_DEBUG_GNRL, "%s: Powering down PHY(s).\n", dev->name);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002483 value = MII_GC_PDOWN | MII_GC_LOOPBK | MII_GC_ISOLATE;
Sakari Ailusc659c382011-01-21 10:59:30 +00002484 tlan_mii_sync(dev->base_addr);
2485 tlan_mii_write_reg(dev, priv->phy[priv->phy_num], MII_GEN_CTL, value);
2486 if ((priv->phy_num == 0) &&
2487 (priv->phy[1] != TLAN_PHY_NONE) &&
2488 (!(priv->adapter->flags & TLAN_ADAPTER_USE_INTERN_10))) {
2489 tlan_mii_sync(dev->base_addr);
2490 tlan_mii_write_reg(dev, priv->phy[1], MII_GEN_CTL, value);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002491 }
2492
2493 /* Wait for 50 ms and powerup
2494 * This is abitrary. It is intended to make sure the
2495 * transceiver settles.
2496 */
Sakari Ailusc659c382011-01-21 10:59:30 +00002497 tlan_set_timer(dev, (HZ/20), TLAN_TIMER_PHY_PUP);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002498
Sakari Ailusc659c382011-01-21 10:59:30 +00002499}
Linus Torvalds1da177e2005-04-16 15:20:36 -07002500
2501
2502
2503
Sakari Ailusc659c382011-01-21 10:59:30 +00002504static void tlan_phy_power_up(struct net_device *dev)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002505{
Sakari Ailusc659c382011-01-21 10:59:30 +00002506 struct tlan_priv *priv = netdev_priv(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002507 u16 value;
2508
Sakari Ailusc659c382011-01-21 10:59:30 +00002509 TLAN_DBG(TLAN_DEBUG_GNRL, "%s: Powering up PHY.\n", dev->name);
2510 tlan_mii_sync(dev->base_addr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002511 value = MII_GC_LOOPBK;
Sakari Ailusc659c382011-01-21 10:59:30 +00002512 tlan_mii_write_reg(dev, priv->phy[priv->phy_num], MII_GEN_CTL, value);
2513 tlan_mii_sync(dev->base_addr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002514 /* Wait for 500 ms and reset the
2515 * transceiver. The TLAN docs say both 50 ms and
2516 * 500 ms, so do the longer, just in case.
2517 */
Sakari Ailusc659c382011-01-21 10:59:30 +00002518 tlan_set_timer(dev, (HZ/20), TLAN_TIMER_PHY_RESET);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002519
Sakari Ailusc659c382011-01-21 10:59:30 +00002520}
Linus Torvalds1da177e2005-04-16 15:20:36 -07002521
2522
2523
2524
Sakari Ailusc659c382011-01-21 10:59:30 +00002525static void tlan_phy_reset(struct net_device *dev)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002526{
Sakari Ailusc659c382011-01-21 10:59:30 +00002527 struct tlan_priv *priv = netdev_priv(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002528 u16 phy;
2529 u16 value;
2530
Sakari Ailusc659c382011-01-21 10:59:30 +00002531 phy = priv->phy[priv->phy_num];
Linus Torvalds1da177e2005-04-16 15:20:36 -07002532
Masanari Iidafd9071e2012-04-13 04:33:20 +00002533 TLAN_DBG(TLAN_DEBUG_GNRL, "%s: Resetting PHY.\n", dev->name);
Sakari Ailusc659c382011-01-21 10:59:30 +00002534 tlan_mii_sync(dev->base_addr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002535 value = MII_GC_LOOPBK | MII_GC_RESET;
Sakari Ailusc659c382011-01-21 10:59:30 +00002536 tlan_mii_write_reg(dev, phy, MII_GEN_CTL, value);
2537 tlan_mii_read_reg(dev, phy, MII_GEN_CTL, &value);
2538 while (value & MII_GC_RESET)
2539 tlan_mii_read_reg(dev, phy, MII_GEN_CTL, &value);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002540
2541 /* Wait for 500 ms and initialize.
2542 * I don't remember why I wait this long.
2543 * I've changed this to 50ms, as it seems long enough.
2544 */
Sakari Ailusc659c382011-01-21 10:59:30 +00002545 tlan_set_timer(dev, (HZ/20), TLAN_TIMER_PHY_START_LINK);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002546
Sakari Ailusc659c382011-01-21 10:59:30 +00002547}
Linus Torvalds1da177e2005-04-16 15:20:36 -07002548
2549
2550
2551
Sakari Ailusc659c382011-01-21 10:59:30 +00002552static void tlan_phy_start_link(struct net_device *dev)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002553{
Sakari Ailusc659c382011-01-21 10:59:30 +00002554 struct tlan_priv *priv = netdev_priv(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002555 u16 ability;
2556 u16 control;
2557 u16 data;
2558 u16 phy;
2559 u16 status;
2560 u16 tctl;
2561
Sakari Ailusc659c382011-01-21 10:59:30 +00002562 phy = priv->phy[priv->phy_num];
2563 TLAN_DBG(TLAN_DEBUG_GNRL, "%s: Trying to activate link.\n", dev->name);
2564 tlan_mii_read_reg(dev, phy, MII_GEN_STS, &status);
2565 tlan_mii_read_reg(dev, phy, MII_GEN_STS, &ability);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002566
Sakari Ailusc659c382011-01-21 10:59:30 +00002567 if ((status & MII_GS_AUTONEG) &&
2568 (!priv->aui)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002569 ability = status >> 11;
Sakari Ailusc659c382011-01-21 10:59:30 +00002570 if (priv->speed == TLAN_SPEED_10 &&
2571 priv->duplex == TLAN_DUPLEX_HALF) {
2572 tlan_mii_write_reg(dev, phy, MII_GEN_CTL, 0x0000);
2573 } else if (priv->speed == TLAN_SPEED_10 &&
2574 priv->duplex == TLAN_DUPLEX_FULL) {
2575 priv->tlan_full_duplex = true;
2576 tlan_mii_write_reg(dev, phy, MII_GEN_CTL, 0x0100);
2577 } else if (priv->speed == TLAN_SPEED_100 &&
2578 priv->duplex == TLAN_DUPLEX_HALF) {
2579 tlan_mii_write_reg(dev, phy, MII_GEN_CTL, 0x2000);
2580 } else if (priv->speed == TLAN_SPEED_100 &&
2581 priv->duplex == TLAN_DUPLEX_FULL) {
2582 priv->tlan_full_duplex = true;
2583 tlan_mii_write_reg(dev, phy, MII_GEN_CTL, 0x2100);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002584 } else {
Jeff Garzik6aa20a22006-09-13 13:24:59 -04002585
Linus Torvalds1da177e2005-04-16 15:20:36 -07002586 /* Set Auto-Neg advertisement */
Sakari Ailusc659c382011-01-21 10:59:30 +00002587 tlan_mii_write_reg(dev, phy, MII_AN_ADV,
2588 (ability << 5) | 1);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002589 /* Enablee Auto-Neg */
Sakari Ailusc659c382011-01-21 10:59:30 +00002590 tlan_mii_write_reg(dev, phy, MII_GEN_CTL, 0x1000);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002591 /* Restart Auto-Neg */
Sakari Ailusc659c382011-01-21 10:59:30 +00002592 tlan_mii_write_reg(dev, phy, MII_GEN_CTL, 0x1200);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002593 /* Wait for 4 sec for autonegotiation
Sakari Ailusc659c382011-01-21 10:59:30 +00002594 * to complete. The max spec time is less than this
2595 * but the card need additional time to start AN.
2596 * .5 sec should be plenty extra.
2597 */
Joe Perches50624aa2011-03-01 06:56:33 +00002598 netdev_info(dev, "Starting autonegotiation\n");
Sakari Ailusc659c382011-01-21 10:59:30 +00002599 tlan_set_timer(dev, (2*HZ), TLAN_TIMER_PHY_FINISH_AN);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002600 return;
2601 }
Jeff Garzik6aa20a22006-09-13 13:24:59 -04002602
2603 }
2604
Sakari Ailusc659c382011-01-21 10:59:30 +00002605 if ((priv->aui) && (priv->phy_num != 0)) {
2606 priv->phy_num = 0;
2607 data = TLAN_NET_CFG_1FRAG | TLAN_NET_CFG_1CHAN
2608 | TLAN_NET_CFG_PHY_EN;
2609 tlan_dio_write16(dev->base_addr, TLAN_NET_CONFIG, data);
2610 tlan_set_timer(dev, (40*HZ/1000), TLAN_TIMER_PHY_PDOWN);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002611 return;
Sakari Ailusc659c382011-01-21 10:59:30 +00002612 } else if (priv->phy_num == 0) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002613 control = 0;
Sakari Ailusc659c382011-01-21 10:59:30 +00002614 tlan_mii_read_reg(dev, phy, TLAN_TLPHY_CTL, &tctl);
2615 if (priv->aui) {
2616 tctl |= TLAN_TC_AUISEL;
Jeff Garzik6aa20a22006-09-13 13:24:59 -04002617 } else {
Sakari Ailusc659c382011-01-21 10:59:30 +00002618 tctl &= ~TLAN_TC_AUISEL;
2619 if (priv->duplex == TLAN_DUPLEX_FULL) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002620 control |= MII_GC_DUPLEX;
Sakari Ailusc659c382011-01-21 10:59:30 +00002621 priv->tlan_full_duplex = true;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002622 }
Sakari Ailusc659c382011-01-21 10:59:30 +00002623 if (priv->speed == TLAN_SPEED_100)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002624 control |= MII_GC_SPEEDSEL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002625 }
Sakari Ailusc659c382011-01-21 10:59:30 +00002626 tlan_mii_write_reg(dev, phy, MII_GEN_CTL, control);
2627 tlan_mii_write_reg(dev, phy, TLAN_TLPHY_CTL, tctl);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002628 }
2629
2630 /* Wait for 2 sec to give the transceiver time
2631 * to establish link.
2632 */
Sakari Ailusc659c382011-01-21 10:59:30 +00002633 tlan_set_timer(dev, (4*HZ), TLAN_TIMER_FINISH_RESET);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002634
Sakari Ailusc659c382011-01-21 10:59:30 +00002635}
Linus Torvalds1da177e2005-04-16 15:20:36 -07002636
2637
2638
2639
Sakari Ailusc659c382011-01-21 10:59:30 +00002640static void tlan_phy_finish_auto_neg(struct net_device *dev)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002641{
Sakari Ailusc659c382011-01-21 10:59:30 +00002642 struct tlan_priv *priv = netdev_priv(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002643 u16 an_adv;
2644 u16 an_lpa;
2645 u16 data;
2646 u16 mode;
2647 u16 phy;
2648 u16 status;
Jeff Garzik6aa20a22006-09-13 13:24:59 -04002649
Sakari Ailusc659c382011-01-21 10:59:30 +00002650 phy = priv->phy[priv->phy_num];
Linus Torvalds1da177e2005-04-16 15:20:36 -07002651
Sakari Ailusc659c382011-01-21 10:59:30 +00002652 tlan_mii_read_reg(dev, phy, MII_GEN_STS, &status);
2653 udelay(1000);
2654 tlan_mii_read_reg(dev, phy, MII_GEN_STS, &status);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002655
Sakari Ailusc659c382011-01-21 10:59:30 +00002656 if (!(status & MII_GS_AUTOCMPLT)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002657 /* Wait for 8 sec to give the process
2658 * more time. Perhaps we should fail after a while.
2659 */
Sakari Ailusc659c382011-01-21 10:59:30 +00002660 if (!priv->neg_be_verbose++) {
Joe Perches50624aa2011-03-01 06:56:33 +00002661 pr_info("Giving autonegotiation more time.\n");
2662 pr_info("Please check that your adapter has\n");
2663 pr_info("been properly connected to a HUB or Switch.\n");
2664 pr_info("Trying to establish link in the background...\n");
Sakari Ailusc659c382011-01-21 10:59:30 +00002665 }
2666 tlan_set_timer(dev, (8*HZ), TLAN_TIMER_PHY_FINISH_AN);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002667 return;
2668 }
2669
Joe Perches50624aa2011-03-01 06:56:33 +00002670 netdev_info(dev, "Autonegotiation complete\n");
Sakari Ailusc659c382011-01-21 10:59:30 +00002671 tlan_mii_read_reg(dev, phy, MII_AN_ADV, &an_adv);
2672 tlan_mii_read_reg(dev, phy, MII_AN_LPA, &an_lpa);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002673 mode = an_adv & an_lpa & 0x03E0;
Sakari Ailusc659c382011-01-21 10:59:30 +00002674 if (mode & 0x0100)
2675 priv->tlan_full_duplex = true;
2676 else if (!(mode & 0x0080) && (mode & 0x0040))
2677 priv->tlan_full_duplex = true;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002678
Sakari Ailusc659c382011-01-21 10:59:30 +00002679 if ((!(mode & 0x0180)) &&
2680 (priv->adapter->flags & TLAN_ADAPTER_USE_INTERN_10) &&
2681 (priv->phy_num != 0)) {
2682 priv->phy_num = 0;
2683 data = TLAN_NET_CFG_1FRAG | TLAN_NET_CFG_1CHAN
2684 | TLAN_NET_CFG_PHY_EN;
2685 tlan_dio_write16(dev->base_addr, TLAN_NET_CONFIG, data);
2686 tlan_set_timer(dev, (400*HZ/1000), TLAN_TIMER_PHY_PDOWN);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002687 return;
2688 }
2689
Sakari Ailusc659c382011-01-21 10:59:30 +00002690 if (priv->phy_num == 0) {
2691 if ((priv->duplex == TLAN_DUPLEX_FULL) ||
2692 (an_adv & an_lpa & 0x0040)) {
2693 tlan_mii_write_reg(dev, phy, MII_GEN_CTL,
2694 MII_GC_AUTOENB | MII_GC_DUPLEX);
Joe Perches50624aa2011-03-01 06:56:33 +00002695 netdev_info(dev, "Starting internal PHY with FULL-DUPLEX\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002696 } else {
Sakari Ailusc659c382011-01-21 10:59:30 +00002697 tlan_mii_write_reg(dev, phy, MII_GEN_CTL,
2698 MII_GC_AUTOENB);
Joe Perches50624aa2011-03-01 06:56:33 +00002699 netdev_info(dev, "Starting internal PHY with HALF-DUPLEX\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002700 }
2701 }
2702
2703 /* Wait for 100 ms. No reason in partiticular.
2704 */
Sakari Ailusc659c382011-01-21 10:59:30 +00002705 tlan_set_timer(dev, (HZ/10), TLAN_TIMER_FINISH_RESET);
Jeff Garzik6aa20a22006-09-13 13:24:59 -04002706
Sakari Ailusc659c382011-01-21 10:59:30 +00002707}
Linus Torvalds1da177e2005-04-16 15:20:36 -07002708
Linus Torvalds1da177e2005-04-16 15:20:36 -07002709
Sakari Ailusc659c382011-01-21 10:59:30 +00002710/*********************************************************************
2711 *
2712 * tlan_phy_monitor
2713 *
2714 * Returns:
2715 * None
2716 *
2717 * Params:
Ondrej Zaryc0a87c22014-06-30 18:38:28 +02002718 * data The device structure of this device.
Sakari Ailusc659c382011-01-21 10:59:30 +00002719 *
2720 *
2721 * This function monitors PHY condition by reading the status
Ondrej Zaryc0a87c22014-06-30 18:38:28 +02002722 * register via the MII bus, controls LINK LED and notifies the
2723 * kernel about link state.
Sakari Ailusc659c382011-01-21 10:59:30 +00002724 *
2725 *******************************************************************/
Linus Torvalds1da177e2005-04-16 15:20:36 -07002726
Ondrej Zaryc0a87c22014-06-30 18:38:28 +02002727static void tlan_phy_monitor(unsigned long data)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002728{
Ondrej Zaryc0a87c22014-06-30 18:38:28 +02002729 struct net_device *dev = (struct net_device *) data;
Sakari Ailusc659c382011-01-21 10:59:30 +00002730 struct tlan_priv *priv = netdev_priv(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002731 u16 phy;
2732 u16 phy_status;
2733
Sakari Ailusc659c382011-01-21 10:59:30 +00002734 phy = priv->phy[priv->phy_num];
Linus Torvalds1da177e2005-04-16 15:20:36 -07002735
Sakari Ailusc659c382011-01-21 10:59:30 +00002736 /* Get PHY status register */
2737 tlan_mii_read_reg(dev, phy, MII_GEN_STS, &phy_status);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002738
Sakari Ailusc659c382011-01-21 10:59:30 +00002739 /* Check if link has been lost */
2740 if (!(phy_status & MII_GS_LINK)) {
Ondrej Zaryc0a87c22014-06-30 18:38:28 +02002741 if (netif_carrier_ok(dev)) {
Sakari Ailusc659c382011-01-21 10:59:30 +00002742 printk(KERN_DEBUG "TLAN: %s has lost link\n",
2743 dev->name);
Ondrej Zaryc0a87c22014-06-30 18:38:28 +02002744 tlan_dio_write8(dev->base_addr, TLAN_LED_REG, 0);
Sakari Ailusc659c382011-01-21 10:59:30 +00002745 netif_carrier_off(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002746 }
2747 }
2748
Sakari Ailusc659c382011-01-21 10:59:30 +00002749 /* Link restablished? */
Ondrej Zaryc0a87c22014-06-30 18:38:28 +02002750 if ((phy_status & MII_GS_LINK) && !netif_carrier_ok(dev)) {
2751 tlan_dio_write8(dev->base_addr, TLAN_LED_REG, TLAN_LED_LINK);
Sakari Ailusc659c382011-01-21 10:59:30 +00002752 printk(KERN_DEBUG "TLAN: %s has reestablished link\n",
2753 dev->name);
7d17c1d2005-05-12 19:45:25 -04002754 netif_carrier_on(dev);
Sakari Ailusc659c382011-01-21 10:59:30 +00002755 }
Ondrej Zaryc0a87c22014-06-30 18:38:28 +02002756 priv->media_timer.expires = jiffies + HZ;
2757 add_timer(&priv->media_timer);
Jeff Garzik6aa20a22006-09-13 13:24:59 -04002758}
Linus Torvalds1da177e2005-04-16 15:20:36 -07002759
Linus Torvalds1da177e2005-04-16 15:20:36 -07002760
2761/*****************************************************************************
2762******************************************************************************
2763
Sakari Ailusc659c382011-01-21 10:59:30 +00002764ThunderLAN driver MII routines
Linus Torvalds1da177e2005-04-16 15:20:36 -07002765
Sakari Ailusc659c382011-01-21 10:59:30 +00002766these routines are based on the information in chap. 2 of the
2767"ThunderLAN Programmer's Guide", pp. 15-24.
Linus Torvalds1da177e2005-04-16 15:20:36 -07002768
2769******************************************************************************
2770*****************************************************************************/
2771
2772
Sakari Ailusc659c382011-01-21 10:59:30 +00002773/***************************************************************
2774 * tlan_mii_read_reg
2775 *
2776 * Returns:
2777 * false if ack received ok
2778 * true if no ack received or other error
2779 *
2780 * Parms:
2781 * dev The device structure containing
2782 * The io address and interrupt count
2783 * for this device.
2784 * phy The address of the PHY to be queried.
2785 * reg The register whose contents are to be
2786 * retrieved.
2787 * val A pointer to a variable to store the
2788 * retrieved value.
2789 *
2790 * This function uses the TLAN's MII bus to retrieve the contents
2791 * of a given register on a PHY. It sends the appropriate info
2792 * and then reads the 16-bit register value from the MII bus via
2793 * the TLAN SIO register.
2794 *
2795 **************************************************************/
Linus Torvalds1da177e2005-04-16 15:20:36 -07002796
Sakari Ailusc659c382011-01-21 10:59:30 +00002797static bool
2798tlan_mii_read_reg(struct net_device *dev, u16 phy, u16 reg, u16 *val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002799{
2800 u8 nack;
2801 u16 sio, tmp;
Sakari Ailusc659c382011-01-21 10:59:30 +00002802 u32 i;
Joe Perches37fce432010-01-12 20:59:13 +00002803 bool err;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002804 int minten;
Sakari Ailusc659c382011-01-21 10:59:30 +00002805 struct tlan_priv *priv = netdev_priv(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002806 unsigned long flags = 0;
2807
Joe Perches37fce432010-01-12 20:59:13 +00002808 err = false;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002809 outw(TLAN_NET_SIO, dev->base_addr + TLAN_DIO_ADR);
2810 sio = dev->base_addr + TLAN_DIO_DATA + TLAN_NET_SIO;
Jeff Garzik6aa20a22006-09-13 13:24:59 -04002811
Linus Torvalds1da177e2005-04-16 15:20:36 -07002812 if (!in_irq())
2813 spin_lock_irqsave(&priv->lock, flags);
2814
Sakari Ailusc659c382011-01-21 10:59:30 +00002815 tlan_mii_sync(dev->base_addr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002816
Sakari Ailusc659c382011-01-21 10:59:30 +00002817 minten = tlan_get_bit(TLAN_NET_SIO_MINTEN, sio);
2818 if (minten)
2819 tlan_clear_bit(TLAN_NET_SIO_MINTEN, sio);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002820
Sakari Ailusc659c382011-01-21 10:59:30 +00002821 tlan_mii_send_data(dev->base_addr, 0x1, 2); /* start (01b) */
2822 tlan_mii_send_data(dev->base_addr, 0x2, 2); /* read (10b) */
2823 tlan_mii_send_data(dev->base_addr, phy, 5); /* device # */
2824 tlan_mii_send_data(dev->base_addr, reg, 5); /* register # */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002825
2826
Sakari Ailusc659c382011-01-21 10:59:30 +00002827 tlan_clear_bit(TLAN_NET_SIO_MTXEN, sio); /* change direction */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002828
Sakari Ailusc659c382011-01-21 10:59:30 +00002829 tlan_clear_bit(TLAN_NET_SIO_MCLK, sio); /* clock idle bit */
2830 tlan_set_bit(TLAN_NET_SIO_MCLK, sio);
2831 tlan_clear_bit(TLAN_NET_SIO_MCLK, sio); /* wait 300ns */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002832
Sakari Ailusc659c382011-01-21 10:59:30 +00002833 nack = tlan_get_bit(TLAN_NET_SIO_MDATA, sio); /* check for ACK */
2834 tlan_set_bit(TLAN_NET_SIO_MCLK, sio); /* finish ACK */
2835 if (nack) { /* no ACK, so fake it */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002836 for (i = 0; i < 16; i++) {
Sakari Ailusc659c382011-01-21 10:59:30 +00002837 tlan_clear_bit(TLAN_NET_SIO_MCLK, sio);
2838 tlan_set_bit(TLAN_NET_SIO_MCLK, sio);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002839 }
2840 tmp = 0xffff;
Joe Perches37fce432010-01-12 20:59:13 +00002841 err = true;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002842 } else { /* ACK, so read data */
2843 for (tmp = 0, i = 0x8000; i; i >>= 1) {
Sakari Ailusc659c382011-01-21 10:59:30 +00002844 tlan_clear_bit(TLAN_NET_SIO_MCLK, sio);
2845 if (tlan_get_bit(TLAN_NET_SIO_MDATA, sio))
Linus Torvalds1da177e2005-04-16 15:20:36 -07002846 tmp |= i;
Sakari Ailusc659c382011-01-21 10:59:30 +00002847 tlan_set_bit(TLAN_NET_SIO_MCLK, sio);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002848 }
2849 }
2850
2851
Sakari Ailusc659c382011-01-21 10:59:30 +00002852 tlan_clear_bit(TLAN_NET_SIO_MCLK, sio); /* idle cycle */
2853 tlan_set_bit(TLAN_NET_SIO_MCLK, sio);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002854
Sakari Ailusc659c382011-01-21 10:59:30 +00002855 if (minten)
2856 tlan_set_bit(TLAN_NET_SIO_MINTEN, sio);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002857
2858 *val = tmp;
Jeff Garzik6aa20a22006-09-13 13:24:59 -04002859
Linus Torvalds1da177e2005-04-16 15:20:36 -07002860 if (!in_irq())
2861 spin_unlock_irqrestore(&priv->lock, flags);
2862
2863 return err;
2864
Sakari Ailusc659c382011-01-21 10:59:30 +00002865}
Linus Torvalds1da177e2005-04-16 15:20:36 -07002866
2867
2868
2869
Sakari Ailusc659c382011-01-21 10:59:30 +00002870/***************************************************************
2871 * tlan_mii_send_data
2872 *
2873 * Returns:
2874 * Nothing
2875 * Parms:
2876 * base_port The base IO port of the adapter in
2877 * question.
2878 * dev The address of the PHY to be queried.
2879 * data The value to be placed on the MII bus.
2880 * num_bits The number of bits in data that are to
2881 * be placed on the MII bus.
2882 *
2883 * This function sends on sequence of bits on the MII
2884 * configuration bus.
2885 *
2886 **************************************************************/
Linus Torvalds1da177e2005-04-16 15:20:36 -07002887
Sakari Ailusc659c382011-01-21 10:59:30 +00002888static void tlan_mii_send_data(u16 base_port, u32 data, unsigned num_bits)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002889{
2890 u16 sio;
2891 u32 i;
2892
Sakari Ailusc659c382011-01-21 10:59:30 +00002893 if (num_bits == 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002894 return;
2895
Sakari Ailusc659c382011-01-21 10:59:30 +00002896 outw(TLAN_NET_SIO, base_port + TLAN_DIO_ADR);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002897 sio = base_port + TLAN_DIO_DATA + TLAN_NET_SIO;
Sakari Ailusc659c382011-01-21 10:59:30 +00002898 tlan_set_bit(TLAN_NET_SIO_MTXEN, sio);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002899
Sakari Ailusc659c382011-01-21 10:59:30 +00002900 for (i = (0x1 << (num_bits - 1)); i; i >>= 1) {
2901 tlan_clear_bit(TLAN_NET_SIO_MCLK, sio);
2902 (void) tlan_get_bit(TLAN_NET_SIO_MCLK, sio);
2903 if (data & i)
2904 tlan_set_bit(TLAN_NET_SIO_MDATA, sio);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002905 else
Sakari Ailusc659c382011-01-21 10:59:30 +00002906 tlan_clear_bit(TLAN_NET_SIO_MDATA, sio);
2907 tlan_set_bit(TLAN_NET_SIO_MCLK, sio);
2908 (void) tlan_get_bit(TLAN_NET_SIO_MCLK, sio);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002909 }
2910
Sakari Ailusc659c382011-01-21 10:59:30 +00002911}
Linus Torvalds1da177e2005-04-16 15:20:36 -07002912
2913
2914
2915
Sakari Ailusc659c382011-01-21 10:59:30 +00002916/***************************************************************
2917 * TLan_MiiSync
2918 *
2919 * Returns:
2920 * Nothing
2921 * Parms:
2922 * base_port The base IO port of the adapter in
2923 * question.
2924 *
2925 * This functions syncs all PHYs in terms of the MII configuration
2926 * bus.
2927 *
2928 **************************************************************/
Linus Torvalds1da177e2005-04-16 15:20:36 -07002929
Sakari Ailusc659c382011-01-21 10:59:30 +00002930static void tlan_mii_sync(u16 base_port)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002931{
2932 int i;
2933 u16 sio;
2934
Sakari Ailusc659c382011-01-21 10:59:30 +00002935 outw(TLAN_NET_SIO, base_port + TLAN_DIO_ADR);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002936 sio = base_port + TLAN_DIO_DATA + TLAN_NET_SIO;
2937
Sakari Ailusc659c382011-01-21 10:59:30 +00002938 tlan_clear_bit(TLAN_NET_SIO_MTXEN, sio);
2939 for (i = 0; i < 32; i++) {
2940 tlan_clear_bit(TLAN_NET_SIO_MCLK, sio);
2941 tlan_set_bit(TLAN_NET_SIO_MCLK, sio);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002942 }
2943
Sakari Ailusc659c382011-01-21 10:59:30 +00002944}
Linus Torvalds1da177e2005-04-16 15:20:36 -07002945
2946
2947
2948
Sakari Ailusc659c382011-01-21 10:59:30 +00002949/***************************************************************
2950 * tlan_mii_write_reg
2951 *
2952 * Returns:
2953 * Nothing
2954 * Parms:
2955 * dev The device structure for the device
2956 * to write to.
2957 * phy The address of the PHY to be written to.
2958 * reg The register whose contents are to be
2959 * written.
2960 * val The value to be written to the register.
2961 *
2962 * This function uses the TLAN's MII bus to write the contents of a
2963 * given register on a PHY. It sends the appropriate info and then
2964 * writes the 16-bit register value from the MII configuration bus
2965 * via the TLAN SIO register.
2966 *
2967 **************************************************************/
Linus Torvalds1da177e2005-04-16 15:20:36 -07002968
Sakari Ailusc659c382011-01-21 10:59:30 +00002969static void
2970tlan_mii_write_reg(struct net_device *dev, u16 phy, u16 reg, u16 val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002971{
2972 u16 sio;
2973 int minten;
2974 unsigned long flags = 0;
Sakari Ailusc659c382011-01-21 10:59:30 +00002975 struct tlan_priv *priv = netdev_priv(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002976
2977 outw(TLAN_NET_SIO, dev->base_addr + TLAN_DIO_ADR);
2978 sio = dev->base_addr + TLAN_DIO_DATA + TLAN_NET_SIO;
Jeff Garzik6aa20a22006-09-13 13:24:59 -04002979
Linus Torvalds1da177e2005-04-16 15:20:36 -07002980 if (!in_irq())
2981 spin_lock_irqsave(&priv->lock, flags);
2982
Sakari Ailusc659c382011-01-21 10:59:30 +00002983 tlan_mii_sync(dev->base_addr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002984
Sakari Ailusc659c382011-01-21 10:59:30 +00002985 minten = tlan_get_bit(TLAN_NET_SIO_MINTEN, sio);
2986 if (minten)
2987 tlan_clear_bit(TLAN_NET_SIO_MINTEN, sio);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002988
Sakari Ailusc659c382011-01-21 10:59:30 +00002989 tlan_mii_send_data(dev->base_addr, 0x1, 2); /* start (01b) */
2990 tlan_mii_send_data(dev->base_addr, 0x1, 2); /* write (01b) */
2991 tlan_mii_send_data(dev->base_addr, phy, 5); /* device # */
2992 tlan_mii_send_data(dev->base_addr, reg, 5); /* register # */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002993
Sakari Ailusc659c382011-01-21 10:59:30 +00002994 tlan_mii_send_data(dev->base_addr, 0x2, 2); /* send ACK */
2995 tlan_mii_send_data(dev->base_addr, val, 16); /* send data */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002996
Sakari Ailusc659c382011-01-21 10:59:30 +00002997 tlan_clear_bit(TLAN_NET_SIO_MCLK, sio); /* idle cycle */
2998 tlan_set_bit(TLAN_NET_SIO_MCLK, sio);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002999
Sakari Ailusc659c382011-01-21 10:59:30 +00003000 if (minten)
3001 tlan_set_bit(TLAN_NET_SIO_MINTEN, sio);
Jeff Garzik6aa20a22006-09-13 13:24:59 -04003002
Linus Torvalds1da177e2005-04-16 15:20:36 -07003003 if (!in_irq())
3004 spin_unlock_irqrestore(&priv->lock, flags);
3005
Sakari Ailusc659c382011-01-21 10:59:30 +00003006}
Linus Torvalds1da177e2005-04-16 15:20:36 -07003007
3008
3009
3010
3011/*****************************************************************************
3012******************************************************************************
3013
Sakari Ailusc659c382011-01-21 10:59:30 +00003014ThunderLAN driver eeprom routines
Linus Torvalds1da177e2005-04-16 15:20:36 -07003015
Sakari Ailusc659c382011-01-21 10:59:30 +00003016the Compaq netelligent 10 and 10/100 cards use a microchip 24C02A
3017EEPROM. these functions are based on information in microchip's
3018data sheet. I don't know how well this functions will work with
3019other Eeproms.
Linus Torvalds1da177e2005-04-16 15:20:36 -07003020
3021******************************************************************************
3022*****************************************************************************/
3023
3024
Sakari Ailusc659c382011-01-21 10:59:30 +00003025/***************************************************************
3026 * tlan_ee_send_start
3027 *
3028 * Returns:
3029 * Nothing
3030 * Parms:
3031 * io_base The IO port base address for the
3032 * TLAN device with the EEPROM to
3033 * use.
3034 *
3035 * This function sends a start cycle to an EEPROM attached
3036 * to a TLAN chip.
3037 *
3038 **************************************************************/
Linus Torvalds1da177e2005-04-16 15:20:36 -07003039
Sakari Ailusc659c382011-01-21 10:59:30 +00003040static void tlan_ee_send_start(u16 io_base)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003041{
3042 u16 sio;
3043
Sakari Ailusc659c382011-01-21 10:59:30 +00003044 outw(TLAN_NET_SIO, io_base + TLAN_DIO_ADR);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003045 sio = io_base + TLAN_DIO_DATA + TLAN_NET_SIO;
3046
Sakari Ailusc659c382011-01-21 10:59:30 +00003047 tlan_set_bit(TLAN_NET_SIO_ECLOK, sio);
3048 tlan_set_bit(TLAN_NET_SIO_EDATA, sio);
3049 tlan_set_bit(TLAN_NET_SIO_ETXEN, sio);
3050 tlan_clear_bit(TLAN_NET_SIO_EDATA, sio);
3051 tlan_clear_bit(TLAN_NET_SIO_ECLOK, sio);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003052
Sakari Ailusc659c382011-01-21 10:59:30 +00003053}
Linus Torvalds1da177e2005-04-16 15:20:36 -07003054
3055
3056
3057
Sakari Ailusc659c382011-01-21 10:59:30 +00003058/***************************************************************
3059 * tlan_ee_send_byte
3060 *
3061 * Returns:
3062 * If the correct ack was received, 0, otherwise 1
3063 * Parms: io_base The IO port base address for the
3064 * TLAN device with the EEPROM to
3065 * use.
3066 * data The 8 bits of information to
3067 * send to the EEPROM.
3068 * stop If TLAN_EEPROM_STOP is passed, a
3069 * stop cycle is sent after the
3070 * byte is sent after the ack is
3071 * read.
3072 *
3073 * This function sends a byte on the serial EEPROM line,
3074 * driving the clock to send each bit. The function then
3075 * reverses transmission direction and reads an acknowledge
3076 * bit.
3077 *
3078 **************************************************************/
Linus Torvalds1da177e2005-04-16 15:20:36 -07003079
Sakari Ailusc659c382011-01-21 10:59:30 +00003080static int tlan_ee_send_byte(u16 io_base, u8 data, int stop)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003081{
3082 int err;
3083 u8 place;
3084 u16 sio;
3085
Sakari Ailusc659c382011-01-21 10:59:30 +00003086 outw(TLAN_NET_SIO, io_base + TLAN_DIO_ADR);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003087 sio = io_base + TLAN_DIO_DATA + TLAN_NET_SIO;
3088
3089 /* Assume clock is low, tx is enabled; */
Sakari Ailusc659c382011-01-21 10:59:30 +00003090 for (place = 0x80; place != 0; place >>= 1) {
3091 if (place & data)
3092 tlan_set_bit(TLAN_NET_SIO_EDATA, sio);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003093 else
Sakari Ailusc659c382011-01-21 10:59:30 +00003094 tlan_clear_bit(TLAN_NET_SIO_EDATA, sio);
3095 tlan_set_bit(TLAN_NET_SIO_ECLOK, sio);
3096 tlan_clear_bit(TLAN_NET_SIO_ECLOK, sio);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003097 }
Sakari Ailusc659c382011-01-21 10:59:30 +00003098 tlan_clear_bit(TLAN_NET_SIO_ETXEN, sio);
3099 tlan_set_bit(TLAN_NET_SIO_ECLOK, sio);
3100 err = tlan_get_bit(TLAN_NET_SIO_EDATA, sio);
3101 tlan_clear_bit(TLAN_NET_SIO_ECLOK, sio);
3102 tlan_set_bit(TLAN_NET_SIO_ETXEN, sio);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003103
Sakari Ailusc659c382011-01-21 10:59:30 +00003104 if ((!err) && stop) {
Stephen Hemmingerdfc2c0a2008-05-30 09:49:58 -07003105 /* STOP, raise data while clock is high */
Sakari Ailusc659c382011-01-21 10:59:30 +00003106 tlan_clear_bit(TLAN_NET_SIO_EDATA, sio);
3107 tlan_set_bit(TLAN_NET_SIO_ECLOK, sio);
3108 tlan_set_bit(TLAN_NET_SIO_EDATA, sio);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003109 }
3110
Eric Dumazet807540b2010-09-23 05:40:09 +00003111 return err;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003112
Sakari Ailusc659c382011-01-21 10:59:30 +00003113}
Linus Torvalds1da177e2005-04-16 15:20:36 -07003114
3115
3116
3117
Sakari Ailusc659c382011-01-21 10:59:30 +00003118/***************************************************************
3119 * tlan_ee_receive_byte
3120 *
3121 * Returns:
3122 * Nothing
3123 * Parms:
3124 * io_base The IO port base address for the
3125 * TLAN device with the EEPROM to
3126 * use.
3127 * data An address to a char to hold the
3128 * data sent from the EEPROM.
3129 * stop If TLAN_EEPROM_STOP is passed, a
3130 * stop cycle is sent after the
3131 * byte is received, and no ack is
3132 * sent.
3133 *
3134 * This function receives 8 bits of data from the EEPROM
3135 * over the serial link. It then sends and ack bit, or no
3136 * ack and a stop bit. This function is used to retrieve
3137 * data after the address of a byte in the EEPROM has been
3138 * sent.
3139 *
3140 **************************************************************/
Linus Torvalds1da177e2005-04-16 15:20:36 -07003141
Sakari Ailusc659c382011-01-21 10:59:30 +00003142static void tlan_ee_receive_byte(u16 io_base, u8 *data, int stop)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003143{
3144 u8 place;
3145 u16 sio;
3146
Sakari Ailusc659c382011-01-21 10:59:30 +00003147 outw(TLAN_NET_SIO, io_base + TLAN_DIO_ADR);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003148 sio = io_base + TLAN_DIO_DATA + TLAN_NET_SIO;
3149 *data = 0;
3150
3151 /* Assume clock is low, tx is enabled; */
Sakari Ailusc659c382011-01-21 10:59:30 +00003152 tlan_clear_bit(TLAN_NET_SIO_ETXEN, sio);
3153 for (place = 0x80; place; place >>= 1) {
3154 tlan_set_bit(TLAN_NET_SIO_ECLOK, sio);
3155 if (tlan_get_bit(TLAN_NET_SIO_EDATA, sio))
Linus Torvalds1da177e2005-04-16 15:20:36 -07003156 *data |= place;
Sakari Ailusc659c382011-01-21 10:59:30 +00003157 tlan_clear_bit(TLAN_NET_SIO_ECLOK, sio);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003158 }
3159
Sakari Ailusc659c382011-01-21 10:59:30 +00003160 tlan_set_bit(TLAN_NET_SIO_ETXEN, sio);
3161 if (!stop) {
3162 tlan_clear_bit(TLAN_NET_SIO_EDATA, sio); /* ack = 0 */
3163 tlan_set_bit(TLAN_NET_SIO_ECLOK, sio);
3164 tlan_clear_bit(TLAN_NET_SIO_ECLOK, sio);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003165 } else {
Sakari Ailusc659c382011-01-21 10:59:30 +00003166 tlan_set_bit(TLAN_NET_SIO_EDATA, sio); /* no ack = 1 (?) */
3167 tlan_set_bit(TLAN_NET_SIO_ECLOK, sio);
3168 tlan_clear_bit(TLAN_NET_SIO_ECLOK, sio);
Stephen Hemmingerdfc2c0a2008-05-30 09:49:58 -07003169 /* STOP, raise data while clock is high */
Sakari Ailusc659c382011-01-21 10:59:30 +00003170 tlan_clear_bit(TLAN_NET_SIO_EDATA, sio);
3171 tlan_set_bit(TLAN_NET_SIO_ECLOK, sio);
3172 tlan_set_bit(TLAN_NET_SIO_EDATA, sio);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003173 }
3174
Sakari Ailusc659c382011-01-21 10:59:30 +00003175}
Linus Torvalds1da177e2005-04-16 15:20:36 -07003176
3177
3178
3179
Sakari Ailusc659c382011-01-21 10:59:30 +00003180/***************************************************************
3181 * tlan_ee_read_byte
3182 *
3183 * Returns:
3184 * No error = 0, else, the stage at which the error
3185 * occurred.
3186 * Parms:
3187 * io_base The IO port base address for the
3188 * TLAN device with the EEPROM to
3189 * use.
3190 * ee_addr The address of the byte in the
3191 * EEPROM whose contents are to be
3192 * retrieved.
3193 * data An address to a char to hold the
3194 * data obtained from the EEPROM.
3195 *
3196 * This function reads a byte of information from an byte
3197 * cell in the EEPROM.
3198 *
3199 **************************************************************/
Linus Torvalds1da177e2005-04-16 15:20:36 -07003200
Sakari Ailusc659c382011-01-21 10:59:30 +00003201static int tlan_ee_read_byte(struct net_device *dev, u8 ee_addr, u8 *data)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003202{
3203 int err;
Sakari Ailusc659c382011-01-21 10:59:30 +00003204 struct tlan_priv *priv = netdev_priv(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003205 unsigned long flags = 0;
Sakari Ailusc659c382011-01-21 10:59:30 +00003206 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003207
3208 spin_lock_irqsave(&priv->lock, flags);
3209
Sakari Ailusc659c382011-01-21 10:59:30 +00003210 tlan_ee_send_start(dev->base_addr);
3211 err = tlan_ee_send_byte(dev->base_addr, 0xa0, TLAN_EEPROM_ACK);
3212 if (err) {
3213 ret = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003214 goto fail;
3215 }
Sakari Ailusc659c382011-01-21 10:59:30 +00003216 err = tlan_ee_send_byte(dev->base_addr, ee_addr, TLAN_EEPROM_ACK);
3217 if (err) {
3218 ret = 2;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003219 goto fail;
3220 }
Sakari Ailusc659c382011-01-21 10:59:30 +00003221 tlan_ee_send_start(dev->base_addr);
3222 err = tlan_ee_send_byte(dev->base_addr, 0xa1, TLAN_EEPROM_ACK);
3223 if (err) {
3224 ret = 3;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003225 goto fail;
3226 }
Sakari Ailusc659c382011-01-21 10:59:30 +00003227 tlan_ee_receive_byte(dev->base_addr, data, TLAN_EEPROM_STOP);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003228fail:
3229 spin_unlock_irqrestore(&priv->lock, flags);
3230
3231 return ret;
3232
Sakari Ailusc659c382011-01-21 10:59:30 +00003233}
Linus Torvalds1da177e2005-04-16 15:20:36 -07003234
3235
3236