1N/A/*
1N/A* 3c595.c -- 3COM 3C595 Fast Etherlink III PCI driver for etherboot
1N/A*
1N/A* Copyright (C) 2000 Shusuke Nisiyama <shu@athena.qe.eng.hokudai.ac.jp>
1N/A* All rights reserved.
1N/A* Mar. 14, 2000
1N/A*
1N/A* This software may be used, modified, copied, distributed, and sold, in
1N/A* both source and binary form provided that the above copyright and these
1N/A* terms are retained. Under no circumstances are the authors responsible for
1N/A* the proper functioning of this software, nor do the authors assume any
1N/A* responsibility for damages incurred with its use.
1N/A*
1N/A* This code is based on Martin Renters' etherboot-4.4.3 3c509.c and
1N/A* Herb Peyerl's FreeBSD 3.4-RELEASE if_vx.c driver.
1N/A*
1N/A* Copyright (C) 1993-1994, David Greenman, Martin Renters.
1N/A* Copyright (C) 1993-1995, Andres Vega Garcia.
1N/A* Copyright (C) 1995, Serge Babkin.
1N/A*
1N/A* Copyright (c) 1994 Herb Peyerl <hpeyerl@novatel.ca>
1N/A*
1N/A* timlegge 08-24-2003 Add Multicast Support
1N/A*/
1N/A
1N/A/* #define EDEBUG */
1N/A
1N/A#include "etherboot.h"
1N/A#include "nic.h"
1N/A#include "pci.h"
1N/A#include "3c595.h"
1N/A#include "timer.h"
1N/A
1N/Astatic unsigned short eth_nic_base;
1N/Astatic unsigned short vx_connector, vx_connectors;
1N/A
1N/Astatic struct connector_entry {
1N/A int bit;
1N/A char *name;
1N/A} conn_tab[VX_CONNECTORS] = {
1N/A#define CONNECTOR_UTP 0
1N/A { 0x08, "utp"},
1N/A#define CONNECTOR_AUI 1
1N/A { 0x20, "aui"},
1N/A/* dummy */
1N/A { 0, "???"},
1N/A#define CONNECTOR_BNC 3
1N/A { 0x10, "bnc"},
1N/A#define CONNECTOR_TX 4
1N/A { 0x02, "tx"},
1N/A#define CONNECTOR_FX 5
1N/A { 0x04, "fx"},
1N/A#define CONNECTOR_MII 6
1N/A { 0x40, "mii"},
1N/A { 0, "???"}
1N/A};
1N/A
1N/Astatic void vxgetlink(void);
1N/Astatic void vxsetlink(void);
1N/A
1N/A/**************************************************************************
1N/AETH_RESET - Reset adapter
1N/A***************************************************************************/
1N/Astatic void t595_reset(struct nic *nic)
1N/A{
1N/A int i;
1N/A
1N/A /***********************************************************
1N/A Reset 3Com 595 card
1N/A *************************************************************/
1N/A
1N/A /* stop card */
1N/A outw(RX_DISABLE, BASE + VX_COMMAND);
1N/A outw(RX_DISCARD_TOP_PACK, BASE + VX_COMMAND);
1N/A VX_BUSY_WAIT;
1N/A outw(TX_DISABLE, BASE + VX_COMMAND);
1N/A outw(STOP_TRANSCEIVER, BASE + VX_COMMAND);
1N/A udelay(8000);
1N/A outw(RX_RESET, BASE + VX_COMMAND);
1N/A VX_BUSY_WAIT;
1N/A outw(TX_RESET, BASE + VX_COMMAND);
1N/A VX_BUSY_WAIT;
1N/A outw(C_INTR_LATCH, BASE + VX_COMMAND);
1N/A outw(SET_RD_0_MASK, BASE + VX_COMMAND);
1N/A outw(SET_INTR_MASK, BASE + VX_COMMAND);
1N/A outw(SET_RX_FILTER, BASE + VX_COMMAND);
1N/A
1N/A /*
1N/A * initialize card
1N/A */
1N/A VX_BUSY_WAIT;
1N/A
1N/A GO_WINDOW(0);
1N/A
1N/A /* Disable the card */
1N/A/* outw(0, BASE + VX_W0_CONFIG_CTRL); */
1N/A
1N/A /* Configure IRQ to none */
1N/A/* outw(SET_IRQ(0), BASE + VX_W0_RESOURCE_CFG); */
1N/A
1N/A /* Enable the card */
1N/A/* outw(ENABLE_DRQ_IRQ, BASE + VX_W0_CONFIG_CTRL); */
1N/A
1N/A GO_WINDOW(2);
1N/A
1N/A /* Reload the ether_addr. */
1N/A for (i = 0; i < ETH_ALEN; i++)
1N/A outb(nic->node_addr[i], BASE + VX_W2_ADDR_0 + i);
1N/A
1N/A outw(RX_RESET, BASE + VX_COMMAND);
1N/A VX_BUSY_WAIT;
1N/A outw(TX_RESET, BASE + VX_COMMAND);
1N/A VX_BUSY_WAIT;
1N/A
1N/A /* Window 1 is operating window */
1N/A GO_WINDOW(1);
1N/A for (i = 0; i < 31; i++)
1N/A inb(BASE + VX_W1_TX_STATUS);
1N/A
1N/A outw(SET_RD_0_MASK | S_CARD_FAILURE | S_RX_COMPLETE |
1N/A S_TX_COMPLETE | S_TX_AVAIL, BASE + VX_COMMAND);
1N/A outw(SET_INTR_MASK | S_CARD_FAILURE | S_RX_COMPLETE |
1N/A S_TX_COMPLETE | S_TX_AVAIL, BASE + VX_COMMAND);
1N/A
1N/A/*
1N/A * Attempt to get rid of any stray interrupts that occured during
1N/A * configuration. On the i386 this isn't possible because one may
1N/A * already be queued. However, a single stray interrupt is
1N/A * unimportant.
1N/A */
1N/A
1N/A outw(ACK_INTR | 0xff, BASE + VX_COMMAND);
1N/A
1N/A outw(SET_RX_FILTER | FIL_INDIVIDUAL |
1N/A FIL_BRDCST|FIL_MULTICAST, BASE + VX_COMMAND);
1N/A
1N/A vxsetlink();
1N/A/*{
1N/A int i,j;
1N/A i = CONNECTOR_TX;
1N/A GO_WINDOW(3);
1N/A j = inl(BASE + VX_W3_INTERNAL_CFG) & ~INTERNAL_CONNECTOR_MASK;
1N/A outl(BASE + VX_W3_INTERNAL_CFG, j | (i <<INTERNAL_CONNECTOR_BITS));
1N/A GO_WINDOW(4);
1N/A outw(LINKBEAT_ENABLE, BASE + VX_W4_MEDIA_TYPE);
1N/A GO_WINDOW(1);
1N/A}*/
1N/A
1N/A /* start tranciever and receiver */
1N/A outw(RX_ENABLE, BASE + VX_COMMAND);
1N/A outw(TX_ENABLE, BASE + VX_COMMAND);
1N/A
1N/A}
1N/A
1N/A/**************************************************************************
1N/AETH_TRANSMIT - Transmit a frame
1N/A***************************************************************************/
1N/Astatic char padmap[] = {
1N/A 0, 3, 2, 1};
1N/A
1N/Astatic void t595_transmit(
1N/Astruct nic *nic,
1N/Aconst char *d, /* Destination */
1N/Aunsigned int t, /* Type */
1N/Aunsigned int s, /* size */
1N/Aconst char *p) /* Packet */
1N/A{
1N/A register int len;
1N/A int pad;
1N/A int status;
1N/A
1N/A#ifdef EDEBUG
1N/A printf("{l=%d,t=%hX}",s+ETH_HLEN,t);
1N/A#endif
1N/A
1N/A /* swap bytes of type */
1N/A t= htons(t);
1N/A
1N/A len=s+ETH_HLEN; /* actual length of packet */
1N/A pad = padmap[len & 3];
1N/A
1N/A /*
1N/A * The 3c595 automatically pads short packets to minimum ethernet length,
1N/A * but we drop packets that are too large. Perhaps we should truncate
1N/A * them instead?
1N/A */
1N/A if (len + pad > ETH_FRAME_LEN) {
1N/A return;
1N/A }
1N/A
1N/A /* drop acknowledgements */
1N/A while(( status=inb(BASE + VX_W1_TX_STATUS) )& TXS_COMPLETE ) {
1N/A if(status & (TXS_UNDERRUN|TXS_MAX_COLLISION|TXS_STATUS_OVERFLOW)) {
1N/A outw(TX_RESET, BASE + VX_COMMAND);
1N/A outw(TX_ENABLE, BASE + VX_COMMAND);
1N/A }
1N/A
1N/A outb(0x0, BASE + VX_W1_TX_STATUS);
1N/A }
1N/A
1N/A while (inw(BASE + VX_W1_FREE_TX) < len + pad + 4) {
1N/A /* no room in FIFO */
1N/A }
1N/A
1N/A outw(len, BASE + VX_W1_TX_PIO_WR_1);
1N/A outw(0x0, BASE + VX_W1_TX_PIO_WR_1); /* Second dword meaningless */
1N/A
1N/A /* write packet */
1N/A outsw(BASE + VX_W1_TX_PIO_WR_1, d, ETH_ALEN/2);
1N/A outsw(BASE + VX_W1_TX_PIO_WR_1, nic->node_addr, ETH_ALEN/2);
1N/A outw(t, BASE + VX_W1_TX_PIO_WR_1);
1N/A outsw(BASE + VX_W1_TX_PIO_WR_1, p, s / 2);
1N/A if (s & 1)
1N/A outb(*(p+s - 1), BASE + VX_W1_TX_PIO_WR_1);
1N/A
1N/A while (pad--)
1N/A outb(0, BASE + VX_W1_TX_PIO_WR_1); /* Padding */
1N/A
1N/A /* wait for Tx complete */
1N/A while((inw(BASE + VX_STATUS) & S_COMMAND_IN_PROGRESS) != 0)
1N/A ;
1N/A}
1N/A
1N/A/**************************************************************************
1N/AETH_POLL - Wait for a frame
1N/A***************************************************************************/
1N/Astatic int t595_poll(struct nic *nic, int retrieve)
1N/A{
1N/A /* common variables */
1N/A /* variables for 3C595 */
1N/A short status, cst;
1N/A register short rx_fifo;
1N/A
1N/A cst=inw(BASE + VX_STATUS);
1N/A
1N/A#ifdef EDEBUG
1N/A if(cst & 0x1FFF)
1N/A printf("-%hX-",cst);
1N/A#endif
1N/A
1N/A if( (cst & S_RX_COMPLETE)==0 ) {
1N/A /* acknowledge everything */
1N/A outw(ACK_INTR | cst, BASE + VX_COMMAND);
1N/A outw(C_INTR_LATCH, BASE + VX_COMMAND);
1N/A
1N/A return 0;
1N/A }
1N/A
1N/A status = inw(BASE + VX_W1_RX_STATUS);
1N/A#ifdef EDEBUG
1N/A printf("*%hX*",status);
1N/A#endif
1N/A
1N/A if (status & ERR_RX) {
1N/A outw(RX_DISCARD_TOP_PACK, BASE + VX_COMMAND);
1N/A return 0;
1N/A }
1N/A
1N/A rx_fifo = status & RX_BYTES_MASK;
1N/A if (rx_fifo==0)
1N/A return 0;
1N/A
1N/A if ( ! retrieve ) return 1;
1N/A
1N/A /* read packet */
1N/A#ifdef EDEBUG
1N/A printf("[l=%d",rx_fifo);
1N/A#endif
1N/A insw(BASE + VX_W1_RX_PIO_RD_1, nic->packet, rx_fifo / 2);
1N/A if(rx_fifo & 1)
1N/A nic->packet[rx_fifo-1]=inb(BASE + VX_W1_RX_PIO_RD_1);
1N/A nic->packetlen=rx_fifo;
1N/A
1N/A while(1) {
1N/A status = inw(BASE + VX_W1_RX_STATUS);
1N/A#ifdef EDEBUG
1N/A printf("*%hX*",status);
1N/A#endif
1N/A rx_fifo = status & RX_BYTES_MASK;
1N/A
1N/A if(rx_fifo>0) {
1N/A insw(BASE + VX_W1_RX_PIO_RD_1, nic->packet+nic->packetlen, rx_fifo / 2);
1N/A if(rx_fifo & 1)
1N/A nic->packet[nic->packetlen+rx_fifo-1]=inb(BASE + VX_W1_RX_PIO_RD_1);
1N/A nic->packetlen+=rx_fifo;
1N/A#ifdef EDEBUG
1N/A printf("+%d",rx_fifo);
1N/A#endif
1N/A }
1N/A if(( status & RX_INCOMPLETE )==0) {
1N/A#ifdef EDEBUG
1N/A printf("=%d",nic->packetlen);
1N/A#endif
1N/A break;
1N/A }
1N/A udelay(1000);
1N/A }
1N/A
1N/A /* acknowledge reception of packet */
1N/A outw(RX_DISCARD_TOP_PACK, BASE + VX_COMMAND);
1N/A while (inw(BASE + VX_STATUS) & S_COMMAND_IN_PROGRESS);
1N/A#ifdef EDEBUG
1N/A{
1N/A unsigned short type = 0; /* used by EDEBUG */
1N/A type = (nic->packet[12]<<8) | nic->packet[13];
1N/A if(nic->packet[0]+nic->packet[1]+nic->packet[2]+nic->packet[3]+nic->packet[4]+
1N/A nic->packet[5] == 0xFF*ETH_ALEN)
1N/A printf(",t=%hX,b]",type);
1N/A else
1N/A printf(",t=%hX]",type);
1N/A}
1N/A#endif
1N/A return 1;
1N/A}
1N/A
1N/A
1N/A/*************************************************************************
1N/A 3Com 595 - specific routines
1N/A**************************************************************************/
1N/A
1N/Astatic int
1N/Aeeprom_rdy()
1N/A{
1N/A int i;
1N/A
1N/A for (i = 0; is_eeprom_busy(BASE) && i < MAX_EEPROMBUSY; i++)
1N/A udelay(1000);
1N/A if (i >= MAX_EEPROMBUSY) {
1N/A /* printf("3c595: eeprom failed to come ready.\n"); */
1N/A printf("3c595: eeprom is busy.\n"); /* memory in EPROM is tight */
1N/A return (0);
1N/A }
1N/A return (1);
1N/A}
1N/A
1N/A/*
1N/A * get_e: gets a 16 bits word from the EEPROM. we must have set the window
1N/A * before
1N/A */
1N/Astatic int
1N/Aget_e(offset)
1N/Aint offset;
1N/A{
1N/A if (!eeprom_rdy())
1N/A return (0xffff);
1N/A outw(EEPROM_CMD_RD | offset, BASE + VX_W0_EEPROM_COMMAND);
1N/A if (!eeprom_rdy())
1N/A return (0xffff);
1N/A return (inw(BASE + VX_W0_EEPROM_DATA));
1N/A}
1N/A
1N/Astatic void
1N/Avxgetlink(void)
1N/A{
1N/A int n, k;
1N/A
1N/A GO_WINDOW(3);
1N/A vx_connectors = inw(BASE + VX_W3_RESET_OPT) & 0x7f;
1N/A for (n = 0, k = 0; k < VX_CONNECTORS; k++) {
1N/A if (vx_connectors & conn_tab[k].bit) {
1N/A if (n > 0) {
1N/A printf("/");
1N/A }
1N/A printf(conn_tab[k].name);
1N/A n++;
1N/A }
1N/A }
1N/A if (vx_connectors == 0) {
1N/A printf("no connectors!");
1N/A return;
1N/A }
1N/A GO_WINDOW(3);
1N/A vx_connector = (inl(BASE + VX_W3_INTERNAL_CFG)
1N/A & INTERNAL_CONNECTOR_MASK)
1N/A >> INTERNAL_CONNECTOR_BITS;
1N/A if (vx_connector & 0x10) {
1N/A vx_connector &= 0x0f;
1N/A printf("[*%s*]", conn_tab[vx_connector].name);
1N/A printf(": disable 'auto select' with DOS util!");
1N/A } else {
1N/A printf("[*%s*]", conn_tab[vx_connector].name);
1N/A }
1N/A}
1N/A
1N/Astatic void
1N/Avxsetlink(void)
1N/A{
1N/A int i, j;
1N/A char *reason, *warning;
1N/A static char prev_conn = -1;
1N/A
1N/A if (prev_conn == -1) {
1N/A prev_conn = vx_connector;
1N/A }
1N/A
1N/A i = vx_connector; /* default in EEPROM */
1N/A reason = "default";
1N/A warning = 0;
1N/A
1N/A if ((vx_connectors & conn_tab[vx_connector].bit) == 0) {
1N/A warning = "strange connector type in EEPROM.";
1N/A reason = "forced";
1N/A i = CONNECTOR_UTP;
1N/A }
1N/A
1N/A if (warning != 0) {
1N/A printf("warning: %s\n", warning);
1N/A }
1N/A printf("selected %s. (%s)\n", conn_tab[i].name, reason);
1N/A
1N/A /* Set the selected connector. */
1N/A GO_WINDOW(3);
1N/A j = inl(BASE + VX_W3_INTERNAL_CFG) & ~INTERNAL_CONNECTOR_MASK;
1N/A outl(j | (i <<INTERNAL_CONNECTOR_BITS), BASE + VX_W3_INTERNAL_CFG);
1N/A
1N/A /* First, disable all. */
1N/A outw(STOP_TRANSCEIVER, BASE + VX_COMMAND);
1N/A udelay(8000);
1N/A GO_WINDOW(4);
1N/A outw(0, BASE + VX_W4_MEDIA_TYPE);
1N/A
1N/A /* Second, enable the selected one. */
1N/A switch(i) {
1N/A case CONNECTOR_UTP:
1N/A GO_WINDOW(4);
1N/A outw(ENABLE_UTP, BASE + VX_W4_MEDIA_TYPE);
1N/A break;
1N/A case CONNECTOR_BNC:
1N/A outw(START_TRANSCEIVER,BASE + VX_COMMAND);
1N/A udelay(8000);
1N/A break;
1N/A case CONNECTOR_TX:
1N/A case CONNECTOR_FX:
1N/A GO_WINDOW(4);
1N/A outw(LINKBEAT_ENABLE, BASE + VX_W4_MEDIA_TYPE);
1N/A break;
1N/A default: /* AUI and MII fall here */
1N/A break;
1N/A }
1N/A GO_WINDOW(1);
1N/A}
1N/A
1N/Astatic void t595_disable(struct dev *dev)
1N/A{
1N/A struct nic *nic = (struct nic *)dev;
1N/A t595_reset(nic);
1N/A
1N/A outw(STOP_TRANSCEIVER, BASE + VX_COMMAND);
1N/A udelay(8000);
1N/A GO_WINDOW(4);
1N/A outw(0, BASE + VX_W4_MEDIA_TYPE);
1N/A GO_WINDOW(1);
1N/A}
1N/A
1N/Astatic void t595_irq(struct nic *nic __unused, irq_action_t action __unused)
1N/A{
1N/A switch ( action ) {
1N/A case DISABLE :
1N/A break;
1N/A case ENABLE :
1N/A break;
1N/A case FORCE :
1N/A break;
1N/A }
1N/A}
1N/A
1N/A/**************************************************************************
1N/AETH_PROBE - Look for an adapter
1N/A***************************************************************************/
1N/Astatic int t595_probe(struct dev *dev, struct pci_device *pci)
1N/A{
1N/A struct nic *nic = (struct nic *)dev;
1N/A int i;
1N/A unsigned short *p;
1N/A
1N/A if (pci->ioaddr == 0)
1N/A return 0;
1N/A/* eth_nic_base = probeaddrs[0] & ~3; */
1N/A eth_nic_base = pci->ioaddr;
1N/A
1N/A nic->irqno = 0;
1N/A nic->ioaddr = pci->ioaddr & ~3;
1N/A
1N/A GO_WINDOW(0);
1N/A outw(GLOBAL_RESET, BASE + VX_COMMAND);
1N/A VX_BUSY_WAIT;
1N/A
1N/A vxgetlink();
1N/A
1N/A/*
1N/A printf("\nEEPROM:");
1N/A for (i = 0; i < (EEPROMSIZE/2); i++) {
1N/A printf("%hX:", get_e(i));
1N/A }
1N/A printf("\n");
1N/A*/
1N/A /*
1N/A * Read the station address from the eeprom
1N/A */
1N/A p = (unsigned short *) nic->node_addr;
1N/A for (i = 0; i < 3; i++) {
1N/A GO_WINDOW(0);
1N/A p[i] = htons(get_e(EEPROM_OEM_ADDR_0 + i));
1N/A GO_WINDOW(2);
1N/A outw(ntohs(p[i]), BASE + VX_W2_ADDR_0 + (i * 2));
1N/A }
1N/A
1N/A printf("Ethernet address: %!\n", nic->node_addr);
1N/A
1N/A t595_reset(nic);
1N/A dev->disable = t595_disable;
1N/A nic->poll = t595_poll;
1N/A nic->transmit = t595_transmit;
1N/A nic->irq = t595_irq;
1N/A return 1;
1N/A
1N/A}
1N/A
1N/Astatic struct pci_id t595_nics[] = {
1N/APCI_ROM(0x10b7, 0x5900, "3c590", "3Com590"), /* Vortex 10Mbps */
1N/APCI_ROM(0x10b7, 0x5950, "3c595", "3Com595"), /* Vortex 100baseTx */
1N/APCI_ROM(0x10b7, 0x5951, "3c595-1", "3Com595"), /* Vortex 100baseT4 */
1N/APCI_ROM(0x10b7, 0x5952, "3c595-2", "3Com595"), /* Vortex 100base-MII */
1N/APCI_ROM(0x10b7, 0x9000, "3c900-tpo", "3Com900-TPO"), /* 10 Base TPO */
1N/APCI_ROM(0x10b7, 0x9001, "3c900-t4", "3Com900-Combo"), /* 10/100 T4 */
1N/APCI_ROM(0x10b7, 0x9004, "3c900b-tpo", "3Com900B-TPO"), /* 10 Base TPO */
1N/APCI_ROM(0x10b7, 0x9005, "3c900b-combo", "3Com900B-Combo"), /* 10 Base Combo */
1N/APCI_ROM(0x10b7, 0x9006, "3c900b-tpb2", "3Com900B-2/T"), /* 10 Base TP and Base2 */
1N/APCI_ROM(0x10b7, 0x900a, "3c900b-fl", "3Com900B-FL"), /* 10 Base F */
1N/APCI_ROM(0x10b7, 0x9800, "3c980-cyclone-1", "3Com980-Cyclone"), /* Cyclone */
1N/APCI_ROM(0x10b7, 0x9805, "3c9805-1", "3Com9805"), /* Dual Port Server Cyclone */
1N/APCI_ROM(0x10b7, 0x7646, "3csoho100-tx-1", "3CSOHO100-TX"), /* Hurricane */
1N/APCI_ROM(0x10b7, 0x4500, "3c450-1", "3Com450 HomePNA Tornado"),
1N/A};
1N/A
1N/Astruct pci_driver t595_driver = {
1N/A .type = NIC_DRIVER,
1N/A .name = "3C595",
1N/A .probe = t595_probe,
1N/A .ids = t595_nics,
1N/A .id_count = sizeof(t595_nics)/sizeof(t595_nics[0]),
1N/A .class = 0,
1N/A};
1N/A
1N/A/*
1N/A * Local variables:
1N/A * c-basic-offset: 8
1N/A * End:
1N/A */
1N/A