Sponsored Content
Top Forums Programming Compiling virtual network adapter driver problem (net_device struct) Post 302465780 by Chrisdot on Sunday 24th of October 2010 08:06:28 AM
Old 10-24-2010
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 created Makefile too with: obj-m = networkAdapter.o content in /usr/src/myModules directory.
I try to compile with:
Code:
make -C /usr/src/linux-headers-2.6.31-14-generic/ M=$(pwd) modules

Code:
cc -I /usr/src/linux-headers-2.6.31-14-generic/include/ -c networkAdapter.c

being in /usr/src/myModules directory.

Make -c ... output contains 3 errors:
Code:
'struct net_device' has no member named 'open'
'struct net_device' has no member named 'stop'
'struct net_device' has no member named 'hard_start_xmit'

cc -I ... output is very long and contains lots of errors.

Could you give me some hints how to compile it?

Regards.


Code:
#define MODULE             
    #define __KERNEL__     
    
    #include < linux/module.h >  
    #include < linux/config.h >  

     #include < linux/netdevice.h > 
    
    int rtl8139_open (struct net_device *dev)
    {
        printk("rtl8139_open called\n");
        netif_start_queue (dev);
        return 0;
    }

    int rtl8139_release (struct net_device *dev)
    {
        printk ("rtl8139_release called\n");
        netif_stop_queue(dev);
        return 0;
    }

    static int rtl8139_xmit (struct sk_buff *skb, 
                    struct net_device *dev)
    {
        printk ("dummy xmit function called....\n");
        dev_kfree_skb(skb);
        return 0;
    }

    int rtl8139_init (struct net_device *dev)
    {
        dev->open = rtl8139_open;
        dev->stop = rtl8139_release;
        dev->hard_start_xmit = rtl8139_xmit;
        printk ("8139 device initialized\n");
        return 0;
    }

    struct net_device rtl8139 = {init: rtl8139_init};

    int rtl8139_init_module (void)
    {
        int result;

        strcpy (rtl8139.name, "rtl8139");
        if ((result = register_netdev (&rtl8139))) {
            printk ("rtl8139: Error %d  initializing card rtl8139 card",result);
            return result;
        }
    return 0;
    }
    
     void rtl8139_cleanup (void)
    {
        printk ("<0> Cleaning Up the Module\n");
        unregister_netdev (&rtl8139);
        return;
    }
    
    module_init (rtl8139_init_module);
    module_exit (rtl8139_cleanup);

 

10 More Discussions You Might Find Interesting

1. Programming

freeBSD device driver (use struct uio)

