2 * 3c595.c -- 3COM 3C595 Fast Etherlink III PCI driver for etherboot
4 * Copyright (C) 2000 Shusuke Nisiyama <shu@athena.qe.eng.hokudai.ac.jp>
8 * This software may be used, modified, copied, distributed, and sold, in
9 * both source and binary form provided that the above copyright and these
10 * terms are retained. Under no circumstances are the authors responsible for
11 * the proper functioning of this software, nor do the authors assume any
12 * responsibility for damages incurred with its use.
14 * This code is based on Martin Renters' etherboot-4.4.3 3c509.c and
15 * Herb Peyerl's FreeBSD 3.4-RELEASE if_vx.c driver.
17 * Copyright (C) 1993-1994, David Greenman, Martin Renters.
18 * Copyright (C) 1993-1995, Andres Vega Garcia.
19 * Copyright (C) 1995, Serge Babkin.
21 * Copyright (c) 1994 Herb Peyerl <hpeyerl@novatel.ca>
23 * timlegge 08-24-2003 Add Multicast Support
26 FILE_LICENCE ( BSD2
);
30 #include "etherboot.h"
33 #include <gpxe/ethernet.h>
36 static struct nic_operations t595_operations
;
38 static unsigned short eth_nic_base
;
39 static unsigned short vx_connector
, vx_connectors
;
41 static struct connector_entry
{
44 } conn_tab
[VX_CONNECTORS
] = {
45 #define CONNECTOR_UTP 0
47 #define CONNECTOR_AUI 1
51 #define CONNECTOR_BNC 3
53 #define CONNECTOR_TX 4
55 #define CONNECTOR_FX 5
57 #define CONNECTOR_MII 6
62 static void vxgetlink(void);
63 static void vxsetlink(void);
65 /**************************************************************************
66 ETH_RESET - Reset adapter
67 ***************************************************************************/
68 static void t595_reset(struct nic
*nic
)
72 /***********************************************************
74 *************************************************************/
77 outw(RX_DISABLE
, BASE
+ VX_COMMAND
);
78 outw(RX_DISCARD_TOP_PACK
, BASE
+ VX_COMMAND
);
80 outw(TX_DISABLE
, BASE
+ VX_COMMAND
);
81 outw(STOP_TRANSCEIVER
, BASE
+ VX_COMMAND
);
83 outw(RX_RESET
, BASE
+ VX_COMMAND
);
85 outw(TX_RESET
, BASE
+ VX_COMMAND
);
87 outw(C_INTR_LATCH
, BASE
+ VX_COMMAND
);
88 outw(SET_RD_0_MASK
, BASE
+ VX_COMMAND
);
89 outw(SET_INTR_MASK
, BASE
+ VX_COMMAND
);
90 outw(SET_RX_FILTER
, BASE
+ VX_COMMAND
);
99 /* Disable the card */
100 /* outw(0, BASE + VX_W0_CONFIG_CTRL); */
102 /* Configure IRQ to none */
103 /* outw(SET_IRQ(0), BASE + VX_W0_RESOURCE_CFG); */
105 /* Enable the card */
106 /* outw(ENABLE_DRQ_IRQ, BASE + VX_W0_CONFIG_CTRL); */
110 /* Reload the ether_addr. */
111 for (i
= 0; i
< ETH_ALEN
; i
++)
112 outb(nic
->node_addr
[i
], BASE
+ VX_W2_ADDR_0
+ i
);
114 outw(RX_RESET
, BASE
+ VX_COMMAND
);
116 outw(TX_RESET
, BASE
+ VX_COMMAND
);
119 /* Window 1 is operating window */
121 for (i
= 0; i
< 31; i
++)
122 inb(BASE
+ VX_W1_TX_STATUS
);
124 outw(SET_RD_0_MASK
| S_CARD_FAILURE
| S_RX_COMPLETE
|
125 S_TX_COMPLETE
| S_TX_AVAIL
, BASE
+ VX_COMMAND
);
126 outw(SET_INTR_MASK
| S_CARD_FAILURE
| S_RX_COMPLETE
|
127 S_TX_COMPLETE
| S_TX_AVAIL
, BASE
+ VX_COMMAND
);
130 * Attempt to get rid of any stray interrupts that occured during
131 * configuration. On the i386 this isn't possible because one may
132 * already be queued. However, a single stray interrupt is
136 outw(ACK_INTR
| 0xff, BASE
+ VX_COMMAND
);
138 outw(SET_RX_FILTER
| FIL_INDIVIDUAL
|
139 FIL_BRDCST
|FIL_MULTICAST
, BASE
+ VX_COMMAND
);
146 j = inl(BASE + VX_W3_INTERNAL_CFG) & ~INTERNAL_CONNECTOR_MASK;
147 outl(BASE + VX_W3_INTERNAL_CFG, j | (i <<INTERNAL_CONNECTOR_BITS));
149 outw(LINKBEAT_ENABLE, BASE + VX_W4_MEDIA_TYPE);
153 /* start tranciever and receiver */
154 outw(RX_ENABLE
, BASE
+ VX_COMMAND
);
155 outw(TX_ENABLE
, BASE
+ VX_COMMAND
);
159 /**************************************************************************
160 ETH_TRANSMIT - Transmit a frame
161 ***************************************************************************/
162 static char padmap
[] = {
165 static void t595_transmit(
167 const char *d
, /* Destination */
168 unsigned int t
, /* Type */
169 unsigned int s
, /* size */
170 const char *p
) /* Packet */
177 printf("{l=%d,t=%hX}",s
+ETH_HLEN
,t
);
180 /* swap bytes of type */
183 len
=s
+ETH_HLEN
; /* actual length of packet */
184 pad
= padmap
[len
& 3];
187 * The 3c595 automatically pads short packets to minimum ethernet length,
188 * but we drop packets that are too large. Perhaps we should truncate
191 if (len
+ pad
> ETH_FRAME_LEN
) {
195 /* drop acknowledgements */
196 while(( status
=inb(BASE
+ VX_W1_TX_STATUS
) )& TXS_COMPLETE
) {
197 if(status
& (TXS_UNDERRUN
|TXS_MAX_COLLISION
|TXS_STATUS_OVERFLOW
)) {
198 outw(TX_RESET
, BASE
+ VX_COMMAND
);
199 outw(TX_ENABLE
, BASE
+ VX_COMMAND
);
202 outb(0x0, BASE
+ VX_W1_TX_STATUS
);
205 while (inw(BASE
+ VX_W1_FREE_TX
) < len
+ pad
+ 4) {
206 /* no room in FIFO */
209 outw(len
, BASE
+ VX_W1_TX_PIO_WR_1
);
210 outw(0x0, BASE
+ VX_W1_TX_PIO_WR_1
); /* Second dword meaningless */
213 outsw(BASE
+ VX_W1_TX_PIO_WR_1
, d
, ETH_ALEN
/2);
214 outsw(BASE
+ VX_W1_TX_PIO_WR_1
, nic
->node_addr
, ETH_ALEN
/2);
215 outw(t
, BASE
+ VX_W1_TX_PIO_WR_1
);
216 outsw(BASE
+ VX_W1_TX_PIO_WR_1
, p
, s
/ 2);
218 outb(*(p
+s
- 1), BASE
+ VX_W1_TX_PIO_WR_1
);
221 outb(0, BASE
+ VX_W1_TX_PIO_WR_1
); /* Padding */
223 /* wait for Tx complete */
224 while((inw(BASE
+ VX_STATUS
) & S_COMMAND_IN_PROGRESS
) != 0)
228 /**************************************************************************
229 ETH_POLL - Wait for a frame
230 ***************************************************************************/
231 static int t595_poll(struct nic
*nic
, int retrieve
)
233 /* common variables */
234 /* variables for 3C595 */
236 register short rx_fifo
;
238 cst
=inw(BASE
+ VX_STATUS
);
245 if( (cst
& S_RX_COMPLETE
)==0 ) {
246 /* acknowledge everything */
247 outw(ACK_INTR
| cst
, BASE
+ VX_COMMAND
);
248 outw(C_INTR_LATCH
, BASE
+ VX_COMMAND
);
253 status
= inw(BASE
+ VX_W1_RX_STATUS
);
255 printf("*%hX*",status
);
258 if (status
& ERR_RX
) {
259 outw(RX_DISCARD_TOP_PACK
, BASE
+ VX_COMMAND
);
263 rx_fifo
= status
& RX_BYTES_MASK
;
267 if ( ! retrieve
) return 1;
271 printf("[l=%d",rx_fifo
);
273 insw(BASE
+ VX_W1_RX_PIO_RD_1
, nic
->packet
, rx_fifo
/ 2);
275 nic
->packet
[rx_fifo
-1]=inb(BASE
+ VX_W1_RX_PIO_RD_1
);
276 nic
->packetlen
=rx_fifo
;
279 status
= inw(BASE
+ VX_W1_RX_STATUS
);
281 printf("*%hX*",status
);
283 rx_fifo
= status
& RX_BYTES_MASK
;
286 insw(BASE
+ VX_W1_RX_PIO_RD_1
, nic
->packet
+nic
->packetlen
, rx_fifo
/ 2);
288 nic
->packet
[nic
->packetlen
+rx_fifo
-1]=inb(BASE
+ VX_W1_RX_PIO_RD_1
);
289 nic
->packetlen
+=rx_fifo
;
291 printf("+%d",rx_fifo
);
294 if(( status
& RX_INCOMPLETE
)==0) {
296 printf("=%d",nic
->packetlen
);
303 /* acknowledge reception of packet */
304 outw(RX_DISCARD_TOP_PACK
, BASE
+ VX_COMMAND
);
305 while (inw(BASE
+ VX_STATUS
) & S_COMMAND_IN_PROGRESS
);
308 unsigned short type
= 0; /* used by EDEBUG */
309 type
= (nic
->packet
[12]<<8) | nic
->packet
[13];
310 if(nic
->packet
[0]+nic
->packet
[1]+nic
->packet
[2]+nic
->packet
[3]+nic
->packet
[4]+
311 nic
->packet
[5] == 0xFF*ETH_ALEN
)
312 printf(",t=%hX,b]",type
);
314 printf(",t=%hX]",type
);
321 /*************************************************************************
322 3Com 595 - specific routines
323 **************************************************************************/
330 for (i
= 0; is_eeprom_busy(BASE
) && i
< MAX_EEPROMBUSY
; i
++)
332 if (i
>= MAX_EEPROMBUSY
) {
333 /* printf("3c595: eeprom failed to come ready.\n"); */
334 printf("3c595: eeprom is busy.\n"); /* memory in EPROM is tight */
341 * get_e: gets a 16 bits word from the EEPROM. we must have set the window
350 outw(EEPROM_CMD_RD
| offset
, BASE
+ VX_W0_EEPROM_COMMAND
);
353 return (inw(BASE
+ VX_W0_EEPROM_DATA
));
362 vx_connectors
= inw(BASE
+ VX_W3_RESET_OPT
) & 0x7f;
363 for (n
= 0, k
= 0; k
< VX_CONNECTORS
; k
++) {
364 if (vx_connectors
& conn_tab
[k
].bit
) {
368 printf("%s", conn_tab
[k
].name
);
372 if (vx_connectors
== 0) {
373 printf("no connectors!");
377 vx_connector
= (inl(BASE
+ VX_W3_INTERNAL_CFG
)
378 & INTERNAL_CONNECTOR_MASK
)
379 >> INTERNAL_CONNECTOR_BITS
;
380 if (vx_connector
& 0x10) {
381 vx_connector
&= 0x0f;
382 printf("[*%s*]", conn_tab
[vx_connector
].name
);
383 printf(": disable 'auto select' with DOS util!");
385 printf("[*%s*]", conn_tab
[vx_connector
].name
);
393 char *reason
, *warning
;
394 static char prev_conn
= -1;
396 if (prev_conn
== -1) {
397 prev_conn
= vx_connector
;
400 i
= vx_connector
; /* default in EEPROM */
404 if ((vx_connectors
& conn_tab
[vx_connector
].bit
) == 0) {
405 warning
= "strange connector type in EEPROM.";
411 printf("warning: %s\n", warning
);
413 printf("selected %s. (%s)\n", conn_tab
[i
].name
, reason
);
415 /* Set the selected connector. */
417 j
= inl(BASE
+ VX_W3_INTERNAL_CFG
) & ~INTERNAL_CONNECTOR_MASK
;
418 outl(j
| (i
<<INTERNAL_CONNECTOR_BITS
), BASE
+ VX_W3_INTERNAL_CFG
);
420 /* First, disable all. */
421 outw(STOP_TRANSCEIVER
, BASE
+ VX_COMMAND
);
424 outw(0, BASE
+ VX_W4_MEDIA_TYPE
);
426 /* Second, enable the selected one. */
430 outw(ENABLE_UTP
, BASE
+ VX_W4_MEDIA_TYPE
);
433 outw(START_TRANSCEIVER
,BASE
+ VX_COMMAND
);
439 outw(LINKBEAT_ENABLE
, BASE
+ VX_W4_MEDIA_TYPE
);
441 default: /* AUI and MII fall here */
447 static void t595_disable ( struct nic
*nic
) {
451 outw(STOP_TRANSCEIVER
, BASE
+ VX_COMMAND
);
454 outw(0, BASE
+ VX_W4_MEDIA_TYPE
);
458 static void t595_irq(struct nic
*nic __unused
, irq_action_t action __unused
)
470 /**************************************************************************
471 ETH_PROBE - Look for an adapter
472 ***************************************************************************/
473 static int t595_probe ( struct nic
*nic
, struct pci_device
*pci
) {
478 if (pci
->ioaddr
== 0)
480 eth_nic_base
= pci
->ioaddr
;
483 nic
->ioaddr
= pci
->ioaddr
;
486 outw(GLOBAL_RESET
, BASE
+ VX_COMMAND
);
493 for (i = 0; i < (EEPROMSIZE/2); i++) {
494 printf("%hX:", get_e(i));
499 * Read the station address from the eeprom
501 p
= (unsigned short *) nic
->node_addr
;
502 for (i
= 0; i
< 3; i
++) {
504 p
[i
] = htons(get_e(EEPROM_OEM_ADDR_0
+ i
));
506 outw(ntohs(p
[i
]), BASE
+ VX_W2_ADDR_0
+ (i
* 2));
509 DBG ( "Ethernet address: %s\n", eth_ntoa (nic
->node_addr
) );
512 nic
->nic_op
= &t595_operations
;
517 static struct nic_operations t595_operations
= {
518 .connect
= dummy_connect
,
520 .transmit
= t595_transmit
,
525 static struct pci_device_id t595_nics
[] = {
526 PCI_ROM(0x10b7, 0x5900, "3c590", "3Com590", 0), /* Vortex 10Mbps */
527 PCI_ROM(0x10b7, 0x5950, "3c595", "3Com595", 0), /* Vortex 100baseTx */
528 PCI_ROM(0x10b7, 0x5951, "3c595-1", "3Com595", 0), /* Vortex 100baseT4 */
529 PCI_ROM(0x10b7, 0x5952, "3c595-2", "3Com595", 0), /* Vortex 100base-MII */
530 PCI_ROM(0x10b7, 0x9000, "3c900-tpo", "3Com900-TPO", 0), /* 10 Base TPO */
531 PCI_ROM(0x10b7, 0x9001, "3c900-t4", "3Com900-Combo", 0), /* 10/100 T4 */
532 PCI_ROM(0x10b7, 0x9004, "3c900b-tpo", "3Com900B-TPO", 0), /* 10 Base TPO */
533 PCI_ROM(0x10b7, 0x9005, "3c900b-combo", "3Com900B-Combo", 0), /* 10 Base Combo */
534 PCI_ROM(0x10b7, 0x9006, "3c900b-tpb2", "3Com900B-2/T", 0), /* 10 Base TP and Base2 */
535 PCI_ROM(0x10b7, 0x900a, "3c900b-fl", "3Com900B-FL", 0), /* 10 Base F */
536 PCI_ROM(0x10b7, 0x9800, "3c980-cyclone-1", "3Com980-Cyclone", 0), /* Cyclone */
537 PCI_ROM(0x10b7, 0x9805, "3c9805-1", "3Com9805", 0), /* Dual Port Server Cyclone */
538 PCI_ROM(0x10b7, 0x7646, "3csoho100-tx-1", "3CSOHO100-TX", 0), /* Hurricane */
539 PCI_ROM(0x10b7, 0x4500, "3c450-1", "3Com450 HomePNA Tornado", 0),
542 PCI_DRIVER ( t595_driver
, t595_nics
, PCI_NO_CLASS
);
544 DRIVER ( "3C595", nic_driver
, pci_driver
, t595_driver
,
545 t595_probe
, t595_disable
);