⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 sk_g16.c

📁 linux和2410结合开发 用他可以生成2410所需的zImage文件
💻 C
📖 第 1 页 / 共 4 页
字号:
                 * Couldn't allocate sk_buffer so we give descriptor back		 * to Lance, update statistics and go ahead.		 */		writeb(RX_OWN, &rmdp->u.s.status); /* Relinquish ownership to LANCE */		printk("%s: Couldn't allocate sk_buff, deferring packet.\n",		       dev->name);		p->stats.rx_dropped++;		break;                      /* Jump out */	    }	    	    /* Prepare sk_buff to queue for upper layers */	    skb->dev = dev;	    skb_reserve(skb,2);		/* Align IP header on 16 byte boundary */	    	    /*              * Copy data out of our receive descriptor into sk_buff.	     *	     * (rmdp->u.buffer & 0x00ffffff) -> get address of buffer and 	     * ignore status fields) 	     */	    memcpy_fromio(skb_put(skb,len), (rmdp->u.buffer & 0x00ffffff), len);	    /*              * Notify the upper protocol layers that there is another packet	     * to handle	     *	     * netif_rx() always succeeds. see /net/inet/dev.c for more.	     */	    skb->protocol=eth_type_trans(skb,dev);	    netif_rx(skb);                 /* queue packet and mark it for processing */	   	    /*              * Packet is queued and marked for processing so we	     * free our descriptor and update statistics 	     */	    writeb(RX_OWN, &rmdp->u.s.status);	    dev->last_rx = jiffies;	    p->stats.rx_packets++;	    p->stats.rx_bytes += len;	    p->rmdnum++;	    p->rmdnum %= RMDNUM;	    rmdp = p->rmdhead + p->rmdnum;	}    }} /* End of SK_rxintr() *//*- * Function       : SK_close * Author         : Patrick J.D. Weichmann * Date Created   : 94/05/26 * * Description    : close gets called from dev_close() and should *                  deinstall the card (free_irq, mem etc). * * Parameters     : I : struct net_device *dev - our device structure * Return Value   : 0 - closed device driver * Errors         : None * Globals        : None * Update History : *     YY/MM/DD  uid  Description-*//* I have tried to set BOOT_ROM on and RAM off but then, after a 'ifconfig * down' the system stops. So I don't shut set card to init state. */static int SK_close(struct net_device *dev){    PRINTK(("## %s: SK_close(). CSR0: %#06x\n",            SK_NAME, SK_read_reg(CSR0)));    netif_stop_queue(dev);	   /* Transmitter busy */    printk("%s: Shutting %s down CSR0 %#06x\n", dev->name, SK_NAME,            (int) SK_read_reg(CSR0));    SK_write_reg(CSR0, CSR0_STOP); /* STOP the LANCE */    free_irq(dev->irq, dev);      /* Free IRQ */    return 0; /* always succeed */    } /* End of SK_close() *//*- * Function       : SK_get_stats * Author         : Patrick J.D. Weichmann * Date Created   : 94/05/26 * * Description    : Return current status structure to upper layers. *                  It is called by sprintf_stats (dev.c). * * Parameters     : I : struct net_device *dev   - our device structure * Return Value   : struct net_device_stats * - our current statistics * Errors         : None * Side Effects   : None * Update History : *     YY/MM/DD  uid  Description-*/static struct net_device_stats *SK_get_stats(struct net_device *dev){    struct priv *p = (struct priv *) dev->priv;    PRINTK(("## %s: SK_get_stats(). CSR0: %#06x\n",            SK_NAME, SK_read_reg(CSR0)));    return &p->stats;             /* Return Device status */} /* End of SK_get_stats() *//*- * Function       : set_multicast_list * Author         : Patrick J.D. Weichmann * Date Created   : 94/05/26 * * Description    : This function gets called when a program performs *                  a SIOCSIFFLAGS call. Ifconfig does this if you call *                  'ifconfig [-]allmulti' which enables or disables the *                  Promiscuous mode. *                  Promiscuous mode is when the Network card accepts all *                  packets, not only the packets which match our MAC  *                  Address. It is useful for writing a network monitor, *                  but it is also a security problem. You have to remember *                  that all information on the net is not encrypted. * * Parameters     : I : struct net_device *dev - SK_G16 device Structure * Return Value   : None * Errors         : None * Globals        : None * Update History : *     YY/MM/DD  uid  Description *     95/10/18  ACox  New multicast calling scheme-*//* Set or clear the multicast filter for SK_G16. */static void set_multicast_list(struct net_device *dev){    if (dev->flags&IFF_PROMISC)    {	/* Reinitialize LANCE with MODE_PROM set */	SK_lance_init(dev, MODE_PROM);    }    else if (dev->mc_count==0 && !(dev->flags&IFF_ALLMULTI))    {	/* Reinitialize LANCE without MODE_PROM */	SK_lance_init(dev, MODE_NORMAL);    }    else    {	/* Multicast with logical address filter on */	/* Reinitialize LANCE without MODE_PROM */	SK_lance_init(dev, MODE_NORMAL);		/* Not implemented yet. */    }} /* End of set_multicast_list() *//*- * Function       : SK_rom_addr * Author         : Patrick J.D. Weichmann * Date Created   : 94/06/01 * * Description    : Try to find a Boot_ROM at all possible locations * * Parameters     : None * Return Value   : Address where Boot_ROM is * Errors         : 0 - Did not find Boot_ROM * Globals        : None * Update History : *     YY/MM/DD  uid  Description-*/unsigned int __init SK_rom_addr(void){    int i,j;    int rom_found = 0;    unsigned int rom_location[] = SK_BOOT_ROM_LOCATIONS;    unsigned char rom_id[] = SK_BOOT_ROM_ID;    unsigned char test_byte;    /* Autodetect Boot_ROM */    PRINTK(("## %s: Autodetection of Boot_ROM\n", SK_NAME));    for (i = 0; (rom_location[i] != 0) && (rom_found == 0); i++)    {		PRINTK(("##   Trying ROM location %#08x", rom_location[i]));		rom_found = 1; 	for (j = 0; j < 6; j++)	{	    test_byte = readb(rom_location[i]+j);	    PRINTK((" %02x ", *test_byte));	    if(test_byte != rom_id[j])	    {		rom_found = 0;	    } 	}	PRINTK(("\n"));    }    if (rom_found == 1)    {	PRINTK(("## %s: Boot_ROM found at %#08x\n",                SK_NAME, rom_location[(i-1)]));	return (rom_location[--i]);    }    else    {	PRINTK(("%s: No Boot_ROM found\n", SK_NAME));	return 0;    }} /* End of SK_rom_addr() *//* LANCE access functions  * * ! CSR1-3 can only be accessed when in CSR0 the STOP bit is set ! *//*- * Function       : SK_reset_board * * Author         : Patrick J.D. Weichmann * * Date Created   : 94/05/25 * * Description    : This function resets SK_G16 and all components, but *                  POS registers are not changed * * Parameters     : None * Return Value   : None * Errors         : None * Globals        : SK_RAM *board - SK_RAM structure pointer * * Update History : *     YY/MM/DD  uid  Description-*/void SK_reset_board(void){    writeb(0x00, SK_PORT);       /* Reset active */    mdelay(5);                /* Delay min 5ms */    writeb(SK_RESET, SK_PORT);   /* Set back to normal operation */} /* End of SK_reset_board() *//*- * Function       : SK_set_RAP * Author         : Patrick J.D. Weichmann * Date Created   : 94/05/25 * * Description    : Set LANCE Register Address Port to register *                  for later data transfer. * * Parameters     : I : reg_number - which CSR to read/write from/to * Return Value   : None * Errors         : None * Globals        : SK_RAM *board - SK_RAM structure pointer * Update History : *     YY/MM/DD  uid  Description-*/void SK_set_RAP(int reg_number){    writew(reg_number, SK_IOREG);    writeb(SK_RESET | SK_RAP | SK_WREG, SK_PORT);    writeb(SK_DOIO, SK_IOCOM);    while (readb(SK_PORT) & SK_IORUN) 	barrier();} /* End of SK_set_RAP() *//*- * Function       : SK_read_reg * Author         : Patrick J.D. Weichmann * Date Created   : 94/05/25 * * Description    : Set RAP and read data from a LANCE CSR register * * Parameters     : I : reg_number - which CSR to read from * Return Value   : Register contents * Errors         : None * Globals        : SK_RAM *board - SK_RAM structure pointer * Update History : *     YY/MM/DD  uid  Description-*/int SK_read_reg(int reg_number){    SK_set_RAP(reg_number);    writeb(SK_RESET | SK_RDATA | SK_RREG, SK_PORT);    writeb(SK_DOIO, SK_IOCOM);    while (readb(SK_PORT) & SK_IORUN)	barrier();    return (readw(SK_IOREG));} /* End of SK_read_reg() *//*- * Function       : SK_rread_reg * Author         : Patrick J.D. Weichmann * Date Created   : 94/05/28 * * Description    : Read data from preseted register. *                  This function requires that you know which *                  Register is actually set. Be aware that CSR1-3 *                  can only be accessed when in CSR0 STOP is set. * * Return Value   : Register contents * Errors         : None * Globals        : SK_RAM *board - SK_RAM structure pointer * Update History : *     YY/MM/DD  uid  Description-*/int SK_rread_reg(void){    writeb(SK_RESET | SK_RDATA | SK_RREG, SK_PORT);    writeb(SK_DOIO, SK_IOCOM);    while (readb(SK_PORT) & SK_IORUN)	barrier();    return (readw(SK_IOREG));} /* End of SK_rread_reg() *//*- * Function       : SK_write_reg * Author         : Patrick J.D. Weichmann * Date Created   : 94/05/25 * * Description    : This function sets the RAP then fills in the *                  LANCE I/O Reg and starts Transfer to LANCE. *                  It waits until transfer has ended which is max. 7 ms *                  and then it returns. * * Parameters     : I : reg_number - which CSR to write to *                  I : value      - what value to fill into register  * Return Value   : None * Errors         : None * Globals        : SK_RAM *board - SK_RAM structure pointer * Update History : *     YY/MM/DD  uid  Description-*/void SK_write_reg(int reg_number, int value){    SK_set_RAP(reg_number);    writew(value, SK_IOREG);    writeb(SK_RESET | SK_RDATA | SK_WREG, SK_PORT);    writeb(SK_DOIO, SK_IOCOM);    while (readb(SK_PORT) & SK_IORUN)	barrier();} /* End of SK_write_reg *//*  * Debugging functions * ------------------- *//*- * Function       : SK_print_pos * Author         : Patrick J.D. Weichmann * Date Created   : 94/05/25 * * Description    : This function prints out the 4 POS (Programmable *                  Option Select) Registers. Used mainly to debug operation. * * Parameters     : I : struct net_device *dev - SK_G16 device structure *                  I : char * - Text which will be printed as title * Return Value   : None * Errors         : None * Update History : *     YY/MM/DD  uid  Description-*/void SK_print_pos(struct net_device *dev, char *text){    int ioaddr = dev->base_addr;    unsigned char pos0 = inb(SK_POS0),		  pos1 = inb(SK_POS1),		  pos2 = inb(SK_POS2),		  pos3 = inb(SK_POS3),		  pos4 = inb(SK_POS4);    printk("## %s: %s.\n"           "##   pos0=%#4x pos1=%#4x pos2=%#04x pos3=%#08x pos4=%#04x\n",           SK_NAME, text, pos0, pos1, pos2, (pos3<<14), pos4);} /* End of SK_print_pos() *//*- * Function       : SK_print_dev * Author         : Patrick J.D. Weichmann * Date Created   : 94/05/25 * * Description    : This function simply prints out the important fields *                  of the device structure. * * Parameters     : I : struct net_device *dev  - SK_G16 device structure *                  I : char *text - Title for printing * Return Value   : None * Errors         : None * Update History : *     YY/MM/DD  uid  Description-*/void SK_print_dev(struct net_device *dev, char *text){    if (dev == NULL)    {	printk("## %s: Device Structure. %s\n", SK_NAME, text);	printk("## DEVICE == NULL\n");    }    else    {	printk("## %s: Device Structure. %s\n", SK_NAME, text);	printk("## Device Name: %s Base Address: %#06lx IRQ: %d\n",                dev->name, dev->base_addr, dev->irq);	       	printk("## next device: %#08x init function: %#08x\n",               (int) dev->next, (int) dev->init);    }} /* End of SK_print_dev() *//*- * Function       : SK_print_ram * Author         : Patrick J.D. Weichmann * Date Created   : 94/06/02 * * Description    : This function is used to check how are things set up *                  in the 16KB RAM. Also the pointers to the receive and  *                  transmit descriptor rings and rx and tx buffers locations. *                  It contains a minor bug in printing, but has no effect to the values *                  only newlines are not correct. * * Parameters     : I : struct net_device *dev - SK_G16 device structure * Return Value   : None * Errors         : None * Globals        : None * Update History : *     YY/MM/DD  uid  Description-*/void __init SK_print_ram(struct net_device *dev){    int i;        struct priv *p = (struct priv *) dev->priv;    printk("## %s: RAM Details.\n"           "##   RAM at %#08x tmdhead: %#08x rmdhead: %#08x initblock: %#08x\n",           SK_NAME,            (unsigned int) p->ram,           (unsigned int) p->tmdhead,            (unsigned int) p->rmdhead,            (unsigned int) &(p->ram)->ib);               printk("##   ");    for(i = 0; i < TMDNUM; i++)    {           if (!(i % 3)) /* Every third line do a newline */           {               printk("\n##   ");           }        printk("tmdbufs%d: %#08x ", (i+1), (int) p->tmdbufs[i]);    }    printk("##   ");    for(i = 0; i < RMDNUM; i++)    {         if (!(i % 3)) /* Every third line do a newline */           {               printk("\n##   ");           }        printk("rmdbufs%d: %#08x ", (i+1), (int) p->rmdbufs[i]);    }     printk("\n");} /* End of SK_print_ram() */

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -