The simplest network driver


 
Thread Tools Search this Thread
Top Forums Programming The simplest network driver
# 8  
Old 11-23-2011
I have read "Linux Device Drivers", chapter "Network Drivers", and "PCI Drivers".
Thanks Corona688 for your response.

What if there are in kernel space two drivers supporting the same device id?
.probe function would be run for all of them?
# 9  
Old 11-23-2011
I haven't tried it, but my suspicion is that "probe" would be run for everything. Probing is how you detect non-plug-and-play things which don't advertise their presence, so PCI ID's wouldn't seem to apply.

But PCI drivers, usually not needing to probe, mostly don't probe at all. I think the PCI NE2000 network driver can, but has to be forced to do so by module options at load-time because blindly poking around at I/O addresses can be dangerous. Something unexpected might be occupying the bus resources it expects which could lock the PC or worse. On some IBM laptops, BIOS resources were found at addresses lm_sensors was expecting temperature sensors at, causing probes to brick the system!

One PCI ID for two drivers is a rare situation. Plug-and-play is supposed to be one model to one PCI ID, no ambiguity. If there's two drivers for the same ID, whichever gets loaded first wins. If they're built-in, whichever gets checked first on boot wins. Since the order of built-ins is arbitrary, if you want to control the order, you must make the drivers modules.

A rare situation but it still happens. There's two incompatible revisions of the old realtek 8139 network chip and two different linux kernel drivers -- 8139cp and 8139too. If you load the wrong one, it complains, and tells you to load the other in dmesg. Easy when they're modules, impossible when they're not.

Last edited by Corona688; 11-23-2011 at 12:38 PM..
# 10  
Old 11-23-2011
Quote:
Originally Posted by Corona688
I haven't tried it, but my suspicion is that "probe" would be run for everything. Probing is how you detect non-plug-and-play things which don't advertise their presence, so PCI ID's wouldn't seem to apply.
Setup:
- Intel network card
- e1000e standard linux driver in autorun
- myModule; customized e1000e driver by me for debugging reasons

Steps:
- after power on execute 'rmmod e1000e'
- 'insmod myModule'
From my debuging experience I see, that .probe function is fired always after 'insmod myModule' (when e1000e is not present).

Steps
- after power on do not remove 'e1000e' driver
- 'insmod myModule'
Now .probe function from myModule is not executed. Only init_module function operates.

What if I add myModule to autorun? Will .probe function be then executed? I don't know. I have no idea how to add myModule to autorun. Smilie.

I guess .probe is 'must be', because there are important lines like:

Code:
.probe function:
{
 netdev = alloc_etherdev
 SET_MODULE_OWNER(netdev);
  netdev->netdev_ops        = &e1000e_netdev_ops;
 err = register_netdev(netdev);
}

static const struct net_device_ops e1000e_netdev_ops = {
    .ndo_open        = e1000_open,    // e.g. ifconfig up
    .ndo_stop        = e1000_close,    // e.g. ifconfig down
    .ndo_start_xmit        = e1000_xmit_frame,
    .ndo_get_stats        = e1000_get_stats,
    .ndo_tx_timeout        = e1000_tx_timeout,
    .ndo_validate_addr    = eth_validate_addr,
};


Last edited by Chrisdot; 11-23-2011 at 01:29 PM..
# 11  
Old 11-23-2011
Quote:
Originally Posted by Chrisdot
Setup:
- Intel network card
- e1000e standard linux driver in autorun
- myModule; customized e1000e driver by me for debugging reasons

Steps:
- after power on execute 'rmmod e1000e'
- 'insmod myModule'
From my debuging experience I see, that .probe function is fired always after 'insmod myModule' (when e1000e is not present).

Steps
- after power on do not remove 'e1000e' driver
- 'insmod myModule'
Now .probe function from myModule is not executed. Only init_module function operates.
Your experience trumps my guess. Device ID's trump "probe". If you want to override/ignore PCI IDs, check out the PCI NE2000 driver.
Quote:
What if I add myModule to autorun?
To what?

The kernel doesn't care about which thing calls insmod/modprobe.

