public inbox for devel@edk2.groups.io
 help / color / mirror / Atom feed
* SNP_INIT while in TPL_NOTIFY
@ 2017-01-27 16:51 Tomas Pilar (tpilar)
  2017-01-27 18:12 ` Laszlo Ersek
  0 siblings, 1 reply; 7+ messages in thread
From: Tomas Pilar (tpilar) @ 2017-01-27 16:51 UTC (permalink / raw)
  To: edk2-devel@lists.01.org

Hi,

I am currently maintaining our network driver written using the EDKII
framework. Our network device implements a MCDI (mc-driver interface)
which is (in theory) asynchronous (DMA doorbell-messagebox
communication), although the majority of the calls take less than a
jiffy. So for example, the setting up of TX and RX queues on the NIC
requires some MCDI calls which the driver then has to wait for. I've
implemented this using the gSB->SetTimer event system.

My problem is that the SimpleNetworkInitialize() method is called by the
UEFI platform network core (network core finds a new NIC with SNP ->
tries to open -> not initialised, so it tries to INIT) using a
TPL_NOTIFY context, where the code is not allowed to sleep (I assume
that this is the MNP generic one second network poll timer). I could in
theory initialise the NIC earlier, during probe, but the SNP allows for
specification of extra buffer space for TX and RX during init. The
network core might conceivable use that. Or the MNP might want to change
station address using SNP or call for a reset which again requires
asynchronous NIC operation.

Has anyone encountered something similar? Is there a canonical solution
to this issue?

Cheers,
Tomas Pilar


The information contained in this message is confidential and is intended for the addressee(s) only. If you have received this message in error, please notify the sender immediately and delete the message. Unless you are an addressee (or authorized to receive for an addressee), you may not use, copy or disclose to anyone this message or any information contained in this message. The unauthorized use, disclosure, copying or alteration of this message is strictly prohibited.


^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: SNP_INIT while in TPL_NOTIFY
  2017-01-27 16:51 SNP_INIT while in TPL_NOTIFY Tomas Pilar (tpilar)
@ 2017-01-27 18:12 ` Laszlo Ersek
  2017-01-30 10:51   ` Tomas Pilar (tpilar)
                     ` (2 more replies)
  0 siblings, 3 replies; 7+ messages in thread
From: Laszlo Ersek @ 2017-01-27 18:12 UTC (permalink / raw)
  To: Tomas Pilar (tpilar), edk2-devel@lists.01.org

On 01/27/17 17:51, Tomas Pilar (tpilar) wrote:
> Hi,
> 
> I am currently maintaining our network driver written using the EDKII
> framework. Our network device implements a MCDI (mc-driver interface)
> which is (in theory) asynchronous (DMA doorbell-messagebox
> communication), although the majority of the calls take less than a
> jiffy. So for example, the setting up of TX and RX queues on the NIC
> requires some MCDI calls which the driver then has to wait for. I've
> implemented this using the gSB->SetTimer event system.
> 
> My problem is that the SimpleNetworkInitialize() method is called by the
> UEFI platform network core (network core finds a new NIC with SNP ->
> tries to open -> not initialised, so it tries to INIT) using a
> TPL_NOTIFY context,

This looks like a bug, in the code that calls SimpleNetworkInitialize().
According to "Table 24. TPL Restrictions", for Simple Network Protocol
methods, the TPL must be <= TPL_CALLBACK. Meaning, an SNP implementation
mustn't raise the TPL above TPL_CALLBACK, but also that any client can't
call SNP methods while executing on a TPL > TPL_CALLBACK.

Worse, even staying at TPL_CALLBACK wouldn't be good enough for calling
gBS->SetTimer(). SetTimer is < TPL_HIGH_LEVEL, so that'd be fine, but
gBS->WaitForEvent() is strictly = TPL_APPLICATION. So WaitForEvent()
can't be called when running on TPL_CALLBACK level.

> where the code is not allowed to sleep (I assume
> that this is the MNP generic one second network poll timer). I could in
> theory initialise the NIC earlier, during probe, but the SNP allows for
> specification of extra buffer space for TX and RX during init. The
> network core might conceivable use that. Or the MNP might want to change
> station address using SNP or call for a reset which again requires
> asynchronous NIC operation.
> 
> Has anyone encountered something similar? Is there a canonical solution
> to this issue?

