* [PATCH v6 02/11] exec: add dirfd parameter to kernel_execve()
From: Thomas Weißschuh @ 2026-05-04 9:33 UTC (permalink / raw)
To: Nathan Chancellor, Andrew Morton, Willy Tarreau,
Thomas Weißschuh, Brendan Higgins, Shuah Khan,
Jonathan Corbet, Nicolas Schier, Kees Cook, Alexander Viro,
Christian Brauner, Jan Kara, Christoph Hellwig, Luis Chamberlain,
David Gow, Rae Moar
Cc: linux-kbuild, linux-kernel, linux-kselftest, kunit-dev, linux-doc,
workflows, linux-mm, linux-fsdevel, Thomas Weißschuh,
Christophe Leroy, Nicolas Schier
In-Reply-To: <20260504-kunit-kselftests-v6-0-712d3d526d97@linutronix.de>
Allow callers to specify the directory against which to resolve the
program filename. Enables running executables from private mounts.
Signed-off-by: Thomas Weißschuh <thomas.weissschuh@linutronix.de>
---
fs/exec.c | 4 ++--
include/linux/binfmts.h | 2 +-
init/main.c | 2 +-
kernel/umh.c | 2 +-
4 files changed, 5 insertions(+), 5 deletions(-)
diff --git a/fs/exec.c b/fs/exec.c
index ba12b4c466f6..affae4b4f6f6 100644
--- a/fs/exec.c
+++ b/fs/exec.c
@@ -1846,7 +1846,7 @@ static int do_execveat_common(int fd, struct filename *filename,
return bprm_execve(bprm);
}
-int kernel_execve(const char *kernel_filename,
+int kernel_execve(int dirfd, const char *kernel_filename,
const char *const *argv, const char *const *envp)
{
int retval;
@@ -1856,7 +1856,7 @@ int kernel_execve(const char *kernel_filename,
return -EINVAL;
CLASS(filename_kernel, filename)(kernel_filename);
- CLASS(bprm, bprm)(AT_FDCWD, filename, 0);
+ CLASS(bprm, bprm)(dirfd, filename, 0);
if (IS_ERR(bprm))
return PTR_ERR(bprm);
diff --git a/include/linux/binfmts.h b/include/linux/binfmts.h
index 65abd5ab8836..04e2b7a85b2b 100644
--- a/include/linux/binfmts.h
+++ b/include/linux/binfmts.h
@@ -144,7 +144,7 @@ int copy_string_kernel(const char *arg, struct linux_binprm *bprm);
extern void set_binfmt(struct linux_binfmt *new);
extern ssize_t read_code(struct file *, unsigned long, loff_t, size_t);
-int kernel_execve(const char *filename,
+int kernel_execve(int dirfd, const char *filename,
const char *const *argv, const char *const *envp);
#endif /* _LINUX_BINFMTS_H */
diff --git a/init/main.c b/init/main.c
index 96f93bb06c49..551d03681234 100644
--- a/init/main.c
+++ b/init/main.c
@@ -1511,7 +1511,7 @@ static int run_init_process(const char *init_filename)
pr_debug(" with environment:\n");
for (p = envp_init; *p; p++)
pr_debug(" %s\n", *p);
- return kernel_execve(init_filename, argv_init, envp_init);
+ return kernel_execve(AT_FDCWD, init_filename, argv_init, envp_init);
}
static int try_to_run_init_process(const char *init_filename)
diff --git a/kernel/umh.c b/kernel/umh.c
index cffda97d961c..bab134fa8c36 100644
--- a/kernel/umh.c
+++ b/kernel/umh.c
@@ -106,7 +106,7 @@ static int call_usermodehelper_exec_async(void *data)
commit_creds(new);
wait_for_initramfs();
- retval = kernel_execve(sub_info->path,
+ retval = kernel_execve(AT_FDCWD, sub_info->path,
(const char *const *)sub_info->argv,
(const char *const *)sub_info->envp);
out:
--
2.53.0
^ permalink raw reply related
* [PATCH v6 01/11] kbuild: doc: add label for userprogs section
From: Thomas Weißschuh @ 2026-05-04 9:33 UTC (permalink / raw)
To: Nathan Chancellor, Andrew Morton, Willy Tarreau,
Thomas Weißschuh, Brendan Higgins, Shuah Khan,
Jonathan Corbet, Nicolas Schier, Kees Cook, Alexander Viro,
Christian Brauner, Jan Kara, Christoph Hellwig, Luis Chamberlain,
David Gow, Rae Moar
Cc: linux-kbuild, linux-kernel, linux-kselftest, kunit-dev, linux-doc,
workflows, linux-mm, linux-fsdevel, Thomas Weißschuh,
Christophe Leroy, Nicolas Schier, Masahiro Yamada
In-Reply-To: <20260504-kunit-kselftests-v6-0-712d3d526d97@linutronix.de>
Some upcoming documentation will link directly to the userprogs section.
Add a label to the section so it can be referenced.
Signed-off-by: Thomas Weißschuh <thomas.weissschuh@linutronix.de>
Reviewed-by: Nicolas Schier <n.schier@avm.de>
Acked-by: Masahiro Yamada <masahiroy@kernel.org>
---
Documentation/kbuild/makefiles.rst | 2 ++
1 file changed, 2 insertions(+)
diff --git a/Documentation/kbuild/makefiles.rst b/Documentation/kbuild/makefiles.rst
index 24a4708d26e8..6e54ad4cfecb 100644
--- a/Documentation/kbuild/makefiles.rst
+++ b/Documentation/kbuild/makefiles.rst
@@ -891,6 +891,8 @@ This is possible in two ways:
This will tell kbuild to build lxdialog even if not referenced in
any rule.
+.. _kbuild_userprogs:
+
Userspace Program support
=========================
--
2.53.0
^ permalink raw reply related
* [PATCH v6 00/11] kunit: Introduce UAPI testing framework
From: Thomas Weißschuh @ 2026-05-04 9:33 UTC (permalink / raw)
To: Nathan Chancellor, Andrew Morton, Willy Tarreau,
Thomas Weißschuh, Brendan Higgins, Shuah Khan,
Jonathan Corbet, Nicolas Schier, Kees Cook, Alexander Viro,
Christian Brauner, Jan Kara, Christoph Hellwig, Luis Chamberlain,
David Gow, Rae Moar
Cc: linux-kbuild, linux-kernel, linux-kselftest, kunit-dev, linux-doc,
workflows, linux-mm, linux-fsdevel, Thomas Weißschuh,
Christophe Leroy, Nicolas Schier, Masahiro Yamada
Currently testing of userspace and in-kernel API use two different
frameworks. kselftests for the userspace ones and Kunit for the
in-kernel ones. Besides their different scopes, both have different
strengths and limitations:
Kunit:
* Tests are normal kernel code.
* They use the regular kernel toolchain.
* They can be packaged and distributed as modules conveniently.
Kselftests:
* Tests are normal userspace code
* They need a userspace toolchain.
A kernel cross toolchain is likely not enough.
* A fair amout of userland is required to run the tests,
which means a full distro or handcrafted rootfs.
* There is no way to conveniently package and run kselftests with a
given kernel image.
* The kselftests makefiles are not as powerful as regular kbuild.
For example they are missing proper header dependency tracking or more
complex compiler option modifications.
Therefore kunit is much easier to run against different kernel
configurations and architectures.
This series aims to combine kselftests and kunit, avoiding both their
limitations. It works by compiling the userspace kselftests as part of
the regular kernel build, embedding them into the kunit kernel or module
and executing them from there. If the kernel toolchain is not fit to
produce userspace because of a missing libc, the kernel's own nolibc can
be used instead.
The structured TAP output from the kselftest is integrated into the
kunit KTAP output transparently, the kunit parser can parse the combined
logs together.
Further room for improvements:
* Call each test in its completely dedicated namespace
* Handle additional test files besides the test executable through
archives. CPIO, cramfs, etc.
* Expose the blobs in debugfs
* Provide some convience wrappers around compat userprogs
* Figure out a migration path/coexistence solution for
kunit UAPI and tools/testing/selftests/
Output from the kunit example testcase, note the output of
"example_uapi_tests".
$ ./tools/testing/kunit/kunit.py run --kunitconfig lib/kunit example
...
Running tests with:
$ .kunit/linux kunit.filter_glob=example kunit.enable=1 mem=1G console=tty kunit_shutdown=halt
[11:53:53] ================== example (10 subtests) ===================
[11:53:53] [PASSED] example_simple_test
[11:53:53] [SKIPPED] example_skip_test
[11:53:53] [SKIPPED] example_mark_skipped_test
[11:53:53] [PASSED] example_all_expect_macros_test
[11:53:53] [PASSED] example_static_stub_test
[11:53:53] [PASSED] example_static_stub_using_fn_ptr_test
[11:53:53] [PASSED] example_priv_test
[11:53:53] =================== example_params_test ===================
[11:53:53] [SKIPPED] example value 3
[11:53:53] [PASSED] example value 2
[11:53:53] [PASSED] example value 1
[11:53:53] [SKIPPED] example value 0
[11:53:53] =============== [PASSED] example_params_test ===============
[11:53:53] [PASSED] example_slow_test
[11:53:53] ======================= (4 subtests) =======================
[11:53:53] [PASSED] procfs
[11:53:53] [PASSED] userspace test 2
[11:53:53] [SKIPPED] userspace test 3: some reason
[11:53:53] [PASSED] userspace test 4
[11:53:53] ================ [PASSED] example_uapi_test ================
[11:53:53] ===================== [PASSED] example =====================
[11:53:53] ============================================================
[11:53:53] Testing complete. Ran 16 tests: passed: 11, skipped: 5
[11:53:53] Elapsed time: 67.543s total, 1.823s configuring, 65.655s building, 0.058s running
---
Changes in v6:
- Use usermode helper framework
- Trim now unnecessary new module exports
- Report unhandled output line
- Add SUPERH to ARCH_HAS_NOLIBC
- Remove non-integral patches submitted elsewhere
- Drop CC_CAN_LINK_STATIC support. It is based on CC_CAN_LINK which is
currently being reworked.
- Use more cleanup helpers
- Split stdout/stderr forwarding into its own patch
- Link to v5: https://lore.kernel.org/r/20250717-kunit-kselftests-v5-0-442b711cde2e@linutronix.de
Changes in v5:
- Initialize output variable of kernel_wait()
- Fix .incbin with in-tree builds
- Keep requirement of KTAP tests to have a number which was removed accidentally
- Only synthesize KTAP subtest failure if the outer one is TestStatus.FAILURE
- Use -I instead of -isystem in NOLIBC_USERCFLAGS to populate dependency files
- +To filesystem developers to all patches
- +To Luis Chamberlain for discussions about usage of usermodehelper
(see patches 6 and 12)
- Link to v4: https://lore.kernel.org/r/20250626-kunit-kselftests-v4-0-48760534fef5@linutronix.de
Changes in v4:
- Move Kconfig.nolibc from tools/ to init/
- Drop generic userprogs nolibc integration
- Drop generic blob framework
- Pick up review tags from David
- Extend new kunit TAP parser tests
- Add MAINTAINERS entry
- Allow CONFIG_KUNIT_UAPI=m
- Split /proc validation into dedicated UAPI test
- Trim recipient list a bit
- Use KUNIT_FAIL_AND_ABORT() over KUNIT_FAIL()
- Link to v3: https://lore.kernel.org/r/20250611-kunit-kselftests-v3-0-55e3d148cbc6@linutronix.de
Changes in v3:
- Reintroduce CONFIG_CC_CAN_LINK_STATIC
- Enable CONFIG_ARCH_HAS_NOLIBC for m68k and SPARC
- Properly handle 'clean' target for userprogs
- Use ramfs over tmpfs to reduce dependencies
- Inherit userprogs byte order and ABI from kernel
- Drop now unnecessary "#ifndef NOLIBC"
- Pick up review tags
- Drop usage of __private in blob.h,
sparse complains and it is not really necessary
- Fix execution on loongarch when using clang
- Drop userprogs libgcc handling, it was ugly and is not yet necessary
- Link to v2: https://lore.kernel.org/r/20250407-kunit-kselftests-v2-0-454114e287fd@linutronix.de
Changes in v2:
- Rebase onto v6.15-rc1
- Add documentation and kernel docs
- Resolve invalid kconfig breakages
- Drop already applied patch "kbuild: implement CONFIG_HEADERS_INSTALL for Usermode Linux"
- Drop userprogs CONFIG_WERROR integration, it doesn't need to be part of this series
- Replace patch prefix "kconfig" with "kbuild"
- Rename kunit_uapi_run_executable() to kunit_uapi_run_kselftest()
- Generate private, conflict-free symbols in the blob framework
- Handle kselftest exit codes
- Handle SIGABRT
- Forward output also to kunit debugfs log
- Install a fd=0 stdin filedescriptor
- Link to v1: https://lore.kernel.org/r/20250217-kunit-kselftests-v1-0-42b4524c3b0a@linutronix.de
To: Nathan Chancellor <nathan@kernel.org>
To: Andrew Morton <akpm@linux-foundation.org>
To: Willy Tarreau <w@1wt.eu>
To: Thomas Weißschuh <linux@weissschuh.net>
To: Brendan Higgins <brendan.higgins@linux.dev>
To: David Gow <davidgow@google.com>
To: Rae Moar <rmoar@google.com>
To: Shuah Khan <shuah@kernel.org>
To: Jonathan Corbet <corbet@lwn.net>
To: Nicolas Schier <nicolas.schier@linux.dev>
Cc: Christophe Leroy <christophe.leroy@csgroup.eu>
Cc: linux-kbuild@vger.kernel.org
Cc: linux-kernel@vger.kernel.org
Cc: linux-kselftest@vger.kernel.org
Cc: kunit-dev@googlegroups.com
Cc: linux-doc@vger.kernel.org
Cc: workflows@vger.kernel.org
To: Kees Cook <kees@kernel.org>
To: Alexander Viro <viro@zeniv.linux.org.uk>
To: Christian Brauner <brauner@kernel.org>
To: Jan Kara <jack@suse.cz>
To: Christoph Hellwig <hch@lst.de>
To: Luis Chamberlain <mcgrof@kernel.org>
Cc: linux-mm@kvack.org
Cc: linux-fsdevel@vger.kernel.org
Cc: Nicolas Schier <n.schier@avm.de>
Signed-off-by: Thomas Weißschuh <thomas.weissschuh@linutronix.de>
---
Thomas Weißschuh (11):
kbuild: doc: add label for userprogs section
exec: add dirfd parameter to kernel_execve()
umh: add dirfd parameter
mount: add support for __free(kern_unmount)
init: add nolibc build support
kunit: qemu_configs: loongarch: Enable LSX/LSAX
kunit: Introduce UAPI testing framework
kunit: uapi: Forward test executable output to KUnit log
kunit: uapi: Add example for UAPI tests
kunit: uapi: Introduce preinit executable
kunit: uapi: Validate usability of /proc
Documentation/dev-tools/kunit/api/index.rst | 5 +
Documentation/dev-tools/kunit/api/uapi.rst | 14 +
Documentation/kbuild/makefiles.rst | 2 +
MAINTAINERS | 11 +
fs/coredump.c | 2 +-
fs/exec.c | 4 +-
include/kunit/uapi.h | 77 ++++++
include/linux/binfmts.h | 2 +-
include/linux/mount.h | 2 +
include/linux/umh.h | 3 +-
init/Kconfig | 2 +
init/Kconfig.nolibc | 16 ++
init/Makefile.nolibc | 13 +
init/main.c | 2 +-
kernel/module/kmod.c | 2 +-
kernel/umh.c | 9 +-
lib/kobject_uevent.c | 2 +-
lib/kunit/Kconfig | 16 ++
lib/kunit/Makefile | 26 ++
lib/kunit/kunit-example-test.c | 15 ++
lib/kunit/kunit-example-uapi.c | 22 ++
lib/kunit/kunit-test-uapi.c | 51 ++++
lib/kunit/kunit-test.c | 24 +-
lib/kunit/kunit-uapi.c | 351 ++++++++++++++++++++++++++
lib/kunit/uapi-preinit.c | 68 +++++
security/keys/request_key.c | 2 +-
tools/testing/kunit/qemu_configs/loongarch.py | 2 +
27 files changed, 732 insertions(+), 13 deletions(-)
---
base-commit: 813d26ba48f9e3909d39966857421500faef508a
change-id: 20241015-kunit-kselftests-56273bc40442
Best regards,
--
Thomas Weißschuh <thomas.weissschuh@linutronix.de>
^ permalink raw reply
* htmldocs: Documentation/admin-guide/reporting-issues.rst:1390: WARNING: Title underline too short.
From: kernel test robot @ 2026-05-04 8:57 UTC (permalink / raw)
To: Felipe Matarazzo; +Cc: oe-kbuild-all, 0day robot, linux-doc
tree: https://github.com/intel-lab-lkp/linux/commits/Felipe-Matarazzo/docs-fix-typos-in-reporting-issues-rst/20260504-100627
head: 87c6043bc64dbd3613715bed7671c5b8e586a71e
commit: 87c6043bc64dbd3613715bed7671c5b8e586a71e docs: fix typos in reporting-issues.rst
date: 7 hours ago
compiler: clang version 20.1.8 (https://github.com/llvm/llvm-project 87f0227cb60147a26a1eeb4fb06e3b505e9c7261)
docutils: docutils (Docutils 0.21.2, Python 3.13.5, on linux)
reproduce: (https://download.01.org/0day-ci/archive/20260504/202605041002.NG14fe8J-lkp@intel.com/reproduce)
If you fix the issue in a separate patch/commit (i.e. not just a new version of
the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <lkp@intel.com>
| Closes: https://lore.kernel.org/oe-kbuild-all/202605041002.NG14fe8J-lkp@intel.com/
All warnings (new ones prefixed by >>):
WARNING: Documentation/ABI/testing/sysfs-class-reboot-mode-reboot_modes:36: abi_sys_class_reboot_mode_driver_reboot_modes doesn't have a description
WARNING: /sys/bus/usb/devices/<busnum>-<devnum>:<config num>.<interface num>/<hid-bus>:<vendor-id>:<product-id>.<num>/os_mode is defined 2 times: Documentation/ABI/testing/sysfs-driver-hid-lenovo-go:364; Documentation/ABI/testing/sysfs-driver-hid-lenovo-go-s:234
WARNING: /sys/bus/usb/devices/<busnum>-<devnum>:<config num>.<interface num>/<hid-bus>:<vendor-id>:<product-id>.<num>/os_mode_index is defined 2 times: Documentation/ABI/testing/sysfs-driver-hid-lenovo-go:373; Documentation/ABI/testing/sysfs-driver-hid-lenovo-go-s:243
WARNING: /sys/bus/usb/devices/<busnum>-<devnum>:<config num>.<interface num>/<hid-bus>:<vendor-id>:<product-id>.<num>/touchpad/enabled is defined 2 times: Documentation/ABI/testing/sysfs-driver-hid-lenovo-go:636; Documentation/ABI/testing/sysfs-driver-hid-lenovo-go-s:252
WARNING: /sys/bus/usb/devices/<busnum>-<devnum>:<config num>.<interface num>/<hid-bus>:<vendor-id>:<product-id>.<num>/touchpad/enabled_index is defined 2 times: Documentation/ABI/testing/sysfs-driver-hid-lenovo-go:645; Documentation/ABI/testing/sysfs-driver-hid-lenovo-go-s:261
>> Documentation/admin-guide/reporting-issues.rst:1390: WARNING: Title underline too short.
vim +1390 Documentation/admin-guide/reporting-issues.rst
3e544d72dfc8bb Thorsten Leemhuis 2020-12-04 1388
87c6043bc64dbd Felipe Matarazzo 2026-05-03 1389 Inquiries and testing requests
3e544d72dfc8bb Thorsten Leemhuis 2020-12-04 @1390 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~
3e544d72dfc8bb Thorsten Leemhuis 2020-12-04 1391
--
0-DAY CI Kernel Test Service
https://github.com/intel/lkp-tests/wiki
^ permalink raw reply
* Re: [PATCH net-next v2 1/2] dpll: move fractional-frequency-offset-ppt under pin-parent-device
From: Jiri Pirko @ 2026-05-04 8:48 UTC (permalink / raw)
To: Ivan Vecera
Cc: netdev, Andrew Lunn, Arkadiusz Kubalewski, David S. Miller,
Donald Hunter, Eric Dumazet, Jakub Kicinski, Jonathan Corbet,
Leon Romanovsky, Mark Bloch, Michal Schmidt, Paolo Abeni,
Pasi Vaananen, Petr Oros, Prathosh Satish, Saeed Mahameed,
Shuah Khan, Simon Horman, Tariq Toukan, Vadim Fedorenko,
linux-doc, linux-kernel, linux-rdma
In-Reply-To: <20260430173611.3312596-2-ivecera@redhat.com>
Thu, Apr 30, 2026 at 07:36:10PM +0200, ivecera@redhat.com wrote:
>Move the fractional-frequency-offset-ppt attribute from the top-level
>pin attributes into the pin-parent-device nested attribute set. This
>makes it consistent with phase-offset which is already per-parent and
>clarifies that FFO PPT represents the frequency difference between
>a pin and its parent DPLL device.
>
>The top-level fractional-frequency-offset attribute (in PPM) remains
>unchanged for backward compatibility.
That is odd. The ppt one was added just for higher precision but was
semantically the same. Now you change it. Could you still treat both the
same?
>
>Distinguish the two contexts in the ffo_get callback by passing
>dpll=NULL for the top-level (rx vs tx symbol rate) call and a valid
>dpll pointer for the nested (pin vs parent DPLL) call. Update mlx5
>and zl3073x drivers to return -ENODATA for the nested context they
>do not yet support.
>
>Add documentation for both FFO attributes to dpll.rst.
>
[..]
^ permalink raw reply
* Re: [PATCH v13 3/4] gpio: rpmsg: add generic rpmsg GPIO driver
From: Beleswar Prasad Padhi @ 2026-05-04 8:17 UTC (permalink / raw)
To: Arnaud POULIQUEN, Mathieu Poirier
Cc: Shenwei Wang, Andrew Lunn, Linus Walleij, Bartosz Golaszewski,
Jonathan Corbet, Rob Herring, Krzysztof Kozlowski, Conor Dooley,
Bjorn Andersson, Frank Li, Sascha Hauer, Shuah Khan,
linux-gpio@vger.kernel.org, linux-doc@vger.kernel.org,
linux-kernel@vger.kernel.org, Pengutronix Kernel Team,
Fabio Estevam, Peng Fan, devicetree@vger.kernel.org,
linux-remoteproc@vger.kernel.org, imx@lists.linux.dev,
linux-arm-kernel@lists.infradead.org, dl-linux-imx,
Bartosz Golaszewski
In-Reply-To: <4c526816-b127-43e7-86e9-eee4dc1152bc@foss.st.com>
Hi Arnaud,
On 30/04/26 22:10, Arnaud POULIQUEN wrote:
>
>
> On 4/30/26 14:56, Beleswar Prasad Padhi wrote:
>> Hello Arnaud,
>>
>> On 30/04/26 13:05, Arnaud POULIQUEN wrote:
>>> Hello,
>>>
>>> On 4/29/26 21:20, Mathieu Poirier wrote:
>>>> On Wed, 29 Apr 2026 at 12:07, Padhi, Beleswar <b-padhi@ti.com> wrote:
>>>>>
>>>>> Hi Mathieu,
>>>>>
>>>>> On 4/29/2026 11:03 PM, Mathieu Poirier wrote:
>>>>>> On Wed, 29 Apr 2026 at 10:53, Shenwei Wang <shenwei.wang@nxp.com> wrote:
>>>>
[...]
>>>>> My mental model looks like this for the complete picture:
>>>>>
>>>>> 1. namespace/channel#1 = rpmsg-io
>>>>> a. ept1 -> gpio-controller@1
>>>>> b. ept2 -> gpio-controller@2
>>>>>
>>>>
>>>> I've asked for one endpoint per GPIO controller since the very
>>>> beginning. I don't yet have a strong opinion on whether to use one
>>>> namespace request per GPIO controller or a single request that spins
>>>> off multiple endpoints. I'll have to look at your link and reflect on
>>>> that. Regardless of how we proceed on that front, multiplexing needs
>>>> to happen at the endpoint level rather than the packet level. This is
>>>> the only way this work can move forward.
>>>>
>>>
>>> I would be more in favor of Mathieu’s proposal: “An endpoint is created with every namespace request.”
>>>
>>> If the endpoint is created only on the Linux side, how do we match the Linux endpoint address with the local port field on the remote side?
>>
>>
>> Simply by sending a message to the remote containing the newly created
>> endpoint and the port idx. Note that is this done just one time, after this
>> Linux need not have the port field in the message everytime its sending
>> a message.
>>
>>>
>>> With a multi-namespace approach, the namespace could be rpmsg-io-[addr], where [addr] corresponds to the GPIO controller address in the DT. This would:
>>
>>
>> You will face the same problem in this case also that you asked above:
>> "how do we match the Linux endpoint address with the local port field
>> on the remote side?"
>
> Sorry I probably introduced confusion here
> my sentence should be;
> With a multi-namespace approach, the namespace could be rpmsg-io-[port],
> where [port] corresponds to the GPIO controller port in the DT.
>
>
> For instance:
>
> rpmsg {
> rpmsg-io {
> #address-cells = <1>;
> #size-cells = <0>;
>
> gpio@25 {
> compatible = "rpmsg-gpio";
> reg = <25>;
> gpio-controller;
> #gpio-cells = <2>;
> #interrupt-cells = <2>;
> interrupt-controller;
> };
>
> gpio@32 {
> compatible = "rpmsg-gpio";
> reg = <32>;
> gpio-controller;
> #gpio-cells = <2>;
> #interrupt-cells = <2>;
> interrupt-controller;
> };
> };
> };
>
> rpmsg-io-25 would match with gpio@25
> rpmsg-io-32 would match with gpio@32
>
>
>>
>> Because the endpoint that is created on a namespace request is also
>> dynamic in nature. How will the remote know which endpoint addr
>> Linux allocated for a namespace that it announced?
>>
>> As an example/PoC, I created a firmware example which announces
>> 2 name services to Linux, one is the standard "rpmsg_chrdev" and
>> the other is a TI specific name service "ti.ipc4.ping-pong". You can
>> see it created 2 different addresses (0x400 and 0x401) for each of
>> the name service request from the same firmware:
>>
>> root@j784s4-evm:~# dmesg | grep virtio0 | grep -i channel
>> [ 9.290275] virtio_rpmsg_bus virtio0: creating channel ti.ipc4.ping-pong addr 0xd
>> [ 9.311230] virtio_rpmsg_bus virtio0: creating channel rpmsg_chrdev addr 0xe
>> [ 9.496645] rpmsg_chrdev virtio0.rpmsg_chrdev.-1.14: DEBUG: Channel formed from src = 0x400 to dst = 0xe
>> [ 9.707255] rpmsg_client_sample virtio0.ti.ipc4.ping-pong.-1.13: new channel: 0x401 -> 0xd!
>>
>> So in this case, rpmsg-io-1 can have different ept addr than rpmsg-io-2
>> Back to same problem. Simple solution is to reply to remote with the
>> created ept addr and the index.
>
> That why I would like to suggest to use the name service field to identify the port/controller, instead of the endpoint address.
>>
>>>
>>> - match the RPMsg probe with the DT,
>>
>>
>> We can probe from all controllers with a single name service
>> announcement too.
>>
>>> - provide a simple mapping between the port and the endpoint on both sides,
>>
>>
>> We are trying to get rid of this mapping from Linux side to adapt
>> the gpio-virtio design.
>>
>>> - allow multiple endpoints on the remote side,
>>
>>
>> We can support this as well with single nameservice model.
>> There is no limitation. Remote has to send a message with
>> its newly created ept that's all.
>>
>>> - provide a simple discovery mechanism for remote capabilities.
>>
>>
>> A single announcement: "rpmsg-io" is also discovery mechanism.
>>
>> Feel free to let me know if you have concerns with any of the
>> suggestions!
>
> My only concern, whatever the solution, is that we find a smart
> solution to associate the correct endpoint with the correct GPIO
> port/controller defined in the DT.
In my solution, there is no need to have this map of endpoint to
GPIO port at Linux side. This aligns more with virtio-gpio design
as well.
>
> I may have misunderstood your solution. Could you please help me
> understand your proposal by explaining how you would handle three
> GPIO ports defined in the DT, considering that the endpoint
> addresses on the Linux side can be random?
> If I assume there is a unique endpoint on the remote side,
> I do not understand how you can match, on the firmware side,
> the Linux endpoint address to the GPIO port.
Sure, let me take an example:
Assumptions: 3 GPIO ports in DT, 3 endpoints in Linux (one per port),
1 endpoint in remote (0xd) and 1 rpmsg channel (rpmsg-io)
rpmsg {
rpmsg-io {
#address-cells = <1>;
#size-cells = <0>;
gpio@25 {
compatible = "rpmsg-gpio";
reg = <25>;
gpio-controller;
#gpio-cells = <2>;
#interrupt-cells = <2>;
interrupt-controller;
};
gpio@32 {
compatible = "rpmsg-gpio";
reg = <32>;
gpio-controller;
#gpio-cells = <2>;
#interrupt-cells = <2>;
interrupt-controller;
};
gpio@35 {
compatible = "rpmsg-gpio";
reg = <35>;
gpio-controller;
#gpio-cells = <2>;
#interrupt-cells = <2>;
interrupt-controller;
};
};
};
Code Flow:
1. "rpmsg-io" channel is announced from remote firmware with unique dst
ept = 0xd.
2. rpmsg_core.c creates the default dynamic local ept for the channel
ept = 0x405.
3. rpmsg_core.c assigns the allocated addr to rpdev device:
rpdev->src = 0x405 and rpdev->dst = 0xd.
4. rpmsg_gpio_channel_probe() is triggered. For *each* of the GPIO ports
in DT, it will trigger rpmsg_gpiochip_register() which will now:
a. Call port->ept = rpmsg_create_ept(rpdev,
rpmsg_gpio_channel_callback,
port,
{rpdev.id.name,
RPMSG_ADDR_ANY,
RPMSG_ADDR_ANY});
Ex- port->ept->addr = 0x408
b. Prepare a 8-byte message having 2 fields:
port->ept->addr (0x408) and port->idx (25)
c. Send this message to remote firmware on default channel ept
(0x405 -> 0xd) by:
rpmsg_send(rpdev->ept, &message, sizeof(message));
d. Remote side receives this message and creates a map of the
linux_ept_addr to gpio_port. (0x408 <-> 25)
5. After this point, any gpio messages sent from Linux from gpio port
endpoints (Ex- 0x408) can be decoded at remote side by looking up
its map (Ex- map[0x408] = 25).
6. Any messages sent from remote to Linux for a particular gpio port can
also be decoded at Linux by simply fetching the priv pointer to get
the per-port device:
struct rpmsg_gpio_port *port = priv;
So Linux does not need to send the port idx everytime while sending a
gpio message anymore.
Thanks,
Beleswar
[...]
^ permalink raw reply
* Re: [PATCH v9 5/6] iio: adc: ad4691: add oversampling support
From: Andy Shevchenko @ 2026-05-04 8:14 UTC (permalink / raw)
To: radu.sabau
Cc: Lars-Peter Clausen, Michael Hennerich, Jonathan Cameron,
David Lechner, Nuno Sá, Andy Shevchenko, Rob Herring,
Krzysztof Kozlowski, Conor Dooley, Uwe Kleine-König,
Liam Girdwood, Mark Brown, Linus Walleij, Bartosz Golaszewski,
Philipp Zabel, Jonathan Corbet, Shuah Khan, linux-iio, devicetree,
linux-kernel, linux-pwm, linux-gpio, linux-doc
In-Reply-To: <20260430-ad4692-multichannel-sar-adc-driver-v9-5-33e439e4fb87@analog.com>
On Thu, Apr 30, 2026 at 01:16:47PM +0300, Radu Sabau via B4 Relay wrote:
> Add per-channel oversampling ratio (OSR) support for CNV burst mode.
> The accumulator depth register (ACC_DEPTH_IN) is programmed with the
> selected OSR at buffer enable time and before each single-shot read.
>
> Supported OSR values: 1, 2, 4, 8, 16, 32.
>
> Introduce AD4691_MANUAL_CHANNEL() for manual mode channels, which do
> not expose the oversampling ratio attribute since OSR is not applicable
> in that mode. A separate manual_channels array is added to
> struct ad4691_channel_info and selected at probe time; offload paths
> reuse the same arrays with num_channels capping access before the soft
> timestamp entry.
>
> in_voltageN_sampling_frequency represents the effective output rate for
> channel N, defined as osc_freq / osr[N]. The chip has one internal
> oscillator shared by all channels; each channel independently
> accumulates osr[N] oscillator cycles before producing a result.
>
> Writing sampling_frequency computes needed_osc = freq * osr[N] and
> snaps down to the largest oscillator table entry that satisfies both
> osc <= needed_osc and osc % osr[N] == 0, guaranteeing an exact integer
> read-back. The result is stored in target_osc_freq_Hz and written to
> OSC_FREQ_REG at buffer enable and single-shot time, so sampling_frequency
> and oversampling_ratio can be set in any order.
>
> in_voltageN_sampling_frequency_available is computed dynamically from
> the channel's current OSR, listing only oscillator table entries that
> divide evenly by osr[N], expressed as effective rates. The list becomes
> sparser as OSR increases, capping at max_rate / osr[N].
>
> Writing oversampling_ratio stores the new OSR for that channel;
> target_osc_freq_Hz is left unchanged. The effective rate read back via
> in_voltageN_sampling_frequency becomes target_osc_freq_Hz / new_osr
> automatically. The two attributes are orthogonal: sampling_frequency
> controls the oscillator, oversampling_ratio controls the averaging depth.
>
> OSR defaults to 1 (no accumulation) for all channels.
...
> +/* Write target_osc_freq_Hz to OSC_FREQ_REG. Called at use time. */
> +static int ad4691_write_osc_freq(struct ad4691_state *st)
> +{
> + unsigned int i;
> +
> + for (i = 0; i < ARRAY_SIZE(ad4691_osc_freqs_Hz); i++) {
It can be
for (unsigned int i = 0; i < ARRAY_SIZE(ad4691_osc_freqs_Hz); i++) {
> + if (ad4691_osc_freqs_Hz[i] == st->target_osc_freq_Hz)
> + return regmap_write(st->regmap, AD4691_OSC_FREQ_REG, i);
> + }
> + return -EINVAL;
> +}
...
> +/*
> + * Find the largest oscillator table entry that is both <= needed_osc and
> + * evenly divisible by osr (guaranteeing an integer effective rate on
> + * read-back). Returns 0 if no such entry exists in the chip's valid range.
> + */
> +static unsigned int ad4691_find_osc_freq(struct ad4691_state *st,
> + unsigned int needed_osc,
> + unsigned int osr)
> {
> + unsigned int start = ad4691_samp_freq_start(st->info);
>
> + for (unsigned int i = start; i < ARRAY_SIZE(ad4691_osc_freqs_Hz); i++) {
> + if ((unsigned int)ad4691_osc_freqs_Hz[i] > needed_osc)
> + continue;
> + if (ad4691_osc_freqs_Hz[i] % osr != 0)
' != 0' is redundant.
> + continue;
> + return ad4691_osc_freqs_Hz[i];
> + }
> + return 0;
> +}
> +static int ad4691_get_sampling_freq(struct ad4691_state *st, u8 osr, int *val)
> +{
> + *val = st->target_osc_freq_Hz / osr;
> return IIO_VAL_INT;
> }
...
> -static int ad4691_set_sampling_freq(struct iio_dev *indio_dev, int freq)
> +static int ad4691_set_sampling_freq(struct iio_dev *indio_dev,
> + struct iio_chan_spec const *chan, int freq)
Can you use --histogram algo when preparing patches? This might make them look
better.
...
> + if (freq <= 0 || (unsigned int)freq > st->info->max_rate / osr)
Why casting?
> + return -EINVAL;
...
> - /* Wait 2 oscillator periods for the conversion to complete. */
> - period_us = DIV_ROUND_UP(2UL * USEC_PER_SEC, ad4691_osc_freqs_Hz[osc_idx]);
> + /*
> + * Wait osr + 1 oscillator periods: osr for accumulation, +1 for the
> + * pipeline margin (one extra period ensures the final result is ready).
> + */
> + period_us = DIV_ROUND_UP((unsigned long)(st->osr[chan->channel] + 1) * USEC_PER_SEC,
Why casting?
> + st->target_osc_freq_Hz);
> fsleep(period_us);
--
With Best Regards,
Andy Shevchenko
^ permalink raw reply
* Re: [PATCH v9 4/6] iio: adc: ad4691: add SPI offload support
From: Andy Shevchenko @ 2026-05-04 8:10 UTC (permalink / raw)
To: radu.sabau
Cc: Lars-Peter Clausen, Michael Hennerich, Jonathan Cameron,
David Lechner, Nuno Sá, Andy Shevchenko, Rob Herring,
Krzysztof Kozlowski, Conor Dooley, Uwe Kleine-König,
Liam Girdwood, Mark Brown, Linus Walleij, Bartosz Golaszewski,
Philipp Zabel, Jonathan Corbet, Shuah Khan, linux-iio, devicetree,
linux-kernel, linux-pwm, linux-gpio, linux-doc
In-Reply-To: <20260430-ad4692-multichannel-sar-adc-driver-v9-4-33e439e4fb87@analog.com>
On Thu, Apr 30, 2026 at 01:16:46PM +0300, Radu Sabau via B4 Relay wrote:
> Add SPI offload support to enable DMA-based, CPU-independent data
> acquisition using the SPI Engine offload framework.
>
> When an SPI offload is available (devm_spi_offload_get() succeeds),
> the driver registers a DMA engine IIO buffer and uses dedicated buffer
> setup operations. If no offload is available the existing software
> triggered buffer path is used unchanged.
>
> Both CNV Burst Mode and Manual Mode support offload, but use different
> trigger mechanisms:
>
> CNV Burst Mode: the SPI Engine is triggered by the ADC's DATA_READY
> signal on the GP pin specified by the trigger-source consumer reference
> in the device tree (one cell = GP pin number 0-3). For this mode the
> driver acts as both an SPI offload consumer (DMA RX stream, message
> optimization) and a trigger source provider: it registers the
> GP/DATA_READY output via devm_spi_offload_trigger_register() so the
> offload framework can match the '#trigger-source-cells' phandle and
> automatically fire the SPI Engine DMA transfer at end-of-conversion.
>
> Manual Mode: the SPI Engine is triggered by a periodic trigger at
> the configured sampling frequency. The pre-built SPI message uses
> the pipelined CNV-on-CS protocol: N+1 16-bit transfers are issued
> for N active channels (the first result is discarded as garbage from
> the pipeline flush) and the remaining N results are captured by DMA.
>
> All offload transfers use 16-bit frames (bits_per_word=16, len=2).
> The channel scan_type (storagebits=16, shift=0, IIO_BE) is shared
> between the software triggered-buffer and offload paths; no separate
> scan_type or channel array is needed for the offload case. The
> ad4691_manual_channels[] array introduced in the triggered-buffer
> commit is reused here: it hides the IIO_CHAN_INFO_OVERSAMPLING_RATIO
> attribute, which is not applicable in Manual Mode.
> Kconfig gains a dependency on IIO_BUFFER_DMAENGINE.
Unneeded detail in the commit message. It's visible from the patch.
You probably wanted to explain "why?" it's required.
...
> #include <linux/regulator/consumer.h>
> #include <linux/reset.h>
> #include <linux/spi/spi.h>
> +#include <linux/spi/offload/consumer.h>
> +#include <linux/spi/offload/provider.h>
You missed at some point types.h (in this patch or earlier).
> #include <linux/units.h>
> #include <linux/unaligned.h>
...
> - /* max 16 + 1 NOOP (manual) or 2*16 + 2 (CNV burst). */
> + /*
> + * Non-offload: max 16 + 1 NOOP (manual) or 2*16 + 2 (CNV burst).
> + * Offload reuses this array — both paths are mutually exclusive.
> + */
Can you make sure this will be in the end result from the beginning, id est
in the previous change put it as
/*
* Non-offload: max 16 + 1 NOOP (manual) or 2*16 + 2 (CNV burst).
* Offload is not supported.
*/
OR
/*
* Non-offload: max 16 + 1 NOOP (manual) or 2*16 + 2 (CNV burst).
*/
OR
/*
* max 16 + 1 NOOP (manual) or 2*16 + 2 (CNV burst).
*/
This will minimize the churn.
> struct spi_transfer scan_xfers[34];
...
> +static bool ad4691_offload_trigger_match(struct spi_offload_trigger *trigger,
> + enum spi_offload_trigger_type type,
> + u64 *args, u32 nargs)
> +{
> + return type == SPI_OFFLOAD_TRIGGER_DATA_READY &&
> + nargs == 1 && args[0] <= 3;
Seems there is a room in the previous line for more.
> +}
...
> - ret = regmap_write(st->regmap, AD4691_ACC_MASK_REG,
> - ~bitmap_read(indio_dev->active_scan_mask, 0,
> - iio_get_masklength(indio_dev)) & GENMASK(15, 0));
> + acc_mask = ~bitmap_read(indio_dev->active_scan_mask, 0,
> + iio_get_masklength(indio_dev)) & GENMASK(15, 0);
> + ret = regmap_write(st->regmap, AD4691_ACC_MASK_REG, acc_mask);
Make it like this in the previous patch.
> if (ret)
> goto err_unoptimize;
...
> + offload = devm_kzalloc(dev, sizeof(*offload), GFP_KERNEL);
Do you have device/devres.h already included (either explicitly or via device.h
or platform_device.h)?
> + if (!offload)
> + return -ENOMEM;
--
With Best Regards,
Andy Shevchenko
^ permalink raw reply
* Re: [PATCH 03/14] mm: rename uffd-wp PTE accessors to uffd
From: Mike Rapoport @ 2026-05-04 7:59 UTC (permalink / raw)
To: Kiryl Shutsemau (Meta)
Cc: akpm, peterx, david, ljs, surenb, vbabka, Liam.Howlett, ziy,
corbet, skhan, seanjc, pbonzini, jthoughton, aarcange, sj,
usama.arif, linux-mm, linux-kernel, linux-doc, linux-kselftest,
kvm, kernel-team
In-Reply-To: <20260427114607.4068647-4-kas@kernel.org>
On Mon, Apr 27, 2026 at 12:45:51PM +0100, Kiryl Shutsemau (Meta) wrote:
> Userfaultfd RWP will reuse the uffd-wp PTE bit to mark access-tracking
> PTEs, alongside the write-protected ones it already marks. The bit's
> meaning now depends on the VMA flag (WP or RWP), not on its name.
>
> Rename the kernel-internal names that describe the bit:
>
> - pte/pmd/huge_pte accessors (and swap variants)
> - pgtable_supports_uffd() capability query
> - SCAN_PTE_UFFD khugepaged enum
>
> The ftrace string emitted by mm_khugepaged_scan_pmd for this enum is
> kept as "pte_uffd_wp" so existing trace-based tooling keeps matching.
>
> Pure mechanical rename -- no behavior change.
>
> Signed-off-by: Kiryl Shutsemau <kas@kernel.org>
> Assisted-by: Claude:claude-opus-4-6
Reviewed-by: Mike Rapoport (Microsoft) <rppt@kernel.org>
--
Sincerely yours,
Mike.
^ permalink raw reply
* Re: [PATCH v9 3/6] iio: adc: ad4691: add triggered buffer support
From: Andy Shevchenko @ 2026-05-04 7:57 UTC (permalink / raw)
To: radu.sabau
Cc: Lars-Peter Clausen, Michael Hennerich, Jonathan Cameron,
David Lechner, Nuno Sá, Andy Shevchenko, Rob Herring,
Krzysztof Kozlowski, Conor Dooley, Uwe Kleine-König,
Liam Girdwood, Mark Brown, Linus Walleij, Bartosz Golaszewski,
Philipp Zabel, Jonathan Corbet, Shuah Khan, linux-iio, devicetree,
linux-kernel, linux-pwm, linux-gpio, linux-doc
In-Reply-To: <20260430-ad4692-multichannel-sar-adc-driver-v9-3-33e439e4fb87@analog.com>
On Thu, Apr 30, 2026 at 01:16:45PM +0300, Radu Sabau via B4 Relay wrote:
> Add buffered capture support using the IIO triggered buffer framework.
>
> CNV Burst Mode: the GP pin identified by interrupt-names in the device
> tree is configured as DATA_READY output. The IRQ handler stops
> conversions and fires the IIO trigger; the trigger handler executes a
> pre-built SPI message that reads all active channels from the AVG_IN
> accumulator registers and then resets accumulator state and restarts
> conversions for the next cycle.
>
> Manual Mode: CNV is tied to SPI CS so each transfer simultaneously
> reads the previous result and starts the next conversion (pipelined
> N+1 scheme). At preenable time a pre-built, optimised SPI message of
> N+1 transfers is constructed (N channel reads plus one NOOP to drain
> the pipeline). The trigger handler executes the message in a single
> spi_sync() call and collects the results. An external trigger (e.g.
> iio-trig-hrtimer) is required to drive the trigger at the desired
> sample rate.
>
> Both modes share the same trigger handler and push a complete scan —
> one u16 slot per channel at its scan_index position, followed by a
> timestamp — to the IIO buffer via iio_push_to_buffers_with_ts().
>
> The CNV Burst Mode sampling frequency (PWM period) is exposed as a
> buffer-level attribute via IIO_DEVICE_ATTR.
...
> #include <linux/array_size.h>
> #include <linux/bitfield.h>
> -#include <linux/bitops.h>
> +#include <linux/bitmap.h>
> #include <linux/cleanup.h>
> #include <linux/delay.h>
> #include <linux/dev_printk.h>
> #include <linux/device/devres.h>
> +#include <linux/dmaengine.h>
> #include <linux/err.h>
> +#include <linux/interrupt.h>
+ kstrtox.h
> #include <linux/limits.h>
> #include <linux/math.h>
> #include <linux/module.h>
> #include <linux/mod_devicetable.h>
> +#include <linux/property.h>
> +#include <linux/pwm.h>
> #include <linux/regmap.h>
> #include <linux/regulator/consumer.h>
> #include <linux/reset.h>
(double check that string.h is here or string_helpers.h in case the latter has
any use)
> #include <linux/units.h>
> #include <linux/unaligned.h>
...
> struct regmap *regmap;
> + struct spi_device *spi;
> +
> + struct pwm_device *conv_trigger;
> + int irq;
> int vref_uV;
> + u32 cnv_period_ns;
> +
> + bool manual_mode;
> bool refbuf_en;
> bool ldo_en;
> struct mutex lock;
> + /*
> + * Per-buffer-enable lifetime resources:
> + * Manual Mode - a pre-built SPI message that clocks out N+1
> + * transfers in one go.
> + * CNV Burst Mode - a pre-built SPI message that clocks out 2*N
> + * transfers in one go.
> + */
> + struct spi_message scan_msg;
> + /* max 16 + 1 NOOP (manual) or 2*16 + 2 (CNV burst). */
> + struct spi_transfer scan_xfers[34];
> + /*
> + * CNV burst: 16 AVG_IN addresses + state-reset address + state-reset
> + * value = 18. Manual: 16 channel cmds + 1 NOOP = 17.
> + */
> + __be16 scan_tx[18] __aligned(IIO_DMA_MINALIGN);
> + /*
> + * Scan buffer: one BE16 slot per active channel, plus timestamp.
> + * DMA-aligned because scan_xfers point rx_buf directly into vals[].
> + */
> + IIO_DECLARE_DMA_BUFFER_WITH_TS(__be16, vals, 16);
Have you run `pahole`? I'm wondering if this aligned member can be coupled with
something that gives lesser gap.
...
> +static ssize_t sampling_frequency_store(struct device *dev,
> + struct device_attribute *attr,
> + const char *buf, size_t len)
> +{
> + struct iio_dev *indio_dev = dev_to_iio_dev(dev);
> + struct ad4691_state *st = iio_priv(indio_dev);
> + int freq, ret;
> +
> + ret = kstrtoint(buf, 10, &freq);
> + if (ret)
> + return ret;
> +
> + IIO_DEV_ACQUIRE_DIRECT_MODE(indio_dev, claim);
> + if (IIO_DEV_ACQUIRE_FAILED(claim))
> + return -EBUSY;
> +
> +
Single blank line is enough.
> + ret = ad4691_set_pwm_freq(st, freq);
> + if (ret)
> + return ret;
> +
> + return len;
> +}
...
> +static int ad4691_read_scan(struct iio_dev *indio_dev, s64 timestamp)
> +{
> + struct ad4691_state *st = iio_priv(indio_dev);
> + int ret;
> +
> + guard(mutex)(&st->lock);
> +
> + ret = spi_sync(st->spi, &st->scan_msg);
> + if (ret)
> + return ret;
> +
> + /*
> + * rx_buf pointers in scan_xfers point directly into scan.vals, so no
> + * copy is needed. The scan_msg already includes a STATE_RESET at the
> + * end (appended in preenable), so no explicit reset is needed here.
> + */
> + iio_push_to_buffers_with_ts(indio_dev, st->vals, sizeof(st->vals),
> + timestamp);
I would leave it on a single line (note, you can also shorten the timestamp to
ts).
> + return 0;
> +}
...
> +static int ad4691_pwm_setup(struct ad4691_state *st)
> +{
> + struct device *dev = regmap_get_device(st->regmap);
> +
> + st->conv_trigger = devm_pwm_get(dev, "cnv");
> + if (IS_ERR(st->conv_trigger))
> + return dev_err_probe(dev, PTR_ERR(st->conv_trigger),
> + "Failed to get cnv pwm\n");
PWM
> + return ad4691_set_pwm_freq(st, st->info->max_rate);
> +}
...
> + /*
> + * The GP pin named in interrupt-names asserts at end-of-conversion.
> + * The IRQ handler stops conversions and fires the IIO trigger so
> + * the trigger handler can read and push the sample to the buffer.
> + * The IRQ is kept disabled until the buffer is enabled.
> + */
> + irq = -ENXIO;
> + for (i = 0; i < ARRAY_SIZE(ad4691_gp_names); i++) {
> + irq = fwnode_irq_get_byname(dev_fwnode(dev),
> + ad4691_gp_names[i]);
> + if (irq > 0)
> + break;
This is problematic in case the above returns EPROBE_DEFER. Can you confirm it
may not ever happen? (Note, I don't know the answer.)
> + }
> + if (irq < 0)
> + return dev_err_probe(dev, irq, "failed to get GP interrupt\n");
--
With Best Regards,
Andy Shevchenko
^ permalink raw reply
* Re: [PATCH 02/14] mm: rename uffd-wp PTE bit macros to uffd
From: Mike Rapoport @ 2026-05-04 7:51 UTC (permalink / raw)
To: Kiryl Shutsemau (Meta)
Cc: akpm, peterx, david, ljs, surenb, vbabka, Liam.Howlett, ziy,
corbet, skhan, seanjc, pbonzini, jthoughton, aarcange, sj,
usama.arif, linux-mm, linux-kernel, linux-doc, linux-kselftest,
kvm, kernel-team
In-Reply-To: <20260427114607.4068647-3-kas@kernel.org>
On Mon, Apr 27, 2026 at 12:45:50PM +0100, Kiryl Shutsemau (Meta) wrote:
> The uffd-wp PTE bit is about to gain a second consumer: userfaultfd
> RWP will use the same bit to mark access-tracking PTEs, distinct
> from mprotect(PROT_NONE) or NUMA-hinting PTEs. WP vs RWP semantics
> come from the VMA flag; the bit is just "uffd has claimed this
> entry." Drop the "_wp" suffix from the arch-private bit macros so
> they reflect that.
>
> x86: _PAGE_BIT_UFFD_WP -> _PAGE_BIT_UFFD
> _PAGE_UFFD_WP -> _PAGE_UFFD
> _PAGE_SWP_UFFD_WP -> _PAGE_SWP_UFFD
> arm64: PTE_UFFD_WP -> PTE_UFFD
> PTE_SWP_UFFD_WP -> PTE_SWP_UFFD
> riscv: _PAGE_UFFD_WP -> _PAGE_UFFD
> _PAGE_SWP_UFFD_WP -> _PAGE_SWP_UFFD
>
> Pure mechanical rename — no behavior change.
>
> Signed-off-by: Kiryl Shutsemau <kas@kernel.org>
> Assisted-by: Claude:claude-opus-4-6
Reviewed-by: Mike Rapoport (Microsoft) <rppt@kernel.org>
> ---
> arch/arm64/include/asm/pgtable-prot.h | 8 ++++----
> arch/arm64/include/asm/pgtable.h | 12 ++++++------
> arch/riscv/include/asm/pgtable-bits.h | 12 ++++++------
> arch/riscv/include/asm/pgtable.h | 14 +++++++-------
> arch/x86/include/asm/pgtable.h | 24 ++++++++++++------------
> arch/x86/include/asm/pgtable_types.h | 16 ++++++++--------
> 6 files changed, 43 insertions(+), 43 deletions(-)
--
Sincerely yours,
Mike.
^ permalink raw reply
* Re: [PATCH 01/14] mm: decouple protnone helpers from CONFIG_NUMA_BALANCING
From: Mike Rapoport @ 2026-05-04 7:48 UTC (permalink / raw)
To: Kiryl Shutsemau (Meta)
Cc: akpm, peterx, david, ljs, surenb, vbabka, Liam.Howlett, ziy,
corbet, skhan, seanjc, pbonzini, jthoughton, aarcange, sj,
usama.arif, linux-mm, linux-kernel, linux-doc, linux-kselftest,
kvm, kernel-team
In-Reply-To: <20260427114607.4068647-2-kas@kernel.org>
On Mon, Apr 27, 2026 at 12:45:49PM +0100, Kiryl Shutsemau (Meta) wrote:
> pte_protnone() and pmd_protnone() detect present-but-inaccessible page
> table entries. This capability is useful beyond NUMA balancing — for
> example, userfaultfd working set tracking uses protnone PTEs to track
> page access without unmapping pages.
>
> Introduce CONFIG_ARCH_HAS_PTE_PROTNONE to decouple the protnone PTE
> infrastructure from CONFIG_NUMA_BALANCING. The six architectures that
> support protnone PTEs (x86_64, arm64, powerpc, s390, riscv, loongarch)
> now select this option, and CONFIG_NUMA_BALANCING depends on it.
>
> No functional change — the same set of architectures continues to have
> working protnone support, but the infrastructure is now available
> independently of NUMA balancing.
>
> Signed-off-by: Kiryl Shutsemau (Meta) <kas@kernel.org>
> Assisted-by: Claude:claude-opus-4-6
With a small nit below
Acked-by: Mike Rapoport (Microsoft) <rppt@kernel.org>
> ---
> arch/arm64/Kconfig | 1 +
> arch/arm64/include/asm/pgtable.h | 7 ++-----
> arch/loongarch/Kconfig | 1 +
> arch/loongarch/include/asm/pgtable.h | 4 ++--
> arch/powerpc/include/asm/book3s/64/pgtable.h | 8 +++----
> arch/powerpc/platforms/Kconfig.cputype | 1 +
> arch/riscv/Kconfig | 1 +
> arch/riscv/include/asm/pgtable.h | 7 ++-----
> arch/s390/Kconfig | 1 +
> arch/s390/include/asm/pgtable.h | 4 ++--
> arch/x86/Kconfig | 1 +
> arch/x86/include/asm/pgtable.h | 8 ++-----
> include/linux/pgtable.h | 22 +++++++++-----------
> init/Kconfig | 8 +++++++
> mm/debug_vm_pgtable.c | 4 ++--
> 15 files changed, 40 insertions(+), 38 deletions(-)
>
> @@ -2052,18 +2052,12 @@ static inline int pud_trans_unstable(pud_t *pud)
> return 0;
> }
>
> -#ifndef CONFIG_NUMA_BALANCING
> +#ifndef CONFIG_ARCH_HAS_PTE_PROTNONE
> /*
> - * In an inaccessible (PROT_NONE) VMA, pte_protnone() may indicate "yes". It is
> - * perfectly valid to indicate "no" in that case, which is why our default
> - * implementation defaults to "always no".
> - *
> - * In an accessible VMA, however, pte_protnone() reliably indicates PROT_NONE
> - * page protection due to NUMA hinting. NUMA hinting faults only apply in
> - * accessible VMAs.
> - *
> - * So, to reliably identify PROT_NONE PTEs that require a NUMA hinting fault,
> - * looking at the VMA accessibility is sufficient.
I think it's better to rephrase the original comment so that it'll actually
describe what pte_protnone() means rather than remove it altogether.
> + * Stubs for architectures that do not support present-but-inaccessible
> + * (PROT_NONE) page table entries. Generic code may still reference
> + * PAGE_NONE from paths that fold to dead code on these arches; the
> + * BUILD_BUG() fallback fires only if such a reference is actually live.
> */
> static inline int pte_protnone(pte_t pte)
> {
> @@ -2074,7 +2068,11 @@ static inline int pmd_protnone(pmd_t pmd)
> {
> return 0;
> }
> -#endif /* CONFIG_NUMA_BALANCING */
> +
> +#ifndef PAGE_NONE
> +#define PAGE_NONE ({ BUILD_BUG(); (pgprot_t){0}; })
> +#endif
> +#endif /* CONFIG_ARCH_HAS_PTE_PROTNONE */
>
> #endif /* CONFIG_MMU */
--
Sincerely yours,
Mike.
^ permalink raw reply
* [PATCH v8 4/4] kunit: Add documentation for warning backtrace suppression API
From: Albert Esteve @ 2026-05-04 7:41 UTC (permalink / raw)
To: Arnd Bergmann, Brendan Higgins, David Gow, Rae Moar,
Maarten Lankhorst, Maxime Ripard, Thomas Zimmermann, David Airlie,
Simona Vetter, Jonathan Corbet, Shuah Khan, Andrew Morton,
Paul Walmsley, Palmer Dabbelt, Albert Ou, Alexandre Ghiti
Cc: linux-kernel, linux-arch, linux-kselftest, kunit-dev, dri-devel,
workflows, linux-riscv, linux-doc, peterz, Guenter Roeck,
Linux Kernel Functional Testing, Dan Carpenter,
Alessandro Carminati, Albert Esteve, Kees Cook, David Gow
In-Reply-To: <20260504-kunit_add_support-v8-0-3e5957cdd235@redhat.com>
From: Guenter Roeck <linux@roeck-us.net>
Document API functions for suppressing warning backtraces.
Tested-by: Linux Kernel Functional Testing <lkft@linaro.org>
Acked-by: Dan Carpenter <dan.carpenter@linaro.org>
Reviewed-by: Kees Cook <keescook@chromium.org>
Signed-off-by: Guenter Roeck <linux@roeck-us.net>
Reviewed-by: David Gow <davidgow@google.com>
Signed-off-by: Alessandro Carminati <acarmina@redhat.com>
Reviewed-by: David Gow <david@davidgow.net>
Signed-off-by: Albert Esteve <aesteve@redhat.com>
---
Documentation/dev-tools/kunit/usage.rst | 63 ++++++++++++++++++++++++++++++++-
1 file changed, 62 insertions(+), 1 deletion(-)
diff --git a/Documentation/dev-tools/kunit/usage.rst b/Documentation/dev-tools/kunit/usage.rst
index ebd06f5ea4550..25724f7e72969 100644
--- a/Documentation/dev-tools/kunit/usage.rst
+++ b/Documentation/dev-tools/kunit/usage.rst
@@ -157,6 +157,67 @@ Alternatively, one can take full control over the error message by using
if (some_setup_function())
KUNIT_FAIL(test, "Failed to setup thing for testing");
+Suppressing warning backtraces
+------------------------------
+
+Some unit tests trigger warning backtraces either intentionally or as a side
+effect. Such backtraces are normally undesirable since they distract from
+the actual test and may result in the impression that there is a problem.
+
+Backtraces can be suppressed with **task-scoped suppression**: while
+suppression is active on the current task, the backtrace and stack dump from
+``WARN*()``, ``WARN_ON*()``, and related macros on that task are suppressed.
+Three API forms are available, in order of convenience.
+
+- Scoped suppression is the simplest form. Wrap the code that triggers
+ warnings in a ``kunit_warning_suppress()`` block:
+
+.. code-block:: c
+
+ static void some_test(struct kunit *test)
+ {
+ kunit_warning_suppress(test) {
+ trigger_backtrace();
+ KUNIT_EXPECT_SUPPRESSED_WARNING_COUNT(test, 1);
+ }
+ }
+
+.. note::
+ The warning count must be checked inside the block; the suppression handle
+ is not accessible after the block exits.
+
+- Manual macros are useful when the suppressed region is large enough that
+ extra indentation is undesirable, or when the warning count needs to be
+ checked after suppression ends. ``KUNIT_START_SUPPRESSED_WARNING()`` must
+ appear before ``KUNIT_END_SUPPRESSED_WARNING()`` in the same scope.
+ Limited to one pair per scope.
+
+.. code-block:: c
+
+ static void some_test(struct kunit *test)
+ {
+ KUNIT_START_SUPPRESSED_WARNING(test);
+ trigger_backtrace();
+ KUNIT_END_SUPPRESSED_WARNING(test);
+
+ KUNIT_EXPECT_SUPPRESSED_WARNING_COUNT(test, 1);
+ }
+
+- Direct functions return an explicit handle pointer. Use them when the handle
+ needs to be retained or passed across helper functions:
+
+.. code-block:: c
+
+ static void some_test(struct kunit *test)
+ {
+ struct kunit_suppressed_warning *w;
+
+ w = kunit_start_suppress_warning(test);
+ trigger_backtrace();
+ kunit_end_suppress_warning(test, w);
+
+ KUNIT_EXPECT_EQ(test, kunit_suppressed_warning_count(w), 1);
+ }
Test Suites
~~~~~~~~~~~
@@ -1211,4 +1272,4 @@ For example:
dev_managed_string = devm_kstrdup(fake_device, "Hello, World!");
// Everything is cleaned up automatically when the test ends.
- }
\ No newline at end of file
+ }
--
2.53.0
^ permalink raw reply related
* [PATCH v8 3/4] drm: Suppress intentional warning backtraces in scaling unit tests
From: Albert Esteve @ 2026-05-04 7:41 UTC (permalink / raw)
To: Arnd Bergmann, Brendan Higgins, David Gow, Rae Moar,
Maarten Lankhorst, Maxime Ripard, Thomas Zimmermann, David Airlie,
Simona Vetter, Jonathan Corbet, Shuah Khan, Andrew Morton,
Paul Walmsley, Palmer Dabbelt, Albert Ou, Alexandre Ghiti
Cc: linux-kernel, linux-arch, linux-kselftest, kunit-dev, dri-devel,
workflows, linux-riscv, linux-doc, peterz, Guenter Roeck,
Linux Kernel Functional Testing, Dan Carpenter, Maíra Canal,
Alessandro Carminati, Albert Esteve, Simona Vetter
In-Reply-To: <20260504-kunit_add_support-v8-0-3e5957cdd235@redhat.com>
From: Guenter Roeck <linux@roeck-us.net>
The drm_test_rect_calc_hscale and drm_test_rect_calc_vscale unit tests
intentionally trigger warning backtraces by providing bad parameters to
the tested functions. What is tested is the return value, not the existence
of a warning backtrace. Suppress the backtraces to avoid clogging the
kernel log and distraction from real problems.
Tested-by: Linux Kernel Functional Testing <lkft@linaro.org>
Acked-by: Dan Carpenter <dan.carpenter@linaro.org>
Acked-by: Maíra Canal <mcanal@igalia.com>
Cc: Maarten Lankhorst <maarten.lankhorst@linux.intel.com>
Cc: David Airlie <airlied@gmail.com>
Cc: Daniel Vetter <daniel@ffwll.ch>
Signed-off-by: Guenter Roeck <linux@roeck-us.net>
Signed-off-by: Alessandro Carminati <acarmina@redhat.com>
Acked-by: David Gow <david@davidgow.net>
Signed-off-by: Albert Esteve <aesteve@redhat.com>
---
drivers/gpu/drm/tests/drm_rect_test.c | 23 +++++++++++++++++++----
1 file changed, 19 insertions(+), 4 deletions(-)
diff --git a/drivers/gpu/drm/tests/drm_rect_test.c b/drivers/gpu/drm/tests/drm_rect_test.c
index 17e1f34b76101..818e16e80c8f9 100644
--- a/drivers/gpu/drm/tests/drm_rect_test.c
+++ b/drivers/gpu/drm/tests/drm_rect_test.c
@@ -409,8 +409,16 @@ static void drm_test_rect_calc_hscale(struct kunit *test)
const struct drm_rect_scale_case *params = test->param_value;
int scaling_factor;
- scaling_factor = drm_rect_calc_hscale(¶ms->src, ¶ms->dst,
- params->min_range, params->max_range);
+ /*
+ * drm_rect_calc_hscale() generates a warning backtrace whenever bad
+ * parameters are passed to it. This affects all unit tests with an
+ * error code in expected_scaling_factor.
+ */
+ kunit_warning_suppress(test) {
+ scaling_factor = drm_rect_calc_hscale(¶ms->src, ¶ms->dst,
+ params->min_range,
+ params->max_range);
+ }
KUNIT_EXPECT_EQ(test, scaling_factor, params->expected_scaling_factor);
}
@@ -420,8 +428,15 @@ static void drm_test_rect_calc_vscale(struct kunit *test)
const struct drm_rect_scale_case *params = test->param_value;
int scaling_factor;
- scaling_factor = drm_rect_calc_vscale(¶ms->src, ¶ms->dst,
- params->min_range, params->max_range);
+ /*
+ * drm_rect_calc_vscale() generates a warning backtrace whenever bad
+ * parameters are passed to it. This affects all unit tests with an
+ * error code in expected_scaling_factor.
+ */
+ kunit_warning_suppress(test) {
+ scaling_factor = drm_rect_calc_vscale(¶ms->src, ¶ms->dst,
+ params->min_range, params->max_range);
+ }
KUNIT_EXPECT_EQ(test, scaling_factor, params->expected_scaling_factor);
}
--
2.53.0
^ permalink raw reply related
* [PATCH v8 2/4] kunit: Add backtrace suppression self-tests
From: Albert Esteve @ 2026-05-04 7:41 UTC (permalink / raw)
To: Arnd Bergmann, Brendan Higgins, David Gow, Rae Moar,
Maarten Lankhorst, Maxime Ripard, Thomas Zimmermann, David Airlie,
Simona Vetter, Jonathan Corbet, Shuah Khan, Andrew Morton,
Paul Walmsley, Palmer Dabbelt, Albert Ou, Alexandre Ghiti
Cc: linux-kernel, linux-arch, linux-kselftest, kunit-dev, dri-devel,
workflows, linux-riscv, linux-doc, peterz, Guenter Roeck,
Linux Kernel Functional Testing, Dan Carpenter,
Alessandro Carminati, Albert Esteve, Kees Cook
In-Reply-To: <20260504-kunit_add_support-v8-0-3e5957cdd235@redhat.com>
From: Guenter Roeck <linux@roeck-us.net>
Add unit tests to verify that warning backtrace suppression works.
Tests cover all three API forms:
- Scoped: kunit_warning_suppress() with in-block count verification
and post-block inactivity check.
- Manual macros: KUNIT_START/END_SUPPRESSED_WARNING() with WARN()
and WARN_ON(), both direct and through helper functions, as well
as multiple warnings in a single block.
- Direct functions: kunit_start/end_suppress_warning() with
sequential independent suppression blocks and per-block counts.
Furthermore, tests verify incremental warning counting, that
kunit_has_active_suppress_warning() transitions correctly around
suppression boundaries, and that suppression active in the test
kthread does not leak to a separate kthread.
If backtrace suppression does _not_ work, the unit tests will likely
trigger unsuppressed backtraces, which should actually help to get
the affected architectures / platforms fixed.
Tested-by: Linux Kernel Functional Testing <lkft@linaro.org>
Acked-by: Dan Carpenter <dan.carpenter@linaro.org>
Reviewed-by: Kees Cook <keescook@chromium.org>
Signed-off-by: Guenter Roeck <linux@roeck-us.net>
Signed-off-by: Alessandro Carminati <acarmina@redhat.com>
Reviewed-by: David Gow <david@davidgow.net>
Signed-off-by: Albert Esteve <aesteve@redhat.com>
---
lib/kunit/Makefile | 1 +
lib/kunit/backtrace-suppression-test.c | 184 +++++++++++++++++++++++++++++++++
2 files changed, 185 insertions(+)
diff --git a/lib/kunit/Makefile b/lib/kunit/Makefile
index 4592f9d0aa8dd..2e8a6b71a2ab0 100644
--- a/lib/kunit/Makefile
+++ b/lib/kunit/Makefile
@@ -22,6 +22,7 @@ obj-$(if $(CONFIG_KUNIT),y) += hooks.o
obj-$(CONFIG_KUNIT_TEST) += kunit-test.o
obj-$(CONFIG_KUNIT_TEST) += platform-test.o
+obj-$(CONFIG_KUNIT_TEST) += backtrace-suppression-test.o
# string-stream-test compiles built-in only.
ifeq ($(CONFIG_KUNIT_TEST),y)
diff --git a/lib/kunit/backtrace-suppression-test.c b/lib/kunit/backtrace-suppression-test.c
new file mode 100644
index 0000000000000..0e6fb685d2cbb
--- /dev/null
+++ b/lib/kunit/backtrace-suppression-test.c
@@ -0,0 +1,184 @@
+// SPDX-License-Identifier: GPL-2.0
+/*
+ * KUnit test for suppressing warning tracebacks.
+ *
+ * Copyright (C) 2024, Guenter Roeck
+ * Author: Guenter Roeck <linux@roeck-us.net>
+ */
+
+#include <kunit/test.h>
+#include <linux/bug.h>
+#include <linux/completion.h>
+#include <linux/kthread.h>
+
+static void backtrace_suppression_test_warn_direct(struct kunit *test)
+{
+ kunit_warning_suppress(test) {
+ WARN(1, "This backtrace should be suppressed");
+ /*
+ * Count must be checked inside the scope; the handle
+ * is not accessible after the block exits.
+ */
+ KUNIT_EXPECT_SUPPRESSED_WARNING_COUNT(test, 1);
+ }
+ KUNIT_EXPECT_FALSE(test, kunit_has_active_suppress_warning());
+}
+
+static void trigger_backtrace_warn(void)
+{
+ WARN(1, "This backtrace should be suppressed");
+}
+
+static void backtrace_suppression_test_warn_indirect(struct kunit *test)
+{
+ KUNIT_START_SUPPRESSED_WARNING(test);
+ trigger_backtrace_warn();
+ KUNIT_END_SUPPRESSED_WARNING(test);
+
+ KUNIT_EXPECT_SUPPRESSED_WARNING_COUNT(test, 1);
+}
+
+static void backtrace_suppression_test_warn_multi(struct kunit *test)
+{
+ KUNIT_START_SUPPRESSED_WARNING(test);
+ WARN(1, "This backtrace should be suppressed");
+ trigger_backtrace_warn();
+ KUNIT_END_SUPPRESSED_WARNING(test);
+
+ KUNIT_EXPECT_SUPPRESSED_WARNING_COUNT(test, 2);
+}
+
+static void backtrace_suppression_test_warn_on_direct(struct kunit *test)
+{
+ if (!IS_ENABLED(CONFIG_DEBUG_BUGVERBOSE) && !IS_ENABLED(CONFIG_KALLSYMS))
+ kunit_skip(test, "requires CONFIG_DEBUG_BUGVERBOSE or CONFIG_KALLSYMS");
+
+ KUNIT_START_SUPPRESSED_WARNING(test);
+ WARN_ON(1);
+ KUNIT_END_SUPPRESSED_WARNING(test);
+
+ KUNIT_EXPECT_SUPPRESSED_WARNING_COUNT(test, 1);
+}
+
+static void trigger_backtrace_warn_on(void)
+{
+ WARN_ON(1);
+}
+
+static void backtrace_suppression_test_warn_on_indirect(struct kunit *test)
+{
+ if (!IS_ENABLED(CONFIG_DEBUG_BUGVERBOSE))
+ kunit_skip(test, "requires CONFIG_DEBUG_BUGVERBOSE");
+
+ KUNIT_START_SUPPRESSED_WARNING(test);
+ trigger_backtrace_warn_on();
+ KUNIT_END_SUPPRESSED_WARNING(test);
+
+ KUNIT_EXPECT_SUPPRESSED_WARNING_COUNT(test, 1);
+}
+
+static void backtrace_suppression_test_count(struct kunit *test)
+{
+ KUNIT_START_SUPPRESSED_WARNING(test);
+
+ KUNIT_EXPECT_SUPPRESSED_WARNING_COUNT(test, 0);
+
+ WARN(1, "suppressed");
+ KUNIT_EXPECT_SUPPRESSED_WARNING_COUNT(test, 1);
+
+ WARN(1, "suppressed again");
+ KUNIT_EXPECT_SUPPRESSED_WARNING_COUNT(test, 2);
+
+ KUNIT_END_SUPPRESSED_WARNING(test);
+}
+
+static void backtrace_suppression_test_active_state(struct kunit *test)
+{
+ KUNIT_EXPECT_FALSE(test, kunit_has_active_suppress_warning());
+
+ KUNIT_START_SUPPRESSED_WARNING(test);
+ KUNIT_EXPECT_TRUE(test, kunit_has_active_suppress_warning());
+ KUNIT_END_SUPPRESSED_WARNING(test);
+
+ KUNIT_EXPECT_FALSE(test, kunit_has_active_suppress_warning());
+
+ kunit_warning_suppress(test) {
+ KUNIT_EXPECT_TRUE(test, kunit_has_active_suppress_warning());
+ }
+
+ KUNIT_EXPECT_FALSE(test, kunit_has_active_suppress_warning());
+}
+
+static void backtrace_suppression_test_multi_scope(struct kunit *test)
+{
+ struct kunit_suppressed_warning *sw1, *sw2;
+
+ if (!IS_ENABLED(CONFIG_DEBUG_BUGVERBOSE))
+ kunit_skip(test, "requires CONFIG_DEBUG_BUGVERBOSE");
+
+ sw1 = kunit_start_suppress_warning(test);
+ trigger_backtrace_warn_on();
+ WARN(1, "suppressed by sw1");
+ kunit_end_suppress_warning(test, sw1);
+
+ sw2 = kunit_start_suppress_warning(test);
+ WARN(1, "suppressed by sw2");
+ kunit_end_suppress_warning(test, sw2);
+
+ KUNIT_EXPECT_EQ(test, kunit_suppressed_warning_count(sw1), 2);
+ KUNIT_EXPECT_EQ(test, kunit_suppressed_warning_count(sw2), 1);
+}
+
+struct cross_kthread_data {
+ bool was_active;
+ struct completion done;
+};
+
+static int cross_kthread_fn(void *data)
+{
+ struct cross_kthread_data *d = data;
+
+ d->was_active = kunit_has_active_suppress_warning();
+ complete(&d->done);
+ return 0;
+}
+
+static void backtrace_suppression_test_cross_kthread(struct kunit *test)
+{
+ struct cross_kthread_data data;
+ struct task_struct *task;
+
+ init_completion(&data.done);
+
+ KUNIT_START_SUPPRESSED_WARNING(test);
+
+ task = kthread_run(cross_kthread_fn, &data, "kunit-cross-test");
+ KUNIT_ASSERT_FALSE(test, IS_ERR(task));
+ wait_for_completion(&data.done);
+
+ KUNIT_END_SUPPRESSED_WARNING(test);
+
+ KUNIT_EXPECT_FALSE(test, data.was_active);
+}
+
+static struct kunit_case backtrace_suppression_test_cases[] = {
+ KUNIT_CASE(backtrace_suppression_test_warn_direct),
+ KUNIT_CASE(backtrace_suppression_test_warn_indirect),
+ KUNIT_CASE(backtrace_suppression_test_warn_multi),
+ KUNIT_CASE(backtrace_suppression_test_warn_on_direct),
+ KUNIT_CASE(backtrace_suppression_test_warn_on_indirect),
+ KUNIT_CASE(backtrace_suppression_test_count),
+ KUNIT_CASE(backtrace_suppression_test_active_state),
+ KUNIT_CASE(backtrace_suppression_test_multi_scope),
+ KUNIT_CASE(backtrace_suppression_test_cross_kthread),
+ {}
+};
+
+static struct kunit_suite backtrace_suppression_test_suite = {
+ .name = "backtrace-suppression-test",
+ .test_cases = backtrace_suppression_test_cases,
+};
+kunit_test_suites(&backtrace_suppression_test_suite);
+
+MODULE_LICENSE("GPL");
+MODULE_DESCRIPTION("KUnit test to verify warning backtrace suppression");
--
2.53.0
^ permalink raw reply related
* [PATCH v8 1/4] bug/kunit: Core support for suppressing warning backtraces
From: Albert Esteve @ 2026-05-04 7:41 UTC (permalink / raw)
To: Arnd Bergmann, Brendan Higgins, David Gow, Rae Moar,
Maarten Lankhorst, Maxime Ripard, Thomas Zimmermann, David Airlie,
Simona Vetter, Jonathan Corbet, Shuah Khan, Andrew Morton,
Paul Walmsley, Palmer Dabbelt, Albert Ou, Alexandre Ghiti
Cc: linux-kernel, linux-arch, linux-kselftest, kunit-dev, dri-devel,
workflows, linux-riscv, linux-doc, peterz, Alessandro Carminati,
Guenter Roeck, Kees Cook, Albert Esteve
In-Reply-To: <20260504-kunit_add_support-v8-0-3e5957cdd235@redhat.com>
From: Alessandro Carminati <acarmina@redhat.com>
Some unit tests intentionally trigger warning backtraces by passing bad
parameters to kernel API functions. Such unit tests typically check the
return value from such calls, not the existence of the warning backtrace.
Such intentionally generated warning backtraces are neither desirable
nor useful for a number of reasons:
- They can result in overlooked real problems.
- A warning that suddenly starts to show up in unit tests needs to be
investigated and has to be marked to be ignored, for example by
adjusting filter scripts. Such filters are ad hoc because there is
no real standard format for warnings. On top of that, such filter
scripts would require constant maintenance.
Solve the problem by providing a means to suppress warning backtraces
originating from the current kthread while executing test code. Since
each KUnit test runs in its own kthread, this effectively scopes
suppression to the test that enabled it. Limit changes to generic code
to the absolute minimum.
Implementation details:
Suppression is integrated into the existing KUnit hooks infrastructure
in test-bug.h, reusing the kunit_running static branch for zero
overhead when no tests are running.
Suppression is checked at three points in the warning path:
- In warn_slowpath_fmt(), the check runs before any output, fully
suppressing both message and backtrace. This covers architectures
without __WARN_FLAGS.
- In __warn_printk(), the check suppresses the warning message text.
This covers architectures that define __WARN_FLAGS but not their own
__WARN_printf (arm64, loongarch, parisc, powerpc, riscv, sh), where
the message is printed before the trap enters __report_bug().
- In __report_bug(), the check runs before __warn() is called,
suppressing the backtrace and stack dump.
To avoid double-counting on architectures where both __warn_printk()
and __report_bug() run for the same warning, kunit_is_suppressed_warning()
takes a bool parameter: true to increment the suppression counter
(used in warn_slowpath_fmt and __report_bug), false to check only
(used in __warn_printk).
The suppression state is dynamically allocated via kunit_kzalloc() and
tied to the KUnit test lifecycle via kunit_add_action(), ensuring
automatic cleanup at test exit. Writer-side access to the global
suppression list is serialized with a spinlock; readers use RCU.
Three API forms are provided:
- kunit_warning_suppress(test) { ... }: scoped, uses __cleanup for
automatic teardown on scope exit, kunit_add_action() as safety net
for abnormal exits (e.g. kthread_exit from failed assertions).
Suppression handle is only accessible inside the block.
- KUNIT_START/END_SUPPRESSED_WARNING(test): manual macros for larger
blocks or when warning counts need to be checked after suppression
ends. Limited to one pair per scope.
- kunit_start/end_suppress_warning(test): direct functions returning
an explicit handle, for retaining the handle within the test,
or for cross-function usage.
Signed-off-by: Guenter Roeck <linux@roeck-us.net>
Signed-off-by: Alessandro Carminati <acarmina@redhat.com>
Reviewed-by: Kees Cook <kees@kernel.org>
Signed-off-by: Albert Esteve <aesteve@redhat.com>
---
include/kunit/test-bug.h | 25 +++++++++
include/kunit/test.h | 138 +++++++++++++++++++++++++++++++++++++++++++++++
kernel/panic.c | 15 +++++-
lib/bug.c | 10 ++++
lib/kunit/Makefile | 3 +-
lib/kunit/bug.c | 115 +++++++++++++++++++++++++++++++++++++++
lib/kunit/hooks-impl.h | 2 +
7 files changed, 305 insertions(+), 3 deletions(-)
diff --git a/include/kunit/test-bug.h b/include/kunit/test-bug.h
index 47aa8f21ccce8..6237e48ceadfd 100644
--- a/include/kunit/test-bug.h
+++ b/include/kunit/test-bug.h
@@ -23,6 +23,7 @@ DECLARE_STATIC_KEY_FALSE(kunit_running);
extern struct kunit_hooks_table {
__printf(3, 4) void (*fail_current_test)(const char*, int, const char*, ...);
void *(*get_static_stub_address)(struct kunit *test, void *real_fn_addr);
+ bool (*is_suppressed_warning)(bool count);
} kunit_hooks;
/**
@@ -60,9 +61,33 @@ static inline struct kunit *kunit_get_current_test(void)
} \
} while (0)
+/**
+ * kunit_is_suppressed_warning() - Check if warnings are being suppressed
+ * by the current KUnit test.
+ * @count: if true, increment the suppression counter on match.
+ *
+ * Returns true if the current task has active warning suppression.
+ * Uses the kunit_running static branch for zero overhead when no tests run.
+ *
+ * A single WARN*() may traverse multiple call sites in the warning path
+ * (e.g., __warn_printk() and __report_bug()). Pass @count = true at the
+ * primary suppression point to count each warning exactly once, and
+ * @count = false at secondary points to suppress output without
+ * inflating the count.
+ */
+static inline bool kunit_is_suppressed_warning(bool count)
+{
+ if (!static_branch_unlikely(&kunit_running))
+ return false;
+
+ return kunit_hooks.is_suppressed_warning &&
+ kunit_hooks.is_suppressed_warning(count);
+}
+
#else
static inline struct kunit *kunit_get_current_test(void) { return NULL; }
+static inline bool kunit_is_suppressed_warning(bool count) { return false; }
#define kunit_fail_current_test(fmt, ...) do {} while (0)
diff --git a/include/kunit/test.h b/include/kunit/test.h
index 9cd1594ab697d..f278ec028019c 100644
--- a/include/kunit/test.h
+++ b/include/kunit/test.h
@@ -1795,4 +1795,142 @@ do { \
// include resource.h themselves if they need it.
#include <kunit/resource.h>
+/*
+ * Warning backtrace suppression API.
+ *
+ * Suppresses WARN*() backtraces on the current task while active. Three forms
+ * are provided, in order of convenience:
+ *
+ * - Scoped: kunit_warning_suppress(test) { ... }
+ * Suppression is active for the duration of the block. On normal exit,
+ * the for-loop increment deactivates suppression. On early exit (break,
+ * return, goto), the __cleanup attribute fires. On kthread_exit() (e.g.,
+ * a failed KUnit assertion), kunit_add_action() cleans up at test
+ * teardown. The suppression handle is only accessible inside the block,
+ * so warning counts must be checked before the block exits.
+ *
+ * - Manual macros: KUNIT_[START|END]_SUPPRESSED_WARNING(test)
+ * Suppression spans an explicit range in the same scope. kunit_add_action()
+ * guarantees cleanup even if KUNIT_END_SUPPRESSED_WARNING() is not reached.
+ * Prefer this form when suppressing warnings across a large block where
+ * extra indentation is undesirable, or when the warning count needs to be
+ * checked after suppression ends. Limited to one pair per scope.
+ *
+ * - Direct: kunit_start_suppress_warning() / kunit_end_suppress_warning()
+ * The underlying functions, returning an explicit handle pointer. Use
+ * when the handle needs to be retained (e.g., for post-suppression
+ * count checks) or passed across helper functions.
+ */
+struct kunit_suppressed_warning;
+
+struct kunit_suppressed_warning *
+kunit_start_suppress_warning(struct kunit *test);
+void kunit_end_suppress_warning(struct kunit *test,
+ struct kunit_suppressed_warning *w);
+int kunit_suppressed_warning_count(struct kunit_suppressed_warning *w);
+void __kunit_suppress_auto_cleanup(struct kunit_suppressed_warning **wp);
+bool kunit_has_active_suppress_warning(void);
+
+/**
+ * kunit_warning_suppress() - Suppress WARN*() backtraces for the duration
+ * of a block.
+ * @test: The test context object.
+ *
+ * Scoped form of the suppression API. Suppression starts when the block is
+ * entered and ends automatically when the block exits through any path. See
+ * the section comment above for the cleanup guarantees on each exit path.
+ * Fails the test if suppression is already active; nesting is not supported.
+ *
+ * The warning count can be checked inside the block via
+ * KUNIT_EXPECT_SUPPRESSED_WARNING_COUNT(). The handle is not accessible
+ * after the block exits.
+ *
+ * Example::
+ *
+ * kunit_warning_suppress(test) {
+ * trigger_warning();
+ * KUNIT_EXPECT_SUPPRESSED_WARNING_COUNT(test, 1);
+ * }
+ */
+#define kunit_warning_suppress(test) \
+ for (struct kunit_suppressed_warning *__kunit_suppress \
+ __cleanup(__kunit_suppress_auto_cleanup) = \
+ kunit_start_suppress_warning(test); \
+ __kunit_suppress; \
+ kunit_end_suppress_warning(test, __kunit_suppress), \
+ __kunit_suppress = NULL)
+
+/**
+ * KUNIT_START_SUPPRESSED_WARNING() - Begin suppressing WARN*() backtraces.
+ * @test: The test context object.
+ *
+ * Manual form of the suppression API. Must be paired with
+ * KUNIT_END_SUPPRESSED_WARNING() in the same scope. See the section comment
+ * above for cleanup guarantees. Fails the test if suppression is already
+ * active; nesting is not supported. Limited to one pair per scope; use
+ * sequential kunit_warning_suppress() blocks or the direct function API
+ * when more than one suppression region is needed.
+ *
+ * Example::
+ *
+ * KUNIT_START_SUPPRESSED_WARNING(test);
+ * trigger_code_that_should_warn_once();
+ * KUNIT_END_SUPPRESSED_WARNING(test);
+ * KUNIT_EXPECT_SUPPRESSED_WARNING_COUNT(test, 1);
+ */
+#define KUNIT_START_SUPPRESSED_WARNING(test) \
+ struct kunit_suppressed_warning *__kunit_suppress = \
+ kunit_start_suppress_warning(test)
+
+/**
+ * KUNIT_END_SUPPRESSED_WARNING() - End suppressing WARN*() backtraces.
+ * @test: The test context object.
+ *
+ * Deactivates suppression started by KUNIT_START_SUPPRESSED_WARNING().
+ * The warning count remains readable via KUNIT_SUPPRESSED_WARNING_COUNT()
+ * after this call.
+ */
+#define KUNIT_END_SUPPRESSED_WARNING(test) \
+ kunit_end_suppress_warning(test, __kunit_suppress)
+
+/**
+ * KUNIT_SUPPRESSED_WARNING_COUNT() - Returns the suppressed warning count.
+ *
+ * Returns the number of WARN*() calls suppressed since the current
+ * suppression block started, or 0 if the handle is NULL. Usable inside a
+ * kunit_warning_suppress() block or after KUNIT_END_SUPPRESSED_WARNING().
+ */
+#define KUNIT_SUPPRESSED_WARNING_COUNT() \
+ kunit_suppressed_warning_count(__kunit_suppress)
+
+/**
+ * KUNIT_EXPECT_SUPPRESSED_WARNING_COUNT() - Sets an expectation that the
+ * suppressed warning count equals
+ * @expected.
+ * @test: The test context object.
+ * @expected: an expression that evaluates to the expected warning count.
+ *
+ * Sets an expectation that the number of suppressed WARN*() calls equals
+ * @expected. This is semantically equivalent to
+ * KUNIT_EXPECT_EQ(@test, KUNIT_SUPPRESSED_WARNING_COUNT(), @expected).
+ * See KUNIT_EXPECT_EQ() for more information.
+ */
+#define KUNIT_EXPECT_SUPPRESSED_WARNING_COUNT(test, expected) \
+ KUNIT_EXPECT_EQ(test, KUNIT_SUPPRESSED_WARNING_COUNT(), expected)
+
+/**
+ * KUNIT_ASSERT_SUPPRESSED_WARNING_COUNT() - Sets an assertion that the
+ * suppressed warning count equals
+ * @expected.
+ * @test: The test context object.
+ * @expected: an expression that evaluates to the expected warning count.
+ *
+ * Sets an assertion that the number of suppressed WARN*() calls equals
+ * @expected. This is the same as KUNIT_EXPECT_SUPPRESSED_WARNING_COUNT(),
+ * except it causes an assertion failure (see KUNIT_ASSERT_TRUE()) when the
+ * assertion is not met.
+ */
+#define KUNIT_ASSERT_SUPPRESSED_WARNING_COUNT(test, expected) \
+ KUNIT_ASSERT_EQ(test, KUNIT_SUPPRESSED_WARNING_COUNT(), expected)
+
#endif /* _KUNIT_TEST_H */
diff --git a/kernel/panic.c b/kernel/panic.c
index c78600212b6c1..697d8ca054bef 100644
--- a/kernel/panic.c
+++ b/kernel/panic.c
@@ -39,6 +39,7 @@
#include <linux/sys_info.h>
#include <trace/events/error_report.h>
#include <asm/sections.h>
+#include <kunit/test-bug.h>
#define PANIC_TIMER_STEP 100
#define PANIC_BLINK_SPD 18
@@ -1080,9 +1081,14 @@ void __warn(const char *file, int line, void *caller, unsigned taint,
void warn_slowpath_fmt(const char *file, int line, unsigned taint,
const char *fmt, ...)
{
- bool rcu = warn_rcu_enter();
+ bool rcu;
struct warn_args args;
+ if (kunit_is_suppressed_warning(true))
+ return;
+
+ rcu = warn_rcu_enter();
+
pr_warn(CUT_HERE);
if (!fmt) {
@@ -1102,9 +1108,14 @@ EXPORT_SYMBOL(warn_slowpath_fmt);
#else
void __warn_printk(const char *fmt, ...)
{
- bool rcu = warn_rcu_enter();
+ bool rcu;
va_list args;
+ if (kunit_is_suppressed_warning(false))
+ return;
+
+ rcu = warn_rcu_enter();
+
pr_warn(CUT_HERE);
va_start(args, fmt);
diff --git a/lib/bug.c b/lib/bug.c
index 623c467a8b76c..a5cebde554ed8 100644
--- a/lib/bug.c
+++ b/lib/bug.c
@@ -48,6 +48,7 @@
#include <linux/rculist.h>
#include <linux/ftrace.h>
#include <linux/context_tracking.h>
+#include <kunit/test-bug.h>
extern struct bug_entry __start___bug_table[], __stop___bug_table[];
@@ -223,6 +224,15 @@ static enum bug_trap_type __report_bug(struct bug_entry *bug, unsigned long buga
no_cut = bug->flags & BUGFLAG_NO_CUT_HERE;
has_args = bug->flags & BUGFLAG_ARGS;
+#ifdef CONFIG_KUNIT
+ /*
+ * Before the once logic so suppressed warnings do not consume
+ * the single-fire budget of WARN_ON_ONCE().
+ */
+ if (warning && kunit_is_suppressed_warning(true))
+ return BUG_TRAP_TYPE_WARN;
+#endif
+
if (warning && once) {
if (done)
return BUG_TRAP_TYPE_WARN;
diff --git a/lib/kunit/Makefile b/lib/kunit/Makefile
index 656f1fa35abcc..4592f9d0aa8dd 100644
--- a/lib/kunit/Makefile
+++ b/lib/kunit/Makefile
@@ -10,7 +10,8 @@ kunit-objs += test.o \
executor.o \
attributes.o \
device.o \
- platform.o
+ platform.o \
+ bug.o
ifeq ($(CONFIG_KUNIT_DEBUGFS),y)
kunit-objs += debugfs.o
diff --git a/lib/kunit/bug.c b/lib/kunit/bug.c
new file mode 100644
index 0000000000000..b0b6778d7399a
--- /dev/null
+++ b/lib/kunit/bug.c
@@ -0,0 +1,115 @@
+// SPDX-License-Identifier: GPL-2.0
+/*
+ * KUnit helpers for backtrace suppression
+ *
+ * Copyright (C) 2025 Alessandro Carminati <acarmina@redhat.com>
+ * Copyright (C) 2024 Guenter Roeck <linux@roeck-us.net>
+ */
+
+#include <kunit/resource.h>
+#include <linux/export.h>
+#include <linux/rculist.h>
+#include <linux/sched.h>
+#include <linux/spinlock.h>
+
+#include "hooks-impl.h"
+
+struct kunit_suppressed_warning {
+ struct list_head node;
+ struct task_struct *task;
+ struct kunit *test;
+ int counter;
+};
+
+static LIST_HEAD(suppressed_warnings);
+static DEFINE_SPINLOCK(suppressed_warnings_lock);
+
+static void kunit_suppress_warning_remove(struct kunit_suppressed_warning *w)
+{
+ unsigned long flags;
+
+ spin_lock_irqsave(&suppressed_warnings_lock, flags);
+ list_del_rcu(&w->node);
+ spin_unlock_irqrestore(&suppressed_warnings_lock, flags);
+ synchronize_rcu(); /* Wait for readers to finish */
+}
+
+KUNIT_DEFINE_ACTION_WRAPPER(kunit_suppress_warning_cleanup,
+ kunit_suppress_warning_remove,
+ struct kunit_suppressed_warning *);
+
+bool kunit_has_active_suppress_warning(void)
+{
+ return __kunit_is_suppressed_warning_impl(false);
+}
+EXPORT_SYMBOL_GPL(kunit_has_active_suppress_warning);
+
+struct kunit_suppressed_warning *
+kunit_start_suppress_warning(struct kunit *test)
+{
+ struct kunit_suppressed_warning *w;
+ unsigned long flags;
+ int ret;
+
+ if (kunit_has_active_suppress_warning()) {
+ KUNIT_FAIL(test, "Another suppression block is already active");
+ return NULL;
+ }
+
+ w = kunit_kzalloc(test, sizeof(*w), GFP_KERNEL);
+ if (!w)
+ return NULL;
+
+ w->task = current;
+ w->test = test;
+
+ spin_lock_irqsave(&suppressed_warnings_lock, flags);
+ list_add_rcu(&w->node, &suppressed_warnings);
+ spin_unlock_irqrestore(&suppressed_warnings_lock, flags);
+
+ ret = kunit_add_action_or_reset(test,
+ kunit_suppress_warning_cleanup, w);
+ if (ret)
+ return NULL;
+
+ return w;
+}
+EXPORT_SYMBOL_GPL(kunit_start_suppress_warning);
+
+void kunit_end_suppress_warning(struct kunit *test,
+ struct kunit_suppressed_warning *w)
+{
+ if (!w)
+ return;
+ kunit_release_action(test, kunit_suppress_warning_cleanup, w);
+}
+EXPORT_SYMBOL_GPL(kunit_end_suppress_warning);
+
+void __kunit_suppress_auto_cleanup(struct kunit_suppressed_warning **wp)
+{
+ if (*wp)
+ kunit_end_suppress_warning((*wp)->test, *wp);
+}
+EXPORT_SYMBOL_GPL(__kunit_suppress_auto_cleanup);
+
+int kunit_suppressed_warning_count(struct kunit_suppressed_warning *w)
+{
+ return w ? w->counter : 0;
+}
+EXPORT_SYMBOL_GPL(kunit_suppressed_warning_count);
+
+bool __kunit_is_suppressed_warning_impl(bool count)
+{
+ struct kunit_suppressed_warning *w;
+
+ guard(rcu)();
+ list_for_each_entry_rcu(w, &suppressed_warnings, node) {
+ if (w->task == current) {
+ if (count)
+ w->counter++;
+ return true;
+ }
+ }
+
+ return false;
+}
diff --git a/lib/kunit/hooks-impl.h b/lib/kunit/hooks-impl.h
index 4e71b2d0143ba..d8720f2616925 100644
--- a/lib/kunit/hooks-impl.h
+++ b/lib/kunit/hooks-impl.h
@@ -19,6 +19,7 @@ void __printf(3, 4) __kunit_fail_current_test_impl(const char *file,
int line,
const char *fmt, ...);
void *__kunit_get_static_stub_address_impl(struct kunit *test, void *real_fn_addr);
+bool __kunit_is_suppressed_warning_impl(bool count);
/* Code to set all of the function pointers. */
static inline void kunit_install_hooks(void)
@@ -26,6 +27,7 @@ static inline void kunit_install_hooks(void)
/* Install the KUnit hook functions. */
kunit_hooks.fail_current_test = __kunit_fail_current_test_impl;
kunit_hooks.get_static_stub_address = __kunit_get_static_stub_address_impl;
+ kunit_hooks.is_suppressed_warning = __kunit_is_suppressed_warning_impl;
}
#endif /* _KUNIT_HOOKS_IMPL_H */
--
2.53.0
^ permalink raw reply related
* [PATCH v8 0/4] kunit: Add support for suppressing warning backtraces
From: Albert Esteve @ 2026-05-04 7:41 UTC (permalink / raw)
To: Arnd Bergmann, Brendan Higgins, David Gow, Rae Moar,
Maarten Lankhorst, Maxime Ripard, Thomas Zimmermann, David Airlie,
Simona Vetter, Jonathan Corbet, Shuah Khan, Andrew Morton,
Paul Walmsley, Palmer Dabbelt, Albert Ou, Alexandre Ghiti
Cc: linux-kernel, linux-arch, linux-kselftest, kunit-dev, dri-devel,
workflows, linux-riscv, linux-doc, peterz, Alessandro Carminati,
Guenter Roeck, Kees Cook, Albert Esteve,
Linux Kernel Functional Testing, Dan Carpenter, Maíra Canal,
Kees Cook, Simona Vetter, David Gow
Some unit tests intentionally trigger warning backtraces by passing bad
parameters to kernel API functions. Such unit tests typically check the
return value from such calls, not the existence of the warning backtrace.
Such intentionally generated warning backtraces are neither desirable
nor useful for a number of reasons:
- They can result in overlooked real problems.
- A warning that suddenly starts to show up in unit tests needs to be
investigated and has to be marked to be ignored, for example by
adjusting filter scripts. Such filters are ad hoc because there is
no real standard format for warnings. On top of that, such filter
scripts would require constant maintenance.
One option to address the problem would be to add messages such as
"expected warning backtraces start/end here" to the kernel log.
However, that would again require filter scripts, might result in
missing real problematic warning backtraces triggered while the test
is running, and the irrelevant backtrace(s) would still clog the
kernel log.
Solve the problem by providing a means to suppress warning backtraces
originating from the current kthread while executing test code.
Since each KUnit test runs in its own kthread, this effectively scopes
suppression to the test that enabled it, without requiring any
architecture-specific code.
Overview:
Patch#1 Introduces the suppression infrastructure integrated into
KUnit's hook mechanism.
Patch#2 Adds selftests to validate the functionality.
Patch#3 Demonstrates real-world usage in the DRM subsystem.
Patch#4 Documents the new API and usage guidelines.
Design Notes:
Suppression is integrated into the existing KUnit hooks infrastructure,
reusing the kunit_running static branch for zero overhead
when no tests are running. The implementation lives entirely in the
kunit module; only a static-inline wrapper and a function pointer
slot are added to built-in code.
Suppression is checked at three points in the warning path:
- In `warn_slowpath_fmt()` (kernel/panic.c), for architectures without
__WARN_FLAGS. The check runs before any output, fully suppressing
both message and backtrace.
- In `__warn_printk()` (kernel/panic.c), for architectures that define
__WARN_FLAGS but not their own __WARN_printf (arm64, loongarch,
parisc, powerpc, riscv, sh). The check suppresses the warning message
text that is printed before the trap enters __report_bug().
- In `__report_bug()` (lib/bug.c), for architectures that define
__WARN_FLAGS. The check runs before `__warn()` is called, suppressing
the backtrace and stack dump.
To avoid double-counting on architectures where both `__warn_printk()`
and `__report_bug()` run for the same warning, the hook takes a bool
parameter: true to increment the suppression counter, false to suppress
without counting.
The suppression state is dynamically allocated via kunit_kzalloc() and
tied to the KUnit test lifecycle via `kunit_add_action()`, ensuring
automatic cleanup at test exit. Writer-side access to the global
suppression list is serialized with a spinlock; readers use RCU.
Three API forms are provided:
- kunit_warning_suppress(test) { ... }: scoped blocks with automatic
cleanup. The suppression handle is not accessible outside the block,
so warning counts (if needed) must be checked inside. Multiple
suppression blocks are allowed.
- KUNIT_START/END_SUPPRESSED_WARNING(test): manual macros for larger
blocks or post-suppression count checks. Limited to one pair per
scope.
- kunit_start/end_suppress_warning(test): direct functions that return
an explicit handle. Use when the handle needs to be retained, or passed
across helpers. Multiple suppression blocks are allowed.
This series is based on the RFC patch and subsequent discussion at
https://patchwork.kernel.org/project/linux-kselftest/patch/02546e59-1afe-4b08-ba81-d94f3b691c9a@moroto.mountain/
and offers a more comprehensive solution of the problem discussed there.
Changes since RFC:
- Introduced CONFIG_KUNIT_SUPPRESS_BACKTRACE
- Minor cleanups and bug fixes
- Added support for all affected architectures
- Added support for counting suppressed warnings
- Added unit tests using those counters
- Added patch to suppress warning backtraces in dev_addr_lists tests
Changes since v1:
- Rebased to v6.9-rc1
- Added Tested-by:, Acked-by:, and Reviewed-by: tags
[I retained those tags since there have been no functional changes]
- Introduced KUNIT_SUPPRESS_BACKTRACE configuration option, enabled by
default.
Changes since v2:
- Rebased to v6.9-rc2
- Added comments to drm warning suppression explaining why it is needed.
- Added patch to move conditional code in arch/sh/include/asm/bug.h
to avoid kerneldoc warning
- Added architecture maintainers to Cc: for architecture specific patches
- No functional changes
Changes since v3:
- Rebased to v6.14-rc6
- Dropped net: "kunit: Suppress lock warning noise at end of dev_addr_lists tests"
since 3db3b62955cd6d73afde05a17d7e8e106695c3b9
- Added __kunit_ and KUNIT_ prefixes.
- Tested on interessed architectures.
Changes since v4:
- Rebased to v6.15-rc7
- Dropped all code in __report_bug()
- Moved all checks in WARN*() macros.
- Dropped all architecture specific code.
- Made __kunit_is_suppressed_warning nice to noinstr functions.
Changes since v5:
- Rebased to v7.0-rc3
- Added RCU protection for the suppressed warnings list.
- Added static key and branching optimization.
- Removed custom `strcmp` implementation and reworked
__kunit_is_suppressed_warning() entrypoint function.
Changes since v6:
- Moved suppression checks from WARN*() macros to warn_slowpath_fmt()
and __report_bug().
- Replaced stack-allocated suppression struct with kunit_kzalloc() heap
allocation tied to the KUnit test lifecycle.
- Changed suppression strategy from function-name matching to task-scoped:
all warnings on the current task are suppressed between START and END,
rather than only warnings originating from a specific named function.
- Simplified macro API: removed KUNIT_DECLARE_SUPPRESSED_WARNING(),
the START macro now takes (test) and handles allocation internally.
- Removed static key and branching optiomization, as by the time it
was executed, callers are already in warn slowpaths.
- Link to v6: https://lore.kernel.org/r/20260317-kunit_add_support-v6-0-dd22aeb3fe5d@redhat.com
Changes since v7:
- Integrated suppression into existing KUnit hooks infrastructure
- Removed CONFIG_KUNIT_SUPPRESS_BACKTRACE
- Added suppression check in __warn_printk()
- Added spinlock for writer-side RCU protection
- Replaced explicit rcu_read_lock/unlock with guard(rcu)()
- Added scoped API (kunit_warning_suppress) using __cleanup attribute
- Updated DRM patch to use scoped API
- Expanded self-tests: incremental counting, cross-kthread isolation
- Rewrote documentation covering all three API forms with examples
- Link to v7: https://lore.kernel.org/r/20260420-kunit_add_support-v7-0-e8bc6e0f70de@redhat.com
--
2.34.1
---
Alessandro Carminati (1):
bug/kunit: Core support for suppressing warning backtraces
Guenter Roeck (3):
kunit: Add backtrace suppression self-tests
drm: Suppress intentional warning backtraces in scaling unit tests
kunit: Add documentation for warning backtrace suppression API
Documentation/dev-tools/kunit/usage.rst | 63 ++++++++++-
drivers/gpu/drm/tests/drm_rect_test.c | 23 +++-
include/kunit/test-bug.h | 25 +++++
include/kunit/test.h | 138 ++++++++++++++++++++++++
kernel/panic.c | 15 ++-
lib/bug.c | 10 ++
lib/kunit/Makefile | 4 +-
lib/kunit/backtrace-suppression-test.c | 184 ++++++++++++++++++++++++++++++++
lib/kunit/bug.c | 115 ++++++++++++++++++++
lib/kunit/hooks-impl.h | 2 +
10 files changed, 571 insertions(+), 8 deletions(-)
---
base-commit: 80234b5ab240f52fa45d201e899e207b9265ef91
change-id: 20260312-kunit_add_support-2f35806b19dd
Best regards,
--
Albert Esteve <aesteve@redhat.com>
^ permalink raw reply
* [PATCH v3 1/2] spi: add new_device/delete_device sysfs interface
From: Vishwaroop A @ 2026-05-04 7:40 UTC (permalink / raw)
To: broonie, linux-spi
Cc: smangipudi, jonathanh, thierry.reding, corbet, linux-doc, va
In-Reply-To: <20260504074037.704833-1-va@nvidia.com>
Development boards such as the Jetson AGX Orin expose SPI buses
on expansion headers (e.g. the 40-pin header) so that users can
connect and interact with SPI peripherals from userspace. The
standard way to get /dev/spidevB.C character device nodes for
this purpose is to register spi_device instances backed by the
spidev driver.
Today there is no viable way to do this on upstream kernels:
- The spidev driver rejects the bare "spidev" compatible
string in DT, since spidev is a Linux software interface
and not a description of real hardware.
- Vendor-specific compatible strings (e.g. "nvidia,tegra-spidev")
have been rejected by DT maintainers for the same reason.
The I2C subsystem solved an analogous problem by exposing
new_device/delete_device sysfs attributes on each adapter. Add
the same interface to SPI host controllers, so that userspace
(e.g. a systemd unit at boot) can instantiate SPI devices at
runtime without needing anything in device-tree.
The new_device file accepts:
<modalias> <chip_select> [<max_speed_hz> [<mode>]]
where chip_select is required, while max_speed_hz and mode are
optional and default to 0 if omitted. max_speed_hz == 0 is
clamped to the controller's maximum by spi_setup(); mode == 0
selects SPI mode 0 (CPOL=0, CPHA=0).
The modalias is used both as the device identifier and as a
driver_override, so that the device binds to the named driver
directly. This is necessary because some drivers like spidev
deliberately exclude generic names from their id_table.
Devices created this way are limited compared to those declared
via DT or board files:
- No IRQ is assigned (the device gets IRQ 0 / no interrupt).
- No platform_data or device properties are attached.
- No OF node is associated with the device.
These limitations are acceptable for spidev, which only needs a
registered spi_device to expose a character device to userspace.
Only devices created via new_device can be removed through
delete_device; DT and platform devices are unaffected.
The sysfs attributes are gated behind CONFIG_SPI_DYNAMIC since
this feature adds a new way of dynamically instantiating and
removing SPI devices, and the add_lock locking in
spi_unregister_controller() is already conditional on
CONFIG_SPI_DYNAMIC.
Link: https://lore.kernel.org/linux-tegra/909f0c92-d110-4253-903e-5c81e21e12c9@nvidia.com/
Signed-off-by: Vishwaroop A <va@nvidia.com>
---
drivers/spi/spi.c | 206 ++++++++++++++++++++++++++++++++++++++++
include/linux/spi/spi.h | 12 +++
2 files changed, 218 insertions(+)
diff --git a/drivers/spi/spi.c b/drivers/spi/spi.c
index 7001f5dce8bd..ce4fab6cd50c 100644
--- a/drivers/spi/spi.c
+++ b/drivers/spi/spi.c
@@ -296,11 +296,192 @@ static const struct attribute_group spi_controller_statistics_group = {
.attrs = spi_controller_statistics_attrs,
};
+#if IS_ENABLED(CONFIG_SPI_DYNAMIC)
+
+static void spi_dev_set_name(struct spi_device *spi);
+static int __spi_add_device(struct spi_device *spi, struct spi_device *parent);
+
+/*
+ * new_device_store - instantiate a new SPI device from userspace
+ *
+ * Takes parameters: <modalias> <chip_select> [<max_speed_hz> [<mode>]]
+ *
+ * Examples:
+ * echo spidev 0 > new_device
+ * echo spidev 0 10000000 > new_device
+ * echo spidev 0 10000000 3 > new_device
+ */
+static ssize_t
+new_device_store(struct device *dev, struct device_attribute *attr,
+ const char *buf, size_t count)
+{
+ struct spi_controller *ctlr = container_of(dev, struct spi_controller,
+ dev);
+ struct spi_device *spi;
+ char modalias[SPI_NAME_SIZE];
+ u16 chip_select;
+ u32 max_speed_hz = 0;
+ u32 mode = 0;
+ char *blank;
+ int n, res, status;
+
+ blank = strchr(buf, ' ');
+ if (!blank) {
+ dev_err(dev, "%s: Missing parameters\n", "new_device");
+ return -EINVAL;
+ }
+
+ if (blank - buf > SPI_NAME_SIZE - 1) {
+ dev_err(dev, "%s: Invalid device name\n", "new_device");
+ return -EINVAL;
+ }
+
+ memset(modalias, 0, sizeof(modalias));
+ memcpy(modalias, buf, blank - buf);
+
+ /*
+ * sscanf fills only the fields it matches; unmatched optional
+ * fields (max_speed_hz, mode) stay zero from initialisation above.
+ * max_speed_hz == 0 is clamped to the controller max by spi_setup().
+ * mode == 0 selects SPI mode 0 (CPOL=0, CPHA=0).
+ */
+ res = sscanf(++blank, "%hu %u %u%n",
+ &chip_select, &max_speed_hz, &mode, &n);
+ if (res < 1) {
+ dev_err(dev, "%s: Can't parse chip select\n", "new_device");
+ return -EINVAL;
+ }
+
+ if (chip_select >= ctlr->num_chipselect) {
+ dev_err(dev, "%s: Chip select %u >= max %u\n", "new_device",
+ chip_select, ctlr->num_chipselect);
+ return -EINVAL;
+ }
+
+ spi = spi_alloc_device(ctlr);
+ if (!spi)
+ return -ENOMEM;
+
+ spi_set_chipselect(spi, 0, chip_select);
+ spi->max_speed_hz = max_speed_hz;
+ spi->mode = mode;
+ spi->cs_index_mask = BIT(0);
+ strscpy(spi->modalias, modalias, sizeof(spi->modalias));
+
+ /*
+ * Set driver_override so that the device binds to the driver
+ * named by modalias regardless of whether that driver's
+ * id_table contains a matching entry. This is needed because
+ * some drivers (e.g. spidev) deliberately omit generic names
+ * from their id_table.
+ */
+ status = device_set_driver_override(&spi->dev, modalias);
+ if (status) {
+ spi_dev_put(spi);
+ return status;
+ }
+
+ /*
+ * Use __spi_add_device() directly rather than spi_add_device()
+ * so we can hold add_lock across both the device registration
+ * and the list insertion. Without this, spi_unregister_controller()
+ * could run between the two operations: the device would be known
+ * to the core (so __unregister iterates over it) but not yet on
+ * the userspace_clients list, leading to a double-free or a
+ * dangling list entry.
+ */
+ spi_dev_set_name(spi);
+
+ mutex_lock(&ctlr->add_lock);
+ status = __spi_add_device(spi, NULL);
+ if (status) {
+ mutex_unlock(&ctlr->add_lock);
+ spi_dev_put(spi);
+ return status;
+ }
+
+ mutex_lock(&ctlr->userspace_clients_lock);
+ list_add_tail(&spi->userspace_node, &ctlr->userspace_clients);
+ mutex_unlock(&ctlr->userspace_clients_lock);
+ mutex_unlock(&ctlr->add_lock);
+
+ dev_info(dev, "%s: Instantiated device %s at CS%u\n", "new_device",
+ modalias, chip_select);
+
+ return count;
+}
+static DEVICE_ATTR_WO(new_device);
+
+static ssize_t
+delete_device_store(struct device *dev, struct device_attribute *attr,
+ const char *buf, size_t count)
+{
+ struct spi_controller *ctlr = container_of(dev, struct spi_controller,
+ dev);
+ struct spi_device *spi, *next;
+ unsigned short cs;
+ char end;
+ int res;
+
+ res = sscanf(buf, "%hu%c", &cs, &end);
+ if (res < 1) {
+ dev_err(dev, "%s: Can't parse chip select\n", "delete_device");
+ return -EINVAL;
+ }
+ if (res > 1 && end != '\n') {
+ dev_err(dev, "%s: Extra parameters\n", "delete_device");
+ return -EINVAL;
+ }
+
+ res = -ENOENT;
+ mutex_lock(&ctlr->userspace_clients_lock);
+ list_for_each_entry_safe(spi, next, &ctlr->userspace_clients,
+ userspace_node) {
+ if (spi_get_chipselect(spi, 0) == cs) {
+ dev_info(dev, "%s: Deleting device %s at CS%u\n",
+ "delete_device", spi->modalias, cs);
+
+ list_del(&spi->userspace_node);
+ spi_unregister_device(spi);
+ res = count;
+ break;
+ }
+ }
+ mutex_unlock(&ctlr->userspace_clients_lock);
+
+ if (res < 0)
+ dev_err(dev, "%s: Can't find device in list\n",
+ "delete_device");
+ return res;
+}
+static DEVICE_ATTR_IGNORE_LOCKDEP(delete_device, 0200, NULL,
+ delete_device_store);
+
+static struct attribute *spi_controller_userspace_attrs[] = {
+ &dev_attr_new_device.attr,
+ &dev_attr_delete_device.attr,
+ NULL,
+};
+
+static const struct attribute_group spi_controller_userspace_group = {
+ .attrs = spi_controller_userspace_attrs,
+};
+
static const struct attribute_group *spi_controller_groups[] = {
&spi_controller_statistics_group,
+ &spi_controller_userspace_group,
NULL,
};
+#else /* !CONFIG_SPI_DYNAMIC */
+
+static const struct attribute_group *spi_controller_groups[] = {
+ &spi_controller_statistics_group,
+ NULL,
+};
+
+#endif /* CONFIG_SPI_DYNAMIC */
+
static void spi_statistics_add_transfer_stats(struct spi_statistics __percpu *pcpu_stats,
struct spi_transfer *xfer,
struct spi_message *msg)
@@ -3256,6 +3437,10 @@ struct spi_controller *__spi_alloc_controller(struct device *dev,
mutex_init(&ctlr->bus_lock_mutex);
mutex_init(&ctlr->io_mutex);
mutex_init(&ctlr->add_lock);
+#if IS_ENABLED(CONFIG_SPI_DYNAMIC)
+ mutex_init(&ctlr->userspace_clients_lock);
+ INIT_LIST_HEAD(&ctlr->userspace_clients);
+#endif
ctlr->bus_num = -1;
ctlr->num_chipselect = 1;
ctlr->num_data_lanes = 1;
@@ -3633,6 +3818,27 @@ void spi_unregister_controller(struct spi_controller *ctlr)
if (IS_ENABLED(CONFIG_SPI_DYNAMIC))
mutex_lock(&ctlr->add_lock);
+ /*
+ * Remove devices created via the sysfs new_device interface.
+ * These must be explicitly removed before device_for_each_child()
+ * below because spi_unregister_device() does not remove devices
+ * from the userspace_clients list; freeing them without list_del()
+ * first would leave dangling pointers in that list.
+ */
+#if IS_ENABLED(CONFIG_SPI_DYNAMIC)
+ mutex_lock(&ctlr->userspace_clients_lock);
+ while (!list_empty(&ctlr->userspace_clients)) {
+ struct spi_device *spi;
+
+ spi = list_first_entry(&ctlr->userspace_clients,
+ struct spi_device,
+ userspace_node);
+ list_del(&spi->userspace_node);
+ spi_unregister_device(spi);
+ }
+ mutex_unlock(&ctlr->userspace_clients_lock);
+#endif
+
device_for_each_child(&ctlr->dev, NULL, __unregister);
/* First make sure that this controller was ever added */
diff --git a/include/linux/spi/spi.h b/include/linux/spi/spi.h
index 7587b1c5d7ec..3dff1a4e630a 100644
--- a/include/linux/spi/spi.h
+++ b/include/linux/spi/spi.h
@@ -250,6 +250,10 @@ struct spi_device {
u8 rx_lane_map[SPI_DEVICE_DATA_LANE_CNT_MAX];
u8 num_rx_lanes;
+#if IS_ENABLED(CONFIG_SPI_DYNAMIC)
+ struct list_head userspace_node;
+#endif
+
/*
* Likely need more hooks for more protocol options affecting how
* the controller talks to each chip, like:
@@ -554,6 +558,9 @@ extern struct spi_device *devm_spi_new_ancillary_device(struct spi_device *spi,
* @defer_optimize_message: set to true if controller cannot pre-optimize messages
* and needs to defer the optimization step until the message is actually
* being transferred
+ * @userspace_clients: list of SPI devices instantiated from userspace via
+ * the sysfs new_device interface
+ * @userspace_clients_lock: mutex protecting @userspace_clients
*
* Each SPI controller can communicate with one or more @spi_device
* children. These make a small bus, sharing MOSI, MISO and SCK signals
@@ -809,6 +816,11 @@ struct spi_controller {
bool queue_empty;
bool must_async;
bool defer_optimize_message;
+
+#if IS_ENABLED(CONFIG_SPI_DYNAMIC)
+ struct list_head userspace_clients;
+ struct mutex userspace_clients_lock;
+#endif
};
static inline void *spi_controller_get_devdata(struct spi_controller *ctlr)
--
2.17.1
^ permalink raw reply related
* [PATCH v3 2/2] docs: spi: add documentation for userspace device instantiation
From: Vishwaroop A @ 2026-05-04 7:40 UTC (permalink / raw)
To: broonie, linux-spi
Cc: smangipudi, jonathanh, thierry.reding, corbet, linux-doc, va
In-Reply-To: <20260504074037.704833-1-va@nvidia.com>
Document the new_device and delete_device sysfs attributes on SPI
controllers:
- Documentation/spi/instantiating-devices.rst: describes when and
why this interface is needed, accepted parameters, usage examples,
and limitations.
- Documentation/ABI/testing/sysfs-class-spi-master: formal ABI
entry for both attributes.
Signed-off-by: Vishwaroop A <va@nvidia.com>
---
.../ABI/testing/sysfs-class-spi-master | 34 +++++++
Documentation/spi/index.rst | 1 +
Documentation/spi/instantiating-devices.rst | 88 +++++++++++++++++++
3 files changed, 123 insertions(+)
create mode 100644 Documentation/ABI/testing/sysfs-class-spi-master
create mode 100644 Documentation/spi/instantiating-devices.rst
diff --git a/Documentation/ABI/testing/sysfs-class-spi-master b/Documentation/ABI/testing/sysfs-class-spi-master
new file mode 100644
index 000000000000..b498be128bad
--- /dev/null
+++ b/Documentation/ABI/testing/sysfs-class-spi-master
@@ -0,0 +1,34 @@
+What: /sys/class/spi_master/spiB/new_device
+Date: April 2026
+KernelVersion: 7.2
+Contact: linux-spi@vger.kernel.org
+Description: (WO) Instantiate a new SPI device on bus B, where B
+ is the bus number (0, 1, 2, ...). Takes parameters
+ in the format:
+
+ <modalias> <chip_select> [<max_speed_hz> [<mode>]]
+
+ where modalias is the driver name, chip_select is the
+ CS line number, and max_speed_hz and mode are optional.
+
+ The device can later be removed with delete_device.
+
+ Only devices created via this interface can be removed
+ with delete_device; platform and DT devices are not
+ affected.
+
+ Example:
+ # echo spidev 0 > /sys/class/spi_master/spi0/new_device
+ # echo spidev 0 10000000 > /sys/class/spi_master/spi0/new_device
+ # echo spidev 0 10000000 3 > /sys/class/spi_master/spi0/new_device
+
+What: /sys/class/spi_master/spiB/delete_device
+Date: April 2026
+KernelVersion: 7.2
+Contact: linux-spi@vger.kernel.org
+Description: (WO) Remove a SPI device previously created via
+ new_device. Takes a single parameter: the chip select
+ number of the device to remove.
+
+ Example:
+ # echo 0 > /sys/class/spi_master/spi0/delete_device
diff --git a/Documentation/spi/index.rst b/Documentation/spi/index.rst
index ac0c2233ce48..3f723e2c07da 100644
--- a/Documentation/spi/index.rst
+++ b/Documentation/spi/index.rst
@@ -8,6 +8,7 @@ Serial Peripheral Interface (SPI)
:maxdepth: 1
spi-summary
+ instantiating-devices
spidev
multiple-data-lanes
butterfly
diff --git a/Documentation/spi/instantiating-devices.rst b/Documentation/spi/instantiating-devices.rst
new file mode 100644
index 000000000000..9ed08d94ae01
--- /dev/null
+++ b/Documentation/spi/instantiating-devices.rst
@@ -0,0 +1,88 @@
+.. SPDX-License-Identifier: GPL-2.0
+
+==============================
+How to instantiate SPI devices
+==============================
+
+SPI devices are normally declared statically via device-tree, ACPI, or
+board files. When the SPI controller is registered, these devices are
+instantiated automatically by the SPI core. This is the preferred method
+for any device with a proper kernel driver.
+
+Instantiate from user-space
+---------------------------
+
+In certain cases a SPI device cannot be declared statically:
+
+* The ``spidev`` driver, which provides raw userspace access to SPI
+ buses, explicitly rejects the bare ``"spidev"`` compatible string in
+ device-tree because spidev is a Linux implementation detail, not a
+ hardware description. Vendor-specific compatible strings for spidev
+ (e.g. ``"vendor,board-spidev"``) are also generally not accepted
+ upstream. Device-tree overlays do not help here either, since the
+ spidev driver performs the same compatible check regardless of how
+ the DT node was loaded.
+
+* You are developing or testing a SPI device on a development board
+ where the SPI bus is exposed on expansion headers, and the connected
+ device may change frequently.
+
+For these cases, a sysfs interface is provided on each SPI controller
+(similar to the I2C ``new_device``/``delete_device`` interface described
+in Documentation/i2c/instantiating-devices.rst). Two write-only
+attribute files are created in every SPI controller directory:
+``new_device`` and ``delete_device``.
+
+File ``new_device`` takes 2 to 4 parameters: the name of the SPI
+device (a string), the chip select number, and optionally
+``max_speed_hz`` and ``mode``::
+
+ <modalias> <chip_select> [<max_speed_hz> [<mode>]]
+
+The modalias is set both as the device's ``modalias`` field and as its
+``driver_override``. This ensures that the device binds to the named
+driver directly, bypassing the normal bus matching logic (OF, ACPI,
+and ``id_table``). This is necessary because drivers like ``spidev``
+deliberately exclude generic names from their ``id_table``.
+
+If ``max_speed_hz`` is omitted or 0, ``spi_setup()`` clamps it to
+the controller's maximum speed. If ``mode`` is omitted, SPI mode 0
+(CPOL=0, CPHA=0) is used.
+
+File ``delete_device`` takes a single parameter: the chip select
+number. As no two devices can share a chip select on a given SPI bus,
+the chip select is sufficient to uniquely identify the device.
+
+Examples::
+
+ # Create a spidev device on SPI bus 0, chip select 0
+ echo spidev 0 > /sys/class/spi_master/spi0/new_device
+
+ # Create with explicit clock rate and SPI mode
+ echo spidev 0 10000000 3 > /sys/class/spi_master/spi0/new_device
+
+ # Remove the device
+ echo 0 > /sys/class/spi_master/spi0/delete_device
+
+On systems that need spidev access at boot, a systemd service or
+udev rule can write to ``new_device`` after the SPI controller is
+available.
+
+Limitations
+^^^^^^^^^^^
+
+Devices created through this interface have the following limitations
+compared to devices declared via device-tree:
+
+* No interrupt (IRQ) support.
+* No additional properties such as ``spi-max-frequency`` DT bindings
+ or controller-specific configuration.
+* No platform data or software nodes.
+
+For ``spidev`` usage these limitations are not relevant, since spidev
+provides a raw byte-level interface that does not require any of these
+features.
+
+Only devices created via ``new_device`` can be removed through
+``delete_device``. Devices declared via device-tree, ACPI, or board
+files are not affected by this interface.
--
2.17.1
^ permalink raw reply related
* [PATCH v3 0/2] spi: add sysfs interface for userspace device instantiation
From: Vishwaroop A @ 2026-05-04 7:40 UTC (permalink / raw)
To: broonie, linux-spi
Cc: smangipudi, jonathanh, thierry.reding, corbet, linux-doc, va
Development boards such as the Jetson AGX Orin expose SPI buses on
expansion headers so that users can connect and interact with SPI
peripherals from userspace via /dev/spidevB.C character devices.
Today, instantiating spidev devices on upstream kernels is impractical:
the spidev driver rejects bare "spidev" compatible strings in DT, and
vendor-specific strings have been rejected by DT maintainers.
This series adds an I2C-style new_device/delete_device sysfs interface
to SPI host controllers, enabling runtime device instantiation from
userspace without any device-tree changes.
Patch 1 adds the core sysfs interface (new_device/delete_device).
Patch 2 adds user-facing documentation and ABI entries.
Changes in v3:
- Made the entire feature conditional on CONFIG_SPI_DYNAMIC using
#if IS_ENABLED(CONFIG_SPI_DYNAMIC) preprocessor guards, since this
adds a new way of dynamically instantiating and removing SPI
devices and the add_lock locking in spi_unregister_controller() is
already conditional on CONFIG_SPI_DYNAMIC (Mark Brown)
- Wrapped userspace_clients list, lock, and userspace_node struct
members in #if IS_ENABLED(CONFIG_SPI_DYNAMIC) in spi.h
- Started a new thread instead of replying to v2 (Mark Brown)
Changes in v2:
- Fixed a race between new_device_store() and
spi_unregister_controller(): hold ctlr->add_lock across both
__spi_add_device() and the list insertion so the two operations
are atomic with respect to controller teardown (Mark Brown)
Vishwaroop A (2):
spi: add new_device/delete_device sysfs interface
docs: spi: add documentation for userspace device instantiation
.../ABI/testing/sysfs-class-spi-master | 34 +++
Documentation/spi/index.rst | 1 +
Documentation/spi/instantiating-devices.rst | 88 ++++++++
drivers/spi/spi.c | 206 ++++++++++++++++++
include/linux/spi/spi.h | 12 +
5 files changed, 341 insertions(+)
create mode 100644 Documentation/ABI/testing/sysfs-class-spi-master
create mode 100644 Documentation/spi/instantiating-devices.rst
--
2.17.1
^ permalink raw reply
* RE: [PATCH net-next 5/5] dt-bindings: net: Add bindings for the ADIN1140
From: Regus, Ciprian @ 2026-05-04 7:33 UTC (permalink / raw)
To: Andrew Lunn
Cc: Parthiban Veerasooran, Andrew Lunn, David S. Miller, Eric Dumazet,
Jakub Kicinski, Paolo Abeni, Simon Horman, Jonathan Corbet,
Shuah Khan, Heiner Kallweit, Russell King, Rob Herring,
Krzysztof Kozlowski, Conor Dooley, netdev@vger.kernel.org,
linux-kernel@vger.kernel.org, linux-doc@vger.kernel.org,
devicetree@vger.kernel.org
In-Reply-To: <05ae6249-1f40-4530-b2dc-e52e4f454c0d@lunn.ch>
> -----Original Message-----
> From: Andrew Lunn <andrew@lunn.ch>
> Sent: Sunday, May 3, 2026 4:07 AM
> To: Regus, Ciprian <Ciprian.Regus@analog.com>
> Cc: Parthiban Veerasooran <parthiban.veerasooran@microchip.com>;
> Andrew Lunn <andrew+netdev@lunn.ch>; David S. Miller
> <davem@davemloft.net>; Eric Dumazet <edumazet@google.com>; Jakub
> Kicinski <kuba@kernel.org>; Paolo Abeni <pabeni@redhat.com>; Simon
> Horman <horms@kernel.org>; Jonathan Corbet <corbet@lwn.net>; Shuah
> Khan <skhan@linuxfoundation.org>; Heiner Kallweit
> <hkallweit1@gmail.com>; Russell King <linux@armlinux.org.uk>; Rob Herring
> <robh@kernel.org>; Krzysztof Kozlowski <krzk+dt@kernel.org>; Conor
> Dooley <conor+dt@kernel.org>; netdev@vger.kernel.org; linux-
> kernel@vger.kernel.org; linux-doc@vger.kernel.org;
> devicetree@vger.kernel.org
> Subject: Re: [PATCH net-next 5/5] dt-bindings: net: Add bindings for the
> ADIN1140
>
> [External]
>
> > + The ADIN1140 (also called AD3306) is a low power single port
> > + 10BASE-T1S MAC-PHY. It integrates an Ethernet PHY with a MAC
> > + and all the associated analog circuitry.
> > + The device implements the Open Alliance TC6 10BASE-T1x MAC-PHY
>
> The device _tries_ to implements the Open Alliance TC6 10BASE-T1x MAC-
> PHY.
Will update in v2.
>
> > +examples:
> > + - |
> > + #include <dt-bindings/interrupt-controller/irq.h>
> > +
> > + spi {
> > + #address-cells = <1>;
> > + #size-cells = <0>;
> > +
> > + ethernet@0 {
> > + compatible = "adi,adin1140";
> > + reg = <0>;
> > + spi-max-frequency = <23000000>;
> > +
> > + interrupt-parent = <&gpio>;
> > + interrupts = <6 IRQ_TYPE_EDGE_FALLING>;
>
> Table 1: OPEN serial 10BASE-T1x Interface Pin Definition
>
> IRQn MAC-PHY Interrupt Request (Active Low)
>
> Or is this something else which the device gets wrong?
The device generates interrupts correctly (the IRQ signal remains
asserted while there are active interrupt conditions that have not
been cleared yet). The oa_tc6 driver requests the interrupt with
the IRQF_TRIGGER_FALLING flag set, so the DT flag will be overridden
and the behavior remains the same.
However, the devicetree shouldn't care about this. I'll update to
IRQ_TYPE_LEVEL_LOW in v2.
>
> Andrew
^ permalink raw reply
* Re: [PATCH v4 00/10] Auto-generate maintainer profile entries
From: Mauro Carvalho Chehab @ 2026-05-04 7:00 UTC (permalink / raw)
To: Jonathan Corbet
Cc: Albert Ou, Mauro Carvalho Chehab, Palmer Dabbelt, Paul Walmsley,
linux-doc, linux-kernel, linux-riscv, workflows, Alexandre Ghiti,
Shuah Khan, Randy Dunlap, Dan Williams
In-Reply-To: <87lde0bii2.fsf@trenco.lwn.net>
On Sun, 03 May 2026 09:49:41 -0600
Jonathan Corbet <corbet@lwn.net> wrote:
> Mauro Carvalho Chehab <mchehab+huawei@kernel.org> writes:
>
> > Hi Jon,
> >
> > This is basically the same patch series I sent during the merge
> > window, rebased on the top of post 7.1-rc1 docs-next branch.
> > It is tested both with and without O=DOCS.
> >
> > It contains just one extra trivial patch adding a missing SPDX
> > header, and, on v4, I dropped two patches touching MAINTAINERS,
> > as those aren't needed anymore.
> >
> > This patch series change the way maintainer entry profile links
> > are added to the documentation. Instead of having an entry for
> > each of them at an ReST file, get them from MAINTAINERS content.
> >
> > That should likely make easier to maintain, as there will be a single
> > point to place all such profiles.
> >
> > The output is a per-subsystem sorted (*) series of links shown as a
> > list like this:
> >
> > - Arm And Arm64 Soc Sub-Architectures (Common Parts)
> > - Arm/Samsung S3C, S5P And Exynos Arm Architectures
> > - Arm/Tesla Fsd Soc Support
> > ...
> > - Xfs Filesystem
> >
> > Please notice that the series is doing one logical change per patch.
> > I could have merged some changes altogether, but I opted doing it
> > in small steps to help reviews. If you prefer, feel free to merge
> > maintainers_include changes on merge.
> >
> > There is one interesting side effect of this series: there is no
> > need to add rst files containing profiles inside a TOC tree: Just
> > creating the file anywhere inside Documentation and adding a P entry
> > is enough. Adding them to a TOC won't hurt.
>
> One thing I kind of dislike about these magic mechanisms is that we end
> up with a single, essentially unsorted list of stuff that readers have
> to go digging their way through. It would be nice if we could somehow
> apply a bit of structure; as the number of these handbooks grows, our
> readers would appreciate it.
The output is sorted by subsystem's name:
for profile, entry in sorted(maint.profile_entries.items()):
if entry.startswith("http"):
output += f"- `{profile} <{entry}>`_\n"
else:
output += f"- :doc:`{profile} <{entry}>`\n"
But yeah, as this grows, We can apply some struct there later on.
I expect that this would be good enough for "P" entries: as such entries
are used only by the biggest subsystems, I won't expect that the profiles
list would be too big.
If I'm wrong, though, changing its output is easy, as all the parsing
were done in separate: all we have to do would be to change this part.
-
Now, for the full MAINTAINERS content, I agree with you. I have
a patch series here which splits the parsing from the output,
which allows placing its contents inside a table and with a
filter javascript [1]. On my view, the output is a lot more
interesting for readers this way [2].
> Oh well, one can always hope. Meanwhile, this seems useful, I've
> applied it.
Thanks!
---
[1] On such series, I'm creating a table with two rows:
output += ".. _maintainers_table:\n\n"
output += ".. flat-table::\n"
output += " :header-rows: 1\n\n"
output += " * - Subsystem\n"
output += " - Properties\n\n"
self.state.document['maintainers_included'] = True
for name, fields in maint_parser.maint_entries.items():
output += f" * - {name}\n"
tag = "-"
for field, lines in fields.items():
field_name = maint_parser.fields.get(field, field)
output += f" {tag} :{field_name}:\n "
output += ",\n ".join(lines) + "\n"
tag = " "
output += "\n"
Which is a lot easier to read than the current output, and adding
a small javascript that allows filtering entries, based at the
contents of either subsystem or properties. That should help
readers to seek for things they're interested.
I considered ordering it by subsystems, and did some tests with that,
but at the final version I ended removing.
The main issue is that MAINTAINERS entries aren't grouped by
subsystems. Also, we don't have any field to identify to what
subsystem each entry belongs.
Using the mailing list field helps to have something close enough,
while being fast. Even so, some caveats are needed, as:
1) several entries contain multiple ML entries, which may include:
- subsystem ML;
- LKML;
- driver-specific ML;
- vendor-specific ML.
2) several entries have only LKML.
For the purpose of grouping such entries, even after filtering out LKML,
due to (1), hints are needed to try to pick subsystem ML. Perhaps the
best hint is to check if the entry is @kernel.org, which works reasonably
well. Yet, not all subsystems have its ML there.
I also considered sorting them by the number of files, using iglob
to calculate it. That would help to place the subsystem first, followed
by subsystem drivers, and this is fast enough with my nvme disks but
this could slow kernel builds on mechanical HDs.
So, I suspect that, if we want to have something more structured,
the first step would be to do some rework at the MAINTAINERS file.
[2] I need some time to check if are there any regressions
on the patch that splits the logic.
Regards,
Mauro
^ permalink raw reply
* Re: [PATCH v11 08/11] tee: add Qualcomm TEE driver
From: Amirreza Zarrabi @ 2026-05-04 6:52 UTC (permalink / raw)
To: Dmitry Baryshkov
Cc: Jens Wiklander, Sumit Garg, Bjorn Andersson, Konrad Dybcio,
Bartosz Golaszewski, Apurupa Pattapu, Kees Cook,
Gustavo A. R. Silva, Sumit Semwal, Christian König,
Harshal Dev, linux-arm-msm, op-tee, linux-kernel, linux-hardening,
dri-devel, linaro-mm-sig, linux-doc, Neil Armstrong, Sumit Garg
In-Reply-To: <ljfhoo5o45m3t5fsqypg75c46qohvszd5azcqxyjdcr5unx7ob@vcgip4yzkmmn>
Hi,
On 4/28/2026 7:21 PM, Dmitry Baryshkov wrote:
> On Wed, Sep 10, 2025 at 08:41:21PM -0700, Amirreza Zarrabi wrote:
>> Introduce qcomtee_object, which represents an object in both QTEE and
>> the kernel. QTEE clients can invoke an instance of qcomtee_object to
>> access QTEE services. If this invocation produces a new object in QTEE,
>> an instance of qcomtee_object will be returned.
>>
>> Similarly, QTEE can request services from by issuing a callback
>> request, which invokes an instance of qcomtee_object.
>>
>> Implement initial support for exporting qcomtee_object to userspace
>> and QTEE, enabling the invocation of objects hosted in QTEE and userspace
>> through the TEE subsystem.
>>
>> Tested-by: Neil Armstrong <neil.armstrong@linaro.org>
>> Tested-by: Harshal Dev <quic_hdev@quicinc.com>
>> Acked-by: Sumit Garg <sumit.garg@oss.qualcomm.com>
>> Signed-off-by: Amirreza Zarrabi <amirreza.zarrabi@oss.qualcomm.com>
>> ---
>> MAINTAINERS | 6 +
>> drivers/tee/Kconfig | 1 +
>> drivers/tee/Makefile | 1 +
>> drivers/tee/qcomtee/Kconfig | 12 +
>> drivers/tee/qcomtee/Makefile | 7 +
>> drivers/tee/qcomtee/async.c | 182 +++++++
>> drivers/tee/qcomtee/call.c | 813 +++++++++++++++++++++++++++++++
>> drivers/tee/qcomtee/core.c | 906 +++++++++++++++++++++++++++++++++++
>> drivers/tee/qcomtee/qcomtee.h | 143 ++++++
>> drivers/tee/qcomtee/qcomtee_msg.h | 304 ++++++++++++
>> drivers/tee/qcomtee/qcomtee_object.h | 316 ++++++++++++
>> drivers/tee/qcomtee/shm.c | 153 ++++++
>> drivers/tee/qcomtee/user_obj.c | 692 ++++++++++++++++++++++++++
>> include/uapi/linux/tee.h | 1 +
>> 14 files changed, 3537 insertions(+)
>>
>> +
>> +static int
>> +qcomtee_object_invoke_ctx_invoke(struct qcomtee_object_invoke_ctx *oic,
>> + int *result, u64 *res_type)
>> +{
>> + phys_addr_t out_msg_paddr;
>> + phys_addr_t in_msg_paddr;
>> + int ret;
>> + u64 res;
>> +
>> + tee_shm_get_pa(oic->out_shm, 0, &out_msg_paddr);
>> + tee_shm_get_pa(oic->in_shm, 0, &in_msg_paddr);
>> + if (!(oic->flags & QCOMTEE_OIC_FLAG_BUSY))
>> + ret = qcom_scm_qtee_invoke_smc(in_msg_paddr, oic->in_msg.size,
>> + out_msg_paddr, oic->out_msg.size,
>> + &res, res_type);
>> + else
>> + ret = qcom_scm_qtee_callback_response(out_msg_paddr,
>> + oic->out_msg.size,
>> + &res, res_type);
>> +
>> + if (ret)
>> + pr_err("QTEE returned with %d.\n", ret);
>> + else
>> + *result = (int)res;
>
> After enablign QCOMTEE driver, I observe the following error during the
> bootup on RB3 Gen2:
>
> [ 4.720777] qcomtee: QTEE returned with -22.
> [ 4.725251] qcomtee: QTEE version 0.0.0
>
>
We are using the RB3 Gen2, and it successfully reports 5.2.0 as the version
number. However, seeing 0.0.0 is not necessarily a problem. What TZ build
are you using?
It's possible that the service responsible for returning the version number
is not available on your device, even though the object invocation itself is
supported.
Are you able to make any object-invoke calls from userspace? A simple test -
such as running the TA diagnostics tool - can help verify this:
https://github.com/quic/quic-teec
Regards,
Amir
>> +
>> + return ret;
>> +}
>> +
>
^ permalink raw reply
* [PATCH v3] tty: synclink_gt: remove broken driver
From: Ethan Nelson-Moore @ 2026-05-04 3:14 UTC (permalink / raw)
To: linux-doc, netdev, linux-serial, rust-for-linux
Cc: Ethan Nelson-Moore, Jonathan Corbet, Shuah Khan,
Madhavan Srinivasan, Michael Ellerman, Nicholas Piggin,
Christophe Leroy (CS GROUP), Andrew Lunn, David S. Miller,
Eric Dumazet, Jakub Kicinski, Paolo Abeni, Greg Kroah-Hartman,
Jiri Slaby, Miguel Ojeda, Boqun Feng, Gary Guo,
Björn Roy Baron, Benno Lossin, Andreas Hindborg, Alice Ryhl,
Trevor Gross, Danilo Krummrich, Bagas Sanjaya, Haren Myneni,
Eric Biggers, Julian Braha, Qingfang Deng
The synclink_gt driver was marked as broken in commit 426263d5fb40
("tty: synclink_gt: mark as BROKEN") in July 2023 because it had severe
structural problems and there had been no evidence of users since 2016.
Since then, no meaningful improvements have been made to the driver,
and it is unlikely that will ever happen due to the lack of interest.
Drop the driver and references to it in comments and documentation.
include/uapi/linux/synclink.h is also removed. The only use of this
header I have found is the linux-raw-sys Rust crate. It generates
bindings for all UAPI headers, but has a hardcoded list of headers and
ioctls, including this one, so that does not indicate that anyone is
using it. I have sent a pull request to remove the include and ioctl
definitions for this header (see the link below).
Link: https://github.com/sunfishcode/linux-raw-sys/pull/185
Signed-off-by: Ethan Nelson-Moore <enelsonmoore@gmail.com>
---
Changes from v2:
Remove UAPI header - I have sent a pull request to remove it from
linux-raw-sys
.../userspace-api/ioctl/ioctl-number.rst | 1 -
arch/powerpc/configs/ppc6xx_defconfig | 1 -
drivers/net/ppp/Kconfig | 4 +-
drivers/tty/Kconfig | 11 +-
drivers/tty/Makefile | 1 -
drivers/tty/n_hdlc.c | 7 -
drivers/tty/synclink_gt.c | 5038 -----------------
include/linux/synclink.h | 37 -
include/uapi/linux/synclink.h | 301 -
9 files changed, 3 insertions(+), 5398 deletions(-)
delete mode 100644 drivers/tty/synclink_gt.c
delete mode 100644 include/linux/synclink.h
delete mode 100644 include/uapi/linux/synclink.h
diff --git a/Documentation/userspace-api/ioctl/ioctl-number.rst b/Documentation/userspace-api/ioctl/ioctl-number.rst
index 331223761fff..58716f4f4834 100644
--- a/Documentation/userspace-api/ioctl/ioctl-number.rst
+++ b/Documentation/userspace-api/ioctl/ioctl-number.rst
@@ -271,7 +271,6 @@ Code Seq# Include File Comments
'm' 00-09 linux/mmtimer.h conflict!
'm' all linux/mtio.h conflict!
'm' all linux/soundcard.h conflict!
-'m' all linux/synclink.h conflict!
'm' 00-19 drivers/message/fusion/mptctl.h conflict!
'm' 00 drivers/scsi/megaraid/megaraid_ioctl.h conflict!
'n' 00-7F linux/ncp_fs.h and fs/ncpfs/ioctl.c
diff --git a/arch/powerpc/configs/ppc6xx_defconfig b/arch/powerpc/configs/ppc6xx_defconfig
index ccabc6e17168..4ddd2c01b8b7 100644
--- a/arch/powerpc/configs/ppc6xx_defconfig
+++ b/arch/powerpc/configs/ppc6xx_defconfig
@@ -551,7 +551,6 @@ CONFIG_GAMEPORT_EMU10K1=m
CONFIG_GAMEPORT_FM801=m
# CONFIG_LEGACY_PTYS is not set
CONFIG_SERIAL_NONSTANDARD=y
-CONFIG_SYNCLINK_GT=m
CONFIG_NOZOMI=m
CONFIG_N_HDLC=m
CONFIG_SERIAL_8250=y
diff --git a/drivers/net/ppp/Kconfig b/drivers/net/ppp/Kconfig
index 753354b4e36c..5324e2102383 100644
--- a/drivers/net/ppp/Kconfig
+++ b/drivers/net/ppp/Kconfig
@@ -191,8 +191,8 @@ config PPP_SYNC_TTY
tristate "PPP support for sync tty ports"
help
Say Y (or M) here if you want to be able to use PPP over synchronous
- (HDLC) tty devices, such as the SyncLink adapter. These devices
- are often used for high-speed leased lines like T1/E1.
+ (HDLC) tty devices. These devices are often used for high-speed leased
+ lines like T1/E1.
To compile this driver as a module, choose M here.
diff --git a/drivers/tty/Kconfig b/drivers/tty/Kconfig
index 149f3d53b760..df6832a4c237 100644
--- a/drivers/tty/Kconfig
+++ b/drivers/tty/Kconfig
@@ -231,21 +231,12 @@ config MOXA_SMARTIO
This driver can also be built as a module. The module will be called
mxser. If you want to do that, say M here.
-config SYNCLINK_GT
- tristate "SyncLink GT/AC support"
- depends on SERIAL_NONSTANDARD && PCI
- depends on BROKEN
- help
- Support for SyncLink GT and SyncLink AC families of
- synchronous and asynchronous serial adapters
- manufactured by Microgate Systems, Ltd. (www.microgate.com)
-
config N_HDLC
tristate "HDLC line discipline support"
depends on SERIAL_NONSTANDARD
help
Allows synchronous HDLC communications with tty device drivers that
- support synchronous HDLC such as the Microgate SyncLink adapter.
+ support synchronous HDLC.
This driver can be built as a module ( = code which can be
inserted in and removed from the running kernel whenever you want).
diff --git a/drivers/tty/Makefile b/drivers/tty/Makefile
index 07aca5184a55..8ca1a0a2229f 100644
--- a/drivers/tty/Makefile
+++ b/drivers/tty/Makefile
@@ -21,7 +21,6 @@ obj-$(CONFIG_MOXA_INTELLIO) += moxa.o
obj-$(CONFIG_MOXA_SMARTIO) += mxser.o
obj-$(CONFIG_NOZOMI) += nozomi.o
obj-$(CONFIG_NULL_TTY) += ttynull.o
-obj-$(CONFIG_SYNCLINK_GT) += synclink_gt.o
obj-$(CONFIG_PPC_EPAPR_HV_BYTECHAN) += ehv_bytechan.o
obj-$(CONFIG_GOLDFISH_TTY) += goldfish.o
obj-$(CONFIG_MIPS_EJTAG_FDC_TTY) += mips_ejtag_fdc.o
diff --git a/drivers/tty/n_hdlc.c b/drivers/tty/n_hdlc.c
index 98eefa2cede4..895b850a5950 100644
--- a/drivers/tty/n_hdlc.c
+++ b/drivers/tty/n_hdlc.c
@@ -4,8 +4,6 @@
* Written by Paul Fulghum paulkf@microgate.com
* for Microgate Corporation
*
- * Microgate and SyncLink are registered trademarks of Microgate Corporation
- *
* Adapted from ppp.c, written by Michael Callahan <callahan@maths.ox.ac.uk>,
* Al Longyear <longyear@netcom.com>,
* Paul Mackerras <Paul.Mackerras@cs.anu.edu.au>
@@ -54,11 +52,6 @@
* this line discipline (or another line discipline that is frame
* oriented such as N_PPP).
*
- * The SyncLink driver (synclink.c) implements both asynchronous
- * (using standard line discipline N_TTY) and synchronous HDLC
- * (using N_HDLC) communications, with the latter using the above
- * conventions.
- *
* This implementation is very basic and does not maintain
* any statistics. The main point is to enforce the raw data
* and frame orientation of HDLC communications.
diff --git a/drivers/tty/synclink_gt.c b/drivers/tty/synclink_gt.c
deleted file mode 100644
index bf4f50e0ce94..000000000000
--- a/drivers/tty/synclink_gt.c
+++ /dev/null
@@ -1,5038 +0,0 @@
-// SPDX-License-Identifier: GPL-1.0+
-/*
- * Device driver for Microgate SyncLink GT serial adapters.
- *
- * written by Paul Fulghum for Microgate Corporation
- * paulkf@microgate.com
- *
- * Microgate and SyncLink are trademarks of Microgate Corporation
- *
- * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED
- * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
- * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
- * DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT,
- * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
- * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
- * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
- * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
- * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
- * OF THE POSSIBILITY OF SUCH DAMAGE.
- */
-
-/*
- * DEBUG OUTPUT DEFINITIONS
- *
- * uncomment lines below to enable specific types of debug output
- *
- * DBGINFO information - most verbose output
- * DBGERR serious errors
- * DBGBH bottom half service routine debugging
- * DBGISR interrupt service routine debugging
- * DBGDATA output receive and transmit data
- * DBGTBUF output transmit DMA buffers and registers
- * DBGRBUF output receive DMA buffers and registers
- */
-
-#define DBGINFO(fmt) if (debug_level >= DEBUG_LEVEL_INFO) printk fmt
-#define DBGERR(fmt) if (debug_level >= DEBUG_LEVEL_ERROR) printk fmt
-#define DBGBH(fmt) if (debug_level >= DEBUG_LEVEL_BH) printk fmt
-#define DBGISR(fmt) if (debug_level >= DEBUG_LEVEL_ISR) printk fmt
-#define DBGDATA(info, buf, size, label) if (debug_level >= DEBUG_LEVEL_DATA) trace_block((info), (buf), (size), (label))
-/*#define DBGTBUF(info) dump_tbufs(info)*/
-/*#define DBGRBUF(info) dump_rbufs(info)*/
-
-
-#include <linux/module.h>
-#include <linux/errno.h>
-#include <linux/signal.h>
-#include <linux/sched.h>
-#include <linux/timer.h>
-#include <linux/interrupt.h>
-#include <linux/pci.h>
-#include <linux/tty.h>
-#include <linux/tty_flip.h>
-#include <linux/serial.h>
-#include <linux/major.h>
-#include <linux/string.h>
-#include <linux/fcntl.h>
-#include <linux/ptrace.h>
-#include <linux/ioport.h>
-#include <linux/mm.h>
-#include <linux/seq_file.h>
-#include <linux/slab.h>
-#include <linux/netdevice.h>
-#include <linux/vmalloc.h>
-#include <linux/init.h>
-#include <linux/delay.h>
-#include <linux/ioctl.h>
-#include <linux/termios.h>
-#include <linux/bitops.h>
-#include <linux/workqueue.h>
-#include <linux/hdlc.h>
-#include <linux/synclink.h>
-
-#include <asm/io.h>
-#include <asm/irq.h>
-#include <asm/dma.h>
-#include <asm/types.h>
-#include <linux/uaccess.h>
-
-#if defined(CONFIG_HDLC) || (defined(CONFIG_HDLC_MODULE) && defined(CONFIG_SYNCLINK_GT_MODULE))
-#define SYNCLINK_GENERIC_HDLC 1
-#else
-#define SYNCLINK_GENERIC_HDLC 0
-#endif
-
-/*
- * module identification
- */
-static const char driver_name[] = "SyncLink GT";
-static const char tty_dev_prefix[] = "ttySLG";
-MODULE_DESCRIPTION("Device driver for Microgate SyncLink GT serial adapters");
-MODULE_LICENSE("GPL");
-#define MAX_DEVICES 32
-
-static const struct pci_device_id pci_table[] = {
- { PCI_VDEVICE(MICROGATE, SYNCLINK_GT_DEVICE_ID) },
- { PCI_VDEVICE(MICROGATE, SYNCLINK_GT2_DEVICE_ID) },
- { PCI_VDEVICE(MICROGATE, SYNCLINK_GT4_DEVICE_ID) },
- { PCI_VDEVICE(MICROGATE, SYNCLINK_AC_DEVICE_ID) },
- { 0 }, /* terminate list */
-};
-MODULE_DEVICE_TABLE(pci, pci_table);
-
-static int init_one(struct pci_dev *dev,const struct pci_device_id *ent);
-static void remove_one(struct pci_dev *dev);
-static struct pci_driver pci_driver = {
- .name = "synclink_gt",
- .id_table = pci_table,
- .probe = init_one,
- .remove = remove_one,
-};
-
-static bool pci_registered;
-
-/*
- * module configuration and status
- */
-static struct slgt_info *slgt_device_list;
-static int slgt_device_count;
-
-static int ttymajor;
-static int debug_level;
-static int maxframe[MAX_DEVICES];
-
-module_param(ttymajor, int, 0);
-module_param(debug_level, int, 0);
-module_param_array(maxframe, int, NULL, 0);
-
-MODULE_PARM_DESC(ttymajor, "TTY major device number override: 0=auto assigned");
-MODULE_PARM_DESC(debug_level, "Debug syslog output: 0=disabled, 1 to 5=increasing detail");
-MODULE_PARM_DESC(maxframe, "Maximum frame size used by device (4096 to 65535)");
-
-/*
- * tty support and callbacks
- */
-static struct tty_driver *serial_driver;
-
-static void wait_until_sent(struct tty_struct *tty, int timeout);
-static void flush_buffer(struct tty_struct *tty);
-static void tx_release(struct tty_struct *tty);
-
-/*
- * generic HDLC support
- */
-#define dev_to_port(D) (dev_to_hdlc(D)->priv)
-
-
-/*
- * device specific structures, macros and functions
- */
-
-#define SLGT_MAX_PORTS 4
-#define SLGT_REG_SIZE 256
-
-/*
- * conditional wait facility
- */
-struct cond_wait {
- struct cond_wait *next;
- wait_queue_head_t q;
- wait_queue_entry_t wait;
- unsigned int data;
-};
-static void flush_cond_wait(struct cond_wait **head);
-
-/*
- * DMA buffer descriptor and access macros
- */
-struct slgt_desc
-{
- __le16 count;
- __le16 status;
- __le32 pbuf; /* physical address of data buffer */
- __le32 next; /* physical address of next descriptor */
-
- /* driver book keeping */
- char *buf; /* virtual address of data buffer */
- unsigned int pdesc; /* physical address of this descriptor */
- dma_addr_t buf_dma_addr;
- unsigned short buf_count;
-};
-
-#define set_desc_buffer(a,b) (a).pbuf = cpu_to_le32((unsigned int)(b))
-#define set_desc_next(a,b) (a).next = cpu_to_le32((unsigned int)(b))
-#define set_desc_count(a,b)(a).count = cpu_to_le16((unsigned short)(b))
-#define set_desc_eof(a,b) (a).status = cpu_to_le16((b) ? (le16_to_cpu((a).status) | BIT0) : (le16_to_cpu((a).status) & ~BIT0))
-#define set_desc_status(a, b) (a).status = cpu_to_le16((unsigned short)(b))
-#define desc_count(a) (le16_to_cpu((a).count))
-#define desc_status(a) (le16_to_cpu((a).status))
-#define desc_complete(a) (le16_to_cpu((a).status) & BIT15)
-#define desc_eof(a) (le16_to_cpu((a).status) & BIT2)
-#define desc_crc_error(a) (le16_to_cpu((a).status) & BIT1)
-#define desc_abort(a) (le16_to_cpu((a).status) & BIT0)
-#define desc_residue(a) ((le16_to_cpu((a).status) & 0x38) >> 3)
-
-struct _input_signal_events {
- int ri_up;
- int ri_down;
- int dsr_up;
- int dsr_down;
- int dcd_up;
- int dcd_down;
- int cts_up;
- int cts_down;
-};
-
-/*
- * device instance data structure
- */
-struct slgt_info {
- void *if_ptr; /* General purpose pointer (used by SPPP) */
- struct tty_port port;
-
- struct slgt_info *next_device; /* device list link */
-
- char device_name[25];
- struct pci_dev *pdev;
-
- int port_count; /* count of ports on adapter */
- int adapter_num; /* adapter instance number */
- int port_num; /* port instance number */
-
- /* array of pointers to port contexts on this adapter */
- struct slgt_info *port_array[SLGT_MAX_PORTS];
-
- int line; /* tty line instance number */
-
- struct mgsl_icount icount;
-
- int timeout;
- int x_char; /* xon/xoff character */
- unsigned int read_status_mask;
- unsigned int ignore_status_mask;
-
- wait_queue_head_t status_event_wait_q;
- wait_queue_head_t event_wait_q;
- struct timer_list tx_timer;
- struct timer_list rx_timer;
-
- unsigned int gpio_present;
- struct cond_wait *gpio_wait_q;
-
- spinlock_t lock; /* spinlock for synchronizing with ISR */
-
- struct work_struct task;
- u32 pending_bh;
- bool bh_requested;
- bool bh_running;
-
- int isr_overflow;
- bool irq_requested; /* true if IRQ requested */
- bool irq_occurred; /* for diagnostics use */
-
- /* device configuration */
-
- unsigned int bus_type;
- unsigned int irq_level;
- unsigned long irq_flags;
-
- unsigned char __iomem * reg_addr; /* memory mapped registers address */
- u32 phys_reg_addr;
- bool reg_addr_requested;
-
- MGSL_PARAMS params; /* communications parameters */
- u32 idle_mode;
- u32 max_frame_size; /* as set by device config */
-
- unsigned int rbuf_fill_level;
- unsigned int rx_pio;
- unsigned int if_mode;
- unsigned int base_clock;
- unsigned int xsync;
- unsigned int xctrl;
-
- /* device status */
-
- bool rx_enabled;
- bool rx_restart;
-
- bool tx_enabled;
- bool tx_active;
-
- unsigned char signals; /* serial signal states */
- int init_error; /* initialization error */
-
- unsigned char *tx_buf;
- int tx_count;
-
- bool drop_rts_on_tx_done;
- struct _input_signal_events input_signal_events;
-
- int dcd_chkcount; /* check counts to prevent */
- int cts_chkcount; /* too many IRQs if a signal */
- int dsr_chkcount; /* is floating */
- int ri_chkcount;
-
- char *bufs; /* virtual address of DMA buffer lists */
- dma_addr_t bufs_dma_addr; /* physical address of buffer descriptors */
-
- unsigned int rbuf_count;
- struct slgt_desc *rbufs;
- unsigned int rbuf_current;
- unsigned int rbuf_index;
- unsigned int rbuf_fill_index;
- unsigned short rbuf_fill_count;
-
- unsigned int tbuf_count;
- struct slgt_desc *tbufs;
- unsigned int tbuf_current;
- unsigned int tbuf_start;
-
- unsigned char *tmp_rbuf;
- unsigned int tmp_rbuf_count;
-
- /* SPPP/Cisco HDLC device parts */
-
- int netcount;
- spinlock_t netlock;
-#if SYNCLINK_GENERIC_HDLC
- struct net_device *netdev;
-#endif
-
-};
-
-static const MGSL_PARAMS default_params = {
- .mode = MGSL_MODE_HDLC,
- .loopback = 0,
- .flags = HDLC_FLAG_UNDERRUN_ABORT15,
- .encoding = HDLC_ENCODING_NRZI_SPACE,
- .clock_speed = 0,
- .addr_filter = 0xff,
- .crc_type = HDLC_CRC_16_CCITT,
- .preamble_length = HDLC_PREAMBLE_LENGTH_8BITS,
- .preamble = HDLC_PREAMBLE_PATTERN_NONE,
- .data_rate = 9600,
- .data_bits = 8,
- .stop_bits = 1,
- .parity = ASYNC_PARITY_NONE
-};
-
-
-#define BH_RECEIVE 1
-#define BH_TRANSMIT 2
-#define BH_STATUS 4
-#define IO_PIN_SHUTDOWN_LIMIT 100
-
-#define DMABUFSIZE 256
-#define DESC_LIST_SIZE 4096
-
-#define MASK_PARITY BIT1
-#define MASK_FRAMING BIT0
-#define MASK_BREAK BIT14
-#define MASK_OVERRUN BIT4
-
-#define GSR 0x00 /* global status */
-#define JCR 0x04 /* JTAG control */
-#define IODR 0x08 /* GPIO direction */
-#define IOER 0x0c /* GPIO interrupt enable */
-#define IOVR 0x10 /* GPIO value */
-#define IOSR 0x14 /* GPIO interrupt status */
-#define TDR 0x80 /* tx data */
-#define RDR 0x80 /* rx data */
-#define TCR 0x82 /* tx control */
-#define TIR 0x84 /* tx idle */
-#define TPR 0x85 /* tx preamble */
-#define RCR 0x86 /* rx control */
-#define VCR 0x88 /* V.24 control */
-#define CCR 0x89 /* clock control */
-#define BDR 0x8a /* baud divisor */
-#define SCR 0x8c /* serial control */
-#define SSR 0x8e /* serial status */
-#define RDCSR 0x90 /* rx DMA control/status */
-#define TDCSR 0x94 /* tx DMA control/status */
-#define RDDAR 0x98 /* rx DMA descriptor address */
-#define TDDAR 0x9c /* tx DMA descriptor address */
-#define XSR 0x40 /* extended sync pattern */
-#define XCR 0x44 /* extended control */
-
-#define RXIDLE BIT14
-#define RXBREAK BIT14
-#define IRQ_TXDATA BIT13
-#define IRQ_TXIDLE BIT12
-#define IRQ_TXUNDER BIT11 /* HDLC */
-#define IRQ_RXDATA BIT10
-#define IRQ_RXIDLE BIT9 /* HDLC */
-#define IRQ_RXBREAK BIT9 /* async */
-#define IRQ_RXOVER BIT8
-#define IRQ_DSR BIT7
-#define IRQ_CTS BIT6
-#define IRQ_DCD BIT5
-#define IRQ_RI BIT4
-#define IRQ_ALL 0x3ff0
-#define IRQ_MASTER BIT0
-
-#define slgt_irq_on(info, mask) \
- wr_reg16((info), SCR, (unsigned short)(rd_reg16((info), SCR) | (mask)))
-#define slgt_irq_off(info, mask) \
- wr_reg16((info), SCR, (unsigned short)(rd_reg16((info), SCR) & ~(mask)))
-
-static __u8 rd_reg8(struct slgt_info *info, unsigned int addr);
-static void wr_reg8(struct slgt_info *info, unsigned int addr, __u8 value);
-static __u16 rd_reg16(struct slgt_info *info, unsigned int addr);
-static void wr_reg16(struct slgt_info *info, unsigned int addr, __u16 value);
-static __u32 rd_reg32(struct slgt_info *info, unsigned int addr);
-static void wr_reg32(struct slgt_info *info, unsigned int addr, __u32 value);
-
-static void msc_set_vcr(struct slgt_info *info);
-
-static int startup_hw(struct slgt_info *info);
-static int block_til_ready(struct tty_struct *tty, struct file * filp,struct slgt_info *info);
-static void shutdown_hw(struct slgt_info *info);
-static void program_hw(struct slgt_info *info);
-static void change_params(struct slgt_info *info);
-
-static int adapter_test(struct slgt_info *info);
-
-static void reset_port(struct slgt_info *info);
-static void async_mode(struct slgt_info *info);
-static void sync_mode(struct slgt_info *info);
-
-static void rx_stop(struct slgt_info *info);
-static void rx_start(struct slgt_info *info);
-static void reset_rbufs(struct slgt_info *info);
-static void free_rbufs(struct slgt_info *info, unsigned int first, unsigned int last);
-static bool rx_get_frame(struct slgt_info *info);
-static bool rx_get_buf(struct slgt_info *info);
-
-static void tx_start(struct slgt_info *info);
-static void tx_stop(struct slgt_info *info);
-static void tx_set_idle(struct slgt_info *info);
-static unsigned int tbuf_bytes(struct slgt_info *info);
-static void reset_tbufs(struct slgt_info *info);
-static void tdma_reset(struct slgt_info *info);
-static bool tx_load(struct slgt_info *info, const u8 *buf, unsigned int count);
-
-static void get_gtsignals(struct slgt_info *info);
-static void set_gtsignals(struct slgt_info *info);
-static void set_rate(struct slgt_info *info, u32 data_rate);
-
-static void bh_transmit(struct slgt_info *info);
-static void isr_txeom(struct slgt_info *info, unsigned short status);
-
-static void tx_timeout(struct timer_list *t);
-static void rx_timeout(struct timer_list *t);
-
-/*
- * ioctl handlers
- */
-static int get_stats(struct slgt_info *info, struct mgsl_icount __user *user_icount);
-static int get_params(struct slgt_info *info, MGSL_PARAMS __user *params);
-static int set_params(struct slgt_info *info, MGSL_PARAMS __user *params);
-static int get_txidle(struct slgt_info *info, int __user *idle_mode);
-static int set_txidle(struct slgt_info *info, int idle_mode);
-static int tx_enable(struct slgt_info *info, int enable);
-static int tx_abort(struct slgt_info *info);
-static int rx_enable(struct slgt_info *info, int enable);
-static int modem_input_wait(struct slgt_info *info,int arg);
-static int wait_mgsl_event(struct slgt_info *info, int __user *mask_ptr);
-static int get_interface(struct slgt_info *info, int __user *if_mode);
-static int set_interface(struct slgt_info *info, int if_mode);
-static int set_gpio(struct slgt_info *info, struct gpio_desc __user *gpio);
-static int get_gpio(struct slgt_info *info, struct gpio_desc __user *gpio);
-static int wait_gpio(struct slgt_info *info, struct gpio_desc __user *gpio);
-static int get_xsync(struct slgt_info *info, int __user *if_mode);
-static int set_xsync(struct slgt_info *info, int if_mode);
-static int get_xctrl(struct slgt_info *info, int __user *if_mode);
-static int set_xctrl(struct slgt_info *info, int if_mode);
-
-/*
- * driver functions
- */
-static void release_resources(struct slgt_info *info);
-
-/*
- * DEBUG OUTPUT CODE
- */
-#ifndef DBGINFO
-#define DBGINFO(fmt)
-#endif
-#ifndef DBGERR
-#define DBGERR(fmt)
-#endif
-#ifndef DBGBH
-#define DBGBH(fmt)
-#endif
-#ifndef DBGISR
-#define DBGISR(fmt)
-#endif
-
-#ifdef DBGDATA
-static void trace_block(struct slgt_info *info, const char *data, int count, const char *label)
-{
- int i;
- int linecount;
- printk("%s %s data:\n",info->device_name, label);
- while(count) {
- linecount = (count > 16) ? 16 : count;
- for(i=0; i < linecount; i++)
- printk("%02X ",(unsigned char)data[i]);
- for(;i<17;i++)
- printk(" ");
- for(i=0;i<linecount;i++) {
- if (data[i]>=040 && data[i]<=0176)
- printk("%c",data[i]);
- else
- printk(".");
- }
- printk("\n");
- data += linecount;
- count -= linecount;
- }
-}
-#else
-#define DBGDATA(info, buf, size, label)
-#endif
-
-#ifdef DBGTBUF
-static void dump_tbufs(struct slgt_info *info)
-{
- int i;
- printk("tbuf_current=%d\n", info->tbuf_current);
- for (i=0 ; i < info->tbuf_count ; i++) {
- printk("%d: count=%04X status=%04X\n",
- i, le16_to_cpu(info->tbufs[i].count), le16_to_cpu(info->tbufs[i].status));
- }
-}
-#else
-#define DBGTBUF(info)
-#endif
-
-#ifdef DBGRBUF
-static void dump_rbufs(struct slgt_info *info)
-{
- int i;
- printk("rbuf_current=%d\n", info->rbuf_current);
- for (i=0 ; i < info->rbuf_count ; i++) {
- printk("%d: count=%04X status=%04X\n",
- i, le16_to_cpu(info->rbufs[i].count), le16_to_cpu(info->rbufs[i].status));
- }
-}
-#else
-#define DBGRBUF(info)
-#endif
-
-static inline int sanity_check(struct slgt_info *info, char *devname, const char *name)
-{
-#ifdef SANITY_CHECK
- if (!info) {
- printk("null struct slgt_info for (%s) in %s\n", devname, name);
- return 1;
- }
-#else
- if (!info)
- return 1;
-#endif
- return 0;
-}
-
-/*
- * line discipline callback wrappers
- *
- * The wrappers maintain line discipline references
- * while calling into the line discipline.
- *
- * ldisc_receive_buf - pass receive data to line discipline
- */
-static void ldisc_receive_buf(struct tty_struct *tty,
- const __u8 *data, char *flags, int count)
-{
- struct tty_ldisc *ld;
- if (!tty)
- return;
- ld = tty_ldisc_ref(tty);
- if (ld) {
- if (ld->ops->receive_buf)
- ld->ops->receive_buf(tty, data, flags, count);
- tty_ldisc_deref(ld);
- }
-}
-
-/* tty callbacks */
-
-static int open(struct tty_struct *tty, struct file *filp)
-{
- struct slgt_info *info;
- int retval, line;
- unsigned long flags;
-
- line = tty->index;
- if (line >= slgt_device_count) {
- DBGERR(("%s: open with invalid line #%d.\n", driver_name, line));
- return -ENODEV;
- }
-
- info = slgt_device_list;
- while(info && info->line != line)
- info = info->next_device;
- if (sanity_check(info, tty->name, "open"))
- return -ENODEV;
- if (info->init_error) {
- DBGERR(("%s init error=%d\n", info->device_name, info->init_error));
- return -ENODEV;
- }
-
- tty->driver_data = info;
- info->port.tty = tty;
-
- DBGINFO(("%s open, old ref count = %d\n", info->device_name, info->port.count));
-
- mutex_lock(&info->port.mutex);
-
- spin_lock_irqsave(&info->netlock, flags);
- if (info->netcount) {
- retval = -EBUSY;
- spin_unlock_irqrestore(&info->netlock, flags);
- mutex_unlock(&info->port.mutex);
- goto cleanup;
- }
- info->port.count++;
- spin_unlock_irqrestore(&info->netlock, flags);
-
- if (info->port.count == 1) {
- /* 1st open on this device, init hardware */
- retval = startup_hw(info);
- if (retval < 0) {
- mutex_unlock(&info->port.mutex);
- goto cleanup;
- }
- }
- mutex_unlock(&info->port.mutex);
- retval = block_til_ready(tty, filp, info);
- if (retval) {
- DBGINFO(("%s block_til_ready rc=%d\n", info->device_name, retval));
- goto cleanup;
- }
-
- retval = 0;
-
-cleanup:
- if (retval) {
- if (tty->count == 1)
- info->port.tty = NULL; /* tty layer will release tty struct */
- if(info->port.count)
- info->port.count--;
- }
-
- DBGINFO(("%s open rc=%d\n", info->device_name, retval));
- return retval;
-}
-
-static void close(struct tty_struct *tty, struct file *filp)
-{
- struct slgt_info *info = tty->driver_data;
-
- if (sanity_check(info, tty->name, "close"))
- return;
- DBGINFO(("%s close entry, count=%d\n", info->device_name, info->port.count));
-
- if (tty_port_close_start(&info->port, tty, filp) == 0)
- goto cleanup;
-
- mutex_lock(&info->port.mutex);
- if (tty_port_initialized(&info->port))
- wait_until_sent(tty, info->timeout);
- flush_buffer(tty);
- tty_ldisc_flush(tty);
-
- shutdown_hw(info);
- mutex_unlock(&info->port.mutex);
-
- tty_port_close_end(&info->port, tty);
- info->port.tty = NULL;
-cleanup:
- DBGINFO(("%s close exit, count=%d\n", tty->driver->name, info->port.count));
-}
-
-static void hangup(struct tty_struct *tty)
-{
- struct slgt_info *info = tty->driver_data;
- unsigned long flags;
-
- if (sanity_check(info, tty->name, "hangup"))
- return;
- DBGINFO(("%s hangup\n", info->device_name));
-
- flush_buffer(tty);
-
- mutex_lock(&info->port.mutex);
- shutdown_hw(info);
-
- spin_lock_irqsave(&info->port.lock, flags);
- info->port.count = 0;
- info->port.tty = NULL;
- spin_unlock_irqrestore(&info->port.lock, flags);
- tty_port_set_active(&info->port, false);
- mutex_unlock(&info->port.mutex);
-
- wake_up_interruptible(&info->port.open_wait);
-}
-
-static void set_termios(struct tty_struct *tty,
- const struct ktermios *old_termios)
-{
- struct slgt_info *info = tty->driver_data;
- unsigned long flags;
-
- DBGINFO(("%s set_termios\n", tty->driver->name));
-
- change_params(info);
-
- /* Handle transition to B0 status */
- if ((old_termios->c_cflag & CBAUD) && !C_BAUD(tty)) {
- info->signals &= ~(SerialSignal_RTS | SerialSignal_DTR);
- spin_lock_irqsave(&info->lock,flags);
- set_gtsignals(info);
- spin_unlock_irqrestore(&info->lock,flags);
- }
-
- /* Handle transition away from B0 status */
- if (!(old_termios->c_cflag & CBAUD) && C_BAUD(tty)) {
- info->signals |= SerialSignal_DTR;
- if (!C_CRTSCTS(tty) || !tty_throttled(tty))
- info->signals |= SerialSignal_RTS;
- spin_lock_irqsave(&info->lock,flags);
- set_gtsignals(info);
- spin_unlock_irqrestore(&info->lock,flags);
- }
-
- /* Handle turning off CRTSCTS */
- if ((old_termios->c_cflag & CRTSCTS) && !C_CRTSCTS(tty)) {
- tty->hw_stopped = false;
- tx_release(tty);
- }
-}
-
-static void update_tx_timer(struct slgt_info *info)
-{
- /*
- * use worst case speed of 1200bps to calculate transmit timeout
- * based on data in buffers (tbuf_bytes) and FIFO (128 bytes)
- */
- if (info->params.mode == MGSL_MODE_HDLC) {
- int timeout = (tbuf_bytes(info) * 7) + 1000;
- mod_timer(&info->tx_timer, jiffies + msecs_to_jiffies(timeout));
- }
-}
-
-static ssize_t write(struct tty_struct *tty, const u8 *buf, size_t count)
-{
- int ret = 0;
- struct slgt_info *info = tty->driver_data;
- unsigned long flags;
-
- if (sanity_check(info, tty->name, "write"))
- return -EIO;
-
- DBGINFO(("%s write count=%zu\n", info->device_name, count));
-
- if (!info->tx_buf || (count > info->max_frame_size))
- return -EIO;
-
- if (!count || tty->flow.stopped || tty->hw_stopped)
- return 0;
-
- spin_lock_irqsave(&info->lock, flags);
-
- if (info->tx_count) {
- /* send accumulated data from send_char() */
- if (!tx_load(info, info->tx_buf, info->tx_count))
- goto cleanup;
- info->tx_count = 0;
- }
-
- if (tx_load(info, buf, count))
- ret = count;
-
-cleanup:
- spin_unlock_irqrestore(&info->lock, flags);
- DBGINFO(("%s write rc=%d\n", info->device_name, ret));
- return ret;
-}
-
-static int put_char(struct tty_struct *tty, u8 ch)
-{
- struct slgt_info *info = tty->driver_data;
- unsigned long flags;
- int ret = 0;
-
- if (sanity_check(info, tty->name, "put_char"))
- return 0;
- DBGINFO(("%s put_char(%u)\n", info->device_name, ch));
- if (!info->tx_buf)
- return 0;
- spin_lock_irqsave(&info->lock,flags);
- if (info->tx_count < info->max_frame_size) {
- info->tx_buf[info->tx_count++] = ch;
- ret = 1;
- }
- spin_unlock_irqrestore(&info->lock,flags);
- return ret;
-}
-
-static void send_xchar(struct tty_struct *tty, char ch)
-{
- struct slgt_info *info = tty->driver_data;
- unsigned long flags;
-
- if (sanity_check(info, tty->name, "send_xchar"))
- return;
- DBGINFO(("%s send_xchar(%d)\n", info->device_name, ch));
- info->x_char = ch;
- if (ch) {
- spin_lock_irqsave(&info->lock,flags);
- if (!info->tx_enabled)
- tx_start(info);
- spin_unlock_irqrestore(&info->lock,flags);
- }
-}
-
-static void wait_until_sent(struct tty_struct *tty, int timeout)
-{
- struct slgt_info *info = tty->driver_data;
- unsigned long orig_jiffies, char_time;
-
- if (!info )
- return;
- if (sanity_check(info, tty->name, "wait_until_sent"))
- return;
- DBGINFO(("%s wait_until_sent entry\n", info->device_name));
- if (!tty_port_initialized(&info->port))
- goto exit;
-
- orig_jiffies = jiffies;
-
- /* Set check interval to 1/5 of estimated time to
- * send a character, and make it at least 1. The check
- * interval should also be less than the timeout.
- * Note: use tight timings here to satisfy the NIST-PCTS.
- */
-
- if (info->params.data_rate) {
- char_time = info->timeout/(32 * 5);
- if (!char_time)
- char_time++;
- } else
- char_time = 1;
-
- if (timeout)
- char_time = min_t(unsigned long, char_time, timeout);
-
- while (info->tx_active) {
- msleep_interruptible(jiffies_to_msecs(char_time));
- if (signal_pending(current))
- break;
- if (timeout && time_after(jiffies, orig_jiffies + timeout))
- break;
- }
-exit:
- DBGINFO(("%s wait_until_sent exit\n", info->device_name));
-}
-
-static unsigned int write_room(struct tty_struct *tty)
-{
- struct slgt_info *info = tty->driver_data;
- unsigned int ret;
-
- if (sanity_check(info, tty->name, "write_room"))
- return 0;
- ret = (info->tx_active) ? 0 : HDLC_MAX_FRAME_SIZE;
- DBGINFO(("%s write_room=%u\n", info->device_name, ret));
- return ret;
-}
-
-static void flush_chars(struct tty_struct *tty)
-{
- struct slgt_info *info = tty->driver_data;
- unsigned long flags;
-
- if (sanity_check(info, tty->name, "flush_chars"))
- return;
- DBGINFO(("%s flush_chars entry tx_count=%d\n", info->device_name, info->tx_count));
-
- if (info->tx_count <= 0 || tty->flow.stopped ||
- tty->hw_stopped || !info->tx_buf)
- return;
-
- DBGINFO(("%s flush_chars start transmit\n", info->device_name));
-
- spin_lock_irqsave(&info->lock,flags);
- if (info->tx_count && tx_load(info, info->tx_buf, info->tx_count))
- info->tx_count = 0;
- spin_unlock_irqrestore(&info->lock,flags);
-}
-
-static void flush_buffer(struct tty_struct *tty)
-{
- struct slgt_info *info = tty->driver_data;
- unsigned long flags;
-
- if (sanity_check(info, tty->name, "flush_buffer"))
- return;
- DBGINFO(("%s flush_buffer\n", info->device_name));
-
- spin_lock_irqsave(&info->lock, flags);
- info->tx_count = 0;
- spin_unlock_irqrestore(&info->lock, flags);
-
- tty_wakeup(tty);
-}
-
-/*
- * throttle (stop) transmitter
- */
-static void tx_hold(struct tty_struct *tty)
-{
- struct slgt_info *info = tty->driver_data;
- unsigned long flags;
-
- if (sanity_check(info, tty->name, "tx_hold"))
- return;
- DBGINFO(("%s tx_hold\n", info->device_name));
- spin_lock_irqsave(&info->lock,flags);
- if (info->tx_enabled && info->params.mode == MGSL_MODE_ASYNC)
- tx_stop(info);
- spin_unlock_irqrestore(&info->lock,flags);
-}
-
-/*
- * release (start) transmitter
- */
-static void tx_release(struct tty_struct *tty)
-{
- struct slgt_info *info = tty->driver_data;
- unsigned long flags;
-
- if (sanity_check(info, tty->name, "tx_release"))
- return;
- DBGINFO(("%s tx_release\n", info->device_name));
- spin_lock_irqsave(&info->lock, flags);
- if (info->tx_count && tx_load(info, info->tx_buf, info->tx_count))
- info->tx_count = 0;
- spin_unlock_irqrestore(&info->lock, flags);
-}
-
-/*
- * Service an IOCTL request
- *
- * Arguments
- *
- * tty pointer to tty instance data
- * cmd IOCTL command code
- * arg command argument/context
- *
- * Return 0 if success, otherwise error code
- */
-static int ioctl(struct tty_struct *tty,
- unsigned int cmd, unsigned long arg)
-{
- struct slgt_info *info = tty->driver_data;
- void __user *argp = (void __user *)arg;
- int ret;
-
- if (sanity_check(info, tty->name, "ioctl"))
- return -ENODEV;
- DBGINFO(("%s ioctl() cmd=%08X\n", info->device_name, cmd));
-
- if (cmd != TIOCMIWAIT) {
- if (tty_io_error(tty))
- return -EIO;
- }
-
- switch (cmd) {
- case MGSL_IOCWAITEVENT:
- return wait_mgsl_event(info, argp);
- case TIOCMIWAIT:
- return modem_input_wait(info,(int)arg);
- case MGSL_IOCSGPIO:
- return set_gpio(info, argp);
- case MGSL_IOCGGPIO:
- return get_gpio(info, argp);
- case MGSL_IOCWAITGPIO:
- return wait_gpio(info, argp);
- case MGSL_IOCGXSYNC:
- return get_xsync(info, argp);
- case MGSL_IOCSXSYNC:
- return set_xsync(info, (int)arg);
- case MGSL_IOCGXCTRL:
- return get_xctrl(info, argp);
- case MGSL_IOCSXCTRL:
- return set_xctrl(info, (int)arg);
- }
- mutex_lock(&info->port.mutex);
- switch (cmd) {
- case MGSL_IOCGPARAMS:
- ret = get_params(info, argp);
- break;
- case MGSL_IOCSPARAMS:
- ret = set_params(info, argp);
- break;
- case MGSL_IOCGTXIDLE:
- ret = get_txidle(info, argp);
- break;
- case MGSL_IOCSTXIDLE:
- ret = set_txidle(info, (int)arg);
- break;
- case MGSL_IOCTXENABLE:
- ret = tx_enable(info, (int)arg);
- break;
- case MGSL_IOCRXENABLE:
- ret = rx_enable(info, (int)arg);
- break;
- case MGSL_IOCTXABORT:
- ret = tx_abort(info);
- break;
- case MGSL_IOCGSTATS:
- ret = get_stats(info, argp);
- break;
- case MGSL_IOCGIF:
- ret = get_interface(info, argp);
- break;
- case MGSL_IOCSIF:
- ret = set_interface(info,(int)arg);
- break;
- default:
- ret = -ENOIOCTLCMD;
- }
- mutex_unlock(&info->port.mutex);
- return ret;
-}
-
-static int get_icount(struct tty_struct *tty,
- struct serial_icounter_struct *icount)
-
-{
- struct slgt_info *info = tty->driver_data;
- struct mgsl_icount cnow; /* kernel counter temps */
- unsigned long flags;
-
- spin_lock_irqsave(&info->lock,flags);
- cnow = info->icount;
- spin_unlock_irqrestore(&info->lock,flags);
-
- icount->cts = cnow.cts;
- icount->dsr = cnow.dsr;
- icount->rng = cnow.rng;
- icount->dcd = cnow.dcd;
- icount->rx = cnow.rx;
- icount->tx = cnow.tx;
- icount->frame = cnow.frame;
- icount->overrun = cnow.overrun;
- icount->parity = cnow.parity;
- icount->brk = cnow.brk;
- icount->buf_overrun = cnow.buf_overrun;
-
- return 0;
-}
-
-/*
- * support for 32 bit ioctl calls on 64 bit systems
- */
-#ifdef CONFIG_COMPAT
-static long get_params32(struct slgt_info *info, struct MGSL_PARAMS32 __user *user_params)
-{
- struct MGSL_PARAMS32 tmp_params;
-
- DBGINFO(("%s get_params32\n", info->device_name));
- memset(&tmp_params, 0, sizeof(tmp_params));
- tmp_params.mode = (compat_ulong_t)info->params.mode;
- tmp_params.loopback = info->params.loopback;
- tmp_params.flags = info->params.flags;
- tmp_params.encoding = info->params.encoding;
- tmp_params.clock_speed = (compat_ulong_t)info->params.clock_speed;
- tmp_params.addr_filter = info->params.addr_filter;
- tmp_params.crc_type = info->params.crc_type;
- tmp_params.preamble_length = info->params.preamble_length;
- tmp_params.preamble = info->params.preamble;
- tmp_params.data_rate = (compat_ulong_t)info->params.data_rate;
- tmp_params.data_bits = info->params.data_bits;
- tmp_params.stop_bits = info->params.stop_bits;
- tmp_params.parity = info->params.parity;
- if (copy_to_user(user_params, &tmp_params, sizeof(struct MGSL_PARAMS32)))
- return -EFAULT;
- return 0;
-}
-
-static long set_params32(struct slgt_info *info, struct MGSL_PARAMS32 __user *new_params)
-{
- struct MGSL_PARAMS32 tmp_params;
- unsigned long flags;
-
- DBGINFO(("%s set_params32\n", info->device_name));
- if (copy_from_user(&tmp_params, new_params, sizeof(struct MGSL_PARAMS32)))
- return -EFAULT;
-
- spin_lock_irqsave(&info->lock, flags);
- if (tmp_params.mode == MGSL_MODE_BASE_CLOCK) {
- info->base_clock = tmp_params.clock_speed;
- } else {
- info->params.mode = tmp_params.mode;
- info->params.loopback = tmp_params.loopback;
- info->params.flags = tmp_params.flags;
- info->params.encoding = tmp_params.encoding;
- info->params.clock_speed = tmp_params.clock_speed;
- info->params.addr_filter = tmp_params.addr_filter;
- info->params.crc_type = tmp_params.crc_type;
- info->params.preamble_length = tmp_params.preamble_length;
- info->params.preamble = tmp_params.preamble;
- info->params.data_rate = tmp_params.data_rate;
- info->params.data_bits = tmp_params.data_bits;
- info->params.stop_bits = tmp_params.stop_bits;
- info->params.parity = tmp_params.parity;
- }
- spin_unlock_irqrestore(&info->lock, flags);
-
- program_hw(info);
-
- return 0;
-}
-
-static long slgt_compat_ioctl(struct tty_struct *tty,
- unsigned int cmd, unsigned long arg)
-{
- struct slgt_info *info = tty->driver_data;
- int rc;
-
- if (sanity_check(info, tty->name, "compat_ioctl"))
- return -ENODEV;
- DBGINFO(("%s compat_ioctl() cmd=%08X\n", info->device_name, cmd));
-
- switch (cmd) {
- case MGSL_IOCSPARAMS32:
- rc = set_params32(info, compat_ptr(arg));
- break;
-
- case MGSL_IOCGPARAMS32:
- rc = get_params32(info, compat_ptr(arg));
- break;
-
- case MGSL_IOCGPARAMS:
- case MGSL_IOCSPARAMS:
- case MGSL_IOCGTXIDLE:
- case MGSL_IOCGSTATS:
- case MGSL_IOCWAITEVENT:
- case MGSL_IOCGIF:
- case MGSL_IOCSGPIO:
- case MGSL_IOCGGPIO:
- case MGSL_IOCWAITGPIO:
- case MGSL_IOCGXSYNC:
- case MGSL_IOCGXCTRL:
- rc = ioctl(tty, cmd, (unsigned long)compat_ptr(arg));
- break;
- default:
- rc = ioctl(tty, cmd, arg);
- }
- DBGINFO(("%s compat_ioctl() cmd=%08X rc=%d\n", info->device_name, cmd, rc));
- return rc;
-}
-#else
-#define slgt_compat_ioctl NULL
-#endif /* ifdef CONFIG_COMPAT */
-
-/*
- * proc fs support
- */
-static inline void line_info(struct seq_file *m, struct slgt_info *info)
-{
- char stat_buf[30];
- unsigned long flags;
-
- seq_printf(m, "%s: IO=%08X IRQ=%d MaxFrameSize=%u\n",
- info->device_name, info->phys_reg_addr,
- info->irq_level, info->max_frame_size);
-
- /* output current serial signal states */
- spin_lock_irqsave(&info->lock,flags);
- get_gtsignals(info);
- spin_unlock_irqrestore(&info->lock,flags);
-
- stat_buf[0] = 0;
- stat_buf[1] = 0;
- if (info->signals & SerialSignal_RTS)
- strcat(stat_buf, "|RTS");
- if (info->signals & SerialSignal_CTS)
- strcat(stat_buf, "|CTS");
- if (info->signals & SerialSignal_DTR)
- strcat(stat_buf, "|DTR");
- if (info->signals & SerialSignal_DSR)
- strcat(stat_buf, "|DSR");
- if (info->signals & SerialSignal_DCD)
- strcat(stat_buf, "|CD");
- if (info->signals & SerialSignal_RI)
- strcat(stat_buf, "|RI");
-
- if (info->params.mode != MGSL_MODE_ASYNC) {
- seq_printf(m, "\tHDLC txok:%d rxok:%d",
- info->icount.txok, info->icount.rxok);
- if (info->icount.txunder)
- seq_printf(m, " txunder:%d", info->icount.txunder);
- if (info->icount.txabort)
- seq_printf(m, " txabort:%d", info->icount.txabort);
- if (info->icount.rxshort)
- seq_printf(m, " rxshort:%d", info->icount.rxshort);
- if (info->icount.rxlong)
- seq_printf(m, " rxlong:%d", info->icount.rxlong);
- if (info->icount.rxover)
- seq_printf(m, " rxover:%d", info->icount.rxover);
- if (info->icount.rxcrc)
- seq_printf(m, " rxcrc:%d", info->icount.rxcrc);
- } else {
- seq_printf(m, "\tASYNC tx:%d rx:%d",
- info->icount.tx, info->icount.rx);
- if (info->icount.frame)
- seq_printf(m, " fe:%d", info->icount.frame);
- if (info->icount.parity)
- seq_printf(m, " pe:%d", info->icount.parity);
- if (info->icount.brk)
- seq_printf(m, " brk:%d", info->icount.brk);
- if (info->icount.overrun)
- seq_printf(m, " oe:%d", info->icount.overrun);
- }
-
- /* Append serial signal status to end */
- seq_printf(m, " %s\n", stat_buf+1);
-
- seq_printf(m, "\ttxactive=%d bh_req=%d bh_run=%d pending_bh=%x\n",
- info->tx_active,info->bh_requested,info->bh_running,
- info->pending_bh);
-}
-
-/* Called to print information about devices
- */
-static int synclink_gt_proc_show(struct seq_file *m, void *v)
-{
- struct slgt_info *info;
-
- seq_puts(m, "synclink_gt driver\n");
-
- info = slgt_device_list;
- while( info ) {
- line_info(m, info);
- info = info->next_device;
- }
- return 0;
-}
-
-/*
- * return count of bytes in transmit buffer
- */
-static unsigned int chars_in_buffer(struct tty_struct *tty)
-{
- struct slgt_info *info = tty->driver_data;
- unsigned int count;
- if (sanity_check(info, tty->name, "chars_in_buffer"))
- return 0;
- count = tbuf_bytes(info);
- DBGINFO(("%s chars_in_buffer()=%u\n", info->device_name, count));
- return count;
-}
-
-/*
- * signal remote device to throttle send data (our receive data)
- */
-static void throttle(struct tty_struct * tty)
-{
- struct slgt_info *info = tty->driver_data;
- unsigned long flags;
-
- if (sanity_check(info, tty->name, "throttle"))
- return;
- DBGINFO(("%s throttle\n", info->device_name));
- if (I_IXOFF(tty))
- send_xchar(tty, STOP_CHAR(tty));
- if (C_CRTSCTS(tty)) {
- spin_lock_irqsave(&info->lock,flags);
- info->signals &= ~SerialSignal_RTS;
- set_gtsignals(info);
- spin_unlock_irqrestore(&info->lock,flags);
- }
-}
-
-/*
- * signal remote device to stop throttling send data (our receive data)
- */
-static void unthrottle(struct tty_struct * tty)
-{
- struct slgt_info *info = tty->driver_data;
- unsigned long flags;
-
- if (sanity_check(info, tty->name, "unthrottle"))
- return;
- DBGINFO(("%s unthrottle\n", info->device_name));
- if (I_IXOFF(tty)) {
- if (info->x_char)
- info->x_char = 0;
- else
- send_xchar(tty, START_CHAR(tty));
- }
- if (C_CRTSCTS(tty)) {
- spin_lock_irqsave(&info->lock,flags);
- info->signals |= SerialSignal_RTS;
- set_gtsignals(info);
- spin_unlock_irqrestore(&info->lock,flags);
- }
-}
-
-/*
- * set or clear transmit break condition
- * break_state -1=set break condition, 0=clear
- */
-static int set_break(struct tty_struct *tty, int break_state)
-{
- struct slgt_info *info = tty->driver_data;
- unsigned short value;
- unsigned long flags;
-
- if (sanity_check(info, tty->name, "set_break"))
- return -EINVAL;
- DBGINFO(("%s set_break(%d)\n", info->device_name, break_state));
-
- spin_lock_irqsave(&info->lock,flags);
- value = rd_reg16(info, TCR);
- if (break_state == -1)
- value |= BIT6;
- else
- value &= ~BIT6;
- wr_reg16(info, TCR, value);
- spin_unlock_irqrestore(&info->lock,flags);
- return 0;
-}
-
-#if SYNCLINK_GENERIC_HDLC
-
-/**
- * hdlcdev_attach - called by generic HDLC layer when protocol selected (PPP, frame relay, etc.)
- * @dev: pointer to network device structure
- * @encoding: serial encoding setting
- * @parity: FCS setting
- *
- * Set encoding and frame check sequence (FCS) options.
- *
- * Return: 0 if success, otherwise error code
- */
-static int hdlcdev_attach(struct net_device *dev, unsigned short encoding,
- unsigned short parity)
-{
- struct slgt_info *info = dev_to_port(dev);
- unsigned char new_encoding;
- unsigned short new_crctype;
-
- /* return error if TTY interface open */
- if (info->port.count)
- return -EBUSY;
-
- DBGINFO(("%s hdlcdev_attach\n", info->device_name));
-
- switch (encoding)
- {
- case ENCODING_NRZ: new_encoding = HDLC_ENCODING_NRZ; break;
- case ENCODING_NRZI: new_encoding = HDLC_ENCODING_NRZI_SPACE; break;
- case ENCODING_FM_MARK: new_encoding = HDLC_ENCODING_BIPHASE_MARK; break;
- case ENCODING_FM_SPACE: new_encoding = HDLC_ENCODING_BIPHASE_SPACE; break;
- case ENCODING_MANCHESTER: new_encoding = HDLC_ENCODING_BIPHASE_LEVEL; break;
- default: return -EINVAL;
- }
-
- switch (parity)
- {
- case PARITY_NONE: new_crctype = HDLC_CRC_NONE; break;
- case PARITY_CRC16_PR1_CCITT: new_crctype = HDLC_CRC_16_CCITT; break;
- case PARITY_CRC32_PR1_CCITT: new_crctype = HDLC_CRC_32_CCITT; break;
- default: return -EINVAL;
- }
-
- info->params.encoding = new_encoding;
- info->params.crc_type = new_crctype;
-
- /* if network interface up, reprogram hardware */
- if (info->netcount)
- program_hw(info);
-
- return 0;
-}
-
-/**
- * hdlcdev_xmit - called by generic HDLC layer to send a frame
- * @skb: socket buffer containing HDLC frame
- * @dev: pointer to network device structure
- */
-static netdev_tx_t hdlcdev_xmit(struct sk_buff *skb,
- struct net_device *dev)
-{
- struct slgt_info *info = dev_to_port(dev);
- unsigned long flags;
-
- DBGINFO(("%s hdlc_xmit\n", dev->name));
-
- if (!skb->len)
- return NETDEV_TX_OK;
-
- /* stop sending until this frame completes */
- netif_stop_queue(dev);
-
- /* update network statistics */
- dev->stats.tx_packets++;
- dev->stats.tx_bytes += skb->len;
-
- /* save start time for transmit timeout detection */
- netif_trans_update(dev);
-
- spin_lock_irqsave(&info->lock, flags);
- tx_load(info, skb->data, skb->len);
- spin_unlock_irqrestore(&info->lock, flags);
-
- /* done with socket buffer, so free it */
- dev_kfree_skb(skb);
-
- return NETDEV_TX_OK;
-}
-
-/**
- * hdlcdev_open - called by network layer when interface enabled
- * @dev: pointer to network device structure
- *
- * Claim resources and initialize hardware.
- *
- * Return: 0 if success, otherwise error code
- */
-static int hdlcdev_open(struct net_device *dev)
-{
- struct slgt_info *info = dev_to_port(dev);
- int rc;
- unsigned long flags;
-
- DBGINFO(("%s hdlcdev_open\n", dev->name));
-
- /* arbitrate between network and tty opens */
- spin_lock_irqsave(&info->netlock, flags);
- if (info->port.count != 0 || info->netcount != 0) {
- DBGINFO(("%s hdlc_open busy\n", dev->name));
- spin_unlock_irqrestore(&info->netlock, flags);
- return -EBUSY;
- }
- info->netcount=1;
- spin_unlock_irqrestore(&info->netlock, flags);
-
- /* claim resources and init adapter */
- if ((rc = startup_hw(info)) != 0) {
- spin_lock_irqsave(&info->netlock, flags);
- info->netcount=0;
- spin_unlock_irqrestore(&info->netlock, flags);
- return rc;
- }
-
- /* generic HDLC layer open processing */
- rc = hdlc_open(dev);
- if (rc) {
- shutdown_hw(info);
- spin_lock_irqsave(&info->netlock, flags);
- info->netcount = 0;
- spin_unlock_irqrestore(&info->netlock, flags);
- return rc;
- }
-
- /* assert RTS and DTR, apply hardware settings */
- info->signals |= SerialSignal_RTS | SerialSignal_DTR;
- program_hw(info);
-
- /* enable network layer transmit */
- netif_trans_update(dev);
- netif_start_queue(dev);
-
- /* inform generic HDLC layer of current DCD status */
- spin_lock_irqsave(&info->lock, flags);
- get_gtsignals(info);
- spin_unlock_irqrestore(&info->lock, flags);
- if (info->signals & SerialSignal_DCD)
- netif_carrier_on(dev);
- else
- netif_carrier_off(dev);
- return 0;
-}
-
-/**
- * hdlcdev_close - called by network layer when interface is disabled
- * @dev: pointer to network device structure
- *
- * Shutdown hardware and release resources.
- *
- * Return: 0 if success, otherwise error code
- */
-static int hdlcdev_close(struct net_device *dev)
-{
- struct slgt_info *info = dev_to_port(dev);
- unsigned long flags;
-
- DBGINFO(("%s hdlcdev_close\n", dev->name));
-
- netif_stop_queue(dev);
-
- /* shutdown adapter and release resources */
- shutdown_hw(info);
-
- hdlc_close(dev);
-
- spin_lock_irqsave(&info->netlock, flags);
- info->netcount=0;
- spin_unlock_irqrestore(&info->netlock, flags);
-
- return 0;
-}
-
-/**
- * hdlcdev_ioctl - called by network layer to process IOCTL call to network device
- * @dev: pointer to network device structure
- * @ifr: pointer to network interface request structure
- * @cmd: IOCTL command code
- *
- * Return: 0 if success, otherwise error code
- */
-static int hdlcdev_ioctl(struct net_device *dev, struct if_settings *ifs)
-{
- const size_t size = sizeof(sync_serial_settings);
- sync_serial_settings new_line;
- sync_serial_settings __user *line = ifs->ifs_ifsu.sync;
- struct slgt_info *info = dev_to_port(dev);
- unsigned int flags;
-
- DBGINFO(("%s hdlcdev_ioctl\n", dev->name));
-
- /* return error if TTY interface open */
- if (info->port.count)
- return -EBUSY;
-
- memset(&new_line, 0, sizeof(new_line));
-
- switch (ifs->type) {
- case IF_GET_IFACE: /* return current sync_serial_settings */
-
- ifs->type = IF_IFACE_SYNC_SERIAL;
- if (ifs->size < size) {
- ifs->size = size; /* data size wanted */
- return -ENOBUFS;
- }
-
- flags = info->params.flags & (HDLC_FLAG_RXC_RXCPIN | HDLC_FLAG_RXC_DPLL |
- HDLC_FLAG_RXC_BRG | HDLC_FLAG_RXC_TXCPIN |
- HDLC_FLAG_TXC_TXCPIN | HDLC_FLAG_TXC_DPLL |
- HDLC_FLAG_TXC_BRG | HDLC_FLAG_TXC_RXCPIN);
-
- switch (flags){
- case (HDLC_FLAG_RXC_RXCPIN | HDLC_FLAG_TXC_TXCPIN): new_line.clock_type = CLOCK_EXT; break;
- case (HDLC_FLAG_RXC_BRG | HDLC_FLAG_TXC_BRG): new_line.clock_type = CLOCK_INT; break;
- case (HDLC_FLAG_RXC_RXCPIN | HDLC_FLAG_TXC_BRG): new_line.clock_type = CLOCK_TXINT; break;
- case (HDLC_FLAG_RXC_RXCPIN | HDLC_FLAG_TXC_RXCPIN): new_line.clock_type = CLOCK_TXFROMRX; break;
- default: new_line.clock_type = CLOCK_DEFAULT;
- }
-
- new_line.clock_rate = info->params.clock_speed;
- new_line.loopback = info->params.loopback ? 1:0;
-
- if (copy_to_user(line, &new_line, size))
- return -EFAULT;
- return 0;
-
- case IF_IFACE_SYNC_SERIAL: /* set sync_serial_settings */
-
- if(!capable(CAP_NET_ADMIN))
- return -EPERM;
- if (copy_from_user(&new_line, line, size))
- return -EFAULT;
-
- switch (new_line.clock_type)
- {
- case CLOCK_EXT: flags = HDLC_FLAG_RXC_RXCPIN | HDLC_FLAG_TXC_TXCPIN; break;
- case CLOCK_TXFROMRX: flags = HDLC_FLAG_RXC_RXCPIN | HDLC_FLAG_TXC_RXCPIN; break;
- case CLOCK_INT: flags = HDLC_FLAG_RXC_BRG | HDLC_FLAG_TXC_BRG; break;
- case CLOCK_TXINT: flags = HDLC_FLAG_RXC_RXCPIN | HDLC_FLAG_TXC_BRG; break;
- case CLOCK_DEFAULT: flags = info->params.flags &
- (HDLC_FLAG_RXC_RXCPIN | HDLC_FLAG_RXC_DPLL |
- HDLC_FLAG_RXC_BRG | HDLC_FLAG_RXC_TXCPIN |
- HDLC_FLAG_TXC_TXCPIN | HDLC_FLAG_TXC_DPLL |
- HDLC_FLAG_TXC_BRG | HDLC_FLAG_TXC_RXCPIN); break;
- default: return -EINVAL;
- }
-
- if (new_line.loopback != 0 && new_line.loopback != 1)
- return -EINVAL;
-
- info->params.flags &= ~(HDLC_FLAG_RXC_RXCPIN | HDLC_FLAG_RXC_DPLL |
- HDLC_FLAG_RXC_BRG | HDLC_FLAG_RXC_TXCPIN |
- HDLC_FLAG_TXC_TXCPIN | HDLC_FLAG_TXC_DPLL |
- HDLC_FLAG_TXC_BRG | HDLC_FLAG_TXC_RXCPIN);
- info->params.flags |= flags;
-
- info->params.loopback = new_line.loopback;
-
- if (flags & (HDLC_FLAG_RXC_BRG | HDLC_FLAG_TXC_BRG))
- info->params.clock_speed = new_line.clock_rate;
- else
- info->params.clock_speed = 0;
-
- /* if network interface up, reprogram hardware */
- if (info->netcount)
- program_hw(info);
- return 0;
-
- default:
- return hdlc_ioctl(dev, ifs);
- }
-}
-
-/**
- * hdlcdev_tx_timeout - called by network layer when transmit timeout is detected
- * @dev: pointer to network device structure
- * @txqueue: unused
- */
-static void hdlcdev_tx_timeout(struct net_device *dev, unsigned int txqueue)
-{
- struct slgt_info *info = dev_to_port(dev);
- unsigned long flags;
-
- DBGINFO(("%s hdlcdev_tx_timeout\n", dev->name));
-
- dev->stats.tx_errors++;
- dev->stats.tx_aborted_errors++;
-
- spin_lock_irqsave(&info->lock,flags);
- tx_stop(info);
- spin_unlock_irqrestore(&info->lock,flags);
-
- netif_wake_queue(dev);
-}
-
-/**
- * hdlcdev_tx_done - called by device driver when transmit completes
- * @info: pointer to device instance information
- *
- * Reenable network layer transmit if stopped.
- */
-static void hdlcdev_tx_done(struct slgt_info *info)
-{
- if (netif_queue_stopped(info->netdev))
- netif_wake_queue(info->netdev);
-}
-
-/**
- * hdlcdev_rx - called by device driver when frame received
- * @info: pointer to device instance information
- * @buf: pointer to buffer contianing frame data
- * @size: count of data bytes in buf
- *
- * Pass frame to network layer.
- */
-static void hdlcdev_rx(struct slgt_info *info, char *buf, int size)
-{
- struct sk_buff *skb = dev_alloc_skb(size);
- struct net_device *dev = info->netdev;
-
- DBGINFO(("%s hdlcdev_rx\n", dev->name));
-
- if (skb == NULL) {
- DBGERR(("%s: can't alloc skb, drop packet\n", dev->name));
- dev->stats.rx_dropped++;
- return;
- }
-
- skb_put_data(skb, buf, size);
-
- skb->protocol = hdlc_type_trans(skb, dev);
-
- dev->stats.rx_packets++;
- dev->stats.rx_bytes += size;
-
- netif_rx(skb);
-}
-
-static const struct net_device_ops hdlcdev_ops = {
- .ndo_open = hdlcdev_open,
- .ndo_stop = hdlcdev_close,
- .ndo_start_xmit = hdlc_start_xmit,
- .ndo_siocwandev = hdlcdev_ioctl,
- .ndo_tx_timeout = hdlcdev_tx_timeout,
-};
-
-/**
- * hdlcdev_init - called by device driver when adding device instance
- * @info: pointer to device instance information
- *
- * Do generic HDLC initialization.
- *
- * Return: 0 if success, otherwise error code
- */
-static int hdlcdev_init(struct slgt_info *info)
-{
- int rc;
- struct net_device *dev;
- hdlc_device *hdlc;
-
- /* allocate and initialize network and HDLC layer objects */
-
- dev = alloc_hdlcdev(info);
- if (!dev) {
- printk(KERN_ERR "%s hdlc device alloc failure\n", info->device_name);
- return -ENOMEM;
- }
-
- /* for network layer reporting purposes only */
- dev->mem_start = info->phys_reg_addr;
- dev->mem_end = info->phys_reg_addr + SLGT_REG_SIZE - 1;
- dev->irq = info->irq_level;
-
- /* network layer callbacks and settings */
- dev->netdev_ops = &hdlcdev_ops;
- dev->watchdog_timeo = 10 * HZ;
- dev->tx_queue_len = 50;
-
- /* generic HDLC layer callbacks and settings */
- hdlc = dev_to_hdlc(dev);
- hdlc->attach = hdlcdev_attach;
- hdlc->xmit = hdlcdev_xmit;
-
- /* register objects with HDLC layer */
- rc = register_hdlc_device(dev);
- if (rc) {
- printk(KERN_WARNING "%s:unable to register hdlc device\n",__FILE__);
- free_netdev(dev);
- return rc;
- }
-
- info->netdev = dev;
- return 0;
-}
-
-/**
- * hdlcdev_exit - called by device driver when removing device instance
- * @info: pointer to device instance information
- *
- * Do generic HDLC cleanup.
- */
-static void hdlcdev_exit(struct slgt_info *info)
-{
- if (!info->netdev)
- return;
- unregister_hdlc_device(info->netdev);
- free_netdev(info->netdev);
- info->netdev = NULL;
-}
-
-#endif /* ifdef CONFIG_HDLC */
-
-/*
- * get async data from rx DMA buffers
- */
-static void rx_async(struct slgt_info *info)
-{
- struct mgsl_icount *icount = &info->icount;
- unsigned int start, end;
- unsigned char *p;
- unsigned char status;
- struct slgt_desc *bufs = info->rbufs;
- int i, count;
- int chars = 0;
- int stat;
- unsigned char ch;
-
- start = end = info->rbuf_current;
-
- while(desc_complete(bufs[end])) {
- count = desc_count(bufs[end]) - info->rbuf_index;
- p = bufs[end].buf + info->rbuf_index;
-
- DBGISR(("%s rx_async count=%d\n", info->device_name, count));
- DBGDATA(info, p, count, "rx");
-
- for(i=0 ; i < count; i+=2, p+=2) {
- ch = *p;
- icount->rx++;
-
- stat = 0;
-
- status = *(p + 1) & (BIT1 + BIT0);
- if (status) {
- if (status & BIT1)
- icount->parity++;
- else if (status & BIT0)
- icount->frame++;
- /* discard char if tty control flags say so */
- if (status & info->ignore_status_mask)
- continue;
- if (status & BIT1)
- stat = TTY_PARITY;
- else if (status & BIT0)
- stat = TTY_FRAME;
- }
- tty_insert_flip_char(&info->port, ch, stat);
- chars++;
- }
-
- if (i < count) {
- /* receive buffer not completed */
- info->rbuf_index += i;
- mod_timer(&info->rx_timer, jiffies + 1);
- break;
- }
-
- info->rbuf_index = 0;
- free_rbufs(info, end, end);
-
- if (++end == info->rbuf_count)
- end = 0;
-
- /* if entire list searched then no frame available */
- if (end == start)
- break;
- }
-
- if (chars)
- tty_flip_buffer_push(&info->port);
-}
-
-/*
- * return next bottom half action to perform
- */
-static int bh_action(struct slgt_info *info)
-{
- unsigned long flags;
- int rc;
-
- spin_lock_irqsave(&info->lock,flags);
-
- if (info->pending_bh & BH_RECEIVE) {
- info->pending_bh &= ~BH_RECEIVE;
- rc = BH_RECEIVE;
- } else if (info->pending_bh & BH_TRANSMIT) {
- info->pending_bh &= ~BH_TRANSMIT;
- rc = BH_TRANSMIT;
- } else if (info->pending_bh & BH_STATUS) {
- info->pending_bh &= ~BH_STATUS;
- rc = BH_STATUS;
- } else {
- /* Mark BH routine as complete */
- info->bh_running = false;
- info->bh_requested = false;
- rc = 0;
- }
-
- spin_unlock_irqrestore(&info->lock,flags);
-
- return rc;
-}
-
-/*
- * perform bottom half processing
- */
-static void bh_handler(struct work_struct *work)
-{
- struct slgt_info *info = container_of(work, struct slgt_info, task);
- int action;
-
- info->bh_running = true;
-
- while((action = bh_action(info))) {
- switch (action) {
- case BH_RECEIVE:
- DBGBH(("%s bh receive\n", info->device_name));
- switch(info->params.mode) {
- case MGSL_MODE_ASYNC:
- rx_async(info);
- break;
- case MGSL_MODE_HDLC:
- while(rx_get_frame(info));
- break;
- case MGSL_MODE_RAW:
- case MGSL_MODE_MONOSYNC:
- case MGSL_MODE_BISYNC:
- case MGSL_MODE_XSYNC:
- while(rx_get_buf(info));
- break;
- }
- /* restart receiver if rx DMA buffers exhausted */
- if (info->rx_restart)
- rx_start(info);
- break;
- case BH_TRANSMIT:
- bh_transmit(info);
- break;
- case BH_STATUS:
- DBGBH(("%s bh status\n", info->device_name));
- info->ri_chkcount = 0;
- info->dsr_chkcount = 0;
- info->dcd_chkcount = 0;
- info->cts_chkcount = 0;
- break;
- default:
- DBGBH(("%s unknown action\n", info->device_name));
- break;
- }
- }
- DBGBH(("%s bh_handler exit\n", info->device_name));
-}
-
-static void bh_transmit(struct slgt_info *info)
-{
- struct tty_struct *tty = info->port.tty;
-
- DBGBH(("%s bh_transmit\n", info->device_name));
- if (tty)
- tty_wakeup(tty);
-}
-
-static void dsr_change(struct slgt_info *info, unsigned short status)
-{
- if (status & BIT3) {
- info->signals |= SerialSignal_DSR;
- info->input_signal_events.dsr_up++;
- } else {
- info->signals &= ~SerialSignal_DSR;
- info->input_signal_events.dsr_down++;
- }
- DBGISR(("dsr_change %s signals=%04X\n", info->device_name, info->signals));
- if ((info->dsr_chkcount)++ == IO_PIN_SHUTDOWN_LIMIT) {
- slgt_irq_off(info, IRQ_DSR);
- return;
- }
- info->icount.dsr++;
- wake_up_interruptible(&info->status_event_wait_q);
- wake_up_interruptible(&info->event_wait_q);
- info->pending_bh |= BH_STATUS;
-}
-
-static void cts_change(struct slgt_info *info, unsigned short status)
-{
- if (status & BIT2) {
- info->signals |= SerialSignal_CTS;
- info->input_signal_events.cts_up++;
- } else {
- info->signals &= ~SerialSignal_CTS;
- info->input_signal_events.cts_down++;
- }
- DBGISR(("cts_change %s signals=%04X\n", info->device_name, info->signals));
- if ((info->cts_chkcount)++ == IO_PIN_SHUTDOWN_LIMIT) {
- slgt_irq_off(info, IRQ_CTS);
- return;
- }
- info->icount.cts++;
- wake_up_interruptible(&info->status_event_wait_q);
- wake_up_interruptible(&info->event_wait_q);
- info->pending_bh |= BH_STATUS;
-
- if (tty_port_cts_enabled(&info->port)) {
- if (info->port.tty) {
- if (info->port.tty->hw_stopped) {
- if (info->signals & SerialSignal_CTS) {
- info->port.tty->hw_stopped = false;
- info->pending_bh |= BH_TRANSMIT;
- return;
- }
- } else {
- if (!(info->signals & SerialSignal_CTS))
- info->port.tty->hw_stopped = true;
- }
- }
- }
-}
-
-static void dcd_change(struct slgt_info *info, unsigned short status)
-{
- if (status & BIT1) {
- info->signals |= SerialSignal_DCD;
- info->input_signal_events.dcd_up++;
- } else {
- info->signals &= ~SerialSignal_DCD;
- info->input_signal_events.dcd_down++;
- }
- DBGISR(("dcd_change %s signals=%04X\n", info->device_name, info->signals));
- if ((info->dcd_chkcount)++ == IO_PIN_SHUTDOWN_LIMIT) {
- slgt_irq_off(info, IRQ_DCD);
- return;
- }
- info->icount.dcd++;
-#if SYNCLINK_GENERIC_HDLC
- if (info->netcount) {
- if (info->signals & SerialSignal_DCD)
- netif_carrier_on(info->netdev);
- else
- netif_carrier_off(info->netdev);
- }
-#endif
- wake_up_interruptible(&info->status_event_wait_q);
- wake_up_interruptible(&info->event_wait_q);
- info->pending_bh |= BH_STATUS;
-
- if (tty_port_check_carrier(&info->port)) {
- if (info->signals & SerialSignal_DCD)
- wake_up_interruptible(&info->port.open_wait);
- else {
- if (info->port.tty)
- tty_hangup(info->port.tty);
- }
- }
-}
-
-static void ri_change(struct slgt_info *info, unsigned short status)
-{
- if (status & BIT0) {
- info->signals |= SerialSignal_RI;
- info->input_signal_events.ri_up++;
- } else {
- info->signals &= ~SerialSignal_RI;
- info->input_signal_events.ri_down++;
- }
- DBGISR(("ri_change %s signals=%04X\n", info->device_name, info->signals));
- if ((info->ri_chkcount)++ == IO_PIN_SHUTDOWN_LIMIT) {
- slgt_irq_off(info, IRQ_RI);
- return;
- }
- info->icount.rng++;
- wake_up_interruptible(&info->status_event_wait_q);
- wake_up_interruptible(&info->event_wait_q);
- info->pending_bh |= BH_STATUS;
-}
-
-static void isr_rxdata(struct slgt_info *info)
-{
- unsigned int count = info->rbuf_fill_count;
- unsigned int i = info->rbuf_fill_index;
- unsigned short reg;
-
- while (rd_reg16(info, SSR) & IRQ_RXDATA) {
- reg = rd_reg16(info, RDR);
- DBGISR(("isr_rxdata %s RDR=%04X\n", info->device_name, reg));
- if (desc_complete(info->rbufs[i])) {
- /* all buffers full */
- rx_stop(info);
- info->rx_restart = true;
- continue;
- }
- info->rbufs[i].buf[count++] = (unsigned char)reg;
- /* async mode saves status byte to buffer for each data byte */
- if (info->params.mode == MGSL_MODE_ASYNC)
- info->rbufs[i].buf[count++] = (unsigned char)(reg >> 8);
- if (count == info->rbuf_fill_level || (reg & BIT10)) {
- /* buffer full or end of frame */
- set_desc_count(info->rbufs[i], count);
- set_desc_status(info->rbufs[i], BIT15 | (reg >> 8));
- info->rbuf_fill_count = count = 0;
- if (++i == info->rbuf_count)
- i = 0;
- info->pending_bh |= BH_RECEIVE;
- }
- }
-
- info->rbuf_fill_index = i;
- info->rbuf_fill_count = count;
-}
-
-static void isr_serial(struct slgt_info *info)
-{
- unsigned short status = rd_reg16(info, SSR);
-
- DBGISR(("%s isr_serial status=%04X\n", info->device_name, status));
-
- wr_reg16(info, SSR, status); /* clear pending */
-
- info->irq_occurred = true;
-
- if (info->params.mode == MGSL_MODE_ASYNC) {
- if (status & IRQ_TXIDLE) {
- if (info->tx_active)
- isr_txeom(info, status);
- }
- if (info->rx_pio && (status & IRQ_RXDATA))
- isr_rxdata(info);
- if ((status & IRQ_RXBREAK) && (status & RXBREAK)) {
- info->icount.brk++;
- /* process break detection if tty control allows */
- if (info->port.tty) {
- if (!(status & info->ignore_status_mask)) {
- if (info->read_status_mask & MASK_BREAK) {
- tty_insert_flip_char(&info->port, 0, TTY_BREAK);
- if (info->port.flags & ASYNC_SAK)
- do_SAK(info->port.tty);
- }
- }
- }
- }
- } else {
- if (status & (IRQ_TXIDLE + IRQ_TXUNDER))
- isr_txeom(info, status);
- if (info->rx_pio && (status & IRQ_RXDATA))
- isr_rxdata(info);
- if (status & IRQ_RXIDLE) {
- if (status & RXIDLE)
- info->icount.rxidle++;
- else
- info->icount.exithunt++;
- wake_up_interruptible(&info->event_wait_q);
- }
-
- if (status & IRQ_RXOVER)
- rx_start(info);
- }
-
- if (status & IRQ_DSR)
- dsr_change(info, status);
- if (status & IRQ_CTS)
- cts_change(info, status);
- if (status & IRQ_DCD)
- dcd_change(info, status);
- if (status & IRQ_RI)
- ri_change(info, status);
-}
-
-static void isr_rdma(struct slgt_info *info)
-{
- unsigned int status = rd_reg32(info, RDCSR);
-
- DBGISR(("%s isr_rdma status=%08x\n", info->device_name, status));
-
- /* RDCSR (rx DMA control/status)
- *
- * 31..07 reserved
- * 06 save status byte to DMA buffer
- * 05 error
- * 04 eol (end of list)
- * 03 eob (end of buffer)
- * 02 IRQ enable
- * 01 reset
- * 00 enable
- */
- wr_reg32(info, RDCSR, status); /* clear pending */
-
- if (status & (BIT5 + BIT4)) {
- DBGISR(("%s isr_rdma rx_restart=1\n", info->device_name));
- info->rx_restart = true;
- }
- info->pending_bh |= BH_RECEIVE;
-}
-
-static void isr_tdma(struct slgt_info *info)
-{
- unsigned int status = rd_reg32(info, TDCSR);
-
- DBGISR(("%s isr_tdma status=%08x\n", info->device_name, status));
-
- /* TDCSR (tx DMA control/status)
- *
- * 31..06 reserved
- * 05 error
- * 04 eol (end of list)
- * 03 eob (end of buffer)
- * 02 IRQ enable
- * 01 reset
- * 00 enable
- */
- wr_reg32(info, TDCSR, status); /* clear pending */
-
- if (status & (BIT5 + BIT4 + BIT3)) {
- // another transmit buffer has completed
- // run bottom half to get more send data from user
- info->pending_bh |= BH_TRANSMIT;
- }
-}
-
-/*
- * return true if there are unsent tx DMA buffers, otherwise false
- *
- * if there are unsent buffers then info->tbuf_start
- * is set to index of first unsent buffer
- */
-static bool unsent_tbufs(struct slgt_info *info)
-{
- unsigned int i = info->tbuf_current;
- bool rc = false;
-
- /*
- * search backwards from last loaded buffer (precedes tbuf_current)
- * for first unsent buffer (desc_count > 0)
- */
-
- do {
- if (i)
- i--;
- else
- i = info->tbuf_count - 1;
- if (!desc_count(info->tbufs[i]))
- break;
- info->tbuf_start = i;
- rc = true;
- } while (i != info->tbuf_current);
-
- return rc;
-}
-
-static void isr_txeom(struct slgt_info *info, unsigned short status)
-{
- DBGISR(("%s txeom status=%04x\n", info->device_name, status));
-
- slgt_irq_off(info, IRQ_TXDATA + IRQ_TXIDLE + IRQ_TXUNDER);
- tdma_reset(info);
- if (status & IRQ_TXUNDER) {
- unsigned short val = rd_reg16(info, TCR);
- wr_reg16(info, TCR, (unsigned short)(val | BIT2)); /* set reset bit */
- wr_reg16(info, TCR, val); /* clear reset bit */
- }
-
- if (info->tx_active) {
- if (info->params.mode != MGSL_MODE_ASYNC) {
- if (status & IRQ_TXUNDER)
- info->icount.txunder++;
- else if (status & IRQ_TXIDLE)
- info->icount.txok++;
- }
-
- if (unsent_tbufs(info)) {
- tx_start(info);
- update_tx_timer(info);
- return;
- }
- info->tx_active = false;
-
- timer_delete(&info->tx_timer);
-
- if (info->params.mode != MGSL_MODE_ASYNC && info->drop_rts_on_tx_done) {
- info->signals &= ~SerialSignal_RTS;
- info->drop_rts_on_tx_done = false;
- set_gtsignals(info);
- }
-
-#if SYNCLINK_GENERIC_HDLC
- if (info->netcount)
- hdlcdev_tx_done(info);
- else
-#endif
- {
- if (info->port.tty && (info->port.tty->flow.stopped || info->port.tty->hw_stopped)) {
- tx_stop(info);
- return;
- }
- info->pending_bh |= BH_TRANSMIT;
- }
- }
-}
-
-static void isr_gpio(struct slgt_info *info, unsigned int changed, unsigned int state)
-{
- struct cond_wait *w, *prev;
-
- /* wake processes waiting for specific transitions */
- for (w = info->gpio_wait_q, prev = NULL ; w != NULL ; w = w->next) {
- if (w->data & changed) {
- w->data = state;
- wake_up_interruptible(&w->q);
- if (prev != NULL)
- prev->next = w->next;
- else
- info->gpio_wait_q = w->next;
- } else
- prev = w;
- }
-}
-
-/* interrupt service routine
- *
- * irq interrupt number
- * dev_id device ID supplied during interrupt registration
- */
-static irqreturn_t slgt_interrupt(int dummy, void *dev_id)
-{
- struct slgt_info *info = dev_id;
- unsigned int gsr;
- unsigned int i;
-
- DBGISR(("slgt_interrupt irq=%d entry\n", info->irq_level));
-
- while((gsr = rd_reg32(info, GSR) & 0xffffff00)) {
- DBGISR(("%s gsr=%08x\n", info->device_name, gsr));
- info->irq_occurred = true;
- for(i=0; i < info->port_count ; i++) {
- if (info->port_array[i] == NULL)
- continue;
- spin_lock(&info->port_array[i]->lock);
- if (gsr & (BIT8 << i))
- isr_serial(info->port_array[i]);
- if (gsr & (BIT16 << (i*2)))
- isr_rdma(info->port_array[i]);
- if (gsr & (BIT17 << (i*2)))
- isr_tdma(info->port_array[i]);
- spin_unlock(&info->port_array[i]->lock);
- }
- }
-
- if (info->gpio_present) {
- unsigned int state;
- unsigned int changed;
- spin_lock(&info->lock);
- while ((changed = rd_reg32(info, IOSR)) != 0) {
- DBGISR(("%s iosr=%08x\n", info->device_name, changed));
- /* read latched state of GPIO signals */
- state = rd_reg32(info, IOVR);
- /* clear pending GPIO interrupt bits */
- wr_reg32(info, IOSR, changed);
- for (i=0 ; i < info->port_count ; i++) {
- if (info->port_array[i] != NULL)
- isr_gpio(info->port_array[i], changed, state);
- }
- }
- spin_unlock(&info->lock);
- }
-
- for(i=0; i < info->port_count ; i++) {
- struct slgt_info *port = info->port_array[i];
- if (port == NULL)
- continue;
- spin_lock(&port->lock);
- if ((port->port.count || port->netcount) &&
- port->pending_bh && !port->bh_running &&
- !port->bh_requested) {
- DBGISR(("%s bh queued\n", port->device_name));
- schedule_work(&port->task);
- port->bh_requested = true;
- }
- spin_unlock(&port->lock);
- }
-
- DBGISR(("slgt_interrupt irq=%d exit\n", info->irq_level));
- return IRQ_HANDLED;
-}
-
-static int startup_hw(struct slgt_info *info)
-{
- DBGINFO(("%s startup\n", info->device_name));
-
- if (tty_port_initialized(&info->port))
- return 0;
-
- if (!info->tx_buf) {
- info->tx_buf = kmalloc(info->max_frame_size, GFP_KERNEL);
- if (!info->tx_buf) {
- DBGERR(("%s can't allocate tx buffer\n", info->device_name));
- return -ENOMEM;
- }
- }
-
- info->pending_bh = 0;
-
- memset(&info->icount, 0, sizeof(info->icount));
-
- /* program hardware for current parameters */
- change_params(info);
-
- if (info->port.tty)
- clear_bit(TTY_IO_ERROR, &info->port.tty->flags);
-
- tty_port_set_initialized(&info->port, true);
-
- return 0;
-}
-
-/*
- * called by close() and hangup() to shutdown hardware
- */
-static void shutdown_hw(struct slgt_info *info)
-{
- unsigned long flags;
-
- if (!tty_port_initialized(&info->port))
- return;
-
- DBGINFO(("%s shutdown\n", info->device_name));
-
- /* clear status wait queue because status changes */
- /* can't happen after shutting down the hardware */
- wake_up_interruptible(&info->status_event_wait_q);
- wake_up_interruptible(&info->event_wait_q);
-
- timer_delete_sync(&info->tx_timer);
- timer_delete_sync(&info->rx_timer);
-
- kfree(info->tx_buf);
- info->tx_buf = NULL;
-
- spin_lock_irqsave(&info->lock,flags);
-
- tx_stop(info);
- rx_stop(info);
-
- slgt_irq_off(info, IRQ_ALL | IRQ_MASTER);
-
- if (!info->port.tty || info->port.tty->termios.c_cflag & HUPCL) {
- info->signals &= ~(SerialSignal_RTS | SerialSignal_DTR);
- set_gtsignals(info);
- }
-
- flush_cond_wait(&info->gpio_wait_q);
-
- spin_unlock_irqrestore(&info->lock,flags);
-
- if (info->port.tty)
- set_bit(TTY_IO_ERROR, &info->port.tty->flags);
-
- tty_port_set_initialized(&info->port, false);
-}
-
-static void program_hw(struct slgt_info *info)
-{
- unsigned long flags;
-
- spin_lock_irqsave(&info->lock,flags);
-
- rx_stop(info);
- tx_stop(info);
-
- if (info->params.mode != MGSL_MODE_ASYNC ||
- info->netcount)
- sync_mode(info);
- else
- async_mode(info);
-
- set_gtsignals(info);
-
- info->dcd_chkcount = 0;
- info->cts_chkcount = 0;
- info->ri_chkcount = 0;
- info->dsr_chkcount = 0;
-
- slgt_irq_on(info, IRQ_DCD | IRQ_CTS | IRQ_DSR | IRQ_RI);
- get_gtsignals(info);
-
- if (info->netcount ||
- (info->port.tty && info->port.tty->termios.c_cflag & CREAD))
- rx_start(info);
-
- spin_unlock_irqrestore(&info->lock,flags);
-}
-
-/*
- * reconfigure adapter based on new parameters
- */
-static void change_params(struct slgt_info *info)
-{
- unsigned cflag;
- int bits_per_char;
-
- if (!info->port.tty)
- return;
- DBGINFO(("%s change_params\n", info->device_name));
-
- cflag = info->port.tty->termios.c_cflag;
-
- /* if B0 rate (hangup) specified then negate RTS and DTR */
- /* otherwise assert RTS and DTR */
- if (cflag & CBAUD)
- info->signals |= SerialSignal_RTS | SerialSignal_DTR;
- else
- info->signals &= ~(SerialSignal_RTS | SerialSignal_DTR);
-
- /* byte size and parity */
-
- info->params.data_bits = tty_get_char_size(cflag);
- info->params.stop_bits = (cflag & CSTOPB) ? 2 : 1;
-
- if (cflag & PARENB)
- info->params.parity = (cflag & PARODD) ? ASYNC_PARITY_ODD : ASYNC_PARITY_EVEN;
- else
- info->params.parity = ASYNC_PARITY_NONE;
-
- /* calculate number of jiffies to transmit a full
- * FIFO (32 bytes) at specified data rate
- */
- bits_per_char = info->params.data_bits +
- info->params.stop_bits + 1;
-
- info->params.data_rate = tty_get_baud_rate(info->port.tty);
-
- if (info->params.data_rate) {
- info->timeout = (32*HZ*bits_per_char) /
- info->params.data_rate;
- }
- info->timeout += HZ/50; /* Add .02 seconds of slop */
-
- tty_port_set_cts_flow(&info->port, cflag & CRTSCTS);
- tty_port_set_check_carrier(&info->port, ~cflag & CLOCAL);
-
- /* process tty input control flags */
-
- info->read_status_mask = IRQ_RXOVER;
- if (I_INPCK(info->port.tty))
- info->read_status_mask |= MASK_PARITY | MASK_FRAMING;
- if (I_BRKINT(info->port.tty) || I_PARMRK(info->port.tty))
- info->read_status_mask |= MASK_BREAK;
- if (I_IGNPAR(info->port.tty))
- info->ignore_status_mask |= MASK_PARITY | MASK_FRAMING;
- if (I_IGNBRK(info->port.tty)) {
- info->ignore_status_mask |= MASK_BREAK;
- /* If ignoring parity and break indicators, ignore
- * overruns too. (For real raw support).
- */
- if (I_IGNPAR(info->port.tty))
- info->ignore_status_mask |= MASK_OVERRUN;
- }
-
- program_hw(info);
-}
-
-static int get_stats(struct slgt_info *info, struct mgsl_icount __user *user_icount)
-{
- DBGINFO(("%s get_stats\n", info->device_name));
- if (!user_icount) {
- memset(&info->icount, 0, sizeof(info->icount));
- } else {
- if (copy_to_user(user_icount, &info->icount, sizeof(struct mgsl_icount)))
- return -EFAULT;
- }
- return 0;
-}
-
-static int get_params(struct slgt_info *info, MGSL_PARAMS __user *user_params)
-{
- DBGINFO(("%s get_params\n", info->device_name));
- if (copy_to_user(user_params, &info->params, sizeof(MGSL_PARAMS)))
- return -EFAULT;
- return 0;
-}
-
-static int set_params(struct slgt_info *info, MGSL_PARAMS __user *new_params)
-{
- unsigned long flags;
- MGSL_PARAMS tmp_params;
-
- DBGINFO(("%s set_params\n", info->device_name));
- if (copy_from_user(&tmp_params, new_params, sizeof(MGSL_PARAMS)))
- return -EFAULT;
-
- spin_lock_irqsave(&info->lock, flags);
- if (tmp_params.mode == MGSL_MODE_BASE_CLOCK)
- info->base_clock = tmp_params.clock_speed;
- else
- memcpy(&info->params, &tmp_params, sizeof(MGSL_PARAMS));
- spin_unlock_irqrestore(&info->lock, flags);
-
- program_hw(info);
-
- return 0;
-}
-
-static int get_txidle(struct slgt_info *info, int __user *idle_mode)
-{
- DBGINFO(("%s get_txidle=%d\n", info->device_name, info->idle_mode));
- if (put_user(info->idle_mode, idle_mode))
- return -EFAULT;
- return 0;
-}
-
-static int set_txidle(struct slgt_info *info, int idle_mode)
-{
- unsigned long flags;
- DBGINFO(("%s set_txidle(%d)\n", info->device_name, idle_mode));
- spin_lock_irqsave(&info->lock,flags);
- info->idle_mode = idle_mode;
- if (info->params.mode != MGSL_MODE_ASYNC)
- tx_set_idle(info);
- spin_unlock_irqrestore(&info->lock,flags);
- return 0;
-}
-
-static int tx_enable(struct slgt_info *info, int enable)
-{
- unsigned long flags;
- DBGINFO(("%s tx_enable(%d)\n", info->device_name, enable));
- spin_lock_irqsave(&info->lock,flags);
- if (enable) {
- if (!info->tx_enabled)
- tx_start(info);
- } else {
- if (info->tx_enabled)
- tx_stop(info);
- }
- spin_unlock_irqrestore(&info->lock,flags);
- return 0;
-}
-
-/*
- * abort transmit HDLC frame
- */
-static int tx_abort(struct slgt_info *info)
-{
- unsigned long flags;
- DBGINFO(("%s tx_abort\n", info->device_name));
- spin_lock_irqsave(&info->lock,flags);
- tdma_reset(info);
- spin_unlock_irqrestore(&info->lock,flags);
- return 0;
-}
-
-static int rx_enable(struct slgt_info *info, int enable)
-{
- unsigned long flags;
- unsigned int rbuf_fill_level;
- DBGINFO(("%s rx_enable(%08x)\n", info->device_name, enable));
- spin_lock_irqsave(&info->lock,flags);
- /*
- * enable[31..16] = receive DMA buffer fill level
- * 0 = noop (leave fill level unchanged)
- * fill level must be multiple of 4 and <= buffer size
- */
- rbuf_fill_level = ((unsigned int)enable) >> 16;
- if (rbuf_fill_level) {
- if ((rbuf_fill_level > DMABUFSIZE) || (rbuf_fill_level % 4)) {
- spin_unlock_irqrestore(&info->lock, flags);
- return -EINVAL;
- }
- info->rbuf_fill_level = rbuf_fill_level;
- if (rbuf_fill_level < 128)
- info->rx_pio = 1; /* PIO mode */
- else
- info->rx_pio = 0; /* DMA mode */
- rx_stop(info); /* restart receiver to use new fill level */
- }
-
- /*
- * enable[1..0] = receiver enable command
- * 0 = disable
- * 1 = enable
- * 2 = enable or force hunt mode if already enabled
- */
- enable &= 3;
- if (enable) {
- if (!info->rx_enabled)
- rx_start(info);
- else if (enable == 2) {
- /* force hunt mode (write 1 to RCR[3]) */
- wr_reg16(info, RCR, rd_reg16(info, RCR) | BIT3);
- }
- } else {
- if (info->rx_enabled)
- rx_stop(info);
- }
- spin_unlock_irqrestore(&info->lock,flags);
- return 0;
-}
-
-/*
- * wait for specified event to occur
- */
-static int wait_mgsl_event(struct slgt_info *info, int __user *mask_ptr)
-{
- unsigned long flags;
- int s;
- int rc=0;
- struct mgsl_icount cprev, cnow;
- int events;
- int mask;
- struct _input_signal_events oldsigs, newsigs;
- DECLARE_WAITQUEUE(wait, current);
-
- if (get_user(mask, mask_ptr))
- return -EFAULT;
-
- DBGINFO(("%s wait_mgsl_event(%d)\n", info->device_name, mask));
-
- spin_lock_irqsave(&info->lock,flags);
-
- /* return immediately if state matches requested events */
- get_gtsignals(info);
- s = info->signals;
-
- events = mask &
- ( ((s & SerialSignal_DSR) ? MgslEvent_DsrActive:MgslEvent_DsrInactive) +
- ((s & SerialSignal_DCD) ? MgslEvent_DcdActive:MgslEvent_DcdInactive) +
- ((s & SerialSignal_CTS) ? MgslEvent_CtsActive:MgslEvent_CtsInactive) +
- ((s & SerialSignal_RI) ? MgslEvent_RiActive :MgslEvent_RiInactive) );
- if (events) {
- spin_unlock_irqrestore(&info->lock,flags);
- goto exit;
- }
-
- /* save current irq counts */
- cprev = info->icount;
- oldsigs = info->input_signal_events;
-
- /* enable hunt and idle irqs if needed */
- if (mask & (MgslEvent_ExitHuntMode+MgslEvent_IdleReceived)) {
- unsigned short val = rd_reg16(info, SCR);
- if (!(val & IRQ_RXIDLE))
- wr_reg16(info, SCR, (unsigned short)(val | IRQ_RXIDLE));
- }
-
- set_current_state(TASK_INTERRUPTIBLE);
- add_wait_queue(&info->event_wait_q, &wait);
-
- spin_unlock_irqrestore(&info->lock,flags);
-
- for(;;) {
- schedule();
- if (signal_pending(current)) {
- rc = -ERESTARTSYS;
- break;
- }
-
- /* get current irq counts */
- spin_lock_irqsave(&info->lock,flags);
- cnow = info->icount;
- newsigs = info->input_signal_events;
- set_current_state(TASK_INTERRUPTIBLE);
- spin_unlock_irqrestore(&info->lock,flags);
-
- /* if no change, wait aborted for some reason */
- if (newsigs.dsr_up == oldsigs.dsr_up &&
- newsigs.dsr_down == oldsigs.dsr_down &&
- newsigs.dcd_up == oldsigs.dcd_up &&
- newsigs.dcd_down == oldsigs.dcd_down &&
- newsigs.cts_up == oldsigs.cts_up &&
- newsigs.cts_down == oldsigs.cts_down &&
- newsigs.ri_up == oldsigs.ri_up &&
- newsigs.ri_down == oldsigs.ri_down &&
- cnow.exithunt == cprev.exithunt &&
- cnow.rxidle == cprev.rxidle) {
- rc = -EIO;
- break;
- }
-
- events = mask &
- ( (newsigs.dsr_up != oldsigs.dsr_up ? MgslEvent_DsrActive:0) +
- (newsigs.dsr_down != oldsigs.dsr_down ? MgslEvent_DsrInactive:0) +
- (newsigs.dcd_up != oldsigs.dcd_up ? MgslEvent_DcdActive:0) +
- (newsigs.dcd_down != oldsigs.dcd_down ? MgslEvent_DcdInactive:0) +
- (newsigs.cts_up != oldsigs.cts_up ? MgslEvent_CtsActive:0) +
- (newsigs.cts_down != oldsigs.cts_down ? MgslEvent_CtsInactive:0) +
- (newsigs.ri_up != oldsigs.ri_up ? MgslEvent_RiActive:0) +
- (newsigs.ri_down != oldsigs.ri_down ? MgslEvent_RiInactive:0) +
- (cnow.exithunt != cprev.exithunt ? MgslEvent_ExitHuntMode:0) +
- (cnow.rxidle != cprev.rxidle ? MgslEvent_IdleReceived:0) );
- if (events)
- break;
-
- cprev = cnow;
- oldsigs = newsigs;
- }
-
- remove_wait_queue(&info->event_wait_q, &wait);
- set_current_state(TASK_RUNNING);
-
-
- if (mask & (MgslEvent_ExitHuntMode + MgslEvent_IdleReceived)) {
- spin_lock_irqsave(&info->lock,flags);
- if (!waitqueue_active(&info->event_wait_q)) {
- /* disable enable exit hunt mode/idle rcvd IRQs */
- wr_reg16(info, SCR,
- (unsigned short)(rd_reg16(info, SCR) & ~IRQ_RXIDLE));
- }
- spin_unlock_irqrestore(&info->lock,flags);
- }
-exit:
- if (rc == 0)
- rc = put_user(events, mask_ptr);
- return rc;
-}
-
-static int get_interface(struct slgt_info *info, int __user *if_mode)
-{
- DBGINFO(("%s get_interface=%x\n", info->device_name, info->if_mode));
- if (put_user(info->if_mode, if_mode))
- return -EFAULT;
- return 0;
-}
-
-static int set_interface(struct slgt_info *info, int if_mode)
-{
- unsigned long flags;
- unsigned short val;
-
- DBGINFO(("%s set_interface=%x)\n", info->device_name, if_mode));
- spin_lock_irqsave(&info->lock,flags);
- info->if_mode = if_mode;
-
- msc_set_vcr(info);
-
- /* TCR (tx control) 07 1=RTS driver control */
- val = rd_reg16(info, TCR);
- if (info->if_mode & MGSL_INTERFACE_RTS_EN)
- val |= BIT7;
- else
- val &= ~BIT7;
- wr_reg16(info, TCR, val);
-
- spin_unlock_irqrestore(&info->lock,flags);
- return 0;
-}
-
-static int get_xsync(struct slgt_info *info, int __user *xsync)
-{
- DBGINFO(("%s get_xsync=%x\n", info->device_name, info->xsync));
- if (put_user(info->xsync, xsync))
- return -EFAULT;
- return 0;
-}
-
-/*
- * set extended sync pattern (1 to 4 bytes) for extended sync mode
- *
- * sync pattern is contained in least significant bytes of value
- * most significant byte of sync pattern is oldest (1st sent/detected)
- */
-static int set_xsync(struct slgt_info *info, int xsync)
-{
- unsigned long flags;
-
- DBGINFO(("%s set_xsync=%x)\n", info->device_name, xsync));
- spin_lock_irqsave(&info->lock, flags);
- info->xsync = xsync;
- wr_reg32(info, XSR, xsync);
- spin_unlock_irqrestore(&info->lock, flags);
- return 0;
-}
-
-static int get_xctrl(struct slgt_info *info, int __user *xctrl)
-{
- DBGINFO(("%s get_xctrl=%x\n", info->device_name, info->xctrl));
- if (put_user(info->xctrl, xctrl))
- return -EFAULT;
- return 0;
-}
-
-/*
- * set extended control options
- *
- * xctrl[31:19] reserved, must be zero
- * xctrl[18:17] extended sync pattern length in bytes
- * 00 = 1 byte in xsr[7:0]
- * 01 = 2 bytes in xsr[15:0]
- * 10 = 3 bytes in xsr[23:0]
- * 11 = 4 bytes in xsr[31:0]
- * xctrl[16] 1 = enable terminal count, 0=disabled
- * xctrl[15:0] receive terminal count for fixed length packets
- * value is count minus one (0 = 1 byte packet)
- * when terminal count is reached, receiver
- * automatically returns to hunt mode and receive
- * FIFO contents are flushed to DMA buffers with
- * end of frame (EOF) status
- */
-static int set_xctrl(struct slgt_info *info, int xctrl)
-{
- unsigned long flags;
-
- DBGINFO(("%s set_xctrl=%x)\n", info->device_name, xctrl));
- spin_lock_irqsave(&info->lock, flags);
- info->xctrl = xctrl;
- wr_reg32(info, XCR, xctrl);
- spin_unlock_irqrestore(&info->lock, flags);
- return 0;
-}
-
-/*
- * set general purpose IO pin state and direction
- *
- * user_gpio fields:
- * state each bit indicates a pin state
- * smask set bit indicates pin state to set
- * dir each bit indicates a pin direction (0=input, 1=output)
- * dmask set bit indicates pin direction to set
- */
-static int set_gpio(struct slgt_info *info, struct gpio_desc __user *user_gpio)
-{
- unsigned long flags;
- struct gpio_desc gpio;
- __u32 data;
-
- if (!info->gpio_present)
- return -EINVAL;
- if (copy_from_user(&gpio, user_gpio, sizeof(gpio)))
- return -EFAULT;
- DBGINFO(("%s set_gpio state=%08x smask=%08x dir=%08x dmask=%08x\n",
- info->device_name, gpio.state, gpio.smask,
- gpio.dir, gpio.dmask));
-
- spin_lock_irqsave(&info->port_array[0]->lock, flags);
- if (gpio.dmask) {
- data = rd_reg32(info, IODR);
- data |= gpio.dmask & gpio.dir;
- data &= ~(gpio.dmask & ~gpio.dir);
- wr_reg32(info, IODR, data);
- }
- if (gpio.smask) {
- data = rd_reg32(info, IOVR);
- data |= gpio.smask & gpio.state;
- data &= ~(gpio.smask & ~gpio.state);
- wr_reg32(info, IOVR, data);
- }
- spin_unlock_irqrestore(&info->port_array[0]->lock, flags);
-
- return 0;
-}
-
-/*
- * get general purpose IO pin state and direction
- */
-static int get_gpio(struct slgt_info *info, struct gpio_desc __user *user_gpio)
-{
- struct gpio_desc gpio;
- if (!info->gpio_present)
- return -EINVAL;
- gpio.state = rd_reg32(info, IOVR);
- gpio.smask = 0xffffffff;
- gpio.dir = rd_reg32(info, IODR);
- gpio.dmask = 0xffffffff;
- if (copy_to_user(user_gpio, &gpio, sizeof(gpio)))
- return -EFAULT;
- DBGINFO(("%s get_gpio state=%08x dir=%08x\n",
- info->device_name, gpio.state, gpio.dir));
- return 0;
-}
-
-/*
- * conditional wait facility
- */
-static void init_cond_wait(struct cond_wait *w, unsigned int data)
-{
- init_waitqueue_head(&w->q);
- init_waitqueue_entry(&w->wait, current);
- w->data = data;
-}
-
-static void add_cond_wait(struct cond_wait **head, struct cond_wait *w)
-{
- set_current_state(TASK_INTERRUPTIBLE);
- add_wait_queue(&w->q, &w->wait);
- w->next = *head;
- *head = w;
-}
-
-static void remove_cond_wait(struct cond_wait **head, struct cond_wait *cw)
-{
- struct cond_wait *w, *prev;
- remove_wait_queue(&cw->q, &cw->wait);
- set_current_state(TASK_RUNNING);
- for (w = *head, prev = NULL ; w != NULL ; prev = w, w = w->next) {
- if (w == cw) {
- if (prev != NULL)
- prev->next = w->next;
- else
- *head = w->next;
- break;
- }
- }
-}
-
-static void flush_cond_wait(struct cond_wait **head)
-{
- while (*head != NULL) {
- wake_up_interruptible(&(*head)->q);
- *head = (*head)->next;
- }
-}
-
-/*
- * wait for general purpose I/O pin(s) to enter specified state
- *
- * user_gpio fields:
- * state - bit indicates target pin state
- * smask - set bit indicates watched pin
- *
- * The wait ends when at least one watched pin enters the specified
- * state. When 0 (no error) is returned, user_gpio->state is set to the
- * state of all GPIO pins when the wait ends.
- *
- * Note: Each pin may be a dedicated input, dedicated output, or
- * configurable input/output. The number and configuration of pins
- * varies with the specific adapter model. Only input pins (dedicated
- * or configured) can be monitored with this function.
- */
-static int wait_gpio(struct slgt_info *info, struct gpio_desc __user *user_gpio)
-{
- unsigned long flags;
- int rc = 0;
- struct gpio_desc gpio;
- struct cond_wait wait;
- u32 state;
-
- if (!info->gpio_present)
- return -EINVAL;
- if (copy_from_user(&gpio, user_gpio, sizeof(gpio)))
- return -EFAULT;
- DBGINFO(("%s wait_gpio() state=%08x smask=%08x\n",
- info->device_name, gpio.state, gpio.smask));
- /* ignore output pins identified by set IODR bit */
- if ((gpio.smask &= ~rd_reg32(info, IODR)) == 0)
- return -EINVAL;
- init_cond_wait(&wait, gpio.smask);
-
- spin_lock_irqsave(&info->port_array[0]->lock, flags);
- /* enable interrupts for watched pins */
- wr_reg32(info, IOER, rd_reg32(info, IOER) | gpio.smask);
- /* get current pin states */
- state = rd_reg32(info, IOVR);
-
- if (gpio.smask & ~(state ^ gpio.state)) {
- /* already in target state */
- gpio.state = state;
- } else {
- /* wait for target state */
- add_cond_wait(&info->gpio_wait_q, &wait);
- spin_unlock_irqrestore(&info->port_array[0]->lock, flags);
- schedule();
- if (signal_pending(current))
- rc = -ERESTARTSYS;
- else
- gpio.state = wait.data;
- spin_lock_irqsave(&info->port_array[0]->lock, flags);
- remove_cond_wait(&info->gpio_wait_q, &wait);
- }
-
- /* disable all GPIO interrupts if no waiting processes */
- if (info->gpio_wait_q == NULL)
- wr_reg32(info, IOER, 0);
- spin_unlock_irqrestore(&info->port_array[0]->lock, flags);
-
- if ((rc == 0) && copy_to_user(user_gpio, &gpio, sizeof(gpio)))
- rc = -EFAULT;
- return rc;
-}
-
-static int modem_input_wait(struct slgt_info *info,int arg)
-{
- unsigned long flags;
- int rc;
- struct mgsl_icount cprev, cnow;
- DECLARE_WAITQUEUE(wait, current);
-
- /* save current irq counts */
- spin_lock_irqsave(&info->lock,flags);
- cprev = info->icount;
- add_wait_queue(&info->status_event_wait_q, &wait);
- set_current_state(TASK_INTERRUPTIBLE);
- spin_unlock_irqrestore(&info->lock,flags);
-
- for(;;) {
- schedule();
- if (signal_pending(current)) {
- rc = -ERESTARTSYS;
- break;
- }
-
- /* get new irq counts */
- spin_lock_irqsave(&info->lock,flags);
- cnow = info->icount;
- set_current_state(TASK_INTERRUPTIBLE);
- spin_unlock_irqrestore(&info->lock,flags);
-
- /* if no change, wait aborted for some reason */
- if (cnow.rng == cprev.rng && cnow.dsr == cprev.dsr &&
- cnow.dcd == cprev.dcd && cnow.cts == cprev.cts) {
- rc = -EIO;
- break;
- }
-
- /* check for change in caller specified modem input */
- if ((arg & TIOCM_RNG && cnow.rng != cprev.rng) ||
- (arg & TIOCM_DSR && cnow.dsr != cprev.dsr) ||
- (arg & TIOCM_CD && cnow.dcd != cprev.dcd) ||
- (arg & TIOCM_CTS && cnow.cts != cprev.cts)) {
- rc = 0;
- break;
- }
-
- cprev = cnow;
- }
- remove_wait_queue(&info->status_event_wait_q, &wait);
- set_current_state(TASK_RUNNING);
- return rc;
-}
-
-/*
- * return state of serial control and status signals
- */
-static int tiocmget(struct tty_struct *tty)
-{
- struct slgt_info *info = tty->driver_data;
- unsigned int result;
- unsigned long flags;
-
- spin_lock_irqsave(&info->lock,flags);
- get_gtsignals(info);
- spin_unlock_irqrestore(&info->lock,flags);
-
- result = ((info->signals & SerialSignal_RTS) ? TIOCM_RTS:0) +
- ((info->signals & SerialSignal_DTR) ? TIOCM_DTR:0) +
- ((info->signals & SerialSignal_DCD) ? TIOCM_CAR:0) +
- ((info->signals & SerialSignal_RI) ? TIOCM_RNG:0) +
- ((info->signals & SerialSignal_DSR) ? TIOCM_DSR:0) +
- ((info->signals & SerialSignal_CTS) ? TIOCM_CTS:0);
-
- DBGINFO(("%s tiocmget value=%08X\n", info->device_name, result));
- return result;
-}
-
-/*
- * set modem control signals (DTR/RTS)
- *
- * cmd signal command: TIOCMBIS = set bit TIOCMBIC = clear bit
- * TIOCMSET = set/clear signal values
- * value bit mask for command
- */
-static int tiocmset(struct tty_struct *tty,
- unsigned int set, unsigned int clear)
-{
- struct slgt_info *info = tty->driver_data;
- unsigned long flags;
-
- DBGINFO(("%s tiocmset(%x,%x)\n", info->device_name, set, clear));
-
- if (set & TIOCM_RTS)
- info->signals |= SerialSignal_RTS;
- if (set & TIOCM_DTR)
- info->signals |= SerialSignal_DTR;
- if (clear & TIOCM_RTS)
- info->signals &= ~SerialSignal_RTS;
- if (clear & TIOCM_DTR)
- info->signals &= ~SerialSignal_DTR;
-
- spin_lock_irqsave(&info->lock,flags);
- set_gtsignals(info);
- spin_unlock_irqrestore(&info->lock,flags);
- return 0;
-}
-
-static bool carrier_raised(struct tty_port *port)
-{
- unsigned long flags;
- struct slgt_info *info = container_of(port, struct slgt_info, port);
-
- spin_lock_irqsave(&info->lock,flags);
- get_gtsignals(info);
- spin_unlock_irqrestore(&info->lock,flags);
-
- return info->signals & SerialSignal_DCD;
-}
-
-static void dtr_rts(struct tty_port *port, bool active)
-{
- unsigned long flags;
- struct slgt_info *info = container_of(port, struct slgt_info, port);
-
- spin_lock_irqsave(&info->lock,flags);
- if (active)
- info->signals |= SerialSignal_RTS | SerialSignal_DTR;
- else
- info->signals &= ~(SerialSignal_RTS | SerialSignal_DTR);
- set_gtsignals(info);
- spin_unlock_irqrestore(&info->lock,flags);
-}
-
-
-/*
- * block current process until the device is ready to open
- */
-static int block_til_ready(struct tty_struct *tty, struct file *filp,
- struct slgt_info *info)
-{
- DECLARE_WAITQUEUE(wait, current);
- int retval;
- bool do_clocal = false;
- unsigned long flags;
- bool cd;
- struct tty_port *port = &info->port;
-
- DBGINFO(("%s block_til_ready\n", tty->driver->name));
-
- if (filp->f_flags & O_NONBLOCK || tty_io_error(tty)) {
- /* nonblock mode is set or port is not enabled */
- tty_port_set_active(port, true);
- return 0;
- }
-
- if (C_CLOCAL(tty))
- do_clocal = true;
-
- /* Wait for carrier detect and the line to become
- * free (i.e., not in use by the callout). While we are in
- * this loop, port->count is dropped by one, so that
- * close() knows when to free things. We restore it upon
- * exit, either normal or abnormal.
- */
-
- retval = 0;
- add_wait_queue(&port->open_wait, &wait);
-
- spin_lock_irqsave(&info->lock, flags);
- port->count--;
- spin_unlock_irqrestore(&info->lock, flags);
- port->blocked_open++;
-
- while (1) {
- if (C_BAUD(tty) && tty_port_initialized(port))
- tty_port_raise_dtr_rts(port);
-
- set_current_state(TASK_INTERRUPTIBLE);
-
- if (tty_hung_up_p(filp) || !tty_port_initialized(port)) {
- retval = (port->flags & ASYNC_HUP_NOTIFY) ?
- -EAGAIN : -ERESTARTSYS;
- break;
- }
-
- cd = tty_port_carrier_raised(port);
- if (do_clocal || cd)
- break;
-
- if (signal_pending(current)) {
- retval = -ERESTARTSYS;
- break;
- }
-
- DBGINFO(("%s block_til_ready wait\n", tty->driver->name));
- tty_unlock(tty);
- schedule();
- tty_lock(tty);
- }
-
- set_current_state(TASK_RUNNING);
- remove_wait_queue(&port->open_wait, &wait);
-
- if (!tty_hung_up_p(filp))
- port->count++;
- port->blocked_open--;
-
- if (!retval)
- tty_port_set_active(port, true);
-
- DBGINFO(("%s block_til_ready ready, rc=%d\n", tty->driver->name, retval));
- return retval;
-}
-
-/*
- * allocate buffers used for calling line discipline receive_buf
- * directly in synchronous mode
- * note: add 5 bytes to max frame size to allow appending
- * 32-bit CRC and status byte when configured to do so
- */
-static int alloc_tmp_rbuf(struct slgt_info *info)
-{
- info->tmp_rbuf = kmalloc(info->max_frame_size + 5, GFP_KERNEL);
- if (info->tmp_rbuf == NULL)
- return -ENOMEM;
-
- return 0;
-}
-
-static void free_tmp_rbuf(struct slgt_info *info)
-{
- kfree(info->tmp_rbuf);
- info->tmp_rbuf = NULL;
-}
-
-/*
- * allocate DMA descriptor lists.
- */
-static int alloc_desc(struct slgt_info *info)
-{
- unsigned int i;
- unsigned int pbufs;
-
- /* allocate memory to hold descriptor lists */
- info->bufs = dma_alloc_coherent(&info->pdev->dev, DESC_LIST_SIZE,
- &info->bufs_dma_addr, GFP_KERNEL);
- if (info->bufs == NULL)
- return -ENOMEM;
-
- info->rbufs = (struct slgt_desc*)info->bufs;
- info->tbufs = ((struct slgt_desc*)info->bufs) + info->rbuf_count;
-
- pbufs = (unsigned int)info->bufs_dma_addr;
-
- /*
- * Build circular lists of descriptors
- */
-
- for (i=0; i < info->rbuf_count; i++) {
- /* physical address of this descriptor */
- info->rbufs[i].pdesc = pbufs + (i * sizeof(struct slgt_desc));
-
- /* physical address of next descriptor */
- if (i == info->rbuf_count - 1)
- info->rbufs[i].next = cpu_to_le32(pbufs);
- else
- info->rbufs[i].next = cpu_to_le32(pbufs + ((i+1) * sizeof(struct slgt_desc)));
- set_desc_count(info->rbufs[i], DMABUFSIZE);
- }
-
- for (i=0; i < info->tbuf_count; i++) {
- /* physical address of this descriptor */
- info->tbufs[i].pdesc = pbufs + ((info->rbuf_count + i) * sizeof(struct slgt_desc));
-
- /* physical address of next descriptor */
- if (i == info->tbuf_count - 1)
- info->tbufs[i].next = cpu_to_le32(pbufs + info->rbuf_count * sizeof(struct slgt_desc));
- else
- info->tbufs[i].next = cpu_to_le32(pbufs + ((info->rbuf_count + i + 1) * sizeof(struct slgt_desc)));
- }
-
- return 0;
-}
-
-static void free_desc(struct slgt_info *info)
-{
- if (info->bufs != NULL) {
- dma_free_coherent(&info->pdev->dev, DESC_LIST_SIZE,
- info->bufs, info->bufs_dma_addr);
- info->bufs = NULL;
- info->rbufs = NULL;
- info->tbufs = NULL;
- }
-}
-
-static int alloc_bufs(struct slgt_info *info, struct slgt_desc *bufs, int count)
-{
- int i;
- for (i=0; i < count; i++) {
- bufs[i].buf = dma_alloc_coherent(&info->pdev->dev, DMABUFSIZE,
- &bufs[i].buf_dma_addr, GFP_KERNEL);
- if (!bufs[i].buf)
- return -ENOMEM;
- bufs[i].pbuf = cpu_to_le32((unsigned int)bufs[i].buf_dma_addr);
- }
- return 0;
-}
-
-static void free_bufs(struct slgt_info *info, struct slgt_desc *bufs, int count)
-{
- int i;
- for (i=0; i < count; i++) {
- if (bufs[i].buf == NULL)
- continue;
- dma_free_coherent(&info->pdev->dev, DMABUFSIZE, bufs[i].buf,
- bufs[i].buf_dma_addr);
- bufs[i].buf = NULL;
- }
-}
-
-static int alloc_dma_bufs(struct slgt_info *info)
-{
- info->rbuf_count = 32;
- info->tbuf_count = 32;
-
- if (alloc_desc(info) < 0 ||
- alloc_bufs(info, info->rbufs, info->rbuf_count) < 0 ||
- alloc_bufs(info, info->tbufs, info->tbuf_count) < 0 ||
- alloc_tmp_rbuf(info) < 0) {
- DBGERR(("%s DMA buffer alloc fail\n", info->device_name));
- return -ENOMEM;
- }
- reset_rbufs(info);
- return 0;
-}
-
-static void free_dma_bufs(struct slgt_info *info)
-{
- if (info->bufs) {
- free_bufs(info, info->rbufs, info->rbuf_count);
- free_bufs(info, info->tbufs, info->tbuf_count);
- free_desc(info);
- }
- free_tmp_rbuf(info);
-}
-
-static int claim_resources(struct slgt_info *info)
-{
- if (request_mem_region(info->phys_reg_addr, SLGT_REG_SIZE, "synclink_gt") == NULL) {
- DBGERR(("%s reg addr conflict, addr=%08X\n",
- info->device_name, info->phys_reg_addr));
- info->init_error = DiagStatus_AddressConflict;
- goto errout;
- }
- else
- info->reg_addr_requested = true;
-
- info->reg_addr = ioremap(info->phys_reg_addr, SLGT_REG_SIZE);
- if (!info->reg_addr) {
- DBGERR(("%s can't map device registers, addr=%08X\n",
- info->device_name, info->phys_reg_addr));
- info->init_error = DiagStatus_CantAssignPciResources;
- goto errout;
- }
- return 0;
-
-errout:
- release_resources(info);
- return -ENODEV;
-}
-
-static void release_resources(struct slgt_info *info)
-{
- if (info->irq_requested) {
- free_irq(info->irq_level, info);
- info->irq_requested = false;
- }
-
- if (info->reg_addr_requested) {
- release_mem_region(info->phys_reg_addr, SLGT_REG_SIZE);
- info->reg_addr_requested = false;
- }
-
- if (info->reg_addr) {
- iounmap(info->reg_addr);
- info->reg_addr = NULL;
- }
-}
-
-/* Add the specified device instance data structure to the
- * global linked list of devices and increment the device count.
- */
-static void add_device(struct slgt_info *info)
-{
- char *devstr;
-
- info->next_device = NULL;
- info->line = slgt_device_count;
- sprintf(info->device_name, "%s%d", tty_dev_prefix, info->line);
-
- if (info->line < MAX_DEVICES) {
- if (maxframe[info->line])
- info->max_frame_size = maxframe[info->line];
- }
-
- slgt_device_count++;
-
- if (!slgt_device_list)
- slgt_device_list = info;
- else {
- struct slgt_info *current_dev = slgt_device_list;
- while(current_dev->next_device)
- current_dev = current_dev->next_device;
- current_dev->next_device = info;
- }
-
- if (info->max_frame_size < 4096)
- info->max_frame_size = 4096;
- else if (info->max_frame_size > 65535)
- info->max_frame_size = 65535;
-
- switch(info->pdev->device) {
- case SYNCLINK_GT_DEVICE_ID:
- devstr = "GT";
- break;
- case SYNCLINK_GT2_DEVICE_ID:
- devstr = "GT2";
- break;
- case SYNCLINK_GT4_DEVICE_ID:
- devstr = "GT4";
- break;
- case SYNCLINK_AC_DEVICE_ID:
- devstr = "AC";
- info->params.mode = MGSL_MODE_ASYNC;
- break;
- default:
- devstr = "(unknown model)";
- }
- printk("SyncLink %s %s IO=%08x IRQ=%d MaxFrameSize=%u\n",
- devstr, info->device_name, info->phys_reg_addr,
- info->irq_level, info->max_frame_size);
-
-#if SYNCLINK_GENERIC_HDLC
- hdlcdev_init(info);
-#endif
-}
-
-static const struct tty_port_operations slgt_port_ops = {
- .carrier_raised = carrier_raised,
- .dtr_rts = dtr_rts,
-};
-
-/*
- * allocate device instance structure, return NULL on failure
- */
-static struct slgt_info *alloc_dev(int adapter_num, int port_num, struct pci_dev *pdev)
-{
- struct slgt_info *info;
-
- info = kzalloc_obj(struct slgt_info);
-
- if (!info) {
- DBGERR(("%s device alloc failed adapter=%d port=%d\n",
- driver_name, adapter_num, port_num));
- } else {
- tty_port_init(&info->port);
- info->port.ops = &slgt_port_ops;
- INIT_WORK(&info->task, bh_handler);
- info->max_frame_size = 4096;
- info->base_clock = 14745600;
- info->rbuf_fill_level = DMABUFSIZE;
- init_waitqueue_head(&info->status_event_wait_q);
- init_waitqueue_head(&info->event_wait_q);
- spin_lock_init(&info->netlock);
- memcpy(&info->params,&default_params,sizeof(MGSL_PARAMS));
- info->idle_mode = HDLC_TXIDLE_FLAGS;
- info->adapter_num = adapter_num;
- info->port_num = port_num;
-
- timer_setup(&info->tx_timer, tx_timeout, 0);
- timer_setup(&info->rx_timer, rx_timeout, 0);
-
- /* Copy configuration info to device instance data */
- info->pdev = pdev;
- info->irq_level = pdev->irq;
- info->phys_reg_addr = pci_resource_start(pdev,0);
-
- info->bus_type = MGSL_BUS_TYPE_PCI;
- info->irq_flags = IRQF_SHARED;
-
- info->init_error = -1; /* assume error, set to 0 on successful init */
- }
-
- return info;
-}
-
-static void device_init(int adapter_num, struct pci_dev *pdev)
-{
- struct slgt_info *port_array[SLGT_MAX_PORTS];
- int i;
- int port_count = 1;
-
- if (pdev->device == SYNCLINK_GT2_DEVICE_ID)
- port_count = 2;
- else if (pdev->device == SYNCLINK_GT4_DEVICE_ID)
- port_count = 4;
-
- /* allocate device instances for all ports */
- for (i=0; i < port_count; ++i) {
- port_array[i] = alloc_dev(adapter_num, i, pdev);
- if (port_array[i] == NULL) {
- for (--i; i >= 0; --i) {
- tty_port_destroy(&port_array[i]->port);
- kfree(port_array[i]);
- }
- return;
- }
- }
-
- /* give copy of port_array to all ports and add to device list */
- for (i=0; i < port_count; ++i) {
- memcpy(port_array[i]->port_array, port_array, sizeof(port_array));
- add_device(port_array[i]);
- port_array[i]->port_count = port_count;
- spin_lock_init(&port_array[i]->lock);
- }
-
- /* Allocate and claim adapter resources */
- if (!claim_resources(port_array[0])) {
-
- alloc_dma_bufs(port_array[0]);
-
- /* copy resource information from first port to others */
- for (i = 1; i < port_count; ++i) {
- port_array[i]->irq_level = port_array[0]->irq_level;
- port_array[i]->reg_addr = port_array[0]->reg_addr;
- alloc_dma_bufs(port_array[i]);
- }
-
- if (request_irq(port_array[0]->irq_level,
- slgt_interrupt,
- port_array[0]->irq_flags,
- port_array[0]->device_name,
- port_array[0]) < 0) {
- DBGERR(("%s request_irq failed IRQ=%d\n",
- port_array[0]->device_name,
- port_array[0]->irq_level));
- } else {
- port_array[0]->irq_requested = true;
- adapter_test(port_array[0]);
- for (i=1 ; i < port_count ; i++) {
- port_array[i]->init_error = port_array[0]->init_error;
- port_array[i]->gpio_present = port_array[0]->gpio_present;
- }
- }
- }
-
- for (i = 0; i < port_count; ++i) {
- struct slgt_info *info = port_array[i];
- tty_port_register_device(&info->port, serial_driver, info->line,
- &info->pdev->dev);
- }
-}
-
-static int init_one(struct pci_dev *dev,
- const struct pci_device_id *ent)
-{
- if (pci_enable_device(dev)) {
- printk("error enabling pci device %p\n", dev);
- return -EIO;
- }
- pci_set_master(dev);
- device_init(slgt_device_count, dev);
- return 0;
-}
-
-static void remove_one(struct pci_dev *dev)
-{
-}
-
-static const struct tty_operations ops = {
- .open = open,
- .close = close,
- .write = write,
- .put_char = put_char,
- .flush_chars = flush_chars,
- .write_room = write_room,
- .chars_in_buffer = chars_in_buffer,
- .flush_buffer = flush_buffer,
- .ioctl = ioctl,
- .compat_ioctl = slgt_compat_ioctl,
- .throttle = throttle,
- .unthrottle = unthrottle,
- .send_xchar = send_xchar,
- .break_ctl = set_break,
- .wait_until_sent = wait_until_sent,
- .set_termios = set_termios,
- .stop = tx_hold,
- .start = tx_release,
- .hangup = hangup,
- .tiocmget = tiocmget,
- .tiocmset = tiocmset,
- .get_icount = get_icount,
- .proc_show = synclink_gt_proc_show,
-};
-
-static void slgt_cleanup(void)
-{
- struct slgt_info *info;
- struct slgt_info *tmp;
-
- if (serial_driver) {
- for (info=slgt_device_list ; info != NULL ; info=info->next_device)
- tty_unregister_device(serial_driver, info->line);
- tty_unregister_driver(serial_driver);
- tty_driver_kref_put(serial_driver);
- }
-
- /* reset devices */
- info = slgt_device_list;
- while(info) {
- reset_port(info);
- info = info->next_device;
- }
-
- /* release devices */
- info = slgt_device_list;
- while(info) {
-#if SYNCLINK_GENERIC_HDLC
- hdlcdev_exit(info);
-#endif
- free_dma_bufs(info);
- free_tmp_rbuf(info);
- if (info->port_num == 0)
- release_resources(info);
- tmp = info;
- info = info->next_device;
- tty_port_destroy(&tmp->port);
- kfree(tmp);
- }
-
- if (pci_registered)
- pci_unregister_driver(&pci_driver);
-}
-
-/*
- * Driver initialization entry point.
- */
-static int __init slgt_init(void)
-{
- int rc;
-
- serial_driver = tty_alloc_driver(MAX_DEVICES, TTY_DRIVER_REAL_RAW |
- TTY_DRIVER_DYNAMIC_DEV);
- if (IS_ERR(serial_driver)) {
- printk("%s can't allocate tty driver\n", driver_name);
- return PTR_ERR(serial_driver);
- }
-
- /* Initialize the tty_driver structure */
-
- serial_driver->driver_name = "synclink_gt";
- serial_driver->name = tty_dev_prefix;
- serial_driver->major = ttymajor;
- serial_driver->minor_start = 64;
- serial_driver->type = TTY_DRIVER_TYPE_SERIAL;
- serial_driver->subtype = SERIAL_TYPE_NORMAL;
- serial_driver->init_termios = tty_std_termios;
- serial_driver->init_termios.c_cflag =
- B9600 | CS8 | CREAD | HUPCL | CLOCAL;
- serial_driver->init_termios.c_ispeed = 9600;
- serial_driver->init_termios.c_ospeed = 9600;
- tty_set_operations(serial_driver, &ops);
- if ((rc = tty_register_driver(serial_driver)) < 0) {
- DBGERR(("%s can't register serial driver\n", driver_name));
- tty_driver_kref_put(serial_driver);
- serial_driver = NULL;
- goto error;
- }
-
- slgt_device_count = 0;
- if ((rc = pci_register_driver(&pci_driver)) < 0) {
- printk("%s pci_register_driver error=%d\n", driver_name, rc);
- goto error;
- }
- pci_registered = true;
-
- return 0;
-
-error:
- slgt_cleanup();
- return rc;
-}
-
-static void __exit slgt_exit(void)
-{
- slgt_cleanup();
-}
-
-module_init(slgt_init);
-module_exit(slgt_exit);
-
-/*
- * register access routines
- */
-
-static inline void __iomem *calc_regaddr(struct slgt_info *info,
- unsigned int addr)
-{
- void __iomem *reg_addr = info->reg_addr + addr;
-
- if (addr >= 0x80)
- reg_addr += info->port_num * 32;
- else if (addr >= 0x40)
- reg_addr += info->port_num * 16;
-
- return reg_addr;
-}
-
-static __u8 rd_reg8(struct slgt_info *info, unsigned int addr)
-{
- return readb(calc_regaddr(info, addr));
-}
-
-static void wr_reg8(struct slgt_info *info, unsigned int addr, __u8 value)
-{
- writeb(value, calc_regaddr(info, addr));
-}
-
-static __u16 rd_reg16(struct slgt_info *info, unsigned int addr)
-{
- return readw(calc_regaddr(info, addr));
-}
-
-static void wr_reg16(struct slgt_info *info, unsigned int addr, __u16 value)
-{
- writew(value, calc_regaddr(info, addr));
-}
-
-static __u32 rd_reg32(struct slgt_info *info, unsigned int addr)
-{
- return readl(calc_regaddr(info, addr));
-}
-
-static void wr_reg32(struct slgt_info *info, unsigned int addr, __u32 value)
-{
- writel(value, calc_regaddr(info, addr));
-}
-
-static void rdma_reset(struct slgt_info *info)
-{
- unsigned int i;
-
- /* set reset bit */
- wr_reg32(info, RDCSR, BIT1);
-
- /* wait for enable bit cleared */
- for(i=0 ; i < 1000 ; i++)
- if (!(rd_reg32(info, RDCSR) & BIT0))
- break;
-}
-
-static void tdma_reset(struct slgt_info *info)
-{
- unsigned int i;
-
- /* set reset bit */
- wr_reg32(info, TDCSR, BIT1);
-
- /* wait for enable bit cleared */
- for(i=0 ; i < 1000 ; i++)
- if (!(rd_reg32(info, TDCSR) & BIT0))
- break;
-}
-
-/*
- * enable internal loopback
- * TxCLK and RxCLK are generated from BRG
- * and TxD is looped back to RxD internally.
- */
-static void enable_loopback(struct slgt_info *info)
-{
- /* SCR (serial control) BIT2=loopback enable */
- wr_reg16(info, SCR, (unsigned short)(rd_reg16(info, SCR) | BIT2));
-
- if (info->params.mode != MGSL_MODE_ASYNC) {
- /* CCR (clock control)
- * 07..05 tx clock source (010 = BRG)
- * 04..02 rx clock source (010 = BRG)
- * 01 auxclk enable (0 = disable)
- * 00 BRG enable (1 = enable)
- *
- * 0100 1001
- */
- wr_reg8(info, CCR, 0x49);
-
- /* set speed if available, otherwise use default */
- if (info->params.clock_speed)
- set_rate(info, info->params.clock_speed);
- else
- set_rate(info, 3686400);
- }
-}
-
-/*
- * set baud rate generator to specified rate
- */
-static void set_rate(struct slgt_info *info, u32 rate)
-{
- unsigned int div;
- unsigned int osc = info->base_clock;
-
- /* div = osc/rate - 1
- *
- * Round div up if osc/rate is not integer to
- * force to next slowest rate.
- */
-
- if (rate) {
- div = osc/rate;
- if (!(osc % rate) && div)
- div--;
- wr_reg16(info, BDR, (unsigned short)div);
- }
-}
-
-static void rx_stop(struct slgt_info *info)
-{
- unsigned short val;
-
- /* disable and reset receiver */
- val = rd_reg16(info, RCR) & ~BIT1; /* clear enable bit */
- wr_reg16(info, RCR, (unsigned short)(val | BIT2)); /* set reset bit */
- wr_reg16(info, RCR, val); /* clear reset bit */
-
- slgt_irq_off(info, IRQ_RXOVER + IRQ_RXDATA + IRQ_RXIDLE);
-
- /* clear pending rx interrupts */
- wr_reg16(info, SSR, IRQ_RXIDLE + IRQ_RXOVER);
-
- rdma_reset(info);
-
- info->rx_enabled = false;
- info->rx_restart = false;
-}
-
-static void rx_start(struct slgt_info *info)
-{
- unsigned short val;
-
- slgt_irq_off(info, IRQ_RXOVER + IRQ_RXDATA);
-
- /* clear pending rx overrun IRQ */
- wr_reg16(info, SSR, IRQ_RXOVER);
-
- /* reset and disable receiver */
- val = rd_reg16(info, RCR) & ~BIT1; /* clear enable bit */
- wr_reg16(info, RCR, (unsigned short)(val | BIT2)); /* set reset bit */
- wr_reg16(info, RCR, val); /* clear reset bit */
-
- rdma_reset(info);
- reset_rbufs(info);
-
- if (info->rx_pio) {
- /* rx request when rx FIFO not empty */
- wr_reg16(info, SCR, (unsigned short)(rd_reg16(info, SCR) & ~BIT14));
- slgt_irq_on(info, IRQ_RXDATA);
- if (info->params.mode == MGSL_MODE_ASYNC) {
- /* enable saving of rx status */
- wr_reg32(info, RDCSR, BIT6);
- }
- } else {
- /* rx request when rx FIFO half full */
- wr_reg16(info, SCR, (unsigned short)(rd_reg16(info, SCR) | BIT14));
- /* set 1st descriptor address */
- wr_reg32(info, RDDAR, info->rbufs[0].pdesc);
-
- if (info->params.mode != MGSL_MODE_ASYNC) {
- /* enable rx DMA and DMA interrupt */
- wr_reg32(info, RDCSR, (BIT2 + BIT0));
- } else {
- /* enable saving of rx status, rx DMA and DMA interrupt */
- wr_reg32(info, RDCSR, (BIT6 + BIT2 + BIT0));
- }
- }
-
- slgt_irq_on(info, IRQ_RXOVER);
-
- /* enable receiver */
- wr_reg16(info, RCR, (unsigned short)(rd_reg16(info, RCR) | BIT1));
-
- info->rx_restart = false;
- info->rx_enabled = true;
-}
-
-static void tx_start(struct slgt_info *info)
-{
- if (!info->tx_enabled) {
- wr_reg16(info, TCR,
- (unsigned short)((rd_reg16(info, TCR) | BIT1) & ~BIT2));
- info->tx_enabled = true;
- }
-
- if (desc_count(info->tbufs[info->tbuf_start])) {
- info->drop_rts_on_tx_done = false;
-
- if (info->params.mode != MGSL_MODE_ASYNC) {
- if (info->params.flags & HDLC_FLAG_AUTO_RTS) {
- get_gtsignals(info);
- if (!(info->signals & SerialSignal_RTS)) {
- info->signals |= SerialSignal_RTS;
- set_gtsignals(info);
- info->drop_rts_on_tx_done = true;
- }
- }
-
- slgt_irq_off(info, IRQ_TXDATA);
- slgt_irq_on(info, IRQ_TXUNDER + IRQ_TXIDLE);
- /* clear tx idle and underrun status bits */
- wr_reg16(info, SSR, (unsigned short)(IRQ_TXIDLE + IRQ_TXUNDER));
- } else {
- slgt_irq_off(info, IRQ_TXDATA);
- slgt_irq_on(info, IRQ_TXIDLE);
- /* clear tx idle status bit */
- wr_reg16(info, SSR, IRQ_TXIDLE);
- }
- /* set 1st descriptor address and start DMA */
- wr_reg32(info, TDDAR, info->tbufs[info->tbuf_start].pdesc);
- wr_reg32(info, TDCSR, BIT2 + BIT0);
- info->tx_active = true;
- }
-}
-
-static void tx_stop(struct slgt_info *info)
-{
- unsigned short val;
-
- timer_delete(&info->tx_timer);
-
- tdma_reset(info);
-
- /* reset and disable transmitter */
- val = rd_reg16(info, TCR) & ~BIT1; /* clear enable bit */
- wr_reg16(info, TCR, (unsigned short)(val | BIT2)); /* set reset bit */
-
- slgt_irq_off(info, IRQ_TXDATA + IRQ_TXIDLE + IRQ_TXUNDER);
-
- /* clear tx idle and underrun status bit */
- wr_reg16(info, SSR, (unsigned short)(IRQ_TXIDLE + IRQ_TXUNDER));
-
- reset_tbufs(info);
-
- info->tx_enabled = false;
- info->tx_active = false;
-}
-
-static void reset_port(struct slgt_info *info)
-{
- if (!info->reg_addr)
- return;
-
- tx_stop(info);
- rx_stop(info);
-
- info->signals &= ~(SerialSignal_RTS | SerialSignal_DTR);
- set_gtsignals(info);
-
- slgt_irq_off(info, IRQ_ALL | IRQ_MASTER);
-}
-
-static void reset_adapter(struct slgt_info *info)
-{
- int i;
- for (i=0; i < info->port_count; ++i) {
- if (info->port_array[i])
- reset_port(info->port_array[i]);
- }
-}
-
-static void async_mode(struct slgt_info *info)
-{
- unsigned short val;
-
- slgt_irq_off(info, IRQ_ALL | IRQ_MASTER);
- tx_stop(info);
- rx_stop(info);
-
- /* TCR (tx control)
- *
- * 15..13 mode, 010=async
- * 12..10 encoding, 000=NRZ
- * 09 parity enable
- * 08 1=odd parity, 0=even parity
- * 07 1=RTS driver control
- * 06 1=break enable
- * 05..04 character length
- * 00=5 bits
- * 01=6 bits
- * 10=7 bits
- * 11=8 bits
- * 03 0=1 stop bit, 1=2 stop bits
- * 02 reset
- * 01 enable
- * 00 auto-CTS enable
- */
- val = 0x4000;
-
- if (info->if_mode & MGSL_INTERFACE_RTS_EN)
- val |= BIT7;
-
- if (info->params.parity != ASYNC_PARITY_NONE) {
- val |= BIT9;
- if (info->params.parity == ASYNC_PARITY_ODD)
- val |= BIT8;
- }
-
- switch (info->params.data_bits)
- {
- case 6: val |= BIT4; break;
- case 7: val |= BIT5; break;
- case 8: val |= BIT5 + BIT4; break;
- }
-
- if (info->params.stop_bits != 1)
- val |= BIT3;
-
- if (info->params.flags & HDLC_FLAG_AUTO_CTS)
- val |= BIT0;
-
- wr_reg16(info, TCR, val);
-
- /* RCR (rx control)
- *
- * 15..13 mode, 010=async
- * 12..10 encoding, 000=NRZ
- * 09 parity enable
- * 08 1=odd parity, 0=even parity
- * 07..06 reserved, must be 0
- * 05..04 character length
- * 00=5 bits
- * 01=6 bits
- * 10=7 bits
- * 11=8 bits
- * 03 reserved, must be zero
- * 02 reset
- * 01 enable
- * 00 auto-DCD enable
- */
- val = 0x4000;
-
- if (info->params.parity != ASYNC_PARITY_NONE) {
- val |= BIT9;
- if (info->params.parity == ASYNC_PARITY_ODD)
- val |= BIT8;
- }
-
- switch (info->params.data_bits)
- {
- case 6: val |= BIT4; break;
- case 7: val |= BIT5; break;
- case 8: val |= BIT5 + BIT4; break;
- }
-
- if (info->params.flags & HDLC_FLAG_AUTO_DCD)
- val |= BIT0;
-
- wr_reg16(info, RCR, val);
-
- /* CCR (clock control)
- *
- * 07..05 011 = tx clock source is BRG/16
- * 04..02 010 = rx clock source is BRG
- * 01 0 = auxclk disabled
- * 00 1 = BRG enabled
- *
- * 0110 1001
- */
- wr_reg8(info, CCR, 0x69);
-
- msc_set_vcr(info);
-
- /* SCR (serial control)
- *
- * 15 1=tx req on FIFO half empty
- * 14 1=rx req on FIFO half full
- * 13 tx data IRQ enable
- * 12 tx idle IRQ enable
- * 11 rx break on IRQ enable
- * 10 rx data IRQ enable
- * 09 rx break off IRQ enable
- * 08 overrun IRQ enable
- * 07 DSR IRQ enable
- * 06 CTS IRQ enable
- * 05 DCD IRQ enable
- * 04 RI IRQ enable
- * 03 0=16x sampling, 1=8x sampling
- * 02 1=txd->rxd internal loopback enable
- * 01 reserved, must be zero
- * 00 1=master IRQ enable
- */
- val = BIT15 + BIT14 + BIT0;
- /* JCR[8] : 1 = x8 async mode feature available */
- if ((rd_reg32(info, JCR) & BIT8) && info->params.data_rate &&
- ((info->base_clock < (info->params.data_rate * 16)) ||
- (info->base_clock % (info->params.data_rate * 16)))) {
- /* use 8x sampling */
- val |= BIT3;
- set_rate(info, info->params.data_rate * 8);
- } else {
- /* use 16x sampling */
- set_rate(info, info->params.data_rate * 16);
- }
- wr_reg16(info, SCR, val);
-
- slgt_irq_on(info, IRQ_RXBREAK | IRQ_RXOVER);
-
- if (info->params.loopback)
- enable_loopback(info);
-}
-
-static void sync_mode(struct slgt_info *info)
-{
- unsigned short val;
-
- slgt_irq_off(info, IRQ_ALL | IRQ_MASTER);
- tx_stop(info);
- rx_stop(info);
-
- /* TCR (tx control)
- *
- * 15..13 mode
- * 000=HDLC/SDLC
- * 001=raw bit synchronous
- * 010=asynchronous/isochronous
- * 011=monosync byte synchronous
- * 100=bisync byte synchronous
- * 101=xsync byte synchronous
- * 12..10 encoding
- * 09 CRC enable
- * 08 CRC32
- * 07 1=RTS driver control
- * 06 preamble enable
- * 05..04 preamble length
- * 03 share open/close flag
- * 02 reset
- * 01 enable
- * 00 auto-CTS enable
- */
- val = BIT2;
-
- switch(info->params.mode) {
- case MGSL_MODE_XSYNC:
- val |= BIT15 + BIT13;
- break;
- case MGSL_MODE_MONOSYNC: val |= BIT14 + BIT13; break;
- case MGSL_MODE_BISYNC: val |= BIT15; break;
- case MGSL_MODE_RAW: val |= BIT13; break;
- }
- if (info->if_mode & MGSL_INTERFACE_RTS_EN)
- val |= BIT7;
-
- switch(info->params.encoding)
- {
- case HDLC_ENCODING_NRZB: val |= BIT10; break;
- case HDLC_ENCODING_NRZI_MARK: val |= BIT11; break;
- case HDLC_ENCODING_NRZI: val |= BIT11 + BIT10; break;
- case HDLC_ENCODING_BIPHASE_MARK: val |= BIT12; break;
- case HDLC_ENCODING_BIPHASE_SPACE: val |= BIT12 + BIT10; break;
- case HDLC_ENCODING_BIPHASE_LEVEL: val |= BIT12 + BIT11; break;
- case HDLC_ENCODING_DIFF_BIPHASE_LEVEL: val |= BIT12 + BIT11 + BIT10; break;
- }
-
- switch (info->params.crc_type & HDLC_CRC_MASK)
- {
- case HDLC_CRC_16_CCITT: val |= BIT9; break;
- case HDLC_CRC_32_CCITT: val |= BIT9 + BIT8; break;
- }
-
- if (info->params.preamble != HDLC_PREAMBLE_PATTERN_NONE)
- val |= BIT6;
-
- switch (info->params.preamble_length)
- {
- case HDLC_PREAMBLE_LENGTH_16BITS: val |= BIT5; break;
- case HDLC_PREAMBLE_LENGTH_32BITS: val |= BIT4; break;
- case HDLC_PREAMBLE_LENGTH_64BITS: val |= BIT5 + BIT4; break;
- }
-
- if (info->params.flags & HDLC_FLAG_AUTO_CTS)
- val |= BIT0;
-
- wr_reg16(info, TCR, val);
-
- /* TPR (transmit preamble) */
-
- switch (info->params.preamble)
- {
- case HDLC_PREAMBLE_PATTERN_FLAGS: val = 0x7e; break;
- case HDLC_PREAMBLE_PATTERN_ONES: val = 0xff; break;
- case HDLC_PREAMBLE_PATTERN_ZEROS: val = 0x00; break;
- case HDLC_PREAMBLE_PATTERN_10: val = 0x55; break;
- case HDLC_PREAMBLE_PATTERN_01: val = 0xaa; break;
- default: val = 0x7e; break;
- }
- wr_reg8(info, TPR, (unsigned char)val);
-
- /* RCR (rx control)
- *
- * 15..13 mode
- * 000=HDLC/SDLC
- * 001=raw bit synchronous
- * 010=asynchronous/isochronous
- * 011=monosync byte synchronous
- * 100=bisync byte synchronous
- * 101=xsync byte synchronous
- * 12..10 encoding
- * 09 CRC enable
- * 08 CRC32
- * 07..03 reserved, must be 0
- * 02 reset
- * 01 enable
- * 00 auto-DCD enable
- */
- val = 0;
-
- switch(info->params.mode) {
- case MGSL_MODE_XSYNC:
- val |= BIT15 + BIT13;
- break;
- case MGSL_MODE_MONOSYNC: val |= BIT14 + BIT13; break;
- case MGSL_MODE_BISYNC: val |= BIT15; break;
- case MGSL_MODE_RAW: val |= BIT13; break;
- }
-
- switch(info->params.encoding)
- {
- case HDLC_ENCODING_NRZB: val |= BIT10; break;
- case HDLC_ENCODING_NRZI_MARK: val |= BIT11; break;
- case HDLC_ENCODING_NRZI: val |= BIT11 + BIT10; break;
- case HDLC_ENCODING_BIPHASE_MARK: val |= BIT12; break;
- case HDLC_ENCODING_BIPHASE_SPACE: val |= BIT12 + BIT10; break;
- case HDLC_ENCODING_BIPHASE_LEVEL: val |= BIT12 + BIT11; break;
- case HDLC_ENCODING_DIFF_BIPHASE_LEVEL: val |= BIT12 + BIT11 + BIT10; break;
- }
-
- switch (info->params.crc_type & HDLC_CRC_MASK)
- {
- case HDLC_CRC_16_CCITT: val |= BIT9; break;
- case HDLC_CRC_32_CCITT: val |= BIT9 + BIT8; break;
- }
-
- if (info->params.flags & HDLC_FLAG_AUTO_DCD)
- val |= BIT0;
-
- wr_reg16(info, RCR, val);
-
- /* CCR (clock control)
- *
- * 07..05 tx clock source
- * 04..02 rx clock source
- * 01 auxclk enable
- * 00 BRG enable
- */
- val = 0;
-
- if (info->params.flags & HDLC_FLAG_TXC_BRG)
- {
- // when RxC source is DPLL, BRG generates 16X DPLL
- // reference clock, so take TxC from BRG/16 to get
- // transmit clock at actual data rate
- if (info->params.flags & HDLC_FLAG_RXC_DPLL)
- val |= BIT6 + BIT5; /* 011, txclk = BRG/16 */
- else
- val |= BIT6; /* 010, txclk = BRG */
- }
- else if (info->params.flags & HDLC_FLAG_TXC_DPLL)
- val |= BIT7; /* 100, txclk = DPLL Input */
- else if (info->params.flags & HDLC_FLAG_TXC_RXCPIN)
- val |= BIT5; /* 001, txclk = RXC Input */
-
- if (info->params.flags & HDLC_FLAG_RXC_BRG)
- val |= BIT3; /* 010, rxclk = BRG */
- else if (info->params.flags & HDLC_FLAG_RXC_DPLL)
- val |= BIT4; /* 100, rxclk = DPLL */
- else if (info->params.flags & HDLC_FLAG_RXC_TXCPIN)
- val |= BIT2; /* 001, rxclk = TXC Input */
-
- if (info->params.clock_speed)
- val |= BIT1 + BIT0;
-
- wr_reg8(info, CCR, (unsigned char)val);
-
- if (info->params.flags & (HDLC_FLAG_TXC_DPLL + HDLC_FLAG_RXC_DPLL))
- {
- // program DPLL mode
- switch(info->params.encoding)
- {
- case HDLC_ENCODING_BIPHASE_MARK:
- case HDLC_ENCODING_BIPHASE_SPACE:
- val = BIT7; break;
- case HDLC_ENCODING_BIPHASE_LEVEL:
- case HDLC_ENCODING_DIFF_BIPHASE_LEVEL:
- val = BIT7 + BIT6; break;
- default: val = BIT6; // NRZ encodings
- }
- wr_reg16(info, RCR, (unsigned short)(rd_reg16(info, RCR) | val));
-
- // DPLL requires a 16X reference clock from BRG
- set_rate(info, info->params.clock_speed * 16);
- }
- else
- set_rate(info, info->params.clock_speed);
-
- tx_set_idle(info);
-
- msc_set_vcr(info);
-
- /* SCR (serial control)
- *
- * 15 1=tx req on FIFO half empty
- * 14 1=rx req on FIFO half full
- * 13 tx data IRQ enable
- * 12 tx idle IRQ enable
- * 11 underrun IRQ enable
- * 10 rx data IRQ enable
- * 09 rx idle IRQ enable
- * 08 overrun IRQ enable
- * 07 DSR IRQ enable
- * 06 CTS IRQ enable
- * 05 DCD IRQ enable
- * 04 RI IRQ enable
- * 03 reserved, must be zero
- * 02 1=txd->rxd internal loopback enable
- * 01 reserved, must be zero
- * 00 1=master IRQ enable
- */
- wr_reg16(info, SCR, BIT15 + BIT14 + BIT0);
-
- if (info->params.loopback)
- enable_loopback(info);
-}
-
-/*
- * set transmit idle mode
- */
-static void tx_set_idle(struct slgt_info *info)
-{
- unsigned char val;
- unsigned short tcr;
-
- /* if preamble enabled (tcr[6] == 1) then tx idle size = 8 bits
- * else tcr[5:4] = tx idle size: 00 = 8 bits, 01 = 16 bits
- */
- tcr = rd_reg16(info, TCR);
- if (info->idle_mode & HDLC_TXIDLE_CUSTOM_16) {
- /* disable preamble, set idle size to 16 bits */
- tcr = (tcr & ~(BIT6 + BIT5)) | BIT4;
- /* MSB of 16 bit idle specified in tx preamble register (TPR) */
- wr_reg8(info, TPR, (unsigned char)((info->idle_mode >> 8) & 0xff));
- } else if (!(tcr & BIT6)) {
- /* preamble is disabled, set idle size to 8 bits */
- tcr &= ~(BIT5 + BIT4);
- }
- wr_reg16(info, TCR, tcr);
-
- if (info->idle_mode & (HDLC_TXIDLE_CUSTOM_8 | HDLC_TXIDLE_CUSTOM_16)) {
- /* LSB of custom tx idle specified in tx idle register */
- val = (unsigned char)(info->idle_mode & 0xff);
- } else {
- /* standard 8 bit idle patterns */
- switch(info->idle_mode)
- {
- case HDLC_TXIDLE_FLAGS: val = 0x7e; break;
- case HDLC_TXIDLE_ALT_ZEROS_ONES:
- case HDLC_TXIDLE_ALT_MARK_SPACE: val = 0xaa; break;
- case HDLC_TXIDLE_ZEROS:
- case HDLC_TXIDLE_SPACE: val = 0x00; break;
- default: val = 0xff;
- }
- }
-
- wr_reg8(info, TIR, val);
-}
-
-/*
- * get state of V24 status (input) signals
- */
-static void get_gtsignals(struct slgt_info *info)
-{
- unsigned short status = rd_reg16(info, SSR);
-
- /* clear all serial signals except RTS and DTR */
- info->signals &= SerialSignal_RTS | SerialSignal_DTR;
-
- if (status & BIT3)
- info->signals |= SerialSignal_DSR;
- if (status & BIT2)
- info->signals |= SerialSignal_CTS;
- if (status & BIT1)
- info->signals |= SerialSignal_DCD;
- if (status & BIT0)
- info->signals |= SerialSignal_RI;
-}
-
-/*
- * set V.24 Control Register based on current configuration
- */
-static void msc_set_vcr(struct slgt_info *info)
-{
- unsigned char val = 0;
-
- /* VCR (V.24 control)
- *
- * 07..04 serial IF select
- * 03 DTR
- * 02 RTS
- * 01 LL
- * 00 RL
- */
-
- switch(info->if_mode & MGSL_INTERFACE_MASK)
- {
- case MGSL_INTERFACE_RS232:
- val |= BIT5; /* 0010 */
- break;
- case MGSL_INTERFACE_V35:
- val |= BIT7 + BIT6 + BIT5; /* 1110 */
- break;
- case MGSL_INTERFACE_RS422:
- val |= BIT6; /* 0100 */
- break;
- }
-
- if (info->if_mode & MGSL_INTERFACE_MSB_FIRST)
- val |= BIT4;
- if (info->signals & SerialSignal_DTR)
- val |= BIT3;
- if (info->signals & SerialSignal_RTS)
- val |= BIT2;
- if (info->if_mode & MGSL_INTERFACE_LL)
- val |= BIT1;
- if (info->if_mode & MGSL_INTERFACE_RL)
- val |= BIT0;
- wr_reg8(info, VCR, val);
-}
-
-/*
- * set state of V24 control (output) signals
- */
-static void set_gtsignals(struct slgt_info *info)
-{
- unsigned char val = rd_reg8(info, VCR);
- if (info->signals & SerialSignal_DTR)
- val |= BIT3;
- else
- val &= ~BIT3;
- if (info->signals & SerialSignal_RTS)
- val |= BIT2;
- else
- val &= ~BIT2;
- wr_reg8(info, VCR, val);
-}
-
-/*
- * free range of receive DMA buffers (i to last)
- */
-static void free_rbufs(struct slgt_info *info, unsigned int i, unsigned int last)
-{
- int done = 0;
-
- while(!done) {
- /* reset current buffer for reuse */
- info->rbufs[i].status = 0;
- set_desc_count(info->rbufs[i], info->rbuf_fill_level);
- if (i == last)
- done = 1;
- if (++i == info->rbuf_count)
- i = 0;
- }
- info->rbuf_current = i;
-}
-
-/*
- * mark all receive DMA buffers as free
- */
-static void reset_rbufs(struct slgt_info *info)
-{
- free_rbufs(info, 0, info->rbuf_count - 1);
- info->rbuf_fill_index = 0;
- info->rbuf_fill_count = 0;
-}
-
-/*
- * pass receive HDLC frame to upper layer
- *
- * return true if frame available, otherwise false
- */
-static bool rx_get_frame(struct slgt_info *info)
-{
- unsigned int start, end;
- unsigned short status;
- unsigned int framesize = 0;
- unsigned long flags;
- struct tty_struct *tty = info->port.tty;
- unsigned char addr_field = 0xff;
- unsigned int crc_size = 0;
-
- switch (info->params.crc_type & HDLC_CRC_MASK) {
- case HDLC_CRC_16_CCITT: crc_size = 2; break;
- case HDLC_CRC_32_CCITT: crc_size = 4; break;
- }
-
-check_again:
-
- framesize = 0;
- addr_field = 0xff;
- start = end = info->rbuf_current;
-
- for (;;) {
- if (!desc_complete(info->rbufs[end]))
- goto cleanup;
-
- if (framesize == 0 && info->params.addr_filter != 0xff)
- addr_field = info->rbufs[end].buf[0];
-
- framesize += desc_count(info->rbufs[end]);
-
- if (desc_eof(info->rbufs[end]))
- break;
-
- if (++end == info->rbuf_count)
- end = 0;
-
- if (end == info->rbuf_current) {
- if (info->rx_enabled){
- spin_lock_irqsave(&info->lock,flags);
- rx_start(info);
- spin_unlock_irqrestore(&info->lock,flags);
- }
- goto cleanup;
- }
- }
-
- /* status
- *
- * 15 buffer complete
- * 14..06 reserved
- * 05..04 residue
- * 02 eof (end of frame)
- * 01 CRC error
- * 00 abort
- */
- status = desc_status(info->rbufs[end]);
-
- /* ignore CRC bit if not using CRC (bit is undefined) */
- if ((info->params.crc_type & HDLC_CRC_MASK) == HDLC_CRC_NONE)
- status &= ~BIT1;
-
- if (framesize == 0 ||
- (addr_field != 0xff && addr_field != info->params.addr_filter)) {
- free_rbufs(info, start, end);
- goto check_again;
- }
-
- if (framesize < (2 + crc_size) || status & BIT0) {
- info->icount.rxshort++;
- framesize = 0;
- } else if (status & BIT1) {
- info->icount.rxcrc++;
- if (!(info->params.crc_type & HDLC_CRC_RETURN_EX))
- framesize = 0;
- }
-
-#if SYNCLINK_GENERIC_HDLC
- if (framesize == 0) {
- info->netdev->stats.rx_errors++;
- info->netdev->stats.rx_frame_errors++;
- }
-#endif
-
- DBGBH(("%s rx frame status=%04X size=%d\n",
- info->device_name, status, framesize));
- DBGDATA(info, info->rbufs[start].buf, min_t(int, framesize, info->rbuf_fill_level), "rx");
-
- if (framesize) {
- if (!(info->params.crc_type & HDLC_CRC_RETURN_EX)) {
- framesize -= crc_size;
- crc_size = 0;
- }
-
- if (framesize > info->max_frame_size + crc_size)
- info->icount.rxlong++;
- else {
- /* copy dma buffer(s) to contiguous temp buffer */
- int copy_count = framesize;
- int i = start;
- unsigned char *p = info->tmp_rbuf;
- info->tmp_rbuf_count = framesize;
-
- info->icount.rxok++;
-
- while(copy_count) {
- int partial_count = min_t(int, copy_count, info->rbuf_fill_level);
- memcpy(p, info->rbufs[i].buf, partial_count);
- p += partial_count;
- copy_count -= partial_count;
- if (++i == info->rbuf_count)
- i = 0;
- }
-
- if (info->params.crc_type & HDLC_CRC_RETURN_EX) {
- *p = (status & BIT1) ? RX_CRC_ERROR : RX_OK;
- framesize++;
- }
-
-#if SYNCLINK_GENERIC_HDLC
- if (info->netcount)
- hdlcdev_rx(info,info->tmp_rbuf, framesize);
- else
-#endif
- ldisc_receive_buf(tty, info->tmp_rbuf, NULL,
- framesize);
- }
- }
- free_rbufs(info, start, end);
- return true;
-
-cleanup:
- return false;
-}
-
-/*
- * pass receive buffer (RAW synchronous mode) to tty layer
- * return true if buffer available, otherwise false
- */
-static bool rx_get_buf(struct slgt_info *info)
-{
- unsigned int i = info->rbuf_current;
- unsigned int count;
-
- if (!desc_complete(info->rbufs[i]))
- return false;
- count = desc_count(info->rbufs[i]);
- switch(info->params.mode) {
- case MGSL_MODE_MONOSYNC:
- case MGSL_MODE_BISYNC:
- case MGSL_MODE_XSYNC:
- /* ignore residue in byte synchronous modes */
- if (desc_residue(info->rbufs[i]))
- count--;
- break;
- }
- DBGDATA(info, info->rbufs[i].buf, count, "rx");
- DBGINFO(("rx_get_buf size=%d\n", count));
- if (count)
- ldisc_receive_buf(info->port.tty, info->rbufs[i].buf, NULL,
- count);
- free_rbufs(info, i, i);
- return true;
-}
-
-static void reset_tbufs(struct slgt_info *info)
-{
- unsigned int i;
- info->tbuf_current = 0;
- for (i=0 ; i < info->tbuf_count ; i++) {
- info->tbufs[i].status = 0;
- info->tbufs[i].count = 0;
- }
-}
-
-/*
- * return number of free transmit DMA buffers
- */
-static unsigned int free_tbuf_count(struct slgt_info *info)
-{
- unsigned int count = 0;
- unsigned int i = info->tbuf_current;
-
- do
- {
- if (desc_count(info->tbufs[i]))
- break; /* buffer in use */
- ++count;
- if (++i == info->tbuf_count)
- i=0;
- } while (i != info->tbuf_current);
-
- /* if tx DMA active, last zero count buffer is in use */
- if (count && (rd_reg32(info, TDCSR) & BIT0))
- --count;
-
- return count;
-}
-
-/*
- * return number of bytes in unsent transmit DMA buffers
- * and the serial controller tx FIFO
- */
-static unsigned int tbuf_bytes(struct slgt_info *info)
-{
- unsigned int total_count = 0;
- unsigned int i = info->tbuf_current;
- unsigned int reg_value;
- unsigned int count;
- unsigned int active_buf_count = 0;
-
- /*
- * Add descriptor counts for all tx DMA buffers.
- * If count is zero (cleared by DMA controller after read),
- * the buffer is complete or is actively being read from.
- *
- * Record buf_count of last buffer with zero count starting
- * from current ring position. buf_count is mirror
- * copy of count and is not cleared by serial controller.
- * If DMA controller is active, that buffer is actively
- * being read so add to total.
- */
- do {
- count = desc_count(info->tbufs[i]);
- if (count)
- total_count += count;
- else if (!total_count)
- active_buf_count = info->tbufs[i].buf_count;
- if (++i == info->tbuf_count)
- i = 0;
- } while (i != info->tbuf_current);
-
- /* read tx DMA status register */
- reg_value = rd_reg32(info, TDCSR);
-
- /* if tx DMA active, last zero count buffer is in use */
- if (reg_value & BIT0)
- total_count += active_buf_count;
-
- /* add tx FIFO count = reg_value[15..8] */
- total_count += (reg_value >> 8) & 0xff;
-
- /* if transmitter active add one byte for shift register */
- if (info->tx_active)
- total_count++;
-
- return total_count;
-}
-
-/*
- * load data into transmit DMA buffer ring and start transmitter if needed
- * return true if data accepted, otherwise false (buffers full)
- */
-static bool tx_load(struct slgt_info *info, const u8 *buf, unsigned int size)
-{
- unsigned short count;
- unsigned int i;
- struct slgt_desc *d;
-
- /* check required buffer space */
- if (DIV_ROUND_UP(size, DMABUFSIZE) > free_tbuf_count(info))
- return false;
-
- DBGDATA(info, buf, size, "tx");
-
- /*
- * copy data to one or more DMA buffers in circular ring
- * tbuf_start = first buffer for this data
- * tbuf_current = next free buffer
- *
- * Copy all data before making data visible to DMA controller by
- * setting descriptor count of the first buffer.
- * This prevents an active DMA controller from reading the first DMA
- * buffers of a frame and stopping before the final buffers are filled.
- */
-
- info->tbuf_start = i = info->tbuf_current;
-
- while (size) {
- d = &info->tbufs[i];
-
- count = (unsigned short)((size > DMABUFSIZE) ? DMABUFSIZE : size);
- memcpy(d->buf, buf, count);
-
- size -= count;
- buf += count;
-
- /*
- * set EOF bit for last buffer of HDLC frame or
- * for every buffer in raw mode
- */
- if ((!size && info->params.mode == MGSL_MODE_HDLC) ||
- info->params.mode == MGSL_MODE_RAW)
- set_desc_eof(*d, 1);
- else
- set_desc_eof(*d, 0);
-
- /* set descriptor count for all but first buffer */
- if (i != info->tbuf_start)
- set_desc_count(*d, count);
- d->buf_count = count;
-
- if (++i == info->tbuf_count)
- i = 0;
- }
-
- info->tbuf_current = i;
-
- /* set first buffer count to make new data visible to DMA controller */
- d = &info->tbufs[info->tbuf_start];
- set_desc_count(*d, d->buf_count);
-
- /* start transmitter if needed and update transmit timeout */
- if (!info->tx_active)
- tx_start(info);
- update_tx_timer(info);
-
- return true;
-}
-
-static int register_test(struct slgt_info *info)
-{
- static unsigned short patterns[] =
- {0x0000, 0xffff, 0xaaaa, 0x5555, 0x6969, 0x9696};
- static unsigned int count = ARRAY_SIZE(patterns);
- unsigned int i;
- int rc = 0;
-
- for (i=0 ; i < count ; i++) {
- wr_reg16(info, TIR, patterns[i]);
- wr_reg16(info, BDR, patterns[(i+1)%count]);
- if ((rd_reg16(info, TIR) != patterns[i]) ||
- (rd_reg16(info, BDR) != patterns[(i+1)%count])) {
- rc = -ENODEV;
- break;
- }
- }
- info->gpio_present = (rd_reg32(info, JCR) & BIT5) ? 1 : 0;
- info->init_error = rc ? 0 : DiagStatus_AddressFailure;
- return rc;
-}
-
-static int irq_test(struct slgt_info *info)
-{
- unsigned long timeout;
- unsigned long flags;
- struct tty_struct *oldtty = info->port.tty;
- u32 speed = info->params.data_rate;
-
- info->params.data_rate = 921600;
- info->port.tty = NULL;
-
- spin_lock_irqsave(&info->lock, flags);
- async_mode(info);
- slgt_irq_on(info, IRQ_TXIDLE);
-
- /* enable transmitter */
- wr_reg16(info, TCR,
- (unsigned short)(rd_reg16(info, TCR) | BIT1));
-
- /* write one byte and wait for tx idle */
- wr_reg16(info, TDR, 0);
-
- /* assume failure */
- info->init_error = DiagStatus_IrqFailure;
- info->irq_occurred = false;
-
- spin_unlock_irqrestore(&info->lock, flags);
-
- timeout=100;
- while(timeout-- && !info->irq_occurred)
- msleep_interruptible(10);
-
- spin_lock_irqsave(&info->lock,flags);
- reset_port(info);
- spin_unlock_irqrestore(&info->lock,flags);
-
- info->params.data_rate = speed;
- info->port.tty = oldtty;
-
- info->init_error = info->irq_occurred ? 0 : DiagStatus_IrqFailure;
- return info->irq_occurred ? 0 : -ENODEV;
-}
-
-static int loopback_test_rx(struct slgt_info *info)
-{
- unsigned char *src, *dest;
- int count;
-
- if (desc_complete(info->rbufs[0])) {
- count = desc_count(info->rbufs[0]);
- src = info->rbufs[0].buf;
- dest = info->tmp_rbuf;
-
- for( ; count ; count-=2, src+=2) {
- /* src=data byte (src+1)=status byte */
- if (!(*(src+1) & (BIT9 + BIT8))) {
- *dest = *src;
- dest++;
- info->tmp_rbuf_count++;
- }
- }
- DBGDATA(info, info->tmp_rbuf, info->tmp_rbuf_count, "rx");
- return 1;
- }
- return 0;
-}
-
-static int loopback_test(struct slgt_info *info)
-{
-#define TESTFRAMESIZE 20
-
- unsigned long timeout;
- u16 count;
- unsigned char buf[TESTFRAMESIZE];
- int rc = -ENODEV;
- unsigned long flags;
-
- struct tty_struct *oldtty = info->port.tty;
- MGSL_PARAMS params;
-
- memcpy(¶ms, &info->params, sizeof(params));
-
- info->params.mode = MGSL_MODE_ASYNC;
- info->params.data_rate = 921600;
- info->params.loopback = 1;
- info->port.tty = NULL;
-
- /* build and send transmit frame */
- for (count = 0; count < TESTFRAMESIZE; ++count)
- buf[count] = (unsigned char)count;
-
- info->tmp_rbuf_count = 0;
- memset(info->tmp_rbuf, 0, TESTFRAMESIZE);
-
- /* program hardware for HDLC and enabled receiver */
- spin_lock_irqsave(&info->lock,flags);
- async_mode(info);
- rx_start(info);
- tx_load(info, buf, count);
- spin_unlock_irqrestore(&info->lock, flags);
-
- /* wait for receive complete */
- for (timeout = 100; timeout; --timeout) {
- msleep_interruptible(10);
- if (loopback_test_rx(info)) {
- rc = 0;
- break;
- }
- }
-
- /* verify received frame length and contents */
- if (!rc && (info->tmp_rbuf_count != count ||
- memcmp(buf, info->tmp_rbuf, count))) {
- rc = -ENODEV;
- }
-
- spin_lock_irqsave(&info->lock,flags);
- reset_adapter(info);
- spin_unlock_irqrestore(&info->lock,flags);
-
- memcpy(&info->params, ¶ms, sizeof(info->params));
- info->port.tty = oldtty;
-
- info->init_error = rc ? DiagStatus_DmaFailure : 0;
- return rc;
-}
-
-static int adapter_test(struct slgt_info *info)
-{
- DBGINFO(("testing %s\n", info->device_name));
- if (register_test(info) < 0) {
- printk("register test failure %s addr=%08X\n",
- info->device_name, info->phys_reg_addr);
- } else if (irq_test(info) < 0) {
- printk("IRQ test failure %s IRQ=%d\n",
- info->device_name, info->irq_level);
- } else if (loopback_test(info) < 0) {
- printk("loopback test failure %s\n", info->device_name);
- }
- return info->init_error;
-}
-
-/*
- * transmit timeout handler
- */
-static void tx_timeout(struct timer_list *t)
-{
- struct slgt_info *info = timer_container_of(info, t, tx_timer);
- unsigned long flags;
-
- DBGINFO(("%s tx_timeout\n", info->device_name));
- if(info->tx_active && info->params.mode == MGSL_MODE_HDLC) {
- info->icount.txtimeout++;
- }
- spin_lock_irqsave(&info->lock,flags);
- tx_stop(info);
- spin_unlock_irqrestore(&info->lock,flags);
-
-#if SYNCLINK_GENERIC_HDLC
- if (info->netcount)
- hdlcdev_tx_done(info);
- else
-#endif
- bh_transmit(info);
-}
-
-/*
- * receive buffer polling timer
- */
-static void rx_timeout(struct timer_list *t)
-{
- struct slgt_info *info = timer_container_of(info, t, rx_timer);
- unsigned long flags;
-
- DBGINFO(("%s rx_timeout\n", info->device_name));
- spin_lock_irqsave(&info->lock, flags);
- info->pending_bh |= BH_RECEIVE;
- spin_unlock_irqrestore(&info->lock, flags);
- bh_handler(&info->task);
-}
-
diff --git a/include/linux/synclink.h b/include/linux/synclink.h
deleted file mode 100644
index f1405b1c71ba..000000000000
--- a/include/linux/synclink.h
+++ /dev/null
@@ -1,37 +0,0 @@
-/*
- * SyncLink Multiprotocol Serial Adapter Driver
- *
- * $Id: synclink.h,v 3.14 2006/07/17 20:15:43 paulkf Exp $
- *
- * Copyright (C) 1998-2000 by Microgate Corporation
- *
- * Redistribution of this file is permitted under
- * the terms of the GNU Public License (GPL)
- */
-#ifndef _SYNCLINK_H_
-#define _SYNCLINK_H_
-
-#include <uapi/linux/synclink.h>
-
-/* provide 32 bit ioctl compatibility on 64 bit systems */
-#ifdef CONFIG_COMPAT
-#include <linux/compat.h>
-struct MGSL_PARAMS32 {
- compat_ulong_t mode;
- unsigned char loopback;
- unsigned short flags;
- unsigned char encoding;
- compat_ulong_t clock_speed;
- unsigned char addr_filter;
- unsigned short crc_type;
- unsigned char preamble_length;
- unsigned char preamble;
- compat_ulong_t data_rate;
- unsigned char data_bits;
- unsigned char stop_bits;
- unsigned char parity;
-};
-#define MGSL_IOCSPARAMS32 _IOW(MGSL_MAGIC_IOC,0,struct MGSL_PARAMS32)
-#define MGSL_IOCGPARAMS32 _IOR(MGSL_MAGIC_IOC,1,struct MGSL_PARAMS32)
-#endif
-#endif /* _SYNCLINK_H_ */
diff --git a/include/uapi/linux/synclink.h b/include/uapi/linux/synclink.h
deleted file mode 100644
index 62f32d4e1021..000000000000
--- a/include/uapi/linux/synclink.h
+++ /dev/null
@@ -1,301 +0,0 @@
-/* SPDX-License-Identifier: GPL-1.0+ WITH Linux-syscall-note */
-/*
- * SyncLink Multiprotocol Serial Adapter Driver
- *
- * $Id: synclink.h,v 3.14 2006/07/17 20:15:43 paulkf Exp $
- *
- * Copyright (C) 1998-2000 by Microgate Corporation
- *
- * Redistribution of this file is permitted under
- * the terms of the GNU Public License (GPL)
- */
-
-#ifndef _UAPI_SYNCLINK_H_
-#define _UAPI_SYNCLINK_H_
-#define SYNCLINK_H_VERSION 3.6
-
-#include <linux/types.h>
-
-#define BIT0 0x0001
-#define BIT1 0x0002
-#define BIT2 0x0004
-#define BIT3 0x0008
-#define BIT4 0x0010
-#define BIT5 0x0020
-#define BIT6 0x0040
-#define BIT7 0x0080
-#define BIT8 0x0100
-#define BIT9 0x0200
-#define BIT10 0x0400
-#define BIT11 0x0800
-#define BIT12 0x1000
-#define BIT13 0x2000
-#define BIT14 0x4000
-#define BIT15 0x8000
-#define BIT16 0x00010000
-#define BIT17 0x00020000
-#define BIT18 0x00040000
-#define BIT19 0x00080000
-#define BIT20 0x00100000
-#define BIT21 0x00200000
-#define BIT22 0x00400000
-#define BIT23 0x00800000
-#define BIT24 0x01000000
-#define BIT25 0x02000000
-#define BIT26 0x04000000
-#define BIT27 0x08000000
-#define BIT28 0x10000000
-#define BIT29 0x20000000
-#define BIT30 0x40000000
-#define BIT31 0x80000000
-
-
-#define HDLC_MAX_FRAME_SIZE 65535
-#define MAX_ASYNC_TRANSMIT 4096
-#define MAX_ASYNC_BUFFER_SIZE 4096
-
-#define ASYNC_PARITY_NONE 0
-#define ASYNC_PARITY_EVEN 1
-#define ASYNC_PARITY_ODD 2
-#define ASYNC_PARITY_SPACE 3
-
-#define HDLC_FLAG_UNDERRUN_ABORT7 0x0000
-#define HDLC_FLAG_UNDERRUN_ABORT15 0x0001
-#define HDLC_FLAG_UNDERRUN_FLAG 0x0002
-#define HDLC_FLAG_UNDERRUN_CRC 0x0004
-#define HDLC_FLAG_SHARE_ZERO 0x0010
-#define HDLC_FLAG_AUTO_CTS 0x0020
-#define HDLC_FLAG_AUTO_DCD 0x0040
-#define HDLC_FLAG_AUTO_RTS 0x0080
-#define HDLC_FLAG_RXC_DPLL 0x0100
-#define HDLC_FLAG_RXC_BRG 0x0200
-#define HDLC_FLAG_RXC_TXCPIN 0x8000
-#define HDLC_FLAG_RXC_RXCPIN 0x0000
-#define HDLC_FLAG_TXC_DPLL 0x0400
-#define HDLC_FLAG_TXC_BRG 0x0800
-#define HDLC_FLAG_TXC_TXCPIN 0x0000
-#define HDLC_FLAG_TXC_RXCPIN 0x0008
-#define HDLC_FLAG_DPLL_DIV8 0x1000
-#define HDLC_FLAG_DPLL_DIV16 0x2000
-#define HDLC_FLAG_DPLL_DIV32 0x0000
-#define HDLC_FLAG_HDLC_LOOPMODE 0x4000
-
-#define HDLC_CRC_NONE 0
-#define HDLC_CRC_16_CCITT 1
-#define HDLC_CRC_32_CCITT 2
-#define HDLC_CRC_MASK 0x00ff
-#define HDLC_CRC_RETURN_EX 0x8000
-
-#define RX_OK 0
-#define RX_CRC_ERROR 1
-
-#define HDLC_TXIDLE_FLAGS 0
-#define HDLC_TXIDLE_ALT_ZEROS_ONES 1
-#define HDLC_TXIDLE_ZEROS 2
-#define HDLC_TXIDLE_ONES 3
-#define HDLC_TXIDLE_ALT_MARK_SPACE 4
-#define HDLC_TXIDLE_SPACE 5
-#define HDLC_TXIDLE_MARK 6
-#define HDLC_TXIDLE_CUSTOM_8 0x10000000
-#define HDLC_TXIDLE_CUSTOM_16 0x20000000
-
-#define HDLC_ENCODING_NRZ 0
-#define HDLC_ENCODING_NRZB 1
-#define HDLC_ENCODING_NRZI_MARK 2
-#define HDLC_ENCODING_NRZI_SPACE 3
-#define HDLC_ENCODING_NRZI HDLC_ENCODING_NRZI_SPACE
-#define HDLC_ENCODING_BIPHASE_MARK 4
-#define HDLC_ENCODING_BIPHASE_SPACE 5
-#define HDLC_ENCODING_BIPHASE_LEVEL 6
-#define HDLC_ENCODING_DIFF_BIPHASE_LEVEL 7
-
-#define HDLC_PREAMBLE_LENGTH_8BITS 0
-#define HDLC_PREAMBLE_LENGTH_16BITS 1
-#define HDLC_PREAMBLE_LENGTH_32BITS 2
-#define HDLC_PREAMBLE_LENGTH_64BITS 3
-
-#define HDLC_PREAMBLE_PATTERN_NONE 0
-#define HDLC_PREAMBLE_PATTERN_ZEROS 1
-#define HDLC_PREAMBLE_PATTERN_FLAGS 2
-#define HDLC_PREAMBLE_PATTERN_10 3
-#define HDLC_PREAMBLE_PATTERN_01 4
-#define HDLC_PREAMBLE_PATTERN_ONES 5
-
-#define MGSL_MODE_ASYNC 1
-#define MGSL_MODE_HDLC 2
-#define MGSL_MODE_MONOSYNC 3
-#define MGSL_MODE_BISYNC 4
-#define MGSL_MODE_RAW 6
-#define MGSL_MODE_BASE_CLOCK 7
-#define MGSL_MODE_XSYNC 8
-
-#define MGSL_BUS_TYPE_ISA 1
-#define MGSL_BUS_TYPE_EISA 2
-#define MGSL_BUS_TYPE_PCI 5
-
-#define MGSL_INTERFACE_MASK 0xf
-#define MGSL_INTERFACE_DISABLE 0
-#define MGSL_INTERFACE_RS232 1
-#define MGSL_INTERFACE_V35 2
-#define MGSL_INTERFACE_RS422 3
-#define MGSL_INTERFACE_RTS_EN 0x10
-#define MGSL_INTERFACE_LL 0x20
-#define MGSL_INTERFACE_RL 0x40
-#define MGSL_INTERFACE_MSB_FIRST 0x80
-
-typedef struct _MGSL_PARAMS
-{
- /* Common */
-
- unsigned long mode; /* Asynchronous or HDLC */
- unsigned char loopback; /* internal loopback mode */
-
- /* HDLC Only */
-
- unsigned short flags;
- unsigned char encoding; /* NRZ, NRZI, etc. */
- unsigned long clock_speed; /* external clock speed in bits per second */
- unsigned char addr_filter; /* receive HDLC address filter, 0xFF = disable */
- unsigned short crc_type; /* None, CRC16-CCITT, or CRC32-CCITT */
- unsigned char preamble_length;
- unsigned char preamble;
-
- /* Async Only */
-
- unsigned long data_rate; /* bits per second */
- unsigned char data_bits; /* 7 or 8 data bits */
- unsigned char stop_bits; /* 1 or 2 stop bits */
- unsigned char parity; /* none, even, or odd */
-
-} MGSL_PARAMS, *PMGSL_PARAMS;
-
-#define MICROGATE_VENDOR_ID 0x13c0
-#define SYNCLINK_DEVICE_ID 0x0010
-#define MGSCC_DEVICE_ID 0x0020
-#define SYNCLINK_SCA_DEVICE_ID 0x0030
-#define SYNCLINK_GT_DEVICE_ID 0x0070
-#define SYNCLINK_GT4_DEVICE_ID 0x0080
-#define SYNCLINK_AC_DEVICE_ID 0x0090
-#define SYNCLINK_GT2_DEVICE_ID 0x00A0
-#define MGSL_MAX_SERIAL_NUMBER 30
-
-/*
-** device diagnostics status
-*/
-
-#define DiagStatus_OK 0
-#define DiagStatus_AddressFailure 1
-#define DiagStatus_AddressConflict 2
-#define DiagStatus_IrqFailure 3
-#define DiagStatus_IrqConflict 4
-#define DiagStatus_DmaFailure 5
-#define DiagStatus_DmaConflict 6
-#define DiagStatus_PciAdapterNotFound 7
-#define DiagStatus_CantAssignPciResources 8
-#define DiagStatus_CantAssignPciMemAddr 9
-#define DiagStatus_CantAssignPciIoAddr 10
-#define DiagStatus_CantAssignPciIrq 11
-#define DiagStatus_MemoryError 12
-
-#define SerialSignal_DCD 0x01 /* Data Carrier Detect */
-#define SerialSignal_TXD 0x02 /* Transmit Data */
-#define SerialSignal_RI 0x04 /* Ring Indicator */
-#define SerialSignal_RXD 0x08 /* Receive Data */
-#define SerialSignal_CTS 0x10 /* Clear to Send */
-#define SerialSignal_RTS 0x20 /* Request to Send */
-#define SerialSignal_DSR 0x40 /* Data Set Ready */
-#define SerialSignal_DTR 0x80 /* Data Terminal Ready */
-
-
-/*
- * Counters of the input lines (CTS, DSR, RI, CD) interrupts
- */
-struct mgsl_icount {
- __u32 cts, dsr, rng, dcd, tx, rx;
- __u32 frame, parity, overrun, brk;
- __u32 buf_overrun;
- __u32 txok;
- __u32 txunder;
- __u32 txabort;
- __u32 txtimeout;
- __u32 rxshort;
- __u32 rxlong;
- __u32 rxabort;
- __u32 rxover;
- __u32 rxcrc;
- __u32 rxok;
- __u32 exithunt;
- __u32 rxidle;
-};
-
-struct gpio_desc {
- __u32 state;
- __u32 smask;
- __u32 dir;
- __u32 dmask;
-};
-
-#define DEBUG_LEVEL_DATA 1
-#define DEBUG_LEVEL_ERROR 2
-#define DEBUG_LEVEL_INFO 3
-#define DEBUG_LEVEL_BH 4
-#define DEBUG_LEVEL_ISR 5
-
-/*
-** Event bit flags for use with MgslWaitEvent
-*/
-
-#define MgslEvent_DsrActive 0x0001
-#define MgslEvent_DsrInactive 0x0002
-#define MgslEvent_Dsr 0x0003
-#define MgslEvent_CtsActive 0x0004
-#define MgslEvent_CtsInactive 0x0008
-#define MgslEvent_Cts 0x000c
-#define MgslEvent_DcdActive 0x0010
-#define MgslEvent_DcdInactive 0x0020
-#define MgslEvent_Dcd 0x0030
-#define MgslEvent_RiActive 0x0040
-#define MgslEvent_RiInactive 0x0080
-#define MgslEvent_Ri 0x00c0
-#define MgslEvent_ExitHuntMode 0x0100
-#define MgslEvent_IdleReceived 0x0200
-
-/* Private IOCTL codes:
- *
- * MGSL_IOCSPARAMS set MGSL_PARAMS structure values
- * MGSL_IOCGPARAMS get current MGSL_PARAMS structure values
- * MGSL_IOCSTXIDLE set current transmit idle mode
- * MGSL_IOCGTXIDLE get current transmit idle mode
- * MGSL_IOCTXENABLE enable or disable transmitter
- * MGSL_IOCRXENABLE enable or disable receiver
- * MGSL_IOCTXABORT abort transmitting frame (HDLC)
- * MGSL_IOCGSTATS return current statistics
- * MGSL_IOCWAITEVENT wait for specified event to occur
- * MGSL_LOOPTXDONE transmit in HDLC LoopMode done
- * MGSL_IOCSIF set the serial interface type
- * MGSL_IOCGIF get the serial interface type
- */
-#define MGSL_MAGIC_IOC 'm'
-#define MGSL_IOCSPARAMS _IOW(MGSL_MAGIC_IOC,0,struct _MGSL_PARAMS)
-#define MGSL_IOCGPARAMS _IOR(MGSL_MAGIC_IOC,1,struct _MGSL_PARAMS)
-#define MGSL_IOCSTXIDLE _IO(MGSL_MAGIC_IOC,2)
-#define MGSL_IOCGTXIDLE _IO(MGSL_MAGIC_IOC,3)
-#define MGSL_IOCTXENABLE _IO(MGSL_MAGIC_IOC,4)
-#define MGSL_IOCRXENABLE _IO(MGSL_MAGIC_IOC,5)
-#define MGSL_IOCTXABORT _IO(MGSL_MAGIC_IOC,6)
-#define MGSL_IOCGSTATS _IO(MGSL_MAGIC_IOC,7)
-#define MGSL_IOCWAITEVENT _IOWR(MGSL_MAGIC_IOC,8,int)
-#define MGSL_IOCCLRMODCOUNT _IO(MGSL_MAGIC_IOC,15)
-#define MGSL_IOCLOOPTXDONE _IO(MGSL_MAGIC_IOC,9)
-#define MGSL_IOCSIF _IO(MGSL_MAGIC_IOC,10)
-#define MGSL_IOCGIF _IO(MGSL_MAGIC_IOC,11)
-#define MGSL_IOCSGPIO _IOW(MGSL_MAGIC_IOC,16,struct gpio_desc)
-#define MGSL_IOCGGPIO _IOR(MGSL_MAGIC_IOC,17,struct gpio_desc)
-#define MGSL_IOCWAITGPIO _IOWR(MGSL_MAGIC_IOC,18,struct gpio_desc)
-#define MGSL_IOCSXSYNC _IO(MGSL_MAGIC_IOC, 19)
-#define MGSL_IOCGXSYNC _IO(MGSL_MAGIC_IOC, 20)
-#define MGSL_IOCSXCTRL _IO(MGSL_MAGIC_IOC, 21)
-#define MGSL_IOCGXCTRL _IO(MGSL_MAGIC_IOC, 22)
-
-
-#endif /* _UAPI_SYNCLINK_H_ */
--
2.43.0
^ permalink raw reply related
* Re: [PATCH] docs: fix typos in reporting-issues.rst
From: Randy Dunlap @ 2026-05-04 0:01 UTC (permalink / raw)
To: Felipe Matarazzo, Thorsten Leemhuis, Jonathan Corbet
Cc: Shuah Khan, linux-doc, linux-kernel
In-Reply-To: <20260503232816.70687-1-felipemps@protonmail.com>
On 5/3/26 4:28 PM, Felipe Matarazzo wrote:
> Fix 33 typos: wrong words (want→what, is→if/it, sent→send,
> abound→about, exiting→existing, option→opinion, and→an),
> missing words (of, a, too, s), extra words (on, over), wrong
> word forms (built, stops, advice, severity, lists, types,
> Inquiries, requests) and garbled phrases.
>
> Signed-off-by: Felipe Matarazzo <felipemps@protonmail.com>
Reviewed-by: Randy Dunlap <rdunlap@infradead.org>
Thanks.
> ---
> .../admin-guide/reporting-issues.rst | 62 +++++++++----------
> 1 file changed, 31 insertions(+), 31 deletions(-)
>
--
~Randy
^ permalink raw reply
page: next (older) | prev (newer) | latest
- recent:[subjects (threaded)|topics (new)|topics (active)]
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox