* add p cc
[mascara-docs.git] / i386 / linux / linux-2.3.21 / drivers / net / tlan.c
blobcbbee85327edf8bb2af41a62e5b99b65bf429b7a
1 /********************************************************************
3 * Linux ThunderLAN Driver
5 * tlan.c
6 * by James Banks
8 * (C) 1997-1998 Caldera, Inc.
9 * (C) 1998 James Banks
11 * This software may be used and distributed according to the terms
12 * of the GNU Public License, incorporated herein by reference.
14 ** This file is best viewed/edited with columns>=132.
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 * Change History
30 * Tigran Aivazian <tigran@sco.com>: TLan_PciProbe() now uses
31 * new PCI BIOS interface.
32 * Alan Cox <alan@redhat.com>: Fixed the out of memory
33 * handling.
35 ********************************************************************/
38 #include <linux/module.h>
40 #include "tlan.h"
42 #include <linux/ioport.h>
43 #include <linux/pci.h>
44 #include <linux/etherdevice.h>
45 #include <linux/delay.h>
49 typedef u32 (TLanIntVectorFunc)( struct net_device *, u16 );
52 #ifdef MODULE
54 static struct net_device *TLanDevices = NULL;
55 static int TLanDevicesInstalled = 0;
57 static int aui = 0;
58 static int sa_int = 0;
59 static int duplex = 0;
60 static int speed = 0;
62 MODULE_PARM(aui, "i");
63 MODULE_PARM(sa_int, "i");
64 MODULE_PARM(duplex, "i");
65 MODULE_PARM(speed, "i");
66 MODULE_PARM(debug, "i");
67 EXPORT_NO_SYMBOLS;
69 #endif
72 static int debug = 0;
73 static int bbuf = 0;
74 static u8 *TLanPadBuffer;
75 static char TLanSignature[] = "TLAN";
76 static int TLanVersionMajor = 1;
77 static int TLanVersionMinor = 0;
80 static TLanAdapterEntry TLanAdapterList[] = {
81 { PCI_VENDOR_ID_COMPAQ,
82 PCI_DEVICE_ID_NETELLIGENT_10,
83 "Compaq Netelligent 10 T PCI UTP",
84 TLAN_ADAPTER_ACTIVITY_LED,
85 0x83
87 { PCI_VENDOR_ID_COMPAQ,
88 PCI_DEVICE_ID_NETELLIGENT_10_100,
89 "Compaq Netelligent 10/100 TX PCI UTP",
90 TLAN_ADAPTER_ACTIVITY_LED,
91 0x83
92 },
93 { PCI_VENDOR_ID_COMPAQ,
94 PCI_DEVICE_ID_NETFLEX_3P_INTEGRATED,
95 "Compaq Integrated NetFlex-3/P",
96 TLAN_ADAPTER_NONE,
97 0x83
98 },
99 { PCI_VENDOR_ID_COMPAQ,
100 PCI_DEVICE_ID_NETFLEX_3P,
101 "Compaq NetFlex-3/P",
102 TLAN_ADAPTER_UNMANAGED_PHY | TLAN_ADAPTER_BIT_RATE_PHY,
103 0x83
105 { PCI_VENDOR_ID_COMPAQ,
106 PCI_DEVICE_ID_NETFLEX_3P_BNC,
107 "Compaq NetFlex-3/P",
108 TLAN_ADAPTER_NONE,
109 0x83
111 { PCI_VENDOR_ID_COMPAQ,
112 PCI_DEVICE_ID_NETELLIGENT_10_100_PROLIANT,
113 "Compaq Netelligent Integrated 10/100 TX UTP",
114 TLAN_ADAPTER_NONE,
115 0x83
117 { PCI_VENDOR_ID_COMPAQ,
118 PCI_DEVICE_ID_NETELLIGENT_10_100_DUAL,
119 "Compaq Netelligent Dual 10/100 TX PCI UTP",
120 TLAN_ADAPTER_NONE,
121 0x83
123 { PCI_VENDOR_ID_COMPAQ,
124 PCI_DEVICE_ID_DESKPRO_4000_5233MMX,
125 "Compaq Netelligent 10/100 TX Embedded UTP",
126 TLAN_ADAPTER_NONE,
127 0x83
129 { PCI_VENDOR_ID_OLICOM,
130 PCI_DEVICE_ID_OLICOM_OC2183,
131 "Olicom OC-2183/2185",
132 TLAN_ADAPTER_USE_INTERN_10,
133 0xF8
135 { PCI_VENDOR_ID_OLICOM,
136 PCI_DEVICE_ID_OLICOM_OC2325,
137 "Olicom OC-2325",
138 TLAN_ADAPTER_UNMANAGED_PHY,
139 0xF8
141 { PCI_VENDOR_ID_OLICOM,
142 PCI_DEVICE_ID_OLICOM_OC2326,
143 "Olicom OC-2326",
144 TLAN_ADAPTER_USE_INTERN_10,
145 0xF8
147 { PCI_VENDOR_ID_COMPAQ,
148 PCI_DEVICE_ID_NETELLIGENT_10_100_WS_5100,
149 "Compaq Netelligent 10/100 TX UTP",
150 TLAN_ADAPTER_ACTIVITY_LED,
151 0x83
153 { PCI_VENDOR_ID_COMPAQ,
154 PCI_DEVICE_ID_NETELLIGENT_10_T2,
155 "Compaq Netelligent 10 T/2 PCI UTP/Coax",
156 TLAN_ADAPTER_NONE,
157 0x83
159 { 0,
161 NULL,
164 } /* End of List */
168 static int TLan_PciProbe( u8 *, u8 *, u8 *, u32 *, u32 * );
169 static int TLan_Init( struct net_device * );
170 static int TLan_Open(struct net_device *dev);
171 static int TLan_StartTx(struct sk_buff *, struct net_device *);
172 static void TLan_HandleInterrupt(int, void *, struct pt_regs *);
173 static int TLan_Close(struct net_device *);
174 static struct net_device_stats *TLan_GetStats( struct net_device * );
175 static void TLan_SetMulticastList( struct net_device * );
177 static u32 TLan_HandleInvalid( struct net_device *, u16 );
178 static u32 TLan_HandleTxEOF( struct net_device *, u16 );
179 static u32 TLan_HandleStatOverflow( struct net_device *, u16 );
180 static u32 TLan_HandleRxEOF( struct net_device *, u16 );
181 static u32 TLan_HandleDummy( struct net_device *, u16 );
182 static u32 TLan_HandleTxEOC( struct net_device *, u16 );
183 static u32 TLan_HandleStatusCheck( struct net_device *, u16 );
184 static u32 TLan_HandleRxEOC( struct net_device *, u16 );
186 static void TLan_Timer( unsigned long );
188 static void TLan_ResetLists( struct net_device * );
189 static void TLan_FreeLists( struct net_device * );
190 static void TLan_PrintDio( u16 );
191 static void TLan_PrintList( TLanList *, char *, int );
192 static void TLan_ReadAndClearStats( struct net_device *, int );
193 static void TLan_ResetAdapter( struct net_device * );
194 static void TLan_FinishReset( struct net_device * );
195 static void TLan_SetMac( struct net_device *, int areg, char *mac );
197 static void TLan_PhyPrint( struct net_device * );
198 static void TLan_PhyDetect( struct net_device * );
199 static void TLan_PhyPowerDown( struct net_device * );
200 static void TLan_PhyPowerUp( struct net_device * );
201 static void TLan_PhyReset( struct net_device * );
202 static void TLan_PhyStartLink( struct net_device * );
203 static void TLan_PhyFinishAutoNeg( struct net_device * );
205 static int TLan_PhyNop( struct net_device * );
206 static int TLan_PhyInternalCheck( struct net_device * );
207 static int TLan_PhyInternalService( struct net_device * );
208 static int TLan_PhyDp83840aCheck( struct net_device * );
211 static int TLan_MiiReadReg( struct net_device *, u16, u16, u16 * );
212 static void TLan_MiiSendData( u16, u32, unsigned );
213 static void TLan_MiiSync( u16 );
214 static void TLan_MiiWriteReg( struct net_device *, u16, u16, u16 );
216 static void TLan_EeSendStart( u16 );
217 static int TLan_EeSendByte( u16, u8, int );
218 static void TLan_EeReceiveByte( u16, u8 *, int );
219 static int TLan_EeReadByte( struct net_device *, u8, u8 * );
222 static TLanIntVectorFunc *TLanIntVector[TLAN_INT_NUMBER_OF_INTS] = {
223 TLan_HandleInvalid,
224 TLan_HandleTxEOF,
225 TLan_HandleStatOverflow,
226 TLan_HandleRxEOF,
227 TLan_HandleDummy,
228 TLan_HandleTxEOC,
229 TLan_HandleStatusCheck,
230 TLan_HandleRxEOC
233 static inline void
234 TLan_SetTimer( struct net_device *dev, u32 ticks, u32 type )
236 TLanPrivateInfo *priv = (TLanPrivateInfo *) dev->priv;
238 cli();
239 if ( priv->timer.function != NULL ) {
240 return;
242 priv->timer.function = &TLan_Timer;
243 sti();
245 priv->timer.data = (unsigned long) dev;
246 priv->timer.expires = jiffies + ticks;
247 priv->timerSetAt = jiffies;
248 priv->timerType = type;
249 add_timer( &priv->timer );
251 } /* TLan_SetTimer */
254 /*****************************************************************************
255 ******************************************************************************
257 ThunderLAN Driver Primary Functions
259 These functions are more or less common to all Linux network drivers.
261 ******************************************************************************
262 *****************************************************************************/
265 #ifdef MODULE
267 /***************************************************************
268 * init_module
270 * Returns:
271 * 0 if module installed ok, non-zero if not.
272 * Parms:
273 * None
275 * This function begins the setup of the driver creating a
276 * pad buffer, finding all TLAN devices (matching
277 * TLanAdapterList entries), and creating and initializing a
278 * device structure for each adapter.
280 **************************************************************/
282 extern int init_module(void)
284 TLanPrivateInfo *priv;
285 struct net_device *dev;
286 size_t dev_size;
287 u8 dfn;
288 u32 index;
289 int failed;
290 int found;
291 u32 io_base;
292 u8 irq;
293 u8 rev;
295 printk( "TLAN driver, v%d.%d, (C) 1997-8 Caldera, Inc.\n",
296 TLanVersionMajor,
297 TLanVersionMinor
299 TLanPadBuffer = (u8 *) kmalloc( TLAN_MIN_FRAME_SIZE,
300 ( GFP_KERNEL | GFP_DMA )
302 if ( TLanPadBuffer == NULL ) {
303 printk( "TLAN: Could not allocate memory for pad buffer.\n" );
304 return -ENOMEM;
307 memset( TLanPadBuffer, 0, TLAN_MIN_FRAME_SIZE );
309 dev_size = sizeof(struct net_device) + sizeof(TLanPrivateInfo);
311 while ( ( found = TLan_PciProbe( &dfn, &irq, &rev, &io_base, &index ) ) ) {
312 dev = (struct net_device *) kmalloc( dev_size, GFP_KERNEL );
313 if ( dev == NULL ) {
314 printk( "TLAN: Could not allocate memory for device.\n" );
315 continue;
317 memset( dev, 0, dev_size );
319 dev->priv = priv = ( (void *) dev ) + sizeof(struct net_device);
320 dev->name = priv->devName;
321 strcpy( priv->devName, " " );
322 dev->base_addr = io_base;
323 dev->irq = irq;
324 dev->init = TLan_Init;
326 priv->adapter = &TLanAdapterList[index];
327 priv->adapterRev = rev;
328 priv->aui = aui;
329 if ( ( duplex != 1 ) && ( duplex != 2 ) ) {
330 duplex = 0;
332 priv->duplex = duplex;
333 if ( ( speed != 10 ) && ( speed != 100 ) ) {
334 speed = 0;
336 priv->speed = speed;
337 priv->sa_int = sa_int;
338 priv->debug = debug;
340 ether_setup( dev );
342 failed = register_netdev( dev );
344 if ( failed ) {
345 printk( "TLAN: Could not register device.\n" );
346 kfree( dev );
347 } else {
348 priv->nextDevice = TLanDevices;
349 TLanDevices = dev;
350 TLanDevicesInstalled++;
351 printk("TLAN: %s irq=%2d io=%04x, %s, Rev. %d\n",
352 dev->name,
353 (int) dev->irq,
354 (int) dev->base_addr,
355 priv->adapter->deviceLabel,
356 priv->adapterRev );
360 /* printk( "TLAN: Found %d device(s).\n", TLanDevicesInstalled ); */
362 return ( ( TLanDevicesInstalled > 0 ) ? 0 : -ENODEV );
364 } /* init_module */
369 /***************************************************************
370 * cleanup_module
372 * Returns:
373 * Nothing
374 * Parms:
375 * None
377 * Goes through the TLanDevices list and frees the device
378 * structs and memory associated with each device (lists
379 * and buffers). It also ureserves the IO port regions
380 * associated with this device.
382 **************************************************************/
384 extern void cleanup_module(void)
386 struct net_device *dev;
387 TLanPrivateInfo *priv;
389 while ( TLanDevicesInstalled ) {
390 dev = TLanDevices;
391 priv = (TLanPrivateInfo *) dev->priv;
392 if ( priv->dmaStorage ) {
393 kfree( priv->dmaStorage );
395 release_region( dev->base_addr, 0x10 );
396 unregister_netdev( dev );
397 TLanDevices = priv->nextDevice;
398 kfree( dev );
399 TLanDevicesInstalled--;
401 kfree( TLanPadBuffer );
403 } /* cleanup_module */
406 #else /* MODULE */
411 /***************************************************************
412 * tlan_probe
414 * Returns:
415 * 0 on success, error code on error
416 * Parms:
417 * dev device struct to use if adapter is
418 * found.
420 * The name is lower case to fit in with all the rest of
421 * the netcard_probe names. This function looks for a/
422 * another TLan based adapter, setting it up with the
423 * provided device struct if one is found.
425 **************************************************************/
427 extern int tlan_probe( struct net_device *dev )
429 TLanPrivateInfo *priv;
430 static int pad_allocated = 0;
431 int found;
432 u8 dfn, irq, rev;
433 u32 io_base, index;
435 found = TLan_PciProbe( &dfn, &irq, &rev, &io_base, &index );
437 if ( ! found ) {
438 return -ENODEV;
441 dev->priv = kmalloc( sizeof(TLanPrivateInfo), GFP_KERNEL );
443 if ( dev->priv == NULL ) {
444 printk( "TLAN: Could not allocate memory for device.\n" );
445 return -ENOMEM;
448 memset( dev->priv, 0, sizeof(TLanPrivateInfo) );
450 if ( ! pad_allocated ) {
451 TLanPadBuffer = (u8 *) kmalloc( TLAN_MIN_FRAME_SIZE,
452 // ( GFP_KERNEL | GFP_DMA )
453 ( GFP_KERNEL )
455 if ( TLanPadBuffer == NULL ) {
456 printk( "TLAN: Could not allocate memory for padding.\n" );
457 kfree( dev->priv );
458 return -ENOMEM;
459 } else {
460 pad_allocated = 1;
461 memset( TLanPadBuffer, 0, TLAN_MIN_FRAME_SIZE );
465 priv = (TLanPrivateInfo *) dev->priv;
467 dev->name = priv->devName;
468 strcpy( priv->devName, " " );
470 dev = init_etherdev( dev, sizeof(TLanPrivateInfo) );
472 dev->base_addr = io_base;
473 dev->irq = irq;
476 priv->adapter = &TLanAdapterList[index];
477 priv->adapterRev = rev;
478 priv->aui = dev->mem_start & 0x01;
479 priv->duplex = ( ( dev->mem_start & 0x0C ) == 0x0C ) ? 0 : ( dev->mem_start & 0x0C ) >> 2;
480 priv->speed = ( ( dev->mem_start & 0x30 ) == 0x30 ) ? 0 : ( dev->mem_start & 0x30 ) >> 4;
481 if ( priv->speed == 0x1 ) {
482 priv->speed = TLAN_SPEED_10;
483 } else if ( priv->speed == 0x2 ) {
484 priv->speed = TLAN_SPEED_100;
486 priv->sa_int = dev->mem_start & 0x02;
487 priv->debug = dev->mem_end;
490 printk("TLAN %d.%d: %s irq=%2d io=%04x, %s, Rev. %d\n",
491 TLanVersionMajor,
492 TLanVersionMinor,
493 dev->name,
494 (int) irq,
495 io_base,
496 priv->adapter->deviceLabel,
497 priv->adapterRev );
499 TLan_Init( dev );
501 return 0;
503 } /* tlan_probe */
506 #endif /* MODULE */
511 /***************************************************************
512 * TLan_PciProbe
514 * Returns:
515 * 1 if another TLAN card was found, 0 if not.
516 * Parms:
517 * pci_dfn The PCI whatever the card was
518 * found at.
519 * pci_irq The IRQ of the found adapter.
520 * pci_rev The revision of the adapter.
521 * pci_io_base The first IO port used by the
522 * adapter.
523 * dl_ix The index in the device list
524 * of the adapter.
526 * This function searches for an adapter with PCI vendor
527 * and device IDs matching those in the TLanAdapterList.
528 * The function 'remembers' the last device it found,
529 * and so finds a new device (if anymore are to be found)
530 * each time the function is called. It then looks up
531 * pertinent PCI info and returns it to the caller.
533 **************************************************************/
535 int TLan_PciProbe(u8 *pci_dfn, u8 *pci_irq, u8 *pci_rev, u32 *pci_io_base, u32 *dl_ix )
537 static int dl_index = 0;
538 static struct pci_dev * pdev = NULL;
539 u16 pci_command;
540 int reg;
543 if ( ! pci_present() ) {
544 printk( "TLAN: PCI Bios not present.\n" );
545 return 0;
548 for (; TLanAdapterList[dl_index].vendorId != 0; dl_index++) {
550 pdev = pci_find_device(
551 TLanAdapterList[dl_index].vendorId,
552 TLanAdapterList[dl_index].deviceId, pdev);
554 if ( pdev ) {
556 TLAN_DBG(
557 TLAN_DEBUG_GNRL,
558 "TLAN: found: Vendor Id = 0x%hx, Device Id = 0x%hx\n",
559 TLanAdapterList[dl_index].vendorId,
560 TLanAdapterList[dl_index].deviceId
563 *pci_irq = pdev->irq;
564 *pci_io_base = pdev->resource[0].start;
565 *pci_dfn = pdev->devfn;
566 pci_read_config_byte ( pdev, PCI_REVISION_ID, pci_rev);
567 pci_read_config_word ( pdev, PCI_COMMAND, &pci_command);
569 for ( reg = PCI_BASE_ADDRESS_0; reg <= PCI_BASE_ADDRESS_5; reg +=4 ) {
570 pci_read_config_dword( pdev, reg, pci_io_base);
571 if ((pci_command & PCI_COMMAND_IO) && (*pci_io_base & 0x3)) {
572 *pci_io_base &= PCI_BASE_ADDRESS_IO_MASK;
573 TLAN_DBG( TLAN_DEBUG_GNRL, "TLAN: IO mapping is available at %x.\n", *pci_io_base);
574 break;
575 } else {
576 *pci_io_base = 0;
580 if ( *pci_io_base == 0 )
581 printk("TLAN: IO mapping not available, ignoring device.\n");
583 pci_set_master(pdev);
585 if ( *pci_io_base ) {
586 *dl_ix = dl_index;
587 return 1;
590 } else {
591 pdev = NULL;
595 return 0;
597 } /* TLan_PciProbe */
602 /***************************************************************
603 * TLan_Init
605 * Returns:
606 * 0 on success, error code otherwise.
607 * Parms:
608 * dev The structure of the device to be
609 * init'ed.
611 * This function completes the initialization of the
612 * device structure and driver. It reserves the IO
613 * addresses, allocates memory for the lists and bounce
614 * buffers, retrieves the MAC address from the eeprom
615 * and assignes the device's methods.
617 **************************************************************/
619 int TLan_Init( struct net_device *dev )
621 int dma_size;
622 int err;
623 int i;
624 TLanPrivateInfo *priv;
626 priv = (TLanPrivateInfo *) dev->priv;
628 err = check_region( dev->base_addr, 0x10 );
629 if ( err ) {
630 printk( "TLAN: %s: Io port region 0x%lx size 0x%x in use.\n",
631 dev->name,
632 dev->base_addr,
633 0x10 );
634 return -EIO;
636 request_region( dev->base_addr, 0x10, TLanSignature );
638 if ( bbuf ) {
639 dma_size = ( TLAN_NUM_RX_LISTS + TLAN_NUM_TX_LISTS )
640 * ( sizeof(TLanList) + TLAN_MAX_FRAME_SIZE );
641 } else {
642 dma_size = ( TLAN_NUM_RX_LISTS + TLAN_NUM_TX_LISTS )
643 * ( sizeof(TLanList) );
646 priv->dmaStorage = kmalloc( dma_size, GFP_KERNEL | GFP_DMA );
647 if ( priv->dmaStorage == NULL ) {
648 printk( "TLAN: Could not allocate lists and buffers for %s.\n",
649 dev->name );
650 return -ENOMEM;
652 memset( priv->dmaStorage, 0, dma_size );
653 priv->rxList = (TLanList *)
654 ( ( ( (u32) priv->dmaStorage ) + 7 ) & 0xFFFFFFF8 );
655 priv->txList = priv->rxList + TLAN_NUM_RX_LISTS;
657 if ( bbuf ) {
658 priv->rxBuffer = (u8 *) ( priv->txList + TLAN_NUM_TX_LISTS );
659 priv->txBuffer = priv->rxBuffer
660 + ( TLAN_NUM_RX_LISTS * TLAN_MAX_FRAME_SIZE );
663 err = 0;
664 for ( i = 0; i < 6 ; i++ )
665 err |= TLan_EeReadByte( dev,
666 (u8) priv->adapter->addrOfs + i,
667 (u8 *) &dev->dev_addr[i] );
668 if ( err ) {
669 printk( "TLAN: %s: Error reading MAC from eeprom: %d\n",
670 dev->name,
671 err );
674 dev->addr_len = 6;
676 dev->open = &TLan_Open;
677 dev->hard_start_xmit = &TLan_StartTx;
678 dev->stop = &TLan_Close;
679 dev->get_stats = &TLan_GetStats;
680 dev->set_multicast_list = &TLan_SetMulticastList;
683 return 0;
685 } /* TLan_Init */
690 /***************************************************************
691 * TLan_Open
693 * Returns:
694 * 0 on success, error code otherwise.
695 * Parms:
696 * dev Structure of device to be opened.
698 * This routine puts the driver and TLAN adapter in a
699 * state where it is ready to send and receive packets.
700 * It allocates the IRQ, resets and brings the adapter
701 * out of reset, and allows interrupts. It also delays
702 * the startup for autonegotiation or sends a Rx GO
703 * command to the adapter, as appropriate.
705 **************************************************************/
707 int TLan_Open( struct net_device *dev )
709 TLanPrivateInfo *priv = (TLanPrivateInfo *) dev->priv;
710 int err;
712 priv->tlanRev = TLan_DioRead8( dev->base_addr, TLAN_DEF_REVISION );
713 if ( priv->sa_int ) {
714 TLAN_DBG( TLAN_DEBUG_GNRL, "TLAN: Using SA_INTERRUPT\n" );
715 err = request_irq( dev->irq, TLan_HandleInterrupt, SA_SHIRQ | SA_INTERRUPT, TLanSignature, dev );
716 } else {
717 err = request_irq( dev->irq, TLan_HandleInterrupt, SA_SHIRQ, TLanSignature, dev );
719 if ( err ) {
720 printk( "TLAN: Cannot open %s because IRQ %d is already in use.\n", dev->name, dev->irq );
721 return -EAGAIN;
724 MOD_INC_USE_COUNT;
726 dev->tbusy = 0;
727 dev->interrupt = 0;
728 dev->start = 1;
730 /* NOTE: It might not be necessary to read the stats before a
731 reset if you don't care what the values are.
733 TLan_ResetLists( dev );
734 TLan_ReadAndClearStats( dev, TLAN_IGNORE );
735 TLan_ResetAdapter( dev );
737 TLAN_DBG( TLAN_DEBUG_GNRL, "TLAN: %s: Opened. TLAN Chip Rev: %x\n", dev->name, priv->tlanRev );
739 return 0;
741 } /* TLan_Open */
746 /***************************************************************
747 * TLan_StartTx
749 * Returns:
750 * 0 on success, non-zero on failure.
751 * Parms:
752 * skb A pointer to the sk_buff containing the
753 * frame to be sent.
754 * dev The device to send the data on.
756 * This function adds a frame to the Tx list to be sent
757 * ASAP. First it verifies that the adapter is ready and
758 * there is room in the queue. Then it sets up the next
759 * available list, copies the frame to the corresponding
760 * buffer. If the adapter Tx channel is idle, it gives
761 * the adapter a Tx Go command on the list, otherwise it
762 * sets the forward address of the previous list to point
763 * to this one. Then it frees the sk_buff.
765 **************************************************************/
767 int TLan_StartTx( struct sk_buff *skb, struct net_device *dev )
769 TLanPrivateInfo *priv = (TLanPrivateInfo *) dev->priv;
770 TLanList *tail_list;
771 u8 *tail_buffer;
772 int pad;
774 if ( ! priv->phyOnline ) {
775 TLAN_DBG( TLAN_DEBUG_TX, "TLAN TRANSMIT: %s PHY is not ready\n", dev->name );
776 dev_kfree_skb( skb );
777 return 0;
780 tail_list = priv->txList + priv->txTail;
782 if ( tail_list->cStat != TLAN_CSTAT_UNUSED ) {
783 TLAN_DBG( TLAN_DEBUG_TX, "TLAN TRANSMIT: %s is busy (Head=%d Tail=%d)\n", dev->name, priv->txHead, priv->txTail );
784 dev->tbusy = 1;
785 priv->txBusyCount++;
786 return 1;
789 tail_list->forward = 0;
791 if ( bbuf ) {
792 tail_buffer = priv->txBuffer + ( priv->txTail * TLAN_MAX_FRAME_SIZE );
793 memcpy( tail_buffer, skb->data, skb->len );
794 } else {
795 tail_list->buffer[0].address = virt_to_bus( skb->data );
796 tail_list->buffer[9].address = (u32) skb;
799 pad = TLAN_MIN_FRAME_SIZE - skb->len;
801 if ( pad > 0 ) {
802 tail_list->frameSize = (u16) skb->len + pad;
803 tail_list->buffer[0].count = (u32) skb->len;
804 tail_list->buffer[1].count = TLAN_LAST_BUFFER | (u32) pad;
805 tail_list->buffer[1].address = virt_to_bus( TLanPadBuffer );
806 } else {
807 tail_list->frameSize = (u16) skb->len;
808 tail_list->buffer[0].count = TLAN_LAST_BUFFER | (u32) skb->len;
809 tail_list->buffer[1].count = 0;
810 tail_list->buffer[1].address = 0;
813 cli();
814 tail_list->cStat = TLAN_CSTAT_READY;
815 if ( ! priv->txInProgress ) {
816 priv->txInProgress = 1;
817 outw( 0x4, dev->base_addr + TLAN_HOST_INT );
818 TLAN_DBG( TLAN_DEBUG_TX, "TLAN TRANSMIT: Starting TX on buffer %d\n", priv->txTail );
819 outl( virt_to_bus( tail_list ), dev->base_addr + TLAN_CH_PARM );
820 outl( TLAN_HC_GO | TLAN_HC_ACK, dev->base_addr + TLAN_HOST_CMD );
821 } else {
822 TLAN_DBG( TLAN_DEBUG_TX, "TLAN TRANSMIT: Adding buffer %d to TX channel\n", priv->txTail );
823 if ( priv->txTail == 0 ) {
824 ( priv->txList + ( TLAN_NUM_TX_LISTS - 1 ) )->forward = virt_to_bus( tail_list );
825 } else {
826 ( priv->txList + ( priv->txTail - 1 ) )->forward = virt_to_bus( tail_list );
829 sti();
831 CIRC_INC( priv->txTail, TLAN_NUM_TX_LISTS );
833 if ( bbuf ) {
834 dev_kfree_skb( skb );
837 dev->trans_start = jiffies;
838 return 0;
840 } /* TLan_StartTx */
845 /***************************************************************
846 * TLan_HandleInterrupt
848 * Returns:
849 * Nothing
850 * Parms:
851 * irq The line on which the interrupt
852 * occurred.
853 * dev_id A pointer to the device assigned to
854 * this irq line.
855 * regs ???
857 * This function handles an interrupt generated by its
858 * assigned TLAN adapter. The function deactivates
859 * interrupts on its adapter, records the type of
860 * interrupt, executes the appropriate subhandler, and
861 * acknowdges the interrupt to the adapter (thus
862 * re-enabling adapter interrupts.
864 **************************************************************/
866 void TLan_HandleInterrupt(int irq, void *dev_id, struct pt_regs *regs)
868 u32 ack;
869 struct net_device *dev;
870 u32 host_cmd;
871 u16 host_int;
872 int type;
874 dev = (struct net_device *) dev_id;
876 cli();
877 if ( dev->interrupt ) {
878 printk( "TLAN: Re-entering interrupt handler for %s: %ld.\n" , dev->name, dev->interrupt );
880 dev->interrupt++;
882 host_int = inw( dev->base_addr + TLAN_HOST_INT );
883 outw( host_int, dev->base_addr + TLAN_HOST_INT );
885 type = ( host_int & TLAN_HI_IT_MASK ) >> 2;
887 ack = TLanIntVector[type]( dev, host_int );
889 if ( ack ) {
890 host_cmd = TLAN_HC_ACK | ack | ( type << 18 );
891 outl( host_cmd, dev->base_addr + TLAN_HOST_CMD );
894 dev->interrupt--;
895 sti();
897 } /* TLan_HandleInterrupts */
902 /***************************************************************
903 * TLan_Close
905 * Returns:
906 * An error code.
907 * Parms:
908 * dev The device structure of the device to
909 * close.
911 * This function shuts down the adapter. It records any
912 * stats, puts the adapter into reset state, deactivates
913 * its time as needed, and frees the irq it is using.
915 **************************************************************/
917 int TLan_Close(struct net_device *dev)
919 TLanPrivateInfo *priv = (TLanPrivateInfo *) dev->priv;
921 dev->start = 0;
922 dev->tbusy = 1;
924 TLan_ReadAndClearStats( dev, TLAN_RECORD );
925 outl( TLAN_HC_AD_RST, dev->base_addr + TLAN_HOST_CMD );
926 if ( priv->timer.function != NULL )
927 del_timer( &priv->timer );
928 free_irq( dev->irq, dev );
929 TLan_FreeLists( dev );
930 TLAN_DBG( TLAN_DEBUG_GNRL, "TLAN: Device %s closed.\n", dev->name );
932 MOD_DEC_USE_COUNT;
934 return 0;
936 } /* TLan_Close */
941 /***************************************************************
942 * TLan_GetStats
944 * Returns:
945 * A pointer to the device's statistics structure.
946 * Parms:
947 * dev The device structure to return the
948 * stats for.
950 * This function updates the devices statistics by reading
951 * the TLAN chip's onboard registers. Then it returns the
952 * address of the statistics structure.
954 **************************************************************/
956 struct net_device_stats *TLan_GetStats( struct net_device *dev )
958 TLanPrivateInfo *priv = (TLanPrivateInfo *) dev->priv;
959 int i;
961 /* Should only read stats if open ? */
962 TLan_ReadAndClearStats( dev, TLAN_RECORD );
964 TLAN_DBG( TLAN_DEBUG_RX, "TLAN RECEIVE: %s EOC count = %d\n", dev->name, priv->rxEocCount );
965 TLAN_DBG( TLAN_DEBUG_TX, "TLAN TRANSMIT: %s Busy count = %d\n", dev->name, priv->txBusyCount );
966 if ( debug & TLAN_DEBUG_GNRL ) {
967 TLan_PrintDio( dev->base_addr );
968 TLan_PhyPrint( dev );
970 if ( debug & TLAN_DEBUG_LIST ) {
971 for ( i = 0; i < TLAN_NUM_RX_LISTS; i++ )
972 TLan_PrintList( priv->rxList + i, "RX", i );
973 for ( i = 0; i < TLAN_NUM_TX_LISTS; i++ )
974 TLan_PrintList( priv->txList + i, "TX", i );
977 return ( &( (TLanPrivateInfo *) dev->priv )->stats );
979 } /* TLan_GetStats */
984 /***************************************************************
985 * TLan_SetMulticastList
987 * Returns:
988 * Nothing
989 * Parms:
990 * dev The device structure to set the
991 * multicast list for.
993 * This function sets the TLAN adaptor to various receive
994 * modes. If the IFF_PROMISC flag is set, promiscuous
995 * mode is acitviated. Otherwise, promiscuous mode is
996 * turned off. If the IFF_ALLMULTI flag is set, then
997 * the hash table is set to receive all group addresses.
998 * Otherwise, the first three multicast addresses are
999 * stored in AREG_1-3, and the rest are selected via the
1000 * hash table, as necessary.
1002 **************************************************************/
1004 void TLan_SetMulticastList( struct net_device *dev )
1006 struct dev_mc_list *dmi = dev->mc_list;
1007 u32 hash1 = 0;
1008 u32 hash2 = 0;
1009 int i;
1010 u32 offset;
1011 u8 tmp;
1013 if ( dev->flags & IFF_PROMISC ) {
1014 tmp = TLan_DioRead8( dev->base_addr, TLAN_NET_CMD );
1015 TLan_DioWrite8( dev->base_addr, TLAN_NET_CMD, tmp | TLAN_NET_CMD_CAF );
1016 } else {
1017 tmp = TLan_DioRead8( dev->base_addr, TLAN_NET_CMD );
1018 TLan_DioWrite8( dev->base_addr, TLAN_NET_CMD, tmp & ~TLAN_NET_CMD_CAF );
1019 if ( dev->flags & IFF_ALLMULTI ) {
1020 for ( i = 0; i < 3; i++ )
1021 TLan_SetMac( dev, i + 1, NULL );
1022 TLan_DioWrite32( dev->base_addr, TLAN_HASH_1, 0xFFFFFFFF );
1023 TLan_DioWrite32( dev->base_addr, TLAN_HASH_2, 0xFFFFFFFF );
1024 } else {
1025 for ( i = 0; i < dev->mc_count; i++ ) {
1026 if ( i < 3 ) {
1027 TLan_SetMac( dev, i + 1, (char *) &dmi->dmi_addr );
1028 } else {
1029 offset = TLan_HashFunc( (u8 *) &dmi->dmi_addr );
1030 if ( offset < 32 )
1031 hash1 |= ( 1 << offset );
1032 else
1033 hash2 |= ( 1 << ( offset - 32 ) );
1035 dmi = dmi->next;
1037 for ( ; i < 3; i++ )
1038 TLan_SetMac( dev, i + 1, NULL );
1039 TLan_DioWrite32( dev->base_addr, TLAN_HASH_1, hash1 );
1040 TLan_DioWrite32( dev->base_addr, TLAN_HASH_2, hash2 );
1044 } /* TLan_SetMulticastList */
1048 /*****************************************************************************
1049 ******************************************************************************
1051 ThunderLAN Driver Interrupt Vectors and Table
1053 Please see Chap. 4, "Interrupt Handling" of the "ThunderLAN
1054 Programmer's Guide" for more informations on handling interrupts
1055 generated by TLAN based adapters.
1057 ******************************************************************************
1058 *****************************************************************************/
1061 /***************************************************************
1062 * TLan_HandleInvalid
1064 * Returns:
1066 * Parms:
1067 * dev Device assigned the IRQ that was
1068 * raised.
1069 * host_int The contents of the HOST_INT
1070 * port.
1072 * This function handles invalid interrupts. This should
1073 * never happen unless some other adapter is trying to use
1074 * the IRQ line assigned to the device.
1076 **************************************************************/
1078 u32 TLan_HandleInvalid( struct net_device *dev, u16 host_int )
1080 host_int = 0;
1081 /* printk( "TLAN: Invalid interrupt on %s.\n", dev->name ); */
1082 return 0;
1084 } /* TLan_HandleInvalid */
1089 /***************************************************************
1090 * TLan_HandleTxEOF
1092 * Returns:
1094 * Parms:
1095 * dev Device assigned the IRQ that was
1096 * raised.
1097 * host_int The contents of the HOST_INT
1098 * port.
1100 * This function handles Tx EOF interrupts which are raised
1101 * by the adapter when it has completed sending the
1102 * contents of a buffer. If detemines which list/buffer
1103 * was completed and resets it. If the buffer was the last
1104 * in the channel (EOC), then the function checks to see if
1105 * another buffer is ready to send, and if so, sends a Tx
1106 * Go command. Finally, the driver activates/continues the
1107 * activity LED.
1109 **************************************************************/
1111 u32 TLan_HandleTxEOF( struct net_device *dev, u16 host_int )
1113 TLanPrivateInfo *priv = (TLanPrivateInfo *) dev->priv;
1114 int eoc = 0;
1115 TLanList *head_list;
1116 u32 ack = 1;
1118 TLAN_DBG( TLAN_DEBUG_TX, "TLAN TRANSMIT: Handling TX EOF (Head=%d Tail=%d)\n", priv->txHead, priv->txTail );
1119 host_int = 0;
1120 head_list = priv->txList + priv->txHead;
1122 if ( ! bbuf ) {
1123 dev_kfree_skb( (struct sk_buff *) head_list->buffer[9].address );
1124 head_list->buffer[9].address = 0;
1127 if ( head_list->cStat & TLAN_CSTAT_EOC )
1128 eoc = 1;
1129 if ( ! head_list->cStat & TLAN_CSTAT_FRM_CMP ) {
1130 printk( "TLAN: Received interrupt for uncompleted TX frame.\n" );
1133 #if LINUX_KERNEL_VERSION > 0x20100
1134 priv->stats->tx_bytes += head_list->frameSize;
1135 #endif
1137 head_list->cStat = TLAN_CSTAT_UNUSED;
1138 dev->tbusy = 0;
1139 CIRC_INC( priv->txHead, TLAN_NUM_TX_LISTS );
1140 if ( eoc ) {
1141 TLAN_DBG( TLAN_DEBUG_TX, "TLAN TRANSMIT: Handling TX EOC (Head=%d Tail=%d)\n", priv->txHead, priv->txTail );
1142 head_list = priv->txList + priv->txHead;
1143 if ( ( head_list->cStat & TLAN_CSTAT_READY ) == TLAN_CSTAT_READY ) {
1144 outl( virt_to_bus( head_list ), dev->base_addr + TLAN_CH_PARM );
1145 ack |= TLAN_HC_GO;
1146 } else {
1147 priv->txInProgress = 0;
1151 if ( priv->adapter->flags & TLAN_ADAPTER_ACTIVITY_LED ) {
1152 TLan_DioWrite8( dev->base_addr, TLAN_LED_REG, TLAN_LED_LINK | TLAN_LED_ACT );
1153 if ( priv->timer.function == NULL ) {
1154 TLan_SetTimer( dev, TLAN_TIMER_ACT_DELAY, TLAN_TIMER_ACTIVITY );
1155 } else if ( priv->timerType == TLAN_TIMER_ACTIVITY ) {
1156 priv->timerSetAt = jiffies;
1160 return ack;
1162 } /* TLan_HandleTxEOF */
1167 /***************************************************************
1168 * TLan_HandleStatOverflow
1170 * Returns:
1172 * Parms:
1173 * dev Device assigned the IRQ that was
1174 * raised.
1175 * host_int The contents of the HOST_INT
1176 * port.
1178 * This function handles the Statistics Overflow interrupt
1179 * which means that one or more of the TLAN statistics
1180 * registers has reached 1/2 capacity and needs to be read.
1182 **************************************************************/
1184 u32 TLan_HandleStatOverflow( struct net_device *dev, u16 host_int )
1186 host_int = 0;
1187 TLan_ReadAndClearStats( dev, TLAN_RECORD );
1189 return 1;
1191 } /* TLan_HandleStatOverflow */
1196 /***************************************************************
1197 * TLan_HandleRxEOF
1199 * Returns:
1201 * Parms:
1202 * dev Device assigned the IRQ that was
1203 * raised.
1204 * host_int The contents of the HOST_INT
1205 * port.
1207 * This function handles the Rx EOF interrupt which
1208 * indicates a frame has been received by the adapter from
1209 * the net and the frame has been transferred to memory.
1210 * The function determines the bounce buffer the frame has
1211 * been loaded into, creates a new sk_buff big enough to
1212 * hold the frame, and sends it to protocol stack. It
1213 * then resets the used buffer and appends it to the end
1214 * of the list. If the frame was the last in the Rx
1215 * channel (EOC), the function restarts the receive channel
1216 * by sending an Rx Go command to the adapter. Then it
1217 * activates/continues the the activity LED.
1219 **************************************************************/
1221 u32 TLan_HandleRxEOF( struct net_device *dev, u16 host_int )
1223 TLanPrivateInfo *priv = (TLanPrivateInfo *) dev->priv;
1224 u32 ack = 1;
1225 int eoc = 0;
1226 u8 *head_buffer;
1227 TLanList *head_list;
1228 struct sk_buff *skb;
1229 TLanList *tail_list;
1230 void *t;
1232 TLAN_DBG( TLAN_DEBUG_RX, "TLAN RECEIVE: Handling RX EOF (Head=%d Tail=%d)\n", priv->rxHead, priv->rxTail );
1233 host_int = 0;
1234 head_list = priv->rxList + priv->rxHead;
1235 tail_list = priv->rxList + priv->rxTail;
1237 if ( head_list->cStat & TLAN_CSTAT_EOC ) {
1238 eoc = 1;
1241 if ( ! head_list->cStat & TLAN_CSTAT_FRM_CMP ) {
1242 printk( "TLAN: Received interrupt for uncompleted RX frame.\n" );
1243 } else if ( bbuf ) {
1244 skb = dev_alloc_skb( head_list->frameSize + 7 );
1245 if ( skb == NULL ) {
1246 printk( "TLAN: Couldn't allocate memory for received data.\n" );
1247 } else {
1248 head_buffer = priv->rxBuffer + ( priv->rxHead * TLAN_MAX_FRAME_SIZE );
1249 skb->dev = dev;
1250 skb_reserve( skb, 2 );
1251 t = (void *) skb_put( skb, head_list->frameSize );
1253 #if LINUX_KERNEL_VERSION > 0x20100
1254 priv->stats->rx_bytes += head_list->frameSize;
1255 #endif
1257 memcpy( t, head_buffer, head_list->frameSize );
1258 skb->protocol = eth_type_trans( skb, dev );
1259 netif_rx( skb );
1261 } else {
1262 struct sk_buff *new_skb;
1265 * I changed the algorithm here. What we now do
1266 * is allocate the new frame. If this fails we
1267 * simply recycle the frame.
1270 new_skb = dev_alloc_skb( TLAN_MAX_FRAME_SIZE + 7 );
1271 if ( new_skb != NULL ) {
1272 /* If this ever happened it would be a problem */
1273 /* not any more - ac */
1274 skb = (struct sk_buff *) head_list->buffer[9].address;
1275 head_list->buffer[9].address = 0;
1276 skb_trim( skb, head_list->frameSize );
1277 #if LINUX_KERNEL_VERSION > 0x20100
1278 priv->stats->rx_bytes += head_list->frameSize;
1279 #endif
1281 skb->protocol = eth_type_trans( skb, dev );
1282 netif_rx( skb );
1284 new_skb->dev = dev;
1285 skb_reserve( new_skb, 2 );
1286 t = (void *) skb_put( new_skb, TLAN_MAX_FRAME_SIZE );
1287 head_list->buffer[0].address = virt_to_bus( t );
1288 head_list->buffer[9].address = (u32) new_skb;
1290 else
1291 printk(KERN_WARNING "TLAN: Couldn't allocate memory for received data.\n" );
1294 head_list->forward = 0;
1295 head_list->frameSize = TLAN_MAX_FRAME_SIZE;
1296 head_list->buffer[0].count = TLAN_MAX_FRAME_SIZE | TLAN_LAST_BUFFER;
1297 tail_list->forward = virt_to_bus( head_list );
1299 CIRC_INC( priv->rxHead, TLAN_NUM_RX_LISTS );
1300 CIRC_INC( priv->rxTail, TLAN_NUM_RX_LISTS );
1302 if ( eoc ) {
1303 TLAN_DBG( TLAN_DEBUG_RX, "TLAN RECEIVE: Handling RX EOC (Head=%d Tail=%d)\n", priv->rxHead, priv->rxTail );
1304 head_list = priv->rxList + priv->rxHead;
1305 outl( virt_to_bus( head_list ), dev->base_addr + TLAN_CH_PARM );
1306 ack |= TLAN_HC_GO | TLAN_HC_RT;
1307 priv->rxEocCount++;
1310 if ( priv->adapter->flags & TLAN_ADAPTER_ACTIVITY_LED ) {
1311 TLan_DioWrite8( dev->base_addr, TLAN_LED_REG, TLAN_LED_LINK | TLAN_LED_ACT );
1312 if ( priv->timer.function == NULL ) {
1313 TLan_SetTimer( dev, TLAN_TIMER_ACT_DELAY, TLAN_TIMER_ACTIVITY );
1314 } else if ( priv->timerType == TLAN_TIMER_ACTIVITY ) {
1315 priv->timerSetAt = jiffies;
1319 dev->last_rx = jiffies;
1321 return ack;
1323 } /* TLan_HandleRxEOF */
1328 /***************************************************************
1329 * TLan_HandleDummy
1331 * Returns:
1333 * Parms:
1334 * dev Device assigned the IRQ that was
1335 * raised.
1336 * host_int The contents of the HOST_INT
1337 * port.
1339 * This function handles the Dummy interrupt, which is
1340 * raised whenever a test interrupt is generated by setting
1341 * the Req_Int bit of HOST_CMD to 1.
1343 **************************************************************/
1345 u32 TLan_HandleDummy( struct net_device *dev, u16 host_int )
1347 host_int = 0;
1348 printk( "TLAN: Test interrupt on %s.\n", dev->name );
1349 return 1;
1351 } /* TLan_HandleDummy */
1356 /***************************************************************
1357 * TLan_HandleTxEOC
1359 * Returns:
1361 * Parms:
1362 * dev Device assigned the IRQ that was
1363 * raised.
1364 * host_int The contents of the HOST_INT
1365 * port.
1367 * This driver is structured to determine EOC occurances by
1368 * reading the CSTAT member of the list structure. Tx EOC
1369 * interrupts are disabled via the DIO INTDIS register.
1370 * However, TLAN chips before revision 3.0 didn't have this
1371 * functionality, so process EOC events if this is the
1372 * case.
1374 **************************************************************/
1376 u32 TLan_HandleTxEOC( struct net_device *dev, u16 host_int )
1378 TLanPrivateInfo *priv = (TLanPrivateInfo *) dev->priv;
1379 TLanList *head_list;
1380 u32 ack = 1;
1382 host_int = 0;
1383 if ( priv->tlanRev < 0x30 ) {
1384 TLAN_DBG( TLAN_DEBUG_TX, "TLAN TRANSMIT: Handling TX EOC (Head=%d Tail=%d) -- IRQ\n", priv->txHead, priv->txTail );
1385 head_list = priv->txList + priv->txHead;
1386 if ( ( head_list->cStat & TLAN_CSTAT_READY ) == TLAN_CSTAT_READY ) {
1387 outl( virt_to_bus( head_list ), dev->base_addr + TLAN_CH_PARM );
1388 ack |= TLAN_HC_GO;
1389 } else {
1390 priv->txInProgress = 0;
1394 return ack;
1396 } /* TLan_HandleTxEOC */
1401 /***************************************************************
1402 * TLan_HandleStatusCheck
1404 * Returns:
1405 * 0 if Adapter check, 1 if Network Status check.
1406 * Parms:
1407 * dev Device assigned the IRQ that was
1408 * raised.
1409 * host_int The contents of the HOST_INT
1410 * port.
1412 * This function handles Adapter Check/Network Status
1413 * interrupts generated by the adapter. It checks the
1414 * vector in the HOST_INT register to determine if it is
1415 * an Adapter Check interrupt. If so, it resets the
1416 * adapter. Otherwise it clears the status registers
1417 * and services the PHY.
1419 **************************************************************/
1421 u32 TLan_HandleStatusCheck( struct net_device *dev, u16 host_int )
1423 TLanPrivateInfo *priv = (TLanPrivateInfo *) dev->priv;
1424 u32 ack;
1425 u32 error;
1426 u8 net_sts;
1427 u32 phy;
1428 u16 tlphy_ctl;
1429 u16 tlphy_sts;
1431 ack = 1;
1432 if ( host_int & TLAN_HI_IV_MASK ) {
1433 error = inl( dev->base_addr + TLAN_CH_PARM );
1434 printk( "TLAN: %s: Adaptor Error = 0x%x\n", dev->name, error );
1435 TLan_ReadAndClearStats( dev, TLAN_RECORD );
1436 outl( TLAN_HC_AD_RST, dev->base_addr + TLAN_HOST_CMD );
1437 TLan_FreeLists( dev );
1438 TLan_ResetLists( dev );
1439 TLan_ResetAdapter( dev );
1440 dev->tbusy = 0;
1441 ack = 0;
1442 } else {
1443 TLAN_DBG( TLAN_DEBUG_GNRL, "TLAN: %s: Status Check\n", dev->name );
1444 phy = priv->phy[priv->phyNum];
1446 net_sts = TLan_DioRead8( dev->base_addr, TLAN_NET_STS );
1447 if ( net_sts ) {
1448 TLan_DioWrite8( dev->base_addr, TLAN_NET_STS, net_sts );
1449 TLAN_DBG( TLAN_DEBUG_GNRL, "TLAN: %s: Net_Sts = %x\n", dev->name, (unsigned) net_sts );
1451 if ( ( net_sts & TLAN_NET_STS_MIRQ ) && ( priv->phyNum == 0 ) ) {
1452 TLan_MiiReadReg( dev, phy, TLAN_TLPHY_STS, &tlphy_sts );
1453 TLan_MiiReadReg( dev, phy, TLAN_TLPHY_CTL, &tlphy_ctl );
1454 if ( ! ( tlphy_sts & TLAN_TS_POLOK ) && ! ( tlphy_ctl & TLAN_TC_SWAPOL ) ) {
1455 tlphy_ctl |= TLAN_TC_SWAPOL;
1456 TLan_MiiWriteReg( dev, phy, TLAN_TLPHY_CTL, tlphy_ctl);
1457 } else if ( ( tlphy_sts & TLAN_TS_POLOK ) && ( tlphy_ctl & TLAN_TC_SWAPOL ) ) {
1458 tlphy_ctl &= ~TLAN_TC_SWAPOL;
1459 TLan_MiiWriteReg( dev, phy, TLAN_TLPHY_CTL, tlphy_ctl);
1462 if (debug) {
1463 TLan_PhyPrint( dev );
1468 return ack;
1470 } /* TLan_HandleStatusCheck */
1475 /***************************************************************
1476 * TLan_HandleRxEOC
1478 * Returns:
1480 * Parms:
1481 * dev Device assigned the IRQ that was
1482 * raised.
1483 * host_int The contents of the HOST_INT
1484 * port.
1486 * This driver is structured to determine EOC occurances by
1487 * reading the CSTAT member of the list structure. Rx EOC
1488 * interrupts are disabled via the DIO INTDIS register.
1489 * However, TLAN chips before revision 3.0 didn't have this
1490 * CSTAT member or a INTDIS register, so if this chip is
1491 * pre-3.0, process EOC interrupts normally.
1493 **************************************************************/
1495 u32 TLan_HandleRxEOC( struct net_device *dev, u16 host_int )
1497 TLanPrivateInfo *priv = (TLanPrivateInfo *) dev->priv;
1498 TLanList *head_list;
1499 u32 ack = 1;
1501 host_int = 0;
1502 if ( priv->tlanRev < 0x30 ) {
1503 TLAN_DBG( TLAN_DEBUG_RX, "TLAN RECEIVE: Handling RX EOC (Head=%d Tail=%d) -- IRQ\n", priv->rxHead, priv->rxTail );
1504 head_list = priv->rxList + priv->rxHead;
1505 outl( virt_to_bus( head_list ), dev->base_addr + TLAN_CH_PARM );
1506 ack |= TLAN_HC_GO | TLAN_HC_RT;
1507 priv->rxEocCount++;
1510 return ack;
1512 } /* TLan_HandleRxEOC */
1517 /*****************************************************************************
1518 ******************************************************************************
1520 ThunderLAN Driver Timer Function
1522 ******************************************************************************
1523 *****************************************************************************/
1526 /***************************************************************
1527 * TLan_Timer
1529 * Returns:
1530 * Nothing
1531 * Parms:
1532 * data A value given to add timer when
1533 * add_timer was called.
1535 * This function handles timed functionality for the
1536 * TLAN driver. The two current timer uses are for
1537 * delaying for autonegotionation and driving the ACT LED.
1538 * - Autonegotiation requires being allowed about
1539 * 2 1/2 seconds before attempting to transmit a
1540 * packet. It would be a very bad thing to hang
1541 * the kernel this long, so the driver doesn't
1542 * allow transmission 'til after this time, for
1543 * certain PHYs. It would be much nicer if all
1544 * PHYs were interrupt-capable like the internal
1545 * PHY.
1546 * - The ACT LED, which shows adapter activity, is
1547 * driven by the driver, and so must be left on
1548 * for a short period to power up the LED so it
1549 * can be seen. This delay can be changed by
1550 * changing the TLAN_TIMER_ACT_DELAY in tlan.h,
1551 * if desired. 10 jiffies produces a slightly
1552 * sluggish response.
1554 **************************************************************/
1556 void TLan_Timer( unsigned long data )
1558 struct net_device *dev = (struct net_device *) data;
1559 TLanPrivateInfo *priv = (TLanPrivateInfo *) dev->priv;
1560 u32 elapsed;
1562 priv->timer.function = NULL;
1564 switch ( priv->timerType ) {
1565 case TLAN_TIMER_PHY_PDOWN:
1566 TLan_PhyPowerDown( dev );
1567 break;
1568 case TLAN_TIMER_PHY_PUP:
1569 TLan_PhyPowerUp( dev );
1570 break;
1571 case TLAN_TIMER_PHY_RESET:
1572 TLan_PhyReset( dev );
1573 break;
1574 case TLAN_TIMER_PHY_START_LINK:
1575 TLan_PhyStartLink( dev );
1576 break;
1577 case TLAN_TIMER_PHY_FINISH_AN:
1578 TLan_PhyFinishAutoNeg( dev );
1579 break;
1580 case TLAN_TIMER_FINISH_RESET:
1581 TLan_FinishReset( dev );
1582 break;
1583 case TLAN_TIMER_ACTIVITY:
1584 cli();
1585 if ( priv->timer.function == NULL ) {
1586 elapsed = jiffies - priv->timerSetAt;
1587 if ( elapsed >= TLAN_TIMER_ACT_DELAY ) {
1588 TLan_DioWrite8( dev->base_addr, TLAN_LED_REG, TLAN_LED_LINK );
1589 } else {
1590 priv->timer.function = &TLan_Timer;
1591 priv->timer.expires = priv->timerSetAt + TLAN_TIMER_ACT_DELAY;
1592 sti();
1593 add_timer( &priv->timer );
1596 sti();
1597 break;
1598 default:
1599 break;
1602 } /* TLan_Timer */
1607 /*****************************************************************************
1608 ******************************************************************************
1610 ThunderLAN Driver Adapter Related Routines
1612 ******************************************************************************
1613 *****************************************************************************/
1616 /***************************************************************
1617 * TLan_ResetLists
1619 * Returns:
1620 * Nothing
1621 * Parms:
1622 * dev The device structure with the list
1623 * stuctures to be reset.
1625 * This routine sets the variables associated with managing
1626 * the TLAN lists to their initial values.
1628 **************************************************************/
1630 void TLan_ResetLists( struct net_device *dev )
1632 TLanPrivateInfo *priv = (TLanPrivateInfo *) dev->priv;
1633 int i;
1634 TLanList *list;
1635 struct sk_buff *skb;
1636 void *t = NULL;
1638 priv->txHead = 0;
1639 priv->txTail = 0;
1640 for ( i = 0; i < TLAN_NUM_TX_LISTS; i++ ) {
1641 list = priv->txList + i;
1642 list->cStat = TLAN_CSTAT_UNUSED;
1643 if ( bbuf ) {
1644 list->buffer[0].address = virt_to_bus( priv->txBuffer + ( i * TLAN_MAX_FRAME_SIZE ) );
1645 } else {
1646 list->buffer[0].address = 0;
1648 list->buffer[2].count = 0;
1649 list->buffer[2].address = 0;
1652 priv->rxHead = 0;
1653 priv->rxTail = TLAN_NUM_RX_LISTS - 1;
1654 for ( i = 0; i < TLAN_NUM_RX_LISTS; i++ ) {
1655 list = priv->rxList + i;
1656 list->cStat = TLAN_CSTAT_READY;
1657 list->frameSize = TLAN_MAX_FRAME_SIZE;
1658 list->buffer[0].count = TLAN_MAX_FRAME_SIZE | TLAN_LAST_BUFFER;
1659 if ( bbuf ) {
1660 list->buffer[0].address = virt_to_bus( priv->rxBuffer + ( i * TLAN_MAX_FRAME_SIZE ) );
1661 } else {
1662 skb = dev_alloc_skb( TLAN_MAX_FRAME_SIZE + 7 );
1663 if ( skb == NULL ) {
1664 printk( "TLAN: Couldn't allocate memory for received data.\n" );
1665 /* If this ever happened it would be a problem */
1666 } else {
1667 skb->dev = dev;
1668 skb_reserve( skb, 2 );
1669 t = (void *) skb_put( skb, TLAN_MAX_FRAME_SIZE );
1671 list->buffer[0].address = virt_to_bus( t );
1672 list->buffer[9].address = (u32) skb;
1674 list->buffer[1].count = 0;
1675 list->buffer[1].address = 0;
1676 if ( i < TLAN_NUM_RX_LISTS - 1 )
1677 list->forward = virt_to_bus( list + 1 );
1678 else
1679 list->forward = 0;
1682 } /* TLan_ResetLists */
1685 void TLan_FreeLists( struct net_device *dev )
1687 TLanPrivateInfo *priv = (TLanPrivateInfo *) dev->priv;
1688 int i;
1689 TLanList *list;
1690 struct sk_buff *skb;
1692 if ( ! bbuf ) {
1693 for ( i = 0; i < TLAN_NUM_TX_LISTS; i++ ) {
1694 list = priv->txList + i;
1695 skb = (struct sk_buff *) list->buffer[9].address;
1696 if ( skb ) {
1697 dev_kfree_skb( skb );
1698 list->buffer[9].address = 0;
1702 for ( i = 0; i < TLAN_NUM_RX_LISTS; i++ ) {
1703 list = priv->rxList + i;
1704 skb = (struct sk_buff *) list->buffer[9].address;
1705 if ( skb ) {
1706 dev_kfree_skb( skb );
1707 list->buffer[9].address = 0;
1712 } /* TLan_FreeLists */
1717 /***************************************************************
1718 * TLan_PrintDio
1720 * Returns:
1721 * Nothing
1722 * Parms:
1723 * io_base Base IO port of the device of
1724 * which to print DIO registers.
1726 * This function prints out all the the internal (DIO)
1727 * registers of a TLAN chip.
1729 **************************************************************/
1731 void TLan_PrintDio( u16 io_base )
1733 u32 data0, data1;
1734 int i;
1736 printk( "TLAN: Contents of internal registers for io base 0x%04hx.\n", io_base );
1737 printk( "TLAN: Off. +0 +4\n" );
1738 for ( i = 0; i < 0x4C; i+= 8 ) {
1739 data0 = TLan_DioRead32( io_base, i );
1740 data1 = TLan_DioRead32( io_base, i + 0x4 );
1741 printk( "TLAN: 0x%02x 0x%08x 0x%08x\n", i, data0, data1 );
1744 } /* TLan_PrintDio */
1749 /***************************************************************
1750 * TLan_PrintList
1752 * Returns:
1753 * Nothing
1754 * Parms:
1755 * list A pointer to the TLanList structure to
1756 * be printed.
1757 * type A string to designate type of list,
1758 * "Rx" or "Tx".
1759 * num The index of the list.
1761 * This function prints out the contents of the list
1762 * pointed to by the list parameter.
1764 **************************************************************/
1766 void TLan_PrintList( TLanList *list, char *type, int num)
1768 int i;
1770 printk( "TLAN: %s List %d at 0x%08x\n", type, num, (u32) list );
1771 printk( "TLAN: Forward = 0x%08x\n", list->forward );
1772 printk( "TLAN: CSTAT = 0x%04hx\n", list->cStat );
1773 printk( "TLAN: Frame Size = 0x%04hx\n", list->frameSize );
1774 /* for ( i = 0; i < 10; i++ ) { */
1775 for ( i = 0; i < 2; i++ ) {
1776 printk( "TLAN: Buffer[%d].count, addr = 0x%08x, 0x%08x\n", i, list->buffer[i].count, list->buffer[i].address );
1779 } /* TLan_PrintList */
1784 /***************************************************************
1785 * TLan_ReadAndClearStats
1787 * Returns:
1788 * Nothing
1789 * Parms:
1790 * dev Pointer to device structure of adapter
1791 * to which to read stats.
1792 * record Flag indicating whether to add
1794 * This functions reads all the internal status registers
1795 * of the TLAN chip, which clears them as a side effect.
1796 * It then either adds the values to the device's status
1797 * struct, or discards them, depending on whether record
1798 * is TLAN_RECORD (!=0) or TLAN_IGNORE (==0).
1800 **************************************************************/
1802 void TLan_ReadAndClearStats( struct net_device *dev, int record )
1804 TLanPrivateInfo *priv = (TLanPrivateInfo *) dev->priv;
1805 u32 tx_good, tx_under;
1806 u32 rx_good, rx_over;
1807 u32 def_tx, crc, code;
1808 u32 multi_col, single_col;
1809 u32 excess_col, late_col, loss;
1811 outw( TLAN_GOOD_TX_FRMS, dev->base_addr + TLAN_DIO_ADR );
1812 tx_good = inb( dev->base_addr + TLAN_DIO_DATA );
1813 tx_good += inb( dev->base_addr + TLAN_DIO_DATA + 1 ) << 8;
1814 tx_good += inb( dev->base_addr + TLAN_DIO_DATA + 2 ) << 16;
1815 tx_under = inb( dev->base_addr + TLAN_DIO_DATA + 3 );
1817 outw( TLAN_GOOD_RX_FRMS, dev->base_addr + TLAN_DIO_ADR );
1818 rx_good = inb( dev->base_addr + TLAN_DIO_DATA );
1819 rx_good += inb( dev->base_addr + TLAN_DIO_DATA + 1 ) << 8;
1820 rx_good += inb( dev->base_addr + TLAN_DIO_DATA + 2 ) << 16;
1821 rx_over = inb( dev->base_addr + TLAN_DIO_DATA + 3 );
1823 outw( TLAN_DEFERRED_TX, dev->base_addr + TLAN_DIO_ADR );
1824 def_tx = inb( dev->base_addr + TLAN_DIO_DATA );
1825 def_tx += inb( dev->base_addr + TLAN_DIO_DATA + 1 ) << 8;
1826 crc = inb( dev->base_addr + TLAN_DIO_DATA + 2 );
1827 code = inb( dev->base_addr + TLAN_DIO_DATA + 3 );
1829 outw( TLAN_MULTICOL_FRMS, dev->base_addr + TLAN_DIO_ADR );
1830 multi_col = inb( dev->base_addr + TLAN_DIO_DATA );
1831 multi_col += inb( dev->base_addr + TLAN_DIO_DATA + 1 ) << 8;
1832 single_col = inb( dev->base_addr + TLAN_DIO_DATA + 2 );
1833 single_col += inb( dev->base_addr + TLAN_DIO_DATA + 3 ) << 8;
1835 outw( TLAN_EXCESSCOL_FRMS, dev->base_addr + TLAN_DIO_ADR );
1836 excess_col = inb( dev->base_addr + TLAN_DIO_DATA );
1837 late_col = inb( dev->base_addr + TLAN_DIO_DATA + 1 );
1838 loss = inb( dev->base_addr + TLAN_DIO_DATA + 2 );
1840 if ( record ) {
1841 priv->stats.rx_packets += rx_good;
1842 priv->stats.rx_errors += rx_over + crc + code;
1843 priv->stats.tx_packets += tx_good;
1844 priv->stats.tx_errors += tx_under + loss;
1845 priv->stats.collisions += multi_col + single_col + excess_col + late_col;
1847 priv->stats.rx_over_errors += rx_over;
1848 priv->stats.rx_crc_errors += crc;
1849 priv->stats.rx_frame_errors += code;
1851 priv->stats.tx_aborted_errors += tx_under;
1852 priv->stats.tx_carrier_errors += loss;
1855 } /* TLan_ReadAndClearStats */
1860 /***************************************************************
1861 * TLan_Reset
1863 * Returns:
1865 * Parms:
1866 * dev Pointer to device structure of adapter
1867 * to be reset.
1869 * This function resets the adapter and it's physical
1870 * device. See Chap. 3, pp. 9-10 of the "ThunderLAN
1871 * Programmer's Guide" for details. The routine tries to
1872 * implement what is detailed there, though adjustments
1873 * have been made.
1875 **************************************************************/
1877 void
1878 TLan_ResetAdapter( struct net_device *dev )
1880 TLanPrivateInfo *priv = (TLanPrivateInfo *) dev->priv;
1881 int i;
1882 u32 addr;
1883 u32 data;
1884 u8 data8;
1886 priv->tlanFullDuplex = FALSE;
1887 priv->phyOnline=0;
1888 /* 1. Assert reset bit. */
1890 data = inl(dev->base_addr + TLAN_HOST_CMD);
1891 data |= TLAN_HC_AD_RST;
1892 outl(data, dev->base_addr + TLAN_HOST_CMD);
1894 udelay(1000);
1896 /* 2. Turn off interrupts. ( Probably isn't necessary ) */
1898 data = inl(dev->base_addr + TLAN_HOST_CMD);
1899 data |= TLAN_HC_INT_OFF;
1900 outl(data, dev->base_addr + TLAN_HOST_CMD);
1902 /* 3. Clear AREGs and HASHs. */
1904 for ( i = TLAN_AREG_0; i <= TLAN_HASH_2; i += 4 ) {
1905 TLan_DioWrite32( dev->base_addr, (u16) i, 0 );
1908 /* 4. Setup NetConfig register. */
1910 data = TLAN_NET_CFG_1FRAG | TLAN_NET_CFG_1CHAN | TLAN_NET_CFG_PHY_EN;
1911 TLan_DioWrite16( dev->base_addr, TLAN_NET_CONFIG, (u16) data );
1913 /* 5. Load Ld_Tmr and Ld_Thr in HOST_CMD. */
1915 outl( TLAN_HC_LD_TMR | 0x0, dev->base_addr + TLAN_HOST_CMD );
1916 outl( TLAN_HC_LD_THR | 0x1, dev->base_addr + TLAN_HOST_CMD );
1918 /* 6. Unreset the MII by setting NMRST (in NetSio) to 1. */
1920 outw( TLAN_NET_SIO, dev->base_addr + TLAN_DIO_ADR );
1921 addr = dev->base_addr + TLAN_DIO_DATA + TLAN_NET_SIO;
1922 TLan_SetBit( TLAN_NET_SIO_NMRST, addr );
1924 /* 7. Setup the remaining registers. */
1926 if ( priv->tlanRev >= 0x30 ) {
1927 data8 = TLAN_ID_TX_EOC | TLAN_ID_RX_EOC;
1928 TLan_DioWrite8( dev->base_addr, TLAN_INT_DIS, data8 );
1930 TLan_PhyDetect( dev );
1931 data = TLAN_NET_CFG_1FRAG | TLAN_NET_CFG_1CHAN;
1932 if ( priv->adapter->flags & TLAN_ADAPTER_BIT_RATE_PHY ) {
1933 data |= TLAN_NET_CFG_BIT;
1934 if ( priv->aui == 1 ) {
1935 TLan_DioWrite8( dev->base_addr, TLAN_ACOMMIT, 0x0a );
1936 } else if ( priv->duplex == TLAN_DUPLEX_FULL ) {
1937 TLan_DioWrite8( dev->base_addr, TLAN_ACOMMIT, 0x00 );
1938 priv->tlanFullDuplex = TRUE;
1939 } else {
1940 TLan_DioWrite8( dev->base_addr, TLAN_ACOMMIT, 0x08 );
1943 if ( priv->phyNum == 0 ) {
1944 data |= TLAN_NET_CFG_PHY_EN;
1946 TLan_DioWrite16( dev->base_addr, TLAN_NET_CONFIG, (u16) data );
1948 if ( priv->adapter->flags & TLAN_ADAPTER_UNMANAGED_PHY ) {
1949 TLan_FinishReset( dev );
1950 } else {
1951 TLan_PhyPowerDown( dev );
1954 } /* TLan_ResetAdapter */
1959 void
1960 TLan_FinishReset( struct net_device *dev )
1962 TLanPrivateInfo *priv = (TLanPrivateInfo *) dev->priv;
1963 u8 data;
1964 u32 phy;
1965 u8 sio;
1966 u16 status;
1967 u16 tlphy_ctl;
1969 phy = priv->phy[priv->phyNum];
1971 data = TLAN_NET_CMD_NRESET | TLAN_NET_CMD_NWRAP;
1972 if ( priv->tlanFullDuplex ) {
1973 data |= TLAN_NET_CMD_DUPLEX;
1975 TLan_DioWrite8( dev->base_addr, TLAN_NET_CMD, data );
1976 data = TLAN_NET_MASK_MASK4 | TLAN_NET_MASK_MASK5;
1977 if ( priv->phyNum == 0 ) {
1978 data |= TLAN_NET_MASK_MASK7;
1980 TLan_DioWrite8( dev->base_addr, TLAN_NET_MASK, data );
1981 TLan_DioWrite16( dev->base_addr, TLAN_MAX_RX, TLAN_MAX_FRAME_SIZE );
1983 if ( ( priv->adapter->flags & TLAN_ADAPTER_UNMANAGED_PHY ) || ( priv->aui ) ) {
1984 status = MII_GS_LINK;
1985 printk( "TLAN: %s: Link forced.\n", dev->name );
1986 } else {
1987 TLan_MiiReadReg( dev, phy, MII_GEN_STS, &status );
1988 udelay( 1000 );
1989 TLan_MiiReadReg( dev, phy, MII_GEN_STS, &status );
1990 if ( status & MII_GS_LINK ) {
1991 printk( "TLAN: %s: Link active.\n", dev->name );
1992 TLan_DioWrite8( dev->base_addr, TLAN_LED_REG, TLAN_LED_LINK );
1996 if ( priv->phyNum == 0 ) {
1997 TLan_MiiReadReg( dev, phy, TLAN_TLPHY_CTL, &tlphy_ctl );
1998 tlphy_ctl |= TLAN_TC_INTEN;
1999 TLan_MiiWriteReg( dev, phy, TLAN_TLPHY_CTL, tlphy_ctl );
2000 sio = TLan_DioRead8( dev->base_addr, TLAN_NET_SIO );
2001 sio |= TLAN_NET_SIO_MINTEN;
2002 TLan_DioWrite8( dev->base_addr, TLAN_NET_SIO, sio );
2005 if ( status & MII_GS_LINK ) {
2006 TLan_SetMac( dev, 0, dev->dev_addr );
2007 priv->phyOnline = 1;
2008 outb( ( TLAN_HC_INT_ON >> 8 ), dev->base_addr + TLAN_HOST_CMD + 1 );
2009 if ( debug >= 1 ) {
2010 outb( ( TLAN_HC_REQ_INT >> 8 ), dev->base_addr + TLAN_HOST_CMD + 1 );
2012 outl( virt_to_bus( priv->rxList ), dev->base_addr + TLAN_CH_PARM );
2013 outl( TLAN_HC_GO | TLAN_HC_RT, dev->base_addr + TLAN_HOST_CMD );
2014 } else {
2015 printk( "TLAN: %s: Link inactive, will retry in 10 secs...\n", dev->name );
2016 TLan_SetTimer( dev, 1000, TLAN_TIMER_FINISH_RESET );
2017 return;
2020 } /* TLan_FinishReset */
2025 /***************************************************************
2026 * TLan_SetMac
2028 * Returns:
2029 * Nothing
2030 * Parms:
2031 * dev Pointer to device structure of adapter
2032 * on which to change the AREG.
2033 * areg The AREG to set the address in (0 - 3).
2034 * mac A pointer to an array of chars. Each
2035 * element stores one byte of the address.
2036 * IE, it isn't in ascii.
2038 * This function transfers a MAC address to one of the
2039 * TLAN AREGs (address registers). The TLAN chip locks
2040 * the register on writing to offset 0 and unlocks the
2041 * register after writing to offset 5. If NULL is passed
2042 * in mac, then the AREG is filled with 0's.
2044 **************************************************************/
2046 void TLan_SetMac( struct net_device *dev, int areg, char *mac )
2048 int i;
2050 areg *= 6;
2052 if ( mac != NULL ) {
2053 for ( i = 0; i < 6; i++ )
2054 TLan_DioWrite8( dev->base_addr, TLAN_AREG_0 + areg + i, mac[i] );
2055 } else {
2056 for ( i = 0; i < 6; i++ )
2057 TLan_DioWrite8( dev->base_addr, TLAN_AREG_0 + areg + i, 0 );
2060 } /* TLan_SetMac */
2065 /*****************************************************************************
2066 ******************************************************************************
2068 ThunderLAN Driver PHY Layer Routines
2070 ******************************************************************************
2071 *****************************************************************************/
2075 /*********************************************************************
2076 * TLan_PhyPrint
2078 * Returns:
2079 * Nothing
2080 * Parms:
2081 * dev A pointer to the device structure of the
2082 * TLAN device having the PHYs to be detailed.
2084 * This function prints the registers a PHY (aka tranceiver).
2086 ********************************************************************/
2088 void TLan_PhyPrint( struct net_device *dev )
2090 TLanPrivateInfo *priv = (TLanPrivateInfo *) dev->priv;
2091 u16 i, data0, data1, data2, data3, phy;
2093 phy = priv->phy[priv->phyNum];
2095 if ( priv->adapter->flags & TLAN_ADAPTER_UNMANAGED_PHY ) {
2096 printk( "TLAN: Device %s, Unmanaged PHY.\n", dev->name );
2097 } else if ( phy <= TLAN_PHY_MAX_ADDR ) {
2098 printk( "TLAN: Device %s, PHY 0x%02x.\n", dev->name, phy );
2099 printk( "TLAN: Off. +0 +1 +2 +3 \n" );
2100 for ( i = 0; i < 0x20; i+= 4 ) {
2101 printk( "TLAN: 0x%02x", i );
2102 TLan_MiiReadReg( dev, phy, i, &data0 );
2103 printk( " 0x%04hx", data0 );
2104 TLan_MiiReadReg( dev, phy, i + 1, &data1 );
2105 printk( " 0x%04hx", data1 );
2106 TLan_MiiReadReg( dev, phy, i + 2, &data2 );
2107 printk( " 0x%04hx", data2 );
2108 TLan_MiiReadReg( dev, phy, i + 3, &data3 );
2109 printk( " 0x%04hx\n", data3 );
2111 } else {
2112 printk( "TLAN: Device %s, Invalid PHY.\n", dev->name );
2115 } /* TLan_PhyPrint */
2120 /*********************************************************************
2121 * TLan_PhyDetect
2123 * Returns:
2124 * Nothing
2125 * Parms:
2126 * dev A pointer to the device structure of the adapter
2127 * for which the PHY needs determined.
2129 * So far I've found that adapters which have external PHYs
2130 * may also use the internal PHY for part of the functionality.
2131 * (eg, AUI/Thinnet). This function finds out if this TLAN
2132 * chip has an internal PHY, and then finds the first external
2133 * PHY (starting from address 0) if it exists).
2135 ********************************************************************/
2137 void TLan_PhyDetect( struct net_device *dev )
2139 TLanPrivateInfo *priv = (TLanPrivateInfo *) dev->priv;
2140 u16 control;
2141 u16 hi;
2142 u16 lo;
2143 u32 phy;
2145 if ( priv->adapter->flags & TLAN_ADAPTER_UNMANAGED_PHY ) {
2146 priv->phyNum = 0xFFFF;
2147 return;
2150 TLan_MiiReadReg( dev, TLAN_PHY_MAX_ADDR, MII_GEN_ID_HI, &hi );
2152 if ( hi != 0xFFFF ) {
2153 priv->phy[0] = TLAN_PHY_MAX_ADDR;
2154 } else {
2155 priv->phy[0] = TLAN_PHY_NONE;
2158 priv->phy[1] = TLAN_PHY_NONE;
2159 for ( phy = 0; phy <= TLAN_PHY_MAX_ADDR; phy++ ) {
2160 TLan_MiiReadReg( dev, phy, MII_GEN_CTL, &control );
2161 TLan_MiiReadReg( dev, phy, MII_GEN_ID_HI, &hi );
2162 TLan_MiiReadReg( dev, phy, MII_GEN_ID_LO, &lo );
2163 if ( ( control != 0xFFFF ) || ( hi != 0xFFFF ) || ( lo != 0xFFFF ) ) {
2164 TLAN_DBG( TLAN_DEBUG_GNRL, "TLAN: PHY found at %02x %04x %04x %04x\n", phy, control, hi, lo );
2165 if ( ( priv->phy[1] == TLAN_PHY_NONE ) && ( phy != TLAN_PHY_MAX_ADDR ) ) {
2166 priv->phy[1] = phy;
2171 if ( priv->phy[1] != TLAN_PHY_NONE ) {
2172 priv->phyNum = 1;
2173 } else if ( priv->phy[0] != TLAN_PHY_NONE ) {
2174 priv->phyNum = 0;
2175 } else {
2176 printk( "TLAN: Cannot initialize device, no PHY was found!\n" );
2179 } /* TLan_PhyDetect */
2184 void TLan_PhyPowerDown( struct net_device *dev )
2186 TLanPrivateInfo *priv = (TLanPrivateInfo *) dev->priv;
2187 u16 value;
2189 TLAN_DBG( TLAN_DEBUG_GNRL, "TLAN: %s: Powering down PHY(s).\n", dev->name );
2190 value = MII_GC_PDOWN | MII_GC_LOOPBK | MII_GC_ISOLATE;
2191 TLan_MiiSync( dev->base_addr );
2192 TLan_MiiWriteReg( dev, priv->phy[priv->phyNum], MII_GEN_CTL, value );
2193 if ( ( priv->phyNum == 0 ) && ( priv->phy[1] != TLAN_PHY_NONE ) && ( ! ( priv->adapter->flags & TLAN_ADAPTER_USE_INTERN_10 ) ) ) {
2194 TLan_MiiSync( dev->base_addr );
2195 TLan_MiiWriteReg( dev, priv->phy[1], MII_GEN_CTL, value );
2198 /* Wait for 5 jiffies (50 ms) and powerup
2199 * This is abitrary. It is intended to make sure the
2200 * tranceiver settles.
2202 TLan_SetTimer( dev, 5, TLAN_TIMER_PHY_PUP );
2204 } /* TLan_PhyPowerDown */
2209 void TLan_PhyPowerUp( struct net_device *dev )
2211 TLanPrivateInfo *priv = (TLanPrivateInfo *) dev->priv;
2212 u16 value;
2214 TLAN_DBG( TLAN_DEBUG_GNRL, "TLAN: %s: Powering up PHY.\n", dev->name );
2215 TLan_MiiSync( dev->base_addr );
2216 value = MII_GC_LOOPBK;
2217 TLan_MiiWriteReg( dev, priv->phy[priv->phyNum], MII_GEN_CTL, value );
2219 /* Wait for 50 jiffies (500 ms) and reset the
2220 * tranceiver. The TLAN docs say both 50 ms and
2221 * 500 ms, so do the longer, just in case
2223 TLan_SetTimer( dev, 50, TLAN_TIMER_PHY_RESET );
2225 } /* TLan_PhyPowerUp */
2230 void TLan_PhyReset( struct net_device *dev )
2232 TLanPrivateInfo *priv = (TLanPrivateInfo *) dev->priv;
2233 u16 phy;
2234 u16 value;
2236 phy = priv->phy[priv->phyNum];
2238 TLAN_DBG( TLAN_DEBUG_GNRL, "TLAN: %s: Reseting PHY.\n", dev->name );
2239 TLan_MiiSync( dev->base_addr );
2240 value = MII_GC_LOOPBK | MII_GC_RESET;
2241 TLan_MiiWriteReg( dev, phy, MII_GEN_CTL, value );
2242 TLan_MiiReadReg( dev, phy, MII_GEN_CTL, &value );
2243 while ( value & MII_GC_RESET ) {
2244 TLan_MiiReadReg( dev, phy, MII_GEN_CTL, &value );
2246 TLan_MiiWriteReg( dev, phy, MII_GEN_CTL, 0 );
2248 /* Wait for 50 jiffies (500 ms) and initialize.
2249 * I don't remember why I wait this long.
2251 TLan_SetTimer( dev, 50, TLAN_TIMER_PHY_START_LINK );
2253 } /* TLan_PhyReset */
2258 void TLan_PhyStartLink( struct net_device *dev )
2260 TLanPrivateInfo *priv = (TLanPrivateInfo *) dev->priv;
2261 u16 ability;
2262 u16 control;
2263 u16 data;
2264 u16 phy;
2265 u16 status;
2266 u16 tctl;
2268 phy = priv->phy[priv->phyNum];
2270 TLAN_DBG( TLAN_DEBUG_GNRL, "TLAN: %s: Trying to activate link.\n", dev->name );
2271 TLan_MiiReadReg( dev, phy, MII_GEN_STS, &status );
2272 if ( ( status & MII_GS_AUTONEG ) &&
2273 ( priv->duplex == TLAN_DUPLEX_DEFAULT ) &&
2274 ( priv->speed == TLAN_SPEED_DEFAULT ) &&
2275 ( ! priv->aui ) ) {
2276 ability = status >> 11;
2278 if ( priv->speed == TLAN_SPEED_10 ) {
2279 ability &= 0x0003;
2280 } else if ( priv->speed == TLAN_SPEED_100 ) {
2281 ability &= 0x001C;
2284 if ( priv->duplex == TLAN_DUPLEX_FULL ) {
2285 ability &= 0x000A;
2286 } else if ( priv->duplex == TLAN_DUPLEX_HALF ) {
2287 ability &= 0x0005;
2290 TLan_MiiWriteReg( dev, phy, MII_AN_ADV, ( ability << 5 ) | 1 );
2291 TLan_MiiWriteReg( dev, phy, MII_GEN_CTL, 0x1000 );
2292 TLan_MiiWriteReg( dev, phy, MII_GEN_CTL, 0x1200 );
2294 /* Wait for 400 jiffies (4 sec) for autonegotiation
2295 * to complete. The max spec time is less than this
2296 * but the card need additional time to start AN.
2297 * .5 sec should be plenty extra.
2299 printk( "TLAN: %s: Starting autonegotiation.\n", dev->name );
2300 TLan_SetTimer( dev, 400, TLAN_TIMER_PHY_FINISH_AN );
2301 return;
2304 if ( ( priv->aui ) && ( priv->phyNum != 0 ) ) {
2305 priv->phyNum = 0;
2306 data = TLAN_NET_CFG_1FRAG | TLAN_NET_CFG_1CHAN | TLAN_NET_CFG_PHY_EN;
2307 TLan_DioWrite16( dev->base_addr, TLAN_NET_CONFIG, data );
2308 TLan_SetTimer( dev, 4, TLAN_TIMER_PHY_PDOWN );
2309 return;
2310 } else if ( priv->phyNum == 0 ) {
2311 TLan_MiiReadReg( dev, phy, TLAN_TLPHY_CTL, &tctl );
2312 if ( priv->aui ) {
2313 tctl |= TLAN_TC_AUISEL;
2314 } else {
2315 tctl &= ~TLAN_TC_AUISEL;
2316 control = 0;
2317 if ( priv->duplex == TLAN_DUPLEX_FULL ) {
2318 control |= MII_GC_DUPLEX;
2319 priv->tlanFullDuplex = TRUE;
2321 if ( priv->speed == TLAN_SPEED_100 ) {
2322 control |= MII_GC_SPEEDSEL;
2324 TLan_MiiWriteReg( dev, phy, MII_GEN_CTL, control );
2326 TLan_MiiWriteReg( dev, phy, TLAN_TLPHY_CTL, tctl );
2329 /* Wait for 100 jiffies (1 sec) to give the tranceiver time
2330 * to establish link.
2332 TLan_SetTimer( dev, 100, TLAN_TIMER_FINISH_RESET );
2334 } /* TLan_PhyStartLink */
2339 void TLan_PhyFinishAutoNeg( struct net_device *dev )
2341 TLanPrivateInfo *priv = (TLanPrivateInfo *) dev->priv;
2342 u16 an_adv;
2343 u16 an_lpa;
2344 u16 data;
2345 u16 mode;
2346 u16 phy;
2347 u16 status;
2349 phy = priv->phy[priv->phyNum];
2351 TLan_MiiReadReg( dev, phy, MII_GEN_STS, &status );
2352 if ( ! ( status & MII_GS_AUTOCMPLT ) ) {
2353 /* Wait for 800 jiffies (8 sec) to give the process
2354 * more time. Perhaps we should fail after a while.
2356 printk( "TLAN: Giving autonegotiation more time.\n" );
2357 TLan_SetTimer( dev, 800, TLAN_TIMER_PHY_FINISH_AN );
2358 return;
2361 printk( "TLAN: %s: Autonegotiation complete.\n", dev->name );
2362 TLan_MiiReadReg( dev, phy, MII_AN_ADV, &an_adv );
2363 TLan_MiiReadReg( dev, phy, MII_AN_LPA, &an_lpa );
2364 mode = an_adv & an_lpa & 0x03E0;
2365 if ( mode & 0x0100 ) {
2366 priv->tlanFullDuplex = TRUE;
2367 } else if ( ! ( mode & 0x0080 ) && ( mode & 0x0040 ) ) {
2368 priv->tlanFullDuplex = TRUE;
2371 if ( ( ! ( mode & 0x0180 ) ) && ( priv->adapter->flags & TLAN_ADAPTER_USE_INTERN_10 ) && ( priv->phyNum != 0 ) ) {
2372 priv->phyNum = 0;
2373 data = TLAN_NET_CFG_1FRAG | TLAN_NET_CFG_1CHAN | TLAN_NET_CFG_PHY_EN;
2374 TLan_DioWrite16( dev->base_addr, TLAN_NET_CONFIG, data );
2375 TLan_SetTimer( dev, 40, TLAN_TIMER_PHY_PDOWN );
2376 return;
2379 if ( priv->phyNum == 0 ) {
2380 if ( ( priv->duplex == TLAN_DUPLEX_FULL ) || ( an_adv & an_lpa & 0x0040 ) ) {
2381 TLan_MiiWriteReg( dev, phy, MII_GEN_CTL, MII_GC_AUTOENB | MII_GC_DUPLEX );
2382 printk( "TLAN: Starting internal PHY with DUPLEX\n" );
2383 } else {
2384 TLan_MiiWriteReg( dev, phy, MII_GEN_CTL, MII_GC_AUTOENB );
2385 printk( "TLAN: Starting internal PHY with HALF-DUPLEX\n" );
2389 /* Wait for 10 jiffies (100 ms). No reason in partiticular.
2391 TLan_SetTimer( dev, 10, TLAN_TIMER_FINISH_RESET );
2393 } /* TLan_PhyFinishAutoNeg */
2398 /*****************************************************************************
2399 ******************************************************************************
2401 ThunderLAN Driver MII Routines
2403 These routines are based on the information in Chap. 2 of the
2404 "ThunderLAN Programmer's Guide", pp. 15-24.
2406 ******************************************************************************
2407 *****************************************************************************/
2410 /***************************************************************
2411 * TLan_MiiReadReg
2413 * Returns:
2414 * 0 if ack received ok
2415 * 1 otherwise.
2417 * Parms:
2418 * dev The device structure containing
2419 * The io address and interrupt count
2420 * for this device.
2421 * phy The address of the PHY to be queried.
2422 * reg The register whose contents are to be
2423 * retreived.
2424 * val A pointer to a variable to store the
2425 * retrieved value.
2427 * This function uses the TLAN's MII bus to retreive the contents
2428 * of a given register on a PHY. It sends the appropriate info
2429 * and then reads the 16-bit register value from the MII bus via
2430 * the TLAN SIO register.
2432 **************************************************************/
2434 int TLan_MiiReadReg( struct net_device *dev, u16 phy, u16 reg, u16 *val )
2436 u8 nack;
2437 u16 sio, tmp;
2438 u32 i;
2439 int err;
2440 int minten;
2442 err = FALSE;
2443 outw(TLAN_NET_SIO, dev->base_addr + TLAN_DIO_ADR);
2444 sio = dev->base_addr + TLAN_DIO_DATA + TLAN_NET_SIO;
2446 if ( dev->interrupt == 0 )
2447 cli();
2448 dev->interrupt++;
2450 TLan_MiiSync(dev->base_addr);
2452 minten = TLan_GetBit( TLAN_NET_SIO_MINTEN, sio );
2453 if ( minten )
2454 TLan_ClearBit(TLAN_NET_SIO_MINTEN, sio);
2456 TLan_MiiSendData( dev->base_addr, 0x1, 2 ); /* Start ( 01b ) */
2457 TLan_MiiSendData( dev->base_addr, 0x2, 2 ); /* Read ( 10b ) */
2458 TLan_MiiSendData( dev->base_addr, phy, 5 ); /* Device # */
2459 TLan_MiiSendData( dev->base_addr, reg, 5 ); /* Register # */
2462 TLan_ClearBit(TLAN_NET_SIO_MTXEN, sio); /* Change direction */
2464 TLan_ClearBit(TLAN_NET_SIO_MCLK, sio); /* Clock Idle bit */
2465 TLan_SetBit(TLAN_NET_SIO_MCLK, sio);
2466 TLan_ClearBit(TLAN_NET_SIO_MCLK, sio); /* Wait 300ns */
2468 nack = TLan_GetBit(TLAN_NET_SIO_MDATA, sio); /* Check for ACK */
2469 TLan_SetBit(TLAN_NET_SIO_MCLK, sio); /* Finish ACK */
2470 if (nack) { /* No ACK, so fake it */
2471 for (i = 0; i < 16; i++) {
2472 TLan_ClearBit(TLAN_NET_SIO_MCLK, sio);
2473 TLan_SetBit(TLAN_NET_SIO_MCLK, sio);
2475 tmp = 0xffff;
2476 err = TRUE;
2477 } else { /* ACK, so read data */
2478 for (tmp = 0, i = 0x8000; i; i >>= 1) {
2479 TLan_ClearBit(TLAN_NET_SIO_MCLK, sio);
2480 if (TLan_GetBit(TLAN_NET_SIO_MDATA, sio))
2481 tmp |= i;
2482 TLan_SetBit(TLAN_NET_SIO_MCLK, sio);
2487 TLan_ClearBit(TLAN_NET_SIO_MCLK, sio); /* Idle cycle */
2488 TLan_SetBit(TLAN_NET_SIO_MCLK, sio);
2490 if ( minten )
2491 TLan_SetBit(TLAN_NET_SIO_MINTEN, sio);
2493 *val = tmp;
2495 dev->interrupt--;
2496 if ( dev->interrupt == 0 )
2497 sti();
2499 return err;
2501 } /* TLan_MiiReadReg */
2506 /***************************************************************
2507 * TLan_MiiSendData
2509 * Returns:
2510 * Nothing
2511 * Parms:
2512 * base_port The base IO port of the adapter in
2513 * question.
2514 * dev The address of the PHY to be queried.
2515 * data The value to be placed on the MII bus.
2516 * num_bits The number of bits in data that are to
2517 * be placed on the MII bus.
2519 * This function sends on sequence of bits on the MII
2520 * configuration bus.
2522 **************************************************************/
2524 void TLan_MiiSendData( u16 base_port, u32 data, unsigned num_bits )
2526 u16 sio;
2527 u32 i;
2529 if ( num_bits == 0 )
2530 return;
2532 outw( TLAN_NET_SIO, base_port + TLAN_DIO_ADR );
2533 sio = base_port + TLAN_DIO_DATA + TLAN_NET_SIO;
2534 TLan_SetBit( TLAN_NET_SIO_MTXEN, sio );
2536 for ( i = ( 0x1 << ( num_bits - 1 ) ); i; i >>= 1 ) {
2537 TLan_ClearBit( TLAN_NET_SIO_MCLK, sio );
2538 (void) TLan_GetBit( TLAN_NET_SIO_MCLK, sio );
2539 if ( data & i )
2540 TLan_SetBit( TLAN_NET_SIO_MDATA, sio );
2541 else
2542 TLan_ClearBit( TLAN_NET_SIO_MDATA, sio );
2543 TLan_SetBit( TLAN_NET_SIO_MCLK, sio );
2544 (void) TLan_GetBit( TLAN_NET_SIO_MCLK, sio );
2547 } /* TLan_MiiSendData */
2552 /***************************************************************
2553 * TLan_MiiSync
2555 * Returns:
2556 * Nothing
2557 * Parms:
2558 * base_port The base IO port of the adapter in
2559 * question.
2561 * This functions syncs all PHYs in terms of the MII configuration
2562 * bus.
2564 **************************************************************/
2566 void TLan_MiiSync( u16 base_port )
2568 int i;
2569 u16 sio;
2571 outw( TLAN_NET_SIO, base_port + TLAN_DIO_ADR );
2572 sio = base_port + TLAN_DIO_DATA + TLAN_NET_SIO;
2574 TLan_ClearBit( TLAN_NET_SIO_MTXEN, sio );
2575 for ( i = 0; i < 32; i++ ) {
2576 TLan_ClearBit( TLAN_NET_SIO_MCLK, sio );
2577 TLan_SetBit( TLAN_NET_SIO_MCLK, sio );
2580 } /* TLan_MiiSync */
2585 /***************************************************************
2586 * TLan_MiiWriteReg
2588 * Returns:
2589 * Nothing
2590 * Parms:
2591 * dev The device structure for the device
2592 * to write to.
2593 * phy The address of the PHY to be written to.
2594 * reg The register whose contents are to be
2595 * written.
2596 * val The value to be written to the register.
2598 * This function uses the TLAN's MII bus to write the contents of a
2599 * given register on a PHY. It sends the appropriate info and then
2600 * writes the 16-bit register value from the MII configuration bus
2601 * via the TLAN SIO register.
2603 **************************************************************/
2605 void TLan_MiiWriteReg( struct net_device *dev, u16 phy, u16 reg, u16 val )
2607 u16 sio;
2608 int minten;
2610 outw(TLAN_NET_SIO, dev->base_addr + TLAN_DIO_ADR);
2611 sio = dev->base_addr + TLAN_DIO_DATA + TLAN_NET_SIO;
2613 if ( dev->interrupt == 0 )
2614 cli();
2615 dev->interrupt++;
2617 TLan_MiiSync( dev->base_addr );
2619 minten = TLan_GetBit( TLAN_NET_SIO_MINTEN, sio );
2620 if ( minten )
2621 TLan_ClearBit( TLAN_NET_SIO_MINTEN, sio );
2623 TLan_MiiSendData( dev->base_addr, 0x1, 2 ); /* Start ( 01b ) */
2624 TLan_MiiSendData( dev->base_addr, 0x1, 2 ); /* Write ( 01b ) */
2625 TLan_MiiSendData( dev->base_addr, phy, 5 ); /* Device # */
2626 TLan_MiiSendData( dev->base_addr, reg, 5 ); /* Register # */
2628 TLan_MiiSendData( dev->base_addr, 0x2, 2 ); /* Send ACK */
2629 TLan_MiiSendData( dev->base_addr, val, 16 ); /* Send Data */
2631 TLan_ClearBit( TLAN_NET_SIO_MCLK, sio ); /* Idle cycle */
2632 TLan_SetBit( TLAN_NET_SIO_MCLK, sio );
2634 if ( minten )
2635 TLan_SetBit( TLAN_NET_SIO_MINTEN, sio );
2637 dev->interrupt--;
2638 if ( dev->interrupt == 0 )
2639 sti();
2641 } /* TLan_MiiWriteReg */
2646 /*****************************************************************************
2647 ******************************************************************************
2649 ThunderLAN Driver Eeprom routines
2651 The Compaq Netelligent 10 and 10/100 cards use a Microchip 24C02A
2652 EEPROM. These functions are based on information in Microchip's
2653 data sheet. I don't know how well this functions will work with
2654 other EEPROMs.
2656 ******************************************************************************
2657 *****************************************************************************/
2660 /***************************************************************
2661 * TLan_EeSendStart
2663 * Returns:
2664 * Nothing
2665 * Parms:
2666 * io_base The IO port base address for the
2667 * TLAN device with the EEPROM to
2668 * use.
2670 * This function sends a start cycle to an EEPROM attached
2671 * to a TLAN chip.
2673 **************************************************************/
2675 void TLan_EeSendStart( u16 io_base )
2677 u16 sio;
2679 outw( TLAN_NET_SIO, io_base + TLAN_DIO_ADR );
2680 sio = io_base + TLAN_DIO_DATA + TLAN_NET_SIO;
2682 TLan_SetBit( TLAN_NET_SIO_ECLOK, sio );
2683 TLan_SetBit( TLAN_NET_SIO_EDATA, sio );
2684 TLan_SetBit( TLAN_NET_SIO_ETXEN, sio );
2685 TLan_ClearBit( TLAN_NET_SIO_EDATA, sio );
2686 TLan_ClearBit( TLAN_NET_SIO_ECLOK, sio );
2688 } /* TLan_EeSendStart */
2693 /***************************************************************
2694 * TLan_EeSendByte
2696 * Returns:
2697 * If the correct ack was received, 0, otherwise 1
2698 * Parms: io_base The IO port base address for the
2699 * TLAN device with the EEPROM to
2700 * use.
2701 * data The 8 bits of information to
2702 * send to the EEPROM.
2703 * stop If TLAN_EEPROM_STOP is passed, a
2704 * stop cycle is sent after the
2705 * byte is sent after the ack is
2706 * read.
2708 * This function sends a byte on the serial EEPROM line,
2709 * driving the clock to send each bit. The function then
2710 * reverses transmission direction and reads an acknowledge
2711 * bit.
2713 **************************************************************/
2715 int TLan_EeSendByte( u16 io_base, u8 data, int stop )
2717 int err;
2718 u8 place;
2719 u16 sio;
2721 outw( TLAN_NET_SIO, io_base + TLAN_DIO_ADR );
2722 sio = io_base + TLAN_DIO_DATA + TLAN_NET_SIO;
2724 /* Assume clock is low, tx is enabled; */
2725 for ( place = 0x80; place != 0; place >>= 1 ) {
2726 if ( place & data )
2727 TLan_SetBit( TLAN_NET_SIO_EDATA, sio );
2728 else
2729 TLan_ClearBit( TLAN_NET_SIO_EDATA, sio );
2730 TLan_SetBit( TLAN_NET_SIO_ECLOK, sio );
2731 TLan_ClearBit( TLAN_NET_SIO_ECLOK, sio );
2733 TLan_ClearBit( TLAN_NET_SIO_ETXEN, sio );
2734 TLan_SetBit( TLAN_NET_SIO_ECLOK, sio );
2735 err = TLan_GetBit( TLAN_NET_SIO_EDATA, sio );
2736 TLan_ClearBit( TLAN_NET_SIO_ECLOK, sio );
2737 TLan_SetBit( TLAN_NET_SIO_ETXEN, sio );
2739 if ( ( ! err ) && stop ) {
2740 TLan_ClearBit( TLAN_NET_SIO_EDATA, sio ); /* STOP, raise data while clock is high */
2741 TLan_SetBit( TLAN_NET_SIO_ECLOK, sio );
2742 TLan_SetBit( TLAN_NET_SIO_EDATA, sio );
2745 return ( err );
2747 } /* TLan_EeSendByte */
2752 /***************************************************************
2753 * TLan_EeReceiveByte
2755 * Returns:
2756 * Nothing
2757 * Parms:
2758 * io_base The IO port base address for the
2759 * TLAN device with the EEPROM to
2760 * use.
2761 * data An address to a char to hold the
2762 * data sent from the EEPROM.
2763 * stop If TLAN_EEPROM_STOP is passed, a
2764 * stop cycle is sent after the
2765 * byte is received, and no ack is
2766 * sent.
2768 * This function receives 8 bits of data from the EEPROM
2769 * over the serial link. It then sends and ack bit, or no
2770 * ack and a stop bit. This function is used to retrieve
2771 * data after the address of a byte in the EEPROM has been
2772 * sent.
2774 **************************************************************/
2776 void TLan_EeReceiveByte( u16 io_base, u8 *data, int stop )
2778 u8 place;
2779 u16 sio;
2781 outw( TLAN_NET_SIO, io_base + TLAN_DIO_ADR );
2782 sio = io_base + TLAN_DIO_DATA + TLAN_NET_SIO;
2783 *data = 0;
2785 /* Assume clock is low, tx is enabled; */
2786 TLan_ClearBit( TLAN_NET_SIO_ETXEN, sio );
2787 for ( place = 0x80; place; place >>= 1 ) {
2788 TLan_SetBit( TLAN_NET_SIO_ECLOK, sio );
2789 if ( TLan_GetBit( TLAN_NET_SIO_EDATA, sio ) )
2790 *data |= place;
2791 TLan_ClearBit( TLAN_NET_SIO_ECLOK, sio );
2794 TLan_SetBit( TLAN_NET_SIO_ETXEN, sio );
2795 if ( ! stop ) {
2796 TLan_ClearBit( TLAN_NET_SIO_EDATA, sio ); /* Ack = 0 */
2797 TLan_SetBit( TLAN_NET_SIO_ECLOK, sio );
2798 TLan_ClearBit( TLAN_NET_SIO_ECLOK, sio );
2799 } else {
2800 TLan_SetBit( TLAN_NET_SIO_EDATA, sio ); /* No ack = 1 (?) */
2801 TLan_SetBit( TLAN_NET_SIO_ECLOK, sio );
2802 TLan_ClearBit( TLAN_NET_SIO_ECLOK, sio );
2803 TLan_ClearBit( TLAN_NET_SIO_EDATA, sio ); /* STOP, raise data while clock is high */
2804 TLan_SetBit( TLAN_NET_SIO_ECLOK, sio );
2805 TLan_SetBit( TLAN_NET_SIO_EDATA, sio );
2808 } /* TLan_EeReceiveByte */
2813 /***************************************************************
2814 * TLan_EeReadByte
2816 * Returns:
2817 * No error = 0, else, the stage at which the error
2818 * occurred.
2819 * Parms:
2820 * io_base The IO port base address for the
2821 * TLAN device with the EEPROM to
2822 * use.
2823 * ee_addr The address of the byte in the
2824 * EEPROM whose contents are to be
2825 * retrieved.
2826 * data An address to a char to hold the
2827 * data obtained from the EEPROM.
2829 * This function reads a byte of information from an byte
2830 * cell in the EEPROM.
2832 **************************************************************/
2834 int TLan_EeReadByte( struct net_device *dev, u8 ee_addr, u8 *data )
2836 int err;
2838 if ( dev->interrupt == 0 )
2839 cli();
2840 dev->interrupt++;
2842 TLan_EeSendStart( dev->base_addr );
2843 err = TLan_EeSendByte( dev->base_addr, 0xA0, TLAN_EEPROM_ACK );
2844 if (err)
2845 return 1;
2846 err = TLan_EeSendByte( dev->base_addr, ee_addr, TLAN_EEPROM_ACK );
2847 if (err)
2848 return 2;
2849 TLan_EeSendStart( dev->base_addr );
2850 err = TLan_EeSendByte( dev->base_addr, 0xA1, TLAN_EEPROM_ACK );
2851 if (err)
2852 return 3;
2853 TLan_EeReceiveByte( dev->base_addr, data, TLAN_EEPROM_STOP );
2855 dev->interrupt--;
2856 if ( dev->interrupt == 0 )
2857 sti();
2859 return 0;
2861 } /* TLan_EeReadByte */