Re: [Libusb-devel] libusb silently ignores permission errors

"Xiaofan Chen" <[email protected]>
Newsgroups gmane.linux.usb.devel,gmane.comp.lib.libusb.devel.general
Message-ID <[email protected]>
On 9/24/07, Alan Stern <[email protected]> wrote:
> On Sun, 23 Sep 2007, Xiaofan Chen wrote:
>
> > > Try building a kernel with CONFIG_USB_SUSPEND disabled.
> > >
> >
> > Ah this is the key. Now it is ok, I believe the firmware does not adequately
> > handle USB suspend. I am still investigating how to handle USB suspend
> > correctly by changing the Microchip provided firmware framework.
> > http://forum.microchip.com/tm.aspx?m=275422
> >
> > Could you explain what happend to lsusb why it failed to find the device in
> > the case that  CONFIG_USB_SUSPEND is enabled? Thanks in advance.
>
> After you plugged in the device, the kernel suspended it.  Then when
> you ran lsusb, the kernel tried to unsuspend the device -- but instead
> of resuming correctly, the device disconnected itself.  (Maybe as part
> of the firmware's resume sequence, it removed the D+ pullup
> resistance.)  Hence lsusb wasn't able to find it.  Shortly afterward,
> the device connected itself again.
>

Thanks a lot for the explanation.

I remember you have a patch in the linux-usb-devel list which helps in
this situation so that lsusb (reading the descriptors) will not
unsuspend the device. Will it fix this issue?

The relaveant Microchip PICDEM FS USB bootloader firmware is
listed here. I will try the simple fix (remove sleep) and see if it helps
when auto-suspend is enabled in the kernel.

/******************************************************************************

 * Function:        void USBDriverService(void)

 *

 * PreCondition:    None

 *

 * Input:           None

 *

 * Output:          None

 *

 * Side Effects:    None

 *

 * Overview:        This routine is the heart of this firmware. It manages

 *                  all USB interrupts.

 *

 * Note:            Device state transitions through the following stages:

 *                  DETACHED -> ATTACHED -> POWERED -> DEFAULT ->

 *                  ADDRESS_PENDING -> ADDRESSED -> CONFIGURED -> READY

 *****************************************************************************/

void USBDriverService(void)

{

    /*

     * Task A: Service USB Activity Interrupt

     */



    if(UIRbits.ACTVIF && UIEbits.ACTVIE)

    {

        UCONbits.SUSPND = 0;

        UIEbits.ACTVIE = 0;

        UIRbits.ACTVIF = 0;

    }//end if



    /*

     * Task B: Service USB Bus Reset Interrupt.

     * When bus reset is received during suspend, ACTVIF will be set first,

     * once the UCONbits.SUSPND is clear, then the URSTIF bit will be asserted.

     * This is why URSTIF is checked after ACTVIF.

     *

     * The USB reset flag is masked when the USB state is in

     * DETACHED_STATE or ATTACHED_STATE, and therefore cannot

     * cause a USB reset event during these two states.

     */

    if(UIRbits.URSTIF && UIEbits.URSTIE)    USBProtocolResetHandler();



    /*

     * Task C: Service other USB interrupts

     */

    if(UIRbits.IDLEIF && UIEbits.IDLEIE)

    {

        UIEbits.ACTVIE = 1;                     // Enable bus activity interrupt

        UIRbits.IDLEIF = 0;

        UCONbits.SUSPND = 1;                    // Put USB module in
power conserve

                                                // mode, SIE clock inactive

        /* Now, go into power saving */

        PIE2bits.USBIE = 1;                     // Set wakeup source

        Sleep();

        PIR2bits.USBIF = 0;

    }//end if



    if(UIRbits.STALLIF && UIEbits.STALLIE)

    {

        if(UEP0bits.EPSTALL == 1)

        {

            USBPrepareForNextSetupTrf();        // Firmware Work-Around

            UEP0bits.EPSTALL = 0;

        }//end if

        UIRbits.STALLIF = 0;

    }//end if



    /*

     * Pointless to continue servicing if the host has not sent a bus reset.

     * Once bus reset is received, the device transitions into the DEFAULT

     * state and is ready for communication.

     */

    if(usb_device_state < DEFAULT_STATE) return;



    /*

     * Task D: Servicing USB Transaction Complete Interrupt

     */

    if(UIRbits.TRNIF && UIEbits.TRNIE)

    {

        /*

         * USBCtrlEPService only services transactions over EP0.

         * It ignores all other EP transactions.

         */

        USBCtrlEPService();



        /*

         * Other EP can be serviced later by responsible device class firmware.

         * Each device driver knows when an OUT or IN transaction is ready by

         * checking the buffer ownership bit.

         * An OUT EP should always be owned by SIE until the data is ready.

         * An IN EP should always be owned by CPU until the data is ready.

         *

         * Because of this logic, it is not necessary to save the USTAT value

         * of non-EP0 transactions.

         */

        UIRbits.TRNIF = 0;

    }//end if(UIRbits.TRNIF && UIEbits.TRNIE)



}//end USBDriverService


Xiaofan

-------------------------------------------------------------------------
This SF.net email is sponsored by: Microsoft
Defy all challenges. Microsoft(R) Visual Studio 2005.
http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/
_______________________________________________
[email protected]
To unsubscribe, use the last form field at:
https://lists.sourceforge.net/lists/listinfo/linux-usb-devel
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.