I think you can poll the NIC in a busy loop, or if that's excessive, use
gBS->Stall() between polls. Stall() is <= TPL_HIGH_LEVEL, so it should
be safe. OTOH, "Execution of the processor is not yielded for the
duration of the stall".

Thanks
Laszlo

> 
> Cheers,
> Tomas Pilar
> 
> 
> The information contained in this message is confidential and is
> intended for the addressee(s) only. If you have received this message in
> error, please notify the sender immediately and delete the message.
> Unless you are an addressee (or authorized to receive for an addressee),
> you may not use, copy or disclose to anyone this message or any
> information contained in this message. The unauthorized use, disclosure,
> copying or alteration of this message is strictly prohibited.
> _______________________________________________
> edk2-devel mailing list
> edk2-devel@lists.01.org
> https://lists.01.org/mailman/listinfo/edk2-devel



^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: SNP_INIT while in TPL_NOTIFY
  2017-01-27 18:12 ` Laszlo Ersek
@ 2017-01-30 10:51   ` Tomas Pilar (tpilar)
  2017-01-30 17:51   ` Andrew Fish
  2017-02-06  6:10   ` Ye, Ting
  2 siblings, 0 replies; 7+ messages in thread
From: Tomas Pilar (tpilar) @ 2017-01-30 10:51 UTC (permalink / raw)
  To: Laszlo Ersek, edk2-devel@lists.01.org

Thanks Laszlo,

I am glad I wasn't going insane there. I'll turn it into a simple busy poll.

Cheers,
Tom


On 27/01/17 18:12, Laszlo Ersek wrote:
> On 01/27/17 17:51, Tomas Pilar (tpilar) wrote:
>> Hi,
>>
>> I am currently maintaining our network driver written using the EDKII
>> framework. Our network device implements a MCDI (mc-driver interface)
>> which is (in theory) asynchronous (DMA doorbell-messagebox
>> communication), although the majority of the calls take less than a
>> jiffy. So for example, the setting up of TX and RX queues on the NIC
>> requires some MCDI calls which the driver then has to wait for. I've
>> implemented this using the gSB->SetTimer event system.
>>
>> My problem is that the SimpleNetworkInitialize() method is called by the
>> UEFI platform network core (network core finds a new NIC with SNP ->
>> tries to open -> not initialised, so it tries to INIT) using a
>> TPL_NOTIFY context,
> This looks like a bug, in the code that calls SimpleNetworkInitialize().
> According to "Table 24. TPL Restrictions", for Simple Network Protocol
> methods, the TPL must be <= TPL_CALLBACK. Meaning, an SNP implementation
> mustn't raise the TPL above TPL_CALLBACK, but also that any client can't
> call SNP methods while executing on a TPL > TPL_CALLBACK.
>
> Worse, even staying at TPL_CALLBACK wouldn't be good enough for calling
> gBS->SetTimer(). SetTimer is < TPL_HIGH_LEVEL, so that'd be fine, but
> gBS->WaitForEvent() is strictly = TPL_APPLICATION. So WaitForEvent()
> can't be called when running on TPL_CALLBACK level.
>
>> where the code is not allowed to sleep (I assume
>> that this is the MNP generic one second network poll timer). I could in
>> theory initialise the NIC earlier, during probe, but the SNP allows for
>> specification of extra buffer space for TX and RX during init. The
>> network core might conceivable use that. Or the MNP might want to change
>> station address using SNP or call for a reset which again requires
>> asynchronous NIC operation.
>>
>> Has anyone encountered something similar? Is there a canonical solution
>> to this issue?
> I think you can poll the NIC in a busy loop, or if that's excessive, use
> gBS->Stall() between polls. Stall() is <= TPL_HIGH_LEVEL, so it should
> be safe. OTOH, "Execution of the processor is not yielded for the
> duration of the stall".
>
> Thanks
> Laszlo
>
>> Cheers,
>> Tomas Pilar
>>
>>
>> The information contained in this message is confidential and is
>> intended for the addressee(s) only. If you have received this message in
>> error, please notify the sender immediately and delete the message.
>> Unless you are an addressee (or authorized to receive for an addressee),
>> you may not use, copy or disclose to anyone this message or any
>> information contained in this message. The unauthorized use, disclosure,
>> copying or alteration of this message is strictly prohibited.
>> _______________________________________________
>> edk2-devel mailing list
>> edk2-devel@lists.01.org
>> https://lists.01.org/mailman/listinfo/edk2-devel

