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

📄 rcpci45.c

📁 Linux内核源代码 为压缩文件 是<<Linux内核>>一书中的源代码
💻 C
📖 第 1 页 / 共 3 页
字号:
/* ****  RCpci45.c  ********  ---------------------------------------------------------------------**  ---     Copyright (c) 1998, 1999, RedCreek Communications Inc.    ---**  ---                   All rights reserved.                        ---**  ---------------------------------------------------------------------**** Written by Pete Popov and Brian Moyle.**** Known Problems** ** None known at this time.****  TODO:**      -Get rid of the wait loops in the API and replace them**       with system independent delays ...something like**       "delayms(2)".  However, under normal circumstances, the **       delays are very short so they're not a problem.****  This program is free software; you can redistribute it and/or modify**  it under the terms of the GNU General Public License as published by**  the Free Software Foundation; either version 2 of the License, or**  (at your option) any later version.**  This program is distributed in the hope that it will be useful,**  but WITHOUT ANY WARRANTY; without even the implied warranty of**  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the**  GNU General Public License for more details.**  You should have received a copy of the GNU General Public License**  along with this program; if not, write to the Free Software**  Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.****   **  Rasmus Andersen, December 2000: Converted to new PCI API.****  Pete Popov, January 11,99: Fixed a couple of 2.1.x problems **  (virt_to_bus() not called), tested it under 2.2pre5 (as a module), and **  added a #define(s) to enable the use of the same file for both, the 2.0.x **  kernels as well as the 2.1.x.****  Ported to 2.1.x by Alan Cox 1998/12/9. ****  Sometime in mid 1998, written by Pete Popov and Brian Moyle.*****************************************************************************/#include <linux/module.h>#include <linux/kernel.h>#include <linux/sched.h>#include <linux/string.h>#include <linux/ptrace.h>#include <linux/errno.h>#include <linux/in.h>#include <linux/init.h>#include <linux/ioport.h>#include <linux/malloc.h>#include <linux/interrupt.h>#include <linux/pci.h>#include <linux/timer.h>#include <asm/irq.h>            /* For NR_IRQS only. */#include <asm/bitops.h>#include <asm/io.h>#include <asm/uaccess.h>#include <linux/if_ether.h>#include <linux/netdevice.h>#include <linux/etherdevice.h>#include <linux/skbuff.h>static char version[] __initdata ="RedCreek Communications PCI linux driver version 2.03\n";#define RC_LINUX_MODULE#include "rclanmtl.h"#include "rcif.h"#define RUN_AT(x) (jiffies + (x))#define NEW_MULTICAST#include <linux/delay.h>/* PCI/45 Configuration space values */#define RC_PCI45_VENDOR_ID  0x4916#define RC_PCI45_DEVICE_ID  0x1960#define MAX_ETHER_SIZE        1520  #define MAX_NMBR_RCV_BUFFERS    96#define RC_POSTED_BUFFERS_LOW_MARK MAX_NMBR_RCV_BUFFERS-16#define BD_SIZE 3           /* Bucket Descriptor size */#define BD_LEN_OFFSET 2     /* Bucket Descriptor offset to length field *//* RedCreek LAN device Target ID */#define RC_LAN_TARGET_ID  0x10 /* RedCreek's OSM default LAN receive Initiator */#define DEFAULT_RECV_INIT_CONTEXT  0xA17  static U32 DriverControlWord =  0;static void rc_timer(unsigned long);/* * Driver Private Area, DPA. */typedef struct{    /*      *    pointer to the device structure which is part     * of the interface to the Linux kernel.     */    struct net_device *dev;                     U8     id;                        /* the AdapterID */    U32    pci_addr;               /* the pci address of the adapter */    U32    bus;    U32    function;    struct timer_list timer;        /*  timer */    struct net_device_stats  stats; /* the statistics structure */    unsigned long numOutRcvBuffers;/* number of outstanding receive buffers*/    unsigned char shutdown;    unsigned char reboot;    unsigned char nexus;    PU8    PLanApiPA;             /* Pointer to Lan Api Private Area */}DPA, *PDPA;#define MAX_ADAPTERS 32static PDPA  PCIAdapters[MAX_ADAPTERS];static int RCinit(struct net_device *dev);static int RCopen(struct net_device *);static int RC_xmit_packet(struct sk_buff *, struct net_device *);static void RCinterrupt(int, void *, struct pt_regs *);static int RCclose(struct net_device *dev);static struct net_device_stats *RCget_stats(struct net_device *);static int RCioctl(struct net_device *, struct ifreq *, int);static int RCconfig(struct net_device *, struct ifmap *);static void RCxmit_callback(U32, U16, PU32, U16);static void RCrecv_callback(U32, U8, U32, PU32, U16);static void RCreset_callback(U32, U32, U32, U16);static void RCreboot_callback(U32, U32, U32, U16);static int RC_allocate_and_post_buffers(struct net_device *, int);static struct pci_device_id rcpci45_pci_table[] __devinitdata = {	{ RC_PCI45_VENDOR_ID, RC_PCI45_DEVICE_ID, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0},	{0, }};MODULE_DEVICE_TABLE(pci, rcpci45_pci_table);static void rcpci45_remove_one(struct pci_dev *pdev){	struct net_device *dev = pdev->driver_data;	PDPA pDpa = dev->priv;        if (!dev) {                printk (KERN_ERR "remove non-existent device\n");                return;        }	printk("IOP reset: 0x%x\n", RCResetIOP(pDpa->id));	unregister_netdev(dev);	iounmap((void *)dev->base_addr);        free_irq(dev->irq, dev);	kfree(dev);}static int RCinit(struct net_device *dev){    dev->open = &RCopen;    dev->hard_start_xmit = &RC_xmit_packet;    dev->stop = &RCclose;    dev->get_stats = &RCget_stats;    dev->do_ioctl = &RCioctl;    dev->set_config = &RCconfig;    return 0;}static int rcpci45_init_one(struct pci_dev *pdev, 			    const struct pci_device_id *ent){    int dev_size = 32768;            unsigned long *vaddr=0;    PDPA pDpa;    int init_status;    long memaddr = pci_resource_start(pdev, 0);    int card_idx;        struct net_device *dev;    static int card_counter = 0;    card_idx = card_counter++; /* Yeah, icky hack. */    /*      * Allocate and fill new device structure.      * We need enough for struct net_device plus DPA plus the LAN API private     * area, which requires a minimum of 16KB.  The top of the allocated     * area will be assigned to struct net_device; the next chunk will be     * assigned to DPA; and finally, the rest will be assigned to the     * the LAN API layer.     */    dev = (struct net_device *) kmalloc(dev_size, GFP_DMA | GFP_KERNEL |GFP_ATOMIC);    if (!dev)    {        printk("rcpci45 driver: unable to kmalloc dev struct\n");        return 1;       }    memset(dev, 0, dev_size);    pdev->driver_data = dev;    /*     * dev->priv will point to the start of DPA.     */    dev->priv = (void *)(((long)dev + sizeof(struct net_device) + 15) & ~15);#ifdef RCDEBUG    printk("rc: dev = 0x%x, dev->priv = 0x%x\n", (uint)dev, (uint)dev->priv);#endif        pDpa = dev->priv;    pDpa->dev = dev;            /* this is just for easy reference */    pDpa->function = pdev->devfn;    pDpa->bus = (unsigned char)pdev->bus->number;    pDpa->id = card_idx;        /* the device number */    pDpa->pci_addr = memaddr;    PCIAdapters[card_idx] = pDpa;#ifdef RCDEBUG    printk("rc: pDpa = 0x%x, id = %d \n", (uint)pDpa, (uint)pDpa->id);#endif    /*     * Save the starting address of the LAN API private area.  We'll     * pass that to RCInitI2OMsgLayer().     */    pDpa->PLanApiPA = (void *)(((long)pDpa + sizeof(DPA) + 0xff) & ~0xff);#ifdef RCDEBUG    printk("rc: pDpa->PLanApiPA = 0x%x\n", (uint)pDpa->PLanApiPA);#endif        /* The adapter is accessable through memory-access read/write, not     * I/O read/write.  Thus, we need to map it to some virtual address     * area in order to access the registers are normal memory.     */    vaddr = (ulong *) ioremap (memaddr, 2*32768);#ifdef RCDEBUG    printk("rc: RCfound_device: 0x%x, priv = 0x%x, vaddr = 0x%x\n",            (uint)dev, (uint)dev->priv, (uint)vaddr);#endif    dev->base_addr = (unsigned long)vaddr;    dev->irq = pdev->irq;    /*     * Request a shared interrupt line.     */    if ( request_irq(dev->irq, (void *)RCinterrupt,                     SA_INTERRUPT|SA_SHIRQ, "RedCreek VPN Adapter", dev) )    {        printk( "RC PCI 45: %s: unable to get IRQ %d\n", (PU8)dev->name, (uint)dev->irq );        iounmap(vaddr);        kfree(dev);        return 1;    }    init_status = RCInitI2OMsgLayer(pDpa->id, dev->base_addr,                   pDpa->PLanApiPA, (PU8)virt_to_bus((void *)pDpa->PLanApiPA),                  (PFNTXCALLBACK)RCxmit_callback,                  (PFNRXCALLBACK)RCrecv_callback,                  (PFNCALLBACK)RCreboot_callback);    if (init_status)    {        printk("rc: Unable to initialize msg layer\n");        free_irq(dev->irq, dev);        iounmap(vaddr);        kfree(dev);        return 1;    }    if (RCGetMAC(pDpa->id, dev->dev_addr, NULL))    {        printk("rc: Unable to get adapter MAC\n");        free_irq(dev->irq, dev);        iounmap(vaddr);        kfree(dev);        return 1;    }    DriverControlWord |= WARM_REBOOT_CAPABLE;    RCReportDriverCapability(pDpa->id, DriverControlWord);    dev->init = &RCinit;    ether_setup(dev);            /* linux kernel interface */    if (register_netdev(dev) != 0) /* linux kernel interface */    {        printk("rc: unable to register device \n");        free_irq(dev->irq, dev);        iounmap(vaddr);        kfree(dev);        return 1;    }    printk("%s: RedCreek Communications IPSEC VPN adapter\n",        dev->name);    return 0; /* success */}static struct pci_driver rcpci45_driver = {	name: "rcpci45",	id_table: rcpci45_pci_table,	probe: rcpci45_init_one,	remove: rcpci45_remove_one,};static int __init rcpci_init_module (void){	int rc = pci_module_init(&rcpci45_driver);	if (!rc)		printk(version);	return rc;}static intRCopen(struct net_device *dev){    int post_buffers = MAX_NMBR_RCV_BUFFERS;    PDPA pDpa = (PDPA) dev->priv;    int count = 0;    int requested = 0;#ifdef RCDEBUG    printk("rc: RCopen\n");#endif    RCEnableI2OInterrupts(pDpa->id);    if (pDpa->nexus)    {        /* This is not the first time RCopen is called.  Thus,         * the interface was previously opened and later closed         * by RCclose().  RCclose() does a Shutdown; to wake up         * the adapter, a reset is mandatory before we can post         * receive buffers.  However, if the adapter initiated          * a reboot while the interface was closed -- and interrupts         * were turned off -- we need will need to reinitialize         * the adapter, rather than simply waking it up.           */        printk("rc: Waking up adapter...\n");        RCResetLANCard(pDpa->id,0,0,0);    }    else    {        pDpa->nexus = 1;    }    while(post_buffers)    {        if (post_buffers > MAX_NMBR_POST_BUFFERS_PER_MSG)            requested = MAX_NMBR_POST_BUFFERS_PER_MSG;        else            requested = post_buffers;        count = RC_allocate_and_post_buffers(dev, requested);        if ( count < requested )        {            /*             * Check to see if we were able to post any buffers at all.             */            if (post_buffers == MAX_NMBR_RCV_BUFFERS)            {                printk("rc: Error RCopen: not able to allocate any buffers\r\n");                return(-ENOMEM);                                }            printk("rc: Warning RCopen: not able to allocate all requested buffers\r\n");            break;            /* we'll try to post more buffers later */        }        else            post_buffers -= count;    }    pDpa->numOutRcvBuffers = MAX_NMBR_RCV_BUFFERS - post_buffers;    pDpa->shutdown = 0;        /* just in case */#ifdef RCDEBUG    printk("rc: RCopen: posted %d buffers\n", (uint)pDpa->numOutRcvBuffers);#endif    MOD_INC_USE_COUNT;    netif_start_queue(dev);    return 0;}static intRC_xmit_packet(struct sk_buff *skb, struct net_device *dev){    PDPA pDpa = (PDPA) dev->priv;    singleTCB tcb;    psingleTCB ptcb = &tcb;    RC_RETURN status = 0;       netif_stop_queue(dev);         if (pDpa->shutdown || pDpa->reboot)    {#ifdef RCDEBUG            printk("rc: RC_xmit_packet: tbusy!\n");#endif            return 1;    }

⌨️ 快捷键说明

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