From nobody Thu Aug 18 20:29:25 2022 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 4M7xLt0GSgz4ZF3R; Thu, 18 Aug 2022 20:29:26 +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 4M7xLs6shDz3f07; Thu, 18 Aug 2022 20:29:25 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1660854566; 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=f1zA/XumsaHvpz+cdpvffmW6P3iQVKmItH4KsIWsX1o=; b=MALSFQZf+gvJZw5pZDWZ44U+tJQgv6pWYO5tWkP2YUfQHTiPo2dYZ48+6xkOhePVFk4Ay2 gZhHPC5H9zAWxW+32BWZFQk0HRZ3nAVe9yNEgNZkDvJ8j0pEgsMkBnEqg3L2IQZ6rvb41b Bu1YABM0JTVeN9j25lIWJ8cDpADJzXrOnLbd173iQA7k9shiaYKHhJ2OtQsk/748zDAgxW /UjulkhjgxqY/LygeP5W4G+oFPiie9DiTFwNuiFfKlVE+67bgvFwB4AMwAxbuFkYaIw7Ct iccyHMhz0vjIM3EleH7imAD90JlDybNaqRSj9wILyKft/k4/coPKejxi788Vpw== 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 4M7xLs5gpfzRnl; Thu, 18 Aug 2022 20:29:25 +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 27IKTPm9074740; Thu, 18 Aug 2022 20:29:25 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 27IKTPwk074739; Thu, 18 Aug 2022 20:29:25 GMT (envelope-from git) Date: Thu, 18 Aug 2022 20:29:25 GMT Message-Id: <202208182029.27IKTPwk074739@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: "Bjoern A. Zeeb" Subject: git: 4a7e8c7bd40b - main - LinuxKPI: extend kfifo to be usable 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: Sender: owner-dev-commits-src-all@freebsd.org X-BeenThere: dev-commits-src-all@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/main X-Git-Reftype: branch X-Git-Commit: 4a7e8c7bd40bc39b3e247df069fa913f0197ea01 Auto-Submitted: auto-generated ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1660854566; 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=f1zA/XumsaHvpz+cdpvffmW6P3iQVKmItH4KsIWsX1o=; b=t4TseaS2u7qhC7AwTqmEe834ulVsRcQLFi6mcZJy4m5xIxAeDtoEBZhtoDvETU5cUZ0XnG 2US+Jx3meuJwGUWdQFO6ZU878bsmV8Sir8y/e0xOi/gTxs8qwT2gkSgN4aaEKf4uGl93jr W9gpRFa3w5W+DXZpkZTCMI83GZKnhOPCxleRHGjuh3GuGZG28RcW4+V71E9rSO7Cx9dVij +3Ue2dCq9Kjmr0mL7dL3GwvoWtFanYhIOwpYZqjyB9wQFQbjDqtDELel0cPu2dCLCiIFCJ tUDOAg9dXFlkJRacnjUMxG5vY8L39pfP5oLn4VTxOv+n379mqeE39lArmPJS+g== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1660854566; a=rsa-sha256; cv=none; b=MWLw3LggcfwJDx6RnnlBmm+WmiLcndeG9ObArR82HFFiD6LBnEgSH5pnQhbgpZoZavbxYB K/tOi8WBEfirJRpJKiiKbf8oYdm6eohg42MSSDDuq38sGM0+oggbYt8DoAKS3c3wdX0H0r eGErI7m8id9qmg/thjpNDSbC2HEWajTabQmwaJA01s0Fr3+Scu4ZaDXiBX6vhrUpSXEugc rS3V2Sm5+4v9a3ZrrbCDrNQDJUIH0UfFv7FJhwFvCACiXk2eB2P+OZCWqUqQXgvqpD8U7K gVs/ToVIB8otWd3p9WWe7oQIK9511mRtNZHtu/GBD1wXC6e+tCVLinsT7zXYeA== ARC-Authentication-Results: i=1; mx1.freebsd.org; none X-ThisMailContainsUnwantedMimeParts: N The branch main has been updated by bz: URL: https://cgit.FreeBSD.org/src/commit/?id=4a7e8c7bd40bc39b3e247df069fa913f0197ea01 commit 4a7e8c7bd40bc39b3e247df069fa913f0197ea01 Author: Bjoern A. Zeeb AuthorDate: 2022-07-16 00:36:55 +0000 Commit: Bjoern A. Zeeb CommitDate: 2022-08-18 20:26:20 +0000 LinuxKPI: extend kfifo to be usable Implement some basic kfifo pieces as needed by drivers. MFC after: 2 weeks Reviewed by: wulf, hselasky Differential Revision: https://reviews.freebsd.org/D35829 --- 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_*/