The information contained in this message is confidential and is intended for the addressee(s) only. If you have received this message in error, please notify the sender immediately and delete the message. Unless you are an addressee (or authorized to receive for an addressee), you may not use, copy or disclose to anyone this message or any information contained in this message. The unauthorized use, disclosure, copying or alteration of this message is strictly prohibited.


^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: SNP_INIT while in TPL_NOTIFY
  2017-01-27 18:12 ` Laszlo Ersek
  2017-01-30 10:51   ` Tomas Pilar (tpilar)
@ 2017-01-30 17:51   ` Andrew Fish
  2017-02-06  6:10   ` Ye, Ting
  2 siblings, 0 replies; 7+ messages in thread
From: Andrew Fish @ 2017-01-30 17:51 UTC (permalink / raw)
  To: Laszlo Ersek; +Cc: Tomas Pilar (tpilar), edk2-devel@lists.01.org


> On Jan 27, 2017, at 10:12 AM, Laszlo Ersek <lersek@redhat.com> wrote:
> 
> On 01/27/17 17:51, Tomas Pilar (tpilar) wrote:
>> Hi,
>> 
>> I am currently maintaining our network driver written using the EDKII
>> framework. Our network device implements a MCDI (mc-driver interface)
>> which is (in theory) asynchronous (DMA doorbell-messagebox
>> communication), although the majority of the calls take less than a
>> jiffy. So for example, the setting up of TX and RX queues on the NIC
>> requires some MCDI calls which the driver then has to wait for. I've
>> implemented this using the gSB->SetTimer event system.
>> 
>> My problem is that the SimpleNetworkInitialize() method is called by the
>> UEFI platform network core (network core finds a new NIC with SNP ->
>> tries to open -> not initialised, so it tries to INIT) using a
>> TPL_NOTIFY context,
> 
> This looks like a bug, in the code that calls SimpleNetworkInitialize().
> According to "Table 24. TPL Restrictions", for Simple Network Protocol
> methods, the TPL must be <= TPL_CALLBACK. Meaning, an SNP implementation
> mustn't raise the TPL above TPL_CALLBACK, but also that any client can't
> call SNP methods while executing on a TPL > TPL_CALLBACK.
> 
> Worse, even staying at TPL_CALLBACK wouldn't be good enough for calling
> gBS->SetTimer(). SetTimer is < TPL_HIGH_LEVEL, so that'd be fine, but
> gBS->WaitForEvent() is strictly = TPL_APPLICATION. So WaitForEvent()
> can't be called when running on TPL_CALLBACK level.
> 
>> where the code is not allowed to sleep (I assume
>> that this is the MNP generic one second network poll timer). I could in
>> theory initialise the NIC earlier, during probe, but the SNP allows for
>> specification of extra buffer space for TX and RX during init. The
>> network core might conceivable use that. Or the MNP might want to change
>> station address using SNP or call for a reset which again requires
>> asynchronous NIC operation.
>> 
>> Has anyone encountered something similar? Is there a canonical solution
>> to this issue?
> 
> I think you can poll the NIC in a busy loop, or if that's excessive, use
> gBS->Stall() between polls. Stall() is <= TPL_HIGH_LEVEL, so it should
> be safe. OTOH, "Execution of the processor is not yielded for the
> duration of the stall".
> 

Laszlo,

You are correct Stall() does not yield. The only way to yield from an event is to return from the event function. 

When your are writing threaded code you think of stall as a way to yield, so you encoded the logic of the program as a loop that yields to the thread. In the event model, since you have to return, the idiom is not a loop but a state machine. Thus your event will yield by returning so you would want to perhaps take a different action the next time you enter the event based on previous state.  So if you had to deal with a long stall you might want to program a timer event that periodically checks for the event and it will always return quickly regardless of the state of the check. So you can break stuff up into smaller events or have a single event that remembers state, but both of these are a lot like solving the problem with a state machine vs. a code loop. 

