Remove *_fill_nic() calls, and directly set nic->ioaddr and nic->irqno .
[gpxe.git] / src / drivers / net / tlan.c
blob60ca182e68170fb151151b712f5db585f097031d
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:
23 * by James Banks
25 * (C) 1997-1998 Caldera, Inc.
26 * (C) 1998 James Banks
27 * (C) 1999-2001 Torben Mathiasen
28 * (C) 2002 Samuel Chessman
30 * REVISION HISTORY:
31 * ================
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"
42 #include "nic.h"
43 #include <gpxe/pci.h>
44 #include <gpxe/ethernet.h>
45 #include "timer.h"
46 #include "tlan.h"
48 #define drv_version "v1.4"
49 #define drv_date "01-17-2004"
51 /* NIC specific static variables go here */
52 #define HZ 100
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);
79 #ifdef MONITOR
80 static void TLan_PhyMonitor(struct nic *nic);
81 #endif
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[]! */
98 enum tlan_nics {
99 NETEL10 = 0, NETEL100 = 1, NETFLEX3I = 2, THUNDER = 3, NETFLEX3B =
100 4, NETEL100PI = 5,
101 NETEL100D = 6, NETEL100I = 7, OC2183 = 8, OC2325 = 9, OC2326 =
102 10, NETELLIGENT_10_100_WS_5100 = 11,
103 NETELLIGENT_10_T2 = 12
106 struct pci_id_info {
107 const char *name;
108 int nic_id;
109 struct match_info {
110 u32 pci, pci_mask, subsystem, subsystem_mask;
111 u32 revision, revision_mask; /* Only 8 bits. */
112 } id;
113 u32 flags;
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 */
158 {0, 0, 0, 0, 0, 0},
159 TLAN_ADAPTER_ACTIVITY_LED | TLAN_ADAPTER_UNMANAGED_PHY |
160 TLAN_ADAPTER_BIT_RATE_PHY, 0x83},
161 {"Compaq NetFlex-3/E", 0, /* EISA card */
162 {0, 0, 0, 0, 0, 0},
163 TLAN_ADAPTER_ACTIVITY_LED, 0x83},
164 {0, 0,
165 {0, 0, 0, 0, 0, 0},
166 0, 0},
169 struct TLanList {
170 u32 forward;
171 u16 cStat;
172 u16 frameSize;
173 struct {
174 u32 count;
175 u32 address;
176 } buffer[TLAN_BUFFERS_PER_LIST];
179 struct {
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];
192 static int chip_idx;
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;
205 u32 txHead;
206 u32 txInProgress;
207 u32 txTail;
208 int eoc;
209 u32 phyOnline;
210 u32 aui;
211 u32 duplex;
212 u32 phy[2];
213 u32 phyNum;
214 u32 speed;
215 u8 tlanRev;
216 u8 tlanFullDuplex;
217 u8 link;
218 u8 neg_be_verbose;
219 } TLanPrivateInfo;
221 static struct tlan_private *priv;
223 static u32 BASE;
225 /***************************************************************
226 * TLan_ResetLists
228 * Returns:
229 * Nothing
230 * Parms:
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)
242 int i;
243 struct TLanList *list;
244 priv->txHead = 0;
245 priv->txTail = 0;
247 for (i = 0; i < TLAN_NUM_TX_LISTS; i++) {
248 list = &tx_ring[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;
257 priv->cur_rx = 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 /***************************************************************
281 * TLan_Reset
283 * Returns:
285 * Parms:
286 * dev Pointer to device structure of adapter
287 * to be reset.
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
293 * have been made.
295 **************************************************************/
297 void TLan_ResetAdapter(struct nic *nic __unused)
299 int i;
300 u32 addr;
301 u32 data;
302 u8 data8;
304 priv->tlanFullDuplex = FALSE;
305 priv->phyOnline = 0;
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);
312 udelay(1000);
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. */
327 data =
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);
348 TLan_PhyDetect(nic);
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;
358 } else {
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);
370 } else {
371 TLan_PhyPowerDown(nic);
374 } /* TLan_ResetAdapter */
376 void TLan_FinishReset(struct nic *nic)
379 u8 data;
380 u32 phy;
381 u8 sio;
382 u16 status;
383 u16 partner;
384 u16 tlphy_ctl;
385 u16 tlphy_par;
386 u16 tlphy_id1, tlphy_id2;
387 int i;
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)
406 || (priv->aui)) {
407 status = MII_GS_LINK;
408 DBG ( "TLAN: %s: Link forced.\n", priv->nic_name );
409 } else {
410 TLan_MiiReadReg(nic, phy, MII_GEN_STS, &status);
411 udelay(1000);
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,
418 &tlphy_par);
420 DBG ( "TLAN: %s: Link active with ",
421 priv->nic_name );
422 if (!(tlphy_par & TLAN_PHY_AN_EN_STAT)) {
423 DBG ( "forced 10%sMbps %s-Duplex\n",
424 tlphy_par & TLAN_PHY_SPEED_100 ? ""
425 : "0",
426 tlphy_par & TLAN_PHY_DUPLEX_FULL ?
427 "Full" : "Half" );
428 } else {
429 DBG
430 ( "AutoNegotiation enabled, at 10%sMbps %s-Duplex\n",
431 tlphy_par & TLAN_PHY_SPEED_100 ? "" :
432 "0",
433 tlphy_par & TLAN_PHY_DUPLEX_FULL ?
434 "Full" : "Half" );
435 DBG ( "TLAN: Partner capability: " );
436 for (i = 5; i <= 10; i++)
437 if (partner & (1 << i)) {
438 DBG ( "%s", media[i - 5] );
440 DBG ( "\n" );
443 TLan_DioWrite8(BASE, TLAN_LED_REG, TLAN_LED_LINK);
444 #ifdef MONITOR
445 /* We have link beat..for now anyway */
446 priv->link = 1;
447 /*Enabling link beat monitoring */
448 /* TLan_SetTimer( nic, (10*HZ), TLAN_TIMER_LINK_BEAT ); */
449 mdelay(10000);
450 TLan_PhyMonitor(nic);
451 #endif
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);
469 priv->phyOnline = 1;
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);
473 } else {
474 DBG
475 ( "TLAN: %s: Link inactive, will retry in 10 secs...\n",
476 priv->nic_name );
477 /* TLan_SetTimer( nic, (10*HZ), TLAN_TIMER_FINISH_RESET ); */
478 mdelay(10000);
479 TLan_FinishReset(nic);
480 return;
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 */
494 u32 framesize;
495 u32 host_cmd = 0;
496 u32 ack = 1;
497 int eoc = 0;
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)
503 return 1;
505 outw(host_int, BASE + TLAN_HOST_INT);
507 if (!(tmpCStat & TLAN_CSTAT_FRM_CMP))
508 return 0;
510 /* printf("PI-1: 0x%hX\n", host_int); */
511 if (tmpCStat & TLAN_CSTAT_EOC)
512 eoc = 1;
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;
525 DBG ( "%d", entry );
527 entry = (entry + 1) % TLAN_NUM_RX_LISTS;
528 priv->cur_rx = entry;
529 if (eoc) {
530 if ((rx_ring[entry].cStat & TLAN_CSTAT_READY) ==
531 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);
536 } else {
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) );
543 refill_rx(nic);
544 return (1); /* initially as this is called to flush the input */
547 static void refill_rx(struct nic *nic __unused)
549 int entry = 0;
551 for (;
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 */
568 const char *p)
569 { /* Packet */
570 u16 nstype;
571 u32 to;
572 struct TLanList *tail_list;
573 struct TLanList *head_list;
574 u8 *tail_buffer;
575 u32 ack = 0;
576 u32 host_cmd;
577 int eoc = 0;
578 u16 tmpCStat;
579 u16 host_int = inw(BASE + TLAN_HOST_INT);
581 int entry = 0;
583 DBG ( "INT0-0x%hX\n", host_int );
585 if (!priv->phyOnline) {
586 printf("TRANSMIT: %s PHY is not ready\n", priv->nic_name);
587 return;
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++;
597 return;
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);
611 s += ETH_HLEN;
612 s &= 0x0FFF;
613 while (s < ETH_ZLEN)
614 tail_buffer[s++] = '\0';
616 /*=====================================================*/
617 /* Receive
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
625 * Transmit
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
632 * */
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);
648 } else {
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);
653 } else {
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)
669 && (ack < 255)) {
670 ack++;
671 if(tmpCStat & TLAN_CSTAT_EOC)
672 eoc =1;
673 head_list->cStat = TLAN_CSTAT_UNUSED;
674 CIRC_INC(priv->txHead, TLAN_NUM_TX_LISTS);
675 head_list = priv->txList + priv->txHead;
678 if(!ack)
679 printf("Incomplete TX Frame\n");
681 if(eoc) {
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);
685 ack |= TLAN_HC_GO;
686 } else {
687 priv->txInProgress = 0;
690 if(ack) {
691 host_cmd = TLAN_HC_ACK | ack;
692 outl(host_cmd, BASE + TLAN_HOST_CMD);
695 if(priv->tlanRev < 0x30 ) {
696 ack = 1;
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);
700 ack |= TLAN_HC_GO;
701 } else {
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)
737 switch ( action ) {
738 case DISABLE :
739 break;
740 case ENABLE :
741 break;
742 case FORCE :
743 break;
747 static struct nic_operations tlan_operations = {
748 .connect = dummy_connect,
749 .poll = tlan_poll,
750 .transmit = tlan_transmit,
751 .irq = tlan_irq,
755 static void TLan_SetMulticastList(struct nic *nic) {
756 int i;
757 u8 tmp;
759 /* !IFF_PROMISC */
760 tmp = TLan_DioRead8(BASE, TLAN_NET_CMD);
761 TLan_DioWrite8(BASE, TLAN_NET_CMD, tmp & ~TLAN_NET_CMD_CAF);
763 /* IFF_ALLMULTI */
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
776 #define valid_link 0
777 static int tlan_probe ( struct nic *nic, struct pci_device *pci ) {
779 u16 data = 0;
780 int err;
781 int i;
783 if (pci->ioaddr == 0)
784 return 0;
786 nic->irqno = 0;
787 nic->ioaddr = pci->ioaddr;
789 BASE = 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 */
798 i = 0;
799 chip_idx = -1;
800 while (tlan_pci_tbl[i].name) {
801 if ((((u32) pci->device << 16) | pci->vendor) ==
802 (tlan_pci_tbl[i].id.pci & 0xffffffff)) {
803 chip_idx = i;
804 break;
806 i++;
809 priv->vendor_id = pci->vendor;
810 priv->dev_id = pci->device;
811 priv->nic_name = pci->driver_name;
812 priv->eoc = 0;
814 err = 0;
815 for (i = 0; i < 6; i++)
816 err |= TLan_EeReadByte(BASE,
817 (u8) tlan_pci_tbl[chip_idx].
818 addrOfs + i,
819 (u8 *) & nic->node_addr[i]);
820 if (err) {
821 printf ( "TLAN: %s: Error reading MAC from eeprom: %d\n",
822 pci->driver_name, err);
823 } else {
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);
839 udelay(100);
840 priv->txList = tx_ring;
842 /* if (board_found && valid_link)
844 /* point to NIC specific routines */
845 nic->nic_op = &tlan_operations;
846 return 1;
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
858 other EEPROMs.
860 ******************************************************************************
861 *****************************************************************************/
864 /***************************************************************
865 * TLan_EeSendStart
867 * Returns:
868 * Nothing
869 * Parms:
870 * io_base The IO port base address for the
871 * TLAN device with the EEPROM to
872 * use.
874 * This function sends a start cycle to an EEPROM attached
875 * to a TLAN chip.
877 **************************************************************/
879 void TLan_EeSendStart(u16 io_base)
881 u16 sio;
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 /***************************************************************
895 * TLan_EeSendByte
897 * Returns:
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
901 * use.
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
907 * read.
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
912 * bit.
914 **************************************************************/
916 int TLan_EeSendByte(u16 io_base, u8 data, int stop)
918 int err;
919 u8 place;
920 u16 sio;
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) {
927 if (place & data)
928 TLan_SetBit(TLAN_NET_SIO_EDATA, sio);
929 else
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);
946 return (err);
948 } /* TLan_EeSendByte */
950 /***************************************************************
951 * TLan_EeReceiveByte
953 * Returns:
954 * Nothing
955 * Parms:
956 * io_base The IO port base address for the
957 * TLAN device with the EEPROM to
958 * use.
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
964 * sent.
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
970 * sent.
972 **************************************************************/
974 void TLan_EeReceiveByte(u16 io_base, u8 * data, int stop)
976 u8 place;
977 u16 sio;
979 outw(TLAN_NET_SIO, io_base + TLAN_DIO_ADR);
980 sio = io_base + TLAN_DIO_DATA + TLAN_NET_SIO;
981 *data = 0;
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))
988 *data |= place;
989 TLan_ClearBit(TLAN_NET_SIO_ECLOK, sio);
992 TLan_SetBit(TLAN_NET_SIO_ETXEN, sio);
993 if (!stop) {
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);
997 } else {
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 /***************************************************************
1009 * TLan_EeReadByte
1011 * Returns:
1012 * No error = 0, else, the stage at which the error
1013 * occurred.
1014 * Parms:
1015 * io_base The IO port base address for the
1016 * TLAN device with the EEPROM to
1017 * use.
1018 * ee_addr The address of the byte in the
1019 * EEPROM whose contents are to be
1020 * retrieved.
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)
1031 int err;
1032 int ret = 0;
1035 TLan_EeSendStart(io_base);
1036 err = TLan_EeSendByte(io_base, 0xA0, TLAN_EEPROM_ACK);
1037 if (err) {
1038 ret = 1;
1039 goto fail;
1041 err = TLan_EeSendByte(io_base, ee_addr, TLAN_EEPROM_ACK);
1042 if (err) {
1043 ret = 2;
1044 goto fail;
1046 TLan_EeSendStart(io_base);
1047 err = TLan_EeSendByte(io_base, 0xA1, TLAN_EEPROM_ACK);
1048 if (err) {
1049 ret = 3;
1050 goto fail;
1052 TLan_EeReceiveByte(io_base, data, TLAN_EEPROM_STOP);
1053 fail:
1055 return ret;
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 /***************************************************************
1073 * TLan_MiiReadReg
1075 * Returns:
1076 * 0 if ack received ok
1077 * 1 otherwise.
1079 * Parms:
1080 * dev The device structure containing
1081 * The io address and interrupt count
1082 * for this device.
1083 * phy The address of the PHY to be queried.
1084 * reg The register whose contents are to be
1085 * retreived.
1086 * val A pointer to a variable to store the
1087 * retrieved value.
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)
1098 u8 nack;
1099 u16 sio, tmp;
1100 u32 i;
1101 int err;
1102 int minten;
1104 err = FALSE;
1105 outw(TLAN_NET_SIO, BASE + TLAN_DIO_ADR);
1106 sio = BASE + TLAN_DIO_DATA + TLAN_NET_SIO;
1108 TLan_MiiSync(BASE);
1110 minten = TLan_GetBit(TLAN_NET_SIO_MINTEN, sio);
1111 if (minten)
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);
1133 tmp = 0xffff;
1134 err = TRUE;
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))
1139 tmp |= i;
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);
1148 if (minten)
1149 TLan_SetBit(TLAN_NET_SIO_MINTEN, sio);
1151 *val = tmp;
1153 return err;
1155 } /* TLan_MiiReadReg */
1157 /***************************************************************
1158 * TLan_MiiSendData
1160 * Returns:
1161 * Nothing
1162 * Parms:
1163 * base_port The base IO port of the adapter in
1164 * question.
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)
1177 u16 sio;
1178 u32 i;
1180 if (num_bits == 0)
1181 return;
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);
1190 if (data & i)
1191 TLan_SetBit(TLAN_NET_SIO_MDATA, sio);
1192 else
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 /***************************************************************
1201 * TLan_MiiSync
1203 * Returns:
1204 * Nothing
1205 * Parms:
1206 * base_port The base IO port of the adapter in
1207 * question.
1209 * This functions syncs all PHYs in terms of the MII configuration
1210 * bus.
1212 **************************************************************/
1214 void TLan_MiiSync(u16 base_port)
1216 int i;
1217 u16 sio;
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 /***************************************************************
1231 * TLan_MiiWriteReg
1233 * Returns:
1234 * Nothing
1235 * Parms:
1236 * dev The device structure for the device
1237 * to write to.
1238 * phy The address of the PHY to be written to.
1239 * reg The register whose contents are to be
1240 * written.
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)
1252 u16 sio;
1253 int minten;
1255 outw(TLAN_NET_SIO, BASE + TLAN_DIO_ADR);
1256 sio = BASE + TLAN_DIO_DATA + TLAN_NET_SIO;
1258 TLan_MiiSync(BASE);
1260 minten = TLan_GetBit(TLAN_NET_SIO_MINTEN, sio);
1261 if (minten)
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);
1275 if (minten)
1276 TLan_SetBit(TLAN_NET_SIO_MINTEN, sio);
1279 } /* TLan_MiiWriteReg */
1281 /***************************************************************
1282 * TLan_SetMac
1284 * Returns:
1285 * Nothing
1286 * Parms:
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)
1304 int i;
1306 areg *= 6;
1308 if (mac != NULL) {
1309 for (i = 0; i < 6; i++)
1310 TLan_DioWrite8(BASE, TLAN_AREG_0 + areg + i,
1311 mac[i]);
1312 } else {
1313 for (i = 0; i < 6; i++)
1314 TLan_DioWrite8(BASE, TLAN_AREG_0 + areg + i, 0);
1317 } /* TLan_SetMac */
1319 /*********************************************************************
1320 * TLan_PhyDetect
1322 * Returns:
1323 * Nothing
1324 * Parms:
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)
1338 u16 control;
1339 u16 hi;
1340 u16 lo;
1341 u32 phy;
1343 if (tlan_pci_tbl[chip_idx].flags & TLAN_ADAPTER_UNMANAGED_PHY) {
1344 priv->phyNum = 0xFFFF;
1345 return;
1348 TLan_MiiReadReg(nic, TLAN_PHY_MAX_ADDR, MII_GEN_ID_HI, &hi);
1350 if (hi != 0xFFFF) {
1351 priv->phy[0] = TLAN_PHY_MAX_ADDR;
1352 } else {
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)) {
1367 priv->phy[1] = phy;
1372 if (priv->phy[1] != TLAN_PHY_NONE) {
1373 priv->phyNum = 1;
1374 } else if (priv->phy[0] != TLAN_PHY_NONE) {
1375 priv->phyNum = 0;
1376 } else {
1377 printf
1378 ("TLAN: Cannot initialize device, no PHY was found!\n");
1381 } /* TLan_PhyDetect */
1383 void TLan_PhyPowerDown(struct nic *nic)
1386 u16 value;
1387 DBG ( "%s: Powering down PHY(s).\n", priv->nic_name );
1388 value = MII_GC_PDOWN | MII_GC_LOOPBK | MII_GC_ISOLATE;
1389 TLan_MiiSync(BASE);
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))) {
1395 TLan_MiiSync(BASE);
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 ); */
1404 mdelay(50);
1405 TLan_PhyPowerUp(nic);
1407 } /* TLan_PhyPowerDown */
1410 void TLan_PhyPowerUp(struct nic *nic)
1412 u16 value;
1414 DBG ( "%s: Powering up PHY.\n", priv->nic_name );
1415 TLan_MiiSync(BASE);
1416 value = MII_GC_LOOPBK;
1417 TLan_MiiWriteReg(nic, priv->phy[priv->phyNum], MII_GEN_CTL, value);
1418 TLan_MiiSync(BASE);
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.
1423 mdelay(500);
1424 TLan_PhyReset(nic);
1425 /* TLan_SetTimer( dev, (HZ/20), TLAN_TIMER_PHY_RESET ); */
1427 } /* TLan_PhyPowerUp */
1429 void TLan_PhyReset(struct nic *nic)
1431 u16 phy;
1432 u16 value;
1434 phy = priv->phy[priv->phyNum];
1436 DBG ( "%s: Reseting PHY.\n", priv->nic_name );
1437 TLan_MiiSync(BASE);
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 ); */
1450 mdelay(50);
1451 TLan_PhyStartLink(nic);
1453 } /* TLan_PhyReset */
1456 void TLan_PhyStartLink(struct nic *nic)
1459 u16 ability;
1460 u16 control;
1461 u16 data;
1462 u16 phy;
1463 u16 status;
1464 u16 tctl;
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);
1487 } else {
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",
1502 priv->nic_name );
1503 mdelay(4000);
1504 TLan_PhyFinishAutoNeg(nic);
1505 /* TLan_SetTimer( dev, (2*HZ), TLAN_TIMER_PHY_FINISH_AN ); */
1506 return;
1511 if ((priv->aui) && (priv->phyNum != 0)) {
1512 priv->phyNum = 0;
1513 data =
1514 TLAN_NET_CFG_1FRAG | TLAN_NET_CFG_1CHAN |
1515 TLAN_NET_CFG_PHY_EN;
1516 TLan_DioWrite16(BASE, TLAN_NET_CONFIG, data);
1517 mdelay(50);
1518 /* TLan_SetTimer( dev, (40*HZ/1000), TLAN_TIMER_PHY_PDOWN ); */
1519 TLan_PhyPowerDown(nic);
1520 return;
1521 } else if (priv->phyNum == 0) {
1522 control = 0;
1523 TLan_MiiReadReg(nic, phy, TLAN_TLPHY_CTL, &tctl);
1524 if (priv->aui) {
1525 tctl |= TLAN_TC_AUISEL;
1526 } else {
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 ); */
1544 mdelay(2000);
1545 TLan_FinishReset(nic);
1547 } /* TLan_PhyStartLink */
1549 void TLan_PhyFinishAutoNeg(struct nic *nic)
1552 u16 an_adv;
1553 u16 an_lpa;
1554 u16 data;
1555 u16 mode;
1556 u16 phy;
1557 u16 status;
1559 phy = priv->phy[priv->phyNum];
1561 TLan_MiiReadReg(nic, phy, MII_GEN_STS, &status);
1562 udelay(1000);
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++) {
1570 printf
1571 ("TLAN: Giving autonegotiation more time.\n");
1572 printf
1573 ("TLAN: Please check that your adapter has\n");
1574 printf
1575 ("TLAN: been properly connected to a HUB or Switch.\n");
1576 printf
1577 ("TLAN: Trying to establish link in the background...\n");
1579 mdelay(8000);
1580 TLan_PhyFinishAutoNeg(nic);
1581 /* TLan_SetTimer( dev, (8*HZ), TLAN_TIMER_PHY_FINISH_AN ); */
1582 return;
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)) {
1600 priv->phyNum = 0;
1601 data =
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 ); */
1606 mdelay(400);
1607 TLan_PhyPowerDown(nic);
1608 return;
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);
1616 DBG
1617 ( "TLAN: Starting internal PHY with FULL-DUPLEX\n" );
1618 } else {
1619 TLan_MiiWriteReg(nic, phy, MII_GEN_CTL,
1620 MII_GC_AUTOENB);
1621 DBG
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 ); */
1629 mdelay(100);
1630 TLan_FinishReset(nic);
1632 } /* TLan_PhyFinishAutoNeg */
1634 #ifdef MONITOR
1636 /*********************************************************************
1638 * TLan_phyMonitor
1640 * Returns:
1641 * None
1643 * Params:
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
1650 * media.
1652 ********************************************************************/
1654 void TLan_PhyMonitor(struct net_device *dev)
1656 TLanPrivateInfo *priv = dev->priv;
1657 u16 phy;
1658 u16 phy_status;
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)) {
1667 if (priv->link) {
1668 priv->link = 0;
1669 printf("TLAN: %s has lost link\n", priv->nic_name);
1670 priv->flags &= ~IFF_RUNNING;
1671 mdelay(2000);
1672 TLan_PhyMonitor(nic);
1673 /* TLan_SetTimer( dev, (2*HZ), TLAN_TIMER_LINK_BEAT ); */
1674 return;
1678 /* Link restablished? */
1679 if ((phy_status & MII_GS_LINK) && !priv->link) {
1680 priv->link = 1;
1681 printf("TLAN: %s has reestablished link\n",
1682 priv->nic_name);
1683 priv->flags |= IFF_RUNNING;
1686 /* Setup a new monitor */
1687 /* TLan_SetTimer( dev, (2*HZ), TLAN_TIMER_LINK_BEAT ); */
1688 mdelay(2000);
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 );
1716 * Local variables:
1717 * c-basic-offset: 8
1718 * c-indent-level: 8
1719 * tab-width: 8
1720 * End: