davicom.c

Go to the documentation of this file.
00001 #ifdef ALLMULTI
00002 #error multicast support is not yet implemented
00003 #endif
00004 /*  
00005     DAVICOM DM9009/DM9102/DM9102A Etherboot Driver      V1.00
00006 
00007     This driver was ported from Marty Connor's Tulip Etherboot driver. 
00008     Thanks Marty Connor (mdc@etherboot.org) 
00009 
00010     This davicom etherboot driver supports DM9009/DM9102/DM9102A/
00011     DM9102A+DM9801/DM9102A+DM9802 NICs.
00012 
00013     This software may be used and distributed according to the terms
00014     of the GNU Public License, incorporated herein by reference.
00015 
00016 */
00017 
00018 FILE_LICENCE ( GPL_ANY );
00019 
00020 /*********************************************************************/
00021 /* Revision History                                                  */
00022 /*********************************************************************/
00023 
00024 /*
00025   19 OCT 2000  Sten     1.00
00026                         Different half and full duplex mode
00027                         Do the different programming for DM9801/DM9802
00028 
00029   12 OCT 2000  Sten     0.90
00030                         This driver was ported from tulip driver and it 
00031                         has the following difference.
00032                         Changed symbol tulip/TULIP to davicom/DAVICOM
00033                         Deleted some code that did not use in this driver.
00034                         Used chain-strcture to replace ring structure
00035                         for both TX/RX descriptor.
00036                         Allocated two tx descriptor.
00037                         According current media mode to set operating 
00038                         register(CR6)
00039 */
00040 
00041 
00042 /*********************************************************************/
00043 /* Declarations                                                      */
00044 /*********************************************************************/
00045 
00046 #include "etherboot.h"
00047 #include "nic.h"
00048 #include <gpxe/pci.h>
00049 #include <gpxe/ethernet.h>
00050 
00051 #undef DAVICOM_DEBUG
00052 #undef DAVICOM_DEBUG_WHERE
00053 
00054 #define TX_TIME_OUT       2*TICKS_PER_SEC
00055 
00056 /* Register offsets for davicom device */
00057 enum davicom_offsets {
00058    CSR0=0,     CSR1=0x08,  CSR2=0x10,  CSR3=0x18,  CSR4=0x20,  CSR5=0x28,
00059    CSR6=0x30,  CSR7=0x38,  CSR8=0x40,  CSR9=0x48, CSR10=0x50, CSR11=0x58,
00060   CSR12=0x60, CSR13=0x68, CSR14=0x70, CSR15=0x78, CSR16=0x80, CSR20=0xA0
00061 };
00062 
00063 /* EEPROM Address width definitions */
00064 #define EEPROM_ADDRLEN 6
00065 #define EEPROM_SIZE    32              /* 1 << EEPROM_ADDRLEN */
00066 /* Used to be 128, but we only need to read enough to get the MAC
00067    address at bytes 20..25 */
00068 
00069 /* Data Read from the EEPROM */
00070 static unsigned char ee_data[EEPROM_SIZE];
00071 
00072 /* The EEPROM commands include the alway-set leading bit. */
00073 #define EE_WRITE_CMD    (5 << addr_len)
00074 #define EE_READ_CMD     (6 << addr_len)
00075 #define EE_ERASE_CMD    (7 << addr_len)
00076 
00077 /* EEPROM_Ctrl bits. */
00078 #define EE_SHIFT_CLK    0x02    /* EEPROM shift clock. */
00079 #define EE_CS           0x01    /* EEPROM chip select. */
00080 #define EE_DATA_WRITE   0x04    /* EEPROM chip data in. */
00081 #define EE_WRITE_0      0x01
00082 #define EE_WRITE_1      0x05
00083 #define EE_DATA_READ    0x08    /* EEPROM chip data out. */
00084 #define EE_ENB          (0x4800 | EE_CS)
00085 
00086 /* Sten 10/11 for phyxcer */
00087 #define PHY_DATA_0      0x0
00088 #define PHY_DATA_1      0x20000
00089 #define MDCLKH          0x10000
00090 
00091 /* Delay between EEPROM clock transitions.  Even at 33Mhz current PCI
00092    implementations don't overrun the EEPROM clock.  We add a bus
00093    turn-around to insure that this remains true.  */
00094 #define eeprom_delay()  inl(ee_addr)
00095 
00096 /* helpful macro if on a big_endian machine for changing byte order.
00097    not strictly needed on Intel
00098    Already defined in Etherboot includes
00099 #define le16_to_cpu(val) (val)
00100 */
00101 
00102 /* transmit and receive descriptor format */
00103 struct txdesc {
00104   volatile unsigned long   status;         /* owner, status */
00105   unsigned long   buf1sz:11,      /* size of buffer 1 */
00106     buf2sz:11,                    /* size of buffer 2 */
00107     control:10;                   /* control bits */
00108   const unsigned char *buf1addr;  /* buffer 1 address */
00109   const unsigned char *buf2addr;  /* buffer 2 address */
00110 };
00111 
00112 struct rxdesc {
00113   volatile unsigned long   status;         /* owner, status */
00114   unsigned long   buf1sz:11,      /* size of buffer 1 */
00115     buf2sz:11,                    /* size of buffer 2 */
00116     control:10;                   /* control bits */
00117   unsigned char   *buf1addr;      /* buffer 1 address */
00118   unsigned char   *buf2addr;      /* buffer 2 address */
00119 };
00120 
00121 /* Size of transmit and receive buffers */
00122 #define BUFLEN 1536
00123 
00124 /*********************************************************************/
00125 /* Global Storage                                                    */
00126 /*********************************************************************/
00127 
00128 static struct nic_operations davicom_operations;
00129 
00130 /* PCI Bus parameters */
00131 static unsigned short vendor, dev_id;
00132 static unsigned long ioaddr;
00133 
00134 /* Note: transmit and receive buffers must be longword aligned and
00135    longword divisable */
00136 
00137 /* transmit descriptor and buffer */
00138 #define NTXD 2
00139 #define NRXD 4
00140 struct {
00141         struct txdesc txd[NTXD] __attribute__ ((aligned(4)));
00142         unsigned char txb[BUFLEN] __attribute__ ((aligned(4)));
00143         struct rxdesc rxd[NRXD] __attribute__ ((aligned(4)));
00144         unsigned char rxb[NRXD * BUFLEN] __attribute__ ((aligned(4)));
00145 } davicom_bufs __shared;
00146 #define txd davicom_bufs.txd
00147 #define txb davicom_bufs.txb
00148 #define rxd davicom_bufs.rxd
00149 #define rxb davicom_bufs.rxb
00150 static int rxd_tail;
00151 static int TxPtr;
00152 
00153 
00154 /*********************************************************************/
00155 /* Function Prototypes                                               */
00156 /*********************************************************************/
00157 static void whereami(const char *str);
00158 static int read_eeprom(unsigned long ioaddr, int location, int addr_len);
00159 static int davicom_probe(struct nic *nic,struct pci_device *pci);
00160 static void davicom_init_chain(struct nic *nic);        /* Sten 10/9 */
00161 static void davicom_reset(struct nic *nic);
00162 static void davicom_transmit(struct nic *nic, const char *d, unsigned int t,
00163                            unsigned int s, const char *p);
00164 static int davicom_poll(struct nic *nic, int retrieve);
00165 static void davicom_disable(struct nic *nic);
00166 #ifdef  DAVICOM_DEBUG
00167 static void davicom_more(void);
00168 #endif /* DAVICOM_DEBUG */
00169 static void davicom_wait(unsigned int nticks);
00170 static int phy_read(int);
00171 static void phy_write(int, u16);
00172 static void phy_write_1bit(u32, u32);
00173 static int phy_read_1bit(u32);
00174 static void davicom_media_chk(struct nic *);
00175 
00176 
00177 /*********************************************************************/
00178 /* Utility Routines                                                  */
00179 /*********************************************************************/
00180 static inline void whereami(const char *str)
00181 {
00182   printf("%s\n", str);
00183   /* sleep(2); */
00184 }
00185 
00186 #ifdef  DAVICOM_DEBUG
00187 static void davicom_more()
00188 {
00189   printf("\n\n-- more --");
00190   while (!iskey())
00191     /* wait */;
00192   getchar();
00193   printf("\n\n");
00194 }
00195 #endif /* DAVICOM_DEBUG */
00196 
00197 static void davicom_wait(unsigned int nticks)
00198 {
00199   unsigned int to = currticks() + nticks;
00200   while (currticks() < to)
00201     /* wait */ ;
00202 }
00203 
00204 
00205 /*********************************************************************/
00206 /* For DAVICOM phyxcer register by MII interface                     */
00207 /*********************************************************************/
00208 /*
00209   Read a word data from phy register
00210 */
00211 static int phy_read(int location)
00212 {
00213  int i, phy_addr=1;
00214  u16 phy_data;
00215  u32 io_dcr9;
00216 
00217  whereami("phy_read\n");
00218 
00219  io_dcr9 = ioaddr + CSR9;
00220 
00221  /* Send 33 synchronization clock to Phy controller */
00222  for (i=0; i<34; i++)
00223      phy_write_1bit(io_dcr9, PHY_DATA_1);
00224 
00225  /* Send start command(01) to Phy */
00226  phy_write_1bit(io_dcr9, PHY_DATA_0);
00227  phy_write_1bit(io_dcr9, PHY_DATA_1);
00228 
00229  /* Send read command(10) to Phy */
00230  phy_write_1bit(io_dcr9, PHY_DATA_1);
00231  phy_write_1bit(io_dcr9, PHY_DATA_0);
00232 
00233  /* Send Phy addres */
00234  for (i=0x10; i>0; i=i>>1)
00235      phy_write_1bit(io_dcr9, phy_addr&i ? PHY_DATA_1: PHY_DATA_0);
00236    
00237  /* Send register addres */
00238  for (i=0x10; i>0; i=i>>1)
00239      phy_write_1bit(io_dcr9, location&i ? PHY_DATA_1: PHY_DATA_0);
00240 
00241  /* Skip transition state */
00242  phy_read_1bit(io_dcr9);
00243 
00244  /* read 16bit data */
00245  for (phy_data=0, i=0; i<16; i++) {
00246    phy_data<<=1;
00247    phy_data|=phy_read_1bit(io_dcr9);
00248  }
00249 
00250  return phy_data;
00251 }
00252 
00253 /*
00254   Write a word to Phy register
00255 */
00256 static void phy_write(int location, u16 phy_data)
00257 {
00258  u16 i, phy_addr=1;
00259  u32 io_dcr9; 
00260 
00261  whereami("phy_write\n");
00262 
00263  io_dcr9 = ioaddr + CSR9;
00264 
00265  /* Send 33 synchronization clock to Phy controller */
00266  for (i=0; i<34; i++)
00267    phy_write_1bit(io_dcr9, PHY_DATA_1);
00268 
00269  /* Send start command(01) to Phy */
00270  phy_write_1bit(io_dcr9, PHY_DATA_0);
00271  phy_write_1bit(io_dcr9, PHY_DATA_1);
00272 
00273  /* Send write command(01) to Phy */
00274  phy_write_1bit(io_dcr9, PHY_DATA_0);
00275  phy_write_1bit(io_dcr9, PHY_DATA_1);
00276 
00277  /* Send Phy addres */
00278  for (i=0x10; i>0; i=i>>1)
00279    phy_write_1bit(io_dcr9, phy_addr&i ? PHY_DATA_1: PHY_DATA_0);
00280 
00281  /* Send register addres */
00282  for (i=0x10; i>0; i=i>>1)
00283    phy_write_1bit(io_dcr9, location&i ? PHY_DATA_1: PHY_DATA_0);
00284 
00285  /* written trasnition */
00286  phy_write_1bit(io_dcr9, PHY_DATA_1);
00287  phy_write_1bit(io_dcr9, PHY_DATA_0);
00288 
00289  /* Write a word data to PHY controller */
00290  for (i=0x8000; i>0; i>>=1)
00291    phy_write_1bit(io_dcr9, phy_data&i ? PHY_DATA_1: PHY_DATA_0);
00292 }
00293 
00294 /*
00295   Write one bit data to Phy Controller
00296 */
00297 static void phy_write_1bit(u32 ee_addr, u32 phy_data)
00298 {
00299  whereami("phy_write_1bit\n");
00300  outl(phy_data, ee_addr);                        /* MII Clock Low */
00301  eeprom_delay();
00302  outl(phy_data|MDCLKH, ee_addr);                 /* MII Clock High */
00303  eeprom_delay();
00304  outl(phy_data, ee_addr);                        /* MII Clock Low */
00305  eeprom_delay();
00306 }
00307 
00308 /*
00309   Read one bit phy data from PHY controller
00310 */
00311 static int phy_read_1bit(u32 ee_addr)
00312 {
00313  int phy_data;
00314 
00315  whereami("phy_read_1bit\n");
00316 
00317  outl(0x50000, ee_addr);
00318  eeprom_delay();
00319 
00320  phy_data=(inl(ee_addr)>>19) & 0x1;
00321 
00322  outl(0x40000, ee_addr);
00323  eeprom_delay();
00324 
00325  return phy_data;
00326 }
00327 
00328 /*
00329   DM9801/DM9802 present check and program 
00330 */
00331 static void HPNA_process(void)
00332 {
00333 
00334  if ( (phy_read(3) & 0xfff0) == 0xb900 ) {
00335    if ( phy_read(31) == 0x4404 ) {
00336      /* DM9801 present */
00337      if (phy_read(3) == 0xb901)
00338        phy_write(16, 0x5);      /* DM9801 E4 */
00339      else
00340        phy_write(16, 0x1005); /* DM9801 E3 and others */
00341      phy_write(25, ((phy_read(24) + 3) & 0xff) | 0xf000);
00342    } else {
00343      /* DM9802 present */
00344      phy_write(16, 0x5);
00345      phy_write(25, (phy_read(25) & 0xff00) + 2);
00346    }
00347  }
00348 }
00349 
00350 /*
00351   Sense media mode and set CR6
00352 */
00353 static void davicom_media_chk(struct nic * nic __unused)
00354 {
00355   unsigned long to, csr6;
00356 
00357   csr6 = 0x00200000;    /* SF */
00358   outl(csr6, ioaddr + CSR6);
00359 
00360 #define PCI_DEVICE_ID_DM9009            0x9009
00361   if (vendor == PCI_VENDOR_ID_DAVICOM && dev_id == PCI_DEVICE_ID_DM9009) {
00362     /* Set to 10BaseT mode for DM9009 */
00363     phy_write(0, 0);
00364   } else {
00365     /* For DM9102/DM9102A */
00366     to = currticks() + 2 * TICKS_PER_SEC;
00367     while ( ((phy_read(1) & 0x24)!=0x24) && (currticks() < to))
00368       /* wait */ ;
00369 
00370     if ( (phy_read(1) & 0x24) == 0x24 ) {
00371       if (phy_read(17) & 0xa000)  
00372         csr6 |= 0x00000200;     /* Full Duplex mode */
00373     } else
00374       csr6 |= 0x00040000; /* Select DM9801/DM9802 when Ethernet link failed */
00375   }
00376 
00377   /* set the chip's operating mode */
00378   outl(csr6, ioaddr + CSR6);
00379 
00380   /* DM9801/DM9802 present check & program */
00381   if (csr6 & 0x40000)
00382     HPNA_process();
00383 }
00384 
00385 
00386 /*********************************************************************/
00387 /* EEPROM Reading Code                                               */
00388 /*********************************************************************/
00389 /* EEPROM routines adapted from the Linux Tulip Code */
00390 /* Reading a serial EEPROM is a "bit" grungy, but we work our way
00391    through:->.
00392 */
00393 static int read_eeprom(unsigned long ioaddr, int location, int addr_len)
00394 {
00395   int i;
00396   unsigned short retval = 0;
00397   long ee_addr = ioaddr + CSR9;
00398   int read_cmd = location | EE_READ_CMD;
00399 
00400   whereami("read_eeprom\n");
00401 
00402   outl(EE_ENB & ~EE_CS, ee_addr);
00403   outl(EE_ENB, ee_addr);
00404 
00405   /* Shift the read command bits out. */
00406   for (i = 4 + addr_len; i >= 0; i--) {
00407     short dataval = (read_cmd & (1 << i)) ? EE_DATA_WRITE : 0;
00408     outl(EE_ENB | dataval, ee_addr);
00409     eeprom_delay();
00410     outl(EE_ENB | dataval | EE_SHIFT_CLK, ee_addr);
00411     eeprom_delay();
00412   }
00413   outl(EE_ENB, ee_addr);
00414 
00415   for (i = 16; i > 0; i--) {
00416     outl(EE_ENB | EE_SHIFT_CLK, ee_addr);
00417     eeprom_delay();
00418     retval = (retval << 1) | ((inl(ee_addr) & EE_DATA_READ) ? 1 : 0);
00419     outl(EE_ENB, ee_addr);
00420     eeprom_delay();
00421   }
00422 
00423   /* Terminate the EEPROM access. */
00424   outl(EE_ENB & ~EE_CS, ee_addr);
00425   return retval;
00426 }
00427 
00428 /*********************************************************************/
00429 /* davicom_init_chain - setup the tx and rx descriptors                */
00430 /* Sten 10/9                                                         */
00431 /*********************************************************************/
00432 static void davicom_init_chain(struct nic *nic)
00433 {
00434   int i;
00435 
00436   /* setup the transmit descriptor */
00437   /* Sten: Set 2 TX descriptor but use one TX buffer because
00438            it transmit a packet and wait complete every time. */
00439   for (i=0; i<NTXD; i++) {
00440     txd[i].buf1addr = (void *)virt_to_bus(&txb[0]);     /* Used same TX buffer */
00441     txd[i].buf2addr = (void *)virt_to_bus(&txd[i+1]);   /*  Point to Next TX desc */
00442     txd[i].buf1sz   = 0;
00443     txd[i].buf2sz   = 0;
00444     txd[i].control  = 0x184;           /* Begin/End/Chain */
00445     txd[i].status   = 0x00000000;      /* give ownership to Host */
00446   }
00447 
00448   /* construct perfect filter frame with mac address as first match
00449      and broadcast address for all others */
00450   for (i=0; i<192; i++) txb[i] = 0xFF;
00451   txb[0] = nic->node_addr[0];
00452   txb[1] = nic->node_addr[1];
00453   txb[4] = nic->node_addr[2];
00454   txb[5] = nic->node_addr[3];
00455   txb[8] = nic->node_addr[4];
00456   txb[9] = nic->node_addr[5];
00457 
00458   /* setup receive descriptor */
00459   for (i=0; i<NRXD; i++) {
00460     rxd[i].buf1addr = (void *)virt_to_bus(&rxb[i * BUFLEN]);
00461     rxd[i].buf2addr = (void *)virt_to_bus(&rxd[i+1]); /* Point to Next RX desc */
00462     rxd[i].buf1sz   = BUFLEN;
00463     rxd[i].buf2sz   = 0;        /* not used */
00464     rxd[i].control  = 0x4;              /* Chain Structure */
00465     rxd[i].status   = 0x80000000;   /* give ownership to device */
00466   }
00467 
00468   /* Chain the last descriptor to first */
00469   txd[NTXD - 1].buf2addr = (void *)virt_to_bus(&txd[0]);
00470   rxd[NRXD - 1].buf2addr = (void *)virt_to_bus(&rxd[0]);
00471   TxPtr = 0;
00472   rxd_tail = 0;
00473 }
00474 
00475 
00476 /*********************************************************************/
00477 /* davicom_reset - Reset adapter                                         */
00478 /*********************************************************************/
00479 static void davicom_reset(struct nic *nic)
00480 {
00481   unsigned long to;
00482 
00483   whereami("davicom_reset\n");
00484 
00485   /* Stop Tx and RX */
00486   outl(inl(ioaddr + CSR6) & ~0x00002002, ioaddr + CSR6);
00487 
00488   /* Reset the chip, holding bit 0 set at least 50 PCI cycles. */
00489   outl(0x00000001, ioaddr + CSR0);
00490 
00491   davicom_wait(TICKS_PER_SEC);
00492 
00493   /* TX/RX descriptor burst */
00494   outl(0x0C00000, ioaddr + CSR0);       /* Sten 10/9 */
00495 
00496   /* set up transmit and receive descriptors */
00497   davicom_init_chain(nic);      /* Sten 10/9 */
00498 
00499   /* Point to receive descriptor */
00500   outl(virt_to_bus(&rxd[0]), ioaddr + CSR3);
00501   outl(virt_to_bus(&txd[0]), ioaddr + CSR4);    /* Sten 10/9 */
00502 
00503   /* According phyxcer media mode to set CR6,
00504      DM9102/A phyxcer can auto-detect media mode */
00505   davicom_media_chk(nic);
00506 
00507   /* Prepare Setup Frame Sten 10/9 */
00508   txd[TxPtr].buf1sz = 192;
00509   txd[TxPtr].control = 0x024;           /* SF/CE */
00510   txd[TxPtr].status = 0x80000000;       /* Give ownership to device */
00511 
00512   /* Start Tx */
00513   outl(inl(ioaddr + CSR6) | 0x00002000, ioaddr + CSR6);
00514   /* immediate transmit demand */
00515   outl(0, ioaddr + CSR1);
00516 
00517   to = currticks() + TX_TIME_OUT;
00518   while ((txd[TxPtr].status & 0x80000000) && (currticks() < to)) /* Sten 10/9 */
00519     /* wait */ ;
00520 
00521   if (currticks() >= to) {
00522     printf ("TX Setup Timeout!\n");
00523   }
00524   /* Point to next TX descriptor */
00525  TxPtr = (++TxPtr >= NTXD) ? 0:TxPtr;   /* Sten 10/9 */
00526 
00527 #ifdef DAVICOM_DEBUG
00528   printf("txd.status = %X\n", txd.status);
00529   printf("ticks = %d\n", currticks() - (to - TX_TIME_OUT));
00530   davicom_more();
00531 #endif
00532 
00533   /* enable RX */
00534   outl(inl(ioaddr + CSR6) | 0x00000002, ioaddr + CSR6);
00535   /* immediate poll demand */
00536   outl(0, ioaddr + CSR2);
00537 }
00538 
00539 
00540 /*********************************************************************/
00541 /* eth_transmit - Transmit a frame                                   */
00542 /*********************************************************************/
00543 static void davicom_transmit(struct nic *nic, const char *d, unsigned int t,
00544                            unsigned int s, const char *p)
00545 {
00546   unsigned long to;
00547 
00548   whereami("davicom_transmit\n");
00549 
00550   /* Stop Tx */
00551   /* outl(inl(ioaddr + CSR6) & ~0x00002000, ioaddr + CSR6); */
00552 
00553   /* setup ethernet header */
00554   memcpy(&txb[0], d, ETH_ALEN); /* DA 6byte */
00555   memcpy(&txb[ETH_ALEN], nic->node_addr, ETH_ALEN); /* SA 6byte*/
00556   txb[ETH_ALEN*2] = (t >> 8) & 0xFF; /* Frame type: 2byte */
00557   txb[ETH_ALEN*2+1] = t & 0xFF;
00558   memcpy(&txb[ETH_HLEN], p, s); /* Frame data */
00559 
00560   /* setup the transmit descriptor */
00561   txd[TxPtr].buf1sz   = ETH_HLEN+s;
00562   txd[TxPtr].control  = 0x00000184;      /* LS+FS+CE */
00563   txd[TxPtr].status   = 0x80000000;      /* give ownership to device */
00564 
00565   /* immediate transmit demand */
00566   outl(0, ioaddr + CSR1);
00567 
00568   to = currticks() + TX_TIME_OUT;
00569   while ((txd[TxPtr].status & 0x80000000) && (currticks() < to))
00570     /* wait */ ;
00571 
00572   if (currticks() >= to) {
00573     printf ("TX Timeout!\n");
00574   }
00575  
00576   /* Point to next TX descriptor */
00577   TxPtr = (++TxPtr >= NTXD) ? 0:TxPtr;  /* Sten 10/9 */
00578 
00579 }
00580 
00581 /*********************************************************************/
00582 /* eth_poll - Wait for a frame                                       */
00583 /*********************************************************************/
00584 static int davicom_poll(struct nic *nic, int retrieve)
00585 {
00586   whereami("davicom_poll\n");
00587 
00588   if (rxd[rxd_tail].status & 0x80000000)
00589     return 0;
00590 
00591   if ( ! retrieve ) return 1;
00592 
00593   whereami("davicom_poll got one\n");
00594 
00595   nic->packetlen = (rxd[rxd_tail].status & 0x3FFF0000) >> 16;
00596 
00597   if( rxd[rxd_tail].status & 0x00008000){
00598       rxd[rxd_tail].status = 0x80000000;
00599       rxd_tail++;
00600       if (rxd_tail == NRXD) rxd_tail = 0;
00601       return 0;
00602   }
00603 
00604   /* copy packet to working buffer */
00605   /* XXX - this copy could be avoided with a little more work
00606      but for now we are content with it because the optimised
00607      memcpy is quite fast */
00608 
00609   memcpy(nic->packet, rxb + rxd_tail * BUFLEN, nic->packetlen);
00610 
00611   /* return the descriptor and buffer to receive ring */
00612   rxd[rxd_tail].status = 0x80000000;
00613   rxd_tail++;
00614   if (rxd_tail == NRXD) rxd_tail = 0;
00615 
00616   return 1;
00617 }
00618 
00619 /*********************************************************************/
00620 /* eth_disable - Disable the interface                               */
00621 /*********************************************************************/
00622 static void davicom_disable ( struct nic *nic ) {
00623 
00624   whereami("davicom_disable\n");
00625 
00626   davicom_reset(nic);
00627 
00628   /* disable interrupts */
00629   outl(0x00000000, ioaddr + CSR7);
00630 
00631   /* Stop the chip's Tx and Rx processes. */
00632   outl(inl(ioaddr + CSR6) & ~0x00002002, ioaddr + CSR6);
00633 
00634   /* Clear the missed-packet counter. */
00635   inl(ioaddr + CSR8);
00636 }
00637 
00638 
00639 /*********************************************************************/
00640 /* eth_irq - enable, disable and force interrupts                    */
00641 /*********************************************************************/
00642 static void davicom_irq(struct nic *nic __unused, irq_action_t action __unused)
00643 {
00644   switch ( action ) {
00645   case DISABLE :
00646     break;
00647   case ENABLE :
00648     break;
00649   case FORCE :
00650     break;
00651   }
00652 }
00653 
00654 
00655 /*********************************************************************/
00656 /* eth_probe - Look for an adapter                                   */
00657 /*********************************************************************/
00658 static int davicom_probe ( struct nic *nic, struct pci_device *pci ) {
00659 
00660   unsigned int i;
00661 
00662   whereami("davicom_probe\n");
00663 
00664   if (pci->ioaddr == 0)
00665     return 0;
00666 
00667   vendor  = pci->vendor;
00668   dev_id  = pci->device;
00669   ioaddr  = pci->ioaddr;
00670 
00671   nic->ioaddr = pci->ioaddr;
00672   nic->irqno = 0;
00673 
00674   /* wakeup chip */
00675   pci_write_config_dword(pci, 0x40, 0x00000000);
00676 
00677   /* Stop the chip's Tx and Rx processes. */
00678   outl(inl(ioaddr + CSR6) & ~0x00002002, ioaddr + CSR6);
00679 
00680   /* Clear the missed-packet counter. */
00681   inl(ioaddr + CSR8);
00682 
00683   /* Get MAC Address */
00684   /* read EEPROM data */
00685   for (i = 0; i < sizeof(ee_data)/2; i++)
00686     ((unsigned short *)ee_data)[i] =
00687         le16_to_cpu(read_eeprom(ioaddr, i, EEPROM_ADDRLEN));
00688 
00689   /* extract MAC address from EEPROM buffer */
00690   for (i=0; i<ETH_ALEN; i++)
00691     nic->node_addr[i] = ee_data[20+i];
00692 
00693   DBG ( "Davicom %s at IOADDR %4.4lx\n", eth_ntoa ( nic->node_addr ), ioaddr );
00694 
00695   /* initialize device */
00696   davicom_reset(nic);
00697   nic->nic_op   = &davicom_operations;
00698   return 1;
00699 }
00700 
00701 static struct nic_operations davicom_operations = {
00702         .connect        = dummy_connect,
00703         .poll           = davicom_poll,
00704         .transmit       = davicom_transmit,
00705         .irq            = davicom_irq,
00706 
00707 };
00708 
00709 static struct pci_device_id davicom_nics[] = {
00710 PCI_ROM(0x1282, 0x9100, "davicom9100", "Davicom 9100", 0),
00711 PCI_ROM(0x1282, 0x9102, "davicom9102", "Davicom 9102", 0),
00712 PCI_ROM(0x1282, 0x9009, "davicom9009", "Davicom 9009", 0),
00713 PCI_ROM(0x1282, 0x9132, "davicom9132", "Davicom 9132", 0),      /* Needs probably some fixing */
00714 };
00715 
00716 PCI_DRIVER ( davicom_driver, davicom_nics, PCI_NO_CLASS );
00717 
00718 DRIVER ( "DAVICOM", nic_driver, pci_driver, davicom_driver,
00719          davicom_probe, davicom_disable );
00720 
00721 /*
00722  * Local variables:
00723  *  c-basic-offset: 8
00724  *  c-indent-level: 8
00725  *  tab-width: 8
00726  * End:
00727  */

Generated on Tue Apr 6 20:00:56 2010 for gPXE by  doxygen 1.5.7.1