1 /**************************************************************************
3 * tlan.c -- Etherboot device driver for the Texas Instruments ThunderLAN
4 * Written 2003-2003 by Timothy Legge <tlegge@rogers.com>
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.
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.
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., 675 Mass Ave, Cambridge, MA 02139, USA.
20 * Portions of this code based on:
21 * lan.c: Linux ThunderLan Driver:
25 * (C) 1997-1998 Caldera, Inc.
26 * (C) 1998 James Banks
27 * (C) 1999-2001 Torben Mathiasen
28 * (C) 2002 Samuel Chessman
32 * v1.0 07-08-2003 timlegge Initial not quite working version
33 * v1.1 07-27-2003 timlegge Sync 5.0 and 5.1 versions
34 * v1.2 08-19-2003 timlegge Implement Multicast Support
35 * v1.3 08-23-2003 timlegge Fix the transmit Function
36 * v1.4 01-17-2004 timlegge Initial driver output cleanup
38 * Indent Options: indent -kr -i8
39 ***************************************************************************/
41 #include "etherboot.h"
44 #include <gpxe/ethernet.h>
48 #define drv_version "v1.4"
49 #define drv_date "01-17-2004"
51 /* NIC specific static variables go here */
53 #define TX_TIME_OUT (6*HZ)
55 /* Condensed operations for readability. */
56 #define virt_to_le32desc(addr) cpu_to_le32(virt_to_bus(addr))
57 #define le32desc_to_virt(addr) bus_to_virt(le32_to_cpu(addr))
59 static void TLan_ResetLists(struct nic
*nic __unused
);
60 static void TLan_ResetAdapter(struct nic
*nic __unused
);
61 static void TLan_FinishReset(struct nic
*nic __unused
);
63 static void TLan_EeSendStart(u16
);
64 static int TLan_EeSendByte(u16
, u8
, int);
65 static void TLan_EeReceiveByte(u16
, u8
*, int);
66 static int TLan_EeReadByte(u16 io_base
, u8
, u8
*);
68 static void TLan_PhyDetect(struct nic
*nic
);
69 static void TLan_PhyPowerDown(struct nic
*nic
);
70 static void TLan_PhyPowerUp(struct nic
*nic
);
73 static void TLan_SetMac(struct nic
*nic __unused
, int areg
, unsigned char *mac
);
75 static void TLan_PhyReset(struct nic
*nic
);
76 static void TLan_PhyStartLink(struct nic
*nic
);
77 static void TLan_PhyFinishAutoNeg(struct nic
*nic
);
80 static void TLan_PhyMonitor(struct nic
*nic
);
84 static void refill_rx(struct nic
*nic __unused
);
86 static int TLan_MiiReadReg(struct nic
*nic __unused
, u16
, u16
, u16
*);
87 static void TLan_MiiSendData(u16
, u32
, unsigned);
88 static void TLan_MiiSync(u16
);
89 static void TLan_MiiWriteReg(struct nic
*nic __unused
, u16
, u16
, u16
);
92 static const char *media
[] = {
93 "10BaseT-HD ", "10BaseT-FD ", "100baseTx-HD ",
94 "100baseTx-FD", "100baseT4", 0
97 /* This much match tlan_pci_tbl[]! */
99 NETEL10
= 0, NETEL100
= 1, NETFLEX3I
= 2, THUNDER
= 3, NETFLEX3B
=
101 NETEL100D
= 6, NETEL100I
= 7, OC2183
= 8, OC2325
= 9, OC2326
=
102 10, NETELLIGENT_10_100_WS_5100
= 11,
103 NETELLIGENT_10_T2
= 12
110 u32 pci
, pci_mask
, subsystem
, subsystem_mask
;
111 u32 revision
, revision_mask
; /* Only 8 bits. */
114 u16 addrOfs
; /* Address Offset */
117 static const struct pci_id_info tlan_pci_tbl
[] = {
118 {"Compaq Netelligent 10 T PCI UTP", NETEL10
,
119 {0xae340e11, 0xffffffff, 0, 0, 0, 0},
120 TLAN_ADAPTER_ACTIVITY_LED
, 0x83},
121 {"Compaq Netelligent 10/100 TX PCI UTP", NETEL100
,
122 {0xae320e11, 0xffffffff, 0, 0, 0, 0},
123 TLAN_ADAPTER_ACTIVITY_LED
, 0x83},
124 {"Compaq Integrated NetFlex-3/P", NETFLEX3I
,
125 {0xae350e11, 0xffffffff, 0, 0, 0, 0},
126 TLAN_ADAPTER_NONE
, 0x83},
127 {"Compaq NetFlex-3/P", THUNDER
,
128 {0xf1300e11, 0xffffffff, 0, 0, 0, 0},
129 TLAN_ADAPTER_UNMANAGED_PHY
| TLAN_ADAPTER_BIT_RATE_PHY
, 0x83},
130 {"Compaq NetFlex-3/P", NETFLEX3B
,
131 {0xf1500e11, 0xffffffff, 0, 0, 0, 0},
132 TLAN_ADAPTER_NONE
, 0x83},
133 {"Compaq Netelligent Integrated 10/100 TX UTP", NETEL100PI
,
134 {0xae430e11, 0xffffffff, 0, 0, 0, 0},
135 TLAN_ADAPTER_ACTIVITY_LED
, 0x83},
136 {"Compaq Netelligent Dual 10/100 TX PCI UTP", NETEL100D
,
137 {0xae400e11, 0xffffffff, 0, 0, 0, 0},
138 TLAN_ADAPTER_NONE
, 0x83},
139 {"Compaq Netelligent 10/100 TX Embedded UTP", NETEL100I
,
140 {0xb0110e11, 0xffffffff, 0, 0, 0, 0},
141 TLAN_ADAPTER_NONE
, 0x83},
142 {"Olicom OC-2183/2185", OC2183
,
143 {0x0013108d, 0xffffffff, 0, 0, 0, 0},
144 TLAN_ADAPTER_USE_INTERN_10
, 0x83},
145 {"Olicom OC-2325", OC2325
,
146 {0x0012108d, 0xffffffff, 0, 0, 0, 0},
147 TLAN_ADAPTER_UNMANAGED_PHY
, 0xF8},
148 {"Olicom OC-2326", OC2326
,
149 {0x0014108d, 0xffffffff, 0, 0, 0, 0},
150 TLAN_ADAPTER_USE_INTERN_10
, 0xF8},
151 {"Compaq Netelligent 10/100 TX UTP", NETELLIGENT_10_100_WS_5100
,
152 {0xb0300e11, 0xffffffff, 0, 0, 0, 0},
153 TLAN_ADAPTER_ACTIVITY_LED
, 0x83},
154 {"Compaq Netelligent 10 T/2 PCI UTP/Coax", NETELLIGENT_10_T2
,
155 {0xb0120e11, 0xffffffff, 0, 0, 0, 0},
156 TLAN_ADAPTER_NONE
, 0x83},
157 {"Compaq NetFlex-3/E", 0, /* EISA card */
159 TLAN_ADAPTER_ACTIVITY_LED
| TLAN_ADAPTER_UNMANAGED_PHY
|
160 TLAN_ADAPTER_BIT_RATE_PHY
, 0x83},
161 {"Compaq NetFlex-3/E", 0, /* EISA card */
163 TLAN_ADAPTER_ACTIVITY_LED
, 0x83},
176 } buffer
[TLAN_BUFFERS_PER_LIST
];
180 struct TLanList tx_ring
[TLAN_NUM_TX_LISTS
];
181 unsigned char txb
[TLAN_MAX_FRAME_SIZE
* TLAN_NUM_TX_LISTS
];
182 struct TLanList rx_ring
[TLAN_NUM_RX_LISTS
];
183 unsigned char rxb
[TLAN_MAX_FRAME_SIZE
* TLAN_NUM_RX_LISTS
];
184 } tlan_buffers __shared
;
185 #define tx_ring tlan_buffers.tx_ring
186 #define txb tlan_buffers.txb
187 #define rx_ring tlan_buffers.rx_ring
188 #define rxb tlan_buffers.rxb
190 typedef u8 TLanBuffer
[TLAN_MAX_FRAME_SIZE
];
194 /*****************************************************************
195 * TLAN Private Information Structure
197 ****************************************************************/
198 static struct tlan_private
{
199 unsigned short vendor_id
; /* PCI Vendor code */
200 unsigned short dev_id
; /* PCI Device code */
201 const char *nic_name
;
202 unsigned int cur_rx
, dirty_rx
; /* Producer/consumer ring indicies */
203 unsigned rx_buf_sz
; /* Based on mtu + Slack */
204 struct TLanList
*txList
;
221 static struct tlan_private
*priv
;
225 /***************************************************************
231 * dev The device structure with the list
232 * stuctures to be reset.
234 * This routine sets the variables associated with managing
235 * the TLAN lists to their initial values.
237 **************************************************************/
239 static void TLan_ResetLists(struct nic
*nic __unused
)
243 struct TLanList
*list
;
247 for (i
= 0; i
< TLAN_NUM_TX_LISTS
; i
++) {
249 list
->cStat
= TLAN_CSTAT_UNUSED
;
250 list
->buffer
[0].address
= virt_to_bus(txb
+
251 (i
* TLAN_MAX_FRAME_SIZE
));
252 list
->buffer
[2].count
= 0;
253 list
->buffer
[2].address
= 0;
254 list
->buffer
[9].address
= 0;
258 priv
->rx_buf_sz
= (TLAN_MAX_FRAME_SIZE
);
259 // priv->rx_head_desc = &rx_ring[0];
261 /* Initialize all the Rx descriptors */
262 for (i
= 0; i
< TLAN_NUM_RX_LISTS
; i
++) {
263 rx_ring
[i
].forward
= virt_to_le32desc(&rx_ring
[i
+ 1]);
264 rx_ring
[i
].cStat
= TLAN_CSTAT_READY
;
265 rx_ring
[i
].frameSize
= TLAN_MAX_FRAME_SIZE
;
266 rx_ring
[i
].buffer
[0].count
=
267 TLAN_MAX_FRAME_SIZE
| TLAN_LAST_BUFFER
;
268 rx_ring
[i
].buffer
[0].address
=
269 virt_to_le32desc(&rxb
[i
* TLAN_MAX_FRAME_SIZE
]);
270 rx_ring
[i
].buffer
[1].count
= 0;
271 rx_ring
[i
].buffer
[1].address
= 0;
274 /* Mark the last entry as wrapping the ring */
275 rx_ring
[i
- 1].forward
= virt_to_le32desc(&rx_ring
[0]);
276 priv
->dirty_rx
= (unsigned int) (i
- TLAN_NUM_RX_LISTS
);
278 } /* TLan_ResetLists */
280 /***************************************************************
286 * dev Pointer to device structure of adapter
289 * This function resets the adapter and it's physical
290 * device. See Chap. 3, pp. 9-10 of the "ThunderLAN
291 * Programmer's Guide" for details. The routine tries to
292 * implement what is detailed there, though adjustments
295 **************************************************************/
297 void TLan_ResetAdapter(struct nic
*nic __unused
)
304 priv
->tlanFullDuplex
= FALSE
;
306 /* 1. Assert reset bit. */
308 data
= inl(BASE
+ TLAN_HOST_CMD
);
309 data
|= TLAN_HC_AD_RST
;
310 outl(data
, BASE
+ TLAN_HOST_CMD
);
314 /* 2. Turn off interrupts. ( Probably isn't necessary ) */
316 data
= inl(BASE
+ TLAN_HOST_CMD
);
317 data
|= TLAN_HC_INT_OFF
;
318 outl(data
, BASE
+ TLAN_HOST_CMD
);
319 /* 3. Clear AREGs and HASHs. */
321 for (i
= TLAN_AREG_0
; i
<= TLAN_HASH_2
; i
+= 4) {
322 TLan_DioWrite32(BASE
, (u16
) i
, 0);
325 /* 4. Setup NetConfig register. */
328 TLAN_NET_CFG_1FRAG
| TLAN_NET_CFG_1CHAN
| TLAN_NET_CFG_PHY_EN
;
329 TLan_DioWrite16(BASE
, TLAN_NET_CONFIG
, (u16
) data
);
331 /* 5. Load Ld_Tmr and Ld_Thr in HOST_CMD. */
333 outl(TLAN_HC_LD_TMR
| 0x3f, BASE
+ TLAN_HOST_CMD
);
334 outl(TLAN_HC_LD_THR
| 0x0, BASE
+ TLAN_HOST_CMD
);
336 /* 6. Unreset the MII by setting NMRST (in NetSio) to 1. */
338 outw(TLAN_NET_SIO
, BASE
+ TLAN_DIO_ADR
);
339 addr
= BASE
+ TLAN_DIO_DATA
+ TLAN_NET_SIO
;
340 TLan_SetBit(TLAN_NET_SIO_NMRST
, addr
);
342 /* 7. Setup the remaining registers. */
344 if (priv
->tlanRev
>= 0x30) {
345 data8
= TLAN_ID_TX_EOC
| TLAN_ID_RX_EOC
;
346 TLan_DioWrite8(BASE
, TLAN_INT_DIS
, data8
);
349 data
= TLAN_NET_CFG_1FRAG
| TLAN_NET_CFG_1CHAN
;
351 if (tlan_pci_tbl
[chip_idx
].flags
& TLAN_ADAPTER_BIT_RATE_PHY
) {
352 data
|= TLAN_NET_CFG_BIT
;
353 if (priv
->aui
== 1) {
354 TLan_DioWrite8(BASE
, TLAN_ACOMMIT
, 0x0a);
355 } else if (priv
->duplex
== TLAN_DUPLEX_FULL
) {
356 TLan_DioWrite8(BASE
, TLAN_ACOMMIT
, 0x00);
357 priv
->tlanFullDuplex
= TRUE
;
359 TLan_DioWrite8(BASE
, TLAN_ACOMMIT
, 0x08);
363 if (priv
->phyNum
== 0) {
364 data
|= TLAN_NET_CFG_PHY_EN
;
366 TLan_DioWrite16(BASE
, TLAN_NET_CONFIG
, (u16
) data
);
368 if (tlan_pci_tbl
[chip_idx
].flags
& TLAN_ADAPTER_UNMANAGED_PHY
) {
369 TLan_FinishReset(nic
);
371 TLan_PhyPowerDown(nic
);
374 } /* TLan_ResetAdapter */
376 void TLan_FinishReset(struct nic
*nic
)
386 u16 tlphy_id1
, tlphy_id2
;
389 phy
= priv
->phy
[priv
->phyNum
];
391 data
= TLAN_NET_CMD_NRESET
| TLAN_NET_CMD_NWRAP
;
392 if (priv
->tlanFullDuplex
) {
393 data
|= TLAN_NET_CMD_DUPLEX
;
395 TLan_DioWrite8(BASE
, TLAN_NET_CMD
, data
);
396 data
= TLAN_NET_MASK_MASK4
| TLAN_NET_MASK_MASK5
;
397 if (priv
->phyNum
== 0) {
398 data
|= TLAN_NET_MASK_MASK7
;
400 TLan_DioWrite8(BASE
, TLAN_NET_MASK
, data
);
401 TLan_DioWrite16(BASE
, TLAN_MAX_RX
, ((1536) + 7) & ~7);
402 TLan_MiiReadReg(nic
, phy
, MII_GEN_ID_HI
, &tlphy_id1
);
403 TLan_MiiReadReg(nic
, phy
, MII_GEN_ID_LO
, &tlphy_id2
);
405 if ((tlan_pci_tbl
[chip_idx
].flags
& TLAN_ADAPTER_UNMANAGED_PHY
)
407 status
= MII_GS_LINK
;
408 DBG ( "TLAN: %s: Link forced.\n", priv
->nic_name
);
410 TLan_MiiReadReg(nic
, phy
, MII_GEN_STS
, &status
);
412 TLan_MiiReadReg(nic
, phy
, MII_GEN_STS
, &status
);
413 if ((status
& MII_GS_LINK
) && /* We only support link info on Nat.Sem. PHY's */
414 (tlphy_id1
== NAT_SEM_ID1
)
415 && (tlphy_id2
== NAT_SEM_ID2
)) {
416 TLan_MiiReadReg(nic
, phy
, MII_AN_LPA
, &partner
);
417 TLan_MiiReadReg(nic
, phy
, TLAN_TLPHY_PAR
,
420 DBG ( "TLAN: %s: Link active with ",
422 if (!(tlphy_par
& TLAN_PHY_AN_EN_STAT
)) {
423 DBG ( "forced 10%sMbps %s-Duplex\n",
424 tlphy_par
& TLAN_PHY_SPEED_100
? ""
426 tlphy_par
& TLAN_PHY_DUPLEX_FULL
?
430 ( "AutoNegotiation enabled, at 10%sMbps %s-Duplex\n",
431 tlphy_par
& TLAN_PHY_SPEED_100
? "" :
433 tlphy_par
& TLAN_PHY_DUPLEX_FULL
?
435 DBG ( "TLAN: Partner capability: " );
436 for (i
= 5; i
<= 10; i
++)
437 if (partner
& (1 << i
)) {
438 DBG ( "%s", media
[i
- 5] );
443 TLan_DioWrite8(BASE
, TLAN_LED_REG
, TLAN_LED_LINK
);
445 /* We have link beat..for now anyway */
447 /*Enabling link beat monitoring */
448 /* TLan_SetTimer( nic, (10*HZ), TLAN_TIMER_LINK_BEAT ); */
450 TLan_PhyMonitor(nic
);
452 } else if (status
& MII_GS_LINK
) {
453 DBG ( "TLAN: %s: Link active\n", priv
->nic_name
);
454 TLan_DioWrite8(BASE
, TLAN_LED_REG
, TLAN_LED_LINK
);
458 if (priv
->phyNum
== 0) {
459 TLan_MiiReadReg(nic
, phy
, TLAN_TLPHY_CTL
, &tlphy_ctl
);
460 tlphy_ctl
|= TLAN_TC_INTEN
;
461 TLan_MiiWriteReg(nic
, phy
, TLAN_TLPHY_CTL
, tlphy_ctl
);
462 sio
= TLan_DioRead8(BASE
, TLAN_NET_SIO
);
463 sio
|= TLAN_NET_SIO_MINTEN
;
464 TLan_DioWrite8(BASE
, TLAN_NET_SIO
, sio
);
467 if (status
& MII_GS_LINK
) {
468 TLan_SetMac(nic
, 0, nic
->node_addr
);
470 outb((TLAN_HC_INT_ON
>> 8), BASE
+ TLAN_HOST_CMD
+ 1);
471 outl(virt_to_bus(&rx_ring
), BASE
+ TLAN_CH_PARM
);
472 outl(TLAN_HC_GO
| TLAN_HC_RT
, BASE
+ TLAN_HOST_CMD
);
475 ( "TLAN: %s: Link inactive, will retry in 10 secs...\n",
477 /* TLan_SetTimer( nic, (10*HZ), TLAN_TIMER_FINISH_RESET ); */
479 TLan_FinishReset(nic
);
484 } /* TLan_FinishReset */
486 /**************************************************************************
487 POLL - Wait for a frame
488 ***************************************************************************/
489 static int tlan_poll(struct nic
*nic
, int retrieve
)
491 /* return true if there's an ethernet packet ready to read */
492 /* nic->packet should contain data on return */
493 /* nic->packetlen should contain length of data */
498 int entry
= priv
->cur_rx
% TLAN_NUM_RX_LISTS
;
499 u16 tmpCStat
= le32_to_cpu(rx_ring
[entry
].cStat
);
500 u16 host_int
= inw(BASE
+ TLAN_HOST_INT
);
502 if ((tmpCStat
& TLAN_CSTAT_FRM_CMP
) && !retrieve
)
505 outw(host_int
, BASE
+ TLAN_HOST_INT
);
507 if (!(tmpCStat
& TLAN_CSTAT_FRM_CMP
))
510 /* printf("PI-1: 0x%hX\n", host_int); */
511 if (tmpCStat
& TLAN_CSTAT_EOC
)
514 framesize
= rx_ring
[entry
].frameSize
;
516 nic
->packetlen
= framesize
;
518 DBG ( ".%d.", (unsigned int) framesize
);
520 memcpy(nic
->packet
, rxb
+
521 (priv
->cur_rx
* TLAN_MAX_FRAME_SIZE
), nic
->packetlen
);
523 rx_ring
[entry
].cStat
= 0;
527 entry
= (entry
+ 1) % TLAN_NUM_RX_LISTS
;
528 priv
->cur_rx
= entry
;
530 if ((rx_ring
[entry
].cStat
& TLAN_CSTAT_READY
) ==
532 ack
|= TLAN_HC_GO
| TLAN_HC_RT
;
533 host_cmd
= TLAN_HC_ACK
| ack
| 0x001C0000;
534 outl(host_cmd
, BASE
+ TLAN_HOST_CMD
);
537 host_cmd
= TLAN_HC_ACK
| ack
| (0x000C0000);
538 outl(host_cmd
, BASE
+ TLAN_HOST_CMD
);
540 DBG ( "AC: 0x%hX\n", inw(BASE
+ TLAN_CH_PARM
) );
541 DBG ( "PI-2: 0x%hX\n", inw(BASE
+ TLAN_HOST_INT
) );
544 return (1); /* initially as this is called to flush the input */
547 static void refill_rx(struct nic
*nic __unused
)
552 (priv
->cur_rx
- priv
->dirty_rx
+
553 TLAN_NUM_RX_LISTS
) % TLAN_NUM_RX_LISTS
> 0;
554 priv
->dirty_rx
= (priv
->dirty_rx
+ 1) % TLAN_NUM_RX_LISTS
) {
555 entry
= priv
->dirty_rx
% TLAN_NUM_TX_LISTS
;
556 rx_ring
[entry
].frameSize
= TLAN_MAX_FRAME_SIZE
;
557 rx_ring
[entry
].cStat
= TLAN_CSTAT_READY
;
562 /**************************************************************************
563 TRANSMIT - Transmit a frame
564 ***************************************************************************/
565 static void tlan_transmit(struct nic
*nic
, const char *d
, /* Destination */
566 unsigned int t
, /* Type */
567 unsigned int s
, /* size */
572 struct TLanList
*tail_list
;
573 struct TLanList
*head_list
;
579 u16 host_int
= inw(BASE
+ TLAN_HOST_INT
);
583 DBG ( "INT0-0x%hX\n", host_int
);
585 if (!priv
->phyOnline
) {
586 printf("TRANSMIT: %s PHY is not ready\n", priv
->nic_name
);
590 tail_list
= priv
->txList
+ priv
->txTail
;
592 if (tail_list
->cStat
!= TLAN_CSTAT_UNUSED
) {
593 printf("TRANSMIT: %s is busy (Head=%p Tail=%x)\n",
594 priv
->nic_name
, priv
->txList
, (unsigned int) priv
->txTail
);
595 tx_ring
[entry
].cStat
= TLAN_CSTAT_UNUSED
;
596 // priv->txBusyCount++;
600 tail_list
->forward
= 0;
602 tail_buffer
= txb
+ (priv
->txTail
* TLAN_MAX_FRAME_SIZE
);
604 /* send the packet to destination */
605 memcpy(tail_buffer
, d
, ETH_ALEN
);
606 memcpy(tail_buffer
+ ETH_ALEN
, nic
->node_addr
, ETH_ALEN
);
607 nstype
= htons((u16
) t
);
608 memcpy(tail_buffer
+ 2 * ETH_ALEN
, (u8
*) & nstype
, 2);
609 memcpy(tail_buffer
+ ETH_HLEN
, p
, s
);
614 tail_buffer
[s
++] = '\0';
616 /*=====================================================*/
618 * 0000 0000 0001 1100
619 * 0000 0000 0000 1100
620 * 0000 0000 0000 0011 = 0x0003
622 * 0000 0000 0000 0000 0000 0000 0000 0011
623 * 0000 0000 0000 1100 0000 0000 0000 0000 = 0x000C0000
626 * 0000 0000 0001 1100
627 * 0000 0000 0000 0100
628 * 0000 0000 0000 0001 = 0x0001
630 * 0000 0000 0000 0000 0000 0000 0000 0001
631 * 0000 0000 0000 0100 0000 0000 0000 0000 = 0x00040000
634 /* Setup the transmit descriptor */
635 tail_list
->frameSize
= (u16
) s
;
636 tail_list
->buffer
[0].count
= TLAN_LAST_BUFFER
| (u32
) s
;
637 tail_list
->buffer
[1].count
= 0;
638 tail_list
->buffer
[1].address
= 0;
640 tail_list
->cStat
= TLAN_CSTAT_READY
;
642 DBG ( "INT1-0x%hX\n", inw(BASE
+ TLAN_HOST_INT
) );
644 if (!priv
->txInProgress
) {
645 priv
->txInProgress
= 1;
646 outl(virt_to_le32desc(tail_list
), BASE
+ TLAN_CH_PARM
);
647 outl(TLAN_HC_GO
, BASE
+ TLAN_HOST_CMD
);
649 if (priv
->txTail
== 0) {
650 DBG ( "Out buffer\n" );
651 (priv
->txList
+ (TLAN_NUM_TX_LISTS
- 1))->forward
=
652 virt_to_le32desc(tail_list
);
654 DBG ( "Fix this \n" );
655 (priv
->txList
+ (priv
->txTail
- 1))->forward
=
656 virt_to_le32desc(tail_list
);
660 CIRC_INC(priv
->txTail
, TLAN_NUM_TX_LISTS
);
662 DBG ( "INT2-0x%hX\n", inw(BASE
+ TLAN_HOST_INT
) );
664 to
= currticks() + TX_TIME_OUT
;
665 while ((tail_list
->cStat
== TLAN_CSTAT_READY
) && currticks() < to
);
667 head_list
= priv
->txList
+ priv
->txHead
;
668 while (((tmpCStat
= head_list
->cStat
) & TLAN_CSTAT_FRM_CMP
)
671 if(tmpCStat
& TLAN_CSTAT_EOC
)
673 head_list
->cStat
= TLAN_CSTAT_UNUSED
;
674 CIRC_INC(priv
->txHead
, TLAN_NUM_TX_LISTS
);
675 head_list
= priv
->txList
+ priv
->txHead
;
679 printf("Incomplete TX Frame\n");
682 head_list
= priv
->txList
+ priv
->txHead
;
683 if ((head_list
->cStat
& TLAN_CSTAT_READY
) == TLAN_CSTAT_READY
) {
684 outl(virt_to_le32desc(head_list
), BASE
+ TLAN_CH_PARM
);
687 priv
->txInProgress
= 0;
691 host_cmd
= TLAN_HC_ACK
| ack
;
692 outl(host_cmd
, BASE
+ TLAN_HOST_CMD
);
695 if(priv
->tlanRev
< 0x30 ) {
697 head_list
= priv
->txList
+ priv
->txHead
;
698 if ((head_list
->cStat
& TLAN_CSTAT_READY
) == TLAN_CSTAT_READY
) {
699 outl(virt_to_le32desc(head_list
), BASE
+ TLAN_CH_PARM
);
702 priv
->txInProgress
= 0;
704 host_cmd
= TLAN_HC_ACK
| ack
| 0x00140000;
705 outl(host_cmd
, BASE
+ TLAN_HOST_CMD
);
709 if (currticks() >= to
) {
710 printf("TX Time Out");
714 /**************************************************************************
715 DISABLE - Turn off ethernet interface
716 ***************************************************************************/
717 static void tlan_disable ( struct nic
*nic __unused
) {
718 /* put the card in its initial state */
719 /* This function serves 3 purposes.
720 * This disables DMA and interrupts so we don't receive
721 * unexpected packets or interrupts from the card after
722 * etherboot has finished.
723 * This frees resources so etherboot may use
724 * this driver on another interface
725 * This allows etherboot to reinitialize the interface
726 * if something is something goes wrong.
729 outl(TLAN_HC_AD_RST
, BASE
+ TLAN_HOST_CMD
);
732 /**************************************************************************
733 IRQ - Enable, Disable, or Force interrupts
734 ***************************************************************************/
735 static void tlan_irq(struct nic
*nic __unused
, irq_action_t action __unused
)
747 static struct nic_operations tlan_operations
= {
748 .connect
= dummy_connect
,
750 .transmit
= tlan_transmit
,
755 static void TLan_SetMulticastList(struct nic
*nic
) {
760 tmp
= TLan_DioRead8(BASE
, TLAN_NET_CMD
);
761 TLan_DioWrite8(BASE
, TLAN_NET_CMD
, tmp
& ~TLAN_NET_CMD_CAF
);
764 for(i
= 0; i
< 3; i
++)
765 TLan_SetMac(nic
, i
+ 1, NULL
);
766 TLan_DioWrite32(BASE
, TLAN_HASH_1
, 0xFFFFFFFF);
767 TLan_DioWrite32(BASE
, TLAN_HASH_2
, 0xFFFFFFFF);
771 /**************************************************************************
772 PROBE - Look for an adapter, this routine's visible to the outside
773 ***************************************************************************/
775 #define board_found 1
777 static int tlan_probe ( struct nic
*nic
, struct pci_device
*pci
) {
783 if (pci
->ioaddr
== 0)
787 nic
->ioaddr
= pci
->ioaddr
;
791 /* Set nic as PCI bus master */
792 adjust_pci_device(pci
);
794 /* Point to private storage */
795 priv
= &TLanPrivateInfo
;
797 /* Figure out which chip we're dealing with */
800 while (tlan_pci_tbl
[i
].name
) {
801 if ((((u32
) pci
->device
<< 16) | pci
->vendor
) ==
802 (tlan_pci_tbl
[i
].id
.pci
& 0xffffffff)) {
809 priv
->vendor_id
= pci
->vendor
;
810 priv
->dev_id
= pci
->device
;
811 priv
->nic_name
= pci
->driver_name
;
815 for (i
= 0; i
< 6; i
++)
816 err
|= TLan_EeReadByte(BASE
,
817 (u8
) tlan_pci_tbl
[chip_idx
].
819 (u8
*) & nic
->node_addr
[i
]);
821 printf ( "TLAN: %s: Error reading MAC from eeprom: %d\n",
822 pci
->driver_name
, err
);
824 DBG ( "%s: %s at ioaddr %#lX, ",
825 pci
->driver_name
, eth_ntoa ( nic
->node_addr
), pci
->ioaddr
);
828 priv
->tlanRev
= TLan_DioRead8(BASE
, TLAN_DEF_REVISION
);
829 printf("revision: 0x%hX\n", priv
->tlanRev
);
831 TLan_ResetLists(nic
);
832 TLan_ResetAdapter(nic
);
834 data
= inl(BASE
+ TLAN_HOST_CMD
);
835 data
|= TLAN_HC_INT_OFF
;
836 outw(data
, BASE
+ TLAN_HOST_CMD
);
838 TLan_SetMulticastList(nic
);
840 priv
->txList
= tx_ring
;
842 /* if (board_found && valid_link)
844 /* point to NIC specific routines */
845 nic
->nic_op
= &tlan_operations
;
850 /*****************************************************************************
851 ******************************************************************************
853 ThunderLAN Driver Eeprom routines
855 The Compaq Netelligent 10 and 10/100 cards use a Microchip 24C02A
856 EEPROM. These functions are based on information in Microchip's
857 data sheet. I don't know how well this functions will work with
860 ******************************************************************************
861 *****************************************************************************/
864 /***************************************************************
870 * io_base The IO port base address for the
871 * TLAN device with the EEPROM to
874 * This function sends a start cycle to an EEPROM attached
877 **************************************************************/
879 void TLan_EeSendStart(u16 io_base
)
883 outw(TLAN_NET_SIO
, io_base
+ TLAN_DIO_ADR
);
884 sio
= io_base
+ TLAN_DIO_DATA
+ TLAN_NET_SIO
;
886 TLan_SetBit(TLAN_NET_SIO_ECLOK
, sio
);
887 TLan_SetBit(TLAN_NET_SIO_EDATA
, sio
);
888 TLan_SetBit(TLAN_NET_SIO_ETXEN
, sio
);
889 TLan_ClearBit(TLAN_NET_SIO_EDATA
, sio
);
890 TLan_ClearBit(TLAN_NET_SIO_ECLOK
, sio
);
892 } /* TLan_EeSendStart */
894 /***************************************************************
898 * If the correct ack was received, 0, otherwise 1
899 * Parms: io_base The IO port base address for the
900 * TLAN device with the EEPROM to
902 * data The 8 bits of information to
903 * send to the EEPROM.
904 * stop If TLAN_EEPROM_STOP is passed, a
905 * stop cycle is sent after the
906 * byte is sent after the ack is
909 * This function sends a byte on the serial EEPROM line,
910 * driving the clock to send each bit. The function then
911 * reverses transmission direction and reads an acknowledge
914 **************************************************************/
916 int TLan_EeSendByte(u16 io_base
, u8 data
, int stop
)
922 outw(TLAN_NET_SIO
, io_base
+ TLAN_DIO_ADR
);
923 sio
= io_base
+ TLAN_DIO_DATA
+ TLAN_NET_SIO
;
925 /* Assume clock is low, tx is enabled; */
926 for (place
= 0x80; place
!= 0; place
>>= 1) {
928 TLan_SetBit(TLAN_NET_SIO_EDATA
, sio
);
930 TLan_ClearBit(TLAN_NET_SIO_EDATA
, sio
);
931 TLan_SetBit(TLAN_NET_SIO_ECLOK
, sio
);
932 TLan_ClearBit(TLAN_NET_SIO_ECLOK
, sio
);
934 TLan_ClearBit(TLAN_NET_SIO_ETXEN
, sio
);
935 TLan_SetBit(TLAN_NET_SIO_ECLOK
, sio
);
936 err
= TLan_GetBit(TLAN_NET_SIO_EDATA
, sio
);
937 TLan_ClearBit(TLAN_NET_SIO_ECLOK
, sio
);
938 TLan_SetBit(TLAN_NET_SIO_ETXEN
, sio
);
940 if ((!err
) && stop
) {
941 TLan_ClearBit(TLAN_NET_SIO_EDATA
, sio
); /* STOP, raise data while clock is high */
942 TLan_SetBit(TLAN_NET_SIO_ECLOK
, sio
);
943 TLan_SetBit(TLAN_NET_SIO_EDATA
, sio
);
948 } /* TLan_EeSendByte */
950 /***************************************************************
956 * io_base The IO port base address for the
957 * TLAN device with the EEPROM to
959 * data An address to a char to hold the
960 * data sent from the EEPROM.
961 * stop If TLAN_EEPROM_STOP is passed, a
962 * stop cycle is sent after the
963 * byte is received, and no ack is
966 * This function receives 8 bits of data from the EEPROM
967 * over the serial link. It then sends and ack bit, or no
968 * ack and a stop bit. This function is used to retrieve
969 * data after the address of a byte in the EEPROM has been
972 **************************************************************/
974 void TLan_EeReceiveByte(u16 io_base
, u8
* data
, int stop
)
979 outw(TLAN_NET_SIO
, io_base
+ TLAN_DIO_ADR
);
980 sio
= io_base
+ TLAN_DIO_DATA
+ TLAN_NET_SIO
;
983 /* Assume clock is low, tx is enabled; */
984 TLan_ClearBit(TLAN_NET_SIO_ETXEN
, sio
);
985 for (place
= 0x80; place
; place
>>= 1) {
986 TLan_SetBit(TLAN_NET_SIO_ECLOK
, sio
);
987 if (TLan_GetBit(TLAN_NET_SIO_EDATA
, sio
))
989 TLan_ClearBit(TLAN_NET_SIO_ECLOK
, sio
);
992 TLan_SetBit(TLAN_NET_SIO_ETXEN
, sio
);
994 TLan_ClearBit(TLAN_NET_SIO_EDATA
, sio
); /* Ack = 0 */
995 TLan_SetBit(TLAN_NET_SIO_ECLOK
, sio
);
996 TLan_ClearBit(TLAN_NET_SIO_ECLOK
, sio
);
998 TLan_SetBit(TLAN_NET_SIO_EDATA
, sio
); /* No ack = 1 (?) */
999 TLan_SetBit(TLAN_NET_SIO_ECLOK
, sio
);
1000 TLan_ClearBit(TLAN_NET_SIO_ECLOK
, sio
);
1001 TLan_ClearBit(TLAN_NET_SIO_EDATA
, sio
); /* STOP, raise data while clock is high */
1002 TLan_SetBit(TLAN_NET_SIO_ECLOK
, sio
);
1003 TLan_SetBit(TLAN_NET_SIO_EDATA
, sio
);
1006 } /* TLan_EeReceiveByte */
1008 /***************************************************************
1012 * No error = 0, else, the stage at which the error
1015 * io_base The IO port base address for the
1016 * TLAN device with the EEPROM to
1018 * ee_addr The address of the byte in the
1019 * EEPROM whose contents are to be
1021 * data An address to a char to hold the
1022 * data obtained from the EEPROM.
1024 * This function reads a byte of information from an byte
1025 * cell in the EEPROM.
1027 **************************************************************/
1029 int TLan_EeReadByte(u16 io_base
, u8 ee_addr
, u8
* data
)
1035 TLan_EeSendStart(io_base
);
1036 err
= TLan_EeSendByte(io_base
, 0xA0, TLAN_EEPROM_ACK
);
1041 err
= TLan_EeSendByte(io_base
, ee_addr
, TLAN_EEPROM_ACK
);
1046 TLan_EeSendStart(io_base
);
1047 err
= TLan_EeSendByte(io_base
, 0xA1, TLAN_EEPROM_ACK
);
1052 TLan_EeReceiveByte(io_base
, data
, TLAN_EEPROM_STOP
);
1057 } /* TLan_EeReadByte */
1060 /*****************************************************************************
1061 ******************************************************************************
1063 ThunderLAN Driver MII Routines
1065 These routines are based on the information in Chap. 2 of the
1066 "ThunderLAN Programmer's Guide", pp. 15-24.
1068 ******************************************************************************
1069 *****************************************************************************/
1072 /***************************************************************
1076 * 0 if ack received ok
1080 * dev The device structure containing
1081 * The io address and interrupt count
1083 * phy The address of the PHY to be queried.
1084 * reg The register whose contents are to be
1086 * val A pointer to a variable to store the
1089 * This function uses the TLAN's MII bus to retreive the contents
1090 * of a given register on a PHY. It sends the appropriate info
1091 * and then reads the 16-bit register value from the MII bus via
1092 * the TLAN SIO register.
1094 **************************************************************/
1096 int TLan_MiiReadReg(struct nic
*nic __unused
, u16 phy
, u16 reg
, u16
* val
)
1105 outw(TLAN_NET_SIO
, BASE
+ TLAN_DIO_ADR
);
1106 sio
= BASE
+ TLAN_DIO_DATA
+ TLAN_NET_SIO
;
1110 minten
= TLan_GetBit(TLAN_NET_SIO_MINTEN
, sio
);
1112 TLan_ClearBit(TLAN_NET_SIO_MINTEN
, sio
);
1114 TLan_MiiSendData(BASE
, 0x1, 2); /* Start ( 01b ) */
1115 TLan_MiiSendData(BASE
, 0x2, 2); /* Read ( 10b ) */
1116 TLan_MiiSendData(BASE
, phy
, 5); /* Device # */
1117 TLan_MiiSendData(BASE
, reg
, 5); /* Register # */
1120 TLan_ClearBit(TLAN_NET_SIO_MTXEN
, sio
); /* Change direction */
1122 TLan_ClearBit(TLAN_NET_SIO_MCLK
, sio
); /* Clock Idle bit */
1123 TLan_SetBit(TLAN_NET_SIO_MCLK
, sio
);
1124 TLan_ClearBit(TLAN_NET_SIO_MCLK
, sio
); /* Wait 300ns */
1126 nack
= TLan_GetBit(TLAN_NET_SIO_MDATA
, sio
); /* Check for ACK */
1127 TLan_SetBit(TLAN_NET_SIO_MCLK
, sio
); /* Finish ACK */
1128 if (nack
) { /* No ACK, so fake it */
1129 for (i
= 0; i
< 16; i
++) {
1130 TLan_ClearBit(TLAN_NET_SIO_MCLK
, sio
);
1131 TLan_SetBit(TLAN_NET_SIO_MCLK
, sio
);
1135 } else { /* ACK, so read data */
1136 for (tmp
= 0, i
= 0x8000; i
; i
>>= 1) {
1137 TLan_ClearBit(TLAN_NET_SIO_MCLK
, sio
);
1138 if (TLan_GetBit(TLAN_NET_SIO_MDATA
, sio
))
1140 TLan_SetBit(TLAN_NET_SIO_MCLK
, sio
);
1145 TLan_ClearBit(TLAN_NET_SIO_MCLK
, sio
); /* Idle cycle */
1146 TLan_SetBit(TLAN_NET_SIO_MCLK
, sio
);
1149 TLan_SetBit(TLAN_NET_SIO_MINTEN
, sio
);
1155 } /* TLan_MiiReadReg */
1157 /***************************************************************
1163 * base_port The base IO port of the adapter in
1165 * dev The address of the PHY to be queried.
1166 * data The value to be placed on the MII bus.
1167 * num_bits The number of bits in data that are to
1168 * be placed on the MII bus.
1170 * This function sends on sequence of bits on the MII
1171 * configuration bus.
1173 **************************************************************/
1175 void TLan_MiiSendData(u16 base_port
, u32 data
, unsigned num_bits
)
1183 outw(TLAN_NET_SIO
, base_port
+ TLAN_DIO_ADR
);
1184 sio
= base_port
+ TLAN_DIO_DATA
+ TLAN_NET_SIO
;
1185 TLan_SetBit(TLAN_NET_SIO_MTXEN
, sio
);
1187 for (i
= (0x1 << (num_bits
- 1)); i
; i
>>= 1) {
1188 TLan_ClearBit(TLAN_NET_SIO_MCLK
, sio
);
1189 (void) TLan_GetBit(TLAN_NET_SIO_MCLK
, sio
);
1191 TLan_SetBit(TLAN_NET_SIO_MDATA
, sio
);
1193 TLan_ClearBit(TLAN_NET_SIO_MDATA
, sio
);
1194 TLan_SetBit(TLAN_NET_SIO_MCLK
, sio
);
1195 (void) TLan_GetBit(TLAN_NET_SIO_MCLK
, sio
);
1198 } /* TLan_MiiSendData */
1200 /***************************************************************
1206 * base_port The base IO port of the adapter in
1209 * This functions syncs all PHYs in terms of the MII configuration
1212 **************************************************************/
1214 void TLan_MiiSync(u16 base_port
)
1219 outw(TLAN_NET_SIO
, base_port
+ TLAN_DIO_ADR
);
1220 sio
= base_port
+ TLAN_DIO_DATA
+ TLAN_NET_SIO
;
1222 TLan_ClearBit(TLAN_NET_SIO_MTXEN
, sio
);
1223 for (i
= 0; i
< 32; i
++) {
1224 TLan_ClearBit(TLAN_NET_SIO_MCLK
, sio
);
1225 TLan_SetBit(TLAN_NET_SIO_MCLK
, sio
);
1228 } /* TLan_MiiSync */
1230 /***************************************************************
1236 * dev The device structure for the device
1238 * phy The address of the PHY to be written to.
1239 * reg The register whose contents are to be
1241 * val The value to be written to the register.
1243 * This function uses the TLAN's MII bus to write the contents of a
1244 * given register on a PHY. It sends the appropriate info and then
1245 * writes the 16-bit register value from the MII configuration bus
1246 * via the TLAN SIO register.
1248 **************************************************************/
1250 void TLan_MiiWriteReg(struct nic
*nic __unused
, u16 phy
, u16 reg
, u16 val
)
1255 outw(TLAN_NET_SIO
, BASE
+ TLAN_DIO_ADR
);
1256 sio
= BASE
+ TLAN_DIO_DATA
+ TLAN_NET_SIO
;
1260 minten
= TLan_GetBit(TLAN_NET_SIO_MINTEN
, sio
);
1262 TLan_ClearBit(TLAN_NET_SIO_MINTEN
, sio
);
1264 TLan_MiiSendData(BASE
, 0x1, 2); /* Start ( 01b ) */
1265 TLan_MiiSendData(BASE
, 0x1, 2); /* Write ( 01b ) */
1266 TLan_MiiSendData(BASE
, phy
, 5); /* Device # */
1267 TLan_MiiSendData(BASE
, reg
, 5); /* Register # */
1269 TLan_MiiSendData(BASE
, 0x2, 2); /* Send ACK */
1270 TLan_MiiSendData(BASE
, val
, 16); /* Send Data */
1272 TLan_ClearBit(TLAN_NET_SIO_MCLK
, sio
); /* Idle cycle */
1273 TLan_SetBit(TLAN_NET_SIO_MCLK
, sio
);
1276 TLan_SetBit(TLAN_NET_SIO_MINTEN
, sio
);
1279 } /* TLan_MiiWriteReg */
1281 /***************************************************************
1287 * dev Pointer to device structure of adapter
1288 * on which to change the AREG.
1289 * areg The AREG to set the address in (0 - 3).
1290 * mac A pointer to an array of chars. Each
1291 * element stores one byte of the address.
1292 * IE, it isn't in ascii.
1294 * This function transfers a MAC address to one of the
1295 * TLAN AREGs (address registers). The TLAN chip locks
1296 * the register on writing to offset 0 and unlocks the
1297 * register after writing to offset 5. If NULL is passed
1298 * in mac, then the AREG is filled with 0's.
1300 **************************************************************/
1302 void TLan_SetMac(struct nic
*nic __unused
, int areg
, unsigned char *mac
)
1309 for (i
= 0; i
< 6; i
++)
1310 TLan_DioWrite8(BASE
, TLAN_AREG_0
+ areg
+ i
,
1313 for (i
= 0; i
< 6; i
++)
1314 TLan_DioWrite8(BASE
, TLAN_AREG_0
+ areg
+ i
, 0);
1319 /*********************************************************************
1325 * dev A pointer to the device structure of the adapter
1326 * for which the PHY needs determined.
1328 * So far I've found that adapters which have external PHYs
1329 * may also use the internal PHY for part of the functionality.
1330 * (eg, AUI/Thinnet). This function finds out if this TLAN
1331 * chip has an internal PHY, and then finds the first external
1332 * PHY (starting from address 0) if it exists).
1334 ********************************************************************/
1336 void TLan_PhyDetect(struct nic
*nic
)
1343 if (tlan_pci_tbl
[chip_idx
].flags
& TLAN_ADAPTER_UNMANAGED_PHY
) {
1344 priv
->phyNum
= 0xFFFF;
1348 TLan_MiiReadReg(nic
, TLAN_PHY_MAX_ADDR
, MII_GEN_ID_HI
, &hi
);
1351 priv
->phy
[0] = TLAN_PHY_MAX_ADDR
;
1353 priv
->phy
[0] = TLAN_PHY_NONE
;
1356 priv
->phy
[1] = TLAN_PHY_NONE
;
1357 for (phy
= 0; phy
<= TLAN_PHY_MAX_ADDR
; phy
++) {
1358 TLan_MiiReadReg(nic
, phy
, MII_GEN_CTL
, &control
);
1359 TLan_MiiReadReg(nic
, phy
, MII_GEN_ID_HI
, &hi
);
1360 TLan_MiiReadReg(nic
, phy
, MII_GEN_ID_LO
, &lo
);
1361 if ((control
!= 0xFFFF) || (hi
!= 0xFFFF)
1362 || (lo
!= 0xFFFF)) {
1363 printf("PHY found at %hX %hX %hX %hX\n",
1364 (unsigned int) phy
, control
, hi
, lo
);
1365 if ((priv
->phy
[1] == TLAN_PHY_NONE
)
1366 && (phy
!= TLAN_PHY_MAX_ADDR
)) {
1372 if (priv
->phy
[1] != TLAN_PHY_NONE
) {
1374 } else if (priv
->phy
[0] != TLAN_PHY_NONE
) {
1378 ("TLAN: Cannot initialize device, no PHY was found!\n");
1381 } /* TLan_PhyDetect */
1383 void TLan_PhyPowerDown(struct nic
*nic
)
1387 DBG ( "%s: Powering down PHY(s).\n", priv
->nic_name
);
1388 value
= MII_GC_PDOWN
| MII_GC_LOOPBK
| MII_GC_ISOLATE
;
1390 TLan_MiiWriteReg(nic
, priv
->phy
[priv
->phyNum
], MII_GEN_CTL
, value
);
1391 if ((priv
->phyNum
== 0) && (priv
->phy
[1] != TLAN_PHY_NONE
)
1393 (!(tlan_pci_tbl
[chip_idx
].
1394 flags
& TLAN_ADAPTER_USE_INTERN_10
))) {
1396 TLan_MiiWriteReg(nic
, priv
->phy
[1], MII_GEN_CTL
, value
);
1399 /* Wait for 50 ms and powerup
1400 * This is abitrary. It is intended to make sure the
1401 * tranceiver settles.
1403 /* TLan_SetTimer( dev, (HZ/20), TLAN_TIMER_PHY_PUP ); */
1405 TLan_PhyPowerUp(nic
);
1407 } /* TLan_PhyPowerDown */
1410 void TLan_PhyPowerUp(struct nic
*nic
)
1414 DBG ( "%s: Powering up PHY.\n", priv
->nic_name
);
1416 value
= MII_GC_LOOPBK
;
1417 TLan_MiiWriteReg(nic
, priv
->phy
[priv
->phyNum
], MII_GEN_CTL
, value
);
1419 /* Wait for 500 ms and reset the
1420 * tranceiver. The TLAN docs say both 50 ms and
1421 * 500 ms, so do the longer, just in case.
1425 /* TLan_SetTimer( dev, (HZ/20), TLAN_TIMER_PHY_RESET ); */
1427 } /* TLan_PhyPowerUp */
1429 void TLan_PhyReset(struct nic
*nic
)
1434 phy
= priv
->phy
[priv
->phyNum
];
1436 DBG ( "%s: Reseting PHY.\n", priv
->nic_name
);
1438 value
= MII_GC_LOOPBK
| MII_GC_RESET
;
1439 TLan_MiiWriteReg(nic
, phy
, MII_GEN_CTL
, value
);
1440 TLan_MiiReadReg(nic
, phy
, MII_GEN_CTL
, &value
);
1441 while (value
& MII_GC_RESET
) {
1442 TLan_MiiReadReg(nic
, phy
, MII_GEN_CTL
, &value
);
1445 /* Wait for 500 ms and initialize.
1446 * I don't remember why I wait this long.
1447 * I've changed this to 50ms, as it seems long enough.
1449 /* TLan_SetTimer( dev, (HZ/20), TLAN_TIMER_PHY_START_LINK ); */
1451 TLan_PhyStartLink(nic
);
1453 } /* TLan_PhyReset */
1456 void TLan_PhyStartLink(struct nic
*nic
)
1466 phy
= priv
->phy
[priv
->phyNum
];
1467 DBG ( "%s: Trying to activate link.\n", priv
->nic_name
);
1468 TLan_MiiReadReg(nic
, phy
, MII_GEN_STS
, &status
);
1469 TLan_MiiReadReg(nic
, phy
, MII_GEN_STS
, &ability
);
1471 if ((status
& MII_GS_AUTONEG
) && (!priv
->aui
)) {
1472 ability
= status
>> 11;
1473 if (priv
->speed
== TLAN_SPEED_10
&&
1474 priv
->duplex
== TLAN_DUPLEX_HALF
) {
1475 TLan_MiiWriteReg(nic
, phy
, MII_GEN_CTL
, 0x0000);
1476 } else if (priv
->speed
== TLAN_SPEED_10
&&
1477 priv
->duplex
== TLAN_DUPLEX_FULL
) {
1478 priv
->tlanFullDuplex
= TRUE
;
1479 TLan_MiiWriteReg(nic
, phy
, MII_GEN_CTL
, 0x0100);
1480 } else if (priv
->speed
== TLAN_SPEED_100
&&
1481 priv
->duplex
== TLAN_DUPLEX_HALF
) {
1482 TLan_MiiWriteReg(nic
, phy
, MII_GEN_CTL
, 0x2000);
1483 } else if (priv
->speed
== TLAN_SPEED_100
&&
1484 priv
->duplex
== TLAN_DUPLEX_FULL
) {
1485 priv
->tlanFullDuplex
= TRUE
;
1486 TLan_MiiWriteReg(nic
, phy
, MII_GEN_CTL
, 0x2100);
1489 /* Set Auto-Neg advertisement */
1490 TLan_MiiWriteReg(nic
, phy
, MII_AN_ADV
,
1491 (ability
<< 5) | 1);
1492 /* Enablee Auto-Neg */
1493 TLan_MiiWriteReg(nic
, phy
, MII_GEN_CTL
, 0x1000);
1494 /* Restart Auto-Neg */
1495 TLan_MiiWriteReg(nic
, phy
, MII_GEN_CTL
, 0x1200);
1496 /* Wait for 4 sec for autonegotiation
1497 * to complete. The max spec time is less than this
1498 * but the card need additional time to start AN.
1499 * .5 sec should be plenty extra.
1501 DBG ( "TLAN: %s: Starting autonegotiation.\n",
1504 TLan_PhyFinishAutoNeg(nic
);
1505 /* TLan_SetTimer( dev, (2*HZ), TLAN_TIMER_PHY_FINISH_AN ); */
1511 if ((priv
->aui
) && (priv
->phyNum
!= 0)) {
1514 TLAN_NET_CFG_1FRAG
| TLAN_NET_CFG_1CHAN
|
1515 TLAN_NET_CFG_PHY_EN
;
1516 TLan_DioWrite16(BASE
, TLAN_NET_CONFIG
, data
);
1518 /* TLan_SetTimer( dev, (40*HZ/1000), TLAN_TIMER_PHY_PDOWN ); */
1519 TLan_PhyPowerDown(nic
);
1521 } else if (priv
->phyNum
== 0) {
1523 TLan_MiiReadReg(nic
, phy
, TLAN_TLPHY_CTL
, &tctl
);
1525 tctl
|= TLAN_TC_AUISEL
;
1527 tctl
&= ~TLAN_TC_AUISEL
;
1528 if (priv
->duplex
== TLAN_DUPLEX_FULL
) {
1529 control
|= MII_GC_DUPLEX
;
1530 priv
->tlanFullDuplex
= TRUE
;
1532 if (priv
->speed
== TLAN_SPEED_100
) {
1533 control
|= MII_GC_SPEEDSEL
;
1536 TLan_MiiWriteReg(nic
, phy
, MII_GEN_CTL
, control
);
1537 TLan_MiiWriteReg(nic
, phy
, TLAN_TLPHY_CTL
, tctl
);
1540 /* Wait for 2 sec to give the tranceiver time
1541 * to establish link.
1543 /* TLan_SetTimer( dev, (4*HZ), TLAN_TIMER_FINISH_RESET ); */
1545 TLan_FinishReset(nic
);
1547 } /* TLan_PhyStartLink */
1549 void TLan_PhyFinishAutoNeg(struct nic
*nic
)
1559 phy
= priv
->phy
[priv
->phyNum
];
1561 TLan_MiiReadReg(nic
, phy
, MII_GEN_STS
, &status
);
1563 TLan_MiiReadReg(nic
, phy
, MII_GEN_STS
, &status
);
1565 if (!(status
& MII_GS_AUTOCMPLT
)) {
1566 /* Wait for 8 sec to give the process
1567 * more time. Perhaps we should fail after a while.
1569 if (!priv
->neg_be_verbose
++) {
1571 ("TLAN: Giving autonegotiation more time.\n");
1573 ("TLAN: Please check that your adapter has\n");
1575 ("TLAN: been properly connected to a HUB or Switch.\n");
1577 ("TLAN: Trying to establish link in the background...\n");
1580 TLan_PhyFinishAutoNeg(nic
);
1581 /* TLan_SetTimer( dev, (8*HZ), TLAN_TIMER_PHY_FINISH_AN ); */
1585 DBG ( "TLAN: %s: Autonegotiation complete.\n", priv
->nic_name
);
1586 TLan_MiiReadReg(nic
, phy
, MII_AN_ADV
, &an_adv
);
1587 TLan_MiiReadReg(nic
, phy
, MII_AN_LPA
, &an_lpa
);
1588 mode
= an_adv
& an_lpa
& 0x03E0;
1589 if (mode
& 0x0100) {
1590 printf("Full Duplex\n");
1591 priv
->tlanFullDuplex
= TRUE
;
1592 } else if (!(mode
& 0x0080) && (mode
& 0x0040)) {
1593 priv
->tlanFullDuplex
= TRUE
;
1594 printf("Full Duplex\n");
1597 if ((!(mode
& 0x0180))
1598 && (tlan_pci_tbl
[chip_idx
].flags
& TLAN_ADAPTER_USE_INTERN_10
)
1599 && (priv
->phyNum
!= 0)) {
1602 TLAN_NET_CFG_1FRAG
| TLAN_NET_CFG_1CHAN
|
1603 TLAN_NET_CFG_PHY_EN
;
1604 TLan_DioWrite16(BASE
, TLAN_NET_CONFIG
, data
);
1605 /* TLan_SetTimer( nic, (400*HZ/1000), TLAN_TIMER_PHY_PDOWN ); */
1607 TLan_PhyPowerDown(nic
);
1611 if (priv
->phyNum
== 0) {
1612 if ((priv
->duplex
== TLAN_DUPLEX_FULL
)
1613 || (an_adv
& an_lpa
& 0x0040)) {
1614 TLan_MiiWriteReg(nic
, phy
, MII_GEN_CTL
,
1615 MII_GC_AUTOENB
| MII_GC_DUPLEX
);
1617 ( "TLAN: Starting internal PHY with FULL-DUPLEX\n" );
1619 TLan_MiiWriteReg(nic
, phy
, MII_GEN_CTL
,
1622 ( "TLAN: Starting internal PHY with HALF-DUPLEX\n" );
1626 /* Wait for 100 ms. No reason in partiticular.
1628 /* TLan_SetTimer( dev, (HZ/10), TLAN_TIMER_FINISH_RESET ); */
1630 TLan_FinishReset(nic
);
1632 } /* TLan_PhyFinishAutoNeg */
1636 /*********************************************************************
1644 * dev The device structure of this device.
1647 * This function monitors PHY condition by reading the status
1648 * register via the MII bus. This can be used to give info
1649 * about link changes (up/down), and possible switch to alternate
1652 ********************************************************************/
1654 void TLan_PhyMonitor(struct net_device
*dev
)
1656 TLanPrivateInfo
*priv
= dev
->priv
;
1660 phy
= priv
->phy
[priv
->phyNum
];
1662 /* Get PHY status register */
1663 TLan_MiiReadReg(nic
, phy
, MII_GEN_STS
, &phy_status
);
1665 /* Check if link has been lost */
1666 if (!(phy_status
& MII_GS_LINK
)) {
1669 printf("TLAN: %s has lost link\n", priv
->nic_name
);
1670 priv
->flags
&= ~IFF_RUNNING
;
1672 TLan_PhyMonitor(nic
);
1673 /* TLan_SetTimer( dev, (2*HZ), TLAN_TIMER_LINK_BEAT ); */
1678 /* Link restablished? */
1679 if ((phy_status
& MII_GS_LINK
) && !priv
->link
) {
1681 printf("TLAN: %s has reestablished link\n",
1683 priv
->flags
|= IFF_RUNNING
;
1686 /* Setup a new monitor */
1687 /* TLan_SetTimer( dev, (2*HZ), TLAN_TIMER_LINK_BEAT ); */
1689 TLan_PhyMonitor(nic
);
1692 #endif /* MONITOR */
1694 static struct pci_device_id tlan_nics
[] = {
1695 PCI_ROM(0x0e11, 0xae34, "netel10", "Compaq Netelligent 10 T PCI UTP"),
1696 PCI_ROM(0x0e11, 0xae32, "netel100","Compaq Netelligent 10/100 TX PCI UTP"),
1697 PCI_ROM(0x0e11, 0xae35, "netflex3i", "Compaq Integrated NetFlex-3/P"),
1698 PCI_ROM(0x0e11, 0xf130, "thunder", "Compaq NetFlex-3/P"),
1699 PCI_ROM(0x0e11, 0xf150, "netflex3b", "Compaq NetFlex-3/P"),
1700 PCI_ROM(0x0e11, 0xae43, "netel100pi", "Compaq Netelligent Integrated 10/100 TX UTP"),
1701 PCI_ROM(0x0e11, 0xae40, "netel100d", "Compaq Netelligent Dual 10/100 TX PCI UTP"),
1702 PCI_ROM(0x0e11, 0xb011, "netel100i", "Compaq Netelligent 10/100 TX Embedded UTP"),
1703 PCI_ROM(0x108d, 0x0013, "oc2183", "Olicom OC-2183/2185"),
1704 PCI_ROM(0x108d, 0x0012, "oc2325", "Olicom OC-2325"),
1705 PCI_ROM(0x108d, 0x0014, "oc2326", "Olicom OC-2326"),
1706 PCI_ROM(0x0e11, 0xb030, "netelligent_10_100_ws_5100", "Compaq Netelligent 10/100 TX UTP"),
1707 PCI_ROM(0x0e11, 0xb012, "netelligent_10_t2", "Compaq Netelligent 10 T/2 PCI UTP/Coax"),
1710 PCI_DRIVER ( tlan_driver
, tlan_nics
, PCI_NO_CLASS
);
1712 DRIVER ( "TLAN/PCI", nic_driver
, pci_driver
, tlan_driver
,
1713 tlan_probe
, tlan_disable
);