pcnet32_purge_tx_ring(dev); 
static int pcnet32_loopback_test(struct net_device *dev, uint64_t *data1){    struct pcnet32_private *lp = dev->priv;    struct pcnet32_access *a = &lp->a;	/* access to registers */    ulong ioaddr = dev->base_addr;	/* card base I/O address */    struct sk_buff *skb;		/* sk buff */    int x, i;				/* counters */    int numbuffs = 4;			/* number of TX/RX buffers and descs */    u16 status = 0x8300;		/* TX ring status */    u16 teststatus;			/* test of ring status */    int rc;				/* return code */    int size;				/* size of packets */    unsigned char *packet;		/* source packet data */    static int data_len = 60;		/* length of source packets */    unsigned long flags;    unsigned long ticks;    *data1 = 1;			/* status of test, default to fail */    rc = 1;			/* default to fail */    if (netif_running(dev))	pcnet32_close(dev);    spin_lock_irqsave(&lp->lock, flags);    /* Reset the PCNET32 */    lp->a.reset (ioaddr);    /* switch pcnet32 to 32bit mode */    lp->a.write_bcr (ioaddr, 20, 2);    lp->init_block.mode = le16_to_cpu((lp->options & PCNET32_PORT_PORTSEL) << 7);    lp->init_block.filter[0] = 0;    lp->init_block.filter[1] = 0;    /* purge & init rings but don't actually restart */    pcnet32_restart(dev, 0x0000);    lp->a.write_csr(ioaddr, 0, 0x0004);	/* Set STOP bit */    /* Initialize Transmit buffers. */    size = data_len + 15;    for (x=0; x<numbuffs; x++) {	if (!(skb = dev_alloc_skb(size))) {	    if (netif_msg_hw(lp))		printk(KERN_DEBUG "%s: Cannot allocate skb at line: %d!\n",		    dev->name, __LINE__);	    goto clean_up;	} else {	    packet = skb->data;	    skb_put(skb, size);		/* create space for data */	    lp->tx_skbuff[x] = skb;	    lp->tx_ring[x].length = le16_to_cpu(-skb->len);	    lp->tx_ring[x].misc = 0;            /* put DA and SA into the skb */	    for (i=0; i<6; i++)		*packet++ = dev->dev_addr[i];	    for (i=0; i<6; i++)		*packet++ = dev->dev_addr[i];	    /* type */	    *packet++ = 0x08;	    *packet++ = 0x06;	    /* packet number */	    *packet++ = x;	    /* fill packet with data */	    for (i=0; i<data_len; i++)		*packet++ = i;	    lp->tx_dma_addr[x] = pci_map_single(lp->pci_dev, skb->data,		    skb->len, PCI_DMA_TODEVICE);	    lp->tx_ring[x].base = (u32)le32_to_cpu(lp->tx_dma_addr[x]);	    wmb(); /* Make sure owner changes after all others are visible */	    lp->tx_ring[x].status = le16_to_cpu(status);	}    }    x = a->read_bcr(ioaddr, 32);	/* set internal loopback in BSR32 */    x = x | 0x0002;    a->write_bcr(ioaddr, 32, x);    lp->a.write_csr (ioaddr, 15, 0x0044);	/* set int loopback in CSR15 */    teststatus = le16_to_cpu(0x8000);    lp->a.write_csr(ioaddr, 0, 0x0002);		/* Set STRT bit */    /* Check status of descriptors */    for (x=0; x<numbuffs; x++) {	ticks = 0;	rmb();	while ((lp->rx_ring[x].status & teststatus) && (ticks < 200)) {	    spin_unlock_irqrestore(&lp->lock, flags);	    mdelay(1);	    spin_lock_irqsave(&lp->lock, flags);	    rmb();	    ticks++;	}	if (ticks == 200) {	    if (netif_msg_hw(lp))		printk("%s: Desc %d failed to reset!\n",dev->name,x);	    break;	}    }    lp->a.write_csr(ioaddr, 0, 0x0004);		/* Set STOP bit */    wmb();    if (netif_msg_hw(lp) && netif_msg_pktdata(lp)) {	printk(KERN_DEBUG "%s: RX loopback packets:\n", dev->name);	for (x=0; x<numbuffs; x++) {	    printk(KERN_DEBUG "%s: Packet %d:\n", dev->name, x);	    skb = lp->rx_skbuff[x];	    for (i=0; i<size; i++) {		printk("%02x ", *(skb->data+i));	    }	    printk("\n");	}    }    x = 0;    rc = 0;    while (x<numbuffs && !rc) {	skb = lp->rx_skbuff[x];	packet = lp->tx_skbuff[x]->data;	for (i=0; i<size; i++) {	    if (*(skb->data+i) != packet[i]) {		if (netif_msg_hw(lp))		    printk(KERN_DEBUG "%s: Error in compare! %2x - %02x %02x\n",			    dev->name, i, *(skb->data+i), packet[i]);		rc = 1;		break;	    }	}	x++;    }    if (!rc) {	*data1 = 0;    }clean_up:    x = a->read_csr(ioaddr, 15) & 0xFFFF;    a->write_csr(ioaddr, 15, (x & ~0x0044));	/* reset bits 6 and 2 */    x = a->read_bcr(ioaddr, 32);		/* reset internal loopback */    x = x & ~0x0002;    a->write_bcr(ioaddr, 32, x);    spin_unlock_irqrestore(&lp->lock, flags);    if (netif_running(dev)) {	pcnet32_open(dev);    } else {	lp->a.write_bcr (ioaddr, 20, 4);	/* return to 16bit mode */    }    return(rc);} /* end pcnet32_loopback_test  */
10457	/local/tlutelli/issta_data/temp/c/2005_temp/2005/10457/1bcd315362e215a72b56d1330bbf32f1c74eefb5/pcnet32.c/clean/drivers/net/pcnet32.c