If you want to never load the intel one, add the intel one to modules.blacklist
# 12  
Old 11-24-2011
I have checked out PCI NE2000 driver:
LXR / The Linux Cross Reference
Do you mean using 'PCI_ANY_ID' ?
Code:
static DEFINE_PCI_DEVICE_TABLE(ne2k_pci_tbl) = {
        { 0x10ec, 0x8029, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CH_RealTek_RTL_8029 },
        { 0x1050, 0x0940, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CH_Winbond_89C940 },
        { 0x11f6, 0x1401, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CH_Compex_RL2000 },
        { 0x8e2e, 0x3000, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CH_KTI_ET32P2 },
        { 0x4a14, 0x5000, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CH_NetVin_NV5000SC },
        { 0x1106, 0x0926, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CH_Via_86C926 },
        { 0x10bd, 0x0e34, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CH_SureCom_NE34 },
        { 0x1050, 0x5a5a, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CH_Winbond_W89C940F },
        { 0x12c3, 0x0058, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CH_Holtek_HT80232 },
        { 0x12c3, 0x5598, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CH_Holtek_HT80229 },
        { 0x8c4a, 0x1980, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CH_Winbond_89C940_8c4a },
        { 0, }

I tried myModule with 'PCI_ANY_ID'. It is visible in dmesg how myModule run .probe for few devices and failed trying to do 'ioremap' (inside .probe routine). Those are:
Code:
Host bridge: Intel Corporation 440FX - 82441FX PMC [Natoma] (rev 02)
Subsystem: Red Hat, Inc Qemu virtual machine
Flags: fast devsel

ISA bridge: Intel Corporation 82371SB PIIX3 ISA [Natoma/Triton II]
Subsystem: Red Hat, Inc Qemu virtual machine
Flags: medium devsel

Only for my Intel newtork card whole .probe routine went well.

Last edited by Chrisdot; 11-24-2011 at 05:56 AM..
# 13  
Old 11-29-2011
No, I don't. It was an option that had to be forced with insmod/modprobe like I said.

I don't see the right messages in that driver, it may be a different one. I'll look for it.

---------- Post updated at 09:48 AM ---------- Previous update was at 09:44 AM ----------

eepro.c has these lines:

Code:
                printk(KERN_WARNING "eepro_init_module: Probe is very dangerous in ISA boards!\n");
                printk(KERN_WARNING "eepro_init_module: Please add \"autodetect=1\" to force probe\n");

Login or Register to Ask a Question

Previous Thread | Next Thread

8 More Discussions You Might Find Interesting

1. Programming

Compiling virtual network adapter driver problem (net_device struct)

Hi, I found on linuxgazette.net/93/bhaskaran.html page very useful sample of virtual driver (not connected to real hardware). I try to compile it with no effect. So: I got fresh Ubuntu 9.10 (kernel 2.6.31-14) My source is saved in networkAdapter.c file in /usr/src/myModules directory. I... (21 Replies)
Discussion started by: Chrisdot
21 Replies

2. UNIX for Dummies Questions & Answers

Simulated driver for Network Interface Adapter

Hi all, I got sort of a task to do. I have to write in C "simulated network driver". What does it mean? - It has to run on all network adapters - It has to be as simple as it can be - It has to run on all linux distributions (or at least most of them) - It does not have to run a network... (4 Replies)
Discussion started by: Chrisdot
4 Replies

3. Solaris

Can I Install the Gani Network Driver Using the Application that Came on the CD?

When I boot up the Solaris 10 5/09 install CD and select 'Solaris' from the GRUB menu that comes up, a menu loads. Option 5 is 'Apply Driver Updates'. Can I install the Gani driver using that? I tried using the tar file (the way it came) that I wrote to a floppy but when I asked it to look at the... (8 Replies)
Discussion started by: Bradj47
8 Replies

4. Red Hat

How to know whether the network driver alredy installed in my system

I am using NVIDIA nforce: Networking controllers And Redhat enterprice linux ws version 4 32 bit: OS I want to connect my system to Broadband internet using linux. From where can I download the driver for nertwork. How to know whether the network driver alredy installed in my system. ... (0 Replies)
Discussion started by: rijas
0 Replies

5. Solaris

network driver not detecting in solaris 10 X86 on HPDL380G5 Server

I have installed solaris10 x86 on HP DL380 G5 Server, but network card is not getting detected. i have installed the network driver, downloaded from the following link HP ProLiant DL380 G5 Server series- Download drivers and software - HP Business Support Center Can any one suggest me how to... (1 Reply)
Discussion started by: raj.chinnu
1 Replies

6. Solaris

Installing Network on Computer, might be driver

Hi All, Just completing my second Solaris installation, in the previous one which was on a Dell X64 machine, I went through the Network configuration setting, on the current computer which I am installing Solaris on, its a custom built machine and for some reason, I didnt see the screen where I... (1 Reply)
Discussion started by: platforminc
1 Replies

7. Solaris

network driver cpu usage

Hello all, Needed a suggestion from you all, if you know anything about this stuff. We have a high network traffic application. Close to around 700Meg /sec on one NIC. When the traffic is around 200Meg on the NIC, the VCPU(not the CPU, cause we have 24 VCPU) utilization by the NIC driver... (5 Replies)
Discussion started by: Naanu
5 Replies

8. Programming

Network device driver

HI, I am writing a network device driver for RTL8139c card on 2.6.18 kernel ... I am facing few queries listed below 1. Can i able to at all write a driver for RTL8139C or Realtek had designed new chip for 2.6 series kernel? 2. If no then which driver file 2.6.18 uses .. Is it 8139too.c or... (1 Reply)
Discussion started by: niketan
1 Replies
Login or Register to Ask a Question