?? cs8900.c
字號:
priv->stats.rx_missed_errors += missed; } if ((RegContent (status) & TxUnderrun)) { priv->stats.tx_errors++; priv->stats.tx_fifo_errors++; priv->txlen = 0; netif_wake_queue (dev); } /* FIXME: if Rdy4Tx, transmit last sent packet (if any) */ break; case TxCOL: priv->stats.collisions += ColCount (cs8900_read (dev,PP_TxCOL)); break; case RxMISS: status = MissCount (cs8900_read (dev,PP_RxMISS)); priv->stats.rx_errors += status; priv->stats.rx_missed_errors += status; break; } } return IRQ_RETVAL(handled);}static void cs8900_transmit_timeout (struct net_device *dev){ cs8900_t *priv = (cs8900_t *) dev->priv; priv->stats.tx_errors++; priv->stats.tx_heartbeat_errors++; priv->txlen = 0; netif_wake_queue (dev);}static int cs8900_start (struct net_device *dev){ int result;#if defined(CONFIG_ARCH_SMDK2410) set_irq_type(dev->irq, IRQT_RISING); /* enable the ethernet controller */ cs8900_set (dev,PP_RxCFG,RxOKiE | BufferCRC | CRCerroriE | RuntiE | ExtradataiE); cs8900_set (dev,PP_RxCTL,RxOKA | IndividualA | BroadcastA); cs8900_set (dev,PP_TxCFG,TxOKiE | Out_of_windowiE | JabberiE); cs8900_set (dev,PP_BufCFG,Rdy4TxiE | RxMissiE | TxUnderruniE | TxColOvfiE | MissOvfloiE); cs8900_set (dev,PP_LineCTL,SerRxON | SerTxON); cs8900_set (dev,PP_BusCTL,EnableRQ);#ifdef FULL_DUPLEX cs8900_set (dev,PP_TestCTL,FDX);#endif /* #ifdef FULL_DUPLEX */ udelay(200); /* install interrupt handler */ if ((result = request_irq (dev->irq, &cs8900_interrupt, 0, dev->name, dev)) < 0) { printk ("%s: could not register interrupt %d\n",dev->name, dev->irq); return (result); }#else /* install interrupt handler */ if ((result = request_irq (dev->irq, &cs8900_interrupt, 0, dev->name, dev)) < 0) { printk ("%s: could not register interrupt %d\n",dev->name, dev->irq); return (result); } set_irq_type(dev->irq, IRQT_RISING); /* enable the ethernet controller */ cs8900_set (dev,PP_RxCFG,RxOKiE | BufferCRC | CRCerroriE | RuntiE | ExtradataiE); cs8900_set (dev,PP_RxCTL,RxOKA | IndividualA | BroadcastA); cs8900_set (dev,PP_TxCFG,TxOKiE | Out_of_windowiE | JabberiE); cs8900_set (dev,PP_BufCFG,Rdy4TxiE | RxMissiE | TxUnderruniE | TxColOvfiE | MissOvfloiE); cs8900_set (dev,PP_LineCTL,SerRxON | SerTxON); cs8900_set (dev,PP_BusCTL,EnableRQ);#ifdef FULL_DUPLEX cs8900_set (dev,PP_TestCTL,FDX);#endif /* #ifdef FULL_DUPLEX */ #endif /* #if defined(CONFIG_ARCH_SMDK2410) */ /* start the queue */ netif_start_queue (dev); return (0);}static int cs8900_stop (struct net_device *dev){ /* disable ethernet controller */ cs8900_write (dev,PP_BusCTL,0); cs8900_write (dev,PP_TestCTL,0); cs8900_write (dev,PP_SelfCTL,0); cs8900_write (dev,PP_LineCTL,0); cs8900_write (dev,PP_BufCFG,0); cs8900_write (dev,PP_TxCFG,0); cs8900_write (dev,PP_RxCTL,0); cs8900_write (dev,PP_RxCFG,0); /* uninstall interrupt handler */ free_irq (dev->irq,dev); /* stop the queue */ netif_stop_queue (dev); return (0);}static struct net_device_stats *cs8900_get_stats (struct net_device *dev){ cs8900_t *priv = (cs8900_t *) dev->priv; return (&priv->stats);}static void cs8900_set_receive_mode (struct net_device *dev){ if ((dev->flags & IFF_PROMISC)) cs8900_set (dev,PP_RxCTL,PromiscuousA); else cs8900_clear (dev,PP_RxCTL,PromiscuousA); if ((dev->flags & IFF_ALLMULTI) && dev->mc_list) cs8900_set (dev,PP_RxCTL,MulticastA); else cs8900_clear (dev,PP_RxCTL,MulticastA);}static int cs8900_eeprom (struct net_device *dev){ cs8900_t *priv = (cs8900_t *) dev->priv; int i; /* SMDK2410 CS8900A without EEPROM at all */#if defined(CONFIG_ARCH_SMDK2410) return (-ENODEV);#endif #ifdef DEBUG eepromdump (dev);#endif if( (cs8900_read( dev, PP_SelfST) & EEPROMpresent) == 0) { /* no eeprom */ return (-ENODEV); } /* add character device for easy eeprom programming */ if( (priv->char_devnum=register_chrdev(0,"cs8900_eeprom",&cs8900_eeprom_fops)) != 0) printk (KERN_INFO "%s: Registered cs8900_eeprom char device (major #%d)\n", dev->name, priv->char_devnum); else printk (KERN_WARNING "%s: Failed to register char device cs8900_eeprom\n",dev->name); if( (cs8900_read( dev, PP_SelfST) & EEPROMOK) == 0) { /* bad checksum, invalid config block */ return (-EFAULT); } /* If we get here, the chip will have initialized the registers * that were specified in the eeprom configuration block * We assume this is at least the mac address. */ for (i = 0; i < ETH_ALEN; i += 2) { u16 mac = cs8900_read (dev,PP_IA + i); dev->dev_addr[i] = mac & 0xff; dev->dev_addr[i+1] = (mac>>8) & 0xff; } return (0);}/* * EEPROM Charater device */static int cs8900_eeprom_fopen(struct inode *inode, struct file *file){ u16 i; for( i=0; i<MAX_EEPROM_SIZE/2; i++) { cs8900_eeprom_read( &cs8900_dev, &cs8900_eeprom_cache[i],i); } return 0;}static int cs8900_eeprom_frelease(struct inode *inode, struct file *file){ return 0;}static loff_t cs8900_eeprom_fllseek(struct file * file,loff_t offset, int whence){ long newpos; switch(whence) { case 0: /* SEEK_SET */ newpos = offset; break; case 1: /* SEEK_CUR */ newpos = file->f_pos + offset; break; case 2: /* SEEK_END */ newpos = (MAX_EEPROM_SIZE-1) - offset; break; default: /* can't happen */ return -EINVAL; } if( (newpos<0) || (newpos>=MAX_EEPROM_SIZE)) return -EINVAL; file->f_pos = newpos; return newpos;}static ssize_t cs8900_eeprom_fread(struct file *file, char *buf, size_t count, loff_t *f_pos){ unsigned char *temp = (unsigned char *)cs8900_eeprom_cache; if (*f_pos >= MAX_EEPROM_SIZE) return 0; if (*f_pos + count > MAX_EEPROM_SIZE) count = MAX_EEPROM_SIZE - *f_pos; if (count<1) return 0; if (copy_to_user(buf, &temp[*f_pos], count)){ return -EFAULT; } *f_pos += count; return count;}static ssize_t cs8900_eeprom_fwrite(struct file *file, const char *buf, size_t count, loff_t *f_pos){ u16 i; unsigned char *temp = (unsigned char *)cs8900_eeprom_cache; if (*f_pos >= MAX_EEPROM_SIZE) return 0; if (*f_pos + count > MAX_EEPROM_SIZE) count = MAX_EEPROM_SIZE - *f_pos; if (count<1) return 0; /* FIXME: lock critical section */ /* update the cache */ if (copy_from_user(&temp[*f_pos], buf, count)){ return -EFAULT; } /* not concerned about performance, so write the entire thing */ for( i=0; i<MAX_EEPROM_SIZE/2; i++) { cs8900_eeprom_write( &cs8900_dev, &cs8900_eeprom_cache[i],i); } *f_pos += count; return count;}/* * Architecture dependant code */#ifdef CONFIG_SA1100_FRODOstatic void frodo_reset (struct net_device *dev){ int i; volatile u16 value; /* reset ethernet controller */ FRODO_CPLD_ETHERNET |= FRODO_ETH_RESET; mdelay (50); FRODO_CPLD_ETHERNET &= ~FRODO_ETH_RESET; mdelay (50); /* we tied SBHE to CHIPSEL, so each memory access ensure the chip is in 16-bit mode */ for (i = 0; i < 3; i++) value = cs8900_read (dev,0); /* FIXME: poll status bit */}#endif /* #ifdef CONFIG_SA1100_FRODO *//* * Driver initialization routines */int __init cs8900_probe (struct net_device *dev){ static cs8900_t priv; int i,result; u16 value; printk (VERSION_STRING"\n"); memset (&priv,0,sizeof (cs8900_t)); ether_setup (dev); dev->open = cs8900_start; dev->stop = cs8900_stop; dev->hard_start_xmit = cs8900_send_start; dev->get_stats = cs8900_get_stats; dev->set_multicast_list = cs8900_set_receive_mode; dev->tx_timeout = cs8900_transmit_timeout; dev->watchdog_timeo = HZ;#if defined(CONFIG_ARCH_SMDK2410) dev->dev_addr[0] = 0x08; dev->dev_addr[1] = 0x00; dev->dev_addr[2] = 0x3e; dev->dev_addr[3] = 0x26; dev->dev_addr[4] = 0x0a; dev->dev_addr[5] = 0x5b;#else dev->dev_addr[0] = 0x00; dev->dev_addr[1] = 0x12; dev->dev_addr[2] = 0x34; dev->dev_addr[3] = 0x56; dev->dev_addr[4] = 0x78; dev->dev_addr[5] = 0x9a;#endif dev->if_port = IF_PORT_10BASET; dev->priv = (void *) &priv; spin_lock_init(&priv.lock); SET_MODULE_OWNER (dev);#ifdef CONFIG_SA1100_FRODO dev->base_addr = FRODO_ETH_IO + 0x300; dev->irq = FRODO_ETH_IRQ; frodo_reset (dev);#endif /* #ifdef CONFIG_SA1100_FRODO */#if defined(CONFIG_SA1100_CERF) dev->base_addr = CERF_ETH_IO + 0x300; dev->irq = CERF_ETH_IRQ;#endif /* #if defined(CONFIG_SA1100_CERF) */#if defined(CONFIG_ARCH_SMDK2410) dev->base_addr = vSMDK2410_ETH_IO + 0x300; dev->irq = SMDK2410_ETH_IRQ;#endif /* #if defined(CONFIG_ARCH_SMDK2410) */ if ((result = check_mem_region (dev->base_addr, 16))) { printk (KERN_ERR "%s: can't get I/O port address 0x%lx\n",dev->name,dev->base_addr); return (result); } request_mem_region (dev->base_addr, 16, dev->name); /* verify EISA registration number for Cirrus Logic */ if ((value = cs8900_read (dev,PP_ProductID)) != EISA_REG_CODE) { printk (KERN_ERR "%s: incorrect signature 0x%.4x\n",dev->name,value); return (-ENXIO); } /* verify chip version */ value = cs8900_read (dev,PP_ProductID + 2); if (VERSION (value) != CS8900A) { printk (KERN_ERR "%s: unknown chip version 0x%.8x\n",dev->name,VERSION (value)); return (-ENXIO); } /* setup interrupt number */ cs8900_write (dev,PP_IntNum,0); /* If an EEPROM is present, use it's MAC address. A valid EEPROM will * initialize the registers automatically. */ result = cs8900_eeprom (dev); printk (KERN_INFO "%s: CS8900A rev %c at %#lx irq=%d", dev->name,'B' + REVISION (value) - REV_B, dev->base_addr, dev->irq); if (result == -ENODEV) { /* no eeprom or invalid config block, configure MAC address by hand */ for (i = 0; i < ETH_ALEN; i += 2) cs8900_write (dev,PP_IA + i,dev->dev_addr[i] | (dev->dev_addr[i + 1] << 8)); printk (", no eeprom "); } else if( result == -EFAULT) {#if defined(CONFIG_SA1100_CERF) /* The default eeprom layout doesn't follow the cs8900 layout * that enables automatic cs8900 initialization. Doh! * Read the mac address manually. */ u16 MAC_addr[3] = {0, 0, 0}; if (cs8900_eeprom_read(dev, &MAC_addr[0], 0x1c) == -1) printk("\ncs8900: [CERF] EEPROM[0] read failed\n"); if (cs8900_eeprom_read(dev, &MAC_addr[1], 0x1d) == -1) printk("\ncs8900: [CERF] EEPROM[1] read failed\n"); if (cs8900_eeprom_read(dev, &MAC_addr[2], 0x1e) == -1) printk("\ncs8900: [CERF] EEPROM[2] read failed\n"); for (i = 0; i < ETH_ALEN / 2; i++) { dev->dev_addr[i*2] = MAC_addr[i] & 0xff; dev->dev_addr[i*2+1] = (MAC_addr[i] >> 8) & 0xff; cs8900_write (dev,PP_IA + i*2,dev->dev_addr[i*2] | (dev->dev_addr[i*2 + 1] << 8)); } printk (", eeprom (smdk2410 layout)");#else printk (", eeprom (invalid config block)");#endif /* #if defined(CONFIG_SA1100_CERF) */ } else { printk (", eeprom ok"); } printk (", addr:"); for (i = 0; i < ETH_ALEN; i += 2) { u16 mac = cs8900_read (dev,PP_IA + i); printk ("%c%02X:%2X", (i==0)?' ':':', mac & 0xff, (mac >> 8)); } printk ("\n"); return (0);}static int __init cs8900_init (void){ strcpy(cs8900_dev.name, "eth%d"); return (register_netdev (&cs8900_dev));}static void __exit cs8900_cleanup (void){ cs8900_t *priv = (cs8900_t *) cs8900_dev.priv; if( priv->char_devnum) { unregister_chrdev(priv->char_devnum,"cs8900_eeprom"); } release_mem_region (cs8900_dev.base_addr,16); unregister_netdev (&cs8900_dev);}MODULE_AUTHOR ("Abraham van der Merwe <abraham at 2d3d.co.za>");MODULE_DESCRIPTION (VERSION_STRING);MODULE_LICENSE ("GPL");module_init (cs8900_init);module_exit (cs8900_cleanup);
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -