From nobody Wed Sep 21 14:01:24 2022 X-Original-To: dev-commits-src-branches@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 4MXg7S6fmtz4cY7M; Wed, 21 Sep 2022 14:01:24 +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 "R3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4MXg7S2FlKz49h8; Wed, 21 Sep 2022 14:01:24 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1663768884; 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=6aysD32zWnQC7FLV/R8g3yJFdz7HJzNmNCc3YAKrMDo=; b=tBcPFWzX05di5BYQn/U6vbIXIxfgAqnnaNTu1H5aXWJAc6zOqeG2KaDBVRURsx3KsRFsH4 clLUGTqMAyCodEF/slquCcjqF8AQPLKXH0cEFcL1oG/D7ZYZKdOofNMZkB9MKFMtQ585Nc oXoWQ2PgbzCd+Ol8VIgyCIaeS+OfMZ/AfXEGu0Bo5PE5pnZPE+QM4avqm3nCg+G22CFSFx zGUCI48NDU3FacmgUugOPICgmU53BLNLUOSp/+96izTD2aCbXI9ZoLy7Oty4DCnsCe59xq jpcjAhYesqdgHWmNRv3+vwYD8aTCbJPf2S43VSaQZA70AmZXcV4RKSJL5OyBJQ== 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 4MXg7S15drz14qV; Wed, 21 Sep 2022 14:01:24 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.16.1/8.16.1) with ESMTP id 28LE1OG2099995; Wed, 21 Sep 2022 14:01:24 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 28LE1OnG099994; Wed, 21 Sep 2022 14:01:24 GMT (envelope-from git) Date: Wed, 21 Sep 2022 14:01:24 GMT Message-Id: <202209211401.28LE1OnG099994@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org From: "Bjoern A. Zeeb" Subject: git: 855405e1750d - stable/13 - LinuxKPI: extend kfifo to be usable List-Id: Commits to the stable branches of the FreeBSD src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-branches List-Help: List-Post: List-Subscribe: List-Unsubscribe: Sender: owner-dev-commits-src-branches@freebsd.org X-BeenThere: dev-commits-src-branches@freebsd.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: bz X-Git-Repository: src X-Git-Refname: refs/heads/stable/13 X-Git-Reftype: branch X-Git-Commit: 855405e1750df5fcd003af127bfbe47bc0f35d04 Auto-Submitted: auto-generated ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1663768884; 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=6aysD32zWnQC7FLV/R8g3yJFdz7HJzNmNCc3YAKrMDo=; b=QkXp3hEto08dcyEWf8O3Nn3qTFDdbu5i5gYNuEnj+OiNX/gMzcg9vj+ksiLSgS3pjhuhmt OCUE2z3ypM+v+oD44CS8Pw3fjmYlAsUZLUaHo2ysjkFDuhWigXBNJqDej4yY5h0nI8CZwB dy5u+/I6un6tPgGGvLXbn2XcYqTjTMi/4rm2XegwO3E296gXrvTo2EXRTRvVpCLDZBXQSn vaMI5aduzpJ7nUhdK7L42pZ3KZYHXQe1jnqwMB1DgBaSs+WMTAYdPaPnCyx27vvI6Y/Nfg GO1k49rB+Yv/wk5Jw5ypHdsgqqCC4KfrIgjJA3zvPUyXydkXCS8xlczxUIJfUg== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1663768884; a=rsa-sha256; cv=none; b=fF+Gltq8EktupzdmCIYcz0ETPQW5Si4WXH+Hh4+Ipo941R2djzkNT3nR1QB++dTd1EZa4Y hj8UhK5/xq8A7Q01mpXYcXP+JOjotwiAP+8kZ5GBBb1Z7ggn78ycfQQF7RT11YKL5YqCh5 bx1vZdMio5iEqbPDk74Bf3Ld/xhquS/PDLzhHtyeEKYEX35RnpBomDehpL9ytoLikinl+A dHh+9xScjVtp/XNZvxTlz4QVwZ7FJZUIQS/D2ItfUDoCMD72j5CHhlc7Cqy+7lpc/EiQNB ScS2muM2RygWB+veEU8VFDRQjhHBDrA5nVFstbN4TSHwvWijKUmrDrq5ozHvsg== ARC-Authentication-Results: i=1; mx1.freebsd.org; none X-ThisMailContainsUnwantedMimeParts: N The branch stable/13 has been updated by bz: URL: https://cgit.FreeBSD.org/src/commit/?id=855405e1750df5fcd003af127bfbe47bc0f35d04 commit 855405e1750df5fcd003af127bfbe47bc0f35d04 Author: Bjoern A. Zeeb AuthorDate: 2022-07-16 00:36:55 +0000 Commit: Bjoern A. Zeeb CommitDate: 2022-09-21 11:46:45 +0000 LinuxKPI: extend kfifo to be usable Implement some basic kfifo pieces as needed by drivers. Reviewed by: wulf, hselasky Differential Revision: https://reviews.freebsd.org/D35829 (cherry picked from commit 4a7e8c7bd40bc39b3e247df069fa913f0197ea01) --- sys/compat/linuxkpi/common/include/linux/kfifo.h | 89 ++++++++++++++++++++++++ 1 file changed, 89 insertions(+) diff --git a/sys/compat/linuxkpi/common/include/linux/kfifo.h b/sys/compat/linuxkpi/common/include/linux/kfifo.h index 6ba1528d965c..d2f570781661 100644 --- a/sys/compat/linuxkpi/common/include/linux/kfifo.h +++ b/sys/compat/linuxkpi/common/include/linux/kfifo.h @@ -1,5 +1,6 @@ /*- * Copyright (c) 2021 Beckhoff Automation GmbH & Co. KG + * Copyright (c) 2022 Bjoern A. Zeeb * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions @@ -27,7 +28,95 @@ #ifndef _LINUXKPI_LINUX_KFIFO_H_ #define _LINUXKPI_LINUX_KFIFO_H_ +#include + +#include +#include + #define INIT_KFIFO(x) 0 #define DECLARE_KFIFO(x, y, z) +#define DECLARE_KFIFO_PTR(_name, _type) \ + struct kfifo_ ## _name { \ + size_t total; \ + size_t count; \ + size_t first; \ + size_t last; \ + _type *head; \ + } _name + +#define kfifo_len(_kf) \ +({ \ + (_kf)->count; \ +}) + +#define kfifo_is_empty(_kf) \ +({ \ + ((_kf)->count == 0) ? true : false; \ +}) + +#define kfifo_is_full(_kf) \ +({ \ + ((_kf)->count == (_kf)->total) ? true : false; \ +}) + +#define kfifo_put(_kf, _e) \ +({ \ + bool _rc; \ + \ + /* Would overflow. */ \ + if (kfifo_is_full(_kf)) { \ + _rc = false; \ + } else { \ + (_kf)->head[(_kf)->last] = (_e); \ + (_kf)->count++; \ + (_kf)->last++; \ + if ((_kf)->last > (_kf)->total) \ + (_kf)->last = 0; \ + _rc = true; \ + } \ + \ + _rc; \ +}) + +#define kfifo_get(_kf, _e) \ +({ \ + bool _rc; \ + \ + if (kfifo_is_empty(_kf)) { \ + _rc = false; \ + } else { \ + *(_e) = (_kf)->head[(_kf)->first]; \ + (_kf)->count--; \ + (_kf)->first++; \ + if ((_kf)->first > (_kf)->total) \ + (_kf)->first = 0; \ + _rc = true; \ + } \ + \ + _rc; \ +}) + +#define kfifo_alloc(_kf, _s, _gfp) \ +({ \ + int _error; \ + \ + (_kf)->head = kmalloc(sizeof(__typeof(*(_kf)->head)) * (_s), _gfp); \ + if ((_kf)->head == NULL) \ + _error = ENOMEM; \ + else { \ + (_kf)->total = (_s); \ + _error = 0; \ + } \ + \ + _error; \ +}) + +#define kfifo_free(_kf) \ +({ \ + kfree((_kf)->head); \ + (_kf)->head = NULL; \ + (_kf)->total = (_kf)->count = (_kf)->first = (_kf)->last = 0; \ +}) + #endif /* _LINUXKPI_LINUX_KFIFO_H_*/