From nobody Thu Jan 23 17:27:36 2025 X-Original-To: dev-commits-src-all@mlmmj.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mlmmj.nyi.freebsd.org (Postfix) with ESMTP id 4Yf7Dn1l5Cz5lDYd; Thu, 23 Jan 2025 17:27:37 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "R11" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4Yf7Dm2r2vz43gp; Thu, 23 Jan 2025 17:27:36 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1737653256; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=vU2yUHa+ePCct8czLydXqH1SU6DKVil0MNCdMDRfLQs=; b=yieXUp4To6rbST1ykTf+KOX6V3Dt2ABxb+G2Cz0CZhVT4nkuz1yu+G8sKagw5BohJnfITT LTYvWOy1Mxa2uivAtsrCF1e0021QJOVzZd9gSRHEDybs/7I9iMmti3OlQNGWT+jpgAxjvc /IVU74tEbIayPeKLQ22WSPwP+lUsgjJpR44YRVs4PQtrdyjsf7hk31rHk3SaYrk1vh2/Bw 09dwfmzucDFM/N7L9YI58ZAy3GKrt3fq/heUz700op6V1e7pyEKlp3n/pn7qezYqP1LhPT OkhBo2IBIueYRFEs/3Dem596YIQYepVOwEoCpkuPzRPj+U00QtwPAdIWcxfFTA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1737653256; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=vU2yUHa+ePCct8czLydXqH1SU6DKVil0MNCdMDRfLQs=; b=cpH4bFlwyr6iLqvSSwKf8+C+WdrRJgx02xxbzxLCZCVxPyWbevWj23/9YjFJBga08vBZGB /0RqI+za1Vy5GKnyPonC5WNOyXbsPd4Z/zMQyPYJVXG63Oq0p+0sY95kwVX6wkac6VenoC clUKJgBdnMLctI9X1iYS0PfbwWIjep9h8OjmPmzSQYUjimHfpQLKE+KX8zb+x7o21oRb3R 1I1+eeX8ypL/eMzccNKUpjsseMVzcZZC0WPhBOyu5Aw9rhf+HH/2KoAMEPZ4Y0PmShxYBQ VzEc9nOBN4moo0zru8D/PaDhiNFL6Ie1LwlCwUiBFQs6Rr01tCeqefrdTxRoZw== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1737653256; a=rsa-sha256; cv=none; b=Y7HLREFMjosBdweJSEIBeFoJcHdzizAGl66tgki+cPIod1CQcqIiqMFu+rJ3p1UYPP6lP4 PhcQ4UlJgo74XKbmWRHV8FktX0WP08iAudFWZWwDx8f/bxEjcDNDrYtP6cocgzffUBmwAo VgEpbn2mFRe1UqOxfTNbDKFzAihjV3o8XGdSitc0/No9jye6X7nlNvvqNGNihXKK8XfueT PMQ5c8dQnRseOzRJML1V5Cf3S++rq1sBEXY0E66mWuJUdLWQf3HXLYhhiBJL3rH4foglvq +5zNV2cA4WkMvQExcHP8TjlUhiYmCIxKXoh8LSA5FjjxDUHYL5Dirla58jeddA== ARC-Authentication-Results: i=1; mx1.freebsd.org; none Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 4Yf7Dm2QkNzp0v; Thu, 23 Jan 2025 17:27:36 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.18.1/8.18.1) with ESMTP id 50NHRaMQ022738; Thu, 23 Jan 2025 17:27:36 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.18.1/8.18.1/Submit) id 50NHRabp022734; Thu, 23 Jan 2025 17:27:36 GMT (envelope-from git) Date: Thu, 23 Jan 2025 17:27:36 GMT Message-Id: <202501231727.50NHRabp022734@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: Andrew Turner Subject: git: c508841dfc59 - main - scmi: Add scmi_token_reserve helper List-Id: Commit messages for all branches of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-all List-Help: List-Post: List-Subscribe: List-Unsubscribe: X-BeenThere: dev-commits-src-all@freebsd.org Sender: owner-dev-commits-src-all@FreeBSD.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: andrew X-Git-Repository: src X-Git-Refname: refs/heads/main X-Git-Reftype: branch X-Git-Commit: c508841dfc5923ef81ed8ea61da364fb20616bbf Auto-Submitted: auto-generated The branch main has been updated by andrew: URL: https://cgit.FreeBSD.org/src/commit/?id=c508841dfc5923ef81ed8ea61da364fb20616bbf commit c508841dfc5923ef81ed8ea61da364fb20616bbf Author: Cristian Marussi AuthorDate: 2025-01-23 13:24:06 +0000 Commit: Andrew Turner CommitDate: 2025-01-23 17:26:27 +0000 scmi: Add scmi_token_reserve helper During normal operation, the SCMI stack, upon each transmission attempt, takes care to automatically pick an appropriate, monotonically increasing, sequence number to fill-in the token field in the egressing message. This does not cope well with the alternative scenario in which, instead, a complete and fully formed message is provided upfront: in such a case the SCMI stack will have to use the already provided sequence number, embedded in the message, to track such transaction. Add a method to attempt to reserve a specific sequence number to be used when a fully firmed (raw) message is handled. Tested on: Arm Morello Board Reviewed by: andrew Sponsored by: Arm Ltd Pull Request: https://reviews.freebsd.org/D47424 Signed-off-by: Cristian Marussi --- sys/dev/firmware/arm/scmi.c | 48 ++++++++++++++++++++++++++++++++++++--------- 1 file changed, 39 insertions(+), 9 deletions(-) diff --git a/sys/dev/firmware/arm/scmi.c b/sys/dev/firmware/arm/scmi.c index 8104f4e10429..c24768a5668a 100644 --- a/sys/dev/firmware/arm/scmi.c +++ b/sys/dev/firmware/arm/scmi.c @@ -93,6 +93,7 @@ struct scmi_req { bool timed_out; bool use_polling; bool done; + bool is_raw; struct mtx mtx; LIST_ENTRY(scmi_req) next; int protocol_id; @@ -139,6 +140,7 @@ static void scmi_req_free_unlocked(struct scmi_softc *, static void scmi_req_get(struct scmi_softc *, struct scmi_req *); static void scmi_req_put(struct scmi_softc *, struct scmi_req *); static int scmi_token_pick(struct scmi_softc *); +static int scmi_token_reserve(struct scmi_softc *, uint16_t); static void scmi_token_release_unlocked(struct scmi_softc *, int); static int scmi_req_track_inflight(struct scmi_softc *, struct scmi_req *); @@ -376,6 +378,7 @@ scmi_req_free_unlocked(struct scmi_softc *sc, enum scmi_chan ch_idx, mtx_lock_spin(&rp->mtx); req->timed_out = false; req->done = false; + req->is_raw = false; refcount_init(&req->cnt, 0); LIST_INSERT_HEAD(&rp->head, req, next); mtx_unlock_spin(&rp->mtx); @@ -424,7 +427,6 @@ scmi_token_pick(struct scmi_softc *sc) */ next_msg_id = sc->trs->next_id++ & SCMI_HDR_TOKEN_BF; token = BIT_FFS_AT(SCMI_MAX_TOKEN, &sc->trs->avail_tokens, next_msg_id); - /* TODO Account for wrap-arounds and holes */ if (token != 0) BIT_CLR(SCMI_MAX_TOKEN, token - 1, &sc->trs->avail_tokens); mtx_unlock_spin(&sc->trs->mtx); @@ -440,6 +442,28 @@ scmi_token_pick(struct scmi_softc *sc) return ((int)(token - 1)); } +static int +scmi_token_reserve(struct scmi_softc *sc, uint16_t candidate) +{ + int token = -EBUSY, retries = 3; + + do { + mtx_lock_spin(&sc->trs->mtx); + if (BIT_ISSET(SCMI_MAX_TOKEN, candidate, &sc->trs->avail_tokens)) { + BIT_CLR(SCMI_MAX_TOKEN, candidate, &sc->trs->avail_tokens); + token = candidate; + sc->trs->next_id++; + } + mtx_unlock_spin(&sc->trs->mtx); + if (token == candidate || retries-- == 0) + break; + + pause("scmi_tk_reserve", hz); + } while (1); + + return (token); +} + static void scmi_token_release_unlocked(struct scmi_softc *sc, int token) { @@ -450,19 +474,23 @@ scmi_token_release_unlocked(struct scmi_softc *sc, int token) static int scmi_finalize_req(struct scmi_softc *sc, struct scmi_req *req) { - uint32_t header = 0; + if (!req->is_raw) + req->token = scmi_token_pick(sc); + else + req->token = scmi_token_reserve(sc, SCMI_MSG_TOKEN(req->msg.hdr)); - req->token = scmi_token_pick(sc); if (req->token < 0) return (EBUSY); - header = req->message_id; - header |= SCMI_MSG_TYPE_CMD << SCMI_HDR_MESSAGE_TYPE_S; - header |= req->protocol_id << SCMI_HDR_PROTOCOL_ID_S; - header |= req->token << SCMI_HDR_TOKEN_S; + if (!req->is_raw) { + req->msg.hdr = req->message_id; + req->msg.hdr |= SCMI_MSG_TYPE_CMD << SCMI_HDR_MESSAGE_TYPE_S; + req->msg.hdr |= req->protocol_id << SCMI_HDR_PROTOCOL_ID_S; + req->msg.hdr |= req->token << SCMI_HDR_TOKEN_S; + } - req->header = htole32(header); - req->msg.hdr = htole32(header); + /* Save requested header */ + req->header = req->msg.hdr; return (0); } @@ -670,6 +698,8 @@ scmi_msg_get(device_t dev, int tx_payld_sz, int rx_payld_sz) if (req == NULL) return (NULL); + req->is_raw = true; + return (&req->msg); }