iPXE
tlan.c
Go to the documentation of this file.
1/**************************************************************************
2*
3* tlan.c -- Etherboot device driver for the Texas Instruments ThunderLAN
4* Written 2003-2003 by Timothy Legge <tlegge@rogers.com>
5*
6* This program is free software; you can redistribute it and/or modify
7* it under the terms of the GNU General Public License as published by
8* the Free Software Foundation; either version 2 of the License, or
9* (at your option) any later version.
10*
11* This program is distributed in the hope that it will be useful,
12* but WITHOUT ANY WARRANTY; without even the implied warranty of
13* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14* GNU General Public License for more details.
15*
16* You should have received a copy of the GNU General Public License
17* along with this program; if not, write to the Free Software
18* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
19* 02110-1301, USA.
20*
21* Portions of this code based on:
22* lan.c: Linux ThunderLan Driver:
23*
24* by James Banks
25*
26* (C) 1997-1998 Caldera, Inc.
27* (C) 1998 James Banks
28* (C) 1999-2001 Torben Mathiasen
29* (C) 2002 Samuel Chessman
30*
31* REVISION HISTORY:
32* ================
33* v1.0 07-08-2003 timlegge Initial not quite working version
34* v1.1 07-27-2003 timlegge Sync 5.0 and 5.1 versions
35* v1.2 08-19-2003 timlegge Implement Multicast Support
36* v1.3 08-23-2003 timlegge Fix the transmit Function
37* v1.4 01-17-2004 timlegge Initial driver output cleanup
38*
39* Indent Options: indent -kr -i8
40***************************************************************************/
41
42FILE_LICENCE ( GPL2_OR_LATER );
43
44#include "etherboot.h"
45#include "nic.h"
46#include <ipxe/pci.h>
47#include <ipxe/ethernet.h>
48#include <mii.h>
49#include "tlan.h"
50
51#define drv_version "v1.4"
52#define drv_date "01-17-2004"
53
54/* NIC specific static variables go here */
55#define HZ 100
56#define TX_TIME_OUT (6*HZ)
57
58/* Condensed operations for readability. */
59#define virt_to_le32desc(addr) cpu_to_le32(virt_to_bus(addr))
60#define le32desc_to_virt(addr) bus_to_virt(le32_to_cpu(addr))
61
62static void TLan_ResetLists(struct nic *nic __unused);
63static void TLan_ResetAdapter(struct nic *nic __unused);
64static void TLan_FinishReset(struct nic *nic __unused);
65
66static void TLan_EeSendStart(u16);
67static int TLan_EeSendByte(u16, u8, int);
68static void TLan_EeReceiveByte(u16, u8 *, int);
69static int TLan_EeReadByte(u16 io_base, u8, u8 *);
70
71static void TLan_PhyDetect(struct nic *nic);
72static void TLan_PhyPowerDown(struct nic *nic);
73static void TLan_PhyPowerUp(struct nic *nic);
74
75
76static void TLan_SetMac(struct nic *nic __unused, int areg, unsigned char *mac);
77
78static void TLan_PhyReset(struct nic *nic);
79static void TLan_PhyStartLink(struct nic *nic);
80static void TLan_PhyFinishAutoNeg(struct nic *nic);
81
82#ifdef MONITOR
83static void TLan_PhyMonitor(struct nic *nic);
84#endif
85
86
87static void refill_rx(struct nic *nic __unused);
88
89static int TLan_MiiReadReg(struct nic *nic __unused, u16, u16, u16 *);
90static void TLan_MiiSendData(u16, u32, unsigned);
91static void TLan_MiiSync(u16);
92static void TLan_MiiWriteReg(struct nic *nic __unused, u16, u16, u16);
93
94
95static const char *media[] = {
96 "10BaseT-HD ", "10BaseT-FD ", "100baseTx-HD ",
97 "100baseTx-FD", "100baseT4", NULL
98};
99
100/* This much match tlan_pci_tbl[]! */
108
110 const char *name;
117 u16 addrOfs; /* Address Offset */
118};
119
120static const struct pci_id_info tlan_pci_tbl[] = {
121 {"Compaq Netelligent 10 T PCI UTP", NETEL10,
122 {0xae340e11, 0xffffffff, 0, 0, 0, 0},
124 {"Compaq Netelligent 10/100 TX PCI UTP", NETEL100,
125 {0xae320e11, 0xffffffff, 0, 0, 0, 0},
127 {"Compaq Integrated NetFlex-3/P", NETFLEX3I,
128 {0xae350e11, 0xffffffff, 0, 0, 0, 0},
129 TLAN_ADAPTER_NONE, 0x83},
130 {"Compaq NetFlex-3/P", THUNDER,
131 {0xf1300e11, 0xffffffff, 0, 0, 0, 0},
133 {"Compaq NetFlex-3/P", NETFLEX3B,
134 {0xf1500e11, 0xffffffff, 0, 0, 0, 0},
135 TLAN_ADAPTER_NONE, 0x83},
136 {"Compaq Netelligent Integrated 10/100 TX UTP", NETEL100PI,
137 {0xae430e11, 0xffffffff, 0, 0, 0, 0},
139 {"Compaq Netelligent Dual 10/100 TX PCI UTP", NETEL100D,
140 {0xae400e11, 0xffffffff, 0, 0, 0, 0},
141 TLAN_ADAPTER_NONE, 0x83},
142 {"Compaq Netelligent 10/100 TX Embedded UTP", NETEL100I,
143 {0xb0110e11, 0xffffffff, 0, 0, 0, 0},
144 TLAN_ADAPTER_NONE, 0x83},
145 {"Olicom OC-2183/2185", OC2183,
146 {0x0013108d, 0xffffffff, 0, 0, 0, 0},
148 {"Olicom OC-2325", OC2325,
149 {0x0012108d, 0xffffffff, 0, 0, 0, 0},
151 {"Olicom OC-2326", OC2326,
152 {0x0014108d, 0xffffffff, 0, 0, 0, 0},
154 {"Compaq Netelligent 10/100 TX UTP", NETELLIGENT_10_100_WS_5100,
155 {0xb0300e11, 0xffffffff, 0, 0, 0, 0},
157 {"Compaq Netelligent 10 T/2 PCI UTP/Coax", NETELLIGENT_10_T2,
158 {0xb0120e11, 0xffffffff, 0, 0, 0, 0},
159 TLAN_ADAPTER_NONE, 0x83},
160 {"Compaq NetFlex-3/E", 0, /* EISA card */
161 {0, 0, 0, 0, 0, 0},
164 {"Compaq NetFlex-3/E", 0, /* EISA card */
165 {0, 0, 0, 0, 0, 0},
167 {NULL, 0,
168 {0, 0, 0, 0, 0, 0},
169 0, 0},
170};
171
181
188#define tlan_buffers NIC_FAKE_BSS ( struct tlan_bss )
189#define tx_ring tlan_buffers.tx_ring
190#define txb tlan_buffers.txb
191#define rx_ring tlan_buffers.rx_ring
192#define rxb tlan_buffers.rxb
193
195
196static int chip_idx;
197
198/*****************************************************************
199* TLAN Private Information Structure
200*
201****************************************************************/
202static struct tlan_private {
203 unsigned short vendor_id; /* PCI Vendor code */
204 unsigned short dev_id; /* PCI Device code */
205 const char *nic_name;
206 unsigned int cur_rx, dirty_rx; /* Producer/consumer ring indices */
207 unsigned rx_buf_sz; /* Based on mtu + Slack */
212 int eoc;
224
225static struct tlan_private *priv;
226
227static u32 BASE;
228
229/***************************************************************
230* TLan_ResetLists
231*
232* Returns:
233* Nothing
234* Parms:
235* dev The device structure with the list
236* stuctures to be reset.
237*
238* This routine sets the variables associated with managing
239* the TLAN lists to their initial values.
240*
241**************************************************************/
242
243static void TLan_ResetLists(struct nic *nic __unused)
244{
245
246 int i;
247 struct TLanList *list;
248 priv->txHead = 0;
249 priv->txTail = 0;
250
251 for (i = 0; i < TLAN_NUM_TX_LISTS; i++) {
252 list = &tx_ring[i];
253 list->cStat = TLAN_CSTAT_UNUSED;
254 list->buffer[0].address = virt_to_bus(txb +
255 (i * TLAN_MAX_FRAME_SIZE));
256 list->buffer[2].count = 0;
257 list->buffer[2].address = 0;
258 list->buffer[9].address = 0;
259 }
260
261 priv->cur_rx = 0;
262 priv->rx_buf_sz = (TLAN_MAX_FRAME_SIZE);
263// priv->rx_head_desc = &rx_ring[0];
264
265 /* Initialize all the Rx descriptors */
266 for (i = 0; i < TLAN_NUM_RX_LISTS; i++) {
267 rx_ring[i].forward = virt_to_le32desc(&rx_ring[i + 1]);
268 rx_ring[i].cStat = TLAN_CSTAT_READY;
269 rx_ring[i].frameSize = TLAN_MAX_FRAME_SIZE;
270 rx_ring[i].buffer[0].count =
272 rx_ring[i].buffer[0].address =
274 rx_ring[i].buffer[1].count = 0;
275 rx_ring[i].buffer[1].address = 0;
276 }
277
278 /* Mark the last entry as wrapping the ring */
279 rx_ring[i - 1].forward = virt_to_le32desc(&rx_ring[0]);
280 priv->dirty_rx = (unsigned int) (i - TLAN_NUM_RX_LISTS);
281
282} /* TLan_ResetLists */
283
284/***************************************************************
285* TLan_Reset
286*
287* Returns:
288* 0
289* Parms:
290* dev Pointer to device structure of adapter
291* to be reset.
292*
293* This function resets the adapter and it's physical
294* device. See Chap. 3, pp. 9-10 of the "ThunderLAN
295* Programmer's Guide" for details. The routine tries to
296* implement what is detailed there, though adjustments
297* have been made.
298*
299**************************************************************/
300
302{
303 int i;
304 u32 addr;
305 u32 data;
306 u8 data8;
307
308 priv->tlanFullDuplex = FALSE;
309 priv->phyOnline = 0;
310/* 1. Assert reset bit. */
311
315
316 udelay(1000);
317
318/* 2. Turn off interrupts. ( Probably isn't necessary ) */
319
323/* 3. Clear AREGs and HASHs. */
324
325 for (i = TLAN_AREG_0; i <= TLAN_HASH_2; i += 4) {
326 TLan_DioWrite32(BASE, (u16) i, 0);
327 }
328
329/* 4. Setup NetConfig register. */
330
331 data =
334
335/* 5. Load Ld_Tmr and Ld_Thr in HOST_CMD. */
336
339
340/* 6. Unreset the MII by setting NMRST (in NetSio) to 1. */
341
345
346/* 7. Setup the remaining registers. */
347
348 if (priv->tlanRev >= 0x30) {
351 }
354
357 if (priv->aui == 1) {
359 } else if (priv->duplex == TLAN_DUPLEX_FULL) {
361 priv->tlanFullDuplex = TRUE;
362 } else {
364 }
365 }
366
367 if (priv->phyNum == 0) {
369 }
371
374 } else {
376 }
377
378} /* TLan_ResetAdapter */
379
381{
382
383 u8 data;
384 u32 phy;
385 u8 sio;
386 u16 status;
387 u16 partner;
388 u16 tlphy_ctl;
389 u16 tlphy_par;
390 u16 tlphy_id1, tlphy_id2;
391 int i;
392
393 phy = priv->phy[priv->phyNum];
394
396 if (priv->tlanFullDuplex) {
398 }
401 if (priv->phyNum == 0) {
403 }
405 TLan_DioWrite16(BASE, TLAN_MAX_RX, ((1536) + 7) & ~7);
406 TLan_MiiReadReg(nic, phy, MII_PHYSID1, &tlphy_id1);
407 TLan_MiiReadReg(nic, phy, MII_PHYSID2, &tlphy_id2);
408
410 || (priv->aui)) {
412 DBG ( "TLAN: %s: Link forced.\n", priv->nic_name );
413 } else {
415 udelay(1000);
417 if ((status & BMSR_LSTATUS) && /* We only support link info on Nat.Sem. PHY's */
418 (tlphy_id1 == NAT_SEM_ID1)
419 && (tlphy_id2 == NAT_SEM_ID2)) {
422 &tlphy_par);
423
424 DBG ( "TLAN: %s: Link active with ",
425 priv->nic_name );
426 if (!(tlphy_par & TLAN_PHY_AN_EN_STAT)) {
427 DBG ( "forced 10%sMbps %s-Duplex\n",
428 tlphy_par & TLAN_PHY_SPEED_100 ? ""
429 : "0",
430 tlphy_par & TLAN_PHY_DUPLEX_FULL ?
431 "Full" : "Half" );
432 } else {
433 DBG
434 ( "AutoNegotiation enabled, at 10%sMbps %s-Duplex\n",
435 tlphy_par & TLAN_PHY_SPEED_100 ? "" :
436 "0",
437 tlphy_par & TLAN_PHY_DUPLEX_FULL ?
438 "Full" : "Half" );
439 DBG ( "TLAN: Partner capability: " );
440 for (i = 5; i <= 10; i++)
441 if (partner & (1 << i)) {
442 DBG ( "%s", media[i - 5] );
443 }
444 DBG ( "\n" );
445 }
446
448#ifdef MONITOR
449 /* We have link beat..for now anyway */
450 priv->link = 1;
451 /*Enabling link beat monitoring */
452 /* TLan_SetTimer( nic, (10*HZ), TLAN_TIMER_LINK_BEAT ); */
453 mdelay(10000);
454 TLan_PhyMonitor(nic);
455#endif
456 } else if (status & BMSR_LSTATUS) {
457 DBG ( "TLAN: %s: Link active\n", priv->nic_name );
459 }
460 }
461
462 if (priv->phyNum == 0) {
463 TLan_MiiReadReg(nic, phy, TLAN_TLPHY_CTL, &tlphy_ctl);
464 tlphy_ctl |= TLAN_TC_INTEN;
465 TLan_MiiWriteReg(nic, phy, TLAN_TLPHY_CTL, tlphy_ctl);
467 sio |= TLAN_NET_SIO_MINTEN;
469 }
470
471 if (status & BMSR_LSTATUS) {
473 priv->phyOnline = 1;
474 outb((TLAN_HC_INT_ON >> 8), BASE + TLAN_HOST_CMD + 1);
477 } else {
478 DBG
479 ( "TLAN: %s: Link inactive, will retry in 10 secs...\n",
480 priv->nic_name );
481 /* TLan_SetTimer( nic, (10*HZ), TLAN_TIMER_FINISH_RESET ); */
482 mdelay(10000);
484 return;
485
486 }
487
488} /* TLan_FinishReset */
489
490/**************************************************************************
491POLL - Wait for a frame
492***************************************************************************/
493static int tlan_poll(struct nic *nic, int retrieve)
494{
495 /* return true if there's an ethernet packet ready to read */
496 /* nic->packet should contain data on return */
497 /* nic->packetlen should contain length of data */
498 u32 framesize;
499 u32 host_cmd = 0;
500 u32 ack = 1;
501 int eoc = 0;
502 int entry = priv->cur_rx % TLAN_NUM_RX_LISTS;
503 u16 tmpCStat = le32_to_cpu(rx_ring[entry].cStat);
504 u16 host_int = inw(BASE + TLAN_HOST_INT);
505
506 if ((tmpCStat & TLAN_CSTAT_FRM_CMP) && !retrieve)
507 return 1;
508
509 outw(host_int, BASE + TLAN_HOST_INT);
510
511 if (!(tmpCStat & TLAN_CSTAT_FRM_CMP))
512 return 0;
513
514 /* printf("PI-1: 0x%hX\n", host_int); */
515 if (tmpCStat & TLAN_CSTAT_EOC)
516 eoc = 1;
517
518 framesize = rx_ring[entry].frameSize;
519
520 nic->packetlen = framesize;
521
522 DBG ( ".%d.", (unsigned int) framesize );
523
524 memcpy(nic->packet, rxb +
525 (priv->cur_rx * TLAN_MAX_FRAME_SIZE), nic->packetlen);
526
527 rx_ring[entry].cStat = 0;
528
529 DBG ( "%d", entry );
530
531 entry = (entry + 1) % TLAN_NUM_RX_LISTS;
532 priv->cur_rx = entry;
533 if (eoc) {
534 if ((rx_ring[entry].cStat & TLAN_CSTAT_READY) ==
536 ack |= TLAN_HC_GO | TLAN_HC_RT;
537 host_cmd = TLAN_HC_ACK | ack | 0x001C0000;
538 outl(host_cmd, BASE + TLAN_HOST_CMD);
539 }
540 } else {
541 host_cmd = TLAN_HC_ACK | ack | (0x000C0000);
542 outl(host_cmd, BASE + TLAN_HOST_CMD);
543
544 DBG ( "AC: 0x%hX\n", inw(BASE + TLAN_CH_PARM) );
545 DBG ( "PI-2: 0x%hX\n", inw(BASE + TLAN_HOST_INT) );
546 }
547 refill_rx(nic);
548 return (1); /* initially as this is called to flush the input */
549}
550
551static void refill_rx(struct nic *nic __unused)
552{
553 int entry = 0;
554
555 for (;
556 (priv->cur_rx - priv->dirty_rx +
558 priv->dirty_rx = (priv->dirty_rx + 1) % TLAN_NUM_RX_LISTS) {
559 entry = priv->dirty_rx % TLAN_NUM_TX_LISTS;
560 rx_ring[entry].frameSize = TLAN_MAX_FRAME_SIZE;
561 rx_ring[entry].cStat = TLAN_CSTAT_READY;
562 }
563
564}
565
566/**************************************************************************
567TRANSMIT - Transmit a frame
568***************************************************************************/
569static void tlan_transmit(struct nic *nic, const char *d, /* Destination */
570 unsigned int t, /* Type */
571 unsigned int s, /* size */
572 const char *p)
573{ /* Packet */
574 u16 nstype;
575 u32 to;
576 struct TLanList *tail_list;
577 struct TLanList *head_list;
578 u8 *tail_buffer;
579 u32 ack = 0;
580 u32 host_cmd;
581 int eoc = 0;
582 u16 tmpCStat;
583 u16 host_int = inw(BASE + TLAN_HOST_INT);
584
585 int entry = 0;
586
587 DBG ( "INT0-0x%hX\n", host_int );
588
589 if (!priv->phyOnline) {
590 printf("TRANSMIT: %s PHY is not ready\n", priv->nic_name);
591 return;
592 }
593
594 tail_list = priv->txList + priv->txTail;
595
596 if (tail_list->cStat != TLAN_CSTAT_UNUSED) {
597 printf("TRANSMIT: %s is busy (Head=%p Tail=%x)\n",
598 priv->nic_name, priv->txList, (unsigned int) priv->txTail);
599 tx_ring[entry].cStat = TLAN_CSTAT_UNUSED;
600// priv->txBusyCount++;
601 return;
602 }
603
604 tail_list->forward = 0;
605
606 tail_buffer = txb + (priv->txTail * TLAN_MAX_FRAME_SIZE);
607
608 /* send the packet to destination */
609 memcpy(tail_buffer, d, ETH_ALEN);
610 memcpy(tail_buffer + ETH_ALEN, nic->node_addr, ETH_ALEN);
611 nstype = htons((u16) t);
612 memcpy(tail_buffer + 2 * ETH_ALEN, (u8 *) & nstype, 2);
613 memcpy(tail_buffer + ETH_HLEN, p, s);
614
615 s += ETH_HLEN;
616 s &= 0x0FFF;
617 while (s < ETH_ZLEN)
618 tail_buffer[s++] = '\0';
619
620 /*=====================================================*/
621 /* Receive
622 * 0000 0000 0001 1100
623 * 0000 0000 0000 1100
624 * 0000 0000 0000 0011 = 0x0003
625 *
626 * 0000 0000 0000 0000 0000 0000 0000 0011
627 * 0000 0000 0000 1100 0000 0000 0000 0000 = 0x000C0000
628 *
629 * Transmit
630 * 0000 0000 0001 1100
631 * 0000 0000 0000 0100
632 * 0000 0000 0000 0001 = 0x0001
633 *
634 * 0000 0000 0000 0000 0000 0000 0000 0001
635 * 0000 0000 0000 0100 0000 0000 0000 0000 = 0x00040000
636 * */
637
638 /* Setup the transmit descriptor */
639 tail_list->frameSize = (u16) s;
640 tail_list->buffer[0].count = TLAN_LAST_BUFFER | (u32) s;
641 tail_list->buffer[1].count = 0;
642 tail_list->buffer[1].address = 0;
643
644 tail_list->cStat = TLAN_CSTAT_READY;
645
646 DBG ( "INT1-0x%hX\n", inw(BASE + TLAN_HOST_INT) );
647
648 if (!priv->txInProgress) {
649 priv->txInProgress = 1;
650 outl(virt_to_le32desc(tail_list), BASE + TLAN_CH_PARM);
652 } else {
653 if (priv->txTail == 0) {
654 DBG ( "Out buffer\n" );
655 (priv->txList + (TLAN_NUM_TX_LISTS - 1))->forward =
656 virt_to_le32desc(tail_list);
657 } else {
658 DBG ( "Fix this \n" );
659 (priv->txList + (priv->txTail - 1))->forward =
660 virt_to_le32desc(tail_list);
661 }
662 }
663
665
666 DBG ( "INT2-0x%hX\n", inw(BASE + TLAN_HOST_INT) );
667
668 to = currticks() + TX_TIME_OUT;
669 while ((tail_list->cStat == TLAN_CSTAT_READY) && currticks() < to);
670
671 head_list = priv->txList + priv->txHead;
672 while (((tmpCStat = head_list->cStat) & TLAN_CSTAT_FRM_CMP)
673 && (ack < 255)) {
674 ack++;
675 if(tmpCStat & TLAN_CSTAT_EOC)
676 eoc =1;
677 head_list->cStat = TLAN_CSTAT_UNUSED;
679 head_list = priv->txList + priv->txHead;
680
681 }
682 if(!ack)
683 printf("Incomplete TX Frame\n");
684
685 if(eoc) {
686 head_list = priv->txList + priv->txHead;
687 if ((head_list->cStat & TLAN_CSTAT_READY) == TLAN_CSTAT_READY) {
688 outl(virt_to_le32desc(head_list), BASE + TLAN_CH_PARM);
689 ack |= TLAN_HC_GO;
690 } else {
691 priv->txInProgress = 0;
692 }
693 }
694 if(ack) {
695 host_cmd = TLAN_HC_ACK | ack;
696 outl(host_cmd, BASE + TLAN_HOST_CMD);
697 }
698
699 if(priv->tlanRev < 0x30 ) {
700 ack = 1;
701 head_list = priv->txList + priv->txHead;
702 if ((head_list->cStat & TLAN_CSTAT_READY) == TLAN_CSTAT_READY) {
703 outl(virt_to_le32desc(head_list), BASE + TLAN_CH_PARM);
704 ack |= TLAN_HC_GO;
705 } else {
706 priv->txInProgress = 0;
707 }
708 host_cmd = TLAN_HC_ACK | ack | 0x00140000;
709 outl(host_cmd, BASE + TLAN_HOST_CMD);
710
711 }
712
713 if (currticks() >= to) {
714 printf("TX Time Out");
715 }
716}
717
718/**************************************************************************
719DISABLE - Turn off ethernet interface
720***************************************************************************/
721static void tlan_disable ( struct nic *nic __unused, void *hwdev __unused ) {
722 /* put the card in its initial state */
723 /* This function serves 3 purposes.
724 * This disables DMA and interrupts so we don't receive
725 * unexpected packets or interrupts from the card after
726 * etherboot has finished.
727 * This frees resources so etherboot may use
728 * this driver on another interface
729 * This allows etherboot to reinitialize the interface
730 * if something is something goes wrong.
731 *
732 */
734}
735
736/**************************************************************************
737IRQ - Enable, Disable, or Force interrupts
738***************************************************************************/
739static void tlan_irq(struct nic *nic __unused, irq_action_t action __unused)
740{
741 switch ( action ) {
742 case DISABLE :
743 break;
744 case ENABLE :
745 break;
746 case FORCE :
747 break;
748 }
749}
750
752 .connect = dummy_connect,
753 .poll = tlan_poll,
754 .transmit = tlan_transmit,
755 .irq = tlan_irq,
756
757};
758
759static void TLan_SetMulticastList(struct nic *nic) {
760 int i;
761 u8 tmp;
762
763 /* !IFF_PROMISC */
766
767 /* IFF_ALLMULTI */
768 for(i = 0; i< 3; i++)
769 TLan_SetMac(nic, i + 1, NULL);
770 TLan_DioWrite32(BASE, TLAN_HASH_1, 0xFFFFFFFF);
771 TLan_DioWrite32(BASE, TLAN_HASH_2, 0xFFFFFFFF);
772
773
774}
775/**************************************************************************
776PROBE - Look for an adapter, this routine's visible to the outside
777***************************************************************************/
778
779#define board_found 1
780#define valid_link 0
781static int tlan_probe ( struct nic *nic, struct pci_device *pci ) {
782
783 u16 data = 0;
784 int err;
785 int i;
786
787 if (pci->ioaddr == 0)
788 return 0;
789
790 nic->irqno = 0;
791 nic->ioaddr = pci->ioaddr;
792
793 BASE = pci->ioaddr;
794
795 /* Set nic as PCI bus master */
797
798 /* Point to private storage */
800
801 /* Figure out which chip we're dealing with */
802 i = 0;
803 chip_idx = -1;
804 while (tlan_pci_tbl[i].name) {
805 if ((((u32) pci->device << 16) | pci->vendor) ==
806 (tlan_pci_tbl[i].id.pci & 0xffffffff)) {
807 chip_idx = i;
808 break;
809 }
810 i++;
811 }
812 if (chip_idx == -1)
813 return 0;
814
815 priv->vendor_id = pci->vendor;
816 priv->dev_id = pci->device;
817 priv->nic_name = pci->id->name;
818 priv->eoc = 0;
819
820 err = 0;
821 for (i = 0; i < 6; i++)
822 err |= TLan_EeReadByte(BASE,
824 addrOfs + i,
825 (u8 *) & nic->node_addr[i]);
826 if (err) {
827 printf ( "TLAN: %s: Error reading MAC from eeprom: %d\n",
828 pci->id->name, err);
829 } else {
830 DBG ( "%s: %s at ioaddr %#lX, ",
831 pci->id->name, eth_ntoa ( nic->node_addr ), pci->ioaddr );
832 }
833
835 printf("revision: 0x%hX\n", priv->tlanRev);
836
839
843
845 udelay(100);
846 priv->txList = tx_ring;
847
848/* if (board_found && valid_link)
849 {*/
850 /* point to NIC specific routines */
852 return 1;
853}
854
855
856/*****************************************************************************
857******************************************************************************
858
859 ThunderLAN Driver Eeprom routines
860
861 The Compaq Netelligent 10 and 10/100 cards use a Microchip 24C02A
862 EEPROM. These functions are based on information in Microchip's
863 data sheet. I don't know how well this functions will work with
864 other EEPROMs.
865
866******************************************************************************
867*****************************************************************************/
868
869
870/***************************************************************
871* TLan_EeSendStart
872*
873* Returns:
874* Nothing
875* Parms:
876* io_base The IO port base address for the
877* TLAN device with the EEPROM to
878* use.
879*
880* This function sends a start cycle to an EEPROM attached
881* to a TLAN chip.
882*
883**************************************************************/
884
886{
887 u16 sio;
888
889 outw(TLAN_NET_SIO, io_base + TLAN_DIO_ADR);
890 sio = io_base + TLAN_DIO_DATA + TLAN_NET_SIO;
891
897
898} /* TLan_EeSendStart */
899
900/***************************************************************
901* TLan_EeSendByte
902*
903* Returns:
904* If the correct ack was received, 0, otherwise 1
905* Parms: io_base The IO port base address for the
906* TLAN device with the EEPROM to
907* use.
908* data The 8 bits of information to
909* send to the EEPROM.
910* stop If TLAN_EEPROM_STOP is passed, a
911* stop cycle is sent after the
912* byte is sent after the ack is
913* read.
914*
915* This function sends a byte on the serial EEPROM line,
916* driving the clock to send each bit. The function then
917* reverses transmission direction and reads an acknowledge
918* bit.
919*
920**************************************************************/
921
922int TLan_EeSendByte(u16 io_base, u8 data, int stop)
923{
924 int err;
925 u8 place;
926 u16 sio;
927
928 outw(TLAN_NET_SIO, io_base + TLAN_DIO_ADR);
929 sio = io_base + TLAN_DIO_DATA + TLAN_NET_SIO;
930
931 /* Assume clock is low, tx is enabled; */
932 for (place = 0x80; place != 0; place >>= 1) {
933 if (place & data)
935 else
939 }
945
946 if ((!err) && stop) {
947 TLan_ClearBit(TLAN_NET_SIO_EDATA, sio); /* STOP, raise data while clock is high */
950 }
951
952 return (err);
953
954} /* TLan_EeSendByte */
955
956/***************************************************************
957* TLan_EeReceiveByte
958*
959* Returns:
960* Nothing
961* Parms:
962* io_base The IO port base address for the
963* TLAN device with the EEPROM to
964* use.
965* data An address to a char to hold the
966* data sent from the EEPROM.
967* stop If TLAN_EEPROM_STOP is passed, a
968* stop cycle is sent after the
969* byte is received, and no ack is
970* sent.
971*
972* This function receives 8 bits of data from the EEPROM
973* over the serial link. It then sends and ack bit, or no
974* ack and a stop bit. This function is used to retrieve
975* data after the address of a byte in the EEPROM has been
976* sent.
977*
978**************************************************************/
979
980void TLan_EeReceiveByte(u16 io_base, u8 * data, int stop)
981{
982 u8 place;
983 u16 sio;
984
985 outw(TLAN_NET_SIO, io_base + TLAN_DIO_ADR);
986 sio = io_base + TLAN_DIO_DATA + TLAN_NET_SIO;
987 *data = 0;
988
989 /* Assume clock is low, tx is enabled; */
991 for (place = 0x80; place; place >>= 1) {
994 *data |= place;
996 }
997
999 if (!stop) {
1000 TLan_ClearBit(TLAN_NET_SIO_EDATA, sio); /* Ack = 0 */
1003 } else {
1004 TLan_SetBit(TLAN_NET_SIO_EDATA, sio); /* No ack = 1 (?) */
1007 TLan_ClearBit(TLAN_NET_SIO_EDATA, sio); /* STOP, raise data while clock is high */
1010 }
1011
1012} /* TLan_EeReceiveByte */
1013
1014/***************************************************************
1015* TLan_EeReadByte
1016*
1017* Returns:
1018* No error = 0, else, the stage at which the error
1019* occurred.
1020* Parms:
1021* io_base The IO port base address for the
1022* TLAN device with the EEPROM to
1023* use.
1024* ee_addr The address of the byte in the
1025* EEPROM whose contents are to be
1026* retrieved.
1027* data An address to a char to hold the
1028* data obtained from the EEPROM.
1029*
1030* This function reads a byte of information from an byte
1031* cell in the EEPROM.
1032*
1033**************************************************************/
1034
1035int TLan_EeReadByte(u16 io_base, u8 ee_addr, u8 * data)
1036{
1037 int err;
1038 int ret = 0;
1039
1040
1041 TLan_EeSendStart(io_base);
1042 err = TLan_EeSendByte(io_base, 0xA0, TLAN_EEPROM_ACK);
1043 if (err) {
1044 ret = 1;
1045 goto fail;
1046 }
1047 err = TLan_EeSendByte(io_base, ee_addr, TLAN_EEPROM_ACK);
1048 if (err) {
1049 ret = 2;
1050 goto fail;
1051 }
1052 TLan_EeSendStart(io_base);
1053 err = TLan_EeSendByte(io_base, 0xA1, TLAN_EEPROM_ACK);
1054 if (err) {
1055 ret = 3;
1056 goto fail;
1057 }
1059 fail:
1060
1061 return ret;
1062
1063} /* TLan_EeReadByte */
1064
1065
1066/*****************************************************************************
1067******************************************************************************
1068
1069ThunderLAN Driver MII Routines
1070
1071These routines are based on the information in Chap. 2 of the
1072"ThunderLAN Programmer's Guide", pp. 15-24.
1073
1074******************************************************************************
1075*****************************************************************************/
1076
1077
1078/***************************************************************
1079* TLan_MiiReadReg
1080*
1081* Returns:
1082* 0 if ack received ok
1083* 1 otherwise.
1084*
1085* Parms:
1086* dev The device structure containing
1087* The io address and interrupt count
1088* for this device.
1089* phy The address of the PHY to be queried.
1090* reg The register whose contents are to be
1091* retrieved.
1092* val A pointer to a variable to store the
1093* retrieved value.
1094*
1095* This function uses the TLAN's MII bus to retrieve the contents
1096* of a given register on a PHY. It sends the appropriate info
1097* and then reads the 16-bit register value from the MII bus via
1098* the TLAN SIO register.
1099*
1100**************************************************************/
1101
1103{
1104 u8 nack;
1105 u16 sio, tmp;
1106 u32 i;
1107 int err;
1108 int minten;
1109
1110 err = FALSE;
1113
1115
1116 minten = TLan_GetBit(TLAN_NET_SIO_MINTEN, sio);
1117 if (minten)
1119
1120 TLan_MiiSendData(BASE, 0x1, 2); /* Start ( 01b ) */
1121 TLan_MiiSendData(BASE, 0x2, 2); /* Read ( 10b ) */
1122 TLan_MiiSendData(BASE, phy, 5); /* Device # */
1123 TLan_MiiSendData(BASE, reg, 5); /* Register # */
1124
1125
1126 TLan_ClearBit(TLAN_NET_SIO_MTXEN, sio); /* Change direction */
1127
1128 TLan_ClearBit(TLAN_NET_SIO_MCLK, sio); /* Clock Idle bit */
1130 TLan_ClearBit(TLAN_NET_SIO_MCLK, sio); /* Wait 300ns */
1131
1132 nack = TLan_GetBit(TLAN_NET_SIO_MDATA, sio); /* Check for ACK */
1133 TLan_SetBit(TLAN_NET_SIO_MCLK, sio); /* Finish ACK */
1134 if (nack) { /* No ACK, so fake it */
1135 for (i = 0; i < 16; i++) {
1138 }
1139 tmp = 0xffff;
1140 err = TRUE;
1141 } else { /* ACK, so read data */
1142 for (tmp = 0, i = 0x8000; i; i >>= 1) {
1145 tmp |= i;
1147 }
1148 }
1149
1150
1151 TLan_ClearBit(TLAN_NET_SIO_MCLK, sio); /* Idle cycle */
1153
1154 if (minten)
1156
1157 *val = tmp;
1158
1159 return err;
1160
1161} /* TLan_MiiReadReg */
1162
1163/***************************************************************
1164* TLan_MiiSendData
1165*
1166* Returns:
1167* Nothing
1168* Parms:
1169* base_port The base IO port of the adapter in
1170* question.
1171* dev The address of the PHY to be queried.
1172* data The value to be placed on the MII bus.
1173* num_bits The number of bits in data that are to
1174* be placed on the MII bus.
1175*
1176* This function sends on sequence of bits on the MII
1177* configuration bus.
1178*
1179**************************************************************/
1180
1181void TLan_MiiSendData(u16 base_port, u32 data, unsigned num_bits)
1182{
1183 u16 sio;
1184 u32 i;
1185
1186 if (num_bits == 0)
1187 return;
1188
1189 outw(TLAN_NET_SIO, base_port + TLAN_DIO_ADR);
1190 sio = base_port + TLAN_DIO_DATA + TLAN_NET_SIO;
1192
1193 for (i = (0x1 << (num_bits - 1)); i; i >>= 1) {
1195 (void) TLan_GetBit(TLAN_NET_SIO_MCLK, sio);
1196 if (data & i)
1198 else
1201 (void) TLan_GetBit(TLAN_NET_SIO_MCLK, sio);
1202 }
1203
1204} /* TLan_MiiSendData */
1205
1206/***************************************************************
1207* TLan_MiiSync
1208*
1209* Returns:
1210* Nothing
1211* Parms:
1212* base_port The base IO port of the adapter in
1213* question.
1214*
1215* This functions syncs all PHYs in terms of the MII configuration
1216* bus.
1217*
1218**************************************************************/
1219
1220void TLan_MiiSync(u16 base_port)
1221{
1222 int i;
1223 u16 sio;
1224
1225 outw(TLAN_NET_SIO, base_port + TLAN_DIO_ADR);
1226 sio = base_port + TLAN_DIO_DATA + TLAN_NET_SIO;
1227
1229 for (i = 0; i < 32; i++) {
1232 }
1233
1234} /* TLan_MiiSync */
1235
1236/***************************************************************
1237* TLan_MiiWriteReg
1238*
1239* Returns:
1240* Nothing
1241* Parms:
1242* dev The device structure for the device
1243* to write to.
1244* phy The address of the PHY to be written to.
1245* reg The register whose contents are to be
1246* written.
1247* val The value to be written to the register.
1248*
1249* This function uses the TLAN's MII bus to write the contents of a
1250* given register on a PHY. It sends the appropriate info and then
1251* writes the 16-bit register value from the MII configuration bus
1252* via the TLAN SIO register.
1253*
1254**************************************************************/
1255
1257{
1258 u16 sio;
1259 int minten;
1260
1263
1265
1266 minten = TLan_GetBit(TLAN_NET_SIO_MINTEN, sio);
1267 if (minten)
1269
1270 TLan_MiiSendData(BASE, 0x1, 2); /* Start ( 01b ) */
1271 TLan_MiiSendData(BASE, 0x1, 2); /* Write ( 01b ) */
1272 TLan_MiiSendData(BASE, phy, 5); /* Device # */
1273 TLan_MiiSendData(BASE, reg, 5); /* Register # */
1274
1275 TLan_MiiSendData(BASE, 0x2, 2); /* Send ACK */
1276 TLan_MiiSendData(BASE, val, 16); /* Send Data */
1277
1278 TLan_ClearBit(TLAN_NET_SIO_MCLK, sio); /* Idle cycle */
1280
1281 if (minten)
1283
1284
1285} /* TLan_MiiWriteReg */
1286
1287/***************************************************************
1288* TLan_SetMac
1289*
1290* Returns:
1291* Nothing
1292* Parms:
1293* dev Pointer to device structure of adapter
1294* on which to change the AREG.
1295* areg The AREG to set the address in (0 - 3).
1296* mac A pointer to an array of chars. Each
1297* element stores one byte of the address.
1298* IE, it isn't in ascii.
1299*
1300* This function transfers a MAC address to one of the
1301* TLAN AREGs (address registers). The TLAN chip locks
1302* the register on writing to offset 0 and unlocks the
1303* register after writing to offset 5. If NULL is passed
1304* in mac, then the AREG is filled with 0's.
1305*
1306**************************************************************/
1307
1308void TLan_SetMac(struct nic *nic __unused, int areg, unsigned char *mac)
1309{
1310 int i;
1311
1312 areg *= 6;
1313
1314 if (mac != NULL) {
1315 for (i = 0; i < 6; i++)
1316 TLan_DioWrite8(BASE, TLAN_AREG_0 + areg + i,
1317 mac[i]);
1318 } else {
1319 for (i = 0; i < 6; i++)
1320 TLan_DioWrite8(BASE, TLAN_AREG_0 + areg + i, 0);
1321 }
1322
1323} /* TLan_SetMac */
1324
1325/*********************************************************************
1326* TLan_PhyDetect
1327*
1328* Returns:
1329* Nothing
1330* Parms:
1331* dev A pointer to the device structure of the adapter
1332* for which the PHY needs determined.
1333*
1334* So far I've found that adapters which have external PHYs
1335* may also use the internal PHY for part of the functionality.
1336* (eg, AUI/Thinnet). This function finds out if this TLAN
1337* chip has an internal PHY, and then finds the first external
1338* PHY (starting from address 0) if it exists).
1339*
1340********************************************************************/
1341
1343{
1344 u16 control;
1345 u16 hi;
1346 u16 lo;
1347 u32 phy;
1348
1350 priv->phyNum = 0xFFFF;
1351 return;
1352 }
1353
1355
1356 if (hi != 0xFFFF) {
1357 priv->phy[0] = TLAN_PHY_MAX_ADDR;
1358 } else {
1359 priv->phy[0] = TLAN_PHY_NONE;
1360 }
1361
1362 priv->phy[1] = TLAN_PHY_NONE;
1363 for (phy = 0; phy <= TLAN_PHY_MAX_ADDR; phy++) {
1365 TLan_MiiReadReg(nic, phy, MII_PHYSID1, &hi);
1366 TLan_MiiReadReg(nic, phy, MII_PHYSID2, &lo);
1367 if ((control != 0xFFFF) || (hi != 0xFFFF)
1368 || (lo != 0xFFFF)) {
1369 printf("PHY found at %hX %hX %hX %hX\n",
1370 (unsigned int) phy, control, hi, lo);
1371 if ((priv->phy[1] == TLAN_PHY_NONE)
1372 && (phy != TLAN_PHY_MAX_ADDR)) {
1373 priv->phy[1] = phy;
1374 }
1375 }
1376 }
1377
1378 if (priv->phy[1] != TLAN_PHY_NONE) {
1379 priv->phyNum = 1;
1380 } else if (priv->phy[0] != TLAN_PHY_NONE) {
1381 priv->phyNum = 0;
1382 } else {
1383 printf
1384 ("TLAN: Cannot initialize device, no PHY was found!\n");
1385 }
1386
1387} /* TLan_PhyDetect */
1388
1390{
1391
1392 u16 value;
1393 DBG ( "%s: Powering down PHY(s).\n", priv->nic_name );
1396 TLan_MiiWriteReg(nic, priv->phy[priv->phyNum], MII_BMCR, value);
1397 if ((priv->phyNum == 0) && (priv->phy[1] != TLAN_PHY_NONE)
1398 &&
1403 }
1404
1405 /* Wait for 50 ms and powerup
1406 * This is abitrary. It is intended to make sure the
1407 * tranceiver settles.
1408 */
1409 /* TLan_SetTimer( dev, (HZ/20), TLAN_TIMER_PHY_PUP ); */
1410 mdelay(50);
1412
1413} /* TLan_PhyPowerDown */
1414
1415
1417{
1418 u16 value;
1419
1420 DBG ( "%s: Powering up PHY.\n", priv->nic_name );
1423 TLan_MiiWriteReg(nic, priv->phy[priv->phyNum], MII_BMCR, value);
1425 /* Wait for 500 ms and reset the
1426 * tranceiver. The TLAN docs say both 50 ms and
1427 * 500 ms, so do the longer, just in case.
1428 */
1429 mdelay(500);
1431 /* TLan_SetTimer( dev, (HZ/20), TLAN_TIMER_PHY_RESET ); */
1432
1433} /* TLan_PhyPowerUp */
1434
1435void TLan_PhyReset(struct nic *nic)
1436{
1437 u16 phy;
1438 u16 value;
1439
1440 phy = priv->phy[priv->phyNum];
1441
1442 DBG ( "%s: Reseting PHY.\n", priv->nic_name );
1447 while (value & BMCR_RESET) {
1449 }
1450
1451 /* Wait for 500 ms and initialize.
1452 * I don't remember why I wait this long.
1453 * I've changed this to 50ms, as it seems long enough.
1454 */
1455 /* TLan_SetTimer( dev, (HZ/20), TLAN_TIMER_PHY_START_LINK ); */
1456 mdelay(50);
1458
1459} /* TLan_PhyReset */
1460
1461
1463{
1464
1465 u16 ability;
1466 u16 control;
1467 u16 data;
1468 u16 phy;
1469 u16 status;
1470 u16 tctl;
1471
1472 phy = priv->phy[priv->phyNum];
1473 DBG ( "%s: Trying to activate link.\n", priv->nic_name );
1475 TLan_MiiReadReg(nic, phy, MII_BMSR, &ability);
1476
1477 if ((status & BMSR_ANEGCAPABLE) && (!priv->aui)) {
1478 ability = status >> 11;
1479 if (priv->speed == TLAN_SPEED_10 &&
1480 priv->duplex == TLAN_DUPLEX_HALF) {
1481 TLan_MiiWriteReg(nic, phy, MII_BMCR, 0x0000);
1482 } else if (priv->speed == TLAN_SPEED_10 &&
1483 priv->duplex == TLAN_DUPLEX_FULL) {
1484 priv->tlanFullDuplex = TRUE;
1485 TLan_MiiWriteReg(nic, phy, MII_BMCR, 0x0100);
1486 } else if (priv->speed == TLAN_SPEED_100 &&
1487 priv->duplex == TLAN_DUPLEX_HALF) {
1488 TLan_MiiWriteReg(nic, phy, MII_BMCR, 0x2000);
1489 } else if (priv->speed == TLAN_SPEED_100 &&
1490 priv->duplex == TLAN_DUPLEX_FULL) {
1491 priv->tlanFullDuplex = TRUE;
1492 TLan_MiiWriteReg(nic, phy, MII_BMCR, 0x2100);
1493 } else {
1494
1495 /* Set Auto-Neg advertisement */
1497 (ability << 5) | 1);
1498 /* Enablee Auto-Neg */
1499 TLan_MiiWriteReg(nic, phy, MII_BMCR, 0x1000);
1500 /* Restart Auto-Neg */
1501 TLan_MiiWriteReg(nic, phy, MII_BMCR, 0x1200);
1502 /* Wait for 4 sec for autonegotiation
1503 * to complete. The max spec time is less than this
1504 * but the card need additional time to start AN.
1505 * .5 sec should be plenty extra.
1506 */
1507 DBG ( "TLAN: %s: Starting autonegotiation.\n",
1508 priv->nic_name );
1509 mdelay(4000);
1511 /* TLan_SetTimer( dev, (2*HZ), TLAN_TIMER_PHY_FINISH_AN ); */
1512 return;
1513 }
1514
1515 }
1516
1517 if ((priv->aui) && (priv->phyNum != 0)) {
1518 priv->phyNum = 0;
1519 data =
1523 mdelay(50);
1524 /* TLan_SetTimer( dev, (40*HZ/1000), TLAN_TIMER_PHY_PDOWN ); */
1526 return;
1527 } else if (priv->phyNum == 0) {
1528 control = 0;
1529 TLan_MiiReadReg(nic, phy, TLAN_TLPHY_CTL, &tctl);
1530 if (priv->aui) {
1531 tctl |= TLAN_TC_AUISEL;
1532 } else {
1533 tctl &= ~TLAN_TC_AUISEL;
1534 if (priv->duplex == TLAN_DUPLEX_FULL) {
1536 priv->tlanFullDuplex = TRUE;
1537 }
1538 if (priv->speed == TLAN_SPEED_100) {
1540 }
1541 }
1543 TLan_MiiWriteReg(nic, phy, TLAN_TLPHY_CTL, tctl);
1544 }
1545
1546 /* Wait for 2 sec to give the tranceiver time
1547 * to establish link.
1548 */
1549 /* TLan_SetTimer( dev, (4*HZ), TLAN_TIMER_FINISH_RESET ); */
1550 mdelay(2000);
1552
1553} /* TLan_PhyStartLink */
1554
1556{
1557
1558 u16 an_adv;
1559 u16 an_lpa;
1560 u16 data;
1561 u16 mode;
1562 u16 phy;
1563 u16 status;
1564
1565 phy = priv->phy[priv->phyNum];
1566
1568 udelay(1000);
1570
1571 if (!(status & BMSR_ANEGCOMPLETE)) {
1572 /* Wait for 8 sec to give the process
1573 * more time. Perhaps we should fail after a while.
1574 */
1575 if (!priv->neg_be_verbose++) {
1576 printf
1577 ("TLAN: Giving autonegotiation more time.\n");
1578 printf
1579 ("TLAN: Please check that your adapter has\n");
1580 printf
1581 ("TLAN: been properly connected to a HUB or Switch.\n");
1582 printf
1583 ("TLAN: Trying to establish link in the background...\n");
1584 }
1585 mdelay(8000);
1587 /* TLan_SetTimer( dev, (8*HZ), TLAN_TIMER_PHY_FINISH_AN ); */
1588 return;
1589 }
1590
1591 DBG ( "TLAN: %s: Autonegotiation complete.\n", priv->nic_name );
1592 TLan_MiiReadReg(nic, phy, MII_ADVERTISE, &an_adv);
1593 TLan_MiiReadReg(nic, phy, MII_LPA, &an_lpa);
1594 mode = an_adv & an_lpa & 0x03E0;
1595 if (mode & 0x0100) {
1596 printf("Full Duplex\n");
1597 priv->tlanFullDuplex = TRUE;
1598 } else if (!(mode & 0x0080) && (mode & 0x0040)) {
1599 priv->tlanFullDuplex = TRUE;
1600 printf("Full Duplex\n");
1601 }
1602
1603 if ((!(mode & 0x0180))
1605 && (priv->phyNum != 0)) {
1606 priv->phyNum = 0;
1607 data =
1611 /* TLan_SetTimer( nic, (400*HZ/1000), TLAN_TIMER_PHY_PDOWN ); */
1612 mdelay(400);
1614 return;
1615 }
1616
1617 if (priv->phyNum == 0) {
1618 if ((priv->duplex == TLAN_DUPLEX_FULL)
1619 || (an_adv & an_lpa & 0x0040)) {
1622 DBG
1623 ( "TLAN: Starting internal PHY with FULL-DUPLEX\n" );
1624 } else {
1627 DBG
1628 ( "TLAN: Starting internal PHY with HALF-DUPLEX\n" );
1629 }
1630 }
1631
1632 /* Wait for 100 ms. No reason in partiticular.
1633 */
1634 /* TLan_SetTimer( dev, (HZ/10), TLAN_TIMER_FINISH_RESET ); */
1635 mdelay(100);
1637
1638} /* TLan_PhyFinishAutoNeg */
1639
1640#ifdef MONITOR
1641
1642/*********************************************************************
1643*
1644* TLan_phyMonitor
1645*
1646* Returns:
1647* None
1648*
1649* Params:
1650* dev The device structure of this device.
1651*
1652*
1653* This function monitors PHY condition by reading the status
1654* register via the MII bus. This can be used to give info
1655* about link changes (up/down), and possible switch to alternate
1656* media.
1657*
1658********************************************************************/
1659
1660void TLan_PhyMonitor(struct net_device *dev)
1661{
1662 TLanPrivateInfo *priv = dev->priv;
1663 u16 phy;
1664 u16 phy_status;
1665
1666 phy = priv->phy[priv->phyNum];
1667
1668 /* Get PHY status register */
1669 TLan_MiiReadReg(nic, phy, MII_BMSR, &phy_status);
1670
1671 /* Check if link has been lost */
1672 if (!(phy_status & BMSR_LSTATUS)) {
1673 if (priv->link) {
1674 priv->link = 0;
1675 printf("TLAN: %s has lost link\n", priv->nic_name);
1676 priv->flags &= ~IFF_RUNNING;
1677 mdelay(2000);
1678 TLan_PhyMonitor(nic);
1679 /* TLan_SetTimer( dev, (2*HZ), TLAN_TIMER_LINK_BEAT ); */
1680 return;
1681 }
1682 }
1683
1684 /* Link restablished? */
1685 if ((phy_status & BMSR_LSTATUS) && !priv->link) {
1686 priv->link = 1;
1687 printf("TLAN: %s has reestablished link\n",
1688 priv->nic_name);
1689 priv->flags |= IFF_RUNNING;
1690 }
1691
1692 /* Setup a new monitor */
1693 /* TLan_SetTimer( dev, (2*HZ), TLAN_TIMER_LINK_BEAT ); */
1694 mdelay(2000);
1695 TLan_PhyMonitor(nic);
1696}
1697
1698#endif /* MONITOR */
1699
1700static struct pci_device_id tlan_nics[] = {
1701 PCI_ROM(0x0e11, 0xae32, "netel100","Compaq Netelligent 10/100 TX PCI UTP", 0),
1702 PCI_ROM(0x0e11, 0xae34, "netel10", "Compaq Netelligent 10 T PCI UTP", 0),
1703 PCI_ROM(0x0e11, 0xae35, "netflex3i", "Compaq Integrated NetFlex-3/P", 0),
1704 PCI_ROM(0x0e11, 0xae40, "netel100d", "Compaq Netelligent Dual 10/100 TX PCI UTP", 0),
1705 PCI_ROM(0x0e11, 0xae43, "netel100pi", "Compaq Netelligent Integrated 10/100 TX UTP", 0),
1706 PCI_ROM(0x0e11, 0xb011, "netel100i", "Compaq Netelligent 10/100 TX Embedded UTP", 0),
1707 PCI_ROM(0x0e11, 0xb012, "netelligent_10_t2", "Compaq Netelligent 10 T/2 PCI UTP/Coax", 0),
1708 PCI_ROM(0x0e11, 0xb030, "netelligent_10_100_ws_5100", "Compaq Netelligent 10/100 TX UTP", 0),
1709 PCI_ROM(0x0e11, 0xf130, "thunder", "Compaq NetFlex-3/P", 0),
1710 PCI_ROM(0x0e11, 0xf150, "netflex3b", "Compaq NetFlex-3/P", 0),
1711 PCI_ROM(0x108d, 0x0012, "oc2325", "Olicom OC-2325", 0),
1712 PCI_ROM(0x108d, 0x0013, "oc2183", "Olicom OC-2183/2185", 0),
1713 PCI_ROM(0x108d, 0x0014, "oc2326", "Olicom OC-2326", 0),
1714};
1715
1716PCI_DRIVER ( tlan_driver, tlan_nics, PCI_NO_CLASS );
1717
1718DRIVER ( "TLAN/PCI", nic_driver, pci_driver, tlan_driver,
1720
1721/*
1722 * Local variables:
1723 * c-basic-offset: 8
1724 * c-indent-level: 8
1725 * tab-width: 8
1726 * End:
1727 */
#define BASE
Definition 3c595.h:69
#define NULL
NULL pointer (VOID *)
Definition Base.h:322
pseudo_bit_t value[0x00020]
Definition arbel.h:2
const char * name
Definition ath9k_hw.c:1986
#define MII_ADVERTISE
Definition atl1e.h:875
#define MII_BMCR
Definition atl1e.h:871
#define MII_BMSR
Definition atl1e.h:872
#define MII_PHYSID2
Definition atl1e.h:874
#define MII_LPA
Definition atl1e.h:876
#define MII_PHYSID1
Definition atl1e.h:873
#define rxb
Definition davicom.c:147
#define TX_TIME_OUT
Definition davicom.c:51
#define txb
Definition davicom.c:145
uint32_t addr
Buffer address.
Definition dwmac.h:9
uint8_t id
Request identifier.
Definition ena.h:1
uint8_t data[48]
Additional event data.
Definition ena.h:11
uint8_t flags
Flags.
Definition ena.h:7
uint8_t status
Status.
Definition ena.h:5
uint8_t mac[ETH_ALEN]
MAC address.
Definition ena.h:13
uint16_t mode
Acceleration mode.
Definition ena.h:15
#define tx_ring
Definition epic100.c:99
#define rx_ring
Definition epic100.c:98
struct eth_slow_lacp_entity_tlv partner
Partner information.
Definition eth_slow.h:5
const char * eth_ntoa(const void *ll_addr)
Transcribe Ethernet address.
Definition ethernet.c:176
Ethernet protocol.
#define __unused
Declare a variable or data structure as unused.
Definition compiler.h:573
#define DBG(...)
Print a debugging message.
Definition compiler.h:498
uint32_t buffer
Buffer index (or NETVSC_RNDIS_NO_BUFFER)
Definition netvsc.h:5
#define FILE_LICENCE(_licence)
Declare a particular licence as applying to a file.
Definition compiler.h:896
uint8_t data8[16]
Definition ib_mad.h:7
#define ETH_ZLEN
Definition if_ether.h:11
#define ETH_ALEN
Definition if_ether.h:9
#define ETH_HLEN
Definition if_ether.h:10
#define u8
Definition igbvf_osdep.h:40
#define le32_to_cpu(value)
Definition byteswap.h:114
#define htons(value)
Definition byteswap.h:136
#define inw(io_addr)
Definition io.h:292
#define outb(data, io_addr)
Definition io.h:310
#define outw(data, io_addr)
Definition io.h:320
#define inl(io_addr)
Definition io.h:301
#define outl(data, io_addr)
Definition io.h:330
static __always_inline unsigned long virt_to_bus(volatile const void *addr)
Convert virtual address to a bus address.
Definition io.h:184
void __asmcall int val
Definition setjmp.h:12
void * memcpy(void *dest, const void *src, size_t len) __nonnull
int dummy_connect(struct nic *nic __unused)
Definition legacy.c:175
unsigned long tmp
Definition linux_pci.h:65
Media Independent Interface constants.
#define BMCR_SPEED100
Definition mii.h:51
#define BMCR_PDOWN
Definition mii.h:49
#define BMCR_RESET
Definition mii.h:53
#define BMSR_ANEGCOMPLETE
Definition mii.h:61
#define BMCR_ANENABLE
Definition mii.h:50
#define BMCR_LOOPBACK
Definition mii.h:52
#define BMSR_ANEGCAPABLE
Definition mii.h:59
#define BMCR_ISOLATE
Definition mii.h:48
#define BMSR_LSTATUS
Definition mii.h:58
#define BMCR_FULLDPLX
Definition mii.h:46
uint32_t control
Control.
Definition myson.h:3
static unsigned int unsigned int reg
Definition myson.h:162
#define DRIVER(_name_text, _unused2, _unused3, _name, _probe, _disable, _fake_bss)
Definition nic.h:220
irq_action_t
Definition nic.h:34
@ FORCE
Definition nic.h:37
@ ENABLE
Definition nic.h:36
@ DISABLE
Definition nic.h:35
#define PCI_DRIVER(_name, _ids, _class)
Definition nic.h:105
void adjust_pci_device(struct pci_device *pci)
Enable PCI device.
Definition pci.c:241
PCI bus.
#define PCI_ROM(_vendor, _device, _name, _description, _data)
Definition pci.h:308
struct TLanList::@305343174134316356326231312366206106076301324152 buffer[TLAN_BUFFERS_PER_LIST]
u32 count
Definition tlan.c:177
u16 frameSize
Definition tlan.c:175
u32 forward
Definition tlan.c:173
u16 cStat
Definition tlan.c:174
u32 address
Definition tlan.c:178
A network device.
Definition netdevice.h:353
void * priv
Driver private data.
Definition netdevice.h:432
Definition nic.h:49
unsigned char * packet
Definition nic.h:53
unsigned char * node_addr
Definition nic.h:52
unsigned int packetlen
Definition nic.h:54
unsigned char irqno
Definition nic.h:56
unsigned int ioaddr
Definition nic.h:55
struct nic_operations * nic_op
Definition nic.h:50
A PCI device ID list entry.
Definition pci.h:175
const char * name
Name.
Definition pci.h:177
A PCI device.
Definition pci.h:211
unsigned long ioaddr
I/O address.
Definition pci.h:226
struct pci_device_id * id
Driver device ID.
Definition pci.h:248
uint16_t vendor
Vendor ID.
Definition pci.h:228
uint16_t device
Device ID.
Definition pci.h:230
A PCI driver.
Definition pci.h:252
u16 addrOfs
Definition tlan.c:117
int nic_id
Definition tlan.c:111
u32 flags
Definition tlan.c:116
const char * name
Definition tlan.c:110
struct TLanList rx_ring[TLAN_NUM_RX_LISTS]
Definition tlan.c:185
unsigned char rxb[TLAN_MAX_FRAME_SIZE *TLAN_NUM_RX_LISTS]
Definition tlan.c:186
unsigned char txb[TLAN_MAX_FRAME_SIZE *TLAN_NUM_TX_LISTS]
Definition tlan.c:184
struct TLanList tx_ring[TLAN_NUM_TX_LISTS]
Definition tlan.c:183
u32 txTail
Definition tlan.c:211
u32 txInProgress
Definition tlan.c:210
u32 phyOnline
Definition tlan.c:213
struct TLanList * txList
Definition tlan.c:208
unsigned short vendor_id
Definition tlan.c:203
unsigned short dev_id
Definition tlan.c:204
unsigned rx_buf_sz
Definition tlan.c:207
u32 aui
Definition tlan.c:214
int eoc
Definition tlan.c:212
u8 tlanRev
Definition tlan.c:219
u32 speed
Definition tlan.c:218
u32 phyNum
Definition tlan.c:217
u8 tlanFullDuplex
Definition tlan.c:220
u8 neg_be_verbose
Definition tlan.c:222
unsigned int dirty_rx
Definition tlan.c:206
u32 phy[2]
Definition tlan.c:216
u32 txHead
Definition tlan.c:209
u32 duplex
Definition tlan.c:215
const char * nic_name
Definition tlan.c:205
unsigned int cur_rx
Definition tlan.c:206
static char media[]
Definition sundance.c:85
unsigned long currticks(void)
Get current system time in ticks.
Definition timer.c:43
void mdelay(unsigned long msecs)
Delay for a fixed number of milliseconds.
Definition timer.c:79
void udelay(unsigned long usecs)
Delay for a fixed number of microseconds.
Definition timer.c:61
static void TLan_MiiSync(u16)
Definition tlan.c:1220
static struct tlan_private * priv
Definition tlan.c:225
static void TLan_SetMulticastList(struct nic *nic)
Definition tlan.c:759
static int tlan_poll(struct nic *nic, int retrieve)
Definition tlan.c:493
static void TLan_EeSendStart(u16)
Definition tlan.c:885
static void TLan_FinishReset(struct nic *nic __unused)
static struct nic_operations tlan_operations
Definition tlan.c:751
static void TLan_SetMac(struct nic *nic __unused, int areg, unsigned char *mac)
Definition tlan.c:1308
u8 TLanBuffer[TLAN_MAX_FRAME_SIZE]
Definition tlan.c:194
static struct tlan_private TLanPrivateInfo
static void TLan_PhyPowerUp(struct nic *nic)
Definition tlan.c:1416
#define virt_to_le32desc(addr)
Definition tlan.c:59
static void refill_rx(struct nic *nic __unused)
Definition tlan.c:551
static void tlan_transmit(struct nic *nic, const char *d, unsigned int t, unsigned int s, const char *p)
Definition tlan.c:569
static void TLan_ResetLists(struct nic *nic __unused)
Definition tlan.c:243
static void TLan_PhyPowerDown(struct nic *nic)
Definition tlan.c:1389
static void tlan_disable(struct nic *nic __unused, void *hwdev __unused)
Definition tlan.c:721
static void TLan_MiiWriteReg(struct nic *nic __unused, u16, u16, u16)
Definition tlan.c:1256
tlan_nics
Definition tlan.c:101
@ NETEL100D
Definition tlan.c:104
@ OC2326
Definition tlan.c:104
@ NETELLIGENT_10_100_WS_5100
Definition tlan.c:105
@ THUNDER
Definition tlan.c:102
@ OC2325
Definition tlan.c:104
@ NETEL100
Definition tlan.c:102
@ NETEL10
Definition tlan.c:102
@ NETFLEX3I
Definition tlan.c:102
@ NETFLEX3B
Definition tlan.c:102
@ OC2183
Definition tlan.c:104
@ NETEL100I
Definition tlan.c:104
@ NETELLIGENT_10_T2
Definition tlan.c:106
@ NETEL100PI
Definition tlan.c:103
static void TLan_MiiSendData(u16, u32, unsigned)
Definition tlan.c:1181
#define tlan_buffers
Definition tlan.c:188
static void TLan_PhyStartLink(struct nic *nic)
Definition tlan.c:1462
static int tlan_probe(struct nic *nic, struct pci_device *pci)
Definition tlan.c:781
static int TLan_EeSendByte(u16, u8, int)
Definition tlan.c:922
static void TLan_PhyDetect(struct nic *nic)
Definition tlan.c:1342
static int TLan_EeReadByte(u16 io_base, u8, u8 *)
Definition tlan.c:1035
static int chip_idx
Definition tlan.c:196
static const struct pci_id_info tlan_pci_tbl[]
Definition tlan.c:120
static void TLan_EeReceiveByte(u16, u8 *, int)
Definition tlan.c:980
static int TLan_MiiReadReg(struct nic *nic __unused, u16, u16, u16 *)
Definition tlan.c:1102
static void TLan_PhyFinishAutoNeg(struct nic *nic)
Definition tlan.c:1555
static void TLan_PhyReset(struct nic *nic)
Definition tlan.c:1435
static void TLan_ResetAdapter(struct nic *nic __unused)
Definition tlan.c:301
static void tlan_irq(struct nic *nic __unused, irq_action_t action __unused)
Definition tlan.c:739
#define TLAN_NET_SIO_ECLOK
Definition tlan.h:232
#define TLAN_NUM_TX_LISTS
Definition tlan.h:52
#define TLAN_NET_SIO_MDATA
Definition tlan.h:238
#define NAT_SEM_ID1
Definition tlan.h:343
#define TLAN_NET_CFG_1CHAN
Definition tlan.h:258
#define TLAN_LAST_BUFFER
Definition tlan.h:135
#define TLAN_NET_MASK_MASK4
Definition tlan.h:249
#define TLAN_ID_RX_EOC
Definition tlan.h:296
#define TLAN_ID_TX_EOC
Definition tlan.h:294
#define TLAN_NET_SIO_EDATA
Definition tlan.h:234
#define TLAN_HC_LD_THR
Definition tlan.h:204
#define TLAN_CSTAT_READY
Definition tlan.h:138
#define TLAN_CSTAT_UNUSED
Definition tlan.h:136
#define TLAN_NET_MASK
Definition tlan.h:245
#define TLAN_HC_GO
Definition tlan.h:195
#define TLAN_HC_ACK
Definition tlan.h:197
#define TLAN_DEF_REVISION
Definition tlan.h:265
#define TLAN_DUPLEX_HALF
Definition tlan.h:105
#define TLAN_DIO_DATA
Definition tlan.h:216
#define TLAN_PHY_AN_EN_STAT
Definition tlan.h:340
#define TLAN_HC_RT
Definition tlan.h:200
#define TLAN_NET_CMD
Definition tlan.h:221
#define TLan_GetBit(bit, port)
Definition tlan.h:435
#define TLAN_SPEED_100
Definition tlan.h:102
#define TLAN_HC_INT_OFF
Definition tlan.h:206
#define TLAN_NET_SIO_ETXEN
Definition tlan.h:233
#define TLAN_HASH_2
Definition tlan.h:274
#define TLAN_NET_CMD_NWRAP
Definition tlan.h:223
static u8 TLan_DioRead8(u16 base_addr, u16 internal_addr)
Definition tlan.h:352
#define TLan_ClearBit(bit, port)
Definition tlan.h:434
#define TLAN_NET_CFG_BIT
Definition tlan.h:254
#define TLAN_MAX_FRAME_SIZE
Definition tlan.h:49
#define TLAN_PHY_SPEED_100
Definition tlan.h:338
#define TLAN_NET_CFG_1FRAG
Definition tlan.h:257
#define TLAN_HC_AD_RST
Definition tlan.h:202
#define TLAN_CSTAT_FRM_CMP
Definition tlan.h:137
#define TLAN_TC_INTEN
Definition tlan.h:328
#define TLAN_LED_REG
Definition tlan.h:288
#define CIRC_INC(a, b)
Definition tlan.h:348
#define TLAN_NET_SIO_MCLK
Definition tlan.h:236
#define TLAN_ADAPTER_BIT_RATE_PHY
Definition tlan.h:96
#define TLAN_DUPLEX_FULL
Definition tlan.h:106
#define TLAN_SPEED_10
Definition tlan.h:101
#define TLAN_HOST_INT
Definition tlan.h:213
#define TLAN_BUFFERS_PER_LIST
Definition tlan.h:134
#define TLAN_ACOMMIT
Definition tlan.h:287
#define TLAN_NET_CONFIG
Definition tlan.h:251
#define TLAN_DIO_ADR
Definition tlan.h:210
#define TLAN_NET_SIO
Definition tlan.h:230
#define TLAN_EEPROM_ACK
Definition tlan.h:183
#define TLAN_PHY_NONE
Definition tlan.h:155
#define TLAN_HC_LD_TMR
Definition tlan.h:203
#define TLAN_NUM_RX_LISTS
Definition tlan.h:51
#define TLAN_NET_CMD_DUPLEX
Definition tlan.h:227
static void TLan_DioWrite16(u16 base_addr, u16 internal_addr, u16 data)
Definition tlan.h:392
#define TLAN_ADAPTER_NONE
Definition tlan.h:94
#define TLAN_TC_AUISEL
Definition tlan.h:323
#define TLAN_PHY_DUPLEX_FULL
Definition tlan.h:339
#define TLAN_ADAPTER_UNMANAGED_PHY
Definition tlan.h:95
#define TRUE
Definition tlan.h:46
#define FALSE
Definition tlan.h:45
#define TLAN_EEPROM_STOP
Definition tlan.h:184
static void TLan_DioWrite8(u16 base_addr, u16 internal_addr, u8 data)
Definition tlan.h:382
#define TLAN_INT_DIS
Definition tlan.h:293
#define TLAN_ADAPTER_USE_INTERN_10
Definition tlan.h:97
#define TLan_SetBit(bit, port)
Definition tlan.h:436
#define TLAN_NET_CFG_PHY_EN
Definition tlan.h:260
#define TLAN_NET_SIO_MTXEN
Definition tlan.h:237
static void TLan_DioWrite32(u16 base_addr, u16 internal_addr, u32 data)
Definition tlan.h:402
#define TLAN_CSTAT_EOC
Definition tlan.h:139
#define TLAN_HOST_CMD
Definition tlan.h:194
#define TLAN_NET_MASK_MASK5
Definition tlan.h:248
#define TLAN_MAX_RX
Definition tlan.h:292
#define TLAN_ADAPTER_ACTIVITY_LED
Definition tlan.h:98
#define NAT_SEM_ID2
Definition tlan.h:344
#define TLAN_NET_CMD_NRESET
Definition tlan.h:222
#define TLAN_AREG_0
Definition tlan.h:269
#define TLAN_PHY_MAX_ADDR
Definition tlan.h:154
#define TLAN_NET_SIO_MINTEN
Definition tlan.h:231
#define TLAN_HASH_1
Definition tlan.h:273
#define TLAN_HC_INT_ON
Definition tlan.h:207
#define TLAN_TLPHY_CTL
Definition tlan.h:320
#define TLAN_CH_PARM
Definition tlan.h:209
#define TLAN_NET_CMD_CAF
Definition tlan.h:225
#define TLAN_NET_SIO_NMRST
Definition tlan.h:235
#define TLAN_NET_MASK_MASK7
Definition tlan.h:246
#define TLAN_LED_LINK
Definition tlan.h:290
#define TLAN_TLPHY_PAR
Definition tlan.h:336
#define u16
Definition vga.h:20
#define u32
Definition vga.h:21
int printf(const char *fmt,...)
Write a formatted string to the console.
Definition vsprintf.c:465