1 /*******************************************************************************
3 * Linux ThunderLAN Driver
8 * (C) 1997-1998 Caldera, Inc.
10 * (C) 1999-2001 Torben Mathiasen
11 * (C) 2002 Samuel Chessman
13 * This software may be used and distributed according to the terms
14 * of the GNU General Public License, incorporated herein by reference.
16 ** Useful (if not required) reading:
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
28 ******************************************************************************/
30 #include <linux/module.h>
31 #include <linux/init.h>
32 #include <linux/ioport.h>
33 #include <linux/eisa.h>
34 #include <linux/pci.h>
35 #include <linux/dma-mapping.h>
36 #include <linux/netdevice.h>
37 #include <linux/etherdevice.h>
38 #include <linux/delay.h>
39 #include <linux/spinlock.h>
40 #include <linux/workqueue.h>
41 #include <linux/mii.h>
46 /* For removing EISA devices */
47 static struct net_device
*tlan_eisa_devices
;
49 static int tlan_devices_installed
;
51 /* Set speed, duplex and aui settings */
52 static int aui
[MAX_TLAN_BOARDS
];
53 static int duplex
[MAX_TLAN_BOARDS
];
54 static int speed
[MAX_TLAN_BOARDS
];
55 static int boards_found
;
56 module_param_array(aui
, int, NULL
, 0);
57 module_param_array(duplex
, int, NULL
, 0);
58 module_param_array(speed
, int, NULL
, 0);
59 MODULE_PARM_DESC(aui
, "ThunderLAN use AUI port(s) (0-1)");
60 MODULE_PARM_DESC(duplex
,
61 "ThunderLAN duplex setting(s) (0-default, 1-half, 2-full)");
62 MODULE_PARM_DESC(speed
, "ThunderLAN port speen setting(s) (0,10,100)");
64 MODULE_AUTHOR("Maintainer: Samuel Chessman <chessman@tux.org>");
65 MODULE_DESCRIPTION("Driver for TI ThunderLAN based ethernet PCI adapters");
66 MODULE_LICENSE("GPL");
69 /* Define this to enable Link beat monitoring */
72 /* Turn on debugging. See Documentation/networking/tlan.txt for details */
74 module_param(debug
, int, 0);
75 MODULE_PARM_DESC(debug
, "ThunderLAN debug mask");
77 static const char tlan_signature
[] = "TLAN";
78 static const char tlan_banner
[] = "ThunderLAN driver v1.17\n";
79 static int tlan_have_pci
;
80 static int tlan_have_eisa
;
82 static const char * const media
[] = {
83 "10BaseT-HD", "10BaseT-FD", "100baseTx-HD",
84 "100BaseTx-FD", "100BaseT4", NULL
88 const char *device_label
;
92 { "Compaq Netelligent 10 T PCI UTP", TLAN_ADAPTER_ACTIVITY_LED
, 0x83 },
93 { "Compaq Netelligent 10/100 TX PCI UTP",
94 TLAN_ADAPTER_ACTIVITY_LED
, 0x83 },
95 { "Compaq Integrated NetFlex-3/P", TLAN_ADAPTER_NONE
, 0x83 },
96 { "Compaq NetFlex-3/P",
97 TLAN_ADAPTER_UNMANAGED_PHY
| TLAN_ADAPTER_BIT_RATE_PHY
, 0x83 },
98 { "Compaq NetFlex-3/P", TLAN_ADAPTER_NONE
, 0x83 },
99 { "Compaq Netelligent Integrated 10/100 TX UTP",
100 TLAN_ADAPTER_ACTIVITY_LED
, 0x83 },
101 { "Compaq Netelligent Dual 10/100 TX PCI UTP",
102 TLAN_ADAPTER_NONE
, 0x83 },
103 { "Compaq Netelligent 10/100 TX Embedded UTP",
104 TLAN_ADAPTER_NONE
, 0x83 },
105 { "Olicom OC-2183/2185", TLAN_ADAPTER_USE_INTERN_10
, 0x83 },
106 { "Olicom OC-2325", TLAN_ADAPTER_UNMANAGED_PHY
, 0xf8 },
107 { "Olicom OC-2326", TLAN_ADAPTER_USE_INTERN_10
, 0xf8 },
108 { "Compaq Netelligent 10/100 TX UTP", TLAN_ADAPTER_ACTIVITY_LED
, 0x83 },
109 { "Compaq Netelligent 10 T/2 PCI UTP/coax", TLAN_ADAPTER_NONE
, 0x83 },
110 { "Compaq NetFlex-3/E",
111 TLAN_ADAPTER_ACTIVITY_LED
| /* EISA card */
112 TLAN_ADAPTER_UNMANAGED_PHY
| TLAN_ADAPTER_BIT_RATE_PHY
, 0x83 },
113 { "Compaq NetFlex-3/E",
114 TLAN_ADAPTER_ACTIVITY_LED
, 0x83 }, /* EISA card */
117 static DEFINE_PCI_DEVICE_TABLE(tlan_pci_tbl
) = {
118 { PCI_VENDOR_ID_COMPAQ
, PCI_DEVICE_ID_COMPAQ_NETEL10
,
119 PCI_ANY_ID
, PCI_ANY_ID
, 0, 0, 0 },
120 { PCI_VENDOR_ID_COMPAQ
, PCI_DEVICE_ID_COMPAQ_NETEL100
,
121 PCI_ANY_ID
, PCI_ANY_ID
, 0, 0, 1 },
122 { PCI_VENDOR_ID_COMPAQ
, PCI_DEVICE_ID_COMPAQ_NETFLEX3I
,
123 PCI_ANY_ID
, PCI_ANY_ID
, 0, 0, 2 },
124 { PCI_VENDOR_ID_COMPAQ
, PCI_DEVICE_ID_COMPAQ_THUNDER
,
125 PCI_ANY_ID
, PCI_ANY_ID
, 0, 0, 3 },
126 { PCI_VENDOR_ID_COMPAQ
, PCI_DEVICE_ID_COMPAQ_NETFLEX3B
,
127 PCI_ANY_ID
, PCI_ANY_ID
, 0, 0, 4 },
128 { PCI_VENDOR_ID_COMPAQ
, PCI_DEVICE_ID_COMPAQ_NETEL100PI
,
129 PCI_ANY_ID
, PCI_ANY_ID
, 0, 0, 5 },
130 { PCI_VENDOR_ID_COMPAQ
, PCI_DEVICE_ID_COMPAQ_NETEL100D
,
131 PCI_ANY_ID
, PCI_ANY_ID
, 0, 0, 6 },
132 { PCI_VENDOR_ID_COMPAQ
, PCI_DEVICE_ID_COMPAQ_NETEL100I
,
133 PCI_ANY_ID
, PCI_ANY_ID
, 0, 0, 7 },
134 { PCI_VENDOR_ID_OLICOM
, PCI_DEVICE_ID_OLICOM_OC2183
,
135 PCI_ANY_ID
, PCI_ANY_ID
, 0, 0, 8 },
136 { PCI_VENDOR_ID_OLICOM
, PCI_DEVICE_ID_OLICOM_OC2325
,
137 PCI_ANY_ID
, PCI_ANY_ID
, 0, 0, 9 },
138 { PCI_VENDOR_ID_OLICOM
, PCI_DEVICE_ID_OLICOM_OC2326
,
139 PCI_ANY_ID
, PCI_ANY_ID
, 0, 0, 10 },
140 { PCI_VENDOR_ID_COMPAQ
, PCI_DEVICE_ID_NETELLIGENT_10_100_WS_5100
,
141 PCI_ANY_ID
, PCI_ANY_ID
, 0, 0, 11 },
142 { PCI_VENDOR_ID_COMPAQ
, PCI_DEVICE_ID_NETELLIGENT_10_T2
,
143 PCI_ANY_ID
, PCI_ANY_ID
, 0, 0, 12 },
146 MODULE_DEVICE_TABLE(pci
, tlan_pci_tbl
);
148 static void tlan_eisa_probe(void);
149 static void tlan_eisa_cleanup(void);
150 static int tlan_init(struct net_device
*);
151 static int tlan_open(struct net_device
*dev
);
152 static netdev_tx_t
tlan_start_tx(struct sk_buff
*, struct net_device
*);
153 static irqreturn_t
tlan_handle_interrupt(int, void *);
154 static int tlan_close(struct net_device
*);
155 static struct net_device_stats
*tlan_get_stats(struct net_device
*);
156 static void tlan_set_multicast_list(struct net_device
*);
157 static int tlan_ioctl(struct net_device
*dev
, struct ifreq
*rq
, int cmd
);
158 static int tlan_probe1(struct pci_dev
*pdev
, long ioaddr
,
159 int irq
, int rev
, const struct pci_device_id
*ent
);
160 static void tlan_tx_timeout(struct net_device
*dev
);
161 static void tlan_tx_timeout_work(struct work_struct
*work
);
162 static int tlan_init_one(struct pci_dev
*pdev
,
163 const struct pci_device_id
*ent
);
165 static u32
tlan_handle_tx_eof(struct net_device
*, u16
);
166 static u32
tlan_handle_stat_overflow(struct net_device
*, u16
);
167 static u32
tlan_handle_rx_eof(struct net_device
*, u16
);
168 static u32
tlan_handle_dummy(struct net_device
*, u16
);
169 static u32
tlan_handle_tx_eoc(struct net_device
*, u16
);
170 static u32
tlan_handle_status_check(struct net_device
*, u16
);
171 static u32
tlan_handle_rx_eoc(struct net_device
*, u16
);
173 static void tlan_timer(unsigned long);
175 static void tlan_reset_lists(struct net_device
*);
176 static void tlan_free_lists(struct net_device
*);
177 static void tlan_print_dio(u16
);
178 static void tlan_print_list(struct tlan_list
*, char *, int);
179 static void tlan_read_and_clear_stats(struct net_device
*, int);
180 static void tlan_reset_adapter(struct net_device
*);
181 static void tlan_finish_reset(struct net_device
*);
182 static void tlan_set_mac(struct net_device
*, int areg
, char *mac
);
184 static void tlan_phy_print(struct net_device
*);
185 static void tlan_phy_detect(struct net_device
*);
186 static void tlan_phy_power_down(struct net_device
*);
187 static void tlan_phy_power_up(struct net_device
*);
188 static void tlan_phy_reset(struct net_device
*);
189 static void tlan_phy_start_link(struct net_device
*);
190 static void tlan_phy_finish_auto_neg(struct net_device
*);
192 static void tlan_phy_monitor(struct net_device
*);
196 static int tlan_phy_nop(struct net_device *);
197 static int tlan_phy_internal_check(struct net_device *);
198 static int tlan_phy_internal_service(struct net_device *);
199 static int tlan_phy_dp83840a_check(struct net_device *);
202 static bool tlan_mii_read_reg(struct net_device
*, u16
, u16
, u16
*);
203 static void tlan_mii_send_data(u16
, u32
, unsigned);
204 static void tlan_mii_sync(u16
);
205 static void tlan_mii_write_reg(struct net_device
*, u16
, u16
, u16
);
207 static void tlan_ee_send_start(u16
);
208 static int tlan_ee_send_byte(u16
, u8
, int);
209 static void tlan_ee_receive_byte(u16
, u8
*, int);
210 static int tlan_ee_read_byte(struct net_device
*, u8
, u8
*);
214 tlan_store_skb(struct tlan_list
*tag
, struct sk_buff
*skb
)
216 unsigned long addr
= (unsigned long)skb
;
217 tag
->buffer
[9].address
= addr
;
218 tag
->buffer
[8].address
= upper_32_bits(addr
);
221 static inline struct sk_buff
*
222 tlan_get_skb(const struct tlan_list
*tag
)
226 addr
= tag
->buffer
[9].address
;
227 addr
|= (tag
->buffer
[8].address
<< 16) << 16;
228 return (struct sk_buff
*) addr
;
232 (*tlan_int_vector
[TLAN_INT_NUMBER_OF_INTS
])(struct net_device
*, u16
) = {
235 tlan_handle_stat_overflow
,
239 tlan_handle_status_check
,
244 tlan_set_timer(struct net_device
*dev
, u32 ticks
, u32 type
)
246 struct tlan_priv
*priv
= netdev_priv(dev
);
247 unsigned long flags
= 0;
250 spin_lock_irqsave(&priv
->lock
, flags
);
251 if (priv
->timer
.function
!= NULL
&&
252 priv
->timer_type
!= TLAN_TIMER_ACTIVITY
) {
254 spin_unlock_irqrestore(&priv
->lock
, flags
);
257 priv
->timer
.function
= tlan_timer
;
259 spin_unlock_irqrestore(&priv
->lock
, flags
);
261 priv
->timer
.data
= (unsigned long) dev
;
262 priv
->timer_set_at
= jiffies
;
263 priv
->timer_type
= type
;
264 mod_timer(&priv
->timer
, jiffies
+ ticks
);
269 /*****************************************************************************
270 ******************************************************************************
272 ThunderLAN driver primary functions
274 these functions are more or less common to all linux network drivers.
276 ******************************************************************************
277 *****************************************************************************/
283 /***************************************************************
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.
296 **************************************************************/
299 static void __devexit
tlan_remove_one(struct pci_dev
*pdev
)
301 struct net_device
*dev
= pci_get_drvdata(pdev
);
302 struct tlan_priv
*priv
= netdev_priv(dev
);
304 unregister_netdev(dev
);
306 if (priv
->dma_storage
) {
307 pci_free_consistent(priv
->pci_dev
,
308 priv
->dma_size
, priv
->dma_storage
,
309 priv
->dma_storage_dma
);
313 pci_release_regions(pdev
);
318 pci_set_drvdata(pdev
, NULL
);
321 static void tlan_start(struct net_device
*dev
)
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.
327 tlan_read_and_clear_stats(dev
, TLAN_IGNORE
);
328 tlan_reset_adapter(dev
);
329 netif_wake_queue(dev
);
332 static void tlan_stop(struct net_device
*dev
)
334 struct tlan_priv
*priv
= netdev_priv(dev
);
336 tlan_read_and_clear_stats(dev
, TLAN_RECORD
);
337 outl(TLAN_HC_AD_RST
, dev
->base_addr
+ TLAN_HOST_CMD
);
338 /* Reset and power down phy */
339 tlan_reset_adapter(dev
);
340 if (priv
->timer
.function
!= NULL
) {
341 del_timer_sync(&priv
->timer
);
342 priv
->timer
.function
= NULL
;
348 static int tlan_suspend(struct pci_dev
*pdev
, pm_message_t state
)
350 struct net_device
*dev
= pci_get_drvdata(pdev
);
352 if (netif_running(dev
))
355 netif_device_detach(dev
);
356 pci_save_state(pdev
);
357 pci_disable_device(pdev
);
358 pci_wake_from_d3(pdev
, false);
359 pci_set_power_state(pdev
, PCI_D3hot
);
364 static int tlan_resume(struct pci_dev
*pdev
)
366 struct net_device
*dev
= pci_get_drvdata(pdev
);
368 pci_set_power_state(pdev
, PCI_D0
);
369 pci_restore_state(pdev
);
370 pci_enable_wake(pdev
, 0, 0);
371 netif_device_attach(dev
);
373 if (netif_running(dev
))
379 #else /* CONFIG_PM */
381 #define tlan_suspend NULL
382 #define tlan_resume NULL
384 #endif /* CONFIG_PM */
387 static struct pci_driver tlan_driver
= {
389 .id_table
= tlan_pci_tbl
,
390 .probe
= tlan_init_one
,
391 .remove
= __devexit_p(tlan_remove_one
),
392 .suspend
= tlan_suspend
,
393 .resume
= tlan_resume
,
396 static int __init
tlan_probe(void)
400 printk(KERN_INFO
"%s", tlan_banner
);
402 TLAN_DBG(TLAN_DEBUG_PROBE
, "Starting PCI Probe....\n");
404 /* Use new style PCI probing. Now the kernel will
405 do most of this for us */
406 rc
= pci_register_driver(&tlan_driver
);
409 printk(KERN_ERR
"TLAN: Could not register pci driver.\n");
410 goto err_out_pci_free
;
413 TLAN_DBG(TLAN_DEBUG_PROBE
, "Starting EISA Probe....\n");
416 printk(KERN_INFO
"TLAN: %d device%s installed, PCI: %d EISA: %d\n",
417 tlan_devices_installed
, tlan_devices_installed
== 1 ? "" : "s",
418 tlan_have_pci
, tlan_have_eisa
);
420 if (tlan_devices_installed
== 0) {
422 goto err_out_pci_unreg
;
427 pci_unregister_driver(&tlan_driver
);
433 static int __devinit
tlan_init_one(struct pci_dev
*pdev
,
434 const struct pci_device_id
*ent
)
436 return tlan_probe1(pdev
, -1, -1, 0, ent
);
441 ***************************************************************
445 * 0 on success, error code on error
449 * The name is lower case to fit in with all the rest of
450 * the netcard_probe names. This function looks for
451 * another TLan based adapter, setting it up with the
452 * allocated device struct if one is found.
453 * tlan_probe has been ported to the new net API and
454 * now allocates its own device structure. This function
455 * is also used by modules.
457 **************************************************************/
459 static int __devinit
tlan_probe1(struct pci_dev
*pdev
,
460 long ioaddr
, int irq
, int rev
,
461 const struct pci_device_id
*ent
)
464 struct net_device
*dev
;
465 struct tlan_priv
*priv
;
467 int reg
, rc
= -ENODEV
;
471 rc
= pci_enable_device(pdev
);
475 rc
= pci_request_regions(pdev
, tlan_signature
);
477 printk(KERN_ERR
"TLAN: Could not reserve IO regions\n");
481 #endif /* CONFIG_PCI */
483 dev
= alloc_etherdev(sizeof(struct tlan_priv
));
485 printk(KERN_ERR
"TLAN: Could not allocate memory for device.\n");
487 goto err_out_regions
;
489 SET_NETDEV_DEV(dev
, &pdev
->dev
);
491 priv
= netdev_priv(dev
);
493 priv
->pci_dev
= pdev
;
496 /* Is this a PCI device? */
500 priv
->adapter
= &board_info
[ent
->driver_data
];
502 rc
= pci_set_dma_mask(pdev
, DMA_BIT_MASK(32));
505 "TLAN: No suitable PCI mapping available.\n");
506 goto err_out_free_dev
;
509 for (reg
= 0; reg
<= 5; reg
++) {
510 if (pci_resource_flags(pdev
, reg
) & IORESOURCE_IO
) {
511 pci_io_base
= pci_resource_start(pdev
, reg
);
512 TLAN_DBG(TLAN_DEBUG_GNRL
,
513 "IO mapping is available at %x.\n",
519 printk(KERN_ERR
"TLAN: No IO mappings available\n");
521 goto err_out_free_dev
;
524 dev
->base_addr
= pci_io_base
;
525 dev
->irq
= pdev
->irq
;
526 priv
->adapter_rev
= pdev
->revision
;
527 pci_set_master(pdev
);
528 pci_set_drvdata(pdev
, dev
);
530 } else { /* EISA card */
531 /* This is a hack. We need to know which board structure
532 * is suited for this adapter */
533 device_id
= inw(ioaddr
+ EISA_ID2
);
535 if (device_id
== 0x20F1) {
536 priv
->adapter
= &board_info
[13]; /* NetFlex-3/E */
537 priv
->adapter_rev
= 23; /* TLAN 2.3 */
539 priv
->adapter
= &board_info
[14];
540 priv
->adapter_rev
= 10; /* TLAN 1.0 */
542 dev
->base_addr
= ioaddr
;
546 /* Kernel parameters */
547 if (dev
->mem_start
) {
548 priv
->aui
= dev
->mem_start
& 0x01;
549 priv
->duplex
= ((dev
->mem_start
& 0x06) == 0x06) ? 0
550 : (dev
->mem_start
& 0x06) >> 1;
551 priv
->speed
= ((dev
->mem_start
& 0x18) == 0x18) ? 0
552 : (dev
->mem_start
& 0x18) >> 3;
554 if (priv
->speed
== 0x1)
555 priv
->speed
= TLAN_SPEED_10
;
556 else if (priv
->speed
== 0x2)
557 priv
->speed
= TLAN_SPEED_100
;
559 debug
= priv
->debug
= dev
->mem_end
;
561 priv
->aui
= aui
[boards_found
];
562 priv
->speed
= speed
[boards_found
];
563 priv
->duplex
= duplex
[boards_found
];
567 /* This will be used when we get an adapter error from
568 * within our irq handler */
569 INIT_WORK(&priv
->tlan_tqueue
, tlan_tx_timeout_work
);
571 spin_lock_init(&priv
->lock
);
575 printk(KERN_ERR
"TLAN: Could not set up device.\n");
576 goto err_out_free_dev
;
579 rc
= register_netdev(dev
);
581 printk(KERN_ERR
"TLAN: Could not register device.\n");
586 tlan_devices_installed
++;
589 /* pdev is NULL if this is an EISA device */
593 priv
->next_device
= tlan_eisa_devices
;
594 tlan_eisa_devices
= dev
;
598 printk(KERN_INFO
"TLAN: %s irq=%2d, io=%04x, %s, Rev. %d\n",
601 (int) dev
->base_addr
,
602 priv
->adapter
->device_label
,
607 pci_free_consistent(priv
->pci_dev
, priv
->dma_size
, priv
->dma_storage
,
608 priv
->dma_storage_dma
);
614 pci_release_regions(pdev
);
618 pci_disable_device(pdev
);
623 static void tlan_eisa_cleanup(void)
625 struct net_device
*dev
;
626 struct tlan_priv
*priv
;
628 while (tlan_have_eisa
) {
629 dev
= tlan_eisa_devices
;
630 priv
= netdev_priv(dev
);
631 if (priv
->dma_storage
) {
632 pci_free_consistent(priv
->pci_dev
, priv
->dma_size
,
634 priv
->dma_storage_dma
);
636 release_region(dev
->base_addr
, 0x10);
637 unregister_netdev(dev
);
638 tlan_eisa_devices
= priv
->next_device
;
645 static void __exit
tlan_exit(void)
647 pci_unregister_driver(&tlan_driver
);
655 /* Module loading/unloading */
656 module_init(tlan_probe
);
657 module_exit(tlan_exit
);
661 /**************************************************************
664 * Returns: 0 on success, 1 otherwise
669 * This functions probes for EISA devices and calls
670 * TLan_probe1 when one is found.
672 *************************************************************/
674 static void __init
tlan_eisa_probe(void)
682 TLAN_DBG(TLAN_DEBUG_PROBE
, "No EISA bus present\n");
686 /* Loop through all slots of the EISA bus */
687 for (ioaddr
= 0x1000; ioaddr
< 0x9000; ioaddr
+= 0x1000) {
689 TLAN_DBG(TLAN_DEBUG_PROBE
, "EISA_ID 0x%4x: 0x%4x\n",
690 (int) ioaddr
+ 0xc80, inw(ioaddr
+ EISA_ID
));
691 TLAN_DBG(TLAN_DEBUG_PROBE
, "EISA_ID 0x%4x: 0x%4x\n",
692 (int) ioaddr
+ 0xc82, inw(ioaddr
+ EISA_ID2
));
695 TLAN_DBG(TLAN_DEBUG_PROBE
,
696 "Probing for EISA adapter at IO: 0x%4x : ",
698 if (request_region(ioaddr
, 0x10, tlan_signature
) == NULL
)
701 if (inw(ioaddr
+ EISA_ID
) != 0x110E) {
702 release_region(ioaddr
, 0x10);
706 device_id
= inw(ioaddr
+ EISA_ID2
);
707 if (device_id
!= 0x20F1 && device_id
!= 0x40F1) {
708 release_region(ioaddr
, 0x10);
712 /* check if adapter is enabled */
713 if (inb(ioaddr
+ EISA_CR
) != 0x1) {
714 release_region(ioaddr
, 0x10);
719 printk(KERN_INFO
"Found one\n");
722 /* Get irq from board */
723 switch (inb(ioaddr
+ 0xcc0)) {
741 /* Setup the newly found eisa adapter */
742 rc
= tlan_probe1(NULL
, ioaddr
, irq
,
748 printk(KERN_INFO
"None found\n");
753 printk(KERN_INFO
"Card found but it is not enabled, skipping\n");
760 #ifdef CONFIG_NET_POLL_CONTROLLER
761 static void tlan_poll(struct net_device
*dev
)
763 disable_irq(dev
->irq
);
764 tlan_handle_interrupt(dev
->irq
, dev
);
765 enable_irq(dev
->irq
);
769 static const struct net_device_ops tlan_netdev_ops
= {
770 .ndo_open
= tlan_open
,
771 .ndo_stop
= tlan_close
,
772 .ndo_start_xmit
= tlan_start_tx
,
773 .ndo_tx_timeout
= tlan_tx_timeout
,
774 .ndo_get_stats
= tlan_get_stats
,
775 .ndo_set_multicast_list
= tlan_set_multicast_list
,
776 .ndo_do_ioctl
= tlan_ioctl
,
777 .ndo_change_mtu
= eth_change_mtu
,
778 .ndo_set_mac_address
= eth_mac_addr
,
779 .ndo_validate_addr
= eth_validate_addr
,
780 #ifdef CONFIG_NET_POLL_CONTROLLER
781 .ndo_poll_controller
= tlan_poll
,
787 /***************************************************************
791 * 0 on success, error code otherwise.
793 * dev The structure of the device to be
796 * This function completes the initialization of the
797 * device structure and driver. It reserves the IO
798 * addresses, allocates memory for the lists and bounce
799 * buffers, retrieves the MAC address from the eeprom
800 * and assignes the device's methods.
802 **************************************************************/
804 static int tlan_init(struct net_device
*dev
)
809 struct tlan_priv
*priv
;
811 priv
= netdev_priv(dev
);
813 dma_size
= (TLAN_NUM_RX_LISTS
+ TLAN_NUM_TX_LISTS
)
814 * (sizeof(struct tlan_list
));
815 priv
->dma_storage
= pci_alloc_consistent(priv
->pci_dev
,
817 &priv
->dma_storage_dma
);
818 priv
->dma_size
= dma_size
;
820 if (priv
->dma_storage
== NULL
) {
822 "TLAN: Could not allocate lists and buffers for %s.\n",
826 memset(priv
->dma_storage
, 0, dma_size
);
827 priv
->rx_list
= (struct tlan_list
*)
828 ALIGN((unsigned long)priv
->dma_storage
, 8);
829 priv
->rx_list_dma
= ALIGN(priv
->dma_storage_dma
, 8);
830 priv
->tx_list
= priv
->rx_list
+ TLAN_NUM_RX_LISTS
;
832 priv
->rx_list_dma
+ sizeof(struct tlan_list
)*TLAN_NUM_RX_LISTS
;
835 for (i
= 0; i
< 6 ; i
++)
836 err
|= tlan_ee_read_byte(dev
,
837 (u8
) priv
->adapter
->addr_ofs
+ i
,
838 (u8
*) &dev
->dev_addr
[i
]);
840 printk(KERN_ERR
"TLAN: %s: Error reading MAC from eeprom: %d\n",
846 netif_carrier_off(dev
);
849 dev
->netdev_ops
= &tlan_netdev_ops
;
850 dev
->watchdog_timeo
= TX_TIMEOUT
;
859 /***************************************************************
863 * 0 on success, error code otherwise.
865 * dev Structure of device to be opened.
867 * This routine puts the driver and TLAN adapter in a
868 * state where it is ready to send and receive packets.
869 * It allocates the IRQ, resets and brings the adapter
870 * out of reset, and allows interrupts. It also delays
871 * the startup for autonegotiation or sends a Rx GO
872 * command to the adapter, as appropriate.
874 **************************************************************/
876 static int tlan_open(struct net_device
*dev
)
878 struct tlan_priv
*priv
= netdev_priv(dev
);
881 priv
->tlan_rev
= tlan_dio_read8(dev
->base_addr
, TLAN_DEF_REVISION
);
882 err
= request_irq(dev
->irq
, tlan_handle_interrupt
, IRQF_SHARED
,
886 pr_err("TLAN: Cannot open %s because IRQ %d is already in use.\n",
887 dev
->name
, dev
->irq
);
891 init_timer(&priv
->timer
);
895 TLAN_DBG(TLAN_DEBUG_GNRL
, "%s: Opened. TLAN Chip Rev: %x\n",
896 dev
->name
, priv
->tlan_rev
);
904 /**************************************************************
908 * 0 on success, error code otherwise
910 * dev structure of device to receive ioctl.
912 * rq ifreq structure to hold userspace data.
917 *************************************************************/
919 static int tlan_ioctl(struct net_device
*dev
, struct ifreq
*rq
, int cmd
)
921 struct tlan_priv
*priv
= netdev_priv(dev
);
922 struct mii_ioctl_data
*data
= if_mii(rq
);
923 u32 phy
= priv
->phy
[priv
->phy_num
];
925 if (!priv
->phy_online
)
929 case SIOCGMIIPHY
: /* get address of MII PHY in use. */
933 case SIOCGMIIREG
: /* read MII PHY register. */
934 tlan_mii_read_reg(dev
, data
->phy_id
& 0x1f,
935 data
->reg_num
& 0x1f, &data
->val_out
);
939 case SIOCSMIIREG
: /* write MII PHY register. */
940 tlan_mii_write_reg(dev
, data
->phy_id
& 0x1f,
941 data
->reg_num
& 0x1f, data
->val_in
);
949 /***************************************************************
955 * dev structure of device which timed out
958 **************************************************************/
960 static void tlan_tx_timeout(struct net_device
*dev
)
963 TLAN_DBG(TLAN_DEBUG_GNRL
, "%s: Transmit timed out.\n", dev
->name
);
965 /* Ok so we timed out, lets see what we can do about it...*/
966 tlan_free_lists(dev
);
967 tlan_reset_lists(dev
);
968 tlan_read_and_clear_stats(dev
, TLAN_IGNORE
);
969 tlan_reset_adapter(dev
);
970 dev
->trans_start
= jiffies
; /* prevent tx timeout */
971 netif_wake_queue(dev
);
976 /***************************************************************
977 * tlan_tx_timeout_work
982 * work work item of device which timed out
984 **************************************************************/
986 static void tlan_tx_timeout_work(struct work_struct
*work
)
988 struct tlan_priv
*priv
=
989 container_of(work
, struct tlan_priv
, tlan_tqueue
);
991 tlan_tx_timeout(priv
->dev
);
996 /***************************************************************
1000 * 0 on success, non-zero on failure.
1002 * skb A pointer to the sk_buff containing the
1004 * dev The device to send the data on.
1006 * This function adds a frame to the Tx list to be sent
1007 * ASAP. First it verifies that the adapter is ready and
1008 * there is room in the queue. Then it sets up the next
1009 * available list, copies the frame to the corresponding
1010 * buffer. If the adapter Tx channel is idle, it gives
1011 * the adapter a Tx Go command on the list, otherwise it
1012 * sets the forward address of the previous list to point
1013 * to this one. Then it frees the sk_buff.
1015 **************************************************************/
1017 static netdev_tx_t
tlan_start_tx(struct sk_buff
*skb
, struct net_device
*dev
)
1019 struct tlan_priv
*priv
= netdev_priv(dev
);
1020 dma_addr_t tail_list_phys
;
1021 struct tlan_list
*tail_list
;
1022 unsigned long flags
;
1025 if (!priv
->phy_online
) {
1026 TLAN_DBG(TLAN_DEBUG_TX
, "TRANSMIT: %s PHY is not ready\n",
1028 dev_kfree_skb_any(skb
);
1029 return NETDEV_TX_OK
;
1032 if (skb_padto(skb
, TLAN_MIN_FRAME_SIZE
))
1033 return NETDEV_TX_OK
;
1034 txlen
= max(skb
->len
, (unsigned int)TLAN_MIN_FRAME_SIZE
);
1036 tail_list
= priv
->tx_list
+ priv
->tx_tail
;
1038 priv
->tx_list_dma
+ sizeof(struct tlan_list
)*priv
->tx_tail
;
1040 if (tail_list
->c_stat
!= TLAN_CSTAT_UNUSED
) {
1041 TLAN_DBG(TLAN_DEBUG_TX
,
1042 "TRANSMIT: %s is busy (Head=%d Tail=%d)\n",
1043 dev
->name
, priv
->tx_head
, priv
->tx_tail
);
1044 netif_stop_queue(dev
);
1045 priv
->tx_busy_count
++;
1046 return NETDEV_TX_BUSY
;
1049 tail_list
->forward
= 0;
1051 tail_list
->buffer
[0].address
= pci_map_single(priv
->pci_dev
,
1054 tlan_store_skb(tail_list
, skb
);
1056 tail_list
->frame_size
= (u16
) txlen
;
1057 tail_list
->buffer
[0].count
= TLAN_LAST_BUFFER
| (u32
) txlen
;
1058 tail_list
->buffer
[1].count
= 0;
1059 tail_list
->buffer
[1].address
= 0;
1061 spin_lock_irqsave(&priv
->lock
, flags
);
1062 tail_list
->c_stat
= TLAN_CSTAT_READY
;
1063 if (!priv
->tx_in_progress
) {
1064 priv
->tx_in_progress
= 1;
1065 TLAN_DBG(TLAN_DEBUG_TX
,
1066 "TRANSMIT: Starting TX on buffer %d\n",
1068 outl(tail_list_phys
, dev
->base_addr
+ TLAN_CH_PARM
);
1069 outl(TLAN_HC_GO
, dev
->base_addr
+ TLAN_HOST_CMD
);
1071 TLAN_DBG(TLAN_DEBUG_TX
,
1072 "TRANSMIT: Adding buffer %d to TX channel\n",
1074 if (priv
->tx_tail
== 0) {
1075 (priv
->tx_list
+ (TLAN_NUM_TX_LISTS
- 1))->forward
1078 (priv
->tx_list
+ (priv
->tx_tail
- 1))->forward
1082 spin_unlock_irqrestore(&priv
->lock
, flags
);
1084 CIRC_INC(priv
->tx_tail
, TLAN_NUM_TX_LISTS
);
1086 return NETDEV_TX_OK
;
1093 /***************************************************************
1094 * tlan_handle_interrupt
1099 * irq The line on which the interrupt
1101 * dev_id A pointer to the device assigned to
1104 * This function handles an interrupt generated by its
1105 * assigned TLAN adapter. The function deactivates
1106 * interrupts on its adapter, records the type of
1107 * interrupt, executes the appropriate subhandler, and
1108 * acknowdges the interrupt to the adapter (thus
1109 * re-enabling adapter interrupts.
1111 **************************************************************/
1113 static irqreturn_t
tlan_handle_interrupt(int irq
, void *dev_id
)
1115 struct net_device
*dev
= dev_id
;
1116 struct tlan_priv
*priv
= netdev_priv(dev
);
1120 spin_lock(&priv
->lock
);
1122 host_int
= inw(dev
->base_addr
+ TLAN_HOST_INT
);
1123 type
= (host_int
& TLAN_HI_IT_MASK
) >> 2;
1128 outw(host_int
, dev
->base_addr
+ TLAN_HOST_INT
);
1129 ack
= tlan_int_vector
[type
](dev
, host_int
);
1132 host_cmd
= TLAN_HC_ACK
| ack
| (type
<< 18);
1133 outl(host_cmd
, dev
->base_addr
+ TLAN_HOST_CMD
);
1137 spin_unlock(&priv
->lock
);
1139 return IRQ_RETVAL(type
);
1145 /***************************************************************
1151 * dev The device structure of the device to
1154 * This function shuts down the adapter. It records any
1155 * stats, puts the adapter into reset state, deactivates
1156 * its time as needed, and frees the irq it is using.
1158 **************************************************************/
1160 static int tlan_close(struct net_device
*dev
)
1162 struct tlan_priv
*priv
= netdev_priv(dev
);
1164 priv
->neg_be_verbose
= 0;
1167 free_irq(dev
->irq
, dev
);
1168 tlan_free_lists(dev
);
1169 TLAN_DBG(TLAN_DEBUG_GNRL
, "Device %s closed.\n", dev
->name
);
1178 /***************************************************************
1182 * A pointer to the device's statistics structure.
1184 * dev The device structure to return the
1187 * This function updates the devices statistics by reading
1188 * the TLAN chip's onboard registers. Then it returns the
1189 * address of the statistics structure.
1191 **************************************************************/
1193 static struct net_device_stats
*tlan_get_stats(struct net_device
*dev
)
1195 struct tlan_priv
*priv
= netdev_priv(dev
);
1198 /* Should only read stats if open ? */
1199 tlan_read_and_clear_stats(dev
, TLAN_RECORD
);
1201 TLAN_DBG(TLAN_DEBUG_RX
, "RECEIVE: %s EOC count = %d\n", dev
->name
,
1202 priv
->rx_eoc_count
);
1203 TLAN_DBG(TLAN_DEBUG_TX
, "TRANSMIT: %s Busy count = %d\n", dev
->name
,
1204 priv
->tx_busy_count
);
1205 if (debug
& TLAN_DEBUG_GNRL
) {
1206 tlan_print_dio(dev
->base_addr
);
1207 tlan_phy_print(dev
);
1209 if (debug
& TLAN_DEBUG_LIST
) {
1210 for (i
= 0; i
< TLAN_NUM_RX_LISTS
; i
++)
1211 tlan_print_list(priv
->rx_list
+ i
, "RX", i
);
1212 for (i
= 0; i
< TLAN_NUM_TX_LISTS
; i
++)
1213 tlan_print_list(priv
->tx_list
+ i
, "TX", i
);
1223 /***************************************************************
1224 * tlan_set_multicast_list
1229 * dev The device structure to set the
1230 * multicast list for.
1232 * This function sets the TLAN adaptor to various receive
1233 * modes. If the IFF_PROMISC flag is set, promiscuous
1234 * mode is acitviated. Otherwise, promiscuous mode is
1235 * turned off. If the IFF_ALLMULTI flag is set, then
1236 * the hash table is set to receive all group addresses.
1237 * Otherwise, the first three multicast addresses are
1238 * stored in AREG_1-3, and the rest are selected via the
1239 * hash table, as necessary.
1241 **************************************************************/
1243 static void tlan_set_multicast_list(struct net_device
*dev
)
1245 struct netdev_hw_addr
*ha
;
1252 if (dev
->flags
& IFF_PROMISC
) {
1253 tmp
= tlan_dio_read8(dev
->base_addr
, TLAN_NET_CMD
);
1254 tlan_dio_write8(dev
->base_addr
,
1255 TLAN_NET_CMD
, tmp
| TLAN_NET_CMD_CAF
);
1257 tmp
= tlan_dio_read8(dev
->base_addr
, TLAN_NET_CMD
);
1258 tlan_dio_write8(dev
->base_addr
,
1259 TLAN_NET_CMD
, tmp
& ~TLAN_NET_CMD_CAF
);
1260 if (dev
->flags
& IFF_ALLMULTI
) {
1261 for (i
= 0; i
< 3; i
++)
1262 tlan_set_mac(dev
, i
+ 1, NULL
);
1263 tlan_dio_write32(dev
->base_addr
, TLAN_HASH_1
,
1265 tlan_dio_write32(dev
->base_addr
, TLAN_HASH_2
,
1269 netdev_for_each_mc_addr(ha
, dev
) {
1271 tlan_set_mac(dev
, i
+ 1,
1272 (char *) &ha
->addr
);
1275 tlan_hash_func((u8
*)&ha
->addr
);
1277 hash1
|= (1 << offset
);
1279 hash2
|= (1 << (offset
- 32));
1284 tlan_set_mac(dev
, i
+ 1, NULL
);
1285 tlan_dio_write32(dev
->base_addr
, TLAN_HASH_1
, hash1
);
1286 tlan_dio_write32(dev
->base_addr
, TLAN_HASH_2
, hash2
);
1294 /*****************************************************************************
1295 ******************************************************************************
1297 ThunderLAN driver interrupt vectors and table
1299 please see chap. 4, "Interrupt Handling" of the "ThunderLAN
1300 Programmer's Guide" for more informations on handling interrupts
1301 generated by TLAN based adapters.
1303 ******************************************************************************
1304 *****************************************************************************/
1309 /***************************************************************
1310 * tlan_handle_tx_eof
1315 * dev Device assigned the IRQ that was
1317 * host_int The contents of the HOST_INT
1320 * This function handles Tx EOF interrupts which are raised
1321 * by the adapter when it has completed sending the
1322 * contents of a buffer. If detemines which list/buffer
1323 * was completed and resets it. If the buffer was the last
1324 * in the channel (EOC), then the function checks to see if
1325 * another buffer is ready to send, and if so, sends a Tx
1326 * Go command. Finally, the driver activates/continues the
1329 **************************************************************/
1331 static u32
tlan_handle_tx_eof(struct net_device
*dev
, u16 host_int
)
1333 struct tlan_priv
*priv
= netdev_priv(dev
);
1335 struct tlan_list
*head_list
;
1336 dma_addr_t head_list_phys
;
1340 TLAN_DBG(TLAN_DEBUG_TX
,
1341 "TRANSMIT: Handling TX EOF (Head=%d Tail=%d)\n",
1342 priv
->tx_head
, priv
->tx_tail
);
1343 head_list
= priv
->tx_list
+ priv
->tx_head
;
1345 while (((tmp_c_stat
= head_list
->c_stat
) & TLAN_CSTAT_FRM_CMP
)
1347 struct sk_buff
*skb
= tlan_get_skb(head_list
);
1350 pci_unmap_single(priv
->pci_dev
, head_list
->buffer
[0].address
,
1352 (unsigned int)TLAN_MIN_FRAME_SIZE
),
1354 dev_kfree_skb_any(skb
);
1355 head_list
->buffer
[8].address
= 0;
1356 head_list
->buffer
[9].address
= 0;
1358 if (tmp_c_stat
& TLAN_CSTAT_EOC
)
1361 dev
->stats
.tx_bytes
+= head_list
->frame_size
;
1363 head_list
->c_stat
= TLAN_CSTAT_UNUSED
;
1364 netif_start_queue(dev
);
1365 CIRC_INC(priv
->tx_head
, TLAN_NUM_TX_LISTS
);
1366 head_list
= priv
->tx_list
+ priv
->tx_head
;
1371 "TLAN: Received interrupt for uncompleted TX frame.\n");
1374 TLAN_DBG(TLAN_DEBUG_TX
,
1375 "TRANSMIT: handling TX EOC (Head=%d Tail=%d)\n",
1376 priv
->tx_head
, priv
->tx_tail
);
1377 head_list
= priv
->tx_list
+ priv
->tx_head
;
1378 head_list_phys
= priv
->tx_list_dma
1379 + sizeof(struct tlan_list
)*priv
->tx_head
;
1380 if ((head_list
->c_stat
& TLAN_CSTAT_READY
)
1381 == TLAN_CSTAT_READY
) {
1382 outl(head_list_phys
, dev
->base_addr
+ TLAN_CH_PARM
);
1385 priv
->tx_in_progress
= 0;
1389 if (priv
->adapter
->flags
& TLAN_ADAPTER_ACTIVITY_LED
) {
1390 tlan_dio_write8(dev
->base_addr
,
1391 TLAN_LED_REG
, TLAN_LED_LINK
| TLAN_LED_ACT
);
1392 if (priv
->timer
.function
== NULL
) {
1393 priv
->timer
.function
= tlan_timer
;
1394 priv
->timer
.data
= (unsigned long) dev
;
1395 priv
->timer
.expires
= jiffies
+ TLAN_TIMER_ACT_DELAY
;
1396 priv
->timer_set_at
= jiffies
;
1397 priv
->timer_type
= TLAN_TIMER_ACTIVITY
;
1398 add_timer(&priv
->timer
);
1399 } else if (priv
->timer_type
== TLAN_TIMER_ACTIVITY
) {
1400 priv
->timer_set_at
= jiffies
;
1411 /***************************************************************
1412 * TLan_HandleStatOverflow
1417 * dev Device assigned the IRQ that was
1419 * host_int The contents of the HOST_INT
1422 * This function handles the Statistics Overflow interrupt
1423 * which means that one or more of the TLAN statistics
1424 * registers has reached 1/2 capacity and needs to be read.
1426 **************************************************************/
1428 static u32
tlan_handle_stat_overflow(struct net_device
*dev
, u16 host_int
)
1430 tlan_read_and_clear_stats(dev
, TLAN_RECORD
);
1439 /***************************************************************
1445 * dev Device assigned the IRQ that was
1447 * host_int The contents of the HOST_INT
1450 * This function handles the Rx EOF interrupt which
1451 * indicates a frame has been received by the adapter from
1452 * the net and the frame has been transferred to memory.
1453 * The function determines the bounce buffer the frame has
1454 * been loaded into, creates a new sk_buff big enough to
1455 * hold the frame, and sends it to protocol stack. It
1456 * then resets the used buffer and appends it to the end
1457 * of the list. If the frame was the last in the Rx
1458 * channel (EOC), the function restarts the receive channel
1459 * by sending an Rx Go command to the adapter. Then it
1460 * activates/continues the activity LED.
1462 **************************************************************/
1464 static u32
tlan_handle_rx_eof(struct net_device
*dev
, u16 host_int
)
1466 struct tlan_priv
*priv
= netdev_priv(dev
);
1469 struct tlan_list
*head_list
;
1470 struct sk_buff
*skb
;
1471 struct tlan_list
*tail_list
;
1473 dma_addr_t head_list_phys
;
1475 TLAN_DBG(TLAN_DEBUG_RX
, "RECEIVE: handling RX EOF (Head=%d Tail=%d)\n",
1476 priv
->rx_head
, priv
->rx_tail
);
1477 head_list
= priv
->rx_list
+ priv
->rx_head
;
1479 priv
->rx_list_dma
+ sizeof(struct tlan_list
)*priv
->rx_head
;
1481 while (((tmp_c_stat
= head_list
->c_stat
) & TLAN_CSTAT_FRM_CMP
)
1483 dma_addr_t frame_dma
= head_list
->buffer
[0].address
;
1484 u32 frame_size
= head_list
->frame_size
;
1485 struct sk_buff
*new_skb
;
1488 if (tmp_c_stat
& TLAN_CSTAT_EOC
)
1491 new_skb
= netdev_alloc_skb_ip_align(dev
,
1492 TLAN_MAX_FRAME_SIZE
+ 5);
1494 goto drop_and_reuse
;
1496 skb
= tlan_get_skb(head_list
);
1497 pci_unmap_single(priv
->pci_dev
, frame_dma
,
1498 TLAN_MAX_FRAME_SIZE
, PCI_DMA_FROMDEVICE
);
1499 skb_put(skb
, frame_size
);
1501 dev
->stats
.rx_bytes
+= frame_size
;
1503 skb
->protocol
= eth_type_trans(skb
, dev
);
1506 head_list
->buffer
[0].address
=
1507 pci_map_single(priv
->pci_dev
, new_skb
->data
,
1508 TLAN_MAX_FRAME_SIZE
, PCI_DMA_FROMDEVICE
);
1510 tlan_store_skb(head_list
, new_skb
);
1512 head_list
->forward
= 0;
1513 head_list
->c_stat
= 0;
1514 tail_list
= priv
->rx_list
+ priv
->rx_tail
;
1515 tail_list
->forward
= head_list_phys
;
1517 CIRC_INC(priv
->rx_head
, TLAN_NUM_RX_LISTS
);
1518 CIRC_INC(priv
->rx_tail
, TLAN_NUM_RX_LISTS
);
1519 head_list
= priv
->rx_list
+ priv
->rx_head
;
1520 head_list_phys
= priv
->rx_list_dma
1521 + sizeof(struct tlan_list
)*priv
->rx_head
;
1526 "TLAN: Received interrupt for uncompleted RX frame.\n");
1530 TLAN_DBG(TLAN_DEBUG_RX
,
1531 "RECEIVE: handling RX EOC (Head=%d Tail=%d)\n",
1532 priv
->rx_head
, priv
->rx_tail
);
1533 head_list
= priv
->rx_list
+ priv
->rx_head
;
1534 head_list_phys
= priv
->rx_list_dma
1535 + sizeof(struct tlan_list
)*priv
->rx_head
;
1536 outl(head_list_phys
, dev
->base_addr
+ TLAN_CH_PARM
);
1537 ack
|= TLAN_HC_GO
| TLAN_HC_RT
;
1538 priv
->rx_eoc_count
++;
1541 if (priv
->adapter
->flags
& TLAN_ADAPTER_ACTIVITY_LED
) {
1542 tlan_dio_write8(dev
->base_addr
,
1543 TLAN_LED_REG
, TLAN_LED_LINK
| TLAN_LED_ACT
);
1544 if (priv
->timer
.function
== NULL
) {
1545 priv
->timer
.function
= tlan_timer
;
1546 priv
->timer
.data
= (unsigned long) dev
;
1547 priv
->timer
.expires
= jiffies
+ TLAN_TIMER_ACT_DELAY
;
1548 priv
->timer_set_at
= jiffies
;
1549 priv
->timer_type
= TLAN_TIMER_ACTIVITY
;
1550 add_timer(&priv
->timer
);
1551 } else if (priv
->timer_type
== TLAN_TIMER_ACTIVITY
) {
1552 priv
->timer_set_at
= jiffies
;
1563 /***************************************************************
1569 * dev Device assigned the IRQ that was
1571 * host_int The contents of the HOST_INT
1574 * This function handles the Dummy interrupt, which is
1575 * raised whenever a test interrupt is generated by setting
1576 * the Req_Int bit of HOST_CMD to 1.
1578 **************************************************************/
1580 static u32
tlan_handle_dummy(struct net_device
*dev
, u16 host_int
)
1582 pr_info("TLAN: Test interrupt on %s.\n", dev
->name
);
1590 /***************************************************************
1591 * tlan_handle_tx_eoc
1596 * dev Device assigned the IRQ that was
1598 * host_int The contents of the HOST_INT
1601 * This driver is structured to determine EOC occurrences by
1602 * reading the CSTAT member of the list structure. Tx EOC
1603 * interrupts are disabled via the DIO INTDIS register.
1604 * However, TLAN chips before revision 3.0 didn't have this
1605 * functionality, so process EOC events if this is the
1608 **************************************************************/
1610 static u32
tlan_handle_tx_eoc(struct net_device
*dev
, u16 host_int
)
1612 struct tlan_priv
*priv
= netdev_priv(dev
);
1613 struct tlan_list
*head_list
;
1614 dma_addr_t head_list_phys
;
1618 if (priv
->tlan_rev
< 0x30) {
1619 TLAN_DBG(TLAN_DEBUG_TX
,
1620 "TRANSMIT: handling TX EOC (Head=%d Tail=%d) -- IRQ\n",
1621 priv
->tx_head
, priv
->tx_tail
);
1622 head_list
= priv
->tx_list
+ priv
->tx_head
;
1623 head_list_phys
= priv
->tx_list_dma
1624 + sizeof(struct tlan_list
)*priv
->tx_head
;
1625 if ((head_list
->c_stat
& TLAN_CSTAT_READY
)
1626 == TLAN_CSTAT_READY
) {
1627 netif_stop_queue(dev
);
1628 outl(head_list_phys
, dev
->base_addr
+ TLAN_CH_PARM
);
1631 priv
->tx_in_progress
= 0;
1642 /***************************************************************
1643 * tlan_handle_status_check
1646 * 0 if Adapter check, 1 if Network Status check.
1648 * dev Device assigned the IRQ that was
1650 * host_int The contents of the HOST_INT
1653 * This function handles Adapter Check/Network Status
1654 * interrupts generated by the adapter. It checks the
1655 * vector in the HOST_INT register to determine if it is
1656 * an Adapter Check interrupt. If so, it resets the
1657 * adapter. Otherwise it clears the status registers
1658 * and services the PHY.
1660 **************************************************************/
1662 static u32
tlan_handle_status_check(struct net_device
*dev
, u16 host_int
)
1664 struct tlan_priv
*priv
= netdev_priv(dev
);
1673 if (host_int
& TLAN_HI_IV_MASK
) {
1674 netif_stop_queue(dev
);
1675 error
= inl(dev
->base_addr
+ TLAN_CH_PARM
);
1676 pr_info("TLAN: %s: Adaptor Error = 0x%x\n", dev
->name
, error
);
1677 tlan_read_and_clear_stats(dev
, TLAN_RECORD
);
1678 outl(TLAN_HC_AD_RST
, dev
->base_addr
+ TLAN_HOST_CMD
);
1680 schedule_work(&priv
->tlan_tqueue
);
1682 netif_wake_queue(dev
);
1685 TLAN_DBG(TLAN_DEBUG_GNRL
, "%s: Status Check\n", dev
->name
);
1686 phy
= priv
->phy
[priv
->phy_num
];
1688 net_sts
= tlan_dio_read8(dev
->base_addr
, TLAN_NET_STS
);
1690 tlan_dio_write8(dev
->base_addr
, TLAN_NET_STS
, net_sts
);
1691 TLAN_DBG(TLAN_DEBUG_GNRL
, "%s: Net_Sts = %x\n",
1692 dev
->name
, (unsigned) net_sts
);
1694 if ((net_sts
& TLAN_NET_STS_MIRQ
) && (priv
->phy_num
== 0)) {
1695 tlan_mii_read_reg(dev
, phy
, TLAN_TLPHY_STS
, &tlphy_sts
);
1696 tlan_mii_read_reg(dev
, phy
, TLAN_TLPHY_CTL
, &tlphy_ctl
);
1697 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
,
1702 } else if ((tlphy_sts
& TLAN_TS_POLOK
) &&
1703 (tlphy_ctl
& TLAN_TC_SWAPOL
)) {
1704 tlphy_ctl
&= ~TLAN_TC_SWAPOL
;
1705 tlan_mii_write_reg(dev
, phy
, TLAN_TLPHY_CTL
,
1710 tlan_phy_print(dev
);
1721 /***************************************************************
1722 * tlan_handle_rx_eoc
1727 * dev Device assigned the IRQ that was
1729 * host_int The contents of the HOST_INT
1732 * This driver is structured to determine EOC occurrences by
1733 * reading the CSTAT member of the list structure. Rx EOC
1734 * interrupts are disabled via the DIO INTDIS register.
1735 * However, TLAN chips before revision 3.0 didn't have this
1736 * CSTAT member or a INTDIS register, so if this chip is
1737 * pre-3.0, process EOC interrupts normally.
1739 **************************************************************/
1741 static u32
tlan_handle_rx_eoc(struct net_device
*dev
, u16 host_int
)
1743 struct tlan_priv
*priv
= netdev_priv(dev
);
1744 dma_addr_t head_list_phys
;
1747 if (priv
->tlan_rev
< 0x30) {
1748 TLAN_DBG(TLAN_DEBUG_RX
,
1749 "RECEIVE: Handling RX EOC (head=%d tail=%d) -- IRQ\n",
1750 priv
->rx_head
, priv
->rx_tail
);
1751 head_list_phys
= priv
->rx_list_dma
1752 + sizeof(struct tlan_list
)*priv
->rx_head
;
1753 outl(head_list_phys
, dev
->base_addr
+ TLAN_CH_PARM
);
1754 ack
|= TLAN_HC_GO
| TLAN_HC_RT
;
1755 priv
->rx_eoc_count
++;
1765 /*****************************************************************************
1766 ******************************************************************************
1768 ThunderLAN driver timer function
1770 ******************************************************************************
1771 *****************************************************************************/
1774 /***************************************************************
1780 * data A value given to add timer when
1781 * add_timer was called.
1783 * This function handles timed functionality for the
1784 * TLAN driver. The two current timer uses are for
1785 * delaying for autonegotionation and driving the ACT LED.
1786 * - Autonegotiation requires being allowed about
1787 * 2 1/2 seconds before attempting to transmit a
1788 * packet. It would be a very bad thing to hang
1789 * the kernel this long, so the driver doesn't
1790 * allow transmission 'til after this time, for
1791 * certain PHYs. It would be much nicer if all
1792 * PHYs were interrupt-capable like the internal
1794 * - The ACT LED, which shows adapter activity, is
1795 * driven by the driver, and so must be left on
1796 * for a short period to power up the LED so it
1797 * can be seen. This delay can be changed by
1798 * changing the TLAN_TIMER_ACT_DELAY in tlan.h,
1799 * if desired. 100 ms produces a slightly
1800 * sluggish response.
1802 **************************************************************/
1804 static void tlan_timer(unsigned long data
)
1806 struct net_device
*dev
= (struct net_device
*) data
;
1807 struct tlan_priv
*priv
= netdev_priv(dev
);
1809 unsigned long flags
= 0;
1811 priv
->timer
.function
= NULL
;
1813 switch (priv
->timer_type
) {
1815 case TLAN_TIMER_LINK_BEAT
:
1816 tlan_phy_monitor(dev
);
1819 case TLAN_TIMER_PHY_PDOWN
:
1820 tlan_phy_power_down(dev
);
1822 case TLAN_TIMER_PHY_PUP
:
1823 tlan_phy_power_up(dev
);
1825 case TLAN_TIMER_PHY_RESET
:
1826 tlan_phy_reset(dev
);
1828 case TLAN_TIMER_PHY_START_LINK
:
1829 tlan_phy_start_link(dev
);
1831 case TLAN_TIMER_PHY_FINISH_AN
:
1832 tlan_phy_finish_auto_neg(dev
);
1834 case TLAN_TIMER_FINISH_RESET
:
1835 tlan_finish_reset(dev
);
1837 case TLAN_TIMER_ACTIVITY
:
1838 spin_lock_irqsave(&priv
->lock
, flags
);
1839 if (priv
->timer
.function
== NULL
) {
1840 elapsed
= jiffies
- priv
->timer_set_at
;
1841 if (elapsed
>= TLAN_TIMER_ACT_DELAY
) {
1842 tlan_dio_write8(dev
->base_addr
,
1843 TLAN_LED_REG
, TLAN_LED_LINK
);
1845 priv
->timer
.function
= tlan_timer
;
1846 priv
->timer
.expires
= priv
->timer_set_at
1847 + TLAN_TIMER_ACT_DELAY
;
1848 spin_unlock_irqrestore(&priv
->lock
, flags
);
1849 add_timer(&priv
->timer
);
1853 spin_unlock_irqrestore(&priv
->lock
, flags
);
1864 /*****************************************************************************
1865 ******************************************************************************
1867 ThunderLAN driver adapter related routines
1869 ******************************************************************************
1870 *****************************************************************************/
1873 /***************************************************************
1879 * dev The device structure with the list
1880 * stuctures to be reset.
1882 * This routine sets the variables associated with managing
1883 * the TLAN lists to their initial values.
1885 **************************************************************/
1887 static void tlan_reset_lists(struct net_device
*dev
)
1889 struct tlan_priv
*priv
= netdev_priv(dev
);
1891 struct tlan_list
*list
;
1892 dma_addr_t list_phys
;
1893 struct sk_buff
*skb
;
1897 for (i
= 0; i
< TLAN_NUM_TX_LISTS
; i
++) {
1898 list
= priv
->tx_list
+ i
;
1899 list
->c_stat
= TLAN_CSTAT_UNUSED
;
1900 list
->buffer
[0].address
= 0;
1901 list
->buffer
[2].count
= 0;
1902 list
->buffer
[2].address
= 0;
1903 list
->buffer
[8].address
= 0;
1904 list
->buffer
[9].address
= 0;
1908 priv
->rx_tail
= TLAN_NUM_RX_LISTS
- 1;
1909 for (i
= 0; i
< TLAN_NUM_RX_LISTS
; i
++) {
1910 list
= priv
->rx_list
+ i
;
1911 list_phys
= priv
->rx_list_dma
+ sizeof(struct tlan_list
)*i
;
1912 list
->c_stat
= TLAN_CSTAT_READY
;
1913 list
->frame_size
= TLAN_MAX_FRAME_SIZE
;
1914 list
->buffer
[0].count
= TLAN_MAX_FRAME_SIZE
| TLAN_LAST_BUFFER
;
1915 skb
= netdev_alloc_skb_ip_align(dev
, TLAN_MAX_FRAME_SIZE
+ 5);
1917 pr_err("TLAN: out of memory for received data.\n");
1921 list
->buffer
[0].address
= pci_map_single(priv
->pci_dev
,
1923 TLAN_MAX_FRAME_SIZE
,
1924 PCI_DMA_FROMDEVICE
);
1925 tlan_store_skb(list
, skb
);
1926 list
->buffer
[1].count
= 0;
1927 list
->buffer
[1].address
= 0;
1928 list
->forward
= list_phys
+ sizeof(struct tlan_list
);
1931 /* in case ran out of memory early, clear bits */
1932 while (i
< TLAN_NUM_RX_LISTS
) {
1933 tlan_store_skb(priv
->rx_list
+ i
, NULL
);
1941 static void tlan_free_lists(struct net_device
*dev
)
1943 struct tlan_priv
*priv
= netdev_priv(dev
);
1945 struct tlan_list
*list
;
1946 struct sk_buff
*skb
;
1948 for (i
= 0; i
< TLAN_NUM_TX_LISTS
; i
++) {
1949 list
= priv
->tx_list
+ i
;
1950 skb
= tlan_get_skb(list
);
1954 list
->buffer
[0].address
,
1956 (unsigned int)TLAN_MIN_FRAME_SIZE
),
1958 dev_kfree_skb_any(skb
);
1959 list
->buffer
[8].address
= 0;
1960 list
->buffer
[9].address
= 0;
1964 for (i
= 0; i
< TLAN_NUM_RX_LISTS
; i
++) {
1965 list
= priv
->rx_list
+ i
;
1966 skb
= tlan_get_skb(list
);
1968 pci_unmap_single(priv
->pci_dev
,
1969 list
->buffer
[0].address
,
1970 TLAN_MAX_FRAME_SIZE
,
1971 PCI_DMA_FROMDEVICE
);
1972 dev_kfree_skb_any(skb
);
1973 list
->buffer
[8].address
= 0;
1974 list
->buffer
[9].address
= 0;
1982 /***************************************************************
1988 * io_base Base IO port of the device of
1989 * which to print DIO registers.
1991 * This function prints out all the internal (DIO)
1992 * registers of a TLAN chip.
1994 **************************************************************/
1996 static void tlan_print_dio(u16 io_base
)
2001 pr_info("TLAN: Contents of internal registers for io base 0x%04hx.\n",
2003 pr_info("TLAN: Off. +0 +4\n");
2004 for (i
= 0; i
< 0x4C; i
+= 8) {
2005 data0
= tlan_dio_read32(io_base
, i
);
2006 data1
= tlan_dio_read32(io_base
, i
+ 0x4);
2007 pr_info("TLAN: 0x%02x 0x%08x 0x%08x\n", i
, data0
, data1
);
2015 /***************************************************************
2021 * list A pointer to the struct tlan_list structure to
2023 * type A string to designate type of list,
2025 * num The index of the list.
2027 * This function prints out the contents of the list
2028 * pointed to by the list parameter.
2030 **************************************************************/
2032 static void tlan_print_list(struct tlan_list
*list
, char *type
, int num
)
2036 pr_info("TLAN: %s List %d at %p\n", type
, num
, list
);
2037 pr_info("TLAN: Forward = 0x%08x\n", list
->forward
);
2038 pr_info("TLAN: CSTAT = 0x%04hx\n", list
->c_stat
);
2039 pr_info("TLAN: Frame Size = 0x%04hx\n", list
->frame_size
);
2040 /* for (i = 0; i < 10; i++) { */
2041 for (i
= 0; i
< 2; i
++) {
2042 pr_info("TLAN: Buffer[%d].count, addr = 0x%08x, 0x%08x\n",
2043 i
, list
->buffer
[i
].count
, list
->buffer
[i
].address
);
2051 /***************************************************************
2052 * tlan_read_and_clear_stats
2057 * dev Pointer to device structure of adapter
2058 * to which to read stats.
2059 * record Flag indicating whether to add
2061 * This functions reads all the internal status registers
2062 * of the TLAN chip, which clears them as a side effect.
2063 * It then either adds the values to the device's status
2064 * struct, or discards them, depending on whether record
2065 * is TLAN_RECORD (!=0) or TLAN_IGNORE (==0).
2067 **************************************************************/
2069 static void tlan_read_and_clear_stats(struct net_device
*dev
, int record
)
2071 u32 tx_good
, tx_under
;
2072 u32 rx_good
, rx_over
;
2073 u32 def_tx
, crc
, code
;
2074 u32 multi_col
, single_col
;
2075 u32 excess_col
, late_col
, loss
;
2077 outw(TLAN_GOOD_TX_FRMS
, dev
->base_addr
+ TLAN_DIO_ADR
);
2078 tx_good
= inb(dev
->base_addr
+ TLAN_DIO_DATA
);
2079 tx_good
+= inb(dev
->base_addr
+ TLAN_DIO_DATA
+ 1) << 8;
2080 tx_good
+= inb(dev
->base_addr
+ TLAN_DIO_DATA
+ 2) << 16;
2081 tx_under
= inb(dev
->base_addr
+ TLAN_DIO_DATA
+ 3);
2083 outw(TLAN_GOOD_RX_FRMS
, dev
->base_addr
+ TLAN_DIO_ADR
);
2084 rx_good
= inb(dev
->base_addr
+ TLAN_DIO_DATA
);
2085 rx_good
+= inb(dev
->base_addr
+ TLAN_DIO_DATA
+ 1) << 8;
2086 rx_good
+= inb(dev
->base_addr
+ TLAN_DIO_DATA
+ 2) << 16;
2087 rx_over
= inb(dev
->base_addr
+ TLAN_DIO_DATA
+ 3);
2089 outw(TLAN_DEFERRED_TX
, dev
->base_addr
+ TLAN_DIO_ADR
);
2090 def_tx
= inb(dev
->base_addr
+ TLAN_DIO_DATA
);
2091 def_tx
+= inb(dev
->base_addr
+ TLAN_DIO_DATA
+ 1) << 8;
2092 crc
= inb(dev
->base_addr
+ TLAN_DIO_DATA
+ 2);
2093 code
= inb(dev
->base_addr
+ TLAN_DIO_DATA
+ 3);
2095 outw(TLAN_MULTICOL_FRMS
, dev
->base_addr
+ TLAN_DIO_ADR
);
2096 multi_col
= inb(dev
->base_addr
+ TLAN_DIO_DATA
);
2097 multi_col
+= inb(dev
->base_addr
+ TLAN_DIO_DATA
+ 1) << 8;
2098 single_col
= inb(dev
->base_addr
+ TLAN_DIO_DATA
+ 2);
2099 single_col
+= inb(dev
->base_addr
+ TLAN_DIO_DATA
+ 3) << 8;
2101 outw(TLAN_EXCESSCOL_FRMS
, dev
->base_addr
+ TLAN_DIO_ADR
);
2102 excess_col
= inb(dev
->base_addr
+ TLAN_DIO_DATA
);
2103 late_col
= inb(dev
->base_addr
+ TLAN_DIO_DATA
+ 1);
2104 loss
= inb(dev
->base_addr
+ TLAN_DIO_DATA
+ 2);
2107 dev
->stats
.rx_packets
+= rx_good
;
2108 dev
->stats
.rx_errors
+= rx_over
+ crc
+ code
;
2109 dev
->stats
.tx_packets
+= tx_good
;
2110 dev
->stats
.tx_errors
+= tx_under
+ loss
;
2111 dev
->stats
.collisions
+= multi_col
2112 + single_col
+ excess_col
+ late_col
;
2114 dev
->stats
.rx_over_errors
+= rx_over
;
2115 dev
->stats
.rx_crc_errors
+= crc
;
2116 dev
->stats
.rx_frame_errors
+= code
;
2118 dev
->stats
.tx_aborted_errors
+= tx_under
;
2119 dev
->stats
.tx_carrier_errors
+= loss
;
2127 /***************************************************************
2133 * dev Pointer to device structure of adapter
2136 * This function resets the adapter and it's physical
2137 * device. See Chap. 3, pp. 9-10 of the "ThunderLAN
2138 * Programmer's Guide" for details. The routine tries to
2139 * implement what is detailed there, though adjustments
2142 **************************************************************/
2145 tlan_reset_adapter(struct net_device
*dev
)
2147 struct tlan_priv
*priv
= netdev_priv(dev
);
2153 priv
->tlan_full_duplex
= false;
2154 priv
->phy_online
= 0;
2155 netif_carrier_off(dev
);
2157 /* 1. Assert reset bit. */
2159 data
= inl(dev
->base_addr
+ TLAN_HOST_CMD
);
2160 data
|= TLAN_HC_AD_RST
;
2161 outl(data
, dev
->base_addr
+ TLAN_HOST_CMD
);
2165 /* 2. Turn off interrupts. (Probably isn't necessary) */
2167 data
= inl(dev
->base_addr
+ TLAN_HOST_CMD
);
2168 data
|= TLAN_HC_INT_OFF
;
2169 outl(data
, dev
->base_addr
+ TLAN_HOST_CMD
);
2171 /* 3. Clear AREGs and HASHs. */
2173 for (i
= TLAN_AREG_0
; i
<= TLAN_HASH_2
; i
+= 4)
2174 tlan_dio_write32(dev
->base_addr
, (u16
) i
, 0);
2176 /* 4. Setup NetConfig register. */
2178 data
= TLAN_NET_CFG_1FRAG
| TLAN_NET_CFG_1CHAN
| TLAN_NET_CFG_PHY_EN
;
2179 tlan_dio_write16(dev
->base_addr
, TLAN_NET_CONFIG
, (u16
) data
);
2181 /* 5. Load Ld_Tmr and Ld_Thr in HOST_CMD. */
2183 outl(TLAN_HC_LD_TMR
| 0x3f, dev
->base_addr
+ TLAN_HOST_CMD
);
2184 outl(TLAN_HC_LD_THR
| 0x9, dev
->base_addr
+ TLAN_HOST_CMD
);
2186 /* 6. Unreset the MII by setting NMRST (in NetSio) to 1. */
2188 outw(TLAN_NET_SIO
, dev
->base_addr
+ TLAN_DIO_ADR
);
2189 addr
= dev
->base_addr
+ TLAN_DIO_DATA
+ TLAN_NET_SIO
;
2190 tlan_set_bit(TLAN_NET_SIO_NMRST
, addr
);
2192 /* 7. Setup the remaining registers. */
2194 if (priv
->tlan_rev
>= 0x30) {
2195 data8
= TLAN_ID_TX_EOC
| TLAN_ID_RX_EOC
;
2196 tlan_dio_write8(dev
->base_addr
, TLAN_INT_DIS
, data8
);
2198 tlan_phy_detect(dev
);
2199 data
= TLAN_NET_CFG_1FRAG
| TLAN_NET_CFG_1CHAN
;
2201 if (priv
->adapter
->flags
& TLAN_ADAPTER_BIT_RATE_PHY
) {
2202 data
|= TLAN_NET_CFG_BIT
;
2203 if (priv
->aui
== 1) {
2204 tlan_dio_write8(dev
->base_addr
, TLAN_ACOMMIT
, 0x0a);
2205 } else if (priv
->duplex
== TLAN_DUPLEX_FULL
) {
2206 tlan_dio_write8(dev
->base_addr
, TLAN_ACOMMIT
, 0x00);
2207 priv
->tlan_full_duplex
= true;
2209 tlan_dio_write8(dev
->base_addr
, TLAN_ACOMMIT
, 0x08);
2213 if (priv
->phy_num
== 0)
2214 data
|= TLAN_NET_CFG_PHY_EN
;
2215 tlan_dio_write16(dev
->base_addr
, TLAN_NET_CONFIG
, (u16
) data
);
2217 if (priv
->adapter
->flags
& TLAN_ADAPTER_UNMANAGED_PHY
)
2218 tlan_finish_reset(dev
);
2220 tlan_phy_power_down(dev
);
2228 tlan_finish_reset(struct net_device
*dev
)
2230 struct tlan_priv
*priv
= netdev_priv(dev
);
2238 u16 tlphy_id1
, tlphy_id2
;
2241 phy
= priv
->phy
[priv
->phy_num
];
2243 data
= TLAN_NET_CMD_NRESET
| TLAN_NET_CMD_NWRAP
;
2244 if (priv
->tlan_full_duplex
)
2245 data
|= TLAN_NET_CMD_DUPLEX
;
2246 tlan_dio_write8(dev
->base_addr
, TLAN_NET_CMD
, data
);
2247 data
= TLAN_NET_MASK_MASK4
| TLAN_NET_MASK_MASK5
;
2248 if (priv
->phy_num
== 0)
2249 data
|= TLAN_NET_MASK_MASK7
;
2250 tlan_dio_write8(dev
->base_addr
, TLAN_NET_MASK
, data
);
2251 tlan_dio_write16(dev
->base_addr
, TLAN_MAX_RX
, ((1536)+7)&~7);
2252 tlan_mii_read_reg(dev
, phy
, MII_GEN_ID_HI
, &tlphy_id1
);
2253 tlan_mii_read_reg(dev
, phy
, MII_GEN_ID_LO
, &tlphy_id2
);
2255 if ((priv
->adapter
->flags
& TLAN_ADAPTER_UNMANAGED_PHY
) ||
2257 status
= MII_GS_LINK
;
2258 pr_info("TLAN: %s: Link forced.\n", dev
->name
);
2260 tlan_mii_read_reg(dev
, phy
, MII_GEN_STS
, &status
);
2262 tlan_mii_read_reg(dev
, phy
, MII_GEN_STS
, &status
);
2263 if ((status
& MII_GS_LINK
) &&
2264 /* We only support link info on Nat.Sem. PHY's */
2265 (tlphy_id1
== NAT_SEM_ID1
) &&
2266 (tlphy_id2
== NAT_SEM_ID2
)) {
2267 tlan_mii_read_reg(dev
, phy
, MII_AN_LPA
, &partner
);
2268 tlan_mii_read_reg(dev
, phy
, TLAN_TLPHY_PAR
, &tlphy_par
);
2270 pr_info("TLAN: %s: Link active with ", dev
->name
);
2271 if (!(tlphy_par
& TLAN_PHY_AN_EN_STAT
)) {
2272 pr_info("forced 10%sMbps %s-Duplex\n",
2273 tlphy_par
& TLAN_PHY_SPEED_100
2275 tlphy_par
& TLAN_PHY_DUPLEX_FULL
2278 pr_info("Autonegotiation enabled, at 10%sMbps %s-Duplex\n",
2279 tlphy_par
& TLAN_PHY_SPEED_100
2281 tlphy_par
& TLAN_PHY_DUPLEX_FULL
2283 pr_info("TLAN: Partner capability: ");
2284 for (i
= 5; i
<= 10; i
++)
2285 if (partner
& (1<<i
))
2286 printk("%s", media
[i
-5]);
2290 tlan_dio_write8(dev
->base_addr
, TLAN_LED_REG
,
2293 /* We have link beat..for now anyway */
2295 /*Enabling link beat monitoring */
2296 tlan_set_timer(dev
, (10*HZ
), TLAN_TIMER_LINK_BEAT
);
2298 } else if (status
& MII_GS_LINK
) {
2299 pr_info("TLAN: %s: Link active\n", dev
->name
);
2300 tlan_dio_write8(dev
->base_addr
, TLAN_LED_REG
,
2305 if (priv
->phy_num
== 0) {
2306 tlan_mii_read_reg(dev
, phy
, TLAN_TLPHY_CTL
, &tlphy_ctl
);
2307 tlphy_ctl
|= TLAN_TC_INTEN
;
2308 tlan_mii_write_reg(dev
, phy
, TLAN_TLPHY_CTL
, tlphy_ctl
);
2309 sio
= tlan_dio_read8(dev
->base_addr
, TLAN_NET_SIO
);
2310 sio
|= TLAN_NET_SIO_MINTEN
;
2311 tlan_dio_write8(dev
->base_addr
, TLAN_NET_SIO
, sio
);
2314 if (status
& MII_GS_LINK
) {
2315 tlan_set_mac(dev
, 0, dev
->dev_addr
);
2316 priv
->phy_online
= 1;
2317 outb((TLAN_HC_INT_ON
>> 8), dev
->base_addr
+ TLAN_HOST_CMD
+ 1);
2318 if (debug
>= 1 && debug
!= TLAN_DEBUG_PROBE
)
2319 outb((TLAN_HC_REQ_INT
>> 8),
2320 dev
->base_addr
+ TLAN_HOST_CMD
+ 1);
2321 outl(priv
->rx_list_dma
, dev
->base_addr
+ TLAN_CH_PARM
);
2322 outl(TLAN_HC_GO
| TLAN_HC_RT
, dev
->base_addr
+ TLAN_HOST_CMD
);
2323 netif_carrier_on(dev
);
2325 pr_info("TLAN: %s: Link inactive, will retry in 10 secs...\n",
2327 tlan_set_timer(dev
, (10*HZ
), TLAN_TIMER_FINISH_RESET
);
2330 tlan_set_multicast_list(dev
);
2337 /***************************************************************
2343 * dev Pointer to device structure of adapter
2344 * on which to change the AREG.
2345 * areg The AREG to set the address in (0 - 3).
2346 * mac A pointer to an array of chars. Each
2347 * element stores one byte of the address.
2348 * IE, it isn't in ascii.
2350 * This function transfers a MAC address to one of the
2351 * TLAN AREGs (address registers). The TLAN chip locks
2352 * the register on writing to offset 0 and unlocks the
2353 * register after writing to offset 5. If NULL is passed
2354 * in mac, then the AREG is filled with 0's.
2356 **************************************************************/
2358 static void tlan_set_mac(struct net_device
*dev
, int areg
, char *mac
)
2365 for (i
= 0; i
< 6; i
++)
2366 tlan_dio_write8(dev
->base_addr
,
2367 TLAN_AREG_0
+ areg
+ i
, mac
[i
]);
2369 for (i
= 0; i
< 6; i
++)
2370 tlan_dio_write8(dev
->base_addr
,
2371 TLAN_AREG_0
+ areg
+ i
, 0);
2379 /*****************************************************************************
2380 ******************************************************************************
2382 ThunderLAN driver PHY layer routines
2384 ******************************************************************************
2385 *****************************************************************************/
2389 /*********************************************************************
2395 * dev A pointer to the device structure of the
2396 * TLAN device having the PHYs to be detailed.
2398 * This function prints the registers a PHY (aka transceiver).
2400 ********************************************************************/
2402 static void tlan_phy_print(struct net_device
*dev
)
2404 struct tlan_priv
*priv
= netdev_priv(dev
);
2405 u16 i
, data0
, data1
, data2
, data3
, phy
;
2407 phy
= priv
->phy
[priv
->phy_num
];
2409 if (priv
->adapter
->flags
& TLAN_ADAPTER_UNMANAGED_PHY
) {
2410 pr_info("TLAN: Device %s, Unmanaged PHY.\n", dev
->name
);
2411 } else if (phy
<= TLAN_PHY_MAX_ADDR
) {
2412 pr_info("TLAN: Device %s, PHY 0x%02x.\n", dev
->name
, phy
);
2413 pr_info("TLAN: Off. +0 +1 +2 +3\n");
2414 for (i
= 0; i
< 0x20; i
+= 4) {
2415 pr_info("TLAN: 0x%02x", i
);
2416 tlan_mii_read_reg(dev
, phy
, i
, &data0
);
2417 printk(" 0x%04hx", data0
);
2418 tlan_mii_read_reg(dev
, phy
, i
+ 1, &data1
);
2419 printk(" 0x%04hx", data1
);
2420 tlan_mii_read_reg(dev
, phy
, i
+ 2, &data2
);
2421 printk(" 0x%04hx", data2
);
2422 tlan_mii_read_reg(dev
, phy
, i
+ 3, &data3
);
2423 printk(" 0x%04hx\n", data3
);
2426 pr_info("TLAN: Device %s, Invalid PHY.\n", dev
->name
);
2434 /*********************************************************************
2440 * dev A pointer to the device structure of the adapter
2441 * for which the PHY needs determined.
2443 * So far I've found that adapters which have external PHYs
2444 * may also use the internal PHY for part of the functionality.
2445 * (eg, AUI/Thinnet). This function finds out if this TLAN
2446 * chip has an internal PHY, and then finds the first external
2447 * PHY (starting from address 0) if it exists).
2449 ********************************************************************/
2451 static void tlan_phy_detect(struct net_device
*dev
)
2453 struct tlan_priv
*priv
= netdev_priv(dev
);
2459 if (priv
->adapter
->flags
& TLAN_ADAPTER_UNMANAGED_PHY
) {
2460 priv
->phy_num
= 0xffff;
2464 tlan_mii_read_reg(dev
, TLAN_PHY_MAX_ADDR
, MII_GEN_ID_HI
, &hi
);
2467 priv
->phy
[0] = TLAN_PHY_MAX_ADDR
;
2469 priv
->phy
[0] = TLAN_PHY_NONE
;
2471 priv
->phy
[1] = TLAN_PHY_NONE
;
2472 for (phy
= 0; phy
<= TLAN_PHY_MAX_ADDR
; phy
++) {
2473 tlan_mii_read_reg(dev
, phy
, MII_GEN_CTL
, &control
);
2474 tlan_mii_read_reg(dev
, phy
, MII_GEN_ID_HI
, &hi
);
2475 tlan_mii_read_reg(dev
, phy
, MII_GEN_ID_LO
, &lo
);
2476 if ((control
!= 0xffff) ||
2477 (hi
!= 0xffff) || (lo
!= 0xffff)) {
2478 TLAN_DBG(TLAN_DEBUG_GNRL
,
2479 "PHY found at %02x %04x %04x %04x\n",
2480 phy
, control
, hi
, lo
);
2481 if ((priv
->phy
[1] == TLAN_PHY_NONE
) &&
2482 (phy
!= TLAN_PHY_MAX_ADDR
)) {
2488 if (priv
->phy
[1] != TLAN_PHY_NONE
)
2490 else if (priv
->phy
[0] != TLAN_PHY_NONE
)
2493 pr_info("TLAN: Cannot initialize device, no PHY was found!\n");
2500 static void tlan_phy_power_down(struct net_device
*dev
)
2502 struct tlan_priv
*priv
= netdev_priv(dev
);
2505 TLAN_DBG(TLAN_DEBUG_GNRL
, "%s: Powering down PHY(s).\n", dev
->name
);
2506 value
= MII_GC_PDOWN
| MII_GC_LOOPBK
| MII_GC_ISOLATE
;
2507 tlan_mii_sync(dev
->base_addr
);
2508 tlan_mii_write_reg(dev
, priv
->phy
[priv
->phy_num
], MII_GEN_CTL
, value
);
2509 if ((priv
->phy_num
== 0) &&
2510 (priv
->phy
[1] != TLAN_PHY_NONE
) &&
2511 (!(priv
->adapter
->flags
& TLAN_ADAPTER_USE_INTERN_10
))) {
2512 tlan_mii_sync(dev
->base_addr
);
2513 tlan_mii_write_reg(dev
, priv
->phy
[1], MII_GEN_CTL
, value
);
2516 /* Wait for 50 ms and powerup
2517 * This is abitrary. It is intended to make sure the
2518 * transceiver settles.
2520 tlan_set_timer(dev
, (HZ
/20), TLAN_TIMER_PHY_PUP
);
2527 static void tlan_phy_power_up(struct net_device
*dev
)
2529 struct tlan_priv
*priv
= netdev_priv(dev
);
2532 TLAN_DBG(TLAN_DEBUG_GNRL
, "%s: Powering up PHY.\n", dev
->name
);
2533 tlan_mii_sync(dev
->base_addr
);
2534 value
= MII_GC_LOOPBK
;
2535 tlan_mii_write_reg(dev
, priv
->phy
[priv
->phy_num
], MII_GEN_CTL
, value
);
2536 tlan_mii_sync(dev
->base_addr
);
2537 /* Wait for 500 ms and reset the
2538 * transceiver. The TLAN docs say both 50 ms and
2539 * 500 ms, so do the longer, just in case.
2541 tlan_set_timer(dev
, (HZ
/20), TLAN_TIMER_PHY_RESET
);
2548 static void tlan_phy_reset(struct net_device
*dev
)
2550 struct tlan_priv
*priv
= netdev_priv(dev
);
2554 phy
= priv
->phy
[priv
->phy_num
];
2556 TLAN_DBG(TLAN_DEBUG_GNRL
, "%s: Reseting PHY.\n", dev
->name
);
2557 tlan_mii_sync(dev
->base_addr
);
2558 value
= MII_GC_LOOPBK
| MII_GC_RESET
;
2559 tlan_mii_write_reg(dev
, phy
, MII_GEN_CTL
, value
);
2560 tlan_mii_read_reg(dev
, phy
, MII_GEN_CTL
, &value
);
2561 while (value
& MII_GC_RESET
)
2562 tlan_mii_read_reg(dev
, phy
, MII_GEN_CTL
, &value
);
2564 /* Wait for 500 ms and initialize.
2565 * I don't remember why I wait this long.
2566 * I've changed this to 50ms, as it seems long enough.
2568 tlan_set_timer(dev
, (HZ
/20), TLAN_TIMER_PHY_START_LINK
);
2575 static void tlan_phy_start_link(struct net_device
*dev
)
2577 struct tlan_priv
*priv
= netdev_priv(dev
);
2585 phy
= priv
->phy
[priv
->phy_num
];
2586 TLAN_DBG(TLAN_DEBUG_GNRL
, "%s: Trying to activate link.\n", dev
->name
);
2587 tlan_mii_read_reg(dev
, phy
, MII_GEN_STS
, &status
);
2588 tlan_mii_read_reg(dev
, phy
, MII_GEN_STS
, &ability
);
2590 if ((status
& MII_GS_AUTONEG
) &&
2592 ability
= status
>> 11;
2593 if (priv
->speed
== TLAN_SPEED_10
&&
2594 priv
->duplex
== TLAN_DUPLEX_HALF
) {
2595 tlan_mii_write_reg(dev
, phy
, MII_GEN_CTL
, 0x0000);
2596 } else if (priv
->speed
== TLAN_SPEED_10
&&
2597 priv
->duplex
== TLAN_DUPLEX_FULL
) {
2598 priv
->tlan_full_duplex
= true;
2599 tlan_mii_write_reg(dev
, phy
, MII_GEN_CTL
, 0x0100);
2600 } else if (priv
->speed
== TLAN_SPEED_100
&&
2601 priv
->duplex
== TLAN_DUPLEX_HALF
) {
2602 tlan_mii_write_reg(dev
, phy
, MII_GEN_CTL
, 0x2000);
2603 } else if (priv
->speed
== TLAN_SPEED_100
&&
2604 priv
->duplex
== TLAN_DUPLEX_FULL
) {
2605 priv
->tlan_full_duplex
= true;
2606 tlan_mii_write_reg(dev
, phy
, MII_GEN_CTL
, 0x2100);
2609 /* Set Auto-Neg advertisement */
2610 tlan_mii_write_reg(dev
, phy
, MII_AN_ADV
,
2611 (ability
<< 5) | 1);
2612 /* Enablee Auto-Neg */
2613 tlan_mii_write_reg(dev
, phy
, MII_GEN_CTL
, 0x1000);
2614 /* Restart Auto-Neg */
2615 tlan_mii_write_reg(dev
, phy
, MII_GEN_CTL
, 0x1200);
2616 /* Wait for 4 sec for autonegotiation
2617 * to complete. The max spec time is less than this
2618 * but the card need additional time to start AN.
2619 * .5 sec should be plenty extra.
2621 pr_info("TLAN: %s: Starting autonegotiation.\n",
2623 tlan_set_timer(dev
, (2*HZ
), TLAN_TIMER_PHY_FINISH_AN
);
2629 if ((priv
->aui
) && (priv
->phy_num
!= 0)) {
2631 data
= TLAN_NET_CFG_1FRAG
| TLAN_NET_CFG_1CHAN
2632 | TLAN_NET_CFG_PHY_EN
;
2633 tlan_dio_write16(dev
->base_addr
, TLAN_NET_CONFIG
, data
);
2634 tlan_set_timer(dev
, (40*HZ
/1000), TLAN_TIMER_PHY_PDOWN
);
2636 } else if (priv
->phy_num
== 0) {
2638 tlan_mii_read_reg(dev
, phy
, TLAN_TLPHY_CTL
, &tctl
);
2640 tctl
|= TLAN_TC_AUISEL
;
2642 tctl
&= ~TLAN_TC_AUISEL
;
2643 if (priv
->duplex
== TLAN_DUPLEX_FULL
) {
2644 control
|= MII_GC_DUPLEX
;
2645 priv
->tlan_full_duplex
= true;
2647 if (priv
->speed
== TLAN_SPEED_100
)
2648 control
|= MII_GC_SPEEDSEL
;
2650 tlan_mii_write_reg(dev
, phy
, MII_GEN_CTL
, control
);
2651 tlan_mii_write_reg(dev
, phy
, TLAN_TLPHY_CTL
, tctl
);
2654 /* Wait for 2 sec to give the transceiver time
2655 * to establish link.
2657 tlan_set_timer(dev
, (4*HZ
), TLAN_TIMER_FINISH_RESET
);
2664 static void tlan_phy_finish_auto_neg(struct net_device
*dev
)
2666 struct tlan_priv
*priv
= netdev_priv(dev
);
2674 phy
= priv
->phy
[priv
->phy_num
];
2676 tlan_mii_read_reg(dev
, phy
, MII_GEN_STS
, &status
);
2678 tlan_mii_read_reg(dev
, phy
, MII_GEN_STS
, &status
);
2680 if (!(status
& MII_GS_AUTOCMPLT
)) {
2681 /* Wait for 8 sec to give the process
2682 * more time. Perhaps we should fail after a while.
2684 if (!priv
->neg_be_verbose
++) {
2685 pr_info("TLAN: Giving autonegotiation more time.\n");
2686 pr_info("TLAN: Please check that your adapter has\n");
2687 pr_info("TLAN: been properly connected to a HUB or Switch.\n");
2688 pr_info("TLAN: Trying to establish link in the background...\n");
2690 tlan_set_timer(dev
, (8*HZ
), TLAN_TIMER_PHY_FINISH_AN
);
2694 pr_info("TLAN: %s: Autonegotiation complete.\n", dev
->name
);
2695 tlan_mii_read_reg(dev
, phy
, MII_AN_ADV
, &an_adv
);
2696 tlan_mii_read_reg(dev
, phy
, MII_AN_LPA
, &an_lpa
);
2697 mode
= an_adv
& an_lpa
& 0x03E0;
2699 priv
->tlan_full_duplex
= true;
2700 else if (!(mode
& 0x0080) && (mode
& 0x0040))
2701 priv
->tlan_full_duplex
= true;
2703 if ((!(mode
& 0x0180)) &&
2704 (priv
->adapter
->flags
& TLAN_ADAPTER_USE_INTERN_10
) &&
2705 (priv
->phy_num
!= 0)) {
2707 data
= TLAN_NET_CFG_1FRAG
| TLAN_NET_CFG_1CHAN
2708 | TLAN_NET_CFG_PHY_EN
;
2709 tlan_dio_write16(dev
->base_addr
, TLAN_NET_CONFIG
, data
);
2710 tlan_set_timer(dev
, (400*HZ
/1000), TLAN_TIMER_PHY_PDOWN
);
2714 if (priv
->phy_num
== 0) {
2715 if ((priv
->duplex
== TLAN_DUPLEX_FULL
) ||
2716 (an_adv
& an_lpa
& 0x0040)) {
2717 tlan_mii_write_reg(dev
, phy
, MII_GEN_CTL
,
2718 MII_GC_AUTOENB
| MII_GC_DUPLEX
);
2719 pr_info("TLAN: Starting internal PHY with FULL-DUPLEX\n");
2721 tlan_mii_write_reg(dev
, phy
, MII_GEN_CTL
,
2723 pr_info("TLAN: Starting internal PHY with HALF-DUPLEX\n");
2727 /* Wait for 100 ms. No reason in partiticular.
2729 tlan_set_timer(dev
, (HZ
/10), TLAN_TIMER_FINISH_RESET
);
2735 /*********************************************************************
2743 * dev The device structure of this device.
2746 * This function monitors PHY condition by reading the status
2747 * register via the MII bus. This can be used to give info
2748 * about link changes (up/down), and possible switch to alternate
2751 *******************************************************************/
2753 void tlan_phy_monitor(struct net_device
*dev
)
2755 struct tlan_priv
*priv
= netdev_priv(dev
);
2759 phy
= priv
->phy
[priv
->phy_num
];
2761 /* Get PHY status register */
2762 tlan_mii_read_reg(dev
, phy
, MII_GEN_STS
, &phy_status
);
2764 /* Check if link has been lost */
2765 if (!(phy_status
& MII_GS_LINK
)) {
2768 printk(KERN_DEBUG
"TLAN: %s has lost link\n",
2770 netif_carrier_off(dev
);
2771 tlan_set_timer(dev
, (2*HZ
), TLAN_TIMER_LINK_BEAT
);
2776 /* Link restablished? */
2777 if ((phy_status
& MII_GS_LINK
) && !priv
->link
) {
2779 printk(KERN_DEBUG
"TLAN: %s has reestablished link\n",
2781 netif_carrier_on(dev
);
2784 /* Setup a new monitor */
2785 tlan_set_timer(dev
, (2*HZ
), TLAN_TIMER_LINK_BEAT
);
2788 #endif /* MONITOR */
2791 /*****************************************************************************
2792 ******************************************************************************
2794 ThunderLAN driver MII routines
2796 these routines are based on the information in chap. 2 of the
2797 "ThunderLAN Programmer's Guide", pp. 15-24.
2799 ******************************************************************************
2800 *****************************************************************************/
2803 /***************************************************************
2807 * false if ack received ok
2808 * true if no ack received or other error
2811 * dev The device structure containing
2812 * The io address and interrupt count
2814 * phy The address of the PHY to be queried.
2815 * reg The register whose contents are to be
2817 * val A pointer to a variable to store the
2820 * This function uses the TLAN's MII bus to retrieve the contents
2821 * of a given register on a PHY. It sends the appropriate info
2822 * and then reads the 16-bit register value from the MII bus via
2823 * the TLAN SIO register.
2825 **************************************************************/
2828 tlan_mii_read_reg(struct net_device
*dev
, u16 phy
, u16 reg
, u16
*val
)
2835 struct tlan_priv
*priv
= netdev_priv(dev
);
2836 unsigned long flags
= 0;
2839 outw(TLAN_NET_SIO
, dev
->base_addr
+ TLAN_DIO_ADR
);
2840 sio
= dev
->base_addr
+ TLAN_DIO_DATA
+ TLAN_NET_SIO
;
2843 spin_lock_irqsave(&priv
->lock
, flags
);
2845 tlan_mii_sync(dev
->base_addr
);
2847 minten
= tlan_get_bit(TLAN_NET_SIO_MINTEN
, sio
);
2849 tlan_clear_bit(TLAN_NET_SIO_MINTEN
, sio
);
2851 tlan_mii_send_data(dev
->base_addr
, 0x1, 2); /* start (01b) */
2852 tlan_mii_send_data(dev
->base_addr
, 0x2, 2); /* read (10b) */
2853 tlan_mii_send_data(dev
->base_addr
, phy
, 5); /* device # */
2854 tlan_mii_send_data(dev
->base_addr
, reg
, 5); /* register # */
2857 tlan_clear_bit(TLAN_NET_SIO_MTXEN
, sio
); /* change direction */
2859 tlan_clear_bit(TLAN_NET_SIO_MCLK
, sio
); /* clock idle bit */
2860 tlan_set_bit(TLAN_NET_SIO_MCLK
, sio
);
2861 tlan_clear_bit(TLAN_NET_SIO_MCLK
, sio
); /* wait 300ns */
2863 nack
= tlan_get_bit(TLAN_NET_SIO_MDATA
, sio
); /* check for ACK */
2864 tlan_set_bit(TLAN_NET_SIO_MCLK
, sio
); /* finish ACK */
2865 if (nack
) { /* no ACK, so fake it */
2866 for (i
= 0; i
< 16; i
++) {
2867 tlan_clear_bit(TLAN_NET_SIO_MCLK
, sio
);
2868 tlan_set_bit(TLAN_NET_SIO_MCLK
, sio
);
2872 } else { /* ACK, so read data */
2873 for (tmp
= 0, i
= 0x8000; i
; i
>>= 1) {
2874 tlan_clear_bit(TLAN_NET_SIO_MCLK
, sio
);
2875 if (tlan_get_bit(TLAN_NET_SIO_MDATA
, sio
))
2877 tlan_set_bit(TLAN_NET_SIO_MCLK
, sio
);
2882 tlan_clear_bit(TLAN_NET_SIO_MCLK
, sio
); /* idle cycle */
2883 tlan_set_bit(TLAN_NET_SIO_MCLK
, sio
);
2886 tlan_set_bit(TLAN_NET_SIO_MINTEN
, sio
);
2891 spin_unlock_irqrestore(&priv
->lock
, flags
);
2900 /***************************************************************
2901 * tlan_mii_send_data
2906 * base_port The base IO port of the adapter in
2908 * dev The address of the PHY to be queried.
2909 * data The value to be placed on the MII bus.
2910 * num_bits The number of bits in data that are to
2911 * be placed on the MII bus.
2913 * This function sends on sequence of bits on the MII
2914 * configuration bus.
2916 **************************************************************/
2918 static void tlan_mii_send_data(u16 base_port
, u32 data
, unsigned num_bits
)
2926 outw(TLAN_NET_SIO
, base_port
+ TLAN_DIO_ADR
);
2927 sio
= base_port
+ TLAN_DIO_DATA
+ TLAN_NET_SIO
;
2928 tlan_set_bit(TLAN_NET_SIO_MTXEN
, sio
);
2930 for (i
= (0x1 << (num_bits
- 1)); i
; i
>>= 1) {
2931 tlan_clear_bit(TLAN_NET_SIO_MCLK
, sio
);
2932 (void) tlan_get_bit(TLAN_NET_SIO_MCLK
, sio
);
2934 tlan_set_bit(TLAN_NET_SIO_MDATA
, sio
);
2936 tlan_clear_bit(TLAN_NET_SIO_MDATA
, sio
);
2937 tlan_set_bit(TLAN_NET_SIO_MCLK
, sio
);
2938 (void) tlan_get_bit(TLAN_NET_SIO_MCLK
, sio
);
2946 /***************************************************************
2952 * base_port The base IO port of the adapter in
2955 * This functions syncs all PHYs in terms of the MII configuration
2958 **************************************************************/
2960 static void tlan_mii_sync(u16 base_port
)
2965 outw(TLAN_NET_SIO
, base_port
+ TLAN_DIO_ADR
);
2966 sio
= base_port
+ TLAN_DIO_DATA
+ TLAN_NET_SIO
;
2968 tlan_clear_bit(TLAN_NET_SIO_MTXEN
, sio
);
2969 for (i
= 0; i
< 32; i
++) {
2970 tlan_clear_bit(TLAN_NET_SIO_MCLK
, sio
);
2971 tlan_set_bit(TLAN_NET_SIO_MCLK
, sio
);
2979 /***************************************************************
2980 * tlan_mii_write_reg
2985 * dev The device structure for the device
2987 * phy The address of the PHY to be written to.
2988 * reg The register whose contents are to be
2990 * val The value to be written to the register.
2992 * This function uses the TLAN's MII bus to write the contents of a
2993 * given register on a PHY. It sends the appropriate info and then
2994 * writes the 16-bit register value from the MII configuration bus
2995 * via the TLAN SIO register.
2997 **************************************************************/
3000 tlan_mii_write_reg(struct net_device
*dev
, u16 phy
, u16 reg
, u16 val
)
3004 unsigned long flags
= 0;
3005 struct tlan_priv
*priv
= netdev_priv(dev
);
3007 outw(TLAN_NET_SIO
, dev
->base_addr
+ TLAN_DIO_ADR
);
3008 sio
= dev
->base_addr
+ TLAN_DIO_DATA
+ TLAN_NET_SIO
;
3011 spin_lock_irqsave(&priv
->lock
, flags
);
3013 tlan_mii_sync(dev
->base_addr
);
3015 minten
= tlan_get_bit(TLAN_NET_SIO_MINTEN
, sio
);
3017 tlan_clear_bit(TLAN_NET_SIO_MINTEN
, sio
);
3019 tlan_mii_send_data(dev
->base_addr
, 0x1, 2); /* start (01b) */
3020 tlan_mii_send_data(dev
->base_addr
, 0x1, 2); /* write (01b) */
3021 tlan_mii_send_data(dev
->base_addr
, phy
, 5); /* device # */
3022 tlan_mii_send_data(dev
->base_addr
, reg
, 5); /* register # */
3024 tlan_mii_send_data(dev
->base_addr
, 0x2, 2); /* send ACK */
3025 tlan_mii_send_data(dev
->base_addr
, val
, 16); /* send data */
3027 tlan_clear_bit(TLAN_NET_SIO_MCLK
, sio
); /* idle cycle */
3028 tlan_set_bit(TLAN_NET_SIO_MCLK
, sio
);
3031 tlan_set_bit(TLAN_NET_SIO_MINTEN
, sio
);
3034 spin_unlock_irqrestore(&priv
->lock
, flags
);
3041 /*****************************************************************************
3042 ******************************************************************************
3044 ThunderLAN driver eeprom routines
3046 the Compaq netelligent 10 and 10/100 cards use a microchip 24C02A
3047 EEPROM. these functions are based on information in microchip's
3048 data sheet. I don't know how well this functions will work with
3051 ******************************************************************************
3052 *****************************************************************************/
3055 /***************************************************************
3056 * tlan_ee_send_start
3061 * io_base The IO port base address for the
3062 * TLAN device with the EEPROM to
3065 * This function sends a start cycle to an EEPROM attached
3068 **************************************************************/
3070 static void tlan_ee_send_start(u16 io_base
)
3074 outw(TLAN_NET_SIO
, io_base
+ TLAN_DIO_ADR
);
3075 sio
= io_base
+ TLAN_DIO_DATA
+ TLAN_NET_SIO
;
3077 tlan_set_bit(TLAN_NET_SIO_ECLOK
, sio
);
3078 tlan_set_bit(TLAN_NET_SIO_EDATA
, sio
);
3079 tlan_set_bit(TLAN_NET_SIO_ETXEN
, sio
);
3080 tlan_clear_bit(TLAN_NET_SIO_EDATA
, sio
);
3081 tlan_clear_bit(TLAN_NET_SIO_ECLOK
, sio
);
3088 /***************************************************************
3092 * If the correct ack was received, 0, otherwise 1
3093 * Parms: io_base The IO port base address for the
3094 * TLAN device with the EEPROM to
3096 * data The 8 bits of information to
3097 * send to the EEPROM.
3098 * stop If TLAN_EEPROM_STOP is passed, a
3099 * stop cycle is sent after the
3100 * byte is sent after the ack is
3103 * This function sends a byte on the serial EEPROM line,
3104 * driving the clock to send each bit. The function then
3105 * reverses transmission direction and reads an acknowledge
3108 **************************************************************/
3110 static int tlan_ee_send_byte(u16 io_base
, u8 data
, int stop
)
3116 outw(TLAN_NET_SIO
, io_base
+ TLAN_DIO_ADR
);
3117 sio
= io_base
+ TLAN_DIO_DATA
+ TLAN_NET_SIO
;
3119 /* Assume clock is low, tx is enabled; */
3120 for (place
= 0x80; place
!= 0; place
>>= 1) {
3122 tlan_set_bit(TLAN_NET_SIO_EDATA
, sio
);
3124 tlan_clear_bit(TLAN_NET_SIO_EDATA
, sio
);
3125 tlan_set_bit(TLAN_NET_SIO_ECLOK
, sio
);
3126 tlan_clear_bit(TLAN_NET_SIO_ECLOK
, sio
);
3128 tlan_clear_bit(TLAN_NET_SIO_ETXEN
, sio
);
3129 tlan_set_bit(TLAN_NET_SIO_ECLOK
, sio
);
3130 err
= tlan_get_bit(TLAN_NET_SIO_EDATA
, sio
);
3131 tlan_clear_bit(TLAN_NET_SIO_ECLOK
, sio
);
3132 tlan_set_bit(TLAN_NET_SIO_ETXEN
, sio
);
3134 if ((!err
) && stop
) {
3135 /* STOP, raise data while clock is high */
3136 tlan_clear_bit(TLAN_NET_SIO_EDATA
, sio
);
3137 tlan_set_bit(TLAN_NET_SIO_ECLOK
, sio
);
3138 tlan_set_bit(TLAN_NET_SIO_EDATA
, sio
);
3148 /***************************************************************
3149 * tlan_ee_receive_byte
3154 * io_base The IO port base address for the
3155 * TLAN device with the EEPROM to
3157 * data An address to a char to hold the
3158 * data sent from the EEPROM.
3159 * stop If TLAN_EEPROM_STOP is passed, a
3160 * stop cycle is sent after the
3161 * byte is received, and no ack is
3164 * This function receives 8 bits of data from the EEPROM
3165 * over the serial link. It then sends and ack bit, or no
3166 * ack and a stop bit. This function is used to retrieve
3167 * data after the address of a byte in the EEPROM has been
3170 **************************************************************/
3172 static void tlan_ee_receive_byte(u16 io_base
, u8
*data
, int stop
)
3177 outw(TLAN_NET_SIO
, io_base
+ TLAN_DIO_ADR
);
3178 sio
= io_base
+ TLAN_DIO_DATA
+ TLAN_NET_SIO
;
3181 /* Assume clock is low, tx is enabled; */
3182 tlan_clear_bit(TLAN_NET_SIO_ETXEN
, sio
);
3183 for (place
= 0x80; place
; place
>>= 1) {
3184 tlan_set_bit(TLAN_NET_SIO_ECLOK
, sio
);
3185 if (tlan_get_bit(TLAN_NET_SIO_EDATA
, sio
))
3187 tlan_clear_bit(TLAN_NET_SIO_ECLOK
, sio
);
3190 tlan_set_bit(TLAN_NET_SIO_ETXEN
, sio
);
3192 tlan_clear_bit(TLAN_NET_SIO_EDATA
, sio
); /* ack = 0 */
3193 tlan_set_bit(TLAN_NET_SIO_ECLOK
, sio
);
3194 tlan_clear_bit(TLAN_NET_SIO_ECLOK
, sio
);
3196 tlan_set_bit(TLAN_NET_SIO_EDATA
, sio
); /* no ack = 1 (?) */
3197 tlan_set_bit(TLAN_NET_SIO_ECLOK
, sio
);
3198 tlan_clear_bit(TLAN_NET_SIO_ECLOK
, sio
);
3199 /* STOP, raise data while clock is high */
3200 tlan_clear_bit(TLAN_NET_SIO_EDATA
, sio
);
3201 tlan_set_bit(TLAN_NET_SIO_ECLOK
, sio
);
3202 tlan_set_bit(TLAN_NET_SIO_EDATA
, sio
);
3210 /***************************************************************
3214 * No error = 0, else, the stage at which the error
3217 * io_base The IO port base address for the
3218 * TLAN device with the EEPROM to
3220 * ee_addr The address of the byte in the
3221 * EEPROM whose contents are to be
3223 * data An address to a char to hold the
3224 * data obtained from the EEPROM.
3226 * This function reads a byte of information from an byte
3227 * cell in the EEPROM.
3229 **************************************************************/
3231 static int tlan_ee_read_byte(struct net_device
*dev
, u8 ee_addr
, u8
*data
)
3234 struct tlan_priv
*priv
= netdev_priv(dev
);
3235 unsigned long flags
= 0;
3238 spin_lock_irqsave(&priv
->lock
, flags
);
3240 tlan_ee_send_start(dev
->base_addr
);
3241 err
= tlan_ee_send_byte(dev
->base_addr
, 0xa0, TLAN_EEPROM_ACK
);
3246 err
= tlan_ee_send_byte(dev
->base_addr
, ee_addr
, TLAN_EEPROM_ACK
);
3251 tlan_ee_send_start(dev
->base_addr
);
3252 err
= tlan_ee_send_byte(dev
->base_addr
, 0xa1, TLAN_EEPROM_ACK
);
3257 tlan_ee_receive_byte(dev
->base_addr
, data
, TLAN_EEPROM_STOP
);
3259 spin_unlock_irqrestore(&priv
->lock
, flags
);