Hi, everybody I have next problem... 1) My Example program code void main() { int fd; int len; int buf; fd=open("mydev", O_RDONLY); lseek(fd, 0, SEEK_SET); len=read(fd, buf, sizeof(buf)); } 2) My Example Driver code static int mydev_read(dev_t dev, ?, ?, struct uio* uio) {... (0 Replies)
Discussion started by: Alex_T
0 Replies

2. AIX

Power6 Virtual Fibre Channel Adapter

Hello, Searched in all IBM Redbooks and on the internet and couldn't find anything about the new feature of POWER 6 which Virtual Fibre ( Fiber ) channel adapter. It is similar to virtual scsi adapter. In my client partition I created the virtual Fibre Adapter mapped it with the VIO... (1 Reply)
Discussion started by: filosophizer
1 Replies

3. AIX

How to active this network adapter?

When I configure two VIO Servers, VIOS1 used to ping its gateway, after I configured second VIOS2, VIOS1 cannpt ping its gateway, when I run this command: entstat -all ent#|grep -i priority Priority: 5 Active: False How to make Active to True? (1 Reply)
Discussion started by: rainbow_bean
1 Replies

4. 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

5. AIX

Setting up an Integrated Virtual Ethernet adapter

All I am trying allocate an IVE to an LPAR (not a VIO) running AIX 7.1. I am getting the error: HSCL068A Explanation Logical port can not be assigned to Logical Partition because this Logical Partition is not the promiscuous LPAR for the physical port. Has anyone encountered this... (1 Reply)
Discussion started by: johnf
1 Replies

6. Programming

Storing C++-struct in file - problem when adding new item in struct

Hi, I have received an application that stores some properties in a file. The existing struct looks like this: struct TData { UINT uSizeIncludingStrings; // copy of Telnet data struct UINT uSize; // basic properties: TCHAR szHost; //defined in Sshconfig UINT iPortNr; TCHAR... (2 Replies)
Discussion started by: Powerponken
2 Replies

7. AIX

Adding Virtual Adapter to LPAR

Hello, hopefully someone can help me out with this, I have created a virtual Ethernet adapter on the VIO but would like to add it to my new LPAR. On my VIO only my disk is mapped. $ lsmap -all SVSA Physloc Client Partition ID --------------- --------------------------------------------... (5 Replies)
Discussion started by: audis$
5 Replies

8. IP Networking

Virtual Adapter MAC address..

Hi, I just want to know whether two MAC address can exist in a adapter.. I mean one there will be mandatory one And another as user defined one.. Any replies will be more helpful.. Please help.. :wall: (0 Replies)
Discussion started by: Priya Amaresh
0 Replies

9. Hardware

Need Sun 10-Gigabit Ethernet Adapter CD or ixge driver

Hi, Does anybody have a "Sun 10-Gigabit Ethernet Adapter installation CD" or driver ixge for Sun 10-Gigabit Ethernet PCI-X adapter? I need it but can't find it anywhere. So if you know where I can download it or purchase it, please let me know. (Already tried Oracle's website, don't have it) ... (5 Replies)
Discussion started by: Lhao
5 Replies

10. Solaris

Attach Solaris 11.1 rwn driver to RaLink RT8200/8260 Wi Fi Adapter

I installed Solaris 11.1 on a X86 PC. It's working except for one glaring problem : I cannot get a driver attached to the RaLink RT2800 (Wi Fi Adapter). Can someone point me in the direction where " the correct" driver exists, or let me know how I can tell Solaris to attach the device to the... (1 Reply)
Discussion started by: JWH
1 Replies
STRUCT 
WIMAX_DEV(9) Linux Networking STRUCT WIMAX_DEV(9) NAME
struct_wimax_dev - Generic WiMAX device SYNOPSIS
struct wimax_dev { struct net_device * net_dev; struct list_head id_table_node; struct mutex mutex; struct mutex mutex_reset; enum wimax_st state; int (* op_msg_from_user) (struct wimax_dev *wimax_dev,const char *,const void *, size_t,const struct genl_info *info); int (* op_rfkill_sw_toggle) (struct wimax_dev *wimax_dev,enum wimax_rf_state); int (* op_reset) (struct wimax_dev *wimax_dev); struct rfkill * rfkill; unsigned int rf_hw; unsigned int rf_sw; char name[32]; struct dentry * debugfs_dentry; }; MEMBERS
net_dev [fill] Pointer to the struct net_device this WiMAX device implements. id_table_node [private] link to the list of wimax devices kept by id-table.c. Protected by it's own spinlock. mutex [private] Serializes all concurrent access and execution of operations. mutex_reset [private] Serializes reset operations. Needs to be a different mutex because as part of the reset operation, the driver has to call back into the stack to do things such as state change, that require wimax_dev->mutex. state [private] Current state of the WiMAX device. op_msg_from_user [fill] Driver-specific operation to handle a raw message from user space to the driver. The driver can send messages to user space using with wimax_msg_to_user. op_rfkill_sw_toggle [fill] Driver-specific operation to act on userspace (or any other agent) requesting the WiMAX device to change the RF Kill software switch (WIMAX_RF_ON or WIMAX_RF_OFF). If such hardware support is not present, it is assumed the radio cannot be switched off and it is always on (and the stack will error out when trying to switch it off). In such case, this function pointer can be left as NULL. op_reset [fill] Driver specific operation to reset the device. This operation should always attempt first a warm reset that does not disconnect the device from the bus and return 0. If that fails, it should resort to some sort of cold or bus reset (even if it implies a bus disconnection and device disappearance). In that case, -ENODEV should be returned to indicate the device is gone. This operation has to be synchronous, and return only when the reset is complete. In case of having had to resort to bus/cold reset implying a device disconnection, the call is allowed to return inmediately. rfkill [private] integration into the RF-Kill infrastructure. rf_hw [private] State of the hardware radio switch (OFF/ON) rf_sw [private] State of the software radio switch (OFF/ON) name[32] [fill] A way to identify this device. We need to register a name with many subsystems (rfkill, workqueue creation, etc). We can't use the network device name as that might change and in some instances we don't know it yet (until we don't call register_netdev). So we generate an unique one using the driver name and device bus id, place it here and use it across the board. Recommended naming: DRIVERNAME-BUSNAME:BUSID (dev->bus->name, dev->bus_id). debugfs_dentry [private] Used to hook up a debugfs entry. This shows up in the debugfs root as wimax:DEVICENAME. NOTE
wimax_dev->mutex is NOT locked when this op is being called; however, wimax_dev->mutex_reset IS locked to ensure serialization of calls to wimax_reset. See wimax_reset's documentation. DESCRIPTION
This structure defines a common interface to access all WiMAX devices from different vendors and provides a common API as well as a free-form device-specific messaging channel. USAGE
1. Embed a struct wimax_dev at *the beginning* the network device structure so that netdev_priv points to it. 2. memset it to zero 3. Initialize with wimax_dev_init. This will leave the WiMAX device in the __WIMAX_ST_NULL state. 4. Fill all the fields marked with [fill]; once called wimax_dev_add, those fields CANNOT be modified. 5. Call wimax_dev_add *after* registering the network device. This will leave the WiMAX device in the WIMAX_ST_DOWN state. Protect the driver's net_device->open against succeeding if the wimax device state is lower than WIMAX_ST_DOWN. 6. Select when the device is going to be turned on/initialized; for example, it could be initialized on 'ifconfig up' (when the netdev op 'open' is called on the driver). When the device is initialized (at `ifconfig up` time, or right after calling wimax_dev_add from _probe, make sure the following steps are taken a. Move the device to WIMAX_ST_UNINITIALIZED. This is needed so some API calls that shouldn't work until the device is ready can be blocked. b. Initialize the device. Make sure to turn the SW radio switch off and move the device to state WIMAX_ST_RADIO_OFF when done. When just initialized, a device should be left in RADIO OFF state until user space devices to turn it on. c. Query the device for the state of the hardware rfkill switch and call wimax_rfkill_report_hw and wimax_rfkill_report_sw as needed. See below. wimax_dev_rm undoes before unregistering the network device. Once wimax_dev_add is called, the driver can get called on the wimax_dev->op_* function pointers CONCURRENCY
The stack provides a mutex for each device that will disallow API calls happening concurrently; thus, op calls into the driver through the wimax_dev->op*() function pointers will always be serialized and *never* concurrent. For locking, take wimax_dev->mutex is taken; (most) operations in the API have to check for wimax_dev_is_ready to return 0 before continuing (this is done internally). REFERENCE COUNTING
The WiMAX device is reference counted by the associated network device. The only operation that can be used to reference the device is wimax_dev_get_by_genl_info, and the reference it acquires has to be released with dev_put(wimax_dev->net_dev). RFKILL
At startup, both HW and SW radio switchess are assumed to be off. At initialization time [after calling wimax_dev_add], have the driver query the device for the status of the software and hardware RF kill switches and call wimax_report_rfkill_hw and wimax_rfkill_report_sw to indicate their state. If any is missing, just call it to indicate it is ON (radio always on). Whenever the driver detects a change in the state of the RF kill switches, it should call wimax_report_rfkill_hw or wimax_report_rfkill_sw to report it to the stack. COPYRIGHT
Kernel Hackers Manual 3.10 June 2014 STRUCT WIMAX_DEV(9)
All times are GMT -4. The time now is 11:29 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy