17c478bd9Sstevel@tonic-gate #ifdef ALLMULTI
27c478bd9Sstevel@tonic-gate #error multicast support is not yet implemented
37c478bd9Sstevel@tonic-gate #endif
47c478bd9Sstevel@tonic-gate /*
57c478bd9Sstevel@tonic-gate DAVICOM DM9009/DM9102/DM9102A Etherboot Driver V1.00
67c478bd9Sstevel@tonic-gate
77c478bd9Sstevel@tonic-gate This driver was ported from Marty Connor's Tulip Etherboot driver.
87c478bd9Sstevel@tonic-gate Thanks Marty Connor (mdc@etherboot.org)
97c478bd9Sstevel@tonic-gate
107c478bd9Sstevel@tonic-gate This davicom etherboot driver supports DM9009/DM9102/DM9102A/
117c478bd9Sstevel@tonic-gate DM9102A+DM9801/DM9102A+DM9802 NICs.
127c478bd9Sstevel@tonic-gate
137c478bd9Sstevel@tonic-gate This software may be used and distributed according to the terms
147c478bd9Sstevel@tonic-gate of the GNU Public License, incorporated herein by reference.
157c478bd9Sstevel@tonic-gate
167c478bd9Sstevel@tonic-gate */
177c478bd9Sstevel@tonic-gate
187c478bd9Sstevel@tonic-gate /*********************************************************************/
197c478bd9Sstevel@tonic-gate /* Revision History */
207c478bd9Sstevel@tonic-gate /*********************************************************************/
217c478bd9Sstevel@tonic-gate
227c478bd9Sstevel@tonic-gate /*
237c478bd9Sstevel@tonic-gate 19 OCT 2000 Sten 1.00
247c478bd9Sstevel@tonic-gate Different half and full duplex mode
257c478bd9Sstevel@tonic-gate Do the different programming for DM9801/DM9802
267c478bd9Sstevel@tonic-gate
277c478bd9Sstevel@tonic-gate 12 OCT 2000 Sten 0.90
287c478bd9Sstevel@tonic-gate This driver was ported from tulip driver and it
297c478bd9Sstevel@tonic-gate has the following difference.
307c478bd9Sstevel@tonic-gate Changed symbol tulip/TULIP to davicom/DAVICOM
317c478bd9Sstevel@tonic-gate Deleted some code that did not use in this driver.
327c478bd9Sstevel@tonic-gate Used chain-strcture to replace ring structure
337c478bd9Sstevel@tonic-gate for both TX/RX descriptor.
347c478bd9Sstevel@tonic-gate Allocated two tx descriptor.
357c478bd9Sstevel@tonic-gate According current media mode to set operating
367c478bd9Sstevel@tonic-gate register(CR6)
377c478bd9Sstevel@tonic-gate */
387c478bd9Sstevel@tonic-gate
397c478bd9Sstevel@tonic-gate /*********************************************************************/
407c478bd9Sstevel@tonic-gate /* Declarations */
417c478bd9Sstevel@tonic-gate /*********************************************************************/
427c478bd9Sstevel@tonic-gate
437c478bd9Sstevel@tonic-gate #include "etherboot.h"
447c478bd9Sstevel@tonic-gate #include "nic.h"
457c478bd9Sstevel@tonic-gate #include "pci.h"
467c478bd9Sstevel@tonic-gate
477c478bd9Sstevel@tonic-gate #undef DAVICOM_DEBUG
487c478bd9Sstevel@tonic-gate #undef DAVICOM_DEBUG_WHERE
497c478bd9Sstevel@tonic-gate
507c478bd9Sstevel@tonic-gate #define TX_TIME_OUT 2*TICKS_PER_SEC
517c478bd9Sstevel@tonic-gate
527c478bd9Sstevel@tonic-gate typedef unsigned char u8;
537c478bd9Sstevel@tonic-gate typedef signed char s8;
547c478bd9Sstevel@tonic-gate typedef unsigned short u16;
557c478bd9Sstevel@tonic-gate typedef signed short s16;
567c478bd9Sstevel@tonic-gate typedef unsigned int u32;
577c478bd9Sstevel@tonic-gate typedef signed int s32;
587c478bd9Sstevel@tonic-gate
597c478bd9Sstevel@tonic-gate /* Register offsets for davicom device */
607c478bd9Sstevel@tonic-gate enum davicom_offsets {
617c478bd9Sstevel@tonic-gate CSR0=0, CSR1=0x08, CSR2=0x10, CSR3=0x18, CSR4=0x20, CSR5=0x28,
627c478bd9Sstevel@tonic-gate CSR6=0x30, CSR7=0x38, CSR8=0x40, CSR9=0x48, CSR10=0x50, CSR11=0x58,
637c478bd9Sstevel@tonic-gate CSR12=0x60, CSR13=0x68, CSR14=0x70, CSR15=0x78, CSR16=0x80, CSR20=0xA0
647c478bd9Sstevel@tonic-gate };
657c478bd9Sstevel@tonic-gate
667c478bd9Sstevel@tonic-gate /* EEPROM Address width definitions */
677c478bd9Sstevel@tonic-gate #define EEPROM_ADDRLEN 6
687c478bd9Sstevel@tonic-gate #define EEPROM_SIZE 32 /* 1 << EEPROM_ADDRLEN */
697c478bd9Sstevel@tonic-gate /* Used to be 128, but we only need to read enough to get the MAC
707c478bd9Sstevel@tonic-gate address at bytes 20..25 */
717c478bd9Sstevel@tonic-gate
727c478bd9Sstevel@tonic-gate /* Data Read from the EEPROM */
737c478bd9Sstevel@tonic-gate static unsigned char ee_data[EEPROM_SIZE];
747c478bd9Sstevel@tonic-gate
757c478bd9Sstevel@tonic-gate /* The EEPROM commands include the alway-set leading bit. */
767c478bd9Sstevel@tonic-gate #define EE_WRITE_CMD (5 << addr_len)
777c478bd9Sstevel@tonic-gate #define EE_READ_CMD (6 << addr_len)
787c478bd9Sstevel@tonic-gate #define EE_ERASE_CMD (7 << addr_len)
797c478bd9Sstevel@tonic-gate
807c478bd9Sstevel@tonic-gate /* EEPROM_Ctrl bits. */
817c478bd9Sstevel@tonic-gate #define EE_SHIFT_CLK 0x02 /* EEPROM shift clock. */
827c478bd9Sstevel@tonic-gate #define EE_CS 0x01 /* EEPROM chip select. */
837c478bd9Sstevel@tonic-gate #define EE_DATA_WRITE 0x04 /* EEPROM chip data in. */
847c478bd9Sstevel@tonic-gate #define EE_WRITE_0 0x01
857c478bd9Sstevel@tonic-gate #define EE_WRITE_1 0x05
867c478bd9Sstevel@tonic-gate #define EE_DATA_READ 0x08 /* EEPROM chip data out. */
877c478bd9Sstevel@tonic-gate #define EE_ENB (0x4800 | EE_CS)
887c478bd9Sstevel@tonic-gate
897c478bd9Sstevel@tonic-gate /* Sten 10/11 for phyxcer */
907c478bd9Sstevel@tonic-gate #define PHY_DATA_0 0x0
917c478bd9Sstevel@tonic-gate #define PHY_DATA_1 0x20000
927c478bd9Sstevel@tonic-gate #define MDCLKH 0x10000
937c478bd9Sstevel@tonic-gate
947c478bd9Sstevel@tonic-gate /* Delay between EEPROM clock transitions. Even at 33Mhz current PCI
957c478bd9Sstevel@tonic-gate implementations don't overrun the EEPROM clock. We add a bus
967c478bd9Sstevel@tonic-gate turn-around to insure that this remains true. */
977c478bd9Sstevel@tonic-gate #define eeprom_delay() inl(ee_addr)
987c478bd9Sstevel@tonic-gate
997c478bd9Sstevel@tonic-gate /* helpful macro if on a big_endian machine for changing byte order.
1007c478bd9Sstevel@tonic-gate not strictly needed on Intel
1017c478bd9Sstevel@tonic-gate Already defined in Etherboot includes
1027c478bd9Sstevel@tonic-gate #define le16_to_cpu(val) (val)
1037c478bd9Sstevel@tonic-gate */
1047c478bd9Sstevel@tonic-gate
1057c478bd9Sstevel@tonic-gate /* transmit and receive descriptor format */
1067c478bd9Sstevel@tonic-gate struct txdesc {
1077c478bd9Sstevel@tonic-gate volatile unsigned long status; /* owner, status */
1087c478bd9Sstevel@tonic-gate unsigned long buf1sz:11, /* size of buffer 1 */
1097c478bd9Sstevel@tonic-gate buf2sz:11, /* size of buffer 2 */
1107c478bd9Sstevel@tonic-gate control:10; /* control bits */
1117c478bd9Sstevel@tonic-gate const unsigned char *buf1addr; /* buffer 1 address */
1127c478bd9Sstevel@tonic-gate const unsigned char *buf2addr; /* buffer 2 address */
1137c478bd9Sstevel@tonic-gate };
1147c478bd9Sstevel@tonic-gate
1157c478bd9Sstevel@tonic-gate struct rxdesc {
1167c478bd9Sstevel@tonic-gate volatile unsigned long status; /* owner, status */
1177c478bd9Sstevel@tonic-gate unsigned long buf1sz:11, /* size of buffer 1 */
1187c478bd9Sstevel@tonic-gate buf2sz:11, /* size of buffer 2 */
1197c478bd9Sstevel@tonic-gate control:10; /* control bits */
1207c478bd9Sstevel@tonic-gate unsigned char *buf1addr; /* buffer 1 address */
1217c478bd9Sstevel@tonic-gate unsigned char *buf2addr; /* buffer 2 address */
1227c478bd9Sstevel@tonic-gate };
1237c478bd9Sstevel@tonic-gate
1247c478bd9Sstevel@tonic-gate /* Size of transmit and receive buffers */
1257c478bd9Sstevel@tonic-gate #define BUFLEN 1536
1267c478bd9Sstevel@tonic-gate
1277c478bd9Sstevel@tonic-gate /*********************************************************************/
1287c478bd9Sstevel@tonic-gate /* Global Storage */
1297c478bd9Sstevel@tonic-gate /*********************************************************************/
1307c478bd9Sstevel@tonic-gate
1317c478bd9Sstevel@tonic-gate /* PCI Bus parameters */
1327c478bd9Sstevel@tonic-gate static unsigned short vendor, dev_id;
1337c478bd9Sstevel@tonic-gate static unsigned long ioaddr;
1347c478bd9Sstevel@tonic-gate
1357c478bd9Sstevel@tonic-gate /* Note: transmit and receive buffers must be longword aligned and
1367c478bd9Sstevel@tonic-gate longword divisable */
1377c478bd9Sstevel@tonic-gate
1387c478bd9Sstevel@tonic-gate /* transmit descriptor and buffer */
1397c478bd9Sstevel@tonic-gate #define NTXD 2
1407c478bd9Sstevel@tonic-gate static struct txdesc txd[NTXD] __attribute__ ((aligned(4)));
1417c478bd9Sstevel@tonic-gate static unsigned char txb[BUFLEN] __attribute__ ((aligned(4)));
1427c478bd9Sstevel@tonic-gate
1437c478bd9Sstevel@tonic-gate /* receive descriptor(s) and buffer(s) */
1447c478bd9Sstevel@tonic-gate #define NRXD 4
1457c478bd9Sstevel@tonic-gate static struct rxdesc rxd[NRXD] __attribute__ ((aligned(4)));
1467c478bd9Sstevel@tonic-gate static unsigned char rxb[NRXD * BUFLEN] __attribute__ ((aligned(4)));
1477c478bd9Sstevel@tonic-gate static int rxd_tail;
1487c478bd9Sstevel@tonic-gate static int TxPtr;
1497c478bd9Sstevel@tonic-gate
1507c478bd9Sstevel@tonic-gate
1517c478bd9Sstevel@tonic-gate /*********************************************************************/
1527c478bd9Sstevel@tonic-gate /* Function Prototypes */
1537c478bd9Sstevel@tonic-gate /*********************************************************************/
1547c478bd9Sstevel@tonic-gate static void whereami(const char *str);
1557c478bd9Sstevel@tonic-gate static int read_eeprom(unsigned long ioaddr, int location, int addr_len);
1567c478bd9Sstevel@tonic-gate static int davicom_probe(struct dev *dev, struct pci_device *pci);
1577c478bd9Sstevel@tonic-gate static void davicom_init_chain(struct nic *nic); /* Sten 10/9 */
1587c478bd9Sstevel@tonic-gate static void davicom_reset(struct nic *nic);
1597c478bd9Sstevel@tonic-gate static void davicom_transmit(struct nic *nic, const char *d, unsigned int t,
1607c478bd9Sstevel@tonic-gate unsigned int s, const char *p);
1617c478bd9Sstevel@tonic-gate static int davicom_poll(struct nic *nic, int retrieve);
1627c478bd9Sstevel@tonic-gate static void davicom_disable(struct dev *dev);
1637c478bd9Sstevel@tonic-gate #ifdef DAVICOM_DEBUG
1647c478bd9Sstevel@tonic-gate static void davicom_more(void);
1657c478bd9Sstevel@tonic-gate #endif /* DAVICOM_DEBUG */
1667c478bd9Sstevel@tonic-gate static void davicom_wait(unsigned int nticks);
1677c478bd9Sstevel@tonic-gate static int phy_read(int);
1687c478bd9Sstevel@tonic-gate static void phy_write(int, u16);
1697c478bd9Sstevel@tonic-gate static void phy_write_1bit(u32, u32);
1707c478bd9Sstevel@tonic-gate static int phy_read_1bit(u32);
1717c478bd9Sstevel@tonic-gate static void davicom_media_chk(struct nic *);
1727c478bd9Sstevel@tonic-gate
1737c478bd9Sstevel@tonic-gate
1747c478bd9Sstevel@tonic-gate /*********************************************************************/
1757c478bd9Sstevel@tonic-gate /* Utility Routines */
1767c478bd9Sstevel@tonic-gate /*********************************************************************/
whereami(const char * str)1777c478bd9Sstevel@tonic-gate static inline void whereami(const char *str)
1787c478bd9Sstevel@tonic-gate {
1797c478bd9Sstevel@tonic-gate printf("%s\n", str);
1807c478bd9Sstevel@tonic-gate /* sleep(2); */
1817c478bd9Sstevel@tonic-gate }
1827c478bd9Sstevel@tonic-gate
1837c478bd9Sstevel@tonic-gate #ifdef DAVICOM_DEBUG
davicom_more()1847c478bd9Sstevel@tonic-gate static void davicom_more()
1857c478bd9Sstevel@tonic-gate {
1867c478bd9Sstevel@tonic-gate printf("\n\n-- more --");
1877c478bd9Sstevel@tonic-gate while (!iskey())
1887c478bd9Sstevel@tonic-gate /* wait */;
1897c478bd9Sstevel@tonic-gate getchar();
1907c478bd9Sstevel@tonic-gate printf("\n\n");
1917c478bd9Sstevel@tonic-gate }
1927c478bd9Sstevel@tonic-gate #endif /* DAVICOM_DEBUG */
1937c478bd9Sstevel@tonic-gate
davicom_wait(unsigned int nticks)1947c478bd9Sstevel@tonic-gate static void davicom_wait(unsigned int nticks)
1957c478bd9Sstevel@tonic-gate {
1967c478bd9Sstevel@tonic-gate unsigned int to = currticks() + nticks;
1977c478bd9Sstevel@tonic-gate while (currticks() < to)
1987c478bd9Sstevel@tonic-gate /* wait */ ;
1997c478bd9Sstevel@tonic-gate }
2007c478bd9Sstevel@tonic-gate
2017c478bd9Sstevel@tonic-gate
2027c478bd9Sstevel@tonic-gate /*********************************************************************/
2037c478bd9Sstevel@tonic-gate /* For DAVICOM phyxcer register by MII interface */
2047c478bd9Sstevel@tonic-gate /*********************************************************************/
2057c478bd9Sstevel@tonic-gate /*
2067c478bd9Sstevel@tonic-gate Read a word data from phy register
2077c478bd9Sstevel@tonic-gate */
phy_read(int location)2087c478bd9Sstevel@tonic-gate static int phy_read(int location)
2097c478bd9Sstevel@tonic-gate {
2107c478bd9Sstevel@tonic-gate int i, phy_addr=1;
2117c478bd9Sstevel@tonic-gate u16 phy_data;
2127c478bd9Sstevel@tonic-gate u32 io_dcr9;
2137c478bd9Sstevel@tonic-gate
2147c478bd9Sstevel@tonic-gate whereami("phy_read\n");
2157c478bd9Sstevel@tonic-gate
2167c478bd9Sstevel@tonic-gate io_dcr9 = ioaddr + CSR9;
2177c478bd9Sstevel@tonic-gate
2187c478bd9Sstevel@tonic-gate /* Send 33 synchronization clock to Phy controller */
2197c478bd9Sstevel@tonic-gate for (i=0; i<34; i++)
2207c478bd9Sstevel@tonic-gate phy_write_1bit(io_dcr9, PHY_DATA_1);
2217c478bd9Sstevel@tonic-gate
2227c478bd9Sstevel@tonic-gate /* Send start command(01) to Phy */
2237c478bd9Sstevel@tonic-gate phy_write_1bit(io_dcr9, PHY_DATA_0);
2247c478bd9Sstevel@tonic-gate phy_write_1bit(io_dcr9, PHY_DATA_1);
2257c478bd9Sstevel@tonic-gate
2267c478bd9Sstevel@tonic-gate /* Send read command(10) to Phy */
2277c478bd9Sstevel@tonic-gate phy_write_1bit(io_dcr9, PHY_DATA_1);
2287c478bd9Sstevel@tonic-gate phy_write_1bit(io_dcr9, PHY_DATA_0);
2297c478bd9Sstevel@tonic-gate
2307c478bd9Sstevel@tonic-gate /* Send Phy addres */
2317c478bd9Sstevel@tonic-gate for (i=0x10; i>0; i=i>>1)
2327c478bd9Sstevel@tonic-gate phy_write_1bit(io_dcr9, phy_addr&i ? PHY_DATA_1: PHY_DATA_0);
2337c478bd9Sstevel@tonic-gate
2347c478bd9Sstevel@tonic-gate /* Send register addres */
2357c478bd9Sstevel@tonic-gate for (i=0x10; i>0; i=i>>1)
2367c478bd9Sstevel@tonic-gate phy_write_1bit(io_dcr9, location&i ? PHY_DATA_1: PHY_DATA_0);
2377c478bd9Sstevel@tonic-gate
2387c478bd9Sstevel@tonic-gate /* Skip transition state */
2397c478bd9Sstevel@tonic-gate phy_read_1bit(io_dcr9);
2407c478bd9Sstevel@tonic-gate
2417c478bd9Sstevel@tonic-gate /* read 16bit data */
2427c478bd9Sstevel@tonic-gate for (phy_data=0, i=0; i<16; i++) {
2437c478bd9Sstevel@tonic-gate phy_data<<=1;
2447c478bd9Sstevel@tonic-gate phy_data|=phy_read_1bit(io_dcr9);
2457c478bd9Sstevel@tonic-gate }
2467c478bd9Sstevel@tonic-gate
2477c478bd9Sstevel@tonic-gate return phy_data;
2487c478bd9Sstevel@tonic-gate }
2497c478bd9Sstevel@tonic-gate
2507c478bd9Sstevel@tonic-gate /*
2517c478bd9Sstevel@tonic-gate Write a word to Phy register
2527c478bd9Sstevel@tonic-gate */
phy_write(int location,u16 phy_data)2537c478bd9Sstevel@tonic-gate static void phy_write(int location, u16 phy_data)
2547c478bd9Sstevel@tonic-gate {
2557c478bd9Sstevel@tonic-gate u16 i, phy_addr=1;
2567c478bd9Sstevel@tonic-gate u32 io_dcr9;
2577c478bd9Sstevel@tonic-gate
2587c478bd9Sstevel@tonic-gate whereami("phy_write\n");
2597c478bd9Sstevel@tonic-gate
2607c478bd9Sstevel@tonic-gate io_dcr9 = ioaddr + CSR9;
2617c478bd9Sstevel@tonic-gate
2627c478bd9Sstevel@tonic-gate /* Send 33 synchronization clock to Phy controller */
2637c478bd9Sstevel@tonic-gate for (i=0; i<34; i++)
2647c478bd9Sstevel@tonic-gate phy_write_1bit(io_dcr9, PHY_DATA_1);
2657c478bd9Sstevel@tonic-gate
2667c478bd9Sstevel@tonic-gate /* Send start command(01) to Phy */
2677c478bd9Sstevel@tonic-gate phy_write_1bit(io_dcr9, PHY_DATA_0);
2687c478bd9Sstevel@tonic-gate phy_write_1bit(io_dcr9, PHY_DATA_1);
2697c478bd9Sstevel@tonic-gate
2707c478bd9Sstevel@tonic-gate /* Send write command(01) to Phy */
2717c478bd9Sstevel@tonic-gate phy_write_1bit(io_dcr9, PHY_DATA_0);
2727c478bd9Sstevel@tonic-gate phy_write_1bit(io_dcr9, PHY_DATA_1);
2737c478bd9Sstevel@tonic-gate
2747c478bd9Sstevel@tonic-gate /* Send Phy addres */
2757c478bd9Sstevel@tonic-gate for (i=0x10; i>0; i=i>>1)
2767c478bd9Sstevel@tonic-gate phy_write_1bit(io_dcr9, phy_addr&i ? PHY_DATA_1: PHY_DATA_0);
2777c478bd9Sstevel@tonic-gate
2787c478bd9Sstevel@tonic-gate /* Send register addres */
2797c478bd9Sstevel@tonic-gate for (i=0x10; i>0; i=i>>1)
2807c478bd9Sstevel@tonic-gate phy_write_1bit(io_dcr9, location&i ? PHY_DATA_1: PHY_DATA_0);
2817c478bd9Sstevel@tonic-gate
2827c478bd9Sstevel@tonic-gate /* written trasnition */
2837c478bd9Sstevel@tonic-gate phy_write_1bit(io_dcr9, PHY_DATA_1);
2847c478bd9Sstevel@tonic-gate phy_write_1bit(io_dcr9, PHY_DATA_0);
2857c478bd9Sstevel@tonic-gate
2867c478bd9Sstevel@tonic-gate /* Write a word data to PHY controller */
2877c478bd9Sstevel@tonic-gate for (i=0x8000; i>0; i>>=1)
2887c478bd9Sstevel@tonic-gate phy_write_1bit(io_dcr9, phy_data&i ? PHY_DATA_1: PHY_DATA_0);
2897c478bd9Sstevel@tonic-gate }
2907c478bd9Sstevel@tonic-gate
2917c478bd9Sstevel@tonic-gate /*
2927c478bd9Sstevel@tonic-gate Write one bit data to Phy Controller
2937c478bd9Sstevel@tonic-gate */
phy_write_1bit(u32 ee_addr,u32 phy_data)2947c478bd9Sstevel@tonic-gate static void phy_write_1bit(u32 ee_addr, u32 phy_data)
2957c478bd9Sstevel@tonic-gate {
2967c478bd9Sstevel@tonic-gate whereami("phy_write_1bit\n");
2977c478bd9Sstevel@tonic-gate outl(phy_data, ee_addr); /* MII Clock Low */
2987c478bd9Sstevel@tonic-gate eeprom_delay();
2997c478bd9Sstevel@tonic-gate outl(phy_data|MDCLKH, ee_addr); /* MII Clock High */
3007c478bd9Sstevel@tonic-gate eeprom_delay();
3017c478bd9Sstevel@tonic-gate outl(phy_data, ee_addr); /* MII Clock Low */
3027c478bd9Sstevel@tonic-gate eeprom_delay();
3037c478bd9Sstevel@tonic-gate }
3047c478bd9Sstevel@tonic-gate
3057c478bd9Sstevel@tonic-gate /*
3067c478bd9Sstevel@tonic-gate Read one bit phy data from PHY controller
3077c478bd9Sstevel@tonic-gate */
phy_read_1bit(u32 ee_addr)3087c478bd9Sstevel@tonic-gate static int phy_read_1bit(u32 ee_addr)
3097c478bd9Sstevel@tonic-gate {
3107c478bd9Sstevel@tonic-gate int phy_data;
3117c478bd9Sstevel@tonic-gate
3127c478bd9Sstevel@tonic-gate whereami("phy_read_1bit\n");
3137c478bd9Sstevel@tonic-gate
3147c478bd9Sstevel@tonic-gate outl(0x50000, ee_addr);
3157c478bd9Sstevel@tonic-gate eeprom_delay();
3167c478bd9Sstevel@tonic-gate
3177c478bd9Sstevel@tonic-gate phy_data=(inl(ee_addr)>>19) & 0x1;
3187c478bd9Sstevel@tonic-gate
3197c478bd9Sstevel@tonic-gate outl(0x40000, ee_addr);
3207c478bd9Sstevel@tonic-gate eeprom_delay();
3217c478bd9Sstevel@tonic-gate
3227c478bd9Sstevel@tonic-gate return phy_data;
3237c478bd9Sstevel@tonic-gate }
3247c478bd9Sstevel@tonic-gate
3257c478bd9Sstevel@tonic-gate /*
3267c478bd9Sstevel@tonic-gate DM9801/DM9802 present check and program
3277c478bd9Sstevel@tonic-gate */
HPNA_process(void)3287c478bd9Sstevel@tonic-gate static void HPNA_process(void)
3297c478bd9Sstevel@tonic-gate {
3307c478bd9Sstevel@tonic-gate
3317c478bd9Sstevel@tonic-gate if ( (phy_read(3) & 0xfff0) == 0xb900 ) {
3327c478bd9Sstevel@tonic-gate if ( phy_read(31) == 0x4404 ) {
3337c478bd9Sstevel@tonic-gate /* DM9801 present */
3347c478bd9Sstevel@tonic-gate if (phy_read(3) == 0xb901)
3357c478bd9Sstevel@tonic-gate phy_write(16, 0x5); /* DM9801 E4 */
3367c478bd9Sstevel@tonic-gate else
3377c478bd9Sstevel@tonic-gate phy_write(16, 0x1005); /* DM9801 E3 and others */
3387c478bd9Sstevel@tonic-gate phy_write(25, ((phy_read(24) + 3) & 0xff) | 0xf000);
3397c478bd9Sstevel@tonic-gate } else {
3407c478bd9Sstevel@tonic-gate /* DM9802 present */
3417c478bd9Sstevel@tonic-gate phy_write(16, 0x5);
3427c478bd9Sstevel@tonic-gate phy_write(25, (phy_read(25) & 0xff00) + 2);
3437c478bd9Sstevel@tonic-gate }
3447c478bd9Sstevel@tonic-gate }
3457c478bd9Sstevel@tonic-gate }
3467c478bd9Sstevel@tonic-gate
3477c478bd9Sstevel@tonic-gate /*
3487c478bd9Sstevel@tonic-gate Sense media mode and set CR6
3497c478bd9Sstevel@tonic-gate */
davicom_media_chk(struct nic * nic __unused)3507c478bd9Sstevel@tonic-gate static void davicom_media_chk(struct nic * nic __unused)
3517c478bd9Sstevel@tonic-gate {
3527c478bd9Sstevel@tonic-gate unsigned long to, csr6;
3537c478bd9Sstevel@tonic-gate
3547c478bd9Sstevel@tonic-gate csr6 = 0x00200000; /* SF */
3557c478bd9Sstevel@tonic-gate outl(csr6, ioaddr + CSR6);
3567c478bd9Sstevel@tonic-gate
3577c478bd9Sstevel@tonic-gate if (vendor == PCI_VENDOR_ID_DAVICOM && dev_id == PCI_DEVICE_ID_DM9009) {
3587c478bd9Sstevel@tonic-gate /* Set to 10BaseT mode for DM9009 */
3597c478bd9Sstevel@tonic-gate phy_write(0, 0);
3607c478bd9Sstevel@tonic-gate } else {
3617c478bd9Sstevel@tonic-gate /* For DM9102/DM9102A */
3627c478bd9Sstevel@tonic-gate to = currticks() + 2 * TICKS_PER_SEC;
3637c478bd9Sstevel@tonic-gate while ( ((phy_read(1) & 0x24)!=0x24) && (currticks() < to))
3647c478bd9Sstevel@tonic-gate /* wait */ ;
3657c478bd9Sstevel@tonic-gate
3667c478bd9Sstevel@tonic-gate if ( (phy_read(1) & 0x24) == 0x24 ) {
3677c478bd9Sstevel@tonic-gate if (phy_read(17) & 0xa000)
3687c478bd9Sstevel@tonic-gate csr6 |= 0x00000200; /* Full Duplex mode */
3697c478bd9Sstevel@tonic-gate } else
3707c478bd9Sstevel@tonic-gate csr6 |= 0x00040000; /* Select DM9801/DM9802 when Ethernet link failed */
3717c478bd9Sstevel@tonic-gate }
3727c478bd9Sstevel@tonic-gate
3737c478bd9Sstevel@tonic-gate /* set the chip's operating mode */
3747c478bd9Sstevel@tonic-gate outl(csr6, ioaddr + CSR6);
3757c478bd9Sstevel@tonic-gate
3767c478bd9Sstevel@tonic-gate /* DM9801/DM9802 present check & program */
3777c478bd9Sstevel@tonic-gate if (csr6 & 0x40000)
3787c478bd9Sstevel@tonic-gate HPNA_process();
3797c478bd9Sstevel@tonic-gate }
3807c478bd9Sstevel@tonic-gate
3817c478bd9Sstevel@tonic-gate
3827c478bd9Sstevel@tonic-gate /*********************************************************************/
3837c478bd9Sstevel@tonic-gate /* EEPROM Reading Code */
3847c478bd9Sstevel@tonic-gate /*********************************************************************/
3857c478bd9Sstevel@tonic-gate /* EEPROM routines adapted from the Linux Tulip Code */
3867c478bd9Sstevel@tonic-gate /* Reading a serial EEPROM is a "bit" grungy, but we work our way
3877c478bd9Sstevel@tonic-gate through:->.
3887c478bd9Sstevel@tonic-gate */
read_eeprom(unsigned long ioaddr,int location,int addr_len)3897c478bd9Sstevel@tonic-gate static int read_eeprom(unsigned long ioaddr, int location, int addr_len)
3907c478bd9Sstevel@tonic-gate {
3917c478bd9Sstevel@tonic-gate int i;
3927c478bd9Sstevel@tonic-gate unsigned short retval = 0;
3937c478bd9Sstevel@tonic-gate long ee_addr = ioaddr + CSR9;
3947c478bd9Sstevel@tonic-gate int read_cmd = location | EE_READ_CMD;
3957c478bd9Sstevel@tonic-gate
3967c478bd9Sstevel@tonic-gate whereami("read_eeprom\n");
3977c478bd9Sstevel@tonic-gate
3987c478bd9Sstevel@tonic-gate outl(EE_ENB & ~EE_CS, ee_addr);
3997c478bd9Sstevel@tonic-gate outl(EE_ENB, ee_addr);
4007c478bd9Sstevel@tonic-gate
4017c478bd9Sstevel@tonic-gate /* Shift the read command bits out. */
4027c478bd9Sstevel@tonic-gate for (i = 4 + addr_len; i >= 0; i--) {
4037c478bd9Sstevel@tonic-gate short dataval = (read_cmd & (1 << i)) ? EE_DATA_WRITE : 0;
4047c478bd9Sstevel@tonic-gate outl(EE_ENB | dataval, ee_addr);
4057c478bd9Sstevel@tonic-gate eeprom_delay();
4067c478bd9Sstevel@tonic-gate outl(EE_ENB | dataval | EE_SHIFT_CLK, ee_addr);
4077c478bd9Sstevel@tonic-gate eeprom_delay();
4087c478bd9Sstevel@tonic-gate }
4097c478bd9Sstevel@tonic-gate outl(EE_ENB, ee_addr);
4107c478bd9Sstevel@tonic-gate
4117c478bd9Sstevel@tonic-gate for (i = 16; i > 0; i--) {
4127c478bd9Sstevel@tonic-gate outl(EE_ENB | EE_SHIFT_CLK, ee_addr);
4137c478bd9Sstevel@tonic-gate eeprom_delay();
4147c478bd9Sstevel@tonic-gate retval = (retval << 1) | ((inl(ee_addr) & EE_DATA_READ) ? 1 : 0);
4157c478bd9Sstevel@tonic-gate outl(EE_ENB, ee_addr);
4167c478bd9Sstevel@tonic-gate eeprom_delay();
4177c478bd9Sstevel@tonic-gate }
4187c478bd9Sstevel@tonic-gate
4197c478bd9Sstevel@tonic-gate /* Terminate the EEPROM access. */
4207c478bd9Sstevel@tonic-gate outl(EE_ENB & ~EE_CS, ee_addr);
4217c478bd9Sstevel@tonic-gate return retval;
4227c478bd9Sstevel@tonic-gate }
4237c478bd9Sstevel@tonic-gate
4247c478bd9Sstevel@tonic-gate /*********************************************************************/
4257c478bd9Sstevel@tonic-gate /* davicom_init_chain - setup the tx and rx descriptors */
4267c478bd9Sstevel@tonic-gate /* Sten 10/9 */
4277c478bd9Sstevel@tonic-gate /*********************************************************************/
davicom_init_chain(struct nic * nic)4287c478bd9Sstevel@tonic-gate static void davicom_init_chain(struct nic *nic)
4297c478bd9Sstevel@tonic-gate {
4307c478bd9Sstevel@tonic-gate int i;
4317c478bd9Sstevel@tonic-gate
4327c478bd9Sstevel@tonic-gate /* setup the transmit descriptor */
4337c478bd9Sstevel@tonic-gate /* Sten: Set 2 TX descriptor but use one TX buffer because
4347c478bd9Sstevel@tonic-gate it transmit a packet and wait complete every time. */
4357c478bd9Sstevel@tonic-gate for (i=0; i<NTXD; i++) {
4367c478bd9Sstevel@tonic-gate txd[i].buf1addr = (void *)virt_to_bus(&txb[0]); /* Used same TX buffer */
4377c478bd9Sstevel@tonic-gate txd[i].buf2addr = (void *)virt_to_bus(&txd[i+1]); /* Point to Next TX desc */
4387c478bd9Sstevel@tonic-gate txd[i].buf1sz = 0;
4397c478bd9Sstevel@tonic-gate txd[i].buf2sz = 0;
4407c478bd9Sstevel@tonic-gate txd[i].control = 0x184; /* Begin/End/Chain */
4417c478bd9Sstevel@tonic-gate txd[i].status = 0x00000000; /* give ownership to Host */
4427c478bd9Sstevel@tonic-gate }
4437c478bd9Sstevel@tonic-gate
4447c478bd9Sstevel@tonic-gate /* construct perfect filter frame with mac address as first match
4457c478bd9Sstevel@tonic-gate and broadcast address for all others */
4467c478bd9Sstevel@tonic-gate for (i=0; i<192; i++) txb[i] = 0xFF;
4477c478bd9Sstevel@tonic-gate txb[0] = nic->node_addr[0];
4487c478bd9Sstevel@tonic-gate txb[1] = nic->node_addr[1];
4497c478bd9Sstevel@tonic-gate txb[4] = nic->node_addr[2];
4507c478bd9Sstevel@tonic-gate txb[5] = nic->node_addr[3];
4517c478bd9Sstevel@tonic-gate txb[8] = nic->node_addr[4];
4527c478bd9Sstevel@tonic-gate txb[9] = nic->node_addr[5];
4537c478bd9Sstevel@tonic-gate
4547c478bd9Sstevel@tonic-gate /* setup receive descriptor */
4557c478bd9Sstevel@tonic-gate for (i=0; i<NRXD; i++) {
4567c478bd9Sstevel@tonic-gate rxd[i].buf1addr = (void *)virt_to_bus(&rxb[i * BUFLEN]);
4577c478bd9Sstevel@tonic-gate rxd[i].buf2addr = (void *)virt_to_bus(&rxd[i+1]); /* Point to Next RX desc */
4587c478bd9Sstevel@tonic-gate rxd[i].buf1sz = BUFLEN;
4597c478bd9Sstevel@tonic-gate rxd[i].buf2sz = 0; /* not used */
4607c478bd9Sstevel@tonic-gate rxd[i].control = 0x4; /* Chain Structure */
4617c478bd9Sstevel@tonic-gate rxd[i].status = 0x80000000; /* give ownership to device */
4627c478bd9Sstevel@tonic-gate }
4637c478bd9Sstevel@tonic-gate
4647c478bd9Sstevel@tonic-gate /* Chain the last descriptor to first */
4657c478bd9Sstevel@tonic-gate txd[NTXD - 1].buf2addr = (void *)virt_to_bus(&txd[0]);
4667c478bd9Sstevel@tonic-gate rxd[NRXD - 1].buf2addr = (void *)virt_to_bus(&rxd[0]);
4677c478bd9Sstevel@tonic-gate TxPtr = 0;
4687c478bd9Sstevel@tonic-gate rxd_tail = 0;
4697c478bd9Sstevel@tonic-gate }
4707c478bd9Sstevel@tonic-gate
4717c478bd9Sstevel@tonic-gate
4727c478bd9Sstevel@tonic-gate /*********************************************************************/
4737c478bd9Sstevel@tonic-gate /* davicom_reset - Reset adapter */
4747c478bd9Sstevel@tonic-gate /*********************************************************************/
davicom_reset(struct nic * nic)4757c478bd9Sstevel@tonic-gate static void davicom_reset(struct nic *nic)
4767c478bd9Sstevel@tonic-gate {
4777c478bd9Sstevel@tonic-gate unsigned long to;
4787c478bd9Sstevel@tonic-gate
4797c478bd9Sstevel@tonic-gate whereami("davicom_reset\n");
4807c478bd9Sstevel@tonic-gate
4817c478bd9Sstevel@tonic-gate /* Stop Tx and RX */
4827c478bd9Sstevel@tonic-gate outl(inl(ioaddr + CSR6) & ~0x00002002, ioaddr + CSR6);
4837c478bd9Sstevel@tonic-gate
4847c478bd9Sstevel@tonic-gate /* Reset the chip, holding bit 0 set at least 50 PCI cycles. */
4857c478bd9Sstevel@tonic-gate outl(0x00000001, ioaddr + CSR0);
4867c478bd9Sstevel@tonic-gate
4877c478bd9Sstevel@tonic-gate davicom_wait(TICKS_PER_SEC);
4887c478bd9Sstevel@tonic-gate
4897c478bd9Sstevel@tonic-gate /* TX/RX descriptor burst */
4907c478bd9Sstevel@tonic-gate outl(0x0C00000, ioaddr + CSR0); /* Sten 10/9 */
4917c478bd9Sstevel@tonic-gate
4927c478bd9Sstevel@tonic-gate /* set up transmit and receive descriptors */
4937c478bd9Sstevel@tonic-gate davicom_init_chain(nic); /* Sten 10/9 */
4947c478bd9Sstevel@tonic-gate
4957c478bd9Sstevel@tonic-gate /* Point to receive descriptor */
4967c478bd9Sstevel@tonic-gate outl(virt_to_bus(&rxd[0]), ioaddr + CSR3);
4977c478bd9Sstevel@tonic-gate outl(virt_to_bus(&txd[0]), ioaddr + CSR4); /* Sten 10/9 */
4987c478bd9Sstevel@tonic-gate
4997c478bd9Sstevel@tonic-gate /* According phyxcer media mode to set CR6,
5007c478bd9Sstevel@tonic-gate DM9102/A phyxcer can auto-detect media mode */
5017c478bd9Sstevel@tonic-gate davicom_media_chk(nic);
5027c478bd9Sstevel@tonic-gate
5037c478bd9Sstevel@tonic-gate /* Prepare Setup Frame Sten 10/9 */
5047c478bd9Sstevel@tonic-gate txd[TxPtr].buf1sz = 192;
5057c478bd9Sstevel@tonic-gate txd[TxPtr].control = 0x024; /* SF/CE */
5067c478bd9Sstevel@tonic-gate txd[TxPtr].status = 0x80000000; /* Give ownership to device */
5077c478bd9Sstevel@tonic-gate
5087c478bd9Sstevel@tonic-gate /* Start Tx */
5097c478bd9Sstevel@tonic-gate outl(inl(ioaddr + CSR6) | 0x00002000, ioaddr + CSR6);
5107c478bd9Sstevel@tonic-gate /* immediate transmit demand */
5117c478bd9Sstevel@tonic-gate outl(0, ioaddr + CSR1);
5127c478bd9Sstevel@tonic-gate
5137c478bd9Sstevel@tonic-gate to = currticks() + TX_TIME_OUT;
5147c478bd9Sstevel@tonic-gate while ((txd[TxPtr].status & 0x80000000) && (currticks() < to)) /* Sten 10/9 */
5157c478bd9Sstevel@tonic-gate /* wait */ ;
5167c478bd9Sstevel@tonic-gate
5177c478bd9Sstevel@tonic-gate if (currticks() >= to) {
5187c478bd9Sstevel@tonic-gate printf ("TX Setup Timeout!\n");
5197c478bd9Sstevel@tonic-gate }
5207c478bd9Sstevel@tonic-gate /* Point to next TX descriptor */
5217c478bd9Sstevel@tonic-gate TxPtr = (++TxPtr >= NTXD) ? 0:TxPtr; /* Sten 10/9 */
5227c478bd9Sstevel@tonic-gate
5237c478bd9Sstevel@tonic-gate #ifdef DAVICOM_DEBUG
5247c478bd9Sstevel@tonic-gate printf("txd.status = %X\n", txd.status);
5257c478bd9Sstevel@tonic-gate printf("ticks = %d\n", currticks() - (to - TX_TIME_OUT));
5267c478bd9Sstevel@tonic-gate davicom_more();
5277c478bd9Sstevel@tonic-gate #endif
5287c478bd9Sstevel@tonic-gate
5297c478bd9Sstevel@tonic-gate /* enable RX */
5307c478bd9Sstevel@tonic-gate outl(inl(ioaddr + CSR6) | 0x00000002, ioaddr + CSR6);
5317c478bd9Sstevel@tonic-gate /* immediate poll demand */
5327c478bd9Sstevel@tonic-gate outl(0, ioaddr + CSR2);
5337c478bd9Sstevel@tonic-gate }
5347c478bd9Sstevel@tonic-gate
5357c478bd9Sstevel@tonic-gate
5367c478bd9Sstevel@tonic-gate /*********************************************************************/
5377c478bd9Sstevel@tonic-gate /* eth_transmit - Transmit a frame */
5387c478bd9Sstevel@tonic-gate /*********************************************************************/
davicom_transmit(struct nic * nic,const char * d,unsigned int t,unsigned int s,const char * p)5397c478bd9Sstevel@tonic-gate static void davicom_transmit(struct nic *nic, const char *d, unsigned int t,
5407c478bd9Sstevel@tonic-gate unsigned int s, const char *p)
5417c478bd9Sstevel@tonic-gate {
5427c478bd9Sstevel@tonic-gate unsigned long to;
5437c478bd9Sstevel@tonic-gate
5447c478bd9Sstevel@tonic-gate whereami("davicom_transmit\n");
5457c478bd9Sstevel@tonic-gate
5467c478bd9Sstevel@tonic-gate /* Stop Tx */
5477c478bd9Sstevel@tonic-gate /* outl(inl(ioaddr + CSR6) & ~0x00002000, ioaddr + CSR6); */
5487c478bd9Sstevel@tonic-gate
5497c478bd9Sstevel@tonic-gate /* setup ethernet header */
5507c478bd9Sstevel@tonic-gate memcpy(&txb[0], d, ETH_ALEN); /* DA 6byte */
5517c478bd9Sstevel@tonic-gate memcpy(&txb[ETH_ALEN], nic->node_addr, ETH_ALEN); /* SA 6byte*/
5527c478bd9Sstevel@tonic-gate txb[ETH_ALEN*2] = (t >> 8) & 0xFF; /* Frame type: 2byte */
5537c478bd9Sstevel@tonic-gate txb[ETH_ALEN*2+1] = t & 0xFF;
5547c478bd9Sstevel@tonic-gate memcpy(&txb[ETH_HLEN], p, s); /* Frame data */
5557c478bd9Sstevel@tonic-gate
5567c478bd9Sstevel@tonic-gate /* setup the transmit descriptor */
5577c478bd9Sstevel@tonic-gate txd[TxPtr].buf1sz = ETH_HLEN+s;
5587c478bd9Sstevel@tonic-gate txd[TxPtr].control = 0x00000184; /* LS+FS+CE */
5597c478bd9Sstevel@tonic-gate txd[TxPtr].status = 0x80000000; /* give ownership to device */
5607c478bd9Sstevel@tonic-gate
5617c478bd9Sstevel@tonic-gate /* immediate transmit demand */
5627c478bd9Sstevel@tonic-gate outl(0, ioaddr + CSR1);
5637c478bd9Sstevel@tonic-gate
5647c478bd9Sstevel@tonic-gate to = currticks() + TX_TIME_OUT;
5657c478bd9Sstevel@tonic-gate while ((txd[TxPtr].status & 0x80000000) && (currticks() < to))
5667c478bd9Sstevel@tonic-gate /* wait */ ;
5677c478bd9Sstevel@tonic-gate
5687c478bd9Sstevel@tonic-gate if (currticks() >= to) {
5697c478bd9Sstevel@tonic-gate printf ("TX Timeout!\n");
5707c478bd9Sstevel@tonic-gate }
5717c478bd9Sstevel@tonic-gate
5727c478bd9Sstevel@tonic-gate /* Point to next TX descriptor */
5737c478bd9Sstevel@tonic-gate TxPtr = (++TxPtr >= NTXD) ? 0:TxPtr; /* Sten 10/9 */
5747c478bd9Sstevel@tonic-gate
5757c478bd9Sstevel@tonic-gate }
5767c478bd9Sstevel@tonic-gate
5777c478bd9Sstevel@tonic-gate /*********************************************************************/
5787c478bd9Sstevel@tonic-gate /* eth_poll - Wait for a frame */
5797c478bd9Sstevel@tonic-gate /*********************************************************************/
davicom_poll(struct nic * nic,int retrieve)5807c478bd9Sstevel@tonic-gate static int davicom_poll(struct nic *nic, int retrieve)
5817c478bd9Sstevel@tonic-gate {
5827c478bd9Sstevel@tonic-gate whereami("davicom_poll\n");
5837c478bd9Sstevel@tonic-gate
5847c478bd9Sstevel@tonic-gate if (rxd[rxd_tail].status & 0x80000000)
5857c478bd9Sstevel@tonic-gate return 0;
5867c478bd9Sstevel@tonic-gate
5877c478bd9Sstevel@tonic-gate if ( ! retrieve ) return 1;
5887c478bd9Sstevel@tonic-gate
5897c478bd9Sstevel@tonic-gate whereami("davicom_poll got one\n");
5907c478bd9Sstevel@tonic-gate
5917c478bd9Sstevel@tonic-gate nic->packetlen = (rxd[rxd_tail].status & 0x3FFF0000) >> 16;
5927c478bd9Sstevel@tonic-gate
5937c478bd9Sstevel@tonic-gate if( rxd[rxd_tail].status & 0x00008000){
5947c478bd9Sstevel@tonic-gate rxd[rxd_tail].status = 0x80000000;
5957c478bd9Sstevel@tonic-gate rxd_tail++;
5967c478bd9Sstevel@tonic-gate if (rxd_tail == NRXD) rxd_tail = 0;
5977c478bd9Sstevel@tonic-gate return 0;
5987c478bd9Sstevel@tonic-gate }
5997c478bd9Sstevel@tonic-gate
6007c478bd9Sstevel@tonic-gate /* copy packet to working buffer */
6017c478bd9Sstevel@tonic-gate /* XXX - this copy could be avoided with a little more work
6027c478bd9Sstevel@tonic-gate but for now we are content with it because the optimised
6037c478bd9Sstevel@tonic-gate memcpy is quite fast */
6047c478bd9Sstevel@tonic-gate
6057c478bd9Sstevel@tonic-gate memcpy(nic->packet, rxb + rxd_tail * BUFLEN, nic->packetlen);
6067c478bd9Sstevel@tonic-gate
6077c478bd9Sstevel@tonic-gate /* return the descriptor and buffer to receive ring */
6087c478bd9Sstevel@tonic-gate rxd[rxd_tail].status = 0x80000000;
6097c478bd9Sstevel@tonic-gate rxd_tail++;
6107c478bd9Sstevel@tonic-gate if (rxd_tail == NRXD) rxd_tail = 0;
6117c478bd9Sstevel@tonic-gate
6127c478bd9Sstevel@tonic-gate return 1;
6137c478bd9Sstevel@tonic-gate }
6147c478bd9Sstevel@tonic-gate
6157c478bd9Sstevel@tonic-gate /*********************************************************************/
6167c478bd9Sstevel@tonic-gate /* eth_disable - Disable the interface */
6177c478bd9Sstevel@tonic-gate /*********************************************************************/
davicom_disable(struct dev * dev)6187c478bd9Sstevel@tonic-gate static void davicom_disable(struct dev *dev)
6197c478bd9Sstevel@tonic-gate {
6207c478bd9Sstevel@tonic-gate struct nic *nic = (struct nic *)dev;
6217c478bd9Sstevel@tonic-gate whereami("davicom_disable\n");
6227c478bd9Sstevel@tonic-gate
6237c478bd9Sstevel@tonic-gate davicom_reset(nic);
6247c478bd9Sstevel@tonic-gate
6257c478bd9Sstevel@tonic-gate /* disable interrupts */
6267c478bd9Sstevel@tonic-gate outl(0x00000000, ioaddr + CSR7);
6277c478bd9Sstevel@tonic-gate
6287c478bd9Sstevel@tonic-gate /* Stop the chip's Tx and Rx processes. */
6297c478bd9Sstevel@tonic-gate outl(inl(ioaddr + CSR6) & ~0x00002002, ioaddr + CSR6);
6307c478bd9Sstevel@tonic-gate
6317c478bd9Sstevel@tonic-gate /* Clear the missed-packet counter. */
6327c478bd9Sstevel@tonic-gate (volatile unsigned long)inl(ioaddr + CSR8);
6337c478bd9Sstevel@tonic-gate }
6347c478bd9Sstevel@tonic-gate
6357c478bd9Sstevel@tonic-gate
6367c478bd9Sstevel@tonic-gate /*********************************************************************/
6377c478bd9Sstevel@tonic-gate /* eth_irq - enable, disable and force interrupts */
6387c478bd9Sstevel@tonic-gate /*********************************************************************/
davicom_irq(struct nic * nic __unused,irq_action_t action __unused)6397c478bd9Sstevel@tonic-gate static void davicom_irq(struct nic *nic __unused, irq_action_t action __unused)
6407c478bd9Sstevel@tonic-gate {
6417c478bd9Sstevel@tonic-gate switch ( action ) {
6427c478bd9Sstevel@tonic-gate case DISABLE :
6437c478bd9Sstevel@tonic-gate break;
6447c478bd9Sstevel@tonic-gate case ENABLE :
6457c478bd9Sstevel@tonic-gate break;
6467c478bd9Sstevel@tonic-gate case FORCE :
6477c478bd9Sstevel@tonic-gate break;
6487c478bd9Sstevel@tonic-gate }
6497c478bd9Sstevel@tonic-gate }
6507c478bd9Sstevel@tonic-gate
6517c478bd9Sstevel@tonic-gate
6527c478bd9Sstevel@tonic-gate /*********************************************************************/
6537c478bd9Sstevel@tonic-gate /* eth_probe - Look for an adapter */
6547c478bd9Sstevel@tonic-gate /*********************************************************************/
davicom_probe(struct dev * dev,struct pci_device * pci)6557c478bd9Sstevel@tonic-gate static int davicom_probe(struct dev *dev, struct pci_device *pci)
6567c478bd9Sstevel@tonic-gate {
6577c478bd9Sstevel@tonic-gate struct nic *nic = (struct nic *)dev;
6587c478bd9Sstevel@tonic-gate unsigned int i;
6597c478bd9Sstevel@tonic-gate
6607c478bd9Sstevel@tonic-gate whereami("davicom_probe\n");
6617c478bd9Sstevel@tonic-gate
6627c478bd9Sstevel@tonic-gate if (pci->ioaddr == 0)
6637c478bd9Sstevel@tonic-gate return 0;
6647c478bd9Sstevel@tonic-gate
6657c478bd9Sstevel@tonic-gate vendor = pci->vendor;
6667c478bd9Sstevel@tonic-gate dev_id = pci->dev_id;
6677c478bd9Sstevel@tonic-gate ioaddr = pci->ioaddr & ~3;
6687c478bd9Sstevel@tonic-gate
6697c478bd9Sstevel@tonic-gate nic->irqno = 0;
6707c478bd9Sstevel@tonic-gate nic->ioaddr = pci->ioaddr & ~3;
6717c478bd9Sstevel@tonic-gate
6727c478bd9Sstevel@tonic-gate /* wakeup chip */
6737c478bd9Sstevel@tonic-gate pcibios_write_config_dword(pci->bus, pci->devfn, 0x40, 0x00000000);
6747c478bd9Sstevel@tonic-gate
6757c478bd9Sstevel@tonic-gate /* Stop the chip's Tx and Rx processes. */
6767c478bd9Sstevel@tonic-gate outl(inl(ioaddr + CSR6) & ~0x00002002, ioaddr + CSR6);
6777c478bd9Sstevel@tonic-gate
6787c478bd9Sstevel@tonic-gate /* Clear the missed-packet counter. */
6797c478bd9Sstevel@tonic-gate (volatile unsigned long)inl(ioaddr + CSR8);
6807c478bd9Sstevel@tonic-gate
6817c478bd9Sstevel@tonic-gate /* Get MAC Address */
6827c478bd9Sstevel@tonic-gate /* read EEPROM data */
6837c478bd9Sstevel@tonic-gate for (i = 0; i < sizeof(ee_data)/2; i++)
6847c478bd9Sstevel@tonic-gate ((unsigned short *)ee_data)[i] =
6857c478bd9Sstevel@tonic-gate le16_to_cpu(read_eeprom(ioaddr, i, EEPROM_ADDRLEN));
6867c478bd9Sstevel@tonic-gate
6877c478bd9Sstevel@tonic-gate /* extract MAC address from EEPROM buffer */
6887c478bd9Sstevel@tonic-gate for (i=0; i<ETH_ALEN; i++)
6897c478bd9Sstevel@tonic-gate nic->node_addr[i] = ee_data[20+i];
6907c478bd9Sstevel@tonic-gate
6917c478bd9Sstevel@tonic-gate printf("Davicom %! at ioaddr %#hX\n", nic->node_addr, ioaddr);
6927c478bd9Sstevel@tonic-gate
6937c478bd9Sstevel@tonic-gate /* initialize device */
6947c478bd9Sstevel@tonic-gate davicom_reset(nic);
6957c478bd9Sstevel@tonic-gate
6967c478bd9Sstevel@tonic-gate dev->disable = davicom_disable;
6977c478bd9Sstevel@tonic-gate nic->poll = davicom_poll;
6987c478bd9Sstevel@tonic-gate nic->transmit = davicom_transmit;
6997c478bd9Sstevel@tonic-gate nic->irq = davicom_irq;
7007c478bd9Sstevel@tonic-gate
7017c478bd9Sstevel@tonic-gate return 1;
7027c478bd9Sstevel@tonic-gate }
7037c478bd9Sstevel@tonic-gate
7047c478bd9Sstevel@tonic-gate static struct pci_id davicom_nics[] = {
7057c478bd9Sstevel@tonic-gate PCI_ROM(0x1282, 0x9100, "davicom9100", "Davicom 9100"),
7067c478bd9Sstevel@tonic-gate PCI_ROM(0x1282, 0x9102, "davicom9102", "Davicom 9102"),
7077c478bd9Sstevel@tonic-gate PCI_ROM(0x1282, 0x9009, "davicom9009", "Davicom 9009"),
7087c478bd9Sstevel@tonic-gate PCI_ROM(0x1282, 0x9132, "davicom9132", "Davicom 9132"), /* Needs probably some fixing */
7097c478bd9Sstevel@tonic-gate };
7107c478bd9Sstevel@tonic-gate
7117c478bd9Sstevel@tonic-gate struct pci_driver davicom_driver = {
7127c478bd9Sstevel@tonic-gate .type = NIC_DRIVER,
7137c478bd9Sstevel@tonic-gate .name = "DAVICOM",
7147c478bd9Sstevel@tonic-gate .probe = davicom_probe,
7157c478bd9Sstevel@tonic-gate .ids = davicom_nics,
7167c478bd9Sstevel@tonic-gate .id_count = sizeof(davicom_nics)/sizeof(davicom_nics[0]),
7177c478bd9Sstevel@tonic-gate .class = 0,
7187c478bd9Sstevel@tonic-gate };
719