Hi,

 Thanks for the response. lsmod shows other drivers

lsmod | grep 8139
8139cp                 21504  0
8139too                24708  0
mii                     8192  3 8139cp,8139too,via_rhine

I do a:
rmmod 8139too
rmmod 8139cp

then I do a :
insmod real3.ko

Then it crashes with:
dmesg | tail -50
Device enabled
----------------------------------------------------------------
Base 0  Starting Address = 9c00 End Address = 9cff  Length = 256
This Port is I/O mapped. It is NON Prefetchable.This is readable and writable.
Base 1  Starting Address = fdaff000 End Address = fdaff0ff  Length = 256
This Port is Memory mapped. It is NON Prefetchable. This is readable and 
writable.
Reading the PCI BAR registers
Checking the PCI BAR registers for Memory mapped flag
region is Memory mapped region
Calling pci_request_region
Calling pci_set_master
Calling ioremap
Assigning ioaddress and length
Assigning hardware address
Assigning function address
Calling register_netdev
rtl8139_get_stats is called
BUG: unable to handle kernel NULL pointer dereference at 00000000
IP: [<c06379ef>] rtnl_fill_ifinfo+0x2cf/0x48f
*pde = 3b7a7067
Oops: 0000 [#1] SMP
Modules linked in: real3(P+) fuse via drm nfsd lockd nfs_acl auth_rpcgss 
exportfs sco bridge stp bnep l2cap bluetooth sunrpc ip6t_REJECT 
nf_conntrack_ipv6 ip6table_filter ip6_tables ipv6 dm_multipath uinput ppdev 
snd_hda_intel snd_seq_dummy snd_seq_oss snd_seq_midi_event snd_seq 
snd_seq_device snd_pcm_oss snd_mixer_oss snd_pcm snd_timer snd_page_alloc 
snd_hwdep snd floppy i2c_viapro i2c_core pcspkr soundcore via_rhine mii 
sata_via parport_pc parport ata_generic pata_acpi pata_via [last unloaded: 
8139cp]

Pid: 3514, comm: insmod Tainted: P          (2.6.27.5-117.fc10.i686 #1)
EIP: 0060:[<c06379ef>] EFLAGS: 00210246 CPU: 0
EIP is at rtnl_fill_ifinfo+0x2cf/0x48f
EAX: 00000000 EBX: e46ad090 ECX: 00000000 EDX: e46ad094
ESI: ec90e960 EDI: e462e700 EBP: e46dee9c ESP: e46dee5c
 DS: 007b ES: 007b FS: 00d8 GS: 0033 SS: 0068
Process insmod (pid: 3514, ti=e46de000 task=e46e3340 task.ti=e46de000)
Stack: c000993b ec90e800 e46ad000 e462e700 e46dee8c 00000000 00000000 00000000
       00000000 f882a000 00000000 00000010 000005dc ec90e800 e462e700 ffffffff
       e46deec4 c0637e48 00000000 00000000 ffffffff 00000000 00000010 c07ee154
Call Trace:
 [<c0637e48>] ? rtmsg_ifinfo+0x45/0xaf
 [<c0637eea>] ? rtnetlink_event+0x38/0x3c
 [<c06a9718>] ? notifier_call_chain+0x2b/0x4a
 [<c0440573>] ? raw_notifier_call_chain+0xc/0xe
 [<c0631f4b>] ? register_netdevice+0x30b/0x345
 [<c0631fb7>] ? register_netdev+0x32/0x3f
 [<f886d432>] ? init_module+0x23b/0x2a9 [real3]
 [<c0401125>] ? _stext+0x3d/0x115
 [<f886d1f7>] ? init_module+0x0/0x2a9 [real3]
 [<c044bf7d>] ? sys_init_module+0x87/0x178
 [<c0403c76>] ? syscall_call+0x7/0xb
 [<c06a007b>] ? init_intel_cacheinfo+0x0/0x421
 =======================
Code: c0 0f 88 c4 01 00 00 b9 5c 00 00 00 ba 07 00 00 00 89 f8 e8 0c dd 00 00 
85 c0 89 c3 0f 84 a9 01 00 00 8b 45 c4 ff 50 50 8d 53 04 <8b> 08 89 4b 04 8b 48 
04 89 4a 04 8b 48 08 89 4a 08 8b 48 0c 89
EIP: [<c06379ef>] rtnl_fill_ifinfo+0x2cf/0x48f SS:ESP 0068:e46dee5c
---[ end trace ef10416be49ddab2 ]---

Thanks & Regards,
D.Giriprasad



Hi,

--- On Fri, Sep 9, 2011 at 12:07 PM, Giriprasad Deviprasad
<g_p...@yahoo.in> wrote:
| Calling pci_request_region
| 8139too 0000:04:03.0: BAR 0: can't reserve I/O region [0x9c00-0x9cff]
| Could not get PCI region
\--

As it says, this region is not available for your driver. Do you have
8139too driver loaded already? Check output of:

  $ lsmod | grep 8139

SK


#define REALTEK_VENDER_ID  0x10EC
#define REALTEK_DEVICE_ID   0x8139

//#define REALTEK_VENDER_ID 0x10b5 
//#define REALTEK_DEVICE_ID  0x9050 

//#define VENDOR_ID 0x10b5
//#define DEVICE_ID 0x9050

#include <linux/kernel.h>
#include <linux/module.h>
#include <linux/stddef.h>
#include <linux/pci.h>
#include <linux/etherdevice.h>

int print_pci(struct pci_dev *pdev);

struct rtl8139_private 
{
        struct pci_dev *pci_dev;  /* PCI device */
        void *mmio_addr; /* memory mapped I/O addr */
        unsigned long regs_len; /* length of I/O or MMI/O region */
};


static struct pci_dev* probe_for_realtek8139(void) 
{
        struct pci_dev *pdev = NULL;
        /* Ensure we are not working on a non-PCI system */
        //if(!pci_present( )) {
        //       printk("<1>pci not present\n");
        //       return pdev;
        //}
        //else
        //        printk("<1>pci device is present\n");

        /* Look for RealTek 8139 NIC */
        pdev = pci_find_device(REALTEK_VENDER_ID, REALTEK_DEVICE_ID, NULL);
        if(pdev) {
               printk("Found PCI device with vendorid = %x deviceid = %x\n", 
REALTEK_VENDER_ID, REALTEK_DEVICE_ID);
               /* device found, enable it */
               if(pci_enable_device(pdev)) {
                        printk("Could not enable the device\n");
                       return NULL;
               }
               else
                        printk("Device enabled\n");
        }
        else {
                printk("device not found\n");
               return pdev;
        }
        return pdev;
}


#define DRIVER "rtl8139"
static struct net_device *rtl8139_dev;

static int rtl8139_init(struct pci_dev *pdev, struct net_device **dev_out) 
{
        struct net_device *dev;
        struct rtl8139_private *tp;

        /* 
         * alloc_etherdev allocates memory for dev and dev->priv.
         * dev->priv shall have sizeof(struct rtl8139_private) memory
         * allocated.
         */
        dev = alloc_etherdev(sizeof(struct rtl8139_private));
        if(!dev) {
                printk("Could not allocate etherdev\n");
               return -1;
        }

        tp = dev->priv;
        tp->pci_dev = pdev;
        *dev_out = dev;

        return 0;
}

static int rtl8139_open(struct net_device *dev) 
{  
   printk("rtl8139_open is called\n"); 
   return 0; 
}

static int rtl8139_stop(struct net_device *dev) 
{
         printk("rtl8139_open is called\n");
        return 0;
}

static int rtl8139_start_xmit(struct sk_buff *skb, struct net_device *dev) 
{
         printk("rtl8139_start_xmit is called\n");
        return 0;
}

static struct net_device_stats* rtl8139_get_stats(struct net_device *dev) 
{
         printk("rtl8139_get_stats is called\n");
        return 0;
}

int init_module(void) 
{
        struct pci_dev *pdev;
        unsigned long mmio_start, mmio_end, mmio_len, mmio_flags;
        void *ioaddr;
        struct rtl8139_private *tp;
        int i, err = 0;

        pdev = probe_for_realtek8139( );
        if(!pdev)
               return 0;

        print_pci(pdev);
        if(rtl8139_init(pdev, &rtl8139_dev)) {
                printk("Could not initialize device\n");
               return 0;
        }

        tp = rtl8139_dev->priv; // rtl8139 private information 
        
        printk("Reading the PCI BAR registers \n");
        // get PCI memory mapped I/O space base address from BAR1 
        mmio_start = pci_resource_start(pdev, 1);
        mmio_end = pci_resource_end(pdev, 1);
        mmio_len = pci_resource_len(pdev, 1);
        mmio_flags = pci_resource_flags(pdev, 1);

        printk("Checking the PCI BAR registers for Memory mapped flag \n");
        // make sure above region is MMI/O 
        if(!(mmio_flags & IORESOURCE_MEM)) {
                printk("region not MMI/O region\n");
               goto cleanup1;
        }
        else
                printk("region is Memory mapped region\n");
        
        printk("Calling pci_request_region \n");
        // get PCI memory space 
        if(pci_request_regions(pdev, DRIVER)) {
                printk("Could not get PCI region\n");
               goto cleanup1;
        }

        printk("Calling pci_set_master\n");
        pci_set_master(pdev);

        printk("Calling ioremap\n");
        // ioremap MMI/O region 
        ioaddr = ioremap(mmio_start, mmio_len);
        if(!ioaddr) {
                printk("Could not ioremap\n");
               goto cleanup2;
        }

        printk("Assigning ioaddress and length \n");
        rtl8139_dev->base_addr = (long)ioaddr;
        tp->mmio_addr = ioaddr;
        tp->regs_len = mmio_len;

        // UPDATE NET_DEVICE 

        printk("Assigning hardware address \n");
        for(i = 0; i < 6; i++) {  // Hardware Address 
               rtl8139_dev->dev_addr[i] = readb(rtl8139_dev->base_addr+i);
               rtl8139_dev->broadcast[i] = 0xff;
        }
        rtl8139_dev->hard_header_len = 14;

        printk("Assigning function address \n");
        memcpy(rtl8139_dev->name, DRIVER, sizeof(DRIVER)); // Device Name 
        rtl8139_dev->irq = pdev->irq;  // Interrupt Number 
        rtl8139_dev->open = rtl8139_open;
        rtl8139_dev->stop = rtl8139_stop;
        rtl8139_dev->hard_start_xmit = rtl8139_start_xmit;
        rtl8139_dev->get_stats = rtl8139_get_stats;

        printk("Calling register_netdev \n");
        // register the device 
        if(register_netdev(rtl8139_dev)) {
                printk("Could not register netdevice\n");
               goto cleanup0;
        }
        goto noerror;

cleanup0:
        printk("Error so, unregister_netdev \n");
        unregister_netdev(rtl8139_dev);
        err = 1;
cleanup2:
        printk("Error so, unmap \n");
        iounmap(tp->mmio_addr);
        err = 1;
cleanup1:
        printk("Error so, pci_release_regions \n");
        pci_release_regions(tp->pci_dev);
        err = 1;

noerror:
        printk("Init function exiting fine ...............\n");
        return err;
}
               


void cleanup_module(void) 
{
        struct rtl8139_private *tp;
        tp = rtl8139_dev->priv;

        iounmap(tp->mmio_addr);
        pci_release_regions(tp->pci_dev);

        unregister_netdev(rtl8139_dev);
        pci_disable_device(tp->pci_dev);
        return;
}




// Should be called after pci_find_device and pci_enable_device have been called

int print_pci(struct pci_dev *dev)
{
        int i;
        int start, end, length, resflags;

        for (i = 0; i < 6; i++)
        {
                start = pci_resource_start (dev, i);
                if (!start)
                        continue;
                end = pci_resource_end (dev, i);
                length = pci_resource_len (dev, i);
                resflags = pci_resource_flags (dev, i);

                if (resflags & IORESOURCE_IO)
                {
                        
printk("----------------------------------------------------------------\n");
                        printk("Base %d  Starting Address = %x End Address = %x 
 Length = %d\n",i, start, end, length);
                        printk ("This Port is I/O mapped. ");
                        if (resflags & IORESOURCE_PREFETCH)
                                printk ("It is Prefetchable.");
                        else
                                printk ("It is NON Prefetchable.");

                        if (resflags & IORESOURCE_READONLY)
                                printk ("This is read only.\n");
                        else
                                printk ("This is readable and writable.\n");

                        if (check_region (start, length) < 0)
                                printk
                                ("Base %d starting Address = %x  End Address = 
%x Length = %d resource is not available \n",
                                        i, start, end, length);
                        //else if (request_region (start, length, DRIVER_NAME) 
< 0)
                //               printk ("The Resource is not allocated for BAR 
%d\n", i);
                //      else
                //              printk ("The Resource is allocated for BAR 
%d\n", i);
                }
                else
                {
                        if (resflags & IORESOURCE_MEM)
                        {
                                printk
                                ("Base %d  Starting Address = %x End Address = 
%x  Length = %d\n",i, start, end, length);
                                printk ("This Port is Memory mapped. ");
                                if (resflags & IORESOURCE_PREFETCH)
                                        printk ("It is Prefetchable. ");
                                else
                                        printk ("It is NON Prefetchable. ");

                                if (resflags & IORESOURCE_READONLY)
                                        printk ("It is read only.\n");
                                else
                                        printk ("This is readable and 
writable.\n");
                                if (check_mem_region (start, length) < 0)
                                 printk
                                 ("Base %d starting Address = %x  End Address = 
%x Length = %d resource is not available \n",
                                        i, start, end, length);
                                else
                                {
                                        //if (request_mem_region (start, 
length, DRIVER_NAME) < 0)
                                        //      printk("The Resource is not 
allocated for BAR %d\n", i);
                                        //else
                                        //      printk ("The Resource is 
allocated for BAR %d\n", i);
                                }
                        }
                }
        }
        

        return 0;
}


_______________________________________________
india mailing list
india@lists.fedoraproject.org
https://admin.fedoraproject.org/mailman/listinfo/india

Reply via email to