Thanks,

Andrew Fish  

> Thanks
> Laszlo
> 
>> 
>> Cheers,
>> Tomas Pilar
>> 
>> 
>> The information contained in this message is confidential and is
>> intended for the addressee(s) only. If you have received this message in
>> error, please notify the sender immediately and delete the message.
>> Unless you are an addressee (or authorized to receive for an addressee),
>> you may not use, copy or disclose to anyone this message or any
>> information contained in this message. The unauthorized use, disclosure,
>> copying or alteration of this message is strictly prohibited.
>> _______________________________________________
>> edk2-devel mailing list
>> edk2-devel@lists.01.org
>> https://lists.01.org/mailman/listinfo/edk2-devel
> 
> _______________________________________________
> edk2-devel mailing list
> edk2-devel@lists.01.org <mailto:edk2-devel@lists.01.org>
> https://lists.01.org/mailman/listinfo/edk2-devel <https://lists.01.org/mailman/listinfo/edk2-devel>


^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: SNP_INIT while in TPL_NOTIFY
  2017-01-27 18:12 ` Laszlo Ersek
  2017-01-30 10:51   ` Tomas Pilar (tpilar)
  2017-01-30 17:51   ` Andrew Fish
@ 2017-02-06  6:10   ` Ye, Ting
  2017-02-06 14:58     ` Tomas Pilar (tpilar)
  2 siblings, 1 reply; 7+ messages in thread
From: Ye, Ting @ 2017-02-06  6:10 UTC (permalink / raw)
  To: Laszlo Ersek, Tomas Pilar (tpilar), edk2-devel@lists.01.org

May I ask which SNP module are we discussing here?  Is it the common SnpDxe driver under MdeModulePkg/Universal/Network, or a specific driver implemented for your network device?

Best Regards,
Ye Ting

-----Original Message-----
From: edk2-devel [mailto:edk2-devel-bounces@lists.01.org] On Behalf Of Laszlo Ersek
Sent: Saturday, January 28, 2017 2:12 AM
To: Tomas Pilar (tpilar) <tpilar@solarflare.com>; edk2-devel@lists.01.org <edk2-devel@ml01.01.org>
Subject: Re: [edk2] SNP_INIT while in TPL_NOTIFY

On 01/27/17 17:51, Tomas Pilar (tpilar) wrote:
> Hi,
> 
> I am currently maintaining our network driver written using the EDKII 
> framework. Our network device implements a MCDI (mc-driver interface) 
> which is (in theory) asynchronous (DMA doorbell-messagebox 
> communication), although the majority of the calls take less than a 
> jiffy. So for example, the setting up of TX and RX queues on the NIC 
> requires some MCDI calls which the driver then has to wait for. I've 
> implemented this using the gSB->SetTimer event system.
> 
> My problem is that the SimpleNetworkInitialize() method is called by 
> the UEFI platform network core (network core finds a new NIC with SNP 
> -> tries to open -> not initialised, so it tries to INIT) using a 
> TPL_NOTIFY context,

This looks like a bug, in the code that calls SimpleNetworkInitialize().
According to "Table 24. TPL Restrictions", for Simple Network Protocol methods, the TPL must be <= TPL_CALLBACK. Meaning, an SNP implementation mustn't raise the TPL above TPL_CALLBACK, but also that any client can't call SNP methods while executing on a TPL > TPL_CALLBACK.

Worse, even staying at TPL_CALLBACK wouldn't be good enough for calling
gBS->SetTimer(). SetTimer is < TPL_HIGH_LEVEL, so that'd be fine, but
gBS->WaitForEvent() is strictly = TPL_APPLICATION. So WaitForEvent()
can't be called when running on TPL_CALLBACK level.

> where the code is not allowed to sleep (I assume that this is the MNP 
> generic one second network poll timer). I could in theory initialise 
> the NIC earlier, during probe, but the SNP allows for specification of 
> extra buffer space for TX and RX during init. The network core might 
> conceivable use that. Or the MNP might want to change station address 
> using SNP or call for a reset which again requires asynchronous NIC 
> operation.
> 
> Has anyone encountered something similar? Is there a canonical 
> solution to this issue?

I think you can poll the NIC in a busy loop, or if that's excessive, use
gBS->Stall() between polls. Stall() is <= TPL_HIGH_LEVEL, so it should
be safe. OTOH, "Execution of the processor is not yielded for the duration of the stall".

Thanks
Laszlo

> 
> Cheers,
> Tomas Pilar
> 
> 
> The information contained in this message is confidential and is 
> intended for the addressee(s) only. If you have received this message 
> in error, please notify the sender immediately and delete the message.
> Unless you are an addressee (or authorized to receive for an 
> addressee), you may not use, copy or disclose to anyone this message 
> or any information contained in this message. The unauthorized use, 
> disclosure, copying or alteration of this message is strictly prohibited.
> _______________________________________________
> edk2-devel mailing list
> edk2-devel@lists.01.org
> https://lists.01.org/mailman/listinfo/edk2-devel

_______________________________________________
edk2-devel mailing list
edk2-devel@lists.01.org
https://lists.01.org/mailman/listinfo/edk2-devel


^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: SNP_INIT while in TPL_NOTIFY
  2017-02-06  6:10   ` Ye, Ting
