mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* Basic idea to write a net pci device driver
@ 2003-10-14  2:01 Breno
  0 siblings, 0 replies; only message in thread
From: Breno @ 2003-10-14  2:01 UTC (permalink / raw)
  To: Kernel List

[-- Attachment #1: Type: text/plain, Size: 186 bytes --]

Hi,

I am studing how to write a net pci device driver. I´d like some help with
my code. I know that it´s need much more code , but i´d like to know if i am
in right way.

thanks

Breno

[-- Attachment #2: ethercard.c --]
[-- Type: application/octet-stream, Size: 2219 bytes --]

#include <linux/module.h>
#include <linux/kernel.h>
#include <linux/sched.h>
#include <linux/errno.h>
#include <linux/pci.h>
#include <linux/init.h>
#include <linux/ethtool.h>
#include <asm/system.h>
#include <asm/io.h>
#include <asm/irq.h>
#include <asm/uaccess.h>
#include <linux/netdevice.h>
#include <linux/etherdevice.h>
#include "8390.h"

#define ETHERNAME "ethercard"

static struct pci_device_id ethercard_id_table[] __devinitdata = {
    {0x10ec, 0x8029, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0},
};

static int ethercard_open(struct net_device *dev)
{
    /*need code*/
    return 0;
}

static int ethercard_stop(struct net_device *dev)
{
    free_irq(dev->irq,dev);
    return 0;
}

/* here some functions for packets */

static int __devinit ethercard_probe(struct pci_dev *c_dev, const struct pci_device_id *idp)
{
    int card,irq;
    struct net_device *dev;
    unsigned long ioaddr,rflag;
    
    card = pci_enable_device(c_dev);
    
    if(card)
    {
	printk(KERN_CRIT"PCI Driver found\n");
	return card;
    }
    
    ioaddr = pci_resource_start(c_dev,0);
    
    irq = c_dev->irq;
    
    rflag = pci_resource_flags(c_dev,0);
    
    if(!ioaddr || ((rflag & IORESOURCE_IO) == 0))
    return -1;
    
    if((request_region(ioaddr,0x30,ETHERNAME) == NULL))
    return -1;
    
    dev = alloc_etherdev(0);
    
    if(!dev)
    return -1;
    
    c_dev->driver_data = dev;
    
    dev->irq = irq;
    dev->base_addr = ioaddr;
    dev->open = &ethercard_open;
    dev->stop = &ethercard_stop;
    
    return 0;
}

static void __devexit ethercard_remove(struct pci_dev *c_dev)
{
}    

static struct pci_driver pci_struct = {
    name:	ETHERNAME,
    probe:	ethercard_probe,
    remove:	__devexit_p(ethercard_remove),
    id_table:	ethercard_id_table,
};

static int __init ethercard_init(void)
{
    printk(KERN_CRIT"Loading ether driver\n");
    
    return pci_module_init(&pci_struct);
}

static void __exit ethercard_exit(void)
{
    printk(KERN_CRIT"Unloading ether driver\n");
    
    return pci_unregister_driver(&pci_struct);
}

module_init(ethercard_init)
module_exit(ethercard_exit)    

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2003-10-14  2:02 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2003-10-14  2:01 Basic idea to write a net pci device driver Breno

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®