• Cristian Marussi's avatar
    firmware: arm_scmi: Introduce monotonically increasing tokens · 9ca5a183
    Cristian Marussi authored
    Tokens are sequence numbers embedded in the each SCMI message header: they
    are used to correlate commands with responses (and delayed responses), but
    their usage and policy of selection is entirely up to the caller (usually
    the OSPM agent), while they are completely opaque to the callee (i.e. SCMI
    platform) which merely copies them back from the command into the response
    message header.
    This also means that the platform does not, can not and should not enforce
    any kind of policy on received messages depending on the contained sequence
    number: platform can perfectly handle concurrent requests carrying the same
    identifiying token if that should happen.
    
    Moreover the platform is not required to produce in-order responses to
    agent requests, the only constraint in these regards is that in case of
    an asynchronous message the delayed response must be sent after the
    immediate response for the synchronous part of the command transaction.
    
    Currenly the SCMI stack of the OSPM agent selects a token for the egressing
    commands picking the lowest possible number which is not already in use by
    an existing in-flight transaction, which means, in other words, that we
    immediately reuse any token after its transaction has completed or it has
    timed out: this policy indeed does simplify management and lookup of tokens
    and associated xfers.
    
    Under the above assumptions and constraints, since there is really no state
    shared between the agent and the platform to let the platform know when a
    token and its associated message has timed out, the current policy of early
    reuse of tokens can easily lead to the situation in which a spurious or
    late received response (or delayed_response), related to an old stale and
    timed out transaction, can be wrongly associated to a newer valid in-flight
    xfer that just happens to have reused the same token.
    
    This misbehaviour on such late/spurious responses is more easily exposed on
    those transports that naturally have an higher level of parallelism in
    processing multiple concurrent in-flight messages.
    
    This commit introduces a new policy of selection of tokens for the OSPM
    agent: each new command transfer now gets the next available, monotonically
    increasing token, until tokens are exhausted and the counter rolls over.
    
    Such new policy mitigates the above issues with late/spurious responses
    since the tokens are now reused as late as possible (when they roll back
    ideally) and so it is much easier to identify such late/spurious responses
    to stale timed out transactions: this also helps in simplifying the
    specific transports implementation since stale transport messages can be
    easily identified and discarded early on in the rx path without the need
    to cross check their actual state with the core transport layer.
    This mitigation is even more effective when, as is usually the case, the
    maximum number of pending messages is capped by the platform to a much
    lower number than the whole possible range of tokens values (2^10).
    
    This internal policy change in the core SCMI transport layer is fully
    transparent to the specific transports so it has not and should not have
    any impact on the transports implementation.
    
    Link: https://lore.kernel.org/r/20210803131024.40280-5-cristian.marussi@arm.comSigned-off-by: default avatarCristian Marussi <cristian.marussi@arm.com>
    Signed-off-by: default avatarSudeep Holla <sudeep.holla@arm.com>
    9ca5a183
common.h 14.1 KB