@ 2017-02-06 14:58     ` Tomas Pilar (tpilar)
  2017-02-07  3:31       ` Ye, Ting
  0 siblings, 1 reply; 7+ messages in thread
From: Tomas Pilar (tpilar) @ 2017-02-06 14:58 UTC (permalink / raw)
  To: Ye, Ting, Laszlo Ersek, edk2-devel@lists.01.org

This is the specific implementation of SNP for our driver. We expose
this implementation which is then consumed by MNP so that our NIC can be
used as a NIC. The specific problem is that some functionality that SNP
needs to implement (initializing queues, changing MAC, resetting) are
asynchronous, but MNP can call our SNP implementation in raised TPL
where one is not allowed to wait.

So the only solution seems to be to use a busy poll and actually hang
the execution until the asynchronous call to the MC on the NIC is
completed, even though we've been called in TPL_CALLBACK or TPL_NOTIFY.

Cheers,
Tom

On 06/02/17 06:10, Ye, Ting wrote:
> May I ask which SNP module are we discussing here?  Is it the common SnpDxe driver under MdeModulePkg/Universal/Network, or a specific driver implemented for your network device?
>
> Best Regards,
> Ye Ting
>
> -----Original Message-----
> From: edk2-devel [mailto:edk2-devel-bounces@lists.01.org] On Behalf Of Laszlo Ersek
> Sent: Saturday, January 28, 2017 2:12 AM
> To: Tomas Pilar (tpilar) <tpilar@solarflare.com>; edk2-devel@lists.01.org <edk2-devel@ml01.01.org>
> Subject: Re: [edk2] SNP_INIT while in TPL_NOTIFY
>
> On 01/27/17 17:51, Tomas Pilar (tpilar) wrote:
>> Hi,
>>
>> I am currently maintaining our network driver written using the EDKII
>> framework. Our network device implements a MCDI (mc-driver interface)
>> which is (in theory) asynchronous (DMA doorbell-messagebox
>> communication), although the majority of the calls take less than a
>> jiffy. So for example, the setting up of TX and RX queues on the NIC
>> requires some MCDI calls which the driver then has to wait for. I've
>> implemented this using the gSB->SetTimer event system.
>>
>> My problem is that the SimpleNetworkInitialize() method is called by
>> the UEFI platform network core (network core finds a new NIC with SNP
>> -> tries to open -> not initialised, so it tries to INIT) using a
>> TPL_NOTIFY context,
> This looks like a bug, in the code that calls SimpleNetworkInitialize().
> According to "Table 24. TPL Restrictions", for Simple Network Protocol methods, the TPL must be <= TPL_CALLBACK. Meaning, an SNP implementation mustn't raise the TPL above TPL_CALLBACK, but also that any client can't call SNP methods while executing on a TPL > TPL_CALLBACK.
>
> Worse, even staying at TPL_CALLBACK wouldn't be good enough for calling
> gBS->SetTimer(). SetTimer is < TPL_HIGH_LEVEL, so that'd be fine, but
> gBS->WaitForEvent() is strictly = TPL_APPLICATION. So WaitForEvent()
> can't be called when running on TPL_CALLBACK level.
>
>> where the code is not allowed to sleep (I assume that this is the MNP
>> generic one second network poll timer). I could in theory initialise
>> the NIC earlier, during probe, but the SNP allows for specification of
>> extra buffer space for TX and RX during init. The network core might
>> conceivable use that. Or the MNP might want to change station address
>> using SNP or call for a reset which again requires asynchronous NIC
>> operation.
>>
>> Has anyone encountered something similar? Is there a canonical
>> solution to this issue?
> I think you can poll the NIC in a busy loop, or if that's excessive, use
> gBS->Stall() between polls. Stall() is <= TPL_HIGH_LEVEL, so it should
> be safe. OTOH, "Execution of the processor is not yielded for the duration of the stall".
>
> Thanks
> Laszlo
>
>> Cheers,
>> Tomas Pilar
>>
>>
>> The information contained in this message is confidential and is
>> intended for the addressee(s) only. If you have received this message
>> in error, please notify the sender immediately and delete the message.
>> Unless you are an addressee (or authorized to receive for an
>> addressee), you may not use, copy or disclose to anyone this message
>> or any information contained in this message. The unauthorized use,
>> disclosure, copying or alteration of this message is strictly prohibited.
>> _______________________________________________
>> edk2-devel mailing list
>> edk2-devel@lists.01.org
>> https://lists.01.org/mailman/listinfo/edk2-devel
> _______________________________________________
> edk2-devel mailing list
> edk2-devel@lists.01.org
> https://lists.01.org/mailman/listinfo/edk2-devel

