mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: "Breno" <brenosp@brasilsec.com.br>
To: "Kernel List" <linux-kernel@vger.kernel.org>
Subject: Basic idea to write a net pci device driver
Date: Mon, 13 Oct 2003 23:01:52 -0300	[thread overview]
Message-ID: <001201c391f7$23c887c0$06dfa7c8@bsb.virtua.com.br> (raw)

[-- 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)    

                 reply	other threads:[~2003-10-14  2:02 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to='001201c391f7$23c887c0$06dfa7c8@bsb.virtua.com.br' \
    --to=brenosp@brasilsec.com.br \
    --cc=linux-kernel@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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®