iPXE
3c595.c
Go to the documentation of this file.
1/*
2* 3c595.c -- 3COM 3C595 Fast Etherlink III PCI driver for etherboot
3*
4* Copyright (C) 2000 Shusuke Nisiyama <shu@athena.qe.eng.hokudai.ac.jp>
5* All rights reserved.
6* Mar. 14, 2000
7*
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.
13*
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.
16*
17* Copyright (C) 1993-1994, David Greenman, Martin Renters.
18* Copyright (C) 1993-1995, Andres Vega Garcia.
19* Copyright (C) 1995, Serge Babkin.
20*
21* Copyright (c) 1994 Herb Peyerl <hpeyerl@novatel.ca>
22*
23* timlegge 08-24-2003 Add Multicast Support
24*/
25
26FILE_LICENCE ( BSD2 );
27
28/* #define EDEBUG */
29
30#include "etherboot.h"
31#include "nic.h"
32#include <ipxe/pci.h>
33#include <ipxe/ethernet.h>
34#include "3c595.h"
35
37
38static unsigned short eth_nic_base;
39static unsigned short vx_connector, vx_connectors;
40
41static struct connector_entry {
42 int bit;
43 char *name;
45#define CONNECTOR_UTP 0
46 { 0x08, "utp"},
47#define CONNECTOR_AUI 1
48 { 0x20, "aui"},
49/* dummy */
50 { 0, "???"},
51#define CONNECTOR_BNC 3
52 { 0x10, "bnc"},
53#define CONNECTOR_TX 4
54 { 0x02, "tx"},
55#define CONNECTOR_FX 5
56 { 0x04, "fx"},
57#define CONNECTOR_MII 6
58 { 0x40, "mii"},
59 { 0, "???"}
60};
61
62static void vxgetlink(void);
63static void vxsetlink(void);
64
65/**************************************************************************
66ETH_RESET - Reset adapter
67***************************************************************************/
68static void t595_reset(struct nic *nic)
69{
70 int i;
71
72 /***********************************************************
73 Reset 3Com 595 card
74 *************************************************************/
75
76 /* stop card */
82 udelay(8000);
91
92 /*
93 * initialize card
94 */
96
97 GO_WINDOW(0);
98
99 /* Disable the card */
100/* outw(0, BASE + VX_W0_CONFIG_CTRL); */
101
102 /* Configure IRQ to none */
103/* outw(SET_IRQ(0), BASE + VX_W0_RESOURCE_CFG); */
104
105 /* Enable the card */
106/* outw(ENABLE_DRQ_IRQ, BASE + VX_W0_CONFIG_CTRL); */
107
108 GO_WINDOW(2);
109
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);
113
118
119 /* Window 1 is operating window */
120 GO_WINDOW(1);
121 for (i = 0; i < 31; i++)
123
128
129/*
130 * Attempt to get rid of any stray interrupts that occurred during
131 * configuration. On the i386 this isn't possible because one may
132 * already be queued. However, a single stray interrupt is
133 * unimportant.
134 */
135
136 outw(ACK_INTR | 0xff, BASE + VX_COMMAND);
137
140
141 vxsetlink();
142/*{
143 int i,j;
144 i = CONNECTOR_TX;
145 GO_WINDOW(3);
146 j = inl(BASE + VX_W3_INTERNAL_CFG) & ~INTERNAL_CONNECTOR_MASK;
147 outl(BASE + VX_W3_INTERNAL_CFG, j | (i <<INTERNAL_CONNECTOR_BITS));
148 GO_WINDOW(4);
149 outw(LINKBEAT_ENABLE, BASE + VX_W4_MEDIA_TYPE);
150 GO_WINDOW(1);
151}*/
152
153 /* start tranciever and receiver */
156
157}
158
159/**************************************************************************
160ETH_TRANSMIT - Transmit a frame
161***************************************************************************/
162static char padmap[] = {
163 0, 3, 2, 1};
164
165static void t595_transmit(
166struct nic *nic,
167const char *d, /* Destination */
168unsigned int t, /* Type */
169unsigned int s, /* size */
170const char *p) /* Packet */
171{
172 register int len;
173 int pad;
174 int status;
175
176#ifdef EDEBUG
177 printf("{l=%d,t=%hX}",s+ETH_HLEN,t);
178#endif
179
180 /* swap bytes of type */
181 t= htons(t);
182
183 len=s+ETH_HLEN; /* actual length of packet */
184 pad = padmap[len & 3];
185
186 /*
187 * The 3c595 automatically pads short packets to minimum ethernet length,
188 * but we drop packets that are too large. Perhaps we should truncate
189 * them instead?
190 */
191 if (len + pad > ETH_FRAME_LEN) {
192 return;
193 }
194
195 /* drop acknowledgements */
196 while(( status=inb(BASE + VX_W1_TX_STATUS) )& TXS_COMPLETE ) {
200 }
201
202 outb(0x0, BASE + VX_W1_TX_STATUS);
203 }
204
205 while (inw(BASE + VX_W1_FREE_TX) < len + pad + 4) {
206 /* no room in FIFO */
207 }
208
210 outw(0x0, BASE + VX_W1_TX_PIO_WR_1); /* Second dword meaningless */
211
212 /* write packet */
216 outsw(BASE + VX_W1_TX_PIO_WR_1, p, s / 2);
217 if (s & 1)
218 outb(*(p+s - 1), BASE + VX_W1_TX_PIO_WR_1);
219
220 while (pad--)
221 outb(0, BASE + VX_W1_TX_PIO_WR_1); /* Padding */
222
223 /* wait for Tx complete */
224 while((inw(BASE + VX_STATUS) & S_COMMAND_IN_PROGRESS) != 0)
225 ;
226}
227
228/**************************************************************************
229ETH_POLL - Wait for a frame
230***************************************************************************/
231static int t595_poll(struct nic *nic, int retrieve)
232{
233 /* common variables */
234 /* variables for 3C595 */
235 short status, cst;
236 register short rx_fifo;
237
238 cst=inw(BASE + VX_STATUS);
239
240#ifdef EDEBUG
241 if(cst & 0x1FFF)
242 printf("-%hX-",cst);
243#endif
244
245 if( (cst & S_RX_COMPLETE)==0 ) {
246 /* acknowledge everything */
247 outw(ACK_INTR | cst, BASE + VX_COMMAND);
249
250 return 0;
251 }
252
254#ifdef EDEBUG
255 printf("*%hX*",status);
256#endif
257
258 if (status & ERR_RX) {
260 return 0;
261 }
262
263 rx_fifo = status & RX_BYTES_MASK;
264 if (rx_fifo==0)
265 return 0;
266
267 if ( ! retrieve ) return 1;
268
269 /* read packet */
270#ifdef EDEBUG
271 printf("[l=%d",rx_fifo);
272#endif
273 insw(BASE + VX_W1_RX_PIO_RD_1, nic->packet, rx_fifo / 2);
274 if(rx_fifo & 1)
275 nic->packet[rx_fifo-1]=inb(BASE + VX_W1_RX_PIO_RD_1);
276 nic->packetlen=rx_fifo;
277
278 while(1) {
280#ifdef EDEBUG
281 printf("*%hX*",status);
282#endif
283 rx_fifo = status & RX_BYTES_MASK;
284
285 if(rx_fifo>0) {
286 insw(BASE + VX_W1_RX_PIO_RD_1, nic->packet+nic->packetlen, rx_fifo / 2);
287 if(rx_fifo & 1)
289 nic->packetlen+=rx_fifo;
290#ifdef EDEBUG
291 printf("+%d",rx_fifo);
292#endif
293 }
294 if(( status & RX_INCOMPLETE )==0) {
295#ifdef EDEBUG
296 printf("=%d",nic->packetlen);
297#endif
298 break;
299 }
300 udelay(1000);
301 }
302
303 /* acknowledge reception of packet */
306#ifdef EDEBUG
307{
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);
313 else
314 printf(",t=%hX]",type);
315}
316#endif
317 return 1;
318}
319
320
321/*************************************************************************
322 3Com 595 - specific routines
323**************************************************************************/
324
325static int
327{
328 int i;
329
330 for (i = 0; is_eeprom_busy(BASE) && i < MAX_EEPROMBUSY; i++)
331 udelay(1000);
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 */
335 return (0);
336 }
337 return (1);
338}
339
340/*
341 * get_e: gets a 16 bits word from the EEPROM. we must have set the window
342 * before
343 */
344static int
346{
347 if (!eeprom_rdy())
348 return (0xffff);
350 if (!eeprom_rdy())
351 return (0xffff);
352 return (inw(BASE + VX_W0_EEPROM_DATA));
353}
354
355static void
357{
358 int n, k;
359
360 GO_WINDOW(3);
362 for (n = 0, k = 0; k < VX_CONNECTORS; k++) {
363 if (vx_connectors & conn_tab[k].bit) {
364 if (n > 0) {
365 printf("/");
366 }
367 printf("%s", conn_tab[k].name );
368 n++;
369 }
370 }
371 if (vx_connectors == 0) {
372 printf("no connectors!");
373 return;
374 }
375 GO_WINDOW(3);
379 if (vx_connector & 0x10) {
380 vx_connector &= 0x0f;
381 printf("[*%s*]", conn_tab[vx_connector].name);
382 printf(": disable 'auto select' with DOS util!");
383 } else {
384 printf("[*%s*]", conn_tab[vx_connector].name);
385 }
386}
387
388static void
390{
391 int i, j;
392 char *reason, *warning;
393 static signed char prev_conn = -1;
394
395 if (prev_conn == -1) {
396 prev_conn = vx_connector;
397 }
398
399 i = vx_connector; /* default in EEPROM */
400 reason = "default";
401 warning = NULL;
402
403 if ((vx_connectors & conn_tab[vx_connector].bit) == 0) {
404 warning = "strange connector type in EEPROM.";
405 reason = "forced";
406 i = CONNECTOR_UTP;
407 }
408
409 if (warning) {
410 printf("warning: %s\n", warning);
411 }
412 printf("selected %s. (%s)\n", conn_tab[i].name, reason);
413
414 /* Set the selected connector. */
415 GO_WINDOW(3);
418
419 /* First, disable all. */
421 udelay(8000);
422 GO_WINDOW(4);
424
425 /* Second, enable the selected one. */
426 switch(i) {
427 case CONNECTOR_UTP:
428 GO_WINDOW(4);
430 break;
431 case CONNECTOR_BNC:
433 udelay(8000);
434 break;
435 case CONNECTOR_TX:
436 case CONNECTOR_FX:
437 GO_WINDOW(4);
439 break;
440 default: /* AUI and MII fall here */
441 break;
442 }
443 GO_WINDOW(1);
444}
445
446static void t595_disable ( struct nic *nic, void *hwdev __unused ) {
447
449
451 udelay(8000);
452 GO_WINDOW(4);
454 GO_WINDOW(1);
455}
456
457static void t595_irq(struct nic *nic __unused, irq_action_t action __unused)
458{
459 switch ( action ) {
460 case DISABLE :
461 break;
462 case ENABLE :
463 break;
464 case FORCE :
465 break;
466 }
467}
468
469/**************************************************************************
470ETH_PROBE - Look for an adapter
471***************************************************************************/
472static int t595_probe ( struct nic *nic, struct pci_device *pci ) {
473
474 int i;
475 unsigned short *p;
476
477 if (pci->ioaddr == 0)
478 return 0;
479 eth_nic_base = pci->ioaddr;
480
481 nic->irqno = 0;
482 nic->ioaddr = pci->ioaddr;
483
484 GO_WINDOW(0);
487
488 vxgetlink();
489
490/*
491 printf("\nEEPROM:");
492 for (i = 0; i < (EEPROMSIZE/2); i++) {
493 printf("%hX:", get_e(i));
494 }
495 printf("\n");
496*/
497 /*
498 * Read the station address from the eeprom
499 */
500 p = (unsigned short *) nic->node_addr;
501 for (i = 0; i < 3; i++) {
502 GO_WINDOW(0);
503 p[i] = htons(get_e(EEPROM_OEM_ADDR_0 + i));
504 GO_WINDOW(2);
505 outw(ntohs(p[i]), BASE + VX_W2_ADDR_0 + (i * 2));
506 }
507
508 DBG ( "Ethernet address: %s\n", eth_ntoa (nic->node_addr) );
509
512 return 1;
513
514}
515
516static struct nic_operations t595_operations = {
517 .connect = dummy_connect,
518 .poll = t595_poll,
519 .transmit = t595_transmit,
520 .irq = t595_irq,
521
522};
523
524static struct pci_device_id t595_nics[] = {
525PCI_ROM(0x10b7, 0x4500, "3c450-1", "3Com450 HomePNA Tornado", 0),
526PCI_ROM(0x10b7, 0x5900, "3c590", "3Com590", 0), /* Vortex 10Mbps */
527PCI_ROM(0x10b7, 0x5950, "3c595", "3Com595", 0), /* Vortex 100baseTx */
528PCI_ROM(0x10b7, 0x5951, "3c595-1", "3Com595", 0), /* Vortex 100baseT4 */
529PCI_ROM(0x10b7, 0x5952, "3c595-2", "3Com595", 0), /* Vortex 100base-MII */
530PCI_ROM(0x10b7, 0x7646, "3csoho100-tx-1", "3CSOHO100-TX", 0), /* Hurricane */
531PCI_ROM(0x10b7, 0x9000, "3c900-tpo", "3Com900-TPO", 0), /* 10 Base TPO */
532PCI_ROM(0x10b7, 0x9001, "3c900-t4", "3Com900-Combo", 0), /* 10/100 T4 */
533PCI_ROM(0x10b7, 0x9004, "3c900b-tpo", "3Com900B-TPO", 0), /* 10 Base TPO */
534PCI_ROM(0x10b7, 0x9005, "3c900b-combo", "3Com900B-Combo", 0), /* 10 Base Combo */
535PCI_ROM(0x10b7, 0x9006, "3c900b-tpb2", "3Com900B-2/T", 0), /* 10 Base TP and Base2 */
536PCI_ROM(0x10b7, 0x900a, "3c900b-fl", "3Com900B-FL", 0), /* 10 Base F */
537PCI_ROM(0x10b7, 0x9800, "3c980-cyclone-1", "3Com980-Cyclone", 0), /* Cyclone */
538PCI_ROM(0x10b7, 0x9805, "3c9805-1", "3Com9805", 0), /* Dual Port Server Cyclone */
539};
540
541PCI_DRIVER ( t595_driver, t595_nics, PCI_NO_CLASS );
542
543DRIVER ( "3C595", nic_driver, pci_driver, t595_driver,
545
546/*
547 * Local variables:
548 * c-basic-offset: 8
549 * c-indent-level: 8
550 * tab-width: 8
551 * End:
552 */
#define TX_RESET
Definition 3c509.h:218
#define ENABLE_UTP
Definition 3c509.h:344
#define FIL_BRDCST
Definition 3c509.h:225
#define S_RX_COMPLETE
Definition 3c509.h:269
#define C_INTR_LATCH
Definition 3c509.h:238
#define RX_BYTES_MASK
Definition 3c509.h:357
#define RX_RESET
Definition 3c509.h:214
#define MAX_EEPROMBUSY
Definition 3c509.h:53
#define RX_ENABLE
Definition 3c509.h:213
#define RX_INCOMPLETE
Definition 3c509.h:359
#define TXS_STATUS_OVERFLOW
Definition 3c509.h:326
#define ACK_INTR
Definition 3c509.h:237
#define SET_INTR_MASK
Definition 3c509.h:220
#define STOP_TRANSCEIVER
Definition 3c509.h:232
#define S_COMMAND_IN_PROGRESS
Definition 3c509.h:275
#define TXS_UNDERRUN
Definition 3c509.h:324
#define TXS_MAX_COLLISION
Definition 3c509.h:325
#define GO_WINDOW(b, x)
Definition 3c509.h:75
#define GLOBAL_RESET
Definition 3c509.h:209
#define is_eeprom_busy(b)
Definition 3c509.h:74
#define SET_RX_FILTER
Definition 3c509.h:222
#define S_TX_AVAIL
Definition 3c509.h:268
#define SET_RD_0_MASK
Definition 3c509.h:221
#define RX_DISCARD_TOP_PACK
Definition 3c509.h:215
#define FIL_INDIVIDUAL
Definition 3c509.h:223
#define S_CARD_FAILURE
Definition 3c509.h:266
#define TXS_COMPLETE
Definition 3c509.h:321
#define S_TX_COMPLETE
Definition 3c509.h:267
#define EEPROM_CMD_RD
Definition 3c509.h:63
#define START_TRANSCEIVER
Definition 3c509.h:211
#define RX_DISABLE
Definition 3c509.h:212
#define TX_ENABLE
Definition 3c509.h:216
#define TX_DISABLE
Definition 3c509.h:217
#define ERR_RX
Definition 3c509.h:295
static char padmap[]
Definition 3c515.c:498
static struct pci_device_id t595_nics[]
Definition 3c595.c:524
#define CONNECTOR_TX
static void t595_reset(struct nic *nic)
Definition 3c595.c:68
#define CONNECTOR_BNC
static struct nic_operations t595_operations
Definition 3c595.c:36
static void t595_transmit(struct nic *nic, const char *d, unsigned int t, unsigned int s, const char *p)
Definition 3c595.c:165
static unsigned short eth_nic_base
Definition 3c595.c:38
static void vxgetlink(void)
Definition 3c595.c:356
static int get_e(int offset)
Definition 3c595.c:345
static int t595_probe(struct nic *nic, struct pci_device *pci)
Definition 3c595.c:472
static struct connector_entry conn_tab[VX_CONNECTORS]
#define CONNECTOR_FX
static void t595_irq(struct nic *nic __unused, irq_action_t action __unused)
Definition 3c595.c:457
static int t595_poll(struct nic *nic, int retrieve)
Definition 3c595.c:231
static void vxsetlink(void)
Definition 3c595.c:389
static void t595_disable(struct nic *nic, void *hwdev __unused)
Definition 3c595.c:446
#define CONNECTOR_UTP
static unsigned short vx_connector
Definition 3c595.c:39
static int eeprom_rdy()
Definition 3c595.c:326
static unsigned short vx_connectors
Definition 3c595.c:39
#define VX_COMMAND
Definition 3c595.h:119
#define VX_W3_RESET_OPT
Definition 3c595.h:166
#define INTERNAL_CONNECTOR_BITS
Definition 3c595.h:299
#define VX_W0_EEPROM_DATA
Definition 3c595.h:126
#define VX_STATUS
Definition 3c595.h:120
#define EEPROM_OEM_ADDR_0
Definition 3c595.h:103
#define VX_W1_TX_PIO_WR_1
Definition 3c595.h:141
#define VX_CONNECTORS
Definition 3c595.h:421
#define VX_W1_TX_STATUS
Definition 3c595.h:144
#define VX_W0_EEPROM_COMMAND
Definition 3c595.h:127
#define BASE
Definition 3c595.h:69
#define VX_W1_FREE_TX
Definition 3c595.h:143
#define LINKBEAT_ENABLE
Definition 3c595.h:410
#define VX_W1_RX_STATUS
Definition 3c595.h:146
#define VX_W3_INTERNAL_CFG
Definition 3c595.h:165
#define FIL_MULTICAST
Definition 3c595.h:250
#define VX_W1_RX_PIO_RD_1
Definition 3c595.h:148
#define VX_BUSY_WAIT
Definition 3c595.h:288
#define INTERNAL_CONNECTOR_MASK
Definition 3c595.h:300
#define VX_W4_MEDIA_TYPE
Definition 3c595.h:174
#define VX_W2_ADDR_0
Definition 3c595.h:159
#define NULL
NULL pointer (VOID *)
Definition Base.h:322
u32 pad[9]
Padding.
Definition ar9003_mac.h:23
const char * name
Definition ath9k_hw.c:1986
uint16_t offset
Offset to command line.
Definition bzimage.h:3
ring len
Length.
Definition dwmac.h:226
uint32_t type
Operating system type.
Definition ena.h:1
uint8_t status
Status.
Definition ena.h:5
const char * eth_ntoa(const void *ll_addr)
Transcribe Ethernet address.
Definition ethernet.c:176
Ethernet protocol.
#define __unused
Declare a variable or data structure as unused.
Definition compiler.h:573
#define DBG(...)
Print a debugging message.
Definition compiler.h:498
#define FILE_LICENCE(_licence)
Declare a particular licence as applying to a file.
Definition compiler.h:896
uint16_t reason
Rejection reason.
Definition ib_mad.h:9
#define ETH_FRAME_LEN
Definition if_ether.h:12
#define ETH_ALEN
Definition if_ether.h:9
#define ETH_HLEN
Definition if_ether.h:10
#define htons(value)
Definition byteswap.h:136
#define ntohs(value)
Definition byteswap.h:137
static unsigned int unsigned int bit
Definition bigint.h:392
#define inw(io_addr)
Definition io.h:292
#define outb(data, io_addr)
Definition io.h:310
#define outw(data, io_addr)
Definition io.h:320
#define inl(io_addr)
Definition io.h:301
#define insw(io_addr, data, count)
Definition io.h:412
#define outl(data, io_addr)
Definition io.h:330
#define inb(io_addr)
Definition io.h:283
#define outsw(io_addr, data, count)
Definition io.h:447
int dummy_connect(struct nic *nic __unused)
Definition legacy.c:175
static const uint32_t k[64]
MD5 constants.
Definition md5.c:54
#define DRIVER(_name_text, _unused2, _unused3, _name, _probe, _disable, _fake_bss)
Definition nic.h:220
irq_action_t
Definition nic.h:34
@ FORCE
Definition nic.h:37
@ ENABLE
Definition nic.h:36
@ DISABLE
Definition nic.h:35
#define PCI_DRIVER(_name, _ids, _class)
Definition nic.h:105
struct @002057171240057303273132130141036221271355330106 no_fake_bss
PCI bus.
#define PCI_ROM(_vendor, _device, _name, _description, _data)
Definition pci.h:308
Definition 3c595.c:41
char * name
Definition 3c595.c:43
int bit
Definition 3c595.c:42
Definition nic.h:49
unsigned char * packet
Definition nic.h:53
unsigned char * node_addr
Definition nic.h:52
unsigned int packetlen
Definition nic.h:54
unsigned char irqno
Definition nic.h:56
unsigned int ioaddr
Definition nic.h:55
struct nic_operations * nic_op
Definition nic.h:50
A PCI device ID list entry.
Definition pci.h:175
A PCI device.
Definition pci.h:211
unsigned long ioaddr
I/O address.
Definition pci.h:226
A PCI driver.
Definition pci.h:252
void udelay(unsigned long usecs)
Delay for a fixed number of microseconds.
Definition timer.c:61
int printf(const char *fmt,...)
Write a formatted string to the console.
Definition vsprintf.c:465