The information contained in this message is confidential and is intended for the addressee(s) only. If you have received this message in error, please notify the sender immediately and delete the message. Unless you are an addressee (or authorized to receive for an addressee), you may not use, copy or disclose to anyone this message or any information contained in this message. The unauthorized use, disclosure, copying or alteration of this message is strictly prohibited.


^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: SNP_INIT while in TPL_NOTIFY
  2017-02-06 14:58     ` Tomas Pilar (tpilar)
@ 2017-02-07  3:31       ` Ye, Ting
  0 siblings, 0 replies; 7+ messages in thread
From: Ye, Ting @ 2017-02-07  3:31 UTC (permalink / raw)
  To: Tomas Pilar (tpilar), Laszlo Ersek, edk2-devel@lists.01.org

Hi Tom,

Thanks for the clarification. I just want to confirm that it is not a bug in the common SNP driver. 

Best Regards,
Ye Ting

-----Original Message-----
From: edk2-devel [mailto:edk2-devel-bounces@lists.01.org] On Behalf Of Tomas Pilar (tpilar)
Sent: Monday, February 06, 2017 10:59 PM
To: Ye, Ting <ting.ye@intel.com>; Laszlo Ersek <lersek@redhat.com>; edk2-devel@lists.01.org <edk2-devel@ml01.01.org>
Subject: Re: [edk2] SNP_INIT while in TPL_NOTIFY

This is the specific implementation of SNP for our driver. We expose this implementation which is then consumed by MNP so that our NIC can be used as a NIC. The specific problem is that some functionality that SNP needs to implement (initializing queues, changing MAC, resetting) are asynchronous, but MNP can call our SNP implementation in raised TPL where one is not allowed to wait.

So the only solution seems to be to use a busy poll and actually hang the execution until the asynchronous call to the MC on the NIC is completed, even though we've been called in TPL_CALLBACK or TPL_NOTIFY.

Cheers,
Tom

