--- zzzz-none-000/linux-2.4.17/drivers/net/au1000_eth.c 2001-09-09 17:43:01.000000000 +0000 +++ sangam-fb-322/linux-2.4.17/drivers/net/au1000_eth.c 2004-11-24 13:23:36.000000000 +0000 @@ -47,6 +47,7 @@ #include #include #include +#include #include #include #include @@ -64,6 +65,7 @@ static void *dma_alloc(size_t, dma_addr_t *); static void dma_free(void *, size_t); static void hard_stop(struct net_device *); +static void enable_rx_tx(struct net_device *dev); static int __init au1000_probe1(struct net_device *, long, int, int); static int au1000_init(struct net_device *); static int au1000_open(struct net_device *); @@ -78,15 +80,17 @@ static inline void update_tx_stats(struct net_device *, u32, u32); static inline void update_rx_stats(struct net_device *, u32); static void au1000_timer(unsigned long); -static void cleanup_buffers(struct net_device *); static int au1000_ioctl(struct net_device *, struct ifreq *, int); static int mdio_read(struct net_device *, int, int); static void mdio_write(struct net_device *, int, int, u16); -static inline void sync(void); +static void dump_mii(struct net_device *dev, int phy_id); +// externs extern void ack_rise_edge_irq(unsigned int); - -static int next_dev; +extern int get_ethernet_addr(char *ethernet_addr); +extern inline void str2eaddr(unsigned char *ea, unsigned char *str); +extern inline unsigned char str2hexnum(unsigned char c); +extern char * __init prom_getcmdline(void); /* * Theory of operation @@ -105,24 +109,30 @@ /* - * Base address and interupt of the Au1000 ethernet macs + * Base address and interupt of the Au1xxx ethernet macs */ static struct { unsigned int port; int irq; } au1000_iflist[NUM_INTERFACES] = { - {AU1000_ETH0_BASE, AU1000_ETH0_IRQ}, - {AU1000_ETH1_BASE, AU1000_ETH1_IRQ} -}; + {AU1000_ETH0_BASE, AU1000_ETH0_IRQ}, + {AU1000_ETH1_BASE, AU1000_ETH1_IRQ} + }, + au1500_iflist[NUM_INTERFACES] = { + {AU1500_ETH0_BASE, AU1000_ETH0_IRQ}, + {AU1500_ETH1_BASE, AU1000_ETH1_IRQ} + }; static char version[] __devinitdata = - "au1000eth.c:0.1 ppopov@mvista.com\n"; + "au1000eth.c:1.0 ppopov@mvista.com\n"; -// FIX! Need real Ethernet addresses -static unsigned char au1000_mac_addr[2][6] __devinitdata = { - {0x00, 0x50, 0xc2, 0x0c, 0x30, 0x00}, - {0x00, 0x50, 0xc2, 0x0c, 0x40, 0x00} +/* These addresses are only used if yamon doesn't tell us what + * the mac address is, and the mac address is not passed on the + * command line. + */ +static unsigned char au1000_mac_addr[6] __devinitdata = { + 0x00, 0x50, 0xc2, 0x0c, 0x30, 0x00 }; #define nibswap(x) ((((x) >> 4) & 0x0f) | (((x) << 4) & 0xf0)) @@ -132,11 +142,6 @@ #define cpu_to_dma32 cpu_to_be32 #define dma32_to_cpu be32_to_cpu -/* CPU pipeline flush */ -static inline void sync(void) -{ - asm volatile ("sync"); -} /* FIXME * All of the PHY code really should be detached from the MAC @@ -147,7 +152,8 @@ {"unknown", "10Base2", "10BaseT", "AUI", - "100BaseT", "100BaseTX", "100BaseFX"}; + "100BaseT", "100BaseTX", "100BaseFX" + }; int bcm_5201_init(struct net_device *dev, int phy_addr) { @@ -168,7 +174,8 @@ data = mdio_read(dev, phy_addr, MII_CONTROL); data |= MII_CNTL_RST_AUTO | MII_CNTL_AUTO; mdio_write(dev, phy_addr, MII_CONTROL, data); - //dump_mii(dev, phy_addr); + + if (au1000_debug > 4) dump_mii(dev, phy_addr); return 0; } @@ -228,10 +235,91 @@ else { *link = 0; *speed = 0; + dev->if_port = IF_PORT_UNKNOWN; } return 0; } +int lsi_80227_init(struct net_device *dev, int phy_addr) +{ + if (au1000_debug > 4) + printk("lsi_80227_init\n"); + + /* restart auto-negotiation */ + mdio_write(dev, phy_addr, 0, 0x3200); + + /* set up LEDs to correct display */ + mdio_write(dev, phy_addr, 17, 0xffc0); + + if (au1000_debug > 4) + dump_mii(dev, phy_addr); + return 0; +} + +int lsi_80227_reset(struct net_device *dev, int phy_addr) +{ + s16 mii_control, timeout; + + if (au1000_debug > 4) { + printk("lsi_80227_reset\n"); + dump_mii(dev, phy_addr); + } + + mii_control = mdio_read(dev, phy_addr, MII_CONTROL); + mdio_write(dev, phy_addr, MII_CONTROL, mii_control | MII_CNTL_RESET); + mdelay(1); + for (timeout = 100; timeout > 0; --timeout) { + mii_control = mdio_read(dev, phy_addr, MII_CONTROL); + if ((mii_control & MII_CNTL_RESET) == 0) + break; + mdelay(1); + } + if (mii_control & MII_CNTL_RESET) { + printk(KERN_ERR "%s PHY reset timeout !\n", dev->name); + return -1; + } + return 0; +} + +int +lsi_80227_status(struct net_device *dev, int phy_addr, u16 *link, u16 *speed) +{ + u16 mii_data; + struct au1000_private *aup; + + if (!dev) { + printk(KERN_ERR "lsi_80227_status error: NULL dev\n"); + return -1; + } + aup = (struct au1000_private *) dev->priv; + + mii_data = mdio_read(dev, aup->phy_addr, MII_STATUS); + if (mii_data & MII_STAT_LINK) { + *link = 1; + mii_data = mdio_read(dev, aup->phy_addr, MII_LSI_STAT); + if (mii_data & MII_LSI_STAT_SPD) { + if (mii_data & MII_LSI_STAT_FDX) { + *speed = IF_PORT_100BASEFX; + dev->if_port = IF_PORT_100BASEFX; + } + else { + *speed = IF_PORT_100BASETX; + dev->if_port = IF_PORT_100BASETX; + } + } + else { + *speed = IF_PORT_10BASET; + dev->if_port = IF_PORT_10BASET; + } + + } + else { + *link = 0; + *speed = 0; + dev->if_port = IF_PORT_UNKNOWN; + } + return 0; +} int am79c901_init(struct net_device *dev, int phy_addr) { @@ -263,6 +351,12 @@ am79c901_status, }; +struct phy_ops lsi_80227_ops = { + lsi_80227_init, + lsi_80227_reset, + lsi_80227_status, +}; + static struct mii_chip_info { const char * name; u16 phy_id0; @@ -271,6 +365,7 @@ } mii_chip_table[] = { {"Broadcom BCM5201 10/100 BaseT PHY", 0x0040, 0x6212, &bcm_5201_ops }, {"AMD 79C901 HomePNA PHY", 0x0000, 0x35c8, &am79c901_ops }, + {"LSI 80227 10/100 BaseT PHY", 0x0016, 0xf840, &lsi_80227_ops }, {0,}, }; @@ -283,7 +378,8 @@ while (aup->mac->mii_control & MAC_MII_BUSY) { mdelay(1); if (--timedout == 0) { - printk(KERN_ERR "%s: read_MII busy timeout!!\n", dev->name); + printk(KERN_ERR "%s: read_MII busy timeout!!\n", + dev->name); return -1; } } @@ -297,7 +393,8 @@ while (aup->mac->mii_control & MAC_MII_BUSY) { mdelay(1); if (--timedout == 0) { - printk(KERN_ERR "%s: mdio_read busy timeout!!\n", dev->name); + printk(KERN_ERR "%s: mdio_read busy timeout!!\n", + dev->name); return -1; } } @@ -313,7 +410,8 @@ while (aup->mac->mii_control & MAC_MII_BUSY) { mdelay(1); if (--timedout == 0) { - printk(KERN_ERR "%s: mdio_write busy timeout!!\n", dev->name); + printk(KERN_ERR "%s: mdio_write busy timeout!!\n", + dev->name); return; } } @@ -362,25 +460,34 @@ phy_id1 = mdio_read(dev, phy_addr, MII_PHY_ID1); /* search our mii table for the current mii */ - for (i = 0; mii_chip_table[i].phy_id1; i++) + for (i = 0; mii_chip_table[i].phy_id1; i++) { if (phy_id0 == mii_chip_table[i].phy_id0 && phy_id1 == mii_chip_table[i].phy_id1) { struct mii_phy * mii_phy; - printk(KERN_INFO "%s: %s found at phy address %d\n", - dev->name, mii_chip_table[i].name, phy_addr); - if ((mii_phy = kmalloc(sizeof(struct mii_phy), GFP_KERNEL)) != NULL) { + printk(KERN_INFO "%s: %s at phy address %d\n", + dev->name, mii_chip_table[i].name, + phy_addr); + mii_phy = kmalloc(sizeof(struct mii_phy), + GFP_KERNEL); + if (mii_phy) { mii_phy->chip_info = mii_chip_table+i; mii_phy->phy_addr = phy_addr; - //mii_phy->status = mdio_read(dev, phy_addr, MII_STATUS); mii_phy->next = aup->mii; - aup->phy_ops = mii_chip_table[i].phy_ops; + aup->phy_ops = + mii_chip_table[i].phy_ops; aup->mii = mii_phy; + aup->phy_ops->phy_init(dev,phy_addr); + } else { + printk(KERN_ERR "%s: out of memory\n", + dev->name); + return -1; } /* the current mii is on our mii_info_table, try next address */ break; } + } } if (aup->mii == NULL) { @@ -390,7 +497,8 @@ /* use last PHY */ aup->phy_addr = aup->mii->phy_addr; - printk(KERN_INFO "%s: Using %s as default\n", dev->name, aup->mii->chip_info->name); + printk(KERN_INFO "%s: Using %s as default\n", + dev->name, aup->mii->chip_info->name); return 0; } @@ -437,7 +545,7 @@ if (ret != NULL) { memset(ret, 0, size); *dma_handle = virt_to_bus(ret); - ret = KSEG0ADDR(ret); + ret = (void *)KSEG0ADDR(ret); } return ret; } @@ -445,11 +553,22 @@ static void dma_free(void *vaddr, size_t size) { - vaddr = KSEG0ADDR(vaddr); + vaddr = (void *)KSEG0ADDR(vaddr); free_pages((unsigned long) vaddr, get_order(size)); } +static void enable_rx_tx(struct net_device *dev) +{ + struct au1000_private *aup = (struct au1000_private *) dev->priv; + + if (au1000_debug > 4) + printk(KERN_INFO "%s: enable_rx_tx\n", dev->name); + + aup->mac->control |= (MAC_RX_ENABLE | MAC_TX_ENABLE); + au_sync_delay(10); +} + static void hard_stop(struct net_device *dev) { struct au1000_private *aup = (struct au1000_private *) dev->priv; @@ -458,8 +577,7 @@ printk(KERN_INFO "%s: hard stop\n", dev->name); aup->mac->control &= ~(MAC_RX_ENABLE | MAC_TX_ENABLE); - sync(); - mdelay(10); + au_sync_delay(10); } @@ -468,39 +586,21 @@ u32 flags; struct au1000_private *aup = (struct au1000_private *) dev->priv; - if (au1000_debug > 4) - printk(KERN_INFO "%s: reset mac, aup %x\n", dev->name, (unsigned)aup); + if (au1000_debug > 4) + printk(KERN_INFO "%s: reset mac, aup %x\n", + dev->name, (unsigned)aup); spin_lock_irqsave(&aup->lock, flags); del_timer(&aup->timer); hard_stop(dev); - *aup->enable |= MAC_DMA_RESET; - sync(); - mdelay(10); + *aup->enable = MAC_EN_CLOCK_ENABLE; + au_sync_delay(2); + *aup->enable = 0; + au_sync_delay(2); aup->tx_full = 0; spin_unlock_irqrestore(&aup->lock, flags); } -static void cleanup_buffers(struct net_device *dev) -{ - int i; - struct au1000_private *aup = (struct au1000_private *) dev->priv; - - for (i=0; irx_db_inuse[i]) { - ReleaseDB(aup, aup->rx_db_inuse[i]); - aup->rx_db_inuse[i] = 0; - } - } - - for (i=0; itx_db_inuse[i]) { - ReleaseDB(aup, aup->tx_db_inuse[i]); - aup->tx_db_inuse[i] = 0; - } - } -} - /* * Setup the receive and transmit "rings". These pointers are the addresses @@ -513,44 +613,40 @@ int i; for (i=0; irx_dma_ring[i] = (volatile rx_dma_t *) ioremap_nocache((unsigned long) - (rx_base + sizeof(rx_dma_t)*i), sizeof(rx_dma_t)); + aup->rx_dma_ring[i] = + (volatile rx_dma_t *) (rx_base + sizeof(rx_dma_t)*i); } for (i=0; itx_dma_ring[i] = (volatile tx_dma_t *)ioremap_nocache((unsigned long) - (tx_base + sizeof(tx_dma_t)*i), sizeof(tx_dma_t)); + aup->tx_dma_ring[i] = + (volatile tx_dma_t *) (tx_base + sizeof(tx_dma_t)*i); } } -/* - * Probe for a AU1000 ethernet controller. - */ -int __init au1000_probe(struct net_device *dev) +static int __init au1000_init_module(void) { - int base_addr = au1000_iflist[next_dev].port; - int irq = au1000_iflist[next_dev].irq; - -#ifndef CONFIG_MIPS_AU1000_ENET - return -ENODEV; -#endif - - if (au1000_debug > 4) - printk(KERN_INFO "%s: au1000_probe base_addr %x\n", - dev->name, base_addr); + int i; + int prid; + int base_addr, irq; - if (next_dev >= NUM_INTERFACES) { - return -ENODEV; - } - if (au1000_probe1(dev, base_addr, irq, next_dev) == 0) { - next_dev++; - return 0; + prid = read_32bit_cp0_register(CP0_PRID); + for (i=0; iname, ioaddr, irq); - + printk("%s: Au1xxx ethernet found at 0x%lx, irq %d\n", + dev->name, ioaddr, irq); /* Initialize our private structure */ if (dev->priv == NULL) { - aup = (struct au1000_private *) kmalloc(sizeof(*aup), GFP_KERNEL); + aup = (struct au1000_private *) + kmalloc(sizeof(*aup), GFP_KERNEL); if (aup == NULL) { retval = -ENOMEM; goto free_region; @@ -597,52 +690,75 @@ /* Allocate the data buffers */ - aup->vaddr = (u32)dma_alloc(MAX_BUF_SIZE * (NUM_TX_BUFFS+NUM_RX_BUFFS), &aup->dma_addr); + aup->vaddr = (u32)dma_alloc(MAX_BUF_SIZE * + (NUM_TX_BUFFS+NUM_RX_BUFFS), &aup->dma_addr); if (!aup->vaddr) { retval = -ENOMEM; goto free_region; } /* aup->mac is the base address of the MAC's registers */ - aup->mac = (volatile mac_reg_t *)ioremap_nocache((unsigned long)ioaddr, sizeof(*aup->mac)); + aup->mac = (volatile mac_reg_t *)((unsigned long)ioaddr); /* Setup some variables for quick register address access */ - if (ioaddr == AU1000_ETH0_BASE) { - aup->enable = (volatile u32 *) - ioremap_nocache((unsigned long)MAC0_ENABLE, sizeof(*aup->enable)); - memcpy(dev->dev_addr, au1000_mac_addr[0], sizeof(dev->dev_addr)); + switch (ioaddr) { + case AU1000_ETH0_BASE: + case AU1500_ETH0_BASE: + /* check env variables first */ + if (!get_ethernet_addr(ethaddr)) { + memcpy(au1000_mac_addr, ethaddr, sizeof(dev->dev_addr)); + } else { + /* Check command line */ + argptr = prom_getcmdline(); + if ((pmac = strstr(argptr, "ethaddr=")) == NULL) { + printk(KERN_INFO "%s: No mac address found\n", + dev->name); + /* use the hard coded mac addresses */ + } else { + str2eaddr(ethaddr, pmac + strlen("ethaddr=")); + memcpy(au1000_mac_addr, ethaddr, + sizeof(dev->dev_addr)); + } + } + if (ioaddr == AU1000_ETH0_BASE) + aup->enable = (volatile u32 *) + ((unsigned long)AU1000_MAC0_ENABLE); + else + aup->enable = (volatile u32 *) + ((unsigned long)AU1500_MAC0_ENABLE); + memcpy(dev->dev_addr, au1000_mac_addr, sizeof(dev->dev_addr)); setup_hw_rings(aup, MAC0_RX_DMA_ADDR, MAC0_TX_DMA_ADDR); - } - else if (ioaddr == AU1000_ETH1_BASE) { - aup->enable = (volatile u32 *) - ioremap_nocache((unsigned long)MAC1_ENABLE, sizeof(*aup->enable)); - memcpy(dev->dev_addr, au1000_mac_addr[1], sizeof(dev->dev_addr)); + break; + case AU1000_ETH1_BASE: + case AU1500_ETH1_BASE: + if (ioaddr == AU1000_ETH1_BASE) + aup->enable = (volatile u32 *) + ((unsigned long)AU1000_MAC1_ENABLE); + else + aup->enable = (volatile u32 *) + ((unsigned long)AU1500_MAC1_ENABLE); + memcpy(dev->dev_addr, au1000_mac_addr, sizeof(dev->dev_addr)); + dev->dev_addr[4] += 0x10; setup_hw_rings(aup, MAC1_RX_DMA_ADDR, MAC1_TX_DMA_ADDR); - } - else { /* should never happen */ - printk (KERN_ERR "au1000 eth: bad ioaddr %x\n", (unsigned)ioaddr); - retval = -ENODEV; - goto free_region; + break; + default: + printk(KERN_ERR "%s: bad ioaddr\n", dev->name); + break; + } aup->phy_addr = PHY_ADDRESS; + /* bring the device out of reset, otherwise probing the mii * will hang */ - *aup->enable = MAC_EN_RESET0 | MAC_EN_RESET1 | MAC_EN_RESET2 | - MAC_EN_CLOCK_ENABLE | MAC_EN_TOSS; - sync(); - mdelay(2); + *aup->enable = MAC_EN_CLOCK_ENABLE; + au_sync_delay(2); + *aup->enable = MAC_EN_RESET0 | MAC_EN_RESET1 | + MAC_EN_RESET2 | MAC_EN_CLOCK_ENABLE; + au_sync_delay(2); + if (mii_probe(dev) != 0) { goto free_region; } - aup->phy_ops->phy_status(dev, aup->phy_addr, &link, &speed); - if (!link) { - printk(KERN_INFO "%s: link down resetting...\n", dev->name); - aup->phy_ops->phy_reset(dev, aup->phy_addr); - aup->phy_ops->phy_init(dev, aup->phy_addr); - } - else { - printk(KERN_INFO "%s: link up (%s)\n", dev->name, phy_link[speed]); - } pDBfree = NULL; /* setup the data buffer descriptors and attach a buffer to each one */ @@ -688,18 +804,18 @@ ether_setup(dev); /* - * The boot code uses the ethernet controller, so reset it to start fresh. - * au1000_init() expects that the device is in reset state. + * The boot code uses the ethernet controller, so reset it to start + * fresh. au1000_init() expects that the device is in reset state. */ reset_mac(dev); - return 0; free_region: release_region(ioaddr, MAC_IOSIZE); unregister_netdev(dev); - if (aup->vaddr) - dma_free((void *)aup->vaddr, MAX_BUF_SIZE * (NUM_TX_BUFFS+NUM_RX_BUFFS)); + if (aup->vaddr) + dma_free((void *)aup->vaddr, + MAX_BUF_SIZE * (NUM_TX_BUFFS+NUM_RX_BUFFS)); if (dev->priv != NULL) kfree(dev->priv); kfree(dev); @@ -723,18 +839,19 @@ struct au1000_private *aup = (struct au1000_private *) dev->priv; u32 flags; int i; - u32 value, control; + u32 control; + u16 link, speed; - if (au1000_debug > 4) printk("%s: au1000_init", dev->name); + if (au1000_debug > 4) printk("%s: au1000_init\n", dev->name); spin_lock_irqsave(&aup->lock, flags); /* bring the device out of reset */ - value = MAC_EN_RESET0 | MAC_EN_RESET1 | MAC_EN_RESET2 | - MAC_EN_CLOCK_ENABLE | MAC_EN_TOSS; - *aup->enable = value; - sync(); - mdelay(200); + *aup->enable = MAC_EN_CLOCK_ENABLE; + au_sync_delay(2); + *aup->enable = MAC_EN_RESET0 | MAC_EN_RESET1 | + MAC_EN_RESET2 | MAC_EN_CLOCK_ENABLE; + au_sync_delay(20); aup->mac->control = 0; aup->tx_head = (aup->tx_dma_ring[0]->buff_stat & 0xC) >> 2; @@ -748,13 +865,18 @@ for (i=0; irx_dma_ring[i]->buff_stat |= RX_DMA_ENABLE; } + au_sync(); - sync(); + aup->phy_ops->phy_status(dev, aup->phy_addr, &link, &speed); control = MAC_DISABLE_RX_OWN | MAC_RX_ENABLE | MAC_TX_ENABLE; #ifndef CONFIG_CPU_LITTLE_ENDIAN control |= MAC_BIG_ENDIAN; #endif + if (link && (dev->if_port == IF_PORT_100BASEFX)) { + control |= MAC_FULL_DUPLEX; + } aup->mac->control = control; + au_sync(); spin_unlock_irqrestore(&aup->lock, flags); return 0; @@ -764,23 +886,22 @@ { struct net_device *dev = (struct net_device *)data; struct au1000_private *aup = (struct au1000_private *) dev->priv; - u16 mii_data, link, speed; + unsigned char if_port; + u16 link, speed; if (!dev) { /* fatal error, don't restart the timer */ printk(KERN_ERR "au1000_timer error: NULL dev\n"); return; } - if (!(dev->flags & IFF_UP)) { - goto set_timer; - } + if_port = dev->if_port; if (aup->phy_ops->phy_status(dev, aup->phy_addr, &link, &speed) == 0) { if (link) { if (!(dev->flags & IFF_RUNNING)) { netif_carrier_on(dev); dev->flags |= IFF_RUNNING; - printk(KERN_DEBUG "%s: link up\n", dev->name); + printk(KERN_INFO "%s: link up\n", dev->name); } } else { @@ -788,12 +909,27 @@ netif_carrier_off(dev); dev->flags &= ~IFF_RUNNING; dev->if_port = 0; - printk(KERN_DEBUG "%s: link down\n", dev->name); + printk(KERN_INFO "%s: link down\n", dev->name); } } } -set_timer: + if (link && (dev->if_port != if_port) && + (dev->if_port != IF_PORT_UNKNOWN)) { + hard_stop(dev); + if (dev->if_port == IF_PORT_100BASEFX) { + printk(KERN_INFO "%s: going to full duplex\n", + dev->name); + aup->mac->control |= MAC_FULL_DUPLEX; + au_sync_delay(1); + } + else { + aup->mac->control &= ~MAC_FULL_DUPLEX; + au_sync_delay(1); + } + enable_rx_tx(dev); + } + aup->timer.expires = RUN_AT((1*HZ)); aup->timer.data = (unsigned long)dev; aup->timer.function = &au1000_timer; /* timer handler */ @@ -819,8 +955,10 @@ } netif_start_queue(dev); - if ((retval = request_irq(dev->irq, &au1000_interrupt, 0, dev->name, dev))) { - printk(KERN_ERR "%s: unable to get IRQ %d\n", dev->name, dev->irq); + if ((retval = request_irq(dev->irq, &au1000_interrupt, 0, + dev->name, dev))) { + printk(KERN_ERR "%s: unable to get IRQ %d\n", + dev->name, dev->irq); MOD_DEC_USE_COUNT; return retval; } @@ -860,8 +998,13 @@ return 0; } +static void __exit au1000_cleanup_module(void) +{ +} + -static inline void update_tx_stats(struct net_device *dev, u32 status, u32 pkt_len) +static inline void +update_tx_stats(struct net_device *dev, u32 status, u32 pkt_len) { struct au1000_private *aup = (struct au1000_private *) dev->priv; struct net_device_stats *ps = &aup->stats; @@ -870,10 +1013,20 @@ ps->tx_bytes += pkt_len; if (status & TX_FRAME_ABORTED) { - ps->tx_errors++; - ps->tx_aborted_errors++; - if (status & (TX_NO_CARRIER | TX_LOSS_CARRIER)) - ps->tx_carrier_errors++; + if (dev->if_port == IF_PORT_100BASEFX) { + if (status & (TX_JAB_TIMEOUT | TX_UNDERRUN)) { + /* any other tx errors are only valid + * in half duplex mode */ + ps->tx_errors++; + ps->tx_aborted_errors++; + } + } + else { + ps->tx_errors++; + ps->tx_aborted_errors++; + if (status & (TX_NO_CARRIER | TX_LOSS_CARRIER)) + ps->tx_carrier_errors++; + } } } @@ -894,7 +1047,7 @@ update_tx_stats(dev, ptxd->status, ptxd->len & 0x3ff); ptxd->buff_stat &= ~TX_T_DONE; ptxd->len = 0; - sync(); + au_sync(); aup->tx_tail = (aup->tx_tail + 1) & (NUM_TX_DMA - 1); ptxd = aup->tx_dma_ring[aup->tx_tail]; @@ -913,26 +1066,22 @@ static int au1000_tx(struct sk_buff *skb, struct net_device *dev) { struct au1000_private *aup = (struct au1000_private *) dev->priv; - //unsigned long flags; volatile tx_dma_t *ptxd; u32 buff_stat; db_dest_t *pDB; int i; if (au1000_debug > 4) - printk("%s: tx: aup %x len=%d, data=%p, head %d\n", - dev->name, (unsigned)aup, skb->len, skb->data, aup->tx_head); + printk("%s: tx: aup %x len=%d, data=%p, head %d\n", + dev->name, (unsigned)aup, skb->len, + skb->data, aup->tx_head); - /* Prevent interrupts from changing the Tx ring */ - //spin_lock_irqsave(&aup->lock, flags); - ptxd = aup->tx_dma_ring[aup->tx_head]; buff_stat = ptxd->buff_stat; if (buff_stat & TX_DMA_ENABLE) { /* We've wrapped around and the transmitter is still busy */ netif_stop_queue(dev); aup->tx_full = 1; - //spin_unlock_irqrestore(&aup->lock, flags); return 1; } else if (buff_stat & TX_T_DONE) { @@ -957,11 +1106,10 @@ ptxd->len = skb->len; ptxd->buff_stat = pDB->dma_addr | TX_DMA_ENABLE; - sync(); + au_sync(); dev_kfree_skb(skb); aup->tx_head = (aup->tx_head + 1) & (NUM_TX_DMA - 1); dev->trans_start = jiffies; - //spin_unlock_irqrestore(&aup->lock, flags); return 0; } @@ -1026,7 +1174,7 @@ skb_reserve(skb, 2); /* 16 byte IP header align */ eth_copy_and_sum(skb, (unsigned char *)pDB->vaddr, status & RX_FRAME_LEN_MASK, 0); - skb_put(skb, status & RX_FRAME_LEN_MASK); /* Make room */ + skb_put(skb, status & RX_FRAME_LEN_MASK); skb->protocol = eth_type_trans(skb, dev); netif_rx(skb); /* pass the packet to upper layers */ } @@ -1056,7 +1204,7 @@ } prxd->buff_stat = (u32)(pDB->dma_addr | RX_DMA_ENABLE); aup->rx_head = (aup->rx_head + 1) & (NUM_RX_DMA - 1); - sync(); + au_sync(); /* next descriptor */ prxd = aup->rx_dma_ring[aup->rx_head]; @@ -1078,8 +1226,8 @@ printk(KERN_ERR "%s: isr: null dev ptr\n", dev->name); return; } - au1000_rx(dev); au1000_tx_ack(dev); + au1000_rx(dev); } @@ -1105,7 +1253,8 @@ int bit; for (bit = 0; bit < 8; bit++, current_octet >>= 1) crc = (crc << 1) ^ - ((crc < 0) ^ (current_octet & 1) ? ethernet_polynomial : 0); + ((crc < 0) ^ (current_octet & 1) ? + ethernet_polynomial : 0); } return crc; } @@ -1114,9 +1263,8 @@ { struct au1000_private *aup = (struct au1000_private *) dev->priv; - /* fixme */ if (au1000_debug > 4) - printk("%s: set_multicast: flags=%x\n", dev->name, dev->flags); + printk("%s: set_rx_mode: flags=%x\n", dev->name, dev->flags); if (dev->flags & IFF_PROMISC) { /* Set promiscuous. */ aup->mac->control |= MAC_PROMISCUOUS; @@ -1134,10 +1282,12 @@ mc_filter[1] = mc_filter[0] = 0; for (i = 0, mclist = dev->mc_list; mclist && i < dev->mc_count; i++, mclist = mclist->next) { - set_bit(ether_crc(ETH_ALEN, mclist->dmi_addr)>>26, mc_filter); + set_bit(ether_crc(ETH_ALEN, mclist->dmi_addr)>>26, + mc_filter); } aup->mac->multi_hash_high = mc_filter[1]; aup->mac->multi_hash_low = mc_filter[0]; + aup->mac->control &= ~MAC_PROMISCUOUS; aup->mac->control |= MAC_HASH_MODE; } } @@ -1145,17 +1295,16 @@ static int au1000_ioctl(struct net_device *dev, struct ifreq *rq, int cmd) { - //struct au1000_private *aup = (struct au1000_private *) dev->priv; u16 *data = (u16 *)&rq->ifr_data; /* fixme */ switch(cmd) { - case SIOCDEVPRIVATE: /* Get the address of the PHY in use. */ + case SIOCDEVPRIVATE: /* Get the address of the PHY in use. */ data[0] = PHY_ADDRESS; - case SIOCDEVPRIVATE+1: /* Read the specified MII register. */ + case SIOCDEVPRIVATE+1: /* Read the specified MII register. */ //data[3] = mdio_read(ioaddr, data[0], data[1]); return 0; - case SIOCDEVPRIVATE+2: /* Write the specified MII register */ + case SIOCDEVPRIVATE+2: /* Write the specified MII register */ //mdio_write(ioaddr, data[0], data[1], data[2]); return 0; default: @@ -1176,7 +1325,8 @@ switch(map->port){ case IF_PORT_UNKNOWN: /* use auto here */ - printk("auto\\n"); + printk(KERN_INFO "%s: config phy for aneg\n", + dev->name); dev->if_port = map->port; /* Link Down: the timer will bring it up */ netif_carrier_off(dev); @@ -1186,13 +1336,15 @@ control &= ~(MII_CNTL_FDX | MII_CNTL_F100); /* enable auto negotiation and reset the negotiation */ - mdio_write(dev, aup->phy_addr, - MII_CONTROL, control | MII_CNTL_AUTO | MII_CNTL_RST_AUTO); + mdio_write(dev, aup->phy_addr, MII_CONTROL, + control | MII_CNTL_AUTO | + MII_CNTL_RST_AUTO); break; case IF_PORT_10BASET: /* 10BaseT */ - printk("10baseT\n"); + printk(KERN_INFO "%s: config phy for 10BaseT\n", + dev->name); dev->if_port = map->port; /* Link Down: the timer will bring it up */ @@ -1200,8 +1352,8 @@ /* set Speed to 10Mbps, Half Duplex */ control = mdio_read(dev, aup->phy_addr, MII_CONTROL); - printk("read control %x\n", control); - control &= ~(MII_CNTL_F100 | MII_CNTL_AUTO | MII_CNTL_FDX); + control &= ~(MII_CNTL_F100 | MII_CNTL_AUTO | + MII_CNTL_FDX); /* disable auto negotiation and force 10M/HD mode*/ mdio_write(dev, aup->phy_addr, MII_CONTROL, control); @@ -1209,7 +1361,8 @@ case IF_PORT_100BASET: /* 100BaseT */ case IF_PORT_100BASETX: /* 100BaseTx */ - printk("100 base T/TX\n"); + printk(KERN_INFO "%s: config phy for 100BaseTX\n", + dev->name); dev->if_port = map->port; /* Link Down: the timer will bring it up */ @@ -1225,7 +1378,8 @@ break; case IF_PORT_100BASEFX: /* 100BaseFx */ - printk("100 Base FX\n"); + printk(KERN_INFO "%s: config phy for 100BaseFX\n", + dev->name); dev->if_port = map->port; /* Link Down: the timer will bring it up */ @@ -1241,12 +1395,14 @@ case IF_PORT_10BASE2: /* 10Base2 */ case IF_PORT_AUI: /* AUI */ /* These Modes are not supported (are they?)*/ - printk(KERN_INFO "Not supported"); + printk(KERN_ERR "%s: 10Base2/AUI not supported", + dev->name); return -EOPNOTSUPP; break; default: - printk("Invalid"); + printk(KERN_ERR "%s: Invalid media selected", + dev->name); return -EINVAL; } return 0; @@ -1264,3 +1420,6 @@ } return 0; } + +module_init(au1000_init_module); +module_exit(au1000_cleanup_module);