]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
smb: smbdirect: introduce smbdirect_connection_grant_recv_credits()
authorStefan Metzmacher <metze@samba.org>
Fri, 17 Oct 2025 13:15:05 +0000 (15:15 +0200)
committerSteve French <stfrench@microsoft.com>
Thu, 16 Apr 2026 02:58:19 +0000 (21:58 -0500)
This is basically a copy of manage_credits_prior_sending() in the client
and the server.

It will replace both versions in future.

Cc: Steve French <smfrench@gmail.com>
Cc: Tom Talpey <tom@talpey.com>
Cc: Long Li <longli@microsoft.com>
Cc: Namjae Jeon <linkinjeon@kernel.org>
Cc: linux-cifs@vger.kernel.org
Cc: samba-technical@lists.samba.org
Signed-off-by: Stefan Metzmacher <metze@samba.org>
Acked-by: Namjae Jeon <linkinjeon@kernel.org>
Signed-off-by: Steve French <stfrench@microsoft.com>
fs/smb/common/smbdirect/smbdirect_connection.c

index 0eebc7f336f5ab32692d698f3215003c86703b23..40d830c58f195ebba7bca8b2f9b5ec54d6e6a811 100644 (file)
@@ -688,6 +688,44 @@ static void smbdirect_connection_idle_timer_work(struct work_struct *work)
        queue_work(sc->workqueue, &sc->idle.immediate_work);
 }
 
+__maybe_unused /* this is temporary while this file is included in others */
+static u16 smbdirect_connection_grant_recv_credits(struct smbdirect_socket *sc)
+{
+       int missing;
+       int available;
+       int new_credits;
+
+       if (atomic_read(&sc->recv_io.credits.count) >= sc->recv_io.credits.target)
+               return 0;
+
+       missing = (int)sc->recv_io.credits.target - atomic_read(&sc->recv_io.credits.count);
+       available = atomic_xchg(&sc->recv_io.credits.available, 0);
+       new_credits = min3((int)U16_MAX, missing, available);
+       if (new_credits <= 0) {
+               /*
+                * If credits are available, but not granted
+                * we need to re-add them again.
+                */
+               if (available)
+                       atomic_add(available, &sc->recv_io.credits.available);
+               return 0;
+       }
+
+       if (new_credits < available) {
+               /*
+                * Readd the remaining available again.
+                */
+               available -= new_credits;
+               atomic_add(available, &sc->recv_io.credits.available);
+       }
+
+       /*
+        * Remember we granted the credits
+        */
+       atomic_add(new_credits, &sc->recv_io.credits.count);
+       return new_credits;
+}
+
 __maybe_unused /* this is temporary while this file is included in others */
 static void smbdirect_connection_send_io_done(struct ib_cq *cq, struct ib_wc *wc)
 {