On Wed, 22 Mar 2006, twomol wrote: > Hi,all > > I'm writing a linux usb driver for our data sampling board which > transmit data with usb bus. I didn't write a host usb driver under linux > before. > I need to send some vendor request to the board to tell it how to work. > Such as , when some one open the device , the driver need to > tell board to start sample.I write the open method like this: > > struct usb_ctrlrequest start_ad_convert_quest = > { > .bRequestType = USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_DEVICE, > .bRequest = AD_BREQUEST_START_CONVERT, > .wValue = 0, > .wIndex = 0, > .wLength = 0, > }; > > static int ad_open(struct inode *inode, struct file *file) > { > [snip] > if(0 == dev->started){ > ctrl_urb = usb_alloc_urb(0, GFP_KERNEL); > if(NULL == ctrl_urb){ > retval = -ENOMEM; > goto exit; > } > usb_fill_control_urb(ctrl_urb, dev->udev, usb_sndctrlpipe(dev->udev, 0), > (unsigned char*)&start_ad_convert_quest, NULL, 0, > ctrl_urb_finish, dev); > retval = usb_submit_urb (ctrl_urb, GFP_KERNEL); > if (0 > retval){ > ERROR("Can't submit start_convert request\n"); > } > } > [snip] > } > > static void ctrl_urb_finish(struct urb* ctrl_urb, struct pt_regs *reg) > { > [snip] > if(0 != ctrl_urb->status){ > ERROR("Start convert request hasn't been sent successfully:%d\n", > ctrl_urb->status); > goto exit; > } > [snip] > exit: > usb_free_urb(ctrl_urb); > }
This code would be a lot easier to read if you or your email client did not omit all the tab characters. > If I do like the above , I will always get ctrl_urb->status = > -32(-EPIPE),and I can only open the device node once > .When I open the node the second time , the HDD led indicate that > harddisk is busy, no output of printk,after about one > minute later ,the host desktop is dead ,no response, I have to reboot > it.I try to change the memory allocating flags from GFP_KERNEL > to GFP_NOIO or GFP_ATOMIC, the result is same. It sounds like you have a bug in your driver. > But if I don't use urb directly, ie, using : > usb_control_msg(dev->udev,usb_sndctrlpipe(dev->udev, > 0),AD_BREQUEST_START_CONVERT,USB_DIR_OUT | USB_TYPE_VENDOR | > USB_RECIP_DEVICE,0,0,NULL,0,1000); > It works fine , every thing is right. > > What's the possible reason?Any advices are welcome. Thanks I can't tell. The code you listed above looks okay. Maybe the bug is in a part of the driver that you didn't include here. Why do you call usb_free_urb() from within the completion routine? Since the URB gets allocated when the device is opened, that means your client program can send only one message. Have you considered writing this as a userspace program (using libusb) instead of as a kernel driver? It would probably be a lot easier. Alan Stern ------------------------------------------------------- This SF.Net email is sponsored by xPML, a groundbreaking scripting language that extends applications into web and mobile media. Attend the live webcast and join the prime developer group breaking into this new coding territory! http://sel.as-us.falkag.net/sel?cmd=lnk&kid=110944&bid=241720&dat=121642 _______________________________________________ linux-usb-devel@lists.sourceforge.net To unsubscribe, use the last form field at: https://lists.sourceforge.net/lists/listinfo/linux-usb-devel