On 06/02/17 06:10, Ye, Ting wrote:
> May I ask which SNP module are we discussing here?  Is it the common SnpDxe driver under MdeModulePkg/Universal/Network, or a specific driver implemented for your network device?
>
> Best Regards,
> Ye Ting
>
> -----Original Message-----
> From: edk2-devel [mailto:edk2-devel-bounces@lists.01.org] On Behalf Of 
> Laszlo Ersek
> Sent: Saturday, January 28, 2017 2:12 AM
> To: Tomas Pilar (tpilar) <tpilar@solarflare.com>; 
> edk2-devel@lists.01.org <edk2-devel@ml01.01.org>
> Subject: Re: [edk2] SNP_INIT while in TPL_NOTIFY
>
> On 01/27/17 17:51, Tomas Pilar (tpilar) wrote:
>> Hi,
>>
>> I am currently maintaining our network driver written using the EDKII 
>> framework. Our network device implements a MCDI (mc-driver interface) 
>> which is (in theory) asynchronous (DMA doorbell-messagebox 
>> communication), although the majority of the calls take less than a 
>> jiffy. So for example, the setting up of TX and RX queues on the NIC 
>> requires some MCDI calls which the driver then has to wait for. I've 
>> implemented this using the gSB->SetTimer event system.
>>
>> My problem is that the SimpleNetworkInitialize() method is called by 
>> the UEFI platform network core (network core finds a new NIC with SNP
>> -> tries to open -> not initialised, so it tries to INIT) using a
>> TPL_NOTIFY context,
> This looks like a bug, in the code that calls SimpleNetworkInitialize().
> According to "Table 24. TPL Restrictions", for Simple Network Protocol methods, the TPL must be <= TPL_CALLBACK. Meaning, an SNP implementation mustn't raise the TPL above TPL_CALLBACK, but also that any client can't call SNP methods while executing on a TPL > TPL_CALLBACK.
>
> Worse, even staying at TPL_CALLBACK wouldn't be good enough for 
> calling
> gBS->SetTimer(). SetTimer is < TPL_HIGH_LEVEL, so that'd be fine, but
> gBS->WaitForEvent() is strictly = TPL_APPLICATION. So WaitForEvent()
> can't be called when running on TPL_CALLBACK level.
>
>> where the code is not allowed to sleep (I assume that this is the MNP 
>> generic one second network poll timer). I could in theory initialise 
>> the NIC earlier, during probe, but the SNP allows for specification 
>> of extra buffer space for TX and RX during init. The network core 
>> might conceivable use that. Or the MNP might want to change station 
>> address using SNP or call for a reset which again requires 
>> asynchronous NIC operation.
>>
>> Has anyone encountered something similar? Is there a canonical 
>> solution to this issue?
> I think you can poll the NIC in a busy loop, or if that's excessive, 
> use
> gBS->Stall() between polls. Stall() is <= TPL_HIGH_LEVEL, so it should
> be safe. OTOH, "Execution of the processor is not yielded for the duration of the stall".
>
> Thanks
> Laszlo
>
>> Cheers,
>> Tomas Pilar
>>
>>
>> The information contained in this message is confidential and is 
>> intended for the addressee(s) only. If you have received this message 
>> in error, please notify the sender immediately and delete the message.
>> Unless you are an addressee (or authorized to receive for an 
>> addressee), you may not use, copy or disclose to anyone this message 
>> or any information contained in this message. The unauthorized use, 
>> disclosure, copying or alteration of this message is strictly prohibited.
>> _______________________________________________
>> edk2-devel mailing list
>> edk2-devel@lists.01.org
>> https://lists.01.org/mailman/listinfo/edk2-devel
> _______________________________________________
> edk2-devel mailing list
> edk2-devel@lists.01.org
> https://lists.01.org/mailman/listinfo/edk2-devel

The information contained in this message is confidential and is intended for the addressee(s) only. If you have received this message in error, please notify the sender immediately and delete the message. Unless you are an addressee (or authorized to receive for an addressee), you may not use, copy or disclose to anyone this message or any information contained in this message. The unauthorized use, disclosure, copying or alteration of this message is strictly prohibited.
_______________________________________________
edk2-devel mailing list
edk2-devel@lists.01.org
https://lists.01.org/mailman/listinfo/edk2-devel


^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2017-02-07  3:32 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2017-01-27 16:51 SNP_INIT while in TPL_NOTIFY Tomas Pilar (tpilar)
2017-01-27 18:12 ` Laszlo Ersek
2017-01-30 10:51   ` Tomas Pilar (tpilar)
2017-01-30 17:51   ` Andrew Fish
2017-02-06  6:10   ` Ye, Ting
2017-02-06 14:58     ` Tomas Pilar (tpilar)
2017-02-07  3:31       ` Ye, Ting

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox