From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-in6.apple.com (mail-out6.apple.com [17.151.62.28]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ml01.01.org (Postfix) with ESMTPS id 054BB81FDE for ; Mon, 30 Jan 2017 09:51:18 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; d=apple.com; s=mailout2048s; c=relaxed/simple; q=dns/txt; i=@apple.com; t=1485798678; h=From:Sender:Reply-To:Subject:Date:Message-id:To:Cc:MIME-version:Content-type: Content-Transfer-Encoding:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:In-reply-to:References:List-Id: List-Help:List-Unsubscribe:List-Subscribe:List-Post:List-Owner:List-Archive; bh=VheSApYjuxHKBO/8XDCxBCR20pyNIePXIMZSl+iWPtk=; b=HYslotRtSXjx13Oz/CqW0mlSw4Tta+gtxdYS5+2aCCQLzTlU5iyY/cZQJNV2Ht4d NKsQcT1DyaObq44t/e2Jq2B6qHO2Ck5WyfKb2JTiF4CIi/FuWqmZBNfTm/jcTUe6 1SCurAKaNpbE9OKgulAOYdFo6fc17yIVlSzhHKZBSd5CzkYkzkbHiWfdBjVCOdBm bCwlA+iPjjdSel7UWFwTzLUO2dF+4L6aktn4W+sWdVYRCD9qC/ejS0KUh0e/hiTf t0WZMvhznVQXIwzASReINYyJ/Sys8iiahsbXK+R8u7/fJeLlJHSH79aq6ae/NKRN SZ5/OMlWjXdJotRjZ+F/VQ==; Received: from relay4.apple.com (relay4.apple.com [17.128.113.87]) by mail-in6.apple.com (Apple Secure Mail Relay) with SMTP id 54.1B.09465.61D7F885; Mon, 30 Jan 2017 09:51:18 -0800 (PST) X-AuditID: 11973e15-360719a0000024f9-e5-588f7d16b822 Received: from nwk-mmpp-sz06.apple.com (nwk-mmpp-sz06.apple.com [17.128.115.234]) by relay4.apple.com (Apple SCV relay) with SMTP id 84.20.29672.61D7F885; Mon, 30 Jan 2017 09:51:18 -0800 (PST) MIME-version: 1.0 Received: from [17.153.28.185] (unknown [17.153.28.185]) by nwk-mmpp-sz06.apple.com (Oracle Communications Messaging Server 8.0.1.1.0 64bit (built Jun 15 2016)) with ESMTPSA id <0OKL009XFTLG8W70@nwk-mmpp-sz06.apple.com>; Mon, 30 Jan 2017 09:51:18 -0800 (PST) Sender: afish@apple.com From: Andrew Fish Message-id: <4635C152-5C77-4A3D-ADE3-B322F7EB87C0@apple.com> Date: Mon, 30 Jan 2017 09:51:16 -0800 In-reply-to: Cc: "Tomas Pilar (tpilar)" , "edk2-devel@lists.01.org" To: Laszlo Ersek References: X-Mailer: Apple Mail (2.3226) X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFrrDLMWRmVeSWpSXmKPExsUi2FAYritW2x9h8GuvtsW6Pd/YLZYd28Fi 0Xm7i82B2WPShcfMHu/3XWXzWP3kB1sAcxSXTUpqTmZZapG+XQJXxt/e7UwFP64zVsy//Iat gXH/bsYuRg4OCQETifN/U7oYuTiEBPYySqzZfZ0FJj6trRAifohRYvbKm0BxTg5eAUGJH5Pv gdnMAmESk9+cZAWxhQS6mCTOX0kDsYUFxCXendnEDGKzCShLrJj/gR2i10bi8+bvbBA1BhL7 jy9kBLFZBFQlzj3dChbnFLCTaHz/mRlifobEkyd7mUBsEQEVidkTHjBB7CqVeDehgwniTlmJ 2b+8QO6UEHjMJrHk933mCYxCs5CcOgvJqRC2lsT3R61AcQ4gW17i4HlZiLCmxLN7n9ghbG2J J+8usC5gZFvFKJSbmJmjm5lnppdYUJCTqpecn7uJERQd0+1EdzCeWWV1iFGAg1GJh/eGcF+E EGtiWXFl7iFGaQ4WJXHe6Iz+CCGB9MSS1OzU1ILUovii0pzU4kOMTBycUg2MRyaqVt+eOrsh r8Tj9/LVgQ8Fbp+42MWa4Rq12Tbk+TLZ4p8TG0wuz9ZZIuWau6dAhOnIy3mn05w3/lJ42jEx 4vH6X84c80y0Wz82TGjy1qzrfr/n2jFuTp1FMwWdPsuk2L2ONOKU26gU1PS77H98m93EIkPv 89nB8lE+8SWuy8+uX5d+ZvlaJZbijERDLeai4kQABY8mqm8CAAA= X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFrrMIsWRmVeSWpSXmKPExsUi2FD8Slestj/CYFabgMW6Pd/YLZYd28Fi 0Xm7i82B2WPShcfMHu/3XWXzWP3kB1sAcxSXTUpqTmZZapG+XQJXxt/e7UwFP64zVsy//Iat gXH/bsYuRg4OCQETiWlthV2MnECmmMSFe+vZuhi5OIQEDjFKzF55kwUkwSsgKPFj8j0wm1kg TGLym5OsILaQQBeTxPkraSC2sIC4xLszm5hBbDYBZYkV8z+wQ/TaSHze/J0NosZAYv/xhYwg NouAqsS5p1vB4pwCdhKN7z8zQ8zPkHjyZC8TiC0ioCIxe8IDJohdpRLvJnQwQdwsKzH7l9cE RoFZSK6bheQ6CFtL4vujVqA4B5AtL3HwvCxEWFPi2b1P7BC2tsSTdxdYFzCyrWIUKErNSaw0 0UssKMhJ1UvOz93ECA7zwvAdjP+WWR1iFOBgVOLhvSHcFyHEmlhWXJkLDCIOZiUR3mlV/RFC vCmJlVWpRfnxRaU5qcWHGCcyAv04kVlKNDkfGIV5JfGGJiYGJsbGZsbG5ibmtBRWEuet39kd ISSQnliSmp2aWpBaBHMUEwenVAPjvfeNZRNzeoWM/53tvHCq+fbyQ5v/r1zSIfXfwD62fypX bcl8m6YrDH5Rx1iv377rs8VT71LFdSZ3a9PLzy89vrWKv6aeUa2ydK5LrXlsyw3VTLG7uzVc ZC5KaNisikx68lZ3xdzcnLdsxb6q8w88zJ1bca2L0a5tv3RbxbbVbLI5L2/NWHZAiaU4I9FQ i7moOBEAadcwr+YCAAA= X-Content-Filtered-By: Mailman/MimeDel 2.1.21 Subject: Re: SNP_INIT while in TPL_NOTIFY X-BeenThere: edk2-devel@lists.01.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: EDK II Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 30 Jan 2017 17:51:19 -0000 Content-Type: text/plain; CHARSET=US-ASCII Content-Transfer-Encoding: 7BIT > On Jan 27, 2017, at 10:12 AM, 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". > 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 > https://lists.01.org/mailman/listinfo/edk2-devel