IOCTL problem for network device

Discussion in 'Linux Networking' started by sara, Dec 27, 2004.

  1. sara

    sara Guest

    Hi all,
    Iam writing PCI device driver for the custom board that is
    registered as network driver "zzz0" using register_netdevice() that
    does bus master DMA data transfer.
    1. In my driver, I could do DMA transfer (filling dma memory in
    the kernel itself) data between pc to board and vice versa by
    programming the memory mapped device DMA register.
    Now what I want is that,I want the user application to fill the
    dma buffer area through IOCTL and to start the transfer.
    Iam not clear with copy_from_user/ copy_to_user with mmap()
    function. I hope using mmap gives high preformance. Let me know how to
    use mmap to map kernelspace into user space.
    hint will be helpfull.

    2. Also,as I registered the device as network device, I could use
    socket and interface name (zzz0) to open the device as I read from
    rubini's virtual network interface.
    But when I try to issue ioctl cmd , I get failed in
    copy_from_user which gives no of bytes not copied error. I used the
    following sample code.

    int sock = socket(AF_INET, SOCK_RAW, IPPROTO_RAW);
    struct zzz_userinfo info; /* configuration data in/out */
    struct ifreq req;

    strcpy(req.ifr_name, "zzz0");
    req.ifr_data = (zzz)&info;

    /* filled my info here*/

    if (ioctl(sock, SIOCGDEVINFO, &req)<0) {
    /* deal with error */

    /* in kernel driver */
    ptr = (struct zzz_userinfo *)ifr->ifr_data;
    err = copy_from_user(&info, ptr, sizeof(info));
    if (err)
    { printk(" not coiped %d",err); return err;}
    /* deal with the information */
    return 0;

    whats wrong in the above code?
    Hope somebody can help me on this.

    sara, Dec 27, 2004
    1. Advertisements

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.