[wdmaudiodev] Re: streamclass USB surprise removal problem: help please

  • From: "John Brinkman" <john@xxxxxxxxx>
  • To: <wdmaudiodev@xxxxxxxxxxxxx>
  • Date: Mon, 14 Apr 2003 17:00:45 -0700

Hi Philip,

I'm not an expert and I can't specifically answer any of your questions, so
I will simply explain how I handle a removal IRP and with any luck I wont
mislead you or waste your time.

When my stream class driver receives a surprise removal IRP, and one of my
MIDI pins is open I will:

1) Any new control or stream requests are completed with
STATUS_DEVICED_REMOVED.

2) I force my open pins back to KSSTATE_STOP performing any cleanup work
that is done when translating from RUN to STOP under normal conditions.  I
force the KStream base class back to KSSTATE_STOP by accessing its member
m_eState (KStream::m_eState = KSSTATE_STOP) and then I complete any pending
SRBs in my queues with STATUS_CANCELLED.  I also "religiously" (because I
don't remember why) set both the Srb->CommandData.DataBufferArray->DataUsed
and Irp->IoStatus.Information fields to zero.

Once all that is done I complete the removal IRP with STATUS_SUCCESS.

Good luck,
-John

----- Original Message -----
From: "pagefault 0x0" <pagefault0x0@xxxxxxxxxxx>
To: <wdmaudiodev@xxxxxxxxxxxxx>
Sent: Sunday, April 13, 2003 10:44 AM
Subject: [wdmaudiodev] streamclass USB surprise removal problem: help please


>
>
> Hello!
>
> I know that this is Win98SE question, and that this is an NT based list,
but
> my USB stream class MIDI driver is WDM, so I hope I'm not too far off
topic.
> While this driver has been made with DriverWorks (not by me- I'm the lucky
> debugger), I have been reading about stream class in the DDK, and take
> nothing for granted in the DriverWorks libraries (seen some questionable
> things in there!).  So let's forget about DriveWorks, and talk in plain
old
> WDM/streamclass language.  I'm away from my source and the DDK headers, so
> apologies if I have mispelled some DDK/streamclass constants.  As stated,
> this question concerns Win98SE, and it also has the WDM audio QFE
installed.
> The driver is MIDI in/out USB bulk driver.
>
> My problem is this: my stream class MIDI driver freezes the system, or
BSODs
> in _VWIN32_CloseVxDHandle on surprise removal.  Here's the mystery: it
does
> not do this with each MIDI app (but all except MIDIOX), AND it works fine
> with for surprise removal with ALL apps under WinXP SP1 (except that
stream
> class BSODs under driver verifier when it completes some IRPs with
> STATUS_PENDING!).  In Win98SE, I do get a SRB_SURPRISE_REMOVAL associated
> with IRP_MN_REMOVE_DEVICE (naturally).  I do wait for all my own created
> IRPsto my device to come back up and I free them (I created them with
> IoCreate Irp).  This is done in accordance to Walter Oney's cancel
examples
> in his 2ed book (Great book!  Can't survive without it!).  Then I complete
> all my queued SRBs with STATUS_CANCELLED.  Then, sometimes I get
> SRB_CLOSE_STREAM, but NEVER SRB_UNINITIALIZE_DEVICE.  I have noted two
> things:
>
> a) I have my IRP stream class interception handlers which allow me to
check
> what is going on before forwarding them to stream class.  I know, this is
> notfor production driver, only for debugging. I have seen that I although
I
> get 3 IRP_MJ_CREATE to stream class, I *never* get 3
> IRP_MJ_CLEANUP/IRP_MJ_CLOSE, but only 2.  Why  is this?  Can I send these
> IRPs myself to ks.sys?  If so, how can I find its DEVICE_OBJECT?  Why do I
> even get IRP_MN_REMOVE_DEVICE in this circumstance, with references on my
> class DEVICE_OBJECT??
>
> Sometimes, even though I received IRP_MN_REMOVE_DEVICE, I continue to find
> IRP_MJ_DEVICE_CONTROL IRPs being sent to stream.sys!!  If I have received
> remove IRP, I complete them with STATUS_DELETE_PENDING, but they keep on
> coming!  Why?
>
> b) As I said, I do get SRB_SURPRISE_REMOVAL.  While I am stepping through
> this handler in SoftICE, I frequently get a freeze *before* I complete the
> SRB.  Later my timeout routine for this SRB is called, which confirms that
I
> was never able to complete the SRB with the default timeout.  When I
specify
> NO timeout, the system freezes.  So I reasoned I am preempted/interrupted.
> So in my surprise removal handler, I did _asm cli, and balanced this with
> _asm sti after I completed the SRB (I know, never in a production
> driver...).  This time I *always* complete the SRB, but later freeze or
BSOD
> in _VWIN32_CloseVxDHandle.  What would cause this?  Is this my interrupt
on
> my device?  When in my IRP interception functions, should I send the
> IRP_MN_REMOVE_DEVICE right away down to the bus driver?  Any ideas on
this??
>
>
> Can anyone help me somewhat with my woes?  Thanks in advance.
>
> Philip Lukidis
>
> --------------------------------------------------------------------------
--
> Add photos to your e-mail with MSN 8. [1]Get 2 months FREE*.
>
> --- Links ---
>    1 http://g.msn.com/8HMRENCA/2746
> ******************
>
> WDMAUDIODEV addresses:
> Post message: mailto:wdmaudiodev@xxxxxxxxxxxxx
> Subscribe:    mailto:wdmaudiodev-request@xxxxxxxxxxxxx?subject=subscribe
> Unsubscribe:  mailto:wdmaudiodev-request@xxxxxxxxxxxxx?subject=unsubscribe
> Moderator:    mailto:wdmaudiodev-moderators@xxxxxxxxxxxxx
>
> URL to WDMAUDIODEV page:
> http://www.wdmaudiodev.de/
>
>

******************

WDMAUDIODEV addresses:
Post message: mailto:wdmaudiodev@xxxxxxxxxxxxx
Subscribe:    mailto:wdmaudiodev-request@xxxxxxxxxxxxx?subject=subscribe
Unsubscribe:  mailto:wdmaudiodev-request@xxxxxxxxxxxxx?subject=unsubscribe
Moderator:    mailto:wdmaudiodev-moderators@xxxxxxxxxxxxx

URL to WDMAUDIODEV page:
http://www.wdmaudiodev.de/

Other related posts: