aboutsummaryrefslogtreecommitdiff
path: root/sys/compat
diff options
context:
space:
mode:
Diffstat (limited to 'sys/compat')
-rw-r--r--sys/compat/freebsd32/Makefile1
-rw-r--r--sys/compat/freebsd32/freebsd32.h98
-rw-r--r--sys/compat/freebsd32/freebsd32_abort2.c5
-rw-r--r--sys/compat/freebsd32/freebsd32_capability.c11
-rw-r--r--sys/compat/freebsd32/freebsd32_ioctl.c4
-rw-r--r--sys/compat/freebsd32/freebsd32_ioctl.h2
-rw-r--r--sys/compat/freebsd32/freebsd32_ipc.h44
-rw-r--r--sys/compat/freebsd32/freebsd32_misc.c536
-rw-r--r--sys/compat/freebsd32/freebsd32_misc.h4
-rw-r--r--sys/compat/freebsd32/freebsd32_proto.h54
-rw-r--r--sys/compat/freebsd32/freebsd32_signal.h10
-rw-r--r--sys/compat/freebsd32/freebsd32_syscall.h39
-rw-r--r--sys/compat/freebsd32/freebsd32_syscalls.c38
-rw-r--r--sys/compat/freebsd32/freebsd32_sysent.c294
-rw-r--r--sys/compat/freebsd32/freebsd32_systrace_args.c748
-rw-r--r--sys/compat/freebsd32/freebsd32_util.h17
-rw-r--r--sys/compat/freebsd32/syscalls.conf16
-rw-r--r--sys/compat/ia32/ia32_genassym.c32
-rw-r--r--sys/compat/ia32/ia32_signal.h226
-rw-r--r--sys/compat/ia32/ia32_sysvec.c63
-rw-r--r--sys/compat/ia32/ia32_util.h2
-rw-r--r--sys/compat/lindebugfs/lindebugfs.c575
-rw-r--r--sys/compat/linprocfs/linprocfs.c926
-rw-r--r--sys/compat/linsysfs/linsysfs.c324
-rw-r--r--sys/compat/linsysfs/linsysfs.h38
-rw-r--r--sys/compat/linsysfs/linsysfs_net.c353
-rw-r--r--sys/compat/linux/check_error.d2
-rw-r--r--sys/compat/linux/check_internal_locks.d2
-rw-r--r--sys/compat/linux/linux.c378
-rw-r--r--sys/compat/linux/linux.h127
-rw-r--r--sys/compat/linux/linux_common.c10
-rw-r--r--sys/compat/linux/linux_common.h21
-rw-r--r--sys/compat/linux/linux_dtrace.h4
-rw-r--r--sys/compat/linux/linux_dummy.c75
-rw-r--r--sys/compat/linux/linux_elf.c282
-rw-r--r--sys/compat/linux/linux_elf.h40
-rw-r--r--sys/compat/linux/linux_elf32.c5
-rw-r--r--sys/compat/linux/linux_elf64.c5
-rw-r--r--sys/compat/linux/linux_emul.c72
-rw-r--r--sys/compat/linux/linux_emul.h16
-rw-r--r--sys/compat/linux/linux_errno.c6
-rw-r--r--sys/compat/linux/linux_errno.h4
-rw-r--r--sys/compat/linux/linux_errno.inc4
-rw-r--r--sys/compat/linux/linux_event.c547
-rw-r--r--sys/compat/linux/linux_event.h10
-rw-r--r--sys/compat/linux/linux_file.c699
-rw-r--r--sys/compat/linux/linux_file.h55
-rw-r--r--sys/compat/linux/linux_fork.c18
-rw-r--r--sys/compat/linux/linux_fork.h6
-rw-r--r--sys/compat/linux/linux_futex.c94
-rw-r--r--sys/compat/linux/linux_futex.h13
-rw-r--r--sys/compat/linux/linux_getcwd.c13
-rw-r--r--sys/compat/linux/linux_ioctl.c626
-rw-r--r--sys/compat/linux/linux_ioctl.h35
-rw-r--r--sys/compat/linux/linux_ipc.c345
-rw-r--r--sys/compat/linux/linux_ipc.h15
-rw-r--r--sys/compat/linux/linux_ipc64.h6
-rw-r--r--sys/compat/linux/linux_mib.c19
-rw-r--r--sys/compat/linux/linux_mib.h15
-rw-r--r--sys/compat/linux/linux_misc.c1460
-rw-r--r--sys/compat/linux/linux_misc.h47
-rw-r--r--sys/compat/linux/linux_mmap.c25
-rw-r--r--sys/compat/linux/linux_mmap.h2
-rw-r--r--sys/compat/linux/linux_netlink.c612
-rw-r--r--sys/compat/linux/linux_persona.h3
-rw-r--r--sys/compat/linux/linux_ptrace.c77
-rw-r--r--sys/compat/linux/linux_rseq.c84
-rw-r--r--sys/compat/linux/linux_siginfo.h234
-rw-r--r--sys/compat/linux/linux_signal.c428
-rw-r--r--sys/compat/linux/linux_signal.h20
-rw-r--r--sys/compat/linux/linux_socket.c1133
-rw-r--r--sys/compat/linux/linux_socket.h68
-rw-r--r--sys/compat/linux/linux_stats.c466
-rw-r--r--sys/compat/linux/linux_sysctl.c16
-rw-r--r--sys/compat/linux/linux_time.c217
-rw-r--r--sys/compat/linux/linux_time.h (renamed from sys/compat/linux/linux_timer.h)33
-rw-r--r--sys/compat/linux/linux_timer.c81
-rw-r--r--sys/compat/linux/linux_uid16.c123
-rw-r--r--sys/compat/linux/linux_util.c72
-rw-r--r--sys/compat/linux/linux_util.h53
-rw-r--r--sys/compat/linux/linux_vdso.c37
-rw-r--r--sys/compat/linux/linux_vdso.h30
-rw-r--r--sys/compat/linux/linux_vdso_gtod.inc50
-rw-r--r--sys/compat/linux/linux_vdso_inc.S39
-rw-r--r--sys/compat/linux/linux_videodev2_compat.h4
-rw-r--r--sys/compat/linux/linux_videodev_compat.h4
-rw-r--r--sys/compat/linux/linux_xattr.c460
-rw-r--r--sys/compat/linux/stats_timing.d2
-rw-r--r--sys/compat/linux/trace_futexes.d2
-rw-r--r--sys/compat/linuxkpi/common/include/acpi/acpi.h94
-rw-r--r--sys/compat/linuxkpi/common/include/acpi/acpi_bus.h31
-rw-r--r--sys/compat/linuxkpi/common/include/acpi/actbl.h1
-rw-r--r--sys/compat/linuxkpi/common/include/acpi/video.h36
-rw-r--r--sys/compat/linuxkpi/common/include/asm-generic/io.h40
-rw-r--r--sys/compat/linuxkpi/common/include/asm/atomic-long.h16
-rw-r--r--sys/compat/linuxkpi/common/include/asm/atomic.h42
-rw-r--r--sys/compat/linuxkpi/common/include/asm/atomic64.h17
-rw-r--r--sys/compat/linuxkpi/common/include/asm/barrier.h64
-rw-r--r--sys/compat/linuxkpi/common/include/asm/byteorder.h8
-rw-r--r--sys/compat/linuxkpi/common/include/asm/cpufeature.h37
-rw-r--r--sys/compat/linuxkpi/common/include/asm/fcntl.h8
-rw-r--r--sys/compat/linuxkpi/common/include/asm/fpu/api.h10
-rw-r--r--sys/compat/linuxkpi/common/include/asm/hypervisor.h19
-rw-r--r--sys/compat/linuxkpi/common/include/asm/intel-family.h6
-rw-r--r--sys/compat/linuxkpi/common/include/asm/io.h15
-rw-r--r--sys/compat/linuxkpi/common/include/asm/iosf_mbi.h15
-rw-r--r--sys/compat/linuxkpi/common/include/asm/memtype.h18
-rw-r--r--sys/compat/linuxkpi/common/include/asm/msr.h8
-rw-r--r--sys/compat/linuxkpi/common/include/asm/neon.h40
-rw-r--r--sys/compat/linuxkpi/common/include/asm/pgtable.h23
-rw-r--r--sys/compat/linuxkpi/common/include/asm/processor.h63
-rw-r--r--sys/compat/linuxkpi/common/include/asm/set_memory.h126
-rw-r--r--sys/compat/linuxkpi/common/include/asm/smp.h12
-rw-r--r--sys/compat/linuxkpi/common/include/asm/topology.h54
-rw-r--r--sys/compat/linuxkpi/common/include/asm/types.h8
-rw-r--r--sys/compat/linuxkpi/common/include/asm/uaccess.h11
-rw-r--r--sys/compat/linuxkpi/common/include/asm/unaligned.h33
-rw-r--r--sys/compat/linuxkpi/common/include/crypto/hash.h94
-rw-r--r--sys/compat/linuxkpi/common/include/kunit/static_stub.h15
-rw-r--r--sys/compat/linuxkpi/common/include/linux/acpi.h14
-rw-r--r--sys/compat/linuxkpi/common/include/linux/acpi_amd_wbrf.h97
-rw-r--r--sys/compat/linuxkpi/common/include/linux/agp_backend.h28
-rw-r--r--sys/compat/linuxkpi/common/include/linux/anon_inodes.h8
-rw-r--r--sys/compat/linuxkpi/common/include/linux/aperture.h64
-rw-r--r--sys/compat/linuxkpi/common/include/linux/apple-gmux.h12
-rw-r--r--sys/compat/linuxkpi/common/include/linux/atomic.h9
-rw-r--r--sys/compat/linuxkpi/common/include/linux/average.h8
-rw-r--r--sys/compat/linuxkpi/common/include/linux/backlight.h32
-rw-r--r--sys/compat/linuxkpi/common/include/linux/bcd.h2
-rw-r--r--sys/compat/linuxkpi/common/include/linux/bitfield.h59
-rw-r--r--sys/compat/linuxkpi/common/include/linux/bitmap.h106
-rw-r--r--sys/compat/linuxkpi/common/include/linux/bitops.h41
-rw-r--r--sys/compat/linuxkpi/common/include/linux/bottom_half.h8
-rw-r--r--sys/compat/linuxkpi/common/include/linux/bsearch.h8
-rw-r--r--sys/compat/linuxkpi/common/include/linux/build_bug.h65
-rw-r--r--sys/compat/linuxkpi/common/include/linux/cache.h9
-rw-r--r--sys/compat/linuxkpi/common/include/linux/capability.h51
-rw-r--r--sys/compat/linuxkpi/common/include/linux/cc_platform.h21
-rw-r--r--sys/compat/linuxkpi/common/include/linux/cdev.h21
-rw-r--r--sys/compat/linuxkpi/common/include/linux/cec.h8
-rw-r--r--sys/compat/linuxkpi/common/include/linux/cgroup.h34
-rw-r--r--sys/compat/linuxkpi/common/include/linux/circ_buf.h34
-rw-r--r--sys/compat/linuxkpi/common/include/linux/cleanup.h93
-rw-r--r--sys/compat/linuxkpi/common/include/linux/clocksource.h8
-rw-r--r--sys/compat/linuxkpi/common/include/linux/compat.h21
-rw-r--r--sys/compat/linuxkpi/common/include/linux/compiler.h52
-rw-r--r--sys/compat/linuxkpi/common/include/linux/completion.h11
-rw-r--r--sys/compat/linuxkpi/common/include/linux/console.h55
-rw-r--r--sys/compat/linuxkpi/common/include/linux/container_of.h54
-rw-r--r--sys/compat/linuxkpi/common/include/linux/cpu.h12
-rw-r--r--sys/compat/linuxkpi/common/include/linux/cpufeature.h43
-rw-r--r--sys/compat/linuxkpi/common/include/linux/crc32.h8
-rw-r--r--sys/compat/linuxkpi/common/include/linux/dcache.h13
-rw-r--r--sys/compat/linuxkpi/common/include/linux/debugfs.h95
-rw-r--r--sys/compat/linuxkpi/common/include/linux/delay.h8
-rw-r--r--sys/compat/linuxkpi/common/include/linux/devcoredump.h17
-rw-r--r--sys/compat/linuxkpi/common/include/linux/device.h254
-rw-r--r--sys/compat/linuxkpi/common/include/linux/device/driver.h33
-rw-r--r--sys/compat/linuxkpi/common/include/linux/dma-attrs.h8
-rw-r--r--sys/compat/linuxkpi/common/include/linux/dma-buf-map.h91
-rw-r--r--sys/compat/linuxkpi/common/include/linux/dma-mapping.h177
-rw-r--r--sys/compat/linuxkpi/common/include/linux/dmapool.h8
-rw-r--r--sys/compat/linuxkpi/common/include/linux/dmi.h21
-rw-r--r--sys/compat/linuxkpi/common/include/linux/dynamic_debug.h8
-rw-r--r--sys/compat/linuxkpi/common/include/linux/efi.h68
-rw-r--r--sys/compat/linuxkpi/common/include/linux/err.h8
-rw-r--r--sys/compat/linuxkpi/common/include/linux/errno.h15
-rw-r--r--sys/compat/linuxkpi/common/include/linux/etherdevice.h63
-rw-r--r--sys/compat/linuxkpi/common/include/linux/ethtool.h57
-rw-r--r--sys/compat/linuxkpi/common/include/linux/eventpoll.h45
-rw-r--r--sys/compat/linuxkpi/common/include/linux/export.h6
-rw-r--r--sys/compat/linuxkpi/common/include/linux/file.h19
-rw-r--r--sys/compat/linuxkpi/common/include/linux/fips.h12
-rw-r--r--sys/compat/linuxkpi/common/include/linux/firmware.h15
-rw-r--r--sys/compat/linuxkpi/common/include/linux/fs.h118
-rw-r--r--sys/compat/linuxkpi/common/include/linux/fwnode.h10
-rw-r--r--sys/compat/linuxkpi/common/include/linux/gcd.h6
-rw-r--r--sys/compat/linuxkpi/common/include/linux/gfp.h68
-rw-r--r--sys/compat/linuxkpi/common/include/linux/gpf.h33
-rw-r--r--sys/compat/linuxkpi/common/include/linux/hardirq.h18
-rw-r--r--sys/compat/linuxkpi/common/include/linux/hash.h76
-rw-r--r--sys/compat/linuxkpi/common/include/linux/hashtable.h183
-rw-r--r--sys/compat/linuxkpi/common/include/linux/hdmi.h447
-rw-r--r--sys/compat/linuxkpi/common/include/linux/highmem.h76
-rw-r--r--sys/compat/linuxkpi/common/include/linux/hrtimer.h11
-rw-r--r--sys/compat/linuxkpi/common/include/linux/i2c-algo-bit.h49
-rw-r--r--sys/compat/linuxkpi/common/include/linux/i2c.h177
-rw-r--r--sys/compat/linuxkpi/common/include/linux/idr.h24
-rw-r--r--sys/compat/linuxkpi/common/include/linux/ieee80211.h1269
-rw-r--r--sys/compat/linuxkpi/common/include/linux/if_arp.h8
-rw-r--r--sys/compat/linuxkpi/common/include/linux/if_ether.h25
-rw-r--r--sys/compat/linuxkpi/common/include/linux/if_vlan.h10
-rw-r--r--sys/compat/linuxkpi/common/include/linux/in.h9
-rw-r--r--sys/compat/linuxkpi/common/include/linux/in6.h8
-rw-r--r--sys/compat/linuxkpi/common/include/linux/inetdevice.h6
-rw-r--r--sys/compat/linuxkpi/common/include/linux/interrupt.h53
-rw-r--r--sys/compat/linuxkpi/common/include/linux/interval_tree.h55
-rw-r--r--sys/compat/linuxkpi/common/include/linux/interval_tree_generic.h99
-rw-r--r--sys/compat/linuxkpi/common/include/linux/io-64-nonatomic-lo-hi.h65
-rw-r--r--sys/compat/linuxkpi/common/include/linux/io-mapping.h45
-rw-r--r--sys/compat/linuxkpi/common/include/linux/io.h115
-rw-r--r--sys/compat/linuxkpi/common/include/linux/ioctl.h8
-rw-r--r--sys/compat/linuxkpi/common/include/linux/iommu.h29
-rw-r--r--sys/compat/linuxkpi/common/include/linux/iopoll.h11
-rw-r--r--sys/compat/linuxkpi/common/include/linux/ioport.h58
-rw-r--r--sys/compat/linuxkpi/common/include/linux/iosys-map.h161
-rw-r--r--sys/compat/linuxkpi/common/include/linux/ip.h9
-rw-r--r--sys/compat/linuxkpi/common/include/linux/irq_work.h33
-rw-r--r--sys/compat/linuxkpi/common/include/linux/irqdomain.h10
-rw-r--r--sys/compat/linuxkpi/common/include/linux/irqreturn.h8
-rw-r--r--sys/compat/linuxkpi/common/include/linux/jhash.h8
-rw-r--r--sys/compat/linuxkpi/common/include/linux/jiffies.h64
-rw-r--r--sys/compat/linuxkpi/common/include/linux/jump_label.h48
-rw-r--r--sys/compat/linuxkpi/common/include/linux/kconfig.h76
-rw-r--r--sys/compat/linuxkpi/common/include/linux/kdev_t.h8
-rw-r--r--sys/compat/linuxkpi/common/include/linux/kernel.h497
-rw-r--r--sys/compat/linuxkpi/common/include/linux/kernel_stat.h34
-rw-r--r--sys/compat/linuxkpi/common/include/linux/kfifo.h122
-rw-r--r--sys/compat/linuxkpi/common/include/linux/kmemleak.h8
-rw-r--r--sys/compat/linuxkpi/common/include/linux/kmod.h13
-rw-r--r--sys/compat/linuxkpi/common/include/linux/kobject.h80
-rw-r--r--sys/compat/linuxkpi/common/include/linux/kref.h28
-rw-r--r--sys/compat/linuxkpi/common/include/linux/kstrtox.h324
-rw-r--r--sys/compat/linuxkpi/common/include/linux/kthread.h105
-rw-r--r--sys/compat/linuxkpi/common/include/linux/ktime.h31
-rw-r--r--sys/compat/linuxkpi/common/include/linux/leds.h41
-rw-r--r--sys/compat/linuxkpi/common/include/linux/limits.h47
-rw-r--r--sys/compat/linuxkpi/common/include/linux/list.h58
-rw-r--r--sys/compat/linuxkpi/common/include/linux/llist.h4
-rw-r--r--sys/compat/linuxkpi/common/include/linux/lockdep.h57
-rw-r--r--sys/compat/linuxkpi/common/include/linux/log2.h104
-rw-r--r--sys/compat/linuxkpi/common/include/linux/math.h76
-rw-r--r--sys/compat/linuxkpi/common/include/linux/math64.h84
-rw-r--r--sys/compat/linuxkpi/common/include/linux/media-bus-format.h8
-rw-r--r--sys/compat/linuxkpi/common/include/linux/mhi.h222
-rw-r--r--sys/compat/linuxkpi/common/include/linux/minmax.h74
-rw-r--r--sys/compat/linuxkpi/common/include/linux/miscdevice.h8
-rw-r--r--sys/compat/linuxkpi/common/include/linux/mm.h220
-rw-r--r--sys/compat/linuxkpi/common/include/linux/mm_types.h21
-rw-r--r--sys/compat/linuxkpi/common/include/linux/mman.h38
-rw-r--r--sys/compat/linuxkpi/common/include/linux/mmap_lock.h54
-rw-r--r--sys/compat/linuxkpi/common/include/linux/mmu_context.h43
-rw-r--r--sys/compat/linuxkpi/common/include/linux/mmu_notifier.h (renamed from sys/compat/linux/linux_sysproto.h)21
-rw-r--r--sys/compat/linuxkpi/common/include/linux/mmzone.h15
-rw-r--r--sys/compat/linuxkpi/common/include/linux/mod_devicetable.h25
-rw-r--r--sys/compat/linuxkpi/common/include/linux/module.h32
-rw-r--r--sys/compat/linuxkpi/common/include/linux/moduleparam.h17
-rw-r--r--sys/compat/linuxkpi/common/include/linux/mutex.h11
-rw-r--r--sys/compat/linuxkpi/common/include/linux/net.h27
-rw-r--r--sys/compat/linuxkpi/common/include/linux/net_dim.h8
-rw-r--r--sys/compat/linuxkpi/common/include/linux/netdev_features.h32
-rw-r--r--sys/compat/linuxkpi/common/include/linux/netdevice.h444
-rw-r--r--sys/compat/linuxkpi/common/include/linux/nl80211.h455
-rw-r--r--sys/compat/linuxkpi/common/include/linux/nodemask.h46
-rw-r--r--sys/compat/linuxkpi/common/include/linux/nospec.h8
-rw-r--r--sys/compat/linuxkpi/common/include/linux/notifier.h13
-rw-r--r--sys/compat/linuxkpi/common/include/linux/numa.h8
-rw-r--r--sys/compat/linuxkpi/common/include/linux/of.h33
-rw-r--r--sys/compat/linuxkpi/common/include/linux/overflow.h520
-rw-r--r--sys/compat/linuxkpi/common/include/linux/page-flags.h41
-rw-r--r--sys/compat/linuxkpi/common/include/linux/page.h18
-rw-r--r--sys/compat/linuxkpi/common/include/linux/pagemap.h22
-rw-r--r--sys/compat/linuxkpi/common/include/linux/pagevec.h137
-rw-r--r--sys/compat/linuxkpi/common/include/linux/pci.h951
-rw-r--r--sys/compat/linuxkpi/common/include/linux/pci_ids.h10
-rw-r--r--sys/compat/linuxkpi/common/include/linux/perf_event.h34
-rw-r--r--sys/compat/linuxkpi/common/include/linux/pfn.h8
-rw-r--r--sys/compat/linuxkpi/common/include/linux/pfn_t.h8
-rw-r--r--sys/compat/linuxkpi/common/include/linux/pid.h8
-rw-r--r--sys/compat/linuxkpi/common/include/linux/platform_device.h97
-rw-r--r--sys/compat/linuxkpi/common/include/linux/pm.h66
-rw-r--r--sys/compat/linuxkpi/common/include/linux/pm_qos.h57
-rw-r--r--sys/compat/linuxkpi/common/include/linux/pm_runtime.h54
-rw-r--r--sys/compat/linuxkpi/common/include/linux/poison.h4
-rw-r--r--sys/compat/linuxkpi/common/include/linux/poll.h9
-rw-r--r--sys/compat/linuxkpi/common/include/linux/power_supply.h6
-rw-r--r--sys/compat/linuxkpi/common/include/linux/preempt.h8
-rw-r--r--sys/compat/linuxkpi/common/include/linux/prefetch.h8
-rw-r--r--sys/compat/linuxkpi/common/include/linux/printk.h75
-rw-r--r--sys/compat/linuxkpi/common/include/linux/ptp_clock_kernel.h75
-rw-r--r--sys/compat/linuxkpi/common/include/linux/pwm.h100
-rw-r--r--sys/compat/linuxkpi/common/include/linux/qrtr.h41
-rw-r--r--sys/compat/linuxkpi/common/include/linux/radix-tree.h9
-rw-r--r--sys/compat/linuxkpi/common/include/linux/random.h62
-rw-r--r--sys/compat/linuxkpi/common/include/linux/ratelimit.h17
-rw-r--r--sys/compat/linuxkpi/common/include/linux/rbtree.h135
-rw-r--r--sys/compat/linuxkpi/common/include/linux/rculist.h13
-rw-r--r--sys/compat/linuxkpi/common/include/linux/rcupdate.h68
-rw-r--r--sys/compat/linuxkpi/common/include/linux/reboot.h40
-rw-r--r--sys/compat/linuxkpi/common/include/linux/ref_tracker.h93
-rw-r--r--sys/compat/linuxkpi/common/include/linux/refcount.h33
-rw-r--r--sys/compat/linuxkpi/common/include/linux/rhashtable.h87
-rw-r--r--sys/compat/linuxkpi/common/include/linux/rwlock.h29
-rw-r--r--sys/compat/linuxkpi/common/include/linux/rwsem.h11
-rw-r--r--sys/compat/linuxkpi/common/include/linux/scatterlist.h100
-rw-r--r--sys/compat/linuxkpi/common/include/linux/sched.h63
-rw-r--r--sys/compat/linuxkpi/common/include/linux/sched/mm.h43
-rw-r--r--sys/compat/linuxkpi/common/include/linux/semaphore.h8
-rw-r--r--sys/compat/linuxkpi/common/include/linux/seq_file.h61
-rw-r--r--sys/compat/linuxkpi/common/include/linux/seqlock.h97
-rw-r--r--sys/compat/linuxkpi/common/include/linux/shmem_fs.h36
-rw-r--r--sys/compat/linuxkpi/common/include/linux/shrinker.h33
-rw-r--r--sys/compat/linuxkpi/common/include/linux/sizes.h20
-rw-r--r--sys/compat/linuxkpi/common/include/linux/skbuff.h1168
-rw-r--r--sys/compat/linuxkpi/common/include/linux/slab.h175
-rw-r--r--sys/compat/linuxkpi/common/include/linux/smp.h22
-rw-r--r--sys/compat/linuxkpi/common/include/linux/soc/mediatek/mtk_wed.h45
-rw-r--r--sys/compat/linuxkpi/common/include/linux/soc/qcom/qmi.h173
-rw-r--r--sys/compat/linuxkpi/common/include/linux/socket.h19
-rw-r--r--sys/compat/linuxkpi/common/include/linux/sort.h41
-rw-r--r--sys/compat/linuxkpi/common/include/linux/spinlock.h52
-rw-r--r--sys/compat/linuxkpi/common/include/linux/srcu.h8
-rw-r--r--sys/compat/linuxkpi/common/include/linux/stackdepot.h32
-rw-r--r--sys/compat/linuxkpi/common/include/linux/stdarg.h33
-rw-r--r--sys/compat/linuxkpi/common/include/linux/stddef.h31
-rw-r--r--sys/compat/linuxkpi/common/include/linux/string.h140
-rw-r--r--sys/compat/linuxkpi/common/include/linux/string_choices.h71
-rw-r--r--sys/compat/linuxkpi/common/include/linux/string_helpers.h12
-rw-r--r--sys/compat/linuxkpi/common/include/linux/stringify.h8
-rw-r--r--sys/compat/linuxkpi/common/include/linux/suspend.h23
-rw-r--r--sys/compat/linuxkpi/common/include/linux/swap.h27
-rw-r--r--sys/compat/linuxkpi/common/include/linux/sysfs.h258
-rw-r--r--sys/compat/linuxkpi/common/include/linux/tcp.h8
-rw-r--r--sys/compat/linuxkpi/common/include/linux/time.h16
-rw-r--r--sys/compat/linuxkpi/common/include/linux/timer.h37
-rw-r--r--sys/compat/linuxkpi/common/include/linux/topology.h35
-rw-r--r--sys/compat/linuxkpi/common/include/linux/tracepoint.h48
-rw-r--r--sys/compat/linuxkpi/common/include/linux/typecheck.h38
-rw-r--r--sys/compat/linuxkpi/common/include/linux/types.h18
-rw-r--r--sys/compat/linuxkpi/common/include/linux/uaccess.h33
-rw-r--r--sys/compat/linuxkpi/common/include/linux/udp.h8
-rw-r--r--sys/compat/linuxkpi/common/include/linux/units.h40
-rw-r--r--sys/compat/linuxkpi/common/include/linux/usb.h4
-rw-r--r--sys/compat/linuxkpi/common/include/linux/utsname.h51
-rw-r--r--sys/compat/linuxkpi/common/include/linux/uuid.h49
-rw-r--r--sys/compat/linuxkpi/common/include/linux/vgaarb.h281
-rw-r--r--sys/compat/linuxkpi/common/include/linux/vmalloc.h9
-rw-r--r--sys/compat/linuxkpi/common/include/linux/wait.h38
-rw-r--r--sys/compat/linuxkpi/common/include/linux/wait_bit.h14
-rw-r--r--sys/compat/linuxkpi/common/include/linux/workqueue.h22
-rw-r--r--sys/compat/linuxkpi/common/include/linux/ww_mutex.h15
-rw-r--r--sys/compat/linuxkpi/common/include/linux/xarray.h46
-rw-r--r--sys/compat/linuxkpi/common/include/net/addrconf.h8
-rw-r--r--sys/compat/linuxkpi/common/include/net/cfg80211.h2259
-rw-r--r--sys/compat/linuxkpi/common/include/net/ieee80211_radiotap.h10
-rw-r--r--sys/compat/linuxkpi/common/include/net/if_inet6.h8
-rw-r--r--sys/compat/linuxkpi/common/include/net/ip.h8
-rw-r--r--sys/compat/linuxkpi/common/include/net/ipv6.h8
-rw-r--r--sys/compat/linuxkpi/common/include/net/mac80211.h2681
-rw-r--r--sys/compat/linuxkpi/common/include/net/netevent.h8
-rw-r--r--sys/compat/linuxkpi/common/include/net/netlink.h53
-rw-r--r--sys/compat/linuxkpi/common/include/net/netmem.h21
-rw-r--r--sys/compat/linuxkpi/common/include/net/page_pool/helpers.h79
-rw-r--r--sys/compat/linuxkpi/common/include/net/page_pool/types.h36
-rw-r--r--sys/compat/linuxkpi/common/include/net/regulatory.h47
-rw-r--r--sys/compat/linuxkpi/common/include/net/tcp.h8
-rw-r--r--sys/compat/linuxkpi/common/include/stdarg.h33
-rw-r--r--sys/compat/linuxkpi/common/include/video/cmdline.h44
-rw-r--r--sys/compat/linuxkpi/common/include/video/mipi_display.h64
-rw-r--r--sys/compat/linuxkpi/common/include/video/vga.h19
-rw-r--r--sys/compat/linuxkpi/common/include/xen/xen.h37
-rw-r--r--sys/compat/linuxkpi/common/src/linux_80211.c8933
-rw-r--r--sys/compat/linuxkpi/common/src/linux_80211.h491
-rw-r--r--sys/compat/linuxkpi/common/src/linux_80211_macops.c762
-rw-r--r--sys/compat/linuxkpi/common/src/linux_acpi.c190
-rw-r--r--sys/compat/linuxkpi/common/src/linux_aperture.c387
-rw-r--r--sys/compat/linuxkpi/common/src/linux_cmdline.c63
-rw-r--r--sys/compat/linuxkpi/common/src/linux_compat.c699
-rw-r--r--sys/compat/linuxkpi/common/src/linux_current.c16
-rw-r--r--sys/compat/linuxkpi/common/src/linux_devres.c71
-rw-r--r--sys/compat/linuxkpi/common/src/linux_dmi.c19
-rw-r--r--sys/compat/linuxkpi/common/src/linux_domain.c3
-rw-r--r--sys/compat/linuxkpi/common/src/linux_firmware.c48
-rw-r--r--sys/compat/linuxkpi/common/src/linux_folio.c58
-rw-r--r--sys/compat/linuxkpi/common/src/linux_fpu.c32
-rw-r--r--sys/compat/linuxkpi/common/src/linux_hdmi.c1959
-rw-r--r--sys/compat/linuxkpi/common/src/linux_hrtimer.c25
-rw-r--r--sys/compat/linuxkpi/common/src/linux_i2c.c381
-rw-r--r--sys/compat/linuxkpi/common/src/linux_i2cbb.c325
-rw-r--r--sys/compat/linuxkpi/common/src/linux_idr.c22
-rw-r--r--sys/compat/linuxkpi/common/src/linux_interrupt.c21
-rw-r--r--sys/compat/linuxkpi/common/src/linux_kmod.c3
-rw-r--r--sys/compat/linuxkpi/common/src/linux_kobject.c354
-rw-r--r--sys/compat/linuxkpi/common/src/linux_kthread.c18
-rw-r--r--sys/compat/linuxkpi/common/src/linux_lock.c15
-rw-r--r--sys/compat/linuxkpi/common/src/linux_mhi.c89
-rw-r--r--sys/compat/linuxkpi/common/src/linux_netdev.c436
-rw-r--r--sys/compat/linuxkpi/common/src/linux_page.c310
-rw-r--r--sys/compat/linuxkpi/common/src/linux_pci.c1036
-rw-r--r--sys/compat/linuxkpi/common/src/linux_radix.c3
-rw-r--r--sys/compat/linuxkpi/common/src/linux_rcu.c35
-rw-r--r--sys/compat/linuxkpi/common/src/linux_schedule.c149
-rw-r--r--sys/compat/linuxkpi/common/src/linux_seq_file.c180
-rw-r--r--sys/compat/linuxkpi/common/src/linux_shmemfs.c7
-rw-r--r--sys/compat/linuxkpi/common/src/linux_shrinker.c65
-rw-r--r--sys/compat/linuxkpi/common/src/linux_simple_attr.c207
-rw-r--r--sys/compat/linuxkpi/common/src/linux_skbuff.c361
-rw-r--r--sys/compat/linuxkpi/common/src/linux_slab.c124
-rw-r--r--sys/compat/linuxkpi/common/src/linux_tasklet.c23
-rw-r--r--sys/compat/linuxkpi/common/src/linux_usb.c16
-rw-r--r--sys/compat/linuxkpi/common/src/linux_work.c87
-rw-r--r--sys/compat/linuxkpi/common/src/linux_xarray.c102
-rw-r--r--sys/compat/linuxkpi/common/src/linuxkpi_hdmikmod.c7
-rw-r--r--sys/compat/linuxkpi/common/src/linuxkpi_videokmod.c7
-rw-r--r--sys/compat/linuxkpi/common/src/lkpi_iic_if.m41
-rw-r--r--sys/compat/linuxkpi/dummy/include/acpi/button.h0
-rw-r--r--sys/compat/linuxkpi/dummy/include/asm/agp.h0
-rw-r--r--sys/compat/linuxkpi/dummy/include/asm/cacheflush.h0
-rw-r--r--sys/compat/linuxkpi/dummy/include/asm/div64.h0
-rw-r--r--sys/compat/linuxkpi/dummy/include/asm/intel-mid.h0
-rw-r--r--sys/compat/linuxkpi/dummy/include/asm/ioctl.h0
-rw-r--r--sys/compat/linuxkpi/dummy/include/asm/msr-index.h0
-rw-r--r--sys/compat/linuxkpi/dummy/include/asm/tsc.h0
-rw-r--r--sys/compat/linuxkpi/dummy/include/kunit/skbuff.h0
-rw-r--r--sys/compat/linuxkpi/dummy/include/kunit/test-bug.h0
-rw-r--r--sys/compat/linuxkpi/dummy/include/kunit/test.h0
-rw-r--r--sys/compat/linuxkpi/dummy/include/kunit/visibility.h0
-rw-r--r--sys/compat/linuxkpi/dummy/include/linux/aer.h0
-rw-r--r--sys/compat/linuxkpi/dummy/include/linux/ascii85.h0
-rw-r--r--sys/compat/linuxkpi/dummy/include/linux/async.h0
-rw-r--r--sys/compat/linuxkpi/dummy/include/linux/bits.h0
-rw-r--r--sys/compat/linuxkpi/dummy/include/linux/bug.h0
-rw-r--r--sys/compat/linuxkpi/dummy/include/linux/byteorder/generic.h0
-rw-r--r--sys/compat/linuxkpi/dummy/include/linux/component.h0
-rw-r--r--sys/compat/linuxkpi/dummy/include/linux/const.h0
-rw-r--r--sys/compat/linuxkpi/dummy/include/linux/cpufreq.h0
-rw-r--r--sys/compat/linuxkpi/dummy/include/linux/ctype.h0
-rw-r--r--sys/compat/linuxkpi/dummy/include/linux/debugobjects.h0
-rw-r--r--sys/compat/linuxkpi/dummy/include/linux/dev_printk.h0
-rw-r--r--sys/compat/linuxkpi/dummy/include/linux/device/bus.h0
-rw-r--r--sys/compat/linuxkpi/dummy/include/linux/dma-direction.h0
-rw-r--r--sys/compat/linuxkpi/dummy/include/linux/elf.h0
-rw-r--r--sys/compat/linuxkpi/dummy/include/linux/eventfd.h0
-rw-r--r--sys/compat/linuxkpi/dummy/include/linux/fault-inject.h0
-rw-r--r--sys/compat/linuxkpi/dummy/include/linux/fdtable.h0
-rw-r--r--sys/compat/linuxkpi/dummy/include/linux/hmm.h0
-rw-r--r--sys/compat/linuxkpi/dummy/include/linux/hwmon-sysfs.h0
-rw-r--r--sys/compat/linuxkpi/dummy/include/linux/hwmon.h0
-rw-r--r--sys/compat/linuxkpi/dummy/include/linux/if.h0
-rw-r--r--sys/compat/linuxkpi/dummy/include/linux/init.h0
-rw-r--r--sys/compat/linuxkpi/dummy/include/linux/input.h0
-rw-r--r--sys/compat/linuxkpi/dummy/include/linux/intel-iommu.h0
-rw-r--r--sys/compat/linuxkpi/dummy/include/linux/irq.h0
-rw-r--r--sys/compat/linuxkpi/dummy/include/linux/irqflags.h0
-rw-r--r--sys/compat/linuxkpi/dummy/include/linux/kgdb.h0
-rw-r--r--sys/compat/linuxkpi/dummy/include/linux/list_sort.h0
-rw-r--r--sys/compat/linuxkpi/dummy/include/linux/mei_aux.h0
-rw-r--r--sys/compat/linuxkpi/dummy/include/linux/mem_encrypt.h0
-rw-r--r--sys/compat/linuxkpi/dummy/include/linux/mempolicy.h0
-rw-r--r--sys/compat/linuxkpi/dummy/include/linux/memremap.h0
-rw-r--r--sys/compat/linuxkpi/dummy/include/linux/mfd/core.h0
-rw-r--r--sys/compat/linuxkpi/dummy/include/linux/mfd/intel_soc_pmic.h0
-rw-r--r--sys/compat/linuxkpi/dummy/include/linux/mmc/card.h0
-rw-r--r--sys/compat/linuxkpi/dummy/include/linux/mmc/core.h0
-rw-r--r--sys/compat/linuxkpi/dummy/include/linux/mmc/host.h0
-rw-r--r--sys/compat/linuxkpi/dummy/include/linux/mmc/mmc.h0
-rw-r--r--sys/compat/linuxkpi/dummy/include/linux/mmc/sd.h0
-rw-r--r--sys/compat/linuxkpi/dummy/include/linux/mmc/sdio.h0
-rw-r--r--sys/compat/linuxkpi/dummy/include/linux/mmc/sdio_func.h0
-rw-r--r--sys/compat/linuxkpi/dummy/include/linux/mmc/sdio_ids.h0
-rw-r--r--sys/compat/linuxkpi/dummy/include/linux/mount.h0
-rw-r--r--sys/compat/linuxkpi/dummy/include/linux/msi.h0
-rw-r--r--sys/compat/linuxkpi/dummy/include/linux/nmi.h0
-rw-r--r--sys/compat/linuxkpi/dummy/include/linux/nvmem-consumer.h0
-rw-r--r--sys/compat/linuxkpi/dummy/include/linux/of_address.h0
-rw-r--r--sys/compat/linuxkpi/dummy/include/linux/of_device.h0
-rw-r--r--sys/compat/linuxkpi/dummy/include/linux/of_irq.h0
-rw-r--r--sys/compat/linuxkpi/dummy/include/linux/of_net.h0
-rw-r--r--sys/compat/linuxkpi/dummy/include/linux/oom.h0
-rw-r--r--sys/compat/linuxkpi/dummy/include/linux/pci-p2pdma.h0
-rw-r--r--sys/compat/linuxkpi/dummy/include/linux/pgtable.h0
-rw-r--r--sys/compat/linuxkpi/dummy/include/linux/pnp.h0
-rw-r--r--sys/compat/linuxkpi/dummy/include/linux/prandom.h0
-rw-r--r--sys/compat/linuxkpi/dummy/include/linux/property.h0
-rw-r--r--sys/compat/linuxkpi/dummy/include/linux/pseudo_fs.h0
-rw-r--r--sys/compat/linuxkpi/dummy/include/linux/regmap.h0
-rw-r--r--sys/compat/linuxkpi/dummy/include/linux/relay.h0
-rw-r--r--sys/compat/linuxkpi/dummy/include/linux/remoteproc.h0
-rw-r--r--sys/compat/linuxkpi/dummy/include/linux/rtnetlink.h0
-rw-r--r--sys/compat/linuxkpi/dummy/include/linux/sched/clock.h0
-rw-r--r--sys/compat/linuxkpi/dummy/include/linux/sched/signal.h0
-rw-r--r--sys/compat/linuxkpi/dummy/include/linux/sched/task.h0
-rw-r--r--sys/compat/linuxkpi/dummy/include/linux/spinlock_types.h0
-rw-r--r--sys/compat/linuxkpi/dummy/include/linux/stacktrace.h0
-rw-r--r--sys/compat/linuxkpi/dummy/include/linux/stat.h0
-rw-r--r--sys/compat/linuxkpi/dummy/include/linux/stop_machine.h0
-rw-r--r--sys/compat/linuxkpi/dummy/include/linux/swiotlb.h0
-rw-r--r--sys/compat/linuxkpi/dummy/include/linux/syscalls.h0
-rw-r--r--sys/compat/linuxkpi/dummy/include/linux/sysfb.h0
-rw-r--r--sys/compat/linuxkpi/dummy/include/linux/sysrq.h0
-rw-r--r--sys/compat/linuxkpi/dummy/include/linux/thermal.h0
-rw-r--r--sys/compat/linuxkpi/dummy/include/linux/time64.h0
-rw-r--r--sys/compat/linuxkpi/dummy/include/linux/timekeeping.h0
-rw-r--r--sys/compat/linuxkpi/dummy/include/linux/tty.h0
-rw-r--r--sys/compat/linuxkpi/dummy/include/linux/unaligned.h0
-rw-r--r--sys/compat/linuxkpi/dummy/include/linux/util_macros.h0
-rw-r--r--sys/compat/linuxkpi/dummy/include/linux/version.h0
-rw-r--r--sys/compat/linuxkpi/dummy/include/linux/vt.h0
-rw-r--r--sys/compat/linuxkpi/dummy/include/linux/zlib.h0
-rw-r--r--sys/compat/linuxkpi/dummy/include/media/cec-notifier.h0
-rw-r--r--sys/compat/linuxkpi/dummy/include/net/gso.h0
-rw-r--r--sys/compat/linuxkpi/dummy/include/net/page_pool/helpers.h0
-rw-r--r--sys/compat/linuxkpi/dummy/include/net/rtnetlink.h0
-rw-r--r--sys/compat/linuxkpi/dummy/include/trace/define_trace.h0
-rw-r--r--sys/compat/linuxkpi/dummy/include/uapi/linux/if_arp.h0
-rw-r--r--sys/compat/linuxkpi/dummy/include/uapi/linux/sched/types.h0
-rw-r--r--sys/compat/linuxkpi/dummy/include/video/nomodeset.h0
-rw-r--r--sys/compat/linuxkpi/dummy/include/video/of_display_timing.h0
-rw-r--r--sys/compat/linuxkpi/dummy/include/video/of_videomode.h0
-rw-r--r--sys/compat/linuxkpi/dummy/include/video/videomode.h0
-rw-r--r--sys/compat/x86bios/x86bios.c12
-rw-r--r--sys/compat/x86bios/x86bios.h2
512 files changed, 46658 insertions, 7732 deletions
diff --git a/sys/compat/freebsd32/Makefile b/sys/compat/freebsd32/Makefile
index b4f72fcc2bca..6d22d5d1ae41 100644
--- a/sys/compat/freebsd32/Makefile
+++ b/sys/compat/freebsd32/Makefile
@@ -1,6 +1,5 @@
# Makefile for syscall tables
#
-# $FreeBSD$
GENERATED_PREFIX= freebsd32_
SYSENT_FILE= ${SYSDIR}/kern/syscalls.master
diff --git a/sys/compat/freebsd32/freebsd32.h b/sys/compat/freebsd32/freebsd32.h
index 4d5cea688a21..9d724c93fee7 100644
--- a/sys/compat/freebsd32/freebsd32.h
+++ b/sys/compat/freebsd32/freebsd32.h
@@ -1,5 +1,5 @@
/*-
- * SPDX-License-Identifier: BSD-2-Clause-FreeBSD
+ * SPDX-License-Identifier: BSD-2-Clause
*
* Copyright (c) 2001 Doug Rabson
* All rights reserved.
@@ -24,8 +24,6 @@
* 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.
- *
- * $FreeBSD$
*/
#ifndef _COMPAT_FREEBSD32_FREEBSD32_H_
@@ -193,16 +191,16 @@ struct nstat32 {
};
struct iovec32 {
- u_int32_t iov_base;
+ uint32_t iov_base;
int iov_len;
};
struct msghdr32 {
- u_int32_t msg_name;
+ uint32_t msg_name;
socklen_t msg_namelen;
- u_int32_t msg_iov;
+ uint32_t msg_iov;
int msg_iovlen;
- u_int32_t msg_control;
+ uint32_t msg_control;
socklen_t msg_controllen;
int msg_flags;
};
@@ -216,10 +214,10 @@ struct stat32 {
ino_t st_ino;
nlink_t st_nlink;
mode_t st_mode;
- u_int16_t st_padding0;
+ uint16_t st_bsdflags;
uid_t st_uid;
gid_t st_gid;
- u_int32_t st_padding1;
+ uint32_t st_padding1;
dev_t st_rdev;
#ifdef __STAT32_TIME_T_EXT
__int32_t st_atim_ext;
@@ -239,27 +237,28 @@ struct stat32 {
struct timespec32 st_birthtim;
off_t st_size;
int64_t st_blocks;
- u_int32_t st_blksize;
- u_int32_t st_flags;
- u_int64_t st_gen;
- u_int64_t st_spare[10];
+ uint32_t st_blksize;
+ uint32_t st_flags;
+ uint64_t st_gen;
+ uint64_t st_filerev;
+ uint64_t st_spare[9];
};
struct freebsd11_stat32 {
- u_int32_t st_dev;
- u_int32_t st_ino;
+ uint32_t st_dev;
+ uint32_t st_ino;
mode_t st_mode;
- u_int16_t st_nlink;
+ uint16_t st_nlink;
uid_t st_uid;
gid_t st_gid;
- u_int32_t st_rdev;
+ uint32_t st_rdev;
struct timespec32 st_atim;
struct timespec32 st_mtim;
struct timespec32 st_ctim;
off_t st_size;
int64_t st_blocks;
- u_int32_t st_blksize;
- u_int32_t st_flags;
- u_int32_t st_gen;
+ uint32_t st_blksize;
+ uint32_t st_flags;
+ uint32_t st_gen;
int32_t st_lspare;
struct timespec32 st_birthtim;
unsigned int :(8 / 2) * (16 - (int)sizeof(struct timespec32));
@@ -280,15 +279,15 @@ struct ostat32 {
struct timespec32 st_ctim;
__int32_t st_blksize;
__int32_t st_blocks;
- u_int32_t st_flags;
+ uint32_t st_flags;
__uint32_t st_gen;
};
struct jail32_v0 {
- u_int32_t version;
+ uint32_t version;
uint32_t path;
uint32_t hostname;
- u_int32_t ip_number;
+ uint32_t ip_number;
};
struct jail32 {
@@ -303,7 +302,7 @@ struct jail32 {
};
struct sigaction32 {
- u_int32_t sa_u;
+ uint32_t sa_u;
int sa_flags;
sigset_t sa_mask;
};
@@ -381,7 +380,7 @@ struct kinfo_proc32 {
u_int ki_slptime;
u_int ki_swtime;
u_int ki_cow;
- u_int64_t ki_runtime;
+ uint64_t ki_runtime;
struct timeval32 ki_start;
struct timeval32 ki_childtime;
int ki_flag;
@@ -420,6 +419,7 @@ struct kinfo_proc32 {
uint32_t ki_kstack;
uint32_t ki_udata;
uint32_t ki_tdaddr;
+ uint32_t ki_uerrmsg;
uint32_t ki_spareptrs[KI_NSPARE_PTR]; /* spare room for growth */
int ki_sparelongs[KI_NSPARE_LONG];
int ki_sflag;
@@ -432,6 +432,42 @@ struct kinfo_sigtramp32 {
uint32_t ksigtramp_spare[4];
};
+struct kinfo_vm_layout32 {
+ uint32_t kvm_min_user_addr;
+ uint32_t kvm_max_user_addr;
+ uint32_t kvm_text_addr;
+ uint32_t kvm_text_size;
+ uint32_t kvm_data_addr;
+ uint32_t kvm_data_size;
+ uint32_t kvm_stack_addr;
+ uint32_t kvm_stack_size;
+ int kvm_map_flags;
+ uint32_t kvm_shp_addr;
+ uint32_t kvm_shp_size;
+ uint32_t kvm_spare[12];
+};
+
+#if defined(_WANT_KEVENT32) || defined(_KERNEL)
+struct kinfo_knote32 {
+ int knt_kq_fd;
+ struct kevent32 knt_event;
+ int knt_status;
+ int knt_extdata;
+ uint32_t knt_spare0[8];
+ union {
+ struct {
+ int knt_vnode_type;
+ uint32_t knt_vnode_fsid[2];
+ uint32_t knt_vnode_fileid[2];
+ char knt_vnode_fullpath[PATH_MAX];
+ } knt_vnode;
+ struct {
+ uint32_t knt_pipe_ino[2];
+ } knt_pipe;
+ };
+};
+#endif
+
struct kld_file_stat_1_32 {
int version; /* set to sizeof(struct kld_file_stat_1) */
char name[MAXPATHLEN];
@@ -477,10 +513,22 @@ struct timex32 {
int32_t stbcnt;
};
+struct ptrace_sc_ret32 {
+ uint32_t sr_retval[2];
+ int sr_error;
+};
+
struct ptrace_coredump32 {
int pc_fd;
uint32_t pc_flags;
uint32_t pc_limit1, pc_limit2;
};
+struct ptrace_sc_remote32 {
+ struct ptrace_sc_ret32 pscr_ret;
+ u_int pscr_syscall;
+ u_int pscr_nargs;
+ uint32_t pscr_args;
+};
+
#endif /* !_COMPAT_FREEBSD32_FREEBSD32_H_ */
diff --git a/sys/compat/freebsd32/freebsd32_abort2.c b/sys/compat/freebsd32/freebsd32_abort2.c
index 615dd5e95345..47386aa22855 100644
--- a/sys/compat/freebsd32/freebsd32_abort2.c
+++ b/sys/compat/freebsd32/freebsd32_abort2.c
@@ -1,5 +1,5 @@
/*-
- * SPDX-License-Identifier: BSD-2-Clause-FreeBSD
+ * SPDX-License-Identifier: BSD-2-Clause
*
* Copyright (c) 2005 Wojciech A. Koszek
* All rights reserved.
@@ -26,9 +26,6 @@
* SUCH DAMAGE.
*/
-#include <sys/cdefs.h>
-__FBSDID("$FreeBSD$");
-
#include <sys/param.h>
#include <sys/proc.h>
#include <sys/sbuf.h>
diff --git a/sys/compat/freebsd32/freebsd32_capability.c b/sys/compat/freebsd32/freebsd32_capability.c
index 2796d2e9384f..681e511a59de 100644
--- a/sys/compat/freebsd32/freebsd32_capability.c
+++ b/sys/compat/freebsd32/freebsd32_capability.c
@@ -1,5 +1,5 @@
/*-
- * SPDX-License-Identifier: BSD-2-Clause-FreeBSD
+ * SPDX-License-Identifier: BSD-2-Clause
*
* Copyright (c) 2013 The FreeBSD Foundation
*
@@ -29,8 +29,6 @@
*/
#include <sys/cdefs.h>
-__FBSDID("$FreeBSD$");
-
#include "opt_capsicum.h"
#include <sys/param.h>
@@ -104,7 +102,7 @@ freebsd32_cap_ioctls_get(struct thread *td,
fdp = td->td_proc->p_fd;
FILEDESC_SLOCK(fdp);
- if (fget_locked(fdp, fd) == NULL) {
+ if (fget_noref(fdp, fd) == NULL) {
error = EBADF;
goto out;
}
@@ -119,9 +117,10 @@ freebsd32_cap_ioctls_get(struct thread *td,
cmds = fdep->fde_ioctls;
if (cmds32 != NULL && cmds != NULL) {
for (i = 0; i < MIN(fdep->fde_nioctls, maxcmds); i++) {
- error = suword32(&cmds32[i], cmds[i]);
- if (error != 0)
+ if (suword32(&cmds32[i], cmds[i]) != 0) {
+ error = EFAULT;
goto out;
+ }
}
}
if (fdep->fde_nioctls == -1)
diff --git a/sys/compat/freebsd32/freebsd32_ioctl.c b/sys/compat/freebsd32/freebsd32_ioctl.c
index 957c546d4daf..23c24e0b30a0 100644
--- a/sys/compat/freebsd32/freebsd32_ioctl.c
+++ b/sys/compat/freebsd32/freebsd32_ioctl.c
@@ -29,9 +29,6 @@
* SUCH DAMAGE.
*/
-#include <sys/cdefs.h>
-__FBSDID("$FreeBSD$");
-
#include <sys/param.h>
#include <sys/capsicum.h>
#include <sys/cdio.h>
@@ -46,7 +43,6 @@ __FBSDID("$FreeBSD$");
#include <sys/syscall.h>
#include <sys/syscallsubr.h>
#include <sys/sysctl.h>
-#include <sys/sysent.h>
#include <sys/sysproto.h>
#include <sys/systm.h>
#include <sys/uio.h>
diff --git a/sys/compat/freebsd32/freebsd32_ioctl.h b/sys/compat/freebsd32/freebsd32_ioctl.h
index 0c0b18496a04..b22cd76cda8d 100644
--- a/sys/compat/freebsd32/freebsd32_ioctl.h
+++ b/sys/compat/freebsd32/freebsd32_ioctl.h
@@ -27,8 +27,6 @@
* 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.
- *
- * $FreeBSD$
*/
#ifndef _COMPAT_FREEBSD32_IOCTL_H_
diff --git a/sys/compat/freebsd32/freebsd32_ipc.h b/sys/compat/freebsd32/freebsd32_ipc.h
index 6c34445e363b..4ff8af359428 100644
--- a/sys/compat/freebsd32/freebsd32_ipc.h
+++ b/sys/compat/freebsd32/freebsd32_ipc.h
@@ -1,5 +1,5 @@
/*-
- * SPDX-License-Identifier: BSD-2-Clause-FreeBSD
+ * SPDX-License-Identifier: BSD-2-Clause
*
* Copyright (c) 2002 Doug Rabson
* All rights reserved.
@@ -24,8 +24,6 @@
* 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.
- *
- * $FreeBSD$
*/
#ifndef _COMPAT_FREEBSD32_FREEBSD32_IPC_H_
@@ -45,8 +43,8 @@ struct semid_ds32 {
struct ipc_perm32 sem_perm;
uint32_t __sem_base;
unsigned short sem_nsems;
- int32_t sem_otime;
- int32_t sem_ctime;
+ time32_t sem_otime;
+ time32_t sem_ctime;
};
#ifdef _KERNEL
@@ -75,9 +73,9 @@ struct msqid_ds32 {
uint32_t msg_qbytes;
pid_t msg_lspid;
pid_t msg_lrpid;
- int32_t msg_stime;
- int32_t msg_rtime;
- int32_t msg_ctime;
+ time32_t msg_stime;
+ time32_t msg_rtime;
+ time32_t msg_ctime;
};
#ifdef _KERNEL
@@ -97,17 +95,17 @@ struct shmid_ds32 {
pid_t shm_lpid;
pid_t shm_cpid;
unsigned int shm_nattch;
- int32_t shm_atime;
- int32_t shm_dtime;
- int32_t shm_ctime;
+ time32_t shm_atime;
+ time32_t shm_dtime;
+ time32_t shm_ctime;
};
#ifdef _KERNEL
struct shmid_kernel32 {
- struct shmid_ds32 u;
- int32_t *object;
- int32_t *label;
- int32_t *cred;
+ struct shmid_ds32 u;
+ int32_t object;
+ int32_t label;
+ int32_t cred;
};
#endif
@@ -144,9 +142,9 @@ struct semid_ds_old32 {
struct ipc_perm_old32 sem_perm;
uint32_t __sem_base;
unsigned short sem_nsems;
- int32_t sem_otime;
+ time32_t sem_otime;
int32_t sem_pad1;
- int32_t sem_ctime;
+ time32_t sem_ctime;
int32_t sem_pad2;
int32_t sem_pad3[4];
};
@@ -160,11 +158,11 @@ struct msqid_ds_old32 {
uint32_t msg_qbytes;
pid_t msg_lspid;
pid_t msg_lrpid;
- int32_t msg_stime;
+ time32_t msg_stime;
int32_t msg_pad1;
- int32_t msg_rtime;
+ time32_t msg_rtime;
int32_t msg_pad2;
- int32_t msg_ctime;
+ time32_t msg_ctime;
int32_t msg_pad3;
int32_t msg_pad4[4];
};
@@ -175,9 +173,9 @@ struct shmid_ds_old32 {
pid_t shm_lpid;
pid_t shm_cpid;
int16_t shm_nattch;
- int32_t shm_atime;
- int32_t shm_dtime;
- int32_t shm_ctime;
+ time32_t shm_atime;
+ time32_t shm_dtime;
+ time32_t shm_ctime;
uint32_t shm_internal;
};
diff --git a/sys/compat/freebsd32/freebsd32_misc.c b/sys/compat/freebsd32/freebsd32_misc.c
index a51daec85fcd..e62c76924d22 100644
--- a/sys/compat/freebsd32/freebsd32_misc.c
+++ b/sys/compat/freebsd32/freebsd32_misc.c
@@ -1,5 +1,5 @@
/*-
- * SPDX-License-Identifier: BSD-2-Clause-FreeBSD
+ * SPDX-License-Identifier: BSD-2-Clause
*
* Copyright (c) 2002 Doug Rabson
* All rights reserved.
@@ -27,8 +27,6 @@
*/
#include <sys/cdefs.h>
-__FBSDID("$FreeBSD$");
-
#include "opt_ffclock.h"
#include "opt_inet.h"
#include "opt_inet6.h"
@@ -84,9 +82,11 @@ __FBSDID("$FreeBSD$");
#include <sys/sysproto.h>
#include <sys/systm.h>
#include <sys/thr.h>
+#include <sys/timerfd.h>
#include <sys/timex.h>
#include <sys/unistd.h>
#include <sys/ucontext.h>
+#include <sys/ucred.h>
#include <sys/vnode.h>
#include <sys/wait.h>
#include <sys/ipc.h>
@@ -116,6 +116,7 @@ __FBSDID("$FreeBSD$");
#endif
#include <security/audit/audit.h>
+#include <security/mac/mac_syscalls.h>
#include <compat/freebsd32/freebsd32_util.h>
#include <compat/freebsd32/freebsd32.h>
@@ -124,7 +125,20 @@ __FBSDID("$FreeBSD$");
#include <compat/freebsd32/freebsd32_signal.h>
#include <compat/freebsd32/freebsd32_proto.h>
-FEATURE(compat_freebsd_32bit, "Compatible with 32-bit FreeBSD");
+int compat_freebsd_32bit = 1;
+
+static void
+register_compat32_feature(void *arg)
+{
+ if (!compat_freebsd_32bit)
+ return;
+
+ FEATURE_ADD("compat_freebsd32", "Compatible with 32-bit FreeBSD");
+ FEATURE_ADD("compat_freebsd_32bit",
+ "Compatible with 32-bit FreeBSD (legacy feature name)");
+}
+SYSINIT(freebsd32, SI_SUB_EXEC, SI_ORDER_ANY, register_compat32_feature,
+ NULL);
struct ptrace_io_desc32 {
int piod_op;
@@ -133,11 +147,6 @@ struct ptrace_io_desc32 {
uint32_t piod_len;
};
-struct ptrace_sc_ret32 {
- uint32_t sr_retval[2];
- int sr_error;
-};
-
struct ptrace_vm_entry32 {
int pve_entry;
int pve_timestamp;
@@ -156,10 +165,17 @@ CTASSERT(sizeof(struct timeval32) == 8);
CTASSERT(sizeof(struct timespec32) == 8);
CTASSERT(sizeof(struct itimerval32) == 16);
CTASSERT(sizeof(struct bintime32) == 12);
+#else
+CTASSERT(sizeof(struct timeval32) == 16);
+CTASSERT(sizeof(struct timespec32) == 16);
+CTASSERT(sizeof(struct itimerval32) == 32);
+CTASSERT(sizeof(struct bintime32) == 16);
#endif
CTASSERT(sizeof(struct ostatfs32) == 256);
#ifdef __amd64__
CTASSERT(sizeof(struct rusage32) == 72);
+#else
+CTASSERT(sizeof(struct rusage32) == 88);
#endif
CTASSERT(sizeof(struct sigaltstack32) == 12);
#ifdef __amd64__
@@ -172,6 +188,9 @@ CTASSERT(sizeof(struct msghdr32) == 28);
#ifdef __amd64__
CTASSERT(sizeof(struct stat32) == 208);
CTASSERT(sizeof(struct freebsd11_stat32) == 96);
+#else
+CTASSERT(sizeof(struct stat32) == 224);
+CTASSERT(sizeof(struct freebsd11_stat32) == 120);
#endif
CTASSERT(sizeof(struct sigaction32) == 24);
@@ -230,7 +249,7 @@ freebsd32_wait6(struct thread *td, struct freebsd32_wait6_args *uap)
{
struct __wrusage32 wru32;
struct __wrusage wru, *wrup;
- struct siginfo32 si32;
+ struct __siginfo32 si32;
struct __siginfo si, *sip;
int error, status;
@@ -382,10 +401,10 @@ freebsd32_sigaltstack(struct thread *td,
*/
int
freebsd32_exec_copyin_args(struct image_args *args, const char *fname,
- enum uio_seg segflg, u_int32_t *argv, u_int32_t *envv)
+ uint32_t *argv, uint32_t *envv)
{
char *argp, *envp;
- u_int32_t *p32, arg;
+ uint32_t *p32, arg;
int error;
bzero(args, sizeof(*args));
@@ -403,7 +422,7 @@ freebsd32_exec_copyin_args(struct image_args *args, const char *fname,
/*
* Copy the file name.
*/
- error = exec_args_add_fname(args, fname, segflg);
+ error = exec_args_add_fname(args, fname, UIO_USERSPACE);
if (error != 0)
goto err_exit;
@@ -458,8 +477,8 @@ freebsd32_execve(struct thread *td, struct freebsd32_execve_args *uap)
error = pre_execve(td, &oldvmspace);
if (error != 0)
return (error);
- error = freebsd32_exec_copyin_args(&eargs, uap->fname, UIO_USERSPACE,
- uap->argv, uap->envv);
+ error = freebsd32_exec_copyin_args(&eargs, uap->fname, uap->argv,
+ uap->envv);
if (error == 0)
error = kern_execve(td, &eargs, NULL, oldvmspace);
post_execve(td, error, oldvmspace);
@@ -477,8 +496,7 @@ freebsd32_fexecve(struct thread *td, struct freebsd32_fexecve_args *uap)
error = pre_execve(td, &oldvmspace);
if (error != 0)
return (error);
- error = freebsd32_exec_copyin_args(&eargs, NULL, UIO_SYSSPACE,
- uap->argv, uap->envv);
+ error = freebsd32_exec_copyin_args(&eargs, NULL, uap->argv, uap->envv);
if (error == 0) {
eargs.fd = uap->fd;
error = kern_execve(td, &eargs, NULL, oldvmspace);
@@ -507,7 +525,7 @@ freebsd32_mprotect(struct thread *td, struct freebsd32_mprotect_args *uap)
prot |= PROT_EXEC;
#endif
return (kern_mprotect(td, (uintptr_t)PTRIN(uap->addr), uap->len,
- prot));
+ prot, 0));
}
int
@@ -660,6 +678,86 @@ freebsd32_pselect(struct thread *td, struct freebsd32_pselect_args *uap)
return (error);
}
+static void
+freebsd32_kevent_to_kevent32(const struct kevent *kevp, struct kevent32 *ks32)
+{
+ uint64_t e;
+ int j;
+
+ CP(*kevp, *ks32, ident);
+ CP(*kevp, *ks32, filter);
+ CP(*kevp, *ks32, flags);
+ CP(*kevp, *ks32, fflags);
+#if BYTE_ORDER == LITTLE_ENDIAN
+ ks32->data1 = kevp->data;
+ ks32->data2 = kevp->data >> 32;
+#else
+ ks32->data1 = kevp->data >> 32;
+ ks32->data2 = kevp->data;
+#endif
+ PTROUT_CP(*kevp, *ks32, udata);
+ for (j = 0; j < nitems(kevp->ext); j++) {
+ e = kevp->ext[j];
+#if BYTE_ORDER == LITTLE_ENDIAN
+ ks32->ext64[2 * j] = e;
+ ks32->ext64[2 * j + 1] = e >> 32;
+#else
+ ks32->ext64[2 * j] = e >> 32;
+ ks32->ext64[2 * j + 1] = e;
+#endif
+ }
+}
+
+void
+freebsd32_kinfo_knote_to_32(const struct kinfo_knote *kin,
+ struct kinfo_knote32 *kin32)
+{
+ memset(kin32, 0, sizeof(*kin32));
+ CP(*kin, *kin32, knt_kq_fd);
+ freebsd32_kevent_to_kevent32(&kin->knt_event, &kin32->knt_event);
+ CP(*kin, *kin32, knt_status);
+ CP(*kin, *kin32, knt_extdata);
+ switch (kin->knt_extdata) {
+ case KNOTE_EXTDATA_NONE:
+ break;
+ case KNOTE_EXTDATA_VNODE:
+ CP(*kin, *kin32, knt_vnode.knt_vnode_type);
+#if BYTE_ORDER == LITTLE_ENDIAN
+ kin32->knt_vnode.knt_vnode_fsid[0] = kin->knt_vnode.
+ knt_vnode_fsid;
+ kin32->knt_vnode.knt_vnode_fsid[1] = kin->knt_vnode.
+ knt_vnode_fsid >> 32;
+ kin32->knt_vnode.knt_vnode_fileid[0] = kin->knt_vnode.
+ knt_vnode_fileid;
+ kin32->knt_vnode.knt_vnode_fileid[1] = kin->knt_vnode.
+ knt_vnode_fileid >> 32;
+#else
+ kin32->knt_vnode.knt_vnode_fsid[1] = kin->knt_vnode.
+ knt_vnode_fsid;
+ kin32->knt_vnode.knt_vnode_fsid[0] = kin->knt_vnode.
+ knt_vnode_fsid >> 32;
+ kin32->knt_vnode.knt_vnode_fileid[1] = kin->knt_vnode.
+ knt_vnode_fileid;
+ kin32->knt_vnode.knt_vnode_fileid[0] = kin->knt_vnode.
+ knt_vnode_fileid >> 32;
+#endif
+ memcpy(kin32->knt_vnode.knt_vnode_fullpath,
+ kin->knt_vnode.knt_vnode_fullpath, PATH_MAX);
+ break;
+ case KNOTE_EXTDATA_PIPE:
+#if BYTE_ORDER == LITTLE_ENDIAN
+ kin32->knt_pipe.knt_pipe_ino[0] = kin->knt_pipe.knt_pipe_ino;
+ kin32->knt_pipe.knt_pipe_ino[1] = kin->knt_pipe.
+ knt_pipe_ino >> 32;
+#else
+ kin32->knt_pipe.knt_pipe_ino[1] = kin->knt_pipe.knt_pipe_ino;
+ kin32->knt_pipe.knt_pipe_ino[0] = kin->knt_pipe.
+ knt_pipe_ino >> 32;
+#endif
+ break;
+ }
+}
+
/*
* Copy 'count' items into the destination list pointed to by uap->eventlist.
*/
@@ -668,36 +766,13 @@ freebsd32_kevent_copyout(void *arg, struct kevent *kevp, int count)
{
struct freebsd32_kevent_args *uap;
struct kevent32 ks32[KQ_NEVENTS];
- uint64_t e;
- int i, j, error;
+ int i, error;
KASSERT(count <= KQ_NEVENTS, ("count (%d) > KQ_NEVENTS", count));
uap = (struct freebsd32_kevent_args *)arg;
- for (i = 0; i < count; i++) {
- CP(kevp[i], ks32[i], ident);
- CP(kevp[i], ks32[i], filter);
- CP(kevp[i], ks32[i], flags);
- CP(kevp[i], ks32[i], fflags);
-#if BYTE_ORDER == LITTLE_ENDIAN
- ks32[i].data1 = kevp[i].data;
- ks32[i].data2 = kevp[i].data >> 32;
-#else
- ks32[i].data1 = kevp[i].data >> 32;
- ks32[i].data2 = kevp[i].data;
-#endif
- PTROUT_CP(kevp[i], ks32[i], udata);
- for (j = 0; j < nitems(kevp->ext); j++) {
- e = kevp[i].ext[j];
-#if BYTE_ORDER == LITTLE_ENDIAN
- ks32[i].ext64[2 * j] = e;
- ks32[i].ext64[2 * j + 1] = e >> 32;
-#else
- ks32[i].ext64[2 * j] = e >> 32;
- ks32[i].ext64[2 * j + 1] = e;
-#endif
- }
- }
+ for (i = 0; i < count; i++)
+ freebsd32_kevent_to_kevent32(&kevp[i], &ks32[i]);
error = copyout(ks32, uap->eventlist, count * sizeof *ks32);
if (error == 0)
uap->eventlist += count;
@@ -961,9 +1036,11 @@ freebsd32_ptrace(struct thread *td, struct freebsd32_ptrace_args *uap)
struct ptrace_lwpinfo pl;
struct ptrace_vm_entry pve;
struct ptrace_coredump pc;
+ struct ptrace_sc_remote sr;
struct dbreg32 dbreg;
struct fpreg32 fpreg;
struct reg32 reg;
+ struct iovec vec;
register_t args[nitems(td->td_sa.args)];
struct ptrace_sc_ret psr;
int ptevents;
@@ -973,11 +1050,19 @@ freebsd32_ptrace(struct thread *td, struct freebsd32_ptrace_args *uap)
struct ptrace_lwpinfo32 pl;
struct ptrace_vm_entry32 pve;
struct ptrace_coredump32 pc;
+ struct ptrace_sc_remote32 sr;
uint32_t args[nitems(td->td_sa.args)];
struct ptrace_sc_ret32 psr;
+ struct iovec32 vec;
} r32;
+ syscallarg_t pscr_args[nitems(td->td_sa.args)];
+ u_int pscr_args32[nitems(td->td_sa.args)];
void *addr;
- int data, error = 0, i;
+ int data, error, i;
+
+ if (!allow_ptrace)
+ return (ENOSYS);
+ error = 0;
AUDIT_ARG_PID(uap->pid);
AUDIT_ARG_CMD(uap->req);
@@ -999,7 +1084,7 @@ freebsd32_ptrace(struct thread *td, struct freebsd32_ptrace_args *uap)
*/
data = sizeof(r.pl);
if (uap->data < offsetof(struct ptrace_lwpinfo32, pl_siginfo) +
- sizeof(struct siginfo32))
+ sizeof(struct __siginfo32))
data = offsetof(struct ptrace_lwpinfo, pl_siginfo);
break;
case PT_GETREGS:
@@ -1020,6 +1105,15 @@ freebsd32_ptrace(struct thread *td, struct freebsd32_ptrace_args *uap)
case PT_SETDBREGS:
error = copyin(uap->addr, &r.dbreg, sizeof(r.dbreg));
break;
+ case PT_GETREGSET:
+ case PT_SETREGSET:
+ error = copyin(uap->addr, &r32.vec, sizeof(r32.vec));
+ if (error != 0)
+ break;
+
+ r.vec.iov_len = r32.vec.iov_len;
+ r.vec.iov_base = PTRIN(r32.vec.iov_base);
+ break;
case PT_SET_EVENT_MASK:
if (uap->data != sizeof(r.ptevents))
error = EINVAL;
@@ -1061,6 +1155,31 @@ freebsd32_ptrace(struct thread *td, struct freebsd32_ptrace_args *uap)
r.pc.pc_limit = PAIR32TO64(off_t, r32.pc.pc_limit);
data = sizeof(r.pc);
break;
+ case PT_SC_REMOTE:
+ if (uap->data != sizeof(r32.sr)) {
+ error = EINVAL;
+ break;
+ }
+ error = copyin(uap->addr, &r32.sr, uap->data);
+ if (error != 0)
+ break;
+ CP(r32.sr, r.sr, pscr_syscall);
+ CP(r32.sr, r.sr, pscr_nargs);
+ if (r.sr.pscr_nargs > nitems(td->td_sa.args)) {
+ error = EINVAL;
+ break;
+ }
+ error = copyin(PTRIN(r32.sr.pscr_args), pscr_args32,
+ sizeof(u_int) * r32.sr.pscr_nargs);
+ if (error != 0)
+ break;
+ for (i = 0; i < r32.sr.pscr_nargs; i++)
+ pscr_args[i] = pscr_args32[i];
+ r.sr.pscr_args = pscr_args;
+ break;
+ case PTINTERNAL_FIRST ... PTINTERNAL_LAST:
+ error = EINVAL;
+ break;
default:
addr = uap->addr;
break;
@@ -1098,6 +1217,10 @@ freebsd32_ptrace(struct thread *td, struct freebsd32_ptrace_args *uap)
case PT_GETDBREGS:
error = copyout(&r.dbreg, uap->addr, sizeof(r.dbreg));
break;
+ case PT_GETREGSET:
+ r32.vec.iov_len = r.vec.iov_len;
+ error = copyout(&r32.vec, uap->addr, sizeof(r32.vec));
+ break;
case PT_GET_EVENT_MASK:
/* NB: The size in uap->data is validated in kern_ptrace(). */
error = copyout(&r.ptevents, uap->addr, uap->data);
@@ -1117,43 +1240,46 @@ freebsd32_ptrace(struct thread *td, struct freebsd32_ptrace_args *uap)
error = copyout(&r32.psr, uap->addr, MIN(uap->data,
sizeof(r32.psr)));
break;
+ case PT_SC_REMOTE:
+ ptrace_sc_ret_to32(&r.sr.pscr_ret, &r32.sr.pscr_ret);
+ error = copyout(&r32.sr.pscr_ret, uap->addr +
+ offsetof(struct ptrace_sc_remote32, pscr_ret),
+ sizeof(r32.psr));
+ break;
}
return (error);
}
int
-freebsd32_copyinuio(struct iovec32 *iovp, u_int iovcnt, struct uio **uiop)
+freebsd32_copyinuio(const struct iovec32 *iovp, u_int iovcnt, struct uio **uiop)
{
struct iovec32 iov32;
struct iovec *iov;
struct uio *uio;
- u_int iovlen;
int error, i;
*uiop = NULL;
if (iovcnt > UIO_MAXIOV)
return (EINVAL);
- iovlen = iovcnt * sizeof(struct iovec);
- uio = malloc(iovlen + sizeof *uio, M_IOV, M_WAITOK);
- iov = (struct iovec *)(uio + 1);
+ uio = allocuio(iovcnt);
+ iov = uio->uio_iov;
for (i = 0; i < iovcnt; i++) {
error = copyin(&iovp[i], &iov32, sizeof(struct iovec32));
if (error) {
- free(uio, M_IOV);
+ freeuio(uio);
return (error);
}
iov[i].iov_base = PTRIN(iov32.iov_base);
iov[i].iov_len = iov32.iov_len;
}
- uio->uio_iov = iov;
uio->uio_iovcnt = iovcnt;
uio->uio_segflg = UIO_USERSPACE;
uio->uio_offset = -1;
uio->uio_resid = 0;
for (i = 0; i < iovcnt; i++) {
if (iov->iov_len > INT_MAX - uio->uio_resid) {
- free(uio, M_IOV);
+ freeuio(uio);
return (EINVAL);
}
uio->uio_resid += iov->iov_len;
@@ -1173,7 +1299,7 @@ freebsd32_readv(struct thread *td, struct freebsd32_readv_args *uap)
if (error)
return (error);
error = kern_readv(td, uap->fd, auio);
- free(auio, M_IOV);
+ freeuio(auio);
return (error);
}
@@ -1187,7 +1313,7 @@ freebsd32_writev(struct thread *td, struct freebsd32_writev_args *uap)
if (error)
return (error);
error = kern_writev(td, uap->fd, auio);
- free(auio, M_IOV);
+ freeuio(auio);
return (error);
}
@@ -1201,7 +1327,7 @@ freebsd32_preadv(struct thread *td, struct freebsd32_preadv_args *uap)
if (error)
return (error);
error = kern_preadv(td, uap->fd, auio, PAIR32TO64(off_t,uap->offset));
- free(auio, M_IOV);
+ freeuio(auio);
return (error);
}
@@ -1215,7 +1341,7 @@ freebsd32_pwritev(struct thread *td, struct freebsd32_pwritev_args *uap)
if (error)
return (error);
error = kern_pwritev(td, uap->fd, auio, PAIR32TO64(off_t,uap->offset));
- free(auio, M_IOV);
+ freeuio(auio);
return (error);
}
@@ -1282,11 +1408,7 @@ freebsd32_copyoutmsghdr(struct msghdr *msg, struct msghdr32 *msg32)
return (error);
}
-#ifndef __mips__
#define FREEBSD32_ALIGNBYTES (sizeof(int) - 1)
-#else
-#define FREEBSD32_ALIGNBYTES (sizeof(long) - 1)
-#endif
#define FREEBSD32_ALIGN(p) \
(((u_long)(p) + FREEBSD32_ALIGNBYTES) & ~FREEBSD32_ALIGNBYTES)
#define FREEBSD32_CMSG_SPACE(l) \
@@ -1506,6 +1628,7 @@ freebsd32_copyin_control(struct mbuf **mp, caddr_t buf, u_int buflen)
u_int msglen, outlen;
int error;
+ /* Enforce the size limit of the native implementation. */
if (buflen > MCLBYTES)
return (EINVAL);
@@ -1526,35 +1649,39 @@ freebsd32_copyin_control(struct mbuf **mp, caddr_t buf, u_int buflen)
break;
}
cm = (struct cmsghdr *)in1;
- if (cm->cmsg_len < FREEBSD32_ALIGN(sizeof(*cm))) {
+ if (cm->cmsg_len < FREEBSD32_ALIGN(sizeof(*cm)) ||
+ cm->cmsg_len > buflen) {
error = EINVAL;
break;
}
msglen = FREEBSD32_ALIGN(cm->cmsg_len);
- if (msglen > buflen || msglen < cm->cmsg_len) {
+ if (msglen < cm->cmsg_len) {
error = EINVAL;
break;
}
+ /* The native ABI permits the final padding to be omitted. */
+ if (msglen > buflen)
+ msglen = buflen;
buflen -= msglen;
in1 = (char *)in1 + msglen;
outlen += CMSG_ALIGN(sizeof(*cm)) +
CMSG_ALIGN(msglen - FREEBSD32_ALIGN(sizeof(*cm)));
}
- if (error == 0 && outlen > MCLBYTES) {
- /*
- * XXXMJ This implies that the upper limit on 32-bit aligned
- * control messages is less than MCLBYTES, and so we are not
- * perfectly compatible. However, there is no platform
- * guarantee that mbuf clusters larger than MCLBYTES can be
- * allocated.
- */
- error = EINVAL;
- }
if (error != 0)
goto out;
+ /*
+ * Allocate up to MJUMPAGESIZE space for the re-aligned and
+ * re-padded control messages. This allows a full MCLBYTES of
+ * 32-bit sized and aligned messages to fit and avoids an ABI
+ * mismatch with the native implementation.
+ */
m = m_get2(outlen, M_WAITOK, MT_CONTROL, 0);
+ if (m == NULL) {
+ error = EINVAL;
+ goto out;
+ }
m->m_len = outlen;
md = mtod(m, void *);
@@ -2126,13 +2253,13 @@ freebsd32_do_sendfile(struct thread *td,
fdrop(fp, td);
if (uap->sbytes != NULL)
- copyout(&sbytes, uap->sbytes, sizeof(off_t));
+ (void)copyout(&sbytes, uap->sbytes, sizeof(off_t));
out:
if (hdr_uio)
- free(hdr_uio, M_IOV);
+ freeuio(hdr_uio);
if (trl_uio)
- free(trl_uio, M_IOV);
+ freeuio(trl_uio);
return (error);
}
@@ -2157,6 +2284,17 @@ static void
copy_stat(struct stat *in, struct stat32 *out)
{
+#ifndef __amd64__
+ /*
+ * 32-bit architectures other than i386 have 64-bit time_t. This
+ * results in struct timespec32 with 12 bytes for tv_sec and tv_nsec,
+ * and 4 bytes of padding. Zero the padding holes in struct stat32.
+ */
+ bzero(&out->st_atim, sizeof(out->st_atim));
+ bzero(&out->st_mtim, sizeof(out->st_mtim));
+ bzero(&out->st_ctim, sizeof(out->st_ctim));
+ bzero(&out->st_birthtim, sizeof(out->st_birthtim));
+#endif
CP(*in, *out, st_dev);
CP(*in, *out, st_ino);
CP(*in, *out, st_mode);
@@ -2172,8 +2310,9 @@ copy_stat(struct stat *in, struct stat32 *out)
CP(*in, *out, st_blksize);
CP(*in, *out, st_flags);
CP(*in, *out, st_gen);
+ CP(*in, *out, st_filerev);
+ CP(*in, *out, st_bsdflags);
TS_CP(*in, *out, st_birthtim);
- out->st_padding0 = 0;
out->st_padding1 = 0;
#ifdef __STAT32_TIME_T_EXT
out->st_atim_ext = 0;
@@ -2216,8 +2355,7 @@ ofreebsd32_stat(struct thread *td, struct ofreebsd32_stat_args *uap)
struct ostat32 sb32;
int error;
- error = kern_statat(td, 0, AT_FDCWD, uap->path, UIO_USERSPACE,
- &sb, NULL);
+ error = kern_statat(td, 0, AT_FDCWD, uap->path, UIO_USERSPACE, &sb);
if (error)
return (error);
copy_ostat(&sb, &sb32);
@@ -2266,7 +2404,7 @@ freebsd32_fstatat(struct thread *td, struct freebsd32_fstatat_args *uap)
int error;
error = kern_statat(td, uap->flag, uap->fd, uap->path, UIO_USERSPACE,
- &ub, NULL);
+ &ub);
if (error)
return (error);
copy_stat(&ub, &ub32);
@@ -2283,7 +2421,7 @@ ofreebsd32_lstat(struct thread *td, struct ofreebsd32_lstat_args *uap)
int error;
error = kern_statat(td, AT_SYMLINK_NOFOLLOW, AT_FDCWD, uap->path,
- UIO_USERSPACE, &sb, NULL);
+ UIO_USERSPACE, &sb);
if (error)
return (error);
copy_ostat(&sb, &sb32);
@@ -2318,6 +2456,18 @@ static int
freebsd11_cvtstat32(struct stat *in, struct freebsd11_stat32 *out)
{
+#ifndef __amd64__
+ /*
+ * 32-bit architectures other than i386 have 64-bit time_t. This
+ * results in struct timespec32 with 12 bytes for tv_sec and tv_nsec,
+ * and 4 bytes of padding. Zero the padding holes in freebsd11_stat32.
+ */
+ bzero(&out->st_atim, sizeof(out->st_atim));
+ bzero(&out->st_mtim, sizeof(out->st_mtim));
+ bzero(&out->st_ctim, sizeof(out->st_ctim));
+ bzero(&out->st_birthtim, sizeof(out->st_birthtim));
+#endif
+
CP(*in, *out, st_ino);
if (in->st_ino != out->st_ino) {
switch (ino64_trunc_error) {
@@ -2389,8 +2539,7 @@ freebsd11_freebsd32_stat(struct thread *td,
struct freebsd11_stat32 sb32;
int error;
- error = kern_statat(td, 0, AT_FDCWD, uap->path, UIO_USERSPACE,
- &sb, NULL);
+ error = kern_statat(td, 0, AT_FDCWD, uap->path, UIO_USERSPACE, &sb);
if (error != 0)
return (error);
error = freebsd11_cvtstat32(&sb, &sb32);
@@ -2425,7 +2574,7 @@ freebsd11_freebsd32_fstatat(struct thread *td,
int error;
error = kern_statat(td, uap->flag, uap->fd, uap->path, UIO_USERSPACE,
- &sb, NULL);
+ &sb);
if (error != 0)
return (error);
error = freebsd11_cvtstat32(&sb, &sb32);
@@ -2443,7 +2592,7 @@ freebsd11_freebsd32_lstat(struct thread *td,
int error;
error = kern_statat(td, AT_SYMLINK_NOFOLLOW, AT_FDCWD, uap->path,
- UIO_USERSPACE, &sb, NULL);
+ UIO_USERSPACE, &sb);
if (error != 0)
return (error);
error = freebsd11_cvtstat32(&sb, &sb32);
@@ -2515,8 +2664,7 @@ freebsd11_freebsd32_nstat(struct thread *td,
struct nstat32 nsb;
int error;
- error = kern_statat(td, 0, AT_FDCWD, uap->path, UIO_USERSPACE,
- &sb, NULL);
+ error = kern_statat(td, 0, AT_FDCWD, uap->path, UIO_USERSPACE, &sb);
if (error != 0)
return (error);
error = freebsd11_cvtnstat32(&sb, &nsb);
@@ -2534,7 +2682,7 @@ freebsd11_freebsd32_nlstat(struct thread *td,
int error;
error = kern_statat(td, AT_SYMLINK_NOFOLLOW, AT_FDCWD, uap->path,
- UIO_USERSPACE, &sb, NULL);
+ UIO_USERSPACE, &sb);
if (error != 0)
return (error);
error = freebsd11_cvtnstat32(&sb, &nsb);
@@ -2586,9 +2734,9 @@ freebsd32___sysctl(struct thread *td, struct freebsd32___sysctl_args *uap)
uap->new, uap->newlen, &j, SCTL_MASK32);
if (error)
return (error);
- if (uap->oldlenp)
- suword32(uap->oldlenp, j);
- return (0);
+ if (uap->oldlenp != NULL && suword32(uap->oldlenp, j) != 0)
+ error = EFAULT;
+ return (error);
}
int
@@ -2611,9 +2759,8 @@ freebsd32___sysctlbyname(struct thread *td,
&oldlen, uap->new, uap->newlen, &rv, SCTL_MASK32, 1);
if (error != 0)
return (error);
- if (uap->oldlenp != NULL)
- error = suword32(uap->oldlenp, rv);
-
+ if (uap->oldlenp != NULL && suword32(uap->oldlenp, rv) != 0)
+ error = EFAULT;
return (error);
}
@@ -2692,7 +2839,7 @@ freebsd32_jail_set(struct thread *td, struct freebsd32_jail_set_args *uap)
if (error)
return (error);
error = kern_jail_set(td, auio, uap->flags);
- free(auio, M_IOV);
+ freeuio(auio);
return (error);
}
@@ -2719,7 +2866,7 @@ freebsd32_jail_get(struct thread *td, struct freebsd32_jail_get_args *uap)
if (error != 0)
break;
}
- free(auio, M_IOV);
+ freeuio(auio);
return (error);
}
@@ -2782,7 +2929,7 @@ freebsd4_freebsd32_sigaction(struct thread *td,
#ifdef COMPAT_43
struct osigaction32 {
- u_int32_t sa_u;
+ uint32_t sa_u;
osigset_t sa_mask;
int sa_flags;
};
@@ -2821,7 +2968,7 @@ ofreebsd32_sigaction(struct thread *td,
}
struct sigvec32 {
- u_int32_t sv_handler;
+ uint32_t sv_handler;
int sv_mask;
int sv_flags;
};
@@ -2861,7 +3008,7 @@ ofreebsd32_sigvec(struct thread *td,
}
struct sigstack32 {
- u_int32_t ss_sp;
+ uint32_t ss_sp;
int ss_onstack;
};
@@ -3064,6 +3211,60 @@ freebsd32_ktimer_gettime(struct thread *td,
}
int
+freebsd32_timerfd_gettime(struct thread *td,
+ struct freebsd32_timerfd_gettime_args *uap)
+{
+ struct itimerspec curr_value;
+ struct itimerspec32 curr_value32;
+ int error;
+
+ error = kern_timerfd_gettime(td, uap->fd, &curr_value);
+ if (error == 0) {
+ CP(curr_value, curr_value32, it_value.tv_sec);
+ CP(curr_value, curr_value32, it_value.tv_nsec);
+ CP(curr_value, curr_value32, it_interval.tv_sec);
+ CP(curr_value, curr_value32, it_interval.tv_nsec);
+ error = copyout(&curr_value32, uap->curr_value,
+ sizeof(curr_value32));
+ }
+
+ return (error);
+}
+
+int
+freebsd32_timerfd_settime(struct thread *td,
+ struct freebsd32_timerfd_settime_args *uap)
+{
+ struct itimerspec new_value, old_value;
+ struct itimerspec32 new_value32, old_value32;
+ int error;
+
+ error = copyin(uap->new_value, &new_value32, sizeof(new_value32));
+ if (error != 0)
+ return (error);
+ CP(new_value32, new_value, it_value.tv_sec);
+ CP(new_value32, new_value, it_value.tv_nsec);
+ CP(new_value32, new_value, it_interval.tv_sec);
+ CP(new_value32, new_value, it_interval.tv_nsec);
+ if (uap->old_value == NULL) {
+ error = kern_timerfd_settime(td, uap->fd, uap->flags,
+ &new_value, NULL);
+ } else {
+ error = kern_timerfd_settime(td, uap->fd, uap->flags,
+ &new_value, &old_value);
+ if (error == 0) {
+ CP(old_value, old_value32, it_value.tv_sec);
+ CP(old_value, old_value32, it_value.tv_nsec);
+ CP(old_value, old_value32, it_interval.tv_sec);
+ CP(old_value, old_value32, it_interval.tv_nsec);
+ error = copyout(&old_value32, uap->old_value,
+ sizeof(old_value32));
+ }
+ }
+ return (error);
+}
+
+int
freebsd32_clock_getcpuclockid2(struct thread *td,
struct freebsd32_clock_getcpuclockid2_args *uap)
{
@@ -3132,7 +3333,7 @@ freebsd32_thr_suspend(struct thread *td, struct freebsd32_thr_suspend_args *uap)
}
void
-siginfo_to_siginfo32(const siginfo_t *src, struct siginfo32 *dst)
+siginfo_to_siginfo32(const siginfo_t *src, struct __siginfo32 *dst)
{
bzero(dst, sizeof(*dst));
dst->si_signo = src->si_signo;
@@ -3181,7 +3382,7 @@ freebsd32_sigtimedwait(struct thread *td, struct freebsd32_sigtimedwait_args *ua
struct timespec *timeout;
sigset_t set;
ksiginfo_t ksi;
- struct siginfo32 si32;
+ struct __siginfo32 si32;
int error;
if (uap->timeout) {
@@ -3204,7 +3405,7 @@ freebsd32_sigtimedwait(struct thread *td, struct freebsd32_sigtimedwait_args *ua
if (uap->info) {
siginfo_to_siginfo32(&ksi.ksi_info, &si32);
- error = copyout(&si32, uap->info, sizeof(struct siginfo32));
+ error = copyout(&si32, uap->info, sizeof(struct __siginfo32));
}
if (error == 0)
@@ -3219,7 +3420,7 @@ int
freebsd32_sigwaitinfo(struct thread *td, struct freebsd32_sigwaitinfo_args *uap)
{
ksiginfo_t ksi;
- struct siginfo32 si32;
+ struct __siginfo32 si32;
sigset_t set;
int error;
@@ -3233,7 +3434,7 @@ freebsd32_sigwaitinfo(struct thread *td, struct freebsd32_sigwaitinfo_args *uap)
if (uap->info) {
siginfo_to_siginfo32(&ksi.ksi_info, &si32);
- error = copyout(&si32, uap->info, sizeof(struct siginfo32));
+ error = copyout(&si32, uap->info, sizeof(struct __siginfo32));
}
if (error == 0)
td->td_retval[0] = ksi.ksi_signo;
@@ -3258,13 +3459,72 @@ freebsd32_cpuset_getid(struct thread *td,
PAIR32TO64(id_t, uap->id), uap->setid));
}
+static int
+copyin32_set(const void *u, void *k, size_t size)
+{
+#if __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__
+ int rv;
+ struct bitset *kb = k;
+ int *p;
+
+ rv = copyin(u, k, size);
+ if (rv != 0)
+ return (rv);
+
+ p = (int *)kb->__bits;
+ /* Loop through swapping words.
+ * `size' is in bytes, we need bits. */
+ for (int i = 0; i < __bitset_words(size * 8); i++) {
+ int tmp = p[0];
+ p[0] = p[1];
+ p[1] = tmp;
+ p += 2;
+ }
+ return (0);
+#else
+ return (copyin(u, k, size));
+#endif
+}
+
+static int
+copyout32_set(const void *k, void *u, size_t size)
+{
+#if __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__
+ const struct bitset *kb = k;
+ struct bitset *ub = u;
+ const int *kp = (const int *)kb->__bits;
+ int *up = (int *)ub->__bits;
+ int rv;
+
+ for (int i = 0; i < __bitset_words(CPU_SETSIZE); i++) {
+ /* `size' is in bytes, we need bits. */
+ for (int i = 0; i < __bitset_words(size * 8); i++) {
+ rv = suword32(up, kp[1]);
+ if (rv == 0)
+ rv = suword32(up + 1, kp[0]);
+ if (rv != 0)
+ return (EFAULT);
+ }
+ }
+ return (0);
+#else
+ return (copyout(k, u, size));
+#endif
+}
+
+static const struct cpuset_copy_cb cpuset_copy32_cb = {
+ .cpuset_copyin = copyin32_set,
+ .cpuset_copyout = copyout32_set
+};
+
int
freebsd32_cpuset_getaffinity(struct thread *td,
struct freebsd32_cpuset_getaffinity_args *uap)
{
- return (kern_cpuset_getaffinity(td, uap->level, uap->which,
- PAIR32TO64(id_t,uap->id), uap->cpusetsize, uap->mask));
+ return (user_cpuset_getaffinity(td, uap->level, uap->which,
+ PAIR32TO64(id_t,uap->id), uap->cpusetsize, uap->mask,
+ &cpuset_copy32_cb));
}
int
@@ -3272,8 +3532,9 @@ freebsd32_cpuset_setaffinity(struct thread *td,
struct freebsd32_cpuset_setaffinity_args *uap)
{
- return (kern_cpuset_setaffinity(td, uap->level, uap->which,
- PAIR32TO64(id_t,uap->id), uap->cpusetsize, uap->mask));
+ return (user_cpuset_setaffinity(td, uap->level, uap->which,
+ PAIR32TO64(id_t,uap->id), uap->cpusetsize, uap->mask,
+ &cpuset_copy32_cb));
}
int
@@ -3282,7 +3543,8 @@ freebsd32_cpuset_getdomain(struct thread *td,
{
return (kern_cpuset_getdomain(td, uap->level, uap->which,
- PAIR32TO64(id_t,uap->id), uap->domainsetsize, uap->mask, uap->policy));
+ PAIR32TO64(id_t,uap->id), uap->domainsetsize, uap->mask, uap->policy,
+ &cpuset_copy32_cb));
}
int
@@ -3291,7 +3553,8 @@ freebsd32_cpuset_setdomain(struct thread *td,
{
return (kern_cpuset_setdomain(td, uap->level, uap->which,
- PAIR32TO64(id_t,uap->id), uap->domainsetsize, uap->mask, uap->policy));
+ PAIR32TO64(id_t,uap->id), uap->domainsetsize, uap->mask, uap->policy,
+ &cpuset_copy32_cb));
}
int
@@ -3336,7 +3599,7 @@ freebsd32_nmount(struct thread *td,
return (error);
error = vfs_donmount(td, flags, auio);
- free(auio, M_IOV);
+ freeuio(auio);
return error;
}
@@ -3391,8 +3654,9 @@ syscall32_helper_unregister(struct syscall_helper_data *sd)
int
freebsd32_copyout_strings(struct image_params *imgp, uintptr_t *stack_base)
{
+ struct sysentvec *sysent;
int argc, envc, i;
- u_int32_t *vectp;
+ uint32_t *vectp;
char *stringp;
uintptr_t destp, ustringp;
struct freebsd32_ps_strings *arginfo;
@@ -3401,30 +3665,20 @@ freebsd32_copyout_strings(struct image_params *imgp, uintptr_t *stack_base)
size_t execpath_len;
int error, szsigcode;
- /*
- * Calculate string base and vector table pointers.
- * Also deal with signal trampoline code for this exec type.
- */
- if (imgp->execpath != NULL && imgp->auxargs != NULL)
- execpath_len = strlen(imgp->execpath) + 1;
- else
- execpath_len = 0;
- arginfo = (struct freebsd32_ps_strings *)curproc->p_sysent->
- sv_psstrings;
+ sysent = imgp->sysent;
+
+ arginfo = (struct freebsd32_ps_strings *)PROC_PS_STRINGS(imgp->proc);
imgp->ps_strings = arginfo;
- if (imgp->proc->p_sysent->sv_sigcode_base == 0)
- szsigcode = *(imgp->proc->p_sysent->sv_szsigcode);
- else
- szsigcode = 0;
destp = (uintptr_t)arginfo;
/*
- * install sigcode
+ * Install sigcode.
*/
- if (szsigcode != 0) {
+ if (!PROC_HAS_SHP(imgp->proc)) {
+ szsigcode = *sysent->sv_szsigcode;
destp -= szsigcode;
destp = rounddown2(destp, sizeof(uint32_t));
- error = copyout(imgp->proc->p_sysent->sv_sigcode, (void *)destp,
+ error = copyout(sysent->sv_sigcode, (void *)destp,
szsigcode);
if (error != 0)
return (error);
@@ -3433,7 +3687,8 @@ freebsd32_copyout_strings(struct image_params *imgp, uintptr_t *stack_base)
/*
* Copy the image path for the rtld.
*/
- if (execpath_len != 0) {
+ if (imgp->execpath != NULL && imgp->auxargs != NULL) {
+ execpath_len = strlen(imgp->execpath) + 1;
destp -= execpath_len;
imgp->execpathp = (void *)destp;
error = copyout(imgp->execpath, imgp->execpathp, execpath_len);
@@ -3472,8 +3727,6 @@ freebsd32_copyout_strings(struct image_params *imgp, uintptr_t *stack_base)
destp = rounddown2(destp, sizeof(uint32_t));
ustringp = destp;
- exec_stackgap(imgp, &destp);
-
if (imgp->auxargs) {
/*
* Allocate room on the stack for the ELF auxargs
@@ -3511,7 +3764,7 @@ freebsd32_copyout_strings(struct image_params *imgp, uintptr_t *stack_base)
* Fill in "ps_strings" struct for ps, w, etc.
*/
imgp->argv = vectp;
- if (suword32(&arginfo->ps_argvstr, (u_int32_t)(intptr_t)vectp) != 0 ||
+ if (suword32(&arginfo->ps_argvstr, (uint32_t)(intptr_t)vectp) != 0 ||
suword32(&arginfo->ps_nargvstr, argc) != 0)
return (EFAULT);
@@ -3531,7 +3784,7 @@ freebsd32_copyout_strings(struct image_params *imgp, uintptr_t *stack_base)
return (EFAULT);
imgp->envv = vectp;
- if (suword32(&arginfo->ps_envstr, (u_int32_t)(intptr_t)vectp) != 0 ||
+ if (suword32(&arginfo->ps_envstr, (uint32_t)(intptr_t)vectp) != 0 ||
suword32(&arginfo->ps_nenvstr, envc) != 0)
return (EFAULT);
@@ -3669,6 +3922,7 @@ freebsd32_procctl(struct thread *td, struct freebsd32_procctl_args *uap)
case PROC_TRAPCAP_CTL:
case PROC_NO_NEW_PRIVS_CTL:
case PROC_WXMAP_CTL:
+ case PROC_LOGSIGEXIT_CTL:
error = copyin(PTRIN(uap->data), &flags, sizeof(flags));
if (error != 0)
return (error);
@@ -3704,6 +3958,7 @@ freebsd32_procctl(struct thread *td, struct freebsd32_procctl_args *uap)
case PROC_TRAPCAP_STATUS:
case PROC_NO_NEW_PRIVS_STATUS:
case PROC_WXMAP_STATUS:
+ case PROC_LOGSIGEXIT_STATUS:
data = &flags;
break;
case PROC_PDEATHSIG_CTL:
@@ -3737,6 +3992,7 @@ freebsd32_procctl(struct thread *td, struct freebsd32_procctl_args *uap)
case PROC_TRAPCAP_STATUS:
case PROC_NO_NEW_PRIVS_STATUS:
case PROC_WXMAP_STATUS:
+ case PROC_LOGSIGEXIT_STATUS:
if (error == 0)
error = copyout(&flags, uap->data, sizeof(flags));
break;
@@ -3751,7 +4007,7 @@ freebsd32_procctl(struct thread *td, struct freebsd32_procctl_args *uap)
int
freebsd32_fcntl(struct thread *td, struct freebsd32_fcntl_args *uap)
{
- long tmp;
+ intptr_t tmp;
switch (uap->cmd) {
/*
@@ -3767,6 +4023,7 @@ freebsd32_fcntl(struct thread *td, struct freebsd32_fcntl_args *uap)
case F_OGETLK:
case F_OSETLK:
case F_OSETLKW:
+ case F_KINFO:
tmp = (unsigned int)(uap->arg);
break;
default:
@@ -3979,3 +4236,10 @@ ofreebsd32_sethostid(struct thread *td, struct ofreebsd32_sethostid_args *uap)
sizeof(hostid), NULL, 0));
}
#endif
+
+int
+freebsd32_setcred(struct thread *td, struct freebsd32_setcred_args *uap)
+{
+ /* Last argument is 'is_32bit'. */
+ return (user_setcred(td, uap->flags, uap->wcred, uap->size, true));
+}
diff --git a/sys/compat/freebsd32/freebsd32_misc.h b/sys/compat/freebsd32/freebsd32_misc.h
index f6f85adc8e72..b39b714183fb 100644
--- a/sys/compat/freebsd32/freebsd32_misc.h
+++ b/sys/compat/freebsd32/freebsd32_misc.h
@@ -1,5 +1,5 @@
/*-
- * SPDX-License-Identifier: BSD-2-Clause-FreeBSD
+ * SPDX-License-Identifier: BSD-2-Clause
*
* Copyright (c) 2013 The FreeBSD Foundation
*
@@ -26,8 +26,6 @@
* 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.
- *
- * $FreeBSD$
*/
#ifndef _COMPAT_FREEBSD32_MISC_H_
diff --git a/sys/compat/freebsd32/freebsd32_proto.h b/sys/compat/freebsd32/freebsd32_proto.h
index ce583e9ac78d..5c0efc64f8a7 100644
--- a/sys/compat/freebsd32/freebsd32_proto.h
+++ b/sys/compat/freebsd32/freebsd32_proto.h
@@ -2,14 +2,13 @@
* System call prototypes.
*
* DO NOT EDIT-- this file is automatically @generated.
- * $FreeBSD$
*/
#ifndef _FREEBSD32_SYSPROTO_H_
#define _FREEBSD32_SYSPROTO_H_
+#include <sys/types.h>
#include <sys/signal.h>
-#include <sys/acl.h>
#include <sys/cpuset.h>
#include <sys/domainset.h>
#include <sys/_ffcounter.h>
@@ -23,8 +22,8 @@ struct proc;
struct thread;
-#define PAD_(t) (sizeof(register_t) <= sizeof(t) ? \
- 0 : sizeof(register_t) - sizeof(t))
+#define PAD_(t) (sizeof(syscallarg_t) <= sizeof(t) ? \
+ 0 : sizeof(syscallarg_t) - sizeof(t))
#if BYTE_ORDER == LITTLE_ENDIAN
#define PADL_(t) 0
@@ -90,7 +89,7 @@ struct freebsd32_getitimer_args {
struct freebsd32_fcntl_args {
char fd_l_[PADL_(int)]; int fd; char fd_r_[PADR_(int)];
char cmd_l_[PADL_(int)]; int cmd; char cmd_r_[PADR_(int)];
- char arg_l_[PADL_(int32_t)]; int32_t arg; char arg_r_[PADR_(int32_t)];
+ char arg_l_[PADL_(intptr_t)]; intptr_t arg; char arg_r_[PADR_(intptr_t)];
};
struct freebsd32_select_args {
char nd_l_[PADL_(int)]; int nd; char nd_r_[PADR_(int)];
@@ -109,12 +108,12 @@ struct freebsd32_getrusage_args {
};
struct freebsd32_readv_args {
char fd_l_[PADL_(int)]; int fd; char fd_r_[PADR_(int)];
- char iovp_l_[PADL_(struct iovec32 *)]; struct iovec32 * iovp; char iovp_r_[PADR_(struct iovec32 *)];
+ char iovp_l_[PADL_(const struct iovec32 *)]; const struct iovec32 * iovp; char iovp_r_[PADR_(const struct iovec32 *)];
char iovcnt_l_[PADL_(u_int)]; u_int iovcnt; char iovcnt_r_[PADR_(u_int)];
};
struct freebsd32_writev_args {
char fd_l_[PADL_(int)]; int fd; char fd_r_[PADR_(int)];
- char iovp_l_[PADL_(struct iovec32 *)]; struct iovec32 * iovp; char iovp_r_[PADR_(struct iovec32 *)];
+ char iovp_l_[PADL_(const struct iovec32 *)]; const struct iovec32 * iovp; char iovp_r_[PADR_(const struct iovec32 *)];
char iovcnt_l_[PADL_(u_int)]; u_int iovcnt; char iovcnt_r_[PADR_(u_int)];
};
struct freebsd32_settimeofday_args {
@@ -158,7 +157,7 @@ struct freebsd32_ntp_adjtime_args {
char tp_l_[PADL_(struct timex32 *)]; struct timex32 * tp; char tp_r_[PADR_(struct timex32 *)];
};
struct freebsd32___sysctl_args {
- char name_l_[PADL_(int *)]; int * name; char name_r_[PADR_(int *)];
+ char name_l_[PADL_(const int *)]; const int * name; char name_r_[PADR_(const int *)];
char namelen_l_[PADL_(u_int)]; u_int namelen; char namelen_r_[PADR_(u_int)];
char old_l_[PADL_(void *)]; void * old; char old_r_[PADR_(void *)];
char oldlenp_l_[PADL_(uint32_t *)]; uint32_t * oldlenp; char oldlenp_r_[PADR_(uint32_t *)];
@@ -295,12 +294,12 @@ struct freebsd32_jail_args {
};
struct freebsd32_sigtimedwait_args {
char set_l_[PADL_(const sigset_t *)]; const sigset_t * set; char set_r_[PADR_(const sigset_t *)];
- char info_l_[PADL_(struct siginfo32 *)]; struct siginfo32 * info; char info_r_[PADR_(struct siginfo32 *)];
+ char info_l_[PADL_(struct __siginfo32 *)]; struct __siginfo32 * info; char info_r_[PADR_(struct __siginfo32 *)];
char timeout_l_[PADL_(const struct timespec32 *)]; const struct timespec32 * timeout; char timeout_r_[PADR_(const struct timespec32 *)];
};
struct freebsd32_sigwaitinfo_args {
char set_l_[PADL_(const sigset_t *)]; const sigset_t * set; char set_r_[PADR_(const sigset_t *)];
- char info_l_[PADL_(struct siginfo32 *)]; struct siginfo32 * info; char info_r_[PADR_(struct siginfo32 *)];
+ char info_l_[PADL_(struct __siginfo32 *)]; struct __siginfo32 * info; char info_r_[PADR_(struct __siginfo32 *)];
};
struct freebsd32_aio_waitcomplete_args {
char aiocbp_l_[PADL_(uint32_t *)]; uint32_t * aiocbp; char aiocbp_r_[PADR_(uint32_t *)];
@@ -575,7 +574,7 @@ struct freebsd32_wait6_args {
char status_l_[PADL_(int *)]; int * status; char status_r_[PADR_(int *)];
char options_l_[PADL_(int)]; int options; char options_r_[PADR_(int)];
char wrusage_l_[PADL_(struct __wrusage32 *)]; struct __wrusage32 * wrusage; char wrusage_r_[PADR_(struct __wrusage32 *)];
- char info_l_[PADL_(struct siginfo32 *)]; struct siginfo32 * info; char info_r_[PADR_(struct siginfo32 *)];
+ char info_l_[PADL_(struct __siginfo32 *)]; struct __siginfo32 * info; char info_r_[PADR_(struct __siginfo32 *)];
};
struct freebsd32_cap_ioctls_limit_args {
char fd_l_[PADL_(int)]; int fd; char fd_r_[PADR_(int)];
@@ -685,6 +684,21 @@ struct freebsd32_aio_writev_args {
struct freebsd32_aio_readv_args {
char aiocbp_l_[PADL_(struct aiocb32 *)]; struct aiocb32 * aiocbp; char aiocbp_r_[PADR_(struct aiocb32 *)];
};
+struct freebsd32_timerfd_gettime_args {
+ char fd_l_[PADL_(int)]; int fd; char fd_r_[PADR_(int)];
+ char curr_value_l_[PADL_(struct itimerspec32 *)]; struct itimerspec32 * curr_value; char curr_value_r_[PADR_(struct itimerspec32 *)];
+};
+struct freebsd32_timerfd_settime_args {
+ char fd_l_[PADL_(int)]; int fd; char fd_r_[PADR_(int)];
+ char flags_l_[PADL_(int)]; int flags; char flags_r_[PADR_(int)];
+ char new_value_l_[PADL_(const struct itimerspec32 *)]; const struct itimerspec32 * new_value; char new_value_r_[PADR_(const struct itimerspec32 *)];
+ char old_value_l_[PADL_(struct itimerspec32 *)]; struct itimerspec32 * old_value; char old_value_r_[PADR_(struct itimerspec32 *)];
+};
+struct freebsd32_setcred_args {
+ char flags_l_[PADL_(u_int)]; u_int flags; char flags_r_[PADR_(u_int)];
+ char wcred_l_[PADL_(const struct setcred32 *)]; const struct setcred32 * wcred; char wcred_r_[PADR_(const struct setcred32 *)];
+ char size_l_[PADL_(size_t)]; size_t size; char size_r_[PADR_(size_t)];
+};
int freebsd32_wait4(struct thread *, struct freebsd32_wait4_args *);
int freebsd32_ptrace(struct thread *, struct freebsd32_ptrace_args *);
int freebsd32_recvmsg(struct thread *, struct freebsd32_recvmsg_args *);
@@ -800,6 +814,9 @@ int freebsd32_cpuset_setdomain(struct thread *, struct freebsd32_cpuset_setdomai
int freebsd32___sysctlbyname(struct thread *, struct freebsd32___sysctlbyname_args *);
int freebsd32_aio_writev(struct thread *, struct freebsd32_aio_writev_args *);
int freebsd32_aio_readv(struct thread *, struct freebsd32_aio_readv_args *);
+int freebsd32_timerfd_gettime(struct thread *, struct freebsd32_timerfd_gettime_args *);
+int freebsd32_timerfd_settime(struct thread *, struct freebsd32_timerfd_settime_args *);
+int freebsd32_setcred(struct thread *, struct freebsd32_setcred_args *);
#ifdef COMPAT_43
@@ -1125,6 +1142,18 @@ int freebsd11_freebsd32_fstatat(struct thread *, struct freebsd11_freebsd32_fsta
#endif /* COMPAT_FREEBSD12 */
+
+#ifdef COMPAT_FREEBSD13
+
+
+#endif /* COMPAT_FREEBSD13 */
+
+
+#ifdef COMPAT_FREEBSD14
+
+
+#endif /* COMPAT_FREEBSD14 */
+
#define FREEBSD32_SYS_AUE_freebsd32_wait4 AUE_WAIT4
#define FREEBSD32_SYS_AUE_freebsd4_freebsd32_getfsstat AUE_GETFSSTAT
#define FREEBSD32_SYS_AUE_ofreebsd32_lseek AUE_LSEEK
@@ -1287,6 +1316,9 @@ int freebsd11_freebsd32_fstatat(struct thread *, struct freebsd11_freebsd32_fsta
#define FREEBSD32_SYS_AUE_freebsd32___sysctlbyname AUE_SYSCTL
#define FREEBSD32_SYS_AUE_freebsd32_aio_writev AUE_AIO_WRITEV
#define FREEBSD32_SYS_AUE_freebsd32_aio_readv AUE_AIO_READV
+#define FREEBSD32_SYS_AUE_freebsd32_timerfd_gettime AUE_TIMERFD
+#define FREEBSD32_SYS_AUE_freebsd32_timerfd_settime AUE_TIMERFD
+#define FREEBSD32_SYS_AUE_freebsd32_setcred AUE_SETCRED
#undef PAD_
#undef PADL_
diff --git a/sys/compat/freebsd32/freebsd32_signal.h b/sys/compat/freebsd32/freebsd32_signal.h
index cc7aeb858fb1..379387dc3a8b 100644
--- a/sys/compat/freebsd32/freebsd32_signal.h
+++ b/sys/compat/freebsd32/freebsd32_signal.h
@@ -1,5 +1,5 @@
/*-
- * SPDX-License-Identifier: BSD-2-Clause-FreeBSD
+ * SPDX-License-Identifier: BSD-2-Clause
*
* Copyright (c) 2006 David Xu <davidxu@freebsd.org>
* All rights reserved.
@@ -24,16 +24,14 @@
* 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.
- *
- * $FreeBSD$
*/
#ifndef _COMPAT_FREEBSD32_SIGNAL_H_
#define _COMPAT_FREEBSD32_SIGNAL_H_
struct sigaltstack32 {
- u_int32_t ss_sp; /* signal stack base */
- u_int32_t ss_size; /* signal stack length */
+ uint32_t ss_sp; /* signal stack base */
+ uint32_t ss_size; /* signal stack length */
int ss_flags; /* SS_DISABLE and/or SS_ONSTACK */
};
@@ -63,6 +61,6 @@ struct sigevent32 {
struct sigevent;
int convert_sigevent32(struct sigevent32 *sig32, struct sigevent *sig);
-void siginfo_to_siginfo32(const siginfo_t *src, struct siginfo32 *dst);
+void siginfo_to_siginfo32(const siginfo_t *src, struct __siginfo32 *dst);
#endif /* !_COMPAT_FREEBSD32_SIGNAL_H_ */
diff --git a/sys/compat/freebsd32/freebsd32_syscall.h b/sys/compat/freebsd32/freebsd32_syscall.h
index a79331c931f9..54063150eef9 100644
--- a/sys/compat/freebsd32/freebsd32_syscall.h
+++ b/sys/compat/freebsd32/freebsd32_syscall.h
@@ -2,11 +2,10 @@
* System call numbers.
*
* DO NOT EDIT-- this file is automatically @generated.
- * $FreeBSD$
*/
#define FREEBSD32_SYS_syscall 0
-#define FREEBSD32_SYS_exit 1
+#define FREEBSD32_SYS__exit 1
#define FREEBSD32_SYS_fork 2
#define FREEBSD32_SYS_read 3
#define FREEBSD32_SYS_write 4
@@ -68,14 +67,14 @@
#define FREEBSD32_SYS_umask 60
#define FREEBSD32_SYS_chroot 61
/* 62 is old freebsd32_fstat */
- /* 63 is obsolete ogetkerninfo */
+ /* 63 is obsolete getkerninfo */
/* 64 is old getpagesize */
#define FREEBSD32_SYS_msync 65
#define FREEBSD32_SYS_vfork 66
/* 67 is obsolete vread */
/* 68 is obsolete vwrite */
-#define FREEBSD32_SYS_sbrk 69
-#define FREEBSD32_SYS_sstk 70
+ /* 69 is obsolete sbrk */
+ /* 70 is obsolete sstk */
/* 71 is old freebsd32_mmap */
#define FREEBSD32_SYS_freebsd11_vadvise 72
#define FREEBSD32_SYS_munmap 73
@@ -84,8 +83,8 @@
/* 76 is obsolete vhangup */
/* 77 is obsolete vlimit */
#define FREEBSD32_SYS_mincore 78
-#define FREEBSD32_SYS_getgroups 79
-#define FREEBSD32_SYS_setgroups 80
+#define FREEBSD32_SYS_freebsd14_getgroups 79
+#define FREEBSD32_SYS_freebsd14_setgroups 80
#define FREEBSD32_SYS_getpgrp 81
#define FREEBSD32_SYS_setpgid 82
#define FREEBSD32_SYS_freebsd32_setitimer 83
@@ -141,7 +140,7 @@
#define FREEBSD32_SYS_mkdir 136
#define FREEBSD32_SYS_rmdir 137
#define FREEBSD32_SYS_freebsd32_utimes 138
- /* 139 is obsolete 4.2 sigreturn */
+ /* 139 is obsolete freebsd32_sigreturn */
#define FREEBSD32_SYS_freebsd32_adjtime 140
/* 141 is old getpeername */
/* 142 is old gethostid */
@@ -327,6 +326,7 @@
#define FREEBSD32_SYS_lchflags 391
#define FREEBSD32_SYS_uuidgen 392
#define FREEBSD32_SYS_freebsd32_sendfile 393
+#define FREEBSD32_SYS_mac_syscall 394
#define FREEBSD32_SYS_freebsd11_freebsd32_getfsstat 395
#define FREEBSD32_SYS_freebsd11_statfs 396
#define FREEBSD32_SYS_freebsd11_fstatfs 397
@@ -348,7 +348,7 @@
#define FREEBSD32_SYS_freebsd32_getcontext 421
#define FREEBSD32_SYS_freebsd32_setcontext 422
#define FREEBSD32_SYS_freebsd32_swapcontext 423
-#define FREEBSD32_SYS_swapoff 424
+#define FREEBSD32_SYS_freebsd13_swapoff 424
#define FREEBSD32_SYS___acl_get_link 425
#define FREEBSD32_SYS___acl_set_link 426
#define FREEBSD32_SYS___acl_delete_link 427
@@ -424,7 +424,7 @@
#define FREEBSD32_SYS_symlinkat 502
#define FREEBSD32_SYS_unlinkat 503
#define FREEBSD32_SYS_posix_openpt 504
-#define FREEBSD32_SYS_gssd_syscall 505
+ /* 505 is obsolete kgssapi */
#define FREEBSD32_SYS_freebsd32_jail_get 506
#define FREEBSD32_SYS_freebsd32_jail_set 507
#define FREEBSD32_SYS_jail_remove 508
@@ -500,4 +500,21 @@
#define FREEBSD32_SYS_freebsd32_aio_readv 579
#define FREEBSD32_SYS_fspacectl 580
#define FREEBSD32_SYS_sched_getcpu 581
-#define FREEBSD32_SYS_MAXSYSCALL 582
+#define FREEBSD32_SYS_swapoff 582
+#define FREEBSD32_SYS_kqueuex 583
+#define FREEBSD32_SYS_membarrier 584
+#define FREEBSD32_SYS_timerfd_create 585
+#define FREEBSD32_SYS_freebsd32_timerfd_gettime 586
+#define FREEBSD32_SYS_freebsd32_timerfd_settime 587
+#define FREEBSD32_SYS_kcmp 588
+#define FREEBSD32_SYS_getrlimitusage 589
+#define FREEBSD32_SYS_fchroot 590
+#define FREEBSD32_SYS_freebsd32_setcred 591
+#define FREEBSD32_SYS_exterrctl 592
+#define FREEBSD32_SYS_inotify_add_watch_at 593
+#define FREEBSD32_SYS_inotify_rm_watch 594
+#define FREEBSD32_SYS_getgroups 595
+#define FREEBSD32_SYS_setgroups 596
+#define FREEBSD32_SYS_jail_attach_jd 597
+#define FREEBSD32_SYS_jail_remove_jd 598
+#define FREEBSD32_SYS_MAXSYSCALL 599
diff --git a/sys/compat/freebsd32/freebsd32_syscalls.c b/sys/compat/freebsd32/freebsd32_syscalls.c
index 1f949cd90b19..f7cc4c284e4d 100644
--- a/sys/compat/freebsd32/freebsd32_syscalls.c
+++ b/sys/compat/freebsd32/freebsd32_syscalls.c
@@ -2,12 +2,11 @@
* System call names.
*
* DO NOT EDIT-- this file is automatically @generated.
- * $FreeBSD$
*/
const char *freebsd32_syscallnames[] = {
"syscall", /* 0 = syscall */
- "exit", /* 1 = exit */
+ "_exit", /* 1 = _exit */
"fork", /* 2 = fork */
"read", /* 3 = read */
"write", /* 4 = write */
@@ -69,14 +68,14 @@ const char *freebsd32_syscallnames[] = {
"umask", /* 60 = umask */
"chroot", /* 61 = chroot */
"compat.freebsd32_fstat", /* 62 = old freebsd32_fstat */
- "obs_getkerninfo", /* 63 = obsolete ogetkerninfo */
+ "obs_getkerninfo", /* 63 = obsolete getkerninfo */
"compat.getpagesize", /* 64 = old getpagesize */
"msync", /* 65 = msync */
"vfork", /* 66 = vfork */
"obs_vread", /* 67 = obsolete vread */
"obs_vwrite", /* 68 = obsolete vwrite */
- "sbrk", /* 69 = sbrk */
- "sstk", /* 70 = sstk */
+ "obs_sbrk", /* 69 = obsolete sbrk */
+ "obs_sstk", /* 70 = obsolete sstk */
"compat.freebsd32_mmap", /* 71 = old freebsd32_mmap */
"compat11.vadvise", /* 72 = freebsd11 vadvise */
"munmap", /* 73 = munmap */
@@ -85,8 +84,8 @@ const char *freebsd32_syscallnames[] = {
"obs_vhangup", /* 76 = obsolete vhangup */
"obs_vlimit", /* 77 = obsolete vlimit */
"mincore", /* 78 = mincore */
- "getgroups", /* 79 = getgroups */
- "setgroups", /* 80 = setgroups */
+ "compat14.getgroups", /* 79 = freebsd14 getgroups */
+ "compat14.setgroups", /* 80 = freebsd14 setgroups */
"getpgrp", /* 81 = getpgrp */
"setpgid", /* 82 = setpgid */
"freebsd32_setitimer", /* 83 = freebsd32_setitimer */
@@ -145,7 +144,7 @@ const char *freebsd32_syscallnames[] = {
"mkdir", /* 136 = mkdir */
"rmdir", /* 137 = rmdir */
"freebsd32_utimes", /* 138 = freebsd32_utimes */
- "obs_4.2", /* 139 = obsolete 4.2 sigreturn */
+ "obs_freebsd32_sigreturn", /* 139 = obsolete freebsd32_sigreturn */
"freebsd32_adjtime", /* 140 = freebsd32_adjtime */
"compat.getpeername", /* 141 = old getpeername */
"compat.gethostid", /* 142 = old gethostid */
@@ -400,7 +399,7 @@ const char *freebsd32_syscallnames[] = {
"lchflags", /* 391 = lchflags */
"uuidgen", /* 392 = uuidgen */
"freebsd32_sendfile", /* 393 = freebsd32_sendfile */
- "#394", /* 394 = mac_syscall */
+ "mac_syscall", /* 394 = mac_syscall */
"compat11.freebsd32_getfsstat", /* 395 = freebsd11 freebsd32_getfsstat */
"compat11.statfs", /* 396 = freebsd11 statfs */
"compat11.fstatfs", /* 397 = freebsd11 fstatfs */
@@ -430,7 +429,7 @@ const char *freebsd32_syscallnames[] = {
"freebsd32_getcontext", /* 421 = freebsd32_getcontext */
"freebsd32_setcontext", /* 422 = freebsd32_setcontext */
"freebsd32_swapcontext", /* 423 = freebsd32_swapcontext */
- "swapoff", /* 424 = swapoff */
+ "compat13.swapoff", /* 424 = freebsd13 swapoff */
"__acl_get_link", /* 425 = __acl_get_link */
"__acl_set_link", /* 426 = __acl_set_link */
"__acl_delete_link", /* 427 = __acl_delete_link */
@@ -511,7 +510,7 @@ const char *freebsd32_syscallnames[] = {
"symlinkat", /* 502 = symlinkat */
"unlinkat", /* 503 = unlinkat */
"posix_openpt", /* 504 = posix_openpt */
- "gssd_syscall", /* 505 = gssd_syscall */
+ "obs_kgssapi", /* 505 = obsolete kgssapi */
"freebsd32_jail_get", /* 506 = freebsd32_jail_get */
"freebsd32_jail_set", /* 507 = freebsd32_jail_set */
"jail_remove", /* 508 = jail_remove */
@@ -588,4 +587,21 @@ const char *freebsd32_syscallnames[] = {
"freebsd32_aio_readv", /* 579 = freebsd32_aio_readv */
"fspacectl", /* 580 = fspacectl */
"sched_getcpu", /* 581 = sched_getcpu */
+ "swapoff", /* 582 = swapoff */
+ "kqueuex", /* 583 = kqueuex */
+ "membarrier", /* 584 = membarrier */
+ "timerfd_create", /* 585 = timerfd_create */
+ "freebsd32_timerfd_gettime", /* 586 = freebsd32_timerfd_gettime */
+ "freebsd32_timerfd_settime", /* 587 = freebsd32_timerfd_settime */
+ "kcmp", /* 588 = kcmp */
+ "getrlimitusage", /* 589 = getrlimitusage */
+ "fchroot", /* 590 = fchroot */
+ "freebsd32_setcred", /* 591 = freebsd32_setcred */
+ "exterrctl", /* 592 = exterrctl */
+ "inotify_add_watch_at", /* 593 = inotify_add_watch_at */
+ "inotify_rm_watch", /* 594 = inotify_rm_watch */
+ "getgroups", /* 595 = getgroups */
+ "setgroups", /* 596 = setgroups */
+ "jail_attach_jd", /* 597 = jail_attach_jd */
+ "jail_remove_jd", /* 598 = jail_remove_jd */
};
diff --git a/sys/compat/freebsd32/freebsd32_sysent.c b/sys/compat/freebsd32/freebsd32_sysent.c
index 29dd2892da05..18f809ef04e3 100644
--- a/sys/compat/freebsd32/freebsd32_sysent.c
+++ b/sys/compat/freebsd32/freebsd32_sysent.c
@@ -2,7 +2,6 @@
* System call switch table.
*
* DO NOT EDIT-- this file is automatically @generated.
- * $FreeBSD$
*/
#include <sys/param.h>
@@ -10,7 +9,7 @@
#include <sys/sysproto.h>
#include <compat/freebsd32/freebsd32_proto.h>
-#define AS(name) (sizeof(struct name) / sizeof(register_t))
+#define AS(name) (sizeof(struct name) / sizeof(syscallarg_t))
#ifdef COMPAT_43
#define compat(n, name) .sy_narg = n, .sy_call = (sy_call_t *)__CONCAT(o, name)
@@ -54,20 +53,32 @@
#define compat12(n, name) .sy_narg = 0, .sy_call = (sy_call_t *)nosys
#endif
+#ifdef COMPAT_FREEBSD13
+#define compat13(n, name) .sy_narg = n, .sy_call = (sy_call_t *)__CONCAT(freebsd13_, name)
+#else
+#define compat13(n, name) .sy_narg = 0, .sy_call = (sy_call_t *)nosys
+#endif
+
+#ifdef COMPAT_FREEBSD14
+#define compat14(n, name) .sy_narg = n, .sy_call = (sy_call_t *)__CONCAT(freebsd14_, name)
+#else
+#define compat14(n, name) .sy_narg = 0, .sy_call = (sy_call_t *)nosys
+#endif
+
/* The casts are bogus but will do for now. */
struct sysent freebsd32_sysent[] = {
- { .sy_narg = 0, .sy_call = (sy_call_t *)nosys, .sy_auevent = AUE_NULL, .sy_flags = 0, .sy_thrcnt = SY_THR_STATIC }, /* 0 = syscall */
- { .sy_narg = AS(exit_args), .sy_call = (sy_call_t *)sys_exit, .sy_auevent = AUE_EXIT, .sy_flags = SYF_CAPENABLED, .sy_thrcnt = SY_THR_STATIC }, /* 1 = exit */
+ { .sy_narg = 0, .sy_call = (sy_call_t *)nosys, .sy_auevent = AUE_NULL, .sy_flags = 0, .sy_thrcnt = SY_THR_STATIC }, /* 0 = syscall */
+ { .sy_narg = AS(_exit_args), .sy_call = (sy_call_t *)sys__exit, .sy_auevent = AUE_EXIT, .sy_flags = SYF_CAPENABLED, .sy_thrcnt = SY_THR_STATIC }, /* 1 = _exit */
{ .sy_narg = 0, .sy_call = (sy_call_t *)sys_fork, .sy_auevent = AUE_FORK, .sy_flags = SYF_CAPENABLED, .sy_thrcnt = SY_THR_STATIC }, /* 2 = fork */
{ .sy_narg = AS(read_args), .sy_call = (sy_call_t *)sys_read, .sy_auevent = AUE_READ, .sy_flags = SYF_CAPENABLED, .sy_thrcnt = SY_THR_STATIC }, /* 3 = read */
{ .sy_narg = AS(write_args), .sy_call = (sy_call_t *)sys_write, .sy_auevent = AUE_WRITE, .sy_flags = SYF_CAPENABLED, .sy_thrcnt = SY_THR_STATIC }, /* 4 = write */
{ .sy_narg = AS(open_args), .sy_call = (sy_call_t *)sys_open, .sy_auevent = AUE_OPEN_RWTC, .sy_flags = 0, .sy_thrcnt = SY_THR_STATIC }, /* 5 = open */
{ .sy_narg = AS(close_args), .sy_call = (sy_call_t *)sys_close, .sy_auevent = AUE_CLOSE, .sy_flags = SYF_CAPENABLED, .sy_thrcnt = SY_THR_STATIC }, /* 6 = close */
- { .sy_narg = AS(freebsd32_wait4_args), .sy_call = (sy_call_t *)freebsd32_wait4, .sy_auevent = AUE_WAIT4, .sy_flags = 0, .sy_thrcnt = SY_THR_STATIC }, /* 7 = freebsd32_wait4 */
+ { .sy_narg = AS(freebsd32_wait4_args), .sy_call = (sy_call_t *)freebsd32_wait4, .sy_auevent = AUE_WAIT4, .sy_flags = SYF_CAPENABLED, .sy_thrcnt = SY_THR_STATIC }, /* 7 = freebsd32_wait4 */
{ compat(AS(ocreat_args),creat), .sy_auevent = AUE_CREAT, .sy_flags = 0, .sy_thrcnt = SY_THR_STATIC }, /* 8 = old creat */
{ .sy_narg = AS(link_args), .sy_call = (sy_call_t *)sys_link, .sy_auevent = AUE_LINK, .sy_flags = 0, .sy_thrcnt = SY_THR_STATIC }, /* 9 = link */
{ .sy_narg = AS(unlink_args), .sy_call = (sy_call_t *)sys_unlink, .sy_auevent = AUE_UNLINK, .sy_flags = 0, .sy_thrcnt = SY_THR_STATIC }, /* 10 = unlink */
- { .sy_narg = 0, .sy_call = (sy_call_t *)nosys, .sy_auevent = AUE_NULL, .sy_flags = 0, .sy_thrcnt = SY_THR_ABSENT }, /* 11 = obsolete execv */
+ { .sy_narg = 0, .sy_call = (sy_call_t *)nosys, .sy_auevent = AUE_NULL, .sy_flags = 0, .sy_thrcnt = SY_THR_ABSENT }, /* 11 = obsolete execv */
{ .sy_narg = AS(chdir_args), .sy_call = (sy_call_t *)sys_chdir, .sy_auevent = AUE_CHDIR, .sy_flags = 0, .sy_thrcnt = SY_THR_STATIC }, /* 12 = chdir */
{ .sy_narg = AS(fchdir_args), .sy_call = (sy_call_t *)sys_fchdir, .sy_auevent = AUE_FCHDIR, .sy_flags = 0, .sy_thrcnt = SY_THR_STATIC }, /* 13 = fchdir */
{ compat11(AS(freebsd11_mknod_args),mknod), .sy_auevent = AUE_MKNOD, .sy_flags = 0, .sy_thrcnt = SY_THR_STATIC }, /* 14 = freebsd11 mknod */
@@ -119,38 +130,38 @@ struct sysent freebsd32_sysent[] = {
{ .sy_narg = AS(umask_args), .sy_call = (sy_call_t *)sys_umask, .sy_auevent = AUE_UMASK, .sy_flags = SYF_CAPENABLED, .sy_thrcnt = SY_THR_STATIC }, /* 60 = umask */
{ .sy_narg = AS(chroot_args), .sy_call = (sy_call_t *)sys_chroot, .sy_auevent = AUE_CHROOT, .sy_flags = 0, .sy_thrcnt = SY_THR_STATIC }, /* 61 = chroot */
{ compat(AS(ofreebsd32_fstat_args),freebsd32_fstat), .sy_auevent = AUE_FSTAT, .sy_flags = SYF_CAPENABLED, .sy_thrcnt = SY_THR_STATIC }, /* 62 = old freebsd32_fstat */
- { .sy_narg = 0, .sy_call = (sy_call_t *)nosys, .sy_auevent = AUE_NULL, .sy_flags = 0, .sy_thrcnt = SY_THR_ABSENT }, /* 63 = obsolete ogetkerninfo */
+ { .sy_narg = 0, .sy_call = (sy_call_t *)nosys, .sy_auevent = AUE_NULL, .sy_flags = 0, .sy_thrcnt = SY_THR_ABSENT }, /* 63 = obsolete getkerninfo */
{ compat(0,getpagesize), .sy_auevent = AUE_NULL, .sy_flags = SYF_CAPENABLED, .sy_thrcnt = SY_THR_STATIC }, /* 64 = old getpagesize */
{ .sy_narg = AS(msync_args), .sy_call = (sy_call_t *)sys_msync, .sy_auevent = AUE_MSYNC, .sy_flags = SYF_CAPENABLED, .sy_thrcnt = SY_THR_STATIC }, /* 65 = msync */
- { .sy_narg = 0, .sy_call = (sy_call_t *)sys_vfork, .sy_auevent = AUE_VFORK, .sy_flags = 0, .sy_thrcnt = SY_THR_STATIC }, /* 66 = vfork */
- { .sy_narg = 0, .sy_call = (sy_call_t *)nosys, .sy_auevent = AUE_NULL, .sy_flags = 0, .sy_thrcnt = SY_THR_ABSENT }, /* 67 = obsolete vread */
- { .sy_narg = 0, .sy_call = (sy_call_t *)nosys, .sy_auevent = AUE_NULL, .sy_flags = 0, .sy_thrcnt = SY_THR_ABSENT }, /* 68 = obsolete vwrite */
- { .sy_narg = AS(sbrk_args), .sy_call = (sy_call_t *)sys_sbrk, .sy_auevent = AUE_SBRK, .sy_flags = SYF_CAPENABLED, .sy_thrcnt = SY_THR_STATIC }, /* 69 = sbrk */
- { .sy_narg = AS(sstk_args), .sy_call = (sy_call_t *)sys_sstk, .sy_auevent = AUE_SSTK, .sy_flags = SYF_CAPENABLED, .sy_thrcnt = SY_THR_STATIC }, /* 70 = sstk */
+ { .sy_narg = 0, .sy_call = (sy_call_t *)sys_vfork, .sy_auevent = AUE_VFORK, .sy_flags = SYF_CAPENABLED, .sy_thrcnt = SY_THR_STATIC }, /* 66 = vfork */
+ { .sy_narg = 0, .sy_call = (sy_call_t *)nosys, .sy_auevent = AUE_NULL, .sy_flags = 0, .sy_thrcnt = SY_THR_ABSENT }, /* 67 = obsolete vread */
+ { .sy_narg = 0, .sy_call = (sy_call_t *)nosys, .sy_auevent = AUE_NULL, .sy_flags = 0, .sy_thrcnt = SY_THR_ABSENT }, /* 68 = obsolete vwrite */
+ { .sy_narg = 0, .sy_call = (sy_call_t *)nosys, .sy_auevent = AUE_NULL, .sy_flags = 0, .sy_thrcnt = SY_THR_ABSENT }, /* 69 = obsolete sbrk */
+ { .sy_narg = 0, .sy_call = (sy_call_t *)nosys, .sy_auevent = AUE_NULL, .sy_flags = 0, .sy_thrcnt = SY_THR_ABSENT }, /* 70 = obsolete sstk */
{ compat(AS(ofreebsd32_mmap_args),freebsd32_mmap), .sy_auevent = AUE_MMAP, .sy_flags = SYF_CAPENABLED, .sy_thrcnt = SY_THR_STATIC }, /* 71 = old freebsd32_mmap */
{ compat11(AS(freebsd11_vadvise_args),vadvise), .sy_auevent = AUE_O_VADVISE, .sy_flags = 0, .sy_thrcnt = SY_THR_STATIC }, /* 72 = freebsd11 vadvise */
{ .sy_narg = AS(munmap_args), .sy_call = (sy_call_t *)sys_munmap, .sy_auevent = AUE_MUNMAP, .sy_flags = SYF_CAPENABLED, .sy_thrcnt = SY_THR_STATIC }, /* 73 = munmap */
{ .sy_narg = AS(freebsd32_mprotect_args), .sy_call = (sy_call_t *)freebsd32_mprotect, .sy_auevent = AUE_MPROTECT, .sy_flags = SYF_CAPENABLED, .sy_thrcnt = SY_THR_STATIC }, /* 74 = freebsd32_mprotect */
{ .sy_narg = AS(madvise_args), .sy_call = (sy_call_t *)sys_madvise, .sy_auevent = AUE_MADVISE, .sy_flags = SYF_CAPENABLED, .sy_thrcnt = SY_THR_STATIC }, /* 75 = madvise */
- { .sy_narg = 0, .sy_call = (sy_call_t *)nosys, .sy_auevent = AUE_NULL, .sy_flags = 0, .sy_thrcnt = SY_THR_ABSENT }, /* 76 = obsolete vhangup */
- { .sy_narg = 0, .sy_call = (sy_call_t *)nosys, .sy_auevent = AUE_NULL, .sy_flags = 0, .sy_thrcnt = SY_THR_ABSENT }, /* 77 = obsolete vlimit */
+ { .sy_narg = 0, .sy_call = (sy_call_t *)nosys, .sy_auevent = AUE_NULL, .sy_flags = 0, .sy_thrcnt = SY_THR_ABSENT }, /* 76 = obsolete vhangup */
+ { .sy_narg = 0, .sy_call = (sy_call_t *)nosys, .sy_auevent = AUE_NULL, .sy_flags = 0, .sy_thrcnt = SY_THR_ABSENT }, /* 77 = obsolete vlimit */
{ .sy_narg = AS(mincore_args), .sy_call = (sy_call_t *)sys_mincore, .sy_auevent = AUE_MINCORE, .sy_flags = SYF_CAPENABLED, .sy_thrcnt = SY_THR_STATIC }, /* 78 = mincore */
- { .sy_narg = AS(getgroups_args), .sy_call = (sy_call_t *)sys_getgroups, .sy_auevent = AUE_GETGROUPS, .sy_flags = SYF_CAPENABLED, .sy_thrcnt = SY_THR_STATIC }, /* 79 = getgroups */
- { .sy_narg = AS(setgroups_args), .sy_call = (sy_call_t *)sys_setgroups, .sy_auevent = AUE_SETGROUPS, .sy_flags = 0, .sy_thrcnt = SY_THR_STATIC }, /* 80 = setgroups */
+ { compat14(AS(freebsd14_getgroups_args),getgroups), .sy_auevent = AUE_GETGROUPS, .sy_flags = SYF_CAPENABLED, .sy_thrcnt = SY_THR_STATIC }, /* 79 = freebsd14 getgroups */
+ { compat14(AS(freebsd14_setgroups_args),setgroups), .sy_auevent = AUE_SETGROUPS, .sy_flags = 0, .sy_thrcnt = SY_THR_STATIC }, /* 80 = freebsd14 setgroups */
{ .sy_narg = 0, .sy_call = (sy_call_t *)sys_getpgrp, .sy_auevent = AUE_GETPGRP, .sy_flags = SYF_CAPENABLED, .sy_thrcnt = SY_THR_STATIC }, /* 81 = getpgrp */
{ .sy_narg = AS(setpgid_args), .sy_call = (sy_call_t *)sys_setpgid, .sy_auevent = AUE_SETPGRP, .sy_flags = 0, .sy_thrcnt = SY_THR_STATIC }, /* 82 = setpgid */
{ .sy_narg = AS(freebsd32_setitimer_args), .sy_call = (sy_call_t *)freebsd32_setitimer, .sy_auevent = AUE_SETITIMER, .sy_flags = SYF_CAPENABLED, .sy_thrcnt = SY_THR_STATIC }, /* 83 = freebsd32_setitimer */
- { compat(0,wait), .sy_auevent = AUE_WAIT4, .sy_flags = 0, .sy_thrcnt = SY_THR_STATIC }, /* 84 = old wait */
+ { compat(0,wait), .sy_auevent = AUE_WAIT4, .sy_flags = 0, .sy_thrcnt = SY_THR_STATIC }, /* 84 = old wait */
{ .sy_narg = AS(swapon_args), .sy_call = (sy_call_t *)sys_swapon, .sy_auevent = AUE_SWAPON, .sy_flags = 0, .sy_thrcnt = SY_THR_STATIC }, /* 85 = swapon */
{ .sy_narg = AS(freebsd32_getitimer_args), .sy_call = (sy_call_t *)freebsd32_getitimer, .sy_auevent = AUE_GETITIMER, .sy_flags = SYF_CAPENABLED, .sy_thrcnt = SY_THR_STATIC }, /* 86 = freebsd32_getitimer */
{ compat(AS(ogethostname_args),gethostname), .sy_auevent = AUE_SYSCTL, .sy_flags = SYF_CAPENABLED, .sy_thrcnt = SY_THR_STATIC }, /* 87 = old gethostname */
{ compat(AS(osethostname_args),sethostname), .sy_auevent = AUE_SYSCTL, .sy_flags = 0, .sy_thrcnt = SY_THR_STATIC }, /* 88 = old sethostname */
{ .sy_narg = 0, .sy_call = (sy_call_t *)sys_getdtablesize, .sy_auevent = AUE_GETDTABLESIZE, .sy_flags = SYF_CAPENABLED, .sy_thrcnt = SY_THR_STATIC }, /* 89 = getdtablesize */
{ .sy_narg = AS(dup2_args), .sy_call = (sy_call_t *)sys_dup2, .sy_auevent = AUE_DUP2, .sy_flags = SYF_CAPENABLED, .sy_thrcnt = SY_THR_STATIC }, /* 90 = dup2 */
- { .sy_narg = 0, .sy_call = (sy_call_t *)nosys, .sy_auevent = AUE_NULL, .sy_flags = 0, .sy_thrcnt = SY_THR_ABSENT }, /* 91 = reserved for local use */
+ { .sy_narg = 0, .sy_call = (sy_call_t *)nosys, .sy_auevent = AUE_NULL, .sy_flags = 0, .sy_thrcnt = SY_THR_ABSENT }, /* 91 = reserved for local use */
{ .sy_narg = AS(freebsd32_fcntl_args), .sy_call = (sy_call_t *)freebsd32_fcntl, .sy_auevent = AUE_FCNTL, .sy_flags = SYF_CAPENABLED, .sy_thrcnt = SY_THR_STATIC }, /* 92 = freebsd32_fcntl */
{ .sy_narg = AS(freebsd32_select_args), .sy_call = (sy_call_t *)freebsd32_select, .sy_auevent = AUE_SELECT, .sy_flags = SYF_CAPENABLED, .sy_thrcnt = SY_THR_STATIC }, /* 93 = freebsd32_select */
- { .sy_narg = 0, .sy_call = (sy_call_t *)nosys, .sy_auevent = AUE_NULL, .sy_flags = 0, .sy_thrcnt = SY_THR_ABSENT }, /* 94 = reserved for local use */
+ { .sy_narg = 0, .sy_call = (sy_call_t *)nosys, .sy_auevent = AUE_NULL, .sy_flags = 0, .sy_thrcnt = SY_THR_ABSENT }, /* 94 = reserved for local use */
{ .sy_narg = AS(fsync_args), .sy_call = (sy_call_t *)sys_fsync, .sy_auevent = AUE_FSYNC, .sy_flags = SYF_CAPENABLED, .sy_thrcnt = SY_THR_STATIC }, /* 95 = fsync */
{ .sy_narg = AS(setpriority_args), .sy_call = (sy_call_t *)sys_setpriority, .sy_auevent = AUE_SETPRIORITY, .sy_flags = SYF_CAPENABLED, .sy_thrcnt = SY_THR_STATIC }, /* 96 = setpriority */
{ .sy_narg = AS(socket_args), .sy_call = (sy_call_t *)sys_socket, .sy_auevent = AUE_SOCKET, .sy_flags = SYF_CAPENABLED, .sy_thrcnt = SY_THR_STATIC }, /* 97 = socket */
@@ -163,7 +174,7 @@ struct sysent freebsd32_sysent[] = {
{ .sy_narg = AS(bind_args), .sy_call = (sy_call_t *)sys_bind, .sy_auevent = AUE_BIND, .sy_flags = 0, .sy_thrcnt = SY_THR_STATIC }, /* 104 = bind */
{ .sy_narg = AS(setsockopt_args), .sy_call = (sy_call_t *)sys_setsockopt, .sy_auevent = AUE_SETSOCKOPT, .sy_flags = SYF_CAPENABLED, .sy_thrcnt = SY_THR_STATIC }, /* 105 = setsockopt */
{ .sy_narg = AS(listen_args), .sy_call = (sy_call_t *)sys_listen, .sy_auevent = AUE_LISTEN, .sy_flags = SYF_CAPENABLED, .sy_thrcnt = SY_THR_STATIC }, /* 106 = listen */
- { .sy_narg = 0, .sy_call = (sy_call_t *)nosys, .sy_auevent = AUE_NULL, .sy_flags = 0, .sy_thrcnt = SY_THR_ABSENT }, /* 107 = obsolete vtimes */
+ { .sy_narg = 0, .sy_call = (sy_call_t *)nosys, .sy_auevent = AUE_NULL, .sy_flags = 0, .sy_thrcnt = SY_THR_ABSENT }, /* 107 = obsolete vtimes */
{ compat(AS(ofreebsd32_sigvec_args),freebsd32_sigvec), .sy_auevent = AUE_NULL, .sy_flags = SYF_CAPENABLED, .sy_thrcnt = SY_THR_STATIC }, /* 108 = old freebsd32_sigvec */
{ compat(AS(osigblock_args),sigblock), .sy_auevent = AUE_NULL, .sy_flags = SYF_CAPENABLED, .sy_thrcnt = SY_THR_STATIC }, /* 109 = old sigblock */
{ compat(AS(osigsetmask_args),sigsetmask), .sy_auevent = AUE_NULL, .sy_flags = SYF_CAPENABLED, .sy_thrcnt = SY_THR_STATIC }, /* 110 = old sigsetmask */
@@ -171,11 +182,11 @@ struct sysent freebsd32_sysent[] = {
{ compat(AS(ofreebsd32_sigstack_args),freebsd32_sigstack), .sy_auevent = AUE_NULL, .sy_flags = SYF_CAPENABLED, .sy_thrcnt = SY_THR_STATIC }, /* 112 = old freebsd32_sigstack */
{ compat(AS(ofreebsd32_recvmsg_args),freebsd32_recvmsg), .sy_auevent = AUE_RECVMSG, .sy_flags = SYF_CAPENABLED, .sy_thrcnt = SY_THR_STATIC }, /* 113 = old freebsd32_recvmsg */
{ compat(AS(ofreebsd32_sendmsg_args),freebsd32_sendmsg), .sy_auevent = AUE_SENDMSG, .sy_flags = SYF_CAPENABLED, .sy_thrcnt = SY_THR_STATIC }, /* 114 = old freebsd32_sendmsg */
- { .sy_narg = 0, .sy_call = (sy_call_t *)nosys, .sy_auevent = AUE_NULL, .sy_flags = 0, .sy_thrcnt = SY_THR_ABSENT }, /* 115 = obsolete vtrace */
+ { .sy_narg = 0, .sy_call = (sy_call_t *)nosys, .sy_auevent = AUE_NULL, .sy_flags = 0, .sy_thrcnt = SY_THR_ABSENT }, /* 115 = obsolete vtrace */
{ .sy_narg = AS(freebsd32_gettimeofday_args), .sy_call = (sy_call_t *)freebsd32_gettimeofday, .sy_auevent = AUE_GETTIMEOFDAY, .sy_flags = SYF_CAPENABLED, .sy_thrcnt = SY_THR_STATIC }, /* 116 = freebsd32_gettimeofday */
{ .sy_narg = AS(freebsd32_getrusage_args), .sy_call = (sy_call_t *)freebsd32_getrusage, .sy_auevent = AUE_GETRUSAGE, .sy_flags = SYF_CAPENABLED, .sy_thrcnt = SY_THR_STATIC }, /* 117 = freebsd32_getrusage */
{ .sy_narg = AS(getsockopt_args), .sy_call = (sy_call_t *)sys_getsockopt, .sy_auevent = AUE_GETSOCKOPT, .sy_flags = SYF_CAPENABLED, .sy_thrcnt = SY_THR_STATIC }, /* 118 = getsockopt */
- { .sy_narg = 0, .sy_call = (sy_call_t *)nosys, .sy_auevent = AUE_NULL, .sy_flags = 0, .sy_thrcnt = SY_THR_ABSENT }, /* 119 = reserved for local use */
+ { .sy_narg = 0, .sy_call = (sy_call_t *)nosys, .sy_auevent = AUE_NULL, .sy_flags = 0, .sy_thrcnt = SY_THR_ABSENT }, /* 119 = reserved for local use */
{ .sy_narg = AS(freebsd32_readv_args), .sy_call = (sy_call_t *)freebsd32_readv, .sy_auevent = AUE_READV, .sy_flags = SYF_CAPENABLED, .sy_thrcnt = SY_THR_STATIC }, /* 120 = freebsd32_readv */
{ .sy_narg = AS(freebsd32_writev_args), .sy_call = (sy_call_t *)freebsd32_writev, .sy_auevent = AUE_WRITEV, .sy_flags = SYF_CAPENABLED, .sy_thrcnt = SY_THR_STATIC }, /* 121 = freebsd32_writev */
{ .sy_narg = AS(freebsd32_settimeofday_args), .sy_call = (sy_call_t *)freebsd32_settimeofday, .sy_auevent = AUE_SETTIMEOFDAY, .sy_flags = 0, .sy_thrcnt = SY_THR_STATIC }, /* 122 = freebsd32_settimeofday */
@@ -195,7 +206,7 @@ struct sysent freebsd32_sysent[] = {
{ .sy_narg = AS(mkdir_args), .sy_call = (sy_call_t *)sys_mkdir, .sy_auevent = AUE_MKDIR, .sy_flags = 0, .sy_thrcnt = SY_THR_STATIC }, /* 136 = mkdir */
{ .sy_narg = AS(rmdir_args), .sy_call = (sy_call_t *)sys_rmdir, .sy_auevent = AUE_RMDIR, .sy_flags = 0, .sy_thrcnt = SY_THR_STATIC }, /* 137 = rmdir */
{ .sy_narg = AS(freebsd32_utimes_args), .sy_call = (sy_call_t *)freebsd32_utimes, .sy_auevent = AUE_UTIMES, .sy_flags = 0, .sy_thrcnt = SY_THR_STATIC }, /* 138 = freebsd32_utimes */
- { .sy_narg = 0, .sy_call = (sy_call_t *)nosys, .sy_auevent = AUE_NULL, .sy_flags = 0, .sy_thrcnt = SY_THR_ABSENT }, /* 139 = obsolete 4.2 sigreturn */
+ { .sy_narg = 0, .sy_call = (sy_call_t *)nosys, .sy_auevent = AUE_NULL, .sy_flags = 0, .sy_thrcnt = SY_THR_ABSENT }, /* 139 = obsolete freebsd32_sigreturn */
{ .sy_narg = AS(freebsd32_adjtime_args), .sy_call = (sy_call_t *)freebsd32_adjtime, .sy_auevent = AUE_ADJTIME, .sy_flags = 0, .sy_thrcnt = SY_THR_STATIC }, /* 140 = freebsd32_adjtime */
{ compat(AS(ogetpeername_args),getpeername), .sy_auevent = AUE_GETPEERNAME, .sy_flags = SYF_CAPENABLED, .sy_thrcnt = SY_THR_STATIC }, /* 141 = old getpeername */
{ compat(0,gethostid), .sy_auevent = AUE_SYSCTL, .sy_flags = SYF_CAPENABLED, .sy_thrcnt = SY_THR_STATIC }, /* 142 = old gethostid */
@@ -205,56 +216,56 @@ struct sysent freebsd32_sysent[] = {
{ compat(AS(okillpg_args),killpg), .sy_auevent = AUE_KILLPG, .sy_flags = 0, .sy_thrcnt = SY_THR_STATIC }, /* 146 = old killpg */
{ .sy_narg = 0, .sy_call = (sy_call_t *)sys_setsid, .sy_auevent = AUE_SETSID, .sy_flags = SYF_CAPENABLED, .sy_thrcnt = SY_THR_STATIC }, /* 147 = setsid */
{ .sy_narg = AS(quotactl_args), .sy_call = (sy_call_t *)sys_quotactl, .sy_auevent = AUE_QUOTACTL, .sy_flags = 0, .sy_thrcnt = SY_THR_STATIC }, /* 148 = quotactl */
- { compat(0,quota), .sy_auevent = AUE_O_QUOTA, .sy_flags = 0, .sy_thrcnt = SY_THR_STATIC }, /* 149 = old quota */
+ { compat(0,quota), .sy_auevent = AUE_O_QUOTA, .sy_flags = 0, .sy_thrcnt = SY_THR_STATIC }, /* 149 = old quota */
{ compat(AS(ogetsockname_args),getsockname), .sy_auevent = AUE_GETSOCKNAME, .sy_flags = SYF_CAPENABLED, .sy_thrcnt = SY_THR_STATIC }, /* 150 = old getsockname */
- { .sy_narg = 0, .sy_call = (sy_call_t *)nosys, .sy_auevent = AUE_NULL, .sy_flags = 0, .sy_thrcnt = SY_THR_ABSENT }, /* 151 = reserved for local use */
- { .sy_narg = 0, .sy_call = (sy_call_t *)nosys, .sy_auevent = AUE_NULL, .sy_flags = 0, .sy_thrcnt = SY_THR_ABSENT }, /* 152 = reserved for local use */
- { .sy_narg = 0, .sy_call = (sy_call_t *)nosys, .sy_auevent = AUE_NULL, .sy_flags = 0, .sy_thrcnt = SY_THR_ABSENT }, /* 153 = reserved for local use */
- { .sy_narg = 0, .sy_call = (sy_call_t *)nosys, .sy_auevent = AUE_NULL, .sy_flags = 0, .sy_thrcnt = SY_THR_ABSENT }, /* 154 = nlm_syscall */
- { .sy_narg = 0, .sy_call = (sy_call_t *)nosys, .sy_auevent = AUE_NULL, .sy_flags = 0, .sy_thrcnt = SY_THR_ABSENT }, /* 155 = nfssvc */
+ { .sy_narg = 0, .sy_call = (sy_call_t *)nosys, .sy_auevent = AUE_NULL, .sy_flags = 0, .sy_thrcnt = SY_THR_ABSENT }, /* 151 = reserved for local use */
+ { .sy_narg = 0, .sy_call = (sy_call_t *)nosys, .sy_auevent = AUE_NULL, .sy_flags = 0, .sy_thrcnt = SY_THR_ABSENT }, /* 152 = reserved for local use */
+ { .sy_narg = 0, .sy_call = (sy_call_t *)nosys, .sy_auevent = AUE_NULL, .sy_flags = 0, .sy_thrcnt = SY_THR_ABSENT }, /* 153 = reserved for local use */
+ { .sy_narg = 0, .sy_call = (sy_call_t *)nosys, .sy_auevent = AUE_NULL, .sy_flags = 0, .sy_thrcnt = SY_THR_ABSENT }, /* 154 = freebsd32_nlm_syscall */
+ { .sy_narg = 0, .sy_call = (sy_call_t *)nosys, .sy_auevent = AUE_NULL, .sy_flags = 0, .sy_thrcnt = SY_THR_ABSENT }, /* 155 = nfssvc */
{ compat(AS(ofreebsd32_getdirentries_args),freebsd32_getdirentries), .sy_auevent = AUE_GETDIRENTRIES, .sy_flags = SYF_CAPENABLED, .sy_thrcnt = SY_THR_STATIC }, /* 156 = old freebsd32_getdirentries */
{ compat4(AS(freebsd4_freebsd32_statfs_args),freebsd32_statfs), .sy_auevent = AUE_STATFS, .sy_flags = 0, .sy_thrcnt = SY_THR_STATIC }, /* 157 = freebsd4 freebsd32_statfs */
{ compat4(AS(freebsd4_freebsd32_fstatfs_args),freebsd32_fstatfs), .sy_auevent = AUE_FSTATFS, .sy_flags = SYF_CAPENABLED, .sy_thrcnt = SY_THR_STATIC }, /* 158 = freebsd4 freebsd32_fstatfs */
- { .sy_narg = 0, .sy_call = (sy_call_t *)nosys, .sy_auevent = AUE_NULL, .sy_flags = 0, .sy_thrcnt = SY_THR_ABSENT }, /* 159 = reserved for local use */
- { .sy_narg = 0, .sy_call = (sy_call_t *)nosys, .sy_auevent = AUE_NULL, .sy_flags = 0, .sy_thrcnt = SY_THR_ABSENT }, /* 160 = lgetfh */
+ { .sy_narg = 0, .sy_call = (sy_call_t *)nosys, .sy_auevent = AUE_NULL, .sy_flags = 0, .sy_thrcnt = SY_THR_ABSENT }, /* 159 = reserved for local use */
+ { .sy_narg = 0, .sy_call = (sy_call_t *)nosys, .sy_auevent = AUE_NULL, .sy_flags = 0, .sy_thrcnt = SY_THR_ABSENT }, /* 160 = lgetfh */
{ .sy_narg = AS(getfh_args), .sy_call = (sy_call_t *)sys_getfh, .sy_auevent = AUE_NFS_GETFH, .sy_flags = 0, .sy_thrcnt = SY_THR_STATIC }, /* 161 = getfh */
{ compat4(AS(freebsd4_getdomainname_args),getdomainname), .sy_auevent = AUE_SYSCTL, .sy_flags = SYF_CAPENABLED, .sy_thrcnt = SY_THR_STATIC }, /* 162 = freebsd4 getdomainname */
{ compat4(AS(freebsd4_setdomainname_args),setdomainname), .sy_auevent = AUE_SYSCTL, .sy_flags = 0, .sy_thrcnt = SY_THR_STATIC }, /* 163 = freebsd4 setdomainname */
{ compat4(AS(freebsd4_uname_args),uname), .sy_auevent = AUE_NULL, .sy_flags = 0, .sy_thrcnt = SY_THR_STATIC }, /* 164 = freebsd4 uname */
{ .sy_narg = AS(freebsd32_sysarch_args), .sy_call = (sy_call_t *)freebsd32_sysarch, .sy_auevent = AUE_SYSARCH, .sy_flags = SYF_CAPENABLED, .sy_thrcnt = SY_THR_STATIC }, /* 165 = freebsd32_sysarch */
{ .sy_narg = AS(rtprio_args), .sy_call = (sy_call_t *)sys_rtprio, .sy_auevent = AUE_RTPRIO, .sy_flags = SYF_CAPENABLED, .sy_thrcnt = SY_THR_STATIC }, /* 166 = rtprio */
- { .sy_narg = 0, .sy_call = (sy_call_t *)nosys, .sy_auevent = AUE_NULL, .sy_flags = 0, .sy_thrcnt = SY_THR_ABSENT }, /* 167 = reserved for local use */
- { .sy_narg = 0, .sy_call = (sy_call_t *)nosys, .sy_auevent = AUE_NULL, .sy_flags = 0, .sy_thrcnt = SY_THR_ABSENT }, /* 168 = reserved for local use */
+ { .sy_narg = 0, .sy_call = (sy_call_t *)nosys, .sy_auevent = AUE_NULL, .sy_flags = 0, .sy_thrcnt = SY_THR_ABSENT }, /* 167 = reserved for local use */
+ { .sy_narg = 0, .sy_call = (sy_call_t *)nosys, .sy_auevent = AUE_NULL, .sy_flags = 0, .sy_thrcnt = SY_THR_ABSENT }, /* 168 = reserved for local use */
{ .sy_narg = AS(freebsd32_semsys_args), .sy_call = (sy_call_t *)lkmressys, .sy_auevent = AUE_NULL, .sy_flags = 0, .sy_thrcnt = SY_THR_ABSENT }, /* 169 = freebsd32_semsys */
{ .sy_narg = AS(freebsd32_msgsys_args), .sy_call = (sy_call_t *)lkmressys, .sy_auevent = AUE_NULL, .sy_flags = 0, .sy_thrcnt = SY_THR_ABSENT }, /* 170 = freebsd32_msgsys */
{ .sy_narg = AS(freebsd32_shmsys_args), .sy_call = (sy_call_t *)lkmressys, .sy_auevent = AUE_NULL, .sy_flags = 0, .sy_thrcnt = SY_THR_ABSENT }, /* 171 = freebsd32_shmsys */
- { .sy_narg = 0, .sy_call = (sy_call_t *)nosys, .sy_auevent = AUE_NULL, .sy_flags = 0, .sy_thrcnt = SY_THR_ABSENT }, /* 172 = reserved for local use */
+ { .sy_narg = 0, .sy_call = (sy_call_t *)nosys, .sy_auevent = AUE_NULL, .sy_flags = 0, .sy_thrcnt = SY_THR_ABSENT }, /* 172 = reserved for local use */
{ compat6(AS(freebsd6_freebsd32_pread_args),freebsd32_pread), .sy_auevent = AUE_PREAD, .sy_flags = SYF_CAPENABLED, .sy_thrcnt = SY_THR_STATIC }, /* 173 = freebsd6 freebsd32_pread */
{ compat6(AS(freebsd6_freebsd32_pwrite_args),freebsd32_pwrite), .sy_auevent = AUE_PWRITE, .sy_flags = SYF_CAPENABLED, .sy_thrcnt = SY_THR_STATIC }, /* 174 = freebsd6 freebsd32_pwrite */
{ .sy_narg = AS(setfib_args), .sy_call = (sy_call_t *)sys_setfib, .sy_auevent = AUE_SETFIB, .sy_flags = 0, .sy_thrcnt = SY_THR_STATIC }, /* 175 = setfib */
{ .sy_narg = AS(freebsd32_ntp_adjtime_args), .sy_call = (sy_call_t *)freebsd32_ntp_adjtime, .sy_auevent = AUE_NTP_ADJTIME, .sy_flags = 0, .sy_thrcnt = SY_THR_STATIC }, /* 176 = freebsd32_ntp_adjtime */
- { .sy_narg = 0, .sy_call = (sy_call_t *)nosys, .sy_auevent = AUE_NULL, .sy_flags = 0, .sy_thrcnt = SY_THR_ABSENT }, /* 177 = reserved for local use */
- { .sy_narg = 0, .sy_call = (sy_call_t *)nosys, .sy_auevent = AUE_NULL, .sy_flags = 0, .sy_thrcnt = SY_THR_ABSENT }, /* 178 = reserved for local use */
- { .sy_narg = 0, .sy_call = (sy_call_t *)nosys, .sy_auevent = AUE_NULL, .sy_flags = 0, .sy_thrcnt = SY_THR_ABSENT }, /* 179 = reserved for local use */
- { .sy_narg = 0, .sy_call = (sy_call_t *)nosys, .sy_auevent = AUE_NULL, .sy_flags = 0, .sy_thrcnt = SY_THR_ABSENT }, /* 180 = reserved for local use */
+ { .sy_narg = 0, .sy_call = (sy_call_t *)nosys, .sy_auevent = AUE_NULL, .sy_flags = 0, .sy_thrcnt = SY_THR_ABSENT }, /* 177 = reserved for local use */
+ { .sy_narg = 0, .sy_call = (sy_call_t *)nosys, .sy_auevent = AUE_NULL, .sy_flags = 0, .sy_thrcnt = SY_THR_ABSENT }, /* 178 = reserved for local use */
+ { .sy_narg = 0, .sy_call = (sy_call_t *)nosys, .sy_auevent = AUE_NULL, .sy_flags = 0, .sy_thrcnt = SY_THR_ABSENT }, /* 179 = reserved for local use */
+ { .sy_narg = 0, .sy_call = (sy_call_t *)nosys, .sy_auevent = AUE_NULL, .sy_flags = 0, .sy_thrcnt = SY_THR_ABSENT }, /* 180 = reserved for local use */
{ .sy_narg = AS(setgid_args), .sy_call = (sy_call_t *)sys_setgid, .sy_auevent = AUE_SETGID, .sy_flags = SYF_CAPENABLED, .sy_thrcnt = SY_THR_STATIC }, /* 181 = setgid */
{ .sy_narg = AS(setegid_args), .sy_call = (sy_call_t *)sys_setegid, .sy_auevent = AUE_SETEGID, .sy_flags = SYF_CAPENABLED, .sy_thrcnt = SY_THR_STATIC }, /* 182 = setegid */
{ .sy_narg = AS(seteuid_args), .sy_call = (sy_call_t *)sys_seteuid, .sy_auevent = AUE_SETEUID, .sy_flags = SYF_CAPENABLED, .sy_thrcnt = SY_THR_STATIC }, /* 183 = seteuid */
- { .sy_narg = 0, .sy_call = (sy_call_t *)nosys, .sy_auevent = AUE_NULL, .sy_flags = 0, .sy_thrcnt = SY_THR_ABSENT }, /* 184 = obsolete lfs_bmapv */
- { .sy_narg = 0, .sy_call = (sy_call_t *)nosys, .sy_auevent = AUE_NULL, .sy_flags = 0, .sy_thrcnt = SY_THR_ABSENT }, /* 185 = obsolete lfs_markv */
- { .sy_narg = 0, .sy_call = (sy_call_t *)nosys, .sy_auevent = AUE_NULL, .sy_flags = 0, .sy_thrcnt = SY_THR_ABSENT }, /* 186 = obsolete lfs_segclean */
- { .sy_narg = 0, .sy_call = (sy_call_t *)nosys, .sy_auevent = AUE_NULL, .sy_flags = 0, .sy_thrcnt = SY_THR_ABSENT }, /* 187 = obsolete lfs_segwait */
+ { .sy_narg = 0, .sy_call = (sy_call_t *)nosys, .sy_auevent = AUE_NULL, .sy_flags = 0, .sy_thrcnt = SY_THR_ABSENT }, /* 184 = obsolete lfs_bmapv */
+ { .sy_narg = 0, .sy_call = (sy_call_t *)nosys, .sy_auevent = AUE_NULL, .sy_flags = 0, .sy_thrcnt = SY_THR_ABSENT }, /* 185 = obsolete lfs_markv */
+ { .sy_narg = 0, .sy_call = (sy_call_t *)nosys, .sy_auevent = AUE_NULL, .sy_flags = 0, .sy_thrcnt = SY_THR_ABSENT }, /* 186 = obsolete lfs_segclean */
+ { .sy_narg = 0, .sy_call = (sy_call_t *)nosys, .sy_auevent = AUE_NULL, .sy_flags = 0, .sy_thrcnt = SY_THR_ABSENT }, /* 187 = obsolete lfs_segwait */
{ compat11(AS(freebsd11_freebsd32_stat_args),freebsd32_stat), .sy_auevent = AUE_STAT, .sy_flags = 0, .sy_thrcnt = SY_THR_STATIC }, /* 188 = freebsd11 freebsd32_stat */
{ compat11(AS(freebsd11_freebsd32_fstat_args),freebsd32_fstat), .sy_auevent = AUE_FSTAT, .sy_flags = SYF_CAPENABLED, .sy_thrcnt = SY_THR_STATIC }, /* 189 = freebsd11 freebsd32_fstat */
{ compat11(AS(freebsd11_freebsd32_lstat_args),freebsd32_lstat), .sy_auevent = AUE_LSTAT, .sy_flags = 0, .sy_thrcnt = SY_THR_STATIC }, /* 190 = freebsd11 freebsd32_lstat */
{ .sy_narg = AS(pathconf_args), .sy_call = (sy_call_t *)sys_pathconf, .sy_auevent = AUE_PATHCONF, .sy_flags = 0, .sy_thrcnt = SY_THR_STATIC }, /* 191 = pathconf */
{ .sy_narg = AS(fpathconf_args), .sy_call = (sy_call_t *)sys_fpathconf, .sy_auevent = AUE_FPATHCONF, .sy_flags = SYF_CAPENABLED, .sy_thrcnt = SY_THR_STATIC }, /* 192 = fpathconf */
- { .sy_narg = 0, .sy_call = (sy_call_t *)nosys, .sy_auevent = AUE_NULL, .sy_flags = 0, .sy_thrcnt = SY_THR_ABSENT }, /* 193 = reserved for local use */
+ { .sy_narg = 0, .sy_call = (sy_call_t *)nosys, .sy_auevent = AUE_NULL, .sy_flags = 0, .sy_thrcnt = SY_THR_ABSENT }, /* 193 = reserved for local use */
{ .sy_narg = AS(getrlimit_args), .sy_call = (sy_call_t *)sys_getrlimit, .sy_auevent = AUE_GETRLIMIT, .sy_flags = SYF_CAPENABLED, .sy_thrcnt = SY_THR_STATIC }, /* 194 = getrlimit */
{ .sy_narg = AS(setrlimit_args), .sy_call = (sy_call_t *)sys_setrlimit, .sy_auevent = AUE_SETRLIMIT, .sy_flags = SYF_CAPENABLED, .sy_thrcnt = SY_THR_STATIC }, /* 195 = setrlimit */
{ compat11(AS(freebsd11_freebsd32_getdirentries_args),freebsd32_getdirentries), .sy_auevent = AUE_GETDIRENTRIES, .sy_flags = SYF_CAPENABLED, .sy_thrcnt = SY_THR_STATIC }, /* 196 = freebsd11 freebsd32_getdirentries */
{ compat6(AS(freebsd6_freebsd32_mmap_args),freebsd32_mmap), .sy_auevent = AUE_MMAP, .sy_flags = SYF_CAPENABLED, .sy_thrcnt = SY_THR_STATIC }, /* 197 = freebsd6 freebsd32_mmap */
- { .sy_narg = 0, .sy_call = (sy_call_t *)nosys, .sy_auevent = AUE_NULL, .sy_flags = 0, .sy_thrcnt = SY_THR_STATIC }, /* 198 = __syscall */
+ { .sy_narg = 0, .sy_call = (sy_call_t *)nosys, .sy_auevent = AUE_NULL, .sy_flags = 0, .sy_thrcnt = SY_THR_STATIC }, /* 198 = __syscall */
{ compat6(AS(freebsd6_freebsd32_lseek_args),freebsd32_lseek), .sy_auevent = AUE_LSEEK, .sy_flags = SYF_CAPENABLED, .sy_thrcnt = SY_THR_STATIC }, /* 199 = freebsd6 freebsd32_lseek */
{ compat6(AS(freebsd6_freebsd32_truncate_args),freebsd32_truncate), .sy_auevent = AUE_TRUNCATE, .sy_flags = 0, .sy_thrcnt = SY_THR_STATIC }, /* 200 = freebsd6 freebsd32_truncate */
{ compat6(AS(freebsd6_freebsd32_ftruncate_args),freebsd32_ftruncate), .sy_auevent = AUE_FTRUNCATE, .sy_flags = SYF_CAPENABLED, .sy_thrcnt = SY_THR_STATIC }, /* 201 = freebsd6 freebsd32_ftruncate */
@@ -264,7 +275,7 @@ struct sysent freebsd32_sysent[] = {
{ .sy_narg = AS(undelete_args), .sy_call = (sy_call_t *)sys_undelete, .sy_auevent = AUE_UNDELETE, .sy_flags = 0, .sy_thrcnt = SY_THR_STATIC }, /* 205 = undelete */
{ .sy_narg = AS(freebsd32_futimes_args), .sy_call = (sy_call_t *)freebsd32_futimes, .sy_auevent = AUE_FUTIMES, .sy_flags = SYF_CAPENABLED, .sy_thrcnt = SY_THR_STATIC }, /* 206 = freebsd32_futimes */
{ .sy_narg = AS(getpgid_args), .sy_call = (sy_call_t *)sys_getpgid, .sy_auevent = AUE_GETPGID, .sy_flags = SYF_CAPENABLED, .sy_thrcnt = SY_THR_STATIC }, /* 207 = getpgid */
- { .sy_narg = 0, .sy_call = (sy_call_t *)nosys, .sy_auevent = AUE_NULL, .sy_flags = 0, .sy_thrcnt = SY_THR_ABSENT }, /* 208 = reserved for local use */
+ { .sy_narg = 0, .sy_call = (sy_call_t *)nosys, .sy_auevent = AUE_NULL, .sy_flags = 0, .sy_thrcnt = SY_THR_ABSENT }, /* 208 = reserved for local use */
{ .sy_narg = AS(poll_args), .sy_call = (sy_call_t *)sys_poll, .sy_auevent = AUE_POLL, .sy_flags = SYF_CAPENABLED, .sy_thrcnt = SY_THR_STATIC }, /* 209 = poll */
{ .sy_narg = AS(nosys_args), .sy_call = (sy_call_t *)lkmnosys, .sy_auevent = AUE_NULL, .sy_flags = 0, .sy_thrcnt = SY_THR_ABSENT }, /* 210 = lkmnosys */
{ .sy_narg = AS(nosys_args), .sy_call = (sy_call_t *)lkmnosys, .sy_auevent = AUE_NULL, .sy_flags = 0, .sy_thrcnt = SY_THR_ABSENT }, /* 211 = lkmnosys */
@@ -276,16 +287,16 @@ struct sysent freebsd32_sysent[] = {
{ .sy_narg = AS(nosys_args), .sy_call = (sy_call_t *)lkmnosys, .sy_auevent = AUE_NULL, .sy_flags = 0, .sy_thrcnt = SY_THR_ABSENT }, /* 217 = lkmnosys */
{ .sy_narg = AS(nosys_args), .sy_call = (sy_call_t *)lkmnosys, .sy_auevent = AUE_NULL, .sy_flags = 0, .sy_thrcnt = SY_THR_ABSENT }, /* 218 = lkmnosys */
{ .sy_narg = AS(nosys_args), .sy_call = (sy_call_t *)lkmnosys, .sy_auevent = AUE_NULL, .sy_flags = 0, .sy_thrcnt = SY_THR_ABSENT }, /* 219 = lkmnosys */
- { .sy_narg = 0, .sy_call = (sy_call_t *)lkmressys, .sy_auevent = AUE_NULL, .sy_flags = 0, .sy_thrcnt = SY_THR_ABSENT }, /* 220 = freebsd7 freebsd32___semctl */
+ { .sy_narg = 0, .sy_call = (sy_call_t *)lkmressys, .sy_auevent = AUE_NULL, .sy_flags = 0, .sy_thrcnt = SY_THR_ABSENT }, /* 220 = freebsd7 freebsd32___semctl */
{ .sy_narg = AS(semget_args), .sy_call = (sy_call_t *)lkmressys, .sy_auevent = AUE_NULL, .sy_flags = 0, .sy_thrcnt = SY_THR_ABSENT }, /* 221 = semget */
{ .sy_narg = AS(semop_args), .sy_call = (sy_call_t *)lkmressys, .sy_auevent = AUE_NULL, .sy_flags = 0, .sy_thrcnt = SY_THR_ABSENT }, /* 222 = semop */
- { .sy_narg = 0, .sy_call = (sy_call_t *)nosys, .sy_auevent = AUE_NULL, .sy_flags = 0, .sy_thrcnt = SY_THR_ABSENT }, /* 223 = obsolete semconfig */
- { .sy_narg = 0, .sy_call = (sy_call_t *)lkmressys, .sy_auevent = AUE_NULL, .sy_flags = 0, .sy_thrcnt = SY_THR_ABSENT }, /* 224 = freebsd7 freebsd32_msgctl */
+ { .sy_narg = 0, .sy_call = (sy_call_t *)nosys, .sy_auevent = AUE_NULL, .sy_flags = 0, .sy_thrcnt = SY_THR_ABSENT }, /* 223 = obsolete semconfig */
+ { .sy_narg = 0, .sy_call = (sy_call_t *)lkmressys, .sy_auevent = AUE_NULL, .sy_flags = 0, .sy_thrcnt = SY_THR_ABSENT }, /* 224 = freebsd7 freebsd32_msgctl */
{ .sy_narg = AS(msgget_args), .sy_call = (sy_call_t *)lkmressys, .sy_auevent = AUE_NULL, .sy_flags = 0, .sy_thrcnt = SY_THR_ABSENT }, /* 225 = msgget */
{ .sy_narg = AS(freebsd32_msgsnd_args), .sy_call = (sy_call_t *)lkmressys, .sy_auevent = AUE_NULL, .sy_flags = 0, .sy_thrcnt = SY_THR_ABSENT }, /* 226 = freebsd32_msgsnd */
{ .sy_narg = AS(freebsd32_msgrcv_args), .sy_call = (sy_call_t *)lkmressys, .sy_auevent = AUE_NULL, .sy_flags = 0, .sy_thrcnt = SY_THR_ABSENT }, /* 227 = freebsd32_msgrcv */
{ .sy_narg = AS(shmat_args), .sy_call = (sy_call_t *)lkmressys, .sy_auevent = AUE_NULL, .sy_flags = 0, .sy_thrcnt = SY_THR_ABSENT }, /* 228 = shmat */
- { .sy_narg = 0, .sy_call = (sy_call_t *)lkmressys, .sy_auevent = AUE_NULL, .sy_flags = 0, .sy_thrcnt = SY_THR_ABSENT }, /* 229 = freebsd7 freebsd32_shmctl */
+ { .sy_narg = 0, .sy_call = (sy_call_t *)lkmressys, .sy_auevent = AUE_NULL, .sy_flags = 0, .sy_thrcnt = SY_THR_ABSENT }, /* 229 = freebsd7 freebsd32_shmctl */
{ .sy_narg = AS(shmdt_args), .sy_call = (sy_call_t *)lkmressys, .sy_auevent = AUE_NULL, .sy_flags = 0, .sy_thrcnt = SY_THR_ABSENT }, /* 230 = shmdt */
{ .sy_narg = AS(shmget_args), .sy_call = (sy_call_t *)lkmressys, .sy_auevent = AUE_NULL, .sy_flags = 0, .sy_thrcnt = SY_THR_ABSENT }, /* 231 = shmget */
{ .sy_narg = AS(freebsd32_clock_gettime_args), .sy_call = (sy_call_t *)freebsd32_clock_gettime, .sy_auevent = AUE_NULL, .sy_flags = SYF_CAPENABLED, .sy_thrcnt = SY_THR_STATIC }, /* 232 = freebsd32_clock_gettime */
@@ -301,58 +312,58 @@ struct sysent freebsd32_sysent[] = {
{ .sy_narg = AS(freebsd32_ffclock_setestimate_args), .sy_call = (sy_call_t *)freebsd32_ffclock_setestimate, .sy_auevent = AUE_NULL, .sy_flags = 0, .sy_thrcnt = SY_THR_STATIC }, /* 242 = freebsd32_ffclock_setestimate */
{ .sy_narg = AS(freebsd32_ffclock_getestimate_args), .sy_call = (sy_call_t *)freebsd32_ffclock_getestimate, .sy_auevent = AUE_NULL, .sy_flags = 0, .sy_thrcnt = SY_THR_STATIC }, /* 243 = freebsd32_ffclock_getestimate */
{ .sy_narg = AS(freebsd32_clock_nanosleep_args), .sy_call = (sy_call_t *)freebsd32_clock_nanosleep, .sy_auevent = AUE_NULL, .sy_flags = 0, .sy_thrcnt = SY_THR_STATIC }, /* 244 = freebsd32_clock_nanosleep */
- { .sy_narg = 0, .sy_call = (sy_call_t *)nosys, .sy_auevent = AUE_NULL, .sy_flags = 0, .sy_thrcnt = SY_THR_ABSENT }, /* 245 = reserved for local use */
- { .sy_narg = 0, .sy_call = (sy_call_t *)nosys, .sy_auevent = AUE_NULL, .sy_flags = 0, .sy_thrcnt = SY_THR_ABSENT }, /* 246 = reserved for local use */
+ { .sy_narg = 0, .sy_call = (sy_call_t *)nosys, .sy_auevent = AUE_NULL, .sy_flags = 0, .sy_thrcnt = SY_THR_ABSENT }, /* 245 = reserved for local use */
+ { .sy_narg = 0, .sy_call = (sy_call_t *)nosys, .sy_auevent = AUE_NULL, .sy_flags = 0, .sy_thrcnt = SY_THR_ABSENT }, /* 246 = reserved for local use */
{ .sy_narg = AS(freebsd32_clock_getcpuclockid2_args), .sy_call = (sy_call_t *)freebsd32_clock_getcpuclockid2, .sy_auevent = AUE_NULL, .sy_flags = 0, .sy_thrcnt = SY_THR_STATIC }, /* 247 = freebsd32_clock_getcpuclockid2 */
- { .sy_narg = 0, .sy_call = (sy_call_t *)nosys, .sy_auevent = AUE_NULL, .sy_flags = 0, .sy_thrcnt = SY_THR_ABSENT }, /* 248 = ntp_gettime */
- { .sy_narg = 0, .sy_call = (sy_call_t *)nosys, .sy_auevent = AUE_NULL, .sy_flags = 0, .sy_thrcnt = SY_THR_ABSENT }, /* 249 = reserved for local use */
+ { .sy_narg = 0, .sy_call = (sy_call_t *)nosys, .sy_auevent = AUE_NULL, .sy_flags = 0, .sy_thrcnt = SY_THR_ABSENT }, /* 248 = freebsd32_ntp_gettime */
+ { .sy_narg = 0, .sy_call = (sy_call_t *)nosys, .sy_auevent = AUE_NULL, .sy_flags = 0, .sy_thrcnt = SY_THR_ABSENT }, /* 249 = reserved for local use */
{ .sy_narg = AS(minherit_args), .sy_call = (sy_call_t *)sys_minherit, .sy_auevent = AUE_MINHERIT, .sy_flags = SYF_CAPENABLED, .sy_thrcnt = SY_THR_STATIC }, /* 250 = minherit */
- { .sy_narg = AS(rfork_args), .sy_call = (sy_call_t *)sys_rfork, .sy_auevent = AUE_RFORK, .sy_flags = 0, .sy_thrcnt = SY_THR_STATIC }, /* 251 = rfork */
- { .sy_narg = 0, .sy_call = (sy_call_t *)nosys, .sy_auevent = AUE_NULL, .sy_flags = 0, .sy_thrcnt = SY_THR_ABSENT }, /* 252 = obsolete openbsd_poll */
+ { .sy_narg = AS(rfork_args), .sy_call = (sy_call_t *)sys_rfork, .sy_auevent = AUE_RFORK, .sy_flags = SYF_CAPENABLED, .sy_thrcnt = SY_THR_STATIC }, /* 251 = rfork */
+ { .sy_narg = 0, .sy_call = (sy_call_t *)nosys, .sy_auevent = AUE_NULL, .sy_flags = 0, .sy_thrcnt = SY_THR_ABSENT }, /* 252 = obsolete openbsd_poll */
{ .sy_narg = 0, .sy_call = (sy_call_t *)sys_issetugid, .sy_auevent = AUE_ISSETUGID, .sy_flags = SYF_CAPENABLED, .sy_thrcnt = SY_THR_STATIC }, /* 253 = issetugid */
{ .sy_narg = AS(lchown_args), .sy_call = (sy_call_t *)sys_lchown, .sy_auevent = AUE_LCHOWN, .sy_flags = 0, .sy_thrcnt = SY_THR_STATIC }, /* 254 = lchown */
{ .sy_narg = AS(freebsd32_aio_read_args), .sy_call = (sy_call_t *)freebsd32_aio_read, .sy_auevent = AUE_AIO_READ, .sy_flags = SYF_CAPENABLED, .sy_thrcnt = SY_THR_STATIC }, /* 255 = freebsd32_aio_read */
{ .sy_narg = AS(freebsd32_aio_write_args), .sy_call = (sy_call_t *)freebsd32_aio_write, .sy_auevent = AUE_AIO_WRITE, .sy_flags = SYF_CAPENABLED, .sy_thrcnt = SY_THR_STATIC }, /* 256 = freebsd32_aio_write */
{ .sy_narg = AS(freebsd32_lio_listio_args), .sy_call = (sy_call_t *)freebsd32_lio_listio, .sy_auevent = AUE_LIO_LISTIO, .sy_flags = SYF_CAPENABLED, .sy_thrcnt = SY_THR_STATIC }, /* 257 = freebsd32_lio_listio */
- { .sy_narg = 0, .sy_call = (sy_call_t *)nosys, .sy_auevent = AUE_NULL, .sy_flags = 0, .sy_thrcnt = SY_THR_ABSENT }, /* 258 = reserved for local use */
- { .sy_narg = 0, .sy_call = (sy_call_t *)nosys, .sy_auevent = AUE_NULL, .sy_flags = 0, .sy_thrcnt = SY_THR_ABSENT }, /* 259 = reserved for local use */
- { .sy_narg = 0, .sy_call = (sy_call_t *)nosys, .sy_auevent = AUE_NULL, .sy_flags = 0, .sy_thrcnt = SY_THR_ABSENT }, /* 260 = reserved for local use */
- { .sy_narg = 0, .sy_call = (sy_call_t *)nosys, .sy_auevent = AUE_NULL, .sy_flags = 0, .sy_thrcnt = SY_THR_ABSENT }, /* 261 = reserved for local use */
- { .sy_narg = 0, .sy_call = (sy_call_t *)nosys, .sy_auevent = AUE_NULL, .sy_flags = 0, .sy_thrcnt = SY_THR_ABSENT }, /* 262 = reserved for local use */
- { .sy_narg = 0, .sy_call = (sy_call_t *)nosys, .sy_auevent = AUE_NULL, .sy_flags = 0, .sy_thrcnt = SY_THR_ABSENT }, /* 263 = reserved for local use */
- { .sy_narg = 0, .sy_call = (sy_call_t *)nosys, .sy_auevent = AUE_NULL, .sy_flags = 0, .sy_thrcnt = SY_THR_ABSENT }, /* 264 = reserved for local use */
- { .sy_narg = 0, .sy_call = (sy_call_t *)nosys, .sy_auevent = AUE_NULL, .sy_flags = 0, .sy_thrcnt = SY_THR_ABSENT }, /* 265 = reserved for local use */
- { .sy_narg = 0, .sy_call = (sy_call_t *)nosys, .sy_auevent = AUE_NULL, .sy_flags = 0, .sy_thrcnt = SY_THR_ABSENT }, /* 266 = reserved for local use */
- { .sy_narg = 0, .sy_call = (sy_call_t *)nosys, .sy_auevent = AUE_NULL, .sy_flags = 0, .sy_thrcnt = SY_THR_ABSENT }, /* 267 = reserved for local use */
- { .sy_narg = 0, .sy_call = (sy_call_t *)nosys, .sy_auevent = AUE_NULL, .sy_flags = 0, .sy_thrcnt = SY_THR_ABSENT }, /* 268 = reserved for local use */
- { .sy_narg = 0, .sy_call = (sy_call_t *)nosys, .sy_auevent = AUE_NULL, .sy_flags = 0, .sy_thrcnt = SY_THR_ABSENT }, /* 269 = reserved for local use */
- { .sy_narg = 0, .sy_call = (sy_call_t *)nosys, .sy_auevent = AUE_NULL, .sy_flags = 0, .sy_thrcnt = SY_THR_ABSENT }, /* 270 = reserved for local use */
- { .sy_narg = 0, .sy_call = (sy_call_t *)nosys, .sy_auevent = AUE_NULL, .sy_flags = 0, .sy_thrcnt = SY_THR_ABSENT }, /* 271 = reserved for local use */
+ { .sy_narg = 0, .sy_call = (sy_call_t *)nosys, .sy_auevent = AUE_NULL, .sy_flags = 0, .sy_thrcnt = SY_THR_ABSENT }, /* 258 = reserved for local use */
+ { .sy_narg = 0, .sy_call = (sy_call_t *)nosys, .sy_auevent = AUE_NULL, .sy_flags = 0, .sy_thrcnt = SY_THR_ABSENT }, /* 259 = reserved for local use */
+ { .sy_narg = 0, .sy_call = (sy_call_t *)nosys, .sy_auevent = AUE_NULL, .sy_flags = 0, .sy_thrcnt = SY_THR_ABSENT }, /* 260 = reserved for local use */
+ { .sy_narg = 0, .sy_call = (sy_call_t *)nosys, .sy_auevent = AUE_NULL, .sy_flags = 0, .sy_thrcnt = SY_THR_ABSENT }, /* 261 = reserved for local use */
+ { .sy_narg = 0, .sy_call = (sy_call_t *)nosys, .sy_auevent = AUE_NULL, .sy_flags = 0, .sy_thrcnt = SY_THR_ABSENT }, /* 262 = reserved for local use */
+ { .sy_narg = 0, .sy_call = (sy_call_t *)nosys, .sy_auevent = AUE_NULL, .sy_flags = 0, .sy_thrcnt = SY_THR_ABSENT }, /* 263 = reserved for local use */
+ { .sy_narg = 0, .sy_call = (sy_call_t *)nosys, .sy_auevent = AUE_NULL, .sy_flags = 0, .sy_thrcnt = SY_THR_ABSENT }, /* 264 = reserved for local use */
+ { .sy_narg = 0, .sy_call = (sy_call_t *)nosys, .sy_auevent = AUE_NULL, .sy_flags = 0, .sy_thrcnt = SY_THR_ABSENT }, /* 265 = reserved for local use */
+ { .sy_narg = 0, .sy_call = (sy_call_t *)nosys, .sy_auevent = AUE_NULL, .sy_flags = 0, .sy_thrcnt = SY_THR_ABSENT }, /* 266 = reserved for local use */
+ { .sy_narg = 0, .sy_call = (sy_call_t *)nosys, .sy_auevent = AUE_NULL, .sy_flags = 0, .sy_thrcnt = SY_THR_ABSENT }, /* 267 = reserved for local use */
+ { .sy_narg = 0, .sy_call = (sy_call_t *)nosys, .sy_auevent = AUE_NULL, .sy_flags = 0, .sy_thrcnt = SY_THR_ABSENT }, /* 268 = reserved for local use */
+ { .sy_narg = 0, .sy_call = (sy_call_t *)nosys, .sy_auevent = AUE_NULL, .sy_flags = 0, .sy_thrcnt = SY_THR_ABSENT }, /* 269 = reserved for local use */
+ { .sy_narg = 0, .sy_call = (sy_call_t *)nosys, .sy_auevent = AUE_NULL, .sy_flags = 0, .sy_thrcnt = SY_THR_ABSENT }, /* 270 = reserved for local use */
+ { .sy_narg = 0, .sy_call = (sy_call_t *)nosys, .sy_auevent = AUE_NULL, .sy_flags = 0, .sy_thrcnt = SY_THR_ABSENT }, /* 271 = reserved for local use */
{ compat11(AS(freebsd11_getdents_args),getdents), .sy_auevent = AUE_O_GETDENTS, .sy_flags = SYF_CAPENABLED, .sy_thrcnt = SY_THR_STATIC }, /* 272 = freebsd11 getdents */
- { .sy_narg = 0, .sy_call = (sy_call_t *)nosys, .sy_auevent = AUE_NULL, .sy_flags = 0, .sy_thrcnt = SY_THR_ABSENT }, /* 273 = reserved for local use */
+ { .sy_narg = 0, .sy_call = (sy_call_t *)nosys, .sy_auevent = AUE_NULL, .sy_flags = 0, .sy_thrcnt = SY_THR_ABSENT }, /* 273 = reserved for local use */
{ .sy_narg = AS(lchmod_args), .sy_call = (sy_call_t *)sys_lchmod, .sy_auevent = AUE_LCHMOD, .sy_flags = 0, .sy_thrcnt = SY_THR_STATIC }, /* 274 = lchmod */
- { .sy_narg = 0, .sy_call = (sy_call_t *)nosys, .sy_auevent = AUE_NULL, .sy_flags = 0, .sy_thrcnt = SY_THR_ABSENT }, /* 275 = obsolete netbsd_lchown */
+ { .sy_narg = 0, .sy_call = (sy_call_t *)nosys, .sy_auevent = AUE_NULL, .sy_flags = 0, .sy_thrcnt = SY_THR_ABSENT }, /* 275 = obsolete netbsd_lchown */
{ .sy_narg = AS(freebsd32_lutimes_args), .sy_call = (sy_call_t *)freebsd32_lutimes, .sy_auevent = AUE_LUTIMES, .sy_flags = 0, .sy_thrcnt = SY_THR_STATIC }, /* 276 = freebsd32_lutimes */
- { .sy_narg = 0, .sy_call = (sy_call_t *)nosys, .sy_auevent = AUE_NULL, .sy_flags = 0, .sy_thrcnt = SY_THR_ABSENT }, /* 277 = obsolete netbsd_msync */
+ { .sy_narg = 0, .sy_call = (sy_call_t *)nosys, .sy_auevent = AUE_NULL, .sy_flags = 0, .sy_thrcnt = SY_THR_ABSENT }, /* 277 = obsolete netbsd_msync */
{ compat11(AS(freebsd11_freebsd32_nstat_args),freebsd32_nstat), .sy_auevent = AUE_STAT, .sy_flags = 0, .sy_thrcnt = SY_THR_STATIC }, /* 278 = freebsd11 freebsd32_nstat */
{ compat11(AS(freebsd11_freebsd32_nfstat_args),freebsd32_nfstat), .sy_auevent = AUE_FSTAT, .sy_flags = 0, .sy_thrcnt = SY_THR_STATIC }, /* 279 = freebsd11 freebsd32_nfstat */
{ compat11(AS(freebsd11_freebsd32_nlstat_args),freebsd32_nlstat), .sy_auevent = AUE_LSTAT, .sy_flags = 0, .sy_thrcnt = SY_THR_STATIC }, /* 280 = freebsd11 freebsd32_nlstat */
- { .sy_narg = 0, .sy_call = (sy_call_t *)nosys, .sy_auevent = AUE_NULL, .sy_flags = 0, .sy_thrcnt = SY_THR_ABSENT }, /* 281 = reserved for local use */
- { .sy_narg = 0, .sy_call = (sy_call_t *)nosys, .sy_auevent = AUE_NULL, .sy_flags = 0, .sy_thrcnt = SY_THR_ABSENT }, /* 282 = reserved for local use */
- { .sy_narg = 0, .sy_call = (sy_call_t *)nosys, .sy_auevent = AUE_NULL, .sy_flags = 0, .sy_thrcnt = SY_THR_ABSENT }, /* 283 = reserved for local use */
- { .sy_narg = 0, .sy_call = (sy_call_t *)nosys, .sy_auevent = AUE_NULL, .sy_flags = 0, .sy_thrcnt = SY_THR_ABSENT }, /* 284 = reserved for local use */
- { .sy_narg = 0, .sy_call = (sy_call_t *)nosys, .sy_auevent = AUE_NULL, .sy_flags = 0, .sy_thrcnt = SY_THR_ABSENT }, /* 285 = reserved for local use */
- { .sy_narg = 0, .sy_call = (sy_call_t *)nosys, .sy_auevent = AUE_NULL, .sy_flags = 0, .sy_thrcnt = SY_THR_ABSENT }, /* 286 = reserved for local use */
- { .sy_narg = 0, .sy_call = (sy_call_t *)nosys, .sy_auevent = AUE_NULL, .sy_flags = 0, .sy_thrcnt = SY_THR_ABSENT }, /* 287 = reserved for local use */
- { .sy_narg = 0, .sy_call = (sy_call_t *)nosys, .sy_auevent = AUE_NULL, .sy_flags = 0, .sy_thrcnt = SY_THR_ABSENT }, /* 288 = reserved for local use */
+ { .sy_narg = 0, .sy_call = (sy_call_t *)nosys, .sy_auevent = AUE_NULL, .sy_flags = 0, .sy_thrcnt = SY_THR_ABSENT }, /* 281 = reserved for local use */
+ { .sy_narg = 0, .sy_call = (sy_call_t *)nosys, .sy_auevent = AUE_NULL, .sy_flags = 0, .sy_thrcnt = SY_THR_ABSENT }, /* 282 = reserved for local use */
+ { .sy_narg = 0, .sy_call = (sy_call_t *)nosys, .sy_auevent = AUE_NULL, .sy_flags = 0, .sy_thrcnt = SY_THR_ABSENT }, /* 283 = reserved for local use */
+ { .sy_narg = 0, .sy_call = (sy_call_t *)nosys, .sy_auevent = AUE_NULL, .sy_flags = 0, .sy_thrcnt = SY_THR_ABSENT }, /* 284 = reserved for local use */
+ { .sy_narg = 0, .sy_call = (sy_call_t *)nosys, .sy_auevent = AUE_NULL, .sy_flags = 0, .sy_thrcnt = SY_THR_ABSENT }, /* 285 = reserved for local use */
+ { .sy_narg = 0, .sy_call = (sy_call_t *)nosys, .sy_auevent = AUE_NULL, .sy_flags = 0, .sy_thrcnt = SY_THR_ABSENT }, /* 286 = reserved for local use */
+ { .sy_narg = 0, .sy_call = (sy_call_t *)nosys, .sy_auevent = AUE_NULL, .sy_flags = 0, .sy_thrcnt = SY_THR_ABSENT }, /* 287 = reserved for local use */
+ { .sy_narg = 0, .sy_call = (sy_call_t *)nosys, .sy_auevent = AUE_NULL, .sy_flags = 0, .sy_thrcnt = SY_THR_ABSENT }, /* 288 = reserved for local use */
{ .sy_narg = AS(freebsd32_preadv_args), .sy_call = (sy_call_t *)freebsd32_preadv, .sy_auevent = AUE_PREADV, .sy_flags = SYF_CAPENABLED, .sy_thrcnt = SY_THR_STATIC }, /* 289 = freebsd32_preadv */
{ .sy_narg = AS(freebsd32_pwritev_args), .sy_call = (sy_call_t *)freebsd32_pwritev, .sy_auevent = AUE_PWRITEV, .sy_flags = SYF_CAPENABLED, .sy_thrcnt = SY_THR_STATIC }, /* 290 = freebsd32_pwritev */
- { .sy_narg = 0, .sy_call = (sy_call_t *)nosys, .sy_auevent = AUE_NULL, .sy_flags = 0, .sy_thrcnt = SY_THR_ABSENT }, /* 291 = reserved for local use */
- { .sy_narg = 0, .sy_call = (sy_call_t *)nosys, .sy_auevent = AUE_NULL, .sy_flags = 0, .sy_thrcnt = SY_THR_ABSENT }, /* 292 = reserved for local use */
- { .sy_narg = 0, .sy_call = (sy_call_t *)nosys, .sy_auevent = AUE_NULL, .sy_flags = 0, .sy_thrcnt = SY_THR_ABSENT }, /* 293 = reserved for local use */
- { .sy_narg = 0, .sy_call = (sy_call_t *)nosys, .sy_auevent = AUE_NULL, .sy_flags = 0, .sy_thrcnt = SY_THR_ABSENT }, /* 294 = reserved for local use */
- { .sy_narg = 0, .sy_call = (sy_call_t *)nosys, .sy_auevent = AUE_NULL, .sy_flags = 0, .sy_thrcnt = SY_THR_ABSENT }, /* 295 = reserved for local use */
- { .sy_narg = 0, .sy_call = (sy_call_t *)nosys, .sy_auevent = AUE_NULL, .sy_flags = 0, .sy_thrcnt = SY_THR_ABSENT }, /* 296 = reserved for local use */
+ { .sy_narg = 0, .sy_call = (sy_call_t *)nosys, .sy_auevent = AUE_NULL, .sy_flags = 0, .sy_thrcnt = SY_THR_ABSENT }, /* 291 = reserved for local use */
+ { .sy_narg = 0, .sy_call = (sy_call_t *)nosys, .sy_auevent = AUE_NULL, .sy_flags = 0, .sy_thrcnt = SY_THR_ABSENT }, /* 292 = reserved for local use */
+ { .sy_narg = 0, .sy_call = (sy_call_t *)nosys, .sy_auevent = AUE_NULL, .sy_flags = 0, .sy_thrcnt = SY_THR_ABSENT }, /* 293 = reserved for local use */
+ { .sy_narg = 0, .sy_call = (sy_call_t *)nosys, .sy_auevent = AUE_NULL, .sy_flags = 0, .sy_thrcnt = SY_THR_ABSENT }, /* 294 = reserved for local use */
+ { .sy_narg = 0, .sy_call = (sy_call_t *)nosys, .sy_auevent = AUE_NULL, .sy_flags = 0, .sy_thrcnt = SY_THR_ABSENT }, /* 295 = reserved for local use */
+ { .sy_narg = 0, .sy_call = (sy_call_t *)nosys, .sy_auevent = AUE_NULL, .sy_flags = 0, .sy_thrcnt = SY_THR_ABSENT }, /* 296 = reserved for local use */
{ compat4(AS(freebsd4_freebsd32_fhstatfs_args),freebsd32_fhstatfs), .sy_auevent = AUE_FHSTATFS, .sy_flags = 0, .sy_thrcnt = SY_THR_STATIC }, /* 297 = freebsd4 freebsd32_fhstatfs */
{ .sy_narg = AS(fhopen_args), .sy_call = (sy_call_t *)sys_fhopen, .sy_auevent = AUE_FHOPEN, .sy_flags = 0, .sy_thrcnt = SY_THR_STATIC }, /* 298 = fhopen */
{ compat11(AS(freebsd11_freebsd32_fhstat_args),freebsd32_fhstat), .sy_auevent = AUE_FHSTAT, .sy_flags = 0, .sy_thrcnt = SY_THR_STATIC }, /* 299 = freebsd11 freebsd32_fhstat */
@@ -369,7 +380,7 @@ struct sysent freebsd32_sysent[] = {
{ .sy_narg = AS(getsid_args), .sy_call = (sy_call_t *)sys_getsid, .sy_auevent = AUE_GETSID, .sy_flags = SYF_CAPENABLED, .sy_thrcnt = SY_THR_STATIC }, /* 310 = getsid */
{ .sy_narg = AS(setresuid_args), .sy_call = (sy_call_t *)sys_setresuid, .sy_auevent = AUE_SETRESUID, .sy_flags = SYF_CAPENABLED, .sy_thrcnt = SY_THR_STATIC }, /* 311 = setresuid */
{ .sy_narg = AS(setresgid_args), .sy_call = (sy_call_t *)sys_setresgid, .sy_auevent = AUE_SETRESGID, .sy_flags = SYF_CAPENABLED, .sy_thrcnt = SY_THR_STATIC }, /* 312 = setresgid */
- { .sy_narg = 0, .sy_call = (sy_call_t *)nosys, .sy_auevent = AUE_NULL, .sy_flags = 0, .sy_thrcnt = SY_THR_ABSENT }, /* 313 = obsolete signanosleep */
+ { .sy_narg = 0, .sy_call = (sy_call_t *)nosys, .sy_auevent = AUE_NULL, .sy_flags = 0, .sy_thrcnt = SY_THR_ABSENT }, /* 313 = obsolete signanosleep */
{ .sy_narg = AS(freebsd32_aio_return_args), .sy_call = (sy_call_t *)freebsd32_aio_return, .sy_auevent = AUE_AIO_RETURN, .sy_flags = SYF_CAPENABLED, .sy_thrcnt = SY_THR_STATIC }, /* 314 = freebsd32_aio_return */
{ .sy_narg = AS(freebsd32_aio_suspend_args), .sy_call = (sy_call_t *)freebsd32_aio_suspend, .sy_auevent = AUE_AIO_SUSPEND, .sy_flags = SYF_CAPENABLED, .sy_thrcnt = SY_THR_STATIC }, /* 315 = freebsd32_aio_suspend */
{ .sy_narg = AS(aio_cancel_args), .sy_call = (sy_call_t *)sys_aio_cancel, .sy_auevent = AUE_AIO_CANCEL, .sy_flags = SYF_CAPENABLED, .sy_thrcnt = SY_THR_STATIC }, /* 316 = aio_cancel */
@@ -378,8 +389,8 @@ struct sysent freebsd32_sysent[] = {
{ compat6(AS(freebsd6_freebsd32_aio_write_args),freebsd32_aio_write), .sy_auevent = AUE_AIO_WRITE, .sy_flags = SYF_CAPENABLED, .sy_thrcnt = SY_THR_STATIC }, /* 319 = freebsd6 freebsd32_aio_write */
{ compat6(AS(freebsd6_freebsd32_lio_listio_args),freebsd32_lio_listio), .sy_auevent = AUE_LIO_LISTIO, .sy_flags = SYF_CAPENABLED, .sy_thrcnt = SY_THR_STATIC }, /* 320 = freebsd6 freebsd32_lio_listio */
{ .sy_narg = 0, .sy_call = (sy_call_t *)sys_yield, .sy_auevent = AUE_NULL, .sy_flags = SYF_CAPENABLED, .sy_thrcnt = SY_THR_STATIC }, /* 321 = yield */
- { .sy_narg = 0, .sy_call = (sy_call_t *)nosys, .sy_auevent = AUE_NULL, .sy_flags = 0, .sy_thrcnt = SY_THR_ABSENT }, /* 322 = obsolete thr_sleep */
- { .sy_narg = 0, .sy_call = (sy_call_t *)nosys, .sy_auevent = AUE_NULL, .sy_flags = 0, .sy_thrcnt = SY_THR_ABSENT }, /* 323 = obsolete thr_wakeup */
+ { .sy_narg = 0, .sy_call = (sy_call_t *)nosys, .sy_auevent = AUE_NULL, .sy_flags = 0, .sy_thrcnt = SY_THR_ABSENT }, /* 322 = obsolete thr_sleep */
+ { .sy_narg = 0, .sy_call = (sy_call_t *)nosys, .sy_auevent = AUE_NULL, .sy_flags = 0, .sy_thrcnt = SY_THR_ABSENT }, /* 323 = obsolete thr_wakeup */
{ .sy_narg = AS(mlockall_args), .sy_call = (sy_call_t *)sys_mlockall, .sy_auevent = AUE_MLOCKALL, .sy_flags = SYF_CAPENABLED, .sy_thrcnt = SY_THR_STATIC }, /* 324 = mlockall */
{ .sy_narg = 0, .sy_call = (sy_call_t *)sys_munlockall, .sy_auevent = AUE_MUNLOCKALL, .sy_flags = SYF_CAPENABLED, .sy_thrcnt = SY_THR_STATIC }, /* 325 = munlockall */
{ .sy_narg = AS(__getcwd_args), .sy_call = (sy_call_t *)sys___getcwd, .sy_auevent = AUE_GETCWD, .sy_flags = 0, .sy_thrcnt = SY_THR_STATIC }, /* 326 = __getcwd */
@@ -393,9 +404,9 @@ struct sysent freebsd32_sysent[] = {
{ .sy_narg = AS(freebsd32_sched_rr_get_interval_args), .sy_call = (sy_call_t *)freebsd32_sched_rr_get_interval, .sy_auevent = AUE_NULL, .sy_flags = SYF_CAPENABLED, .sy_thrcnt = SY_THR_STATIC }, /* 334 = freebsd32_sched_rr_get_interval */
{ .sy_narg = AS(utrace_args), .sy_call = (sy_call_t *)sys_utrace, .sy_auevent = AUE_NULL, .sy_flags = SYF_CAPENABLED, .sy_thrcnt = SY_THR_STATIC }, /* 335 = utrace */
{ compat4(AS(freebsd4_freebsd32_sendfile_args),freebsd32_sendfile), .sy_auevent = AUE_SENDFILE, .sy_flags = SYF_CAPENABLED, .sy_thrcnt = SY_THR_STATIC }, /* 336 = freebsd4 freebsd32_sendfile */
- { .sy_narg = 0, .sy_call = (sy_call_t *)nosys, .sy_auevent = AUE_NULL, .sy_flags = 0, .sy_thrcnt = SY_THR_ABSENT }, /* 337 = kldsym */
+ { .sy_narg = 0, .sy_call = (sy_call_t *)nosys, .sy_auevent = AUE_NULL, .sy_flags = 0, .sy_thrcnt = SY_THR_ABSENT }, /* 337 = freebsd32_kldsym */
{ .sy_narg = AS(freebsd32_jail_args), .sy_call = (sy_call_t *)freebsd32_jail, .sy_auevent = AUE_JAIL, .sy_flags = 0, .sy_thrcnt = SY_THR_STATIC }, /* 338 = freebsd32_jail */
- { .sy_narg = 0, .sy_call = (sy_call_t *)nosys, .sy_auevent = AUE_NULL, .sy_flags = 0, .sy_thrcnt = SY_THR_ABSENT }, /* 339 = nnpfs_syscall */
+ { .sy_narg = 0, .sy_call = (sy_call_t *)nosys, .sy_auevent = AUE_NULL, .sy_flags = 0, .sy_thrcnt = SY_THR_ABSENT }, /* 339 = nnpfs_syscall */
{ .sy_narg = AS(sigprocmask_args), .sy_call = (sy_call_t *)sys_sigprocmask, .sy_auevent = AUE_SIGPROCMASK, .sy_flags = SYF_CAPENABLED, .sy_thrcnt = SY_THR_STATIC }, /* 340 = sigprocmask */
{ .sy_narg = AS(sigsuspend_args), .sy_call = (sy_call_t *)sys_sigsuspend, .sy_auevent = AUE_SIGSUSPEND, .sy_flags = SYF_CAPENABLED, .sy_thrcnt = SY_THR_STATIC }, /* 341 = sigsuspend */
{ compat4(AS(freebsd4_freebsd32_sigaction_args),freebsd32_sigaction), .sy_auevent = AUE_SIGACTION, .sy_flags = SYF_CAPENABLED, .sy_thrcnt = SY_THR_STATIC }, /* 342 = freebsd4 freebsd32_sigaction */
@@ -420,42 +431,42 @@ struct sysent freebsd32_sysent[] = {
{ .sy_narg = AS(getresgid_args), .sy_call = (sy_call_t *)sys_getresgid, .sy_auevent = AUE_GETRESGID, .sy_flags = SYF_CAPENABLED, .sy_thrcnt = SY_THR_STATIC }, /* 361 = getresgid */
{ .sy_narg = 0, .sy_call = (sy_call_t *)sys_kqueue, .sy_auevent = AUE_KQUEUE, .sy_flags = SYF_CAPENABLED, .sy_thrcnt = SY_THR_STATIC }, /* 362 = kqueue */
{ compat11(AS(freebsd11_freebsd32_kevent_args),freebsd32_kevent), .sy_auevent = AUE_KEVENT, .sy_flags = SYF_CAPENABLED, .sy_thrcnt = SY_THR_STATIC }, /* 363 = freebsd11 freebsd32_kevent */
- { .sy_narg = 0, .sy_call = (sy_call_t *)nosys, .sy_auevent = AUE_NULL, .sy_flags = 0, .sy_thrcnt = SY_THR_ABSENT }, /* 364 = obsolete __cap_get_proc */
- { .sy_narg = 0, .sy_call = (sy_call_t *)nosys, .sy_auevent = AUE_NULL, .sy_flags = 0, .sy_thrcnt = SY_THR_ABSENT }, /* 365 = obsolete __cap_set_proc */
- { .sy_narg = 0, .sy_call = (sy_call_t *)nosys, .sy_auevent = AUE_NULL, .sy_flags = 0, .sy_thrcnt = SY_THR_ABSENT }, /* 366 = obsolete __cap_get_fd */
- { .sy_narg = 0, .sy_call = (sy_call_t *)nosys, .sy_auevent = AUE_NULL, .sy_flags = 0, .sy_thrcnt = SY_THR_ABSENT }, /* 367 = obsolete __cap_get_file */
- { .sy_narg = 0, .sy_call = (sy_call_t *)nosys, .sy_auevent = AUE_NULL, .sy_flags = 0, .sy_thrcnt = SY_THR_ABSENT }, /* 368 = obsolete __cap_set_fd */
- { .sy_narg = 0, .sy_call = (sy_call_t *)nosys, .sy_auevent = AUE_NULL, .sy_flags = 0, .sy_thrcnt = SY_THR_ABSENT }, /* 369 = obsolete __cap_set_file */
- { .sy_narg = 0, .sy_call = (sy_call_t *)nosys, .sy_auevent = AUE_NULL, .sy_flags = 0, .sy_thrcnt = SY_THR_ABSENT }, /* 370 = reserved for local use */
+ { .sy_narg = 0, .sy_call = (sy_call_t *)nosys, .sy_auevent = AUE_NULL, .sy_flags = 0, .sy_thrcnt = SY_THR_ABSENT }, /* 364 = obsolete __cap_get_proc */
+ { .sy_narg = 0, .sy_call = (sy_call_t *)nosys, .sy_auevent = AUE_NULL, .sy_flags = 0, .sy_thrcnt = SY_THR_ABSENT }, /* 365 = obsolete __cap_set_proc */
+ { .sy_narg = 0, .sy_call = (sy_call_t *)nosys, .sy_auevent = AUE_NULL, .sy_flags = 0, .sy_thrcnt = SY_THR_ABSENT }, /* 366 = obsolete __cap_get_fd */
+ { .sy_narg = 0, .sy_call = (sy_call_t *)nosys, .sy_auevent = AUE_NULL, .sy_flags = 0, .sy_thrcnt = SY_THR_ABSENT }, /* 367 = obsolete __cap_get_file */
+ { .sy_narg = 0, .sy_call = (sy_call_t *)nosys, .sy_auevent = AUE_NULL, .sy_flags = 0, .sy_thrcnt = SY_THR_ABSENT }, /* 368 = obsolete __cap_set_fd */
+ { .sy_narg = 0, .sy_call = (sy_call_t *)nosys, .sy_auevent = AUE_NULL, .sy_flags = 0, .sy_thrcnt = SY_THR_ABSENT }, /* 369 = obsolete __cap_set_file */
+ { .sy_narg = 0, .sy_call = (sy_call_t *)nosys, .sy_auevent = AUE_NULL, .sy_flags = 0, .sy_thrcnt = SY_THR_ABSENT }, /* 370 = reserved for local use */
{ .sy_narg = AS(extattr_set_fd_args), .sy_call = (sy_call_t *)sys_extattr_set_fd, .sy_auevent = AUE_EXTATTR_SET_FD, .sy_flags = SYF_CAPENABLED, .sy_thrcnt = SY_THR_STATIC }, /* 371 = extattr_set_fd */
{ .sy_narg = AS(extattr_get_fd_args), .sy_call = (sy_call_t *)sys_extattr_get_fd, .sy_auevent = AUE_EXTATTR_GET_FD, .sy_flags = SYF_CAPENABLED, .sy_thrcnt = SY_THR_STATIC }, /* 372 = extattr_get_fd */
{ .sy_narg = AS(extattr_delete_fd_args), .sy_call = (sy_call_t *)sys_extattr_delete_fd, .sy_auevent = AUE_EXTATTR_DELETE_FD, .sy_flags = SYF_CAPENABLED, .sy_thrcnt = SY_THR_STATIC }, /* 373 = extattr_delete_fd */
{ .sy_narg = AS(__setugid_args), .sy_call = (sy_call_t *)sys___setugid, .sy_auevent = AUE_SETUGID, .sy_flags = 0, .sy_thrcnt = SY_THR_STATIC }, /* 374 = __setugid */
- { .sy_narg = 0, .sy_call = (sy_call_t *)nosys, .sy_auevent = AUE_NULL, .sy_flags = 0, .sy_thrcnt = SY_THR_ABSENT }, /* 375 = obsolete nfsclnt */
+ { .sy_narg = 0, .sy_call = (sy_call_t *)nosys, .sy_auevent = AUE_NULL, .sy_flags = 0, .sy_thrcnt = SY_THR_ABSENT }, /* 375 = obsolete nfsclnt */
{ .sy_narg = AS(eaccess_args), .sy_call = (sy_call_t *)sys_eaccess, .sy_auevent = AUE_EACCESS, .sy_flags = 0, .sy_thrcnt = SY_THR_STATIC }, /* 376 = eaccess */
- { .sy_narg = 0, .sy_call = (sy_call_t *)nosys, .sy_auevent = AUE_NULL, .sy_flags = 0, .sy_thrcnt = SY_THR_ABSENT }, /* 377 = afs3_syscall */
+ { .sy_narg = 0, .sy_call = (sy_call_t *)nosys, .sy_auevent = AUE_NULL, .sy_flags = 0, .sy_thrcnt = SY_THR_ABSENT }, /* 377 = freebsd32_afs3_syscall */
{ .sy_narg = AS(freebsd32_nmount_args), .sy_call = (sy_call_t *)freebsd32_nmount, .sy_auevent = AUE_NMOUNT, .sy_flags = 0, .sy_thrcnt = SY_THR_STATIC }, /* 378 = freebsd32_nmount */
- { .sy_narg = 0, .sy_call = (sy_call_t *)nosys, .sy_auevent = AUE_NULL, .sy_flags = 0, .sy_thrcnt = SY_THR_ABSENT }, /* 379 = obsolete kse_exit */
- { .sy_narg = 0, .sy_call = (sy_call_t *)nosys, .sy_auevent = AUE_NULL, .sy_flags = 0, .sy_thrcnt = SY_THR_ABSENT }, /* 380 = obsolete kse_wakeup */
- { .sy_narg = 0, .sy_call = (sy_call_t *)nosys, .sy_auevent = AUE_NULL, .sy_flags = 0, .sy_thrcnt = SY_THR_ABSENT }, /* 381 = obsolete kse_create */
- { .sy_narg = 0, .sy_call = (sy_call_t *)nosys, .sy_auevent = AUE_NULL, .sy_flags = 0, .sy_thrcnt = SY_THR_ABSENT }, /* 382 = obsolete kse_thr_interrupt */
- { .sy_narg = 0, .sy_call = (sy_call_t *)nosys, .sy_auevent = AUE_NULL, .sy_flags = 0, .sy_thrcnt = SY_THR_ABSENT }, /* 383 = obsolete kse_release */
- { .sy_narg = 0, .sy_call = (sy_call_t *)nosys, .sy_auevent = AUE_NULL, .sy_flags = 0, .sy_thrcnt = SY_THR_ABSENT }, /* 384 = __mac_get_proc */
- { .sy_narg = 0, .sy_call = (sy_call_t *)nosys, .sy_auevent = AUE_NULL, .sy_flags = 0, .sy_thrcnt = SY_THR_ABSENT }, /* 385 = __mac_set_proc */
- { .sy_narg = 0, .sy_call = (sy_call_t *)nosys, .sy_auevent = AUE_NULL, .sy_flags = 0, .sy_thrcnt = SY_THR_ABSENT }, /* 386 = __mac_get_fd */
- { .sy_narg = 0, .sy_call = (sy_call_t *)nosys, .sy_auevent = AUE_NULL, .sy_flags = 0, .sy_thrcnt = SY_THR_ABSENT }, /* 387 = __mac_get_file */
- { .sy_narg = 0, .sy_call = (sy_call_t *)nosys, .sy_auevent = AUE_NULL, .sy_flags = 0, .sy_thrcnt = SY_THR_ABSENT }, /* 388 = __mac_set_fd */
- { .sy_narg = 0, .sy_call = (sy_call_t *)nosys, .sy_auevent = AUE_NULL, .sy_flags = 0, .sy_thrcnt = SY_THR_ABSENT }, /* 389 = __mac_set_file */
+ { .sy_narg = 0, .sy_call = (sy_call_t *)nosys, .sy_auevent = AUE_NULL, .sy_flags = 0, .sy_thrcnt = SY_THR_ABSENT }, /* 379 = obsolete kse_exit */
+ { .sy_narg = 0, .sy_call = (sy_call_t *)nosys, .sy_auevent = AUE_NULL, .sy_flags = 0, .sy_thrcnt = SY_THR_ABSENT }, /* 380 = obsolete kse_wakeup */
+ { .sy_narg = 0, .sy_call = (sy_call_t *)nosys, .sy_auevent = AUE_NULL, .sy_flags = 0, .sy_thrcnt = SY_THR_ABSENT }, /* 381 = obsolete kse_create */
+ { .sy_narg = 0, .sy_call = (sy_call_t *)nosys, .sy_auevent = AUE_NULL, .sy_flags = 0, .sy_thrcnt = SY_THR_ABSENT }, /* 382 = obsolete kse_thr_interrupt */
+ { .sy_narg = 0, .sy_call = (sy_call_t *)nosys, .sy_auevent = AUE_NULL, .sy_flags = 0, .sy_thrcnt = SY_THR_ABSENT }, /* 383 = obsolete kse_release */
+ { .sy_narg = 0, .sy_call = (sy_call_t *)nosys, .sy_auevent = AUE_NULL, .sy_flags = 0, .sy_thrcnt = SY_THR_ABSENT }, /* 384 = freebsd32___mac_get_proc */
+ { .sy_narg = 0, .sy_call = (sy_call_t *)nosys, .sy_auevent = AUE_NULL, .sy_flags = 0, .sy_thrcnt = SY_THR_ABSENT }, /* 385 = freebsd32___mac_set_proc */
+ { .sy_narg = 0, .sy_call = (sy_call_t *)nosys, .sy_auevent = AUE_NULL, .sy_flags = 0, .sy_thrcnt = SY_THR_ABSENT }, /* 386 = freebsd32___mac_get_fd */
+ { .sy_narg = 0, .sy_call = (sy_call_t *)nosys, .sy_auevent = AUE_NULL, .sy_flags = 0, .sy_thrcnt = SY_THR_ABSENT }, /* 387 = freebsd32___mac_get_file */
+ { .sy_narg = 0, .sy_call = (sy_call_t *)nosys, .sy_auevent = AUE_NULL, .sy_flags = 0, .sy_thrcnt = SY_THR_ABSENT }, /* 388 = freebsd32___mac_set_fd */
+ { .sy_narg = 0, .sy_call = (sy_call_t *)nosys, .sy_auevent = AUE_NULL, .sy_flags = 0, .sy_thrcnt = SY_THR_ABSENT }, /* 389 = freebsd32___mac_set_file */
{ .sy_narg = AS(kenv_args), .sy_call = (sy_call_t *)sys_kenv, .sy_auevent = AUE_NULL, .sy_flags = 0, .sy_thrcnt = SY_THR_STATIC }, /* 390 = kenv */
{ .sy_narg = AS(lchflags_args), .sy_call = (sy_call_t *)sys_lchflags, .sy_auevent = AUE_LCHFLAGS, .sy_flags = 0, .sy_thrcnt = SY_THR_STATIC }, /* 391 = lchflags */
{ .sy_narg = AS(uuidgen_args), .sy_call = (sy_call_t *)sys_uuidgen, .sy_auevent = AUE_NULL, .sy_flags = SYF_CAPENABLED, .sy_thrcnt = SY_THR_STATIC }, /* 392 = uuidgen */
{ .sy_narg = AS(freebsd32_sendfile_args), .sy_call = (sy_call_t *)freebsd32_sendfile, .sy_auevent = AUE_SENDFILE, .sy_flags = SYF_CAPENABLED, .sy_thrcnt = SY_THR_STATIC }, /* 393 = freebsd32_sendfile */
- { .sy_narg = 0, .sy_call = (sy_call_t *)nosys, .sy_auevent = AUE_NULL, .sy_flags = 0, .sy_thrcnt = SY_THR_ABSENT }, /* 394 = mac_syscall */
+ { .sy_narg = AS(mac_syscall_args), .sy_call = (sy_call_t *)sys_mac_syscall, .sy_auevent = AUE_NULL, .sy_flags = 0, .sy_thrcnt = SY_THR_STATIC }, /* 394 = mac_syscall */
{ compat11(AS(freebsd11_freebsd32_getfsstat_args),freebsd32_getfsstat), .sy_auevent = AUE_GETFSSTAT, .sy_flags = 0, .sy_thrcnt = SY_THR_STATIC }, /* 395 = freebsd11 freebsd32_getfsstat */
{ compat11(AS(freebsd11_statfs_args),statfs), .sy_auevent = AUE_STATFS, .sy_flags = 0, .sy_thrcnt = SY_THR_STATIC }, /* 396 = freebsd11 statfs */
{ compat11(AS(freebsd11_fstatfs_args),fstatfs), .sy_auevent = AUE_FSTATFS, .sy_flags = SYF_CAPENABLED, .sy_thrcnt = SY_THR_STATIC }, /* 397 = freebsd11 fstatfs */
{ compat11(AS(freebsd11_fhstatfs_args),fhstatfs), .sy_auevent = AUE_FHSTATFS, .sy_flags = 0, .sy_thrcnt = SY_THR_STATIC }, /* 398 = freebsd11 fhstatfs */
- { .sy_narg = 0, .sy_call = (sy_call_t *)nosys, .sy_auevent = AUE_NULL, .sy_flags = 0, .sy_thrcnt = SY_THR_ABSENT }, /* 399 = reserved for local use */
+ { .sy_narg = 0, .sy_call = (sy_call_t *)nosys, .sy_auevent = AUE_NULL, .sy_flags = 0, .sy_thrcnt = SY_THR_ABSENT }, /* 399 = reserved for local use */
{ .sy_narg = AS(ksem_close_args), .sy_call = (sy_call_t *)lkmressys, .sy_auevent = AUE_NULL, .sy_flags = 0, .sy_thrcnt = SY_THR_ABSENT }, /* 400 = ksem_close */
{ .sy_narg = AS(ksem_post_args), .sy_call = (sy_call_t *)lkmressys, .sy_auevent = AUE_NULL, .sy_flags = 0, .sy_thrcnt = SY_THR_ABSENT }, /* 401 = ksem_post */
{ .sy_narg = AS(ksem_wait_args), .sy_call = (sy_call_t *)lkmressys, .sy_auevent = AUE_NULL, .sy_flags = 0, .sy_thrcnt = SY_THR_ABSENT }, /* 402 = ksem_wait */
@@ -465,28 +476,28 @@ struct sysent freebsd32_sysent[] = {
{ .sy_narg = AS(ksem_unlink_args), .sy_call = (sy_call_t *)lkmressys, .sy_auevent = AUE_NULL, .sy_flags = 0, .sy_thrcnt = SY_THR_ABSENT }, /* 406 = ksem_unlink */
{ .sy_narg = AS(ksem_getvalue_args), .sy_call = (sy_call_t *)lkmressys, .sy_auevent = AUE_NULL, .sy_flags = 0, .sy_thrcnt = SY_THR_ABSENT }, /* 407 = ksem_getvalue */
{ .sy_narg = AS(ksem_destroy_args), .sy_call = (sy_call_t *)lkmressys, .sy_auevent = AUE_NULL, .sy_flags = 0, .sy_thrcnt = SY_THR_ABSENT }, /* 408 = ksem_destroy */
- { .sy_narg = 0, .sy_call = (sy_call_t *)nosys, .sy_auevent = AUE_NULL, .sy_flags = 0, .sy_thrcnt = SY_THR_ABSENT }, /* 409 = __mac_get_pid */
- { .sy_narg = 0, .sy_call = (sy_call_t *)nosys, .sy_auevent = AUE_NULL, .sy_flags = 0, .sy_thrcnt = SY_THR_ABSENT }, /* 410 = __mac_get_link */
- { .sy_narg = 0, .sy_call = (sy_call_t *)nosys, .sy_auevent = AUE_NULL, .sy_flags = 0, .sy_thrcnt = SY_THR_ABSENT }, /* 411 = __mac_set_link */
+ { .sy_narg = 0, .sy_call = (sy_call_t *)nosys, .sy_auevent = AUE_NULL, .sy_flags = 0, .sy_thrcnt = SY_THR_ABSENT }, /* 409 = freebsd32___mac_get_pid */
+ { .sy_narg = 0, .sy_call = (sy_call_t *)nosys, .sy_auevent = AUE_NULL, .sy_flags = 0, .sy_thrcnt = SY_THR_ABSENT }, /* 410 = freebsd32___mac_get_link */
+ { .sy_narg = 0, .sy_call = (sy_call_t *)nosys, .sy_auevent = AUE_NULL, .sy_flags = 0, .sy_thrcnt = SY_THR_ABSENT }, /* 411 = freebsd32___mac_set_link */
{ .sy_narg = AS(extattr_set_link_args), .sy_call = (sy_call_t *)sys_extattr_set_link, .sy_auevent = AUE_EXTATTR_SET_LINK, .sy_flags = 0, .sy_thrcnt = SY_THR_STATIC }, /* 412 = extattr_set_link */
{ .sy_narg = AS(extattr_get_link_args), .sy_call = (sy_call_t *)sys_extattr_get_link, .sy_auevent = AUE_EXTATTR_GET_LINK, .sy_flags = 0, .sy_thrcnt = SY_THR_STATIC }, /* 413 = extattr_get_link */
{ .sy_narg = AS(extattr_delete_link_args), .sy_call = (sy_call_t *)sys_extattr_delete_link, .sy_auevent = AUE_EXTATTR_DELETE_LINK, .sy_flags = 0, .sy_thrcnt = SY_THR_STATIC }, /* 414 = extattr_delete_link */
- { .sy_narg = 0, .sy_call = (sy_call_t *)nosys, .sy_auevent = AUE_NULL, .sy_flags = 0, .sy_thrcnt = SY_THR_ABSENT }, /* 415 = __mac_execve */
+ { .sy_narg = 0, .sy_call = (sy_call_t *)nosys, .sy_auevent = AUE_NULL, .sy_flags = 0, .sy_thrcnt = SY_THR_ABSENT }, /* 415 = freebsd32___mac_execve */
{ .sy_narg = AS(freebsd32_sigaction_args), .sy_call = (sy_call_t *)freebsd32_sigaction, .sy_auevent = AUE_SIGACTION, .sy_flags = SYF_CAPENABLED, .sy_thrcnt = SY_THR_STATIC }, /* 416 = freebsd32_sigaction */
{ .sy_narg = AS(freebsd32_sigreturn_args), .sy_call = (sy_call_t *)freebsd32_sigreturn, .sy_auevent = AUE_SIGRETURN, .sy_flags = SYF_CAPENABLED, .sy_thrcnt = SY_THR_STATIC }, /* 417 = freebsd32_sigreturn */
- { .sy_narg = 0, .sy_call = (sy_call_t *)nosys, .sy_auevent = AUE_NULL, .sy_flags = 0, .sy_thrcnt = SY_THR_ABSENT }, /* 418 = reserved for local use */
- { .sy_narg = 0, .sy_call = (sy_call_t *)nosys, .sy_auevent = AUE_NULL, .sy_flags = 0, .sy_thrcnt = SY_THR_ABSENT }, /* 419 = reserved for local use */
- { .sy_narg = 0, .sy_call = (sy_call_t *)nosys, .sy_auevent = AUE_NULL, .sy_flags = 0, .sy_thrcnt = SY_THR_ABSENT }, /* 420 = reserved for local use */
+ { .sy_narg = 0, .sy_call = (sy_call_t *)nosys, .sy_auevent = AUE_NULL, .sy_flags = 0, .sy_thrcnt = SY_THR_ABSENT }, /* 418 = reserved for local use */
+ { .sy_narg = 0, .sy_call = (sy_call_t *)nosys, .sy_auevent = AUE_NULL, .sy_flags = 0, .sy_thrcnt = SY_THR_ABSENT }, /* 419 = reserved for local use */
+ { .sy_narg = 0, .sy_call = (sy_call_t *)nosys, .sy_auevent = AUE_NULL, .sy_flags = 0, .sy_thrcnt = SY_THR_ABSENT }, /* 420 = reserved for local use */
{ .sy_narg = AS(freebsd32_getcontext_args), .sy_call = (sy_call_t *)freebsd32_getcontext, .sy_auevent = AUE_NULL, .sy_flags = SYF_CAPENABLED, .sy_thrcnt = SY_THR_STATIC }, /* 421 = freebsd32_getcontext */
{ .sy_narg = AS(freebsd32_setcontext_args), .sy_call = (sy_call_t *)freebsd32_setcontext, .sy_auevent = AUE_NULL, .sy_flags = SYF_CAPENABLED, .sy_thrcnt = SY_THR_STATIC }, /* 422 = freebsd32_setcontext */
{ .sy_narg = AS(freebsd32_swapcontext_args), .sy_call = (sy_call_t *)freebsd32_swapcontext, .sy_auevent = AUE_NULL, .sy_flags = 0, .sy_thrcnt = SY_THR_STATIC }, /* 423 = freebsd32_swapcontext */
- { .sy_narg = AS(swapoff_args), .sy_call = (sy_call_t *)sys_swapoff, .sy_auevent = AUE_SWAPOFF, .sy_flags = 0, .sy_thrcnt = SY_THR_STATIC }, /* 424 = swapoff */
+ { compat13(AS(freebsd13_swapoff_args),swapoff), .sy_auevent = AUE_SWAPOFF, .sy_flags = 0, .sy_thrcnt = SY_THR_STATIC }, /* 424 = freebsd13 swapoff */
{ .sy_narg = AS(__acl_get_link_args), .sy_call = (sy_call_t *)sys___acl_get_link, .sy_auevent = AUE_ACL_GET_LINK, .sy_flags = 0, .sy_thrcnt = SY_THR_STATIC }, /* 425 = __acl_get_link */
{ .sy_narg = AS(__acl_set_link_args), .sy_call = (sy_call_t *)sys___acl_set_link, .sy_auevent = AUE_ACL_SET_LINK, .sy_flags = 0, .sy_thrcnt = SY_THR_STATIC }, /* 426 = __acl_set_link */
{ .sy_narg = AS(__acl_delete_link_args), .sy_call = (sy_call_t *)sys___acl_delete_link, .sy_auevent = AUE_ACL_DELETE_LINK, .sy_flags = 0, .sy_thrcnt = SY_THR_STATIC }, /* 427 = __acl_delete_link */
{ .sy_narg = AS(__acl_aclcheck_link_args), .sy_call = (sy_call_t *)sys___acl_aclcheck_link, .sy_auevent = AUE_ACL_CHECK_LINK, .sy_flags = 0, .sy_thrcnt = SY_THR_STATIC }, /* 428 = __acl_aclcheck_link */
{ .sy_narg = AS(sigwait_args), .sy_call = (sy_call_t *)sys_sigwait, .sy_auevent = AUE_SIGWAIT, .sy_flags = SYF_CAPENABLED, .sy_thrcnt = SY_THR_STATIC }, /* 429 = sigwait */
- { .sy_narg = 0, .sy_call = (sy_call_t *)nosys, .sy_auevent = AUE_NULL, .sy_flags = 0, .sy_thrcnt = SY_THR_ABSENT }, /* 430 = thr_create */
+ { .sy_narg = 0, .sy_call = (sy_call_t *)nosys, .sy_auevent = AUE_NULL, .sy_flags = 0, .sy_thrcnt = SY_THR_ABSENT }, /* 430 = freebsd32_thr_create */
{ .sy_narg = AS(thr_exit_args), .sy_call = (sy_call_t *)sys_thr_exit, .sy_auevent = AUE_THR_EXIT, .sy_flags = SYF_CAPENABLED, .sy_thrcnt = SY_THR_STATIC }, /* 431 = thr_exit */
{ .sy_narg = AS(thr_self_args), .sy_call = (sy_call_t *)sys_thr_self, .sy_auevent = AUE_NULL, .sy_flags = SYF_CAPENABLED, .sy_thrcnt = SY_THR_STATIC }, /* 432 = thr_self */
{ .sy_narg = AS(thr_kill_args), .sy_call = (sy_call_t *)sys_thr_kill, .sy_auevent = AUE_THR_KILL, .sy_flags = SYF_CAPENABLED, .sy_thrcnt = SY_THR_STATIC }, /* 433 = thr_kill */
@@ -496,7 +507,7 @@ struct sysent freebsd32_sysent[] = {
{ .sy_narg = AS(extattr_list_fd_args), .sy_call = (sy_call_t *)sys_extattr_list_fd, .sy_auevent = AUE_EXTATTR_LIST_FD, .sy_flags = SYF_CAPENABLED, .sy_thrcnt = SY_THR_STATIC }, /* 437 = extattr_list_fd */
{ .sy_narg = AS(extattr_list_file_args), .sy_call = (sy_call_t *)sys_extattr_list_file, .sy_auevent = AUE_EXTATTR_LIST_FILE, .sy_flags = 0, .sy_thrcnt = SY_THR_STATIC }, /* 438 = extattr_list_file */
{ .sy_narg = AS(extattr_list_link_args), .sy_call = (sy_call_t *)sys_extattr_list_link, .sy_auevent = AUE_EXTATTR_LIST_LINK, .sy_flags = 0, .sy_thrcnt = SY_THR_STATIC }, /* 439 = extattr_list_link */
- { .sy_narg = 0, .sy_call = (sy_call_t *)nosys, .sy_auevent = AUE_NULL, .sy_flags = 0, .sy_thrcnt = SY_THR_ABSENT }, /* 440 = obsolete kse_switchin */
+ { .sy_narg = 0, .sy_call = (sy_call_t *)nosys, .sy_auevent = AUE_NULL, .sy_flags = 0, .sy_thrcnt = SY_THR_ABSENT }, /* 440 = obsolete kse_switchin */
{ .sy_narg = AS(freebsd32_ksem_timedwait_args), .sy_call = (sy_call_t *)lkmressys, .sy_auevent = AUE_NULL, .sy_flags = 0, .sy_thrcnt = SY_THR_ABSENT }, /* 441 = freebsd32_ksem_timedwait */
{ .sy_narg = AS(freebsd32_thr_suspend_args), .sy_call = (sy_call_t *)freebsd32_thr_suspend, .sy_auevent = AUE_NULL, .sy_flags = SYF_CAPENABLED, .sy_thrcnt = SY_THR_STATIC }, /* 442 = freebsd32_thr_suspend */
{ .sy_narg = AS(thr_wake_args), .sy_call = (sy_call_t *)sys_thr_wake, .sy_auevent = AUE_NULL, .sy_flags = SYF_CAPENABLED, .sy_thrcnt = SY_THR_STATIC }, /* 443 = thr_wake */
@@ -523,10 +534,10 @@ struct sysent freebsd32_sysent[] = {
{ .sy_narg = AS(thr_set_name_args), .sy_call = (sy_call_t *)sys_thr_set_name, .sy_auevent = AUE_NULL, .sy_flags = SYF_CAPENABLED, .sy_thrcnt = SY_THR_STATIC }, /* 464 = thr_set_name */
{ .sy_narg = AS(freebsd32_aio_fsync_args), .sy_call = (sy_call_t *)freebsd32_aio_fsync, .sy_auevent = AUE_AIO_FSYNC, .sy_flags = SYF_CAPENABLED, .sy_thrcnt = SY_THR_STATIC }, /* 465 = freebsd32_aio_fsync */
{ .sy_narg = AS(rtprio_thread_args), .sy_call = (sy_call_t *)sys_rtprio_thread, .sy_auevent = AUE_RTPRIO, .sy_flags = SYF_CAPENABLED, .sy_thrcnt = SY_THR_STATIC }, /* 466 = rtprio_thread */
- { .sy_narg = 0, .sy_call = (sy_call_t *)nosys, .sy_auevent = AUE_NULL, .sy_flags = 0, .sy_thrcnt = SY_THR_ABSENT }, /* 467 = reserved for local use */
- { .sy_narg = 0, .sy_call = (sy_call_t *)nosys, .sy_auevent = AUE_NULL, .sy_flags = 0, .sy_thrcnt = SY_THR_ABSENT }, /* 468 = reserved for local use */
- { .sy_narg = 0, .sy_call = (sy_call_t *)nosys, .sy_auevent = AUE_NULL, .sy_flags = 0, .sy_thrcnt = SY_THR_ABSENT }, /* 469 = reserved for local use */
- { .sy_narg = 0, .sy_call = (sy_call_t *)nosys, .sy_auevent = AUE_NULL, .sy_flags = 0, .sy_thrcnt = SY_THR_ABSENT }, /* 470 = reserved for local use */
+ { .sy_narg = 0, .sy_call = (sy_call_t *)nosys, .sy_auevent = AUE_NULL, .sy_flags = 0, .sy_thrcnt = SY_THR_ABSENT }, /* 467 = reserved for local use */
+ { .sy_narg = 0, .sy_call = (sy_call_t *)nosys, .sy_auevent = AUE_NULL, .sy_flags = 0, .sy_thrcnt = SY_THR_ABSENT }, /* 468 = reserved for local use */
+ { .sy_narg = 0, .sy_call = (sy_call_t *)nosys, .sy_auevent = AUE_NULL, .sy_flags = 0, .sy_thrcnt = SY_THR_ABSENT }, /* 469 = reserved for local use */
+ { .sy_narg = 0, .sy_call = (sy_call_t *)nosys, .sy_auevent = AUE_NULL, .sy_flags = 0, .sy_thrcnt = SY_THR_ABSENT }, /* 470 = reserved for local use */
{ .sy_narg = AS(sctp_peeloff_args), .sy_call = (sy_call_t *)lkmressys, .sy_auevent = AUE_NULL, .sy_flags = SYF_CAPENABLED, .sy_thrcnt = SY_THR_ABSENT }, /* 471 = sctp_peeloff */
{ .sy_narg = AS(sctp_generic_sendmsg_args), .sy_call = (sy_call_t *)lkmressys, .sy_auevent = AUE_NULL, .sy_flags = SYF_CAPENABLED, .sy_thrcnt = SY_THR_ABSENT }, /* 472 = sctp_generic_sendmsg */
{ .sy_narg = AS(sctp_generic_sendmsg_iov_args), .sy_call = (sy_call_t *)lkmressys, .sy_auevent = AUE_NULL, .sy_flags = SYF_CAPENABLED, .sy_thrcnt = SY_THR_ABSENT }, /* 473 = sctp_generic_sendmsg_iov */
@@ -561,7 +572,7 @@ struct sysent freebsd32_sysent[] = {
{ .sy_narg = AS(symlinkat_args), .sy_call = (sy_call_t *)sys_symlinkat, .sy_auevent = AUE_SYMLINKAT, .sy_flags = SYF_CAPENABLED, .sy_thrcnt = SY_THR_STATIC }, /* 502 = symlinkat */
{ .sy_narg = AS(unlinkat_args), .sy_call = (sy_call_t *)sys_unlinkat, .sy_auevent = AUE_UNLINKAT, .sy_flags = SYF_CAPENABLED, .sy_thrcnt = SY_THR_STATIC }, /* 503 = unlinkat */
{ .sy_narg = AS(posix_openpt_args), .sy_call = (sy_call_t *)sys_posix_openpt, .sy_auevent = AUE_POSIX_OPENPT, .sy_flags = 0, .sy_thrcnt = SY_THR_STATIC }, /* 504 = posix_openpt */
- { .sy_narg = AS(gssd_syscall_args), .sy_call = (sy_call_t *)lkmressys, .sy_auevent = AUE_NULL, .sy_flags = 0, .sy_thrcnt = SY_THR_ABSENT }, /* 505 = gssd_syscall */
+ { .sy_narg = 0, .sy_call = (sy_call_t *)nosys, .sy_auevent = AUE_NULL, .sy_flags = 0, .sy_thrcnt = SY_THR_ABSENT }, /* 505 = obsolete kgssapi */
{ .sy_narg = AS(freebsd32_jail_get_args), .sy_call = (sy_call_t *)freebsd32_jail_get, .sy_auevent = AUE_JAIL_GET, .sy_flags = 0, .sy_thrcnt = SY_THR_STATIC }, /* 506 = freebsd32_jail_get */
{ .sy_narg = AS(freebsd32_jail_set_args), .sy_call = (sy_call_t *)freebsd32_jail_set, .sy_auevent = AUE_JAIL_SET, .sy_flags = 0, .sy_thrcnt = SY_THR_STATIC }, /* 507 = freebsd32_jail_set */
{ .sy_narg = AS(jail_remove_args), .sy_call = (sy_call_t *)sys_jail_remove, .sy_auevent = AUE_JAIL_REMOVE, .sy_flags = 0, .sy_thrcnt = SY_THR_STATIC }, /* 508 = jail_remove */
@@ -570,14 +581,14 @@ struct sysent freebsd32_sysent[] = {
{ .sy_narg = AS(freebsd32_msgctl_args), .sy_call = (sy_call_t *)lkmressys, .sy_auevent = AUE_NULL, .sy_flags = 0, .sy_thrcnt = SY_THR_ABSENT }, /* 511 = freebsd32_msgctl */
{ .sy_narg = AS(freebsd32_shmctl_args), .sy_call = (sy_call_t *)lkmressys, .sy_auevent = AUE_NULL, .sy_flags = 0, .sy_thrcnt = SY_THR_ABSENT }, /* 512 = freebsd32_shmctl */
{ .sy_narg = AS(lpathconf_args), .sy_call = (sy_call_t *)sys_lpathconf, .sy_auevent = AUE_LPATHCONF, .sy_flags = 0, .sy_thrcnt = SY_THR_STATIC }, /* 513 = lpathconf */
- { .sy_narg = 0, .sy_call = (sy_call_t *)nosys, .sy_auevent = AUE_NULL, .sy_flags = 0, .sy_thrcnt = SY_THR_ABSENT }, /* 514 = obsolete cap_new */
+ { .sy_narg = 0, .sy_call = (sy_call_t *)nosys, .sy_auevent = AUE_NULL, .sy_flags = 0, .sy_thrcnt = SY_THR_ABSENT }, /* 514 = obsolete cap_new */
{ .sy_narg = AS(__cap_rights_get_args), .sy_call = (sy_call_t *)sys___cap_rights_get, .sy_auevent = AUE_CAP_RIGHTS_GET, .sy_flags = SYF_CAPENABLED, .sy_thrcnt = SY_THR_STATIC }, /* 515 = __cap_rights_get */
{ .sy_narg = 0, .sy_call = (sy_call_t *)sys_cap_enter, .sy_auevent = AUE_CAP_ENTER, .sy_flags = SYF_CAPENABLED, .sy_thrcnt = SY_THR_STATIC }, /* 516 = cap_enter */
{ .sy_narg = AS(cap_getmode_args), .sy_call = (sy_call_t *)sys_cap_getmode, .sy_auevent = AUE_CAP_GETMODE, .sy_flags = SYF_CAPENABLED, .sy_thrcnt = SY_THR_STATIC }, /* 517 = cap_getmode */
{ .sy_narg = AS(pdfork_args), .sy_call = (sy_call_t *)sys_pdfork, .sy_auevent = AUE_PDFORK, .sy_flags = SYF_CAPENABLED, .sy_thrcnt = SY_THR_STATIC }, /* 518 = pdfork */
{ .sy_narg = AS(pdkill_args), .sy_call = (sy_call_t *)sys_pdkill, .sy_auevent = AUE_PDKILL, .sy_flags = SYF_CAPENABLED, .sy_thrcnt = SY_THR_STATIC }, /* 519 = pdkill */
{ .sy_narg = AS(pdgetpid_args), .sy_call = (sy_call_t *)sys_pdgetpid, .sy_auevent = AUE_PDGETPID, .sy_flags = SYF_CAPENABLED, .sy_thrcnt = SY_THR_STATIC }, /* 520 = pdgetpid */
- { .sy_narg = 0, .sy_call = (sy_call_t *)nosys, .sy_auevent = AUE_NULL, .sy_flags = 0, .sy_thrcnt = SY_THR_ABSENT }, /* 521 = reserved for local use */
+ { .sy_narg = 0, .sy_call = (sy_call_t *)nosys, .sy_auevent = AUE_NULL, .sy_flags = 0, .sy_thrcnt = SY_THR_ABSENT }, /* 521 = reserved for local use */
{ .sy_narg = AS(freebsd32_pselect_args), .sy_call = (sy_call_t *)freebsd32_pselect, .sy_auevent = AUE_SELECT, .sy_flags = SYF_CAPENABLED, .sy_thrcnt = SY_THR_STATIC }, /* 522 = freebsd32_pselect */
{ .sy_narg = AS(getloginclass_args), .sy_call = (sy_call_t *)sys_getloginclass, .sy_auevent = AUE_GETLOGINCLASS, .sy_flags = SYF_CAPENABLED, .sy_thrcnt = SY_THR_STATIC }, /* 523 = getloginclass */
{ .sy_narg = AS(setloginclass_args), .sy_call = (sy_call_t *)sys_setloginclass, .sy_auevent = AUE_SETLOGINCLASS, .sy_flags = 0, .sy_thrcnt = SY_THR_STATIC }, /* 524 = setloginclass */
@@ -587,7 +598,7 @@ struct sysent freebsd32_sysent[] = {
{ .sy_narg = AS(rctl_add_rule_args), .sy_call = (sy_call_t *)sys_rctl_add_rule, .sy_auevent = AUE_NULL, .sy_flags = 0, .sy_thrcnt = SY_THR_STATIC }, /* 528 = rctl_add_rule */
{ .sy_narg = AS(rctl_remove_rule_args), .sy_call = (sy_call_t *)sys_rctl_remove_rule, .sy_auevent = AUE_NULL, .sy_flags = 0, .sy_thrcnt = SY_THR_STATIC }, /* 529 = rctl_remove_rule */
{ .sy_narg = AS(freebsd32_posix_fallocate_args), .sy_call = (sy_call_t *)freebsd32_posix_fallocate, .sy_auevent = AUE_POSIX_FALLOCATE, .sy_flags = SYF_CAPENABLED, .sy_thrcnt = SY_THR_STATIC }, /* 530 = freebsd32_posix_fallocate */
- { .sy_narg = AS(freebsd32_posix_fadvise_args), .sy_call = (sy_call_t *)freebsd32_posix_fadvise, .sy_auevent = AUE_POSIX_FADVISE, .sy_flags = 0, .sy_thrcnt = SY_THR_STATIC }, /* 531 = freebsd32_posix_fadvise */
+ { .sy_narg = AS(freebsd32_posix_fadvise_args), .sy_call = (sy_call_t *)freebsd32_posix_fadvise, .sy_auevent = AUE_POSIX_FADVISE, .sy_flags = SYF_CAPENABLED, .sy_thrcnt = SY_THR_STATIC }, /* 531 = freebsd32_posix_fadvise */
{ .sy_narg = AS(freebsd32_wait6_args), .sy_call = (sy_call_t *)freebsd32_wait6, .sy_auevent = AUE_WAIT6, .sy_flags = 0, .sy_thrcnt = SY_THR_STATIC }, /* 532 = freebsd32_wait6 */
{ .sy_narg = AS(cap_rights_limit_args), .sy_call = (sy_call_t *)sys_cap_rights_limit, .sy_auevent = AUE_CAP_RIGHTS_LIMIT, .sy_flags = SYF_CAPENABLED, .sy_thrcnt = SY_THR_STATIC }, /* 533 = cap_rights_limit */
{ .sy_narg = AS(freebsd32_cap_ioctls_limit_args), .sy_call = (sy_call_t *)freebsd32_cap_ioctls_limit, .sy_auevent = AUE_CAP_IOCTLS_LIMIT, .sy_flags = SYF_CAPENABLED, .sy_thrcnt = SY_THR_STATIC }, /* 534 = freebsd32_cap_ioctls_limit */
@@ -604,8 +615,8 @@ struct sysent freebsd32_sysent[] = {
{ .sy_narg = AS(freebsd32_ppoll_args), .sy_call = (sy_call_t *)freebsd32_ppoll, .sy_auevent = AUE_POLL, .sy_flags = SYF_CAPENABLED, .sy_thrcnt = SY_THR_STATIC }, /* 545 = freebsd32_ppoll */
{ .sy_narg = AS(freebsd32_futimens_args), .sy_call = (sy_call_t *)freebsd32_futimens, .sy_auevent = AUE_FUTIMES, .sy_flags = SYF_CAPENABLED, .sy_thrcnt = SY_THR_STATIC }, /* 546 = freebsd32_futimens */
{ .sy_narg = AS(freebsd32_utimensat_args), .sy_call = (sy_call_t *)freebsd32_utimensat, .sy_auevent = AUE_FUTIMESAT, .sy_flags = SYF_CAPENABLED, .sy_thrcnt = SY_THR_STATIC }, /* 547 = freebsd32_utimensat */
- { .sy_narg = 0, .sy_call = (sy_call_t *)nosys, .sy_auevent = AUE_NULL, .sy_flags = 0, .sy_thrcnt = SY_THR_ABSENT }, /* 548 = obsolete numa_getaffinity */
- { .sy_narg = 0, .sy_call = (sy_call_t *)nosys, .sy_auevent = AUE_NULL, .sy_flags = 0, .sy_thrcnt = SY_THR_ABSENT }, /* 549 = obsolete numa_setaffinity */
+ { .sy_narg = 0, .sy_call = (sy_call_t *)nosys, .sy_auevent = AUE_NULL, .sy_flags = 0, .sy_thrcnt = SY_THR_ABSENT }, /* 548 = obsolete numa_getaffinity */
+ { .sy_narg = 0, .sy_call = (sy_call_t *)nosys, .sy_auevent = AUE_NULL, .sy_flags = 0, .sy_thrcnt = SY_THR_ABSENT }, /* 549 = obsolete numa_setaffinity */
{ .sy_narg = AS(fdatasync_args), .sy_call = (sy_call_t *)sys_fdatasync, .sy_auevent = AUE_FSYNC, .sy_flags = SYF_CAPENABLED, .sy_thrcnt = SY_THR_STATIC }, /* 550 = fdatasync */
{ .sy_narg = AS(freebsd32_fstat_args), .sy_call = (sy_call_t *)freebsd32_fstat, .sy_auevent = AUE_FSTAT, .sy_flags = SYF_CAPENABLED, .sy_thrcnt = SY_THR_STATIC }, /* 551 = freebsd32_fstat */
{ .sy_narg = AS(freebsd32_fstatat_args), .sy_call = (sy_call_t *)freebsd32_fstatat, .sy_auevent = AUE_FSTATAT, .sy_flags = SYF_CAPENABLED, .sy_thrcnt = SY_THR_STATIC }, /* 552 = freebsd32_fstatat */
@@ -638,4 +649,21 @@ struct sysent freebsd32_sysent[] = {
{ .sy_narg = AS(freebsd32_aio_readv_args), .sy_call = (sy_call_t *)freebsd32_aio_readv, .sy_auevent = AUE_AIO_READV, .sy_flags = SYF_CAPENABLED, .sy_thrcnt = SY_THR_STATIC }, /* 579 = freebsd32_aio_readv */
{ .sy_narg = AS(fspacectl_args), .sy_call = (sy_call_t *)sys_fspacectl, .sy_auevent = AUE_FSPACECTL, .sy_flags = SYF_CAPENABLED, .sy_thrcnt = SY_THR_STATIC }, /* 580 = fspacectl */
{ .sy_narg = 0, .sy_call = (sy_call_t *)sys_sched_getcpu, .sy_auevent = AUE_NULL, .sy_flags = SYF_CAPENABLED, .sy_thrcnt = SY_THR_STATIC }, /* 581 = sched_getcpu */
+ { .sy_narg = AS(swapoff_args), .sy_call = (sy_call_t *)sys_swapoff, .sy_auevent = AUE_SWAPOFF, .sy_flags = 0, .sy_thrcnt = SY_THR_STATIC }, /* 582 = swapoff */
+ { .sy_narg = AS(kqueuex_args), .sy_call = (sy_call_t *)sys_kqueuex, .sy_auevent = AUE_KQUEUE, .sy_flags = SYF_CAPENABLED, .sy_thrcnt = SY_THR_STATIC }, /* 583 = kqueuex */
+ { .sy_narg = AS(membarrier_args), .sy_call = (sy_call_t *)sys_membarrier, .sy_auevent = AUE_NULL, .sy_flags = SYF_CAPENABLED, .sy_thrcnt = SY_THR_STATIC }, /* 584 = membarrier */
+ { .sy_narg = AS(timerfd_create_args), .sy_call = (sy_call_t *)sys_timerfd_create, .sy_auevent = AUE_TIMERFD, .sy_flags = SYF_CAPENABLED, .sy_thrcnt = SY_THR_STATIC }, /* 585 = timerfd_create */
+ { .sy_narg = AS(freebsd32_timerfd_gettime_args), .sy_call = (sy_call_t *)freebsd32_timerfd_gettime, .sy_auevent = AUE_TIMERFD, .sy_flags = SYF_CAPENABLED, .sy_thrcnt = SY_THR_STATIC }, /* 586 = freebsd32_timerfd_gettime */
+ { .sy_narg = AS(freebsd32_timerfd_settime_args), .sy_call = (sy_call_t *)freebsd32_timerfd_settime, .sy_auevent = AUE_TIMERFD, .sy_flags = SYF_CAPENABLED, .sy_thrcnt = SY_THR_STATIC }, /* 587 = freebsd32_timerfd_settime */
+ { .sy_narg = AS(kcmp_args), .sy_call = (sy_call_t *)sys_kcmp, .sy_auevent = AUE_NULL, .sy_flags = 0, .sy_thrcnt = SY_THR_STATIC }, /* 588 = kcmp */
+ { .sy_narg = AS(getrlimitusage_args), .sy_call = (sy_call_t *)sys_getrlimitusage, .sy_auevent = AUE_NULL, .sy_flags = SYF_CAPENABLED, .sy_thrcnt = SY_THR_STATIC }, /* 589 = getrlimitusage */
+ { .sy_narg = AS(fchroot_args), .sy_call = (sy_call_t *)sys_fchroot, .sy_auevent = AUE_NULL, .sy_flags = 0, .sy_thrcnt = SY_THR_STATIC }, /* 590 = fchroot */
+ { .sy_narg = AS(freebsd32_setcred_args), .sy_call = (sy_call_t *)freebsd32_setcred, .sy_auevent = AUE_SETCRED, .sy_flags = SYF_CAPENABLED, .sy_thrcnt = SY_THR_STATIC }, /* 591 = freebsd32_setcred */
+ { .sy_narg = AS(exterrctl_args), .sy_call = (sy_call_t *)sys_exterrctl, .sy_auevent = AUE_NULL, .sy_flags = SYF_CAPENABLED, .sy_thrcnt = SY_THR_STATIC }, /* 592 = exterrctl */
+ { .sy_narg = AS(inotify_add_watch_at_args), .sy_call = (sy_call_t *)sys_inotify_add_watch_at, .sy_auevent = AUE_INOTIFY, .sy_flags = SYF_CAPENABLED, .sy_thrcnt = SY_THR_STATIC }, /* 593 = inotify_add_watch_at */
+ { .sy_narg = AS(inotify_rm_watch_args), .sy_call = (sy_call_t *)sys_inotify_rm_watch, .sy_auevent = AUE_INOTIFY, .sy_flags = SYF_CAPENABLED, .sy_thrcnt = SY_THR_STATIC }, /* 594 = inotify_rm_watch */
+ { .sy_narg = AS(getgroups_args), .sy_call = (sy_call_t *)sys_getgroups, .sy_auevent = AUE_GETGROUPS, .sy_flags = SYF_CAPENABLED, .sy_thrcnt = SY_THR_STATIC }, /* 595 = getgroups */
+ { .sy_narg = AS(setgroups_args), .sy_call = (sy_call_t *)sys_setgroups, .sy_auevent = AUE_SETGROUPS, .sy_flags = 0, .sy_thrcnt = SY_THR_STATIC }, /* 596 = setgroups */
+ { .sy_narg = AS(jail_attach_jd_args), .sy_call = (sy_call_t *)sys_jail_attach_jd, .sy_auevent = AUE_JAIL_ATTACH, .sy_flags = 0, .sy_thrcnt = SY_THR_STATIC }, /* 597 = jail_attach_jd */
+ { .sy_narg = AS(jail_remove_jd_args), .sy_call = (sy_call_t *)sys_jail_remove_jd, .sy_auevent = AUE_JAIL_REMOVE, .sy_flags = 0, .sy_thrcnt = SY_THR_STATIC }, /* 598 = jail_remove_jd */
};
diff --git a/sys/compat/freebsd32/freebsd32_systrace_args.c b/sys/compat/freebsd32/freebsd32_systrace_args.c
index 4d075ca7470e..29a5497e9efa 100644
--- a/sys/compat/freebsd32/freebsd32_systrace_args.c
+++ b/sys/compat/freebsd32/freebsd32_systrace_args.c
@@ -2,11 +2,11 @@
#define PAD64_REQUIRED
#endif
/*
- * System call argument to DTrace register array converstion.
+ * System call argument to DTrace register array conversion.
*
- * DO NOT EDIT-- this file is automatically @generated.
- * $FreeBSD$
* This file is part of the DTrace syscall provider.
+ *
+ * DO NOT EDIT-- this file is automatically @generated.
*/
static void
@@ -20,9 +20,9 @@ systrace_args(int sysnum, void *params, uint64_t *uarg, int *n_args)
*n_args = 0;
break;
}
- /* exit */
+ /* _exit */
case 1: {
- struct exit_args *p = params;
+ struct _exit_args *p = params;
iarg[a++] = p->rval; /* int */
*n_args = 1;
break;
@@ -422,20 +422,6 @@ systrace_args(int sysnum, void *params, uint64_t *uarg, int *n_args)
*n_args = 0;
break;
}
- /* sbrk */
- case 69: {
- struct sbrk_args *p = params;
- iarg[a++] = p->incr; /* int */
- *n_args = 1;
- break;
- }
- /* sstk */
- case 70: {
- struct sstk_args *p = params;
- iarg[a++] = p->incr; /* int */
- *n_args = 1;
- break;
- }
/* munmap */
case 73: {
struct munmap_args *p = params;
@@ -471,22 +457,6 @@ systrace_args(int sysnum, void *params, uint64_t *uarg, int *n_args)
*n_args = 3;
break;
}
- /* getgroups */
- case 79: {
- struct getgroups_args *p = params;
- iarg[a++] = p->gidsetsize; /* int */
- uarg[a++] = (intptr_t)p->gidset; /* gid_t * */
- *n_args = 2;
- break;
- }
- /* setgroups */
- case 80: {
- struct setgroups_args *p = params;
- iarg[a++] = p->gidsetsize; /* int */
- uarg[a++] = (intptr_t)p->gidset; /* const gid_t * */
- *n_args = 2;
- break;
- }
/* getpgrp */
case 81: {
*n_args = 0;
@@ -542,7 +512,7 @@ systrace_args(int sysnum, void *params, uint64_t *uarg, int *n_args)
struct freebsd32_fcntl_args *p = params;
iarg[a++] = p->fd; /* int */
iarg[a++] = p->cmd; /* int */
- iarg[a++] = p->arg; /* int32_t */
+ uarg[a++] = (intptr_t)p->arg; /* intptr_t */
*n_args = 3;
break;
}
@@ -658,7 +628,7 @@ systrace_args(int sysnum, void *params, uint64_t *uarg, int *n_args)
case 120: {
struct freebsd32_readv_args *p = params;
iarg[a++] = p->fd; /* int */
- uarg[a++] = (intptr_t)p->iovp; /* struct iovec32 * */
+ uarg[a++] = (intptr_t)p->iovp; /* const struct iovec32 * */
uarg[a++] = p->iovcnt; /* u_int */
*n_args = 3;
break;
@@ -667,7 +637,7 @@ systrace_args(int sysnum, void *params, uint64_t *uarg, int *n_args)
case 121: {
struct freebsd32_writev_args *p = params;
iarg[a++] = p->fd; /* int */
- uarg[a++] = (intptr_t)p->iovp; /* struct iovec32 * */
+ uarg[a++] = (intptr_t)p->iovp; /* const struct iovec32 * */
uarg[a++] = p->iovcnt; /* u_int */
*n_args = 3;
break;
@@ -946,7 +916,7 @@ systrace_args(int sysnum, void *params, uint64_t *uarg, int *n_args)
/* freebsd32___sysctl */
case 202: {
struct freebsd32___sysctl_args *p = params;
- uarg[a++] = (intptr_t)p->name; /* int * */
+ uarg[a++] = (intptr_t)p->name; /* const int * */
uarg[a++] = p->namelen; /* u_int */
uarg[a++] = (intptr_t)p->old; /* void * */
uarg[a++] = (intptr_t)p->oldlenp; /* uint32_t * */
@@ -1598,7 +1568,7 @@ systrace_args(int sysnum, void *params, uint64_t *uarg, int *n_args)
case 345: {
struct freebsd32_sigtimedwait_args *p = params;
uarg[a++] = (intptr_t)p->set; /* const sigset_t * */
- uarg[a++] = (intptr_t)p->info; /* struct siginfo32 * */
+ uarg[a++] = (intptr_t)p->info; /* struct __siginfo32 * */
uarg[a++] = (intptr_t)p->timeout; /* const struct timespec32 * */
*n_args = 3;
break;
@@ -1607,7 +1577,7 @@ systrace_args(int sysnum, void *params, uint64_t *uarg, int *n_args)
case 346: {
struct freebsd32_sigwaitinfo_args *p = params;
uarg[a++] = (intptr_t)p->set; /* const sigset_t * */
- uarg[a++] = (intptr_t)p->info; /* struct siginfo32 * */
+ uarg[a++] = (intptr_t)p->info; /* struct __siginfo32 * */
*n_args = 2;
break;
}
@@ -1615,7 +1585,7 @@ systrace_args(int sysnum, void *params, uint64_t *uarg, int *n_args)
case 347: {
struct __acl_get_file_args *p = params;
uarg[a++] = (intptr_t)p->path; /* const char * */
- iarg[a++] = p->type; /* acl_type_t */
+ iarg[a++] = p->type; /* __acl_type_t */
uarg[a++] = (intptr_t)p->aclp; /* struct acl * */
*n_args = 3;
break;
@@ -1624,7 +1594,7 @@ systrace_args(int sysnum, void *params, uint64_t *uarg, int *n_args)
case 348: {
struct __acl_set_file_args *p = params;
uarg[a++] = (intptr_t)p->path; /* const char * */
- iarg[a++] = p->type; /* acl_type_t */
+ iarg[a++] = p->type; /* __acl_type_t */
uarg[a++] = (intptr_t)p->aclp; /* struct acl * */
*n_args = 3;
break;
@@ -1633,7 +1603,7 @@ systrace_args(int sysnum, void *params, uint64_t *uarg, int *n_args)
case 349: {
struct __acl_get_fd_args *p = params;
iarg[a++] = p->filedes; /* int */
- iarg[a++] = p->type; /* acl_type_t */
+ iarg[a++] = p->type; /* __acl_type_t */
uarg[a++] = (intptr_t)p->aclp; /* struct acl * */
*n_args = 3;
break;
@@ -1642,7 +1612,7 @@ systrace_args(int sysnum, void *params, uint64_t *uarg, int *n_args)
case 350: {
struct __acl_set_fd_args *p = params;
iarg[a++] = p->filedes; /* int */
- iarg[a++] = p->type; /* acl_type_t */
+ iarg[a++] = p->type; /* __acl_type_t */
uarg[a++] = (intptr_t)p->aclp; /* struct acl * */
*n_args = 3;
break;
@@ -1651,7 +1621,7 @@ systrace_args(int sysnum, void *params, uint64_t *uarg, int *n_args)
case 351: {
struct __acl_delete_file_args *p = params;
uarg[a++] = (intptr_t)p->path; /* const char * */
- iarg[a++] = p->type; /* acl_type_t */
+ iarg[a++] = p->type; /* __acl_type_t */
*n_args = 2;
break;
}
@@ -1659,7 +1629,7 @@ systrace_args(int sysnum, void *params, uint64_t *uarg, int *n_args)
case 352: {
struct __acl_delete_fd_args *p = params;
iarg[a++] = p->filedes; /* int */
- iarg[a++] = p->type; /* acl_type_t */
+ iarg[a++] = p->type; /* __acl_type_t */
*n_args = 2;
break;
}
@@ -1667,7 +1637,7 @@ systrace_args(int sysnum, void *params, uint64_t *uarg, int *n_args)
case 353: {
struct __acl_aclcheck_file_args *p = params;
uarg[a++] = (intptr_t)p->path; /* const char * */
- iarg[a++] = p->type; /* acl_type_t */
+ iarg[a++] = p->type; /* __acl_type_t */
uarg[a++] = (intptr_t)p->aclp; /* struct acl * */
*n_args = 3;
break;
@@ -1676,7 +1646,7 @@ systrace_args(int sysnum, void *params, uint64_t *uarg, int *n_args)
case 354: {
struct __acl_aclcheck_fd_args *p = params;
iarg[a++] = p->filedes; /* int */
- iarg[a++] = p->type; /* acl_type_t */
+ iarg[a++] = p->type; /* __acl_type_t */
uarg[a++] = (intptr_t)p->aclp; /* struct acl * */
*n_args = 3;
break;
@@ -1849,6 +1819,15 @@ systrace_args(int sysnum, void *params, uint64_t *uarg, int *n_args)
*n_args = 8;
break;
}
+ /* mac_syscall */
+ case 394: {
+ struct mac_syscall_args *p = params;
+ uarg[a++] = (intptr_t)p->policy; /* const char * */
+ iarg[a++] = p->call; /* int */
+ uarg[a++] = (intptr_t)p->arg; /* void * */
+ *n_args = 3;
+ break;
+ }
/* ksem_close */
case 400: {
struct ksem_close_args *p = params;
@@ -1987,18 +1966,11 @@ systrace_args(int sysnum, void *params, uint64_t *uarg, int *n_args)
*n_args = 2;
break;
}
- /* swapoff */
- case 424: {
- struct swapoff_args *p = params;
- uarg[a++] = (intptr_t)p->name; /* const char * */
- *n_args = 1;
- break;
- }
/* __acl_get_link */
case 425: {
struct __acl_get_link_args *p = params;
uarg[a++] = (intptr_t)p->path; /* const char * */
- iarg[a++] = p->type; /* acl_type_t */
+ iarg[a++] = p->type; /* __acl_type_t */
uarg[a++] = (intptr_t)p->aclp; /* struct acl * */
*n_args = 3;
break;
@@ -2007,7 +1979,7 @@ systrace_args(int sysnum, void *params, uint64_t *uarg, int *n_args)
case 426: {
struct __acl_set_link_args *p = params;
uarg[a++] = (intptr_t)p->path; /* const char * */
- iarg[a++] = p->type; /* acl_type_t */
+ iarg[a++] = p->type; /* __acl_type_t */
uarg[a++] = (intptr_t)p->aclp; /* struct acl * */
*n_args = 3;
break;
@@ -2016,7 +1988,7 @@ systrace_args(int sysnum, void *params, uint64_t *uarg, int *n_args)
case 427: {
struct __acl_delete_link_args *p = params;
uarg[a++] = (intptr_t)p->path; /* const char * */
- iarg[a++] = p->type; /* acl_type_t */
+ iarg[a++] = p->type; /* __acl_type_t */
*n_args = 2;
break;
}
@@ -2024,7 +1996,7 @@ systrace_args(int sysnum, void *params, uint64_t *uarg, int *n_args)
case 428: {
struct __acl_aclcheck_link_args *p = params;
uarg[a++] = (intptr_t)p->path; /* const char * */
- iarg[a++] = p->type; /* acl_type_t */
+ iarg[a++] = p->type; /* __acl_type_t */
uarg[a++] = (intptr_t)p->aclp; /* struct acl * */
*n_args = 3;
break;
@@ -2644,13 +2616,6 @@ systrace_args(int sysnum, void *params, uint64_t *uarg, int *n_args)
*n_args = 1;
break;
}
- /* gssd_syscall */
- case 505: {
- struct gssd_syscall_args *p = params;
- uarg[a++] = (intptr_t)p->path; /* const char * */
- *n_args = 1;
- break;
- }
/* freebsd32_jail_get */
case 506: {
struct freebsd32_jail_get_args *p = params;
@@ -2875,7 +2840,7 @@ systrace_args(int sysnum, void *params, uint64_t *uarg, int *n_args)
uarg[a++] = (intptr_t)p->status; /* int * */
iarg[a++] = p->options; /* int */
uarg[a++] = (intptr_t)p->wrusage; /* struct __wrusage32 * */
- uarg[a++] = (intptr_t)p->info; /* struct siginfo32 * */
+ uarg[a++] = (intptr_t)p->info; /* struct __siginfo32 * */
*n_args = 8;
break;
}
@@ -3249,7 +3214,7 @@ systrace_args(int sysnum, void *params, uint64_t *uarg, int *n_args)
case 573: {
struct sigfastblock_args *p = params;
iarg[a++] = p->cmd; /* int */
- uarg[a++] = (intptr_t)p->ptr; /* uint32_t * */
+ uarg[a++] = (intptr_t)p->ptr; /* void * */
*n_args = 2;
break;
}
@@ -3276,9 +3241,8 @@ systrace_args(int sysnum, void *params, uint64_t *uarg, int *n_args)
/* rpctls_syscall */
case 576: {
struct rpctls_syscall_args *p = params;
- iarg[a++] = p->op; /* int */
- uarg[a++] = (intptr_t)p->path; /* const char * */
- *n_args = 2;
+ uarg[a++] = p->socookie; /* uint64_t */
+ *n_args = 1;
break;
}
/* __specialfd */
@@ -3320,6 +3284,149 @@ systrace_args(int sysnum, void *params, uint64_t *uarg, int *n_args)
*n_args = 0;
break;
}
+ /* swapoff */
+ case 582: {
+ struct swapoff_args *p = params;
+ uarg[a++] = (intptr_t)p->name; /* const char * */
+ uarg[a++] = p->flags; /* u_int */
+ *n_args = 2;
+ break;
+ }
+ /* kqueuex */
+ case 583: {
+ struct kqueuex_args *p = params;
+ uarg[a++] = p->flags; /* u_int */
+ *n_args = 1;
+ break;
+ }
+ /* membarrier */
+ case 584: {
+ struct membarrier_args *p = params;
+ iarg[a++] = p->cmd; /* int */
+ uarg[a++] = p->flags; /* unsigned */
+ iarg[a++] = p->cpu_id; /* int */
+ *n_args = 3;
+ break;
+ }
+ /* timerfd_create */
+ case 585: {
+ struct timerfd_create_args *p = params;
+ iarg[a++] = p->clockid; /* int */
+ iarg[a++] = p->flags; /* int */
+ *n_args = 2;
+ break;
+ }
+ /* freebsd32_timerfd_gettime */
+ case 586: {
+ struct freebsd32_timerfd_gettime_args *p = params;
+ iarg[a++] = p->fd; /* int */
+ uarg[a++] = (intptr_t)p->curr_value; /* struct itimerspec32 * */
+ *n_args = 2;
+ break;
+ }
+ /* freebsd32_timerfd_settime */
+ case 587: {
+ struct freebsd32_timerfd_settime_args *p = params;
+ iarg[a++] = p->fd; /* int */
+ iarg[a++] = p->flags; /* int */
+ uarg[a++] = (intptr_t)p->new_value; /* const struct itimerspec32 * */
+ uarg[a++] = (intptr_t)p->old_value; /* struct itimerspec32 * */
+ *n_args = 4;
+ break;
+ }
+ /* kcmp */
+ case 588: {
+ struct kcmp_args *p = params;
+ iarg[a++] = p->pid1; /* pid_t */
+ iarg[a++] = p->pid2; /* pid_t */
+ iarg[a++] = p->type; /* int */
+ uarg[a++] = (intptr_t)p->idx1; /* uintptr_t */
+ uarg[a++] = (intptr_t)p->idx2; /* uintptr_t */
+ *n_args = 5;
+ break;
+ }
+ /* getrlimitusage */
+ case 589: {
+ struct getrlimitusage_args *p = params;
+ uarg[a++] = p->which; /* u_int */
+ iarg[a++] = p->flags; /* int */
+ uarg[a++] = (intptr_t)p->res; /* rlim_t * */
+ *n_args = 3;
+ break;
+ }
+ /* fchroot */
+ case 590: {
+ struct fchroot_args *p = params;
+ iarg[a++] = p->fd; /* int */
+ *n_args = 1;
+ break;
+ }
+ /* freebsd32_setcred */
+ case 591: {
+ struct freebsd32_setcred_args *p = params;
+ uarg[a++] = p->flags; /* u_int */
+ uarg[a++] = (intptr_t)p->wcred; /* const struct setcred32 * */
+ uarg[a++] = p->size; /* size_t */
+ *n_args = 3;
+ break;
+ }
+ /* exterrctl */
+ case 592: {
+ struct exterrctl_args *p = params;
+ uarg[a++] = p->op; /* u_int */
+ uarg[a++] = p->flags; /* u_int */
+ uarg[a++] = (intptr_t)p->ptr; /* void * */
+ *n_args = 3;
+ break;
+ }
+ /* inotify_add_watch_at */
+ case 593: {
+ struct inotify_add_watch_at_args *p = params;
+ iarg[a++] = p->fd; /* int */
+ iarg[a++] = p->dfd; /* int */
+ uarg[a++] = (intptr_t)p->path; /* const char * */
+ uarg[a++] = p->mask; /* uint32_t */
+ *n_args = 4;
+ break;
+ }
+ /* inotify_rm_watch */
+ case 594: {
+ struct inotify_rm_watch_args *p = params;
+ iarg[a++] = p->fd; /* int */
+ iarg[a++] = p->wd; /* int */
+ *n_args = 2;
+ break;
+ }
+ /* getgroups */
+ case 595: {
+ struct getgroups_args *p = params;
+ iarg[a++] = p->gidsetsize; /* int */
+ uarg[a++] = (intptr_t)p->gidset; /* gid_t * */
+ *n_args = 2;
+ break;
+ }
+ /* setgroups */
+ case 596: {
+ struct setgroups_args *p = params;
+ iarg[a++] = p->gidsetsize; /* int */
+ uarg[a++] = (intptr_t)p->gidset; /* const gid_t * */
+ *n_args = 2;
+ break;
+ }
+ /* jail_attach_jd */
+ case 597: {
+ struct jail_attach_jd_args *p = params;
+ iarg[a++] = p->fd; /* int */
+ *n_args = 1;
+ break;
+ }
+ /* jail_remove_jd */
+ case 598: {
+ struct jail_remove_jd_args *p = params;
+ iarg[a++] = p->fd; /* int */
+ *n_args = 1;
+ break;
+ }
default:
*n_args = 0;
break;
@@ -3333,7 +3440,7 @@ systrace_entry_setargdesc(int sysnum, int ndx, char *desc, size_t descsz)
/* syscall */
case 0:
break;
- /* exit */
+ /* _exit */
case 1:
switch (ndx) {
case 0:
@@ -3958,26 +4065,6 @@ systrace_entry_setargdesc(int sysnum, int ndx, char *desc, size_t descsz)
/* vfork */
case 66:
break;
- /* sbrk */
- case 69:
- switch (ndx) {
- case 0:
- p = "int";
- break;
- default:
- break;
- };
- break;
- /* sstk */
- case 70:
- switch (ndx) {
- case 0:
- p = "int";
- break;
- default:
- break;
- };
- break;
/* munmap */
case 73:
switch (ndx) {
@@ -4039,32 +4126,6 @@ systrace_entry_setargdesc(int sysnum, int ndx, char *desc, size_t descsz)
break;
};
break;
- /* getgroups */
- case 79:
- switch (ndx) {
- case 0:
- p = "int";
- break;
- case 1:
- p = "userland gid_t *";
- break;
- default:
- break;
- };
- break;
- /* setgroups */
- case 80:
- switch (ndx) {
- case 0:
- p = "int";
- break;
- case 1:
- p = "userland const gid_t *";
- break;
- default:
- break;
- };
- break;
/* getpgrp */
case 81:
break;
@@ -4146,7 +4207,7 @@ systrace_entry_setargdesc(int sysnum, int ndx, char *desc, size_t descsz)
p = "int";
break;
case 2:
- p = "int32_t";
+ p = "intptr_t";
break;
default:
break;
@@ -4351,7 +4412,7 @@ systrace_entry_setargdesc(int sysnum, int ndx, char *desc, size_t descsz)
p = "int";
break;
case 1:
- p = "userland struct iovec32 *";
+ p = "userland const struct iovec32 *";
break;
case 2:
p = "u_int";
@@ -4367,7 +4428,7 @@ systrace_entry_setargdesc(int sysnum, int ndx, char *desc, size_t descsz)
p = "int";
break;
case 1:
- p = "userland struct iovec32 *";
+ p = "userland const struct iovec32 *";
break;
case 2:
p = "u_int";
@@ -4828,7 +4889,7 @@ systrace_entry_setargdesc(int sysnum, int ndx, char *desc, size_t descsz)
case 202:
switch (ndx) {
case 0:
- p = "userland int *";
+ p = "userland const int *";
break;
case 1:
p = "u_int";
@@ -5837,7 +5898,7 @@ systrace_entry_setargdesc(int sysnum, int ndx, char *desc, size_t descsz)
p = "userland const sigset_t *";
break;
case 1:
- p = "userland struct siginfo32 *";
+ p = "userland struct __siginfo32 *";
break;
case 2:
p = "userland const struct timespec32 *";
@@ -5853,7 +5914,7 @@ systrace_entry_setargdesc(int sysnum, int ndx, char *desc, size_t descsz)
p = "userland const sigset_t *";
break;
case 1:
- p = "userland struct siginfo32 *";
+ p = "userland struct __siginfo32 *";
break;
default:
break;
@@ -5866,7 +5927,7 @@ systrace_entry_setargdesc(int sysnum, int ndx, char *desc, size_t descsz)
p = "userland const char *";
break;
case 1:
- p = "acl_type_t";
+ p = "__acl_type_t";
break;
case 2:
p = "userland struct acl *";
@@ -5882,7 +5943,7 @@ systrace_entry_setargdesc(int sysnum, int ndx, char *desc, size_t descsz)
p = "userland const char *";
break;
case 1:
- p = "acl_type_t";
+ p = "__acl_type_t";
break;
case 2:
p = "userland struct acl *";
@@ -5898,7 +5959,7 @@ systrace_entry_setargdesc(int sysnum, int ndx, char *desc, size_t descsz)
p = "int";
break;
case 1:
- p = "acl_type_t";
+ p = "__acl_type_t";
break;
case 2:
p = "userland struct acl *";
@@ -5914,7 +5975,7 @@ systrace_entry_setargdesc(int sysnum, int ndx, char *desc, size_t descsz)
p = "int";
break;
case 1:
- p = "acl_type_t";
+ p = "__acl_type_t";
break;
case 2:
p = "userland struct acl *";
@@ -5930,7 +5991,7 @@ systrace_entry_setargdesc(int sysnum, int ndx, char *desc, size_t descsz)
p = "userland const char *";
break;
case 1:
- p = "acl_type_t";
+ p = "__acl_type_t";
break;
default:
break;
@@ -5943,7 +6004,7 @@ systrace_entry_setargdesc(int sysnum, int ndx, char *desc, size_t descsz)
p = "int";
break;
case 1:
- p = "acl_type_t";
+ p = "__acl_type_t";
break;
default:
break;
@@ -5956,7 +6017,7 @@ systrace_entry_setargdesc(int sysnum, int ndx, char *desc, size_t descsz)
p = "userland const char *";
break;
case 1:
- p = "acl_type_t";
+ p = "__acl_type_t";
break;
case 2:
p = "userland struct acl *";
@@ -5972,7 +6033,7 @@ systrace_entry_setargdesc(int sysnum, int ndx, char *desc, size_t descsz)
p = "int";
break;
case 1:
- p = "acl_type_t";
+ p = "__acl_type_t";
break;
case 2:
p = "userland struct acl *";
@@ -6286,6 +6347,22 @@ systrace_entry_setargdesc(int sysnum, int ndx, char *desc, size_t descsz)
break;
};
break;
+ /* mac_syscall */
+ case 394:
+ switch (ndx) {
+ case 0:
+ p = "userland const char *";
+ break;
+ case 1:
+ p = "int";
+ break;
+ case 2:
+ p = "userland void *";
+ break;
+ default:
+ break;
+ };
+ break;
/* ksem_close */
case 400:
switch (ndx) {
@@ -6513,16 +6590,6 @@ systrace_entry_setargdesc(int sysnum, int ndx, char *desc, size_t descsz)
break;
};
break;
- /* swapoff */
- case 424:
- switch (ndx) {
- case 0:
- p = "userland const char *";
- break;
- default:
- break;
- };
- break;
/* __acl_get_link */
case 425:
switch (ndx) {
@@ -6530,7 +6597,7 @@ systrace_entry_setargdesc(int sysnum, int ndx, char *desc, size_t descsz)
p = "userland const char *";
break;
case 1:
- p = "acl_type_t";
+ p = "__acl_type_t";
break;
case 2:
p = "userland struct acl *";
@@ -6546,7 +6613,7 @@ systrace_entry_setargdesc(int sysnum, int ndx, char *desc, size_t descsz)
p = "userland const char *";
break;
case 1:
- p = "acl_type_t";
+ p = "__acl_type_t";
break;
case 2:
p = "userland struct acl *";
@@ -6562,7 +6629,7 @@ systrace_entry_setargdesc(int sysnum, int ndx, char *desc, size_t descsz)
p = "userland const char *";
break;
case 1:
- p = "acl_type_t";
+ p = "__acl_type_t";
break;
default:
break;
@@ -6575,7 +6642,7 @@ systrace_entry_setargdesc(int sysnum, int ndx, char *desc, size_t descsz)
p = "userland const char *";
break;
case 1:
- p = "acl_type_t";
+ p = "__acl_type_t";
break;
case 2:
p = "userland struct acl *";
@@ -7721,16 +7788,6 @@ systrace_entry_setargdesc(int sysnum, int ndx, char *desc, size_t descsz)
break;
};
break;
- /* gssd_syscall */
- case 505:
- switch (ndx) {
- case 0:
- p = "userland const char *";
- break;
- default:
- break;
- };
- break;
/* freebsd32_jail_get */
case 506:
switch (ndx) {
@@ -8145,7 +8202,7 @@ systrace_entry_setargdesc(int sysnum, int ndx, char *desc, size_t descsz)
p = "userland struct __wrusage32 *";
break;
case 7 - _P_:
- p = "userland struct siginfo32 *";
+ p = "userland struct __siginfo32 *";
break;
default:
break;
@@ -8842,7 +8899,7 @@ systrace_entry_setargdesc(int sysnum, int ndx, char *desc, size_t descsz)
p = "int";
break;
case 1:
- p = "userland uint32_t *";
+ p = "userland void *";
break;
default:
break;
@@ -8890,10 +8947,7 @@ systrace_entry_setargdesc(int sysnum, int ndx, char *desc, size_t descsz)
case 576:
switch (ndx) {
case 0:
- p = "int";
- break;
- case 1:
- p = "userland const char *";
+ p = "uint64_t";
break;
default:
break;
@@ -8960,6 +9014,248 @@ systrace_entry_setargdesc(int sysnum, int ndx, char *desc, size_t descsz)
/* sched_getcpu */
case 581:
break;
+ /* swapoff */
+ case 582:
+ switch (ndx) {
+ case 0:
+ p = "userland const char *";
+ break;
+ case 1:
+ p = "u_int";
+ break;
+ default:
+ break;
+ };
+ break;
+ /* kqueuex */
+ case 583:
+ switch (ndx) {
+ case 0:
+ p = "u_int";
+ break;
+ default:
+ break;
+ };
+ break;
+ /* membarrier */
+ case 584:
+ switch (ndx) {
+ case 0:
+ p = "int";
+ break;
+ case 1:
+ p = "unsigned";
+ break;
+ case 2:
+ p = "int";
+ break;
+ default:
+ break;
+ };
+ break;
+ /* timerfd_create */
+ case 585:
+ switch (ndx) {
+ case 0:
+ p = "int";
+ break;
+ case 1:
+ p = "int";
+ break;
+ default:
+ break;
+ };
+ break;
+ /* freebsd32_timerfd_gettime */
+ case 586:
+ switch (ndx) {
+ case 0:
+ p = "int";
+ break;
+ case 1:
+ p = "userland struct itimerspec32 *";
+ break;
+ default:
+ break;
+ };
+ break;
+ /* freebsd32_timerfd_settime */
+ case 587:
+ switch (ndx) {
+ case 0:
+ p = "int";
+ break;
+ case 1:
+ p = "int";
+ break;
+ case 2:
+ p = "userland const struct itimerspec32 *";
+ break;
+ case 3:
+ p = "userland struct itimerspec32 *";
+ break;
+ default:
+ break;
+ };
+ break;
+ /* kcmp */
+ case 588:
+ switch (ndx) {
+ case 0:
+ p = "pid_t";
+ break;
+ case 1:
+ p = "pid_t";
+ break;
+ case 2:
+ p = "int";
+ break;
+ case 3:
+ p = "uintptr_t";
+ break;
+ case 4:
+ p = "uintptr_t";
+ break;
+ default:
+ break;
+ };
+ break;
+ /* getrlimitusage */
+ case 589:
+ switch (ndx) {
+ case 0:
+ p = "u_int";
+ break;
+ case 1:
+ p = "int";
+ break;
+ case 2:
+ p = "userland rlim_t *";
+ break;
+ default:
+ break;
+ };
+ break;
+ /* fchroot */
+ case 590:
+ switch (ndx) {
+ case 0:
+ p = "int";
+ break;
+ default:
+ break;
+ };
+ break;
+ /* freebsd32_setcred */
+ case 591:
+ switch (ndx) {
+ case 0:
+ p = "u_int";
+ break;
+ case 1:
+ p = "userland const struct setcred32 *";
+ break;
+ case 2:
+ p = "size_t";
+ break;
+ default:
+ break;
+ };
+ break;
+ /* exterrctl */
+ case 592:
+ switch (ndx) {
+ case 0:
+ p = "u_int";
+ break;
+ case 1:
+ p = "u_int";
+ break;
+ case 2:
+ p = "userland void *";
+ break;
+ default:
+ break;
+ };
+ break;
+ /* inotify_add_watch_at */
+ case 593:
+ switch (ndx) {
+ case 0:
+ p = "int";
+ break;
+ case 1:
+ p = "int";
+ break;
+ case 2:
+ p = "userland const char *";
+ break;
+ case 3:
+ p = "uint32_t";
+ break;
+ default:
+ break;
+ };
+ break;
+ /* inotify_rm_watch */
+ case 594:
+ switch (ndx) {
+ case 0:
+ p = "int";
+ break;
+ case 1:
+ p = "int";
+ break;
+ default:
+ break;
+ };
+ break;
+ /* getgroups */
+ case 595:
+ switch (ndx) {
+ case 0:
+ p = "int";
+ break;
+ case 1:
+ p = "userland gid_t *";
+ break;
+ default:
+ break;
+ };
+ break;
+ /* setgroups */
+ case 596:
+ switch (ndx) {
+ case 0:
+ p = "int";
+ break;
+ case 1:
+ p = "userland const gid_t *";
+ break;
+ default:
+ break;
+ };
+ break;
+ /* jail_attach_jd */
+ case 597:
+ switch (ndx) {
+ case 0:
+ p = "int";
+ break;
+ default:
+ break;
+ };
+ break;
+ /* jail_remove_jd */
+ case 598:
+ switch (ndx) {
+ case 0:
+ p = "int";
+ break;
+ default:
+ break;
+ };
+ break;
default:
break;
};
@@ -8973,7 +9269,7 @@ systrace_return_setargdesc(int sysnum, int ndx, char *desc, size_t descsz)
switch (sysnum) {
/* syscall */
case 0:
- /* exit */
+ /* _exit */
case 1:
if (ndx == 0 || ndx == 1)
p = "void";
@@ -9206,16 +9502,6 @@ systrace_return_setargdesc(int sysnum, int ndx, char *desc, size_t descsz)
break;
/* vfork */
case 66:
- /* sbrk */
- case 69:
- if (ndx == 0 || ndx == 1)
- p = "int";
- break;
- /* sstk */
- case 70:
- if (ndx == 0 || ndx == 1)
- p = "int";
- break;
/* munmap */
case 73:
if (ndx == 0 || ndx == 1)
@@ -9236,16 +9522,6 @@ systrace_return_setargdesc(int sysnum, int ndx, char *desc, size_t descsz)
if (ndx == 0 || ndx == 1)
p = "int";
break;
- /* getgroups */
- case 79:
- if (ndx == 0 || ndx == 1)
- p = "int";
- break;
- /* setgroups */
- case 80:
- if (ndx == 0 || ndx == 1)
- p = "int";
- break;
/* getpgrp */
case 81:
/* setpgid */
@@ -9343,12 +9619,12 @@ systrace_return_setargdesc(int sysnum, int ndx, char *desc, size_t descsz)
/* freebsd32_readv */
case 120:
if (ndx == 0 || ndx == 1)
- p = "int";
+ p = "ssize_t";
break;
/* freebsd32_writev */
case 121:
if (ndx == 0 || ndx == 1)
- p = "int";
+ p = "ssize_t";
break;
/* freebsd32_settimeofday */
case 122:
@@ -10029,6 +10305,11 @@ systrace_return_setargdesc(int sysnum, int ndx, char *desc, size_t descsz)
if (ndx == 0 || ndx == 1)
p = "int";
break;
+ /* mac_syscall */
+ case 394:
+ if (ndx == 0 || ndx == 1)
+ p = "int";
+ break;
/* ksem_close */
case 400:
if (ndx == 0 || ndx == 1)
@@ -10114,11 +10395,6 @@ systrace_return_setargdesc(int sysnum, int ndx, char *desc, size_t descsz)
if (ndx == 0 || ndx == 1)
p = "int";
break;
- /* swapoff */
- case 424:
- if (ndx == 0 || ndx == 1)
- p = "int";
- break;
/* __acl_get_link */
case 425:
if (ndx == 0 || ndx == 1)
@@ -10464,11 +10740,6 @@ systrace_return_setargdesc(int sysnum, int ndx, char *desc, size_t descsz)
if (ndx == 0 || ndx == 1)
p = "int";
break;
- /* gssd_syscall */
- case 505:
- if (ndx == 0 || ndx == 1)
- p = "int";
- break;
/* freebsd32_jail_get */
case 506:
if (ndx == 0 || ndx == 1)
@@ -10818,6 +11089,91 @@ systrace_return_setargdesc(int sysnum, int ndx, char *desc, size_t descsz)
break;
/* sched_getcpu */
case 581:
+ /* swapoff */
+ case 582:
+ if (ndx == 0 || ndx == 1)
+ p = "int";
+ break;
+ /* kqueuex */
+ case 583:
+ if (ndx == 0 || ndx == 1)
+ p = "int";
+ break;
+ /* membarrier */
+ case 584:
+ if (ndx == 0 || ndx == 1)
+ p = "int";
+ break;
+ /* timerfd_create */
+ case 585:
+ if (ndx == 0 || ndx == 1)
+ p = "int";
+ break;
+ /* freebsd32_timerfd_gettime */
+ case 586:
+ if (ndx == 0 || ndx == 1)
+ p = "int";
+ break;
+ /* freebsd32_timerfd_settime */
+ case 587:
+ if (ndx == 0 || ndx == 1)
+ p = "int";
+ break;
+ /* kcmp */
+ case 588:
+ if (ndx == 0 || ndx == 1)
+ p = "int";
+ break;
+ /* getrlimitusage */
+ case 589:
+ if (ndx == 0 || ndx == 1)
+ p = "int";
+ break;
+ /* fchroot */
+ case 590:
+ if (ndx == 0 || ndx == 1)
+ p = "int";
+ break;
+ /* freebsd32_setcred */
+ case 591:
+ if (ndx == 0 || ndx == 1)
+ p = "int";
+ break;
+ /* exterrctl */
+ case 592:
+ if (ndx == 0 || ndx == 1)
+ p = "int";
+ break;
+ /* inotify_add_watch_at */
+ case 593:
+ if (ndx == 0 || ndx == 1)
+ p = "int";
+ break;
+ /* inotify_rm_watch */
+ case 594:
+ if (ndx == 0 || ndx == 1)
+ p = "int";
+ break;
+ /* getgroups */
+ case 595:
+ if (ndx == 0 || ndx == 1)
+ p = "int";
+ break;
+ /* setgroups */
+ case 596:
+ if (ndx == 0 || ndx == 1)
+ p = "int";
+ break;
+ /* jail_attach_jd */
+ case 597:
+ if (ndx == 0 || ndx == 1)
+ p = "int";
+ break;
+ /* jail_remove_jd */
+ case 598:
+ if (ndx == 0 || ndx == 1)
+ p = "int";
+ break;
default:
break;
};
diff --git a/sys/compat/freebsd32/freebsd32_util.h b/sys/compat/freebsd32/freebsd32_util.h
index b126fbde0857..1ae016814329 100644
--- a/sys/compat/freebsd32/freebsd32_util.h
+++ b/sys/compat/freebsd32/freebsd32_util.h
@@ -26,8 +26,6 @@
* 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.
- *
- * $FreeBSD$
*/
#ifndef _COMPAT_FREEBSD32_FREEBSD32_UTIL_H_
@@ -43,9 +41,9 @@
#include <vm/pmap.h>
struct freebsd32_ps_strings {
- u_int32_t ps_argvstr; /* first of 0 or more argument strings */
+ uint32_t ps_argvstr; /* first of 0 or more argument strings */
int ps_nargvstr; /* the number of argument strings */
- u_int32_t ps_envstr; /* first of 0 or more environment strings */
+ uint32_t ps_envstr; /* first of 0 or more environment strings */
int ps_nenvstr; /* the number of environment strings */
};
@@ -116,12 +114,19 @@ int freebsd32_copyout_strings(struct image_params *imgp,
uintptr_t *stack_base);
int freebsd32_copyiniov(struct iovec32 *iovp, u_int iovcnt,
struct iovec **iov, int error);
-int freebsd32_copyinuio(struct iovec32 *iovp, u_int iovcnt,
+int freebsd32_copyinuio(const struct iovec32 *iovp, u_int iovcnt,
struct uio **uiop);
void freebsd32_rusage_out(const struct rusage *s, struct rusage32 *s32);
struct image_args;
int freebsd32_exec_copyin_args(struct image_args *args, const char *fname,
- enum uio_seg segflg, u_int32_t *argv, u_int32_t *envv);
+ uint32_t *argv, uint32_t *envv);
+
+struct kinfo_knote;
+struct kinfo_knote32;
+void freebsd32_kinfo_knote_to_32(const struct kinfo_knote *kin,
+ struct kinfo_knote32 *kin32);
+
+extern int compat_freebsd_32bit;
#endif /* !_COMPAT_FREEBSD32_FREEBSD32_UTIL_H_ */
diff --git a/sys/compat/freebsd32/syscalls.conf b/sys/compat/freebsd32/syscalls.conf
index 6b80018165df..72006631c89e 100644
--- a/sys/compat/freebsd32/syscalls.conf
+++ b/sys/compat/freebsd32/syscalls.conf
@@ -1,10 +1,8 @@
-# $FreeBSD$
sysnames="freebsd32_syscalls.c"
sysproto="freebsd32_proto.h"
sysproto_h=_FREEBSD32_SYSPROTO_H_
syshdr="freebsd32_syscall.h"
syssw="freebsd32_sysent.c"
-sysmk="/dev/null"
syscallprefix="FREEBSD32_SYS_"
switchname="freebsd32_sysent"
namesname="freebsd32_syscallnames"
@@ -20,10 +18,10 @@ abi_ptr_array_t="uint32_t"
abi_headers="#include <compat/freebsd32/freebsd32_proto.h>"
#
-# Variables below this line are exceptions to the ABI changes programatically
-# detected by makesyscalls.lua. New system calls should not require an entry
-# here in nearly virtually all cases. New entries are almost certainly
-# representative of badly designed interfaces.
+# Variables below this line are exceptions to the ABI changes
+# programmatically detected by sys/tools/syscalls. New system calls
+# should not require an entry here in virtually all cases. New entries
+# are almost certainly representative of badly designed interfaces.
#
# System calls that require freebsd32-specific handling:
@@ -48,12 +46,12 @@ syscall_no_abi_change="aio_cancel thr_exit thr_kill thr_kill2 thr_self thr_set_n
obsol="getkerninfo"
# Syscalls without implementations:
-# *mac_* - should be implemented
+# __mac_* - should be implemented
# afs3_syscall - requires significant porting, probably doesn't make sense
# kldsym - can't be implemented (kernel virtual addresses can't fit in 32-bits)
# lgetfh - should be implemented
# nlm_syscall - requires significant porting, probably doesn't make sense
# nnpfs_syscall - requires significant porting, probably doesn't make sense
# ntp_gettime - should be implemented
-# thr_create - was unimplemented and appears to be unnecessicary
-unimpl="afs3_syscall kldsym __mac_get_proc __mac_set_proc __mac_get_fd __mac_get_file __mac_set_fd __mac_set_file __mac_get_pid __mac_get_link __mac_set_link __mac_execve mac_syscall nfssvc nlm_syscall ntp_gettime lgetfh nnpfs_syscall thr_create"
+# thr_create - was unimplemented and appears to be unnecessary
+unimpl="afs3_syscall kldsym __mac_get_proc __mac_set_proc __mac_get_fd __mac_get_file __mac_set_fd __mac_set_file __mac_get_pid __mac_get_link __mac_set_link __mac_execve nfssvc nlm_syscall ntp_gettime lgetfh nnpfs_syscall thr_create"
diff --git a/sys/compat/ia32/ia32_genassym.c b/sys/compat/ia32/ia32_genassym.c
index 5a1faae892db..cc0b1e4e8ca5 100644
--- a/sys/compat/ia32/ia32_genassym.c
+++ b/sys/compat/ia32/ia32_genassym.c
@@ -1,6 +1,4 @@
#include <sys/cdefs.h>
-__FBSDID("$FreeBSD$");
-
#include <sys/param.h>
#include <sys/assym.h>
#include <sys/systm.h>
@@ -11,17 +9,31 @@ __FBSDID("$FreeBSD$");
ASSYM(IA32_SIGF_HANDLER, offsetof(struct ia32_sigframe, sf_ah));
ASSYM(IA32_SIGF_UC, offsetof(struct ia32_sigframe, sf_uc));
-#ifdef COMPAT_43
-ASSYM(IA32_SIGF_SC, offsetof(struct ia32_sigframe3, sf_siginfo.si_sc));
-#endif
ASSYM(IA32_UC_GS, offsetof(struct ia32_ucontext, uc_mcontext.mc_gs));
ASSYM(IA32_UC_FS, offsetof(struct ia32_ucontext, uc_mcontext.mc_fs));
ASSYM(IA32_UC_ES, offsetof(struct ia32_ucontext, uc_mcontext.mc_es));
ASSYM(IA32_UC_DS, offsetof(struct ia32_ucontext, uc_mcontext.mc_ds));
+ASSYM(IA32_UC_EDI, offsetof(struct ia32_ucontext, uc_mcontext.mc_edi));
+ASSYM(IA32_UC_ESI, offsetof(struct ia32_ucontext, uc_mcontext.mc_esi));
+ASSYM(IA32_UC_EBP, offsetof(struct ia32_ucontext, uc_mcontext.mc_ebp));
+ASSYM(IA32_UC_EBX, offsetof(struct ia32_ucontext, uc_mcontext.mc_ebx));
+ASSYM(IA32_UC_EDX, offsetof(struct ia32_ucontext, uc_mcontext.mc_edx));
+ASSYM(IA32_UC_ECX, offsetof(struct ia32_ucontext, uc_mcontext.mc_ecx));
+ASSYM(IA32_UC_EAX, offsetof(struct ia32_ucontext, uc_mcontext.mc_eax));
+ASSYM(IA32_UC_EIP, offsetof(struct ia32_ucontext, uc_mcontext.mc_eip));
+ASSYM(IA32_UC_CS, offsetof(struct ia32_ucontext, uc_mcontext.mc_cs));
+ASSYM(IA32_UC_EFLAGS, offsetof(struct ia32_ucontext, uc_mcontext.mc_eflags));
+ASSYM(IA32_UC_ESP, offsetof(struct ia32_ucontext, uc_mcontext.mc_esp));
+ASSYM(IA32_UC_SS, offsetof(struct ia32_ucontext, uc_mcontext.mc_ss));
+ASSYM(IA32_UC_FSBASE, offsetof(struct ia32_ucontext, uc_mcontext.mc_fsbase));
+ASSYM(IA32_UC_GSBASE, offsetof(struct ia32_ucontext, uc_mcontext.mc_gsbase));
+#ifdef COMPAT_43
+ASSYM(IA32_SIGF_SC, offsetof(struct ia32_osigframe, sf_siginfo.si_sc));
+#endif
#ifdef COMPAT_FREEBSD4
-ASSYM(IA32_SIGF_UC4, offsetof(struct ia32_sigframe4, sf_uc));
-ASSYM(IA32_UC4_GS, offsetof(struct ia32_ucontext4, uc_mcontext.mc_gs));
-ASSYM(IA32_UC4_FS, offsetof(struct ia32_ucontext4, uc_mcontext.mc_fs));
-ASSYM(IA32_UC4_ES, offsetof(struct ia32_ucontext4, uc_mcontext.mc_es));
-ASSYM(IA32_UC4_DS, offsetof(struct ia32_ucontext4, uc_mcontext.mc_ds));
+ASSYM(IA32_SIGF_UC4, offsetof(struct ia32_freebsd4_sigframe, sf_uc));
+ASSYM(IA32_UC4_GS, offsetof(struct ia32_freebsd4_ucontext, uc_mcontext.mc_gs));
+ASSYM(IA32_UC4_FS, offsetof(struct ia32_freebsd4_ucontext, uc_mcontext.mc_fs));
+ASSYM(IA32_UC4_ES, offsetof(struct ia32_freebsd4_ucontext, uc_mcontext.mc_es));
+ASSYM(IA32_UC4_DS, offsetof(struct ia32_freebsd4_ucontext, uc_mcontext.mc_ds));
#endif
diff --git a/sys/compat/ia32/ia32_signal.h b/sys/compat/ia32/ia32_signal.h
index e5fb8ec90fa2..fbb50c4ef1f2 100644
--- a/sys/compat/ia32/ia32_signal.h
+++ b/sys/compat/ia32/ia32_signal.h
@@ -27,8 +27,6 @@
* 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.
- *
- * $FreeBSD$
*/
#ifndef _COMPAT_IA32_IA32_SIGNAL_H
@@ -43,166 +41,150 @@
(_MC_IA32_HASSEGS | _MC_IA32_HASBASES | _MC_IA32_HASFPXSTATE)
struct ia32_mcontext {
- u_int32_t mc_onstack; /* XXX - sigcontext compat. */
- u_int32_t mc_gs; /* machine state (struct trapframe) */
- u_int32_t mc_fs;
- u_int32_t mc_es;
- u_int32_t mc_ds;
- u_int32_t mc_edi;
- u_int32_t mc_esi;
- u_int32_t mc_ebp;
- u_int32_t mc_isp;
- u_int32_t mc_ebx;
- u_int32_t mc_edx;
- u_int32_t mc_ecx;
- u_int32_t mc_eax;
- u_int32_t mc_trapno;
- u_int32_t mc_err;
- u_int32_t mc_eip;
- u_int32_t mc_cs;
- u_int32_t mc_eflags;
- u_int32_t mc_esp;
- u_int32_t mc_ss;
- u_int32_t mc_len; /* sizeof(struct ia32_mcontext) */
+ uint32_t mc_onstack; /* XXX - sigcontext compat. */
+ uint32_t mc_gs; /* machine state (struct trapframe) */
+ uint32_t mc_fs;
+ uint32_t mc_es;
+ uint32_t mc_ds;
+ uint32_t mc_edi;
+ uint32_t mc_esi;
+ uint32_t mc_ebp;
+ uint32_t mc_isp;
+ uint32_t mc_ebx;
+ uint32_t mc_edx;
+ uint32_t mc_ecx;
+ uint32_t mc_eax;
+ uint32_t mc_trapno;
+ uint32_t mc_err;
+ uint32_t mc_eip;
+ uint32_t mc_cs;
+ uint32_t mc_eflags;
+ uint32_t mc_esp;
+ uint32_t mc_ss;
+ uint32_t mc_len; /* sizeof(struct ia32_mcontext) */
/* We use the same values for fpformat and ownedfp */
- u_int32_t mc_fpformat;
- u_int32_t mc_ownedfp;
- u_int32_t mc_flags;
+ uint32_t mc_fpformat;
+ uint32_t mc_ownedfp;
+ uint32_t mc_flags;
/*
* See <i386/include/npx.h> for the internals of mc_fpstate[].
*/
- u_int32_t mc_fpstate[128] __aligned(16);
- u_int32_t mc_fsbase;
- u_int32_t mc_gsbase;
- u_int32_t mc_xfpustate;
- u_int32_t mc_xfpustate_len;
- u_int32_t mc_spare2[4];
+ uint32_t mc_fpstate[128] __aligned(16);
+ uint32_t mc_fsbase;
+ uint32_t mc_gsbase;
+ uint32_t mc_xfpustate;
+ uint32_t mc_xfpustate_len;
+ uint32_t mc_spare2[4];
};
struct ia32_ucontext {
sigset_t uc_sigmask;
struct ia32_mcontext uc_mcontext;
- u_int32_t uc_link;
+ uint32_t uc_link;
struct sigaltstack32 uc_stack;
- u_int32_t uc_flags;
- u_int32_t __spare__[4];
+ uint32_t uc_flags;
+ uint32_t __spare__[4];
};
-#if defined(COMPAT_FREEBSD4)
-struct ia32_mcontext4 {
- u_int32_t mc_onstack; /* XXX - sigcontext compat. */
- u_int32_t mc_gs; /* machine state (struct trapframe) */
- u_int32_t mc_fs;
- u_int32_t mc_es;
- u_int32_t mc_ds;
- u_int32_t mc_edi;
- u_int32_t mc_esi;
- u_int32_t mc_ebp;
- u_int32_t mc_isp;
- u_int32_t mc_ebx;
- u_int32_t mc_edx;
- u_int32_t mc_ecx;
- u_int32_t mc_eax;
- u_int32_t mc_trapno;
- u_int32_t mc_err;
- u_int32_t mc_eip;
- u_int32_t mc_cs;
- u_int32_t mc_eflags;
- u_int32_t mc_esp;
- u_int32_t mc_ss;
- u_int32_t mc_fpregs[28];
- u_int32_t __spare__[17];
+struct ia32_freebsd4_mcontext {
+ uint32_t mc_onstack; /* XXX - sigcontext compat. */
+ uint32_t mc_gs; /* machine state (struct trapframe) */
+ uint32_t mc_fs;
+ uint32_t mc_es;
+ uint32_t mc_ds;
+ uint32_t mc_edi;
+ uint32_t mc_esi;
+ uint32_t mc_ebp;
+ uint32_t mc_isp;
+ uint32_t mc_ebx;
+ uint32_t mc_edx;
+ uint32_t mc_ecx;
+ uint32_t mc_eax;
+ uint32_t mc_trapno;
+ uint32_t mc_err;
+ uint32_t mc_eip;
+ uint32_t mc_cs;
+ uint32_t mc_eflags;
+ uint32_t mc_esp;
+ uint32_t mc_ss;
+ uint32_t mc_fpregs[28];
+ uint32_t __spare__[17];
};
-struct ia32_ucontext4 {
+struct ia32_freebsd4_ucontext {
sigset_t uc_sigmask;
- struct ia32_mcontext4 uc_mcontext;
- u_int32_t uc_link;
+ struct ia32_freebsd4_mcontext uc_mcontext;
+ uint32_t uc_link;
struct sigaltstack32 uc_stack;
- u_int32_t __spare__[8];
+ uint32_t __spare__[8];
};
-#endif
-#ifdef COMPAT_43
-struct ia32_sigcontext3 {
- u_int32_t sc_onstack;
- u_int32_t sc_mask;
- u_int32_t sc_esp;
- u_int32_t sc_ebp;
- u_int32_t sc_isp;
- u_int32_t sc_eip;
- u_int32_t sc_eflags;
- u_int32_t sc_es;
- u_int32_t sc_ds;
- u_int32_t sc_cs;
- u_int32_t sc_ss;
- u_int32_t sc_edi;
- u_int32_t sc_esi;
- u_int32_t sc_ebx;
- u_int32_t sc_edx;
- u_int32_t sc_ecx;
- u_int32_t sc_eax;
- u_int32_t sc_gs;
- u_int32_t sc_fs;
- u_int32_t sc_trapno;
- u_int32_t sc_err;
+struct ia32_osigcontext {
+ uint32_t sc_onstack;
+ uint32_t sc_mask;
+ uint32_t sc_esp;
+ uint32_t sc_ebp;
+ uint32_t sc_isp;
+ uint32_t sc_eip;
+ uint32_t sc_eflags;
+ uint32_t sc_es;
+ uint32_t sc_ds;
+ uint32_t sc_cs;
+ uint32_t sc_ss;
+ uint32_t sc_edi;
+ uint32_t sc_esi;
+ uint32_t sc_ebx;
+ uint32_t sc_edx;
+ uint32_t sc_ecx;
+ uint32_t sc_eax;
+ uint32_t sc_gs;
+ uint32_t sc_fs;
+ uint32_t sc_trapno;
+ uint32_t sc_err;
};
-#endif
/*
* Signal frames, arguments passed to application signal handlers.
*/
-#ifdef COMPAT_FREEBSD4
-struct ia32_sigframe4 {
- u_int32_t sf_signum;
- u_int32_t sf_siginfo; /* code or pointer to sf_si */
- u_int32_t sf_ucontext; /* points to sf_uc */
- u_int32_t sf_addr; /* undocumented 4th arg */
- u_int32_t sf_ah; /* action/handler pointer */
- struct ia32_ucontext4 sf_uc; /* = *sf_ucontext */
- struct siginfo32 sf_si; /* = *sf_siginfo (SA_SIGINFO case) */
+struct ia32_freebsd4_sigframe {
+ uint32_t sf_signum;
+ uint32_t sf_siginfo; /* code or pointer to sf_si */
+ uint32_t sf_ucontext; /* points to sf_uc */
+ uint32_t sf_addr; /* undocumented 4th arg */
+ uint32_t sf_ah; /* action/handler pointer */
+ struct ia32_freebsd4_ucontext sf_uc; /* = *sf_ucontext */
+ struct __siginfo32 sf_si; /* = *sf_siginfo (SA_SIGINFO case) */
};
-#endif
struct ia32_sigframe {
- u_int32_t sf_signum;
- u_int32_t sf_siginfo; /* code or pointer to sf_si */
- u_int32_t sf_ucontext; /* points to sf_uc */
- u_int32_t sf_addr; /* undocumented 4th arg */
- u_int32_t sf_ah; /* action/handler pointer */
+ uint32_t sf_signum;
+ uint32_t sf_siginfo; /* code or pointer to sf_si */
+ uint32_t sf_ucontext; /* points to sf_uc */
+ uint32_t sf_addr; /* undocumented 4th arg */
+ uint32_t sf_ah; /* action/handler pointer */
/* Beware, hole due to ucontext being 16 byte aligned! */
struct ia32_ucontext sf_uc; /* = *sf_ucontext */
- struct siginfo32 sf_si; /* = *sf_siginfo (SA_SIGINFO case) */
+ struct __siginfo32 sf_si; /* = *sf_siginfo (SA_SIGINFO case) */
};
-#ifdef COMPAT_43
-struct ia32_siginfo3 {
- struct ia32_sigcontext3 si_sc;
+struct ia32_osiginfo {
+ struct ia32_osigcontext si_sc;
int si_signo;
int si_code;
union sigval32 si_value;
};
-struct ia32_sigframe3 {
+struct ia32_osigframe {
int sf_signum;
- u_int32_t sf_arg2; /* int or siginfo_t */
- u_int32_t sf_scp;
- u_int32_t sf_addr;
- u_int32_t sf_ah; /* action/handler pointer */
- struct ia32_siginfo3 sf_siginfo;
+ uint32_t sf_arg2; /* int or siginfo_t */
+ uint32_t sf_scp;
+ uint32_t sf_addr;
+ uint32_t sf_ah; /* action/handler pointer */
+ struct ia32_osiginfo sf_siginfo;
};
-#endif
struct ksiginfo;
struct image_params;
-extern char ia32_sigcode[];
-extern char freebsd4_ia32_sigcode[];
-extern char ia32_osigcode[];
-extern char lcall_tramp;
-extern int sz_ia32_sigcode;
-extern int sz_freebsd4_ia32_sigcode;
-extern int sz_ia32_osigcode;
-extern int sz_lcall_tramp;
void ia32_sendsig(sig_t, struct ksiginfo *, sigset_t *);
void ia32_setregs(struct thread *td, struct image_params *imgp,
uintptr_t stack);
diff --git a/sys/compat/ia32/ia32_sysvec.c b/sys/compat/ia32/ia32_sysvec.c
index 969f5645a0f4..b9dada4eee7b 100644
--- a/sys/compat/ia32/ia32_sysvec.c
+++ b/sys/compat/ia32/ia32_sysvec.c
@@ -1,5 +1,5 @@
/*-
- * SPDX-License-Identifier: BSD-2-Clause-FreeBSD
+ * SPDX-License-Identifier: BSD-2-Clause
*
* Copyright (c) 2002 Doug Rabson
* Copyright (c) 2003 Peter Wemm
@@ -28,11 +28,10 @@
*/
#include <sys/cdefs.h>
-__FBSDID("$FreeBSD$");
-
#define __ELF_WORD_SIZE 32
#include <sys/param.h>
+#include <sys/elf.h>
#include <sys/exec.h>
#include <sys/fcntl.h>
#include <sys/imgact.h>
@@ -44,6 +43,7 @@ __FBSDID("$FreeBSD$");
#include <sys/namei.h>
#include <sys/proc.h>
#include <sys/procfs.h>
+#include <sys/reg.h>
#include <sys/resourcevar.h>
#include <sys/systm.h>
#include <sys/signalvar.h>
@@ -76,13 +76,19 @@ __FBSDID("$FreeBSD$");
CTASSERT(sizeof(struct ia32_mcontext) == 640);
CTASSERT(sizeof(struct ia32_ucontext) == 704);
CTASSERT(sizeof(struct ia32_sigframe) == 800);
-CTASSERT(sizeof(struct siginfo32) == 64);
+CTASSERT(sizeof(struct __siginfo32) == 64);
#ifdef COMPAT_FREEBSD4
-CTASSERT(sizeof(struct ia32_mcontext4) == 260);
-CTASSERT(sizeof(struct ia32_ucontext4) == 324);
-CTASSERT(sizeof(struct ia32_sigframe4) == 408);
+CTASSERT(sizeof(struct ia32_freebsd4_mcontext) == 260);
+CTASSERT(sizeof(struct ia32_freebsd4_ucontext) == 324);
+CTASSERT(sizeof(struct ia32_freebsd4_sigframe) == 408);
#endif
+#include "vdso_ia32_offsets.h"
+
+extern const char _binary_elf_vdso32_so_1_start[];
+extern const char _binary_elf_vdso32_so_1_end[];
+extern char _binary_elf_vdso32_so_1_size;
+
extern const char *freebsd32_syscallnames[];
static SYSCTL_NODE(_compat, OID_AUTO, ia32, CTLFLAG_RW | CTLFLAG_MPSAFE, 0,
@@ -98,30 +104,31 @@ SYSCTL_ULONG(_compat_ia32, OID_AUTO, maxvmem, CTLFLAG_RWTUN, &ia32_maxvmem, 0, "
struct sysentvec ia32_freebsd_sysvec = {
.sv_size = FREEBSD32_SYS_MAXSYSCALL,
.sv_table = freebsd32_sysent,
- .sv_transtrap = NULL,
.sv_fixup = elf32_freebsd_fixup,
.sv_sendsig = ia32_sendsig,
- .sv_sigcode = ia32_sigcode,
- .sv_szsigcode = &sz_ia32_sigcode,
+ .sv_sigcode = _binary_elf_vdso32_so_1_start,
+ .sv_szsigcode = (int *)&_binary_elf_vdso32_so_1_size,
+ .sv_sigcodeoff = VDSO_IA32_SIGCODE_OFFSET,
.sv_name = "FreeBSD ELF32",
.sv_coredump = elf32_coredump,
.sv_elf_core_osabi = ELFOSABI_FREEBSD,
.sv_elf_core_abi_vendor = FREEBSD_ABI_VENDOR,
.sv_elf_core_prepare_notes = elf32_prepare_notes,
- .sv_imgact_try = NULL,
.sv_minsigstksz = MINSIGSTKSZ,
.sv_minuser = FREEBSD32_MINUSER,
.sv_maxuser = FREEBSD32_MAXUSER,
.sv_usrstack = FREEBSD32_USRSTACK,
.sv_psstrings = FREEBSD32_PS_STRINGS,
+ .sv_psstringssz = sizeof(struct freebsd32_ps_strings),
.sv_stackprot = VM_PROT_ALL,
.sv_copyout_auxargs = elf32_freebsd_copyout_auxargs,
.sv_copyout_strings = freebsd32_copyout_strings,
.sv_setregs = ia32_setregs,
.sv_fixlimit = ia32_fixlimit,
.sv_maxssiz = &ia32_maxssiz,
- .sv_flags = SV_ABI_FREEBSD | SV_ASLR | SV_IA32 | SV_ILP32 |
- SV_SHP | SV_TIMEKEEP | SV_RNG_SEED_VER,
+ .sv_flags = SV_ABI_FREEBSD | SV_ASLR | SV_ILP32 |
+ SV_SHP | SV_TIMEKEEP | SV_RNG_SEED_VER |
+ SV_DSO_SIG | SV_SIGSYS,
.sv_set_syscall_retval = ia32_set_syscall_retval,
.sv_fetch_syscall_args = ia32_fetch_syscall_args,
.sv_syscallnames = freebsd32_syscallnames,
@@ -130,59 +137,51 @@ struct sysentvec ia32_freebsd_sysvec = {
.sv_schedtail = NULL,
.sv_thread_detach = NULL,
.sv_trap = NULL,
- .sv_stackgap = elf32_stackgap,
.sv_onexec_old = exec_onexec_old,
.sv_onexit = exit_onexit,
.sv_set_fork_retval = x86_set_fork_retval,
+ .sv_regset_begin = SET_BEGIN(__elfN(regset)),
+ .sv_regset_end = SET_LIMIT(__elfN(regset)),
};
INIT_SYSENTVEC(elf_ia32_sysvec, &ia32_freebsd_sysvec);
-static Elf32_Brandinfo ia32_brand_info = {
+static const Elf32_Brandinfo ia32_brand_info = {
.brand = ELFOSABI_FREEBSD,
.machine = EM_386,
.compat_3_brand = "FreeBSD",
- .emul_path = NULL,
.interp_path = "/libexec/ld-elf.so.1",
.sysvec = &ia32_freebsd_sysvec,
.interp_newpath = "/libexec/ld-elf32.so.1",
.brand_note = &elf32_freebsd_brandnote,
.flags = BI_CAN_EXEC_DYN | BI_BRAND_NOTE
};
+C_SYSINIT(ia32, SI_SUB_EXEC, SI_ORDER_MIDDLE,
+ (sysinit_cfunc_t)elf32_insert_brand_entry, &ia32_brand_info);
-SYSINIT(ia32, SI_SUB_EXEC, SI_ORDER_MIDDLE,
- (sysinit_cfunc_t) elf32_insert_brand_entry,
- &ia32_brand_info);
-
-static Elf32_Brandinfo ia32_brand_oinfo = {
+static const Elf32_Brandinfo ia32_brand_oinfo = {
.brand = ELFOSABI_FREEBSD,
.machine = EM_386,
.compat_3_brand = "FreeBSD",
- .emul_path = NULL,
.interp_path = "/usr/libexec/ld-elf.so.1",
.sysvec = &ia32_freebsd_sysvec,
.interp_newpath = "/libexec/ld-elf32.so.1",
.brand_note = &elf32_freebsd_brandnote,
.flags = BI_CAN_EXEC_DYN | BI_BRAND_NOTE
};
+C_SYSINIT(oia32, SI_SUB_EXEC, SI_ORDER_ANY,
+ (sysinit_cfunc_t)elf32_insert_brand_entry, &ia32_brand_oinfo);
-SYSINIT(oia32, SI_SUB_EXEC, SI_ORDER_ANY,
- (sysinit_cfunc_t) elf32_insert_brand_entry,
- &ia32_brand_oinfo);
-
-static Elf32_Brandinfo kia32_brand_info = {
+static const Elf32_Brandinfo kia32_brand_info = {
.brand = ELFOSABI_FREEBSD,
.machine = EM_386,
.compat_3_brand = "FreeBSD",
- .emul_path = NULL,
.interp_path = "/lib/ld.so.1",
.sysvec = &ia32_freebsd_sysvec,
.brand_note = &elf32_kfreebsd_brandnote,
.flags = BI_CAN_EXEC_DYN | BI_BRAND_NOTE_MANDATORY
};
-
-SYSINIT(kia32, SI_SUB_EXEC, SI_ORDER_ANY,
- (sysinit_cfunc_t) elf32_insert_brand_entry,
- &kia32_brand_info);
+C_SYSINIT(kia32, SI_SUB_EXEC, SI_ORDER_ANY,
+ (sysinit_cfunc_t)elf32_insert_brand_entry, &kia32_brand_info);
void
elf32_dump_thread(struct thread *td, void *dst, size_t *off)
diff --git a/sys/compat/ia32/ia32_util.h b/sys/compat/ia32/ia32_util.h
index 8a41b90b2afa..ef1ad95f42bb 100644
--- a/sys/compat/ia32/ia32_util.h
+++ b/sys/compat/ia32/ia32_util.h
@@ -26,8 +26,6 @@
* 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.
- *
- * $FreeBSD$
*/
#ifndef _COMPAT_IA32_IA32_UTIL_H
diff --git a/sys/compat/lindebugfs/lindebugfs.c b/sys/compat/lindebugfs/lindebugfs.c
index 63161eedf14f..8cddc6f390bc 100644
--- a/sys/compat/lindebugfs/lindebugfs.c
+++ b/sys/compat/lindebugfs/lindebugfs.c
@@ -1,5 +1,5 @@
/*-
- * SPDX-License-Identifier: BSD-2-Clause-FreeBSD
+ * SPDX-License-Identifier: BSD-2-Clause
*
* Copyright (c) 2016-2018, Matthew Macy <mmacy@freebsd.org>
*
@@ -26,9 +26,6 @@
*
*/
-#include <sys/cdefs.h>
-__FBSDID("$FreeBSD$");
-
#include <sys/param.h>
#include <sys/systm.h>
#include <sys/queue.h>
@@ -69,9 +66,10 @@ __FBSDID("$FreeBSD$");
#include <compat/linux/linux_util.h>
#include <fs/pseudofs/pseudofs.h>
-#include <linux/debugfs.h>
-#include <linux/seq_file.h>
+#include <asm/atomic.h>
#include <linux/compat.h>
+#include <linux/debugfs.h>
+#include <linux/fs.h>
MALLOC_DEFINE(M_DFSINT, "debugfsint", "Linux debugfs internal");
@@ -106,7 +104,7 @@ debugfs_destroy(PFS_DESTROY_ARGS)
struct dentry_meta *dm;
dm = pn->pn_data;
- if (dm->dm_type == DM_SYMLINK)
+ if (dm != NULL && dm->dm_type == DM_SYMLINK)
free(dm->dm_data, M_DFSINT);
free(dm, M_DFSINT);
@@ -117,51 +115,57 @@ static int
debugfs_fill(PFS_FILL_ARGS)
{
struct dentry_meta *d;
- struct linux_file lf;
- struct seq_file *sf;
+ struct linux_file lf = {};
struct vnode vn;
- void *buf;
+ char *buf;
int rc;
- size_t len;
- off_t off;
-
- d = pn->pn_data;
+ off_t off = 0;
if ((rc = linux_set_current_flags(curthread, M_NOWAIT)))
return (rc);
+
+ d = pn->pn_data;
vn.v_data = d->dm_data;
- buf = uio->uio_iov[0].iov_base;
- len = min(uio->uio_iov[0].iov_len, uio->uio_resid);
- off = 0;
- lf.private_data = NULL;
+
rc = d->dm_fops->open(&vn, &lf);
if (rc < 0) {
#ifdef INVARIANTS
- printf("%s:%d open failed with %d\n", __FUNCTION__, __LINE__, rc);
+ printf("%s:%d open failed with %d\n", __func__, __LINE__, rc);
#endif
return (-rc);
}
- sf = lf.private_data;
- sf->buf = sb;
- if (uio->uio_rw == UIO_READ) {
- if (d->dm_fops->read)
- rc = d->dm_fops->read(&lf, NULL, len, &off);
- else
- rc = ENODEV;
- } else {
- if (d->dm_fops->write)
- rc = d->dm_fops->write(&lf, buf, len, &off);
- else
- rc = ENODEV;
+
+ rc = -ENODEV;
+ switch (uio->uio_rw) {
+ case UIO_READ:
+ if (d->dm_fops->read != NULL) {
+ rc = -ENOMEM;
+ buf = malloc(sb->s_size, M_DFSINT, M_ZERO | M_NOWAIT);
+ if (buf != NULL) {
+ rc = d->dm_fops->read(&lf, buf, sb->s_size,
+ &off);
+ if (rc > 0)
+ sbuf_bcpy(sb, buf, strlen(buf));
+
+ free(buf, M_DFSINT);
+ }
+ }
+ break;
+ case UIO_WRITE:
+ if (d->dm_fops->write != NULL) {
+ sbuf_finish(sb);
+ rc = d->dm_fops->write(&lf, sbuf_data(sb), sbuf_len(sb),
+ &off);
+ }
+ break;
}
+
if (d->dm_fops->release)
d->dm_fops->release(&vn, &lf);
- else
- single_release(&vn, &lf);
if (rc < 0) {
#ifdef INVARIANTS
- printf("%s:%d read/write failed with %d\n", __FUNCTION__, __LINE__, rc);
+ printf("%s:%d read/write failed with %d\n", __func__, __LINE__, rc);
#endif
return (-rc);
}
@@ -180,8 +184,8 @@ debugfs_fill_data(PFS_FILL_ARGS)
struct dentry *
debugfs_create_file(const char *name, umode_t mode,
- struct dentry *parent, void *data,
- const struct file_operations *fops)
+ struct dentry *parent, void *data,
+ const struct file_operations *fops)
{
struct dentry_meta *dm;
struct dentry *dnode;
@@ -202,7 +206,7 @@ debugfs_create_file(const char *name, umode_t mode,
pnode = debugfs_root;
flags = fops->write ? PFS_RDWR : PFS_RD;
- dnode->d_pfs_node = pfs_create_file(pnode, name, debugfs_fill,
+ pfs_create_file(pnode, &dnode->d_pfs_node, name, debugfs_fill,
debugfs_attr, NULL, debugfs_destroy, flags | PFS_NOWAIT);
if (dnode->d_pfs_node == NULL) {
free(dm, M_DFSINT);
@@ -214,6 +218,54 @@ debugfs_create_file(const char *name, umode_t mode,
}
struct dentry *
+debugfs_create_file_size(const char *name, umode_t mode,
+ struct dentry *parent, void *data,
+ const struct file_operations *fops,
+ loff_t file_size __unused)
+{
+
+ return debugfs_create_file(name, mode, parent, data, fops);
+}
+
+/*
+ * NOTE: Files created with the _unsafe moniker will not be protected from
+ * debugfs core file removals. It is the responsibility of @fops to protect
+ * its file using debugfs_file_get() and debugfs_file_put().
+ *
+ * FreeBSD's LinuxKPI lindebugfs does not perform file removals at the time
+ * of writing. Therefore there is no difference between functions with _unsafe
+ * and functions without _unsafe when using lindebugfs. Functions with _unsafe
+ * exist only for Linux compatibility.
+ */
+struct dentry *
+debugfs_create_file_unsafe(const char *name, umode_t mode,
+ struct dentry *parent, void *data,
+ const struct file_operations *fops)
+{
+
+ return (debugfs_create_file(name, mode, parent, data, fops));
+}
+
+struct dentry *
+debugfs_create_mode_unsafe(const char *name, umode_t mode,
+ struct dentry *parent, void *data,
+ const struct file_operations *fops,
+ const struct file_operations *fops_ro,
+ const struct file_operations *fops_wo)
+{
+ umode_t read = mode & S_IRUGO;
+ umode_t write = mode & S_IWUGO;
+
+ if (read && !write)
+ return (debugfs_create_file_unsafe(name, mode, parent, data, fops_ro));
+
+ if (write && !read)
+ return (debugfs_create_file_unsafe(name, mode, parent, data, fops_wo));
+
+ return (debugfs_create_file_unsafe(name, mode, parent, data, fops));
+}
+
+struct dentry *
debugfs_create_dir(const char *name, struct dentry *parent)
{
struct dentry_meta *dm;
@@ -231,7 +283,8 @@ debugfs_create_dir(const char *name, struct dentry *parent)
else
pnode = debugfs_root;
- dnode->d_pfs_node = pfs_create_dir(pnode, name, debugfs_attr, NULL, debugfs_destroy, PFS_RD | PFS_NOWAIT);
+ pfs_create_dir(pnode, &dnode->d_pfs_node, name, debugfs_attr, NULL,
+ debugfs_destroy, PFS_RD | PFS_NOWAIT);
if (dnode->d_pfs_node == NULL) {
free(dm, M_DFSINT);
return (NULL);
@@ -242,7 +295,7 @@ debugfs_create_dir(const char *name, struct dentry *parent)
struct dentry *
debugfs_create_symlink(const char *name, struct dentry *parent,
- const char *dest)
+ const char *dest)
{
struct dentry_meta *dm;
struct dentry *dnode;
@@ -264,7 +317,8 @@ debugfs_create_symlink(const char *name, struct dentry *parent,
else
pnode = debugfs_root;
- dnode->d_pfs_node = pfs_create_link(pnode, name, &debugfs_fill_data, NULL, NULL, NULL, PFS_NOWAIT);
+ pfs_create_link(pnode, &dnode->d_pfs_node, name, &debugfs_fill_data,
+ NULL, NULL, NULL, PFS_NOWAIT);
if (dnode->d_pfs_node == NULL)
goto fail;
dnode->d_pfs_node->pn_data = dm;
@@ -276,6 +330,23 @@ debugfs_create_symlink(const char *name, struct dentry *parent,
return (NULL);
}
+struct dentry *
+debugfs_lookup(const char *name, struct dentry *parent)
+{
+ struct dentry_meta *dm;
+ struct dentry *dnode;
+ struct pfs_node *pnode;
+
+ pnode = pfs_find_node(parent->d_pfs_node, name);
+ if (pnode == NULL)
+ return (NULL);
+
+ dm = (struct dentry_meta *)pnode->pn_data;
+ dnode = &dm->dm_dnode;
+
+ return (dnode);
+}
+
void
debugfs_remove(struct dentry *dnode)
{
@@ -295,7 +366,420 @@ debugfs_remove_recursive(struct dentry *dnode)
}
static int
-debugfs_init(PFS_INIT_ARGS)
+debugfs_bool_get(void *data, uint64_t *ullval)
+{
+ bool *bval = data;
+
+ if (*bval)
+ *ullval = 1;
+ else
+ *ullval = 0;
+
+ return (0);
+}
+
+static int
+debugfs_bool_set(void *data, uint64_t ullval)
+{
+ bool *bval = data;
+
+ if (ullval)
+ *bval = 1;
+ else
+ *bval = 0;
+
+ return (0);
+}
+
+DEFINE_DEBUGFS_ATTRIBUTE(fops_bool, debugfs_bool_get, debugfs_bool_set, "%llu\n");
+DEFINE_DEBUGFS_ATTRIBUTE(fops_bool_ro, debugfs_bool_get, NULL, "%llu\n");
+DEFINE_DEBUGFS_ATTRIBUTE(fops_bool_wo, NULL, debugfs_bool_set, "%llu\n");
+
+void
+debugfs_create_bool(const char *name, umode_t mode, struct dentry *parent, bool *value)
+{
+
+ debugfs_create_mode_unsafe(name, mode, parent, value, &fops_bool,
+ &fops_bool_ro, &fops_bool_wo);
+}
+
+
+static int
+debugfs_u8_get(void *data, uint64_t *value)
+{
+ uint8_t *u8data = data;
+ *value = *u8data;
+ return (0);
+}
+
+static int
+debugfs_u8_set(void *data, uint64_t value)
+{
+ uint8_t *u8data = data;
+ *u8data = (uint8_t)value;
+ return (0);
+}
+
+DEFINE_DEBUGFS_ATTRIBUTE(fops_u8, debugfs_u8_get, debugfs_u8_set, "%u\n");
+DEFINE_DEBUGFS_ATTRIBUTE(fops_u8_ro, debugfs_u8_get, NULL, "%u\n");
+DEFINE_DEBUGFS_ATTRIBUTE(fops_u8_wo, NULL, debugfs_u8_set, "%u\n");
+
+void
+debugfs_create_u8(const char *name, umode_t mode, struct dentry *parent, uint8_t *value)
+{
+
+ debugfs_create_mode_unsafe(name, mode, parent, value, &fops_u8,
+ &fops_u8_ro, &fops_u8_wo);
+}
+
+DEFINE_DEBUGFS_ATTRIBUTE(fops_x8, debugfs_u8_get, debugfs_u8_set, "0x%016llx\n");
+DEFINE_DEBUGFS_ATTRIBUTE(fops_x8_ro, debugfs_u8_get, NULL, "0x%016llx\n");
+DEFINE_DEBUGFS_ATTRIBUTE(fops_x8_wo, NULL, debugfs_u8_set, "0x%016llx\n");
+
+void
+debugfs_create_x8(const char *name, umode_t mode, struct dentry *parent, uint8_t *value)
+{
+
+ debugfs_create_mode_unsafe(name, mode, parent, value, &fops_x8,
+ &fops_x8_ro, &fops_x8_wo);
+}
+
+
+static int
+debugfs_u16_get(void *data, uint64_t *value)
+{
+ uint16_t *u16data = data;
+ *value = *u16data;
+ return (0);
+}
+
+static int
+debugfs_u16_set(void *data, uint64_t value)
+{
+ uint16_t *u16data = data;
+ *u16data = (uint16_t)value;
+ return (0);
+}
+
+DEFINE_DEBUGFS_ATTRIBUTE(fops_u16, debugfs_u16_get, debugfs_u16_set, "%u\n");
+DEFINE_DEBUGFS_ATTRIBUTE(fops_u16_ro, debugfs_u16_get, NULL, "%u\n");
+DEFINE_DEBUGFS_ATTRIBUTE(fops_u16_wo, NULL, debugfs_u16_set, "%u\n");
+
+void
+debugfs_create_u16(const char *name, umode_t mode, struct dentry *parent, uint16_t *value)
+{
+
+ debugfs_create_mode_unsafe(name, mode, parent, value, &fops_u16,
+ &fops_u16_ro, &fops_u16_wo);
+}
+
+DEFINE_DEBUGFS_ATTRIBUTE(fops_x16, debugfs_u16_get, debugfs_u16_set, "0x%016llx\n");
+DEFINE_DEBUGFS_ATTRIBUTE(fops_x16_ro, debugfs_u16_get, NULL, "0x%016llx\n");
+DEFINE_DEBUGFS_ATTRIBUTE(fops_x16_wo, NULL, debugfs_u16_set, "0x%016llx\n");
+
+void
+debugfs_create_x16(const char *name, umode_t mode, struct dentry *parent, uint16_t *value)
+{
+
+ debugfs_create_mode_unsafe(name, mode, parent, value, &fops_x16,
+ &fops_x16_ro, &fops_x16_wo);
+}
+
+
+static int
+debugfs_u32_get(void *data, uint64_t *value)
+{
+ uint32_t *u32data = data;
+ *value = *u32data;
+ return (0);
+}
+
+static int
+debugfs_u32_set(void *data, uint64_t value)
+{
+ uint32_t *u32data = data;
+ *u32data = (uint32_t)value;
+ return (0);
+}
+
+DEFINE_DEBUGFS_ATTRIBUTE(fops_u32, debugfs_u32_get, debugfs_u32_set, "%u\n");
+DEFINE_DEBUGFS_ATTRIBUTE(fops_u32_ro, debugfs_u32_get, NULL, "%u\n");
+DEFINE_DEBUGFS_ATTRIBUTE(fops_u32_wo, NULL, debugfs_u32_set, "%u\n");
+
+void
+debugfs_create_u32(const char *name, umode_t mode, struct dentry *parent, uint32_t *value)
+{
+
+ debugfs_create_mode_unsafe(name, mode, parent, value, &fops_u32,
+ &fops_u32_ro, &fops_u32_wo);
+}
+
+DEFINE_DEBUGFS_ATTRIBUTE(fops_x32, debugfs_u32_get, debugfs_u32_set, "0x%016llx\n");
+DEFINE_DEBUGFS_ATTRIBUTE(fops_x32_ro, debugfs_u32_get, NULL, "0x%016llx\n");
+DEFINE_DEBUGFS_ATTRIBUTE(fops_x32_wo, NULL, debugfs_u32_set, "0x%016llx\n");
+
+void
+debugfs_create_x32(const char *name, umode_t mode, struct dentry *parent, uint32_t *value)
+{
+
+ debugfs_create_mode_unsafe(name, mode, parent, value, &fops_x32,
+ &fops_x32_ro, &fops_x32_wo);
+}
+
+
+static int
+debugfs_u64_get(void *data, uint64_t *value)
+{
+ uint64_t *u64data = data;
+ *value = *u64data;
+ return (0);
+}
+
+static int
+debugfs_u64_set(void *data, uint64_t value)
+{
+ uint64_t *u64data = data;
+ *u64data = (uint64_t)value;
+ return (0);
+}
+
+DEFINE_DEBUGFS_ATTRIBUTE(fops_u64, debugfs_u64_get, debugfs_u64_set, "%u\n");
+DEFINE_DEBUGFS_ATTRIBUTE(fops_u64_ro, debugfs_u64_get, NULL, "%u\n");
+DEFINE_DEBUGFS_ATTRIBUTE(fops_u64_wo, NULL, debugfs_u64_set, "%u\n");
+
+void
+debugfs_create_u64(const char *name, umode_t mode, struct dentry *parent, uint64_t *value)
+{
+
+ debugfs_create_mode_unsafe(name, mode, parent, value, &fops_u64,
+ &fops_u64_ro, &fops_u64_wo);
+}
+
+DEFINE_DEBUGFS_ATTRIBUTE(fops_x64, debugfs_u64_get, debugfs_u64_set, "0x%016llx\n");
+DEFINE_DEBUGFS_ATTRIBUTE(fops_x64_ro, debugfs_u64_get, NULL, "0x%016llx\n");
+DEFINE_DEBUGFS_ATTRIBUTE(fops_x64_wo, NULL, debugfs_u64_set, "0x%016llx\n");
+
+void
+debugfs_create_x64(const char *name, umode_t mode, struct dentry *parent, uint64_t *value)
+{
+
+ debugfs_create_mode_unsafe(name, mode, parent, value, &fops_x64,
+ &fops_x64_ro, &fops_x64_wo);
+}
+
+
+static int
+debugfs_ulong_get(void *data, uint64_t *value)
+{
+ uint64_t *uldata = data;
+ *value = *uldata;
+ return (0);
+}
+
+static int
+debugfs_ulong_set(void *data, uint64_t value)
+{
+ uint64_t *uldata = data;
+ *uldata = value;
+ return (0);
+}
+
+DEFINE_DEBUGFS_ATTRIBUTE(fops_ulong, debugfs_ulong_get, debugfs_ulong_set, "%llu\n");
+DEFINE_DEBUGFS_ATTRIBUTE(fops_ulong_ro, debugfs_ulong_get, NULL, "%llu\n");
+DEFINE_DEBUGFS_ATTRIBUTE(fops_ulong_wo, NULL, debugfs_ulong_set, "%llu\n");
+
+void
+debugfs_create_ulong(const char *name, umode_t mode, struct dentry *parent, unsigned long *value)
+{
+
+ debugfs_create_mode_unsafe(name, mode, parent, value, &fops_ulong,
+ &fops_ulong_ro, &fops_ulong_wo);
+}
+
+
+static int
+debugfs_atomic_t_get(void *data, uint64_t *value)
+{
+ atomic_t *atomic_data = data;
+ *value = atomic_read(atomic_data);
+ return (0);
+}
+
+static int
+debugfs_atomic_t_set(void *data, uint64_t value)
+{
+ atomic_t *atomic_data = data;
+ atomic_set(atomic_data, (int)value);
+ return (0);
+}
+
+DEFINE_DEBUGFS_ATTRIBUTE(fops_atomic_t, debugfs_atomic_t_get, debugfs_atomic_t_set, "%d\n");
+DEFINE_DEBUGFS_ATTRIBUTE(fops_atomic_t_ro, debugfs_atomic_t_get, NULL, "%d\n");
+DEFINE_DEBUGFS_ATTRIBUTE(fops_atomic_t_wo, NULL, debugfs_atomic_t_set, "%d\n");
+
+void
+debugfs_create_atomic_t(const char *name, umode_t mode, struct dentry *parent, atomic_t *value)
+{
+
+ debugfs_create_mode_unsafe(name, mode, parent, value, &fops_atomic_t,
+ &fops_atomic_t_ro, &fops_atomic_t_wo);
+}
+
+
+static int
+fops_str_open(struct inode *inode, struct file *filp)
+{
+
+ return (simple_open(inode, filp));
+}
+
+static ssize_t
+fops_str_read(struct file *filp, char __user *ubuf, size_t read_size,
+ loff_t *ppos)
+{
+ ssize_t ret;
+ char *str, *str_with_newline;
+ size_t str_len, str_with_newline_len;
+
+ if (filp->private_data == NULL)
+ return (-EINVAL);
+
+ str = *(char **)filp->private_data;
+ str_len = strlen(str);
+
+ /*
+ * `str_with_newline` is terminated with a newline, but is not
+ * NUL-terminated.
+ */
+ str_with_newline_len = str_len + 1;
+ str_with_newline = kmalloc(str_with_newline_len, GFP_KERNEL);
+ if (str_with_newline == NULL)
+ return (-ENOMEM);
+
+ strncpy(str_with_newline, str, str_len);
+ str_with_newline[str_len] = '\n';
+
+ ret = simple_read_from_buffer(ubuf, read_size, ppos,
+ str_with_newline, str_with_newline_len);
+
+ kfree(str_with_newline);
+
+ return (ret);
+}
+
+static ssize_t
+fops_str_write(struct file *filp, const char *buf, size_t write_size,
+ loff_t *ppos)
+{
+ char *old, *new;
+ size_t old_len, new_len;
+
+ if (filp->private_data == NULL)
+ return (-EINVAL);
+
+ old = *(char **)filp->private_data;
+ new = NULL;
+
+ /*
+ * We enforce concatenation of the newly written value to the existing
+ * value.
+ */
+ old_len = strlen(old);
+ if (*ppos && *ppos != old_len)
+ return (-EINVAL);
+
+ new_len = old_len + write_size;
+ if (new_len + 1 > PAGE_SIZE)
+ return (-E2BIG);
+
+ new = kmalloc(new_len + 1, GFP_KERNEL);
+ if (new == NULL)
+ return (-ENOMEM);
+
+ memcpy(new, old, old_len);
+ if (copy_from_user(new + old_len, buf, write_size) != 0) {
+ kfree(new);
+ return (-EFAULT);
+ }
+
+ new[new_len] = '\0';
+ strim(new);
+
+ filp->private_data = &new;
+
+ kfree(old);
+
+ return (write_size);
+}
+
+static const struct file_operations fops_str = {
+ .owner = THIS_MODULE,
+ .open = fops_str_open,
+ .read = fops_str_read,
+ .write = fops_str_write,
+ .llseek = no_llseek
+};
+static const struct file_operations fops_str_ro = {
+ .owner = THIS_MODULE,
+ .open = fops_str_open,
+ .read = fops_str_read,
+ .llseek = no_llseek
+};
+static const struct file_operations fops_str_wo = {
+ .owner = THIS_MODULE,
+ .open = fops_str_open,
+ .write = fops_str_write,
+ .llseek = no_llseek
+};
+
+void
+debugfs_create_str(const char *name, umode_t mode, struct dentry *parent,
+ char **value)
+{
+ debugfs_create_mode_unsafe(name, mode, parent, value,
+ &fops_str, &fops_str_ro, &fops_str_wo);
+}
+
+
+static ssize_t
+fops_blob_read(struct file *filp, char __user *ubuf, size_t read_size, loff_t *ppos)
+{
+ struct debugfs_blob_wrapper *blob;
+
+ blob = filp->private_data;
+ if (blob == NULL)
+ return (-EINVAL);
+ if (blob->size == 0 || blob->data == NULL)
+ return (-EINVAL);
+
+ return (simple_read_from_buffer(ubuf, read_size, ppos, blob->data, blob->size));
+}
+
+static int
+fops_blob_open(struct inode *inode, struct file *filp)
+{
+
+ return (simple_open(inode, filp));
+}
+
+static const struct file_operations __fops_blob_ro = {
+ .owner = THIS_MODULE,
+ .open = fops_blob_open,
+ .read = fops_blob_read,
+ .llseek = no_llseek
+};
+
+struct dentry *
+debugfs_create_blob(const char *name, umode_t mode, struct dentry *parent,
+ struct debugfs_blob_wrapper *value)
+{
+ /* Blobs are read-only. */
+ return (debugfs_create_file(name, mode & 0444, parent, value, &__fops_blob_ro));
+}
+
+
+static int
+lindebugfs_init(PFS_INIT_ARGS)
{
debugfs_root = pi->pi_root;
@@ -306,14 +790,11 @@ debugfs_init(PFS_INIT_ARGS)
}
static int
-debugfs_uninit(PFS_INIT_ARGS)
+lindebugfs_uninit(PFS_INIT_ARGS)
{
+
return (0);
}
-#ifdef PR_ALLOW_MOUNT_LINSYSFS
-PSEUDOFS(debugfs, 1, PR_ALLOW_MOUNT_LINSYSFS);
-#else
-PSEUDOFS(debugfs, 1, VFCF_JAIL);
-#endif
+PSEUDOFS(lindebugfs, 1, VFCF_JAIL);
MODULE_DEPEND(lindebugfs, linuxkpi, 1, 1, 1);
diff --git a/sys/compat/linprocfs/linprocfs.c b/sys/compat/linprocfs/linprocfs.c
index 09144350a8ee..7ac48786c77b 100644
--- a/sys/compat/linprocfs/linprocfs.c
+++ b/sys/compat/linprocfs/linprocfs.c
@@ -1,7 +1,7 @@
/*-
* SPDX-License-Identifier: BSD-4-Clause
*
- * Copyright (c) 2000 Dag-Erling Coïdan Smørgrav
+ * Copyright (c) 2000 Dag-Erling Smørgrav
* Copyright (c) 1999 Pierre Beyssac
* Copyright (c) 1993 Jan-Simon Pendry
* Copyright (c) 1993
@@ -37,15 +37,12 @@
* 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.
- *
- * @(#)procfs_status.c 8.4 (Berkeley) 6/15/94
*/
-#include <sys/cdefs.h>
-__FBSDID("$FreeBSD$");
+#include "opt_inet.h"
#include <sys/param.h>
-#include <sys/queue.h>
+#include <sys/systm.h>
#include <sys/blist.h>
#include <sys/conf.h>
#include <sys/exec.h>
@@ -62,6 +59,7 @@ __FBSDID("$FreeBSD$");
#include <sys/namei.h>
#include <sys/proc.h>
#include <sys/ptrace.h>
+#include <sys/queue.h>
#include <sys/resourcevar.h>
#include <sys/resource.h>
#include <sys/sbuf.h>
@@ -72,7 +70,6 @@ __FBSDID("$FreeBSD$");
#include <sys/syscallsubr.h>
#include <sys/sysctl.h>
#include <sys/sysent.h>
-#include <sys/systm.h>
#include <sys/time.h>
#include <sys/tty.h>
#include <sys/user.h>
@@ -80,11 +77,16 @@ __FBSDID("$FreeBSD$");
#include <sys/vmmeter.h>
#include <sys/vnode.h>
#include <sys/bus.h>
+#include <sys/uio.h>
#include <net/if.h>
#include <net/if_var.h>
#include <net/if_types.h>
+#include <net/route.h>
+#include <net/route/nhop.h>
+#include <net/route/route_ctl.h>
+
#include <vm/vm.h>
#include <vm/vm_extern.h>
#include <vm/pmap.h>
@@ -104,6 +106,8 @@ __FBSDID("$FreeBSD$");
#endif /* __i386__ || __amd64__ */
#include <compat/linux/linux.h>
+#include <compat/linux/linux_common.h>
+#include <compat/linux/linux_emul.h>
#include <compat/linux/linux_mib.h>
#include <compat/linux/linux_misc.h>
#include <compat/linux/linux_util.h>
@@ -195,11 +199,9 @@ linprocfs_domeminfo(PFS_FILL_ARGS)
static int
linprocfs_docpuinfo(PFS_FILL_ARGS)
{
- int hw_model[2];
- char model[128];
uint64_t freq;
- size_t size;
u_int cache_size[4];
+ u_int regs[4] = { 0 };
int fqmhz, fqkhz;
int i, j;
@@ -252,7 +254,7 @@ linprocfs_docpuinfo(PFS_FILL_ARGS)
};
static char *cpu_stdext_feature_names[] = {
- /* 0 */ "fsgsbase", "tsc_adjust", "", "bmi1",
+ /* 0 */ "fsgsbase", "tsc_adjust", "sgx", "bmi1",
/* 4 */ "hle", "avx2", "", "smep",
/* 8 */ "bmi2", "erms", "invpcid", "rtm",
/* 12 */ "cqm", "", "mpx", "rdt_a",
@@ -262,6 +264,33 @@ linprocfs_docpuinfo(PFS_FILL_ARGS)
/* 28 */ "avx512cd", "sha_ni", "avx512bw", "avx512vl"
};
+ static char *cpu_stdext_feature2_names[] = {
+ /* 0 */ "prefetchwt1", "avx512vbmi", "umip", "pku",
+ /* 4 */ "ospke", "waitpkg", "avx512_vbmi2", "",
+ /* 8 */ "gfni", "vaes", "vpclmulqdq", "avx512_vnni",
+ /* 12 */ "avx512_bitalg", "", "avx512_vpopcntdq", "",
+ /* 16 */ "", "", "", "",
+ /* 20 */ "", "", "rdpid", "",
+ /* 24 */ "", "cldemote", "", "movdiri",
+ /* 28 */ "movdir64b", "enqcmd", "sgx_lc", ""
+ };
+
+ static char *cpu_stdext_feature3_names[] = {
+ /* 0 */ "", "", "avx512_4vnniw", "avx512_4fmaps",
+ /* 4 */ "fsrm", "", "", "",
+ /* 8 */ "avx512_vp2intersect", "", "md_clear", "",
+ /* 12 */ "", "", "", "",
+ /* 16 */ "", "", "pconfig", "",
+ /* 20 */ "", "", "", "",
+ /* 24 */ "", "", "ibrs", "stibp",
+ /* 28 */ "flush_l1d", "arch_capabilities", "core_capabilities", "ssbd"
+ };
+
+ static char *cpu_stdext_feature_l1_names[] = {
+ /* 0 */ "xsaveopt", "xsavec", "xgetbv1", "xsaves",
+ /* 4 */ "xfd"
+ };
+
static char *power_flags[] = {
"ts", "fid", "vid",
"ttp", "tm", "stc",
@@ -270,12 +299,6 @@ linprocfs_docpuinfo(PFS_FILL_ARGS)
"acc_power",
};
- hw_model[0] = CTL_HW;
- hw_model[1] = HW_MODEL;
- model[0] = '\0';
- size = sizeof(model);
- if (kernel_sysctl(td, hw_model, 2, &model, &size, 0, 0, 0, 0) != 0)
- strcpy(model, "unknown");
#ifdef __i386__
switch (cpu_vendor_id) {
case CPU_VENDOR_AMD:
@@ -319,7 +342,7 @@ linprocfs_docpuinfo(PFS_FILL_ARGS)
"cpuid level\t: %d\n"
"wp\t\t: %s\n",
i, cpu_vendor, CPUID_TO_FAMILY(cpu_id),
- CPUID_TO_MODEL(cpu_id), model, cpu_id & CPUID_STEPPING,
+ CPUID_TO_MODEL(cpu_id), cpu_model, cpu_id & CPUID_STEPPING,
fqmhz, fqkhz,
(cache_size[2] >> 16), 0, mp_ncpus, i, mp_ncpus,
i, i, /*cpu_id & CPUID_LOCAL_APIC_ID ??*/
@@ -347,6 +370,26 @@ linprocfs_docpuinfo(PFS_FILL_ARGS)
cpu_stdext_feature_names[j][0] != '\0')
sbuf_printf(sb, " %s",
cpu_stdext_feature_names[j]);
+ if (tsc_is_invariant)
+ sbuf_cat(sb, " constant_tsc");
+ for (j = 0; j < nitems(cpu_stdext_feature2_names); j++)
+ if (cpu_stdext_feature2 & (1 << j) &&
+ cpu_stdext_feature2_names[j][0] != '\0')
+ sbuf_printf(sb, " %s",
+ cpu_stdext_feature2_names[j]);
+ for (j = 0; j < nitems(cpu_stdext_feature3_names); j++)
+ if (cpu_stdext_feature3 & (1 << j) &&
+ cpu_stdext_feature3_names[j][0] != '\0')
+ sbuf_printf(sb, " %s",
+ cpu_stdext_feature3_names[j]);
+ if ((cpu_feature2 & CPUID2_XSAVE) != 0) {
+ cpuid_count(0xd, 0x1, regs);
+ for (j = 0; j < nitems(cpu_stdext_feature_l1_names); j++)
+ if (regs[0] & (1 << j) &&
+ cpu_stdext_feature_l1_names[j][0] != '\0')
+ sbuf_printf(sb, " %s",
+ cpu_stdext_feature_l1_names[j]);
+ }
sbuf_cat(sb, "\n");
sbuf_printf(sb,
"bugs\t\t: %s\n"
@@ -403,9 +446,6 @@ linprocfs_docpuinfo(PFS_FILL_ARGS)
}
#endif /* __i386__ || __amd64__ */
-static const char *path_slash_sys = "/sys";
-static const char *fstype_sysfs = "sysfs";
-
static int
_mtab_helper(const struct pfs_node *pn, const struct statfs *sp,
const char **mntfrom, const char **mntto, const char **fstype)
@@ -433,8 +473,7 @@ _mtab_helper(const struct pfs_node *pn, const struct statfs *sp,
}
if (strcmp(*fstype, "linsysfs") == 0) {
- *mntfrom = path_slash_sys;
- *fstype = fstype_sysfs;
+ *mntfrom = *fstype = "sysfs";
} else {
/* For Linux msdosfs is called vfat */
if (strcmp(*fstype, "msdosfs") == 0)
@@ -469,37 +508,32 @@ _sbuf_mntoptions_helper(struct sbuf *sb, uint64_t f_flags)
static int
linprocfs_domtab(PFS_FILL_ARGS)
{
- struct nameidata nd;
- const char *lep, *mntto, *mntfrom, *fstype;
+ const char *mntto, *mntfrom, *fstype;
char *dlep, *flep;
+ struct vnode *vp;
+ struct pwd *pwd;
size_t lep_len;
int error;
struct statfs *buf, *sp;
size_t count;
- /* resolve symlinks etc. in the emulation tree prefix */
/*
- * Ideally, this would use the current chroot rather than some
- * hardcoded path.
+ * Resolve emulation tree prefix
*/
- NDINIT(&nd, LOOKUP, FOLLOW, UIO_SYSSPACE, linux_emul_path);
flep = NULL;
- error = namei(&nd);
- lep = linux_emul_path;
- if (error == 0) {
- if (vn_fullpath(nd.ni_vp, &dlep, &flep) == 0)
- lep = dlep;
- vrele(nd.ni_vp);
- }
- lep_len = strlen(lep);
+ pwd = pwd_hold(td);
+ vp = pwd->pwd_adir;
+ error = vn_fullpath_global(vp, &dlep, &flep);
+ pwd_drop(pwd);
+ if (error != 0)
+ return (error);
+ lep_len = strlen(dlep);
buf = NULL;
error = kern_getfsstat(td, &buf, SIZE_T_MAX, &count,
UIO_SYSSPACE, MNT_WAIT);
if (error != 0) {
- free(buf, M_TEMP);
- free(flep, M_TEMP);
- return (error);
+ goto out;
}
for (sp = buf; count > 0; sp++, count--) {
@@ -510,7 +544,7 @@ linprocfs_domtab(PFS_FILL_ARGS)
}
/* determine mount point */
- if (strncmp(mntto, lep, lep_len) == 0 && mntto[lep_len] == '/')
+ if (strncmp(mntto, dlep, lep_len) == 0 && mntto[lep_len] == '/')
mntto += lep_len;
sbuf_printf(sb, "%s %s %s ", mntfrom, mntto, fstype);
@@ -519,6 +553,8 @@ linprocfs_domtab(PFS_FILL_ARGS)
sbuf_printf(sb, " 0 0\n");
}
+ error = 0;
+out:
free(buf, M_TEMP);
free(flep, M_TEMP);
return (error);
@@ -527,28 +563,25 @@ linprocfs_domtab(PFS_FILL_ARGS)
static int
linprocfs_doprocmountinfo(PFS_FILL_ARGS)
{
- struct nameidata nd;
const char *mntfrom, *mntto, *fstype;
- const char *lep;
char *dlep, *flep;
struct statfs *buf, *sp;
size_t count, lep_len;
+ struct vnode *vp;
+ struct pwd *pwd;
int error;
/*
- * Ideally, this would use the current chroot rather than some
- * hardcoded path.
+ * Resolve emulation tree prefix
*/
- NDINIT(&nd, LOOKUP, FOLLOW, UIO_SYSSPACE, linux_emul_path);
flep = NULL;
- error = namei(&nd);
- lep = linux_emul_path;
- if (error == 0) {
- if (vn_fullpath(nd.ni_vp, &dlep, &flep) == 0)
- lep = dlep;
- vrele(nd.ni_vp);
- }
- lep_len = strlen(lep);
+ pwd = pwd_hold(td);
+ vp = pwd->pwd_adir;
+ error = vn_fullpath_global(vp, &dlep, &flep);
+ pwd_drop(pwd);
+ if (error != 0)
+ return (error);
+ lep_len = strlen(dlep);
buf = NULL;
error = kern_getfsstat(td, &buf, SIZE_T_MAX, &count,
@@ -563,7 +596,7 @@ linprocfs_doprocmountinfo(PFS_FILL_ARGS)
continue;
}
- if (strncmp(mntto, lep, lep_len) == 0 && mntto[lep_len] == '/')
+ if (strncmp(mntto, dlep, lep_len) == 0 && mntto[lep_len] == '/')
mntto += lep_len;
#if 0
/*
@@ -966,7 +999,7 @@ linprocfs_doprocstat(PFS_FILL_ARGS)
PS_ADD("0", "%d", 0); /* removed field */
PS_ADD("itrealvalue", "%d", 0); /* XXX */
PS_ADD("starttime", "%lu", TV2J(&kp.ki_start) - TV2J(&boottime));
- PS_ADD("vsize", "%ju", P2K((uintmax_t)kp.ki_size));
+ PS_ADD("vsize", "%ju", (uintmax_t)kp.ki_size);
PS_ADD("rss", "%ju", (uintmax_t)kp.ki_rssize);
PS_ADD("rlim", "%lu", kp.ki_rusage.ru_maxrss);
PS_ADD("startcode", "%ju", (uintmax_t)startcode);
@@ -1040,7 +1073,7 @@ linprocfs_doprocstatus(PFS_FILL_ARGS)
sx_slock(&proctree_lock);
PROC_LOCK(p);
- td2 = FIRST_THREAD_IN_PROC(p); /* XXXKSE pretend only one thread */
+ td2 = FIRST_THREAD_IN_PROC(p);
if (P_SHOULDSTOP(p)) {
state = "T (stopped)";
@@ -1305,7 +1338,13 @@ linprocfs_doprocmaps(PFS_FILL_ARGS)
VM_MAP_ENTRY_FOREACH(entry, map) {
name = "";
freename = NULL;
- if (entry->eflags & MAP_ENTRY_IS_SUB_MAP)
+ /*
+ * Skip printing of the guard page of the stack region, as
+ * it confuses glibc pthread_getattr_np() method, where both
+ * the base address and size of the stack of the initial thread
+ * are calculated.
+ */
+ if ((entry->eflags & (MAP_ENTRY_IS_SUB_MAP | MAP_ENTRY_GUARD)) != 0)
continue;
e_prot = entry->protection;
e_start = entry->start;
@@ -1413,42 +1452,51 @@ linprocfs_doprocmem(PFS_FILL_ARGS)
}
/*
- * Criteria for interface name translation
+ * Filler function for proc/net/dev
*/
-#define IFP_IS_ETH(ifp) (ifp->if_type == IFT_ETHER)
-
static int
-linux_ifname(struct ifnet *ifp, char *buffer, size_t buflen)
+linprocfs_donetdev_cb(if_t ifp, void *arg)
{
- struct ifnet *ifscan;
- int ethno;
-
- IFNET_RLOCK_ASSERT();
-
- /* Short-circuit non ethernet interfaces */
- if (!IFP_IS_ETH(ifp))
- return (strlcpy(buffer, ifp->if_xname, buflen));
-
- /* Determine the (relative) unit number for ethernet interfaces */
- ethno = 0;
- CK_STAILQ_FOREACH(ifscan, &V_ifnet, if_link) {
- if (ifscan == ifp)
- return (snprintf(buffer, buflen, "eth%d", ethno));
- if (IFP_IS_ETH(ifscan))
- ethno++;
- }
-
+ char ifname[LINUX_IFNAMSIZ];
+ struct sbuf *sb = arg;
+
+ if (ifname_bsd_to_linux_ifp(ifp, ifname, sizeof(ifname)) <= 0)
+ return (ENODEV);
+
+ sbuf_printf(sb, "%6.6s: ", ifname);
+ sbuf_printf(sb, "%7ju %7ju %4ju %4ju %4lu %5lu %10lu %9ju ",
+ (uintmax_t)if_getcounter(ifp, IFCOUNTER_IBYTES),
+ (uintmax_t)if_getcounter(ifp, IFCOUNTER_IPACKETS),
+ (uintmax_t)if_getcounter(ifp, IFCOUNTER_IERRORS),
+ (uintmax_t)if_getcounter(ifp, IFCOUNTER_IQDROPS),
+ /* rx_missed_errors */
+ 0UL, /* rx_fifo_errors */
+ 0UL, /* rx_length_errors +
+ * rx_over_errors +
+ * rx_crc_errors +
+ * rx_frame_errors */
+ 0UL, /* rx_compressed */
+ (uintmax_t)if_getcounter(ifp, IFCOUNTER_IMCASTS));
+ /* XXX-BZ rx only? */
+ sbuf_printf(sb, "%8ju %7ju %4ju %4ju %4lu %5ju %7lu %10lu\n",
+ (uintmax_t)if_getcounter(ifp, IFCOUNTER_OBYTES),
+ (uintmax_t)if_getcounter(ifp, IFCOUNTER_OPACKETS),
+ (uintmax_t)if_getcounter(ifp, IFCOUNTER_OERRORS),
+ (uintmax_t)if_getcounter(ifp, IFCOUNTER_OQDROPS),
+ 0UL, /* tx_fifo_errors */
+ (uintmax_t)if_getcounter(ifp, IFCOUNTER_COLLISIONS),
+ 0UL, /* tx_carrier_errors +
+ * tx_aborted_errors +
+ * tx_window_errors +
+ * tx_heartbeat_errors*/
+ 0UL); /* tx_compressed */
return (0);
}
-/*
- * Filler function for proc/net/dev
- */
static int
linprocfs_donetdev(PFS_FILL_ARGS)
{
- char ifname[16]; /* XXX LINUX_IFNAMSIZ */
- struct ifnet *ifp;
+ struct epoch_tracker et;
sbuf_printf(sb, "%6s|%58s|%s\n"
"%6s|%58s|%58s\n",
@@ -1458,38 +1506,82 @@ linprocfs_donetdev(PFS_FILL_ARGS)
"bytes packets errs drop fifo colls carrier compressed");
CURVNET_SET(TD_TO_VNET(curthread));
- IFNET_RLOCK();
- CK_STAILQ_FOREACH(ifp, &V_ifnet, if_link) {
- linux_ifname(ifp, ifname, sizeof ifname);
- sbuf_printf(sb, "%6.6s: ", ifname);
- sbuf_printf(sb, "%7ju %7ju %4ju %4ju %4lu %5lu %10lu %9ju ",
- (uintmax_t )ifp->if_get_counter(ifp, IFCOUNTER_IBYTES),
- (uintmax_t )ifp->if_get_counter(ifp, IFCOUNTER_IPACKETS),
- (uintmax_t )ifp->if_get_counter(ifp, IFCOUNTER_IERRORS),
- (uintmax_t )ifp->if_get_counter(ifp, IFCOUNTER_IQDROPS),
- /* rx_missed_errors */
- 0UL, /* rx_fifo_errors */
- 0UL, /* rx_length_errors +
- * rx_over_errors +
- * rx_crc_errors +
- * rx_frame_errors */
- 0UL, /* rx_compressed */
- (uintmax_t )ifp->if_get_counter(ifp, IFCOUNTER_IMCASTS));
- /* XXX-BZ rx only? */
- sbuf_printf(sb, "%8ju %7ju %4ju %4ju %4lu %5ju %7lu %10lu\n",
- (uintmax_t )ifp->if_get_counter(ifp, IFCOUNTER_OBYTES),
- (uintmax_t )ifp->if_get_counter(ifp, IFCOUNTER_OPACKETS),
- (uintmax_t )ifp->if_get_counter(ifp, IFCOUNTER_OERRORS),
- (uintmax_t )ifp->if_get_counter(ifp, IFCOUNTER_OQDROPS),
- 0UL, /* tx_fifo_errors */
- (uintmax_t )ifp->if_get_counter(ifp, IFCOUNTER_COLLISIONS),
- 0UL, /* tx_carrier_errors +
- * tx_aborted_errors +
- * tx_window_errors +
- * tx_heartbeat_errors*/
- 0UL); /* tx_compressed */
- }
- IFNET_RUNLOCK();
+ NET_EPOCH_ENTER(et);
+ if_foreach(linprocfs_donetdev_cb, sb);
+ NET_EPOCH_EXIT(et);
+ CURVNET_RESTORE();
+
+ return (0);
+}
+
+struct walkarg {
+ struct sbuf *sb;
+};
+
+static int
+linux_route_print(struct rtentry *rt, void *vw)
+{
+#ifdef INET
+ struct walkarg *w = vw;
+ struct route_nhop_data rnd;
+ struct in_addr dst, mask;
+ struct nhop_object *nh;
+ char ifname[16];
+ uint32_t scopeid = 0;
+ uint32_t gw = 0;
+ uint32_t linux_flags = 0;
+
+ rt_get_inet_prefix_pmask(rt, &dst, &mask, &scopeid);
+
+ rt_get_rnd(rt, &rnd);
+
+ /* select only first route in case of multipath */
+ nh = nhop_select_func(rnd.rnd_nhop, 0);
+
+ if (ifname_bsd_to_linux_ifp(nh->nh_ifp, ifname, sizeof(ifname)) <= 0)
+ return (ENODEV);
+
+ gw = (nh->nh_flags & NHF_GATEWAY)
+ ? nh->gw4_sa.sin_addr.s_addr : 0;
+
+ linux_flags = RTF_UP |
+ (nhop_get_rtflags(nh) & (RTF_GATEWAY | RTF_HOST));
+
+ sbuf_printf(w->sb,
+ "%s\t"
+ "%08X\t%08X\t%04X\t"
+ "%d\t%u\t%d\t"
+ "%08X\t%d\t%u\t%u",
+ ifname,
+ dst.s_addr, gw, linux_flags,
+ 0, 0, rnd.rnd_weight,
+ mask.s_addr, nh->nh_mtu, 0, 0);
+
+ sbuf_printf(w->sb, "\n\n");
+#endif
+ return (0);
+}
+
+/*
+ * Filler function for proc/net/route
+ */
+static int
+linprocfs_donetroute(PFS_FILL_ARGS)
+{
+ struct epoch_tracker et;
+ struct walkarg w = {
+ .sb = sb
+ };
+ uint32_t fibnum = curthread->td_proc->p_fibnum;
+
+ sbuf_printf(w.sb, "%-127s\n", "Iface\tDestination\tGateway "
+ "\tFlags\tRefCnt\tUse\tMetric\tMask\t\tMTU"
+ "\tWindow\tIRTT");
+
+ CURVNET_SET(TD_TO_VNET(curthread));
+ NET_EPOCH_ENTER(et);
+ rib_walk(fibnum, AF_INET, false, linux_route_print, &w);
+ NET_EPOCH_EXIT(et);
CURVNET_RESTORE();
return (0);
@@ -1819,7 +1911,7 @@ linprocfs_doproclimits(PFS_FILL_ARGS)
"kern.sigqueue.max_pending_per_proc",
&res, &size, 0, 0, 0, 0);
if (error != 0)
- goto out;
+ continue;
rl.rlim_cur = res;
rl.rlim_max = res;
break;
@@ -1827,7 +1919,7 @@ linprocfs_doproclimits(PFS_FILL_ARGS)
error = kernel_sysctlbyname(td,
"kern.ipc.msgmnb", &res, &size, 0, 0, 0, 0);
if (error != 0)
- goto out;
+ continue;
rl.rlim_cur = res;
rl.rlim_max = res;
break;
@@ -1849,9 +1941,9 @@ linprocfs_doproclimits(PFS_FILL_ARGS)
li->desc, (unsigned long long)rl.rlim_cur,
(unsigned long long)rl.rlim_max, li->unit);
}
-out:
+
lim_free(limp);
- return (error);
+ return (0);
}
/*
@@ -1891,6 +1983,24 @@ linprocfs_douuid(PFS_FILL_ARGS)
}
/*
+ * Filler function for proc/sys/kernel/random/boot_id
+ */
+static int
+linprocfs_doboot_id(PFS_FILL_ARGS)
+{
+ static bool firstboot = 1;
+ static struct uuid uuid;
+
+ if (firstboot) {
+ kern_uuidgen(&uuid, 1);
+ firstboot = 0;
+ }
+ sbuf_printf_uuid(sb, &uuid);
+ sbuf_printf(sb, "\n");
+ return(0);
+}
+
+/*
* Filler function for proc/pid/auxv
*/
static int
@@ -1938,144 +2048,504 @@ linprocfs_doauxv(PFS_FILL_ARGS)
}
/*
+ * Filler function for proc/self/oom_score_adj
+ */
+static int
+linprocfs_do_oom_score_adj(PFS_FILL_ARGS)
+{
+ struct linux_pemuldata *pem;
+ long oom;
+
+ pem = pem_find(p);
+ if (pem == NULL || uio == NULL)
+ return (EOPNOTSUPP);
+ if (uio->uio_rw == UIO_READ) {
+ sbuf_printf(sb, "%d\n", pem->oom_score_adj);
+ } else {
+ sbuf_trim(sb);
+ sbuf_finish(sb);
+ oom = strtol(sbuf_data(sb), NULL, 10);
+ if (oom < LINUX_OOM_SCORE_ADJ_MIN ||
+ oom > LINUX_OOM_SCORE_ADJ_MAX)
+ return (EINVAL);
+ pem->oom_score_adj = oom;
+ }
+ return (0);
+}
+
+/*
+ * Filler function for proc/sys/vm/max_map_count
+ *
+ * Maximum number of active map areas, on Linux this limits the number
+ * of vmaps per mm struct. We don't limit mappings, return a suitable
+ * large value.
+ */
+static int
+linprocfs_domax_map_cnt(PFS_FILL_ARGS)
+{
+
+ sbuf_printf(sb, "%d\n", INT32_MAX);
+ return (0);
+}
+
+/*
+ * Filler function for proc/sysvipc/msg
+ */
+static int
+linprocfs_dosysvipc_msg(PFS_FILL_ARGS)
+{
+ struct msqid_kernel *msqids;
+ size_t id, size;
+ int error;
+
+ sbuf_printf(sb,
+ "%10s %10s %4s %10s %10s %5s %5s %5s %5s %5s %5s %10s %10s %10s\n",
+ "key", "msqid", "perms", "cbytes", "qnum", "lspid", "lrpid",
+ "uid", "gid", "cuid", "cgid", "stime", "rtime", "ctime");
+
+ error = kern_get_msqids(curthread, &msqids, &size);
+ if (error != 0)
+ return (error);
+
+ for (id = 0; id < size; id++) {
+ if (msqids[id].u.msg_qbytes == 0)
+ continue;
+ sbuf_printf(sb,
+ "%10d %10zu %4o %10lu %10lu %5u %5u %5u %5u %5u %5u %jd %jd %jd\n",
+ (int)msqids[id].u.msg_perm.key,
+ IXSEQ_TO_IPCID(id, msqids[id].u.msg_perm),
+ msqids[id].u.msg_perm.mode,
+ msqids[id].u.msg_cbytes,
+ msqids[id].u.msg_qnum,
+ msqids[id].u.msg_lspid,
+ msqids[id].u.msg_lrpid,
+ msqids[id].u.msg_perm.uid,
+ msqids[id].u.msg_perm.gid,
+ msqids[id].u.msg_perm.cuid,
+ msqids[id].u.msg_perm.cgid,
+ (intmax_t)msqids[id].u.msg_stime,
+ (intmax_t)msqids[id].u.msg_rtime,
+ (intmax_t)msqids[id].u.msg_ctime);
+ }
+
+ free(msqids, M_TEMP);
+ return (0);
+}
+
+/*
+ * Filler function for proc/sysvipc/sem
+ */
+static int
+linprocfs_dosysvipc_sem(PFS_FILL_ARGS)
+{
+ struct semid_kernel *semids;
+ size_t id, size;
+ int error;
+
+ sbuf_printf(sb, "%10s %10s %4s %10s %5s %5s %5s %5s %10s %10s\n",
+ "key", "semid", "perms", "nsems", "uid", "gid", "cuid", "cgid",
+ "otime", "ctime");
+
+ error = kern_get_sema(curthread, &semids, &size);
+ if (error != 0)
+ return (error);
+
+ for (id = 0; id < size; id++) {
+ if ((semids[id].u.sem_perm.mode & SEM_ALLOC) == 0)
+ continue;
+ sbuf_printf(sb,
+ "%10d %10zu %4o %10u %5u %5u %5u %5u %jd %jd\n",
+ (int)semids[id].u.sem_perm.key,
+ IXSEQ_TO_IPCID(id, semids[id].u.sem_perm),
+ semids[id].u.sem_perm.mode,
+ semids[id].u.sem_nsems,
+ semids[id].u.sem_perm.uid,
+ semids[id].u.sem_perm.gid,
+ semids[id].u.sem_perm.cuid,
+ semids[id].u.sem_perm.cgid,
+ (intmax_t)semids[id].u.sem_otime,
+ (intmax_t)semids[id].u.sem_ctime);
+ }
+
+ free(semids, M_TEMP);
+ return (0);
+}
+
+/*
+ * Filler function for proc/sysvipc/shm
+ */
+static int
+linprocfs_dosysvipc_shm(PFS_FILL_ARGS)
+{
+ struct shmid_kernel *shmids;
+ size_t id, size;
+ int error;
+
+ sbuf_printf(sb,
+ "%10s %10s %s %21s %5s %5s %5s %5s %5s %5s %5s %10s %10s %10s %21s %21s\n",
+ "key", "shmid", "perms", "size", "cpid", "lpid", "nattch", "uid",
+ "gid", "cuid", "cgid", "atime", "dtime", "ctime", "rss", "swap");
+
+ error = kern_get_shmsegs(curthread, &shmids, &size);
+ if (error != 0)
+ return (error);
+
+ for (id = 0; id < size; id++) {
+ if ((shmids[id].u.shm_perm.mode & SHMSEG_ALLOCATED) == 0)
+ continue;
+ sbuf_printf(sb,
+ "%10d %10zu %4o %21zu %5u %5u %5u %5u %5u %5u %5u %jd %jd %jd %21d %21d\n",
+ (int)shmids[id].u.shm_perm.key,
+ IXSEQ_TO_IPCID(id, shmids[id].u.shm_perm),
+ shmids[id].u.shm_perm.mode,
+ shmids[id].u.shm_segsz,
+ shmids[id].u.shm_cpid,
+ shmids[id].u.shm_lpid,
+ shmids[id].u.shm_nattch,
+ shmids[id].u.shm_perm.uid,
+ shmids[id].u.shm_perm.gid,
+ shmids[id].u.shm_perm.cuid,
+ shmids[id].u.shm_perm.cgid,
+ (intmax_t)shmids[id].u.shm_atime,
+ (intmax_t)shmids[id].u.shm_dtime,
+ (intmax_t)shmids[id].u.shm_ctime,
+ 0, 0); /* XXX rss & swp are not supported */
+ }
+
+ free(shmids, M_TEMP);
+ return (0);
+}
+
+static int
+linprocfs_doinotify(const char *sysctl, PFS_FILL_ARGS)
+{
+ size_t size;
+ int error, val;
+
+ if (uio->uio_rw == UIO_READ) {
+ size = sizeof(val);
+ error = kernel_sysctlbyname(curthread,
+ __DECONST(void *, sysctl), &val, &size, NULL, 0, 0, 0);
+ if (error == 0)
+ sbuf_printf(sb, "%d\n", val);
+ } else {
+ char *endp, *newval;
+ long vall;
+
+ sbuf_trim(sb);
+ sbuf_finish(sb);
+ newval = sbuf_data(sb);
+ vall = strtol(newval, &endp, 10);
+ if (vall < 0 || vall > INT_MAX || endp == newval ||
+ *endp != '\0')
+ return (EINVAL);
+ val = (int)vall;
+ error = kernel_sysctlbyname(curthread,
+ __DECONST(void *, sysctl), NULL, NULL,
+ &val, sizeof(val), 0, 0);
+ }
+ return (error);
+}
+
+/*
+ * Filler function for proc/sys/fs/inotify/max_queued_events
+ */
+static int
+linprocfs_doinotify_max_queued_events(PFS_FILL_ARGS)
+{
+ return (linprocfs_doinotify("vfs.inotify.max_queued_events",
+ PFS_FILL_ARGNAMES));
+}
+
+/*
+ * Filler function for proc/sys/fs/inotify/max_user_instances
+ */
+static int
+linprocfs_doinotify_max_user_instances(PFS_FILL_ARGS)
+{
+ return (linprocfs_doinotify("vfs.inotify.max_user_instances",
+ PFS_FILL_ARGNAMES));
+}
+
+/*
+ * Filler function for proc/sys/fs/inotify/max_user_watches
+ */
+static int
+linprocfs_doinotify_max_user_watches(PFS_FILL_ARGS)
+{
+ return (linprocfs_doinotify("vfs.inotify.max_user_watches",
+ PFS_FILL_ARGNAMES));
+}
+
+/*
+ * Filler function for proc/sys/fs/mqueue/msg_default
+ */
+static int
+linprocfs_domqueue_msg_default(PFS_FILL_ARGS)
+{
+ int res, error;
+ size_t size = sizeof(res);
+
+ error = kernel_sysctlbyname(curthread, "kern.mqueue.default_maxmsg",
+ &res, &size, NULL, 0, 0, 0);
+ if (error != 0)
+ return (error);
+
+ sbuf_printf(sb, "%d\n", res);
+ return (0);
+}
+
+/*
+ * Filler function for proc/sys/fs/mqueue/msgsize_default
+ */
+static int
+linprocfs_domqueue_msgsize_default(PFS_FILL_ARGS)
+{
+ int res, error;
+ size_t size = sizeof(res);
+
+ error = kernel_sysctlbyname(curthread, "kern.mqueue.default_msgsize",
+ &res, &size, NULL, 0, 0, 0);
+ if (error != 0)
+ return (error);
+
+ sbuf_printf(sb, "%d\n", res);
+ return (0);
+
+}
+
+/*
+ * Filler function for proc/sys/fs/mqueue/msg_max
+ */
+static int
+linprocfs_domqueue_msg_max(PFS_FILL_ARGS)
+{
+ int res, error;
+ size_t size = sizeof(res);
+
+ error = kernel_sysctlbyname(curthread, "kern.mqueue.maxmsg",
+ &res, &size, NULL, 0, 0, 0);
+ if (error != 0)
+ return (error);
+
+ sbuf_printf(sb, "%d\n", res);
+ return (0);
+}
+
+/*
+ * Filler function for proc/sys/fs/mqueue/msgsize_max
+ */
+static int
+linprocfs_domqueue_msgsize_max(PFS_FILL_ARGS)
+{
+ int res, error;
+ size_t size = sizeof(res);
+
+ error = kernel_sysctlbyname(curthread, "kern.mqueue.maxmsgsize",
+ &res, &size, NULL, 0, 0, 0);
+ if (error != 0)
+ return (error);
+
+ sbuf_printf(sb, "%d\n", res);
+ return (0);
+}
+
+/*
+ * Filler function for proc/sys/fs/mqueue/queues_max
+ */
+static int
+linprocfs_domqueue_queues_max(PFS_FILL_ARGS)
+{
+ int res, error;
+ size_t size = sizeof(res);
+
+ error = kernel_sysctlbyname(curthread, "kern.mqueue.maxmq",
+ &res, &size, NULL, 0, 0, 0);
+ if (error != 0)
+ return (error);
+
+ sbuf_printf(sb, "%d\n", res);
+ return (0);
+}
+
+/*
* Constructor
*/
static int
linprocfs_init(PFS_INIT_ARGS)
{
- struct pfs_node *root;
- struct pfs_node *dir;
- struct pfs_node *sys;
+ struct pfs_node *dir, *fs, *root, *sys;
root = pi->pi_root;
/* /proc/... */
- pfs_create_file(root, "cmdline", &linprocfs_docmdline,
- NULL, NULL, NULL, PFS_RD);
- pfs_create_file(root, "cpuinfo", &linprocfs_docpuinfo,
- NULL, NULL, NULL, PFS_RD);
- pfs_create_file(root, "devices", &linprocfs_dodevices,
- NULL, NULL, NULL, PFS_RD);
- pfs_create_file(root, "filesystems", &linprocfs_dofilesystems,
- NULL, NULL, NULL, PFS_RD);
- pfs_create_file(root, "loadavg", &linprocfs_doloadavg,
- NULL, NULL, NULL, PFS_RD);
- pfs_create_file(root, "meminfo", &linprocfs_domeminfo,
- NULL, NULL, NULL, PFS_RD);
- pfs_create_file(root, "modules", &linprocfs_domodules,
- NULL, NULL, NULL, PFS_RD);
- pfs_create_file(root, "mounts", &linprocfs_domtab,
- NULL, NULL, NULL, PFS_RD);
- pfs_create_file(root, "mtab", &linprocfs_domtab,
- NULL, NULL, NULL, PFS_RD);
- pfs_create_file(root, "partitions", &linprocfs_dopartitions,
- NULL, NULL, NULL, PFS_RD);
- pfs_create_link(root, "self", &procfs_docurproc,
- NULL, NULL, NULL, 0);
- pfs_create_file(root, "stat", &linprocfs_dostat,
- NULL, NULL, NULL, PFS_RD);
- pfs_create_file(root, "swaps", &linprocfs_doswaps,
- NULL, NULL, NULL, PFS_RD);
- pfs_create_file(root, "uptime", &linprocfs_douptime,
- NULL, NULL, NULL, PFS_RD);
- pfs_create_file(root, "version", &linprocfs_doversion,
+ pfs_create_file(root, NULL, "cmdline", &linprocfs_docmdline, NULL, NULL,
+ NULL, PFS_RD);
+ pfs_create_file(root, NULL, "cpuinfo", &linprocfs_docpuinfo, NULL, NULL,
+ NULL, PFS_RD);
+ pfs_create_file(root, NULL, "devices", &linprocfs_dodevices, NULL, NULL,
+ NULL, PFS_RD);
+ pfs_create_file(root, NULL, "filesystems", &linprocfs_dofilesystems,
NULL, NULL, NULL, PFS_RD);
+ pfs_create_file(root, NULL, "loadavg", &linprocfs_doloadavg, NULL, NULL,
+ NULL, PFS_RD);
+ pfs_create_file(root, NULL, "meminfo", &linprocfs_domeminfo, NULL, NULL,
+ NULL, PFS_RD);
+ pfs_create_file(root, NULL, "modules", &linprocfs_domodules, NULL, NULL,
+ NULL, PFS_RD);
+ pfs_create_file(root, NULL, "mounts", &linprocfs_domtab, NULL, NULL,
+ NULL, PFS_RD);
+ pfs_create_file(root, NULL, "mtab", &linprocfs_domtab, NULL, NULL, NULL,
+ PFS_RD);
+ pfs_create_file(root, NULL, "partitions", &linprocfs_dopartitions, NULL,
+ NULL, NULL, PFS_RD);
+ pfs_create_link(root, NULL, "self", &procfs_docurproc, NULL, NULL, NULL,
+ 0);
+ pfs_create_file(root, NULL, "stat", &linprocfs_dostat, NULL, NULL, NULL,
+ PFS_RD);
+ pfs_create_file(root, NULL, "swaps", &linprocfs_doswaps, NULL, NULL,
+ NULL, PFS_RD);
+ pfs_create_file(root, NULL, "uptime", &linprocfs_douptime, NULL, NULL,
+ NULL, PFS_RD);
+ pfs_create_file(root, NULL, "version", &linprocfs_doversion, NULL, NULL,
+ NULL, PFS_RD);
/* /proc/bus/... */
- dir = pfs_create_dir(root, "bus", NULL, NULL, NULL, 0);
- dir = pfs_create_dir(dir, "pci", NULL, NULL, NULL, 0);
- dir = pfs_create_dir(dir, "devices", NULL, NULL, NULL, 0);
+ pfs_create_dir(root, &dir, "bus", NULL, NULL, NULL, 0);
+ pfs_create_dir(dir, &dir, "pci", NULL, NULL, NULL, 0);
+ pfs_create_dir(dir, &dir, "devices", NULL, NULL, NULL, 0);
/* /proc/net/... */
- dir = pfs_create_dir(root, "net", NULL, NULL, NULL, 0);
- pfs_create_file(dir, "dev", &linprocfs_donetdev,
- NULL, NULL, NULL, PFS_RD);
+ pfs_create_dir(root, &dir, "net", NULL, NULL, NULL, 0);
+ pfs_create_file(dir, NULL, "dev", &linprocfs_donetdev, NULL, NULL, NULL,
+ PFS_RD);
+ pfs_create_file(dir, NULL, "route", &linprocfs_donetroute, NULL, NULL,
+ NULL, PFS_RD);
/* /proc/<pid>/... */
- dir = pfs_create_dir(root, "pid", NULL, NULL, NULL, PFS_PROCDEP);
- pfs_create_file(dir, "cmdline", &linprocfs_doproccmdline,
- NULL, NULL, NULL, PFS_RD);
- pfs_create_link(dir, "cwd", &linprocfs_doproccwd,
- NULL, NULL, NULL, 0);
- pfs_create_file(dir, "environ", &linprocfs_doprocenviron,
- NULL, &procfs_candebug, NULL, PFS_RD);
- pfs_create_link(dir, "exe", &procfs_doprocfile,
- NULL, &procfs_notsystem, NULL, 0);
- pfs_create_file(dir, "maps", &linprocfs_doprocmaps,
- NULL, NULL, NULL, PFS_RD | PFS_AUTODRAIN);
- pfs_create_file(dir, "mem", &linprocfs_doprocmem,
- procfs_attr_rw, &procfs_candebug, NULL, PFS_RDWR | PFS_RAW);
- pfs_create_file(dir, "mountinfo", &linprocfs_doprocmountinfo,
- NULL, NULL, NULL, PFS_RD);
- pfs_create_file(dir, "mounts", &linprocfs_domtab,
- NULL, NULL, NULL, PFS_RD);
- pfs_create_link(dir, "root", &linprocfs_doprocroot,
- NULL, NULL, NULL, 0);
- pfs_create_file(dir, "stat", &linprocfs_doprocstat,
- NULL, NULL, NULL, PFS_RD);
- pfs_create_file(dir, "statm", &linprocfs_doprocstatm,
- NULL, NULL, NULL, PFS_RD);
- pfs_create_file(dir, "status", &linprocfs_doprocstatus,
- NULL, NULL, NULL, PFS_RD);
- pfs_create_link(dir, "fd", &linprocfs_dofdescfs,
- NULL, NULL, NULL, 0);
- pfs_create_file(dir, "auxv", &linprocfs_doauxv,
- NULL, &procfs_candebug, NULL, PFS_RD|PFS_RAWRD);
- pfs_create_file(dir, "limits", &linprocfs_doproclimits,
+ pfs_create_dir(root, &dir, "pid", NULL, NULL, NULL, PFS_PROCDEP);
+ pfs_create_file(dir, NULL, "cmdline", &linprocfs_doproccmdline, NULL,
+ NULL, NULL, PFS_RD);
+ pfs_create_link(dir, NULL, "cwd", &linprocfs_doproccwd, NULL, NULL,
+ NULL, 0);
+ pfs_create_file(dir, NULL, "environ", &linprocfs_doprocenviron, NULL,
+ &procfs_candebug, NULL, PFS_RD);
+ pfs_create_link(dir, NULL, "exe", &procfs_doprocfile, NULL,
+ &procfs_notsystem, NULL, 0);
+ pfs_create_file(dir, NULL, "maps", &linprocfs_doprocmaps, NULL, NULL,
+ NULL, PFS_RD | PFS_AUTODRAIN);
+ pfs_create_file(dir, NULL, "mem", &linprocfs_doprocmem, procfs_attr_rw,
+ &procfs_candebug, NULL, PFS_RDWR | PFS_RAW);
+ pfs_create_file(dir, NULL, "mountinfo", &linprocfs_doprocmountinfo,
NULL, NULL, NULL, PFS_RD);
+ pfs_create_file(dir, NULL, "mounts", &linprocfs_domtab, NULL, NULL,
+ NULL, PFS_RD);
+ pfs_create_link(dir, NULL, "root", &linprocfs_doprocroot, NULL, NULL,
+ NULL, 0);
+ pfs_create_file(dir, NULL, "stat", &linprocfs_doprocstat, NULL, NULL,
+ NULL, PFS_RD);
+ pfs_create_file(dir, NULL, "statm", &linprocfs_doprocstatm, NULL, NULL,
+ NULL, PFS_RD);
+ pfs_create_file(dir, NULL, "status", &linprocfs_doprocstatus, NULL,
+ NULL, NULL, PFS_RD);
+ pfs_create_link(dir, NULL, "fd", &linprocfs_dofdescfs, NULL, NULL, NULL,
+ 0);
+ pfs_create_file(dir, NULL, "auxv", &linprocfs_doauxv, NULL,
+ &procfs_candebug, NULL, PFS_RD | PFS_RAWRD);
+ pfs_create_file(dir, NULL, "limits", &linprocfs_doproclimits, NULL,
+ NULL, NULL, PFS_RD);
+ pfs_create_file(dir, NULL, "oom_score_adj", &linprocfs_do_oom_score_adj,
+ procfs_attr_rw, &procfs_candebug, NULL, PFS_RDWR);
/* /proc/<pid>/task/... */
- dir = pfs_create_dir(dir, "task", linprocfs_dotaskattr, NULL, NULL, 0);
- pfs_create_file(dir, ".dummy", &linprocfs_dotaskdummy,
- NULL, NULL, NULL, PFS_RD);
+ pfs_create_dir(dir, &dir, "task", linprocfs_dotaskattr, NULL, NULL, 0);
+ pfs_create_file(dir, NULL, ".dummy", &linprocfs_dotaskdummy, NULL, NULL,
+ NULL, PFS_RD);
/* /proc/scsi/... */
- dir = pfs_create_dir(root, "scsi", NULL, NULL, NULL, 0);
- pfs_create_file(dir, "device_info", &linprocfs_doscsidevinfo,
- NULL, NULL, NULL, PFS_RD);
- pfs_create_file(dir, "scsi", &linprocfs_doscsiscsi,
+ pfs_create_dir(root, &dir, "scsi", NULL, NULL, NULL, 0);
+ pfs_create_file(dir, NULL, "device_info", &linprocfs_doscsidevinfo,
NULL, NULL, NULL, PFS_RD);
+ pfs_create_file(dir, NULL, "scsi", &linprocfs_doscsiscsi, NULL, NULL,
+ NULL, PFS_RD);
/* /proc/sys/... */
- sys = pfs_create_dir(root, "sys", NULL, NULL, NULL, 0);
+ pfs_create_dir(root, &sys, "sys", NULL, NULL, NULL, 0);
/* /proc/sys/kernel/... */
- dir = pfs_create_dir(sys, "kernel", NULL, NULL, NULL, 0);
- pfs_create_file(dir, "osrelease", &linprocfs_doosrelease,
- NULL, NULL, NULL, PFS_RD);
- pfs_create_file(dir, "ostype", &linprocfs_doostype,
- NULL, NULL, NULL, PFS_RD);
- pfs_create_file(dir, "version", &linprocfs_doosbuild,
- NULL, NULL, NULL, PFS_RD);
- pfs_create_file(dir, "msgmax", &linprocfs_domsgmax,
- NULL, NULL, NULL, PFS_RD);
- pfs_create_file(dir, "msgmni", &linprocfs_domsgmni,
- NULL, NULL, NULL, PFS_RD);
- pfs_create_file(dir, "msgmnb", &linprocfs_domsgmnb,
- NULL, NULL, NULL, PFS_RD);
- pfs_create_file(dir, "ngroups_max", &linprocfs_dongroups_max,
- NULL, NULL, NULL, PFS_RD);
- pfs_create_file(dir, "pid_max", &linprocfs_dopid_max,
- NULL, NULL, NULL, PFS_RD);
- pfs_create_file(dir, "sem", &linprocfs_dosem,
- NULL, NULL, NULL, PFS_RD);
- pfs_create_file(dir, "shmall", &linprocfs_doshmall,
- NULL, NULL, NULL, PFS_RD);
- pfs_create_file(dir, "shmmax", &linprocfs_doshmmax,
- NULL, NULL, NULL, PFS_RD);
- pfs_create_file(dir, "shmmni", &linprocfs_doshmmni,
- NULL, NULL, NULL, PFS_RD);
- pfs_create_file(dir, "tainted", &linprocfs_dotainted,
+ pfs_create_dir(sys, &dir, "kernel", NULL, NULL, NULL, 0);
+ pfs_create_file(dir, NULL, "osrelease", &linprocfs_doosrelease, NULL,
+ NULL, NULL, PFS_RD);
+ pfs_create_file(dir, NULL, "ostype", &linprocfs_doostype, NULL, NULL,
+ NULL, PFS_RD);
+ pfs_create_file(dir, NULL, "version", &linprocfs_doosbuild, NULL, NULL,
+ NULL, PFS_RD);
+ pfs_create_file(dir, NULL, "msgmax", &linprocfs_domsgmax, NULL, NULL,
+ NULL, PFS_RD);
+ pfs_create_file(dir, NULL, "msgmni", &linprocfs_domsgmni, NULL, NULL,
+ NULL, PFS_RD);
+ pfs_create_file(dir, NULL, "msgmnb", &linprocfs_domsgmnb, NULL, NULL,
+ NULL, PFS_RD);
+ pfs_create_file(dir, NULL, "ngroups_max", &linprocfs_dongroups_max,
NULL, NULL, NULL, PFS_RD);
+ pfs_create_file(dir, NULL, "pid_max", &linprocfs_dopid_max, NULL, NULL,
+ NULL, PFS_RD);
+ pfs_create_file(dir, NULL, "sem", &linprocfs_dosem, NULL, NULL, NULL,
+ PFS_RD);
+ pfs_create_file(dir, NULL, "shmall", &linprocfs_doshmall, NULL, NULL,
+ NULL, PFS_RD);
+ pfs_create_file(dir, NULL, "shmmax", &linprocfs_doshmmax, NULL, NULL,
+ NULL, PFS_RD);
+ pfs_create_file(dir, NULL, "shmmni", &linprocfs_doshmmni, NULL, NULL,
+ NULL, PFS_RD);
+ pfs_create_file(dir, NULL, "tainted", &linprocfs_dotainted, NULL, NULL,
+ NULL, PFS_RD);
/* /proc/sys/kernel/random/... */
- dir = pfs_create_dir(dir, "random", NULL, NULL, NULL, 0);
- pfs_create_file(dir, "uuid", &linprocfs_douuid,
- NULL, NULL, NULL, PFS_RD);
+ pfs_create_dir(dir, &dir, "random", NULL, NULL, NULL, 0);
+ pfs_create_file(dir, NULL, "uuid", &linprocfs_douuid, NULL, NULL, NULL,
+ PFS_RD);
+ pfs_create_file(dir, NULL, "boot_id", &linprocfs_doboot_id, NULL, NULL,
+ NULL, PFS_RD);
/* /proc/sys/vm/.... */
- dir = pfs_create_dir(sys, "vm", NULL, NULL, NULL, 0);
- pfs_create_file(dir, "min_free_kbytes", &linprocfs_dominfree,
+ pfs_create_dir(sys, &dir, "vm", NULL, NULL, NULL, 0);
+ pfs_create_file(dir, NULL, "min_free_kbytes", &linprocfs_dominfree,
+ NULL, NULL, NULL, PFS_RD);
+ pfs_create_file(dir, NULL, "max_map_count", &linprocfs_domax_map_cnt,
+ NULL, NULL, NULL, PFS_RD);
+
+ /* /proc/sysvipc/... */
+ pfs_create_dir(root, &dir, "sysvipc", NULL, NULL, NULL, 0);
+ pfs_create_file(dir, NULL, "msg", &linprocfs_dosysvipc_msg, NULL, NULL,
+ NULL, PFS_RD);
+ pfs_create_file(dir, NULL, "sem", &linprocfs_dosysvipc_sem, NULL, NULL,
+ NULL, PFS_RD);
+ pfs_create_file(dir, NULL, "shm", &linprocfs_dosysvipc_shm, NULL, NULL,
+ NULL, PFS_RD);
+
+ /* /proc/sys/fs/... */
+ pfs_create_dir(sys, &fs, "fs", NULL, NULL, NULL, 0);
+
+ pfs_create_dir(fs, &dir, "inotify", NULL, NULL, NULL, 0);
+ pfs_create_file(dir, NULL, "max_queued_events",
+ &linprocfs_doinotify_max_queued_events, NULL, NULL, NULL, PFS_RDWR);
+ pfs_create_file(dir, NULL, "max_user_instances",
+ &linprocfs_doinotify_max_user_instances, NULL, NULL, NULL, PFS_RDWR);
+ pfs_create_file(dir, NULL, "max_user_watches",
+ &linprocfs_doinotify_max_user_watches, NULL, NULL, NULL, PFS_RDWR);
+
+ /* /proc/sys/fs/mqueue/... */
+ pfs_create_dir(fs, &dir, "mqueue", NULL, NULL, NULL, 0);
+ pfs_create_file(dir, NULL, "msg_default",
+ &linprocfs_domqueue_msg_default, NULL, NULL, NULL, PFS_RD);
+ pfs_create_file(dir, NULL, "msgsize_default",
+ &linprocfs_domqueue_msgsize_default, NULL, NULL, NULL, PFS_RD);
+ pfs_create_file(dir, NULL, "msg_max", &linprocfs_domqueue_msg_max, NULL,
+ NULL, NULL, PFS_RD);
+ pfs_create_file(dir, NULL, "msgsize_max",
+ &linprocfs_domqueue_msgsize_max, NULL, NULL, NULL, PFS_RD);
+ pfs_create_file(dir, NULL, "queues_max", &linprocfs_domqueue_queues_max,
NULL, NULL, NULL, PFS_RD);
return (0);
diff --git a/sys/compat/linsysfs/linsysfs.c b/sys/compat/linsysfs/linsysfs.c
index 8d3be1507de9..5a41c5193415 100644
--- a/sys/compat/linsysfs/linsysfs.c
+++ b/sys/compat/linsysfs/linsysfs.c
@@ -1,5 +1,5 @@
/*-
- * SPDX-License-Identifier: BSD-2-Clause-FreeBSD
+ * SPDX-License-Identifier: BSD-2-Clause
*
* Copyright (c) 2006 IronPort Systems
* All rights reserved.
@@ -26,9 +26,6 @@
* SUCH DAMAGE.
*/
-#include <sys/cdefs.h>
-__FBSDID("$FreeBSD$");
-
#include <sys/param.h>
#include <sys/systm.h>
#include <sys/ctype.h>
@@ -37,22 +34,19 @@ __FBSDID("$FreeBSD$");
#include <sys/mount.h>
#include <sys/sbuf.h>
#include <sys/smp.h>
-#include <sys/socket.h>
#include <sys/bus.h>
#include <sys/pciio.h>
#include <dev/pci/pcivar.h>
#include <dev/pci/pcireg.h>
-#include <net/if.h>
-#include <net/if_var.h>
-#include <net/if_dl.h>
-
-#include <compat/linux/linux.h>
-#include <compat/linux/linux_common.h>
#include <compat/linux/linux_util.h>
#include <fs/pseudofs/pseudofs.h>
+#include <compat/linsysfs/linsysfs.h>
+
+MALLOC_DEFINE(M_LINSYSFS, "linsysfs", "Linsysfs structures");
+
struct scsi_host_queue {
TAILQ_ENTRY(scsi_host_queue) scsi_host_next;
char *path;
@@ -69,146 +63,6 @@ atoi(const char *str)
return (int)strtol(str, (char **)NULL, 10);
}
-static int
-linsysfs_ifnet_addr(PFS_FILL_ARGS)
-{
- struct l_sockaddr lsa;
- struct ifnet *ifp;
-
- ifp = ifname_linux_to_bsd(td, pn->pn_parent->pn_name, NULL);
- if (ifp == NULL)
- return (ENOENT);
- if (linux_ifhwaddr(ifp, &lsa) != 0)
- return (ENOENT);
- sbuf_printf(sb, "%02hhx:%02hhx:%02hhx:%02hhx:%02hhx:%02hhx\n",
- lsa.sa_data[0], lsa.sa_data[1], lsa.sa_data[2],
- lsa.sa_data[3], lsa.sa_data[4], lsa.sa_data[5]);
- return (0);
-}
-
-static int
-linsysfs_ifnet_addrlen(PFS_FILL_ARGS)
-{
-
- sbuf_printf(sb, "%d\n", LINUX_IFHWADDRLEN);
- return (0);
-}
-
-static int
-linsysfs_ifnet_flags(PFS_FILL_ARGS)
-{
- struct ifnet *ifp;
- unsigned short flags;
-
- ifp = ifname_linux_to_bsd(td, pn->pn_parent->pn_name, NULL);
- if (ifp == NULL)
- return (ENOENT);
- linux_ifflags(ifp, &flags);
- sbuf_printf(sb, "0x%x\n", flags);
- return (0);
-}
-
-static int
-linsysfs_ifnet_ifindex(PFS_FILL_ARGS)
-{
- struct ifnet *ifp;
-
- ifp = ifname_linux_to_bsd(td, pn->pn_parent->pn_name, NULL);
- if (ifp == NULL)
- return (ENOENT);
- sbuf_printf(sb, "%u\n", ifp->if_index);
- return (0);
-}
-
-static int
-linsysfs_ifnet_mtu(PFS_FILL_ARGS)
-{
- struct ifnet *ifp;
-
- ifp = ifname_linux_to_bsd(td, pn->pn_parent->pn_name, NULL);
- if (ifp == NULL)
- return (ENOENT);
- sbuf_printf(sb, "%u\n", ifp->if_mtu);
- return (0);
-}
-
-static int
-linsysfs_ifnet_tx_queue_len(PFS_FILL_ARGS)
-{
-
- /* XXX */
- sbuf_printf(sb, "1000\n");
- return (0);
-}
-
-static int
-linsysfs_ifnet_type(PFS_FILL_ARGS)
-{
- struct l_sockaddr lsa;
- struct ifnet *ifp;
-
- ifp = ifname_linux_to_bsd(td, pn->pn_parent->pn_name, NULL);
- if (ifp == NULL)
- return (ENOENT);
- if (linux_ifhwaddr(ifp, &lsa) != 0)
- return (ENOENT);
- sbuf_printf(sb, "%d\n", lsa.sa_family);
- return (0);
-}
-
-static void
-linsysfs_listnics(struct pfs_node *dir)
-{
- struct pfs_node *nic;
- struct pfs_node *lo;
-
- nic = pfs_create_dir(dir, "eth0", NULL, NULL, NULL, 0);
-
- pfs_create_file(nic, "address", &linsysfs_ifnet_addr,
- NULL, NULL, NULL, PFS_RD);
-
- pfs_create_file(nic, "addr_len", &linsysfs_ifnet_addrlen,
- NULL, NULL, NULL, PFS_RD);
-
- pfs_create_file(nic, "flags", &linsysfs_ifnet_flags,
- NULL, NULL, NULL, PFS_RD);
-
- pfs_create_file(nic, "ifindex", &linsysfs_ifnet_ifindex,
- NULL, NULL, NULL, PFS_RD);
-
- pfs_create_file(nic, "mtu", &linsysfs_ifnet_mtu,
- NULL, NULL, NULL, PFS_RD);
-
- pfs_create_file(nic, "tx_queue_len", &linsysfs_ifnet_tx_queue_len,
- NULL, NULL, NULL, PFS_RD);
-
- pfs_create_file(nic, "type", &linsysfs_ifnet_type,
- NULL, NULL, NULL, PFS_RD);
-
- lo = pfs_create_dir(dir, "lo", NULL, NULL, NULL, 0);
-
- pfs_create_file(lo, "address", &linsysfs_ifnet_addr,
- NULL, NULL, NULL, PFS_RD);
-
- pfs_create_file(lo, "addr_len", &linsysfs_ifnet_addrlen,
- NULL, NULL, NULL, PFS_RD);
-
- pfs_create_file(lo, "flags", &linsysfs_ifnet_flags,
- NULL, NULL, NULL, PFS_RD);
-
- pfs_create_file(lo, "ifindex", &linsysfs_ifnet_ifindex,
- NULL, NULL, NULL, PFS_RD);
-
- pfs_create_file(lo, "mtu", &linsysfs_ifnet_mtu,
- NULL, NULL, NULL, PFS_RD);
-
- pfs_create_file(lo, "tx_queue_len", &linsysfs_ifnet_tx_queue_len,
- NULL, NULL, NULL, PFS_RD);
-
- pfs_create_file(lo, "type", &linsysfs_ifnet_type,
- NULL, NULL, NULL, PFS_RD);
-}
-
/*
* Filler function for proc_name
*/
@@ -413,6 +267,8 @@ linsysfs_run_bus(device_t dev, struct pfs_node *dir, struct pfs_node *scsi,
struct pci_devinfo *dinfo;
char *device, *host, *new_path, *devname;
+ children = NULL;
+ device = host = NULL;
new_path = path;
devname = malloc(16, M_TEMP, M_WAITOK);
@@ -438,39 +294,43 @@ linsysfs_run_bus(device_t dev, struct pfs_node *dir, struct pfs_node *scsi,
dinfo->cfg.func);
strcat(new_path, "/");
strcat(new_path, device);
- dir = pfs_create_dir(dir, device,
+ error = pfs_create_dir(dir, &dir, device,
NULL, NULL, NULL, 0);
- cur_file = pfs_create_file(dir, "vendor",
+ if (error != 0)
+ goto out;
+ pfs_create_dir(dir, &dir, device, NULL, NULL,
+ NULL, 0);
+ pfs_create_file(dir, &cur_file, "vendor",
&linsysfs_fill_vendor, NULL, NULL, NULL,
PFS_RD);
cur_file->pn_data = (void*)dev;
- cur_file = pfs_create_file(dir, "device",
+ pfs_create_file(dir, &cur_file, "device",
&linsysfs_fill_device, NULL, NULL, NULL,
PFS_RD);
cur_file->pn_data = (void*)dev;
- cur_file = pfs_create_file(dir,
+ pfs_create_file(dir, &cur_file,
"subsystem_vendor",
&linsysfs_fill_subvendor, NULL, NULL, NULL,
PFS_RD);
cur_file->pn_data = (void*)dev;
- cur_file = pfs_create_file(dir,
+ pfs_create_file(dir, &cur_file,
"subsystem_device",
&linsysfs_fill_subdevice, NULL, NULL, NULL,
PFS_RD);
cur_file->pn_data = (void*)dev;
- cur_file = pfs_create_file(dir, "revision",
+ pfs_create_file(dir, &cur_file, "revision",
&linsysfs_fill_revid, NULL, NULL, NULL,
PFS_RD);
cur_file->pn_data = (void*)dev;
- cur_file = pfs_create_file(dir, "config",
+ pfs_create_file(dir, &cur_file, "config",
&linsysfs_fill_config, NULL, NULL, NULL,
PFS_RD);
cur_file->pn_data = (void*)dev;
- cur_file = pfs_create_file(dir, "uevent",
- &linsysfs_fill_uevent_pci, NULL, NULL,
- NULL, PFS_RD);
+ pfs_create_file(dir, &cur_file, "uevent",
+ &linsysfs_fill_uevent_pci, NULL, NULL, NULL,
+ PFS_RD);
cur_file->pn_data = (void*)dev;
- cur_file = pfs_create_link(dir, "subsystem",
+ pfs_create_link(dir, &cur_file, "subsystem",
&linsysfs_fill_data, NULL, NULL, NULL, 0);
/* libdrm just checks that the link ends in "/pci" */
cur_file->pn_data = "/sys/bus/pci";
@@ -480,34 +340,32 @@ linsysfs_run_bus(device_t dev, struct pfs_node *dir, struct pfs_node *scsi,
sprintf(host, "host%d", host_number++);
strcat(new_path, "/");
strcat(new_path, host);
- pfs_create_dir(dir, host,
- NULL, NULL, NULL, 0);
+ pfs_create_dir(dir, NULL, host, NULL,
+ NULL, NULL, 0);
scsi_host = malloc(sizeof(
struct scsi_host_queue),
- M_DEVBUF, M_NOWAIT);
+ M_DEVBUF, M_WAITOK);
scsi_host->path = malloc(
strlen(new_path) + 1,
- M_DEVBUF, M_NOWAIT);
+ M_DEVBUF, M_WAITOK);
scsi_host->path[0] = '\000';
bcopy(new_path, scsi_host->path,
strlen(new_path) + 1);
scsi_host->name = "unknown";
- sub_dir = pfs_create_dir(scsi, host,
- NULL, NULL, NULL, 0);
- pfs_create_link(sub_dir, "device",
- &linsysfs_link_scsi_host,
+ pfs_create_dir(scsi, &sub_dir, host,
NULL, NULL, NULL, 0);
- pfs_create_file(sub_dir, "proc_name",
- &linsysfs_scsiname,
+ pfs_create_link(sub_dir, NULL, "device",
+ &linsysfs_link_scsi_host, NULL,
+ NULL, NULL, 0);
+ pfs_create_file(sub_dir, NULL,
+ "proc_name", &linsysfs_scsiname,
NULL, NULL, NULL, PFS_RD);
scsi_host->name
= linux_driver_get_name_dev(dev);
TAILQ_INSERT_TAIL(&scsi_host_q,
scsi_host, scsi_host_next);
}
- free(device, M_TEMP);
- free(host, M_TEMP);
}
}
@@ -520,26 +378,27 @@ linsysfs_run_bus(device_t dev, struct pfs_node *dir, struct pfs_node *scsi,
device_get_unit(dev) >= 0) {
dinfo = device_get_ivars(parent);
if (dinfo != NULL && dinfo->cfg.baseclass == PCIC_DISPLAY) {
- pfs_create_dir(dir, "drm", NULL, NULL, NULL, 0);
+ pfs_create_dir(dir, NULL, "drm", NULL, NULL,
+ NULL, 0);
sprintf(devname, "226:%d",
device_get_unit(dev));
- sub_dir = pfs_create_dir(chardev,
- devname, NULL, NULL, NULL, 0);
- cur_file = pfs_create_link(sub_dir,
- "device", &linsysfs_fill_vgapci, NULL,
- NULL, NULL, PFS_RD);
+ pfs_create_dir(chardev, &sub_dir, devname, NULL,
+ NULL, NULL, 0);
+ pfs_create_link(sub_dir, &cur_file, "device",
+ &linsysfs_fill_vgapci, NULL, NULL, NULL,
+ PFS_RD);
cur_file->pn_data = (void*)dir;
- cur_file = pfs_create_file(sub_dir,
- "uevent", &linsysfs_fill_uevent_drm, NULL,
- NULL, NULL, PFS_RD);
+ pfs_create_file(sub_dir, &cur_file, "uevent",
+ &linsysfs_fill_uevent_drm, NULL, NULL, NULL,
+ PFS_RD);
cur_file->pn_data = (void*)dev;
sprintf(devname, "card%d",
device_get_unit(dev));
- sub_dir = pfs_create_dir(drm,
- devname, NULL, NULL, NULL, 0);
- cur_file = pfs_create_link(sub_dir,
- "device", &linsysfs_fill_vgapci, NULL,
- NULL, NULL, PFS_RD);
+ pfs_create_dir(drm, &sub_dir, devname, NULL,
+ NULL, NULL, 0);
+ pfs_create_link(sub_dir, &cur_file, "device",
+ &linsysfs_fill_vgapci, NULL, NULL, NULL,
+ PFS_RD);
cur_file->pn_data = (void*)dir;
}
}
@@ -547,17 +406,37 @@ linsysfs_run_bus(device_t dev, struct pfs_node *dir, struct pfs_node *scsi,
error = device_get_children(dev, &children, &nchildren);
if (error == 0) {
- for (i = 0; i < nchildren; i++)
- if (children[i])
- linsysfs_run_bus(children[i], dir, scsi,
+ for (i = 0; i < nchildren; i++) {
+ if (children[i]) {
+ error = linsysfs_run_bus(children[i], dir, scsi,
chardev, drm, new_path, prefix);
- free(children, M_TEMP);
+ if (error != 0) {
+ printf(
+ "linsysfs_run_bus: %s omitted from sysfs tree, error %d\n",
+ device_get_nameunit(children[i]),
+ error);
+ }
+ }
+ }
+
+ /*
+ * We override the error to avoid cascading failures; the
+ * innermost device that failed in a tree is probably the most
+ * significant one for diagnostics, its parents would be noise.
+ */
+ error = 0;
}
+
+out:
+ free(host, M_TEMP);
+ free(device, M_TEMP);
+ if (children != NULL)
+ free(children, M_TEMP);
if (new_path != path)
free(new_path, M_TEMP);
free(devname, M_TEMP);
- return (1);
+ return (error);
}
/*
@@ -601,10 +480,10 @@ linsysfs_listcpus(struct pfs_node *dir)
for (i = 0; i < mp_ncpus; ++i) {
/* /sys/devices/system/cpu/cpuX */
sprintf(name, "cpu%d", i);
- cpu = pfs_create_dir(dir, name, NULL, NULL, NULL, 0);
+ pfs_create_dir(dir, &cpu, name, NULL, NULL, NULL, 0);
- pfs_create_file(cpu, "online", &linsysfs_cpuxonline,
- NULL, NULL, NULL, PFS_RD);
+ pfs_create_file(cpu, NULL, "online", &linsysfs_cpuxonline, NULL,
+ NULL, NULL, PFS_RD);
}
free(name, M_TEMP);
}
@@ -621,11 +500,8 @@ linsysfs_init(PFS_INIT_ARGS)
struct pfs_node *drm;
struct pfs_node *pci;
struct pfs_node *scsi;
- struct pfs_node *net;
- struct pfs_node *power_supply;
struct pfs_node *devdir, *chardev;
struct pfs_node *kernel;
- struct pfs_node *debug;
devclass_t devclass;
device_t dev;
@@ -634,56 +510,58 @@ linsysfs_init(PFS_INIT_ARGS)
root = pi->pi_root;
/* /sys/bus/... */
- dir = pfs_create_dir(root, "bus", NULL, NULL, NULL, 0);
+ pfs_create_dir(root, &dir, "bus", NULL, NULL, NULL, 0);
/* /sys/class/... */
- class = pfs_create_dir(root, "class", NULL, NULL, NULL, 0);
- scsi = pfs_create_dir(class, "scsi_host", NULL, NULL, NULL, 0);
- drm = pfs_create_dir(class, "drm", NULL, NULL, NULL, 0);
- power_supply = pfs_create_dir(class, "power_supply", NULL, NULL, NULL, 0);
+ pfs_create_dir(root, &class, "class", NULL, NULL, NULL, 0);
+ pfs_create_dir(class, &scsi, "scsi_host", NULL, NULL, NULL, 0);
+ pfs_create_dir(class, &drm, "drm", NULL, NULL, NULL, 0);
+ pfs_create_dir(class, NULL, "power_supply", NULL, NULL, NULL, 0);
/* /sys/class/net/.. */
- net = pfs_create_dir(class, "net", NULL, NULL, NULL, 0);
+ pfs_create_dir(class, &net, "net", NULL, NULL, NULL, 0);
/* /sys/dev/... */
- devdir = pfs_create_dir(root, "dev", NULL, NULL, NULL, 0);
- chardev = pfs_create_dir(devdir, "char", NULL, NULL, NULL, 0);
+ pfs_create_dir(root, &devdir, "dev", NULL, NULL, NULL, 0);
+ pfs_create_dir(devdir, &chardev, "char", NULL, NULL, NULL, 0);
/* /sys/devices/... */
- dir = pfs_create_dir(root, "devices", NULL, NULL, NULL, 0);
- pci = pfs_create_dir(dir, "pci0000:00", NULL, NULL, NULL, 0);
+ pfs_create_dir(root, &dir, "devices", NULL, NULL, NULL, 0);
+ pfs_create_dir(dir, &pci, "pci0000:00", NULL, NULL, NULL, 0);
devclass = devclass_find("root");
if (devclass == NULL) {
return (0);
}
+ /*
+ * This assumes that the root node is unlikely to error out in
+ * linsysfs_run_bus, which may or may not be true.
+ */
dev = devclass_get_device(devclass, 0);
linsysfs_run_bus(dev, pci, scsi, chardev, drm, "/pci0000:00", "0000");
/* /sys/devices/system */
- sys = pfs_create_dir(dir, "system", NULL, NULL, NULL, 0);
+ pfs_create_dir(dir, &sys, "system", NULL, NULL, NULL, 0);
/* /sys/devices/system/cpu */
- cpu = pfs_create_dir(sys, "cpu", NULL, NULL, NULL, 0);
+ pfs_create_dir(sys, &cpu, "cpu", NULL, NULL, NULL, 0);
- pfs_create_file(cpu, "online", &linsysfs_cpuonline,
- NULL, NULL, NULL, PFS_RD);
- pfs_create_file(cpu, "possible", &linsysfs_cpuonline,
- NULL, NULL, NULL, PFS_RD);
- pfs_create_file(cpu, "present", &linsysfs_cpuonline,
- NULL, NULL, NULL, PFS_RD);
+ pfs_create_file(cpu, NULL, "online", &linsysfs_cpuonline, NULL, NULL,
+ NULL, PFS_RD);
+ pfs_create_file(cpu, NULL, "possible", &linsysfs_cpuonline, NULL, NULL,
+ NULL, PFS_RD);
+ pfs_create_file(cpu, NULL, "present", &linsysfs_cpuonline, NULL, NULL,
+ NULL, PFS_RD);
linsysfs_listcpus(cpu);
- linsysfs_listnics(net);
/* /sys/kernel */
- kernel = pfs_create_dir(root, "kernel", NULL, NULL, NULL, 0);
+ pfs_create_dir(root, &kernel, "kernel", NULL, NULL, NULL, 0);
/* /sys/kernel/debug, mountpoint for lindebugfs. */
- debug = pfs_create_dir(kernel, "debug", NULL, NULL, NULL, 0);
+ pfs_create_dir(kernel, NULL, "debug", NULL, NULL, NULL, 0);
- /* /sys/subsystem/... */
- dir = pfs_create_dir(root, "subsystem", NULL, NULL, NULL, 0);
+ linsysfs_net_init();
return (0);
}
@@ -703,6 +581,8 @@ linsysfs_uninit(PFS_INIT_ARGS)
free(scsi_host, M_TEMP);
}
+ linsysfs_net_uninit();
+
return (0);
}
diff --git a/sys/compat/linsysfs/linsysfs.h b/sys/compat/linsysfs/linsysfs.h
new file mode 100644
index 000000000000..97b368ff711c
--- /dev/null
+++ b/sys/compat/linsysfs/linsysfs.h
@@ -0,0 +1,38 @@
+/*-
+ * SPDX-License-Identifier: BSD-2-Clause
+ *
+ * Copyright (c) 2023 Dmitry Chagin <dchagin@FreeBSD.org>
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``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 OR CONTRIBUTORS 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.
+ */
+
+#ifndef _COMPAT_LINSYSFS_LINSYSFS_H_
+#define _COMPAT_LINSYSFS_LINSYSFS_H_
+
+MALLOC_DECLARE(M_LINSYSFS);
+
+extern struct pfs_node *net;
+
+void linsysfs_net_init(void);
+void linsysfs_net_uninit(void);
+
+#endif /* _COMPAT_LINSYSFS_LINSYSFS_H_ */
diff --git a/sys/compat/linsysfs/linsysfs_net.c b/sys/compat/linsysfs/linsysfs_net.c
new file mode 100644
index 000000000000..751dbb5b3713
--- /dev/null
+++ b/sys/compat/linsysfs/linsysfs_net.c
@@ -0,0 +1,353 @@
+/*-
+ * SPDX-License-Identifier: BSD-2-Clause
+ *
+ * Copyright (c) 2023 Dmitry Chagin <dchagin@FreeBSD.org>
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``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 OR CONTRIBUTORS 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.
+ */
+
+#include <sys/param.h>
+#include <sys/eventhandler.h>
+#include <sys/kernel.h>
+#include <sys/lock.h>
+#include <sys/malloc.h>
+#include <sys/mutex.h>
+#include <sys/sbuf.h>
+#include <sys/socket.h>
+
+#include <net/if.h>
+#include <net/if_var.h>
+#include <net/vnet.h>
+
+#include <compat/linux/linux.h>
+#include <compat/linux/linux_common.h>
+#include <fs/pseudofs/pseudofs.h>
+
+#include <compat/linsysfs/linsysfs.h>
+
+struct pfs_node *net;
+static eventhandler_tag if_arrival_tag, if_departure_tag;
+
+static uint32_t net_latch_count = 0;
+static struct mtx net_latch_mtx;
+MTX_SYSINIT(net_latch_mtx, &net_latch_mtx, "lsfnet", MTX_DEF);
+
+struct ifp_nodes_queue {
+ TAILQ_ENTRY(ifp_nodes_queue) ifp_nodes_next;
+ if_t ifp;
+ struct vnet *vnet;
+ struct pfs_node *pn;
+};
+TAILQ_HEAD(,ifp_nodes_queue) ifp_nodes_q;
+
+static void
+linsysfs_net_latch_hold(void)
+{
+
+ mtx_lock(&net_latch_mtx);
+ if (net_latch_count++ > 0)
+ mtx_sleep(&net_latch_count, &net_latch_mtx, PDROP, "lsfnet", 0);
+ else
+ mtx_unlock(&net_latch_mtx);
+}
+
+static void
+linsysfs_net_latch_rele(void)
+{
+
+ mtx_lock(&net_latch_mtx);
+ if (--net_latch_count > 0)
+ wakeup_one(&net_latch_count);
+ mtx_unlock(&net_latch_mtx);
+}
+
+static int
+linsysfs_if_addr(PFS_FILL_ARGS)
+{
+ struct epoch_tracker et;
+ struct l_sockaddr lsa;
+ if_t ifp;
+ int error;
+
+ CURVNET_SET(TD_TO_VNET(td));
+ NET_EPOCH_ENTER(et);
+ ifp = ifname_linux_to_ifp(td, pn->pn_parent->pn_name);
+ if (ifp != NULL && (error = linux_ifhwaddr(ifp, &lsa)) == 0)
+ error = sbuf_printf(sb, "%02hhx:%02hhx:%02hhx:%02hhx:%02hhx:%02hhx\n",
+ lsa.sa_data[0], lsa.sa_data[1], lsa.sa_data[2],
+ lsa.sa_data[3], lsa.sa_data[4], lsa.sa_data[5]);
+ else
+ error = ENOENT;
+ NET_EPOCH_EXIT(et);
+ CURVNET_RESTORE();
+ return (error == -1 ? ERANGE : error);
+}
+
+static int
+linsysfs_if_addrlen(PFS_FILL_ARGS)
+{
+
+ sbuf_printf(sb, "%d\n", LINUX_IFHWADDRLEN);
+ return (0);
+}
+
+static int
+linsysfs_if_flags(PFS_FILL_ARGS)
+{
+ struct epoch_tracker et;
+ if_t ifp;
+ int error;
+
+ CURVNET_SET(TD_TO_VNET(td));
+ NET_EPOCH_ENTER(et);
+ ifp = ifname_linux_to_ifp(td, pn->pn_parent->pn_name);
+ if (ifp != NULL)
+ error = sbuf_printf(sb, "0x%x\n", linux_ifflags(ifp));
+ else
+ error = ENOENT;
+ NET_EPOCH_EXIT(et);
+ CURVNET_RESTORE();
+ return (error == -1 ? ERANGE : error);
+}
+
+static int
+linsysfs_if_ifindex(PFS_FILL_ARGS)
+{
+ struct epoch_tracker et;
+ if_t ifp;
+ int error;
+
+ CURVNET_SET(TD_TO_VNET(td));
+ NET_EPOCH_ENTER(et);
+ ifp = ifname_linux_to_ifp(td, pn->pn_parent->pn_name);
+ if (ifp != NULL)
+ error = sbuf_printf(sb, "%u\n", if_getindex(ifp));
+ else
+ error = ENOENT;
+ NET_EPOCH_EXIT(et);
+ CURVNET_RESTORE();
+ return (error == -1 ? ERANGE : error);
+}
+
+static int
+linsysfs_if_mtu(PFS_FILL_ARGS)
+{
+ struct epoch_tracker et;
+ if_t ifp;
+ int error;
+
+ CURVNET_SET(TD_TO_VNET(td));
+ NET_EPOCH_ENTER(et);
+ ifp = ifname_linux_to_ifp(td, pn->pn_parent->pn_name);
+ if (ifp != NULL)
+ error = sbuf_printf(sb, "%u\n", if_getmtu(ifp));
+ else
+ error = ENOENT;
+ NET_EPOCH_EXIT(et);
+ CURVNET_RESTORE();
+ return (error == -1 ? ERANGE : error);
+}
+
+static int
+linsysfs_if_txq_len(PFS_FILL_ARGS)
+{
+
+ /* XXX */
+ sbuf_printf(sb, "1000\n");
+ return (0);
+}
+
+static int
+linsysfs_if_type(PFS_FILL_ARGS)
+{
+ struct epoch_tracker et;
+ struct l_sockaddr lsa;
+ if_t ifp;
+ int error;
+
+ CURVNET_SET(TD_TO_VNET(td));
+ NET_EPOCH_ENTER(et);
+ ifp = ifname_linux_to_ifp(td, pn->pn_parent->pn_name);
+ if (ifp != NULL && (error = linux_ifhwaddr(ifp, &lsa)) == 0)
+ error = sbuf_printf(sb, "%d\n", lsa.sa_family);
+ else
+ error = ENOENT;
+ NET_EPOCH_EXIT(et);
+ CURVNET_RESTORE();
+ return (error == -1 ? ERANGE : error);
+}
+
+static int
+linsysfs_if_visible(PFS_VIS_ARGS)
+{
+ struct ifp_nodes_queue *nq, *nq_tmp;
+ struct epoch_tracker et;
+ if_t ifp;
+ int visible;
+
+ visible = 0;
+ CURVNET_SET(TD_TO_VNET(td));
+ NET_EPOCH_ENTER(et);
+ ifp = ifname_linux_to_ifp(td, pn->pn_name);
+ if (ifp != NULL) {
+ TAILQ_FOREACH_SAFE(nq, &ifp_nodes_q, ifp_nodes_next, nq_tmp) {
+ if (nq->ifp == ifp && nq->vnet == curvnet) {
+ visible = 1;
+ break;
+ }
+ }
+ }
+ NET_EPOCH_EXIT(et);
+ CURVNET_RESTORE();
+ return (visible);
+}
+
+static int
+linsysfs_net_addif(if_t ifp, void *arg)
+{
+ struct ifp_nodes_queue *nq, *nq_tmp;
+ struct pfs_node *nic, *dir = arg;
+ char ifname[LINUX_IFNAMSIZ];
+ struct epoch_tracker et;
+ int ret __diagused;
+
+ NET_EPOCH_ENTER(et);
+ ret = ifname_bsd_to_linux_ifp(ifp, ifname, sizeof(ifname));
+ NET_EPOCH_EXIT(et);
+ KASSERT(ret > 0, ("Interface (%s) is not converted", if_name(ifp)));
+
+ nic = pfs_find_node(dir, ifname);
+ if (nic == NULL) {
+ pfs_create_dir(dir, &nic, ifname, NULL, linsysfs_if_visible,
+ NULL, 0);
+ pfs_create_file(nic, NULL, "address", &linsysfs_if_addr, NULL,
+ NULL, NULL, PFS_RD);
+ pfs_create_file(nic, NULL, "addr_len", &linsysfs_if_addrlen,
+ NULL, NULL, NULL, PFS_RD);
+ pfs_create_file(nic, NULL, "flags", &linsysfs_if_flags, NULL,
+ NULL, NULL, PFS_RD);
+ pfs_create_file(nic, NULL, "ifindex", &linsysfs_if_ifindex,
+ NULL, NULL, NULL, PFS_RD);
+ pfs_create_file(nic, NULL, "mtu", &linsysfs_if_mtu, NULL, NULL,
+ NULL, PFS_RD);
+ pfs_create_file(nic, NULL, "tx_queue_len", &linsysfs_if_txq_len,
+ NULL, NULL, NULL, PFS_RD);
+ pfs_create_file(nic, NULL, "type", &linsysfs_if_type, NULL,
+ NULL, NULL, PFS_RD);
+ }
+ /*
+ * There is a small window between registering the if_arrival
+ * eventhandler and creating a list of interfaces.
+ */
+ TAILQ_FOREACH_SAFE(nq, &ifp_nodes_q, ifp_nodes_next, nq_tmp) {
+ if (nq->ifp == ifp && nq->vnet == curvnet)
+ return (0);
+ }
+ nq = malloc(sizeof(*nq), M_LINSYSFS, M_WAITOK);
+ nq->pn = nic;
+ nq->ifp = ifp;
+ nq->vnet = curvnet;
+ TAILQ_INSERT_TAIL(&ifp_nodes_q, nq, ifp_nodes_next);
+ return (0);
+}
+
+static void
+linsysfs_net_delif(if_t ifp)
+{
+ struct ifp_nodes_queue *nq, *nq_tmp;
+ struct pfs_node *pn;
+
+ pn = NULL;
+ TAILQ_FOREACH_SAFE(nq, &ifp_nodes_q, ifp_nodes_next, nq_tmp) {
+ if (nq->ifp == ifp && nq->vnet == curvnet) {
+ TAILQ_REMOVE(&ifp_nodes_q, nq, ifp_nodes_next);
+ pn = nq->pn;
+ free(nq, M_LINSYSFS);
+ break;
+ }
+ }
+ if (pn == NULL)
+ return;
+ TAILQ_FOREACH_SAFE(nq, &ifp_nodes_q, ifp_nodes_next, nq_tmp) {
+ if (nq->pn == pn)
+ return;
+ }
+ pfs_destroy(pn);
+}
+
+static void
+linsysfs_if_arrival(void *arg __unused, if_t ifp)
+{
+
+ linsysfs_net_latch_hold();
+ (void)linsysfs_net_addif(ifp, net);
+ linsysfs_net_latch_rele();
+}
+
+static void
+linsysfs_if_departure(void *arg __unused, if_t ifp)
+{
+
+ linsysfs_net_latch_hold();
+ linsysfs_net_delif(ifp);
+ linsysfs_net_latch_rele();
+}
+
+void
+linsysfs_net_init(void)
+{
+ VNET_ITERATOR_DECL(vnet_iter);
+
+ MPASS(net != NULL);
+ TAILQ_INIT(&ifp_nodes_q);
+
+ if_arrival_tag = EVENTHANDLER_REGISTER(ifnet_arrival_event,
+ linsysfs_if_arrival, NULL, EVENTHANDLER_PRI_ANY);
+ if_departure_tag = EVENTHANDLER_REGISTER(ifnet_departure_event,
+ linsysfs_if_departure, NULL, EVENTHANDLER_PRI_ANY);
+
+ linsysfs_net_latch_hold();
+ VNET_LIST_RLOCK();
+ VNET_FOREACH(vnet_iter) {
+ CURVNET_SET(vnet_iter);
+ if_foreach_sleep(NULL, NULL, linsysfs_net_addif, net);
+ CURVNET_RESTORE();
+ }
+ VNET_LIST_RUNLOCK();
+ linsysfs_net_latch_rele();
+}
+
+void
+linsysfs_net_uninit(void)
+{
+ struct ifp_nodes_queue *nq, *nq_tmp;
+
+ EVENTHANDLER_DEREGISTER(ifnet_arrival_event, if_arrival_tag);
+ EVENTHANDLER_DEREGISTER(ifnet_departure_event, if_departure_tag);
+
+ linsysfs_net_latch_hold();
+ TAILQ_FOREACH_SAFE(nq, &ifp_nodes_q, ifp_nodes_next, nq_tmp) {
+ TAILQ_REMOVE(&ifp_nodes_q, nq, ifp_nodes_next);
+ free(nq, M_LINSYSFS);
+ }
+ linsysfs_net_latch_rele();
+}
diff --git a/sys/compat/linux/check_error.d b/sys/compat/linux/check_error.d
index 8ed87a397863..6d922454b1f0 100644
--- a/sys/compat/linux/check_error.d
+++ b/sys/compat/linux/check_error.d
@@ -24,8 +24,6 @@
* 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.
- *
- * $FreeBSD$
*/
/*
diff --git a/sys/compat/linux/check_internal_locks.d b/sys/compat/linux/check_internal_locks.d
index d3032c06c512..ceed81b3b0f8 100644
--- a/sys/compat/linux/check_internal_locks.d
+++ b/sys/compat/linux/check_internal_locks.d
@@ -24,8 +24,6 @@
* 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.
- *
- * $FreeBSD$
*/
/**
diff --git a/sys/compat/linux/linux.c b/sys/compat/linux/linux.c
index 8cc678e1ec7d..a40f110634f7 100644
--- a/sys/compat/linux/linux.c
+++ b/sys/compat/linux/linux.c
@@ -23,13 +23,9 @@
* SUCH DAMAGE.
*/
-#include <sys/cdefs.h>
-__FBSDID("$FreeBSD$");
-
-#include <opt_inet6.h>
+#include "opt_inet6.h"
#include <sys/param.h>
-#include <sys/systm.h>
#include <sys/conf.h>
#include <sys/ctype.h>
#include <sys/file.h>
@@ -47,6 +43,7 @@ __FBSDID("$FreeBSD$");
#include <net/if_var.h>
#include <net/if_dl.h>
#include <net/if_types.h>
+#include <netlink/netlink.h>
#include <sys/un.h>
#include <netinet/in.h>
@@ -56,7 +53,16 @@ __FBSDID("$FreeBSD$");
#include <compat/linux/linux_mib.h>
#include <compat/linux/linux_util.h>
-CTASSERT(LINUX_IFNAMSIZ == IFNAMSIZ);
+_Static_assert(LINUX_IFNAMSIZ == IFNAMSIZ, "Linux IFNAMSIZ");
+_Static_assert(sizeof(struct sockaddr) == sizeof(struct l_sockaddr),
+ "Linux struct sockaddr size");
+_Static_assert(offsetof(struct sockaddr, sa_data) ==
+ offsetof(struct l_sockaddr, sa_data), "Linux struct sockaddr layout");
+
+static bool use_real_ifnames = false;
+SYSCTL_BOOL(_compat_linux, OID_AUTO, use_real_ifnames, CTLFLAG_RWTUN,
+ &use_real_ifnames, 0,
+ "Use FreeBSD interface names instead of generating ethN aliases");
static int bsd_to_linux_sigtbl[LINUX_SIGTBLSZ] = {
LINUX_SIGHUP, /* SIGHUP */
@@ -92,6 +98,8 @@ static int bsd_to_linux_sigtbl[LINUX_SIGTBLSZ] = {
LINUX_SIGUSR2 /* SIGUSR2 */
};
+#define LINUX_SIGPWREMU (SIGRTMIN + (LINUX_SIGRTMAX - LINUX_SIGRTMIN) + 1)
+
static int linux_to_bsd_sigtbl[LINUX_SIGTBLSZ] = {
SIGHUP, /* LINUX_SIGHUP */
SIGINT, /* LINUX_SIGINT */
@@ -127,7 +135,7 @@ static int linux_to_bsd_sigtbl[LINUX_SIGTBLSZ] = {
* to the first unused FreeBSD signal number. Since Linux supports
* signals from 1 to 64 we are ok here as our SIGRTMIN = 65.
*/
- SIGRTMIN, /* LINUX_SIGPWR */
+ LINUX_SIGPWREMU,/* LINUX_SIGPWR */
SIGSYS /* LINUX_SIGSYS */
};
@@ -144,14 +152,14 @@ static inline int
linux_to_bsd_rt_signal(int sig)
{
- return (SIGRTMIN + 1 + sig - LINUX_SIGRTMIN);
+ return (SIGRTMIN + sig - LINUX_SIGRTMIN);
}
static inline int
bsd_to_linux_rt_signal(int sig)
{
- return (sig - SIGRTMIN - 1 + LINUX_SIGRTMIN);
+ return (sig - SIGRTMIN + LINUX_SIGRTMIN);
}
int
@@ -172,7 +180,7 @@ bsd_to_linux_signal(int sig)
if (sig <= LINUX_SIGTBLSZ)
return (bsd_to_linux_sigtbl[_SIG_IDX(sig)]);
- if (sig == SIGRTMIN)
+ if (sig == LINUX_SIGPWREMU)
return (LINUX_SIGPWR);
return (bsd_to_linux_rt_signal(sig));
@@ -235,116 +243,266 @@ bsd_to_linux_sigset(sigset_t *bss, l_sigset_t *lss)
}
/*
+ * Translate a FreeBSD interface name to a Linux interface name
+ * by interface name, and return the number of bytes copied to lxname.
+ */
+int
+ifname_bsd_to_linux_name(const char *bsdname, char *lxname, size_t len)
+{
+ struct epoch_tracker et;
+ struct ifnet *ifp;
+ int ret;
+
+ CURVNET_ASSERT_SET();
+
+ ret = 0;
+ NET_EPOCH_ENTER(et);
+ ifp = ifunit(bsdname);
+ if (ifp != NULL)
+ ret = ifname_bsd_to_linux_ifp(ifp, lxname, len);
+ NET_EPOCH_EXIT(et);
+ return (ret);
+}
+
+/*
+ * Translate a FreeBSD interface name to a Linux interface name
+ * by interface index, and return the number of bytes copied to lxname.
+ */
+int
+ifname_bsd_to_linux_idx(u_int idx, char *lxname, size_t len)
+{
+ struct epoch_tracker et;
+ struct ifnet *ifp;
+ int ret;
+
+ ret = 0;
+ CURVNET_SET(TD_TO_VNET(curthread));
+ NET_EPOCH_ENTER(et);
+ ifp = ifnet_byindex(idx);
+ if (ifp != NULL)
+ ret = ifname_bsd_to_linux_ifp(ifp, lxname, len);
+ NET_EPOCH_EXIT(et);
+ CURVNET_RESTORE();
+ return (ret);
+}
+
+/*
+ * Translate a FreeBSD interface name to a Linux interface name,
+ * and return the number of bytes copied to lxname, 0 if interface
+ * not found, -1 on error.
+ */
+struct ifname_bsd_to_linux_ifp_cb_s {
+ struct ifnet *ifp;
+ int ethno;
+ char *lxname;
+ size_t len;
+};
+
+static int
+ifname_bsd_to_linux_ifp_cb(if_t ifp, void *arg)
+{
+ struct ifname_bsd_to_linux_ifp_cb_s *cbs = arg;
+
+ if (ifp == cbs->ifp)
+ return (snprintf(cbs->lxname, cbs->len, "eth%d", cbs->ethno));
+ if (IFP_IS_ETH(ifp))
+ cbs->ethno++;
+ return (0);
+}
+
+int
+ifname_bsd_to_linux_ifp(struct ifnet *ifp, char *lxname, size_t len)
+{
+ struct ifname_bsd_to_linux_ifp_cb_s arg = {
+ .ifp = ifp,
+ .ethno = 0,
+ .lxname = lxname,
+ .len = len,
+ };
+
+ NET_EPOCH_ASSERT();
+
+ /*
+ * Linux loopback interface name is lo (not lo0),
+ * we translate lo to lo0, loX to loX.
+ */
+ if (IFP_IS_LOOP(ifp) && strncmp(if_name(ifp), "lo0", IFNAMSIZ) == 0)
+ return (strlcpy(lxname, "lo", len));
+
+ /* Short-circuit non ethernet interfaces. */
+ if (!IFP_IS_ETH(ifp) || linux_use_real_ifname(ifp))
+ return (strlcpy(lxname, if_name(ifp), len));
+
+ /* Determine the (relative) unit number for ethernet interfaces. */
+ return (if_foreach(ifname_bsd_to_linux_ifp_cb, &arg));
+}
+
+/*
* Translate a Linux interface name to a FreeBSD interface name,
* and return the associated ifnet structure
* bsdname and lxname need to be least IFNAMSIZ bytes long, but
* can point to the same buffer.
*/
+struct ifname_linux_to_ifp_cb_s {
+ bool is_lo;
+ bool is_eth;
+ int ethno;
+ int unit;
+ const char *lxname;
+ if_t ifp;
+};
+
+static int
+ifname_linux_to_ifp_cb(if_t ifp, void *arg)
+{
+ struct ifname_linux_to_ifp_cb_s *cbs = arg;
+
+ NET_EPOCH_ASSERT();
+
+ /*
+ * Allow Linux programs to use FreeBSD names. Don't presume
+ * we never have an interface named "eth", so don't make
+ * the test optional based on is_eth.
+ */
+ if (strncmp(if_name(ifp), cbs->lxname, LINUX_IFNAMSIZ) == 0)
+ goto out;
+ if (cbs->is_eth && IFP_IS_ETH(ifp) && cbs->unit == cbs->ethno)
+ goto out;
+ if (cbs->is_lo && IFP_IS_LOOP(ifp))
+ goto out;
+ if (IFP_IS_ETH(ifp))
+ cbs->ethno++;
+ return (0);
+
+out:
+ cbs->ifp = ifp;
+ return (1);
+}
+
struct ifnet *
-ifname_linux_to_bsd(struct thread *td, const char *lxname, char *bsdname)
+ifname_linux_to_ifp(struct thread *td, const char *lxname)
{
- struct ifnet *ifp;
- int len, unit;
+ struct ifname_linux_to_ifp_cb_s arg = {
+ .ethno = 0,
+ .lxname = lxname,
+ .ifp = NULL,
+ };
+ int len;
char *ep;
- int index;
- bool is_eth, is_lo;
+
+ NET_EPOCH_ASSERT();
for (len = 0; len < LINUX_IFNAMSIZ; ++len)
if (!isalpha(lxname[len]) || lxname[len] == '\0')
break;
if (len == 0 || len == LINUX_IFNAMSIZ)
return (NULL);
- /* Linux loopback interface name is lo (not lo0) */
- is_lo = (len == 2 && strncmp(lxname, "lo", len) == 0);
- unit = (int)strtoul(lxname + len, &ep, 10);
+ /*
+ * Linux loopback interface name is lo (not lo0),
+ * we translate lo to lo0, loX to loX.
+ */
+ arg.is_lo = (len == 2 && strncmp(lxname, "lo", LINUX_IFNAMSIZ) == 0);
+ arg.unit = (int)strtoul(lxname + len, &ep, 10);
if ((ep == NULL || ep == lxname + len || ep >= lxname + LINUX_IFNAMSIZ) &&
- is_lo == 0)
+ arg.is_lo == 0)
return (NULL);
- index = 0;
- is_eth = (len == 3 && strncmp(lxname, "eth", len) == 0);
+ arg.is_eth = (len == 3 && strncmp(lxname, "eth", len) == 0);
+
+ if_foreach(ifname_linux_to_ifp_cb, &arg);
+ return (arg.ifp);
+}
+
+int
+ifname_linux_to_bsd(struct thread *td, const char *lxname, char *bsdname)
+{
+ struct epoch_tracker et;
+ struct ifnet *ifp;
CURVNET_SET(TD_TO_VNET(td));
- IFNET_RLOCK();
- CK_STAILQ_FOREACH(ifp, &V_ifnet, if_link) {
- /*
- * Allow Linux programs to use FreeBSD names. Don't presume
- * we never have an interface named "eth", so don't make
- * the test optional based on is_eth.
- */
- if (strncmp(ifp->if_xname, lxname, LINUX_IFNAMSIZ) == 0)
- break;
- if (is_eth && IFP_IS_ETH(ifp) && unit == index++)
- break;
- if (is_lo && IFP_IS_LOOP(ifp))
- break;
- }
- IFNET_RUNLOCK();
- CURVNET_RESTORE();
+ NET_EPOCH_ENTER(et);
+ ifp = ifname_linux_to_ifp(td, lxname);
if (ifp != NULL && bsdname != NULL)
- strlcpy(bsdname, ifp->if_xname, IFNAMSIZ);
- return (ifp);
+ strlcpy(bsdname, if_name(ifp), IFNAMSIZ);
+ NET_EPOCH_EXIT(et);
+ CURVNET_RESTORE();
+ return (ifp != NULL ? 0 : EINVAL);
}
-void
-linux_ifflags(struct ifnet *ifp, short *flags)
+unsigned short
+linux_ifflags(struct ifnet *ifp)
{
- unsigned short fl;
+ unsigned short flags;
+
+ NET_EPOCH_ASSERT();
+
+ flags = if_getflags(ifp) | if_getdrvflags(ifp);
+ return (bsd_to_linux_ifflags(flags));
+}
+
+unsigned short
+bsd_to_linux_ifflags(int fl)
+{
+ unsigned short flags = 0;
- fl = (ifp->if_flags | ifp->if_drv_flags) & 0xffff;
- *flags = 0;
if (fl & IFF_UP)
- *flags |= LINUX_IFF_UP;
+ flags |= LINUX_IFF_UP;
if (fl & IFF_BROADCAST)
- *flags |= LINUX_IFF_BROADCAST;
+ flags |= LINUX_IFF_BROADCAST;
if (fl & IFF_DEBUG)
- *flags |= LINUX_IFF_DEBUG;
+ flags |= LINUX_IFF_DEBUG;
if (fl & IFF_LOOPBACK)
- *flags |= LINUX_IFF_LOOPBACK;
+ flags |= LINUX_IFF_LOOPBACK;
if (fl & IFF_POINTOPOINT)
- *flags |= LINUX_IFF_POINTOPOINT;
+ flags |= LINUX_IFF_POINTOPOINT;
if (fl & IFF_DRV_RUNNING)
- *flags |= LINUX_IFF_RUNNING;
+ flags |= LINUX_IFF_RUNNING;
if (fl & IFF_NOARP)
- *flags |= LINUX_IFF_NOARP;
+ flags |= LINUX_IFF_NOARP;
if (fl & IFF_PROMISC)
- *flags |= LINUX_IFF_PROMISC;
+ flags |= LINUX_IFF_PROMISC;
if (fl & IFF_ALLMULTI)
- *flags |= LINUX_IFF_ALLMULTI;
+ flags |= LINUX_IFF_ALLMULTI;
if (fl & IFF_MULTICAST)
- *flags |= LINUX_IFF_MULTICAST;
+ flags |= LINUX_IFF_MULTICAST;
+ return (flags);
+}
+
+static u_int
+linux_ifhwaddr_cb(void *arg, struct ifaddr *ifa, u_int count)
+{
+ struct sockaddr_dl *sdl = (struct sockaddr_dl *)ifa->ifa_addr;
+ struct l_sockaddr *lsa = arg;
+
+ if (count > 0)
+ return (0);
+ if (sdl->sdl_type != IFT_ETHER)
+ return (0);
+ bzero(lsa, sizeof(*lsa));
+ lsa->sa_family = LINUX_ARPHRD_ETHER;
+ bcopy(LLADDR(sdl), lsa->sa_data, LINUX_IFHWADDRLEN);
+ return (1);
}
int
linux_ifhwaddr(struct ifnet *ifp, struct l_sockaddr *lsa)
{
- struct ifaddr *ifa;
- struct sockaddr_dl *sdl;
+
+ NET_EPOCH_ASSERT();
if (IFP_IS_LOOP(ifp)) {
bzero(lsa, sizeof(*lsa));
lsa->sa_family = LINUX_ARPHRD_LOOPBACK;
return (0);
}
-
if (!IFP_IS_ETH(ifp))
return (ENOENT);
-
- CK_STAILQ_FOREACH(ifa, &ifp->if_addrhead, ifa_link) {
- sdl = (struct sockaddr_dl*)ifa->ifa_addr;
- if (sdl != NULL && (sdl->sdl_family == AF_LINK) &&
- (sdl->sdl_type == IFT_ETHER)) {
- bzero(lsa, sizeof(*lsa));
- lsa->sa_family = LINUX_ARPHRD_ETHER;
- bcopy(LLADDR(sdl), lsa->sa_data, LINUX_IFHWADDRLEN);
- return (0);
- }
- }
-
+ if (if_foreach_addr_type(ifp, AF_LINK, linux_ifhwaddr_cb, lsa) > 0)
+ return (0);
return (ENOENT);
}
-int
-linux_to_bsd_domain(int domain)
+sa_family_t
+linux_to_bsd_domain(sa_family_t domain)
{
switch (domain) {
@@ -362,12 +520,14 @@ linux_to_bsd_domain(int domain)
return (AF_IPX);
case LINUX_AF_APPLETALK:
return (AF_APPLETALK);
+ case LINUX_AF_NETLINK:
+ return (AF_NETLINK);
}
- return (-1);
+ return (AF_UNKNOWN);
}
-int
-bsd_to_linux_domain(int domain)
+sa_family_t
+bsd_to_linux_domain(sa_family_t domain)
{
switch (domain) {
@@ -385,8 +545,10 @@ bsd_to_linux_domain(int domain)
return (LINUX_AF_IPX);
case AF_APPLETALK:
return (LINUX_AF_APPLETALK);
+ case AF_NETLINK:
+ return (LINUX_AF_NETLINK);
}
- return (-1);
+ return (AF_UNKNOWN);
}
/*
@@ -400,32 +562,29 @@ bsd_to_linux_sockaddr(const struct sockaddr *sa, struct l_sockaddr **lsa,
socklen_t len)
{
struct l_sockaddr *kosa;
- int error, bdom;
+ sa_family_t bdom;
*lsa = NULL;
if (len < 2 || len > UCHAR_MAX)
return (EINVAL);
-
- kosa = malloc(len, M_SONAME, M_WAITOK);
- bcopy(sa, kosa, len);
-
bdom = bsd_to_linux_domain(sa->sa_family);
- if (bdom == -1) {
- error = EAFNOSUPPORT;
- goto out;
- }
+ if (bdom == AF_UNKNOWN)
+ return (EAFNOSUPPORT);
+ kosa = malloc(len, M_LINUX, M_WAITOK);
+ bcopy(sa, kosa, len);
kosa->sa_family = bdom;
*lsa = kosa;
return (0);
-
-out:
- free(kosa, M_SONAME);
- return (error);
}
+/*
+ * If sap is NULL, then osa points at already copied in linux sockaddr that
+ * should be edited in place. Otherwise memory is allocated, sockaddr
+ * copied in and returned in *sap.
+ */
int
-linux_to_bsd_sockaddr(const struct l_sockaddr *osa, struct sockaddr **sap,
+linux_to_bsd_sockaddr(struct l_sockaddr *osa, struct sockaddr **sap,
socklen_t *len)
{
struct sockaddr *sa;
@@ -455,13 +614,15 @@ linux_to_bsd_sockaddr(const struct l_sockaddr *osa, struct sockaddr **sap,
}
#endif
- kosa = malloc(salen, M_SONAME, M_WAITOK);
-
- if ((error = copyin(osa, kosa, *len)))
- goto out;
+ if (sap != NULL) {
+ kosa = malloc(salen, M_SONAME, M_WAITOK);
+ if ((error = copyin(osa, kosa, *len)))
+ goto out;
+ } else
+ kosa = osa;
bdom = linux_to_bsd_domain(kosa->sa_family);
- if (bdom == -1) {
+ if (bdom == AF_UNKNOWN) {
error = EAFNOSUPPORT;
goto out;
}
@@ -520,16 +681,27 @@ linux_to_bsd_sockaddr(const struct l_sockaddr *osa, struct sockaddr **sap,
}
}
+ if (bdom == AF_NETLINK) {
+ if (salen < sizeof(struct sockaddr_nl)) {
+ error = EINVAL;
+ goto out;
+ }
+ salen = sizeof(struct sockaddr_nl);
+ }
+
sa = (struct sockaddr *)kosa;
sa->sa_family = bdom;
sa->sa_len = salen;
- *sap = sa;
- *len = salen;
+ if (sap != NULL) {
+ *sap = sa;
+ *len = salen;
+ }
return (0);
out:
- free(kosa, M_SONAME);
+ if (sap != NULL)
+ free(kosa, M_SONAME);
return (error);
}
@@ -633,8 +805,6 @@ void
linux_to_bsd_poll_events(struct thread *td, int fd, short lev,
short *bev)
{
- struct proc *p = td->td_proc;
- struct filedesc *fdp;
struct file *fp;
int error;
short bits = 0;
@@ -666,8 +836,7 @@ linux_to_bsd_poll_events(struct thread *td, int fd, short lev,
* on non-socket file descriptors unlike FreeBSD, where
* events bits is more strictly checked (POLLSTANDARD).
*/
- fdp = p->p_fd;
- error = fget_unlocked(fdp, fd, &cap_no_rights, &fp);
+ error = fget_unlocked(td, fd, &cap_no_rights, &fp);
if (error == 0) {
/*
* XXX. On FreeBSD POLLRDHUP applies only to
@@ -719,3 +888,10 @@ bsd_to_linux_poll_events(short bev, short *lev)
*lev = bits;
}
+
+bool
+linux_use_real_ifname(const struct ifnet *ifp)
+{
+
+ return (use_real_ifnames);
+}
diff --git a/sys/compat/linux/linux.h b/sys/compat/linux/linux.h
index e75fbe773e61..6d276b8a69f4 100644
--- a/sys/compat/linux/linux.h
+++ b/sys/compat/linux/linux.h
@@ -1,4 +1,6 @@
/*-
+ * SPDX-License-Identifier: BSD-2-Clause
+ *
* Copyright (c) 2015 Dmitry Chagin <dchagin@FreeBSD.org>
*
* Redistribution and use in source and binary forms, with or without
@@ -21,14 +23,83 @@
* 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.
- *
- * $FreeBSD$
*/
#ifndef _LINUX_MI_H_
#define _LINUX_MI_H_
-#include <sys/queue.h>
+/*
+ * Machine independent set of types for the Linux types.
+ */
+typedef uint32_t l_dev_t;
+
+/*
+ * Linux dev_t conversion routines.
+ *
+ * As of version 2.6.0 of the Linux kernel, dev_t is a 32-bit quantity
+ * with 12 bits set asaid for the major number and 20 for the minor number.
+ * The in-kernel dev_t encoded as MMMmmmmm, where M is a hex digit of the
+ * major number and m is a hex digit of the minor number.
+ * The user-space dev_t encoded as mmmM MMmm, where M and m is the major
+ * and minor numbers accordingly. This is downward compatible with legacy
+ * systems where dev_t is 16 bits wide, encoded as MMmm.
+ * In glibc dev_t is a 64-bit quantity, with 32-bit major and minor numbers,
+ * encoded as MMMM Mmmm mmmM MMmm. This is downward compatible with the Linux
+ * kernel and with legacy systems where dev_t is 16 bits wide.
+ *
+ * In the FreeBSD dev_t is a 64-bit quantity. The major and minor numbers
+ * are encoded as MMMmmmMm, therefore conversion of the device numbers between
+ * Linux user-space and FreeBSD kernel required.
+ */
+static __inline l_dev_t
+linux_encode_dev(int _major, int _minor)
+{
+
+ return ((_minor & 0xff) | ((_major & 0xfff) << 8) |
+ (((_minor & ~0xff) << 12) & 0xfff00000));
+}
+
+static __inline l_dev_t
+linux_new_encode_dev(dev_t _dev)
+{
+
+ return (_dev == NODEV ? 0 : linux_encode_dev(major(_dev), minor(_dev)));
+}
+
+static __inline int
+linux_encode_major(dev_t _dev)
+{
+
+ return (_dev == NODEV ? 0 : major(_dev) & 0xfff);
+}
+
+static __inline int
+linux_encode_minor(dev_t _dev)
+{
+
+ return (_dev == NODEV ? 0 : minor(_dev) & 0xfffff);
+}
+
+static __inline int
+linux_decode_major(l_dev_t _dev)
+{
+
+ return ((_dev & 0xfff00) >> 8);
+}
+
+static __inline int
+linux_decode_minor(l_dev_t _dev)
+{
+
+ return ((_dev & 0xff) | ((_dev & 0xfff00000) >> 12));
+}
+
+static __inline dev_t
+linux_decode_dev(l_dev_t _dev)
+{
+
+ return (makedev(linux_decode_major(_dev), linux_decode_minor(_dev)));
+}
/*
* Private Brandinfo flags
@@ -55,12 +126,6 @@
#define LINUX_IFHWADDRLEN 6
#define LINUX_IFNAMSIZ 16
-/*
- * Criteria for interface name translation
- */
-#define IFP_IS_ETH(ifp) (ifp->if_type == IFT_ETHER)
-#define IFP_IS_LOOP(ifp) (ifp->if_type == IFT_LOOP)
-
struct l_sockaddr {
unsigned short sa_family;
char sa_data[14];
@@ -124,8 +189,8 @@ typedef struct {
/* primitives to manipulate sigset_t */
#define LINUX_SIGEMPTYSET(set) (set).__mask = 0
-#define LINUX_SIGISMEMBER(set, sig) (1UL & ((set).__mask >> _SIG_IDX(sig)))
-#define LINUX_SIGADDSET(set, sig) (set).__mask |= 1UL << _SIG_IDX(sig)
+#define LINUX_SIGISMEMBER(set, sig) (1ULL & ((set).__mask >> _SIG_IDX(sig)))
+#define LINUX_SIGADDSET(set, sig) (set).__mask |= 1ULL << _SIG_IDX(sig)
void linux_to_bsd_sigset(l_sigset_t *, sigset_t *);
void bsd_to_linux_sigset(sigset_t *, l_sigset_t *);
@@ -173,6 +238,11 @@ void bsd_to_linux_sigset(sigset_t *, l_sigset_t *);
int linux_to_bsd_signal(int sig);
int bsd_to_linux_signal(int sig);
+/* sigprocmask actions */
+#define LINUX_SIG_BLOCK 0
+#define LINUX_SIG_UNBLOCK 1
+#define LINUX_SIG_SETMASK 2
+
void linux_dev_shm_create(void);
void linux_dev_shm_destroy(void);
@@ -265,6 +335,41 @@ struct l_statx {
uint64_t __spare2[13];
};
+/*
+ * statfs f_flags
+ */
+#define LINUX_ST_RDONLY 0x0001
+#define LINUX_ST_NOSUID 0x0002
+#define LINUX_ST_NODEV 0x0004 /* No native analogue */
+#define LINUX_ST_NOEXEC 0x0008
+#define LINUX_ST_SYNCHRONOUS 0x0010
+#define LINUX_ST_VALID 0x0020
+#define LINUX_ST_MANDLOCK 0x0040 /* No native analogue */
+#define LINUX_ST_NOATIME 0x0400
+#define LINUX_ST_NODIRATIME 0x0800 /* No native analogue */
+#define LINUX_ST_RELATIME 0x1000 /* No native analogue */
+#define LINUX_ST_NOSYMFOLLOW 0x2000
+
+#ifndef lower_32_bits
#define lower_32_bits(n) ((uint32_t)((n) & 0xffffffff))
+#endif
+
+#ifdef KTRACE
+#define linux_ktrsigset(s, l) \
+ ktrstruct("l_sigset_t", (s), l)
+#endif
+
+/*
+ * Criteria for interface name translation
+ */
+#define IFP_IS_ETH(ifp) (if_gettype(ifp) == IFT_ETHER)
+#define IFP_IS_LOOP(ifp) (if_gettype(ifp) == IFT_LOOP)
+
+struct ifnet;
+
+bool linux_use_real_ifname(const struct ifnet *);
+
+void linux_netlink_register(void);
+void linux_netlink_deregister(void);
#endif /* _LINUX_MI_H_ */
diff --git a/sys/compat/linux/linux_common.c b/sys/compat/linux/linux_common.c
index 0009d9d26164..e22e29ff2b24 100644
--- a/sys/compat/linux/linux_common.c
+++ b/sys/compat/linux/linux_common.c
@@ -24,21 +24,14 @@
* SUCH DAMAGE.
*/
-#include <sys/cdefs.h>
-__FBSDID("$FreeBSD$");
-
#include <sys/param.h>
-#include <sys/systm.h>
#include <sys/exec.h>
#include <sys/imgact.h>
-#include <sys/imgact_elf.h>
#include <sys/kernel.h>
#include <sys/malloc.h>
#include <sys/sx.h>
#include <compat/linux/linux.h>
-#include <compat/linux/linux_emul.h>
-#include <compat/linux/linux_ioctl.h>
#include <compat/linux/linux_mib.h>
#include <compat/linux/linux_util.h>
@@ -63,12 +56,14 @@ linux_common_modevent(module_t mod, int type, void *data)
linux_osd_jail_register();
SET_FOREACH(ldhp, linux_device_handler_set)
linux_device_register_handler(*ldhp);
+ linux_netlink_register();
break;
case MOD_UNLOAD:
linux_dev_shm_destroy();
linux_osd_jail_deregister();
SET_FOREACH(ldhp, linux_device_handler_set)
linux_device_unregister_handler(*ldhp);
+ linux_netlink_deregister();
break;
default:
return (EOPNOTSUPP);
@@ -84,3 +79,4 @@ static moduledata_t linux_common_mod = {
DECLARE_MODULE(linux_common, linux_common_mod, SI_SUB_EXEC, SI_ORDER_ANY);
MODULE_VERSION(linux_common, 1);
+MODULE_DEPEND(linux_common, netlink, 1, 1, 1);
diff --git a/sys/compat/linux/linux_common.h b/sys/compat/linux/linux_common.h
index c6837a6a3b52..814c183b338a 100644
--- a/sys/compat/linux/linux_common.h
+++ b/sys/compat/linux/linux_common.h
@@ -23,27 +23,30 @@
* 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.
- *
- * $FreeBSD$
*/
#ifndef _LINUX_COMMON_H_
#define _LINUX_COMMON_H_
-struct ifnet *ifname_linux_to_bsd(struct thread *td,
- const char *lxname, char *bsdname);
-void linux_ifflags(struct ifnet *ifp, short *flags);
+int ifname_bsd_to_linux_ifp(struct ifnet *, char *, size_t);
+int ifname_bsd_to_linux_idx(u_int, char *, size_t);
+int ifname_bsd_to_linux_name(const char *, char *, size_t);
+struct ifnet *ifname_linux_to_ifp(struct thread *, const char *);
+int ifname_linux_to_bsd(struct thread *, const char *, char *);
+
+unsigned short linux_ifflags(struct ifnet *);
int linux_ifhwaddr(struct ifnet *ifp, struct l_sockaddr *lsa);
-int linux_to_bsd_domain(int domain);
-int bsd_to_linux_domain(int domain);
+unsigned short bsd_to_linux_ifflags(int);
+sa_family_t linux_to_bsd_domain(sa_family_t domain);
+sa_family_t bsd_to_linux_domain(sa_family_t domain);
+#define AF_UNKNOWN UINT8_MAX
int bsd_to_linux_sockaddr(const struct sockaddr *sa,
struct l_sockaddr **lsa, socklen_t len);
-int linux_to_bsd_sockaddr(const struct l_sockaddr *lsa,
+int linux_to_bsd_sockaddr(struct l_sockaddr *lsa,
struct sockaddr **sap, socklen_t *len);
void linux_to_bsd_poll_events(struct thread *td, int fd,
short lev, short *bev);
void bsd_to_linux_poll_events(short bev, short *lev);
-
#endif /* _LINUX_COMMON_H_ */
diff --git a/sys/compat/linux/linux_dtrace.h b/sys/compat/linux/linux_dtrace.h
index 0bf42f43bac1..2e4c1315aa3d 100644
--- a/sys/compat/linux/linux_dtrace.h
+++ b/sys/compat/linux/linux_dtrace.h
@@ -1,5 +1,5 @@
/*-
- * SPDX-License-Identifier: BSD-2-Clause-FreeBSD
+ * SPDX-License-Identifier: BSD-2-Clause
*
* Copyright (c) 2008-2012 Alexander Leidinger <netchild@FreeBSD.org>
* All rights reserved.
@@ -24,8 +24,6 @@
* 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.
- *
- * $FreeBSD$
*/
#ifndef _LINUX_DTRACE_H_
diff --git a/sys/compat/linux/linux_dummy.c b/sys/compat/linux/linux_dummy.c
index 91a56616fc10..19cd55849f65 100644
--- a/sys/compat/linux/linux_dummy.c
+++ b/sys/compat/linux/linux_dummy.c
@@ -1,5 +1,5 @@
/*-
- * SPDX-License-Identifier: BSD-2-Clause-FreeBSD
+ * SPDX-License-Identifier: BSD-2-Clause
*
* Copyright (c) 2013 Dmitry Chagin <dchagin@FreeBSD.org>
*
@@ -25,13 +25,9 @@
* SUCH DAMAGE.
*/
-#include <sys/cdefs.h>
-__FBSDID("$FreeBSD$");
-
#include <sys/param.h>
-#include <sys/kernel.h>
-#include <sys/sdt.h>
#include <sys/systm.h>
+#include <sys/sdt.h>
#include <sys/proc.h>
/*
@@ -78,11 +74,6 @@ DUMMY(kexec_load);
DUMMY(add_key);
DUMMY(request_key);
DUMMY(keyctl);
-/* Linux 2.6.13: */
-DUMMY(ioprio_set);
-DUMMY(ioprio_get);
-DUMMY(inotify_add_watch);
-DUMMY(inotify_rm_watch);
/* Linux 2.6.16: */
DUMMY(migrate_pages);
DUMMY(unshare);
@@ -93,7 +84,6 @@ DUMMY(vmsplice);
DUMMY(move_pages);
/* Linux 2.6.27: */
DUMMY(signalfd4);
-DUMMY(inotify_init1);
/* Linux 2.6.31: */
DUMMY(perf_event_open);
/* Linux 2.6.36: */
@@ -112,8 +102,6 @@ DUMMY(kcmp);
DUMMY(finit_module);
DUMMY(sched_setattr);
DUMMY(sched_getattr);
-/* Linux 3.17: */
-DUMMY(seccomp);
/* Linux 3.18: */
DUMMY(bpf);
/* Linux 3.19: */
@@ -131,45 +119,42 @@ DUMMY(pwritev2);
DUMMY(pkey_mprotect);
DUMMY(pkey_alloc);
DUMMY(pkey_free);
+/* Linux 4.18: */
+DUMMY(io_pgetevents);
+/* Linux 5.1: */
+DUMMY(pidfd_send_signal);
+DUMMY(io_uring_setup);
+DUMMY(io_uring_enter);
+DUMMY(io_uring_register);
+/* Linux 5.2: */
DUMMY(open_tree);
DUMMY(move_mount);
DUMMY(fsopen);
DUMMY(fsconfig);
DUMMY(fsmount);
DUMMY(fspick);
+/* Linux 5.3: */
DUMMY(pidfd_open);
-DUMMY(close_range);
+/* Linux 5.6: */
DUMMY(openat2);
DUMMY(pidfd_getfd);
+/* Linux 5.10: */
DUMMY(process_madvise);
-DUMMY(epoll_pwait2);
+/* Linux 5.12: */
DUMMY(mount_setattr);
-/* Linux 4.18: */
-DUMMY(io_pgetevents);
-DUMMY(rseq);
-/* Linux 5.0: */
-DUMMY(pidfd_send_signal);
-DUMMY(io_uring_setup);
-DUMMY(io_uring_enter);
-DUMMY(io_uring_register);
-
-#define DUMMY_XATTR(s) \
-int \
-linux_ ## s ## xattr( \
- struct thread *td, struct linux_ ## s ## xattr_args *arg) \
-{ \
- \
- return (EOPNOTSUPP); \
-}
-DUMMY_XATTR(set);
-DUMMY_XATTR(lset);
-DUMMY_XATTR(fset);
-DUMMY_XATTR(get);
-DUMMY_XATTR(lget);
-DUMMY_XATTR(fget);
-DUMMY_XATTR(list);
-DUMMY_XATTR(llist);
-DUMMY_XATTR(flist);
-DUMMY_XATTR(remove);
-DUMMY_XATTR(lremove);
-DUMMY_XATTR(fremove);
+/* Linux 5.13: */
+DUMMY(landlock_create_ruleset);
+DUMMY(landlock_add_rule);
+DUMMY(landlock_restrict_self);
+/* Linux 5.14: */
+DUMMY(memfd_secret);
+DUMMY(quotactl_fd);
+/* Linux 5.15: */
+DUMMY(process_mrelease);
+/* Linux 5.16: */
+DUMMY(futex_waitv);
+DUMMY(set_mempolicy_home_node);
+/* Linux 6.5: */
+DUMMY(cachestat);
+/* Linux 6.6: */
+DUMMY(fchmodat2);
diff --git a/sys/compat/linux/linux_elf.c b/sys/compat/linux/linux_elf.c
index bcbd4d1cad51..c9eb6aea8373 100644
--- a/sys/compat/linux/linux_elf.c
+++ b/sys/compat/linux/linux_elf.c
@@ -37,10 +37,8 @@
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
-#include <sys/cdefs.h>
-__FBSDID("$FreeBSD$");
-
#include <sys/param.h>
+#include <sys/exec.h>
#include <sys/imgact.h>
#include <sys/imgact_elf.h>
#include <sys/lock.h>
@@ -50,10 +48,15 @@ __FBSDID("$FreeBSD$");
#include <sys/procfs.h>
#include <sys/reg.h>
#include <sys/sbuf.h>
+#include <sys/sysent.h>
+
+#include <vm/vm.h>
+#include <vm/pmap.h>
+#include <vm/vm_map.h>
#include <machine/elf.h>
-#if __ELF_WORD_SIZE == 32
+#ifdef COMPAT_LINUX32
#define linux_pt_regset linux_pt_regset32
#define bsd_to_linux_regset bsd_to_linux_regset32
#include <machine/../linux32/linux.h>
@@ -61,11 +64,33 @@ __FBSDID("$FreeBSD$");
#include <machine/../linux/linux.h>
#endif
#include <compat/linux/linux_elf.h>
-#include <compat/linux/linux_emul.h>
+#include <compat/linux/linux_mib.h>
#include <compat/linux/linux_misc.h>
-/* This adds "linux32_" and "linux64_" prefixes. */
-#define __linuxN(x) __CONCAT(__CONCAT(__CONCAT(linux,__ELF_WORD_SIZE),_),x)
+struct l_elf_siginfo {
+ l_int si_signo;
+ l_int si_code;
+ l_int si_errno;
+};
+
+typedef struct linux_pt_regset l_elf_gregset_t;
+
+struct linux_elf_prstatus {
+ struct l_elf_siginfo pr_info;
+ l_short pr_cursig;
+ l_ulong pr_sigpend;
+ l_ulong pr_sighold;
+ l_pid_t pr_pid;
+ l_pid_t pr_ppid;
+ l_pid_t pr_pgrp;
+ l_pid_t pr_sid;
+ l_timeval pr_utime;
+ l_timeval pr_stime;
+ l_timeval pr_cutime;
+ l_timeval pr_cstime;
+ l_elf_gregset_t pr_reg;
+ l_int pr_fpvalid;
+};
#define LINUX_NT_AUXV 6
@@ -115,7 +140,7 @@ __linuxN(prepare_notes)(struct thread *td, struct note_info_list *list,
}
typedef struct linux_elf_prstatus linux_elf_prstatus_t;
-#if __ELF_WORD_SIZE == 32
+#ifdef COMPAT_LINUX32
typedef struct prpsinfo32 linux_elf_prpsinfo_t;
typedef struct fpreg32 linux_elf_prfpregset_t;
#else
@@ -155,13 +180,16 @@ __linuxN(note_prpsinfo)(void *arg, struct sbuf *sb, size_t *sizep)
sizeof(psinfo->pr_psargs), SBUF_FIXEDLEN);
error = proc_getargv(curthread, p, &sbarg);
PRELE(p);
- if (sbuf_finish(&sbarg) == 0)
+ if (sbuf_finish(&sbarg) == 0) {
len = sbuf_len(&sbarg) - 1;
- else
+ if (len > 0)
+ len--;
+ } else {
len = sizeof(psinfo->pr_psargs) - 1;
+ }
sbuf_delete(&sbarg);
}
- if (error || len == 0)
+ if (error != 0 || len == 0 || (ssize_t)len == -1)
strlcpy(psinfo->pr_psargs, p->p_comm,
sizeof(psinfo->pr_psargs));
else {
@@ -189,7 +217,7 @@ __linuxN(note_prstatus)(void *arg, struct sbuf *sb, size_t *sizep)
{
struct thread *td;
linux_elf_prstatus_t *status;
-#if __ELF_WORD_SIZE == 32
+#ifdef COMPAT_LINUX32
struct reg32 pr_reg;
#else
struct reg pr_reg;
@@ -206,7 +234,7 @@ __linuxN(note_prstatus)(void *arg, struct sbuf *sb, size_t *sizep)
status->pr_cursig = td->td_proc->p_sig;
status->pr_pid = td->td_tid;
-#if __ELF_WORD_SIZE == 32
+#ifdef COMPAT_LINUX32
fill_regs32(td, &pr_reg);
#else
fill_regs(td, &pr_reg);
@@ -228,7 +256,7 @@ __linuxN(note_fpregset)(void *arg, struct sbuf *sb, size_t *sizep)
if (sb != NULL) {
KASSERT(*sizep == sizeof(*fpregset), ("invalid size"));
fpregset = malloc(sizeof(*fpregset), M_TEMP, M_ZERO | M_WAITOK);
-#if __ELF_WORD_SIZE == 32
+#ifdef COMPAT_LINUX32
fill_fpregs32(td, fpregset);
#else
fill_fpregs(td, fpregset);
@@ -289,3 +317,229 @@ __linuxN(note_nt_auxv)(void *arg, struct sbuf *sb, size_t *sizep)
PRELE(p);
}
}
+
+/*
+ * Copy strings out to the new process address space, constructing new arg
+ * and env vector tables. Return a pointer to the base so that it can be used
+ * as the initial stack pointer.
+ */
+int
+__linuxN(copyout_strings)(struct image_params *imgp, uintptr_t *stack_base)
+{
+ char canary[LINUX_AT_RANDOM_LEN];
+ char **vectp;
+ char *stringp;
+ uintptr_t destp, ustringp;
+ struct ps_strings *arginfo;
+ struct proc *p;
+ size_t execpath_len;
+ int argc, envc;
+ int error;
+
+ p = imgp->proc;
+ destp = PROC_PS_STRINGS(p);
+ arginfo = imgp->ps_strings = (void *)destp;
+
+ /*
+ * Copy the image path for the rtld.
+ */
+ if (imgp->execpath != NULL && imgp->auxargs != NULL) {
+ execpath_len = strlen(imgp->execpath) + 1;
+ destp -= execpath_len;
+ destp = rounddown2(destp, sizeof(void *));
+ imgp->execpathp = (void *)destp;
+ error = copyout(imgp->execpath, imgp->execpathp, execpath_len);
+ if (error != 0)
+ return (error);
+ }
+
+ /*
+ * Prepare the canary for SSP.
+ */
+ arc4rand(canary, sizeof(canary), 0);
+ destp -= sizeof(canary);
+ imgp->canary = (void *)destp;
+ error = copyout(canary, imgp->canary, sizeof(canary));
+ if (error != 0)
+ return (error);
+ imgp->canarylen = sizeof(canary);
+
+ /*
+ * Allocate room for the argument and environment strings.
+ */
+ destp -= ARG_MAX - imgp->args->stringspace;
+ destp = rounddown2(destp, sizeof(void *));
+ ustringp = destp;
+
+ if (imgp->auxargs) {
+ /*
+ * Allocate room on the stack for the ELF auxargs
+ * array. It has up to LINUX_AT_COUNT entries.
+ */
+ destp -= LINUX_AT_COUNT * sizeof(Elf_Auxinfo);
+ destp = rounddown2(destp, sizeof(void *));
+ }
+
+ vectp = (char **)destp;
+
+ /*
+ * Allocate room for the argv[] and env vectors including the
+ * terminating NULL pointers.
+ */
+ vectp -= imgp->args->argc + 1 + imgp->args->envc + 1;
+
+ /*
+ * Starting with 2.24, glibc depends on a 16-byte stack alignment.
+ */
+ vectp = (char **)((((uintptr_t)vectp + 8) & ~0xF) - 8);
+
+ /*
+ * vectp also becomes our initial stack base
+ */
+ *stack_base = (uintptr_t)vectp;
+
+ stringp = imgp->args->begin_argv;
+ argc = imgp->args->argc;
+ envc = imgp->args->envc;
+
+ /*
+ * Copy out strings - arguments and environment.
+ */
+ error = copyout(stringp, (void *)ustringp,
+ ARG_MAX - imgp->args->stringspace);
+ if (error != 0)
+ return (error);
+
+ /*
+ * Fill in "ps_strings" struct for ps, w, etc.
+ */
+ imgp->argv = vectp;
+ if (suword(&arginfo->ps_argvstr, (long)(intptr_t)vectp) != 0 ||
+ suword32(&arginfo->ps_nargvstr, argc) != 0)
+ return (EFAULT);
+
+ /*
+ * Fill in argument portion of vector table.
+ */
+ for (; argc > 0; --argc) {
+ if (suword(vectp++, ustringp) != 0)
+ return (EFAULT);
+ while (*stringp++ != 0)
+ ustringp++;
+ ustringp++;
+ }
+
+ /* a null vector table pointer separates the argp's from the envp's */
+ if (suword(vectp++, 0) != 0)
+ return (EFAULT);
+
+ imgp->envv = vectp;
+ if (suword(&arginfo->ps_envstr, (long)(intptr_t)vectp) != 0 ||
+ suword32(&arginfo->ps_nenvstr, envc) != 0)
+ return (EFAULT);
+
+ /*
+ * Fill in environment portion of vector table.
+ */
+ for (; envc > 0; --envc) {
+ if (suword(vectp++, ustringp) != 0)
+ return (EFAULT);
+ while (*stringp++ != 0)
+ ustringp++;
+ ustringp++;
+ }
+
+ /* end of vector table is a null pointer */
+ if (suword(vectp, 0) != 0)
+ return (EFAULT);
+
+ if (imgp->auxargs) {
+ vectp++;
+ error = imgp->sysent->sv_copyout_auxargs(imgp,
+ (uintptr_t)vectp);
+ if (error != 0)
+ return (error);
+ }
+
+ return (0);
+}
+
+bool
+linux_trans_osrel(const Elf_Note *note, int32_t *osrel)
+{
+ const Elf32_Word *desc;
+ uintptr_t p;
+
+ p = (uintptr_t)(note + 1);
+ p += roundup2(note->n_namesz, sizeof(Elf32_Addr));
+
+ desc = (const Elf32_Word *)p;
+ if (desc[0] != GNU_ABI_LINUX)
+ return (false);
+ /*
+ * For Linux we encode osrel using the Linux convention of
+ * (version << 16) | (major << 8) | (minor)
+ * See macro in linux_mib.h
+ */
+ *osrel = LINUX_KERNVER(desc[1], desc[2], desc[3]);
+
+ return (true);
+}
+
+int
+__linuxN(copyout_auxargs)(struct image_params *imgp, uintptr_t base)
+{
+ struct thread *td = curthread;
+ Elf_Auxargs *args;
+ Elf_Auxinfo *aarray, *pos;
+ struct proc *p;
+ int error, issetugid;
+
+ p = imgp->proc;
+ issetugid = p->p_flag & P_SUGID ? 1 : 0;
+ args = imgp->auxargs;
+ aarray = pos = malloc(LINUX_AT_COUNT * sizeof(*pos), M_TEMP,
+ M_WAITOK | M_ZERO);
+
+ __linuxN(arch_copyout_auxargs)(imgp, &pos);
+ /*
+ * Do not export AT_CLKTCK when emulating Linux kernel prior to 2.4.0,
+ * as it has appeared in the 2.4.0-rc7 first time.
+ * Being exported, AT_CLKTCK is returned by sysconf(_SC_CLK_TCK),
+ * glibc falls back to the hard-coded CLK_TCK value when aux entry
+ * is not present.
+ * Also see linux_times() implementation.
+ */
+ if (linux_kernver(td) >= LINUX_KERNVER(2,4,0))
+ AUXARGS_ENTRY(pos, LINUX_AT_CLKTCK, stclohz);
+ AUXARGS_ENTRY(pos, AT_PAGESZ, args->pagesz);
+ AUXARGS_ENTRY(pos, AT_PHDR, args->phdr);
+ AUXARGS_ENTRY(pos, AT_PHENT, args->phent);
+ AUXARGS_ENTRY(pos, AT_PHNUM, args->phnum);
+ AUXARGS_ENTRY(pos, AT_BASE, args->base);
+ AUXARGS_ENTRY(pos, AT_FLAGS, args->flags);
+ AUXARGS_ENTRY(pos, AT_ENTRY, args->entry);
+ AUXARGS_ENTRY(pos, AT_UID, imgp->proc->p_ucred->cr_ruid);
+ AUXARGS_ENTRY(pos, AT_EUID, imgp->proc->p_ucred->cr_svuid);
+ AUXARGS_ENTRY(pos, AT_GID, imgp->proc->p_ucred->cr_rgid);
+ AUXARGS_ENTRY(pos, AT_EGID, imgp->proc->p_ucred->cr_svgid);
+ AUXARGS_ENTRY(pos, LINUX_AT_SECURE, issetugid);
+ if (linux_kernver(td) >= LINUX_KERNVER(2,6,30))
+ AUXARGS_ENTRY_PTR(pos, LINUX_AT_RANDOM, imgp->canary);
+ if (linux_kernver(td) >= LINUX_KERNVER(2,6,26) && imgp->execpathp != 0)
+ AUXARGS_ENTRY(pos, LINUX_AT_EXECFN, PTROUT(imgp->execpathp));
+ if (args->execfd != -1)
+ AUXARGS_ENTRY(pos, AT_EXECFD, args->execfd);
+ if (linux_kernver(td) >= LINUX_KERNVER(5,13,0))
+ AUXARGS_ENTRY(pos, LINUX_AT_MINSIGSTKSZ,
+ imgp->sysent->sv_minsigstksz);
+ AUXARGS_ENTRY(pos, AT_NULL, 0);
+
+ free(imgp->auxargs, M_TEMP);
+ imgp->auxargs = NULL;
+ KASSERT(pos - aarray <= LINUX_AT_COUNT, ("Too many auxargs"));
+
+ error = copyout(aarray, PTRIN(base), sizeof(*aarray) * LINUX_AT_COUNT);
+ free(aarray, M_TEMP);
+ return (error);
+}
diff --git a/sys/compat/linux/linux_elf.h b/sys/compat/linux/linux_elf.h
index 4bb9318e360b..2584a8a990c0 100644
--- a/sys/compat/linux/linux_elf.h
+++ b/sys/compat/linux/linux_elf.h
@@ -1,5 +1,5 @@
/*-
- * SPDX-License-Identifier: BSD-2-Clause-FreeBSD
+ * SPDX-License-Identifier: BSD-2-Clause
*
* Copyright (c) 2018 Chuck Tuffli
*
@@ -28,29 +28,23 @@
#ifndef _COMPAT_LINUX_ELF_H_
#define _COMPAT_LINUX_ELF_H_
-struct l_elf_siginfo {
- l_int si_signo;
- l_int si_code;
- l_int si_errno;
-};
+struct note_info_list;
-typedef struct linux_pt_regset l_elf_gregset_t;
+/* Linux core notes are labeled "CORE" */
+#define LINUX_ABI_VENDOR "CORE"
-struct linux_elf_prstatus {
- struct l_elf_siginfo pr_info;
- l_short pr_cursig;
- l_ulong pr_sigpend;
- l_ulong pr_sighold;
- l_pid_t pr_pid;
- l_pid_t pr_ppid;
- l_pid_t pr_pgrp;
- l_pid_t pr_sid;
- l_timeval pr_utime;
- l_timeval pr_stime;
- l_timeval pr_cutime;
- l_timeval pr_cstime;
- l_elf_gregset_t pr_reg;
- l_int pr_fpvalid;
-};
+/* Elf notes */
+#define GNU_ABI_VENDOR "GNU"
+#define GNU_ABI_LINUX 0
+
+/* This adds "linux32_" and "linux64_" prefixes. */
+#define __linuxN(x) __CONCAT(__CONCAT(__CONCAT(linux,__ELF_WORD_SIZE),_),x)
+
+void __linuxN(prepare_notes)(struct thread *, struct note_info_list *,
+ size_t *);
+void __linuxN(arch_copyout_auxargs)(struct image_params *, Elf_Auxinfo **);
+int __linuxN(copyout_auxargs)(struct image_params *, uintptr_t);
+int __linuxN(copyout_strings)(struct image_params *, uintptr_t *);
+bool linux_trans_osrel(const Elf_Note *note, int32_t *osrel);
#endif
diff --git a/sys/compat/linux/linux_elf32.c b/sys/compat/linux/linux_elf32.c
index 17ee4b6baa0a..6bd4b141af85 100644
--- a/sys/compat/linux/linux_elf32.c
+++ b/sys/compat/linux/linux_elf32.c
@@ -1,5 +1,5 @@
/*-
- * SPDX-License-Identifier: BSD-2-Clause-FreeBSD
+ * SPDX-License-Identifier: BSD-2-Clause
*
* Copyright (c) 2021 Edward Tomasz Napierala <trasz@FreeBSD.org>
* Copyright (c) 2002 Doug Rabson
@@ -31,8 +31,5 @@
* SUCH DAMAGE.
*/
-#include <sys/cdefs.h>
-__FBSDID("$FreeBSD$");
-
#define __ELF_WORD_SIZE 32
#include <compat/linux/linux_elf.c>
diff --git a/sys/compat/linux/linux_elf64.c b/sys/compat/linux/linux_elf64.c
index 2e283d763bbc..397bcf741fae 100644
--- a/sys/compat/linux/linux_elf64.c
+++ b/sys/compat/linux/linux_elf64.c
@@ -1,5 +1,5 @@
/*-
- * SPDX-License-Identifier: BSD-2-Clause-FreeBSD
+ * SPDX-License-Identifier: BSD-2-Clause
*
* Copyright (c) 2021 Edward Tomasz Napierala <trasz@FreeBSD.org>
* Copyright (c) 2002 Doug Rabson
@@ -31,8 +31,5 @@
* SUCH DAMAGE.
*/
-#include <sys/cdefs.h>
-__FBSDID("$FreeBSD$");
-
#define __ELF_WORD_SIZE 64
#include <compat/linux/linux_elf.c>
diff --git a/sys/compat/linux/linux_emul.c b/sys/compat/linux/linux_emul.c
index f99f31fb668b..e5ab51802468 100644
--- a/sys/compat/linux/linux_emul.c
+++ b/sys/compat/linux/linux_emul.c
@@ -1,5 +1,5 @@
/*-
- * SPDX-License-Identifier: BSD-2-Clause-FreeBSD
+ * SPDX-License-Identifier: BSD-2-Clause
*
* Copyright (c) 1994-1996 Søren Schmidt
* Copyright (c) 2006 Roman Divacky
@@ -28,21 +28,16 @@
* SUCH DAMAGE.
*/
-#include <sys/cdefs.h>
-__FBSDID("$FreeBSD$");
-
#include <sys/param.h>
-#include <sys/systm.h>
#include <sys/fcntl.h>
#include <sys/imgact.h>
-#include <sys/kernel.h>
#include <sys/ktr.h>
#include <sys/lock.h>
#include <sys/malloc.h>
#include <sys/mutex.h>
-#include <sys/sx.h>
#include <sys/proc.h>
#include <sys/resourcevar.h>
+#include <sys/sx.h>
#include <sys/syscallsubr.h>
#include <sys/sysent.h>
@@ -99,7 +94,7 @@ static void
linux_set_default_openfiles(struct thread *td, struct proc *p)
{
struct rlimit rlim;
- int error;
+ int error __diagused;
if (linux_default_openfiles < 0)
return;
@@ -122,7 +117,7 @@ static void
linux_set_default_stacksize(struct thread *td, struct proc *p)
{
struct rlimit rlim;
- int error;
+ int error __diagused;
if (linux_default_stacksize < 0)
return;
@@ -149,7 +144,7 @@ linux_proc_init(struct thread *td, struct thread *newtd, bool init_thread)
p = newtd->td_proc;
/* non-exec call */
- em = malloc(sizeof(*em), M_TEMP, M_WAITOK | M_ZERO);
+ em = malloc(sizeof(*em), M_LINUX, M_WAITOK | M_ZERO);
if (init_thread) {
LINUX_CTR1(proc_init, "thread newtd(%d)",
newtd->td_tid);
@@ -176,7 +171,7 @@ linux_proc_init(struct thread *td, struct thread *newtd, bool init_thread)
/* lookup the old one */
em = em_find(td);
- KASSERT(em != NULL, ("proc_init: emuldata not found in exec case.\n"));
+ KASSERT(em != NULL, ("proc_init: thread emuldata not found.\n"));
em->em_tid = p->p_pid;
em->flags = 0;
@@ -185,10 +180,10 @@ linux_proc_init(struct thread *td, struct thread *newtd, bool init_thread)
em->child_set_tid = NULL;
pem = pem_find(p);
- KASSERT(pem != NULL, ("proc_exit: proc emuldata not found.\n"));
+ KASSERT(pem != NULL, ("proc_init: proc emuldata not found.\n"));
pem->persona = 0;
+ pem->oom_score_adj = 0;
}
-
}
void
@@ -213,41 +208,6 @@ linux_on_exit(struct proc *p)
free(pem, M_LINUX);
}
-/*
- * If a Linux binary is exec'ing something, try this image activator
- * first. We override standard shell script execution in order to
- * be able to modify the interpreter path. We only do this if a Linux
- * binary is doing the exec, so we do not create an EXEC module for it.
- */
-int
-linux_exec_imgact_try(struct image_params *imgp)
-{
- const char *head = (const char *)imgp->image_header;
- char *rpath;
- int error = -1;
-
- /*
- * The interpreter for shell scripts run from a Linux binary needs
- * to be located in /compat/linux if possible in order to recursively
- * maintain Linux path emulation.
- */
- if (((const short *)head)[0] == SHELLMAGIC) {
- /*
- * Run our normal shell image activator. If it succeeds attempt
- * to use the alternate path for the interpreter. If an
- * alternate path is found, use our stringspace to store it.
- */
- if ((error = exec_shell_imgact(imgp)) == 0) {
- linux_emul_convpath(imgp->interpreter_name, UIO_SYSSPACE,
- &rpath, 0, AT_FDCWD);
- if (rpath != NULL)
- imgp->args->fname_buf =
- imgp->interpreter_name = rpath;
- }
- }
- return (error);
-}
-
int
linux_common_execve(struct thread *td, struct image_args *eargs)
{
@@ -273,6 +233,10 @@ linux_common_execve(struct thread *td, struct image_args *eargs)
* FreeBSD binary we destroy Linux emuldata thread & proc entries.
*/
if (SV_CURPROC_ABI() != SV_ABI_LINUX) {
+
+ /* Clear ABI root directory if set. */
+ linux_pwd_onexec_native(td);
+
PROC_LOCK(p);
em = em_find(td);
KASSERT(em != NULL, ("proc_exec: thread emuldata not found.\n"));
@@ -283,13 +247,13 @@ linux_common_execve(struct thread *td, struct image_args *eargs)
p->p_emuldata = NULL;
PROC_UNLOCK(p);
- free(em, M_TEMP);
+ free(em, M_LINUX);
free(pem, M_LINUX);
}
return (EJUSTRETURN);
}
-void
+int
linux_on_exec(struct proc *p, struct image_params *imgp)
{
struct thread *td;
@@ -297,6 +261,7 @@ linux_on_exec(struct proc *p, struct image_params *imgp)
#if defined(__amd64__)
struct linux_pemuldata *pem;
#endif
+ int error;
td = curthread;
MPASS((imgp->sysent->sv_flags & SV_ABI_MASK) == SV_ABI_LINUX);
@@ -329,6 +294,10 @@ linux_on_exec(struct proc *p, struct image_params *imgp)
continue;
linux_proc_init(td, othertd, true);
}
+
+ /* Set ABI root directory. */
+ if ((error = linux_pwd_onexec(td)) != 0)
+ return (error);
}
#if defined(__amd64__)
/*
@@ -341,6 +310,7 @@ linux_on_exec(struct proc *p, struct image_params *imgp)
pem->persona |= LINUX_READ_IMPLIES_EXEC;
}
#endif
+ return (0);
}
void
@@ -355,7 +325,7 @@ linux_thread_dtor(struct thread *td)
LINUX_CTR1(thread_dtor, "thread(%d)", em->em_tid);
- free(em, M_TEMP);
+ free(em, M_LINUX);
}
void
diff --git a/sys/compat/linux/linux_emul.h b/sys/compat/linux/linux_emul.h
index 70646cc93847..6dfa31f6edf7 100644
--- a/sys/compat/linux/linux_emul.h
+++ b/sys/compat/linux/linux_emul.h
@@ -1,5 +1,5 @@
/*-
- * SPDX-License-Identifier: BSD-2-Clause-FreeBSD
+ * SPDX-License-Identifier: BSD-2-Clause
*
* Copyright (c) 2006 Roman Divacky
* All rights reserved.
@@ -25,18 +25,12 @@
* 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.
- *
- * $FreeBSD$
*/
#ifndef _LINUX_EMUL_H_
#define _LINUX_EMUL_H_
struct image_params;
-struct note_info_list;
-
-/* Linux core notes are labeled "CORE" */
-#define LINUX_ABI_VENDOR "CORE"
/*
* modeled after similar structure in NetBSD
@@ -54,15 +48,12 @@ struct linux_emuldata {
struct linux_emuldata *em_find(struct thread *);
-int linux_exec_imgact_try(struct image_params *);
void linux_proc_init(struct thread *, struct thread *, bool);
void linux_on_exit(struct proc *);
void linux_schedtail(struct thread *);
-void linux_on_exec(struct proc *, struct image_params *);
+int linux_on_exec(struct proc *, struct image_params *);
void linux_thread_dtor(struct thread *);
int linux_common_execve(struct thread *, struct image_args *);
-void linux32_prepare_notes(struct thread *, struct note_info_list *, size_t *);
-void linux64_prepare_notes(struct thread *, struct note_info_list *, size_t *);
/* process emuldata flags */
#define LINUX_XDEPR_REQUEUEOP 0x00000001 /* uses deprecated
@@ -75,6 +66,9 @@ struct linux_pemuldata {
struct sx pem_sx; /* lock for this struct */
uint32_t persona; /* process execution domain */
uint32_t ptrace_flags; /* used by ptrace(2) */
+ uint32_t oom_score_adj; /* /proc/self/oom_score_adj */
+ uint32_t so_timestamp; /* requested timeval */
+ uint32_t so_timestampns; /* requested timespec */
};
#define LINUX_PEM_XLOCK(p) sx_xlock(&(p)->pem_sx)
diff --git a/sys/compat/linux/linux_errno.c b/sys/compat/linux/linux_errno.c
index 69880db86319..f04f694e5bec 100644
--- a/sys/compat/linux/linux_errno.c
+++ b/sys/compat/linux/linux_errno.c
@@ -1,11 +1,7 @@
-/* $FreeBSD$ */
-
-#include <sys/cdefs.h>
-__FBSDID("$FreeBSD$");
#include <sys/param.h>
-#include <sys/errno.h>
#include <sys/systm.h>
+#include <sys/errno.h>
#include <compat/linux/linux.h>
#include <compat/linux/linux_errno.h>
diff --git a/sys/compat/linux/linux_errno.h b/sys/compat/linux/linux_errno.h
index 0eae6684ce44..22c52272bae6 100644
--- a/sys/compat/linux/linux_errno.h
+++ b/sys/compat/linux/linux_errno.h
@@ -1,5 +1,5 @@
/*-
- * SPDX-License-Identifier: BSD-2-Clause-FreeBSD
+ * SPDX-License-Identifier: BSD-2-Clause
*
* Copyright (c) 2020 The FreeBSD Foundation
*
@@ -26,8 +26,6 @@
* 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.
- *
- * $FreeBSD$
*/
#ifndef _LINUX_ERRNO_H_
diff --git a/sys/compat/linux/linux_errno.inc b/sys/compat/linux/linux_errno.inc
index 37d83962fe44..9e051db495d8 100644
--- a/sys/compat/linux/linux_errno.inc
+++ b/sys/compat/linux/linux_errno.inc
@@ -1,5 +1,5 @@
/*-
- * SPDX-License-Identifier: BSD-2-Clause-FreeBSD
+ * SPDX-License-Identifier: BSD-2-Clause
*
* Copyright (c) 1994-1996 Søren Schmidt
* All rights reserved.
@@ -24,8 +24,6 @@
* 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.
- *
- * $FreeBSD$
*/
/*
diff --git a/sys/compat/linux/linux_event.c b/sys/compat/linux/linux_event.c
index fa6ebc366ae9..fc3ef7c3e90a 100644
--- a/sys/compat/linux/linux_event.c
+++ b/sys/compat/linux/linux_event.c
@@ -1,5 +1,5 @@
/*-
- * SPDX-License-Identifier: BSD-2-Clause-FreeBSD
+ * SPDX-License-Identifier: BSD-2-Clause
*
* Copyright (c) 2007 Roman Divacky
* Copyright (c) 2014 Dmitry Chagin <dchagin@FreeBSD.org>
@@ -26,35 +26,27 @@
* SUCH DAMAGE.
*/
-#include <sys/cdefs.h>
-__FBSDID("$FreeBSD$");
-
-#include "opt_compat.h"
-
#include <sys/param.h>
-#include <sys/systm.h>
-#include <sys/imgact.h>
-#include <sys/kernel.h>
-#include <sys/limits.h>
-#include <sys/lock.h>
-#include <sys/mutex.h>
#include <sys/callout.h>
#include <sys/capsicum.h>
-#include <sys/types.h>
-#include <sys/user.h>
+#include <sys/errno.h>
+#include <sys/event.h>
+#include <sys/eventfd.h>
#include <sys/file.h>
#include <sys/filedesc.h>
#include <sys/filio.h>
-#include <sys/errno.h>
-#include <sys/event.h>
+#include <sys/limits.h>
+#include <sys/lock.h>
+#include <sys/mutex.h>
#include <sys/poll.h>
#include <sys/proc.h>
#include <sys/selinfo.h>
#include <sys/specialfd.h>
#include <sys/sx.h>
#include <sys/syscallsubr.h>
+#include <sys/timerfd.h>
#include <sys/timespec.h>
-#include <sys/eventfd.h>
+#include <sys/user.h>
#ifdef COMPAT_LINUX32
#include <machine/../linux32/linux.h>
@@ -67,7 +59,8 @@ __FBSDID("$FreeBSD$");
#include <compat/linux/linux_emul.h>
#include <compat/linux/linux_event.h>
#include <compat/linux/linux_file.h>
-#include <compat/linux/linux_timer.h>
+#include <compat/linux/linux_signal.h>
+#include <compat/linux/linux_time.h>
#include <compat/linux/linux_util.h>
typedef uint64_t epoll_udata_t;
@@ -107,60 +100,11 @@ struct epoll_copyout_args {
int error;
};
-/* timerfd */
-typedef uint64_t timerfd_t;
-
-static fo_rdwr_t timerfd_read;
-static fo_ioctl_t timerfd_ioctl;
-static fo_poll_t timerfd_poll;
-static fo_kqfilter_t timerfd_kqfilter;
-static fo_stat_t timerfd_stat;
-static fo_close_t timerfd_close;
-static fo_fill_kinfo_t timerfd_fill_kinfo;
-
-static struct fileops timerfdops = {
- .fo_read = timerfd_read,
- .fo_write = invfo_rdwr,
- .fo_truncate = invfo_truncate,
- .fo_ioctl = timerfd_ioctl,
- .fo_poll = timerfd_poll,
- .fo_kqfilter = timerfd_kqfilter,
- .fo_stat = timerfd_stat,
- .fo_close = timerfd_close,
- .fo_chmod = invfo_chmod,
- .fo_chown = invfo_chown,
- .fo_sendfile = invfo_sendfile,
- .fo_fill_kinfo = timerfd_fill_kinfo,
- .fo_flags = DFLAG_PASSABLE
-};
-
-static void filt_timerfddetach(struct knote *kn);
-static int filt_timerfdread(struct knote *kn, long hint);
-
-static struct filterops timerfd_rfiltops = {
- .f_isfd = 1,
- .f_detach = filt_timerfddetach,
- .f_event = filt_timerfdread
-};
-
-struct timerfd {
- clockid_t tfd_clockid;
- struct itimerspec tfd_time;
- struct callout tfd_callout;
- timerfd_t tfd_count;
- bool tfd_canceled;
- struct selinfo tfd_sel;
- struct mtx tfd_lock;
-};
-
-static void linux_timerfd_expire(void *);
-static void linux_timerfd_curval(struct timerfd *, struct itimerspec *);
-
static int
epoll_create_common(struct thread *td, int flags)
{
- return (kern_kqueue(td, flags, NULL));
+ return (kern_kqueue(td, flags, false, NULL));
}
#ifdef LINUX_LEGACY_SYSCALLS
@@ -421,15 +365,15 @@ leave1:
/*
* Wait for a filter to be triggered on the epoll file descriptor.
*/
+
static int
-linux_epoll_wait_common(struct thread *td, int epfd, struct epoll_event *events,
- int maxevents, int timeout, sigset_t *uset)
+linux_epoll_wait_ts(struct thread *td, int epfd, struct epoll_event *events,
+ int maxevents, struct timespec *tsp, sigset_t *uset)
{
struct epoll_copyout_args coargs;
struct kevent_copyops k_ops = { &coargs,
epoll_kev_copyout,
NULL};
- struct timespec ts, *tsp;
cap_rights_t rights;
struct file *epfp;
sigset_t omask;
@@ -457,9 +401,7 @@ linux_epoll_wait_common(struct thread *td, int epfd, struct epoll_event *events,
* usermode and TDP_OLDMASK is cleared, restoring old
* sigmask.
*/
- thread_lock(td);
- td->td_flags |= TDF_ASTPENDING;
- thread_unlock(td);
+ ast_sched(td, TDA_SIGSUSPEND);
}
coargs.leventlist = events;
@@ -467,20 +409,6 @@ linux_epoll_wait_common(struct thread *td, int epfd, struct epoll_event *events,
coargs.count = 0;
coargs.error = 0;
- /*
- * Linux epoll_wait(2) man page states that timeout of -1 causes caller
- * to block indefinitely. Real implementation does it if any negative
- * timeout value is passed.
- */
- if (timeout >= 0) {
- /* Convert from milliseconds to timespec. */
- ts.tv_sec = timeout / 1000;
- ts.tv_nsec = (timeout % 1000) * 1000000;
- tsp = &ts;
- } else {
- tsp = NULL;
- }
-
error = kern_kevent_fp(td, epfp, 0, maxevents, &k_ops, tsp);
if (error == 0 && coargs.error != 0)
error = coargs.error;
@@ -500,6 +428,29 @@ leave:
return (error);
}
+static int
+linux_epoll_wait_common(struct thread *td, int epfd, struct epoll_event *events,
+ int maxevents, int timeout, sigset_t *uset)
+{
+ struct timespec ts, *tsp;
+
+ /*
+ * Linux epoll_wait(2) man page states that timeout of -1 causes caller
+ * to block indefinitely. Real implementation does it if any negative
+ * timeout value is passed.
+ */
+ if (timeout >= 0) {
+ /* Convert from milliseconds to timespec. */
+ ts.tv_sec = timeout / 1000;
+ ts.tv_nsec = (timeout % 1000) * 1000000;
+ tsp = &ts;
+ } else {
+ tsp = NULL;
+ }
+ return (linux_epoll_wait_ts(td, epfd, events, maxevents, tsp, uset));
+
+}
+
#ifdef LINUX_LEGACY_SYSCALLS
int
linux_epoll_wait(struct thread *td, struct linux_epoll_wait_args *args)
@@ -514,22 +465,66 @@ int
linux_epoll_pwait(struct thread *td, struct linux_epoll_pwait_args *args)
{
sigset_t mask, *pmask;
- l_sigset_t lmask;
int error;
- if (args->mask != NULL) {
- if (args->sigsetsize != sizeof(l_sigset_t))
- return (EINVAL);
- error = copyin(args->mask, &lmask, sizeof(l_sigset_t));
+ error = linux_copyin_sigset(td, args->mask, sizeof(l_sigset_t),
+ &mask, &pmask);
+ if (error != 0)
+ return (error);
+
+ return (linux_epoll_wait_common(td, args->epfd, args->events,
+ args->maxevents, args->timeout, pmask));
+}
+
+#if defined(__i386__) || (defined(__amd64__) && defined(COMPAT_LINUX32))
+int
+linux_epoll_pwait2_64(struct thread *td, struct linux_epoll_pwait2_64_args *args)
+{
+ struct timespec ts, *tsa;
+ sigset_t mask, *pmask;
+ int error;
+
+ error = linux_copyin_sigset(td, args->mask, sizeof(l_sigset_t),
+ &mask, &pmask);
+ if (error != 0)
+ return (error);
+
+ if (args->timeout) {
+ error = linux_get_timespec64(&ts, args->timeout);
if (error != 0)
return (error);
- linux_to_bsd_sigset(&lmask, &mask);
- pmask = &mask;
+ tsa = &ts;
} else
- pmask = NULL;
- return (linux_epoll_wait_common(td, args->epfd, args->events,
- args->maxevents, args->timeout, pmask));
+ tsa = NULL;
+
+ return (linux_epoll_wait_ts(td, args->epfd, args->events,
+ args->maxevents, tsa, pmask));
}
+#else
+int
+linux_epoll_pwait2(struct thread *td, struct linux_epoll_pwait2_args *args)
+{
+ struct timespec ts, *tsa;
+ sigset_t mask, *pmask;
+ int error;
+
+ error = linux_copyin_sigset(td, args->mask, sizeof(l_sigset_t),
+ &mask, &pmask);
+ if (error != 0)
+ return (error);
+
+ if (args->timeout) {
+ error = linux_get_timespec(&ts, args->timeout);
+ if (error != 0)
+ return (error);
+ tsa = &ts;
+ } else
+ tsa = NULL;
+
+ return (linux_epoll_wait_ts(td, args->epfd, args->events,
+ args->maxevents, tsa, pmask));
+}
+#endif /* __i386__ || (__amd64__ && COMPAT_LINUX32) */
static int
epoll_register_kevent(struct thread *td, struct file *epfp, int fd, int filter,
@@ -615,363 +610,107 @@ linux_eventfd2(struct thread *td, struct linux_eventfd2_args *args)
int
linux_timerfd_create(struct thread *td, struct linux_timerfd_create_args *args)
{
- struct timerfd *tfd;
- struct file *fp;
clockid_t clockid;
- int fflags, fd, error;
-
- if ((args->flags & ~LINUX_TFD_CREATE_FLAGS) != 0)
- return (EINVAL);
+ int error, flags;
error = linux_to_native_clockid(&clockid, args->clockid);
if (error != 0)
return (error);
- if (clockid != CLOCK_REALTIME && clockid != CLOCK_MONOTONIC)
- return (EINVAL);
-
- fflags = 0;
+ flags = 0;
if ((args->flags & LINUX_TFD_CLOEXEC) != 0)
- fflags |= O_CLOEXEC;
-
- error = falloc(td, &fp, &fd, fflags);
- if (error != 0)
- return (error);
-
- tfd = malloc(sizeof(*tfd), M_EPOLL, M_WAITOK | M_ZERO);
- tfd->tfd_clockid = clockid;
- mtx_init(&tfd->tfd_lock, "timerfd", NULL, MTX_DEF);
-
- callout_init_mtx(&tfd->tfd_callout, &tfd->tfd_lock, 0);
- knlist_init_mtx(&tfd->tfd_sel.si_note, &tfd->tfd_lock);
-
- fflags = FREAD;
- if ((args->flags & LINUX_O_NONBLOCK) != 0)
- fflags |= FNONBLOCK;
-
- finit(fp, fflags, DTYPE_LINUXTFD, tfd, &timerfdops);
- fdrop(fp, td);
-
- td->td_retval[0] = fd;
- return (error);
-}
-
-static int
-timerfd_close(struct file *fp, struct thread *td)
-{
- struct timerfd *tfd;
-
- tfd = fp->f_data;
- if (fp->f_type != DTYPE_LINUXTFD || tfd == NULL)
- return (EINVAL);
-
- timespecclear(&tfd->tfd_time.it_value);
- timespecclear(&tfd->tfd_time.it_interval);
-
- callout_drain(&tfd->tfd_callout);
-
- seldrain(&tfd->tfd_sel);
- knlist_destroy(&tfd->tfd_sel.si_note);
-
- fp->f_ops = &badfileops;
- mtx_destroy(&tfd->tfd_lock);
- free(tfd, M_EPOLL);
+ flags |= O_CLOEXEC;
+ if ((args->flags & LINUX_TFD_NONBLOCK) != 0)
+ flags |= TFD_NONBLOCK;
- return (0);
+ return (kern_timerfd_create(td, clockid, flags));
}
-static int
-timerfd_read(struct file *fp, struct uio *uio, struct ucred *active_cred,
- int flags, struct thread *td)
+int
+linux_timerfd_gettime(struct thread *td, struct linux_timerfd_gettime_args *args)
{
- struct timerfd *tfd;
- timerfd_t count;
+ struct l_itimerspec lots;
+ struct itimerspec ots;
int error;
- tfd = fp->f_data;
- if (fp->f_type != DTYPE_LINUXTFD || tfd == NULL)
- return (EINVAL);
-
- if (uio->uio_resid < sizeof(timerfd_t))
- return (EINVAL);
+ error = kern_timerfd_gettime(td, args->fd, &ots);
+ if (error != 0)
+ return (error);
- error = 0;
- mtx_lock(&tfd->tfd_lock);
-retry:
- if (tfd->tfd_canceled) {
- tfd->tfd_count = 0;
- mtx_unlock(&tfd->tfd_lock);
- return (ECANCELED);
- }
- if (tfd->tfd_count == 0) {
- if ((fp->f_flag & FNONBLOCK) != 0) {
- mtx_unlock(&tfd->tfd_lock);
- return (EAGAIN);
- }
- error = mtx_sleep(&tfd->tfd_count, &tfd->tfd_lock, PCATCH, "ltfdrd", 0);
- if (error == 0)
- goto retry;
- }
- if (error == 0) {
- count = tfd->tfd_count;
- tfd->tfd_count = 0;
- mtx_unlock(&tfd->tfd_lock);
- error = uiomove(&count, sizeof(timerfd_t), uio);
- } else
- mtx_unlock(&tfd->tfd_lock);
+ error = native_to_linux_itimerspec(&lots, &ots);
+ if (error == 0)
+ error = copyout(&lots, args->old_value, sizeof(lots));
return (error);
}
-static int
-timerfd_poll(struct file *fp, int events, struct ucred *active_cred,
- struct thread *td)
-{
- struct timerfd *tfd;
- int revents = 0;
-
- tfd = fp->f_data;
- if (fp->f_type != DTYPE_LINUXTFD || tfd == NULL)
- return (POLLERR);
-
- mtx_lock(&tfd->tfd_lock);
- if ((events & (POLLIN|POLLRDNORM)) && tfd->tfd_count > 0)
- revents |= events & (POLLIN|POLLRDNORM);
- if (revents == 0)
- selrecord(td, &tfd->tfd_sel);
- mtx_unlock(&tfd->tfd_lock);
-
- return (revents);
-}
-
-static int
-timerfd_kqfilter(struct file *fp, struct knote *kn)
+int
+linux_timerfd_settime(struct thread *td, struct linux_timerfd_settime_args *args)
{
- struct timerfd *tfd;
-
- tfd = fp->f_data;
- if (fp->f_type != DTYPE_LINUXTFD || tfd == NULL)
- return (EINVAL);
+ struct l_itimerspec lots;
+ struct itimerspec nts, ots;
+ int error;
- if (kn->kn_filter == EVFILT_READ)
- kn->kn_fop = &timerfd_rfiltops;
+ error = copyin(args->new_value, &lots, sizeof(lots));
+ if (error != 0)
+ return (error);
+ error = linux_to_native_itimerspec(&nts, &lots);
+ if (error != 0)
+ return (error);
+ if (args->old_value == NULL)
+ error = kern_timerfd_settime(td, args->fd, args->flags, &nts, NULL);
else
- return (EINVAL);
-
- kn->kn_hook = tfd;
- knlist_add(&tfd->tfd_sel.si_note, kn, 0);
-
- return (0);
-}
-
-static void
-filt_timerfddetach(struct knote *kn)
-{
- struct timerfd *tfd = kn->kn_hook;
-
- mtx_lock(&tfd->tfd_lock);
- knlist_remove(&tfd->tfd_sel.si_note, kn, 1);
- mtx_unlock(&tfd->tfd_lock);
-}
-
-static int
-filt_timerfdread(struct knote *kn, long hint)
-{
- struct timerfd *tfd = kn->kn_hook;
-
- return (tfd->tfd_count > 0);
-}
-
-static int
-timerfd_ioctl(struct file *fp, u_long cmd, void *data,
- struct ucred *active_cred, struct thread *td)
-{
-
- if (fp->f_data == NULL || fp->f_type != DTYPE_LINUXTFD)
- return (EINVAL);
-
- switch (cmd) {
- case FIONBIO:
- case FIOASYNC:
- return (0);
+ error = kern_timerfd_settime(td, args->fd, args->flags, &nts, &ots);
+ if (error == 0 && args->old_value != NULL) {
+ error = native_to_linux_itimerspec(&lots, &ots);
+ if (error == 0)
+ error = copyout(&lots, args->old_value, sizeof(lots));
}
- return (ENOTTY);
-}
-
-static int
-timerfd_stat(struct file *fp, struct stat *st, struct ucred *active_cred)
-{
-
- return (ENXIO);
-}
-
-static int
-timerfd_fill_kinfo(struct file *fp, struct kinfo_file *kif, struct filedesc *fdp)
-{
-
- kif->kf_type = KF_TYPE_UNKNOWN;
- return (0);
-}
-
-static void
-linux_timerfd_clocktime(struct timerfd *tfd, struct timespec *ts)
-{
-
- if (tfd->tfd_clockid == CLOCK_REALTIME)
- getnanotime(ts);
- else /* CLOCK_MONOTONIC */
- getnanouptime(ts);
-}
-
-static void
-linux_timerfd_curval(struct timerfd *tfd, struct itimerspec *ots)
-{
- struct timespec cts;
-
- linux_timerfd_clocktime(tfd, &cts);
- *ots = tfd->tfd_time;
- if (ots->it_value.tv_sec != 0 || ots->it_value.tv_nsec != 0) {
- timespecsub(&ots->it_value, &cts, &ots->it_value);
- if (ots->it_value.tv_sec < 0 ||
- (ots->it_value.tv_sec == 0 &&
- ots->it_value.tv_nsec == 0)) {
- ots->it_value.tv_sec = 0;
- ots->it_value.tv_nsec = 1;
- }
- }
+ return (error);
}
+#if defined(__i386__) || (defined(__amd64__) && defined(COMPAT_LINUX32))
int
-linux_timerfd_gettime(struct thread *td, struct linux_timerfd_gettime_args *args)
+linux_timerfd_gettime64(struct thread *td, struct linux_timerfd_gettime64_args *args)
{
- struct l_itimerspec lots;
+ struct l_itimerspec64 lots;
struct itimerspec ots;
- struct timerfd *tfd;
- struct file *fp;
int error;
- error = fget(td, args->fd, &cap_read_rights, &fp);
+ error = kern_timerfd_gettime(td, args->fd, &ots);
if (error != 0)
return (error);
- tfd = fp->f_data;
- if (fp->f_type != DTYPE_LINUXTFD || tfd == NULL) {
- error = EINVAL;
- goto out;
- }
- mtx_lock(&tfd->tfd_lock);
- linux_timerfd_curval(tfd, &ots);
- mtx_unlock(&tfd->tfd_lock);
-
- error = native_to_linux_itimerspec(&lots, &ots);
+ error = native_to_linux_itimerspec64(&lots, &ots);
if (error == 0)
error = copyout(&lots, args->old_value, sizeof(lots));
-out:
- fdrop(fp, td);
return (error);
}
int
-linux_timerfd_settime(struct thread *td, struct linux_timerfd_settime_args *args)
+linux_timerfd_settime64(struct thread *td, struct linux_timerfd_settime64_args *args)
{
- struct l_itimerspec lots;
+ struct l_itimerspec64 lots;
struct itimerspec nts, ots;
- struct timespec cts, ts;
- struct timerfd *tfd;
- struct timeval tv;
- struct file *fp;
int error;
- if ((args->flags & ~LINUX_TFD_SETTIME_FLAGS) != 0)
- return (EINVAL);
-
error = copyin(args->new_value, &lots, sizeof(lots));
if (error != 0)
return (error);
- error = linux_to_native_itimerspec(&nts, &lots);
+ error = linux_to_native_itimerspec64(&nts, &lots);
if (error != 0)
return (error);
-
- error = fget(td, args->fd, &cap_write_rights, &fp);
- if (error != 0)
- return (error);
- tfd = fp->f_data;
- if (fp->f_type != DTYPE_LINUXTFD || tfd == NULL) {
- error = EINVAL;
- goto out;
- }
-
- mtx_lock(&tfd->tfd_lock);
- if (!timespecisset(&nts.it_value))
- timespecclear(&nts.it_interval);
- if (args->old_value != NULL)
- linux_timerfd_curval(tfd, &ots);
-
- tfd->tfd_time = nts;
- tfd->tfd_count = 0;
- if (timespecisset(&nts.it_value)) {
- linux_timerfd_clocktime(tfd, &cts);
- ts = nts.it_value;
- if ((args->flags & LINUX_TFD_TIMER_ABSTIME) == 0) {
- timespecadd(&tfd->tfd_time.it_value, &cts,
- &tfd->tfd_time.it_value);
- } else {
- timespecsub(&ts, &cts, &ts);
- }
- TIMESPEC_TO_TIMEVAL(&tv, &ts);
- callout_reset(&tfd->tfd_callout, tvtohz(&tv),
- linux_timerfd_expire, tfd);
- tfd->tfd_canceled = false;
- } else {
- tfd->tfd_canceled = true;
- callout_stop(&tfd->tfd_callout);
- }
- mtx_unlock(&tfd->tfd_lock);
-
- if (args->old_value != NULL) {
- error = native_to_linux_itimerspec(&lots, &ots);
+ if (args->old_value == NULL)
+ error = kern_timerfd_settime(td, args->fd, args->flags, &nts, NULL);
+ else
+ error = kern_timerfd_settime(td, args->fd, args->flags, &nts, &ots);
+ if (error == 0 && args->old_value != NULL) {
+ error = native_to_linux_itimerspec64(&lots, &ots);
if (error == 0)
error = copyout(&lots, args->old_value, sizeof(lots));
}
-out:
- fdrop(fp, td);
return (error);
}
-
-static void
-linux_timerfd_expire(void *arg)
-{
- struct timespec cts, ts;
- struct timeval tv;
- struct timerfd *tfd;
-
- tfd = (struct timerfd *)arg;
-
- linux_timerfd_clocktime(tfd, &cts);
- if (timespeccmp(&cts, &tfd->tfd_time.it_value, >=)) {
- if (timespecisset(&tfd->tfd_time.it_interval))
- timespecadd(&tfd->tfd_time.it_value,
- &tfd->tfd_time.it_interval,
- &tfd->tfd_time.it_value);
- else
- /* single shot timer */
- timespecclear(&tfd->tfd_time.it_value);
- if (timespecisset(&tfd->tfd_time.it_value)) {
- timespecsub(&tfd->tfd_time.it_value, &cts, &ts);
- TIMESPEC_TO_TIMEVAL(&tv, &ts);
- callout_reset(&tfd->tfd_callout, tvtohz(&tv),
- linux_timerfd_expire, tfd);
- }
- tfd->tfd_count++;
- KNOTE_LOCKED(&tfd->tfd_sel.si_note, 0);
- selwakeup(&tfd->tfd_sel);
- wakeup(&tfd->tfd_count);
- } else if (timespecisset(&tfd->tfd_time.it_value)) {
- timespecsub(&tfd->tfd_time.it_value, &cts, &ts);
- TIMESPEC_TO_TIMEVAL(&tv, &ts);
- callout_reset(&tfd->tfd_callout, tvtohz(&tv),
- linux_timerfd_expire, tfd);
- }
-}
+#endif
diff --git a/sys/compat/linux/linux_event.h b/sys/compat/linux/linux_event.h
index 445564da4150..8c6758fefcc9 100644
--- a/sys/compat/linux/linux_event.h
+++ b/sys/compat/linux/linux_event.h
@@ -22,8 +22,6 @@
* 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.
- *
- * $FreeBSD$
*/
#ifndef _LINUX_EVENT_H_
@@ -56,15 +54,7 @@
#define LINUX_EFD_SEMAPHORE (1 << 0)
-#define LINUX_TFD_TIMER_ABSTIME (1 << 0)
-#define LINUX_TFD_TIMER_CANCEL_ON_SET (1 << 1)
#define LINUX_TFD_CLOEXEC LINUX_O_CLOEXEC
#define LINUX_TFD_NONBLOCK LINUX_O_NONBLOCK
-#define LINUX_TFD_SHARED_FCNTL_FLAGS (LINUX_TFD_CLOEXEC \
- |LINUX_TFD_NONBLOCK)
-#define LINUX_TFD_CREATE_FLAGS LINUX_TFD_SHARED_FCNTL_FLAGS
-#define LINUX_TFD_SETTIME_FLAGS (LINUX_TFD_TIMER_ABSTIME \
- |LINUX_TFD_TIMER_CANCEL_ON_SET)
-
#endif /* !_LINUX_EVENT_H_ */
diff --git a/sys/compat/linux/linux_file.c b/sys/compat/linux/linux_file.c
index 285faaf8927b..a4be5313aa96 100644
--- a/sys/compat/linux/linux_file.c
+++ b/sys/compat/linux/linux_file.c
@@ -1,5 +1,5 @@
/*-
- * SPDX-License-Identifier: BSD-2-Clause-FreeBSD
+ * SPDX-License-Identifier: BSD-2-Clause
*
* Copyright (c) 1994-1995 Søren Schmidt
* All rights reserved.
@@ -26,28 +26,19 @@
* SUCH DAMAGE.
*/
-#include <sys/cdefs.h>
-__FBSDID("$FreeBSD$");
-
-#include "opt_compat.h"
-
#include <sys/param.h>
#include <sys/systm.h>
-#include <sys/capsicum.h>
-#include <sys/conf.h>
#include <sys/dirent.h>
#include <sys/fcntl.h>
#include <sys/file.h>
#include <sys/filedesc.h>
+#include <sys/inotify.h>
#include <sys/lock.h>
-#include <sys/malloc.h>
#include <sys/mman.h>
-#include <sys/mount.h>
-#include <sys/mutex.h>
-#include <sys/namei.h>
#include <sys/selinfo.h>
#include <sys/pipe.h>
#include <sys/proc.h>
+#include <sys/specialfd.h>
#include <sys/stat.h>
#include <sys/sx.h>
#include <sys/syscallsubr.h>
@@ -58,6 +49,7 @@ __FBSDID("$FreeBSD$");
#ifdef COMPAT_LINUX32
#include <compat/freebsd32/freebsd32_misc.h>
+#include <compat/freebsd32/freebsd32_util.h>
#include <machine/../linux32/linux.h>
#include <machine/../linux32/linux32_proto.h>
#else
@@ -108,22 +100,13 @@ static struct bsd_to_linux_bitmap mfd_bitmap[] = {
int
linux_creat(struct thread *td, struct linux_creat_args *args)
{
- char *path;
- int error;
- if (!LUSECONVPATH(td)) {
- return (kern_openat(td, AT_FDCWD, args->path, UIO_USERSPACE,
- O_WRONLY | O_CREAT | O_TRUNC, args->mode));
- }
- LCONVPATHEXIST(args->path, &path);
- error = kern_openat(td, AT_FDCWD, path, UIO_SYSSPACE,
- O_WRONLY | O_CREAT | O_TRUNC, args->mode);
- LFREEPATH(path);
- return (error);
+ return (kern_openat(td, AT_FDCWD, args->path, UIO_USERSPACE,
+ O_WRONLY | O_CREAT | O_TRUNC, args->mode));
}
#endif
-static int
+int
linux_common_openflags(int l_flags)
{
int bsd_flags;
@@ -225,45 +208,20 @@ done:
int
linux_openat(struct thread *td, struct linux_openat_args *args)
{
- char *path;
- int dfd, error;
+ int dfd;
dfd = (args->dfd == LINUX_AT_FDCWD) ? AT_FDCWD : args->dfd;
- if (!LUSECONVPATH(td)) {
- return (linux_common_open(td, dfd, args->filename, args->flags,
- args->mode, UIO_USERSPACE));
- }
- if (args->flags & LINUX_O_CREAT)
- LCONVPATH_AT(args->filename, &path, 1, dfd);
- else
- LCONVPATH_AT(args->filename, &path, 0, dfd);
-
- error = linux_common_open(td, dfd, path, args->flags, args->mode,
- UIO_SYSSPACE);
- LFREEPATH(path);
- return (error);
+ return (linux_common_open(td, dfd, args->filename, args->flags,
+ args->mode, UIO_USERSPACE));
}
#ifdef LINUX_LEGACY_SYSCALLS
int
linux_open(struct thread *td, struct linux_open_args *args)
{
- char *path;
- int error;
- if (!LUSECONVPATH(td)) {
- return (linux_common_open(td, AT_FDCWD, args->path, args->flags,
- args->mode, UIO_USERSPACE));
- }
- if (args->flags & LINUX_O_CREAT)
- LCONVPATHCREAT(args->path, &path);
- else
- LCONVPATHEXIST(args->path, &path);
-
- error = linux_common_open(td, AT_FDCWD, path, args->flags, args->mode,
- UIO_SYSSPACE);
- LFREEPATH(path);
- return (error);
+ return (linux_common_open(td, AT_FDCWD, args->path, args->flags,
+ args->mode, UIO_USERSPACE));
}
#endif
@@ -293,17 +251,8 @@ linux_name_to_handle_at(struct thread *td,
if ((args->flags & LINUX_AT_EMPTY_PATH) != 0)
bsd_flags |= AT_EMPTY_PATH;
- if (!LUSECONVPATH(td)) {
- error = kern_getfhat(td, bsd_flags, fd, args->name,
- UIO_USERSPACE, &fh, UIO_SYSSPACE);
- } else {
- char *path;
-
- LCONVPATH_AT(args->name, &path, 0, fd);
- error = kern_getfhat(td, bsd_flags, fd, path, UIO_SYSSPACE,
- &fh, UIO_SYSSPACE);
- LFREEPATH(path);
- }
+ error = kern_getfhat(td, bsd_flags, fd, args->name,
+ UIO_USERSPACE, &fh, UIO_SYSSPACE);
if (error != 0)
return (error);
@@ -465,7 +414,7 @@ linux_getdents(struct thread *td, struct linux_getdents_args *args)
size_t retval;
buflen = min(args->count, MAXBSIZE);
- buf = malloc(buflen, M_TEMP, M_WAITOK);
+ buf = malloc(buflen, M_LINUX, M_WAITOK);
error = kern_getdirentries(td, args->fd, buf, buflen,
&base, NULL, UIO_SYSSPACE);
@@ -474,7 +423,7 @@ linux_getdents(struct thread *td, struct linux_getdents_args *args)
goto out1;
}
- lbuf = malloc(LINUX_RECLEN(LINUX_NAME_MAX), M_TEMP, M_WAITOK | M_ZERO);
+ lbuf = malloc(LINUX_RECLEN(LINUX_NAME_MAX), M_LINUX, M_WAITOK | M_ZERO);
len = td->td_retval[0];
inp = buf;
@@ -497,7 +446,7 @@ linux_getdents(struct thread *td, struct linux_getdents_args *args)
linux_dirent = (struct l_dirent*)lbuf;
linux_dirent->d_ino = bdp->d_fileno;
- linux_dirent->d_off = base + reclen;
+ linux_dirent->d_off = bdp->d_off;
linux_dirent->d_reclen = linuxreclen;
/*
* Copy d_type to last byte of l_dirent buffer
@@ -520,9 +469,9 @@ linux_getdents(struct thread *td, struct linux_getdents_args *args)
td->td_retval[0] = retval;
out:
- free(lbuf, M_TEMP);
+ free(lbuf, M_LINUX);
out1:
- free(buf, M_TEMP);
+ free(buf, M_LINUX);
return (error);
}
#endif
@@ -535,14 +484,13 @@ linux_getdents64(struct thread *td, struct linux_getdents64_args *args)
int len, reclen; /* BSD-format */
caddr_t outp; /* Linux-format */
int resid, linuxreclen; /* Linux-format */
- caddr_t lbuf; /* Linux-format */
off_t base;
struct l_dirent64 *linux_dirent64;
int buflen, error;
size_t retval;
buflen = min(args->count, MAXBSIZE);
- buf = malloc(buflen, M_TEMP, M_WAITOK);
+ buf = malloc(buflen, M_LINUX, M_WAITOK);
error = kern_getdirentries(td, args->fd, buf, buflen,
&base, NULL, UIO_SYSSPACE);
@@ -551,7 +499,8 @@ linux_getdents64(struct thread *td, struct linux_getdents64_args *args)
goto out1;
}
- lbuf = malloc(LINUX_RECLEN64(LINUX_NAME_MAX), M_TEMP, M_WAITOK | M_ZERO);
+ linux_dirent64 = malloc(LINUX_RECLEN64(LINUX_NAME_MAX), M_LINUX,
+ M_WAITOK | M_ZERO);
len = td->td_retval[0];
inp = buf;
@@ -572,9 +521,8 @@ linux_getdents64(struct thread *td, struct linux_getdents64_args *args)
goto out;
}
- linux_dirent64 = (struct l_dirent64*)lbuf;
linux_dirent64->d_ino = bdp->d_fileno;
- linux_dirent64->d_off = base + reclen;
+ linux_dirent64->d_off = bdp->d_off;
linux_dirent64->d_reclen = linuxreclen;
linux_dirent64->d_type = bdp->d_type;
strlcpy(linux_dirent64->d_name, bdp->d_name,
@@ -594,9 +542,9 @@ linux_getdents64(struct thread *td, struct linux_getdents64_args *args)
td->td_retval[0] = retval;
out:
- free(lbuf, M_TEMP);
+ free(linux_dirent64, M_LINUX);
out1:
- free(buf, M_TEMP);
+ free(buf, M_LINUX);
return (error);
}
@@ -607,13 +555,12 @@ linux_readdir(struct thread *td, struct linux_readdir_args *args)
struct dirent *bdp;
caddr_t buf; /* BSD-format */
int linuxreclen; /* Linux-format */
- caddr_t lbuf; /* Linux-format */
off_t base;
- struct l_dirent *linux_dirent;
+ struct l_dirent *linux_dirent; /* Linux-format */
int buflen, error;
- buflen = LINUX_RECLEN(LINUX_NAME_MAX);
- buf = malloc(buflen, M_TEMP, M_WAITOK);
+ buflen = sizeof(*bdp);
+ buf = malloc(buflen, M_LINUX, M_WAITOK);
error = kern_getdirentries(td, args->fd, buf, buflen,
&base, NULL, UIO_SYSSPACE);
@@ -624,14 +571,14 @@ linux_readdir(struct thread *td, struct linux_readdir_args *args)
if (td->td_retval[0] == 0)
goto out;
- lbuf = malloc(LINUX_RECLEN(LINUX_NAME_MAX), M_TEMP, M_WAITOK | M_ZERO);
+ linux_dirent = malloc(LINUX_RECLEN(LINUX_NAME_MAX), M_LINUX,
+ M_WAITOK | M_ZERO);
bdp = (struct dirent *) buf;
linuxreclen = LINUX_RECLEN(bdp->d_namlen);
- linux_dirent = (struct l_dirent*)lbuf;
linux_dirent->d_ino = bdp->d_fileno;
- linux_dirent->d_off = linuxreclen;
+ linux_dirent->d_off = bdp->d_off;
linux_dirent->d_reclen = bdp->d_namlen;
strlcpy(linux_dirent->d_name, bdp->d_name,
linuxreclen - offsetof(struct l_dirent, d_name));
@@ -639,9 +586,9 @@ linux_readdir(struct thread *td, struct linux_readdir_args *args)
if (error == 0)
td->td_retval[0] = linuxreclen;
- free(lbuf, M_TEMP);
+ free(linux_dirent, M_LINUX);
out:
- free(buf, M_TEMP);
+ free(buf, M_LINUX);
return (error);
}
#endif /* __i386__ || (__amd64__ && COMPAT_LINUX32) */
@@ -654,24 +601,13 @@ out:
int
linux_access(struct thread *td, struct linux_access_args *args)
{
- char *path;
- int error;
/* Linux convention. */
if (args->amode & ~(F_OK | X_OK | W_OK | R_OK))
return (EINVAL);
- if (!LUSECONVPATH(td)) {
- error = kern_accessat(td, AT_FDCWD, args->path, UIO_USERSPACE, 0,
- args->amode);
- } else {
- LCONVPATHEXIST(args->path, &path);
- error = kern_accessat(td, AT_FDCWD, path, UIO_SYSSPACE, 0,
- args->amode);
- LFREEPATH(path);
- }
-
- return (error);
+ return (kern_accessat(td, AT_FDCWD, args->path, UIO_USERSPACE, 0,
+ args->amode));
}
#endif
@@ -679,23 +615,14 @@ static int
linux_do_accessat(struct thread *td, int ldfd, const char *filename,
int amode, int flags)
{
- char *path;
- int error, dfd;
+ int dfd;
/* Linux convention. */
if (amode & ~(F_OK | X_OK | W_OK | R_OK))
return (EINVAL);
dfd = (ldfd == LINUX_AT_FDCWD) ? AT_FDCWD : ldfd;
- if (!LUSECONVPATH(td)) {
- error = kern_accessat(td, dfd, filename, UIO_USERSPACE, flags, amode);
- } else {
- LCONVPATHEXIST_AT(filename, &path, dfd);
- error = kern_accessat(td, dfd, path, UIO_SYSSPACE, flags, amode);
- LFREEPATH(path);
- }
-
- return (error);
+ return (kern_accessat(td, dfd, filename, UIO_USERSPACE, flags, amode));
}
int
@@ -711,8 +638,8 @@ linux_faccessat2(struct thread *td, struct linux_faccessat2_args *args)
{
int flags, unsupported;
- /* XXX. AT_SYMLINK_NOFOLLOW is not supported by kern_accessat */
- unsupported = args->flags & ~(LINUX_AT_EACCESS | LINUX_AT_EMPTY_PATH);
+ unsupported = args->flags & ~(LINUX_AT_EACCESS | LINUX_AT_EMPTY_PATH |
+ LINUX_AT_SYMLINK_NOFOLLOW);
if (unsupported != 0) {
linux_msg(td, "faccessat2 unsupported flag 0x%x", unsupported);
return (EINVAL);
@@ -722,6 +649,8 @@ linux_faccessat2(struct thread *td, struct linux_faccessat2_args *args)
AT_EACCESS;
flags |= (args->flags & LINUX_AT_EMPTY_PATH) == 0 ? 0 :
AT_EMPTY_PATH;
+ flags |= (args->flags & LINUX_AT_SYMLINK_NOFOLLOW) == 0 ? 0 :
+ AT_SYMLINK_NOFOLLOW;
return (linux_do_accessat(td, args->dfd, args->filename, args->amode,
flags));
}
@@ -731,33 +660,18 @@ linux_faccessat2(struct thread *td, struct linux_faccessat2_args *args)
int
linux_unlink(struct thread *td, struct linux_unlink_args *args)
{
- char *path;
int error;
struct stat st;
- if (!LUSECONVPATH(td)) {
- error = kern_funlinkat(td, AT_FDCWD, args->path, FD_NONE,
- UIO_USERSPACE, 0, 0);
- if (error == EPERM) {
- /* Introduce POSIX noncompliant behaviour of Linux */
- if (kern_statat(td, 0, AT_FDCWD, args->path,
- UIO_SYSSPACE, &st, NULL) == 0) {
- if (S_ISDIR(st.st_mode))
- error = EISDIR;
- }
- }
- } else {
- LCONVPATHEXIST(args->path, &path);
- error = kern_funlinkat(td, AT_FDCWD, path, FD_NONE, UIO_SYSSPACE, 0, 0);
- if (error == EPERM) {
- /* Introduce POSIX noncompliant behaviour of Linux */
- if (kern_statat(td, 0, AT_FDCWD, path, UIO_SYSSPACE, &st,
- NULL) == 0) {
- if (S_ISDIR(st.st_mode))
- error = EISDIR;
- }
+ error = kern_funlinkat(td, AT_FDCWD, args->path, FD_NONE,
+ UIO_USERSPACE, 0, 0);
+ if (error == EPERM) {
+ /* Introduce POSIX noncompliant behaviour of Linux */
+ if (kern_statat(td, 0, AT_FDCWD, args->path,
+ UIO_USERSPACE, &st) == 0) {
+ if (S_ISDIR(st.st_mode))
+ error = EISDIR;
}
- LFREEPATH(path);
}
return (error);
@@ -778,7 +692,7 @@ linux_unlinkat_impl(struct thread *td, enum uio_seg pathseg, const char *path,
if (error == EPERM && !(args->flag & LINUX_AT_REMOVEDIR)) {
/* Introduce POSIX noncompliant behaviour of Linux */
if (kern_statat(td, AT_SYMLINK_NOFOLLOW, dfd, path,
- UIO_SYSSPACE, &st, NULL) == 0 && S_ISDIR(st.st_mode))
+ pathseg, &st) == 0 && S_ISDIR(st.st_mode))
error = EISDIR;
}
return (error);
@@ -787,142 +701,75 @@ linux_unlinkat_impl(struct thread *td, enum uio_seg pathseg, const char *path,
int
linux_unlinkat(struct thread *td, struct linux_unlinkat_args *args)
{
- char *path;
- int error, dfd;
+ int dfd;
if (args->flag & ~LINUX_AT_REMOVEDIR)
return (EINVAL);
dfd = (args->dfd == LINUX_AT_FDCWD) ? AT_FDCWD : args->dfd;
- if (!LUSECONVPATH(td)) {
- return (linux_unlinkat_impl(td, UIO_USERSPACE, args->pathname,
- dfd, args));
- }
- LCONVPATHEXIST_AT(args->pathname, &path, dfd);
- error = linux_unlinkat_impl(td, UIO_SYSSPACE, path, dfd, args);
- LFREEPATH(path);
- return (error);
+ return (linux_unlinkat_impl(td, UIO_USERSPACE, args->pathname,
+ dfd, args));
}
+
int
linux_chdir(struct thread *td, struct linux_chdir_args *args)
{
- char *path;
- int error;
- if (!LUSECONVPATH(td)) {
- return (kern_chdir(td, args->path, UIO_USERSPACE));
- }
- LCONVPATHEXIST(args->path, &path);
- error = kern_chdir(td, path, UIO_SYSSPACE);
- LFREEPATH(path);
- return (error);
+ return (kern_chdir(td, args->path, UIO_USERSPACE));
}
#ifdef LINUX_LEGACY_SYSCALLS
int
linux_chmod(struct thread *td, struct linux_chmod_args *args)
{
- char *path;
- int error;
- if (!LUSECONVPATH(td)) {
- return (kern_fchmodat(td, AT_FDCWD, args->path, UIO_USERSPACE,
- args->mode, 0));
- }
- LCONVPATHEXIST(args->path, &path);
- error = kern_fchmodat(td, AT_FDCWD, path, UIO_SYSSPACE, args->mode, 0);
- LFREEPATH(path);
- return (error);
+ return (kern_fchmodat(td, AT_FDCWD, args->path, UIO_USERSPACE,
+ args->mode, 0));
}
#endif
int
linux_fchmodat(struct thread *td, struct linux_fchmodat_args *args)
{
- char *path;
- int error, dfd;
+ int dfd;
dfd = (args->dfd == LINUX_AT_FDCWD) ? AT_FDCWD : args->dfd;
- if (!LUSECONVPATH(td)) {
- return (kern_fchmodat(td, dfd, args->filename, UIO_USERSPACE,
- args->mode, 0));
- }
- LCONVPATHEXIST_AT(args->filename, &path, dfd);
- error = kern_fchmodat(td, dfd, path, UIO_SYSSPACE, args->mode, 0);
- LFREEPATH(path);
- return (error);
+ return (kern_fchmodat(td, dfd, args->filename, UIO_USERSPACE,
+ args->mode, 0));
}
#ifdef LINUX_LEGACY_SYSCALLS
int
linux_mkdir(struct thread *td, struct linux_mkdir_args *args)
{
- char *path;
- int error;
- if (!LUSECONVPATH(td)) {
- return (kern_mkdirat(td, AT_FDCWD, args->path, UIO_USERSPACE, args->mode));
- }
- LCONVPATHCREAT(args->path, &path);
- error = kern_mkdirat(td, AT_FDCWD, path, UIO_SYSSPACE, args->mode);
- LFREEPATH(path);
- return (error);
+ return (kern_mkdirat(td, AT_FDCWD, args->path, UIO_USERSPACE, args->mode));
}
#endif
int
linux_mkdirat(struct thread *td, struct linux_mkdirat_args *args)
{
- char *path;
- int error, dfd;
+ int dfd;
dfd = (args->dfd == LINUX_AT_FDCWD) ? AT_FDCWD : args->dfd;
- if (!LUSECONVPATH(td)) {
- return (kern_mkdirat(td, dfd, args->pathname, UIO_USERSPACE, args->mode));
- }
- LCONVPATHCREAT_AT(args->pathname, &path, dfd);
- error = kern_mkdirat(td, dfd, path, UIO_SYSSPACE, args->mode);
- LFREEPATH(path);
- return (error);
+ return (kern_mkdirat(td, dfd, args->pathname, UIO_USERSPACE, args->mode));
}
#ifdef LINUX_LEGACY_SYSCALLS
int
linux_rmdir(struct thread *td, struct linux_rmdir_args *args)
{
- char *path;
- int error;
- if (!LUSECONVPATH(td)) {
- return (kern_frmdirat(td, AT_FDCWD, args->path, FD_NONE,
- UIO_USERSPACE, 0));
- }
- LCONVPATHEXIST(args->path, &path);
- error = kern_frmdirat(td, AT_FDCWD, path, FD_NONE, UIO_SYSSPACE, 0);
- LFREEPATH(path);
- return (error);
+ return (kern_frmdirat(td, AT_FDCWD, args->path, FD_NONE,
+ UIO_USERSPACE, 0));
}
int
linux_rename(struct thread *td, struct linux_rename_args *args)
{
- char *from, *to;
- int error;
- if (!LUSECONVPATH(td)) {
- return (kern_renameat(td, AT_FDCWD, args->from, AT_FDCWD,
- args->to, UIO_USERSPACE));
- }
- LCONVPATHEXIST(args->from, &from);
- /* Expand LCONVPATHCREATE so that `from' can be freed on errors */
- error = linux_emul_convpath(args->to, UIO_USERSPACE, &to, 1, AT_FDCWD);
- if (to == NULL) {
- LFREEPATH(from);
- return (error);
- }
- error = kern_renameat(td, AT_FDCWD, from, AT_FDCWD, to, UIO_SYSSPACE);
- LFREEPATH(from);
- LFREEPATH(to);
- return (error);
+ return (kern_renameat(td, AT_FDCWD, args->from, AT_FDCWD,
+ args->to, UIO_USERSPACE));
}
#endif
@@ -943,8 +790,7 @@ linux_renameat(struct thread *td, struct linux_renameat_args *args)
int
linux_renameat2(struct thread *td, struct linux_renameat2_args *args)
{
- char *from, *to;
- int error, olddfd, newdfd;
+ int olddfd, newdfd;
if (args->flags != 0) {
if (args->flags & ~(LINUX_RENAME_EXCHANGE |
@@ -969,131 +815,68 @@ linux_renameat2(struct thread *td, struct linux_renameat2_args *args)
olddfd = (args->olddfd == LINUX_AT_FDCWD) ? AT_FDCWD : args->olddfd;
newdfd = (args->newdfd == LINUX_AT_FDCWD) ? AT_FDCWD : args->newdfd;
- if (!LUSECONVPATH(td)) {
- return (kern_renameat(td, olddfd, args->oldname, newdfd,
- args->newname, UIO_USERSPACE));
- }
- LCONVPATHEXIST_AT(args->oldname, &from, olddfd);
- /* Expand LCONVPATHCREATE so that `from' can be freed on errors */
- error = linux_emul_convpath(args->newname, UIO_USERSPACE, &to, 1, newdfd);
- if (to == NULL) {
- LFREEPATH(from);
- return (error);
- }
- error = kern_renameat(td, olddfd, from, newdfd, to, UIO_SYSSPACE);
- LFREEPATH(from);
- LFREEPATH(to);
- return (error);
+ return (kern_renameat(td, olddfd, args->oldname, newdfd,
+ args->newname, UIO_USERSPACE));
}
#ifdef LINUX_LEGACY_SYSCALLS
int
linux_symlink(struct thread *td, struct linux_symlink_args *args)
{
- char *path, *to;
- int error;
- if (!LUSECONVPATH(td)) {
- return (kern_symlinkat(td, args->path, AT_FDCWD, args->to,
- UIO_USERSPACE));
- }
- LCONVPATHEXIST(args->path, &path);
- /* Expand LCONVPATHCREATE so that `path' can be freed on errors */
- error = linux_emul_convpath(args->to, UIO_USERSPACE, &to, 1, AT_FDCWD);
- if (to == NULL) {
- LFREEPATH(path);
- return (error);
- }
- error = kern_symlinkat(td, path, AT_FDCWD, to, UIO_SYSSPACE);
- LFREEPATH(path);
- LFREEPATH(to);
- return (error);
+ return (kern_symlinkat(td, args->path, AT_FDCWD, args->to,
+ UIO_USERSPACE));
}
#endif
int
linux_symlinkat(struct thread *td, struct linux_symlinkat_args *args)
{
- char *path, *to;
- int error, dfd;
+ int dfd;
dfd = (args->newdfd == LINUX_AT_FDCWD) ? AT_FDCWD : args->newdfd;
- if (!LUSECONVPATH(td)) {
- return (kern_symlinkat(td, args->oldname, dfd, args->newname,
- UIO_USERSPACE));
- }
- LCONVPATHEXIST(args->oldname, &path);
- /* Expand LCONVPATHCREATE so that `path' can be freed on errors */
- error = linux_emul_convpath(args->newname, UIO_USERSPACE, &to, 1, dfd);
- if (to == NULL) {
- LFREEPATH(path);
- return (error);
- }
- error = kern_symlinkat(td, path, dfd, to, UIO_SYSSPACE);
- LFREEPATH(path);
- LFREEPATH(to);
- return (error);
+ return (kern_symlinkat(td, args->oldname, dfd, args->newname,
+ UIO_USERSPACE));
}
#ifdef LINUX_LEGACY_SYSCALLS
int
linux_readlink(struct thread *td, struct linux_readlink_args *args)
{
- char *name;
- int error;
- if (!LUSECONVPATH(td)) {
- return (kern_readlinkat(td, AT_FDCWD, args->name, UIO_USERSPACE,
- args->buf, UIO_USERSPACE, args->count));
- }
- LCONVPATHEXIST(args->name, &name);
- error = kern_readlinkat(td, AT_FDCWD, name, UIO_SYSSPACE,
- args->buf, UIO_USERSPACE, args->count);
- LFREEPATH(name);
- return (error);
+ if (args->count <= 0)
+ return (EINVAL);
+
+ return (kern_readlinkat(td, AT_FDCWD, args->name, UIO_USERSPACE,
+ args->buf, UIO_USERSPACE, args->count));
}
#endif
int
linux_readlinkat(struct thread *td, struct linux_readlinkat_args *args)
{
- char *name;
- int error, dfd;
+ int dfd;
+
+ if (args->bufsiz <= 0)
+ return (EINVAL);
dfd = (args->dfd == LINUX_AT_FDCWD) ? AT_FDCWD : args->dfd;
- if (!LUSECONVPATH(td)) {
- return (kern_readlinkat(td, dfd, args->path, UIO_USERSPACE,
- args->buf, UIO_USERSPACE, args->bufsiz));
- }
- LCONVPATHEXIST_AT(args->path, &name, dfd);
- error = kern_readlinkat(td, dfd, name, UIO_SYSSPACE, args->buf,
- UIO_USERSPACE, args->bufsiz);
- LFREEPATH(name);
- return (error);
+ return (kern_readlinkat(td, dfd, args->path, UIO_USERSPACE,
+ args->buf, UIO_USERSPACE, args->bufsiz));
}
int
linux_truncate(struct thread *td, struct linux_truncate_args *args)
{
- char *path;
- int error;
- if (!LUSECONVPATH(td)) {
- return (kern_truncate(td, args->path, UIO_USERSPACE, args->length));
- }
- LCONVPATHEXIST(args->path, &path);
- error = kern_truncate(td, path, UIO_SYSSPACE, args->length);
- LFREEPATH(path);
- return (error);
+ return (kern_truncate(td, args->path, UIO_USERSPACE, args->length));
}
#if defined(__i386__) || (defined(__amd64__) && defined(COMPAT_LINUX32))
int
linux_truncate64(struct thread *td, struct linux_truncate64_args *args)
{
- char *path;
off_t length;
- int error;
#if defined(__amd64__) && defined(COMPAT_LINUX32)
length = PAIR32TO64(off_t, args->length);
@@ -1101,13 +884,7 @@ linux_truncate64(struct thread *td, struct linux_truncate64_args *args)
length = args->length;
#endif
- if (!LUSECONVPATH(td)) {
- return (kern_truncate(td, args->path, UIO_USERSPACE, length));
- }
- LCONVPATHEXIST(args->path, &path);
- error = kern_truncate(td, path, UIO_SYSSPACE, length);
- LFREEPATH(path);
- return (error);
+ return (kern_truncate(td, args->path, UIO_USERSPACE, length));
}
#endif /* __i386__ || (__amd64__ && COMPAT_LINUX32) */
@@ -1138,33 +915,16 @@ linux_ftruncate64(struct thread *td, struct linux_ftruncate64_args *args)
int
linux_link(struct thread *td, struct linux_link_args *args)
{
- char *path, *to;
- int error;
- if (!LUSECONVPATH(td)) {
- return (kern_linkat(td, AT_FDCWD, AT_FDCWD, args->path, args->to,
- UIO_USERSPACE, AT_SYMLINK_FOLLOW));
- }
- LCONVPATHEXIST(args->path, &path);
- /* Expand LCONVPATHCREATE so that `path' can be freed on errors */
- error = linux_emul_convpath(args->to, UIO_USERSPACE, &to, 1, AT_FDCWD);
- if (to == NULL) {
- LFREEPATH(path);
- return (error);
- }
- error = kern_linkat(td, AT_FDCWD, AT_FDCWD, path, to, UIO_SYSSPACE,
- AT_SYMLINK_FOLLOW);
- LFREEPATH(path);
- LFREEPATH(to);
- return (error);
+ return (kern_linkat(td, AT_FDCWD, AT_FDCWD, args->path, args->to,
+ UIO_USERSPACE, AT_SYMLINK_FOLLOW));
}
#endif
int
linux_linkat(struct thread *td, struct linux_linkat_args *args)
{
- char *path, *to;
- int error, olddfd, newdfd, flag;
+ int olddfd, newdfd, flag;
if (args->flag & ~(LINUX_AT_SYMLINK_FOLLOW | LINUX_AT_EMPTY_PATH))
return (EINVAL);
@@ -1175,21 +935,8 @@ linux_linkat(struct thread *td, struct linux_linkat_args *args)
olddfd = (args->olddfd == LINUX_AT_FDCWD) ? AT_FDCWD : args->olddfd;
newdfd = (args->newdfd == LINUX_AT_FDCWD) ? AT_FDCWD : args->newdfd;
- if (!LUSECONVPATH(td)) {
- return (kern_linkat(td, olddfd, newdfd, args->oldname,
- args->newname, UIO_USERSPACE, flag));
- }
- LCONVPATHEXIST_AT(args->oldname, &path, olddfd);
- /* Expand LCONVPATHCREATE so that `path' can be freed on errors */
- error = linux_emul_convpath(args->newname, UIO_USERSPACE, &to, 1, newdfd);
- if (to == NULL) {
- LFREEPATH(path);
- return (error);
- }
- error = kern_linkat(td, olddfd, newdfd, path, to, UIO_SYSSPACE, flag);
- LFREEPATH(path);
- LFREEPATH(to);
- return (error);
+ return (kern_linkat(td, olddfd, newdfd, args->oldname,
+ args->newname, UIO_USERSPACE, flag));
}
int
@@ -1259,7 +1006,17 @@ linux_pwrite(struct thread *td, struct linux_pwrite_args *uap)
offset = uap->offset;
#endif
- return (kern_pwrite(td, uap->fd, uap->buf, uap->nbyte, offset));
+ return (linux_enobufs2eagain(td, uap->fd,
+ kern_pwrite(td, uap->fd, uap->buf, uap->nbyte, offset)));
+}
+
+#define HALF_LONG_BITS ((sizeof(l_long) * NBBY / 2))
+
+static inline off_t
+pos_from_hilo(unsigned long high, unsigned long low)
+{
+
+ return (((off_t)high << HALF_LONG_BITS) << HALF_LONG_BITS) | low;
}
int
@@ -1274,19 +1031,18 @@ linux_preadv(struct thread *td, struct linux_preadv_args *uap)
* pos_l and pos_h, respectively, contain the
* low order and high order 32 bits of offset.
*/
- offset = (((off_t)uap->pos_h << (sizeof(offset) * 4)) <<
- (sizeof(offset) * 4)) | uap->pos_l;
+ offset = pos_from_hilo(uap->pos_h, uap->pos_l);
if (offset < 0)
return (EINVAL);
#ifdef COMPAT_LINUX32
- error = linux32_copyinuio(PTRIN(uap->vec), uap->vlen, &auio);
+ error = freebsd32_copyinuio(PTRIN(uap->vec), uap->vlen, &auio);
#else
error = copyinuio(uap->vec, uap->vlen, &auio);
#endif
if (error != 0)
return (error);
error = kern_preadv(td, uap->fd, auio, offset);
- free(auio, M_IOV);
+ freeuio(auio);
return (error);
}
@@ -1302,20 +1058,19 @@ linux_pwritev(struct thread *td, struct linux_pwritev_args *uap)
* pos_l and pos_h, respectively, contain the
* low order and high order 32 bits of offset.
*/
- offset = (((off_t)uap->pos_h << (sizeof(offset) * 4)) <<
- (sizeof(offset) * 4)) | uap->pos_l;
+ offset = pos_from_hilo(uap->pos_h, uap->pos_l);
if (offset < 0)
return (EINVAL);
#ifdef COMPAT_LINUX32
- error = linux32_copyinuio(PTRIN(uap->vec), uap->vlen, &auio);
+ error = freebsd32_copyinuio(PTRIN(uap->vec), uap->vlen, &auio);
#else
error = copyinuio(uap->vec, uap->vlen, &auio);
#endif
if (error != 0)
return (error);
error = kern_pwritev(td, uap->fd, auio, offset);
- free(auio, M_IOV);
- return (error);
+ freeuio(auio);
+ return (linux_enobufs2eagain(td, uap->fd, error));
}
int
@@ -1768,26 +1523,16 @@ linux_fcntl64(struct thread *td, struct linux_fcntl64_args *args)
int
linux_chown(struct thread *td, struct linux_chown_args *args)
{
- char *path;
- int error;
- if (!LUSECONVPATH(td)) {
- return (kern_fchownat(td, AT_FDCWD, args->path, UIO_USERSPACE,
- args->uid, args->gid, 0));
- }
- LCONVPATHEXIST(args->path, &path);
- error = kern_fchownat(td, AT_FDCWD, path, UIO_SYSSPACE, args->uid,
- args->gid, 0);
- LFREEPATH(path);
- return (error);
+ return (kern_fchownat(td, AT_FDCWD, args->path, UIO_USERSPACE,
+ args->uid, args->gid, 0));
}
#endif
int
linux_fchownat(struct thread *td, struct linux_fchownat_args *args)
{
- char *path;
- int error, dfd, flag, unsupported;
+ int dfd, flag, unsupported;
unsupported = args->flag & ~(LINUX_AT_SYMLINK_NOFOLLOW | LINUX_AT_EMPTY_PATH);
if (unsupported != 0) {
@@ -1801,33 +1546,17 @@ linux_fchownat(struct thread *td, struct linux_fchownat_args *args)
AT_EMPTY_PATH;
dfd = (args->dfd == LINUX_AT_FDCWD) ? AT_FDCWD : args->dfd;
- if (!LUSECONVPATH(td)) {
- return (kern_fchownat(td, dfd, args->filename, UIO_USERSPACE,
- args->uid, args->gid, flag));
- }
- LCONVPATHEXIST_AT(args->filename, &path, dfd);
- error = kern_fchownat(td, dfd, path, UIO_SYSSPACE, args->uid, args->gid,
- flag);
- LFREEPATH(path);
- return (error);
+ return (kern_fchownat(td, dfd, args->filename, UIO_USERSPACE,
+ args->uid, args->gid, flag));
}
#ifdef LINUX_LEGACY_SYSCALLS
int
linux_lchown(struct thread *td, struct linux_lchown_args *args)
{
- char *path;
- int error;
- if (!LUSECONVPATH(td)) {
- return (kern_fchownat(td, AT_FDCWD, args->path, UIO_USERSPACE, args->uid,
- args->gid, AT_SYMLINK_NOFOLLOW));
- }
- LCONVPATHEXIST(args->path, &path);
- error = kern_fchownat(td, AT_FDCWD, path, UIO_SYSSPACE, args->uid, args->gid,
- AT_SYMLINK_NOFOLLOW);
- LFREEPATH(path);
- return (error);
+ return (kern_fchownat(td, AT_FDCWD, args->path, UIO_USERSPACE, args->uid,
+ args->gid, AT_SYMLINK_NOFOLLOW));
}
#endif
@@ -2063,7 +1792,7 @@ linux_memfd_create(struct thread *td, struct linux_memfd_create_args *args)
if ((flags & MFD_ALLOW_SEALING) != 0)
shmflags |= SHM_ALLOW_SEALING;
return (kern_shm_open2(td, SHM_ANON, oflags, 0, shmflags, NULL,
- memfd_name));
+ memfd_name, NULL));
}
int
@@ -2079,3 +1808,193 @@ linux_splice(struct thread *td, struct linux_splice_args *args)
*/
return (EINVAL);
}
+
+int
+linux_close_range(struct thread *td, struct linux_close_range_args *args)
+{
+ u_int flags = 0;
+
+ /*
+ * Implementing close_range(CLOSE_RANGE_UNSHARE) allows Linux to
+ * unshare filedesc table of the calling thread from others threads
+ * in a thread group (i.e., process in the FreeBSD) or others processes,
+ * which shares the same table, before closing the files. FreeBSD does
+ * not have compatible unsharing mechanism due to the fact that sharing
+ * process resources, including filedesc table, is at thread level in the
+ * Linux, while in the FreeBSD it is at the process level.
+ * Return EINVAL for now if the CLOSE_RANGE_UNSHARE flag is specified
+ * until this new Linux API stabilizes.
+ */
+
+ if ((args->flags & ~(LINUX_CLOSE_RANGE_CLOEXEC)) != 0)
+ return (EINVAL);
+ if (args->first > args->last)
+ return (EINVAL);
+ if ((args->flags & LINUX_CLOSE_RANGE_CLOEXEC) != 0)
+ flags |= CLOSE_RANGE_CLOEXEC;
+ return (kern_close_range(td, flags, args->first, args->last));
+}
+
+int
+linux_enobufs2eagain(struct thread *td, int fd, int error)
+{
+ struct file *fp;
+
+ if (error != ENOBUFS)
+ return (error);
+ if (fget(td, fd, &cap_no_rights, &fp) != 0)
+ return (error);
+ if (fp->f_type == DTYPE_SOCKET && (fp->f_flag & FNONBLOCK) != 0)
+ error = EAGAIN;
+ fdrop(fp, td);
+ return (error);
+}
+
+int
+linux_write(struct thread *td, struct linux_write_args *args)
+{
+ struct write_args bargs = {
+ .fd = args->fd,
+ .buf = args->buf,
+ .nbyte = args->nbyte,
+ };
+
+ return (linux_enobufs2eagain(td, args->fd, sys_write(td, &bargs)));
+}
+
+int
+linux_writev(struct thread *td, struct linux_writev_args *args)
+{
+ struct uio *auio;
+ int error;
+
+#ifdef COMPAT_LINUX32
+ error = freebsd32_copyinuio(PTRIN(args->iovp), args->iovcnt, &auio);
+#else
+ error = copyinuio(args->iovp, args->iovcnt, &auio);
+#endif
+ if (error != 0)
+ return (error);
+ error = kern_writev(td, args->fd, auio);
+ freeuio(auio);
+ return (linux_enobufs2eagain(td, args->fd, error));
+}
+
+static int
+linux_inotify_init_flags(int l_flags)
+{
+ int bsd_flags;
+
+ if ((l_flags & ~(LINUX_IN_CLOEXEC | LINUX_IN_NONBLOCK)) != 0)
+ linux_msg(NULL, "inotify_init1 unsupported flags 0x%x",
+ l_flags);
+
+ bsd_flags = 0;
+ if ((l_flags & LINUX_IN_CLOEXEC) != 0)
+ bsd_flags |= O_CLOEXEC;
+ if ((l_flags & LINUX_IN_NONBLOCK) != 0)
+ bsd_flags |= O_NONBLOCK;
+ return (bsd_flags);
+}
+
+static int
+inotify_init_common(struct thread *td, int flags)
+{
+ struct specialfd_inotify si;
+
+ si.flags = linux_inotify_init_flags(flags);
+ return (kern_specialfd(td, SPECIALFD_INOTIFY, &si));
+}
+
+#if defined(__i386__) || defined(__amd64__)
+int
+linux_inotify_init(struct thread *td, struct linux_inotify_init_args *args)
+{
+ return (inotify_init_common(td, 0));
+}
+#endif
+
+int
+linux_inotify_init1(struct thread *td, struct linux_inotify_init1_args *args)
+{
+ return (inotify_init_common(td, args->flags));
+}
+
+/*
+ * The native implementation uses the same values for inotify events as
+ * libinotify, which gives us binary compatibility with Linux. This simplifies
+ * the shim implementation a lot, as otherwise we would have to handle read(2)
+ * calls on inotify descriptors and translate events to Linux's ABI.
+ */
+_Static_assert(LINUX_IN_ACCESS == IN_ACCESS,
+ "IN_ACCESS mismatch");
+_Static_assert(LINUX_IN_MODIFY == IN_MODIFY,
+ "IN_MODIFY mismatch");
+_Static_assert(LINUX_IN_ATTRIB == IN_ATTRIB,
+ "IN_ATTRIB mismatch");
+_Static_assert(LINUX_IN_CLOSE_WRITE == IN_CLOSE_WRITE,
+ "IN_CLOSE_WRITE mismatch");
+_Static_assert(LINUX_IN_CLOSE_NOWRITE == IN_CLOSE_NOWRITE,
+ "IN_CLOSE_NOWRITE mismatch");
+_Static_assert(LINUX_IN_OPEN == IN_OPEN,
+ "IN_OPEN mismatch");
+_Static_assert(LINUX_IN_MOVED_FROM == IN_MOVED_FROM,
+ "IN_MOVED_FROM mismatch");
+_Static_assert(LINUX_IN_MOVED_TO == IN_MOVED_TO,
+ "IN_MOVED_TO mismatch");
+_Static_assert(LINUX_IN_CREATE == IN_CREATE,
+ "IN_CREATE mismatch");
+_Static_assert(LINUX_IN_DELETE == IN_DELETE,
+ "IN_DELETE mismatch");
+_Static_assert(LINUX_IN_DELETE_SELF == IN_DELETE_SELF,
+ "IN_DELETE_SELF mismatch");
+_Static_assert(LINUX_IN_MOVE_SELF == IN_MOVE_SELF,
+ "IN_MOVE_SELF mismatch");
+
+_Static_assert(LINUX_IN_UNMOUNT == IN_UNMOUNT,
+ "IN_UNMOUNT mismatch");
+_Static_assert(LINUX_IN_Q_OVERFLOW == IN_Q_OVERFLOW,
+ "IN_Q_OVERFLOW mismatch");
+_Static_assert(LINUX_IN_IGNORED == IN_IGNORED,
+ "IN_IGNORED mismatch");
+
+_Static_assert(LINUX_IN_ISDIR == IN_ISDIR,
+ "IN_ISDIR mismatch");
+_Static_assert(LINUX_IN_ONLYDIR == IN_ONLYDIR,
+ "IN_ONLYDIR mismatch");
+_Static_assert(LINUX_IN_DONT_FOLLOW == IN_DONT_FOLLOW,
+ "IN_DONT_FOLLOW mismatch");
+_Static_assert(LINUX_IN_MASK_CREATE == IN_MASK_CREATE,
+ "IN_MASK_CREATE mismatch");
+_Static_assert(LINUX_IN_MASK_ADD == IN_MASK_ADD,
+ "IN_MASK_ADD mismatch");
+_Static_assert(LINUX_IN_ONESHOT == IN_ONESHOT,
+ "IN_ONESHOT mismatch");
+_Static_assert(LINUX_IN_EXCL_UNLINK == IN_EXCL_UNLINK,
+ "IN_EXCL_UNLINK mismatch");
+
+static int
+linux_inotify_watch_flags(int l_flags)
+{
+ if ((l_flags & ~(LINUX_IN_ALL_EVENTS | LINUX_IN_ALL_FLAGS)) != 0) {
+ linux_msg(NULL, "inotify_add_watch unsupported flags 0x%x",
+ l_flags);
+ }
+
+ return (l_flags);
+}
+
+int
+linux_inotify_add_watch(struct thread *td,
+ struct linux_inotify_add_watch_args *args)
+{
+ return (kern_inotify_add_watch(args->fd, AT_FDCWD, args->pathname,
+ linux_inotify_watch_flags(args->mask), td));
+}
+
+int
+linux_inotify_rm_watch(struct thread *td,
+ struct linux_inotify_rm_watch_args *args)
+{
+ return (kern_inotify_rm_watch(args->fd, args->wd, td));
+}
diff --git a/sys/compat/linux/linux_file.h b/sys/compat/linux/linux_file.h
index e6a5bf0ce8a6..7448dc597230 100644
--- a/sys/compat/linux/linux_file.h
+++ b/sys/compat/linux/linux_file.h
@@ -1,5 +1,5 @@
/*-
- * SPDX-License-Identifier: BSD-2-Clause-FreeBSD
+ * SPDX-License-Identifier: BSD-2-Clause
*
* Copyright (c) 2007 Roman Divacky
* All rights reserved.
@@ -24,8 +24,6 @@
* 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.
- *
- * $FreeBSD$
*/
#ifndef _LINUX_FILE_H_
@@ -36,6 +34,13 @@
#define LINUX_AT_EACCESS 0x200
#define LINUX_AT_REMOVEDIR 0x200
#define LINUX_AT_SYMLINK_FOLLOW 0x400
+#define LINUX_AT_NO_AUTOMOUNT 0x800
+ /*
+ * Specific to Linux AT_NO_AUTOMOUNT flag tells the kernel to
+ * not automount the terminal component of pathname if it is a
+ * directory that is an automount point. As FreeBSD does not
+ * have such facility (automount), we can simply ignore this flag.
+ */
#define LINUX_AT_EMPTY_PATH 0x1000
/*
@@ -184,10 +189,54 @@
#define LINUX_HUGETLB_FLAG_ENCODE_2GB (31 << LINUX_HUGETLB_FLAG_ENCODE_SHIFT)
#define LINUX_HUGETLB_FLAG_ENCODE_16GB (34U << LINUX_HUGETLB_FLAG_ENCODE_SHIFT)
+/* inotify flags */
+#define LINUX_IN_ACCESS 0x00000001
+#define LINUX_IN_MODIFY 0x00000002
+#define LINUX_IN_ATTRIB 0x00000004
+#define LINUX_IN_CLOSE_WRITE 0x00000008
+#define LINUX_IN_CLOSE_NOWRITE 0x00000010
+#define LINUX_IN_OPEN 0x00000020
+#define LINUX_IN_MOVED_FROM 0x00000040
+#define LINUX_IN_MOVED_TO 0x00000080
+#define LINUX_IN_CREATE 0x00000100
+#define LINUX_IN_DELETE 0x00000200
+#define LINUX_IN_DELETE_SELF 0x00000400
+#define LINUX_IN_MOVE_SELF 0x00000800
+
+#define LINUX_IN_UNMOUNT 0x00002000
+#define LINUX_IN_Q_OVERFLOW 0x00004000
+#define LINUX_IN_IGNORED 0x00008000
+
+#define LINUX_IN_ONLYDIR 0x01000000
+#define LINUX_IN_DONT_FOLLOW 0x02000000
+#define LINUX_IN_EXCL_UNLINK 0x04000000
+#define LINUX_IN_MASK_CREATE 0x10000000
+#define LINUX_IN_MASK_ADD 0x20000000
+#define LINUX_IN_ISDIR 0x40000000
+#define LINUX_IN_ONESHOT 0x80000000
+
+#define LINUX_IN_ALL_EVENTS 0x00000fff
+#define LINUX_IN_ALL_FLAGS 0xf700e000
+
+#define LINUX_IN_NONBLOCK 0x00000800
+#define LINUX_IN_CLOEXEC 0x00080000
+
+#if defined(_KERNEL)
struct l_file_handle {
l_uint handle_bytes;
l_int handle_type;
unsigned char f_handle[0];
};
+int linux_enobufs2eagain(struct thread *, int, int);
+int linux_common_openflags(int);
+#endif
+
+/*
+ * Look at linux_close_range() for an explanation.
+ *
+ * #define LINUX_CLOSE_RANGE_UNSHARE (1U << 1)
+ */
+#define LINUX_CLOSE_RANGE_CLOEXEC (1U << 2)
+
#endif /* !_LINUX_FILE_H_ */
diff --git a/sys/compat/linux/linux_fork.c b/sys/compat/linux/linux_fork.c
index bcd5ffe3c589..1c9189162a09 100644
--- a/sys/compat/linux/linux_fork.c
+++ b/sys/compat/linux/linux_fork.c
@@ -1,5 +1,5 @@
/*-
- * SPDX-License-Identifier: BSD-2-Clause-FreeBSD
+ * SPDX-License-Identifier: BSD-2-Clause
*
* Copyright (c) 2004 Tim J. Robbins
* Copyright (c) 2002 Doug Rabson
@@ -28,14 +28,7 @@
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
-#include <sys/cdefs.h>
-__FBSDID("$FreeBSD$");
-
-#include "opt_compat.h"
-
#include <sys/param.h>
-#include <sys/systm.h>
-#include <sys/imgact.h>
#include <sys/ktr.h>
#include <sys/lock.h>
#include <sys/mutex.h>
@@ -47,7 +40,6 @@ __FBSDID("$FreeBSD$");
#include <sys/sx.h>
#include <sys/umtxvar.h>
#include <sys/unistd.h>
-#include <sys/wait.h>
#include <vm/vm.h>
#include <vm/pmap.h>
@@ -280,8 +272,6 @@ linux_clone_thread(struct thread *td, struct l_clone_args *args)
if (error)
goto fail;
- cpu_copy_thread(newtd, td);
-
bzero(&newtd->td_startzero,
__rangeof(struct thread, td_startzero, td_endzero));
bcopy(&td->td_startcopy, &newtd->td_startcopy,
@@ -290,6 +280,8 @@ linux_clone_thread(struct thread *td, struct l_clone_args *args)
newtd->td_proc = p;
thread_cow_get(newtd, td);
+ cpu_copy_thread(newtd, td);
+
/* create the emuldata */
linux_proc_init(td, newtd, true);
@@ -309,8 +301,6 @@ linux_clone_thread(struct thread *td, struct l_clone_args *args)
else
em->child_clear_tid = NULL;
- cpu_thread_clean(newtd);
-
linux_set_upcall(newtd, args->stack);
PROC_LOCK(p);
@@ -323,7 +313,7 @@ linux_clone_thread(struct thread *td, struct l_clone_args *args)
sched_fork_thread(td, newtd);
thread_unlock(td);
if (P_SHOULDSTOP(p))
- newtd->td_flags |= TDF_ASTPENDING | TDF_NEEDSUSPCHK;
+ ast_sched(newtd, TDA_SUSPEND);
if (p->p_ptevents & PTRACE_LWP)
newtd->td_dbgflags |= TDB_BORN;
diff --git a/sys/compat/linux/linux_fork.h b/sys/compat/linux/linux_fork.h
index bdc201bce57e..6e2d204a81ea 100644
--- a/sys/compat/linux/linux_fork.h
+++ b/sys/compat/linux/linux_fork.h
@@ -1,4 +1,6 @@
/*-
+ * SPDX-License-Identifier: BSD-2-Clause
+ *
* Copyright (c) 2021 Dmitry Chagin <dchagin@FreeBSD.org>
*
* Redistribution and use in source and binary forms, with or without
@@ -21,8 +23,6 @@
* 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.
- *
- * $FreeBSD$
*/
#ifndef _LINUX_FORK_H_
@@ -62,6 +62,7 @@
#define LINUX_CSIGNAL 0x000000ff
+#if defined(_KERNEL)
/*
* User-space clone3 args layout.
*/
@@ -97,5 +98,6 @@ struct l_clone_args {
int linux_set_upcall(struct thread *, register_t);
int linux_set_cloned_tls(struct thread *, void *);
void linux_thread_detach(struct thread *);
+#endif /* defined(_KERNEL) */
#endif /* _LINUX_FORK_H_ */
diff --git a/sys/compat/linux/linux_futex.c b/sys/compat/linux/linux_futex.c
index a194e0ac7962..0586eb55a8f3 100644
--- a/sys/compat/linux/linux_futex.c
+++ b/sys/compat/linux/linux_futex.c
@@ -1,5 +1,5 @@
/*-
- * SPDX-License-Identifier: BSD-2-Clause-FreeBSD
+ * SPDX-License-Identifier: BSD-2-Clause
*
* Copyright (c) 2009-2021 Dmitry Chagin <dchagin@FreeBSD.org>
* Copyright (c) 2008 Roman Divacky
@@ -26,20 +26,17 @@
* SUCH DAMAGE.
*/
-#include <sys/cdefs.h>
-__FBSDID("$FreeBSD$");
-
-#include "opt_compat.h"
-
#include <sys/param.h>
-#include <sys/systm.h>
#include <sys/imgact.h>
#include <sys/imgact_elf.h>
#include <sys/ktr.h>
+#include <sys/lock.h>
#include <sys/mutex.h>
#include <sys/priv.h>
#include <sys/proc.h>
#include <sys/sched.h>
+#include <sys/sysent.h>
+#include <sys/vnode.h>
#include <sys/umtxvar.h>
#ifdef COMPAT_LINUX32
@@ -52,14 +49,15 @@ __FBSDID("$FreeBSD$");
#include <compat/linux/linux_emul.h>
#include <compat/linux/linux_futex.h>
#include <compat/linux/linux_misc.h>
-#include <compat/linux/linux_timer.h>
+#include <compat/linux/linux_time.h>
#include <compat/linux/linux_util.h>
#define FUTEX_SHARED 0x8 /* shared futex */
+#define FUTEX_UNOWNED 0
#define GET_SHARED(a) (a->flags & FUTEX_SHARED) ? AUTO_SHARE : THREAD_SHARE
-static int futex_atomic_op(struct thread *, int, uint32_t *);
+static int futex_atomic_op(struct thread *, int, uint32_t *, int *);
static int handle_futex_death(struct thread *td, struct linux_emuldata *,
uint32_t *, unsigned int, bool);
static int fetch_robust_entry(struct linux_robust_list **,
@@ -81,7 +79,7 @@ struct linux_futex_args {
static inline int futex_key_get(const void *, int, int, struct umtx_key *);
static void linux_umtx_abs_timeout_init(struct umtx_abs_timeout *,
struct linux_futex_args *);
-static int linux_futex(struct thread *, struct linux_futex_args *);
+static int linux_futex(struct thread *, struct linux_futex_args *);
static int linux_futex_wait(struct thread *, struct linux_futex_args *);
static int linux_futex_wake(struct thread *, struct linux_futex_args *);
static int linux_futex_requeue(struct thread *, struct linux_futex_args *);
@@ -130,7 +128,8 @@ futex_wake_pi(struct thread *td, uint32_t *uaddr, bool shared)
}
static int
-futex_atomic_op(struct thread *td, int encoded_op, uint32_t *uaddr)
+futex_atomic_op(struct thread *td, int encoded_op, uint32_t *uaddr,
+ int *res)
{
int op = (encoded_op >> 28) & 7;
int cmp = (encoded_op >> 24) & 15;
@@ -158,34 +157,34 @@ futex_atomic_op(struct thread *td, int encoded_op, uint32_t *uaddr)
ret = futex_xorl(oparg, uaddr, &oldval);
break;
default:
- ret = -ENOSYS;
+ ret = ENOSYS;
break;
}
- if (ret)
+ if (ret != 0)
return (ret);
switch (cmp) {
case FUTEX_OP_CMP_EQ:
- ret = (oldval == cmparg);
+ *res = (oldval == cmparg);
break;
case FUTEX_OP_CMP_NE:
- ret = (oldval != cmparg);
+ *res = (oldval != cmparg);
break;
case FUTEX_OP_CMP_LT:
- ret = (oldval < cmparg);
+ *res = (oldval < cmparg);
break;
case FUTEX_OP_CMP_GE:
- ret = (oldval >= cmparg);
+ *res = (oldval >= cmparg);
break;
case FUTEX_OP_CMP_LE:
- ret = (oldval <= cmparg);
+ *res = (oldval <= cmparg);
break;
case FUTEX_OP_CMP_GT:
- ret = (oldval > cmparg);
+ *res = (oldval > cmparg);
break;
default:
- ret = -ENOSYS;
+ ret = ENOSYS;
}
return (ret);
@@ -252,7 +251,7 @@ linux_futex(struct thread *td, struct linux_futex_args *args)
* set LINUX_BI_FUTEX_REQUEUE bit of Brandinfo flags.
*/
p = td->td_proc;
- Elf_Brandinfo *bi = p->p_elf_brandinfo;
+ const Elf_Brandinfo *bi = p->p_elf_brandinfo;
if (bi == NULL || ((bi->flags & LINUX_BI_FUTEX_REQUEUE)) == 0)
return (EINVAL);
args->val3_compare = false;
@@ -398,7 +397,7 @@ linux_futex_lock_pi(struct thread *td, bool try, struct linux_futex_args *args)
umtxq_unlock(&uq->uq_key);
for (;;) {
/* Try uncontested case first. */
- rv = casueword32(args->uaddr, 0, &owner, em->em_tid);
+ rv = casueword32(args->uaddr, FUTEX_UNOWNED, &owner, em->em_tid);
/* The acquire succeeded. */
if (rv == 0) {
error = 0;
@@ -410,6 +409,17 @@ linux_futex_lock_pi(struct thread *td, bool try, struct linux_futex_args *args)
}
/*
+ * Nobody owns it, but the acquire failed. This can happen
+ * with ll/sc atomic.
+ */
+ if (owner == FUTEX_UNOWNED) {
+ error = thread_check_susp(td, true);
+ if (error != 0)
+ break;
+ continue;
+ }
+
+ /*
* Avoid overwriting a possible error from sleep due
* to the pending signal with suspension check result.
*/
@@ -429,7 +439,7 @@ linux_futex_lock_pi(struct thread *td, bool try, struct linux_futex_args *args)
* Futex owner died, handle_futex_death() set the OWNER_DIED bit
* and clear tid. Try to acquire it.
*/
- if ((owner & FUTEX_TID_MASK) == 0) {
+ if ((owner & FUTEX_TID_MASK) == FUTEX_UNOWNED) {
old_owner = owner;
owner = owner & (FUTEX_WAITERS | FUTEX_OWNER_DIED);
owner |= em->em_tid;
@@ -474,7 +484,7 @@ linux_futex_lock_pi(struct thread *td, bool try, struct linux_futex_args *args)
* Linux does some checks of futex state, we return EINVAL,
* as the user space can take care of this.
*/
- if ((owner & FUTEX_OWNER_DIED) != 0) {
+ if ((owner & FUTEX_OWNER_DIED) != FUTEX_UNOWNED) {
error = EINVAL;
break;
}
@@ -491,9 +501,7 @@ linux_futex_lock_pi(struct thread *td, bool try, struct linux_futex_args *args)
if (error != 0)
break;
- umtxq_lock(&uq->uq_key);
- umtxq_busy(&uq->uq_key);
- umtxq_unlock(&uq->uq_key);
+ umtxq_busy_unlocked(&uq->uq_key);
/*
* Set the contested bit so that a release in user space knows
@@ -596,7 +604,7 @@ linux_futex_unlock_pi(struct thread *td, bool rb, struct linux_futex_args *args)
if (count > 1)
new_owner = FUTEX_WAITERS;
else
- new_owner = 0;
+ new_owner = FUTEX_UNOWNED;
again:
error = casueword32(args->uaddr, owner, &old, new_owner);
@@ -632,16 +640,8 @@ linux_futex_wakeop(struct thread *td, struct linux_futex_args *args)
umtx_key_release(&key);
return (error);
}
- umtxq_lock(&key);
- umtxq_busy(&key);
- umtxq_unlock(&key);
- op_ret = futex_atomic_op(td, args->val3, args->uaddr2);
- if (op_ret < 0) {
- if (op_ret == -ENOSYS)
- error = ENOSYS;
- else
- error = EFAULT;
- }
+ umtxq_busy_unlocked(&key);
+ error = futex_atomic_op(td, args->val3, args->uaddr2, &op_ret);
umtxq_lock(&key);
umtxq_unbusy(&key);
if (error != 0)
@@ -697,9 +697,7 @@ linux_futex_requeue(struct thread *td, struct linux_futex_args *args)
umtx_key_release(&key);
return (error);
}
- umtxq_lock(&key);
- umtxq_busy(&key);
- umtxq_unlock(&key);
+ umtxq_busy_unlocked(&key);
error = fueword32(args->uaddr, &uval);
if (error != 0)
error = EFAULT;
@@ -816,7 +814,6 @@ linux_sys_futex(struct thread *td, struct linux_sys_futex_args *args)
.val3 = args->val3,
.val3_compare = true,
};
- struct l_timespec lts;
int error;
switch (args->op & LINUX_FUTEX_CMD_MASK) {
@@ -825,10 +822,7 @@ linux_sys_futex(struct thread *td, struct linux_sys_futex_args *args)
case LINUX_FUTEX_LOCK_PI:
case LINUX_FUTEX_LOCK_PI2:
if (args->timeout != NULL) {
- error = copyin(args->timeout, &lts, sizeof(lts));
- if (error != 0)
- return (error);
- error = linux_to_native_timespec(&fargs.kts, &lts);
+ error = linux_get_timespec(&fargs.kts, args->timeout);
if (error != 0)
return (error);
fargs.ts = &fargs.kts;
@@ -854,7 +848,6 @@ linux_sys_futex_time64(struct thread *td,
.val3 = args->val3,
.val3_compare = true,
};
- struct l_timespec64 lts;
int error;
switch (args->op & LINUX_FUTEX_CMD_MASK) {
@@ -863,10 +856,7 @@ linux_sys_futex_time64(struct thread *td,
case LINUX_FUTEX_LOCK_PI:
case LINUX_FUTEX_LOCK_PI2:
if (args->timeout != NULL) {
- error = copyin(args->timeout, &lts, sizeof(lts));
- if (error != 0)
- return (error);
- error = linux_to_native_timespec64(&fargs.kts, &lts);
+ error = linux_get_timespec64(&fargs.kts, args->timeout);
if (error != 0)
return (error);
fargs.ts = &fargs.kts;
@@ -934,7 +924,7 @@ linux_get_robust_list(struct thread *td, struct linux_get_robust_list_args *args
if (error != 0)
return (EFAULT);
- return (copyout(&head, args->head, sizeof(head)));
+ return (copyout(&head, args->head, sizeof(l_uintptr_t)));
}
static int
diff --git a/sys/compat/linux/linux_futex.h b/sys/compat/linux/linux_futex.h
index 189db4e17c4f..b6b6b0c98573 100644
--- a/sys/compat/linux/linux_futex.h
+++ b/sys/compat/linux/linux_futex.h
@@ -31,8 +31,6 @@
* 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.
- *
- * $FreeBSD$
*/
#ifndef _LINUX_FUTEX_H
@@ -79,6 +77,17 @@
#define FUTEX_TID_MASK 0x3fffffff
#define FUTEX_BITSET_MATCH_ANY 0xffffffff
+/* robust futexes */
+struct linux_robust_list {
+ l_uintptr_t next;
+};
+
+struct linux_robust_list_head {
+ struct linux_robust_list list;
+ l_long futex_offset;
+ l_uintptr_t pending_list;
+};
+
int futex_xchgl(int oparg, uint32_t *uaddr, int *oldval);
int futex_addl(int oparg, uint32_t *uaddr, int *oldval);
int futex_orl(int oparg, uint32_t *uaddr, int *oldval);
diff --git a/sys/compat/linux/linux_getcwd.c b/sys/compat/linux/linux_getcwd.c
index 4917641be5e5..e11b47aff178 100644
--- a/sys/compat/linux/linux_getcwd.c
+++ b/sys/compat/linux/linux_getcwd.c
@@ -1,7 +1,7 @@
/* $OpenBSD: linux_getcwd.c,v 1.2 2001/05/16 12:50:21 ho Exp $ */
/* $NetBSD: vfs_getcwd.c,v 1.3.2.3 1999/07/11 10:24:09 sommerfeld Exp $ */
/*-
- * SPDX-License-Identifier: BSD-2-Clause-NetBSD
+ * SPDX-License-Identifier: BSD-2-Clause
*
* Copyright (c) 1999 The NetBSD Foundation, Inc.
* Copyright (c) 2015 The FreeBSD Foundation
@@ -35,16 +35,10 @@
* POSSIBILITY OF SUCH DAMAGE.
*/
-#include <sys/cdefs.h>
-__FBSDID("$FreeBSD$");
-
-#include "opt_compat.h"
-
#include <sys/param.h>
-#include <sys/systm.h>
-#include <sys/vnode.h>
-#include <sys/proc.h>
#include <sys/malloc.h>
+#include <sys/proc.h>
+#include <sys/vnode.h>
#ifdef COMPAT_LINUX32
#include <machine/../linux32/linux.h>
@@ -54,7 +48,6 @@ __FBSDID("$FreeBSD$");
#include <machine/../linux/linux_proto.h>
#endif
#include <compat/linux/linux_misc.h>
-#include <compat/linux/linux_util.h>
/*
* Find pathname of process's current directory.
diff --git a/sys/compat/linux/linux_ioctl.c b/sys/compat/linux/linux_ioctl.c
index e3ce41ed38f8..ceb17bd040b5 100644
--- a/sys/compat/linux/linux_ioctl.c
+++ b/sys/compat/linux/linux_ioctl.c
@@ -1,5 +1,5 @@
/*-
- * SPDX-License-Identifier: BSD-2-Clause-FreeBSD
+ * SPDX-License-Identifier: BSD-2-Clause
*
* Copyright (c) 1994-1995 Søren Schmidt
* All rights reserved.
@@ -26,27 +26,13 @@
* SUCH DAMAGE.
*/
-#include "opt_compat.h"
-
-#include <sys/cdefs.h>
-__FBSDID("$FreeBSD$");
-
#include <sys/param.h>
-#include <sys/systm.h>
-#include <sys/sysproto.h>
-#ifdef COMPAT_LINUX32
-#include <sys/abi_compat.h>
-#endif
#include <sys/capsicum.h>
#include <sys/cdio.h>
-#include <sys/dvdio.h>
-#include <sys/conf.h>
-#include <sys/disk.h>
#include <sys/consio.h>
-#include <sys/ctype.h>
+#include <sys/disk.h>
+#include <sys/dvdio.h>
#include <sys/fcntl.h>
-#include <sys/file.h>
-#include <sys/filedesc.h>
#include <sys/filio.h>
#include <sys/jail.h>
#include <sys/kbio.h>
@@ -55,19 +41,16 @@ __FBSDID("$FreeBSD$");
#include <sys/linker_set.h>
#include <sys/lock.h>
#include <sys/malloc.h>
+#include <sys/mman.h>
#include <sys/proc.h>
#include <sys/sbuf.h>
-#include <sys/socket.h>
#include <sys/sockio.h>
#include <sys/soundcard.h>
-#include <sys/stdint.h>
-#include <sys/sx.h>
+#include <sys/syscallsubr.h>
#include <sys/sysctl.h>
+#include <sys/sysproto.h>
+#include <sys/sx.h>
#include <sys/tty.h>
-#include <sys/uio.h>
-#include <sys/types.h>
-#include <sys/mman.h>
-#include <sys/resourcevar.h>
#include <net/if.h>
#include <net/if_var.h>
@@ -89,7 +72,7 @@ __FBSDID("$FreeBSD$");
#include <compat/linux/linux_ioctl.h>
#include <compat/linux/linux_mib.h>
#include <compat/linux/linux_socket.h>
-#include <compat/linux/linux_timer.h>
+#include <compat/linux/linux_time.h>
#include <compat/linux/linux_util.h>
#include <contrib/v4l/videodev.h>
@@ -100,7 +83,7 @@ __FBSDID("$FreeBSD$");
#include <cam/scsi/scsi_sg.h>
-CTASSERT(LINUX_IFNAMSIZ == IFNAMSIZ);
+#include <dev/nvme/nvme_linux.h>
#define DEFINE_LINUX_IOCTL_SET(shortname, SHORTNAME) \
static linux_ioctl_function_t linux_ioctl_ ## shortname; \
@@ -127,6 +110,9 @@ DEFINE_LINUX_IOCTL_SET(v4l2, VIDEO2);
DEFINE_LINUX_IOCTL_SET(fbsd_usb, FBSD_LUSB);
DEFINE_LINUX_IOCTL_SET(evdev, EVDEV);
DEFINE_LINUX_IOCTL_SET(kcov, KCOV);
+#ifndef COMPAT_LINUX32
+DEFINE_LINUX_IOCTL_SET(nvme, NVME);
+#endif
#undef DEFINE_LINUX_IOCTL_SET
@@ -159,17 +145,17 @@ static TAILQ_HEAD(, linux_ioctl_handler_element) linux32_ioctl_handlers =
*/
struct linux_hd_geometry {
- u_int8_t heads;
- u_int8_t sectors;
- u_int16_t cylinders;
- u_int32_t start;
+ uint8_t heads;
+ uint8_t sectors;
+ uint16_t cylinders;
+ uint32_t start;
};
struct linux_hd_big_geometry {
- u_int8_t heads;
- u_int8_t sectors;
- u_int32_t cylinders;
- u_int32_t start;
+ uint8_t heads;
+ uint8_t sectors;
+ uint32_t cylinders;
+ uint32_t start;
};
static int
@@ -285,7 +271,7 @@ linux_ioctl_disk(struct thread *td, struct linux_ioctl_args *args)
fdrop(fp, td);
if (error)
return (error);
- blksize64 = mediasize;;
+ blksize64 = mediasize;
return (copyout(&blksize64, (void *)args->arg,
sizeof(blksize64)));
case LINUX_BLKSSZGET:
@@ -435,6 +421,8 @@ bsd_to_linux_termios(struct termios *bios, struct linux_termios *lios)
lios->c_iflag |= LINUX_IXOFF;
if (bios->c_iflag & IMAXBEL)
lios->c_iflag |= LINUX_IMAXBEL;
+ if (bios->c_iflag & IUTF8)
+ lios->c_iflag |= LINUX_IUTF8;
lios->c_oflag = 0;
if (bios->c_oflag & OPOST)
@@ -552,6 +540,8 @@ linux_to_bsd_termios(struct linux_termios *lios, struct termios *bios)
bios->c_iflag |= IXOFF;
if (lios->c_iflag & LINUX_IMAXBEL)
bios->c_iflag |= IMAXBEL;
+ if (lios->c_iflag & LINUX_IUTF8)
+ bios->c_iflag |= IUTF8;
bios->c_oflag = 0;
if (lios->c_oflag & LINUX_OPOST)
@@ -1020,9 +1010,17 @@ linux_ioctl_termio(struct thread *td, struct linux_ioctl_args *args)
sizeof(int));
break;
}
+ case LINUX_TIOCGPTPEER:
+ linux_msg(td, "unsupported ioctl TIOCGPTPEER");
+ error = ENOIOCTL;
+ break;
case LINUX_TIOCSPTLCK:
- /* Our unlockpt() does nothing. */
- error = 0;
+ /*
+ * Our unlockpt() does nothing. Check that fd refers
+ * to a pseudo-terminal master device.
+ */
+ args->cmd = TIOCPTMASTER;
+ error = (sys_ioctl(td, (struct ioctl_args *)args));
break;
default:
error = ENOIOCTL;
@@ -1103,9 +1101,9 @@ struct l_dvd_layer {
u_char track_density:4;
u_char linear_density:4;
u_char bca:1;
- u_int32_t start_sector;
- u_int32_t end_sector;
- u_int32_t end_sector_l0;
+ uint32_t start_sector;
+ uint32_t end_sector;
+ uint32_t end_sector_l0;
};
struct l_dvd_physical {
@@ -1460,7 +1458,7 @@ linux_ioctl_cdrom(struct thread *td, struct linux_ioctl_args *args)
if (!error) {
lth.cdth_trk0 = th.starting_track;
lth.cdth_trk1 = th.ending_track;
- copyout(&lth, (void *)args->arg, sizeof(lth));
+ error = copyout(&lth, (void *)args->arg, sizeof(lth));
}
break;
}
@@ -1622,7 +1620,8 @@ linux_ioctl_cdrom(struct thread *td, struct linux_ioctl_args *args)
if (error) {
if (lda.type == LINUX_DVD_HOST_SEND_KEY2) {
lda.type = LINUX_DVD_AUTH_FAILURE;
- copyout(&lda, (void *)args->arg, sizeof(lda));
+ (void)copyout(&lda, (void *)args->arg,
+ sizeof(lda));
}
break;
}
@@ -1690,7 +1689,7 @@ struct linux_old_mixer_info {
char name[32];
};
-static u_int32_t dirbits[4] = { IOC_VOID, IOC_IN, IOC_OUT, IOC_INOUT };
+static uint32_t dirbits[4] = { IOC_VOID, IOC_IN, IOC_OUT, IOC_INOUT };
#define SETDIR(c) (((c) & ~IOC_DIRMASK) | dirbits[args->cmd >> 30])
@@ -1782,9 +1781,10 @@ linux_ioctl_sound(struct thread *td, struct linux_ioctl_args *args)
struct linux_old_mixer_info info;
bzero(&info, sizeof(info));
strncpy(info.id, "OSS", sizeof(info.id) - 1);
- strncpy(info.name, "FreeBSD OSS Mixer", sizeof(info.name) - 1);
- copyout(&info, (void *)args->arg, sizeof(info));
- return (0);
+ strncpy(info.name, "FreeBSD OSS Mixer",
+ sizeof(info.name) - 1);
+ return (copyout(&info, (void *)args->arg,
+ sizeof(info)));
}
default:
return (ENOIOCTL);
@@ -2103,195 +2103,273 @@ static int
linux_ioctl_ifname(struct thread *td, struct l_ifreq *uifr)
{
struct l_ifreq ifr;
- struct ifnet *ifp;
- int error, ethno, index;
+ int error, ret;
error = copyin(uifr, &ifr, sizeof(ifr));
if (error != 0)
return (error);
-
- CURVNET_SET(TD_TO_VNET(curthread));
- IFNET_RLOCK();
- index = 1; /* ifr.ifr_ifindex starts from 1 */
- ethno = 0;
- error = ENODEV;
- CK_STAILQ_FOREACH(ifp, &V_ifnet, if_link) {
- if (ifr.ifr_ifindex == index) {
- if (IFP_IS_ETH(ifp))
- snprintf(ifr.ifr_name, LINUX_IFNAMSIZ,
- "eth%d", ethno);
- else
- strlcpy(ifr.ifr_name, ifp->if_xname,
- LINUX_IFNAMSIZ);
- error = 0;
- break;
- }
- if (IFP_IS_ETH(ifp))
- ethno++;
- index++;
- }
- IFNET_RUNLOCK();
- if (error == 0)
- error = copyout(&ifr, uifr, sizeof(ifr));
- CURVNET_RESTORE();
-
- return (error);
+ ret = ifname_bsd_to_linux_idx(ifr.ifr_index, ifr.ifr_name,
+ LINUX_IFNAMSIZ);
+ if (ret > 0)
+ return (copyout(&ifr, uifr, sizeof(ifr)));
+ else
+ return (ENODEV);
}
/*
* Implement the SIOCGIFCONF ioctl
*/
+static u_int
+linux_ifconf_ifaddr_cb(void *arg, struct ifaddr *ifa, u_int count)
+{
+#ifdef COMPAT_LINUX32
+ struct l_ifconf *ifc;
+#else
+ struct ifconf *ifc;
+#endif
+
+ ifc = arg;
+ ifc->ifc_len += sizeof(struct l_ifreq);
+ return (1);
+}
+
+static int
+linux_ifconf_ifnet_cb(if_t ifp, void *arg)
+{
+
+ if_foreach_addr_type(ifp, AF_INET, linux_ifconf_ifaddr_cb, arg);
+ return (0);
+}
+
+struct linux_ifconfig_ifaddr_cb2_s {
+ struct l_ifreq ifr;
+ struct sbuf *sb;
+ size_t max_len;
+ size_t valid_len;
+};
+
+static u_int
+linux_ifconf_ifaddr_cb2(void *arg, struct ifaddr *ifa, u_int len)
+{
+ struct linux_ifconfig_ifaddr_cb2_s *cbs = arg;
+ struct sockaddr *sa = ifa->ifa_addr;
+
+ cbs->ifr.ifr_addr.sa_family = LINUX_AF_INET;
+ memcpy(cbs->ifr.ifr_addr.sa_data, sa->sa_data,
+ sizeof(cbs->ifr.ifr_addr.sa_data));
+ sbuf_bcat(cbs->sb, &cbs->ifr, sizeof(cbs->ifr));
+ cbs->max_len += sizeof(cbs->ifr);
+
+ if (sbuf_error(cbs->sb) == 0)
+ cbs->valid_len = sbuf_len(cbs->sb);
+ return (1);
+}
+
+static int
+linux_ifconf_ifnet_cb2(if_t ifp, void *arg)
+{
+ struct linux_ifconfig_ifaddr_cb2_s *cbs = arg;
+
+ bzero(&cbs->ifr, sizeof(cbs->ifr));
+ ifname_bsd_to_linux_ifp(ifp, cbs->ifr.ifr_name,
+ sizeof(cbs->ifr.ifr_name));
+
+ /* Walk the address list */
+ if_foreach_addr_type(ifp, AF_INET, linux_ifconf_ifaddr_cb2, cbs);
+ return (0);
+}
static int
linux_ifconf(struct thread *td, struct ifconf *uifc)
{
+ struct linux_ifconfig_ifaddr_cb2_s cbs;
+ struct epoch_tracker et;
#ifdef COMPAT_LINUX32
struct l_ifconf ifc;
#else
struct ifconf ifc;
#endif
- struct l_ifreq ifr;
- struct ifnet *ifp;
- struct ifaddr *ifa;
struct sbuf *sb;
- int error, ethno, full = 0, valid_len, max_len;
+ int error, full;
error = copyin(uifc, &ifc, sizeof(ifc));
if (error != 0)
return (error);
- max_len = maxphys - 1;
-
- CURVNET_SET(TD_TO_VNET(td));
/* handle the 'request buffer size' case */
- if ((l_uintptr_t)ifc.ifc_buf == PTROUT(NULL)) {
+ if (PTRIN(ifc.ifc_buf) == NULL) {
ifc.ifc_len = 0;
- IFNET_RLOCK();
- CK_STAILQ_FOREACH(ifp, &V_ifnet, if_link) {
- CK_STAILQ_FOREACH(ifa, &ifp->if_addrhead, ifa_link) {
- struct sockaddr *sa = ifa->ifa_addr;
- if (sa->sa_family == AF_INET)
- ifc.ifc_len += sizeof(ifr);
- }
- }
- IFNET_RUNLOCK();
- error = copyout(&ifc, uifc, sizeof(ifc));
- CURVNET_RESTORE();
- return (error);
+ NET_EPOCH_ENTER(et);
+ if_foreach(linux_ifconf_ifnet_cb, &ifc);
+ NET_EPOCH_EXIT(et);
+ return (copyout(&ifc, uifc, sizeof(ifc)));
}
-
- if (ifc.ifc_len <= 0) {
- CURVNET_RESTORE();
+ if (ifc.ifc_len <= 0)
return (EINVAL);
- }
+
+ full = 0;
+ cbs.max_len = maxphys - 1;
again:
- /* Keep track of eth interfaces */
- ethno = 0;
- if (ifc.ifc_len <= max_len) {
- max_len = ifc.ifc_len;
+ if (ifc.ifc_len <= cbs.max_len) {
+ cbs.max_len = ifc.ifc_len;
full = 1;
}
- sb = sbuf_new(NULL, NULL, max_len + 1, SBUF_FIXEDLEN);
- max_len = 0;
- valid_len = 0;
+ cbs.sb = sb = sbuf_new(NULL, NULL, cbs.max_len + 1, SBUF_FIXEDLEN);
+ cbs.max_len = 0;
+ cbs.valid_len = 0;
/* Return all AF_INET addresses of all interfaces */
- IFNET_RLOCK();
- CK_STAILQ_FOREACH(ifp, &V_ifnet, if_link) {
- int addrs = 0;
-
- bzero(&ifr, sizeof(ifr));
- if (IFP_IS_ETH(ifp))
- snprintf(ifr.ifr_name, LINUX_IFNAMSIZ, "eth%d",
- ethno++);
- else
- strlcpy(ifr.ifr_name, ifp->if_xname, LINUX_IFNAMSIZ);
-
- /* Walk the address list */
- CK_STAILQ_FOREACH(ifa, &ifp->if_addrhead, ifa_link) {
- struct sockaddr *sa = ifa->ifa_addr;
-
- if (sa->sa_family == AF_INET) {
- ifr.ifr_addr.sa_family = LINUX_AF_INET;
- memcpy(ifr.ifr_addr.sa_data, sa->sa_data,
- sizeof(ifr.ifr_addr.sa_data));
- sbuf_bcat(sb, &ifr, sizeof(ifr));
- max_len += sizeof(ifr);
- addrs++;
- }
-
- if (sbuf_error(sb) == 0)
- valid_len = sbuf_len(sb);
- }
- if (addrs == 0) {
- bzero((caddr_t)&ifr.ifr_addr, sizeof(ifr.ifr_addr));
- sbuf_bcat(sb, &ifr, sizeof(ifr));
- max_len += sizeof(ifr);
+ NET_EPOCH_ENTER(et);
+ if_foreach(linux_ifconf_ifnet_cb2, &cbs);
+ NET_EPOCH_EXIT(et);
- if (sbuf_error(sb) == 0)
- valid_len = sbuf_len(sb);
- }
- }
- IFNET_RUNLOCK();
-
- if (valid_len != max_len && !full) {
+ if (cbs.valid_len != cbs.max_len && !full) {
sbuf_delete(sb);
goto again;
}
- ifc.ifc_len = valid_len;
+ ifc.ifc_len = cbs.valid_len;
sbuf_finish(sb);
error = copyout(sbuf_data(sb), PTRIN(ifc.ifc_buf), ifc.ifc_len);
if (error == 0)
error = copyout(&ifc, uifc, sizeof(ifc));
sbuf_delete(sb);
- CURVNET_RESTORE();
return (error);
}
static int
-linux_gifflags(struct thread *td, struct ifnet *ifp, struct l_ifreq *ifr)
+linux_ioctl_socket_ifreq(struct thread *td, int fd, u_int cmd,
+ struct l_ifreq *uifr)
{
- l_short flags;
+ struct l_ifreq lifr;
+ struct ifreq bifr;
+ size_t ifrusiz;
+ int error, temp_flags;
- linux_ifflags(ifp, &flags);
-
- return (copyout(&flags, &ifr->ifr_flags, sizeof(flags)));
-}
-
-static int
-linux_gifhwaddr(struct ifnet *ifp, struct l_ifreq *ifr)
-{
- struct l_sockaddr lsa;
-
- if (linux_ifhwaddr(ifp, &lsa) != 0)
- return (ENOENT);
+ switch (cmd) {
+ case LINUX_SIOCGIFINDEX:
+ cmd = SIOCGIFINDEX;
+ break;
+ case LINUX_SIOCGIFFLAGS:
+ cmd = SIOCGIFFLAGS;
+ break;
+ case LINUX_SIOCGIFADDR:
+ cmd = SIOCGIFADDR;
+ break;
+ case LINUX_SIOCSIFADDR:
+ cmd = SIOCSIFADDR;
+ break;
+ case LINUX_SIOCGIFDSTADDR:
+ cmd = SIOCGIFDSTADDR;
+ break;
+ case LINUX_SIOCGIFBRDADDR:
+ cmd = SIOCGIFBRDADDR;
+ break;
+ case LINUX_SIOCGIFNETMASK:
+ cmd = SIOCGIFNETMASK;
+ break;
+ case LINUX_SIOCSIFNETMASK:
+ cmd = SIOCSIFNETMASK;
+ break;
+ case LINUX_SIOCGIFMTU:
+ cmd = SIOCGIFMTU;
+ break;
+ case LINUX_SIOCSIFMTU:
+ cmd = SIOCSIFMTU;
+ break;
+ case LINUX_SIOCGIFHWADDR:
+ cmd = SIOCGHWADDR;
+ break;
+ case LINUX_SIOCGIFMETRIC:
+ cmd = SIOCGIFMETRIC;
+ break;
+ case LINUX_SIOCSIFMETRIC:
+ cmd = SIOCSIFMETRIC;
+ break;
+ /*
+ * XXX This is slightly bogus, but these ioctls are currently
+ * XXX only used by the aironet (if_an) network driver.
+ */
+ case LINUX_SIOCDEVPRIVATE:
+ cmd = SIOCGPRIVATE_0;
+ break;
+ case LINUX_SIOCDEVPRIVATE+1:
+ cmd = SIOCGPRIVATE_1;
+ break;
+ default:
+ LINUX_RATELIMIT_MSG_OPT2(
+ "ioctl_socket_ifreq fd=%d, cmd=0x%x is not implemented",
+ fd, cmd);
+ return (ENOIOCTL);
+ }
- return (copyout(&lsa, &ifr->ifr_hwaddr, sizeof(lsa)));
-}
+ error = copyin(uifr, &lifr, sizeof(lifr));
+ if (error != 0)
+ return (error);
+ bzero(&bifr, sizeof(bifr));
- /*
-* If we fault in bsd_to_linux_ifreq() then we will fault when we call
-* the native ioctl(). Thus, we don't really need to check the return
-* value of this function.
-*/
-static int
-bsd_to_linux_ifreq(struct ifreq *arg)
-{
- struct ifreq ifr;
- size_t ifr_len = sizeof(struct ifreq);
- int error;
+ /*
+ * The size of Linux enum ifr_ifru is bigger than
+ * the FreeBSD size due to the struct ifmap.
+ */
+ ifrusiz = (sizeof(lifr) > sizeof(bifr) ? sizeof(bifr) :
+ sizeof(lifr)) - offsetof(struct l_ifreq, ifr_ifru);
+ bcopy(&lifr.ifr_ifru, &bifr.ifr_ifru, ifrusiz);
- if ((error = copyin(arg, &ifr, ifr_len)))
+ error = ifname_linux_to_bsd(td, lifr.ifr_name, bifr.ifr_name);
+ if (error != 0)
return (error);
- *(u_short *)&ifr.ifr_addr = ifr.ifr_addr.sa_family;
+ /* Translate in values. */
+ switch (cmd) {
+ case SIOCGIFINDEX:
+ bifr.ifr_index = lifr.ifr_index;
+ break;
+ case SIOCSIFADDR:
+ case SIOCSIFNETMASK:
+ bifr.ifr_addr.sa_len = sizeof(struct sockaddr);
+ bifr.ifr_addr.sa_family =
+ linux_to_bsd_domain(lifr.ifr_addr.sa_family);
+ break;
+ default:
+ break;
+ }
- error = copyout(&ifr, arg, ifr_len);
+ error = kern_ioctl(td, fd, cmd, (caddr_t)&bifr);
+ if (error != 0)
+ return (error);
+ bzero(&lifr.ifr_ifru, sizeof(lifr.ifr_ifru));
+
+ /* Translate out values. */
+ switch (cmd) {
+ case SIOCGIFINDEX:
+ lifr.ifr_index = bifr.ifr_index;
+ break;
+ case SIOCGIFFLAGS:
+ temp_flags = bifr.ifr_flags | (bifr.ifr_flagshigh << 16);
+ lifr.ifr_flags = bsd_to_linux_ifflags(temp_flags);
+ break;
+ case SIOCGIFADDR:
+ case SIOCSIFADDR:
+ case SIOCGIFDSTADDR:
+ case SIOCGIFBRDADDR:
+ case SIOCGIFNETMASK:
+ bcopy(&bifr.ifr_addr, &lifr.ifr_addr, sizeof(bifr.ifr_addr));
+ lifr.ifr_addr.sa_family =
+ bsd_to_linux_domain(bifr.ifr_addr.sa_family);
+ break;
+ case SIOCGHWADDR:
+ bcopy(&bifr.ifr_addr, &lifr.ifr_hwaddr, sizeof(bifr.ifr_addr));
+ lifr.ifr_hwaddr.sa_family = LINUX_ARPHRD_ETHER;
+ break;
+ default:
+ bcopy(&bifr.ifr_ifru, &lifr.ifr_ifru, ifrusiz);
+ break;
+ }
- return (error);
+ return (copyout(&lifr, uifr, sizeof(lifr)));
}
/*
@@ -2301,84 +2379,34 @@ bsd_to_linux_ifreq(struct ifreq *arg)
static int
linux_ioctl_socket(struct thread *td, struct linux_ioctl_args *args)
{
- char lifname[LINUX_IFNAMSIZ], ifname[IFNAMSIZ];
- struct ifnet *ifp;
struct file *fp;
int error, type;
- ifp = NULL;
- error = 0;
-
error = fget(td, args->fd, &cap_ioctl_rights, &fp);
if (error != 0)
return (error);
type = fp->f_type;
fdrop(fp, td);
+
+ CURVNET_SET(TD_TO_VNET(td));
+
if (type != DTYPE_SOCKET) {
/* not a socket - probably a tap / vmnet device */
switch (args->cmd) {
case LINUX_SIOCGIFADDR:
case LINUX_SIOCSIFADDR:
case LINUX_SIOCGIFFLAGS:
- return (linux_ioctl_special(td, args));
+ error = linux_ioctl_special(td, args);
+ break;
default:
- return (ENOIOCTL);
+ error = ENOIOCTL;
+ break;
}
+ CURVNET_RESTORE();
+ return (error);
}
- switch (args->cmd & 0xffff) {
- case LINUX_FIOGETOWN:
- case LINUX_FIOSETOWN:
- case LINUX_SIOCADDMULTI:
- case LINUX_SIOCATMARK:
- case LINUX_SIOCDELMULTI:
- case LINUX_SIOCGIFNAME:
- case LINUX_SIOCGIFCONF:
- case LINUX_SIOCGPGRP:
- case LINUX_SIOCSPGRP:
- case LINUX_SIOCGIFCOUNT:
- /* these ioctls don't take an interface name */
- break;
-
- case LINUX_SIOCGIFFLAGS:
- case LINUX_SIOCGIFADDR:
- case LINUX_SIOCSIFADDR:
- case LINUX_SIOCGIFDSTADDR:
- case LINUX_SIOCGIFBRDADDR:
- case LINUX_SIOCGIFNETMASK:
- case LINUX_SIOCSIFNETMASK:
- case LINUX_SIOCGIFMTU:
- case LINUX_SIOCSIFMTU:
- case LINUX_SIOCSIFNAME:
- case LINUX_SIOCGIFHWADDR:
- case LINUX_SIOCSIFHWADDR:
- case LINUX_SIOCDEVPRIVATE:
- case LINUX_SIOCDEVPRIVATE+1:
- case LINUX_SIOCGIFINDEX:
- /* copy in the interface name and translate it. */
- error = copyin((void *)args->arg, lifname, LINUX_IFNAMSIZ);
- if (error != 0)
- return (error);
- memset(ifname, 0, sizeof(ifname));
- ifp = ifname_linux_to_bsd(td, lifname, ifname);
- if (ifp == NULL)
- return (EINVAL);
- /*
- * We need to copy it back out in case we pass the
- * request on to our native ioctl(), which will expect
- * the ifreq to be in user space and have the correct
- * interface name.
- */
- error = copyout(ifname, (void *)args->arg, IFNAMSIZ);
- if (error != 0)
- return (error);
- break;
-
- default:
- return (ENOIOCTL);
- }
-
- switch (args->cmd & 0xffff) {
+ switch (args->cmd) {
case LINUX_FIOSETOWN:
args->cmd = FIOSETOWN;
error = sys_ioctl(td, (struct ioctl_args *)args);
@@ -2414,67 +2442,6 @@ linux_ioctl_socket(struct thread *td, struct linux_ioctl_args *args)
error = linux_ifconf(td, (struct ifconf *)args->arg);
break;
- case LINUX_SIOCGIFFLAGS:
- args->cmd = SIOCGIFFLAGS;
- error = linux_gifflags(td, ifp, (struct l_ifreq *)args->arg);
- break;
-
- case LINUX_SIOCGIFADDR:
- args->cmd = SIOCGIFADDR;
- error = sys_ioctl(td, (struct ioctl_args *)args);
- bsd_to_linux_ifreq((struct ifreq *)args->arg);
- break;
-
- case LINUX_SIOCSIFADDR:
- /* XXX probably doesn't work, included for completeness */
- args->cmd = SIOCSIFADDR;
- error = sys_ioctl(td, (struct ioctl_args *)args);
- break;
-
- case LINUX_SIOCGIFDSTADDR:
- args->cmd = SIOCGIFDSTADDR;
- error = sys_ioctl(td, (struct ioctl_args *)args);
- bsd_to_linux_ifreq((struct ifreq *)args->arg);
- break;
-
- case LINUX_SIOCGIFBRDADDR:
- args->cmd = SIOCGIFBRDADDR;
- error = sys_ioctl(td, (struct ioctl_args *)args);
- bsd_to_linux_ifreq((struct ifreq *)args->arg);
- break;
-
- case LINUX_SIOCGIFNETMASK:
- args->cmd = SIOCGIFNETMASK;
- error = sys_ioctl(td, (struct ioctl_args *)args);
- bsd_to_linux_ifreq((struct ifreq *)args->arg);
- break;
-
- case LINUX_SIOCSIFNETMASK:
- error = ENOIOCTL;
- break;
-
- case LINUX_SIOCGIFMTU:
- args->cmd = SIOCGIFMTU;
- error = sys_ioctl(td, (struct ioctl_args *)args);
- break;
-
- case LINUX_SIOCSIFMTU:
- args->cmd = SIOCSIFMTU;
- error = sys_ioctl(td, (struct ioctl_args *)args);
- break;
-
- case LINUX_SIOCSIFNAME:
- error = ENOIOCTL;
- break;
-
- case LINUX_SIOCGIFHWADDR:
- error = linux_gifhwaddr(ifp, (struct l_ifreq *)args->arg);
- break;
-
- case LINUX_SIOCSIFHWADDR:
- error = ENOIOCTL;
- break;
-
case LINUX_SIOCADDMULTI:
args->cmd = SIOCADDMULTI;
error = sys_ioctl(td, (struct ioctl_args *)args);
@@ -2485,34 +2452,17 @@ linux_ioctl_socket(struct thread *td, struct linux_ioctl_args *args)
error = sys_ioctl(td, (struct ioctl_args *)args);
break;
- case LINUX_SIOCGIFINDEX:
- args->cmd = SIOCGIFINDEX;
- error = sys_ioctl(td, (struct ioctl_args *)args);
- break;
-
case LINUX_SIOCGIFCOUNT:
error = 0;
break;
- /*
- * XXX This is slightly bogus, but these ioctls are currently
- * XXX only used by the aironet (if_an) network driver.
- */
- case LINUX_SIOCDEVPRIVATE:
- args->cmd = SIOCGPRIVATE_0;
- error = sys_ioctl(td, (struct ioctl_args *)args);
- break;
-
- case LINUX_SIOCDEVPRIVATE+1:
- args->cmd = SIOCGPRIVATE_1;
- error = sys_ioctl(td, (struct ioctl_args *)args);
+ default:
+ error = linux_ioctl_socket_ifreq(td, args->fd, args->cmd,
+ PTRIN(args->arg));
break;
}
- if (ifp != NULL)
- /* restore the original interface name */
- copyout(lifname, (void *)args->arg, LINUX_IFNAMSIZ);
-
+ CURVNET_RESTORE();
return (error);
}
@@ -3275,7 +3225,9 @@ linux_ioctl_v4l2(struct thread *td, struct linux_ioctl_args *args)
error = fo_ioctl(fp, VIDIOC_TRY_FMT, &vformat,
td->td_ucred, td);
bsd_to_linux_v4l2_format(&vformat, &l_vformat);
- copyout(&l_vformat, (void *)args->arg, sizeof(l_vformat));
+ if (error == 0)
+ error = copyout(&l_vformat, (void *)args->arg,
+ sizeof(l_vformat));
fdrop(fp, td);
return (error);
@@ -3344,7 +3296,9 @@ linux_ioctl_v4l2(struct thread *td, struct linux_ioctl_args *args)
error = fo_ioctl(fp, VIDIOC_DQBUF, &vbuf,
td->td_ucred, td);
bsd_to_linux_v4l2_buffer(&vbuf, &l_vbuf);
- copyout(&l_vbuf, (void *)args->arg, sizeof(l_vbuf));
+ if (error == 0)
+ error = copyout(&l_vbuf, (void *)args->arg,
+ sizeof(l_vbuf));
fdrop(fp, td);
return (error);
@@ -3586,6 +3540,36 @@ linux_ioctl_kcov(struct thread *td, struct linux_ioctl_args *args)
return (error);
}
+#ifndef COMPAT_LINUX32
+static int
+linux_ioctl_nvme(struct thread *td, struct linux_ioctl_args *args)
+{
+
+ /*
+ * The NVMe drivers for namespace and controller implement these
+ * commands using their native format. All the others are not
+ * implemented yet.
+ */
+ switch (args->cmd & 0xffff) {
+ case LINUX_NVME_IOCTL_ID:
+ args->cmd = NVME_IOCTL_ID;
+ break;
+ case LINUX_NVME_IOCTL_RESET:
+ args->cmd = NVME_IOCTL_RESET;
+ break;
+ case LINUX_NVME_IOCTL_ADMIN_CMD:
+ args->cmd = NVME_IOCTL_ADMIN_CMD;
+ break;
+ case LINUX_NVME_IOCTL_IO_CMD:
+ args->cmd = NVME_IOCTL_IO_CMD;
+ break;
+ default:
+ return (ENODEV);
+ }
+ return (sys_ioctl(td, (struct ioctl_args *)args));
+}
+#endif
+
/*
* main ioctl syscall function
*/
diff --git a/sys/compat/linux/linux_ioctl.h b/sys/compat/linux/linux_ioctl.h
index 4aaf1114ff39..8345b7e4b719 100644
--- a/sys/compat/linux/linux_ioctl.h
+++ b/sys/compat/linux/linux_ioctl.h
@@ -1,5 +1,5 @@
/*-
- * SPDX-License-Identifier: BSD-2-Clause-FreeBSD
+ * SPDX-License-Identifier: BSD-2-Clause
*
* Copyright (c) 1999 Marcel Moolenaar
* All rights reserved.
@@ -24,8 +24,6 @@
* 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.
- *
- * $FreeBSD$
*/
#ifndef _LINUX_IOCTL_H_
@@ -237,6 +235,8 @@
#define LINUX_SIOCGIFBRDADDR 0x8919
#define LINUX_SIOCGIFNETMASK 0x891b
#define LINUX_SIOCSIFNETMASK 0x891c
+#define LINUX_SIOCGIFMETRIC 0x891d
+#define LINUX_SIOCSIFMETRIC 0x891e
#define LINUX_SIOCGIFMTU 0x8921
#define LINUX_SIOCSIFMTU 0x8922
#define LINUX_SIOCSIFNAME 0x8923
@@ -386,6 +386,8 @@
#define LINUX_TIOCGPTN 0x5430
#define LINUX_TIOCSPTLCK 0x5431
+#define LINUX_TIOCGPTPEER 0x5441
+
#define LINUX_FIONCLEX 0x5450
#define LINUX_FIOCLEX 0x5451
#define LINUX_FIOASYNC 0x5452
@@ -460,6 +462,7 @@
#define LINUX_IXOFF 0x0001000
#define LINUX_IMAXBEL 0x0002000
+#define LINUX_IUTF8 0x0004000
/* Linux c_oflag masks */
#define LINUX_OPOST 0x0000001
@@ -780,6 +783,20 @@
#define LINUX_KCOV_REMOTE_ENABLE 0x6366
/*
+ * NVMe IOCTLs defined by Linux
+ */
+#define LINUX_NVME_IOCTL_ID 0x4e40
+#define LINUX_NVME_IOCTL_ADMIN_CMD 0x4e41
+#define LINUX_NVME_IOCTL_SUBMIT_IO 0x4e42
+#define LINUX_NVME_IOCTL_IO_CMD 0x4e43
+#define LINUX_NVME_IOCTL_RESET 0x4e44
+#define LINUX_NVME_IOCTL_SUBSYS_RESET 0x4e45
+#define LINUX_NVME_IOCTL_RESCAN 0x4e46
+
+#define LINUX_IOCTL_NVME_MIN LINUX_NVME_IOCTL_ID
+#define LINUX_IOCTL_NVME_MAX LINUX_NVME_IOCTL_RESCAN
+
+/*
* Pluggable ioctl handlers
*/
struct linux_ioctl_args;
@@ -806,4 +823,16 @@ int linux32_ioctl_register_handler(struct linux_ioctl_handler *h);
int linux32_ioctl_unregister_handler(struct linux_ioctl_handler *h);
#endif
+#define LINUX_IOCTL_SET(n, low, high) \
+static linux_ioctl_function_t n##_linux_ioctl; \
+static struct linux_ioctl_handler n##_linux_handler = { \
+ n##_linux_ioctl, \
+ low, \
+ high \
+}; \
+SYSINIT(n##_ioctl_register, SI_SUB_KLD, SI_ORDER_MIDDLE, \
+ linux_ioctl_register_handler, &n##_linux_handler); \
+SYSUNINIT(n##_ioctl_unregister, SI_SUB_KLD, SI_ORDER_MIDDLE, \
+ linux_ioctl_unregister_handler, &n##_linux_handler)
+
#endif /* !_LINUX_IOCTL_H_ */
diff --git a/sys/compat/linux/linux_ipc.c b/sys/compat/linux/linux_ipc.c
index 82fe54fae65e..5b6a28b20774 100644
--- a/sys/compat/linux/linux_ipc.c
+++ b/sys/compat/linux/linux_ipc.c
@@ -1,5 +1,5 @@
/*-
- * SPDX-License-Identifier: BSD-2-Clause-FreeBSD
+ * SPDX-License-Identifier: BSD-2-Clause
*
* Copyright (c) 1994-1995 Søren Schmidt
* All rights reserved.
@@ -26,21 +26,16 @@
* SUCH DAMAGE.
*/
-#include <sys/cdefs.h>
-__FBSDID("$FreeBSD$");
-
#include <sys/param.h>
-#include <sys/systm.h>
-#include <sys/syscallsubr.h>
-#include <sys/sysproto.h>
-#include <sys/proc.h>
#include <sys/limits.h>
#include <sys/msg.h>
+#include <sys/proc.h>
#include <sys/sem.h>
#include <sys/shm.h>
#include <sys/stat.h>
-
-#include "opt_compat.h"
+#include <sys/syscallsubr.h>
+#include <sys/sysent.h>
+#include <sys/sysproto.h>
#ifdef COMPAT_LINUX32
#include <machine/../linux32/linux.h>
@@ -51,6 +46,7 @@ __FBSDID("$FreeBSD$");
#endif
#include <compat/linux/linux_ipc.h>
#include <compat/linux/linux_ipc64.h>
+#include <compat/linux/linux_time.h>
#include <compat/linux/linux_util.h>
/*
@@ -304,22 +300,20 @@ linux_msqid_pullup(l_int ver, struct l_msqid64_ds *linux_msqid64, caddr_t uaddr)
if (ver == LINUX_IPC_64 || SV_CURPROC_FLAG(SV_LP64))
return (copyin(uaddr, linux_msqid64, sizeof(*linux_msqid64)));
- else {
- error = copyin(uaddr, &linux_msqid, sizeof(linux_msqid));
- if (error != 0)
- return (error);
- bzero(linux_msqid64, sizeof(*linux_msqid64));
+ error = copyin(uaddr, &linux_msqid, sizeof(linux_msqid));
+ if (error != 0)
+ return (error);
- linux_msqid64->msg_perm.uid = linux_msqid.msg_perm.uid;
- linux_msqid64->msg_perm.gid = linux_msqid.msg_perm.gid;
- linux_msqid64->msg_perm.mode = linux_msqid.msg_perm.mode;
- if (linux_msqid.msg_qbytes == 0)
- linux_msqid64->msg_qbytes = linux_msqid.msg_lqbytes;
- else
- linux_msqid64->msg_qbytes = linux_msqid.msg_qbytes;
- return (0);
- }
+ bzero(linux_msqid64, sizeof(*linux_msqid64));
+ linux_msqid64->msg_perm.uid = linux_msqid.msg_perm.uid;
+ linux_msqid64->msg_perm.gid = linux_msqid.msg_perm.gid;
+ linux_msqid64->msg_perm.mode = linux_msqid.msg_perm.mode;
+ if (linux_msqid.msg_qbytes == 0)
+ linux_msqid64->msg_qbytes = linux_msqid.msg_lqbytes;
+ else
+ linux_msqid64->msg_qbytes = linux_msqid.msg_qbytes;
+ return (0);
}
static int
@@ -330,43 +324,40 @@ linux_msqid_pushdown(l_int ver, struct l_msqid64_ds *linux_msqid64, caddr_t uadd
if (ver == LINUX_IPC_64 || SV_CURPROC_FLAG(SV_LP64))
return (copyout(linux_msqid64, uaddr, sizeof(*linux_msqid64)));
- else {
- bzero(&linux_msqid, sizeof(linux_msqid));
- error = linux_ipc64_perm_to_ipc_perm(&linux_msqid64->msg_perm,
- &linux_msqid.msg_perm);
- if (error != 0)
- return (error);
+ bzero(&linux_msqid, sizeof(linux_msqid));
+ error = linux_ipc64_perm_to_ipc_perm(&linux_msqid64->msg_perm,
+ &linux_msqid.msg_perm);
+ if (error != 0)
+ return (error);
- linux_msqid.msg_stime = linux_msqid64->msg_stime;
- linux_msqid.msg_rtime = linux_msqid64->msg_rtime;
- linux_msqid.msg_ctime = linux_msqid64->msg_ctime;
-
- if (linux_msqid64->msg_cbytes > USHRT_MAX)
- linux_msqid.msg_cbytes = USHRT_MAX;
- else
- linux_msqid.msg_cbytes = linux_msqid64->msg_cbytes;
- linux_msqid.msg_lcbytes = linux_msqid64->msg_cbytes;
- if (linux_msqid64->msg_qnum > USHRT_MAX)
- linux_msqid.msg_qnum = USHRT_MAX;
- else
- linux_msqid.msg_qnum = linux_msqid64->msg_qnum;
- if (linux_msqid64->msg_qbytes > USHRT_MAX)
- linux_msqid.msg_qbytes = USHRT_MAX;
- else
- linux_msqid.msg_qbytes = linux_msqid64->msg_qbytes;
- linux_msqid.msg_lqbytes = linux_msqid64->msg_qbytes;
- linux_msqid.msg_lspid = linux_msqid64->msg_lspid;
- linux_msqid.msg_lrpid = linux_msqid64->msg_lrpid;
-
- /* Linux does not check overflow */
- if (linux_msqid.msg_stime != linux_msqid64->msg_stime ||
- linux_msqid.msg_rtime != linux_msqid64->msg_rtime ||
- linux_msqid.msg_ctime != linux_msqid64->msg_ctime)
- return (EOVERFLOW);
-
- return (copyout(&linux_msqid, uaddr, sizeof(linux_msqid)));
- }
+ linux_msqid.msg_stime = linux_msqid64->msg_stime;
+ linux_msqid.msg_rtime = linux_msqid64->msg_rtime;
+ linux_msqid.msg_ctime = linux_msqid64->msg_ctime;
+
+ if (linux_msqid64->msg_cbytes > USHRT_MAX)
+ linux_msqid.msg_cbytes = USHRT_MAX;
+ else
+ linux_msqid.msg_cbytes = linux_msqid64->msg_cbytes;
+ linux_msqid.msg_lcbytes = linux_msqid64->msg_cbytes;
+ if (linux_msqid64->msg_qnum > USHRT_MAX)
+ linux_msqid.msg_qnum = USHRT_MAX;
+ else
+ linux_msqid.msg_qnum = linux_msqid64->msg_qnum;
+ if (linux_msqid64->msg_qbytes > USHRT_MAX)
+ linux_msqid.msg_qbytes = USHRT_MAX;
+ else
+ linux_msqid.msg_qbytes = linux_msqid64->msg_qbytes;
+ linux_msqid.msg_lqbytes = linux_msqid64->msg_qbytes;
+ linux_msqid.msg_lspid = linux_msqid64->msg_lspid;
+ linux_msqid.msg_lrpid = linux_msqid64->msg_lrpid;
+
+ /* Linux does not check overflow */
+ if (linux_msqid.msg_stime != linux_msqid64->msg_stime ||
+ linux_msqid.msg_rtime != linux_msqid64->msg_rtime ||
+ linux_msqid.msg_ctime != linux_msqid64->msg_ctime)
+ return (EOVERFLOW);
+ return (copyout(&linux_msqid, uaddr, sizeof(linux_msqid)));
}
static int
@@ -377,18 +368,15 @@ linux_semid_pullup(l_int ver, struct l_semid64_ds *linux_semid64, caddr_t uaddr)
if (ver == LINUX_IPC_64 || SV_CURPROC_FLAG(SV_LP64))
return (copyin(uaddr, linux_semid64, sizeof(*linux_semid64)));
- else {
- error = copyin(uaddr, &linux_semid, sizeof(linux_semid));
- if (error != 0)
- return (error);
-
- bzero(linux_semid64, sizeof(*linux_semid64));
+ error = copyin(uaddr, &linux_semid, sizeof(linux_semid));
+ if (error != 0)
+ return (error);
- linux_semid64->sem_perm.uid = linux_semid.sem_perm.uid;
- linux_semid64->sem_perm.gid = linux_semid.sem_perm.gid;
- linux_semid64->sem_perm.mode = linux_semid.sem_perm.mode;
- return (0);
- }
+ bzero(linux_semid64, sizeof(*linux_semid64));
+ linux_semid64->sem_perm.uid = linux_semid.sem_perm.uid;
+ linux_semid64->sem_perm.gid = linux_semid.sem_perm.gid;
+ linux_semid64->sem_perm.mode = linux_semid.sem_perm.mode;
+ return (0);
}
static int
@@ -399,26 +387,23 @@ linux_semid_pushdown(l_int ver, struct l_semid64_ds *linux_semid64, caddr_t uadd
if (ver == LINUX_IPC_64 || SV_CURPROC_FLAG(SV_LP64))
return (copyout(linux_semid64, uaddr, sizeof(*linux_semid64)));
- else {
- bzero(&linux_semid, sizeof(linux_semid));
+ bzero(&linux_semid, sizeof(linux_semid));
error = linux_ipc64_perm_to_ipc_perm(&linux_semid64->sem_perm,
- &linux_semid.sem_perm);
- if (error != 0)
- return (error);
-
- linux_semid.sem_otime = linux_semid64->sem_otime;
- linux_semid.sem_ctime = linux_semid64->sem_ctime;
- linux_semid.sem_nsems = linux_semid64->sem_nsems;
+ &linux_semid.sem_perm);
+ if (error != 0)
+ return (error);
- /* Linux does not check overflow */
- if (linux_semid.sem_otime != linux_semid64->sem_otime ||
- linux_semid.sem_ctime != linux_semid64->sem_ctime ||
- linux_semid.sem_nsems != linux_semid64->sem_nsems)
- return (EOVERFLOW);
+ linux_semid.sem_otime = linux_semid64->sem_otime;
+ linux_semid.sem_ctime = linux_semid64->sem_ctime;
+ linux_semid.sem_nsems = linux_semid64->sem_nsems;
- return (copyout(&linux_semid, uaddr, sizeof(linux_semid)));
- }
+ /* Linux does not check overflow */
+ if (linux_semid.sem_otime != linux_semid64->sem_otime ||
+ linux_semid.sem_ctime != linux_semid64->sem_ctime ||
+ linux_semid.sem_nsems != linux_semid64->sem_nsems)
+ return (EOVERFLOW);
+ return (copyout(&linux_semid, uaddr, sizeof(linux_semid)));
}
static int
@@ -429,18 +414,16 @@ linux_shmid_pullup(l_int ver, struct l_shmid64_ds *linux_shmid64, caddr_t uaddr)
if (ver == LINUX_IPC_64 || SV_CURPROC_FLAG(SV_LP64))
return (copyin(uaddr, linux_shmid64, sizeof(*linux_shmid64)));
- else {
- error = copyin(uaddr, &linux_shmid, sizeof(linux_shmid));
- if (error != 0)
- return (error);
- bzero(linux_shmid64, sizeof(*linux_shmid64));
+ error = copyin(uaddr, &linux_shmid, sizeof(linux_shmid));
+ if (error != 0)
+ return (error);
- linux_shmid64->shm_perm.uid = linux_shmid.shm_perm.uid;
- linux_shmid64->shm_perm.gid = linux_shmid.shm_perm.gid;
- linux_shmid64->shm_perm.mode = linux_shmid.shm_perm.mode;
- return (0);
- }
+ bzero(linux_shmid64, sizeof(*linux_shmid64));
+ linux_shmid64->shm_perm.uid = linux_shmid.shm_perm.uid;
+ linux_shmid64->shm_perm.gid = linux_shmid.shm_perm.gid;
+ linux_shmid64->shm_perm.mode = linux_shmid.shm_perm.mode;
+ return (0);
}
static int
@@ -451,34 +434,31 @@ linux_shmid_pushdown(l_int ver, struct l_shmid64_ds *linux_shmid64, caddr_t uadd
if (ver == LINUX_IPC_64 || SV_CURPROC_FLAG(SV_LP64))
return (copyout(linux_shmid64, uaddr, sizeof(*linux_shmid64)));
- else {
- bzero(&linux_shmid, sizeof(linux_shmid));
- error = linux_ipc64_perm_to_ipc_perm(&linux_shmid64->shm_perm,
- &linux_shmid.shm_perm);
- if (error != 0)
- return (error);
+ bzero(&linux_shmid, sizeof(linux_shmid));
+ error = linux_ipc64_perm_to_ipc_perm(&linux_shmid64->shm_perm,
+ &linux_shmid.shm_perm);
+ if (error != 0)
+ return (error);
- linux_shmid.shm_segsz = linux_shmid64->shm_segsz;
- linux_shmid.shm_atime = linux_shmid64->shm_atime;
- linux_shmid.shm_dtime = linux_shmid64->shm_dtime;
- linux_shmid.shm_ctime = linux_shmid64->shm_ctime;
- linux_shmid.shm_cpid = linux_shmid64->shm_cpid;
- linux_shmid.shm_lpid = linux_shmid64->shm_lpid;
- linux_shmid.shm_nattch = linux_shmid64->shm_nattch;
-
- /* Linux does not check overflow */
- if (linux_shmid.shm_segsz != linux_shmid64->shm_segsz ||
- linux_shmid.shm_atime != linux_shmid64->shm_atime ||
- linux_shmid.shm_dtime != linux_shmid64->shm_dtime ||
- linux_shmid.shm_ctime != linux_shmid64->shm_ctime ||
- linux_shmid.shm_cpid != linux_shmid64->shm_cpid ||
- linux_shmid.shm_lpid != linux_shmid64->shm_lpid ||
- linux_shmid.shm_nattch != linux_shmid64->shm_nattch)
- return (EOVERFLOW);
-
- return (copyout(&linux_shmid, uaddr, sizeof(linux_shmid)));
- }
+ linux_shmid.shm_segsz = linux_shmid64->shm_segsz;
+ linux_shmid.shm_atime = linux_shmid64->shm_atime;
+ linux_shmid.shm_dtime = linux_shmid64->shm_dtime;
+ linux_shmid.shm_ctime = linux_shmid64->shm_ctime;
+ linux_shmid.shm_cpid = linux_shmid64->shm_cpid;
+ linux_shmid.shm_lpid = linux_shmid64->shm_lpid;
+ linux_shmid.shm_nattch = linux_shmid64->shm_nattch;
+
+ /* Linux does not check overflow */
+ if (linux_shmid.shm_segsz != linux_shmid64->shm_segsz ||
+ linux_shmid.shm_atime != linux_shmid64->shm_atime ||
+ linux_shmid.shm_dtime != linux_shmid64->shm_dtime ||
+ linux_shmid.shm_ctime != linux_shmid64->shm_ctime ||
+ linux_shmid.shm_cpid != linux_shmid64->shm_cpid ||
+ linux_shmid.shm_lpid != linux_shmid64->shm_lpid ||
+ linux_shmid.shm_nattch != linux_shmid64->shm_nattch)
+ return (EOVERFLOW);
+ return (copyout(&linux_shmid, uaddr, sizeof(linux_shmid)));
}
static int
@@ -490,51 +470,65 @@ linux_shminfo_pushdown(l_int ver, struct l_shminfo64 *linux_shminfo64,
if (ver == LINUX_IPC_64 || SV_CURPROC_FLAG(SV_LP64))
return (copyout(linux_shminfo64, uaddr,
sizeof(*linux_shminfo64)));
- else {
- bzero(&linux_shminfo, sizeof(linux_shminfo));
- linux_shminfo.shmmax = linux_shminfo64->shmmax;
- linux_shminfo.shmmin = linux_shminfo64->shmmin;
- linux_shminfo.shmmni = linux_shminfo64->shmmni;
- linux_shminfo.shmseg = linux_shminfo64->shmseg;
- linux_shminfo.shmall = linux_shminfo64->shmall;
+ bzero(&linux_shminfo, sizeof(linux_shminfo));
+ linux_shminfo.shmmax = linux_shminfo64->shmmax;
+ linux_shminfo.shmmin = linux_shminfo64->shmmin;
+ linux_shminfo.shmmni = linux_shminfo64->shmmni;
+ linux_shminfo.shmseg = linux_shminfo64->shmseg;
+ linux_shminfo.shmall = linux_shminfo64->shmall;
+ return (copyout(&linux_shminfo, uaddr, sizeof(linux_shminfo)));
+}
- return (copyout(&linux_shminfo, uaddr,
- sizeof(linux_shminfo)));
- }
+#if defined(__i386__) || (defined(__amd64__) && defined(COMPAT_LINUX32))
+int
+linux_semtimedop_time64(struct thread *td, struct linux_semtimedop_time64_args *args)
+{
+ struct timespec ts, *tsa;
+ int error;
+
+ if (args->timeout) {
+ error = linux_get_timespec64(&ts, args->timeout);
+ if (error != 0)
+ return (error);
+ tsa = &ts;
+ } else
+ tsa = NULL;
+
+ return (kern_semop(td, args->semid, PTRIN(args->tsops),
+ args->nsops, tsa));
}
+#endif /* __i386__) || (__amd64__ && COMPAT_LINUX32) */
int
-linux_semop(struct thread *td, struct linux_semop_args *args)
+linux_semtimedop(struct thread *td, struct linux_semtimedop_args *args)
{
- struct semop_args /* {
- int semid;
- struct sembuf *sops;
- int nsops;
- } */ bsd_args;
+ struct timespec ts, *tsa;
+ int error;
- if (args->nsops < 1 || args->semid < 0)
- return (EINVAL);
- bsd_args.semid = args->semid;
- bsd_args.sops = PTRIN(args->tsops);
- bsd_args.nsops = args->nsops;
- return (sys_semop(td, &bsd_args));
+ if (args->timeout) {
+ error = linux_get_timespec(&ts, args->timeout);
+ if (error != 0)
+ return (error);
+ tsa = &ts;
+ } else
+ tsa = NULL;
+
+ return (kern_semop(td, args->semid, PTRIN(args->tsops),
+ args->nsops, tsa));
}
int
linux_semget(struct thread *td, struct linux_semget_args *args)
{
- struct semget_args /* {
- key_t key;
- int nsems;
- int semflg;
- } */ bsd_args;
+ struct semget_args bsd_args = {
+ .key = args->key,
+ .nsems = args->nsems,
+ .semflg = args->semflg
+ };
if (args->nsems < 0)
return (EINVAL);
- bsd_args.key = args->key;
- bsd_args.nsems = args->nsems;
- bsd_args.semflg = args->semflg;
return (sys_semget(td, &bsd_args));
}
@@ -688,13 +682,11 @@ linux_msgrcv(struct thread *td, struct linux_msgrcv_args *args)
int
linux_msgget(struct thread *td, struct linux_msgget_args *args)
{
- struct msgget_args /* {
- key_t key;
- int msgflg;
- } */ bsd_args;
+ struct msgget_args bsd_args = {
+ .key = args->key,
+ .msgflg = args->msgflg
+ };
- bsd_args.key = args->key;
- bsd_args.msgflg = args->msgflg;
return (sys_msgget(td, &bsd_args));
}
@@ -780,41 +772,34 @@ linux_msgctl(struct thread *td, struct linux_msgctl_args *args)
int
linux_shmat(struct thread *td, struct linux_shmat_args *args)
{
- struct shmat_args /* {
- int shmid;
- void *shmaddr;
- int shmflg;
- } */ bsd_args;
-
- bsd_args.shmid = args->shmid;
- bsd_args.shmaddr = PTRIN(args->shmaddr);
- bsd_args.shmflg = args->shmflg;
+ struct shmat_args bsd_args = {
+ .shmid = args->shmid,
+ .shmaddr = PTRIN(args->shmaddr),
+ .shmflg = args->shmflg
+ };
+
return (sys_shmat(td, &bsd_args));
}
int
linux_shmdt(struct thread *td, struct linux_shmdt_args *args)
{
- struct shmdt_args /* {
- void *shmaddr;
- } */ bsd_args;
+ struct shmdt_args bsd_args = {
+ .shmaddr = PTRIN(args->shmaddr)
+ };
- bsd_args.shmaddr = PTRIN(args->shmaddr);
return (sys_shmdt(td, &bsd_args));
}
int
linux_shmget(struct thread *td, struct linux_shmget_args *args)
{
- struct shmget_args /* {
- key_t key;
- int size;
- int shmflg;
- } */ bsd_args;
-
- bsd_args.key = args->key;
- bsd_args.size = args->size;
- bsd_args.shmflg = args->shmflg;
+ struct shmget_args bsd_args = {
+ .key = args->key,
+ .size = args->size,
+ .shmflg = args->shmflg
+ };
+
return (sys_shmget(td, &bsd_args));
}
diff --git a/sys/compat/linux/linux_ipc.h b/sys/compat/linux/linux_ipc.h
index b1bd3fffa4d6..c7a512516444 100644
--- a/sys/compat/linux/linux_ipc.h
+++ b/sys/compat/linux/linux_ipc.h
@@ -1,5 +1,5 @@
/*-
- * SPDX-License-Identifier: BSD-2-Clause-FreeBSD
+ * SPDX-License-Identifier: BSD-2-Clause
*
* Copyright (c) 2000 Marcel Moolenaar
* All rights reserved.
@@ -24,8 +24,6 @@
* 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.
- *
- * $FreeBSD$
*/
#ifndef _LINUX_IPC_H_
@@ -37,6 +35,7 @@
#define LINUX_SEMOP 1
#define LINUX_SEMGET 2
#define LINUX_SEMCTL 3
+#define LINUX_SEMTIMEDOP 4
#define LINUX_MSGSND 11
#define LINUX_MSGRCV 12
#define LINUX_MSGGET 13
@@ -83,15 +82,15 @@
message sizes, etc. */
#if defined(__i386__) || (defined(__amd64__) && defined(COMPAT_LINUX32))
-
-struct linux_semop_args
+struct linux_semtimedop_args
{
l_int semid;
- struct l_sembuf *tsops;
+ struct sembuf *tsops;
l_uint nsops;
+ struct l_timespec *timeout;
};
-int linux_semop(struct thread *, struct linux_semop_args *);
-#endif /* __i386__ || (__amd64__ && COMPAT_LINUX32) */
+int linux_semtimedop(struct thread *, struct linux_semtimedop_args *);
+#endif /* __i386__ || (__amd64__ && COMPAT_LINUX32) */
#endif /* _LINUX_IPC_H_ */
diff --git a/sys/compat/linux/linux_ipc64.h b/sys/compat/linux/linux_ipc64.h
index f0aa5618dff1..e3834b909bfc 100644
--- a/sys/compat/linux/linux_ipc64.h
+++ b/sys/compat/linux/linux_ipc64.h
@@ -24,8 +24,6 @@
* 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.
- *
- * $FreeBSD$
*/
#ifndef _LINUX_IPC64_H_
@@ -103,9 +101,13 @@ struct l_msqid64_ds {
struct l_semid64_ds {
struct l_ipc64_perm sem_perm; /* permissions */
l_time_t sem_otime; /* last semop time */
+#if defined(__amd64__) || defined(__i386__)
l_ulong __unused1;
+#endif
l_time_t sem_ctime; /* last change time */
+#if defined(__amd64__) || defined(__i386__)
l_ulong __unused2;
+#endif
l_ulong sem_nsems; /* no. of semaphores in array */
l_ulong __unused3;
l_ulong __unused4;
diff --git a/sys/compat/linux/linux_mib.c b/sys/compat/linux/linux_mib.c
index 13beba323787..9e1c4ed9df57 100644
--- a/sys/compat/linux/linux_mib.c
+++ b/sys/compat/linux/linux_mib.c
@@ -1,5 +1,5 @@
/*-
- * SPDX-License-Identifier: BSD-2-Clause-FreeBSD
+ * SPDX-License-Identifier: BSD-2-Clause
*
* Copyright (c) 1999 Marcel Moolenaar
* All rights reserved.
@@ -26,19 +26,12 @@
* SUCH DAMAGE.
*/
-#include <sys/cdefs.h>
-__FBSDID("$FreeBSD$");
-
#include <sys/param.h>
-#include <sys/kernel.h>
-#include <sys/sdt.h>
-#include <sys/systm.h>
-#include <sys/sysctl.h>
-#include <sys/proc.h>
+#include <sys/lock.h>
#include <sys/malloc.h>
#include <sys/mount.h>
#include <sys/jail.h>
-#include <sys/lock.h>
+#include <sys/proc.h>
#include <sys/sx.h>
#include <compat/linux/linux_mib.h>
@@ -86,7 +79,7 @@ int linux_ignore_ip_recverr = 1;
SYSCTL_INT(_compat_linux, OID_AUTO, ignore_ip_recverr, CTLFLAG_RWTUN,
&linux_ignore_ip_recverr, 0, "Ignore enabling IP_RECVERR");
-int linux_preserve_vstatus = 0;
+int linux_preserve_vstatus = 1;
SYSCTL_INT(_compat_linux, OID_AUTO, preserve_vstatus, CTLFLAG_RWTUN,
&linux_preserve_vstatus, 0, "Preserve VSTATUS termios(4) flag");
@@ -95,10 +88,6 @@ SYSCTL_BOOL(_compat_linux, OID_AUTO, map_sched_prio, CTLFLAG_RDTUN,
&linux_map_sched_prio, 0, "Map scheduler priorities to Linux priorities "
"(not POSIX compliant)");
-int linux_use_emul_path = 1;
-SYSCTL_INT(_compat_linux, OID_AUTO, use_emul_path, CTLFLAG_RWTUN,
- &linux_use_emul_path, 0, "Use linux.compat.emul_path");
-
static bool linux_setid_allowed = true;
SYSCTL_BOOL(_compat_linux, OID_AUTO, setid_allowed, CTLFLAG_RWTUN,
&linux_setid_allowed, 0,
diff --git a/sys/compat/linux/linux_mib.h b/sys/compat/linux/linux_mib.h
index 61a3a38a23ae..1372f4a0f5cf 100644
--- a/sys/compat/linux/linux_mib.h
+++ b/sys/compat/linux/linux_mib.h
@@ -1,5 +1,5 @@
/*-
- * SPDX-License-Identifier: BSD-2-Clause-FreeBSD
+ * SPDX-License-Identifier: BSD-2-Clause
*
* Copyright (c) 1999 Marcel Moolenaar
* All rights reserved.
@@ -24,8 +24,6 @@
* 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.
- *
- * $FreeBSD$
*/
#ifndef _LINUX_MIB_H_
@@ -46,8 +44,8 @@ int linux_get_oss_version(struct thread *td);
int linux_kernver(struct thread *td);
-#define LINUX_KVERSION 4
-#define LINUX_KPATCHLEVEL 4
+#define LINUX_KVERSION 5
+#define LINUX_KPATCHLEVEL 15
#define LINUX_KSUBLEVEL 0
#define LINUX_KERNVER(a,b,c) (((a) << 16) + ((b) << 8) + (c))
@@ -57,13 +55,6 @@ int linux_kernver(struct thread *td);
#define LINUX_XKERNVERSTR(x) LINUX_KERNVERSTR(x)
#define LINUX_VERSION_STR LINUX_XKERNVERSTR(LINUX_KVERSION.LINUX_KPATCHLEVEL.LINUX_KSUBLEVEL)
-#define LINUX_KERNVER_2004000 LINUX_KERNVER(2,4,0)
-#define LINUX_KERNVER_2006000 LINUX_KERNVER(2,6,0)
-#define LINUX_KERNVER_2006039 LINUX_KERNVER(2,6,39)
-
-#define linux_use26(t) (linux_kernver(t) >= LINUX_KERNVER_2006000)
-
-extern int linux_debug;
extern int linux_default_openfiles;
extern int linux_default_stacksize;
extern int linux_dummy_rlimits;
diff --git a/sys/compat/linux/linux_misc.c b/sys/compat/linux/linux_misc.c
index a7502465efbf..0925ffb64480 100644
--- a/sys/compat/linux/linux_misc.c
+++ b/sys/compat/linux/linux_misc.c
@@ -29,57 +29,39 @@
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
-#include <sys/cdefs.h>
-__FBSDID("$FreeBSD$");
-
-#include "opt_compat.h"
-
#include <sys/param.h>
-#include <sys/blist.h>
#include <sys/fcntl.h>
-#if defined(__i386__)
-#include <sys/imgact_aout.h>
-#endif
#include <sys/jail.h>
-#include <sys/kernel.h>
+#include <sys/imgact.h>
#include <sys/limits.h>
#include <sys/lock.h>
-#include <sys/malloc.h>
-#include <sys/mman.h>
-#include <sys/mount.h>
#include <sys/msgbuf.h>
+#include <sys/mqueue.h>
#include <sys/mutex.h>
-#include <sys/namei.h>
#include <sys/poll.h>
#include <sys/priv.h>
#include <sys/proc.h>
#include <sys/procctl.h>
#include <sys/reboot.h>
-#include <sys/racct.h>
#include <sys/random.h>
#include <sys/resourcevar.h>
+#include <sys/rtprio.h>
#include <sys/sched.h>
-#include <sys/sdt.h>
-#include <sys/signalvar.h>
+#include <sys/smp.h>
#include <sys/stat.h>
#include <sys/syscallsubr.h>
#include <sys/sysctl.h>
+#include <sys/sysent.h>
#include <sys/sysproto.h>
-#include <sys/systm.h>
#include <sys/time.h>
#include <sys/vmmeter.h>
#include <sys/vnode.h>
-#include <sys/wait.h>
-#include <sys/cpuset.h>
-#include <sys/uio.h>
+#include <security/audit/audit.h>
#include <security/mac/mac_framework.h>
-#include <vm/vm.h>
#include <vm/pmap.h>
-#include <vm/vm_kern.h>
#include <vm/vm_map.h>
-#include <vm/vm_extern.h>
#include <vm/swap_pager.h>
#ifdef COMPAT_LINUX32
@@ -94,10 +76,10 @@ __FBSDID("$FreeBSD$");
#include <compat/linux/linux_dtrace.h>
#include <compat/linux/linux_file.h>
#include <compat/linux/linux_mib.h>
+#include <compat/linux/linux_mmap.h>
#include <compat/linux/linux_signal.h>
-#include <compat/linux/linux_timer.h>
+#include <compat/linux/linux_time.h>
#include <compat/linux/linux_util.h>
-#include <compat/linux/linux_sysproto.h>
#include <compat/linux/linux_emul.h>
#include <compat/linux/linux_misc.h>
@@ -205,7 +187,7 @@ linux_alarm(struct thread *td, struct linux_alarm_args *args)
{
struct itimerval it, old_it;
u_int secs;
- int error;
+ int error __diagused;
secs = args->secs;
/*
@@ -248,261 +230,6 @@ linux_brk(struct thread *td, struct linux_brk_args *args)
return (0);
}
-#if defined(__i386__)
-/* XXX: what about amd64/linux32? */
-
-int
-linux_uselib(struct thread *td, struct linux_uselib_args *args)
-{
- struct nameidata ni;
- struct vnode *vp;
- struct exec *a_out;
- vm_map_t map;
- vm_map_entry_t entry;
- struct vattr attr;
- vm_offset_t vmaddr;
- unsigned long file_offset;
- unsigned long bss_size;
- char *library;
- ssize_t aresid;
- int error;
- bool locked, opened, textset;
-
- a_out = NULL;
- vp = NULL;
- locked = false;
- textset = false;
- opened = false;
-
- if (!LUSECONVPATH(td)) {
- NDINIT(&ni, LOOKUP, ISOPEN | FOLLOW | LOCKLEAF | AUDITVNODE1,
- UIO_USERSPACE, args->library);
- error = namei(&ni);
- } else {
- LCONVPATHEXIST(args->library, &library);
- NDINIT(&ni, LOOKUP, ISOPEN | FOLLOW | LOCKLEAF | AUDITVNODE1,
- UIO_SYSSPACE, library);
- error = namei(&ni);
- LFREEPATH(library);
- }
- if (error)
- goto cleanup;
-
- vp = ni.ni_vp;
- NDFREE(&ni, NDF_ONLY_PNBUF);
-
- /*
- * From here on down, we have a locked vnode that must be unlocked.
- * XXX: The code below largely duplicates exec_check_permissions().
- */
- locked = true;
-
- /* Executable? */
- error = VOP_GETATTR(vp, &attr, td->td_ucred);
- if (error)
- goto cleanup;
-
- if ((vp->v_mount->mnt_flag & MNT_NOEXEC) ||
- ((attr.va_mode & 0111) == 0) || (attr.va_type != VREG)) {
- /* EACCESS is what exec(2) returns. */
- error = ENOEXEC;
- goto cleanup;
- }
-
- /* Sensible size? */
- if (attr.va_size == 0) {
- error = ENOEXEC;
- goto cleanup;
- }
-
- /* Can we access it? */
- error = VOP_ACCESS(vp, VEXEC, td->td_ucred, td);
- if (error)
- goto cleanup;
-
- /*
- * XXX: This should use vn_open() so that it is properly authorized,
- * and to reduce code redundancy all over the place here.
- * XXX: Not really, it duplicates far more of exec_check_permissions()
- * than vn_open().
- */
-#ifdef MAC
- error = mac_vnode_check_open(td->td_ucred, vp, VREAD);
- if (error)
- goto cleanup;
-#endif
- error = VOP_OPEN(vp, FREAD, td->td_ucred, td, NULL);
- if (error)
- goto cleanup;
- opened = true;
-
- /* Pull in executable header into exec_map */
- error = vm_mmap(exec_map, (vm_offset_t *)&a_out, PAGE_SIZE,
- VM_PROT_READ, VM_PROT_READ, 0, OBJT_VNODE, vp, 0);
- if (error)
- goto cleanup;
-
- /* Is it a Linux binary ? */
- if (((a_out->a_magic >> 16) & 0xff) != 0x64) {
- error = ENOEXEC;
- goto cleanup;
- }
-
- /*
- * While we are here, we should REALLY do some more checks
- */
-
- /* Set file/virtual offset based on a.out variant. */
- switch ((int)(a_out->a_magic & 0xffff)) {
- case 0413: /* ZMAGIC */
- file_offset = 1024;
- break;
- case 0314: /* QMAGIC */
- file_offset = 0;
- break;
- default:
- error = ENOEXEC;
- goto cleanup;
- }
-
- bss_size = round_page(a_out->a_bss);
-
- /* Check various fields in header for validity/bounds. */
- if (a_out->a_text & PAGE_MASK || a_out->a_data & PAGE_MASK) {
- error = ENOEXEC;
- goto cleanup;
- }
-
- /* text + data can't exceed file size */
- if (a_out->a_data + a_out->a_text > attr.va_size) {
- error = EFAULT;
- goto cleanup;
- }
-
- /*
- * text/data/bss must not exceed limits
- * XXX - this is not complete. it should check current usage PLUS
- * the resources needed by this library.
- */
- PROC_LOCK(td->td_proc);
- if (a_out->a_text > maxtsiz ||
- a_out->a_data + bss_size > lim_cur_proc(td->td_proc, RLIMIT_DATA) ||
- racct_set(td->td_proc, RACCT_DATA, a_out->a_data +
- bss_size) != 0) {
- PROC_UNLOCK(td->td_proc);
- error = ENOMEM;
- goto cleanup;
- }
- PROC_UNLOCK(td->td_proc);
-
- /*
- * Prevent more writers.
- */
- error = VOP_SET_TEXT(vp);
- if (error != 0)
- goto cleanup;
- textset = true;
-
- /*
- * Lock no longer needed
- */
- locked = false;
- VOP_UNLOCK(vp);
-
- /*
- * Check if file_offset page aligned. Currently we cannot handle
- * misalinged file offsets, and so we read in the entire image
- * (what a waste).
- */
- if (file_offset & PAGE_MASK) {
- /* Map text+data read/write/execute */
-
- /* a_entry is the load address and is page aligned */
- vmaddr = trunc_page(a_out->a_entry);
-
- /* get anon user mapping, read+write+execute */
- error = vm_map_find(&td->td_proc->p_vmspace->vm_map, NULL, 0,
- &vmaddr, a_out->a_text + a_out->a_data, 0, VMFS_NO_SPACE,
- VM_PROT_ALL, VM_PROT_ALL, 0);
- if (error)
- goto cleanup;
-
- error = vn_rdwr(UIO_READ, vp, (void *)vmaddr, file_offset,
- a_out->a_text + a_out->a_data, UIO_USERSPACE, 0,
- td->td_ucred, NOCRED, &aresid, td);
- if (error != 0)
- goto cleanup;
- if (aresid != 0) {
- error = ENOEXEC;
- goto cleanup;
- }
- } else {
- /*
- * for QMAGIC, a_entry is 20 bytes beyond the load address
- * to skip the executable header
- */
- vmaddr = trunc_page(a_out->a_entry);
-
- /*
- * Map it all into the process's space as a single
- * copy-on-write "data" segment.
- */
- map = &td->td_proc->p_vmspace->vm_map;
- error = vm_mmap(map, &vmaddr,
- a_out->a_text + a_out->a_data, VM_PROT_ALL, VM_PROT_ALL,
- MAP_PRIVATE | MAP_FIXED, OBJT_VNODE, vp, file_offset);
- if (error)
- goto cleanup;
- vm_map_lock(map);
- if (!vm_map_lookup_entry(map, vmaddr, &entry)) {
- vm_map_unlock(map);
- error = EDOOFUS;
- goto cleanup;
- }
- entry->eflags |= MAP_ENTRY_VN_EXEC;
- vm_map_unlock(map);
- textset = false;
- }
-
- if (bss_size != 0) {
- /* Calculate BSS start address */
- vmaddr = trunc_page(a_out->a_entry) + a_out->a_text +
- a_out->a_data;
-
- /* allocate some 'anon' space */
- error = vm_map_find(&td->td_proc->p_vmspace->vm_map, NULL, 0,
- &vmaddr, bss_size, 0, VMFS_NO_SPACE, VM_PROT_ALL,
- VM_PROT_ALL, 0);
- if (error)
- goto cleanup;
- }
-
-cleanup:
- if (opened) {
- if (locked)
- VOP_UNLOCK(vp);
- locked = false;
- VOP_CLOSE(vp, FREAD, td->td_ucred, td);
- }
- if (textset) {
- if (!locked) {
- locked = true;
- VOP_LOCK(vp, LK_SHARED | LK_RETRY);
- }
- VOP_UNSET_TEXT_CHECKED(vp);
- }
- if (locked)
- VOP_UNLOCK(vp);
-
- /* Release the temporary mapping. */
- if (a_out)
- kmap_free_wakeup(exec_map, (vm_offset_t)a_out, PAGE_SIZE);
-
- return (error);
-}
-
-#endif /* __i386__ */
-
#ifdef LINUX_LEGACY_SYSCALLS
int
linux_select(struct thread *td, struct linux_select_args *args)
@@ -622,6 +349,39 @@ linux_msync(struct thread *td, struct linux_msync_args *args)
args->fl & ~LINUX_MS_SYNC));
}
+int
+linux_mprotect(struct thread *td, struct linux_mprotect_args *uap)
+{
+
+ return (linux_mprotect_common(td, PTROUT(uap->addr), uap->len,
+ uap->prot));
+}
+
+int
+linux_madvise(struct thread *td, struct linux_madvise_args *uap)
+{
+
+ return (linux_madvise_common(td, PTROUT(uap->addr), uap->len,
+ uap->behav));
+}
+
+int
+linux_mmap2(struct thread *td, struct linux_mmap2_args *uap)
+{
+#if defined(LINUX_ARCHWANT_MMAP2PGOFF)
+ /*
+ * For architectures with sizeof (off_t) < sizeof (loff_t) mmap is
+ * implemented with mmap2 syscall and the offset is represented in
+ * multiples of page size.
+ */
+ return (linux_mmap_common(td, PTROUT(uap->addr), uap->len, uap->prot,
+ uap->flags, uap->fd, (uint64_t)(uint32_t)uap->pgoff * PAGE_SIZE));
+#else
+ return (linux_mmap_common(td, PTROUT(uap->addr), uap->len, uap->prot,
+ uap->flags, uap->fd, uap->pgoff));
+#endif
+}
+
#ifdef LINUX_LEGACY_SYSCALLS
int
linux_time(struct thread *td, struct linux_time_args *args)
@@ -656,7 +416,7 @@ struct l_times_argv {
#define CONVOTCK(r) (r.tv_sec * CLK_TCK + r.tv_usec / (1000000 / CLK_TCK))
#define CONVNTCK(r) (r.tv_sec * stclohz + r.tv_usec / (1000000 / stclohz))
-#define CONVTCK(r) (linux_kernver(td) >= LINUX_KERNVER_2004000 ? \
+#define CONVTCK(r) (linux_kernver(td) >= LINUX_KERNVER(2,4,0) ? \
CONVNTCK(r) : CONVOTCK(r))
int
@@ -720,6 +480,11 @@ linux_newuname(struct thread *td, struct linux_newuname_args *args)
* the string returned by getauxval(AT_PLATFORM) needs
* to remain "i686", though.
*/
+#if defined(COMPAT_LINUX32)
+ if (linux32_emulate_i386)
+ strlcpy(utsname.machine, "i686", LINUX_MAX_UTSNAME);
+ else
+#endif
strlcpy(utsname.machine, "x86_64", LINUX_MAX_UTSNAME);
#elif defined(__aarch64__)
strlcpy(utsname.machine, "aarch64", LINUX_MAX_UTSNAME);
@@ -741,7 +506,6 @@ linux_utime(struct thread *td, struct linux_utime_args *args)
{
struct timeval tv[2], *tvp;
struct l_utimbuf lut;
- char *fname;
int error;
if (args->times) {
@@ -755,16 +519,8 @@ linux_utime(struct thread *td, struct linux_utime_args *args)
} else
tvp = NULL;
- if (!LUSECONVPATH(td)) {
- error = kern_utimesat(td, AT_FDCWD, args->fname, UIO_USERSPACE,
- tvp, UIO_SYSSPACE);
- } else {
- LCONVPATHEXIST(args->fname, &fname);
- error = kern_utimesat(td, AT_FDCWD, fname, UIO_SYSSPACE, tvp,
- UIO_SYSSPACE);
- LFREEPATH(fname);
- }
- return (error);
+ return (kern_utimesat(td, AT_FDCWD, args->fname, UIO_USERSPACE,
+ tvp, UIO_SYSSPACE));
}
#endif
@@ -774,7 +530,6 @@ linux_utimes(struct thread *td, struct linux_utimes_args *args)
{
l_timeval ltv[2];
struct timeval tv[2], *tvp = NULL;
- char *fname;
int error;
if (args->tptr != NULL) {
@@ -787,16 +542,8 @@ linux_utimes(struct thread *td, struct linux_utimes_args *args)
tvp = tv;
}
- if (!LUSECONVPATH(td)) {
- error = kern_utimesat(td, AT_FDCWD, args->fname, UIO_USERSPACE,
- tvp, UIO_SYSSPACE);
- } else {
- LCONVPATHEXIST(args->fname, &fname);
- error = kern_utimesat(td, AT_FDCWD, fname, UIO_SYSSPACE,
- tvp, UIO_SYSSPACE);
- LFREEPATH(fname);
- }
- return (error);
+ return (kern_utimesat(td, AT_FDCWD, args->fname, UIO_USERSPACE,
+ tvp, UIO_SYSSPACE));
}
#endif
@@ -829,8 +576,7 @@ static int
linux_common_utimensat(struct thread *td, int ldfd, const char *pathname,
struct timespec *timesp, int lflags)
{
- char *path = NULL;
- int error, dfd, flags = 0;
+ int dfd, flags = 0;
dfd = (ldfd == LINUX_AT_FDCWD) ? AT_FDCWD : ldfd;
@@ -851,27 +597,14 @@ linux_common_utimensat(struct thread *td, int ldfd, const char *pathname,
if (lflags & LINUX_AT_EMPTY_PATH)
flags |= AT_EMPTY_PATH;
- if (!LUSECONVPATH(td)) {
- if (pathname != NULL) {
- return (kern_utimensat(td, dfd, pathname,
- UIO_USERSPACE, timesp, UIO_SYSSPACE, flags));
- }
- }
-
if (pathname != NULL)
- LCONVPATHEXIST_AT(pathname, &path, dfd);
- else if (lflags != 0)
- return (EINVAL);
+ return (kern_utimensat(td, dfd, pathname,
+ UIO_USERSPACE, timesp, UIO_SYSSPACE, flags));
- if (path == NULL)
- error = kern_futimens(td, dfd, timesp, UIO_SYSSPACE);
- else {
- error = kern_utimensat(td, dfd, path, UIO_SYSSPACE, timesp,
- UIO_SYSSPACE, flags);
- LFREEPATH(path);
- }
+ if (lflags != 0)
+ return (EINVAL);
- return (error);
+ return (kern_futimens(td, dfd, timesp, UIO_SYSSPACE));
}
int
@@ -905,6 +638,9 @@ static int
linux_utimensat_lts64_to_ts(struct l_timespec64 *l_times, struct timespec *times)
{
+ /* Zero out the padding in compat mode. */
+ l_times->tv_nsec &= 0xFFFFFFFFUL;
+
if (l_times->tv_nsec != LINUX_UTIME_OMIT &&
l_times->tv_nsec != LINUX_UTIME_NOW &&
(l_times->tv_nsec < 0 || l_times->tv_nsec > 999999999))
@@ -959,7 +695,6 @@ linux_futimesat(struct thread *td, struct linux_futimesat_args *args)
{
l_timeval ltv[2];
struct timeval tv[2], *tvp = NULL;
- char *fname;
int error, dfd;
dfd = (args->dfd == LINUX_AT_FDCWD) ? AT_FDCWD : args->dfd;
@@ -974,49 +709,24 @@ linux_futimesat(struct thread *td, struct linux_futimesat_args *args)
tvp = tv;
}
- if (!LUSECONVPATH(td)) {
- error = kern_utimesat(td, dfd, args->filename, UIO_USERSPACE,
- tvp, UIO_SYSSPACE);
- } else {
- LCONVPATHEXIST_AT(args->filename, &fname, dfd);
- error = kern_utimesat(td, dfd, fname, UIO_SYSSPACE,
- tvp, UIO_SYSSPACE);
- LFREEPATH(fname);
- }
- return (error);
+ return (kern_utimesat(td, dfd, args->filename, UIO_USERSPACE,
+ tvp, UIO_SYSSPACE));
}
#endif
static int
-linux_common_wait(struct thread *td, int pid, int *statusp,
- int options, struct __wrusage *wrup)
+linux_common_wait(struct thread *td, idtype_t idtype, int id, int *statusp,
+ int options, void *rup, l_siginfo_t *infop)
{
+ l_siginfo_t lsi;
siginfo_t siginfo;
- idtype_t idtype;
- id_t id;
- int error, status, tmpstat;
+ struct __wrusage wru;
+ int error, status, tmpstat, sig;
- if (pid == WAIT_ANY) {
- idtype = P_ALL;
- id = 0;
- } else if (pid < 0) {
- idtype = P_PGID;
- id = (id_t)-pid;
- } else {
- idtype = P_PID;
- id = (id_t)pid;
- }
+ error = kern_wait6(td, idtype, id, &status, options,
+ rup != NULL ? &wru : NULL, &siginfo);
- /*
- * For backward compatibility we implicitly add flags WEXITED
- * and WTRAPPED here.
- */
- options |= WEXITED | WTRAPPED;
- error = kern_wait6(td, idtype, id, &status, options, wrup, &siginfo);
- if (error)
- return (error);
-
- if (statusp) {
+ if (error == 0 && statusp) {
tmpstat = status & 0xffff;
if (WIFSIGNALED(tmpstat)) {
tmpstat = (tmpstat & 0xffffff80) |
@@ -1035,6 +745,13 @@ linux_common_wait(struct thread *td, int pid, int *statusp,
}
error = copyout(&tmpstat, statusp, sizeof(int));
}
+ if (error == 0 && rup != NULL)
+ error = linux_copyout_rusage(&wru.wru_self, rup);
+ if (error == 0 && infop != NULL && td->td_retval[0] != 0) {
+ sig = bsd_to_linux_signal(siginfo.si_signo);
+ siginfo_to_lsiginfo(&siginfo, &lsi, sig);
+ error = copyout(&lsi, infop, sizeof(lsi));
+ }
return (error);
}
@@ -1043,12 +760,12 @@ linux_common_wait(struct thread *td, int pid, int *statusp,
int
linux_waitpid(struct thread *td, struct linux_waitpid_args *args)
{
- struct linux_wait4_args wait4_args;
-
- wait4_args.pid = args->pid;
- wait4_args.status = args->status;
- wait4_args.options = args->options;
- wait4_args.rusage = NULL;
+ struct linux_wait4_args wait4_args = {
+ .pid = args->pid,
+ .status = args->status,
+ .options = args->options,
+ .rusage = NULL,
+ };
return (linux_wait4(td, &wait4_args));
}
@@ -1057,46 +774,63 @@ linux_waitpid(struct thread *td, struct linux_waitpid_args *args)
int
linux_wait4(struct thread *td, struct linux_wait4_args *args)
{
- int error, options;
- struct __wrusage wru, *wrup;
+ struct proc *p;
+ int options, id, idtype;
if (args->options & ~(LINUX_WUNTRACED | LINUX_WNOHANG |
LINUX_WCONTINUED | __WCLONE | __WNOTHREAD | __WALL))
return (EINVAL);
- options = WEXITED;
+ /* -INT_MIN is not defined. */
+ if (args->pid == INT_MIN)
+ return (ESRCH);
+
+ options = 0;
linux_to_bsd_waitopts(args->options, &options);
- if (args->rusage != NULL)
- wrup = &wru;
- else
- wrup = NULL;
- error = linux_common_wait(td, args->pid, args->status, options, wrup);
- if (error != 0)
- return (error);
- if (args->rusage != NULL)
- error = linux_copyout_rusage(&wru.wru_self, args->rusage);
- return (error);
+ /*
+ * For backward compatibility we implicitly add flags WEXITED
+ * and WTRAPPED here.
+ */
+ options |= WEXITED | WTRAPPED;
+
+ if (args->pid == WAIT_ANY) {
+ idtype = P_ALL;
+ id = 0;
+ } else if (args->pid < 0) {
+ idtype = P_PGID;
+ id = (id_t)-args->pid;
+ } else if (args->pid == 0) {
+ idtype = P_PGID;
+ p = td->td_proc;
+ PROC_LOCK(p);
+ id = p->p_pgid;
+ PROC_UNLOCK(p);
+ } else {
+ idtype = P_PID;
+ id = (id_t)args->pid;
+ }
+
+ return (linux_common_wait(td, idtype, id, args->status, options,
+ args->rusage, NULL));
}
int
linux_waitid(struct thread *td, struct linux_waitid_args *args)
{
- int status, options, sig;
- struct __wrusage wru;
- siginfo_t siginfo;
- l_siginfo_t lsi;
idtype_t idtype;
- int error;
+ int error, options;
+ struct proc *p;
+ pid_t id;
+
+ if (args->options & ~(LINUX_WNOHANG | LINUX_WNOWAIT | LINUX_WEXITED |
+ LINUX_WSTOPPED | LINUX_WCONTINUED | __WCLONE | __WNOTHREAD | __WALL))
+ return (EINVAL);
options = 0;
linux_to_bsd_waitopts(args->options, &options);
- if (options & ~(WNOHANG | WNOWAIT | WEXITED | WUNTRACED | WCONTINUED))
- return (EINVAL);
- if (!(options & (WEXITED | WUNTRACED | WCONTINUED)))
- return (EINVAL);
-
+ id = args->id;
switch (args->idtype) {
case LINUX_P_ALL:
idtype = P_ALL;
@@ -1107,32 +841,24 @@ linux_waitid(struct thread *td, struct linux_waitid_args *args)
idtype = P_PID;
break;
case LINUX_P_PGID:
- if (args->id <= 0)
+ if (linux_kernver(td) >= LINUX_KERNVER(5,4,0) && args->id == 0) {
+ p = td->td_proc;
+ PROC_LOCK(p);
+ id = p->p_pgid;
+ PROC_UNLOCK(p);
+ } else if (args->id <= 0)
return (EINVAL);
idtype = P_PGID;
break;
+ case LINUX_P_PIDFD:
+ LINUX_RATELIMIT_MSG("unsupported waitid P_PIDFD idtype");
+ return (ENOSYS);
default:
return (EINVAL);
}
- error = kern_wait6(td, idtype, args->id, &status, options,
- &wru, &siginfo);
- if (error != 0)
- return (error);
- if (args->rusage != NULL) {
- error = linux_copyout_rusage(&wru.wru_children,
- args->rusage);
- if (error != 0)
- return (error);
- }
- if (args->info != NULL) {
- bzero(&lsi, sizeof(lsi));
- if (td->td_retval[0] != 0) {
- sig = bsd_to_linux_signal(siginfo.si_signo);
- siginfo_to_lsiginfo(&siginfo, &lsi, sig);
- }
- error = copyout(&lsi, args->info, sizeof(lsi));
- }
+ error = linux_common_wait(td, idtype, id, NULL, options,
+ args->rusage, args->info);
td->td_retval[0] = 0;
return (error);
@@ -1142,31 +868,19 @@ linux_waitid(struct thread *td, struct linux_waitid_args *args)
int
linux_mknod(struct thread *td, struct linux_mknod_args *args)
{
- char *path;
int error;
- enum uio_seg seg;
- bool convpath;
-
- convpath = LUSECONVPATH(td);
- if (!convpath) {
- path = args->path;
- seg = UIO_USERSPACE;
- } else {
- LCONVPATHCREAT(args->path, &path);
- seg = UIO_SYSSPACE;
- }
switch (args->mode & S_IFMT) {
case S_IFIFO:
case S_IFSOCK:
- error = kern_mkfifoat(td, AT_FDCWD, path, seg,
+ error = kern_mkfifoat(td, AT_FDCWD, args->path, UIO_USERSPACE,
args->mode);
break;
case S_IFCHR:
case S_IFBLK:
- error = kern_mknodat(td, AT_FDCWD, path, seg,
- args->mode, args->dev);
+ error = kern_mknodat(td, AT_FDCWD, args->path, UIO_USERSPACE,
+ args->mode, linux_decode_dev(args->dev));
break;
case S_IFDIR:
@@ -1177,7 +891,7 @@ linux_mknod(struct thread *td, struct linux_mknod_args *args)
args->mode |= S_IFREG;
/* FALLTHROUGH */
case S_IFREG:
- error = kern_openat(td, AT_FDCWD, path, seg,
+ error = kern_openat(td, AT_FDCWD, args->path, UIO_USERSPACE,
O_WRONLY | O_CREAT | O_TRUNC, args->mode);
if (error == 0)
kern_close(td, td->td_retval[0]);
@@ -1187,8 +901,6 @@ linux_mknod(struct thread *td, struct linux_mknod_args *args)
error = EINVAL;
break;
}
- if (convpath)
- LFREEPATH(path);
return (error);
}
#endif
@@ -1196,32 +908,21 @@ linux_mknod(struct thread *td, struct linux_mknod_args *args)
int
linux_mknodat(struct thread *td, struct linux_mknodat_args *args)
{
- char *path;
int error, dfd;
- enum uio_seg seg;
- bool convpath;
dfd = (args->dfd == LINUX_AT_FDCWD) ? AT_FDCWD : args->dfd;
- convpath = LUSECONVPATH(td);
- if (!convpath) {
- path = __DECONST(char *, args->filename);
- seg = UIO_USERSPACE;
- } else {
- LCONVPATHCREAT_AT(args->filename, &path, dfd);
- seg = UIO_SYSSPACE;
- }
-
switch (args->mode & S_IFMT) {
case S_IFIFO:
case S_IFSOCK:
- error = kern_mkfifoat(td, dfd, path, seg, args->mode);
+ error = kern_mkfifoat(td, dfd, args->filename, UIO_USERSPACE,
+ args->mode);
break;
case S_IFCHR:
case S_IFBLK:
- error = kern_mknodat(td, dfd, path, seg, args->mode,
- args->dev);
+ error = kern_mknodat(td, dfd, args->filename, UIO_USERSPACE,
+ args->mode, linux_decode_dev(args->dev));
break;
case S_IFDIR:
@@ -1232,7 +933,7 @@ linux_mknodat(struct thread *td, struct linux_mknodat_args *args)
args->mode |= S_IFREG;
/* FALLTHROUGH */
case S_IFREG:
- error = kern_openat(td, dfd, path, seg,
+ error = kern_openat(td, dfd, args->filename, UIO_USERSPACE,
O_WRONLY | O_CREAT | O_TRUNC, args->mode);
if (error == 0)
kern_close(td, td->td_retval[0]);
@@ -1242,8 +943,6 @@ linux_mknodat(struct thread *td, struct linux_mknodat_args *args)
error = EINVAL;
break;
}
- if (convpath)
- LFREEPATH(path);
return (error);
}
@@ -1329,31 +1028,24 @@ linux_nice(struct thread *td, struct linux_nice_args *args)
int
linux_setgroups(struct thread *td, struct linux_setgroups_args *args)
{
+ const int ngrp = args->gidsetsize;
struct ucred *newcred, *oldcred;
l_gid_t *linux_gidset;
- gid_t *bsd_gidset;
- int ngrp, error;
+ int error;
struct proc *p;
- ngrp = args->gidsetsize;
- if (ngrp < 0 || ngrp >= ngroups_max + 1)
+ if (ngrp < 0 || ngrp > ngroups_max)
return (EINVAL);
linux_gidset = malloc(ngrp * sizeof(*linux_gidset), M_LINUX, M_WAITOK);
error = copyin(args->grouplist, linux_gidset, ngrp * sizeof(l_gid_t));
if (error)
goto out;
+
newcred = crget();
- crextend(newcred, ngrp + 1);
+ crextend(newcred, ngrp);
p = td->td_proc;
PROC_LOCK(p);
- oldcred = p->p_ucred;
- crcopy(newcred, oldcred);
-
- /*
- * cr_groups[0] holds egid. Setting the whole set from
- * the supplied set will cause egid to be changed too.
- * Keep cr_groups[0] unchanged to prevent that.
- */
+ oldcred = crcopysafe(p, newcred);
if ((error = priv_check_cred(oldcred, PRIV_CRED_SETGROUPS)) != 0) {
PROC_UNLOCK(p);
@@ -1361,17 +1053,10 @@ linux_setgroups(struct thread *td, struct linux_setgroups_args *args)
goto out;
}
- if (ngrp > 0) {
- newcred->cr_ngroups = ngrp + 1;
-
- bsd_gidset = newcred->cr_groups;
- ngrp--;
- while (ngrp >= 0) {
- bsd_gidset[ngrp + 1] = linux_gidset[ngrp];
- ngrp--;
- }
- } else
- newcred->cr_ngroups = 1;
+ newcred->cr_ngroups = ngrp;
+ for (int i = 0; i < ngrp; i++)
+ newcred->cr_groups[i] = linux_gidset[i];
+ newcred->cr_flags |= CRED_FLAG_GROUPSET;
setsugid(p);
proc_set_cred(p, newcred);
@@ -1386,40 +1071,29 @@ out:
int
linux_getgroups(struct thread *td, struct linux_getgroups_args *args)
{
- struct ucred *cred;
+ const struct ucred *const cred = td->td_ucred;
l_gid_t *linux_gidset;
- gid_t *bsd_gidset;
- int bsd_gidsetsz, ngrp, error;
-
- cred = td->td_ucred;
- bsd_gidset = cred->cr_groups;
- bsd_gidsetsz = cred->cr_ngroups - 1;
+ int ngrp, error;
- /*
- * cr_groups[0] holds egid. Returning the whole set
- * here will cause a duplicate. Exclude cr_groups[0]
- * to prevent that.
- */
+ ngrp = args->gidsetsize;
- if ((ngrp = args->gidsetsize) == 0) {
- td->td_retval[0] = bsd_gidsetsz;
+ if (ngrp == 0) {
+ td->td_retval[0] = cred->cr_ngroups;
return (0);
}
-
- if (ngrp < bsd_gidsetsz)
+ if (ngrp < cred->cr_ngroups)
return (EINVAL);
- ngrp = 0;
- linux_gidset = malloc(bsd_gidsetsz * sizeof(*linux_gidset),
- M_LINUX, M_WAITOK);
- while (ngrp < bsd_gidsetsz) {
- linux_gidset[ngrp] = bsd_gidset[ngrp + 1];
- ngrp++;
- }
+ ngrp = cred->cr_ngroups;
+
+ linux_gidset = malloc(ngrp * sizeof(*linux_gidset), M_LINUX, M_WAITOK);
+ for (int i = 0; i < ngrp; ++i)
+ linux_gidset[i] = cred->cr_groups[i];
error = copyout(linux_gidset, args->grouplist, ngrp * sizeof(l_gid_t));
free(linux_gidset, M_LINUX);
- if (error)
+
+ if (error != 0)
return (error);
td->td_retval[0] = ngrp;
@@ -1427,16 +1101,16 @@ linux_getgroups(struct thread *td, struct linux_getgroups_args *args)
}
static bool
-linux_get_dummy_limit(l_uint resource, struct rlimit *rlim)
+linux_get_dummy_limit(struct thread *td, l_uint resource, struct rlimit *rlim)
{
+ ssize_t size;
+ int res, error;
if (linux_dummy_rlimits == 0)
return (false);
switch (resource) {
case LINUX_RLIMIT_LOCKS:
- case LINUX_RLIMIT_SIGPENDING:
- case LINUX_RLIMIT_MSGQUEUE:
case LINUX_RLIMIT_RTTIME:
rlim->rlim_cur = LINUX_RLIM_INFINITY;
rlim->rlim_max = LINUX_RLIM_INFINITY;
@@ -1446,6 +1120,23 @@ linux_get_dummy_limit(l_uint resource, struct rlimit *rlim)
rlim->rlim_cur = 0;
rlim->rlim_max = 0;
return (true);
+ case LINUX_RLIMIT_SIGPENDING:
+ error = kernel_sysctlbyname(td,
+ "kern.sigqueue.max_pending_per_proc",
+ &res, &size, 0, 0, 0, 0);
+ if (error != 0)
+ return (false);
+ rlim->rlim_cur = res;
+ rlim->rlim_max = res;
+ return (true);
+ case LINUX_RLIMIT_MSGQUEUE:
+ error = kernel_sysctlbyname(td,
+ "kern.ipc.msgmnb", &res, &size, 0, 0, 0, 0);
+ if (error != 0)
+ return (false);
+ rlim->rlim_cur = res;
+ rlim->rlim_max = res;
+ return (true);
default:
return (false);
}
@@ -1483,7 +1174,7 @@ linux_old_getrlimit(struct thread *td, struct linux_old_getrlimit_args *args)
struct rlimit bsd_rlim;
u_int which;
- if (linux_get_dummy_limit(args->resource, &bsd_rlim)) {
+ if (linux_get_dummy_limit(td, args->resource, &bsd_rlim)) {
rlim.rlim_cur = bsd_rlim.rlim_cur;
rlim.rlim_max = bsd_rlim.rlim_max;
return (copyout(&rlim, args->rlim, sizeof(rlim)));
@@ -1524,7 +1215,7 @@ linux_getrlimit(struct thread *td, struct linux_getrlimit_args *args)
struct rlimit bsd_rlim;
u_int which;
- if (linux_get_dummy_limit(args->resource, &bsd_rlim)) {
+ if (linux_get_dummy_limit(td, args->resource, &bsd_rlim)) {
rlim.rlim_cur = bsd_rlim.rlim_cur;
rlim.rlim_max = bsd_rlim.rlim_max;
return (copyout(&rlim, args->rlim, sizeof(rlim)));
@@ -1808,13 +1499,6 @@ linux_getsid(struct thread *td, struct linux_getsid_args *args)
}
int
-linux_nosys(struct thread *td, struct nosys_args *ignore)
-{
-
- return (ENOSYS);
-}
-
-int
linux_getpriority(struct thread *td, struct linux_getpriority_args *args)
{
int error;
@@ -2110,6 +1794,14 @@ linux_prctl(struct thread *td, struct linux_prctl_args *args)
#endif
error = EINVAL;
break;
+ case LINUX_PR_SET_CHILD_SUBREAPER:
+ if (args->arg2 == 0) {
+ return (kern_procctl(td, P_PID, 0, PROC_REAP_RELEASE,
+ NULL));
+ }
+
+ return (kern_procctl(td, P_PID, 0, PROC_REAP_ACQUIRE,
+ NULL));
case LINUX_PR_SET_NO_NEW_PRIVS:
arg = args->arg2 == 1 ?
PROC_NO_NEW_PRIVS_ENABLE : PROC_NO_NEW_PRIVS_DISABLE;
@@ -2238,23 +1930,29 @@ int
linux_sched_getaffinity(struct thread *td,
struct linux_sched_getaffinity_args *args)
{
- int error;
struct thread *tdt;
-
- if (args->len < sizeof(cpuset_t))
- return (EINVAL);
+ cpuset_t *mask;
+ size_t size;
+ int error;
+ id_t tid;
tdt = linux_tdfind(td, args->pid, -1);
if (tdt == NULL)
return (ESRCH);
-
+ tid = tdt->td_tid;
PROC_UNLOCK(tdt->td_proc);
+ mask = malloc(sizeof(cpuset_t), M_LINUX, M_WAITOK | M_ZERO);
+ size = min(args->len, sizeof(cpuset_t));
error = kern_cpuset_getaffinity(td, CPU_LEVEL_WHICH, CPU_WHICH_TID,
- tdt->td_tid, sizeof(cpuset_t), (cpuset_t *)args->user_mask_ptr);
+ tid, size, mask);
+ if (error == ERANGE)
+ error = EINVAL;
+ if (error == 0)
+ error = copyout(mask, args->user_mask_ptr, size);
if (error == 0)
- td->td_retval[0] = sizeof(cpuset_t);
-
+ td->td_retval[0] = size;
+ free(mask, M_LINUX);
return (error);
}
@@ -2266,18 +1964,34 @@ linux_sched_setaffinity(struct thread *td,
struct linux_sched_setaffinity_args *args)
{
struct thread *tdt;
-
- if (args->len < sizeof(cpuset_t))
- return (EINVAL);
+ cpuset_t *mask;
+ int cpu, error;
+ size_t len;
+ id_t tid;
tdt = linux_tdfind(td, args->pid, -1);
if (tdt == NULL)
return (ESRCH);
-
+ tid = tdt->td_tid;
PROC_UNLOCK(tdt->td_proc);
- return (kern_cpuset_setaffinity(td, CPU_LEVEL_WHICH, CPU_WHICH_TID,
- tdt->td_tid, sizeof(cpuset_t), (cpuset_t *) args->user_mask_ptr));
+ len = min(args->len, sizeof(cpuset_t));
+ mask = malloc(sizeof(cpuset_t), M_TEMP, M_WAITOK | M_ZERO);
+ error = copyin(args->user_mask_ptr, mask, len);
+ if (error != 0)
+ goto out;
+ /* Linux ignore high bits */
+ CPU_FOREACH_ISSET(cpu, mask)
+ if (cpu > mp_maxid)
+ CPU_CLR(cpu, mask);
+
+ error = kern_cpuset_setaffinity(td, CPU_LEVEL_WHICH, CPU_WHICH_TID,
+ tid, mask);
+ if (error == EDEADLK)
+ error = EINVAL;
+out:
+ free(mask, M_TEMP);
+ return (error);
}
struct linux_rlimit64 {
@@ -2296,7 +2010,7 @@ linux_prlimit64(struct thread *td, struct linux_prlimit64_args *args)
int error;
if (args->new == NULL && args->old != NULL) {
- if (linux_get_dummy_limit(args->resource, &rlim)) {
+ if (linux_get_dummy_limit(td, args->resource, &rlim)) {
lrlim.rlim_cur = rlim.rlim_cur;
lrlim.rlim_max = rlim.rlim_max;
return (copyout(&lrlim, args->old, sizeof(lrlim)));
@@ -2362,15 +2076,11 @@ linux_prlimit64(struct thread *td, struct linux_prlimit64_args *args)
int
linux_pselect6(struct thread *td, struct linux_pselect6_args *args)
{
- struct l_timespec lts;
struct timespec ts, *tsp;
int error;
if (args->tsp != NULL) {
- error = copyin(args->tsp, &lts, sizeof(lts));
- if (error != 0)
- return (error);
- error = linux_to_native_timespec(&ts, &lts);
+ error = linux_get_timespec(&ts, args->tsp);
if (error != 0)
return (error);
tsp = &ts;
@@ -2379,14 +2089,9 @@ linux_pselect6(struct thread *td, struct linux_pselect6_args *args)
error = linux_common_pselect6(td, args->nfds, args->readfds,
args->writefds, args->exceptfds, tsp, args->sig);
- if (error != 0)
- return (error);
- if (args->tsp != NULL) {
- error = native_to_linux_timespec(&lts, tsp);
- if (error == 0)
- error = copyout(&lts, args->tsp, sizeof(lts));
- }
+ if (args->tsp != NULL)
+ linux_put_timespec(&ts, args->tsp);
return (error);
}
@@ -2397,7 +2102,6 @@ linux_common_pselect6(struct thread *td, l_int nfds, l_fd_set *readfds,
{
struct timeval utv, tv0, tv1, *tvp;
struct l_pselect6arg lpse6;
- l_sigset_t l_ss;
sigset_t *ssp;
sigset_t ss;
int error;
@@ -2407,16 +2111,10 @@ linux_common_pselect6(struct thread *td, l_int nfds, l_fd_set *readfds,
error = copyin(sig, &lpse6, sizeof(lpse6));
if (error != 0)
return (error);
- if (lpse6.ss_len != sizeof(l_ss))
- return (EINVAL);
- if (lpse6.ss != 0) {
- error = copyin(PTRIN(lpse6.ss), &l_ss,
- sizeof(l_ss));
- if (error != 0)
- return (error);
- linux_to_bsd_sigset(&l_ss, &ss);
- ssp = &ss;
- }
+ error = linux_copyin_sigset(td, PTRIN(lpse6.ss),
+ lpse6.ss_len, &ss, &ssp);
+ if (error != 0)
+ return (error);
} else
ssp = NULL;
@@ -2437,21 +2135,17 @@ linux_common_pselect6(struct thread *td, l_int nfds, l_fd_set *readfds,
error = kern_pselect(td, nfds, readfds, writefds,
exceptfds, tvp, ssp, LINUX_NFDBITS);
- if (error == 0 && tsp != NULL) {
- if (td->td_retval[0] != 0) {
- /*
- * Compute how much time was left of the timeout,
- * by subtracting the current time and the time
- * before we started the call, and subtracting
- * that result from the user-supplied value.
- */
-
- microtime(&tv1);
- timevalsub(&tv1, &tv0);
- timevalsub(&utv, &tv1);
- if (utv.tv_sec < 0)
- timevalclear(&utv);
- } else
+ if (tsp != NULL) {
+ /*
+ * Compute how much time was left of the timeout,
+ * by subtracting the current time and the time
+ * before we started the call, and subtracting
+ * that result from the user-supplied value.
+ */
+ microtime(&tv1);
+ timevalsub(&tv1, &tv0);
+ timevalsub(&utv, &tv1);
+ if (utv.tv_sec < 0)
timevalclear(&utv);
TIMEVAL_TO_TIMESPEC(&utv, tsp);
}
@@ -2463,15 +2157,11 @@ int
linux_pselect6_time64(struct thread *td,
struct linux_pselect6_time64_args *args)
{
- struct l_timespec64 lts;
struct timespec ts, *tsp;
int error;
if (args->tsp != NULL) {
- error = copyin(args->tsp, &lts, sizeof(lts));
- if (error != 0)
- return (error);
- error = linux_to_native_timespec64(&ts, &lts);
+ error = linux_get_timespec64(&ts, args->tsp);
if (error != 0)
return (error);
tsp = &ts;
@@ -2480,14 +2170,9 @@ linux_pselect6_time64(struct thread *td,
error = linux_common_pselect6(td, args->nfds, args->readfds,
args->writefds, args->exceptfds, tsp, args->sig);
- if (error != 0)
- return (error);
- if (args->tsp != NULL) {
- error = native_to_linux_timespec64(&lts, tsp);
- if (error == 0)
- error = copyout(&lts, args->tsp, sizeof(lts));
- }
+ if (args->tsp != NULL)
+ linux_put_timespec64(&ts, args->tsp);
return (error);
}
#endif /* __i386__ || (__amd64__ && COMPAT_LINUX32) */
@@ -2496,14 +2181,10 @@ int
linux_ppoll(struct thread *td, struct linux_ppoll_args *args)
{
struct timespec uts, *tsp;
- struct l_timespec lts;
int error;
if (args->tsp != NULL) {
- error = copyin(args->tsp, &lts, sizeof(lts));
- if (error)
- return (error);
- error = linux_to_native_timespec(&uts, &lts);
+ error = linux_get_timespec(&uts, args->tsp);
if (error != 0)
return (error);
tsp = &uts;
@@ -2512,13 +2193,8 @@ linux_ppoll(struct thread *td, struct linux_ppoll_args *args)
error = linux_common_ppoll(td, args->fds, args->nfds, tsp,
args->sset, args->ssize);
- if (error != 0)
- return (error);
- if (tsp != NULL) {
- error = native_to_linux_timespec(&lts, tsp);
- if (error == 0)
- error = copyout(&lts, args->tsp, sizeof(lts));
- }
+ if (error == 0 && args->tsp != NULL)
+ error = linux_put_timespec(&uts, args->tsp);
return (error);
}
@@ -2529,7 +2205,6 @@ linux_common_ppoll(struct thread *td, struct pollfd *fds, uint32_t nfds,
struct timespec ts0, ts1;
struct pollfd stackfds[32];
struct pollfd *kfds;
- l_sigset_t l_ss;
sigset_t *ssp;
sigset_t ss;
int error;
@@ -2537,13 +2212,9 @@ linux_common_ppoll(struct thread *td, struct pollfd *fds, uint32_t nfds,
if (kern_poll_maxfds(nfds))
return (EINVAL);
if (sset != NULL) {
- if (ssize != sizeof(l_ss))
- return (EINVAL);
- error = copyin(sset, &l_ss, sizeof(l_ss));
- if (error)
- return (error);
- linux_to_bsd_sigset(&l_ss, &ss);
- ssp = &ss;
+ error = linux_copyin_sigset(td, sset, ssize, &ss, &ssp);
+ if (error != 0)
+ return (error);
} else
ssp = NULL;
if (tsp != NULL)
@@ -2583,14 +2254,10 @@ int
linux_ppoll_time64(struct thread *td, struct linux_ppoll_time64_args *args)
{
struct timespec uts, *tsp;
- struct l_timespec64 lts;
int error;
if (args->tsp != NULL) {
- error = copyin(args->tsp, &lts, sizeof(lts));
- if (error != 0)
- return (error);
- error = linux_to_native_timespec64(&uts, &lts);
+ error = linux_get_timespec64(&uts, args->tsp);
if (error != 0)
return (error);
tsp = &uts;
@@ -2598,13 +2265,8 @@ linux_ppoll_time64(struct thread *td, struct linux_ppoll_time64_args *args)
tsp = NULL;
error = linux_common_ppoll(td, args->fds, args->nfds, tsp,
args->sset, args->ssize);
- if (error != 0)
- return (error);
- if (tsp != NULL) {
- error = native_to_linux_timespec64(&lts, tsp);
- if (error == 0)
- error = copyout(&lts, args->tsp, sizeof(lts));
- }
+ if (error == 0 && args->tsp != NULL)
+ error = linux_put_timespec64(&uts, args->tsp);
return (error);
}
#endif /* __i386__ || (__amd64__ && COMPAT_LINUX32) */
@@ -2651,12 +2313,10 @@ linux_pollout(struct thread *td, struct pollfd *fds, struct pollfd *ufds, u_int
return (0);
}
-int
-linux_sched_rr_get_interval(struct thread *td,
- struct linux_sched_rr_get_interval_args *uap)
+static int
+linux_sched_rr_get_interval_common(struct thread *td, pid_t pid,
+ struct timespec *ts)
{
- struct timespec ts;
- struct l_timespec lts;
struct thread *tdt;
int error;
@@ -2664,22 +2324,45 @@ linux_sched_rr_get_interval(struct thread *td,
* According to man in case the invalid pid specified
* EINVAL should be returned.
*/
- if (uap->pid < 0)
+ if (pid < 0)
return (EINVAL);
- tdt = linux_tdfind(td, uap->pid, -1);
+ tdt = linux_tdfind(td, pid, -1);
if (tdt == NULL)
return (ESRCH);
- error = kern_sched_rr_get_interval_td(td, tdt, &ts);
+ error = kern_sched_rr_get_interval_td(td, tdt, ts);
PROC_UNLOCK(tdt->td_proc);
+ return (error);
+}
+
+int
+linux_sched_rr_get_interval(struct thread *td,
+ struct linux_sched_rr_get_interval_args *uap)
+{
+ struct timespec ts;
+ int error;
+
+ error = linux_sched_rr_get_interval_common(td, uap->pid, &ts);
if (error != 0)
return (error);
- error = native_to_linux_timespec(&lts, &ts);
+ return (linux_put_timespec(&ts, uap->interval));
+}
+
+#if defined(__i386__) || (defined(__amd64__) && defined(COMPAT_LINUX32))
+int
+linux_sched_rr_get_interval_time64(struct thread *td,
+ struct linux_sched_rr_get_interval_time64_args *uap)
+{
+ struct timespec ts;
+ int error;
+
+ error = linux_sched_rr_get_interval_common(td, uap->pid, &ts);
if (error != 0)
return (error);
- return (copyout(&lts, uap->interval, sizeof(lts)));
+ return (linux_put_timespec64(&ts, uap->interval));
}
+#endif
/*
* In case when the Linux thread is the initial thread in
@@ -2695,34 +2378,34 @@ linux_tdfind(struct thread *td, lwpid_t tid, pid_t pid)
tdt = NULL;
if (tid == 0 || tid == td->td_tid) {
- tdt = td;
- PROC_LOCK(tdt->td_proc);
+ if (pid != -1 && td->td_proc->p_pid != pid)
+ return (NULL);
+ PROC_LOCK(td->td_proc);
+ return (td);
} else if (tid > PID_MAX)
- tdt = tdfind(tid, pid);
- else {
- /*
- * Initial thread where the tid equal to the pid.
- */
- p = pfind(tid);
- if (p != NULL) {
- if (SV_PROC_ABI(p) != SV_ABI_LINUX) {
- /*
- * p is not a Linuxulator process.
- */
- PROC_UNLOCK(p);
- return (NULL);
- }
- FOREACH_THREAD_IN_PROC(p, tdt) {
- em = em_find(tdt);
- if (tid == em->em_tid)
- return (tdt);
- }
+ return (tdfind(tid, pid));
+
+ /*
+ * Initial thread where the tid equal to the pid.
+ */
+ p = pfind(tid);
+ if (p != NULL) {
+ if (SV_PROC_ABI(p) != SV_ABI_LINUX ||
+ (pid != -1 && tid != pid)) {
+ /*
+ * p is not a Linuxulator process.
+ */
PROC_UNLOCK(p);
+ return (NULL);
+ }
+ FOREACH_THREAD_IN_PROC(p, tdt) {
+ em = em_find(tdt);
+ if (tid == em->em_tid)
+ return (tdt);
}
- return (NULL);
+ PROC_UNLOCK(p);
}
-
- return (tdt);
+ return (NULL);
}
void
@@ -2880,3 +2563,508 @@ linux_poll(struct thread *td, struct linux_poll_args *args)
tsp, NULL, 0));
}
#endif /* __i386__ || __amd64__ */
+
+int
+linux_seccomp(struct thread *td, struct linux_seccomp_args *args)
+{
+
+ switch (args->op) {
+ case LINUX_SECCOMP_GET_ACTION_AVAIL:
+ return (EOPNOTSUPP);
+ default:
+ /*
+ * Ignore unknown operations, just like Linux kernel built
+ * without CONFIG_SECCOMP.
+ */
+ return (EINVAL);
+ }
+}
+
+/*
+ * Custom version of exec_copyin_args(), to copy out argument and environment
+ * strings from the old process address space into the temporary string buffer.
+ * Based on freebsd32_exec_copyin_args.
+ */
+static int
+linux_exec_copyin_args(struct image_args *args, const char *fname,
+ l_uintptr_t *argv, l_uintptr_t *envv)
+{
+ char *argp, *envp;
+ l_uintptr_t *ptr, arg;
+ int error;
+
+ bzero(args, sizeof(*args));
+ if (argv == NULL)
+ return (EFAULT);
+
+ /*
+ * Allocate demand-paged memory for the file name, argument, and
+ * environment strings.
+ */
+ error = exec_alloc_args(args);
+ if (error != 0)
+ return (error);
+
+ /*
+ * Copy the file name.
+ */
+ error = exec_args_add_fname(args, fname, UIO_USERSPACE);
+ if (error != 0)
+ goto err_exit;
+
+ /*
+ * extract arguments first
+ */
+ ptr = argv;
+ for (;;) {
+ error = copyin(ptr++, &arg, sizeof(arg));
+ if (error)
+ goto err_exit;
+ if (arg == 0)
+ break;
+ argp = PTRIN(arg);
+ error = exec_args_add_arg(args, argp, UIO_USERSPACE);
+ if (error != 0)
+ goto err_exit;
+ }
+
+ /*
+ * This comment is from Linux do_execveat_common:
+ * When argv is empty, add an empty string ("") as argv[0] to
+ * ensure confused userspace programs that start processing
+ * from argv[1] won't end up walking envp.
+ */
+ if (args->argc == 0 &&
+ (error = exec_args_add_arg(args, "", UIO_SYSSPACE) != 0))
+ goto err_exit;
+
+ /*
+ * extract environment strings
+ */
+ if (envv) {
+ ptr = envv;
+ for (;;) {
+ error = copyin(ptr++, &arg, sizeof(arg));
+ if (error)
+ goto err_exit;
+ if (arg == 0)
+ break;
+ envp = PTRIN(arg);
+ error = exec_args_add_env(args, envp, UIO_USERSPACE);
+ if (error != 0)
+ goto err_exit;
+ }
+ }
+
+ return (0);
+
+err_exit:
+ exec_free_args(args);
+ return (error);
+}
+
+int
+linux_execve(struct thread *td, struct linux_execve_args *args)
+{
+ struct image_args eargs;
+ int error;
+
+ LINUX_CTR(execve);
+
+ error = linux_exec_copyin_args(&eargs, args->path, args->argp,
+ args->envp);
+ if (error == 0)
+ error = linux_common_execve(td, &eargs);
+ AUDIT_SYSCALL_EXIT(error == EJUSTRETURN ? 0 : error, td);
+ return (error);
+}
+
+static void
+linux_up_rtprio_if(struct thread *td1, struct rtprio *rtp)
+{
+ struct rtprio rtp2;
+
+ pri_to_rtp(td1, &rtp2);
+ if (rtp2.type < rtp->type ||
+ (rtp2.type == rtp->type &&
+ rtp2.prio < rtp->prio)) {
+ rtp->type = rtp2.type;
+ rtp->prio = rtp2.prio;
+ }
+}
+
+#define LINUX_PRIO_DIVIDER RTP_PRIO_MAX / LINUX_IOPRIO_MAX
+
+static int
+linux_rtprio2ioprio(struct rtprio *rtp)
+{
+ int ioprio, prio;
+
+ switch (rtp->type) {
+ case RTP_PRIO_IDLE:
+ prio = RTP_PRIO_MIN;
+ ioprio = LINUX_IOPRIO_PRIO(LINUX_IOPRIO_CLASS_IDLE, prio);
+ break;
+ case RTP_PRIO_NORMAL:
+ prio = rtp->prio / LINUX_PRIO_DIVIDER;
+ ioprio = LINUX_IOPRIO_PRIO(LINUX_IOPRIO_CLASS_BE, prio);
+ break;
+ case RTP_PRIO_REALTIME:
+ prio = rtp->prio / LINUX_PRIO_DIVIDER;
+ ioprio = LINUX_IOPRIO_PRIO(LINUX_IOPRIO_CLASS_RT, prio);
+ break;
+ default:
+ prio = RTP_PRIO_MIN;
+ ioprio = LINUX_IOPRIO_PRIO(LINUX_IOPRIO_CLASS_NONE, prio);
+ break;
+ }
+ return (ioprio);
+}
+
+static int
+linux_ioprio2rtprio(int ioprio, struct rtprio *rtp)
+{
+
+ switch (LINUX_IOPRIO_PRIO_CLASS(ioprio)) {
+ case LINUX_IOPRIO_CLASS_IDLE:
+ rtp->prio = RTP_PRIO_MIN;
+ rtp->type = RTP_PRIO_IDLE;
+ break;
+ case LINUX_IOPRIO_CLASS_BE:
+ rtp->prio = LINUX_IOPRIO_PRIO_DATA(ioprio) * LINUX_PRIO_DIVIDER;
+ rtp->type = RTP_PRIO_NORMAL;
+ break;
+ case LINUX_IOPRIO_CLASS_RT:
+ rtp->prio = LINUX_IOPRIO_PRIO_DATA(ioprio) * LINUX_PRIO_DIVIDER;
+ rtp->type = RTP_PRIO_REALTIME;
+ break;
+ default:
+ return (EINVAL);
+ }
+ return (0);
+}
+#undef LINUX_PRIO_DIVIDER
+
+int
+linux_ioprio_get(struct thread *td, struct linux_ioprio_get_args *args)
+{
+ struct thread *td1;
+ struct rtprio rtp;
+ struct pgrp *pg;
+ struct proc *p;
+ int error, found;
+
+ p = NULL;
+ td1 = NULL;
+ error = 0;
+ found = 0;
+ rtp.type = RTP_PRIO_IDLE;
+ rtp.prio = RTP_PRIO_MAX;
+ switch (args->which) {
+ case LINUX_IOPRIO_WHO_PROCESS:
+ if (args->who == 0) {
+ td1 = td;
+ p = td1->td_proc;
+ PROC_LOCK(p);
+ } else if (args->who > PID_MAX) {
+ td1 = linux_tdfind(td, args->who, -1);
+ if (td1 != NULL)
+ p = td1->td_proc;
+ } else
+ p = pfind(args->who);
+ if (p == NULL)
+ return (ESRCH);
+ if ((error = p_cansee(td, p))) {
+ PROC_UNLOCK(p);
+ break;
+ }
+ if (td1 != NULL) {
+ pri_to_rtp(td1, &rtp);
+ } else {
+ FOREACH_THREAD_IN_PROC(p, td1) {
+ linux_up_rtprio_if(td1, &rtp);
+ }
+ }
+ found++;
+ PROC_UNLOCK(p);
+ break;
+ case LINUX_IOPRIO_WHO_PGRP:
+ sx_slock(&proctree_lock);
+ if (args->who == 0) {
+ pg = td->td_proc->p_pgrp;
+ PGRP_LOCK(pg);
+ } else {
+ pg = pgfind(args->who);
+ if (pg == NULL) {
+ sx_sunlock(&proctree_lock);
+ error = ESRCH;
+ break;
+ }
+ }
+ sx_sunlock(&proctree_lock);
+ LIST_FOREACH(p, &pg->pg_members, p_pglist) {
+ PROC_LOCK(p);
+ if (p->p_state == PRS_NORMAL &&
+ p_cansee(td, p) == 0) {
+ FOREACH_THREAD_IN_PROC(p, td1) {
+ linux_up_rtprio_if(td1, &rtp);
+ found++;
+ }
+ }
+ PROC_UNLOCK(p);
+ }
+ PGRP_UNLOCK(pg);
+ break;
+ case LINUX_IOPRIO_WHO_USER:
+ if (args->who == 0)
+ args->who = td->td_ucred->cr_uid;
+ sx_slock(&allproc_lock);
+ FOREACH_PROC_IN_SYSTEM(p) {
+ PROC_LOCK(p);
+ if (p->p_state == PRS_NORMAL &&
+ p->p_ucred->cr_uid == args->who &&
+ p_cansee(td, p) == 0) {
+ FOREACH_THREAD_IN_PROC(p, td1) {
+ linux_up_rtprio_if(td1, &rtp);
+ found++;
+ }
+ }
+ PROC_UNLOCK(p);
+ }
+ sx_sunlock(&allproc_lock);
+ break;
+ default:
+ error = EINVAL;
+ break;
+ }
+ if (error == 0) {
+ if (found != 0)
+ td->td_retval[0] = linux_rtprio2ioprio(&rtp);
+ else
+ error = ESRCH;
+ }
+ return (error);
+}
+
+int
+linux_ioprio_set(struct thread *td, struct linux_ioprio_set_args *args)
+{
+ struct thread *td1;
+ struct rtprio rtp;
+ struct pgrp *pg;
+ struct proc *p;
+ int error;
+
+ if ((error = linux_ioprio2rtprio(args->ioprio, &rtp)) != 0)
+ return (error);
+ /* Attempts to set high priorities (REALTIME) require su privileges. */
+ if (RTP_PRIO_BASE(rtp.type) == RTP_PRIO_REALTIME &&
+ (error = priv_check(td, PRIV_SCHED_RTPRIO)) != 0)
+ return (error);
+
+ p = NULL;
+ td1 = NULL;
+ switch (args->which) {
+ case LINUX_IOPRIO_WHO_PROCESS:
+ if (args->who == 0) {
+ td1 = td;
+ p = td1->td_proc;
+ PROC_LOCK(p);
+ } else if (args->who > PID_MAX) {
+ td1 = linux_tdfind(td, args->who, -1);
+ if (td1 != NULL)
+ p = td1->td_proc;
+ } else
+ p = pfind(args->who);
+ if (p == NULL)
+ return (ESRCH);
+ if ((error = p_cansched(td, p))) {
+ PROC_UNLOCK(p);
+ break;
+ }
+ if (td1 != NULL) {
+ error = rtp_to_pri(&rtp, td1);
+ } else {
+ FOREACH_THREAD_IN_PROC(p, td1) {
+ if ((error = rtp_to_pri(&rtp, td1)) != 0)
+ break;
+ }
+ }
+ PROC_UNLOCK(p);
+ break;
+ case LINUX_IOPRIO_WHO_PGRP:
+ sx_slock(&proctree_lock);
+ if (args->who == 0) {
+ pg = td->td_proc->p_pgrp;
+ PGRP_LOCK(pg);
+ } else {
+ pg = pgfind(args->who);
+ if (pg == NULL) {
+ sx_sunlock(&proctree_lock);
+ error = ESRCH;
+ break;
+ }
+ }
+ sx_sunlock(&proctree_lock);
+ LIST_FOREACH(p, &pg->pg_members, p_pglist) {
+ PROC_LOCK(p);
+ if (p->p_state == PRS_NORMAL &&
+ p_cansched(td, p) == 0) {
+ FOREACH_THREAD_IN_PROC(p, td1) {
+ if ((error = rtp_to_pri(&rtp, td1)) != 0)
+ break;
+ }
+ }
+ PROC_UNLOCK(p);
+ if (error != 0)
+ break;
+ }
+ PGRP_UNLOCK(pg);
+ break;
+ case LINUX_IOPRIO_WHO_USER:
+ if (args->who == 0)
+ args->who = td->td_ucred->cr_uid;
+ sx_slock(&allproc_lock);
+ FOREACH_PROC_IN_SYSTEM(p) {
+ PROC_LOCK(p);
+ if (p->p_state == PRS_NORMAL &&
+ p->p_ucred->cr_uid == args->who &&
+ p_cansched(td, p) == 0) {
+ FOREACH_THREAD_IN_PROC(p, td1) {
+ if ((error = rtp_to_pri(&rtp, td1)) != 0)
+ break;
+ }
+ }
+ PROC_UNLOCK(p);
+ if (error != 0)
+ break;
+ }
+ sx_sunlock(&allproc_lock);
+ break;
+ default:
+ error = EINVAL;
+ break;
+ }
+ return (error);
+}
+
+/* The only flag is O_NONBLOCK */
+#define B2L_MQ_FLAGS(bflags) ((bflags) != 0 ? LINUX_O_NONBLOCK : 0)
+#define L2B_MQ_FLAGS(lflags) ((lflags) != 0 ? O_NONBLOCK : 0)
+
+int
+linux_mq_open(struct thread *td, struct linux_mq_open_args *args)
+{
+ struct mq_attr attr;
+ int error, flags;
+
+ flags = linux_common_openflags(args->oflag);
+ if ((flags & O_ACCMODE) == O_ACCMODE || (flags & O_EXEC) != 0)
+ return (EINVAL);
+ flags = FFLAGS(flags);
+ if ((flags & O_CREAT) != 0 && args->attr != NULL) {
+ error = copyin(args->attr, &attr, sizeof(attr));
+ if (error != 0)
+ return (error);
+ attr.mq_flags = L2B_MQ_FLAGS(attr.mq_flags);
+ }
+
+ return (kern_kmq_open(td, args->name, flags, args->mode,
+ args->attr != NULL ? &attr : NULL));
+}
+
+int
+linux_mq_unlink(struct thread *td, struct linux_mq_unlink_args *args)
+{
+ struct kmq_unlink_args bsd_args = {
+ .path = PTRIN(args->name)
+ };
+
+ return (sys_kmq_unlink(td, &bsd_args));
+}
+
+int
+linux_mq_timedsend(struct thread *td, struct linux_mq_timedsend_args *args)
+{
+ struct timespec ts, *abs_timeout;
+ int error;
+
+ if (args->abs_timeout == NULL)
+ abs_timeout = NULL;
+ else {
+ error = linux_get_timespec(&ts, args->abs_timeout);
+ if (error != 0)
+ return (error);
+ abs_timeout = &ts;
+ }
+
+ return (kern_kmq_timedsend(td, args->mqd, PTRIN(args->msg_ptr),
+ args->msg_len, args->msg_prio, abs_timeout));
+}
+
+int
+linux_mq_timedreceive(struct thread *td, struct linux_mq_timedreceive_args *args)
+{
+ struct timespec ts, *abs_timeout;
+ int error;
+
+ if (args->abs_timeout == NULL)
+ abs_timeout = NULL;
+ else {
+ error = linux_get_timespec(&ts, args->abs_timeout);
+ if (error != 0)
+ return (error);
+ abs_timeout = &ts;
+ }
+
+ return (kern_kmq_timedreceive(td, args->mqd, PTRIN(args->msg_ptr),
+ args->msg_len, args->msg_prio, abs_timeout));
+}
+
+int
+linux_mq_notify(struct thread *td, struct linux_mq_notify_args *args)
+{
+ struct sigevent ev, *evp;
+ struct l_sigevent l_ev;
+ int error;
+
+ if (args->sevp == NULL)
+ evp = NULL;
+ else {
+ error = copyin(args->sevp, &l_ev, sizeof(l_ev));
+ if (error != 0)
+ return (error);
+ error = linux_convert_l_sigevent(&l_ev, &ev);
+ if (error != 0)
+ return (error);
+ evp = &ev;
+ }
+
+ return (kern_kmq_notify(td, args->mqd, evp));
+}
+
+int
+linux_mq_getsetattr(struct thread *td, struct linux_mq_getsetattr_args *args)
+{
+ struct mq_attr attr, oattr;
+ int error;
+
+ if (args->attr != NULL) {
+ error = copyin(args->attr, &attr, sizeof(attr));
+ if (error != 0)
+ return (error);
+ attr.mq_flags = L2B_MQ_FLAGS(attr.mq_flags);
+ }
+
+ error = kern_kmq_setattr(td, args->mqd, args->attr != NULL ? &attr : NULL,
+ &oattr);
+ if (error == 0 && args->oattr != NULL) {
+ oattr.mq_flags = B2L_MQ_FLAGS(oattr.mq_flags);
+ bzero(oattr.__reserved, sizeof(oattr.__reserved));
+ error = copyout(&oattr, args->oattr, sizeof(oattr));
+ }
+
+ return (error);
+}
+
+MODULE_DEPEND(linux, mqueuefs, 1, 1, 1);
diff --git a/sys/compat/linux/linux_misc.h b/sys/compat/linux/linux_misc.h
index 3bfc9843cda2..2d2b12ef0127 100644
--- a/sys/compat/linux/linux_misc.h
+++ b/sys/compat/linux/linux_misc.h
@@ -1,5 +1,5 @@
/*-
- * SPDX-License-Identifier: BSD-2-Clause-FreeBSD
+ * SPDX-License-Identifier: BSD-2-Clause
*
* Copyright (c) 2006 Roman Divacky
* All rights reserved.
@@ -24,15 +24,11 @@
* 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.
- *
- * $FreeBSD$
*/
#ifndef _LINUX_MISC_H_
#define _LINUX_MISC_H_
-#include <sys/sysctl.h>
-
#define LINUX_MAX_PID_NS_LEVEL 32
/* bits per mask */
@@ -61,6 +57,7 @@
#define LINUX_PR_GET_SECCOMP 21
#define LINUX_PR_SET_SECCOMP 22
#define LINUX_PR_CAPBSET_READ 23
+#define LINUX_PR_SET_CHILD_SUBREAPER 36
#define LINUX_PR_SET_NO_NEW_PRIVS 38
#define LINUX_PR_SET_PTRACER 1499557217
@@ -88,13 +85,19 @@
* differ from AT_PLATFORM.
*/
#define LINUX_AT_RANDOM 25 /* address of random bytes */
-#define LINUX_AT_HWCAP2 26 /* CPU capabilities, second part */
+#define LINUX_AT_HWCAP2 26 /* CPU capabilities */
+#define LINUX_AT_HWCAP3 29 /* CPU capabilities */
+#define LINUX_AT_HWCAP4 30 /* CPU capabilities */
#define LINUX_AT_EXECFN 31 /* filename of program */
#define LINUX_AT_SYSINFO 32 /* vsyscall */
#define LINUX_AT_SYSINFO_EHDR 33 /* vdso header */
#define LINUX_AT_RANDOM_LEN 16 /* size of random bytes */
+#ifndef LINUX_AT_MINSIGSTKSZ
+#define LINUX_AT_MINSIGSTKSZ 51 /* min stack size required by the kernel */
+#endif
+
/* Linux sets the i387 to extended precision. */
#if defined(__i386__) || defined(__amd64__)
#define __LINUX_NPXCW__ 0x37f
@@ -136,6 +139,7 @@ extern int stclohz;
#define LINUX_P_ALL 0
#define LINUX_P_PID 1
#define LINUX_P_PGID 2
+#define LINUX_P_PIDFD 3
#define LINUX_RLIMIT_LOCKS 10
#define LINUX_RLIMIT_SIGPENDING 11
@@ -153,6 +157,13 @@ extern int stclohz;
/* Linux syslog flags */
#define LINUX_SYSLOG_ACTION_READ_ALL 3
+/* Linux seccomp flags */
+#define LINUX_SECCOMP_GET_ACTION_AVAIL 2
+
+/* Linux /proc/self/oom_score_adj */
+#define LINUX_OOM_SCORE_ADJ_MIN -1000
+#define LINUX_OOM_SCORE_ADJ_MAX 1000
+
#if defined(__aarch64__) || (defined(__amd64__) && !defined(COMPAT_LINUX32))
int linux_ptrace_status(struct thread *td, int pid, int status);
#endif
@@ -181,4 +192,28 @@ struct syscall_info {
};
};
+/* Linux ioprio set/get syscalls */
+#define LINUX_IOPRIO_CLASS_SHIFT 13
+#define LINUX_IOPRIO_CLASS_MASK 0x07
+#define LINUX_IOPRIO_PRIO_MASK ((1UL << LINUX_IOPRIO_CLASS_SHIFT) - 1)
+
+#define LINUX_IOPRIO_PRIO_CLASS(ioprio) \
+ (((ioprio) >> LINUX_IOPRIO_CLASS_SHIFT) & LINUX_IOPRIO_CLASS_MASK)
+#define LINUX_IOPRIO_PRIO_DATA(ioprio) ((ioprio) & LINUX_IOPRIO_PRIO_MASK)
+#define LINUX_IOPRIO_PRIO(class, data) \
+ ((((class) & LINUX_IOPRIO_CLASS_MASK) << LINUX_IOPRIO_CLASS_SHIFT) | \
+ ((data) & LINUX_IOPRIO_PRIO_MASK))
+
+#define LINUX_IOPRIO_CLASS_NONE 0
+#define LINUX_IOPRIO_CLASS_RT 1
+#define LINUX_IOPRIO_CLASS_BE 2
+#define LINUX_IOPRIO_CLASS_IDLE 3
+
+#define LINUX_IOPRIO_MIN 0
+#define LINUX_IOPRIO_MAX 7
+
+#define LINUX_IOPRIO_WHO_PROCESS 1
+#define LINUX_IOPRIO_WHO_PGRP 2
+#define LINUX_IOPRIO_WHO_USER 3
+
#endif /* _LINUX_MISC_H_ */
diff --git a/sys/compat/linux/linux_mmap.c b/sys/compat/linux/linux_mmap.c
index af2ccc74ba12..a8e790a29da4 100644
--- a/sys/compat/linux/linux_mmap.c
+++ b/sys/compat/linux/linux_mmap.c
@@ -27,18 +27,13 @@
* 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.
- *
- * $FreeBSD$
*/
-#include <sys/cdefs.h>
-__FBSDID("$FreeBSD$");
-
-#include <sys/capsicum.h>
+#include <sys/fcntl.h>
#include <sys/file.h>
-#include <sys/imgact.h>
#include <sys/ktr.h>
#include <sys/lock.h>
+#include <sys/malloc.h>
#include <sys/mman.h>
#include <sys/proc.h>
#include <sys/resourcevar.h>
@@ -176,7 +171,7 @@ linux_mmap_common(struct thread *td, uintptr_t addr, size_t len, int prot,
* mmap's return value.
*/
PROC_LOCK(p);
- vms->vm_maxsaddr = (char *)p->p_sysent->sv_usrstack -
+ vms->vm_maxsaddr = (char *)round_page(vms->vm_stacktop) -
lim_cur_proc(p, RLIMIT_STACK);
PROC_UNLOCK(p);
}
@@ -230,16 +225,22 @@ out:
int
linux_mprotect_common(struct thread *td, uintptr_t addr, size_t len, int prot)
{
+ int flags = 0;
- /* XXX Ignore PROT_GROWSDOWN and PROT_GROWSUP for now. */
- prot &= ~(LINUX_PROT_GROWSDOWN | LINUX_PROT_GROWSUP);
- if ((prot & ~(PROT_READ | PROT_WRITE | PROT_EXEC)) != 0)
+ /* XXX Ignore PROT_GROWSUP for now. */
+ prot &= ~LINUX_PROT_GROWSUP;
+ if ((prot & ~(LINUX_PROT_GROWSDOWN | PROT_READ | PROT_WRITE |
+ PROT_EXEC)) != 0)
return (EINVAL);
+ if ((prot & LINUX_PROT_GROWSDOWN) != 0) {
+ prot &= ~LINUX_PROT_GROWSDOWN;
+ flags |= VM_MAP_PROTECT_GROWSDOWN;
+ }
#if defined(__amd64__)
linux_fixup_prot(td, &prot);
#endif
- return (kern_mprotect(td, addr, len, prot));
+ return (kern_mprotect(td, addr, len, prot, flags));
}
/*
diff --git a/sys/compat/linux/linux_mmap.h b/sys/compat/linux/linux_mmap.h
index 3bedc2102f5f..043dec9d40b7 100644
--- a/sys/compat/linux/linux_mmap.h
+++ b/sys/compat/linux/linux_mmap.h
@@ -27,8 +27,6 @@
* 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.
- *
- * $FreeBSD$
*/
#ifndef _LINUX_MMAP_H_
diff --git a/sys/compat/linux/linux_netlink.c b/sys/compat/linux/linux_netlink.c
new file mode 100644
index 000000000000..6aeafe84adc6
--- /dev/null
+++ b/sys/compat/linux/linux_netlink.c
@@ -0,0 +1,612 @@
+/*-
+ * SPDX-License-Identifier: BSD-2-Clause
+ *
+ * Copyright (c) 2022 Alexander V. Chernikov
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``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 OR CONTRIBUTORS 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.
+ */
+
+#include "opt_inet.h"
+#include "opt_inet6.h"
+
+#include <sys/types.h>
+#include <sys/ck.h>
+#include <sys/lock.h>
+#include <sys/socket.h>
+#include <sys/vnode.h>
+
+#include <net/if.h>
+#include <net/if_dl.h>
+#include <net/route.h>
+#include <net/route/nhop.h>
+#include <net/route/route_ctl.h>
+#include <netlink/netlink.h>
+#include <netlink/netlink_ctl.h>
+#include <netlink/netlink_linux.h>
+#include <netlink/netlink_var.h>
+#include <netlink/netlink_route.h>
+
+#include <compat/linux/linux.h>
+#include <compat/linux/linux_common.h>
+#include <compat/linux/linux_util.h>
+
+#define DEBUG_MOD_NAME nl_linux
+#define DEBUG_MAX_LEVEL LOG_DEBUG3
+#include <netlink/netlink_debug.h>
+_DECLARE_DEBUG(LOG_INFO);
+
+static bool
+valid_rta_size(const struct rtattr *rta, int sz)
+{
+ return (NL_RTA_DATA_LEN(rta) == sz);
+}
+
+static bool
+valid_rta_u32(const struct rtattr *rta)
+{
+ return (valid_rta_size(rta, sizeof(uint32_t)));
+}
+
+static uint32_t
+_rta_get_uint32(const struct rtattr *rta)
+{
+ return (*((const uint32_t *)NL_RTA_DATA_CONST(rta)));
+}
+
+static int
+rtnl_neigh_from_linux(struct nlmsghdr *hdr, struct nl_pstate *npt)
+{
+ struct ndmsg *ndm = (struct ndmsg *)(hdr + 1);
+ sa_family_t f;
+
+ if (hdr->nlmsg_len < sizeof(struct nlmsghdr) + sizeof(struct ndmsg))
+ return (EBADMSG);
+ if ((f = linux_to_bsd_domain(ndm->ndm_family)) == AF_UNKNOWN)
+ return (EPFNOSUPPORT);
+
+ ndm->ndm_family = f;
+
+ return (0);
+}
+
+static int
+rtnl_ifaddr_from_linux(struct nlmsghdr *hdr, struct nl_pstate *npt)
+{
+ struct ifaddrmsg *ifam = (struct ifaddrmsg *)(hdr + 1);
+ sa_family_t f;
+
+ if (hdr->nlmsg_len < sizeof(struct nlmsghdr) +
+ offsetof(struct ifaddrmsg, ifa_family) + sizeof(ifam->ifa_family))
+ return (EBADMSG);
+ if ((f = linux_to_bsd_domain(ifam->ifa_family)) == AF_UNKNOWN)
+ return (EPFNOSUPPORT);
+
+ ifam->ifa_family = f;
+
+ return (0);
+}
+
+/*
+ * XXX: in case of error state of hdr is inconsistent.
+ */
+static int
+rtnl_route_from_linux(struct nlmsghdr *hdr, struct nl_pstate *npt)
+{
+ /* Tweak address families and default fib only */
+ struct rtmsg *rtm = (struct rtmsg *)(hdr + 1);
+ struct nlattr *nla, *nla_head;
+ int attrs_len;
+ sa_family_t f;
+
+ if (hdr->nlmsg_len < sizeof(struct nlmsghdr) + sizeof(struct rtmsg))
+ return (EBADMSG);
+ if ((f = linux_to_bsd_domain(rtm->rtm_family)) == AF_UNKNOWN)
+ return (EPFNOSUPPORT);
+ rtm->rtm_family = f;
+
+ if (rtm->rtm_table == 254)
+ rtm->rtm_table = 0;
+
+ attrs_len = hdr->nlmsg_len - sizeof(struct nlmsghdr);
+ attrs_len -= NETLINK_ALIGN(sizeof(struct rtmsg));
+ nla_head = (struct nlattr *)((char *)rtm + NETLINK_ALIGN(sizeof(struct rtmsg)));
+
+ NLA_FOREACH(nla, nla_head, attrs_len) {
+ RT_LOG(LOG_DEBUG3, "GOT type %d len %d total %d",
+ nla->nla_type, nla->nla_len, attrs_len);
+ struct rtattr *rta = (struct rtattr *)nla;
+ if (rta->rta_len < sizeof(struct rtattr)) {
+ break;
+ }
+ switch (rta->rta_type) {
+ case NL_RTA_TABLE:
+ if (!valid_rta_u32(rta))
+ return (EBADMSG);
+ rtm->rtm_table = 0;
+ uint32_t fibnum = _rta_get_uint32(rta);
+ RT_LOG(LOG_DEBUG3, "GET RTABLE: %u", fibnum);
+ if (fibnum == 254) {
+ *((uint32_t *)NL_RTA_DATA(rta)) = 0;
+ }
+ break;
+ }
+ }
+
+ return (0);
+}
+
+static int
+rtnl_from_linux(struct nlmsghdr *hdr, struct nl_pstate *npt)
+{
+
+ switch (hdr->nlmsg_type) {
+ case NL_RTM_GETROUTE:
+ case NL_RTM_NEWROUTE:
+ case NL_RTM_DELROUTE:
+ return (rtnl_route_from_linux(hdr, npt));
+ case NL_RTM_GETNEIGH:
+ return (rtnl_neigh_from_linux(hdr, npt));
+ case NL_RTM_GETADDR:
+ return (rtnl_ifaddr_from_linux(hdr, npt));
+ /* Silence warning for the messages where no translation is required */
+ case NL_RTM_NEWLINK:
+ case NL_RTM_DELLINK:
+ case NL_RTM_GETLINK:
+ break;
+ default:
+ RT_LOG(LOG_DEBUG, "Passing message type %d untranslated",
+ hdr->nlmsg_type);
+ /* XXXGL: maybe return error? */
+ }
+
+ return (0);
+}
+
+static int
+nlmsg_from_linux(int netlink_family, struct nlmsghdr **hdr,
+ struct nl_pstate *npt)
+{
+ switch (netlink_family) {
+ case NETLINK_ROUTE:
+ return (rtnl_from_linux(*hdr, npt));
+ }
+
+ return (0);
+}
+
+
+/************************************************************
+ * Kernel -> Linux
+ ************************************************************/
+
+static bool
+handle_default_out(struct nlmsghdr *hdr, struct nl_writer *nw)
+{
+ char *out_hdr;
+ out_hdr = nlmsg_reserve_data(nw, NLMSG_ALIGN(hdr->nlmsg_len), char);
+
+ if (out_hdr != NULL) {
+ memcpy(out_hdr, hdr, hdr->nlmsg_len);
+ nw->num_messages++;
+ return (true);
+ }
+ return (false);
+}
+
+static bool
+nlmsg_copy_header(struct nlmsghdr *hdr, struct nl_writer *nw)
+{
+ return (nlmsg_add(nw, hdr->nlmsg_pid, hdr->nlmsg_seq, hdr->nlmsg_type,
+ hdr->nlmsg_flags, 0));
+}
+
+static void *
+_nlmsg_copy_next_header(struct nlmsghdr *hdr, struct nl_writer *nw, int sz)
+{
+ void *next_hdr = nlmsg_reserve_data(nw, sz, void);
+ memcpy(next_hdr, hdr + 1, NLMSG_ALIGN(sz));
+
+ return (next_hdr);
+}
+#define nlmsg_copy_next_header(_hdr, _ns, _t) \
+ ((_t *)(_nlmsg_copy_next_header(_hdr, _ns, sizeof(_t))))
+
+static bool
+nlmsg_copy_nla(const struct nlattr *nla_orig, struct nl_writer *nw)
+{
+ struct nlattr *nla = nlmsg_reserve_data(nw, nla_orig->nla_len, struct nlattr);
+ if (nla != NULL) {
+ memcpy(nla, nla_orig, nla_orig->nla_len);
+ return (true);
+ }
+ return (false);
+}
+
+/*
+ * Translate a FreeBSD interface name to a Linux interface name.
+ */
+static bool
+nlmsg_translate_ifname_nla(struct nlattr *nla, struct nl_writer *nw)
+{
+ char ifname[LINUX_IFNAMSIZ];
+
+ if (ifname_bsd_to_linux_name((char *)(nla + 1), ifname,
+ sizeof(ifname)) <= 0)
+ return (false);
+ return (nlattr_add_string(nw, IFLA_IFNAME, ifname));
+}
+
+#define LINUX_NLA_UNHANDLED -1
+/*
+ * Translate a FreeBSD attribute to a Linux attribute.
+ * Returns LINUX_NLA_UNHANDLED when the attribute is not processed
+ * and the caller must take care of it, otherwise the result is returned.
+ */
+static int
+nlmsg_translate_all_nla(struct nlmsghdr *hdr, struct nlattr *nla,
+ struct nl_writer *nw)
+{
+
+ switch (hdr->nlmsg_type) {
+ case NL_RTM_NEWLINK:
+ case NL_RTM_DELLINK:
+ case NL_RTM_GETLINK:
+ switch (nla->nla_type) {
+ case IFLA_IFNAME:
+ return (nlmsg_translate_ifname_nla(nla, nw));
+ default:
+ break;
+ }
+ default:
+ break;
+ }
+ return (LINUX_NLA_UNHANDLED);
+}
+
+static bool
+nlmsg_copy_all_nla(struct nlmsghdr *hdr, int raw_hdrlen, struct nl_writer *nw)
+{
+ struct nlattr *nla;
+ int ret;
+
+ int hdrlen = NETLINK_ALIGN(raw_hdrlen);
+ int attrs_len = hdr->nlmsg_len - sizeof(struct nlmsghdr) - hdrlen;
+ struct nlattr *nla_head = (struct nlattr *)((char *)(hdr + 1) + hdrlen);
+
+ NLA_FOREACH(nla, nla_head, attrs_len) {
+ RT_LOG(LOG_DEBUG3, "reading attr %d len %d", nla->nla_type, nla->nla_len);
+ if (nla->nla_len < sizeof(struct nlattr)) {
+ return (false);
+ }
+ ret = nlmsg_translate_all_nla(hdr, nla, nw);
+ if (ret == LINUX_NLA_UNHANDLED)
+ ret = nlmsg_copy_nla(nla, nw);
+ if (!ret)
+ return (false);
+ }
+ return (true);
+}
+#undef LINUX_NLA_UNHANDLED
+
+static unsigned int
+rtnl_if_flags_to_linux(unsigned int if_flags)
+{
+ unsigned int result = 0;
+
+ for (int i = 0; i < 31; i++) {
+ unsigned int flag = 1 << i;
+ if (!(flag & if_flags))
+ continue;
+ switch (flag) {
+ case IFF_UP:
+ case IFF_BROADCAST:
+ case IFF_DEBUG:
+ case IFF_LOOPBACK:
+ case IFF_POINTOPOINT:
+ case IFF_DRV_RUNNING:
+ case IFF_NOARP:
+ case IFF_PROMISC:
+ case IFF_ALLMULTI:
+ result |= flag;
+ break;
+ case IFF_NEEDSEPOCH:
+ case IFF_DRV_OACTIVE:
+ case IFF_SIMPLEX:
+ case IFF_LINK0:
+ case IFF_LINK1:
+ case IFF_LINK2:
+ case IFF_CANTCONFIG:
+ case IFF_PPROMISC:
+ case IFF_MONITOR:
+ case IFF_STATICARP:
+ case IFF_STICKYARP:
+ case IFF_DYING:
+ case IFF_RENAMING:
+ /* No Linux analogue */
+ break;
+ case IFF_MULTICAST:
+ result |= 1 << 12;
+ }
+ }
+ return (result);
+}
+
+static bool
+rtnl_newlink_to_linux(struct nlmsghdr *hdr, struct nlpcb *nlp,
+ struct nl_writer *nw)
+{
+ if (!nlmsg_copy_header(hdr, nw))
+ return (false);
+
+ struct ifinfomsg *ifinfo;
+ ifinfo = nlmsg_copy_next_header(hdr, nw, struct ifinfomsg);
+
+ ifinfo->ifi_family = bsd_to_linux_domain(ifinfo->ifi_family);
+ /* Convert interface type */
+ switch (ifinfo->ifi_type) {
+ case IFT_ETHER:
+ ifinfo->ifi_type = LINUX_ARPHRD_ETHER;
+ break;
+ }
+ ifinfo->ifi_flags = rtnl_if_flags_to_linux(ifinfo->ifi_flags);
+
+ /* Copy attributes unchanged */
+ if (!nlmsg_copy_all_nla(hdr, sizeof(struct ifinfomsg), nw))
+ return (false);
+
+ /* make ip(8) happy */
+ if (!nlattr_add_string(nw, IFLA_QDISC, "noqueue"))
+ return (false);
+
+ if (!nlattr_add_u32(nw, IFLA_TXQLEN, 1000))
+ return (false);
+
+ nlmsg_end(nw);
+ RT_LOG(LOG_DEBUG2, "done processing nw %p", nw);
+ return (true);
+}
+
+static bool
+rtnl_newaddr_to_linux(struct nlmsghdr *hdr, struct nlpcb *nlp,
+ struct nl_writer *nw)
+{
+ if (!nlmsg_copy_header(hdr, nw))
+ return (false);
+
+ struct ifaddrmsg *ifamsg;
+ ifamsg = nlmsg_copy_next_header(hdr, nw, struct ifaddrmsg);
+
+ ifamsg->ifa_family = bsd_to_linux_domain(ifamsg->ifa_family);
+ /* XXX: fake ifa_flags? */
+
+ /* Copy attributes unchanged */
+ if (!nlmsg_copy_all_nla(hdr, sizeof(struct ifaddrmsg), nw))
+ return (false);
+
+ nlmsg_end(nw);
+ RT_LOG(LOG_DEBUG2, "done processing nw %p", nw);
+ return (true);
+}
+
+static bool
+rtnl_newneigh_to_linux(struct nlmsghdr *hdr, struct nlpcb *nlp,
+ struct nl_writer *nw)
+{
+ if (!nlmsg_copy_header(hdr, nw))
+ return (false);
+
+ struct ndmsg *ndm;
+ ndm = nlmsg_copy_next_header(hdr, nw, struct ndmsg);
+
+ ndm->ndm_family = bsd_to_linux_domain(ndm->ndm_family);
+
+ /* Copy attributes unchanged */
+ if (!nlmsg_copy_all_nla(hdr, sizeof(struct ndmsg), nw))
+ return (false);
+
+ nlmsg_end(nw);
+ RT_LOG(LOG_DEBUG2, "done processing nw %p", nw);
+ return (true);
+}
+
+static bool
+rtnl_newroute_to_linux(struct nlmsghdr *hdr, struct nlpcb *nlp,
+ struct nl_writer *nw)
+{
+ if (!nlmsg_copy_header(hdr, nw))
+ return (false);
+
+ struct rtmsg *rtm;
+ rtm = nlmsg_copy_next_header(hdr, nw, struct rtmsg);
+ rtm->rtm_family = bsd_to_linux_domain(rtm->rtm_family);
+
+ struct nlattr *nla;
+
+ int hdrlen = NETLINK_ALIGN(sizeof(struct rtmsg));
+ int attrs_len = hdr->nlmsg_len - sizeof(struct nlmsghdr) - hdrlen;
+ struct nlattr *nla_head = (struct nlattr *)((char *)(hdr + 1) + hdrlen);
+
+ NLA_FOREACH(nla, nla_head, attrs_len) {
+ struct rtattr *rta = (struct rtattr *)nla;
+ //RT_LOG(LOG_DEBUG, "READING attr %d len %d", nla->nla_type, nla->nla_len);
+ if (rta->rta_len < sizeof(struct rtattr)) {
+ break;
+ }
+
+ switch (rta->rta_type) {
+ case NL_RTA_TABLE:
+ {
+ uint32_t fibnum;
+ fibnum = _rta_get_uint32(rta);
+ if (fibnum == 0)
+ fibnum = 254;
+ RT_LOG(LOG_DEBUG3, "XFIBNUM %u", fibnum);
+ if (!nlattr_add_u32(nw, NL_RTA_TABLE, fibnum))
+ return (false);
+ }
+ break;
+ default:
+ if (!nlmsg_copy_nla(nla, nw))
+ return (false);
+ break;
+ }
+ }
+
+ nlmsg_end(nw);
+ RT_LOG(LOG_DEBUG2, "done processing nw %p", nw);
+ return (true);
+}
+
+static bool
+rtnl_to_linux(struct nlmsghdr *hdr, struct nlpcb *nlp, struct nl_writer *nw)
+{
+ RT_LOG(LOG_DEBUG2, "Got message type %d", hdr->nlmsg_type);
+
+ switch (hdr->nlmsg_type) {
+ case NL_RTM_NEWLINK:
+ case NL_RTM_DELLINK:
+ case NL_RTM_GETLINK:
+ return (rtnl_newlink_to_linux(hdr, nlp, nw));
+ case NL_RTM_NEWADDR:
+ case NL_RTM_DELADDR:
+ return (rtnl_newaddr_to_linux(hdr, nlp, nw));
+ case NL_RTM_NEWROUTE:
+ case NL_RTM_DELROUTE:
+ return (rtnl_newroute_to_linux(hdr, nlp, nw));
+ case NL_RTM_NEWNEIGH:
+ case NL_RTM_DELNEIGH:
+ case NL_RTM_GETNEIGH:
+ return (rtnl_newneigh_to_linux(hdr, nlp, nw));
+ default:
+ RT_LOG(LOG_DEBUG, "[WARN] Passing message type %d untranslated",
+ hdr->nlmsg_type);
+ return (handle_default_out(hdr, nw));
+ }
+}
+
+static bool
+nlmsg_error_to_linux(struct nlmsghdr *hdr, struct nlpcb *nlp, struct nl_writer *nw)
+{
+ if (!nlmsg_copy_header(hdr, nw))
+ return (false);
+
+ struct nlmsgerr *nlerr;
+ nlerr = nlmsg_copy_next_header(hdr, nw, struct nlmsgerr);
+ nlerr->error = bsd_to_linux_errno(nlerr->error);
+
+ int copied_len = sizeof(struct nlmsghdr) + sizeof(struct nlmsgerr);
+ if (hdr->nlmsg_len == copied_len) {
+ nlmsg_end(nw);
+ return (true);
+ }
+
+ /*
+ * CAP_ACK was not set. Original request needs to be translated.
+ * XXX: implement translation of the original message
+ */
+ RT_LOG(LOG_DEBUG, "[WARN] Passing ack message type %d untranslated",
+ nlerr->msg.nlmsg_type);
+ char *dst_payload, *src_payload;
+ int copy_len = hdr->nlmsg_len - copied_len;
+ dst_payload = nlmsg_reserve_data(nw, NLMSG_ALIGN(copy_len), char);
+
+ src_payload = (char *)hdr + copied_len;
+
+ memcpy(dst_payload, src_payload, copy_len);
+ nlmsg_end(nw);
+
+ return (true);
+}
+
+static bool
+nlmsg_to_linux(struct nlmsghdr *hdr, struct nlpcb *nlp, struct nl_writer *nw)
+{
+ if (hdr->nlmsg_type < NLMSG_MIN_TYPE) {
+ switch (hdr->nlmsg_type) {
+ case NLMSG_ERROR:
+ return (nlmsg_error_to_linux(hdr, nlp, nw));
+ case NLMSG_NOOP:
+ case NLMSG_DONE:
+ case NLMSG_OVERRUN:
+ return (handle_default_out(hdr, nw));
+ default:
+ RT_LOG(LOG_DEBUG, "[WARN] Passing message type %d untranslated",
+ hdr->nlmsg_type);
+ return (handle_default_out(hdr, nw));
+ }
+ }
+
+ switch (nlp->nl_proto) {
+ case NETLINK_ROUTE:
+ return (rtnl_to_linux(hdr, nlp, nw));
+ default:
+ return (handle_default_out(hdr, nw));
+ }
+}
+
+static struct nl_buf *
+nlmsgs_to_linux(struct nl_buf *orig, struct nlpcb *nlp)
+{
+ struct nl_writer nw;
+ u_int offset, msglen;
+
+ if (__predict_false(!nl_writer_unicast(&nw,
+ orig->datalen + SCRATCH_BUFFER_SIZE, nlp, false)))
+ return (NULL);
+
+ /* Assume correct headers. Buffer IS mutable */
+ for (offset = 0;
+ offset + sizeof(struct nlmsghdr) <= orig->datalen;
+ offset += msglen) {
+ struct nlmsghdr *hdr = (struct nlmsghdr *)&orig->data[offset];
+
+ msglen = NLMSG_ALIGN(hdr->nlmsg_len);
+ if (!nlmsg_to_linux(hdr, nlp, &nw)) {
+ RT_LOG(LOG_DEBUG, "failed to process msg type %d",
+ hdr->nlmsg_type);
+ nl_buf_free(nw.buf);
+ return (NULL);
+ }
+ }
+
+ RT_LOG(LOG_DEBUG3, "%p: in %u bytes %u messages", __func__,
+ nw.buf->datalen, nw.num_messages);
+
+ return (nw.buf);
+}
+
+static struct linux_netlink_provider linux_netlink_v1 = {
+ .msgs_to_linux = nlmsgs_to_linux,
+ .msg_from_linux = nlmsg_from_linux,
+};
+
+void
+linux_netlink_register(void)
+{
+ linux_netlink_p = &linux_netlink_v1;
+}
+
+void
+linux_netlink_deregister(void)
+{
+ linux_netlink_p = NULL;
+}
diff --git a/sys/compat/linux/linux_persona.h b/sys/compat/linux/linux_persona.h
index 7ae166aeb2cf..18aef6f02d76 100644
--- a/sys/compat/linux/linux_persona.h
+++ b/sys/compat/linux/linux_persona.h
@@ -1,6 +1,3 @@
-/*
- * $FreeBSD$
- */
#ifndef LINUX_PERSONALITY_H
#define LINUX_PERSONALITY_H
diff --git a/sys/compat/linux/linux_ptrace.c b/sys/compat/linux/linux_ptrace.c
index 590a3474a006..0dbfd2177122 100644
--- a/sys/compat/linux/linux_ptrace.c
+++ b/sys/compat/linux/linux_ptrace.c
@@ -1,5 +1,5 @@
/*-
- * SPDX-License-Identifier: BSD-2-Clause-FreeBSD
+ * SPDX-License-Identifier: BSD-2-Clause
*
* Copyright (c) 2017 Edward Tomasz Napierala <trasz@FreeBSD.org>
*
@@ -29,9 +29,6 @@
* SUCH DAMAGE.
*/
-#include <sys/cdefs.h>
-__FBSDID("$FreeBSD$");
-
#include <sys/param.h>
#include <sys/lock.h>
#include <sys/proc.h>
@@ -100,11 +97,6 @@ __FBSDID("$FreeBSD$");
#define LINUX_PTRACE_SYSCALL_INFO_ENTRY 1
#define LINUX_PTRACE_SYSCALL_INFO_EXIT 2
-#define LINUX_PTRACE_PEEKUSER_ORIG_RAX 120
-#define LINUX_PTRACE_PEEKUSER_RIP 128
-#define LINUX_PTRACE_PEEKUSER_CS 136
-#define LINUX_PTRACE_PEEKUSER_DS 184
-
static int
map_signum(int lsig, int *bsigp)
{
@@ -180,52 +172,6 @@ linux_ptrace_peek(struct thread *td, pid_t pid, void *addr, void *data)
}
static int
-linux_ptrace_peekuser(struct thread *td, pid_t pid, void *addr, void *data)
-{
- struct reg b_reg;
- uint64_t val;
- int error;
-
- error = kern_ptrace(td, PT_GETREGS, pid, &b_reg, 0);
- if (error != 0)
- return (error);
-
- switch ((uintptr_t)addr) {
-#ifdef __amd64__
- case LINUX_PTRACE_PEEKUSER_ORIG_RAX:
- val = b_reg.r_rax;
- break;
- case LINUX_PTRACE_PEEKUSER_RIP:
- val = b_reg.r_rip;
- break;
- case LINUX_PTRACE_PEEKUSER_CS:
- val = b_reg.r_cs;
- break;
- case LINUX_PTRACE_PEEKUSER_DS:
- val = b_reg.r_ds;
- break;
-#endif /* __amd64__ */
- default:
- linux_msg(td, "PTRACE_PEEKUSER offset %ld not implemented; "
- "returning EINVAL", (uintptr_t)addr);
- return (EINVAL);
- }
-
- error = copyout(&val, data, sizeof(val));
- td->td_retval[0] = error;
-
- return (error);
-}
-
-static int
-linux_ptrace_pokeuser(struct thread *td, pid_t pid, void *addr, void *data)
-{
-
- linux_msg(td, "PTRACE_POKEUSER not implemented; returning EINVAL");
- return (EINVAL);
-}
-
-static int
linux_ptrace_setoptions(struct thread *td, pid_t pid, l_ulong data)
{
struct linux_pemuldata *pem;
@@ -440,21 +386,11 @@ linux_ptrace_get_syscall_info(struct thread *td, pid_t pid,
if (lwpinfo.pl_flags & PL_FLAG_SCE) {
si.op = LINUX_PTRACE_SYSCALL_INFO_ENTRY;
si.entry.nr = lwpinfo.pl_syscall_code;
- /*
- * The use of PT_GET_SC_ARGS there is special,
- * implementation of PT_GET_SC_ARGS for Linux-ABI
- * callers emulates Linux bug which strace(1) depends
- * on: at initialization it tests whether ptrace works
- * by calling close(2), or some other single-argument
- * syscall, _with six arguments_, and then verifies
- * whether it can fetch them all using this API;
- * otherwise it bails out.
- */
- error = kern_ptrace(td, PT_GET_SC_ARGS, pid,
- &si.entry.args, sizeof(si.entry.args));
+ error = kern_ptrace(td, PTLINUX_GET_SC_ARGS, pid,
+ si.entry.args, sizeof(si.entry.args));
if (error != 0) {
- linux_msg(td, "PT_GET_SC_ARGS failed with error %d",
- error);
+ linux_msg(td,
+ "PT_LINUX_GET_SC_ARGS failed with error %d", error);
return (error);
}
} else if (lwpinfo.pl_flags & PL_FLAG_SCX) {
@@ -511,6 +447,9 @@ linux_ptrace(struct thread *td, struct linux_ptrace_args *uap)
pid_t pid;
int error, sig;
+ if (!allow_ptrace)
+ return (ENOSYS);
+
pid = (pid_t)uap->pid;
addr = (void *)uap->addr;
diff --git a/sys/compat/linux/linux_rseq.c b/sys/compat/linux/linux_rseq.c
new file mode 100644
index 000000000000..e8de17318d60
--- /dev/null
+++ b/sys/compat/linux/linux_rseq.c
@@ -0,0 +1,84 @@
+/*-
+ * SPDX-License-Identifier: BSD-2-Clause
+ *
+ * Copyright (c) 2022 Dmitry Chagin <dchagin@FreeBSD.org>
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``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 OR CONTRIBUTORS 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.
+ */
+
+#include <sys/param.h>
+#include <sys/systm.h>
+
+#ifdef COMPAT_LINUX32
+#include <machine/../linux32/linux.h>
+#include <machine/../linux32/linux32_proto.h>
+#else
+#include <machine/../linux/linux.h>
+#include <machine/../linux/linux_proto.h>
+#endif
+
+
+enum linux_rseq_cpu_id_state {
+ LINUX_RSEQ_CPU_ID_UNINITIALIZED = -1,
+ LINUX_RSEQ_CPU_ID_REGISTRATION_FAILED = -2,
+};
+
+enum linux_rseq_flags {
+ LINUX_RSEQ_FLAG_UNREGISTER = (1 << 0),
+};
+
+enum linux_rseq_cs_flags_bit {
+ LINUX_RSEQ_CS_FLAG_NO_RESTART_ON_PREEMPT_BIT = 0,
+ LINUX_RSEQ_CS_FLAG_NO_RESTART_ON_SIGNAL_BIT = 1,
+ LINUX_RSEQ_CS_FLAG_NO_RESTART_ON_MIGRATE_BIT = 2,
+};
+
+enum linux_rseq_cs_flags {
+ LINUX_RSEQ_CS_FLAG_NO_RESTART_ON_PREEMPT =
+ (1U << LINUX_RSEQ_CS_FLAG_NO_RESTART_ON_PREEMPT_BIT),
+ LINUX_RSEQ_CS_FLAG_NO_RESTART_ON_SIGNAL =
+ (1U << LINUX_RSEQ_CS_FLAG_NO_RESTART_ON_SIGNAL_BIT),
+ LINUX_RSEQ_CS_FLAG_NO_RESTART_ON_MIGRATE =
+ (1U << LINUX_RSEQ_CS_FLAG_NO_RESTART_ON_MIGRATE_BIT),
+};
+
+struct linux_rseq_cs {
+ uint32_t version;
+ uint32_t flags;
+ uint64_t start_ip;
+ uint64_t post_commit_offset;
+ uint64_t abort_ip;
+} __attribute__((aligned(4 * sizeof(uint64_t))));
+
+struct linux_rseq {
+ uint32_t cpu_id_start;
+ uint32_t cpu_id;
+ uint64_t rseq_cs;
+ uint32_t flags;
+} __attribute__((aligned(4 * sizeof(uint64_t))));
+
+int
+linux_rseq(struct thread *td, struct linux_rseq_args *args)
+{
+
+ return (ENOSYS);
+}
diff --git a/sys/compat/linux/linux_siginfo.h b/sys/compat/linux/linux_siginfo.h
new file mode 100644
index 000000000000..f254b6a22bbd
--- /dev/null
+++ b/sys/compat/linux/linux_siginfo.h
@@ -0,0 +1,234 @@
+/*-
+ * SPDX-License-Identifier: BSD-3-Clause
+ *
+ * Copyright (c) 2004 Tim J. Robbins
+ * Copyright (c) 2001 Doug Rabson
+ * Copyright (c) 1994-1996 Søren Schmidt
+ * All rights reserved.
+ * Copyright (c) 2022 Dmitry Chagin <dchagin@FreeBSD.org>
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer
+ * in this position and unchanged.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. The name of the author may not be used to endorse or promote products
+ * derived from this software without specific prior written permission
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``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.
+ */
+
+#ifndef _LINUX_SIGINFO_H_
+#define _LINUX_SIGINFO_H_
+
+/*
+ * si_code values
+ */
+#define LINUX_SI_USER 0 /* sent by kill, sigsend, raise */
+#define LINUX_SI_KERNEL 0x80 /* sent by the kernel from somewhere */
+#define LINUX_SI_QUEUE -1 /* sent by sigqueue */
+#define LINUX_SI_TIMER -2 /* sent by timer expiration */
+#define LINUX_SI_MESGQ -3 /* sent by real time mesq state change */
+#define LINUX_SI_ASYNCIO -4 /* sent by AIO completion */
+#define LINUX_SI_SIGIO -5 /* sent by queued SIGIO */
+#define LINUX_SI_TKILL -6 /* sent by tkill system call */
+
+/*
+ * SIGILL si_codes
+ */
+#define LINUX_ILL_ILLOPC 1 /* illegal opcode */
+#define LINUX_ILL_ILLOPN 2 /* illegal operand */
+#define LINUX_ILL_ILLADR 3 /* illegal addressing mode */
+#define LINUX_ILL_ILLTRP 4 /* illegal trap */
+#define LINUX_ILL_PRVOPC 5 /* privileged opcode */
+#define LINUX_ILL_PRVREG 6 /* privileged register */
+#define LINUX_ILL_COPROC 7 /* coprocessor error */
+#define LINUX_ILL_BADSTK 8 /* internal stack error */
+#define LINUX_ILL_BADIADDR 9 /* unimplemented instruction address */
+#define LINUX___ILL_BREAK 10 /* (ia64) illegal break */
+#define LINUX___ILL_BNDMOD 11 /* (ia64) bundle-update (modification)
+ * in progress
+ */
+
+/*
+ * SIGFPE si_codes
+ */
+#define LINUX_FPE_INTDIV 1 /* integer divide by zero */
+#define LINUX_FPE_INTOVF 2 /* integer overflow */
+#define LINUX_FPE_FLTDIV 3 /* floating point divide by zero */
+#define LINUX_FPE_FLTOVF 4 /* floating point overflow */
+#define LINUX_FPE_FLTUND 5 /* floating point underflow */
+#define LINUX_FPE_FLTRES 6 /* floating point inexact result */
+#define LINUX_FPE_FLTINV 7 /* floating point invalid operation */
+#define LINUX_FPE_FLTSUB 8 /* (ia64) subscript out of range */
+#define LINUX___FPE_DECOVF 9 /* (ia64) decimal overflow */
+#define LINUX___FPE_DECDIV 10 /* (ia64) decimal division by zero */
+#define LINUX___FPE_DECERR 11 /* (ia64) packed decimal error */
+#define LINUX___FPE_INVASC 12 /* (ia64) invalid ASCII digit */
+#define LINUX___FPE_INVDEC 13 /* (ia64) invalid decimal digit */
+#define LINUX_FPE_FLTUNK 14 /* undiagnosed floating-point exception */
+#define LINUX_FPE_CONDTRAP 15 /* trap on condition */
+
+/*
+ * SIGSEGV si_codes
+ */
+#define LINUX_SEGV_MAPERR 1 /* address not mapped to object */
+#define LINUX_SEGV_ACCERR 2 /* invalid permissions for mapped object */
+#define LINUX_SEGV_BNDERR 3 /* failed address bound checks */
+#ifdef __ia64__
+#define LINUX___SEGV_PSTKOVF 4 /* paragraph stack overflow */
+#else
+#define LINUX_SEGV_PKUERR 4 /* failed protection key checks */
+#endif
+#define LINUX_SEGV_ACCADI 5 /* ADI not enabled for mapped object */
+#define LINUX_SEGV_ADIDERR 6 /* Disrupting MCD error */
+#define LINUX_SEGV_ADIPERR 7 /* Precise MCD exception */
+#define LINUX_SEGV_MTEAERR 8 /* Asynchronous ARM MTE error */
+#define LINUX_SEGV_MTESERR 9 /* Synchronous ARM MTE exception */
+
+/*
+ * SIGBUS si_codes
+ */
+#define LINUX_BUS_ADRALN 1 /* invalid address alignment */
+#define LINUX_BUS_ADRERR 2 /* non-existent physical address */
+#define LINUX_BUS_OBJERR 3 /* object specific hardware error */
+
+#define LINUX_BUS_MCEERR_AR 4 /* hardware memory error consumed
+ * on a machine check:
+ * action required
+ */
+#define LINUX_BUS_MCEERR_AO 5 /* hardware memory error detected
+ * in process but not consumed:
+ * action optional
+ */
+
+/*
+ * SIGTRAP si_codes
+ */
+#define LINUX_TRAP_BRKPT 1 /* process breakpoint */
+#define LINUX_TRAP_TRACE 2 /* process trace trap */
+#define LINUX_TRAP_BRANCH 3 /* process taken branch trap */
+#define LINUX_TRAP_HWBKPT 4 /* hardware breakpoint/watchpoint */
+#define LINUX_TRAP_UNK 5 /* undiagnosed trap */
+#define LINUX_TRAP_PERF 6 /* perf event with sigtrap=1 */
+
+/*
+ * SIGCHLD si_codes
+ */
+#define LINUX_CLD_EXITED 1 /* child has exited */
+#define LINUX_CLD_KILLED 2 /* child was killed */
+#define LINUX_CLD_DUMPED 3 /* child terminated abnormally */
+#define LINUX_CLD_TRAPPED 4 /* traced child has trapped */
+#define LINUX_CLD_STOPPED 5 /* child has stopped */
+#define LINUX_CLD_CONTINUED 6 /* stopped child has continued */
+
+/*
+ * SIGPOLL (or any other signal without signal specific si_codes) si_codes
+ */
+#define LINUX_POLL_IN 1 /* data input available */
+#define LINUX_POLL_OUT 2 /* output buffers available */
+#define LINUX_POLL_MSG 3 /* input message available */
+#define LINUX_POLL_ERR 4 /* i/o error */
+#define LINUX_POLL_PRI 5 /* high priority input available */
+#define LINUX_POLL_HUP 6 /* device disconnected */
+
+/*
+ * SIGSYS si_codes
+ */
+#define LINUX_SYS_SECCOMP 1 /* seccomp triggered */
+#define LINUX_SYS_USER_DISPATCH 2 /* syscall user dispatch triggered */
+
+/*
+ * SIGEMT si_codes
+ */
+#define LINUX_EMT_TAGOVF 1 /* tag overflow */
+
+typedef union l_sigval {
+ l_int sival_int;
+ l_uintptr_t sival_ptr;
+} l_sigval_t;
+
+#define LINUX_SI_MAX_SIZE 128
+
+union __sifields {
+ struct {
+ l_pid_t _pid;
+ l_uid_t _uid;
+ } _kill;
+
+ struct {
+ l_timer_t _tid;
+ l_int _overrun;
+ char _pad[sizeof(l_uid_t) - sizeof(int)];
+ union l_sigval _sigval;
+ l_uint _sys_private;
+ } _timer;
+
+ struct {
+ l_pid_t _pid; /* sender's pid */
+ l_uid_t _uid; /* sender's uid */
+ union l_sigval _sigval;
+ } _rt;
+
+ struct {
+ l_pid_t _pid; /* which child */
+ l_uid_t _uid; /* sender's uid */
+ l_int _status; /* exit code */
+ l_clock_t _utime;
+ l_clock_t _stime;
+ } _sigchld;
+
+ struct {
+ l_uintptr_t _addr; /* Faulting insn/memory ref. */
+ } _sigfault;
+
+ struct {
+ l_long _band; /* POLL_IN,POLL_OUT,POLL_MSG */
+ l_int _fd;
+ } _sigpoll;
+};
+
+typedef struct l_siginfo {
+ union {
+ struct {
+ l_int lsi_signo;
+ l_int lsi_errno;
+ l_int lsi_code;
+ union __sifields _sifields;
+ };
+ l_int _pad[LINUX_SI_MAX_SIZE/sizeof(l_int)];
+ };
+} l_siginfo_t;
+
+_Static_assert(sizeof(l_siginfo_t) == LINUX_SI_MAX_SIZE, "l_siginfo_t size");
+
+#define lsi_pid _sifields._kill._pid
+#define lsi_uid _sifields._kill._uid
+#define lsi_tid _sifields._timer._tid
+#define lsi_overrun _sifields._timer._overrun
+#define lsi_sys_private _sifields._timer._sys_private
+#define lsi_status _sifields._sigchld._status
+#define lsi_utime _sifields._sigchld._utime
+#define lsi_stime _sifields._sigchld._stime
+#define lsi_value _sifields._rt._sigval
+#define lsi_int _sifields._rt._sigval.sival_int
+#define lsi_ptr _sifields._rt._sigval.sival_ptr
+#define lsi_addr _sifields._sigfault._addr
+#define lsi_band _sifields._sigpoll._band
+#define lsi_fd _sifields._sigpoll._fd
+
+#endif /* _LINUX_SIGINFO_H_ */
+
diff --git a/sys/compat/linux/linux_signal.c b/sys/compat/linux/linux_signal.c
index 786bcab2bf5e..9a84700b3949 100644
--- a/sys/compat/linux/linux_signal.c
+++ b/sys/compat/linux/linux_signal.c
@@ -26,24 +26,23 @@
* SUCH DAMAGE.
*/
-#include <sys/cdefs.h>
-__FBSDID("$FreeBSD$");
+#include "opt_ktrace.h"
#include <sys/param.h>
-#include <sys/systm.h>
#include <sys/ktr.h>
#include <sys/lock.h>
#include <sys/mutex.h>
-#include <sys/sx.h>
#include <sys/proc.h>
#include <sys/signalvar.h>
+#include <sys/sx.h>
#include <sys/syscallsubr.h>
#include <sys/sysproto.h>
+#ifdef KTRACE
+#include <sys/ktrace.h>
+#endif
#include <security/audit/audit.h>
-#include "opt_compat.h"
-
#ifdef COMPAT_LINUX32
#include <machine/../linux32/linux.h>
#include <machine/../linux32/linux32_proto.h>
@@ -53,14 +52,19 @@ __FBSDID("$FreeBSD$");
#endif
#include <compat/linux/linux_mib.h>
#include <compat/linux/linux_signal.h>
-#include <compat/linux/linux_timer.h>
+#include <compat/linux/linux_time.h>
#include <compat/linux/linux_util.h>
#include <compat/linux/linux_emul.h>
#include <compat/linux/linux_misc.h>
-static int linux_do_tkill(struct thread *td, struct thread *tdt,
+static int linux_pksignal(struct thread *td, int pid, int sig,
ksiginfo_t *ksi);
-static void sicode_to_lsicode(int si_code, int *lsi_code);
+static int linux_psignal(struct thread *td, int pid, int sig);
+static int linux_tdksignal(struct thread *td, lwpid_t tid,
+ int tgid, int sig, ksiginfo_t *ksi);
+static int linux_tdsignal(struct thread *td, lwpid_t tid,
+ int tgid, int sig);
+static void sicode_to_lsicode(int sig, int si_code, int *lsi_code);
static int linux_common_rt_sigtimedwait(struct thread *,
l_sigset_t *, struct timespec *, l_siginfo_t *,
l_size_t);
@@ -166,22 +170,35 @@ linux_do_sigaction(struct thread *td, int linux_sig, l_sigaction_t *linux_nsa,
if (!LINUX_SIG_VALID(linux_sig))
return (EINVAL);
+ sig = linux_to_bsd_signal(linux_sig);
osa = (linux_osa != NULL) ? &oact : NULL;
if (linux_nsa != NULL) {
nsa = &act;
linux_to_bsd_sigaction(linux_nsa, nsa);
+#ifdef KTRACE
+ if (KTRPOINT(td, KTR_STRUCT))
+ linux_ktrsigset(&linux_nsa->lsa_mask,
+ sizeof(linux_nsa->lsa_mask));
+#endif
+ if ((sig == SIGKILL || sig == SIGSTOP) &&
+ nsa->sa_handler == SIG_DFL)
+ return (EINVAL);
} else
nsa = NULL;
- sig = linux_to_bsd_signal(linux_sig);
error = kern_sigaction(td, sig, nsa, osa, 0);
- if (error)
+ if (error != 0)
return (error);
- if (linux_osa != NULL)
+ if (linux_osa != NULL) {
bsd_to_linux_sigaction(osa, linux_osa);
-
+#ifdef KTRACE
+ if (KTRPOINT(td, KTR_STRUCT))
+ linux_ktrsigset(&linux_osa->lsa_mask,
+ sizeof(linux_osa->lsa_mask));
+#endif
+ }
return (0);
}
@@ -196,7 +213,7 @@ linux_sigaltstack(struct thread *td, struct linux_sigaltstack_args *uap)
LINUX_CTR2(sigaltstack, "%p, %p", uap->uss, uap->uoss);
if (uap->uss != NULL) {
- error = copyin(uap->uss, &lss, sizeof(l_stack_t));
+ error = copyin(uap->uss, &lss, sizeof(lss));
if (error != 0)
return (error);
@@ -210,7 +227,7 @@ linux_sigaltstack(struct thread *td, struct linux_sigaltstack_args *uap)
lss.ss_sp = PTROUT(oss.ss_sp);
lss.ss_size = oss.ss_size;
lss.ss_flags = bsd_to_linux_sigaltstack(oss.ss_flags);
- error = copyout(&lss, uap->uoss, sizeof(l_stack_t));
+ error = copyout(&lss, uap->uoss, sizeof(lss));
}
return (error);
@@ -244,8 +261,8 @@ linux_rt_sigaction(struct thread *td, struct linux_rt_sigaction_args *args)
return (EINVAL);
if (args->act != NULL) {
- error = copyin(args->act, &nsa, sizeof(l_sigaction_t));
- if (error)
+ error = copyin(args->act, &nsa, sizeof(nsa));
+ if (error != 0)
return (error);
}
@@ -253,19 +270,17 @@ linux_rt_sigaction(struct thread *td, struct linux_rt_sigaction_args *args)
args->act ? &nsa : NULL,
args->oact ? &osa : NULL);
- if (args->oact != NULL && !error) {
- error = copyout(&osa, args->oact, sizeof(l_sigaction_t));
- }
+ if (args->oact != NULL && error == 0)
+ error = copyout(&osa, args->oact, sizeof(osa));
return (error);
}
static int
-linux_do_sigprocmask(struct thread *td, int how, l_sigset_t *new,
+linux_do_sigprocmask(struct thread *td, int how, sigset_t *new,
l_sigset_t *old)
{
- sigset_t omask, nmask;
- sigset_t *nmaskp;
+ sigset_t omask;
int error;
td->td_retval[0] = 0;
@@ -283,12 +298,7 @@ linux_do_sigprocmask(struct thread *td, int how, l_sigset_t *new,
default:
return (EINVAL);
}
- if (new != NULL) {
- linux_to_bsd_sigset(new, &nmask);
- nmaskp = &nmask;
- } else
- nmaskp = NULL;
- error = kern_sigprocmask(td, how, nmaskp, &omask, 0);
+ error = kern_sigprocmask(td, how, new, &omask, 0);
if (error == 0 && old != NULL)
bsd_to_linux_sigset(&omask, old);
@@ -300,24 +310,34 @@ int
linux_sigprocmask(struct thread *td, struct linux_sigprocmask_args *args)
{
l_osigset_t mask;
- l_sigset_t set, oset;
+ l_sigset_t lset, oset;
+ sigset_t set;
int error;
if (args->mask != NULL) {
- error = copyin(args->mask, &mask, sizeof(l_osigset_t));
- if (error)
+ error = copyin(args->mask, &mask, sizeof(mask));
+ if (error != 0)
return (error);
- LINUX_SIGEMPTYSET(set);
- set.__mask = mask;
+ LINUX_SIGEMPTYSET(lset);
+ lset.__mask = mask;
+#ifdef KTRACE
+ if (KTRPOINT(td, KTR_STRUCT))
+ linux_ktrsigset(&lset, sizeof(lset));
+#endif
+ linux_to_bsd_sigset(&lset, &set);
}
error = linux_do_sigprocmask(td, args->how,
args->mask ? &set : NULL,
args->omask ? &oset : NULL);
- if (args->omask != NULL && !error) {
+ if (args->omask != NULL && error == 0) {
+#ifdef KTRACE
+ if (KTRPOINT(td, KTR_STRUCT))
+ linux_ktrsigset(&oset, sizeof(oset));
+#endif
mask = oset.__mask;
- error = copyout(&mask, args->omask, sizeof(l_osigset_t));
+ error = copyout(&mask, args->omask, sizeof(mask));
}
return (error);
@@ -327,24 +347,24 @@ linux_sigprocmask(struct thread *td, struct linux_sigprocmask_args *args)
int
linux_rt_sigprocmask(struct thread *td, struct linux_rt_sigprocmask_args *args)
{
- l_sigset_t set, oset;
+ l_sigset_t oset;
+ sigset_t set, *pset;
int error;
- if (args->sigsetsize != sizeof(l_sigset_t))
+ error = linux_copyin_sigset(td, args->mask, args->sigsetsize,
+ &set, &pset);
+ if (error != 0)
return (EINVAL);
- if (args->mask != NULL) {
- error = copyin(args->mask, &set, sizeof(l_sigset_t));
- if (error)
- return (error);
- }
-
- error = linux_do_sigprocmask(td, args->how,
- args->mask ? &set : NULL,
+ error = linux_do_sigprocmask(td, args->how, pset,
args->omask ? &oset : NULL);
- if (args->omask != NULL && !error) {
- error = copyout(&oset, args->omask, sizeof(l_sigset_t));
+ if (args->omask != NULL && error == 0) {
+#ifdef KTRACE
+ if (KTRPOINT(td, KTR_STRUCT))
+ linux_ktrsigset(&oset, sizeof(oset));
+#endif
+ error = copyout(&oset, args->omask, sizeof(oset));
}
return (error);
@@ -361,6 +381,10 @@ linux_sgetmask(struct thread *td, struct linux_sgetmask_args *args)
bsd_to_linux_sigset(&td->td_sigmask, &mask);
PROC_UNLOCK(p);
td->td_retval[0] = mask.__mask;
+#ifdef KTRACE
+ if (KTRPOINT(td, KTR_STRUCT))
+ linux_ktrsigset(&mask, sizeof(mask));
+#endif
return (0);
}
@@ -377,6 +401,10 @@ linux_ssetmask(struct thread *td, struct linux_ssetmask_args *args)
LINUX_SIGEMPTYSET(lset);
lset.__mask = args->mask;
linux_to_bsd_sigset(&lset, &bset);
+#ifdef KTRACE
+ if (KTRPOINT(td, KTR_STRUCT))
+ linux_ktrsigset(&lset, sizeof(lset));
+#endif
td->td_sigmask = bset;
SIG_CANTMASK(td->td_sigmask);
signotify(td);
@@ -398,6 +426,10 @@ linux_sigpending(struct thread *td, struct linux_sigpending_args *args)
SIGSETAND(bset, td->td_sigmask);
PROC_UNLOCK(p);
bsd_to_linux_sigset(&bset, &lset);
+#ifdef KTRACE
+ if (KTRPOINT(td, KTR_STRUCT))
+ linux_ktrsigset(&lset, sizeof(lset));
+#endif
mask = lset.__mask;
return (copyout(&mask, args->mask, sizeof(mask)));
}
@@ -423,6 +455,10 @@ linux_rt_sigpending(struct thread *td, struct linux_rt_sigpending_args *args)
SIGSETAND(bset, td->td_sigmask);
PROC_UNLOCK(p);
bsd_to_linux_sigset(&bset, &lset);
+#ifdef KTRACE
+ if (KTRPOINT(td, KTR_STRUCT))
+ linux_ktrsigset(&lset, sizeof(lset));
+#endif
return (copyout(&lset, args->set, args->sigsetsize));
}
@@ -431,13 +467,10 @@ linux_rt_sigtimedwait(struct thread *td,
struct linux_rt_sigtimedwait_args *args)
{
struct timespec ts, *tsa;
- struct l_timespec lts;
int error;
if (args->timeout) {
- if ((error = copyin(args->timeout, &lts, sizeof(lts))))
- return (error);
- error = linux_to_native_timespec(&ts, &lts);
+ error = linux_get_timespec(&ts, args->timeout);
if (error != 0)
return (error);
tsa = &ts;
@@ -453,21 +486,17 @@ linux_common_rt_sigtimedwait(struct thread *td, l_sigset_t *mask,
struct timespec *tsa, l_siginfo_t *ptr, l_size_t sigsetsize)
{
int error, sig;
- l_sigset_t lset;
sigset_t bset;
l_siginfo_t lsi;
ksiginfo_t ksi;
- if (sigsetsize != sizeof(l_sigset_t))
- return (EINVAL);
-
- if ((error = copyin(mask, &lset, sizeof(lset))))
+ error = linux_copyin_sigset(td, mask, sigsetsize, &bset, NULL);
+ if (error != 0)
return (error);
- linux_to_bsd_sigset(&lset, &bset);
ksiginfo_init(&ksi);
error = kern_sigtimedwait(td, bset, &ksi, tsa);
- if (error)
+ if (error != 0)
return (error);
sig = bsd_to_linux_signal(ksi.ksi_signo);
@@ -489,13 +518,10 @@ linux_rt_sigtimedwait_time64(struct thread *td,
struct linux_rt_sigtimedwait_time64_args *args)
{
struct timespec ts, *tsa;
- struct l_timespec64 lts;
int error;
if (args->timeout) {
- if ((error = copyin(args->timeout, &lts, sizeof(lts))))
- return (error);
- error = linux_to_native_timespec64(&ts, &lts);
+ error = linux_get_timespec64(&ts, args->timeout);
if (error != 0)
return (error);
tsa = &ts;
@@ -510,7 +536,7 @@ linux_rt_sigtimedwait_time64(struct thread *td,
int
linux_kill(struct thread *td, struct linux_kill_args *args)
{
- int l_signum;
+ int sig;
/*
* Allow signal 0 as a means to check for privileges
@@ -519,40 +545,19 @@ linux_kill(struct thread *td, struct linux_kill_args *args)
return (EINVAL);
if (args->signum > 0)
- l_signum = linux_to_bsd_signal(args->signum);
+ sig = linux_to_bsd_signal(args->signum);
else
- l_signum = 0;
-
- return (kern_kill(td, args->pid, l_signum));
-}
-
-static int
-linux_do_tkill(struct thread *td, struct thread *tdt, ksiginfo_t *ksi)
-{
- struct proc *p;
- int error;
-
- p = tdt->td_proc;
- AUDIT_ARG_SIGNUM(ksi->ksi_signo);
- AUDIT_ARG_PID(p->p_pid);
- AUDIT_ARG_PROCESS(p);
-
- error = p_cansignal(td, p, ksi->ksi_signo);
- if (error != 0 || ksi->ksi_signo == 0)
- goto out;
-
- tdksignal(tdt, ksi->ksi_signo, ksi);
+ sig = 0;
-out:
- PROC_UNLOCK(p);
- return (error);
+ if (args->pid > PID_MAX)
+ return (linux_psignal(td, args->pid, sig));
+ else
+ return (kern_kill(td, args->pid, sig));
}
int
linux_tgkill(struct thread *td, struct linux_tgkill_args *args)
{
- struct thread *tdt;
- ksiginfo_t ksi;
int sig;
if (args->pid <= 0 || args->tgid <=0)
@@ -569,17 +574,7 @@ linux_tgkill(struct thread *td, struct linux_tgkill_args *args)
else
sig = 0;
- tdt = linux_tdfind(td, args->pid, args->tgid);
- if (tdt == NULL)
- return (ESRCH);
-
- ksiginfo_init(&ksi);
- ksi.ksi_signo = sig;
- ksi.ksi_code = SI_LWP;
- ksi.ksi_errno = 0;
- ksi.ksi_pid = td->td_proc->p_pid;
- ksi.ksi_uid = td->td_proc->p_ucred->cr_ruid;
- return (linux_do_tkill(td, tdt, &ksi));
+ return (linux_tdsignal(td, args->pid, args->tgid, sig));
}
/*
@@ -588,8 +583,6 @@ linux_tgkill(struct thread *td, struct linux_tgkill_args *args)
int
linux_tkill(struct thread *td, struct linux_tkill_args *args)
{
- struct thread *tdt;
- ksiginfo_t ksi;
int sig;
if (args->tid <= 0)
@@ -600,21 +593,65 @@ linux_tkill(struct thread *td, struct linux_tkill_args *args)
sig = linux_to_bsd_signal(args->sig);
- tdt = linux_tdfind(td, args->tid, -1);
- if (tdt == NULL)
- return (ESRCH);
+ return (linux_tdsignal(td, args->tid, -1, sig));
+}
- ksiginfo_init(&ksi);
- ksi.ksi_signo = sig;
- ksi.ksi_code = SI_LWP;
- ksi.ksi_errno = 0;
- ksi.ksi_pid = td->td_proc->p_pid;
- ksi.ksi_uid = td->td_proc->p_ucred->cr_ruid;
- return (linux_do_tkill(td, tdt, &ksi));
+static int
+sigfpe_sicode2lsicode(int si_code)
+{
+
+ switch (si_code) {
+ case FPE_INTOVF:
+ return (LINUX_FPE_INTOVF);
+ case FPE_INTDIV:
+ return (LINUX_FPE_INTDIV);
+ case FPE_FLTIDO:
+ return (LINUX_FPE_FLTUNK);
+ default:
+ return (si_code);
+ }
+}
+
+static int
+sigbus_sicode2lsicode(int si_code)
+{
+
+ switch (si_code) {
+ case BUS_OOMERR:
+ return (LINUX_BUS_MCEERR_AR);
+ default:
+ return (si_code);
+ }
+}
+
+static int
+sigsegv_sicode2lsicode(int si_code)
+{
+
+ switch (si_code) {
+ case SEGV_PKUERR:
+ return (LINUX_SEGV_PKUERR);
+ default:
+ return (si_code);
+ }
+}
+
+static int
+sigtrap_sicode2lsicode(int si_code)
+{
+
+ switch (si_code) {
+ case TRAP_DTRACE:
+ return (LINUX_TRAP_TRACE);
+ case TRAP_CAP:
+ return (LINUX_TRAP_UNK);
+ default:
+ return (si_code);
+ }
}
static void
-sicode_to_lsicode(int si_code, int *lsi_code)
+sicode_to_lsicode(int sig, int si_code, int *lsi_code)
{
switch (si_code) {
@@ -640,7 +677,23 @@ sicode_to_lsicode(int si_code, int *lsi_code)
*lsi_code = LINUX_SI_TKILL;
break;
default:
- *lsi_code = si_code;
+ switch (sig) {
+ case LINUX_SIGFPE:
+ *lsi_code = sigfpe_sicode2lsicode(si_code);
+ break;
+ case LINUX_SIGBUS:
+ *lsi_code = sigbus_sicode2lsicode(si_code);
+ break;
+ case LINUX_SIGSEGV:
+ *lsi_code = sigsegv_sicode2lsicode(si_code);
+ break;
+ case LINUX_SIGTRAP:
+ *lsi_code = sigtrap_sicode2lsicode(si_code);
+ break;
+ default:
+ *lsi_code = si_code;
+ break;
+ }
break;
}
}
@@ -649,9 +702,9 @@ void
siginfo_to_lsiginfo(const siginfo_t *si, l_siginfo_t *lsi, l_int sig)
{
- /* sig alredy converted */
+ /* sig already converted */
lsi->lsi_signo = sig;
- sicode_to_lsicode(si->si_code, &lsi->lsi_code);
+ sicode_to_lsicode(sig, si->si_code, &lsi->lsi_code);
switch (si->si_code) {
case SI_LWP:
@@ -716,14 +769,14 @@ siginfo_to_lsiginfo(const siginfo_t *si, l_siginfo_t *lsi, l_int sig)
}
}
-int
+static int
lsiginfo_to_siginfo(struct thread *td, const l_siginfo_t *lsi,
siginfo_t *si, int sig)
{
switch (lsi->lsi_code) {
case LINUX_SI_TKILL:
- if (linux_kernver(td) >= LINUX_KERNVER_2006039) {
+ if (linux_kernver(td) >= LINUX_KERNVER(2,6,39)) {
linux_msg(td, "SI_TKILL forbidden since 2.6.39");
return (EPERM);
}
@@ -756,7 +809,6 @@ int
linux_rt_sigqueueinfo(struct thread *td, struct linux_rt_sigqueueinfo_args *args)
{
l_siginfo_t linfo;
- struct proc *p;
ksiginfo_t ksi;
int error;
int sig;
@@ -778,25 +830,13 @@ linux_rt_sigqueueinfo(struct thread *td, struct linux_rt_sigqueueinfo_args *args
if (error != 0)
return (error);
- error = ESRCH;
- if ((p = pfind_any(args->pid)) != NULL) {
- error = p_cansignal(td, p, sig);
- if (error != 0) {
- PROC_UNLOCK(p);
- return (error);
- }
- error = tdsendsignal(p, NULL, sig, &ksi);
- PROC_UNLOCK(p);
- }
-
- return (error);
+ return (linux_pksignal(td, args->pid, sig, &ksi));
}
int
linux_rt_tgsigqueueinfo(struct thread *td, struct linux_rt_tgsigqueueinfo_args *args)
{
l_siginfo_t linfo;
- struct thread *tds;
ksiginfo_t ksi;
int error;
int sig;
@@ -817,27 +857,125 @@ linux_rt_tgsigqueueinfo(struct thread *td, struct linux_rt_tgsigqueueinfo_args *
if (error != 0)
return (error);
- tds = linux_tdfind(td, args->tid, args->tgid);
- if (tds == NULL)
- return (ESRCH);
-
- return (linux_do_tkill(td, tds, &ksi));
+ return (linux_tdksignal(td, args->tid, args->tgid, sig, &ksi));
}
int
linux_rt_sigsuspend(struct thread *td, struct linux_rt_sigsuspend_args *uap)
{
- l_sigset_t lmask;
sigset_t sigmask;
int error;
- if (uap->sigsetsize != sizeof(l_sigset_t))
- return (EINVAL);
-
- error = copyin(uap->newset, &lmask, sizeof(l_sigset_t));
+ error = linux_copyin_sigset(td, uap->newset, uap->sigsetsize,
+ &sigmask, NULL);
if (error != 0)
return (error);
- linux_to_bsd_sigset(&lmask, &sigmask);
return (kern_sigsuspend(td, sigmask));
}
+
+static int
+linux_tdksignal(struct thread *td, lwpid_t tid, int tgid, int sig,
+ ksiginfo_t *ksi)
+{
+ struct thread *tdt;
+ struct proc *p;
+ int error;
+
+ tdt = linux_tdfind(td, tid, tgid);
+ if (tdt == NULL)
+ return (ESRCH);
+
+ p = tdt->td_proc;
+ AUDIT_ARG_SIGNUM(sig);
+ AUDIT_ARG_PID(p->p_pid);
+ AUDIT_ARG_PROCESS(p);
+
+ error = p_cansignal(td, p, sig);
+ if (error != 0 || sig == 0)
+ goto out;
+
+ tdksignal(tdt, sig, ksi);
+
+out:
+ PROC_UNLOCK(p);
+ return (error);
+}
+
+static int
+linux_tdsignal(struct thread *td, lwpid_t tid, int tgid, int sig)
+{
+ ksiginfo_t ksi;
+
+ ksiginfo_init(&ksi);
+ ksi.ksi_signo = sig;
+ ksi.ksi_code = SI_LWP;
+ ksi.ksi_pid = td->td_proc->p_pid;
+ ksi.ksi_uid = td->td_proc->p_ucred->cr_ruid;
+ return (linux_tdksignal(td, tid, tgid, sig, &ksi));
+}
+
+static int
+linux_pksignal(struct thread *td, int pid, int sig, ksiginfo_t *ksi)
+{
+ struct thread *tdt;
+ struct proc *p;
+ int error;
+
+ tdt = linux_tdfind(td, pid, -1);
+ if (tdt == NULL)
+ return (ESRCH);
+
+ p = tdt->td_proc;
+ AUDIT_ARG_SIGNUM(sig);
+ AUDIT_ARG_PID(p->p_pid);
+ AUDIT_ARG_PROCESS(p);
+
+ error = p_cansignal(td, p, sig);
+ if (error != 0 || sig == 0)
+ goto out;
+
+ pksignal(p, sig, ksi);
+
+out:
+ PROC_UNLOCK(p);
+ return (error);
+}
+
+static int
+linux_psignal(struct thread *td, int pid, int sig)
+{
+ ksiginfo_t ksi;
+
+ ksiginfo_init(&ksi);
+ ksi.ksi_signo = sig;
+ ksi.ksi_code = SI_LWP;
+ ksi.ksi_pid = td->td_proc->p_pid;
+ ksi.ksi_uid = td->td_proc->p_ucred->cr_ruid;
+ return (linux_pksignal(td, pid, sig, &ksi));
+}
+
+int
+linux_copyin_sigset(struct thread *td, l_sigset_t *lset,
+ l_size_t sigsetsize, sigset_t *set, sigset_t **pset)
+{
+ l_sigset_t lmask;
+ int error;
+
+ if (sigsetsize != sizeof(l_sigset_t))
+ return (EINVAL);
+ if (lset != NULL) {
+ error = copyin(lset, &lmask, sizeof(lmask));
+ if (error != 0)
+ return (error);
+ linux_to_bsd_sigset(&lmask, set);
+ if (pset != NULL)
+ *pset = set;
+#ifdef KTRACE
+ if (KTRPOINT(td, KTR_STRUCT))
+ linux_ktrsigset(&lmask, sizeof(lmask));
+#endif
+ } else if (pset != NULL)
+ *pset = NULL;
+ return (0);
+}
diff --git a/sys/compat/linux/linux_signal.h b/sys/compat/linux/linux_signal.h
index f434ab1b1b35..3f3599f4027e 100644
--- a/sys/compat/linux/linux_signal.h
+++ b/sys/compat/linux/linux_signal.h
@@ -1,5 +1,5 @@
/*-
- * SPDX-License-Identifier: BSD-2-Clause-FreeBSD
+ * SPDX-License-Identifier: BSD-2-Clause
*
* Copyright (c) 2000 Marcel Moolenaar
* All rights reserved.
@@ -24,28 +24,14 @@
* 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.
- *
- * $FreeBSD$
*/
#ifndef _LINUX_SIGNAL_H_
#define _LINUX_SIGNAL_H_
-/*
- * si_code values
- */
-#define LINUX_SI_USER 0 /* sent by kill, sigsend, raise */
-#define LINUX_SI_KERNEL 0x80 /* sent by the kernel from somewhere */
-#define LINUX_SI_QUEUE -1 /* sent by sigqueue */
-#define LINUX_SI_TIMER -2 /* sent by timer expiration */
-#define LINUX_SI_MESGQ -3 /* sent by real time mesq state change */
-#define LINUX_SI_ASYNCIO -4 /* sent by AIO completion */
-#define LINUX_SI_SIGIO -5 /* sent by queued SIGIO */
-#define LINUX_SI_TKILL -6 /* sent by tkill system call */
-
int linux_do_sigaction(struct thread *, int, l_sigaction_t *, l_sigaction_t *);
void siginfo_to_lsiginfo(const siginfo_t *si, l_siginfo_t *lsi, l_int sig);
-int lsiginfo_to_siginfo(struct thread *td, const l_siginfo_t *lsi,
- siginfo_t *si, int sig);
+int linux_copyin_sigset(struct thread *td, l_sigset_t *, l_size_t, sigset_t *,
+ sigset_t **);
#endif /* _LINUX_SIGNAL_H_ */
diff --git a/sys/compat/linux/linux_socket.c b/sys/compat/linux/linux_socket.c
index a2b45edf7bdc..b1a483ce611c 100644
--- a/sys/compat/linux/linux_socket.c
+++ b/sys/compat/linux/linux_socket.c
@@ -1,5 +1,5 @@
/*-
- * SPDX-License-Identifier: BSD-2-Clause-FreeBSD
+ * SPDX-License-Identifier: BSD-2-Clause
*
* Copyright (c) 1995 Søren Schmidt
* All rights reserved.
@@ -26,32 +26,21 @@
* SUCH DAMAGE.
*/
-#include <sys/cdefs.h>
-__FBSDID("$FreeBSD$");
-
-/* XXX we use functions that might not exist. */
-#include "opt_compat.h"
#include "opt_inet6.h"
#include <sys/param.h>
-#include <sys/proc.h>
-#include <sys/systm.h>
-#include <sys/sysproto.h>
#include <sys/capsicum.h>
-#include <sys/fcntl.h>
-#include <sys/file.h>
#include <sys/filedesc.h>
#include <sys/limits.h>
-#include <sys/lock.h>
#include <sys/malloc.h>
-#include <sys/mutex.h>
#include <sys/mbuf.h>
+#include <sys/proc.h>
+#include <sys/protosw.h>
#include <sys/socket.h>
#include <sys/socketvar.h>
#include <sys/syscallsubr.h>
-#include <sys/uio.h>
-#include <sys/stat.h>
-#include <sys/syslog.h>
+#include <sys/sysproto.h>
+#include <sys/vnode.h>
#include <sys/un.h>
#include <sys/unistd.h>
@@ -60,7 +49,6 @@ __FBSDID("$FreeBSD$");
#include <net/if.h>
#include <net/vnet.h>
#include <netinet/in.h>
-#include <netinet/in_systm.h>
#include <netinet/ip.h>
#include <netinet/tcp.h>
#ifdef INET6
@@ -69,6 +57,7 @@ __FBSDID("$FreeBSD$");
#endif
#ifdef COMPAT_LINUX32
+#include <compat/freebsd32/freebsd32_util.h>
#include <machine/../linux32/linux.h>
#include <machine/../linux32/linux32_proto.h>
#else
@@ -76,12 +65,23 @@ __FBSDID("$FreeBSD$");
#include <machine/../linux/linux_proto.h>
#endif
#include <compat/linux/linux_common.h>
+#include <compat/linux/linux_emul.h>
#include <compat/linux/linux_file.h>
#include <compat/linux/linux_mib.h>
#include <compat/linux/linux_socket.h>
-#include <compat/linux/linux_timer.h>
+#include <compat/linux/linux_time.h>
#include <compat/linux/linux_util.h>
+_Static_assert(offsetof(struct l_ifreq, ifr_ifru) ==
+ offsetof(struct ifreq, ifr_ifru),
+ "Linux ifreq members names should be equal to FreeeBSD");
+_Static_assert(offsetof(struct l_ifreq, ifr_index) ==
+ offsetof(struct ifreq, ifr_index),
+ "Linux ifreq members names should be equal to FreeeBSD");
+_Static_assert(offsetof(struct l_ifreq, ifr_name) ==
+ offsetof(struct ifreq, ifr_name),
+ "Linux ifreq members names should be equal to FreeeBSD");
+
#define SECURITY_CONTEXT_STRING "unconfined"
static int linux_sendmsg_common(struct thread *, l_int, struct l_msghdr *,
@@ -90,6 +90,8 @@ static int linux_recvmsg_common(struct thread *, l_int, struct l_msghdr *,
l_uint, struct msghdr *);
static int linux_set_socket_flags(int, int *);
+#define SOL_NETLINK 270
+
static int
linux_to_bsd_sockopt_level(int level)
{
@@ -133,7 +135,6 @@ linux_to_bsd_ip_sockopt(int opt)
LINUX_RATELIMIT_MSG_NOTTESTED("IPv4 socket option IP_RECVTTL");
return (IP_RECVTTL);
case LINUX_IP_RECVTOS:
- LINUX_RATELIMIT_MSG_NOTTESTED("IPv4 socket option IP_RECVTOS");
return (IP_RECVTOS);
case LINUX_IP_FREEBIND:
LINUX_RATELIMIT_MSG_NOTTESTED("IPv4 socket option IP_FREEBIND");
@@ -179,6 +180,8 @@ linux_to_bsd_ip_sockopt(int opt)
case LINUX_MCAST_LEAVE_SOURCE_GROUP:
LINUX_RATELIMIT_MSG_NOTTESTED("IPv4 socket option IP_MCAST_LEAVE_SOURCE_GROUP");
return (MCAST_LEAVE_SOURCE_GROUP);
+ case LINUX_IP_RECVORIGDSTADDR:
+ return (IP_RECVORIGDSTADDR);
/* known but not implemented sockopts */
case LINUX_IP_ROUTER_ALERT:
@@ -497,6 +500,11 @@ linux_to_bsd_ip6_sockopt(int opt)
"unsupported IPv6 socket option IPV6_RECVFRAGSIZE (%d)",
opt);
return (-2);
+ case LINUX_IPV6_RECVERR:
+ LINUX_RATELIMIT_MSG_OPT1(
+ "unsupported IPv6 socket option IPV6_RECVERR (%d), you can not get extended reliability info in linux programs",
+ opt);
+ return (-2);
/* unknown sockopts */
default:
@@ -547,12 +555,18 @@ linux_to_bsd_so_sockopt(int opt)
return (SO_RCVTIMEO);
case LINUX_SO_SNDTIMEO:
return (SO_SNDTIMEO);
- case LINUX_SO_TIMESTAMP:
+ case LINUX_SO_TIMESTAMPO:
+ case LINUX_SO_TIMESTAMPN:
return (SO_TIMESTAMP);
+ case LINUX_SO_TIMESTAMPNSO:
+ case LINUX_SO_TIMESTAMPNSN:
+ return (SO_BINTIME);
case LINUX_SO_ACCEPTCONN:
return (SO_ACCEPTCONN);
case LINUX_SO_PROTOCOL:
return (SO_PROTOCOL);
+ case LINUX_SO_DOMAIN:
+ return (SO_DOMAIN);
}
return (-1);
}
@@ -642,10 +656,31 @@ linux_to_bsd_cmsg_type(int cmsg_type)
}
static int
-bsd_to_linux_cmsg_type(int cmsg_type)
+bsd_to_linux_ip_cmsg_type(int cmsg_type)
{
switch (cmsg_type) {
+ case IP_RECVORIGDSTADDR:
+ return (LINUX_IP_RECVORIGDSTADDR);
+ case IP_RECVTOS:
+ return (LINUX_IP_TOS);
+ }
+ return (-1);
+}
+
+static int
+bsd_to_linux_cmsg_type(struct proc *p, int cmsg_type, int cmsg_level)
+{
+ struct linux_pemuldata *pem;
+
+ if (cmsg_level == IPPROTO_IP)
+ return (bsd_to_linux_ip_cmsg_type(cmsg_type));
+ if (cmsg_level != SOL_SOCKET)
+ return (-1);
+
+ pem = pem_find(p);
+
+ switch (cmsg_type) {
case SCM_RIGHTS:
return (LINUX_SCM_RIGHTS);
case SCM_CREDS:
@@ -653,7 +688,9 @@ bsd_to_linux_cmsg_type(int cmsg_type)
case SCM_CREDS2:
return (LINUX_SCM_CREDENTIALS);
case SCM_TIMESTAMP:
- return (LINUX_SCM_TIMESTAMP);
+ return (pem->so_timestamp);
+ case SCM_BINTIME:
+ return (pem->so_timestampns);
}
return (-1);
}
@@ -727,9 +764,9 @@ linux_copyout_sockaddr(const struct sockaddr *sa, void *uaddr, size_t len)
error = bsd_to_linux_sockaddr(sa, &lsa, len);
if (error != 0)
return (error);
-
+
error = copyout(lsa, uaddr, len);
- free(lsa, M_SONAME);
+ free(lsa, M_LINUX);
return (error);
}
@@ -839,7 +876,8 @@ static const char *linux_netlink_names[] = {
int
linux_socket(struct thread *td, struct linux_socket_args *args)
{
- int domain, retval_socket, type;
+ int retval_socket, type;
+ sa_family_t domain;
type = args->type & LINUX_SOCK_TYPE_MASK;
if (type < 0 || type > LINUX_SOCK_MAX)
@@ -849,7 +887,7 @@ linux_socket(struct thread *td, struct linux_socket_args *args)
if (retval_socket != 0)
return (retval_socket);
domain = linux_to_bsd_domain(args->domain);
- if (domain == -1) {
+ if (domain == AF_UNKNOWN) {
/* Mask off SOCK_NONBLOCK / CLOEXEC for error messages. */
type = args->type & LINUX_SOCK_TYPE_MASK;
if (args->domain == LINUX_AF_NETLINK &&
@@ -940,7 +978,6 @@ linux_connect(struct thread *td, struct linux_connect_args *args)
struct socket *so;
struct sockaddr *sa;
struct file *fp;
- u_int fflag;
int error;
error = linux_to_bsd_sockaddr(PTRIN(args->name), &sa,
@@ -958,14 +995,13 @@ linux_connect(struct thread *td, struct linux_connect_args *args)
* when on a non-blocking socket. Instead it returns the
* error getsockopt(SOL_SOCKET, SO_ERROR) would return on BSD.
*/
- error = getsock_cap(td, args->s, &cap_connect_rights,
- &fp, &fflag, NULL);
+ error = getsock(td, args->s, &cap_connect_rights, &fp);
if (error != 0)
return (error);
error = EISCONN;
so = fp->f_data;
- if (fflag & FNONBLOCK) {
+ if (atomic_load_int(&fp->f_flag) & FNONBLOCK) {
SOCK_LOCK(so);
if (so->so_emuldata == 0)
error = so->so_error;
@@ -988,31 +1024,29 @@ static int
linux_accept_common(struct thread *td, int s, l_uintptr_t addr,
l_uintptr_t namelen, int flags)
{
- struct sockaddr *sa;
+ struct sockaddr_storage ss = { .ss_len = sizeof(ss) };
struct file *fp, *fp1;
- int bflags, len;
struct socket *so;
- int error, error1;
+ socklen_t len;
+ int bflags, error, error1;
bflags = 0;
fp = NULL;
- sa = NULL;
error = linux_set_socket_flags(flags, &bflags);
if (error != 0)
return (error);
- if (PTRIN(addr) == NULL) {
- len = 0;
- error = kern_accept4(td, s, NULL, NULL, bflags, NULL);
- } else {
+ if (PTRIN(addr) != NULL) {
error = copyin(PTRIN(namelen), &len, sizeof(len));
if (error != 0)
return (error);
if (len < 0)
return (EINVAL);
- error = kern_accept4(td, s, &sa, &len, bflags, &fp);
- }
+ } else
+ len = 0;
+
+ error = kern_accept4(td, s, (struct sockaddr *)&ss, bflags, &fp);
/*
* Translate errno values into ones used by Linux.
@@ -1028,7 +1062,7 @@ linux_accept_common(struct thread *td, int s, l_uintptr_t addr,
error = EINVAL;
break;
case EINVAL:
- error1 = getsock_cap(td, s, &cap_accept_rights, &fp1, NULL, NULL);
+ error1 = getsock(td, s, &cap_accept_rights, &fp1);
if (error1 != 0) {
error = error1;
break;
@@ -1042,13 +1076,14 @@ linux_accept_common(struct thread *td, int s, l_uintptr_t addr,
return (error);
}
- if (len != 0) {
- error = linux_copyout_sockaddr(sa, PTRIN(addr), len);
-
- /*
- * XXX: We should also copyout the len, shouldn't we?
- */
-
+ if (PTRIN(addr) != NULL) {
+ len = min(ss.ss_len, len);
+ error = linux_copyout_sockaddr((struct sockaddr *)&ss,
+ PTRIN(addr), len);
+ if (error == 0) {
+ len = ss.ss_len;
+ error = copyout(&len, PTRIN(namelen), sizeof(len));
+ }
if (error != 0) {
fdclose(td, fp, td->td_retval[0]);
td->td_retval[0] = 0;
@@ -1056,7 +1091,6 @@ linux_accept_common(struct thread *td, int s, l_uintptr_t addr,
}
if (fp != NULL)
fdrop(fp, td);
- free(sa, M_SONAME);
return (error);
}
@@ -1079,48 +1113,50 @@ linux_accept4(struct thread *td, struct linux_accept4_args *args)
int
linux_getsockname(struct thread *td, struct linux_getsockname_args *args)
{
- struct sockaddr *sa;
- int len, error;
+ struct sockaddr_storage ss = { .ss_len = sizeof(ss) };
+ socklen_t len;
+ int error;
error = copyin(PTRIN(args->namelen), &len, sizeof(len));
if (error != 0)
return (error);
- error = kern_getsockname(td, args->s, &sa, &len);
+ error = kern_getsockname(td, args->s, (struct sockaddr *)&ss);
if (error != 0)
return (error);
- if (len != 0)
- error = linux_copyout_sockaddr(sa, PTRIN(args->addr), len);
-
- free(sa, M_SONAME);
- if (error == 0)
+ len = min(ss.ss_len, len);
+ error = linux_copyout_sockaddr((struct sockaddr *)&ss,
+ PTRIN(args->addr), len);
+ if (error == 0) {
+ len = ss.ss_len;
error = copyout(&len, PTRIN(args->namelen), sizeof(len));
+ }
return (error);
}
int
linux_getpeername(struct thread *td, struct linux_getpeername_args *args)
{
- struct sockaddr *sa;
- int len, error;
+ struct sockaddr_storage ss = { .ss_len = sizeof(ss) };
+ socklen_t len;
+ int error;
error = copyin(PTRIN(args->namelen), &len, sizeof(len));
if (error != 0)
return (error);
- if (len < 0)
- return (EINVAL);
- error = kern_getpeername(td, args->s, &sa, &len);
+ error = kern_getpeername(td, args->s, (struct sockaddr *)&ss);
if (error != 0)
return (error);
- if (len != 0)
- error = linux_copyout_sockaddr(sa, PTRIN(args->addr), len);
-
- free(sa, M_SONAME);
- if (error == 0)
+ len = min(ss.ss_len, len);
+ error = linux_copyout_sockaddr((struct sockaddr *)&ss,
+ PTRIN(args->addr), len);
+ if (error == 0) {
+ len = ss.ss_len;
error = copyout(&len, PTRIN(args->namelen), sizeof(len));
+ }
return (error);
}
@@ -1179,7 +1215,7 @@ linux_send(struct thread *td, struct linux_send_args *args)
int tolen;
} */ bsd_args;
struct file *fp;
- int error, fflag;
+ int error;
bsd_args.s = args->s;
bsd_args.buf = (caddr_t)PTRIN(args->msg);
@@ -1193,10 +1229,9 @@ linux_send(struct thread *td, struct linux_send_args *args)
* Linux doesn't return ENOTCONN for non-blocking sockets.
* Instead it returns the EAGAIN.
*/
- error = getsock_cap(td, args->s, &cap_send_rights, &fp,
- &fflag, NULL);
+ error = getsock(td, args->s, &cap_send_rights, &fp);
if (error == 0) {
- if (fflag & FNONBLOCK)
+ if (atomic_load_int(&fp->f_flag) & FNONBLOCK)
error = EAGAIN;
fdrop(fp, td);
}
@@ -1238,19 +1273,28 @@ linux_sendto(struct thread *td, struct linux_sendto_args *args)
{
struct msghdr msg;
struct iovec aiov;
+ struct socket *so;
+ struct file *fp;
+ int error;
if (linux_check_hdrincl(td, args->s) == 0)
/* IP_HDRINCL set, tweak the packet before sending */
return (linux_sendto_hdrincl(td, args));
- msg.msg_name = PTRIN(args->to);
- msg.msg_namelen = args->tolen;
+ bzero(&msg, sizeof(msg));
+ error = getsock(td, args->s, &cap_send_connect_rights, &fp);
+ if (error != 0)
+ return (error);
+ so = fp->f_data;
+ if ((so->so_state & (SS_ISCONNECTED|SS_ISCONNECTING)) == 0) {
+ msg.msg_name = PTRIN(args->to);
+ msg.msg_namelen = args->tolen;
+ }
msg.msg_iov = &aiov;
msg.msg_iovlen = 1;
- msg.msg_control = NULL;
- msg.msg_flags = 0;
aiov.iov_base = PTRIN(args->msg);
aiov.iov_len = args->len;
+ fdrop(fp, td);
return (linux_sendit(td, args->s, &msg, args->flags, NULL,
UIO_USERSPACE));
}
@@ -1270,6 +1314,7 @@ linux_recvfrom(struct thread *td, struct linux_recvfrom_args *args)
return (error);
if (fromlen < 0)
return (EINVAL);
+ fromlen = min(fromlen, SOCK_MAXADDRLEN);
sa = malloc(fromlen, M_SONAME, M_WAITOK);
} else {
fromlen = 0;
@@ -1289,8 +1334,16 @@ linux_recvfrom(struct thread *td, struct linux_recvfrom_args *args)
if (error != 0)
goto out;
- if (PTRIN(args->from) != NULL)
- error = linux_copyout_sockaddr(sa, PTRIN(args->from), msg.msg_namelen);
+ /*
+ * XXX. Seems that FreeBSD is different from Linux here. Linux
+ * fill source address if underlying protocol provides it, while
+ * FreeBSD fill it if underlying protocol is not connection-oriented.
+ * So, kern_recvit() set msg.msg_namelen to 0 if protocol pr_flags
+ * does not contains PR_ADDR flag.
+ */
+ if (PTRIN(args->from) != NULL && msg.msg_namelen != 0)
+ error = linux_copyout_sockaddr(sa, PTRIN(args->from),
+ msg.msg_namelen);
if (error == 0 && PTRIN(args->fromlen) != NULL)
error = copyout(&msg.msg_namelen, PTRIN(args->fromlen),
@@ -1304,6 +1357,7 @@ static int
linux_sendmsg_common(struct thread *td, l_int s, struct l_msghdr *msghdr,
l_uint flags)
{
+ struct sockaddr_storage ss = { .ss_len = sizeof(ss) };
struct cmsghdr *cmsg;
struct mbuf *control;
struct msghdr msg;
@@ -1312,14 +1366,13 @@ linux_sendmsg_common(struct thread *td, l_int s, struct l_msghdr *msghdr,
struct l_msghdr linux_msghdr;
struct iovec *iov;
socklen_t datalen;
- struct sockaddr *sa;
struct socket *so;
sa_family_t sa_family;
struct file *fp;
void *data;
l_size_t len;
l_size_t clen;
- int error, fflag;
+ int error;
error = copyin(msghdr, &linux_msghdr, sizeof(linux_msghdr));
if (error != 0)
@@ -1341,7 +1394,7 @@ linux_sendmsg_common(struct thread *td, l_int s, struct l_msghdr *msghdr,
return (error);
#ifdef COMPAT_LINUX32
- error = linux32_copyiniov(PTRIN(msg.msg_iov), msg.msg_iovlen,
+ error = freebsd32_copyiniov(PTRIN(msg.msg_iov), msg.msg_iovlen,
&iov, EMSGSIZE);
#else
error = copyiniov(msg.msg_iov, msg.msg_iovlen, &iov, EMSGSIZE);
@@ -1351,19 +1404,17 @@ linux_sendmsg_common(struct thread *td, l_int s, struct l_msghdr *msghdr,
control = NULL;
- error = kern_getsockname(td, s, &sa, &datalen);
+ error = kern_getsockname(td, s, (struct sockaddr *)&ss);
if (error != 0)
goto bad;
- sa_family = sa->sa_family;
- free(sa, M_SONAME);
+ sa_family = ss.ss_family;
if (flags & LINUX_MSG_OOB) {
error = EOPNOTSUPP;
if (sa_family == AF_UNIX)
goto bad;
- error = getsock_cap(td, s, &cap_send_rights, &fp,
- &fflag, NULL);
+ error = getsock(td, s, &cap_send_rights, &fp);
if (error != 0)
goto bad;
so = fp->f_data;
@@ -1514,36 +1565,245 @@ linux_sendmmsg(struct thread *td, struct linux_sendmmsg_args *args)
}
static int
+recvmsg_scm_rights(struct thread *td, l_uint flags, socklen_t *datalen,
+ void **data, void **udata)
+{
+ int i, fd, fds, *fdp;
+
+ if (flags & LINUX_MSG_CMSG_CLOEXEC) {
+ fds = *datalen / sizeof(int);
+ fdp = *data;
+ for (i = 0; i < fds; i++) {
+ fd = *fdp++;
+ (void)kern_fcntl(td, fd, F_SETFD, FD_CLOEXEC);
+ }
+ }
+ return (0);
+}
+
+
+static int
+recvmsg_scm_creds(socklen_t *datalen, void **data, void **udata)
+{
+ struct cmsgcred *cmcred;
+ struct l_ucred lu;
+
+ cmcred = *data;
+ lu.pid = cmcred->cmcred_pid;
+ lu.uid = cmcred->cmcred_uid;
+ lu.gid = cmcred->cmcred_gid;
+ memmove(*data, &lu, sizeof(lu));
+ *datalen = sizeof(lu);
+ return (0);
+}
+_Static_assert(sizeof(struct cmsgcred) >= sizeof(struct l_ucred),
+ "scm_creds sizeof l_ucred");
+
+static int
+recvmsg_scm_creds2(socklen_t *datalen, void **data, void **udata)
+{
+ struct sockcred2 *scred;
+ struct l_ucred lu;
+
+ scred = *data;
+ lu.pid = scred->sc_pid;
+ lu.uid = scred->sc_uid;
+ lu.gid = scred->sc_gid;
+ memmove(*data, &lu, sizeof(lu));
+ *datalen = sizeof(lu);
+ return (0);
+}
+_Static_assert(sizeof(struct sockcred2) >= sizeof(struct l_ucred),
+ "scm_creds2 sizeof l_ucred");
+
+#if defined(__i386__) || (defined(__amd64__) && defined(COMPAT_LINUX32))
+static int
+recvmsg_scm_timestamp(l_int msg_type, socklen_t *datalen, void **data,
+ void **udata)
+{
+ l_sock_timeval ltv64;
+ l_timeval ltv;
+ struct timeval *tv;
+ socklen_t len;
+ void *buf;
+
+ if (*datalen != sizeof(struct timeval))
+ return (EMSGSIZE);
+
+ tv = *data;
+#if defined(COMPAT_LINUX32)
+ if (msg_type == LINUX_SCM_TIMESTAMPO &&
+ (tv->tv_sec > INT_MAX || tv->tv_sec < INT_MIN))
+ return (EOVERFLOW);
+#endif
+ if (msg_type == LINUX_SCM_TIMESTAMPN)
+ len = sizeof(ltv64);
+ else
+ len = sizeof(ltv);
+
+ buf = malloc(len, M_LINUX, M_WAITOK);
+ if (msg_type == LINUX_SCM_TIMESTAMPN) {
+ ltv64.tv_sec = tv->tv_sec;
+ ltv64.tv_usec = tv->tv_usec;
+ memmove(buf, &ltv64, len);
+ } else {
+ ltv.tv_sec = tv->tv_sec;
+ ltv.tv_usec = tv->tv_usec;
+ memmove(buf, &ltv, len);
+ }
+ *data = *udata = buf;
+ *datalen = len;
+ return (0);
+}
+#else
+_Static_assert(sizeof(struct timeval) == sizeof(l_timeval),
+ "scm_timestamp sizeof l_timeval");
+#endif /* __i386__ || (__amd64__ && COMPAT_LINUX32) */
+
+#if defined(__i386__) || (defined(__amd64__) && defined(COMPAT_LINUX32))
+static int
+recvmsg_scm_timestampns(l_int msg_type, socklen_t *datalen, void **data,
+ void **udata)
+{
+ struct l_timespec64 ts64;
+ struct l_timespec ts32;
+ struct timespec ts;
+ socklen_t len;
+ void *buf;
+
+ if (msg_type == LINUX_SCM_TIMESTAMPNSO)
+ len = sizeof(ts32);
+ else
+ len = sizeof(ts64);
+
+ buf = malloc(len, M_LINUX, M_WAITOK);
+ bintime2timespec(*data, &ts);
+ if (msg_type == LINUX_SCM_TIMESTAMPNSO) {
+ ts32.tv_sec = ts.tv_sec;
+ ts32.tv_nsec = ts.tv_nsec;
+ memmove(buf, &ts32, len);
+ } else {
+ ts64.tv_sec = ts.tv_sec;
+ ts64.tv_nsec = ts.tv_nsec;
+ memmove(buf, &ts64, len);
+ }
+ *data = *udata = buf;
+ *datalen = len;
+ return (0);
+}
+#else
+static int
+recvmsg_scm_timestampns(l_int msg_type, socklen_t *datalen, void **data,
+ void **udata)
+{
+ struct timespec ts;
+
+ bintime2timespec(*data, &ts);
+ memmove(*data, &ts, sizeof(struct timespec));
+ *datalen = sizeof(struct timespec);
+ return (0);
+}
+_Static_assert(sizeof(struct bintime) >= sizeof(struct timespec),
+ "scm_timestampns sizeof timespec");
+#endif /* __i386__ || (__amd64__ && COMPAT_LINUX32) */
+
+static int
+recvmsg_scm_sol_socket(struct thread *td, l_int msg_type, l_int lmsg_type,
+ l_uint flags, socklen_t *datalen, void **data, void **udata)
+{
+ int error;
+
+ error = 0;
+ switch (msg_type) {
+ case SCM_RIGHTS:
+ error = recvmsg_scm_rights(td, flags, datalen,
+ data, udata);
+ break;
+ case SCM_CREDS:
+ error = recvmsg_scm_creds(datalen, data, udata);
+ break;
+ case SCM_CREDS2:
+ error = recvmsg_scm_creds2(datalen, data, udata);
+ break;
+ case SCM_TIMESTAMP:
+#if defined(__i386__) || (defined(__amd64__) && defined(COMPAT_LINUX32))
+ error = recvmsg_scm_timestamp(lmsg_type, datalen,
+ data, udata);
+#endif
+ break;
+ case SCM_BINTIME:
+ error = recvmsg_scm_timestampns(lmsg_type, datalen,
+ data, udata);
+ break;
+ }
+
+ return (error);
+}
+
+static int
+recvmsg_scm_ip_origdstaddr(socklen_t *datalen, void **data, void **udata)
+{
+ struct l_sockaddr *lsa;
+ int error;
+
+ error = bsd_to_linux_sockaddr(*data, &lsa, *datalen);
+ if (error == 0) {
+ *data = *udata = lsa;
+ *datalen = sizeof(*lsa);
+ }
+ return (error);
+}
+
+static int
+recvmsg_scm_ipproto_ip(l_int msg_type, l_int lmsg_type, socklen_t *datalen,
+ void **data, void **udata)
+{
+ int error;
+
+ error = 0;
+ switch (msg_type) {
+ case IP_ORIGDSTADDR:
+ error = recvmsg_scm_ip_origdstaddr(datalen, data,
+ udata);
+ break;
+ }
+
+ return (error);
+}
+
+static int
linux_recvmsg_common(struct thread *td, l_int s, struct l_msghdr *msghdr,
l_uint flags, struct msghdr *msg)
{
+ struct proc *p = td->td_proc;
struct cmsghdr *cm;
- struct cmsgcred *cmcred;
- struct sockcred2 *scred;
- struct l_cmsghdr *linux_cmsg = NULL;
- struct l_ucred linux_ucred;
+ struct l_cmsghdr *lcm = NULL;
socklen_t datalen, maxlen, outlen;
- struct l_msghdr linux_msghdr;
+ struct l_msghdr l_msghdr;
struct iovec *iov, *uiov;
- struct mbuf *control = NULL;
+ struct mbuf *m, *control = NULL;
struct mbuf **controlp;
- struct timeval *ftmvl;
struct sockaddr *sa;
- l_timeval ltmvl;
caddr_t outbuf;
- void *data;
- int error, i, fd, fds, *fdp;
+ void *data, *udata;
+ int error, skiped;
- error = copyin(msghdr, &linux_msghdr, sizeof(linux_msghdr));
+ error = copyin(msghdr, &l_msghdr, sizeof(l_msghdr));
if (error != 0)
return (error);
- error = linux_to_bsd_msghdr(msg, &linux_msghdr);
+ /*
+ * Pass user-supplied recvmsg() flags in msg_flags field,
+ * following sys_recvmsg() convention.
+ */
+ l_msghdr.msg_flags = flags;
+
+ error = linux_to_bsd_msghdr(msg, &l_msghdr);
if (error != 0)
return (error);
#ifdef COMPAT_LINUX32
- error = linux32_copyiniov(PTRIN(msg->msg_iov), msg->msg_iovlen,
+ error = freebsd32_copyiniov(PTRIN(msg->msg_iov), msg->msg_iovlen,
&iov, EMSGSIZE);
#else
error = copyiniov(msg->msg_iov, msg->msg_iovlen, &iov, EMSGSIZE);
@@ -1572,132 +1832,95 @@ linux_recvmsg_common(struct thread *td, l_int s, struct l_msghdr *msghdr,
* Note that kern_recvit() updates msg->msg_namelen.
*/
if (msg->msg_name != NULL && msg->msg_namelen > 0) {
- msg->msg_name = PTRIN(linux_msghdr.msg_name);
- error = linux_copyout_sockaddr(sa,
- PTRIN(msg->msg_name), msg->msg_namelen);
+ msg->msg_name = PTRIN(l_msghdr.msg_name);
+ error = linux_copyout_sockaddr(sa, msg->msg_name,
+ msg->msg_namelen);
if (error != 0)
goto bad;
}
- error = bsd_to_linux_msghdr(msg, &linux_msghdr);
+ error = bsd_to_linux_msghdr(msg, &l_msghdr);
if (error != 0)
goto bad;
- maxlen = linux_msghdr.msg_controllen;
- linux_msghdr.msg_controllen = 0;
- if (control) {
- linux_cmsg = malloc(L_CMSG_HDRSZ, M_LINUX, M_WAITOK | M_ZERO);
-
- msg->msg_control = mtod(control, struct cmsghdr *);
- msg->msg_controllen = control->m_len;
-
- cm = CMSG_FIRSTHDR(msg);
- outbuf = PTRIN(linux_msghdr.msg_control);
- outlen = 0;
- while (cm != NULL) {
- linux_cmsg->cmsg_type =
- bsd_to_linux_cmsg_type(cm->cmsg_type);
- linux_cmsg->cmsg_level =
- bsd_to_linux_sockopt_level(cm->cmsg_level);
- if (linux_cmsg->cmsg_type == -1 ||
- cm->cmsg_level != SOL_SOCKET) {
- linux_msg(curthread,
- "unsupported recvmsg cmsg level %d type %d",
- cm->cmsg_level, cm->cmsg_type);
- error = EINVAL;
- goto bad;
- }
-
- data = CMSG_DATA(cm);
- datalen = (caddr_t)cm + cm->cmsg_len - (caddr_t)data;
-
- switch (cm->cmsg_type) {
- case SCM_RIGHTS:
- if (flags & LINUX_MSG_CMSG_CLOEXEC) {
- fds = datalen / sizeof(int);
- fdp = data;
- for (i = 0; i < fds; i++) {
- fd = *fdp++;
- (void)kern_fcntl(td, fd,
- F_SETFD, FD_CLOEXEC);
- }
- }
- break;
-
- case SCM_CREDS:
- /*
- * Currently LOCAL_CREDS is never in
- * effect for Linux so no need to worry
- * about sockcred
- */
- if (datalen != sizeof(*cmcred)) {
- error = EMSGSIZE;
- goto bad;
- }
- cmcred = (struct cmsgcred *)data;
- bzero(&linux_ucred, sizeof(linux_ucred));
- linux_ucred.pid = cmcred->cmcred_pid;
- linux_ucred.uid = cmcred->cmcred_uid;
- linux_ucred.gid = cmcred->cmcred_gid;
- data = &linux_ucred;
- datalen = sizeof(linux_ucred);
- break;
+ skiped = outlen = 0;
+ maxlen = l_msghdr.msg_controllen;
+ if (control == NULL)
+ goto out;
- case SCM_CREDS2:
- scred = data;
- bzero(&linux_ucred, sizeof(linux_ucred));
- linux_ucred.pid = scred->sc_pid;
- linux_ucred.uid = scred->sc_uid;
- linux_ucred.gid = scred->sc_gid;
- data = &linux_ucred;
- datalen = sizeof(linux_ucred);
- break;
+ lcm = malloc(L_CMSG_HDRSZ, M_LINUX, M_WAITOK | M_ZERO);
+ msg->msg_control = mtod(control, struct cmsghdr *);
+ msg->msg_controllen = control->m_len;
+ outbuf = PTRIN(l_msghdr.msg_control);
+ for (m = control; m != NULL; m = m->m_next) {
+ cm = mtod(m, struct cmsghdr *);
+ lcm->cmsg_type = bsd_to_linux_cmsg_type(p, cm->cmsg_type,
+ cm->cmsg_level);
+ lcm->cmsg_level = bsd_to_linux_sockopt_level(cm->cmsg_level);
+
+ if (lcm->cmsg_type == -1 ||
+ lcm->cmsg_level == -1) {
+ LINUX_RATELIMIT_MSG_OPT2(
+ "unsupported recvmsg cmsg level %d type %d",
+ cm->cmsg_level, cm->cmsg_type);
+ /* Skip unsupported messages */
+ skiped++;
+ continue;
+ }
+ data = CMSG_DATA(cm);
+ datalen = (caddr_t)cm + cm->cmsg_len - (caddr_t)data;
+ udata = NULL;
+ error = 0;
+
+ switch (cm->cmsg_level) {
+ case IPPROTO_IP:
+ error = recvmsg_scm_ipproto_ip(cm->cmsg_type,
+ lcm->cmsg_type, &datalen, &data, &udata);
+ break;
+ case SOL_SOCKET:
+ error = recvmsg_scm_sol_socket(td, cm->cmsg_type,
+ lcm->cmsg_type, flags, &datalen, &data, &udata);
+ break;
+ }
+
+ /* The recvmsg_scm_ is responsible to free udata on error. */
+ if (error != 0)
+ goto bad;
- case SCM_TIMESTAMP:
- if (datalen != sizeof(struct timeval)) {
- error = EMSGSIZE;
- goto bad;
- }
- ftmvl = (struct timeval *)data;
- ltmvl.tv_sec = ftmvl->tv_sec;
- ltmvl.tv_usec = ftmvl->tv_usec;
- data = &ltmvl;
- datalen = sizeof(ltmvl);
- break;
+ if (outlen + LINUX_CMSG_LEN(datalen) > maxlen) {
+ if (outlen == 0) {
+ error = EMSGSIZE;
+ goto err;
+ } else {
+ l_msghdr.msg_flags |= LINUX_MSG_CTRUNC;
+ m_dispose_extcontrolm(control);
+ free(udata, M_LINUX);
+ goto out;
}
+ }
- if (outlen + LINUX_CMSG_LEN(datalen) > maxlen) {
- if (outlen == 0) {
- error = EMSGSIZE;
- goto bad;
- } else {
- linux_msghdr.msg_flags |= LINUX_MSG_CTRUNC;
- m_dispose_extcontrolm(control);
- goto out;
- }
+ lcm->cmsg_len = LINUX_CMSG_LEN(datalen);
+ error = copyout(lcm, outbuf, L_CMSG_HDRSZ);
+ if (error == 0) {
+ error = copyout(data, LINUX_CMSG_DATA(outbuf), datalen);
+ if (error == 0) {
+ outbuf += LINUX_CMSG_SPACE(datalen);
+ outlen += LINUX_CMSG_SPACE(datalen);
}
-
- linux_cmsg->cmsg_len = LINUX_CMSG_LEN(datalen);
-
- error = copyout(linux_cmsg, outbuf, L_CMSG_HDRSZ);
- if (error != 0)
- goto bad;
- outbuf += L_CMSG_HDRSZ;
-
- error = copyout(data, outbuf, datalen);
- if (error != 0)
- goto bad;
-
- outbuf += LINUX_CMSG_ALIGN(datalen);
- outlen += LINUX_CMSG_LEN(datalen);
-
- cm = CMSG_NXTHDR(msg, cm);
}
- linux_msghdr.msg_controllen = outlen;
+err:
+ free(udata, M_LINUX);
+ if (error != 0)
+ goto bad;
+ }
+ if (outlen == 0 && skiped > 0) {
+ error = EINVAL;
+ goto bad;
}
out:
- error = copyout(&linux_msghdr, msghdr, sizeof(linux_msghdr));
+ l_msghdr.msg_controllen = outlen;
+ error = copyout(&l_msghdr, msghdr, sizeof(l_msghdr));
bad:
if (control != NULL) {
@@ -1706,7 +1929,7 @@ bad:
m_freem(control);
}
free(iov, M_IOV);
- free(linux_cmsg, M_LINUX);
+ free(lcm, M_LINUX);
free(sa, M_SONAME);
return (error);
@@ -1716,37 +1939,34 @@ int
linux_recvmsg(struct thread *td, struct linux_recvmsg_args *args)
{
struct msghdr bsd_msg;
+ struct file *fp;
+ int error;
+ error = getsock(td, args->s, &cap_recv_rights, &fp);
+ if (error != 0)
+ return (error);
+ fdrop(fp, td);
return (linux_recvmsg_common(td, args->s, PTRIN(args->msg),
args->flags, &bsd_msg));
}
-int
-linux_recvmmsg(struct thread *td, struct linux_recvmmsg_args *args)
+static int
+linux_recvmmsg_common(struct thread *td, l_int s, struct l_mmsghdr *msg,
+ l_uint vlen, l_uint flags, struct timespec *tts)
{
- struct l_mmsghdr *msg;
struct msghdr bsd_msg;
- struct l_timespec lts;
- struct timespec ts, tts;
+ struct timespec ts;
+ struct file *fp;
l_uint retval;
int error, datagrams;
- if (args->timeout) {
- error = copyin(args->timeout, &lts, sizeof(struct l_timespec));
- if (error != 0)
- return (error);
- error = linux_to_native_timespec(&ts, &lts);
- if (error != 0)
- return (error);
- getnanotime(&tts);
- timespecadd(&tts, &ts, &tts);
- }
-
- msg = PTRIN(args->msg);
+ error = getsock(td, s, &cap_recv_rights, &fp);
+ if (error != 0)
+ return (error);
datagrams = 0;
- while (datagrams < args->vlen) {
- error = linux_recvmsg_common(td, args->s, &msg->msg_hdr,
- args->flags & ~LINUX_MSG_WAITFORONE, &bsd_msg);
+ while (datagrams < vlen) {
+ error = linux_recvmsg_common(td, s, &msg->msg_hdr,
+ flags & ~LINUX_MSG_WAITFORONE, &bsd_msg);
if (error != 0)
break;
@@ -1760,15 +1980,15 @@ linux_recvmmsg(struct thread *td, struct linux_recvmmsg_args *args)
/*
* MSG_WAITFORONE turns on MSG_DONTWAIT after one packet.
*/
- if (args->flags & LINUX_MSG_WAITFORONE)
- args->flags |= LINUX_MSG_DONTWAIT;
+ if (flags & LINUX_MSG_WAITFORONE)
+ flags |= LINUX_MSG_DONTWAIT;
/*
* See BUGS section of recvmmsg(2).
*/
- if (args->timeout) {
+ if (tts) {
getnanotime(&ts);
- timespecsub(&ts, &tts, &ts);
+ timespecsub(&ts, tts, &ts);
if (!timespecisset(&ts) || ts.tv_sec > 0)
break;
}
@@ -1778,10 +1998,53 @@ linux_recvmmsg(struct thread *td, struct linux_recvmmsg_args *args)
}
if (error == 0)
td->td_retval[0] = datagrams;
+ fdrop(fp, td);
return (error);
}
int
+linux_recvmmsg(struct thread *td, struct linux_recvmmsg_args *args)
+{
+ struct timespec ts, tts, *ptts;
+ int error;
+
+ if (args->timeout) {
+ error = linux_get_timespec(&ts, args->timeout);
+ if (error != 0)
+ return (error);
+ getnanotime(&tts);
+ timespecadd(&tts, &ts, &tts);
+ ptts = &tts;
+ }
+ else ptts = NULL;
+
+ return (linux_recvmmsg_common(td, args->s, PTRIN(args->msg),
+ args->vlen, args->flags, ptts));
+}
+
+#if defined(__i386__) || (defined(__amd64__) && defined(COMPAT_LINUX32))
+int
+linux_recvmmsg_time64(struct thread *td, struct linux_recvmmsg_time64_args *args)
+{
+ struct timespec ts, tts, *ptts;
+ int error;
+
+ if (args->timeout) {
+ error = linux_get_timespec64(&ts, args->timeout);
+ if (error != 0)
+ return (error);
+ getnanotime(&tts);
+ timespecadd(&tts, &ts, &tts);
+ ptts = &tts;
+ }
+ else ptts = NULL;
+
+ return (linux_recvmmsg_common(td, args->s, PTRIN(args->msg),
+ args->vlen, args->flags, ptts));
+}
+#endif
+
+int
linux_shutdown(struct thread *td, struct linux_shutdown_args *args)
{
@@ -1791,11 +2054,13 @@ linux_shutdown(struct thread *td, struct linux_shutdown_args *args)
int
linux_setsockopt(struct thread *td, struct linux_setsockopt_args *args)
{
+ struct proc *p = td->td_proc;
+ struct linux_pemuldata *pem;
l_timeval linux_tv;
struct sockaddr *sa;
struct timeval tv;
socklen_t len;
- int error, level, name;
+ int error, level, name, val;
level = linux_to_bsd_sockopt_level(args->level);
switch (level) {
@@ -1817,6 +2082,26 @@ linux_setsockopt(struct thread *td, struct linux_setsockopt_args *args)
return (kern_setsockopt(td, args->s, level,
name, &tv, UIO_SYSSPACE, sizeof(tv)));
/* NOTREACHED */
+ case SO_TIMESTAMP:
+ /* overwrite SO_BINTIME */
+ val = 0;
+ error = kern_setsockopt(td, args->s, level,
+ SO_BINTIME, &val, UIO_SYSSPACE, sizeof(val));
+ if (error != 0)
+ return (error);
+ pem = pem_find(p);
+ pem->so_timestamp = args->optname;
+ break;
+ case SO_BINTIME:
+ /* overwrite SO_TIMESTAMP */
+ val = 0;
+ error = kern_setsockopt(td, args->s, level,
+ SO_TIMESTAMP, &val, UIO_SYSSPACE, sizeof(val));
+ if (error != 0)
+ return (error);
+ pem = pem_find(p);
+ pem->so_timestampns = args->optname;
+ break;
default:
break;
}
@@ -1833,11 +2118,22 @@ linux_setsockopt(struct thread *td, struct linux_setsockopt_args *args)
name = linux_to_bsd_ip_sockopt(args->optname);
break;
case IPPROTO_IPV6:
+ if (args->optname == LINUX_IPV6_RECVERR &&
+ linux_ignore_ip_recverr) {
+ /*
+ * XXX: This is a hack to unbreak DNS resolution
+ * with glibc 2.30 and above.
+ */
+ return (0);
+ }
name = linux_to_bsd_ip6_sockopt(args->optname);
break;
case IPPROTO_TCP:
name = linux_to_bsd_tcp_sockopt(args->optname);
break;
+ case SOL_NETLINK:
+ name = args->optname;
+ break;
default:
name = -1;
break;
@@ -1850,7 +2146,8 @@ linux_setsockopt(struct thread *td, struct linux_setsockopt_args *args)
return (ENOPROTOOPT);
}
- if (name == IPV6_NEXTHOP) {
+ switch (name) {
+ case IPV6_NEXTHOP: {
len = args->optlen;
error = linux_to_bsd_sockaddr(PTRIN(args->optval), &sa, &len);
if (error != 0)
@@ -1859,7 +2156,34 @@ linux_setsockopt(struct thread *td, struct linux_setsockopt_args *args)
error = kern_setsockopt(td, args->s, level,
name, sa, UIO_SYSSPACE, len);
free(sa, M_SONAME);
- } else {
+ break;
+ }
+ case MCAST_JOIN_GROUP:
+ case MCAST_LEAVE_GROUP:
+ case MCAST_JOIN_SOURCE_GROUP:
+ case MCAST_LEAVE_SOURCE_GROUP: {
+ struct group_source_req req;
+ size_t size;
+
+ size = (name == MCAST_JOIN_SOURCE_GROUP ||
+ name == MCAST_LEAVE_SOURCE_GROUP) ?
+ sizeof(struct group_source_req) : sizeof(struct group_req);
+
+ if ((error = copyin(PTRIN(args->optval), &req, size)))
+ return (error);
+ len = sizeof(struct sockaddr_storage);
+ if ((error = linux_to_bsd_sockaddr(
+ (struct l_sockaddr *)&req.gsr_group, NULL, &len)))
+ return (error);
+ if (size == sizeof(struct group_source_req) &&
+ (error = linux_to_bsd_sockaddr(
+ (struct l_sockaddr *)&req.gsr_source, NULL, &len)))
+ return (error);
+ error = kern_setsockopt(td, args->s, level, name, &req,
+ UIO_SYSSPACE, size);
+ break;
+ }
+ default:
error = kern_setsockopt(td, args->s, level,
name, PTRIN(args->optval), UIO_USERSPACE, args->optlen);
}
@@ -1868,9 +2192,22 @@ linux_setsockopt(struct thread *td, struct linux_setsockopt_args *args)
}
static int
+linux_sockopt_copyout(struct thread *td, void *val, socklen_t len,
+ struct linux_getsockopt_args *args)
+{
+ int error;
+
+ error = copyout(val, PTRIN(args->optval), len);
+ if (error == 0)
+ error = copyout(&len, PTRIN(args->optlen), sizeof(len));
+ return (error);
+}
+
+static int
linux_getsockopt_so_peergroups(struct thread *td,
struct linux_getsockopt_args *args)
{
+ l_gid_t *out = PTRIN(args->optval);
struct xucred xu;
socklen_t xulen, len;
int error, i;
@@ -1889,13 +2226,12 @@ linux_getsockopt_so_peergroups(struct thread *td,
return (error);
}
- /*
- * "- 1" to skip the primary group.
- */
+ /* "- 1" to skip the primary group. */
for (i = 0; i < xu.cr_ngroups - 1; i++) {
- error = copyout(xu.cr_groups + i + 1,
- (void *)(args->optval + i * sizeof(l_gid_t)),
- sizeof(l_gid_t));
+ /* Copy to cope with a possible type discrepancy. */
+ const l_gid_t g = xu.cr_groups[i + 1];
+
+ error = copyout(&g, out + i, sizeof(l_gid_t));
if (error != 0)
return (error);
}
@@ -1919,11 +2255,25 @@ linux_getsockopt_so_peersec(struct thread *td,
return (error);
}
- error = copyout(SECURITY_CONTEXT_STRING,
- PTRIN(args->optval), sizeof(SECURITY_CONTEXT_STRING));
- if (error == 0)
- error = copyout(&len, PTRIN(args->optlen), sizeof(len));
- return (error);
+ return (linux_sockopt_copyout(td, SECURITY_CONTEXT_STRING,
+ len, args));
+}
+
+static int
+linux_getsockopt_so_linger(struct thread *td,
+ struct linux_getsockopt_args *args)
+{
+ struct linger ling;
+ socklen_t len;
+ int error;
+
+ len = sizeof(ling);
+ error = kern_getsockopt(td, args->s, SOL_SOCKET,
+ SO_LINGER, &ling, UIO_SYSSPACE, &len);
+ if (error != 0)
+ return (error);
+ ling.l_onoff = ((ling.l_onoff & SO_LINGER) != 0);
+ return (linux_sockopt_copyout(td, &ling, len, args));
}
int
@@ -1964,8 +2314,8 @@ linux_getsockopt(struct thread *td, struct linux_getsockopt_args *args)
return (error);
linux_tv.tv_sec = tv.tv_sec;
linux_tv.tv_usec = tv.tv_usec;
- return (copyout(&linux_tv, PTRIN(args->optval),
- sizeof(linux_tv)));
+ return (linux_sockopt_copyout(td, &linux_tv,
+ sizeof(linux_tv), args));
/* NOTREACHED */
case LOCAL_PEERCRED:
if (args->optlen < sizeof(lxu))
@@ -1983,7 +2333,8 @@ linux_getsockopt(struct thread *td, struct linux_getsockopt_args *args)
lxu.pid = xu.cr_pid;
lxu.uid = xu.cr_uid;
lxu.gid = xu.cr_gid;
- return (copyout(&lxu, PTRIN(args->optval), sizeof(lxu)));
+ return (linux_sockopt_copyout(td, &lxu,
+ sizeof(lxu), args));
/* NOTREACHED */
case SO_ERROR:
len = sizeof(newval);
@@ -1992,7 +2343,23 @@ linux_getsockopt(struct thread *td, struct linux_getsockopt_args *args)
if (error != 0)
return (error);
newval = -bsd_to_linux_errno(newval);
- return (copyout(&newval, PTRIN(args->optval), len));
+ return (linux_sockopt_copyout(td, &newval,
+ len, args));
+ /* NOTREACHED */
+ case SO_DOMAIN:
+ len = sizeof(newval);
+ error = kern_getsockopt(td, args->s, level,
+ name, &newval, UIO_SYSSPACE, &len);
+ if (error != 0)
+ return (error);
+ newval = bsd_to_linux_domain((sa_family_t)newval);
+ if (newval == AF_UNKNOWN)
+ return (ENOPROTOOPT);
+ return (linux_sockopt_copyout(td, &newval,
+ len, args));
+ /* NOTREACHED */
+ case SO_LINGER:
+ return (linux_getsockopt_so_linger(td, args));
/* NOTREACHED */
default:
break;
@@ -2052,57 +2419,217 @@ out:
return (error);
}
-static int
-linux_sendfile_common(struct thread *td, l_int out, l_int in,
- l_loff_t *offset, l_size_t count)
+/*
+ * Based on sendfile_getsock from kern_sendfile.c
+ * Determines whether an fd is a stream socket that can be used
+ * with FreeBSD sendfile.
+ */
+static bool
+is_sendfile(struct file *fp, struct file *ofp)
{
- off_t bytes_read;
- int error;
- l_loff_t current_offset;
- struct file *fp;
+ struct socket *so;
- AUDIT_ARG_FD(in);
- error = fget_read(td, in, &cap_pread_rights, &fp);
- if (error != 0)
- return (error);
+ /*
+ * FreeBSD sendfile() system call sends a regular file or
+ * shared memory object out a stream socket.
+ */
+ if ((fp->f_type != DTYPE_SHM && fp->f_type != DTYPE_VNODE) ||
+ (fp->f_type == DTYPE_VNODE &&
+ (fp->f_vnode == NULL || fp->f_vnode->v_type != VREG)))
+ return (false);
+ /*
+ * The socket must be a stream socket and connected.
+ */
+ if (ofp->f_type != DTYPE_SOCKET)
+ return (false);
+ so = ofp->f_data;
+ if (so->so_type != SOCK_STREAM)
+ return (false);
+ /*
+ * SCTP one-to-one style sockets currently don't work with
+ * sendfile().
+ */
+ if (so->so_proto->pr_protocol == IPPROTO_SCTP)
+ return (false);
+ return (!SOLISTENING(so));
+}
- if (offset != NULL) {
- current_offset = *offset;
+static bool
+is_regular_file(struct file *fp)
+{
+
+ return (fp->f_type == DTYPE_VNODE && fp->f_vnode != NULL &&
+ fp->f_vnode->v_type == VREG);
+}
+
+static int
+sendfile_fallback(struct thread *td, struct file *fp, l_int out,
+ off_t *offset, l_size_t count, off_t *sbytes)
+{
+ off_t current_offset, out_offset, to_send;
+ l_size_t bytes_sent, n_read;
+ struct file *ofp;
+ struct iovec aiov;
+ struct uio auio;
+ bool seekable;
+ size_t bufsz;
+ void *buf;
+ int flags, error;
+
+ if (offset == NULL) {
+ if ((error = fo_seek(fp, 0, SEEK_CUR, td)) != 0)
+ return (error);
+ current_offset = td->td_uretoff.tdu_off;
} else {
- error = (fp->f_ops->fo_flags & DFLAG_SEEKABLE) != 0 ?
- fo_seek(fp, 0, SEEK_CUR, td) : ESPIPE;
- if (error != 0)
+ if ((fp->f_ops->fo_flags & DFLAG_SEEKABLE) == 0)
+ return (ESPIPE);
+ current_offset = *offset;
+ }
+ error = fget_write(td, out, &cap_pwrite_rights, &ofp);
+ if (error != 0)
+ return (error);
+ seekable = (ofp->f_ops->fo_flags & DFLAG_SEEKABLE) != 0;
+ if (seekable) {
+ if ((error = fo_seek(ofp, 0, SEEK_CUR, td)) != 0)
goto drop;
+ out_offset = td->td_uretoff.tdu_off;
+ } else
+ out_offset = 0;
+
+ flags = FOF_OFFSET | FOF_NOUPDATE;
+ bufsz = min(count, maxphys);
+ buf = malloc(bufsz, M_LINUX, M_WAITOK);
+ bytes_sent = 0;
+ while (bytes_sent < count) {
+ to_send = min(count - bytes_sent, bufsz);
+ aiov.iov_base = buf;
+ aiov.iov_len = bufsz;
+ auio.uio_iov = &aiov;
+ auio.uio_iovcnt = 1;
+ auio.uio_segflg = UIO_SYSSPACE;
+ auio.uio_td = td;
+ auio.uio_rw = UIO_READ;
+ auio.uio_offset = current_offset;
+ auio.uio_resid = to_send;
+ error = fo_read(fp, &auio, fp->f_cred, flags, td);
+ if (error != 0)
+ break;
+ n_read = to_send - auio.uio_resid;
+ if (n_read == 0)
+ break;
+ aiov.iov_base = buf;
+ aiov.iov_len = bufsz;
+ auio.uio_iov = &aiov;
+ auio.uio_iovcnt = 1;
+ auio.uio_segflg = UIO_SYSSPACE;
+ auio.uio_td = td;
+ auio.uio_rw = UIO_WRITE;
+ auio.uio_offset = (seekable) ? out_offset : 0;
+ auio.uio_resid = n_read;
+ error = fo_write(ofp, &auio, ofp->f_cred, flags, td);
+ if (error != 0)
+ break;
+ bytes_sent += n_read;
+ current_offset += n_read;
+ out_offset += n_read;
+ }
+ free(buf, M_LINUX);
+
+ if (error == 0) {
+ *sbytes = bytes_sent;
+ if (offset != NULL)
+ *offset = current_offset;
+ else
+ error = fo_seek(fp, current_offset, SEEK_SET, td);
+ }
+ if (error == 0 && seekable)
+ error = fo_seek(ofp, out_offset, SEEK_SET, td);
+
+drop:
+ fdrop(ofp, td);
+ return (error);
+}
+
+static int
+sendfile_sendfile(struct thread *td, struct file *fp, l_int out,
+ off_t *offset, l_size_t count, off_t *sbytes)
+{
+ off_t current_offset;
+ int error;
+
+ if (offset == NULL) {
+ if ((fp->f_ops->fo_flags & DFLAG_SEEKABLE) == 0)
+ return (ESPIPE);
+ if ((error = fo_seek(fp, 0, SEEK_CUR, td)) != 0)
+ return (error);
current_offset = td->td_uretoff.tdu_off;
+ } else
+ current_offset = *offset;
+ error = fo_sendfile(fp, out, NULL, NULL, current_offset, count,
+ sbytes, 0, td);
+ if (error == EAGAIN && *sbytes > 0) {
+ /*
+ * The socket is non-blocking and we didn't finish sending.
+ * Squash the error, since that's what Linux does.
+ */
+ error = 0;
+ }
+ if (error == 0) {
+ current_offset += *sbytes;
+ if (offset != NULL)
+ *offset = current_offset;
+ else
+ error = fo_seek(fp, current_offset, SEEK_SET, td);
}
+ return (error);
+}
- bytes_read = 0;
+static int
+linux_sendfile_common(struct thread *td, l_int out, l_int in,
+ off_t *offset, l_size_t count)
+{
+ struct file *fp, *ofp;
+ off_t sbytes;
+ int error;
/* Linux cannot have 0 count. */
- if (count <= 0 || current_offset < 0) {
+ if (count <= 0 || (offset != NULL && *offset < 0))
+ return (EINVAL);
+
+ AUDIT_ARG_FD(in);
+ error = fget_read(td, in, &cap_pread_rights, &fp);
+ if (error != 0)
+ return (error);
+ if ((fp->f_type != DTYPE_SHM && fp->f_type != DTYPE_VNODE) ||
+ (fp->f_type == DTYPE_VNODE &&
+ (fp->f_vnode == NULL || fp->f_vnode->v_type != VREG))) {
error = EINVAL;
goto drop;
}
-
- error = fo_sendfile(fp, out, NULL, NULL, current_offset, count,
- &bytes_read, 0, td);
+ error = fget_unlocked(td, out, &cap_no_rights, &ofp);
if (error != 0)
goto drop;
- current_offset += bytes_read;
- if (offset != NULL) {
- *offset = current_offset;
+ if (is_regular_file(fp) && is_regular_file(ofp)) {
+ error = kern_copy_file_range(td, in, offset, out, NULL, count,
+ 0);
} else {
- error = fo_seek(fp, current_offset, SEEK_SET, td);
- if (error != 0)
- goto drop;
+ sbytes = 0;
+ if (is_sendfile(fp, ofp))
+ error = sendfile_sendfile(td, fp, out, offset, count,
+ &sbytes);
+ else
+ error = sendfile_fallback(td, fp, out, offset, count,
+ &sbytes);
+ if (error == ENOBUFS && (ofp->f_flag & FNONBLOCK) != 0)
+ error = EAGAIN;
+ if (error == 0)
+ td->td_retval[0] = sbytes;
}
+ fdrop(ofp, td);
- td->td_retval[0] = (ssize_t)bytes_read;
drop:
fdrop(fp, td);
- if (error == ENOTSOCK)
- error = EINVAL;
return (error);
}
@@ -2112,10 +2639,10 @@ linux_sendfile(struct thread *td, struct linux_sendfile_args *arg)
/*
* Differences between FreeBSD and Linux sendfile:
* - Linux doesn't send anything when count is 0 (FreeBSD uses 0 to
- * mean send the whole file.) In linux_sendfile given fds are still
- * checked for validity when the count is 0.
+ * mean send the whole file).
* - Linux can send to any fd whereas FreeBSD only supports sockets.
- * The same restriction follows for linux_sendfile.
+ * We therefore use FreeBSD sendfile where possible for performance,
+ * but fall back on a manual copy (sendfile_fallback).
* - Linux doesn't have an equivalent for FreeBSD's flags and sf_hdtr.
* - Linux takes an offset pointer and updates it to the read location.
* FreeBSD takes in an offset and a 'bytes read' parameter which is
@@ -2125,44 +2652,37 @@ linux_sendfile(struct thread *td, struct linux_sendfile_args *arg)
* returns 0. We use the 'bytes read' parameter to get this value.
*/
- l_loff_t offset64;
- l_long offset;
- int ret;
+ off_t offset64;
+ l_off_t offset;
int error;
if (arg->offset != NULL) {
error = copyin(arg->offset, &offset, sizeof(offset));
if (error != 0)
return (error);
- offset64 = (l_loff_t)offset;
+ offset64 = offset;
}
- ret = linux_sendfile_common(td, arg->out, arg->in,
+ error = linux_sendfile_common(td, arg->out, arg->in,
arg->offset != NULL ? &offset64 : NULL, arg->count);
- if (arg->offset != NULL) {
-#if defined(__i386__) || defined(__arm__) || \
- (defined(__amd64__) && defined(COMPAT_LINUX32))
+ if (error == 0 && arg->offset != NULL) {
+#if defined(__i386__) || (defined(__amd64__) && defined(COMPAT_LINUX32))
if (offset64 > INT32_MAX)
return (EOVERFLOW);
#endif
- offset = (l_long)offset64;
+ offset = (l_off_t)offset64;
error = copyout(&offset, arg->offset, sizeof(offset));
- if (error != 0)
- return (error);
}
- return (ret);
+ return (error);
}
-#if defined(__i386__) || defined(__arm__) || \
- (defined(__amd64__) && defined(COMPAT_LINUX32))
-
+#if defined(__i386__) || (defined(__amd64__) && defined(COMPAT_LINUX32))
int
linux_sendfile64(struct thread *td, struct linux_sendfile64_args *arg)
{
- l_loff_t offset;
- int ret;
+ off_t offset;
int error;
if (arg->offset != NULL) {
@@ -2171,16 +2691,13 @@ linux_sendfile64(struct thread *td, struct linux_sendfile64_args *arg)
return (error);
}
- ret = linux_sendfile_common(td, arg->out, arg->in,
+ error = linux_sendfile_common(td, arg->out, arg->in,
arg->offset != NULL ? &offset : NULL, arg->count);
- if (arg->offset != NULL) {
+ if (error == 0 && arg->offset != NULL)
error = copyout(&offset, arg->offset, sizeof(offset));
- if (error != 0)
- return (error);
- }
- return (ret);
+ return (error);
}
/* Argument list sizes for linux_socketcall */
@@ -2271,4 +2788,4 @@ linux_socketcall(struct thread *td, struct linux_socketcall_args *args)
linux_msg(td, "socket type %d not implemented", args->what);
return (ENOSYS);
}
-#endif /* __i386__ || __arm__ || (__amd64__ && COMPAT_LINUX32) */
+#endif /* __i386__ || (__amd64__ && COMPAT_LINUX32) */
diff --git a/sys/compat/linux/linux_socket.h b/sys/compat/linux/linux_socket.h
index 9c37d8c97c3d..68176c3cc401 100644
--- a/sys/compat/linux/linux_socket.h
+++ b/sys/compat/linux/linux_socket.h
@@ -26,8 +26,6 @@
* 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.
- *
- * $FreeBSD$
*/
#ifndef _LINUX_SOCKET_H_
@@ -53,12 +51,6 @@
#define LINUX_MSG_WAITFORONE 0x10000
#define LINUX_MSG_CMSG_CLOEXEC 0x40000000
-/* Socket-level control message types */
-
-#define LINUX_SCM_RIGHTS 0x01
-#define LINUX_SCM_CREDENTIALS 0x02
-#define LINUX_SCM_TIMESTAMP 0x1D
-
struct l_msghdr {
l_uintptr_t msg_name;
l_int msg_namelen;
@@ -132,8 +124,7 @@ struct l_ucred {
uint32_t gid;
};
-#if defined(__i386__) || defined(__arm__) || \
- (defined(__amd64__) && defined(COMPAT_LINUX32))
+#if defined(__i386__) || (defined(__amd64__) && defined(COMPAT_LINUX32))
struct linux_accept_args {
register_t s;
@@ -166,7 +157,7 @@ int linux_accept(struct thread *td, struct linux_accept_args *args);
#define LINUX_SENDMMSG 20
#define LINUX_SENDFILE 21
-#endif /* __i386__ || __arm__ || (__amd64__ && COMPAT_LINUX32) */
+#endif /* __i386__ || (__amd64__ && COMPAT_LINUX32) */
/* Socket defines */
#define LINUX_SOL_SOCKET 1
@@ -193,14 +184,27 @@ int linux_accept(struct thread *td, struct linux_accept_args *args);
#define LINUX_SO_RCVTIMEO 20
#define LINUX_SO_SNDTIMEO 21
#endif
-#define LINUX_SO_TIMESTAMP 29
+#define LINUX_SO_TIMESTAMPO 29
+#define LINUX_SO_TIMESTAMPN 63
+#define LINUX_SO_TIMESTAMPNSO 35
+#define LINUX_SO_TIMESTAMPNSN 64
#define LINUX_SO_ACCEPTCONN 30
#define LINUX_SO_PEERSEC 31
#define LINUX_SO_SNDBUFFORCE 32
#define LINUX_SO_RCVBUFFORCE 33
#define LINUX_SO_PROTOCOL 38
+#define LINUX_SO_DOMAIN 39
#define LINUX_SO_PEERGROUPS 59
+/* Socket-level control message types */
+
+#define LINUX_SCM_RIGHTS 0x01
+#define LINUX_SCM_CREDENTIALS 0x02
+#define LINUX_SCM_TIMESTAMPO LINUX_SO_TIMESTAMPO
+#define LINUX_SCM_TIMESTAMPN LINUX_SO_TIMESTAMPN
+#define LINUX_SCM_TIMESTAMPNSO LINUX_SO_TIMESTAMPNSO
+#define LINUX_SCM_TIMESTAMPNSN LINUX_SO_TIMESTAMPNSN
+
/* Socket options */
#define LINUX_IP_TOS 1
#define LINUX_IP_TTL 2
@@ -222,6 +226,8 @@ int linux_accept(struct thread *td, struct linux_accept_args *args);
#define LINUX_IP_PASSSEC 18
#define LINUX_IP_TRANSPARENT 19
+#define LINUX_IP_ORIGDSTADDR 20
+#define LINUX_IP_RECVORIGDSTADDR LINUX_IP_ORIGDSTADDR
#define LINUX_IP_MINTTL 21
#define LINUX_IP_NODEFRAG 22
#define LINUX_IP_CHECKSUM 23
@@ -317,4 +323,42 @@ int linux_accept(struct thread *td, struct linux_accept_args *args);
#define LINUX_TCP_INFO 11
#define LINUX_TCP_MD5SIG 14
+struct l_ifmap {
+ l_ulong mem_start;
+ l_ulong mem_end;
+ l_ushort base_addr;
+ u_char irq;
+ u_char dma;
+ u_char port;
+ /* 3 bytes spare */
+};
+
+/*
+ * Careful changing the declaration of this structure.
+ * To use FreeBSD names to access the struct l_ifreq members the
+ * member names of struct l_ifreq should be equal to the FreeBSD.
+ */
+struct l_ifreq {
+ char ifr_name[LINUX_IFNAMSIZ];
+ union {
+ struct l_sockaddr ifru_addr;
+ struct l_sockaddr ifru_dstaddr;
+ struct l_sockaddr ifru_broadaddr;
+ struct l_sockaddr ifru_netmask;
+ struct l_sockaddr ifru_hwaddr;
+ l_short ifru_flags[1];
+ l_int ifru_index;
+ l_int ifru_mtu;
+ struct l_ifmap ifru_map;
+ char ifru_slave[LINUX_IFNAMSIZ];
+ char ifru_newname[LINUX_IFNAMSIZ];
+ l_uintptr_t ifru_data;
+ } ifr_ifru;
+};
+
+/*
+ * Define here members which are not exists in the FreeBSD struct ifreq.
+ */
+#define ifr_hwaddr ifr_ifru.ifru_hwaddr /* MAC address */
+
#endif /* _LINUX_SOCKET_H_ */
diff --git a/sys/compat/linux/linux_stats.c b/sys/compat/linux/linux_stats.c
index 9dc7686cb963..03783d466211 100644
--- a/sys/compat/linux/linux_stats.c
+++ b/sys/compat/linux/linux_stats.c
@@ -1,5 +1,5 @@
/*-
- * SPDX-License-Identifier: BSD-2-Clause-FreeBSD
+ * SPDX-License-Identifier: BSD-2-Clause
*
* Copyright (c) 1994-1995 Søren Schmidt
* All rights reserved.
@@ -26,27 +26,25 @@
* SUCH DAMAGE.
*/
-#include <sys/cdefs.h>
-__FBSDID("$FreeBSD$");
-
-#include "opt_compat.h"
+#include "opt_ktrace.h"
#include <sys/param.h>
#include <sys/capsicum.h>
#include <sys/dirent.h>
-#include <sys/file.h>
-#include <sys/filedesc.h>
-#include <sys/proc.h>
+#include <sys/lock.h>
#include <sys/malloc.h>
-#include <sys/mount.h>
+#include <sys/mutex.h>
#include <sys/namei.h>
+#include <sys/proc.h>
#include <sys/stat.h>
#include <sys/syscallsubr.h>
-#include <sys/systm.h>
#include <sys/tty.h>
#include <sys/vnode.h>
-#include <sys/conf.h>
-#include <sys/fcntl.h>
+#ifdef KTRACE
+#include <sys/ktrace.h>
+#endif
+
+#include <security/audit/audit.h>
#ifdef COMPAT_LINUX32
#include <machine/../linux32/linux.h>
@@ -56,41 +54,68 @@ __FBSDID("$FreeBSD$");
#include <machine/../linux/linux_proto.h>
#endif
-#include <compat/linux/linux_util.h>
+#include <compat/linux/linux.h>
#include <compat/linux/linux_file.h>
+#include <compat/linux/linux_util.h>
-static void
-translate_vnhook_major_minor(struct vnode *vp, struct stat *sb)
+
+static int
+linux_kern_fstat(struct thread *td, int fd, struct stat *sbp)
{
- int major, minor;
+ struct vnode *vp;
+ struct file *fp;
+ int error;
- if (vn_isdisk(vp)) {
- sb->st_mode &= ~S_IFMT;
- sb->st_mode |= S_IFBLK;
- }
+ AUDIT_ARG_FD(fd);
- /*
- * Return the same st_dev for every devfs instance. The reason
- * for this is to work around an idiosyncrasy of glibc getttynam()
- * implementation: it checks whether st_dev returned for fd 0
- * is the same as st_dev returned for the target of /proc/self/fd/0
- * symlink, and with linux chroots having their own devfs instance,
- * the check will fail if you chroot into it.
- */
- if (rootdevmp != NULL && vp->v_mount->mnt_vfc == rootdevmp->mnt_vfc)
- sb->st_dev = rootdevmp->mnt_stat.f_fsid.val[0];
+ error = fget(td, fd, &cap_fstat_rights, &fp);
+ if (__predict_false(error != 0))
+ return (error);
- if (linux_vn_get_major_minor(vp, &major, &minor) == 0)
- sb->st_rdev = (major << 8 | minor);
+ AUDIT_ARG_FILE(td->td_proc, fp);
+
+ error = fo_stat(fp, sbp, td->td_ucred);
+ if (error == 0 && (vp = fp->f_vnode) != NULL)
+ translate_vnhook_major_minor(vp, sbp);
+ fdrop(fp, td);
+#ifdef KTRACE
+ if (KTRPOINT(td, KTR_STRUCT))
+ ktrstat_error(sbp, error);
+#endif
+ return (error);
}
static int
linux_kern_statat(struct thread *td, int flag, int fd, const char *path,
enum uio_seg pathseg, struct stat *sbp)
{
+ struct nameidata nd;
+ int error;
+
+ if ((flag & ~(AT_SYMLINK_NOFOLLOW | AT_RESOLVE_BENEATH |
+ AT_EMPTY_PATH)) != 0)
+ return (EINVAL);
- return (kern_statat(td, flag, fd, path, pathseg, sbp,
- translate_vnhook_major_minor));
+ NDINIT_ATRIGHTS(&nd, LOOKUP, at2cnpflags(flag, AT_RESOLVE_BENEATH |
+ AT_SYMLINK_NOFOLLOW | AT_EMPTY_PATH) | LOCKSHARED | LOCKLEAF |
+ AUDITVNODE1, pathseg, path, fd, &cap_fstat_rights);
+
+ if ((error = namei(&nd)) != 0) {
+ if (error == ENOTDIR &&
+ (nd.ni_resflags & NIRES_EMPTYPATH) != 0)
+ error = linux_kern_fstat(td, fd, sbp);
+ return (error);
+ }
+ error = VOP_STAT(nd.ni_vp, sbp, td->td_ucred, NOCRED);
+ if (error == 0)
+ translate_vnhook_major_minor(nd.ni_vp, sbp);
+ NDFREE_PNBUF(&nd);
+ vput(nd.ni_vp);
+#ifdef KTRACE
+ if (KTRPOINT(td, KTR_STRUCT))
+ ktrstat_error(sbp, error);
+#endif
+ return (error);
}
#ifdef LINUX_LEGACY_SYSCALLS
@@ -112,77 +137,19 @@ linux_kern_lstat(struct thread *td, const char *path, enum uio_seg pathseg,
}
#endif
-static void
-translate_fd_major_minor(struct thread *td, int fd, struct stat *buf)
-{
- struct file *fp;
- struct vnode *vp;
- struct mount *mp;
- int major, minor;
-
- /*
- * No capability rights required here.
- */
- if ((!S_ISCHR(buf->st_mode) && !S_ISBLK(buf->st_mode)) ||
- fget(td, fd, &cap_no_rights, &fp) != 0)
- return;
- vp = fp->f_vnode;
- if (vp != NULL && vn_isdisk(vp)) {
- buf->st_mode &= ~S_IFMT;
- buf->st_mode |= S_IFBLK;
- }
- if (vp != NULL && rootdevmp != NULL) {
- mp = vp->v_mount;
- __compiler_membar();
- if (mp != NULL && mp->mnt_vfc == rootdevmp->mnt_vfc)
- buf->st_dev = rootdevmp->mnt_stat.f_fsid.val[0];
- }
- if (linux_vn_get_major_minor(vp, &major, &minor) == 0) {
- buf->st_rdev = (major << 8 | minor);
- } else if (fp->f_type == DTYPE_PTS) {
- struct tty *tp = fp->f_data;
-
- /* Convert the numbers for the slave device. */
- if (linux_driver_get_major_minor(devtoname(tp->t_dev),
- &major, &minor) == 0) {
- buf->st_rdev = (major << 8 | minor);
- }
- }
- fdrop(fp, td);
-}
-
-/*
- * l_dev_t has the same encoding as dev_t in the latter's low 16 bits, so
- * truncation of a dev_t to 16 bits gives the same result as unpacking
- * using major() and minor() and repacking in the l_dev_t format. This
- * detail is hidden in dev_to_ldev(). Overflow in conversions of dev_t's
- * are not checked for, as for other fields.
- *
- * dev_to_ldev() is only used for translating st_dev. When we convert
- * st_rdev for copying it out, it isn't really a dev_t, but has already
- * been translated to an l_dev_t in a nontrivial way. Translating it
- * again would be illogical but would have no effect since the low 16
- * bits have the same encoding.
- *
- * The nontrivial translation for st_rdev renumbers some devices, but not
- * ones that can be mounted on, so it is consistent with the translation
- * for st_dev except when the renumbering or truncation causes conflicts.
- */
-#define dev_to_ldev(d) ((uint16_t)(d))
-
static int
newstat_copyout(struct stat *buf, void *ubuf)
{
struct l_newstat tbuf;
bzero(&tbuf, sizeof(tbuf));
- tbuf.st_dev = dev_to_ldev(buf->st_dev);
+ tbuf.st_dev = linux_new_encode_dev(buf->st_dev);
tbuf.st_ino = buf->st_ino;
tbuf.st_mode = buf->st_mode;
tbuf.st_nlink = buf->st_nlink;
tbuf.st_uid = buf->st_uid;
tbuf.st_gid = buf->st_gid;
- tbuf.st_rdev = buf->st_rdev;
+ tbuf.st_rdev = linux_new_encode_dev(buf->st_rdev);
tbuf.st_size = buf->st_size;
tbuf.st_atim.tv_sec = buf->st_atim.tv_sec;
tbuf.st_atim.tv_nsec = buf->st_atim.tv_nsec;
@@ -196,55 +163,15 @@ newstat_copyout(struct stat *buf, void *ubuf)
return (copyout(&tbuf, ubuf, sizeof(tbuf)));
}
-static int
-statx_copyout(struct stat *buf, void *ubuf)
-{
- struct l_statx tbuf;
-
- bzero(&tbuf, sizeof(tbuf));
- tbuf.stx_mask = STATX_ALL;
- tbuf.stx_blksize = buf->st_blksize;
- tbuf.stx_attributes = 0;
- tbuf.stx_nlink = buf->st_nlink;
- tbuf.stx_uid = buf->st_uid;
- tbuf.stx_gid = buf->st_gid;
- tbuf.stx_mode = buf->st_mode;
- tbuf.stx_ino = buf->st_ino;
- tbuf.stx_size = buf->st_size;
- tbuf.stx_blocks = buf->st_blocks;
-
- tbuf.stx_atime.tv_sec = buf->st_atim.tv_sec;
- tbuf.stx_atime.tv_nsec = buf->st_atim.tv_nsec;
- tbuf.stx_btime.tv_sec = buf->st_birthtim.tv_sec;
- tbuf.stx_btime.tv_nsec = buf->st_birthtim.tv_nsec;
- tbuf.stx_ctime.tv_sec = buf->st_ctim.tv_sec;
- tbuf.stx_ctime.tv_nsec = buf->st_ctim.tv_nsec;
- tbuf.stx_mtime.tv_sec = buf->st_mtim.tv_sec;
- tbuf.stx_mtime.tv_nsec = buf->st_mtim.tv_nsec;
-
- tbuf.stx_rdev_major = buf->st_rdev >> 8;
- tbuf.stx_rdev_minor = buf->st_rdev & 0xff;
- tbuf.stx_dev_major = buf->st_dev >> 8;
- tbuf.stx_dev_minor = buf->st_dev & 0xff;
-
- return (copyout(&tbuf, ubuf, sizeof(tbuf)));
-}
#ifdef LINUX_LEGACY_SYSCALLS
int
linux_newstat(struct thread *td, struct linux_newstat_args *args)
{
struct stat buf;
- char *path;
int error;
- if (!LUSECONVPATH(td)) {
- error = linux_kern_stat(td, args->path, UIO_USERSPACE, &buf);
- } else {
- LCONVPATHEXIST(args->path, &path);
- error = linux_kern_stat(td, path, UIO_SYSSPACE, &buf);
- LFREEPATH(path);
- }
+ error = linux_kern_stat(td, args->path, UIO_USERSPACE, &buf);
if (error)
return (error);
return (newstat_copyout(&buf, args->buf));
@@ -254,16 +181,9 @@ int
linux_newlstat(struct thread *td, struct linux_newlstat_args *args)
{
struct stat sb;
- char *path;
int error;
- if (!LUSECONVPATH(td)) {
- error = linux_kern_lstat(td, args->path, UIO_USERSPACE, &sb);
- } else {
- LCONVPATHEXIST(args->path, &path);
- error = linux_kern_lstat(td, path, UIO_SYSSPACE, &sb);
- LFREEPATH(path);
- }
+ error = linux_kern_lstat(td, args->path, UIO_USERSPACE, &sb);
if (error)
return (error);
return (newstat_copyout(&sb, args->buf));
@@ -276,8 +196,7 @@ linux_newfstat(struct thread *td, struct linux_newfstat_args *args)
struct stat buf;
int error;
- error = kern_fstat(td, args->fd, &buf);
- translate_fd_major_minor(td, args->fd, &buf);
+ error = linux_kern_fstat(td, args->fd, &buf);
if (!error)
error = newstat_copyout(&buf, args->buf);
@@ -285,19 +204,27 @@ linux_newfstat(struct thread *td, struct linux_newfstat_args *args)
}
#if defined(__i386__) || (defined(__amd64__) && defined(COMPAT_LINUX32))
+
+static __inline uint16_t
+linux_old_encode_dev(dev_t _dev)
+{
+
+ return (_dev == NODEV ? 0 : linux_encode_dev(major(_dev), minor(_dev)));
+}
+
static int
-stat_copyout(struct stat *buf, void *ubuf)
+old_stat_copyout(struct stat *buf, void *ubuf)
{
- struct l_stat lbuf;
+ struct l_old_stat lbuf;
bzero(&lbuf, sizeof(lbuf));
- lbuf.st_dev = dev_to_ldev(buf->st_dev);
+ lbuf.st_dev = linux_old_encode_dev(buf->st_dev);
lbuf.st_ino = buf->st_ino;
lbuf.st_mode = buf->st_mode;
lbuf.st_nlink = buf->st_nlink;
lbuf.st_uid = buf->st_uid;
lbuf.st_gid = buf->st_gid;
- lbuf.st_rdev = buf->st_rdev;
+ lbuf.st_rdev = linux_old_encode_dev(buf->st_rdev);
lbuf.st_size = MIN(buf->st_size, INT32_MAX);
lbuf.st_atim.tv_sec = buf->st_atim.tv_sec;
lbuf.st_atim.tv_nsec = buf->st_atim.tv_nsec;
@@ -317,40 +244,26 @@ int
linux_stat(struct thread *td, struct linux_stat_args *args)
{
struct stat buf;
- char *path;
int error;
- if (!LUSECONVPATH(td)) {
- error = linux_kern_stat(td, args->path, UIO_USERSPACE, &buf);
- } else {
- LCONVPATHEXIST(args->path, &path);
- error = linux_kern_stat(td, path, UIO_SYSSPACE, &buf);
- LFREEPATH(path);
- }
+ error = linux_kern_stat(td, args->path, UIO_USERSPACE, &buf);
if (error) {
return (error);
}
- return (stat_copyout(&buf, args->up));
+ return (old_stat_copyout(&buf, args->up));
}
int
linux_lstat(struct thread *td, struct linux_lstat_args *args)
{
struct stat buf;
- char *path;
int error;
- if (!LUSECONVPATH(td)) {
- error = linux_kern_lstat(td, args->path, UIO_USERSPACE, &buf);
- } else {
- LCONVPATHEXIST(args->path, &path);
- error = linux_kern_lstat(td, path, UIO_SYSSPACE, &buf);
- LFREEPATH(path);
- }
+ error = linux_kern_lstat(td, args->path, UIO_USERSPACE, &buf);
if (error) {
return (error);
}
- return (stat_copyout(&buf, args->up));
+ return (old_stat_copyout(&buf, args->up));
}
#endif /* __i386__ || (__amd64__ && COMPAT_LINUX32) */
@@ -411,33 +324,50 @@ bsd_to_linux_ftype(const char *fstypename)
}
static int
-bsd_to_linux_statfs(struct statfs *bsd_statfs, struct l_statfs *linux_statfs)
+bsd_to_linux_mnt_flags(int f_flags)
{
-#if defined(__i386__) || (defined(__amd64__) && defined(COMPAT_LINUX32))
- uint64_t tmp;
+ int flags = LINUX_ST_VALID;
+
+ if (f_flags & MNT_RDONLY)
+ flags |= LINUX_ST_RDONLY;
+ if (f_flags & MNT_NOEXEC)
+ flags |= LINUX_ST_NOEXEC;
+ if (f_flags & MNT_NOSUID)
+ flags |= LINUX_ST_NOSUID;
+ if (f_flags & MNT_NOATIME)
+ flags |= LINUX_ST_NOATIME;
+ if (f_flags & MNT_NOSYMFOLLOW)
+ flags |= LINUX_ST_NOSYMFOLLOW;
+ if (f_flags & MNT_SYNCHRONOUS)
+ flags |= LINUX_ST_SYNCHRONOUS;
+
+ return (flags);
+}
-#define LINUX_HIBITS 0xffffffff00000000ULL
+static int
+bsd_to_linux_statfs(struct statfs *bsd_statfs, struct l_statfs *linux_statfs)
+{
- tmp = bsd_statfs->f_blocks | bsd_statfs->f_bfree | bsd_statfs->f_files |
- bsd_statfs->f_bsize;
- if ((bsd_statfs->f_bavail != -1 && (bsd_statfs->f_bavail & LINUX_HIBITS)) ||
- (bsd_statfs->f_ffree != -1 && (bsd_statfs->f_ffree & LINUX_HIBITS)) ||
- (tmp & LINUX_HIBITS))
- return (EOVERFLOW);
-#undef LINUX_HIBITS
+#if defined(__i386__) || (defined(__amd64__) && defined(COMPAT_LINUX32))
+ statfs_scale_blocks(bsd_statfs, INT32_MAX);
#endif
linux_statfs->f_type = bsd_to_linux_ftype(bsd_statfs->f_fstypename);
linux_statfs->f_bsize = bsd_statfs->f_bsize;
linux_statfs->f_blocks = bsd_statfs->f_blocks;
linux_statfs->f_bfree = bsd_statfs->f_bfree;
linux_statfs->f_bavail = bsd_statfs->f_bavail;
+#if defined(__i386__) || (defined(__amd64__) && defined(COMPAT_LINUX32))
+ linux_statfs->f_ffree = MIN(bsd_statfs->f_ffree, INT32_MAX);
+ linux_statfs->f_files = MIN(bsd_statfs->f_files, INT32_MAX);
+#else
linux_statfs->f_ffree = bsd_statfs->f_ffree;
linux_statfs->f_files = bsd_statfs->f_files;
+#endif
linux_statfs->f_fsid.val[0] = bsd_statfs->f_fsid.val[0];
linux_statfs->f_fsid.val[1] = bsd_statfs->f_fsid.val[1];
linux_statfs->f_namelen = MAXNAMLEN;
linux_statfs->f_frsize = bsd_statfs->f_bsize;
- linux_statfs->f_flags = 0;
+ linux_statfs->f_flags = bsd_to_linux_mnt_flags(bsd_statfs->f_flags);
memset(linux_statfs->f_spare, 0, sizeof(linux_statfs->f_spare));
return (0);
@@ -448,18 +378,10 @@ linux_statfs(struct thread *td, struct linux_statfs_args *args)
{
struct l_statfs linux_statfs;
struct statfs *bsd_statfs;
- char *path;
int error;
- if (!LUSECONVPATH(td)) {
- bsd_statfs = malloc(sizeof(struct statfs), M_STATFS, M_WAITOK);
- error = kern_statfs(td, args->path, UIO_USERSPACE, bsd_statfs);
- } else {
- LCONVPATHEXIST(args->path, &path);
- bsd_statfs = malloc(sizeof(struct statfs), M_STATFS, M_WAITOK);
- error = kern_statfs(td, path, UIO_SYSSPACE, bsd_statfs);
- LFREEPATH(path);
- }
+ bsd_statfs = malloc(sizeof(struct statfs), M_STATFS, M_WAITOK);
+ error = kern_statfs(td, args->path, UIO_USERSPACE, bsd_statfs);
if (error == 0)
error = bsd_to_linux_statfs(bsd_statfs, &linux_statfs);
free(bsd_statfs, M_STATFS);
@@ -484,7 +406,7 @@ bsd_to_linux_statfs64(struct statfs *bsd_statfs, struct l_statfs64 *linux_statfs
linux_statfs->f_fsid.val[1] = bsd_statfs->f_fsid.val[1];
linux_statfs->f_namelen = MAXNAMLEN;
linux_statfs->f_frsize = bsd_statfs->f_bsize;
- linux_statfs->f_flags = 0;
+ linux_statfs->f_flags = bsd_to_linux_mnt_flags(bsd_statfs->f_flags);
memset(linux_statfs->f_spare, 0, sizeof(linux_statfs->f_spare));
}
@@ -493,21 +415,13 @@ linux_statfs64(struct thread *td, struct linux_statfs64_args *args)
{
struct l_statfs64 linux_statfs;
struct statfs *bsd_statfs;
- char *path;
int error;
if (args->bufsize != sizeof(struct l_statfs64))
return (EINVAL);
- if (!LUSECONVPATH(td)) {
- bsd_statfs = malloc(sizeof(struct statfs), M_STATFS, M_WAITOK);
- error = kern_statfs(td, args->path, UIO_USERSPACE, bsd_statfs);
- } else {
- LCONVPATHEXIST(args->path, &path);
- bsd_statfs = malloc(sizeof(struct statfs), M_STATFS, M_WAITOK);
- error = kern_statfs(td, path, UIO_SYSSPACE, bsd_statfs);
- LFREEPATH(path);
- }
+ bsd_statfs = malloc(sizeof(struct statfs), M_STATFS, M_WAITOK);
+ error = kern_statfs(td, args->path, UIO_USERSPACE, bsd_statfs);
if (error == 0)
bsd_to_linux_statfs64(bsd_statfs, &linux_statfs);
free(bsd_statfs, M_STATFS);
@@ -571,6 +485,31 @@ linux_ustat(struct thread *td, struct linux_ustat_args *args)
}
#endif
+/*
+ * Convert Linux stat flags to BSD flags. Return value indicates successful
+ * conversion (no unknown flags).
+ */
+static bool
+linux_to_bsd_stat_flags(int linux_flags, int *out_flags)
+{
+ int flags, unsupported;
+
+ unsupported = linux_flags & ~(LINUX_AT_SYMLINK_NOFOLLOW |
+ LINUX_AT_EMPTY_PATH | LINUX_AT_NO_AUTOMOUNT);
+ if (unsupported != 0) {
+ *out_flags = unsupported;
+ return (false);
+ }
+
+ flags = 0;
+ if (linux_flags & LINUX_AT_SYMLINK_NOFOLLOW)
+ flags |= AT_SYMLINK_NOFOLLOW;
+ if (linux_flags & LINUX_AT_EMPTY_PATH)
+ flags |= AT_EMPTY_PATH;
+ *out_flags = flags;
+ return (true);
+}
+
#if defined(__i386__) || (defined(__amd64__) && defined(COMPAT_LINUX32))
static int
@@ -579,13 +518,13 @@ stat64_copyout(struct stat *buf, void *ubuf)
struct l_stat64 lbuf;
bzero(&lbuf, sizeof(lbuf));
- lbuf.st_dev = dev_to_ldev(buf->st_dev);
+ lbuf.st_dev = linux_new_encode_dev(buf->st_dev);
lbuf.st_ino = buf->st_ino;
lbuf.st_mode = buf->st_mode;
lbuf.st_nlink = buf->st_nlink;
lbuf.st_uid = buf->st_uid;
lbuf.st_gid = buf->st_gid;
- lbuf.st_rdev = buf->st_rdev;
+ lbuf.st_rdev = linux_new_encode_dev(buf->st_rdev);
lbuf.st_size = buf->st_size;
lbuf.st_atim.tv_sec = buf->st_atim.tv_sec;
lbuf.st_atim.tv_nsec = buf->st_atim.tv_nsec;
@@ -611,16 +550,9 @@ int
linux_stat64(struct thread *td, struct linux_stat64_args *args)
{
struct stat buf;
- char *filename;
int error;
- if (!LUSECONVPATH(td)) {
- error = linux_kern_stat(td, args->filename, UIO_USERSPACE, &buf);
- } else {
- LCONVPATHEXIST(args->filename, &filename);
- error = linux_kern_stat(td, filename, UIO_SYSSPACE, &buf);
- LFREEPATH(filename);
- }
+ error = linux_kern_stat(td, args->filename, UIO_USERSPACE, &buf);
if (error)
return (error);
return (stat64_copyout(&buf, args->statbuf));
@@ -630,16 +562,9 @@ int
linux_lstat64(struct thread *td, struct linux_lstat64_args *args)
{
struct stat sb;
- char *filename;
int error;
- if (!LUSECONVPATH(td)) {
- error = linux_kern_lstat(td, args->filename, UIO_USERSPACE, &sb);
- } else {
- LCONVPATHEXIST(args->filename, &filename);
- error = linux_kern_lstat(td, filename, UIO_SYSSPACE, &sb);
- LFREEPATH(filename);
- }
+ error = linux_kern_lstat(td, args->filename, UIO_USERSPACE, &sb);
if (error)
return (error);
return (stat64_copyout(&sb, args->statbuf));
@@ -651,8 +576,7 @@ linux_fstat64(struct thread *td, struct linux_fstat64_args *args)
struct stat buf;
int error;
- error = kern_fstat(td, args->fd, &buf);
- translate_fd_major_minor(td, args->fd, &buf);
+ error = linux_kern_fstat(td, args->fd, &buf);
if (!error)
error = stat64_copyout(&buf, args->statbuf);
@@ -662,29 +586,17 @@ linux_fstat64(struct thread *td, struct linux_fstat64_args *args)
int
linux_fstatat64(struct thread *td, struct linux_fstatat64_args *args)
{
- char *path;
- int error, dfd, flag, unsupported;
+ int error, dfd, flags;
struct stat buf;
- unsupported = args->flag & ~(LINUX_AT_SYMLINK_NOFOLLOW | LINUX_AT_EMPTY_PATH);
- if (unsupported != 0) {
- linux_msg(td, "fstatat64 unsupported flag 0x%x", unsupported);
+ if (!linux_to_bsd_stat_flags(args->flag, &flags)) {
+ linux_msg(td, "fstatat64 unsupported flags 0x%x", flags);
return (EINVAL);
}
- flag = (args->flag & LINUX_AT_SYMLINK_NOFOLLOW) ?
- AT_SYMLINK_NOFOLLOW : 0;
- flag |= (args->flag & LINUX_AT_EMPTY_PATH) ?
- AT_EMPTY_PATH : 0;
dfd = (args->dfd == LINUX_AT_FDCWD) ? AT_FDCWD : args->dfd;
- if (!LUSECONVPATH(td)) {
- error = linux_kern_statat(td, flag, dfd, args->pathname,
- UIO_USERSPACE, &buf);
- } else {
- LCONVPATHEXIST_AT(args->pathname, &path, dfd);
- error = linux_kern_statat(td, flag, dfd, path, UIO_SYSSPACE, &buf);
- LFREEPATH(path);
- }
+ error = linux_kern_statat(td, flags, dfd, args->pathname,
+ UIO_USERSPACE, &buf);
if (error == 0)
error = stat64_copyout(&buf, args->statbuf);
@@ -696,30 +608,17 @@ linux_fstatat64(struct thread *td, struct linux_fstatat64_args *args)
int
linux_newfstatat(struct thread *td, struct linux_newfstatat_args *args)
{
- char *path;
- int error, dfd, flag, unsupported;
+ int error, dfd, flags;
struct stat buf;
- unsupported = args->flag & ~(LINUX_AT_SYMLINK_NOFOLLOW | LINUX_AT_EMPTY_PATH);
- if (unsupported != 0) {
- linux_msg(td, "fstatat unsupported flag 0x%x", unsupported);
+ if (!linux_to_bsd_stat_flags(args->flag, &flags)) {
+ linux_msg(td, "fstatat unsupported flags 0x%x", flags);
return (EINVAL);
}
- flag = (args->flag & LINUX_AT_SYMLINK_NOFOLLOW) ?
- AT_SYMLINK_NOFOLLOW : 0;
- flag |= (args->flag & LINUX_AT_EMPTY_PATH) ?
- AT_EMPTY_PATH : 0;
-
dfd = (args->dfd == LINUX_AT_FDCWD) ? AT_FDCWD : args->dfd;
- if (!LUSECONVPATH(td)) {
- error = linux_kern_statat(td, flag, dfd, args->pathname,
- UIO_USERSPACE, &buf);
- } else {
- LCONVPATHEXIST_AT(args->pathname, &path, dfd);
- error = linux_kern_statat(td, flag, dfd, path, UIO_SYSSPACE, &buf);
- LFREEPATH(path);
- }
+ error = linux_kern_statat(td, flags, dfd, args->pathname,
+ UIO_USERSPACE, &buf);
if (error == 0)
error = newstat_copyout(&buf, args->statbuf);
@@ -767,36 +666,55 @@ linux_syncfs(struct thread *td, struct linux_syncfs_args *args)
return (error);
}
+static int
+statx_copyout(struct stat *buf, void *ubuf)
+{
+ struct l_statx tbuf;
+
+ bzero(&tbuf, sizeof(tbuf));
+ tbuf.stx_mask = STATX_ALL;
+ tbuf.stx_blksize = buf->st_blksize;
+ tbuf.stx_attributes = 0;
+ tbuf.stx_nlink = buf->st_nlink;
+ tbuf.stx_uid = buf->st_uid;
+ tbuf.stx_gid = buf->st_gid;
+ tbuf.stx_mode = buf->st_mode;
+ tbuf.stx_ino = buf->st_ino;
+ tbuf.stx_size = buf->st_size;
+ tbuf.stx_blocks = buf->st_blocks;
+
+ tbuf.stx_atime.tv_sec = buf->st_atim.tv_sec;
+ tbuf.stx_atime.tv_nsec = buf->st_atim.tv_nsec;
+ tbuf.stx_btime.tv_sec = buf->st_birthtim.tv_sec;
+ tbuf.stx_btime.tv_nsec = buf->st_birthtim.tv_nsec;
+ tbuf.stx_ctime.tv_sec = buf->st_ctim.tv_sec;
+ tbuf.stx_ctime.tv_nsec = buf->st_ctim.tv_nsec;
+ tbuf.stx_mtime.tv_sec = buf->st_mtim.tv_sec;
+ tbuf.stx_mtime.tv_nsec = buf->st_mtim.tv_nsec;
+ tbuf.stx_rdev_major = linux_encode_major(buf->st_rdev);
+ tbuf.stx_rdev_minor = linux_encode_minor(buf->st_rdev);
+ tbuf.stx_dev_major = linux_encode_major(buf->st_dev);
+ tbuf.stx_dev_minor = linux_encode_minor(buf->st_dev);
+
+ return (copyout(&tbuf, ubuf, sizeof(tbuf)));
+}
+
int
linux_statx(struct thread *td, struct linux_statx_args *args)
{
- char *path;
- int error, dirfd, flags, unsupported;
+ int error, dirfd, flags;
struct stat buf;
- unsupported = args->flags & ~(LINUX_AT_SYMLINK_NOFOLLOW | LINUX_AT_EMPTY_PATH);
- if (unsupported != 0) {
- linux_msg(td, "statx unsupported flags 0x%x", unsupported);
+ if (!linux_to_bsd_stat_flags(args->flags, &flags)) {
+ linux_msg(td, "statx unsupported flags 0x%x", flags);
return (EINVAL);
}
- flags = (args->flags & LINUX_AT_SYMLINK_NOFOLLOW) ?
- AT_SYMLINK_NOFOLLOW : 0;
- flags |= (args->flags & LINUX_AT_EMPTY_PATH) ?
- AT_EMPTY_PATH : 0;
-
dirfd = (args->dirfd == LINUX_AT_FDCWD) ? AT_FDCWD : args->dirfd;
- if (!LUSECONVPATH(td)) {
- error = linux_kern_statat(td, flags, dirfd, args->pathname,
- UIO_USERSPACE, &buf);
- } else {
- LCONVPATHEXIST_AT(args->pathname, &path, dirfd);
- error = linux_kern_statat(td, flags, dirfd, path, UIO_SYSSPACE, &buf);
- LFREEPATH(path);
- }
+ error = linux_kern_statat(td, flags, dirfd, args->pathname,
+ UIO_USERSPACE, &buf);
if (error == 0)
error = statx_copyout(&buf, args->statxbuf);
return (error);
}
-
diff --git a/sys/compat/linux/linux_sysctl.c b/sys/compat/linux/linux_sysctl.c
index e722280a2bbf..97341c051af7 100644
--- a/sys/compat/linux/linux_sysctl.c
+++ b/sys/compat/linux/linux_sysctl.c
@@ -1,5 +1,5 @@
/*-
- * SPDX-License-Identifier: BSD-2-Clause-FreeBSD
+ * SPDX-License-Identifier: BSD-2-Clause
*
* Copyright (c) 2001 Marcel Moolenaar
* All rights reserved.
@@ -26,21 +26,13 @@
* SUCH DAMAGE.
*/
-#include <sys/cdefs.h>
-__FBSDID("$FreeBSD$");
-
-#include "opt_compat.h"
-
#include <sys/param.h>
-#include <sys/kernel.h>
#include <sys/lock.h>
#include <sys/malloc.h>
#include <sys/mutex.h>
-#include <sys/proc.h>
-#include <sys/sdt.h>
#include <sys/sysctl.h>
-#include <sys/systm.h>
#include <sys/sbuf.h>
+#include <sys/vnode.h>
#ifdef COMPAT_LINUX32
#include <machine/../linux32/linux.h>
@@ -82,7 +74,7 @@ LIN_SDT_PROBE_DEFINE1(sysctl, linux_sysctl, unsupported_sysctl, "char *");
#ifdef LINUX_LEGACY_SYSCALLS
static int
-handle_string(struct l___sysctl_args *la, char *value)
+handle_string(struct l___sysctl_args *la, const char *value)
{
int error;
@@ -163,7 +155,7 @@ linux_sysctl(struct thread *td, struct linux_sysctl_args *args)
sbuf_printf(sb, "} is not implemented");
sbuf_finish(sb);
sysctl_string = sbuf_data(sb);
- linux_msg(td, "%s", sbuf_data(sb));
+ linux_msg(td, "%s", sysctl_string);
LIN_SDT_PROBE1(sysctl, linux_sysctl, unsupported_sysctl,
sysctl_string);
sbuf_delete(sb);
diff --git a/sys/compat/linux/linux_time.c b/sys/compat/linux/linux_time.c
index c1644b5de939..f4dd26dd3d2a 100644
--- a/sys/compat/linux/linux_time.c
+++ b/sys/compat/linux/linux_time.c
@@ -1,7 +1,7 @@
/* $NetBSD: linux_time.c,v 1.14 2006/05/14 03:40:54 christos Exp $ */
/*-
- * SPDX-License-Identifier: BSD-2-Clause-NetBSD
+ * SPDX-License-Identifier: BSD-2-Clause
*
* Copyright (c) 2001 The NetBSD Foundation, Inc.
* All rights reserved.
@@ -32,29 +32,18 @@
*/
#include <sys/cdefs.h>
-__FBSDID("$FreeBSD$");
#if 0
__KERNEL_RCSID(0, "$NetBSD: linux_time.c,v 1.14 2006/05/14 03:40:54 christos Exp $");
#endif
-#include "opt_compat.h"
-
#include <sys/param.h>
-#include <sys/kernel.h>
-#include <sys/lock.h>
-#include <sys/ucred.h>
#include <sys/limits.h>
-#include <sys/mount.h>
+#include <sys/lock.h>
#include <sys/mutex.h>
+#include <sys/proc.h>
#include <sys/resourcevar.h>
-#include <sys/sdt.h>
-#include <sys/signal.h>
-#include <sys/stdint.h>
#include <sys/syscallsubr.h>
-#include <sys/sysproto.h>
#include <sys/time.h>
-#include <sys/systm.h>
-#include <sys/proc.h>
#ifdef COMPAT_LINUX32
#include <machine/../linux32/linux.h>
@@ -66,7 +55,7 @@ __KERNEL_RCSID(0, "$NetBSD: linux_time.c,v 1.14 2006/05/14 03:40:54 christos Exp
#include <compat/linux/linux_dtrace.h>
#include <compat/linux/linux_misc.h>
-#include <compat/linux/linux_timer.h>
+#include <compat/linux/linux_time.h>
#include <compat/linux/linux_util.h>
/* DTrace init */
@@ -101,16 +90,13 @@ LIN_SDT_PROBE_DEFINE1(time, linux_clock_getres, copyout_error, "int");
#if defined(__i386__) || (defined(__amd64__) && defined(COMPAT_LINUX32))
LIN_SDT_PROBE_DEFINE1(time, linux_clock_getres_time64, copyout_error, "int");
#endif
-LIN_SDT_PROBE_DEFINE1(time, linux_nanosleep, conversion_error, "int");
LIN_SDT_PROBE_DEFINE1(time, linux_nanosleep, copyout_error, "int");
LIN_SDT_PROBE_DEFINE1(time, linux_nanosleep, copyin_error, "int");
-LIN_SDT_PROBE_DEFINE1(time, linux_clock_nanosleep, conversion_error, "int");
LIN_SDT_PROBE_DEFINE1(time, linux_clock_nanosleep, copyout_error, "int");
LIN_SDT_PROBE_DEFINE1(time, linux_clock_nanosleep, copyin_error, "int");
LIN_SDT_PROBE_DEFINE1(time, linux_common_clock_nanosleep, unsupported_flags, "int");
LIN_SDT_PROBE_DEFINE1(time, linux_common_clock_nanosleep, unsupported_clockid, "int");
#if defined(__i386__) || (defined(__amd64__) && defined(COMPAT_LINUX32))
-LIN_SDT_PROBE_DEFINE1(time, linux_clock_nanosleep_time64, conversion_error, "int");
LIN_SDT_PROBE_DEFINE1(time, linux_clock_nanosleep_time64, copyout_error, "int");
LIN_SDT_PROBE_DEFINE1(time, linux_clock_nanosleep_time64, copyin_error, "int");
#endif
@@ -142,7 +128,7 @@ int
linux_to_native_timespec(struct timespec *ntp, struct l_timespec *ltp)
{
- if (ltp->tv_sec < 0 || ltp->tv_nsec < 0 || ltp->tv_nsec > 999999999)
+ if (!timespecvalid_interval(ltp))
return (EINVAL);
ntp->tv_sec = ltp->tv_sec;
ntp->tv_nsec = ltp->tv_nsec;
@@ -150,6 +136,30 @@ linux_to_native_timespec(struct timespec *ntp, struct l_timespec *ltp)
return (0);
}
+int
+linux_put_timespec(struct timespec *ntp, struct l_timespec *ltp)
+{
+ struct l_timespec lts;
+ int error;
+
+ error = native_to_linux_timespec(&lts, ntp);
+ if (error != 0)
+ return (error);
+ return (copyout(&lts, ltp, sizeof(lts)));
+}
+
+int
+linux_get_timespec(struct timespec *ntp, const struct l_timespec *ultp)
+{
+ struct l_timespec lts;
+ int error;
+
+ error = copyin(ultp, &lts, sizeof(lts));
+ if (error != 0)
+ return (error);
+ return (linux_to_native_timespec(ntp, &lts));
+}
+
#if defined(__i386__) || (defined(__amd64__) && defined(COMPAT_LINUX32))
int
native_to_linux_timespec64(struct l_timespec64 *ltp64, struct timespec *ntp)
@@ -165,13 +175,44 @@ int
linux_to_native_timespec64(struct timespec *ntp, struct l_timespec64 *ltp64)
{
- if (ltp64->tv_sec < 0 || ltp64->tv_nsec < 0 || ltp64->tv_nsec > 999999999)
- return (EINVAL);
+#if defined(__i386__)
+ /* i386 time_t is still 32-bit */
+ if (ltp64->tv_sec > INT_MAX || ltp64->tv_sec < INT_MIN)
+ return (EOVERFLOW);
+#endif
+ /* Zero out the padding in compat mode. */
+ ntp->tv_nsec = ltp64->tv_nsec & 0xFFFFFFFFUL;
ntp->tv_sec = ltp64->tv_sec;
- ntp->tv_nsec = ltp64->tv_nsec;
+
+ if (!timespecvalid_interval(ntp))
+ return (EINVAL);
return (0);
}
+
+int
+linux_put_timespec64(struct timespec *ntp, struct l_timespec64 *ltp)
+{
+ struct l_timespec64 lts;
+ int error;
+
+ error = native_to_linux_timespec64(&lts, ntp);
+ if (error != 0)
+ return (error);
+ return (copyout(&lts, ltp, sizeof(lts)));
+}
+
+int
+linux_get_timespec64(struct timespec *ntp, const struct l_timespec64 *ultp)
+{
+ struct l_timespec64 lts;
+ int error;
+
+ error = copyin(ultp, &lts, sizeof(lts));
+ if (error != 0)
+ return (error);
+ return (linux_to_native_timespec64(ntp, &lts));
+}
#endif
int
@@ -181,7 +222,7 @@ native_to_linux_itimerspec(struct l_itimerspec *ltp, struct itimerspec *ntp)
error = native_to_linux_timespec(&ltp->it_interval, &ntp->it_interval);
if (error == 0)
- error = native_to_linux_timespec(&ltp->it_value, &ntp->it_interval);
+ error = native_to_linux_timespec(&ltp->it_value, &ntp->it_value);
return (error);
}
@@ -196,15 +237,42 @@ linux_to_native_itimerspec(struct itimerspec *ntp, struct l_itimerspec *ltp)
return (error);
}
+#if defined(__i386__) || (defined(__amd64__) && defined(COMPAT_LINUX32))
+int
+linux_to_native_itimerspec64(struct itimerspec *ntp, struct l_itimerspec64 *ltp)
+{
+ int error;
+
+ error = linux_to_native_timespec64(&ntp->it_interval, &ltp->it_interval);
+ if (error == 0)
+ error = linux_to_native_timespec64(&ntp->it_value, &ltp->it_value);
+ return (error);
+}
+
+int
+native_to_linux_itimerspec64(struct l_itimerspec64 *ltp, struct itimerspec *ntp)
+{
+ int error;
+
+ error = native_to_linux_timespec64(&ltp->it_interval, &ntp->it_interval);
+ if (error == 0)
+ error = native_to_linux_timespec64(&ltp->it_value, &ntp->it_value);
+ return (error);
+}
+#endif
+
int
linux_to_native_clockid(clockid_t *n, clockid_t l)
{
if (l < 0) {
/* cpu-clock */
- if ((l & LINUX_CLOCKFD_MASK) == LINUX_CLOCKFD)
- return (EINVAL);
- if (LINUX_CPUCLOCK_WHICH(l) >= LINUX_CPUCLOCK_MAX)
+ if (LINUX_CPUCLOCK_WHICH(l) == LINUX_CLOCKFD) {
+ LIN_SDT_PROBE1(time, linux_to_native_clockid,
+ unsupported_clockid, l);
+ return (ENOTSUP);
+ }
+ if ((l & LINUX_CLOCKFD_MASK) == LINUX_CLOCKFD_MASK)
return (EINVAL);
if (LINUX_CPUCLOCK_PERTHREAD(l))
@@ -219,7 +287,7 @@ linux_to_native_clockid(clockid_t *n, clockid_t l)
*n = CLOCK_REALTIME;
break;
case LINUX_CLOCK_MONOTONIC:
- *n = CLOCK_MONOTONIC;
+ *n = CLOCK_UPTIME;
break;
case LINUX_CLOCK_PROCESS_CPUTIME_ID:
*n = CLOCK_PROCESS_CPUTIME_ID;
@@ -232,10 +300,10 @@ linux_to_native_clockid(clockid_t *n, clockid_t l)
break;
case LINUX_CLOCK_MONOTONIC_COARSE:
case LINUX_CLOCK_MONOTONIC_RAW:
- *n = CLOCK_MONOTONIC_FAST;
+ *n = CLOCK_UPTIME_FAST;
break;
case LINUX_CLOCK_BOOTTIME:
- *n = CLOCK_UPTIME;
+ *n = CLOCK_MONOTONIC;
break;
case LINUX_CLOCK_REALTIME_ALARM:
case LINUX_CLOCK_BOOTTIME_ALARM:
@@ -243,11 +311,11 @@ linux_to_native_clockid(clockid_t *n, clockid_t l)
case LINUX_CLOCK_TAI:
LIN_SDT_PROBE1(time, linux_to_native_clockid,
unsupported_clockid, l);
- return (EINVAL);
+ return (ENOTSUP);
default:
LIN_SDT_PROBE1(time, linux_to_native_clockid,
unknown_clockid, l);
- return (EINVAL);
+ return (ENOTSUP);
}
return (0);
@@ -390,7 +458,6 @@ linux_common_clock_gettime(struct thread *td, clockid_t which,
int
linux_clock_gettime(struct thread *td, struct linux_clock_gettime_args *args)
{
- struct l_timespec lts;
struct timespec tp;
int error;
@@ -399,10 +466,7 @@ linux_clock_gettime(struct thread *td, struct linux_clock_gettime_args *args)
LIN_SDT_PROBE1(time, linux_clock_gettime, gettime_error, error);
return (error);
}
- error = native_to_linux_timespec(&lts, &tp);
- if (error != 0)
- return (error);
- error = copyout(&lts, args->tp, sizeof(lts));
+ error = linux_put_timespec(&tp, args->tp);
if (error != 0)
LIN_SDT_PROBE1(time, linux_clock_gettime, copyout_error, error);
@@ -413,7 +477,6 @@ linux_clock_gettime(struct thread *td, struct linux_clock_gettime_args *args)
int
linux_clock_gettime64(struct thread *td, struct linux_clock_gettime64_args *args)
{
- struct l_timespec64 lts;
struct timespec tp;
int error;
@@ -422,10 +485,7 @@ linux_clock_gettime64(struct thread *td, struct linux_clock_gettime64_args *args
LIN_SDT_PROBE1(time, linux_clock_gettime64, gettime_error, error);
return (error);
}
- error = native_to_linux_timespec64(&lts, &tp);
- if (error != 0)
- return (error);
- error = copyout(&lts, args->tp, sizeof(lts));
+ error = linux_put_timespec64(&tp, args->tp);
if (error != 0)
LIN_SDT_PROBE1(time, linux_clock_gettime64, copyout_error, error);
@@ -461,19 +521,13 @@ int
linux_clock_settime(struct thread *td, struct linux_clock_settime_args *args)
{
struct timespec ts;
- struct l_timespec lts;
int error;
- error = copyin(args->tp, &lts, sizeof(lts));
+ error = linux_get_timespec(&ts, args->tp);
if (error != 0) {
LIN_SDT_PROBE1(time, linux_clock_settime, copyin_error, error);
return (error);
}
- error = linux_to_native_timespec(&ts, &lts);
- if (error != 0)
- LIN_SDT_PROBE1(time, linux_clock_settime, conversion_error,
- error);
-
return (linux_common_clock_settime(td, args->which, &ts));
}
@@ -482,18 +536,13 @@ int
linux_clock_settime64(struct thread *td, struct linux_clock_settime64_args *args)
{
struct timespec ts;
- struct l_timespec64 lts;
int error;
- error = copyin(args->tp, &lts, sizeof(lts));
+ error = linux_get_timespec64(&ts, args->tp);
if (error != 0) {
LIN_SDT_PROBE1(time, linux_clock_settime64, copyin_error, error);
return (error);
}
- error = linux_to_native_timespec64(&ts, &lts);
- if (error != 0)
- LIN_SDT_PROBE1(time, linux_clock_settime64, conversion_error,
- error);
return (linux_common_clock_settime(td, args->which, &ts));
}
#endif
@@ -598,17 +647,12 @@ linux_clock_getres(struct thread *td,
struct linux_clock_getres_args *args)
{
struct timespec ts;
- struct l_timespec lts;
int error;
error = linux_common_clock_getres(td, args->which, &ts);
if (error != 0 || args->tp == NULL)
return (error);
-
- error = native_to_linux_timespec(&lts, &ts);
- if (error != 0)
- return (error);
- error = copyout(&lts, args->tp, sizeof(lts));
+ error = linux_put_timespec(&ts, args->tp);
if (error != 0)
LIN_SDT_PROBE1(time, linux_clock_getres,
copyout_error, error);
@@ -621,17 +665,12 @@ linux_clock_getres_time64(struct thread *td,
struct linux_clock_getres_time64_args *args)
{
struct timespec ts;
- struct l_timespec64 lts;
int error;
error = linux_common_clock_getres(td, args->which, &ts);
if (error != 0 || args->tp == NULL)
return (error);
-
- error = native_to_linux_timespec64(&lts, &ts);
- if (error != 0)
- return (error);
- error = copyout(&lts, args->tp, sizeof(lts));
+ error = linux_put_timespec64(&ts, args->tp);
if (error != 0)
LIN_SDT_PROBE1(time, linux_clock_getres_time64,
copyout_error, error);
@@ -643,32 +682,22 @@ int
linux_nanosleep(struct thread *td, struct linux_nanosleep_args *args)
{
struct timespec *rmtp;
- struct l_timespec lrqts, lrmts;
struct timespec rqts, rmts;
int error, error2;
- error = copyin(args->rqtp, &lrqts, sizeof lrqts);
+ error = linux_get_timespec(&rqts, args->rqtp);
if (error != 0) {
LIN_SDT_PROBE1(time, linux_nanosleep, copyin_error, error);
return (error);
}
-
if (args->rmtp != NULL)
rmtp = &rmts;
else
rmtp = NULL;
- error = linux_to_native_timespec(&rqts, &lrqts);
- if (error != 0) {
- LIN_SDT_PROBE1(time, linux_nanosleep, conversion_error, error);
- return (error);
- }
error = kern_nanosleep(td, &rqts, rmtp);
if (error == EINTR && args->rmtp != NULL) {
- error2 = native_to_linux_timespec(&lrmts, rmtp);
- if (error2 != 0)
- return (error2);
- error2 = copyout(&lrmts, args->rmtp, sizeof(lrmts));
+ error2 = linux_put_timespec(rmtp, args->rmtp);
if (error2 != 0) {
LIN_SDT_PROBE1(time, linux_nanosleep, copyout_error,
error2);
@@ -712,24 +741,15 @@ linux_clock_nanosleep(struct thread *td,
struct linux_clock_nanosleep_args *args)
{
struct timespec *rmtp;
- struct l_timespec lrqts, lrmts;
struct timespec rqts, rmts;
int error, error2;
- error = copyin(args->rqtp, &lrqts, sizeof(lrqts));
+ error = linux_get_timespec(&rqts, args->rqtp);
if (error != 0) {
LIN_SDT_PROBE1(time, linux_clock_nanosleep, copyin_error,
error);
return (error);
}
-
- error = linux_to_native_timespec(&rqts, &lrqts);
- if (error != 0) {
- LIN_SDT_PROBE1(time, linux_clock_nanosleep, conversion_error,
- error);
- return (error);
- }
-
if (args->rmtp != NULL)
rmtp = &rmts;
else
@@ -739,10 +759,7 @@ linux_clock_nanosleep(struct thread *td,
&rqts, rmtp);
if (error == EINTR && (args->flags & LINUX_TIMER_ABSTIME) == 0 &&
args->rmtp != NULL) {
- error2 = native_to_linux_timespec(&lrmts, rmtp);
- if (error2 != 0)
- return (error2);
- error2 = copyout(&lrmts, args->rmtp, sizeof(lrmts));
+ error2 = linux_put_timespec(rmtp, args->rmtp);
if (error2 != 0) {
LIN_SDT_PROBE1(time, linux_clock_nanosleep,
copyout_error, error2);
@@ -758,24 +775,15 @@ linux_clock_nanosleep_time64(struct thread *td,
struct linux_clock_nanosleep_time64_args *args)
{
struct timespec *rmtp;
- struct l_timespec64 lrqts, lrmts;
struct timespec rqts, rmts;
int error, error2;
- error = copyin(args->rqtp, &lrqts, sizeof(lrqts));
+ error = linux_get_timespec64(&rqts, args->rqtp);
if (error != 0) {
LIN_SDT_PROBE1(time, linux_clock_nanosleep_time64,
copyin_error, error);
return (error);
}
-
- error = linux_to_native_timespec64(&rqts, &lrqts);
- if (error != 0) {
- LIN_SDT_PROBE1(time, linux_clock_nanosleep_time64,
- conversion_error, error);
- return (error);
- }
-
if (args->rmtp != NULL)
rmtp = &rmts;
else
@@ -785,10 +793,7 @@ linux_clock_nanosleep_time64(struct thread *td,
&rqts, rmtp);
if (error == EINTR && (args->flags & LINUX_TIMER_ABSTIME) == 0 &&
args->rmtp != NULL) {
- error2 = native_to_linux_timespec64(&lrmts, rmtp);
- if (error2 != 0)
- return (error2);
- error2 = copyout(&lrmts, args->rmtp, sizeof(lrmts));
+ error2 = linux_put_timespec64(rmtp, args->rmtp);
if (error2 != 0) {
LIN_SDT_PROBE1(time, linux_clock_nanosleep_time64,
copyout_error, error2);
diff --git a/sys/compat/linux/linux_timer.h b/sys/compat/linux/linux_time.h
index 6b5cf346049e..bb23105f4f23 100644
--- a/sys/compat/linux/linux_timer.h
+++ b/sys/compat/linux/linux_time.h
@@ -26,14 +26,10 @@
* 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.
- *
- * $FreeBSD$
*/
-#ifndef _LINUX_TIMER_H
-#define _LINUX_TIMER_H
-
-#include <sys/abi_compat.h>
+#ifndef _LINUX_TIME_H
+#define _LINUX_TIME_H
#ifndef __LINUX_ARCH_SIGEV_PREAMBLE_SIZE
#define __LINUX_ARCH_SIGEV_PREAMBLE_SIZE \
@@ -104,21 +100,44 @@ struct l_itimerspec {
struct l_timespec it_value;
};
+#if defined(__i386__) || (defined(__amd64__) && defined(COMPAT_LINUX32))
+struct l_itimerspec64 {
+ struct l_timespec64 it_interval;
+ struct l_timespec64 it_value;
+};
+#endif
+
int native_to_linux_timespec(struct l_timespec *,
struct timespec *);
int linux_to_native_timespec(struct timespec *,
struct l_timespec *);
+int linux_put_timespec(struct timespec *,
+ struct l_timespec *);
+int linux_get_timespec(struct timespec *,
+ const struct l_timespec *);
#if defined(__i386__) || (defined(__amd64__) && defined(COMPAT_LINUX32))
int native_to_linux_timespec64(struct l_timespec64 *,
struct timespec *);
int linux_to_native_timespec64(struct timespec *,
struct l_timespec64 *);
+int linux_put_timespec64(struct timespec *,
+ struct l_timespec64 *);
+int linux_get_timespec64(struct timespec *,
+ const struct l_timespec64 *);
#endif
int linux_to_native_clockid(clockid_t *, clockid_t);
int native_to_linux_itimerspec(struct l_itimerspec *,
struct itimerspec *);
int linux_to_native_itimerspec(struct itimerspec *,
struct l_itimerspec *);
+#if defined(__i386__) || (defined(__amd64__) && defined(COMPAT_LINUX32))
+int native_to_linux_itimerspec64(struct l_itimerspec64 *,
+ struct itimerspec *);
+int linux_to_native_itimerspec64(struct itimerspec *,
+ struct l_itimerspec64 *);
+#endif
+
+int linux_convert_l_sigevent(const struct l_sigevent *l_sig, struct sigevent *sig);
int linux_to_native_timerflags(int *, int);
-#endif /* _LINUX_TIMER_H */
+#endif /* _LINUX_TIME_H */
diff --git a/sys/compat/linux/linux_timer.c b/sys/compat/linux/linux_timer.c
index 4e1b56d4b2e2..ed9133359302 100644
--- a/sys/compat/linux/linux_timer.c
+++ b/sys/compat/linux/linux_timer.c
@@ -27,18 +27,12 @@
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*/
-#include <sys/cdefs.h>
-__FBSDID("$FreeBSD$");
-
-#include "opt_compat.h"
#include <sys/param.h>
-#include <sys/errno.h>
+#include <sys/proc.h>
#include <sys/signal.h>
#include <sys/syscallsubr.h>
-#include <sys/systm.h>
#include <sys/time.h>
-#include <sys/types.h>
#ifdef COMPAT_LINUX32
#include <machine/../linux32/linux.h>
@@ -47,10 +41,10 @@ __FBSDID("$FreeBSD$");
#include <machine/../linux/linux.h>
#include <machine/../linux/linux_proto.h>
#endif
-#include <compat/linux/linux_timer.h>
+#include <compat/linux/linux_time.h>
-static int
-linux_convert_l_sigevent(struct l_sigevent *l_sig, struct sigevent *sig)
+int
+linux_convert_l_sigevent(const struct l_sigevent *l_sig, struct sigevent *sig)
{
CP(*l_sig, *sig, sigev_notify);
@@ -123,20 +117,54 @@ linux_timer_settime(struct thread *td, struct linux_timer_settime_args *uap)
{
struct l_itimerspec l_val, l_oval;
struct itimerspec val, oval, *ovalp;
- int error;
+ int flags, error;
+
+ error = copyin(uap->new, &l_val, sizeof(l_val));
+ if (error != 0)
+ return (error);
+ error = linux_to_native_itimerspec(&val, &l_val);
+ if (error != 0)
+ return (error);
+ ovalp = uap->old != NULL ? &oval : NULL;
+ error = linux_to_native_timerflags(&flags, uap->flags);
+ if (error != 0)
+ return (error);
+ error = kern_ktimer_settime(td, uap->timerid, flags, &val, ovalp);
+ if (error == 0 && uap->old != NULL) {
+ error = native_to_linux_itimerspec(&l_val, &val);
+ if (error == 0)
+ error = copyout(&l_oval, uap->old, sizeof(l_oval));
+ }
+ return (error);
+}
+
+#if defined(__i386__) || (defined(__amd64__) && defined(COMPAT_LINUX32))
+int
+linux_timer_settime64(struct thread *td, struct linux_timer_settime64_args *uap)
+{
+ struct l_itimerspec64 l_val, l_oval;
+ struct itimerspec val, oval, *ovalp;
+ int flags, error;
error = copyin(uap->new, &l_val, sizeof(l_val));
if (error != 0)
return (error);
- ITS_CP(l_val, val);
+ error = linux_to_native_itimerspec64(&val, &l_val);
+ if (error != 0)
+ return (error);
ovalp = uap->old != NULL ? &oval : NULL;
- error = kern_ktimer_settime(td, uap->timerid, uap->flags, &val, ovalp);
+ error = linux_to_native_timerflags(&flags, uap->flags);
+ if (error != 0)
+ return (error);
+ error = kern_ktimer_settime(td, uap->timerid, flags, &val, ovalp);
if (error == 0 && uap->old != NULL) {
- ITS_CP(oval, l_oval);
- error = copyout(&l_oval, uap->old, sizeof(l_oval));
+ error = native_to_linux_itimerspec64(&l_val, &val);
+ if (error == 0)
+ error = copyout(&l_oval, uap->old, sizeof(l_oval));
}
return (error);
}
+#endif
int
linux_timer_gettime(struct thread *td, struct linux_timer_gettime_args *uap)
@@ -146,13 +174,30 @@ linux_timer_gettime(struct thread *td, struct linux_timer_gettime_args *uap)
int error;
error = kern_ktimer_gettime(td, uap->timerid, &val);
- if (error == 0) {
- ITS_CP(val, l_val);
+ if (error == 0)
+ error = native_to_linux_itimerspec(&l_val, &val);
+ if (error == 0)
error = copyout(&l_val, uap->setting, sizeof(l_val));
- }
return (error);
}
+#if defined(__i386__) || (defined(__amd64__) && defined(COMPAT_LINUX32))
+int
+linux_timer_gettime64(struct thread *td, struct linux_timer_gettime64_args *uap)
+{
+ struct l_itimerspec64 l_val;
+ struct itimerspec val;
+ int error;
+
+ error = kern_ktimer_gettime(td, uap->timerid, &val);
+ if (error == 0)
+ error = native_to_linux_itimerspec64(&l_val, &val);
+ if (error == 0)
+ error = copyout(&l_val, uap->setting, sizeof(l_val));
+ return (error);
+}
+#endif
+
int
linux_timer_getoverrun(struct thread *td, struct linux_timer_getoverrun_args *uap)
{
diff --git a/sys/compat/linux/linux_uid16.c b/sys/compat/linux/linux_uid16.c
index 4dd4129cfa0b..8ac093e004d0 100644
--- a/sys/compat/linux/linux_uid16.c
+++ b/sys/compat/linux/linux_uid16.c
@@ -1,5 +1,5 @@
/*-
- * SPDX-License-Identifier: BSD-2-Clause-FreeBSD
+ * SPDX-License-Identifier: BSD-2-Clause
*
* Copyright (c) 2001 The FreeBSD Project
* All rights reserved.
@@ -26,23 +26,15 @@
* SUCH DAMAGE.
*/
-#include <sys/cdefs.h>
-__FBSDID("$FreeBSD$");
-
-#include "opt_compat.h"
-
-#include <sys/fcntl.h>
#include <sys/param.h>
-#include <sys/kernel.h>
+#include <sys/fcntl.h>
#include <sys/lock.h>
#include <sys/malloc.h>
#include <sys/mutex.h>
#include <sys/priv.h>
#include <sys/proc.h>
-#include <sys/sdt.h>
#include <sys/syscallsubr.h>
#include <sys/sysproto.h>
-#include <sys/systm.h>
#ifdef COMPAT_LINUX32
#include <machine/../linux32/linux.h>
@@ -77,65 +69,29 @@ DUMMY(getresgid16);
int
linux_chown16(struct thread *td, struct linux_chown16_args *args)
{
- char *path;
- int error;
- if (!LUSECONVPATH(td) && !SDT_PROBES_ENABLED()) {
- error = kern_fchownat(td, AT_FDCWD, args->path, UIO_USERSPACE,
- CAST_NOCHG(args->uid), CAST_NOCHG(args->gid), 0);
- } else {
- LCONVPATHEXIST(args->path, &path);
- /*
- * The DTrace probes have to be after the LCONVPATHEXIST, as
- * LCONVPATHEXIST may return on its own and we do not want to
- * have a stray entry without the corresponding return.
- */
- LIN_SDT_PROBE1(uid16, linux_chown16, conv_path, path);
-
- error = kern_fchownat(td, AT_FDCWD, path, UIO_SYSSPACE,
- CAST_NOCHG(args->uid), CAST_NOCHG(args->gid), 0);
- LFREEPATH(path);
- }
- return (error);
+ return (kern_fchownat(td, AT_FDCWD, args->path, UIO_USERSPACE,
+ CAST_NOCHG(args->uid), CAST_NOCHG(args->gid), 0));
}
int
linux_lchown16(struct thread *td, struct linux_lchown16_args *args)
{
- char *path;
- int error;
- if (!LUSECONVPATH(td) && !SDT_PROBES_ENABLED()) {
- error = kern_fchownat(td, AT_FDCWD, args->path, UIO_USERSPACE,
- CAST_NOCHG(args->uid), CAST_NOCHG(args->gid), AT_SYMLINK_NOFOLLOW);
- } else {
- LCONVPATHEXIST(args->path, &path);
-
- /*
- * The DTrace probes have to be after the LCONVPATHEXIST, as
- * LCONVPATHEXIST may return on its own and we do not want to
- * have a stray entry without the corresponding return.
- */
- LIN_SDT_PROBE1(uid16, linux_lchown16, conv_path, path);
-
- error = kern_fchownat(td, AT_FDCWD, path, UIO_SYSSPACE,
- CAST_NOCHG(args->uid), CAST_NOCHG(args->gid), AT_SYMLINK_NOFOLLOW);
- LFREEPATH(path);
- }
- return (error);
+ return (kern_fchownat(td, AT_FDCWD, args->path, UIO_USERSPACE,
+ CAST_NOCHG(args->uid), CAST_NOCHG(args->gid), AT_SYMLINK_NOFOLLOW));
}
int
linux_setgroups16(struct thread *td, struct linux_setgroups16_args *args)
{
+ const int ngrp = args->gidsetsize;
struct ucred *newcred, *oldcred;
l_gid16_t *linux_gidset;
- gid_t *bsd_gidset;
- int ngrp, error;
+ int error;
struct proc *p;
- ngrp = args->gidsetsize;
- if (ngrp < 0 || ngrp >= ngroups_max + 1)
+ if (ngrp < 0 || ngrp > ngroups_max)
return (EINVAL);
linux_gidset = malloc(ngrp * sizeof(*linux_gidset), M_LINUX, M_WAITOK);
error = copyin(args->gidset, linux_gidset, ngrp * sizeof(l_gid16_t));
@@ -144,17 +100,13 @@ linux_setgroups16(struct thread *td, struct linux_setgroups16_args *args)
free(linux_gidset, M_LINUX);
return (error);
}
+
newcred = crget();
+ crextend(newcred, ngrp);
p = td->td_proc;
PROC_LOCK(p);
oldcred = crcopysafe(p, newcred);
- /*
- * cr_groups[0] holds egid. Setting the whole set from
- * the supplied set will cause egid to be changed too.
- * Keep cr_groups[0] unchanged to prevent that.
- */
-
if ((error = priv_check_cred(oldcred, PRIV_CRED_SETGROUPS)) != 0) {
PROC_UNLOCK(p);
crfree(newcred);
@@ -164,18 +116,10 @@ linux_setgroups16(struct thread *td, struct linux_setgroups16_args *args)
goto out;
}
- if (ngrp > 0) {
- newcred->cr_ngroups = ngrp + 1;
-
- bsd_gidset = newcred->cr_groups;
- ngrp--;
- while (ngrp >= 0) {
- bsd_gidset[ngrp + 1] = linux_gidset[ngrp];
- ngrp--;
- }
- }
- else
- newcred->cr_ngroups = 1;
+ newcred->cr_ngroups = ngrp;
+ for (int i = 0; i < ngrp; i++)
+ newcred->cr_groups[i] = linux_gidset[i];
+ newcred->cr_flags |= CRED_FLAG_GROUPSET;
setsugid(td->td_proc);
proc_set_cred(p, newcred);
@@ -191,40 +135,29 @@ out:
int
linux_getgroups16(struct thread *td, struct linux_getgroups16_args *args)
{
- struct ucred *cred;
+ const struct ucred *const cred = td->td_ucred;
l_gid16_t *linux_gidset;
- gid_t *bsd_gidset;
- int bsd_gidsetsz, ngrp, error;
-
- cred = td->td_ucred;
- bsd_gidset = cred->cr_groups;
- bsd_gidsetsz = cred->cr_ngroups - 1;
+ int ngrp, error;
- /*
- * cr_groups[0] holds egid. Returning the whole set
- * here will cause a duplicate. Exclude cr_groups[0]
- * to prevent that.
- */
+ ngrp = args->gidsetsize;
- if ((ngrp = args->gidsetsize) == 0) {
- td->td_retval[0] = bsd_gidsetsz;
+ if (ngrp == 0) {
+ td->td_retval[0] = cred->cr_ngroups;
return (0);
}
-
- if (ngrp < bsd_gidsetsz)
+ if (ngrp < cred->cr_ngroups)
return (EINVAL);
- ngrp = 0;
- linux_gidset = malloc(bsd_gidsetsz * sizeof(*linux_gidset),
- M_LINUX, M_WAITOK);
- while (ngrp < bsd_gidsetsz) {
- linux_gidset[ngrp] = bsd_gidset[ngrp + 1];
- ngrp++;
- }
+ ngrp = cred->cr_ngroups;
+
+ linux_gidset = malloc(ngrp * sizeof(*linux_gidset), M_LINUX, M_WAITOK);
+ for (int i = 0; i < ngrp; ++i)
+ linux_gidset[i] = cred->cr_groups[i];
error = copyout(linux_gidset, args->gidset, ngrp * sizeof(l_gid16_t));
free(linux_gidset, M_LINUX);
- if (error) {
+
+ if (error != 0) {
LIN_SDT_PROBE1(uid16, linux_getgroups16, copyout_error, error);
return (error);
}
diff --git a/sys/compat/linux/linux_util.c b/sys/compat/linux/linux_util.c
index 35376db6063d..910800489874 100644
--- a/sys/compat/linux/linux_util.c
+++ b/sys/compat/linux/linux_util.c
@@ -31,27 +31,19 @@
* from: svr4_util.c,v 1.5 1995/01/22 23:44:50 christos Exp
*/
-#include <sys/cdefs.h>
-__FBSDID("$FreeBSD$");
-
#include <sys/param.h>
#include <sys/bus.h>
#include <sys/conf.h>
#include <sys/fcntl.h>
#include <sys/jail.h>
#include <sys/malloc.h>
-#include <sys/kernel.h>
-#include <sys/linker_set.h>
#include <sys/namei.h>
#include <sys/proc.h>
-#include <sys/sdt.h>
+#include <sys/stat.h>
+#include <sys/stdarg.h>
#include <sys/syscallsubr.h>
-#include <sys/sysctl.h>
-#include <sys/systm.h>
#include <sys/vnode.h>
-#include <machine/stdarg.h>
-
#include <compat/linux/linux_dtrace.h>
#include <compat/linux/linux_mib.h>
#include <compat/linux/linux_util.h>
@@ -82,23 +74,30 @@ SYSCTL_STRING(_compat_linux, OID_AUTO, emul_path, CTLFLAG_RWTUN,
linux_emul_path, sizeof(linux_emul_path),
"Linux runtime environment path");
-/*
- * Search an alternate path before passing pathname arguments on to
- * system calls. Useful for keeping a separate 'emulation tree'.
- *
- * If cflag is set, we check if an attempt can be made to create the
- * named file, i.e. we check if the directory it should be in exists.
- */
int
-linux_emul_convpath(const char *path, enum uio_seg pathseg,
- char **pbuf, int cflag, int dfd)
+linux_pwd_onexec(struct thread *td)
{
- int retval;
+ struct nameidata nd;
+ int error;
- retval = kern_alternate_path(linux_emul_path, path, pathseg, pbuf,
- cflag, dfd);
+ NDINIT(&nd, LOOKUP, FOLLOW, UIO_SYSSPACE, linux_emul_path);
+ error = namei(&nd);
+ if (error != 0) {
+ /* Do not prevent execution if altroot is non-existent. */
+ pwd_altroot(td, NULL);
+ return (0);
+ }
+ NDFREE_PNBUF(&nd);
+ pwd_altroot(td, nd.ni_vp);
+ vrele(nd.ni_vp);
+ return (0);
+}
- return (retval);
+void
+linux_pwd_onexec_native(struct thread *td)
+{
+
+ pwd_altroot(td, NULL);
}
void
@@ -230,8 +229,33 @@ linux_vn_get_major_minor(const struct vnode *vp, int *major, int *minor)
return (error);
}
+void
+translate_vnhook_major_minor(struct vnode *vp, struct stat *sb)
+{
+ int major, minor;
+
+ if (vn_isdisk(vp)) {
+ sb->st_mode &= ~S_IFMT;
+ sb->st_mode |= S_IFBLK;
+ }
+
+ /*
+ * Return the same st_dev for every devfs instance. The reason
+ * for this is to work around an idiosyncrasy of glibc getttynam()
+ * implementation: it checks whether st_dev returned for fd 0
+ * is the same as st_dev returned for the target of /proc/self/fd/0
+ * symlink, and with linux chroots having their own devfs instance,
+ * the check will fail if you chroot into it.
+ */
+ if (rootdevmp != NULL && vp->v_mount->mnt_vfc == rootdevmp->mnt_vfc)
+ sb->st_dev = rootdevmp->mnt_stat.f_fsid.val[0];
+
+ if (linux_vn_get_major_minor(vp, &major, &minor) == 0)
+ sb->st_rdev = makedev(major, minor);
+}
+
char *
-linux_get_char_devices()
+linux_get_char_devices(void)
{
struct device_element *de;
char *temp, *string, *last;
diff --git a/sys/compat/linux/linux_util.h b/sys/compat/linux/linux_util.h
index 621b99afbff3..58f7c533d647 100644
--- a/sys/compat/linux/linux_util.h
+++ b/sys/compat/linux/linux_util.h
@@ -30,49 +30,21 @@
*
* from: svr4_util.h,v 1.5 1994/11/18 02:54:31 christos Exp
* from: linux_util.h,v 1.2 1995/03/05 23:23:50 fvdl Exp
- * $FreeBSD$
*/
#ifndef _LINUX_UTIL_H_
#define _LINUX_UTIL_H_
-#include <vm/vm.h>
-#include <vm/vm_param.h>
-#include <vm/pmap.h>
-#include <sys/exec.h>
-#include <sys/sysent.h>
-#include <sys/syslog.h>
-#include <sys/cdefs.h>
+#include <sys/malloc.h>
#include <sys/uio.h>
+extern int linux_debug;
+
MALLOC_DECLARE(M_LINUX);
MALLOC_DECLARE(M_EPOLL);
-extern char linux_emul_path[];
-extern int linux_use_emul_path;
-
-int linux_emul_convpath(const char *, enum uio_seg, char **, int, int);
-
-#define LUSECONVPATH(td) atomic_load_int(&linux_use_emul_path)
-
-#define LCONVPATH_AT(upath, pathp, i, dfd) \
- do { \
- int _error; \
- \
- _error = linux_emul_convpath(upath, UIO_USERSPACE, \
- pathp, i, dfd); \
- if (*(pathp) == NULL) \
- return (_error); \
- } while (0)
-
-#define LCONVPATH(upath, pathp, i) \
- LCONVPATH_AT(upath, pathp, i, AT_FDCWD)
-
-#define LCONVPATHEXIST(upath, pathp) LCONVPATH(upath, pathp, 0)
-#define LCONVPATHEXIST_AT(upath, pathp, dfd) LCONVPATH_AT(upath, pathp, 0, dfd)
-#define LCONVPATHCREAT(upath, pathp) LCONVPATH(upath, pathp, 1)
-#define LCONVPATHCREAT_AT(upath, pathp, dfd) LCONVPATH_AT(upath, pathp, 1, dfd)
-#define LFREEPATH(path) free(path, M_TEMP)
+int linux_pwd_onexec(struct thread *);
+void linux_pwd_onexec_native(struct thread *);
#define DUMMY(s) \
LIN_SDT_PROBE_DEFINE0(dummy, s, not_implemented); \
@@ -112,6 +84,8 @@ struct linux_device_handler {
int linux_char_device;
};
+struct stat;
+
int linux_device_register_handler(struct linux_device_handler *h);
int linux_device_unregister_handler(struct linux_device_handler *h);
char *linux_driver_get_name_dev(device_t dev);
@@ -119,6 +93,7 @@ int linux_driver_get_major_minor(const char *node, int *major, int *minor);
int linux_vn_get_major_minor(const struct vnode *vn, int *major, int *minor);
char *linux_get_char_devices(void);
void linux_free_get_char_devices(char *string);
+void translate_vnhook_major_minor(struct vnode *vp, struct stat *sb);
#if defined(KTR)
@@ -189,4 +164,16 @@ void linux_free_get_char_devices(char *string);
} \
} while (0)
+#define LINUX_RATELIMIT_MSG_OPT2(_message, _opt1, _opt2) \
+ do { \
+ static int seen = 0; \
+ \
+ if (seen == 0) { \
+ linux_msg(curthread, _message, _opt1, _opt2); \
+ \
+ if (linux_debug < 3) \
+ seen = 1; \
+ } \
+ } while (0)
+
#endif /* ! _LINUX_UTIL_H_ */
diff --git a/sys/compat/linux/linux_vdso.c b/sys/compat/linux/linux_vdso.c
index f5fc7a20b1ef..a415a92783de 100644
--- a/sys/compat/linux/linux_vdso.c
+++ b/sys/compat/linux/linux_vdso.c
@@ -1,33 +1,30 @@
/*-
+ * SPDX-License-Identifier: BSD-2-Clause
+ *
* Copyright (c) 2013-2021 Dmitry Chagin <dchagin@FreeBSD.org>
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer
- * in this position and unchanged.
+ * notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
- * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``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.
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``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 OR CONTRIBUTORS 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.
*/
-#include <sys/cdefs.h>
-__FBSDID("$FreeBSD$");
-
-#include "opt_compat.h"
-
#if defined(__i386__) || (defined(__amd64__) && defined(COMPAT_LINUX32))
#define __ELF_WORD_SIZE 32
#else
@@ -35,22 +32,20 @@ __FBSDID("$FreeBSD$");
#endif
#include <sys/param.h>
-#include <sys/systm.h>
#include <sys/elf.h>
#include <sys/imgact.h>
-#include <sys/kernel.h>
+#include <sys/lock.h>
#include <sys/proc.h>
#include <sys/rwlock.h>
-#include <sys/queue.h>
#include <sys/sysent.h>
-#include <vm/vm_param.h>
#include <vm/pmap.h>
#include <vm/vm_extern.h>
#include <vm/vm_map.h>
#include <vm/vm_object.h>
#include <vm/vm_page.h>
#include <vm/vm_pager.h>
+#include <vm/vm_param.h>
#include <compat/linux/linux_vdso.h>
diff --git a/sys/compat/linux/linux_vdso.h b/sys/compat/linux/linux_vdso.h
index 6708b94f2694..e7f45f38c662 100644
--- a/sys/compat/linux/linux_vdso.h
+++ b/sys/compat/linux/linux_vdso.h
@@ -1,35 +1,33 @@
/*-
+ * SPDX-License-Identifier: BSD-2-Clause
+ *
* Copyright (c) 2013-2021 Dmitry Chagin <dchagin@FreeBSD.org>
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer
- * in this position and unchanged.
+ * notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
- * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``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.
- *
- * $FreeBSD$
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``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 OR CONTRIBUTORS 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.
*/
#ifndef _LINUX_VDSO_H_
#define _LINUX_VDSO_H_
-#include <sys/types.h>
-
struct linux_vdso_sym {
SLIST_ENTRY(linux_vdso_sym) sym;
uint32_t size;
diff --git a/sys/compat/linux/linux_vdso_gtod.inc b/sys/compat/linux/linux_vdso_gtod.inc
index 52fab2bbc5d7..e508f821725d 100644
--- a/sys/compat/linux/linux_vdso_gtod.inc
+++ b/sys/compat/linux/linux_vdso_gtod.inc
@@ -1,5 +1,5 @@
/*-
- * SPDX-License-Identifier: BSD-2-Clause-FreeBSD
+ * SPDX-License-Identifier: BSD-2-Clause
*
* Copyright (c) 2012 Konstantin Belousov <kib@FreeBSD.org>
* Copyright (c) 2021 Dmitry Chagin <dchagin@FreeBSD.org>
@@ -26,6 +26,14 @@
* SUCH DAMAGE.
*/
+#if defined(__aarch64__)
+#define __VDSO_PREFIX __kernel
+#else
+#define __VDSO_PREFIX __vdso
+#endif
+
+#define __vdsoN(x) __CONCAT(__CONCAT(__VDSO_PREFIX,_),x)
+
static int
fls(int mask)
{
@@ -37,25 +45,25 @@ fls(int mask)
#ifdef _LP64
static int
-ffsl(long mask)
+flsl(long mask)
{
int bit;
if (mask == 0)
return (0);
- for (bit = 1; !(mask & 1); bit++)
+ for (bit = 1; mask != 1; bit++)
mask = (unsigned long)mask >> 1;
return (bit);
}
#else
static int
-ffsll(long long mask)
+flsll(long long mask)
{
int bit;
if (mask == 0)
return (0);
- for (bit = 1; !(mask & 1); bit++)
+ for (bit = 1; mask != 1; bit++)
mask = (unsigned long long)mask >> 1;
return (bit);
}
@@ -186,9 +194,9 @@ freebsd_binuptime(struct bintime *bt, struct vdso_timekeep *tk, bool abs)
return (error);
scale = th->th_scale;
#ifdef _LP64
- scale_bits = ffsl(scale);
+ scale_bits = flsl(scale);
#else
- scale_bits = ffsll(scale);
+ scale_bits = flsll(scale);
#endif
if (__predict_false(scale_bits + fls(delta) > 63)) {
x = (scale >> 32) * delta;
@@ -295,7 +303,7 @@ freebsd_clock_gettime(clockid_t clock_id, struct timespec *ts)
*
*/
int
-__vdso_clock_gettime(clockid_t clock_id, struct l_timespec *lts)
+__vdsoN(clock_gettime)(clockid_t clock_id, struct l_timespec *lts)
{
struct timespec ts;
clockid_t which;
@@ -312,7 +320,7 @@ __vdso_clock_gettime(clockid_t clock_id, struct l_timespec *lts)
}
int
-__vdso_gettimeofday(l_timeval *ltv, struct timezone *tz)
+__vdsoN(gettimeofday)(l_timeval *ltv, struct timezone *tz)
{
struct timeval tv;
int error;
@@ -324,7 +332,7 @@ __vdso_gettimeofday(l_timeval *ltv, struct timezone *tz)
}
int
-__vdso_clock_getres(clockid_t clock_id, struct l_timespec *lts)
+__vdsoN(clock_getres)(clockid_t clock_id, struct l_timespec *lts)
{
return (__vdso_clock_getres_fallback(clock_id, lts));
@@ -352,12 +360,19 @@ int clock_gettime64(clockid_t clock_id, struct l_timespec64 *lts)
__attribute__((weak, alias("__vdso_clock_gettime64")));
#endif
-#if defined(__amd64__) && !defined(COMPAT_LINUX32)
+#if defined(__i386__) || defined(__amd64__)
int
__vdso_getcpu(uint32_t *cpu, uint32_t *node, void *cache)
{
-
- return (__vdso_getcpu_fallback(cpu, node, cache));
+ int ret;
+
+ if (node != NULL)
+ return (__vdso_getcpu_fallback(cpu, node, cache));
+ ret = __vdso_getcpu_try();
+ if (ret < 0)
+ return (__vdso_getcpu_fallback(cpu, node, cache));
+ *cpu = ret;
+ return (0);
}
#endif
@@ -365,7 +380,14 @@ __vdso_getcpu(uint32_t *cpu, uint32_t *node, void *cache)
int
__vdso_time(long *tm)
{
+ struct timeval tv;
+ int error;
- return (__vdso_time_fallback(tm));
+ error = freebsd_gettimeofday(&tv, NULL);
+ if (error != 0)
+ return (__vdso_time_fallback(tm));
+ if (tm != NULL)
+ *tm = tv.tv_sec;
+ return (tv.tv_sec);
}
#endif
diff --git a/sys/compat/linux/linux_vdso_inc.S b/sys/compat/linux/linux_vdso_inc.S
new file mode 100644
index 000000000000..44cc357b4a4a
--- /dev/null
+++ b/sys/compat/linux/linux_vdso_inc.S
@@ -0,0 +1,39 @@
+/*-
+ * SPDX-License-Identifier: BSD-2-Clause
+ *
+ * Copyright (C) 2020 Arm Ltd
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``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 OR CONTRIBUTORS 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.
+ */
+
+ .section .data
+ .globl _binary_linux_vdso_so_o_start
+_binary_linux_vdso_so_o_start:
+ .incbin "linux_vdso.so.o"
+ .globl _binary_linux_vdso_so_o_end
+_binary_linux_vdso_so_o_end:
+
+#if defined(__aarch64__)
+#include <sys/elf_common.h>
+#include <machine/asm.h>
+GNU_PROPERTY_AARCH64_FEATURE_1_NOTE(GNU_PROPERTY_AARCH64_FEATURE_1_VAL)
+#endif
diff --git a/sys/compat/linux/linux_videodev2_compat.h b/sys/compat/linux/linux_videodev2_compat.h
index 0d9a3a348b8f..cd7ca5f002e1 100644
--- a/sys/compat/linux/linux_videodev2_compat.h
+++ b/sys/compat/linux/linux_videodev2_compat.h
@@ -1,8 +1,4 @@
/*
- * $FreeBSD$
- */
-
-/*
* This file defines compatibility versions of several video structures
* defined in the Linux videodev2.h header (linux_videodev2.h). The
* structures defined in this file are the ones that have been determined
diff --git a/sys/compat/linux/linux_videodev_compat.h b/sys/compat/linux/linux_videodev_compat.h
index 98034bcbb04d..c35a59d2ecf8 100644
--- a/sys/compat/linux/linux_videodev_compat.h
+++ b/sys/compat/linux/linux_videodev_compat.h
@@ -1,8 +1,4 @@
/*
- * $FreeBSD$
- */
-
-/*
* This file defines compatibility versions of several video structures
* defined in the Linux videodev.h header (linux_videodev.h). The
* structures defined in this file are the ones that have been determined
diff --git a/sys/compat/linux/linux_xattr.c b/sys/compat/linux/linux_xattr.c
new file mode 100644
index 000000000000..2eec33f8ef93
--- /dev/null
+++ b/sys/compat/linux/linux_xattr.c
@@ -0,0 +1,460 @@
+/*-
+ * SPDX-License-Identifier: BSD-2-Clause
+ *
+ * Copyright (c) 2023 Dmitry Chagin <dchagin@FreeBSD.org>
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``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 OR CONTRIBUTORS 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.
+ */
+
+#include <sys/param.h>
+#include <sys/extattr.h>
+#include <sys/fcntl.h>
+#include <sys/namei.h>
+#include <sys/proc.h>
+#include <sys/syscallsubr.h>
+
+#ifdef COMPAT_LINUX32
+#include <machine/../linux32/linux.h>
+#include <machine/../linux32/linux32_proto.h>
+#else
+#include <machine/../linux/linux.h>
+#include <machine/../linux/linux_proto.h>
+#endif
+
+#include <compat/linux/linux_util.h>
+
+#define LINUX_XATTR_SIZE_MAX 65536
+#define LINUX_XATTR_LIST_MAX 65536
+#define LINUX_XATTR_NAME_MAX 255
+
+#define LINUX_XATTR_CREATE 0x1
+#define LINUX_XATTR_REPLACE 0x2
+#define LINUX_XATTR_FLAGS LINUX_XATTR_CREATE|LINUX_XATTR_REPLACE
+
+struct listxattr_args {
+ int fd;
+ const char *path;
+ char *list;
+ l_size_t size;
+ int follow;
+};
+
+struct setxattr_args {
+ int fd;
+ const char *path;
+ const char *name;
+ void *value;
+ l_size_t size;
+ l_int flags;
+ int follow;
+};
+
+struct getxattr_args {
+ int fd;
+ const char *path;
+ const char *name;
+ void *value;
+ l_size_t size;
+ int follow;
+};
+
+struct removexattr_args {
+ int fd;
+ const char *path;
+ const char *name;
+ int follow;
+};
+
+static char *extattr_namespace_names[] = EXTATTR_NAMESPACE_NAMES;
+
+
+static int
+error_to_xattrerror(int attrnamespace, int error)
+{
+
+ if (attrnamespace == EXTATTR_NAMESPACE_SYSTEM && error == EPERM)
+ return (ENOTSUP);
+ else
+ return (error);
+}
+
+static int
+xattr_to_extattr(const char *uattrname, int *attrnamespace, char *attrname)
+{
+ char uname[LINUX_XATTR_NAME_MAX + 1], *dot;
+ size_t len, cplen;
+ int error;
+
+ error = copyinstr(uattrname, uname, sizeof(uname), &cplen);
+ if (error != 0)
+ return (error);
+ if (cplen == sizeof(uname))
+ return (ERANGE);
+ dot = strchr(uname, '.');
+ if (dot == NULL)
+ return (ENOTSUP);
+ *dot = '\0';
+ for (*attrnamespace = EXTATTR_NAMESPACE_USER;
+ *attrnamespace < nitems(extattr_namespace_names);
+ (*attrnamespace)++) {
+ if (bcmp(uname, extattr_namespace_names[*attrnamespace],
+ dot - uname + 1) == 0) {
+ dot++;
+ len = strlen(dot) + 1;
+ bcopy(dot, attrname, len);
+ return (0);
+ }
+ }
+ return (ENOTSUP);
+}
+
+static int
+listxattr(struct thread *td, struct listxattr_args *args)
+{
+ char attrname[LINUX_XATTR_NAME_MAX + 1];
+ char *data, *prefix, *key;
+ struct uio auio;
+ struct iovec aiov;
+ unsigned char keylen;
+ size_t sz, cnt, rs, prefixlen, pairlen;
+ int attrnamespace, error;
+
+ if (args->size != 0)
+ sz = min(LINUX_XATTR_LIST_MAX, args->size);
+ else
+ sz = LINUX_XATTR_LIST_MAX;
+
+ data = malloc(sz, M_LINUX, M_WAITOK);
+ auio.uio_iov = &aiov;
+ auio.uio_iovcnt = 1;
+ auio.uio_rw = UIO_READ;
+ auio.uio_segflg = UIO_SYSSPACE;
+ auio.uio_td = td;
+ cnt = 0;
+ for (attrnamespace = EXTATTR_NAMESPACE_USER;
+ attrnamespace < nitems(extattr_namespace_names);
+ attrnamespace++) {
+ aiov.iov_base = data;
+ aiov.iov_len = sz;
+ auio.uio_resid = sz;
+ auio.uio_offset = 0;
+
+ if (args->path != NULL)
+ error = kern_extattr_list_path(td, args->path,
+ attrnamespace, &auio, args->follow, UIO_USERSPACE);
+ else
+ error = kern_extattr_list_fd(td, args->fd,
+ attrnamespace, &auio);
+ rs = sz - auio.uio_resid;
+ if (error == EPERM)
+ break;
+ if (error != 0 || rs == 0)
+ continue;
+ prefix = extattr_namespace_names[attrnamespace];
+ prefixlen = strlen(prefix);
+ key = data;
+ while (rs > 0) {
+ keylen = (unsigned char)key[0];
+ pairlen = prefixlen + 1 + keylen + 1;
+ cnt += pairlen;
+ if (cnt > LINUX_XATTR_LIST_MAX) {
+ error = E2BIG;
+ break;
+ }
+ /*
+ * If size is specified as zero, return the current size
+ * of the list of extended attribute names.
+ */
+ if ((args->size > 0 && cnt > args->size) ||
+ pairlen >= sizeof(attrname)) {
+ error = ERANGE;
+ break;
+ }
+ ++key;
+ if (args->list != NULL && args->size > 0) {
+ sprintf(attrname, "%s.%.*s", prefix, keylen, key);
+ error = copyout(attrname, args->list, pairlen);
+ if (error != 0)
+ break;
+ args->list += pairlen;
+ }
+ key += keylen;
+ rs -= (keylen + 1);
+ }
+ }
+ if (error == 0)
+ td->td_retval[0] = cnt;
+ free(data, M_LINUX);
+ return (error_to_xattrerror(attrnamespace, error));
+}
+
+int
+linux_listxattr(struct thread *td, struct linux_listxattr_args *args)
+{
+ struct listxattr_args eargs = {
+ .fd = -1,
+ .path = args->path,
+ .list = args->list,
+ .size = args->size,
+ .follow = FOLLOW,
+ };
+
+ return (listxattr(td, &eargs));
+}
+
+int
+linux_llistxattr(struct thread *td, struct linux_llistxattr_args *args)
+{
+ struct listxattr_args eargs = {
+ .fd = -1,
+ .path = args->path,
+ .list = args->list,
+ .size = args->size,
+ .follow = NOFOLLOW,
+ };
+
+ return (listxattr(td, &eargs));
+}
+
+int
+linux_flistxattr(struct thread *td, struct linux_flistxattr_args *args)
+{
+ struct listxattr_args eargs = {
+ .fd = args->fd,
+ .path = NULL,
+ .list = args->list,
+ .size = args->size,
+ .follow = 0,
+ };
+
+ return (listxattr(td, &eargs));
+}
+
+static int
+removexattr(struct thread *td, struct removexattr_args *args)
+{
+ char attrname[LINUX_XATTR_NAME_MAX + 1];
+ int attrnamespace, error;
+
+ error = xattr_to_extattr(args->name, &attrnamespace, attrname);
+ if (error != 0)
+ return (error);
+ if (args->path != NULL)
+ error = kern_extattr_delete_path(td, args->path, attrnamespace,
+ attrname, args->follow, UIO_USERSPACE);
+ else
+ error = kern_extattr_delete_fd(td, args->fd, attrnamespace,
+ attrname);
+ return (error_to_xattrerror(attrnamespace, error));
+}
+
+int
+linux_removexattr(struct thread *td, struct linux_removexattr_args *args)
+{
+ struct removexattr_args eargs = {
+ .fd = -1,
+ .path = args->path,
+ .name = args->name,
+ .follow = FOLLOW,
+ };
+
+ return (removexattr(td, &eargs));
+}
+
+int
+linux_lremovexattr(struct thread *td, struct linux_lremovexattr_args *args)
+{
+ struct removexattr_args eargs = {
+ .fd = -1,
+ .path = args->path,
+ .name = args->name,
+ .follow = NOFOLLOW,
+ };
+
+ return (removexattr(td, &eargs));
+}
+
+int
+linux_fremovexattr(struct thread *td, struct linux_fremovexattr_args *args)
+{
+ struct removexattr_args eargs = {
+ .fd = args->fd,
+ .path = NULL,
+ .name = args->name,
+ .follow = 0,
+ };
+
+ return (removexattr(td, &eargs));
+}
+
+static int
+getxattr(struct thread *td, struct getxattr_args *args)
+{
+ char attrname[LINUX_XATTR_NAME_MAX + 1];
+ int attrnamespace, error;
+
+ error = xattr_to_extattr(args->name, &attrnamespace, attrname);
+ if (error != 0)
+ return (error);
+ if (args->path != NULL)
+ error = kern_extattr_get_path(td, args->path, attrnamespace,
+ attrname, args->value, args->size, args->follow, UIO_USERSPACE);
+ else
+ error = kern_extattr_get_fd(td, args->fd, attrnamespace,
+ attrname, args->value, args->size);
+ return (error == EPERM ? ENOATTR : error);
+}
+
+int
+linux_getxattr(struct thread *td, struct linux_getxattr_args *args)
+{
+ struct getxattr_args eargs = {
+ .fd = -1,
+ .path = args->path,
+ .name = args->name,
+ .value = args->value,
+ .size = args->size,
+ .follow = FOLLOW,
+ };
+
+ return (getxattr(td, &eargs));
+}
+
+int
+linux_lgetxattr(struct thread *td, struct linux_lgetxattr_args *args)
+{
+ struct getxattr_args eargs = {
+ .fd = -1,
+ .path = args->path,
+ .name = args->name,
+ .value = args->value,
+ .size = args->size,
+ .follow = NOFOLLOW,
+ };
+
+ return (getxattr(td, &eargs));
+}
+
+int
+linux_fgetxattr(struct thread *td, struct linux_fgetxattr_args *args)
+{
+ struct getxattr_args eargs = {
+ .fd = args->fd,
+ .path = NULL,
+ .name = args->name,
+ .value = args->value,
+ .size = args->size,
+ .follow = 0,
+ };
+
+ return (getxattr(td, &eargs));
+}
+
+static int
+setxattr(struct thread *td, struct setxattr_args *args)
+{
+ char attrname[LINUX_XATTR_NAME_MAX + 1];
+ int attrnamespace, error;
+
+ if ((args->flags & ~(LINUX_XATTR_FLAGS)) != 0 ||
+ args->flags == (LINUX_XATTR_FLAGS))
+ return (EINVAL);
+ error = xattr_to_extattr(args->name, &attrnamespace, attrname);
+ if (error != 0)
+ return (error);
+
+ if ((args->flags & (LINUX_XATTR_FLAGS)) != 0 ) {
+ if (args->path != NULL)
+ error = kern_extattr_get_path(td, args->path,
+ attrnamespace, attrname, NULL, args->size,
+ args->follow, UIO_USERSPACE);
+ else
+ error = kern_extattr_get_fd(td, args->fd,
+ attrnamespace, attrname, NULL, args->size);
+ if ((args->flags & LINUX_XATTR_CREATE) != 0) {
+ if (error == 0)
+ error = EEXIST;
+ else if (error == ENOATTR)
+ error = 0;
+ }
+ if (error != 0)
+ goto out;
+ }
+ if (args->path != NULL)
+ error = kern_extattr_set_path(td, args->path, attrnamespace,
+ attrname, args->value, args->size, args->follow,
+ UIO_USERSPACE);
+ else
+ error = kern_extattr_set_fd(td, args->fd, attrnamespace,
+ attrname, args->value, args->size);
+out:
+ td->td_retval[0] = 0;
+ return (error_to_xattrerror(attrnamespace, error));
+}
+
+int
+linux_setxattr(struct thread *td, struct linux_setxattr_args *args)
+{
+ struct setxattr_args eargs = {
+ .fd = -1,
+ .path = args->path,
+ .name = args->name,
+ .value = args->value,
+ .size = args->size,
+ .flags = args->flags,
+ .follow = FOLLOW,
+ };
+
+ return (setxattr(td, &eargs));
+}
+
+int
+linux_lsetxattr(struct thread *td, struct linux_lsetxattr_args *args)
+{
+ struct setxattr_args eargs = {
+ .fd = -1,
+ .path = args->path,
+ .name = args->name,
+ .value = args->value,
+ .size = args->size,
+ .flags = args->flags,
+ .follow = NOFOLLOW,
+ };
+
+ return (setxattr(td, &eargs));
+}
+
+int
+linux_fsetxattr(struct thread *td, struct linux_fsetxattr_args *args)
+{
+ struct setxattr_args eargs = {
+ .fd = args->fd,
+ .path = NULL,
+ .name = args->name,
+ .value = args->value,
+ .size = args->size,
+ .flags = args->flags,
+ .follow = 0,
+ };
+
+ return (setxattr(td, &eargs));
+}
diff --git a/sys/compat/linux/stats_timing.d b/sys/compat/linux/stats_timing.d
index 66a813a9af92..f0aa291e2155 100644
--- a/sys/compat/linux/stats_timing.d
+++ b/sys/compat/linux/stats_timing.d
@@ -24,8 +24,6 @@
* 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.
- *
- * $FreeBSD$
*/
/**
diff --git a/sys/compat/linux/trace_futexes.d b/sys/compat/linux/trace_futexes.d
index 94129212043a..0827cf78aa8f 100644
--- a/sys/compat/linux/trace_futexes.d
+++ b/sys/compat/linux/trace_futexes.d
@@ -24,8 +24,6 @@
* 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.
- *
- * $FreeBSD$
*/
/**
diff --git a/sys/compat/linuxkpi/common/include/acpi/acpi.h b/sys/compat/linuxkpi/common/include/acpi/acpi.h
index b6579f42774e..9bb435591daa 100644
--- a/sys/compat/linuxkpi/common/include/acpi/acpi.h
+++ b/sys/compat/linuxkpi/common/include/acpi/acpi.h
@@ -1,8 +1,12 @@
/*-
- * SPDX-License-Identifier: BSD-2-Clause-FreeBSD
+ * SPDX-License-Identifier: BSD-2-Clause
*
* Copyright (c) 2017 Mark Johnston <markj@FreeBSD.org>
* Copyright (c) 2020 Vladimir Kondratyev <wulf@FreeBSD.org>
+ * Copyright (c) 2025 The FreeBSD Foundation
+ *
+ * Portions of this software were developed by Björn Zeeb
+ * under sponsorship from the FreeBSD Foundation.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are
@@ -25,12 +29,17 @@
* 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.
- *
- * $FreeBSD$
*/
-#ifndef _ACPI_ACPI_H_
-#define _ACPI_ACPI_H_
+#ifndef _LINUXKPI_ACPI_ACPI_H_
+#define _LINUXKPI_ACPI_ACPI_H_
+
+/*
+ * LINUXKPI_WANT_LINUX_ACPI is a temporary workaround to allow drm-kmod
+ * to update all needed branches without breaking builds.
+ * Once that happened and checks are implemented based on __FreeBSD_version
+ * we will remove these conditions again.
+ */
/*
* FreeBSD import of ACPICA has a typedef for BOOLEAN which conflicts with
@@ -48,8 +57,8 @@ typedef int64_t INT64;
#include <contrib/dev/acpica/include/acpi.h>
#undef BOOLEAN
+typedef ACPI_IO_ADDRESS acpi_io_address;
typedef ACPI_HANDLE acpi_handle;
-typedef ACPI_OBJECT acpi_object;
typedef ACPI_OBJECT_HANDLER acpi_object_handler;
typedef ACPI_OBJECT_TYPE acpi_object_type;
typedef ACPI_STATUS acpi_status;
@@ -57,12 +66,62 @@ typedef ACPI_STRING acpi_string;
typedef ACPI_SIZE acpi_size;
typedef ACPI_WALK_CALLBACK acpi_walk_callback;
+union linuxkpi_acpi_object {
+ acpi_object_type type;
+ struct {
+ acpi_object_type type;
+ UINT64 value;
+ } integer;
+ struct {
+ acpi_object_type type;
+ UINT32 length;
+ char *pointer;
+ } string;
+ struct {
+ acpi_object_type type;
+ UINT32 length;
+ UINT8 *pointer;
+ } buffer;
+ struct {
+ acpi_object_type type;
+ UINT32 count;
+ union linuxkpi_acpi_object *elements;
+ } package;
+ struct {
+ acpi_object_type type;
+ acpi_object_type actual_type;
+ acpi_handle handle;
+ } reference;
+ struct {
+ acpi_object_type type;
+ UINT32 proc_id;
+ acpi_io_address pblk_address;
+ UINT32 pblk_length;
+ } processor;
+ struct {
+ acpi_object_type type;
+ UINT32 system_level;
+ UINT32 resource_order;
+ } power_resource;
+};
+
+#ifdef LINUXKPI_WANT_LINUX_ACPI
+struct linuxkpi_acpi_buffer {
+ acpi_size length; /* Length in bytes of the buffer */
+ void *pointer; /* pointer to buffer */
+};
+
+typedef struct linuxkpi_acpi_buffer lkpi_acpi_buffer_t;
+#else
+typedef ACPI_BUFFER lkpi_acpi_buffer_t;
+#endif
+
static inline ACPI_STATUS
acpi_evaluate_object(ACPI_HANDLE Object, ACPI_STRING Pathname,
- ACPI_OBJECT_LIST *ParameterObjects, ACPI_BUFFER *ReturnObjectBuffer)
+ ACPI_OBJECT_LIST *ParameterObjects, lkpi_acpi_buffer_t *ReturnObjectBuffer)
{
return (AcpiEvaluateObject(
- Object, Pathname, ParameterObjects, ReturnObjectBuffer));
+ Object, Pathname, ParameterObjects, (ACPI_BUFFER *)ReturnObjectBuffer));
}
static inline const char *
@@ -72,7 +131,7 @@ acpi_format_exception(ACPI_STATUS Exception)
}
static inline ACPI_STATUS
-acpi_get_handle(ACPI_HANDLE Parent, ACPI_STRING Pathname,
+acpi_get_handle(ACPI_HANDLE Parent, const char *Pathname,
ACPI_HANDLE *RetHandle)
{
return (AcpiGetHandle(Parent, Pathname, RetHandle));
@@ -85,9 +144,9 @@ acpi_get_data(ACPI_HANDLE ObjHandle, ACPI_OBJECT_HANDLER Handler, void **Data)
}
static inline ACPI_STATUS
-acpi_get_name(ACPI_HANDLE Object, UINT32 NameType, ACPI_BUFFER *RetPathPtr)
+acpi_get_name(ACPI_HANDLE Object, UINT32 NameType, lkpi_acpi_buffer_t *RetPathPtr)
{
- return (AcpiGetName(Object, NameType, RetPathPtr));
+ return (AcpiGetName(Object, NameType, (ACPI_BUFFER *)RetPathPtr));
}
static inline ACPI_STATUS
@@ -97,4 +156,15 @@ acpi_get_table(ACPI_STRING Signature, UINT32 Instance,
return (AcpiGetTable(Signature, Instance, OutTable));
}
-#endif /* _ACPI_ACPI_H_ */
+static inline void
+acpi_put_table(ACPI_TABLE_HEADER *Table)
+{
+ AcpiPutTable(Table);
+}
+
+#ifdef LINUXKPI_WANT_LINUX_ACPI
+#define acpi_object linuxkpi_acpi_object
+#define acpi_buffer linuxkpi_acpi_buffer
+#endif
+
+#endif /* _LINUXKPI_ACPI_ACPI_H_ */
diff --git a/sys/compat/linuxkpi/common/include/acpi/acpi_bus.h b/sys/compat/linuxkpi/common/include/acpi/acpi_bus.h
index abee5223af60..da50d25a63bb 100644
--- a/sys/compat/linuxkpi/common/include/acpi/acpi_bus.h
+++ b/sys/compat/linuxkpi/common/include/acpi/acpi_bus.h
@@ -1,5 +1,5 @@
/*-
- * SPDX-License-Identifier: BSD-2-Clause-FreeBSD
+ * SPDX-License-Identifier: BSD-2-Clause
*
* Copyright (c) 2020 Vladimir Kondratyev <wulf@FreeBSD.org>
*
@@ -24,12 +24,13 @@
* 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.
- *
- * $FreeBSD$
*/
-#ifndef _ACPI_ACPI_BUS_H_
-#define _ACPI_ACPI_BUS_H_
+#ifndef _LINUXKPI_ACPI_ACPI_BUS_H_
+#define _LINUXKPI_ACPI_ACPI_BUS_H_
+
+/* Aliase struct acpi_device to device_t */
+#define acpi_device _device
typedef char acpi_device_class[20];
@@ -39,14 +40,28 @@ struct acpi_bus_event {
uint32_t data;
};
+#define acpi_dev_present(...) lkpi_acpi_dev_present(__VA_ARGS__)
+#define acpi_dev_get_first_match_dev(...) \
+ lkpi_acpi_dev_get_first_match_dev(__VA_ARGS__)
+
ACPI_HANDLE bsd_acpi_get_handle(device_t bsddev);
-bool acpi_check_dsm(ACPI_HANDLE handle, const char *uuid, int rev,
+bool acpi_check_dsm(ACPI_HANDLE handle, const guid_t *uuid, int rev,
uint64_t funcs);
-ACPI_OBJECT * acpi_evaluate_dsm_typed(ACPI_HANDLE handle, const char *uuid,
+ACPI_OBJECT * acpi_evaluate_dsm_typed(ACPI_HANDLE handle, const guid_t *uuid,
int rev, int func, ACPI_OBJECT *argv4,
ACPI_OBJECT_TYPE type);
int register_acpi_notifier(struct notifier_block *nb);
int unregister_acpi_notifier(struct notifier_block *nb);
uint32_t acpi_target_system_state(void);
+bool lkpi_acpi_dev_present(const char *hid, const char *uid,
+ int64_t hrv);
+struct acpi_device *lkpi_acpi_dev_get_first_match_dev(const char *hid,
+ const char *uid, int64_t hrv);
+
+union linuxkpi_acpi_object;
+
+union linuxkpi_acpi_object *
+acpi_evaluate_dsm(ACPI_HANDLE ObjHandle, const guid_t *guid,
+ UINT64 rev, UINT64 func, union linuxkpi_acpi_object *arg);
-#endif /* !_ACPI_ACPI_BUS_H_ */
+#endif /* _LINUXKPI_ACPI_ACPI_BUS_H_ */
diff --git a/sys/compat/linuxkpi/common/include/acpi/actbl.h b/sys/compat/linuxkpi/common/include/acpi/actbl.h
new file mode 100644
index 000000000000..dbb7db41bb66
--- /dev/null
+++ b/sys/compat/linuxkpi/common/include/acpi/actbl.h
@@ -0,0 +1 @@
+#include <contrib/dev/acpica/include/actbl.h>
diff --git a/sys/compat/linuxkpi/common/include/acpi/video.h b/sys/compat/linuxkpi/common/include/acpi/video.h
index 5c42153356c0..fd2ffd6764d0 100644
--- a/sys/compat/linuxkpi/common/include/acpi/video.h
+++ b/sys/compat/linuxkpi/common/include/acpi/video.h
@@ -1,5 +1,5 @@
/*-
- * SPDX-License-Identifier: BSD-2-Clause-FreeBSD
+ * SPDX-License-Identifier: BSD-2-Clause
*
* Copyright (c) 2020 Vladimir Kondratyev <wulf@FreeBSD.org>
*
@@ -24,15 +24,39 @@
* 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.
- *
- * $FreeBSD$
*/
-#ifndef _ACPI_VIDEO_H_
-#define _ACPI_VIDEO_H_
+#ifndef _LINUXKPI_ACPI_VIDEO_H_
+#define _LINUXKPI_ACPI_VIDEO_H_
+
+#include <sys/types.h>
+#include <sys/errno.h>
#define ACPI_VIDEO_CLASS "video"
#define ACPI_VIDEO_NOTIFY_PROBE 0x81
-#endif /* !_ACPI_VIDEO_H_ */
+static inline int
+acpi_video_register(void)
+{
+
+ return (-ENODEV);
+}
+
+static inline void
+acpi_video_unregister(void)
+{
+}
+
+static inline void
+acpi_video_register_backlight(void)
+{
+}
+
+static inline bool
+acpi_video_backlight_use_native(void)
+{
+ return (true);
+}
+
+#endif /* _LINUXKPI_ACPI_VIDEO_H_ */
diff --git a/sys/compat/linuxkpi/common/include/asm-generic/io.h b/sys/compat/linuxkpi/common/include/asm-generic/io.h
new file mode 100644
index 000000000000..8dc7eb6cf453
--- /dev/null
+++ b/sys/compat/linuxkpi/common/include/asm-generic/io.h
@@ -0,0 +1,40 @@
+/*-
+ * Copyright (c) 2022 Beckhoff Automation GmbH & Co. KG
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``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 OR CONTRIBUTORS 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.
+ *
+ */
+
+#ifndef _LINUXKPI_ASMGENERIC_IO_H_
+#define _LINUXKPI_ASMGENERIC_IO_H_
+
+#if defined(__i386__) || defined(__amd64__)
+
+#include <machine/cpufunc.h>
+
+#define outb(a,b) outb(b,a)
+#define outw(a,b) outw(b,a)
+#define outl(a,b) outl(b,a)
+
+#endif
+
+#endif /* _LINUXKPI_ASMGENERIC_IO_H_ */
diff --git a/sys/compat/linuxkpi/common/include/asm/atomic-long.h b/sys/compat/linuxkpi/common/include/asm/atomic-long.h
index c80c348f95f9..db3a94c539e5 100644
--- a/sys/compat/linuxkpi/common/include/asm/atomic-long.h
+++ b/sys/compat/linuxkpi/common/include/asm/atomic-long.h
@@ -25,11 +25,9 @@
* 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.
- *
- * $FreeBSD$
*/
-#ifndef _ATOMIC_LONG_H_
-#define _ATOMIC_LONG_H_
+#ifndef _LINUXKPI_ASM_ATOMIC_LONG_H_
+#define _LINUXKPI_ASM_ATOMIC_LONG_H_
#include <linux/compiler.h>
#include <sys/types.h>
@@ -41,7 +39,7 @@ typedef struct {
} atomic_long_t;
#define atomic_long_add(i, v) atomic_long_add_return((i), (v))
-#define atomic_long_sub(i, v) atomic_long_add_return(-(i), (v))
+#define atomic_long_sub(i, v) atomic_long_sub_return((i), (v))
#define atomic_long_inc_return(v) atomic_long_add_return(1, (v))
#define atomic_long_inc_not_zero(v) atomic_long_add_unless((v), 1, 0)
@@ -51,6 +49,12 @@ atomic_long_add_return(long i, atomic_long_t *v)
return i + atomic_fetchadd_long(&v->counter, i);
}
+static inline long
+atomic_long_sub_return(long i, atomic_long_t *v)
+{
+ return atomic_fetchadd_long(&v->counter, -i) - i;
+}
+
static inline void
atomic_long_set(atomic_long_t *v, long i)
{
@@ -130,4 +134,4 @@ atomic_long_dec_and_test(atomic_long_t *v)
return i == 0 ;
}
-#endif /* _ATOMIC_LONG_H_ */
+#endif /* _LINUXKPI_ASM_ATOMIC_LONG_H_ */
diff --git a/sys/compat/linuxkpi/common/include/asm/atomic.h b/sys/compat/linuxkpi/common/include/asm/atomic.h
index 5cdfbe674ef3..edb478af8c82 100644
--- a/sys/compat/linuxkpi/common/include/asm/atomic.h
+++ b/sys/compat/linuxkpi/common/include/asm/atomic.h
@@ -25,12 +25,10 @@
* 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.
- *
- * $FreeBSD$
*/
-#ifndef _ASM_ATOMIC_H_
-#define _ASM_ATOMIC_H_
+#ifndef _LINUXKPI_ASM_ATOMIC_H_
+#define _LINUXKPI_ASM_ATOMIC_H_
#include <linux/compiler.h>
#include <sys/types.h>
@@ -166,9 +164,7 @@ atomic_cmpxchg(atomic_t *v, int old, int new)
#define LINUXKPI_ATOMIC_16(...)
#endif
-#if !(defined(i386) || (defined(__mips__) && !(defined(__mips_n32) || \
- defined(__mips_n64))) || (defined(__powerpc__) && \
- !defined(__powerpc64__)))
+#if !(defined(i386) || (defined(__powerpc__) && !defined(__powerpc64__)))
#define LINUXKPI_ATOMIC_64(...) __VA_ARGS__
#else
#define LINUXKPI_ATOMIC_64(...)
@@ -220,6 +216,7 @@ atomic_cmpxchg(atomic_t *v, int old, int new)
__ret.val; \
})
+#define cmpxchg64(...) cmpxchg(__VA_ARGS__)
#define cmpxchg_relaxed(...) cmpxchg(__VA_ARGS__)
#define xchg(ptr, new) ({ \
@@ -268,6 +265,28 @@ atomic_cmpxchg(atomic_t *v, int old, int new)
__ret.val; \
})
+#define try_cmpxchg(p, op, n) \
+({ \
+ __typeof(p) __op = (__typeof((p)))(op); \
+ __typeof(*(p)) __o = *__op; \
+ __typeof(*(p)) __p = __sync_val_compare_and_swap((p), (__o), (n)); \
+ if (__p != __o) \
+ *__op = __p; \
+ (__p == __o); \
+})
+
+#define __atomic_try_cmpxchg(type, _p, _po, _n) \
+({ \
+ __typeof(_po) __po = (_po); \
+ __typeof(*(_po)) __r, __o = *__po; \
+ __r = atomic_cmpxchg##type((_p), __o, (_n)); \
+ if (unlikely(__r != __o)) \
+ *__po = __r; \
+ likely(__r == __o); \
+})
+
+#define atomic_try_cmpxchg(_p, _po, _n) __atomic_try_cmpxchg(, _p, _po, _n)
+
static inline int
atomic_dec_if_positive(atomic_t *v)
{
@@ -307,6 +326,13 @@ static inline int atomic_fetch_##op(int i, atomic_t *v) \
return (c); \
}
+static inline int
+atomic_fetch_inc(atomic_t *v)
+{
+
+ return ((atomic_inc_return(v) - 1));
+}
+
LINUX_ATOMIC_OP(or, |)
LINUX_ATOMIC_OP(and, &)
LINUX_ATOMIC_OP(andnot, &~)
@@ -317,4 +343,4 @@ LINUX_ATOMIC_FETCH_OP(and, &)
LINUX_ATOMIC_FETCH_OP(andnot, &~)
LINUX_ATOMIC_FETCH_OP(xor, ^)
-#endif /* _ASM_ATOMIC_H_ */
+#endif /* _LINUXKPI_ASM_ATOMIC_H_ */
diff --git a/sys/compat/linuxkpi/common/include/asm/atomic64.h b/sys/compat/linuxkpi/common/include/asm/atomic64.h
index b8b87bb2c685..fbfb9254b64c 100644
--- a/sys/compat/linuxkpi/common/include/asm/atomic64.h
+++ b/sys/compat/linuxkpi/common/include/asm/atomic64.h
@@ -22,11 +22,9 @@
* 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.
- *
- * $FreeBSD$
*/
-#ifndef _ASM_ATOMIC64_H_
-#define _ASM_ATOMIC64_H_
+#ifndef _LINUXKPI_ASM_ATOMIC64_H_
+#define _LINUXKPI_ASM_ATOMIC64_H_
#include <linux/compiler.h>
#include <sys/types.h>
@@ -53,6 +51,12 @@ typedef struct {
#define atomic64_inc_not_zero(v) atomic64_add_unless((v), 1, 0)
static inline int64_t
+atomic64_fetch_add(int64_t i, atomic64_t *v)
+{
+ return (atomic_fetchadd_64(&v->counter, i));
+}
+
+static inline int64_t
atomic64_add_return(int64_t i, atomic64_t *v)
{
return i + atomic_fetchadd_64(&v->counter, i);
@@ -119,8 +123,7 @@ atomic64_fetch_add_unless(atomic64_t *v, int64_t a, int64_t u)
static inline int64_t
atomic64_xchg(atomic64_t *v, int64_t i)
{
-#if !((defined(__mips__) && !(defined(__mips_n32) || defined(__mips_n64))) || \
- (defined(__powerpc__) && !defined(__powerpc64__)))
+#if !(defined(__powerpc__) && !defined(__powerpc64__))
return (atomic_swap_64(&v->counter, i));
#else
int64_t ret = atomic64_read(v);
@@ -145,4 +148,4 @@ atomic64_cmpxchg(atomic64_t *v, int64_t old, int64_t new)
return (ret);
}
-#endif /* _ASM_ATOMIC64_H_ */
+#endif /* _LINUXKPI_ASM_ATOMIC64_H_ */
diff --git a/sys/compat/linuxkpi/common/include/asm/barrier.h b/sys/compat/linuxkpi/common/include/asm/barrier.h
new file mode 100644
index 000000000000..39c5139cb322
--- /dev/null
+++ b/sys/compat/linuxkpi/common/include/asm/barrier.h
@@ -0,0 +1,64 @@
+/*-
+ * SPDX-License-Identifier: BSD-2-Clause
+ *
+ * Copyright (c) 2021 Vladimir Kondratyev <wulf@FreeBSD.org>
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice unmodified, this list of conditions, and the following
+ * disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``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.
+ */
+
+#ifndef _LINUXKPI_ASM_BARRIER_H_
+#define _LINUXKPI_ASM_BARRIER_H_
+
+#include <sys/types.h>
+#include <machine/atomic.h>
+
+#include <asm/atomic.h>
+#include <linux/compiler.h>
+
+/* TODO: Check other archs for atomic_thread_fence_* useability */
+#if defined(__amd64__) || defined(__i386__)
+#define smp_mb() atomic_thread_fence_seq_cst()
+#define smp_wmb() atomic_thread_fence_rel()
+#define smp_rmb() atomic_thread_fence_acq()
+#define smp_store_mb(x, v) do { (void)xchg(&(x), v); } while (0)
+#endif
+
+#ifndef smp_mb
+#define smp_mb() mb()
+#endif
+#ifndef smp_wmb
+#define smp_wmb() wmb()
+#endif
+#ifndef smp_rmb
+#define smp_rmb() rmb()
+#endif
+#ifndef smp_store_mb
+#define smp_store_mb(x, v) do { WRITE_ONCE(x, v); smp_mb(); } while (0)
+#endif
+
+#define smp_mb__before_atomic() barrier()
+#define smp_mb__after_atomic() barrier()
+
+#define smp_store_release(p, v) do { smp_mb(); WRITE_ONCE(*p, v); } while (0)
+#define smp_load_acquire(p) ({ typeof(*p) _v = READ_ONCE(*p); smp_mb(); _v; })
+
+#endif /* _LINUXKPI_ASM_BARRIER_H_ */
diff --git a/sys/compat/linuxkpi/common/include/asm/byteorder.h b/sys/compat/linuxkpi/common/include/asm/byteorder.h
index 05e39bb52149..ad7a923ca143 100644
--- a/sys/compat/linuxkpi/common/include/asm/byteorder.h
+++ b/sys/compat/linuxkpi/common/include/asm/byteorder.h
@@ -25,11 +25,9 @@
* 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.
- *
- * $FreeBSD$
*/
-#ifndef _ASM_BYTEORDER_H_
-#define _ASM_BYTEORDER_H_
+#ifndef _LINUXKPI_ASM_BYTEORDER_H_
+#define _LINUXKPI_ASM_BYTEORDER_H_
#include <sys/types.h>
#include <sys/endian.h>
@@ -157,4 +155,4 @@ le16_add_cpu(uint16_t *var, uint16_t val)
*var = cpu_to_le16(le16_to_cpu(*var) + val);
}
-#endif /* _ASM_BYTEORDER_H_ */
+#endif /* _LINUXKPI_ASM_BYTEORDER_H_ */
diff --git a/sys/compat/linuxkpi/common/include/asm/cpufeature.h b/sys/compat/linuxkpi/common/include/asm/cpufeature.h
new file mode 100644
index 000000000000..84ab86af33dd
--- /dev/null
+++ b/sys/compat/linuxkpi/common/include/asm/cpufeature.h
@@ -0,0 +1,37 @@
+/* Public domain. */
+
+#ifndef _LINUXKPI_ASM_CPUFEATURE_H
+#define _LINUXKPI_ASM_CPUFEATURE_H
+
+#if defined(__amd64__) || defined(__i386__)
+
+#include <sys/types.h>
+#include <machine/md_var.h>
+
+#define X86_FEATURE_CLFLUSH 1
+#define X86_FEATURE_XMM4_1 2
+#define X86_FEATURE_PAT 3
+#define X86_FEATURE_HYPERVISOR 4
+
+static inline bool
+static_cpu_has(uint16_t f)
+{
+ switch (f) {
+ case X86_FEATURE_CLFLUSH:
+ return ((cpu_feature & CPUID_CLFSH) != 0);
+ case X86_FEATURE_XMM4_1:
+ return ((cpu_feature2 & CPUID2_SSE41) != 0);
+ case X86_FEATURE_PAT:
+ return ((cpu_feature & CPUID_PAT) != 0);
+ case X86_FEATURE_HYPERVISOR:
+ return ((cpu_feature2 & CPUID2_HV) != 0);
+ default:
+ return (false);
+ }
+}
+
+#define boot_cpu_has(x) static_cpu_has(x)
+
+#endif
+
+#endif
diff --git a/sys/compat/linuxkpi/common/include/asm/fcntl.h b/sys/compat/linuxkpi/common/include/asm/fcntl.h
index f24624e6eeed..3820e15039f2 100644
--- a/sys/compat/linuxkpi/common/include/asm/fcntl.h
+++ b/sys/compat/linuxkpi/common/include/asm/fcntl.h
@@ -25,12 +25,10 @@
* 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.
- *
- * $FreeBSD$
*/
-#ifndef _ASM_FCNTL_H_
-#define _ASM_FCNTL_H_
+#ifndef _LINUXKPI_ASM_FCNTL_H_
+#define _LINUXKPI_ASM_FCNTL_H_
#include <sys/fcntl.h>
-#endif /* _ASM_FCNTL_H_ */
+#endif /* _LINUXKPI_ASM_FCNTL_H_ */
diff --git a/sys/compat/linuxkpi/common/include/asm/fpu/api.h b/sys/compat/linuxkpi/common/include/asm/fpu/api.h
index 9c63b2e972bf..a4803bde461f 100644
--- a/sys/compat/linuxkpi/common/include/asm/fpu/api.h
+++ b/sys/compat/linuxkpi/common/include/asm/fpu/api.h
@@ -1,7 +1,7 @@
/*-
- * SPDX-License-Identifier: BSD-2-Clause-FreeBSD
+ * SPDX-License-Identifier: BSD-2-Clause
*
- * Copyright (c) 2020 Greg V <greg@unrelenting.technology>
+ * Copyright (c) 2020 Val Packett <val@packett.cool>
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
@@ -25,8 +25,8 @@
* SUCH DAMAGE.
*/
-#ifndef _FPU_API_H_
-#define _FPU_API_H_
+#ifndef _LINUXKPI_ASM_FPU_API_H_
+#define _LINUXKPI_ASM_FPU_API_H_
#define kernel_fpu_begin() \
lkpi_kernel_fpu_begin()
@@ -37,4 +37,4 @@
extern void lkpi_kernel_fpu_begin(void);
extern void lkpi_kernel_fpu_end(void);
-#endif /* _FPU_API_H_ */
+#endif /* _LINUXKPI_ASM_FPU_API_H_ */
diff --git a/sys/compat/linuxkpi/common/include/asm/hypervisor.h b/sys/compat/linuxkpi/common/include/asm/hypervisor.h
new file mode 100644
index 000000000000..f344a2929359
--- /dev/null
+++ b/sys/compat/linuxkpi/common/include/asm/hypervisor.h
@@ -0,0 +1,19 @@
+/* Public domain. */
+
+#ifndef _LINUXKPI_ASM_HYPERVISOR_H
+#define _LINUXKPI_ASM_HYPERVISOR_H
+
+#if defined(__i386__) || defined(__amd64__)
+
+#define X86_HYPER_NATIVE 1
+#define X86_HYPER_MS_HYPERV 2
+
+static inline bool
+hypervisor_is_type(int type)
+{
+ return (type == X86_HYPER_NATIVE);
+}
+
+#endif
+
+#endif
diff --git a/sys/compat/linuxkpi/common/include/asm/intel-family.h b/sys/compat/linuxkpi/common/include/asm/intel-family.h
new file mode 100644
index 000000000000..91ad1d1a8ff3
--- /dev/null
+++ b/sys/compat/linuxkpi/common/include/asm/intel-family.h
@@ -0,0 +1,6 @@
+/* Public domain. */
+
+#define INTEL_FAM6_ALDERLAKE 0x97
+#define INTEL_FAM6_ALDERLAKE_L 0x9A
+
+#define INTEL_FAM6_ROCKETLAKE 0xA7
diff --git a/sys/compat/linuxkpi/common/include/asm/io.h b/sys/compat/linuxkpi/common/include/asm/io.h
index 24d350f4743e..63d1c8f72f8e 100644
--- a/sys/compat/linuxkpi/common/include/asm/io.h
+++ b/sys/compat/linuxkpi/common/include/asm/io.h
@@ -25,12 +25,17 @@
* 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.
- *
- * $FreeBSD$
*/
-#ifndef _ASM_IO_H_
-#define _ASM_IO_H_
+#ifndef _LINUXKPI_ASM_IO_H_
+#define _LINUXKPI_ASM_IO_H_
+
+#include <sys/param.h>
+
+#include <vm/vm.h>
+#include <vm/pmap.h>
#include <linux/io.h>
-#endif /* _ASM_IO_H_ */
+#define virt_to_phys(x) vtophys(x)
+
+#endif /* _LINUXKPI_ASM_IO_H_ */
diff --git a/sys/compat/linuxkpi/common/include/asm/iosf_mbi.h b/sys/compat/linuxkpi/common/include/asm/iosf_mbi.h
new file mode 100644
index 000000000000..a99c9cced6a4
--- /dev/null
+++ b/sys/compat/linuxkpi/common/include/asm/iosf_mbi.h
@@ -0,0 +1,15 @@
+/* Public domain. */
+
+#ifndef _LINUXKPI_ASM_IOSF_MBI_H_
+#define _LINUXKPI_ASM_IOSF_MBI_H_
+
+#define MBI_PMIC_BUS_ACCESS_BEGIN 1
+#define MBI_PMIC_BUS_ACCESS_END 2
+
+#define iosf_mbi_assert_punit_acquired()
+#define iosf_mbi_punit_acquire()
+#define iosf_mbi_punit_release()
+#define iosf_mbi_register_pmic_bus_access_notifier(x) 0
+#define iosf_mbi_unregister_pmic_bus_access_notifier_unlocked(x) 0
+
+#endif /* _LINUXKPI_ASM_IOSF_MBI_H_ */
diff --git a/sys/compat/linuxkpi/common/include/asm/memtype.h b/sys/compat/linuxkpi/common/include/asm/memtype.h
new file mode 100644
index 000000000000..c433e54fd7bf
--- /dev/null
+++ b/sys/compat/linuxkpi/common/include/asm/memtype.h
@@ -0,0 +1,18 @@
+/* Public domain. */
+
+#ifndef _LINUXKPI_ASM_MEMTYPE_H_
+#define _LINUXKPI_ASM_MEMTYPE_H_
+
+#if defined(__amd64__) || defined(__i386__)
+
+#include <asm/cpufeature.h>
+
+static inline bool
+pat_enabled(void)
+{
+ return (boot_cpu_has(X86_FEATURE_PAT));
+}
+
+#endif
+
+#endif /* _LINUXKPI_ASM_MEMTYPE_H_ */
diff --git a/sys/compat/linuxkpi/common/include/asm/msr.h b/sys/compat/linuxkpi/common/include/asm/msr.h
index 1697c20767a5..6f7c10f2860b 100644
--- a/sys/compat/linuxkpi/common/include/asm/msr.h
+++ b/sys/compat/linuxkpi/common/include/asm/msr.h
@@ -22,16 +22,14 @@
* 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.
- *
- * $FreeBSD$
*/
-#ifndef _ASM_MSR_H_
-#define _ASM_MSR_H_
+#ifndef _LINUXKPI_ASM_MSR_H_
+#define _LINUXKPI_ASM_MSR_H_
#include <machine/cpufunc.h>
#define rdmsrl(msr, val) ((val) = rdmsr(msr))
#define rdmsrl_safe(msr, val) rdmsr_safe(msr, val)
-#endif /* _ASM_MSR_H_ */
+#endif /* _LINUXKPI_ASM_MSR_H_ */
diff --git a/sys/compat/linuxkpi/common/include/asm/neon.h b/sys/compat/linuxkpi/common/include/asm/neon.h
new file mode 100644
index 000000000000..0488a90d6664
--- /dev/null
+++ b/sys/compat/linuxkpi/common/include/asm/neon.h
@@ -0,0 +1,40 @@
+/*-
+ * SPDX-License-Identifier: BSD-2-Clause
+ *
+ * Copyright (c) 2022 Val Packett <val@packett.cool>
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHORS AND CONTRIBUTORS ``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 AUTHORS OR CONTRIBUTORS 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.
+ */
+
+#ifndef _LINUXKPI_ASM_NEON_H_
+#define _LINUXKPI_ASM_NEON_H_
+
+#define kernel_neon_begin() \
+ lkpi_kernel_fpu_begin()
+
+#define kernel_neon_end() \
+ lkpi_kernel_fpu_end()
+
+extern void lkpi_kernel_fpu_begin(void);
+extern void lkpi_kernel_fpu_end(void);
+
+#endif /* _LINUXKPI_ASM_NEON_H_ */
diff --git a/sys/compat/linuxkpi/common/include/asm/pgtable.h b/sys/compat/linuxkpi/common/include/asm/pgtable.h
index 4831c144888d..865662d587db 100644
--- a/sys/compat/linuxkpi/common/include/asm/pgtable.h
+++ b/sys/compat/linuxkpi/common/include/asm/pgtable.h
@@ -25,11 +25,9 @@
* 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.
- *
- * $FreeBSD$
*/
-#ifndef _ASM_PGTABLE_H_
-#define _ASM_PGTABLE_H_
+#ifndef _LINUXKPI_ASM_PGTABLE_H_
+#define _LINUXKPI_ASM_PGTABLE_H_
#include <linux/page.h>
@@ -42,4 +40,19 @@ typedef struct page *pgtable_t;
#define pgprot_decrypted(prot) (prot)
-#endif /* _ASM_PGTABLE_H_ */
+#if defined(__i386__) || defined(__amd64__)
+#define _PAGE_BIT_PRESENT 0
+#define _PAGE_BIT_RW 1
+#define _PAGE_BIT_USER 2
+#define _PAGE_BIT_PWT 3
+#define _PAGE_BIT_PCD 4
+#define _PAGE_BIT_PAT 7
+
+#define _PAGE_PRESENT (((pteval_t) 1) << _PAGE_BIT_PRESENT)
+#define _PAGE_RW (((pteval_t) 1) << _PAGE_BIT_RW)
+#define _PAGE_PWT (((pteval_t) 1) << _PAGE_BIT_PWT)
+#define _PAGE_PCD (((pteval_t) 1) << _PAGE_BIT_PCD)
+#define _PAGE_PAT (((pteval_t) 1) << _PAGE_BIT_PAT)
+#endif
+
+#endif /* _LINUXKPI_ASM_PGTABLE_H_ */
diff --git a/sys/compat/linuxkpi/common/include/asm/processor.h b/sys/compat/linuxkpi/common/include/asm/processor.h
new file mode 100644
index 000000000000..2bc4b6532544
--- /dev/null
+++ b/sys/compat/linuxkpi/common/include/asm/processor.h
@@ -0,0 +1,63 @@
+/*-
+ * SPDX-License-Identifier: BSD-2-Clause
+ *
+ * Copyright (c) 2021 Vladimir Kondratyev <wulf@FreeBSD.org>
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``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.
+ */
+
+#ifndef _LINUXKPI_ASM_PROCESSOR_H_
+#define _LINUXKPI_ASM_PROCESSOR_H_
+
+#include <sys/types.h>
+#include <machine/cpufunc.h>
+#include <machine/cpu.h>
+
+#if defined(__i386__) || defined(__amd64__)
+#define X86_VENDOR_INTEL 0
+#define X86_VENDOR_CYRIX 1
+#define X86_VENDOR_AMD 2
+#define X86_VENDOR_UMC 3
+#define X86_VENDOR_CENTAUR 5
+#define X86_VENDOR_TRANSMETA 7
+#define X86_VENDOR_NSC 8
+#define X86_VENDOR_HYGON 9
+#define X86_VENDOR_NUM 12
+
+#define X86_VENDOR_UNKNOWN 0xff
+
+struct cpuinfo_x86 {
+ uint8_t x86;
+ uint8_t x86_model;
+ uint16_t x86_clflush_size;
+ uint16_t x86_max_cores;
+ uint8_t x86_vendor;
+};
+
+extern struct cpuinfo_x86 boot_cpu_data;
+extern struct cpuinfo_x86 *__cpu_data;
+#define cpu_data(cpu) __cpu_data[cpu]
+#endif
+
+#define cpu_relax() cpu_spinwait()
+
+#endif /* _LINUXKPI_ASM_PROCESSOR_H_ */
diff --git a/sys/compat/linuxkpi/common/include/asm/set_memory.h b/sys/compat/linuxkpi/common/include/asm/set_memory.h
new file mode 100644
index 000000000000..1019aaf264a0
--- /dev/null
+++ b/sys/compat/linuxkpi/common/include/asm/set_memory.h
@@ -0,0 +1,126 @@
+/*-
+ * Copyright (c) 2010 Isilon Systems, Inc.
+ * Copyright (c) 2016 Matt Macy (mmacy@nextbsd.org)
+ * Copyright (c) 2017 Mellanox Technologies, Ltd.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice unmodified, this list of conditions, and the following
+ * disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``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.
+ */
+
+#ifndef _LINUXKPI_ASM_SET_MEMORY_H_
+#define _LINUXKPI_ASM_SET_MEMORY_H_
+
+#include <linux/page.h>
+
+static inline int
+set_memory_uc(unsigned long addr, int numpages)
+{
+ vm_size_t len;
+
+ len = (vm_size_t)numpages << PAGE_SHIFT;
+ return (-pmap_change_attr(addr, len, VM_MEMATTR_UNCACHEABLE));
+}
+
+static inline int
+set_memory_wc(unsigned long addr, int numpages)
+{
+#ifdef VM_MEMATTR_WRITE_COMBINING
+ vm_size_t len;
+
+ len = (vm_size_t)numpages << PAGE_SHIFT;
+ return (-pmap_change_attr(addr, len, VM_MEMATTR_WRITE_COMBINING));
+#else
+ return (set_memory_uc(addr, numpages));
+#endif
+}
+
+static inline int
+set_memory_wb(unsigned long addr, int numpages)
+{
+ vm_size_t len;
+
+ len = (vm_size_t)numpages << PAGE_SHIFT;
+ return (-pmap_change_attr(addr, len, VM_MEMATTR_WRITE_BACK));
+}
+
+static inline int
+set_pages_uc(struct page *page, int numpages)
+{
+ KASSERT(numpages == 1, ("%s: numpages %d", __func__, numpages));
+
+ pmap_page_set_memattr(page, VM_MEMATTR_UNCACHEABLE);
+ return (0);
+}
+
+static inline int
+set_pages_wc(struct page *page, int numpages)
+{
+ KASSERT(numpages == 1, ("%s: numpages %d", __func__, numpages));
+
+#ifdef VM_MEMATTR_WRITE_COMBINING
+ pmap_page_set_memattr(page, VM_MEMATTR_WRITE_COMBINING);
+#else
+ return (set_pages_uc(page, numpages));
+#endif
+ return (0);
+}
+
+static inline int
+set_pages_wb(struct page *page, int numpages)
+{
+ KASSERT(numpages == 1, ("%s: numpages %d", __func__, numpages));
+
+ pmap_page_set_memattr(page, VM_MEMATTR_WRITE_BACK);
+ return (0);
+}
+
+static inline int
+set_pages_array_wb(struct page **pages, int addrinarray)
+{
+ int i;
+
+ for (i = 0; i < addrinarray; i++)
+ set_pages_wb(pages[i], 1);
+ return (0);
+}
+
+static inline int
+set_pages_array_wc(struct page **pages, int addrinarray)
+{
+ int i;
+
+ for (i = 0; i < addrinarray; i++)
+ set_pages_wc(pages[i], 1);
+ return (0);
+}
+
+static inline int
+set_pages_array_uc(struct page **pages, int addrinarray)
+{
+ int i;
+
+ for (i = 0; i < addrinarray; i++)
+ set_pages_uc(pages[i], 1);
+ return (0);
+}
+
+#endif /* _LINUXKPI_ASM_SET_MEMORY_H_ */
diff --git a/sys/compat/linuxkpi/common/include/asm/smp.h b/sys/compat/linuxkpi/common/include/asm/smp.h
index dd25b02115a8..27c3a81ef101 100644
--- a/sys/compat/linuxkpi/common/include/asm/smp.h
+++ b/sys/compat/linuxkpi/common/include/asm/smp.h
@@ -22,12 +22,14 @@
* 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.
- *
- * $FreeBSD$
*/
-#ifndef _ASM_SMP_H_
-#define _ASM_SMP_H_
+#ifndef _LINUXKPI_ASM_SMP_H_
+#define _LINUXKPI_ASM_SMP_H_
+
+#include <linux/jump_label.h>
+#include <linux/preempt.h>
+#include <asm/fpu/api.h>
#if defined(__i386__) || defined(__amd64__)
@@ -45,4 +47,4 @@ int linux_wbinvd_on_all_cpus(void);
#define put_cpu() \
critical_exit()
-#endif /* _ASM_SMP_H_ */
+#endif /* _LINUXKPI_ASM_SMP_H_ */
diff --git a/sys/compat/linuxkpi/common/include/asm/topology.h b/sys/compat/linuxkpi/common/include/asm/topology.h
new file mode 100644
index 000000000000..f334d3253cfb
--- /dev/null
+++ b/sys/compat/linuxkpi/common/include/asm/topology.h
@@ -0,0 +1,54 @@
+/*-
+ * Copyright (c) 2025 The FreeBSD Foundation
+ * Copyright (c) 2025 Jean-Sébastien Pédron <dumbbell@FreeBSD.org>
+ *
+ * This software was developed by Jean-Sébastien Pédron under sponsorship
+ * from the FreeBSD Foundation.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``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 OR CONTRIBUTORS 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.
+ */
+
+#ifndef _LINUXKPI_ASM_TOPOLOGY_H_
+#define _LINUXKPI_ASM_TOPOLOGY_H_
+
+#if defined(__i386__) || defined(__amd64__)
+#include <sys/smp.h>
+
+/*
+ * The following functions are defined in `arch/x86/include/asm/topology.h`
+ * and thus are specific to i386 and amd64.
+ */
+
+static inline unsigned int
+topology_num_cores_per_package(void)
+{
+ return (mp_ncores);
+}
+
+static inline unsigned int
+topology_num_threads_per_package(void)
+{
+ return (mp_ncpus);
+}
+#endif
+
+#endif /* _LINUXKPI_ASM_TOPOLOGY_H_ */
diff --git a/sys/compat/linuxkpi/common/include/asm/types.h b/sys/compat/linuxkpi/common/include/asm/types.h
index daa5d83616a2..2e61bcfdb5e6 100644
--- a/sys/compat/linuxkpi/common/include/asm/types.h
+++ b/sys/compat/linuxkpi/common/include/asm/types.h
@@ -25,11 +25,9 @@
* 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.
- *
- * $FreeBSD$
*/
-#ifndef _ASM_TYPES_H_
-#define _ASM_TYPES_H_
+#ifndef _LINUXKPI_ASM_TYPES_H_
+#define _LINUXKPI_ASM_TYPES_H_
#if defined(_KERNEL) || defined(_STANDALONE)
@@ -61,4 +59,4 @@ typedef unsigned short umode_t;
#endif /* _KERNEL || _STANDALONE */
-#endif /* _ASM_TYPES_H_ */
+#endif /* _LINUXKPI_ASM_TYPES_H_ */
diff --git a/sys/compat/linuxkpi/common/include/asm/uaccess.h b/sys/compat/linuxkpi/common/include/asm/uaccess.h
index 102373634ba3..94354f8ddeee 100644
--- a/sys/compat/linuxkpi/common/include/asm/uaccess.h
+++ b/sys/compat/linuxkpi/common/include/asm/uaccess.h
@@ -25,11 +25,9 @@
* 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.
- *
- * $FreeBSD$
*/
-#ifndef _ASM_UACCESS_H_
-#define _ASM_UACCESS_H_
+#ifndef _LINUXKPI_ASM_UACCESS_H_
+#define _LINUXKPI_ASM_UACCESS_H_
#include <linux/uaccess.h>
@@ -55,6 +53,9 @@ copy_from_user(void *to, const void *from, unsigned long n)
#define user_access_begin(ptr, len) access_ok(ptr, len)
#define user_access_end() do { } while (0)
+#define user_write_access_begin(ptr, len) access_ok(ptr, len)
+#define user_write_access_end() do { } while (0)
+
#define unsafe_get_user(x, ptr, err) do { \
if (unlikely(__get_user(x, ptr))) \
goto err; \
@@ -65,4 +66,4 @@ copy_from_user(void *to, const void *from, unsigned long n)
goto err; \
} while (0)
-#endif /* _ASM_UACCESS_H_ */
+#endif /* _LINUXKPI_ASM_UACCESS_H_ */
diff --git a/sys/compat/linuxkpi/common/include/asm/unaligned.h b/sys/compat/linuxkpi/common/include/asm/unaligned.h
index 7597f00f7596..e45846a3b543 100644
--- a/sys/compat/linuxkpi/common/include/asm/unaligned.h
+++ b/sys/compat/linuxkpi/common/include/asm/unaligned.h
@@ -1,7 +1,7 @@
/*-
* SPDX-License-Identifier: BSD-2-Clause
*
- * Copyright (c) 2020 The FreeBSD Foundation
+ * Copyright (c) 2020,2023 The FreeBSD Foundation
*
* This software was developed by Björn Zeeb under sponsorship from
* the FreeBSD Foundation.
@@ -26,16 +26,21 @@
* 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.
- *
- * $FreeBSD$
*/
-#ifndef _ASM_UNALIGNED_H
-#define _ASM_UNALIGNED_H
+#ifndef _LINUXKPI_ASM_UNALIGNED_H
+#define _LINUXKPI_ASM_UNALIGNED_H
#include <linux/types.h>
#include <asm/byteorder.h>
+static __inline uint16_t
+get_unaligned_le16(const void *p)
+{
+
+ return (le16_to_cpup((const __le16 *)p));
+}
+
static __inline uint32_t
get_unaligned_le32(const void *p)
{
@@ -44,6 +49,15 @@ get_unaligned_le32(const void *p)
}
static __inline void
+put_unaligned_le16(__le16 v, void *p)
+{
+ __le16 x;
+
+ x = cpu_to_le16(v);
+ memcpy(p, &x, sizeof(x));
+}
+
+static __inline void
put_unaligned_le32(__le32 v, void *p)
{
__le32 x;
@@ -75,4 +89,11 @@ get_unaligned_be32(const void *p)
return (be32_to_cpup((const __be32 *)p));
}
-#endif /* _ASM_UNALIGNED_H */
+static __inline uint64_t
+get_unaligned_be64(const void *p)
+{
+
+ return (be64_to_cpup((const __be64 *)p));
+}
+
+#endif /* _LINUXKPI_ASM_UNALIGNED_H */
diff --git a/sys/compat/linuxkpi/common/include/crypto/hash.h b/sys/compat/linuxkpi/common/include/crypto/hash.h
new file mode 100644
index 000000000000..bf401691722a
--- /dev/null
+++ b/sys/compat/linuxkpi/common/include/crypto/hash.h
@@ -0,0 +1,94 @@
+/*-
+ * SPDX-License-Identifier: BSD-2-Clause
+ *
+ * Copyright (c) 2022 Bjoern A. Zeeb
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``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 OR CONTRIBUTORS 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.
+ */
+
+#ifndef _LINUXKPI_CRYPTO_HASH_H
+#define _LINUXKPI_CRYPTO_HASH_H
+
+#include <linux/kernel.h> /* for pr_debug */
+
+struct crypto_shash {
+};
+
+struct shash_desc {
+ struct crypto_shash *tfm;
+};
+
+static inline struct crypto_shash *
+crypto_alloc_shash(const char *algostr, int x, int y)
+{
+
+ pr_debug("%s: TODO\n", __func__);
+ return (NULL);
+}
+
+static inline void
+crypto_free_shash(struct crypto_shash *csh)
+{
+ pr_debug("%s: TODO\n", __func__);
+}
+
+static inline int
+crypto_shash_init(struct shash_desc *desc)
+{
+ pr_debug("%s: TODO\n", __func__);
+ return (-ENXIO);
+}
+
+static inline int
+crypto_shash_final(struct shash_desc *desc, uint8_t *mic)
+{
+ pr_debug("%s: TODO\n", __func__);
+ return (-ENXIO);
+}
+
+static inline int
+crypto_shash_setkey(struct crypto_shash *csh, const uint8_t *key, size_t keylen)
+{
+ pr_debug("%s: TODO\n", __func__);
+ return (-ENXIO);
+}
+
+static inline int
+crypto_shash_update(struct shash_desc *desc, uint8_t *data, size_t datalen)
+{
+ pr_debug("%s: TODO\n", __func__);
+ return (-ENXIO);
+}
+
+static inline void
+shash_desc_zero(struct shash_desc *desc)
+{
+
+ explicit_bzero(desc, sizeof(*desc));
+}
+
+/* XXX review this. */
+#define SHASH_DESC_ON_STACK(desc, tfm) \
+ uint8_t ___ ## desc ## _desc[sizeof(struct shash_desc)]; \
+ struct shash_desc *desc = (struct shash_desc *)___ ## desc ## _desc
+
+#endif /* _LINUXKPI_CRYPTO_HASH_H */
diff --git a/sys/compat/linuxkpi/common/include/kunit/static_stub.h b/sys/compat/linuxkpi/common/include/kunit/static_stub.h
new file mode 100644
index 000000000000..9d425d46dbb0
--- /dev/null
+++ b/sys/compat/linuxkpi/common/include/kunit/static_stub.h
@@ -0,0 +1,15 @@
+/*
+ * Copyright (c) 2025 The FreeBSD Foundation
+ *
+ * This software was developed by Björn Zeeb under sponsorship from
+ * the FreeBSD Foundation.
+ *
+ * SPDX-License-Identifier: BSD-2-Clause
+ */
+
+#ifndef _LINUXKPI_KUNIT_STATIC_STUB_H
+#define _LINUXKPI_KUNIT_STATIC_STUB_H
+
+#define KUNIT_STATIC_STUB_REDIRECT(_fn, ...) do { } while(0)
+
+#endif /* _LINUXKPI_KUNIT_STATIC_STUB_H */
diff --git a/sys/compat/linuxkpi/common/include/linux/acpi.h b/sys/compat/linuxkpi/common/include/linux/acpi.h
index b1e65b9afad9..3e1ec1b20626 100644
--- a/sys/compat/linuxkpi/common/include/linux/acpi.h
+++ b/sys/compat/linuxkpi/common/include/linux/acpi.h
@@ -1,5 +1,5 @@
/*-
- * SPDX-License-Identifier: BSD-2-Clause-FreeBSD
+ * SPDX-License-Identifier: BSD-2-Clause
*
* Copyright (c) 2020 Vladimir Kondratyev <wulf@FreeBSD.org>
*
@@ -24,12 +24,10 @@
* 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.
- *
- * $FreeBSD$
*/
-#ifndef _LINUX_ACPI_H_
-#define _LINUX_ACPI_H_
+#ifndef _LINUXKPI_LINUX_ACPI_H_
+#define _LINUXKPI_LINUX_ACPI_H_
#include <linux/device.h>
#include <linux/uuid.h>
@@ -41,7 +39,11 @@
#define ACPI_HANDLE(dev) \
((dev)->bsddev != NULL ? bsd_acpi_get_handle((dev)->bsddev) : NULL)
+#define acpi_device_handle(dev) \
+ ((dev) != NULL ? bsd_acpi_get_handle(dev) : NULL)
+static inline void acpi_dev_put(struct acpi_device *adev) {}
+#define acpi_handle_debug(handle, fmt, ...)
#endif
-#endif /* _LINUX_ACPI_H_ */
+#endif /* _LINUXKPI_LINUX_ACPI_H_ */
diff --git a/sys/compat/linuxkpi/common/include/linux/acpi_amd_wbrf.h b/sys/compat/linuxkpi/common/include/linux/acpi_amd_wbrf.h
new file mode 100644
index 000000000000..92c2ead41c45
--- /dev/null
+++ b/sys/compat/linuxkpi/common/include/linux/acpi_amd_wbrf.h
@@ -0,0 +1,97 @@
+/*-
+ * Copyright (c) 2025 The FreeBSD Foundation
+ * Copyright (c) 2025 Jean-Sébastien Pédron
+ *
+ * This software was developed by Jean-Sébastien Pédron under sponsorship
+ * from the FreeBSD Foundation.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``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 OR CONTRIBUTORS 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.
+ */
+
+#ifndef _LINUXKPI_LINUX_ACPI_AMD_WBRF_H_
+#define _LINUXKPI_LINUX_ACPI_AMD_WBRF_H_
+
+#include <linux/device.h>
+#include <linux/notifier.h>
+
+#define MAX_NUM_OF_WBRF_RANGES 11
+
+#define WBRF_RECORD_ADD 0x0
+#define WBRF_RECORD_REMOVE 0x1
+
+struct freq_band_range {
+ uint64_t start;
+ uint64_t end;
+};
+
+struct wbrf_ranges_in_out {
+ uint64_t num_of_ranges;
+ struct freq_band_range band_list[MAX_NUM_OF_WBRF_RANGES];
+};
+
+enum wbrf_notifier_actions {
+ WBRF_CHANGED,
+};
+
+/*
+ * The following functions currently have dummy implementations that, on Linux,
+ * are used when CONFIG_AMD_WBRF is not set at compile time.
+ */
+
+static inline bool
+acpi_amd_wbrf_supported_consumer(struct device *dev)
+{
+ return (false);
+}
+
+static inline int
+acpi_amd_wbrf_add_remove(struct device *dev, uint8_t action,
+ struct wbrf_ranges_in_out *in)
+{
+ return (-ENODEV);
+}
+
+static inline bool
+acpi_amd_wbrf_supported_producer(struct device *dev)
+{
+ return (false);
+}
+
+static inline int
+amd_wbrf_retrieve_freq_band(struct device *dev, struct wbrf_ranges_in_out *out)
+{
+ return (-ENODEV);
+}
+
+static inline int
+amd_wbrf_register_notifier(struct notifier_block *nb)
+{
+ return (-ENODEV);
+}
+
+static inline int
+amd_wbrf_unregister_notifier(struct notifier_block *nb)
+{
+ return (-ENODEV);
+}
+
+#endif /* _LINUXKPI_LINUX_ACPI_AMD_WBRF_H_ */
diff --git a/sys/compat/linuxkpi/common/include/linux/agp_backend.h b/sys/compat/linuxkpi/common/include/linux/agp_backend.h
new file mode 100644
index 000000000000..c855fd842970
--- /dev/null
+++ b/sys/compat/linuxkpi/common/include/linux/agp_backend.h
@@ -0,0 +1,28 @@
+/* Public domain */
+
+#ifndef _LINUXKPI_LINUX_AGP_BACKEND_H_
+#define _LINUXKPI_LINUX_AGP_BACKEND_H_
+
+#include <sys/types.h>
+
+struct agp_version {
+ uint16_t major;
+ uint16_t minor;
+};
+
+struct agp_kern_info {
+ struct agp_version version;
+ uint16_t vendor;
+ uint16_t device;
+ unsigned long mode;
+ unsigned long aper_base;
+ size_t aper_size;
+ int max_memory;
+ int current_memory;
+ bool cant_use_aperture;
+ unsigned long page_mask;
+};
+
+struct agp_memory;
+
+#endif /* _LINUXKPI_LINUX_AGP_BACKEND_H_ */
diff --git a/sys/compat/linuxkpi/common/include/linux/anon_inodes.h b/sys/compat/linuxkpi/common/include/linux/anon_inodes.h
index 8fa61cd4b45f..c69f6e152b17 100644
--- a/sys/compat/linuxkpi/common/include/linux/anon_inodes.h
+++ b/sys/compat/linuxkpi/common/include/linux/anon_inodes.h
@@ -1,5 +1,5 @@
/*-
- * SPDX-License-Identifier: BSD-2-Clause-FreeBSD
+ * SPDX-License-Identifier: BSD-2-Clause
*
* Copyright (c) 2021 Vladimir Kondratyev <wulf@FreeBSD.org>
*
@@ -26,8 +26,8 @@
* SUCH DAMAGE.
*/
-#ifndef _LINUX_ANON_INODES_H_
-#define _LINUX_ANON_INODES_H_
+#ifndef _LINUXKPI_LINUX_ANON_INODES_H_
+#define _LINUXKPI_LINUX_ANON_INODES_H_
#include <linux/fs.h>
#include <linux/file.h>
@@ -45,4 +45,4 @@ anon_inode_getfile(const char *name __unused,
return (file);
}
-#endif /* _LINUX_ANON_INODES_H_ */
+#endif /* _LINUXKPI_LINUX_ANON_INODES_H_ */
diff --git a/sys/compat/linuxkpi/common/include/linux/aperture.h b/sys/compat/linuxkpi/common/include/linux/aperture.h
new file mode 100644
index 000000000000..7eced3cc3cb1
--- /dev/null
+++ b/sys/compat/linuxkpi/common/include/linux/aperture.h
@@ -0,0 +1,64 @@
+/* SPDX-License-Identifier: MIT */
+
+#ifndef _LINUX_APERTURE_H_
+#define _LINUX_APERTURE_H_
+
+#include <linux/types.h>
+
+#define CONFIG_APERTURE_HELPERS
+
+struct pci_dev;
+struct platform_device;
+
+#if defined(CONFIG_APERTURE_HELPERS)
+int devm_aperture_acquire_for_platform_device(struct platform_device *pdev,
+ resource_size_t base,
+ resource_size_t size);
+
+int aperture_remove_conflicting_devices(resource_size_t base, resource_size_t size,
+ const char *name);
+
+int __aperture_remove_legacy_vga_devices(struct pci_dev *pdev);
+
+int aperture_remove_conflicting_pci_devices(struct pci_dev *pdev, const char *name);
+#else
+static inline int devm_aperture_acquire_for_platform_device(struct platform_device *pdev,
+ resource_size_t base,
+ resource_size_t size)
+{
+ return 0;
+}
+
+static inline int aperture_remove_conflicting_devices(resource_size_t base, resource_size_t size,
+ const char *name)
+{
+ return 0;
+}
+
+static inline int __aperture_remove_legacy_vga_devices(struct pci_dev *pdev)
+{
+ return 0;
+}
+
+static inline int aperture_remove_conflicting_pci_devices(struct pci_dev *pdev, const char *name)
+{
+ return 0;
+}
+#endif
+
+/**
+ * aperture_remove_all_conflicting_devices - remove all existing framebuffers
+ * @name: a descriptive name of the requesting driver
+ *
+ * This function removes all graphics device drivers. Use this function on systems
+ * that can have their framebuffer located anywhere in memory.
+ *
+ * Returns:
+ * 0 on success, or a negative errno code otherwise
+ */
+static inline int aperture_remove_all_conflicting_devices(const char *name)
+{
+ return aperture_remove_conflicting_devices(0, (resource_size_t)-1, name);
+}
+
+#endif
diff --git a/sys/compat/linuxkpi/common/include/linux/apple-gmux.h b/sys/compat/linuxkpi/common/include/linux/apple-gmux.h
new file mode 100644
index 000000000000..812a782c57d4
--- /dev/null
+++ b/sys/compat/linuxkpi/common/include/linux/apple-gmux.h
@@ -0,0 +1,12 @@
+/* Public domain. */
+
+#ifndef _LINUXKPI_LINUX_APPLE_GMUX_H
+#define _LINUXKPI_LINUX_APPLE_GMUX_H
+
+static inline bool
+apple_gmux_detect(void *a, void *b)
+{
+ return false;
+}
+
+#endif
diff --git a/sys/compat/linuxkpi/common/include/linux/atomic.h b/sys/compat/linuxkpi/common/include/linux/atomic.h
index f8aa5c9276e7..bc76928a7d67 100644
--- a/sys/compat/linuxkpi/common/include/linux/atomic.h
+++ b/sys/compat/linuxkpi/common/include/linux/atomic.h
@@ -22,15 +22,14 @@
* 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.
- *
- * $FreeBSD$
*/
-#ifndef _LINUX_ATOMIC_H_
-#define _LINUX_ATOMIC_H_
+#ifndef _LINUXKPI_LINUX_ATOMIC_H_
+#define _LINUXKPI_LINUX_ATOMIC_H_
#include <asm/atomic.h>
#include <asm/atomic64.h>
#include <asm/atomic-long.h>
+#include <asm/barrier.h>
-#endif /* _LINUX_ATOMIC_H_ */
+#endif /* _LINUXKPI_LINUX_ATOMIC_H_ */
diff --git a/sys/compat/linuxkpi/common/include/linux/average.h b/sys/compat/linuxkpi/common/include/linux/average.h
index 4291bf2d85be..4191a351c5c6 100644
--- a/sys/compat/linuxkpi/common/include/linux/average.h
+++ b/sys/compat/linuxkpi/common/include/linux/average.h
@@ -26,12 +26,10 @@
* 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.
- *
- * $FreeBSD$
*/
-#ifndef __LKPI_LINUX_AVERAGE_H
-#define __LKPI_LINUX_AVERAGE_H
+#ifndef _LINUXKPI_LINUX_AVERAGE_H
+#define _LINUXKPI_LINUX_AVERAGE_H
#include <sys/param.h>
#include <sys/systm.h>
@@ -89,4 +87,4 @@
return (ewma->zt >> (_p)); \
} \
-#endif /* __LKPI_LINUX_AVERAGE_H */
+#endif /* _LINUXKPI_LINUX_AVERAGE_H */
diff --git a/sys/compat/linuxkpi/common/include/linux/backlight.h b/sys/compat/linuxkpi/common/include/linux/backlight.h
index b3a07c4cdcaa..4f8f7440925a 100644
--- a/sys/compat/linuxkpi/common/include/linux/backlight.h
+++ b/sys/compat/linuxkpi/common/include/linux/backlight.h
@@ -24,12 +24,10 @@
* 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.
- *
- * $FreeBSD$
*/
-#ifndef _LINUX_BACKLIGHT_H_
-#define _LINUX_BACKLIGHT_H_
+#ifndef _LINUXKPI_LINUX_BACKLIGHT_H_
+#define _LINUXKPI_LINUX_BACKLIGHT_H_
#include <linux/notifier.h>
@@ -92,6 +90,23 @@ backlight_force_update(struct backlight_device *bd, int reason)
}
static inline int
+backlight_get_brightness(struct backlight_device *bd)
+{
+
+ return (bd->props.brightness);
+}
+
+static inline int
+backlight_device_set_brightness(struct backlight_device *bd, int brightness)
+{
+
+ if (brightness > bd->props.max_brightness)
+ return (EINVAL);
+ bd->props.brightness = brightness;
+ return (bd->ops->update_status(bd));
+}
+
+static inline int
backlight_enable(struct backlight_device *bd)
{
if (bd == NULL)
@@ -109,4 +124,11 @@ backlight_disable(struct backlight_device *bd)
return (backlight_update_status(bd));
}
-#endif /* _LINUX_BACKLIGHT_H_ */
+static inline bool
+backlight_is_blank(struct backlight_device *bd)
+{
+
+ return (bd->props.power != 0/* FB_BLANK_UNBLANK */);
+}
+
+#endif /* _LINUXKPI_LINUX_BACKLIGHT_H_ */
diff --git a/sys/compat/linuxkpi/common/include/linux/bcd.h b/sys/compat/linuxkpi/common/include/linux/bcd.h
index 8a40da1a330b..385819910454 100644
--- a/sys/compat/linuxkpi/common/include/linux/bcd.h
+++ b/sys/compat/linuxkpi/common/include/linux/bcd.h
@@ -23,8 +23,6 @@
* 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.
- *
- * $FreeBSD$
*/
#ifndef _LINUXKPI_LINUX_BCD_H
diff --git a/sys/compat/linuxkpi/common/include/linux/bitfield.h b/sys/compat/linuxkpi/common/include/linux/bitfield.h
index a805c1bca5a1..8a91b0663f37 100644
--- a/sys/compat/linuxkpi/common/include/linux/bitfield.h
+++ b/sys/compat/linuxkpi/common/include/linux/bitfield.h
@@ -1,7 +1,7 @@
/*-
* SPDX-License-Identifier: BSD-2-Clause
*
- * Copyright (c) 2020 The FreeBSD Foundation
+ * Copyright (c) 2020-2024 The FreeBSD Foundation
*
* This software was developed by Björn Zeeb under sponsorship from
* the FreeBSD Foundation.
@@ -26,12 +26,10 @@
* 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.
- *
- * $FreeBSD$
*/
-#ifndef _LINUX_BITFIELD_H
-#define _LINUX_BITFIELD_H
+#ifndef _LINUXKPI_LINUX_BITFIELD_H
+#define _LINUXKPI_LINUX_BITFIELD_H
#include <linux/types.h>
#include <asm/byteorder.h>
@@ -86,19 +84,58 @@ _leX_encode_bits(64)
_leX_encode_bits(32)
_leX_encode_bits(16)
-static __inline void
-le32p_replace_bits(uint32_t *p, uint32_t v, uint32_t f)
-{
+#define _leXp_replace_bits(_n) \
+ static __inline void \
+ le ## _n ## p_replace_bits(uint ## _n ## _t *p, \
+ uint ## _n ## _t v, uint ## _n ## _t f) \
+ { \
+ *p = (*p & ~(cpu_to_le ## _n(f))) | \
+ le ## _n ## _encode_bits(v, f); \
+ }
+
+_leXp_replace_bits(64)
+_leXp_replace_bits(32)
+_leXp_replace_bits(16)
- *p = (*p & ~(cpu_to_le32(f))) | le32_encode_bits(v, f);
-}
+#define _uXp_replace_bits(_n) \
+ static __inline void \
+ u ## _n ## p_replace_bits(uint ## _n ## _t *p, \
+ uint ## _n ## _t v, uint ## _n ## _t f) \
+ { \
+ *p = (*p & ~f) | u ## _n ## _encode_bits(v, f); \
+ }
+
+_uXp_replace_bits(64)
+_uXp_replace_bits(32)
+_uXp_replace_bits(16)
+_uXp_replace_bits(8)
+
+#define _uX_replace_bits(_n) \
+ static __inline uint ## _n ## _t \
+ u ## _n ## _replace_bits(uint ## _n ## _t p, \
+ uint ## _n ## _t v, uint ## _n ## _t f) \
+ { \
+ return ((p & ~f) | u ## _n ## _encode_bits(v, f)); \
+ }
+
+_uX_replace_bits(64)
+_uX_replace_bits(32)
+_uX_replace_bits(16)
+_uX_replace_bits(8)
#define __bf_shf(x) (__builtin_ffsll(x) - 1)
+#define FIELD_FIT(_mask, _value) \
+ (!(((typeof(_mask))(_value) << __bf_shf(_mask)) & ~(_mask)))
+
#define FIELD_PREP(_mask, _value) \
(((typeof(_mask))(_value) << __bf_shf(_mask)) & (_mask))
+/* Likely would need extra sanity checks compared to FIELD_PREP()? */
+#define FIELD_PREP_CONST(_mask, _value) \
+ (((typeof(_mask))(_value) << __bf_shf(_mask)) & (_mask))
+
#define FIELD_GET(_mask, _value) \
((typeof(_mask))(((_value) & (_mask)) >> __bf_shf(_mask)))
-#endif /* _LINUX_BITFIELD_H */
+#endif /* _LINUXKPI_LINUX_BITFIELD_H */
diff --git a/sys/compat/linuxkpi/common/include/linux/bitmap.h b/sys/compat/linuxkpi/common/include/linux/bitmap.h
index 4de94333c99f..f26a0f99dc03 100644
--- a/sys/compat/linuxkpi/common/include/linux/bitmap.h
+++ b/sys/compat/linuxkpi/common/include/linux/bitmap.h
@@ -22,12 +22,10 @@
* 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.
- *
- * $FreeBSD$
*/
-#ifndef _LINUX_BITMAP_H_
-#define _LINUX_BITMAP_H_
+#ifndef _LINUXKPI_LINUX_BITMAP_H_
+#define _LINUXKPI_LINUX_BITMAP_H_
#include <linux/bitops.h>
#include <linux/slab.h>
@@ -266,6 +264,27 @@ bitmap_subset(const unsigned long *pa,
return (1);
}
+static inline bool
+bitmap_intersects(const unsigned long *pa, const unsigned long *pb,
+ unsigned size)
+{
+ const unsigned end = BIT_WORD(size);
+ const unsigned tail = size & (BITS_PER_LONG - 1);
+ unsigned i;
+
+ for (i = 0; i != end; i++)
+ if (pa[i] & pb[i])
+ return (true);
+
+ if (tail) {
+ const unsigned long mask = BITMAP_LAST_WORD_MASK(tail);
+
+ if (pa[end] & pb[end] & mask)
+ return (true);
+ }
+ return (false);
+}
+
static inline void
bitmap_complement(unsigned long *dst, const unsigned long *src,
const unsigned int size)
@@ -289,6 +308,49 @@ bitmap_copy(unsigned long *dst, const unsigned long *src,
}
static inline void
+bitmap_to_arr32(uint32_t *dst, const unsigned long *src, unsigned int size)
+{
+ const unsigned int end = howmany(size, 32);
+
+#ifdef __LP64__
+ unsigned int i = 0;
+ while (i < end) {
+ dst[i++] = (uint32_t)(*src & UINT_MAX);
+ if (i < end)
+ dst[i++] = (uint32_t)(*src >> 32);
+ src++;
+ }
+#else
+ bitmap_copy((unsigned long *)dst, src, size);
+#endif
+ if ((size % 32) != 0) /* Linux uses BITS_PER_LONG. Seems to be a bug */
+ dst[end - 1] &= (uint32_t)(UINT_MAX >> (32 - (size % 32)));
+}
+
+static inline void
+bitmap_from_arr32(unsigned long *dst, const uint32_t *src,
+ unsigned int size)
+{
+ const unsigned int end = BIT_WORD(size);
+ const unsigned int tail = size & (BITS_PER_LONG - 1);
+
+#ifdef __LP64__
+ const unsigned int end32 = howmany(size, 32);
+ unsigned int i = 0;
+
+ while (i < end32) {
+ dst[i++/2] = (unsigned long) *(src++);
+ if (i < end32)
+ dst[i++/2] |= ((unsigned long) *(src++)) << 32;
+ }
+#else
+ bitmap_copy(dst, (const unsigned long *)src, size);
+#endif
+ if ((size % BITS_PER_LONG) != 0)
+ dst[end] &= BITMAP_LAST_WORD_MASK(tail);
+}
+
+static inline void
bitmap_or(unsigned long *dst, const unsigned long *src1,
const unsigned long *src2, const unsigned int size)
{
@@ -332,6 +394,40 @@ bitmap_xor(unsigned long *dst, const unsigned long *src1,
dst[i] = src1[i] ^ src2[i];
}
+static inline void
+bitmap_shift_right(unsigned long *dst, const unsigned long *src,
+ unsigned int shift, unsigned int size)
+{
+ const unsigned int end = BITS_TO_LONGS(size);
+ const unsigned int tail = size & (BITS_PER_LONG - 1);
+ const unsigned long mask = BITMAP_LAST_WORD_MASK(tail);
+ const unsigned int off = BIT_WORD(shift);
+ const unsigned int rem = shift & (BITS_PER_LONG - 1);
+ unsigned long left, right;
+ unsigned int i, srcpos;
+
+ for (i = 0, srcpos = off; srcpos < end; i++, srcpos++) {
+ right = src[srcpos];
+ left = 0;
+
+ if (srcpos == end - 1)
+ right &= mask;
+
+ if (rem != 0) {
+ right >>= rem;
+ if (srcpos + 1 < end) {
+ left = src[srcpos + 1];
+ if (srcpos + 1 == end - 1)
+ left &= mask;
+ left <<= (BITS_PER_LONG - rem);
+ }
+ }
+ dst[i] = left | right;
+ }
+ if (off != 0)
+ memset(dst + end - off, 0, off * sizeof(unsigned long));
+}
+
static inline unsigned long *
bitmap_alloc(unsigned int size, gfp_t flags)
{
@@ -351,4 +447,4 @@ bitmap_free(const unsigned long *bitmap)
kfree(bitmap);
}
-#endif /* _LINUX_BITMAP_H_ */
+#endif /* _LINUXKPI_LINUX_BITMAP_H_ */
diff --git a/sys/compat/linuxkpi/common/include/linux/bitops.h b/sys/compat/linuxkpi/common/include/linux/bitops.h
index 0d7ab376e02d..a5a7abd55287 100644
--- a/sys/compat/linuxkpi/common/include/linux/bitops.h
+++ b/sys/compat/linuxkpi/common/include/linux/bitops.h
@@ -25,11 +25,9 @@
* 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.
- *
- * $FreeBSD$
*/
-#ifndef _LINUX_BITOPS_H_
-#define _LINUX_BITOPS_H_
+#ifndef _LINUXKPI_LINUX_BITOPS_H_
+#define _LINUXKPI_LINUX_BITOPS_H_
#include <sys/param.h>
#include <sys/types.h>
@@ -39,13 +37,8 @@
#define BIT(nr) (1UL << (nr))
#define BIT_ULL(nr) (1ULL << (nr))
-#ifdef __LP64__
-#define BITS_PER_LONG 64
-#else
-#define BITS_PER_LONG 32
-#endif
-
-#define BITS_PER_LONG_LONG 64
+#define BITS_PER_LONG (__SIZEOF_LONG__ * __CHAR_BIT__)
+#define BITS_PER_LONG_LONG (__SIZEOF_LONG_LONG__ * __CHAR_BIT__)
#define BITMAP_FIRST_WORD_MASK(start) (~0UL << ((start) % BITS_PER_LONG))
#define BITMAP_LAST_WORD_MASK(n) (~0UL >> (BITS_PER_LONG - (n)))
@@ -56,6 +49,7 @@
#define GENMASK_ULL(h, l) (((~0ULL) >> (BITS_PER_LONG_LONG - (h) - 1)) & ((~0ULL) << (l)))
#define BITS_PER_BYTE 8
#define BITS_PER_TYPE(t) (sizeof(t) * BITS_PER_BYTE)
+#define BITS_TO_BYTES(n) howmany((n), BITS_PER_BYTE)
#define hweight8(x) bitcount((uint8_t)(x))
#define hweight16(x) bitcount16(x)
@@ -63,10 +57,10 @@
#define hweight64(x) bitcount64(x)
#define hweight_long(x) bitcountl(x)
-#define HWEIGHT8(x) (bitcount8((uint8_t)(x)) + 1)
-#define HWEIGHT16(x) (bitcount16(x) + 1)
-#define HWEIGHT32(x) (bitcount32(x) + 1)
-#define HWEIGHT64(x) (bitcount64(x) + 1)
+#define HWEIGHT8(x) (__builtin_popcountg((uint8_t)(x)))
+#define HWEIGHT16(x) (__builtin_popcountg((uint16_t)(x)))
+#define HWEIGHT32(x) (__builtin_popcountg((uint32_t)(x)))
+#define HWEIGHT64(x) (__builtin_popcountg((uint64_t)(x)))
static inline int
__ffs(int mask)
@@ -86,6 +80,12 @@ __ffsl(long mask)
return (ffsl(mask) - 1);
}
+static inline unsigned long
+__ffs64(uint64_t mask)
+{
+ return (ffsll(mask) - 1);
+}
+
static inline int
__flsl(long mask)
{
@@ -283,6 +283,15 @@ find_next_zero_bit(const unsigned long *addr, unsigned long size,
#define test_bit(i, a) \
!!(READ_ONCE(((volatile const unsigned long *)(a))[BIT_WORD(i)]) & BIT_MASK(i))
+static inline void
+__assign_bit(long bit, volatile unsigned long *addr, bool value)
+{
+ if (value)
+ __set_bit(bit, addr);
+ else
+ __clear_bit(bit, addr);
+}
+
static inline int
test_and_clear_bit(long bit, volatile unsigned long *var)
{
@@ -420,4 +429,4 @@ sign_extend32(uint32_t value, int index)
return ((int32_t)(value << shift) >> shift);
}
-#endif /* _LINUX_BITOPS_H_ */
+#endif /* _LINUXKPI_LINUX_BITOPS_H_ */
diff --git a/sys/compat/linuxkpi/common/include/linux/bottom_half.h b/sys/compat/linuxkpi/common/include/linux/bottom_half.h
index 9f8dc02f2798..12b170845cbc 100644
--- a/sys/compat/linuxkpi/common/include/linux/bottom_half.h
+++ b/sys/compat/linuxkpi/common/include/linux/bottom_half.h
@@ -22,13 +22,11 @@
* 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.
- *
- * $FreeBSD$
*/
-#ifndef _LINUX_BOTTOM_HALF_H_
-#define _LINUX_BOTTOM_HALF_H_
+#ifndef _LINUXKPI_LINUX_BOTTOM_HALF_H_
+#define _LINUXKPI_LINUX_BOTTOM_HALF_H_
extern void local_bh_enable(void);
extern void local_bh_disable(void);
-#endif /* _LINUX_BOTTOM_HALF_H_ */
+#endif /* _LINUXKPI_LINUX_BOTTOM_HALF_H_ */
diff --git a/sys/compat/linuxkpi/common/include/linux/bsearch.h b/sys/compat/linuxkpi/common/include/linux/bsearch.h
index b8cf7b19b467..fb67109e4bba 100644
--- a/sys/compat/linuxkpi/common/include/linux/bsearch.h
+++ b/sys/compat/linuxkpi/common/include/linux/bsearch.h
@@ -26,13 +26,11 @@
* 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.
- *
- * $FreeBSD$
*/
-#ifndef __LKPI_LINUX_BSEARCH_H
-#define __LKPI_LINUX_BSEARCH_H
+#ifndef _LINUXKPI_LINUX_BSEARCH_H
+#define _LINUXKPI_LINUX_BSEARCH_H
#include <sys/libkern.h>
-#endif /* __LKPI_LINUX_BSEARCH_H */
+#endif /* _LINUXKPI_LINUX_BSEARCH_H */
diff --git a/sys/compat/linuxkpi/common/include/linux/build_bug.h b/sys/compat/linuxkpi/common/include/linux/build_bug.h
new file mode 100644
index 000000000000..6a026376cfc8
--- /dev/null
+++ b/sys/compat/linuxkpi/common/include/linux/build_bug.h
@@ -0,0 +1,65 @@
+/*-
+ * Copyright (c) 2017 Mark Johnston <markj@FreeBSD.org>
+ * Copyright (c) 2018 Johannes Lundberg <johalun0@gmail.com>
+ * Copyright (c) 2021 The FreeBSD Foundation
+ * Copyright (c) 2021 Vladimir Kondratyev <wulf@FreeBSD.org>
+ * Copyright (c) 2023 Serenity Cyber Security, LLC
+ *
+ * Portions of this software were developed by Bjoern A. Zeeb
+ * under sponsorship from the FreeBSD Foundation.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice unmodified, this list of conditions, and the following
+ * disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``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.
+ */
+
+#ifndef _LINUXKPI_LINUX_BUILD_BUG_H_
+#define _LINUXKPI_LINUX_BUILD_BUG_H_
+
+#include <sys/param.h>
+
+#include <linux/compiler.h>
+
+/*
+ * BUILD_BUG_ON() can happen inside functions where _Static_assert() does not
+ * seem to work. Use old-schoold-ish CTASSERT from before commit
+ * a3085588a88fa58eb5b1eaae471999e1995a29cf but also make sure we do not
+ * end up with an unused typedef or variable. The compiler should optimise
+ * it away entirely.
+ */
+#define _O_CTASSERT(x) _O__CTASSERT(x, __LINE__)
+#define _O__CTASSERT(x, y) _O___CTASSERT(x, y)
+#define _O___CTASSERT(x, y) while (0) { \
+ typedef char __assert_line_ ## y[(x) ? 1 : -1]; \
+ __assert_line_ ## y _x __unused; \
+ _x[0] = '\0'; \
+}
+
+#define BUILD_BUG() do { CTASSERT(0); } while (0)
+#define BUILD_BUG_ON(x) do { _O_CTASSERT(!(x)) } while (0)
+#define BUILD_BUG_ON_MSG(x, msg) BUILD_BUG_ON(x)
+#define BUILD_BUG_ON_NOT_POWER_OF_2(x) BUILD_BUG_ON(!powerof2(x))
+#define BUILD_BUG_ON_INVALID(expr) while (0) { (void)(expr); }
+#define BUILD_BUG_ON_ZERO(x) ((int)sizeof(struct { int:-((x) != 0); }))
+
+#define static_assert(x, ...) __static_assert(x, ##__VA_ARGS__, #x)
+#define __static_assert(x, msg, ...) _Static_assert(x, msg)
+
+#endif
diff --git a/sys/compat/linuxkpi/common/include/linux/cache.h b/sys/compat/linuxkpi/common/include/linux/cache.h
index 4d1d400152ff..b02b28d08ea9 100644
--- a/sys/compat/linuxkpi/common/include/linux/cache.h
+++ b/sys/compat/linuxkpi/common/include/linux/cache.h
@@ -25,17 +25,16 @@
* 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.
- *
- * $FreeBSD$
*/
-#ifndef _LINUX_CACHE_H_
-#define _LINUX_CACHE_H_
+#ifndef _LINUXKPI_LINUX_CACHE_H_
+#define _LINUXKPI_LINUX_CACHE_H_
#include <sys/param.h>
#define cache_line_size() CACHE_LINE_SIZE
#define L1_CACHE_BYTES CACHE_LINE_SIZE
+#define L1_CACHE_ALIGN(x) ALIGN(x, CACHE_LINE_SIZE)
#define SMP_CACHE_BYTES L1_CACHE_BYTES
-#endif /* _LINUX_CACHE_H_ */
+#endif /* _LINUXKPI_LINUX_CACHE_H_ */
diff --git a/sys/compat/linuxkpi/common/include/linux/capability.h b/sys/compat/linuxkpi/common/include/linux/capability.h
new file mode 100644
index 000000000000..e3dacd4e9f15
--- /dev/null
+++ b/sys/compat/linuxkpi/common/include/linux/capability.h
@@ -0,0 +1,51 @@
+/*-
+ * SPDX-License-Identifier: BSD-2-Clause
+ *
+ * Copyright (c) 2015 Rimvydas Jasinskas
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice unmodified, this list of conditions, and the following
+ * disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``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.
+ */
+
+/*
+ * linux/capability.h
+ *
+ * Simple capable() priv_check helper
+ */
+
+#ifndef _LINUXKPI_LINUX_CAPABILITY_H
+#define _LINUXKPI_LINUX_CAPABILITY_H
+
+#include <sys/types.h>
+#include <sys/proc.h>
+#include <sys/priv.h>
+
+#define CAP_SYS_ADMIN PRIV_DRIVER
+#define CAP_SYS_NICE PRIV_SCHED_SETPRIORITY
+
+static inline bool
+capable(const int tryme)
+{
+ return (priv_check(curthread, tryme) == 0);
+}
+
+#endif /* _LINUXKPI_LINUX_CAPABILITY_H */
diff --git a/sys/compat/linuxkpi/common/include/linux/cc_platform.h b/sys/compat/linuxkpi/common/include/linux/cc_platform.h
new file mode 100644
index 000000000000..1544c141614b
--- /dev/null
+++ b/sys/compat/linuxkpi/common/include/linux/cc_platform.h
@@ -0,0 +1,21 @@
+/* Public domain. */
+
+#ifndef _LINUXKPI_LINUX_CC_PLATFORM_H_
+#define _LINUXKPI_LINUX_CC_PLATFORM_H_
+
+#include <linux/types.h>
+#include <linux/stddef.h>
+
+enum cc_attr {
+ CC_ATTR_MEM_ENCRYPT,
+ CC_ATTR_GUEST_MEM_ENCRYPT,
+};
+
+static inline bool
+cc_platform_has(enum cc_attr attr __unused)
+{
+
+ return (false);
+}
+
+#endif /* _LINUXKPI_LINUX_CC_PLATFORM_H_ */
diff --git a/sys/compat/linuxkpi/common/include/linux/cdev.h b/sys/compat/linuxkpi/common/include/linux/cdev.h
index 39a65472e921..d989db14c2f8 100644
--- a/sys/compat/linuxkpi/common/include/linux/cdev.h
+++ b/sys/compat/linuxkpi/common/include/linux/cdev.h
@@ -25,11 +25,9 @@
* 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.
- *
- * $FreeBSD$
*/
-#ifndef _LINUX_CDEV_H_
-#define _LINUX_CDEV_H_
+#ifndef _LINUXKPI_LINUX_CDEV_H_
+#define _LINUXKPI_LINUX_CDEV_H_
#include <linux/kobject.h>
#include <linux/sysfs.h>
@@ -57,6 +55,8 @@ struct linux_cdev {
u_int siref;
};
+struct linux_cdev *cdev_alloc(void);
+
static inline void
cdev_init(struct linux_cdev *cdev, const struct file_operations *ops)
{
@@ -66,17 +66,6 @@ cdev_init(struct linux_cdev *cdev, const struct file_operations *ops)
cdev->refs = 1;
}
-static inline struct linux_cdev *
-cdev_alloc(void)
-{
- struct linux_cdev *cdev;
-
- cdev = kzalloc(sizeof(struct linux_cdev), M_WAITOK);
- kobject_init(&cdev->kobj, &linux_cdev_ktype);
- cdev->refs = 1;
- return (cdev);
-}
-
static inline void
cdev_put(struct linux_cdev *p)
{
@@ -154,4 +143,4 @@ void linux_cdev_device_del(struct linux_cdev *, struct device *);
#define cdev linux_cdev
-#endif /* _LINUX_CDEV_H_ */
+#endif /* _LINUXKPI_LINUX_CDEV_H_ */
diff --git a/sys/compat/linuxkpi/common/include/linux/cec.h b/sys/compat/linuxkpi/common/include/linux/cec.h
new file mode 100644
index 000000000000..e0854d87d85c
--- /dev/null
+++ b/sys/compat/linuxkpi/common/include/linux/cec.h
@@ -0,0 +1,8 @@
+/* Public domain */
+
+#ifndef _LINUXKPI_LINUX_CEC_H_
+#define _LINUXKPI_LINUX_CEC_H_
+
+#define CEC_PHYS_ADDR_INVALID 0xffff
+
+#endif /* _LINUXKPI_LINUX_CEC_H_ */
diff --git a/sys/compat/linuxkpi/common/include/linux/cgroup.h b/sys/compat/linuxkpi/common/include/linux/cgroup.h
new file mode 100644
index 000000000000..a9dd22fd0f4c
--- /dev/null
+++ b/sys/compat/linuxkpi/common/include/linux/cgroup.h
@@ -0,0 +1,34 @@
+/*-
+ * SPDX-License-Identifier: BSD-2-Clause
+ *
+ * Copyright (c) 2025 Jean-Sébastien Pédron <dumbbell@FreeBSD.org>
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are
+ * met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in
+ * the documentation and/or other materials provided with the
+ * distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``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 OR CONTRIBUTORS 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.
+ */
+
+#ifndef _LINUXKPI_LINUX_CGROUP_H_
+#define _LINUXKPI_LINUX_CGROUP_H_
+
+#include <linux/kernel_stat.h>
+
+#endif /* _LINUXKPI_LINUX_CGROUP_H_ */
diff --git a/sys/compat/linuxkpi/common/include/linux/circ_buf.h b/sys/compat/linuxkpi/common/include/linux/circ_buf.h
new file mode 100644
index 000000000000..53d7fa736ef8
--- /dev/null
+++ b/sys/compat/linuxkpi/common/include/linux/circ_buf.h
@@ -0,0 +1,34 @@
+/*-
+ * Copyright (c) 2022 Beckhoff Automation GmbH & Co. KG
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``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 OR CONTRIBUTORS 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.
+ *
+ */
+
+#ifndef _LINUXKPI_LINUX_CIRC_BUF_H_
+#define _LINUXKPI_LINUX_CIRC_BUF_H_
+
+#define CIRC_CNT(head,tail,size) (((head) - (tail)) & ((size) - 1))
+#define CIRC_SPACE(head,tail,size) CIRC_CNT((tail),((head) + 1),(size))
+
+#endif /* _LINUXKPI_LINUX_CIRC_BUF_H_ */
+
diff --git a/sys/compat/linuxkpi/common/include/linux/cleanup.h b/sys/compat/linuxkpi/common/include/linux/cleanup.h
new file mode 100644
index 000000000000..5bb146f082ed
--- /dev/null
+++ b/sys/compat/linuxkpi/common/include/linux/cleanup.h
@@ -0,0 +1,93 @@
+/*-
+ * SPDX-License-Identifier: BSD-2-Clause
+ *
+ * Copyright (c) 2024-2025 The FreeBSD Foundation
+ *
+ * This software was developed by Björn Zeeb under sponsorship from
+ * the FreeBSD Foundation.
+ */
+
+#ifndef _LINUXKPI_LINUX_CLEANUP_H
+#define _LINUXKPI_LINUX_CLEANUP_H
+
+#define __cleanup(_f) __attribute__((__cleanup__(_f)))
+
+/*
+ * Note: "_T" are special as they are exposed into common code for
+ * statements. Extra care should be taken when changing the code.
+ */
+#define DEFINE_GUARD(_n, _dt, _lock, _unlock) \
+ \
+ typedef _dt guard_ ## _n ## _t; \
+ \
+ static inline _dt \
+ guard_ ## _n ## _create( _dt _T) \
+ { \
+ _dt c; \
+ \
+ c = ({ _lock; _T; }); \
+ return (c); \
+ } \
+ \
+ static inline void \
+ guard_ ## _n ## _destroy(_dt *t) \
+ { \
+ _dt _T; \
+ \
+ _T = *t; \
+ if (_T) { _unlock; }; \
+ }
+
+/* We need to keep these calls unique. */
+#define guard(_n) \
+ guard_ ## _n ## _t guard_ ## _n ## _ ## __COUNTER__ \
+ __cleanup(guard_ ## _n ## _destroy) = guard_ ## _n ## _create
+
+#define DEFINE_FREE(_n, _t, _f) \
+ static inline void \
+ __free_ ## _n(void *p) \
+ { \
+ _t _T; \
+ \
+ _T = *(_t *)p; \
+ _f; \
+ }
+
+#define __free(_n) __cleanup(__free_##_n)
+
+/*
+ * Given this is a _0 version it should likely be broken up into parts.
+ * But we have no idead what a _1, _2, ... version would do different
+ * until we see a call.
+ * This is used for a not-real-type (rcu). We use a bool to "simulate"
+ * the lock held. Also _T still special, may not always be used, so tag
+ * with __unused (or better the LinuxKPI __maybe_unused).
+ */
+#define DEFINE_LOCK_GUARD_0(_n, _lock, _unlock, ...) \
+ \
+ typedef struct { \
+ bool lock; \
+ __VA_ARGS__; \
+ } guard_ ## _n ## _t; \
+ \
+ static inline void \
+ guard_ ## _n ## _destroy(guard_ ## _n ## _t *_T) \
+ { \
+ if (_T->lock) { \
+ _unlock; \
+ } \
+ } \
+ \
+ static inline guard_ ## _n ## _t \
+ guard_ ## _n ## _create(void) \
+ { \
+ guard_ ## _n ## _t _tmp; \
+ guard_ ## _n ## _t *_T __maybe_unused; \
+ \
+ _tmp.lock = true; \
+ _T = &_tmp; \
+ _lock; \
+ return (_tmp); \
+ }
+
+#endif /* _LINUXKPI_LINUX_CLEANUP_H */
diff --git a/sys/compat/linuxkpi/common/include/linux/clocksource.h b/sys/compat/linuxkpi/common/include/linux/clocksource.h
index f775aa6bb329..3e7664c3e57e 100644
--- a/sys/compat/linuxkpi/common/include/linux/clocksource.h
+++ b/sys/compat/linuxkpi/common/include/linux/clocksource.h
@@ -25,14 +25,12 @@
* 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.
- *
- * $FreeBSD$
*/
-#ifndef _LINUX_CLOCKSOURCE_H
-#define _LINUX_CLOCKSOURCE_H
+#ifndef _LINUXKPI_LINUX_CLOCKSOURCE_H
+#define _LINUXKPI_LINUX_CLOCKSOURCE_H
#include <asm/types.h>
#define CLOCKSOURCE_MASK(x) ((u64)(-1ULL >> ((-(x)) & 63)))
-#endif /* _LINUX_CLOCKSOURCE_H */
+#endif /* _LINUXKPI_LINUX_CLOCKSOURCE_H */
diff --git a/sys/compat/linuxkpi/common/include/linux/compat.h b/sys/compat/linuxkpi/common/include/linux/compat.h
index 84b7b47a36dc..8a5a6918bb7c 100644
--- a/sys/compat/linuxkpi/common/include/linux/compat.h
+++ b/sys/compat/linuxkpi/common/include/linux/compat.h
@@ -25,11 +25,9 @@
* 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.
- *
- * $FreeBSD$
*/
-#ifndef _LINUX_COMPAT_H_
-#define _LINUX_COMPAT_H_
+#ifndef _LINUXKPI_LINUX_COMPAT_H_
+#define _LINUXKPI_LINUX_COMPAT_H_
#include <sys/param.h>
#include <sys/proc.h>
@@ -43,19 +41,28 @@ extern int linux_alloc_current(struct thread *, int flags);
extern void linux_free_current(struct task_struct *);
extern struct domainset *linux_get_vm_domain_set(int node);
+#define __current_unallocated(td) \
+ __predict_false((td)->td_lkpi_task == NULL)
+
static inline void
linux_set_current(struct thread *td)
{
- if (__predict_false(td->td_lkpi_task == NULL))
+ if (__current_unallocated(td))
lkpi_alloc_current(td, M_WAITOK);
}
static inline int
linux_set_current_flags(struct thread *td, int flags)
{
- if (__predict_false(td->td_lkpi_task == NULL))
+ if (__current_unallocated(td))
return (lkpi_alloc_current(td, flags));
return (0);
}
-#endif /* _LINUX_COMPAT_H_ */
+#define compat_ptr(x) ((void *)(uintptr_t)x)
+#define ptr_to_compat(x) ((uintptr_t)x)
+
+typedef void fpu_safe_exec_cb_t(void *ctx);
+void lkpi_fpu_safe_exec(fpu_safe_exec_cb_t func, void *ctx);
+
+#endif /* _LINUXKPI_LINUX_COMPAT_H_ */
diff --git a/sys/compat/linuxkpi/common/include/linux/compiler.h b/sys/compat/linuxkpi/common/include/linux/compiler.h
index e641b1b096c3..4146c829b936 100644
--- a/sys/compat/linuxkpi/common/include/linux/compiler.h
+++ b/sys/compat/linuxkpi/common/include/linux/compiler.h
@@ -26,13 +26,12 @@
* 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.
- *
- * $FreeBSD$
*/
-#ifndef _LINUX_COMPILER_H_
-#define _LINUX_COMPILER_H_
+#ifndef _LINUXKPI_LINUX_COMPILER_H_
+#define _LINUXKPI_LINUX_COMPILER_H_
#include <sys/cdefs.h>
+#include <sys/endian.h>
#define __user
#define __kernel
@@ -50,7 +49,9 @@
#define __cond_lock(x,c) (c)
#define __bitwise
#define __devinitdata
+#ifndef __deprecated
#define __deprecated
+#endif
#define __init
#define __initconst
#define __devinit
@@ -64,10 +65,29 @@
#undef __always_inline
#define __always_inline inline
#define noinline __noinline
+#define noinline_for_stack __noinline
#define ____cacheline_aligned __aligned(CACHE_LINE_SIZE)
#define ____cacheline_aligned_in_smp __aligned(CACHE_LINE_SIZE)
#define fallthrough /* FALLTHROUGH */ do { } while(0)
+#if __has_attribute(__nonstring__)
+#define __nonstring __attribute__((__nonstring__))
+#else
+#define __nonstring
+#endif
+#if __has_attribute(__counted_by__)
+#define __counted_by(_x) __attribute__((__counted_by__(_x)))
+#else
+#define __counted_by(_x)
+#endif
+#if BYTE_ORDER == LITTLE_ENDIAN
+#define __counted_by_le(_x) __counted_by(_x)
+#define __counted_by_be(_x)
+#else
+#define __counted_by_le(_x)
+#define __counted_by_be(_x) __counted_by(_x)
+#endif
+
#define likely(x) __builtin_expect(!!(x), 1)
#define unlikely(x) __builtin_expect(!!(x), 0)
#define typeof(x) __typeof(x)
@@ -79,8 +99,11 @@
#define __printf(a,b) __printflike(a,b)
+#define __diag_push()
+#define __diag_pop()
+#define __diag_ignore_all(...)
+
#define barrier() __asm__ __volatile__("": : :"memory")
-#define smp_mb() mb()
#define lower_32_bits(n) ((u32)(n))
#define upper_32_bits(n) ((u32)(((n) >> 16) >> 16))
@@ -88,18 +111,16 @@
#define ___PASTE(a,b) a##b
#define __PASTE(a,b) ___PASTE(a,b)
-#define ACCESS_ONCE(x) (*(volatile __typeof(x) *)&(x))
-
#define WRITE_ONCE(x,v) do { \
barrier(); \
- ACCESS_ONCE(x) = (v); \
+ (*(volatile __typeof(x) *)(uintptr_t)&(x)) = (v); \
barrier(); \
} while (0)
#define READ_ONCE(x) ({ \
__typeof(x) __var = ({ \
barrier(); \
- ACCESS_ONCE(x); \
+ (*(const volatile __typeof(x) *)&(x)); \
}); \
barrier(); \
__var; \
@@ -112,4 +133,15 @@
#define __same_type(a, b) __builtin_types_compatible_p(typeof(a), typeof(b))
#define __must_be_array(a) __same_type(a, &(a)[0])
-#endif /* _LINUX_COMPILER_H_ */
+#define sizeof_field(_s, _m) sizeof(((_s *)0)->_m)
+
+#define is_signed_type(t) ((t)-1 < (t)1)
+#define is_unsigned_type(t) ((t)-1 > (t)1)
+
+#if __has_builtin(__builtin_dynamic_object_size)
+#define __struct_size(_s) __builtin_dynamic_object_size(_s, 0)
+#else
+#define __struct_size(_s) __builtin_object_size(_s, 0)
+#endif
+
+#endif /* _LINUXKPI_LINUX_COMPILER_H_ */
diff --git a/sys/compat/linuxkpi/common/include/linux/completion.h b/sys/compat/linuxkpi/common/include/linux/completion.h
index 09d499309e5a..9f8bebb4cf82 100644
--- a/sys/compat/linuxkpi/common/include/linux/completion.h
+++ b/sys/compat/linuxkpi/common/include/linux/completion.h
@@ -25,11 +25,9 @@
* 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.
- *
- * $FreeBSD$
*/
-#ifndef _LINUX_COMPLETION_H_
-#define _LINUX_COMPLETION_H_
+#ifndef _LINUXKPI_LINUX_COMPLETION_H_
+#define _LINUXKPI_LINUX_COMPLETION_H_
#include <linux/errno.h>
@@ -62,8 +60,9 @@ struct completion {
extern void linux_complete_common(struct completion *, int);
extern int linux_wait_for_common(struct completion *, int);
-extern int linux_wait_for_timeout_common(struct completion *, int, int);
+extern unsigned long linux_wait_for_timeout_common(struct completion *,
+ unsigned long, int);
extern int linux_try_wait_for_completion(struct completion *);
extern int linux_completion_done(struct completion *);
-#endif /* _LINUX_COMPLETION_H_ */
+#endif /* _LINUXKPI_LINUX_COMPLETION_H_ */
diff --git a/sys/compat/linuxkpi/common/include/linux/console.h b/sys/compat/linuxkpi/common/include/linux/console.h
new file mode 100644
index 000000000000..09f486203815
--- /dev/null
+++ b/sys/compat/linuxkpi/common/include/linux/console.h
@@ -0,0 +1,55 @@
+/*-
+ * Copyright (c) 2022 Beckhoff Automation GmbH & Co. KG
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``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 OR CONTRIBUTORS 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.
+ *
+ */
+
+#ifndef _LINUXKPI_LINUX_CONSOLE_H_
+#define _LINUXKPI_LINUX_CONSOLE_H_
+
+#include <linux/types.h>
+
+static inline void
+console_lock(void)
+{
+}
+
+static inline int
+console_trylock(void)
+{
+ return (1);
+}
+
+static inline void
+console_unlock(void)
+{
+}
+
+static inline bool
+vgacon_text_force(void)
+{
+
+ return (false);
+}
+
+#endif /* _LINUXKPI_LINUX_CONSOLE_H_ */
diff --git a/sys/compat/linuxkpi/common/include/linux/container_of.h b/sys/compat/linuxkpi/common/include/linux/container_of.h
new file mode 100644
index 000000000000..7210d531b055
--- /dev/null
+++ b/sys/compat/linuxkpi/common/include/linux/container_of.h
@@ -0,0 +1,54 @@
+/*-
+ * Copyright (c) 2010 Isilon Systems, Inc.
+ * Copyright (c) 2010 iX Systems, Inc.
+ * Copyright (c) 2010 Panasas, Inc.
+ * Copyright (c) 2017 Matt Macy <mmacy@FreeBSD.org>
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice unmodified, this list of conditions, and the following
+ * disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``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.
+ */
+
+#ifndef _LINUXKPI_LINUX_CONTAINER_OF_H
+#define _LINUXKPI_LINUX_CONTAINER_OF_H
+
+#include <sys/stdint.h>
+
+#include <linux/build_bug.h>
+#include <linux/stddef.h>
+
+#define container_of(ptr, type, member) \
+({ \
+ const __typeof(((type *)0)->member) *__p = (ptr); \
+ (type *)((uintptr_t)__p - offsetof(type, member)); \
+})
+
+#define container_of_const(ptr, type, member) \
+ _Generic(ptr, \
+ const typeof(*(ptr)) *: \
+ (const type *)container_of(ptr, type, member), \
+ default: \
+ container_of(ptr, type, member) \
+ )
+
+#define typeof_member(type, member) __typeof(((type *)0)->member)
+
+#endif
diff --git a/sys/compat/linuxkpi/common/include/linux/cpu.h b/sys/compat/linuxkpi/common/include/linux/cpu.h
index 5be8f3d5a0d5..43ec3d66a2e3 100644
--- a/sys/compat/linuxkpi/common/include/linux/cpu.h
+++ b/sys/compat/linuxkpi/common/include/linux/cpu.h
@@ -26,12 +26,10 @@
* 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.
- *
- * $FreeBSD$
*/
-#ifndef __LKPI_LINUX_CPU_H
-#define __LKPI_LINUX_CPU_H
+#ifndef _LINUXKPI_LINUX_CPU_H
+#define _LINUXKPI_LINUX_CPU_H
#include <sys/types.h>
#include <sys/systm.h>
@@ -44,6 +42,8 @@ typedef cpuset_t cpumask_t;
extern cpumask_t cpu_online_mask;
+cpumask_t *lkpi_get_static_single_cpu_mask(int);
+
static __inline int
cpumask_next(int cpuid, cpumask_t mask)
{
@@ -73,4 +73,6 @@ cpumask_set_cpu(int cpu, cpumask_t *mask)
CPU_SET(cpu, mask);
}
-#endif /* __LKPI_LINUX_CPU_H */
+#define cpumask_of(_cpu) (lkpi_get_static_single_cpu_mask(_cpu))
+
+#endif /* _LINUXKPI_LINUX_CPU_H */
diff --git a/sys/compat/linuxkpi/common/include/linux/cpufeature.h b/sys/compat/linuxkpi/common/include/linux/cpufeature.h
new file mode 100644
index 000000000000..746d1a7164a8
--- /dev/null
+++ b/sys/compat/linuxkpi/common/include/linux/cpufeature.h
@@ -0,0 +1,43 @@
+/*-
+ * Copyright (c) 2025 The FreeBSD Foundation
+ * Copyright (c) 2025 Jean-Sébastien Pédron
+ *
+ * This software was developed by Jean-Sébastien Pédron under sponsorship
+ * from the FreeBSD Foundation.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``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 OR CONTRIBUTORS 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.
+ */
+
+#ifndef _LINUXKPI_LINUX_CPUFEATURE_H_
+#define _LINUXKPI_LINUX_CPUFEATURE_H_
+
+/*
+ * Linux includes the following header. We don't have it on FreeBSD yet, so
+ * let's comment this include for now. It is still referenced here because
+ * sometimes, consumers of headers rely voluntarily or not on the namespace
+ * pollution.
+ */
+/* #include <linux/init.h> */
+#include <linux/mod_devicetable.h>
+#include <asm/cpufeature.h>
+
+#endif /* _LINUXKPI_LINUX_CPUFEATURE_H_ */
diff --git a/sys/compat/linuxkpi/common/include/linux/crc32.h b/sys/compat/linuxkpi/common/include/linux/crc32.h
index 6d43eb7b1859..e6d39fa7c5ff 100644
--- a/sys/compat/linuxkpi/common/include/linux/crc32.h
+++ b/sys/compat/linuxkpi/common/include/linux/crc32.h
@@ -26,12 +26,10 @@
* 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.
- *
- * $FreeBSD$
*/
-#ifndef __LKPI_LINUX_CRC32_H
-#define __LKPI_LINUX_CRC32_H
+#ifndef _LINUXKPI_LINUX_CRC32_H
+#define _LINUXKPI_LINUX_CRC32_H
#include <sys/gsb_crc32.h>
@@ -42,4 +40,4 @@ crc32_le(uint32_t crc, const void *data, size_t len)
return (crc32_raw(data, len, crc));
}
-#endif /* __LKPI_LINUX_CRC32_H */
+#endif /* _LINUXKPI_LINUX_CRC32_H */
diff --git a/sys/compat/linuxkpi/common/include/linux/dcache.h b/sys/compat/linuxkpi/common/include/linux/dcache.h
index 1bafa3dbd1fe..992d6f7c2720 100644
--- a/sys/compat/linuxkpi/common/include/linux/dcache.h
+++ b/sys/compat/linuxkpi/common/include/linux/dcache.h
@@ -22,15 +22,14 @@
* 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.
- *
- * $FreeBSD$
*/
-#ifndef __LINUX_DCACHE_H
-#define __LINUX_DCACHE_H
+#ifndef _LINUXKPI_LINUX_DCACHE_H
+#define _LINUXKPI_LINUX_DCACHE_H
+
+#include <sys/vnode.h>
-struct vnode;
-struct pfs_node;
+#include <fs/pseudofs/pseudofs.h>
struct dentry {
struct vnode *d_inode;
@@ -43,4 +42,4 @@ d_inode(const struct dentry *dentry)
return (dentry->d_inode);
}
-#endif /* __LINUX_DCACHE_H */
+#endif /* _LINUXKPI_LINUX_DCACHE_H */
diff --git a/sys/compat/linuxkpi/common/include/linux/debugfs.h b/sys/compat/linuxkpi/common/include/linux/debugfs.h
index 406016d7e2c8..4d146e085a7b 100644
--- a/sys/compat/linuxkpi/common/include/linux/debugfs.h
+++ b/sys/compat/linuxkpi/common/include/linux/debugfs.h
@@ -1,5 +1,5 @@
/*-
- * SPDX-License-Identifier: BSD-2-Clause-FreeBSD
+ * SPDX-License-Identifier: BSD-2-Clause
*
* Copyright (c) 2016-2018, Matthew Macy <mmacy@freebsd.org>
*
@@ -23,29 +23,102 @@
* 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.
- *
- * $FreeBSD$
*/
-#ifndef _LINUX_DEBUGFS_H_
-#define _LINUX_DEBUGFS_H_
+#ifndef _LINUXKPI_LINUX_DEBUGFS_H_
+#define _LINUXKPI_LINUX_DEBUGFS_H_
#include <linux/fs.h>
+#include <linux/module.h>
#include <linux/seq_file.h>
-
#include <linux/types.h>
-void debugfs_remove(struct dentry *dentry);
+MALLOC_DECLARE(M_DFSINT);
+
+struct debugfs_reg32 {
+ char *name;
+ unsigned long offset;
+};
+
+struct debugfs_regset32 {
+ const struct debugfs_reg32 *regs;
+ int nregs;
+};
+
+struct debugfs_blob_wrapper {
+ void *data;
+ size_t size;
+};
+
+static inline bool
+debugfs_initialized(void)
+{
+
+ return (true);
+}
struct dentry *debugfs_create_file(const char *name, umode_t mode,
- struct dentry *parent, void *data,
- const struct file_operations *fops);
+ struct dentry *parent, void *data,
+ const struct file_operations *fops);
+
+/* TODO: We currently ignore the `file_size` argument. */
+struct dentry *debugfs_create_file_size(const char *name, umode_t mode,
+ struct dentry *parent, void *data,
+ const struct file_operations *fops,
+ loff_t file_size);
+
+struct dentry *debugfs_create_file_unsafe(const char *name, umode_t mode,
+struct dentry *parent, void *data,
+ const struct file_operations *fops);
+
+struct dentry *debugfs_create_mode_unsafe(const char *name, umode_t mode,
+ struct dentry *parent, void *data,
+ const struct file_operations *fops,
+ const struct file_operations *fops_ro,
+ const struct file_operations *fops_wo);
struct dentry *debugfs_create_dir(const char *name, struct dentry *parent);
struct dentry *debugfs_create_symlink(const char *name, struct dentry *parent,
- const char *dest);
+ const char *dest);
+
+struct dentry *debugfs_lookup(const char *name, struct dentry *parent);
+
+void debugfs_remove(struct dentry *dentry);
void debugfs_remove_recursive(struct dentry *dentry);
-#endif
+#define DEFINE_DEBUGFS_ATTRIBUTE(__fops, __get, __set, __fmt) \
+ DEFINE_SIMPLE_ATTRIBUTE(__fops, __get, __set, __fmt)
+#define DEFINE_DEBUGFS_ATTRIBUTE_SIGNED(__fops, __get, __set, __fmt) \
+ DEFINE_SIMPLE_ATTRIBUTE_SIGNED(__fops, __get, __set, __fmt)
+
+void debugfs_create_bool(const char *name, umode_t mode, struct dentry *parent,
+ bool *value);
+void debugfs_create_u8(const char *name, umode_t mode, struct dentry *parent,
+ uint8_t *value);
+void debugfs_create_u16(const char *name, umode_t mode, struct dentry *parent,
+ uint16_t *value);
+void debugfs_create_u32(const char *name, umode_t mode, struct dentry *parent,
+ uint32_t *value);
+void debugfs_create_u64(const char *name, umode_t mode, struct dentry *parent,
+ uint64_t *value);
+void debugfs_create_x8(const char *name, umode_t mode, struct dentry *parent,
+ uint8_t *value);
+void debugfs_create_x16(const char *name, umode_t mode, struct dentry *parent,
+ uint16_t *value);
+void debugfs_create_x32(const char *name, umode_t mode, struct dentry *parent,
+ uint32_t *value);
+void debugfs_create_x64(const char *name, umode_t mode, struct dentry *parent,
+ uint64_t *value);
+void debugfs_create_ulong(const char *name, umode_t mode, struct dentry *parent,
+ unsigned long *value);
+void debugfs_create_atomic_t(const char *name, umode_t mode, struct dentry *parent,
+ atomic_t *value);
+void debugfs_create_str(const char *name, umode_t mode, struct dentry *parent,
+ char **value);
+
+struct dentry *debugfs_create_blob(const char *name, umode_t mode,
+ struct dentry *parent, struct debugfs_blob_wrapper *value);
+
+#endif /* _LINUXKPI_LINUX_DEBUGFS_H_ */
diff --git a/sys/compat/linuxkpi/common/include/linux/delay.h b/sys/compat/linuxkpi/common/include/linux/delay.h
index c13a1797adf9..f19d1a759c26 100644
--- a/sys/compat/linuxkpi/common/include/linux/delay.h
+++ b/sys/compat/linuxkpi/common/include/linux/delay.h
@@ -26,11 +26,9 @@
* 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.
- *
- * $FreeBSD$
*/
-#ifndef _LINUX_DELAY_H_
-#define _LINUX_DELAY_H_
+#ifndef _LINUXKPI_LINUX_DELAY_H_
+#define _LINUXKPI_LINUX_DELAY_H_
#include <linux/jiffies.h>
#include <sys/systm.h>
@@ -86,4 +84,4 @@ fsleep(unsigned long us)
usleep_range(us, us);
}
-#endif /* _LINUX_DELAY_H_ */
+#endif /* _LINUXKPI_LINUX_DELAY_H_ */
diff --git a/sys/compat/linuxkpi/common/include/linux/devcoredump.h b/sys/compat/linuxkpi/common/include/linux/devcoredump.h
index 4616fbb5a2ea..5fa06c6595a8 100644
--- a/sys/compat/linuxkpi/common/include/linux/devcoredump.h
+++ b/sys/compat/linuxkpi/common/include/linux/devcoredump.h
@@ -1,7 +1,7 @@
/*-
* SPDX-License-Identifier: BSD-2-Clause
*
- * Copyright (c) 2020 The FreeBSD Foundation
+ * Copyright (c) 2020-2025 The FreeBSD Foundation
*
* This software was developed by Björn Zeeb under sponsorship from
* the FreeBSD Foundation.
@@ -26,12 +26,10 @@
* 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.
- *
- * $FreeBSD$
*/
-#ifndef __LKPI_LINUX_DEVCOREDUMP_H
-#define __LKPI_LINUX_DEVCOREDUMP_H
+#ifndef _LINUXKPI_LINUX_DEVCOREDUMP_H
+#define _LINUXKPI_LINUX_DEVCOREDUMP_H
#include <linux/slab.h>
#include <linux/scatterlist.h>
@@ -73,4 +71,11 @@ dev_coredumpsg(struct device *dev __unused, struct scatterlist *table,
_lkpi_dev_coredumpsg_free(table);
}
-#endif /* __LKPI_LINUX_DEVCOREDUMP_H */
+static inline void
+_devcd_free_sgtable(struct scatterlist *table)
+{
+ /* UNIMPLEMENTED */
+ _lkpi_dev_coredumpsg_free(table);
+}
+
+#endif /* _LINUXKPI_LINUX_DEVCOREDUMP_H */
diff --git a/sys/compat/linuxkpi/common/include/linux/device.h b/sys/compat/linuxkpi/common/include/linux/device.h
index abafcd7ba5c4..c291133e2e0b 100644
--- a/sys/compat/linuxkpi/common/include/linux/device.h
+++ b/sys/compat/linuxkpi/common/include/linux/device.h
@@ -4,6 +4,10 @@
* Copyright (c) 2010 Panasas, Inc.
* Copyright (c) 2013-2016 Mellanox Technologies, Ltd.
* All rights reserved.
+ * Copyright (c) 2021-2025 The FreeBSD Foundation
+ *
+ * Portions of this software were developed by Björn Zeeb
+ * under sponsorship from the FreeBSD Foundation.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
@@ -25,11 +29,9 @@
* 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.
- *
- * $FreeBSD$
*/
-#ifndef _LINUX_DEVICE_H_
-#define _LINUX_DEVICE_H_
+#ifndef _LINUXKPI_LINUX_DEVICE_H_
+#define _LINUXKPI_LINUX_DEVICE_H_
#include <linux/err.h>
#include <linux/types.h>
@@ -37,22 +39,24 @@
#include <linux/sysfs.h>
#include <linux/list.h>
#include <linux/compiler.h>
-#include <linux/types.h>
#include <linux/module.h>
#include <linux/workqueue.h>
#include <linux/kdev_t.h>
#include <linux/backlight.h>
+#include <linux/pm.h>
+#include <linux/idr.h>
+#include <linux/overflow.h>
+#include <linux/ratelimit.h> /* via linux/dev_printk.h */
+#include <linux/fwnode.h>
#include <asm/atomic.h>
#include <sys/bus.h>
#include <sys/backlight.h>
struct device;
-struct fwnode_handle;
struct class {
const char *name;
- struct module *owner;
struct kobject kobj;
devclass_t bsdclass;
const struct dev_pm_ops *pm;
@@ -64,6 +68,7 @@ struct class {
struct dev_pm_ops {
int (*prepare)(struct device *dev);
+ void (*complete)(struct device *dev);
int (*suspend)(struct device *dev);
int (*suspend_late)(struct device *dev);
int (*resume)(struct device *dev);
@@ -76,6 +81,7 @@ struct dev_pm_ops {
int (*poweroff_late)(struct device *dev);
int (*restore)(struct device *dev);
int (*restore_early)(struct device *dev);
+ int (*suspend_noirq)(struct device *dev);
int (*runtime_suspend)(struct device *dev);
int (*runtime_resume)(struct device *dev);
int (*runtime_idle)(struct device *dev);
@@ -84,6 +90,9 @@ struct dev_pm_ops {
struct device_driver {
const char *name;
const struct dev_pm_ops *pm;
+
+ void (*shutdown) (struct device *);
+ void (*coredump) (struct device *);
};
struct device_type {
@@ -121,6 +130,8 @@ struct device {
spinlock_t devres_lock;
struct list_head devres_head;
+
+ struct dev_pm_info power;
};
extern struct device linux_root_device;
@@ -180,14 +191,47 @@ show_class_attr_string(struct class *class,
struct class_attribute_string class_attr_##_name = \
_CLASS_ATTR_STRING(_name, _mode, _str)
-#define dev_err(dev, fmt, ...) device_printf((dev)->bsddev, fmt, ##__VA_ARGS__)
-#define dev_crit(dev, fmt, ...) device_printf((dev)->bsddev, fmt, ##__VA_ARGS__)
-#define dev_warn(dev, fmt, ...) device_printf((dev)->bsddev, fmt, ##__VA_ARGS__)
-#define dev_info(dev, fmt, ...) device_printf((dev)->bsddev, fmt, ##__VA_ARGS__)
-#define dev_notice(dev, fmt, ...) device_printf((dev)->bsddev, fmt, ##__VA_ARGS__)
-#define dev_dbg(dev, fmt, ...) do { } while (0)
#define dev_printk(lvl, dev, fmt, ...) \
- device_printf((dev)->bsddev, fmt, ##__VA_ARGS__)
+ device_printf((dev)->bsddev, fmt, ##__VA_ARGS__)
+
+#define dev_emerg(dev, fmt, ...) device_printf((dev)->bsddev, fmt, ##__VA_ARGS__)
+#define dev_alert(dev, fmt, ...) device_printf((dev)->bsddev, fmt, ##__VA_ARGS__)
+#define dev_crit(dev, fmt, ...) device_printf((dev)->bsddev, fmt, ##__VA_ARGS__)
+#define dev_err(dev, fmt, ...) device_printf((dev)->bsddev, fmt, ##__VA_ARGS__)
+#define dev_warn(dev, fmt, ...) device_printf((dev)->bsddev, fmt, ##__VA_ARGS__)
+#define dev_notice(dev, fmt, ...) device_printf((dev)->bsddev, fmt, ##__VA_ARGS__)
+#define dev_info(dev, fmt, ...) device_printf((dev)->bsddev, fmt, ##__VA_ARGS__)
+#define dev_dbg(dev, fmt, ...) do { } while (0)
+
+#define dev_WARN(dev, fmt, ...) \
+ device_printf((dev)->bsddev, "%s:%d: " fmt, __func__, __LINE__, ##__VA_ARGS__)
+
+#define dev_WARN_ONCE(dev, condition, fmt, ...) do { \
+ static bool __dev_WARN_ONCE; \
+ bool __ret_warn_on = (condition); \
+ if (unlikely(__ret_warn_on)) { \
+ if (!__dev_WARN_ONCE) { \
+ __dev_WARN_ONCE = true; \
+ device_printf((dev)->bsddev, "%s:%d: " fmt, __func__, __LINE__, ##__VA_ARGS__); \
+ } \
+ } \
+} while (0)
+
+#define dev_info_once(dev, ...) do { \
+ static bool __dev_info_once; \
+ if (!__dev_info_once) { \
+ __dev_info_once = true; \
+ dev_info(dev, __VA_ARGS__); \
+ } \
+} while (0)
+
+#define dev_warn_once(dev, ...) do { \
+ static bool __dev_warn_once; \
+ if (!__dev_warn_once) { \
+ __dev_warn_once = 1; \
+ dev_warn(dev, __VA_ARGS__); \
+ } \
+} while (0)
#define dev_err_once(dev, ...) do { \
static bool __dev_err_once; \
@@ -197,6 +241,14 @@ show_class_attr_string(struct class *class,
} \
} while (0)
+#define dev_dbg_once(dev, ...) do { \
+ static bool __dev_dbg_once; \
+ if (!__dev_dbg_once) { \
+ __dev_dbg_once = 1; \
+ dev_dbg(dev, __VA_ARGS__); \
+ } \
+} while (0)
+
#define dev_err_ratelimited(dev, ...) do { \
static linux_ratelimit_t __ratelimited; \
if (linux_ratelimited(&__ratelimited)) \
@@ -209,6 +261,12 @@ show_class_attr_string(struct class *class,
dev_warn(dev, __VA_ARGS__); \
} while (0)
+#define dev_dbg_ratelimited(dev, ...) do { \
+ static linux_ratelimit_t __ratelimited; \
+ if (linux_ratelimited(&__ratelimited)) \
+ dev_dbg(dev, __VA_ARGS__); \
+} while (0)
+
/* Public and LinuxKPI internal devres functions. */
void *lkpi_devres_alloc(void(*release)(struct device *, void *), size_t, gfp_t);
void lkpi_devres_add(struct device *, void *);
@@ -227,6 +285,23 @@ int lkpi_devres_destroy(struct device *, void(*release)(struct device *, void *)
void lkpi_devres_release_free_list(struct device *);
void lkpi_devres_unlink(struct device *, void *);
void lkpi_devm_kmalloc_release(struct device *, void *);
+void lkpi_devm_kfree(struct device *, const void *);
+#define devm_kfree(_d, _p) lkpi_devm_kfree(_d, _p)
+
+static inline const char *
+dev_driver_string(const struct device *dev)
+{
+ driver_t *drv;
+ const char *str = "";
+
+ if (dev->bsddev != NULL) {
+ drv = device_get_driver(dev->bsddev);
+ if (drv != NULL)
+ str = drv->name;
+ }
+
+ return (str);
+}
static inline void *
dev_get_drvdata(const struct device *dev)
@@ -259,6 +334,13 @@ dev_name(const struct device *dev)
return kobject_name(&dev->kobj);
}
+static inline bool
+dev_is_removable(struct device *dev)
+{
+
+ return (false);
+}
+
#define dev_set_name(_dev, _fmt, ...) \
kobject_set_name(&(_dev)->kobj, (_fmt), ##__VA_ARGS__)
@@ -270,6 +352,13 @@ put_device(struct device *dev)
kobject_put(&dev->kobj);
}
+struct class *lkpi_class_create(const char *name);
+#if defined(LINUXKPI_VERSION) && LINUXKPI_VERSION >= 60400
+#define class_create(name) lkpi_class_create(name)
+#else
+#define class_create(owner, name) lkpi_class_create(name)
+#endif
+
static inline int
class_register(struct class *class)
{
@@ -294,6 +383,12 @@ static inline struct device *kobj_to_dev(struct kobject *kobj)
return container_of(kobj, struct device, kobj);
}
+struct device *device_create(struct class *class, struct device *parent,
+ dev_t devt, void *drvdata, const char *fmt, ...);
+struct device *device_create_groups_vargs(struct class *class, struct device *parent,
+ dev_t devt, void *drvdata, const struct attribute_group **groups,
+ const char *fmt, va_list args);
+
/*
* Devices are registered and created for exporting to sysfs. Create
* implies register and register assumes the device fields have been
@@ -354,47 +449,6 @@ device_create_release(struct device *dev)
}
static inline struct device *
-device_create_groups_vargs(struct class *class, struct device *parent,
- dev_t devt, void *drvdata, const struct attribute_group **groups,
- const char *fmt, va_list args)
-{
- struct device *dev = NULL;
- int retval = -ENODEV;
-
- if (class == NULL || IS_ERR(class))
- goto error;
-
- dev = kzalloc(sizeof(*dev), GFP_KERNEL);
- if (!dev) {
- retval = -ENOMEM;
- goto error;
- }
-
- dev->devt = devt;
- dev->class = class;
- dev->parent = parent;
- dev->groups = groups;
- dev->release = device_create_release;
- /* device_initialize() needs the class and parent to be set */
- device_initialize(dev);
- dev_set_drvdata(dev, drvdata);
-
- retval = kobject_set_name_vargs(&dev->kobj, fmt, args);
- if (retval)
- goto error;
-
- retval = device_add(dev);
- if (retval)
- goto error;
-
- return dev;
-
-error:
- put_device(dev);
- return ERR_PTR(retval);
-}
-
-static inline struct device *
device_create_with_groups(struct class *class,
struct device *parent, dev_t devt, void *drvdata,
const struct attribute_group **groups, const char *fmt, ...)
@@ -465,9 +519,9 @@ device_unregister(struct device *dev)
dev->bsddev = NULL;
if (bsddev != NULL && dev->bsddev_attached_here) {
- mtx_lock(&Giant);
+ bus_topo_lock();
device_delete_child(device_get_parent(bsddev), bsddev);
- mtx_unlock(&Giant);
+ bus_topo_unlock();
}
put_device(dev);
}
@@ -481,15 +535,12 @@ device_del(struct device *dev)
dev->bsddev = NULL;
if (bsddev != NULL && dev->bsddev_attached_here) {
- mtx_lock(&Giant);
+ bus_topo_lock();
device_delete_child(device_get_parent(bsddev), bsddev);
- mtx_unlock(&Giant);
+ bus_topo_unlock();
}
}
-struct device *device_create(struct class *class, struct device *parent,
- dev_t devt, void *drvdata, const char *fmt, ...);
-
static inline void
device_destroy(struct class *class, dev_t devt)
{
@@ -514,10 +565,10 @@ device_release_driver(struct device *dev)
dev_set_drvdata(dev, NULL);
/* Do not call dev->release! */
- mtx_lock(&Giant);
+ bus_topo_lock();
if (device_is_attached(dev->bsddev))
device_detach(dev->bsddev);
- mtx_unlock(&Giant);
+ bus_topo_unlock();
#endif
}
@@ -527,40 +578,45 @@ device_reprobe(struct device *dev)
int error;
device_release_driver(dev);
- mtx_lock(&Giant);
+ bus_topo_lock();
error = device_probe_and_attach(dev->bsddev);
- mtx_unlock(&Giant);
+ bus_topo_unlock();
return (-error);
}
-#define dev_pm_set_driver_flags(dev, flags) do { \
-} while (0)
-
static inline void
-linux_class_kfree(struct class *class)
+device_set_wakeup_enable(struct device *dev __unused, bool enable __unused)
{
- kfree(class);
+ /*
+ * XXX-BZ TODO This is used by wireless drivers supporting WoWLAN which
+ * we currently do not support.
+ */
}
-static inline struct class *
-class_create(struct module *owner, const char *name)
+static inline int
+device_wakeup_enable(struct device *dev)
{
- struct class *class;
- int error;
- class = kzalloc(sizeof(*class), M_WAITOK);
- class->owner = owner;
- class->name = name;
- class->class_release = linux_class_kfree;
- error = class_register(class);
- if (error) {
- kfree(class);
- return (NULL);
- }
+ device_set_wakeup_enable(dev, true);
+ return (0);
+}
- return (class);
+static inline bool
+device_iommu_mapped(struct device *dev __unused)
+{
+ return (false);
+}
+
+#define dev_pm_set_driver_flags(dev, flags) do { \
+} while (0)
+
+static inline void
+linux_class_kfree(struct class *class)
+{
+
+ kfree(class);
}
static inline void
@@ -629,10 +685,36 @@ devm_kmalloc(struct device *dev, size_t size, gfp_t gfp)
return (p);
}
+static inline void *
+devm_kmemdup(struct device *dev, const void *src, size_t len, gfp_t gfp)
+{
+ void *dst;
+
+ if (len == 0)
+ return (NULL);
+
+ dst = devm_kmalloc(dev, len, gfp);
+ if (dst != NULL)
+ memcpy(dst, src, len);
+
+ return (dst);
+}
+
#define devm_kzalloc(_dev, _size, _gfp) \
devm_kmalloc((_dev), (_size), (_gfp) | __GFP_ZERO)
#define devm_kcalloc(_dev, _sizen, _size, _gfp) \
devm_kmalloc((_dev), ((_sizen) * (_size)), (_gfp) | __GFP_ZERO)
-#endif /* _LINUX_DEVICE_H_ */
+int lkpi_devm_add_action(struct device *dev, void (*action)(void *), void *data);
+#define devm_add_action(dev, action, data) \
+ lkpi_devm_add_action(dev, action, data);
+int lkpi_devm_add_action_or_reset(struct device *dev, void (*action)(void *), void *data);
+#define devm_add_action_or_reset(dev, action, data) \
+ lkpi_devm_add_action_or_reset(dev, action, data)
+
+int lkpi_devm_device_add_group(struct device *dev, const struct attribute_group *group);
+#define devm_device_add_group(dev, group) \
+ lkpi_devm_device_add_group(dev, group)
+
+#endif /* _LINUXKPI_LINUX_DEVICE_H_ */
diff --git a/sys/compat/linuxkpi/common/include/linux/device/driver.h b/sys/compat/linuxkpi/common/include/linux/device/driver.h
new file mode 100644
index 000000000000..03b510c9c8b7
--- /dev/null
+++ b/sys/compat/linuxkpi/common/include/linux/device/driver.h
@@ -0,0 +1,33 @@
+/*-
+ * SPDX-License-Identifier: BSD-2-Clause
+ *
+ * Copyright (c) 2021 Bjoern A. Zeeb
+ * Copyright (c) 2024 The FreeBSD Foundation
+ *
+ * Portions of this software were developed by Björn Zeeb
+ * under sponsorship from the FreeBSD Foundation.
+ */
+
+#ifndef LINUXKPI_LINUX_DEVICE_DRIVER_H
+#define LINUXKPI_LINUX_DEVICE_DRIVER_H
+
+#include <sys/cdefs.h>
+#include <linux/module.h>
+
+#define module_driver(_drv, _regf, _unregf) \
+static inline int \
+__CONCAT(__CONCAT(_, _drv), _init)(void) \
+{ \
+ return (_regf(&(_drv))); \
+} \
+ \
+static inline void \
+__CONCAT(__CONCAT(_, _drv), _exit)(void) \
+{ \
+ _unregf(&(_drv)); \
+} \
+ \
+module_init(__CONCAT(__CONCAT(_, _drv), _init)); \
+module_exit(__CONCAT(__CONCAT(_, _drv), _exit))
+
+#endif /* LINUXKPI_LINUX_DEVICE_DRIVER_H */
diff --git a/sys/compat/linuxkpi/common/include/linux/dma-attrs.h b/sys/compat/linuxkpi/common/include/linux/dma-attrs.h
index d424d16164a6..c9cfa9b621d5 100644
--- a/sys/compat/linuxkpi/common/include/linux/dma-attrs.h
+++ b/sys/compat/linuxkpi/common/include/linux/dma-attrs.h
@@ -25,11 +25,9 @@
* 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.
- *
- * $FreeBSD$
*/
-#ifndef _LINUX_DMA_ATTR_H_
-#define _LINUX_DMA_ATTR_H_
+#ifndef _LINUXKPI_LINUX_DMA_ATTR_H_
+#define _LINUXKPI_LINUX_DMA_ATTR_H_
#define DMA_ATTR_WRITE_BARRIER (1 << 0)
#define DMA_ATTR_WEAK_ORDERING (1 << 1)
@@ -53,4 +51,4 @@ init_dma_attrs(struct dma_attrs *attrs)
attrs->flags = 0;
}
-#endif /* _LINUX_DMA_ATTR_H_ */
+#endif /* _LINUXKPI_LINUX_DMA_ATTR_H_ */
diff --git a/sys/compat/linuxkpi/common/include/linux/dma-buf-map.h b/sys/compat/linuxkpi/common/include/linux/dma-buf-map.h
new file mode 100644
index 000000000000..567ce3b072b3
--- /dev/null
+++ b/sys/compat/linuxkpi/common/include/linux/dma-buf-map.h
@@ -0,0 +1,91 @@
+/* Public domain. */
+
+#ifndef _LINUX_DMA_BUF_MAP_H
+#define _LINUX_DMA_BUF_MAP_H
+
+#include <linux/io.h>
+#include <linux/string.h>
+
+struct dma_buf_map {
+ union {
+ void *vaddr_iomem;
+ void *vaddr;
+ };
+ bool is_iomem;
+};
+
+static inline void
+dma_buf_map_incr(struct dma_buf_map *dbm, size_t n)
+{
+ if (dbm->is_iomem)
+ dbm->vaddr_iomem += n;
+ else
+ dbm->vaddr += n;
+}
+
+static inline void
+dma_buf_map_memcpy_to(struct dma_buf_map *dbm, const void *src, size_t len)
+{
+ if (dbm->is_iomem)
+ memcpy_toio(dbm->vaddr_iomem, src, len);
+ else
+ memcpy(dbm->vaddr, src, len);
+}
+
+static inline bool
+dma_buf_map_is_null(const struct dma_buf_map *dbm)
+{
+ if (dbm->is_iomem)
+ return (dbm->vaddr_iomem == NULL);
+ else
+ return (dbm->vaddr == NULL);
+}
+
+static inline bool
+dma_buf_map_is_set(const struct dma_buf_map *dbm)
+{
+ if (dbm->is_iomem)
+ return (dbm->vaddr_iomem != NULL);
+ else
+ return (dbm->vaddr != NULL);
+}
+
+static inline bool
+dma_buf_map_is_equal(
+ const struct dma_buf_map *dbm_a, const struct dma_buf_map *dbm_b)
+{
+ if (dbm_a->is_iomem != dbm_b->is_iomem)
+ return (false);
+
+ if (dbm_a->is_iomem)
+ return (dbm_a->vaddr_iomem == dbm_b->vaddr_iomem);
+ else
+ return (dbm_a->vaddr == dbm_b->vaddr);
+}
+
+static inline void
+dma_buf_map_clear(struct dma_buf_map *dbm)
+{
+ if (dbm->is_iomem) {
+ dbm->vaddr_iomem = NULL;
+ dbm->is_iomem = false;
+ } else {
+ dbm->vaddr = NULL;
+ }
+}
+
+static inline void
+dma_buf_map_set_vaddr_iomem(struct dma_buf_map *dbm, void *addr)
+{
+ dbm->vaddr_iomem = addr;
+ dbm->is_iomem = true;
+}
+
+static inline void
+dma_buf_map_set_vaddr(struct dma_buf_map *dbm, void *addr)
+{
+ dbm->vaddr = addr;
+ dbm->is_iomem = false;
+}
+
+#endif
diff --git a/sys/compat/linuxkpi/common/include/linux/dma-mapping.h b/sys/compat/linuxkpi/common/include/linux/dma-mapping.h
index c86a24d1270a..2d8e1196d3d3 100644
--- a/sys/compat/linuxkpi/common/include/linux/dma-mapping.h
+++ b/sys/compat/linuxkpi/common/include/linux/dma-mapping.h
@@ -25,11 +25,9 @@
* 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.
- *
- * $FreeBSD$
*/
-#ifndef _LINUX_DMA_MAPPING_H_
-#define _LINUX_DMA_MAPPING_H_
+#ifndef _LINUXKPI_LINUX_DMA_MAPPING_H_
+#define _LINUXKPI_LINUX_DMA_MAPPING_H_
#include <linux/types.h>
#include <linux/device.h>
@@ -45,6 +43,7 @@
#include <vm/vm.h>
#include <vm/vm_page.h>
+#include <vm/uma_align_mask.h>
#include <vm/pmap.h>
#include <machine/bus.h>
@@ -95,14 +94,21 @@ int linux_dma_tag_init(struct device *, u64);
int linux_dma_tag_init_coherent(struct device *, u64);
void *linux_dma_alloc_coherent(struct device *dev, size_t size,
dma_addr_t *dma_handle, gfp_t flag);
-dma_addr_t linux_dma_map_phys(struct device *dev, vm_paddr_t phys, size_t len);
-void linux_dma_unmap(struct device *dev, dma_addr_t dma_addr, size_t size);
+void *linuxkpi_dmam_alloc_coherent(struct device *dev, size_t size,
+ dma_addr_t *dma_handle, gfp_t flag);
+dma_addr_t linux_dma_map_phys(struct device *dev, vm_paddr_t phys, size_t len); /* backward compat */
+dma_addr_t lkpi_dma_map_phys(struct device *, vm_paddr_t, size_t,
+ enum dma_data_direction, unsigned long);
+void linux_dma_unmap(struct device *dev, dma_addr_t dma_addr, size_t size); /* backward compat */
+void lkpi_dma_unmap(struct device *, dma_addr_t, size_t,
+ enum dma_data_direction, unsigned long);
int linux_dma_map_sg_attrs(struct device *dev, struct scatterlist *sgl,
- int nents, enum dma_data_direction dir __unused,
+ int nents, enum dma_data_direction direction,
unsigned long attrs __unused);
void linux_dma_unmap_sg_attrs(struct device *dev, struct scatterlist *sg,
- int nents __unused, enum dma_data_direction dir __unused,
+ int nents __unused, enum dma_data_direction direction,
unsigned long attrs __unused);
+void linuxkpi_dma_sync(struct device *, dma_addr_t, size_t, bus_dmasync_op_t);
static inline int
dma_supported(struct device *dev, u64 dma_mask)
@@ -158,27 +164,30 @@ dma_zalloc_coherent(struct device *dev, size_t size, dma_addr_t *dma_handle,
return (dma_alloc_coherent(dev, size, dma_handle, flag | __GFP_ZERO));
}
+static inline void *
+dmam_alloc_coherent(struct device *dev, size_t size, dma_addr_t *dma_handle,
+ gfp_t flag)
+{
+
+ return (linuxkpi_dmam_alloc_coherent(dev, size, dma_handle, flag));
+}
+
static inline void
dma_free_coherent(struct device *dev, size_t size, void *cpu_addr,
dma_addr_t dma_addr)
{
- linux_dma_unmap(dev, dma_addr, size);
- kmem_free((vm_offset_t)cpu_addr, size);
+ lkpi_dma_unmap(dev, dma_addr, size, DMA_BIDIRECTIONAL, 0);
+ kmem_free(cpu_addr, size);
}
-#define dma_map_single_attrs(dev, ptr, size, dir, attrs) \
- linux_dma_map_phys(dev, vtophys(ptr), size)
-
-#define dma_unmap_single_attrs(dev, dma_addr, size, dir, attrs) \
- linux_dma_unmap(dev, dma_addr, size)
-
static inline dma_addr_t
dma_map_page_attrs(struct device *dev, struct page *page, size_t offset,
- size_t size, enum dma_data_direction dir, unsigned long attrs)
+ size_t size, enum dma_data_direction direction, unsigned long attrs)
{
- return (linux_dma_map_phys(dev, VM_PAGE_TO_PHYS(page) + offset, size));
+ return (lkpi_dma_map_phys(dev, page_to_phys(page) + offset, size,
+ direction, attrs));
}
/* linux_dma_(un)map_sg_attrs does not support attrs yet */
@@ -193,7 +202,8 @@ dma_map_page(struct device *dev, struct page *page,
unsigned long offset, size_t size, enum dma_data_direction direction)
{
- return (linux_dma_map_phys(dev, VM_PAGE_TO_PHYS(page) + offset, size));
+ return (lkpi_dma_map_phys(dev, page_to_phys(page) + offset, size,
+ direction, 0));
}
static inline void
@@ -201,13 +211,46 @@ dma_unmap_page(struct device *dev, dma_addr_t dma_address, size_t size,
enum dma_data_direction direction)
{
- linux_dma_unmap(dev, dma_address, size);
+ lkpi_dma_unmap(dev, dma_address, size, direction, 0);
+}
+
+static inline dma_addr_t
+dma_map_resource(struct device *dev, phys_addr_t paddr, size_t size,
+ enum dma_data_direction direction, unsigned long attrs)
+{
+ return (lkpi_dma_map_phys(dev, paddr, size, direction, attrs));
}
static inline void
-dma_sync_single_for_cpu(struct device *dev, dma_addr_t dma_handle, size_t size,
+dma_unmap_resource(struct device *dev, dma_addr_t dma, size_t size,
+ enum dma_data_direction direction, unsigned long attrs)
+{
+ lkpi_dma_unmap(dev, dma, size, direction, attrs);
+}
+
+static inline void
+dma_sync_single_for_cpu(struct device *dev, dma_addr_t dma, size_t size,
enum dma_data_direction direction)
{
+ bus_dmasync_op_t op;
+
+ switch (direction) {
+ case DMA_BIDIRECTIONAL:
+ op = BUS_DMASYNC_POSTREAD;
+ linuxkpi_dma_sync(dev, dma, size, op);
+ op = BUS_DMASYNC_PREREAD;
+ break;
+ case DMA_TO_DEVICE:
+ op = BUS_DMASYNC_POSTWRITE;
+ break;
+ case DMA_FROM_DEVICE:
+ op = BUS_DMASYNC_POSTREAD;
+ break;
+ default:
+ return;
+ }
+
+ linuxkpi_dma_sync(dev, dma, size, op);
}
static inline void
@@ -218,40 +261,66 @@ dma_sync_single(struct device *dev, dma_addr_t addr, size_t size,
}
static inline void
-dma_sync_single_for_device(struct device *dev, dma_addr_t dma_handle,
+dma_sync_single_for_device(struct device *dev, dma_addr_t dma,
size_t size, enum dma_data_direction direction)
{
+ bus_dmasync_op_t op;
+
+ switch (direction) {
+ case DMA_BIDIRECTIONAL:
+ op = BUS_DMASYNC_PREWRITE;
+ break;
+ case DMA_TO_DEVICE:
+ op = BUS_DMASYNC_PREREAD;
+ break;
+ case DMA_FROM_DEVICE:
+ op = BUS_DMASYNC_PREWRITE;
+ break;
+ default:
+ return;
+ }
+
+ linuxkpi_dma_sync(dev, dma, size, op);
}
+/* (20250329) These four seem to be unused code. */
static inline void
dma_sync_sg_for_cpu(struct device *dev, struct scatterlist *sg, int nelems,
enum dma_data_direction direction)
{
+ pr_debug("%s:%d: TODO dir %d\n", __func__, __LINE__, direction);
}
static inline void
dma_sync_sg_for_device(struct device *dev, struct scatterlist *sg, int nelems,
enum dma_data_direction direction)
{
+ pr_debug("%s:%d: TODO dir %d\n", __func__, __LINE__, direction);
}
static inline void
dma_sync_single_range_for_cpu(struct device *dev, dma_addr_t dma_handle,
- unsigned long offset, size_t size, int direction)
+ unsigned long offset, size_t size, enum dma_data_direction direction)
{
+ pr_debug("%s:%d: TODO dir %d\n", __func__, __LINE__, direction);
}
static inline void
dma_sync_single_range_for_device(struct device *dev, dma_addr_t dma_handle,
- unsigned long offset, size_t size, int direction)
+ unsigned long offset, size_t size, enum dma_data_direction direction)
{
+ pr_debug("%s:%d: TODO dir %d\n", __func__, __LINE__, direction);
}
+#define DMA_MAPPING_ERROR (~(dma_addr_t)0)
+
static inline int
dma_mapping_error(struct device *dev, dma_addr_t dma_addr)
{
- return (dma_addr == 0);
+ if (dma_addr == 0 || dma_addr == DMA_MAPPING_ERROR)
+ return (-ENOMEM);
+ return (0);
}
static inline unsigned int dma_set_max_seg_size(struct device *dev,
@@ -260,6 +329,34 @@ static inline unsigned int dma_set_max_seg_size(struct device *dev,
return (0);
}
+static inline dma_addr_t
+_dma_map_single_attrs(struct device *dev, void *ptr, size_t size,
+ enum dma_data_direction direction, unsigned long attrs)
+{
+ return (lkpi_dma_map_phys(dev, vtophys(ptr), size,
+ direction, attrs));
+}
+
+static inline void
+_dma_unmap_single_attrs(struct device *dev, dma_addr_t dma, size_t size,
+ enum dma_data_direction direction, unsigned long attrs)
+{
+ lkpi_dma_unmap(dev, dma, size, direction, attrs);
+}
+
+static inline size_t
+dma_max_mapping_size(struct device *dev)
+{
+
+ return (SCATTERLIST_MAX_SEGMENT);
+}
+
+#define dma_map_single_attrs(dev, ptr, size, dir, attrs) \
+ _dma_map_single_attrs(dev, ptr, size, dir, 0)
+
+#define dma_unmap_single_attrs(dev, dma_addr, size, dir, attrs) \
+ _dma_unmap_single_attrs(dev, dma_addr, size, dir, 0)
+
#define dma_map_single(d, a, s, r) dma_map_single_attrs(d, a, s, r, 0)
#define dma_unmap_single(d, a, s, r) dma_unmap_single_attrs(d, a, s, r, 0)
#define dma_map_sg(d, s, n, r) dma_map_sg_attrs(d, s, n, r, 0)
@@ -272,7 +369,31 @@ static inline unsigned int dma_set_max_seg_size(struct device *dev,
#define dma_unmap_len(p, name) ((p)->name)
#define dma_unmap_len_set(p, name, v) (((p)->name) = (v))
-extern int uma_align_cache;
-#define dma_get_cache_alignment() uma_align_cache
+#define dma_get_cache_alignment() (uma_get_cache_align_mask() + 1)
+
+
+static inline int
+dma_map_sgtable(struct device *dev, struct sg_table *sgt,
+ enum dma_data_direction dir,
+ unsigned long attrs)
+{
+ int nents;
+
+ nents = dma_map_sg_attrs(dev, sgt->sgl, sgt->nents, dir, attrs);
+ if (nents < 0)
+ return (nents);
+ sgt->nents = nents;
+ return (0);
+}
+
+static inline void
+dma_unmap_sgtable(struct device *dev, struct sg_table *sgt,
+ enum dma_data_direction dir,
+ unsigned long attrs)
+{
+
+ dma_unmap_sg_attrs(dev, sgt->sgl, sgt->nents, dir, attrs);
+}
+
-#endif /* _LINUX_DMA_MAPPING_H_ */
+#endif /* _LINUXKPI_LINUX_DMA_MAPPING_H_ */
diff --git a/sys/compat/linuxkpi/common/include/linux/dmapool.h b/sys/compat/linuxkpi/common/include/linux/dmapool.h
index 60353ede6a82..8501a32e30b7 100644
--- a/sys/compat/linuxkpi/common/include/linux/dmapool.h
+++ b/sys/compat/linuxkpi/common/include/linux/dmapool.h
@@ -25,11 +25,9 @@
* 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.
- *
- * $FreeBSD$
*/
-#ifndef _LINUX_DMAPOOL_H_
-#define _LINUX_DMAPOOL_H_
+#ifndef _LINUXKPI_LINUX_DMAPOOL_H_
+#define _LINUXKPI_LINUX_DMAPOOL_H_
#include <linux/types.h>
#include <linux/io.h>
@@ -102,4 +100,4 @@ dma_pool_free(struct dma_pool *pool, void *vaddr, dma_addr_t dma_addr)
linux_dma_pool_free(pool, vaddr, dma_addr);
}
-#endif /* _LINUX_DMAPOOL_H_ */
+#endif /* _LINUXKPI_LINUX_DMAPOOL_H_ */
diff --git a/sys/compat/linuxkpi/common/include/linux/dmi.h b/sys/compat/linuxkpi/common/include/linux/dmi.h
index 6e450e156b73..d9760ee0324f 100644
--- a/sys/compat/linuxkpi/common/include/linux/dmi.h
+++ b/sys/compat/linuxkpi/common/include/linux/dmi.h
@@ -24,16 +24,20 @@
* 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.
- *
- * $FreeBSD$
*/
-#ifndef __LINUX_DMI_H__
-#define __LINUX_DMI_H__
+#ifndef __LINUXKPI_LINUX_DMI_H__
+#define __LINUXKPI_LINUX_DMI_H__
#include <sys/types.h>
#include <linux/mod_devicetable.h>
+struct dmi_header {
+ uint8_t type;
+ uint8_t length;
+ uint16_t handle;
+};
+
int linux_dmi_check_system(const struct dmi_system_id *);
bool linux_dmi_match(enum dmi_field, const char *);
const struct dmi_system_id *linux_dmi_first_match(const struct dmi_system_id *);
@@ -44,4 +48,11 @@ const char *linux_dmi_get_system_info(int);
#define dmi_first_match(sysid) linux_dmi_first_match(sysid)
#define dmi_get_system_info(sysid) linux_dmi_get_system_info(sysid)
-#endif /* __LINUX_DMI_H__ */
+static inline int
+dmi_walk(void (*callbackf)(const struct dmi_header *, void *), void *arg)
+{
+
+ return (-ENXIO);
+}
+
+#endif /* __LINUXKPI_LINUX_DMI_H__ */
diff --git a/sys/compat/linuxkpi/common/include/linux/dynamic_debug.h b/sys/compat/linuxkpi/common/include/linux/dynamic_debug.h
new file mode 100644
index 000000000000..12915eec3b68
--- /dev/null
+++ b/sys/compat/linuxkpi/common/include/linux/dynamic_debug.h
@@ -0,0 +1,8 @@
+/* Public domain. */
+
+#ifndef _LINUXKPI_LINUX_DYNAMIC_DEBUG_H
+#define _LINUXKPI_LINUX_DYNAMIC_DEBUG_H
+
+#define DECLARE_DYNDBG_CLASSMAP(a, b, c, ...)
+
+#endif
diff --git a/sys/compat/linuxkpi/common/include/linux/efi.h b/sys/compat/linuxkpi/common/include/linux/efi.h
new file mode 100644
index 000000000000..aa33371bd0e8
--- /dev/null
+++ b/sys/compat/linuxkpi/common/include/linux/efi.h
@@ -0,0 +1,68 @@
+/*-
+ * SPDX-License-Identifier: BSD-2-Clause
+ *
+ * Copyright (c) 2021 Vladimir Kondratyev <wulf@FreeBSD.org>
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``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.
+ */
+
+#ifndef _LINUXKPI_LINUX_EFI_H_
+#define _LINUXKPI_LINUX_EFI_H_
+
+#include <sys/param.h>
+#include <sys/queue.h>
+#include <sys/linker.h>
+#include <sys/systm.h>
+
+#include <machine/md_var.h>
+#include <machine/metadata.h>
+
+#define EFI_BOOT 0
+
+static inline bool
+__efi_enabled(int feature)
+{
+ bool enabled = false;
+
+ switch (feature) {
+ case EFI_BOOT:
+#ifdef __amd64__
+ /* Use cached value on amd64 */
+ enabled = efi_boot;
+#elif defined(MODINFOMD_EFI_MAP)
+ enabled = preload_search_info(preload_kmdp,
+ MODINFO_METADATA | MODINFOMD_EFI_MAP) != NULL;
+#endif
+ break;
+ default:
+ break;
+ }
+
+ return (enabled);
+}
+
+#define efi_enabled(x) ({ \
+ _Static_assert((x) == EFI_BOOT, "unsupported feature"); \
+ __efi_enabled(x); \
+})
+
+#endif /* _LINUXKPI_LINUX_EFI_H_ */
diff --git a/sys/compat/linuxkpi/common/include/linux/err.h b/sys/compat/linuxkpi/common/include/linux/err.h
index 40a8ba82dfda..3d19949e641e 100644
--- a/sys/compat/linuxkpi/common/include/linux/err.h
+++ b/sys/compat/linuxkpi/common/include/linux/err.h
@@ -25,11 +25,9 @@
* 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.
- *
- * $FreeBSD$
*/
-#ifndef _LINUX_ERR_H_
-#define _LINUX_ERR_H_
+#ifndef _LINUXKPI_LINUX_ERR_H_
+#define _LINUXKPI_LINUX_ERR_H_
#include <sys/types.h>
@@ -80,4 +78,4 @@ PTR_ERR_OR_ZERO(const void *ptr)
#define PTR_RET(p) PTR_ERR_OR_ZERO(p)
-#endif /* _LINUX_ERR_H_ */
+#endif /* _LINUXKPI_LINUX_ERR_H_ */
diff --git a/sys/compat/linuxkpi/common/include/linux/errno.h b/sys/compat/linuxkpi/common/include/linux/errno.h
index efdde9a7a72a..d634675d43d0 100644
--- a/sys/compat/linuxkpi/common/include/linux/errno.h
+++ b/sys/compat/linuxkpi/common/include/linux/errno.h
@@ -25,15 +25,15 @@
* 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.
- *
- * $FreeBSD$
*/
-#ifndef _LINUX_ERRNO_H_
-#define _LINUX_ERRNO_H_
+#ifndef _LINUXKPI_LINUX_ERRNO_H_
+#define _LINUXKPI_LINUX_ERRNO_H_
#include <sys/errno.h>
#define EBADRQC 56 /* Bad request code */
+#define EBADSLT 57 /* Invalid slot */
+#define ENOKEY 126 /* Required key not available */
#define ECHRNG EDOM
#define ETIME ETIMEDOUT
@@ -44,6 +44,7 @@
#define ERESTARTSYS 512
#define ENOTSUPP EOPNOTSUPP
#define ENONET EHOSTDOWN
+#define EHWPOISON 133 /* Memory page hardware error */
/*
* The error numbers below are arbitrary and do not resemble the numbers
@@ -64,5 +65,9 @@
#define EIOCBQUEUED 529
#define ERFKILL 530
#define EBADE 531
+#define ENOMEDIUM 532
+#define ENOSR 533
+#define ELNRNG 534
+#define ENAVAIL 535
-#endif /* _LINUX_ERRNO_H_ */
+#endif /* _LINUXKPI_LINUX_ERRNO_H_ */
diff --git a/sys/compat/linuxkpi/common/include/linux/etherdevice.h b/sys/compat/linuxkpi/common/include/linux/etherdevice.h
index 9062cd562347..b9a4951de8ac 100644
--- a/sys/compat/linuxkpi/common/include/linux/etherdevice.h
+++ b/sys/compat/linuxkpi/common/include/linux/etherdevice.h
@@ -21,13 +21,14 @@
* 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.
- *
- * $FreeBSD$
*/
-#ifndef _LINUX_ETHERDEVICE
-#define _LINUX_ETHERDEVICE
+#ifndef _LINUXKPI_LINUX_ETHERDEVICE_H_
+#define _LINUXKPI_LINUX_ETHERDEVICE_H_
#include <linux/types.h>
+#include <linux/device.h>
+#include <linux/skbuff.h>
+#include <linux/netdevice.h>
#include <sys/random.h>
#include <sys/libkern.h>
@@ -54,19 +55,27 @@ struct ethtool_modinfo {
static inline bool
is_zero_ether_addr(const u8 * addr)
{
- return ((addr[0] + addr[1] + addr[2] + addr[3] + addr[4] + addr[5]) == 0x00);
+ return ((addr[0] | addr[1] | addr[2] | addr[3] | addr[4] | addr[5]) ==
+ 0x00);
+}
+
+static inline bool
+is_unicast_ether_addr(const u8 * addr)
+{
+ return ((addr[0] & 0x01) == 0x00);
}
static inline bool
is_multicast_ether_addr(const u8 * addr)
{
- return (0x01 & addr[0]);
+ return ((addr[0] & 0x01) == 0x01);
}
static inline bool
is_broadcast_ether_addr(const u8 * addr)
{
- return ((addr[0] + addr[1] + addr[2] + addr[3] + addr[4] + addr[5]) == (6 * 0xff));
+ return ((addr[0] & addr[1] & addr[2] & addr[3] & addr[4] & addr[5]) ==
+ 0xff);
}
static inline bool
@@ -107,7 +116,7 @@ eth_zero_addr(u8 *pa)
}
static inline void
-random_ether_addr(u8 * dst)
+random_ether_addr(u8 *dst)
{
arc4random_buf(dst, 6);
@@ -115,4 +124,40 @@ random_ether_addr(u8 * dst)
dst[0] |= 0x02;
}
-#endif /* _LINUX_ETHERDEVICE */
+static inline void
+eth_random_addr(u8 *dst)
+{
+
+ random_ether_addr(dst);
+}
+
+static inline int
+device_get_mac_address(struct device *dev, char *dst)
+{
+
+ /* XXX get mac address from FDT? */
+ return (-ENOENT);
+}
+
+/* Returns network byte order. */
+static inline uint16_t
+eth_type_trans(struct sk_buff *skb, struct net_device *dev)
+{
+ pr_debug("%s: TODO\n", __func__);
+ return (htons(ETHERTYPE_8023));
+}
+
+static inline void
+eth_hw_addr_set(struct net_device *dev, const u8 *addr)
+{
+ pr_debug("%s: TODO (if we want to)\n", __func__);
+}
+
+static inline int
+eth_platform_get_mac_address(struct device *dev __unused, u8 *addr __unused)
+{
+ pr_debug("%s: TODO\n", __func__);
+ return (-ENODEV);
+}
+
+#endif /* _LINUXKPI_LINUX_ETHERDEVICE_H_ */
diff --git a/sys/compat/linuxkpi/common/include/linux/ethtool.h b/sys/compat/linuxkpi/common/include/linux/ethtool.h
new file mode 100644
index 000000000000..f5567cd7ea40
--- /dev/null
+++ b/sys/compat/linuxkpi/common/include/linux/ethtool.h
@@ -0,0 +1,57 @@
+/*-
+ * SPDX-License-Identifier: BSD-2-Clause
+ *
+ * Copyright (c) 2022 Bjoern A. Zeeb
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``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 OR CONTRIBUTORS 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.
+ */
+
+#ifndef _LINUXKPI_LINUX_ETHTOOL_H_
+#define _LINUXKPI_LINUX_ETHTOOL_H_
+
+#include <linux/types.h>
+
+#define ETH_GSTRING_LEN (2 * IF_NAMESIZE) /* Increase if not large enough */
+
+#define ETHTOOL_FWVERS_LEN 32
+
+struct ethtool_stats {
+ uint8_t __dummy[0];
+};
+
+enum ethtool_ss {
+ ETH_SS_STATS,
+};
+
+struct ethtool_drvinfo {
+ char driver[32];
+ char version[32];
+ char fw_version[ETHTOOL_FWVERS_LEN];
+ char bus_info[32];
+};
+
+struct net_device;
+struct ethtool_ops {
+ void(*get_drvinfo)(struct net_device *, struct ethtool_drvinfo *);
+};
+
+#endif /* _LINUXKPI_LINUX_ETHTOOL_H_ */
diff --git a/sys/compat/linuxkpi/common/include/linux/eventpoll.h b/sys/compat/linuxkpi/common/include/linux/eventpoll.h
new file mode 100644
index 000000000000..e77e6d689f86
--- /dev/null
+++ b/sys/compat/linuxkpi/common/include/linux/eventpoll.h
@@ -0,0 +1,45 @@
+/*-
+ * SPDX-License-Identifier: BSD-2-Clause
+ *
+ * Copyright (c) 2022, Jake Freeland <jfree@freebsd.org>
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice unmodified, this list of conditions, and the following
+ * disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``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.
+ */
+
+#ifndef _LINUXKPI_LINUX_EVENTPOLL_H_
+#define _LINUXKPI_LINUX_EVENTPOLL_H_
+
+#include <sys/poll.h>
+
+#define EPOLLIN POLLIN
+#define EPOLLPRI POLLPRI
+#define EPOLLOUT POLLOUT
+#define EPOLLERR POLLERR
+#define EPOLLHUP POLLHUP
+#define EPOLLNVAL POLLNVAL
+#define EPOLLRDNORM POLLRDNORM
+#define EPOLLRDBAND POLLRDBAND
+#define EPOLLWRNORM POLLWRNORM
+#define EPOLLWRBAND POLLWRBAND
+#define EPOLLRDHUP POLLRDHUP
+
+#endif /* _LINUXKPI_LINUX_EVENTPOLL_H_ */
diff --git a/sys/compat/linuxkpi/common/include/linux/export.h b/sys/compat/linuxkpi/common/include/linux/export.h
index 00d51114f774..f48bd6af45d3 100644
--- a/sys/compat/linuxkpi/common/include/linux/export.h
+++ b/sys/compat/linuxkpi/common/include/linux/export.h
@@ -21,11 +21,9 @@
* 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.
- *
- * $FreeBSD$
*/
-#ifndef _LINUX_EXPORT_H
-#define _LINUX_EXPORT_H
+#ifndef _LINUXKPI_LINUX_EXPORT_H
+#define _LINUXKPI_LINUX_EXPORT_H
#define EXPORT_SYMBOL(name)
#define EXPORT_SYMBOL_GPL(name)
diff --git a/sys/compat/linuxkpi/common/include/linux/file.h b/sys/compat/linuxkpi/common/include/linux/file.h
index 21b254211cfd..f6e988c2d88e 100644
--- a/sys/compat/linuxkpi/common/include/linux/file.h
+++ b/sys/compat/linuxkpi/common/include/linux/file.h
@@ -25,11 +25,9 @@
* 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.
- *
- * $FreeBSD$
*/
-#ifndef _LINUX_FILE_H_
-#define _LINUX_FILE_H_
+#ifndef _LINUXKPI_LINUX_FILE_H_
+#define _LINUXKPI_LINUX_FILE_H_
#include <sys/param.h>
#include <sys/file.h>
@@ -45,7 +43,7 @@ struct linux_file;
#undef file
-extern struct fileops linuxfileops;
+extern const struct fileops linuxfileops;
static inline struct linux_file *
linux_fget(unsigned int fd)
@@ -53,8 +51,7 @@ linux_fget(unsigned int fd)
struct file *file;
/* lookup file pointer by file descriptor index */
- if (fget_unlocked(curthread->td_proc->p_fd, fd,
- &cap_no_rights, &file) != 0)
+ if (fget_unlocked(curthread, fd, &cap_no_rights, &file) != 0)
return (NULL);
/* check if file handle really belongs to us */
@@ -89,8 +86,7 @@ put_unused_fd(unsigned int fd)
{
struct file *file;
- if (fget_unlocked(curthread->td_proc->p_fd, fd,
- &cap_no_rights, &file) != 0) {
+ if (fget_unlocked(curthread, fd, &cap_no_rights, &file) != 0) {
return;
}
/*
@@ -109,8 +105,7 @@ fd_install(unsigned int fd, struct linux_file *filp)
{
struct file *file;
- if (fget_unlocked(curthread->td_proc->p_fd, fd,
- &cap_no_rights, &file) != 0) {
+ if (fget_unlocked(curthread, fd, &cap_no_rights, &file) != 0) {
filp->_file = NULL;
} else {
filp->_file = file;
@@ -187,4 +182,4 @@ static inline struct fd fdget(unsigned int fd)
#define file linux_file
#define fget(...) linux_fget(__VA_ARGS__)
-#endif /* _LINUX_FILE_H_ */
+#endif /* _LINUXKPI_LINUX_FILE_H_ */
diff --git a/sys/compat/linuxkpi/common/include/linux/fips.h b/sys/compat/linuxkpi/common/include/linux/fips.h
new file mode 100644
index 000000000000..25c0c1fc1fa0
--- /dev/null
+++ b/sys/compat/linuxkpi/common/include/linux/fips.h
@@ -0,0 +1,12 @@
+/*
+ * Copyright (c) 2025 Bjoern A. Zeeb
+ *
+ * SPDX-License-Identifier: BSD-2-Clause
+ */
+
+#ifndef _LINUXKPI_LINUX_FIPS_H
+#define _LINUXKPI_LINUX_FIPS_H
+
+#define fips_enabled 0
+
+#endif /* _LINUXKPI_LINUX_FIPS_H */
diff --git a/sys/compat/linuxkpi/common/include/linux/firmware.h b/sys/compat/linuxkpi/common/include/linux/firmware.h
index ada7d0d73edf..a6330ddafb55 100644
--- a/sys/compat/linuxkpi/common/include/linux/firmware.h
+++ b/sys/compat/linuxkpi/common/include/linux/firmware.h
@@ -2,6 +2,7 @@
* SPDX-License-Identifier: BSD-2-Clause
*
* Copyright (c) 2020-2021 The FreeBSD Foundation
+ * Copyright (c) 2022 Bjoern A. Zeeb
*
* This software was developed by Björn Zeeb under sponsorship from
* the FreeBSD Foundation.
@@ -26,8 +27,6 @@
* 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.
- *
- * $FreeBSD$
*/
#ifndef _LINUXKPI_LINUX_FIRMWARE_H
@@ -56,6 +55,8 @@ int linuxkpi_request_firmware(const struct linuxkpi_firmware **,
int linuxkpi_firmware_request_nowarn(const struct linuxkpi_firmware **,
const char *, struct device *);
void linuxkpi_release_firmware(const struct linuxkpi_firmware *);
+int linuxkpi_request_partial_firmware_into_buf(const struct linuxkpi_firmware **,
+ const char *, struct device *, uint8_t *, size_t, size_t);
static __inline int
@@ -100,6 +101,16 @@ release_firmware(const struct linuxkpi_firmware *fw)
linuxkpi_release_firmware(fw);
}
+static inline int
+request_partial_firmware_into_buf(const struct linuxkpi_firmware **fw,
+ const char *fw_name, struct device *dev, void *buf, size_t buflen,
+ size_t offset)
+{
+
+ return (linuxkpi_request_partial_firmware_into_buf(fw, fw_name,
+ dev, buf, buflen, offset));
+}
+
#define firmware linuxkpi_firmware
#endif /* _LINUXKPI_LINUX_FIRMWARE_H */
diff --git a/sys/compat/linuxkpi/common/include/linux/fs.h b/sys/compat/linuxkpi/common/include/linux/fs.h
index f1892352d598..f1568ad6282d 100644
--- a/sys/compat/linuxkpi/common/include/linux/fs.h
+++ b/sys/compat/linuxkpi/common/include/linux/fs.h
@@ -25,13 +25,10 @@
* 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.
- *
- * $FreeBSD$
*/
-#ifndef _LINUX_FS_H_
-#define _LINUX_FS_H_
+#ifndef _LINUXKPI_LINUX_FS_H_
+#define _LINUXKPI_LINUX_FS_H_
-#include <sys/cdefs.h>
#include <sys/param.h>
#include <sys/systm.h>
#include <sys/conf.h>
@@ -43,6 +40,10 @@
#include <linux/semaphore.h>
#include <linux/spinlock.h>
#include <linux/dcache.h>
+#include <linux/capability.h>
+#include <linux/wait_bit.h>
+#include <linux/kernel.h>
+#include <linux/mutex.h>
struct module;
struct kiocb;
@@ -149,6 +150,11 @@ struct file_operations {
* an illegal seek error
*/
off_t (*llseek)(struct linux_file *, off_t, int);
+/*
+ * Not supported in FreeBSD. That's ok, we never call it and it allows some
+ * drivers like DRM drivers to compile without changes.
+ */
+ void (*show_fdinfo)(struct seq_file *, struct file *);
#if 0
/* We do not support these methods. Don't permit them to compile. */
loff_t (*llseek)(struct file *, loff_t, int);
@@ -248,6 +254,7 @@ nonseekable_open(struct inode *inode, struct file *filp)
static inline int
simple_open(struct inode *inode, struct file *filp)
{
+ filp->private_data = inode->i_private;
return 0;
}
@@ -262,12 +269,18 @@ get_file(struct linux_file *f)
return (f);
}
+struct linux_file * linux_get_file_rcu(struct linux_file **f);
+struct linux_file * get_file_active(struct linux_file **f);
+#if defined(LINUXKPI_VERSION) && LINUXKPI_VERSION < 60700
static inline bool
get_file_rcu(struct linux_file *f)
{
return (refcount_acquire_if_not_zero(
f->_file == NULL ? &f->f_count : &f->_file->f_count));
}
+#else
+#define get_file_rcu(f) linux_get_file_rcu(f)
+#endif
static inline struct inode *
igrab(struct inode *inode)
@@ -296,6 +309,18 @@ no_llseek(struct file *file, loff_t offset, int whence)
}
static inline loff_t
+default_llseek(struct file *file, loff_t offset, int whence)
+{
+ return (no_llseek(file, offset, whence));
+}
+
+static inline loff_t
+generic_file_llseek(struct file *file, loff_t offset, int whence)
+{
+ return (no_llseek(file, offset, whence));
+}
+
+static inline loff_t
noop_llseek(struct linux_file *file, loff_t offset, int whence)
{
@@ -316,4 +341,85 @@ call_mmap(struct linux_file *file, struct vm_area_struct *vma)
return (file->f_op->mmap(file, vma));
}
-#endif /* _LINUX_FS_H_ */
+static inline void
+i_size_write(struct inode *inode, loff_t i_size)
+{
+}
+
+/*
+ * simple_read_from_buffer: copy data from kernel-space origin
+ * buffer into user-space destination buffer
+ *
+ * @dest: destination buffer
+ * @read_size: number of bytes to be transferred
+ * @ppos: starting transfer position pointer
+ * @orig: origin buffer
+ * @buf_size: size of destination and origin buffers
+ *
+ * Return value:
+ * On success, total bytes copied with *ppos incremented accordingly.
+ * On failure, negative value.
+ */
+static inline ssize_t
+simple_read_from_buffer(void __user *dest, size_t read_size, loff_t *ppos,
+ void *orig, size_t buf_size)
+{
+ void *p, *read_pos = ((char *) orig) + *ppos;
+ size_t buf_remain = buf_size - *ppos;
+
+ if (buf_remain < 0 || buf_remain > buf_size)
+ return -EINVAL;
+
+ if (read_size > buf_remain)
+ read_size = buf_remain;
+
+ /*
+ * XXX At time of commit only debugfs consumers could be
+ * identified. If others will use this function we may
+ * have to revise this: normally we would call copy_to_user()
+ * here but lindebugfs will return the result and the
+ * copyout is done elsewhere for us.
+ */
+ p = memcpy(dest, read_pos, read_size);
+ if (p != NULL)
+ *ppos += read_size;
+
+ return (read_size);
+}
+
+MALLOC_DECLARE(M_LSATTR);
+
+#define __DEFINE_SIMPLE_ATTRIBUTE(__fops, __get, __set, __fmt, __wrfunc)\
+static inline int \
+__fops ## _open(struct inode *inode, struct file *filp) \
+{ \
+ return (simple_attr_open(inode, filp, __get, __set, __fmt)); \
+} \
+static const struct file_operations __fops = { \
+ .owner = THIS_MODULE, \
+ .open = __fops ## _open, \
+ .release = simple_attr_release, \
+ .read = simple_attr_read, \
+ .write = __wrfunc, \
+ .llseek = no_llseek \
+}
+
+#define DEFINE_SIMPLE_ATTRIBUTE(fops, get, set, fmt) \
+ __DEFINE_SIMPLE_ATTRIBUTE(fops, get, set, fmt, simple_attr_write)
+#define DEFINE_SIMPLE_ATTRIBUTE_SIGNED(fops, get, set, fmt) \
+ __DEFINE_SIMPLE_ATTRIBUTE(fops, get, set, fmt, simple_attr_write_signed)
+
+int simple_attr_open(struct inode *inode, struct file *filp,
+ int (*get)(void *, uint64_t *), int (*set)(void *, uint64_t),
+ const char *fmt);
+
+int simple_attr_release(struct inode *inode, struct file *filp);
+
+ssize_t simple_attr_read(struct file *filp, char *buf, size_t read_size, loff_t *ppos);
+
+ssize_t simple_attr_write(struct file *filp, const char *buf, size_t write_size, loff_t *ppos);
+
+ssize_t simple_attr_write_signed(struct file *filp, const char *buf,
+ size_t write_size, loff_t *ppos);
+
+#endif /* _LINUXKPI_LINUX_FS_H_ */
diff --git a/sys/compat/linuxkpi/common/include/linux/fwnode.h b/sys/compat/linuxkpi/common/include/linux/fwnode.h
new file mode 100644
index 000000000000..a1fbc1b6d6a3
--- /dev/null
+++ b/sys/compat/linuxkpi/common/include/linux/fwnode.h
@@ -0,0 +1,10 @@
+/* Public domain. */
+
+#ifndef _LINUXKPI_LINUX_FWNODE_H_
+#define _LINUXKPI_LINUX_FWNODE_H_
+
+struct fwnode_handle {
+ struct fwnode_handle *secondary;
+};
+
+#endif /* _LINUXKPI_LINUX_FWNODE_H_ */
diff --git a/sys/compat/linuxkpi/common/include/linux/gcd.h b/sys/compat/linuxkpi/common/include/linux/gcd.h
index bff28340cfae..5ca0540e5102 100644
--- a/sys/compat/linuxkpi/common/include/linux/gcd.h
+++ b/sys/compat/linuxkpi/common/include/linux/gcd.h
@@ -25,12 +25,10 @@
* 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.
- *
- * $FreeBSD$
*/
-#ifndef _LINUX_GCD_H_
-#define _LINUX_GCD_H_
+#ifndef _LINUXKPI_LINUX_GCD_H_
+#define _LINUXKPI_LINUX_GCD_H_
static inline unsigned long
gcd(unsigned long a, unsigned long b)
diff --git a/sys/compat/linuxkpi/common/include/linux/gfp.h b/sys/compat/linuxkpi/common/include/linux/gfp.h
index 1366e75ad26a..7a32e7862338 100644
--- a/sys/compat/linuxkpi/common/include/linux/gfp.h
+++ b/sys/compat/linuxkpi/common/include/linux/gfp.h
@@ -25,18 +25,16 @@
* 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.
- *
- * $FreeBSD$
*/
-#ifndef _LINUX_GFP_H_
-#define _LINUX_GFP_H_
+#ifndef _LINUXKPI_LINUX_GFP_H_
+#define _LINUXKPI_LINUX_GFP_H_
-#include <sys/cdefs.h>
#include <sys/types.h>
#include <sys/systm.h>
#include <sys/malloc.h>
#include <linux/page.h>
+#include <linux/topology.h>
#include <vm/vm_param.h>
#include <vm/vm_object.h>
@@ -46,7 +44,7 @@
#define __GFP_NOWARN 0
#define __GFP_HIGHMEM 0
#define __GFP_ZERO M_ZERO
-#define __GFP_NORETRY 0
+#define __GFP_NOMEMALLOC 0
#define __GFP_RECLAIM 0
#define __GFP_RECLAIMABLE 0
#define __GFP_RETRY_MAYFAIL 0
@@ -59,7 +57,8 @@
#define __GFP_KSWAPD_RECLAIM 0
#define __GFP_WAIT M_WAITOK
#define __GFP_DMA32 (1U << 24) /* LinuxKPI only */
-#define __GFP_BITS_SHIFT 25
+#define __GFP_NORETRY (1U << 25) /* LinuxKPI only */
+#define __GFP_BITS_SHIFT 26
#define __GFP_BITS_MASK ((1 << __GFP_BITS_SHIFT) - 1)
#define __GFP_NOFAIL M_WAITOK
@@ -71,6 +70,7 @@
#define GFP_HIGHUSER_MOVABLE M_WAITOK
#define GFP_IOFS M_NOWAIT
#define GFP_NOIO M_NOWAIT
+#define GFP_NOFS M_NOWAIT
#define GFP_DMA32 __GFP_DMA32
#define GFP_TEMPORARY M_NOWAIT
#define GFP_NATIVE_MASK (M_NOWAIT | M_WAITOK | M_USE_RESERVE | M_ZERO)
@@ -80,20 +80,19 @@
CTASSERT((__GFP_DMA32 & GFP_NATIVE_MASK) == 0);
CTASSERT((__GFP_BITS_MASK & GFP_NATIVE_MASK) == GFP_NATIVE_MASK);
-/*
- * Resolve a page into a virtual address:
- *
- * NOTE: This function only works for pages allocated by the kernel.
- */
-extern void *linux_page_address(struct page *);
-
-#define page_address(page) linux_page_address(page)
+struct page_frag_cache {
+ void *va;
+ int pagecnt_bias;
+};
/*
* Page management for unmapped pages:
*/
-extern vm_page_t linux_alloc_pages(gfp_t flags, unsigned int order);
-extern void linux_free_pages(vm_page_t page, unsigned int order);
+struct page *linux_alloc_pages(gfp_t flags, unsigned int order);
+void linux_free_pages(struct page *page, unsigned int order);
+void *linuxkpi_page_frag_alloc(struct page_frag_cache *, size_t, gfp_t);
+void linuxkpi_page_frag_free(void *);
+void linuxkpi__page_frag_cache_drain(struct page *, size_t);
static inline struct page *
alloc_page(gfp_t flags)
@@ -130,11 +129,19 @@ __free_page(struct page *page)
linux_free_pages(page, 0);
}
+static inline struct page *
+dev_alloc_pages(unsigned int order)
+{
+ return (linux_alloc_pages(GFP_ATOMIC, order));
+}
+
+struct folio *folio_alloc(gfp_t gfp, unsigned int order);
+
/*
* Page management for mapped pages:
*/
-extern vm_offset_t linux_alloc_kmem(gfp_t flags, unsigned int order);
-extern void linux_free_kmem(vm_offset_t, unsigned int order);
+vm_offset_t linux_alloc_kmem(gfp_t flags, unsigned int order);
+void linux_free_kmem(vm_offset_t, unsigned int order);
static inline vm_offset_t
get_zeroed_page(gfp_t flags)
@@ -175,6 +182,27 @@ free_page(uintptr_t addr)
linux_free_kmem(addr, 0);
}
+static inline void *
+page_frag_alloc(struct page_frag_cache *pfc, size_t fragsz, gfp_t gfp)
+{
+
+ return (linuxkpi_page_frag_alloc(pfc, fragsz, gfp));
+}
+
+static inline void
+page_frag_free(void *addr)
+{
+
+ linuxkpi_page_frag_free(addr);
+}
+
+static inline void
+__page_frag_cache_drain(struct page *page, size_t count)
+{
+
+ linuxkpi__page_frag_cache_drain(page, count);
+}
+
static inline bool
gfpflags_allow_blocking(const gfp_t gfp_flags)
{
@@ -184,4 +212,4 @@ gfpflags_allow_blocking(const gfp_t gfp_flags)
#define SetPageReserved(page) do { } while (0) /* NOP */
#define ClearPageReserved(page) do { } while (0) /* NOP */
-#endif /* _LINUX_GFP_H_ */
+#endif /* _LINUXKPI_LINUX_GFP_H_ */
diff --git a/sys/compat/linuxkpi/common/include/linux/gpf.h b/sys/compat/linuxkpi/common/include/linux/gpf.h
new file mode 100644
index 000000000000..01e883a94728
--- /dev/null
+++ b/sys/compat/linuxkpi/common/include/linux/gpf.h
@@ -0,0 +1,33 @@
+/*-
+ * SPDX-License-Identifier: BSD-2-Clause
+ *
+ * Copyright (c) 2024 Serenity Cyber Security, LLC.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``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 OR CONTRIBUTORS 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.
+ */
+
+#ifndef _LINUXKPI_LINUX_GPF_H_
+#define _LINUXKPI_LINUX_GPF_H_
+
+#include <linux/mmzone.h>
+
+#endif /* _LINUXKPI_LINUX_GPF_H_ */
diff --git a/sys/compat/linuxkpi/common/include/linux/hardirq.h b/sys/compat/linuxkpi/common/include/linux/hardirq.h
index d338e11c5a6f..f79451dd0d35 100644
--- a/sys/compat/linuxkpi/common/include/linux/hardirq.h
+++ b/sys/compat/linuxkpi/common/include/linux/hardirq.h
@@ -25,11 +25,9 @@
* 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.
- *
- * $FreeBSD$
*/
-#ifndef _LINUX_HARDIRQ_H_
-#define _LINUX_HARDIRQ_H_
+#ifndef _LINUXKPI_LINUX_HARDIRQ_H_
+#define _LINUXKPI_LINUX_HARDIRQ_H_
#include <linux/types.h>
#include <linux/lockdep.h>
@@ -40,4 +38,14 @@
#define synchronize_irq(irq) _intr_drain((irq))
-#endif /* _LINUX_HARDIRQ_H_ */
+/*
+ * FIXME: In the i915 driver's `intel_engine_cs.c` file,
+ * `synchronize_hardirq()` was replaced by `synchronize_rcu()` with the
+ * following comment:
+ * "Is it enough to wait that all cpu have context-switched?"
+ *
+ * See commit f6d50b7af554e21c380486d6f41c8537b265c777 in drm-kmod.
+ */
+#define synchronize_hardirq(irq) _intr_drain((irq))
+
+#endif /* _LINUXKPI_LINUX_HARDIRQ_H_ */
diff --git a/sys/compat/linuxkpi/common/include/linux/hash.h b/sys/compat/linuxkpi/common/include/linux/hash.h
new file mode 100644
index 000000000000..c75814c96724
--- /dev/null
+++ b/sys/compat/linuxkpi/common/include/linux/hash.h
@@ -0,0 +1,76 @@
+/*
+ * SPDX-License-Identifier: BSD-2-Clause
+ *
+ * Copyright (c) 2022 NVIDIA corporation & affiliates.
+ * Copyright (c) 2013 François Tigeot
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice unmodified, this list of conditions, and the following
+ * disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``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.
+ */
+
+#ifndef _LINUXKPI_LINUX_HASH_H_
+#define _LINUXKPI_LINUX_HASH_H_
+
+#include <sys/hash.h>
+#include <sys/param.h>
+#include <sys/systm.h>
+
+#include <asm/types.h>
+
+#include <linux/bitops.h>
+
+static inline u64
+hash_64(u64 val, u8 bits)
+{
+ u64 ret;
+ u8 x;
+
+ ret = bits;
+
+ for (x = 0; x != sizeof(ret); x++) {
+ u64 chunk = (val >> (8 * x)) & 0xFF;
+ ret = HASHSTEP(ret, chunk);
+ }
+ return (ret >> (64 - bits));
+}
+
+static inline u32
+hash_32(u32 val, u8 bits)
+{
+ u32 ret;
+ u8 x;
+
+ ret = bits;
+
+ for (x = 0; x != sizeof(ret); x++) {
+ u32 chunk = (val >> (8 * x)) & 0xFF;
+ ret = HASHSTEP(ret, chunk);
+ }
+ return (ret >> (32 - bits));
+}
+
+#if BITS_PER_LONG == 64
+#define hash_long(...) hash_64(__VA_ARGS__)
+#else
+#define hash_long(...) hash_32(__VA_ARGS__)
+#endif
+
+#endif /* _LINUXKPI_LINUX_HASH_H_ */
diff --git a/sys/compat/linuxkpi/common/include/linux/hashtable.h b/sys/compat/linuxkpi/common/include/linux/hashtable.h
new file mode 100644
index 000000000000..55755c354959
--- /dev/null
+++ b/sys/compat/linuxkpi/common/include/linux/hashtable.h
@@ -0,0 +1,183 @@
+/*-
+ * SPDX-License-Identifier: BSD-2-Clause
+ *
+ * Copyright (c) 2022 NVIDIA corporation & affiliates.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice unmodified, this list of conditions, and the following
+ * disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``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.
+ */
+
+#ifndef _LINUXKPI_LINUX_HASHTABLE_H
+#define _LINUXKPI_LINUX_HASHTABLE_H
+
+#include <sys/param.h>
+#include <sys/systm.h>
+
+#include <linux/hash.h>
+#include <linux/kernel.h>
+#include <linux/list.h>
+#include <linux/log2.h>
+#include <linux/rcupdate.h>
+#include <linux/rculist.h>
+
+#include <ck_queue.h>
+
+struct lkpi_hash_entry {
+ CK_LIST_ENTRY(lkpi_hash_entry) entry;
+};
+
+struct lkpi_hash_head {
+ CK_LIST_HEAD(, lkpi_hash_entry) head;
+};
+
+#define DEFINE_HASHTABLE(name, bits) \
+ struct lkpi_hash_head name[1UL << (bits)]
+
+#define DEFINE_READ_MOSTLY_HASHTABLE(name, bits) \
+ struct lkpi_hash_head name[1UL << (bits)] __read_mostly
+
+#define DECLARE_HASHTABLE(name, bits) \
+ struct lkpi_hash_head name[1UL << (bits)]
+
+#define HASH_SIZE(name) ARRAY_SIZE(name)
+#define HASH_BITS(name) ilog2(HASH_SIZE(name))
+
+#define hash_min(...) \
+ hash_long(__VA_ARGS__)
+
+static inline void
+__hash_init(struct lkpi_hash_head *ht, unsigned long size)
+{
+ unsigned long x;
+
+ for (x = 0; x != size; x++)
+ CK_LIST_INIT(&ht[x].head);
+}
+
+#define hash_init(ht) \
+ __hash_init(ht, HASH_SIZE(ht))
+
+#define hash_add(...) \
+ hash_add_rcu(__VA_ARGS__)
+
+static inline void
+__hash_node_type_assert(struct hlist_node *node)
+{
+ /*
+ * Unfortunately Linux doesn't have an own type for the hash
+ * table node entries. The purpose of this function is simply
+ * to check the type of the passed argument.
+ */
+ CTASSERT(sizeof(struct lkpi_hash_entry) == sizeof(*node));
+}
+
+#define hash_add_rcu(ht, node, key) do { \
+ struct lkpi_hash_head *__head = &(ht)[hash_min(key, HASH_BITS(ht))]; \
+ __hash_node_type_assert(node); \
+ CK_LIST_INSERT_HEAD(&__head->head, \
+ (struct lkpi_hash_entry *)(node), entry); \
+} while (0)
+
+static inline bool
+hash_hashed(struct hlist_node *node)
+{
+ return (((struct lkpi_hash_entry *)node)->entry.cle_prev != NULL);
+}
+
+static inline bool
+__hash_empty(struct lkpi_hash_head *ht, unsigned long size)
+{
+ unsigned long x;
+
+ for (x = 0; x != size; x++) {
+ if (!CK_LIST_EMPTY(&ht[x].head))
+ return (false);
+ }
+ return (true);
+}
+
+#define hash_empty(ht) \
+ __hash_empty(ht, HASH_SIZE(ht))
+
+#define hash_del(...) \
+ hash_del_rcu(__VA_ARGS__)
+
+static inline void
+hash_del_rcu(struct hlist_node *node)
+{
+ CK_LIST_REMOVE((struct lkpi_hash_entry *)node, entry);
+ memset(node, 0, sizeof(*node));
+}
+
+#define __hash_first(ht, type, member) ({ \
+ const struct lkpi_hash_entry *__first = CK_LIST_FIRST(&(ht)->head); \
+ __hash_node_type_assert(&((type *)0)->member); \
+ (__first != NULL ? container_of((const void *)__first, type, member) : NULL); \
+})
+
+#define __hash_next(obj, type, member) ({ \
+ const struct lkpi_hash_entry *__next = \
+ CK_LIST_NEXT((struct lkpi_hash_entry *)&(obj)->member, entry); \
+ __hash_node_type_assert(&(obj)->member); \
+ (__next != NULL ? container_of((const void *)__next, type, member) : NULL); \
+})
+
+#define hash_for_each(...) \
+ hash_for_each_rcu(__VA_ARGS__)
+
+#define hash_for_each_rcu(name, bkt, obj, member) \
+ for ((bkt) = 0, (obj) = NULL; (obj) == NULL && \
+ (bkt) != HASH_SIZE(name); (bkt)++) \
+ for ((obj) = __hash_first(&(name)[bkt], \
+ __typeof(*(obj)), member); \
+ (obj) != NULL; \
+ (obj) = __hash_next(obj, \
+ __typeof(*(obj)), member))
+
+#define hash_for_each_safe(name, bkt, tmp, obj, member) \
+ for ((bkt) = 0, (obj) = NULL; (obj) == NULL && \
+ (bkt) != HASH_SIZE(name); (bkt)++) \
+ for ((obj) = __hash_first(&(name)[bkt], \
+ __typeof(*(obj)), member); \
+ (obj) != NULL && ((tmp) = &__hash_next(obj, \
+ __typeof(*(obj)), member)->member, 1); \
+ (obj) = container_of(tmp, __typeof(*(obj)), member))
+
+#define hash_for_each_possible(...) \
+ hash_for_each_possible_rcu(__VA_ARGS__)
+
+#define hash_for_each_possible_rcu_notrace(...) \
+ hash_for_each_possible_rcu(__VA_ARGS__)
+
+#define hash_for_each_possible_rcu(name, obj, member, key) \
+ for ((obj) = __hash_first(&(name)[hash_min(key, HASH_BITS(name))], \
+ __typeof(*(obj)), member); \
+ (obj) != NULL; \
+ (obj) = __hash_next(obj, __typeof(*(obj)), member))
+
+#define hash_for_each_possible_safe(name, obj, tmp, member, key) \
+ for ((obj) = __hash_first(&(name)[hash_min(key, HASH_BITS(name))], \
+ __typeof(*(obj)), member); \
+ (obj) != NULL && ((tmp) = &__hash_next(obj, \
+ __typeof(*(obj)), member)->member, 1); \
+ (obj) = container_of(tmp, __typeof(*(obj)), member))
+
+#endif /* _LINUXKPI_LINUX_HASHTABLE_H */
diff --git a/sys/compat/linuxkpi/common/include/linux/hdmi.h b/sys/compat/linuxkpi/common/include/linux/hdmi.h
new file mode 100644
index 000000000000..e07578167d69
--- /dev/null
+++ b/sys/compat/linuxkpi/common/include/linux/hdmi.h
@@ -0,0 +1,447 @@
+/*
+ * Copyright (C) 2012 Avionic Design GmbH
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sub license,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice (including the
+ * next paragraph) shall be included in all copies or substantial portions
+ * of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL
+ * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+ * DEALINGS IN THE SOFTWARE.
+ */
+
+#ifndef __LINUX_HDMI_H_
+#define __LINUX_HDMI_H_
+
+#include <linux/types.h>
+#include <linux/device.h>
+
+enum hdmi_packet_type {
+ HDMI_PACKET_TYPE_NULL = 0x00,
+ HDMI_PACKET_TYPE_AUDIO_CLOCK_REGEN = 0x01,
+ HDMI_PACKET_TYPE_AUDIO_SAMPLE = 0x02,
+ HDMI_PACKET_TYPE_GENERAL_CONTROL = 0x03,
+ HDMI_PACKET_TYPE_ACP = 0x04,
+ HDMI_PACKET_TYPE_ISRC1 = 0x05,
+ HDMI_PACKET_TYPE_ISRC2 = 0x06,
+ HDMI_PACKET_TYPE_ONE_BIT_AUDIO_SAMPLE = 0x07,
+ HDMI_PACKET_TYPE_DST_AUDIO = 0x08,
+ HDMI_PACKET_TYPE_HBR_AUDIO_STREAM = 0x09,
+ HDMI_PACKET_TYPE_GAMUT_METADATA = 0x0a,
+ /* + enum hdmi_infoframe_type */
+};
+
+enum hdmi_infoframe_type {
+ HDMI_INFOFRAME_TYPE_VENDOR = 0x81,
+ HDMI_INFOFRAME_TYPE_AVI = 0x82,
+ HDMI_INFOFRAME_TYPE_SPD = 0x83,
+ HDMI_INFOFRAME_TYPE_AUDIO = 0x84,
+ HDMI_INFOFRAME_TYPE_DRM = 0x87,
+};
+
+#define HDMI_IEEE_OUI 0x000c03
+#define HDMI_FORUM_IEEE_OUI 0xc45dd8
+#define HDMI_INFOFRAME_HEADER_SIZE 4
+#define HDMI_AVI_INFOFRAME_SIZE 13
+#define HDMI_SPD_INFOFRAME_SIZE 25
+#define HDMI_AUDIO_INFOFRAME_SIZE 10
+#define HDMI_DRM_INFOFRAME_SIZE 26
+#define HDMI_VENDOR_INFOFRAME_SIZE 4
+
+#define HDMI_INFOFRAME_SIZE(type) \
+ (HDMI_INFOFRAME_HEADER_SIZE + HDMI_ ## type ## _INFOFRAME_SIZE)
+
+struct hdmi_any_infoframe {
+ enum hdmi_infoframe_type type;
+ unsigned char version;
+ unsigned char length;
+};
+
+enum hdmi_colorspace {
+ HDMI_COLORSPACE_RGB,
+ HDMI_COLORSPACE_YUV422,
+ HDMI_COLORSPACE_YUV444,
+ HDMI_COLORSPACE_YUV420,
+ HDMI_COLORSPACE_RESERVED4,
+ HDMI_COLORSPACE_RESERVED5,
+ HDMI_COLORSPACE_RESERVED6,
+ HDMI_COLORSPACE_IDO_DEFINED,
+};
+
+enum hdmi_scan_mode {
+ HDMI_SCAN_MODE_NONE,
+ HDMI_SCAN_MODE_OVERSCAN,
+ HDMI_SCAN_MODE_UNDERSCAN,
+ HDMI_SCAN_MODE_RESERVED,
+};
+
+enum hdmi_colorimetry {
+ HDMI_COLORIMETRY_NONE,
+ HDMI_COLORIMETRY_ITU_601,
+ HDMI_COLORIMETRY_ITU_709,
+ HDMI_COLORIMETRY_EXTENDED,
+};
+
+enum hdmi_picture_aspect {
+ HDMI_PICTURE_ASPECT_NONE,
+ HDMI_PICTURE_ASPECT_4_3,
+ HDMI_PICTURE_ASPECT_16_9,
+ HDMI_PICTURE_ASPECT_64_27,
+ HDMI_PICTURE_ASPECT_256_135,
+ HDMI_PICTURE_ASPECT_RESERVED,
+};
+
+enum hdmi_active_aspect {
+ HDMI_ACTIVE_ASPECT_16_9_TOP = 2,
+ HDMI_ACTIVE_ASPECT_14_9_TOP = 3,
+ HDMI_ACTIVE_ASPECT_16_9_CENTER = 4,
+ HDMI_ACTIVE_ASPECT_PICTURE = 8,
+ HDMI_ACTIVE_ASPECT_4_3 = 9,
+ HDMI_ACTIVE_ASPECT_16_9 = 10,
+ HDMI_ACTIVE_ASPECT_14_9 = 11,
+ HDMI_ACTIVE_ASPECT_4_3_SP_14_9 = 13,
+ HDMI_ACTIVE_ASPECT_16_9_SP_14_9 = 14,
+ HDMI_ACTIVE_ASPECT_16_9_SP_4_3 = 15,
+};
+
+enum hdmi_extended_colorimetry {
+ HDMI_EXTENDED_COLORIMETRY_XV_YCC_601,
+ HDMI_EXTENDED_COLORIMETRY_XV_YCC_709,
+ HDMI_EXTENDED_COLORIMETRY_S_YCC_601,
+ HDMI_EXTENDED_COLORIMETRY_OPYCC_601,
+ HDMI_EXTENDED_COLORIMETRY_OPRGB,
+
+ /* The following EC values are only defined in CEA-861-F. */
+ HDMI_EXTENDED_COLORIMETRY_BT2020_CONST_LUM,
+ HDMI_EXTENDED_COLORIMETRY_BT2020,
+ HDMI_EXTENDED_COLORIMETRY_RESERVED,
+};
+
+enum hdmi_quantization_range {
+ HDMI_QUANTIZATION_RANGE_DEFAULT,
+ HDMI_QUANTIZATION_RANGE_LIMITED,
+ HDMI_QUANTIZATION_RANGE_FULL,
+ HDMI_QUANTIZATION_RANGE_RESERVED,
+};
+
+/* non-uniform picture scaling */
+enum hdmi_nups {
+ HDMI_NUPS_UNKNOWN,
+ HDMI_NUPS_HORIZONTAL,
+ HDMI_NUPS_VERTICAL,
+ HDMI_NUPS_BOTH,
+};
+
+enum hdmi_ycc_quantization_range {
+ HDMI_YCC_QUANTIZATION_RANGE_LIMITED,
+ HDMI_YCC_QUANTIZATION_RANGE_FULL,
+};
+
+enum hdmi_content_type {
+ HDMI_CONTENT_TYPE_GRAPHICS,
+ HDMI_CONTENT_TYPE_PHOTO,
+ HDMI_CONTENT_TYPE_CINEMA,
+ HDMI_CONTENT_TYPE_GAME,
+};
+
+enum hdmi_metadata_type {
+ HDMI_STATIC_METADATA_TYPE1 = 0,
+};
+
+enum hdmi_eotf {
+ HDMI_EOTF_TRADITIONAL_GAMMA_SDR,
+ HDMI_EOTF_TRADITIONAL_GAMMA_HDR,
+ HDMI_EOTF_SMPTE_ST2084,
+ HDMI_EOTF_BT_2100_HLG,
+};
+
+struct hdmi_avi_infoframe {
+ enum hdmi_infoframe_type type;
+ unsigned char version;
+ unsigned char length;
+ bool itc;
+ unsigned char pixel_repeat;
+ enum hdmi_colorspace colorspace;
+ enum hdmi_scan_mode scan_mode;
+ enum hdmi_colorimetry colorimetry;
+ enum hdmi_picture_aspect picture_aspect;
+ enum hdmi_active_aspect active_aspect;
+ enum hdmi_extended_colorimetry extended_colorimetry;
+ enum hdmi_quantization_range quantization_range;
+ enum hdmi_nups nups;
+ unsigned char video_code;
+ enum hdmi_ycc_quantization_range ycc_quantization_range;
+ enum hdmi_content_type content_type;
+ unsigned short top_bar;
+ unsigned short bottom_bar;
+ unsigned short left_bar;
+ unsigned short right_bar;
+};
+
+/* DRM Infoframe as per CTA 861.G spec */
+struct hdmi_drm_infoframe {
+ enum hdmi_infoframe_type type;
+ unsigned char version;
+ unsigned char length;
+ enum hdmi_eotf eotf;
+ enum hdmi_metadata_type metadata_type;
+ struct {
+ u16 x, y;
+ } display_primaries[3];
+ struct {
+ u16 x, y;
+ } white_point;
+ u16 max_display_mastering_luminance;
+ u16 min_display_mastering_luminance;
+ u16 max_cll;
+ u16 max_fall;
+};
+
+void hdmi_avi_infoframe_init(struct hdmi_avi_infoframe *frame);
+ssize_t hdmi_avi_infoframe_pack(struct hdmi_avi_infoframe *frame, void *buffer,
+ size_t size);
+ssize_t hdmi_avi_infoframe_pack_only(const struct hdmi_avi_infoframe *frame,
+ void *buffer, size_t size);
+int hdmi_avi_infoframe_check(struct hdmi_avi_infoframe *frame);
+int hdmi_drm_infoframe_init(struct hdmi_drm_infoframe *frame);
+ssize_t hdmi_drm_infoframe_pack(struct hdmi_drm_infoframe *frame, void *buffer,
+ size_t size);
+ssize_t hdmi_drm_infoframe_pack_only(const struct hdmi_drm_infoframe *frame,
+ void *buffer, size_t size);
+int hdmi_drm_infoframe_check(struct hdmi_drm_infoframe *frame);
+int hdmi_drm_infoframe_unpack_only(struct hdmi_drm_infoframe *frame,
+ const void *buffer, size_t size);
+
+enum hdmi_spd_sdi {
+ HDMI_SPD_SDI_UNKNOWN,
+ HDMI_SPD_SDI_DSTB,
+ HDMI_SPD_SDI_DVDP,
+ HDMI_SPD_SDI_DVHS,
+ HDMI_SPD_SDI_HDDVR,
+ HDMI_SPD_SDI_DVC,
+ HDMI_SPD_SDI_DSC,
+ HDMI_SPD_SDI_VCD,
+ HDMI_SPD_SDI_GAME,
+ HDMI_SPD_SDI_PC,
+ HDMI_SPD_SDI_BD,
+ HDMI_SPD_SDI_SACD,
+ HDMI_SPD_SDI_HDDVD,
+ HDMI_SPD_SDI_PMP,
+};
+
+struct hdmi_spd_infoframe {
+ enum hdmi_infoframe_type type;
+ unsigned char version;
+ unsigned char length;
+ char vendor[8];
+ char product[16];
+ enum hdmi_spd_sdi sdi;
+};
+
+int hdmi_spd_infoframe_init(struct hdmi_spd_infoframe *frame,
+ const char *vendor, const char *product);
+ssize_t hdmi_spd_infoframe_pack(struct hdmi_spd_infoframe *frame, void *buffer,
+ size_t size);
+ssize_t hdmi_spd_infoframe_pack_only(const struct hdmi_spd_infoframe *frame,
+ void *buffer, size_t size);
+int hdmi_spd_infoframe_check(struct hdmi_spd_infoframe *frame);
+
+enum hdmi_audio_coding_type {
+ HDMI_AUDIO_CODING_TYPE_STREAM,
+ HDMI_AUDIO_CODING_TYPE_PCM,
+ HDMI_AUDIO_CODING_TYPE_AC3,
+ HDMI_AUDIO_CODING_TYPE_MPEG1,
+ HDMI_AUDIO_CODING_TYPE_MP3,
+ HDMI_AUDIO_CODING_TYPE_MPEG2,
+ HDMI_AUDIO_CODING_TYPE_AAC_LC,
+ HDMI_AUDIO_CODING_TYPE_DTS,
+ HDMI_AUDIO_CODING_TYPE_ATRAC,
+ HDMI_AUDIO_CODING_TYPE_DSD,
+ HDMI_AUDIO_CODING_TYPE_EAC3,
+ HDMI_AUDIO_CODING_TYPE_DTS_HD,
+ HDMI_AUDIO_CODING_TYPE_MLP,
+ HDMI_AUDIO_CODING_TYPE_DST,
+ HDMI_AUDIO_CODING_TYPE_WMA_PRO,
+ HDMI_AUDIO_CODING_TYPE_CXT,
+};
+
+enum hdmi_audio_sample_size {
+ HDMI_AUDIO_SAMPLE_SIZE_STREAM,
+ HDMI_AUDIO_SAMPLE_SIZE_16,
+ HDMI_AUDIO_SAMPLE_SIZE_20,
+ HDMI_AUDIO_SAMPLE_SIZE_24,
+};
+
+enum hdmi_audio_sample_frequency {
+ HDMI_AUDIO_SAMPLE_FREQUENCY_STREAM,
+ HDMI_AUDIO_SAMPLE_FREQUENCY_32000,
+ HDMI_AUDIO_SAMPLE_FREQUENCY_44100,
+ HDMI_AUDIO_SAMPLE_FREQUENCY_48000,
+ HDMI_AUDIO_SAMPLE_FREQUENCY_88200,
+ HDMI_AUDIO_SAMPLE_FREQUENCY_96000,
+ HDMI_AUDIO_SAMPLE_FREQUENCY_176400,
+ HDMI_AUDIO_SAMPLE_FREQUENCY_192000,
+};
+
+enum hdmi_audio_coding_type_ext {
+ /* Refer to Audio Coding Type (CT) field in Data Byte 1 */
+ HDMI_AUDIO_CODING_TYPE_EXT_CT,
+
+ /*
+ * The next three CXT values are defined in CEA-861-E only.
+ * They do not exist in older versions, and in CEA-861-F they are
+ * defined as 'Not in use'.
+ */
+ HDMI_AUDIO_CODING_TYPE_EXT_HE_AAC,
+ HDMI_AUDIO_CODING_TYPE_EXT_HE_AAC_V2,
+ HDMI_AUDIO_CODING_TYPE_EXT_MPEG_SURROUND,
+
+ /* The following CXT values are only defined in CEA-861-F. */
+ HDMI_AUDIO_CODING_TYPE_EXT_MPEG4_HE_AAC,
+ HDMI_AUDIO_CODING_TYPE_EXT_MPEG4_HE_AAC_V2,
+ HDMI_AUDIO_CODING_TYPE_EXT_MPEG4_AAC_LC,
+ HDMI_AUDIO_CODING_TYPE_EXT_DRA,
+ HDMI_AUDIO_CODING_TYPE_EXT_MPEG4_HE_AAC_SURROUND,
+ HDMI_AUDIO_CODING_TYPE_EXT_MPEG4_AAC_LC_SURROUND = 10,
+};
+
+struct hdmi_audio_infoframe {
+ enum hdmi_infoframe_type type;
+ unsigned char version;
+ unsigned char length;
+ unsigned char channels;
+ enum hdmi_audio_coding_type coding_type;
+ enum hdmi_audio_sample_size sample_size;
+ enum hdmi_audio_sample_frequency sample_frequency;
+ enum hdmi_audio_coding_type_ext coding_type_ext;
+ unsigned char channel_allocation;
+ unsigned char level_shift_value;
+ bool downmix_inhibit;
+
+};
+
+int hdmi_audio_infoframe_init(struct hdmi_audio_infoframe *frame);
+ssize_t hdmi_audio_infoframe_pack(struct hdmi_audio_infoframe *frame,
+ void *buffer, size_t size);
+ssize_t hdmi_audio_infoframe_pack_only(const struct hdmi_audio_infoframe *frame,
+ void *buffer, size_t size);
+int hdmi_audio_infoframe_check(const struct hdmi_audio_infoframe *frame);
+
+#ifdef __linux__
+struct dp_sdp;
+ssize_t
+hdmi_audio_infoframe_pack_for_dp(const struct hdmi_audio_infoframe *frame,
+ struct dp_sdp *sdp, u8 dp_version);
+#endif
+
+enum hdmi_3d_structure {
+ HDMI_3D_STRUCTURE_INVALID = -1,
+ HDMI_3D_STRUCTURE_FRAME_PACKING = 0,
+ HDMI_3D_STRUCTURE_FIELD_ALTERNATIVE,
+ HDMI_3D_STRUCTURE_LINE_ALTERNATIVE,
+ HDMI_3D_STRUCTURE_SIDE_BY_SIDE_FULL,
+ HDMI_3D_STRUCTURE_L_DEPTH,
+ HDMI_3D_STRUCTURE_L_DEPTH_GFX_GFX_DEPTH,
+ HDMI_3D_STRUCTURE_TOP_AND_BOTTOM,
+ HDMI_3D_STRUCTURE_SIDE_BY_SIDE_HALF = 8,
+};
+
+
+struct hdmi_vendor_infoframe {
+ enum hdmi_infoframe_type type;
+ unsigned char version;
+ unsigned char length;
+ unsigned int oui;
+ u8 vic;
+ enum hdmi_3d_structure s3d_struct;
+ unsigned int s3d_ext_data;
+};
+
+/* HDR Metadata as per 861.G spec */
+struct hdr_static_metadata {
+ __u8 eotf;
+ __u8 metadata_type;
+ __u16 max_cll;
+ __u16 max_fall;
+ __u16 min_cll;
+};
+
+/**
+ * struct hdr_sink_metadata - HDR sink metadata
+ *
+ * Metadata Information read from Sink's EDID
+ */
+struct hdr_sink_metadata {
+ /**
+ * @metadata_type: Static_Metadata_Descriptor_ID.
+ */
+ __u32 metadata_type;
+ /**
+ * @hdmi_type1: HDR Metadata Infoframe.
+ */
+ union {
+ struct hdr_static_metadata hdmi_type1;
+ };
+};
+
+int hdmi_vendor_infoframe_init(struct hdmi_vendor_infoframe *frame);
+ssize_t hdmi_vendor_infoframe_pack(struct hdmi_vendor_infoframe *frame,
+ void *buffer, size_t size);
+ssize_t hdmi_vendor_infoframe_pack_only(const struct hdmi_vendor_infoframe *frame,
+ void *buffer, size_t size);
+int hdmi_vendor_infoframe_check(struct hdmi_vendor_infoframe *frame);
+
+union hdmi_vendor_any_infoframe {
+ struct {
+ enum hdmi_infoframe_type type;
+ unsigned char version;
+ unsigned char length;
+ unsigned int oui;
+ } any;
+ struct hdmi_vendor_infoframe hdmi;
+};
+
+/**
+ * union hdmi_infoframe - overall union of all abstract infoframe representations
+ * @any: generic infoframe
+ * @avi: avi infoframe
+ * @spd: spd infoframe
+ * @vendor: union of all vendor infoframes
+ * @audio: audio infoframe
+ * @drm: Dynamic Range and Mastering infoframe
+ *
+ * This is used by the generic pack function. This works since all infoframes
+ * have the same header which also indicates which type of infoframe should be
+ * packed.
+ */
+union hdmi_infoframe {
+ struct hdmi_any_infoframe any;
+ struct hdmi_avi_infoframe avi;
+ struct hdmi_spd_infoframe spd;
+ union hdmi_vendor_any_infoframe vendor;
+ struct hdmi_audio_infoframe audio;
+ struct hdmi_drm_infoframe drm;
+};
+
+ssize_t hdmi_infoframe_pack(union hdmi_infoframe *frame, void *buffer,
+ size_t size);
+ssize_t hdmi_infoframe_pack_only(const union hdmi_infoframe *frame,
+ void *buffer, size_t size);
+int hdmi_infoframe_check(union hdmi_infoframe *frame);
+int hdmi_infoframe_unpack(union hdmi_infoframe *frame,
+ const void *buffer, size_t size);
+void hdmi_infoframe_log(const char *level, struct device *dev,
+ const union hdmi_infoframe *frame);
+
+#endif /* _DRM_HDMI_H */
diff --git a/sys/compat/linuxkpi/common/include/linux/highmem.h b/sys/compat/linuxkpi/common/include/linux/highmem.h
index 9378746ea480..58a9cdcdf60f 100644
--- a/sys/compat/linuxkpi/common/include/linux/highmem.h
+++ b/sys/compat/linuxkpi/common/include/linux/highmem.h
@@ -1,5 +1,5 @@
/*-
- * SPDX-License-Identifier: BSD-2-Clause-FreeBSD
+ * SPDX-License-Identifier: BSD-2-Clause
*
* Copyright (c) 2010 Isilon Systems, Inc.
* Copyright (c) 2016 Matthew Macy (mmacy@mattmacy.io)
@@ -29,8 +29,8 @@
* SUCH DAMAGE.
*/
-#ifndef _LINUX_HIGHMEM_H_
-#define _LINUX_HIGHMEM_H_
+#ifndef _LINUXKPI_LINUX_HIGHMEM_H_
+#define _LINUXKPI_LINUX_HIGHMEM_H_
#include <sys/types.h>
#include <sys/lock.h>
@@ -43,23 +43,25 @@
#include <vm/vm_page.h>
#include <vm/pmap.h>
+#include <linux/mm.h>
#include <linux/page.h>
#define PageHighMem(p) (0)
-static inline vm_page_t
+static inline struct page *
kmap_to_page(void *addr)
{
+
return (virt_to_page(addr));
}
static inline void *
-kmap(vm_page_t page)
+kmap(struct page *page)
{
struct sf_buf *sf;
if (PMAP_HAS_DMAP) {
- return ((void *)PHYS_TO_DMAP(VM_PAGE_TO_PHYS(page)));
+ return ((void *)PHYS_TO_DMAP(page_to_phys(page)));
} else {
sched_pin();
sf = sf_buf_alloc(page, SFB_NOWAIT | SFB_CPUPRIVATE);
@@ -72,27 +74,39 @@ kmap(vm_page_t page)
}
static inline void *
-kmap_atomic_prot(vm_page_t page, pgprot_t prot)
+kmap_atomic_prot(struct page *page, pgprot_t prot)
{
vm_memattr_t attr = pgprot2cachemode(prot);
if (attr != VM_MEMATTR_DEFAULT) {
- vm_page_lock(page);
page->flags |= PG_FICTITIOUS;
- vm_page_unlock(page);
pmap_page_set_memattr(page, attr);
}
return (kmap(page));
}
static inline void *
-kmap_atomic(vm_page_t page)
+kmap_atomic(struct page *page)
{
+
return (kmap_atomic_prot(page, VM_PROT_ALL));
}
+static inline void *
+kmap_local_page(struct page *page)
+{
+ return (kmap(page));
+}
+
+static inline void *
+kmap_local_page_prot(struct page *page, pgprot_t prot)
+{
+
+ return (kmap_atomic_prot(page, prot));
+}
+
static inline void
-kunmap(vm_page_t page)
+kunmap(struct page *page)
{
struct sf_buf *sf;
@@ -111,8 +125,46 @@ kunmap(vm_page_t page)
static inline void
kunmap_atomic(void *vaddr)
{
+
if (!PMAP_HAS_DMAP)
kunmap(virt_to_page(vaddr));
}
-#endif /* _LINUX_HIGHMEM_H_ */
+static inline void
+kunmap_local(void *addr)
+{
+
+ kunmap_atomic(addr);
+}
+
+static inline void
+memcpy_from_page(char *to, struct page *page, size_t offset, size_t len)
+{
+ char *from;
+
+ KASSERT(offset + len <= PAGE_SIZE,
+ ("%s: memcpy from page %p to address %p: "
+ "offset+len (%zu+%zu) would go beyond page end",
+ __func__, page, to, offset, len));
+
+ from = kmap_local_page(page);
+ memcpy(to, from + offset, len);
+ kunmap_local(from);
+}
+
+static inline void
+memcpy_to_page(struct page *page, size_t offset, const char *from, size_t len)
+{
+ char *to;
+
+ KASSERT(offset + len <= PAGE_SIZE,
+ ("%s: memcpy from address %p to page %p: "
+ "offset+len (%zu+%zu) would go beyond page end",
+ __func__, from, page, offset, len));
+
+ to = kmap_local_page(page);
+ memcpy(to + offset, from, len);
+ kunmap_local(to);
+}
+
+#endif /* _LINUXKPI_LINUX_HIGHMEM_H_ */
diff --git a/sys/compat/linuxkpi/common/include/linux/hrtimer.h b/sys/compat/linuxkpi/common/include/linux/hrtimer.h
index a5ff7480a271..88f9487d0b85 100644
--- a/sys/compat/linuxkpi/common/include/linux/hrtimer.h
+++ b/sys/compat/linuxkpi/common/include/linux/hrtimer.h
@@ -21,17 +21,16 @@
* 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.
- *
- * $FreeBSD$
*/
-#ifndef _LINUX_HRTIMER_H_
-#define _LINUX_HRTIMER_H_
+#ifndef _LINUXKPI_LINUX_HRTIMER_H_
+#define _LINUXKPI_LINUX_HRTIMER_H_
#include <sys/_callout.h>
#include <sys/_mutex.h>
#include <linux/ktime.h>
+#include <linux/rbtree.h>
#include <linux/timer.h>
enum hrtimer_mode {
@@ -53,6 +52,7 @@ struct hrtimer {
};
#define hrtimer_active(hrtimer) linux_hrtimer_active(hrtimer)
+#define hrtimer_try_to_cancel(hrtimer) linux_hrtimer_try_to_cancel(hrtimer)
#define hrtimer_cancel(hrtimer) linux_hrtimer_cancel(hrtimer)
#define hrtimer_init(hrtimer, clock, mode) do { \
@@ -79,6 +79,7 @@ struct hrtimer {
} while (0)
bool linux_hrtimer_active(struct hrtimer *);
+int linux_hrtimer_try_to_cancel(struct hrtimer *);
int linux_hrtimer_cancel(struct hrtimer *);
void linux_hrtimer_init(struct hrtimer *);
void linux_hrtimer_set_expires(struct hrtimer *, ktime_t);
@@ -86,4 +87,4 @@ void linux_hrtimer_start(struct hrtimer *, ktime_t);
void linux_hrtimer_start_range_ns(struct hrtimer *, ktime_t, int64_t);
void linux_hrtimer_forward_now(struct hrtimer *, ktime_t);
-#endif /* _LINUX_HRTIMER_H_ */
+#endif /* _LINUXKPI_LINUX_HRTIMER_H_ */
diff --git a/sys/compat/linuxkpi/common/include/linux/i2c-algo-bit.h b/sys/compat/linuxkpi/common/include/linux/i2c-algo-bit.h
new file mode 100644
index 000000000000..4e8f00f9bebc
--- /dev/null
+++ b/sys/compat/linuxkpi/common/include/linux/i2c-algo-bit.h
@@ -0,0 +1,49 @@
+/*-
+ * Copyright (c) 2021 Beckhoff Automation GmbH & Co. KG
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``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 OR CONTRIBUTORS 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.
+ *
+ */
+
+#ifndef _LINUX_I2C_ALGO_BIT_H_
+#define _LINUX_I2C_ALGO_BIT_H_
+
+#include <linux/i2c.h>
+
+struct i2c_algo_bit_data {
+ void *data;
+ void (*setsda) (void *data, int state);
+ void (*setscl) (void *data, int state);
+ int (*getsda) (void *data);
+ int (*getscl) (void *data);
+ int (*pre_xfer) (struct i2c_adapter *);
+ void (*post_xfer) (struct i2c_adapter *);
+
+ int udelay;
+ int timeout;
+};
+
+int lkpi_i2c_bit_add_bus(struct i2c_adapter *adapter);
+
+#define i2c_bit_add_bus(adapter) lkpi_i2c_bit_add_bus(adapter)
+
+#endif /*_LINUX_I2C_ALGO_BIT_H_ */
diff --git a/sys/compat/linuxkpi/common/include/linux/i2c.h b/sys/compat/linuxkpi/common/include/linux/i2c.h
new file mode 100644
index 000000000000..f24d282586f6
--- /dev/null
+++ b/sys/compat/linuxkpi/common/include/linux/i2c.h
@@ -0,0 +1,177 @@
+/*-
+ * Copyright (c) 2021 Beckhoff Automation GmbH & Co. KG
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``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 OR CONTRIBUTORS 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.
+ *
+ */
+
+#ifndef _LINUX_I2C_H_
+#define _LINUX_I2C_H_
+
+#include <sys/types.h>
+#include <sys/errno.h>
+#include <sys/systm.h>
+
+#include <linux/device.h>
+
+#define I2C_MAX_ADAPTER_NAME_LENGTH 32
+
+#define I2C_M_RD 0x0001
+#define I2C_M_NOSTART 0x0002
+#define I2C_M_STOP 0x0004
+
+/* No need for us */
+#define I2C_FUNC_I2C 0
+#define I2C_FUNC_SMBUS_EMUL 0
+#define I2C_FUNC_SMBUS_READ_BLOCK_DATA 0
+#define I2C_FUNC_SMBUS_BLOCK_PROC_CALL 0
+#define I2C_FUNC_10BIT_ADDR 0
+
+#define I2C_CLASS_HWMON 0x1
+#define I2C_CLASS_DDC 0x8
+#define I2C_CLASS_SPD 0x80
+
+struct i2c_adapter {
+ struct module *owner;
+ unsigned int class;
+
+ char name[I2C_MAX_ADAPTER_NAME_LENGTH];
+ struct device dev;
+
+ const struct i2c_lock_operations *lock_ops;
+ const struct i2c_algorithm *algo;
+ const struct i2c_adapter_quirks *quirks;
+ void *algo_data;
+
+ int retries;
+ void *data;
+};
+
+struct i2c_msg {
+ uint16_t addr;
+ uint16_t flags;
+ uint16_t len;
+ uint8_t *buf;
+};
+
+struct i2c_algorithm {
+ int (*master_xfer)(struct i2c_adapter *, struct i2c_msg *, int);
+ uint32_t (*functionality)(struct i2c_adapter *);
+};
+
+struct i2c_lock_operations {
+ void (*lock_bus)(struct i2c_adapter *, unsigned int);
+ int (*trylock_bus)(struct i2c_adapter *, unsigned int);
+ void (*unlock_bus)(struct i2c_adapter *, unsigned int);
+};
+
+struct i2c_adapter_quirks {
+ uint64_t flags;
+ int max_num_msgs;
+ uint16_t max_write_len;
+ uint16_t max_read_len;
+ uint16_t max_comb_1st_msg_len;
+ uint16_t max_comb_2nd_msg_len;
+};
+
+#define I2C_AQ_COMB BIT(0)
+#define I2C_AQ_COMB_WRITE_FIRST BIT(1)
+#define I2C_AQ_COMB_READ_SECOND BIT(2)
+#define I2C_AQ_COMB_SAME_ADDR BIT(3)
+#define I2C_AQ_COMB_WRITE_THEN_READ \
+ (I2C_AQ_COMB | I2C_AQ_COMB_WRITE_FIRST | \
+ I2C_AQ_COMB_READ_SECOND | I2C_AQ_COMB_SAME_ADDR)
+#define I2C_AQ_NO_CLK_STRETCH BIT(4)
+#define I2C_AQ_NO_ZERO_LEN_READ BIT(5)
+#define I2C_AQ_NO_ZERO_LEN_WRITE BIT(6)
+#define I2C_AQ_NO_ZERO_LEN \
+ (I2C_AQ_NO_ZERO_LEN_READ | I2C_AQ_NO_ZERO_LEN_WRITE)
+#define I2C_AQ_NO_REP_START BIT(7)
+
+int lkpi_i2c_add_adapter(struct i2c_adapter *adapter);
+int lkpi_i2c_del_adapter(struct i2c_adapter *adapter);
+
+int lkpi_i2cbb_transfer(struct i2c_adapter *adapter, struct i2c_msg *msgs, int nmsgs);
+
+#define i2c_add_adapter(adapter) lkpi_i2c_add_adapter(adapter)
+#define i2c_del_adapter(adapter) lkpi_i2c_del_adapter(adapter)
+
+#define i2c_get_adapter(x) NULL
+#define i2c_put_adapter(x)
+
+static inline int
+do_i2c_transfer(struct i2c_adapter *adapter, struct i2c_msg *msgs, int nmsgs)
+{
+ int ret, retries;
+
+ retries = adapter->retries == 0 ? 1 : adapter->retries;
+ for (; retries != 0; retries--) {
+ if (adapter->algo != NULL && adapter->algo->master_xfer != NULL)
+ ret = adapter->algo->master_xfer(adapter, msgs, nmsgs);
+ else
+ ret = lkpi_i2cbb_transfer(adapter, msgs, nmsgs);
+ if (ret != -EAGAIN)
+ break;
+ }
+
+ return (ret);
+}
+
+static inline int
+i2c_transfer(struct i2c_adapter *adapter, struct i2c_msg *msgs, int nmsgs)
+{
+ int ret;
+
+ if (adapter->algo == NULL && adapter->algo_data == NULL)
+ return (-EOPNOTSUPP);
+
+ if (adapter->lock_ops)
+ adapter->lock_ops->lock_bus(adapter, 0);
+
+ ret = do_i2c_transfer(adapter, msgs, nmsgs);
+
+ if (adapter->lock_ops)
+ adapter->lock_ops->unlock_bus(adapter, 0);
+
+ return (ret);
+}
+
+/* Unlocked version of i2c_transfer */
+static inline int
+__i2c_transfer(struct i2c_adapter *adapter, struct i2c_msg *msgs, int nmsgs)
+{
+ return (do_i2c_transfer(adapter, msgs, nmsgs));
+}
+
+static inline void
+i2c_set_adapdata(struct i2c_adapter *adapter, void *data)
+{
+ adapter->data = data;
+}
+
+static inline void *
+i2c_get_adapdata(struct i2c_adapter *adapter)
+{
+ return (adapter->data);
+}
+
+#endif /* _LINUX_I2C_H_ */
diff --git a/sys/compat/linuxkpi/common/include/linux/idr.h b/sys/compat/linuxkpi/common/include/linux/idr.h
index cba3f96c88ae..06850c94a5e9 100644
--- a/sys/compat/linuxkpi/common/include/linux/idr.h
+++ b/sys/compat/linuxkpi/common/include/linux/idr.h
@@ -25,16 +25,17 @@
* 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.
- *
- * $FreeBSD$
*/
-#ifndef _LINUX_IDR_H_
-#define _LINUX_IDR_H_
+#ifndef _LINUXKPI_LINUX_IDR_H_
+#define _LINUXKPI_LINUX_IDR_H_
#include <sys/param.h>
#include <sys/lock.h>
+#include <sys/limits.h>
#include <sys/mutex.h>
+#include <linux/radix-tree.h>
+#include <linux/gpf.h>
#include <linux/types.h>
#define IDR_BITS 5
@@ -134,12 +135,25 @@ ida_get_new(struct ida *ida, int *p_id)
}
static inline int
+ida_alloc_min(struct ida *ida, unsigned int min, gfp_t gfp)
+{
+ return (ida_simple_get(ida, min, UINT_MAX, gfp));
+}
+
+static inline int
ida_alloc_max(struct ida *ida, unsigned int max, gfp_t gfp)
{
return (ida_simple_get(ida, 0, max, gfp));
}
+static inline int
+ida_alloc_range(struct ida *ida, unsigned int min, unsigned int max, gfp_t gfp)
+{
+
+ return (ida_simple_get(ida, min, max, gfp));
+}
+
static inline int ida_alloc(struct ida *ida, gfp_t gfp)
{
return (ida_alloc_max(ida, ~0u, gfp));
@@ -152,4 +166,4 @@ ida_is_empty(struct ida *ida)
return (idr_is_empty(&ida->idr));
}
-#endif /* _LINUX_IDR_H_ */
+#endif /* _LINUXKPI_LINUX_IDR_H_ */
diff --git a/sys/compat/linuxkpi/common/include/linux/ieee80211.h b/sys/compat/linuxkpi/common/include/linux/ieee80211.h
new file mode 100644
index 000000000000..ea8c0fc8ef5e
--- /dev/null
+++ b/sys/compat/linuxkpi/common/include/linux/ieee80211.h
@@ -0,0 +1,1269 @@
+/*-
+ * Copyright (c) 2020-2025 The FreeBSD Foundation
+ *
+ * This software was developed by Björn Zeeb under sponsorship from
+ * the FreeBSD Foundation.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``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 OR CONTRIBUTORS 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.
+ */
+
+#ifndef _LINUXKPI_LINUX_IEEE80211_H
+#define _LINUXKPI_LINUX_IEEE80211_H
+
+#include <sys/types.h>
+#include <net80211/ieee80211.h>
+
+#include <asm/unaligned.h>
+#include <linux/kernel.h>
+#include <linux/bitops.h>
+#include <linux/bitfield.h>
+#include <linux/if_ether.h>
+
+/* linux_80211.c */
+extern int linuxkpi_debug_80211;
+#ifndef D80211_TODO
+#define D80211_TODO 0x1
+#endif
+#define TODO(fmt, ...) if (linuxkpi_debug_80211 & D80211_TODO) \
+ printf("%s:%d: XXX LKPI80211 TODO " fmt "\n", __func__, __LINE__, ##__VA_ARGS__)
+
+
+/* 9.4.2.55 Management MIC element (CMAC-256, GMAC-128, and GMAC-256). */
+struct ieee80211_mmie_16 {
+ uint8_t element_id;
+ uint8_t length;
+ uint16_t key_id;
+ uint8_t ipn[6];
+ uint8_t mic[16];
+};
+
+#define IEEE80211_CCMP_HDR_LEN 8 /* 802.11i .. net80211 comment */
+#define IEEE80211_CCMP_PN_LEN 6
+#define IEEE80211_CCMP_MIC_LEN 8 /* || 16 */
+#define IEEE80211_CCMP_256_HDR_LEN 8
+#define IEEE80211_CCMP_256_MIC_LEN 16
+#define IEEE80211_GCMP_HDR_LEN 8
+#define IEEE80211_GCMP_MIC_LEN 16
+#define IEEE80211_GCMP_PN_LEN 6
+#define IEEE80211_GMAC_PN_LEN 6
+#define IEEE80211_CMAC_PN_LEN 6
+
+#define IEEE80211_MAX_PN_LEN 16
+
+#define IEEE80211_INVAL_HW_QUEUE ((uint8_t)-1)
+
+#define IEEE80211_MAX_AMPDU_BUF_HT IEEE80211_AGGR_BAWMAX
+#define IEEE80211_MAX_AMPDU_BUF_HE 256
+#define IEEE80211_MAX_AMPDU_BUF_EHT 1024
+
+#define IEEE80211_MAX_FRAME_LEN 2352
+#define IEEE80211_MAX_DATA_LEN (2300 + IEEE80211_CRC_LEN)
+
+#define IEEE80211_MAX_MPDU_LEN_HT_BA 4095 /* 9.3.2.1 Format of Data frames; non-VHT non-DMG STA */
+#define IEEE80211_MAX_MPDU_LEN_HT_3839 3839
+#define IEEE80211_MAX_MPDU_LEN_HT_7935 7935
+#define IEEE80211_MAX_MPDU_LEN_VHT_3895 3895
+#define IEEE80211_MAX_MPDU_LEN_VHT_7991 7991
+#define IEEE80211_MAX_MPDU_LEN_VHT_11454 11454
+
+#define IEEE80211_MAX_RTS_THRESHOLD 2346 /* net80211::IEEE80211_RTS_MAX */
+
+#define IEEE80211_MIN_ACTION_SIZE 23 /* ? */
+
+/* Wi-Fi Peer-to-Peer (P2P) Technical Specification */
+#define IEEE80211_P2P_OPPPS_CTWINDOW_MASK 0x7f
+#define IEEE80211_P2P_OPPPS_ENABLE_BIT BIT(7)
+
+/* 802.11-2016, 9.2.4.5.1, Table 9-6 QoS Control Field */
+#define IEEE80211_QOS_CTL_TAG1D_MASK 0x0007
+#define IEEE80211_QOS_CTL_TID_MASK IEEE80211_QOS_TID
+#define IEEE80211_QOS_CTL_EOSP 0x0010
+#define IEEE80211_QOS_CTL_A_MSDU_PRESENT 0x0080
+#define IEEE80211_QOS_CTL_ACK_POLICY_MASK 0x0060
+#define IEEE80211_QOS_CTL_ACK_POLICY_NOACK 0x0020
+#define IEEE80211_QOS_CTL_MESH_CONTROL_PRESENT 0x0100
+
+enum ieee80211_rate_flags {
+ IEEE80211_RATE_SHORT_PREAMBLE = BIT(0),
+};
+
+enum ieee80211_rate_control_changed_flags {
+ IEEE80211_RC_BW_CHANGED = BIT(0),
+ IEEE80211_RC_NSS_CHANGED = BIT(1),
+ IEEE80211_RC_SUPP_RATES_CHANGED = BIT(2),
+ IEEE80211_RC_SMPS_CHANGED = BIT(3),
+};
+
+#define IEEE80211_SCTL_FRAG IEEE80211_SEQ_FRAG_MASK
+#define IEEE80211_SCTL_SEQ IEEE80211_SEQ_SEQ_MASK
+
+#define IEEE80211_TKIP_ICV_LEN 4
+#define IEEE80211_TKIP_IV_LEN 8 /* WEP + KID + EXT */
+
+/* 802.11-2016, 9.4.2.158.3 Supported VHT-MCS and NSS Set field. */
+#define IEEE80211_VHT_EXT_NSS_BW_CAPABLE (1 << 13) /* part of tx_highest */
+
+/*
+ * 802.11-2020, 9.4.2.157.2 VHT Capabilities Information field,
+ * Table 9-271-Subfields of the VHT Capabilities Information field (continued).
+ */
+enum ieee80211_vht_max_ampdu_len_exp {
+ IEEE80211_VHT_MAX_AMPDU_8K = 0,
+ IEEE80211_VHT_MAX_AMPDU_16K = 1,
+ IEEE80211_VHT_MAX_AMPDU_32K = 2,
+ IEEE80211_VHT_MAX_AMPDU_64K = 3,
+ IEEE80211_VHT_MAX_AMPDU_128K = 4,
+ IEEE80211_VHT_MAX_AMPDU_256K = 5,
+ IEEE80211_VHT_MAX_AMPDU_512K = 6,
+ IEEE80211_VHT_MAX_AMPDU_1024K = 7,
+};
+
+#define IEEE80211_WEP_IV_LEN 3 /* net80211: IEEE80211_WEP_IVLEN */
+#define IEEE80211_WEP_ICV_LEN 4
+
+#define WLAN_AUTH_OPEN __LINE__ /* TODO FIXME brcmfmac */
+#define WLAN_CAPABILITY_IBSS __LINE__ /* TODO FIXME no longer used? */
+#define WLAN_CAPABILITY_SHORT_PREAMBLE __LINE__ /* TODO FIXME brcmfmac */
+#define WLAN_CAPABILITY_SHORT_SLOT_TIME __LINE__ /* TODO FIXME brcmfmac */
+
+enum wlan_ht_cap_sm_ps {
+ WLAN_HT_CAP_SM_PS_STATIC = 0,
+ WLAN_HT_CAP_SM_PS_DYNAMIC = 1,
+ WLAN_HT_CAP_SM_PS_INVALID = 2,
+ WLAN_HT_CAP_SM_PS_DISABLED = 3
+};
+
+#define WLAN_MAX_KEY_LEN 32
+#define WLAN_PMKID_LEN 16
+#define WLAN_PMK_LEN_SUITE_B_192 48
+
+enum ieee80211_key_len {
+ WLAN_KEY_LEN_WEP40 = 5,
+ WLAN_KEY_LEN_WEP104 = 13,
+ WLAN_KEY_LEN_TKIP = 32,
+ WLAN_KEY_LEN_CCMP = 16,
+ WLAN_KEY_LEN_CCMP_256 = 32,
+ WLAN_KEY_LEN_GCMP = 16,
+ WLAN_KEY_LEN_AES_CMAC = 16,
+ WLAN_KEY_LEN_GCMP_256 = 32,
+ WLAN_KEY_LEN_BIP_CMAC_256 = 32,
+ WLAN_KEY_LEN_BIP_GMAC_128 = 16,
+ WLAN_KEY_LEN_BIP_GMAC_256 = 32,
+};
+
+/* 802.11-2020, 9.4.2.55.3, Table 9-185 Subfields of the A-MPDU Parameters field */
+enum ieee80211_min_mpdu_start_spacing {
+ IEEE80211_HT_MPDU_DENSITY_NONE = 0,
+#if 0
+ IEEE80211_HT_MPDU_DENSITY_XXX = 1, /* 1/4 us */
+#endif
+ IEEE80211_HT_MPDU_DENSITY_0_5 = 2, /* 1/2 us */
+ IEEE80211_HT_MPDU_DENSITY_1 = 3, /* 1 us */
+ IEEE80211_HT_MPDU_DENSITY_2 = 4, /* 2 us */
+ IEEE80211_HT_MPDU_DENSITY_4 = 5, /* 4us */
+ IEEE80211_HT_MPDU_DENSITY_8 = 6, /* 8us */
+ IEEE80211_HT_MPDU_DENSITY_16 = 7, /* 16us */
+};
+
+/* 9.4.2.57, Table 9-168, HT Operation element fields and subfields */
+#define IEEE80211_HT_STBC_PARAM_DUAL_CTS_PROT 0x0080 /* B24.. */
+
+#define IEEE80211_FCTL_FTYPE IEEE80211_FC0_TYPE_MASK
+#define IEEE80211_FCTL_STYPE IEEE80211_FC0_SUBTYPE_MASK
+#define IEEE80211_FCTL_ORDER (IEEE80211_FC1_ORDER << 8)
+#define IEEE80211_FCTL_PROTECTED (IEEE80211_FC1_PROTECTED << 8)
+#define IEEE80211_FCTL_FROMDS (IEEE80211_FC1_DIR_FROMDS << 8)
+#define IEEE80211_FCTL_TODS (IEEE80211_FC1_DIR_TODS << 8)
+#define IEEE80211_FCTL_MOREFRAGS (IEEE80211_FC1_MORE_FRAG << 8)
+#define IEEE80211_FCTL_PM (IEEE80211_FC1_PWR_MGT << 8)
+
+#define IEEE80211_FTYPE_MGMT IEEE80211_FC0_TYPE_MGT
+#define IEEE80211_FTYPE_CTL IEEE80211_FC0_TYPE_CTL
+#define IEEE80211_FTYPE_DATA IEEE80211_FC0_TYPE_DATA
+
+#define IEEE80211_STYPE_ASSOC_REQ IEEE80211_FC0_SUBTYPE_ASSOC_REQ
+#define IEEE80211_STYPE_REASSOC_REQ IEEE80211_FC0_SUBTYPE_REASSOC_REQ
+#define IEEE80211_STYPE_PROBE_REQ IEEE80211_FC0_SUBTYPE_PROBE_REQ
+#define IEEE80211_STYPE_DISASSOC IEEE80211_FC0_SUBTYPE_DISASSOC
+#define IEEE80211_STYPE_AUTH IEEE80211_FC0_SUBTYPE_AUTH
+#define IEEE80211_STYPE_DEAUTH IEEE80211_FC0_SUBTYPE_DEAUTH
+#define IEEE80211_STYPE_CTS IEEE80211_FC0_SUBTYPE_CTS
+#define IEEE80211_STYPE_RTS IEEE80211_FC0_SUBTYPE_RTS
+#define IEEE80211_STYPE_ACTION IEEE80211_FC0_SUBTYPE_ACTION
+#define IEEE80211_STYPE_DATA IEEE80211_FC0_SUBTYPE_DATA
+#define IEEE80211_STYPE_QOS_DATA IEEE80211_FC0_SUBTYPE_QOS_DATA
+#define IEEE80211_STYPE_QOS_NULLFUNC IEEE80211_FC0_SUBTYPE_QOS_NULL
+#define IEEE80211_STYPE_QOS_CFACK 0xd0 /* XXX-BZ reserved? */
+
+#define IEEE80211_NUM_ACS 4 /* net8021::WME_NUM_AC */
+
+#define IEEE80211_MAX_SSID_LEN 32 /* 9.4.2.2 SSID element, net80211: IEEE80211_NWID_LEN */
+
+
+/* Figure 9-27, BAR Control field */
+#define IEEE80211_BAR_CTRL_TID_INFO_MASK 0xf000
+#define IEEE80211_BAR_CTRL_TID_INFO_SHIFT 12
+
+#define IEEE80211_PPE_THRES_INFO_PPET_SIZE 1 /* TODO FIXME ax? */
+#define IEEE80211_PPE_THRES_NSS_MASK 2 /* TODO FIXME ax? */
+#define IEEE80211_PPE_THRES_RU_INDEX_BITMASK_POS 3 /* TODO FIXME ax? */
+#define IEEE80211_PPE_THRES_RU_INDEX_BITMASK_MASK 8 /* TODO FIXME ax? */
+#define IEEE80211_HE_PPE_THRES_INFO_HEADER_SIZE 16 /* TODO FIXME ax? */
+
+/* 802.11-2012, Table 8-130-HT Operation element fields and subfields, HT Protection */
+#define IEEE80211_HT_OP_MODE_PROTECTION IEEE80211_HTINFO_OPMODE /* Mask. */
+#define IEEE80211_HT_OP_MODE_PROTECTION_NONE IEEE80211_HTINFO_OPMODE_PURE /* No protection */
+#define IEEE80211_HT_OP_MODE_PROTECTION_NONMEMBER IEEE80211_HTINFO_OPMODE_PROTOPT /* Nonmember protection */
+#define IEEE80211_HT_OP_MODE_PROTECTION_20MHZ IEEE80211_HTINFO_OPMODE_HT20PR /* 20 MHz protection */
+#define IEEE80211_HT_OP_MODE_PROTECTION_NONHT_MIXED IEEE80211_HTINFO_OPMODE_MIXED /* Non-HT mixed */
+
+
+/* 9.6.13.1, Table 9-342 TDLS Action field values. */
+enum ieee80211_tdls_action_code {
+ WLAN_TDLS_SETUP_REQUEST = 0,
+ WLAN_TDLS_SETUP_RESPONSE = 1,
+ WLAN_TDLS_SETUP_CONFIRM = 2,
+ WLAN_TDLS_TEARDOWN = 3,
+ WLAN_TDLS_PEER_TRAFFIC_INDICATION = 4,
+ WLAN_TDLS_CHANNEL_SWITCH_REQUEST = 5,
+ WLAN_TDLS_CHANNEL_SWITCH_RESPONSE = 6,
+ WLAN_TDLS_PEER_PSM_REQUEST = 7,
+ WLAN_TDLS_PEER_PSM_RESPONSE = 8,
+ WLAN_TDLS_PEER_TRAFFIC_RESPONSE = 9,
+ WLAN_TDLS_DISCOVERY_REQUEST = 10,
+ /* 11-255 reserved */
+};
+
+/* 802.11-2020 9.4.2.26, Table 9-153. Extended Capabilities field. */
+/* This is split up into octets CAPA1 = octet 1, ... */
+#define WLAN_EXT_CAPA1_EXT_CHANNEL_SWITCHING BIT(2 % 8)
+#define WLAN_EXT_CAPA3_MULTI_BSSID_SUPPORT BIT(22 % 8)
+#define WLAN_EXT_CAPA3_TIMING_MEASUREMENT_SUPPORT BIT(23 % 8)
+#define WLAN_EXT_CAPA8_OPMODE_NOTIF BIT(62 % 8)
+#define WLAN_EXT_CAPA8_MAX_MSDU_IN_AMSDU_LSB BIT(63 % 8)
+#define WLAN_EXT_CAPA9_MAX_MSDU_IN_AMSDU_MSB BIT(64 % 8)
+#define WLAN_EXT_CAPA10_TWT_REQUESTER_SUPPORT BIT(77 % 8)
+#define WLAN_EXT_CAPA10_TWT_RESPONDER_SUPPORT BIT(78 % 8)
+#define WLAN_EXT_CAPA10_OBSS_NARROW_BW_RU_TOLERANCE_SUPPORT BIT(79 % 8)
+
+#define WLAN_EXT_CAPA11_EMA_SUPPORT 0x00 /* XXX TODO FIXME */
+
+
+/* iwlwifi/mvm/utils:: for (ac = IEEE80211_AC_VO; ac <= IEEE80211_AC_VI; ac++) */
+/* Would be so much easier if we'd define constants to the same. */
+enum ieee80211_ac_numbers {
+ IEEE80211_AC_VO = 0, /* net80211::WME_AC_VO */
+ IEEE80211_AC_VI = 1, /* net80211::WME_AC_VI */
+ IEEE80211_AC_BE = 2, /* net80211::WME_AC_BE */
+ IEEE80211_AC_BK = 3, /* net80211::WME_AC_BK */
+};
+
+#define IEEE80211_MAX_QUEUES 16 /* Assume IEEE80211_NUM_TIDS for the moment. */
+
+#define IEEE80211_WMM_IE_STA_QOSINFO_AC_VO 1
+#define IEEE80211_WMM_IE_STA_QOSINFO_AC_VI 2
+#define IEEE80211_WMM_IE_STA_QOSINFO_AC_BK 4
+#define IEEE80211_WMM_IE_STA_QOSINFO_AC_BE 8
+#define IEEE80211_WMM_IE_STA_QOSINFO_SP_ALL 0xf
+
+
+/* Define the LinuxKPI names directly to the net80211 ones. */
+#define IEEE80211_HT_CAP_LDPC_CODING IEEE80211_HTCAP_LDPC
+#define IEEE80211_HT_CAP_SUP_WIDTH_20_40 IEEE80211_HTCAP_CHWIDTH40
+#define IEEE80211_HT_CAP_SM_PS IEEE80211_HTCAP_SMPS
+#define IEEE80211_HT_CAP_SM_PS_SHIFT 2
+#define IEEE80211_HT_CAP_GRN_FLD IEEE80211_HTCAP_GREENFIELD
+#define IEEE80211_HT_CAP_SGI_20 IEEE80211_HTCAP_SHORTGI20
+#define IEEE80211_HT_CAP_SGI_40 IEEE80211_HTCAP_SHORTGI40
+#define IEEE80211_HT_CAP_TX_STBC IEEE80211_HTCAP_TXSTBC
+#define IEEE80211_HT_CAP_RX_STBC IEEE80211_HTCAP_RXSTBC
+#define IEEE80211_HT_CAP_RX_STBC_SHIFT IEEE80211_HTCAP_RXSTBC_S
+#define IEEE80211_HT_CAP_MAX_AMSDU IEEE80211_HTCAP_MAXAMSDU
+#define IEEE80211_HT_CAP_DSSSCCK40 IEEE80211_HTCAP_DSSSCCK40
+#define IEEE80211_HT_CAP_LSIG_TXOP_PROT IEEE80211_HTCAP_LSIGTXOPPROT
+
+#define IEEE80211_HT_MCS_TX_DEFINED 0x0001
+#define IEEE80211_HT_MCS_TX_RX_DIFF 0x0002
+#define IEEE80211_HT_MCS_TX_MAX_STREAMS_SHIFT 2
+#define IEEE80211_HT_MCS_TX_MAX_STREAMS_MASK 0x0c
+#define IEEE80211_HT_MCS_RX_HIGHEST_MASK 0x3ff
+#define IEEE80211_HT_MCS_MASK_LEN 10
+
+#define IEEE80211_MLD_MAX_NUM_LINKS 15
+#define IEEE80211_MLD_CAP_OP_MAX_SIMUL_LINKS 0xf
+#define IEEE80211_MLD_CAP_OP_TID_TO_LINK_MAP_NEG_SUPP 0x0060
+#define IEEE80211_MLD_CAP_OP_TID_TO_LINK_MAP_NEG_SUPP_SAME 1
+#define IEEE80211_MLD_CAP_OP_LINK_RECONF_SUPPORT 0x2000
+
+struct ieee80211_mcs_info {
+ uint8_t rx_mask[IEEE80211_HT_MCS_MASK_LEN];
+ uint16_t rx_highest;
+ uint8_t tx_params;
+ uint8_t __reserved[3];
+} __packed;
+
+/* 802.11-2020, 9.4.2.55.1 HT Capabilities element structure */
+struct ieee80211_ht_cap {
+ uint16_t cap_info;
+ uint8_t ampdu_params_info;
+ struct ieee80211_mcs_info mcs;
+ uint16_t extended_ht_cap_info;
+ uint32_t tx_BF_cap_info;
+ uint8_t antenna_selection_info;
+} __packed;
+
+#define IEEE80211_HT_MAX_AMPDU_FACTOR 13
+#define IEEE80211_HE_HT_MAX_AMPDU_FACTOR 16
+#define IEEE80211_HE_VHT_MAX_AMPDU_FACTOR 20
+#define IEEE80211_HE_6GHZ_MAX_AMPDU_FACTOR 13
+
+enum ieee80211_ht_max_ampdu_len {
+ IEEE80211_HT_MAX_AMPDU_64K
+};
+
+enum ieee80211_ampdu_mlme_action {
+ IEEE80211_AMPDU_RX_START,
+ IEEE80211_AMPDU_RX_STOP,
+ IEEE80211_AMPDU_TX_OPERATIONAL,
+ IEEE80211_AMPDU_TX_START,
+ IEEE80211_AMPDU_TX_STOP_CONT,
+ IEEE80211_AMPDU_TX_STOP_FLUSH,
+ IEEE80211_AMPDU_TX_STOP_FLUSH_CONT
+};
+
+#define IEEE80211_AMPDU_TX_START_IMMEDIATE 1
+#define IEEE80211_AMPDU_TX_START_DELAY_ADDBA 2
+
+enum ieee80211_chanctx_switch_mode {
+ CHANCTX_SWMODE_REASSIGN_VIF,
+ CHANCTX_SWMODE_SWAP_CONTEXTS,
+};
+
+enum ieee80211_chanctx_change_flags {
+ IEEE80211_CHANCTX_CHANGE_MIN_WIDTH = BIT(0),
+ IEEE80211_CHANCTX_CHANGE_RADAR = BIT(1),
+ IEEE80211_CHANCTX_CHANGE_RX_CHAINS = BIT(2),
+ IEEE80211_CHANCTX_CHANGE_WIDTH = BIT(3),
+ IEEE80211_CHANCTX_CHANGE_CHANNEL = BIT(4),
+ IEEE80211_CHANCTX_CHANGE_PUNCTURING = BIT(5),
+ IEEE80211_CHANCTX_CHANGE_MIN_DEF = BIT(6),
+ IEEE80211_CHANCTX_CHANGE_AP = BIT(7),
+};
+
+enum ieee80211_frame_release_type {
+ IEEE80211_FRAME_RELEASE_PSPOLL = 1,
+ IEEE80211_FRAME_RELEASE_UAPSD = 2,
+};
+
+enum ieee80211_p2p_attr_ids {
+ IEEE80211_P2P_ATTR_DEVICE_ID,
+ IEEE80211_P2P_ATTR_DEVICE_INFO,
+ IEEE80211_P2P_ATTR_GROUP_ID,
+ IEEE80211_P2P_ATTR_LISTEN_CHANNEL,
+ IEEE80211_P2P_ATTR_ABSENCE_NOTICE,
+};
+
+enum ieee80211_reconfig_type {
+ IEEE80211_RECONFIG_TYPE_RESTART,
+ IEEE80211_RECONFIG_TYPE_SUSPEND,
+};
+
+enum ieee80211_roc_type {
+ IEEE80211_ROC_TYPE_MGMT_TX,
+ IEEE80211_ROC_TYPE_NORMAL,
+};
+
+enum ieee80211_smps_mode {
+ IEEE80211_SMPS_OFF,
+ IEEE80211_SMPS_STATIC,
+ IEEE80211_SMPS_DYNAMIC,
+ IEEE80211_SMPS_AUTOMATIC,
+ IEEE80211_SMPS_NUM_MODES,
+};
+
+/* net80211::IEEE80211_S_* different but represents the state machine. */
+/* Note: order here is important! */
+enum ieee80211_sta_state {
+ IEEE80211_STA_NOTEXIST = 0,
+ IEEE80211_STA_NONE = 1,
+ IEEE80211_STA_AUTH = 2,
+ IEEE80211_STA_ASSOC = 3,
+ IEEE80211_STA_AUTHORIZED = 4, /* 802.1x */
+};
+
+enum ieee80211_sta_rx_bandwidth {
+ IEEE80211_STA_RX_BW_20 = 0,
+ IEEE80211_STA_RX_BW_40,
+ IEEE80211_STA_RX_BW_80,
+ IEEE80211_STA_RX_BW_160,
+ IEEE80211_STA_RX_BW_320,
+};
+
+enum ieee80211_tx_info_flags {
+ /* XXX TODO .. right shift numbers - not sure where that came from? */
+ IEEE80211_TX_CTL_AMPDU = BIT(0),
+ IEEE80211_TX_CTL_ASSIGN_SEQ = BIT(1),
+ IEEE80211_TX_CTL_NO_ACK = BIT(2),
+ IEEE80211_TX_CTL_SEND_AFTER_DTIM = BIT(3),
+ IEEE80211_TX_CTL_TX_OFFCHAN = BIT(4),
+ IEEE80211_TX_CTL_REQ_TX_STATUS = BIT(5),
+ IEEE80211_TX_STATUS_EOSP = BIT(6),
+ IEEE80211_TX_STAT_ACK = BIT(7),
+ IEEE80211_TX_STAT_AMPDU = BIT(8),
+ IEEE80211_TX_STAT_AMPDU_NO_BACK = BIT(9),
+ IEEE80211_TX_STAT_TX_FILTERED = BIT(10),
+ IEEE80211_TX_STAT_NOACK_TRANSMITTED = BIT(11),
+ IEEE80211_TX_CTL_FIRST_FRAGMENT = BIT(12),
+ IEEE80211_TX_INTFL_DONT_ENCRYPT = BIT(13),
+ IEEE80211_TX_CTL_NO_CCK_RATE = BIT(14),
+ IEEE80211_TX_CTL_INJECTED = BIT(15),
+ IEEE80211_TX_CTL_HW_80211_ENCAP = BIT(16),
+ IEEE80211_TX_CTL_USE_MINRATE = BIT(17),
+ IEEE80211_TX_CTL_RATE_CTRL_PROBE = BIT(18),
+ IEEE80211_TX_CTL_LDPC = BIT(19),
+ IEEE80211_TX_CTL_STBC = BIT(20),
+} __packed;
+
+enum ieee80211_tx_status_flags {
+ IEEE80211_TX_STATUS_ACK_SIGNAL_VALID = BIT(0),
+};
+
+enum ieee80211_tx_control_flags {
+ /* XXX TODO .. right shift numbers */
+ IEEE80211_TX_CTRL_PORT_CTRL_PROTO = BIT(0),
+ IEEE80211_TX_CTRL_PS_RESPONSE = BIT(1),
+ IEEE80211_TX_CTRL_RATE_INJECT = BIT(2),
+ IEEE80211_TX_CTRL_DONT_USE_RATE_MASK = BIT(3),
+ IEEE80211_TX_CTRL_MLO_LINK = 0xF0000000, /* This is IEEE80211_LINK_UNSPECIFIED on the high bits. */
+};
+
+enum ieee80211_tx_rate_flags {
+ /* XXX TODO .. right shift numbers */
+ IEEE80211_TX_RC_40_MHZ_WIDTH = BIT(0),
+ IEEE80211_TX_RC_80_MHZ_WIDTH = BIT(1),
+ IEEE80211_TX_RC_160_MHZ_WIDTH = BIT(2),
+ IEEE80211_TX_RC_GREEN_FIELD = BIT(3),
+ IEEE80211_TX_RC_MCS = BIT(4),
+ IEEE80211_TX_RC_SHORT_GI = BIT(5),
+ IEEE80211_TX_RC_VHT_MCS = BIT(6),
+ IEEE80211_TX_RC_USE_SHORT_PREAMBLE = BIT(7),
+};
+
+#define IEEE80211_RNR_TBTT_PARAMS_PSD_RESERVED -128
+
+#define IEEE80211_HT_CTL_LEN 4
+
+struct ieee80211_hdr { /* net80211::ieee80211_frame_addr4 */
+ __le16 frame_control;
+ __le16 duration_id;
+ uint8_t addr1[ETH_ALEN];
+ uint8_t addr2[ETH_ALEN];
+ uint8_t addr3[ETH_ALEN];
+ __le16 seq_ctrl;
+ uint8_t addr4[ETH_ALEN];
+};
+
+struct ieee80211_hdr_3addr { /* net80211::ieee80211_frame */
+ __le16 frame_control;
+ __le16 duration_id;
+ uint8_t addr1[ETH_ALEN];
+ uint8_t addr2[ETH_ALEN];
+ uint8_t addr3[ETH_ALEN];
+ __le16 seq_ctrl;
+};
+
+struct ieee80211_qos_hdr { /* net80211:ieee80211_qosframe */
+ __le16 frame_control;
+ __le16 duration_id;
+ uint8_t addr1[ETH_ALEN];
+ uint8_t addr2[ETH_ALEN];
+ uint8_t addr3[ETH_ALEN];
+ __le16 seq_ctrl;
+ __le16 qos_ctrl;
+};
+
+struct ieee80211_vendor_ie {
+};
+
+/* 802.11-2020, Table 9-359-Block Ack Action field values */
+enum ieee80211_back {
+ WLAN_ACTION_ADDBA_REQ = 0,
+};
+
+enum ieee80211_sa_query {
+ WLAN_ACTION_SA_QUERY_RESPONSE = 1,
+};
+
+/* 802.11-2020, Table 9-51-Category values */
+enum ieee80211_category {
+ WLAN_CATEGORY_BACK = 3,
+ WLAN_CATEGORY_SA_QUERY = 8, /* net80211::IEEE80211_ACTION_CAT_SA_QUERY */
+};
+
+/* 80211-2020 9.3.3.2 Format of Management frames */
+struct ieee80211_mgmt {
+ __le16 frame_control;
+ __le16 duration_id;
+ uint8_t da[ETH_ALEN];
+ uint8_t sa[ETH_ALEN];
+ uint8_t bssid[ETH_ALEN];
+ __le16 seq_ctrl;
+ union {
+ /* 9.3.3.3 Beacon frame format */
+ struct {
+ uint64_t timestamp;
+ uint16_t beacon_int;
+ uint16_t capab_info;
+ uint8_t variable[0];
+ } __packed beacon;
+ /* 9.3.3.5 Association Request frame format */
+ struct {
+ uint16_t capab_info;
+ uint16_t listen_interval;
+ uint8_t variable[0];
+ } __packed assoc_req;
+ /* 9.3.3.10 Probe Request frame format */
+ struct {
+ uint8_t variable[0];
+ } __packed probe_req;
+ /* 9.3.3.11 Probe Response frame format */
+ struct {
+ uint64_t timestamp;
+ uint16_t beacon_int;
+ uint16_t capab_info;
+ uint8_t variable[0];
+ } __packed probe_resp;
+ /* 9.3.3.14 Action frame format */
+ struct {
+ /* 9.4.1.11 Action field */
+ uint8_t category;
+ /* 9.6.8 Public Action details */
+ union {
+ /* 9.6.2.5 TPC Report frame format */
+ struct {
+ uint8_t spec_mgmt;
+ uint8_t dialog_token;
+ /* uint32_t tpc_rep_elem:: */
+ uint8_t tpc_elem_id;
+ uint8_t tpc_elem_length;
+ uint8_t tpc_elem_tx_power;
+ uint8_t tpc_elem_link_margin;
+ } __packed tpc_report;
+ /* 9.6.8.33 Fine Timing Measurement frame format */
+ struct {
+ uint8_t dialog_token;
+ uint8_t follow_up;
+ uint8_t tod[6];
+ uint8_t toa[6];
+ uint16_t tod_error;
+ uint16_t toa_error;
+ uint8_t variable[0];
+ } __packed ftm;
+ /* 802.11-2016, 9.6.5.2 ADDBA Request frame format */
+ struct {
+ uint8_t action_code;
+ uint8_t dialog_token;
+ uint16_t capab;
+ uint16_t timeout;
+ uint16_t start_seq_num;
+ /* Optional follows... */
+ uint8_t variable[0];
+ } __packed addba_req;
+ /* XXX */
+ struct {
+ uint8_t dialog_token;
+ } __packed wnm_timing_msr;
+ } u;
+ } __packed action;
+ DECLARE_FLEX_ARRAY(uint8_t, body);
+ } u;
+} __packed __aligned(2);
+
+struct ieee80211_cts { /* net80211::ieee80211_frame_cts */
+ __le16 frame_control;
+ __le16 duration;
+ uint8_t ra[ETH_ALEN];
+} __packed;
+
+struct ieee80211_rts { /* net80211::ieee80211_frame_rts */
+ __le16 frame_control;
+ __le16 duration;
+ uint8_t ra[ETH_ALEN];
+ uint8_t ta[ETH_ALEN];
+} __packed;
+
+#define MHZ_TO_KHZ(_f) ((_f) * 1000)
+#define DBI_TO_MBI(_g) ((_g) * 100)
+#define MBI_TO_DBI(_x) ((_x) / 100)
+#define DBM_TO_MBM(_g) ((_g) * 100)
+#define MBM_TO_DBM(_x) ((_x) / 100)
+
+#define IEEE80211_SEQ_TO_SN(_seqn) (((_seqn) & IEEE80211_SEQ_SEQ_MASK) >> \
+ IEEE80211_SEQ_SEQ_SHIFT)
+#define IEEE80211_SN_TO_SEQ(_sn) (((_sn) << IEEE80211_SEQ_SEQ_SHIFT) & \
+ IEEE80211_SEQ_SEQ_MASK)
+
+/* Time unit (TU) to .. See net80211: IEEE80211_DUR_TU */
+#define TU_TO_JIFFIES(_tu) (usecs_to_jiffies(_tu) * 1024)
+#define TU_TO_EXP_TIME(_tu) (jiffies + TU_TO_JIFFIES(_tu))
+
+/* 9.4.2.21.1, Table 9-82. */
+#define IEEE80211_SPCT_MSR_RPRT_TYPE_LCI 8
+#define IEEE80211_SPCT_MSR_RPRT_TYPE_CIVIC 11
+
+/* 9.4.2.1, Table 9-77. Element IDs. */
+enum ieee80211_eid {
+ WLAN_EID_SSID = 0,
+ WLAN_EID_SUPP_RATES = 1,
+ WLAN_EID_DS_PARAMS = 3,
+ WLAN_EID_TIM = 5,
+ WLAN_EID_COUNTRY = 7, /* IEEE80211_ELEMID_COUNTRY */
+ WLAN_EID_REQUEST = 10,
+ WLAN_EID_QBSS_LOAD = 11, /* IEEE80211_ELEMID_BSSLOAD */
+ WLAN_EID_CHANNEL_SWITCH = 37,
+ WLAN_EID_MEASURE_REPORT = 39,
+ WLAN_EID_HT_CAPABILITY = 45, /* IEEE80211_ELEMID_HTCAP */
+ WLAN_EID_RSN = 48, /* IEEE80211_ELEMID_RSN */
+ WLAN_EID_EXT_SUPP_RATES = 50,
+ WLAN_EID_EXT_NON_INHERITANCE = 56,
+ WLAN_EID_EXT_CHANSWITCH_ANN = 60,
+ WLAN_EID_MULTIPLE_BSSID = 71, /* IEEE80211_ELEMID_MULTIBSSID */
+ WLAN_EID_MULTI_BSSID_IDX = 85,
+ WLAN_EID_EXT_CAPABILITY = 127,
+ WLAN_EID_VHT_CAPABILITY = 191, /* IEEE80211_ELEMID_VHT_CAP */
+ WLAN_EID_S1G_TWT = 216,
+ WLAN_EID_VENDOR_SPECIFIC = 221, /* IEEE80211_ELEMID_VENDOR */
+};
+
+enum ieee80211_eid_ext {
+ WLAN_EID_EXT_HE_CAPABILITY = 35,
+};
+
+#define for_each_element(_elem, _data, _len) \
+ for (_elem = (const struct element *)(_data); \
+ (((const uint8_t *)(_data) + (_len) - (const uint8_t *)_elem) >= sizeof(*_elem)) && \
+ (((const uint8_t *)(_data) + (_len) - (const uint8_t *)_elem) >= (sizeof(*_elem) + _elem->datalen)); \
+ _elem = (const struct element *)(_elem->data + _elem->datalen))
+
+#define for_each_element_id(_elem, _eid, _data, _len) \
+ for_each_element(_elem, _data, _len) \
+ if (_elem->id == (_eid))
+
+/* 9.4.1.7, Table 9-45. Reason codes. */
+enum ieee80211_reason_code {
+ /* reserved = 0, */
+ WLAN_REASON_UNSPECIFIED = 1,
+ WLAN_REASON_DEAUTH_LEAVING = 3, /* LEAVING_NETWORK_DEAUTH */
+ WLAN_REASON_TDLS_TEARDOWN_UNREACHABLE = 25,
+ WLAN_REASON_TDLS_TEARDOWN_UNSPECIFIED = 26,
+};
+
+/* 9.4.1.9, Table 9-46. Status codes. */
+enum ieee80211_status_code {
+ WLAN_STATUS_SUCCESS = 0,
+ WLAN_STATUS_AUTH_TIMEOUT = 16, /* REJECTED_SEQUENCE_TIMEOUT */
+};
+
+/* 9.3.1.22 Trigger frame format; 80211ax-2021 */
+struct ieee80211_trigger {
+ __le16 frame_control;
+ __le16 duration_id;
+ uint8_t ra[ETH_ALEN];
+ uint8_t ta[ETH_ALEN];
+ __le64 common_info; /* 8+ really */
+ uint8_t variable[];
+};
+
+/* Table 9-29c-Trigger Type subfield encoding */
+enum {
+ IEEE80211_TRIGGER_TYPE_BASIC = 0x0,
+ IEEE80211_TRIGGER_TYPE_MU_BAR = 0x2,
+#if 0
+ /* Not seen yet. */
+ BFRP = 0x1,
+ MU-RTS = 0x3,
+ BSRP = 0x4,
+ GCR MU-BAR = 0x5,
+ BQRP = 0x6,
+ NFRP = 0x7,
+ /* 0x8..0xf reserved */
+#endif
+ IEEE80211_TRIGGER_TYPE_MASK = 0xf
+};
+
+#define IEEE80211_TRIGGER_ULBW_MASK 0xc0000
+#define IEEE80211_TRIGGER_ULBW_20MHZ 0x0
+#define IEEE80211_TRIGGER_ULBW_40MHZ 0x1
+#define IEEE80211_TRIGGER_ULBW_80MHZ 0x2
+#define IEEE80211_TRIGGER_ULBW_160_80P80MHZ 0x3
+
+/* 802.11-2020, Figure 9-687-Control field format; 802.11ax-2021 */
+#define IEEE80211_TWT_CONTROL_NEG_TYPE_BROADCAST BIT(3)
+#define IEEE80211_TWT_CONTROL_RX_DISABLED BIT(4)
+#define IEEE80211_TWT_CONTROL_WAKE_DUR_UNIT BIT(5)
+
+/* 802.11-2020, Figure 9-688-Request Type field format; 802.11ax-2021 */
+#define IEEE80211_TWT_REQTYPE_SETUP_CMD (BIT(1) | BIT(2) | BIT(3))
+#define IEEE80211_TWT_REQTYPE_TRIGGER BIT(4)
+#define IEEE80211_TWT_REQTYPE_IMPLICIT BIT(5)
+#define IEEE80211_TWT_REQTYPE_FLOWTYPE BIT(6)
+#define IEEE80211_TWT_REQTYPE_FLOWID (BIT(7) | BIT(8) | BIT(9))
+#define IEEE80211_TWT_REQTYPE_WAKE_INT_EXP (BIT(10) | BIT(11) | BIT(12) | BIT(13) | BIT(14))
+#define IEEE80211_TWT_REQTYPE_PROTECTION BIT(15)
+
+struct ieee80211_twt_params {
+ int mantissa, min_twt_dur, twt;
+ uint16_t req_type;
+};
+
+struct ieee80211_twt_setup {
+ int control;
+ struct ieee80211_twt_params *params;
+};
+
+/* 802.11-2020, Table 9-297-TWT Setup Command field values */
+enum ieee80211_twt_setup_cmd {
+ TWT_SETUP_CMD_REQUEST = 0,
+ TWT_SETUP_CMD_SUGGEST = 1,
+ /* DEMAND = 2, */
+ /* GROUPING = 3, */
+ TWT_SETUP_CMD_ACCEPT = 4,
+ /* ALTERNATE = 5 */
+ TWT_SETUP_CMD_DICTATE = 6,
+ TWT_SETUP_CMD_REJECT = 7,
+};
+
+struct ieee80211_bssid_index {
+ int bssid_index;
+};
+
+enum ieee80211_ap_reg_power {
+ IEEE80211_REG_UNSET_AP,
+ IEEE80211_REG_LPI_AP,
+ IEEE80211_REG_SP_AP,
+ IEEE80211_REG_VLP_AP,
+};
+
+/*
+ * 802.11ax-2021, Table 9-277-Meaning of Maximum Transmit Power Count subfield
+ * if Maximum Transmit Power Interpretation subfield is 1 or 3
+ */
+#define IEEE80211_MAX_NUM_PWR_LEVEL 8
+
+/*
+ * 802.11ax-2021, Table 9-275a-Maximum Transmit Power Interpretation subfield
+ * encoding (4) * Table E-12-Regulatory Info subfield encoding in the
+ * United States (2)
+ */
+#define IEEE80211_TPE_MAX_IE_NUM 8
+
+/* 802.11ax-2021, 9.4.2.161 Transmit Power Envelope element */
+struct ieee80211_tx_pwr_env {
+ uint8_t tx_power_info;
+ uint8_t tx_power[IEEE80211_MAX_NUM_PWR_LEVEL];
+};
+
+/* 802.11ax-2021, Figure 9-617-Transmit Power Information field format */
+/* These are field masks (3bit/3bit/2bit). */
+#define IEEE80211_TX_PWR_ENV_INFO_COUNT 0x07
+#define IEEE80211_TX_PWR_ENV_INFO_INTERPRET 0x38
+#define IEEE80211_TX_PWR_ENV_INFO_CATEGORY 0xc0
+
+/*
+ * 802.11ax-2021, Table 9-275a-Maximum Transmit Power Interpretation subfield
+ * encoding
+ */
+enum ieee80211_tx_pwr_interpretation_subfield_enc {
+ IEEE80211_TPE_LOCAL_EIRP,
+ IEEE80211_TPE_LOCAL_EIRP_PSD,
+ IEEE80211_TPE_REG_CLIENT_EIRP,
+ IEEE80211_TPE_REG_CLIENT_EIRP_PSD,
+};
+
+enum ieee80211_tx_pwr_category_6ghz {
+ IEEE80211_TPE_CAT_6GHZ_DEFAULT,
+};
+
+/* 802.11-2020, 9.4.2.27 BSS Load element */
+struct ieee80211_bss_load_elem {
+ uint16_t sta_count;
+ uint8_t channel_util;
+ uint16_t avail_adm_capa;
+};
+
+struct ieee80211_p2p_noa_desc {
+ uint32_t count; /* uint8_t ? */
+ uint32_t duration;
+ uint32_t interval;
+ uint32_t start_time;
+};
+
+struct ieee80211_p2p_noa_attr {
+ uint8_t index;
+ uint8_t oppps_ctwindow;
+ struct ieee80211_p2p_noa_desc desc[4];
+};
+
+
+/* net80211: IEEE80211_IS_CTL() */
+static __inline bool
+ieee80211_is_ctl(__le16 fc)
+{
+ __le16 v;
+
+ fc &= htole16(IEEE80211_FC0_TYPE_MASK);
+ v = htole16(IEEE80211_FC0_TYPE_CTL);
+
+ return (fc == v);
+}
+
+/* net80211: IEEE80211_IS_DATA() */
+static __inline bool
+ieee80211_is_data(__le16 fc)
+{
+ __le16 v;
+
+ fc &= htole16(IEEE80211_FC0_TYPE_MASK);
+ v = htole16(IEEE80211_FC0_TYPE_DATA);
+
+ return (fc == v);
+}
+
+/* net80211: IEEE80211_IS_QOSDATA() */
+static __inline bool
+ieee80211_is_data_qos(__le16 fc)
+{
+ __le16 v;
+
+ fc &= htole16(IEEE80211_FC0_SUBTYPE_QOS_DATA | IEEE80211_FC0_TYPE_MASK);
+ v = htole16(IEEE80211_FC0_SUBTYPE_QOS_DATA | IEEE80211_FC0_TYPE_DATA);
+
+ return (fc == v);
+}
+
+/* net80211: IEEE80211_IS_MGMT() */
+static __inline bool
+ieee80211_is_mgmt(__le16 fc)
+{
+ __le16 v;
+
+ fc &= htole16(IEEE80211_FC0_TYPE_MASK);
+ v = htole16(IEEE80211_FC0_TYPE_MGT);
+
+ return (fc == v);
+}
+
+
+/* Derived from net80211::ieee80211_anyhdrsize. */
+static __inline unsigned int
+ieee80211_hdrlen(__le16 fc)
+{
+ unsigned int size;
+
+ if (ieee80211_is_ctl(fc)) {
+ switch (fc & htole16(IEEE80211_FC0_SUBTYPE_MASK)) {
+ case htole16(IEEE80211_FC0_SUBTYPE_CTS):
+ case htole16(IEEE80211_FC0_SUBTYPE_ACK):
+ return sizeof(struct ieee80211_frame_ack);
+ case htole16(IEEE80211_FC0_SUBTYPE_BAR):
+ return sizeof(struct ieee80211_frame_bar);
+ }
+ return (sizeof(struct ieee80211_frame_min));
+ }
+
+ size = sizeof(struct ieee80211_frame);
+ if (ieee80211_is_data(fc)) {
+ if ((fc & htole16(IEEE80211_FC1_DIR_MASK << 8)) ==
+ htole16(IEEE80211_FC1_DIR_DSTODS << 8))
+ size += IEEE80211_ADDR_LEN;
+ if ((fc & htole16(IEEE80211_FC0_SUBTYPE_QOS_DATA |
+ IEEE80211_FC0_TYPE_MASK)) ==
+ htole16(IEEE80211_FC0_SUBTYPE_QOS_DATA |
+ IEEE80211_FC0_TYPE_DATA))
+ size += sizeof(uint16_t);
+ }
+
+ if (ieee80211_is_mgmt(fc)) {
+#ifdef __notyet__
+ printf("XXX-BZ %s: TODO? fc %#04x size %u\n",
+ __func__, fc, size);
+#endif
+ ;
+ }
+
+ return (size);
+}
+
+static inline bool
+ieee80211_is_trigger(__le16 fc)
+{
+ __le16 v;
+
+ fc &= htole16(IEEE80211_FC0_SUBTYPE_MASK | IEEE80211_FC0_TYPE_MASK);
+ v = htole16(IEEE80211_FC0_SUBTYPE_TRIGGER | IEEE80211_FC0_TYPE_CTL);
+
+ return (fc == v);
+}
+
+static __inline bool
+ieee80211_is_action(__le16 fc)
+{
+ __le16 v;
+
+ fc &= htole16(IEEE80211_FC0_SUBTYPE_MASK | IEEE80211_FC0_TYPE_MASK);
+ v = htole16(IEEE80211_FC0_SUBTYPE_ACTION | IEEE80211_FC0_TYPE_MGT);
+
+ return (fc == v);
+}
+
+static __inline bool
+ieee80211_is_probe_resp(__le16 fc)
+{
+ __le16 v;
+
+ fc &= htole16(IEEE80211_FC0_SUBTYPE_MASK | IEEE80211_FC0_TYPE_MASK);
+ v = htole16(IEEE80211_FC0_SUBTYPE_PROBE_RESP | IEEE80211_FC0_TYPE_MGT);
+
+ return (fc == v);
+}
+
+static __inline bool
+ieee80211_is_auth(__le16 fc)
+{
+ __le16 v;
+
+ fc &= htole16(IEEE80211_FC0_SUBTYPE_MASK | IEEE80211_FC0_TYPE_MASK);
+ v = htole16(IEEE80211_FC0_SUBTYPE_AUTH | IEEE80211_FC0_TYPE_MGT);
+
+ return (fc == v);
+}
+
+static __inline bool
+ieee80211_is_assoc_req(__le16 fc)
+{
+ __le16 v;
+
+ fc &= htole16(IEEE80211_FC0_SUBTYPE_MASK | IEEE80211_FC0_TYPE_MASK);
+ v = htole16(IEEE80211_FC0_SUBTYPE_ASSOC_REQ | IEEE80211_FC0_TYPE_MGT);
+
+ return (fc == v);
+}
+
+static __inline bool
+ieee80211_is_assoc_resp(__le16 fc)
+{
+ __le16 v;
+
+ fc &= htole16(IEEE80211_FC0_SUBTYPE_MASK | IEEE80211_FC0_TYPE_MASK);
+ v = htole16(IEEE80211_FC0_SUBTYPE_ASSOC_RESP | IEEE80211_FC0_TYPE_MGT);
+
+ return (fc == v);
+}
+
+static __inline bool
+ieee80211_is_reassoc_req(__le16 fc)
+{
+ __le16 v;
+
+ fc &= htole16(IEEE80211_FC0_SUBTYPE_MASK | IEEE80211_FC0_TYPE_MASK);
+ v = htole16(IEEE80211_FC0_SUBTYPE_REASSOC_REQ | IEEE80211_FC0_TYPE_MGT);
+
+ return (fc == v);
+}
+
+static __inline bool
+ieee80211_is_reassoc_resp(__le16 fc)
+{
+ __le16 v;
+
+ fc &= htole16(IEEE80211_FC0_SUBTYPE_MASK | IEEE80211_FC0_TYPE_MASK);
+ v = htole16(IEEE80211_FC0_SUBTYPE_REASSOC_RESP | IEEE80211_FC0_TYPE_MGT);
+
+ return (fc == v);
+}
+
+static __inline bool
+ieee80211_is_disassoc(__le16 fc)
+{
+ __le16 v;
+
+ fc &= htole16(IEEE80211_FC0_SUBTYPE_MASK | IEEE80211_FC0_TYPE_MASK);
+ v = htole16(IEEE80211_FC0_SUBTYPE_DISASSOC | IEEE80211_FC0_TYPE_MGT);
+
+ return (fc == v);
+}
+
+static __inline bool
+ieee80211_is_data_present(__le16 fc)
+{
+ __le16 v;
+
+ /* If it is a data frame and NODATA is not present. */
+ fc &= htole16(IEEE80211_FC0_TYPE_MASK | IEEE80211_FC0_SUBTYPE_NODATA);
+ v = htole16(IEEE80211_FC0_TYPE_DATA);
+
+ return (fc == v);
+}
+
+static __inline bool
+ieee80211_is_deauth(__le16 fc)
+{
+ __le16 v;
+
+ fc &= htole16(IEEE80211_FC0_SUBTYPE_MASK | IEEE80211_FC0_TYPE_MASK);
+ v = htole16(IEEE80211_FC0_SUBTYPE_DEAUTH | IEEE80211_FC0_TYPE_MGT);
+
+ return (fc == v);
+}
+
+static __inline bool
+ieee80211_is_beacon(__le16 fc)
+{
+ __le16 v;
+
+ /*
+ * For as much as I get it this comes in LE and unlike FreeBSD
+ * where we get the entire frame header and u8[], here we get the
+ * 9.2.4.1 Frame Control field only. Mask and compare.
+ */
+ fc &= htole16(IEEE80211_FC0_SUBTYPE_MASK | IEEE80211_FC0_TYPE_MASK);
+ v = htole16(IEEE80211_FC0_SUBTYPE_BEACON | IEEE80211_FC0_TYPE_MGT);
+
+ return (fc == v);
+}
+
+
+static __inline bool
+ieee80211_is_probe_req(__le16 fc)
+{
+ __le16 v;
+
+ fc &= htole16(IEEE80211_FC0_SUBTYPE_MASK | IEEE80211_FC0_TYPE_MASK);
+ v = htole16(IEEE80211_FC0_SUBTYPE_PROBE_REQ | IEEE80211_FC0_TYPE_MGT);
+
+ return (fc == v);
+}
+
+static __inline bool
+ieee80211_has_protected(__le16 fc)
+{
+
+ return (fc & htole16(IEEE80211_FC1_PROTECTED << 8));
+}
+
+static __inline bool
+ieee80211_is_back_req(__le16 fc)
+{
+ __le16 v;
+
+ fc &= htole16(IEEE80211_FC0_SUBTYPE_MASK | IEEE80211_FC0_TYPE_MASK);
+ v = htole16(IEEE80211_FC0_SUBTYPE_BAR | IEEE80211_FC0_TYPE_CTL);
+
+ return (fc == v);
+}
+
+static __inline bool
+ieee80211_is_bufferable_mmpdu(struct sk_buff *skb)
+{
+ struct ieee80211_mgmt *mgmt;
+ __le16 fc;
+
+ mgmt = (struct ieee80211_mgmt *)skb->data;
+ fc = mgmt->frame_control;
+
+ /* 11.2.2 Bufferable MMPDUs, 80211-2020. */
+ /* XXX we do not care about IBSS yet. */
+
+ if (!ieee80211_is_mgmt(fc))
+ return (false);
+ if (ieee80211_is_action(fc)) /* XXX FTM? */
+ return (true); /* XXX false? */
+ if (ieee80211_is_disassoc(fc))
+ return (true);
+ if (ieee80211_is_deauth(fc))
+ return (true);
+
+ TODO();
+
+ return (false);
+}
+
+static __inline bool
+ieee80211_is_nullfunc(__le16 fc)
+{
+ __le16 v;
+
+ fc &= htole16(IEEE80211_FC0_SUBTYPE_MASK | IEEE80211_FC0_TYPE_MASK);
+ v = htole16(IEEE80211_FC0_SUBTYPE_NODATA | IEEE80211_FC0_TYPE_DATA);
+
+ return (fc == v);
+}
+
+static __inline bool
+ieee80211_is_qos_nullfunc(__le16 fc)
+{
+ __le16 v;
+
+ fc &= htole16(IEEE80211_FC0_SUBTYPE_MASK | IEEE80211_FC0_TYPE_MASK);
+ v = htole16(IEEE80211_FC0_SUBTYPE_QOS_NULL | IEEE80211_FC0_TYPE_DATA);
+
+ return (fc == v);
+}
+
+static __inline bool
+ieee80211_is_any_nullfunc(__le16 fc)
+{
+
+ return (ieee80211_is_nullfunc(fc) || ieee80211_is_qos_nullfunc(fc));
+}
+
+static inline bool
+ieee80211_is_pspoll(__le16 fc)
+{
+ __le16 v;
+
+ fc &= htole16(IEEE80211_FC0_SUBTYPE_MASK | IEEE80211_FC0_TYPE_MASK);
+ v = htole16(IEEE80211_FC0_SUBTYPE_PS_POLL | IEEE80211_FC0_TYPE_CTL);
+
+ return (fc == v);
+}
+
+static __inline bool
+ieee80211_has_a4(__le16 fc)
+{
+ __le16 v;
+
+ fc &= htole16((IEEE80211_FC1_DIR_TODS | IEEE80211_FC1_DIR_FROMDS) << 8);
+ v = htole16((IEEE80211_FC1_DIR_TODS | IEEE80211_FC1_DIR_FROMDS) << 8);
+
+ return (fc == v);
+}
+
+static __inline bool
+ieee80211_has_order(__le16 fc)
+{
+
+ return (fc & htole16(IEEE80211_FC1_ORDER << 8));
+}
+
+static __inline bool
+ieee80211_has_retry(__le16 fc)
+{
+
+ return (fc & htole16(IEEE80211_FC1_RETRY << 8));
+}
+
+
+static __inline bool
+ieee80211_has_fromds(__le16 fc)
+{
+
+ return (fc & htole16(IEEE80211_FC1_DIR_FROMDS << 8));
+}
+
+static __inline bool
+ieee80211_has_tods(__le16 fc)
+{
+
+ return (fc & htole16(IEEE80211_FC1_DIR_TODS << 8));
+}
+
+static __inline uint8_t *
+ieee80211_get_SA(struct ieee80211_hdr *hdr)
+{
+
+ if (ieee80211_has_a4(hdr->frame_control))
+ return (hdr->addr4);
+ if (ieee80211_has_fromds(hdr->frame_control))
+ return (hdr->addr3);
+ return (hdr->addr2);
+}
+
+static __inline uint8_t *
+ieee80211_get_DA(struct ieee80211_hdr *hdr)
+{
+
+ if (ieee80211_has_tods(hdr->frame_control))
+ return (hdr->addr3);
+ return (hdr->addr1);
+}
+
+static __inline bool
+ieee80211_is_frag(struct ieee80211_hdr *hdr)
+{
+ TODO();
+ return (false);
+}
+
+static __inline bool
+ieee80211_is_first_frag(__le16 fc)
+{
+ TODO();
+ return (false);
+}
+
+static __inline bool
+ieee80211_is_robust_mgmt_frame(struct sk_buff *skb)
+{
+ TODO();
+ return (false);
+}
+
+static __inline bool
+ieee80211_is_ftm(struct sk_buff *skb)
+{
+ TODO();
+ return (false);
+}
+
+static __inline bool
+ieee80211_is_timing_measurement(struct sk_buff *skb)
+{
+ TODO();
+ return (false);
+}
+
+static __inline bool
+ieee80211_has_pm(__le16 fc)
+{
+ TODO();
+ return (false);
+}
+
+static __inline bool
+ieee80211_has_morefrags(__le16 fc)
+{
+
+ fc &= htole16(IEEE80211_FC1_MORE_FRAG << 8);
+ return (fc != 0);
+}
+
+static __inline u8 *
+ieee80211_get_qos_ctl(struct ieee80211_hdr *hdr)
+{
+ if (ieee80211_has_a4(hdr->frame_control))
+ return (u8 *)hdr + 30;
+ else
+ return (u8 *)hdr + 24;
+}
+
+#endif /* _LINUXKPI_LINUX_IEEE80211_H */
diff --git a/sys/compat/linuxkpi/common/include/linux/if_arp.h b/sys/compat/linuxkpi/common/include/linux/if_arp.h
index 9235e2dff9cf..6201c3a1c284 100644
--- a/sys/compat/linuxkpi/common/include/linux/if_arp.h
+++ b/sys/compat/linuxkpi/common/include/linux/if_arp.h
@@ -25,13 +25,11 @@
* 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.
- *
- * $FreeBSD$
*/
-#ifndef _LINUX_IF_ARP_H_
-#define _LINUX_IF_ARP_H_
+#ifndef _LINUXKPI_LINUX_IF_ARP_H_
+#define _LINUXKPI_LINUX_IF_ARP_H_
#include <sys/param.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <net/if_arp.h>
-#endif /* _LINUX_IF_ARP_H_ */
+#endif /* _LINUXKPI_LINUX_IF_ARP_H_ */
diff --git a/sys/compat/linuxkpi/common/include/linux/if_ether.h b/sys/compat/linuxkpi/common/include/linux/if_ether.h
index 187446c4c591..6676e8fc142f 100644
--- a/sys/compat/linuxkpi/common/include/linux/if_ether.h
+++ b/sys/compat/linuxkpi/common/include/linux/if_ether.h
@@ -4,6 +4,10 @@
* Copyright (c) 2010 Panasas, Inc.
* Copyright (c) 2013 Mellanox Technologies, Ltd.
* All rights reserved.
+ * Copyright (c) 2021-2022 The FreeBSD Foundation
+ *
+ * Portions of this software were developed by Björn Zeeb
+ * under sponsorship from the FreeBSD Foundation.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
@@ -25,13 +29,12 @@
* 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.
- *
- * $FreeBSD$
*/
-#ifndef _LINUX_IF_ETHER_H_
-#define _LINUX_IF_ETHER_H_
+#ifndef _LINUXKPI_LINUX_IF_ETHER_H_
+#define _LINUXKPI_LINUX_IF_ETHER_H_
#include <linux/types.h>
+#include <linux/skbuff.h>
#include <net/ethernet.h>
@@ -55,6 +58,9 @@
#define ETH_P_8021AD ETHERTYPE_QINQ
#define ETH_P_PAE ETHERTYPE_PAE
#define ETH_P_802_2 ETHERTYPE_8023
+#define ETH_P_IPX ETHERTYPE_IPX
+#define ETH_P_AARP ETHERTYPE_AARP
+#define ETH_P_802_3_MIN 0x05DD /* See comment in sys/net/ethernet.h */
#define ETH_P_LINK_CTL 0x886C /* ITU-T G.989.2 */
#define ETH_P_TDLS 0x890D /* 802.11z-2010, see wpa. */
@@ -64,4 +70,13 @@ struct ethhdr {
uint16_t h_proto;
} __packed;
-#endif /* _LINUX_IF_ETHER_H_ */
+static inline struct ethhdr *
+eth_hdr(const struct sk_buff *skb)
+{
+ struct ethhdr *hdr;
+
+ hdr = (struct ethhdr *)skb_mac_header(skb);
+ return (hdr);
+}
+
+#endif /* _LINUXKPI_LINUX_IF_ETHER_H_ */
diff --git a/sys/compat/linuxkpi/common/include/linux/if_vlan.h b/sys/compat/linuxkpi/common/include/linux/if_vlan.h
index 4d8b8926a032..3d1c61db1882 100644
--- a/sys/compat/linuxkpi/common/include/linux/if_vlan.h
+++ b/sys/compat/linuxkpi/common/include/linux/if_vlan.h
@@ -25,11 +25,9 @@
* 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.
- *
- * $FreeBSD$
*/
-#ifndef _LINUX_IF_VLAN_H_
-#define _LINUX_IF_VLAN_H_
+#ifndef _LINUXKPI_LINUX_IF_VLAN_H_
+#define _LINUXKPI_LINUX_IF_VLAN_H_
#include <sys/types.h>
#include <sys/socket.h>
@@ -44,7 +42,7 @@
static inline int
is_vlan_dev(struct ifnet *ifp)
{
- return (ifp->if_type == IFT_L2VLAN);
+ return (if_gettype(ifp) == IFT_L2VLAN);
}
static inline uint16_t
@@ -56,4 +54,4 @@ vlan_dev_vlan_id(struct ifnet *ifp)
return (0);
}
-#endif /* _LINUX_IF_VLAN_H_ */
+#endif /* _LINUXKPI_LINUX_IF_VLAN_H_ */
diff --git a/sys/compat/linuxkpi/common/include/linux/in.h b/sys/compat/linuxkpi/common/include/linux/in.h
index 96d66fbae2f0..5cc92416c7da 100644
--- a/sys/compat/linuxkpi/common/include/linux/in.h
+++ b/sys/compat/linuxkpi/common/include/linux/in.h
@@ -25,15 +25,12 @@
* 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.
- *
- * $FreeBSD$
*/
-#ifndef _LINUX_IN_H_
-#define _LINUX_IN_H_
+#ifndef _LINUXKPI_LINUX_IN_H_
+#define _LINUXKPI_LINUX_IN_H_
#include "opt_inet.h"
-#include <sys/cdefs.h>
#include <sys/param.h>
#include <sys/systm.h>
#include <netinet/in.h>
@@ -44,4 +41,4 @@
#define ipv4_is_multicast(be) IN_MULTICAST(ntohl(be))
#define ipv4_is_lbcast(be) ((be) == INADDR_BROADCAST)
-#endif /* _LINUX_IN_H_ */
+#endif /* _LINUXKPI_LINUX_IN_H_ */
diff --git a/sys/compat/linuxkpi/common/include/linux/in6.h b/sys/compat/linuxkpi/common/include/linux/in6.h
index c72bfb6f0b88..79be45b6819a 100644
--- a/sys/compat/linuxkpi/common/include/linux/in6.h
+++ b/sys/compat/linuxkpi/common/include/linux/in6.h
@@ -25,12 +25,10 @@
* 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.
- *
- * $FreeBSD$
*/
-#ifndef _LINUX_IN6_H_
-#define _LINUX_IN6_H_
+#ifndef _LINUXKPI_LINUX_IN6_H_
+#define _LINUXKPI_LINUX_IN6_H_
#include "opt_inet6.h"
-#endif /* _LINUX_IN6_H_ */
+#endif /* _LINUXKPI_LINUX_IN6_H_ */
diff --git a/sys/compat/linuxkpi/common/include/linux/inetdevice.h b/sys/compat/linuxkpi/common/include/linux/inetdevice.h
index 41852e8fed81..ea256cd084a8 100644
--- a/sys/compat/linuxkpi/common/include/linux/inetdevice.h
+++ b/sys/compat/linuxkpi/common/include/linux/inetdevice.h
@@ -1,6 +1,6 @@
-#ifndef _LINUX_INETDEVICE_H_
-#define _LINUX_INETDEVICE_H_
+#ifndef _LINUXKPI_LINUX_INETDEVICE_H_
+#define _LINUXKPI_LINUX_INETDEVICE_H_
#include <linux/netdevice.h>
-#endif /* _LINUX_INETDEVICE_H_ */
+#endif /* _LINUXKPI_LINUX_INETDEVICE_H_ */
diff --git a/sys/compat/linuxkpi/common/include/linux/interrupt.h b/sys/compat/linuxkpi/common/include/linux/interrupt.h
index 964b95edb43f..dfd9816da8be 100644
--- a/sys/compat/linuxkpi/common/include/linux/interrupt.h
+++ b/sys/compat/linuxkpi/common/include/linux/interrupt.h
@@ -25,11 +25,9 @@
* 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.
- *
- * $FreeBSD$
*/
-#ifndef _LINUX_INTERRUPT_H_
-#define _LINUX_INTERRUPT_H_
+#ifndef _LINUXKPI_LINUX_INTERRUPT_H_
+#define _LINUXKPI_LINUX_INTERRUPT_H_
#include <linux/cpu.h>
#include <linux/device.h>
@@ -42,7 +40,12 @@
typedef irqreturn_t (*irq_handler_t)(int, void *);
-#define IRQF_SHARED RF_SHAREABLE
+#define IRQF_SHARED 0x0004 /* Historically */
+#define IRQF_NOBALANCING 0
+
+#define IRQ_DISABLE_UNLAZY 0
+
+#define IRQ_NOTCONNECTED (1U << 31)
int lkpi_request_irq(struct device *, unsigned int, irq_handler_t,
irq_handler_t, unsigned long, const char *, void *);
@@ -71,6 +74,14 @@ request_threaded_irq(int irq, irq_handler_t handler,
}
static inline int
+devm_request_irq(struct device *dev, int irq,
+ irq_handler_t handler, unsigned long flags, const char *name, void *arg)
+{
+
+ return (lkpi_request_irq(dev, irq, handler, NULL, flags, name, arg));
+}
+
+static inline int
devm_request_threaded_irq(struct device *dev, int irq,
irq_handler_t handler, irq_handler_t thread_handler,
unsigned long flags, const char *name, void *arg)
@@ -92,6 +103,12 @@ disable_irq(unsigned int irq)
lkpi_disable_irq(irq);
}
+static inline void
+disable_irq_nosync(unsigned int irq)
+{
+ lkpi_disable_irq(irq);
+}
+
static inline int
bind_irq_to_cpu(unsigned int irq, int cpu_id)
{
@@ -111,7 +128,7 @@ devm_free_irq(struct device *xdev, unsigned int irq, void *p)
}
static inline int
-irq_set_affinity_hint(int vector, cpumask_t *mask)
+irq_set_affinity_hint(int vector, const cpumask_t *mask)
{
int error;
@@ -123,10 +140,24 @@ irq_set_affinity_hint(int vector, cpumask_t *mask)
return (-error);
}
+static inline struct msi_desc *
+irq_get_msi_desc(unsigned int irq)
+{
+
+ return (lkpi_pci_msi_desc_alloc(irq));
+}
+
+static inline void
+irq_set_status_flags(unsigned int irq __unused, unsigned long flags __unused)
+{
+}
+
/*
* LinuxKPI tasklet support
*/
+struct tasklet_struct;
typedef void tasklet_func_t(unsigned long);
+typedef void tasklet_callback_t(struct tasklet_struct *);
struct tasklet_struct {
TAILQ_ENTRY(tasklet_struct) entry;
@@ -135,6 +166,8 @@ struct tasklet_struct {
volatile u_int tasklet_state;
atomic_t count;
unsigned long data;
+ tasklet_callback_t *callback;
+ bool use_callback;
};
#define DECLARE_TASKLET(_name, _func, _data) \
@@ -142,6 +175,11 @@ struct tasklet_struct _name = { .func = (_func), .data = (_data) }
#define tasklet_hi_schedule(t) tasklet_schedule(t)
+/* Some other compat code in the tree has this defined as well. */
+#define from_tasklet(_dev, _t, _field) \
+ container_of(_t, typeof(*(_dev)), _field)
+
+void tasklet_setup(struct tasklet_struct *, tasklet_callback_t *);
extern void tasklet_schedule(struct tasklet_struct *);
extern void tasklet_kill(struct tasklet_struct *);
extern void tasklet_init(struct tasklet_struct *, tasklet_func_t *,
@@ -152,5 +190,6 @@ extern void tasklet_disable_nosync(struct tasklet_struct *);
extern int tasklet_trylock(struct tasklet_struct *);
extern void tasklet_unlock(struct tasklet_struct *);
extern void tasklet_unlock_wait(struct tasklet_struct *ts);
+#define tasklet_unlock_spin_wait(ts) tasklet_unlock_wait(ts)
-#endif /* _LINUX_INTERRUPT_H_ */
+#endif /* _LINUXKPI_LINUX_INTERRUPT_H_ */
diff --git a/sys/compat/linuxkpi/common/include/linux/interval_tree.h b/sys/compat/linuxkpi/common/include/linux/interval_tree.h
new file mode 100644
index 000000000000..1eb8a2fb9181
--- /dev/null
+++ b/sys/compat/linuxkpi/common/include/linux/interval_tree.h
@@ -0,0 +1,55 @@
+/*-
+ * SPDX-License-Identifier: BSD-2-Clause
+ *
+ * Copyright (c) 2021 Vladimir Kondratyev <wulf@FreeBSD.org>
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice unmodified, this list of conditions, and the following
+ * disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``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.
+ */
+
+#ifndef _LINUXKPI_LINUX_INTERVAL_TREE_H
+#define _LINUXKPI_LINUX_INTERVAL_TREE_H
+
+#include <linux/rbtree.h>
+
+struct interval_tree_node {
+ struct rb_node rb;
+ unsigned long start;
+ unsigned long last;
+};
+
+#define interval_tree_iter_first(...) \
+ lkpi_interval_tree_iter_first(__VA_ARGS__)
+#define interval_tree_iter_next(...) \
+ lkpi_interval_tree_iter_next(__VA_ARGS__)
+#define interval_tree_insert(...) lkpi_interval_tree_insert(__VA_ARGS__)
+#define interval_tree_remove(...) lkpi_interval_tree_remove(__VA_ARGS__)
+
+struct interval_tree_node *lkpi_interval_tree_iter_first(
+ struct rb_root_cached *, unsigned long, unsigned long);
+struct interval_tree_node *lkpi_interval_tree_iter_next(
+ struct interval_tree_node *, unsigned long, unsigned long);
+void lkpi_interval_tree_insert(struct interval_tree_node *,
+ struct rb_root_cached *);
+void lkpi_interval_tree_remove(struct interval_tree_node *,
+ struct rb_root_cached *);
+
+#endif /* _LINUXKPI_LINUX_INTERVAL_TREE_H */
diff --git a/sys/compat/linuxkpi/common/include/linux/interval_tree_generic.h b/sys/compat/linuxkpi/common/include/linux/interval_tree_generic.h
new file mode 100644
index 000000000000..3ed6e105cbda
--- /dev/null
+++ b/sys/compat/linuxkpi/common/include/linux/interval_tree_generic.h
@@ -0,0 +1,99 @@
+/*-
+ * SPDX-License-Identifier: BSD-2-Clause
+ *
+ * Copyright (c) 2019 Mark Kettenis <kettenis@OpenBSD.org>
+ * Copyright (c) 2021 Vladimir Kondratyev <wulf@FreeBSD.org>
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice unmodified, this list of conditions, and the following
+ * disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``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.
+ */
+
+#include <linux/rbtree.h>
+
+#define INTERVAL_TREE_DEFINE(type, field, valtype, dummy, START, LAST, \
+ attr, name) \
+ __IT_DEFINE_ITER_FROM(type, field, valtype, START, LAST, name) \
+ __IT_DEFINE_ITER_FIRST(type, valtype, attr, name) \
+ __IT_DEFINE_ITER_NEXT(type, field, valtype, attr, name) \
+ __IT_DEFINE_INSERT(type, field, START, attr, name) \
+ __IT_DEFINE_REMOVE(type, field, attr, name)
+
+#define __IT_DEFINE_ITER_FROM(type, field, valtype, START, LAST, name) \
+static inline type * \
+name##_iter_from(struct rb_node *rb, valtype start, valtype last) \
+{ \
+ type *node; \
+ \
+ while (rb != NULL) { \
+ node = rb_entry(rb, type, field); \
+ if (LAST(node) >= start && START(node) <= last) \
+ return (node); \
+ else if (START(node) > last) \
+ break; \
+ rb = rb_next(rb); \
+ } \
+ return (NULL); \
+}
+
+#define __IT_DEFINE_ITER_FIRST(type, valtype, attr, name) \
+attr type * \
+name##_iter_first(struct rb_root_cached *root, valtype start, valtype last) \
+{ \
+ return (name##_iter_from(rb_first_cached(root), start, last)); \
+}
+
+#define __IT_DEFINE_ITER_NEXT(type, field, valtype, attr, name) \
+attr type * \
+name##_iter_next(type *node, valtype start, valtype last) \
+{ \
+ return (name##_iter_from(rb_next(&node->field), start, last)); \
+}
+
+#define __IT_DEFINE_INSERT(type, field, START, attr, name) \
+attr void \
+name##_insert(type *node, struct rb_root_cached *root) \
+{ \
+ struct rb_node **iter = &root->rb_root.rb_node; \
+ struct rb_node *parent = NULL; \
+ type *iter_node; \
+ bool min_entry = true; \
+ \
+ while (*iter != NULL) { \
+ parent = *iter; \
+ iter_node = rb_entry(parent, type, field); \
+ if (START(node) < START(iter_node)) \
+ iter = &parent->rb_left; \
+ else { \
+ iter = &parent->rb_right; \
+ min_entry = false; \
+ } \
+ } \
+ \
+ rb_link_node(&node->field, parent, iter); \
+ rb_insert_color_cached(&node->field, root, min_entry); \
+}
+
+#define __IT_DEFINE_REMOVE(type, field, attr, name) \
+attr void \
+name##_remove(type *node, struct rb_root_cached *root) \
+{ \
+ rb_erase_cached(&node->field, root); \
+}
diff --git a/sys/compat/linuxkpi/common/include/linux/io-64-nonatomic-lo-hi.h b/sys/compat/linuxkpi/common/include/linux/io-64-nonatomic-lo-hi.h
new file mode 100644
index 000000000000..844b3ef171d5
--- /dev/null
+++ b/sys/compat/linuxkpi/common/include/linux/io-64-nonatomic-lo-hi.h
@@ -0,0 +1,65 @@
+/*-
+ * SPDX-License-Identifier: BSD-2-Clause
+ *
+ * Copyright (c) 2022 Felix Palmen
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``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 OR CONTRIBUTORS 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.
+ */
+#ifndef _LINUXKPI_LINUX_IO_64_NONATOMIC_LO_HI_H_
+#define _LINUXKPI_LINUX_IO_64_NONATOMIC_LO_HI_H_
+
+#include <linux/io.h>
+
+static inline uint64_t
+lo_hi_readq(const volatile void *addr)
+{
+ const volatile uint32_t *p = addr;
+ uint32_t l, h;
+
+ __io_br();
+ l = le32toh(__raw_readl(p));
+ h = le32toh(__raw_readl(p + 1));
+ __io_ar();
+
+ return (l + ((uint64_t)h << 32));
+}
+
+static inline void
+lo_hi_writeq(uint64_t v, volatile void *addr)
+{
+ volatile uint32_t *p = addr;
+
+ __io_bw();
+ __raw_writel(htole32(v), p);
+ __raw_writel(htole32(v >> 32), p + 1);
+ __io_aw();
+}
+
+#ifndef readq
+#define readq(addr) lo_hi_readq(addr)
+#endif
+
+#ifndef writeq
+#define writeq(v, addr) lo_hi_writeq(v, addr)
+#endif
+
+#endif /* _LINUXKPI_LINUX_IO_64_NONATOMIC_LO_HI_H_ */
diff --git a/sys/compat/linuxkpi/common/include/linux/io-mapping.h b/sys/compat/linuxkpi/common/include/linux/io-mapping.h
index 12643be9c6e6..f5f2fbc5c2cb 100644
--- a/sys/compat/linuxkpi/common/include/linux/io-mapping.h
+++ b/sys/compat/linuxkpi/common/include/linux/io-mapping.h
@@ -25,18 +25,17 @@
* 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.
- *
- * $FreeBSD$
*/
-#ifndef _LINUX_IO_MAPPING_H_
-#define _LINUX_IO_MAPPING_H_
+#ifndef _LINUXKPI_LINUX_IO_MAPPING_H_
+#define _LINUXKPI_LINUX_IO_MAPPING_H_
#include <sys/types.h>
#include <machine/vm.h>
#include <linux/types.h>
#include <linux/io.h>
+#include <linux/mm.h>
#include <linux/slab.h>
struct io_mapping {
@@ -46,6 +45,8 @@ struct io_mapping {
vm_memattr_t attr;
};
+struct io_mapping *io_mapping_create_wc(resource_size_t base, unsigned long size);
+
static inline struct io_mapping *
io_mapping_init_wc(struct io_mapping *mapping, resource_size_t base,
unsigned long size)
@@ -63,17 +64,6 @@ io_mapping_init_wc(struct io_mapping *mapping, resource_size_t base,
return (mapping);
}
-static inline struct io_mapping *
-io_mapping_create_wc(resource_size_t base, unsigned long size)
-{
- struct io_mapping *mapping;
-
- mapping = kmalloc(sizeof(*mapping), GFP_KERNEL);
- if (mapping == NULL)
- return (NULL);
- return (io_mapping_init_wc(mapping, base, size));
-}
-
static inline void
io_mapping_fini(struct io_mapping *mapping)
{
@@ -102,6 +92,18 @@ io_mapping_unmap_atomic(void *vaddr)
}
static inline void *
+io_mapping_map_local_wc(struct io_mapping *mapping, unsigned long offset)
+{
+
+ return (io_mapping_map_atomic_wc(mapping, offset));
+}
+
+static inline void
+io_mapping_unmap_local(void *vaddr __unused)
+{
+}
+
+static inline void *
io_mapping_map_wc(struct io_mapping *mapping, unsigned long offset,
unsigned long size)
{
@@ -109,9 +111,20 @@ io_mapping_map_wc(struct io_mapping *mapping, unsigned long offset,
return ((char *)mapping->mem + offset);
}
+int lkpi_io_mapping_map_user(struct io_mapping *iomap,
+ struct vm_area_struct *vma, unsigned long addr, unsigned long pfn,
+ unsigned long size);
+
+static inline int
+io_mapping_map_user(struct io_mapping *iomap, struct vm_area_struct *vma,
+ unsigned long addr, unsigned long pfn, unsigned long size)
+{
+ return (lkpi_io_mapping_map_user(iomap, vma, addr, pfn, size));
+}
+
static inline void
io_mapping_unmap(void *vaddr)
{
}
-#endif /* _LINUX_IO_MAPPING_H_ */
+#endif /* _LINUXKPI_LINUX_IO_MAPPING_H_ */
diff --git a/sys/compat/linuxkpi/common/include/linux/io.h b/sys/compat/linuxkpi/common/include/linux/io.h
index e402ebed0665..2d6fef4e7c52 100644
--- a/sys/compat/linuxkpi/common/include/linux/io.h
+++ b/sys/compat/linuxkpi/common/include/linux/io.h
@@ -25,11 +25,9 @@
* 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.
- *
- * $FreeBSD$
*/
-#ifndef _LINUX_IO_H_
-#define _LINUX_IO_H_
+#ifndef _LINUXKPI_LINUX_IO_H_
+#define _LINUXKPI_LINUX_IO_H_
#include <sys/endian.h>
#include <sys/types.h>
@@ -37,7 +35,12 @@
#include <machine/vm.h>
#include <linux/compiler.h>
+#include <linux/err.h>
+#include <asm-generic/io.h>
#include <linux/types.h>
+#if !defined(__arm__)
+#include <asm/set_memory.h>
+#endif
/*
* XXX This is all x86 specific. It should be bus space access.
@@ -348,6 +351,16 @@ ioread32be(const volatile void *addr)
}
#define ioread32be(addr) ioread32be(addr)
+#ifdef __LP64__
+#undef ioread64
+static inline uint64_t
+ioread64(const volatile void *addr)
+{
+ return (readq(addr));
+}
+#define ioread64(addr) ioread64(addr)
+#endif
+
#undef iowrite8
static inline void
iowrite8(uint8_t v, volatile void *addr)
@@ -383,19 +396,26 @@ iowrite32be(uint32_t v, volatile void *addr)
#define iowrite32be(v, addr) iowrite32be(v, addr)
#if defined(__i386__) || defined(__amd64__)
-static inline void
-_outb(u_char data, u_int port)
-{
- __asm __volatile("outb %0, %w1" : : "a" (data), "Nd" (port));
-}
+#define _outb(data, port) outb((data), (port))
#endif
#if defined(__i386__) || defined(__amd64__) || defined(__powerpc__) || defined(__aarch64__) || defined(__riscv)
void *_ioremap_attr(vm_paddr_t phys_addr, unsigned long size, int attr);
#else
-#define _ioremap_attr(...) NULL
+static __inline void *
+_ioremap_attr(vm_paddr_t _phys_addr, unsigned long _size, int _attr)
+{
+ return (NULL);
+}
#endif
+struct device;
+static inline void *
+devm_ioremap(struct device *dev, resource_size_t offset, resource_size_t size)
+{
+ return (NULL);
+}
+
#ifdef VM_MEMATTR_DEVICE
#define ioremap_nocache(addr, size) \
_ioremap_attr((addr), (size), VM_MEMATTR_DEVICE)
@@ -417,7 +437,7 @@ void *_ioremap_attr(vm_paddr_t phys_addr, unsigned long size, int attr);
#else
#define ioremap_wc(addr, size) ioremap_nocache(addr, size)
#endif
-#define ioremap_wb(addr, size) \
+#define ioremap_cache(addr, size) \
_ioremap_attr((addr), (size), VM_MEMATTR_WRITE_BACK)
void iounmap(void *addr);
@@ -426,9 +446,9 @@ void iounmap(void *addr);
#define memcpy_toio(a, b, c) memcpy((a), (b), (c))
static inline void
-__iowrite32_copy(void *to, void *from, size_t count)
+__iowrite32_copy(void *to, const void *from, size_t count)
{
- uint32_t *src;
+ const uint32_t *src;
uint32_t *dst;
int i;
@@ -437,10 +457,10 @@ __iowrite32_copy(void *to, void *from, size_t count)
}
static inline void
-__iowrite64_copy(void *to, void *from, size_t count)
+__iowrite64_copy(void *to, const void *from, size_t count)
{
#ifdef __LP64__
- uint64_t *src;
+ const uint64_t *src;
uint64_t *dst;
int i;
@@ -451,6 +471,32 @@ __iowrite64_copy(void *to, void *from, size_t count)
#endif
}
+static inline void
+__ioread32_copy(void *to, const void *from, size_t count)
+{
+ const uint32_t *src;
+ uint32_t *dst;
+ int i;
+
+ for (i = 0, src = from, dst = to; i < count; i++, src++, dst++)
+ *dst = __raw_readl(src);
+}
+
+static inline void
+__ioread64_copy(void *to, const void *from, size_t count)
+{
+#ifdef __LP64__
+ const uint64_t *src;
+ uint64_t *dst;
+ int i;
+
+ for (i = 0, src = from, dst = to; i < count; i++, src++, dst++)
+ *dst = __raw_readq(src);
+#else
+ __ioread32_copy(to, from, count * 2);
+#endif
+}
+
enum {
MEMREMAP_WB = 1 << 0,
MEMREMAP_WT = 1 << 1,
@@ -463,7 +509,7 @@ memremap(resource_size_t offset, size_t size, unsigned long flags)
void *addr = NULL;
if ((flags & MEMREMAP_WB) &&
- (addr = ioremap_wb(offset, size)) != NULL)
+ (addr = ioremap_cache(offset, size)) != NULL)
goto done;
if ((flags & MEMREMAP_WT) &&
(addr = ioremap_wt(offset, size)) != NULL)
@@ -482,4 +528,39 @@ memunmap(void *addr)
iounmap(addr);
}
-#endif /* _LINUX_IO_H_ */
+#define IOMEM_ERR_PTR(err) (void __iomem *)ERR_PTR(err)
+
+#define __MTRR_ID_BASE 1
+int lkpi_arch_phys_wc_add(unsigned long, unsigned long);
+void lkpi_arch_phys_wc_del(int);
+#define arch_phys_wc_add(...) lkpi_arch_phys_wc_add(__VA_ARGS__)
+#define arch_phys_wc_del(...) lkpi_arch_phys_wc_del(__VA_ARGS__)
+#define arch_phys_wc_index(x) \
+ (((x) < __MTRR_ID_BASE) ? -1 : ((x) - __MTRR_ID_BASE))
+
+static inline int
+arch_io_reserve_memtype_wc(resource_size_t start, resource_size_t size)
+{
+#if defined(__amd64__)
+ vm_offset_t va;
+
+ va = PHYS_TO_DMAP(start);
+ return (-pmap_change_attr(va, size, VM_MEMATTR_WRITE_COMBINING));
+#else
+ return (0);
+#endif
+}
+
+static inline void
+arch_io_free_memtype_wc(resource_size_t start, resource_size_t size)
+{
+#if defined(__amd64__)
+ vm_offset_t va;
+
+ va = PHYS_TO_DMAP(start);
+
+ pmap_change_attr(va, size, VM_MEMATTR_WRITE_BACK);
+#endif
+}
+
+#endif /* _LINUXKPI_LINUX_IO_H_ */
diff --git a/sys/compat/linuxkpi/common/include/linux/ioctl.h b/sys/compat/linuxkpi/common/include/linux/ioctl.h
index fcdb5c547e73..77c01224e6a5 100644
--- a/sys/compat/linuxkpi/common/include/linux/ioctl.h
+++ b/sys/compat/linuxkpi/common/include/linux/ioctl.h
@@ -25,11 +25,9 @@
* 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.
- *
- * $FreeBSD$
*/
-#ifndef _LINUX_IOCTL_H_
-#define _LINUX_IOCTL_H_
+#ifndef _LINUXKPI_LINUX_IOCTL_H_
+#define _LINUXKPI_LINUX_IOCTL_H_
#include <sys/ioccom.h>
@@ -37,4 +35,4 @@
#define _IOC_TYPE(cmd) IOCGROUP(cmd)
#define _IOC_NR(cmd) ((cmd) & 0xff)
-#endif /* _LINUX_IOCTL_H_ */
+#endif /* _LINUXKPI_LINUX_IOCTL_H_ */
diff --git a/sys/compat/linuxkpi/common/include/linux/iommu.h b/sys/compat/linuxkpi/common/include/linux/iommu.h
new file mode 100644
index 000000000000..391d9778a0c8
--- /dev/null
+++ b/sys/compat/linuxkpi/common/include/linux/iommu.h
@@ -0,0 +1,29 @@
+/* Public domain. */
+
+#ifndef _LINUXKPI_LINUX_IOMMU_H_
+#define _LINUXKPI_LINUX_IOMMU_H_
+
+#include <linux/device.h>
+
+#define __IOMMU_DOMAIN_PAGING (1U << 0)
+#define __IOMMU_DOMAIN_DMA_API (1U << 1)
+#define __IOMMU_DOMAIN_PT (1U << 2)
+#define __IOMMU_DOMAIN_DMA_FQ (1U << 3)
+
+#define IOMMU_DOMAIN_BLOCKED (0U)
+#define IOMMU_DOMAIN_IDENTITY (__IOMMU_DOMAIN_PT)
+#define IOMMU_DOMAIN_UNMANAGED (__IOMMU_DOMAIN_PAGING)
+#define IOMMU_DOMAIN_DMA (__IOMMU_DOMAIN_PAGING | __IOMMU_DOMAIN_DMA_API)
+#define IOMMU_DOMAIN_DMA_FQ (__IOMMU_DOMAIN_PAGING | __IOMMU_DOMAIN_DMA_API | __IOMMU_DOMAIN_DMA_FQ)
+
+struct iommu_domain {
+ unsigned int type;
+};
+
+static inline struct iommu_domain *
+iommu_get_domain_for_dev(struct device *dev __unused)
+{
+ return (NULL);
+}
+
+#endif /* _LINUXKPI_LINUX_IOMMU_H_ */
diff --git a/sys/compat/linuxkpi/common/include/linux/iopoll.h b/sys/compat/linuxkpi/common/include/linux/iopoll.h
index ea876042eab6..8d0498a26da1 100644
--- a/sys/compat/linuxkpi/common/include/linux/iopoll.h
+++ b/sys/compat/linuxkpi/common/include/linux/iopoll.h
@@ -23,12 +23,10 @@
* 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.
- *
- * $FreeBSD$
*/
-#ifndef __LINUXKPI_LINUX_IOPOLL_H
-#define __LINUXKPI_LINUX_IOPOLL_H
+#ifndef _LINUXKPI_LINUX_IOPOLL_H
+#define _LINUXKPI_LINUX_IOPOLL_H
#include <sys/types.h>
#include <sys/time.h>
@@ -61,6 +59,9 @@
(_cond) ? 0 : (-ETIMEDOUT); \
})
+#define readx_poll_timeout(_pollfp, _addr, _var, _cond, _us, _to) \
+ read_poll_timeout(_pollfp, _var, _cond, _us, _to, false, _addr)
+
#define read_poll_timeout_atomic(_pollfp, _var, _cond, _us, _to, _early_sleep, ...) \
({ \
struct timeval __now, __end; \
@@ -88,4 +89,4 @@
(_cond) ? 0 : (-ETIMEDOUT); \
})
-#endif /* __LINUXKPI_LINUX_IOPOLL_H */
+#endif /* _LINUXKPI_LINUX_IOPOLL_H */
diff --git a/sys/compat/linuxkpi/common/include/linux/ioport.h b/sys/compat/linuxkpi/common/include/linux/ioport.h
new file mode 100644
index 000000000000..763af2de7c4f
--- /dev/null
+++ b/sys/compat/linuxkpi/common/include/linux/ioport.h
@@ -0,0 +1,58 @@
+/*-
+ * SPDX-License-Identifier: BSD-2-Clause
+ *
+ * Copyright (c) 2023 Serenity Cyber Security, LLC.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``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 OR CONTRIBUTORS 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.
+ */
+
+#ifndef _LINUXKPI_LINUX_IOPORT_H
+#define _LINUXKPI_LINUX_IOPORT_H
+
+#include <linux/compiler.h>
+#include <linux/types.h>
+
+#define DEFINE_RES_MEM(_start, _size) \
+ (struct resource) { \
+ .start = (_start), \
+ .end = (_start) + (_size) - 1, \
+ }
+
+struct resource {
+ resource_size_t start;
+ resource_size_t end;
+ const char *name;
+};
+
+static inline resource_size_t
+resource_size(const struct resource *r)
+{
+ return (r->end - r->start + 1);
+}
+
+static inline bool
+resource_contains(struct resource *a, struct resource *b)
+{
+ return (a->start <= b->start && a->end >= b->end);
+}
+
+#endif
diff --git a/sys/compat/linuxkpi/common/include/linux/iosys-map.h b/sys/compat/linuxkpi/common/include/linux/iosys-map.h
new file mode 100644
index 000000000000..66c442b8668f
--- /dev/null
+++ b/sys/compat/linuxkpi/common/include/linux/iosys-map.h
@@ -0,0 +1,161 @@
+/* Public domain. */
+
+#ifndef _LINUXKPI_LINUX_IOSYS_MAP_H
+#define _LINUXKPI_LINUX_IOSYS_MAP_H
+
+#include <linux/io.h>
+#include <linux/string.h>
+
+struct iosys_map {
+ union {
+ void *vaddr_iomem;
+ void *vaddr;
+ };
+ bool is_iomem;
+#ifdef __OpenBSD__
+ bus_space_handle_t bsh;
+ bus_size_t size;
+#endif
+};
+
+#define IOSYS_MAP_INIT_OFFSET(_ism_src_p, _off) ({ \
+ struct iosys_map ism_dst = *(_ism_src_p); \
+ iosys_map_incr(&ism_dst, _off); \
+ ism_dst; \
+})
+
+static inline void
+iosys_map_incr(struct iosys_map *ism, size_t n)
+{
+ if (ism->is_iomem)
+ ism->vaddr_iomem += n;
+ else
+ ism->vaddr += n;
+}
+
+static inline void
+iosys_map_memcpy_to(struct iosys_map *ism, size_t off, const void *src,
+ size_t len)
+{
+ if (ism->is_iomem)
+ memcpy_toio(ism->vaddr_iomem + off, src, len);
+ else
+ memcpy(ism->vaddr + off, src, len);
+}
+
+static inline bool
+iosys_map_is_null(const struct iosys_map *ism)
+{
+ if (ism->is_iomem)
+ return (ism->vaddr_iomem == NULL);
+ else
+ return (ism->vaddr == NULL);
+}
+
+static inline bool
+iosys_map_is_set(const struct iosys_map *ism)
+{
+ if (ism->is_iomem)
+ return (ism->vaddr_iomem != NULL);
+ else
+ return (ism->vaddr != NULL);
+}
+
+static inline bool
+iosys_map_is_equal(const struct iosys_map *ism_a,
+ const struct iosys_map *ism_b)
+{
+ if (ism_a->is_iomem != ism_b->is_iomem)
+ return (false);
+
+ if (ism_a->is_iomem)
+ return (ism_a->vaddr_iomem == ism_b->vaddr_iomem);
+ else
+ return (ism_a->vaddr == ism_b->vaddr);
+}
+
+static inline void
+iosys_map_clear(struct iosys_map *ism)
+{
+ if (ism->is_iomem) {
+ ism->vaddr_iomem = NULL;
+ ism->is_iomem = false;
+ } else {
+ ism->vaddr = NULL;
+ }
+}
+
+static inline void
+iosys_map_set_vaddr_iomem(struct iosys_map *ism, void *addr)
+{
+ ism->vaddr_iomem = addr;
+ ism->is_iomem = true;
+}
+
+static inline void
+iosys_map_set_vaddr(struct iosys_map *ism, void *addr)
+{
+ ism->vaddr = addr;
+ ism->is_iomem = false;
+}
+
+static inline void
+iosys_map_memset(struct iosys_map *ism, size_t off, int value, size_t len)
+{
+ if (ism->is_iomem)
+ memset_io(ism->vaddr_iomem + off, value, len);
+ else
+ memset(ism->vaddr + off, value, len);
+}
+
+#ifdef __LP64__
+#define _iosys_map_readq(_addr) readq(_addr)
+#define _iosys_map_writeq(_val, _addr) writeq(_val, _addr)
+#else
+#define _iosys_map_readq(_addr) ({ \
+ uint64_t val; \
+ memcpy_fromio(&val, _addr, sizeof(uint64_t)); \
+ val; \
+})
+#define _iosys_map_writeq(_val, _addr) \
+ memcpy_toio(_addr, &(_val), sizeof(uint64_t))
+#endif
+
+#define iosys_map_rd(_ism, _off, _type) ({ \
+ _type val; \
+ if ((_ism)->is_iomem) { \
+ void *addr = (_ism)->vaddr_iomem + (_off); \
+ val = _Generic(val, \
+ uint8_t : readb(addr), \
+ uint16_t: readw(addr), \
+ uint32_t: readl(addr), \
+ uint64_t: _iosys_map_readq(addr)); \
+ } else \
+ val = READ_ONCE(*(_type *)((_ism)->vaddr + (_off))); \
+ val; \
+})
+#define iosys_map_wr(_ism, _off, _type, _val) ({ \
+ _type val = (_val); \
+ if ((_ism)->is_iomem) { \
+ void *addr = (_ism)->vaddr_iomem + (_off); \
+ _Generic(val, \
+ uint8_t : writeb(val, addr), \
+ uint16_t: writew(val, addr), \
+ uint32_t: writel(val, addr), \
+ uint64_t: _iosys_map_writeq(val, addr)); \
+ } else \
+ WRITE_ONCE(*(_type *)((_ism)->vaddr + (_off)), val); \
+})
+
+#define iosys_map_rd_field(_ism, _off, _type, _field) ({ \
+ _type *s; \
+ iosys_map_rd(_ism, (_off) + offsetof(_type, _field), \
+ __typeof(s->_field)); \
+})
+#define iosys_map_wr_field(_ism, _off, _type, _field, _val) ({ \
+ _type *s; \
+ iosys_map_wr(_ism, (_off) + offsetof(_type, _field), \
+ __typeof(s->_field), _val); \
+})
+
+#endif
diff --git a/sys/compat/linuxkpi/common/include/linux/ip.h b/sys/compat/linuxkpi/common/include/linux/ip.h
index 3507c6fe9b97..137cf89e7dcb 100644
--- a/sys/compat/linuxkpi/common/include/linux/ip.h
+++ b/sys/compat/linuxkpi/common/include/linux/ip.h
@@ -26,15 +26,14 @@
* 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.
- *
- * $FreeBSD$
*/
-#ifndef __LKPI_LINUX_IP_H
-#define __LKPI_LINUX_IP_H
+#ifndef _LINUXKPI_LINUX_IP_H
+#define _LINUXKPI_LINUX_IP_H
#include <sys/types.h>
+#include <netinet/in.h>
#include <netinet/ip.h>
#include <machine/in_cksum.h>
@@ -71,4 +70,4 @@ ip_send_check(struct iphdr *iph)
iph->check = in_cksum_hdr((const void *)iph);
}
-#endif /* __LKPI_LINUX_IP_H */
+#endif /* _LINUXKPI_LINUX_IP_H */
diff --git a/sys/compat/linuxkpi/common/include/linux/irq_work.h b/sys/compat/linuxkpi/common/include/linux/irq_work.h
index 1b376b829818..7c4019bc0242 100644
--- a/sys/compat/linuxkpi/common/include/linux/irq_work.h
+++ b/sys/compat/linuxkpi/common/include/linux/irq_work.h
@@ -24,21 +24,37 @@
* 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.
- *
- * $FreeBSD$
*/
-#ifndef __LINUX_IRQ_WORK_H__
-#define __LINUX_IRQ_WORK_H__
+#ifndef _LINUXKPI_LINUX_IRQ_WORK_H_
+#define _LINUXKPI_LINUX_IRQ_WORK_H_
#include <sys/param.h>
#include <sys/taskqueue.h>
+#include <linux/llist.h>
+#include <linux/workqueue.h>
+
+#define LKPI_IRQ_WORK_STD_TQ system_wq->taskqueue
+#define LKPI_IRQ_WORK_FAST_TQ linux_irq_work_tq
+
+#ifdef LKPI_IRQ_WORK_USE_FAST_TQ
+#define LKPI_IRQ_WORK_TQ LKPI_IRQ_WORK_FAST_TQ
+#else
+#define LKPI_IRQ_WORK_TQ LKPI_IRQ_WORK_STD_TQ
+#endif
+
struct irq_work;
typedef void (*irq_work_func_t)(struct irq_work *);
struct irq_work {
struct task irq_task;
+ union {
+ struct llist_node llnode;
+ struct {
+ struct llist_node llist;
+ } node;
+ };
irq_work_func_t func;
};
@@ -58,16 +74,17 @@ init_irq_work(struct irq_work *irqw, irq_work_func_t func)
irqw->func = func;
}
-static inline void
+static inline bool
irq_work_queue(struct irq_work *irqw)
{
- taskqueue_enqueue(linux_irq_work_tq, &irqw->irq_task);
+ return (taskqueue_enqueue_flags(LKPI_IRQ_WORK_TQ, &irqw->irq_task,
+ TASKQUEUE_FAIL_IF_PENDING) == 0);
}
static inline void
irq_work_sync(struct irq_work *irqw)
{
- taskqueue_drain(linux_irq_work_tq, &irqw->irq_task);
+ taskqueue_drain(LKPI_IRQ_WORK_TQ, &irqw->irq_task);
}
-#endif /* __LINUX_IRQ_WORK_H__ */
+#endif /* _LINUXKPI_LINUX_IRQ_WORK_H_ */
diff --git a/sys/compat/linuxkpi/common/include/linux/irqdomain.h b/sys/compat/linuxkpi/common/include/linux/irqdomain.h
new file mode 100644
index 000000000000..c7788e51cc89
--- /dev/null
+++ b/sys/compat/linuxkpi/common/include/linux/irqdomain.h
@@ -0,0 +1,10 @@
+/* Public domain. */
+
+#ifndef _LINUXKPI_LINUX_IRQDOMAIN_H
+#define _LINUXKPI_LINUX_IRQDOMAIN_H
+
+#include <linux/mutex.h>
+#include <linux/of.h>
+#include <linux/radix-tree.h>
+
+#endif
diff --git a/sys/compat/linuxkpi/common/include/linux/irqreturn.h b/sys/compat/linuxkpi/common/include/linux/irqreturn.h
index 780fccad017c..ff2618449d5e 100644
--- a/sys/compat/linuxkpi/common/include/linux/irqreturn.h
+++ b/sys/compat/linuxkpi/common/include/linux/irqreturn.h
@@ -22,12 +22,10 @@
* 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.
- *
- * $FreeBSD$
*/
-#ifndef _LINUX_IRQRETURN_H
-#define _LINUX_IRQRETURN_H
+#ifndef _LINUXKPI_LINUX_IRQRETURN_H
+#define _LINUXKPI_LINUX_IRQRETURN_H
typedef enum irqreturn {
IRQ_NONE = 0,
@@ -37,4 +35,4 @@ typedef enum irqreturn {
#define IRQ_RETVAL(x) ((x) ? IRQ_HANDLED : IRQ_NONE)
-#endif /* _LINUX_IRQRETURN_H */
+#endif /* _LINUXKPI_LINUX_IRQRETURN_H */
diff --git a/sys/compat/linuxkpi/common/include/linux/jhash.h b/sys/compat/linuxkpi/common/include/linux/jhash.h
index 08300083212f..25e2c04f1965 100644
--- a/sys/compat/linuxkpi/common/include/linux/jhash.h
+++ b/sys/compat/linuxkpi/common/include/linux/jhash.h
@@ -1,5 +1,5 @@
-#ifndef _LINUX_JHASH_H_
-#define _LINUX_JHASH_H_
+#ifndef _LINUXKPI_LINUX_JHASH_H_
+#define _LINUXKPI_LINUX_JHASH_H_
#include <asm/types.h>
@@ -20,8 +20,6 @@
*
* I've modified Bob's hash to be useful in the Linux kernel, and
* any bugs present are surely my fault. -DaveM
- *
- * $FreeBSD$
*/
/* NOTE: Arguments are modified. */
@@ -143,4 +141,4 @@ static inline u32 jhash_1word(u32 a, u32 initval)
return jhash_3words(a, 0, 0, initval);
}
-#endif /* _LINUX_JHASH_H_ */
+#endif /* _LINUXKPI_LINUX_JHASH_H_ */
diff --git a/sys/compat/linuxkpi/common/include/linux/jiffies.h b/sys/compat/linuxkpi/common/include/linux/jiffies.h
index 7d547e6d66cd..c2409726e874 100644
--- a/sys/compat/linuxkpi/common/include/linux/jiffies.h
+++ b/sys/compat/linuxkpi/common/include/linux/jiffies.h
@@ -25,35 +25,34 @@
* 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.
- *
- * $FreeBSD$
*/
-#ifndef _LINUX_JIFFIES_H_
-#define _LINUX_JIFFIES_H_
+#ifndef _LINUXKPI_LINUX_JIFFIES_H_
+#define _LINUXKPI_LINUX_JIFFIES_H_
#include <linux/types.h>
#include <linux/time.h>
-#include <sys/time.h>
#include <sys/kernel.h>
#include <sys/limits.h>
+#include <sys/time.h>
-#define jiffies ticks
-#define jiffies_64 ticks
-#define jiffies_to_msecs(x) (((int64_t)(int)(x)) * 1000 / hz)
+extern unsigned long jiffies; /* defined in sys/kern/subr_ticks.S */
+#define jiffies_64 jiffies /* XXX-MJ wrong on 32-bit platforms */
+#define jiffies_to_msecs(x) ((unsigned int)(((int64_t)(int)(x)) * 1000 / hz))
-#define MAX_JIFFY_OFFSET ((INT_MAX >> 1) - 1)
+#define MAX_JIFFY_OFFSET ((LONG_MAX >> 1) - 1)
-#define time_after(a, b) ((int)((b) - (a)) < 0)
+#define time_after(a, b) ((long)((b) - (a)) < 0)
#define time_after32(a, b) ((int32_t)((uint32_t)(b) - (uint32_t)(a)) < 0)
#define time_before(a, b) time_after(b,a)
#define time_before32(a, b) time_after32(b, a)
-#define time_after_eq(a, b) ((int)((a) - (b)) >= 0)
+#define time_after_eq(a, b) ((long)((a) - (b)) >= 0)
#define time_before_eq(a, b) time_after_eq(b, a)
#define time_in_range(a,b,c) \
(time_after_eq(a,b) && time_before_eq(a,c))
#define time_is_after_eq_jiffies(a) time_after_eq(a, jiffies)
#define time_is_after_jiffies(a) time_after(a, jiffies)
+#define time_is_before_jiffies(a) time_before(a, jiffies)
#define HZ hz
@@ -69,20 +68,7 @@ extern uint64_t lkpi_msec2hz_rem;
extern uint64_t lkpi_msec2hz_div;
extern uint64_t lkpi_msec2hz_max;
-static inline int
-timespec_to_jiffies(const struct timespec *ts)
-{
- u64 result;
-
- result = ((u64)hz * ts->tv_sec) +
- (((u64)hz * ts->tv_nsec + NSEC_PER_SEC - 1) / NSEC_PER_SEC);
- if (result > MAX_JIFFY_OFFSET)
- result = MAX_JIFFY_OFFSET;
-
- return ((int)result);
-}
-
-static inline int
+static inline unsigned long
msecs_to_jiffies(uint64_t msec)
{
uint64_t result;
@@ -93,10 +79,10 @@ msecs_to_jiffies(uint64_t msec)
if (result > MAX_JIFFY_OFFSET)
result = MAX_JIFFY_OFFSET;
- return ((int)result);
+ return ((unsigned long)result);
}
-static inline int
+static inline unsigned long
usecs_to_jiffies(uint64_t usec)
{
uint64_t result;
@@ -107,7 +93,7 @@ usecs_to_jiffies(uint64_t usec)
if (result > MAX_JIFFY_OFFSET)
result = MAX_JIFFY_OFFSET;
- return ((int)result);
+ return ((unsigned long)result);
}
static inline uint64_t
@@ -134,34 +120,24 @@ nsecs_to_jiffies(uint64_t nsec)
}
static inline uint64_t
-jiffies_to_nsecs(int j)
+jiffies_to_nsecs(unsigned long j)
{
- return ((1000000000ULL / hz) * (uint64_t)(unsigned int)j);
+ return ((1000000000ULL / hz) * (uint64_t)j);
}
static inline uint64_t
-jiffies_to_usecs(int j)
+jiffies_to_usecs(unsigned long j)
{
- return ((1000000ULL / hz) * (uint64_t)(unsigned int)j);
+ return ((1000000ULL / hz) * (uint64_t)j);
}
static inline uint64_t
get_jiffies_64(void)
{
- return ((uint64_t)(unsigned int)ticks);
-}
-
-static inline int
-linux_timer_jiffies_until(int expires)
-{
- int delta = expires - jiffies;
- /* guard against already expired values */
- if (delta < 1)
- delta = 1;
- return (delta);
+ return ((uint64_t)jiffies);
}
-#endif /* _LINUX_JIFFIES_H_ */
+#endif /* _LINUXKPI_LINUX_JIFFIES_H_ */
diff --git a/sys/compat/linuxkpi/common/include/linux/jump_label.h b/sys/compat/linuxkpi/common/include/linux/jump_label.h
new file mode 100644
index 000000000000..444754a0ff82
--- /dev/null
+++ b/sys/compat/linuxkpi/common/include/linux/jump_label.h
@@ -0,0 +1,48 @@
+/*
+ * Copyright (c) 2016-2020 François Tigeot <ftigeot@wolfpond.org>
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice unmodified, this list of conditions, and the following
+ * disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``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.
+ */
+
+#ifndef _LINUXKPI_LINUX_JUMP_LABEL_H_
+#define _LINUXKPI_LINUX_JUMP_LABEL_H_
+
+#include <linux/types.h>
+#include <linux/compiler.h>
+#include <linux/bug.h>
+
+#define DEFINE_STATIC_KEY_FALSE(key) bool key = false
+
+static inline void
+static_branch_enable(bool *flag)
+{
+ *flag = true;
+}
+
+static inline bool
+static_branch_likely(bool *flag)
+{
+ return *flag;
+}
+
+#endif /* _LINUXKPI_LINUX_JUMP_LABEL_H_ */
diff --git a/sys/compat/linuxkpi/common/include/linux/kconfig.h b/sys/compat/linuxkpi/common/include/linux/kconfig.h
new file mode 100644
index 000000000000..c1d186b56e1f
--- /dev/null
+++ b/sys/compat/linuxkpi/common/include/linux/kconfig.h
@@ -0,0 +1,76 @@
+/*-
+ * SPDX-License-Identifier: BSD-2-Clause
+ *
+ * Copyright (c) 2020 The FreeBSD Foundation
+ *
+ * This software was developed by Björn Zeeb under sponsorship from
+ * the FreeBSD Foundation.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``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 OR CONTRIBUTORS 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.
+ */
+
+#ifndef _LINUXKPI_LINUX_KCONFIG_H_
+#define _LINUXKPI_LINUX_KCONFIG_H_
+
+/*
+ * Checking if an option is defined would be easy if we could do CPP inside CPP.
+ * The defined case whether -Dxxx or -Dxxx=1 are easy to deal with. In either
+ * case the defined value is "1". A more general -Dxxx=<c> case will require
+ * more effort to deal with all possible "true" values. Hope we do not have
+ * to do this as well.
+ * The real problem is the undefined case. To avoid this problem we do the
+ * concat/varargs trick: "yyy" ## xxx can make two arguments if xxx is "1"
+ * by having a #define for yyy_1 which is "ignore,".
+ * Otherwise we will just get "yyy".
+ * Need to be careful about variable substitutions in macros though.
+ * This way we make a (true, false) problem a (don't care, true, false) or a
+ * (don't care true, false). Then we can use a variadic macro to only select
+ * the always well known and defined argument #2. And that seems to be
+ * exactly what we need. Use 1 for true and 0 for false to also allow
+ * #if IS_*() checks pre-compiler checks which do not like #if true.
+ */
+#define ___XAB_1 dontcare,
+#define ___IS_XAB(_ignore, _x, ...) (_x)
+#define __IS_XAB(_x) ___IS_XAB(_x 1, 0)
+#define _IS_XAB(_x) __IS_XAB(__CONCAT(___XAB_, _x))
+
+/* This is if CONFIG_ccc=y. */
+#define IS_BUILTIN(_x) _IS_XAB(_x)
+/* This is if CONFIG_ccc=m. */
+#define IS_MODULE(_x) _IS_XAB(_x ## _MODULE)
+/* This is if CONFIG_ccc is compiled in(=y) or a module(=m). */
+#define IS_ENABLED(_x) (IS_BUILTIN(_x) || IS_MODULE(_x))
+/*
+ * This is weird case. If the CONFIG_ccc is builtin (=y) this returns true;
+ * or if the CONFIG_ccc is a module (=m) and the caller is built as a module
+ * (-DMODULE defined) this returns true, but if the callers is not a module
+ * (-DMODULE not defined, which means caller is BUILTIN) then it returns
+ * false. In other words, a module can reach the kernel, a module can reach
+ * a module, but the kernel cannot reach a module, and code never compiled
+ * cannot be reached either.
+ * XXX -- I'd hope the module-to-module case would be handled by a proper
+ * module dependency definition (MODULE_DEPEND() in FreeBSD).
+ */
+#define IS_REACHABLE(_x) (IS_BUILTIN(_x) || \
+ (IS_MODULE(_x) && IS_BUILTIN(MODULE)))
+
+#endif /* _LINUXKPI_LINUX_KCONFIG_H_ */
diff --git a/sys/compat/linuxkpi/common/include/linux/kdev_t.h b/sys/compat/linuxkpi/common/include/linux/kdev_t.h
index 9477ba739e31..988dd771254a 100644
--- a/sys/compat/linuxkpi/common/include/linux/kdev_t.h
+++ b/sys/compat/linuxkpi/common/include/linux/kdev_t.h
@@ -25,11 +25,9 @@
* 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.
- *
- * $FreeBSD$
*/
-#ifndef _LINUX_KDEV_T_H_
-#define _LINUX_KDEV_T_H_
+#ifndef _LINUXKPI_LINUX_KDEV_T_H_
+#define _LINUXKPI_LINUX_KDEV_T_H_
#include <sys/types.h>
@@ -43,4 +41,4 @@ old_encode_dev(dev_t dev)
return ((MAJOR(dev) << 8) | MINOR(dev));
}
-#endif /* _LINUX_KDEV_T_H_ */
+#endif /* _LINUXKPI_LINUX_KDEV_T_H_ */
diff --git a/sys/compat/linuxkpi/common/include/linux/kernel.h b/sys/compat/linuxkpi/common/include/linux/kernel.h
index 94af8f29c4d7..11a13cbd49b4 100644
--- a/sys/compat/linuxkpi/common/include/linux/kernel.h
+++ b/sys/compat/linuxkpi/common/include/linux/kernel.h
@@ -26,13 +26,10 @@
* 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.
- *
- * $FreeBSD$
*/
-#ifndef _LINUX_KERNEL_H_
-#define _LINUX_KERNEL_H_
+#ifndef _LINUXKPI_LINUX_KERNEL_H_
+#define _LINUXKPI_LINUX_KERNEL_H_
-#include <sys/cdefs.h>
#include <sys/types.h>
#include <sys/systm.h>
#include <sys/param.h>
@@ -44,18 +41,27 @@
#include <sys/time.h>
#include <linux/bitops.h>
+#include <linux/build_bug.h>
#include <linux/compiler.h>
+#include <linux/container_of.h>
+#include <linux/kstrtox.h>
+#include <linux/limits.h>
+#include <linux/math.h>
+#include <linux/minmax.h>
#include <linux/stringify.h>
#include <linux/errno.h>
-#include <linux/sched.h>
#include <linux/types.h>
+#include <linux/typecheck.h>
#include <linux/jiffies.h>
#include <linux/log2.h>
+#include <linux/kconfig.h>
#include <asm/byteorder.h>
+#include <asm/cpufeature.h>
+#include <asm/processor.h>
#include <asm/uaccess.h>
-#include <machine/stdarg.h>
+#include <linux/stdarg.h>
#define KERN_CONT ""
#define KERN_EMERG "<0>"
@@ -67,19 +73,6 @@
#define KERN_INFO "<6>"
#define KERN_DEBUG "<7>"
-#define U8_MAX ((u8)~0U)
-#define S8_MAX ((s8)(U8_MAX >> 1))
-#define S8_MIN ((s8)(-S8_MAX - 1))
-#define U16_MAX ((u16)~0U)
-#define S16_MAX ((s16)(U16_MAX >> 1))
-#define S16_MIN ((s16)(-S16_MAX - 1))
-#define U32_MAX ((u32)~0U)
-#define S32_MAX ((s32)(U32_MAX >> 1))
-#define S32_MIN ((s32)(-S32_MAX - 1))
-#define U64_MAX ((u64)~0ULL)
-#define S64_MAX ((s64)(U64_MAX >> 1))
-#define S64_MIN ((s64)(-S64_MAX - 1))
-
#define S8_C(x) x
#define U8_C(x) x ## U
#define S16_C(x) x
@@ -89,30 +82,6 @@
#define S64_C(x) x ## LL
#define U64_C(x) x ## ULL
-/*
- * BUILD_BUG_ON() can happen inside functions where _Static_assert() does not
- * seem to work. Use old-schoold-ish CTASSERT from before commit
- * a3085588a88fa58eb5b1eaae471999e1995a29cf but also make sure we do not
- * end up with an unused typedef or variable. The compiler should optimise
- * it away entirely.
- */
-#define _O_CTASSERT(x) _O__CTASSERT(x, __LINE__)
-#define _O__CTASSERT(x, y) _O___CTASSERT(x, y)
-#define _O___CTASSERT(x, y) while (0) { \
- typedef char __assert_line_ ## y[(x) ? 1 : -1]; \
- __assert_line_ ## y _x; \
- _x[0] = '\0'; \
-}
-
-#define BUILD_BUG() do { CTASSERT(0); } while (0)
-#define BUILD_BUG_ON(x) do { _O_CTASSERT(!(x)) } while (0)
-#define BUILD_BUG_ON_MSG(x, msg) BUILD_BUG_ON(x)
-#define BUILD_BUG_ON_NOT_POWER_OF_2(x) BUILD_BUG_ON(!powerof2(x))
-#define BUILD_BUG_ON_INVALID(expr) while (0) { (void)(expr); }
-
-extern const volatile int lkpi_build_bug_on_zero;
-#define BUILD_BUG_ON_ZERO(x) ((x) ? lkpi_build_bug_on_zero : 0)
-
#define BUG() panic("BUG at %s:%d", __FILE__, __LINE__)
#define BUG_ON(cond) do { \
if (cond) { \
@@ -152,18 +121,18 @@ extern int linuxkpi_warn_dump_stack;
#undef ALIGN
#define ALIGN(x, y) roundup2((x), (y))
+#define ALIGN_DOWN(x, y) rounddown2(x, y)
#undef PTR_ALIGN
#define PTR_ALIGN(p, a) ((__typeof(p))ALIGN((uintptr_t)(p), (a)))
#define IS_ALIGNED(x, a) (((x) & ((__typeof(x))(a) - 1)) == 0)
-#define DIV_ROUND_UP(x, n) howmany(x, n)
#define __KERNEL_DIV_ROUND_UP(x, n) howmany(x, n)
-#define DIV_ROUND_UP_ULL(x, n) DIV_ROUND_UP((unsigned long long)(x), (n))
-#define DIV_ROUND_DOWN_ULL(x, n) (((unsigned long long)(x) / (n)) * (n))
#define FIELD_SIZEOF(t, f) sizeof(((t *)0)->f)
#define printk(...) printf(__VA_ARGS__)
#define vprintk(f, a) vprintf(f, a)
+#define PTR_IF(x, p) ((x) ? (p) : NULL)
+
#define asm __asm
extern void linux_dump_stack(void);
@@ -294,265 +263,15 @@ extern int linuxkpi_debug;
})
#endif
-#define container_of(ptr, type, member) \
-({ \
- const __typeof(((type *)0)->member) *__p = (ptr); \
- (type *)((uintptr_t)__p - offsetof(type, member)); \
-})
-
#define ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0]))
#define u64_to_user_ptr(val) ((void *)(uintptr_t)(val))
#define _RET_IP_ __builtin_return_address(0)
-static inline unsigned long long
-simple_strtoull(const char *cp, char **endp, unsigned int base)
-{
- return (strtouq(cp, endp, base));
-}
-
-static inline long long
-simple_strtoll(const char *cp, char **endp, unsigned int base)
-{
- return (strtoq(cp, endp, base));
-}
-
-static inline unsigned long
-simple_strtoul(const char *cp, char **endp, unsigned int base)
-{
- return (strtoul(cp, endp, base));
-}
-
-static inline long
-simple_strtol(const char *cp, char **endp, unsigned int base)
-{
- return (strtol(cp, endp, base));
-}
-
-static inline int
-kstrtoul(const char *cp, unsigned int base, unsigned long *res)
-{
- char *end;
-
- *res = strtoul(cp, &end, base);
-
- /* skip newline character, if any */
- if (*end == '\n')
- end++;
- if (*cp == 0 || *end != 0)
- return (-EINVAL);
- return (0);
-}
-
-static inline int
-kstrtol(const char *cp, unsigned int base, long *res)
-{
- char *end;
-
- *res = strtol(cp, &end, base);
-
- /* skip newline character, if any */
- if (*end == '\n')
- end++;
- if (*cp == 0 || *end != 0)
- return (-EINVAL);
- return (0);
-}
-
-static inline int
-kstrtoint(const char *cp, unsigned int base, int *res)
-{
- char *end;
- long temp;
-
- *res = temp = strtol(cp, &end, base);
-
- /* skip newline character, if any */
- if (*end == '\n')
- end++;
- if (*cp == 0 || *end != 0)
- return (-EINVAL);
- if (temp != (int)temp)
- return (-ERANGE);
- return (0);
-}
-
-static inline int
-kstrtouint(const char *cp, unsigned int base, unsigned int *res)
-{
- char *end;
- unsigned long temp;
-
- *res = temp = strtoul(cp, &end, base);
-
- /* skip newline character, if any */
- if (*end == '\n')
- end++;
- if (*cp == 0 || *end != 0)
- return (-EINVAL);
- if (temp != (unsigned int)temp)
- return (-ERANGE);
- return (0);
-}
-
-static inline int
-kstrtou8(const char *cp, unsigned int base, u8 *res)
-{
- char *end;
- unsigned long temp;
-
- *res = temp = strtoul(cp, &end, base);
-
- /* skip newline character, if any */
- if (*end == '\n')
- end++;
- if (*cp == 0 || *end != 0)
- return (-EINVAL);
- if (temp != (u8)temp)
- return (-ERANGE);
- return (0);
-}
-
-static inline int
-kstrtou16(const char *cp, unsigned int base, u16 *res)
-{
- char *end;
- unsigned long temp;
-
- *res = temp = strtoul(cp, &end, base);
-
- /* skip newline character, if any */
- if (*end == '\n')
- end++;
- if (*cp == 0 || *end != 0)
- return (-EINVAL);
- if (temp != (u16)temp)
- return (-ERANGE);
- return (0);
-}
-
-static inline int
-kstrtou32(const char *cp, unsigned int base, u32 *res)
-{
- char *end;
- unsigned long temp;
-
- *res = temp = strtoul(cp, &end, base);
-
- /* skip newline character, if any */
- if (*end == '\n')
- end++;
- if (*cp == 0 || *end != 0)
- return (-EINVAL);
- if (temp != (u32)temp)
- return (-ERANGE);
- return (0);
-}
-
-static inline int
-kstrtou64(const char *cp, unsigned int base, u64 *res)
-{
- char *end;
-
- *res = strtouq(cp, &end, base);
-
- /* skip newline character, if any */
- if (*end == '\n')
- end++;
- if (*cp == 0 || *end != 0)
- return (-EINVAL);
- return (0);
-}
-
-static inline int
-kstrtobool(const char *s, bool *res)
-{
- int len;
-
- if (s == NULL || (len = strlen(s)) == 0 || res == NULL)
- return (-EINVAL);
-
- /* skip newline character, if any */
- if (s[len - 1] == '\n')
- len--;
-
- if (len == 1 && strchr("yY1", s[0]) != NULL)
- *res = true;
- else if (len == 1 && strchr("nN0", s[0]) != NULL)
- *res = false;
- else if (strncasecmp("on", s, len) == 0)
- *res = true;
- else if (strncasecmp("off", s, len) == 0)
- *res = false;
- else
- return (-EINVAL);
-
- return (0);
-}
-
-static inline int
-kstrtobool_from_user(const char __user *s, size_t count, bool *res)
-{
- char buf[8] = {};
-
- if (count > (sizeof(buf) - 1))
- count = (sizeof(buf) - 1);
-
- if (copy_from_user(buf, s, count))
- return (-EFAULT);
-
- return (kstrtobool(buf, res));
-}
-
-static inline int
-kstrtou8_from_user(const char __user *s, size_t count, unsigned int base,
- u8 *p)
-{
- char buf[8] = {};
-
- if (count > (sizeof(buf) - 1))
- count = (sizeof(buf) - 1);
-
- if (copy_from_user(buf, s, count))
- return (-EFAULT);
-
- return (kstrtou8(buf, base, p));
-}
-
-#define min(x, y) ((x) < (y) ? (x) : (y))
-#define max(x, y) ((x) > (y) ? (x) : (y))
-
-#define min3(a, b, c) min(a, min(b,c))
-#define max3(a, b, c) max(a, max(b,c))
-
-#define min_t(type, x, y) ({ \
- type __min1 = (x); \
- type __min2 = (y); \
- __min1 < __min2 ? __min1 : __min2; })
-
-#define max_t(type, x, y) ({ \
- type __max1 = (x); \
- type __max2 = (y); \
- __max1 > __max2 ? __max1 : __max2; })
-
#define offsetofend(t, m) \
(offsetof(t, m) + sizeof((((t *)0)->m)))
-#define clamp_t(type, _x, min, max) min_t(type, max_t(type, _x, min), max)
-#define clamp(x, lo, hi) min( max(x,lo), hi)
-#define clamp_val(val, lo, hi) clamp_t(typeof(val), val, lo, hi)
-
-/*
- * This looks more complex than it should be. But we need to
- * get the type for the ~ right in round_down (it needs to be
- * as wide as the result!), and we want to evaluate the macro
- * arguments just once each.
- */
-#define __round_mask(x, y) ((__typeof__(x))((y)-1))
-#define round_up(x, y) ((((x)-1) | __round_mask(x, y))+1)
-#define round_down(x, y) ((x) & ~__round_mask(x, y))
-
#define smp_processor_id() PCPU_GET(cpuid)
#define num_possible_cpus() mp_ncpus
#define num_online_cpus() mp_ncpus
@@ -562,41 +281,6 @@ extern bool linux_cpu_has_clflush;
#define cpu_has_clflush linux_cpu_has_clflush
#endif
-typedef struct pm_message {
- int event;
-} pm_message_t;
-
-/* Swap values of a and b */
-#define swap(a, b) do { \
- typeof(a) _swap_tmp = a; \
- a = b; \
- b = _swap_tmp; \
-} while (0)
-
-#define DIV_ROUND_CLOSEST(x, divisor) (((x) + ((divisor) / 2)) / (divisor))
-
-#define DIV_ROUND_CLOSEST_ULL(x, divisor) ({ \
- __typeof(divisor) __d = (divisor); \
- unsigned long long __ret = (x) + (__d) / 2; \
- __ret /= __d; \
- __ret; \
-})
-
-static inline uintmax_t
-mult_frac(uintmax_t x, uintmax_t multiplier, uintmax_t divisor)
-{
- uintmax_t q = (x / divisor);
- uintmax_t r = (x % divisor);
-
- return ((q * multiplier) + ((r * multiplier) / divisor));
-}
-
-static inline int64_t
-abs64(int64_t x)
-{
- return (x < 0 ? -x : x);
-}
-
typedef struct linux_ratelimit {
struct timeval lasttime;
int counter;
@@ -608,12 +292,6 @@ linux_ratelimited(linux_ratelimit_t *rl)
return (ppsratecheck(&rl->lasttime, &rl->counter, 1));
}
-#define struct_size(ptr, field, num) ({ \
- const size_t __size = offsetof(__typeof(*(ptr)), field); \
- const size_t __max = (SIZE_MAX - __size) / sizeof((ptr)->field[0]); \
- ((num) > __max) ? SIZE_MAX : (__size + sizeof((ptr)->field[0]) * (num)); \
-})
-
#define __is_constexpr(x) \
__builtin_constant_p(x)
@@ -623,72 +301,85 @@ linux_ratelimited(linux_ratelimit_t *rl)
*/
#define is_signed(datatype) (((datatype)-1 / (datatype)2) == (datatype)0)
-/*
- * The type_max() macro below returns the maxium positive value the
- * passed data type can hold.
- */
-#define type_max(datatype) ( \
- (sizeof(datatype) >= 8) ? (is_signed(datatype) ? INT64_MAX : UINT64_MAX) : \
- (sizeof(datatype) >= 4) ? (is_signed(datatype) ? INT32_MAX : UINT32_MAX) : \
- (sizeof(datatype) >= 2) ? (is_signed(datatype) ? INT16_MAX : UINT16_MAX) : \
- (is_signed(datatype) ? INT8_MAX : UINT8_MAX) \
-)
-
-/*
- * The type_min() macro below returns the minimum value the passed
- * data type can hold. For unsigned types the minimum value is always
- * zero. For signed types it may vary.
- */
-#define type_min(datatype) ( \
- (sizeof(datatype) >= 8) ? (is_signed(datatype) ? INT64_MIN : 0) : \
- (sizeof(datatype) >= 4) ? (is_signed(datatype) ? INT32_MIN : 0) : \
- (sizeof(datatype) >= 2) ? (is_signed(datatype) ? INT16_MIN : 0) : \
- (is_signed(datatype) ? INT8_MIN : 0) \
-)
-
#define TAINT_WARN 0
#define test_taint(x) (0)
+#define add_taint(x,y) do { \
+ } while (0)
-/*
- * Checking if an option is defined would be easy if we could do CPP inside CPP.
- * The defined case whether -Dxxx or -Dxxx=1 are easy to deal with. In either
- * case the defined value is "1". A more general -Dxxx=<c> case will require
- * more effort to deal with all possible "true" values. Hope we do not have
- * to do this as well.
- * The real problem is the undefined case. To avoid this problem we do the
- * concat/varargs trick: "yyy" ## xxx can make two arguments if xxx is "1"
- * by having a #define for yyy_1 which is "ignore,".
- * Otherwise we will just get "yyy".
- * Need to be careful about variable substitutions in macros though.
- * This way we make a (true, false) problem a (don't care, true, false) or a
- * (don't care true, false). Then we can use a variadic macro to only select
- * the always well known and defined argument #2. And that seems to be
- * exactly what we need. Use 1 for true and 0 for false to also allow
- * #if IS_*() checks pre-compiler checks which do not like #if true.
- */
-#define ___XAB_1 dontcare,
-#define ___IS_XAB(_ignore, _x, ...) (_x)
-#define __IS_XAB(_x) ___IS_XAB(_x 1, 0)
-#define _IS_XAB(_x) __IS_XAB(__CONCAT(___XAB_, _x))
-
-/* This is if CONFIG_ccc=y. */
-#define IS_BUILTIN(_x) _IS_XAB(_x)
-/* This is if CONFIG_ccc=m. */
-#define IS_MODULE(_x) _IS_XAB(_x ## _MODULE)
-/* This is if CONFIG_ccc is compiled in(=y) or a module(=m). */
-#define IS_ENABLED(_x) (IS_BUILTIN(_x) || IS_MODULE(_x))
-/*
- * This is weird case. If the CONFIG_ccc is builtin (=y) this returns true;
- * or if the CONFIG_ccc is a module (=m) and the caller is built as a module
- * (-DMODULE defined) this returns true, but if the callers is not a module
- * (-DMODULE not defined, which means caller is BUILTIN) then it returns
- * false. In other words, a module can reach the kernel, a module can reach
- * a module, but the kernel cannot reach a module, and code never compiled
- * cannot be reached either.
- * XXX -- I'd hope the module-to-module case would be handled by a proper
- * module dependency definition (MODULE_DEPEND() in FreeBSD).
- */
-#define IS_REACHABLE(_x) (IS_BUILTIN(_x) || \
- (IS_MODULE(_x) && IS_BUILTIN(MODULE)))
+static inline int
+_h2b(const char c)
+{
+
+ if (c >= '0' && c <= '9')
+ return (c - '0');
+ if (c >= 'a' && c <= 'f')
+ return (10 + c - 'a');
+ if (c >= 'A' && c <= 'F')
+ return (10 + c - 'A');
+ return (-EINVAL);
+}
+
+static inline int
+hex2bin(uint8_t *bindst, const char *hexsrc, size_t binlen)
+{
+ int hi4, lo4;
+
+ while (binlen > 0) {
+ hi4 = _h2b(*hexsrc++);
+ lo4 = _h2b(*hexsrc++);
+ if (hi4 < 0 || lo4 < 0)
+ return (-EINVAL);
+
+ *bindst++ = (hi4 << 4) | lo4;
+ binlen--;
+ }
+
+ return (0);
+}
+
+static inline bool
+mac_pton(const char *macin, uint8_t *macout)
+{
+ const char *s, *d;
+ uint8_t mac[6], hx, lx;
+ int i;
+
+ if (strlen(macin) < (3 * 6 - 1))
+ return (false);
+
+ i = 0;
+ s = macin;
+ do {
+ /* Should we also support '-'-delimiters? */
+ d = strchrnul(s, ':');
+ hx = lx = 0;
+ while (s < d) {
+ /* Fail on abc:123:xxx:... */
+ if ((d - s) > 2)
+ return (false);
+ /* We do support non-well-formed strings: 3:45:6:... */
+ if ((d - s) > 1) {
+ hx = _h2b(*s);
+ if (hx < 0)
+ return (false);
+ s++;
+ }
+ lx = _h2b(*s);
+ if (lx < 0)
+ return (false);
+ s++;
+ }
+ mac[i] = (hx << 4) | lx;
+ i++;
+ if (i >= 6)
+ return (false);
+ } while (d != NULL && *d != '\0');
+
+ memcpy(macout, mac, 6);
+ return (true);
+}
+
+#define DECLARE_FLEX_ARRAY(_t, _n) \
+ struct { struct { } __dummy_ ## _n; _t _n[0]; }
-#endif /* _LINUX_KERNEL_H_ */
+#endif /* _LINUXKPI_LINUX_KERNEL_H_ */
diff --git a/sys/compat/linuxkpi/common/include/linux/kernel_stat.h b/sys/compat/linuxkpi/common/include/linux/kernel_stat.h
new file mode 100644
index 000000000000..c960b4ad2cff
--- /dev/null
+++ b/sys/compat/linuxkpi/common/include/linux/kernel_stat.h
@@ -0,0 +1,34 @@
+/*-
+ * SPDX-License-Identifier: BSD-2-Clause
+ *
+ * Copyright (c) 2025 Jean-Sébastien Pédron <dumbbell@FreeBSD.org>
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are
+ * met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in
+ * the documentation and/or other materials provided with the
+ * distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``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 OR CONTRIBUTORS 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.
+ */
+
+#ifndef _LINUXKPI_LINUX_KERNEL_STAT_H_
+#define _LINUXKPI_LINUX_KERNEL_STAT_H_
+
+#include <linux/interrupt.h>
+
+#endif /* _LINUXKPI_LINUX_KERNEL_STAT_H_ */
diff --git a/sys/compat/linuxkpi/common/include/linux/kfifo.h b/sys/compat/linuxkpi/common/include/linux/kfifo.h
new file mode 100644
index 000000000000..d2f570781661
--- /dev/null
+++ b/sys/compat/linuxkpi/common/include/linux/kfifo.h
@@ -0,0 +1,122 @@
+/*-
+ * Copyright (c) 2021 Beckhoff Automation GmbH & Co. KG
+ * Copyright (c) 2022 Bjoern A. Zeeb
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``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 OR CONTRIBUTORS 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.
+ *
+ */
+
+#ifndef _LINUXKPI_LINUX_KFIFO_H_
+#define _LINUXKPI_LINUX_KFIFO_H_
+
+#include <sys/types.h>
+
+#include <linux/slab.h>
+#include <linux/gfp.h>
+
+#define INIT_KFIFO(x) 0
+#define DECLARE_KFIFO(x, y, z)
+
+#define DECLARE_KFIFO_PTR(_name, _type) \
+ struct kfifo_ ## _name { \
+ size_t total; \
+ size_t count; \
+ size_t first; \
+ size_t last; \
+ _type *head; \
+ } _name
+
+#define kfifo_len(_kf) \
+({ \
+ (_kf)->count; \
+})
+
+#define kfifo_is_empty(_kf) \
+({ \
+ ((_kf)->count == 0) ? true : false; \
+})
+
+#define kfifo_is_full(_kf) \
+({ \
+ ((_kf)->count == (_kf)->total) ? true : false; \
+})
+
+#define kfifo_put(_kf, _e) \
+({ \
+ bool _rc; \
+ \
+ /* Would overflow. */ \
+ if (kfifo_is_full(_kf)) { \
+ _rc = false; \
+ } else { \
+ (_kf)->head[(_kf)->last] = (_e); \
+ (_kf)->count++; \
+ (_kf)->last++; \
+ if ((_kf)->last > (_kf)->total) \
+ (_kf)->last = 0; \
+ _rc = true; \
+ } \
+ \
+ _rc; \
+})
+
+#define kfifo_get(_kf, _e) \
+({ \
+ bool _rc; \
+ \
+ if (kfifo_is_empty(_kf)) { \
+ _rc = false; \
+ } else { \
+ *(_e) = (_kf)->head[(_kf)->first]; \
+ (_kf)->count--; \
+ (_kf)->first++; \
+ if ((_kf)->first > (_kf)->total) \
+ (_kf)->first = 0; \
+ _rc = true; \
+ } \
+ \
+ _rc; \
+})
+
+#define kfifo_alloc(_kf, _s, _gfp) \
+({ \
+ int _error; \
+ \
+ (_kf)->head = kmalloc(sizeof(__typeof(*(_kf)->head)) * (_s), _gfp); \
+ if ((_kf)->head == NULL) \
+ _error = ENOMEM; \
+ else { \
+ (_kf)->total = (_s); \
+ _error = 0; \
+ } \
+ \
+ _error; \
+})
+
+#define kfifo_free(_kf) \
+({ \
+ kfree((_kf)->head); \
+ (_kf)->head = NULL; \
+ (_kf)->total = (_kf)->count = (_kf)->first = (_kf)->last = 0; \
+})
+
+#endif /* _LINUXKPI_LINUX_KFIFO_H_*/
diff --git a/sys/compat/linuxkpi/common/include/linux/kmemleak.h b/sys/compat/linuxkpi/common/include/linux/kmemleak.h
new file mode 100644
index 000000000000..7007e72718c7
--- /dev/null
+++ b/sys/compat/linuxkpi/common/include/linux/kmemleak.h
@@ -0,0 +1,8 @@
+/* Public domain. */
+
+#ifndef _LINUXKPI_LINUX_KMEMLEAK_H_
+#define _LINUXKPI_LINUX_KMEMLEAK_H_
+
+#define kmemleak_update_trace(x)
+
+#endif /* _LINUXKPI_LINUX_KMEMLEAK_H_ */
diff --git a/sys/compat/linuxkpi/common/include/linux/kmod.h b/sys/compat/linuxkpi/common/include/linux/kmod.h
index b8a1a8b677ed..8f9f034aabd8 100644
--- a/sys/compat/linuxkpi/common/include/linux/kmod.h
+++ b/sys/compat/linuxkpi/common/include/linux/kmod.h
@@ -25,27 +25,24 @@
* 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.
- *
- * $FreeBSD$
*/
-#ifndef _LINUX_KMOD_H_
-#define _LINUX_KMOD_H_
+#ifndef _LINUXKPI_LINUX_KMOD_H_
+#define _LINUXKPI_LINUX_KMOD_H_
#include <sys/types.h>
#include <sys/syscallsubr.h>
#include <sys/refcount.h>
#include <sys/sbuf.h>
-#include <machine/stdarg.h>
+#include <sys/stdarg.h>
#include <sys/proc.h>
#define request_module(...) \
({\
char modname[128]; \
- int fileid; \
snprintf(modname, sizeof(modname), __VA_ARGS__); \
- kern_kldload(curthread, modname, &fileid); \
+ kern_kldload(curthread, modname, NULL); \
})
#define request_module_nowait request_module
-#endif /* _LINUX_KMOD_H_ */
+#endif /* _LINUXKPI_LINUX_KMOD_H_ */
diff --git a/sys/compat/linuxkpi/common/include/linux/kobject.h b/sys/compat/linuxkpi/common/include/linux/kobject.h
index 403ec1495c32..98f55d1234c4 100644
--- a/sys/compat/linuxkpi/common/include/linux/kobject.h
+++ b/sys/compat/linuxkpi/common/include/linux/kobject.h
@@ -25,20 +25,22 @@
* 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.
- *
- * $FreeBSD$
*/
-#ifndef _LINUX_KOBJECT_H_
-#define _LINUX_KOBJECT_H_
+#ifndef _LINUXKPI_LINUX_KOBJECT_H_
+#define _LINUXKPI_LINUX_KOBJECT_H_
-#include <machine/stdarg.h>
+#include <sys/stdarg.h>
#include <linux/kernel.h>
#include <linux/kref.h>
#include <linux/list.h>
#include <linux/slab.h>
+#include <linux/spinlock.h>
+#include <linux/wait.h>
+#include <linux/workqueue.h>
struct kobject;
+struct kset;
struct sysctl_oid;
#define KOBJ_CHANGE 0x01
@@ -47,6 +49,7 @@ struct kobj_type {
void (*release)(struct kobject *kobj);
const struct sysfs_ops *sysfs_ops;
struct attribute **default_attrs;
+ const struct attribute_group **default_groups;
};
extern const struct kobj_type linux_kfree_type;
@@ -58,6 +61,7 @@ struct kobject {
const struct kobj_type *ktype;
struct list_head entry;
struct sysctl_oid *oidp;
+ struct kset *kset;
};
extern struct kobject *mm_kobj;
@@ -68,6 +72,8 @@ struct attribute {
mode_t mode;
};
+extern const struct sysfs_ops kobj_sysfs_ops;
+
struct kobj_attribute {
struct attribute attr;
ssize_t (*show)(struct kobject *kobj, struct kobj_attribute *attr,
@@ -76,6 +82,17 @@ struct kobj_attribute {
const char *buf, size_t count);
};
+struct kset_uevent_ops {
+ /* TODO */
+};
+
+struct kset {
+ struct list_head list;
+ spinlock_t list_lock;
+ struct kobject kobj;
+ const struct kset_uevent_ops *uevent_ops;
+};
+
static inline void
kobject_init(struct kobject *kobj, const struct kobj_type *ktype)
{
@@ -105,24 +122,12 @@ kobject_get(struct kobject *kobj)
return kobj;
}
+struct kobject *kobject_create(void);
int kobject_set_name_vargs(struct kobject *kobj, const char *fmt, va_list);
int kobject_add(struct kobject *kobj, struct kobject *parent,
const char *fmt, ...);
static inline struct kobject *
-kobject_create(void)
-{
- struct kobject *kobj;
-
- kobj = kzalloc(sizeof(*kobj), GFP_KERNEL);
- if (kobj == NULL)
- return (NULL);
- kobject_init(kobj, &linux_kfree_type);
-
- return (kobj);
-}
-
-static inline struct kobject *
kobject_create_and_add(const char *name, struct kobject *parent)
{
struct kobject *kobj;
@@ -165,4 +170,41 @@ kobject_uevent_env(struct kobject *kobj, int action, char *envp[])
*/
}
-#endif /* _LINUX_KOBJECT_H_ */
+void kset_init(struct kset *kset);
+int kset_register(struct kset *kset);
+void kset_unregister(struct kset *kset);
+struct kset * kset_create_and_add(const char *name,
+ const struct kset_uevent_ops *u, struct kobject *parent_kobj);
+
+static inline struct kset *
+to_kset(struct kobject *kobj)
+{
+ if (kobj != NULL)
+ return container_of(kobj, struct kset, kobj);
+ else
+ return NULL;
+}
+
+static inline struct kset *
+kset_get(struct kset *kset)
+{
+ if (kset != NULL) {
+ struct kobject *kobj;
+
+ kobj = kobject_get(&kset->kobj);
+ return to_kset(kobj);
+ } else {
+ return NULL;
+ }
+}
+
+static inline void
+kset_put(struct kset *kset)
+{
+ if (kset != NULL)
+ kobject_put(&kset->kobj);
+}
+
+void linux_kobject_kfree_name(struct kobject *kobj);
+
+#endif /* _LINUXKPI_LINUX_KOBJECT_H_ */
diff --git a/sys/compat/linuxkpi/common/include/linux/kref.h b/sys/compat/linuxkpi/common/include/linux/kref.h
index d5b45ba59313..b2fba468f7df 100644
--- a/sys/compat/linuxkpi/common/include/linux/kref.h
+++ b/sys/compat/linuxkpi/common/include/linux/kref.h
@@ -26,11 +26,9 @@
* 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.
- *
- * $FreeBSD$
*/
-#ifndef _LINUX_KREF_H_
-#define _LINUX_KREF_H_
+#ifndef _LINUXKPI_LINUX_KREF_H_
+#define _LINUXKPI_LINUX_KREF_H_
#include <sys/types.h>
#include <sys/refcount.h>
@@ -43,35 +41,35 @@
#include <asm/atomic.h>
struct kref {
- atomic_t refcount;
+ refcount_t refcount;
};
static inline void
kref_init(struct kref *kref)
{
- refcount_init(&kref->refcount.counter, 1);
+ refcount_init((uint32_t *)&kref->refcount, 1);
}
static inline unsigned int
kref_read(const struct kref *kref)
{
- return (atomic_read(&kref->refcount));
+ return (refcount_load(__DECONST(u_int32_t *, &kref->refcount)));
}
static inline void
kref_get(struct kref *kref)
{
- refcount_acquire(&kref->refcount.counter);
+ refcount_acquire((uint32_t *)&kref->refcount);
}
static inline int
kref_put(struct kref *kref, void (*rel)(struct kref *kref))
{
- if (refcount_release(&kref->refcount.counter)) {
+ if (refcount_release((uint32_t *)&kref->refcount)) {
rel(kref);
return 1;
}
@@ -83,7 +81,7 @@ kref_put_lock(struct kref *kref, void (*rel)(struct kref *kref),
spinlock_t *lock)
{
- if (refcount_release(&kref->refcount.counter)) {
+ if (refcount_release((uint32_t *)&kref->refcount)) {
spin_lock(lock);
rel(kref);
return (1);
@@ -97,7 +95,7 @@ kref_sub(struct kref *kref, unsigned int count,
{
while (count--) {
- if (refcount_release(&kref->refcount.counter)) {
+ if (refcount_release((uint32_t *)&kref->refcount)) {
rel(kref);
return 1;
}
@@ -109,16 +107,16 @@ static inline int __must_check
kref_get_unless_zero(struct kref *kref)
{
- return atomic_add_unless(&kref->refcount, 1, 0);
+ return refcount_acquire_if_not_zero((uint32_t *)&kref->refcount);
}
static inline int kref_put_mutex(struct kref *kref,
void (*release)(struct kref *kref), struct mutex *lock)
{
WARN_ON(release == NULL);
- if (unlikely(!atomic_add_unless(&kref->refcount, -1, 1))) {
+ if (unlikely(!refcount_release_if_not_last((uint32_t *)&kref->refcount))) {
mutex_lock(lock);
- if (unlikely(!atomic_dec_and_test(&kref->refcount))) {
+ if (unlikely(!refcount_release((uint32_t *)&kref->refcount))) {
mutex_unlock(lock);
return 0;
}
@@ -128,4 +126,4 @@ static inline int kref_put_mutex(struct kref *kref,
return 0;
}
-#endif /* _LINUX_KREF_H_ */
+#endif /* _LINUXKPI_LINUX_KREF_H_ */
diff --git a/sys/compat/linuxkpi/common/include/linux/kstrtox.h b/sys/compat/linuxkpi/common/include/linux/kstrtox.h
new file mode 100644
index 000000000000..5da99de24197
--- /dev/null
+++ b/sys/compat/linuxkpi/common/include/linux/kstrtox.h
@@ -0,0 +1,324 @@
+/*-
+ * Copyright (c) 2010 Isilon Systems, Inc.
+ * Copyright (c) 2010 iX Systems, Inc.
+ * Copyright (c) 2010 Panasas, Inc.
+ * Copyright (c) 2017-2018 Mellanox Technologies, Ltd.
+ * All rights reserved.
+ * Copyright (c) 2018 Johannes Lundberg <johalun0@gmail.com>
+ * Copyright (c) 2020-2022 The FreeBSD Foundation
+ * Copyright (c) 2021 Vladimir Kondratyev <wulf@FreeBSD.org>
+ * Copyright (c) 2023 Serenity Cyber Security, LLC
+ *
+ * Portions of this software were developed by Bjoern A. Zeeb and
+ * Emmanuel Vadot under sponsorship from the FreeBSD Foundation.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice unmodified, this list of conditions, and the following
+ * disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``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.
+ */
+
+#ifndef _LINUXKPI_LINUX_KSTRTOX_H_
+#define _LINUXKPI_LINUX_KSTRTOX_H_
+
+#include <sys/types.h>
+#include <sys/errno.h>
+#include <sys/libkern.h>
+
+#include <linux/compiler.h>
+#include <linux/types.h>
+
+#include <asm/uaccess.h>
+
+static inline unsigned long long
+simple_strtoull(const char *cp, char **endp, unsigned int base)
+{
+ return (strtouq(cp, endp, base));
+}
+
+static inline long long
+simple_strtoll(const char *cp, char **endp, unsigned int base)
+{
+ return (strtoq(cp, endp, base));
+}
+
+static inline unsigned long
+simple_strtoul(const char *cp, char **endp, unsigned int base)
+{
+ return (strtoul(cp, endp, base));
+}
+
+static inline long
+simple_strtol(const char *cp, char **endp, unsigned int base)
+{
+ return (strtol(cp, endp, base));
+}
+
+static inline int
+kstrtoul(const char *cp, unsigned int base, unsigned long *res)
+{
+ char *end;
+
+ *res = strtoul(cp, &end, base);
+
+ /* skip newline character, if any */
+ if (*end == '\n')
+ end++;
+ if (*cp == 0 || *end != 0)
+ return (-EINVAL);
+ return (0);
+}
+
+static inline int
+kstrtol(const char *cp, unsigned int base, long *res)
+{
+ char *end;
+
+ *res = strtol(cp, &end, base);
+
+ /* skip newline character, if any */
+ if (*end == '\n')
+ end++;
+ if (*cp == 0 || *end != 0)
+ return (-EINVAL);
+ return (0);
+}
+
+static inline int
+kstrtoint(const char *cp, unsigned int base, int *res)
+{
+ char *end;
+ long temp;
+
+ *res = temp = strtol(cp, &end, base);
+
+ /* skip newline character, if any */
+ if (*end == '\n')
+ end++;
+ if (*cp == 0 || *end != 0)
+ return (-EINVAL);
+ if (temp != (int)temp)
+ return (-ERANGE);
+ return (0);
+}
+
+static inline int
+kstrtouint(const char *cp, unsigned int base, unsigned int *res)
+{
+ char *end;
+ unsigned long temp;
+
+ *res = temp = strtoul(cp, &end, base);
+
+ /* skip newline character, if any */
+ if (*end == '\n')
+ end++;
+ if (*cp == 0 || *end != 0)
+ return (-EINVAL);
+ if (temp != (unsigned int)temp)
+ return (-ERANGE);
+ return (0);
+}
+
+static inline int
+kstrtou8(const char *cp, unsigned int base, uint8_t *res)
+{
+ char *end;
+ unsigned long temp;
+
+ *res = temp = strtoul(cp, &end, base);
+
+ /* skip newline character, if any */
+ if (*end == '\n')
+ end++;
+ if (*cp == 0 || *end != 0)
+ return (-EINVAL);
+ if (temp != (uint8_t)temp)
+ return (-ERANGE);
+ return (0);
+}
+
+static inline int
+kstrtou16(const char *cp, unsigned int base, uint16_t *res)
+{
+ char *end;
+ unsigned long temp;
+
+ *res = temp = strtoul(cp, &end, base);
+
+ /* skip newline character, if any */
+ if (*end == '\n')
+ end++;
+ if (*cp == 0 || *end != 0)
+ return (-EINVAL);
+ if (temp != (uint16_t)temp)
+ return (-ERANGE);
+ return (0);
+}
+
+static inline int
+kstrtou32(const char *cp, unsigned int base, uint32_t *res)
+{
+
+ return (kstrtouint(cp, base, res));
+}
+
+static inline int
+kstrtos32(const char *cp, unsigned int base, int32_t *res)
+{
+
+ return (kstrtoint(cp, base, res));
+}
+
+static inline int
+kstrtos64(const char *cp, unsigned int base, int64_t *res)
+{
+ char *end;
+
+ *res = strtoq(cp, &end, base);
+
+ /* skip newline character, if any */
+ if (*end == '\n')
+ end++;
+ if (*cp == 0 || *end != 0)
+ return (-EINVAL);
+ return (0);
+}
+
+static inline int
+kstrtoll(const char *cp, unsigned int base, long long *res)
+{
+ return (kstrtos64(cp, base, (int64_t *)res));
+}
+
+static inline int
+kstrtou64(const char *cp, unsigned int base, u64 *res)
+{
+ char *end;
+
+ *res = strtouq(cp, &end, base);
+
+ /* skip newline character, if any */
+ if (*end == '\n')
+ end++;
+ if (*cp == 0 || *end != 0)
+ return (-EINVAL);
+ return (0);
+}
+
+static inline int
+kstrtoull(const char *cp, unsigned int base, unsigned long long *res)
+{
+ return (kstrtou64(cp, base, (uint64_t *)res));
+}
+
+static inline int
+kstrtobool(const char *s, bool *res)
+{
+ int len;
+
+ if (s == NULL || (len = strlen(s)) == 0 || res == NULL)
+ return (-EINVAL);
+
+ /* skip newline character, if any */
+ if (s[len - 1] == '\n')
+ len--;
+
+ if (len == 1 && strchr("yY1", s[0]) != NULL)
+ *res = true;
+ else if (len == 1 && strchr("nN0", s[0]) != NULL)
+ *res = false;
+ else if (strncasecmp("on", s, len) == 0)
+ *res = true;
+ else if (strncasecmp("off", s, len) == 0)
+ *res = false;
+ else
+ return (-EINVAL);
+
+ return (0);
+}
+
+static inline int
+kstrtobool_from_user(const char __user *s, size_t count, bool *res)
+{
+ char buf[8] = {};
+
+ if (count > (sizeof(buf) - 1))
+ count = (sizeof(buf) - 1);
+
+ if (copy_from_user(buf, s, count))
+ return (-EFAULT);
+
+ return (kstrtobool(buf, res));
+}
+
+static inline int
+kstrtoint_from_user(const char __user *s, size_t count, unsigned int base,
+ int *p)
+{
+ char buf[36] = {};
+
+ if (count > (sizeof(buf) - 1))
+ count = (sizeof(buf) - 1);
+
+ if (copy_from_user(buf, s, count))
+ return (-EFAULT);
+
+ return (kstrtoint(buf, base, p));
+}
+
+static inline int
+kstrtouint_from_user(const char __user *s, size_t count, unsigned int base,
+ unsigned int *p)
+{
+ char buf[36] = {};
+
+ if (count > (sizeof(buf) - 1))
+ count = (sizeof(buf) - 1);
+
+ if (copy_from_user(buf, s, count))
+ return (-EFAULT);
+
+ return (kstrtouint(buf, base, p));
+}
+
+static inline int
+kstrtou32_from_user(const char __user *s, size_t count, unsigned int base,
+ unsigned int *p)
+{
+
+ return (kstrtouint_from_user(s, count, base, p));
+}
+
+static inline int
+kstrtou8_from_user(const char __user *s, size_t count, unsigned int base,
+ uint8_t *p)
+{
+ char buf[8] = {};
+
+ if (count > (sizeof(buf) - 1))
+ count = (sizeof(buf) - 1);
+
+ if (copy_from_user(buf, s, count))
+ return (-EFAULT);
+
+ return (kstrtou8(buf, base, p));
+}
+
+#endif /* _LINUXKPI_LINUX_KSTRTOX_H_ */
diff --git a/sys/compat/linuxkpi/common/include/linux/kthread.h b/sys/compat/linuxkpi/common/include/linux/kthread.h
index 3afd21dc9356..1fde734fd767 100644
--- a/sys/compat/linuxkpi/common/include/linux/kthread.h
+++ b/sys/compat/linuxkpi/common/include/linux/kthread.h
@@ -25,16 +25,35 @@
* 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.
- *
- * $FreeBSD$
*/
-#ifndef _LINUX_KTHREAD_H_
-#define _LINUX_KTHREAD_H_
+#ifndef _LINUXKPI_LINUX_KTHREAD_H_
+#define _LINUXKPI_LINUX_KTHREAD_H_
#include <linux/sched.h>
-#include <sys/unistd.h>
+#include <sys/param.h>
+#include <sys/kernel.h>
#include <sys/kthread.h>
+#include <sys/malloc.h>
+#include <sys/queue.h>
+#include <sys/taskqueue.h>
+#include <sys/unistd.h>
+
+struct task_struct;
+struct kthread_work;
+
+typedef void (*kthread_work_func_t)(struct kthread_work *work);
+
+struct kthread_worker {
+ struct task_struct *task;
+ struct taskqueue *tq;
+};
+
+struct kthread_work {
+ struct taskqueue *tq;
+ struct task task;
+ kthread_work_func_t func;
+};
#define kthread_run(fn, data, fmt, ...) ({ \
struct task_struct *__task; \
@@ -70,4 +89,78 @@ int linux_in_atomic(void);
#define in_atomic() linux_in_atomic()
-#endif /* _LINUX_KTHREAD_H_ */
+/* Only kthread_(create|destroy)_worker interface is allowed */
+#define kthread_init_worker(worker) \
+ _Static_assert(false, "pre-4.9 worker interface is not supported");
+
+task_fn_t lkpi_kthread_work_fn;
+task_fn_t lkpi_kthread_worker_init_fn;
+
+#define kthread_create_worker(flags, fmt, ...) ({ \
+ struct kthread_worker *__w; \
+ struct task __task; \
+ \
+ __w = malloc(sizeof(*__w), M_KMALLOC, M_WAITOK | M_ZERO); \
+ __w->tq = taskqueue_create("lkpi kthread taskq", M_WAITOK, \
+ taskqueue_thread_enqueue, &__w->tq); \
+ taskqueue_start_threads(&__w->tq, 1, PWAIT, fmt, ##__VA_ARGS__);\
+ TASK_INIT(&__task, 0, lkpi_kthread_worker_init_fn, __w); \
+ taskqueue_enqueue(__w->tq, &__task); \
+ taskqueue_drain(__w->tq, &__task); \
+ __w; \
+})
+
+static inline void
+kthread_destroy_worker(struct kthread_worker *worker)
+{
+ taskqueue_drain_all(worker->tq);
+ taskqueue_free(worker->tq);
+ free(worker, M_KMALLOC);
+}
+
+static inline void
+kthread_init_work(struct kthread_work *work, kthread_work_func_t func)
+{
+ work->tq = NULL;
+ work->func = func;
+ TASK_INIT(&work->task, 0, lkpi_kthread_work_fn, work);
+}
+
+static inline bool
+kthread_queue_work(struct kthread_worker *worker, struct kthread_work *work)
+{
+ int error;
+
+ error = taskqueue_enqueue_flags(worker->tq, &work->task,
+ TASKQUEUE_FAIL_IF_CANCELING | TASKQUEUE_FAIL_IF_PENDING);
+ if (error == 0)
+ work->tq = worker->tq;
+ return (error == 0);
+}
+
+static inline bool
+kthread_cancel_work_sync(struct kthread_work *work)
+{
+ u_int pending = 0;
+
+ if (work->tq != NULL &&
+ taskqueue_cancel(work->tq, &work->task, &pending) != 0)
+ taskqueue_drain(work->tq, &work->task);
+
+ return (pending != 0);
+}
+
+static inline void
+kthread_flush_work(struct kthread_work *work)
+{
+ if (work->tq != NULL)
+ taskqueue_drain(work->tq, &work->task);
+}
+
+static inline void
+kthread_flush_worker(struct kthread_worker *worker)
+{
+ taskqueue_drain_all(worker->tq);
+}
+
+#endif /* _LINUXKPI_LINUX_KTHREAD_H_ */
diff --git a/sys/compat/linuxkpi/common/include/linux/ktime.h b/sys/compat/linuxkpi/common/include/linux/ktime.h
index 1475674a12e6..6a2f04f3d789 100644
--- a/sys/compat/linuxkpi/common/include/linux/ktime.h
+++ b/sys/compat/linuxkpi/common/include/linux/ktime.h
@@ -24,12 +24,10 @@
* 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.
- *
- * $FreeBSD$
*/
-#ifndef _LINUX_KTIME_H
-#define _LINUX_KTIME_H
+#ifndef _LINUXKPI_LINUX_KTIME_H
+#define _LINUXKPI_LINUX_KTIME_H
#include <linux/types.h>
#include <linux/time.h>
@@ -71,6 +69,12 @@ ktime_to_ms(ktime_t kt)
return (ktime_divns(kt, NSEC_PER_MSEC));
}
+static inline ktime_t
+ms_to_ktime(uint64_t ms)
+{
+ return (ms * NSEC_PER_MSEC);
+}
+
static inline struct timeval
ktime_to_timeval(ktime_t kt)
{
@@ -190,6 +194,7 @@ timespec64_to_ns(struct timespec64 *ts)
#define ktime_get_ts(ts) getnanouptime(ts)
#define ktime_get_ts64(ts) getnanouptime(ts)
#define ktime_get_raw_ts64(ts) getnanouptime(ts)
+#define ktime_get_real_ts64(ts) getnanotime(ts)
#define getrawmonotonic64(ts) getnanouptime(ts)
static inline int64_t
@@ -227,6 +232,13 @@ ktime_get_boottime_ns(void)
return (ktime_to_ns(ktime_get_boottime()));
}
+static inline uint64_t
+ktime_get_boottime_seconds(void)
+{
+
+ return (ktime_divns(ktime_get_boottime(), NSEC_PER_SEC));
+}
+
static inline ktime_t
ktime_get_real(void)
{
@@ -263,4 +275,13 @@ ktime_get_raw_ns(void)
return (ktime_to_ns(timespec_to_ktime(ts)));
}
-#endif /* _LINUX_KTIME_H */
+static inline uint64_t
+ktime_get_raw_fast_ns(void)
+{
+ struct timespec ts;
+
+ getnanouptime(&ts);
+ return (ktime_to_ns(timespec_to_ktime(ts)));
+}
+
+#endif /* _LINUXKPI_LINUX_KTIME_H */
diff --git a/sys/compat/linuxkpi/common/include/linux/leds.h b/sys/compat/linuxkpi/common/include/linux/leds.h
new file mode 100644
index 000000000000..89f7286f6800
--- /dev/null
+++ b/sys/compat/linuxkpi/common/include/linux/leds.h
@@ -0,0 +1,41 @@
+/*-
+ * Copyright (c) 2022 Bjoern A. Zeeb
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``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 OR CONTRIBUTORS 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.
+ */
+
+#ifndef _LINUXKPI_LINUX_LEDS_H
+#define _LINUXKPI_LINUX_LEDS_H
+
+enum led_brightness {
+ LED_OFF,
+};
+
+struct led_classdev {
+ const char *name;
+ const char *default_trigger;
+ int (*blink_set)(struct led_classdev *, unsigned long *, unsigned long *);
+ void (*brightness_set)(struct led_classdev *, enum led_brightness);
+ void (*led_set)(struct led_classdev *, enum led_brightness);
+};
+
+#endif /* _LINUXKPI_LINUX_LEDS_H */
diff --git a/sys/compat/linuxkpi/common/include/linux/limits.h b/sys/compat/linuxkpi/common/include/linux/limits.h
new file mode 100644
index 000000000000..716366033bb3
--- /dev/null
+++ b/sys/compat/linuxkpi/common/include/linux/limits.h
@@ -0,0 +1,47 @@
+/*-
+ * SPDX-License-Identifier: BSD-2-Clause
+ *
+ * Copyright (c) 2023 Serenity Cyber Security, LLC.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``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 OR CONTRIBUTORS 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.
+ */
+
+#ifndef _LINUXKPI_LINUX_LIMITS_H
+#define _LINUXKPI_LINUX_LIMITS_H
+
+#include <sys/types.h>
+#include <sys/stdint.h>
+
+#define U8_MAX UINT8_MAX
+#define S8_MAX INT8_MAX
+#define S8_MIN INT8_MIN
+#define U16_MAX UINT16_MAX
+#define S16_MAX INT16_MAX
+#define S16_MIN INT16_MIN
+#define U32_MAX UINT32_MAX
+#define S32_MAX INT32_MAX
+#define S32_MIN INT32_MIN
+#define U64_MAX UINT64_MAX
+#define S64_MAX INT64_MAX
+#define S64_MIN INT64_MIN
+
+#endif
diff --git a/sys/compat/linuxkpi/common/include/linux/list.h b/sys/compat/linuxkpi/common/include/linux/list.h
index 37b5b751d21b..a6c74a324dac 100644
--- a/sys/compat/linuxkpi/common/include/linux/list.h
+++ b/sys/compat/linuxkpi/common/include/linux/list.h
@@ -25,11 +25,9 @@
* 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.
- *
- * $FreeBSD$
*/
-#ifndef _LINUX_LIST_H_
-#define _LINUX_LIST_H_
+#ifndef _LINUXKPI_LINUX_LIST_H_
+#define _LINUXKPI_LINUX_LIST_H_
#ifndef _STANDALONE
/*
@@ -86,14 +84,6 @@
#define LINUX_LIST_HEAD(name) \
struct list_head name = LINUX_LIST_HEAD_INIT(name)
-#ifndef LIST_HEAD_DEF
-#define LIST_HEAD_DEF
-struct list_head {
- struct list_head *next;
- struct list_head *prev;
-};
-#endif
-
static inline void
INIT_LIST_HEAD(struct list_head *list)
{
@@ -154,7 +144,7 @@ list_replace_init(struct list_head *old, struct list_head *new)
}
static inline void
-linux_list_add(struct list_head *new, struct list_head *prev,
+__list_add(struct list_head *new, struct list_head *prev,
struct list_head *next)
{
@@ -235,22 +225,32 @@ list_del_init(struct list_head *entry)
#define list_for_each_prev(p, h) for (p = (h)->prev; p != (h); p = (p)->prev)
+#define list_for_each_prev_safe(p, n, h) \
+ for (p = (h)->prev, n = (p)->prev; \
+ p != (h); \
+ p = n, n = (p)->prev)
+
#define list_for_each_entry_from_reverse(p, h, field) \
for (; &p->field != (h); \
p = list_prev_entry(p, field))
+#define list_for_each_rcu(p, head) \
+ for (p = rcu_dereference((head)->next); \
+ p != (head); \
+ p = rcu_dereference((p)->next))
+
static inline void
list_add(struct list_head *new, struct list_head *head)
{
- linux_list_add(new, head, head->next);
+ __list_add(new, head, head->next);
}
static inline void
list_add_tail(struct list_head *new, struct list_head *head)
{
- linux_list_add(new, head->prev, head);
+ __list_add(new, head->prev, head);
}
static inline void
@@ -270,6 +270,13 @@ list_move_tail(struct list_head *entry, struct list_head *head)
}
static inline void
+list_rotate_to_front(struct list_head *entry, struct list_head *head)
+{
+
+ list_move_tail(entry, head);
+}
+
+static inline void
list_bulk_move_tail(struct list_head *head, struct list_head *first,
struct list_head *last)
{
@@ -467,6 +474,20 @@ static inline int list_is_last(const struct list_head *list,
return list->next == head;
}
+static inline size_t
+list_count_nodes(const struct list_head *list)
+{
+ const struct list_head *lh;
+ size_t count;
+
+ count = 0;
+ list_for_each(lh, list) {
+ count++;
+ }
+
+ return (count);
+}
+
#define hlist_entry(ptr, type, field) container_of(ptr, type, field)
#define hlist_for_each(p, head) \
@@ -497,7 +518,12 @@ static inline int list_is_last(const struct list_head *list,
(pos) && ({ n = (pos)->member.next; 1; }); \
pos = hlist_entry_safe(n, typeof(*(pos)), member))
+#if defined(LINUXKPI_VERSION) && LINUXKPI_VERSION >= 51300
+extern void list_sort(void *priv, struct list_head *head, int (*cmp)(void *priv,
+ const struct list_head *a, const struct list_head *b));
+#else
extern void list_sort(void *priv, struct list_head *head, int (*cmp)(void *priv,
struct list_head *a, struct list_head *b));
+#endif
-#endif /* _LINUX_LIST_H_ */
+#endif /* _LINUXKPI_LINUX_LIST_H_ */
diff --git a/sys/compat/linuxkpi/common/include/linux/llist.h b/sys/compat/linuxkpi/common/include/linux/llist.h
index b3c89516e710..fd842f05e9eb 100644
--- a/sys/compat/linuxkpi/common/include/linux/llist.h
+++ b/sys/compat/linuxkpi/common/include/linux/llist.h
@@ -1,7 +1,7 @@
/* Public domain. */
-#ifndef _LINUX_LLIST_H
-#define _LINUX_LLIST_H
+#ifndef _LINUXKPI_LINUX_LLIST_H
+#define _LINUXKPI_LINUX_LLIST_H
#include <sys/types.h>
#include <machine/atomic.h>
diff --git a/sys/compat/linuxkpi/common/include/linux/lockdep.h b/sys/compat/linuxkpi/common/include/linux/lockdep.h
index d12bd049b820..93fe445f7057 100644
--- a/sys/compat/linuxkpi/common/include/linux/lockdep.h
+++ b/sys/compat/linuxkpi/common/include/linux/lockdep.h
@@ -25,19 +25,21 @@
* 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.
- *
- * $FreeBSD$
*/
-#ifndef _LINUX_LOCKDEP_H_
-#define _LINUX_LOCKDEP_H_
+#ifndef _LINUXKPI_LINUX_LOCKDEP_H_
+#define _LINUXKPI_LINUX_LOCKDEP_H_
+#include <sys/systm.h>
+#include <sys/types.h>
#include <sys/lock.h>
struct lock_class_key {
};
struct lockdep_map {
};
+struct pin_cookie {
+};
#define lockdep_set_class(lock, key)
#define lockdep_set_subclass(lock, sub)
@@ -45,8 +47,18 @@ struct lockdep_map {
#define lockdep_set_current_reclaim_state(g) do { } while (0)
#define lockdep_clear_current_reclaim_state() do { } while (0)
#define lockdep_init_map(_map, _name, _key, _x) do { } while(0)
+#define lockdep_register_key(key) do { } while(0)
+#define lockdep_unregister_key(key) do { } while(0)
#ifdef INVARIANTS
+#define lockdep_assert(cond) do { WARN_ON(!(cond)); } while (0)
+#define lockdep_assert_once(cond) do { WARN_ON_ONCE(!(cond)); } while (0)
+
+#define lockdep_assert_not_held(m) do { \
+ struct lock_object *__lock = (struct lock_object *)(m); \
+ LOCK_CLASS(__lock)->lc_assert(__lock, LA_UNLOCKED); \
+} while (0)
+
#define lockdep_assert_held(m) do { \
struct lock_object *__lock = (struct lock_object *)(m); \
LOCK_CLASS(__lock)->lc_assert(__lock, LA_LOCKED); \
@@ -57,25 +69,34 @@ struct lockdep_map {
LOCK_CLASS(__lock)->lc_assert(__lock, LA_LOCKED | LA_NOTRECURSED); \
} while (0)
+#define lockdep_assert_none_held_once() do { } while (0)
+
+#else
+#define lockdep_assert(cond) do { } while (0)
+#define lockdep_assert_once(cond) do { } while (0)
+
+#define lockdep_assert_not_held(m) do { (void)(m); } while (0)
+#define lockdep_assert_held(m) do { (void)(m); } while (0)
+#define lockdep_assert_none_held_once() do { } while (0)
+
+#define lockdep_assert_held_once(m) do { (void)(m); } while (0)
+
+#endif
+
static __inline bool
-lockdep_is_held(void *__m)
+lockdep_is_held(void *__m __diagused)
{
+#ifdef INVARIANTS
struct lock_object *__lock;
struct thread *__td;
__lock = __m;
return (LOCK_CLASS(__lock)->lc_owner(__lock, &__td) != 0);
-}
-#define lockdep_is_held_type(_m, _t) lockdep_is_held(_m)
-
#else
-#define lockdep_assert_held(m) do { } while (0)
-
-#define lockdep_assert_held_once(m) do { } while (0)
-
-#define lockdep_is_held(m) 1
-#define lockdep_is_held_type(_m, _t) 1
+ return (true);
#endif
+}
+#define lockdep_is_held_type(_m, _t) lockdep_is_held(_m)
#define might_lock(m) do { } while (0)
#define might_lock_read(m) do { } while (0)
@@ -92,8 +113,8 @@ lockdep_is_held(void *__m)
#define lock_map_acquire_read(_map) do { } while (0)
#define lock_map_release(_map) do { } while (0)
-#define lockdep_pin_lock(l) do { } while (0)
-#define lockdep_repin_lock(l,c) do { } while (0)
-#define lockdep_unpin_lock(l,c) do { } while (0)
+#define lockdep_pin_lock(l) ({ struct pin_cookie __pc = { }; __pc; })
+#define lockdep_repin_lock(l,c) do { (void)(l); (void)(c); } while (0)
+#define lockdep_unpin_lock(l,c) do { (void)(l); (void)(c); } while (0)
-#endif /* _LINUX_LOCKDEP_H_ */
+#endif /* _LINUXKPI_LINUX_LOCKDEP_H_ */
diff --git a/sys/compat/linuxkpi/common/include/linux/log2.h b/sys/compat/linuxkpi/common/include/linux/log2.h
index d79eedf38176..660e9adb6fa9 100644
--- a/sys/compat/linuxkpi/common/include/linux/log2.h
+++ b/sys/compat/linuxkpi/common/include/linux/log2.h
@@ -25,107 +25,17 @@
* 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.
- *
- * $FreeBSD$
*/
-#ifndef _LINUX_LOG2_H_
-#define _LINUX_LOG2_H_
+#ifndef _LINUXKPI_LINUX_LOG2_H_
+#define _LINUXKPI_LINUX_LOG2_H_
#include <linux/types.h>
#include <sys/libkern.h>
-static inline unsigned long
-roundup_pow_of_two(unsigned long x)
-{
- return (1UL << flsl(x - 1));
-}
-
-static inline int
-is_power_of_2(unsigned long n)
-{
- return (n == roundup_pow_of_two(n));
-}
-
-static inline unsigned long
-rounddown_pow_of_two(unsigned long x)
-{
- return (1UL << (flsl(x) - 1));
-}
-
-#define ilog2(n) \
-( \
- __builtin_constant_p(n) ? ( \
- (n) < 1 ? -1 : \
- (n) & (1ULL << 63) ? 63 : \
- (n) & (1ULL << 62) ? 62 : \
- (n) & (1ULL << 61) ? 61 : \
- (n) & (1ULL << 60) ? 60 : \
- (n) & (1ULL << 59) ? 59 : \
- (n) & (1ULL << 58) ? 58 : \
- (n) & (1ULL << 57) ? 57 : \
- (n) & (1ULL << 56) ? 56 : \
- (n) & (1ULL << 55) ? 55 : \
- (n) & (1ULL << 54) ? 54 : \
- (n) & (1ULL << 53) ? 53 : \
- (n) & (1ULL << 52) ? 52 : \
- (n) & (1ULL << 51) ? 51 : \
- (n) & (1ULL << 50) ? 50 : \
- (n) & (1ULL << 49) ? 49 : \
- (n) & (1ULL << 48) ? 48 : \
- (n) & (1ULL << 47) ? 47 : \
- (n) & (1ULL << 46) ? 46 : \
- (n) & (1ULL << 45) ? 45 : \
- (n) & (1ULL << 44) ? 44 : \
- (n) & (1ULL << 43) ? 43 : \
- (n) & (1ULL << 42) ? 42 : \
- (n) & (1ULL << 41) ? 41 : \
- (n) & (1ULL << 40) ? 40 : \
- (n) & (1ULL << 39) ? 39 : \
- (n) & (1ULL << 38) ? 38 : \
- (n) & (1ULL << 37) ? 37 : \
- (n) & (1ULL << 36) ? 36 : \
- (n) & (1ULL << 35) ? 35 : \
- (n) & (1ULL << 34) ? 34 : \
- (n) & (1ULL << 33) ? 33 : \
- (n) & (1ULL << 32) ? 32 : \
- (n) & (1ULL << 31) ? 31 : \
- (n) & (1ULL << 30) ? 30 : \
- (n) & (1ULL << 29) ? 29 : \
- (n) & (1ULL << 28) ? 28 : \
- (n) & (1ULL << 27) ? 27 : \
- (n) & (1ULL << 26) ? 26 : \
- (n) & (1ULL << 25) ? 25 : \
- (n) & (1ULL << 24) ? 24 : \
- (n) & (1ULL << 23) ? 23 : \
- (n) & (1ULL << 22) ? 22 : \
- (n) & (1ULL << 21) ? 21 : \
- (n) & (1ULL << 20) ? 20 : \
- (n) & (1ULL << 19) ? 19 : \
- (n) & (1ULL << 18) ? 18 : \
- (n) & (1ULL << 17) ? 17 : \
- (n) & (1ULL << 16) ? 16 : \
- (n) & (1ULL << 15) ? 15 : \
- (n) & (1ULL << 14) ? 14 : \
- (n) & (1ULL << 13) ? 13 : \
- (n) & (1ULL << 12) ? 12 : \
- (n) & (1ULL << 11) ? 11 : \
- (n) & (1ULL << 10) ? 10 : \
- (n) & (1ULL << 9) ? 9 : \
- (n) & (1ULL << 8) ? 8 : \
- (n) & (1ULL << 7) ? 7 : \
- (n) & (1ULL << 6) ? 6 : \
- (n) & (1ULL << 5) ? 5 : \
- (n) & (1ULL << 4) ? 4 : \
- (n) & (1ULL << 3) ? 3 : \
- (n) & (1ULL << 2) ? 2 : \
- (n) & (1ULL << 1) ? 1 : \
- (n) & (1ULL << 0) ? 0 : \
- -1) : \
- (sizeof(n) <= 4) ? \
- fls((u32)(n)) - 1 : flsll((u64)(n)) - 1 \
-)
-
-#define order_base_2(x) ilog2(roundup_pow_of_two(x))
+#define is_power_of_2(n) ({ \
+ __typeof(n) _n = (n); \
+ _n != 0 && (_n & (_n - 1)) == 0; \
+})
-#endif /* _LINUX_LOG2_H_ */
+#endif /* _LINUXKPI_LINUX_LOG2_H_ */
diff --git a/sys/compat/linuxkpi/common/include/linux/math.h b/sys/compat/linuxkpi/common/include/linux/math.h
new file mode 100644
index 000000000000..1d50e011f66d
--- /dev/null
+++ b/sys/compat/linuxkpi/common/include/linux/math.h
@@ -0,0 +1,76 @@
+/*-
+ * SPDX-License-Identifier: BSD-2-Clause
+ *
+ * Copyright (c) 2013-2015 Mellanox Technologies, Ltd.
+ * Copyright (c) 2014-2015 François Tigeot
+ * Copyright (c) 2016 Matt Macy <mmacy@FreeBSD.org>
+ * Copyright (c) 2019 Johannes Lundberg <johalun@FreeBSD.org>
+ * Copyright (c) 2023 Serenity Cyber Security, LLC.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``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 OR CONTRIBUTORS 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.
+ */
+
+#ifndef _LINUXKPI_LINUX_MATH_H_
+#define _LINUXKPI_LINUX_MATH_H_
+
+#include <linux/types.h>
+
+/*
+ * This looks more complex than it should be. But we need to
+ * get the type for the ~ right in round_down (it needs to be
+ * as wide as the result!), and we want to evaluate the macro
+ * arguments just once each.
+ */
+#define __round_mask(x, y) ((__typeof__(x))((y)-1))
+#define round_up(x, y) ((((x)-1) | __round_mask(x, y))+1)
+#define round_down(x, y) ((x) & ~__round_mask(x, y))
+
+#define DIV_ROUND_UP(x, n) howmany(x, n)
+#define DIV_ROUND_UP_ULL(x, n) DIV_ROUND_UP((unsigned long long)(x), (n))
+#define DIV_ROUND_DOWN_ULL(x, n) ((unsigned long long)(x) / (n))
+
+#define DIV_ROUND_CLOSEST(x, divisor) (((x) + ((divisor) / 2)) / (divisor))
+#define DIV_ROUND_CLOSEST_ULL(x, divisor) ({ \
+ __typeof(divisor) __d = (divisor); \
+ unsigned long long __ret = (x) + (__d) / 2; \
+ __ret /= __d; \
+ __ret; \
+})
+
+#if !defined(LINUXKPI_VERSION) || (LINUXKPI_VERSION >= 60600)
+#define abs_diff(x, y) ({ \
+ __typeof(x) _x = (x); \
+ __typeof(y) _y = (y); \
+ _x > _y ? _x - _y : _y - _x; \
+})
+#endif
+
+static inline uintmax_t
+mult_frac(uintmax_t x, uintmax_t multiplier, uintmax_t divisor)
+{
+ uintmax_t q = (x / divisor);
+ uintmax_t r = (x % divisor);
+
+ return ((q * multiplier) + ((r * multiplier) / divisor));
+}
+
+#endif /* _LINUXKPI_LINUX_MATH_H_ */
diff --git a/sys/compat/linuxkpi/common/include/linux/math64.h b/sys/compat/linuxkpi/common/include/linux/math64.h
index a3af81c92c9e..25ca9da1b622 100644
--- a/sys/compat/linuxkpi/common/include/linux/math64.h
+++ b/sys/compat/linuxkpi/common/include/linux/math64.h
@@ -23,14 +23,13 @@
* 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.
- *
- * $FreeBSD$
*/
-#ifndef _LINUX_MATH64_H
-#define _LINUX_MATH64_H
+#ifndef _LINUXKPI_LINUX_MATH64_H
+#define _LINUXKPI_LINUX_MATH64_H
#include <sys/stdint.h>
+#include <sys/systm.h>
#define do_div(n, base) ({ \
uint32_t __base = (base); \
@@ -62,6 +61,8 @@ div64_u64(uint64_t dividend, uint64_t divisor)
return (dividend / divisor);
}
+#define div64_ul(x, y) div64_u64((x), (y))
+
static inline uint64_t
div_u64_rem(uint64_t dividend, uint32_t divisor, uint32_t *remainder)
{
@@ -97,7 +98,80 @@ div64_u64_round_up(uint64_t dividend, uint64_t divisor)
return ((dividend + divisor - 1) / divisor);
}
+static inline uint64_t
+roundup_u64(uint64_t x1, uint32_t x2)
+{
+ return (div_u64(x1 + x2 - 1, x2) * x2);
+}
+
#define DIV64_U64_ROUND_UP(...) \
div64_u64_round_up(__VA_ARGS__)
-#endif /* _LINUX_MATH64_H */
+static inline uint64_t
+mul_u64_u32_div(uint64_t x, uint32_t y, uint32_t div)
+{
+ const uint64_t rem = x % div;
+
+ return ((x / div) * y + (rem * y) / div);
+}
+
+static inline uint64_t
+mul_u64_u64_div_u64(uint64_t x, uint64_t y, uint64_t z)
+{
+ uint64_t res, rem;
+ uint64_t x1, y1, y1z;
+
+ res = rem = 0;
+ x1 = x;
+ y1z = y / z;
+ y1 = y - y1z * z;
+
+ /*
+ * INVARIANT: x * y = res * z + rem + (y1 + y1z * z) * x1
+ * INVARIANT: y1 < z
+ * INVARIANT: rem < z
+ */
+ while (x1 > 0) {
+ /* Handle low bit. */
+ if (x1 & 1) {
+ x1 &= ~1;
+ res += y1z;
+ rem += y1;
+ if ((rem < y1) || (rem >= z)) {
+ res += 1;
+ rem -= z;
+ }
+ }
+
+ /* Shift x1 right and (y1 + y1z * z) left */
+ x1 >>= 1;
+ if ((y1 * 2 < y1) || (y1 * 2 >= z)) {
+ y1z = y1z * 2 + 1;
+ y1 = y1 * 2 - z;
+ } else {
+ y1z *= 2;
+ y1 *= 2;
+ }
+ }
+
+ KASSERT(res * z + rem == x * y, ("%s: res %ju * z %ju + rem %ju != "
+ "x %ju * y %ju", __func__, (uintmax_t)res, (uintmax_t)z,
+ (uintmax_t)rem, (uintmax_t)x, (uintmax_t)y));
+ KASSERT(rem < z, ("%s: rem %ju >= z %ju\n", __func__,
+ (uintmax_t)rem, (uintmax_t)z));
+
+ return (res);
+}
+
+static inline uint64_t
+mul_u64_u32_shr(uint64_t x, uint32_t y, unsigned int shift)
+{
+ uint32_t hi, lo;
+ hi = x >> 32;
+ lo = x & 0xffffffff;
+
+ return (mul_u32_u32(lo, y) >> shift) +
+ (mul_u32_u32(hi, y) << (32 - shift));
+}
+
+#endif /* _LINUXKPI_LINUX_MATH64_H */
diff --git a/sys/compat/linuxkpi/common/include/linux/media-bus-format.h b/sys/compat/linuxkpi/common/include/linux/media-bus-format.h
new file mode 100644
index 000000000000..1e1954d45409
--- /dev/null
+++ b/sys/compat/linuxkpi/common/include/linux/media-bus-format.h
@@ -0,0 +1,8 @@
+/* Public domain. */
+
+#ifndef _LINUXKPI_LINUX_MEDIA_BUS_FORMAT_H_
+#define _LINUXKPI_LINUX_MEDIA_BUS_FORMAT_H_
+
+#define MEDIA_BUS_FMT_FIXED 1
+
+#endif /* _LINUXKPI_LINUX_MEDIA_BUS_FORMAT_H_ */
diff --git a/sys/compat/linuxkpi/common/include/linux/mhi.h b/sys/compat/linuxkpi/common/include/linux/mhi.h
new file mode 100644
index 000000000000..24b3205d6f5a
--- /dev/null
+++ b/sys/compat/linuxkpi/common/include/linux/mhi.h
@@ -0,0 +1,222 @@
+/*-
+ * SPDX-License-Identifier: BSD-2-Clause
+ *
+ * Copyright (c) 2022-2023 Bjoern A. Zeeb
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``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 OR CONTRIBUTORS 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.
+ */
+
+#ifndef _LINUXKPI_LINUX_MHI_H
+#define _LINUXKPI_LINUX_MHI_H
+
+#include <linux/types.h>
+
+/* Modem Host Interface (MHI) */
+
+/* XXX FIXME */
+#define MHI_DB_BRST_DISABLE 0
+#define MHI_ER_CTRL 0
+
+enum mhi_callback {
+ MHI_CB_SYS_ERROR,
+ MHI_CB_BW_REQ,
+ MHI_CB_EE_MISSION_MODE,
+ MHI_CB_EE_RDDM,
+ MHI_CB_FATAL_ERROR,
+ MHI_CB_IDLE,
+ MHI_CB_LPM_ENTER,
+ MHI_CB_LPM_EXIT,
+ MHI_CB_PENDING_DATA,
+};
+
+struct mhi_channel_config {
+ const char *name;
+ int auto_queue, dir, doorbell, doorbell_mode_switch, ee_mask, event_ring, lpm_notify, num, num_elements, offload_channel, pollcfg;
+};
+
+struct mhi_event_config {
+ int client_managed, data_type, hardware_event, irq, irq_moderation_ms, mode, num_elements, offload_channel, priority;
+};
+
+struct mhi_device {
+};
+
+struct mhi_controller_config {
+ const struct mhi_channel_config *ch_cfg;
+ struct mhi_event_config *event_cfg;
+
+ int buf_len, max_channels, num_channels, num_events, use_bounce_buf;
+
+ uint32_t timeout_ms;
+};
+
+struct mhi_controller {
+ struct device *cntrl_dev;
+ struct mhi_device *mhi_dev;
+ void *regs;
+ int *irq;
+ const char *fw_image;
+ const u8 *fw_data;
+ size_t fw_sz;
+
+ bool fbc_download;
+ size_t rddm_size;
+ size_t sbl_size;
+ size_t seg_len;
+ size_t reg_len;
+ int nr_irqs;
+ unsigned long irq_flags;
+ uint32_t timeout_ms;
+
+ dma_addr_t iova_start;
+ dma_addr_t iova_stop;
+
+ int (*runtime_get)(struct mhi_controller *);
+ void (*runtime_put)(struct mhi_controller *);
+ void (*status_cb)(struct mhi_controller *, enum mhi_callback);
+ int (*read_reg)(struct mhi_controller *, void __iomem *, uint32_t *);
+ void (*write_reg)(struct mhi_controller *, void __iomem *, uint32_t);
+};
+
+/* -------------------------------------------------------------------------- */
+
+struct mhi_controller *linuxkpi_mhi_alloc_controller(void);
+void linuxkpi_mhi_free_controller(struct mhi_controller *);
+int linuxkpi_mhi_register_controller(struct mhi_controller *,
+ const struct mhi_controller_config *);
+void linuxkpi_mhi_unregister_controller(struct mhi_controller *);
+
+/* -------------------------------------------------------------------------- */
+
+static inline struct mhi_controller *
+mhi_alloc_controller(void)
+{
+
+ /* Keep allocations internal to our implementation. */
+ return (linuxkpi_mhi_alloc_controller());
+}
+
+static inline void
+mhi_free_controller(struct mhi_controller *mhi_ctrl)
+{
+
+ linuxkpi_mhi_free_controller(mhi_ctrl);
+}
+
+static inline int
+mhi_register_controller(struct mhi_controller *mhi_ctrl,
+ const struct mhi_controller_config *cfg)
+{
+
+ return (linuxkpi_mhi_register_controller(mhi_ctrl, cfg));
+}
+
+static inline void
+mhi_unregister_controller(struct mhi_controller *mhi_ctrl)
+{
+
+ linuxkpi_mhi_unregister_controller(mhi_ctrl);
+}
+
+/* -------------------------------------------------------------------------- */
+
+static __inline int
+mhi_device_get_sync(struct mhi_device *mhi_dev)
+{
+ /* XXX TODO */
+ return (-1);
+}
+
+static __inline void
+mhi_device_put(struct mhi_device *mhi_dev)
+{
+ /* XXX TODO */
+}
+
+/* -------------------------------------------------------------------------- */
+
+static __inline int
+mhi_prepare_for_power_up(struct mhi_controller *mhi_ctrl)
+{
+ /* XXX TODO */
+ return (0);
+}
+
+static __inline int
+mhi_sync_power_up(struct mhi_controller *mhi_ctrl)
+{
+ /* XXX TODO */
+ return (0);
+}
+
+static __inline int
+mhi_async_power_up(struct mhi_controller *mhi_ctrl)
+{
+ /* XXX TODO */
+ return (0);
+}
+
+static __inline void
+mhi_power_down(struct mhi_controller *mhi_ctrl, bool x)
+{
+ /* XXX TODO */
+}
+
+static __inline void
+mhi_unprepare_after_power_down(struct mhi_controller *mhi_ctrl)
+{
+ /* XXX TODO */
+}
+
+/* -------------------------------------------------------------------------- */
+
+static __inline int
+mhi_pm_suspend(struct mhi_controller *mhi_ctrl)
+{
+ /* XXX TODO */
+ return (0);
+}
+
+static __inline int
+mhi_pm_resume(struct mhi_controller *mhi_ctrl)
+{
+ /* XXX TODO */
+ return (0);
+}
+
+static __inline int
+mhi_pm_resume_force(struct mhi_controller *mhi_ctrl)
+{
+ /* XXX TODO */
+ return (0);
+}
+
+/* -------------------------------------------------------------------------- */
+
+static __inline int
+mhi_force_rddm_mode(struct mhi_controller *mhi_ctrl)
+{
+ /* XXX TODO */
+ return (0);
+}
+
+#endif /* _LINUXKPI_LINUX_MHI_H */
diff --git a/sys/compat/linuxkpi/common/include/linux/minmax.h b/sys/compat/linuxkpi/common/include/linux/minmax.h
new file mode 100644
index 000000000000..d48958f0899f
--- /dev/null
+++ b/sys/compat/linuxkpi/common/include/linux/minmax.h
@@ -0,0 +1,74 @@
+/*-
+ * SPDX-License-Identifier: BSD-2-Clause
+ *
+ * Copyright (c) 2010 iX Systems, Inc.
+ * Copyright (c) 2010 Panasas, Inc.
+ * Copyright (c) 2013-2015 Mellanox Technologies, Ltd.
+ * Copyright (c) 2014-2015 François Tigeot
+ * Copyright (c) 2015 Hans Petter Selasky <hselasky@FreeBSD.org>
+ * Copyright (c) 2016 Matt Macy <mmacy@FreeBSD.org>
+ * Copyright (c) 2023 Serenity Cyber Security, LLC.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``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 OR CONTRIBUTORS 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.
+ */
+
+#ifndef _LINUXKPI_LINUX_MINMAX_H_
+#define _LINUXKPI_LINUX_MINMAX_H_
+
+#include <linux/build_bug.h>
+#include <linux/compiler.h>
+#include <linux/types.h>
+
+#define min(x, y) ((x) < (y) ? (x) : (y))
+#define max(x, y) ((x) > (y) ? (x) : (y))
+
+#define min3(a, b, c) min(a, min(b, c))
+#define max3(a, b, c) max(a, max(b, c))
+
+#define min_not_zero(x, y) ({ \
+ __typeof(x) __min1 = (x); \
+ __typeof(y) __min2 = (y); \
+ __min1 == 0 ? __min2 : ((__min2 == 0) ? __min1 : min(__min1, __min2));\
+})
+
+#define min_t(type, x, y) ({ \
+ type __min1 = (x); \
+ type __min2 = (y); \
+ __min1 < __min2 ? __min1 : __min2; })
+
+#define max_t(type, x, y) ({ \
+ type __max1 = (x); \
+ type __max2 = (y); \
+ __max1 > __max2 ? __max1 : __max2; })
+
+#define clamp_t(type, _x, min, max) min_t(type, max_t(type, _x, min), max)
+#define clamp(x, lo, hi) min(max(x, lo), hi)
+#define clamp_val(val, lo, hi) clamp_t(typeof(val), val, lo, hi)
+
+/* Swap values of a and b */
+#define swap(a, b) do { \
+ __typeof(a) _swap_tmp = a; \
+ a = b; \
+ b = _swap_tmp; \
+} while (0)
+
+#endif /* _LINUXKPI_LINUX_MINMAX_H_ */
diff --git a/sys/compat/linuxkpi/common/include/linux/miscdevice.h b/sys/compat/linuxkpi/common/include/linux/miscdevice.h
index 26a4a2c049c1..c66006a6b78e 100644
--- a/sys/compat/linuxkpi/common/include/linux/miscdevice.h
+++ b/sys/compat/linuxkpi/common/include/linux/miscdevice.h
@@ -25,11 +25,9 @@
* 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.
- *
- * $FreeBSD$
*/
-#ifndef _LINUX_MISCDEVICE_H_
-#define _LINUX_MISCDEVICE_H_
+#ifndef _LINUXKPI_LINUX_MISCDEVICE_H_
+#define _LINUXKPI_LINUX_MISCDEVICE_H_
#define MISC_DYNAMIC_MINOR -1
@@ -73,4 +71,4 @@ misc_deregister(struct miscdevice *misc)
return (0);
}
-#endif /* _LINUX_MISCDEVICE_H_ */
+#endif /* _LINUXKPI_LINUX_MISCDEVICE_H_ */
diff --git a/sys/compat/linuxkpi/common/include/linux/mm.h b/sys/compat/linuxkpi/common/include/linux/mm.h
index 00583937318b..156b00a0c0f0 100644
--- a/sys/compat/linuxkpi/common/include/linux/mm.h
+++ b/sys/compat/linuxkpi/common/include/linux/mm.h
@@ -27,18 +27,21 @@
* 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.
- *
- * $FreeBSD$
*/
-#ifndef _LINUX_MM_H_
-#define _LINUX_MM_H_
+#ifndef _LINUXKPI_LINUX_MM_H_
+#define _LINUXKPI_LINUX_MM_H_
#include <linux/spinlock.h>
#include <linux/gfp.h>
#include <linux/kernel.h>
#include <linux/mm_types.h>
+#include <linux/mmzone.h>
#include <linux/pfn.h>
#include <linux/list.h>
+#include <linux/mmap_lock.h>
+#include <linux/overflow.h>
+#include <linux/shrinker.h>
+#include <linux/page.h>
#include <asm/pgtable.h>
@@ -54,6 +57,8 @@ CTASSERT((VM_PROT_ALL & -(1 << 8)) == 0);
#define VM_WRITE VM_PROT_WRITE
#define VM_EXEC VM_PROT_EXECUTE
+#define VM_ACCESS_FLAGS (VM_READ | VM_WRITE | VM_EXEC)
+
#define VM_PFNINTERNAL (1 << 8) /* FreeBSD private flag to vm_insert_pfn() */
#define VM_MIXEDMAP (1 << 9)
#define VM_NORESERVE (1 << 10)
@@ -142,11 +147,28 @@ struct vm_operations_struct {
};
struct sysinfo {
- uint64_t totalram;
- uint64_t totalhigh;
- uint32_t mem_unit;
+ uint64_t totalram; /* Total usable main memory size */
+ uint64_t freeram; /* Available memory size */
+ uint64_t totalhigh; /* Total high memory size */
+ uint64_t freehigh; /* Available high memory size */
+ uint32_t mem_unit; /* Memory unit size in bytes */
};
+static inline struct page *
+virt_to_head_page(const void *p)
+{
+
+ return (virt_to_page(p));
+}
+
+static inline struct folio *
+virt_to_folio(const void *p)
+{
+ struct page *page = virt_to_page(p);
+
+ return (page_folio(page));
+}
+
/*
* Compute log2 of the power of two rounded up count of pages
* needed for size bytes.
@@ -165,6 +187,14 @@ get_order(unsigned long size)
return (order);
}
+/*
+ * Resolve a page into a virtual address:
+ *
+ * NOTE: This function only works for pages allocated by the kernel.
+ */
+void *linux_page_address(const struct page *);
+#define page_address(page) linux_page_address(page)
+
static inline void *
lowmem_page_address(struct page *page)
{
@@ -216,11 +246,15 @@ apply_to_page_range(struct mm_struct *mm, unsigned long address,
int zap_vma_ptes(struct vm_area_struct *vma, unsigned long address,
unsigned long size);
+int lkpi_remap_pfn_range(struct vm_area_struct *vma,
+ unsigned long start_addr, unsigned long start_pfn, unsigned long size,
+ pgprot_t prot);
+
static inline int
remap_pfn_range(struct vm_area_struct *vma, unsigned long addr,
unsigned long pfn, unsigned long size, pgprot_t prot)
{
- return (-ENOTSUP);
+ return (lkpi_remap_pfn_range(vma, addr, pfn, size, prot));
}
static inline unsigned long
@@ -232,44 +266,114 @@ vma_pages(struct vm_area_struct *vma)
#define offset_in_page(off) ((unsigned long)(off) & (PAGE_SIZE - 1))
static inline void
-set_page_dirty(struct vm_page *page)
+set_page_dirty(struct page *page)
{
vm_page_dirty(page);
}
static inline void
-mark_page_accessed(struct vm_page *page)
+mark_page_accessed(struct page *page)
{
vm_page_reference(page);
}
static inline void
-get_page(struct vm_page *page)
+get_page(struct page *page)
{
vm_page_wire(page);
}
+static inline void
+put_page(struct page *page)
+{
+ /* `__free_page()` takes care of the refcounting (unwire). */
+ __free_page(page);
+}
+
+static inline void
+folio_get(struct folio *folio)
+{
+ get_page(&folio->page);
+}
+
+static inline void
+folio_put(struct folio *folio)
+{
+ put_page(&folio->page);
+}
+
+/*
+ * Linux uses the following "transparent" union so that `release_pages()`
+ * accepts both a list of `struct page` or a list of `struct folio`. This
+ * relies on the fact that a `struct folio` can be cast to a `struct page`.
+ */
+typedef union {
+ struct page **pages;
+ struct folio **folios;
+} release_pages_arg __attribute__ ((__transparent_union__));
+
+void linux_release_pages(release_pages_arg arg, int nr);
+#define release_pages(arg, nr) linux_release_pages((arg), (nr))
+
extern long
-get_user_pages(unsigned long start, unsigned long nr_pages,
- int gup_flags, struct page **,
- struct vm_area_struct **);
+lkpi_get_user_pages(unsigned long start, unsigned long nr_pages,
+ unsigned int gup_flags, struct page **);
+#if defined(LINUXKPI_VERSION) && LINUXKPI_VERSION >= 60500
+#define get_user_pages(start, nr_pages, gup_flags, pages) \
+ lkpi_get_user_pages(start, nr_pages, gup_flags, pages)
+#else
+#define get_user_pages(start, nr_pages, gup_flags, pages, vmas) \
+ lkpi_get_user_pages(start, nr_pages, gup_flags, pages)
+#endif
+
+#if defined(LINUXKPI_VERSION) && LINUXKPI_VERSION >= 60500
+static inline long
+pin_user_pages(unsigned long start, unsigned long nr_pages,
+ unsigned int gup_flags, struct page **pages)
+{
+ return (get_user_pages(start, nr_pages, gup_flags, pages));
+}
+#else
+static inline long
+pin_user_pages(unsigned long start, unsigned long nr_pages,
+ unsigned int gup_flags, struct page **pages,
+ struct vm_area_struct **vmas)
+{
+ return (get_user_pages(start, nr_pages, gup_flags, pages, vmas));
+}
+#endif
extern int
__get_user_pages_fast(unsigned long start, int nr_pages, int write,
struct page **);
+static inline int
+pin_user_pages_fast(unsigned long start, int nr_pages,
+ unsigned int gup_flags, struct page **pages)
+{
+ return __get_user_pages_fast(
+ start, nr_pages, !!(gup_flags & FOLL_WRITE), pages);
+}
+
extern long
get_user_pages_remote(struct task_struct *, struct mm_struct *,
unsigned long start, unsigned long nr_pages,
- int gup_flags, struct page **,
+ unsigned int gup_flags, struct page **,
struct vm_area_struct **);
-static inline void
-put_page(struct vm_page *page)
+static inline long
+pin_user_pages_remote(struct task_struct *task, struct mm_struct *mm,
+ unsigned long start, unsigned long nr_pages,
+ unsigned int gup_flags, struct page **pages,
+ struct vm_area_struct **vmas)
{
- vm_page_unwire(page, PQ_ACTIVE);
+ return get_user_pages_remote(
+ task, mm, start, nr_pages, gup_flags, pages, vmas);
}
+#define unpin_user_page(page) put_page(page)
+#define unpin_user_pages(pages, npages) release_pages(pages, npages)
+
#define copy_highpage(to, from) pmap_copy_page(from, to)
static inline pgprot_t
@@ -278,7 +382,19 @@ vm_get_page_prot(unsigned long vm_flags)
return (vm_flags & VM_PROT_ALL);
}
-static inline vm_page_t
+static inline void
+vm_flags_set(struct vm_area_struct *vma, unsigned long flags)
+{
+ vma->vm_flags |= flags;
+}
+
+static inline void
+vm_flags_clear(struct vm_area_struct *vma, unsigned long flags)
+{
+ vma->vm_flags &= ~flags;
+}
+
+static inline struct page *
vmalloc_to_page(const void *addr)
{
vm_paddr_t paddr;
@@ -287,13 +403,77 @@ vmalloc_to_page(const void *addr)
return (PHYS_TO_VM_PAGE(paddr));
}
+static inline int
+trylock_page(struct page *page)
+{
+ return (vm_page_tryxbusy(page));
+}
+
+static inline void
+unlock_page(struct page *page)
+{
+
+ vm_page_xunbusy(page);
+}
+
extern int is_vmalloc_addr(const void *addr);
void si_meminfo(struct sysinfo *si);
+static inline unsigned long
+totalram_pages(void)
+{
+ return ((unsigned long)physmem);
+}
+
#define unmap_mapping_range(...) lkpi_unmap_mapping_range(__VA_ARGS__)
void lkpi_unmap_mapping_range(void *obj, loff_t const holebegin __unused,
loff_t const holelen, int even_cows __unused);
#define PAGE_ALIGNED(p) __is_aligned(p, PAGE_SIZE)
-#endif /* _LINUX_MM_H_ */
+void vma_set_file(struct vm_area_struct *vma, struct linux_file *file);
+
+static inline void
+might_alloc(gfp_t gfp_mask __unused)
+{
+}
+
+#define is_cow_mapping(flags) (false)
+
+static inline bool
+want_init_on_free(void)
+{
+ return (false);
+}
+
+static inline unsigned long
+folio_pfn(struct folio *folio)
+{
+ return (page_to_pfn(&folio->page));
+}
+
+static inline long
+folio_nr_pages(struct folio *folio)
+{
+ return (1);
+}
+
+static inline size_t
+folio_size(struct folio *folio)
+{
+ return (PAGE_SIZE);
+}
+
+static inline void
+folio_mark_dirty(struct folio *folio)
+{
+ set_page_dirty(&folio->page);
+}
+
+static inline void *
+folio_address(const struct folio *folio)
+{
+ return (page_address(&folio->page));
+}
+
+#endif /* _LINUXKPI_LINUX_MM_H_ */
diff --git a/sys/compat/linuxkpi/common/include/linux/mm_types.h b/sys/compat/linuxkpi/common/include/linux/mm_types.h
index 4c9eddf500d6..3ea68e97004c 100644
--- a/sys/compat/linuxkpi/common/include/linux/mm_types.h
+++ b/sys/compat/linuxkpi/common/include/linux/mm_types.h
@@ -22,15 +22,14 @@
* 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.
- *
- * $FreeBSD$
*/
-#ifndef _LINUX_MM_TYPES_H_
-#define _LINUX_MM_TYPES_H_
+#ifndef _LINUXKPI_LINUX_MM_TYPES_H_
+#define _LINUXKPI_LINUX_MM_TYPES_H_
#include <linux/types.h>
#include <linux/page.h>
+#include <linux/rbtree.h>
#include <linux/rwsem.h>
#include <asm/atomic.h>
@@ -45,6 +44,7 @@ struct mm_struct {
atomic_t mm_count;
atomic_t mm_users;
size_t pinned_vm;
+ /* Renamed to mmap_lock in v5.8 */
struct rw_semaphore mmap_sem;
};
@@ -79,4 +79,15 @@ mmgrab(struct mm_struct *mm)
extern struct mm_struct *linux_get_task_mm(struct task_struct *);
#define get_task_mm(task) linux_get_task_mm(task)
-#endif /* _LINUX_MM_TYPES_H_ */
+struct folio {
+ /*
+ * The page member must be at the beginning because `page_folio(p)`
+ * casts from a `struct page` to a `struct folio`.
+ *
+ * `release_pages()` also relies on this to be able to accept either a
+ * list of `struct page` or a list of `struct folio`.
+ */
+ struct page page;
+};
+
+#endif /* _LINUXKPI_LINUX_MM_TYPES_H_ */
diff --git a/sys/compat/linuxkpi/common/include/linux/mman.h b/sys/compat/linuxkpi/common/include/linux/mman.h
new file mode 100644
index 000000000000..eff80759b4cd
--- /dev/null
+++ b/sys/compat/linuxkpi/common/include/linux/mman.h
@@ -0,0 +1,38 @@
+/*-
+ * SPDX-License-Identifier: BSD-2-Clause
+ *
+ * Copyright (c) 2022 Jean-Sébastien Pédron <dumbbell@FreeBSD.org>
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are
+ * met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in
+ * the documentation and/or other materials provided with the
+ * distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``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 OR CONTRIBUTORS 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.
+ */
+
+#ifndef _LINUX_MMAN_H
+#define _LINUX_MMAN_H
+
+/*
+ * In Linux, <linux/mman.h> includes <linux/percpu_counter.h>, which includes
+ * <linux/smp.h>.
+ */
+#include <linux/smp.h>
+
+#endif /* _LINUX_MMAN_H */
diff --git a/sys/compat/linuxkpi/common/include/linux/mmap_lock.h b/sys/compat/linuxkpi/common/include/linux/mmap_lock.h
new file mode 100644
index 000000000000..de6b2a029b1f
--- /dev/null
+++ b/sys/compat/linuxkpi/common/include/linux/mmap_lock.h
@@ -0,0 +1,54 @@
+/*-
+ * Copyright (c) 2022 Beckhoff Automation GmbH & Co. KG
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``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 OR CONTRIBUTORS 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.
+ *
+ */
+
+#ifndef _LINUXKPI_LINUX_MMAP_LOCK_H_
+#define _LINUXKPI_LINUX_MMAP_LOCK_H_
+
+#include <linux/mm_types.h>
+#include <linux/rwsem.h>
+
+static inline void
+mmap_read_lock(struct mm_struct *mm)
+{
+
+ down_read(&mm->mmap_sem);
+}
+
+static inline void
+mmap_read_unlock(struct mm_struct *mm)
+{
+
+ up_read(&mm->mmap_sem);
+}
+
+static inline void
+mmap_write_lock_killable(struct mm_struct *mm)
+{
+
+ down_write_killable(&mm->mmap_sem);
+}
+
+#endif /* _LINUXKPI_LINUX_MMAP_LOCK_H_ */
diff --git a/sys/compat/linuxkpi/common/include/linux/mmu_context.h b/sys/compat/linuxkpi/common/include/linux/mmu_context.h
new file mode 100644
index 000000000000..4c1bc61b3edb
--- /dev/null
+++ b/sys/compat/linuxkpi/common/include/linux/mmu_context.h
@@ -0,0 +1,43 @@
+/*-
+ * Copyright (c) 2018 Johannes Lundberg <johalun0@gmail.com>
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice unmodified, this list of conditions, and the following
+ * disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``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.
+ */
+
+#ifndef _LINUXKPI_LINUX_MMU_CONTEXT_H_
+#define _LINUXKPI_LINUX_MMU_CONTEXT_H_
+
+struct mm_struct;
+
+static inline void
+use_mm(struct mm_struct *mm)
+{
+ /* NOP is deliberate */
+}
+
+static inline void
+unuse_mm(struct mm_struct *mm)
+{
+ /* NOP is deliberate */
+}
+
+#endif /* _LINUXKPI_LINUX_MMU_CONTEXT_H_ */
diff --git a/sys/compat/linux/linux_sysproto.h b/sys/compat/linuxkpi/common/include/linux/mmu_notifier.h
index cc392fb1b5ea..2492a6a3bd4f 100644
--- a/sys/compat/linux/linux_sysproto.h
+++ b/sys/compat/linuxkpi/common/include/linux/mmu_notifier.h
@@ -1,20 +1,16 @@
/*-
- * SPDX-License-Identifier: BSD-3-Clause
- *
- * Copyright (c) 2005 Travis Poppe
+ * Copyright (c) 2017 Mark Johnston <markj@FreeBSD.org>
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer
- * in this position and unchanged.
+ * notice unmodified, this list of conditions, and the following
+ * disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
- * 3. The name of the author may not be used to endorse or promote products
- * derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
@@ -26,13 +22,12 @@
* 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.
- *
- * $FreeBSD$
*/
-#ifndef LINUX_SYSPROTO
-#define LINUX_SYSPROTO
+#ifndef _LINUXKPI_LINUX_MMU_NOTIFIER_H_
+#define _LINUXKPI_LINUX_MMU_NOTIFIER_H_
-int linux_nosys(struct thread *, struct nosys_args *);
+struct mmu_notifier {
+};
-#endif
+#endif /* _LINUXKPI_LINUX_MMU_NOTIFIER_H_ */
diff --git a/sys/compat/linuxkpi/common/include/linux/mmzone.h b/sys/compat/linuxkpi/common/include/linux/mmzone.h
new file mode 100644
index 000000000000..57d3dcac9597
--- /dev/null
+++ b/sys/compat/linuxkpi/common/include/linux/mmzone.h
@@ -0,0 +1,15 @@
+/* Public domain. */
+
+#ifndef _LINUX_MMZONE_H
+#define _LINUX_MMZONE_H
+
+#include <linux/mm_types.h>
+#include <linux/numa.h>
+#include <linux/page-flags.h>
+
+#define MAX_ORDER 11
+
+#define MAX_PAGE_ORDER 10
+#define NR_PAGE_ORDERS (MAX_PAGE_ORDER + 1)
+
+#endif
diff --git a/sys/compat/linuxkpi/common/include/linux/mod_devicetable.h b/sys/compat/linuxkpi/common/include/linux/mod_devicetable.h
index f2a913bc6346..87bd6ec24bce 100644
--- a/sys/compat/linuxkpi/common/include/linux/mod_devicetable.h
+++ b/sys/compat/linuxkpi/common/include/linux/mod_devicetable.h
@@ -24,23 +24,27 @@
* 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.
- *
- * $FreeBSD$
*/
-#ifndef __LINUX_MOD_DEVICETABLE_H__
-#define __LINUX_MOD_DEVICETABLE_H__
+#ifndef __LINUXKPI_LINUX_MOD_DEVICETABLE_H__
+#define __LINUXKPI_LINUX_MOD_DEVICETABLE_H__
+
+#include <linux/types.h>
enum dmi_field {
DMI_NONE,
DMI_BIOS_VENDOR,
DMI_BIOS_VERSION,
DMI_BIOS_DATE,
+ DMI_BIOS_RELEASE,
+ DMI_EC_FIRMWARE_RELEASE,
DMI_SYS_VENDOR,
DMI_PRODUCT_NAME,
DMI_PRODUCT_VERSION,
DMI_PRODUCT_SERIAL,
DMI_PRODUCT_UUID,
+ DMI_PRODUCT_SKU,
+ DMI_PRODUCT_FAMILY,
DMI_BOARD_VENDOR,
DMI_BOARD_NAME,
DMI_BOARD_VERSION,
@@ -52,10 +56,12 @@ enum dmi_field {
DMI_CHASSIS_SERIAL,
DMI_CHASSIS_ASSET_TAG,
DMI_STRING_MAX,
+ DMI_OEM_STRING,
};
struct dmi_strmatch {
- unsigned char slot;
+ unsigned char slot : 7;
+ unsigned char exact_match : 1;
char substr[79];
};
@@ -67,6 +73,11 @@ struct dmi_system_id {
};
#define DMI_MATCH(a, b) { .slot = a, .substr = b }
-#define DMI_EXACT_MATCH(a, b) { .slot = a, .substr = b, }
+#define DMI_EXACT_MATCH(a, b) { .slot = a, .substr = b, .exact_match = 1 }
+
+#define I2C_NAME_SIZE 20
+#define I2C_MODULE_PREFIX "i2c:"
+
+#define ACPI_ID_LEN 16
-#endif /* __LINUX_MOD_DEVICETABLE_H__ */
+#endif /* __LINUXKPI_LINUX_MOD_DEVICETABLE_H__ */
diff --git a/sys/compat/linuxkpi/common/include/linux/module.h b/sys/compat/linuxkpi/common/include/linux/module.h
index 2a4fdc5a11a9..079dacf8df6c 100644
--- a/sys/compat/linuxkpi/common/include/linux/module.h
+++ b/sys/compat/linuxkpi/common/include/linux/module.h
@@ -25,15 +25,15 @@
* 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.
- *
- * $FreeBSD$
*/
-#ifndef _LINUX_MODULE_H_
-#define _LINUX_MODULE_H_
+#ifndef _LINUXKPI_LINUX_MODULE_H_
+#define _LINUXKPI_LINUX_MODULE_H_
-#include <sys/cdefs.h>
#include <sys/types.h>
+#include <sys/param.h>
#include <sys/module.h>
+#include <sys/queue.h>
+#include <sys/linker.h>
#include <linux/list.h>
#include <linux/compiler.h>
@@ -51,8 +51,28 @@
#define MODULE_INFO(tag, info)
#define MODULE_FIRMWARE(firmware)
#define MODULE_SUPPORTED_DEVICE(name)
+#define MODULE_IMPORT_NS(_name)
+/*
+ * THIS_MODULE is used to differentiate modules on Linux. We currently
+ * completely stub out any Linux struct module usage, but THIS_MODULE is still
+ * used to populate the "owner" fields of various drivers. Even though we
+ * don't actually dereference these "owner" fields they are still used by
+ * drivers to check if devices/dmabufs/etc come from different modules. For
+ * example, during DRM GEM import some drivers check if the dmabuf's owner
+ * matches the dev's owner. If they match because they are both NULL drivers
+ * may incorrectly think two resources come from the same module.
+ *
+ * To handle this we specify an undefined symbol __this_linker_file, which
+ * will get special treatment from the linker when resolving. This will
+ * populate the usages of __this_linker_file with the linker_file_t of the
+ * module.
+ */
+#ifdef KLD_MODULE
+#define THIS_MODULE ((struct module *)&__this_linker_file)
+#else
#define THIS_MODULE ((struct module *)0)
+#endif
#define __MODULE_STRING(x) __stringify(x)
@@ -104,4 +124,4 @@ _module_run(void *arg)
#define postcore_initcall(fn) module_init(fn)
-#endif /* _LINUX_MODULE_H_ */
+#endif /* _LINUXKPI_LINUX_MODULE_H_ */
diff --git a/sys/compat/linuxkpi/common/include/linux/moduleparam.h b/sys/compat/linuxkpi/common/include/linux/moduleparam.h
index 2b48ec1809b7..b61bbce495ea 100644
--- a/sys/compat/linuxkpi/common/include/linux/moduleparam.h
+++ b/sys/compat/linuxkpi/common/include/linux/moduleparam.h
@@ -25,11 +25,9 @@
* 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.
- *
- * $FreeBSD$
*/
-#ifndef _LINUX_MODULEPARAM_H_
-#define _LINUX_MODULEPARAM_H_
+#ifndef _LINUXKPI_LINUX_MODULEPARAM_H_
+#define _LINUXKPI_LINUX_MODULEPARAM_H_
#include <sys/types.h>
#include <sys/sysctl.h>
@@ -90,6 +88,15 @@
LINUXKPI_PARAM_NAME(name), LINUXKPI_PARAM_PERM(perm), &(var), 0, \
LINUXKPI_PARAM_DESC(name)))
+#define LINUXKPI_PARAM_bint(name, var, perm) \
+ LINUXKPI_PARAM_int(name, var, perm)
+
+#define LINUXKPI_PARAM_hexint(name, var, perm) \
+ extern const char LINUXKPI_PARAM_DESC(name)[]; \
+ LINUXKPI_PARAM_PASS(SYSCTL_UINT(LINUXKPI_PARAM_PARENT, OID_AUTO, \
+ LINUXKPI_PARAM_NAME(name), LINUXKPI_PARAM_PERM(perm), &(var), 0, \
+ LINUXKPI_PARAM_DESC(name)))
+
#define LINUXKPI_PARAM_long(name, var, perm) \
extern const char LINUXKPI_PARAM_DESC(name)[]; \
LINUXKPI_PARAM_PASS(SYSCTL_LONG(LINUXKPI_PARAM_PARENT, OID_AUTO, \
@@ -136,4 +143,4 @@
SYSCTL_DECL(_compat_linuxkpi);
-#endif /* _LINUX_MODULEPARAM_H_ */
+#endif /* _LINUXKPI_LINUX_MODULEPARAM_H_ */
diff --git a/sys/compat/linuxkpi/common/include/linux/mutex.h b/sys/compat/linuxkpi/common/include/linux/mutex.h
index bdf0b4dbdb2d..6fb6a7744a89 100644
--- a/sys/compat/linuxkpi/common/include/linux/mutex.h
+++ b/sys/compat/linuxkpi/common/include/linux/mutex.h
@@ -25,17 +25,18 @@
* 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.
- *
- * $FreeBSD$
*/
-#ifndef _LINUX_MUTEX_H_
-#define _LINUX_MUTEX_H_
+#ifndef _LINUXKPI_LINUX_MUTEX_H_
+#define _LINUXKPI_LINUX_MUTEX_H_
#include <sys/param.h>
#include <sys/proc.h>
#include <sys/lock.h>
#include <sys/sx.h>
+#include <linux/kernel.h>
+#include <linux/cleanup.h>
+#include <linux/list.h>
#include <linux/spinlock.h>
#include <asm/atomic.h>
@@ -173,4 +174,4 @@ linux_mutex_destroy(mutex_t *m)
extern int linux_mutex_lock_interruptible(mutex_t *m);
-#endif /* _LINUX_MUTEX_H_ */
+#endif /* _LINUXKPI_LINUX_MUTEX_H_ */
diff --git a/sys/compat/linuxkpi/common/include/linux/net.h b/sys/compat/linuxkpi/common/include/linux/net.h
index 5365cd0e9552..a5172f3f31eb 100644
--- a/sys/compat/linuxkpi/common/include/linux/net.h
+++ b/sys/compat/linuxkpi/common/include/linux/net.h
@@ -25,11 +25,9 @@
* 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.
- *
- * $FreeBSD$
*/
-#ifndef _LINUX_NET_H_
-#define _LINUX_NET_H_
+#ifndef _LINUXKPI_LINUX_NET_H_
+#define _LINUXKPI_LINUX_NET_H_
#include <sys/types.h>
#include <sys/malloc.h>
@@ -47,26 +45,27 @@ sock_create_kern(int family, int type, int proto, struct socket **res)
}
static inline int
-sock_getname(struct socket *so, struct sockaddr *addr, int *sockaddr_len,
+sock_getname(struct socket *so, struct sockaddr *sa, int *sockaddr_len,
int peer)
{
- struct sockaddr *nam;
int error;
- nam = NULL;
+ /*
+ * XXXGL: we can't use sopeeraddr()/sosockaddr() here since with
+ * INVARIANTS they would check if supplied sockaddr has enough
+ * length. Such notion doesn't even exist in Linux KPI.
+ */
if (peer) {
- if ((so->so_state & (SS_ISCONNECTED|SS_ISCONFIRMING)) == 0)
+ if ((so->so_state & SS_ISCONNECTED) == 0)
return (-ENOTCONN);
- error = (*so->so_proto->pr_usrreqs->pru_peeraddr)(so, &nam);
+ error = so->so_proto->pr_peeraddr(so, sa);
} else
- error = (*so->so_proto->pr_usrreqs->pru_sockaddr)(so, &nam);
+ error = so->so_proto->pr_sockaddr(so, sa);
if (error)
return (-error);
- *addr = *nam;
- *sockaddr_len = addr->sa_len;
+ *sockaddr_len = sa->sa_len;
- free(nam, M_SONAME);
return (0);
}
@@ -86,4 +85,4 @@ net_ratelimit(void)
return (linuxkpi_net_ratelimit());
}
-#endif /* _LINUX_NET_H_ */
+#endif /* _LINUXKPI_LINUX_NET_H_ */
diff --git a/sys/compat/linuxkpi/common/include/linux/net_dim.h b/sys/compat/linuxkpi/common/include/linux/net_dim.h
index f1b7e06b820e..4fe3e39210e7 100644
--- a/sys/compat/linuxkpi/common/include/linux/net_dim.h
+++ b/sys/compat/linuxkpi/common/include/linux/net_dim.h
@@ -31,14 +31,12 @@
* ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
- *
- * $FreeBSD$
*/
/* This file implements Dynamic Interrupt Moderation, DIM */
-#ifndef NET_DIM_H
-#define NET_DIM_H
+#ifndef _LINUXKPI_LINUX_NET_DIM_H
+#define _LINUXKPI_LINUX_NET_DIM_H
#include <asm/types.h>
@@ -407,4 +405,4 @@ net_dim(struct net_dim *dim,
}
}
-#endif /* NET_DIM_H */
+#endif /* _LINUXKPI_LINUX_NET_DIM_H */
diff --git a/sys/compat/linuxkpi/common/include/linux/netdev_features.h b/sys/compat/linuxkpi/common/include/linux/netdev_features.h
index a4901f4d48c3..fae82776b071 100644
--- a/sys/compat/linuxkpi/common/include/linux/netdev_features.h
+++ b/sys/compat/linuxkpi/common/include/linux/netdev_features.h
@@ -1,5 +1,5 @@
/*-
- * Copyright (c) 2020-2021 The FreeBSD Foundation
+ * Copyright (c) 2020-2025 The FreeBSD Foundation
*
* Portions of this software were developed by Björn Zeeb
* under sponsorship from the FreeBSD Foundation.
@@ -24,25 +24,29 @@
* 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.
- *
- * $FreeBSD$
*/
-#ifndef __LKPI_LINUX_NETDEV_FEATURES_H_
-#define __LKPI_LINUX_NETDEV_FEATURES_H_
+#ifndef _LINUXKPI_LINUX_NETDEV_FEATURES_H_
+#define _LINUXKPI_LINUX_NETDEV_FEATURES_H_
#include <linux/types.h>
#include <linux/bitops.h>
typedef uint32_t netdev_features_t;
-#define NETIF_F_HIGHDMA BIT(0)
-#define NETIF_F_SG BIT(1)
-#define NETIF_F_IP_CSUM BIT(2)
-#define NETIF_F_IPV6_CSUM BIT(3)
-#define NETIF_F_TSO BIT(4)
-#define NETIF_F_TSO6 BIT(5)
-#define NETIF_F_RXCSUM BIT(6)
+#define NETIF_F_HIGHDMA BIT(0) /* Can DMA to high memory. */
+#define NETIF_F_SG BIT(1) /* Can do scatter/gather I/O. */
+#define NETIF_F_IP_CSUM BIT(2) /* Can csum TCP/UDP on IPv4. */
+#define NETIF_F_IPV6_CSUM BIT(3) /* Can csum TCP/UDP on IPv6. */
+#define NETIF_F_TSO BIT(4) /* Can do TCP over IPv4 segmentation. */
+#define NETIF_F_TSO6 BIT(5) /* Can do TCP over IPv6 segmentation. */
+#define NETIF_F_RXCSUM BIT(6) /* Can do receive csum offload. */
+#define NETIF_F_HW_CSUM BIT(7) /* Can csum packets (which?). */
+#define NETIF_F_HW_TC BIT(8) /* Can offload TC. */
+
+#define NETIF_F_CSUM_MASK (NETIF_F_IP_CSUM | NETIF_F_IPV6_CSUM)
-#define NETIF_F_CSUM_MASK (NETIF_F_IP_CSUM | NETIF_F_IPV6_CSUM)
+#define NETIF_F_BITS \
+ "\20\1HIGHDMA\2SG\3IP_CSUM\4IPV6_CSUM\5TSO\6TSO6\7RXCSUM" \
+ "\10HW_CSUM\11HW_TC"
-#endif /* __LKPI_LINUX_NETDEV_FEATURES_H_ */
+#endif /* _LINUXKPI_LINUX_NETDEV_FEATURES_H_ */
diff --git a/sys/compat/linuxkpi/common/include/linux/netdevice.h b/sys/compat/linuxkpi/common/include/linux/netdevice.h
index 1de31b3fa156..cf27753bcb80 100644
--- a/sys/compat/linuxkpi/common/include/linux/netdevice.h
+++ b/sys/compat/linuxkpi/common/include/linux/netdevice.h
@@ -4,6 +4,11 @@
* Copyright (c) 2010 Panasas, Inc.
* Copyright (c) 2013-2019 Mellanox Technologies, Ltd.
* All rights reserved.
+ * Copyright (c) 2020-2025 The FreeBSD Foundation
+ * Copyright (c) 2020-2022 Bjoern A. Zeeb
+ *
+ * Portions of this software were developed by Björn Zeeb
+ * under sponsorship from the FreeBSD Foundation.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
@@ -25,23 +30,36 @@
* 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.
- *
- * $FreeBSD$
*/
-#ifndef _LINUX_NETDEVICE_H_
-#define _LINUX_NETDEVICE_H_
+#ifndef _LINUXKPI_LINUX_NETDEVICE_H
+#define _LINUXKPI_LINUX_NETDEVICE_H
#include <linux/types.h>
+#include <linux/netdev_features.h>
+#include <sys/param.h>
+#include <sys/kernel.h>
+#include <sys/lock.h>
+#include <sys/mutex.h>
+#include <sys/malloc.h>
+#include <sys/queue.h>
#include <sys/socket.h>
+#include <sys/taskqueue.h>
#include <net/if_types.h>
#include <net/if.h>
#include <net/if_var.h>
#include <net/if_dl.h>
+#include <linux/kernel.h>
+#include <linux/bitops.h>
+#include <linux/list.h>
+#include <linux/device.h>
#include <linux/net.h>
+#include <linux/if_ether.h>
#include <linux/notifier.h>
+#include <linux/random.h>
+#include <linux/rcupdate.h>
#ifdef VIMAGE
#define init_net *vnet0
@@ -49,13 +67,100 @@
#define init_net *((struct vnet *)0)
#endif
+struct sk_buff;
+struct net_device;
+struct wireless_dev; /* net/cfg80211.h */
+
#define MAX_ADDR_LEN 20
-#define net_device ifnet
+#define NET_NAME_UNKNOWN 0
+
+enum net_addr_assign_type {
+ NET_ADDR_RANDOM,
+};
+
+enum netdev_tx {
+ NETDEV_TX_OK = 0,
+};
+typedef enum netdev_tx netdev_tx_t;
+
+struct netdev_hw_addr {
+ struct list_head addr_list;
+ uint8_t addr[MAX_ADDR_LEN];
+};
+
+struct netdev_hw_addr_list {
+ struct list_head addr_list;
+ int count;
+};
+
+enum net_device_reg_state {
+ NETREG_DUMMY = 1,
+ NETREG_REGISTERED,
+};
+
+enum tc_setup_type {
+ TC_SETUP_MAX_DUMMY,
+};
+
+struct net_device_ops {
+ int (*ndo_open)(struct net_device *);
+ int (*ndo_stop)(struct net_device *);
+ int (*ndo_set_mac_address)(struct net_device *, void *);
+ netdev_tx_t (*ndo_start_xmit)(struct sk_buff *, struct net_device *);
+ void (*ndo_set_rx_mode)(struct net_device *);
+};
+
+struct net_device {
+ /* net_device fields seen publicly. */
+ /* XXX can we later make some aliases to ifnet? */
+ char name[IFNAMSIZ];
+ struct wireless_dev *ieee80211_ptr;
+ uint8_t dev_addr[ETH_ALEN];
+ struct netdev_hw_addr_list mc;
+ netdev_features_t features;
+ struct {
+ unsigned long multicast;
+
+ unsigned long rx_bytes;
+ unsigned long rx_errors;
+ unsigned long rx_packets;
+ unsigned long tx_bytes;
+ unsigned long tx_dropped;
+ unsigned long tx_errors;
+ unsigned long tx_packets;
+ } stats;
+ enum net_addr_assign_type addr_assign_type;
+ enum net_device_reg_state reg_state;
+ const struct ethtool_ops *ethtool_ops;
+ const struct net_device_ops *netdev_ops;
-#define rtnl_lock()
-#define rtnl_unlock()
+ bool needs_free_netdev;
+ /* Not properly typed as-of now. */
+ int flags, type;
+ int name_assign_type, needed_headroom;
+ int threaded;
+ void (*priv_destructor)(struct net_device *);
+
+ /* net_device internal. */
+ struct device dev;
+
+ /*
+ * In case we delete the net_device we need to be able to clear all
+ * NAPI consumers.
+ */
+ struct mtx napi_mtx;
+ TAILQ_HEAD(, napi_struct) napi_head;
+ struct taskqueue *napi_tq;
+
+ /* Must stay last. */
+ uint8_t drv_priv[0] __aligned(CACHE_LINE_SIZE);
+};
+
+#define SET_NETDEV_DEV(_ndev, _dev) (_ndev)->dev.parent = _dev;
+
+/* -------------------------------------------------------------------------- */
/* According to linux::ipoib_main.c. */
struct netdev_notifier_info {
struct net_device *dev;
@@ -79,4 +184,327 @@ int register_inetaddr_notifier(struct notifier_block *);
int unregister_netdevice_notifier(struct notifier_block *);
int unregister_inetaddr_notifier(struct notifier_block *);
-#endif /* _LINUX_NETDEVICE_H_ */
+/* -------------------------------------------------------------------------- */
+
+#define NAPI_POLL_WEIGHT 64 /* budget */
+
+/*
+ * There are drivers directly testing napi state bits, so we need to publicly
+ * expose them. If you ask me, those accesses should be hid behind an
+ * inline function and the bit flags not be directly exposed.
+ */
+enum napi_state_bits {
+ /*
+ * Official Linux flags encountered.
+ */
+ NAPI_STATE_SCHED = 1,
+
+ /*
+ * Our internal versions (for now).
+ */
+ /* Do not schedule new things while we are waiting to clear things. */
+ LKPI_NAPI_FLAG_DISABLE_PENDING = 0,
+ /* To synchronise that only one poll is ever running. */
+ LKPI_NAPI_FLAG_IS_SCHEDULED = 1,
+ /* If trying to schedule while poll is running. Need to re-schedule. */
+ LKPI_NAPI_FLAG_LOST_RACE_TRY_AGAIN = 2,
+ /* When shutting down forcefully prevent anything from running task/poll. */
+ LKPI_NAPI_FLAG_SHUTDOWN = 3,
+};
+
+struct napi_struct {
+ TAILQ_ENTRY(napi_struct) entry;
+
+ struct list_head rx_list;
+ struct net_device *dev;
+ int (*poll)(struct napi_struct *, int);
+ int budget;
+ int rx_count;
+
+
+ /*
+ * These flags mostly need to be checked/changed atomically
+ * (multiple together in some cases).
+ */
+ volatile unsigned long state;
+
+ /* FreeBSD internal. */
+ /* Use task for now, so we can easily switch between direct and task. */
+ struct task napi_task;
+};
+
+void linuxkpi_init_dummy_netdev(struct net_device *);
+void linuxkpi_netif_napi_add(struct net_device *, struct napi_struct *,
+ int(*napi_poll)(struct napi_struct *, int));
+void linuxkpi_netif_napi_del(struct napi_struct *);
+bool linuxkpi_napi_schedule_prep(struct napi_struct *);
+void linuxkpi___napi_schedule(struct napi_struct *);
+bool linuxkpi_napi_schedule(struct napi_struct *);
+void linuxkpi_napi_reschedule(struct napi_struct *);
+bool linuxkpi_napi_complete_done(struct napi_struct *, int);
+bool linuxkpi_napi_complete(struct napi_struct *);
+void linuxkpi_napi_disable(struct napi_struct *);
+void linuxkpi_napi_enable(struct napi_struct *);
+void linuxkpi_napi_synchronize(struct napi_struct *);
+
+#define init_dummy_netdev(_n) \
+ linuxkpi_init_dummy_netdev(_n)
+#define netif_napi_add(_nd, _ns, _p) \
+ linuxkpi_netif_napi_add(_nd, _ns, _p)
+#define netif_napi_del(_n) \
+ linuxkpi_netif_napi_del(_n)
+#define napi_schedule_prep(_n) \
+ linuxkpi_napi_schedule_prep(_n)
+#define __napi_schedule(_n) \
+ linuxkpi___napi_schedule(_n)
+#define napi_schedule(_n) \
+ linuxkpi_napi_schedule(_n)
+#define napi_reschedule(_n) \
+ linuxkpi_napi_reschedule(_n)
+#define napi_complete_done(_n, _r) \
+ linuxkpi_napi_complete_done(_n, _r)
+#define napi_complete(_n) \
+ linuxkpi_napi_complete(_n)
+#define napi_disable(_n) \
+ linuxkpi_napi_disable(_n)
+#define napi_enable(_n) \
+ linuxkpi_napi_enable(_n)
+#define napi_synchronize(_n) \
+ linuxkpi_napi_synchronize(_n)
+
+
+static inline void
+netif_napi_add_tx(struct net_device *dev, struct napi_struct *napi,
+ int(*napi_poll)(struct napi_struct *, int))
+{
+
+ netif_napi_add(dev, napi, napi_poll);
+}
+
+static inline bool
+napi_is_scheduled(struct napi_struct *napi)
+{
+
+ return (test_bit(LKPI_NAPI_FLAG_IS_SCHEDULED, &napi->state));
+}
+
+/* -------------------------------------------------------------------------- */
+
+static inline void
+netdev_rss_key_fill(uint32_t *buf, size_t len)
+{
+
+ /*
+ * Remembering from a previous life there was discussions on what is
+ * a good RSS hash key. See end of rss_init() in net/rss_config.c.
+ * iwlwifi is looking for a 10byte "secret" so stay with random for now.
+ */
+ get_random_bytes(buf, len);
+}
+
+static inline void
+__hw_addr_init(struct netdev_hw_addr_list *list)
+{
+ list->count = 0;
+ INIT_LIST_HEAD(&list->addr_list);
+}
+
+static inline int
+netdev_hw_addr_list_count(struct netdev_hw_addr_list *list)
+{
+
+ return (list->count);
+}
+
+static inline int
+netdev_mc_count(struct net_device *ndev)
+{
+
+ return (netdev_hw_addr_list_count(&ndev->mc));
+}
+
+#define netdev_hw_addr_list_for_each(_addr, _list) \
+ list_for_each_entry((_addr), &(_list)->addr_list, addr_list)
+
+#define netdev_for_each_mc_addr(na, ndev) \
+ netdev_hw_addr_list_for_each(na, &(ndev)->mc)
+
+static __inline void
+synchronize_net(void)
+{
+
+ /* We probably cannot do that unconditionally at some point anymore. */
+ synchronize_rcu();
+}
+
+static __inline void
+netif_receive_skb_list(struct list_head *head)
+{
+
+ pr_debug("%s: TODO\n", __func__);
+}
+
+static __inline int
+napi_gro_receive(struct napi_struct *napi, struct sk_buff *skb)
+{
+
+ pr_debug("%s: TODO\n", __func__);
+ return (-1);
+}
+
+static __inline void
+ether_setup(struct net_device *ndev)
+{
+
+ pr_debug("%s: TODO\n", __func__);
+}
+
+static __inline void
+dev_net_set(struct net_device *ndev, void *p)
+{
+
+ pr_debug("%s: TODO\n", __func__);
+}
+
+static __inline int
+dev_set_threaded(struct net_device *ndev, bool threaded)
+{
+
+ pr_debug("%s: TODO\n", __func__);
+ return (-ENODEV);
+}
+
+/* -------------------------------------------------------------------------- */
+
+static __inline bool
+netif_carrier_ok(struct net_device *ndev)
+{
+ pr_debug("%s: TODO\n", __func__);
+ return (false);
+}
+
+static __inline void
+netif_carrier_off(struct net_device *ndev)
+{
+ pr_debug("%s: TODO\n", __func__);
+}
+
+static __inline void
+netif_carrier_on(struct net_device *ndev)
+{
+ pr_debug("%s: TODO\n", __func__);
+}
+
+/* -------------------------------------------------------------------------- */
+
+static __inline bool
+netif_queue_stopped(struct net_device *ndev)
+{
+ pr_debug("%s: TODO\n", __func__);
+ return (false);
+}
+
+static __inline void
+netif_stop_queue(struct net_device *ndev)
+{
+ pr_debug("%s: TODO\n", __func__);
+}
+
+static __inline void
+netif_wake_queue(struct net_device *ndev)
+{
+ pr_debug("%s: TODO\n", __func__);
+}
+
+/* -------------------------------------------------------------------------- */
+
+static __inline int
+register_netdevice(struct net_device *ndev)
+{
+
+ /* assert rtnl_locked? */
+ pr_debug("%s: TODO\n", __func__);
+ return (0);
+}
+
+static __inline int
+register_netdev(struct net_device *ndev)
+{
+ int error;
+
+ /* lock */
+ error = register_netdevice(ndev);
+ /* unlock */
+ pr_debug("%s: TODO\n", __func__);
+ return (error);
+}
+
+static __inline void
+unregister_netdev(struct net_device *ndev)
+{
+ pr_debug("%s: TODO\n", __func__);
+}
+
+static __inline void
+unregister_netdevice(struct net_device *ndev)
+{
+ pr_debug("%s: TODO\n", __func__);
+}
+
+/* -------------------------------------------------------------------------- */
+
+static __inline void
+netif_rx(struct sk_buff *skb)
+{
+ pr_debug("%s: TODO\n", __func__);
+}
+
+static __inline void
+netif_rx_ni(struct sk_buff *skb)
+{
+ pr_debug("%s: TODO\n", __func__);
+}
+
+/* -------------------------------------------------------------------------- */
+
+struct net_device *linuxkpi_alloc_netdev(size_t, const char *, uint32_t,
+ void(*)(struct net_device *));
+void linuxkpi_free_netdev(struct net_device *);
+
+#define alloc_netdev(_l, _n, _f, _func) \
+ linuxkpi_alloc_netdev(_l, _n, _f, _func)
+#define alloc_netdev_dummy(_l) \
+ linuxkpi_alloc_netdev(_l, "dummy", NET_NAME_UNKNOWN, NULL)
+#define free_netdev(_n) \
+ linuxkpi_free_netdev(_n)
+
+static inline void *
+netdev_priv(const struct net_device *ndev)
+{
+
+ return (__DECONST(void *, ndev->drv_priv));
+}
+
+/* -------------------------------------------------------------------------- */
+
+static __inline void
+netif_device_attach(struct net_device *ndev)
+{
+ pr_debug("%s: TODO\n", __func__);
+}
+
+static __inline void
+netif_device_detach(struct net_device *ndev)
+{
+ pr_debug("%s: TODO\n", __func__);
+}
+
+
+/* -------------------------------------------------------------------------- */
+/* This is really rtnetlink and probably belongs elsewhere. */
+
+#define rtnl_lock() do { } while(0)
+#define rtnl_unlock() do { } while(0)
+#define rcu_dereference_rtnl(x) READ_ONCE(x)
+
+#endif /* _LINUXKPI_LINUX_NETDEVICE_H */
diff --git a/sys/compat/linuxkpi/common/include/linux/nl80211.h b/sys/compat/linuxkpi/common/include/linux/nl80211.h
new file mode 100644
index 000000000000..845ffec4bcba
--- /dev/null
+++ b/sys/compat/linuxkpi/common/include/linux/nl80211.h
@@ -0,0 +1,455 @@
+/*-
+ * Copyright (c) 2020-2024 The FreeBSD Foundation
+ *
+ * This software was developed by Björn Zeeb under sponsorship from
+ * the FreeBSD Foundation.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``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 OR CONTRIBUTORS 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.
+ */
+
+#ifndef _LINUXKPI_LINUX_NL80211_H
+#define _LINUXKPI_LINUX_NL80211_H
+
+#include <linux/bitops.h>
+
+enum nl80211_feature_flags {
+ NL80211_FEATURE_AP_MODE_CHAN_WIDTH_CHANGE = BIT(0),
+ NL80211_FEATURE_DS_PARAM_SET_IE_IN_PROBES = BIT(1),
+ NL80211_FEATURE_HT_IBSS = BIT(2),
+ NL80211_FEATURE_LOW_PRIORITY_SCAN = BIT(3),
+ NL80211_FEATURE_ND_RANDOM_MAC_ADDR = BIT(4),
+ NL80211_FEATURE_P2P_GO_CTWIN = BIT(5),
+ NL80211_FEATURE_P2P_GO_OPPPS = BIT(6),
+ NL80211_FEATURE_QUIET = BIT(7),
+ NL80211_FEATURE_SCAN_RANDOM_MAC_ADDR = BIT(8),
+ NL80211_FEATURE_SCHED_SCAN_RANDOM_MAC_ADDR = BIT(9),
+ NL80211_FEATURE_DYNAMIC_SMPS = BIT(10),
+ NL80211_FEATURE_STATIC_SMPS = BIT(11),
+ NL80211_FEATURE_SUPPORTS_WMM_ADMISSION = BIT(12),
+ NL80211_FEATURE_TDLS_CHANNEL_SWITCH = BIT(13),
+ NL80211_FEATURE_TX_POWER_INSERTION = BIT(14),
+ NL80211_FEATURE_WFA_TPC_IE_IN_PROBES = BIT(15),
+ NL80211_FEATURE_AP_SCAN = BIT(16),
+ NL80211_FEATURE_ACTIVE_MONITOR = BIT(17),
+ NL80211_FEATURE_SAE = BIT(18),
+};
+
+enum nl80211_pmsr_ftm_failure_flags {
+ NL80211_PMSR_FTM_FAILURE_NO_RESPONSE = BIT(0),
+ NL80211_PMSR_FTM_FAILURE_PEER_BUSY = BIT(1),
+ NL80211_PMSR_FTM_FAILURE_UNSPECIFIED = BIT(2),
+};
+
+enum nl80211_pmsr_status_flags {
+ NL80211_PMSR_STATUS_FAILURE = BIT(0),
+ NL80211_PMSR_STATUS_SUCCESS = BIT(1),
+ NL80211_PMSR_STATUS_TIMEOUT = BIT(2),
+};
+
+#define NL80211_PMSR_TYPE_FTM 1
+
+enum nl80211_reg_rule_flags {
+ NL80211_RRF_AUTO_BW = BIT(0),
+ NL80211_RRF_DFS = BIT(1),
+ NL80211_RRF_GO_CONCURRENT = BIT(2),
+ NL80211_RRF_NO_IR = BIT(3),
+ NL80211_RRF_NO_OUTDOOR = BIT(4),
+ NL80211_RRF_NO_HT40MINUS = BIT(5),
+ NL80211_RRF_NO_HT40PLUS = BIT(6),
+ NL80211_RRF_NO_80MHZ = BIT(7),
+ NL80211_RRF_NO_160MHZ = BIT(8),
+ NL80211_RRF_NO_HE = BIT(9),
+ NL80211_RRF_NO_OFDM = BIT(10),
+ NL80211_RRF_NO_320MHZ = BIT(11),
+ NL80211_RRF_NO_EHT = BIT(12),
+ NL80211_RRF_DFS_CONCURRENT = BIT(13),
+ NL80211_RRF_NO_6GHZ_VLP_CLIENT = BIT(14),
+ NL80211_RRF_NO_6GHZ_AFC_CLIENT = BIT(15),
+ NL80211_RRF_PSD = BIT(16),
+ NL80211_RRF_ALLOW_6GHZ_VLP_AP = BIT(17),
+ NL80211_RRF_ALLOW_20MHZ_ACTIVITY = BIT(18),
+};
+#define NL80211_RRF_NO_HT40 (NL80211_RRF_NO_HT40MINUS|NL80211_RRF_NO_HT40PLUS)
+
+enum nl80211_scan_flags {
+ NL80211_SCAN_FLAG_FILS_MAX_CHANNEL_TIME = BIT(0),
+ NL80211_SCAN_FLAG_OCE_PROBE_REQ_DEFERRAL_SUPPRESSION = BIT(1),
+ NL80211_SCAN_FLAG_OCE_PROBE_REQ_HIGH_TX_RATE = BIT(2),
+ NL80211_SCAN_FLAG_RANDOM_ADDR = BIT(3),
+ NL80211_SCAN_FLAG_COLOCATED_6GHZ = BIT(4),
+ NL80211_SCAN_FLAG_RANDOM_SN = BIT(5),
+ NL80211_SCAN_FLAG_ACCEPT_BCAST_PROBE_RESP = BIT(6),
+};
+
+#define NL80211_MAX_SUPP_REG_RULES 512 /* TODO FIXME, random */
+
+#define NL80211_BSS_CHAN_WIDTH_20 __LINE__ /* TODO FIXME, brcmfmac */
+
+enum nl80211_wpa_versions {
+ NL80211_WPA_VERSION_1 = 1,
+ NL80211_WPA_VERSION_2,
+ NL80211_WPA_VERSION_3,
+};
+
+enum nl80211_bss_select_attr {
+ __NL80211_BSS_SELECT_ATTR_INVALID = 0,
+ NL80211_BSS_SELECT_ATTR_BAND_PREF,
+ NL80211_BSS_SELECT_ATTR_RSSI,
+ NL80211_BSS_SELECT_ATTR_RSSI_ADJUST,
+};
+
+enum nl80211_sta_flag {
+ /* XXX TODO */
+ NL80211_STA_FLAG_ASSOCIATED,
+ NL80211_STA_FLAG_AUTHENTICATED,
+ NL80211_STA_FLAG_AUTHORIZED,
+ NL80211_STA_FLAG_TDLS_PEER,
+ NL80211_STA_FLAG_WME,
+};
+
+enum nl80211_band {
+ /* XXX TODO */
+ NL80211_BAND_2GHZ = 0,
+ NL80211_BAND_5GHZ,
+ NL80211_BAND_60GHZ,
+ NL80211_BAND_6GHZ,
+
+ /* Keep this last. */
+ NUM_NL80211_BANDS
+} __packed;
+
+enum nl80211_channel_type {
+ NL80211_CHAN_NO_HT,
+ NL80211_CHAN_HT20,
+ NL80211_CHAN_HT40PLUS,
+ NL80211_CHAN_HT40MINUS,
+};
+
+enum nl80211_chan_width {
+ /* XXX TODO */
+ NL80211_CHAN_WIDTH_20_NOHT,
+ NL80211_CHAN_WIDTH_20,
+ NL80211_CHAN_WIDTH_40,
+ NL80211_CHAN_WIDTH_80,
+ NL80211_CHAN_WIDTH_80P80,
+ NL80211_CHAN_WIDTH_160,
+ NL80211_CHAN_WIDTH_5,
+ NL80211_CHAN_WIDTH_10,
+ NL80211_CHAN_WIDTH_320,
+};
+
+enum nl80211_iftype {
+ /* XXX TODO */
+ NL80211_IFTYPE_UNSPECIFIED,
+ NL80211_IFTYPE_ADHOC,
+ NL80211_IFTYPE_STATION,
+ NL80211_IFTYPE_AP,
+ NL80211_IFTYPE_AP_VLAN,
+ NL80211_IFTYPE_MONITOR,
+ NL80211_IFTYPE_P2P_CLIENT,
+ NL80211_IFTYPE_P2P_DEVICE,
+ NL80211_IFTYPE_P2P_GO,
+ NL80211_IFTYPE_MESH_POINT,
+ NL80211_IFTYPE_WDS,
+ NL80211_IFTYPE_OCB,
+ NL80211_IFTYPE_NAN,
+
+ /* Keep this last. */
+ NUM_NL80211_IFTYPES
+};
+
+enum nl80211_preamble {
+ /* XXX TODO */
+ NL80211_PREAMBLE_LEGACY,
+ NL80211_PREAMBLE_HT,
+ NL80211_PREAMBLE_VHT,
+ NL80211_PREAMBLE_HE,
+};
+
+enum nl80211_tdls_operation {
+ /* XXX TODO */
+ NL80211_TDLS_SETUP,
+ NL80211_TDLS_TEARDOWN,
+ NL80211_TDLS_ENABLE_LINK,
+ NL80211_TDLS_DISABLE_LINK,
+ NL80211_TDLS_DISCOVERY_REQ,
+};
+
+enum nl80211_cqm_rssi_threshold_event {
+ /* XXX TODO */
+ NL80211_CQM_RSSI_THRESHOLD_EVENT_LOW,
+ NL80211_CQM_RSSI_THRESHOLD_EVENT_HIGH,
+};
+
+enum nl80211_ext_feature {
+ /* XXX TODO */
+ NL80211_EXT_FEATURE_ACCEPT_BCAST_PROBE_RESP,
+ NL80211_EXT_FEATURE_BSS_PARENT_TSF,
+ NL80211_EXT_FEATURE_CAN_REPLACE_PTK0,
+ NL80211_EXT_FEATURE_DFS_OFFLOAD,
+ NL80211_EXT_FEATURE_ENABLE_FTM_RESPONDER,
+ NL80211_EXT_FEATURE_EXT_KEY_ID,
+ NL80211_EXT_FEATURE_FILS_MAX_CHANNEL_TIME,
+ NL80211_EXT_FEATURE_MU_MIMO_AIR_SNIFFER,
+ NL80211_EXT_FEATURE_OCE_PROBE_REQ_DEFERRAL_SUPPRESSION,
+ NL80211_EXT_FEATURE_OCE_PROBE_REQ_HIGH_TX_RATE,
+ NL80211_EXT_FEATURE_PROTECTED_TWT,
+ NL80211_EXT_FEATURE_SAE_OFFLOAD,
+ NL80211_EXT_FEATURE_SCAN_START_TIME,
+ NL80211_EXT_FEATURE_SET_SCAN_DWELL,
+ NL80211_EXT_FEATURE_VHT_IBSS,
+ NL80211_EXT_FEATURE_4WAY_HANDSHAKE_STA_1X,
+ NL80211_EXT_FEATURE_4WAY_HANDSHAKE_STA_PSK,
+ NL80211_EXT_FEATURE_BEACON_PROTECTION_CLIENT,
+ NL80211_EXT_FEATURE_SCAN_RANDOM_SN,
+ NL80211_EXT_FEATURE_STA_TX_PWR,
+ NL80211_EXT_FEATURE_CQM_RSSI_LIST,
+ NL80211_EXT_FEATURE_AQL,
+ NL80211_EXT_FEATURE_AIRTIME_FAIRNESS,
+ NL80211_EXT_FEATURE_ACK_SIGNAL_SUPPORT,
+ NL80211_EXT_FEATURE_BEACON_RATE_LEGACY,
+ NL80211_EXT_FEATURE_BEACON_RATE_HT,
+ NL80211_EXT_FEATURE_BEACON_RATE_VHT,
+ NL80211_EXT_FEATURE_BEACON_RATE_HE,
+ NL80211_EXT_FEATURE_BSS_COLOR,
+ NL80211_EXT_FEATURE_FILS_DISCOVERY,
+ NL80211_EXT_FEATURE_RADAR_BACKGROUND,
+ NL80211_EXT_FEATURE_UNSOL_BCAST_PROBE_RESP,
+ NL80211_EXT_FEATURE_BEACON_PROTECTION,
+ NL80211_EXT_FEATURE_SCAN_MIN_PREQ_CONTENT,
+ NL80211_EXT_FEATURE_PUNCT,
+ NL80211_EXT_FEATURE_DFS_CONCURRENT,
+ NL80211_EXT_FEATURE_MULTICAST_REGISTRATIONS,
+ NL80211_EXT_FEATURE_SPP_AMSDU_SUPPORT,
+ NL80211_EXT_FEATURE_SECURE_LTF,
+ NL80211_EXT_FEATURE_PROT_RANGE_NEGO_AND_MEASURE,
+ NL80211_EXT_FEATURE_4WAY_HANDSHAKE_AP_PSK,
+ NL80211_EXT_FEATURE_SAE_OFFLOAD_AP,
+
+ /* Keep this last. */
+ NUM_NL80211_EXT_FEATURES
+};
+
+/* Keep in order with lkpi_nl80211_sta_info_to_str() */
+enum nl80211_sta_info {
+ /* XXX TODO */
+ NL80211_STA_INFO_BEACON_RX,
+ NL80211_STA_INFO_BEACON_SIGNAL_AVG,
+ NL80211_STA_INFO_BSS_PARAM,
+ NL80211_STA_INFO_CHAIN_SIGNAL,
+ NL80211_STA_INFO_CHAIN_SIGNAL_AVG,
+ NL80211_STA_INFO_CONNECTED_TIME,
+ NL80211_STA_INFO_INACTIVE_TIME,
+ NL80211_STA_INFO_SIGNAL,
+ NL80211_STA_INFO_SIGNAL_AVG,
+ NL80211_STA_INFO_STA_FLAGS,
+ NL80211_STA_INFO_RX_BITRATE,
+ NL80211_STA_INFO_RX_PACKETS,
+ NL80211_STA_INFO_RX_BYTES,
+ NL80211_STA_INFO_RX_DROP_MISC,
+ NL80211_STA_INFO_TX_BITRATE,
+ NL80211_STA_INFO_TX_PACKETS,
+ NL80211_STA_INFO_TX_BYTES,
+ NL80211_STA_INFO_TX_BYTES64,
+ NL80211_STA_INFO_RX_BYTES64,
+ NL80211_STA_INFO_TX_FAILED,
+ NL80211_STA_INFO_TX_RETRIES,
+ NL80211_STA_INFO_RX_DURATION,
+ NL80211_STA_INFO_TX_DURATION,
+ NL80211_STA_INFO_ACK_SIGNAL,
+ NL80211_STA_INFO_ACK_SIGNAL_AVG,
+};
+
+enum nl80211_ftm_stats {
+ /* XXX TODO */
+ NL80211_FTM_STATS_ASAP_NUM,
+ NL80211_FTM_STATS_FAILED_NUM,
+ NL80211_FTM_STATS_NON_ASAP_NUM,
+ NL80211_FTM_STATS_OUT_OF_WINDOW_TRIGGERS_NUM,
+ NL80211_FTM_STATS_PARTIAL_NUM,
+ NL80211_FTM_STATS_RESCHEDULE_REQUESTS_NUM,
+ NL80211_FTM_STATS_SUCCESS_NUM,
+ NL80211_FTM_STATS_TOTAL_DURATION_MSEC,
+ NL80211_FTM_STATS_UNKNOWN_TRIGGERS_NUM,
+};
+
+enum nl80211_reg_initiator {
+ /* XXX TODO */
+ NL80211_REGDOM_SET_BY_USER,
+ NL80211_REGDOM_SET_BY_DRIVER,
+ NL80211_REGDOM_SET_BY_CORE,
+ NL80211_REGDOM_SET_BY_COUNTRY_IE,
+};
+
+struct nl80211_sta_flag_update {
+ /* XXX TODO */
+ int mask, set;
+
+};
+
+enum nl80211_tx_power_setting {
+ /* XXX TODO */
+ NL80211_TX_POWER_AUTOMATIC,
+ NL80211_TX_POWER_FIXED,
+ NL80211_TX_POWER_LIMITED,
+};
+
+enum nl80211_crit_proto_id {
+ /* XXX TODO */
+ NL80211_CRIT_PROTO_DHCP,
+};
+
+enum nl80211_auth_type {
+ NL80211_AUTHTYPE_AUTOMATIC,
+ NL80211_AUTHTYPE_OPEN_SYSTEM,
+ NL80211_AUTHTYPE_SHARED_KEY,
+ NL80211_AUTHTYPE_SAE,
+};
+
+enum nl80211_key_type {
+ NL80211_KEYTYPE_GROUP,
+ NL80211_KEYTYPE_PAIRWISE,
+};
+
+enum nl80211_he_ru_alloc {
+ NL80211_RATE_INFO_HE_RU_ALLOC_26,
+ NL80211_RATE_INFO_HE_RU_ALLOC_52,
+ NL80211_RATE_INFO_HE_RU_ALLOC_106,
+ NL80211_RATE_INFO_HE_RU_ALLOC_242,
+ NL80211_RATE_INFO_HE_RU_ALLOC_484,
+ NL80211_RATE_INFO_HE_RU_ALLOC_996,
+ NL80211_RATE_INFO_HE_RU_ALLOC_2x996,
+};
+
+enum nl80211_he_gi {
+ NL80211_RATE_INFO_HE_GI_0_8,
+ NL80211_RATE_INFO_HE_GI_1_6,
+ NL80211_RATE_INFO_HE_GI_3_2,
+};
+
+enum nl80211_he_ltf {
+ NL80211_RATE_INFO_HE_1XLTF,
+ NL80211_RATE_INFO_HE_2XLTF,
+ NL80211_RATE_INFO_HE_4XLTF,
+};
+
+enum nl80211_eht_gi {
+ NL80211_RATE_INFO_EHT_GI_0_8,
+ NL80211_RATE_INFO_EHT_GI_1_6,
+ NL80211_RATE_INFO_EHT_GI_3_2,
+};
+
+enum nl80211_eht_ru_alloc {
+ NL80211_RATE_INFO_EHT_RU_ALLOC_26,
+ NL80211_RATE_INFO_EHT_RU_ALLOC_52,
+ NL80211_RATE_INFO_EHT_RU_ALLOC_52P26,
+ NL80211_RATE_INFO_EHT_RU_ALLOC_106,
+ NL80211_RATE_INFO_EHT_RU_ALLOC_106P26,
+ NL80211_RATE_INFO_EHT_RU_ALLOC_242,
+ NL80211_RATE_INFO_EHT_RU_ALLOC_484,
+ NL80211_RATE_INFO_EHT_RU_ALLOC_484P242,
+ NL80211_RATE_INFO_EHT_RU_ALLOC_996,
+ NL80211_RATE_INFO_EHT_RU_ALLOC_996P484,
+ NL80211_RATE_INFO_EHT_RU_ALLOC_996P484P242,
+ NL80211_RATE_INFO_EHT_RU_ALLOC_2x996,
+ NL80211_RATE_INFO_EHT_RU_ALLOC_2x996P484,
+ NL80211_RATE_INFO_EHT_RU_ALLOC_3x996,
+ NL80211_RATE_INFO_EHT_RU_ALLOC_3x996P484,
+ NL80211_RATE_INFO_EHT_RU_ALLOC_4x996,
+};
+
+enum nl80211_dfs_regions {
+ NL80211_DFS_UNSET,
+ NL80211_DFS_FCC,
+ NL80211_DFS_ETSI,
+ NL80211_DFS_JP,
+};
+
+enum nl80211_dfs_state {
+ NL80211_DFS_USABLE,
+};
+
+enum nl80211_sar_type {
+ NL80211_SAR_TYPE_POWER,
+};
+
+#define NL80211_VHT_NSS_MAX 8
+#define NL80211_HE_NSS_MAX 8
+
+enum nl80211_tid_cfg_attr {
+ NL80211_TID_CONFIG_ATTR_NOACK,
+ NL80211_TID_CONFIG_ATTR_RETRY_SHORT,
+ NL80211_TID_CONFIG_ATTR_TX_RATE_TYPE,
+ NL80211_TID_CONFIG_ATTR_TX_RATE,
+ NL80211_TID_CONFIG_ATTR_RTSCTS_CTRL,
+ NL80211_TID_CONFIG_ATTR_RETRY_LONG,
+ NL80211_TID_CONFIG_ATTR_AMPDU_CTRL,
+ NL80211_TID_CONFIG_ATTR_AMSDU_CTRL,
+};
+
+enum nl80211_tid_config {
+ NL80211_TID_CONFIG_ENABLE,
+};
+
+enum nl80211_tx_rate_setting {
+ NL80211_TX_RATE_AUTOMATIC,
+ NL80211_TX_RATE_FIXED,
+ NL80211_TX_RATE_LIMITED,
+};
+
+enum nl80211_txrate_gi {
+ NL80211_TXRATE_DEFAULT_GI,
+ NL80211_TXRATE_FORCE_SGI,
+ NL80211_TXRATE_FORCE_LGI,
+};
+
+enum nl80211_probe_resp_offload_support {
+ NL80211_PROBE_RESP_OFFLOAD_SUPPORT_WPS2,
+ NL80211_PROBE_RESP_OFFLOAD_SUPPORT_WPS,
+ NL80211_PROBE_RESP_OFFLOAD_SUPPORT_P2P,
+};
+
+enum nl80211_user_reg_hint_type {
+ NL80211_USER_REG_HINT_USER,
+};
+
+enum nl80211_hidden_ssid {
+ NL80211_HIDDEN_SSID_NOT_IN_USE,
+};
+
+enum nl80211_external_auth_action {
+ NL80211_EXTERNAL_AUTH_START,
+};
+
+enum nl80211_rxmgmt_flags {
+ NL80211_RXMGMT_FLAG_EXTERNAL_AUTH = BIT(1),
+};
+
+#define NL80211_TKIP_DATA_OFFSET_TX_MIC_KEY 16
+#define NL80211_TKIP_DATA_OFFSET_RX_MIC_KEY 24
+
+#define NL80211_KCK_LEN 16
+#define NL80211_KCK_EXT_LEN 24
+#define NL80211_KEK_LEN 16
+#define NL80211_KEK_EXT_LEN 32
+#define NL80211_REPLAY_CTR_LEN 8
+#endif /* _LINUXKPI_LINUX_NL80211_H */
diff --git a/sys/compat/linuxkpi/common/include/linux/nodemask.h b/sys/compat/linuxkpi/common/include/linux/nodemask.h
new file mode 100644
index 000000000000..7a245cc6f256
--- /dev/null
+++ b/sys/compat/linuxkpi/common/include/linux/nodemask.h
@@ -0,0 +1,46 @@
+/*-
+ * SPDX-License-Identifier: BSD-2-Clause
+ *
+ * Copyright (c) 2023 Serenity Cyber Security, LLC.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``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 OR CONTRIBUTORS 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.
+ */
+
+#ifndef _LINUXKPI_LINUX_NODEMASK_H_
+#define _LINUXKPI_LINUX_NODEMASK_H_
+
+#include <linux/kernel.h> /* pr_debug */
+
+static inline int
+num_online_nodes(void)
+{
+ return (1);
+}
+
+static inline int
+num_possible_nodes(void)
+{
+ pr_debug("%s: TODO\n", __func__);
+ return (1);
+}
+
+#endif /* _LINUXKPI_LINUX_NODEMASK_H_ */
diff --git a/sys/compat/linuxkpi/common/include/linux/nospec.h b/sys/compat/linuxkpi/common/include/linux/nospec.h
new file mode 100644
index 000000000000..e8458ae8b371
--- /dev/null
+++ b/sys/compat/linuxkpi/common/include/linux/nospec.h
@@ -0,0 +1,8 @@
+/* Public domain. */
+
+#ifndef _LINUXKPI_LINUX_NOSPEC_H_
+#define _LINUXKPI_LINUX_NOSPEC_H_
+
+#define array_index_nospec(a, b) (a)
+
+#endif /* _LINUXKPILINUX_NOSPEC_H_ */
diff --git a/sys/compat/linuxkpi/common/include/linux/notifier.h b/sys/compat/linuxkpi/common/include/linux/notifier.h
index ae292439bf54..9302a1ce4606 100644
--- a/sys/compat/linuxkpi/common/include/linux/notifier.h
+++ b/sys/compat/linuxkpi/common/include/linux/notifier.h
@@ -25,16 +25,17 @@
* 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.
- *
- * $FreeBSD$
*/
-#ifndef _LINUX_NOTIFIER_H_
-#define _LINUX_NOTIFIER_H_
+#ifndef _LINUXKPI_LINUX_NOTIFIER_H_
+#define _LINUXKPI_LINUX_NOTIFIER_H_
#include <sys/types.h>
#include <sys/eventhandler.h>
-#define NOTIFY_DONE 0
+#define NOTIFY_DONE 0
+#define NOTIFY_OK 0x0001
+#define NOTIFY_STOP_MASK 0x8000
+#define NOTIFY_BAD (NOTIFY_STOP_MASK | 0x0002)
enum {
NETDEV_CHANGE,
@@ -54,4 +55,4 @@ struct notifier_block {
eventhandler_tag tags[LINUX_NOTIFY_TAGS];
};
-#endif /* _LINUX_NOTIFIER_H_ */
+#endif /* _LINUXKPI_LINUX_NOTIFIER_H_ */
diff --git a/sys/compat/linuxkpi/common/include/linux/numa.h b/sys/compat/linuxkpi/common/include/linux/numa.h
index 19455349a7a6..6b227e177a64 100644
--- a/sys/compat/linuxkpi/common/include/linux/numa.h
+++ b/sys/compat/linuxkpi/common/include/linux/numa.h
@@ -24,13 +24,11 @@
* 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.
- *
- * $FreeBSD$
*/
-#ifndef _LINUX_NUMA_H_
-#define _LINUX_NUMA_H_
+#ifndef _LINUXKPI_LINUX_NUMA_H_
+#define _LINUXKPI_LINUX_NUMA_H_
#define NUMA_NO_NODE -1
-#endif /* _LINUX_NUMA_H_ */
+#endif /* _LINUXKPI_LINUX_NUMA_H_ */
diff --git a/sys/compat/linuxkpi/common/include/linux/of.h b/sys/compat/linuxkpi/common/include/linux/of.h
new file mode 100644
index 000000000000..fb4554a8ddbc
--- /dev/null
+++ b/sys/compat/linuxkpi/common/include/linux/of.h
@@ -0,0 +1,33 @@
+/*-
+ * SPDX-License-Identifier: BSD-2-Clause
+ *
+ * Copyright (c) 2023 Serenity Cyber Security, LLC.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``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 OR CONTRIBUTORS 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.
+ */
+
+#ifndef _LINUXKPI_LINUX_OF_H
+#define _LINUXKPI_LINUX_OF_H
+
+#include <linux/kobject.h>
+
+#endif
diff --git a/sys/compat/linuxkpi/common/include/linux/overflow.h b/sys/compat/linuxkpi/common/include/linux/overflow.h
index 2d540796cd43..e811037b8ecc 100644
--- a/sys/compat/linuxkpi/common/include/linux/overflow.h
+++ b/sys/compat/linuxkpi/common/include/linux/overflow.h
@@ -1,53 +1,475 @@
-/*-
- * Copyright (c) 2020 The FreeBSD Foundation
- *
- * This software was developed by Emmanuel Vadot under sponsorship
- * from the FreeBSD Foundation.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- *
- * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``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 OR CONTRIBUTORS 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.
- *
- * $FreeBSD$
- */
-
-#ifndef __LINUX_OVERFLOW_H__
-#define __LINUX_OVERFLOW_H__
-
-#include <sys/stdint.h>
-#include <sys/types.h>
-
-#define check_add_overflow(a, b, c) \
- __builtin_add_overflow(a, b, c)
-
-#define check_mul_overflow(a, b, c) \
- __builtin_mul_overflow(a, b, c)
-
-static inline size_t
-array_size(size_t x, size_t y)
+/* SPDX-License-Identifier: GPL-2.0 OR MIT */
+#ifndef _LINUXKPI_LINUX_OVERFLOW_H
+#define _LINUXKPI_LINUX_OVERFLOW_H
+
+#include <linux/compiler.h>
+#include <linux/limits.h>
+#ifdef __linux__
+#include <linux/const.h>
+#endif
+
+/*
+ * We need to compute the minimum and maximum values representable in a given
+ * type. These macros may also be useful elsewhere. It would seem more obvious
+ * to do something like:
+ *
+ * #define type_min(T) (T)(is_signed_type(T) ? (T)1 << (8*sizeof(T)-1) : 0)
+ * #define type_max(T) (T)(is_signed_type(T) ? ((T)1 << (8*sizeof(T)-1)) - 1 : ~(T)0)
+ *
+ * Unfortunately, the middle expressions, strictly speaking, have
+ * undefined behaviour, and at least some versions of gcc warn about
+ * the type_max expression (but not if -fsanitize=undefined is in
+ * effect; in that case, the warning is deferred to runtime...).
+ *
+ * The slightly excessive casting in type_min is to make sure the
+ * macros also produce sensible values for the exotic type _Bool. [The
+ * overflow checkers only almost work for _Bool, but that's
+ * a-feature-not-a-bug, since people shouldn't be doing arithmetic on
+ * _Bools. Besides, the gcc builtins don't allow _Bool* as third
+ * argument.]
+ *
+ * Idea stolen from
+ * https://mail-index.netbsd.org/tech-misc/2007/02/05/0000.html -
+ * credit to Christian Biere.
+ */
+#define __type_half_max(type) ((type)1 << (8*sizeof(type) - 1 - is_signed_type(type)))
+#define __type_max(T) ((T)((__type_half_max(T) - 1) + __type_half_max(T)))
+#define type_max(t) __type_max(typeof(t))
+#define __type_min(T) ((T)((T)-type_max(T)-(T)1))
+#define type_min(t) __type_min(typeof(t))
+
+/*
+ * Avoids triggering -Wtype-limits compilation warning,
+ * while using unsigned data types to check a < 0.
+ */
+#define is_non_negative(a) ((a) > 0 || (a) == 0)
+#define is_negative(a) (!(is_non_negative(a)))
+
+/*
+ * Allows for effectively applying __must_check to a macro so we can have
+ * both the type-agnostic benefits of the macros while also being able to
+ * enforce that the return value is, in fact, checked.
+ */
+static inline bool __must_check __must_check_overflow(bool overflow)
+{
+ return unlikely(overflow);
+}
+
+/**
+ * check_add_overflow() - Calculate addition with overflow checking
+ * @a: first addend
+ * @b: second addend
+ * @d: pointer to store sum
+ *
+ * Returns true on wrap-around, false otherwise.
+ *
+ * *@d holds the results of the attempted addition, regardless of whether
+ * wrap-around occurred.
+ */
+#define check_add_overflow(a, b, d) \
+ __must_check_overflow(__builtin_add_overflow(a, b, d))
+
+/**
+ * wrapping_add() - Intentionally perform a wrapping addition
+ * @type: type for result of calculation
+ * @a: first addend
+ * @b: second addend
+ *
+ * Return the potentially wrapped-around addition without
+ * tripping any wrap-around sanitizers that may be enabled.
+ */
+#define wrapping_add(type, a, b) \
+ ({ \
+ type __val; \
+ __builtin_add_overflow(a, b, &__val); \
+ __val; \
+ })
+
+/**
+ * wrapping_assign_add() - Intentionally perform a wrapping increment assignment
+ * @var: variable to be incremented
+ * @offset: amount to add
+ *
+ * Increments @var by @offset with wrap-around. Returns the resulting
+ * value of @var. Will not trip any wrap-around sanitizers.
+ *
+ * Returns the new value of @var.
+ */
+#define wrapping_assign_add(var, offset) \
+ ({ \
+ typeof(var) *__ptr = &(var); \
+ *__ptr = wrapping_add(typeof(var), *__ptr, offset); \
+ })
+
+/**
+ * check_sub_overflow() - Calculate subtraction with overflow checking
+ * @a: minuend; value to subtract from
+ * @b: subtrahend; value to subtract from @a
+ * @d: pointer to store difference
+ *
+ * Returns true on wrap-around, false otherwise.
+ *
+ * *@d holds the results of the attempted subtraction, regardless of whether
+ * wrap-around occurred.
+ */
+#define check_sub_overflow(a, b, d) \
+ __must_check_overflow(__builtin_sub_overflow(a, b, d))
+
+/**
+ * wrapping_sub() - Intentionally perform a wrapping subtraction
+ * @type: type for result of calculation
+ * @a: minuend; value to subtract from
+ * @b: subtrahend; value to subtract from @a
+ *
+ * Return the potentially wrapped-around subtraction without
+ * tripping any wrap-around sanitizers that may be enabled.
+ */
+#define wrapping_sub(type, a, b) \
+ ({ \
+ type __val; \
+ __builtin_sub_overflow(a, b, &__val); \
+ __val; \
+ })
+
+/**
+ * wrapping_assign_sub() - Intentionally perform a wrapping decrement assign
+ * @var: variable to be decremented
+ * @offset: amount to subtract
+ *
+ * Decrements @var by @offset with wrap-around. Returns the resulting
+ * value of @var. Will not trip any wrap-around sanitizers.
+ *
+ * Returns the new value of @var.
+ */
+#define wrapping_assign_sub(var, offset) \
+ ({ \
+ typeof(var) *__ptr = &(var); \
+ *__ptr = wrapping_sub(typeof(var), *__ptr, offset); \
+ })
+
+/**
+ * check_mul_overflow() - Calculate multiplication with overflow checking
+ * @a: first factor
+ * @b: second factor
+ * @d: pointer to store product
+ *
+ * Returns true on wrap-around, false otherwise.
+ *
+ * *@d holds the results of the attempted multiplication, regardless of whether
+ * wrap-around occurred.
+ */
+#define check_mul_overflow(a, b, d) \
+ __must_check_overflow(__builtin_mul_overflow(a, b, d))
+
+/**
+ * wrapping_mul() - Intentionally perform a wrapping multiplication
+ * @type: type for result of calculation
+ * @a: first factor
+ * @b: second factor
+ *
+ * Return the potentially wrapped-around multiplication without
+ * tripping any wrap-around sanitizers that may be enabled.
+ */
+#define wrapping_mul(type, a, b) \
+ ({ \
+ type __val; \
+ __builtin_mul_overflow(a, b, &__val); \
+ __val; \
+ })
+
+/**
+ * check_shl_overflow() - Calculate a left-shifted value and check overflow
+ * @a: Value to be shifted
+ * @s: How many bits left to shift
+ * @d: Pointer to where to store the result
+ *
+ * Computes *@d = (@a << @s)
+ *
+ * Returns true if '*@d' cannot hold the result or when '@a << @s' doesn't
+ * make sense. Example conditions:
+ *
+ * - '@a << @s' causes bits to be lost when stored in *@d.
+ * - '@s' is garbage (e.g. negative) or so large that the result of
+ * '@a << @s' is guaranteed to be 0.
+ * - '@a' is negative.
+ * - '@a << @s' sets the sign bit, if any, in '*@d'.
+ *
+ * '*@d' will hold the results of the attempted shift, but is not
+ * considered "safe for use" if true is returned.
+ */
+#define check_shl_overflow(a, s, d) __must_check_overflow(({ \
+ typeof(a) _a = a; \
+ typeof(s) _s = s; \
+ typeof(d) _d = d; \
+ unsigned long long _a_full = _a; \
+ unsigned int _to_shift = \
+ is_non_negative(_s) && _s < 8 * sizeof(*d) ? _s : 0; \
+ *_d = (_a_full << _to_shift); \
+ (_to_shift != _s || is_negative(*_d) || is_negative(_a) || \
+ (*_d >> _to_shift) != _a); \
+}))
+
+#define __overflows_type_constexpr(x, T) ( \
+ is_unsigned_type(typeof(x)) ? \
+ (x) > type_max(T) : \
+ is_unsigned_type(typeof(T)) ? \
+ (x) < 0 || (x) > type_max(T) : \
+ (x) < type_min(T) || (x) > type_max(T))
+
+#define __overflows_type(x, T) ({ \
+ typeof(T) v = 0; \
+ check_add_overflow((x), v, &v); \
+})
+
+/**
+ * overflows_type - helper for checking the overflows between value, variables,
+ * or data type
+ *
+ * @n: source constant value or variable to be checked
+ * @T: destination variable or data type proposed to store @x
+ *
+ * Compares the @x expression for whether or not it can safely fit in
+ * the storage of the type in @T. @x and @T can have different types.
+ * If @x is a constant expression, this will also resolve to a constant
+ * expression.
+ *
+ * Returns: true if overflow can occur, false otherwise.
+ */
+#define overflows_type(n, T) \
+ __builtin_choose_expr(__is_constexpr(n), \
+ __overflows_type_constexpr(n, T), \
+ __overflows_type(n, T))
+
+/**
+ * castable_to_type - like __same_type(), but also allows for casted literals
+ *
+ * @n: variable or constant value
+ * @T: variable or data type
+ *
+ * Unlike the __same_type() macro, this allows a constant value as the
+ * first argument. If this value would not overflow into an assignment
+ * of the second argument's type, it returns true. Otherwise, this falls
+ * back to __same_type().
+ */
+#define castable_to_type(n, T) \
+ __builtin_choose_expr(__is_constexpr(n), \
+ !__overflows_type_constexpr(n, T), \
+ __same_type(n, T))
+
+/**
+ * size_mul() - Calculate size_t multiplication with saturation at SIZE_MAX
+ * @factor1: first factor
+ * @factor2: second factor
+ *
+ * Returns: calculate @factor1 * @factor2, both promoted to size_t,
+ * with any overflow causing the return value to be SIZE_MAX. The
+ * lvalue must be size_t to avoid implicit type conversion.
+ */
+static inline size_t __must_check size_mul(size_t factor1, size_t factor2)
{
- size_t retval;
+ size_t bytes;
+
+ if (check_mul_overflow(factor1, factor2, &bytes))
+ return SIZE_MAX;
- if (__builtin_mul_overflow(x, y, &retval))
- retval = SIZE_MAX;
- return (retval);
+ return bytes;
}
-#endif /* __LINUX_OVERFLOW_H__ */
+/**
+ * size_add() - Calculate size_t addition with saturation at SIZE_MAX
+ * @addend1: first addend
+ * @addend2: second addend
+ *
+ * Returns: calculate @addend1 + @addend2, both promoted to size_t,
+ * with any overflow causing the return value to be SIZE_MAX. The
+ * lvalue must be size_t to avoid implicit type conversion.
+ */
+static inline size_t __must_check size_add(size_t addend1, size_t addend2)
+{
+ size_t bytes;
+
+ if (check_add_overflow(addend1, addend2, &bytes))
+ return SIZE_MAX;
+
+ return bytes;
+}
+
+/**
+ * size_sub() - Calculate size_t subtraction with saturation at SIZE_MAX
+ * @minuend: value to subtract from
+ * @subtrahend: value to subtract from @minuend
+ *
+ * Returns: calculate @minuend - @subtrahend, both promoted to size_t,
+ * with any overflow causing the return value to be SIZE_MAX. For
+ * composition with the size_add() and size_mul() helpers, neither
+ * argument may be SIZE_MAX (or the result with be forced to SIZE_MAX).
+ * The lvalue must be size_t to avoid implicit type conversion.
+ */
+static inline size_t __must_check size_sub(size_t minuend, size_t subtrahend)
+{
+ size_t bytes;
+
+ if (minuend == SIZE_MAX || subtrahend == SIZE_MAX ||
+ check_sub_overflow(minuend, subtrahend, &bytes))
+ return SIZE_MAX;
+
+ return bytes;
+}
+
+/**
+ * array_size() - Calculate size of 2-dimensional array.
+ * @a: dimension one
+ * @b: dimension two
+ *
+ * Calculates size of 2-dimensional array: @a * @b.
+ *
+ * Returns: number of bytes needed to represent the array or SIZE_MAX on
+ * overflow.
+ */
+#define array_size(a, b) size_mul(a, b)
+
+/**
+ * array3_size() - Calculate size of 3-dimensional array.
+ * @a: dimension one
+ * @b: dimension two
+ * @c: dimension three
+ *
+ * Calculates size of 3-dimensional array: @a * @b * @c.
+ *
+ * Returns: number of bytes needed to represent the array or SIZE_MAX on
+ * overflow.
+ */
+#define array3_size(a, b, c) size_mul(size_mul(a, b), c)
+
+/**
+ * flex_array_size() - Calculate size of a flexible array member
+ * within an enclosing structure.
+ * @p: Pointer to the structure.
+ * @member: Name of the flexible array member.
+ * @count: Number of elements in the array.
+ *
+ * Calculates size of a flexible array of @count number of @member
+ * elements, at the end of structure @p.
+ *
+ * Return: number of bytes needed or SIZE_MAX on overflow.
+ */
+#define flex_array_size(p, member, count) \
+ __builtin_choose_expr(__is_constexpr(count), \
+ (count) * sizeof(*(p)->member) + __must_be_array((p)->member), \
+ size_mul(count, sizeof(*(p)->member) + __must_be_array((p)->member)))
+
+/**
+ * struct_size() - Calculate size of structure with trailing flexible array.
+ * @p: Pointer to the structure.
+ * @member: Name of the array member.
+ * @count: Number of elements in the array.
+ *
+ * Calculates size of memory needed for structure of @p followed by an
+ * array of @count number of @member elements.
+ *
+ * Return: number of bytes needed or SIZE_MAX on overflow.
+ */
+#define struct_size(p, member, count) \
+ __builtin_choose_expr(__is_constexpr(count), \
+ sizeof(*(p)) + flex_array_size(p, member, count), \
+ size_add(sizeof(*(p)), flex_array_size(p, member, count)))
+
+/**
+ * struct_size_t() - Calculate size of structure with trailing flexible array
+ * @type: structure type name.
+ * @member: Name of the array member.
+ * @count: Number of elements in the array.
+ *
+ * Calculates size of memory needed for structure @type followed by an
+ * array of @count number of @member elements. Prefer using struct_size()
+ * when possible instead, to keep calculations associated with a specific
+ * instance variable of type @type.
+ *
+ * Return: number of bytes needed or SIZE_MAX on overflow.
+ */
+#define struct_size_t(type, member, count) \
+ struct_size((type *)NULL, member, count)
+
+/**
+ * __DEFINE_FLEX() - helper macro for DEFINE_FLEX() family.
+ * Enables caller macro to pass arbitrary trailing expressions
+ *
+ * @type: structure type name, including "struct" keyword.
+ * @name: Name for a variable to define.
+ * @member: Name of the array member.
+ * @count: Number of elements in the array; must be compile-time const.
+ * @trailer: Trailing expressions for attributes and/or initializers.
+ */
+#define __DEFINE_FLEX(type, name, member, count, trailer...) \
+ _Static_assert(__builtin_constant_p(count), \
+ "onstack flex array members require compile-time const count"); \
+ union { \
+ u8 bytes[struct_size_t(type, member, count)]; \
+ type obj; \
+ } name##_u trailer; \
+ type *name = (type *)&name##_u
+
+/**
+ * _DEFINE_FLEX() - helper macro for DEFINE_FLEX() family.
+ * Enables caller macro to pass (different) initializer.
+ *
+ * @type: structure type name, including "struct" keyword.
+ * @name: Name for a variable to define.
+ * @member: Name of the array member.
+ * @count: Number of elements in the array; must be compile-time const.
+ * @initializer: Initializer expression (e.g., pass `= { }` at minimum).
+ */
+#define _DEFINE_FLEX(type, name, member, count, initializer...) \
+ __DEFINE_FLEX(type, name, member, count, = { .obj initializer })
+
+/**
+ * DEFINE_RAW_FLEX() - Define an on-stack instance of structure with a trailing
+ * flexible array member, when it does not have a __counted_by annotation.
+ *
+ * @type: structure type name, including "struct" keyword.
+ * @name: Name for a variable to define.
+ * @member: Name of the array member.
+ * @count: Number of elements in the array; must be compile-time const.
+ *
+ * Define a zeroed, on-stack, instance of @type structure with a trailing
+ * flexible array member.
+ * Use __struct_size(@name) to get compile-time size of it afterwards.
+ * Use __member_size(@name->member) to get compile-time size of @name members.
+ * Use STACK_FLEX_ARRAY_SIZE(@name, @member) to get compile-time number of
+ * elements in array @member.
+ */
+#define DEFINE_RAW_FLEX(type, name, member, count) \
+ __DEFINE_FLEX(type, name, member, count, = { })
+
+/**
+ * DEFINE_FLEX() - Define an on-stack instance of structure with a trailing
+ * flexible array member.
+ *
+ * @TYPE: structure type name, including "struct" keyword.
+ * @NAME: Name for a variable to define.
+ * @MEMBER: Name of the array member.
+ * @COUNTER: Name of the __counted_by member.
+ * @COUNT: Number of elements in the array; must be compile-time const.
+ *
+ * Define a zeroed, on-stack, instance of @TYPE structure with a trailing
+ * flexible array member.
+ * Use __struct_size(@NAME) to get compile-time size of it afterwards.
+ * Use __member_size(@NAME->member) to get compile-time size of @NAME members.
+ * Use STACK_FLEX_ARRAY_SIZE(@name, @member) to get compile-time number of
+ * elements in array @member.
+ */
+#define DEFINE_FLEX(TYPE, NAME, MEMBER, COUNTER, COUNT) \
+ _DEFINE_FLEX(TYPE, NAME, MEMBER, COUNT, = { .COUNTER = COUNT, })
+
+/**
+ * STACK_FLEX_ARRAY_SIZE() - helper macro for DEFINE_FLEX() family.
+ * Returns the number of elements in @array.
+ *
+ * @name: Name for a variable defined in DEFINE_RAW_FLEX()/DEFINE_FLEX().
+ * @array: Name of the array member.
+ */
+#define STACK_FLEX_ARRAY_SIZE(name, array) \
+ (__member_size((name)->array) / sizeof(*(name)->array) + \
+ __must_be_array((name)->array))
+
+#endif /* _LINUXKPI_LINUX_OVERFLOW_H */
diff --git a/sys/compat/linuxkpi/common/include/linux/page-flags.h b/sys/compat/linuxkpi/common/include/linux/page-flags.h
new file mode 100644
index 000000000000..a22b3a24c330
--- /dev/null
+++ b/sys/compat/linuxkpi/common/include/linux/page-flags.h
@@ -0,0 +1,41 @@
+/*-
+ * SPDX-License-Identifier: BSD-2-Clause
+ *
+ * Copyright (c) 2022 Jean-Sébastien Pédron <dumbbell@FreeBSD.org>
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are
+ * met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in
+ * the documentation and/or other materials provided with the
+ * distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``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 OR CONTRIBUTORS 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.
+ */
+
+#ifndef _LINUXKPI_LINUX_PAGEFLAGS_H_
+#define _LINUXKPI_LINUX_PAGEFLAGS_H_
+
+#include <linux/mm_types.h>
+
+#define PageHighMem(p) (0)
+
+#define page_folio(p) \
+ (_Generic((p), \
+ const struct page *: (const struct folio *)(p), \
+ struct page *: (struct folio *)(p)))
+
+#endif /* _LINUXKPI_LINUX_PAGEFLAGS_H_ */
diff --git a/sys/compat/linuxkpi/common/include/linux/page.h b/sys/compat/linuxkpi/common/include/linux/page.h
index 0c3d456d6ec0..37ab593a64e9 100644
--- a/sys/compat/linuxkpi/common/include/linux/page.h
+++ b/sys/compat/linuxkpi/common/include/linux/page.h
@@ -25,11 +25,9 @@
* 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.
- *
- * $FreeBSD$
*/
-#ifndef _LINUX_PAGE_H_
-#define _LINUX_PAGE_H_
+#ifndef _LINUXKPI_LINUX_PAGE_H_
+#define _LINUXKPI_LINUX_PAGE_H_
#include <linux/types.h>
@@ -74,6 +72,7 @@ pgprot2cachemode(pgprot_t prot)
return (VM_MEMATTR_DEFAULT);
}
+#define page_to_virt(page) linux_page_address(page)
#define virt_to_page(x) PHYS_TO_VM_PAGE(vtophys(x))
#define page_to_pfn(pp) (VM_PAGE_TO_PHYS(pp) >> PAGE_SHIFT)
#define pfn_to_page(pfn) (PHYS_TO_VM_PAGE((pfn) << PAGE_SHIFT))
@@ -105,6 +104,7 @@ pgprot2cachemode(pgprot_t prot)
#define trunc_page(x) ((uintptr_t)(x) & ~(PAGE_SIZE - 1))
#if defined(__i386__) || defined(__amd64__)
+#undef clflush
#undef clflushopt
static inline void
lkpi_clflushopt(unsigned long addr)
@@ -116,7 +116,15 @@ lkpi_clflushopt(unsigned long addr)
else
pmap_invalidate_cache();
}
+#define clflush(x) clflush((unsigned long)(x))
#define clflushopt(x) lkpi_clflushopt((unsigned long)(x))
+
+static inline void
+clflush_cache_range(void *addr, unsigned int size)
+{
+ pmap_force_invalidate_cache_range((vm_offset_t)addr,
+ (vm_offset_t)addr + size);
+}
#endif
-#endif /* _LINUX_PAGE_H_ */
+#endif /* _LINUXKPI_LINUX_PAGE_H_ */
diff --git a/sys/compat/linuxkpi/common/include/linux/pagemap.h b/sys/compat/linuxkpi/common/include/linux/pagemap.h
index 100bcfaeb433..cb6a1820ea8b 100644
--- a/sys/compat/linuxkpi/common/include/linux/pagemap.h
+++ b/sys/compat/linuxkpi/common/include/linux/pagemap.h
@@ -24,22 +24,26 @@
* 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.
- *
- * $FreeBSD$
*/
-#ifndef _LINUX_PAGEMAP_H_
-#define _LINUX_PAGEMAP_H_
+#ifndef _LINUXKPI_LINUX_PAGEMAP_H_
+#define _LINUXKPI_LINUX_PAGEMAP_H_
#include <linux/mm.h>
+#include <linux/highmem.h>
+#include <linux/vmalloc.h>
+
+struct folio_batch;
+
+#define invalidate_mapping_pages(...) \
+ linux_invalidate_mapping_pages(__VA_ARGS__)
+
+unsigned long linux_invalidate_mapping_pages(vm_object_t obj, pgoff_t start,
+ pgoff_t end);
static inline void
-release_pages(struct page **pages, int nr)
+mapping_clear_unevictable(vm_object_t mapping)
{
- int i;
-
- for (i = 0; i < nr; i++)
- put_page(pages[i]);
}
#endif
diff --git a/sys/compat/linuxkpi/common/include/linux/pagevec.h b/sys/compat/linuxkpi/common/include/linux/pagevec.h
new file mode 100644
index 000000000000..0a952e965b5a
--- /dev/null
+++ b/sys/compat/linuxkpi/common/include/linux/pagevec.h
@@ -0,0 +1,137 @@
+/* Public domain. */
+
+#ifndef _LINUXKPI_LINUX_PAGEVEC_H_
+#define _LINUXKPI_LINUX_PAGEVEC_H_
+
+#include <sys/types.h>
+#include <sys/systm.h>
+#include <sys/errno.h>
+
+#include <linux/pagemap.h>
+
+#define PAGEVEC_SIZE 15
+
+struct pagevec {
+ uint8_t nr;
+ struct page *pages[PAGEVEC_SIZE];
+};
+
+static inline unsigned int
+pagevec_space(struct pagevec *pvec)
+{
+ return PAGEVEC_SIZE - pvec->nr;
+}
+
+static inline void
+pagevec_init(struct pagevec *pvec)
+{
+ pvec->nr = 0;
+}
+
+static inline void
+pagevec_reinit(struct pagevec *pvec)
+{
+ pvec->nr = 0;
+}
+
+static inline unsigned int
+pagevec_count(struct pagevec *pvec)
+{
+ return pvec->nr;
+}
+
+static inline unsigned int
+pagevec_add(struct pagevec *pvec, struct page *page)
+{
+ pvec->pages[pvec->nr++] = page;
+ return PAGEVEC_SIZE - pvec->nr;
+}
+
+static inline void
+__pagevec_release(struct pagevec *pvec)
+{
+ release_pages(pvec->pages, pagevec_count(pvec));
+ pagevec_reinit(pvec);
+}
+
+static inline void
+pagevec_release(struct pagevec *pvec)
+{
+ if (pagevec_count(pvec))
+ __pagevec_release(pvec);
+}
+
+static inline void
+check_move_unevictable_pages(struct pagevec *pvec)
+{
+}
+
+/*
+ * struct folio
+ *
+ * On Linux, `struct folio` replaces `struct page`. To manage a list of folios,
+ * there is `struct folio_batch` on top of this, which replaces `struct
+ * pagevec` above.
+ *
+ * Here is the original description when `struct folio` was added to the Linux
+ * kernel:
+ * "A struct folio is a new abstraction to replace the venerable struct page.
+ * A function which takes a struct folio argument declares that it will
+ * operate on the entire (possibly compound) page, not just PAGE_SIZE bytes.
+ * In return, the caller guarantees that the pointer it is passing does not
+ * point to a tail page. No change to generated code."
+ */
+
+struct folio;
+
+struct folio_batch {
+ uint8_t nr;
+ struct folio *folios[PAGEVEC_SIZE];
+};
+
+static inline void
+folio_batch_init(struct folio_batch *fbatch)
+{
+ fbatch->nr = 0;
+}
+
+static inline void
+folio_batch_reinit(struct folio_batch *fbatch)
+{
+ fbatch->nr = 0;
+}
+
+static inline unsigned int
+folio_batch_count(struct folio_batch *fbatch)
+{
+ return (fbatch->nr);
+}
+
+static inline unsigned int
+folio_batch_space(struct folio_batch *fbatch)
+{
+ return (PAGEVEC_SIZE - fbatch->nr);
+}
+
+static inline unsigned int
+folio_batch_add(struct folio_batch *fbatch, struct folio *folio)
+{
+ KASSERT(
+ fbatch->nr < PAGEVEC_SIZE,
+ ("struct folio_batch %p is full", fbatch));
+
+ fbatch->folios[fbatch->nr++] = folio;
+
+ return (folio_batch_space(fbatch));
+}
+
+void __folio_batch_release(struct folio_batch *fbatch);
+
+static inline void
+folio_batch_release(struct folio_batch *fbatch)
+{
+ if (folio_batch_count(fbatch))
+ __folio_batch_release(fbatch);
+}
+
+#endif /* _LINUXKPI_LINUX_PAGEVEC_H_ */
diff --git a/sys/compat/linuxkpi/common/include/linux/pci.h b/sys/compat/linuxkpi/common/include/linux/pci.h
index 1b4f55c2a2e5..06336bf963d6 100644
--- a/sys/compat/linuxkpi/common/include/linux/pci.h
+++ b/sys/compat/linuxkpi/common/include/linux/pci.h
@@ -4,7 +4,7 @@
* Copyright (c) 2010 Panasas, Inc.
* Copyright (c) 2013-2016 Mellanox Technologies, Ltd.
* All rights reserved.
- * Copyright (c) 2020-2021 The FreeBSD Foundation
+ * Copyright (c) 2020-2025 The FreeBSD Foundation
*
* Portions of this software were developed by Björn Zeeb
* under sponsorship from the FreeBSD Foundation.
@@ -29,22 +29,20 @@
* 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.
- *
- * $FreeBSD$
*/
-#ifndef _LINUX_PCI_H_
-#define _LINUX_PCI_H_
+#ifndef _LINUXKPI_LINUX_PCI_H_
+#define _LINUXKPI_LINUX_PCI_H_
#define CONFIG_PCI_MSI
#include <linux/types.h>
+#include <linux/device/driver.h>
#include <sys/param.h>
#include <sys/bus.h>
+#include <sys/module.h>
#include <sys/nv.h>
#include <sys/pciio.h>
-#include <sys/rman.h>
-#include <sys/bus.h>
#include <dev/pci/pcivar.h>
#include <dev/pci/pcireg.h>
#include <dev/pci/pci_private.h>
@@ -57,8 +55,12 @@
#include <linux/compiler.h>
#include <linux/errno.h>
#include <asm/atomic.h>
+#include <asm/memtype.h>
#include <linux/device.h>
#include <linux/pci_ids.h>
+#include <linux/pm.h>
+
+#include <linux/kernel.h> /* pr_debug */
struct pci_device_id {
uint32_t vendor;
@@ -70,7 +72,27 @@ struct pci_device_id {
uintptr_t driver_data;
};
-#define MODULE_DEVICE_TABLE(bus, table)
+#define MODULE_DEVICE_TABLE_BUS_pci(_bus, _table) \
+MODULE_PNP_INFO("U32:vendor;U32:device;V32:subvendor;V32:subdevice", \
+ _bus, lkpi_ ## _table, _table, nitems(_table) - 1)
+
+/* Linux has an empty element at the end of the ID table -> nitems() - 1. */
+#define MODULE_DEVICE_TABLE(_bus, _table) \
+ \
+static device_method_t _ ## _bus ## _ ## _table ## _methods[] = { \
+ DEVMETHOD_END \
+}; \
+ \
+static driver_t _ ## _bus ## _ ## _table ## _driver = { \
+ "lkpi_" #_bus #_table, \
+ _ ## _bus ## _ ## _table ## _methods, \
+ 0 \
+}; \
+ \
+DRIVER_MODULE(lkpi_ ## _table, _bus, _ ## _bus ## _ ## _table ## _driver,\
+ 0, 0); \
+ \
+MODULE_DEVICE_TABLE_BUS_ ## _bus(_bus, _table)
#define PCI_ANY_ID -1U
@@ -78,6 +100,7 @@ struct pci_device_id {
#define PCI_SLOT(devfn) (((devfn) >> 3) & 0x1f)
#define PCI_FUNC(devfn) ((devfn) & 0x07)
#define PCI_BUS_NUM(devfn) (((devfn) >> 8) & 0xff)
+#define PCI_DEVID(bus, devfn) ((((uint16_t)(bus)) << 8) | (devfn))
#define PCI_VDEVICE(_vendor, _device) \
.vendor = PCI_VENDOR_ID_##_vendor, .device = (_device), \
@@ -88,14 +111,25 @@ struct pci_device_id {
#define to_pci_dev(n) container_of(n, struct pci_dev, dev)
-#define PCI_VENDOR_ID PCIR_DEVVENDOR
+#define PCI_STD_NUM_BARS 6
+#define PCI_BASE_ADDRESS_0 PCIR_BARS
+#define PCI_BASE_ADDRESS_MEM_TYPE_64 PCIM_BAR_MEM_64
+#define PCI_VENDOR_ID PCIR_VENDOR
+#define PCI_DEVICE_ID PCIR_DEVICE
#define PCI_COMMAND PCIR_COMMAND
#define PCI_COMMAND_INTX_DISABLE PCIM_CMD_INTxDIS
+#define PCI_COMMAND_MEMORY PCIM_CMD_MEMEN
+#define PCI_PRIMARY_BUS PCIR_PRIBUS_1
+#define PCI_SECONDARY_BUS PCIR_SECBUS_1
+#define PCI_SUBORDINATE_BUS PCIR_SUBBUS_1
+#define PCI_SEC_LATENCY_TIMER PCIR_SECLAT_1
#define PCI_EXP_DEVCTL PCIER_DEVICE_CTL /* Device Control */
#define PCI_EXP_LNKCTL PCIER_LINK_CTL /* Link Control */
#define PCI_EXP_LNKCTL_ASPM_L0S PCIEM_LINK_CTL_ASPMC_L0S
#define PCI_EXP_LNKCTL_ASPM_L1 PCIEM_LINK_CTL_ASPMC_L1
+#define PCI_EXP_LNKCTL_ASPMC PCIEM_LINK_CTL_ASPMC
#define PCI_EXP_LNKCTL_CLKREQ_EN PCIEM_LINK_CTL_ECPM /* Enable clock PM */
+#define PCI_EXP_LNKCTL_HAWD PCIEM_LINK_CTL_HAWD
#define PCI_EXP_FLAGS_TYPE PCIEM_FLAGS_TYPE /* Device/Port type */
#define PCI_EXP_DEVCAP PCIER_DEVICE_CAP /* Device capabilities */
#define PCI_EXP_DEVSTA PCIER_DEVICE_STA /* Device Status */
@@ -110,6 +144,7 @@ struct pci_device_id {
#define PCI_EXP_DEVCAP2 PCIER_DEVICE_CAP2 /* Device Capabilities 2 */
#define PCI_EXP_DEVCTL2 PCIER_DEVICE_CTL2 /* Device Control 2 */
#define PCI_EXP_DEVCTL2_LTR_EN PCIEM_CTL2_LTR_ENABLE
+#define PCI_EXP_DEVCTL2_COMP_TMOUT_DIS PCIEM_CTL2_COMP_TIMO_DISABLE
#define PCI_EXP_LNKCAP2 PCIER_LINK_CAP2 /* Link Capabilities 2 */
#define PCI_EXP_LNKCTL2 PCIER_LINK_CTL2 /* Link Control 2 */
#define PCI_EXP_LNKSTA2 PCIER_LINK_STA2 /* Link Status 2 */
@@ -121,25 +156,38 @@ struct pci_device_id {
#define PCI_EXP_TYPE_DOWNSTREAM PCIEM_TYPE_DOWNSTREAM_PORT /* Downstream Port */
#define PCI_EXP_FLAGS_SLOT PCIEM_FLAGS_SLOT /* Slot implemented */
#define PCI_EXP_TYPE_RC_EC PCIEM_TYPE_ROOT_EC /* Root Complex Event Collector */
+#define PCI_EXP_LNKSTA_CLS PCIEM_LINK_STA_SPEED
+#define PCI_EXP_LNKSTA_CLS_8_0GB 0x0003 /* Current Link Speed 8.0GT/s */
#define PCI_EXP_LNKCAP_SLS_2_5GB 0x01 /* Supported Link Speed 2.5GT/s */
#define PCI_EXP_LNKCAP_SLS_5_0GB 0x02 /* Supported Link Speed 5.0GT/s */
-#define PCI_EXP_LNKCAP_SLS_8_0GB 0x04 /* Supported Link Speed 8.0GT/s */
-#define PCI_EXP_LNKCAP_SLS_16_0GB 0x08 /* Supported Link Speed 16.0GT/s */
+#define PCI_EXP_LNKCAP_SLS_8_0GB 0x03 /* Supported Link Speed 8.0GT/s */
+#define PCI_EXP_LNKCAP_SLS_16_0GB 0x04 /* Supported Link Speed 16.0GT/s */
+#define PCI_EXP_LNKCAP_SLS_32_0GB 0x05 /* Supported Link Speed 32.0GT/s */
+#define PCI_EXP_LNKCAP_SLS_64_0GB 0x06 /* Supported Link Speed 64.0GT/s */
#define PCI_EXP_LNKCAP_MLW 0x03f0 /* Maximum Link Width */
#define PCI_EXP_LNKCAP2_SLS_2_5GB 0x02 /* Supported Link Speed 2.5GT/s */
#define PCI_EXP_LNKCAP2_SLS_5_0GB 0x04 /* Supported Link Speed 5.0GT/s */
#define PCI_EXP_LNKCAP2_SLS_8_0GB 0x08 /* Supported Link Speed 8.0GT/s */
#define PCI_EXP_LNKCAP2_SLS_16_0GB 0x10 /* Supported Link Speed 16.0GT/s */
+#define PCI_EXP_LNKCAP2_SLS_32_0GB 0x20 /* Supported Link Speed 32.0GT/s */
+#define PCI_EXP_LNKCAP2_SLS_64_0GB 0x40 /* Supported Link Speed 64.0GT/s */
#define PCI_EXP_LNKCTL2_TLS 0x000f
#define PCI_EXP_LNKCTL2_TLS_2_5GT 0x0001 /* Supported Speed 2.5GT/s */
#define PCI_EXP_LNKCTL2_TLS_5_0GT 0x0002 /* Supported Speed 5GT/s */
#define PCI_EXP_LNKCTL2_TLS_8_0GT 0x0003 /* Supported Speed 8GT/s */
#define PCI_EXP_LNKCTL2_TLS_16_0GT 0x0004 /* Supported Speed 16GT/s */
#define PCI_EXP_LNKCTL2_TLS_32_0GT 0x0005 /* Supported Speed 32GT/s */
+#define PCI_EXP_LNKCTL2_TLS_64_0GT 0x0006 /* Supported Speed 64GT/s */
#define PCI_EXP_LNKCTL2_ENTER_COMP 0x0010 /* Enter Compliance */
#define PCI_EXP_LNKCTL2_TX_MARGIN 0x0380 /* Transmit Margin */
-#define PCI_EXP_LNKCTL_HAWD PCIEM_LINK_CTL_HAWD
+#define PCI_MSI_ADDRESS_LO PCIR_MSI_ADDR
+#define PCI_MSI_ADDRESS_HI PCIR_MSI_ADDR_HIGH
+#define PCI_MSI_FLAGS PCIR_MSI_CTRL
+#define PCI_MSI_FLAGS_ENABLE PCIM_MSICTRL_MSI_ENABLE
+#define PCI_MSIX_FLAGS PCIR_MSIX_CTRL
+#define PCI_MSIX_FLAGS_ENABLE PCIM_MSIXCTRL_MSIX_ENABLE
+
#define PCI_EXP_LNKCAP_CLKPM 0x00040000
#define PCI_EXP_DEVSTA_TRPND 0x0020
@@ -153,6 +201,8 @@ enum pci_bus_speed {
PCIE_SPEED_5_0GT,
PCIE_SPEED_8_0GT,
PCIE_SPEED_16_0GT,
+ PCIE_SPEED_32_0GT,
+ PCIE_SPEED_64_0GT,
};
enum pcie_link_width {
@@ -173,22 +223,35 @@ enum pcie_link_width {
typedef int pci_power_t;
-#define PCI_D0 PCI_POWERSTATE_D0
-#define PCI_D1 PCI_POWERSTATE_D1
-#define PCI_D2 PCI_POWERSTATE_D2
-#define PCI_D3hot PCI_POWERSTATE_D3
-#define PCI_D3cold 4
+#define PCI_D0 PCI_POWERSTATE_D0
+#define PCI_D1 PCI_POWERSTATE_D1
+#define PCI_D2 PCI_POWERSTATE_D2
+#define PCI_D3hot PCI_POWERSTATE_D3_HOT
+#define PCI_D3cold PCI_POWERSTATE_D3_COLD
#define PCI_POWER_ERROR PCI_POWERSTATE_UNKNOWN
+extern const char *pci_power_names[6];
+
+#define PCI_ERR_UNCOR_STATUS PCIR_AER_UC_STATUS
+#define PCI_ERR_COR_STATUS PCIR_AER_COR_STATUS
#define PCI_ERR_ROOT_COMMAND PCIR_AER_ROOTERR_CMD
#define PCI_ERR_ROOT_ERR_SRC PCIR_AER_COR_SOURCE_ID
#define PCI_EXT_CAP_ID_ERR PCIZ_AER
+#define PCI_EXT_CAP_ID_L1SS PCIZ_L1PM
+
+#define PCI_L1SS_CTL1 0x8
+#define PCI_L1SS_CTL1_L1SS_MASK 0xf
-#define PCI_IRQ_LEGACY 0x01
+#define PCI_IRQ_INTX 0x01
#define PCI_IRQ_MSI 0x02
#define PCI_IRQ_MSIX 0x04
+#define PCI_IRQ_ALL_TYPES (PCI_IRQ_MSIX|PCI_IRQ_MSI|PCI_IRQ_INTX)
+
+#if defined(LINUXKPI_VERSION) && (LINUXKPI_VERSION <= 61000)
+#define PCI_IRQ_LEGACY PCI_IRQ_INTX
+#endif
struct pci_dev;
@@ -206,6 +269,7 @@ struct pci_driver {
struct device_driver driver;
const struct pci_error_handlers *err_handler;
bool isdrm;
+ int bsd_probe_return;
int (*bsd_iov_init)(device_t dev, uint16_t num_vfs,
const nvlist_t *pf_config);
void (*bsd_iov_uninit)(device_t dev);
@@ -215,6 +279,7 @@ struct pci_driver {
struct pci_bus {
struct pci_dev *self;
+ /* struct pci_bus *parent */
int domain;
int number;
};
@@ -225,29 +290,34 @@ extern spinlock_t pci_lock;
#define __devexit_p(x) x
-#define module_pci_driver(_driver) \
- \
-static inline int \
-_pci_init(void) \
-{ \
- \
- return (linux_pci_register_driver(&_driver)); \
-} \
- \
-static inline void \
-_pci_exit(void) \
-{ \
- \
- linux_pci_unregister_driver(&_driver); \
-} \
- \
-module_init(_pci_init); \
-module_exit(_pci_exit)
+#define module_pci_driver(_drv) \
+ module_driver(_drv, linux_pci_register_driver, linux_pci_unregister_driver)
+
+struct msi_msg {
+ uint32_t data;
+};
+
+struct pci_msi_desc {
+ struct {
+ bool is_64;
+ } msi_attrib;
+};
+
+struct msi_desc {
+ struct msi_msg msg;
+ struct pci_msi_desc pci;
+};
+
+struct msix_entry {
+ int entry;
+ int vector;
+};
/*
* If we find drivers accessing this from multiple KPIs we may have to
* refcount objects of this structure.
*/
+struct resource;
struct pci_mmio_region {
TAILQ_ENTRY(pci_mmio_region) next;
struct resource *res;
@@ -261,6 +331,7 @@ struct pci_dev {
struct pci_driver *pdrv;
struct pci_bus *bus;
struct pci_dev *root;
+ pci_power_t current_state;
uint16_t device;
uint16_t vendor;
uint16_t subsystem_vendor;
@@ -269,32 +340,67 @@ struct pci_dev {
unsigned int devfn;
uint32_t class;
uint8_t revision;
+ uint8_t msi_cap;
+ uint8_t msix_cap;
bool managed; /* devres "pcim_*(). */
bool want_iomap_res;
bool msi_enabled;
bool msix_enabled;
phys_addr_t rom;
size_t romlen;
+ struct msi_desc **msi_desc;
+ char *path_name;
+ spinlock_t pcie_cap_lock;
TAILQ_HEAD(, pci_mmio_region) mmio;
};
-/* We need some meta-struct to keep track of these for devres. */
-struct pci_devres {
- bool enable_io;
- /* PCIR_MAX_BAR_0 + 1 = 6 => BIT(0..5). */
- uint8_t region_mask;
- struct resource *region_table[PCIR_MAX_BAR_0 + 1]; /* Not needed. */
-};
-struct pcim_iomap_devres {
- void *mmio_table[PCIR_MAX_BAR_0 + 1];
- struct resource *res_table[PCIR_MAX_BAR_0 + 1];
-};
+int pci_alloc_irq_vectors(struct pci_dev *pdev, int minv, int maxv,
+ unsigned int flags);
+bool pci_device_is_present(struct pci_dev *pdev);
+
+int linuxkpi_pcim_enable_device(struct pci_dev *pdev);
+void __iomem **linuxkpi_pcim_iomap_table(struct pci_dev *pdev);
+void *linuxkpi_pci_iomap_range(struct pci_dev *, int,
+ unsigned long, unsigned long);
+void *linuxkpi_pci_iomap(struct pci_dev *, int, unsigned long);
+void *linuxkpi_pcim_iomap(struct pci_dev *, int, unsigned long);
+void linuxkpi_pci_iounmap(struct pci_dev *pdev, void *res);
+int linuxkpi_pcim_iomap_regions(struct pci_dev *pdev, uint32_t mask,
+ const char *name);
+int linuxkpi_pci_request_region(struct pci_dev *, int, const char *);
+int linuxkpi_pci_request_regions(struct pci_dev *pdev, const char *res_name);
+int linuxkpi_pcim_request_all_regions(struct pci_dev *, const char *);
+void linuxkpi_pci_release_region(struct pci_dev *pdev, int bar);
+void linuxkpi_pci_release_regions(struct pci_dev *pdev);
+int linuxkpi_pci_enable_msix(struct pci_dev *pdev, struct msix_entry *entries,
+ int nreq);
/* Internal helper function(s). */
struct pci_dev *lkpinew_pci_dev(device_t);
void lkpi_pci_devres_release(struct device *, void *);
-void lkpi_pcim_iomap_table_release(struct device *, void *);
+struct pci_dev *lkpi_pci_get_device(uint32_t, uint32_t, struct pci_dev *);
+struct msi_desc *lkpi_pci_msi_desc_alloc(int);
+struct device *lkpi_pci_find_irq_dev(unsigned int irq);
+int _lkpi_pci_enable_msi_range(struct pci_dev *pdev, int minvec, int maxvec);
+
+#define pci_err(pdev, fmt, ...) \
+ dev_err(&(pdev)->dev, fmt, ##__VA_ARGS__)
+#define pci_info(pdev, fmt, ...) \
+ dev_info(&(pdev)->dev, fmt, ##__VA_ARGS__)
+
+static inline bool
+dev_is_pci(struct device *dev)
+{
+
+ return (device_get_devclass(dev->bsddev) == devclass_find("pci"));
+}
+
+static inline uint16_t
+pci_dev_id(struct pci_dev *pdev)
+{
+ return (PCI_DEVID(pdev->bus->number, pdev->devfn));
+}
static inline int
pci_resource_type(struct pci_dev *pdev, int bar)
@@ -311,56 +417,6 @@ pci_resource_type(struct pci_dev *pdev, int bar)
return (SYS_RES_MEMORY);
}
-struct resource_list_entry *linux_pci_reserve_bar(struct pci_dev *pdev,
- struct resource_list *rl, int type, int rid);
-
-static inline struct resource_list_entry *
-linux_pci_get_rle(struct pci_dev *pdev, int type, int rid, bool reserve_bar)
-{
- struct pci_devinfo *dinfo;
- struct resource_list *rl;
- struct resource_list_entry *rle;
-
- dinfo = device_get_ivars(pdev->dev.bsddev);
- rl = &dinfo->resources;
- rle = resource_list_find(rl, type, rid);
- /* Reserve resources for this BAR if needed. */
- if (rle == NULL && reserve_bar)
- rle = linux_pci_reserve_bar(pdev, rl, type, rid);
- return (rle);
-}
-
-static inline struct resource_list_entry *
-linux_pci_get_bar(struct pci_dev *pdev, int bar, bool reserve)
-{
- int type;
-
- type = pci_resource_type(pdev, bar);
- if (type < 0)
- return (NULL);
- bar = PCIR_BAR(bar);
- return (linux_pci_get_rle(pdev, type, bar, reserve));
-}
-
-static inline struct device *
-linux_pci_find_irq_dev(unsigned int irq)
-{
- struct pci_dev *pdev;
- struct device *found;
-
- found = NULL;
- spin_lock(&pci_lock);
- list_for_each_entry(pdev, &pci_devices, links) {
- if (irq == pdev->dev.irq ||
- (irq >= pdev->dev.irq_start && irq < pdev->dev.irq_end)) {
- found = &pdev->dev;
- break;
- }
- }
- spin_unlock(&pci_lock);
- return (found);
-}
-
/*
* All drivers just seem to want to inspect the type not flags.
*/
@@ -378,8 +434,7 @@ pci_resource_flags(struct pci_dev *pdev, int bar)
static inline const char *
pci_name(struct pci_dev *d)
{
-
- return device_get_desc(d->dev.bsddev);
+ return d->path_name;
}
static inline void *
@@ -453,132 +508,71 @@ pci_clear_master(struct pci_dev *pdev)
return (0);
}
-static inline struct pci_devres *
-lkpi_pci_devres_get_alloc(struct pci_dev *pdev)
-{
- struct pci_devres *dr;
-
- dr = lkpi_devres_find(&pdev->dev, lkpi_pci_devres_release, NULL, NULL);
- if (dr == NULL) {
- dr = lkpi_devres_alloc(lkpi_pci_devres_release, sizeof(*dr),
- GFP_KERNEL | __GFP_ZERO);
- if (dr != NULL)
- lkpi_devres_add(&pdev->dev, dr);
- }
-
- return (dr);
-}
-static inline struct pci_devres *
-lkpi_pci_devres_find(struct pci_dev *pdev)
-{
-
- if (!pdev->managed)
- return (NULL);
-
- return (lkpi_pci_devres_get_alloc(pdev));
-}
-
-static inline int
-pci_request_region(struct pci_dev *pdev, int bar, const char *res_name)
+static inline bool
+pci_is_root_bus(struct pci_bus *pbus)
{
- struct resource *res;
- struct pci_devres *dr;
- struct pci_mmio_region *mmio;
- int rid;
- int type;
- type = pci_resource_type(pdev, bar);
- if (type < 0)
- return (-ENODEV);
- rid = PCIR_BAR(bar);
- res = bus_alloc_resource_any(pdev->dev.bsddev, type, &rid,
- RF_ACTIVE|RF_SHAREABLE);
- if (res == NULL) {
- device_printf(pdev->dev.bsddev, "%s: failed to alloc "
- "bar %d type %d rid %d\n",
- __func__, bar, type, PCIR_BAR(bar));
- return (-ENODEV);
- }
-
- /*
- * It seems there is an implicit devres tracking on these if the device
- * is managed; otherwise the resources are not automatiaclly freed on
- * FreeBSD/LinuxKPI tough they should be/are expected to be by Linux
- * drivers.
- */
- dr = lkpi_pci_devres_find(pdev);
- if (dr != NULL) {
- dr->region_mask |= (1 << bar);
- dr->region_table[bar] = res;
- }
-
- /* Even if the device is not managed we need to track it for iomap. */
- mmio = malloc(sizeof(*mmio), M_DEVBUF, M_WAITOK | M_ZERO);
- mmio->rid = PCIR_BAR(bar);
- mmio->type = type;
- mmio->res = res;
- TAILQ_INSERT_TAIL(&pdev->mmio, mmio, next);
-
- return (0);
+ return (pbus->self == NULL);
}
-static inline void
-pci_release_region(struct pci_dev *pdev, int bar)
+static inline struct pci_dev *
+pci_upstream_bridge(struct pci_dev *pdev)
{
- struct resource_list_entry *rle;
- struct pci_devres *dr;
- struct pci_mmio_region *mmio, *p;
- if ((rle = linux_pci_get_bar(pdev, bar, false)) == NULL)
- return;
+ if (pci_is_root_bus(pdev->bus))
+ return (NULL);
/*
- * As we implicitly track the requests we also need to clear them on
- * release. Do clear before resource release.
+ * If we do not have a (proper) "upstream bridge" set, e.g., we point
+ * to ourselves, try to handle this case on the fly like we do
+ * for pcie_find_root_port().
*/
- dr = lkpi_pci_devres_find(pdev);
- if (dr != NULL) {
- KASSERT(dr->region_table[bar] == rle->res, ("%s: pdev %p bar %d"
- " region_table res %p != rel->res %p\n", __func__, pdev,
- bar, dr->region_table[bar], rle->res));
- dr->region_table[bar] = NULL;
- dr->region_mask &= ~(1 << bar);
+ if (pdev == pdev->bus->self) {
+ device_t bridge;
+
+ /*
+ * In the case of DRM drivers, the passed device is a child of
+ * `vgapci`. We want to start the lookup from `vgapci`, so the
+ * parent of the passed `drmn`.
+ *
+ * We can use the `isdrm` flag to determine this.
+ */
+ bridge = pdev->dev.bsddev;
+ if (pdev->pdrv != NULL && pdev->pdrv->isdrm)
+ bridge = device_get_parent(bridge);
+ if (bridge == NULL)
+ goto done;
+
+ bridge = device_get_parent(bridge);
+ if (bridge == NULL)
+ goto done;
+ bridge = device_get_parent(bridge);
+ if (bridge == NULL)
+ goto done;
+ if (device_get_devclass(device_get_parent(bridge)) !=
+ devclass_find("pci"))
+ goto done;
+
+ /*
+ * "bridge" is a PCI-to-PCI bridge. Create a Linux pci_dev
+ * for it so it can be returned.
+ */
+ pdev->bus->self = lkpinew_pci_dev(bridge);
}
-
- TAILQ_FOREACH_SAFE(mmio, &pdev->mmio, next, p) {
- if (rle->res != (void *)rman_get_bushandle(mmio->res))
- continue;
- TAILQ_REMOVE(&pdev->mmio, mmio, next);
- free(mmio, M_DEVBUF);
- }
-
- bus_release_resource(pdev->dev.bsddev, rle->type, rle->rid, rle->res);
-}
-
-static inline void
-pci_release_regions(struct pci_dev *pdev)
-{
- int i;
-
- for (i = 0; i <= PCIR_MAX_BAR_0; i++)
- pci_release_region(pdev, i);
+done:
+ return (pdev->bus->self);
}
-static inline int
-pci_request_regions(struct pci_dev *pdev, const char *res_name)
-{
- int error;
- int i;
-
- for (i = 0; i <= PCIR_MAX_BAR_0; i++) {
- error = pci_request_region(pdev, i, res_name);
- if (error && error != -ENODEV) {
- pci_release_regions(pdev);
- return (error);
- }
- }
- return (0);
-}
+#define pci_request_region(pdev, bar, res_name) \
+ linuxkpi_pci_request_region(pdev, bar, res_name)
+#define pci_release_region(pdev, bar) \
+ linuxkpi_pci_release_region(pdev, bar)
+#define pci_request_regions(pdev, res_name) \
+ linuxkpi_pci_request_regions(pdev, res_name)
+#define pci_release_regions(pdev) \
+ linuxkpi_pci_release_regions(pdev)
+#define pcim_request_all_regions(pdev, name) \
+ linuxkpi_pcim_request_all_regions(pdev, name)
static inline void
lkpi_pci_disable_msix(struct pci_dev *pdev)
@@ -589,7 +583,7 @@ lkpi_pci_disable_msix(struct pci_dev *pdev)
/*
* The MSIX IRQ numbers associated with this PCI device are no
* longer valid and might be re-assigned. Make sure
- * linux_pci_find_irq_dev() does no longer see them by
+ * lkpi_pci_find_irq_dev() does no longer see them by
* resetting their references to zero:
*/
pdev->dev.irq_start = 0;
@@ -744,13 +738,10 @@ int linux_pci_register_drm_driver(struct pci_driver *pdrv);
void linux_pci_unregister_driver(struct pci_driver *pdrv);
void linux_pci_unregister_drm_driver(struct pci_driver *pdrv);
-#define pci_register_driver(pdrv) linux_pci_register_driver(pdrv)
-#define pci_unregister_driver(pdrv) linux_pci_unregister_driver(pdrv)
-
-struct msix_entry {
- int entry;
- int vector;
-};
+#define pci_register_driver(pdrv) \
+ linux_pci_register_driver(pdrv)
+#define pci_unregister_driver(pdrv) \
+ linux_pci_unregister_driver(pdrv)
/*
* Enable msix, positive errors indicate actual number of available
@@ -759,45 +750,11 @@ struct msix_entry {
* NB: define added to prevent this definition of pci_enable_msix from
* clashing with the native FreeBSD version.
*/
-#define pci_enable_msix(...) \
- linux_pci_enable_msix(__VA_ARGS__)
-
-static inline int
-pci_enable_msix(struct pci_dev *pdev, struct msix_entry *entries, int nreq)
-{
- struct resource_list_entry *rle;
- int error;
- int avail;
- int i;
-
- avail = pci_msix_count(pdev->dev.bsddev);
- if (avail < nreq) {
- if (avail == 0)
- return -EINVAL;
- return avail;
- }
- avail = nreq;
- if ((error = -pci_alloc_msix(pdev->dev.bsddev, &avail)) != 0)
- return error;
- /*
- * Handle case where "pci_alloc_msix()" may allocate less
- * interrupts than available and return with no error:
- */
- if (avail < nreq) {
- pci_release_msi(pdev->dev.bsddev);
- return avail;
- }
- rle = linux_pci_get_rle(pdev, SYS_RES_IRQ, 1, false);
- pdev->dev.irq_start = rle->start;
- pdev->dev.irq_end = rle->start + avail;
- for (i = 0; i < nreq; i++)
- entries[i].vector = pdev->dev.irq_start + i;
- pdev->msix_enabled = true;
- return (0);
-}
+#define pci_enable_msix(...) \
+ linuxkpi_pci_enable_msix(__VA_ARGS__)
-#define pci_enable_msix_range(...) \
- linux_pci_enable_msix_range(__VA_ARGS__)
+#define pci_enable_msix_range(...) \
+ linux_pci_enable_msix_range(__VA_ARGS__)
static inline int
pci_enable_msix_range(struct pci_dev *dev, struct msix_entry *entries,
@@ -822,66 +779,14 @@ pci_enable_msix_range(struct pci_dev *dev, struct msix_entry *entries,
return (nvec);
}
-#define pci_enable_msi(pdev) \
- linux_pci_enable_msi(pdev)
+#define pci_enable_msi(pdev) \
+ linux_pci_enable_msi(pdev)
static inline int
pci_enable_msi(struct pci_dev *pdev)
{
- struct resource_list_entry *rle;
- int error;
- int avail;
-
- avail = pci_msi_count(pdev->dev.bsddev);
- if (avail < 1)
- return -EINVAL;
-
- avail = 1; /* this function only enable one MSI IRQ */
- if ((error = -pci_alloc_msi(pdev->dev.bsddev, &avail)) != 0)
- return error;
-
- rle = linux_pci_get_rle(pdev, SYS_RES_IRQ, 1, false);
- pdev->dev.irq_start = rle->start;
- pdev->dev.irq_end = rle->start + avail;
- pdev->irq = rle->start;
- pdev->msi_enabled = true;
- return (0);
-}
-
-static inline int
-pci_alloc_irq_vectors(struct pci_dev *pdev, int minv, int maxv,
- unsigned int flags)
-{
- int error;
-
- if (flags & PCI_IRQ_MSIX) {
- struct msix_entry *entries;
- int i;
-
- entries = kcalloc(maxv, sizeof(*entries), GFP_KERNEL);
- if (entries == NULL) {
- error = -ENOMEM;
- goto out;
- }
- for (i = 0; i < maxv; ++i)
- entries[i].entry = i;
- error = pci_enable_msix(pdev, entries, maxv);
-out:
- kfree(entries);
- if (error == 0 && pdev->msix_enabled)
- return (pdev->dev.irq_end - pdev->dev.irq_start);
- }
- if (flags & PCI_IRQ_MSI) {
- error = pci_enable_msi(pdev);
- if (error == 0 && pdev->msi_enabled)
- return (pdev->dev.irq_end - pdev->dev.irq_start);
- }
- if (flags & PCI_IRQ_LEGACY) {
- if (pdev->irq)
- return (1);
- }
- return (-EINVAL);
+ return (_lkpi_pci_enable_msi_range(pdev, 1, 1));
}
static inline int
@@ -895,79 +800,19 @@ static inline int pci_enable_sriov(struct pci_dev *dev, int nr_virtfn)
{
return -ENODEV;
}
-static inline void pci_disable_sriov(struct pci_dev *dev)
-{
-}
-
-static inline struct resource *
-_lkpi_pci_iomap(struct pci_dev *pdev, int bar, int mmio_size __unused)
-{
- struct pci_mmio_region *mmio, *p;
- int type;
-
- type = pci_resource_type(pdev, bar);
- if (type < 0) {
- device_printf(pdev->dev.bsddev, "%s: bar %d type %d\n",
- __func__, bar, type);
- return (NULL);
- }
-
- /*
- * Check for duplicate mappings.
- * This can happen if a driver calls pci_request_region() first.
- */
- TAILQ_FOREACH_SAFE(mmio, &pdev->mmio, next, p) {
- if (mmio->type == type && mmio->rid == PCIR_BAR(bar)) {
- return (mmio->res);
- }
- }
-
- mmio = malloc(sizeof(*mmio), M_DEVBUF, M_WAITOK | M_ZERO);
- mmio->rid = PCIR_BAR(bar);
- mmio->type = type;
- mmio->res = bus_alloc_resource_any(pdev->dev.bsddev, mmio->type,
- &mmio->rid, RF_ACTIVE|RF_SHAREABLE);
- if (mmio->res == NULL) {
- device_printf(pdev->dev.bsddev, "%s: failed to alloc "
- "bar %d type %d rid %d\n",
- __func__, bar, type, PCIR_BAR(bar));
- free(mmio, M_DEVBUF);
- return (NULL);
- }
- TAILQ_INSERT_TAIL(&pdev->mmio, mmio, next);
- return (mmio->res);
-}
-
-static inline void *
-pci_iomap(struct pci_dev *pdev, int mmio_bar, int mmio_size)
+static inline void pci_disable_sriov(struct pci_dev *dev)
{
- struct resource *res;
-
- res = _lkpi_pci_iomap(pdev, mmio_bar, mmio_size);
- if (res == NULL)
- return (NULL);
- /* This is a FreeBSD extension so we can use bus_*(). */
- if (pdev->want_iomap_res)
- return (res);
- return ((void *)rman_get_bushandle(res));
}
-static inline void
-pci_iounmap(struct pci_dev *pdev, void *res)
-{
- struct pci_mmio_region *mmio, *p;
-
- TAILQ_FOREACH_SAFE(mmio, &pdev->mmio, next, p) {
- if (res != (void *)rman_get_bushandle(mmio->res))
- continue;
- bus_release_resource(pdev->dev.bsddev,
- mmio->type, mmio->rid, mmio->res);
- TAILQ_REMOVE(&pdev->mmio, mmio, next);
- free(mmio, M_DEVBUF);
- return;
- }
-}
+#define pci_iomap_range(pdev, mmio_bar, mmio_off, mmio_size) \
+ linuxkpi_pci_iomap_range(pdev, mmio_bar, mmio_off, mmio_size)
+#define pci_iomap(pdev, mmio_bar, mmio_size) \
+ linuxkpi_pci_iomap(pdev, mmio_bar, mmio_size)
+#define pcim_iomap(pdev, bar, maxlen) \
+ linuxkpi_pcim_iomap(pdev, bar, maxlen)
+#define pci_iounmap(pdev, res) \
+ linuxkpi_pci_iounmap(pdev, res)
static inline void
lkpi_pci_save_state(struct pci_dev *pdev)
@@ -986,6 +831,26 @@ lkpi_pci_restore_state(struct pci_dev *pdev)
#define pci_save_state(dev) lkpi_pci_save_state(dev)
#define pci_restore_state(dev) lkpi_pci_restore_state(dev)
+static inline int
+linuxkpi_pci_enable_wake(struct pci_dev *pdev, pci_power_t state, bool ena)
+{
+ /*
+ * We do not currently support this in device.h either to
+ * check if the device is allowed to wake up in first place.
+ */
+ pr_debug("%s: TODO\n", __func__);
+ return (0);
+}
+#define pci_enable_wake(dev, state, ena) \
+ linuxkpi_pci_enable_wake(dev, state, ena)
+
+static inline int
+pci_reset_function(struct pci_dev *pdev)
+{
+
+ return (-ENOSYS);
+}
+
#define DEFINE_PCI_DEVICE_TABLE(_table) \
const struct pci_device_id _table[] __devinitdata
@@ -1170,6 +1035,7 @@ static bool pcie_capability_reg_implemented(struct pci_dev *dev, int pos)
static inline int
pcie_capability_read_dword(struct pci_dev *dev, int pos, u32 *dst)
{
+ *dst = 0;
if (pos & 3)
return -EINVAL;
@@ -1182,6 +1048,7 @@ pcie_capability_read_dword(struct pci_dev *dev, int pos, u32 *dst)
static inline int
pcie_capability_read_word(struct pci_dev *dev, int pos, u16 *dst)
{
+ *dst = 0;
if (pos & 3)
return -EINVAL;
@@ -1203,6 +1070,41 @@ pcie_capability_write_word(struct pci_dev *dev, int pos, u16 val)
return pci_write_config_word(dev, pci_pcie_cap(dev) + pos, val);
}
+static inline int
+pcie_capability_clear_and_set_word(struct pci_dev *dev, int pos,
+ uint16_t clear, uint16_t set)
+{
+ int error;
+ uint16_t v;
+
+ if (pos == PCI_EXP_LNKCTL || pos == PCI_EXP_RTCTL)
+ spin_lock(&dev->pcie_cap_lock);
+
+ error = pcie_capability_read_word(dev, pos, &v);
+ if (error == 0) {
+ v &= ~clear;
+ v |= set;
+ error = pcie_capability_write_word(dev, pos, v);
+ }
+
+ if (pos == PCI_EXP_LNKCTL || pos == PCI_EXP_RTCTL)
+ spin_unlock(&dev->pcie_cap_lock);
+
+ return (error);
+}
+
+static inline int
+pcie_capability_set_word(struct pci_dev *dev, int pos, uint16_t val)
+{
+ return (pcie_capability_clear_and_set_word(dev, pos, 0, val));
+}
+
+static inline int
+pcie_capability_clear_word(struct pci_dev *dev, int pos, uint16_t val)
+{
+ return (pcie_capability_clear_and_set_word(dev, pos, val, 0));
+}
+
static inline int pcie_get_minimum_link(struct pci_dev *dev,
enum pci_bus_speed *speed, enum pcie_link_width *width)
{
@@ -1252,6 +1154,10 @@ pcie_get_speed_cap(struct pci_dev *dev)
return (PCIE_SPEED_8_0GT);
if (lnkcap2 & PCI_EXP_LNKCAP2_SLS_16_0GB)
return (PCIE_SPEED_16_0GT);
+ if (lnkcap2 & PCI_EXP_LNKCAP2_SLS_32_0GB)
+ return (PCIE_SPEED_32_0GT);
+ if (lnkcap2 & PCI_EXP_LNKCAP2_SLS_64_0GB)
+ return (PCIE_SPEED_64_0GT);
} else { /* pre-r3.0 */
lnkcap = pci_read_config(root, pos + PCIER_LINK_CAP, 4);
if (lnkcap & PCI_EXP_LNKCAP_SLS_2_5GB)
@@ -1262,6 +1168,10 @@ pcie_get_speed_cap(struct pci_dev *dev)
return (PCIE_SPEED_8_0GT);
if (lnkcap & PCI_EXP_LNKCAP_SLS_16_0GB)
return (PCIE_SPEED_16_0GT);
+ if (lnkcap & PCI_EXP_LNKCAP_SLS_32_0GB)
+ return (PCIE_SPEED_32_0GT);
+ if (lnkcap & PCI_EXP_LNKCAP_SLS_64_0GB)
+ return (PCIE_SPEED_64_0GT);
}
return (PCI_SPEED_UNKNOWN);
}
@@ -1289,6 +1199,10 @@ PCIE_SPEED2MBS_ENC(enum pci_bus_speed spd)
{
switch(spd) {
+ case PCIE_SPEED_64_0GT:
+ return (64000 * 128 / 130);
+ case PCIE_SPEED_32_0GT:
+ return (32000 * 128 / 130);
case PCIE_SPEED_16_0GT:
return (16000 * 128 / 130);
case PCIE_SPEED_8_0GT:
@@ -1319,6 +1233,12 @@ pcie_bandwidth_available(struct pci_dev *pdev,
return (nwidth * PCIE_SPEED2MBS_ENC(nspeed));
}
+static inline bool
+pcie_aspm_enabled(struct pci_dev *pdev)
+{
+ return (false);
+}
+
static inline struct pci_dev *
pcie_find_root_port(struct pci_dev *pdev)
{
@@ -1351,6 +1271,29 @@ pci_stop_and_remove_bus_device(struct pci_dev *pdev)
{
}
+static inline int
+pci_rescan_bus(struct pci_bus *pbus)
+{
+ device_t *devlist, parent;
+ int devcount, error;
+
+ if (!device_is_attached(pbus->self->dev.bsddev))
+ return (0);
+ /* pci_rescan_method() will work on the pcib (parent). */
+ error = BUS_RESCAN(pbus->self->dev.bsddev);
+ if (error != 0)
+ return (0);
+
+ parent = device_get_parent(pbus->self->dev.bsddev);
+ error = device_get_children(parent, &devlist, &devcount);
+ if (error != 0)
+ return (0);
+ if (devcount != 0)
+ free(devlist, M_TEMP);
+
+ return (devcount);
+}
+
/*
* The following functions can be used to attach/detach the LinuxKPI's
* PCI device runtime. The pci_driver and pci_device_id pointer is
@@ -1374,11 +1317,27 @@ pci_dev_present(const struct pci_device_id *cur)
return (0);
}
-static inline bool
-pci_is_root_bus(struct pci_bus *pbus)
+static inline const struct pci_device_id *
+pci_match_id(const struct pci_device_id *ids, struct pci_dev *pdev)
{
+ if (ids == NULL)
+ return (NULL);
- return (pbus->self == NULL);
+ for (;
+ ids->vendor != 0 || ids->subvendor != 0 || ids->class_mask != 0;
+ ids++)
+ if ((ids->vendor == PCI_ANY_ID ||
+ ids->vendor == pdev->vendor) &&
+ (ids->device == PCI_ANY_ID ||
+ ids->device == pdev->device) &&
+ (ids->subvendor == PCI_ANY_ID ||
+ ids->subvendor == pdev->subsystem_vendor) &&
+ (ids->subdevice == PCI_ANY_ID ||
+ ids->subdevice == pdev->subsystem_device) &&
+ ((ids->class ^ pdev->class) & ids->class_mask) == 0)
+ return (ids);
+
+ return (NULL);
}
struct pci_dev *lkpi_pci_get_domain_bus_and_slot(int domain,
@@ -1386,6 +1345,12 @@ struct pci_dev *lkpi_pci_get_domain_bus_and_slot(int domain,
#define pci_get_domain_bus_and_slot(domain, bus, devfn) \
lkpi_pci_get_domain_bus_and_slot(domain, bus, devfn)
+struct pci_dev *lkpi_pci_get_slot(struct pci_bus *, unsigned int);
+#ifndef WANT_NATIVE_PCI_GET_SLOT
+#define pci_get_slot(_pbus, _devfn) \
+ lkpi_pci_get_slot(_pbus, _devfn)
+#endif
+
static inline int
pci_domain_nr(struct pci_bus *pbus)
{
@@ -1449,140 +1414,162 @@ pci_bus_write_config_word(struct pci_bus *bus, unsigned int devfn, int pos,
struct pci_dev *lkpi_pci_get_class(unsigned int class, struct pci_dev *from);
#define pci_get_class(class, from) lkpi_pci_get_class(class, from)
+struct pci_dev *lkpi_pci_get_base_class(unsigned int class,
+ struct pci_dev *from);
+#define pci_get_base_class(class, from) lkpi_pci_get_base_class(class, from)
/* -------------------------------------------------------------------------- */
+#define pcim_enable_device(pdev) \
+ linuxkpi_pcim_enable_device(pdev)
+#define pcim_iomap_table(pdev) \
+ linuxkpi_pcim_iomap_table(pdev)
+#define pcim_iomap_regions(pdev, mask, name) \
+ linuxkpi_pcim_iomap_regions(pdev, mask, name)
+
static inline int
-pcim_enable_device(struct pci_dev *pdev)
+pcim_iomap_regions_request_all(struct pci_dev *pdev, uint32_t mask, char *name)
{
- struct pci_devres *dr;
- int error;
+ uint32_t requests, req_mask;
+ int bar, error;
- /* Here we cannot run through the pdev->managed check. */
- dr = lkpi_pci_devres_get_alloc(pdev);
- if (dr == NULL)
- return (-ENOMEM);
+ /* Request all the BARs ("regions") we do not iomap. */
+ req_mask = ((1 << (PCIR_MAX_BAR_0 + 1)) - 1) & ~mask;
+ for (bar = requests = 0; requests != req_mask; bar++) {
+ if ((req_mask & (1 << bar)) == 0)
+ continue;
+ error = pci_request_region(pdev, bar, name);
+ if (error != 0 && error != -ENODEV)
+ goto err;
+ requests |= (1 << bar);
+ }
- /* If resources were enabled before do not do it again. */
- if (dr->enable_io)
- return (0);
+ error = pcim_iomap_regions(pdev, mask, name);
+ if (error != 0)
+ goto err;
- error = pci_enable_device(pdev);
- if (error == 0)
- dr->enable_io = true;
+ return (0);
- /* This device is not managed. */
- pdev->managed = true;
+err:
+ for (bar = PCIR_MAX_BAR_0; bar >= 0; bar--) {
+ if ((requests & (1 << bar)) != 0)
+ pci_release_region(pdev, bar);
+ }
- return (error);
+ return (-EINVAL);
}
-static inline struct pcim_iomap_devres *
-lkpi_pcim_iomap_devres_find(struct pci_dev *pdev)
+/*
+ * We cannot simply re-define pci_get_device() as we would normally do
+ * and then hide it in linux_pci.c as too many semi-native drivers still
+ * include linux/pci.h and run into the conflict with native PCI. Linux drivers
+ * using pci_get_device() need to be changed to call linuxkpi_pci_get_device().
+ */
+static inline struct pci_dev *
+linuxkpi_pci_get_device(uint32_t vendor, uint32_t device, struct pci_dev *odev)
{
- struct pcim_iomap_devres *dr;
- dr = lkpi_devres_find(&pdev->dev, lkpi_pcim_iomap_table_release,
- NULL, NULL);
- if (dr == NULL) {
- dr = lkpi_devres_alloc(lkpi_pcim_iomap_table_release,
- sizeof(*dr), GFP_KERNEL | __GFP_ZERO);
- if (dr != NULL)
- lkpi_devres_add(&pdev->dev, dr);
- }
+ return (lkpi_pci_get_device(vendor, device, odev));
+}
- if (dr == NULL)
- device_printf(pdev->dev.bsddev, "%s: NULL\n", __func__);
+#define for_each_pci_dev(_pdev) \
+ while ((_pdev = linuxkpi_pci_get_device(PCI_ANY_ID, PCI_ANY_ID, _pdev)) != NULL)
- return (dr);
+/* This is a FreeBSD extension so we can use bus_*(). */
+static inline void
+linuxkpi_pcim_want_to_use_bus_functions(struct pci_dev *pdev)
+{
+ pdev->want_iomap_res = true;
}
-static inline void __iomem **
-pcim_iomap_table(struct pci_dev *pdev)
+static inline bool
+pci_is_thunderbolt_attached(struct pci_dev *pdev)
{
- struct pcim_iomap_devres *dr;
- dr = lkpi_pcim_iomap_devres_find(pdev);
- if (dr == NULL)
- return (NULL);
+ return (false);
+}
- /*
- * If the driver has manually set a flag to be able to request the
- * resource to use bus_read/write_<n>, return the shadow table.
- */
- if (pdev->want_iomap_res)
- return ((void **)dr->res_table);
+static inline void *
+pci_platform_rom(struct pci_dev *pdev, size_t *size)
+{
+
+ return (NULL);
+}
+
+static inline void
+pci_ignore_hotplug(struct pci_dev *pdev)
+{
+}
- /* This is the Linux default. */
- return (dr->mmio_table);
+static inline const char *
+pci_power_name(pci_power_t state)
+{
+ int pstate = state + 1;
+
+ if (pstate >= 0 && pstate < nitems(pci_power_names))
+ return (pci_power_names[pstate]);
+ else
+ return (pci_power_names[0]);
}
static inline int
-pcim_iomap_regions_request_all(struct pci_dev *pdev, uint32_t mask, char *name)
+pcie_get_readrq(struct pci_dev *dev)
{
- struct pcim_iomap_devres *dr;
- void *res;
- uint32_t mappings, requests, req_mask;
- int bar, error;
+ u16 ctl;
- dr = lkpi_pcim_iomap_devres_find(pdev);
- if (dr == NULL)
- return (-ENOMEM);
+ if (pcie_capability_read_word(dev, PCI_EXP_DEVCTL, &ctl))
+ return (-EINVAL);
- /* Request all the BARs ("regions") we do not iomap. */
- req_mask = ((1 << (PCIR_MAX_BAR_0 + 1)) - 1) & ~mask;
- for (bar = requests = 0; requests != req_mask; bar++) {
- if ((req_mask & (1 << bar)) == 0)
- continue;
- error = pci_request_region(pdev, bar, name);
- if (error != 0 && error != -ENODEV)
- goto err;
- requests |= (1 << bar);
- }
+ return (128 << ((ctl & PCI_EXP_DEVCTL_READRQ) >> 12));
+}
- /* Now iomap all the requested (by "mask") ones. */
- for (bar = mappings = 0; mappings != mask; bar++) {
- if ((mask & (1 << bar)) == 0)
- continue;
+static inline bool
+pci_is_enabled(struct pci_dev *pdev)
+{
- /* Request double is not allowed. */
- if (dr->mmio_table[bar] != NULL) {
- device_printf(pdev->dev.bsddev, "%s: bar %d %p\n",
- __func__, bar, dr->mmio_table[bar]);
- goto err;
- }
+ return ((pci_read_config(pdev->dev.bsddev, PCIR_COMMAND, 2) &
+ PCIM_CMD_BUSMASTEREN) != 0);
+}
- res = _lkpi_pci_iomap(pdev, bar, 0);
- if (res == NULL)
- goto err;
- dr->mmio_table[bar] = (void *)rman_get_bushandle(res);
- dr->res_table[bar] = res;
+static inline int
+pci_wait_for_pending_transaction(struct pci_dev *pdev)
+{
- mappings |= (1 << bar);
- }
+ return (0);
+}
+
+static inline int
+pci_assign_resource(struct pci_dev *pdev, int bar)
+{
return (0);
+}
-err:
- for (bar = PCIR_MAX_BAR_0; bar >= 0; bar--) {
- if ((mappings & (1 << bar)) != 0) {
- res = dr->mmio_table[bar];
- if (res == NULL)
- continue;
- pci_iounmap(pdev, res);
- } else if ((requests & (1 << bar)) != 0) {
- pci_release_region(pdev, bar);
- }
+static inline int
+pci_irq_vector(struct pci_dev *pdev, unsigned int vector)
+{
+
+ if (!pdev->msix_enabled && !pdev->msi_enabled) {
+ if (vector != 0)
+ return (-EINVAL);
+ return (pdev->irq);
}
- return (-EINVAL);
+ if (pdev->msix_enabled || pdev->msi_enabled) {
+ if ((pdev->dev.irq_start + vector) >= pdev->dev.irq_end)
+ return (-EINVAL);
+ return (pdev->dev.irq_start + vector);
+ }
+
+ return (-ENXIO);
}
-/* This is a FreeBSD extension so we can use bus_*(). */
-static inline void
-linuxkpi_pcim_want_to_use_bus_functions(struct pci_dev *pdev)
+static inline int
+pci_wake_from_d3(struct pci_dev *pdev, bool enable)
{
- pdev->want_iomap_res = true;
+
+ pr_debug("%s: TODO\n", __func__);
+ return (0);
}
-#endif /* _LINUX_PCI_H_ */
+#endif /* _LINUXKPI_LINUX_PCI_H_ */
diff --git a/sys/compat/linuxkpi/common/include/linux/pci_ids.h b/sys/compat/linuxkpi/common/include/linux/pci_ids.h
index 519d1b6eb663..e318f6f75ce7 100644
--- a/sys/compat/linuxkpi/common/include/linux/pci_ids.h
+++ b/sys/compat/linuxkpi/common/include/linux/pci_ids.h
@@ -25,8 +25,6 @@
* 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.
- *
- * $FreeBSD$
*/
#ifndef _LINUXKPI_LINUX_PCI_IDS_H
@@ -41,23 +39,31 @@
#define PCI_BASE_CLASS_BRIDGE 0x06
#define PCI_CLASS_BRIDGE_ISA 0x0601
+#define PCI_CLASS_ACCELERATOR_PROCESSING 0x1200
+
/* XXX We should really generate these and use them throughout the tree. */
#define PCI_VENDOR_ID_APPLE 0x106b
#define PCI_VENDOR_ID_ASUSTEK 0x1043
+#define PCI_VENDOR_ID_ASMEDIA 0x1b21
+#define PCI_VENDOR_ID_ATHEROS 0x168c
#define PCI_VENDOR_ID_ATI 0x1002
#define PCI_VENDOR_ID_BROADCOM 0x14e4
#define PCI_VENDOR_ID_DELL 0x1028
#define PCI_VENDOR_ID_HP 0x103c
#define PCI_VENDOR_ID_IBM 0x1014
#define PCI_VENDOR_ID_INTEL 0x8086
+#define PCI_VENDOR_ID_ITTIM 0x0b48
+#define PCI_VENDOR_ID_MEDIATEK 0x14c3
#define PCI_VENDOR_ID_MELLANOX 0x15b3
+#define PCI_VENDOR_ID_QCOM 0x17cb
#define PCI_VENDOR_ID_REALTEK 0x10ec
#define PCI_VENDOR_ID_REDHAT_QUMRANET 0x1af4
#define PCI_VENDOR_ID_SERVERWORKS 0x1166
#define PCI_VENDOR_ID_SONY 0x104d
#define PCI_VENDOR_ID_TOPSPIN 0x1867
+#define PCI_VENDOR_ID_UBIQUITI 0x0777
#define PCI_VENDOR_ID_VIA 0x1106
#define PCI_SUBVENDOR_ID_REDHAT_QUMRANET 0x1af4
#define PCI_DEVICE_ID_ATI_RADEON_QY 0x5159
diff --git a/sys/compat/linuxkpi/common/include/linux/perf_event.h b/sys/compat/linuxkpi/common/include/linux/perf_event.h
new file mode 100644
index 000000000000..86b0d06cdc1f
--- /dev/null
+++ b/sys/compat/linuxkpi/common/include/linux/perf_event.h
@@ -0,0 +1,34 @@
+/*-
+ * SPDX-License-Identifier: BSD-2-Clause
+ *
+ * Copyright (c) 2025 Jean-Sébastien Pédron <dumbbell@FreeBSD.org>
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are
+ * met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in
+ * the documentation and/or other materials provided with the
+ * distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``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 OR CONTRIBUTORS 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.
+ */
+
+#ifndef _LINUXKPI_LINUX_PERF_EVENT_H_
+#define _LINUXKPI_LINUX_PERF_EVENT_H_
+
+#include <linux/cgroup.h>
+
+#endif /* _LINUXKPI_LINUX_PERF_EVENT_H_ */
diff --git a/sys/compat/linuxkpi/common/include/linux/pfn.h b/sys/compat/linuxkpi/common/include/linux/pfn.h
index 162ca102c951..26d47b9bc3b1 100644
--- a/sys/compat/linuxkpi/common/include/linux/pfn.h
+++ b/sys/compat/linuxkpi/common/include/linux/pfn.h
@@ -22,12 +22,10 @@
* 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.
- *
- * $FreeBSD$
*/
-#ifndef _LINUX_PFN_H_
-#define _LINUX_PFN_H_
+#ifndef _LINUXKPI_LINUX_PFN_H_
+#define _LINUXKPI_LINUX_PFN_H_
#include <linux/types.h>
@@ -41,4 +39,4 @@ typedef struct {
#define PFN_PHYS(x) ((phys_addr_t)(x) << PAGE_SHIFT)
#define PHYS_PFN(x) ((unsigned long)((x) >> PAGE_SHIFT))
-#endif /* _LINUX_PFN_H_ */
+#endif /* _LINUXKPI_LINUX_PFN_H_ */
diff --git a/sys/compat/linuxkpi/common/include/linux/pfn_t.h b/sys/compat/linuxkpi/common/include/linux/pfn_t.h
index bfa80b14ae94..f22289802cb8 100644
--- a/sys/compat/linuxkpi/common/include/linux/pfn_t.h
+++ b/sys/compat/linuxkpi/common/include/linux/pfn_t.h
@@ -22,12 +22,10 @@
* 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.
- *
- * $FreeBSD$
*/
-#ifndef _LINUX_PFN_T_H_
-#define _LINUX_PFN_T_H_
+#ifndef _LINUXKPI_LINUX_PFN_T_H_
+#define _LINUXKPI_LINUX_PFN_T_H_
#include <linux/mm.h>
@@ -53,4 +51,4 @@ pfn_to_pfn_t(unsigned long pfn)
return (__pfn_to_pfn_t (pfn, 0));
}
-#endif /* _LINUX_PFN_T_H_ */
+#endif /* _LINUXKPI_LINUX_PFN_T_H_ */
diff --git a/sys/compat/linuxkpi/common/include/linux/pid.h b/sys/compat/linuxkpi/common/include/linux/pid.h
index 73d8f1f6edfe..60cb9f725b21 100644
--- a/sys/compat/linuxkpi/common/include/linux/pid.h
+++ b/sys/compat/linuxkpi/common/include/linux/pid.h
@@ -22,12 +22,10 @@
* 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.
- *
- * $FreeBSD$
*/
-#ifndef _LINUX_PID_H_
-#define _LINUX_PID_H_
+#ifndef _LINUXKPI_LINUX_PID_H_
+#define _LINUXKPI_LINUX_PID_H_
#include <sys/param.h>
#include <sys/systm.h>
@@ -67,4 +65,4 @@ struct task_struct;
extern struct task_struct *linux_pid_task(pid_t);
extern struct task_struct *linux_get_pid_task(pid_t);
-#endif /* _LINUX_PID_H_ */
+#endif /* _LINUXKPI_LINUX_PID_H_ */
diff --git a/sys/compat/linuxkpi/common/include/linux/platform_device.h b/sys/compat/linuxkpi/common/include/linux/platform_device.h
new file mode 100644
index 000000000000..dba79f5936cc
--- /dev/null
+++ b/sys/compat/linuxkpi/common/include/linux/platform_device.h
@@ -0,0 +1,97 @@
+/*-
+ * SPDX-License-Identifier: BSD-2-Clause
+ *
+ * Copyright (c) 2020-2022 Bjoern A. Zeeb
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``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 OR CONTRIBUTORS 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.
+ */
+
+#ifndef _LINUXKPI_LINUX_PLATFORM_DEVICE_H
+#define _LINUXKPI_LINUX_PLATFORM_DEVICE_H
+
+#include <linux/kernel.h>
+#include <linux/device.h>
+
+struct platform_device {
+ const char *name;
+ int id;
+ bool id_auto;
+ struct device dev;
+};
+
+struct platform_driver {
+ void (*remove)(struct platform_device *);
+ struct device_driver driver;
+};
+
+#define dev_is_platform(dev) (false)
+#define to_platform_device(dev) (NULL)
+
+static __inline int
+platform_driver_register(struct platform_driver *pdrv)
+{
+
+ pr_debug("%s: TODO\n", __func__);
+ return (-ENXIO);
+}
+
+static __inline void *
+dev_get_platdata(struct device *dev)
+{
+
+ pr_debug("%s: TODO\n", __func__);
+ return (NULL);
+}
+
+static __inline int
+platform_driver_probe(struct platform_driver *pdrv,
+ int(*pd_probe_f)(struct platform_device *))
+{
+
+ pr_debug("%s: TODO\n", __func__);
+ return (-ENODEV);
+}
+
+static __inline void
+platform_driver_unregister(struct platform_driver *pdrv)
+{
+
+ pr_debug("%s: TODO\n", __func__);
+ return;
+}
+
+static __inline int
+platform_device_register(struct platform_device *pdev)
+{
+ pr_debug("%s: TODO\n", __func__);
+ return (0);
+}
+
+static __inline void
+platform_device_unregister(struct platform_device *pdev)
+{
+
+ pr_debug("%s: TODO\n", __func__);
+ return;
+}
+
+#endif /* _LINUXKPI_LINUX_PLATFORM_DEVICE_H */
diff --git a/sys/compat/linuxkpi/common/include/linux/pm.h b/sys/compat/linuxkpi/common/include/linux/pm.h
index 6b8a7e768a8c..c8d943027909 100644
--- a/sys/compat/linuxkpi/common/include/linux/pm.h
+++ b/sys/compat/linuxkpi/common/include/linux/pm.h
@@ -1,7 +1,7 @@
/*-
* SPDX-License-Identifier: BSD-2-Clause
*
- * Copyright (c) 2020 The FreeBSD Foundation
+ * Copyright (c) 2020-2024 The FreeBSD Foundation
*
* This software was developed by Björn Zeeb under sponsorship from
* the FreeBSD Foundation.
@@ -26,27 +26,75 @@
* 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.
- *
- * $FreeBSD$
*/
#ifndef _LINUXKPI_LINUX_PM_H
#define _LINUXKPI_LINUX_PM_H
+#include <linux/kernel.h> /* pr_debug */
+#include <asm/atomic.h>
+
+/* Needed but breaks linux_usb.c */
+/* #include <linux/completion.h> */
+/* #include <linux/wait.h> */
+
+struct device;
+
+typedef struct pm_message {
+ int event;
+} pm_message_t;
+
+struct dev_pm_domain {
+};
+
+struct dev_pm_info {
+ atomic_t usage_count;
+};
+
+#define PM_EVENT_FREEZE 0x0001
+#define PM_EVENT_SUSPEND 0x0002
+
+#define pm_sleep_ptr(_p) \
+ IS_ENABLED(CONFIG_PM_SLEEP) ? (_p) : NULL
+
#ifdef CONFIG_PM_SLEEP
+#define __SET_PM_OPS(_suspendfunc, _resumefunc) \
+ .suspend = _suspendfunc, \
+ .resume = _resumefunc, \
+ .freeze = _suspendfunc, \
+ .thaw = _resumefunc, \
+ .poweroff = _suspendfunc, \
+ .restore = _resumefunc, \
+
#define SIMPLE_DEV_PM_OPS(_name, _suspendfunc, _resumefunc) \
const struct dev_pm_ops _name = { \
- .suspend = _suspendfunc, \
- .resume = _resumefunc, \
- .freeze = _suspendfunc, \
- .thaw = _resumefunc, \
- .poweroff = _suspendfunc, \
- .restore = _resumefunc, \
+ __SET_PM_OPS(_suspendfunc, _resumefunc) \
}
+
+#define DEFINE_SIMPLE_DEV_PM_OPS(_name, _suspendfunc, _resumefunc) \
+const struct dev_pm_ops _name = { \
+ __SET_PM_OPS(_suspendfunc, _resumefunc) \
+}
+
+#define SET_SYSTEM_SLEEP_PM_OPS(_suspendfunc, _resumefunc) \
+ __SET_PM_OPS(_suspendfunc, _resumefunc)
#else
#define SIMPLE_DEV_PM_OPS(_name, _suspendfunc, _resumefunc) \
const struct dev_pm_ops _name = { \
}
+#define DEFINE_SIMPLE_DEV_PM_OPS(_name, _suspendfunc, _resumefunc) \
+const struct dev_pm_ops _name = { \
+}
#endif
+bool linuxkpi_device_can_wakeup(struct device *);
+#define device_can_wakeup(_dev) linuxkpi_device_can_wakeup(_dev)
+
+static inline void
+pm_wakeup_event(struct device *dev __unused, unsigned int x __unused)
+{
+
+ pr_debug("%s: TODO\n", __func__);
+}
+
#endif /* _LINUXKPI_LINUX_PM_H */
diff --git a/sys/compat/linuxkpi/common/include/linux/pm_qos.h b/sys/compat/linuxkpi/common/include/linux/pm_qos.h
new file mode 100644
index 000000000000..47c41a819ba8
--- /dev/null
+++ b/sys/compat/linuxkpi/common/include/linux/pm_qos.h
@@ -0,0 +1,57 @@
+/*-
+ * SPDX-License-Identifier: BSD-2-Clause
+ *
+ * Copyright (c) 2022 Bjoern A. Zeeb
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``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 OR CONTRIBUTORS 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.
+ */
+
+#ifndef _LINUXKPI_LINUX_PM_QOS_H
+#define _LINUXKPI_LINUX_PM_QOS_H
+
+#define PM_QOS_DEFAULT_VALUE (-1)
+
+struct pm_qos_request {
+};
+
+static inline void
+cpu_latency_qos_add_request(struct pm_qos_request *qos, int x)
+{
+}
+
+static inline void
+cpu_latency_qos_update_request(struct pm_qos_request *qos, int x)
+{
+}
+
+static inline void
+cpu_latency_qos_remove_request(struct pm_qos_request *qos)
+{
+}
+
+static inline bool
+cpu_latency_qos_request_active(struct pm_qos_request *qos)
+{
+ return (false);
+}
+
+#endif /* _LINUXKPI_LINUX_PM_QOS_H */
diff --git a/sys/compat/linuxkpi/common/include/linux/pm_runtime.h b/sys/compat/linuxkpi/common/include/linux/pm_runtime.h
new file mode 100644
index 000000000000..6114b7b159d7
--- /dev/null
+++ b/sys/compat/linuxkpi/common/include/linux/pm_runtime.h
@@ -0,0 +1,54 @@
+/* Public domain. */
+
+#ifndef _LINUXKPI_LINUX_PM_RUNTIME_H_
+#define _LINUXKPI_LINUX_PM_RUNTIME_H_
+
+#include <linux/device.h>
+#include <linux/pm.h>
+
+#define pm_runtime_mark_last_busy(x) (void)(x)
+#define pm_runtime_use_autosuspend(x) (void)(x)
+#define pm_runtime_dont_use_autosuspend(x) (void)(x)
+#define pm_runtime_put_autosuspend(x) (void)(x)
+#define pm_runtime_set_autosuspend_delay(x, y) (void)(x); (void)(y)
+#define pm_runtime_set_active(x) (void)(x)
+#define pm_runtime_allow(x) (void)(x)
+#define pm_runtime_put_noidle(x) (void)(x)
+#define pm_runtime_forbid(x) (void)(x)
+#define pm_runtime_get_noresume(x) (void)(x)
+#define pm_runtime_put(x) (void)(x)
+#define pm_runtime_enable(x) (void)(x)
+#define pm_runtime_disable(x) (void)(x)
+#define pm_runtime_autosuspend(x) (void)(x)
+#define pm_runtime_resume(x) (void)(x)
+
+static inline int
+pm_runtime_get_sync(struct device *dev)
+{
+ return 0;
+}
+
+static inline int
+pm_runtime_get_if_in_use(struct device *dev)
+{
+ return 1;
+}
+
+#if defined(LINUXKPI_VERSION) && LINUXKPI_VERSION < 60900
+static inline int
+pm_runtime_get_if_active(struct device *dev, bool x)
+#else
+static inline int
+pm_runtime_get_if_active(struct device *dev)
+#endif
+{
+ return 1;
+}
+
+static inline int
+pm_runtime_suspended(struct device *dev)
+{
+ return 0;
+}
+
+#endif /* _LINUXKPI_LINUX_PM_RUNTIME_H_ */
diff --git a/sys/compat/linuxkpi/common/include/linux/poison.h b/sys/compat/linuxkpi/common/include/linux/poison.h
index 35ccb5b5499a..f1594c6dd1dc 100644
--- a/sys/compat/linuxkpi/common/include/linux/poison.h
+++ b/sys/compat/linuxkpi/common/include/linux/poison.h
@@ -1,7 +1,7 @@
/* Public domain. */
-#ifndef _LINUX_POISON_H
-#define _LINUX_POISON_H
+#ifndef _LINUXKPI_LINUX_POISON_H
+#define _LINUXKPI_LINUX_POISON_H
#define POISON_INUSE 0xdb
#define POISON_FREE 0xdf
diff --git a/sys/compat/linuxkpi/common/include/linux/poll.h b/sys/compat/linuxkpi/common/include/linux/poll.h
index 33501165df24..3acb3c740954 100644
--- a/sys/compat/linuxkpi/common/include/linux/poll.h
+++ b/sys/compat/linuxkpi/common/include/linux/poll.h
@@ -25,15 +25,14 @@
* 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.
- *
- * $FreeBSD$
*/
-#ifndef _LINUX_POLL_H_
-#define _LINUX_POLL_H_
+#ifndef _LINUXKPI_LINUX_POLL_H_
+#define _LINUXKPI_LINUX_POLL_H_
#include <sys/poll.h>
#include <sys/fcntl.h>
+#include <linux/eventpoll.h>
#include <linux/wait.h>
#include <linux/file.h>
@@ -45,4 +44,4 @@ extern void linux_poll_wait(struct linux_file *, wait_queue_head_t *, poll_table
extern void linux_poll_wakeup(struct linux_file *);
-#endif /* _LINUX_POLL_H_ */
+#endif /* _LINUXKPI_LINUX_POLL_H_ */
diff --git a/sys/compat/linuxkpi/common/include/linux/power_supply.h b/sys/compat/linuxkpi/common/include/linux/power_supply.h
index 6f6d8b28c5ee..8855cfff0539 100644
--- a/sys/compat/linuxkpi/common/include/linux/power_supply.h
+++ b/sys/compat/linuxkpi/common/include/linux/power_supply.h
@@ -24,12 +24,10 @@
* 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.
- *
- * $FreeBSD$
*/
-#ifndef _LINUX_POWER_SUPPLY_H_
-#define _LINUX_POWER_SUPPLY_H_
+#ifndef _LINUXKPI_LINUX_POWER_SUPPLY_H_
+#define _LINUXKPI_LINUX_POWER_SUPPLY_H_
#include <sys/types.h>
#include <sys/power.h>
diff --git a/sys/compat/linuxkpi/common/include/linux/preempt.h b/sys/compat/linuxkpi/common/include/linux/preempt.h
index e19e7ee09a48..32177d4a980c 100644
--- a/sys/compat/linuxkpi/common/include/linux/preempt.h
+++ b/sys/compat/linuxkpi/common/include/linux/preempt.h
@@ -22,12 +22,10 @@
* 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.
- *
- * $FreeBSD$
*/
-#ifndef _LINUX_PREEMPT_H_
-#define _LINUX_PREEMPT_H_
+#ifndef _LINUXKPI_LINUX_PREEMPT_H_
+#define _LINUXKPI_LINUX_PREEMPT_H_
#include <linux/hardirq.h>
#include <linux/list.h>
@@ -40,4 +38,4 @@
#define preempt_disable() critical_enter()
#define preempt_enable() critical_exit()
-#endif /* _LINUX_PREEMPT_H_ */
+#endif /* _LINUXKPI_LINUX_PREEMPT_H_ */
diff --git a/sys/compat/linuxkpi/common/include/linux/prefetch.h b/sys/compat/linuxkpi/common/include/linux/prefetch.h
index ed8f1838e178..71839f0ca191 100644
--- a/sys/compat/linuxkpi/common/include/linux/prefetch.h
+++ b/sys/compat/linuxkpi/common/include/linux/prefetch.h
@@ -24,13 +24,11 @@
* 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.
- *
- * $FreeBSD$
*/
-#ifndef _LINUX_PREFETCH_H_
-#define _LINUX_PREFETCH_H_
+#ifndef _LINUXKPI_LINUX_PREFETCH_H_
+#define _LINUXKPI_LINUX_PREFETCH_H_
#define prefetchw(x) __builtin_prefetch(x,1)
-#endif /* _LINUX_PREFETCH_H_ */
+#endif /* _LINUXKPI_LINUX_PREFETCH_H_ */
diff --git a/sys/compat/linuxkpi/common/include/linux/printk.h b/sys/compat/linuxkpi/common/include/linux/printk.h
index e6510e9e9834..d2d197682782 100644
--- a/sys/compat/linuxkpi/common/include/linux/printk.h
+++ b/sys/compat/linuxkpi/common/include/linux/printk.h
@@ -25,11 +25,9 @@
* 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.
- *
- * $FreeBSD$
*/
-#ifndef _LINUX_PRINTK_H_
-#define _LINUX_PRINTK_H_
+#ifndef _LINUXKPI_LINUX_PRINTK_H_
+#define _LINUXKPI_LINUX_PRINTK_H_
#include <linux/kernel.h>
@@ -46,57 +44,19 @@ enum {
DUMP_PREFIX_OFFSET
};
+int __lkpi_hexdump_printf(void *, const char *, ...) __printflike(2, 3);
+
+void lkpi_hex_dump(int(*)(void *, const char *, ...), void *arg1,
+ const char *, const char *, const int, const int, const int,
+ const void *, size_t, const bool);
+
static inline void
print_hex_dump(const char *level, const char *prefix_str,
const int prefix_type, const int rowsize, const int groupsize,
const void *buf, size_t len, const bool ascii)
{
- typedef const struct { long long value; } __packed *print_64p_t;
- typedef const struct { uint32_t value; } __packed *print_32p_t;
- typedef const struct { uint16_t value; } __packed *print_16p_t;
- const void *buf_old = buf;
- int row;
-
- while (len > 0) {
- if (level != NULL)
- printf("%s", level);
- if (prefix_str != NULL)
- printf("%s ", prefix_str);
-
- switch (prefix_type) {
- case DUMP_PREFIX_ADDRESS:
- printf("[%p] ", buf);
- break;
- case DUMP_PREFIX_OFFSET:
- printf("[%#tx] ", ((const char *)buf -
- (const char *)buf_old));
- break;
- default:
- break;
- }
- for (row = 0; row != rowsize; row++) {
- if (groupsize == 8 && len > 7) {
- printf("%016llx ", ((print_64p_t)buf)->value);
- buf = (const uint8_t *)buf + 8;
- len -= 8;
- } else if (groupsize == 4 && len > 3) {
- printf("%08x ", ((print_32p_t)buf)->value);
- buf = (const uint8_t *)buf + 4;
- len -= 4;
- } else if (groupsize == 2 && len > 1) {
- printf("%04x ", ((print_16p_t)buf)->value);
- buf = (const uint8_t *)buf + 2;
- len -= 2;
- } else if (len > 0) {
- printf("%02x ", *(const uint8_t *)buf);
- buf = (const uint8_t *)buf + 1;
- len--;
- } else {
- break;
- }
- }
- printf("\n");
- }
+ lkpi_hex_dump(__lkpi_hexdump_printf, NULL, level, prefix_str, prefix_type,
+ rowsize, groupsize, buf, len, ascii);
}
static inline void
@@ -127,4 +87,17 @@ print_hex_dump_bytes(const char *prefix_str, const int prefix_type,
#define pr_info_ratelimited(fmt, ...) \
printk_ratelimited(KERN_INFO pr_fmt(fmt), ##__VA_ARGS__)
-#endif /* _LINUX_PRINTK_H_ */
+#define no_printk(fmt, ...) \
+({ \
+ if (0) \
+ printk(pr_fmt(fmt), ##__VA_ARGS__); \
+ 0; \
+})
+
+#define FW_BUG "[Firmware Bug]: "
+#define FW_WARN "[Firmware Warn]: "
+#define FW_INFO "[Firmware Info]: "
+#define HW_ERR "[Hardware Error]: "
+#define DEPRECATED "[Deprecated]: "
+
+#endif /* _LINUXKPI_LINUX_PRINTK_H_ */
diff --git a/sys/compat/linuxkpi/common/include/linux/ptp_clock_kernel.h b/sys/compat/linuxkpi/common/include/linux/ptp_clock_kernel.h
new file mode 100644
index 000000000000..aad46cc25b1b
--- /dev/null
+++ b/sys/compat/linuxkpi/common/include/linux/ptp_clock_kernel.h
@@ -0,0 +1,75 @@
+/*-
+ * Copyright (c) 2023 The FreeBSD Foundation
+ *
+ * This software was developed by Björn Zeeb under sponsorship from
+ * the FreeBSD Foundation.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``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 OR CONTRIBUTORS 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.
+ */
+
+#ifndef _LINUXKPI_LINUX_PTP_CLOCK_KERNEL_H
+#define _LINUXKPI_LINUX_PTP_CLOCK_KERNEL_H
+
+#include <linux/types.h>
+#include <linux/device.h>
+#include <linux/kernel.h> /* pr_debug */
+#include <linux/ktime.h> /* system_device_crosststamp */
+
+/* This very likely belongs elsewhere. */
+struct system_device_crosststamp {
+ ktime_t device;
+ ktime_t sys_realtime;
+ ktime_t sys_monotonic_raw; /* name guessed based on comment */
+};
+
+struct ptp_clock_info {
+ char name[32];
+ int max_adj;
+ void *owner; /* THIS_MODULE */
+ int (*adjfine)(struct ptp_clock_info *, long);
+ int (*adjtime)(struct ptp_clock_info *, s64);
+ int (*getcrosststamp)(struct ptp_clock_info *, struct system_device_crosststamp *);
+ int (*gettime64)(struct ptp_clock_info *, struct timespec *);
+};
+
+static inline struct ptp_clock *
+ptp_clock_register(struct ptp_clock_info *ptpci, struct device *dev)
+{
+
+ pr_debug("%s: TODO\n", __func__);
+ return (NULL);
+}
+
+static inline void
+ptp_clock_unregister(struct ptp_clock *ptpc)
+{
+ pr_debug("%s: TODO\n", __func__);
+}
+
+static inline int
+ptp_clock_index(struct ptp_clock *ptpc)
+{
+ pr_debug("%s: TODO\n", __func__);
+ return (0);
+}
+
+#endif /* _LINUXKPI_LINUX_PTP_CLOCK_KERNEL_H */
diff --git a/sys/compat/linuxkpi/common/include/linux/pwm.h b/sys/compat/linuxkpi/common/include/linux/pwm.h
new file mode 100644
index 000000000000..c0740db675e8
--- /dev/null
+++ b/sys/compat/linuxkpi/common/include/linux/pwm.h
@@ -0,0 +1,100 @@
+/*-
+ * Copyright (c) 2022 Vladimir Kondratyev <wulf@FreeBSD.org>
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``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 OR CONTRIBUTORS 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.
+ */
+
+#ifndef _LINUXKPI_LINUX_PWM_H_
+#define _LINUXKPI_LINUX_PWM_H_
+
+#include <linux/device.h>
+#include <linux/err.h>
+
+struct pwm_state {
+ uint64_t period;
+ bool enabled;
+};
+
+struct pwm_device {
+ struct pwm_state state;
+};
+
+static inline struct pwm_device *
+pwm_get(struct device *dev, const char *consumer)
+{
+ return (ERR_PTR(-ENODEV));
+}
+
+static inline void
+pwm_put(struct pwm_device *pwm)
+{
+}
+
+static inline int
+pwm_enable(struct pwm_device *pwm)
+{
+ return (-EINVAL);
+}
+
+static inline void
+pwm_disable(struct pwm_device *pwm)
+{
+}
+
+static inline bool
+pwm_is_enabled(const struct pwm_device *pwm)
+{
+ return (false);
+}
+
+static inline unsigned int
+pwm_get_relative_duty_cycle(const struct pwm_state *state, unsigned int scale)
+{
+ return (0);
+}
+
+static inline int
+pwm_set_relative_duty_cycle(struct pwm_state *state, unsigned int duty_cycle,
+ unsigned int scale)
+{
+ return (0);
+}
+
+static inline void
+pwm_get_state(const struct pwm_device *pwm, struct pwm_state *state)
+{
+ *state = pwm->state;
+}
+
+static inline int
+pwm_apply_state(struct pwm_device *pwm, const struct pwm_state *state)
+{
+ return (-ENOTSUPP);
+}
+
+static inline int
+pwm_apply_might_sleep(struct pwm_device *pwm, const struct pwm_state *state)
+{
+ return (0);
+}
+
+#endif /* _LINUXKPI_LINUX_PWM_H_ */
diff --git a/sys/compat/linuxkpi/common/include/linux/qrtr.h b/sys/compat/linuxkpi/common/include/linux/qrtr.h
new file mode 100644
index 000000000000..1d2af0efdce2
--- /dev/null
+++ b/sys/compat/linuxkpi/common/include/linux/qrtr.h
@@ -0,0 +1,41 @@
+/*-
+ * SPDX-License-Identifier: BSD-2-Clause
+ *
+ * Copyright (c) 2022 Bjoern A. Zeeb
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``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 OR CONTRIBUTORS 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.
+ */
+
+#ifndef _LINUXKPI_LINUX_QRTR_H
+#define _LINUXKPI_LINUX_QRTR_H
+
+/* Qualcomm IPC Router (QRTR) */
+
+#include <sys/socket.h>
+
+struct sockaddr_qrtr {
+ sa_family_t sq_family;
+ uint32_t sq_node;
+ uint32_t sq_port;
+};
+
+#endif /* _LINUXKPI_LINUX_QRTR_H */
diff --git a/sys/compat/linuxkpi/common/include/linux/radix-tree.h b/sys/compat/linuxkpi/common/include/linux/radix-tree.h
index 1bef60c44c41..ea75836c26fb 100644
--- a/sys/compat/linuxkpi/common/include/linux/radix-tree.h
+++ b/sys/compat/linuxkpi/common/include/linux/radix-tree.h
@@ -25,12 +25,11 @@
* 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.
- *
- * $FreeBSD$
*/
-#ifndef _LINUX_RADIX_TREE_H_
-#define _LINUX_RADIX_TREE_H_
+#ifndef _LINUXKPI_LINUX_RADIX_TREE_H_
+#define _LINUXKPI_LINUX_RADIX_TREE_H_
+#include <linux/rcupdate.h>
#include <linux/types.h>
#define RADIX_TREE_MAP_SHIFT 6
@@ -82,4 +81,4 @@ int radix_tree_store(struct radix_tree_root *, unsigned long, void **);
bool radix_tree_iter_find(struct radix_tree_root *, struct radix_tree_iter *, void ***);
void radix_tree_iter_delete(struct radix_tree_root *, struct radix_tree_iter *, void **);
-#endif /* _LINUX_RADIX_TREE_H_ */
+#endif /* _LINUXKPI_LINUX_RADIX_TREE_H_ */
diff --git a/sys/compat/linuxkpi/common/include/linux/random.h b/sys/compat/linuxkpi/common/include/linux/random.h
index 12de0e12bc5a..893ee2b7b728 100644
--- a/sys/compat/linuxkpi/common/include/linux/random.h
+++ b/sys/compat/linuxkpi/common/include/linux/random.h
@@ -4,6 +4,10 @@
* Copyright (c) 2010 Panasas, Inc.
* Copyright (c) 2013-2016 Mellanox Technologies, Ltd.
* All rights reserved.
+ * Copyright 2023 The FreeBSD Foundation
+ *
+ * Portions of this software was developed by Björn Zeeb
+ * under sponsorship from the FreeBSD Foundation.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
@@ -25,19 +29,15 @@
* 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.
- *
- * $FreeBSD$
*/
-#ifndef _LINUX_RANDOM_H_
-#define _LINUX_RANDOM_H_
+#ifndef _LINUXKPI_LINUX_RANDOM_H_
+#define _LINUXKPI_LINUX_RANDOM_H_
#include <linux/types.h>
#include <sys/random.h>
#include <sys/libkern.h>
-#define get_random_u32() get_random_int()
-
static inline void
get_random_bytes(void *buf, int nbytes)
{
@@ -54,6 +54,39 @@ get_random_int(void)
return (val);
}
+static inline uint8_t
+get_random_u8(void)
+{
+ uint8_t val;
+
+ get_random_bytes(&val, sizeof(val));
+ return (val);
+}
+
+#define get_random_u32() get_random_int()
+
+/*
+ * See "Fast Random Integer Generation in an Interval" by Daniel Lemire
+ * [https://arxiv.org/pdf/1805.10941.pdf] for implementation insights.
+ */
+static inline uint32_t
+get_random_u32_inclusive(uint32_t floor, uint32_t ceil)
+{
+ uint64_t x;
+ uint32_t t, v;
+
+ MPASS(ceil >= floor);
+
+ v = get_random_u32();
+ t = ceil - floor + 1;
+ x = (uint64_t)t * v;
+ while (x < t)
+ x = (uint64_t)t * get_random_u32();
+ v = x >> 32;
+
+ return (floor + v);
+}
+
static inline u_long
get_random_long(void)
{
@@ -63,6 +96,21 @@ get_random_long(void)
return (val);
}
+static inline uint64_t
+get_random_u64(void)
+{
+ uint64_t val;
+
+ get_random_bytes(&val, sizeof(val));
+ return (val);
+}
+
+static inline uint32_t
+get_random_u32_below(uint32_t max)
+{
+ return (arc4random_uniform(max));
+}
+
static __inline uint32_t
prandom_u32(void)
{
@@ -78,4 +126,4 @@ prandom_u32_max(u32 max)
return (arc4random_uniform(max));
}
-#endif /* _LINUX_RANDOM_H_ */
+#endif /* _LINUXKPI_LINUX_RANDOM_H_ */
diff --git a/sys/compat/linuxkpi/common/include/linux/ratelimit.h b/sys/compat/linuxkpi/common/include/linux/ratelimit.h
new file mode 100644
index 000000000000..9585b4b994d7
--- /dev/null
+++ b/sys/compat/linuxkpi/common/include/linux/ratelimit.h
@@ -0,0 +1,17 @@
+/* Public domain. */
+
+#ifndef _LINUXKPI_LINUX_RATELIMIT_H
+#define _LINUXKPI_LINUX_RATELIMIT_H
+
+struct ratelimit_state {
+};
+
+#define DEFINE_RATELIMIT_STATE(name, interval, burst) \
+ int name __used = 1;
+
+#define __ratelimit(x) (1)
+
+#define ratelimit_state_init(x, y, z)
+#define ratelimit_set_flags(x, y)
+
+#endif
diff --git a/sys/compat/linuxkpi/common/include/linux/rbtree.h b/sys/compat/linuxkpi/common/include/linux/rbtree.h
index 78da33ad2658..e6033cfd760d 100644
--- a/sys/compat/linuxkpi/common/include/linux/rbtree.h
+++ b/sys/compat/linuxkpi/common/include/linux/rbtree.h
@@ -25,23 +25,22 @@
* 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.
- *
- * $FreeBSD$
*/
-#ifndef _LINUX_RBTREE_H_
-#define _LINUX_RBTREE_H_
+#ifndef _LINUXKPI_LINUX_RBTREE_H_
+#define _LINUXKPI_LINUX_RBTREE_H_
#ifndef _STANDALONE
#include <sys/stddef.h>
#endif
+#include <sys/types.h>
#include <sys/tree.h>
struct rb_node {
RB_ENTRY(rb_node) __entry;
};
-#define rb_left __entry.rbe_left
-#define rb_right __entry.rbe_right
+#define rb_left __entry.rbe_link[_RB_L]
+#define rb_right __entry.rbe_link[_RB_R]
/*
* We provide a false structure that has the same bit pattern as tree.h
@@ -51,6 +50,11 @@ struct rb_root {
struct rb_node *rb_node;
};
+struct rb_root_cached {
+ struct rb_root rb_root;
+ struct rb_node *rb_leftmost;
+};
+
/*
* In linux all of the comparisons are done by the caller.
*/
@@ -59,20 +63,62 @@ int panic_cmp(struct rb_node *one, struct rb_node *two);
RB_HEAD(linux_root, rb_node);
RB_PROTOTYPE(linux_root, rb_node, __entry, panic_cmp);
+#define rb_parent(r) RB_PARENT(r, __entry)
#define rb_entry(ptr, type, member) container_of(ptr, type, member)
+#define rb_entry_safe(ptr, type, member) \
+ ((ptr) != NULL ? rb_entry(ptr, type, member) : NULL)
-#define RB_EMPTY_ROOT(root) RB_EMPTY((struct linux_root *)root)
+#define RB_EMPTY_ROOT(root) ((root)->rb_node == NULL)
#define RB_EMPTY_NODE(node) (RB_PARENT(node, __entry) == node)
#define RB_CLEAR_NODE(node) RB_SET_PARENT(node, node, __entry)
-#define rb_insert_color(node, root) \
- linux_root_RB_INSERT_COLOR((struct linux_root *)(root), (node))
+#define rb_insert_color(node, root) do { \
+ if (rb_parent(node)) \
+ linux_root_RB_INSERT_COLOR((struct linux_root *)(root), \
+ rb_parent(node), (node)); \
+} while (0)
#define rb_erase(node, root) \
linux_root_RB_REMOVE((struct linux_root *)(root), (node))
#define rb_next(node) RB_NEXT(linux_root, NULL, (node))
#define rb_prev(node) RB_PREV(linux_root, NULL, (node))
#define rb_first(root) RB_MIN(linux_root, (struct linux_root *)(root))
#define rb_last(root) RB_MAX(linux_root, (struct linux_root *)(root))
+#define rb_first_cached(root) (root)->rb_leftmost
+
+static inline struct rb_node *
+__rb_deepest_left(struct rb_node *node)
+{
+ struct rb_node *parent = NULL;
+ while (node != NULL) {
+ parent = node;
+ if (RB_LEFT(node, __entry))
+ node = RB_LEFT(node, __entry);
+ else
+ node = RB_RIGHT(node, __entry);
+ }
+ return (parent);
+}
+
+static inline struct rb_node *
+rb_next_postorder(const struct rb_node *node)
+{
+ struct rb_node *parent =
+ RB_PARENT(__DECONST(struct rb_node *, node), __entry);
+ /* left -> right, right -> root */
+ if (parent != NULL &&
+ (node == RB_LEFT(parent, __entry)) &&
+ (RB_RIGHT(parent, __entry)))
+ return (__rb_deepest_left(RB_RIGHT(parent, __entry)));
+ else
+ return (parent);
+}
+
+#define rbtree_postorder_for_each_entry_safe(x, y, head, member) \
+ for ((x) = rb_entry_safe(__rb_deepest_left((head)->rb_node), \
+ __typeof(*x), member); \
+ ((x) != NULL) && ((y) = \
+ rb_entry_safe(rb_next_postorder(&x->member), typeof(*x), member), 1); \
+ (x) = (y))
static inline void
rb_link_node(struct rb_node *node, struct rb_node *parent,
@@ -87,15 +133,74 @@ rb_replace_node(struct rb_node *victim, struct rb_node *new,
struct rb_root *root)
{
- RB_SWAP_CHILD((struct linux_root *)root, victim, new, __entry);
- if (victim->rb_left)
- RB_SET_PARENT(victim->rb_left, new, __entry);
- if (victim->rb_right)
- RB_SET_PARENT(victim->rb_right, new, __entry);
+ RB_SWAP_CHILD((struct linux_root *)root, rb_parent(victim),
+ victim, new, __entry);
+ if (RB_LEFT(victim, __entry))
+ RB_SET_PARENT(RB_LEFT(victim, __entry), new, __entry);
+ if (RB_RIGHT(victim, __entry))
+ RB_SET_PARENT(RB_RIGHT(victim, __entry), new, __entry);
*new = *victim;
}
+static inline void
+rb_insert_color_cached(struct rb_node *node, struct rb_root_cached *root,
+ bool leftmost)
+{
+ if (rb_parent(node))
+ linux_root_RB_INSERT_COLOR((struct linux_root *)&root->rb_root,
+ rb_parent(node), node);
+ if (leftmost)
+ root->rb_leftmost = node;
+}
+
+static inline struct rb_node *
+rb_erase_cached(struct rb_node *node, struct rb_root_cached *root)
+{
+ struct rb_node *retval;
+
+ if (node == root->rb_leftmost)
+ retval = root->rb_leftmost = linux_root_RB_NEXT(node);
+ else
+ retval = NULL;
+ linux_root_RB_REMOVE((struct linux_root *)&root->rb_root, node);
+ return (retval);
+}
+
+static inline void
+rb_replace_node_cached(struct rb_node *old, struct rb_node *new,
+ struct rb_root_cached *root)
+{
+ rb_replace_node(old, new, &root->rb_root);
+ if (root->rb_leftmost == old)
+ root->rb_leftmost = new;
+}
+
+static inline struct rb_node *
+rb_add_cached(struct rb_node *node, struct rb_root_cached *tree,
+ bool (*less)(struct rb_node *, const struct rb_node *))
+{
+ struct rb_node **link = &tree->rb_root.rb_node;
+ struct rb_node *parent = NULL;
+ bool leftmost = true;
+
+ while (*link != NULL) {
+ parent = *link;
+ if (less(node, parent)) {
+ link = &RB_LEFT(parent, __entry);
+ } else {
+ link = &RB_RIGHT(parent, __entry);
+ leftmost = false;
+ }
+ }
+
+ rb_link_node(node, parent, link);
+ rb_insert_color_cached(node, tree, leftmost);
+
+ return (leftmost ? node : NULL);
+}
+
#undef RB_ROOT
#define RB_ROOT (struct rb_root) { NULL }
+#define RB_ROOT_CACHED (struct rb_root_cached) { RB_ROOT, NULL }
-#endif /* _LINUX_RBTREE_H_ */
+#endif /* _LINUXKPI_LINUX_RBTREE_H_ */
diff --git a/sys/compat/linuxkpi/common/include/linux/rculist.h b/sys/compat/linuxkpi/common/include/linux/rculist.h
index 6c21a6943f98..066ed92b7996 100644
--- a/sys/compat/linuxkpi/common/include/linux/rculist.h
+++ b/sys/compat/linuxkpi/common/include/linux/rculist.h
@@ -23,12 +23,10 @@
* 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.
- *
- * $FreeBSD$
*/
-#ifndef _LINUX_RCULIST_H_
-#define _LINUX_RCULIST_H_
+#ifndef _LINUXKPI_LINUX_RCULIST_H_
+#define _LINUXKPI_LINUX_RCULIST_H_
#include <linux/list.h>
#include <linux/rcupdate.h>
@@ -44,6 +42,11 @@
&(pos)->member != (head); \
pos = list_entry_rcu((pos)->member.next, typeof(*(pos)), member))
+#define list_for_each_entry_from_rcu(pos, head, member) \
+ for (; \
+ &(pos)->member != (head); \
+ pos = list_entry_rcu((pos)->member.next, typeof(*(pos)), member))
+
#define list_for_each_entry_lockless(pos, head, member) \
list_for_each_entry_rcu(pos, head, member)
@@ -141,4 +144,4 @@ hlist_del_init_rcu(struct hlist_node *n)
}
}
-#endif /* _LINUX_RCULIST_H_ */
+#endif /* _LINUXKPI_LINUX_RCULIST_H_ */
diff --git a/sys/compat/linuxkpi/common/include/linux/rcupdate.h b/sys/compat/linuxkpi/common/include/linux/rcupdate.h
index bd8335216d1d..4aceb7296cd6 100644
--- a/sys/compat/linuxkpi/common/include/linux/rcupdate.h
+++ b/sys/compat/linuxkpi/common/include/linux/rcupdate.h
@@ -1,6 +1,10 @@
/*-
* Copyright (c) 2016-2017 Mellanox Technologies, Ltd.
* All rights reserved.
+ * Copyright (c) 2024-2025 The FreeBSD Foundation
+ *
+ * Portions of this software were developed by Björn Zeeb
+ * under sponsorship from the FreeBSD Foundation.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
@@ -22,17 +26,25 @@
* 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.
- *
- * $FreeBSD$
*/
-#ifndef _LINUX_RCUPDATE_H_
-#define _LINUX_RCUPDATE_H_
+#ifndef _LINUXKPI_LINUX_RCUPDATE_H_
+#define _LINUXKPI_LINUX_RCUPDATE_H_
+
+#include <sys/cdefs.h>
#include <linux/compiler.h>
#include <linux/types.h>
+#include <linux/kernel.h>
+#include <linux/cleanup.h>
#include <machine/atomic.h>
+extern int linuxkpi_rcu_debug;
+#define RCU_WARN_ONCE(c, ...) do { \
+ if (unlikely(linuxkpi_rcu_debug > 0)) \
+ WARN_ONCE((c), ##__VA_ARGS__); \
+} while(0)
+
#define LINUX_KFREE_RCU_OFFSET_MAX 4096 /* exclusive */
/* BSD specific defines */
@@ -63,6 +75,9 @@
linux_rcu_read_unlock(RCU_TYPE_REGULAR);\
} while (0)
+#define rcu_read_lock_held(void) \
+ linux_rcu_read_lock_held(RCU_TYPE_REGULAR)
+
#define synchronize_rcu(void) do { \
linux_synchronize_rcu(RCU_TYPE_REGULAR); \
} while (0)
@@ -81,14 +96,34 @@
#define rcu_access_pointer(p) \
((__typeof(*p) *)READ_ONCE(p))
-#define rcu_dereference_protected(p, c) \
+#define rcu_dereference(p) \
((__typeof(*p) *)READ_ONCE(p))
-#define rcu_dereference(p) \
- rcu_dereference_protected(p, 0)
+#define __rcu_var_name(n, f, l) \
+ __CONCAT(__CONCAT(__CONCAT(rcu_, n), _), __COUNTER__)
-#define rcu_dereference_check(p, c) \
- rcu_dereference_protected(p, c)
+#define __rcu_dereference_protected(p, c, n) \
+({ \
+ RCU_WARN_ONCE(!(c), "%s:%d: condition for %s failed\n", \
+ __func__, __LINE__, __XSTRING(n)); \
+ rcu_dereference(p); \
+})
+
+#define rcu_dereference_protected(p, c) \
+ __rcu_dereference_protected((p), (c), \
+ __rcu_var_name(protected, __func__, __LINE__))
+
+#define __rcu_dereference_check(p, c, n) \
+({ \
+ __typeof(*p) *n = rcu_dereference(p); \
+ RCU_WARN_ONCE(!(c), "%s:%d: condition for %s failed\n", \
+ __func__, __LINE__, __XSTRING(n)); \
+ n; \
+})
+
+#define rcu_dereference_check(p, c) \
+ __rcu_dereference_check((p), (c) || rcu_read_lock_held(), \
+ __rcu_var_name(check, __func__, __LINE__))
#define rcu_dereference_raw(p) \
((__typeof(*p) *)READ_ONCE(p))
@@ -115,11 +150,12 @@
/* prototypes */
-extern void linux_call_rcu(unsigned type, struct rcu_head *ptr, rcu_callback_t func);
-extern void linux_rcu_barrier(unsigned type);
-extern void linux_rcu_read_lock(unsigned type);
-extern void linux_rcu_read_unlock(unsigned type);
-extern void linux_synchronize_rcu(unsigned type);
+void linux_call_rcu(unsigned type, struct rcu_head *ptr, rcu_callback_t func);
+void linux_rcu_barrier(unsigned type);
+void linux_rcu_read_lock(unsigned type);
+void linux_rcu_read_unlock(unsigned type);
+bool linux_rcu_read_lock_held(unsigned);
+void linux_synchronize_rcu(unsigned type);
/* Empty implementation for !DEBUG */
#define init_rcu_head(...)
@@ -127,4 +163,6 @@ extern void linux_synchronize_rcu(unsigned type);
#define init_rcu_head_on_stack(...)
#define destroy_rcu_head_on_stack(...)
-#endif /* _LINUX_RCUPDATE_H_ */
+DEFINE_LOCK_GUARD_0(rcu, rcu_read_lock(), rcu_read_unlock())
+
+#endif /* _LINUXKPI_LINUX_RCUPDATE_H_ */
diff --git a/sys/compat/linuxkpi/common/include/linux/reboot.h b/sys/compat/linuxkpi/common/include/linux/reboot.h
new file mode 100644
index 000000000000..eb696d7b9d2e
--- /dev/null
+++ b/sys/compat/linuxkpi/common/include/linux/reboot.h
@@ -0,0 +1,40 @@
+/*-
+ * Copyright (c) 2022 Beckhoff Automation GmbH & Co. KG
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``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 OR CONTRIBUTORS 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.
+ *
+ */
+
+#ifndef _LINUXKPI_LINUX_REBOOT_H_
+#define _LINUXKPI_LINUX_REBOOT_H_
+
+#include <sys/reboot.h>
+
+static inline void
+orderly_poweroff(bool force)
+{
+
+ shutdown_nice(RB_POWEROFF);
+}
+
+#endif
+
diff --git a/sys/compat/linuxkpi/common/include/linux/ref_tracker.h b/sys/compat/linuxkpi/common/include/linux/ref_tracker.h
new file mode 100644
index 000000000000..fa510b2498e1
--- /dev/null
+++ b/sys/compat/linuxkpi/common/include/linux/ref_tracker.h
@@ -0,0 +1,93 @@
+/*-
+ * Copyright (c) 2025 The FreeBSD Foundation
+ * Copyright (c) 2025 Jean-Sébastien Pédron
+ *
+ * This software was developed by Jean-Sébastien Pédron under sponsorship
+ * from the FreeBSD Foundation.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``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 OR CONTRIBUTORS 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.
+ */
+
+#ifndef _LINUXKPI_LINUX_REF_TRACKER_H_
+#define _LINUXKPI_LINUX_REF_TRACKER_H_
+
+#include <linux/refcount.h>
+#include <linux/types.h>
+#include <linux/spinlock.h>
+#include <linux/stackdepot.h>
+
+struct ref_tracker;
+
+struct ref_tracker_dir {
+};
+
+/*
+ * The following functions currently have dummy implementations that, on Linux,
+ * are used when CONFIG_REF_TRACKER is not set at compile time.
+ *
+ * The ref tracker is a tool to associate a refcount increase to a refcount
+ * decrease. This helps developers track, document and debug refcounts. We
+ * don't need this feature for now in linuxkpi.
+ */
+
+static inline void
+ref_tracker_dir_init(struct ref_tracker_dir *dir,
+ unsigned int quarantine_count, const char *name)
+{
+}
+
+static inline void
+ref_tracker_dir_exit(struct ref_tracker_dir *dir)
+{
+}
+
+static inline void
+ref_tracker_dir_print_locked(struct ref_tracker_dir *dir,
+ unsigned int display_limit)
+{
+}
+
+static inline void
+ref_tracker_dir_print(struct ref_tracker_dir *dir, unsigned int display_limit)
+{
+}
+
+static inline int
+ref_tracker_dir_snprint(struct ref_tracker_dir *dir, char *buf, size_t size)
+{
+ return (0);
+}
+
+static inline int
+ref_tracker_alloc(struct ref_tracker_dir *dir, struct ref_tracker **trackerp,
+ gfp_t gfp)
+{
+ return (0);
+}
+
+static inline int
+ref_tracker_free(struct ref_tracker_dir *dir, struct ref_tracker **trackerp)
+{
+ return (0);
+}
+
+#endif /* !defined(_LINUXKPI_LINUX_REF_TRACKER_H_) */
diff --git a/sys/compat/linuxkpi/common/include/linux/refcount.h b/sys/compat/linuxkpi/common/include/linux/refcount.h
index 02f9f32f7eb4..46e501a65396 100644
--- a/sys/compat/linuxkpi/common/include/linux/refcount.h
+++ b/sys/compat/linuxkpi/common/include/linux/refcount.h
@@ -24,59 +24,62 @@
* 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.
- *
- * $FreeBSD$
*/
-#ifndef _LINUX_REFCOUNT_H
-#define _LINUX_REFCOUNT_H
+#ifndef _LINUXKPI_LINUX_REFCOUNT_H
+#define _LINUXKPI_LINUX_REFCOUNT_H
#include <linux/atomic.h>
+#include <linux/spinlock.h>
-struct refcount_linux {
- atomic_t value;
-};
-typedef struct refcount_linux refcount_t;
+typedef atomic_t refcount_t;
static inline void
refcount_set(refcount_t *ref, unsigned int i)
{
- atomic_set(&ref->value, i);
+ atomic_set(ref, i);
}
static inline void
refcount_inc(refcount_t *ref)
{
- atomic_inc(&ref->value);
+ atomic_inc(ref);
}
static inline bool
refcount_inc_not_zero(refcount_t *ref)
{
- return (atomic_inc_not_zero(&ref->value));
+ return (atomic_inc_not_zero(ref));
}
static inline void
refcount_dec(refcount_t *ref)
{
- atomic_dec(&ref->value);
+ atomic_dec(ref);
}
static inline unsigned int
refcount_read(refcount_t *ref)
{
- return atomic_read(&ref->value);
+ return atomic_read(ref);
}
static inline bool
refcount_dec_and_lock_irqsave(refcount_t *ref, spinlock_t *lock,
unsigned long *flags)
{
- if (atomic_dec_and_test(&ref->value) == true) {
+ if (atomic_dec_and_test(ref) == true) {
spin_lock_irqsave(lock, flags);
return (true);
}
return (false);
}
-#endif /* __LINUX_REFCOUNT_H__ */
+static inline bool
+refcount_dec_and_test(refcount_t *r)
+{
+
+ return (atomic_dec_and_test(r));
+}
+
+#endif /* __LINUXKPI_LINUX_REFCOUNT_H__ */
diff --git a/sys/compat/linuxkpi/common/include/linux/rhashtable.h b/sys/compat/linuxkpi/common/include/linux/rhashtable.h
new file mode 100644
index 000000000000..c6958b6ee5f3
--- /dev/null
+++ b/sys/compat/linuxkpi/common/include/linux/rhashtable.h
@@ -0,0 +1,87 @@
+/*-
+ * Copyright (c) 2023 Bjoern A. Zeeb
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``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 OR CONTRIBUTORS 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.
+ */
+
+#ifndef _LINUXKPI_LINUX_RHASHTABLE_H
+#define _LINUXKPI_LINUX_RHASHTABLE_H
+
+#include <linux/kernel.h> /* pr_debug */
+
+struct rhash_head {
+};
+
+struct rhashtable_params {
+ uint16_t head_offset;
+ uint16_t key_len;
+ uint16_t key_offset;
+ uint16_t nelem_hint;
+ bool automatic_shrinking;
+};
+
+struct rhashtable {
+};
+
+static inline int
+rhashtable_init(struct rhashtable *rht,
+ const struct rhashtable_params *params)
+{
+
+ pr_debug("%s: TODO\n", __func__);
+ return (-1);
+}
+
+static inline void
+rhashtable_destroy(struct rhashtable *rht)
+{
+ pr_debug("%s: TODO\n", __func__);
+}
+
+static inline void *
+rhashtable_lookup_fast(struct rhashtable *rht, const void *key,
+ const struct rhashtable_params params)
+{
+
+ pr_debug("%s: TODO\n", __func__);
+ return (NULL);
+}
+
+static inline void *
+rhashtable_lookup_get_insert_fast(struct rhashtable *rht,
+ struct rhash_head *obj, const struct rhashtable_params params)
+{
+
+ pr_debug("%s: TODO\n", __func__);
+ return (NULL);
+}
+
+static inline int
+rhashtable_remove_fast(struct rhashtable *rht,
+ struct rhash_head *obj, const struct rhashtable_params params)
+{
+
+ pr_debug("%s: TODO\n", __func__);
+ return (-ENOENT);
+}
+
+#endif /* _LINUXKPI_LINUX_RHASHTABLE_H */
diff --git a/sys/compat/linuxkpi/common/include/linux/rwlock.h b/sys/compat/linuxkpi/common/include/linux/rwlock.h
index 621afb1e954b..3030ec89ff1e 100644
--- a/sys/compat/linuxkpi/common/include/linux/rwlock.h
+++ b/sys/compat/linuxkpi/common/include/linux/rwlock.h
@@ -25,25 +25,21 @@
* 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.
- *
- * $FreeBSD$
*/
-#ifndef _LINUX_RWLOCK_H_
-#define _LINUX_RWLOCK_H_
+#ifndef _LINUXKPI_LINUX_RWLOCK_H_
+#define _LINUXKPI_LINUX_RWLOCK_H_
#include <sys/types.h>
#include <sys/lock.h>
#include <sys/rwlock.h>
#include <sys/libkern.h>
-typedef struct {
- struct rwlock rw;
-} rwlock_t;
+typedef struct rwlock rwlock_t;
-#define read_lock(_l) rw_rlock(&(_l)->rw)
-#define write_lock(_l) rw_wlock(&(_l)->rw)
-#define read_unlock(_l) rw_runlock(&(_l)->rw)
-#define write_unlock(_l) rw_wunlock(&(_l)->rw)
+#define read_lock(_l) rw_rlock(_l)
+#define write_lock(_l) rw_wlock(_l)
+#define read_unlock(_l) rw_runlock(_l)
+#define write_unlock(_l) rw_wunlock(_l)
#define read_lock_irq(lock) read_lock((lock))
#define read_unlock_irq(lock) read_unlock((lock))
#define write_lock_irq(lock) write_lock((lock))
@@ -56,13 +52,6 @@ typedef struct {
do { read_unlock(lock); } while (0)
#define write_unlock_irqrestore(lock, flags) \
do { write_unlock(lock); } while (0)
+#define rwlock_init(_l) rw_init_flags(_l, "lnxrw", RW_NOWITNESS | RW_NEW)
-static inline void
-rwlock_init(rwlock_t *lock)
-{
-
- memset(&lock->rw, 0, sizeof(lock->rw));
- rw_init_flags(&lock->rw, "lnxrw", RW_NOWITNESS);
-}
-
-#endif /* _LINUX_RWLOCK_H_ */
+#endif /* _LINUXKPI_LINUX_RWLOCK_H_ */
diff --git a/sys/compat/linuxkpi/common/include/linux/rwsem.h b/sys/compat/linuxkpi/common/include/linux/rwsem.h
index 8850da91bd4d..b7a800b12e18 100644
--- a/sys/compat/linuxkpi/common/include/linux/rwsem.h
+++ b/sys/compat/linuxkpi/common/include/linux/rwsem.h
@@ -25,11 +25,9 @@
* 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.
- *
- * $FreeBSD$
*/
-#ifndef _LINUX_RWSEM_H_
-#define _LINUX_RWSEM_H_
+#ifndef _LINUXKPI_LINUX_RWSEM_H_
+#define _LINUXKPI_LINUX_RWSEM_H_
#include <sys/param.h>
#include <sys/lock.h>
@@ -46,11 +44,13 @@ struct rw_semaphore {
#define down_read(_rw) sx_slock(&(_rw)->sx)
#define up_read(_rw) sx_sunlock(&(_rw)->sx)
#define down_read_trylock(_rw) !!sx_try_slock(&(_rw)->sx)
+#define down_read_killable(_rw) linux_down_read_killable(_rw)
#define down_write_trylock(_rw) !!sx_try_xlock(&(_rw)->sx)
#define down_write_killable(_rw) linux_down_write_killable(_rw)
#define downgrade_write(_rw) sx_downgrade(&(_rw)->sx)
#define down_read_nested(_rw, _sc) down_read(_rw)
#define init_rwsem(_rw) linux_init_rwsem(_rw, rwsem_name("lnxrwsem"))
+#define down_write_nest_lock(sem, _rw) down_write(_rw)
#ifdef WITNESS_ALL
/* NOTE: the maximum WITNESS name is 64 chars */
@@ -79,6 +79,7 @@ linux_init_rwsem(struct rw_semaphore *rw, const char *name)
sx_init_flags(&rw->sx, name, SX_NOWITNESS);
}
+extern int linux_down_read_killable(struct rw_semaphore *);
extern int linux_down_write_killable(struct rw_semaphore *);
-#endif /* _LINUX_RWSEM_H_ */
+#endif /* _LINUXKPI_LINUX_RWSEM_H_ */
diff --git a/sys/compat/linuxkpi/common/include/linux/scatterlist.h b/sys/compat/linuxkpi/common/include/linux/scatterlist.h
index 295ca2ba3cfd..537f5bebc5aa 100644
--- a/sys/compat/linuxkpi/common/include/linux/scatterlist.h
+++ b/sys/compat/linuxkpi/common/include/linux/scatterlist.h
@@ -27,15 +27,16 @@
* 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.
- *
- * $FreeBSD$
*/
-#ifndef _LINUX_SCATTERLIST_H_
-#define _LINUX_SCATTERLIST_H_
+#ifndef _LINUXKPI_LINUX_SCATTERLIST_H_
+#define _LINUXKPI_LINUX_SCATTERLIST_H_
#include <sys/types.h>
+#include <sys/proc.h>
+#include <sys/sched.h>
#include <sys/sf_buf.h>
+#include <linux/err.h>
#include <linux/page.h>
#include <linux/slab.h>
#include <linux/mm.h>
@@ -99,6 +100,18 @@ struct sg_dma_page_iter {
#define for_each_sg(sglist, sg, sgmax, iter) \
for (iter = 0, sg = (sglist); iter < (sgmax); iter++, sg = sg_next(sg))
+#define for_each_sgtable_sg(sgt, sg, i) \
+ for_each_sg((sgt)->sgl, sg, (sgt)->orig_nents, i)
+
+#define for_each_sgtable_page(sgt, iter, pgoffset) \
+ for_each_sg_page((sgt)->sgl, iter, (sgt)->orig_nents, pgoffset)
+
+#define for_each_sgtable_dma_sg(sgt, sg, iter) \
+ for_each_sg((sgt)->sgl, sg, (sgt)->nents, iter)
+
+#define for_each_sgtable_dma_page(sgt, iter, pgoffset) \
+ for_each_sg_dma_page((sgt)->sgl, iter, (sgt)->nents, pgoffset)
+
typedef struct scatterlist *(sg_alloc_fn) (unsigned int, gfp_t);
typedef void (sg_free_fn) (struct scatterlist *, unsigned int);
@@ -146,7 +159,7 @@ sg_next(struct scatterlist *sg)
static inline vm_paddr_t
sg_phys(struct scatterlist *sg)
{
- return (VM_PAGE_TO_PHYS(sg_page(sg)) + sg->offset);
+ return (page_to_phys(sg_page(sg)) + sg->offset);
}
static inline void *
@@ -315,18 +328,40 @@ sg_alloc_table(struct sg_table *table, unsigned int nents, gfp_t gfp_mask)
return (ret);
}
+#if defined(LINUXKPI_VERSION) && LINUXKPI_VERSION >= 51300
+static inline struct scatterlist *
+__sg_alloc_table_from_pages(struct sg_table *sgt,
+ struct page **pages, unsigned int count,
+ unsigned long off, unsigned long size,
+ unsigned int max_segment,
+ struct scatterlist *prv, unsigned int left_pages,
+ gfp_t gfp_mask)
+#else
static inline int
__sg_alloc_table_from_pages(struct sg_table *sgt,
struct page **pages, unsigned int count,
unsigned long off, unsigned long size,
unsigned int max_segment, gfp_t gfp_mask)
+#endif
{
unsigned int i, segs, cur, len;
int rc;
- struct scatterlist *s;
+ struct scatterlist *s, *sg_iter;
+
+#if defined(LINUXKPI_VERSION) && LINUXKPI_VERSION >= 51300
+ if (prv != NULL) {
+ panic(
+ "Support for prv != NULL not implemented in "
+ "__sg_alloc_table_from_pages()");
+ }
+#endif
if (__predict_false(!max_segment || offset_in_page(max_segment)))
+#if defined(LINUXKPI_VERSION) && LINUXKPI_VERSION >= 51300
+ return (ERR_PTR(-EINVAL));
+#else
return (-EINVAL);
+#endif
len = 0;
for (segs = i = 1; i < count; ++i) {
@@ -338,13 +373,25 @@ __sg_alloc_table_from_pages(struct sg_table *sgt,
}
}
if (__predict_false((rc = sg_alloc_table(sgt, segs, gfp_mask))))
+#if defined(LINUXKPI_VERSION) && LINUXKPI_VERSION >= 51300
+ return (ERR_PTR(rc));
+#else
return (rc);
+#endif
cur = 0;
- for_each_sg(sgt->sgl, s, sgt->orig_nents, i) {
+ for_each_sg(sgt->sgl, sg_iter, sgt->orig_nents, i) {
unsigned long seg_size;
unsigned int j;
+ /*
+ * We need to make sure that when we exit this loop "s" has the
+ * last sg in the chain so we can call sg_mark_end() on it.
+ * Only set this inside the loop since sg_iter will be iterated
+ * until it is NULL.
+ */
+ s = sg_iter;
+
len = 0;
for (j = cur + 1; j < count; ++j) {
len += PAGE_SIZE;
@@ -359,7 +406,16 @@ __sg_alloc_table_from_pages(struct sg_table *sgt,
off = 0;
cur = j;
}
+ KASSERT(s != NULL, ("s is NULL after loop in __sg_alloc_table_from_pages()"));
+
+#if defined(LINUXKPI_VERSION) && LINUXKPI_VERSION >= 51300
+ if (left_pages == 0)
+ sg_mark_end(s);
+
+ return (s);
+#else
return (0);
+#endif
}
static inline int
@@ -369,8 +425,27 @@ sg_alloc_table_from_pages(struct sg_table *sgt,
gfp_t gfp_mask)
{
+#if defined(LINUXKPI_VERSION) && LINUXKPI_VERSION >= 51300
+ return (PTR_ERR_OR_ZERO(__sg_alloc_table_from_pages(sgt, pages, count, off, size,
+ SCATTERLIST_MAX_SEGMENT, NULL, 0, gfp_mask)));
+#else
return (__sg_alloc_table_from_pages(sgt, pages, count, off, size,
SCATTERLIST_MAX_SEGMENT, gfp_mask));
+#endif
+}
+
+static inline int
+sg_alloc_table_from_pages_segment(struct sg_table *sgt,
+ struct page **pages, unsigned int count, unsigned int off,
+ unsigned long size, unsigned int max_segment, gfp_t gfp_mask)
+{
+#if defined(LINUXKPI_VERSION) && LINUXKPI_VERSION >= 51300
+ return (PTR_ERR_OR_ZERO(__sg_alloc_table_from_pages(sgt, pages, count, off, size,
+ max_segment, NULL, 0, gfp_mask)));
+#else
+ return (__sg_alloc_table_from_pages(sgt, pages, count, off, size,
+ max_segment, gfp_mask));
+#endif
}
static inline int
@@ -581,7 +656,7 @@ sg_pcopy_to_buffer(struct scatterlist *sgl, unsigned int nents,
break;
vaddr = (char *)sf_buf_kva(sf);
} else
- vaddr = (char *)PHYS_TO_DMAP(VM_PAGE_TO_PHYS(page));
+ vaddr = (char *)PHYS_TO_DMAP(page_to_phys(page));
memcpy(buf, vaddr + sg->offset + offset, len);
if (!PMAP_HAS_DMAP)
sf_buf_free(sf);
@@ -599,4 +674,11 @@ sg_pcopy_to_buffer(struct scatterlist *sgl, unsigned int nents,
return (total);
}
-#endif /* _LINUX_SCATTERLIST_H_ */
+static inline void
+sg_set_folio(struct scatterlist *sg, struct folio *folio, size_t len,
+ size_t offset)
+{
+ sg_set_page(sg, &folio->page, len, offset);
+}
+
+#endif /* _LINUXKPI_LINUX_SCATTERLIST_H_ */
diff --git a/sys/compat/linuxkpi/common/include/linux/sched.h b/sys/compat/linuxkpi/common/include/linux/sched.h
index 5954b16f6496..3ad2f8e4ce8b 100644
--- a/sys/compat/linuxkpi/common/include/linux/sched.h
+++ b/sys/compat/linuxkpi/common/include/linux/sched.h
@@ -25,15 +25,14 @@
* 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.
- *
- * $FreeBSD$
*/
-#ifndef _LINUX_SCHED_H_
-#define _LINUX_SCHED_H_
+#ifndef _LINUXKPI_LINUX_SCHED_H_
+#define _LINUXKPI_LINUX_SCHED_H_
#include <sys/param.h>
#include <sys/systm.h>
#include <sys/proc.h>
+#include <sys/rtprio.h>
#include <sys/sched.h>
#include <sys/sleepqueue.h>
#include <sys/time.h>
@@ -41,15 +40,20 @@
#include <linux/bitmap.h>
#include <linux/compat.h>
#include <linux/completion.h>
+#include <linux/hrtimer.h>
#include <linux/mm_types.h>
+#include <linux/nodemask.h>
#include <linux/pid.h>
#include <linux/slab.h>
#include <linux/string.h>
+#include <linux/spinlock.h>
#include <linux/time.h>
+#include <linux/sched/mm.h>
+
#include <asm/atomic.h>
-#define MAX_SCHEDULE_TIMEOUT INT_MAX
+#define MAX_SCHEDULE_TIMEOUT LONG_MAX
#define TASK_RUNNING 0x0000
#define TASK_INTERRUPTIBLE 0x0001
@@ -60,6 +64,8 @@
#define TASK_COMM_LEN (MAXCOMLEN + 1)
+struct seq_file;
+
struct work_struct;
struct task_struct {
struct thread *task_thread;
@@ -125,7 +131,20 @@ put_task_struct(struct task_struct *task)
#define yield() kern_yield(PRI_UNCHANGED)
#define sched_yield() sched_relinquish(curthread)
-#define need_resched() (curthread->td_flags & TDF_NEEDRESCHED)
+#define need_resched() (curthread->td_owepreempt || \
+ td_ast_pending(curthread, TDA_SCHED))
+
+static inline int
+cond_resched_lock(spinlock_t *lock)
+{
+
+ if (need_resched() == 0)
+ return (0);
+ spin_unlock(lock);
+ cond_resched();
+ spin_lock(lock);
+ return (1);
+}
bool linux_signal_pending(struct task_struct *task);
bool linux_fatal_signal_pending(struct task_struct *task);
@@ -141,7 +160,7 @@ void linux_send_sig(int signo, struct task_struct *task);
linux_send_sig(signo, task); \
} while (0)
-int linux_schedule_timeout(int timeout);
+long linux_schedule_timeout(long timeout);
static inline void
linux_schedule_save_interrupt_value(struct task_struct *task, int value)
@@ -162,8 +181,12 @@ linux_schedule_get_interrupt_value(struct task_struct *task)
return (value);
}
-#define schedule() \
- (void)linux_schedule_timeout(MAX_SCHEDULE_TIMEOUT)
+static inline void
+schedule(void)
+{
+ (void)linux_schedule_timeout(MAX_SCHEDULE_TIMEOUT);
+}
+
#define schedule_timeout(timeout) \
linux_schedule_timeout(timeout)
#define schedule_timeout_killable(timeout) \
@@ -197,4 +220,24 @@ get_task_comm(char *buf, struct task_struct *task)
return (task->comm);
}
-#endif /* _LINUX_SCHED_H_ */
+static inline void
+sched_set_fifo(struct task_struct *t)
+{
+ struct rtprio rtp;
+
+ rtp.prio = (RTP_PRIO_MIN + RTP_PRIO_MAX) / 2;
+ rtp.type = RTP_PRIO_FIFO;
+ rtp_to_pri(&rtp, t->task_thread);
+}
+
+static inline void
+sched_set_fifo_low(struct task_struct *t)
+{
+ struct rtprio rtp;
+
+ rtp.prio = RTP_PRIO_MAX; /* lowest priority */
+ rtp.type = RTP_PRIO_FIFO;
+ rtp_to_pri(&rtp, t->task_thread);
+}
+
+#endif /* _LINUXKPI_LINUX_SCHED_H_ */
diff --git a/sys/compat/linuxkpi/common/include/linux/sched/mm.h b/sys/compat/linuxkpi/common/include/linux/sched/mm.h
new file mode 100644
index 000000000000..c26d99378974
--- /dev/null
+++ b/sys/compat/linuxkpi/common/include/linux/sched/mm.h
@@ -0,0 +1,43 @@
+/*-
+ * Copyright (c) 2021 Beckhoff Automation GmbH & Co. KG
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``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 OR CONTRIBUTORS 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.
+ *
+ */
+
+#ifndef _LINUXKPI_LINUX_SCHED_MM_H_
+#define _LINUXKPI_LINUX_SCHED_MM_H_
+
+#include <linux/gfp.h>
+
+#define fs_reclaim_acquire(x) do { \
+ } while (0)
+#define fs_reclaim_release(x) do { \
+ } while (0)
+#define memalloc_nofs_save(x) 0
+#define memalloc_nofs_restore(x) do { \
+ } while (0)
+#define memalloc_noreclaim_save(x) 0
+#define memalloc_noreclaim_restore(x) do { \
+ } while (0)
+
+#endif /* _BSD_LKPI_LINUX_SCHED_MM_H_ */
diff --git a/sys/compat/linuxkpi/common/include/linux/semaphore.h b/sys/compat/linuxkpi/common/include/linux/semaphore.h
index e4a72fd9b47a..4b1a1502e589 100644
--- a/sys/compat/linuxkpi/common/include/linux/semaphore.h
+++ b/sys/compat/linuxkpi/common/include/linux/semaphore.h
@@ -25,11 +25,9 @@
* 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.
- *
- * $FreeBSD$
*/
-#ifndef _LINUX_SEMAPHORE_H_
-#define _LINUX_SEMAPHORE_H_
+#ifndef _LINUXKPI_LINUX_SEMAPHORE_H_
+#define _LINUXKPI_LINUX_SEMAPHORE_H_
#include <sys/param.h>
#include <sys/lock.h>
@@ -67,4 +65,4 @@ init_MUTEX(struct semaphore *sem)
#define sema_init(...) linux_sema_init(__VA_ARGS__)
-#endif /* _LINUX_SEMAPHORE_H_ */
+#endif /* _LINUXKPI_LINUX_SEMAPHORE_H_ */
diff --git a/sys/compat/linuxkpi/common/include/linux/seq_file.h b/sys/compat/linuxkpi/common/include/linux/seq_file.h
index dab8020a0336..47da16ab8688 100644
--- a/sys/compat/linuxkpi/common/include/linux/seq_file.h
+++ b/sys/compat/linuxkpi/common/include/linux/seq_file.h
@@ -1,5 +1,5 @@
/*-
- * SPDX-License-Identifier: BSD-2-Clause-FreeBSD
+ * SPDX-License-Identifier: BSD-2-Clause
*
* Copyright (c) 2016-2018, Matthew Macy <mmacy@freebsd.org>
*
@@ -23,20 +23,24 @@
* 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.
- *
- * $FreeBSD$
*/
-#ifndef _LINUX_SEQ_FILE_H_
-#define _LINUX_SEQ_FILE_H_
+#ifndef _LINUXKPI_LINUX_SEQ_FILE_H_
+#define _LINUXKPI_LINUX_SEQ_FILE_H_
+
+#include <sys/types.h>
+#include <sys/sbuf.h>
#include <linux/types.h>
#include <linux/fs.h>
-#include <sys/sbuf.h>
+#include <linux/string_helpers.h>
+#include <linux/printk.h>
#undef file
#define inode vnode
+MALLOC_DECLARE(M_LSEQ);
+
#define DEFINE_SHOW_ATTRIBUTE(__name) \
static int __name ## _open(struct inode *inode, struct linux_file *file) \
{ \
@@ -51,11 +55,24 @@ static const struct file_operations __name ## _fops = { \
.release = single_release, \
}
-struct seq_operations;
+#define DEFINE_SHOW_STORE_ATTRIBUTE(__name) \
+static int __name ## _open(struct inode *inode, struct linux_file *file) \
+{ \
+ return single_open(file, __name ## _show, inode->i_private); \
+} \
+ \
+static const struct file_operations __name ## _fops = { \
+ .owner = THIS_MODULE, \
+ .open = __name ## _open, \
+ .read = seq_read, \
+ .write = __name ## _write, \
+ .llseek = seq_lseek, \
+ .release = single_release, \
+}
struct seq_file {
- struct sbuf *buf;
-
+ struct sbuf *buf;
+ size_t size;
const struct seq_operations *op;
const struct linux_file *file;
void *private;
@@ -70,19 +87,37 @@ struct seq_operations {
ssize_t seq_read(struct linux_file *, char *, size_t, off_t *);
int seq_write(struct seq_file *seq, const void *data, size_t len);
+void seq_putc(struct seq_file *m, char c);
+void seq_puts(struct seq_file *m, const char *str);
+bool seq_has_overflowed(struct seq_file *m);
+
+void *__seq_open_private(struct linux_file *, const struct seq_operations *, int);
+int seq_release_private(struct inode *, struct linux_file *);
int seq_open(struct linux_file *f, const struct seq_operations *op);
int seq_release(struct inode *inode, struct linux_file *file);
off_t seq_lseek(struct linux_file *file, off_t offset, int whence);
int single_open(struct linux_file *, int (*)(struct seq_file *, void *), void *);
+int single_open_size(struct linux_file *, int (*)(struct seq_file *, void *), void *, size_t);
int single_release(struct inode *, struct linux_file *);
-#define seq_printf(m, fmt, ...) sbuf_printf((m)->buf, (fmt), ##__VA_ARGS__)
+void lkpi_seq_vprintf(struct seq_file *m, const char *fmt, va_list args);
+void lkpi_seq_printf(struct seq_file *m, const char *fmt, ...);
+
+#define seq_vprintf(...) lkpi_seq_vprintf(__VA_ARGS__)
+#define seq_printf(...) lkpi_seq_printf(__VA_ARGS__)
-#define seq_puts(m, str) sbuf_printf((m)->buf, str)
-#define seq_putc(m, str) sbuf_putc((m)->buf, str)
+int __lkpi_hexdump_sbuf_printf(void *, const char *, ...) __printflike(2, 3);
+
+static inline void
+seq_hex_dump(struct seq_file *m, const char *prefix_str, int prefix_type,
+ int rowsize, int groupsize, const void *buf, size_t len, bool ascii)
+{
+ lkpi_hex_dump(__lkpi_hexdump_sbuf_printf, m->buf, NULL, prefix_str, prefix_type,
+ rowsize, groupsize, buf, len, ascii);
+}
#define file linux_file
-#endif /* _LINUX_SEQ_FILE_H_ */
+#endif /* _LINUXKPI_LINUX_SEQ_FILE_H_ */
diff --git a/sys/compat/linuxkpi/common/include/linux/seqlock.h b/sys/compat/linuxkpi/common/include/linux/seqlock.h
index b7ae6e32ae69..554fdfd6e202 100644
--- a/sys/compat/linuxkpi/common/include/linux/seqlock.h
+++ b/sys/compat/linuxkpi/common/include/linux/seqlock.h
@@ -1,5 +1,5 @@
/*-
- * SPDX-License-Identifier: BSD-2-Clause-FreeBSD
+ * SPDX-License-Identifier: BSD-2-Clause
*
* Copyright (c) 2021 Vladimir Kondratyev <wulf@FreeBSD.org>
*
@@ -26,12 +26,15 @@
* SUCH DAMAGE.
*/
-#ifndef _LINUX_SEQLOCK_H__
-#define _LINUX_SEQLOCK_H__
+#ifndef _LINUXKPI_LINUX_SEQLOCK_H__
+#define _LINUXKPI_LINUX_SEQLOCK_H__
#include <sys/param.h>
+#include <sys/systm.h>
+#include <sys/cdefs.h>
#include <sys/lock.h>
#include <sys/mutex.h>
+#include <sys/rwlock.h>
#include <sys/seqc.h>
struct lock_class_key;
@@ -47,6 +50,12 @@ struct seqlock {
};
typedef struct seqlock seqlock_t;
+struct seqcount_mutex {
+ seqc_t seqc;
+};
+typedef struct seqcount_mutex seqcount_mutex_t;
+typedef struct seqcount_mutex seqcount_ww_mutex_t;
+
static inline void
__seqcount_init(struct seqcount *seqcount, const char *name __unused,
struct lock_class_key *key __unused)
@@ -56,37 +65,52 @@ __seqcount_init(struct seqcount *seqcount, const char *name __unused,
#define seqcount_init(seqcount) __seqcount_init(seqcount, NULL, NULL)
static inline void
-write_seqcount_begin(struct seqcount *seqcount)
+seqcount_mutex_init(struct seqcount_mutex *seqcount, void *mutex __unused)
{
- seqc_sleepable_write_begin(&seqcount->seqc);
+ seqcount->seqc = 0;
}
+#define seqcount_ww_mutex_init(seqcount, ww_mutex) \
+ seqcount_mutex_init((seqcount), (ww_mutex))
+
+#define write_seqcount_begin(s) \
+ _Generic(*(s), \
+ struct seqcount: seqc_sleepable_write_begin, \
+ struct seqcount_mutex: seqc_write_begin \
+ )(&(s)->seqc)
+
+#define write_seqcount_end(s) \
+ _Generic(*(s), \
+ struct seqcount: seqc_sleepable_write_end, \
+ struct seqcount_mutex: seqc_write_end \
+ )(&(s)->seqc)
+
static inline void
-write_seqcount_end(struct seqcount *seqcount)
+lkpi_write_seqcount_invalidate(seqc_t *seqcp)
{
- seqc_sleepable_write_end(&seqcount->seqc);
+ atomic_thread_fence_rel();
+ *seqcp += SEQC_MOD * 2;
}
+#define write_seqcount_invalidate(s) lkpi_write_seqcount_invalidate(&(s)->seqc)
+
+#define read_seqcount_begin(s) seqc_read(&(s)->seqc)
+#define raw_read_seqcount(s) seqc_read_any(&(s)->seqc)
+
+static inline seqc_t
+lkpi_seqprop_sequence(const seqc_t *seqcp)
+{
+ return (atomic_load_int(seqcp));
+}
+#define seqprop_sequence(s) lkpi_seqprop_sequence(&(s)->seqc)
/*
* XXX: Are predicts from inline functions still not honored by clang?
*/
#define __read_seqcount_retry(seqcount, gen) \
- (!seqc_consistent_nomb(&(seqcount)->seqc, gen))
+ (!seqc_consistent_no_fence(&(seqcount)->seqc, gen))
#define read_seqcount_retry(seqcount, gen) \
(!seqc_consistent(&(seqcount)->seqc, gen))
-static inline unsigned
-read_seqcount_begin(const struct seqcount *seqcount)
-{
- return (seqc_read(&seqcount->seqc));
-}
-
-static inline unsigned
-raw_read_seqcount(const struct seqcount *seqcount)
-{
- return (seqc_read_any(&seqcount->seqc));
-}
-
static inline void
seqlock_init(struct seqlock *seqlock)
{
@@ -100,29 +124,52 @@ seqlock_init(struct seqlock *seqlock)
}
static inline void
-write_seqlock(struct seqlock *seqlock)
+lkpi_write_seqlock(struct seqlock *seqlock, const bool irqsave)
{
mtx_lock(&seqlock->seql_lock);
+ if (irqsave)
+ critical_enter();
write_seqcount_begin(&seqlock->seql_count);
}
static inline void
-write_sequnlock(struct seqlock *seqlock)
+write_seqlock(struct seqlock *seqlock)
+{
+ lkpi_write_seqlock(seqlock, false);
+}
+
+static inline void
+lkpi_write_sequnlock(struct seqlock *seqlock, const bool irqsave)
{
write_seqcount_end(&seqlock->seql_count);
+ if (irqsave)
+ critical_exit();
mtx_unlock(&seqlock->seql_lock);
}
+static inline void
+write_sequnlock(struct seqlock *seqlock)
+{
+ lkpi_write_sequnlock(seqlock, false);
+}
+
+/*
+ * Disable preemption when the consumer wants to disable interrupts. This
+ * ensures that the caller won't be starved if it is preempted by a
+ * higher-priority reader, but assumes that the caller won't perform any
+ * blocking operations while holding the write lock; probably a safe
+ * assumption.
+ */
#define write_seqlock_irqsave(seqlock, flags) do { \
(flags) = 0; \
- write_seqlock(seqlock); \
+ lkpi_write_seqlock(seqlock, true); \
} while (0)
static inline void
write_sequnlock_irqrestore(struct seqlock *seqlock,
unsigned long flags __unused)
{
- write_sequnlock(seqlock);
+ lkpi_write_sequnlock(seqlock, true);
}
static inline unsigned
@@ -134,4 +181,4 @@ read_seqbegin(const struct seqlock *seqlock)
#define read_seqretry(seqlock, gen) \
read_seqcount_retry(&(seqlock)->seql_count, gen)
-#endif /* _LINUX_SEQLOCK_H__ */
+#endif /* _LINUXKPI_LINUX_SEQLOCK_H__ */
diff --git a/sys/compat/linuxkpi/common/include/linux/shmem_fs.h b/sys/compat/linuxkpi/common/include/linux/shmem_fs.h
index 63aff012c6bb..5e91725d4a1c 100644
--- a/sys/compat/linuxkpi/common/include/linux/shmem_fs.h
+++ b/sys/compat/linuxkpi/common/include/linux/shmem_fs.h
@@ -25,20 +25,22 @@
* 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.
- *
- * $FreeBSD$
*/
-#ifndef _LINUX_SHMEM_FS_H_
-#define _LINUX_SHMEM_FS_H_
+#ifndef _LINUXKPI_LINUX_SHMEM_FS_H_
+#define _LINUXKPI_LINUX_SHMEM_FS_H_
-/* Shared memory support */
-unsigned long linux_invalidate_mapping_pages(vm_object_t, pgoff_t, pgoff_t);
-struct page *linux_shmem_read_mapping_page_gfp(vm_object_t, int, gfp_t);
-struct linux_file *linux_shmem_file_setup(const char *, loff_t, unsigned long);
-void linux_shmem_truncate_range(vm_object_t, loff_t, loff_t);
+#include <linux/file.h>
+#include <linux/mempolicy.h>
+#include <linux/pagemap.h>
+#include <linux/swap.h>
-#define invalidate_mapping_pages(...) \
- linux_invalidate_mapping_pages(__VA_ARGS__)
+/* Shared memory support */
+struct page *linux_shmem_read_mapping_page_gfp(vm_object_t obj, int pindex,
+ gfp_t gfp);
+struct linux_file *linux_shmem_file_setup(const char *name, loff_t size,
+ unsigned long flags);
+void linux_shmem_truncate_range(vm_object_t obj, loff_t lstart,
+ loff_t lend);
#define shmem_read_mapping_page(...) \
linux_shmem_read_mapping_page_gfp(__VA_ARGS__, 0)
@@ -52,4 +54,14 @@ void linux_shmem_truncate_range(vm_object_t, loff_t, loff_t);
#define shmem_truncate_range(...) \
linux_shmem_truncate_range(__VA_ARGS__)
-#endif /* _LINUX_SHMEM_FS_H_ */
+static inline struct folio *
+shmem_read_folio_gfp(vm_object_t obj, int pindex, gfp_t gfp)
+{
+ struct page *page;
+
+ page = shmem_read_mapping_page_gfp(obj, pindex, gfp);
+
+ return (page_folio(page));
+}
+
+#endif /* _LINUXKPI_LINUX_SHMEM_FS_H_ */
diff --git a/sys/compat/linuxkpi/common/include/linux/shrinker.h b/sys/compat/linuxkpi/common/include/linux/shrinker.h
index d18bb60645f8..eb95dafb83ce 100644
--- a/sys/compat/linuxkpi/common/include/linux/shrinker.h
+++ b/sys/compat/linuxkpi/common/include/linux/shrinker.h
@@ -21,16 +21,18 @@
* 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.
- *
- * $FreeBSD$
*/
-#ifndef __LINUX_SHRINKER_H__
-#define __LINUX_SHRINKER_H__
+#ifndef _LINUXKPI_LINUX_SHRINKER_H_
+#define _LINUXKPI_LINUX_SHRINKER_H_
#include <sys/queue.h>
+#include <linux/bitops.h>
+#include <linux/gfp.h>
+
struct shrink_control {
+ gfp_t gfp_mask;
unsigned long nr_to_scan;
unsigned long nr_scanned;
};
@@ -39,6 +41,8 @@ struct shrinker {
unsigned long (*count_objects)(struct shrinker *, struct shrink_control *);
unsigned long (*scan_objects)(struct shrinker *, struct shrink_control *);
int seeks;
+ unsigned int flags;
+ void * private_data;
long batch;
TAILQ_ENTRY(shrinker) next;
};
@@ -47,10 +51,29 @@ struct shrinker {
#define DEFAULT_SEEKS 2
+#define SHRINKER_REGISTERED BIT(0)
+#define SHRINKER_ALLOCATED BIT(1)
+
+struct shrinker *linuxkpi_shrinker_alloc(
+ unsigned int flags, const char *fmt, ...);
int linuxkpi_register_shrinker(struct shrinker *s);
void linuxkpi_unregister_shrinker(struct shrinker *s);
+void linuxkpi_shrinker_free(struct shrinker *shrinker);
+void linuxkpi_synchronize_shrinkers(void);
+
+#define shrinker_alloc(flags, fmt, ...) \
+ linuxkpi_shrinker_alloc(flags, fmt __VA_OPT__(,) __VA_ARGS__)
+#define shrinker_register(shrinker) \
+ linuxkpi_register_shrinker(shrinker)
+#define shrinker_free(shrinker) \
+ linuxkpi_shrinker_free(shrinker)
+#if defined(LINUXKPI_VERSION) && LINUXKPI_VERSION >= 60000
+#define register_shrinker(s, ...) linuxkpi_register_shrinker(s)
+#else
#define register_shrinker(s) linuxkpi_register_shrinker(s)
+#endif
#define unregister_shrinker(s) linuxkpi_unregister_shrinker(s)
+#define synchronize_shrinkers() linuxkpi_synchronize_shrinkers()
-#endif /* __LINUX_SHRINKER_H__ */
+#endif /* _LINUXKPI_LINUX_SHRINKER_H_ */
diff --git a/sys/compat/linuxkpi/common/include/linux/sizes.h b/sys/compat/linuxkpi/common/include/linux/sizes.h
index a180cee5f022..d8a6e75192f6 100644
--- a/sys/compat/linuxkpi/common/include/linux/sizes.h
+++ b/sys/compat/linuxkpi/common/include/linux/sizes.h
@@ -24,14 +24,13 @@
* 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.
- *
- * $FreeBSD$
*/
-#ifndef __LINUX_SIZES_H__
-#define __LINUX_SIZES_H__
+#ifndef _LINUXKPI_LINUX_SIZES_H_
+#define _LINUXKPI_LINUX_SIZES_H_
#define SZ_1K (1024 * 1)
+#define SZ_2K (1024 * 2)
#define SZ_4K (1024 * 4)
#define SZ_8K (1024 * 8)
#define SZ_16K (1024 * 16)
@@ -43,9 +42,22 @@
#define SZ_1M (1024 * 1024 * 1)
#define SZ_2M (1024 * 1024 * 2)
+#define SZ_4M (1024 * 1024 * 4)
#define SZ_8M (1024 * 1024 * 8)
#define SZ_16M (1024 * 1024 * 16)
#define SZ_32M (1024 * 1024 * 32)
#define SZ_64M (1024 * 1024 * 64)
+#define SZ_128M (1024 * 1024 * 128)
+#define SZ_256M (1024 * 1024 * 256)
+#define SZ_512M (1024 * 1024 * 512)
+
+#define SZ_1G (1024 * 1024 * 1024 * 1)
+#define SZ_2G (1024 * 1024 * 1024 * 2)
+#define SZ_4G (1024 * 1024 * 1024 * 4)
+#define SZ_8G (1024 * 1024 * 1024 * 8)
+#define SZ_16G (1024 * 1024 * 1024 * 16)
+#define SZ_32G (1024 * 1024 * 1024 * 32)
+
+#define SZ_64T (1024 * 1024 * 1024 * 1024 * 64)
#endif
diff --git a/sys/compat/linuxkpi/common/include/linux/skbuff.h b/sys/compat/linuxkpi/common/include/linux/skbuff.h
new file mode 100644
index 000000000000..2e560a120e41
--- /dev/null
+++ b/sys/compat/linuxkpi/common/include/linux/skbuff.h
@@ -0,0 +1,1168 @@
+/*-
+ * Copyright (c) 2020-2025 The FreeBSD Foundation
+ * Copyright (c) 2021-2025 Bjoern A. Zeeb
+ *
+ * This software was developed by Björn Zeeb under sponsorship from
+ * the FreeBSD Foundation.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``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 OR CONTRIBUTORS 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.
+ */
+
+/*
+ * NOTE: this socket buffer compatibility code is highly EXPERIMENTAL.
+ * Do not rely on the internals of this implementation. They are highly
+ * likely to change as we will improve the integration to FreeBSD mbufs.
+ */
+
+#ifndef _LINUXKPI_LINUX_SKBUFF_H
+#define _LINUXKPI_LINUX_SKBUFF_H
+
+#include <linux/kernel.h>
+#include <linux/page.h>
+#include <linux/dma-mapping.h>
+#include <linux/netdev_features.h>
+#include <linux/list.h>
+#include <linux/gfp.h>
+#include <linux/compiler.h>
+#include <linux/spinlock.h>
+#include <linux/ktime.h>
+#include <linux/compiler.h>
+
+/*
+ * At least the net/intel-irdma-kmod port pulls this header in; likely through
+ * if_ether.h (see PR289268). This means we no longer can rely on
+ * IEEE80211_DEBUG (opt_wlan.h) to automatically set SKB_DEBUG.
+ */
+/* #define SKB_DEBUG */
+
+#ifdef SKB_DEBUG
+#define DSKB_TODO 0x01
+#define DSKB_IMPROVE 0x02
+#define DSKB_TRACE 0x10
+#define DSKB_TRACEX 0x20
+extern int linuxkpi_debug_skb;
+
+#define SKB_TODO() \
+ if (linuxkpi_debug_skb & DSKB_TODO) \
+ printf("SKB_TODO %s:%d\n", __func__, __LINE__)
+#define SKB_IMPROVE(...) \
+ if (linuxkpi_debug_skb & DSKB_IMPROVE) \
+ printf("SKB_IMPROVE %s:%d\n", __func__, __LINE__)
+#define SKB_TRACE(_s) \
+ if (linuxkpi_debug_skb & DSKB_TRACE) \
+ printf("SKB_TRACE %s:%d %p\n", __func__, __LINE__, _s)
+#define SKB_TRACE2(_s, _p) \
+ if (linuxkpi_debug_skb & DSKB_TRACE) \
+ printf("SKB_TRACE %s:%d %p, %p\n", __func__, __LINE__, _s, _p)
+#define SKB_TRACE_FMT(_s, _fmt, ...) \
+ if (linuxkpi_debug_skb & DSKB_TRACE) \
+ printf("SKB_TRACE %s:%d %p " _fmt "\n", __func__, __LINE__, _s, \
+ __VA_ARGS__)
+#else
+#define SKB_TODO() do { } while(0)
+#define SKB_IMPROVE(...) do { } while(0)
+#define SKB_TRACE(_s) do { } while(0)
+#define SKB_TRACE2(_s, _p) do { } while(0)
+#define SKB_TRACE_FMT(_s, ...) do { } while(0)
+#endif
+
+enum sk_buff_pkt_type {
+ PACKET_BROADCAST,
+ PACKET_MULTICAST,
+ PACKET_OTHERHOST,
+};
+
+struct skb_shared_hwtstamps {
+ ktime_t hwtstamp;
+};
+
+#define NET_SKB_PAD max(CACHE_LINE_SIZE, 32)
+#define SKB_DATA_ALIGN(_x) roundup2(_x, CACHE_LINE_SIZE)
+
+struct sk_buff_head {
+ /* XXX TODO */
+ union {
+ struct {
+ struct sk_buff *next;
+ struct sk_buff *prev;
+ };
+ struct sk_buff_head_l {
+ struct sk_buff *next;
+ struct sk_buff *prev;
+ } list;
+ };
+ size_t qlen;
+ spinlock_t lock;
+};
+
+enum sk_checksum_flags {
+ CHECKSUM_NONE = 0x00,
+ CHECKSUM_UNNECESSARY = 0x01,
+ CHECKSUM_PARTIAL = 0x02,
+ CHECKSUM_COMPLETE = 0x03,
+};
+
+struct skb_frag {
+ /* XXX TODO */
+ struct page *page; /* XXX-BZ These three are a wild guess so far! */
+ off_t offset;
+ size_t size;
+};
+typedef struct skb_frag skb_frag_t;
+
+enum skb_shared_info_gso_type {
+ SKB_GSO_TCPV4,
+ SKB_GSO_TCPV6,
+};
+
+struct skb_shared_info {
+ enum skb_shared_info_gso_type gso_type;
+ uint16_t gso_size;
+ uint16_t nr_frags;
+ struct sk_buff *frag_list;
+ skb_frag_t frags[64]; /* XXX TODO, 16xpage? */
+};
+
+struct sk_buff {
+ /* XXX TODO */
+ union {
+ /* struct sk_buff_head */
+ struct {
+ struct sk_buff *next;
+ struct sk_buff *prev;
+ };
+ struct list_head list;
+ };
+
+ uint8_t *head; /* Head of buffer. */
+ uint8_t *data; /* Head of data. */
+ uint8_t *tail; /* End of data. */
+ uint8_t *end; /* End of buffer. */
+
+ uint32_t len; /* ? */
+ uint32_t data_len; /* ? If we have frags? */
+ union {
+ __wsum csum;
+ struct {
+ uint16_t csum_offset;
+ uint16_t csum_start;
+ };
+ };
+ uint16_t protocol;
+ uint8_t ip_summed; /* 2 bit only. */
+ /* uint8_t */
+
+ /* "Scratch" area for layers to store metadata. */
+ /* ??? I see sizeof() operations so probably an array. */
+ uint8_t cb[64] __aligned(CACHE_LINE_SIZE);
+
+ struct skb_shared_info *shinfo __aligned(CACHE_LINE_SIZE);
+
+ uint32_t truesize; /* The total size of all buffers, incl. frags. */
+ uint32_t priority;
+ uint16_t qmap; /* queue mapping */
+ uint16_t _flags; /* Internal flags. */
+#define _SKB_FLAGS_SKBEXTFRAG 0x0001
+ uint16_t l3hdroff; /* network header offset from *head */
+ uint16_t l4hdroff; /* transport header offset from *head */
+ uint16_t mac_header; /* offset of mac_header */
+ uint16_t mac_len; /* Link-layer header length. */
+ enum sk_buff_pkt_type pkt_type;
+ refcount_t refcnt;
+
+ struct net_device *dev;
+ void *sk; /* XXX net/sock.h? */
+
+ /* FreeBSD specific bandaid (see linuxkpi_kfree_skb). */
+ void *m;
+ void(*m_free_func)(void *);
+
+ /* Force padding to CACHE_LINE_SIZE. */
+ uint8_t __scratch[0] __aligned(CACHE_LINE_SIZE);
+};
+
+/* -------------------------------------------------------------------------- */
+
+struct sk_buff *linuxkpi_alloc_skb(size_t, gfp_t);
+struct sk_buff *linuxkpi_dev_alloc_skb(size_t, gfp_t);
+struct sk_buff *linuxkpi_build_skb(void *, size_t);
+void linuxkpi_kfree_skb(struct sk_buff *);
+
+struct sk_buff *linuxkpi_skb_copy(const struct sk_buff *, gfp_t);
+
+/* -------------------------------------------------------------------------- */
+
+static inline struct sk_buff *
+alloc_skb(size_t size, gfp_t gfp)
+{
+ struct sk_buff *skb;
+
+ skb = linuxkpi_alloc_skb(size, gfp);
+ SKB_TRACE(skb);
+ return (skb);
+}
+
+static inline struct sk_buff *
+__dev_alloc_skb(size_t len, gfp_t gfp)
+{
+ struct sk_buff *skb;
+
+ skb = linuxkpi_dev_alloc_skb(len, gfp);
+ SKB_IMPROVE();
+ SKB_TRACE(skb);
+ return (skb);
+}
+
+static inline struct sk_buff *
+dev_alloc_skb(size_t len)
+{
+ struct sk_buff *skb;
+
+ skb = __dev_alloc_skb(len, GFP_NOWAIT);
+ SKB_IMPROVE();
+ SKB_TRACE(skb);
+ return (skb);
+}
+
+static inline void
+kfree_skb(struct sk_buff *skb)
+{
+ SKB_TRACE(skb);
+ linuxkpi_kfree_skb(skb);
+}
+
+static inline void
+consume_skb(struct sk_buff *skb)
+{
+ SKB_TRACE(skb);
+ kfree_skb(skb);
+}
+
+static inline void
+dev_kfree_skb(struct sk_buff *skb)
+{
+ SKB_TRACE(skb);
+ kfree_skb(skb);
+}
+
+static inline void
+dev_kfree_skb_any(struct sk_buff *skb)
+{
+ SKB_TRACE(skb);
+ dev_kfree_skb(skb);
+}
+
+static inline void
+dev_kfree_skb_irq(struct sk_buff *skb)
+{
+ SKB_TRACE(skb);
+ SKB_IMPROVE("Do we have to defer this?");
+ dev_kfree_skb(skb);
+}
+
+static inline struct sk_buff *
+build_skb(void *data, unsigned int fragsz)
+{
+ struct sk_buff *skb;
+
+ skb = linuxkpi_build_skb(data, fragsz);
+ SKB_TRACE(skb);
+ return (skb);
+}
+
+/* -------------------------------------------------------------------------- */
+
+static inline bool
+skb_is_nonlinear(struct sk_buff *skb)
+{
+ SKB_TRACE(skb);
+ return ((skb->data_len > 0) ? true : false);
+}
+
+/* Add headroom; cannot do once there is data in there. */
+static inline void
+skb_reserve(struct sk_buff *skb, size_t len)
+{
+ SKB_TRACE(skb);
+#if 0
+ /* Apparently it is allowed to call skb_reserve multiple times in a row. */
+ KASSERT(skb->data == skb->head, ("%s: skb %p not empty head %p data %p "
+ "tail %p\n", __func__, skb, skb->head, skb->data, skb->tail));
+#else
+ KASSERT(skb->len == 0 && skb->data == skb->tail, ("%s: skb %p not "
+ "empty head %p data %p tail %p len %u\n", __func__, skb,
+ skb->head, skb->data, skb->tail, skb->len));
+#endif
+ skb->data += len;
+ skb->tail += len;
+}
+
+/*
+ * Remove headroom; return new data pointer; basically make space at the
+ * front to copy data in (manually).
+ */
+static inline void *
+__skb_push(struct sk_buff *skb, size_t len)
+{
+ SKB_TRACE(skb);
+ KASSERT(((skb->data - len) >= skb->head), ("%s: skb %p (data %p - "
+ "len %zu) < head %p\n", __func__, skb, skb->data, len, skb->data));
+ skb->len += len;
+ skb->data -= len;
+ return (skb->data);
+}
+
+static inline void *
+skb_push(struct sk_buff *skb, size_t len)
+{
+
+ SKB_TRACE(skb);
+ return (__skb_push(skb, len));
+}
+
+/*
+ * Length of the data on the skb (without any frags)???
+ */
+static inline size_t
+skb_headlen(struct sk_buff *skb)
+{
+
+ SKB_TRACE(skb);
+ return (skb->len - skb->data_len);
+}
+
+
+/* Return the end of data (tail pointer). */
+static inline uint8_t *
+skb_tail_pointer(struct sk_buff *skb)
+{
+
+ SKB_TRACE(skb);
+ return (skb->tail);
+}
+
+/* Return number of bytes available at end of buffer. */
+static inline unsigned int
+skb_tailroom(struct sk_buff *skb)
+{
+
+ SKB_TRACE(skb);
+ KASSERT((skb->end - skb->tail) >= 0, ("%s: skb %p tailroom < 0, "
+ "end %p tail %p\n", __func__, skb, skb->end, skb->tail));
+ if (unlikely(skb_is_nonlinear(skb)))
+ return (0);
+ return (skb->end - skb->tail);
+}
+
+/* Return number of bytes available at the beginning of buffer. */
+static inline unsigned int
+skb_headroom(const struct sk_buff *skb)
+{
+ SKB_TRACE(skb);
+ KASSERT((skb->data - skb->head) >= 0, ("%s: skb %p headroom < 0, "
+ "data %p head %p\n", __func__, skb, skb->data, skb->head));
+ return (skb->data - skb->head);
+}
+
+
+/*
+ * Remove tailroom; return the old tail pointer; basically make space at
+ * the end to copy data in (manually). See also skb_put_data() below.
+ */
+static inline void *
+__skb_put(struct sk_buff *skb, size_t len)
+{
+ void *s;
+
+ SKB_TRACE(skb);
+ KASSERT(((skb->tail + len) <= skb->end), ("%s: skb %p (tail %p + "
+ "len %zu) > end %p, head %p data %p len %u\n", __func__,
+ skb, skb->tail, len, skb->end, skb->head, skb->data, skb->len));
+
+ s = skb_tail_pointer(skb);
+ if (len == 0)
+ return (s);
+ skb->tail += len;
+ skb->len += len;
+#ifdef SKB_DEBUG
+ if (linuxkpi_debug_skb & DSKB_TRACEX)
+ printf("%s: skb %p (%u) head %p data %p tail %p end %p, s %p len %zu\n",
+ __func__, skb, skb->len, skb->head, skb->data, skb->tail, skb->end,
+ s, len);
+#endif
+ return (s);
+}
+
+static inline void *
+skb_put(struct sk_buff *skb, size_t len)
+{
+
+ SKB_TRACE(skb);
+ return (__skb_put(skb, len));
+}
+
+/* skb_put() + copying data in. */
+static inline void *
+skb_put_data(struct sk_buff *skb, const void *buf, size_t len)
+{
+ void *s;
+
+ SKB_TRACE2(skb, buf);
+ s = skb_put(skb, len);
+ if (len == 0)
+ return (s);
+ memcpy(s, buf, len);
+ return (s);
+}
+
+/* skb_put() + filling with zeros. */
+static inline void *
+skb_put_zero(struct sk_buff *skb, size_t len)
+{
+ void *s;
+
+ SKB_TRACE(skb);
+ s = skb_put(skb, len);
+ memset(s, '\0', len);
+ return (s);
+}
+
+/*
+ * Remove len bytes from beginning of data.
+ *
+ * XXX-BZ ath10k checks for !NULL conditions so I assume this doesn't panic;
+ * we return the advanced data pointer so we don't have to keep a temp, correct?
+ */
+static inline void *
+skb_pull(struct sk_buff *skb, size_t len)
+{
+
+ SKB_TRACE(skb);
+#if 0 /* Apparently this doesn't barf... */
+ KASSERT(skb->len >= len, ("%s: skb %p skb->len %u < len %u, data %p\n",
+ __func__, skb, skb->len, len, skb->data));
+#endif
+ if (skb->len < len)
+ return (NULL);
+ skb->len -= len;
+ skb->data += len;
+ return (skb->data);
+}
+
+/* Reduce skb data to given length or do nothing if smaller already. */
+static inline void
+__skb_trim(struct sk_buff *skb, unsigned int len)
+{
+
+ SKB_TRACE(skb);
+ if (skb->len < len)
+ return;
+
+ skb->len = len;
+ skb->tail = skb->data + skb->len;
+}
+
+static inline void
+skb_trim(struct sk_buff *skb, unsigned int len)
+{
+
+ return (__skb_trim(skb, len));
+}
+
+static inline struct skb_shared_info *
+skb_shinfo(struct sk_buff *skb)
+{
+
+ SKB_TRACE(skb);
+ return (skb->shinfo);
+}
+
+static inline void
+skb_add_rx_frag(struct sk_buff *skb, int fragno, struct page *page,
+ off_t offset, size_t size, unsigned int truesize)
+{
+ struct skb_shared_info *shinfo;
+
+ SKB_TRACE(skb);
+#ifdef SKB_DEBUG
+ if (linuxkpi_debug_skb & DSKB_TRACEX)
+ printf("%s: skb %p head %p data %p tail %p end %p len %u fragno %d "
+ "page %#jx offset %ju size %zu truesize %u\n", __func__,
+ skb, skb->head, skb->data, skb->tail, skb->end, skb->len, fragno,
+ (uintmax_t)(uintptr_t)linux_page_address(page), (uintmax_t)offset,
+ size, truesize);
+#endif
+
+ shinfo = skb_shinfo(skb);
+ KASSERT(fragno >= 0 && fragno < nitems(shinfo->frags), ("%s: skb %p "
+ "fragno %d too big\n", __func__, skb, fragno));
+ shinfo->frags[fragno].page = page;
+ shinfo->frags[fragno].offset = offset;
+ shinfo->frags[fragno].size = size;
+ shinfo->nr_frags = fragno + 1;
+ skb->len += size;
+ skb->data_len += size;
+ skb->truesize += truesize;
+}
+
+/* -------------------------------------------------------------------------- */
+
+#define skb_queue_walk(_q, skb) \
+ for ((skb) = (_q)->next; (skb) != (struct sk_buff *)(_q); \
+ (skb) = (skb)->next)
+
+#define skb_queue_walk_safe(_q, skb, tmp) \
+ for ((skb) = (_q)->next, (tmp) = (skb)->next; \
+ (skb) != (struct sk_buff *)(_q); (skb) = (tmp), (tmp) = (skb)->next)
+
+#define skb_list_walk_safe(_q, skb, tmp) \
+ for ((skb) = (_q), (tmp) = ((skb) != NULL) ? (skb)->next ? NULL; \
+ ((skb) != NULL); \
+ (skb) = (tmp), (tmp) = ((skb) != NULL) ? (skb)->next ? NULL)
+
+static inline bool
+skb_queue_empty(const struct sk_buff_head *q)
+{
+ SKB_TRACE(q);
+ return (q->next == (const struct sk_buff *)q);
+}
+
+static inline bool
+skb_queue_empty_lockless(const struct sk_buff_head *q)
+{
+ SKB_TRACE(q);
+ return (READ_ONCE(q->next) == (const struct sk_buff *)q);
+}
+
+static inline void
+__skb_queue_head_init(struct sk_buff_head *q)
+{
+ SKB_TRACE(q);
+ q->prev = q->next = (struct sk_buff *)q;
+ q->qlen = 0;
+}
+
+static inline void
+skb_queue_head_init(struct sk_buff_head *q)
+{
+ SKB_TRACE(q);
+ __skb_queue_head_init(q);
+ spin_lock_init(&q->lock);
+}
+
+static inline void
+__skb_insert(struct sk_buff *new, struct sk_buff *prev, struct sk_buff *next,
+ struct sk_buff_head *q)
+{
+
+ SKB_TRACE_FMT(new, "prev %p next %p q %p", prev, next, q);
+ WRITE_ONCE(new->prev, prev);
+ WRITE_ONCE(new->next, next);
+ WRITE_ONCE(((struct sk_buff_head_l *)next)->prev, new);
+ WRITE_ONCE(((struct sk_buff_head_l *)prev)->next, new);
+ WRITE_ONCE(q->qlen, q->qlen + 1);
+}
+
+static inline void
+__skb_queue_after(struct sk_buff_head *q, struct sk_buff *skb,
+ struct sk_buff *new)
+{
+
+ SKB_TRACE_FMT(q, "skb %p new %p", skb, new);
+ __skb_insert(new, skb, ((struct sk_buff_head_l *)skb)->next, q);
+}
+
+static inline void
+__skb_queue_before(struct sk_buff_head *q, struct sk_buff *skb,
+ struct sk_buff *new)
+{
+
+ SKB_TRACE_FMT(q, "skb %p new %p", skb, new);
+ __skb_insert(new, skb->prev, skb, q);
+}
+
+static inline void
+__skb_queue_tail(struct sk_buff_head *q, struct sk_buff *new)
+{
+
+ SKB_TRACE2(q, new);
+ __skb_queue_before(q, (struct sk_buff *)q, new);
+}
+
+static inline void
+skb_queue_tail(struct sk_buff_head *q, struct sk_buff *new)
+{
+ unsigned long flags;
+
+ SKB_TRACE2(q, new);
+ spin_lock_irqsave(&q->lock, flags);
+ __skb_queue_tail(q, new);
+ spin_unlock_irqrestore(&q->lock, flags);
+}
+
+static inline struct sk_buff *
+skb_peek(const struct sk_buff_head *q)
+{
+ struct sk_buff *skb;
+
+ skb = q->next;
+ SKB_TRACE2(q, skb);
+ if (skb == (const struct sk_buff *)q)
+ return (NULL);
+ return (skb);
+}
+
+static inline struct sk_buff *
+skb_peek_tail(const struct sk_buff_head *q)
+{
+ struct sk_buff *skb;
+
+ skb = READ_ONCE(q->prev);
+ SKB_TRACE2(q, skb);
+ if (skb == (const struct sk_buff *)q)
+ return (NULL);
+ return (skb);
+}
+
+static inline void
+__skb_unlink(struct sk_buff *skb, struct sk_buff_head *q)
+{
+ struct sk_buff *p, *n;
+
+ SKB_TRACE2(skb, q);
+
+ WRITE_ONCE(q->qlen, q->qlen - 1);
+ p = skb->prev;
+ n = skb->next;
+ WRITE_ONCE(n->prev, p);
+ WRITE_ONCE(p->next, n);
+ skb->prev = skb->next = NULL;
+}
+
+static inline void
+skb_unlink(struct sk_buff *skb, struct sk_buff_head *q)
+{
+ unsigned long flags;
+
+ SKB_TRACE2(skb, q);
+ spin_lock_irqsave(&q->lock, flags);
+ __skb_unlink(skb, q);
+ spin_unlock_irqrestore(&q->lock, flags);
+}
+
+static inline struct sk_buff *
+__skb_dequeue(struct sk_buff_head *q)
+{
+ struct sk_buff *skb;
+
+ skb = skb_peek(q);
+ if (skb != NULL)
+ __skb_unlink(skb, q);
+ SKB_TRACE2(q, skb);
+ return (skb);
+}
+
+static inline struct sk_buff *
+skb_dequeue(struct sk_buff_head *q)
+{
+ unsigned long flags;
+ struct sk_buff *skb;
+
+ spin_lock_irqsave(&q->lock, flags);
+ skb = __skb_dequeue(q);
+ spin_unlock_irqrestore(&q->lock, flags);
+ SKB_TRACE2(q, skb);
+ return (skb);
+}
+
+static inline struct sk_buff *
+__skb_dequeue_tail(struct sk_buff_head *q)
+{
+ struct sk_buff *skb;
+
+ skb = skb_peek_tail(q);
+ if (skb != NULL)
+ __skb_unlink(skb, q);
+ SKB_TRACE2(q, skb);
+ return (skb);
+}
+
+static inline struct sk_buff *
+skb_dequeue_tail(struct sk_buff_head *q)
+{
+ unsigned long flags;
+ struct sk_buff *skb;
+
+ spin_lock_irqsave(&q->lock, flags);
+ skb = __skb_dequeue_tail(q);
+ spin_unlock_irqrestore(&q->lock, flags);
+ SKB_TRACE2(q, skb);
+ return (skb);
+}
+
+static inline void
+__skb_queue_head(struct sk_buff_head *q, struct sk_buff *skb)
+{
+
+ SKB_TRACE2(q, skb);
+ __skb_queue_after(q, (struct sk_buff *)q, skb);
+}
+
+static inline void
+skb_queue_head(struct sk_buff_head *q, struct sk_buff *skb)
+{
+ unsigned long flags;
+
+ SKB_TRACE2(q, skb);
+ spin_lock_irqsave(&q->lock, flags);
+ __skb_queue_head(q, skb);
+ spin_unlock_irqrestore(&q->lock, flags);
+}
+
+static inline uint32_t
+skb_queue_len(const struct sk_buff_head *q)
+{
+
+ SKB_TRACE(q);
+ return (q->qlen);
+}
+
+static inline uint32_t
+skb_queue_len_lockless(const struct sk_buff_head *q)
+{
+
+ SKB_TRACE(q);
+ return (READ_ONCE(q->qlen));
+}
+
+static inline void
+___skb_queue_splice(const struct sk_buff_head *from,
+ struct sk_buff *p, struct sk_buff *n)
+{
+ struct sk_buff *b, *e;
+
+ b = from->next;
+ e = from->prev;
+
+ WRITE_ONCE(b->prev, p);
+ WRITE_ONCE(((struct sk_buff_head_l *)p)->next, b);
+ WRITE_ONCE(e->next, n);
+ WRITE_ONCE(((struct sk_buff_head_l *)n)->prev, e);
+}
+
+static inline void
+skb_queue_splice_init(struct sk_buff_head *from, struct sk_buff_head *to)
+{
+
+ SKB_TRACE2(from, to);
+
+ if (skb_queue_empty(from))
+ return;
+
+ ___skb_queue_splice(from, (struct sk_buff *)to, to->next);
+ to->qlen += from->qlen;
+ __skb_queue_head_init(from);
+}
+
+static inline void
+skb_queue_splice_tail_init(struct sk_buff_head *from, struct sk_buff_head *to)
+{
+
+ SKB_TRACE2(from, to);
+
+ if (skb_queue_empty(from))
+ return;
+
+ ___skb_queue_splice(from, to->prev, (struct sk_buff *)to);
+ to->qlen += from->qlen;
+ __skb_queue_head_init(from);
+}
+
+
+static inline void
+__skb_queue_purge(struct sk_buff_head *q)
+{
+ struct sk_buff *skb;
+
+ SKB_TRACE(q);
+ while ((skb = __skb_dequeue(q)) != NULL)
+ kfree_skb(skb);
+ WARN_ONCE(skb_queue_len(q) != 0, "%s: queue %p not empty: %u",
+ __func__, q, skb_queue_len(q));
+}
+
+static inline void
+skb_queue_purge(struct sk_buff_head *q)
+{
+ struct sk_buff_head _q;
+ unsigned long flags;
+
+ SKB_TRACE(q);
+
+ if (skb_queue_empty_lockless(q))
+ return;
+
+ __skb_queue_head_init(&_q);
+ spin_lock_irqsave(&q->lock, flags);
+ skb_queue_splice_init(q, &_q);
+ spin_unlock_irqrestore(&q->lock, flags);
+ __skb_queue_purge(&_q);
+}
+
+static inline struct sk_buff *
+skb_queue_prev(struct sk_buff_head *q, struct sk_buff *skb)
+{
+
+ SKB_TRACE2(q, skb);
+ /* XXX what is the q argument good for? */
+ return (skb->prev);
+}
+
+/* -------------------------------------------------------------------------- */
+
+static inline struct sk_buff *
+skb_copy(const struct sk_buff *skb, gfp_t gfp)
+{
+ struct sk_buff *new;
+
+ new = linuxkpi_skb_copy(skb, gfp);
+ SKB_TRACE2(skb, new);
+ return (new);
+}
+
+static inline uint16_t
+skb_checksum(struct sk_buff *skb, int offs, size_t len, int x)
+{
+ SKB_TRACE(skb);
+ SKB_TODO();
+ return (0xffff);
+}
+
+static inline int
+skb_checksum_start_offset(struct sk_buff *skb)
+{
+ SKB_TRACE(skb);
+ SKB_TODO();
+ return (-1);
+}
+
+static inline dma_addr_t
+skb_frag_dma_map(struct device *dev, const skb_frag_t *frag, int x,
+ size_t fragsz, enum dma_data_direction dir)
+{
+ SKB_TRACE2(frag, dev);
+ SKB_TODO();
+ return (-1);
+}
+
+static inline size_t
+skb_frag_size(const skb_frag_t *frag)
+{
+ SKB_TRACE(frag);
+ return (frag->size);
+}
+
+#define skb_walk_frags(_skb, _frag) \
+ for ((_frag) = (_skb); false; (_frag)++)
+
+static inline void
+skb_checksum_help(struct sk_buff *skb)
+{
+ SKB_TRACE(skb);
+ SKB_TODO();
+}
+
+static inline bool
+skb_ensure_writable(struct sk_buff *skb, size_t off)
+{
+ SKB_TRACE(skb);
+ SKB_TODO();
+ return (false);
+}
+
+static inline void *
+skb_frag_address(const skb_frag_t *frag)
+{
+ SKB_TRACE(frag);
+ return (page_address(frag->page + frag->offset));
+}
+
+static inline void
+skb_free_frag(void *frag)
+{
+
+ page_frag_free(frag);
+}
+
+static inline struct sk_buff *
+skb_gso_segment(struct sk_buff *skb, netdev_features_t netdev_flags)
+{
+ SKB_TRACE(skb);
+ SKB_TODO();
+ return (NULL);
+}
+
+static inline bool
+skb_is_gso(struct sk_buff *skb)
+{
+ SKB_TRACE(skb);
+ SKB_IMPROVE("Really a TODO but get it away from logging");
+ return (false);
+}
+
+static inline void
+skb_mark_not_on_list(struct sk_buff *skb)
+{
+ SKB_TRACE(skb);
+ skb->next = NULL;
+}
+
+static inline void
+skb_reset_transport_header(struct sk_buff *skb)
+{
+
+ SKB_TRACE(skb);
+ skb->l4hdroff = skb->data - skb->head;
+}
+
+static inline uint8_t *
+skb_transport_header(struct sk_buff *skb)
+{
+
+ SKB_TRACE(skb);
+ return (skb->head + skb->l4hdroff);
+}
+
+static inline uint8_t *
+skb_network_header(struct sk_buff *skb)
+{
+
+ SKB_TRACE(skb);
+ return (skb->head + skb->l3hdroff);
+}
+
+static inline int
+__skb_linearize(struct sk_buff *skb)
+{
+ SKB_TRACE(skb);
+ SKB_TODO();
+ return (-ENXIO);
+}
+
+static inline int
+skb_linearize(struct sk_buff *skb)
+{
+ return (skb_is_nonlinear(skb) ? __skb_linearize(skb) : 0);
+}
+
+static inline int
+pskb_expand_head(struct sk_buff *skb, int x, int len, gfp_t gfp)
+{
+ SKB_TRACE(skb);
+ SKB_TODO();
+ return (-ENXIO);
+}
+
+/* Not really seen this one but need it as symmetric accessor function. */
+static inline void
+skb_set_queue_mapping(struct sk_buff *skb, uint16_t qmap)
+{
+
+ SKB_TRACE_FMT(skb, "qmap %u", qmap);
+ skb->qmap = qmap;
+}
+
+static inline uint16_t
+skb_get_queue_mapping(struct sk_buff *skb)
+{
+
+ SKB_TRACE_FMT(skb, "qmap %u", skb->qmap);
+ return (skb->qmap);
+}
+
+static inline void
+skb_copy_header(struct sk_buff *to, const struct sk_buff *from)
+{
+ SKB_TRACE2(to, from);
+ SKB_TODO();
+}
+
+static inline bool
+skb_header_cloned(struct sk_buff *skb)
+{
+ SKB_TRACE(skb);
+ SKB_TODO();
+ return (true);
+}
+
+static inline uint8_t *
+skb_mac_header(const struct sk_buff *skb)
+{
+ SKB_TRACE(skb);
+ return (skb->head + skb->mac_header);
+}
+
+static inline void
+skb_reset_mac_header(struct sk_buff *skb)
+{
+ SKB_TRACE(skb);
+ skb->mac_header = skb->data - skb->head;
+}
+
+static inline void
+skb_set_mac_header(struct sk_buff *skb, const size_t len)
+{
+ SKB_TRACE(skb);
+ skb_reset_mac_header(skb);
+ skb->mac_header += len;
+}
+
+static inline struct skb_shared_hwtstamps *
+skb_hwtstamps(struct sk_buff *skb)
+{
+ SKB_TRACE(skb);
+ SKB_TODO();
+ return (NULL);
+}
+
+static inline void
+skb_orphan(struct sk_buff *skb)
+{
+ SKB_TRACE(skb);
+ SKB_TODO();
+}
+
+static inline __wsum
+csum_unfold(__sum16 sum)
+{
+ return (sum);
+}
+
+static __inline void
+skb_postpush_rcsum(struct sk_buff *skb, const void *data, size_t len)
+{
+ SKB_TODO();
+}
+
+static inline void
+skb_reset_tail_pointer(struct sk_buff *skb)
+{
+
+ SKB_TRACE(skb);
+#ifdef SKB_DOING_OFFSETS_US_NOT
+ skb->tail = (uint8_t *)(uintptr_t)(skb->data - skb->head);
+#endif
+ skb->tail = skb->data;
+ SKB_TRACE(skb);
+}
+
+static inline struct sk_buff *
+skb_get(struct sk_buff *skb)
+{
+
+ SKB_TRACE(skb);
+ refcount_inc(&skb->refcnt);
+ return (skb);
+}
+
+static inline struct sk_buff *
+skb_realloc_headroom(struct sk_buff *skb, unsigned int headroom)
+{
+
+ SKB_TODO();
+ return (NULL);
+}
+
+static inline void
+skb_copy_from_linear_data(const struct sk_buff *skb, void *dst, size_t len)
+{
+
+ SKB_TRACE(skb);
+ /* Let us just hope the destination has len space ... */
+ memcpy(dst, skb->data, len);
+}
+
+static inline int
+skb_pad(struct sk_buff *skb, int pad)
+{
+
+ SKB_TRACE(skb);
+ SKB_TODO();
+ return (-1);
+}
+
+static inline void
+skb_list_del_init(struct sk_buff *skb)
+{
+
+ SKB_TRACE(skb);
+ __list_del_entry(&skb->list);
+ skb_mark_not_on_list(skb);
+}
+
+static inline void
+napi_consume_skb(struct sk_buff *skb, int budget)
+{
+
+ SKB_TRACE(skb);
+ SKB_TODO();
+}
+
+static inline struct sk_buff *
+napi_build_skb(void *data, size_t len)
+{
+
+ SKB_TODO();
+ return (NULL);
+}
+
+static inline uint32_t
+skb_get_hash(struct sk_buff *skb)
+{
+ SKB_TRACE(skb);
+ SKB_TODO();
+ return (0);
+}
+
+static inline void
+skb_mark_for_recycle(struct sk_buff *skb)
+{
+ SKB_TRACE(skb);
+ /* page_pool */
+ SKB_TODO();
+}
+
+static inline int
+skb_cow_head(struct sk_buff *skb, unsigned int headroom)
+{
+ SKB_TRACE(skb);
+ SKB_TODO();
+ return (-1);
+}
+
+/* Misplaced here really but sock comes from skbuff. */
+#define sk_pacing_shift_update(sock, n)
+
+#define SKB_WITH_OVERHEAD(_s) \
+ (_s) - ALIGN(sizeof(struct skb_shared_info), CACHE_LINE_SIZE)
+
+#endif /* _LINUXKPI_LINUX_SKBUFF_H */
diff --git a/sys/compat/linuxkpi/common/include/linux/slab.h b/sys/compat/linuxkpi/common/include/linux/slab.h
index ecd39d711eb4..0e649e1e3c4a 100644
--- a/sys/compat/linuxkpi/common/include/linux/slab.h
+++ b/sys/compat/linuxkpi/common/include/linux/slab.h
@@ -4,6 +4,10 @@
* Copyright (c) 2010 Panasas, Inc.
* Copyright (c) 2013-2021 Mellanox Technologies, Ltd.
* All rights reserved.
+ * Copyright (c) 2024-2025 The FreeBSD Foundation
+ *
+ * Portions of this software were developed by Björn Zeeb
+ * under sponsorship from the FreeBSD Foundation.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
@@ -25,11 +29,9 @@
* 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.
- *
- * $FreeBSD$
*/
-#ifndef _LINUX_SLAB_H_
-#define _LINUX_SLAB_H_
+#ifndef _LINUXKPI_LINUX_SLAB_H_
+#define _LINUXKPI_LINUX_SLAB_H_
#include <sys/types.h>
#include <sys/malloc.h>
@@ -38,23 +40,25 @@
#include <linux/compat.h>
#include <linux/types.h>
#include <linux/gfp.h>
+#include <linux/err.h>
#include <linux/llist.h>
+#include <linux/overflow.h>
+#include <linux/cleanup.h>
MALLOC_DECLARE(M_KMALLOC);
-#define kvmalloc(size, flags) kmalloc(size, flags)
-#define kvzalloc(size, flags) kmalloc(size, (flags) | __GFP_ZERO)
+#define kvzalloc(size, flags) kvmalloc(size, (flags) | __GFP_ZERO)
#define kvcalloc(n, size, flags) kvmalloc_array(n, size, (flags) | __GFP_ZERO)
#define kzalloc(size, flags) kmalloc(size, (flags) | __GFP_ZERO)
#define kzalloc_node(size, flags, node) kmalloc_node(size, (flags) | __GFP_ZERO, node)
#define kfree_const(ptr) kfree(ptr)
+#define kfree_async(ptr) kfree(ptr) /* drm-kmod 5.4 compat */
#define vzalloc(size) __vmalloc(size, GFP_KERNEL | __GFP_NOWARN | __GFP_ZERO, 0)
#define vfree(arg) kfree(arg)
#define kvfree(arg) kfree(arg)
#define vmalloc_node(size, node) __vmalloc_node(size, GFP_KERNEL, node)
#define vmalloc_user(size) __vmalloc(size, GFP_KERNEL | __GFP_ZERO, 0)
#define vmalloc(size) __vmalloc(size, GFP_KERNEL, 0)
-#define __kmalloc(...) kmalloc(__VA_ARGS__)
/*
* Prefix some functions with linux_ to avoid namespace conflict
@@ -66,6 +70,7 @@ MALLOC_DECLARE(M_KMALLOC);
#define kmem_cache_zalloc(...) lkpi_kmem_cache_zalloc(__VA_ARGS__)
#define kmem_cache_free(...) lkpi_kmem_cache_free(__VA_ARGS__)
#define kmem_cache_destroy(...) linux_kmem_cache_destroy(__VA_ARGS__)
+#define kmem_cache_shrink(x) (0)
#define KMEM_CACHE(__struct, flags) \
linux_kmem_cache_create(#__struct, sizeof(struct __struct), \
@@ -85,18 +90,22 @@ struct linux_kmem_cache;
#define ARCH_KMALLOC_MINALIGN \
__alignof(unsigned long long)
-/*
- * Critical section-friendly version of kfree().
- * Requires knowledge of the allocation size at build time.
- */
-#define kfree_async(ptr) do { \
- _Static_assert(sizeof(*(ptr)) >= sizeof(struct llist_node), \
- "Size of object to free is unknown or too small"); \
- if (curthread->td_critnest != 0) \
- linux_kfree_async(ptr); \
- else \
- kfree(ptr); \
-} while (0)
+#define ZERO_SIZE_PTR ((void *)16)
+#define ZERO_OR_NULL_PTR(x) ((x) == NULL || (x) == ZERO_SIZE_PTR)
+
+struct linux_kmem_cache *linux_kmem_cache_create(const char *name,
+ size_t size, size_t align, unsigned flags, linux_kmem_ctor_t *ctor);
+void *lkpi_kmem_cache_alloc(struct linux_kmem_cache *, gfp_t);
+void *lkpi_kmem_cache_zalloc(struct linux_kmem_cache *, gfp_t);
+void lkpi_kmem_cache_free(struct linux_kmem_cache *, void *);
+void linux_kmem_cache_destroy(struct linux_kmem_cache *);
+
+void *lkpi_kmalloc(size_t, gfp_t);
+void *lkpi_kvmalloc(size_t, gfp_t);
+void *lkpi___kmalloc(size_t, gfp_t);
+void *lkpi___kmalloc_node(size_t, gfp_t, int);
+void *lkpi_krealloc(void *, size_t, gfp_t);
+void lkpi_kfree(const void *);
static inline gfp_t
linux_check_m_flags(gfp_t flags)
@@ -113,34 +122,91 @@ linux_check_m_flags(gfp_t flags)
return (flags & GFP_NATIVE_MASK);
}
+/*
+ * Base functions with a native implementation.
+ */
static inline void *
kmalloc(size_t size, gfp_t flags)
{
- return (malloc(size, M_KMALLOC, linux_check_m_flags(flags)));
+ return (lkpi_kmalloc(size, flags));
+}
+
+static inline void *
+__kmalloc(size_t size, gfp_t flags)
+{
+ return (lkpi___kmalloc(size, flags));
}
static inline void *
kmalloc_node(size_t size, gfp_t flags, int node)
{
- return (malloc_domainset(size, M_KMALLOC,
- linux_get_vm_domain_set(node), linux_check_m_flags(flags)));
+ return (lkpi___kmalloc_node(size, flags, node));
+}
+
+static inline void *
+krealloc(void *ptr, size_t size, gfp_t flags)
+{
+ return (lkpi_krealloc(ptr, size, flags));
+}
+
+static inline void
+kfree(const void *ptr)
+{
+ lkpi_kfree(ptr);
+}
+
+DEFINE_FREE(kfree, void *, if (!IS_ERR_OR_NULL(_T)) kfree(_T))
+
+/*
+ * Other k*alloc() funtions using the above as underlying allocator.
+ */
+/* kmalloc */
+static inline void *
+kmalloc_array(size_t n, size_t size, gfp_t flags)
+{
+ if (WOULD_OVERFLOW(n, size))
+ panic("%s: %zu * %zu overflowed", __func__, n, size);
+
+ return (kmalloc(size * n, flags));
}
static inline void *
kcalloc(size_t n, size_t size, gfp_t flags)
{
flags |= __GFP_ZERO;
- return (mallocarray(n, size, M_KMALLOC, linux_check_m_flags(flags)));
+ return (kmalloc_array(n, size, flags));
+}
+
+/* kmalloc_node */
+static inline void *
+kmalloc_array_node(size_t n, size_t size, gfp_t flags, int node)
+{
+ if (WOULD_OVERFLOW(n, size))
+ panic("%s: %zu * %zu overflowed", __func__, n, size);
+
+ return (kmalloc_node(size * n, flags, node));
}
static inline void *
kcalloc_node(size_t n, size_t size, gfp_t flags, int node)
{
flags |= __GFP_ZERO;
- return (mallocarray_domainset(n, size, M_KMALLOC,
- linux_get_vm_domain_set(node), linux_check_m_flags(flags)));
+ return (kmalloc_array_node(n, size, flags, node));
+}
+
+/* krealloc */
+static inline void *
+krealloc_array(void *ptr, size_t n, size_t size, gfp_t flags)
+{
+ if (WOULD_OVERFLOW(n, size))
+ return NULL;
+
+ return (krealloc(ptr, n * size, flags));
}
+/*
+ * vmalloc/kvalloc functions.
+ */
static inline void *
__vmalloc(size_t size, gfp_t flags, int other)
{
@@ -160,40 +226,49 @@ vmalloc_32(size_t size)
return (contigmalloc(size, M_KMALLOC, M_WAITOK, 0, UINT_MAX, 1, 1));
}
+/* May return non-contiguous memory. */
static inline void *
-kmalloc_array(size_t n, size_t size, gfp_t flags)
-{
- return (mallocarray(n, size, M_KMALLOC, linux_check_m_flags(flags)));
-}
-
-static inline void *
-kmalloc_array_node(size_t n, size_t size, gfp_t flags, int node)
+kvmalloc(size_t size, gfp_t flags)
{
- return (mallocarray_domainset(n, size, M_KMALLOC,
- linux_get_vm_domain_set(node), linux_check_m_flags(flags)));
+ return (lkpi_kvmalloc(size, flags));
}
static inline void *
kvmalloc_array(size_t n, size_t size, gfp_t flags)
{
- return (mallocarray(n, size, M_KMALLOC, linux_check_m_flags(flags)));
+ if (WOULD_OVERFLOW(n, size))
+ panic("%s: %zu * %zu overflowed", __func__, n, size);
+
+ return (kvmalloc(size * n, flags));
}
static inline void *
-krealloc(void *ptr, size_t size, gfp_t flags)
+kvrealloc(const void *ptr, size_t oldsize, size_t newsize, gfp_t flags)
{
- return (realloc(ptr, size, M_KMALLOC, linux_check_m_flags(flags)));
-}
+ void *newptr;
-static inline void
-kfree(const void *ptr)
-{
- free(__DECONST(void *, ptr), M_KMALLOC);
+ if (newsize <= oldsize)
+ return (__DECONST(void *, ptr));
+
+ newptr = kvmalloc(newsize, flags);
+ if (newptr != NULL) {
+ memcpy(newptr, ptr, oldsize);
+ kvfree(ptr);
+ }
+
+ return (newptr);
}
+/*
+ * Misc.
+ */
+
static __inline void
kfree_sensitive(const void *ptr)
{
+ if (ZERO_OR_NULL_PTR(ptr))
+ return;
+
zfree(__DECONST(void *, ptr), M_KMALLOC);
}
@@ -203,12 +278,12 @@ ksize(const void *ptr)
return (malloc_usable_size(ptr));
}
-extern struct linux_kmem_cache *linux_kmem_cache_create(const char *name,
- size_t size, size_t align, unsigned flags, linux_kmem_ctor_t *ctor);
-extern void *lkpi_kmem_cache_alloc(struct linux_kmem_cache *, gfp_t);
-extern void *lkpi_kmem_cache_zalloc(struct linux_kmem_cache *, gfp_t);
-extern void lkpi_kmem_cache_free(struct linux_kmem_cache *, void *);
-extern void linux_kmem_cache_destroy(struct linux_kmem_cache *);
-void linux_kfree_async(void *);
+static inline size_t
+kmalloc_size_roundup(size_t size)
+{
+ if (unlikely(size == 0 || size == SIZE_MAX))
+ return (size);
+ return (malloc_size(size));
+}
-#endif /* _LINUX_SLAB_H_ */
+#endif /* _LINUXKPI_LINUX_SLAB_H_ */
diff --git a/sys/compat/linuxkpi/common/include/linux/smp.h b/sys/compat/linuxkpi/common/include/linux/smp.h
index 3f5684015547..b057953e6282 100644
--- a/sys/compat/linuxkpi/common/include/linux/smp.h
+++ b/sys/compat/linuxkpi/common/include/linux/smp.h
@@ -22,13 +22,25 @@
* 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.
- *
- * $FreeBSD$
*/
-#ifndef _LINUX_SMP_H_
-#define _LINUX_SMP_H_
+#ifndef _LINUXKPI_LINUX_SMP_H_
+#define _LINUXKPI_LINUX_SMP_H_
+
+#include <asm/smp.h>
+/*
+ * Important note about the use of the function provided below:
+ *
+ * The callback function passed to on_each_cpu() is called from a
+ * so-called critical section, and if you need a mutex you will have
+ * to rewrite the code to use native FreeBSD mtx spinlocks instead of
+ * the spinlocks provided by the LinuxKPI! Be very careful to not call
+ * any LinuxKPI functions inside the on_each_cpu()'s callback
+ * function, because they may sleep, unlike in native Linux.
+ *
+ * Enabling witness(4) when testing, can catch such issues.
+ */
#define on_each_cpu(cb, data, wait) ({ \
CTASSERT(wait); \
linux_on_each_cpu(cb, data); \
@@ -36,4 +48,4 @@
extern int linux_on_each_cpu(void (*)(void *), void *);
-#endif /* _LINUX_SMP_H_ */
+#endif /* _LINUXKPI_LINUX_SMP_H_ */
diff --git a/sys/compat/linuxkpi/common/include/linux/soc/mediatek/mtk_wed.h b/sys/compat/linuxkpi/common/include/linux/soc/mediatek/mtk_wed.h
new file mode 100644
index 000000000000..9f3a1ee4c139
--- /dev/null
+++ b/sys/compat/linuxkpi/common/include/linux/soc/mediatek/mtk_wed.h
@@ -0,0 +1,45 @@
+/*-
+ * Copyright (c) 2022-2025 Bjoern A. Zeeb
+ *
+ * SPDX-License-Identifier: BSD-2-Clause
+ */
+
+#ifndef _LINUXKPI_LINUX_SOC_MEDIATEK_MTK_WED_H
+#define _LINUXKPI_LINUX_SOC_MEDIATEK_MTK_WED_H
+
+#include <linux/kernel.h> /* pr_debug */
+
+struct mtk_wed_device {
+};
+
+#define WED_WO_STA_REC 0x6
+
+#define mtk_wed_device_start(_dev, _mask) do { pr_debug("%s: TODO\n", __func__); } while(0)
+#define mtk_wed_device_detach(_dev) do { pr_debug("%s: TODO\n", __func__); } while(0)
+#define mtk_wed_device_irq_get(_dev, _mask) 0
+#define mtk_wed_device_irq_set_mask(_dev, _mask) do { pr_debug("%s: TODO\n", __func__); } while(0)
+#define mtk_wed_device_update_msg(_dev, _id, _msg, _len) ({ pr_debug("%s: TODO\n", __func__); -ENODEV; })
+#define mtk_wed_device_dma_reset(_dev) do { pr_debug("%s: TODO\n", __func__); } while (0)
+#define mtk_wed_device_ppe_check(_dev, _skb, _reason, _entry) \
+ do { pr_debug("%s: TODO\n", __func__); } while (0)
+#define mtk_wed_device_stop(_dev) do { pr_debug("%s: TODO\n", __func__); } while(0)
+#define mtk_wed_device_start_hw_rro(_dev, _mask, _b) do { pr_debug("%s: TODO\n", __func__); } while(0)
+#define mtk_wed_device_setup_tc(_dev, _ndev, _type, _tdata) ({ pr_debug("%s: TODO\n", __func__); -EOPNOTSUPP; })
+
+static inline bool
+mtk_wed_device_active(struct mtk_wed_device *dev __unused)
+{
+
+ pr_debug("%s: TODO\n", __func__);
+ return (false);
+}
+
+static inline bool
+mtk_wed_get_rx_capa(struct mtk_wed_device *dev __unused)
+{
+
+ pr_debug("%s: TODO\n", __func__);
+ return (false);
+}
+
+#endif /* _LINUXKPI_LINUX_SOC_MEDIATEK_MTK_WED_H */
diff --git a/sys/compat/linuxkpi/common/include/linux/soc/qcom/qmi.h b/sys/compat/linuxkpi/common/include/linux/soc/qcom/qmi.h
new file mode 100644
index 000000000000..647eaf271d87
--- /dev/null
+++ b/sys/compat/linuxkpi/common/include/linux/soc/qcom/qmi.h
@@ -0,0 +1,173 @@
+/*-
+ * SPDX-License-Identifier: BSD-2-Clause
+ *
+ * Copyright (c) 2022-2023 Bjoern A. Zeeb
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``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 OR CONTRIBUTORS 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.
+ */
+
+#ifndef _LINUXKPI_LINUX_SOC_QCOM_QMI_H
+#define _LINUXKPI_LINUX_SOC_QCOM_QMI_H
+
+/* QMI (Qualcomm MSM Interface) */
+
+#include <linux/qrtr.h>
+
+enum soc_qcom_qmi_data_type {
+ QMI_EOTI,
+ QMI_DATA_LEN,
+ QMI_OPT_FLAG,
+ QMI_UNSIGNED_1_BYTE,
+ QMI_UNSIGNED_2_BYTE,
+ QMI_UNSIGNED_4_BYTE,
+ QMI_UNSIGNED_8_BYTE,
+ QMI_SIGNED_4_BYTE_ENUM,
+ QMI_STRUCT,
+ QMI_STRING,
+};
+
+#define QMI_RESULT_SUCCESS_V01 __LINE__
+#define QMI_INDICATION __LINE__
+
+struct qmi_handle;
+
+enum soc_qcom_qmi_array_type {
+ NO_ARRAY,
+ STATIC_ARRAY,
+ VAR_LEN_ARRAY,
+};
+
+/* Should this become an enum? */
+#define QMI_COMMON_TLV_TYPE 0
+
+struct qmi_elem_info {
+ enum soc_qcom_qmi_data_type data_type;
+ uint32_t elem_len;
+ uint32_t elem_size;
+ enum soc_qcom_qmi_array_type array_type;
+ uint8_t tlv_type;
+ uint32_t offset;
+ const struct qmi_elem_info *ei_array;
+};
+
+struct qmi_response_type_v01 {
+ uint16_t result;
+ uint16_t error;
+};
+
+struct qmi_txn {
+};
+
+struct qmi_service {
+ uint32_t node;
+ uint32_t port;
+};
+
+struct qmi_msg_handler {
+ uint32_t type;
+ uint32_t msg_id;
+ const struct qmi_elem_info *ei;
+ size_t decoded_size;
+ void (*fn)(struct qmi_handle *, struct sockaddr_qrtr *, struct qmi_txn *, const void *);
+};
+
+struct qmi_ops {
+ int (*new_server)(struct qmi_handle *, struct qmi_service *);
+ void (*del_server)(struct qmi_handle *, struct qmi_service *);
+};
+
+struct qmi_handle {
+ int sock;
+
+ const struct qmi_msg_handler *handler;
+ struct qmi_ops ops;
+};
+
+
+/* XXX-TODO need implementation somewhere... it is not in ath1xk* */
+extern struct qmi_elem_info qmi_response_type_v01_ei[];
+
+static inline int
+qmi_handle_init(struct qmi_handle *handle, size_t resp_len_max,
+ const struct qmi_ops *ops, const struct qmi_msg_handler *handler)
+{
+
+ handle->handler = handler;
+ if (ops != NULL)
+ handle->ops = *ops;
+
+ /* We will find out what else to do here. */
+ /* XXX TODO */
+
+ return (0);
+}
+
+static __inline int
+qmi_add_lookup(struct qmi_handle *handle, uint32_t service, uint32_t version,
+ uint32_t service_ins_id)
+{
+
+ /* XXX TODO */
+ return (0);
+}
+
+static __inline void
+qmi_handle_release(struct qmi_handle *handle)
+{
+
+ /* XXX TODO */
+}
+
+static __inline int
+qmi_send_request(struct qmi_handle *handle, void *x, struct qmi_txn *txn,
+ uint32_t msd_id, size_t len, const struct qmi_elem_info *ei, void *req)
+{
+
+ /* XXX TODO */
+ return (-ENXIO);
+}
+
+static __inline void
+qmi_txn_cancel(struct qmi_txn *txn)
+{
+
+ /* XXX TODO */
+}
+
+static __inline int
+qmi_txn_init(struct qmi_handle *handle, struct qmi_txn *txn,
+ const struct qmi_elem_info *ei, void *resp)
+{
+
+ /* XXX TODO */
+ return (-ENXIO);
+}
+
+static __inline int
+qmi_txn_wait(struct qmi_txn *txn, uint64_t jiffies)
+{
+
+ /* XXX TODO */
+ return (-ENXIO);
+}
+
+#endif /* _LINUXKPI_LINUX_SOC_QCOM_QMI_H */
diff --git a/sys/compat/linuxkpi/common/include/linux/socket.h b/sys/compat/linuxkpi/common/include/linux/socket.h
index a9a952e4ffd8..638ee058c2f5 100644
--- a/sys/compat/linuxkpi/common/include/linux/socket.h
+++ b/sys/compat/linuxkpi/common/include/linux/socket.h
@@ -25,14 +25,23 @@
* 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.
- *
- * $FreeBSD$
*/
-#ifndef _LINUX_SOCKET_H_
-#define _LINUX_SOCKET_H_
+#ifndef _LINUXKPI_LINUX_SOCKET_H_
+#define _LINUXKPI_LINUX_SOCKET_H_
#include <sys/socket.h>
+#define AF_QIPCRTR 42
+
+static inline int
+kernel_connect(int sd, struct sockaddr *sa, size_t salen, int flags)
+{
+
+ /* kern_connectat()? It is used for sockaddr_qrtr by ath1xk/qmi. */
+ pr_debug("%s: TODO\n", __func__);
+ return (-EINVAL);
+}
+
#ifdef notyet
static inline int
memcpy_toiovec(struct iovec *v, unsigned char *kdata, int len)
@@ -66,4 +75,4 @@ memcpy_fromiovec(unsigned char *kdata, struct iovec *iov, int len)
}
#endif
-#endif /* _LINUX_SOCKET_H_ */
+#endif /* _LINUXKPI_LINUX_SOCKET_H_ */
diff --git a/sys/compat/linuxkpi/common/include/linux/sort.h b/sys/compat/linuxkpi/common/include/linux/sort.h
new file mode 100644
index 000000000000..e6196d1f41c7
--- /dev/null
+++ b/sys/compat/linuxkpi/common/include/linux/sort.h
@@ -0,0 +1,41 @@
+/*-
+ * SPDX-License-Identifier: BSD-2-Clause
+ *
+ * Copyright (c) 2021 Vladimir Kondratyev <wulf@FreeBSD.org>
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice unmodified, this list of conditions, and the following
+ * disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``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.
+ */
+
+#ifndef _LINUXKPI_LINUX_SORT_H_
+#define _LINUXKPI_LINUX_SORT_H_
+
+#include <linux/types.h>
+#include <linux/kernel.h>
+
+#include <sys/libkern.h>
+
+#define sort(base, num, size, cmp, swap) do { \
+ BUILD_BUG_ON_ZERO(swap); \
+ qsort(base, num, size, cmp); \
+} while (0)
+
+#endif /* _LINUXKPI_LINUX_SORT_H_ */
diff --git a/sys/compat/linuxkpi/common/include/linux/spinlock.h b/sys/compat/linuxkpi/common/include/linux/spinlock.h
index 56eaecfb4cd6..dc10b0457153 100644
--- a/sys/compat/linuxkpi/common/include/linux/spinlock.h
+++ b/sys/compat/linuxkpi/common/include/linux/spinlock.h
@@ -25,11 +25,9 @@
* 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.
- *
- * $FreeBSD$
*/
-#ifndef _LINUX_SPINLOCK_H_
-#define _LINUX_SPINLOCK_H_
+#ifndef _LINUXKPI_LINUX_SPINLOCK_H_
+#define _LINUXKPI_LINUX_SPINLOCK_H_
#include <asm/atomic.h>
#include <sys/param.h>
@@ -41,10 +39,9 @@
#include <linux/compiler.h>
#include <linux/rwlock.h>
#include <linux/bottom_half.h>
+#include <linux/lockdep.h>
-typedef struct {
- struct mtx m;
-} spinlock_t;
+typedef struct mtx spinlock_t;
/*
* By defining CONFIG_SPIN_SKIP LinuxKPI spinlocks and asserts will be
@@ -60,7 +57,7 @@ typedef struct {
#define spin_lock(_l) do { \
if (SPIN_SKIP()) \
break; \
- mtx_lock(&(_l)->m); \
+ mtx_lock(_l); \
local_bh_disable(); \
} while (0)
@@ -77,7 +74,7 @@ typedef struct {
if (SPIN_SKIP()) \
break; \
local_bh_enable(); \
- mtx_unlock(&(_l)->m); \
+ mtx_unlock(_l); \
} while (0)
#define spin_unlock_bh(_l) do { \
@@ -94,7 +91,7 @@ typedef struct {
if (SPIN_SKIP()) { \
__ret = 1; \
} else { \
- __ret = mtx_trylock(&(_l)->m); \
+ __ret = mtx_trylock(_l); \
if (likely(__ret != 0)) \
local_bh_disable(); \
} \
@@ -112,7 +109,7 @@ typedef struct {
#define spin_lock_nested(_l, _n) do { \
if (SPIN_SKIP()) \
break; \
- mtx_lock_flags(&(_l)->m, MTX_DUPOK); \
+ mtx_lock_flags(_l, MTX_DUPOK); \
local_bh_disable(); \
} while (0)
@@ -127,6 +124,7 @@ typedef struct {
} while (0)
#define spin_unlock_irqrestore(_l, flags) do { \
+ (void)(flags); \
spin_unlock(_l); \
} while (0)
@@ -141,31 +139,27 @@ typedef struct {
#define _spin_lock_name(...) __spin_lock_name(__VA_ARGS__)
#define spin_lock_name(name) _spin_lock_name(name, __FILE__, __LINE__)
-#define spin_lock_init(lock) linux_spin_lock_init(lock, spin_lock_name("lnxspin"))
-
-static inline void
-linux_spin_lock_init(spinlock_t *lock, const char *name)
-{
+#define spin_lock_init(lock) mtx_init(lock, spin_lock_name("lnxspin"), \
+ NULL, MTX_DEF | MTX_NOWITNESS | MTX_NEW)
- memset(lock, 0, sizeof(*lock));
- mtx_init(&lock->m, name, NULL, MTX_DEF | MTX_NOWITNESS);
-}
-
-static inline void
-spin_lock_destroy(spinlock_t *lock)
-{
-
- mtx_destroy(&lock->m);
-}
+#define spin_lock_destroy(_l) mtx_destroy(_l)
#define DEFINE_SPINLOCK(lock) \
spinlock_t lock; \
- MTX_SYSINIT(lock, &(lock).m, spin_lock_name("lnxspin"), MTX_DEF)
+ MTX_SYSINIT(lock, &lock, spin_lock_name("lnxspin"), MTX_DEF)
#define assert_spin_locked(_l) do { \
if (SPIN_SKIP()) \
break; \
- mtx_assert(&(_l)->m, MA_OWNED); \
+ mtx_assert(_l, MA_OWNED); \
+} while (0)
+
+#define local_irq_save(flags) do { \
+ (flags) = 0; \
+} while (0)
+
+#define local_irq_restore(flags) do { \
+ (void)(flags); \
} while (0)
#define atomic_dec_and_lock_irqsave(cnt, lock, flags) \
@@ -184,4 +178,4 @@ _atomic_dec_and_lock_irqsave(atomic_t *cnt, spinlock_t *lock,
return (0);
}
-#endif /* _LINUX_SPINLOCK_H_ */
+#endif /* _LINUXKPI_LINUX_SPINLOCK_H_ */
diff --git a/sys/compat/linuxkpi/common/include/linux/srcu.h b/sys/compat/linuxkpi/common/include/linux/srcu.h
index 1de7e8acedb8..b42c28a1311b 100644
--- a/sys/compat/linuxkpi/common/include/linux/srcu.h
+++ b/sys/compat/linuxkpi/common/include/linux/srcu.h
@@ -22,12 +22,10 @@
* 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.
- *
- * $FreeBSD$
*/
-#ifndef _LINUX_SRCU_H_
-#define _LINUX_SRCU_H_
+#ifndef _LINUXKPI_LINUX_SRCU_H_
+#define _LINUXKPI_LINUX_SRCU_H_
#include <linux/compiler.h>
@@ -53,4 +51,4 @@ extern void cleanup_srcu_struct(struct srcu_struct *);
synchronize_srcu(srcu); \
} while (0)
-#endif /* _LINUX_SRCU_H_ */
+#endif /* _LINUXKPI_LINUX_SRCU_H_ */
diff --git a/sys/compat/linuxkpi/common/include/linux/stackdepot.h b/sys/compat/linuxkpi/common/include/linux/stackdepot.h
new file mode 100644
index 000000000000..df223d46be6e
--- /dev/null
+++ b/sys/compat/linuxkpi/common/include/linux/stackdepot.h
@@ -0,0 +1,32 @@
+/*-
+ * Copyright (c) 2022 Beckhoff Automation GmbH & Co. KG
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``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 OR CONTRIBUTORS 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.
+ *
+ */
+
+#ifndef _LINUXKPI_LINUX_STACKDEPOT_H_
+#define _LINUXKPI_LINUX_STACKDEPOT_H_
+
+typedef bool depot_stack_handle_t;
+
+#endif /* _LINUXKPI_LINUX_STACKDEPOT_H_ */
diff --git a/sys/compat/linuxkpi/common/include/linux/stdarg.h b/sys/compat/linuxkpi/common/include/linux/stdarg.h
new file mode 100644
index 000000000000..698ac45e9198
--- /dev/null
+++ b/sys/compat/linuxkpi/common/include/linux/stdarg.h
@@ -0,0 +1,33 @@
+/*-
+ * SPDX-License-Identifier: BSD-2-Clause
+ *
+ * Copyright (c) 2021 Vladimir Kondratyev <wulf@FreeBSD.org>
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice unmodified, this list of conditions, and the following
+ * disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``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.
+ */
+
+#ifndef _LINUXKPI_STDARG_H_
+#define _LINUXKPI_STDARG_H_
+
+#include <sys/stdarg.h>
+
+#endif /* _LINUXKPI_STDARG_H_ */
diff --git a/sys/compat/linuxkpi/common/include/linux/stddef.h b/sys/compat/linuxkpi/common/include/linux/stddef.h
new file mode 100644
index 000000000000..d04a5a4bf516
--- /dev/null
+++ b/sys/compat/linuxkpi/common/include/linux/stddef.h
@@ -0,0 +1,31 @@
+/* Public domain */
+
+#ifndef _LINUXKPI_LINUX_STDDEF_H_
+#define _LINUXKPI_LINUX_STDDEF_H_
+
+#include <sys/stddef.h>
+
+/*
+ * FreeBSD has multiple (vendor) drivers containing copies of this
+ * and including LinuxKPI headers. Put the #defines behind guards.
+ */
+
+#ifndef __struct_group
+#define __struct_group(_tag, _name, _attrs, _members...) \
+ union { \
+ struct { _members } _attrs; \
+ struct _tag { _members } _attrs _name; \
+ } _attrs
+#endif
+
+#ifndef struct_group
+#define struct_group(_name, _members...) \
+ __struct_group(/* no tag */, _name, /* no attrs */, _members)
+#endif
+
+#ifndef struct_group_tagged
+#define struct_group_tagged(_tag, _name, _members...) \
+ __struct_group(_tag, _name, /* no attrs */, _members)
+#endif
+
+#endif /* _LINUXKPI_LINUX_STDDEF_H_ */
diff --git a/sys/compat/linuxkpi/common/include/linux/string.h b/sys/compat/linuxkpi/common/include/linux/string.h
index a757464bf02b..f7b64560d254 100644
--- a/sys/compat/linuxkpi/common/include/linux/string.h
+++ b/sys/compat/linuxkpi/common/include/linux/string.h
@@ -25,11 +25,9 @@
* 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.
- *
- * $FreeBSD$
*/
-#ifndef _LINUX_STRING_H_
-#define _LINUX_STRING_H_
+#ifndef _LINUXKPI_LINUX_STRING_H_
+#define _LINUXKPI_LINUX_STRING_H_
#include <sys/ctype.h>
@@ -38,6 +36,9 @@
#include <linux/slab.h>
#include <linux/uaccess.h>
#include <linux/err.h>
+#include <linux/bitops.h> /* for BITS_PER_LONG */
+#include <linux/overflow.h>
+#include <linux/stdarg.h>
#include <sys/libkern.h>
@@ -97,6 +98,27 @@ kmemdup(const void *src, size_t len, gfp_t gfp)
return (dst);
}
+/* See slab.h for kvmalloc/kvfree(). */
+static inline void *
+kvmemdup(const void *src, size_t len, gfp_t gfp)
+{
+ void *dst;
+
+ dst = kvmalloc(len, gfp);
+ if (dst != NULL)
+ memcpy(dst, src, len);
+ return (dst);
+}
+
+static inline char *
+strndup_user(const char __user *ustr, long n)
+{
+ if (n < 1)
+ return (ERR_PTR(-EINVAL));
+
+ return (memdup_user_nul(ustr, n - 1));
+}
+
static inline char *
kstrdup(const char *string, gfp_t gfp)
{
@@ -139,6 +161,24 @@ skip_spaces(const char *str)
return (__DECONST(char *, str));
}
+/*
+ * This function trims whitespaces at the end of a string and returns a pointer
+ * to the first non-whitespace character.
+ */
+static inline char *
+strim(char *str)
+{
+ char *end;
+
+ end = str + strlen(str);
+ while (end >= str && (*end == '\0' || isspace(*end))) {
+ *end = '\0';
+ end--;
+ }
+
+ return (skip_spaces(str));
+}
+
static inline void *
memchr_inv(const void *start, int c, size_t length)
{
@@ -196,4 +236,94 @@ strscpy(char* dst, const char* src, size_t len)
return (-E2BIG);
}
-#endif /* _LINUX_STRING_H_ */
+static inline ssize_t
+strscpy_pad(char* dst, const char* src, size_t len)
+{
+
+ bzero(dst, len);
+
+ return (strscpy(dst, src, len));
+}
+
+static inline char *
+strnchr(const char *cp, size_t n, int ch)
+{
+ char *p;
+
+ for (p = __DECONST(char *, cp); n--; ++p) {
+ if (*p == ch)
+ return (p);
+ if (*p == '\0')
+ break;
+ }
+
+ return (NULL);
+}
+
+static inline void *
+memset32(uint32_t *b, uint32_t c, size_t len)
+{
+ uint32_t *dst = b;
+
+ while (len--)
+ *dst++ = c;
+ return (b);
+}
+
+static inline void *
+memset64(uint64_t *b, uint64_t c, size_t len)
+{
+ uint64_t *dst = b;
+
+ while (len--)
+ *dst++ = c;
+ return (b);
+}
+
+static inline void *
+memset_p(void **p, void *v, size_t n)
+{
+
+ if (BITS_PER_LONG == 32)
+ return (memset32((uint32_t *)p, (uintptr_t)v, n));
+ else
+ return (memset64((uint64_t *)p, (uintptr_t)v, n));
+}
+
+static inline void
+memcpy_and_pad(void *dst, size_t dstlen, const void *src, size_t len, int ch)
+{
+
+ if (len >= dstlen) {
+ memcpy(dst, src, dstlen);
+ } else {
+ memcpy(dst, src, len);
+ /* Pad with given padding character. */
+ memset((char *)dst + len, ch, dstlen - len);
+ }
+}
+
+#define memset_startat(ptr, bytepat, smember) \
+({ \
+ uint8_t *_ptr = (uint8_t *)(ptr); \
+ int _c = (int)(bytepat); \
+ size_t _o = offsetof(typeof(*(ptr)), smember); \
+ memset(_ptr + _o, _c, sizeof(*(ptr)) - _o); \
+})
+
+#define memset_after(ptr, bytepat, smember) \
+({ \
+ uint8_t *_ptr = (uint8_t *)(ptr); \
+ int _c = (int)(bytepat); \
+ size_t _o = offsetofend(typeof(*(ptr)), smember); \
+ memset(_ptr + _o, _c, sizeof(*(ptr)) - _o); \
+})
+
+static inline void
+memzero_explicit(void *p, size_t s)
+{
+ memset(p, 0, s);
+ __asm__ __volatile__("": :"r"(p) :"memory");
+}
+
+#endif /* _LINUXKPI_LINUX_STRING_H_ */
diff --git a/sys/compat/linuxkpi/common/include/linux/string_choices.h b/sys/compat/linuxkpi/common/include/linux/string_choices.h
new file mode 100644
index 000000000000..74aa3fd019b2
--- /dev/null
+++ b/sys/compat/linuxkpi/common/include/linux/string_choices.h
@@ -0,0 +1,71 @@
+/*-
+ * SPDX-License-Identifier: BSD-2-Clause
+ *
+ * Copyright (c) 2023 Jean-Sébastien Pédron <dumbbell@FreeBSD.org>
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice unmodified, this list of conditions, and the following
+ * disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``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.
+ */
+
+#ifndef _LINUXKPI_LINUX_STRING_CHOICES_H_
+#define _LINUXKPI_LINUX_STRING_CHOICES_H_
+
+#include <sys/types.h>
+
+static inline const char *
+str_yes_no(bool value)
+{
+ if (value)
+ return "yes";
+ else
+ return "no";
+}
+
+static inline const char *
+str_on_off(bool value)
+{
+ if (value)
+ return "on";
+ else
+ return "off";
+}
+
+static inline const char *
+str_enabled_disabled(bool value)
+{
+ if (value)
+ return "enabled";
+ else
+ return "disabled";
+}
+
+static inline const char *
+str_enable_disable(bool value)
+{
+ if (value)
+ return "enable";
+ else
+ return "disable";
+}
+
+#define str_disable_enable(_v) str_enable_disable(!(_v))
+
+#endif
diff --git a/sys/compat/linuxkpi/common/include/linux/string_helpers.h b/sys/compat/linuxkpi/common/include/linux/string_helpers.h
new file mode 100644
index 000000000000..07d113c0cb21
--- /dev/null
+++ b/sys/compat/linuxkpi/common/include/linux/string_helpers.h
@@ -0,0 +1,12 @@
+/*
+ * Copyright (c) 2025 The FreeBSD Foundation
+ *
+ * SPDX-License-Identifier: BSD-2-Clause
+ */
+
+#ifndef _LINUXKPI_LINUX_STRING_HELPERS_H_
+#define _LINUXKPI_LINUX_STRING_HELPERS_H_
+
+#include <linux/string_choices.h>
+
+#endif
diff --git a/sys/compat/linuxkpi/common/include/linux/stringify.h b/sys/compat/linuxkpi/common/include/linux/stringify.h
index 08fd0d909fae..9345bdc441aa 100644
--- a/sys/compat/linuxkpi/common/include/linux/stringify.h
+++ b/sys/compat/linuxkpi/common/include/linux/stringify.h
@@ -22,16 +22,14 @@
* 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.
- *
- * $FreeBSD$
*/
-#ifndef __LKPI_LINUX_STRINGIFY_H_
-#define __LKPI_LINUX_STRINGIFY_H_
+#ifndef _LINUXKPI_LINUX_STRINGIFY_H_
+#define _LINUXKPI_LINUX_STRINGIFY_H_
#include <sys/cdefs.h>
#define ___stringify(...) #__VA_ARGS__
#define __stringify(...) ___stringify(__VA_ARGS__)
-#endif /* __LKPI_LINUX_STRINGIFY_H_ */
+#endif /* _LINUXKPI_LINUX_STRINGIFY_H_ */
diff --git a/sys/compat/linuxkpi/common/include/linux/suspend.h b/sys/compat/linuxkpi/common/include/linux/suspend.h
new file mode 100644
index 000000000000..dacecbebdc08
--- /dev/null
+++ b/sys/compat/linuxkpi/common/include/linux/suspend.h
@@ -0,0 +1,23 @@
+/* Public domain. */
+
+#ifndef _LINUXKPI_LINUX_SUSPEND_H_
+#define _LINUXKPI_LINUX_SUSPEND_H_
+
+typedef int suspend_state_t;
+
+extern suspend_state_t pm_suspend_target_state;
+
+#define PM_SUSPEND_ON 0
+#define PM_SUSPEND_TO_IDLE 1
+#define PM_SUSPEND_STANDBY 2
+#define PM_SUSPEND_MEM 3
+#define PM_SUSPEND_MIN PM_SUSPEND_TO_IDLE
+#define PM_SUSPEND_MAX 4
+
+static inline int
+pm_suspend_via_firmware(void)
+{
+ return 0;
+}
+
+#endif /* _LINUXKPI_LINUX_SUSPEND_H_ */
diff --git a/sys/compat/linuxkpi/common/include/linux/swap.h b/sys/compat/linuxkpi/common/include/linux/swap.h
index 33f8de4721a4..5828db7ae392 100644
--- a/sys/compat/linuxkpi/common/include/linux/swap.h
+++ b/sys/compat/linuxkpi/common/include/linux/swap.h
@@ -22,16 +22,24 @@
* 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.
- *
- * $FreeBSD$
*/
-#ifndef _LINUX_SWAP_H_
-#define _LINUX_SWAP_H_
+#ifndef _LINUXKPI_LINUX_SWAP_H_
+#define _LINUXKPI_LINUX_SWAP_H_
+
+#include <sys/param.h>
+#include <sys/domainset.h>
+#include <sys/queue.h>
+#include <sys/proc.h>
+#include <sys/pcpu.h>
+#include <vm/vm.h>
#include <vm/swap_pager.h>
#include <vm/vm_pageout.h>
+#include <linux/pagemap.h>
+#include <linux/page-flags.h>
+
static inline long
get_nr_swap_pages(void)
{
@@ -49,4 +57,15 @@ current_is_kswapd(void)
return (curproc == pageproc);
}
+static inline void
+folio_mark_accessed(struct folio *folio)
+{
+ mark_page_accessed(&folio->page);
+}
+
+static inline void
+check_move_unevictable_folios(struct folio_batch *fbatch)
+{
+}
+
#endif
diff --git a/sys/compat/linuxkpi/common/include/linux/sysfs.h b/sys/compat/linuxkpi/common/include/linux/sysfs.h
index f84790f1b910..470c224a9778 100644
--- a/sys/compat/linuxkpi/common/include/linux/sysfs.h
+++ b/sys/compat/linuxkpi/common/include/linux/sysfs.h
@@ -25,11 +25,9 @@
* 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.
- *
- * $FreeBSD$
*/
-#ifndef _LINUX_SYSFS_H_
-#define _LINUX_SYSFS_H_
+#ifndef _LINUXKPI_LINUX_SYSFS_H_
+#define _LINUXKPI_LINUX_SYSFS_H_
#include <sys/types.h>
#include <sys/sysctl.h>
@@ -37,6 +35,7 @@
#include <linux/kobject.h>
#include <linux/stringify.h>
+#include <linux/mm.h>
struct sysfs_ops {
ssize_t (*show)(struct kobject *, struct attribute *, char *);
@@ -51,11 +50,23 @@ struct attribute_group {
struct attribute **attrs;
};
+struct bin_attribute {
+ struct attribute attr;
+ size_t size;
+ ssize_t (*read)(struct linux_file *, struct kobject *,
+ struct bin_attribute *, char *, loff_t, size_t);
+ ssize_t (*write)(struct linux_file *, struct kobject *,
+ struct bin_attribute *, char *, loff_t, size_t);
+};
+
#define __ATTR(_name, _mode, _show, _store) { \
.attr = { .name = __stringify(_name), .mode = _mode }, \
.show = _show, .store = _store, \
}
-#define __ATTR_RO(_name) __ATTR(_name, 0444, _name##_show, NULL)
+#define __ATTR_RO(_name) { \
+ .attr = { .name = __stringify(_name), .mode = 0444 }, \
+ .show = _name##_show, \
+}
#define __ATTR_WO(_name) __ATTR(_name, 0200, NULL, _name##_store)
#define __ATTR_RW(_name) __ATTR(_name, 0644, _name##_show, _name##_store)
#define __ATTR_NULL { .attr = { .name = NULL } }
@@ -70,6 +81,39 @@ struct attribute_group {
NULL, \
}
+#define __BIN_ATTR(_name, _mode, _read, _write, _size) { \
+ .attr = { .name = __stringify(_name), .mode = _mode }, \
+ .read = _read, .write = _write, .size = _size, \
+}
+#define __BIN_ATTR_RO(_name, _size) { \
+ .attr = { .name = __stringify(_name), .mode = 0444 }, \
+ .read = _name##_read, .size = _size, \
+}
+#define __BIN_ATTR_WO(_name, _size) { \
+ .attr = { .name = __stringify(_name), .mode = 0200 }, \
+ .write = _name##_write, .size = _size, \
+}
+#define __BIN_ATTR_WR(_name, _size) { \
+ .attr = { .name = __stringify(_name), .mode = 0644 }, \
+ .read = _name##_read, .write = _name##_write, .size = _size, \
+}
+
+#define BIN_ATTR(_name, _mode, _read, _write, _size) \
+struct bin_attribute bin_attr_##_name = \
+ __BIN_ATTR(_name, _mode, _read, _write, _size);
+
+#define BIN_ATTR_RO(_name, _size) \
+struct bin_attribute bin_attr_##_name = \
+ __BIN_ATTR_RO(_name, _size);
+
+#define BIN_ATTR_WO(_name, _size) \
+struct bin_attribute bin_attr_##_name = \
+ __BIN_ATTR_WO(_name, _size);
+
+#define BIN_ATTR_WR(_name, _size) \
+struct bin_attribute bin_attr_##_name = \
+ __BIN_ATTR_WR(_name, _size);
+
/*
* Handle our generic '\0' terminated 'C' string.
* Two cases:
@@ -145,6 +189,50 @@ sysfs_create_file(struct kobject *kobj, const struct attribute *attr)
return (0);
}
+static inline struct kobject *
+__sysfs_lookup_group(struct kobject *kobj, const char *group)
+{
+ int found;
+ struct sysctl_oid *group_oidp;
+ struct kobject *group_kobj;
+
+ found = 0;
+ if (group != NULL) {
+ SYSCTL_FOREACH(group_oidp, SYSCTL_CHILDREN(kobj->oidp)) {
+ if (strcmp(group_oidp->oid_name, group) != 0)
+ continue;
+ found = 1;
+ break;
+ }
+ } else {
+ found = 1;
+ group_oidp = kobj->oidp;
+ }
+
+ if (!found)
+ return (NULL);
+
+ group_kobj = group_oidp->oid_arg1;
+
+ return (group_kobj);
+}
+
+static inline int
+sysfs_add_file_to_group(struct kobject *kobj,
+ const struct attribute *attr, const char *group)
+{
+ int ret;
+ struct kobject *group_kobj;
+
+ group_kobj = __sysfs_lookup_group(kobj, group);
+ if (group_kobj == NULL)
+ return (-ENOENT);
+
+ ret = sysfs_create_file(group_kobj, attr);
+
+ return (ret);
+}
+
static inline void
sysfs_remove_file(struct kobject *kobj, const struct attribute *attr)
{
@@ -153,6 +241,108 @@ sysfs_remove_file(struct kobject *kobj, const struct attribute *attr)
sysctl_remove_name(kobj->oidp, attr->name, 1, 1);
}
+static inline void
+sysfs_remove_file_from_group(struct kobject *kobj,
+ const struct attribute *attr, const char *group)
+{
+ struct kobject *group_kobj;
+
+ group_kobj = __sysfs_lookup_group(kobj, group);
+ if (group_kobj == NULL)
+ return;
+
+ sysfs_remove_file(group_kobj, attr);
+}
+
+static inline int
+sysctl_handle_bin_attr(SYSCTL_HANDLER_ARGS)
+{
+ struct kobject *kobj;
+ struct bin_attribute *attr;
+ char *buf;
+ int error;
+ ssize_t len;
+
+ kobj = arg1;
+ attr = (struct bin_attribute *)(intptr_t)arg2;
+ if (kobj->ktype == NULL || kobj->ktype->sysfs_ops == NULL)
+ return (ENODEV);
+ buf = (char *)get_zeroed_page(GFP_KERNEL);
+ if (buf == NULL)
+ return (ENOMEM);
+
+ if (attr->read) {
+ len = attr->read(
+ NULL, /* <-- struct file, unimplemented */
+ kobj, attr, buf, req->oldidx, PAGE_SIZE);
+ if (len < 0) {
+ error = -len;
+ if (error != EIO)
+ goto out;
+ }
+ }
+
+ error = sysctl_handle_opaque(oidp, buf, PAGE_SIZE, req);
+ if (error != 0 || req->newptr == NULL || attr->write == NULL)
+ goto out;
+
+ len = attr->write(
+ NULL, /* <-- struct file, unimplemented */
+ kobj, attr, buf, req->newidx, req->newlen);
+ if (len < 0)
+ error = -len;
+out:
+ free_page((unsigned long)buf);
+
+ return (error);
+}
+
+static inline int
+sysfs_create_bin_file(struct kobject *kobj, const struct bin_attribute *attr)
+{
+ struct sysctl_oid *oid;
+ int ctlflags;
+
+ ctlflags = CTLTYPE_OPAQUE | CTLFLAG_MPSAFE;
+ if (attr->attr.mode & (S_IRUSR | S_IWUSR))
+ ctlflags |= CTLFLAG_RW;
+ else if (attr->attr.mode & S_IRUSR)
+ ctlflags |= CTLFLAG_RD;
+ else if (attr->attr.mode & S_IWUSR)
+ ctlflags |= CTLFLAG_WR;
+
+ oid = SYSCTL_ADD_OID(NULL, SYSCTL_CHILDREN(kobj->oidp), OID_AUTO,
+ attr->attr.name, ctlflags, kobj,
+ (uintptr_t)attr, sysctl_handle_bin_attr, "", "");
+ if (oid == NULL)
+ return (-ENOMEM);
+
+ return (0);
+}
+
+static inline void
+sysfs_remove_bin_file(struct kobject *kobj, const struct bin_attribute *attr)
+{
+
+ if (kobj->oidp)
+ sysctl_remove_name(kobj->oidp, attr->attr.name, 1, 1);
+}
+
+static inline int
+sysfs_create_link(struct kobject *kobj __unused,
+ struct kobject *target __unused, const char *name __unused)
+{
+ /* TODO */
+
+ return (0);
+}
+
+static inline void
+sysfs_remove_link(struct kobject *kobj, const char *name)
+{
+ /* TODO (along with sysfs_create_link) */
+}
+
static inline int
sysfs_create_files(struct kobject *kobj, const struct attribute * const *attrs)
{
@@ -246,7 +436,7 @@ sysfs_unmerge_group(struct kobject *kobj, const struct attribute_group *grp)
struct attribute **attr;
struct sysctl_oid *oidp;
- SLIST_FOREACH(oidp, SYSCTL_CHILDREN(kobj->oidp), oid_link) {
+ SYSCTL_FOREACH(oidp, SYSCTL_CHILDREN(kobj->oidp)) {
if (strcmp(oidp->oid_name, grp->name) != 0)
continue;
for (attr = grp->attrs; *attr != NULL; attr++) {
@@ -295,6 +485,60 @@ sysfs_streq(const char *s1, const char *s2)
return (l1 == l2 && strncmp(s1, s2, l1) == 0);
}
+static inline int
+sysfs_emit(char *buf, const char *fmt, ...)
+{
+ va_list args;
+ int i;
+
+ if (!buf || offset_in_page(buf)) {
+ pr_warn("invalid sysfs_emit: buf:%p\n", buf);
+ return (0);
+ }
+
+ va_start(args, fmt);
+ i = vscnprintf(buf, PAGE_SIZE, fmt, args);
+ va_end(args);
+
+ return (i);
+}
+
+static inline int
+sysfs_emit_at(char *buf, int at, const char *fmt, ...)
+{
+ va_list args;
+ int i;
+
+ if (!buf || offset_in_page(buf) || at < 0 || at >= PAGE_SIZE) {
+ pr_warn("invalid sysfs_emit: buf:%p at:%d\n", buf, at);
+ return (0);
+ }
+
+ va_start(args, fmt);
+ i = vscnprintf(buf + at, PAGE_SIZE - at, fmt, args);
+ va_end(args);
+
+ return (i);
+}
+
+static inline int
+_sysfs_match_string(const char * const *a, size_t l, const char *s)
+{
+ const char *p;
+ int i;
+
+ for (i = 0; i < l; i++) {
+ p = a[i];
+ if (p == NULL)
+ break;
+ if (sysfs_streq(p, s))
+ return (i);
+ }
+
+ return (-ENOENT);
+}
+#define sysfs_match_string(a, s) _sysfs_match_string(a, ARRAY_SIZE(a), s)
+
#define sysfs_attr_init(attr) do {} while(0)
-#endif /* _LINUX_SYSFS_H_ */
+#endif /* _LINUXKPI_LINUX_SYSFS_H_ */
diff --git a/sys/compat/linuxkpi/common/include/linux/tcp.h b/sys/compat/linuxkpi/common/include/linux/tcp.h
index 1197f38b7898..3e461d8e7075 100644
--- a/sys/compat/linuxkpi/common/include/linux/tcp.h
+++ b/sys/compat/linuxkpi/common/include/linux/tcp.h
@@ -26,12 +26,10 @@
* 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.
- *
- * $FreeBSD$
*/
-#ifndef __LKPI_LINUX_TCP_H
-#define __LKPI_LINUX_TCP_H
+#ifndef _LINUXKPI_LINUX_TCP_H
+#define _LINUXKPI_LINUX_TCP_H
#include <sys/types.h>
#include <linux/skbuff.h>
@@ -69,4 +67,4 @@ tcp_hdrlen(struct sk_buff *skb)
return (4 * th->doff);
}
-#endif /* __LKPI_LINUX_TCP_H */
+#endif /* _LINUXKPI_LINUX_TCP_H */
diff --git a/sys/compat/linuxkpi/common/include/linux/time.h b/sys/compat/linuxkpi/common/include/linux/time.h
index 1c07c69a67a6..ca77a20516ff 100644
--- a/sys/compat/linuxkpi/common/include/linux/time.h
+++ b/sys/compat/linuxkpi/common/include/linux/time.h
@@ -22,11 +22,11 @@
* 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.
- *
- * $FreeBSD$
*/
-#ifndef _LINUX_TIME_H_
-#define _LINUX_TIME_H_
+#ifndef _LINUXKPI_LINUX_TIME_H_
+#define _LINUXKPI_LINUX_TIME_H_
+
+#define MSEC_PER_SEC 1000L
#define NSEC_PER_USEC 1000L
#define NSEC_PER_MSEC 1000000L
@@ -40,6 +40,10 @@
#include <sys/time.h>
#include <sys/stdint.h>
+#include <linux/math64.h>
+
+typedef int64_t time64_t;
+
static inline struct timeval
ns_to_timeval(const int64_t nsec)
{
@@ -117,6 +121,8 @@ ns_to_timespec(const int64_t nsec)
return (ts);
}
+#define ns_to_timespec64(_x) ns_to_timespec(_x)
+
static inline int
timespec_valid(const struct timespec *ts)
{
@@ -132,4 +138,4 @@ get_seconds(void)
return time_uptime;
}
-#endif /* _LINUX_TIME_H_ */
+#endif /* _LINUXKPI_LINUX_TIME_H_ */
diff --git a/sys/compat/linuxkpi/common/include/linux/timer.h b/sys/compat/linuxkpi/common/include/linux/timer.h
index 86048af31b2d..d48939e28a02 100644
--- a/sys/compat/linuxkpi/common/include/linux/timer.h
+++ b/sys/compat/linuxkpi/common/include/linux/timer.h
@@ -25,11 +25,9 @@
* 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.
- *
- * $FreeBSD$
*/
-#ifndef _LINUX_TIMER_H_
-#define _LINUX_TIMER_H_
+#ifndef _LINUXKPI_LINUX_TIMER_H_
+#define _LINUXKPI_LINUX_TIMER_H_
#include <linux/types.h>
@@ -44,15 +42,20 @@ struct timer_list {
void (*function_415) (struct timer_list *);
};
unsigned long data;
- int expires;
+ unsigned long expires;
};
extern unsigned long linux_timer_hz_mask;
#define TIMER_IRQSAFE 0x0001
+#if defined(LINUXKPI_VERSION) && (LINUXKPI_VERSION < 61600)
#define from_timer(var, arg, field) \
container_of(arg, typeof(*(var)), field)
+#else
+#define timer_container_of(var, arg, field) \
+ container_of(arg, typeof(*(var)), field)
+#endif
#define timer_setup(timer, func, flags) do { \
CTASSERT(((flags) & ~TIMER_IRQSAFE) == 0); \
@@ -78,17 +81,31 @@ extern unsigned long linux_timer_hz_mask;
callout_init(&(timer)->callout, 1); \
} while (0)
-extern int mod_timer(struct timer_list *, int);
+extern int mod_timer(struct timer_list *, unsigned long);
extern void add_timer(struct timer_list *);
extern void add_timer_on(struct timer_list *, int cpu);
-extern int del_timer(struct timer_list *);
-extern int del_timer_sync(struct timer_list *);
+
+extern int timer_delete(struct timer_list *);
+extern int timer_delete_sync(struct timer_list *);
+extern int timer_shutdown_sync(struct timer_list *);
+
+static inline int
+del_timer(struct timer_list *tl)
+{
+ return (timer_delete(tl));
+}
+
+static inline int
+del_timer_sync(struct timer_list *tl)
+{
+ return (timer_delete_sync(tl));
+}
#define timer_pending(timer) callout_pending(&(timer)->callout)
#define round_jiffies(j) \
- ((int)(((j) + linux_timer_hz_mask) & ~linux_timer_hz_mask))
+ ((unsigned long)(((j) + linux_timer_hz_mask) & ~linux_timer_hz_mask))
#define round_jiffies_relative(j) round_jiffies(j)
#define round_jiffies_up(j) round_jiffies(j)
#define round_jiffies_up_relative(j) round_jiffies_up(j)
-#endif /* _LINUX_TIMER_H_ */
+#endif /* _LINUXKPI_LINUX_TIMER_H_ */
diff --git a/sys/compat/linuxkpi/common/include/linux/topology.h b/sys/compat/linuxkpi/common/include/linux/topology.h
new file mode 100644
index 000000000000..16baffc024d1
--- /dev/null
+++ b/sys/compat/linuxkpi/common/include/linux/topology.h
@@ -0,0 +1,35 @@
+/*-
+ * Copyright (c) 2025 The FreeBSD Foundation
+ * Copyright (c) 2025 Jean-Sébastien Pédron
+ *
+ * This software was developed by Jean-Sébastien Pédron under sponsorship
+ * from the FreeBSD Foundation.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``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 OR CONTRIBUTORS 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.
+ */
+
+#ifndef _LINUXKPI_LINUX_TOPOLOGY_H_
+#define _LINUXKPI_LINUX_TOPOLOGY_H_
+
+#include <asm/topology.h>
+
+#endif /* _LINUXKPI_LINUX_TOPOLOGY_H_ */
diff --git a/sys/compat/linuxkpi/common/include/linux/tracepoint.h b/sys/compat/linuxkpi/common/include/linux/tracepoint.h
new file mode 100644
index 000000000000..8ce7992306b9
--- /dev/null
+++ b/sys/compat/linuxkpi/common/include/linux/tracepoint.h
@@ -0,0 +1,48 @@
+/*-
+ * SPDX-License-Identifier: BSD-2-Clause
+ *
+ * Copyright (c) 2022 Bjoern A. Zeeb
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``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 OR CONTRIBUTORS 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.
+ */
+
+#ifndef _LINUXKPI_LINUX_TRACEPOINT_H
+#define _LINUXKPI_LINUX_TRACEPOINT_H
+
+#define TP_PROTO(...) __VA_ARGS__
+#define TP_ARGS(...)
+#define TP_STRUCT__entry(...)
+#define TP_fast_assign(...)
+#define TP_printk(...)
+
+#define TRACE_EVENT(_name, _proto, _args, _struct, _assign, _printk) \
+static inline void trace_ ## _name(_proto) \
+{ \
+}
+
+#define DECLARE_EVENT_CLASS(...)
+#define DEFINE_EVENT(_x, _name, _proto, _args) \
+static inline void trace_ ## _name(_proto) \
+{ \
+}
+
+#endif /* _LINUXKPI_LINUX_TRACEPOINT_H */
diff --git a/sys/compat/linuxkpi/common/include/linux/typecheck.h b/sys/compat/linuxkpi/common/include/linux/typecheck.h
new file mode 100644
index 000000000000..0e813962a7f5
--- /dev/null
+++ b/sys/compat/linuxkpi/common/include/linux/typecheck.h
@@ -0,0 +1,38 @@
+/*-
+ * Copyright (c) 2022 Beckhoff Automation GmbH & Co. KG
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``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 OR CONTRIBUTORS 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.
+ *
+ */
+
+#ifndef _LINUXKPI_LINUX_TYPECHECK_H_
+#define _LINUXKPI_LINUX_TYPECHECK_H_
+
+#define typecheck(type,x) \
+({ type __var1; \
+ typeof(x) __var2; \
+ (void)(&__var1 == &__var2); \
+ 1; \
+})
+
+
+#endif /* _LINUXKPI_LINUX_TYPECHECK_H_ */
diff --git a/sys/compat/linuxkpi/common/include/linux/types.h b/sys/compat/linuxkpi/common/include/linux/types.h
index db362c388573..fcc455e5f731 100644
--- a/sys/compat/linuxkpi/common/include/linux/types.h
+++ b/sys/compat/linuxkpi/common/include/linux/types.h
@@ -25,13 +25,10 @@
* 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.
- *
- * $FreeBSD$
*/
-#ifndef _LINUX_TYPES_H_
-#define _LINUX_TYPES_H_
+#ifndef _LINUXKPI_LINUX_TYPES_H_
+#define _LINUXKPI_LINUX_TYPES_H_
-#include <sys/cdefs.h>
#include <sys/types.h>
#include <sys/param.h>
#include <sys/systm.h>
@@ -66,6 +63,7 @@ typedef unsigned gfp_t;
typedef off_t loff_t;
typedef vm_paddr_t resource_size_t;
typedef uint16_t __bitwise__ __sum16;
+typedef uint32_t __bitwise__ __wsum;
typedef unsigned long pgoff_t;
typedef unsigned __poll_t;
@@ -79,6 +77,14 @@ typedef unsigned long kernel_ulong_t;
typedef unsigned long irq_hw_number_t;
+#ifndef LIST_HEAD_DEF
+#define LIST_HEAD_DEF
+struct list_head {
+ struct list_head *next;
+ struct list_head *prev;
+};
+#endif
+
struct rcu_head {
void *raw[2];
} __aligned(sizeof(void *));
@@ -87,4 +93,4 @@ typedef void (*rcu_callback_t)(struct rcu_head *head);
typedef void (*call_rcu_func_t)(struct rcu_head *head, rcu_callback_t func);
typedef int linux_task_fn_t(void *data);
-#endif /* _LINUX_TYPES_H_ */
+#endif /* _LINUXKPI_LINUX_TYPES_H_ */
diff --git a/sys/compat/linuxkpi/common/include/linux/uaccess.h b/sys/compat/linuxkpi/common/include/linux/uaccess.h
index 10a06a220f86..660e84e6af3b 100644
--- a/sys/compat/linuxkpi/common/include/linux/uaccess.h
+++ b/sys/compat/linuxkpi/common/include/linux/uaccess.h
@@ -26,12 +26,10 @@
* 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.
- *
- * $FreeBSD$
*/
-#ifndef _LINUX_UACCESS_H_
-#define _LINUX_UACCESS_H_
+#ifndef _LINUXKPI_LINUX_UACCESS_H_
+#define _LINUXKPI_LINUX_UACCESS_H_
#include <sys/param.h>
#include <sys/lock.h>
@@ -89,4 +87,29 @@ pagefault_disabled(void)
return ((curthread->td_pflags & TDP_NOFAULTING) != 0);
}
-#endif /* _LINUX_UACCESS_H_ */
+static inline int
+__copy_to_user_inatomic(void __user *to, const void *from, unsigned n)
+{
+
+ return (copyout_nofault(from, to, n) != 0 ? n : 0);
+}
+#define __copy_to_user_inatomic_nocache(to, from, n) \
+ __copy_to_user_inatomic((to), (from), (n))
+
+static inline unsigned long
+__copy_from_user_inatomic(void *to, const void __user *from,
+ unsigned long n)
+{
+ /*
+ * XXXKIB. Equivalent Linux function is implemented using
+ * MOVNTI for aligned moves. For unaligned head and tail,
+ * normal move is performed. As such, it is not incorrect, if
+ * only somewhat slower, to use normal copyin. All uses
+ * except shmem_pwrite_fast() have the destination mapped WC.
+ */
+ return ((copyin_nofault(__DECONST(void *, from), to, n) != 0 ? n : 0));
+}
+#define __copy_from_user_inatomic_nocache(to, from, n) \
+ __copy_from_user_inatomic((to), (from), (n))
+
+#endif /* _LINUXKPI_LINUX_UACCESS_H_ */
diff --git a/sys/compat/linuxkpi/common/include/linux/udp.h b/sys/compat/linuxkpi/common/include/linux/udp.h
index 259bdbfc1199..f3cd40cf8bb7 100644
--- a/sys/compat/linuxkpi/common/include/linux/udp.h
+++ b/sys/compat/linuxkpi/common/include/linux/udp.h
@@ -26,12 +26,10 @@
* 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.
- *
- * $FreeBSD$
*/
-#ifndef __LKPI_LINUX_UDP_H
-#define __LKPI_LINUX_UDP_H
+#ifndef _LINUXKPI_LINUX_UDP_H
+#define _LINUXKPI_LINUX_UDP_H
#include <sys/types.h>
#include <linux/skbuff.h>
@@ -51,4 +49,4 @@ udp_hdr(struct sk_buff *skb)
return (struct udphdr *)skb_transport_header(skb);
}
-#endif /* __LKPI_LINUX_UDP_H */
+#endif /* _LINUXKPI_LINUX_UDP_H */
diff --git a/sys/compat/linuxkpi/common/include/linux/units.h b/sys/compat/linuxkpi/common/include/linux/units.h
new file mode 100644
index 000000000000..304b5c27d87f
--- /dev/null
+++ b/sys/compat/linuxkpi/common/include/linux/units.h
@@ -0,0 +1,40 @@
+/*-
+ * Copyright (c) 2025 The FreeBSD Foundation
+ * Copyright (c) 2025 Jean-Sébastien Pédron
+ *
+ * This software was developed by Jean-Sébastien Pédron under sponsorship
+ * from the FreeBSD Foundation.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``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 OR CONTRIBUTORS 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.
+ */
+
+#ifndef _LINUXKPI_LINUX_UNITS_H_
+#define _LINUXKPI_LINUX_UNITS_H_
+
+#define NANOHZ_PER_HZ 1000000000UL
+#define MICROHZ_PER_HZ 1000000UL
+#define MILLIHZ_PER_HZ 1000UL
+#define HZ_PER_KHZ 1000UL
+#define KHZ_PER_MHZ 1000UL
+#define HZ_PER_MHZ 1000000UL
+
+#endif /* _LINUXKPI_LINUX_UNITS_H_ */
diff --git a/sys/compat/linuxkpi/common/include/linux/usb.h b/sys/compat/linuxkpi/common/include/linux/usb.h
index 032c1e53a015..d9649dcb5471 100644
--- a/sys/compat/linuxkpi/common/include/linux/usb.h
+++ b/sys/compat/linuxkpi/common/include/linux/usb.h
@@ -1,4 +1,3 @@
-/* $FreeBSD$ */
/*-
* Copyright (c) 2007 Luigi Rizzo - Universita` di Pisa. All rights reserved.
* Copyright (c) 2007 Hans Petter Selasky. All rights reserved.
@@ -37,12 +36,13 @@
#include <dev/usb/usbdi.h>
#include <dev/usb/usbdi_util.h>
+#include <linux/pm.h>
+
struct usb_device;
struct usb_interface;
struct usb_driver;
struct urb;
-typedef void *pm_message_t;
typedef void (usb_complete_t)(struct urb *);
#define USB_MAX_FULL_SPEED_ISOC_FRAMES (60 * 1)
diff --git a/sys/compat/linuxkpi/common/include/linux/utsname.h b/sys/compat/linuxkpi/common/include/linux/utsname.h
new file mode 100644
index 000000000000..3239801ca17b
--- /dev/null
+++ b/sys/compat/linuxkpi/common/include/linux/utsname.h
@@ -0,0 +1,51 @@
+/*-
+ * SPDX-License-Identifier: BSD-2-Clause
+ *
+ * Copyright (c) 2023 Bjoern A. Zeeb
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``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 OR CONTRIBUTORS 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.
+ */
+
+#ifndef _LINUXKPI_LINUX_UTSNAME_H
+#define _LINUXKPI_LINUX_UTSNAME_H
+
+#include <sys/types.h>
+#include <sys/jail.h>
+
+struct _utsname {
+ char release[OSRELEASELEN];
+};
+
+struct uts_namespace {
+ struct _utsname name;
+};
+
+extern struct uts_namespace init_uts_ns;
+
+static inline struct _utsname *
+init_utsname(void)
+{
+
+ return &init_uts_ns.name;
+}
+
+#endif /* _LINUXKPI_LINUX_UTSNAME_H */
diff --git a/sys/compat/linuxkpi/common/include/linux/uuid.h b/sys/compat/linuxkpi/common/include/linux/uuid.h
index f2ff450ee907..4f6f4a8b34f0 100644
--- a/sys/compat/linuxkpi/common/include/linux/uuid.h
+++ b/sys/compat/linuxkpi/common/include/linux/uuid.h
@@ -1,7 +1,7 @@
/*-
* SPDX-License-Identifier: BSD-2-Clause
*
- * Copyright (c) 2021 The FreeBSD Foundation
+ * Copyright (c) 2021,2023 The FreeBSD Foundation
*
* This software was developed by Björn Zeeb under sponsorship from
* the FreeBSD Foundation.
@@ -26,15 +26,52 @@
* 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.
- *
- * $FreeBSD$
*/
-#ifndef __LKPI_LINUX_UUID_H
-#define __LKPI_LINUX_UUID_H
+#ifndef _LINUXKPI_LINUX_UUID_H
+#define _LINUXKPI_LINUX_UUID_H
+
+#include <linux/random.h>
+
+#define UUID_STRING_LEN 36
+
+#define GUID_INIT(x0_3, x4_5, x6_7, x8, x9, x10, x11, x12, x13, x14, x15) \
+ ((guid_t) { .x = { \
+ [0] = (x0_3) & 0xff, \
+ [1] = ((x0_3) >> 8) & 0xff, \
+ [2] = ((x0_3) >> 16) & 0xff, \
+ [3] = ((x0_3) >> 24) & 0xff, \
+ [4] = (x4_5) & 0xff, \
+ [5] = ((x4_5) >> 8) & 0xff, \
+ [6] = (x6_7) & 0xff, \
+ [7] = ((x6_7) >> 8) & 0xff, \
+ [8] = (x8), \
+ [9] = (x9), \
+ [10] = (x10), \
+ [11] = (x11), \
+ [12] = (x12), \
+ [13] = (x13), \
+ [14] = (x14), \
+ [15] = (x15) \
+}})
typedef struct {
char x[16];
} guid_t;
-#endif /* __LKPI_LINUX_UUID_H */
+static inline void
+guid_gen(guid_t *g)
+{
+
+ get_random_bytes(g, 16);
+ g->x[7] = (g->x[7] & 0x0f) | 0x40;
+ g->x[8] = (g->x[8] & 0x3f) | 0x80;
+}
+
+static inline void
+guid_copy(guid_t *dst, const guid_t *src)
+{
+ memcpy(dst, src, sizeof(*dst));
+}
+
+#endif /* _LINUXKPI_LINUX_UUID_H */
diff --git a/sys/compat/linuxkpi/common/include/linux/vgaarb.h b/sys/compat/linuxkpi/common/include/linux/vgaarb.h
new file mode 100644
index 000000000000..d43a88136864
--- /dev/null
+++ b/sys/compat/linuxkpi/common/include/linux/vgaarb.h
@@ -0,0 +1,281 @@
+/*
+ * The VGA aribiter manages VGA space routing and VGA resource decode to
+ * allow multiple VGA devices to be used in a system in a safe way.
+ *
+ * (C) Copyright 2005 Benjamin Herrenschmidt <benh@kernel.crashing.org>
+ * (C) Copyright 2007 Paulo R. Zanoni <przanoni@gmail.com>
+ * (C) Copyright 2007, 2009 Tiago Vignatti <vignatti@freedesktop.org>
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice (including the next
+ * paragraph) shall be included in all copies or substantial portions of the
+ * Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
+ * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+ * DEALINGS
+ * IN THE SOFTWARE.
+ *
+ */
+
+#ifndef _LINUXKPI_LINUX_VGA_H_
+#define _LINUXKPI_LINUX_VGA_H_
+
+#include <video/vga.h>
+
+/* Legacy VGA regions */
+#define VGA_RSRC_NONE 0x00
+#define VGA_RSRC_LEGACY_IO 0x01
+#define VGA_RSRC_LEGACY_MEM 0x02
+#define VGA_RSRC_LEGACY_MASK (VGA_RSRC_LEGACY_IO | VGA_RSRC_LEGACY_MEM)
+/* Non-legacy access */
+#define VGA_RSRC_NORMAL_IO 0x04
+#define VGA_RSRC_NORMAL_MEM 0x08
+
+/* Passing that instead of a pci_dev to use the system "default"
+ * device, that is the one used by vgacon. Archs will probably
+ * have to provide their own vga_default_device();
+ */
+#define VGA_DEFAULT_DEVICE (NULL)
+
+struct pci_dev;
+
+/* For use by clients */
+
+/**
+ * vga_set_legacy_decoding
+ *
+ * @pdev: pci device of the VGA card
+ * @decodes: bit mask of what legacy regions the card decodes
+ *
+ * Indicates to the arbiter if the card decodes legacy VGA IOs,
+ * legacy VGA Memory, both, or none. All cards default to both,
+ * the card driver (fbdev for example) should tell the arbiter
+ * if it has disabled legacy decoding, so the card can be left
+ * out of the arbitration process (and can be safe to take
+ * interrupts at any time.
+ */
+#if defined(CONFIG_VGA_ARB)
+extern void vga_set_legacy_decoding(struct pci_dev *pdev,
+ unsigned int decodes);
+#else
+static inline void vga_set_legacy_decoding(struct pci_dev *pdev,
+ unsigned int decodes) { };
+#endif
+
+/**
+ * vga_get - acquire & locks VGA resources
+ *
+ * @pdev: pci device of the VGA card or NULL for the system default
+ * @rsrc: bit mask of resources to acquire and lock
+ * @interruptible: blocking should be interruptible by signals ?
+ *
+ * This function acquires VGA resources for the given
+ * card and mark those resources locked. If the resource requested
+ * are "normal" (and not legacy) resources, the arbiter will first check
+ * whether the card is doing legacy decoding for that type of resource. If
+ * yes, the lock is "converted" into a legacy resource lock.
+ * The arbiter will first look for all VGA cards that might conflict
+ * and disable their IOs and/or Memory access, including VGA forwarding
+ * on P2P bridges if necessary, so that the requested resources can
+ * be used. Then, the card is marked as locking these resources and
+ * the IO and/or Memory accesse are enabled on the card (including
+ * VGA forwarding on parent P2P bridges if any).
+ * This function will block if some conflicting card is already locking
+ * one of the required resources (or any resource on a different bus
+ * segment, since P2P bridges don't differenciate VGA memory and IO
+ * afaik). You can indicate whether this blocking should be interruptible
+ * by a signal (for userland interface) or not.
+ * Must not be called at interrupt time or in atomic context.
+ * If the card already owns the resources, the function succeeds.
+ * Nested calls are supported (a per-resource counter is maintained)
+ */
+
+#if defined(CONFIG_VGA_ARB)
+extern int vga_get(struct pci_dev *pdev, unsigned int rsrc, int interruptible);
+#else
+static inline int vga_get(struct pci_dev *pdev, unsigned int rsrc, int interruptible) { return 0; }
+#endif
+
+/**
+ * vga_get_interruptible
+ *
+ * Shortcut to vga_get
+ */
+
+static inline int vga_get_interruptible(struct pci_dev *pdev,
+ unsigned int rsrc)
+{
+ return vga_get(pdev, rsrc, 1);
+}
+
+/**
+ * vga_get_uninterruptible
+ *
+ * Shortcut to vga_get
+ */
+
+static inline int vga_get_uninterruptible(struct pci_dev *pdev,
+ unsigned int rsrc)
+{
+ return vga_get(pdev, rsrc, 0);
+}
+
+/**
+ * vga_tryget - try to acquire & lock legacy VGA resources
+ *
+ * @pdev: pci devivce of VGA card or NULL for system default
+ * @rsrc: bit mask of resources to acquire and lock
+ *
+ * This function performs the same operation as vga_get(), but
+ * will return an error (-EBUSY) instead of blocking if the resources
+ * are already locked by another card. It can be called in any context
+ */
+
+#if defined(CONFIG_VGA_ARB)
+extern int vga_tryget(struct pci_dev *pdev, unsigned int rsrc);
+#else
+static inline int vga_tryget(struct pci_dev *pdev, unsigned int rsrc) { return 0; }
+#endif
+
+/**
+ * vga_put - release lock on legacy VGA resources
+ *
+ * @pdev: pci device of VGA card or NULL for system default
+ * @rsrc: but mask of resource to release
+ *
+ * This function releases resources previously locked by vga_get()
+ * or vga_tryget(). The resources aren't disabled right away, so
+ * that a subsequence vga_get() on the same card will succeed
+ * immediately. Resources have a counter, so locks are only
+ * released if the counter reaches 0.
+ */
+
+#if defined(CONFIG_VGA_ARB)
+extern void vga_put(struct pci_dev *pdev, unsigned int rsrc);
+#else
+#define vga_put(pdev, rsrc)
+#endif
+
+
+/**
+ * vga_default_device
+ *
+ * This can be defined by the platform. The default implementation
+ * is rather dumb and will probably only work properly on single
+ * vga card setups and/or x86 platforms.
+ *
+ * If your VGA default device is not PCI, you'll have to return
+ * NULL here. In this case, I assume it will not conflict with
+ * any PCI card. If this is not true, I'll have to define two archs
+ * hooks for enabling/disabling the VGA default device if that is
+ * possible. This may be a problem with real _ISA_ VGA cards, in
+ * addition to a PCI one. I don't know at this point how to deal
+ * with that card. Can theirs IOs be disabled at all ? If not, then
+ * I suppose it's a matter of having the proper arch hook telling
+ * us about it, so we basically never allow anybody to succeed a
+ * vga_get()...
+ */
+
+#ifdef CONFIG_VGA_ARB
+extern struct pci_dev *vga_default_device(void);
+extern void vga_set_default_device(struct pci_dev *pdev);
+#else
+static inline struct pci_dev *vga_default_device(void) { return NULL; };
+static inline void vga_set_default_device(struct pci_dev *pdev) { };
+#endif
+
+/**
+ * vga_conflicts
+ *
+ * Architectures should define this if they have several
+ * independent PCI domains that can afford concurrent VGA
+ * decoding
+ */
+
+#ifndef __ARCH_HAS_VGA_CONFLICT
+static inline int vga_conflicts(struct pci_dev *p1, struct pci_dev *p2)
+{
+ return 1;
+}
+#endif
+
+/**
+ * vga_client_register
+ *
+ * @pdev: pci device of the VGA client
+ * @cookie: client cookie to be used in callbacks
+ * @irq_set_state: irq state change callback
+ * @set_vga_decode: vga decode change callback
+ *
+ * return value: 0 on success, -1 on failure
+ * Register a client with the VGA arbitration logic
+ *
+ * Clients have two callback mechanisms they can use.
+ * irq enable/disable callback -
+ * If a client can't disable its GPUs VGA resources, then we
+ * need to be able to ask it to turn off its irqs when we
+ * turn off its mem and io decoding.
+ * set_vga_decode
+ * If a client can disable its GPU VGA resource, it will
+ * get a callback from this to set the encode/decode state
+ *
+ * Rationale: we cannot disable VGA decode resources unconditionally
+ * some single GPU laptops seem to require ACPI or BIOS access to the
+ * VGA registers to control things like backlights etc.
+ * Hopefully newer multi-GPU laptops do something saner, and desktops
+ * won't have any special ACPI for this.
+ * They driver will get a callback when VGA arbitration is first used
+ * by userspace since we some older X servers have issues.
+ */
+#if defined(CONFIG_VGA_ARB)
+#if defined(LINUXKPI_VERSION) && LINUXKPI_VERSION >= 51501
+int vga_client_register(struct pci_dev *pdev,
+ unsigned int (*set_vga_decode)(struct pci_dev *pdev, bool state));
+#elif defined(LINUXKPI_VERSION) && LINUXKPI_VERSION >= 51500
+int vga_client_register(struct pci_dev *pdev, void *cookie,
+ unsigned int (*set_vga_decode)(void *cookie, bool state));
+#else
+int vga_client_register(struct pci_dev *pdev, void *cookie,
+ void (*irq_set_state)(void *cookie, bool state),
+ unsigned int (*set_vga_decode)(void *cookie, bool state));
+#endif
+#else
+#if defined(LINUXKPI_VERSION) && LINUXKPI_VERSION >= 51501
+static inline int vga_client_register(struct pci_dev *pdev,
+ unsigned int (*set_vga_decode)(struct pci_dev *pdev, bool state))
+#elif defined(LINUXKPI_VERSION) && LINUXKPI_VERSION >= 51500
+static inline int vga_client_register(struct pci_dev *pdev, void *cookie,
+ unsigned int (*set_vga_decode)(void *cookie, bool state))
+#else
+static inline int vga_client_register(struct pci_dev *pdev, void *cookie,
+ void (*irq_set_state)(void *cookie, bool state),
+ unsigned int (*set_vga_decode)(void *cookie, bool state))
+#endif
+{
+ return 0;
+}
+
+static inline int vga_client_unregister(struct pci_dev *pdev)
+{
+#if defined(LINUXKPI_VERSION) && LINUXKPI_VERSION >= 51501
+ return (vga_client_register(NULL, NULL));
+#elif defined(LINUXKPI_VERSION) && LINUXKPI_VERSION >= 51500
+ return (vga_client_register(NULL, NULL, NULL));
+#else
+ return (vga_client_register(NULL, NULL, NULL, NULL));
+#endif
+}
+#endif
+
+#endif /* _LINUXKPI_LINUX_VGA_H_ */
diff --git a/sys/compat/linuxkpi/common/include/linux/vmalloc.h b/sys/compat/linuxkpi/common/include/linux/vmalloc.h
index 53178314c35a..00650a2df9b6 100644
--- a/sys/compat/linuxkpi/common/include/linux/vmalloc.h
+++ b/sys/compat/linuxkpi/common/include/linux/vmalloc.h
@@ -25,12 +25,11 @@
* 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.
- *
- * $FreeBSD$
*/
-#ifndef _LINUX_VMALLOC_H_
-#define _LINUX_VMALLOC_H_
+#ifndef _LINUXKPI_LINUX_VMALLOC_H_
+#define _LINUXKPI_LINUX_VMALLOC_H_
+#include <linux/overflow.h>
#include <linux/page.h>
#define VM_MAP 0x0000
@@ -40,4 +39,4 @@ void *vmap(struct page **pages, unsigned int count, unsigned long flags,
int prot);
void vunmap(void *addr);
-#endif /* _LINUX_VMALLOC_H_ */
+#endif /* _LINUXKPI_LINUX_VMALLOC_H_ */
diff --git a/sys/compat/linuxkpi/common/include/linux/wait.h b/sys/compat/linuxkpi/common/include/linux/wait.h
index 348464fb27df..03ddce2c06f5 100644
--- a/sys/compat/linuxkpi/common/include/linux/wait.h
+++ b/sys/compat/linuxkpi/common/include/linux/wait.h
@@ -26,12 +26,10 @@
* 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.
- *
- * $FreeBSD$
*/
-#ifndef _LINUX_WAIT_H_
-#define _LINUX_WAIT_H_
+#ifndef _LINUXKPI_LINUX_WAIT_H_
+#define _LINUXKPI_LINUX_WAIT_H_
#include <linux/compiler.h>
#include <linux/list.h>
@@ -63,12 +61,14 @@ typedef struct wait_queue_head wait_queue_head_t;
typedef int wait_queue_func_t(wait_queue_t *, unsigned int, int, void *);
+#define WQ_FLAG_WOKEN 0x02
+
/*
* Many API consumers directly reference these fields and those of
* wait_queue_head.
*/
struct wait_queue {
- unsigned int flags; /* always 0 */
+ unsigned int flags;
void *private;
wait_queue_func_t *func;
union {
@@ -89,8 +89,14 @@ struct wait_queue_head {
* This function is referenced by at least one DRM driver, so it may not be
* renamed and furthermore must be the default wait queue callback.
*/
-extern wait_queue_func_t autoremove_wake_function;
-extern wait_queue_func_t default_wake_function;
+wait_queue_func_t autoremove_wake_function;
+wait_queue_func_t default_wake_function;
+wait_queue_func_t woken_wake_function;
+
+long linux_wait_woken(wait_queue_t *wq, unsigned state, long timeout);
+
+#define wait_woken(wq, state, timeout) \
+ linux_wait_woken((wq), (state), (timeout))
#define DEFINE_WAIT_FUNC(name, function) \
wait_queue_t name = { \
@@ -112,10 +118,10 @@ extern wait_queue_func_t default_wake_function;
wait_queue_head_t name = { \
.task_list = LINUX_LIST_HEAD_INIT(name.task_list), \
}; \
- MTX_SYSINIT(name, &(name).lock.m, spin_lock_name("wqhead"), MTX_DEF)
+ MTX_SYSINIT(name, &(name).lock, spin_lock_name("wqhead"), MTX_DEF)
#define init_waitqueue_head(wqh) do { \
- mtx_init(&(wqh)->lock.m, spin_lock_name("wqhead"), \
+ mtx_init(&(wqh)->lock, spin_lock_name("wqhead"), \
NULL, MTX_DEF | MTX_NEW | MTX_NOWITNESS); \
INIT_LIST_HEAD(&(wqh)->task_list); \
} while (0)
@@ -140,7 +146,7 @@ void linux_wake_up(wait_queue_head_t *, unsigned int, int, bool);
#define wake_up_interruptible_all(wqh) \
linux_wake_up(wqh, TASK_INTERRUPTIBLE, 0, false)
-int linux_wait_event_common(wait_queue_head_t *, wait_queue_t *, int,
+int linux_wait_event_common(wait_queue_head_t *, wait_queue_t *, long,
unsigned int, spinlock_t *);
/*
@@ -150,9 +156,9 @@ int linux_wait_event_common(wait_queue_head_t *, wait_queue_t *, int,
*/
#define __wait_event_common(wqh, cond, timeout, state, lock) ({ \
DEFINE_WAIT(__wq); \
- const int __timeout = ((int)(timeout)) < 1 ? 1 : (timeout); \
- int __start = ticks; \
- int __ret = 0; \
+ const long __timeout = ((long)(timeout)) < 1 ? 1 : (timeout); \
+ long __start = jiffies; \
+ long __ret = 0; \
\
for (;;) { \
linux_prepare_to_wait(&(wqh), &__wq, state); \
@@ -168,7 +174,7 @@ int linux_wait_event_common(wait_queue_head_t *, wait_queue_t *, int,
if (__ret == -EWOULDBLOCK) \
__ret = !!(cond); \
else if (__ret != -ERESTARTSYS) { \
- __ret = __timeout + __start - ticks; \
+ __ret = __timeout + __start - jiffies; \
/* range check return value */ \
if (__ret < 1) \
__ret = 1; \
@@ -286,7 +292,7 @@ void linux_finish_wait(wait_queue_head_t *, wait_queue_t *);
#define finish_wait(wqh, wq) linux_finish_wait(wqh, wq)
void linux_wake_up_bit(void *, int);
-int linux_wait_on_bit_timeout(unsigned long *, int, unsigned int, int);
+int linux_wait_on_bit_timeout(unsigned long *, int, unsigned int, long);
void linux_wake_up_atomic_t(atomic_t *);
int linux_wait_on_atomic_t(atomic_t *, unsigned int);
@@ -310,4 +316,4 @@ bool linux_wake_up_state(struct task_struct *, unsigned int);
#define wake_up_process(task) linux_wake_up_state(task, TASK_NORMAL)
#define wake_up_state(task, state) linux_wake_up_state(task, state)
-#endif /* _LINUX_WAIT_H_ */
+#endif /* _LINUXKPI_LINUX_WAIT_H_ */
diff --git a/sys/compat/linuxkpi/common/include/linux/wait_bit.h b/sys/compat/linuxkpi/common/include/linux/wait_bit.h
index 711b19da6582..573798590b73 100644
--- a/sys/compat/linuxkpi/common/include/linux/wait_bit.h
+++ b/sys/compat/linuxkpi/common/include/linux/wait_bit.h
@@ -24,12 +24,10 @@
* 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.
- *
- * $FreeBSD$
*/
-#ifndef __LINUX_WAITBIT_H__
-#define __LINUX_WAITBIT_H__
+#ifndef __LINUXKPI_LINUX_WAITBIT_H__
+#define __LINUXKPI_LINUX_WAITBIT_H__
#include <linux/wait.h>
#include <linux/bitops.h>
@@ -64,4 +62,10 @@ wake_up_var(void *var)
wake_up(&linux_var_waitq);
}
-#endif /* __LINUX_WAITBIT_H__ */
+static inline wait_queue_head_t *
+__var_waitqueue(void *p)
+{
+ return (&linux_var_waitq);
+}
+
+#endif /* __LINUXKPI_LINUX_WAITBIT_H__ */
diff --git a/sys/compat/linuxkpi/common/include/linux/workqueue.h b/sys/compat/linuxkpi/common/include/linux/workqueue.h
index 768ce33bb20d..66d3981d4229 100644
--- a/sys/compat/linuxkpi/common/include/linux/workqueue.h
+++ b/sys/compat/linuxkpi/common/include/linux/workqueue.h
@@ -25,11 +25,9 @@
* 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.
- *
- * $FreeBSD$
*/
-#ifndef _LINUX_WORKQUEUE_H_
-#define _LINUX_WORKQUEUE_H_
+#ifndef _LINUXKPI_LINUX_WORKQUEUE_H_
+#define _LINUXKPI_LINUX_WORKQUEUE_H_
#include <linux/types.h>
#include <linux/kernel.h>
@@ -92,7 +90,7 @@ struct delayed_work {
struct {
struct callout callout;
struct mtx mtx;
- int expires;
+ unsigned long expires;
} timer;
};
@@ -190,6 +188,9 @@ do { \
#define delayed_work_pending(dwork) \
linux_work_pending(&(dwork)->work)
+#define cancel_work(work) \
+ linux_cancel_work(work)
+
#define cancel_delayed_work(dwork) \
linux_cancel_delayed_work(dwork)
@@ -244,7 +245,8 @@ extern struct workqueue_struct *linux_create_workqueue_common(const char *, int)
extern void linux_destroy_workqueue(struct workqueue_struct *);
extern bool linux_queue_work_on(int cpu, struct workqueue_struct *, struct work_struct *);
extern bool linux_queue_delayed_work_on(int cpu, struct workqueue_struct *,
- struct delayed_work *, unsigned delay);
+ struct delayed_work *, unsigned long delay);
+extern bool linux_cancel_work(struct work_struct *);
extern bool linux_cancel_delayed_work(struct delayed_work *);
extern bool linux_cancel_work_sync(struct work_struct *);
extern bool linux_cancel_delayed_work_sync(struct delayed_work *);
@@ -256,4 +258,10 @@ extern struct work_struct *linux_current_work(void);
extern bool linux_queue_rcu_work(struct workqueue_struct *wq, struct rcu_work *rwork);
extern bool linux_flush_rcu_work(struct rcu_work *rwork);
-#endif /* _LINUX_WORKQUEUE_H_ */
+static inline bool
+queue_work_node(int node __unused, struct workqueue_struct *wq, struct work_struct *work)
+{
+ return (queue_work(wq, work));
+}
+
+#endif /* _LINUXKPI_LINUX_WORKQUEUE_H_ */
diff --git a/sys/compat/linuxkpi/common/include/linux/ww_mutex.h b/sys/compat/linuxkpi/common/include/linux/ww_mutex.h
index 49bec6628486..9219755bb78e 100644
--- a/sys/compat/linuxkpi/common/include/linux/ww_mutex.h
+++ b/sys/compat/linuxkpi/common/include/linux/ww_mutex.h
@@ -22,11 +22,9 @@
* 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.
- *
- * $FreeBSD$
*/
-#ifndef _LINUX_WW_MUTEX_H_
-#define _LINUX_WW_MUTEX_H_
+#ifndef _LINUXKPI_LINUX_WW_MUTEX_H_
+#define _LINUXKPI_LINUX_WW_MUTEX_H_
#include <sys/param.h>
#include <sys/proc.h>
@@ -61,6 +59,8 @@ struct ww_mutex {
} \
SYSINIT(name, SI_SUB_LOCK, SI_ORDER_SECOND, name##_init, NULL)
+#define DEFINE_WD_CLASS(name) DEFINE_WW_CLASS(name)
+
#define ww_mutex_is_locked(_m) \
sx_xlocked(&(_m)->base.sx)
@@ -70,8 +70,13 @@ struct ww_mutex {
#define ww_mutex_lock_slow_interruptible(_m, _x) \
ww_mutex_lock_interruptible(_m, _x)
+#if defined(LINUXKPI_VERSION) && LINUXKPI_VERSION >= 51600
+static inline int __must_check
+ww_mutex_trylock(struct ww_mutex *lock, struct ww_acquire_ctx *ctx __unused)
+#else
static inline int __must_check
ww_mutex_trylock(struct ww_mutex *lock)
+#endif
{
return (mutex_trylock(&lock->base));
}
@@ -141,4 +146,4 @@ ww_acquire_done(struct ww_acquire_ctx *ctx)
{
}
-#endif /* _LINUX_WW_MUTEX_H_ */
+#endif /* _LINUXKPI_LINUX_WW_MUTEX_H_ */
diff --git a/sys/compat/linuxkpi/common/include/linux/xarray.h b/sys/compat/linuxkpi/common/include/linux/xarray.h
index 7427f6e4f9f9..fba36eea0ab5 100644
--- a/sys/compat/linuxkpi/common/include/linux/xarray.h
+++ b/sys/compat/linuxkpi/common/include/linux/xarray.h
@@ -22,15 +22,14 @@
* 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.
- *
- * $FreeBSD$
*/
-#ifndef _LINUX_XARRAY_H_
-#define _LINUX_XARRAY_H_
+#ifndef _LINUXKPI_LINUX_XARRAY_H_
+#define _LINUXKPI_LINUX_XARRAY_H_
#include <linux/gfp.h>
#include <linux/radix-tree.h>
#include <linux/err.h>
+#include <linux/kconfig.h>
#include <sys/lock.h>
#include <sys/mutex.h>
@@ -40,19 +39,24 @@
#define XA_FLAGS_ALLOC (1U << 0)
#define XA_FLAGS_LOCK_IRQ (1U << 1)
+#define XA_FLAGS_ALLOC1 (1U << 2)
#define XA_ERROR(x) \
ERR_PTR(x)
+#define xa_is_err(x) \
+ IS_ERR(x)
+
#define xa_limit_32b XA_LIMIT(0, 0xFFFFFFFF)
-#define XA_ASSERT_LOCKED(xa) mtx_assert(&(xa)->mtx, MA_OWNED)
-#define xa_lock(xa) mtx_lock(&(xa)->mtx)
-#define xa_unlock(xa) mtx_unlock(&(xa)->mtx)
+#define XA_ASSERT_LOCKED(xa) mtx_assert(&(xa)->xa_lock, MA_OWNED)
+#define xa_lock(xa) mtx_lock(&(xa)->xa_lock)
+#define xa_unlock(xa) mtx_unlock(&(xa)->xa_lock)
struct xarray {
- struct radix_tree_root root;
- struct mtx mtx; /* internal mutex */
+ struct radix_tree_root xa_head;
+ struct mtx xa_lock; /* internal mutex */
+ uint32_t xa_flags; /* see XA_FLAGS_XXX */
};
/*
@@ -63,6 +67,7 @@ void *xa_erase(struct xarray *, uint32_t);
void *xa_load(struct xarray *, uint32_t);
int xa_alloc(struct xarray *, uint32_t *, void *, uint32_t, gfp_t);
int xa_alloc_cyclic(struct xarray *, uint32_t *, void *, uint32_t, uint32_t *, gfp_t);
+int xa_alloc_cyclic_irq(struct xarray *, uint32_t *, void *, uint32_t, uint32_t *, gfp_t);
int xa_insert(struct xarray *, uint32_t, void *, gfp_t);
void *xa_store(struct xarray *, uint32_t, void *, gfp_t);
void xa_init_flags(struct xarray *, uint32_t);
@@ -85,6 +90,27 @@ void *__xa_store(struct xarray *, uint32_t, void *, gfp_t);
bool __xa_empty(struct xarray *);
void *__xa_next(struct xarray *, unsigned long *, bool);
+#define xa_store_irq(xa, index, ptr, gfp) \
+ xa_store((xa), (index), (ptr), (gfp))
+
+#define xa_erase_irq(xa, index) \
+ xa_erase((xa), (index))
+
+#define xa_lock_irq(xa) xa_lock(xa)
+#define xa_unlock_irq(xa) xa_unlock(xa)
+
+#define xa_lock_irqsave(xa, flags) \
+ do { \
+ xa_lock((xa)); \
+ flags = 0; \
+ } while (0)
+
+#define xa_unlock_irqrestore(xa, flags) \
+ do { \
+ xa_unlock((xa)); \
+ flags == 0; \
+ } while (0)
+
static inline int
xa_err(void *ptr)
{
@@ -120,4 +146,4 @@ xa_to_value(const void *e)
return (v >> 1);
}
-#endif /* _LINUX_XARRAY_H_ */
+#endif /* _LINUXKPI_LINUX_XARRAY_H_ */
diff --git a/sys/compat/linuxkpi/common/include/net/addrconf.h b/sys/compat/linuxkpi/common/include/net/addrconf.h
index 32bbaf176336..33c07792d807 100644
--- a/sys/compat/linuxkpi/common/include/net/addrconf.h
+++ b/sys/compat/linuxkpi/common/include/net/addrconf.h
@@ -26,12 +26,10 @@
* 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.
- *
- * $FreeBSD$
*/
-#ifndef __LKPI_NET_ADDRCONF_H
-#define __LKPI_NET_ADDRCONF_H
+#ifndef _LINUXKPI_NET_ADDRCONF_H
+#define _LINUXKPI_NET_ADDRCONF_H
#include <sys/types.h>
#include <netinet/in.h>
@@ -48,4 +46,4 @@ addrconf_addr_solict_mult(struct in6_addr *ia6, struct in6_addr *sol)
sol->s6_addr8[12] = 0xff;
}
-#endif /* __LKPI_NET_ADDRCONF_H */
+#endif /* _LINUXKPI_NET_ADDRCONF_H */
diff --git a/sys/compat/linuxkpi/common/include/net/cfg80211.h b/sys/compat/linuxkpi/common/include/net/cfg80211.h
new file mode 100644
index 000000000000..f769cfdd4075
--- /dev/null
+++ b/sys/compat/linuxkpi/common/include/net/cfg80211.h
@@ -0,0 +1,2259 @@
+/*-
+ * Copyright (c) 2020-2025 The FreeBSD Foundation
+ * Copyright (c) 2021-2022 Bjoern A. Zeeb
+ *
+ * This software was developed by Björn Zeeb under sponsorship from
+ * the FreeBSD Foundation.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``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 OR CONTRIBUTORS 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.
+ */
+
+#ifndef _LINUXKPI_NET_CFG80211_H
+#define _LINUXKPI_NET_CFG80211_H
+
+#include <linux/types.h>
+#include <linux/nl80211.h>
+#include <linux/ieee80211.h>
+#include <linux/mutex.h>
+#include <linux/if_ether.h>
+#include <linux/ethtool.h>
+#include <linux/debugfs.h>
+#include <linux/device.h>
+#include <linux/netdevice.h>
+#include <linux/random.h>
+#include <linux/skbuff.h>
+#include <linux/timer.h>
+#include <linux/workqueue.h>
+#include <net/regulatory.h>
+
+#include <net80211/ieee80211.h>
+
+/* linux_80211.c */
+extern int linuxkpi_debug_80211;
+#ifndef D80211_TODO
+#define D80211_TODO 0x1
+#endif
+#ifndef D80211_IMPROVE
+#define D80211_IMPROVE 0x2
+#endif
+#define TODO(fmt, ...) if (linuxkpi_debug_80211 & D80211_TODO) \
+ printf("%s:%d: XXX LKPI80211 TODO " fmt "\n", __func__, __LINE__, ##__VA_ARGS__)
+#define IMPROVE(fmt, ...) if (linuxkpi_debug_80211 & D80211_IMPROVE) \
+ printf("%s:%d: XXX LKPI80211 IMPROVE " fmt "\n", __func__, __LINE__, ##__VA_ARGS__)
+
+enum rfkill_hard_block_reasons {
+ RFKILL_HARD_BLOCK_NOT_OWNER = BIT(0),
+};
+
+#define WIPHY_PARAM_FRAG_THRESHOLD __LINE__ /* TODO FIXME brcmfmac */
+#define WIPHY_PARAM_RETRY_LONG __LINE__ /* TODO FIXME brcmfmac */
+#define WIPHY_PARAM_RETRY_SHORT __LINE__ /* TODO FIXME brcmfmac */
+#define WIPHY_PARAM_RTS_THRESHOLD __LINE__ /* TODO FIXME brcmfmac */
+
+#define CFG80211_SIGNAL_TYPE_MBM __LINE__ /* TODO FIXME brcmfmac */
+
+#define UPDATE_ASSOC_IES 1
+
+#define IEEE80211_MAX_CHAINS 4 /* net80211: IEEE80211_MAX_CHAINS copied */
+
+enum cfg80211_rate_info_flags {
+ RATE_INFO_FLAGS_MCS = BIT(0),
+ RATE_INFO_FLAGS_VHT_MCS = BIT(1),
+ RATE_INFO_FLAGS_SHORT_GI = BIT(2),
+ RATE_INFO_FLAGS_HE_MCS = BIT(4),
+ RATE_INFO_FLAGS_EHT_MCS = BIT(7),
+ /* Max 8 bits as used in struct rate_info. */
+};
+
+#define CFG80211_RATE_INFO_FLAGS_BITS \
+ "\20\1MCS\2VHT_MCS\3SGI\5HE_MCS\10EHT_MCS"
+
+extern const uint8_t rfc1042_header[6];
+extern const uint8_t bridge_tunnel_header[6];
+
+enum ieee80211_privacy {
+ IEEE80211_PRIVACY_ANY,
+};
+
+enum ieee80211_bss_type {
+ IEEE80211_BSS_TYPE_ANY,
+};
+
+enum cfg80211_bss_frame_type {
+ CFG80211_BSS_FTYPE_UNKNOWN,
+ CFG80211_BSS_FTYPE_BEACON,
+ CFG80211_BSS_FTYPE_PRESP,
+};
+
+enum ieee80211_channel_flags {
+ IEEE80211_CHAN_DISABLED = BIT(0),
+ IEEE80211_CHAN_INDOOR_ONLY = BIT(1),
+ IEEE80211_CHAN_IR_CONCURRENT = BIT(2),
+ IEEE80211_CHAN_RADAR = BIT(3),
+ IEEE80211_CHAN_NO_IR = BIT(4),
+ IEEE80211_CHAN_NO_HT40MINUS = BIT(5),
+ IEEE80211_CHAN_NO_HT40PLUS = BIT(6),
+ IEEE80211_CHAN_NO_80MHZ = BIT(7),
+ IEEE80211_CHAN_NO_160MHZ = BIT(8),
+ IEEE80211_CHAN_NO_OFDM = BIT(9),
+ IEEE80211_CHAN_NO_6GHZ_VLP_CLIENT = BIT(10),
+ IEEE80211_CHAN_NO_6GHZ_AFC_CLIENT = BIT(11),
+ IEEE80211_CHAN_PSD = BIT(12),
+ IEEE80211_CHAN_ALLOW_6GHZ_VLP_AP = BIT(13),
+ IEEE80211_CHAN_CAN_MONITOR = BIT(14),
+};
+#define IEEE80211_CHAN_NO_HT40 (IEEE80211_CHAN_NO_HT40MINUS|IEEE80211_CHAN_NO_HT40PLUS)
+
+struct ieee80211_txrx_stypes {
+ uint16_t tx;
+ uint16_t rx;
+};
+
+/*
+ * net80211 has an ieee80211_channel as well; we use the linuxkpi_ version
+ * interally in LinuxKPI and re-define ieee80211_channel for the drivers
+ * at the end of the file.
+ */
+struct linuxkpi_ieee80211_channel {
+ uint32_t center_freq;
+ uint16_t hw_value;
+ enum ieee80211_channel_flags flags;
+ enum nl80211_band band;
+ bool beacon_found;
+ enum nl80211_dfs_state dfs_state;
+ unsigned int dfs_cac_ms;
+ int max_antenna_gain;
+ int max_power;
+ int max_reg_power;
+ uint32_t orig_flags;
+ int orig_mpwr;
+};
+
+struct cfg80211_bitrate_mask {
+ /* TODO FIXME */
+ struct {
+ uint32_t legacy;
+ uint8_t ht_mcs[IEEE80211_HT_MCS_MASK_LEN];
+ uint16_t vht_mcs[8];
+ uint16_t he_mcs[8];
+ enum nl80211_txrate_gi gi;
+ enum nl80211_he_gi he_gi;
+ uint8_t he_ltf; /* XXX enum? */
+ } control[NUM_NL80211_BANDS];
+};
+
+enum rate_info_bw {
+ RATE_INFO_BW_20 = 0,
+ RATE_INFO_BW_5,
+ RATE_INFO_BW_10,
+ RATE_INFO_BW_40,
+ RATE_INFO_BW_80,
+ RATE_INFO_BW_160,
+ RATE_INFO_BW_HE_RU,
+ RATE_INFO_BW_320,
+ RATE_INFO_BW_EHT_RU,
+};
+
+struct rate_info {
+ uint8_t flags; /* enum cfg80211_rate_info_flags */
+ uint8_t bw; /* enum rate_info_bw */
+ uint16_t legacy;
+ uint8_t mcs;
+ uint8_t nss;
+ uint8_t he_dcm;
+ uint8_t he_gi;
+ uint8_t he_ru_alloc;
+ uint8_t eht_gi;
+};
+
+struct ieee80211_rate {
+ uint32_t flags; /* enum ieee80211_rate_flags */
+ uint16_t bitrate;
+ uint16_t hw_value;
+ uint16_t hw_value_short;
+};
+
+struct ieee80211_sta_ht_cap {
+ bool ht_supported;
+ uint8_t ampdu_density;
+ uint8_t ampdu_factor;
+ uint16_t cap;
+ struct ieee80211_mcs_info mcs;
+};
+
+/* XXX net80211 calls these IEEE80211_VHTCAP_* */
+#define IEEE80211_VHT_CAP_MAX_MPDU_LENGTH_3895 0x00000000 /* IEEE80211_VHTCAP_MAX_MPDU_LENGTH_3895 */
+#define IEEE80211_VHT_CAP_MAX_MPDU_LENGTH_7991 0x00000001 /* IEEE80211_VHTCAP_MAX_MPDU_LENGTH_7991 */
+#define IEEE80211_VHT_CAP_MAX_MPDU_LENGTH_11454 0x00000002 /* IEEE80211_VHTCAP_MAX_MPDU_LENGTH_11454 */
+#define IEEE80211_VHT_CAP_MAX_MPDU_MASK 0x00000003 /* IEEE80211_VHTCAP_MAX_MPDU_MASK */
+
+#define IEEE80211_VHT_CAP_SUPP_CHAN_WIDTH_160MHZ (IEEE80211_VHTCAP_SUPP_CHAN_WIDTH_160MHZ << IEEE80211_VHTCAP_SUPP_CHAN_WIDTH_MASK_S)
+#define IEEE80211_VHT_CAP_SUPP_CHAN_WIDTH_160_80PLUS80MHZ (IEEE80211_VHTCAP_SUPP_CHAN_WIDTH_160_80P80MHZ << IEEE80211_VHTCAP_SUPP_CHAN_WIDTH_MASK_S)
+#define IEEE80211_VHT_CAP_SUPP_CHAN_WIDTH_MASK IEEE80211_VHTCAP_SUPP_CHAN_WIDTH_MASK
+
+#define IEEE80211_VHT_CAP_RXLDPC 0x00000010 /* IEEE80211_VHTCAP_RXLDPC */
+
+#define IEEE80211_VHT_CAP_SHORT_GI_80 0x00000020 /* IEEE80211_VHTCAP_SHORT_GI_80 */
+#define IEEE80211_VHT_CAP_SHORT_GI_160 0x00000040 /* IEEE80211_VHTCAP_SHORT_GI_160 */
+
+#define IEEE80211_VHT_CAP_TXSTBC 0x00000080 /* IEEE80211_VHTCAP_TXSTBC */
+
+#define IEEE80211_VHT_CAP_RXSTBC_1 0x00000100 /* IEEE80211_VHTCAP_RXSTBC_1 */
+#define IEEE80211_VHT_CAP_RXSTBC_MASK 0x00000700 /* IEEE80211_VHTCAP_RXSTBC_MASK */
+
+#define IEEE80211_VHT_CAP_SU_BEAMFORMER_CAPABLE 0x00000800 /* IEEE80211_VHTCAP_SU_BEAMFORMER_CAPABLE */
+
+#define IEEE80211_VHT_CAP_SU_BEAMFORMEE_CAPABLE 0x00001000 /* IEEE80211_VHTCAP_SU_BEAMFORMEE_CAPABLE */
+
+#define IEEE80211_VHT_CAP_MU_BEAMFORMER_CAPABLE 0x00080000 /* IEEE80211_VHTCAP_MU_BEAMFORMER_CAPABLE */
+
+#define IEEE80211_VHT_CAP_MU_BEAMFORMEE_CAPABLE 0x00100000 /* IEEE80211_VHTCAP_MU_BEAMFORMEE_CAPABLE */
+
+#define IEEE80211_VHT_CAP_BEAMFORMEE_STS_SHIFT 13 /* IEEE80211_VHTCAP_BEAMFORMEE_STS_SHIFT */
+#define IEEE80211_VHT_CAP_BEAMFORMEE_STS_MASK (7 << IEEE80211_VHT_CAP_BEAMFORMEE_STS_SHIFT) /* IEEE80211_VHTCAP_BEAMFORMEE_STS_MASK */
+
+#define IEEE80211_VHT_CAP_HTC_VHT 0x00400000 /* IEEE80211_VHTCAP_HTC_VHT */
+
+#define IEEE80211_VHT_CAP_RX_ANTENNA_PATTERN 0x10000000 /* IEEE80211_VHTCAP_RX_ANTENNA_PATTERN */
+#define IEEE80211_VHT_CAP_TX_ANTENNA_PATTERN 0x20000000 /* IEEE80211_VHTCAP_TX_ANTENNA_PATTERN */
+
+#define IEEE80211_VHT_CAP_VHT_LINK_ADAPTATION_VHT_MRQ_MFB 0x0c000000 /* IEEE80211_VHTCAP_VHT_LINK_ADAPTATION_VHT_MRQ_MFB */
+
+#define IEEE80211_VHT_CAP_SOUNDING_DIMENSIONS_SHIFT 16 /* IEEE80211_VHTCAP_SOUNDING_DIMENSIONS_SHIFT */
+#define IEEE80211_VHT_CAP_SOUNDING_DIMENSIONS_MASK \
+ (7 << IEEE80211_VHTCAP_SOUNDING_DIMENSIONS_SHIFT) /* IEEE80211_VHTCAP_SOUNDING_DIMENSIONS_MASK */
+
+#define IEEE80211_VHT_CAP_MAX_A_MPDU_LENGTH_EXPONENT_SHIFT 23 /* IEEE80211_VHTCAP_MAX_A_MPDU_LENGTH_EXPONENT_SHIFT */
+#define IEEE80211_VHT_CAP_MAX_A_MPDU_LENGTH_EXPONENT_MASK \
+ (7 << IEEE80211_VHT_CAP_MAX_A_MPDU_LENGTH_EXPONENT_SHIFT) /* IEEE80211_VHTCAP_MAX_A_MPDU_LENGTH_EXPONENT_MASK */
+
+#define IEEE80211_VHT_CAP_EXT_NSS_BW_MASK IEEE80211_VHTCAP_EXT_NSS_BW
+#define IEEE80211_VHT_CAP_EXT_NSS_BW_SHIFT IEEE80211_VHTCAP_EXT_NSS_BW_S
+
+struct ieee80211_sta_vht_cap {
+ /* TODO FIXME */
+ bool vht_supported;
+ uint32_t cap;
+ struct ieee80211_vht_mcs_info vht_mcs;
+};
+
+enum ieee80211_vht_opmode {
+ IEEE80211_OPMODE_NOTIF_RX_NSS_SHIFT = 4,
+};
+
+struct cfg80211_bss_ies {
+ uint8_t *data;
+ size_t len;
+};
+
+struct cfg80211_bss {
+ /* XXX TODO */
+ struct cfg80211_bss_ies *ies;
+ struct cfg80211_bss_ies *beacon_ies;
+ uint64_t ts_boottime;
+ int32_t signal;
+};
+
+struct cfg80211_connect_resp_params {
+ /* XXX TODO */
+ uint8_t *bssid;
+ const uint8_t *req_ie;
+ const uint8_t *resp_ie;
+ uint32_t req_ie_len;
+ uint32_t resp_ie_len;
+ int status;
+ struct {
+ const uint8_t *addr;
+ const uint8_t *bssid;
+ struct cfg80211_bss *bss;
+ uint16_t status;
+ } links[IEEE80211_MLD_MAX_NUM_LINKS];
+};
+
+struct cfg80211_inform_bss {
+ /* XXX TODO */
+ int boottime_ns, scan_width, signal;
+ struct linuxkpi_ieee80211_channel *chan;
+};
+
+struct cfg80211_roam_info {
+ /* XXX TODO */
+ uint8_t *bssid;
+ const uint8_t *req_ie;
+ const uint8_t *resp_ie;
+ uint32_t req_ie_len;
+ uint32_t resp_ie_len;
+ struct linuxkpi_ieee80211_channel *channel;
+ struct {
+ const uint8_t *addr;
+ const uint8_t *bssid;
+ struct cfg80211_bss *bss;
+ struct linuxkpi_ieee80211_channel *channel;
+ } links[IEEE80211_MLD_MAX_NUM_LINKS];
+};
+
+struct cfg80211_chan_def {
+ /* XXX TODO */
+ struct linuxkpi_ieee80211_channel *chan;
+ enum nl80211_chan_width width;
+ uint32_t center_freq1;
+ uint32_t center_freq2;
+ uint16_t punctured;
+};
+
+struct cfg80211_ftm_responder_stats {
+ /* XXX TODO */
+ int asap_num, failed_num, filled, non_asap_num, out_of_window_triggers_num, partial_num, reschedule_requests_num, success_num, total_duration_ms, unknown_triggers_num;
+};
+
+struct cfg80211_pmsr_capabilities {
+ /* XXX TODO */
+ int max_peers, randomize_mac_addr, report_ap_tsf;
+ struct {
+ int asap, bandwidths, max_bursts_exponent, max_ftms_per_burst, non_asap, non_trigger_based, preambles, request_civicloc, request_lci, supported, trigger_based;
+ } ftm;
+};
+
+struct cfg80211_pmsr_ftm_request {
+ /* XXX TODO */
+ int asap, burst_period, ftmr_retries, ftms_per_burst, non_trigger_based, num_bursts_exp, request_civicloc, request_lci, trigger_based;
+ uint8_t bss_color;
+ bool lmr_feedback;
+};
+
+struct cfg80211_pmsr_request_peer {
+ /* XXX TODO */
+ struct cfg80211_chan_def chandef;
+ struct cfg80211_pmsr_ftm_request ftm;
+ uint8_t addr[ETH_ALEN];
+ int report_ap_tsf;
+};
+
+struct cfg80211_pmsr_request {
+ /* XXX TODO */
+ int cookie, n_peers, timeout;
+ uint8_t mac_addr[ETH_ALEN], mac_addr_mask[ETH_ALEN];
+ struct cfg80211_pmsr_request_peer peers[];
+};
+
+struct cfg80211_pmsr_ftm_result {
+ /* XXX TODO */
+ int burst_index, busy_retry_time, failure_reason;
+ int num_ftmr_successes, rssi_avg, rssi_avg_valid, rssi_spread, rssi_spread_valid, rtt_avg, rtt_avg_valid, rtt_spread, rtt_spread_valid, rtt_variance, rtt_variance_valid;
+ uint8_t *lci;
+ uint8_t *civicloc;
+ int lci_len;
+ int civicloc_len;
+};
+
+struct cfg80211_pmsr_result {
+ /* XXX TODO */
+ int ap_tsf, ap_tsf_valid, final, host_time, status, type;
+ uint8_t addr[ETH_ALEN];
+ struct cfg80211_pmsr_ftm_result ftm;
+};
+
+struct cfg80211_sar_freq_ranges {
+ uint32_t start_freq;
+ uint32_t end_freq;
+};
+
+struct cfg80211_sar_sub_specs {
+ uint32_t freq_range_index;
+ int power;
+};
+
+struct cfg80211_sar_specs {
+ enum nl80211_sar_type type;
+ uint32_t num_sub_specs;
+ struct cfg80211_sar_sub_specs sub_specs[];
+};
+
+struct cfg80211_sar_capa {
+ enum nl80211_sar_type type;
+ uint32_t num_freq_ranges;
+ const struct cfg80211_sar_freq_ranges *freq_ranges;
+};
+
+struct cfg80211_ssid {
+ int ssid_len;
+ uint8_t ssid[IEEE80211_MAX_SSID_LEN];
+};
+
+struct cfg80211_scan_6ghz_params {
+ /* XXX TODO */
+ uint8_t *bssid;
+ int channel_idx, psc_no_listen, short_ssid, short_ssid_valid, unsolicited_probe, psd_20;
+};
+
+struct cfg80211_match_set {
+ uint8_t bssid[ETH_ALEN];
+ struct cfg80211_ssid ssid;
+ int rssi_thold;
+};
+
+struct cfg80211_scan_request {
+ /* XXX TODO */
+ bool no_cck;
+ bool scan_6ghz;
+ bool duration_mandatory;
+ bool first_part;
+ int8_t tsf_report_link_id;
+ uint16_t duration;
+ uint32_t flags;
+ struct wireless_dev *wdev;
+ struct wiphy *wiphy;
+ uint64_t scan_start;
+ uint32_t rates[NUM_NL80211_BANDS];
+ int ie_len;
+ uint8_t *ie;
+ uint8_t mac_addr[ETH_ALEN], mac_addr_mask[ETH_ALEN];
+ uint8_t bssid[ETH_ALEN];
+ int n_ssids;
+ int n_6ghz_params;
+ int n_channels;
+ struct cfg80211_ssid *ssids;
+ struct cfg80211_scan_6ghz_params *scan_6ghz_params;
+ struct linuxkpi_ieee80211_channel *channels[0];
+};
+
+struct cfg80211_sched_scan_plan {
+ /* XXX TODO */
+ int interval, iterations;
+};
+
+struct cfg80211_sched_scan_request {
+ /* XXX TODO */
+ int delay, flags;
+ uint8_t mac_addr[ETH_ALEN], mac_addr_mask[ETH_ALEN];
+ uint64_t reqid;
+ int n_match_sets;
+ int n_scan_plans;
+ int n_ssids;
+ int n_channels;
+ int ie_len;
+ uint8_t *ie;
+ struct cfg80211_match_set *match_sets;
+ struct cfg80211_sched_scan_plan *scan_plans;
+ struct cfg80211_ssid *ssids;
+ struct linuxkpi_ieee80211_channel *channels[0];
+};
+
+struct cfg80211_scan_info {
+ uint64_t scan_start_tsf;
+ uint8_t tsf_bssid[ETH_ALEN];
+ bool aborted;
+};
+
+struct cfg80211_beacon_data {
+ /* XXX TODO */
+ const uint8_t *head;
+ const uint8_t *tail;
+ uint32_t head_len;
+ uint32_t tail_len;
+ const uint8_t *proberesp_ies;
+ const uint8_t *assocresp_ies;
+ uint32_t proberesp_ies_len;
+ uint32_t assocresp_ies_len;
+};
+
+struct cfg80211_ap_update {
+ /* XXX TODO */
+ struct cfg80211_beacon_data beacon;
+};
+
+struct cfg80211_crypto_settings {
+ /* XXX TODO */
+ enum nl80211_wpa_versions wpa_versions;
+ uint32_t cipher_group; /* WLAN_CIPHER_SUITE_* */
+ uint32_t *akm_suites;
+ uint32_t *ciphers_pairwise;
+ const uint8_t *sae_pwd;
+ const uint8_t *psk;
+ int n_akm_suites;
+ int n_ciphers_pairwise;
+ int sae_pwd_len;
+};
+
+struct cfg80211_ap_settings {
+ /* XXX TODO */
+ int auth_type, beacon_interval, dtim_period, hidden_ssid, inactivity_timeout;
+ const uint8_t *ssid;
+ size_t ssid_len;
+ struct cfg80211_beacon_data beacon;
+ struct cfg80211_chan_def chandef;
+ struct cfg80211_crypto_settings crypto;
+};
+
+struct cfg80211_bss_selection {
+ /* XXX TODO */
+ enum nl80211_bss_select_attr behaviour;
+ union {
+ enum nl80211_band band_pref;
+ struct {
+ enum nl80211_band band;
+ uint8_t delta;
+ } adjust;
+ } param;
+};
+
+struct cfg80211_connect_params {
+ /* XXX TODO */
+ struct linuxkpi_ieee80211_channel *channel;
+ struct linuxkpi_ieee80211_channel *channel_hint;
+ uint8_t *bssid;
+ uint8_t *bssid_hint;
+ const uint8_t *ie;
+ const uint8_t *ssid;
+ uint32_t ie_len;
+ uint32_t ssid_len;
+ const void *key;
+ uint32_t key_len;
+ int auth_type, key_idx, privacy, want_1x;
+ struct cfg80211_bss_selection bss_select;
+ struct cfg80211_crypto_settings crypto;
+};
+
+enum bss_param_flags { /* Used as bitflags. XXX FIXME values? */
+ BSS_PARAM_FLAGS_CTS_PROT = 0x01,
+ BSS_PARAM_FLAGS_SHORT_PREAMBLE = 0x02,
+ BSS_PARAM_FLAGS_SHORT_SLOT_TIME = 0x04,
+};
+
+struct cfg80211_ibss_params {
+ /* XXX TODO */
+ int basic_rates, beacon_interval;
+ int channel_fixed, ie, ie_len, privacy;
+ int dtim_period;
+ uint8_t *ssid;
+ uint8_t *bssid;
+ int ssid_len;
+ struct cfg80211_chan_def chandef;
+ enum bss_param_flags flags;
+};
+
+struct cfg80211_mgmt_tx_params {
+ /* XXX TODO */
+ struct linuxkpi_ieee80211_channel *chan;
+ const uint8_t *buf;
+ size_t len;
+ int wait;
+};
+
+struct cfg80211_external_auth_params {
+ uint8_t bssid[ETH_ALEN];
+ uint16_t status;
+ enum nl80211_external_auth_action action;
+ unsigned int key_mgmt_suite;
+ struct cfg80211_ssid ssid;
+};
+
+struct cfg80211_pmk_conf {
+ /* XXX TODO */
+ const uint8_t *pmk;
+ uint8_t pmk_len;
+};
+
+struct cfg80211_pmksa {
+ /* XXX TODO */
+ const uint8_t *bssid;
+ const uint8_t *pmkid;
+ const uint8_t *ssid;
+ size_t ssid_len;
+};
+
+struct station_del_parameters {
+ /* XXX TODO */
+ const uint8_t *mac;
+ uint32_t reason_code; /* elsewhere uint16_t? */
+};
+
+struct station_info {
+ uint64_t filled; /* enum nl80211_sta_info */
+ uint32_t connected_time;
+ uint32_t inactive_time;
+
+ uint64_t rx_bytes;
+ uint32_t rx_packets;
+ uint32_t rx_dropped_misc;
+
+ uint64_t rx_duration;
+ uint32_t rx_beacon;
+ uint8_t rx_beacon_signal_avg;
+
+ int8_t signal;
+ int8_t signal_avg;
+ int8_t ack_signal;
+ int8_t avg_ack_signal;
+
+ /* gap */
+ int generation;
+
+ uint64_t tx_bytes;
+ uint32_t tx_packets;
+ uint32_t tx_failed;
+ uint64_t tx_duration;
+ uint32_t tx_retries;
+
+ int chains;
+ uint8_t chain_signal[IEEE80211_MAX_CHAINS];
+ uint8_t chain_signal_avg[IEEE80211_MAX_CHAINS];
+
+ uint8_t *assoc_req_ies;
+ size_t assoc_req_ies_len;
+
+ struct rate_info rxrate;
+ struct rate_info txrate;
+ struct cfg80211_ibss_params bss_param;
+ struct nl80211_sta_flag_update sta_flags;
+};
+
+struct station_parameters {
+ /* XXX TODO */
+ int sta_flags_mask, sta_flags_set;
+};
+
+struct key_params {
+ /* XXX TODO */
+ const uint8_t *key;
+ const uint8_t *seq;
+ int key_len;
+ int seq_len;
+ uint32_t cipher; /* WLAN_CIPHER_SUITE_* */
+};
+
+struct mgmt_frame_regs {
+ /* XXX TODO */
+ int interface_stypes;
+};
+
+struct vif_params {
+ /* XXX TODO */
+ uint8_t macaddr[ETH_ALEN];
+};
+
+/* That the world needs so many different structs for this is amazing. */
+struct mac_address {
+ uint8_t addr[ETH_ALEN];
+};
+
+struct ieee80211_reg_rule {
+ /* TODO FIXME */
+ uint32_t flags;
+ int dfs_cac_ms;
+ struct freq_range {
+ int start_freq_khz;
+ int end_freq_khz;
+ int max_bandwidth_khz;
+ } freq_range;
+ struct power_rule {
+ int max_antenna_gain;
+ int max_eirp;
+ } power_rule;
+};
+
+struct linuxkpi_ieee80211_regdomain {
+ /* TODO FIXME */
+ uint8_t alpha2[2];
+ int dfs_region;
+ int n_reg_rules;
+ struct ieee80211_reg_rule reg_rules[];
+};
+
+#define IEEE80211_EHT_MAC_CAP0_EPCS_PRIO_ACCESS 0x01
+#define IEEE80211_EHT_MAC_CAP0_MAX_MPDU_LEN_11454 0x02
+#define IEEE80211_EHT_MAC_CAP0_MAX_MPDU_LEN_MASK 0x03
+#define IEEE80211_EHT_MAC_CAP0_OM_CONTROL 0x04
+#define IEEE80211_EHT_MAC_CAP0_TRIG_TXOP_SHARING_MODE1 0x05
+#define IEEE80211_EHT_MAC_CAP0_TRIG_TXOP_SHARING_MODE2 0x06
+#define IEEE80211_EHT_MAC_CAP0_MAX_MPDU_LEN_7991 0x07
+#define IEEE80211_EHT_MAC_CAP0_SCS_TRAFFIC_DESC 0x08
+
+#define IEEE80211_EHT_MAC_CAP1_MAX_AMPDU_LEN_MASK 0x01
+
+#define IEEE80211_EHT_MCS_NSS_RX 0x01
+#define IEEE80211_EHT_MCS_NSS_TX 0x02
+
+#define IEEE80211_EHT_PHY_CAP0_242_TONE_RU_GT20MHZ 0x01
+#define IEEE80211_EHT_PHY_CAP0_320MHZ_IN_6GHZ 0x02
+#define IEEE80211_EHT_PHY_CAP0_BEAMFORMEE_SS_80MHZ_MASK 0x03
+#define IEEE80211_EHT_PHY_CAP0_NDP_4_EHT_LFT_32_GI 0x04
+#define IEEE80211_EHT_PHY_CAP0_PARTIAL_BW_UL_MU_MIMO 0x05
+#define IEEE80211_EHT_PHY_CAP0_SU_BEAMFORMEE 0x06
+#define IEEE80211_EHT_PHY_CAP0_SU_BEAMFORMER 0x07
+
+#define IEEE80211_EHT_PHY_CAP1_BEAMFORMEE_SS_160MHZ_MASK 0x01
+#define IEEE80211_EHT_PHY_CAP1_BEAMFORMEE_SS_320MHZ_MASK 0x02
+#define IEEE80211_EHT_PHY_CAP1_BEAMFORMEE_SS_80MHZ_MASK 0x03
+
+#define IEEE80211_EHT_PHY_CAP2_SOUNDING_DIM_80MHZ_MASK 0x01
+#define IEEE80211_EHT_PHY_CAP2_SOUNDING_DIM_160MHZ_MASK 0x02
+#define IEEE80211_EHT_PHY_CAP2_SOUNDING_DIM_320MHZ_MASK 0x03
+
+#define IEEE80211_EHT_PHY_CAP3_CODEBOOK_4_2_SU_FDBK 0x01
+#define IEEE80211_EHT_PHY_CAP3_CODEBOOK_7_5_MU_FDBK 0x02
+#define IEEE80211_EHT_PHY_CAP3_NG_16_MU_FEEDBACK 0x03
+#define IEEE80211_EHT_PHY_CAP3_NG_16_SU_FEEDBACK 0x04
+#define IEEE80211_EHT_PHY_CAP3_TRIG_CQI_FDBK 0x05
+#define IEEE80211_EHT_PHY_CAP3_TRIG_MU_BF_PART_BW_FDBK 0x06
+#define IEEE80211_EHT_PHY_CAP3_TRIG_SU_BF_FDBK 0x07
+#define IEEE80211_EHT_PHY_CAP3_SOUNDING_DIM_320MHZ_MASK 0x08
+
+#define IEEE80211_EHT_PHY_CAP4_EHT_MU_PPDU_4_EHT_LTF_08_GI 0x01
+#define IEEE80211_EHT_PHY_CAP4_PART_BW_DL_MU_MIMO 0x02
+#define IEEE80211_EHT_PHY_CAP4_POWER_BOOST_FACT_SUPP 0x03
+#define IEEE80211_EHT_PHY_CAP4_MAX_NC_MASK 0x04
+
+#define IEEE80211_EHT_PHY_CAP5_COMMON_NOMINAL_PKT_PAD_0US 0x01
+#define IEEE80211_EHT_PHY_CAP5_COMMON_NOMINAL_PKT_PAD_16US 0x02
+#define IEEE80211_EHT_PHY_CAP5_COMMON_NOMINAL_PKT_PAD_20US 0x03
+#define IEEE80211_EHT_PHY_CAP5_COMMON_NOMINAL_PKT_PAD_8US 0x04
+#define IEEE80211_EHT_PHY_CAP5_COMMON_NOMINAL_PKT_PAD_MASK 0x05
+#define IEEE80211_EHT_PHY_CAP5_NON_TRIG_CQI_FEEDBACK 0x06
+#define IEEE80211_EHT_PHY_CAP5_PPE_THRESHOLD_PRESENT 0x07
+#define IEEE80211_EHT_PHY_CAP5_RX_LESS_242_TONE_RU_SUPP 0x08
+#define IEEE80211_EHT_PHY_CAP5_TX_LESS_242_TONE_RU_SUPP 0x09
+#define IEEE80211_EHT_PHY_CAP5_MAX_NUM_SUPP_EHT_LTF_MASK 0x0a
+#define IEEE80211_EHT_PHY_CAP5_SUPP_EXTRA_EHT_LTF 0x0b
+
+#define IEEE80211_EHT_PHY_CAP6_EHT_DUP_6GHZ_SUPP 0x01
+#define IEEE80211_EHT_PHY_CAP6_MCS15_SUPP_MASK 0x02
+#define IEEE80211_EHT_PHY_CAP6_MAX_NUM_SUPP_EHT_LTF_MASK 0x03
+
+#define IEEE80211_EHT_PHY_CAP7_MU_BEAMFORMER_80MHZ 0x01
+#define IEEE80211_EHT_PHY_CAP7_MU_BEAMFORMER_160MHZ 0x02
+#define IEEE80211_EHT_PHY_CAP7_MU_BEAMFORMER_320MHZ 0x03
+#define IEEE80211_EHT_PHY_CAP7_NON_OFDMA_UL_MU_MIMO_80MHZ 0x04
+#define IEEE80211_EHT_PHY_CAP7_NON_OFDMA_UL_MU_MIMO_160MHZ 0x05
+#define IEEE80211_EHT_PHY_CAP7_NON_OFDMA_UL_MU_MIMO_320MHZ 0x06
+
+#define IEEE80211_EHT_PHY_CAP8_RX_1024QAM_WIDER_BW_DL_OFDMA 0x01
+#define IEEE80211_EHT_PHY_CAP8_RX_4096QAM_WIDER_BW_DL_OFDMA 0x02
+
+#define IEEE80211_EHT_PPE_THRES_INFO_HEADER_SIZE 0x01
+#define IEEE80211_EHT_PPE_THRES_NSS_MASK 0x02
+#define IEEE80211_EHT_PPE_THRES_RU_INDEX_BITMASK_MASK 0x03
+#define IEEE80211_EHT_PPE_THRES_INFO_PPET_SIZE 0x04
+
+#define IEEE80211_EML_CAP_EMLSR_SUPP 0x01
+#define IEEE80211_EML_CAP_TRANSITION_TIMEOUT 0x02
+#define IEEE80211_EML_CAP_TRANSITION_TIMEOUT_128TU 0x04
+#define IEEE80211_EML_CAP_EMLSR_PADDING_DELAY 0x08
+#define IEEE80211_EML_CAP_EMLSR_PADDING_DELAY_32US 0x10
+#define IEEE80211_EML_CAP_EMLSR_PADDING_DELAY_256US 0x10
+#define IEEE80211_EML_CAP_EMLSR_TRANSITION_DELAY 0x20
+#define IEEE80211_EML_CAP_EMLSR_TRANSITION_DELAY_64US 0x40
+#define IEEE80211_EML_CAP_EMLSR_TRANSITION_DELAY_256US 0x40
+
+#define VENDOR_CMD_RAW_DATA (void *)(uintptr_t)(-ENOENT)
+
+/* net80211::net80211_he_cap */
+struct ieee80211_sta_he_cap {
+ bool has_he;
+ struct ieee80211_he_cap_elem he_cap_elem;
+ struct ieee80211_he_mcs_nss_supp he_mcs_nss_supp;
+ uint8_t ppe_thres[IEEE80211_HE_CAP_PPE_THRES_MAX];
+};
+
+struct cfg80211_he_bss_color {
+ int color, enabled;
+};
+
+struct ieee80211_he_obss_pd {
+ bool enable;
+ uint8_t min_offset;
+ uint8_t max_offset;
+ uint8_t non_srg_max_offset;
+ uint8_t sr_ctrl;
+ uint8_t bss_color_bitmap[8];
+ uint8_t partial_bssid_bitmap[8];
+};
+
+struct ieee80211_eht_mcs_nss_supp_20mhz_only {
+ union {
+ struct {
+ uint8_t rx_tx_mcs7_max_nss;
+ uint8_t rx_tx_mcs9_max_nss;
+ uint8_t rx_tx_mcs11_max_nss;
+ uint8_t rx_tx_mcs13_max_nss;
+ };
+ uint8_t rx_tx_max_nss[4];
+ };
+};
+
+struct ieee80211_eht_mcs_nss_supp_bw {
+ union {
+ struct {
+ uint8_t rx_tx_mcs9_max_nss;
+ uint8_t rx_tx_mcs11_max_nss;
+ uint8_t rx_tx_mcs13_max_nss;
+ };
+ uint8_t rx_tx_max_nss[3];
+ };
+};
+
+struct ieee80211_eht_cap_elem_fixed {
+ uint8_t mac_cap_info[2];
+ uint8_t phy_cap_info[9];
+};
+
+struct ieee80211_eht_mcs_nss_supp {
+ /* TODO FIXME */
+ /* Can only have either or... */
+ union {
+ struct ieee80211_eht_mcs_nss_supp_20mhz_only only_20mhz;
+ struct {
+ struct ieee80211_eht_mcs_nss_supp_bw _80;
+ struct ieee80211_eht_mcs_nss_supp_bw _160;
+ struct ieee80211_eht_mcs_nss_supp_bw _320;
+ } bw;
+ };
+};
+
+#define IEEE80211_STA_EHT_PPE_THRES_MAX 32
+struct ieee80211_sta_eht_cap {
+ bool has_eht;
+ struct ieee80211_eht_cap_elem_fixed eht_cap_elem;
+ struct ieee80211_eht_mcs_nss_supp eht_mcs_nss_supp;
+ uint8_t eht_ppe_thres[IEEE80211_STA_EHT_PPE_THRES_MAX];
+};
+
+struct ieee80211_sband_iftype_data {
+ /* TODO FIXME */
+ enum nl80211_iftype types_mask;
+ struct ieee80211_sta_he_cap he_cap;
+ struct ieee80211_he_6ghz_capa he_6ghz_capa;
+ struct ieee80211_sta_eht_cap eht_cap;
+ struct {
+ const uint8_t *data;
+ size_t len;
+ } vendor_elems;
+};
+
+struct ieee80211_supported_band {
+ /* TODO FIXME */
+ struct linuxkpi_ieee80211_channel *channels;
+ struct ieee80211_rate *bitrates;
+ struct ieee80211_sband_iftype_data *iftype_data;
+ int n_channels;
+ int n_bitrates;
+ int n_iftype_data;
+ enum nl80211_band band;
+ struct ieee80211_sta_ht_cap ht_cap;
+ struct ieee80211_sta_vht_cap vht_cap;
+};
+
+struct cfg80211_pkt_pattern {
+ /* XXX TODO */
+ uint8_t *mask;
+ uint8_t *pattern;
+ int pattern_len;
+ int pkt_offset;
+};
+
+struct cfg80211_wowlan_nd_match {
+ /* XXX TODO */
+ struct cfg80211_ssid ssid;
+ int n_channels;
+ uint32_t channels[0]; /* freq! = ieee80211_channel_to_frequency() */
+};
+
+struct cfg80211_wowlan_nd_info {
+ /* XXX TODO */
+ int n_matches;
+ struct cfg80211_wowlan_nd_match *matches[0];
+};
+
+enum wiphy_wowlan_support_flags {
+ WIPHY_WOWLAN_DISCONNECT,
+ WIPHY_WOWLAN_MAGIC_PKT,
+ WIPHY_WOWLAN_SUPPORTS_GTK_REKEY,
+ WIPHY_WOWLAN_GTK_REKEY_FAILURE,
+ WIPHY_WOWLAN_EAP_IDENTITY_REQ,
+ WIPHY_WOWLAN_4WAY_HANDSHAKE,
+ WIPHY_WOWLAN_RFKILL_RELEASE,
+ WIPHY_WOWLAN_NET_DETECT,
+};
+
+struct wiphy_wowlan_support {
+ /* XXX TODO */
+ enum wiphy_wowlan_support_flags flags;
+ int max_nd_match_sets, max_pkt_offset, n_patterns, pattern_max_len, pattern_min_len;
+};
+
+struct cfg80211_wowlan_wakeup {
+ /* XXX TODO */
+ uint16_t pattern_idx;
+ bool disconnect;
+ bool unprot_deauth_disassoc;
+ bool eap_identity_req;
+ bool four_way_handshake;
+ bool gtk_rekey_failure;
+ bool magic_pkt;
+ bool rfkill_release;
+ bool tcp_connlost;
+ bool tcp_nomoretokens;
+ bool tcp_match;
+ bool packet_80211;
+ struct cfg80211_wowlan_nd_info *net_detect;
+ uint8_t *packet;
+ uint16_t packet_len;
+ uint16_t packet_present_len;
+};
+
+struct cfg80211_wowlan {
+ /* XXX TODO */
+ bool any;
+ bool disconnect;
+ bool magic_pkt;
+ bool gtk_rekey_failure;
+ bool eap_identity_req;
+ bool four_way_handshake;
+ bool rfkill_release;
+
+ /* Magic packet patterns. */
+ int n_patterns;
+ struct cfg80211_pkt_pattern *patterns;
+
+ /* netdetect? if not assoc? */
+ struct cfg80211_sched_scan_request *nd_config;
+
+ void *tcp; /* XXX ? */
+};
+
+struct cfg80211_gtk_rekey_data {
+ /* XXX TODO */
+ const uint8_t *kck, *kek, *replay_ctr;
+ uint32_t akm;
+ uint8_t kck_len, kek_len;
+};
+
+struct cfg80211_tid_cfg {
+ /* XXX TODO */
+ int mask, noack, retry_long, rtscts, tids, amsdu, ampdu;
+ enum nl80211_tx_rate_setting txrate_type;
+ struct cfg80211_bitrate_mask txrate_mask;
+};
+
+struct cfg80211_tid_config {
+ /* XXX TODO */
+ int n_tid_conf;
+ struct cfg80211_tid_cfg tid_conf[0];
+};
+
+struct ieee80211_iface_limit {
+ /* TODO FIXME */
+ int max, types;
+};
+
+struct ieee80211_iface_combination {
+ /* TODO FIXME */
+ const struct ieee80211_iface_limit *limits;
+ int n_limits;
+ int max_interfaces, num_different_channels;
+ int beacon_int_infra_match, beacon_int_min_gcd;
+ int radar_detect_widths;
+};
+
+struct iface_combination_params {
+ int num_different_channels;
+ int iftype_num[NUM_NL80211_IFTYPES];
+};
+
+struct regulatory_request {
+ /* XXX TODO */
+ uint8_t alpha2[2];
+ enum environment_cap country_ie_env;
+ int initiator, dfs_region;
+ int user_reg_hint_type;
+};
+
+struct cfg80211_set_hw_timestamp {
+ const uint8_t *macaddr;
+ bool enable;
+};
+
+struct survey_info { /* net80211::struct ieee80211_channel_survey */
+ /* TODO FIXME */
+ uint32_t filled;
+#define SURVEY_INFO_TIME 0x0001
+#define SURVEY_INFO_TIME_RX 0x0002
+#define SURVEY_INFO_TIME_SCAN 0x0004
+#define SURVEY_INFO_TIME_TX 0x0008
+#define SURVEY_INFO_TIME_BSS_RX 0x0010
+#define SURVEY_INFO_TIME_BUSY 0x0020
+#define SURVEY_INFO_IN_USE 0x0040
+#define SURVEY_INFO_NOISE_DBM 0x0080
+ uint32_t noise;
+ uint64_t time;
+ uint64_t time_bss_rx;
+ uint64_t time_busy;
+ uint64_t time_rx;
+ uint64_t time_scan;
+ uint64_t time_tx;
+ struct linuxkpi_ieee80211_channel *channel;
+};
+
+enum wiphy_vendor_cmd_need_flags {
+ WIPHY_VENDOR_CMD_NEED_NETDEV = 0x01,
+ WIPHY_VENDOR_CMD_NEED_RUNNING = 0x02,
+ WIPHY_VENDOR_CMD_NEED_WDEV = 0x04,
+};
+
+struct wiphy_vendor_command {
+ struct {
+ uint32_t vendor_id;
+ uint32_t subcmd;
+ };
+ uint32_t flags;
+ void *policy;
+ int (*doit)(struct wiphy *, struct wireless_dev *, const void *, int);
+};
+
+struct wiphy_iftype_ext_capab {
+ /* TODO FIXME */
+ enum nl80211_iftype iftype;
+ const uint8_t *extended_capabilities;
+ const uint8_t *extended_capabilities_mask;
+ uint8_t extended_capabilities_len;
+ uint16_t eml_capabilities;
+ uint16_t mld_capa_and_ops;
+};
+
+struct tid_config_support {
+ /* TODO FIXME */
+ uint64_t vif; /* enum nl80211_tid_cfg_attr */
+ uint64_t peer; /* enum nl80211_tid_cfg_attr */
+};
+
+enum cfg80211_regulatory {
+ REGULATORY_CUSTOM_REG = BIT(0),
+ REGULATORY_STRICT_REG = BIT(1),
+ REGULATORY_DISABLE_BEACON_HINTS = BIT(2),
+ REGULATORY_ENABLE_RELAX_NO_IR = BIT(3),
+ REGULATORY_WIPHY_SELF_MANAGED = BIT(4),
+ REGULATORY_COUNTRY_IE_IGNORE = BIT(5),
+ REGULATORY_COUNTRY_IE_FOLLOW_POWER = BIT(6),
+};
+
+struct wiphy_radio_freq_range {
+ uint32_t start_freq;
+ uint32_t end_freq;
+};
+
+struct wiphy_radio {
+ int n_freq_range;
+ int n_iface_combinations;
+ const struct wiphy_radio_freq_range *freq_range;
+ const struct ieee80211_iface_combination *iface_combinations;
+};
+
+enum wiphy_flags {
+ WIPHY_FLAG_AP_UAPSD = BIT(0),
+ WIPHY_FLAG_HAS_CHANNEL_SWITCH = BIT(1),
+ WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL = BIT(2),
+ WIPHY_FLAG_HAVE_AP_SME = BIT(3),
+ WIPHY_FLAG_IBSS_RSN = BIT(4),
+ WIPHY_FLAG_NETNS_OK = BIT(5),
+ WIPHY_FLAG_OFFCHAN_TX = BIT(6),
+ WIPHY_FLAG_PS_ON_BY_DEFAULT = BIT(7),
+ WIPHY_FLAG_SPLIT_SCAN_6GHZ = BIT(8),
+ WIPHY_FLAG_SUPPORTS_EXT_KEK_KCK = BIT(9),
+ WIPHY_FLAG_SUPPORTS_FW_ROAM = BIT(10),
+ WIPHY_FLAG_SUPPORTS_TDLS = BIT(11),
+ WIPHY_FLAG_TDLS_EXTERNAL_SETUP = BIT(12),
+ WIPHY_FLAG_AP_PROBE_RESP_OFFLOAD = BIT(13),
+ WIPHY_FLAG_4ADDR_AP = BIT(14),
+ WIPHY_FLAG_4ADDR_STATION = BIT(15),
+ WIPHY_FLAG_SUPPORTS_MLO = BIT(16),
+ WIPHY_FLAG_DISABLE_WEXT = BIT(17),
+};
+
+struct wiphy_work;
+typedef void (*wiphy_work_fn)(struct wiphy *, struct wiphy_work *);
+struct wiphy_work {
+ struct list_head entry;
+ wiphy_work_fn fn;
+};
+struct wiphy_delayed_work {
+ struct wiphy_work work;
+ struct wiphy *wiphy;
+ struct timer_list timer;
+};
+
+struct wiphy {
+ struct mutex mtx;
+ struct device *dev;
+ struct mac_address *addresses;
+ int n_addresses;
+ uint32_t flags;
+ struct ieee80211_supported_band *bands[NUM_NL80211_BANDS];
+ uint8_t perm_addr[ETH_ALEN];
+ uint16_t max_scan_ie_len;
+
+ /* XXX TODO */
+ const struct cfg80211_pmsr_capabilities *pmsr_capa;
+ const struct cfg80211_sar_capa *sar_capa;
+ const struct wiphy_iftype_ext_capab *iftype_ext_capab;
+ const struct linuxkpi_ieee80211_regdomain *regd;
+ char fw_version[ETHTOOL_FWVERS_LEN];
+ const struct ieee80211_iface_combination *iface_combinations;
+ const uint32_t *cipher_suites;
+ int n_iface_combinations;
+ int n_cipher_suites;
+ void(*reg_notifier)(struct wiphy *, struct regulatory_request *);
+ enum cfg80211_regulatory regulatory_flags;
+ int n_vendor_commands;
+ const struct wiphy_vendor_command *vendor_commands;
+ const struct ieee80211_txrx_stypes *mgmt_stypes;
+ uint32_t rts_threshold;
+ uint32_t frag_threshold;
+ struct tid_config_support tid_config_support;
+ uint8_t available_antennas_rx;
+ uint8_t available_antennas_tx;
+
+ int n_radio;
+ const struct wiphy_radio *radio;
+
+ int features, hw_version;
+ int interface_modes, max_match_sets, max_remain_on_channel_duration, max_scan_ssids, max_sched_scan_ie_len, max_sched_scan_plan_interval, max_sched_scan_plan_iterations, max_sched_scan_plans, max_sched_scan_reqs, max_sched_scan_ssids;
+ int num_iftype_ext_capab;
+ int max_ap_assoc_sta, probe_resp_offload, software_iftypes;
+ int bss_select_support, max_num_pmkids, retry_long, retry_short, signal_type;
+ int max_data_retry_count;
+ int tx_queue_len, rfkill;
+ int mbssid_max_interfaces;
+ int hw_timestamp_max_peers;
+ int ema_max_profile_periodicity;
+
+ unsigned long ext_features[BITS_TO_LONGS(NUM_NL80211_EXT_FEATURES)];
+ struct dentry *debugfsdir;
+
+ const struct wiphy_wowlan_support *wowlan;
+ struct cfg80211_wowlan *wowlan_config;
+ /* Lower layer (driver/mac80211) specific data. */
+ /* Must stay last. */
+ uint8_t priv[0] __aligned(CACHE_LINE_SIZE);
+};
+
+#define lockdep_assert_wiphy(wiphy) \
+ lockdep_assert_held(&(wiphy)->mtx)
+
+struct wireless_dev {
+ /* XXX TODO, like ic? */
+ enum nl80211_iftype iftype;
+ uint32_t radio_mask;
+ uint8_t address[ETH_ALEN];
+ struct net_device *netdev;
+ struct wiphy *wiphy;
+};
+
+struct cfg80211_ops {
+ /* XXX TODO */
+ struct wireless_dev *(*add_virtual_intf)(struct wiphy *, const char *, unsigned char, enum nl80211_iftype, struct vif_params *);
+ int (*del_virtual_intf)(struct wiphy *, struct wireless_dev *);
+ int (*change_virtual_intf)(struct wiphy *, struct net_device *, enum nl80211_iftype, struct vif_params *);
+ int (*scan)(struct wiphy *, struct cfg80211_scan_request *);
+ int (*set_wiphy_params)(struct wiphy *, int, uint32_t);
+ int (*join_ibss)(struct wiphy *, struct net_device *, struct cfg80211_ibss_params *);
+ int (*leave_ibss)(struct wiphy *, struct net_device *);
+ int (*get_station)(struct wiphy *, struct net_device *, const uint8_t *, struct station_info *);
+ int (*dump_station)(struct wiphy *, struct net_device *, int, uint8_t *, struct station_info *);
+ int (*set_tx_power)(struct wiphy *, struct wireless_dev *, int, enum nl80211_tx_power_setting, int);
+ int (*get_tx_power)(struct wiphy *, struct wireless_dev *, int, unsigned int, int *);
+ int (*add_key)(struct wiphy *, struct net_device *, int, uint8_t, bool, const uint8_t *, struct key_params *);
+ int (*del_key)(struct wiphy *, struct net_device *, int, uint8_t, bool, const uint8_t *);
+ int (*get_key)(struct wiphy *, struct net_device *, int, uint8_t, bool, const uint8_t *, void *, void(*)(void *, struct key_params *));
+ int (*set_default_key)(struct wiphy *, struct net_device *, int, uint8_t, bool, bool);
+ int (*set_default_mgmt_key)(struct wiphy *, struct net_device *, int, uint8_t);
+ int (*set_power_mgmt)(struct wiphy *, struct net_device *, bool, int);
+ int (*connect)(struct wiphy *, struct net_device *, struct cfg80211_connect_params *);
+ int (*disconnect)(struct wiphy *, struct net_device *, uint16_t);
+ int (*suspend)(struct wiphy *, struct cfg80211_wowlan *);
+ int (*resume)(struct wiphy *);
+ int (*set_pmksa)(struct wiphy *, struct net_device *, struct cfg80211_pmksa *);
+ int (*del_pmksa)(struct wiphy *, struct net_device *, struct cfg80211_pmksa *);
+ int (*flush_pmksa)(struct wiphy *, struct net_device *);
+ int (*start_ap)(struct wiphy *, struct net_device *, struct cfg80211_ap_settings *);
+ int (*stop_ap)(struct wiphy *, struct net_device *, unsigned int);
+ int (*change_beacon)(struct wiphy *, struct net_device *, struct cfg80211_ap_update *);
+ int (*del_station)(struct wiphy *, struct net_device *, struct station_del_parameters *);
+ int (*change_station)(struct wiphy *, struct net_device *, const uint8_t *, struct station_parameters *);
+ int (*sched_scan_start)(struct wiphy *, struct net_device *, struct cfg80211_sched_scan_request *);
+ int (*sched_scan_stop)(struct wiphy *, struct net_device *, uint64_t);
+ void (*update_mgmt_frame_registrations)(struct wiphy *, struct wireless_dev *, struct mgmt_frame_regs *);
+ int (*mgmt_tx)(struct wiphy *, struct wireless_dev *, struct cfg80211_mgmt_tx_params *, uint64_t *);
+ int (*cancel_remain_on_channel)(struct wiphy *, struct wireless_dev *, uint64_t);
+ int (*get_channel)(struct wiphy *, struct wireless_dev *, unsigned int, struct cfg80211_chan_def *);
+ int (*crit_proto_start)(struct wiphy *, struct wireless_dev *, enum nl80211_crit_proto_id, uint16_t);
+ void (*crit_proto_stop)(struct wiphy *, struct wireless_dev *);
+ int (*tdls_oper)(struct wiphy *, struct net_device *, const uint8_t *, enum nl80211_tdls_operation);
+ int (*update_connect_params)(struct wiphy *, struct net_device *, struct cfg80211_connect_params *, uint32_t);
+ int (*set_pmk)(struct wiphy *, struct net_device *, const struct cfg80211_pmk_conf *);
+ int (*del_pmk)(struct wiphy *, struct net_device *, const uint8_t *);
+ int (*remain_on_channel)(struct wiphy *, struct wireless_dev *, struct linuxkpi_ieee80211_channel *, unsigned int, uint64_t *);
+ int (*start_p2p_device)(struct wiphy *, struct wireless_dev *);
+ void (*stop_p2p_device)(struct wiphy *, struct wireless_dev *);
+ int (*dump_survey)(struct wiphy *, struct net_device *, int, struct survey_info *);
+ int (*external_auth)(struct wiphy *, struct net_device *, struct cfg80211_external_auth_params *);
+ int (*set_cqm_rssi_range_config)(struct wiphy *, struct net_device *, int, int);
+
+};
+
+
+/* -------------------------------------------------------------------------- */
+
+/* linux_80211.c */
+
+struct wiphy *linuxkpi_wiphy_new(const struct cfg80211_ops *, size_t);
+void linuxkpi_wiphy_free(struct wiphy *wiphy);
+
+void linuxkpi_wiphy_work_queue(struct wiphy *, struct wiphy_work *);
+void linuxkpi_wiphy_work_cancel(struct wiphy *, struct wiphy_work *);
+void linuxkpi_wiphy_work_flush(struct wiphy *, struct wiphy_work *);
+void lkpi_wiphy_delayed_work_timer(struct timer_list *);
+void linuxkpi_wiphy_delayed_work_queue(struct wiphy *,
+ struct wiphy_delayed_work *, unsigned long);
+void linuxkpi_wiphy_delayed_work_cancel(struct wiphy *,
+ struct wiphy_delayed_work *);
+void linuxkpi_wiphy_delayed_work_flush(struct wiphy *,
+ struct wiphy_delayed_work *);
+
+int linuxkpi_regulatory_set_wiphy_regd_sync(struct wiphy *wiphy,
+ struct linuxkpi_ieee80211_regdomain *regd);
+uint32_t linuxkpi_cfg80211_calculate_bitrate(struct rate_info *);
+uint32_t linuxkpi_ieee80211_channel_to_frequency(uint32_t, enum nl80211_band);
+uint32_t linuxkpi_ieee80211_frequency_to_channel(uint32_t, uint32_t);
+struct linuxkpi_ieee80211_channel *
+ linuxkpi_ieee80211_get_channel(struct wiphy *, uint32_t);
+struct cfg80211_bss *linuxkpi_cfg80211_get_bss(struct wiphy *,
+ struct linuxkpi_ieee80211_channel *, const uint8_t *,
+ const uint8_t *, size_t, enum ieee80211_bss_type, enum ieee80211_privacy);
+void linuxkpi_cfg80211_put_bss(struct wiphy *, struct cfg80211_bss *);
+void linuxkpi_cfg80211_bss_flush(struct wiphy *);
+struct linuxkpi_ieee80211_regdomain *
+ lkpi_get_linuxkpi_ieee80211_regdomain(size_t);
+
+/* -------------------------------------------------------------------------- */
+
+static __inline struct wiphy *
+wiphy_new(const struct cfg80211_ops *ops, size_t priv_len)
+{
+
+ return (linuxkpi_wiphy_new(ops, priv_len));
+}
+
+static __inline void
+wiphy_free(struct wiphy *wiphy)
+{
+
+ linuxkpi_wiphy_free(wiphy);
+}
+
+static __inline void *
+wiphy_priv(struct wiphy *wiphy)
+{
+
+ return (wiphy->priv);
+}
+
+static __inline void
+set_wiphy_dev(struct wiphy *wiphy, struct device *dev)
+{
+
+ wiphy->dev = dev;
+}
+
+static __inline struct device *
+wiphy_dev(struct wiphy *wiphy)
+{
+
+ return (wiphy->dev);
+}
+
+#define wiphy_dereference(_w, p) \
+ rcu_dereference_check(p, lockdep_is_held(&(_w)->mtx))
+
+#define wiphy_lock(_w) mutex_lock(&(_w)->mtx)
+#define wiphy_unlock(_w) mutex_unlock(&(_w)->mtx)
+
+static __inline void
+wiphy_rfkill_set_hw_state_reason(struct wiphy *wiphy, bool blocked,
+ enum rfkill_hard_block_reasons reason)
+{
+ TODO();
+}
+
+/* -------------------------------------------------------------------------- */
+
+static inline int
+cfg80211_register_netdevice(struct net_device *ndev)
+{
+ TODO();
+ return (-ENXIO);
+}
+
+static inline void
+cfg80211_unregister_netdevice(struct net_device *ndev)
+{
+ TODO();
+}
+
+/* -------------------------------------------------------------------------- */
+
+static inline struct cfg80211_bss *
+cfg80211_get_bss(struct wiphy *wiphy, struct linuxkpi_ieee80211_channel *chan,
+ const uint8_t *bssid, const uint8_t *ssid, size_t ssid_len,
+ enum ieee80211_bss_type bss_type, enum ieee80211_privacy privacy)
+{
+
+ return (linuxkpi_cfg80211_get_bss(wiphy, chan, bssid, ssid, ssid_len,
+ bss_type, privacy));
+}
+
+static inline void
+cfg80211_put_bss(struct wiphy *wiphy, struct cfg80211_bss *bss)
+{
+
+ linuxkpi_cfg80211_put_bss(wiphy, bss);
+}
+
+static inline void
+cfg80211_bss_flush(struct wiphy *wiphy)
+{
+
+ linuxkpi_cfg80211_bss_flush(wiphy);
+}
+
+/* -------------------------------------------------------------------------- */
+
+static __inline bool
+rfkill_blocked(int rfkill) /* argument type? */
+{
+ TODO();
+ return (false);
+}
+
+static __inline bool
+rfkill_soft_blocked(int rfkill)
+{
+ TODO();
+ return (false);
+}
+
+static __inline void
+wiphy_rfkill_start_polling(struct wiphy *wiphy)
+{
+ TODO();
+}
+
+static __inline void
+wiphy_rfkill_stop_polling(struct wiphy *wiphy)
+{
+ TODO();
+}
+
+static __inline int
+reg_query_regdb_wmm(uint8_t *alpha2, uint32_t center_freq,
+ struct ieee80211_reg_rule *rule)
+{
+
+ IMPROVE("regdomain.xml needs to grow wmm information for at least ETSI");
+
+ return (-ENODATA);
+}
+
+static __inline const uint8_t *
+cfg80211_find_ie_match(uint32_t f, const uint8_t *ies, size_t ies_len,
+ const uint8_t *match, int x, int y)
+{
+ TODO();
+ return (NULL);
+}
+
+static __inline const uint8_t *
+cfg80211_find_ie(uint8_t eid, const uint8_t *ie, uint32_t ielen)
+{
+ TODO();
+ return (NULL);
+}
+
+static __inline void
+cfg80211_pmsr_complete(struct wireless_dev *wdev,
+ struct cfg80211_pmsr_request *req, gfp_t gfp)
+{
+ TODO();
+}
+
+static __inline void
+cfg80211_pmsr_report(struct wireless_dev *wdev,
+ struct cfg80211_pmsr_request *req,
+ struct cfg80211_pmsr_result *result, gfp_t gfp)
+{
+ TODO();
+}
+
+static inline int
+nl80211_chan_width_to_mhz(enum nl80211_chan_width width)
+{
+ switch (width) {
+ case NL80211_CHAN_WIDTH_5:
+ return (5);
+ break;
+ case NL80211_CHAN_WIDTH_10:
+ return (10);
+ break;
+ case NL80211_CHAN_WIDTH_20_NOHT:
+ case NL80211_CHAN_WIDTH_20:
+ return (20);
+ break;
+ case NL80211_CHAN_WIDTH_40:
+ return (40);
+ break;
+ case NL80211_CHAN_WIDTH_80:
+ case NL80211_CHAN_WIDTH_80P80:
+ return (80);
+ break;
+ case NL80211_CHAN_WIDTH_160:
+ return (160);
+ break;
+ case NL80211_CHAN_WIDTH_320:
+ return (320);
+ break;
+ }
+}
+
+static inline void
+cfg80211_chandef_create(struct cfg80211_chan_def *chandef,
+ struct linuxkpi_ieee80211_channel *chan, enum nl80211_channel_type chan_type)
+{
+
+ KASSERT(chandef != NULL, ("%s: chandef is NULL\n", __func__));
+ KASSERT(chan != NULL, ("%s: chan is NULL\n", __func__));
+
+ /* memset(chandef, 0, sizeof(*chandef)); */
+ chandef->chan = chan;
+ chandef->center_freq1 = chan->center_freq;
+ /* chandef->width, center_freq2, punctured */
+
+ switch (chan_type) {
+ case NL80211_CHAN_NO_HT:
+ chandef->width = NL80211_CHAN_WIDTH_20_NOHT;
+ break;
+ case NL80211_CHAN_HT20:
+ chandef->width = NL80211_CHAN_WIDTH_20;
+ break;
+ case NL80211_CHAN_HT40MINUS:
+ chandef->width = NL80211_CHAN_WIDTH_40;
+ chandef->center_freq1 -= 10;
+ break;
+ case NL80211_CHAN_HT40PLUS:
+ chandef->width = NL80211_CHAN_WIDTH_40;
+ chandef->center_freq1 += 10;
+ break;
+ };
+}
+
+static __inline bool
+cfg80211_chandef_valid(const struct cfg80211_chan_def *chandef)
+{
+ TODO();
+ return (false);
+}
+
+static inline int
+cfg80211_chandef_get_width(const struct cfg80211_chan_def *chandef)
+{
+ return (nl80211_chan_width_to_mhz(chandef->width));
+}
+
+static __inline bool
+cfg80211_chandef_dfs_usable(struct wiphy *wiphy, const struct cfg80211_chan_def *chandef)
+{
+ TODO();
+ return (false);
+}
+
+static __inline unsigned int
+cfg80211_chandef_dfs_cac_time(struct wiphy *wiphy, const struct cfg80211_chan_def *chandef)
+{
+ TODO();
+ return (0);
+}
+
+static __inline bool
+cfg80211_chandef_identical(const struct cfg80211_chan_def *chandef_1,
+ const struct cfg80211_chan_def *chandef_2)
+{
+ TODO();
+ return (false);
+}
+
+static __inline bool
+cfg80211_chandef_usable(struct wiphy *wiphy,
+ const struct cfg80211_chan_def *chandef, uint32_t flags)
+{
+ TODO();
+ return (false);
+}
+
+static __inline void
+cfg80211_bss_iter(struct wiphy *wiphy, struct cfg80211_chan_def *chandef,
+ void (*iterfunc)(struct wiphy *, struct cfg80211_bss *, void *), void *data)
+{
+ TODO();
+}
+
+struct element {
+ uint8_t id;
+ uint8_t datalen;
+ uint8_t data[0];
+} __packed;
+
+static inline const struct element *
+lkpi_cfg80211_find_elem_pattern(enum ieee80211_eid eid,
+ const uint8_t *data, size_t len, uint8_t *pattern, size_t plen)
+{
+ const struct element *elem;
+ const uint8_t *p;
+ size_t ielen;
+
+ p = data;
+ elem = (const struct element *)p;
+ ielen = len;
+ while (elem != NULL && ielen > 1) {
+ if ((2 + elem->datalen) > ielen)
+ /* Element overruns our memory. */
+ return (NULL);
+ if (elem->id == eid) {
+ if (pattern == NULL)
+ return (elem);
+ if (elem->datalen >= plen &&
+ memcmp(elem->data, pattern, plen) == 0)
+ return (elem);
+ }
+ ielen -= 2 + elem->datalen;
+ p += 2 + elem->datalen;
+ elem = (const struct element *)p;
+ }
+
+ return (NULL);
+}
+
+static inline const struct element *
+cfg80211_find_elem(enum ieee80211_eid eid, const uint8_t *data, size_t len)
+{
+
+ return (lkpi_cfg80211_find_elem_pattern(eid, data, len, NULL, 0));
+}
+
+static inline const struct element *
+ieee80211_bss_get_elem(struct cfg80211_bss *bss, uint32_t eid)
+{
+
+ if (bss->ies == NULL)
+ return (NULL);
+ return (cfg80211_find_elem(eid, bss->ies->data, bss->ies->len));
+}
+
+static inline const uint8_t *
+ieee80211_bss_get_ie(struct cfg80211_bss *bss, uint32_t eid)
+{
+
+ return ((const uint8_t *)ieee80211_bss_get_elem(bss, eid));
+}
+
+static inline uint8_t *
+cfg80211_find_vendor_ie(unsigned int oui, int oui_type,
+ uint8_t *data, size_t len)
+{
+ const struct element *elem;
+ uint8_t pattern[4] = { oui << 16, oui << 8, oui, oui_type };
+ uint8_t plen = 4; /* >= 3? oui_type always part of this? */
+ IMPROVE("plen currently always incl. oui_type");
+
+ elem = lkpi_cfg80211_find_elem_pattern(IEEE80211_ELEMID_VENDOR,
+ data, len, pattern, plen);
+ if (elem == NULL)
+ return (NULL);
+ return (__DECONST(uint8_t *, elem));
+}
+
+static inline uint32_t
+cfg80211_calculate_bitrate(struct rate_info *rate)
+{
+ return (linuxkpi_cfg80211_calculate_bitrate(rate));
+}
+
+static __inline uint32_t
+ieee80211_channel_to_frequency(uint32_t channel, enum nl80211_band band)
+{
+
+ return (linuxkpi_ieee80211_channel_to_frequency(channel, band));
+}
+
+static __inline uint32_t
+ieee80211_frequency_to_channel(uint32_t freq)
+{
+
+ return (linuxkpi_ieee80211_frequency_to_channel(freq, 0));
+}
+
+static __inline int
+regulatory_set_wiphy_regd_sync(struct wiphy *wiphy,
+ struct linuxkpi_ieee80211_regdomain *regd)
+{
+ IMPROVE();
+ return (linuxkpi_regulatory_set_wiphy_regd_sync(wiphy, regd));
+}
+
+static __inline int
+regulatory_set_wiphy_regd_sync_rtnl(struct wiphy *wiphy,
+ struct linuxkpi_ieee80211_regdomain *regd)
+{
+
+ IMPROVE();
+ return (linuxkpi_regulatory_set_wiphy_regd_sync(wiphy, regd));
+}
+
+static __inline int
+regulatory_set_wiphy_regd(struct wiphy *wiphy,
+ struct linuxkpi_ieee80211_regdomain *regd)
+{
+
+ IMPROVE();
+ if (regd == NULL)
+ return (EINVAL);
+
+ /* XXX-BZ wild guessing here based on brcmfmac. */
+ if (wiphy->regulatory_flags & REGULATORY_WIPHY_SELF_MANAGED)
+ wiphy->regd = regd;
+ else
+ return (EPERM);
+
+ /* XXX FIXME, do we have to do anything with reg_notifier? */
+ return (0);
+}
+
+static __inline int
+regulatory_hint(struct wiphy *wiphy, const uint8_t *alpha2)
+{
+ struct linuxkpi_ieee80211_regdomain *regd;
+
+ if (wiphy->regd != NULL)
+ return (-EBUSY);
+
+ regd = lkpi_get_linuxkpi_ieee80211_regdomain(0);
+ if (regd == NULL)
+ return (-ENOMEM);
+
+ regd->alpha2[0] = alpha2[0];
+ regd->alpha2[1] = alpha2[1];
+ wiphy->regd = regd;
+
+ IMPROVE("are there flags who is managing? update net8011?");
+
+ return (0);
+}
+
+static __inline const char *
+reg_initiator_name(enum nl80211_reg_initiator initiator)
+{
+ TODO();
+ return (NULL);
+}
+
+static __inline struct linuxkpi_ieee80211_regdomain *
+rtnl_dereference(const struct linuxkpi_ieee80211_regdomain *regd)
+{
+ TODO();
+ return (NULL);
+}
+
+static __inline struct ieee80211_reg_rule *
+freq_reg_info(struct wiphy *wiphy, uint32_t center_freq)
+{
+ TODO();
+ return (NULL);
+}
+
+static __inline void
+wiphy_apply_custom_regulatory(struct wiphy *wiphy,
+ const struct linuxkpi_ieee80211_regdomain *regd)
+{
+ TODO();
+}
+
+static __inline char *
+wiphy_name(struct wiphy *wiphy)
+{
+ if (wiphy != NULL && wiphy->dev != NULL)
+ return dev_name(wiphy->dev);
+ else {
+ IMPROVE("wlanNA");
+ return ("wlanNA");
+ }
+}
+
+static __inline void
+wiphy_read_of_freq_limits(struct wiphy *wiphy)
+{
+#ifdef FDT
+ TODO();
+#endif
+}
+
+static __inline void
+wiphy_ext_feature_set(struct wiphy *wiphy, enum nl80211_ext_feature ef)
+{
+
+ set_bit(ef, wiphy->ext_features);
+}
+
+static inline bool
+wiphy_ext_feature_isset(struct wiphy *wiphy, enum nl80211_ext_feature ef)
+{
+ return (test_bit(ef, wiphy->ext_features));
+}
+
+static __inline void *
+wiphy_net(struct wiphy *wiphy)
+{
+ TODO();
+ return (NULL); /* XXX passed to dev_net_set() */
+}
+
+static __inline int
+wiphy_register(struct wiphy *wiphy)
+{
+ TODO();
+ return (0);
+}
+
+static __inline void
+wiphy_unregister(struct wiphy *wiphy)
+{
+ TODO();
+}
+
+static __inline void
+wiphy_warn(struct wiphy *wiphy, const char *fmt, ...)
+{
+ TODO();
+}
+
+static __inline int
+cfg80211_check_combinations(struct wiphy *wiphy,
+ struct iface_combination_params *params)
+{
+ TODO();
+ return (-ENOENT);
+}
+
+static __inline uint8_t
+cfg80211_classify8021d(struct sk_buff *skb, void *p)
+{
+ TODO();
+ return (0);
+}
+
+static __inline void
+cfg80211_connect_done(struct net_device *ndev,
+ struct cfg80211_connect_resp_params *conn_params, gfp_t gfp)
+{
+ TODO();
+}
+
+static __inline void
+cfg80211_crit_proto_stopped(struct wireless_dev *wdev, gfp_t gfp)
+{
+ TODO();
+}
+
+static __inline void
+cfg80211_disconnected(struct net_device *ndev, uint16_t reason,
+ void *p, int x, bool locally_generated, gfp_t gfp)
+{
+ TODO();
+}
+
+static __inline int
+cfg80211_get_p2p_attr(const uint8_t *ie, uint32_t ie_len,
+ enum ieee80211_p2p_attr_ids attr, uint8_t *p, size_t p_len)
+{
+ TODO();
+ return (-1);
+}
+
+static __inline void
+cfg80211_ibss_joined(struct net_device *ndev, const uint8_t *addr,
+ struct linuxkpi_ieee80211_channel *chan, gfp_t gfp)
+{
+ TODO();
+}
+
+static __inline struct cfg80211_bss *
+cfg80211_inform_bss(struct wiphy *wiphy,
+ struct linuxkpi_ieee80211_channel *channel,
+ enum cfg80211_bss_frame_type bss_ftype, const uint8_t *bss, int _x,
+ uint16_t cap, uint16_t intvl, const uint8_t *ie, size_t ie_len,
+ int signal, gfp_t gfp)
+{
+ TODO();
+ return (NULL);
+}
+
+static __inline struct cfg80211_bss *
+cfg80211_inform_bss_data(struct wiphy *wiphy,
+ struct cfg80211_inform_bss *bss_data,
+ enum cfg80211_bss_frame_type bss_ftype, const uint8_t *bss, int _x,
+ uint16_t cap, uint16_t intvl, const uint8_t *ie, size_t ie_len, gfp_t gfp)
+{
+ TODO();
+ return (NULL);
+}
+
+static __inline void
+cfg80211_mgmt_tx_status(struct wireless_dev *wdev, uint64_t cookie,
+ const uint8_t *buf, size_t len, bool ack, gfp_t gfp)
+{
+ TODO();
+}
+
+static __inline void
+cfg80211_michael_mic_failure(struct net_device *ndev, const uint8_t addr[ETH_ALEN],
+ enum nl80211_key_type key_type, int _x, void *p, gfp_t gfp)
+{
+ TODO();
+}
+
+static __inline void
+cfg80211_new_sta(struct net_device *ndev, const uint8_t *addr,
+ struct station_info *sinfo, gfp_t gfp)
+{
+ TODO();
+}
+
+static __inline void
+cfg80211_del_sta(struct net_device *ndev, const uint8_t *addr, gfp_t gfp)
+{
+ TODO();
+}
+
+static __inline void
+cfg80211_port_authorized(struct net_device *ndev, const uint8_t *addr,
+ const uint8_t *bitmap, uint8_t len, gfp_t gfp)
+{
+ TODO();
+}
+
+static __inline void
+cfg80211_ready_on_channel(struct wireless_dev *wdev, uint64_t cookie,
+ struct linuxkpi_ieee80211_channel *channel, unsigned int duration,
+ gfp_t gfp)
+{
+ TODO();
+}
+
+static __inline void
+cfg80211_remain_on_channel_expired(struct wireless_dev *wdev,
+ uint64_t cookie, struct linuxkpi_ieee80211_channel *channel, gfp_t gfp)
+{
+ TODO();
+}
+
+static __inline void
+cfg80211_report_wowlan_wakeup(void)
+{
+ TODO();
+}
+
+static __inline void
+cfg80211_roamed(struct net_device *ndev, struct cfg80211_roam_info *roam_info,
+ gfp_t gfp)
+{
+ TODO();
+}
+
+static __inline void
+cfg80211_rx_mgmt(struct wireless_dev *wdev, int freq, int _x,
+ uint8_t *p, size_t p_len, int _x2)
+{
+ TODO();
+}
+
+static __inline void
+cfg80211_scan_done(struct cfg80211_scan_request *scan_request,
+ struct cfg80211_scan_info *info)
+{
+ TODO();
+}
+
+static __inline void
+cfg80211_sched_scan_results(struct wiphy *wiphy, uint64_t reqid)
+{
+ TODO();
+}
+
+static __inline void
+cfg80211_sched_scan_stopped(struct wiphy *wiphy, int _x)
+{
+ TODO();
+}
+
+static __inline void
+cfg80211_unregister_wdev(struct wireless_dev *wdev)
+{
+ TODO();
+}
+
+static __inline struct sk_buff *
+cfg80211_vendor_cmd_alloc_reply_skb(struct wiphy *wiphy, unsigned int len)
+{
+ TODO();
+ return (NULL);
+}
+
+static __inline int
+cfg80211_vendor_cmd_reply(struct sk_buff *skb)
+{
+ TODO();
+ return (-ENXIO);
+}
+
+static __inline struct linuxkpi_ieee80211_channel *
+ieee80211_get_channel(struct wiphy *wiphy, uint32_t freq)
+{
+
+ return (linuxkpi_ieee80211_get_channel(wiphy, freq));
+}
+
+static inline size_t
+ieee80211_get_hdrlen_from_skb(struct sk_buff *skb)
+{
+ const struct ieee80211_hdr *hdr;
+ size_t len;
+
+ if (skb->len < 10) /* sizeof(ieee80211_frame_[ack,cts]) */
+ return (0);
+
+ hdr = (const struct ieee80211_hdr *)skb->data;
+ len = ieee80211_hdrlen(hdr->frame_control);
+
+ /* If larger than what is in the skb return. */
+ if (len > skb->len)
+ return (0);
+
+ return (len);
+}
+
+static __inline bool
+cfg80211_channel_is_psc(struct linuxkpi_ieee80211_channel *channel)
+{
+
+ /* Only 6Ghz. */
+ if (channel->band != NL80211_BAND_6GHZ)
+ return (false);
+
+ TODO();
+ return (false);
+}
+
+static inline int
+cfg80211_get_ies_channel_number(const uint8_t *ie, size_t len,
+ enum nl80211_band band)
+{
+ const struct element *elem;
+
+ switch (band) {
+ case NL80211_BAND_6GHZ:
+ TODO();
+ break;
+ case NL80211_BAND_5GHZ:
+ case NL80211_BAND_2GHZ:
+ /* DSPARAMS has the channel number. */
+ elem = cfg80211_find_elem(IEEE80211_ELEMID_DSPARMS, ie, len);
+ if (elem != NULL && elem->datalen == 1)
+ return (elem->data[0]);
+ /* HTINFO has the primary center channel. */
+ elem = cfg80211_find_elem(IEEE80211_ELEMID_HTINFO, ie, len);
+ if (elem != NULL &&
+ elem->datalen >= (sizeof(struct ieee80211_ie_htinfo) - 2)) {
+ const struct ieee80211_ie_htinfo *htinfo;
+ htinfo = (const struct ieee80211_ie_htinfo *)elem;
+ return (htinfo->hi_ctrlchannel);
+ }
+ /* What else? */
+ break;
+ default:
+ IMPROVE("Unsupported");
+ break;
+ }
+ return (-1);
+}
+
+/* Used for scanning at least. */
+static __inline void
+get_random_mask_addr(uint8_t *dst, const uint8_t *addr, const uint8_t *mask)
+{
+ int i;
+
+ /* Get a completely random address and then overlay what we want. */
+ get_random_bytes(dst, ETH_ALEN);
+ for (i = 0; i < ETH_ALEN; i++)
+ dst[i] = (dst[i] & ~(mask[i])) | (addr[i] & mask[i]);
+}
+
+static __inline void
+cfg80211_shutdown_all_interfaces(struct wiphy *wiphy)
+{
+ TODO();
+}
+
+static __inline bool
+cfg80211_reg_can_beacon(struct wiphy *wiphy, struct cfg80211_chan_def *chandef,
+ enum nl80211_iftype iftype)
+{
+ TODO();
+ return (false);
+}
+
+static __inline void
+cfg80211_background_radar_event(struct wiphy *wiphy,
+ struct cfg80211_chan_def *chandef, gfp_t gfp)
+{
+ TODO();
+}
+
+static __inline const uint8_t *
+cfg80211_find_ext_ie(uint8_t eid, const uint8_t *p, size_t len)
+{
+ TODO();
+ return (NULL);
+}
+
+static inline void
+_ieee80211_set_sband_iftype_data(struct ieee80211_supported_band *band,
+ struct ieee80211_sband_iftype_data *iftype_data, size_t nitems)
+{
+ band->iftype_data = iftype_data;
+ band->n_iftype_data = nitems;
+}
+
+static inline const struct ieee80211_sband_iftype_data *
+ieee80211_get_sband_iftype_data(const struct ieee80211_supported_band *band,
+ enum nl80211_iftype iftype)
+{
+ const struct ieee80211_sband_iftype_data *iftype_data;
+ int i;
+
+ for (i = 0; i < band->n_iftype_data; i++) {
+ iftype_data = (const void *)&band->iftype_data[i];
+ if (iftype_data->types_mask & BIT(iftype))
+ return (iftype_data);
+ }
+
+ return (NULL);
+}
+
+static inline const struct ieee80211_sta_he_cap *
+ieee80211_get_he_iftype_cap(const struct ieee80211_supported_band *band,
+ enum nl80211_iftype iftype)
+{
+ const struct ieee80211_sband_iftype_data *iftype_data;
+ const struct ieee80211_sta_he_cap *he_cap;
+
+ iftype_data = ieee80211_get_sband_iftype_data(band, iftype);
+ if (iftype_data == NULL)
+ return (NULL);
+
+ he_cap = NULL;
+ if (iftype_data->he_cap.has_he)
+ he_cap = &iftype_data->he_cap;
+
+ return (he_cap);
+}
+
+static inline const struct ieee80211_sta_eht_cap *
+ieee80211_get_eht_iftype_cap(const struct ieee80211_supported_band *band,
+ enum nl80211_iftype iftype)
+{
+ const struct ieee80211_sband_iftype_data *iftype_data;
+ const struct ieee80211_sta_eht_cap *eht_cap;
+
+ iftype_data = ieee80211_get_sband_iftype_data(band, iftype);
+ if (iftype_data == NULL)
+ return (NULL);
+
+ eht_cap = NULL;
+ if (iftype_data->eht_cap.has_eht)
+ eht_cap = &iftype_data->eht_cap;
+
+ return (eht_cap);
+}
+
+static inline bool
+cfg80211_ssid_eq(struct cfg80211_ssid *ssid1, struct cfg80211_ssid *ssid2)
+{
+ int error;
+
+ if (ssid1 == NULL || ssid2 == NULL) /* Can we KASSERT this? */
+ return (false);
+
+ if (ssid1->ssid_len != ssid2->ssid_len)
+ return (false);
+ error = memcmp(ssid1->ssid, ssid2->ssid, ssid2->ssid_len);
+ if (error != 0)
+ return (false);
+ return (true);
+}
+
+static inline void
+cfg80211_rx_unprot_mlme_mgmt(struct net_device *ndev, const uint8_t *hdr,
+ uint32_t len)
+{
+ TODO();
+}
+
+static inline const struct wiphy_iftype_ext_capab *
+cfg80211_get_iftype_ext_capa(struct wiphy *wiphy, enum nl80211_iftype iftype)
+{
+
+ TODO();
+ return (NULL);
+}
+
+static inline int
+cfg80211_external_auth_request(struct net_device *ndev,
+ struct cfg80211_external_auth_params *params, gfp_t gfp)
+{
+ TODO();
+ return (-ENXIO);
+}
+
+static inline uint16_t
+ieee80211_get_he_6ghz_capa(const struct ieee80211_supported_band *sband,
+ enum nl80211_iftype iftype)
+{
+ TODO();
+ return (0);
+}
+
+static __inline ssize_t
+wiphy_locked_debugfs_read(struct wiphy *wiphy, struct file *file,
+ char *buf, size_t bufsize, const char __user *userbuf, size_t count,
+ loff_t *ppos,
+ ssize_t (*handler)(struct wiphy *, struct file *, char *, size_t, void *),
+ void *data)
+{
+ TODO();
+ return (-ENXIO);
+}
+
+
+static __inline ssize_t
+wiphy_locked_debugfs_write(struct wiphy *wiphy, struct file *file,
+ char *buf, size_t bufsize, const char __user *userbuf, size_t count,
+ ssize_t (*handler)(struct wiphy *, struct file *, char *, size_t, void *),
+ void *data)
+{
+ TODO();
+ return (-ENXIO);
+}
+
+static inline void
+cfg80211_cqm_rssi_notify(struct net_device *dev,
+ enum nl80211_cqm_rssi_threshold_event rssi_te, int32_t rssi, gfp_t gfp)
+{
+ TODO();
+}
+
+/* -------------------------------------------------------------------------- */
+
+static inline void
+wiphy_work_init(struct wiphy_work *wwk, wiphy_work_fn fn)
+{
+ INIT_LIST_HEAD(&wwk->entry);
+ wwk->fn = fn;
+}
+
+static inline void
+wiphy_work_queue(struct wiphy *wiphy, struct wiphy_work *wwk)
+{
+ linuxkpi_wiphy_work_queue(wiphy, wwk);
+}
+
+static inline void
+wiphy_work_cancel(struct wiphy *wiphy, struct wiphy_work *wwk)
+{
+ linuxkpi_wiphy_work_cancel(wiphy, wwk);
+}
+
+static inline void
+wiphy_work_flush(struct wiphy *wiphy, struct wiphy_work *wwk)
+{
+ linuxkpi_wiphy_work_flush(wiphy, wwk);
+}
+
+static inline void
+wiphy_delayed_work_init(struct wiphy_delayed_work *wdwk, wiphy_work_fn fn)
+{
+ wiphy_work_init(&wdwk->work, fn);
+ timer_setup(&wdwk->timer, lkpi_wiphy_delayed_work_timer, 0);
+}
+
+static inline void
+wiphy_delayed_work_queue(struct wiphy *wiphy, struct wiphy_delayed_work *wdwk,
+ unsigned long delay)
+{
+ linuxkpi_wiphy_delayed_work_queue(wiphy, wdwk, delay);
+}
+
+static inline void
+wiphy_delayed_work_cancel(struct wiphy *wiphy, struct wiphy_delayed_work *wdwk)
+{
+ linuxkpi_wiphy_delayed_work_cancel(wiphy, wdwk);
+}
+
+static inline void
+wiphy_delayed_work_flush(struct wiphy *wiphy, struct wiphy_delayed_work *wdwk)
+{
+ linuxkpi_wiphy_delayed_work_flush(wiphy, wdwk);
+}
+
+/* -------------------------------------------------------------------------- */
+
+#define wiphy_err(_wiphy, _fmt, ...) \
+ dev_err((_wiphy)->dev, _fmt, __VA_ARGS__)
+#define wiphy_info(wiphy, fmt, ...) \
+ dev_info((wiphy)->dev, fmt, ##__VA_ARGS__)
+#define wiphy_info_once(wiphy, fmt, ...) \
+ dev_info_once((wiphy)->dev, fmt, ##__VA_ARGS__)
+
+#ifndef LINUXKPI_NET80211
+#define ieee80211_channel linuxkpi_ieee80211_channel
+#define ieee80211_regdomain linuxkpi_ieee80211_regdomain
+#endif
+
+#include <net/mac80211.h>
+
+#endif /* _LINUXKPI_NET_CFG80211_H */
diff --git a/sys/compat/linuxkpi/common/include/net/ieee80211_radiotap.h b/sys/compat/linuxkpi/common/include/net/ieee80211_radiotap.h
index 9c22e3e06988..82e554f6b96e 100644
--- a/sys/compat/linuxkpi/common/include/net/ieee80211_radiotap.h
+++ b/sys/compat/linuxkpi/common/include/net/ieee80211_radiotap.h
@@ -1,6 +1,4 @@
/*-
- * SPDX-License-Identifier: BSD-2-Clause
- *
* Copyright (c) 2020-2021 The FreeBSD Foundation
*
* This software was developed by Björn Zeeb under sponsorship from
@@ -26,12 +24,10 @@
* 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.
- *
- * $FreeBSD$
*/
-#ifndef __LKPI_NET_IEEE80211_RADIOTAP_H
-#define __LKPI_NET_IEEE80211_RADIOTAP_H
+#ifndef _LINUXKPI_NET_IEEE80211_RADIOTAP_H
+#define _LINUXKPI_NET_IEEE80211_RADIOTAP_H
/* Any possibly duplicate content is only maintained in one place now. */
#include <net80211/ieee80211_radiotap.h>
@@ -52,4 +48,4 @@ struct ieee80211_vendor_radiotap {
u8 data[0];
};
-#endif /* __LKPI_NET_IEEE80211_RADIOTAP_H */
+#endif /* _LINUXKPI_NET_IEEE80211_RADIOTAP_H */
diff --git a/sys/compat/linuxkpi/common/include/net/if_inet6.h b/sys/compat/linuxkpi/common/include/net/if_inet6.h
index 16f3a9965675..c340909d7098 100644
--- a/sys/compat/linuxkpi/common/include/net/if_inet6.h
+++ b/sys/compat/linuxkpi/common/include/net/if_inet6.h
@@ -25,11 +25,9 @@
* 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.
- *
- * $FreeBSD$
*/
-#ifndef _NET_IF_INET6_H_
-#define _NET_IF_INET6_H_
+#ifndef _LINUXKPI_NET_IF_INET6_H_
+#define _LINUXKPI_NET_IF_INET6_H_
#include <sys/types.h>
#include <netinet/in.h>
@@ -54,4 +52,4 @@ static inline void ipv6_eth_mc_map(const struct in6_addr *addr, char *buf)
memcpy(buf + 2, &addr->s6_addr32[3], sizeof(__u32));
}
-#endif /* _NET_IF_INET6_H_ */
+#endif /* _LINUXKPI_NET_IF_INET6_H_ */
diff --git a/sys/compat/linuxkpi/common/include/net/ip.h b/sys/compat/linuxkpi/common/include/net/ip.h
index 1cfc568db323..3e7baab6cc0b 100644
--- a/sys/compat/linuxkpi/common/include/net/ip.h
+++ b/sys/compat/linuxkpi/common/include/net/ip.h
@@ -25,11 +25,9 @@
* 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.
- *
- * $FreeBSD$
*/
-#ifndef _LINUX_NET_IP_H_
-#define _LINUX_NET_IP_H_
+#ifndef _LINUXKPI_NET_IP_H_
+#define _LINUXKPI_NET_IP_H_
#include "opt_inet.h"
@@ -100,4 +98,4 @@ ip_ib_mc_map(uint32_t addr, const unsigned char *bcast, char *buf)
buf[19] = addr & 0xff;
}
-#endif /* _LINUX_NET_IP_H_ */
+#endif /* _LINUXKPI_NET_IP_H_ */
diff --git a/sys/compat/linuxkpi/common/include/net/ipv6.h b/sys/compat/linuxkpi/common/include/net/ipv6.h
index dfe77ef1c6ed..3a85781e3a49 100644
--- a/sys/compat/linuxkpi/common/include/net/ipv6.h
+++ b/sys/compat/linuxkpi/common/include/net/ipv6.h
@@ -25,11 +25,9 @@
* 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.
- *
- * $FreeBSD$
*/
-#ifndef _LINUX_NET_IPV6_H_
-#define _LINUX_NET_IPV6_H_
+#ifndef _LINUXKPI_NET_IPV6_H_
+#define _LINUXKPI_NET_IPV6_H_
#include <sys/types.h>
#include <netinet/in.h>
@@ -116,4 +114,4 @@ static inline int ipv6_addr_cmp(const struct in6_addr *a1, const struct in6_addr
return memcmp(a1, a2, sizeof(struct in6_addr));
}
-#endif /* _LINUX_NET_IPV6_H_ */
+#endif /* _LINUXKPI_NET_IPV6_H_ */
diff --git a/sys/compat/linuxkpi/common/include/net/mac80211.h b/sys/compat/linuxkpi/common/include/net/mac80211.h
new file mode 100644
index 000000000000..ee1ace3684de
--- /dev/null
+++ b/sys/compat/linuxkpi/common/include/net/mac80211.h
@@ -0,0 +1,2681 @@
+/*-
+ * Copyright (c) 2020-2025 The FreeBSD Foundation
+ * Copyright (c) 2020-2025 Bjoern A. Zeeb
+ *
+ * This software was developed by Björn Zeeb under sponsorship from
+ * the FreeBSD Foundation.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``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 OR CONTRIBUTORS 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.
+ */
+
+#ifndef _LINUXKPI_NET_MAC80211_H
+#define _LINUXKPI_NET_MAC80211_H
+
+#include <sys/types.h>
+
+#include <asm/atomic64.h>
+#include <linux/bitops.h>
+#include <linux/bitfield.h>
+#include <linux/etherdevice.h>
+#include <linux/ethtool.h>
+#include <linux/netdevice.h>
+#include <linux/skbuff.h>
+#include <linux/workqueue.h>
+#include <linux/dcache.h>
+#include <linux/ieee80211.h>
+#include <net/cfg80211.h>
+#include <net/if_inet6.h>
+
+#define ARPHRD_IEEE80211_RADIOTAP __LINE__ /* XXX TODO brcmfmac */
+
+#define WLAN_OUI_MICROSOFT (0x0050F2)
+#define WLAN_OUI_TYPE_MICROSOFT_WPA (1)
+#define WLAN_OUI_TYPE_MICROSOFT_TPC (8)
+#define WLAN_OUI_TYPE_WFA_P2P (9)
+#define WLAN_OUI_WFA (0x506F9A)
+
+#define IEEE80211_LINK_UNSPECIFIED 0x0f
+
+/* hw->conf.flags */
+enum ieee80211_hw_conf_flags {
+ IEEE80211_CONF_IDLE = BIT(0),
+ IEEE80211_CONF_PS = BIT(1),
+ IEEE80211_CONF_MONITOR = BIT(2),
+ IEEE80211_CONF_OFFCHANNEL = BIT(3),
+};
+
+/* (*ops->config()) */
+enum ieee80211_hw_conf_changed_flags {
+ IEEE80211_CONF_CHANGE_CHANNEL = BIT(0),
+ IEEE80211_CONF_CHANGE_IDLE = BIT(1),
+ IEEE80211_CONF_CHANGE_PS = BIT(2),
+ IEEE80211_CONF_CHANGE_MONITOR = BIT(3),
+ IEEE80211_CONF_CHANGE_POWER = BIT(4),
+};
+
+#define CFG80211_TESTMODE_CMD(_x) /* XXX TODO */
+#define CFG80211_TESTMODE_DUMP(_x) /* XXX TODO */
+
+#define FCS_LEN 4
+
+/* ops.configure_filter() */
+enum mcast_filter_flags {
+ FIF_ALLMULTI = BIT(0),
+ FIF_PROBE_REQ = BIT(1),
+ FIF_BCN_PRBRESP_PROMISC = BIT(2),
+ FIF_FCSFAIL = BIT(3),
+ FIF_OTHER_BSS = BIT(4),
+ FIF_PSPOLL = BIT(5),
+ FIF_CONTROL = BIT(6),
+ FIF_MCAST_ACTION = BIT(7),
+
+ /* Must stay last. */
+ FIF_FLAGS_MASK = BIT(8)-1,
+};
+
+enum ieee80211_bss_changed {
+ BSS_CHANGED_ARP_FILTER = BIT(0),
+ BSS_CHANGED_ASSOC = BIT(1),
+ BSS_CHANGED_BANDWIDTH = BIT(2),
+ BSS_CHANGED_BEACON = BIT(3),
+ BSS_CHANGED_BEACON_ENABLED = BIT(4),
+ BSS_CHANGED_BEACON_INFO = BIT(5),
+ BSS_CHANGED_BEACON_INT = BIT(6),
+ BSS_CHANGED_BSSID = BIT(7),
+ BSS_CHANGED_CQM = BIT(8),
+ BSS_CHANGED_ERP_CTS_PROT = BIT(9),
+ BSS_CHANGED_ERP_SLOT = BIT(10),
+ BSS_CHANGED_FTM_RESPONDER = BIT(11),
+ BSS_CHANGED_HT = BIT(12),
+ BSS_CHANGED_IDLE = BIT(13),
+ BSS_CHANGED_MU_GROUPS = BIT(14),
+ BSS_CHANGED_P2P_PS = BIT(15),
+ BSS_CHANGED_PS = BIT(16),
+ BSS_CHANGED_QOS = BIT(17),
+ BSS_CHANGED_TXPOWER = BIT(18),
+ BSS_CHANGED_HE_BSS_COLOR = BIT(19),
+ BSS_CHANGED_AP_PROBE_RESP = BIT(20),
+ BSS_CHANGED_BASIC_RATES = BIT(21),
+ BSS_CHANGED_ERP_PREAMBLE = BIT(22),
+ BSS_CHANGED_IBSS = BIT(23),
+ BSS_CHANGED_MCAST_RATE = BIT(24),
+ BSS_CHANGED_SSID = BIT(25),
+ BSS_CHANGED_FILS_DISCOVERY = BIT(26),
+ BSS_CHANGED_HE_OBSS_PD = BIT(27),
+ BSS_CHANGED_TWT = BIT(28),
+ BSS_CHANGED_UNSOL_BCAST_PROBE_RESP = BIT(30),
+ BSS_CHANGED_EHT_PUNCTURING = BIT(31),
+ BSS_CHANGED_MLD_VALID_LINKS = BIT_ULL(32),
+ BSS_CHANGED_MLD_TTLM = BIT_ULL(33),
+ BSS_CHANGED_TPE = BIT_ULL(34),
+};
+
+/* 802.11 Figure 9-256 Suite selector format. [OUI(3), SUITE TYPE(1)] */
+#define WLAN_CIPHER_SUITE_OUI(_oui, _x) (((_oui) << 8) | ((_x) & 0xff))
+
+/* 802.11 Table 9-131 Cipher suite selectors. */
+/* 802.1x suite B 11 */
+#define WLAN_CIPHER_SUITE(_x) WLAN_CIPHER_SUITE_OUI(0x000fac, _x)
+/* Use group 0 */
+#define WLAN_CIPHER_SUITE_WEP40 WLAN_CIPHER_SUITE(1)
+#define WLAN_CIPHER_SUITE_TKIP WLAN_CIPHER_SUITE(2)
+/* Reserved 3 */
+#define WLAN_CIPHER_SUITE_CCMP WLAN_CIPHER_SUITE(4) /* CCMP-128 */
+#define WLAN_CIPHER_SUITE_WEP104 WLAN_CIPHER_SUITE(5)
+#define WLAN_CIPHER_SUITE_AES_CMAC WLAN_CIPHER_SUITE(6) /* BIP-CMAC-128 */
+/* Group addressed traffic not allowed 7 */
+#define WLAN_CIPHER_SUITE_GCMP WLAN_CIPHER_SUITE(8)
+#define WLAN_CIPHER_SUITE_GCMP_256 WLAN_CIPHER_SUITE(9)
+#define WLAN_CIPHER_SUITE_CCMP_256 WLAN_CIPHER_SUITE(10)
+#define WLAN_CIPHER_SUITE_BIP_GMAC_128 WLAN_CIPHER_SUITE(11)
+#define WLAN_CIPHER_SUITE_BIP_GMAC_256 WLAN_CIPHER_SUITE(12)
+#define WLAN_CIPHER_SUITE_BIP_CMAC_256 WLAN_CIPHER_SUITE(13)
+/* Reserved 14-255 */
+
+/* See ISO/IEC JTC 1 N 9880 Table 11 */
+#define WLAN_CIPHER_SUITE_SMS4 WLAN_CIPHER_SUITE_OUI(0x001472, 1)
+
+
+/* 802.11 Table 9-133 AKM suite selectors. */
+#define WLAN_AKM_SUITE(_x) WLAN_CIPHER_SUITE_OUI(0x000fac, _x)
+/* Reserved 0 */
+#define WLAN_AKM_SUITE_8021X WLAN_AKM_SUITE(1)
+#define WLAN_AKM_SUITE_PSK WLAN_AKM_SUITE(2)
+#define WLAN_AKM_SUITE_FT_8021X WLAN_AKM_SUITE(3)
+#define WLAN_AKM_SUITE_FT_PSK WLAN_AKM_SUITE(4)
+#define WLAN_AKM_SUITE_8021X_SHA256 WLAN_AKM_SUITE(5)
+#define WLAN_AKM_SUITE_PSK_SHA256 WLAN_AKM_SUITE(6)
+/* TDLS 7 */
+#define WLAN_AKM_SUITE_SAE WLAN_AKM_SUITE(8)
+#define WLAN_AKM_SUITE_FT_OVER_SAE WLAN_AKM_SUITE(9)
+/* AP peer key 10 */
+/* 802.1x suite B 11 */
+/* 802.1x suite B 384 12 */
+/* FTo802.1x 384 13 */
+/* Reserved 14-255 */
+/* Apparently 11ax defines more. Seen (19,20) mentioned. */
+
+#define TKIP_PN_TO_IV16(_x) ((uint16_t)(_x & 0xffff))
+#define TKIP_PN_TO_IV32(_x) ((uint32_t)((_x >> 16) & 0xffffffff))
+
+enum ieee80211_neg_ttlm_res {
+ NEG_TTLM_RES_ACCEPT,
+ NEG_TTLM_RES_REJECT,
+};
+
+#define IEEE80211_TTLM_NUM_TIDS 8
+struct ieee80211_neg_ttlm {
+ uint16_t downlink[IEEE80211_TTLM_NUM_TIDS];
+ uint16_t uplink[IEEE80211_TTLM_NUM_TIDS];
+};
+
+/* 802.11-2020 9.4.2.55.3 A-MPDU Parameters field */
+#define IEEE80211_HT_AMPDU_PARM_FACTOR 0x3
+#define IEEE80211_HT_AMPDU_PARM_DENSITY_SHIFT 2
+#define IEEE80211_HT_AMPDU_PARM_DENSITY (0x7 << IEEE80211_HT_AMPDU_PARM_DENSITY_SHIFT)
+
+struct ieee80211_sta;
+
+struct ieee80211_ampdu_params {
+ struct ieee80211_sta *sta;
+ enum ieee80211_ampdu_mlme_action action;
+ uint16_t buf_size;
+ uint16_t timeout;
+ uint16_t ssn;
+ uint8_t tid;
+ bool amsdu;
+};
+
+struct ieee80211_bar {
+ /* TODO FIXME */
+ int control, start_seq_num;
+ uint8_t *ra;
+ uint16_t frame_control;
+};
+
+struct ieee80211_mutable_offsets {
+ /* TODO FIXME */
+ uint16_t tim_offset;
+ uint16_t cntdwn_counter_offs[2];
+
+ int mbssid_off;
+};
+
+struct mac80211_fils_discovery {
+ uint32_t max_interval;
+};
+
+struct ieee80211_chanctx_conf {
+ struct cfg80211_chan_def def;
+ struct cfg80211_chan_def min_def;
+ struct cfg80211_chan_def ap;
+
+ uint8_t rx_chains_dynamic;
+ uint8_t rx_chains_static;
+ bool radar_enabled;
+
+ /* Must stay last. */
+ uint8_t drv_priv[0] __aligned(CACHE_LINE_SIZE);
+};
+
+struct ieee80211_rate_status {
+ struct rate_info rate_idx;
+ uint8_t try_count;
+};
+
+struct ieee80211_ema_beacons {
+ uint8_t cnt;
+ struct {
+ struct sk_buff *skb;
+ struct ieee80211_mutable_offsets offs;
+ } bcn[0];
+};
+
+struct ieee80211_chanreq {
+ struct cfg80211_chan_def oper;
+};
+
+#define WLAN_MEMBERSHIP_LEN (8)
+#define WLAN_USER_POSITION_LEN (16)
+
+/*
+ * 802.11ac-2013, 8.4.2.164 VHT Transmit Power Envelope element
+ * 802.11-???? ?
+ */
+struct ieee80211_parsed_tpe_eirp {
+ int8_t power[5];
+ uint8_t count;
+ bool valid;
+};
+struct ieee80211_parsed_tpe_psd {
+ int8_t power[16];
+ uint8_t count;
+ bool valid;
+};
+struct ieee80211_parsed_tpe {
+ /* We see access to [0] so assume at least 2. */
+ struct ieee80211_parsed_tpe_eirp max_local[2];
+ struct ieee80211_parsed_tpe_eirp max_reg_client[2];
+ struct ieee80211_parsed_tpe_psd psd_local[2];
+ struct ieee80211_parsed_tpe_psd psd_reg_client[2];
+};
+
+struct ieee80211_bss_conf {
+ /* TODO FIXME */
+ struct ieee80211_vif *vif;
+ struct cfg80211_bss *bss;
+ const uint8_t *bssid;
+ uint8_t addr[ETH_ALEN];
+ uint8_t link_id;
+ uint8_t _pad0;
+ uint8_t transmitter_bssid[ETH_ALEN];
+ struct ieee80211_ftm_responder_params *ftmr_params;
+ struct ieee80211_p2p_noa_attr p2p_noa_attr;
+ struct ieee80211_chanreq chanreq;
+ __be32 arp_addr_list[1]; /* XXX TODO */
+ struct ieee80211_rate *beacon_rate;
+ struct {
+ uint8_t membership[WLAN_MEMBERSHIP_LEN];
+ uint8_t position[WLAN_USER_POSITION_LEN];
+ } mu_group;
+ struct {
+ uint32_t params;
+ /* single field struct? */
+ } he_oper;
+ struct cfg80211_he_bss_color he_bss_color;
+ struct ieee80211_he_obss_pd he_obss_pd;
+
+ bool ht_ldpc;
+ bool vht_ldpc;
+ bool he_ldpc;
+ bool vht_mu_beamformee;
+ bool vht_mu_beamformer;
+ bool vht_su_beamformee;
+ bool vht_su_beamformer;
+ bool he_mu_beamformer;
+ bool he_su_beamformee;
+ bool he_su_beamformer;
+ bool he_full_ul_mumimo;
+ bool eht_su_beamformee;
+ bool eht_su_beamformer;
+ bool eht_mu_beamformer;
+
+ uint16_t ht_operation_mode;
+ int arp_addr_cnt;
+ uint16_t eht_puncturing;
+
+ uint8_t dtim_period;
+ uint8_t sync_dtim_count;
+ uint8_t bss_param_ch_cnt_link_id;
+ bool qos;
+ bool twt_broadcast;
+ bool use_cts_prot;
+ bool use_short_preamble;
+ bool use_short_slot;
+ bool he_support;
+ bool eht_support;
+ bool csa_active;
+ bool mu_mimo_owner;
+ bool color_change_active;
+ uint32_t sync_device_ts;
+ uint64_t sync_tsf;
+ uint16_t beacon_int;
+ int16_t txpower;
+ uint32_t basic_rates;
+ int mcast_rate[NUM_NL80211_BANDS];
+ enum ieee80211_ap_reg_power power_type;
+ struct cfg80211_bitrate_mask beacon_tx_rate;
+ struct mac80211_fils_discovery fils_discovery;
+ struct ieee80211_chanctx_conf *chanctx_conf;
+ struct ieee80211_vif *mbssid_tx_vif;
+ struct ieee80211_parsed_tpe tpe;
+
+ int ack_enabled, bssid_index, bssid_indicator, cqm_rssi_hyst, cqm_rssi_thold, ema_ap, frame_time_rts_th, ftm_responder;
+ int htc_trig_based_pkt_ext;
+ int multi_sta_back_32bit, nontransmitted;
+ int profile_periodicity;
+ int twt_requester, uora_exists, uora_ocw_range;
+ int assoc_capability, enable_beacon, hidden_ssid, ibss_joined, twt_protected;
+ int twt_responder, unsol_bcast_probe_resp_interval;
+};
+
+struct ieee80211_channel_switch {
+ /* TODO FIXME */
+ int block_tx, count, delay, device_timestamp, timestamp;
+ uint8_t link_id;
+ struct cfg80211_chan_def chandef;
+};
+
+enum ieee80211_event_type {
+ BA_FRAME_TIMEOUT,
+ BAR_RX_EVENT,
+ MLME_EVENT,
+ RSSI_EVENT,
+};
+
+enum ieee80211_rssi_event_data {
+ RSSI_EVENT_LOW,
+ RSSI_EVENT_HIGH,
+};
+
+enum ieee80211_mlme_event_data {
+ ASSOC_EVENT,
+ AUTH_EVENT,
+ DEAUTH_RX_EVENT,
+ DEAUTH_TX_EVENT,
+};
+
+enum ieee80211_mlme_event_status {
+ MLME_DENIED,
+ MLME_TIMEOUT,
+};
+
+struct ieee80211_mlme_event {
+ enum ieee80211_mlme_event_data data;
+ enum ieee80211_mlme_event_status status;
+ int reason;
+};
+
+struct ieee80211_event {
+ /* TODO FIXME */
+ enum ieee80211_event_type type;
+ union {
+ struct {
+ int ssn;
+ struct ieee80211_sta *sta;
+ uint8_t tid;
+ } ba;
+ struct ieee80211_mlme_event mlme;
+ } u;
+};
+
+struct ieee80211_ftm_responder_params {
+ /* TODO FIXME */
+ uint8_t *lci;
+ uint8_t *civicloc;
+ int lci_len;
+ int civicloc_len;
+};
+
+struct ieee80211_conf {
+ int dynamic_ps_timeout;
+ int power_level;
+ uint32_t listen_interval;
+ bool radar_enabled;
+ enum ieee80211_hw_conf_flags flags;
+ struct cfg80211_chan_def chandef;
+};
+
+enum ieee80211_hw_flags {
+ IEEE80211_HW_AMPDU_AGGREGATION,
+ IEEE80211_HW_AP_LINK_PS,
+ IEEE80211_HW_BUFF_MMPDU_TXQ,
+ IEEE80211_HW_CHANCTX_STA_CSA,
+ IEEE80211_HW_CONNECTION_MONITOR,
+ IEEE80211_HW_DEAUTH_NEED_MGD_TX_PREP,
+ IEEE80211_HW_HAS_RATE_CONTROL,
+ IEEE80211_HW_MFP_CAPABLE,
+ IEEE80211_HW_NEEDS_UNIQUE_STA_ADDR,
+ IEEE80211_HW_REPORTS_TX_ACK_STATUS,
+ IEEE80211_HW_RX_INCLUDES_FCS,
+ IEEE80211_HW_SIGNAL_DBM,
+ IEEE80211_HW_SINGLE_SCAN_ON_ALL_BANDS,
+ IEEE80211_HW_SPECTRUM_MGMT,
+ IEEE80211_HW_STA_MMPDU_TXQ,
+ IEEE80211_HW_SUPPORTS_AMSDU_IN_AMPDU,
+ IEEE80211_HW_SUPPORTS_CLONED_SKBS,
+ IEEE80211_HW_SUPPORTS_DYNAMIC_PS,
+ IEEE80211_HW_SUPPORTS_MULTI_BSSID,
+ IEEE80211_HW_SUPPORTS_ONLY_HE_MULTI_BSSID,
+ IEEE80211_HW_SUPPORTS_PS,
+ IEEE80211_HW_SUPPORTS_REORDERING_BUFFER,
+ IEEE80211_HW_SUPPORTS_VHT_EXT_NSS_BW,
+ IEEE80211_HW_SUPPORT_FAST_XMIT,
+ IEEE80211_HW_TDLS_WIDER_BW,
+ IEEE80211_HW_TIMING_BEACON_ONLY,
+ IEEE80211_HW_TX_AMPDU_SETUP_IN_HW,
+ IEEE80211_HW_TX_AMSDU,
+ IEEE80211_HW_TX_FRAG_LIST,
+ IEEE80211_HW_USES_RSS,
+ IEEE80211_HW_WANT_MONITOR_VIF,
+ IEEE80211_HW_SW_CRYPTO_CONTROL,
+ IEEE80211_HW_SUPPORTS_TX_FRAG,
+ IEEE80211_HW_SUPPORTS_TDLS_BUFFER_STA,
+ IEEE80211_HW_SUPPORTS_PER_STA_GTK,
+ IEEE80211_HW_REPORTS_LOW_ACK,
+ IEEE80211_HW_QUEUE_CONTROL,
+ IEEE80211_HW_SUPPORTS_RX_DECAP_OFFLOAD,
+ IEEE80211_HW_SUPPORTS_TX_ENCAP_OFFLOAD,
+ IEEE80211_HW_SUPPORTS_RC_TABLE,
+ IEEE80211_HW_DETECTS_COLOR_COLLISION,
+ IEEE80211_HW_DISALLOW_PUNCTURING,
+ IEEE80211_HW_DISALLOW_PUNCTURING_5GHZ,
+ IEEE80211_HW_TX_STATUS_NO_AMPDU_LEN,
+ IEEE80211_HW_HANDLES_QUIET_CSA,
+ IEEE80211_HW_NO_VIRTUAL_MONITOR,
+
+ /* Keep last. */
+ NUM_IEEE80211_HW_FLAGS
+};
+
+struct ieee80211_hw {
+
+ struct wiphy *wiphy;
+
+ /* TODO FIXME */
+ int extra_tx_headroom, weight_multiplier;
+ int max_rate_tries, max_rates, max_report_rates;
+ const char *rate_control_algorithm;
+ struct {
+ uint16_t units_pos; /* radiotap "spec" is .. inconsistent. */
+ uint16_t accuracy;
+ } radiotap_timestamp;
+ size_t sta_data_size;
+ size_t vif_data_size;
+ size_t chanctx_data_size;
+ size_t txq_data_size;
+ uint16_t radiotap_mcs_details;
+ uint16_t radiotap_vht_details;
+ uint16_t queues;
+ uint16_t offchannel_tx_hw_queue;
+ uint16_t uapsd_max_sp_len;
+ uint16_t uapsd_queues;
+ uint16_t max_rx_aggregation_subframes;
+ uint16_t max_tx_aggregation_subframes;
+ uint16_t max_tx_fragments;
+ uint16_t max_listen_interval;
+ uint32_t extra_beacon_tailroom;
+ netdev_features_t netdev_features;
+ unsigned long flags[BITS_TO_LONGS(NUM_IEEE80211_HW_FLAGS)];
+ struct ieee80211_conf conf;
+
+#if 0 /* leave here for documentation purposes. This does NOT work. */
+ /* Must stay last. */
+ uint8_t priv[0] __aligned(CACHE_LINE_SIZE);
+#else
+ void *priv;
+#endif
+};
+
+enum ieee802111_key_flag {
+ IEEE80211_KEY_FLAG_GENERATE_IV = BIT(0),
+ IEEE80211_KEY_FLAG_GENERATE_MMIC = BIT(1),
+ IEEE80211_KEY_FLAG_PAIRWISE = BIT(2),
+ IEEE80211_KEY_FLAG_PUT_IV_SPACE = BIT(3),
+ IEEE80211_KEY_FLAG_PUT_MIC_SPACE = BIT(4),
+ IEEE80211_KEY_FLAG_SW_MGMT_TX = BIT(5),
+ IEEE80211_KEY_FLAG_GENERATE_IV_MGMT = BIT(6),
+ IEEE80211_KEY_FLAG_GENERATE_MMIE = BIT(7),
+ IEEE80211_KEY_FLAG_RESERVE_TAILROOM = BIT(8),
+ IEEE80211_KEY_FLAG_SPP_AMSDU = BIT(9),
+};
+
+#define IEEE80211_KEY_FLAG_BITS \
+ "\20\1GENERATE_IV\2GENERATE_MMIC\3PAIRWISE\4PUT_IV_SPACE" \
+ "\5PUT_MIC_SPACE\6SW_MGMT_TX\7GENERATE_IV_MGMT\10GENERATE_MMIE" \
+ "\11RESERVE_TAILROOM\12SPP_AMSDU"
+
+struct ieee80211_key_conf {
+#if defined(__FreeBSD__)
+ const struct ieee80211_key *_k; /* backpointer to net80211 */
+#endif
+ atomic64_t tx_pn;
+ uint32_t cipher;
+ uint8_t icv_len; /* __unused nowadays? */
+ uint8_t iv_len;
+ uint8_t hw_key_idx; /* Set by drv. */
+ uint8_t keyidx;
+ uint16_t flags;
+ int8_t link_id; /* signed! */
+ uint8_t keylen;
+ uint8_t key[0]; /* Must stay last! */
+};
+
+struct ieee80211_key_seq {
+ /* TODO FIXME */
+ union {
+ struct {
+ uint8_t seq[IEEE80211_MAX_PN_LEN];
+ uint8_t seq_len;
+ } hw;
+ struct {
+ uint8_t pn[IEEE80211_CCMP_PN_LEN];
+ } ccmp;
+ struct {
+ uint8_t pn[IEEE80211_GCMP_PN_LEN];
+ } gcmp;
+ struct {
+ uint8_t pn[IEEE80211_CMAC_PN_LEN];
+ } aes_cmac;
+ struct {
+ uint8_t pn[IEEE80211_GMAC_PN_LEN];
+ } aes_gmac;
+ struct {
+ uint32_t iv32;
+ uint16_t iv16;
+ } tkip;
+ };
+};
+
+
+enum ieee80211_rx_status_flags {
+ RX_FLAG_ALLOW_SAME_PN = BIT(0),
+ RX_FLAG_AMPDU_DETAILS = BIT(1),
+ RX_FLAG_AMPDU_EOF_BIT = BIT(2),
+ RX_FLAG_AMPDU_EOF_BIT_KNOWN = BIT(3),
+ RX_FLAG_DECRYPTED = BIT(4),
+ RX_FLAG_DUP_VALIDATED = BIT(5),
+ RX_FLAG_FAILED_FCS_CRC = BIT(6),
+ RX_FLAG_ICV_STRIPPED = BIT(7),
+ RX_FLAG_MACTIME = BIT(8) | BIT(9),
+ RX_FLAG_MACTIME_PLCP_START = 1 << 8,
+ RX_FLAG_MACTIME_START = 2 << 8,
+ RX_FLAG_MACTIME_END = 3 << 8,
+ RX_FLAG_MIC_STRIPPED = BIT(10),
+ RX_FLAG_MMIC_ERROR = BIT(11),
+ RX_FLAG_MMIC_STRIPPED = BIT(12),
+ RX_FLAG_NO_PSDU = BIT(13),
+ RX_FLAG_PN_VALIDATED = BIT(14),
+ RX_FLAG_RADIOTAP_HE = BIT(15),
+ RX_FLAG_RADIOTAP_HE_MU = BIT(16),
+ RX_FLAG_RADIOTAP_LSIG = BIT(17),
+ RX_FLAG_RADIOTAP_VENDOR_DATA = BIT(18),
+ RX_FLAG_NO_SIGNAL_VAL = BIT(19),
+ RX_FLAG_IV_STRIPPED = BIT(20),
+ RX_FLAG_AMPDU_IS_LAST = BIT(21),
+ RX_FLAG_AMPDU_LAST_KNOWN = BIT(22),
+ RX_FLAG_AMSDU_MORE = BIT(23),
+ /* = BIT(24), */
+ RX_FLAG_ONLY_MONITOR = BIT(25),
+ RX_FLAG_SKIP_MONITOR = BIT(26),
+ RX_FLAG_8023 = BIT(27),
+ RX_FLAG_RADIOTAP_TLV_AT_END = BIT(28),
+ /* = BIT(29), */
+ RX_FLAG_MACTIME_IS_RTAP_TS64 = BIT(30),
+ RX_FLAG_FAILED_PLCP_CRC = BIT(31),
+};
+
+#define IEEE80211_RX_STATUS_FLAGS_BITS \
+ "\20\1ALLOW_SAME_PN\2AMPDU_DETAILS\3AMPDU_EOF_BIT\4AMPDU_EOF_BIT_KNOWN" \
+ "\5DECRYPTED\6DUP_VALIDATED\7FAILED_FCS_CRC\10ICV_STRIPPED" \
+ "\11MACTIME_PLCP_START\12MACTIME_START\13MIC_STRIPPED" \
+ "\14MMIC_ERROR\15MMIC_STRIPPED\16NO_PSDU\17PN_VALIDATED" \
+ "\20RADIOTAP_HE\21RADIOTAP_HE_MU\22RADIOTAP_LSIG\23RADIOTAP_VENDOR_DATA" \
+ "\24NO_SIGNAL_VAL\25IV_STRIPPED\26AMPDU_IS_LAST\27AMPDU_LAST_KNOWN" \
+ "\30AMSDU_MORE\31MACTIME_END\32ONLY_MONITOR\33SKIP_MONITOR" \
+ "\348023\35RADIOTAP_TLV_AT_END\36MACTIME\37MACTIME_IS_RTAP_TS64" \
+ "\40FAILED_PLCP_CRC"
+
+enum mac80211_rx_encoding {
+ RX_ENC_LEGACY = 0,
+ RX_ENC_HT,
+ RX_ENC_VHT,
+ RX_ENC_HE,
+ RX_ENC_EHT,
+};
+
+struct ieee80211_rx_status {
+ /* TODO FIXME, this is too large. Over-reduce types to u8 where possible. */
+ union {
+ uint64_t boottime_ns;
+ int64_t ack_tx_hwtstamp;
+ };
+ uint64_t mactime;
+ uint32_t device_timestamp;
+ enum ieee80211_rx_status_flags flag;
+ uint16_t freq;
+ uint8_t encoding:3, bw:4; /* enum mac80211_rx_encoding, rate_info_bw */ /* See mt76.h */
+ uint8_t ampdu_reference;
+ uint8_t band;
+ uint8_t chains;
+ int8_t chain_signal[IEEE80211_MAX_CHAINS];
+ int8_t signal;
+ uint8_t enc_flags;
+ union {
+ struct {
+ uint8_t he_ru:3; /* nl80211::enum nl80211_he_ru_alloc */
+ uint8_t he_gi:2; /* nl80211::enum nl80211_he_gi */
+ uint8_t he_dcm:1;
+ };
+ struct {
+ uint8_t ru:4; /* nl80211::enum nl80211_eht_ru_alloc */
+ uint8_t gi:2; /* nl80211::enum nl80211_eht_gi */
+ } eht;
+ };
+ bool link_valid;
+ uint8_t link_id; /* very incosistent sizes? */
+ uint8_t zero_length_psdu_type;
+ uint8_t nss;
+ uint8_t rate_idx;
+};
+
+struct ieee80211_tx_status {
+ struct ieee80211_sta *sta;
+ struct ieee80211_tx_info *info;
+ int64_t ack_hwtstamp;
+
+ u8 n_rates;
+ struct ieee80211_rate_status *rates;
+
+ struct sk_buff *skb;
+ struct list_head *free_list;
+};
+
+struct ieee80211_scan_ies {
+ /* TODO FIXME */
+ int common_ie_len;
+ int len[NUM_NL80211_BANDS];
+ uint8_t *common_ies;
+ uint8_t *ies[NUM_NL80211_BANDS];
+};
+
+struct ieee80211_scan_request {
+ struct ieee80211_scan_ies ies;
+ struct cfg80211_scan_request req;
+};
+
+struct ieee80211_txq {
+ struct ieee80211_sta *sta;
+ struct ieee80211_vif *vif;
+ int ac;
+ uint8_t tid;
+
+ /* Must stay last. */
+ uint8_t drv_priv[0] __aligned(CACHE_LINE_SIZE);
+};
+
+struct ieee80211_sta_rates {
+ /* XXX TODO */
+ /* XXX some _rcu thing */
+ struct {
+ uint8_t idx;
+ uint8_t count;
+ uint16_t flags;
+ } rate[4]; /* XXX what is the real number? */
+};
+
+struct ieee80211_sta_txpwr {
+ /* XXX TODO */
+ enum nl80211_tx_power_setting type;
+ short power;
+};
+
+#define IEEE80211_NUM_TIDS 16 /* net80211::WME_NUM_TID */
+struct ieee80211_sta_agg {
+ uint16_t max_amsdu_len;
+ uint16_t max_rc_amsdu_len;
+ uint16_t max_tid_amsdu_len[IEEE80211_NUM_TIDS];
+};
+
+struct ieee80211_link_sta {
+ struct ieee80211_sta *sta;
+ uint8_t addr[ETH_ALEN];
+ uint8_t link_id;
+ uint32_t supp_rates[NUM_NL80211_BANDS];
+ struct ieee80211_sta_ht_cap ht_cap;
+ struct ieee80211_sta_vht_cap vht_cap;
+ struct ieee80211_sta_he_cap he_cap;
+ struct ieee80211_he_6ghz_capa he_6ghz_capa;
+ struct ieee80211_sta_eht_cap eht_cap;
+ uint8_t rx_nss;
+ enum ieee80211_sta_rx_bandwidth bandwidth;
+ enum ieee80211_smps_mode smps_mode;
+ struct ieee80211_sta_agg agg;
+ struct ieee80211_sta_txpwr txpwr;
+};
+
+struct ieee80211_sta {
+ /* TODO FIXME */
+ int max_amsdu_subframes;
+ int mfp, smps_mode, tdls, tdls_initiator;
+ struct ieee80211_txq *txq[IEEE80211_NUM_TIDS + 1]; /* iwlwifi: 8 and adds +1 to tid_data, net80211::IEEE80211_TID_SIZE */
+ struct ieee80211_sta_rates *rates; /* some rcu thing? */
+ uint8_t addr[ETH_ALEN];
+ uint16_t aid;
+ bool wme;
+ bool mlo;
+ uint8_t max_sp;
+ uint8_t uapsd_queues;
+ uint16_t valid_links;
+
+ struct ieee80211_link_sta deflink;
+ struct ieee80211_link_sta *link[IEEE80211_MLD_MAX_NUM_LINKS]; /* rcu? */
+
+ /* Must stay last. */
+ uint8_t drv_priv[0] __aligned(CACHE_LINE_SIZE);
+};
+
+struct ieee80211_tdls_ch_sw_params {
+ /* TODO FIXME */
+ int action_code, ch_sw_tm_ie, status, switch_time, switch_timeout, timestamp;
+ struct ieee80211_sta *sta;
+ struct cfg80211_chan_def *chandef;
+ struct sk_buff *tmpl_skb;
+};
+
+struct ieee80211_tx_control {
+ /* TODO FIXME */
+ struct ieee80211_sta *sta;
+};
+
+struct ieee80211_tx_queue_params {
+ /* These types are based on iwlwifi FW structs. */
+ uint16_t cw_min;
+ uint16_t cw_max;
+ uint16_t txop;
+ uint8_t aifs;
+
+ /* TODO FIXME */
+ int acm, mu_edca, uapsd;
+ struct ieee80211_he_mu_edca_param_ac_rec mu_edca_param_rec;
+};
+
+struct ieee80211_tx_rate {
+ uint8_t idx;
+ uint16_t count:5,
+ flags:11;
+};
+
+enum ieee80211_vif_driver_flags {
+ IEEE80211_VIF_BEACON_FILTER = BIT(0),
+ IEEE80211_VIF_SUPPORTS_CQM_RSSI = BIT(1),
+ IEEE80211_VIF_SUPPORTS_UAPSD = BIT(2),
+#if defined(LINUXKPI_VERSION) && (LINUXKPI_VERSION < 60600) /* v6.6 */
+ IEEE80211_VIF_DISABLE_SMPS_OVERRIDE = BIT(3), /* Renamed to IEEE80211_VIF_EML_ACTIVE. */
+#endif
+ IEEE80211_VIF_EML_ACTIVE = BIT(4),
+ IEEE80211_VIF_IGNORE_OFDMA_WIDER_BW = BIT(5),
+ IEEE80211_VIF_REMOVE_AP_AFTER_DISASSOC = BIT(6),
+};
+
+#define IEEE80211_BSS_ARP_ADDR_LIST_LEN 4
+
+struct ieee80211_vif_cfg {
+ uint16_t aid;
+ uint16_t eml_cap;
+ uint16_t eml_med_sync_delay;
+ bool assoc;
+ bool ps;
+ bool idle;
+ bool ibss_joined;
+ int arp_addr_cnt;
+ size_t ssid_len;
+ uint32_t arp_addr_list[IEEE80211_BSS_ARP_ADDR_LIST_LEN]; /* big endian */
+ uint8_t ssid[IEEE80211_NWID_LEN];
+ uint8_t ap_addr[ETH_ALEN];
+};
+
+struct ieee80211_vif {
+ /* TODO FIXME */
+ enum nl80211_iftype type;
+ int cab_queue;
+ int offload_flags;
+ enum ieee80211_vif_driver_flags driver_flags;
+ bool p2p;
+ bool probe_req_reg;
+ uint8_t addr[ETH_ALEN];
+ struct ieee80211_vif_cfg cfg;
+ struct ieee80211_txq *txq;
+ struct ieee80211_bss_conf bss_conf;
+ struct ieee80211_bss_conf *link_conf[IEEE80211_MLD_MAX_NUM_LINKS]; /* rcu? */
+ uint8_t hw_queue[IEEE80211_NUM_ACS];
+ uint16_t active_links;
+ uint16_t valid_links;
+ struct ieee80211_vif *mbssid_tx_vif;
+
+/* #ifdef CONFIG_MAC80211_DEBUGFS */ /* Do not change structure depending on compile-time option. */
+ struct dentry *debugfs_dir;
+/* #endif */
+
+ /* Must stay last. */
+ uint8_t drv_priv[0] __aligned(CACHE_LINE_SIZE);
+};
+
+struct ieee80211_vif_chanctx_switch {
+ struct ieee80211_chanctx_conf *old_ctx, *new_ctx;
+ struct ieee80211_vif *vif;
+ struct ieee80211_bss_conf *link_conf;
+};
+
+struct ieee80211_prep_tx_info {
+ uint16_t duration;
+ uint16_t subtype;
+ bool success;
+ bool was_assoc;
+ int link_id;
+};
+
+/* XXX-BZ too big, over-reduce size to u8, and array sizes to minuimum to fit in skb->cb. */
+/* Also warning: some sizes change by pointer size! This is 64bit only. */
+struct ieee80211_tx_info {
+ enum ieee80211_tx_info_flags flags; /* 32 bits */
+ /* TODO FIXME */
+ enum nl80211_band band; /* 3 bits */
+ uint16_t hw_queue:4, /* 4 bits */
+ tx_time_est:10; /* 10 bits */
+ union {
+ struct {
+ struct ieee80211_tx_rate rates[4];
+ bool use_rts;
+ uint8_t antennas:2;
+ struct ieee80211_vif *vif;
+ struct ieee80211_key_conf *hw_key;
+ enum ieee80211_tx_control_flags flags;
+ } control;
+ struct {
+ struct ieee80211_tx_rate rates[4];
+ uint32_t ack_signal;
+ uint8_t ampdu_ack_len;
+ uint8_t ampdu_len;
+ uint8_t antenna;
+ uint16_t tx_time;
+ uint8_t flags;
+ void *status_driver_data[16 / sizeof(void *)]; /* XXX TODO */
+ } status;
+#define IEEE80211_TX_INFO_DRIVER_DATA_SIZE 40
+ void *driver_data[IEEE80211_TX_INFO_DRIVER_DATA_SIZE / sizeof(void *)];
+ };
+};
+
+/* net80211 conflict */
+struct linuxkpi_ieee80211_tim_ie {
+ uint8_t dtim_count;
+ uint8_t dtim_period;
+ uint8_t bitmap_ctrl;
+ uint8_t *virtual_map;
+};
+#define ieee80211_tim_ie linuxkpi_ieee80211_tim_ie
+
+enum ieee80211_iface_iter {
+ IEEE80211_IFACE_ITER_NORMAL = BIT(0),
+ IEEE80211_IFACE_ITER_RESUME_ALL = BIT(1),
+ IEEE80211_IFACE_SKIP_SDATA_NOT_IN_DRIVER = BIT(2), /* seems to be an iter flag */
+ IEEE80211_IFACE_ITER_ACTIVE = BIT(3),
+
+ /* Internal flags only. */
+ IEEE80211_IFACE_ITER__ATOMIC = BIT(6),
+ IEEE80211_IFACE_ITER__MTX = BIT(8),
+};
+
+enum set_key_cmd {
+ SET_KEY,
+ DISABLE_KEY,
+};
+
+/* 802.11-2020, 9.4.2.55.2 HT Capability Information field. */
+enum rx_enc_flags {
+ RX_ENC_FLAG_SHORTPRE = BIT(0),
+ RX_ENC_FLAG_SHORT_GI = BIT(2),
+ RX_ENC_FLAG_HT_GF = BIT(3),
+ RX_ENC_FLAG_STBC_MASK = BIT(4) | BIT(5),
+#define RX_ENC_FLAG_STBC_SHIFT 4
+ RX_ENC_FLAG_LDPC = BIT(6),
+ RX_ENC_FLAG_BF = BIT(7),
+};
+
+enum sta_notify_cmd {
+ STA_NOTIFY_AWAKE,
+ STA_NOTIFY_SLEEP,
+};
+
+struct ieee80211_low_level_stats {
+ /* Can we make them uint64_t? */
+ uint32_t dot11ACKFailureCount;
+ uint32_t dot11FCSErrorCount;
+ uint32_t dot11RTSFailureCount;
+ uint32_t dot11RTSSuccessCount;
+};
+
+enum ieee80211_offload_flags {
+ IEEE80211_OFFLOAD_ENCAP_4ADDR,
+ IEEE80211_OFFLOAD_ENCAP_ENABLED,
+ IEEE80211_OFFLOAD_DECAP_ENABLED,
+};
+
+struct ieee80211_ops {
+ /* TODO FIXME */
+ int (*start)(struct ieee80211_hw *);
+ void (*stop)(struct ieee80211_hw *, bool);
+
+ int (*config)(struct ieee80211_hw *, int, u32);
+ void (*reconfig_complete)(struct ieee80211_hw *, enum ieee80211_reconfig_type);
+
+ void (*prep_add_interface)(struct ieee80211_hw *, enum nl80211_iftype);
+ int (*add_interface)(struct ieee80211_hw *, struct ieee80211_vif *);
+ void (*remove_interface)(struct ieee80211_hw *, struct ieee80211_vif *);
+ int (*change_interface)(struct ieee80211_hw *, struct ieee80211_vif *, enum nl80211_iftype, bool);
+
+ void (*sw_scan_start)(struct ieee80211_hw *, struct ieee80211_vif *, const u8 *);
+ void (*sw_scan_complete)(struct ieee80211_hw *, struct ieee80211_vif *);
+ int (*sched_scan_start)(struct ieee80211_hw *, struct ieee80211_vif *, struct cfg80211_sched_scan_request *, struct ieee80211_scan_ies *);
+ int (*sched_scan_stop)(struct ieee80211_hw *, struct ieee80211_vif *);
+ int (*hw_scan)(struct ieee80211_hw *, struct ieee80211_vif *, struct ieee80211_scan_request *);
+ void (*cancel_hw_scan)(struct ieee80211_hw *, struct ieee80211_vif *);
+
+ int (*conf_tx)(struct ieee80211_hw *, struct ieee80211_vif *, u32, u16, const struct ieee80211_tx_queue_params *);
+ void (*tx)(struct ieee80211_hw *, struct ieee80211_tx_control *, struct sk_buff *);
+ int (*tx_last_beacon)(struct ieee80211_hw *);
+ void (*wake_tx_queue)(struct ieee80211_hw *, struct ieee80211_txq *);
+
+ void (*mgd_prepare_tx)(struct ieee80211_hw *, struct ieee80211_vif *, struct ieee80211_prep_tx_info *);
+ void (*mgd_complete_tx)(struct ieee80211_hw *, struct ieee80211_vif *, struct ieee80211_prep_tx_info *);
+ void (*mgd_protect_tdls_discover)(struct ieee80211_hw *, struct ieee80211_vif *, unsigned int);
+
+ void (*flush)(struct ieee80211_hw *, struct ieee80211_vif *, u32, bool);
+ void (*flush_sta)(struct ieee80211_hw *, struct ieee80211_vif *, struct ieee80211_sta *);
+
+ int (*set_frag_threshold)(struct ieee80211_hw *, int, u32);
+
+ void (*sync_rx_queues)(struct ieee80211_hw *);
+
+ void (*allow_buffered_frames)(struct ieee80211_hw *, struct ieee80211_sta *, u16, int, enum ieee80211_frame_release_type, bool);
+ void (*release_buffered_frames)(struct ieee80211_hw *, struct ieee80211_sta *, u16, int, enum ieee80211_frame_release_type, bool);
+
+ int (*sta_add)(struct ieee80211_hw *, struct ieee80211_vif *, struct ieee80211_sta *);
+ int (*sta_remove)(struct ieee80211_hw *, struct ieee80211_vif *, struct ieee80211_sta *);
+ int (*sta_set_txpwr)(struct ieee80211_hw *, struct ieee80211_vif *, struct ieee80211_sta *);
+ void (*sta_statistics)(struct ieee80211_hw *, struct ieee80211_vif *, struct ieee80211_sta *, struct station_info *);
+ void (*sta_pre_rcu_remove)(struct ieee80211_hw *, struct ieee80211_vif *, struct ieee80211_sta *);
+ int (*sta_state)(struct ieee80211_hw *, struct ieee80211_vif *, struct ieee80211_sta *, enum ieee80211_sta_state, enum ieee80211_sta_state);
+ void (*sta_notify)(struct ieee80211_hw *, struct ieee80211_vif *, enum sta_notify_cmd, struct ieee80211_sta *);
+ void (*sta_rc_update)(struct ieee80211_hw *, struct ieee80211_vif *, struct ieee80211_sta *, u32);
+ void (*link_sta_rc_update)(struct ieee80211_hw *, struct ieee80211_vif *, struct ieee80211_link_sta *, u32);
+ void (*sta_rate_tbl_update)(struct ieee80211_hw *, struct ieee80211_vif *, struct ieee80211_sta *);
+ void (*sta_set_4addr)(struct ieee80211_hw *, struct ieee80211_vif *, struct ieee80211_sta *, bool);
+ void (*sta_set_decap_offload)(struct ieee80211_hw *, struct ieee80211_vif *, struct ieee80211_sta *, bool);
+
+ u64 (*prepare_multicast)(struct ieee80211_hw *, struct netdev_hw_addr_list *);
+
+ int (*ampdu_action)(struct ieee80211_hw *, struct ieee80211_vif *, struct ieee80211_ampdu_params *);
+
+ bool (*can_aggregate_in_amsdu)(struct ieee80211_hw *, struct sk_buff *, struct sk_buff *);
+
+ int (*pre_channel_switch)(struct ieee80211_hw *, struct ieee80211_vif *, struct ieee80211_channel_switch *);
+ int (*post_channel_switch)(struct ieee80211_hw *, struct ieee80211_vif *, struct ieee80211_bss_conf *);
+ void (*channel_switch)(struct ieee80211_hw *, struct ieee80211_vif *, struct ieee80211_channel_switch *);
+ void (*channel_switch_beacon)(struct ieee80211_hw *, struct ieee80211_vif *, struct cfg80211_chan_def *);
+ void (*abort_channel_switch)(struct ieee80211_hw *, struct ieee80211_vif *, struct ieee80211_bss_conf *);
+ void (*channel_switch_rx_beacon)(struct ieee80211_hw *, struct ieee80211_vif *, struct ieee80211_channel_switch *);
+ int (*tdls_channel_switch)(struct ieee80211_hw *, struct ieee80211_vif *, struct ieee80211_sta *, u8, struct cfg80211_chan_def *, struct sk_buff *, u32);
+ void (*tdls_cancel_channel_switch)(struct ieee80211_hw *, struct ieee80211_vif *, struct ieee80211_sta *);
+ void (*tdls_recv_channel_switch)(struct ieee80211_hw *, struct ieee80211_vif *, struct ieee80211_tdls_ch_sw_params *);
+
+ int (*add_chanctx)(struct ieee80211_hw *, struct ieee80211_chanctx_conf *);
+ void (*remove_chanctx)(struct ieee80211_hw *, struct ieee80211_chanctx_conf *);
+ void (*change_chanctx)(struct ieee80211_hw *, struct ieee80211_chanctx_conf *, u32);
+ int (*assign_vif_chanctx)(struct ieee80211_hw *, struct ieee80211_vif *, struct ieee80211_bss_conf *, struct ieee80211_chanctx_conf *);
+ void (*unassign_vif_chanctx)(struct ieee80211_hw *, struct ieee80211_vif *, struct ieee80211_bss_conf *, struct ieee80211_chanctx_conf *);
+ int (*switch_vif_chanctx)(struct ieee80211_hw *, struct ieee80211_vif_chanctx_switch *, int, enum ieee80211_chanctx_switch_mode);
+
+ int (*get_antenna)(struct ieee80211_hw *, int, u32 *, u32 *);
+ int (*set_antenna)(struct ieee80211_hw *, int, u32, u32);
+
+ int (*remain_on_channel)(struct ieee80211_hw *, struct ieee80211_vif *, struct ieee80211_channel *, int, enum ieee80211_roc_type);
+ int (*cancel_remain_on_channel)(struct ieee80211_hw *, struct ieee80211_vif *);
+
+ void (*configure_filter)(struct ieee80211_hw *, unsigned int, unsigned int *, u64);
+ void (*config_iface_filter)(struct ieee80211_hw *, struct ieee80211_vif *, unsigned int, unsigned int);
+
+ void (*bss_info_changed)(struct ieee80211_hw *, struct ieee80211_vif *, struct ieee80211_bss_conf *, u64);
+ void (*link_info_changed)(struct ieee80211_hw *, struct ieee80211_vif *, struct ieee80211_bss_conf *, u64);
+
+ int (*set_rts_threshold)(struct ieee80211_hw *, int, u32);
+ void (*event_callback)(struct ieee80211_hw *, struct ieee80211_vif *, const struct ieee80211_event *);
+ int (*get_survey)(struct ieee80211_hw *, int, struct survey_info *);
+ int (*get_ftm_responder_stats)(struct ieee80211_hw *, struct ieee80211_vif *, struct cfg80211_ftm_responder_stats *);
+
+ uint64_t (*get_tsf)(struct ieee80211_hw *, struct ieee80211_vif *);
+ void (*set_tsf)(struct ieee80211_hw *, struct ieee80211_vif *, uint64_t);
+ void (*offset_tsf)(struct ieee80211_hw *, struct ieee80211_vif *, s64);
+
+ int (*set_bitrate_mask)(struct ieee80211_hw *, struct ieee80211_vif *, const struct cfg80211_bitrate_mask *);
+ void (*set_coverage_class)(struct ieee80211_hw *, int, s16);
+ int (*set_tim)(struct ieee80211_hw *, struct ieee80211_sta *, bool);
+
+ int (*set_key)(struct ieee80211_hw *, enum set_key_cmd, struct ieee80211_vif *, struct ieee80211_sta *, struct ieee80211_key_conf *);
+ void (*update_tkip_key)(struct ieee80211_hw *, struct ieee80211_vif *, struct ieee80211_key_conf *, struct ieee80211_sta *, u32, u16 *);
+
+ int (*start_pmsr)(struct ieee80211_hw *, struct ieee80211_vif *, struct cfg80211_pmsr_request *);
+ void (*abort_pmsr)(struct ieee80211_hw *, struct ieee80211_vif *, struct cfg80211_pmsr_request *);
+
+ int (*start_ap)(struct ieee80211_hw *, struct ieee80211_vif *, struct ieee80211_bss_conf *link_conf);
+ void (*stop_ap)(struct ieee80211_hw *, struct ieee80211_vif *, struct ieee80211_bss_conf *link_conf);
+ int (*join_ibss)(struct ieee80211_hw *, struct ieee80211_vif *);
+ void (*leave_ibss)(struct ieee80211_hw *, struct ieee80211_vif *);
+
+ int (*set_sar_specs)(struct ieee80211_hw *, const struct cfg80211_sar_specs *);
+
+ int (*set_tid_config)(struct ieee80211_hw *, struct ieee80211_vif *, struct ieee80211_sta *, struct cfg80211_tid_config *);
+ int (*reset_tid_config)(struct ieee80211_hw *, struct ieee80211_vif *, struct ieee80211_sta *, u8);
+
+ int (*get_et_sset_count)(struct ieee80211_hw *, struct ieee80211_vif *, int);
+ void (*get_et_stats)(struct ieee80211_hw *, struct ieee80211_vif *, struct ethtool_stats *, u64 *);
+ void (*get_et_strings)(struct ieee80211_hw *, struct ieee80211_vif *, u32, u8 *);
+
+ void (*update_vif_offload)(struct ieee80211_hw *, struct ieee80211_vif *);
+
+ int (*get_txpower)(struct ieee80211_hw *, struct ieee80211_vif *, unsigned int, int *);
+ int (*get_stats)(struct ieee80211_hw *, struct ieee80211_low_level_stats *);
+
+ int (*set_radar_background)(struct ieee80211_hw *, struct cfg80211_chan_def *);
+
+ void (*add_twt_setup)(struct ieee80211_hw *, struct ieee80211_sta *, struct ieee80211_twt_setup *);
+ void (*twt_teardown_request)(struct ieee80211_hw *, struct ieee80211_sta *, u8);
+
+ int (*set_hw_timestamp)(struct ieee80211_hw *, struct ieee80211_vif *, struct cfg80211_set_hw_timestamp *);
+
+ void (*vif_cfg_changed)(struct ieee80211_hw *, struct ieee80211_vif *, u64);
+
+ int (*change_vif_links)(struct ieee80211_hw *, struct ieee80211_vif *, u16, u16, struct ieee80211_bss_conf *[IEEE80211_MLD_MAX_NUM_LINKS]);
+ int (*change_sta_links)(struct ieee80211_hw *, struct ieee80211_vif *, struct ieee80211_sta *, u16, u16);
+ bool (*can_activate_links)(struct ieee80211_hw *, struct ieee80211_vif *, u16);
+ enum ieee80211_neg_ttlm_res (*can_neg_ttlm)(struct ieee80211_hw *, struct ieee80211_vif *, struct ieee80211_neg_ttlm *);
+
+ void (*rfkill_poll)(struct ieee80211_hw *);
+
+/* #ifdef CONFIG_MAC80211_DEBUGFS */ /* Do not change depending on compile-time option. */
+ void (*sta_add_debugfs)(struct ieee80211_hw *, struct ieee80211_vif *, struct ieee80211_sta *, struct dentry *);
+ void (*vif_add_debugfs)(struct ieee80211_hw *, struct ieee80211_vif *);
+ void (*link_sta_add_debugfs)(struct ieee80211_hw *, struct ieee80211_vif *, struct ieee80211_link_sta *, struct dentry *);
+ void (*link_add_debugfs)(struct ieee80211_hw *, struct ieee80211_vif *, struct ieee80211_bss_conf *, struct dentry *);
+/* #endif */
+/* #ifdef CONFIG_PM_SLEEP */ /* Do not change depending on compile-time option. */
+ int (*suspend)(struct ieee80211_hw *, struct cfg80211_wowlan *);
+ int (*resume)(struct ieee80211_hw *);
+ void (*set_wakeup)(struct ieee80211_hw *, bool);
+ void (*set_rekey_data)(struct ieee80211_hw *, struct ieee80211_vif *, struct cfg80211_gtk_rekey_data *);
+ void (*set_default_unicast_key)(struct ieee80211_hw *, struct ieee80211_vif *, int);
+/* #if IS_ENABLED(CONFIG_IPV6) */
+ void (*ipv6_addr_change)(struct ieee80211_hw *, struct ieee80211_vif *, struct inet6_dev *);
+/* #endif */
+/* #endif CONFIG_PM_SLEEP */
+};
+
+/* -------------------------------------------------------------------------- */
+
+/* linux_80211.c */
+extern const struct cfg80211_ops linuxkpi_mac80211cfgops;
+
+struct ieee80211_hw *linuxkpi_ieee80211_alloc_hw(size_t,
+ const struct ieee80211_ops *);
+void linuxkpi_ieee80211_iffree(struct ieee80211_hw *);
+void linuxkpi_set_ieee80211_dev(struct ieee80211_hw *);
+int linuxkpi_ieee80211_ifattach(struct ieee80211_hw *);
+void linuxkpi_ieee80211_ifdetach(struct ieee80211_hw *);
+void linuxkpi_ieee80211_unregister_hw(struct ieee80211_hw *);
+struct ieee80211_hw * linuxkpi_wiphy_to_ieee80211_hw(struct wiphy *);
+void linuxkpi_ieee80211_restart_hw(struct ieee80211_hw *);
+void linuxkpi_ieee80211_iterate_interfaces(
+ struct ieee80211_hw *hw, enum ieee80211_iface_iter flags,
+ void(*iterfunc)(void *, uint8_t *, struct ieee80211_vif *),
+ void *);
+void linuxkpi_ieee80211_iterate_keys(struct ieee80211_hw *,
+ struct ieee80211_vif *,
+ void(*iterfunc)(struct ieee80211_hw *, struct ieee80211_vif *,
+ struct ieee80211_sta *, struct ieee80211_key_conf *, void *),
+ void *, bool);
+void linuxkpi_ieee80211_iterate_chan_contexts(struct ieee80211_hw *,
+ void(*iterfunc)(struct ieee80211_hw *,
+ struct ieee80211_chanctx_conf *, void *),
+ void *);
+void linuxkpi_ieee80211_iterate_stations_atomic(struct ieee80211_hw *,
+ void (*iterfunc)(void *, struct ieee80211_sta *), void *);
+void linuxkpi_ieee80211_scan_completed(struct ieee80211_hw *,
+ struct cfg80211_scan_info *);
+void linuxkpi_ieee80211_rx(struct ieee80211_hw *, struct sk_buff *,
+ struct ieee80211_sta *, struct napi_struct *, struct list_head *);
+uint8_t linuxkpi_ieee80211_get_tid(struct ieee80211_hdr *, bool);
+struct ieee80211_sta *linuxkpi_ieee80211_find_sta(struct ieee80211_vif *,
+ const u8 *);
+struct ieee80211_sta *linuxkpi_ieee80211_find_sta_by_ifaddr(
+ struct ieee80211_hw *, const uint8_t *, const uint8_t *);
+struct sk_buff *linuxkpi_ieee80211_tx_dequeue(struct ieee80211_hw *,
+ struct ieee80211_txq *);
+bool linuxkpi_ieee80211_is_ie_id_in_ie_buf(const u8, const u8 *, size_t);
+bool linuxkpi_ieee80211_ie_advance(size_t *, const u8 *, size_t);
+void linuxkpi_ieee80211_free_txskb(struct ieee80211_hw *, struct sk_buff *,
+ int);
+void linuxkpi_ieee80211_queue_delayed_work(struct ieee80211_hw *,
+ struct delayed_work *, int);
+void linuxkpi_ieee80211_queue_work(struct ieee80211_hw *, struct work_struct *);
+struct sk_buff *linuxkpi_ieee80211_pspoll_get(struct ieee80211_hw *,
+ struct ieee80211_vif *);
+struct sk_buff *linuxkpi_ieee80211_nullfunc_get(struct ieee80211_hw *,
+ struct ieee80211_vif *, int, bool);
+void linuxkpi_ieee80211_txq_get_depth(struct ieee80211_txq *, unsigned long *,
+ unsigned long *);
+struct wireless_dev *linuxkpi_ieee80211_vif_to_wdev(struct ieee80211_vif *);
+void linuxkpi_ieee80211_connection_loss(struct ieee80211_vif *);
+void linuxkpi_ieee80211_beacon_loss(struct ieee80211_vif *);
+struct sk_buff *linuxkpi_ieee80211_probereq_get(struct ieee80211_hw *,
+ const uint8_t *, const uint8_t *, size_t, size_t);
+void linuxkpi_ieee80211_tx_status(struct ieee80211_hw *, struct sk_buff *);
+void linuxkpi_ieee80211_tx_status_ext(struct ieee80211_hw *,
+ struct ieee80211_tx_status *);
+void linuxkpi_ieee80211_stop_queues(struct ieee80211_hw *);
+void linuxkpi_ieee80211_wake_queues(struct ieee80211_hw *);
+void linuxkpi_ieee80211_stop_queue(struct ieee80211_hw *, int);
+void linuxkpi_ieee80211_wake_queue(struct ieee80211_hw *, int);
+void linuxkpi_ieee80211_txq_schedule_start(struct ieee80211_hw *, uint8_t);
+struct ieee80211_txq *linuxkpi_ieee80211_next_txq(struct ieee80211_hw *, uint8_t);
+void linuxkpi_ieee80211_schedule_txq(struct ieee80211_hw *,
+ struct ieee80211_txq *, bool);
+void linuxkpi_ieee80211_handle_wake_tx_queue(struct ieee80211_hw *,
+ struct ieee80211_txq *);
+
+/* -------------------------------------------------------------------------- */
+
+static __inline void
+_ieee80211_hw_set(struct ieee80211_hw *hw, enum ieee80211_hw_flags flag)
+{
+
+ set_bit(flag, hw->flags);
+}
+
+static __inline bool
+__ieee80211_hw_check(struct ieee80211_hw *hw, enum ieee80211_hw_flags flag)
+{
+
+ return (test_bit(flag, hw->flags));
+}
+
+/* They pass in shortened flag names; how confusingly inconsistent. */
+#define ieee80211_hw_set(_hw, _flag) \
+ _ieee80211_hw_set(_hw, IEEE80211_HW_ ## _flag)
+#define ieee80211_hw_check(_hw, _flag) \
+ __ieee80211_hw_check(_hw, IEEE80211_HW_ ## _flag)
+
+/* XXX-BZ add CTASSERTS that size of struct is <= sizeof skb->cb. */
+CTASSERT(sizeof(struct ieee80211_tx_info) <= sizeof(((struct sk_buff *)0)->cb));
+#define IEEE80211_SKB_CB(_skb) \
+ ((struct ieee80211_tx_info *)((_skb)->cb))
+
+CTASSERT(sizeof(struct ieee80211_rx_status) <= sizeof(((struct sk_buff *)0)->cb));
+#define IEEE80211_SKB_RXCB(_skb) \
+ ((struct ieee80211_rx_status *)((_skb)->cb))
+
+static __inline void
+ieee80211_free_hw(struct ieee80211_hw *hw)
+{
+
+ linuxkpi_ieee80211_iffree(hw);
+
+ if (hw->wiphy != NULL)
+ wiphy_free(hw->wiphy);
+ /* Note that *hw is not valid any longer after this. */
+
+ IMPROVE();
+}
+
+static __inline struct ieee80211_hw *
+ieee80211_alloc_hw(size_t priv_len, const struct ieee80211_ops *ops)
+{
+
+ return (linuxkpi_ieee80211_alloc_hw(priv_len, ops));
+}
+
+static __inline void
+SET_IEEE80211_DEV(struct ieee80211_hw *hw, struct device *dev)
+{
+
+ set_wiphy_dev(hw->wiphy, dev);
+ linuxkpi_set_ieee80211_dev(hw);
+
+ IMPROVE();
+}
+
+static __inline int
+ieee80211_register_hw(struct ieee80211_hw *hw)
+{
+ int error;
+
+ error = wiphy_register(hw->wiphy);
+ if (error != 0)
+ return (error);
+
+ /*
+ * At this point the driver has set all the options, flags, bands,
+ * ciphers, hw address(es), ... basically mac80211/cfg80211 hw/wiphy
+ * setup is done.
+ * We need to replicate a lot of information from here into net80211.
+ */
+ error = linuxkpi_ieee80211_ifattach(hw);
+
+ IMPROVE();
+
+ return (error);
+}
+
+static inline void
+ieee80211_unregister_hw(struct ieee80211_hw *hw)
+{
+
+ linuxkpi_ieee80211_unregister_hw(hw);
+}
+
+static __inline struct ieee80211_hw *
+wiphy_to_ieee80211_hw(struct wiphy *wiphy)
+{
+
+ return (linuxkpi_wiphy_to_ieee80211_hw(wiphy));
+}
+
+static inline void
+ieee80211_restart_hw(struct ieee80211_hw *hw)
+{
+ linuxkpi_ieee80211_restart_hw(hw);
+}
+
+static inline void
+ieee80211_hw_restart_disconnect(struct ieee80211_vif *vif)
+{
+ TODO();
+}
+
+/* -------------------------------------------------------------------------- */
+
+#define link_conf_dereference_check(_vif, _linkid) \
+ rcu_dereference_check((_vif)->link_conf[_linkid], true)
+
+#define link_conf_dereference_protected(_vif, _linkid) \
+ rcu_dereference_protected((_vif)->link_conf[_linkid], true)
+
+#define link_sta_dereference_check(_sta, _linkid) \
+ rcu_dereference_check((_sta)->link[_linkid], true)
+
+#define link_sta_dereference_protected(_sta, _linkid) \
+ rcu_dereference_protected((_sta)->link[_linkid], true)
+
+#define for_each_vif_active_link(_vif, _link, _linkid) \
+ for (_linkid = 0; _linkid < nitems((_vif)->link_conf); _linkid++) \
+ if ( ((_vif)->active_links == 0 /* no MLO */ || \
+ ((_vif)->active_links & BIT(_linkid)) != 0) && \
+ (_link = rcu_dereference((_vif)->link_conf[_linkid])) )
+
+#define for_each_sta_active_link(_vif, _sta, _linksta, _linkid) \
+ for (_linkid = 0; _linkid < nitems((_sta)->link); _linkid++) \
+ if ( ((_vif)->active_links == 0 /* no MLO */ || \
+ ((_vif)->active_links & BIT(_linkid)) != 0) && \
+ (_linksta = link_sta_dereference_protected((_sta), (_linkid))) )
+
+/* -------------------------------------------------------------------------- */
+
+static __inline bool
+ieee80211_vif_is_mesh(struct ieee80211_vif *vif)
+{
+ TODO();
+ return (false);
+}
+
+
+/* -------------------------------------------------------------------------- */
+/* Receive functions (air/driver to mac80211/net80211). */
+
+
+static __inline void
+ieee80211_rx_napi(struct ieee80211_hw *hw, struct ieee80211_sta *sta,
+ struct sk_buff *skb, struct napi_struct *napi)
+{
+
+ linuxkpi_ieee80211_rx(hw, skb, sta, napi, NULL);
+}
+
+static __inline void
+ieee80211_rx_list(struct ieee80211_hw *hw, struct ieee80211_sta *sta,
+ struct sk_buff *skb, struct list_head *list)
+{
+
+ linuxkpi_ieee80211_rx(hw, skb, sta, NULL, list);
+}
+
+static __inline void
+ieee80211_rx_ni(struct ieee80211_hw *hw, struct sk_buff *skb)
+{
+
+ linuxkpi_ieee80211_rx(hw, skb, NULL, NULL, NULL);
+}
+
+static __inline void
+ieee80211_rx_irqsafe(struct ieee80211_hw *hw, struct sk_buff *skb)
+{
+
+ linuxkpi_ieee80211_rx(hw, skb, NULL, NULL, NULL);
+}
+
+static __inline void
+ieee80211_rx(struct ieee80211_hw *hw, struct sk_buff *skb)
+{
+
+ linuxkpi_ieee80211_rx(hw, skb, NULL, NULL, NULL);
+}
+
+/* -------------------------------------------------------------------------- */
+
+static inline void
+ieee80211_stop_queues(struct ieee80211_hw *hw)
+{
+ linuxkpi_ieee80211_stop_queues(hw);
+}
+
+static inline void
+ieee80211_wake_queues(struct ieee80211_hw *hw)
+{
+ linuxkpi_ieee80211_wake_queues(hw);
+}
+
+static inline void
+ieee80211_stop_queue(struct ieee80211_hw *hw, int qnum)
+{
+ linuxkpi_ieee80211_stop_queue(hw, qnum);
+}
+
+static inline void
+ieee80211_wake_queue(struct ieee80211_hw *hw, int qnum)
+{
+ linuxkpi_ieee80211_wake_queue(hw, qnum);
+}
+
+static inline void
+ieee80211_schedule_txq(struct ieee80211_hw *hw, struct ieee80211_txq *txq)
+{
+ linuxkpi_ieee80211_schedule_txq(hw, txq, true);
+}
+
+static inline void
+ieee80211_return_txq(struct ieee80211_hw *hw, struct ieee80211_txq *txq,
+ bool withoutpkts)
+{
+ linuxkpi_ieee80211_schedule_txq(hw, txq, withoutpkts);
+}
+
+static inline void
+ieee80211_txq_schedule_start(struct ieee80211_hw *hw, uint8_t ac)
+{
+ linuxkpi_ieee80211_txq_schedule_start(hw, ac);
+}
+
+static inline void
+ieee80211_txq_schedule_end(struct ieee80211_hw *hw, uint8_t ac)
+{
+ /* DO_NADA; */
+}
+
+static inline struct ieee80211_txq *
+ieee80211_next_txq(struct ieee80211_hw *hw, uint8_t ac)
+{
+ return (linuxkpi_ieee80211_next_txq(hw, ac));
+}
+
+static inline void
+ieee80211_handle_wake_tx_queue(struct ieee80211_hw *hw,
+ struct ieee80211_txq *txq)
+{
+ linuxkpi_ieee80211_handle_wake_tx_queue(hw, txq);
+}
+
+static inline void
+ieee80211_purge_tx_queue(struct ieee80211_hw *hw,
+ struct sk_buff_head *skbs)
+{
+ TODO();
+}
+
+/* -------------------------------------------------------------------------- */
+
+static __inline uint8_t
+ieee80211_get_tid(struct ieee80211_hdr *hdr)
+{
+
+ return (linuxkpi_ieee80211_get_tid(hdr, false));
+}
+
+static __inline struct sk_buff *
+ieee80211_beacon_get_tim(struct ieee80211_hw *hw, struct ieee80211_vif *vif,
+ uint16_t *tim_offset, uint16_t *tim_len, uint32_t link_id)
+{
+
+ if (tim_offset != NULL)
+ *tim_offset = 0;
+ if (tim_len != NULL)
+ *tim_len = 0;
+ TODO();
+ return (NULL);
+}
+
+static __inline void
+ieee80211_iterate_active_interfaces_atomic(struct ieee80211_hw *hw,
+ enum ieee80211_iface_iter flags,
+ void(*iterfunc)(void *, uint8_t *, struct ieee80211_vif *),
+ void *arg)
+{
+
+ flags |= IEEE80211_IFACE_ITER__ATOMIC;
+ flags |= IEEE80211_IFACE_ITER_ACTIVE;
+ linuxkpi_ieee80211_iterate_interfaces(hw, flags, iterfunc, arg);
+}
+
+static __inline void
+ieee80211_iterate_active_interfaces(struct ieee80211_hw *hw,
+ enum ieee80211_iface_iter flags,
+ void(*iterfunc)(void *, uint8_t *, struct ieee80211_vif *),
+ void *arg)
+{
+
+ flags |= IEEE80211_IFACE_ITER_ACTIVE;
+ linuxkpi_ieee80211_iterate_interfaces(hw, flags, iterfunc, arg);
+}
+
+static __inline void
+ieee80211_iterate_active_interfaces_mtx(struct ieee80211_hw *hw,
+ enum ieee80211_iface_iter flags,
+ void(*iterfunc)(void *, uint8_t *, struct ieee80211_vif *),
+ void *arg)
+{
+ flags |= IEEE80211_IFACE_ITER_ACTIVE;
+ flags |= IEEE80211_IFACE_ITER__MTX;
+ linuxkpi_ieee80211_iterate_interfaces(hw, flags, iterfunc, arg);
+}
+
+static __inline void
+ieee80211_iterate_interfaces(struct ieee80211_hw *hw,
+ enum ieee80211_iface_iter flags,
+ void (*iterfunc)(void *, uint8_t *, struct ieee80211_vif *),
+ void *arg)
+{
+
+ linuxkpi_ieee80211_iterate_interfaces(hw, flags, iterfunc, arg);
+}
+
+static inline void
+ieee80211_iter_keys(struct ieee80211_hw *hw, struct ieee80211_vif *vif,
+ void(*iterfunc)(struct ieee80211_hw *, struct ieee80211_vif *,
+ struct ieee80211_sta *, struct ieee80211_key_conf *, void *),
+ void *arg)
+{
+ linuxkpi_ieee80211_iterate_keys(hw, vif, iterfunc, arg, false);
+}
+
+static inline void
+ieee80211_iter_keys_rcu(struct ieee80211_hw *hw, struct ieee80211_vif *vif,
+ void(*iterfunc)(struct ieee80211_hw *, struct ieee80211_vif *,
+ struct ieee80211_sta *, struct ieee80211_key_conf *, void *),
+ void *arg)
+{
+ linuxkpi_ieee80211_iterate_keys(hw, vif, iterfunc, arg, true);
+}
+
+static __inline void
+ieee80211_iter_chan_contexts_atomic(struct ieee80211_hw *hw,
+ void(*iterfunc)(struct ieee80211_hw *, struct ieee80211_chanctx_conf *, void *),
+ void *arg)
+{
+
+ linuxkpi_ieee80211_iterate_chan_contexts(hw, iterfunc, arg);
+}
+
+static __inline void
+ieee80211_iter_chan_contexts_mtx(struct ieee80211_hw *hw,
+ void (*iterfunc)(struct ieee80211_hw *, struct ieee80211_chanctx_conf *, void *),
+ void *arg)
+{
+ IMPROVE("XXX LKPI80211 TODO MTX\n");
+ linuxkpi_ieee80211_iterate_chan_contexts(hw, iterfunc, arg);
+}
+
+static __inline void
+ieee80211_iterate_stations_atomic(struct ieee80211_hw *hw,
+ void (*iterfunc)(void *, struct ieee80211_sta *), void *arg)
+{
+
+ linuxkpi_ieee80211_iterate_stations_atomic(hw, iterfunc, arg);
+}
+
+static __inline struct wireless_dev *
+ieee80211_vif_to_wdev(struct ieee80211_vif *vif)
+{
+
+ return (linuxkpi_ieee80211_vif_to_wdev(vif));
+}
+
+static __inline struct sk_buff *
+ieee80211_beacon_get_template(struct ieee80211_hw *hw,
+ struct ieee80211_vif *vif, struct ieee80211_mutable_offsets *offs,
+ uint32_t link_id)
+{
+ TODO();
+ return (NULL);
+}
+
+static __inline void
+ieee80211_beacon_loss(struct ieee80211_vif *vif)
+{
+ linuxkpi_ieee80211_beacon_loss(vif);
+}
+
+static __inline void
+ieee80211_chswitch_done(struct ieee80211_vif *vif, bool t, uint32_t link_id)
+{
+ TODO();
+}
+
+static __inline bool
+ieee80211_csa_is_complete(struct ieee80211_vif *vif)
+{
+ TODO();
+ return (false);
+}
+
+static __inline void
+ieee80211_csa_set_counter(struct ieee80211_vif *vif, uint8_t counter)
+{
+ TODO();
+}
+
+static __inline int
+ieee80211_csa_update_counter(struct ieee80211_vif *vif)
+{
+ TODO();
+ return (-1);
+}
+
+static __inline void
+ieee80211_csa_finish(struct ieee80211_vif *vif, uint32_t link_id)
+{
+ TODO();
+}
+
+static inline enum nl80211_iftype
+ieee80211_vif_type_p2p(struct ieee80211_vif *vif)
+{
+
+ /* If we are not p2p enabled, just return the type. */
+ if (!vif->p2p)
+ return (vif->type);
+
+ /* If we are p2p, depending on side, return type. */
+ switch (vif->type) {
+ case NL80211_IFTYPE_AP:
+ return (NL80211_IFTYPE_P2P_GO);
+ case NL80211_IFTYPE_STATION:
+ return (NL80211_IFTYPE_P2P_CLIENT);
+ default:
+ fallthrough;
+ }
+ return (vif->type);
+}
+
+static __inline unsigned long
+ieee80211_tu_to_usec(unsigned long tu)
+{
+
+ return (tu * IEEE80211_DUR_TU);
+}
+
+/*
+ * Below we assume that the two values from different emums are the same.
+ * Make sure this does not accidentally change.
+ */
+CTASSERT((int)IEEE80211_ACTION_SM_TPCREP == (int)IEEE80211_ACTION_RADIO_MEASUREMENT_LMREP);
+
+static __inline bool
+ieee80211_action_contains_tpc(struct sk_buff *skb)
+{
+ struct ieee80211_mgmt *mgmt;
+
+ mgmt = (struct ieee80211_mgmt *)skb->data;
+
+ /* Check that this is a mgmt/action frame? */
+ if (!ieee80211_is_action(mgmt->frame_control))
+ return (false);
+
+ /*
+ * This is a bit convoluted but according to docs both actions
+ * are checked for this. Kind-of makes sense for the only consumer
+ * (iwlwifi) I am aware off given the txpower fields are at the
+ * same location so firmware can update the value.
+ */
+ /* 80211-2020 9.6.2 Spectrum Management Action frames */
+ /* 80211-2020 9.6.2.5 TPC Report frame format */
+ /* 80211-2020 9.6.6 Radio Measurement action details */
+ /* 80211-2020 9.6.6.4 Link Measurement Report frame format */
+ /* Check that it is Spectrum Management or Radio Measurement? */
+ if (mgmt->u.action.category != IEEE80211_ACTION_CAT_SM &&
+ mgmt->u.action.category != IEEE80211_ACTION_CAT_RADIO_MEASUREMENT)
+ return (false);
+
+ /*
+ * Check that it is TPC Report or Link Measurement Report?
+ * The values of each are the same (see CTASSERT above function).
+ */
+ if (mgmt->u.action.u.tpc_report.spec_mgmt != IEEE80211_ACTION_SM_TPCREP)
+ return (false);
+
+ /* 80211-2020 9.4.2.16 TPC Report element */
+ /* Check that the ELEMID and length are correct? */
+ if (mgmt->u.action.u.tpc_report.tpc_elem_id != IEEE80211_ELEMID_TPCREP ||
+ mgmt->u.action.u.tpc_report.tpc_elem_length != 4)
+ return (false);
+
+ /* All the right fields in the right place. */
+ return (true);
+}
+
+static __inline void
+ieee80211_connection_loss(struct ieee80211_vif *vif)
+{
+
+ linuxkpi_ieee80211_connection_loss(vif);
+}
+
+static __inline struct ieee80211_sta *
+ieee80211_find_sta(struct ieee80211_vif *vif, const u8 *peer)
+{
+
+ return (linuxkpi_ieee80211_find_sta(vif, peer));
+}
+
+static __inline struct ieee80211_sta *
+ieee80211_find_sta_by_ifaddr(struct ieee80211_hw *hw, const uint8_t *addr,
+ const uint8_t *ourvifaddr)
+{
+
+ return (linuxkpi_ieee80211_find_sta_by_ifaddr(hw, addr, ourvifaddr));
+}
+
+static __inline size_t
+ieee80211_ie_split(const u8 *ies, size_t ies_len,
+ const u8 *ie_ids, size_t ie_ids_len, size_t start)
+{
+ size_t x;
+
+ x = start;
+
+ /* XXX FIXME, we need to deal with "Element ID Extension" */
+ while (x < ies_len) {
+
+ /* Is this IE[s] one of the ie_ids? */
+ if (!linuxkpi_ieee80211_is_ie_id_in_ie_buf(ies[x],
+ ie_ids, ie_ids_len))
+ break;
+
+ if (!linuxkpi_ieee80211_ie_advance(&x, ies, ies_len))
+ break;
+ }
+
+ return (x);
+}
+
+static __inline void
+ieee80211_request_smps(struct ieee80211_vif *vif, u_int link_id,
+ enum ieee80211_smps_mode smps)
+{
+ static const char *smps_mode_name[] = {
+ "SMPS_OFF",
+ "SMPS_STATIC",
+ "SMPS_DYNAMIC",
+ "SMPS_AUTOMATIC",
+ };
+
+ if (vif->type != NL80211_IFTYPE_STATION)
+ return;
+
+ if (smps >= nitems(smps_mode_name))
+ panic("%s: unsupported smps value: %d\n", __func__, smps);
+
+ IMPROVE("XXX LKPI80211 TODO smps %d %s\n", smps, smps_mode_name[smps]);
+}
+
+static __inline void
+ieee80211_tdls_oper_request(struct ieee80211_vif *vif, uint8_t *addr,
+ enum nl80211_tdls_operation oper, enum ieee80211_reason_code code,
+ gfp_t gfp)
+{
+ TODO();
+}
+
+static __inline void
+wiphy_rfkill_set_hw_state(struct wiphy *wiphy, bool state)
+{
+ TODO();
+}
+
+static __inline void
+ieee80211_free_txskb(struct ieee80211_hw *hw, struct sk_buff *skb)
+{
+ IMPROVE();
+
+ /*
+ * This is called on transmit failure.
+ * Use a not-so-random random high status error so we can distinguish
+ * it from normal low values flying around in net80211 ("ETX").
+ */
+ linuxkpi_ieee80211_free_txskb(hw, skb, 0x455458);
+}
+
+static __inline void
+ieee80211_ready_on_channel(struct ieee80211_hw *hw)
+{
+ TODO();
+/* XXX-BZ We need to see that. */
+}
+
+static __inline void
+ieee80211_remain_on_channel_expired(struct ieee80211_hw *hw)
+{
+ TODO();
+}
+
+static __inline void
+ieee80211_cqm_rssi_notify(struct ieee80211_vif *vif,
+ enum nl80211_cqm_rssi_threshold_event crte, int sig, gfp_t gfp)
+{
+ TODO();
+}
+
+/* -------------------------------------------------------------------------- */
+
+static inline bool
+ieee80211_sn_less(uint16_t sn1, uint16_t sn2)
+{
+ return (IEEE80211_SEQ_BA_BEFORE(sn1, sn2));
+}
+
+static inline uint16_t
+ieee80211_sn_inc(uint16_t sn)
+{
+ return (IEEE80211_SEQ_INC(sn));
+}
+
+static inline uint16_t
+ieee80211_sn_add(uint16_t sn, uint16_t a)
+{
+ return (IEEE80211_SEQ_ADD(sn, a));
+}
+
+static inline uint16_t
+ieee80211_sn_sub(uint16_t sa, uint16_t sb)
+{
+ return (IEEE80211_SEQ_SUB(sa, sb));
+}
+
+static __inline void
+ieee80211_mark_rx_ba_filtered_frames(struct ieee80211_sta *sta, uint8_t tid,
+ uint32_t ssn, uint64_t bitmap, uint16_t received_mpdu)
+{
+ TODO();
+}
+
+static __inline void
+ieee80211_stop_rx_ba_session(struct ieee80211_vif *vif, uint32_t x, uint8_t *addr)
+{
+ TODO();
+}
+
+static __inline void
+ieee80211_rx_ba_timer_expired(struct ieee80211_vif *vif, uint8_t *addr,
+ uint8_t tid)
+{
+ TODO();
+}
+
+static __inline void
+ieee80211_start_rx_ba_session_offl(struct ieee80211_vif *vif, uint8_t *addr,
+ uint8_t tid)
+{
+ TODO();
+}
+
+static __inline void
+ieee80211_stop_rx_ba_session_offl(struct ieee80211_vif *vif, uint8_t *addr,
+ uint8_t tid)
+{
+ TODO();
+}
+
+/* -------------------------------------------------------------------------- */
+
+static inline void
+ieee80211_rate_set_vht(struct ieee80211_tx_rate *r, uint8_t mcs, uint8_t nss)
+{
+
+ /* XXX-BZ make it KASSERTS? */
+ if (((mcs & 0xF0) != 0) || (((nss - 1) & 0xf8) != 0)) {
+ printf("%s:%d: mcs %#04x nss %#04x invalid\n",
+ __func__, __LINE__, mcs, nss);
+ return;
+ }
+
+ r->idx = mcs;
+ r->idx |= ((nss - 1) << 4);
+}
+
+static inline uint8_t
+ieee80211_rate_get_vht_nss(const struct ieee80211_tx_rate *r)
+{
+ return (((r->idx >> 4) & 0x07) + 1);
+}
+
+static inline uint8_t
+ieee80211_rate_get_vht_mcs(const struct ieee80211_tx_rate *r)
+{
+ return (r->idx & 0x0f);
+}
+
+static inline int
+ieee80211_get_vht_max_nss(struct ieee80211_vht_cap *vht_cap,
+ enum ieee80211_vht_chanwidth chanwidth, /* defined in net80211. */
+ int mcs /* always 0 */, bool ext_nss_bw_cap /* always true */, int max_nss)
+{
+ enum ieee80211_vht_mcs_support mcs_s;
+ uint32_t supp_cw, ext_nss_bw;
+
+ switch (mcs) {
+ case 0 ... 7:
+ mcs_s = IEEE80211_VHT_MCS_SUPPORT_0_7;
+ break;
+ case 8:
+ mcs_s = IEEE80211_VHT_MCS_SUPPORT_0_8;
+ break;
+ case 9:
+ mcs_s = IEEE80211_VHT_MCS_SUPPORT_0_9;
+ break;
+ default:
+ printf("%s: unsupported mcs value %d\n", __func__, mcs);
+ return (0);
+ }
+
+ if (max_nss == 0) {
+ uint16_t map;
+
+ map = le16toh(vht_cap->supp_mcs.rx_mcs_map);
+ for (int i = 7; i >= 0; i--) {
+ uint8_t val;
+
+ val = (map >> (2 * i)) & 0x03;
+ if (val == IEEE80211_VHT_MCS_NOT_SUPPORTED)
+ continue;
+ if (val >= mcs_s) {
+ max_nss = i + 1;
+ break;
+ }
+ }
+ }
+
+ if (max_nss == 0)
+ return (0);
+
+ if ((le16toh(vht_cap->supp_mcs.tx_mcs_map) &
+ IEEE80211_VHT_EXT_NSS_BW_CAPABLE) == 0)
+ return (max_nss);
+
+ supp_cw = le32_get_bits(vht_cap->vht_cap_info,
+ IEEE80211_VHT_CAP_SUPP_CHAN_WIDTH_MASK);
+ ext_nss_bw = le32_get_bits(vht_cap->vht_cap_info,
+ IEEE80211_VHT_CAP_EXT_NSS_BW_MASK);
+
+ /* If requested as ext nss not supported assume ext_nss_bw 0. */
+ if (!ext_nss_bw_cap)
+ ext_nss_bw = 0;
+
+ /*
+ * Cover 802.11-2016, Table 9-250.
+ */
+
+ /* Unsupported settings. */
+ if (supp_cw == 3)
+ return (0);
+ if (supp_cw == 2 && (ext_nss_bw == 1 || ext_nss_bw == 2))
+ return (0);
+
+ /* Settings with factor != 1 or unsupported. */
+ switch (chanwidth) {
+ case IEEE80211_VHT_CHANWIDTH_80P80MHZ:
+ if (supp_cw == 0 && (ext_nss_bw == 0 || ext_nss_bw == 1))
+ return (0);
+ if (supp_cw == 1 && ext_nss_bw == 0)
+ return (0);
+ if ((supp_cw == 0 || supp_cw == 1) && ext_nss_bw == 2)
+ return (max_nss / 2);
+ if ((supp_cw == 0 || supp_cw == 1) && ext_nss_bw == 3)
+ return (3 * max_nss / 4);
+ break;
+ case IEEE80211_VHT_CHANWIDTH_160MHZ:
+ if (supp_cw == 0 && ext_nss_bw == 0)
+ return (0);
+ if (supp_cw == 0 && (ext_nss_bw == 1 || ext_nss_bw == 2))
+ return (max_nss / 2);
+ if (supp_cw == 0 && ext_nss_bw == 3)
+ return (3 * max_nss / 4);
+ if (supp_cw == 1 && ext_nss_bw == 3)
+ return (2 * max_nss);
+ break;
+ case IEEE80211_VHT_CHANWIDTH_80MHZ:
+ case IEEE80211_VHT_CHANWIDTH_USE_HT:
+ if ((supp_cw == 1 || supp_cw == 2) && ext_nss_bw == 3)
+ return (2 * max_nss);
+ break;
+ }
+
+ /* Everything else has a factor of 1. */
+ return (max_nss);
+}
+
+
+static __inline void
+ieee80211_reserve_tid(struct ieee80211_sta *sta, uint8_t tid)
+{
+ TODO();
+}
+
+static __inline void
+ieee80211_unreserve_tid(struct ieee80211_sta *sta, uint8_t tid)
+{
+ TODO();
+}
+
+static __inline void
+ieee80211_send_eosp_nullfunc(struct ieee80211_sta *sta, uint8_t tid)
+{
+ TODO();
+}
+
+static __inline void
+ieee80211_sta_block_awake(struct ieee80211_hw *hw, struct ieee80211_sta *sta,
+ bool disable)
+{
+ TODO();
+}
+
+static __inline void
+ieee80211_sta_ps_transition(struct ieee80211_sta *sta, bool sleeping)
+{
+ TODO();
+}
+
+static __inline void
+ieee80211_sta_pspoll(struct ieee80211_sta *sta)
+{
+ TODO();
+}
+
+static inline void
+ieee80211_sta_recalc_aggregates(struct ieee80211_sta *sta)
+{
+ if (sta->valid_links) {
+ TODO();
+ }
+}
+
+static __inline void
+ieee80211_sta_uapsd_trigger(struct ieee80211_sta *sta, int ntids)
+{
+ TODO();
+}
+
+static inline struct sk_buff *
+ieee80211_tx_dequeue(struct ieee80211_hw *hw, struct ieee80211_txq *txq)
+{
+
+ return (linuxkpi_ieee80211_tx_dequeue(hw, txq));
+}
+
+static inline struct sk_buff *
+ieee80211_tx_dequeue_ni(struct ieee80211_hw *hw, struct ieee80211_txq *txq)
+{
+ struct sk_buff *skb;
+
+ local_bh_disable();
+ skb = linuxkpi_ieee80211_tx_dequeue(hw, txq);
+ local_bh_enable();
+
+ return (skb);
+}
+
+static __inline void
+ieee80211_update_mu_groups(struct ieee80211_vif *vif,
+ u_int link_id, const uint8_t *ms, const uint8_t *up)
+{
+ TODO();
+}
+
+static __inline void
+ieee80211_sta_set_buffered(struct ieee80211_sta *sta, uint8_t tid, bool t)
+{
+ TODO();
+}
+
+static __inline void
+ieee80211_sched_scan_results(struct ieee80211_hw *hw)
+{
+ TODO();
+}
+
+static __inline void
+ieee80211_sta_eosp(struct ieee80211_sta *sta)
+{
+ TODO();
+}
+
+static __inline int
+ieee80211_start_tx_ba_session(struct ieee80211_sta *sta, uint8_t tid, int x)
+{
+ TODO("rtw8x");
+ return (-EINVAL);
+}
+
+static __inline int
+ieee80211_stop_tx_ba_session(struct ieee80211_sta *sta, uint8_t tid)
+{
+ TODO("rtw89");
+ return (-EINVAL);
+}
+
+static __inline void
+ieee80211_start_tx_ba_cb_irqsafe(struct ieee80211_vif *vif, uint8_t *addr,
+ uint8_t tid)
+{
+ TODO("iwlwifi");
+}
+
+static __inline void
+ieee80211_stop_tx_ba_cb_irqsafe(struct ieee80211_vif *vif, uint8_t *addr,
+ uint8_t tid)
+{
+ TODO("iwlwifi/rtw8x/...");
+}
+
+static __inline void
+ieee80211_sched_scan_stopped(struct ieee80211_hw *hw)
+{
+ TODO();
+}
+
+static __inline void
+ieee80211_scan_completed(struct ieee80211_hw *hw,
+ struct cfg80211_scan_info *info)
+{
+
+ linuxkpi_ieee80211_scan_completed(hw, info);
+}
+
+static __inline struct sk_buff *
+ieee80211_beacon_get(struct ieee80211_hw *hw, struct ieee80211_vif *vif,
+ uint32_t link_id)
+{
+ TODO();
+ return (NULL);
+}
+
+static __inline struct sk_buff *
+ieee80211_pspoll_get(struct ieee80211_hw *hw, struct ieee80211_vif *vif)
+{
+
+ /* Only STA needs this. Otherwise return NULL and panic bad drivers. */
+ if (vif->type != NL80211_IFTYPE_STATION)
+ return (NULL);
+
+ return (linuxkpi_ieee80211_pspoll_get(hw, vif));
+}
+
+static __inline struct sk_buff *
+ieee80211_proberesp_get(struct ieee80211_hw *hw, struct ieee80211_vif *vif)
+{
+ TODO();
+ return (NULL);
+}
+
+static __inline struct sk_buff *
+ieee80211_nullfunc_get(struct ieee80211_hw *hw, struct ieee80211_vif *vif,
+ int linkid, bool qos)
+{
+
+ /* Only STA needs this. Otherwise return NULL and panic bad drivers. */
+ if (vif->type != NL80211_IFTYPE_STATION)
+ return (NULL);
+
+ return (linuxkpi_ieee80211_nullfunc_get(hw, vif, linkid, qos));
+}
+
+static __inline struct sk_buff *
+ieee80211_probereq_get(struct ieee80211_hw *hw, const uint8_t *addr,
+ const uint8_t *ssid, size_t ssid_len, size_t tailroom)
+{
+
+ return (linuxkpi_ieee80211_probereq_get(hw, addr, ssid, ssid_len,
+ tailroom));
+}
+
+static __inline void
+ieee80211_queue_delayed_work(struct ieee80211_hw *hw, struct delayed_work *w,
+ int delay)
+{
+
+ linuxkpi_ieee80211_queue_delayed_work(hw, w, delay);
+}
+
+static __inline void
+ieee80211_queue_work(struct ieee80211_hw *hw, struct work_struct *w)
+{
+
+ linuxkpi_ieee80211_queue_work(hw, w);
+}
+
+static __inline bool
+ieee80211_tx_prepare_skb(struct ieee80211_hw *hw, struct ieee80211_vif *vif,
+ struct sk_buff *skb, enum nl80211_band band, struct ieee80211_sta **sta)
+{
+ TODO();
+ return (false);
+}
+
+static __inline void
+ieee80211_tx_status_skb(struct ieee80211_hw *hw, struct sk_buff *skb)
+{
+ linuxkpi_ieee80211_tx_status(hw, skb);
+}
+
+static inline void
+ieee80211_tx_status_noskb(struct ieee80211_hw *hw, struct ieee80211_sta *sta,
+ struct ieee80211_tx_info *info)
+{
+ TODO();
+}
+
+static __inline void
+ieee80211_tx_status_irqsafe(struct ieee80211_hw *hw, struct sk_buff *skb)
+{
+ IMPROVE();
+ linuxkpi_ieee80211_tx_status(hw, skb);
+}
+
+static __inline void
+ieee80211_tx_status_ni(struct ieee80211_hw *hw, struct sk_buff *skb)
+{
+ IMPROVE();
+ linuxkpi_ieee80211_tx_status(hw, skb);
+}
+
+static __inline void
+ieee80211_tx_status_ext(struct ieee80211_hw *hw,
+ struct ieee80211_tx_status *txstat)
+{
+
+ linuxkpi_ieee80211_tx_status_ext(hw, txstat);
+}
+
+static __inline void
+ieee80211_tx_info_clear_status(struct ieee80211_tx_info *info)
+{
+ int i;
+
+ /*
+ * Apparently clearing flags and some other fields is not right.
+ * Given the function is called "status" we work on that part of
+ * the union.
+ */
+ for (i = 0; i < nitems(info->status.rates); i++)
+ info->status.rates[i].count = 0;
+ /*
+ * Unclear if ack_signal should be included or not but we clear the
+ * "valid" bool so this field is no longer valid.
+ */
+ memset(&info->status.ack_signal, 0, sizeof(*info) -
+ offsetof(struct ieee80211_tx_info, status.ack_signal));
+}
+
+static __inline void
+ieee80211_txq_get_depth(struct ieee80211_txq *txq, unsigned long *frame_cnt,
+ unsigned long *byte_cnt)
+{
+
+ if (frame_cnt == NULL && byte_cnt == NULL)
+ return;
+
+ linuxkpi_ieee80211_txq_get_depth(txq, frame_cnt, byte_cnt);
+}
+
+static __inline void
+SET_IEEE80211_PERM_ADDR (struct ieee80211_hw *hw, uint8_t *addr)
+{
+
+ ether_addr_copy(hw->wiphy->perm_addr, addr);
+}
+
+static __inline void
+ieee80211_report_low_ack(struct ieee80211_sta *sta, int x)
+{
+ TODO();
+}
+
+static __inline void
+ieee80211_tx_rate_update(struct ieee80211_hw *hw, struct ieee80211_sta *sta,
+ struct ieee80211_tx_info *info)
+{
+ TODO();
+}
+
+static __inline bool
+ieee80211_txq_may_transmit(struct ieee80211_hw *hw, struct ieee80211_txq *txq)
+{
+ TODO();
+ return (false);
+}
+
+static __inline void
+ieee80211_radar_detected(struct ieee80211_hw *hw,
+ struct ieee80211_chanctx_conf *chanctx_conf)
+{
+ TODO();
+}
+
+static __inline void
+ieee80211_sta_register_airtime(struct ieee80211_sta *sta,
+ uint8_t tid, uint32_t duration, int x)
+{
+ TODO();
+}
+
+static __inline void
+ieee80211_beacon_set_cntdwn(struct ieee80211_vif *vif, u8 counter)
+{
+ TODO();
+}
+
+static __inline int
+ieee80211_beacon_update_cntdwn(struct ieee80211_vif *vif, uint32_t link_id)
+{
+ TODO();
+ return (-1);
+}
+
+static __inline bool
+ieee80211_beacon_cntdwn_is_complete(struct ieee80211_vif *vif, uint32_t link_id)
+{
+ TODO();
+ return (true);
+}
+
+static __inline void
+ieee80211_disconnect(struct ieee80211_vif *vif, bool _x)
+{
+ TODO();
+}
+
+static __inline void
+ieee80211_channel_switch_disconnect(struct ieee80211_vif *vif)
+{
+ TODO();
+}
+
+static __inline uint32_t
+ieee80211_calc_rx_airtime(struct ieee80211_hw *hw,
+ struct ieee80211_rx_status *rxstat, int len)
+{
+ TODO();
+ return (0);
+}
+
+static __inline void
+ieee80211_get_tx_rates(struct ieee80211_vif *vif, struct ieee80211_sta *sta,
+ struct sk_buff *skb, struct ieee80211_tx_rate *txrate, int nrates)
+{
+ TODO();
+}
+
+static __inline void
+ieee80211_color_change_finish(struct ieee80211_vif *vif, uint8_t link_id)
+{
+ TODO();
+}
+
+static __inline struct sk_buff *
+ieee80211_get_fils_discovery_tmpl(struct ieee80211_hw *hw,
+ struct ieee80211_vif *vif)
+{
+ TODO();
+ return (NULL);
+}
+
+static __inline struct sk_buff *
+ieee80211_get_unsol_bcast_probe_resp_tmpl(struct ieee80211_hw *hw,
+ struct ieee80211_vif *vif)
+{
+ TODO();
+ return (NULL);
+}
+
+static __inline void
+linuxkpi_ieee80211_send_bar(struct ieee80211_vif *vif, uint8_t *ra, uint16_t tid,
+ uint16_t ssn)
+{
+ TODO();
+}
+
+static __inline void
+ieee80211_resume_disconnect(struct ieee80211_vif *vif)
+{
+ TODO();
+}
+
+static __inline int
+ieee80211_data_to_8023(struct sk_buff *skb, const uint8_t *addr,
+ enum nl80211_iftype iftype)
+{
+ TODO();
+ return (-1);
+}
+
+/* -------------------------------------------------------------------------- */
+
+static __inline void
+ieee80211_key_mic_failure(struct ieee80211_key_conf *key)
+{
+ TODO();
+}
+
+static __inline void
+ieee80211_key_replay(struct ieee80211_key_conf *key)
+{
+ TODO();
+}
+
+static __inline void
+ieee80211_remove_key(struct ieee80211_key_conf *key)
+{
+ TODO();
+}
+
+static __inline struct ieee80211_key_conf *
+ieee80211_gtk_rekey_add(struct ieee80211_vif *vif,
+ uint16_t keyidx, uint8_t *key, size_t keylen, int link_id)
+{
+ TODO();
+ return (NULL);
+}
+
+static __inline void
+ieee80211_gtk_rekey_notify(struct ieee80211_vif *vif, const uint8_t *bssid,
+ const uint8_t *replay_ctr, gfp_t gfp)
+{
+ TODO();
+}
+
+static __inline void
+ieee80211_tkip_add_iv(u8 *crypto_hdr, struct ieee80211_key_conf *keyconf,
+ uint64_t pn)
+{
+ TODO();
+}
+
+static __inline void
+ieee80211_get_tkip_rx_p1k(struct ieee80211_key_conf *keyconf,
+ const u8 *addr, uint32_t iv32, u16 *p1k)
+{
+
+ KASSERT(keyconf != NULL && addr != NULL && p1k != NULL,
+ ("%s: keyconf %p addr %p p1k %p\n", __func__, keyconf, addr, p1k));
+
+ TODO();
+ memset(p1k, 0xfa, 5 * sizeof(*p1k)); /* Just initializing. */
+}
+
+static __inline void
+ieee80211_get_tkip_p1k_iv(struct ieee80211_key_conf *key,
+ uint32_t iv32, uint16_t *p1k)
+{
+ TODO();
+}
+
+static __inline void
+ieee80211_get_tkip_p2k(struct ieee80211_key_conf *keyconf,
+ struct sk_buff *skb_frag, u8 *key)
+{
+ TODO();
+}
+
+static inline void
+ieee80211_get_key_rx_seq(struct ieee80211_key_conf *keyconf, int8_t tid,
+ struct ieee80211_key_seq *seq)
+{
+ const struct ieee80211_key *k;
+ const uint8_t *p;
+
+ KASSERT(keyconf != NULL && seq != NULL, ("%s: keyconf %p seq %p\n",
+ __func__, keyconf, seq));
+ k = keyconf->_k;
+ KASSERT(k != NULL, ("%s: keyconf %p ieee80211_key is NULL\n", __func__, keyconf));
+
+ switch (keyconf->cipher) {
+ case WLAN_CIPHER_SUITE_TKIP:
+ if (tid < 0 || tid >= IEEE80211_NUM_TIDS)
+ return;
+ /* See net80211::tkip_decrypt() */
+ seq->tkip.iv32 = TKIP_PN_TO_IV32(k->wk_keyrsc[tid]);
+ seq->tkip.iv16 = TKIP_PN_TO_IV16(k->wk_keyrsc[tid]);
+ break;
+ case WLAN_CIPHER_SUITE_CCMP:
+ case WLAN_CIPHER_SUITE_CCMP_256:
+ if (tid < -1 || tid >= IEEE80211_NUM_TIDS)
+ return;
+ if (tid == -1)
+ p = (const uint8_t *)&k->wk_keyrsc[IEEE80211_NUM_TIDS]; /* IEEE80211_NONQOS_TID */
+ else
+ p = (const uint8_t *)&k->wk_keyrsc[tid];
+ memcpy(seq->ccmp.pn, p, sizeof(seq->ccmp.pn));
+ break;
+ case WLAN_CIPHER_SUITE_GCMP:
+ case WLAN_CIPHER_SUITE_GCMP_256:
+ if (tid < -1 || tid >= IEEE80211_NUM_TIDS)
+ return;
+ if (tid == -1)
+ p = (const uint8_t *)&k->wk_keyrsc[IEEE80211_NUM_TIDS]; /* IEEE80211_NONQOS_TID */
+ else
+ p = (const uint8_t *)&k->wk_keyrsc[tid];
+ memcpy(seq->gcmp.pn, p, sizeof(seq->gcmp.pn));
+ break;
+ case WLAN_CIPHER_SUITE_AES_CMAC:
+ case WLAN_CIPHER_SUITE_BIP_CMAC_256:
+ TODO();
+ memset(seq->aes_cmac.pn, 0xfa, sizeof(seq->aes_cmac.pn)); /* XXX TODO */
+ break;
+ case WLAN_CIPHER_SUITE_BIP_GMAC_128:
+ case WLAN_CIPHER_SUITE_BIP_GMAC_256:
+ TODO();
+ memset(seq->aes_gmac.pn, 0xfa, sizeof(seq->aes_gmac.pn)); /* XXX TODO */
+ break;
+ default:
+ pr_debug("%s: unsupported cipher suite %d\n", __func__, keyconf->cipher);
+ break;
+ }
+}
+
+static __inline void
+ieee80211_set_key_rx_seq(struct ieee80211_key_conf *key, int tid,
+ struct ieee80211_key_seq *seq)
+{
+ TODO();
+}
+
+/* -------------------------------------------------------------------------- */
+
+static __inline void
+ieee80211_report_wowlan_wakeup(struct ieee80211_vif *vif,
+ struct cfg80211_wowlan_wakeup *wakeup, gfp_t gfp)
+{
+ TODO();
+}
+
+static __inline void
+ieee80211_obss_color_collision_notify(struct ieee80211_vif *vif,
+ uint64_t obss_color_bitmap, gfp_t gfp)
+{
+ TODO();
+}
+
+static __inline void
+ieee80211_refresh_tx_agg_session_timer(struct ieee80211_sta *sta,
+ uint8_t tid)
+{
+ TODO();
+}
+
+static __inline struct ieee80211_ema_beacons *
+ieee80211_beacon_get_template_ema_list(struct ieee80211_hw *hw,
+ struct ieee80211_vif *vif, uint32_t link_id)
+{
+ TODO();
+ return (NULL);
+}
+
+static __inline void
+ieee80211_beacon_free_ema_list(struct ieee80211_ema_beacons *bcns)
+{
+ TODO();
+}
+
+static inline bool
+ieee80211_vif_is_mld(const struct ieee80211_vif *vif)
+{
+
+ /* If valid_links is non-zero, the vif is an MLD. */
+ return (vif->valid_links != 0);
+}
+
+static inline const struct ieee80211_sta_he_cap *
+ieee80211_get_he_iftype_cap_vif(const struct ieee80211_supported_band *band,
+ struct ieee80211_vif *vif)
+{
+ enum nl80211_iftype iftype;
+
+ iftype = ieee80211_vif_type_p2p(vif);
+ return (ieee80211_get_he_iftype_cap(band, iftype));
+}
+
+static inline const struct ieee80211_sta_eht_cap *
+ieee80211_get_eht_iftype_cap_vif(const struct ieee80211_supported_band *band,
+ struct ieee80211_vif *vif)
+{
+ enum nl80211_iftype iftype;
+
+ iftype = ieee80211_vif_type_p2p(vif);
+ return (ieee80211_get_eht_iftype_cap(band, iftype));
+}
+
+static inline uint32_t
+ieee80211_vif_usable_links(const struct ieee80211_vif *vif)
+{
+ IMPROVE("MLO usable links likely are not just valid");
+ return (vif->valid_links);
+}
+
+static inline bool
+ieee80211_vif_link_active(const struct ieee80211_vif *vif, uint8_t link_id)
+{
+ if (ieee80211_vif_is_mld(vif))
+ return (vif->active_links & BIT(link_id));
+ return (link_id == 0);
+}
+
+static inline void
+ieee80211_set_active_links_async(struct ieee80211_vif *vif,
+ uint32_t new_active_links)
+{
+ TODO();
+}
+
+static inline int
+ieee80211_set_active_links(struct ieee80211_vif *vif,
+ uint32_t active_links)
+{
+ TODO();
+ return (-ENXIO);
+}
+
+static inline void
+ieee80211_cqm_beacon_loss_notify(struct ieee80211_vif *vif, gfp_t gfp __unused)
+{
+ IMPROVE("we notify user space by a vap state change eventually");
+ linuxkpi_ieee80211_beacon_loss(vif);
+}
+
+#define ieee80211_send_bar(_v, _r, _t, _s) \
+ linuxkpi_ieee80211_send_bar(_v, _r, _t, _s)
+
+/* -------------------------------------------------------------------------- */
+
+int lkpi_80211_update_chandef(struct ieee80211_hw *,
+ struct ieee80211_chanctx_conf *);
+
+static inline int
+ieee80211_emulate_add_chanctx(struct ieee80211_hw *hw,
+ struct ieee80211_chanctx_conf *chanctx_conf)
+{
+ int error;
+
+ hw->conf.radar_enabled = chanctx_conf->radar_enabled;
+ error = lkpi_80211_update_chandef(hw, chanctx_conf);
+ return (error);
+}
+
+static inline void
+ieee80211_emulate_remove_chanctx(struct ieee80211_hw *hw,
+ struct ieee80211_chanctx_conf *chanctx_conf __unused)
+{
+ hw->conf.radar_enabled = false;
+ lkpi_80211_update_chandef(hw, NULL);
+}
+
+static inline void
+ieee80211_emulate_change_chanctx(struct ieee80211_hw *hw,
+ struct ieee80211_chanctx_conf *chanctx_conf, uint32_t changed __unused)
+{
+ hw->conf.radar_enabled = chanctx_conf->radar_enabled;
+ lkpi_80211_update_chandef(hw, chanctx_conf);
+}
+
+static inline int
+ieee80211_emulate_switch_vif_chanctx(struct ieee80211_hw *hw,
+ struct ieee80211_vif_chanctx_switch *vifs, int n_vifs,
+ enum ieee80211_chanctx_switch_mode mode __unused)
+{
+ struct ieee80211_chanctx_conf *chanctx_conf;
+ int error;
+
+ /* Sanity check. */
+ if (n_vifs <= 0)
+ return (-EINVAL);
+ if (vifs == NULL || vifs[0].new_ctx == NULL)
+ return (-EINVAL);
+
+ /*
+ * What to do if n_vifs > 1?
+ * Does that make sense for drivers not supporting chanctx?
+ */
+ hw->conf.radar_enabled = vifs[0].new_ctx->radar_enabled;
+ chanctx_conf = vifs[0].new_ctx;
+ error = lkpi_80211_update_chandef(hw, chanctx_conf);
+ return (error);
+}
+
+/* -------------------------------------------------------------------------- */
+
+#endif /* _LINUXKPI_NET_MAC80211_H */
diff --git a/sys/compat/linuxkpi/common/include/net/netevent.h b/sys/compat/linuxkpi/common/include/net/netevent.h
index 3c6fba2f28d6..c1c39af3a772 100644
--- a/sys/compat/linuxkpi/common/include/net/netevent.h
+++ b/sys/compat/linuxkpi/common/include/net/netevent.h
@@ -25,11 +25,9 @@
* 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.
- *
- * $FreeBSD$
*/
-#ifndef _LINUX_NET_NETEVENT_H_
-#define _LINUX_NET_NETEVENT_H_
+#ifndef _LINUXKPI_NET_NETEVENT_H_
+#define _LINUXKPI_NET_NETEVENT_H_
#include <sys/types.h>
#include <sys/eventhandler.h>
@@ -72,4 +70,4 @@ unregister_netevent_notifier(struct notifier_block *nb)
return (0);
}
-#endif /* _LINUX_NET_NETEVENT_H_ */
+#endif /* _LINUXKPI_NET_NETEVENT_H_ */
diff --git a/sys/compat/linuxkpi/common/include/net/netlink.h b/sys/compat/linuxkpi/common/include/net/netlink.h
new file mode 100644
index 000000000000..ae250177d18b
--- /dev/null
+++ b/sys/compat/linuxkpi/common/include/net/netlink.h
@@ -0,0 +1,53 @@
+/*-
+ * Copyright (c) 2020,2022 Bjoern A. Zeeb
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``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 OR CONTRIBUTORS 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.
+ */
+
+#ifndef _LINUXKPI_NET_NETLINK_H
+#define _LINUXKPI_NET_NETLINK_H
+
+#include <netlink/netlink.h>
+
+struct nla_policy {
+};
+
+struct netlink_callback {
+ int args[8];
+};
+
+static __inline int
+nla_put(struct sk_buff *skb, int attr, size_t len, void *data)
+{
+
+ pr_debug("%s: TODO -- now native?\n", __func__);
+ return (-ENXIO);
+}
+
+static __inline int
+nla_put_u16(struct sk_buff *skb, int attr, uint32_t val)
+{
+
+ return (nla_put(skb, attr, sizeof(uint32_t), &val));
+}
+
+#endif /* _LINUXKPI_NET_NETLINK_H */
diff --git a/sys/compat/linuxkpi/common/include/net/netmem.h b/sys/compat/linuxkpi/common/include/net/netmem.h
new file mode 100644
index 000000000000..c8de09a2e8c2
--- /dev/null
+++ b/sys/compat/linuxkpi/common/include/net/netmem.h
@@ -0,0 +1,21 @@
+/*-
+ * Copyright (c) 2023-2025 Bjoern A. Zeeb
+ *
+ * SPDX-License-Identifier: BSD-2-Clause
+ */
+
+#ifndef _LINUXKPI_NET_NETMEM_H
+#define _LINUXKPI_NET_NETMEM_H
+
+struct page_pool;
+
+struct netmem_desc {
+ struct page_pool *pp;
+};
+
+#define pp_page_to_nmdesc(page) \
+ (_Generic((page), \
+ const struct page *: (const struct netmem_desc *)(page), \
+ struct page *: (struct netmem_desc *)(page)))
+
+#endif /* _LINUXKPI_NET_NETMEM_H */
diff --git a/sys/compat/linuxkpi/common/include/net/page_pool/helpers.h b/sys/compat/linuxkpi/common/include/net/page_pool/helpers.h
new file mode 100644
index 000000000000..3469c39c7757
--- /dev/null
+++ b/sys/compat/linuxkpi/common/include/net/page_pool/helpers.h
@@ -0,0 +1,79 @@
+/*-
+ * Copyright (c) 2023-2025 Bjoern A. Zeeb
+ *
+ * SPDX-License-Identifier: BSD-2-Clause
+ */
+
+#ifndef _LINUXKPI_NET_PAGE_POOL_HELPERS_H
+#define _LINUXKPI_NET_PAGE_POOL_HELPERS_H
+
+#include <linux/kernel.h> /* pr_debug */
+#include <linux/types.h>
+#include <linux/dma-mapping.h>
+#include <net/page_pool/types.h>
+
+static inline struct page_pool *
+page_pool_create(const struct page_pool_params *ppparams)
+{
+
+ pr_debug("%s: TODO\n", __func__);
+ return (NULL);
+}
+
+static inline void
+page_pool_destroy(struct page_pool *ppool)
+{
+
+ pr_debug("%s: TODO\n", __func__);
+}
+
+static inline struct page *
+page_pool_dev_alloc_frag(struct page_pool *ppool, uint32_t *offset,
+ size_t size)
+{
+
+ pr_debug("%s: TODO\n", __func__);
+ return (NULL);
+}
+
+static inline dma_addr_t
+page_pool_get_dma_addr(struct page *page)
+{
+
+ pr_debug("%s: TODO\n", __func__);
+ return (0);
+}
+
+static inline enum dma_data_direction
+page_pool_get_dma_dir(const struct page_pool *ppool)
+{
+
+ pr_debug("%s: TODO\n", __func__);
+ return (DMA_BIDIRECTIONAL);
+}
+
+static inline void
+page_pool_put_full_page(struct page_pool *ppool, struct page *page,
+ bool allow_direct)
+{
+
+ pr_debug("%s: TODO\n", __func__);
+}
+
+static inline int
+page_pool_ethtool_stats_get_count(void)
+{
+
+ pr_debug("%s: TODO\n", __func__);
+ return (0);
+}
+
+static inline uint8_t *
+page_pool_ethtool_stats_get_strings(uint8_t *x)
+{
+
+ pr_debug("%s: TODO\n", __func__);
+ return (x);
+}
+
+#endif /* _LINUXKPI_NET_PAGE_POOL_HELPERS_H */
diff --git a/sys/compat/linuxkpi/common/include/net/page_pool/types.h b/sys/compat/linuxkpi/common/include/net/page_pool/types.h
new file mode 100644
index 000000000000..6747be50b9b2
--- /dev/null
+++ b/sys/compat/linuxkpi/common/include/net/page_pool/types.h
@@ -0,0 +1,36 @@
+/*-
+ * Copyright (c) 2023-2025 Bjoern A. Zeeb
+ *
+ * SPDX-License-Identifier: BSD-2-Clause
+ */
+
+#ifndef _LINUXKPI_NET_PAGE_POOL_TYPES_H
+#define _LINUXKPI_NET_PAGE_POOL_TYPES_H
+
+#include <linux/types.h>
+#include <linux/dma-mapping.h>
+#include <net/netmem.h>
+
+struct device;
+struct napi_struct;
+
+struct page_pool_params {
+ struct device *dev;
+ uint32_t flags;
+ uint32_t order;
+ uint32_t pool_size;
+ uint32_t max_len;
+ uint32_t offset;
+ int nid; /* NUMA */
+ enum dma_data_direction dma_dir;
+ struct napi_struct *napi;
+};
+
+struct page_pool {
+};
+
+#define PP_FLAG_DMA_MAP BIT(0)
+#define PP_FLAG_DMA_SYNC_DEV BIT(1)
+#define PP_FLAG_PAGE_FRAG BIT(2)
+
+#endif /* _LINUXKPI_NET_PAGE_POOL_TYPES_H */
diff --git a/sys/compat/linuxkpi/common/include/net/regulatory.h b/sys/compat/linuxkpi/common/include/net/regulatory.h
new file mode 100644
index 000000000000..0a538f1531f9
--- /dev/null
+++ b/sys/compat/linuxkpi/common/include/net/regulatory.h
@@ -0,0 +1,47 @@
+/*-
+ * Copyright (c) 2020-2021 The FreeBSD Foundation
+ * Copyright (c) 2021-2022 Bjoern A. Zeeb
+ *
+ * This software was developed by Björn Zeeb under sponsorship from
+ * the FreeBSD Foundation.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``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 OR CONTRIBUTORS 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.
+ */
+
+#ifndef _LINUXKPI_NET_REGULATORY_H
+#define _LINUXKPI_NET_REGULATORY_H
+
+enum environment_cap {
+ ENVIRON_INDOOR = 1, /* keep != 0 */
+};
+
+#define REG_RULE(_begin, _end, _bw, _mag, _meirp, _flags) \
+{ \
+ .flags = (_flags), \
+ .freq_range.start_freq_khz = MHZ_TO_KHZ(_begin), \
+ .freq_range.end_freq_khz = MHZ_TO_KHZ(_end), \
+ .freq_range.max_bandwidth_khz = MHZ_TO_KHZ(_bw), \
+ .power_rule.max_antenna_gain = DBI_TO_MBI(_mag), \
+ .power_rule.max_eirp = DBI_TO_MBI(_meirp), \
+}
+
+#endif /* _LINUXKPI_NET_REGULATORY_H */
diff --git a/sys/compat/linuxkpi/common/include/net/tcp.h b/sys/compat/linuxkpi/common/include/net/tcp.h
index 3f156196aaaf..4804a2b09b9d 100644
--- a/sys/compat/linuxkpi/common/include/net/tcp.h
+++ b/sys/compat/linuxkpi/common/include/net/tcp.h
@@ -25,11 +25,9 @@
* 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.
- *
- * $FreeBSD$
*/
-#ifndef _LINUX_NET_TCP_H_
-#define _LINUX_NET_TCP_H_
+#ifndef _LINUXKPI_NET_TCP_H_
+#define _LINUXKPI_NET_TCP_H_
#include <linux/list.h>
#include <linux/slab.h>
@@ -37,4 +35,4 @@
#include <net/ip.h>
-#endif /* _LINUX_NET_TCP_H_ */
+#endif /* _LINUXKPI_NET_TCP_H_ */
diff --git a/sys/compat/linuxkpi/common/include/stdarg.h b/sys/compat/linuxkpi/common/include/stdarg.h
new file mode 100644
index 000000000000..698ac45e9198
--- /dev/null
+++ b/sys/compat/linuxkpi/common/include/stdarg.h
@@ -0,0 +1,33 @@
+/*-
+ * SPDX-License-Identifier: BSD-2-Clause
+ *
+ * Copyright (c) 2021 Vladimir Kondratyev <wulf@FreeBSD.org>
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice unmodified, this list of conditions, and the following
+ * disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``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.
+ */
+
+#ifndef _LINUXKPI_STDARG_H_
+#define _LINUXKPI_STDARG_H_
+
+#include <sys/stdarg.h>
+
+#endif /* _LINUXKPI_STDARG_H_ */
diff --git a/sys/compat/linuxkpi/common/include/video/cmdline.h b/sys/compat/linuxkpi/common/include/video/cmdline.h
new file mode 100644
index 000000000000..eaa9a998fda2
--- /dev/null
+++ b/sys/compat/linuxkpi/common/include/video/cmdline.h
@@ -0,0 +1,44 @@
+/*-
+ * SPDX-License-Identifier: BSD-2-Clause
+ *
+ * Copyright (c) 2023 Serenity Cyber Security, LLC.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``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 OR CONTRIBUTORS 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.
+ */
+
+#ifndef _VIDEO_CMDLINE_H_
+#define _VIDEO_CMDLINE_H_
+
+#include <linux/types.h>
+
+#define CONFIG_VIDEO_CMDLINE
+
+#if defined(CONFIG_VIDEO_CMDLINE)
+const char *video_get_options(const char *name);
+#else
+static inline const char *
+video_get_options(const char *name)
+{
+ return (NULL);
+}
+#endif
+#endif /* _VIDEO_CMDLINE_H_ */
diff --git a/sys/compat/linuxkpi/common/include/video/mipi_display.h b/sys/compat/linuxkpi/common/include/video/mipi_display.h
new file mode 100644
index 000000000000..ea079a57d39f
--- /dev/null
+++ b/sys/compat/linuxkpi/common/include/video/mipi_display.h
@@ -0,0 +1,64 @@
+/* Public domain. */
+
+#ifndef _LINUXKPI_VIDEO_MIPI_DISPLAY_H_
+#define _LINUXKPI_VIDEO_MIPI_DISPLAY_H_
+
+#define MIPI_DSI_V_SYNC_START 0x01
+#define MIPI_DSI_V_SYNC_END 0x11
+#define MIPI_DSI_H_SYNC_START 0x21
+#define MIPI_DSI_H_SYNC_END 0x31
+#define MIPI_DSI_COMPRESSION_MODE 0x07
+#define MIPI_DSI_END_OF_TRANSMISSION 0x08
+#define MIPI_DSI_COLOR_MODE_OFF 0x02
+#define MIPI_DSI_COLOR_MODE_ON 0x12
+#define MIPI_DSI_SHUTDOWN_PERIPHERAL 0x22
+#define MIPI_DSI_TURN_ON_PERIPHERAL 0x32
+#define MIPI_DSI_GENERIC_SHORT_WRITE_0_PARAM 0x03
+#define MIPI_DSI_GENERIC_SHORT_WRITE_1_PARAM 0x13
+#define MIPI_DSI_GENERIC_SHORT_WRITE_2_PARAM 0x23
+#define MIPI_DSI_GENERIC_READ_REQUEST_0_PARAM 0x04
+#define MIPI_DSI_GENERIC_READ_REQUEST_1_PARAM 0x14
+#define MIPI_DSI_GENERIC_READ_REQUEST_2_PARAM 0x24
+#define MIPI_DSI_DCS_SHORT_WRITE 0x05
+#define MIPI_DSI_DCS_SHORT_WRITE_PARAM 0x15
+#define MIPI_DSI_DCS_READ 0x06
+#define MIPI_DSI_EXECUTE_QUEUE 0x16
+#define MIPI_DSI_SET_MAXIMUM_RETURN_PACKET_SIZE 0x37
+#define MIPI_DSI_NULL_PACKET 0x09
+#define MIPI_DSI_BLANKING_PACKET 0x19
+#define MIPI_DSI_GENERIC_LONG_WRITE 0x29
+#define MIPI_DSI_DCS_LONG_WRITE 0x39
+#define MIPI_DSI_PICTURE_PARAMETER_SET 0x0a
+#define MIPI_DSI_COMPRESSED_PIXEL_STREAM 0x0b
+#define MIPI_DSI_LOOSELY_PACKED_PIXEL_STREAM_YCBCR20 0x0c
+#define MIPI_DSI_PACKED_PIXEL_STREAM_YCBCR24 0x1c
+#define MIPI_DSI_PACKED_PIXEL_STREAM_YCBCR16 0x2c
+#define MIPI_DSI_PACKED_PIXEL_STREAM_30 0x0d
+#define MIPI_DSI_PACKED_PIXEL_STREAM_36 0x1d
+#define MIPI_DSI_PACKED_PIXEL_STREAM_YCBCR12 0x3d
+#define MIPI_DSI_PACKED_PIXEL_STREAM_16 0x0e
+#define MIPI_DSI_PACKED_PIXEL_STREAM_18 0x1e
+#define MIPI_DSI_PIXEL_STREAM_3BYTE_18 0x2e
+#define MIPI_DSI_PACKED_PIXEL_STREAM_24 0x3e
+
+#define MIPI_DCS_NOP 0x00
+#define MIPI_DCS_SOFT_RESET 0x01
+#define MIPI_DCS_GET_POWER_MODE 0x0a
+#define MIPI_DCS_GET_PIXEL_FORMAT 0x0c
+#define MIPI_DCS_ENTER_SLEEP_MODE 0x10
+#define MIPI_DCS_EXIT_SLEEP_MODE 0x11
+#define MIPI_DCS_SET_DISPLAY_OFF 0x28
+#define MIPI_DCS_SET_DISPLAY_ON 0x29
+#define MIPI_DCS_SET_COLUMN_ADDRESS 0x2a
+#define MIPI_DCS_SET_PAGE_ADDRESS 0x2b
+#define MIPI_DCS_SET_TEAR_OFF 0x34
+#define MIPI_DCS_SET_TEAR_ON 0x35
+#define MIPI_DCS_SET_PIXEL_FORMAT 0x3a
+#define MIPI_DCS_SET_TEAR_SCANLINE 0x44
+#define MIPI_DCS_SET_DISPLAY_BRIGHTNESS 0x51
+#define MIPI_DCS_GET_DISPLAY_BRIGHTNESS 0x52
+#define MIPI_DCS_WRITE_CONTROL_DISPLAY 0x53
+#define MIPI_DCS_GET_CONTROL_DISPLAY 0x54
+#define MIPI_DCS_WRITE_POWER_SAVE 0x55
+
+#endif /* _LINUXKPI_VIDEO_MIPI_DISPLAY_H_ */
diff --git a/sys/compat/linuxkpi/common/include/video/vga.h b/sys/compat/linuxkpi/common/include/video/vga.h
new file mode 100644
index 000000000000..a5012d9e2f3f
--- /dev/null
+++ b/sys/compat/linuxkpi/common/include/video/vga.h
@@ -0,0 +1,19 @@
+/* Public domain. */
+
+#ifndef _LINUXKPI_VIDEO_VGA_H
+#define _LINUXKPI_VIDEO_VGA_H
+
+#include <linux/types.h>
+#include <linux/io.h>
+
+#define VGA_MIS_W 0x3c2
+#define VGA_SEQ_I 0x3c4
+#define VGA_SEQ_D 0x3c5
+#define VGA_MIS_R 0x3cc
+
+#define VGA_SR01_SCREEN_OFF (1 << 5)
+
+#define VGA_FB_PHYS_BASE 0xA0000
+#define VGA_FB_PHYS_SIZE 65536
+
+#endif
diff --git a/sys/compat/linuxkpi/common/include/xen/xen.h b/sys/compat/linuxkpi/common/include/xen/xen.h
new file mode 100644
index 000000000000..16e77724111d
--- /dev/null
+++ b/sys/compat/linuxkpi/common/include/xen/xen.h
@@ -0,0 +1,37 @@
+/*-
+ * SPDX-License-Identifier: BSD-2-Clause
+ *
+ * Copyright (c) 2023 Serenity Cyber Security, LLC.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``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 OR CONTRIBUTORS 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.
+ */
+
+#ifndef _LINUXKPI_XEN_XEN_H_
+#define _LINUXKPI_XEN_XEN_H_
+
+#define xen_initial_domain() lkpi_xen_initial_domain()
+#define xen_pv_domain() lkpi_xen_pv_domain()
+
+bool lkpi_xen_initial_domain(void);
+bool lkpi_xen_pv_domain(void);
+
+#endif /* _LINUXKPI_XEN_XEN_H_ */
diff --git a/sys/compat/linuxkpi/common/src/linux_80211.c b/sys/compat/linuxkpi/common/src/linux_80211.c
new file mode 100644
index 000000000000..0dc3b2631804
--- /dev/null
+++ b/sys/compat/linuxkpi/common/src/linux_80211.c
@@ -0,0 +1,8933 @@
+/*-
+ * Copyright (c) 2020-2025 The FreeBSD Foundation
+ * Copyright (c) 2020-2025 Bjoern A. Zeeb
+ *
+ * This software was developed by Björn Zeeb under sponsorship from
+ * the FreeBSD Foundation.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``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 OR CONTRIBUTORS 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.
+ */
+
+/*
+ * Public functions are called linuxkpi_*().
+ * Internal (static) functions are called lkpi_*().
+ *
+ * The internal structures holding metadata over public structures are also
+ * called lkpi_xxx (usually with a member at the end called xxx).
+ * Note: we do not replicate the structure names but the general variable names
+ * for these (e.g., struct hw -> struct lkpi_hw, struct sta -> struct lkpi_sta).
+ * There are macros to access one from the other.
+ * We call the internal versions lxxx (e.g., hw -> lhw, sta -> lsta).
+ */
+
+/*
+ * TODO:
+ * - lots :)
+ * - HW_CRYPTO: we need a "keystore" and an ordered list for suspend/resume.
+ */
+
+#include <sys/param.h>
+#include <sys/types.h>
+#include <sys/kernel.h>
+#include <sys/errno.h>
+#include <sys/malloc.h>
+#include <sys/module.h>
+#include <sys/mutex.h>
+#include <sys/sbuf.h>
+#include <sys/socket.h>
+#include <sys/sysctl.h>
+#include <sys/queue.h>
+#include <sys/taskqueue.h>
+#include <sys/libkern.h>
+
+#include <net/if.h>
+#include <net/if_var.h>
+#include <net/if_media.h>
+#include <net/ethernet.h>
+
+#include <net80211/ieee80211_var.h>
+#include <net80211/ieee80211_proto.h>
+#include <net80211/ieee80211_ratectl.h>
+#include <net80211/ieee80211_radiotap.h>
+#include <net80211/ieee80211_vht.h>
+
+#define LINUXKPI_NET80211
+#include <net/mac80211.h>
+
+#include <linux/workqueue.h>
+#include <linux/rculist.h>
+#include "linux_80211.h"
+
+/* #define LKPI_80211_USE_SCANLIST */
+/* #define LKPI_80211_BGSCAN */
+#define LKPI_80211_WME
+#define LKPI_80211_HW_CRYPTO
+#define LKPI_80211_HT
+#define LKPI_80211_VHT
+
+#if defined(LKPI_80211_VHT) && !defined(LKPI_80211_HT)
+#define LKPI_80211_HT
+#endif
+#if defined(LKPI_80211_HT) && !defined(LKPI_80211_HW_CRYPTO)
+#define LKPI_80211_HW_CRYPTO
+#endif
+
+static MALLOC_DEFINE(M_LKPI80211, "lkpi80211", "LinuxKPI 80211 compat");
+
+/* XXX-BZ really want this and others in queue.h */
+#define TAILQ_ELEM_INIT(elm, field) do { \
+ (elm)->field.tqe_next = NULL; \
+ (elm)->field.tqe_prev = NULL; \
+} while (0)
+
+/* -------------------------------------------------------------------------- */
+
+SYSCTL_DECL(_compat_linuxkpi);
+SYSCTL_NODE(_compat_linuxkpi, OID_AUTO, 80211, CTLFLAG_RW | CTLFLAG_MPSAFE, 0,
+ "LinuxKPI 802.11 compatibility layer");
+
+static bool lkpi_order_scanlist = false;
+SYSCTL_BOOL(_compat_linuxkpi_80211, OID_AUTO, order_scanlist, CTLFLAG_RW,
+ &lkpi_order_scanlist, 0, "Enable LinuxKPI 802.11 scan list shuffeling");
+
+#if defined(LKPI_80211_HW_CRYPTO)
+static bool lkpi_hwcrypto = false;
+SYSCTL_BOOL(_compat_linuxkpi_80211, OID_AUTO, hw_crypto, CTLFLAG_RDTUN,
+ &lkpi_hwcrypto, 0, "Enable LinuxKPI 802.11 hardware crypto offload");
+
+static bool lkpi_hwcrypto_tkip = false;
+SYSCTL_BOOL(_compat_linuxkpi_80211, OID_AUTO, tkip, CTLFLAG_RDTUN,
+ &lkpi_hwcrypto_tkip, 0, "Enable LinuxKPI 802.11 TKIP crypto offload");
+#endif
+
+/* Keep public for as long as header files are using it too. */
+int linuxkpi_debug_80211;
+
+#ifdef LINUXKPI_DEBUG_80211
+SYSCTL_INT(_compat_linuxkpi_80211, OID_AUTO, debug, CTLFLAG_RWTUN,
+ &linuxkpi_debug_80211, 0, "LinuxKPI 802.11 debug level");
+
+#define UNIMPLEMENTED if (linuxkpi_debug_80211 & D80211_TODO) \
+ printf("XXX-TODO %s:%d: UNIMPLEMENTED\n", __func__, __LINE__)
+#define TRACEOK() if (linuxkpi_debug_80211 & D80211_TRACEOK) \
+ printf("XXX-TODO %s:%d: TRACEPOINT\n", __func__, __LINE__)
+#else
+#define UNIMPLEMENTED do { } while (0)
+#define TRACEOK() do { } while (0)
+#endif
+
+/* #define PREP_TX_INFO_DURATION (IEEE80211_TRANS_WAIT * 1000) */
+#ifndef PREP_TX_INFO_DURATION
+#define PREP_TX_INFO_DURATION 0 /* Let the driver do its thing. */
+#endif
+
+/* This is DSAP | SSAP | CTRL | ProtoID/OrgCode{3}. */
+const uint8_t rfc1042_header[6] = { 0xaa, 0xaa, 0x03, 0x00, 0x00, 0x00 };
+
+/* IEEE 802.11-05/0257r1 */
+const uint8_t bridge_tunnel_header[6] = { 0xaa, 0xaa, 0x03, 0x00, 0x00, 0xf8 };
+
+/* IEEE 802.11e Table 20i-UP-to-AC mappings. */
+static const uint8_t ieee80211e_up_to_ac[] = {
+ IEEE80211_AC_BE,
+ IEEE80211_AC_BK,
+ IEEE80211_AC_BK,
+ IEEE80211_AC_BE,
+ IEEE80211_AC_VI,
+ IEEE80211_AC_VI,
+ IEEE80211_AC_VO,
+ IEEE80211_AC_VO,
+#if 0
+ IEEE80211_AC_VO, /* We treat MGMT as TID 8, which is set as AC_VO */
+#endif
+};
+
+const struct cfg80211_ops linuxkpi_mac80211cfgops = {
+ /*
+ * XXX TODO need a "glue layer" to link cfg80211 ops to
+ * mac80211 and to the driver or net80211.
+ * Can we pass some on 1:1? Need to compare the (*f)().
+ */
+};
+
+#if 0
+static struct lkpi_sta *lkpi_find_lsta_by_ni(struct lkpi_vif *,
+ struct ieee80211_node *);
+#endif
+static void lkpi_sw_scan_task(void *, int);
+static void lkpi_80211_txq_tx_one(struct lkpi_sta *, struct mbuf *);
+static void lkpi_80211_txq_task(void *, int);
+static void lkpi_80211_lhw_rxq_task(void *, int);
+static void lkpi_ieee80211_free_skb_mbuf(void *);
+#ifdef LKPI_80211_WME
+static int lkpi_wme_update(struct lkpi_hw *, struct ieee80211vap *, bool);
+#endif
+static void lkpi_ieee80211_wake_queues_locked(struct ieee80211_hw *);
+
+static const char *
+lkpi_rate_info_bw_to_str(enum rate_info_bw bw)
+{
+
+ switch (bw) {
+
+ case RATE_INFO_BW_20:
+ return ("20");
+ break;
+ case RATE_INFO_BW_5:
+ return ("5");
+ break;
+ case RATE_INFO_BW_10:
+ return ("10");
+ break;
+ case RATE_INFO_BW_40:
+ return ("40");
+ break;
+ case RATE_INFO_BW_80:
+ return ("80");
+ break;
+ case RATE_INFO_BW_160:
+ return ("160");
+ break;
+ case RATE_INFO_BW_HE_RU:
+ IMPROVE("nl80211_he_ru_alloc");
+ return ("HE_RU");
+ break;
+ case RATE_INFO_BW_320:
+ return ("320");
+ break;
+ case RATE_INFO_BW_EHT_RU:
+ IMPROVE("nl80211_eht_ru_alloc");
+ return ("EHT_RU");
+ break;
+ default:
+ return ("?");
+ break;
+ }
+}
+
+static void
+lkpi_nl80211_sta_info_to_str(struct sbuf *s, const char *prefix,
+ const uint64_t flags)
+{
+ int bit, i;
+
+ sbuf_printf(s, "%s %#010jx", prefix, flags);
+
+ i = 0;
+ for (bit = 0; bit < BITS_PER_TYPE(flags); bit++) {
+
+ if ((flags & BIT_ULL(bit)) == 0)
+ continue;
+
+#define EXPAND_CASE(_flag) \
+ case NL80211_STA_INFO_ ## _flag: \
+ sbuf_printf(s, "%c%s", (i == 0) ? '<' : ',', #_flag); \
+ i++; \
+ break;
+
+ switch (bit) {
+ EXPAND_CASE(BEACON_RX)
+ EXPAND_CASE(BEACON_SIGNAL_AVG)
+ EXPAND_CASE(BSS_PARAM)
+ EXPAND_CASE(CHAIN_SIGNAL)
+ EXPAND_CASE(CHAIN_SIGNAL_AVG)
+ EXPAND_CASE(CONNECTED_TIME)
+ EXPAND_CASE(INACTIVE_TIME)
+ EXPAND_CASE(SIGNAL)
+ EXPAND_CASE(SIGNAL_AVG)
+ EXPAND_CASE(STA_FLAGS)
+ EXPAND_CASE(RX_BITRATE)
+ EXPAND_CASE(RX_PACKETS)
+ EXPAND_CASE(RX_BYTES)
+ EXPAND_CASE(RX_DROP_MISC)
+ EXPAND_CASE(TX_BITRATE)
+ EXPAND_CASE(TX_PACKETS)
+ EXPAND_CASE(TX_BYTES)
+ EXPAND_CASE(TX_BYTES64)
+ EXPAND_CASE(RX_BYTES64)
+ EXPAND_CASE(TX_FAILED)
+ EXPAND_CASE(TX_RETRIES)
+ EXPAND_CASE(RX_DURATION)
+ EXPAND_CASE(TX_DURATION)
+ EXPAND_CASE(ACK_SIGNAL)
+ EXPAND_CASE(ACK_SIGNAL_AVG)
+ default:
+ sbuf_printf(s, "%c?%d", (i == 0) ? '<' : ',', bit);
+ break;
+ }
+ }
+#undef EXPAND_CASE
+ if (i > 0)
+ sbuf_printf(s, ">");
+ sbuf_printf(s, "\n");
+}
+
+static void
+lkpi_80211_dump_lvif_stas(struct lkpi_vif *lvif, struct sbuf *s)
+{
+ struct lkpi_hw *lhw;
+ struct ieee80211_hw *hw;
+ struct ieee80211vap *vap;
+ struct ieee80211_vif *vif;
+ struct lkpi_sta *lsta;
+ struct ieee80211_sta *sta;
+ struct station_info sinfo;
+ int error;
+
+ vif = LVIF_TO_VIF(lvif);
+ vap = LVIF_TO_VAP(lvif);
+ lhw = vap->iv_ic->ic_softc;
+ hw = LHW_TO_HW(lhw);
+
+ wiphy_lock(hw->wiphy);
+ list_for_each_entry(lsta, &lvif->lsta_list, lsta_list) {
+ sta = LSTA_TO_STA(lsta);
+
+ sbuf_putc(s, '\n');
+ sbuf_printf(s, "lsta %p sta %p added_to_drv %d\n", lsta, sta, lsta->added_to_drv);
+
+ memset(&sinfo, 0, sizeof(sinfo));
+ error = lkpi_80211_mo_sta_statistics(hw, vif, sta, &sinfo);
+ if (error == EEXIST) /* Not added to driver. */
+ continue;
+ if (error == ENOTSUPP) {
+ sbuf_printf(s, " sta_statistics not supported\n");
+ continue;
+ }
+ if (error != 0) {
+ sbuf_printf(s, " sta_statistics failed: %d\n", error);
+ continue;
+ }
+
+ /* If no RX_BITRATE is reported, try to fill it in from the lsta sinfo. */
+ if ((sinfo.filled & BIT_ULL(NL80211_STA_INFO_RX_BITRATE)) == 0 &&
+ (lsta->sinfo.filled & BIT_ULL(NL80211_STA_INFO_RX_BITRATE)) != 0) {
+ memcpy(&sinfo.rxrate, &lsta->sinfo.rxrate, sizeof(sinfo.rxrate));
+ sinfo.filled |= BIT_ULL(NL80211_STA_INFO_RX_BITRATE);
+ }
+ /* If no CHAIN_SIGNAL is reported, try to fill it in from the lsta sinfo. */
+ if ((sinfo.filled & BIT_ULL(NL80211_STA_INFO_CHAIN_SIGNAL)) == 0 &&
+ (lsta->sinfo.filled & BIT_ULL(NL80211_STA_INFO_CHAIN_SIGNAL)) != 0) {
+ sinfo.chains = lsta->sinfo.chains;
+ memcpy(sinfo.chain_signal, lsta->sinfo.chain_signal,
+ sizeof(sinfo.chain_signal));
+ sinfo.filled |= BIT_ULL(NL80211_STA_INFO_CHAIN_SIGNAL);
+ }
+
+ lkpi_nl80211_sta_info_to_str(s, " nl80211_sta_info (valid fields)", sinfo.filled);
+ sbuf_printf(s, " connected_time %u inactive_time %u\n",
+ sinfo.connected_time, sinfo.inactive_time);
+ sbuf_printf(s, " rx_bytes %ju rx_packets %u rx_dropped_misc %u\n",
+ (uintmax_t)sinfo.rx_bytes, sinfo.rx_packets, sinfo.rx_dropped_misc);
+ sbuf_printf(s, " rx_duration %ju rx_beacon %u rx_beacon_signal_avg %d\n",
+ (uintmax_t)sinfo.rx_duration, sinfo.rx_beacon, (int8_t)sinfo.rx_beacon_signal_avg);
+
+ sbuf_printf(s, " tx_bytes %ju tx_packets %u tx_failed %u\n",
+ (uintmax_t)sinfo.tx_bytes, sinfo.tx_packets, sinfo.tx_failed);
+ sbuf_printf(s, " tx_duration %ju tx_retries %u\n",
+ (uintmax_t)sinfo.tx_duration, sinfo.tx_retries);
+
+ sbuf_printf(s, " signal %d signal_avg %d ack_signal %d avg_ack_signal %d\n",
+ sinfo.signal, sinfo.signal_avg, sinfo.ack_signal, sinfo.avg_ack_signal);
+ sbuf_printf(s, " generation %d assoc_req_ies_len %zu chains %#04x\n",
+ sinfo.generation, sinfo.assoc_req_ies_len, sinfo.chains);
+
+ for (int i = 0; i < nitems(sinfo.chain_signal) && i < IEEE80211_MAX_CHAINS; i++) {
+ if (!(sinfo.chains & BIT(i)))
+ continue;
+ sbuf_printf(s, " chain[%d] signal %d signal_avg %d\n",
+ i, (int8_t)sinfo.chain_signal[i], (int8_t)sinfo.chain_signal_avg[i]);
+ }
+
+ /* assoc_req_ies, bss_param, sta_flags */
+
+ sbuf_printf(s, " rxrate: flags %b bw %u(%s) legacy %u kbit/s mcs %u nss %u\n",
+ sinfo.rxrate.flags, CFG80211_RATE_INFO_FLAGS_BITS,
+ sinfo.rxrate.bw, lkpi_rate_info_bw_to_str(sinfo.rxrate.bw),
+ sinfo.rxrate.legacy * 100,
+ sinfo.rxrate.mcs, sinfo.rxrate.nss);
+ sbuf_printf(s, " he_dcm %u he_gi %u he_ru_alloc %u eht_gi %u\n",
+ sinfo.rxrate.he_dcm, sinfo.rxrate.he_gi, sinfo.rxrate.he_ru_alloc,
+ sinfo.rxrate.eht_gi);
+ sbuf_printf(s, " txrate: flags %b bw %u(%s) legacy %u kbit/s mcs %u nss %u\n",
+ sinfo.txrate.flags, CFG80211_RATE_INFO_FLAGS_BITS,
+ sinfo.txrate.bw, lkpi_rate_info_bw_to_str(sinfo.txrate.bw),
+ sinfo.txrate.legacy * 100,
+ sinfo.txrate.mcs, sinfo.txrate.nss);
+ sbuf_printf(s, " he_dcm %u he_gi %u he_ru_alloc %u eht_gi %u\n",
+ sinfo.txrate.he_dcm, sinfo.txrate.he_gi, sinfo.txrate.he_ru_alloc,
+ sinfo.txrate.eht_gi);
+ }
+ wiphy_unlock(hw->wiphy);
+}
+
+static int
+lkpi_80211_dump_stas(SYSCTL_HANDLER_ARGS)
+{
+ struct lkpi_vif *lvif;
+ struct sbuf s;
+
+ if (req->newptr)
+ return (EPERM);
+
+ lvif = (struct lkpi_vif *)arg1;
+
+ sbuf_new_for_sysctl(&s, NULL, 1024, req);
+
+ lkpi_80211_dump_lvif_stas(lvif, &s);
+
+ sbuf_finish(&s);
+ sbuf_delete(&s);
+
+ return (0);
+}
+
+static enum ieee80211_sta_rx_bandwidth
+lkpi_cw_to_rx_bw(enum nl80211_chan_width cw)
+{
+ switch (cw) {
+ case NL80211_CHAN_WIDTH_320:
+ return (IEEE80211_STA_RX_BW_320);
+ case NL80211_CHAN_WIDTH_160:
+ case NL80211_CHAN_WIDTH_80P80:
+ return (IEEE80211_STA_RX_BW_160);
+ case NL80211_CHAN_WIDTH_80:
+ return (IEEE80211_STA_RX_BW_80);
+ case NL80211_CHAN_WIDTH_40:
+ return (IEEE80211_STA_RX_BW_40);
+ case NL80211_CHAN_WIDTH_20:
+ case NL80211_CHAN_WIDTH_20_NOHT:
+ return (IEEE80211_STA_RX_BW_20);
+ case NL80211_CHAN_WIDTH_5:
+ case NL80211_CHAN_WIDTH_10:
+ /* Unsupported input. */
+ return (IEEE80211_STA_RX_BW_20);
+ }
+}
+
+static enum nl80211_chan_width
+lkpi_rx_bw_to_cw(enum ieee80211_sta_rx_bandwidth rx_bw)
+{
+ switch (rx_bw) {
+ case IEEE80211_STA_RX_BW_20:
+ return (NL80211_CHAN_WIDTH_20); /* _NOHT */
+ case IEEE80211_STA_RX_BW_40:
+ return (NL80211_CHAN_WIDTH_40);
+ case IEEE80211_STA_RX_BW_80:
+ return (NL80211_CHAN_WIDTH_80);
+ case IEEE80211_STA_RX_BW_160:
+ return (NL80211_CHAN_WIDTH_160); /* 80P80 */
+ case IEEE80211_STA_RX_BW_320:
+ return (NL80211_CHAN_WIDTH_320);
+ }
+}
+
+static void
+lkpi_sync_chanctx_cw_from_rx_bw(struct ieee80211_hw *hw,
+ struct ieee80211_vif *vif, struct ieee80211_sta *sta)
+{
+ struct ieee80211_chanctx_conf *chanctx_conf;
+ enum ieee80211_sta_rx_bandwidth old_bw;
+ uint32_t changed;
+
+ chanctx_conf = rcu_dereference_protected(vif->bss_conf.chanctx_conf,
+ lockdep_is_held(&hw->wiphy->mtx));
+ if (chanctx_conf == NULL)
+ return;
+
+ old_bw = lkpi_cw_to_rx_bw(chanctx_conf->def.width);
+ if (old_bw == sta->deflink.bandwidth)
+ return;
+
+ chanctx_conf->def.width = lkpi_rx_bw_to_cw(sta->deflink.bandwidth);
+ if (chanctx_conf->def.width == NL80211_CHAN_WIDTH_20 &&
+ !sta->deflink.ht_cap.ht_supported)
+ chanctx_conf->def.width = NL80211_CHAN_WIDTH_20_NOHT;
+
+ chanctx_conf->min_def = chanctx_conf->def;
+
+ vif->bss_conf.chanreq.oper.width = chanctx_conf->def.width;
+
+ changed = IEEE80211_CHANCTX_CHANGE_MIN_WIDTH;
+ changed |= IEEE80211_CHANCTX_CHANGE_WIDTH;
+ lkpi_80211_mo_change_chanctx(hw, chanctx_conf, changed);
+}
+
+#if defined(LKPI_80211_HT)
+static void
+lkpi_sta_sync_ht_from_ni(struct ieee80211_vif *vif, struct ieee80211_sta *sta,
+ struct ieee80211_node *ni)
+{
+ struct ieee80211vap *vap;
+ uint8_t *ie;
+ struct ieee80211_ht_cap *htcap;
+ int i, rx_nss;
+
+ if ((ni->ni_flags & IEEE80211_NODE_HT) == 0) {
+ sta->deflink.ht_cap.ht_supported = false;
+ return;
+ }
+
+ sta->deflink.ht_cap.ht_supported = true;
+
+ /* htcap->ampdu_params_info */
+ vap = ni->ni_vap;
+ sta->deflink.ht_cap.ampdu_density = _IEEE80211_MASKSHIFT(ni->ni_htparam, IEEE80211_HTCAP_MPDUDENSITY);
+ if (sta->deflink.ht_cap.ampdu_density > vap->iv_ampdu_density)
+ sta->deflink.ht_cap.ampdu_density = vap->iv_ampdu_density;
+ sta->deflink.ht_cap.ampdu_factor = _IEEE80211_MASKSHIFT(ni->ni_htparam, IEEE80211_HTCAP_MAXRXAMPDU);
+ if (sta->deflink.ht_cap.ampdu_factor > vap->iv_ampdu_rxmax)
+ sta->deflink.ht_cap.ampdu_factor = vap->iv_ampdu_rxmax;
+
+ ie = ni->ni_ies.htcap_ie;
+ KASSERT(ie != NULL, ("%s: HT but no htcap_ie on ni %p\n", __func__, ni));
+ if (ie[0] == IEEE80211_ELEMID_VENDOR)
+ ie += 4;
+ ie += 2;
+ htcap = (struct ieee80211_ht_cap *)ie;
+ sta->deflink.ht_cap.cap = htcap->cap_info;
+ sta->deflink.ht_cap.mcs = htcap->mcs;
+
+ /*
+ * 802.11n-2009 20.6 Parameters for HT MCSs gives the mandatory/
+ * optional MCS for Nss=1..4. We need to check the first four
+ * MCS sets from the Rx MCS Bitmask; then there is MCS 32 and
+ * MCS33.. is UEQM.
+ */
+ rx_nss = 0;
+ for (i = 0; i < 4; i++) {
+ if (htcap->mcs.rx_mask[i] != 0)
+ rx_nss++;
+ }
+ if (rx_nss > 0) {
+ sta->deflink.rx_nss = rx_nss;
+ } else {
+ sta->deflink.ht_cap.ht_supported = false;
+ return;
+ }
+
+ if ((sta->deflink.ht_cap.cap & IEEE80211_HT_CAP_SUP_WIDTH_20_40) != 0 &&
+ IEEE80211_IS_CHAN_HT40(ni->ni_chan))
+ sta->deflink.bandwidth = IEEE80211_STA_RX_BW_40;
+ else
+ sta->deflink.bandwidth = IEEE80211_STA_RX_BW_20;
+
+ IMPROVE("sta->wme");
+
+ if (sta->deflink.ht_cap.cap & IEEE80211_HT_CAP_MAX_AMSDU)
+ sta->deflink.agg.max_amsdu_len = IEEE80211_MAX_MPDU_LEN_HT_7935;
+ else
+ sta->deflink.agg.max_amsdu_len = IEEE80211_MAX_MPDU_LEN_HT_3839;
+ sta->deflink.agg.max_rc_amsdu_len = IEEE80211_MAX_MPDU_LEN_HT_BA;
+#ifdef __handled_by_driver__ /* iwlwifi only? actually unused? */
+ for (i = 0; i < nitems(sta.deflink.agg.max_tid_amsdu_len); i++) {
+ sta->deflink.agg.max_tid_amsdu_len[j] = ;
+ }
+#endif
+}
+#endif
+
+#if defined(LKPI_80211_VHT)
+static void
+lkpi_sta_sync_vht_from_ni(struct ieee80211_vif *vif, struct ieee80211_sta *sta,
+ struct ieee80211_node *ni)
+{
+ enum ieee80211_sta_rx_bandwidth bw;
+ uint32_t width;
+ int rx_nss;
+ uint16_t rx_mcs_map;
+ uint8_t mcs;
+
+ if ((ni->ni_flags & IEEE80211_NODE_VHT) == 0 ||
+ !IEEE80211_IS_CHAN_VHT_5GHZ(ni->ni_chan)) {
+ sta->deflink.vht_cap.vht_supported = false;
+ return;
+ }
+
+ sta->deflink.vht_cap.vht_supported = true;
+
+ sta->deflink.vht_cap.cap = ni->ni_vhtcap;
+ sta->deflink.vht_cap.vht_mcs = ni->ni_vht_mcsinfo;
+
+ /*
+ * If VHT20/40 are selected do not update the bandwidth
+ * from HT but stya on VHT.
+ */
+ if (ni->ni_vht_chanwidth == IEEE80211_VHT_CHANWIDTH_USE_HT)
+ goto skip_bw;
+
+ bw = sta->deflink.bandwidth;
+ width = (sta->deflink.vht_cap.cap & IEEE80211_VHT_CAP_SUPP_CHAN_WIDTH_MASK);
+ switch (width) {
+ /* Deprecated. */
+ case IEEE80211_VHT_CAP_SUPP_CHAN_WIDTH_160MHZ:
+ case IEEE80211_VHT_CAP_SUPP_CHAN_WIDTH_160_80PLUS80MHZ:
+ bw = IEEE80211_STA_RX_BW_160;
+ break;
+ default:
+ /* Check if we do support 160Mhz somehow after all. */
+ if ((sta->deflink.vht_cap.cap & IEEE80211_VHT_CAP_EXT_NSS_BW_MASK) != 0)
+ bw = IEEE80211_STA_RX_BW_160;
+ else
+ bw = IEEE80211_STA_RX_BW_80;
+ }
+ /*
+ * While we can set what is possibly supported we also need to be
+ * on a channel which supports that bandwidth; e.g., we can support
+ * VHT160 but the AP only does VHT80.
+ * Further ni_chan will also have filtered out what we disabled
+ * by configuration.
+ * Once net80211 channel selection is fixed for 802.11-2020 and
+ * VHT160 we can possibly spare ourselves the above.
+ */
+ if (bw == IEEE80211_STA_RX_BW_160 &&
+ !IEEE80211_IS_CHAN_VHT160(ni->ni_chan) &&
+ !IEEE80211_IS_CHAN_VHT80P80(ni->ni_chan))
+ bw = IEEE80211_STA_RX_BW_80;
+ if (bw == IEEE80211_STA_RX_BW_80 &&
+ !IEEE80211_IS_CHAN_VHT80(ni->ni_chan))
+ bw = sta->deflink.bandwidth;
+ sta->deflink.bandwidth = bw;
+skip_bw:
+
+ rx_nss = 0;
+ rx_mcs_map = sta->deflink.vht_cap.vht_mcs.rx_mcs_map;
+ for (int i = 7; i >= 0; i--) {
+ mcs = rx_mcs_map >> (2 * i);
+ mcs &= 0x3;
+ if (mcs != IEEE80211_VHT_MCS_NOT_SUPPORTED) {
+ rx_nss = i + 1;
+ break;
+ }
+ }
+ if (rx_nss > 0)
+ sta->deflink.rx_nss = rx_nss;
+
+ switch (sta->deflink.vht_cap.cap & IEEE80211_VHT_CAP_MAX_MPDU_MASK) {
+ case IEEE80211_VHT_CAP_MAX_MPDU_LENGTH_11454:
+ sta->deflink.agg.max_amsdu_len = IEEE80211_MAX_MPDU_LEN_VHT_11454;
+ break;
+ case IEEE80211_VHT_CAP_MAX_MPDU_LENGTH_7991:
+ sta->deflink.agg.max_amsdu_len = IEEE80211_MAX_MPDU_LEN_VHT_7991;
+ break;
+ case IEEE80211_VHT_CAP_MAX_MPDU_LENGTH_3895:
+ default:
+ sta->deflink.agg.max_amsdu_len = IEEE80211_MAX_MPDU_LEN_VHT_3895;
+ break;
+ }
+}
+#endif
+
+static void
+lkpi_sta_sync_from_ni(struct ieee80211_hw *hw, struct ieee80211_vif *vif,
+ struct ieee80211_sta *sta, struct ieee80211_node *ni, bool updchnctx)
+{
+
+#if defined(LKPI_80211_HT)
+ lkpi_sta_sync_ht_from_ni(vif, sta, ni);
+#endif
+#if defined(LKPI_80211_VHT)
+ lkpi_sta_sync_vht_from_ni(vif, sta, ni);
+#endif
+
+ /*
+ * Ensure rx_nss is at least 1 as otherwise drivers run into
+ * unexpected problems.
+ */
+ sta->deflink.rx_nss = MAX(1, sta->deflink.rx_nss);
+
+ /*
+ * We are also called from node allocation which net80211
+ * can do even on `ifconfig down`; in that case the chanctx
+ * may still be valid and we get a discrepancy between
+ * sta and chanctx. Thus do not try to update the chanctx
+ * when called from lkpi_lsta_alloc().
+ */
+ if (updchnctx)
+ lkpi_sync_chanctx_cw_from_rx_bw(hw, vif, sta);
+}
+
+static uint8_t
+lkpi_get_max_rx_chains(struct ieee80211_node *ni)
+{
+ uint8_t chains;
+#if defined(LKPI_80211_HT) || defined(LKPI_80211_VHT)
+ struct lkpi_sta *lsta;
+ struct ieee80211_sta *sta;
+
+ lsta = ni->ni_drv_data;
+ sta = LSTA_TO_STA(lsta);
+#endif
+
+ chains = 1;
+#if defined(LKPI_80211_HT)
+ IMPROVE("We should factor counting MCS/NSS out for sync and here");
+ if (sta->deflink.ht_cap.ht_supported)
+ chains = MAX(chains, sta->deflink.rx_nss);
+#endif
+
+#if defined(LKPI_80211_VHT)
+ if (sta->deflink.vht_cap.vht_supported)
+ chains = MAX(chains, sta->deflink.rx_nss);
+#endif
+
+ return (chains);
+}
+
+static void
+lkpi_lsta_dump(struct lkpi_sta *lsta, struct ieee80211_node *ni,
+ const char *_f, int _l)
+{
+
+#ifdef LINUXKPI_DEBUG_80211
+ if ((linuxkpi_debug_80211 & D80211_TRACE_STA) == 0)
+ return;
+ if (lsta == NULL)
+ return;
+
+ printf("%s:%d lsta %p ni %p sta %p\n",
+ _f, _l, lsta, ni, &lsta->sta);
+ if (ni != NULL)
+ ieee80211_dump_node(NULL, ni);
+ printf("\ttxq_task txq len %d mtx\n", mbufq_len(&lsta->txq));
+ printf("\tkc %p state %d added_to_drv %d in_mgd %d\n",
+ &lsta->kc[0], lsta->state, lsta->added_to_drv, lsta->in_mgd);
+#endif
+}
+
+static void
+lkpi_lsta_remove(struct lkpi_sta *lsta, struct lkpi_vif *lvif)
+{
+
+ lockdep_assert_wiphy(lsta->hw->wiphy);
+
+ KASSERT(!list_empty(&lsta->lsta_list),
+ ("%s: lsta %p ni %p\n", __func__, lsta, lsta->ni));
+ list_del_init(&lsta->lsta_list);
+}
+
+static struct lkpi_sta *
+lkpi_lsta_alloc(struct ieee80211vap *vap, const uint8_t mac[IEEE80211_ADDR_LEN],
+ struct ieee80211_hw *hw, struct ieee80211_node *ni)
+{
+ struct lkpi_sta *lsta;
+ struct lkpi_vif *lvif;
+ struct ieee80211_vif *vif;
+ struct ieee80211_sta *sta;
+ int band, i, tid;
+
+ lsta = malloc(sizeof(*lsta) + hw->sta_data_size, M_LKPI80211,
+ M_NOWAIT | M_ZERO);
+ if (lsta == NULL)
+ return (NULL);
+
+ lsta->hw = hw;
+ lsta->added_to_drv = false;
+ lsta->state = IEEE80211_STA_NOTEXIST;
+ /*
+ * Link the ni to the lsta here without taking a reference.
+ * For one we would have to take the reference in node_init()
+ * as ieee80211_alloc_node() will initialise the refcount after us.
+ * For the other a ni and an lsta are 1:1 mapped and always together
+ * from [ic_]node_alloc() to [ic_]node_free() so we are essentally
+ * using the ni references for the lsta as well despite it being
+ * two separate allocations.
+ */
+ lsta->ni = ni;
+ /* The back-pointer "drv_data" to net80211_node let's us get lsta. */
+ ni->ni_drv_data = lsta;
+
+ lvif = VAP_TO_LVIF(vap);
+ vif = LVIF_TO_VIF(lvif);
+ sta = LSTA_TO_STA(lsta);
+
+ IEEE80211_ADDR_COPY(sta->addr, mac);
+
+ /* TXQ */
+ for (tid = 0; tid < nitems(sta->txq); tid++) {
+ struct lkpi_txq *ltxq;
+
+ /* We are not limiting ourselves to hw.queues here. */
+ ltxq = malloc(sizeof(*ltxq) + hw->txq_data_size,
+ M_LKPI80211, M_NOWAIT | M_ZERO);
+ if (ltxq == NULL)
+ goto cleanup;
+ /* iwlwifi//mvm/sta.c::tid_to_mac80211_ac[] */
+ if (tid == IEEE80211_NUM_TIDS) {
+ if (!ieee80211_hw_check(hw, STA_MMPDU_TXQ)) {
+ free(ltxq, M_LKPI80211);
+ continue;
+ }
+ IMPROVE("AP/if we support non-STA here too");
+ ltxq->txq.ac = IEEE80211_AC_VO;
+ } else {
+ ltxq->txq.ac = ieee80211e_up_to_ac[tid & 7];
+ }
+ ltxq->seen_dequeue = false;
+ ltxq->stopped = false;
+ ltxq->txq.vif = vif;
+ ltxq->txq.tid = tid;
+ ltxq->txq.sta = sta;
+ TAILQ_ELEM_INIT(ltxq, txq_entry);
+ skb_queue_head_init(&ltxq->skbq);
+ LKPI_80211_LTXQ_LOCK_INIT(ltxq);
+ sta->txq[tid] = &ltxq->txq;
+ }
+
+ /* Deflink information. */
+ for (band = 0; band < NUM_NL80211_BANDS; band++) {
+ struct ieee80211_supported_band *supband;
+
+ supband = hw->wiphy->bands[band];
+ if (supband == NULL)
+ continue;
+
+ for (i = 0; i < supband->n_bitrates; i++) {
+ switch (band) {
+ case NL80211_BAND_2GHZ:
+ switch (supband->bitrates[i].bitrate) {
+ case 240: /* 11g only */
+ case 120: /* 11g only */
+ case 110:
+ case 60: /* 11g only */
+ case 55:
+ case 20:
+ case 10:
+ sta->deflink.supp_rates[band] |= BIT(i);
+ break;
+ }
+ break;
+ case NL80211_BAND_5GHZ:
+ switch (supband->bitrates[i].bitrate) {
+ case 240:
+ case 120:
+ case 60:
+ sta->deflink.supp_rates[band] |= BIT(i);
+ break;
+ }
+ break;
+ }
+ }
+ }
+
+ sta->deflink.smps_mode = IEEE80211_SMPS_OFF;
+ sta->deflink.bandwidth = IEEE80211_STA_RX_BW_20;
+ sta->deflink.rx_nss = 1;
+
+ lkpi_sta_sync_from_ni(hw, vif, sta, ni, false);
+
+ IMPROVE("he, eht, bw_320, ... smps_mode, ..");
+
+ /* Link configuration. */
+ IEEE80211_ADDR_COPY(sta->deflink.addr, sta->addr);
+ sta->link[0] = &sta->deflink;
+ for (i = 1; i < nitems(sta->link); i++) {
+ IMPROVE("more links; only link[0] = deflink currently.");
+ }
+ IMPROVE("11be");
+ sta->mlo = false;
+
+ /* Deferred TX path. */
+ LKPI_80211_LSTA_TXQ_LOCK_INIT(lsta);
+ TASK_INIT(&lsta->txq_task, 0, lkpi_80211_txq_task, lsta);
+ mbufq_init(&lsta->txq, 32 * NAPI_POLL_WEIGHT);
+ lsta->txq_ready = true;
+
+ return (lsta);
+
+cleanup:
+ for (; tid >= 0; tid--) {
+ struct lkpi_txq *ltxq;
+
+ ltxq = TXQ_TO_LTXQ(sta->txq[tid]);
+ LKPI_80211_LTXQ_LOCK_DESTROY(ltxq);
+ free(sta->txq[tid], M_LKPI80211);
+ }
+ free(lsta, M_LKPI80211);
+ return (NULL);
+}
+
+static void
+lkpi_lsta_free(struct lkpi_sta *lsta, struct ieee80211_node *ni)
+{
+ struct mbuf *m;
+
+ if (lsta->added_to_drv)
+ panic("%s: Trying to free an lsta still known to firmware: "
+ "lsta %p ni %p added_to_drv %d\n",
+ __func__, lsta, ni, lsta->added_to_drv);
+
+ /* XXX-BZ free resources, ... */
+ IMPROVE();
+
+ /* Drain sta->txq[] */
+
+ LKPI_80211_LSTA_TXQ_LOCK(lsta);
+ lsta->txq_ready = false;
+ LKPI_80211_LSTA_TXQ_UNLOCK(lsta);
+
+ /* Drain taskq, won't be restarted until added_to_drv is set again. */
+ while (taskqueue_cancel(taskqueue_thread, &lsta->txq_task, NULL) != 0)
+ taskqueue_drain(taskqueue_thread, &lsta->txq_task);
+
+ /* Flush mbufq (make sure to release ni refs!). */
+ m = mbufq_dequeue(&lsta->txq);
+ while (m != NULL) {
+ struct ieee80211_node *nim;
+
+ nim = (struct ieee80211_node *)m->m_pkthdr.rcvif;
+ if (nim != NULL)
+ ieee80211_free_node(nim);
+ m_freem(m);
+ m = mbufq_dequeue(&lsta->txq);
+ }
+ KASSERT(mbufq_empty(&lsta->txq), ("%s: lsta %p has txq len %d != 0\n",
+ __func__, lsta, mbufq_len(&lsta->txq)));
+ LKPI_80211_LSTA_TXQ_LOCK_DESTROY(lsta);
+
+ /* Remove lsta from vif; that is done by the state machine. Should assert it? */
+
+ IMPROVE("Make sure everything is cleaned up.");
+
+ /* Free lsta. */
+ lsta->ni = NULL;
+ ni->ni_drv_data = NULL;
+ free(lsta, M_LKPI80211);
+}
+
+
+static enum nl80211_band
+lkpi_net80211_chan_to_nl80211_band(struct ieee80211_channel *c)
+{
+
+ if (IEEE80211_IS_CHAN_2GHZ(c))
+ return (NL80211_BAND_2GHZ);
+ else if (IEEE80211_IS_CHAN_5GHZ(c))
+ return (NL80211_BAND_5GHZ);
+#ifdef __notyet__
+ else if ()
+ return (NL80211_BAND_6GHZ);
+ else if ()
+ return (NL80211_BAND_60GHZ);
+ else if (IEEE80211_IS_CHAN_GSM(c))
+ return (NL80211_BAND_XXX);
+#endif
+ else
+ panic("%s: unsupported band. c %p flags %#x\n",
+ __func__, c, c->ic_flags);
+}
+
+static uint32_t
+lkpi_nl80211_band_to_net80211_band(enum nl80211_band band)
+{
+
+ /* XXX-BZ this is just silly; net80211 is too convoluted. */
+ /* IEEE80211_CHAN_A / _G / .. doesn't really work either. */
+ switch (band) {
+ case NL80211_BAND_2GHZ:
+ return (IEEE80211_CHAN_2GHZ);
+ break;
+ case NL80211_BAND_5GHZ:
+ return (IEEE80211_CHAN_5GHZ);
+ break;
+ case NL80211_BAND_60GHZ:
+ break;
+ case NL80211_BAND_6GHZ:
+ break;
+ default:
+ panic("%s: unsupported band %u\n", __func__, band);
+ break;
+ }
+
+ IMPROVE();
+ return (0x00);
+}
+
+#ifdef LINUXKPI_DEBUG_80211
+static const char *
+lkpi_nl80211_band_name(enum nl80211_band band)
+{
+ switch (band) {
+ case NL80211_BAND_2GHZ:
+ return "2Ghz";
+ break;
+ case NL80211_BAND_5GHZ:
+ return "5Ghz";
+ break;
+ case NL80211_BAND_60GHZ:
+ return "60Ghz";
+ break;
+ case NL80211_BAND_6GHZ:
+ return "6Ghz";
+ break;
+ default:
+ panic("%s: unsupported band %u\n", __func__, band);
+ break;
+ }
+}
+#endif
+
+#if 0
+static enum ieee80211_ac_numbers
+lkpi_ac_net_to_l80211(int ac)
+{
+
+ switch (ac) {
+ case WME_AC_VO:
+ return (IEEE80211_AC_VO);
+ case WME_AC_VI:
+ return (IEEE80211_AC_VI);
+ case WME_AC_BE:
+ return (IEEE80211_AC_BE);
+ case WME_AC_BK:
+ return (IEEE80211_AC_BK);
+ default:
+ printf("%s: invalid WME_AC_* input: ac = %d\n", __func__, ac);
+ return (IEEE80211_AC_BE);
+ }
+}
+#endif
+
+static enum nl80211_iftype
+lkpi_opmode_to_vif_type(enum ieee80211_opmode opmode)
+{
+
+ switch (opmode) {
+ case IEEE80211_M_IBSS:
+ return (NL80211_IFTYPE_ADHOC);
+ break;
+ case IEEE80211_M_STA:
+ return (NL80211_IFTYPE_STATION);
+ break;
+ case IEEE80211_M_WDS:
+ return (NL80211_IFTYPE_WDS);
+ break;
+ case IEEE80211_M_HOSTAP:
+ return (NL80211_IFTYPE_AP);
+ break;
+ case IEEE80211_M_MONITOR:
+ return (NL80211_IFTYPE_MONITOR);
+ break;
+ case IEEE80211_M_MBSS:
+ return (NL80211_IFTYPE_MESH_POINT);
+ break;
+ case IEEE80211_M_AHDEMO:
+ /* FALLTHROUGH */
+ default:
+ printf("ERROR: %s: unsupported opmode %d\n", __func__, opmode);
+ /* FALLTHROUGH */
+ }
+ return (NL80211_IFTYPE_UNSPECIFIED);
+}
+
+#ifdef LKPI_80211_HW_CRYPTO
+static const char *
+lkpi_cipher_suite_to_name(uint32_t wlan_cipher_suite)
+{
+ switch (wlan_cipher_suite) {
+ case WLAN_CIPHER_SUITE_WEP40:
+ return ("WEP40");
+ case WLAN_CIPHER_SUITE_WEP104:
+ return ("WEP104");
+ case WLAN_CIPHER_SUITE_TKIP:
+ return ("TKIP");
+ case WLAN_CIPHER_SUITE_CCMP:
+ return ("CCMP");
+ case WLAN_CIPHER_SUITE_CCMP_256:
+ return ("CCMP_256");
+ case WLAN_CIPHER_SUITE_GCMP:
+ return ("GCMP");
+ case WLAN_CIPHER_SUITE_GCMP_256:
+ return ("GCMP_256");
+ case WLAN_CIPHER_SUITE_AES_CMAC:
+ return ("AES_CMAC");
+ case WLAN_CIPHER_SUITE_BIP_CMAC_256:
+ return ("BIP_CMAC_256");
+ case WLAN_CIPHER_SUITE_BIP_GMAC_128:
+ return ("BIP_GMAC_128");
+ case WLAN_CIPHER_SUITE_BIP_GMAC_256:
+ return ("BIP_GMAC_256");
+ default:
+ return ("??");
+ }
+}
+
+static uint32_t
+lkpi_l80211_to_net80211_cyphers(struct ieee80211com *ic,
+ uint32_t wlan_cipher_suite)
+{
+ switch (wlan_cipher_suite) {
+ case WLAN_CIPHER_SUITE_WEP40:
+ return (IEEE80211_CRYPTO_WEP);
+ case WLAN_CIPHER_SUITE_WEP104:
+ return (IEEE80211_CRYPTO_WEP);
+ case WLAN_CIPHER_SUITE_TKIP:
+ return (IEEE80211_CRYPTO_TKIP);
+ case WLAN_CIPHER_SUITE_CCMP:
+ return (IEEE80211_CRYPTO_AES_CCM);
+ case WLAN_CIPHER_SUITE_CCMP_256:
+ return (IEEE80211_CRYPTO_AES_CCM_256);
+ case WLAN_CIPHER_SUITE_GCMP:
+ return (IEEE80211_CRYPTO_AES_GCM_128);
+ case WLAN_CIPHER_SUITE_GCMP_256:
+ return (IEEE80211_CRYPTO_AES_GCM_256);
+ case WLAN_CIPHER_SUITE_AES_CMAC:
+ return (IEEE80211_CRYPTO_BIP_CMAC_128);
+ case WLAN_CIPHER_SUITE_BIP_CMAC_256:
+ return (IEEE80211_CRYPTO_BIP_CMAC_256);
+ case WLAN_CIPHER_SUITE_BIP_GMAC_128:
+ return (IEEE80211_CRYPTO_BIP_GMAC_128);
+ case WLAN_CIPHER_SUITE_BIP_GMAC_256:
+ return (IEEE80211_CRYPTO_BIP_GMAC_256);
+ default:
+ ic_printf(ic, "%s: unknown WLAN Cipher Suite %#08x | %u (%s)\n",
+ __func__,
+ wlan_cipher_suite >> 8, wlan_cipher_suite & 0xff,
+ lkpi_cipher_suite_to_name(wlan_cipher_suite));
+ return (0);
+ }
+}
+
+static uint32_t
+lkpi_net80211_to_l80211_cipher_suite(uint32_t cipher, uint8_t keylen)
+{
+
+ switch (cipher) {
+ case IEEE80211_CIPHER_WEP:
+ if (keylen == (40/NBBY))
+ return (WLAN_CIPHER_SUITE_WEP40);
+ else if (keylen == (104/NBBY))
+ return (WLAN_CIPHER_SUITE_WEP104);
+ else {
+ printf("%s: WEP with unsupported keylen %d\n",
+ __func__, keylen * NBBY);
+ return (0);
+ }
+ break;
+ case IEEE80211_CIPHER_TKIP:
+ return (WLAN_CIPHER_SUITE_TKIP);
+ case IEEE80211_CIPHER_AES_CCM:
+ return (WLAN_CIPHER_SUITE_CCMP);
+ case IEEE80211_CIPHER_AES_CCM_256:
+ return (WLAN_CIPHER_SUITE_CCMP_256);
+ case IEEE80211_CIPHER_AES_GCM_128:
+ return (WLAN_CIPHER_SUITE_GCMP);
+ case IEEE80211_CIPHER_AES_GCM_256:
+ return (WLAN_CIPHER_SUITE_GCMP_256);
+ case IEEE80211_CIPHER_BIP_CMAC_128:
+ return (WLAN_CIPHER_SUITE_AES_CMAC);
+ case IEEE80211_CIPHER_BIP_CMAC_256:
+ return (WLAN_CIPHER_SUITE_BIP_CMAC_256);
+ case IEEE80211_CIPHER_BIP_GMAC_128:
+ return (WLAN_CIPHER_SUITE_BIP_GMAC_128);
+ case IEEE80211_CIPHER_BIP_GMAC_256:
+ return (WLAN_CIPHER_SUITE_BIP_GMAC_256);
+
+ case IEEE80211_CIPHER_AES_OCB:
+ case IEEE80211_CIPHER_TKIPMIC:
+ /*
+ * TKIP w/ hw MIC support
+ * (gone wrong; should really be a crypto flag in net80211).
+ */
+ case IEEE80211_CIPHER_CKIP:
+ case IEEE80211_CIPHER_NONE:
+ printf("%s: unsupported cipher %#010x\n", __func__, cipher);
+ break;
+ default:
+ printf("%s: unknown cipher %#010x\n", __func__, cipher);
+ };
+ return (0);
+}
+#endif
+
+#ifdef __notyet__
+static enum ieee80211_sta_state
+lkpi_net80211_state_to_sta_state(enum ieee80211_state state)
+{
+
+ /*
+ * XXX-BZ The net80211 states are "try to ..", the lkpi8011 states are
+ * "done". Also ASSOC/AUTHORIZED are both "RUN" then?
+ */
+ switch (state) {
+ case IEEE80211_S_INIT:
+ return (IEEE80211_STA_NOTEXIST);
+ case IEEE80211_S_SCAN:
+ return (IEEE80211_STA_NONE);
+ case IEEE80211_S_AUTH:
+ return (IEEE80211_STA_AUTH);
+ case IEEE80211_S_ASSOC:
+ return (IEEE80211_STA_ASSOC);
+ case IEEE80211_S_RUN:
+ return (IEEE80211_STA_AUTHORIZED);
+ case IEEE80211_S_CAC:
+ case IEEE80211_S_CSA:
+ case IEEE80211_S_SLEEP:
+ default:
+ UNIMPLEMENTED;
+ };
+
+ return (IEEE80211_STA_NOTEXIST);
+}
+#endif
+
+static struct linuxkpi_ieee80211_channel *
+lkpi_find_lkpi80211_chan(struct lkpi_hw *lhw,
+ struct ieee80211_channel *c)
+{
+ struct ieee80211_hw *hw;
+ struct linuxkpi_ieee80211_channel *channels;
+ enum nl80211_band band;
+ int i, nchans;
+
+ hw = LHW_TO_HW(lhw);
+ band = lkpi_net80211_chan_to_nl80211_band(c);
+ if (hw->wiphy->bands[band] == NULL)
+ return (NULL);
+
+ nchans = hw->wiphy->bands[band]->n_channels;
+ if (nchans <= 0)
+ return (NULL);
+
+ channels = hw->wiphy->bands[band]->channels;
+ for (i = 0; i < nchans; i++) {
+ if (channels[i].center_freq == c->ic_freq)
+ return (&channels[i]);
+ }
+
+ return (NULL);
+}
+
+#if 0
+static struct linuxkpi_ieee80211_channel *
+lkpi_get_lkpi80211_chan(struct ieee80211com *ic, struct ieee80211_node *ni)
+{
+ struct linuxkpi_ieee80211_channel *chan;
+ struct ieee80211_channel *c;
+ struct lkpi_hw *lhw;
+
+ chan = NULL;
+ if (ni != NULL && ni->ni_chan != IEEE80211_CHAN_ANYC)
+ c = ni->ni_chan;
+ else if (ic->ic_bsschan != IEEE80211_CHAN_ANYC)
+ c = ic->ic_bsschan;
+ else if (ic->ic_curchan != IEEE80211_CHAN_ANYC)
+ c = ic->ic_curchan;
+ else
+ c = NULL;
+
+ if (c != NULL && c != IEEE80211_CHAN_ANYC) {
+ lhw = ic->ic_softc;
+ chan = lkpi_find_lkpi80211_chan(lhw, c);
+ }
+
+ return (chan);
+}
+#endif
+
+struct linuxkpi_ieee80211_channel *
+linuxkpi_ieee80211_get_channel(struct wiphy *wiphy, uint32_t freq)
+{
+ enum nl80211_band band;
+
+ for (band = 0; band < NUM_NL80211_BANDS; band++) {
+ struct ieee80211_supported_band *supband;
+ struct linuxkpi_ieee80211_channel *channels;
+ int i;
+
+ supband = wiphy->bands[band];
+ if (supband == NULL || supband->n_channels == 0)
+ continue;
+
+ channels = supband->channels;
+ for (i = 0; i < supband->n_channels; i++) {
+ if (channels[i].center_freq == freq)
+ return (&channels[i]);
+ }
+ }
+
+ return (NULL);
+}
+
+#ifdef LKPI_80211_HW_CRYPTO
+static int
+lkpi_sta_del_keys(struct ieee80211_hw *hw, struct ieee80211_vif *vif,
+ struct lkpi_sta *lsta)
+{
+ int error;
+
+ if (!lkpi_hwcrypto)
+ return (0);
+
+ lockdep_assert_wiphy(hw->wiphy);
+ ieee80211_ref_node(lsta->ni);
+
+ error = 0;
+ for (ieee80211_keyix keyix = 0; keyix < nitems(lsta->kc); keyix++) {
+ struct ieee80211_key_conf *kc;
+ int err;
+
+ if (lsta->kc[keyix] == NULL)
+ continue;
+ kc = lsta->kc[keyix];
+
+#ifdef LINUXKPI_DEBUG_80211
+ if (linuxkpi_debug_80211 & D80211_TRACE_HW_CRYPTO)
+ ic_printf(lsta->ni->ni_ic, "%d %lu %s: running set_key cmd %d(%s) for "
+ "sta %6D: keyidx %u hw_key_idx %u flags %b\n",
+ curthread->td_tid, jiffies, __func__,
+ DISABLE_KEY, "DISABLE", lsta->sta.addr, ":",
+ kc->keyidx, kc->hw_key_idx, kc->flags, IEEE80211_KEY_FLAG_BITS);
+#endif
+
+ err = lkpi_80211_mo_set_key(hw, DISABLE_KEY, vif,
+ LSTA_TO_STA(lsta), kc);
+ if (err != 0) {
+ ic_printf(lsta->ni->ni_ic, "%d %lu %s: set_key cmd %d(%s) for "
+ "sta %6D failed: %d\n", curthread->td_tid, jiffies, __func__,
+ DISABLE_KEY, "DISABLE", lsta->sta.addr, ":", err);
+ error++;
+
+ /*
+ * If we free the key here we will never be able to get it
+ * removed from the driver/fw which will likely make us
+ * crash (firmware).
+ */
+ continue;
+ }
+#ifdef LINUXKPI_DEBUG_80211
+ if (linuxkpi_debug_80211 & D80211_TRACE_HW_CRYPTO)
+ ic_printf(lsta->ni->ni_ic, "%d %lu %s: set_key cmd %d(%s) for "
+ "sta %6D succeeded: keyidx %u hw_key_idx %u flags %b\n",
+ curthread->td_tid, jiffies, __func__,
+ DISABLE_KEY, "DISABLE", lsta->sta.addr, ":",
+ kc->keyidx, kc->hw_key_idx, kc->flags, IEEE80211_KEY_FLAG_BITS);
+#endif
+
+ lsta->kc[keyix] = NULL;
+ free(kc, M_LKPI80211);
+ }
+ ieee80211_free_node(lsta->ni);
+ return (error);
+}
+
+/* XXX-BZ one day we should replace this iterating over VIFs, or node list? */
+/* See also lkpi_sta_del_keys() these days. */
+static int
+lkpi_iv_key_delete(struct ieee80211vap *vap, const struct ieee80211_key *k)
+{
+ struct ieee80211com *ic;
+ struct lkpi_hw *lhw;
+ struct ieee80211_hw *hw;
+ struct lkpi_vif *lvif;
+ struct lkpi_sta *lsta;
+ struct ieee80211_vif *vif;
+ struct ieee80211_sta *sta;
+ struct ieee80211_node *ni;
+ struct ieee80211_key_conf *kc;
+ int error;
+
+ ic = vap->iv_ic;
+ lhw = ic->ic_softc;
+ hw = LHW_TO_HW(lhw);
+ lvif = VAP_TO_LVIF(vap);
+ vif = LVIF_TO_VIF(lvif);
+
+ /*
+ * Make sure we do not make it here without going through
+ * lkpi_iv_key_update_begin() first.
+ */
+ lockdep_assert_wiphy(hw->wiphy);
+
+ /*
+ * While we are assoc we may still send packets. We cannot delete the
+ * keys as otherwise packets could go out unencrypted. Some firmware
+ * does not like this and will fire an assert.
+ * net80211 needs to drive this better but given we want the disassoc
+ * frame out and have to unlock we are open to a race currently.
+ * This check should prevent problems.
+ * How to test: run 800Mbit/s UDP traffic and during that restart your
+ * supplicant. You want to survive that.
+ */
+ if (vif->cfg.assoc) {
+ if (linuxkpi_debug_80211 & D80211_TRACE_HW_CRYPTO)
+ ic_printf(ic, "%d %lu %s: vif still assoc; not deleting keys\n",
+ curthread->td_tid, jiffies, __func__);
+ return (0);
+ }
+
+ if (IEEE80211_KEY_UNDEFINED(k)) {
+ ic_printf(ic, "%s: vap %p key %p is undefined: %p %u\n",
+ __func__, vap, k, k->wk_cipher, k->wk_keyix);
+ return (0);
+ }
+
+ if (vap->iv_bss == NULL) {
+ ic_printf(ic, "%s: iv_bss %p for vap %p is NULL\n",
+ __func__, vap->iv_bss, vap);
+ return (0);
+ }
+
+ ni = ieee80211_ref_node(vap->iv_bss);
+ lsta = ni->ni_drv_data;
+ if (lsta == NULL) {
+ ic_printf(ic, "%s: ni %p (%6D) with lsta NULL\n",
+ __func__, ni, ni->ni_bssid, ":");
+ ieee80211_free_node(ni);
+ return (0);
+ }
+ sta = LSTA_TO_STA(lsta);
+
+ if (lsta->kc[k->wk_keyix] == NULL) {
+#ifdef LINUXKPI_DEBUG_80211
+ if (linuxkpi_debug_80211 & D80211_TRACE_HW_CRYPTO)
+ ic_printf(ic, "%d %lu %s: sta %6D and no key information, "
+ "keyidx %u wk_macaddr %6D; returning success\n",
+ curthread->td_tid, jiffies, __func__, sta->addr, ":",
+ k->wk_keyix, k->wk_macaddr, ":");
+#endif
+ ieee80211_free_node(ni);
+ return (1);
+ }
+ kc = lsta->kc[k->wk_keyix];
+
+#ifdef LINUXKPI_DEBUG_80211
+ if (linuxkpi_debug_80211 & D80211_TRACE_HW_CRYPTO)
+ ic_printf(ic, "%d %lu %s: running set_key cmd %d(%s) for sta %6D: "
+ "keyidx %u hw_key_idx %u flags %b\n",
+ curthread->td_tid, jiffies, __func__,
+ DISABLE_KEY, "DISABLE", sta->addr, ":",
+ kc->keyidx, kc->hw_key_idx, kc->flags, IEEE80211_KEY_FLAG_BITS);
+#endif
+
+ error = lkpi_80211_mo_set_key(hw, DISABLE_KEY, vif, sta, kc);
+ if (error != 0) {
+ ic_printf(ic, "%d %lu %s: set_key cmd %d(%s) for sta %6D failed: %d\n",
+ curthread->td_tid, jiffies, __func__,
+ DISABLE_KEY, "DISABLE", sta->addr, ":", error);
+ error = 0;
+ goto out;
+ }
+
+#ifdef LINUXKPI_DEBUG_80211
+ if (linuxkpi_debug_80211 & D80211_TRACE_HW_CRYPTO)
+ ic_printf(ic, "%d %lu %s: set_key cmd %d(%s) for sta %6D succeeded: "
+ "keyidx %u hw_key_idx %u flags %b\n",
+ curthread->td_tid, jiffies, __func__,
+ DISABLE_KEY, "DISABLE", sta->addr, ":",
+ kc->keyidx, kc->hw_key_idx, kc->flags, IEEE80211_KEY_FLAG_BITS);
+#endif
+ lsta->kc[k->wk_keyix] = NULL;
+ free(kc, M_LKPI80211);
+ error = 1;
+out:
+ ieee80211_free_node(ni);
+ return (error);
+}
+
+static int
+lkpi_iv_key_set(struct ieee80211vap *vap, const struct ieee80211_key *k)
+{
+ struct ieee80211com *ic;
+ struct lkpi_hw *lhw;
+ struct ieee80211_hw *hw;
+ struct lkpi_vif *lvif;
+ struct lkpi_sta *lsta;
+ struct ieee80211_vif *vif;
+ struct ieee80211_sta *sta;
+ struct ieee80211_node *ni;
+ struct ieee80211_key_conf *kc;
+ uint32_t lcipher;
+ uint16_t exp_flags;
+ uint8_t keylen;
+ int error;
+
+ ic = vap->iv_ic;
+ lhw = ic->ic_softc;
+ hw = LHW_TO_HW(lhw);
+
+ /*
+ * Make sure we do not make it here without going through
+ * lkpi_iv_key_update_begin() first.
+ */
+ lockdep_assert_wiphy(hw->wiphy);
+
+ if (IEEE80211_KEY_UNDEFINED(k)) {
+ ic_printf(ic, "%s: vap %p key %p is undefined: %p %u\n",
+ __func__, vap, k, k->wk_cipher, k->wk_keyix);
+ return (0);
+ }
+
+ if (vap->iv_bss == NULL) {
+ ic_printf(ic, "%s: iv_bss %p for vap %p is NULL\n",
+ __func__, vap->iv_bss, vap);
+ return (0);
+ }
+ ni = ieee80211_ref_node(vap->iv_bss);
+ lsta = ni->ni_drv_data;
+ if (lsta == NULL) {
+ ic_printf(ic, "%s: ni %p (%6D) with lsta NULL\n",
+ __func__, ni, ni->ni_bssid, ":");
+ ieee80211_free_node(ni);
+ return (0);
+ }
+ sta = LSTA_TO_STA(lsta);
+
+ keylen = k->wk_keylen;
+ lcipher = lkpi_net80211_to_l80211_cipher_suite(
+ k->wk_cipher->ic_cipher, k->wk_keylen);
+ switch (lcipher) {
+ case WLAN_CIPHER_SUITE_TKIP:
+ keylen += 2 * k->wk_cipher->ic_miclen;
+ break;
+ case WLAN_CIPHER_SUITE_CCMP:
+ case WLAN_CIPHER_SUITE_GCMP:
+ break;
+ default:
+ ic_printf(ic, "%s: CIPHER SUITE %#x (%s) not supported\n",
+ __func__, lcipher, lkpi_cipher_suite_to_name(lcipher));
+ IMPROVE();
+ ieee80211_free_node(ni);
+ return (0);
+ }
+
+ if (lsta->kc[k->wk_keyix] != NULL) {
+ IMPROVE("Still in firmware? Del first. Can we assert this cannot happen?");
+ ic_printf(ic, "%s: sta %6D found with key information\n",
+ __func__, sta->addr, ":");
+ kc = lsta->kc[k->wk_keyix];
+ lsta->kc[k->wk_keyix] = NULL;
+ free(kc, M_LKPI80211);
+ kc = NULL; /* safeguard */
+ }
+
+ kc = malloc(sizeof(*kc) + keylen, M_LKPI80211, M_WAITOK | M_ZERO);
+ kc->_k = k; /* Save the pointer to net80211. */
+ kc->cipher = lcipher;
+ kc->keyidx = k->wk_keyix;
+#if 0
+ kc->hw_key_idx = /* set by hw and needs to be passed for TX */;
+#endif
+ atomic64_set(&kc->tx_pn, k->wk_keytsc);
+ kc->keylen = k->wk_keylen;
+ memcpy(kc->key, k->wk_key, k->wk_keylen);
+
+ if (k->wk_flags & (IEEE80211_KEY_XMIT | IEEE80211_KEY_RECV))
+ kc->flags |= IEEE80211_KEY_FLAG_PAIRWISE;
+ if (k->wk_flags & IEEE80211_KEY_GROUP)
+ kc->flags &= ~IEEE80211_KEY_FLAG_PAIRWISE;
+
+ kc->iv_len = k->wk_cipher->ic_header;
+ kc->icv_len = k->wk_cipher->ic_trailer;
+
+ switch (kc->cipher) {
+ case WLAN_CIPHER_SUITE_TKIP:
+ memcpy(kc->key + NL80211_TKIP_DATA_OFFSET_TX_MIC_KEY, k->wk_txmic, k->wk_cipher->ic_miclen);
+ memcpy(kc->key + NL80211_TKIP_DATA_OFFSET_RX_MIC_KEY, k->wk_rxmic, k->wk_cipher->ic_miclen);
+ break;
+ case WLAN_CIPHER_SUITE_CCMP:
+ case WLAN_CIPHER_SUITE_GCMP:
+ break;
+ default:
+ /* currently UNREACH */
+ IMPROVE();
+ break;
+ };
+ lsta->kc[k->wk_keyix] = kc;
+
+#ifdef LINUXKPI_DEBUG_80211
+ if (linuxkpi_debug_80211 & D80211_TRACE_HW_CRYPTO)
+ ic_printf(ic, "%d %lu %s: running set_key cmd %d(%s) for sta %6D: "
+ "kc %p keyidx %u hw_key_idx %u keylen %u flags %b\n",
+ curthread->td_tid, jiffies, __func__,
+ SET_KEY, "SET", sta->addr, ":", kc, kc->keyidx, kc->hw_key_idx,
+ kc->keylen, kc->flags, IEEE80211_KEY_FLAG_BITS);
+#endif
+
+ lvif = VAP_TO_LVIF(vap);
+ vif = LVIF_TO_VIF(lvif);
+ error = lkpi_80211_mo_set_key(hw, SET_KEY, vif, sta, kc);
+ if (error != 0) {
+ ic_printf(ic, "%d %lu %s: set_key cmd %d(%s) for sta %6D failed: %d\n",
+ curthread->td_tid, jiffies, __func__,
+ SET_KEY, "SET", sta->addr, ":", error);
+ lsta->kc[k->wk_keyix] = NULL;
+ free(kc, M_LKPI80211);
+ ieee80211_free_node(ni);
+ return (0);
+ }
+
+#ifdef LINUXKPI_DEBUG_80211
+ if (linuxkpi_debug_80211 & D80211_TRACE_HW_CRYPTO)
+ ic_printf(ic, "%d %lu %s: set_key cmd %d(%s) for sta %6D succeeded: "
+ "kc %p keyidx %u hw_key_idx %u flags %b\n",
+ curthread->td_tid, jiffies, __func__,
+ SET_KEY, "SET", sta->addr, ":",
+ kc, kc->keyidx, kc->hw_key_idx, kc->flags, IEEE80211_KEY_FLAG_BITS);
+#endif
+
+ exp_flags = 0;
+ switch (kc->cipher) {
+ case WLAN_CIPHER_SUITE_TKIP:
+ exp_flags = (IEEE80211_KEY_FLAG_PAIRWISE |
+ IEEE80211_KEY_FLAG_PUT_IV_SPACE |
+ IEEE80211_KEY_FLAG_GENERATE_MMIC |
+ IEEE80211_KEY_FLAG_PUT_MIC_SPACE);
+#define TKIP_INVAL_COMBINATION \
+ (IEEE80211_KEY_FLAG_PUT_MIC_SPACE|IEEE80211_KEY_FLAG_GENERATE_MMIC)
+ if ((kc->flags & TKIP_INVAL_COMBINATION) == TKIP_INVAL_COMBINATION) {
+ ic_printf(ic, "%s: SET_KEY for %s returned invalid "
+ "combination %b\n", __func__,
+ lkpi_cipher_suite_to_name(kc->cipher),
+ kc->flags, IEEE80211_KEY_FLAG_BITS);
+ }
+#undef TKIP_INVAL_COMBINATION
+#ifdef __notyet__
+ /* Do flags surgery; special see linuxkpi_ieee80211_ifattach(). */
+ if ((kc->flags & IEEE80211_KEY_FLAG_GENERATE_MMIC) != 0) {
+ k->wk_flags &= ~(IEEE80211_KEY_NOMICMGT|IEEE80211_KEY_NOMIC);
+ k->wk_flags |= IEEE80211_KEY_SWMIC;
+ ic->ic_cryptocaps &= ~IEEE80211_CRYPTO_TKIPMIC
+ }
+#endif
+ break;
+ case WLAN_CIPHER_SUITE_CCMP:
+ case WLAN_CIPHER_SUITE_GCMP:
+ exp_flags = (IEEE80211_KEY_FLAG_PAIRWISE |
+ IEEE80211_KEY_FLAG_PUT_IV_SPACE |
+ IEEE80211_KEY_FLAG_GENERATE_IV |
+ IEEE80211_KEY_FLAG_GENERATE_IV_MGMT | /* Only needs IV geeration for MGMT frames. */
+ IEEE80211_KEY_FLAG_SW_MGMT_TX); /* MFP in software */
+ break;
+ }
+ if ((kc->flags & ~exp_flags) != 0)
+ ic_printf(ic, "%s: SET_KEY for %s returned unexpected key flags: "
+ " %#06x & ~%#06x = %b\n", __func__,
+ lkpi_cipher_suite_to_name(kc->cipher), kc->flags, exp_flags,
+ (kc->flags & ~exp_flags), IEEE80211_KEY_FLAG_BITS);
+
+#ifdef __notyet__
+ /* Do flags surgery. */
+ if ((kc->flags & IEEE80211_KEY_FLAG_GENERATE_IV_MGMT) == 0)
+ k->wk_flags |= IEEE80211_KEY_NOIVMGT;
+ if ((kc->flags & IEEE80211_KEY_FLAG_GENERATE_IV) == 0)
+ k->wk_flags |= IEEE80211_KEY_NOIV;
+#endif
+
+ ieee80211_free_node(ni);
+ return (1);
+}
+
+static void
+lkpi_iv_key_update_begin(struct ieee80211vap *vap)
+{
+ struct ieee80211_node_table *nt;
+ struct ieee80211com *ic;
+ struct lkpi_hw *lhw;
+ struct ieee80211_hw *hw;
+ struct lkpi_vif *lvif;
+ struct ieee80211_node *ni;
+ bool icislocked, ntislocked;
+
+ ic = vap->iv_ic;
+ lhw = ic->ic_softc;
+ hw = LHW_TO_HW(lhw);
+ lvif = VAP_TO_LVIF(vap);
+ nt = &ic->ic_sta;
+
+ icislocked = IEEE80211_IS_LOCKED(ic);
+ ntislocked = IEEE80211_NODE_IS_LOCKED(nt);
+
+#ifdef LINUXKPI_DEBUG_80211
+ if (linuxkpi_debug_80211 & D80211_TRACE_HW_CRYPTO)
+ ic_printf(ic, "%d %lu %s: vap %p ic %p %slocked nt %p %slocked "
+ "lvif ic_unlocked %d nt_unlocked %d\n",
+ curthread->td_tid, jiffies, __func__, vap,
+ ic, icislocked ? "" : "un", nt, ntislocked ? "" : "un",
+ lvif->ic_unlocked, lvif->nt_unlocked);
+#endif
+
+ /*
+ * This is inconsistent net80211 locking to be fixed one day.
+ */
+ /* Try to make sure the node does not go away while possibly unlocked. */
+ ni = NULL;
+ if (icislocked || ntislocked) {
+ if (vap->iv_bss != NULL)
+ ni = ieee80211_ref_node(vap->iv_bss);
+ }
+
+ if (icislocked)
+ IEEE80211_UNLOCK(ic);
+ if (ntislocked)
+ IEEE80211_NODE_UNLOCK(nt);
+
+ wiphy_lock(hw->wiphy);
+
+ KASSERT(lvif->key_update_iv_bss == NULL, ("%s: key_update_iv_bss not NULL %p",
+ __func__, lvif->key_update_iv_bss));
+ lvif->key_update_iv_bss = ni;
+
+ /*
+ * ic/nt_unlocked could be a bool given we are under the lock and there
+ * must only be a single thread.
+ * In case anything in the future disturbs the order the refcnt will
+ * help us catching problems a lot easier.
+ */
+ if (icislocked)
+ refcount_acquire(&lvif->ic_unlocked);
+ if (ntislocked)
+ refcount_acquire(&lvif->nt_unlocked);
+
+ /*
+ * Stop the queues while doing key updates.
+ */
+ ieee80211_stop_queues(hw);
+}
+
+static void
+lkpi_iv_key_update_end(struct ieee80211vap *vap)
+{
+ struct ieee80211_node_table *nt;
+ struct ieee80211com *ic;
+ struct lkpi_hw *lhw;
+ struct ieee80211_hw *hw;
+ struct lkpi_vif *lvif;
+ bool icislocked, ntislocked;
+
+ ic = vap->iv_ic;
+ lhw = ic->ic_softc;
+ hw = LHW_TO_HW(lhw);
+ lvif = VAP_TO_LVIF(vap);
+ nt = &ic->ic_sta;
+
+ /*
+ * Re-enabled the queues after the key update.
+ */
+ lkpi_ieee80211_wake_queues_locked(hw);
+
+ icislocked = IEEE80211_IS_LOCKED(ic);
+ MPASS(!icislocked);
+ ntislocked = IEEE80211_NODE_IS_LOCKED(nt);
+ MPASS(!ntislocked);
+
+#ifdef LINUXKPI_DEBUG_80211
+ if (linuxkpi_debug_80211 & D80211_TRACE_HW_CRYPTO)
+ ic_printf(ic, "%d %lu %s: vap %p ic %p %slocked nt %p %slocked "
+ "lvif ic_unlocked %d nt_unlocked %d\n",
+ curthread->td_tid, jiffies, __func__, vap,
+ ic, icislocked ? "" : "un", nt, ntislocked ? "" : "un",
+ lvif->ic_unlocked, lvif->nt_unlocked);
+#endif
+
+ /*
+ * Check under lock; see comment in lkpi_iv_key_update_begin().
+ * In case the refcnt gets out of sync locking in net80211 will
+ * quickly barf as well (trying to unlock a lock not held).
+ */
+ icislocked = refcount_release_if_last(&lvif->ic_unlocked);
+ ntislocked = refcount_release_if_last(&lvif->nt_unlocked);
+
+ if (lvif->key_update_iv_bss != NULL) {
+ ieee80211_free_node(lvif->key_update_iv_bss);
+ lvif->key_update_iv_bss = NULL;
+ }
+
+ wiphy_unlock(hw->wiphy);
+
+ /*
+ * This is inconsistent net80211 locking to be fixed one day.
+ * ic before nt to avoid a LOR.
+ */
+ if (icislocked)
+ IEEE80211_LOCK(ic);
+ if (ntislocked)
+ IEEE80211_NODE_LOCK(nt);
+}
+#endif
+
+static void
+lkpi_cleanup_mcast_list_locked(struct lkpi_hw *lhw)
+{
+ struct list_head *le, *next;
+ struct netdev_hw_addr *addr;
+
+ if (lhw->mc_list.count != 0) {
+ list_for_each_safe(le, next, &lhw->mc_list.addr_list) {
+ addr = list_entry(le, struct netdev_hw_addr, addr_list);
+ list_del(le);
+ lhw->mc_list.count--;
+ free(addr, M_LKPI80211);
+ }
+ }
+ KASSERT(lhw->mc_list.count == 0, ("%s: mc_list %p count %d != 0\n",
+ __func__, &lhw->mc_list, lhw->mc_list.count));
+}
+
+static u_int
+lkpi_ic_update_mcast_copy(void *arg, struct sockaddr_dl *sdl, u_int cnt)
+{
+ struct netdev_hw_addr_list *mc_list;
+ struct netdev_hw_addr *addr;
+
+ KASSERT(arg != NULL && sdl != NULL, ("%s: arg %p sdl %p cnt %u\n",
+ __func__, arg, sdl, cnt));
+
+ mc_list = arg;
+ /* If it is on the list already skip it. */
+ netdev_hw_addr_list_for_each(addr, mc_list) {
+ if (!memcmp(addr->addr, LLADDR(sdl), sdl->sdl_alen))
+ return (0);
+ }
+
+ addr = malloc(sizeof(*addr), M_LKPI80211, M_NOWAIT | M_ZERO);
+ if (addr == NULL)
+ return (0);
+
+ INIT_LIST_HEAD(&addr->addr_list);
+ memcpy(addr->addr, LLADDR(sdl), sdl->sdl_alen);
+ /* XXX this should be a netdev function? */
+ list_add(&addr->addr_list, &mc_list->addr_list);
+ mc_list->count++;
+
+#ifdef LINUXKPI_DEBUG_80211
+ if (linuxkpi_debug_80211 & D80211_TRACE)
+ printf("%s:%d: mc_list count %d: added %6D\n",
+ __func__, __LINE__, mc_list->count, addr->addr, ":");
+#endif
+
+ return (1);
+}
+
+static void
+lkpi_update_mcast_filter(struct ieee80211com *ic)
+{
+ struct lkpi_hw *lhw;
+ struct ieee80211_hw *hw;
+ u64 mc;
+ unsigned int changed_flags, flags;
+ bool scanning;
+
+ lhw = ic->ic_softc;
+
+ if (lhw->ops->prepare_multicast == NULL ||
+ lhw->ops->configure_filter == NULL)
+ return;
+
+ LKPI_80211_LHW_SCAN_LOCK(lhw);
+ scanning = (lhw->scan_flags & LKPI_LHW_SCAN_RUNNING) != 0;
+ LKPI_80211_LHW_SCAN_UNLOCK(lhw);
+
+ LKPI_80211_LHW_MC_LOCK(lhw);
+
+ flags = 0;
+ if (scanning)
+ flags |= FIF_BCN_PRBRESP_PROMISC;
+ if (lhw->mc_all_multi)
+ flags |= FIF_ALLMULTI;
+
+ hw = LHW_TO_HW(lhw);
+ mc = lkpi_80211_mo_prepare_multicast(hw, &lhw->mc_list);
+
+ changed_flags = (lhw->mc_flags ^ flags) & FIF_FLAGS_MASK;
+ lkpi_80211_mo_configure_filter(hw, changed_flags, &flags, mc);
+ lhw->mc_flags = flags;
+
+#ifdef LINUXKPI_DEBUG_80211
+ if (linuxkpi_debug_80211 & D80211_TRACE)
+ printf("%s: changed_flags %#06x count %d mc_flags %#010x\n",
+ __func__, changed_flags, lhw->mc_list.count, lhw->mc_flags);
+#endif
+
+ LKPI_80211_LHW_MC_UNLOCK(lhw);
+}
+
+static enum ieee80211_bss_changed
+lkpi_update_dtim_tsf(struct ieee80211_vif *vif, struct ieee80211_node *ni,
+ struct ieee80211vap *vap, const char *_f, int _l)
+{
+ enum ieee80211_bss_changed bss_changed;
+
+ bss_changed = 0;
+
+#ifdef LINUXKPI_DEBUG_80211
+ if (linuxkpi_debug_80211 & D80211_TRACE)
+ printf("%s:%d [%s:%d] assoc %d aid %d beacon_int %u "
+ "dtim_period %u sync_dtim_count %u sync_tsf %ju "
+ "sync_device_ts %u bss_changed %#010jx\n",
+ __func__, __LINE__, _f, _l,
+ vif->cfg.assoc, vif->cfg.aid,
+ vif->bss_conf.beacon_int, vif->bss_conf.dtim_period,
+ vif->bss_conf.sync_dtim_count,
+ (uintmax_t)vif->bss_conf.sync_tsf,
+ vif->bss_conf.sync_device_ts,
+ (uintmax_t)bss_changed);
+#endif
+
+ if (vif->bss_conf.beacon_int != ni->ni_intval) {
+ vif->bss_conf.beacon_int = ni->ni_intval;
+ /* iwlwifi FW bug workaround; iwl_mvm_mac_sta_state. */
+ if (vif->bss_conf.beacon_int < 16)
+ vif->bss_conf.beacon_int = 16;
+ bss_changed |= BSS_CHANGED_BEACON_INT;
+ }
+
+ /*
+ * lkpi_iv_sta_recv_mgmt() will directly call into this function.
+ * iwlwifi(4) in iwl_mvm_bss_info_changed_station_common() will
+ * stop seesion protection the moment it sees
+ * BSS_CHANGED_BEACON_INFO (with the expectations that it was
+ * "a beacon from the associated AP"). It will also update
+ * the beacon filter in that case. This is the only place
+ * we set the BSS_CHANGED_BEACON_INFO on the non-teardown
+ * path so make sure we only do run this check once we are
+ * assoc. (*iv_recv_mgmt)() will be called before we enter
+ * here so the ni will be updates with information from the
+ * beacon via net80211::sta_recv_mgmt(). We also need to
+ * make sure we do not do it on every beacon we still may
+ * get so only do if something changed. vif->bss_conf.dtim_period
+ * should be 0 as we start up (we also reset it on teardown).
+ */
+ if (vif->cfg.assoc &&
+ vif->bss_conf.dtim_period != ni->ni_dtim_period &&
+ ni->ni_dtim_period > 0) {
+ vif->bss_conf.dtim_period = ni->ni_dtim_period;
+ bss_changed |= BSS_CHANGED_BEACON_INFO;
+ }
+
+ vif->bss_conf.sync_dtim_count = ni->ni_dtim_count;
+ vif->bss_conf.sync_tsf = le64toh(ni->ni_tstamp.tsf);
+ /* vif->bss_conf.sync_device_ts = set in linuxkpi_ieee80211_rx. */
+
+#ifdef LINUXKPI_DEBUG_80211
+ if (linuxkpi_debug_80211 & D80211_TRACE)
+ printf("%s:%d [%s:%d] assoc %d aid %d beacon_int %u "
+ "dtim_period %u sync_dtim_count %u sync_tsf %ju "
+ "sync_device_ts %u bss_changed %#010jx\n",
+ __func__, __LINE__, _f, _l,
+ vif->cfg.assoc, vif->cfg.aid,
+ vif->bss_conf.beacon_int, vif->bss_conf.dtim_period,
+ vif->bss_conf.sync_dtim_count,
+ (uintmax_t)vif->bss_conf.sync_tsf,
+ vif->bss_conf.sync_device_ts,
+ (uintmax_t)bss_changed);
+#endif
+
+ return (bss_changed);
+}
+
+static void
+lkpi_stop_hw_scan(struct lkpi_hw *lhw, struct ieee80211_vif *vif)
+{
+ struct ieee80211_hw *hw;
+ int error;
+ bool cancel;
+
+ TRACE_SCAN(lhw->ic, "scan_flags %b", lhw->scan_flags, LKPI_LHW_SCAN_BITS);
+
+ LKPI_80211_LHW_SCAN_LOCK(lhw);
+ cancel = (lhw->scan_flags & LKPI_LHW_SCAN_RUNNING) != 0;
+ LKPI_80211_LHW_SCAN_UNLOCK(lhw);
+ if (!cancel)
+ return;
+
+ hw = LHW_TO_HW(lhw);
+
+ IEEE80211_UNLOCK(lhw->ic);
+ wiphy_lock(hw->wiphy);
+ /* Need to cancel the scan. */
+ lkpi_80211_mo_cancel_hw_scan(hw, vif);
+ wiphy_unlock(hw->wiphy);
+
+ /* Need to make sure we see ieee80211_scan_completed. */
+ LKPI_80211_LHW_SCAN_LOCK(lhw);
+ if ((lhw->scan_flags & LKPI_LHW_SCAN_RUNNING) != 0)
+ error = msleep(lhw, &lhw->scan_mtx, 0, "lhwscanstop", hz/2);
+ cancel = (lhw->scan_flags & LKPI_LHW_SCAN_RUNNING) != 0;
+ LKPI_80211_LHW_SCAN_UNLOCK(lhw);
+
+ IEEE80211_LOCK(lhw->ic);
+
+ if (cancel)
+ ic_printf(lhw->ic, "%s: failed to cancel scan: %d (%p, %p)\n",
+ __func__, error, lhw, vif);
+}
+
+static void
+lkpi_hw_conf_idle(struct ieee80211_hw *hw, bool new)
+{
+ struct lkpi_hw *lhw;
+ int error;
+ bool old;
+
+ old = hw->conf.flags & IEEE80211_CONF_IDLE;
+ if (old == new)
+ return;
+
+ hw->conf.flags ^= IEEE80211_CONF_IDLE;
+ error = lkpi_80211_mo_config(hw, IEEE80211_CONF_CHANGE_IDLE);
+ if (error != 0 && error != EOPNOTSUPP) {
+ lhw = HW_TO_LHW(hw);
+ ic_printf(lhw->ic, "ERROR: %s: config %#0x returned %d\n",
+ __func__, IEEE80211_CONF_CHANGE_IDLE, error);
+ }
+}
+
+static enum ieee80211_bss_changed
+lkpi_disassoc(struct ieee80211_sta *sta, struct ieee80211_vif *vif,
+ struct lkpi_hw *lhw)
+{
+ enum ieee80211_bss_changed changed;
+ struct lkpi_vif *lvif;
+
+ changed = 0;
+ sta->aid = 0;
+ if (vif->cfg.assoc) {
+
+ vif->cfg.assoc = false;
+ vif->cfg.aid = 0;
+ changed |= BSS_CHANGED_ASSOC;
+ IMPROVE();
+
+ lkpi_update_mcast_filter(lhw->ic);
+
+ /*
+ * Executing the bss_info_changed(BSS_CHANGED_ASSOC) with
+ * assoc = false right away here will remove the sta from
+ * firmware for iwlwifi.
+ * We no longer do this but only return the BSS_CHNAGED value.
+ * The caller is responsible for removing the sta gong to
+ * IEEE80211_STA_NOTEXIST and then executing the
+ * bss_info_changed() update.
+ * See lkpi_sta_run_to_init() for more detailed comment.
+ */
+
+ lvif = VIF_TO_LVIF(vif);
+ lvif->beacons = 0;
+ }
+
+ return (changed);
+}
+
+static void
+lkpi_wake_tx_queues(struct ieee80211_hw *hw, struct ieee80211_sta *sta,
+ bool dequeue_seen, bool no_emptyq)
+{
+ struct lkpi_txq *ltxq;
+ int tid;
+ bool ltxq_empty;
+
+ /* Wake up all queues to know they are allocated in the driver. */
+ for (tid = 0; tid < nitems(sta->txq); tid++) {
+
+ if (tid == IEEE80211_NUM_TIDS) {
+ IMPROVE("station specific?");
+ if (!ieee80211_hw_check(hw, STA_MMPDU_TXQ))
+ continue;
+ } else if (tid >= hw->queues)
+ continue;
+
+ if (sta->txq[tid] == NULL)
+ continue;
+
+ ltxq = TXQ_TO_LTXQ(sta->txq[tid]);
+ if (dequeue_seen && !ltxq->seen_dequeue)
+ continue;
+
+ LKPI_80211_LTXQ_LOCK(ltxq);
+ ltxq_empty = skb_queue_empty(&ltxq->skbq);
+ LKPI_80211_LTXQ_UNLOCK(ltxq);
+ if (no_emptyq && ltxq_empty)
+ continue;
+
+ lkpi_80211_mo_wake_tx_queue(hw, sta->txq[tid]);
+ }
+}
+
+/*
+ * On the way down from RUN -> ASSOC -> AUTH we may send a DISASSOC or DEAUTH
+ * packet. The problem is that the state machine functions tend to hold the
+ * LHW lock which will prevent lkpi_80211_txq_tx_one() from sending the packet.
+ * We call this after dropping the ic lock and before acquiring the LHW lock.
+ * we make sure no further packets are queued and if they are queued the task
+ * will finish or be cancelled. At the end if a packet is left we manually
+ * send it. scan_to_auth() would re-enable sending if the lsta would be
+ * re-used.
+ */
+static void
+lkpi_80211_flush_tx(struct lkpi_hw *lhw, struct lkpi_sta *lsta)
+{
+ struct ieee80211_hw *hw;
+ struct mbufq mq;
+ struct mbuf *m;
+ int len;
+
+ /* There is no lockdep_assert_not_held_wiphy(). */
+ hw = LHW_TO_HW(lhw);
+ lockdep_assert_not_held(&hw->wiphy->mtx);
+
+ /* Do not accept any new packets until scan_to_auth or lsta_free(). */
+ LKPI_80211_LSTA_TXQ_LOCK(lsta);
+ lsta->txq_ready = false;
+ LKPI_80211_LSTA_TXQ_UNLOCK(lsta);
+
+ while (taskqueue_cancel(taskqueue_thread, &lsta->txq_task, NULL) != 0)
+ taskqueue_drain(taskqueue_thread, &lsta->txq_task);
+
+ LKPI_80211_LSTA_TXQ_LOCK(lsta);
+ len = mbufq_len(&lsta->txq);
+ if (len <= 0) {
+ LKPI_80211_LSTA_TXQ_UNLOCK(lsta);
+ return;
+ }
+
+ mbufq_init(&mq, IFQ_MAXLEN);
+ mbufq_concat(&mq, &lsta->txq);
+ LKPI_80211_LSTA_TXQ_UNLOCK(lsta);
+
+ m = mbufq_dequeue(&mq);
+ while (m != NULL) {
+ lkpi_80211_txq_tx_one(lsta, m);
+ m = mbufq_dequeue(&mq);
+ }
+}
+
+
+static void
+lkpi_remove_chanctx(struct ieee80211_hw *hw, struct ieee80211_vif *vif)
+{
+ struct ieee80211_chanctx_conf *chanctx_conf;
+ struct lkpi_chanctx *lchanctx;
+
+ chanctx_conf = rcu_dereference_protected(vif->bss_conf.chanctx_conf,
+ lockdep_is_held(&hw->wiphy->mtx));
+
+ if (chanctx_conf == NULL)
+ return;
+
+ /* Remove vif context. */
+ lkpi_80211_mo_unassign_vif_chanctx(hw, vif, &vif->bss_conf, chanctx_conf);
+
+ lkpi_hw_conf_idle(hw, true);
+
+ /* Remove chan ctx. */
+ lkpi_80211_mo_remove_chanctx(hw, chanctx_conf);
+
+ /* Cleanup. */
+ rcu_assign_pointer(vif->bss_conf.chanctx_conf, NULL);
+ lchanctx = CHANCTX_CONF_TO_LCHANCTX(chanctx_conf);
+ list_del(&lchanctx->entry);
+ free(lchanctx, M_LKPI80211);
+}
+
+
+/* -------------------------------------------------------------------------- */
+
+static int
+lkpi_sta_state_do_nada(struct ieee80211vap *vap, enum ieee80211_state nstate, int arg)
+{
+
+ return (0);
+}
+
+/* lkpi_iv_newstate() handles the stop scan case generally. */
+#define lkpi_sta_scan_to_init(_v, _n, _a) lkpi_sta_state_do_nada(_v, _n, _a)
+
+static int
+lkpi_sta_scan_to_auth(struct ieee80211vap *vap, enum ieee80211_state nstate, int arg)
+{
+ struct linuxkpi_ieee80211_channel *chan;
+ struct lkpi_chanctx *lchanctx;
+ struct ieee80211_chanctx_conf *chanctx_conf;
+ struct lkpi_hw *lhw;
+ struct ieee80211_hw *hw;
+ struct lkpi_vif *lvif;
+ struct ieee80211_vif *vif;
+ struct ieee80211_node *ni;
+ struct lkpi_sta *lsta;
+ enum ieee80211_bss_changed bss_changed;
+ struct ieee80211_prep_tx_info prep_tx_info;
+ uint32_t changed;
+ int error;
+ bool synched;
+
+ /*
+ * In here we use vap->iv_bss until lvif->lvif_bss is set.
+ * For all later (STATE >= AUTH) functions we need to use the lvif
+ * cache which will be tracked even through (*iv_update_bss)().
+ */
+
+ if (vap->iv_bss == NULL) {
+ ic_printf(vap->iv_ic, "%s: no iv_bss for vap %p\n", __func__, vap);
+ return (EINVAL);
+ }
+ /*
+ * Keep the ni alive locally. In theory (and practice) iv_bss can change
+ * once we unlock here. This is due to net80211 allowing state changes
+ * and new join1() despite having an active node as well as due to
+ * the fact that the iv_bss can be swapped under the hood in (*iv_update_bss).
+ */
+ ni = ieee80211_ref_node(vap->iv_bss);
+ if (ni->ni_chan == NULL || ni->ni_chan == IEEE80211_CHAN_ANYC) {
+ ic_printf(vap->iv_ic, "%s: no channel set for iv_bss ni %p "
+ "on vap %p\n", __func__, ni, vap);
+ ieee80211_free_node(ni); /* Error handling for the local ni. */
+ return (EINVAL);
+ }
+
+ lhw = vap->iv_ic->ic_softc;
+ chan = lkpi_find_lkpi80211_chan(lhw, ni->ni_chan);
+ if (chan == NULL) {
+ ic_printf(vap->iv_ic, "%s: failed to get LKPI channel from "
+ "iv_bss ni %p on vap %p\n", __func__, ni, vap);
+ ieee80211_free_node(ni); /* Error handling for the local ni. */
+ return (ESRCH);
+ }
+
+ hw = LHW_TO_HW(lhw);
+ lvif = VAP_TO_LVIF(vap);
+ vif = LVIF_TO_VIF(lvif);
+
+ LKPI_80211_LVIF_LOCK(lvif);
+ /* XXX-BZ KASSERT later? */
+ if (lvif->lvif_bss_synched || lvif->lvif_bss != NULL) {
+ ic_printf(vap->iv_ic, "%s:%d: lvif %p vap %p iv_bss %p lvif_bss %p "
+ "lvif_bss->ni %p synched %d\n", __func__, __LINE__,
+ lvif, vap, vap->iv_bss, lvif->lvif_bss,
+ (lvif->lvif_bss != NULL) ? lvif->lvif_bss->ni : NULL,
+ lvif->lvif_bss_synched);
+ LKPI_80211_LVIF_UNLOCK(lvif);
+ ieee80211_free_node(ni); /* Error handling for the local ni. */
+ return (EBUSY);
+ }
+ LKPI_80211_LVIF_UNLOCK(lvif);
+
+ IEEE80211_UNLOCK(vap->iv_ic);
+ wiphy_lock(hw->wiphy);
+
+ /* Add chanctx (or if exists, change it). */
+ chanctx_conf = rcu_dereference_protected(vif->bss_conf.chanctx_conf,
+ lockdep_is_held(&hw->wiphy->mtx));
+ if (chanctx_conf != NULL) {
+ lchanctx = CHANCTX_CONF_TO_LCHANCTX(chanctx_conf);
+ IMPROVE("diff changes for changed, working on live copy, rcu");
+ } else {
+ /* Keep separate alloc as in Linux this is rcu managed? */
+ lchanctx = malloc(sizeof(*lchanctx) + hw->chanctx_data_size,
+ M_LKPI80211, M_WAITOK | M_ZERO);
+ chanctx_conf = &lchanctx->chanctx_conf;
+ }
+
+ chanctx_conf->rx_chains_static = 1;
+ chanctx_conf->rx_chains_dynamic = 1;
+ chanctx_conf->radar_enabled =
+ (chan->flags & IEEE80211_CHAN_RADAR) ? true : false;
+ chanctx_conf->def.chan = chan;
+ chanctx_conf->def.width = NL80211_CHAN_WIDTH_20_NOHT;
+ chanctx_conf->def.center_freq1 = ieee80211_get_channel_center_freq1(ni->ni_chan);
+ chanctx_conf->def.center_freq2 = ieee80211_get_channel_center_freq2(ni->ni_chan);
+ IMPROVE("Check vht_cap from band not just chan?");
+ KASSERT(ni->ni_chan != NULL && ni->ni_chan != IEEE80211_CHAN_ANYC,
+ ("%s:%d: ni %p ni_chan %p\n", __func__, __LINE__, ni, ni->ni_chan));
+
+#ifdef LKPI_80211_HT
+ if (IEEE80211_IS_CHAN_HT(ni->ni_chan)) {
+ if (IEEE80211_IS_CHAN_HT40(ni->ni_chan))
+ chanctx_conf->def.width = NL80211_CHAN_WIDTH_40;
+ else
+ chanctx_conf->def.width = NL80211_CHAN_WIDTH_20;
+ }
+#endif
+#ifdef LKPI_80211_VHT
+ if (IEEE80211_IS_CHAN_VHT_5GHZ(ni->ni_chan)) {
+ if (IEEE80211_IS_CHAN_VHT80P80(ni->ni_chan))
+ chanctx_conf->def.width = NL80211_CHAN_WIDTH_80P80;
+ else if (IEEE80211_IS_CHAN_VHT160(ni->ni_chan))
+ chanctx_conf->def.width = NL80211_CHAN_WIDTH_160;
+ else if (IEEE80211_IS_CHAN_VHT80(ni->ni_chan))
+ chanctx_conf->def.width = NL80211_CHAN_WIDTH_80;
+ }
+#endif
+ chanctx_conf->rx_chains_dynamic = lkpi_get_max_rx_chains(ni);
+ /* Responder ... */
+#if 0
+ chanctx_conf->min_def.chan = chanctx_conf->def.chan;
+ chanctx_conf->min_def.width = NL80211_CHAN_WIDTH_20_NOHT;
+#ifdef LKPI_80211_HT
+ if (IEEE80211_IS_CHAN_HT(ni->ni_chan) || IEEE80211_IS_CHAN_VHT(ni->ni_chan))
+ chanctx_conf->min_def.width = NL80211_CHAN_WIDTH_20;
+#endif
+ chanctx_conf->min_def.center_freq1 = chanctx_conf->def.center_freq1;
+ chanctx_conf->min_def.center_freq2 = chanctx_conf->def.center_freq2;
+#else
+ chanctx_conf->min_def = chanctx_conf->def;
+#endif
+
+ /* Set bss info (bss_info_changed). */
+ bss_changed = 0;
+ vif->bss_conf.bssid = ni->ni_bssid;
+ bss_changed |= BSS_CHANGED_BSSID;
+ vif->bss_conf.txpower = ni->ni_txpower;
+ bss_changed |= BSS_CHANGED_TXPOWER;
+ vif->cfg.idle = false;
+ bss_changed |= BSS_CHANGED_IDLE;
+
+ /* vif->bss_conf.basic_rates ? Where exactly? */
+
+ lvif->beacons = 0;
+ /* Should almost assert it is this. */
+ vif->cfg.assoc = false;
+ vif->cfg.aid = 0;
+
+ bss_changed |= lkpi_update_dtim_tsf(vif, ni, vap, __func__, __LINE__);
+
+ error = 0;
+ if (vif->bss_conf.chanctx_conf == chanctx_conf) {
+ changed = IEEE80211_CHANCTX_CHANGE_MIN_WIDTH;
+ changed |= IEEE80211_CHANCTX_CHANGE_RADAR;
+ changed |= IEEE80211_CHANCTX_CHANGE_RX_CHAINS;
+ changed |= IEEE80211_CHANCTX_CHANGE_WIDTH;
+ lkpi_80211_mo_change_chanctx(hw, chanctx_conf, changed);
+ } else {
+ error = lkpi_80211_mo_add_chanctx(hw, chanctx_conf);
+ if (error == 0 || error == EOPNOTSUPP) {
+ vif->bss_conf.chanreq.oper.chan = chanctx_conf->def.chan;
+ vif->bss_conf.chanreq.oper.width = chanctx_conf->def.width;
+ vif->bss_conf.chanreq.oper.center_freq1 =
+ chanctx_conf->def.center_freq1;
+ vif->bss_conf.chanreq.oper.center_freq2 =
+ chanctx_conf->def.center_freq2;
+ } else {
+ ic_printf(vap->iv_ic, "%s:%d: mo_add_chanctx "
+ "failed: %d\n", __func__, __LINE__, error);
+ goto out;
+ }
+
+ list_add_rcu(&lchanctx->entry, &lhw->lchanctx_list);
+ rcu_assign_pointer(vif->bss_conf.chanctx_conf, chanctx_conf);
+
+ /* Assign vif chanctx. */
+ if (error == 0)
+ error = lkpi_80211_mo_assign_vif_chanctx(hw, vif,
+ &vif->bss_conf, chanctx_conf);
+ if (error == EOPNOTSUPP)
+ error = 0;
+ if (error != 0) {
+ ic_printf(vap->iv_ic, "%s:%d: mo_assign_vif_chanctx "
+ "failed: %d\n", __func__, __LINE__, error);
+ lkpi_80211_mo_remove_chanctx(hw, chanctx_conf);
+ rcu_assign_pointer(vif->bss_conf.chanctx_conf, NULL);
+ lchanctx = CHANCTX_CONF_TO_LCHANCTX(chanctx_conf);
+ list_del(&lchanctx->entry);
+ free(lchanctx, M_LKPI80211);
+ goto out;
+ }
+ }
+ IMPROVE("update radiotap chan fields too");
+
+ /* RATES */
+ IMPROVE("bss info: not all needs to come now and rates are missing");
+ lkpi_80211_mo_bss_info_changed(hw, vif, &vif->bss_conf, bss_changed);
+
+ /*
+ * Given ni and lsta are 1:1 from alloc to free we can assert that
+ * ni always has lsta data attach despite net80211 node swapping
+ * under the hoods.
+ */
+ KASSERT(ni->ni_drv_data != NULL, ("%s: ni %p ni_drv_data %p\n",
+ __func__, ni, ni->ni_drv_data));
+ lsta = ni->ni_drv_data;
+
+ /* Insert the [l]sta into the list of known stations. */
+ list_add_tail(&lsta->lsta_list, &lvif->lsta_list);
+
+ /* Add (or adjust) sta and change state (from NOTEXIST) to NONE. */
+ KASSERT(lsta != NULL, ("%s: ni %p lsta is NULL\n", __func__, ni));
+ KASSERT(lsta->state == IEEE80211_STA_NOTEXIST, ("%s: lsta %p state not "
+ "NOTEXIST: %#x\n", __func__, lsta, lsta->state));
+ error = lkpi_80211_mo_sta_state(hw, vif, lsta, IEEE80211_STA_NONE);
+ if (error != 0) {
+ IMPROVE("do we need to undo the chan ctx?");
+ ic_printf(vap->iv_ic, "%s:%d: mo_sta_state(NONE) "
+ "failed: %d\n", __func__, __LINE__, error);
+ goto out;
+ }
+#if 0
+ lsta->added_to_drv = true; /* mo manages. */
+#endif
+
+ lkpi_lsta_dump(lsta, ni, __func__, __LINE__);
+
+#if 0
+ /*
+ * Wakeup all queues now that sta is there so we have as much time to
+ * possibly prepare the queue in the driver to be ready for the 1st
+ * packet; lkpi_80211_txq_tx_one() still has a workaround as there
+ * is no guarantee or way to check.
+ * XXX-BZ and by now we know that this does not work on all drivers
+ * for all queues.
+ */
+ lkpi_wake_tx_queues(hw, LSTA_TO_STA(lsta), false, false);
+#endif
+
+ /* Start mgd_prepare_tx. */
+ memset(&prep_tx_info, 0, sizeof(prep_tx_info));
+ prep_tx_info.duration = PREP_TX_INFO_DURATION;
+ lkpi_80211_mo_mgd_prepare_tx(hw, vif, &prep_tx_info);
+ lsta->in_mgd = true;
+
+ /*
+ * What is going to happen next:
+ * - <twiddle> .. we should end up in "auth_to_assoc"
+ * - event_callback
+ * - update sta_state (NONE to AUTH)
+ * - mgd_complete_tx
+ * (ideally we'd do that on a callback for something else ...)
+ */
+
+ wiphy_unlock(hw->wiphy);
+ IEEE80211_LOCK(vap->iv_ic);
+
+ LKPI_80211_LVIF_LOCK(lvif);
+ /* Re-check given (*iv_update_bss) could have happened while we were unlocked. */
+ if (lvif->lvif_bss_synched || lvif->lvif_bss != NULL ||
+ lsta->ni != vap->iv_bss)
+ ic_printf(vap->iv_ic, "%s:%d: lvif %p vap %p iv_bss %p lvif_bss %p "
+ "lvif_bss->ni %p synched %d, ni %p lsta %p\n", __func__, __LINE__,
+ lvif, vap, vap->iv_bss, lvif->lvif_bss,
+ (lvif->lvif_bss != NULL) ? lvif->lvif_bss->ni : NULL,
+ lvif->lvif_bss_synched, ni, lsta);
+
+ /*
+ * Reference the "ni" for caching the lsta/ni in lvif->lvif_bss.
+ * Given we cache lsta we use lsta->ni instead of ni here (even though
+ * lsta->ni == ni) to be distinct from the rest of the code where we do
+ * assume that ni == vap->iv_bss which it may or may not be.
+ * So do NOT use iv_bss here anymore as that may have diverged from our
+ * function local ni already while ic was unlocked and would lead to
+ * inconsistencies. Go and see if we lost a race and do not update
+ * lvif_bss_synched in that case.
+ */
+ ieee80211_ref_node(lsta->ni);
+ lvif->lvif_bss = lsta;
+ if (lsta->ni == vap->iv_bss) {
+ lvif->lvif_bss_synched = synched = true;
+ } else {
+ /* Set to un-synched no matter what. */
+ lvif->lvif_bss_synched = synched = false;
+ /*
+ * We do not error as someone has to take us down.
+ * If we are followed by a 2nd, new net80211::join1() going to
+ * AUTH lkpi_sta_a_to_a() will error, lkpi_sta_auth_to_{scan,init}()
+ * will take the lvif->lvif_bss node down eventually.
+ * What happens with the vap->iv_bss node will entirely be up
+ * to net80211 as we never used the node beyond alloc()/free()
+ * and we do not hold an extra reference for that anymore given
+ * ni : lsta == 1:1.
+ * Problem is if we do not error a MGMT/AUTH frame will be
+ * sent from net80211::sta_newstate(); disable lsta queue below.
+ */
+ }
+ LKPI_80211_LVIF_UNLOCK(lvif);
+ /*
+ * Make sure in case the sta did not change and we re-added it,
+ * that we can tx again but only if the vif/iv_bss are in sync.
+ * Otherwise this should prevent the MGMT/AUTH frame from being
+ * sent triggering a warning in iwlwifi.
+ */
+ LKPI_80211_LSTA_TXQ_LOCK(lsta);
+ lsta->txq_ready = synched;
+ LKPI_80211_LSTA_TXQ_UNLOCK(lsta);
+ goto out_relocked;
+
+out:
+ wiphy_unlock(hw->wiphy);
+ IEEE80211_LOCK(vap->iv_ic);
+out_relocked:
+ /*
+ * Release the reference that kept the ni stable locally
+ * during the work of this function.
+ */
+ if (ni != NULL)
+ ieee80211_free_node(ni);
+ return (error);
+}
+
+static int
+lkpi_sta_auth_to_scan(struct ieee80211vap *vap, enum ieee80211_state nstate, int arg)
+{
+ struct lkpi_hw *lhw;
+ struct ieee80211_hw *hw;
+ struct lkpi_vif *lvif;
+ struct ieee80211_vif *vif;
+ struct ieee80211_node *ni;
+ struct lkpi_sta *lsta;
+ struct ieee80211_sta *sta;
+ struct ieee80211_prep_tx_info prep_tx_info;
+ enum ieee80211_bss_changed bss_changed;
+ int error;
+
+ lhw = vap->iv_ic->ic_softc;
+ hw = LHW_TO_HW(lhw);
+ lvif = VAP_TO_LVIF(vap);
+ vif = LVIF_TO_VIF(lvif);
+
+ LKPI_80211_LVIF_LOCK(lvif);
+#ifdef LINUXKPI_DEBUG_80211
+ /* XXX-BZ KASSERT later; state going down so no action. */
+ if (lvif->lvif_bss == NULL)
+ ic_printf(vap->iv_ic, "%s:%d: lvif %p vap %p iv_bss %p lvif_bss %p "
+ "lvif_bss->ni %p synched %d\n", __func__, __LINE__,
+ lvif, vap, vap->iv_bss, lvif->lvif_bss,
+ (lvif->lvif_bss != NULL) ? lvif->lvif_bss->ni : NULL,
+ lvif->lvif_bss_synched);
+#endif
+
+ lsta = lvif->lvif_bss;
+ LKPI_80211_LVIF_UNLOCK(lvif);
+ KASSERT(lsta != NULL && lsta->ni != NULL, ("%s: lsta %p ni %p "
+ "lvif %p vap %p\n", __func__,
+ lsta, (lsta != NULL) ? lsta->ni : NULL, lvif, vap));
+ ni = lsta->ni; /* Reference held for lvif_bss. */
+ sta = LSTA_TO_STA(lsta);
+
+ lkpi_lsta_dump(lsta, ni, __func__, __LINE__);
+
+ IEEE80211_UNLOCK(vap->iv_ic);
+ wiphy_lock(hw->wiphy);
+
+ /* flush, drop. */
+ lkpi_80211_mo_flush(hw, vif, nitems(sta->txq), true);
+
+ /* Wake tx queues to get packet(s) out. */
+ lkpi_wake_tx_queues(hw, sta, false, true);
+
+ /* flush, no drop */
+ lkpi_80211_mo_flush(hw, vif, nitems(sta->txq), false);
+
+ /* End mgd_complete_tx. */
+ if (lsta->in_mgd) {
+ memset(&prep_tx_info, 0, sizeof(prep_tx_info));
+ prep_tx_info.success = false;
+ lkpi_80211_mo_mgd_complete_tx(hw, vif, &prep_tx_info);
+ lsta->in_mgd = false;
+ }
+
+ /* sync_rx_queues */
+ lkpi_80211_mo_sync_rx_queues(hw);
+
+ /* sta_pre_rcu_remove */
+ lkpi_80211_mo_sta_pre_rcu_remove(hw, vif, sta);
+
+ /* Take the station down. */
+
+ /* Adjust sta and change state (from NONE) to NOTEXIST. */
+ KASSERT(lsta != NULL, ("%s: ni %p lsta is NULL\n", __func__, ni));
+ KASSERT(lsta->state == IEEE80211_STA_NONE, ("%s: lsta %p state not "
+ "NONE: %#x, nstate %d arg %d\n", __func__, lsta, lsta->state, nstate, arg));
+ error = lkpi_80211_mo_sta_state(hw, vif, lsta, IEEE80211_STA_NOTEXIST);
+ if (error != 0) {
+ IMPROVE("do we need to undo the chan ctx?");
+ ic_printf(vap->iv_ic, "%s:%d: mo_sta_state(NOTEXIST) "
+ "failed: %d\n", __func__, __LINE__, error);
+ goto out;
+ }
+#if 0
+ lsta->added_to_drv = false; /* mo manages. */
+#endif
+
+ bss_changed = 0;
+ vif->bss_conf.dtim_period = 0; /* go back to 0. */
+ bss_changed |= BSS_CHANGED_BEACON_INFO;
+ lkpi_80211_mo_bss_info_changed(hw, vif, &vif->bss_conf, bss_changed);
+
+ lkpi_lsta_dump(lsta, ni, __func__, __LINE__);
+
+ LKPI_80211_LVIF_LOCK(lvif);
+ /* Remove ni reference for this cache of lsta. */
+ lvif->lvif_bss = NULL;
+ lvif->lvif_bss_synched = false;
+ LKPI_80211_LVIF_UNLOCK(lvif);
+ lkpi_lsta_remove(lsta, lvif);
+
+ /* conf_tx */
+
+ lkpi_remove_chanctx(hw, vif);
+
+out:
+ wiphy_unlock(hw->wiphy);
+ IEEE80211_LOCK(vap->iv_ic);
+ if (error == 0) {
+ /*
+ * We do this outside the wiphy lock as net80211::node_free() may call
+ * into crypto code to delete keys and we have a recursed on
+ * non-recursive sx panic. Also only do this if we get here w/o error.
+ *
+ * The very last release the reference on the ni for the ni/lsta on
+ * lvif->lvif_bss. Upon return from this both ni and lsta are invalid
+ * and potentially freed.
+ */
+ ieee80211_free_node(ni);
+ }
+ return (error);
+}
+
+static int
+lkpi_sta_auth_to_init(struct ieee80211vap *vap, enum ieee80211_state nstate, int arg)
+{
+ int error;
+
+ error = lkpi_sta_auth_to_scan(vap, nstate, arg);
+ if (error == 0)
+ error = lkpi_sta_scan_to_init(vap, nstate, arg);
+ return (error);
+}
+
+static int
+lkpi_sta_auth_to_assoc(struct ieee80211vap *vap, enum ieee80211_state nstate, int arg)
+{
+ struct lkpi_hw *lhw;
+ struct ieee80211_hw *hw;
+ struct lkpi_vif *lvif;
+ struct ieee80211_vif *vif;
+ struct lkpi_sta *lsta;
+ struct ieee80211_prep_tx_info prep_tx_info;
+ int error;
+
+ lhw = vap->iv_ic->ic_softc;
+ hw = LHW_TO_HW(lhw);
+ lvif = VAP_TO_LVIF(vap);
+ vif = LVIF_TO_VIF(lvif);
+
+ IEEE80211_UNLOCK(vap->iv_ic);
+ wiphy_lock(hw->wiphy);
+
+ LKPI_80211_LVIF_LOCK(lvif);
+ /* XXX-BZ KASSERT later? */
+ if (!lvif->lvif_bss_synched || lvif->lvif_bss == NULL) {
+#ifdef LINUXKPI_DEBUG_80211
+ ic_printf(vap->iv_ic, "%s:%d: lvif %p vap %p iv_bss %p lvif_bss %p "
+ "lvif_bss->ni %p synched %d\n", __func__, __LINE__,
+ lvif, vap, vap->iv_bss, lvif->lvif_bss,
+ (lvif->lvif_bss != NULL) ? lvif->lvif_bss->ni : NULL,
+ lvif->lvif_bss_synched);
+#endif
+ error = ENOTRECOVERABLE;
+ LKPI_80211_LVIF_UNLOCK(lvif);
+ goto out;
+ }
+ lsta = lvif->lvif_bss;
+ LKPI_80211_LVIF_UNLOCK(lvif);
+
+ KASSERT(lsta != NULL, ("%s: lsta %p\n", __func__, lsta));
+
+ /* Finish auth. */
+ IMPROVE("event callback");
+
+ /* Update sta_state (NONE to AUTH). */
+ KASSERT(lsta->state == IEEE80211_STA_NONE, ("%s: lsta %p state not "
+ "NONE: %#x\n", __func__, lsta, lsta->state));
+ error = lkpi_80211_mo_sta_state(hw, vif, lsta, IEEE80211_STA_AUTH);
+ if (error != 0) {
+ ic_printf(vap->iv_ic, "%s:%d: mo_sta_state(AUTH) "
+ "failed: %d\n", __func__, __LINE__, error);
+ goto out;
+ }
+
+ /* End mgd_complete_tx. */
+ if (lsta->in_mgd) {
+ memset(&prep_tx_info, 0, sizeof(prep_tx_info));
+ prep_tx_info.success = true;
+ lkpi_80211_mo_mgd_complete_tx(hw, vif, &prep_tx_info);
+ lsta->in_mgd = false;
+ }
+
+ /* Now start assoc. */
+
+ /* Start mgd_prepare_tx. */
+ if (!lsta->in_mgd) {
+ memset(&prep_tx_info, 0, sizeof(prep_tx_info));
+ prep_tx_info.duration = PREP_TX_INFO_DURATION;
+ lkpi_80211_mo_mgd_prepare_tx(hw, vif, &prep_tx_info);
+ lsta->in_mgd = true;
+ }
+
+ /* Wake tx queue to get packet out. */
+ lkpi_wake_tx_queues(hw, LSTA_TO_STA(lsta), false, true);
+
+ /*
+ * <twiddle> .. we end up in "assoc_to_run"
+ * - update sta_state (AUTH to ASSOC)
+ * - conf_tx [all]
+ * - bss_info_changed (assoc, aid, ssid, ..)
+ * - change_chanctx (if needed)
+ * - event_callback
+ * - mgd_complete_tx
+ */
+
+out:
+ wiphy_unlock(hw->wiphy);
+ IEEE80211_LOCK(vap->iv_ic);
+ return (error);
+}
+
+/* auth_to_auth, assoc_to_assoc. */
+static int
+lkpi_sta_a_to_a(struct ieee80211vap *vap, enum ieee80211_state nstate, int arg)
+{
+ struct lkpi_hw *lhw;
+ struct ieee80211_hw *hw;
+ struct lkpi_vif *lvif;
+ struct ieee80211_vif *vif;
+ struct lkpi_sta *lsta;
+ struct ieee80211_prep_tx_info prep_tx_info;
+ int error;
+
+ lhw = vap->iv_ic->ic_softc;
+ hw = LHW_TO_HW(lhw);
+ lvif = VAP_TO_LVIF(vap);
+ vif = LVIF_TO_VIF(lvif);
+
+ IEEE80211_UNLOCK(vap->iv_ic);
+ wiphy_lock(hw->wiphy);
+
+ LKPI_80211_LVIF_LOCK(lvif);
+ /* XXX-BZ KASSERT later? */
+ if (!lvif->lvif_bss_synched || lvif->lvif_bss == NULL) {
+#ifdef LINUXKPI_DEBUG_80211
+ ic_printf(vap->iv_ic, "%s:%d: lvif %p vap %p iv_bss %p lvif_bss %p "
+ "lvif_bss->ni %p synched %d\n", __func__, __LINE__,
+ lvif, vap, vap->iv_bss, lvif->lvif_bss,
+ (lvif->lvif_bss != NULL) ? lvif->lvif_bss->ni : NULL,
+ lvif->lvif_bss_synched);
+#endif
+ LKPI_80211_LVIF_UNLOCK(lvif);
+ error = ENOTRECOVERABLE;
+ goto out;
+ }
+ lsta = lvif->lvif_bss;
+ LKPI_80211_LVIF_UNLOCK(lvif);
+
+ KASSERT(lsta != NULL, ("%s: lsta %p! lvif %p vap %p\n", __func__,
+ lsta, lvif, vap));
+
+ IMPROVE("event callback?");
+
+ /* End mgd_complete_tx. */
+ if (lsta->in_mgd) {
+ memset(&prep_tx_info, 0, sizeof(prep_tx_info));
+ prep_tx_info.success = false;
+ lkpi_80211_mo_mgd_complete_tx(hw, vif, &prep_tx_info);
+ lsta->in_mgd = false;
+ }
+
+ /* Now start assoc. */
+
+ /* Start mgd_prepare_tx. */
+ if (!lsta->in_mgd) {
+ memset(&prep_tx_info, 0, sizeof(prep_tx_info));
+ prep_tx_info.duration = PREP_TX_INFO_DURATION;
+ lkpi_80211_mo_mgd_prepare_tx(hw, vif, &prep_tx_info);
+ lsta->in_mgd = true;
+ }
+
+ error = 0;
+out:
+ wiphy_unlock(hw->wiphy);
+ IEEE80211_LOCK(vap->iv_ic);
+
+ return (error);
+}
+
+static int
+_lkpi_sta_assoc_to_down(struct ieee80211vap *vap, enum ieee80211_state nstate, int arg)
+{
+ struct lkpi_hw *lhw;
+ struct ieee80211_hw *hw;
+ struct lkpi_vif *lvif;
+ struct ieee80211_vif *vif;
+ struct ieee80211_node *ni;
+ struct lkpi_sta *lsta;
+ struct ieee80211_sta *sta;
+ struct ieee80211_prep_tx_info prep_tx_info;
+ enum ieee80211_bss_changed bss_changed;
+ int error;
+
+ lhw = vap->iv_ic->ic_softc;
+ hw = LHW_TO_HW(lhw);
+ lvif = VAP_TO_LVIF(vap);
+ vif = LVIF_TO_VIF(lvif);
+
+ IEEE80211_UNLOCK(vap->iv_ic);
+ wiphy_lock(hw->wiphy);
+
+ LKPI_80211_LVIF_LOCK(lvif);
+#ifdef LINUXKPI_DEBUG_80211
+ /* XXX-BZ KASSERT later; state going down so no action. */
+ if (lvif->lvif_bss == NULL)
+ ic_printf(vap->iv_ic, "%s:%d: lvif %p vap %p iv_bss %p lvif_bss %p "
+ "lvif_bss->ni %p synched %d\n", __func__, __LINE__,
+ lvif, vap, vap->iv_bss, lvif->lvif_bss,
+ (lvif->lvif_bss != NULL) ? lvif->lvif_bss->ni : NULL,
+ lvif->lvif_bss_synched);
+#endif
+ lsta = lvif->lvif_bss;
+ LKPI_80211_LVIF_UNLOCK(lvif);
+ KASSERT(lsta != NULL && lsta->ni != NULL, ("%s: lsta %p ni %p "
+ "lvif %p vap %p\n", __func__,
+ lsta, (lsta != NULL) ? lsta->ni : NULL, lvif, vap));
+
+ ni = lsta->ni; /* Reference held for lvif_bss. */
+ sta = LSTA_TO_STA(lsta);
+
+ lkpi_lsta_dump(lsta, ni, __func__, __LINE__);
+
+ /* flush, drop. */
+ lkpi_80211_mo_flush(hw, vif, nitems(sta->txq), true);
+
+ IMPROVE("What are the proper conditions for DEAUTH_NEED_MGD_TX_PREP?");
+ if (ieee80211_hw_check(hw, DEAUTH_NEED_MGD_TX_PREP) &&
+ !lsta->in_mgd) {
+ memset(&prep_tx_info, 0, sizeof(prep_tx_info));
+ prep_tx_info.duration = PREP_TX_INFO_DURATION;
+ prep_tx_info.was_assoc = true;
+ lkpi_80211_mo_mgd_prepare_tx(hw, vif, &prep_tx_info);
+ lsta->in_mgd = true;
+ }
+
+ wiphy_unlock(hw->wiphy);
+ IEEE80211_LOCK(vap->iv_ic);
+
+ /* Call iv_newstate first so we get potential DEAUTH packet out. */
+ error = lvif->iv_newstate(vap, nstate, arg);
+ if (error != 0) {
+ ic_printf(vap->iv_ic, "%s:%d: iv_newstate(%p, %d, %d) "
+ "failed: %d\n", __func__, __LINE__, vap, nstate, arg, error);
+ goto outni;
+ }
+
+ IEEE80211_UNLOCK(vap->iv_ic);
+
+ /* Ensure the packets get out. */
+ lkpi_80211_flush_tx(lhw, lsta);
+
+ wiphy_lock(hw->wiphy);
+
+ lkpi_lsta_dump(lsta, ni, __func__, __LINE__);
+
+ /* Wake tx queues to get packet(s) out. */
+ lkpi_wake_tx_queues(hw, sta, false, true);
+
+ /* flush, no drop */
+ lkpi_80211_mo_flush(hw, vif, nitems(sta->txq), false);
+
+ /* End mgd_complete_tx. */
+ if (lsta->in_mgd) {
+ memset(&prep_tx_info, 0, sizeof(prep_tx_info));
+ prep_tx_info.success = false;
+ prep_tx_info.was_assoc = true;
+ lkpi_80211_mo_mgd_complete_tx(hw, vif, &prep_tx_info);
+ lsta->in_mgd = false;
+ }
+
+ /* sync_rx_queues */
+ lkpi_80211_mo_sync_rx_queues(hw);
+
+ /* sta_pre_rcu_remove */
+ lkpi_80211_mo_sta_pre_rcu_remove(hw, vif, sta);
+
+ /* Take the station down. */
+
+ /* Update sta and change state (from AUTH) to NONE. */
+ KASSERT(lsta != NULL, ("%s: ni %p lsta is NULL\n", __func__, ni));
+ KASSERT(lsta->state == IEEE80211_STA_AUTH, ("%s: lsta %p state not "
+ "AUTH: %#x\n", __func__, lsta, lsta->state));
+ error = lkpi_80211_mo_sta_state(hw, vif, lsta, IEEE80211_STA_NONE);
+ if (error != 0) {
+ ic_printf(vap->iv_ic, "%s:%d: mo_sta_state(NONE) "
+ "failed: %d\n", __func__, __LINE__, error);
+ goto out;
+ }
+
+ /* See comment in lkpi_sta_run_to_init(). */
+ bss_changed = 0;
+ bss_changed |= lkpi_disassoc(sta, vif, lhw);
+
+#ifdef LKPI_80211_HW_CRYPTO
+ /*
+ * In theory we remove keys here but there must not exist any for this
+ * state change until we clean them up again into small steps and no
+ * code duplication.
+ */
+#endif
+
+ lkpi_lsta_dump(lsta, ni, __func__, __LINE__);
+
+ /* Adjust sta and change state (from NONE) to NOTEXIST. */
+ KASSERT(lsta != NULL, ("%s: ni %p lsta is NULL\n", __func__, ni));
+ KASSERT(lsta->state == IEEE80211_STA_NONE, ("%s: lsta %p state not "
+ "NONE: %#x, nstate %d arg %d\n", __func__, lsta, lsta->state, nstate, arg));
+ error = lkpi_80211_mo_sta_state(hw, vif, lsta, IEEE80211_STA_NOTEXIST);
+ if (error != 0) {
+ IMPROVE("do we need to undo the chan ctx?");
+ ic_printf(vap->iv_ic, "%s:%d: mo_sta_state(NOTEXIST) "
+ "failed: %d\n", __func__, __LINE__, error);
+ goto out;
+ }
+
+ lkpi_lsta_dump(lsta, ni, __func__, __LINE__); /* sta no longer save to use. */
+
+ IMPROVE("Any bss_info changes to announce?");
+ vif->bss_conf.qos = 0;
+ bss_changed |= BSS_CHANGED_QOS;
+ vif->cfg.ssid_len = 0;
+ memset(vif->cfg.ssid, '\0', sizeof(vif->cfg.ssid));
+ bss_changed |= BSS_CHANGED_BSSID;
+ vif->bss_conf.dtim_period = 0; /* go back to 0. */
+ bss_changed |= BSS_CHANGED_BEACON_INFO;
+ lkpi_80211_mo_bss_info_changed(hw, vif, &vif->bss_conf, bss_changed);
+
+ LKPI_80211_LVIF_LOCK(lvif);
+ /* Remove ni reference for this cache of lsta. */
+ lvif->lvif_bss = NULL;
+ lvif->lvif_bss_synched = false;
+ LKPI_80211_LVIF_UNLOCK(lvif);
+ lkpi_lsta_remove(lsta, lvif);
+
+ /* conf_tx */
+
+ lkpi_remove_chanctx(hw, vif);
+
+ error = EALREADY;
+out:
+ wiphy_unlock(hw->wiphy);
+ IEEE80211_LOCK(vap->iv_ic);
+ if (error == EALREADY) {
+ /*
+ * We do this outside the wiphy lock as net80211::node_free() may call
+ * into crypto code to delete keys and we have a recursed on
+ * non-recursive sx panic. Also only do this if we get here w/o error.
+ *
+ * The very last release the reference on the ni for the ni/lsta on
+ * lvif->lvif_bss. Upon return from this both ni and lsta are invalid
+ * and potentially freed.
+ */
+ ieee80211_free_node(ni);
+ }
+outni:
+ return (error);
+}
+
+static int
+lkpi_sta_assoc_to_auth(struct ieee80211vap *vap, enum ieee80211_state nstate, int arg)
+{
+ int error;
+
+ error = _lkpi_sta_assoc_to_down(vap, nstate, arg);
+ if (error != 0 && error != EALREADY)
+ return (error);
+
+ /* At this point iv_bss is long a new node! */
+
+ error |= lkpi_sta_scan_to_auth(vap, nstate, 0);
+ return (error);
+}
+
+static int
+lkpi_sta_assoc_to_scan(struct ieee80211vap *vap, enum ieee80211_state nstate, int arg)
+{
+ int error;
+
+ error = _lkpi_sta_assoc_to_down(vap, nstate, arg);
+ return (error);
+}
+
+static int
+lkpi_sta_assoc_to_init(struct ieee80211vap *vap, enum ieee80211_state nstate, int arg)
+{
+ int error;
+
+ error = _lkpi_sta_assoc_to_down(vap, nstate, arg);
+ return (error);
+}
+
+static int
+lkpi_sta_assoc_to_run(struct ieee80211vap *vap, enum ieee80211_state nstate, int arg)
+{
+ struct lkpi_hw *lhw;
+ struct ieee80211_hw *hw;
+ struct lkpi_vif *lvif;
+ struct ieee80211_vif *vif;
+ struct ieee80211_node *ni;
+ struct lkpi_sta *lsta;
+ struct ieee80211_sta *sta;
+ struct ieee80211_prep_tx_info prep_tx_info;
+ enum ieee80211_bss_changed bss_changed;
+ int error;
+
+ lhw = vap->iv_ic->ic_softc;
+ hw = LHW_TO_HW(lhw);
+ lvif = VAP_TO_LVIF(vap);
+ vif = LVIF_TO_VIF(lvif);
+
+ IEEE80211_UNLOCK(vap->iv_ic);
+ wiphy_lock(hw->wiphy);
+
+ LKPI_80211_LVIF_LOCK(lvif);
+ /* XXX-BZ KASSERT later? */
+ if (!lvif->lvif_bss_synched || lvif->lvif_bss == NULL) {
+#ifdef LINUXKPI_DEBUG_80211
+ ic_printf(vap->iv_ic, "%s:%d: lvif %p vap %p iv_bss %p lvif_bss %p "
+ "lvif_bss->ni %p synched %d\n", __func__, __LINE__,
+ lvif, vap, vap->iv_bss, lvif->lvif_bss,
+ (lvif->lvif_bss != NULL) ? lvif->lvif_bss->ni : NULL,
+ lvif->lvif_bss_synched);
+#endif
+ LKPI_80211_LVIF_UNLOCK(lvif);
+ error = ENOTRECOVERABLE;
+ goto out;
+ }
+ lsta = lvif->lvif_bss;
+ LKPI_80211_LVIF_UNLOCK(lvif);
+ KASSERT(lsta != NULL && lsta->ni != NULL, ("%s: lsta %p ni %p "
+ "lvif %p vap %p\n", __func__,
+ lsta, (lsta != NULL) ? lsta->ni : NULL, lvif, vap));
+
+ ni = lsta->ni; /* Reference held for lvif_bss. */
+
+ IMPROVE("ponder some of this moved to ic_newassoc, scan_assoc_success, "
+ "and to lesser extend ieee80211_notify_node_join");
+
+ /* Finish assoc. */
+ /* Update sta_state (AUTH to ASSOC) and set aid. */
+ KASSERT(lsta->state == IEEE80211_STA_AUTH, ("%s: lsta %p state not "
+ "AUTH: %#x\n", __func__, lsta, lsta->state));
+ sta = LSTA_TO_STA(lsta);
+ sta->aid = IEEE80211_NODE_AID(ni);
+#ifdef LKPI_80211_WME
+ if (vap->iv_flags & IEEE80211_F_WME)
+ sta->wme = true;
+#endif
+ error = lkpi_80211_mo_sta_state(hw, vif, lsta, IEEE80211_STA_ASSOC);
+ if (error != 0) {
+ ic_printf(vap->iv_ic, "%s:%d: mo_sta_state(ASSOC) "
+ "failed: %d\n", __func__, __LINE__, error);
+ goto out;
+ }
+
+ IMPROVE("wme / conf_tx [all]");
+
+ /* Update bss info (bss_info_changed) (assoc, aid, ..). */
+ bss_changed = 0;
+#ifdef LKPI_80211_WME
+ bss_changed |= lkpi_wme_update(lhw, vap, true);
+#endif
+ if (!vif->cfg.assoc || vif->cfg.aid != IEEE80211_NODE_AID(ni)) {
+ lvif->beacons = 0;
+ vif->cfg.assoc = true;
+ vif->cfg.aid = IEEE80211_NODE_AID(ni);
+ bss_changed |= BSS_CHANGED_ASSOC;
+ }
+ /* We set SSID but this is not BSSID! */
+ vif->cfg.ssid_len = ni->ni_esslen;
+ memcpy(vif->cfg.ssid, ni->ni_essid, ni->ni_esslen);
+ if ((vap->iv_flags & IEEE80211_F_SHPREAMBLE) !=
+ vif->bss_conf.use_short_preamble) {
+ vif->bss_conf.use_short_preamble ^= 1;
+ /* bss_changed |= BSS_CHANGED_??? */
+ }
+ if ((vap->iv_flags & IEEE80211_F_SHSLOT) !=
+ vif->bss_conf.use_short_slot) {
+ vif->bss_conf.use_short_slot ^= 1;
+ /* bss_changed |= BSS_CHANGED_??? */
+ }
+ if ((ni->ni_flags & IEEE80211_NODE_QOS) !=
+ vif->bss_conf.qos) {
+ vif->bss_conf.qos ^= 1;
+ bss_changed |= BSS_CHANGED_QOS;
+ }
+
+ bss_changed |= lkpi_update_dtim_tsf(vif, ni, vap, __func__, __LINE__);
+ lkpi_80211_mo_bss_info_changed(hw, vif, &vif->bss_conf, bss_changed);
+
+ /* - change_chanctx (if needed)
+ * - event_callback
+ */
+
+ /* End mgd_complete_tx. */
+ if (lsta->in_mgd) {
+ memset(&prep_tx_info, 0, sizeof(prep_tx_info));
+ prep_tx_info.success = true;
+ lkpi_80211_mo_mgd_complete_tx(hw, vif, &prep_tx_info);
+ lsta->in_mgd = false;
+ }
+
+ lkpi_hw_conf_idle(hw, false);
+
+ /*
+ * And then:
+ * - (more packets)?
+ * - set_key
+ * - set_default_unicast_key
+ * - set_key (?)
+ * - ipv6_addr_change (?)
+ */
+
+ if (!ieee80211_node_is_authorized(ni)) {
+ IMPROVE("net80211 does not consider node authorized");
+ }
+
+ IMPROVE("Is this the right spot, has net80211 done all updates already?");
+ lkpi_sta_sync_from_ni(hw, vif, sta, ni, true);
+
+ /* Update thresholds. */
+ hw->wiphy->frag_threshold = vap->iv_fragthreshold;
+ lkpi_80211_mo_set_frag_threshold(hw, vap->iv_fragthreshold);
+ hw->wiphy->rts_threshold = vap->iv_rtsthreshold;
+ lkpi_80211_mo_set_rts_threshold(hw, vap->iv_rtsthreshold);
+
+ /* Update sta_state (ASSOC to AUTHORIZED). */
+ KASSERT(lsta != NULL, ("%s: ni %p lsta is NULL\n", __func__, ni));
+ KASSERT(lsta->state == IEEE80211_STA_ASSOC, ("%s: lsta %p state not "
+ "ASSOC: %#x\n", __func__, lsta, lsta->state));
+ error = lkpi_80211_mo_sta_state(hw, vif, lsta, IEEE80211_STA_AUTHORIZED);
+ if (error != 0) {
+ IMPROVE("undo some changes?");
+ ic_printf(vap->iv_ic, "%s:%d: mo_sta_state(AUTHORIZED) "
+ "failed: %d\n", __func__, __LINE__, error);
+ goto out;
+ }
+
+ /* - drv_config (?)
+ * - bss_info_changed
+ * - set_rekey_data (?)
+ *
+ * And now we should be passing packets.
+ */
+ IMPROVE("Need that bssid setting, and the keys");
+
+ bss_changed = 0;
+ bss_changed |= lkpi_update_dtim_tsf(vif, ni, vap, __func__, __LINE__);
+ lkpi_80211_mo_bss_info_changed(hw, vif, &vif->bss_conf, bss_changed);
+
+ /* Prepare_multicast && configure_filter. */
+ lkpi_update_mcast_filter(vap->iv_ic);
+
+out:
+ wiphy_unlock(hw->wiphy);
+ IEEE80211_LOCK(vap->iv_ic);
+ return (error);
+}
+
+static int
+lkpi_sta_auth_to_run(struct ieee80211vap *vap, enum ieee80211_state nstate, int arg)
+{
+ int error;
+
+ error = lkpi_sta_auth_to_assoc(vap, nstate, arg);
+ if (error == 0)
+ error = lkpi_sta_assoc_to_run(vap, nstate, arg);
+ return (error);
+}
+
+static int
+lkpi_sta_run_to_assoc(struct ieee80211vap *vap, enum ieee80211_state nstate, int arg)
+{
+ struct lkpi_hw *lhw;
+ struct ieee80211_hw *hw;
+ struct lkpi_vif *lvif;
+ struct ieee80211_vif *vif;
+ struct ieee80211_node *ni;
+ struct lkpi_sta *lsta;
+ struct ieee80211_sta *sta;
+ struct ieee80211_prep_tx_info prep_tx_info;
+#if 0
+ enum ieee80211_bss_changed bss_changed;
+#endif
+ int error;
+
+ lhw = vap->iv_ic->ic_softc;
+ hw = LHW_TO_HW(lhw);
+ lvif = VAP_TO_LVIF(vap);
+ vif = LVIF_TO_VIF(lvif);
+
+ LKPI_80211_LVIF_LOCK(lvif);
+#ifdef LINUXKPI_DEBUG_80211
+ /* XXX-BZ KASSERT later; state going down so no action. */
+ if (lvif->lvif_bss == NULL)
+ ic_printf(vap->iv_ic, "%s:%d: lvif %p vap %p iv_bss %p lvif_bss %p "
+ "lvif_bss->ni %p synched %d\n", __func__, __LINE__,
+ lvif, vap, vap->iv_bss, lvif->lvif_bss,
+ (lvif->lvif_bss != NULL) ? lvif->lvif_bss->ni : NULL,
+ lvif->lvif_bss_synched);
+#endif
+ lsta = lvif->lvif_bss;
+ LKPI_80211_LVIF_UNLOCK(lvif);
+ KASSERT(lsta != NULL && lsta->ni != NULL, ("%s: lsta %p ni %p "
+ "lvif %p vap %p\n", __func__,
+ lsta, (lsta != NULL) ? lsta->ni : NULL, lvif, vap));
+
+ ni = lsta->ni; /* Reference held for lvif_bss. */
+ sta = LSTA_TO_STA(lsta);
+
+ lkpi_lsta_dump(lsta, ni, __func__, __LINE__);
+
+ IEEE80211_UNLOCK(vap->iv_ic);
+ wiphy_lock(hw->wiphy);
+
+ /* flush, drop. */
+ lkpi_80211_mo_flush(hw, vif, nitems(sta->txq), true);
+
+ IMPROVE("What are the proper conditions for DEAUTH_NEED_MGD_TX_PREP?");
+ if (ieee80211_hw_check(hw, DEAUTH_NEED_MGD_TX_PREP) &&
+ !lsta->in_mgd) {
+ memset(&prep_tx_info, 0, sizeof(prep_tx_info));
+ prep_tx_info.duration = PREP_TX_INFO_DURATION;
+ prep_tx_info.was_assoc = true;
+ lkpi_80211_mo_mgd_prepare_tx(hw, vif, &prep_tx_info);
+ lsta->in_mgd = true;
+ }
+
+ wiphy_unlock(hw->wiphy);
+ IEEE80211_LOCK(vap->iv_ic);
+
+ /* Call iv_newstate first so we get potential DISASSOC packet out. */
+ error = lvif->iv_newstate(vap, nstate, arg);
+ if (error != 0) {
+ ic_printf(vap->iv_ic, "%s:%d: iv_newstate(%p, %d, %d) "
+ "failed: %d\n", __func__, __LINE__, vap, nstate, arg, error);
+ goto outni;
+ }
+
+ IEEE80211_UNLOCK(vap->iv_ic);
+
+ /* Ensure the packets get out. */
+ lkpi_80211_flush_tx(lhw, lsta);
+
+ wiphy_lock(hw->wiphy);
+
+ lkpi_lsta_dump(lsta, ni, __func__, __LINE__);
+
+ /* Wake tx queues to get packet(s) out. */
+ lkpi_wake_tx_queues(hw, sta, false, true);
+
+ /* flush, no drop */
+ lkpi_80211_mo_flush(hw, vif, nitems(sta->txq), false);
+
+ /* End mgd_complete_tx. */
+ if (lsta->in_mgd) {
+ memset(&prep_tx_info, 0, sizeof(prep_tx_info));
+ prep_tx_info.success = false;
+ prep_tx_info.was_assoc = true;
+ lkpi_80211_mo_mgd_complete_tx(hw, vif, &prep_tx_info);
+ lsta->in_mgd = false;
+ }
+
+#if 0
+ /* sync_rx_queues */
+ lkpi_80211_mo_sync_rx_queues(hw);
+
+ /* sta_pre_rcu_remove */
+ lkpi_80211_mo_sta_pre_rcu_remove(hw, vif, sta);
+#endif
+
+ /* Take the station down. */
+
+ /* Adjust sta and change state (from AUTHORIZED) to ASSOC. */
+ KASSERT(lsta != NULL, ("%s: ni %p lsta is NULL\n", __func__, ni));
+ KASSERT(lsta->state == IEEE80211_STA_AUTHORIZED, ("%s: lsta %p state not "
+ "AUTHORIZED: %#x\n", __func__, lsta, lsta->state));
+ error = lkpi_80211_mo_sta_state(hw, vif, lsta, IEEE80211_STA_ASSOC);
+ if (error != 0) {
+ ic_printf(vap->iv_ic, "%s:%d: mo_sta_state(ASSOC) "
+ "failed: %d\n", __func__, __LINE__, error);
+ goto out;
+ }
+
+ lkpi_lsta_dump(lsta, ni, __func__, __LINE__);
+
+#ifdef LKPI_80211_HW_CRYPTO
+ if (lkpi_hwcrypto) {
+ error = lkpi_sta_del_keys(hw, vif, lsta);
+ if (error != 0) {
+ ic_printf(vap->iv_ic, "%s:%d: lkpi_sta_del_keys "
+ "failed: %d\n", __func__, __LINE__, error);
+ /*
+ * Either drv/fw will crash or cleanup itself,
+ * otherwise net80211 will delete the keys (at a
+ * less appropriate time).
+ */
+ /* goto out; */
+ }
+ }
+#endif
+
+ /* Update sta_state (ASSOC to AUTH). */
+ KASSERT(lsta != NULL, ("%s: ni %p lsta is NULL\n", __func__, ni));
+ KASSERT(lsta->state == IEEE80211_STA_ASSOC, ("%s: lsta %p state not "
+ "ASSOC: %#x\n", __func__, lsta, lsta->state));
+ error = lkpi_80211_mo_sta_state(hw, vif, lsta, IEEE80211_STA_AUTH);
+ if (error != 0) {
+ ic_printf(vap->iv_ic, "%s:%d: mo_sta_state(AUTH) "
+ "failed: %d\n", __func__, __LINE__, error);
+ goto out;
+ }
+
+ lkpi_lsta_dump(lsta, ni, __func__, __LINE__);
+
+#if 0
+ /* Update bss info (bss_info_changed) (assoc, aid, ..). */
+ lkpi_disassoc(sta, vif, lhw);
+#endif
+
+ error = EALREADY;
+out:
+ wiphy_unlock(hw->wiphy);
+ IEEE80211_LOCK(vap->iv_ic);
+outni:
+ return (error);
+}
+
+static int
+lkpi_sta_run_to_init(struct ieee80211vap *vap, enum ieee80211_state nstate, int arg)
+{
+ struct lkpi_hw *lhw;
+ struct ieee80211_hw *hw;
+ struct lkpi_vif *lvif;
+ struct ieee80211_vif *vif;
+ struct ieee80211_node *ni;
+ struct lkpi_sta *lsta;
+ struct ieee80211_sta *sta;
+ struct ieee80211_prep_tx_info prep_tx_info;
+ enum ieee80211_bss_changed bss_changed;
+ int error;
+
+ lhw = vap->iv_ic->ic_softc;
+ hw = LHW_TO_HW(lhw);
+ lvif = VAP_TO_LVIF(vap);
+ vif = LVIF_TO_VIF(lvif);
+
+ IEEE80211_UNLOCK(vap->iv_ic);
+ wiphy_lock(hw->wiphy);
+
+ LKPI_80211_LVIF_LOCK(lvif);
+#ifdef LINUXKPI_DEBUG_80211
+ /* XXX-BZ KASSERT later; state going down so no action. */
+ if (lvif->lvif_bss == NULL)
+ ic_printf(vap->iv_ic, "%s:%d: lvif %p vap %p iv_bss %p lvif_bss %p "
+ "lvif_bss->ni %p synched %d\n", __func__, __LINE__,
+ lvif, vap, vap->iv_bss, lvif->lvif_bss,
+ (lvif->lvif_bss != NULL) ? lvif->lvif_bss->ni : NULL,
+ lvif->lvif_bss_synched);
+#endif
+ lsta = lvif->lvif_bss;
+ LKPI_80211_LVIF_UNLOCK(lvif);
+ KASSERT(lsta != NULL && lsta->ni != NULL, ("%s: lsta %p ni %p "
+ "lvif %p vap %p\n", __func__,
+ lsta, (lsta != NULL) ? lsta->ni : NULL, lvif, vap));
+
+ ni = lsta->ni; /* Reference held for lvif_bss. */
+ sta = LSTA_TO_STA(lsta);
+
+ lkpi_lsta_dump(lsta, ni, __func__, __LINE__);
+
+ /* flush, drop. */
+ lkpi_80211_mo_flush(hw, vif, nitems(sta->txq), true);
+
+ IMPROVE("What are the proper conditions for DEAUTH_NEED_MGD_TX_PREP?");
+ if (ieee80211_hw_check(hw, DEAUTH_NEED_MGD_TX_PREP) &&
+ !lsta->in_mgd) {
+ memset(&prep_tx_info, 0, sizeof(prep_tx_info));
+ prep_tx_info.duration = PREP_TX_INFO_DURATION;
+ prep_tx_info.was_assoc = true;
+ lkpi_80211_mo_mgd_prepare_tx(hw, vif, &prep_tx_info);
+ lsta->in_mgd = true;
+ }
+
+ wiphy_unlock(hw->wiphy);
+ IEEE80211_LOCK(vap->iv_ic);
+
+ /* Call iv_newstate first so we get potential DISASSOC packet out. */
+ error = lvif->iv_newstate(vap, nstate, arg);
+ if (error != 0) {
+ ic_printf(vap->iv_ic, "%s:%d: iv_newstate(%p, %d, %d) "
+ "failed: %d\n", __func__, __LINE__, vap, nstate, arg, error);
+ goto outni;
+ }
+
+ IEEE80211_UNLOCK(vap->iv_ic);
+
+ /* Ensure the packets get out. */
+ lkpi_80211_flush_tx(lhw, lsta);
+
+ wiphy_lock(hw->wiphy);
+
+ lkpi_lsta_dump(lsta, ni, __func__, __LINE__);
+
+ /* Wake tx queues to get packet(s) out. */
+ lkpi_wake_tx_queues(hw, sta, false, true);
+
+ /* flush, no drop */
+ lkpi_80211_mo_flush(hw, vif, nitems(sta->txq), false);
+
+ /* End mgd_complete_tx. */
+ if (lsta->in_mgd) {
+ memset(&prep_tx_info, 0, sizeof(prep_tx_info));
+ prep_tx_info.success = false;
+ prep_tx_info.was_assoc = true;
+ lkpi_80211_mo_mgd_complete_tx(hw, vif, &prep_tx_info);
+ lsta->in_mgd = false;
+ }
+
+ /* sync_rx_queues */
+ lkpi_80211_mo_sync_rx_queues(hw);
+
+ /* sta_pre_rcu_remove */
+ lkpi_80211_mo_sta_pre_rcu_remove(hw, vif, sta);
+
+ /* Take the station down. */
+
+ /* Adjust sta and change state (from AUTHORIZED) to ASSOC. */
+ KASSERT(lsta != NULL, ("%s: ni %p lsta is NULL\n", __func__, ni));
+ KASSERT(lsta->state == IEEE80211_STA_AUTHORIZED, ("%s: lsta %p state not "
+ "AUTHORIZED: %#x\n", __func__, lsta, lsta->state));
+ error = lkpi_80211_mo_sta_state(hw, vif, lsta, IEEE80211_STA_ASSOC);
+ if (error != 0) {
+ ic_printf(vap->iv_ic, "%s:%d: mo_sta_state(ASSOC) "
+ "failed: %d\n", __func__, __LINE__, error);
+ goto out;
+ }
+
+ lkpi_lsta_dump(lsta, ni, __func__, __LINE__);
+
+#ifdef LKPI_80211_HW_CRYPTO
+ if (lkpi_hwcrypto) {
+ /*
+ * In theory we only need to do this if we changed assoc.
+ * If we were not assoc, there should be no keys and we
+ * should not be here.
+ */
+#ifdef notyet
+ KASSERT((bss_changed & BSS_CHANGED_ASSOC) != 0, ("%s: "
+ "trying to remove keys but were not assoc: %#010jx, lvif %p\n",
+ __func__, (uintmax_t)bss_changed, lvif));
+#endif
+ error = lkpi_sta_del_keys(hw, vif, lsta);
+ if (error != 0) {
+ ic_printf(vap->iv_ic, "%s:%d: lkpi_sta_del_keys "
+ "failed: %d\n", __func__, __LINE__, error);
+ /*
+ * Either drv/fw will crash or cleanup itself,
+ * otherwise net80211 will delete the keys (at a
+ * less appropriate time).
+ */
+ /* goto out; */
+ }
+ }
+#endif
+
+ /* Update sta_state (ASSOC to AUTH). */
+ KASSERT(lsta != NULL, ("%s: ni %p lsta is NULL\n", __func__, ni));
+ KASSERT(lsta->state == IEEE80211_STA_ASSOC, ("%s: lsta %p state not "
+ "ASSOC: %#x\n", __func__, lsta, lsta->state));
+ error = lkpi_80211_mo_sta_state(hw, vif, lsta, IEEE80211_STA_AUTH);
+ if (error != 0) {
+ ic_printf(vap->iv_ic, "%s:%d: mo_sta_state(AUTH) "
+ "failed: %d\n", __func__, __LINE__, error);
+ goto out;
+ }
+
+ lkpi_lsta_dump(lsta, ni, __func__, __LINE__);
+
+ /* Update sta and change state (from AUTH) to NONE. */
+ KASSERT(lsta != NULL, ("%s: ni %p lsta is NULL\n", __func__, ni));
+ KASSERT(lsta->state == IEEE80211_STA_AUTH, ("%s: lsta %p state not "
+ "AUTH: %#x\n", __func__, lsta, lsta->state));
+ error = lkpi_80211_mo_sta_state(hw, vif, lsta, IEEE80211_STA_NONE);
+ if (error != 0) {
+ ic_printf(vap->iv_ic, "%s:%d: mo_sta_state(NONE) "
+ "failed: %d\n", __func__, __LINE__, error);
+ goto out;
+ }
+
+ bss_changed = 0;
+ /*
+ * Start updating bss info (bss_info_changed) (assoc, aid, ..).
+ *
+ * One would expect this to happen when going off AUTHORIZED.
+ * See comment there; removes the sta from fw if not careful
+ * (bss_info_changed() change is executed right away).
+ *
+ * We need to do this now, before sta changes to IEEE80211_STA_NOTEXIST
+ * as otherwise drivers (iwlwifi at least) will silently not remove
+ * the sta from the firmware and when we will add a new one trigger
+ * a fw assert.
+ *
+ * The order which works best so far avoiding early removal or silent
+ * non-removal seems to be (for iwlwifi::mld-mac80211.c cases;
+ * the iwlwifi:mac80211.c case still to be tested):
+ * 1) lkpi_disassoc(): set vif->cfg.assoc = false (aid=0 side effect here)
+ * 2) call the last sta_state update -> IEEE80211_STA_NOTEXIST
+ * (removes the sta given assoc is false)
+ * 3) add the remaining BSS_CHANGED changes and call bss_info_changed()
+ * 4) call unassign_vif_chanctx
+ * 5) call lkpi_hw_conf_idle
+ * 6) call remove_chanctx
+ *
+ * Note: vif->driver_flags & IEEE80211_VIF_REMOVE_AP_AFTER_DISASSOC
+ * might change this.
+ */
+ bss_changed |= lkpi_disassoc(sta, vif, lhw);
+
+ lkpi_lsta_dump(lsta, ni, __func__, __LINE__);
+
+ /* Adjust sta and change state (from NONE) to NOTEXIST. */
+ KASSERT(lsta != NULL, ("%s: ni %p lsta is NULL\n", __func__, ni));
+ KASSERT(lsta->state == IEEE80211_STA_NONE, ("%s: lsta %p state not "
+ "NONE: %#x, nstate %d arg %d\n", __func__, lsta, lsta->state, nstate, arg));
+ error = lkpi_80211_mo_sta_state(hw, vif, lsta, IEEE80211_STA_NOTEXIST);
+ if (error != 0) {
+ IMPROVE("do we need to undo the chan ctx?");
+ ic_printf(vap->iv_ic, "%s:%d: mo_sta_state(NOTEXIST) "
+ "failed: %d\n", __func__, __LINE__, error);
+ goto out;
+ }
+
+ lkpi_lsta_remove(lsta, lvif);
+
+ lkpi_lsta_dump(lsta, ni, __func__, __LINE__); /* sta no longer save to use. */
+
+ IMPROVE("Any bss_info changes to announce?");
+ vif->bss_conf.qos = 0;
+ bss_changed |= BSS_CHANGED_QOS;
+ vif->cfg.ssid_len = 0;
+ memset(vif->cfg.ssid, '\0', sizeof(vif->cfg.ssid));
+ bss_changed |= BSS_CHANGED_BSSID;
+ vif->bss_conf.use_short_preamble = false;
+ vif->bss_conf.qos = false;
+ /* XXX BSS_CHANGED_???? */
+ vif->bss_conf.dtim_period = 0; /* go back to 0. */
+ bss_changed |= BSS_CHANGED_BEACON_INFO;
+ lkpi_80211_mo_bss_info_changed(hw, vif, &vif->bss_conf, bss_changed);
+
+ LKPI_80211_LVIF_LOCK(lvif);
+ /* Remove ni reference for this cache of lsta. */
+ lvif->lvif_bss = NULL;
+ lvif->lvif_bss_synched = false;
+ LKPI_80211_LVIF_UNLOCK(lvif);
+
+ /* conf_tx */
+
+ lkpi_remove_chanctx(hw, vif);
+
+ error = EALREADY;
+out:
+ wiphy_unlock(hw->wiphy);
+ IEEE80211_LOCK(vap->iv_ic);
+ if (error == EALREADY) {
+ /*
+ * We do this outside the wiphy lock as net80211::node_free() may call
+ * into crypto code to delete keys and we have a recursed on
+ * non-recursive sx panic. Also only do this if we get here w/o error.
+ *
+ * The very last release the reference on the ni for the ni/lsta on
+ * lvif->lvif_bss. Upon return from this both ni and lsta are invalid
+ * and potentially freed.
+ */
+ ieee80211_free_node(ni);
+ }
+outni:
+ return (error);
+}
+
+static int
+lkpi_sta_run_to_scan(struct ieee80211vap *vap, enum ieee80211_state nstate, int arg)
+{
+
+ return (lkpi_sta_run_to_init(vap, nstate, arg));
+}
+
+static int
+lkpi_sta_run_to_auth(struct ieee80211vap *vap, enum ieee80211_state nstate, int arg)
+{
+ int error;
+
+ error = lkpi_sta_run_to_init(vap, nstate, arg);
+ if (error != 0 && error != EALREADY)
+ return (error);
+
+ /* At this point iv_bss is long a new node! */
+
+ error |= lkpi_sta_scan_to_auth(vap, nstate, 0);
+ return (error);
+}
+
+/* -------------------------------------------------------------------------- */
+
+/*
+ * The matches the documented state changes in net80211::sta_newstate().
+ * XXX (1) without CSA and SLEEP yet, * XXX (2) not all unhandled cases
+ * there are "invalid" (so there is a room for failure here).
+ */
+struct fsm_state {
+ /* INIT, SCAN, AUTH, ASSOC, CAC, RUN, CSA, SLEEP */
+ enum ieee80211_state ostate;
+ enum ieee80211_state nstate;
+ int (*handler)(struct ieee80211vap *, enum ieee80211_state, int);
+} sta_state_fsm[] = {
+ { IEEE80211_S_INIT, IEEE80211_S_INIT, lkpi_sta_state_do_nada },
+ { IEEE80211_S_SCAN, IEEE80211_S_INIT, lkpi_sta_state_do_nada }, /* scan_to_init */
+ { IEEE80211_S_AUTH, IEEE80211_S_INIT, lkpi_sta_auth_to_init }, /* not explicitly in sta_newstate() */
+ { IEEE80211_S_ASSOC, IEEE80211_S_INIT, lkpi_sta_assoc_to_init }, /* Send DEAUTH. */
+ { IEEE80211_S_RUN, IEEE80211_S_INIT, lkpi_sta_run_to_init }, /* Send DISASSOC. */
+
+ { IEEE80211_S_INIT, IEEE80211_S_SCAN, lkpi_sta_state_do_nada },
+ { IEEE80211_S_SCAN, IEEE80211_S_SCAN, lkpi_sta_state_do_nada },
+ { IEEE80211_S_AUTH, IEEE80211_S_SCAN, lkpi_sta_auth_to_scan },
+ { IEEE80211_S_ASSOC, IEEE80211_S_SCAN, lkpi_sta_assoc_to_scan },
+ { IEEE80211_S_RUN, IEEE80211_S_SCAN, lkpi_sta_run_to_scan }, /* Beacon miss. */
+
+ { IEEE80211_S_INIT, IEEE80211_S_AUTH, lkpi_sta_scan_to_auth }, /* Send AUTH. */
+ { IEEE80211_S_SCAN, IEEE80211_S_AUTH, lkpi_sta_scan_to_auth }, /* Send AUTH. */
+ { IEEE80211_S_AUTH, IEEE80211_S_AUTH, lkpi_sta_a_to_a }, /* Send ?AUTH. */
+ { IEEE80211_S_ASSOC, IEEE80211_S_AUTH, lkpi_sta_assoc_to_auth }, /* Send ?AUTH. */
+ { IEEE80211_S_RUN, IEEE80211_S_AUTH, lkpi_sta_run_to_auth }, /* Send ?AUTH. */
+
+ { IEEE80211_S_AUTH, IEEE80211_S_ASSOC, lkpi_sta_auth_to_assoc }, /* Send ASSOCREQ. */
+ { IEEE80211_S_ASSOC, IEEE80211_S_ASSOC, lkpi_sta_a_to_a }, /* Send ASSOCREQ. */
+ { IEEE80211_S_RUN, IEEE80211_S_ASSOC, lkpi_sta_run_to_assoc }, /* Send ASSOCREQ/REASSOCREQ. */
+
+ { IEEE80211_S_AUTH, IEEE80211_S_RUN, lkpi_sta_auth_to_run },
+ { IEEE80211_S_ASSOC, IEEE80211_S_RUN, lkpi_sta_assoc_to_run },
+ { IEEE80211_S_RUN, IEEE80211_S_RUN, lkpi_sta_state_do_nada },
+
+ /* Dummy at the end without handler. */
+ { IEEE80211_S_INIT, IEEE80211_S_INIT, NULL },
+};
+
+static int
+lkpi_iv_newstate(struct ieee80211vap *vap, enum ieee80211_state nstate, int arg)
+{
+ struct ieee80211com *ic;
+ struct lkpi_hw *lhw;
+ struct lkpi_vif *lvif;
+ struct ieee80211_vif *vif;
+ struct fsm_state *s;
+ enum ieee80211_state ostate;
+ int error;
+
+ ic = vap->iv_ic;
+ IEEE80211_LOCK_ASSERT(ic);
+ ostate = vap->iv_state;
+
+#ifdef LINUXKPI_DEBUG_80211
+ if (linuxkpi_debug_80211 & D80211_TRACE)
+ ic_printf(vap->iv_ic, "%s:%d: vap %p nstate %#x arg %#x\n",
+ __func__, __LINE__, vap, nstate, arg);
+#endif
+
+ if (vap->iv_opmode == IEEE80211_M_STA) {
+
+ lhw = ic->ic_softc;
+ lvif = VAP_TO_LVIF(vap);
+ vif = LVIF_TO_VIF(lvif);
+
+ /* No need to replicate this in most state handlers. */
+ if (nstate > IEEE80211_S_SCAN)
+ lkpi_stop_hw_scan(lhw, vif);
+
+ s = sta_state_fsm;
+
+ } else {
+ ic_printf(vap->iv_ic, "%s: only station mode currently supported: "
+ "cap %p iv_opmode %d\n", __func__, vap, vap->iv_opmode);
+ return (ENOSYS);
+ }
+
+ error = 0;
+ for (; s->handler != NULL; s++) {
+ if (ostate == s->ostate && nstate == s->nstate) {
+#ifdef LINUXKPI_DEBUG_80211
+ if (linuxkpi_debug_80211 & D80211_TRACE)
+ ic_printf(vap->iv_ic, "%s: new state %d (%s) ->"
+ " %d (%s): arg %d.\n", __func__,
+ ostate, ieee80211_state_name[ostate],
+ nstate, ieee80211_state_name[nstate], arg);
+#endif
+ error = s->handler(vap, nstate, arg);
+ break;
+ }
+ }
+ IEEE80211_LOCK_ASSERT(vap->iv_ic);
+
+ if (s->handler == NULL) {
+ IMPROVE("turn this into a KASSERT\n");
+ ic_printf(vap->iv_ic, "%s: unsupported state transition "
+ "%d (%s) -> %d (%s)\n", __func__,
+ ostate, ieee80211_state_name[ostate],
+ nstate, ieee80211_state_name[nstate]);
+ return (ENOSYS);
+ }
+
+ if (error == EALREADY) {
+#ifdef LINUXKPI_DEBUG_80211
+ if (linuxkpi_debug_80211 & D80211_TRACE)
+ ic_printf(vap->iv_ic, "%s: state transition %d (%s) -> "
+ "%d (%s): iv_newstate already handled: %d.\n",
+ __func__, ostate, ieee80211_state_name[ostate],
+ nstate, ieee80211_state_name[nstate], error);
+#endif
+ return (0);
+ }
+
+ if (error != 0) {
+ ic_printf(vap->iv_ic, "%s: error %d during state transition "
+ "%d (%s) -> %d (%s)\n", __func__, error,
+ ostate, ieee80211_state_name[ostate],
+ nstate, ieee80211_state_name[nstate]);
+ return (error);
+ }
+
+#ifdef LINUXKPI_DEBUG_80211
+ if (linuxkpi_debug_80211 & D80211_TRACE)
+ ic_printf(vap->iv_ic, "%s:%d: vap %p nstate %#x arg %#x "
+ "calling net80211 parent\n",
+ __func__, __LINE__, vap, nstate, arg);
+#endif
+
+ return (lvif->iv_newstate(vap, nstate, arg));
+}
+
+/* -------------------------------------------------------------------------- */
+
+/*
+ * We overload (*iv_update_bss) as otherwise we have cases in, e.g.,
+ * net80211::ieee80211_sta_join1() where vap->iv_bss gets replaced by a
+ * new node without us knowing and thus our ni/lsta are out of sync.
+ */
+static struct ieee80211_node *
+lkpi_iv_update_bss(struct ieee80211vap *vap, struct ieee80211_node *ni)
+{
+ struct lkpi_vif *lvif;
+ struct ieee80211_node *rni;
+
+ IEEE80211_LOCK_ASSERT(vap->iv_ic);
+
+ lvif = VAP_TO_LVIF(vap);
+
+ LKPI_80211_LVIF_LOCK(lvif);
+ lvif->lvif_bss_synched = false;
+ LKPI_80211_LVIF_UNLOCK(lvif);
+
+ rni = lvif->iv_update_bss(vap, ni);
+ return (rni);
+}
+
+#ifdef LKPI_80211_WME
+static int
+lkpi_wme_update(struct lkpi_hw *lhw, struct ieee80211vap *vap, bool planned)
+{
+ struct ieee80211com *ic;
+ struct ieee80211_hw *hw;
+ struct lkpi_vif *lvif;
+ struct ieee80211_vif *vif;
+ struct chanAccParams chp;
+ struct wmeParams wmeparr[WME_NUM_AC];
+ struct ieee80211_tx_queue_params txqp;
+ enum ieee80211_bss_changed changed;
+ int error;
+ uint16_t ac;
+
+ hw = LHW_TO_HW(lhw);
+ lockdep_assert_wiphy(hw->wiphy);
+
+ IMPROVE();
+ KASSERT(WME_NUM_AC == IEEE80211_NUM_ACS, ("%s: WME_NUM_AC %d != "
+ "IEEE80211_NUM_ACS %d\n", __func__, WME_NUM_AC, IEEE80211_NUM_ACS));
+
+ if (vap == NULL)
+ return (0);
+
+ if ((vap->iv_flags & IEEE80211_F_WME) == 0)
+ return (0);
+
+ if (lhw->ops->conf_tx == NULL)
+ return (0);
+
+ if (!planned && (vap->iv_state != IEEE80211_S_RUN)) {
+ lhw->update_wme = true;
+ return (0);
+ }
+ lhw->update_wme = false;
+
+ ic = lhw->ic;
+ ieee80211_wme_ic_getparams(ic, &chp);
+ IEEE80211_LOCK(ic);
+ for (ac = 0; ac < WME_NUM_AC; ac++)
+ wmeparr[ac] = chp.cap_wmeParams[ac];
+ IEEE80211_UNLOCK(ic);
+
+ lvif = VAP_TO_LVIF(vap);
+ vif = LVIF_TO_VIF(lvif);
+
+ /* Configure tx queues (conf_tx) & send BSS_CHANGED_QOS. */
+ for (ac = 0; ac < IEEE80211_NUM_ACS; ac++) {
+ struct wmeParams *wmep;
+
+ wmep = &wmeparr[ac];
+ bzero(&txqp, sizeof(txqp));
+ txqp.cw_min = wmep->wmep_logcwmin;
+ txqp.cw_max = wmep->wmep_logcwmax;
+ txqp.txop = wmep->wmep_txopLimit;
+ txqp.aifs = wmep->wmep_aifsn;
+ error = lkpi_80211_mo_conf_tx(hw, vif, /* link_id */0, ac, &txqp);
+ if (error != 0)
+ ic_printf(ic, "%s: conf_tx ac %u failed %d\n",
+ __func__, ac, error);
+ }
+ changed = BSS_CHANGED_QOS;
+ if (!planned)
+ lkpi_80211_mo_bss_info_changed(hw, vif, &vif->bss_conf, changed);
+
+ return (changed);
+}
+#endif
+
+static int
+lkpi_ic_wme_update(struct ieee80211com *ic)
+{
+#ifdef LKPI_80211_WME
+ struct ieee80211vap *vap;
+ struct lkpi_hw *lhw;
+ struct ieee80211_hw *hw;
+
+ IMPROVE("Use the per-VAP callback in net80211.");
+ vap = TAILQ_FIRST(&ic->ic_vaps);
+ if (vap == NULL)
+ return (0);
+
+ lhw = ic->ic_softc;
+ hw = LHW_TO_HW(lhw);
+
+ wiphy_lock(hw->wiphy);
+ lkpi_wme_update(lhw, vap, false);
+ wiphy_unlock(hw->wiphy);
+#endif
+ return (0); /* unused */
+}
+
+static void
+lkpi_iv_sta_recv_mgmt(struct ieee80211_node *ni, struct mbuf *m0,
+ int subtype, const struct ieee80211_rx_stats *rxs, int rssi, int nf)
+{
+ struct lkpi_hw *lhw;
+ struct ieee80211_hw *hw;
+ struct lkpi_vif *lvif;
+ struct ieee80211_vif *vif;
+ enum ieee80211_bss_changed bss_changed;
+
+ lvif = VAP_TO_LVIF(ni->ni_vap);
+ vif = LVIF_TO_VIF(lvif);
+
+ lvif->iv_recv_mgmt(ni, m0, subtype, rxs, rssi, nf);
+
+ switch (subtype) {
+ case IEEE80211_FC0_SUBTYPE_PROBE_RESP:
+ break;
+ case IEEE80211_FC0_SUBTYPE_BEACON:
+ /*
+ * Only count beacons when assoc. SCAN has its own logging.
+ * This is for connection/beacon loss/session protection almost
+ * over debugging when trying to get into a stable RUN state.
+ */
+ if (vif->cfg.assoc)
+ lvif->beacons++;
+ break;
+ default:
+ return;
+ }
+
+ lhw = ni->ni_ic->ic_softc;
+ hw = LHW_TO_HW(lhw);
+
+ /*
+ * If this direct call to mo_bss_info_changed will not work due to
+ * locking, see if queue_work() is fast enough.
+ */
+ bss_changed = lkpi_update_dtim_tsf(vif, ni, ni->ni_vap, __func__, __LINE__);
+ lkpi_80211_mo_bss_info_changed(hw, vif, &vif->bss_conf, bss_changed);
+}
+
+/*
+ * Change link-layer address on the vif (if the vap is not started/"UP").
+ * This can happen if a user changes 'ether' using ifconfig.
+ * The code is based on net80211/ieee80211_freebsd.c::wlan_iflladdr() but
+ * we do use a per-[l]vif event handler to be sure we exist as we
+ * cannot assume that from every vap derives a vif and we have a hard
+ * time checking based on net80211 information.
+ * Should this ever become a real problem we could add a callback function
+ * to wlan_iflladdr() to be set optionally but that would be for a
+ * single-consumer (or needs a list) -- was just too complicated for an
+ * otherwise perfect mechanism FreeBSD already provides.
+ */
+static void
+lkpi_vif_iflladdr(void *arg, struct ifnet *ifp)
+{
+ struct epoch_tracker et;
+ struct ieee80211_vif *vif;
+
+ NET_EPOCH_ENTER(et);
+ /* NB: identify vap's by if_transmit; left as an extra check. */
+ if (if_gettransmitfn(ifp) != ieee80211_vap_transmit ||
+ (if_getflags(ifp) & IFF_UP) != 0) {
+ NET_EPOCH_EXIT(et);
+ return;
+ }
+
+ vif = arg;
+ IEEE80211_ADDR_COPY(vif->bss_conf.addr, if_getlladdr(ifp));
+ NET_EPOCH_EXIT(et);
+}
+
+static struct ieee80211vap *
+lkpi_ic_vap_create(struct ieee80211com *ic, const char name[IFNAMSIZ],
+ int unit, enum ieee80211_opmode opmode, int flags,
+ const uint8_t bssid[IEEE80211_ADDR_LEN],
+ const uint8_t mac[IEEE80211_ADDR_LEN])
+{
+ struct lkpi_hw *lhw;
+ struct ieee80211_hw *hw;
+ struct lkpi_vif *lvif;
+ struct ieee80211vap *vap;
+ struct ieee80211_vif *vif;
+ struct ieee80211_tx_queue_params txqp;
+ enum ieee80211_bss_changed changed;
+ struct sysctl_oid *node;
+ size_t len;
+ int error, i;
+ uint16_t ac;
+
+ if (!TAILQ_EMPTY(&ic->ic_vaps)) /* 1 so far. Add <n> once this works. */
+ return (NULL);
+
+ lhw = ic->ic_softc;
+ hw = LHW_TO_HW(lhw);
+
+ len = sizeof(*lvif);
+ len += hw->vif_data_size; /* vif->drv_priv */
+
+ lvif = malloc(len, M_80211_VAP, M_WAITOK | M_ZERO);
+ mtx_init(&lvif->mtx, "lvif", NULL, MTX_DEF);
+ TASK_INIT(&lvif->sw_scan_task, 0, lkpi_sw_scan_task, lvif);
+ INIT_LIST_HEAD(&lvif->lsta_list);
+ lvif->lvif_bss = NULL;
+ refcount_init(&lvif->nt_unlocked, 0);
+ lvif->lvif_bss_synched = false;
+ vap = LVIF_TO_VAP(lvif);
+
+ vif = LVIF_TO_VIF(lvif);
+ memcpy(vif->addr, mac, IEEE80211_ADDR_LEN);
+ vif->p2p = false;
+ vif->probe_req_reg = false;
+ vif->type = lkpi_opmode_to_vif_type(opmode);
+ lvif->wdev.iftype = vif->type;
+ /* Need to fill in other fields as well. */
+ IMPROVE();
+
+ /* XXX-BZ hardcoded for now! */
+#if 1
+ RCU_INIT_POINTER(vif->bss_conf.chanctx_conf, NULL);
+ vif->bss_conf.vif = vif;
+ /* vap->iv_myaddr is not set until net80211::vap_setup or vap_attach. */
+ IEEE80211_ADDR_COPY(vif->bss_conf.addr, mac);
+ lvif->lvif_ifllevent = EVENTHANDLER_REGISTER(iflladdr_event,
+ lkpi_vif_iflladdr, vif, EVENTHANDLER_PRI_ANY);
+ vif->bss_conf.link_id = 0; /* Non-MLO operation. */
+ vif->bss_conf.chanreq.oper.width = NL80211_CHAN_WIDTH_20_NOHT;
+ vif->bss_conf.use_short_preamble = false; /* vap->iv_flags IEEE80211_F_SHPREAMBLE */
+ vif->bss_conf.use_short_slot = false; /* vap->iv_flags IEEE80211_F_SHSLOT */
+ vif->bss_conf.qos = false;
+ vif->bss_conf.use_cts_prot = false; /* vap->iv_protmode */
+ vif->bss_conf.ht_operation_mode = IEEE80211_HT_OP_MODE_PROTECTION_NONE;
+ vif->cfg.aid = 0;
+ vif->cfg.assoc = false;
+ vif->cfg.idle = true;
+ vif->cfg.ps = false;
+ IMPROVE("Check other fields and then figure out whats is left elsewhere of them");
+ /*
+ * We need to initialize it to something as the bss_info_changed call
+ * will try to copy from it in iwlwifi and NULL is a panic.
+ * We will set the proper one in scan_to_auth() before being assoc.
+ */
+ vif->bss_conf.bssid = ieee80211broadcastaddr;
+#endif
+#if 0
+ vif->bss_conf.dtim_period = 0; /* IEEE80211_DTIM_DEFAULT ; must stay 0. */
+ IEEE80211_ADDR_COPY(vif->bss_conf.bssid, bssid);
+ vif->bss_conf.beacon_int = ic->ic_bintval;
+ /* iwlwifi bug. */
+ if (vif->bss_conf.beacon_int < 16)
+ vif->bss_conf.beacon_int = 16;
+#endif
+
+ /* Link Config */
+ vif->link_conf[0] = &vif->bss_conf;
+ for (i = 0; i < nitems(vif->link_conf); i++) {
+ IMPROVE("more than 1 link one day");
+ }
+
+ /* Setup queue defaults; driver may override in (*add_interface). */
+ for (i = 0; i < IEEE80211_NUM_ACS; i++) {
+ if (ieee80211_hw_check(hw, QUEUE_CONTROL))
+ vif->hw_queue[i] = IEEE80211_INVAL_HW_QUEUE;
+ else if (hw->queues >= IEEE80211_NUM_ACS)
+ vif->hw_queue[i] = i;
+ else
+ vif->hw_queue[i] = 0;
+
+ /* Initialize the queue to running. Stopped? */
+ lvif->hw_queue_stopped[i] = false;
+ }
+ vif->cab_queue = IEEE80211_INVAL_HW_QUEUE;
+
+ IMPROVE();
+
+ wiphy_lock(hw->wiphy);
+ error = lkpi_80211_mo_start(hw);
+ if (error != 0) {
+ wiphy_unlock(hw->wiphy);
+ ic_printf(ic, "%s: failed to start hw: %d\n", __func__, error);
+ mtx_destroy(&lvif->mtx);
+ free(lvif, M_80211_VAP);
+ return (NULL);
+ }
+
+ error = lkpi_80211_mo_add_interface(hw, vif);
+ if (error != 0) {
+ IMPROVE(); /* XXX-BZ mo_stop()? */
+ wiphy_unlock(hw->wiphy);
+ ic_printf(ic, "%s: failed to add interface: %d\n", __func__, error);
+ mtx_destroy(&lvif->mtx);
+ free(lvif, M_80211_VAP);
+ return (NULL);
+ }
+ wiphy_unlock(hw->wiphy);
+
+ LKPI_80211_LHW_LVIF_LOCK(lhw);
+ TAILQ_INSERT_TAIL(&lhw->lvif_head, lvif, lvif_entry);
+ LKPI_80211_LHW_LVIF_UNLOCK(lhw);
+
+ /* Set bss_info. */
+ changed = 0;
+ lkpi_80211_mo_bss_info_changed(hw, vif, &vif->bss_conf, changed);
+
+ /* Configure tx queues (conf_tx), default WME & send BSS_CHANGED_QOS. */
+ IMPROVE("Hardcoded values; to fix see 802.11-2016, 9.4.2.29 EDCA Parameter Set element");
+ wiphy_lock(hw->wiphy);
+ for (ac = 0; ac < IEEE80211_NUM_ACS; ac++) {
+
+ bzero(&txqp, sizeof(txqp));
+ txqp.cw_min = 15;
+ txqp.cw_max = 1023;
+ txqp.txop = 0;
+ txqp.aifs = 2;
+ error = lkpi_80211_mo_conf_tx(hw, vif, /* link_id */0, ac, &txqp);
+ if (error != 0)
+ ic_printf(ic, "%s: conf_tx ac %u failed %d\n",
+ __func__, ac, error);
+ }
+ wiphy_unlock(hw->wiphy);
+ changed = BSS_CHANGED_QOS;
+ lkpi_80211_mo_bss_info_changed(hw, vif, &vif->bss_conf, changed);
+
+ /* Force MC init. */
+ lkpi_update_mcast_filter(ic);
+
+ ieee80211_vap_setup(ic, vap, name, unit, opmode, flags, bssid);
+
+ /* Now we have a valid vap->iv_ifp. Any checksum offloading goes below. */
+
+ IMPROVE();
+
+ /* Override with LinuxKPI method so we can drive mac80211/cfg80211. */
+ lvif->iv_newstate = vap->iv_newstate;
+ vap->iv_newstate = lkpi_iv_newstate;
+ lvif->iv_update_bss = vap->iv_update_bss;
+ vap->iv_update_bss = lkpi_iv_update_bss;
+ lvif->iv_recv_mgmt = vap->iv_recv_mgmt;
+ vap->iv_recv_mgmt = lkpi_iv_sta_recv_mgmt;
+
+#ifdef LKPI_80211_HW_CRYPTO
+ /* Key management. */
+ if (lkpi_hwcrypto && lhw->ops->set_key != NULL) {
+ vap->iv_key_set = lkpi_iv_key_set;
+ vap->iv_key_delete = lkpi_iv_key_delete;
+ vap->iv_key_update_begin = lkpi_iv_key_update_begin;
+ vap->iv_key_update_end = lkpi_iv_key_update_end;
+ }
+#endif
+
+#ifdef LKPI_80211_HT
+ /* Stay with the iv_ampdu_rxmax,limit / iv_ampdu_density defaults until later. */
+#endif
+
+ ieee80211_ratectl_init(vap);
+
+ /* Complete setup. */
+ ieee80211_vap_attach(vap, ieee80211_media_change,
+ ieee80211_media_status, mac);
+
+#ifdef LKPI_80211_HT
+ /*
+ * Modern chipset/fw/drv will do A-MPDU in drv/fw and fail
+ * to do so if they cannot do the crypto too.
+ */
+ if (!lkpi_hwcrypto && IEEE80211_CONF_AMPDU_OFFLOAD(ic))
+ vap->iv_flags_ht &= ~IEEE80211_FHT_AMPDU_RX;
+#endif
+
+ if (hw->max_listen_interval == 0)
+ hw->max_listen_interval = 7 * (ic->ic_lintval / ic->ic_bintval);
+ hw->conf.listen_interval = hw->max_listen_interval;
+ ic->ic_set_channel(ic);
+
+ /* XXX-BZ do we need to be able to update these? */
+ hw->wiphy->frag_threshold = vap->iv_fragthreshold;
+ lkpi_80211_mo_set_frag_threshold(hw, vap->iv_fragthreshold);
+ hw->wiphy->rts_threshold = vap->iv_rtsthreshold;
+ lkpi_80211_mo_set_rts_threshold(hw, vap->iv_rtsthreshold);
+ /* any others? */
+
+ /* Add per-VIF/VAP sysctls. */
+ sysctl_ctx_init(&lvif->sysctl_ctx);
+
+ node = SYSCTL_ADD_NODE(&lvif->sysctl_ctx,
+ SYSCTL_CHILDREN(&sysctl___compat_linuxkpi_80211),
+ OID_AUTO, if_name(vap->iv_ifp),
+ CTLFLAG_RD | CTLFLAG_SKIP | CTLFLAG_MPSAFE, NULL, "VIF Information");
+
+ SYSCTL_ADD_PROC(&lvif->sysctl_ctx,
+ SYSCTL_CHILDREN(node), OID_AUTO, "dump_stas",
+ CTLTYPE_STRING | CTLFLAG_RD | CTLFLAG_MPSAFE, lvif, 0,
+ lkpi_80211_dump_stas, "A", "Dump sta statistics of this vif");
+
+ IMPROVE();
+
+ return (vap);
+}
+
+void
+linuxkpi_ieee80211_unregister_hw(struct ieee80211_hw *hw)
+{
+
+ wiphy_unregister(hw->wiphy);
+ linuxkpi_ieee80211_ifdetach(hw);
+
+ IMPROVE();
+}
+
+void
+linuxkpi_ieee80211_restart_hw(struct ieee80211_hw *hw)
+{
+
+ TODO();
+}
+
+static void
+lkpi_ic_vap_delete(struct ieee80211vap *vap)
+{
+ struct ieee80211com *ic;
+ struct lkpi_hw *lhw;
+ struct ieee80211_hw *hw;
+ struct lkpi_vif *lvif;
+ struct ieee80211_vif *vif;
+
+ lvif = VAP_TO_LVIF(vap);
+ vif = LVIF_TO_VIF(lvif);
+ ic = vap->iv_ic;
+ lhw = ic->ic_softc;
+ hw = LHW_TO_HW(lhw);
+
+ EVENTHANDLER_DEREGISTER(iflladdr_event, lvif->lvif_ifllevent);
+
+ /* Clear up per-VIF/VAP sysctls. */
+ sysctl_ctx_free(&lvif->sysctl_ctx);
+
+ ieee80211_draintask(ic, &lvif->sw_scan_task);
+
+ LKPI_80211_LHW_LVIF_LOCK(lhw);
+ TAILQ_REMOVE(&lhw->lvif_head, lvif, lvif_entry);
+ LKPI_80211_LHW_LVIF_UNLOCK(lhw);
+
+ ieee80211_ratectl_deinit(vap);
+ ieee80211_vap_detach(vap);
+
+ IMPROVE("clear up other bits in this state");
+
+ lkpi_80211_mo_remove_interface(hw, vif);
+
+ /* Single VAP, so we can do this here. */
+ lkpi_80211_mo_stop(hw, false); /* XXX SUSPEND */
+
+ mtx_destroy(&lvif->mtx);
+ free(lvif, M_80211_VAP);
+}
+
+static void
+lkpi_ic_update_mcast(struct ieee80211com *ic)
+{
+ struct ieee80211vap *vap;
+ struct lkpi_hw *lhw;
+
+ lhw = ic->ic_softc;
+ if (lhw->ops->prepare_multicast == NULL ||
+ lhw->ops->configure_filter == NULL)
+ return;
+
+ LKPI_80211_LHW_MC_LOCK(lhw);
+ /* Cleanup anything on the current list. */
+ lkpi_cleanup_mcast_list_locked(lhw);
+
+ /* Build up the new list (or allmulti). */
+ if (ic->ic_allmulti == 0) {
+ TAILQ_FOREACH(vap, &ic->ic_vaps, iv_next)
+ if_foreach_llmaddr(vap->iv_ifp,
+ lkpi_ic_update_mcast_copy, &lhw->mc_list);
+ lhw->mc_all_multi = false;
+ } else {
+ lhw->mc_all_multi = true;
+ }
+ LKPI_80211_LHW_MC_UNLOCK(lhw);
+
+ lkpi_update_mcast_filter(ic);
+ TRACEOK();
+}
+
+static void
+lkpi_ic_update_promisc(struct ieee80211com *ic)
+{
+
+ UNIMPLEMENTED;
+}
+
+static void
+lkpi_ic_update_chw(struct ieee80211com *ic)
+{
+
+ UNIMPLEMENTED;
+}
+
+/* Start / stop device. */
+static void
+lkpi_ic_parent(struct ieee80211com *ic)
+{
+ struct lkpi_hw *lhw;
+ struct ieee80211_hw *hw;
+#ifdef HW_START_STOP
+ int error;
+#endif
+ bool start_all;
+
+ IMPROVE();
+
+ lhw = ic->ic_softc;
+ hw = LHW_TO_HW(lhw);
+ start_all = false;
+
+ /* IEEE80211_UNLOCK(ic); */
+ wiphy_lock(hw->wiphy);
+ if (ic->ic_nrunning > 0) {
+#ifdef HW_START_STOP
+ error = lkpi_80211_mo_start(hw);
+ if (error == 0)
+#endif
+ start_all = true;
+ } else {
+#ifdef HW_START_STOP
+ lkpi_80211_mo_stop(hw, false); /* XXX SUSPEND */
+#endif
+ }
+ wiphy_unlock(hw->wiphy);
+ /* IEEE80211_LOCK(ic); */
+
+ if (start_all)
+ ieee80211_start_all(ic);
+}
+
+bool
+linuxkpi_ieee80211_is_ie_id_in_ie_buf(const u8 ie, const u8 *ie_ids,
+ size_t ie_ids_len)
+{
+ int i;
+
+ for (i = 0; i < ie_ids_len; i++) {
+ if (ie == *ie_ids)
+ return (true);
+ }
+
+ return (false);
+}
+
+/* Return true if skipped; false if error. */
+bool
+linuxkpi_ieee80211_ie_advance(size_t *xp, const u8 *ies, size_t ies_len)
+{
+ size_t x;
+ uint8_t l;
+
+ x = *xp;
+
+ KASSERT(x < ies_len, ("%s: x %zu ies_len %zu ies %p\n",
+ __func__, x, ies_len, ies));
+ l = ies[x + 1];
+ x += 2 + l;
+
+ if (x > ies_len)
+ return (false);
+
+ *xp = x;
+ return (true);
+}
+
+static uint8_t *
+lkpi_scan_ies_add(uint8_t *p, struct ieee80211_scan_ies *scan_ies,
+ uint32_t band_mask, struct ieee80211vap *vap, struct ieee80211_hw *hw)
+{
+ struct ieee80211_supported_band *supband;
+ struct linuxkpi_ieee80211_channel *channels;
+ struct ieee80211com *ic;
+ const struct ieee80211_channel *chan;
+ const struct ieee80211_rateset *rs;
+ uint8_t *pb;
+ int band, i;
+
+ ic = vap->iv_ic;
+ for (band = 0; band < NUM_NL80211_BANDS; band++) {
+ if ((band_mask & (1 << band)) == 0)
+ continue;
+
+ supband = hw->wiphy->bands[band];
+ /*
+ * This should not happen;
+ * band_mask is a bitmask of valid bands to scan on.
+ */
+ if (supband == NULL || supband->n_channels == 0)
+ continue;
+
+ /* Find a first channel to get the mode and rates from. */
+ channels = supband->channels;
+ chan = NULL;
+ for (i = 0; i < supband->n_channels; i++) {
+ uint32_t flags;
+
+ if (channels[i].flags & IEEE80211_CHAN_DISABLED)
+ continue;
+
+ flags = 0;
+ switch (band) {
+ case NL80211_BAND_2GHZ:
+ flags |= IEEE80211_CHAN_G;
+ break;
+ case NL80211_BAND_5GHZ:
+ flags |= IEEE80211_CHAN_A;
+ break;
+ default:
+ panic("%s:%d: unupported band %d\n",
+ __func__, __LINE__, band);
+ }
+
+ chan = ieee80211_find_channel(ic,
+ channels[i].center_freq, flags);
+ if (chan != NULL)
+ break;
+ }
+
+ /* This really should not happen. */
+ if (chan == NULL)
+ continue;
+
+ pb = p;
+ rs = ieee80211_get_suprates(ic, chan); /* calls chan2mode */
+ p = ieee80211_add_rates(p, rs);
+ p = ieee80211_add_xrates(p, rs);
+
+#if defined(LKPI_80211_HT)
+ if ((vap->iv_flags_ht & IEEE80211_FHT_HT) != 0) {
+ struct ieee80211_channel *c;
+
+ c = ieee80211_ht_adjust_channel(ic, ic->ic_curchan,
+ vap->iv_flags_ht);
+ p = ieee80211_add_htcap_ch(p, vap, c);
+ }
+#endif
+#if defined(LKPI_80211_VHT)
+ if (band == NL80211_BAND_5GHZ &&
+ (vap->iv_vht_flags & IEEE80211_FVHT_VHT) != 0) {
+ struct ieee80211_channel *c;
+
+ c = ieee80211_ht_adjust_channel(ic, ic->ic_curchan,
+ vap->iv_flags_ht);
+ c = ieee80211_vht_adjust_channel(ic, c,
+ vap->iv_vht_flags);
+ p = ieee80211_add_vhtcap_ch(p, vap, c);
+ }
+#endif
+
+ scan_ies->ies[band] = pb;
+ scan_ies->len[band] = p - pb;
+ }
+
+ /* Add common_ies */
+ pb = p;
+ if ((vap->iv_flags & IEEE80211_F_WPA1) != 0 &&
+ vap->iv_wpa_ie != NULL) {
+ memcpy(p, vap->iv_wpa_ie, 2 + vap->iv_wpa_ie[1]);
+ p += 2 + vap->iv_wpa_ie[1];
+ }
+ if (vap->iv_appie_probereq != NULL) {
+ memcpy(p, vap->iv_appie_probereq->ie_data,
+ vap->iv_appie_probereq->ie_len);
+ p += vap->iv_appie_probereq->ie_len;
+ }
+ scan_ies->common_ies = pb;
+ scan_ies->common_ie_len = p - pb;
+
+ return (p);
+}
+
+static void
+lkpi_enable_hw_scan(struct lkpi_hw *lhw)
+{
+
+ if (lhw->ops->hw_scan) {
+ /*
+ * Advertise full-offload scanning.
+ *
+ * Not limiting to SINGLE_SCAN_ON_ALL_BANDS here as otherwise
+ * we essentially disable hw_scan for all drivers not setting
+ * the flag.
+ */
+ lhw->ic->ic_flags_ext |= IEEE80211_FEXT_SCAN_OFFLOAD;
+ lhw->scan_flags |= LKPI_LHW_SCAN_HW;
+ }
+}
+
+#ifndef LKPI_80211_USE_SCANLIST
+static const uint32_t chan_pri[] = {
+ 5180, 5500, 5745,
+ 5260, 5580, 5660, 5825,
+ 5220, 5300, 5540, 5620, 5700, 5785, 5865,
+ 2437, 2412, 2422, 2462, 2472, 2432, 2452
+};
+
+static int
+lkpi_scan_chan_list_idx(const struct linuxkpi_ieee80211_channel *lc)
+{
+ int i;
+
+ for (i = 0; i < nitems(chan_pri); i++) {
+ if (lc->center_freq == chan_pri[i])
+ return (i);
+ }
+
+ return (-1);
+}
+
+static int
+lkpi_scan_chan_list_comp(const struct linuxkpi_ieee80211_channel *lc1,
+ const struct linuxkpi_ieee80211_channel *lc2)
+{
+ int idx1, idx2;
+
+ /* Find index in list. */
+ idx1 = lkpi_scan_chan_list_idx(lc1);
+ idx2 = lkpi_scan_chan_list_idx(lc2);
+
+ if (idx1 == -1 && idx2 != -1)
+ return (1);
+ if (idx1 != -1 && idx2 == -1)
+ return (-1);
+
+ /* Neither on the list, use center_freq. */
+ if (idx1 == -1 && idx2 == -1)
+ return (lc1->center_freq - lc2->center_freq);
+
+ /* Whichever is first in the list. */
+ return (idx1 - idx2);
+}
+
+static void
+lkpi_scan_chan_list_resort(struct linuxkpi_ieee80211_channel **cpp, size_t nchan)
+{
+ struct linuxkpi_ieee80211_channel *lc, *nc;
+ size_t i, j;
+ int rc;
+
+ for (i = (nchan - 1); i > 0; i--) {
+ for (j = i; j > 0 ; j--) {
+ lc = *(cpp + j);
+ nc = *(cpp + j - 1);
+ rc = lkpi_scan_chan_list_comp(lc, nc);
+ if (rc < 0) {
+ *(cpp + j) = nc;
+ *(cpp + j - 1) = lc;
+ }
+ }
+ }
+}
+
+static bool
+lkpi_scan_chan(struct linuxkpi_ieee80211_channel *c,
+ struct ieee80211com *ic, bool log)
+{
+
+ if ((c->flags & IEEE80211_CHAN_DISABLED) != 0) {
+ if (log)
+ TRACE_SCAN(ic, "Skipping disabled chan "
+ "on band %s [%#x/%u/%#x]",
+ lkpi_nl80211_band_name(c->band), c->hw_value,
+ c->center_freq, c->flags);
+ return (false);
+ }
+ if (isclr(ic->ic_chan_active, ieee80211_mhz2ieee(c->center_freq,
+ lkpi_nl80211_band_to_net80211_band(c->band)))) {
+ if (log)
+ TRACE_SCAN(ic, "Skipping !active chan "
+ "on band %s [%#x/%u/%#x]",
+ lkpi_nl80211_band_name(c->band), c->hw_value,
+ c->center_freq, c->flags);
+ return (false);
+ }
+ return (true);
+}
+#endif
+
+static void
+lkpi_ic_scan_start(struct ieee80211com *ic)
+{
+ struct lkpi_hw *lhw;
+ struct ieee80211_hw *hw;
+ struct lkpi_vif *lvif;
+ struct ieee80211_vif *vif;
+ struct ieee80211_scan_state *ss;
+ struct ieee80211vap *vap;
+ int error;
+ bool is_hw_scan;
+
+ lhw = ic->ic_softc;
+ ss = ic->ic_scan;
+ vap = ss->ss_vap;
+ TRACE_SCAN(ic, "scan_flags %b", lhw->scan_flags, LKPI_LHW_SCAN_BITS);
+
+ LKPI_80211_LHW_SCAN_LOCK(lhw);
+ if ((lhw->scan_flags & LKPI_LHW_SCAN_RUNNING) != 0) {
+ /* A scan is still running. */
+ LKPI_80211_LHW_SCAN_UNLOCK(lhw);
+ TRACE_SCAN(ic, "Trying to start new scan while still running; "
+ "cancelling new net80211 scan; scan_flags %b",
+ lhw->scan_flags, LKPI_LHW_SCAN_BITS);
+ ieee80211_cancel_scan(vap);
+ return;
+ }
+ is_hw_scan = (lhw->scan_flags & LKPI_LHW_SCAN_HW) != 0;
+ LKPI_80211_LHW_SCAN_UNLOCK(lhw);
+
+#if 0
+ if (vap->iv_state != IEEE80211_S_SCAN) {
+ TODO("We need to be able to scan if not in S_SCAN");
+ TRACE_SCAN(ic, "scan_flags %b iv_state %d",
+ lhw->scan_flags, LKPI_LHW_SCAN_BITS, vap->iv_state);
+ ieee80211_cancel_scan(vap);
+ return;
+ }
+#endif
+
+ hw = LHW_TO_HW(lhw);
+ if (!is_hw_scan) {
+ /* If hw_scan is cleared clear FEXT_SCAN_OFFLOAD too. */
+ vap->iv_flags_ext &= ~IEEE80211_FEXT_SCAN_OFFLOAD;
+
+ lvif = VAP_TO_LVIF(vap);
+ vif = LVIF_TO_VIF(lvif);
+
+ if (vap->iv_state == IEEE80211_S_SCAN)
+ lkpi_hw_conf_idle(hw, false);
+
+ LKPI_80211_LHW_SCAN_LOCK(lhw);
+ lhw->scan_flags |= LKPI_LHW_SCAN_RUNNING;
+ LKPI_80211_LHW_SCAN_UNLOCK(lhw);
+
+ lkpi_update_mcast_filter(ic);
+
+ TRACE_SCAN(vap->iv_ic, "Starting SW_SCAN: scan_flags %b",
+ lhw->scan_flags, LKPI_LHW_SCAN_BITS);
+ lkpi_80211_mo_sw_scan_start(hw, vif, vif->addr);
+ /* net80211::scan_start() handled PS for us. */
+ IMPROVE();
+ /* XXX Also means it is too late to flush queues?
+ * need to check iv_sta_ps or overload? */
+ /* XXX want to adjust ss end time/ maxdwell? */
+
+ } else {
+ struct ieee80211_scan_request *hw_req;
+ struct linuxkpi_ieee80211_channel *lc, **cpp;
+ struct cfg80211_ssid *ssids;
+ struct cfg80211_scan_6ghz_params *s6gp;
+ size_t chan_len, nchan, ssids_len, s6ghzlen;
+ int band, i, ssid_count, common_ie_len;
+#ifndef LKPI_80211_USE_SCANLIST
+ int n;
+#endif
+ uint32_t band_mask;
+ uint8_t *ie, *ieend;
+ bool running;
+
+ ssid_count = min(ss->ss_nssid, hw->wiphy->max_scan_ssids);
+ ssids_len = ssid_count * sizeof(*ssids);
+ s6ghzlen = 0 * (sizeof(*s6gp)); /* XXX-BZ */
+
+ band_mask = 0;
+ nchan = 0;
+ if (ieee80211_hw_check(hw, SINGLE_SCAN_ON_ALL_BANDS)) {
+#ifdef LKPI_80211_USE_SCANLIST
+ /* Avoid net80211 scan lists until it has proper scan offload support. */
+ for (i = ss->ss_next; i < ss->ss_last; i++) {
+ nchan++;
+ band = lkpi_net80211_chan_to_nl80211_band(
+ ss->ss_chans[ss->ss_next + i]);
+ band_mask |= (1 << band);
+ }
+#else
+ /* Instead we scan for all channels all the time. */
+ for (band = 0; band < NUM_NL80211_BANDS; band++) {
+ switch (band) {
+ case NL80211_BAND_2GHZ:
+ case NL80211_BAND_5GHZ:
+ break;
+ default:
+ continue;
+ }
+ if (hw->wiphy->bands[band] != NULL) {
+ struct linuxkpi_ieee80211_channel *channels;
+ int n;
+
+ band_mask |= (1 << band);
+
+ channels = hw->wiphy->bands[band]->channels;
+ n = hw->wiphy->bands[band]->n_channels;
+ for (i = 0; i < n; i++) {
+ if (lkpi_scan_chan(&channels[i], ic, true))
+ nchan++;
+ }
+ }
+ }
+#endif
+ } else {
+ IMPROVE("individual band scans not yet supported, only scanning first band");
+ /* In theory net80211 should drive this. */
+ /* Probably we need to add local logic for now;
+ * need to deal with scan_complete
+ * and cancel_scan and keep local state.
+ * Also cut the nchan down above.
+ */
+ /* XXX-BZ ath10k does not set this but still does it? &$%^ */
+ }
+
+ chan_len = nchan * (sizeof(lc) + sizeof(*lc));
+
+ common_ie_len = 0;
+ if ((vap->iv_flags & IEEE80211_F_WPA1) != 0 &&
+ vap->iv_wpa_ie != NULL)
+ common_ie_len += vap->iv_wpa_ie[1];
+ if (vap->iv_appie_probereq != NULL)
+ common_ie_len += vap->iv_appie_probereq->ie_len;
+
+ /* We would love to check this at an earlier stage... */
+ if (common_ie_len > hw->wiphy->max_scan_ie_len) {
+ ic_printf(ic, "WARNING: %s: common_ie_len %d > "
+ "wiphy->max_scan_ie_len %d\n", __func__,
+ common_ie_len, hw->wiphy->max_scan_ie_len);
+ }
+
+ hw_req = malloc(sizeof(*hw_req) + ssids_len +
+ s6ghzlen + chan_len + lhw->supbands * lhw->scan_ie_len +
+ common_ie_len, M_LKPI80211, M_WAITOK | M_ZERO);
+
+ hw_req->req.flags = 0; /* XXX ??? */
+ /* hw_req->req.wdev */
+ hw_req->req.wiphy = hw->wiphy;
+ hw_req->req.no_cck = false; /* XXX */
+
+ /*
+ * In general setting duration[_mandatory] seems to pessimise
+ * default scanning behaviour. We only use it for BGSCANnig
+ * to keep the dwell times small.
+ * Setting duration_mandatory makes this the maximum dwell
+ * time (otherwise may be shorter). Duration is in TU.
+ */
+ if ((ic->ic_flags_ext & IEEE80211_FEXT_BGSCAN) != 0) {
+ unsigned long dwell;
+
+ if ((ic->ic_caps & IEEE80211_C_BGSCAN) == 0 ||
+ (vap->iv_flags & IEEE80211_F_BGSCAN) == 0)
+ ic_printf(ic, "BGSCAN despite off: %b, %b, %b\n",
+ ic->ic_flags_ext, IEEE80211_FEXT_BITS,
+ vap->iv_flags, IEEE80211_F_BITS,
+ ic->ic_caps, IEEE80211_C_BITS);
+
+ dwell = ss->ss_mindwell;
+ if (dwell == 0)
+ dwell = msecs_to_ticks(20);
+
+ hw_req->req.duration_mandatory = true;
+ hw_req->req.duration = TICKS_2_USEC(dwell) / 1024;
+ }
+
+#ifdef __notyet__
+ hw_req->req.flags |= NL80211_SCAN_FLAG_RANDOM_ADDR;
+ memcpy(hw_req->req.mac_addr, xxx, IEEE80211_ADDR_LEN);
+ memset(hw_req->req.mac_addr_mask, 0xxx, IEEE80211_ADDR_LEN);
+#endif
+ eth_broadcast_addr(hw_req->req.bssid);
+
+ hw_req->req.n_channels = nchan;
+ cpp = (struct linuxkpi_ieee80211_channel **)(hw_req + 1);
+ lc = (struct linuxkpi_ieee80211_channel *)(cpp + nchan);
+#ifdef LKPI_80211_USE_SCANLIST
+ for (i = 0; i < nchan; i++) {
+ *(cpp + i) =
+ (struct linuxkpi_ieee80211_channel *)(lc + i);
+ }
+ /* Avoid net80211 scan lists until it has proper scan offload support. */
+ for (i = 0; i < nchan; i++) {
+ struct ieee80211_channel *c;
+
+ c = ss->ss_chans[ss->ss_next + i];
+ lc->center_freq = c->ic_freq; /* XXX */
+ /* lc->flags */
+ lc->band = lkpi_net80211_chan_to_nl80211_band(c);
+ lc->max_power = c->ic_maxpower;
+ /* lc-> ... */
+ lc++;
+ }
+#else
+ /* Add bands in reverse order for scanning. */
+ n = 0;
+ for (band = NUM_NL80211_BANDS - 1; band >= 0; band--) {
+ struct ieee80211_supported_band *supband;
+ struct linuxkpi_ieee80211_channel *channels;
+
+ /* Band disabled for scanning? */
+ if ((band_mask & (1 << band)) == 0)
+ continue;
+
+ /* Nothing to scan in band? */
+ supband = hw->wiphy->bands[band];
+ if (supband == NULL || supband->n_channels == 0)
+ continue;
+
+ channels = supband->channels;
+ for (i = 0; i < supband->n_channels; i++) {
+ if (lkpi_scan_chan(&channels[i], ic, false))
+ *(cpp + n++) = &channels[i];
+ }
+ }
+ if (lkpi_order_scanlist)
+ lkpi_scan_chan_list_resort(cpp, nchan);
+
+ if ((linuxkpi_debug_80211 & D80211_SCAN) != 0) {
+ printf("%s:%d: %s SCAN Channel List (nchan=%zu): ",
+ __func__, __LINE__, ic->ic_name, nchan);
+ for (i = 0; i < nchan; i++) {
+ struct linuxkpi_ieee80211_channel *xc;
+
+ xc = *(cpp + i);
+ printf(" %d(%d)",
+ ieee80211_mhz2ieee(xc->center_freq,
+ lkpi_nl80211_band_to_net80211_band(
+ xc->band)),
+ xc->center_freq);
+ }
+ printf("\n");
+ }
+#endif
+
+ hw_req->req.n_ssids = ssid_count;
+ if (hw_req->req.n_ssids > 0) {
+ ssids = (struct cfg80211_ssid *)lc;
+ hw_req->req.ssids = ssids;
+ for (i = 0; i < ssid_count; i++) {
+ ssids->ssid_len = ss->ss_ssid[i].len;
+ memcpy(ssids->ssid, ss->ss_ssid[i].ssid,
+ ss->ss_ssid[i].len);
+ ssids++;
+ }
+ s6gp = (struct cfg80211_scan_6ghz_params *)ssids;
+ } else {
+ s6gp = (struct cfg80211_scan_6ghz_params *)lc;
+ }
+
+ /* 6GHz one day. */
+ hw_req->req.n_6ghz_params = 0;
+ hw_req->req.scan_6ghz_params = NULL;
+ hw_req->req.scan_6ghz = false; /* Weird boolean; not what you think. */
+ /* s6gp->... */
+
+ ie = ieend = (uint8_t *)s6gp;
+ /* Copy per-band IEs, copy common IEs */
+ ieend = lkpi_scan_ies_add(ie, &hw_req->ies, band_mask, vap, hw);
+ hw_req->req.ie = ie;
+ hw_req->req.ie_len = ieend - ie;
+ hw_req->req.scan_start = jiffies;
+
+ lvif = VAP_TO_LVIF(vap);
+ vif = LVIF_TO_VIF(lvif);
+
+ LKPI_80211_LHW_SCAN_LOCK(lhw);
+ /* Re-check under lock. */
+ running = (lhw->scan_flags & LKPI_LHW_SCAN_RUNNING) != 0;
+ if (!running) {
+ KASSERT(lhw->hw_req == NULL, ("%s: ic %p lhw %p hw_req %p "
+ "!= NULL\n", __func__, ic, lhw, lhw->hw_req));
+
+ lhw->scan_flags |= LKPI_LHW_SCAN_RUNNING;
+ lhw->hw_req = hw_req;
+ }
+ LKPI_80211_LHW_SCAN_UNLOCK(lhw);
+ if (running) {
+ free(hw_req, M_LKPI80211);
+ TRACE_SCAN(ic, "Trying to start new scan while still "
+ "running (2); cancelling new net80211 scan; "
+ "scan_flags %b",
+ lhw->scan_flags, LKPI_LHW_SCAN_BITS);
+ ieee80211_cancel_scan(vap);
+ return;
+ }
+
+ lkpi_update_mcast_filter(ic);
+ TRACE_SCAN(ic, "Starting HW_SCAN: scan_flags %b, "
+ "ie_len %d, n_ssids %d, n_chan %d, common_ie_len %d [%d, %d]",
+ lhw->scan_flags, LKPI_LHW_SCAN_BITS, hw_req->req.ie_len,
+ hw_req->req.n_ssids, hw_req->req.n_channels,
+ hw_req->ies.common_ie_len,
+ hw_req->ies.len[NL80211_BAND_2GHZ],
+ hw_req->ies.len[NL80211_BAND_5GHZ]);
+
+ error = lkpi_80211_mo_hw_scan(hw, vif, hw_req);
+ if (error != 0) {
+ bool scan_done;
+ int e;
+
+ TRACE_SCAN(ic, "hw_scan failed; scan_flags %b, error %d",
+ lhw->scan_flags, LKPI_LHW_SCAN_BITS, error);
+ ieee80211_cancel_scan(vap);
+
+ /*
+ * ieee80211_scan_completed must be called in either
+ * case of error or none. So let the free happen there
+ * and only there.
+ * That would be fine in theory but in practice drivers
+ * behave differently:
+ * ath10k does not return hw_scan until after scan_complete
+ * and can then still return an error.
+ * rtw88 can return 1 or -EBUSY without scan_complete
+ * iwlwifi can return various errors before scan starts
+ * ...
+ * So we cannot rely on that behaviour and have to check
+ * and balance between both code paths.
+ */
+ e = 0;
+ scan_done = true;
+ LKPI_80211_LHW_SCAN_LOCK(lhw);
+ if ((lhw->scan_flags & LKPI_LHW_SCAN_RUNNING) != 0) {
+
+ free(lhw->hw_req, M_LKPI80211);
+ lhw->hw_req = NULL;
+ /*
+ * The ieee80211_cancel_scan() above runs in a
+ * taskq and it may take ages for the previous
+ * scan to clear; starting a new one right away
+ * we run into the problem that the old one is
+ * still active.
+ */
+ e = msleep(lhw, &lhw->scan_mtx, 0, "lhwscanstop", hz);
+ scan_done = (lhw->scan_flags & LKPI_LHW_SCAN_RUNNING) != 0;
+
+ /*
+ * Now we can clear running if no one else did.
+ */
+ lhw->scan_flags &= ~LKPI_LHW_SCAN_RUNNING;
+ }
+ LKPI_80211_LHW_SCAN_UNLOCK(lhw);
+ lkpi_update_mcast_filter(ic);
+ if (!scan_done) {
+ ic_printf(ic, "ERROR: %s: timeout/error to wait "
+ "for ieee80211_cancel_scan: %d\n", __func__, e);
+ return;
+ }
+
+ /*
+ * XXX-SIGH magic number.
+ * rtw88 has a magic "return 1" if offloading scan is
+ * not possible. Fall back to sw scan in that case.
+ */
+ if (error == 1) {
+ /*
+ * We need to put this into some defered context
+ * the net80211 scan may not be done yet
+ * (ic_flags & IEEE80211_F_SCAN) and we cannot
+ * wait here; if we do scan_curchan_task always
+ * runs after our timeout to finalize the scan.
+ */
+ ieee80211_runtask(ic, &lvif->sw_scan_task);
+ return;
+ }
+
+ ic_printf(ic, "ERROR: %s: hw_scan returned %d\n",
+ __func__, error);
+ }
+ }
+}
+
+static void
+lkpi_sw_scan_task(void *arg, int pending __unused)
+{
+ struct lkpi_hw *lhw;
+ struct lkpi_vif *lvif;
+ struct ieee80211vap *vap;
+ struct ieee80211_scan_state *ss;
+
+ lvif = arg;
+ vap = LVIF_TO_VAP(lvif);
+ lhw = vap->iv_ic->ic_softc;
+ ss = vap->iv_ic->ic_scan;
+
+ LKPI_80211_LHW_SCAN_LOCK(lhw);
+ /*
+ * We will re-enable this at scan_end calling lkpi_enable_hw_scan().
+ * IEEE80211_FEXT_SCAN_OFFLOAD will be cleared by lkpi_ic_scan_start.
+ */
+ lhw->scan_flags &= ~LKPI_LHW_SCAN_HW;
+ LKPI_80211_LHW_SCAN_UNLOCK(lhw);
+
+ TRACE_SCAN(vap->iv_ic, "Triggering SW_SCAN: pending %d, scan_flags %b",
+ pending, lhw->scan_flags, LKPI_LHW_SCAN_BITS);
+
+ /*
+ * This will call ic_scan_start() and we will get into the right path
+ * unless other scans started in between.
+ */
+ ieee80211_start_scan(vap,
+ IEEE80211_SCAN_ONCE,
+ msecs_to_ticks(10000), /* 10000 ms (=~ 50 chan * 200 ms) */
+ ss->ss_mindwell ? ss->ss_mindwell : msecs_to_ticks(20),
+ ss->ss_maxdwell ? ss->ss_maxdwell : msecs_to_ticks(200),
+ vap->iv_des_nssid, vap->iv_des_ssid);
+}
+
+static void
+lkpi_ic_scan_end(struct ieee80211com *ic)
+{
+ struct lkpi_hw *lhw;
+ bool is_hw_scan;
+
+ lhw = ic->ic_softc;
+ TRACE_SCAN(ic, "scan_flags %b", lhw->scan_flags, LKPI_LHW_SCAN_BITS);
+
+ LKPI_80211_LHW_SCAN_LOCK(lhw);
+ if ((lhw->scan_flags & LKPI_LHW_SCAN_RUNNING) == 0) {
+ LKPI_80211_LHW_SCAN_UNLOCK(lhw);
+ return;
+ }
+ is_hw_scan = (lhw->scan_flags & LKPI_LHW_SCAN_HW) != 0;
+ LKPI_80211_LHW_SCAN_UNLOCK(lhw);
+
+ if (!is_hw_scan) {
+ struct ieee80211_scan_state *ss;
+ struct ieee80211vap *vap;
+ struct ieee80211_hw *hw;
+ struct lkpi_vif *lvif;
+ struct ieee80211_vif *vif;
+
+ ss = ic->ic_scan;
+ vap = ss->ss_vap;
+ hw = LHW_TO_HW(lhw);
+ lvif = VAP_TO_LVIF(vap);
+ vif = LVIF_TO_VIF(lvif);
+
+ lkpi_80211_mo_sw_scan_complete(hw, vif);
+
+ /* Send PS to stop buffering if n80211 does not for us? */
+
+ if (vap->iv_state == IEEE80211_S_SCAN)
+ lkpi_hw_conf_idle(hw, true);
+ }
+
+ /*
+ * In case we disabled the hw_scan in lkpi_ic_scan_start() and
+ * switched to swscan, re-enable hw_scan if available.
+ */
+ lkpi_enable_hw_scan(lhw);
+
+ LKPI_80211_LHW_SCAN_LOCK(lhw);
+ wakeup(lhw);
+ LKPI_80211_LHW_SCAN_UNLOCK(lhw);
+}
+
+static void
+lkpi_ic_scan_curchan(struct ieee80211_scan_state *ss,
+ unsigned long maxdwell)
+{
+ struct lkpi_hw *lhw;
+ bool is_hw_scan;
+
+ lhw = ss->ss_ic->ic_softc;
+ TRACE_SCAN(ss->ss_ic, "scan_flags %b chan %d maxdwell %lu",
+ lhw->scan_flags, LKPI_LHW_SCAN_BITS,
+ ss->ss_ic->ic_curchan->ic_ieee, maxdwell);
+
+ LKPI_80211_LHW_SCAN_LOCK(lhw);
+ is_hw_scan = (lhw->scan_flags & LKPI_LHW_SCAN_HW) != 0;
+ LKPI_80211_LHW_SCAN_UNLOCK(lhw);
+ if (!is_hw_scan)
+ lhw->ic_scan_curchan(ss, maxdwell);
+}
+
+static void
+lkpi_ic_scan_mindwell(struct ieee80211_scan_state *ss)
+{
+ struct lkpi_hw *lhw;
+ bool is_hw_scan;
+
+ lhw = ss->ss_ic->ic_softc;
+ TRACE_SCAN(ss->ss_ic, "scan_flags %b chan %d mindwell %lu",
+ lhw->scan_flags, LKPI_LHW_SCAN_BITS,
+ ss->ss_ic->ic_curchan->ic_ieee, ss->ss_mindwell);
+
+ LKPI_80211_LHW_SCAN_LOCK(lhw);
+ is_hw_scan = (lhw->scan_flags & LKPI_LHW_SCAN_HW) != 0;
+ LKPI_80211_LHW_SCAN_UNLOCK(lhw);
+ if (!is_hw_scan)
+ lhw->ic_scan_mindwell(ss);
+}
+
+static void
+lkpi_ic_set_channel(struct ieee80211com *ic)
+{
+ struct lkpi_hw *lhw;
+ struct ieee80211_hw *hw;
+ struct ieee80211_channel *c;
+ struct linuxkpi_ieee80211_channel *chan;
+ int error;
+ bool hw_scan_running;
+
+ lhw = ic->ic_softc;
+
+ /* If we do not support (*config)() save us the work. */
+ if (lhw->ops->config == NULL)
+ return;
+
+ /* If we have a hw_scan running do not switch channels. */
+ LKPI_80211_LHW_SCAN_LOCK(lhw);
+ hw_scan_running =
+ (lhw->scan_flags & (LKPI_LHW_SCAN_RUNNING|LKPI_LHW_SCAN_HW)) ==
+ (LKPI_LHW_SCAN_RUNNING|LKPI_LHW_SCAN_HW);
+ LKPI_80211_LHW_SCAN_UNLOCK(lhw);
+ if (hw_scan_running)
+ return;
+
+ c = ic->ic_curchan;
+ if (c == NULL || c == IEEE80211_CHAN_ANYC) {
+ ic_printf(ic, "%s: c %p ops->config %p\n", __func__,
+ c, lhw->ops->config);
+ return;
+ }
+
+ chan = lkpi_find_lkpi80211_chan(lhw, c);
+ if (chan == NULL) {
+ ic_printf(ic, "%s: c %p chan %p\n", __func__,
+ c, chan);
+ return;
+ }
+
+ /* XXX max power for scanning? */
+ IMPROVE();
+
+ hw = LHW_TO_HW(lhw);
+ cfg80211_chandef_create(&hw->conf.chandef, chan,
+#ifdef LKPI_80211_HT
+ (ic->ic_flags_ht & IEEE80211_FHT_HT) ? NL80211_CHAN_HT20 :
+#endif
+ NL80211_CHAN_NO_HT);
+
+ error = lkpi_80211_mo_config(hw, IEEE80211_CONF_CHANGE_CHANNEL);
+ if (error != 0 && error != EOPNOTSUPP) {
+ ic_printf(ic, "ERROR: %s: config %#0x returned %d\n",
+ __func__, IEEE80211_CONF_CHANGE_CHANNEL, error);
+ /* XXX should we unroll to the previous chandef? */
+ IMPROVE();
+ } else {
+ /* Update radiotap channels as well. */
+ lhw->rtap_tx.wt_chan_freq = htole16(c->ic_freq);
+ lhw->rtap_tx.wt_chan_flags = htole16(c->ic_flags);
+ lhw->rtap_rx.wr_chan_freq = htole16(c->ic_freq);
+ lhw->rtap_rx.wr_chan_flags = htole16(c->ic_flags);
+ }
+
+ /* Currently PS is hard coded off! Not sure it belongs here. */
+ IMPROVE();
+ if (ieee80211_hw_check(hw, SUPPORTS_PS) &&
+ (hw->conf.flags & IEEE80211_CONF_PS) != 0) {
+ hw->conf.flags &= ~IEEE80211_CONF_PS;
+ error = lkpi_80211_mo_config(hw, IEEE80211_CONF_CHANGE_PS);
+ if (error != 0 && error != EOPNOTSUPP)
+ ic_printf(ic, "ERROR: %s: config %#0x returned "
+ "%d\n", __func__, IEEE80211_CONF_CHANGE_PS,
+ error);
+ }
+}
+
+static struct ieee80211_node *
+lkpi_ic_node_alloc(struct ieee80211vap *vap,
+ const uint8_t mac[IEEE80211_ADDR_LEN])
+{
+ struct ieee80211com *ic;
+ struct lkpi_hw *lhw;
+ struct ieee80211_node *ni;
+ struct ieee80211_hw *hw;
+ struct lkpi_sta *lsta;
+
+ ic = vap->iv_ic;
+ lhw = ic->ic_softc;
+
+ /* We keep allocations de-coupled so we can deal with the two worlds. */
+ if (lhw->ic_node_alloc == NULL)
+ return (NULL);
+
+ ni = lhw->ic_node_alloc(vap, mac);
+ if (ni == NULL)
+ return (NULL);
+
+ hw = LHW_TO_HW(lhw);
+ lsta = lkpi_lsta_alloc(vap, mac, hw, ni);
+ if (lsta == NULL) {
+ if (lhw->ic_node_free != NULL)
+ lhw->ic_node_free(ni);
+ return (NULL);
+ }
+
+ return (ni);
+}
+
+static int
+lkpi_ic_node_init(struct ieee80211_node *ni)
+{
+ struct ieee80211com *ic;
+ struct lkpi_hw *lhw;
+ int error;
+
+ ic = ni->ni_ic;
+ lhw = ic->ic_softc;
+
+ if (lhw->ic_node_init != NULL) {
+ error = lhw->ic_node_init(ni);
+ if (error != 0)
+ return (error);
+ }
+
+ /* XXX-BZ Sync other state over. */
+ IMPROVE();
+
+ return (0);
+}
+
+static void
+lkpi_ic_node_cleanup(struct ieee80211_node *ni)
+{
+ struct ieee80211com *ic;
+ struct lkpi_hw *lhw;
+
+ ic = ni->ni_ic;
+ lhw = ic->ic_softc;
+
+ /* XXX-BZ remove from driver, ... */
+ IMPROVE();
+
+ if (lhw->ic_node_cleanup != NULL)
+ lhw->ic_node_cleanup(ni);
+}
+
+static void
+lkpi_ic_node_free(struct ieee80211_node *ni)
+{
+ struct ieee80211com *ic;
+ struct lkpi_hw *lhw;
+ struct lkpi_sta *lsta;
+
+ ic = ni->ni_ic;
+ lhw = ic->ic_softc;
+ lsta = ni->ni_drv_data;
+
+ /* KASSERT lsta is not NULL here. Print ni/ni__refcnt. */
+
+ /*
+ * Pass in the original ni just in case of error we could check that
+ * it is the same as lsta->ni.
+ */
+ lkpi_lsta_free(lsta, ni);
+
+ if (lhw->ic_node_free != NULL)
+ lhw->ic_node_free(ni);
+}
+
+/*
+ * lkpi_xmit() called from both the (*ic_raw_xmit) as well as the (*ic_transmit)
+ * call path.
+ * Unfortunately they have slightly different invariants. See
+ * ieee80211_raw_output() and ieee80211_parent_xmitpkt().
+ * Both take care of the ni reference in case of error, and otherwise during
+ * the callback after transmit.
+ * The difference is that in case of error (*ic_raw_xmit) needs us to release
+ * the mbuf, while (*ic_transmit) will free the mbuf itself.
+ */
+static int
+lkpi_xmit(struct ieee80211_node *ni, struct mbuf *m,
+ const struct ieee80211_bpf_params *params __unused,
+ bool freem)
+{
+ struct lkpi_sta *lsta;
+ int error;
+
+ lsta = ni->ni_drv_data;
+ LKPI_80211_LSTA_TXQ_LOCK(lsta);
+#if 0
+ if (!lsta->added_to_drv || !lsta->txq_ready) {
+#else
+ /*
+ * Backout this part of 886653492945f which breaks rtw88 or
+ * in general drivers without (*sta_state)() but only the
+ * legacy fallback to (*sta_add)().
+ */
+ if (!lsta->txq_ready) {
+#endif
+ LKPI_80211_LSTA_TXQ_UNLOCK(lsta);
+ if (freem)
+ m_free(m);
+ return (ENETDOWN);
+ }
+
+ /* Queue the packet and enqueue the task to handle it. */
+ error = mbufq_enqueue(&lsta->txq, m);
+ if (error != 0) {
+ LKPI_80211_LSTA_TXQ_UNLOCK(lsta);
+ if (freem)
+ m_free(m);
+#ifdef LINUXKPI_DEBUG_80211
+ if (linuxkpi_debug_80211 & D80211_TRACE_TX)
+ ic_printf(ni->ni_ic, "%s: mbufq_enqueue failed: %d\n",
+ __func__, error);
+#endif
+ return (ENETDOWN);
+ }
+ taskqueue_enqueue(taskqueue_thread, &lsta->txq_task);
+ LKPI_80211_LSTA_TXQ_UNLOCK(lsta);
+
+#ifdef LINUXKPI_DEBUG_80211
+ if (linuxkpi_debug_80211 & D80211_TRACE_TX)
+ printf("%s:%d lsta %p ni %p %6D mbuf_qlen %d\n",
+ __func__, __LINE__, lsta, ni, ni->ni_macaddr, ":",
+ mbufq_len(&lsta->txq));
+#endif
+
+ return (0);
+}
+
+static int
+lkpi_ic_raw_xmit(struct ieee80211_node *ni, struct mbuf *m,
+ const struct ieee80211_bpf_params *params __unused)
+{
+ return (lkpi_xmit(ni, m, NULL, true));
+}
+
+#ifdef LKPI_80211_HW_CRYPTO
+/*
+ * This is a bit of a hack given we know we are operating on a
+ * single frame and we know that hardware will deal with it.
+ * But otherwise the enmic bit and the encrypt bit need to be
+ * decoupled.
+ */
+static int
+lkpi_hw_crypto_prepare_tkip(struct ieee80211_key *k,
+ struct ieee80211_key_conf *kc, struct sk_buff *skb)
+{
+ struct ieee80211_hdr *hdr;
+ uint32_t hlen, hdrlen;
+ uint8_t *p;
+
+ /*
+ * TKIP only happens on data.
+ */
+ hdr = (void *)skb->data;
+ if (!ieee80211_is_data_present(hdr->frame_control))
+ return (0);
+
+ /*
+ * "enmic" (though we do not do that).
+ */
+ /* any conditions to not apply this? */
+ if (skb_tailroom(skb) < k->wk_cipher->ic_miclen)
+ return (ENOBUFS);
+
+ p = skb_put(skb, k->wk_cipher->ic_miclen);
+ if ((kc->flags & IEEE80211_KEY_FLAG_PUT_MIC_SPACE) != 0)
+ goto encrypt;
+
+ /*
+ * (*enmic) which we hopefully do not have to do with hw accel.
+ * That means if we make it here we have a problem.
+ */
+ TODO("(*enmic)");
+ return (ENXIO);
+
+encrypt:
+ /*
+ * "encrypt" (though we do not do that).
+ */
+ /*
+ * Check if we have anything to do as requested by driver
+ * or if we are done?
+ */
+ if ((kc->flags & IEEE80211_KEY_FLAG_PUT_IV_SPACE) == 0 &&
+ (kc->flags & IEEE80211_KEY_FLAG_GENERATE_IV) == 0)
+ return (0);
+
+ hlen = k->wk_cipher->ic_header;
+ if (skb_headroom(skb) < hlen)
+ return (ENOBUFS);
+
+ hdr = (void *)skb->data;
+ hdrlen = ieee80211_hdrlen(hdr->frame_control);
+ p = skb_push(skb, hlen);
+ memmove(p, p + hlen, hdrlen);
+
+ /* If driver request space only we are done. */
+ if ((kc->flags & IEEE80211_KEY_FLAG_PUT_IV_SPACE) != 0)
+ return (0);
+
+ p += hdrlen;
+ k->wk_cipher->ic_setiv(k, p);
+
+ /* If we make it hear we do sw encryption. */
+ TODO("sw encrypt");
+ return (ENXIO);
+}
+
+static int
+lkpi_hw_crypto_prepare_ccmp(struct ieee80211_key *k,
+ struct ieee80211_key_conf *kc, struct sk_buff *skb)
+{
+ struct ieee80211_hdr *hdr;
+ uint32_t hlen, hdrlen;
+ uint8_t *p;
+
+ hdr = (void *)skb->data;
+
+ /*
+ * Check if we have anythig to do as requested by driver
+ * or if we are done?
+ */
+ if ((kc->flags & IEEE80211_KEY_FLAG_PUT_IV_SPACE) == 0 &&
+ (kc->flags & IEEE80211_KEY_FLAG_GENERATE_IV) == 0 &&
+ /* MFP */
+ !((kc->flags & IEEE80211_KEY_FLAG_GENERATE_IV_MGMT) != 0 &&
+ ieee80211_is_mgmt(hdr->frame_control)))
+ return (0);
+
+ hlen = k->wk_cipher->ic_header;
+ if (skb_headroom(skb) < hlen)
+ return (ENOBUFS);
+
+ hdrlen = ieee80211_hdrlen(hdr->frame_control);
+ p = skb_push(skb, hlen);
+ memmove(p, p + hlen, hdrlen);
+
+ /* If driver request space only we are done. */
+ if ((kc->flags & IEEE80211_KEY_FLAG_PUT_IV_SPACE) != 0)
+ return (0);
+
+ p += hdrlen;
+ k->wk_cipher->ic_setiv(k, p);
+
+ return (0);
+}
+
+static int
+lkpi_hw_crypto_prepare(struct lkpi_sta *lsta, struct ieee80211_key *k,
+ struct sk_buff *skb)
+{
+ struct ieee80211_tx_info *info;
+ struct ieee80211_key_conf *kc;
+
+ KASSERT(lsta != NULL, ("%s: lsta is NULL", __func__));
+ KASSERT(k != NULL, ("%s: key is NULL", __func__));
+ KASSERT(skb != NULL, ("%s: skb is NULL", __func__));
+
+ kc = lsta->kc[k->wk_keyix];
+
+ info = IEEE80211_SKB_CB(skb);
+ info->control.hw_key = kc;
+
+ /* MUST NOT happen. KASSERT? */
+ if (kc == NULL) {
+ ic_printf(lsta->ni->ni_ic, "%s: lsta %p k %p skb %p, "
+ "kc is NULL on hw crypto offload\n", __func__, lsta, k, skb);
+ return (ENXIO);
+ }
+
+ switch (kc->cipher) {
+ case WLAN_CIPHER_SUITE_TKIP:
+ return (lkpi_hw_crypto_prepare_tkip(k, kc, skb));
+ case WLAN_CIPHER_SUITE_CCMP:
+ return (lkpi_hw_crypto_prepare_ccmp(k, kc, skb));
+ case WLAN_CIPHER_SUITE_GCMP:
+ return (lkpi_hw_crypto_prepare_ccmp(k, kc, skb));
+ case WLAN_CIPHER_SUITE_WEP40:
+ case WLAN_CIPHER_SUITE_WEP104:
+ case WLAN_CIPHER_SUITE_CCMP_256:
+ case WLAN_CIPHER_SUITE_GCMP_256:
+ case WLAN_CIPHER_SUITE_AES_CMAC:
+ case WLAN_CIPHER_SUITE_BIP_CMAC_256:
+ case WLAN_CIPHER_SUITE_BIP_GMAC_128:
+ case WLAN_CIPHER_SUITE_BIP_GMAC_256:
+ default:
+ ic_printf(lsta->ni->ni_ic, "%s: lsta %p k %p kc %p skb %p, "
+ "unsupported cipher suite %u (%s)\n", __func__, lsta, k, kc,
+ skb, kc->cipher, lkpi_cipher_suite_to_name(kc->cipher));
+ return (EOPNOTSUPP);
+ }
+}
+
+static uint8_t
+lkpi_hw_crypto_tailroom(struct lkpi_sta *lsta, struct ieee80211_key *k)
+{
+ struct ieee80211_key_conf *kc;
+
+ kc = lsta->kc[k->wk_keyix];
+ if (kc == NULL)
+ return (0);
+
+ IMPROVE("which other flags need tailroom?");
+ if (kc->flags & (IEEE80211_KEY_FLAG_PUT_MIC_SPACE))
+ return (32); /* Large enough to hold everything and pow2. */
+
+ return (0);
+}
+#endif
+
+static void
+lkpi_80211_txq_tx_one(struct lkpi_sta *lsta, struct mbuf *m)
+{
+ struct ieee80211_node *ni;
+ struct ieee80211_frame *wh;
+ struct ieee80211_key *k;
+ struct sk_buff *skb;
+ struct ieee80211com *ic;
+ struct lkpi_hw *lhw;
+ struct ieee80211_hw *hw;
+ struct lkpi_vif *lvif;
+ struct ieee80211_vif *vif;
+ struct ieee80211_channel *c;
+ struct ieee80211_tx_control control;
+ struct ieee80211_tx_info *info;
+ struct ieee80211_sta *sta;
+ struct ieee80211_hdr *hdr;
+ struct lkpi_txq *ltxq;
+ void *buf;
+ ieee80211_keyix keyix;
+ uint8_t ac, tid, tailroom;
+
+ M_ASSERTPKTHDR(m);
+#ifdef LINUXKPI_DEBUG_80211
+ if (linuxkpi_debug_80211 & D80211_TRACE_TX_DUMP)
+ hexdump(mtod(m, const void *), m->m_len, "RAW TX (plain) ", 0);
+#endif
+
+ ni = lsta->ni;
+ k = NULL;
+ keyix = IEEE80211_KEYIX_NONE;
+ wh = mtod(m, struct ieee80211_frame *);
+ if (wh->i_fc[1] & IEEE80211_FC1_PROTECTED) {
+
+#ifdef LKPI_80211_HW_CRYPTO
+ if (lkpi_hwcrypto) {
+ k = ieee80211_crypto_get_txkey(ni, m);
+ if (k != NULL && lsta->kc[k->wk_keyix] != NULL)
+ keyix = k->wk_keyix;
+ }
+#endif
+
+ /* Encrypt the frame if need be. */
+ if (keyix == IEEE80211_KEYIX_NONE) {
+ /* Retrieve key for TX && do software encryption. */
+ k = ieee80211_crypto_encap(ni, m);
+ if (k == NULL) {
+ ieee80211_free_node(ni);
+ m_freem(m);
+ return;
+ }
+ }
+ }
+
+ ic = ni->ni_ic;
+ lhw = ic->ic_softc;
+ hw = LHW_TO_HW(lhw);
+ c = ni->ni_chan;
+
+ if (ieee80211_radiotap_active_vap(ni->ni_vap)) {
+ struct lkpi_radiotap_tx_hdr *rtap;
+
+ rtap = &lhw->rtap_tx;
+ rtap->wt_flags = 0;
+ if (k != NULL)
+ rtap->wt_flags |= IEEE80211_RADIOTAP_F_WEP;
+ if (m->m_flags & M_FRAG)
+ rtap->wt_flags |= IEEE80211_RADIOTAP_F_FRAG;
+ IMPROVE();
+ rtap->wt_rate = 0;
+ if (c != NULL && c != IEEE80211_CHAN_ANYC) {
+ rtap->wt_chan_freq = htole16(c->ic_freq);
+ rtap->wt_chan_flags = htole16(c->ic_flags);
+ }
+
+ ieee80211_radiotap_tx(ni->ni_vap, m);
+ }
+
+#ifdef LKPI_80211_HW_CRYPTO
+ if (lkpi_hwcrypto && keyix != IEEE80211_KEYIX_NONE)
+ tailroom = lkpi_hw_crypto_tailroom(lsta, k);
+ else
+#endif
+ tailroom = 0;
+
+ /*
+ * net80211 should handle hw->extra_tx_headroom.
+ * Though for as long as we are copying we don't mind.
+ * XXX-BZ rtw88 asks for too much headroom for ipv6+tcp:
+ * https://lists.freebsd.org/archives/freebsd-transport/2022-February/000012.html
+ */
+ skb = dev_alloc_skb(hw->extra_tx_headroom + tailroom + m->m_pkthdr.len);
+ if (skb == NULL) {
+ static uint8_t skb_alloc_failures = 0;
+
+ if (skb_alloc_failures++ == 0) {
+ int tid;
+
+ sta = LSTA_TO_STA(lsta);
+ ic_printf(ic, "ERROR %s: skb alloc failed %d + %d, lsta %p sta %p ni %p\n",
+ __func__, hw->extra_tx_headroom, m->m_pkthdr.len, lsta, sta, ni);
+ for (tid = 0; tid < nitems(sta->txq); tid++) {
+ if (sta->txq[tid] == NULL)
+ continue;
+ ltxq = TXQ_TO_LTXQ(sta->txq[tid]);
+ ic_printf(ic, " tid %d ltxq %p seen_dequeue %d stopped %d skb_queue_len %u\n",
+ tid, ltxq, ltxq->seen_dequeue, ltxq->stopped, skb_queue_len(&ltxq->skbq));
+ }
+ }
+ ieee80211_free_node(ni);
+ m_freem(m);
+ return;
+ }
+ skb_reserve(skb, hw->extra_tx_headroom);
+
+ /* XXX-BZ we need a SKB version understanding mbuf. */
+ /* Save the mbuf for ieee80211_tx_complete(). */
+ skb->m_free_func = lkpi_ieee80211_free_skb_mbuf;
+ skb->m = m;
+#if 0
+ skb_put_data(skb, m->m_data, m->m_pkthdr.len);
+#else
+ buf = skb_put(skb, m->m_pkthdr.len);
+ m_copydata(m, 0, m->m_pkthdr.len, buf);
+#endif
+ /* Save the ni. */
+ m->m_pkthdr.PH_loc.ptr = ni;
+
+ lvif = VAP_TO_LVIF(ni->ni_vap);
+ vif = LVIF_TO_VIF(lvif);
+
+ hdr = (void *)skb->data;
+ tid = linuxkpi_ieee80211_get_tid(hdr, true);
+ if (tid == IEEE80211_NONQOS_TID) { /* == IEEE80211_NUM_TIDS */
+ if (!ieee80211_is_data(hdr->frame_control)) {
+ /* MGMT and CTRL frames go on TID 7/VO. */
+ skb->priority = 7;
+ ac = IEEE80211_AC_VO;
+ } else {
+ /* Other non-QOS traffic goes to BE. */
+ /* Contrary to net80211 we MUST NOT promote M_EAPOL. */
+ skb->priority = 0;
+ ac = IEEE80211_AC_BE;
+ }
+ } else {
+ skb->priority = tid & IEEE80211_QOS_CTL_TID_MASK;
+ ac = ieee80211e_up_to_ac[tid & 7];
+ }
+ skb_set_queue_mapping(skb, ac);
+
+ info = IEEE80211_SKB_CB(skb);
+ info->flags |= IEEE80211_TX_CTL_REQ_TX_STATUS;
+ /* Slight delay; probably only happens on scanning so fine? */
+ if (c == NULL || c == IEEE80211_CHAN_ANYC)
+ c = ic->ic_curchan;
+ info->band = lkpi_net80211_chan_to_nl80211_band(c);
+ info->hw_queue = vif->hw_queue[ac];
+ if (m->m_flags & M_EAPOL)
+ info->control.flags |= IEEE80211_TX_CTRL_PORT_CTRL_PROTO;
+ info->control.vif = vif;
+ /* XXX-BZ info->control.rates */
+#ifdef __notyet__
+#ifdef LKPI_80211_HT
+ info->control.rts_cts_rate_idx=
+ info->control.use_rts= /* RTS */
+ info->control.use_cts_prot= /* RTS/CTS*/
+#endif
+#endif
+
+ sta = LSTA_TO_STA(lsta);
+#ifdef LKPI_80211_HW_CRYPTO
+ if (lkpi_hwcrypto && keyix != IEEE80211_KEYIX_NONE) {
+ int error;
+
+ error = lkpi_hw_crypto_prepare(lsta, k, skb);
+ if (error != 0) {
+ /*
+ * We only have to free the skb which will free the
+ * mbuf and release the reference on the ni.
+ */
+ dev_kfree_skb(skb);
+ return;
+ }
+ }
+#endif
+
+ IMPROVE();
+
+ ltxq = NULL;
+ if (!ieee80211_is_data_present(hdr->frame_control)) {
+ if (vif->type == NL80211_IFTYPE_STATION &&
+ lsta->added_to_drv &&
+ sta->txq[IEEE80211_NUM_TIDS] != NULL)
+ ltxq = TXQ_TO_LTXQ(sta->txq[IEEE80211_NUM_TIDS]);
+ } else if (lsta->added_to_drv &&
+ sta->txq[skb->priority] != NULL) {
+ ltxq = TXQ_TO_LTXQ(sta->txq[skb->priority]);
+ }
+ if (ltxq == NULL)
+ goto ops_tx;
+
+ KASSERT(ltxq != NULL, ("%s: lsta %p sta %p m %p skb %p "
+ "ltxq %p != NULL\n", __func__, lsta, sta, m, skb, ltxq));
+
+ LKPI_80211_LTXQ_LOCK(ltxq);
+ skb_queue_tail(&ltxq->skbq, skb);
+#ifdef LINUXKPI_DEBUG_80211
+ if (linuxkpi_debug_80211 & D80211_TRACE_TX)
+ printf("%s:%d mo_wake_tx_queue :: %d %lu lsta %p sta %p "
+ "ni %p %6D skb %p lxtq %p { qlen %u, ac %d tid %u } "
+ "WAKE_TX_Q ac %d prio %u qmap %u\n",
+ __func__, __LINE__,
+ curthread->td_tid, jiffies,
+ lsta, sta, ni, ni->ni_macaddr, ":", skb, ltxq,
+ skb_queue_len(&ltxq->skbq), ltxq->txq.ac,
+ ltxq->txq.tid, ac, skb->priority, skb->qmap);
+#endif
+ LKPI_80211_LTXQ_UNLOCK(ltxq);
+ wiphy_lock(hw->wiphy);
+ lkpi_80211_mo_wake_tx_queue(hw, &ltxq->txq);
+ wiphy_unlock(hw->wiphy);
+ return;
+
+ops_tx:
+#ifdef LINUXKPI_DEBUG_80211
+ if (linuxkpi_debug_80211 & D80211_TRACE_TX)
+ printf("%s:%d mo_tx :: lsta %p sta %p ni %p %6D skb %p "
+ "TX ac %d prio %u qmap %u\n",
+ __func__, __LINE__, lsta, sta, ni, ni->ni_macaddr, ":",
+ skb, ac, skb->priority, skb->qmap);
+#endif
+ memset(&control, 0, sizeof(control));
+ control.sta = sta;
+ wiphy_lock(hw->wiphy);
+ lkpi_80211_mo_tx(hw, &control, skb);
+ wiphy_unlock(hw->wiphy);
+}
+
+static void
+lkpi_80211_txq_task(void *ctx, int pending)
+{
+ struct lkpi_sta *lsta;
+ struct mbufq mq;
+ struct mbuf *m;
+ bool shall_tx;
+
+ lsta = ctx;
+
+#ifdef LINUXKPI_DEBUG_80211
+ if (linuxkpi_debug_80211 & D80211_TRACE_TX)
+ printf("%s:%d lsta %p ni %p %6D pending %d mbuf_qlen %d\n",
+ __func__, __LINE__, lsta, lsta->ni, lsta->ni->ni_macaddr, ":",
+ pending, mbufq_len(&lsta->txq));
+#endif
+
+ mbufq_init(&mq, IFQ_MAXLEN);
+
+ LKPI_80211_LSTA_TXQ_LOCK(lsta);
+ /*
+ * Do not re-check lsta->txq_ready here; we may have a pending
+ * disassoc/deauth frame still. On the contrary if txq_ready is
+ * false we do not have a valid sta anymore in the firmware so no
+ * point to try to TX.
+ * We also use txq_ready as a semaphore and will drain the txq manually
+ * if needed on our way towards SCAN/INIT in the state machine.
+ */
+#if 0
+ shall_tx = lsta->added_to_drv && lsta->txq_ready;
+#else
+ /*
+ * Backout this part of 886653492945f which breaks rtw88 or
+ * in general drivers without (*sta_state)() but only the
+ * legacy fallback to (*sta_add)().
+ */
+ shall_tx = lsta->txq_ready;
+#endif
+ if (__predict_true(shall_tx))
+ mbufq_concat(&mq, &lsta->txq);
+ /*
+ * else a state change will push the packets out manually or
+ * lkpi_lsta_free() will drain the lsta->txq and free the mbufs.
+ */
+ LKPI_80211_LSTA_TXQ_UNLOCK(lsta);
+
+ m = mbufq_dequeue(&mq);
+ while (m != NULL) {
+ lkpi_80211_txq_tx_one(lsta, m);
+ m = mbufq_dequeue(&mq);
+ }
+}
+
+static int
+lkpi_ic_transmit(struct ieee80211com *ic, struct mbuf *m)
+{
+
+ /* XXX TODO */
+ IMPROVE();
+
+ /* Quick and dirty cheating hack. */
+ struct ieee80211_node *ni;
+
+ ni = (struct ieee80211_node *)m->m_pkthdr.rcvif;
+ return (lkpi_xmit(ni, m, NULL, false));
+}
+
+#ifdef LKPI_80211_HT
+static int
+lkpi_ic_recv_action(struct ieee80211_node *ni, const struct ieee80211_frame *wh,
+ const uint8_t *frm, const uint8_t *efrm)
+{
+ struct ieee80211com *ic;
+ struct lkpi_hw *lhw;
+
+ ic = ni->ni_ic;
+ lhw = ic->ic_softc;
+
+ IMPROVE_HT("recv_action called; nothing to do in lkpi; make debugging");
+
+ return (lhw->ic_recv_action(ni, wh, frm, efrm));
+}
+
+static int
+lkpi_ic_send_action(struct ieee80211_node *ni, int category, int action, void *sa)
+{
+ struct ieee80211com *ic;
+ struct lkpi_hw *lhw;
+
+ ic = ni->ni_ic;
+ lhw = ic->ic_softc;
+
+ IMPROVE_HT("send_action called; nothing to do in lkpi; make debugging");
+
+ return (lhw->ic_send_action(ni, category, action, sa));
+}
+
+
+static int
+lkpi_ic_ampdu_enable(struct ieee80211_node *ni, struct ieee80211_tx_ampdu *tap)
+{
+ struct ieee80211com *ic;
+ struct lkpi_hw *lhw;
+
+ ic = ni->ni_ic;
+ lhw = ic->ic_softc;
+
+ IMPROVE_HT("ieee80211_ampdu_enable called; nothing to do in lkpi for now; make debugging");
+
+ return (lhw->ic_ampdu_enable(ni, tap));
+}
+
+/*
+ * (*ic_addba_request)() is called by ieee80211_ampdu_request() before
+ * calling send_action(CAT_BA, BA_ADDBA_REQUEST).
+ *
+ * NB: returns 0 on ERROR!
+ */
+static int
+lkpi_ic_addba_request(struct ieee80211_node *ni, struct ieee80211_tx_ampdu *tap,
+ int dialogtoken, int baparamset, int batimeout)
+{
+ struct ieee80211com *ic;
+ struct lkpi_hw *lhw;
+ struct ieee80211_hw *hw;
+ struct ieee80211vap *vap;
+ struct lkpi_vif *lvif;
+ struct ieee80211_vif *vif;
+ struct lkpi_sta *lsta;
+ struct ieee80211_sta *sta;
+ struct ieee80211_ampdu_params params = { };
+ int error;
+
+ ic = ni->ni_ic;
+ lhw = ic->ic_softc;
+ hw = LHW_TO_HW(lhw);
+ vap = ni->ni_vap;
+ lvif = VAP_TO_LVIF(vap);
+ vif = LVIF_TO_VIF(lvif);
+ lsta = ni->ni_drv_data;
+ sta = LSTA_TO_STA(lsta);
+
+ if (!lsta->added_to_drv) {
+ ic_printf(ic, "%s: lsta %p ni %p, sta %p not added to firmware\n",
+ __func__, lsta, ni, sta);
+ return (0);
+ }
+
+ params.sta = sta;
+ params.action = IEEE80211_AMPDU_TX_START;
+ /* Keep 0 here! */
+ params.buf_size = 0;
+ params.timeout = 0;
+ params.ssn = tap->txa_start & (IEEE80211_SEQ_RANGE-1);
+ params.tid = tap->txa_tid;
+ params.amsdu = false;
+
+ IEEE80211_UNLOCK(ic);
+ wiphy_lock(hw->wiphy);
+ error = lkpi_80211_mo_ampdu_action(hw, vif, &params);
+ wiphy_unlock(hw->wiphy);
+ IEEE80211_LOCK(ic);
+ if (error != 0) {
+ ic_printf(ic, "%s: mo_ampdu_action returned %d. ni %p tap %p\n",
+ __func__, error, ni, tap);
+ return (0);
+ }
+
+ return (lhw->ic_addba_request(ni, tap, dialogtoken, baparamset, batimeout));
+}
+
+/*
+ * (*ic_addba_response)() is called from ht_recv_action_ba_addba_response()
+ * and calls the default ieee80211_addba_response() which always returns 1.
+ *
+ * NB: No error checking in net80211!
+ * Staying with 0 is an error.
+ */
+static int
+lkpi_ic_addba_response(struct ieee80211_node *ni, struct ieee80211_tx_ampdu *tap,
+ int status, int baparamset, int batimeout)
+{
+ struct ieee80211com *ic;
+ struct lkpi_hw *lhw;
+ struct ieee80211_hw *hw;
+ struct ieee80211vap *vap;
+ struct lkpi_vif *lvif;
+ struct ieee80211_vif *vif;
+ struct lkpi_sta *lsta;
+ struct ieee80211_sta *sta;
+ struct ieee80211_ampdu_params params = { };
+ int error;
+
+ ic = ni->ni_ic;
+ lhw = ic->ic_softc;
+ hw = LHW_TO_HW(lhw);
+ vap = ni->ni_vap;
+ lvif = VAP_TO_LVIF(vap);
+ vif = LVIF_TO_VIF(lvif);
+ lsta = ni->ni_drv_data;
+ sta = LSTA_TO_STA(lsta);
+
+ if (!lsta->added_to_drv) {
+ ic_printf(ic, "%s: lsta %p ni %p, sta %p not added to firmware\n",
+ __func__, lsta, ni, sta);
+ return (0);
+ }
+
+ if (status == IEEE80211_STATUS_SUCCESS) {
+ params.sta = sta;
+ params.action = IEEE80211_AMPDU_TX_OPERATIONAL;
+ params.buf_size = tap->txa_wnd;
+ params.timeout = 0;
+ params.ssn = 0;
+ params.tid = tap->txa_tid;
+ if ((tap->txa_flags & IEEE80211_AGGR_AMSDU) != 0)
+ params.amsdu = true;
+ else
+ params.amsdu = false;
+ } else {
+ /* We need to free the allocated resources. */
+ params.sta = sta;
+ switch (status) {
+ /* params.action = FLUSH, FLUSH_CONT */
+ default:
+ params.action = IEEE80211_AMPDU_TX_STOP_CONT;
+ break;
+ }
+ params.buf_size = 0;
+ params.timeout = 0;
+ params.ssn = 0;
+ params.tid = tap->txa_tid;
+ params.amsdu = false;
+ }
+
+ IEEE80211_UNLOCK(ic);
+ wiphy_lock(hw->wiphy);
+ error = lkpi_80211_mo_ampdu_action(hw, vif, &params);
+ wiphy_unlock(hw->wiphy);
+ IEEE80211_LOCK(ic);
+ if (error != 0) {
+ ic_printf(ic, "%s: mo_ampdu_action returned %d. ni %p tap %p\n",
+ __func__, error, ni, tap);
+ return (0);
+ }
+
+ IMPROVE_HT("who unleashes the TXQ? and when?, do we need to ni->ni_txseqs[tid] = tap->txa_start & 0xfff;");
+
+ return (lhw->ic_addba_response(ni, tap, status, baparamset, batimeout));
+}
+
+/*
+ * (*ic_addba_stop)() is called from ampdu_tx_stop(), ht_recv_action_ba_delba(),
+ * and ieee80211_ampdu_stop() and calls the default ieee80211_addba_stop().
+ */
+static void
+lkpi_ic_addba_stop(struct ieee80211_node *ni, struct ieee80211_tx_ampdu *tap)
+{
+ struct ieee80211com *ic;
+ struct lkpi_hw *lhw;
+ struct ieee80211_hw *hw;
+ struct ieee80211vap *vap;
+ struct lkpi_vif *lvif;
+ struct ieee80211_vif *vif;
+ struct lkpi_sta *lsta;
+ struct ieee80211_sta *sta;
+ struct ieee80211_ampdu_params params = { };
+ int error;
+
+ ic = ni->ni_ic;
+ lhw = ic->ic_softc;
+ hw = LHW_TO_HW(lhw);
+ vap = ni->ni_vap;
+ lvif = VAP_TO_LVIF(vap);
+ vif = LVIF_TO_VIF(lvif);
+ lsta = ni->ni_drv_data;
+ sta = LSTA_TO_STA(lsta);
+
+ if (!lsta->added_to_drv) {
+ ic_printf(ic, "%s: lsta %p ni %p, sta %p not added to firmware\n",
+ __func__, lsta, ni, sta);
+ goto n80211;
+ }
+
+ /* We need to free the allocated resources. */
+ params.sta = sta;
+ IMPROVE("net80211 does not provide a reason to us");
+ params.action = IEEE80211_AMPDU_TX_STOP_CONT; /* params.action = FLUSH, FLUSH_CONT */
+ params.buf_size = 0;
+ params.timeout = 0;
+ params.ssn = 0;
+ params.tid = tap->txa_tid;
+ params.amsdu = false;
+
+ IEEE80211_UNLOCK(ic);
+ wiphy_lock(hw->wiphy);
+ error = lkpi_80211_mo_ampdu_action(hw, vif, &params);
+ wiphy_unlock(hw->wiphy);
+ IEEE80211_LOCK(ic);
+ if (error != 0) {
+ ic_printf(ic, "%s: mo_ampdu_action returned %d. ni %p tap %p\n",
+ __func__, error, ni, tap);
+ goto n80211;
+ }
+
+ IMPROVE_HT("anyting else?");
+
+n80211:
+ lhw->ic_addba_stop(ni, tap);
+}
+
+static void
+lkpi_ic_addba_response_timeout(struct ieee80211_node *ni, struct ieee80211_tx_ampdu *tap)
+{
+ struct ieee80211com *ic;
+ struct lkpi_hw *lhw;
+
+ ic = ni->ni_ic;
+ lhw = ic->ic_softc;
+
+ IMPROVE_HT();
+
+ lhw->ic_addba_response_timeout(ni, tap);
+}
+
+static void
+lkpi_ic_bar_response(struct ieee80211_node *ni, struct ieee80211_tx_ampdu *tap,
+ int status)
+{
+ struct ieee80211com *ic;
+ struct lkpi_hw *lhw;
+
+ ic = ni->ni_ic;
+ lhw = ic->ic_softc;
+
+ IMPROVE_HT();
+
+ lhw->ic_bar_response(ni, tap, status);
+}
+
+static int
+lkpi_ic_ampdu_rx_start(struct ieee80211_node *ni, struct ieee80211_rx_ampdu *rap,
+ int baparamset, int batimeout, int baseqctl)
+{
+ struct ieee80211com *ic;
+ struct lkpi_hw *lhw;
+ struct ieee80211_hw *hw;
+ struct ieee80211vap *vap;
+ struct lkpi_vif *lvif;
+ struct ieee80211_vif *vif;
+ struct lkpi_sta *lsta;
+ struct ieee80211_sta *sta;
+ struct ieee80211_ampdu_params params = { };
+ int error;
+
+ ic = ni->ni_ic;
+ lhw = ic->ic_softc;
+ hw = LHW_TO_HW(lhw);
+ vap = ni->ni_vap;
+ lvif = VAP_TO_LVIF(vap);
+ vif = LVIF_TO_VIF(lvif);
+ lsta = ni->ni_drv_data;
+ sta = LSTA_TO_STA(lsta);
+
+ IEEE80211_UNLOCK_ASSERT(ic);
+
+ if (!lsta->added_to_drv) {
+ ic_printf(ic, "%s: lsta %p ni %p vap %p, sta %p not added to firmware\n",
+ __func__, lsta, ni, vap, sta);
+ return (-ENXIO);
+ }
+
+ if (lsta->state != IEEE80211_STA_AUTHORIZED) {
+ ic_printf(ic, "%s: lsta %p ni %p vap %p, sta %p state %d not AUTHORIZED\n",
+ __func__, lsta, ni, vap, sta, lsta->state);
+ return (-ENXIO);
+ }
+
+ params.sta = sta;
+ params.action = IEEE80211_AMPDU_RX_START;
+ params.buf_size = _IEEE80211_MASKSHIFT(le16toh(baparamset), IEEE80211_BAPS_BUFSIZ);
+ if (params.buf_size == 0)
+ params.buf_size = IEEE80211_MAX_AMPDU_BUF_HT;
+ else
+ params.buf_size = min(params.buf_size, IEEE80211_MAX_AMPDU_BUF_HT);
+ if (hw->max_rx_aggregation_subframes > 0 &&
+ params.buf_size > hw->max_rx_aggregation_subframes)
+ params.buf_size = hw->max_rx_aggregation_subframes;
+ params.timeout = le16toh(batimeout);
+ params.ssn = _IEEE80211_MASKSHIFT(le16toh(baseqctl), IEEE80211_BASEQ_START);
+ params.tid = _IEEE80211_MASKSHIFT(le16toh(baparamset), IEEE80211_BAPS_TID);
+
+ /* Based on net80211::ampdu_rx_start(). */
+ if ((vap->iv_htcaps & IEEE80211_HTC_RX_AMSDU_AMPDU) &&
+ (_IEEE80211_MASKSHIFT(baparamset, IEEE80211_BAPS_AMSDU)))
+ params.amsdu = true;
+ else
+ params.amsdu = false;
+
+ wiphy_lock(hw->wiphy);
+ error = lkpi_80211_mo_ampdu_action(hw, vif, &params);
+ wiphy_unlock(hw->wiphy);
+ if (error != 0) {
+ ic_printf(ic, "%s: mo_ampdu_action returned %d. ni %p rap %p\n",
+ __func__, error, ni, rap);
+ return (error);
+ }
+
+ if (!ieee80211_hw_check(hw, SUPPORTS_REORDERING_BUFFER)) {
+ IMPROVE("%s: TODO: SUPPORTS_REORDERING_BUFFER not set; check net80211\n", __func__);
+ }
+
+ IMPROVE_HT("net80211 is missing the error check on return and assumes success");
+
+ error = lhw->ic_ampdu_rx_start(ni, rap, baparamset, batimeout, baseqctl);
+ return (error);
+}
+
+static void
+lkpi_ic_ampdu_rx_stop(struct ieee80211_node *ni, struct ieee80211_rx_ampdu *rap)
+{
+ struct ieee80211com *ic;
+ struct lkpi_hw *lhw;
+ struct ieee80211_hw *hw;
+ struct ieee80211vap *vap;
+ struct lkpi_vif *lvif;
+ struct ieee80211_vif *vif;
+ struct lkpi_sta *lsta;
+ struct ieee80211_sta *sta;
+ struct ieee80211_ampdu_params params = { };
+ int error;
+ uint8_t tid;
+ bool ic_locked;
+
+ ic = ni->ni_ic;
+ lhw = ic->ic_softc;
+
+ /*
+ * We should not (cannot) call into mac80211 ops with AMPDU_RX_STOP if
+ * we did not START. Some drivers pass it down to firmware which will
+ * simply barf and net80211 calls ieee80211_ht_node_cleanup() from
+ * ieee80211_ht_node_init() amongst others which will iterate over all
+ * tid and call ic_ampdu_rx_stop() unconditionally.
+ * XXX net80211 should probably be more "gentle" in these cases and
+ * track some state itself.
+ */
+ if ((rap->rxa_flags & IEEE80211_AGGR_RUNNING) == 0)
+ goto net80211_only;
+
+ hw = LHW_TO_HW(lhw);
+ vap = ni->ni_vap;
+ lvif = VAP_TO_LVIF(vap);
+ vif = LVIF_TO_VIF(lvif);
+ lsta = ni->ni_drv_data;
+ if (lsta == NULL) {
+ ic_printf(ic, "%s: lsta %p ni %p vap %p, lsta is NULL\n",
+ __func__, lsta, ni, vap);
+ goto net80211_only;
+ }
+ sta = LSTA_TO_STA(lsta);
+
+ if (!lsta->added_to_drv) {
+ ic_printf(ic, "%s: lsta %p ni %p vap %p, sta %p not added to firmware\n",
+ __func__, lsta, ni, vap, sta);
+ goto net80211_only;
+ }
+
+ if (lsta->state != IEEE80211_STA_AUTHORIZED) {
+ ic_printf(ic, "%s: lsta %p ni %p vap %p, sta %p state %d not AUTHORIZED\n",
+ __func__, lsta, ni, vap, sta, lsta->state);
+ goto net80211_only;
+ }
+
+ IMPROVE_HT("This really should be passed from ht_recv_action_ba_delba.");
+ for (tid = 0; tid < WME_NUM_TID; tid++) {
+ if (&ni->ni_rx_ampdu[tid] == rap)
+ break;
+ }
+ if (tid == WME_NUM_TID) {
+ ic_printf(ic, "%s: lsta %p ni %p vap %p, sta %p TID not found\n",
+ __func__, lsta, ni, vap, sta);
+ goto net80211_only;
+ }
+
+ params.sta = sta;
+ params.action = IEEE80211_AMPDU_RX_STOP;
+ params.buf_size = 0;
+ params.timeout = 0;
+ params.ssn = 0;
+ params.tid = tid;
+ params.amsdu = false;
+
+ ic_locked = IEEE80211_IS_LOCKED(ic);
+ if (ic_locked)
+ IEEE80211_UNLOCK(ic);
+ wiphy_lock(hw->wiphy);
+ error = lkpi_80211_mo_ampdu_action(hw, vif, &params);
+ wiphy_unlock(hw->wiphy);
+ if (ic_locked)
+ IEEE80211_LOCK(ic);
+ if (error != 0)
+ ic_printf(ic, "%s: mo_ampdu_action returned %d. ni %p rap %p\n",
+ __func__, error, ni, rap);
+
+net80211_only:
+ lhw->ic_ampdu_rx_stop(ni, rap);
+}
+#endif
+
+static void
+lkpi_ic_getradiocaps_ht(struct ieee80211com *ic, struct ieee80211_hw *hw,
+ uint8_t *bands, int *chan_flags, enum nl80211_band band)
+{
+#ifdef LKPI_80211_HT
+ struct ieee80211_sta_ht_cap *ht_cap;
+
+ ht_cap = &hw->wiphy->bands[band]->ht_cap;
+ if (!ht_cap->ht_supported)
+ return;
+
+ switch (band) {
+ case NL80211_BAND_2GHZ:
+ setbit(bands, IEEE80211_MODE_11NG);
+ break;
+ case NL80211_BAND_5GHZ:
+ setbit(bands, IEEE80211_MODE_11NA);
+ break;
+ default:
+ IMPROVE("Unsupported band %d", band);
+ return;
+ }
+
+ ic->ic_htcaps = IEEE80211_HTC_HT; /* HT operation */
+
+ /*
+ * Rather than manually checking each flag and
+ * translating IEEE80211_HT_CAP_ to IEEE80211_HTCAP_,
+ * simply copy the 16bits.
+ */
+ ic->ic_htcaps |= ht_cap->cap;
+
+ /* Then deal with the other flags. */
+ if (ieee80211_hw_check(hw, AMPDU_AGGREGATION))
+ ic->ic_htcaps |= IEEE80211_HTC_AMPDU;
+#ifdef __notyet__
+ if (ieee80211_hw_check(hw, TX_AMSDU))
+ ic->ic_htcaps |= IEEE80211_HTC_AMSDU;
+ if (ieee80211_hw_check(hw, SUPPORTS_AMSDU_IN_AMPDU))
+ ic->ic_htcaps |= (IEEE80211_HTC_RX_AMSDU_AMPDU |
+ IEEE80211_HTC_TX_AMSDU_AMPDU);
+#endif
+
+ IMPROVE("PS, ampdu_*, ht_cap.mcs.tx_params, ...");
+ ic->ic_htcaps |= IEEE80211_HTCAP_SMPS_OFF;
+
+ /* Only add HT40 channels if supported. */
+ if ((ic->ic_htcaps & IEEE80211_HTCAP_CHWIDTH40) != 0 &&
+ chan_flags != NULL)
+ *chan_flags |= NET80211_CBW_FLAG_HT40;
+#endif
+}
+
+static void
+lkpi_ic_getradiocaps(struct ieee80211com *ic, int maxchan,
+ int *n, struct ieee80211_channel *c)
+{
+ struct lkpi_hw *lhw;
+ struct ieee80211_hw *hw;
+ struct linuxkpi_ieee80211_channel *channels;
+ uint8_t bands[IEEE80211_MODE_BYTES];
+ int chan_flags, error, i, nchans;
+
+ /* Channels */
+ lhw = ic->ic_softc;
+ hw = LHW_TO_HW(lhw);
+
+ /* NL80211_BAND_2GHZ */
+ nchans = 0;
+ if (hw->wiphy->bands[NL80211_BAND_2GHZ] != NULL)
+ nchans = hw->wiphy->bands[NL80211_BAND_2GHZ]->n_channels;
+ if (nchans > 0) {
+ memset(bands, 0, sizeof(bands));
+ chan_flags = 0;
+ setbit(bands, IEEE80211_MODE_11B);
+ /* XXX-BZ unclear how to check for 11g. */
+
+ IMPROVE("the bitrates may have flags?");
+ setbit(bands, IEEE80211_MODE_11G);
+
+ lkpi_ic_getradiocaps_ht(ic, hw, bands, &chan_flags,
+ NL80211_BAND_2GHZ);
+
+ channels = hw->wiphy->bands[NL80211_BAND_2GHZ]->channels;
+ for (i = 0; i < nchans && *n < maxchan; i++) {
+ uint32_t nflags = 0;
+ int cflags = chan_flags;
+
+ if (channels[i].flags & IEEE80211_CHAN_DISABLED) {
+ ic_printf(ic, "%s: Skipping disabled chan "
+ "[%u/%u/%#x]\n", __func__,
+ channels[i].hw_value,
+ channels[i].center_freq, channels[i].flags);
+ continue;
+ }
+ if (channels[i].flags & IEEE80211_CHAN_NO_IR)
+ nflags |= (IEEE80211_CHAN_NOADHOC|IEEE80211_CHAN_PASSIVE);
+ if (channels[i].flags & IEEE80211_CHAN_RADAR)
+ nflags |= IEEE80211_CHAN_DFS;
+ if (channels[i].flags & IEEE80211_CHAN_NO_160MHZ)
+ cflags &= ~(NET80211_CBW_FLAG_VHT160|NET80211_CBW_FLAG_VHT80P80);
+ if (channels[i].flags & IEEE80211_CHAN_NO_80MHZ)
+ cflags &= ~NET80211_CBW_FLAG_VHT80;
+ /* XXX how to map the remaining enum ieee80211_channel_flags? */
+ if (channels[i].flags & IEEE80211_CHAN_NO_HT40)
+ cflags &= ~NET80211_CBW_FLAG_HT40;
+
+ error = ieee80211_add_channel_cbw(c, maxchan, n,
+ ieee80211_mhz2ieee(channels[i].center_freq,
+ lkpi_nl80211_band_to_net80211_band(channels[i].band)),
+ channels[i].center_freq, channels[i].max_power,
+ nflags, bands, cflags);
+ /* net80211::ENOBUFS: *n >= maxchans */
+ if (error != 0 && error != ENOBUFS)
+ ic_printf(ic, "%s: Adding chan %u/%u/%#x/%#x/%#x/%#x "
+ "returned error %d\n",
+ __func__, channels[i].hw_value,
+ channels[i].center_freq, channels[i].flags,
+ nflags, chan_flags, cflags, error);
+ if (error != 0)
+ break;
+ }
+ }
+
+ /* NL80211_BAND_5GHZ */
+ nchans = 0;
+ if (hw->wiphy->bands[NL80211_BAND_5GHZ] != NULL)
+ nchans = hw->wiphy->bands[NL80211_BAND_5GHZ]->n_channels;
+ if (nchans > 0) {
+ memset(bands, 0, sizeof(bands));
+ chan_flags = 0;
+ setbit(bands, IEEE80211_MODE_11A);
+
+ lkpi_ic_getradiocaps_ht(ic, hw, bands, &chan_flags,
+ NL80211_BAND_5GHZ);
+
+#ifdef LKPI_80211_VHT
+ if (hw->wiphy->bands[NL80211_BAND_5GHZ]->vht_cap.vht_supported) {
+
+ ic->ic_flags_ext |= IEEE80211_FEXT_VHT;
+ ic->ic_vht_cap.vht_cap_info =
+ hw->wiphy->bands[NL80211_BAND_5GHZ]->vht_cap.cap;
+ ic->ic_vht_cap.supp_mcs =
+ hw->wiphy->bands[NL80211_BAND_5GHZ]->vht_cap.vht_mcs;
+
+ setbit(bands, IEEE80211_MODE_VHT_5GHZ);
+ chan_flags |= NET80211_CBW_FLAG_VHT80;
+ if (IEEE80211_VHTCAP_SUPP_CHAN_WIDTH_IS_160MHZ(
+ ic->ic_vht_cap.vht_cap_info))
+ chan_flags |= NET80211_CBW_FLAG_VHT160;
+ if (IEEE80211_VHTCAP_SUPP_CHAN_WIDTH_IS_160_80P80MHZ(
+ ic->ic_vht_cap.vht_cap_info))
+ chan_flags |= NET80211_CBW_FLAG_VHT80P80;
+ }
+#endif
+
+ channels = hw->wiphy->bands[NL80211_BAND_5GHZ]->channels;
+ for (i = 0; i < nchans && *n < maxchan; i++) {
+ uint32_t nflags = 0;
+ int cflags = chan_flags;
+
+ if (channels[i].flags & IEEE80211_CHAN_DISABLED) {
+ ic_printf(ic, "%s: Skipping disabled chan "
+ "[%u/%u/%#x]\n", __func__,
+ channels[i].hw_value,
+ channels[i].center_freq, channels[i].flags);
+ continue;
+ }
+ if (channels[i].flags & IEEE80211_CHAN_NO_IR)
+ nflags |= (IEEE80211_CHAN_NOADHOC|IEEE80211_CHAN_PASSIVE);
+ if (channels[i].flags & IEEE80211_CHAN_RADAR)
+ nflags |= IEEE80211_CHAN_DFS;
+ if (channels[i].flags & IEEE80211_CHAN_NO_160MHZ)
+ cflags &= ~(NET80211_CBW_FLAG_VHT160|NET80211_CBW_FLAG_VHT80P80);
+ if (channels[i].flags & IEEE80211_CHAN_NO_80MHZ)
+ cflags &= ~NET80211_CBW_FLAG_VHT80;
+ /* XXX hwo to map the remaining enum ieee80211_channel_flags? */
+ if (channels[i].flags & IEEE80211_CHAN_NO_HT40)
+ cflags &= ~NET80211_CBW_FLAG_HT40;
+
+ error = ieee80211_add_channel_cbw(c, maxchan, n,
+ ieee80211_mhz2ieee(channels[i].center_freq,
+ lkpi_nl80211_band_to_net80211_band(channels[i].band)),
+ channels[i].center_freq, channels[i].max_power,
+ nflags, bands, cflags);
+ /* net80211::ENOBUFS: *n >= maxchans */
+ if (error != 0 && error != ENOBUFS)
+ ic_printf(ic, "%s: Adding chan %u/%u/%#x/%#x/%#x/%#x "
+ "returned error %d\n",
+ __func__, channels[i].hw_value,
+ channels[i].center_freq, channels[i].flags,
+ nflags, chan_flags, cflags, error);
+ if (error != 0)
+ break;
+ }
+ }
+}
+
+static void *
+lkpi_ieee80211_ifalloc(void)
+{
+ struct ieee80211com *ic;
+
+ ic = malloc(sizeof(*ic), M_LKPI80211, M_WAITOK | M_ZERO);
+
+ /* Setting these happens later when we have device information. */
+ ic->ic_softc = NULL;
+ ic->ic_name = "linuxkpi";
+
+ return (ic);
+}
+
+struct ieee80211_hw *
+linuxkpi_ieee80211_alloc_hw(size_t priv_len, const struct ieee80211_ops *ops)
+{
+ struct ieee80211_hw *hw;
+ struct lkpi_hw *lhw;
+ struct wiphy *wiphy;
+ int ac;
+
+ /* Get us and the driver data also allocated. */
+ wiphy = wiphy_new(&linuxkpi_mac80211cfgops, sizeof(*lhw) + priv_len);
+ if (wiphy == NULL)
+ return (NULL);
+
+ lhw = wiphy_priv(wiphy);
+ lhw->ops = ops;
+
+ LKPI_80211_LHW_SCAN_LOCK_INIT(lhw);
+ LKPI_80211_LHW_TXQ_LOCK_INIT(lhw);
+ spin_lock_init(&lhw->txq_lock);
+ sx_init_flags(&lhw->lvif_sx, "lhw-lvif", SX_RECURSE | SX_DUPOK);
+ LKPI_80211_LHW_MC_LOCK_INIT(lhw);
+ TAILQ_INIT(&lhw->lvif_head);
+ __hw_addr_init(&lhw->mc_list);
+ for (ac = 0; ac < IEEE80211_NUM_ACS; ac++) {
+ lhw->txq_generation[ac] = 1;
+ TAILQ_INIT(&lhw->scheduled_txqs[ac]);
+ }
+
+ /* Chanctx_conf */
+ INIT_LIST_HEAD(&lhw->lchanctx_list);
+
+ /* Deferred RX path. */
+ LKPI_80211_LHW_RXQ_LOCK_INIT(lhw);
+ TASK_INIT(&lhw->rxq_task, 0, lkpi_80211_lhw_rxq_task, lhw);
+ mbufq_init(&lhw->rxq, 32 * NAPI_POLL_WEIGHT);
+ lhw->rxq_stopped = false;
+
+ /*
+ * XXX-BZ TODO make sure there is a "_null" function to all ops
+ * not initialized.
+ */
+ hw = LHW_TO_HW(lhw);
+ hw->wiphy = wiphy;
+ hw->conf.flags |= IEEE80211_CONF_IDLE;
+ hw->priv = (void *)(lhw + 1);
+
+ /* BSD Specific. */
+ lhw->ic = lkpi_ieee80211_ifalloc();
+
+ IMPROVE();
+
+ return (hw);
+}
+
+void
+linuxkpi_ieee80211_iffree(struct ieee80211_hw *hw)
+{
+ struct lkpi_hw *lhw;
+ struct mbuf *m;
+
+ lhw = HW_TO_LHW(hw);
+ free(lhw->ic, M_LKPI80211);
+ lhw->ic = NULL;
+
+ /*
+ * Drain the deferred RX path.
+ */
+ LKPI_80211_LHW_RXQ_LOCK(lhw);
+ lhw->rxq_stopped = true;
+ LKPI_80211_LHW_RXQ_UNLOCK(lhw);
+
+ /* Drain taskq, won't be restarted due to rxq_stopped being set. */
+ while (taskqueue_cancel(taskqueue_thread, &lhw->rxq_task, NULL) != 0)
+ taskqueue_drain(taskqueue_thread, &lhw->rxq_task);
+
+ /* Flush mbufq (make sure to release ni refs!). */
+ m = mbufq_dequeue(&lhw->rxq);
+ while (m != NULL) {
+#ifdef LKPI_80211_USE_MTAG
+ struct m_tag *mtag;
+
+ mtag = m_tag_locate(m, MTAG_ABI_LKPI80211, LKPI80211_TAG_RXNI, NULL);
+ if (mtag != NULL) {
+ struct lkpi_80211_tag_rxni *rxni;
+
+ rxni = (struct lkpi_80211_tag_rxni *)(mtag + 1);
+ ieee80211_free_node(rxni->ni);
+ }
+#else
+ if (m->m_pkthdr.PH_loc.ptr != NULL) {
+ struct ieee80211_node *ni;
+
+ ni = m->m_pkthdr.PH_loc.ptr;
+ ieee80211_free_node(ni);
+ }
+#endif
+ m_freem(m);
+ m = mbufq_dequeue(&lhw->rxq);
+ }
+ KASSERT(mbufq_empty(&lhw->rxq), ("%s: lhw %p has rxq len %d != 0\n",
+ __func__, lhw, mbufq_len(&lhw->rxq)));
+ LKPI_80211_LHW_RXQ_LOCK_DESTROY(lhw);
+
+ /* Chanctx_conf. */
+ if (!list_empty_careful(&lhw->lchanctx_list)) {
+ struct lkpi_chanctx *lchanctx, *next;
+ struct ieee80211_chanctx_conf *chanctx_conf;
+
+ list_for_each_entry_safe(lchanctx, next, &lhw->lchanctx_list, entry) {
+ if (lchanctx->added_to_drv) {
+ /* In reality we should panic? */
+ chanctx_conf = &lchanctx->chanctx_conf;
+ lkpi_80211_mo_remove_chanctx(hw, chanctx_conf);
+ }
+ list_del(&lchanctx->entry);
+ free(lchanctx, M_LKPI80211);
+ }
+ }
+
+ LKPI_80211_LHW_MC_LOCK(lhw);
+ lkpi_cleanup_mcast_list_locked(lhw);
+ LKPI_80211_LHW_MC_UNLOCK(lhw);
+
+ /* Cleanup more of lhw here or in wiphy_free()? */
+ spin_lock_destroy(&lhw->txq_lock);
+ LKPI_80211_LHW_TXQ_LOCK_DESTROY(lhw);
+ LKPI_80211_LHW_SCAN_LOCK_DESTROY(lhw);
+ sx_destroy(&lhw->lvif_sx);
+ LKPI_80211_LHW_MC_LOCK_DESTROY(lhw)
+ IMPROVE();
+}
+
+void
+linuxkpi_set_ieee80211_dev(struct ieee80211_hw *hw)
+{
+ struct lkpi_hw *lhw;
+ struct ieee80211com *ic;
+ struct device *dev;
+
+ lhw = HW_TO_LHW(hw);
+ ic = lhw->ic;
+
+ /* Save the backpointer from net80211 to LinuxKPI. */
+ ic->ic_softc = lhw;
+
+ /*
+ * Set a proper name before ieee80211_ifattach() if dev is set.
+ * ath1xk also unset the dev so we need to check.
+ */
+ dev = wiphy_dev(hw->wiphy);
+ if (dev != NULL) {
+ ic->ic_name = dev_name(dev);
+ } else {
+ TODO("adjust arguments to still have the old dev or go through "
+ "the hoops of getting the bsddev from hw and detach; "
+ "or do in XXX; check ath1kx drivers");
+ }
+
+ /* XXX-BZ do we also need to set wiphy name? */
+}
+
+struct ieee80211_hw *
+linuxkpi_wiphy_to_ieee80211_hw(struct wiphy *wiphy)
+{
+ struct lkpi_hw *lhw;
+
+ lhw = wiphy_priv(wiphy);
+ return (LHW_TO_HW(lhw));
+}
+
+static void
+lkpi_radiotap_attach(struct lkpi_hw *lhw)
+{
+ struct ieee80211com *ic;
+
+ ic = lhw->ic;
+ ieee80211_radiotap_attach(ic,
+ &lhw->rtap_tx.wt_ihdr, sizeof(lhw->rtap_tx),
+ LKPI_RTAP_TX_FLAGS_PRESENT,
+ &lhw->rtap_rx.wr_ihdr, sizeof(lhw->rtap_rx),
+ LKPI_RTAP_RX_FLAGS_PRESENT);
+}
+
+int
+linuxkpi_ieee80211_ifattach(struct ieee80211_hw *hw)
+{
+ struct ieee80211com *ic;
+ struct lkpi_hw *lhw;
+ int band, i;
+
+ lhw = HW_TO_LHW(hw);
+ ic = lhw->ic;
+
+ /* We do it this late as wiphy->dev should be set for the name. */
+ lhw->workq = alloc_ordered_workqueue(wiphy_name(hw->wiphy), 0);
+ if (lhw->workq == NULL)
+ return (-EAGAIN);
+
+ /* XXX-BZ figure this out how they count his... */
+ if (!is_zero_ether_addr(hw->wiphy->perm_addr)) {
+ IEEE80211_ADDR_COPY(ic->ic_macaddr,
+ hw->wiphy->perm_addr);
+ } else if (hw->wiphy->n_addresses > 0) {
+ /* We take the first one. */
+ IEEE80211_ADDR_COPY(ic->ic_macaddr,
+ hw->wiphy->addresses[0].addr);
+ } else {
+ ic_printf(ic, "%s: warning, no hardware address!\n", __func__);
+ }
+
+#ifdef __not_yet__
+ /* See comment in lkpi_80211_txq_tx_one(). */
+ ic->ic_headroom = hw->extra_tx_headroom;
+#endif
+
+ ic->ic_phytype = IEEE80211_T_OFDM; /* not only, but not used */
+ ic->ic_opmode = IEEE80211_M_STA;
+
+ /* Set device capabilities. */
+ /* XXX-BZ we need to get these from linux80211/drivers and convert. */
+ ic->ic_caps =
+ IEEE80211_C_STA |
+ IEEE80211_C_MONITOR |
+ IEEE80211_C_WPA | /* WPA/RSN */
+#ifdef LKPI_80211_WME
+ IEEE80211_C_WME |
+#endif
+#if 0
+ IEEE80211_C_PMGT |
+#endif
+ IEEE80211_C_SHSLOT | /* short slot time supported */
+ IEEE80211_C_SHPREAMBLE /* short preamble supported */
+ ;
+
+#ifdef LKPI_80211_BGSCAN
+ if (lhw->ops->hw_scan)
+ ic->ic_caps |= IEEE80211_C_BGSCAN;
+#endif
+
+ lkpi_enable_hw_scan(lhw);
+
+ /* Does HW support Fragmentation offload? */
+ if (ieee80211_hw_check(hw, SUPPORTS_TX_FRAG))
+ ic->ic_flags_ext |= IEEE80211_FEXT_FRAG_OFFLOAD;
+
+ /* Does HW support full AMPDU[-TX] offload? */
+ if (ieee80211_hw_check(hw, AMPDU_AGGREGATION))
+ ic->ic_flags_ext |= IEEE80211_FEXT_AMPDU_OFFLOAD;
+#ifdef __notyet__
+ if (ieee80211_hw_check(hw, TX_AMSDU))
+ if (ieee80211_hw_check(hw, SUPPORTS_AMSDU_IN_AMPDU))
+#endif
+
+ /*
+ * The wiphy variables report bitmasks of avail antennas.
+ * (*get_antenna) get the current bitmask sets which can be
+ * altered by (*set_antenna) for some drivers.
+ * XXX-BZ will the count alone do us much good long-term in net80211?
+ */
+ if (hw->wiphy->available_antennas_rx ||
+ hw->wiphy->available_antennas_tx) {
+ uint32_t rxs, txs;
+
+ if (lkpi_80211_mo_get_antenna(hw, &txs, &rxs) == 0) {
+ ic->ic_rxstream = bitcount32(rxs);
+ ic->ic_txstream = bitcount32(txs);
+ }
+ }
+
+ ic->ic_cryptocaps = 0;
+#ifdef LKPI_80211_HW_CRYPTO
+ if (lkpi_hwcrypto && hw->wiphy->n_cipher_suites > 0) {
+ uint32_t hwciphers;
+
+ hwciphers = 0;
+ for (i = 0; i < hw->wiphy->n_cipher_suites; i++) {
+ uint32_t cs;
+
+ cs = lkpi_l80211_to_net80211_cyphers(
+ ic, hw->wiphy->cipher_suites[i]);
+ if (cs == IEEE80211_CRYPTO_TKIP) {
+ /*
+ * We do set this here. We will only find out
+ * when doing a SET_KEY operation depending on
+ * what the driver returns.
+ * net80211::ieee80211_crypto_newkey()
+ * checks this so we will have to do flags
+ * surgery later.
+ */
+ cs |= IEEE80211_CRYPTO_TKIPMIC;
+ }
+ hwciphers |= cs;
+ }
+ /*
+ * (20250415) nothing anywhere in the path checks we actually
+ * support all these in net80211.
+ * net80211 supports _256 variants but the ioctl does not.
+ */
+ IMPROVE("as net80211 grows more support, enable them");
+ hwciphers &= (IEEE80211_CRYPTO_WEP |
+ IEEE80211_CRYPTO_TKIP | IEEE80211_CRYPTO_TKIPMIC |
+ IEEE80211_CRYPTO_AES_CCM | IEEE80211_CRYPTO_AES_GCM_128);
+ /*
+ * We only support CCMP here, so further filter.
+ * Also permit TKIP if turned on.
+ */
+ hwciphers &= (IEEE80211_CRYPTO_AES_CCM |
+ IEEE80211_CRYPTO_AES_GCM_128 |
+ (lkpi_hwcrypto_tkip ? (IEEE80211_CRYPTO_TKIP |
+ IEEE80211_CRYPTO_TKIPMIC) : 0));
+ ieee80211_set_hardware_ciphers(ic, hwciphers);
+ }
+#endif
+
+ lkpi_ic_getradiocaps(ic, IEEE80211_CHAN_MAX, &ic->ic_nchans,
+ ic->ic_channels);
+
+ ieee80211_ifattach(ic);
+
+ ic->ic_update_mcast = lkpi_ic_update_mcast;
+ ic->ic_update_promisc = lkpi_ic_update_promisc;
+ ic->ic_update_chw = lkpi_ic_update_chw;
+ ic->ic_parent = lkpi_ic_parent;
+ ic->ic_scan_start = lkpi_ic_scan_start;
+ ic->ic_scan_end = lkpi_ic_scan_end;
+ ic->ic_set_channel = lkpi_ic_set_channel;
+ ic->ic_transmit = lkpi_ic_transmit;
+ ic->ic_raw_xmit = lkpi_ic_raw_xmit;
+ ic->ic_vap_create = lkpi_ic_vap_create;
+ ic->ic_vap_delete = lkpi_ic_vap_delete;
+ ic->ic_getradiocaps = lkpi_ic_getradiocaps;
+ ic->ic_wme.wme_update = lkpi_ic_wme_update;
+
+ lhw->ic_scan_curchan = ic->ic_scan_curchan;
+ ic->ic_scan_curchan = lkpi_ic_scan_curchan;
+ lhw->ic_scan_mindwell = ic->ic_scan_mindwell;
+ ic->ic_scan_mindwell = lkpi_ic_scan_mindwell;
+
+ lhw->ic_node_alloc = ic->ic_node_alloc;
+ ic->ic_node_alloc = lkpi_ic_node_alloc;
+ lhw->ic_node_init = ic->ic_node_init;
+ ic->ic_node_init = lkpi_ic_node_init;
+ lhw->ic_node_cleanup = ic->ic_node_cleanup;
+ ic->ic_node_cleanup = lkpi_ic_node_cleanup;
+ lhw->ic_node_free = ic->ic_node_free;
+ ic->ic_node_free = lkpi_ic_node_free;
+
+#ifdef LKPI_80211_HT
+ /*
+ * Only attach if the driver/firmware supports (*ampdu_action)().
+ * Otherwise it is in the hands of net80211.
+ */
+ if (lhw->ops->ampdu_action != NULL) {
+ lhw->ic_recv_action = ic->ic_recv_action;
+ ic->ic_recv_action = lkpi_ic_recv_action;
+ lhw->ic_send_action = ic->ic_send_action;
+ ic->ic_send_action = lkpi_ic_send_action;
+
+ lhw->ic_ampdu_enable = ic->ic_ampdu_enable;
+ ic->ic_ampdu_enable = lkpi_ic_ampdu_enable;
+
+ lhw->ic_addba_request = ic->ic_addba_request;
+ ic->ic_addba_request = lkpi_ic_addba_request;
+ lhw->ic_addba_response = ic->ic_addba_response;
+ ic->ic_addba_response = lkpi_ic_addba_response;
+ lhw->ic_addba_stop = ic->ic_addba_stop;
+ ic->ic_addba_stop = lkpi_ic_addba_stop;
+ lhw->ic_addba_response_timeout = ic->ic_addba_response_timeout;
+ ic->ic_addba_response_timeout = lkpi_ic_addba_response_timeout;
+
+ lhw->ic_bar_response = ic->ic_bar_response;
+ ic->ic_bar_response = lkpi_ic_bar_response;
+
+ lhw->ic_ampdu_rx_start = ic->ic_ampdu_rx_start;
+ ic->ic_ampdu_rx_start = lkpi_ic_ampdu_rx_start;
+ lhw->ic_ampdu_rx_stop = ic->ic_ampdu_rx_stop;
+ ic->ic_ampdu_rx_stop = lkpi_ic_ampdu_rx_stop;
+ }
+#endif
+
+ lkpi_radiotap_attach(lhw);
+
+ /*
+ * Assign the first possible channel for now; seems Realtek drivers
+ * expect one.
+ * Also remember the amount of bands we support and the most rates
+ * in any band so we can scale [(ext) sup rates] IE(s) accordingly.
+ */
+ lhw->supbands = lhw->max_rates = 0;
+ for (band = 0; band < NUM_NL80211_BANDS; band++) {
+ struct ieee80211_supported_band *supband;
+ struct linuxkpi_ieee80211_channel *channels;
+
+ supband = hw->wiphy->bands[band];
+ if (supband == NULL || supband->n_channels == 0)
+ continue;
+
+ lhw->supbands++;
+ lhw->max_rates = max(lhw->max_rates, supband->n_bitrates);
+
+ /* If we have a channel, we need to keep counting supbands. */
+ if (hw->conf.chandef.chan != NULL)
+ continue;
+
+ channels = supband->channels;
+ for (i = 0; i < supband->n_channels; i++) {
+
+ if (channels[i].flags & IEEE80211_CHAN_DISABLED)
+ continue;
+
+ cfg80211_chandef_create(&hw->conf.chandef, &channels[i],
+#ifdef LKPI_80211_HT
+ (ic->ic_flags_ht & IEEE80211_FHT_HT) ? NL80211_CHAN_HT20 :
+#endif
+ NL80211_CHAN_NO_HT);
+ break;
+ }
+ }
+
+ IMPROVE("see net80211::ieee80211_chan_init vs. wiphy->bands[].bitrates possibly in lkpi_ic_getradiocaps?");
+
+ /* Make sure we do not support more than net80211 is willing to take. */
+ if (lhw->max_rates > IEEE80211_RATE_MAXSIZE) {
+ ic_printf(ic, "%s: limiting max_rates %d to %d!\n", __func__,
+ lhw->max_rates, IEEE80211_RATE_MAXSIZE);
+ lhw->max_rates = IEEE80211_RATE_MAXSIZE;
+ }
+
+ /*
+ * The maximum supported bitrates on any band + size for
+ * DSSS Parameter Set give our per-band IE size.
+ * SSID is the responsibility of the driver and goes on the side.
+ * The user specified bits coming from the vap go into the
+ * "common ies" fields.
+ */
+ lhw->scan_ie_len = 2 + IEEE80211_RATE_SIZE;
+ if (lhw->max_rates > IEEE80211_RATE_SIZE)
+ lhw->scan_ie_len += 2 + (lhw->max_rates - IEEE80211_RATE_SIZE);
+
+ if (hw->wiphy->features & NL80211_FEATURE_DS_PARAM_SET_IE_IN_PROBES) {
+ /*
+ * net80211 does not seem to support the DSSS Parameter Set but
+ * some of the drivers insert it so calculate the extra fixed
+ * space in.
+ */
+ lhw->scan_ie_len += 2 + 1;
+ }
+
+#if defined(LKPI_80211_HT)
+ if ((ic->ic_htcaps & IEEE80211_HTC_HT) != 0)
+ lhw->scan_ie_len += sizeof(struct ieee80211_ie_htcap);
+#endif
+#if defined(LKPI_80211_VHT)
+ if (IEEE80211_CONF_VHT(ic))
+ lhw->scan_ie_len += 2 + sizeof(struct ieee80211_vht_cap);
+#endif
+
+ /* Reduce the max_scan_ie_len "left" by the amount we consume already. */
+ if (hw->wiphy->max_scan_ie_len > 0) {
+ if (lhw->scan_ie_len > hw->wiphy->max_scan_ie_len)
+ goto err;
+ hw->wiphy->max_scan_ie_len -= lhw->scan_ie_len;
+ }
+
+ if (bootverbose) {
+ ic_printf(ic, "netdev_features %b\n", hw->netdev_features, NETIF_F_BITS);
+ ieee80211_announce(ic);
+ }
+
+ return (0);
+err:
+ IMPROVE("TODO FIXME CLEANUP");
+ return (-EAGAIN);
+}
+
+void
+linuxkpi_ieee80211_ifdetach(struct ieee80211_hw *hw)
+{
+ struct lkpi_hw *lhw;
+ struct ieee80211com *ic;
+
+ lhw = HW_TO_LHW(hw);
+ ic = lhw->ic;
+ ieee80211_ifdetach(ic);
+}
+
+void
+linuxkpi_ieee80211_iterate_interfaces(struct ieee80211_hw *hw,
+ enum ieee80211_iface_iter flags,
+ void(*iterfunc)(void *, uint8_t *, struct ieee80211_vif *),
+ void *arg)
+{
+ struct lkpi_hw *lhw;
+ struct lkpi_vif *lvif;
+ struct ieee80211_vif *vif;
+ bool active, atomic, nin_drv;
+
+ lhw = HW_TO_LHW(hw);
+
+ if (flags & ~(IEEE80211_IFACE_ITER_NORMAL|
+ IEEE80211_IFACE_ITER_RESUME_ALL|
+ IEEE80211_IFACE_SKIP_SDATA_NOT_IN_DRIVER|
+ IEEE80211_IFACE_ITER_ACTIVE|IEEE80211_IFACE_ITER__ATOMIC)) {
+ ic_printf(lhw->ic, "XXX TODO %s flags(%#x) not yet supported.\n",
+ __func__, flags);
+ }
+
+ active = (flags & IEEE80211_IFACE_ITER_ACTIVE) != 0;
+ atomic = (flags & IEEE80211_IFACE_ITER__ATOMIC) != 0;
+ nin_drv = (flags & IEEE80211_IFACE_SKIP_SDATA_NOT_IN_DRIVER) != 0;
+
+ if (atomic)
+ LKPI_80211_LHW_LVIF_LOCK(lhw);
+ TAILQ_FOREACH(lvif, &lhw->lvif_head, lvif_entry) {
+ struct ieee80211vap *vap;
+
+ vif = LVIF_TO_VIF(lvif);
+
+ /*
+ * If we want "active" interfaces, we need to distinguish on
+ * whether the driver knows about them or not to be able to
+ * handle the "resume" case correctly. Skip the ones the
+ * driver does not know about.
+ */
+ if (active && !lvif->added_to_drv &&
+ (flags & IEEE80211_IFACE_ITER_RESUME_ALL) != 0)
+ continue;
+
+ /*
+ * If we shall skip interfaces not added to the driver do so
+ * if we haven't yet.
+ */
+ if (nin_drv && !lvif->added_to_drv)
+ continue;
+
+ /*
+ * Run the iterator function if we are either not asking
+ * asking for active only or if the VAP is "running".
+ */
+ /* XXX-BZ probably should have state in the lvif as well. */
+ vap = LVIF_TO_VAP(lvif);
+ if (!active || (vap->iv_state != IEEE80211_S_INIT))
+ iterfunc(arg, vif->addr, vif);
+ }
+ if (atomic)
+ LKPI_80211_LHW_LVIF_UNLOCK(lhw);
+}
+
+static void
+lkpi_ieee80211_iterate_keys(struct ieee80211_hw *hw, struct ieee80211_vif *vif,
+ ieee80211_keyix keyix, struct lkpi_sta *lsta,
+ void(*iterfunc)(struct ieee80211_hw *, struct ieee80211_vif *,
+ struct ieee80211_sta *, struct ieee80211_key_conf *, void *),
+ void *arg)
+{
+ if (!lsta->added_to_drv)
+ return;
+
+ if (lsta->kc[keyix] == NULL)
+ return;
+
+ iterfunc(hw, vif, LSTA_TO_STA(lsta), lsta->kc[keyix], arg);
+}
+
+void
+linuxkpi_ieee80211_iterate_keys(struct ieee80211_hw *hw,
+ struct ieee80211_vif *vif,
+ void(*iterfunc)(struct ieee80211_hw *, struct ieee80211_vif *,
+ struct ieee80211_sta *, struct ieee80211_key_conf *, void *),
+ void *arg, bool rcu)
+{
+ struct lkpi_sta *lsta;
+ struct lkpi_vif *lvif;
+
+ lvif = VIF_TO_LVIF(vif);
+
+ if (rcu) {
+ rcu_read_lock_held(); /* XXX-BZ is this correct? */
+
+ if (vif == NULL) {
+ TODO();
+ } else {
+ list_for_each_entry_rcu(lsta, &lvif->lsta_list, lsta_list) {
+ for (ieee80211_keyix keyix = 0; keyix < nitems(lsta->kc);
+ keyix++)
+ lkpi_ieee80211_iterate_keys(hw, vif,
+ keyix, lsta, iterfunc, arg);
+ }
+ }
+ } else {
+ TODO("Used by suspend/resume; order of keys as installed to "
+ "firmware is important; we'll need to rewrite some code for that");
+ lockdep_assert_wiphy(hw->wiphy);
+
+ if (vif == NULL) {
+ TODO();
+ } else {
+ list_for_each_entry(lsta, &lvif->lsta_list, lsta_list) {
+ for (ieee80211_keyix keyix = 0; keyix < nitems(lsta->kc);
+ keyix++)
+ lkpi_ieee80211_iterate_keys(hw, vif,
+ keyix, lsta, iterfunc, arg);
+ }
+ }
+ }
+}
+
+void
+linuxkpi_ieee80211_iterate_chan_contexts(struct ieee80211_hw *hw,
+ void(*iterfunc)(struct ieee80211_hw *, struct ieee80211_chanctx_conf *,
+ void *),
+ void *arg)
+{
+ struct lkpi_hw *lhw;
+ struct lkpi_chanctx *lchanctx;
+
+ KASSERT(hw != NULL && iterfunc != NULL,
+ ("%s: hw %p iterfunc %p arg %p\n", __func__, hw, iterfunc, arg));
+
+ lhw = HW_TO_LHW(hw);
+
+ rcu_read_lock();
+ list_for_each_entry_rcu(lchanctx, &lhw->lchanctx_list, entry) {
+ if (!lchanctx->added_to_drv)
+ continue;
+ iterfunc(hw, &lchanctx->chanctx_conf, arg);
+ }
+ rcu_read_unlock();
+}
+
+void
+linuxkpi_ieee80211_iterate_stations_atomic(struct ieee80211_hw *hw,
+ void (*iterfunc)(void *, struct ieee80211_sta *), void *arg)
+{
+ struct lkpi_hw *lhw;
+ struct lkpi_vif *lvif;
+ struct lkpi_sta *lsta;
+ struct ieee80211_sta *sta;
+
+ KASSERT(hw != NULL && iterfunc != NULL,
+ ("%s: hw %p iterfunc %p arg %p\n", __func__, hw, iterfunc, arg));
+
+ lhw = HW_TO_LHW(hw);
+
+ LKPI_80211_LHW_LVIF_LOCK(lhw);
+ TAILQ_FOREACH(lvif, &lhw->lvif_head, lvif_entry) {
+
+ rcu_read_lock();
+ list_for_each_entry_rcu(lsta, &lvif->lsta_list, lsta_list) {
+ if (!lsta->added_to_drv)
+ continue;
+ sta = LSTA_TO_STA(lsta);
+ iterfunc(arg, sta);
+ }
+ rcu_read_unlock();
+ }
+ LKPI_80211_LHW_LVIF_UNLOCK(lhw);
+}
+
+struct linuxkpi_ieee80211_regdomain *
+lkpi_get_linuxkpi_ieee80211_regdomain(size_t n)
+{
+ struct linuxkpi_ieee80211_regdomain *regd;
+
+ regd = kzalloc(sizeof(*regd) + n * sizeof(struct ieee80211_reg_rule),
+ GFP_KERNEL);
+ return (regd);
+}
+
+int
+linuxkpi_regulatory_set_wiphy_regd_sync(struct wiphy *wiphy,
+ struct linuxkpi_ieee80211_regdomain *regd)
+{
+ struct lkpi_hw *lhw;
+ struct ieee80211com *ic;
+ struct ieee80211_regdomain *rd;
+
+ lhw = wiphy_priv(wiphy);
+ ic = lhw->ic;
+
+ rd = &ic->ic_regdomain;
+ if (rd->isocc[0] == '\0') {
+ rd->isocc[0] = regd->alpha2[0];
+ rd->isocc[1] = regd->alpha2[1];
+ }
+
+ TODO();
+ /* XXX-BZ finish the rest. */
+
+ return (0);
+}
+
+void
+linuxkpi_ieee80211_scan_completed(struct ieee80211_hw *hw,
+ struct cfg80211_scan_info *info)
+{
+ struct lkpi_hw *lhw;
+ struct ieee80211com *ic;
+ struct ieee80211_scan_state *ss;
+
+ lhw = wiphy_priv(hw->wiphy);
+ ic = lhw->ic;
+ ss = ic->ic_scan;
+
+ TRACE_SCAN(ic, "scan_flags %b info { %ju, %6D, aborted %d }",
+ lhw->scan_flags, LKPI_LHW_SCAN_BITS,
+ (uintmax_t)info->scan_start_tsf, info->tsf_bssid, ":",
+ info->aborted);
+
+ ieee80211_scan_done(ss->ss_vap);
+
+ LKPI_80211_LHW_SCAN_LOCK(lhw);
+ free(lhw->hw_req, M_LKPI80211);
+ lhw->hw_req = NULL;
+ lhw->scan_flags &= ~LKPI_LHW_SCAN_RUNNING;
+ /* The wakeup(lhw) will be called from lkpi_ic_scan_end(). */
+ /* wakeup(lhw); */
+ LKPI_80211_LHW_SCAN_UNLOCK(lhw);
+
+ return;
+}
+
+static void
+lkpi_80211_lhw_rxq_rx_one(struct lkpi_hw *lhw, struct mbuf *m)
+{
+ struct ieee80211_node *ni;
+#ifdef LKPI_80211_USE_MTAG
+ struct m_tag *mtag;
+#endif
+ int ok;
+
+ ni = NULL;
+#ifdef LKPI_80211_USE_MTAG
+ mtag = m_tag_locate(m, MTAG_ABI_LKPI80211, LKPI80211_TAG_RXNI, NULL);
+ if (mtag != NULL) {
+ struct lkpi_80211_tag_rxni *rxni;
+
+ rxni = (struct lkpi_80211_tag_rxni *)(mtag + 1);
+ ni = rxni->ni;
+ }
+#else
+ if (m->m_pkthdr.PH_loc.ptr != NULL) {
+ ni = m->m_pkthdr.PH_loc.ptr;
+ m->m_pkthdr.PH_loc.ptr = NULL;
+ }
+#endif
+
+ if (ni != NULL) {
+ ok = ieee80211_input_mimo(ni, m);
+ ieee80211_free_node(ni); /* Release the reference. */
+ if (ok < 0)
+ m_freem(m);
+ } else {
+ ok = ieee80211_input_mimo_all(lhw->ic, m);
+ /* mbuf got consumed. */
+ }
+
+#ifdef LINUXKPI_DEBUG_80211
+ if (linuxkpi_debug_80211 & D80211_TRACE_RX)
+ printf("TRACE-RX: %s: handled frame type %#0x\n", __func__, ok);
+#endif
+}
+
+static void
+lkpi_80211_lhw_rxq_task(void *ctx, int pending)
+{
+ struct lkpi_hw *lhw;
+ struct mbufq mq;
+ struct mbuf *m;
+
+ lhw = ctx;
+
+#ifdef LINUXKPI_DEBUG_80211
+ if (linuxkpi_debug_80211 & D80211_TRACE_RX)
+ printf("TRACE-RX: %s: lhw %p pending %d mbuf_qlen %d\n",
+ __func__, lhw, pending, mbufq_len(&lhw->rxq));
+#endif
+
+ mbufq_init(&mq, IFQ_MAXLEN);
+
+ LKPI_80211_LHW_RXQ_LOCK(lhw);
+ mbufq_concat(&mq, &lhw->rxq);
+ LKPI_80211_LHW_RXQ_UNLOCK(lhw);
+
+ m = mbufq_dequeue(&mq);
+ while (m != NULL) {
+ lkpi_80211_lhw_rxq_rx_one(lhw, m);
+ m = mbufq_dequeue(&mq);
+ }
+}
+
+static void
+lkpi_convert_rx_status(struct ieee80211_hw *hw, struct lkpi_sta *lsta,
+ struct ieee80211_rx_status *rx_status,
+ struct ieee80211_rx_stats *rx_stats,
+ uint8_t *rssip)
+{
+ struct ieee80211_supported_band *supband;
+ struct rate_info rxrate;
+ int i;
+ uint8_t rssi;
+
+ memset(&rxrate, 0, sizeof(rxrate));
+ memset(rx_stats, 0, sizeof(*rx_stats));
+ rx_stats->r_flags = IEEE80211_R_NF | IEEE80211_R_RSSI;
+ /* XXX-BZ correct hardcoded noise floor, survey data? */
+ rx_stats->c_nf = -96;
+ if (ieee80211_hw_check(hw, SIGNAL_DBM) &&
+ !(rx_status->flag & RX_FLAG_NO_SIGNAL_VAL))
+ rssi = rx_status->signal;
+ else
+ rssi = rx_stats->c_nf;
+ /*
+ * net80211 signal strength data are in .5 dBm units relative to
+ * the current noise floor (see comment in ieee80211_node.h).
+ */
+ rssi -= rx_stats->c_nf;
+ if (rssip != NULL)
+ *rssip = rssi;
+ rx_stats->c_rssi = rssi * 2;
+ rx_stats->r_flags |= IEEE80211_R_BAND;
+ rx_stats->c_band =
+ lkpi_nl80211_band_to_net80211_band(rx_status->band);
+ rx_stats->r_flags |= IEEE80211_R_FREQ | IEEE80211_R_IEEE;
+ rx_stats->c_freq = rx_status->freq;
+ rx_stats->c_ieee = ieee80211_mhz2ieee(rx_stats->c_freq, rx_stats->c_band);
+
+ rx_stats->c_rx_tsf = rx_status->mactime;
+
+ /* XXX RX_FLAG_MACTIME_IS_RTAP_TS64 ? */
+ if ((rx_status->flag & RX_FLAG_MACTIME) ==
+ (RX_FLAG_MACTIME_START|RX_FLAG_MACTIME_END)) {
+ rx_stats->r_flags |= IEEE80211_R_TSF64;
+ /* XXX RX_FLAG_MACTIME_PLCP_START ? */
+ if ((rx_status->flag & RX_FLAG_MACTIME) == RX_FLAG_MACTIME_START)
+ rx_stats->r_flags |= IEEE80211_R_TSF_START;
+ if ((rx_status->flag & RX_FLAG_MACTIME) == RX_FLAG_MACTIME_END)
+ rx_stats->r_flags |= IEEE80211_R_TSF_END;
+ /* XXX-BZ if TSF_END will net80211 do the unwind of time? */
+ }
+
+ if (rx_status->chains != 0) {
+ int cc;
+ int8_t crssi;
+
+ rx_stats->c_chain = rx_status->chains;
+ rx_stats->r_flags |= IEEE80211_R_C_CHAIN;
+
+ cc = 0;
+ for (i = 0; i < nitems(rx_status->chain_signal); i++) {
+ if (!(rx_status->chains & BIT(i)))
+ continue;
+ crssi = rx_status->chain_signal[i];
+ crssi -= rx_stats->c_nf;
+ rx_stats->c_rssi_ctl[i] = crssi * 2;
+ rx_stats->c_rssi_ext[i] = crssi * 2; /* XXX _ext ??? ATH thing? */
+ /* We currently only have the global noise floor value. */
+ rx_stats->c_nf_ctl[i] = rx_stats->c_nf;
+ rx_stats->c_nf_ext[i] = rx_stats->c_nf;
+ cc++;
+ }
+ if (cc > 0)
+ rx_stats->r_flags |= (IEEE80211_R_C_NF | IEEE80211_R_C_RSSI);
+ }
+
+ /* XXX-NET80211 We are not going to populate c_phytype! */
+
+ switch (rx_status->encoding) {
+ case RX_ENC_LEGACY:
+ {
+ uint32_t legacy = 0;
+
+ supband = hw->wiphy->bands[rx_status->band];
+ if (supband != NULL)
+ legacy = supband->bitrates[rx_status->rate_idx].bitrate;
+ rx_stats->c_rate = legacy;
+ rxrate.legacy = legacy;
+ /* Is there a LinuxKPI way of reporting IEEE80211_RX_F_CCK / _OFDM? */
+ break;
+ }
+ case RX_ENC_HT:
+ rx_stats->c_pktflags |= IEEE80211_RX_F_HT;
+ rx_stats->c_rate = rx_status->rate_idx; /* mcs */
+ rxrate.flags |= RATE_INFO_FLAGS_MCS;
+ rxrate.mcs = rx_status->rate_idx;
+ if ((rx_status->enc_flags & RX_ENC_FLAG_SHORT_GI) != 0) {
+ rx_stats->c_pktflags |= IEEE80211_RX_F_SHORTGI;
+ rxrate.flags |= RATE_INFO_FLAGS_SHORT_GI;
+ }
+ break;
+ case RX_ENC_VHT:
+ rx_stats->c_pktflags |= IEEE80211_RX_F_VHT;
+ rx_stats->c_rate = rx_status->rate_idx; /* mcs */
+ rx_stats->c_vhtnss = rx_status->nss;
+ rxrate.flags |= RATE_INFO_FLAGS_VHT_MCS;
+ rxrate.mcs = rx_status->rate_idx;
+ rxrate.nss = rx_status->nss;
+ if ((rx_status->enc_flags & RX_ENC_FLAG_SHORT_GI) != 0) {
+ rx_stats->c_pktflags |= IEEE80211_RX_F_SHORTGI;
+ rxrate.flags |= RATE_INFO_FLAGS_SHORT_GI;
+ }
+ break;
+ case RX_ENC_HE:
+ rxrate.flags |= RATE_INFO_FLAGS_HE_MCS;
+ rxrate.mcs = rx_status->rate_idx;
+ rxrate.nss = rx_status->nss;
+ /* XXX TODO */
+ TODO("net80211 has not matching encoding for %u", rx_status->encoding);
+ break;
+ case RX_ENC_EHT:
+ rxrate.flags |= RATE_INFO_FLAGS_EHT_MCS;
+ rxrate.mcs = rx_status->rate_idx;
+ rxrate.nss = rx_status->nss;
+ /* XXX TODO */
+ TODO("net80211 has not matching encoding for %u", rx_status->encoding);
+ break;
+ }
+
+ rxrate.bw = rx_status->bw;
+ switch (rx_status->bw) {
+ case RATE_INFO_BW_20:
+ rx_stats->c_width = IEEE80211_RX_FW_20MHZ;
+ break;
+ case RATE_INFO_BW_40:
+ rx_stats->c_width = IEEE80211_RX_FW_40MHZ;
+ break;
+ case RATE_INFO_BW_80:
+ rx_stats->c_width = IEEE80211_RX_FW_80MHZ;
+ break;
+ case RATE_INFO_BW_160:
+ rx_stats->c_width = IEEE80211_RX_FW_160MHZ;
+ break;
+ case RATE_INFO_BW_320:
+ case RATE_INFO_BW_HE_RU:
+ case RATE_INFO_BW_EHT_RU:
+ case RATE_INFO_BW_5:
+ case RATE_INFO_BW_10:
+ TODO("net80211 has not matching bandwidth for %u", rx_status->bw);
+ break;
+ }
+
+ if ((rx_status->enc_flags & RX_ENC_FLAG_LDPC) != 0)
+ rx_stats->c_pktflags |= IEEE80211_RX_F_LDPC;
+ if ((rx_status->enc_flags & RX_ENC_FLAG_STBC_MASK) != 0)
+ rx_stats->c_pktflags |= IEEE80211_RX_F_STBC;
+
+ /*
+ * We only need these for LKPI_80211_HW_CRYPTO in theory but in
+ * case the hardware does something we do not expect always leave
+ * these enabled. Leaving this commant as documentation for the || 1.
+ */
+#if defined(LKPI_80211_HW_CRYPTO) || 1
+ if (rx_status->flag & RX_FLAG_DECRYPTED) {
+ rx_stats->c_pktflags |= IEEE80211_RX_F_DECRYPTED;
+ /* Only valid if decrypted is set. */
+ if (rx_status->flag & RX_FLAG_PN_VALIDATED)
+ rx_stats->c_pktflags |= IEEE80211_RX_F_PN_VALIDATED;
+ }
+ if (rx_status->flag & RX_FLAG_IV_STRIPPED)
+ rx_stats->c_pktflags |= IEEE80211_RX_F_IV_STRIP;
+ if (rx_status->flag & RX_FLAG_ICV_STRIPPED)
+ rx_stats->c_pktflags |= IEEE80211_RX_F_ICV_STRIP;
+ if (rx_status->flag & RX_FLAG_MIC_STRIPPED)
+ rx_stats->c_pktflags |= IEEE80211_RX_F_MIC_STRIP;
+ if (rx_status->flag & RX_FLAG_MMIC_STRIPPED)
+ rx_stats->c_pktflags |= IEEE80211_RX_F_MMIC_STRIP;
+ if (rx_status->flag & RX_FLAG_MMIC_ERROR)
+ rx_stats->c_pktflags |= IEEE80211_RX_F_FAIL_MMIC;
+ if (rx_status->flag & RX_FLAG_FAILED_FCS_CRC)
+ rx_stats->c_pktflags |= IEEE80211_RX_F_FAIL_FCSCRC;
+#endif
+
+ /* Fill in some sinfo bits to fill gaps not reported byt the driver. */
+ if (lsta != NULL) {
+ memcpy(&lsta->sinfo.rxrate, &rxrate, sizeof(rxrate));
+ lsta->sinfo.filled |= BIT_ULL(NL80211_STA_INFO_RX_BITRATE);
+
+ if (rx_status->chains != 0) {
+ lsta->sinfo.chains = rx_status->chains;
+ memcpy(lsta->sinfo.chain_signal, rx_status->chain_signal,
+ sizeof(lsta->sinfo.chain_signal));
+ lsta->sinfo.filled |= BIT_ULL(NL80211_STA_INFO_CHAIN_SIGNAL);
+ }
+ }
+}
+
+#ifdef LINUXKPI_DEBUG_80211
+static void
+lkpi_rx_log_beacon(struct mbuf *m, struct lkpi_hw *lhw,
+ struct ieee80211_rx_status *rx_status)
+{
+ struct ieee80211_mgmt *f;
+ uint8_t *e;
+ char ssid[IEEE80211_NWID_LEN * 4 + 1];
+
+ memset(ssid, '\0', sizeof(ssid));
+
+ f = mtod(m, struct ieee80211_mgmt *);
+ e = f->u.beacon.variable;
+ /*
+ * Usually SSID is right after the fixed part and for debugging we will
+ * be fine should we miss it if it is not.
+ */
+ while ((e - (uint8_t *)f) < m->m_len) {
+ if (*e == IEEE80211_ELEMID_SSID)
+ break;
+ e += (2 + *(e + 1));
+ }
+ if (*e == IEEE80211_ELEMID_SSID) {
+ int i, len;
+ char *p;
+
+ p = ssid;
+ len = m->m_len - ((e + 2) - (uint8_t *)f);
+ if (len > *(e + 1))
+ len = *(e + 1);
+ e += 2;
+ for (i = 0; i < len; i++) {
+ /* Printable character? */
+ if (*e >= 0x20 && *e < 0x7f) {
+ *p++ = *e++;
+ } else {
+ snprintf(p, 5, "%#04x", *e++);
+ p += 4;
+ }
+ }
+ *p = '\0';
+ }
+
+ /* We print skb, skb->data, m as we are seeing 'ghost beacons'. */
+ TRACE_SCAN_BEACON(lhw->ic, "Beacon: scan_flags %b, band %s freq %u chan %-4d "
+ "len %d { %#06x %#06x %6D %6D %6D %#06x %ju %u %#06x SSID '%s' }",
+ lhw->scan_flags, LKPI_LHW_SCAN_BITS,
+ lkpi_nl80211_band_name(rx_status->band), rx_status->freq,
+ linuxkpi_ieee80211_frequency_to_channel(rx_status->freq, 0),
+ m->m_pkthdr.len, f->frame_control, f->duration_id,
+ f->da, ":", f->sa, ":", f->bssid, ":", f->seq_ctrl,
+ (uintmax_t)le64_to_cpu(f->u.beacon.timestamp),
+ le16_to_cpu(f->u.beacon.beacon_int),
+ le16_to_cpu(f->u.beacon.capab_info), ssid);
+}
+#endif
+
+/* For %list see comment towards the end of the function. */
+void
+linuxkpi_ieee80211_rx(struct ieee80211_hw *hw, struct sk_buff *skb,
+ struct ieee80211_sta *sta, struct napi_struct *napi __unused,
+ struct list_head *list __unused)
+{
+ struct lkpi_hw *lhw;
+ struct ieee80211com *ic;
+ struct mbuf *m;
+ struct skb_shared_info *shinfo;
+ struct ieee80211_rx_status *rx_status;
+ struct ieee80211_rx_stats rx_stats;
+ struct ieee80211_node *ni;
+ struct ieee80211vap *vap;
+ struct ieee80211_hdr *hdr;
+ struct lkpi_sta *lsta;
+ int i, offset, ok, error;
+ uint8_t rssi;
+ bool is_beacon;
+
+ lhw = HW_TO_LHW(hw);
+ ic = lhw->ic;
+
+ if (skb->len < 2) {
+ /* Need 80211 stats here. */
+ counter_u64_add(ic->ic_ierrors, 1);
+ IMPROVE();
+ goto err;
+ }
+
+ /*
+ * For now do the data copy; we can later improve things. Might even
+ * have an mbuf backing the skb data then?
+ */
+ m = m_get3(skb->len, M_NOWAIT, MT_DATA, M_PKTHDR);
+ if (m == NULL) {
+ counter_u64_add(ic->ic_ierrors, 1);
+ goto err;
+ }
+ m_copyback(m, 0, skb->tail - skb->data, skb->data);
+
+ shinfo = skb_shinfo(skb);
+ offset = m->m_len;
+ for (i = 0; i < shinfo->nr_frags; i++) {
+ m_copyback(m, offset, shinfo->frags[i].size,
+ (uint8_t *)linux_page_address(shinfo->frags[i].page) +
+ shinfo->frags[i].offset);
+ offset += shinfo->frags[i].size;
+ }
+
+ rx_status = IEEE80211_SKB_RXCB(skb);
+
+ hdr = (void *)skb->data;
+ is_beacon = ieee80211_is_beacon(hdr->frame_control);
+
+#ifdef LINUXKPI_DEBUG_80211
+ /*
+ * We use the mbuf here as otherwise the variable part might
+ * be in skb frags.
+ */
+ if (is_beacon && ((linuxkpi_debug_80211 & D80211_SCAN_BEACON) != 0))
+ lkpi_rx_log_beacon(m, lhw, rx_status);
+
+ if (is_beacon && (linuxkpi_debug_80211 & D80211_TRACE_RX_BEACONS) == 0 &&
+ (linuxkpi_debug_80211 & D80211_SCAN_BEACON) == 0)
+ goto no_trace_beacons;
+
+ if (linuxkpi_debug_80211 & D80211_TRACE_RX)
+ printf("TRACE-RX: %s: skb %p l/d/t-len (%u/%u/%u) "
+ "h %p d %p t %p e %p sh %p (%u) m %p plen %u len %u%s\n",
+ __func__, skb, skb->len, skb->data_len,
+ skb->truesize, skb->head, skb->data, skb->tail, skb->end,
+ shinfo, shinfo->nr_frags,
+ m, m->m_pkthdr.len, m->m_len, is_beacon ? " beacon" : "");
+
+ if (linuxkpi_debug_80211 & D80211_TRACE_RX_DUMP)
+ hexdump(mtod(m, const void *), m->m_len, "RX (raw) ", 0);
+
+ /* Implement a dump_rxcb() !!! */
+ if ((linuxkpi_debug_80211 & D80211_TRACE_RX) != 0 ||
+ (linuxkpi_debug_80211 & D80211_SCAN_BEACON) != 0)
+ printf("TRACE-RX: %s: RXCB: %ju %ju %u, %b, %u, %#0x, %#0x, "
+ "%u band %u, %u { %d %d %d %d }, %d, %#x %#x %#x %#x %u %u %u\n",
+ __func__,
+ (uintmax_t)rx_status->boottime_ns,
+ (uintmax_t)rx_status->mactime,
+ rx_status->device_timestamp,
+ rx_status->flag, IEEE80211_RX_STATUS_FLAGS_BITS,
+ rx_status->freq,
+ rx_status->bw,
+ rx_status->encoding,
+ rx_status->ampdu_reference,
+ rx_status->band,
+ rx_status->chains,
+ rx_status->chain_signal[0],
+ rx_status->chain_signal[1],
+ rx_status->chain_signal[2],
+ rx_status->chain_signal[3],
+ rx_status->signal,
+ rx_status->enc_flags,
+ rx_status->he_dcm,
+ rx_status->he_gi,
+ rx_status->he_ru,
+ rx_status->zero_length_psdu_type,
+ rx_status->nss,
+ rx_status->rate_idx);
+no_trace_beacons:
+#endif
+
+ lsta = NULL;
+ if (sta != NULL) {
+ lsta = STA_TO_LSTA(sta);
+ ni = ieee80211_ref_node(lsta->ni);
+ } else {
+ struct ieee80211_frame_min *wh;
+
+ wh = mtod(m, struct ieee80211_frame_min *);
+ ni = ieee80211_find_rxnode(ic, wh);
+ if (ni != NULL)
+ lsta = ni->ni_drv_data;
+ }
+
+ rssi = 0;
+ lkpi_convert_rx_status(hw, lsta, rx_status, &rx_stats, &rssi);
+
+ ok = ieee80211_add_rx_params(m, &rx_stats);
+ if (ok == 0) {
+ m_freem(m);
+ counter_u64_add(ic->ic_ierrors, 1);
+ goto err;
+ }
+
+ if (ni != NULL)
+ vap = ni->ni_vap;
+ else
+ /*
+ * XXX-BZ can we improve this by looking at the frame hdr
+ * or other meta-data passed up?
+ */
+ vap = TAILQ_FIRST(&ic->ic_vaps);
+
+#ifdef LINUXKPI_DEBUG_80211
+ if (linuxkpi_debug_80211 & D80211_TRACE_RX)
+ printf("TRACE-RX: %s: sta %p lsta %p state %d ni %p vap %p%s\n",
+ __func__, sta, lsta, (lsta != NULL) ? lsta->state : -1,
+ ni, vap, is_beacon ? " beacon" : "");
+#endif
+
+ if (ni != NULL && vap != NULL && is_beacon &&
+ rx_status->device_timestamp > 0 &&
+ m->m_pkthdr.len >= sizeof(struct ieee80211_frame)) {
+ struct lkpi_vif *lvif;
+ struct ieee80211_vif *vif;
+ struct ieee80211_frame *wh;
+
+ wh = mtod(m, struct ieee80211_frame *);
+ if (!IEEE80211_ADDR_EQ(wh->i_addr2, ni->ni_bssid))
+ goto skip_device_ts;
+
+ lvif = VAP_TO_LVIF(vap);
+ vif = LVIF_TO_VIF(lvif);
+
+ IMPROVE("TIMING_BEACON_ONLY?");
+ /* mac80211 specific (not net80211) so keep it here. */
+ vif->bss_conf.sync_device_ts = rx_status->device_timestamp;
+ /*
+ * net80211 should take care of the other information (sync_tsf,
+ * sync_dtim_count) as otherwise we need to parse the beacon.
+ */
+skip_device_ts:
+ ;
+ }
+
+ if (vap != NULL && vap->iv_state > IEEE80211_S_INIT &&
+ ieee80211_radiotap_active_vap(vap)) {
+ struct lkpi_radiotap_rx_hdr *rtap;
+
+ rtap = &lhw->rtap_rx;
+ rtap->wr_tsft = rx_status->device_timestamp;
+ rtap->wr_flags = 0;
+ if (rx_status->enc_flags & RX_ENC_FLAG_SHORTPRE)
+ rtap->wr_flags |= IEEE80211_RADIOTAP_F_SHORTPRE;
+ if (rx_status->enc_flags & RX_ENC_FLAG_SHORT_GI)
+ rtap->wr_flags |= IEEE80211_RADIOTAP_F_SHORTGI;
+#if 0 /* .. or it does not given we strip it below. */
+ if (ieee80211_hw_check(hw, RX_INCLUDES_FCS))
+ rtap->wr_flags |= IEEE80211_RADIOTAP_F_FCS;
+#endif
+ if (rx_status->flag & RX_FLAG_FAILED_FCS_CRC)
+ rtap->wr_flags |= IEEE80211_RADIOTAP_F_BADFCS;
+ rtap->wr_rate = 0;
+ IMPROVE();
+ /* XXX TODO status->encoding / rate_index / bw */
+ rtap->wr_chan_freq = htole16(rx_stats.c_freq);
+ if (ic->ic_curchan->ic_ieee == rx_stats.c_ieee)
+ rtap->wr_chan_flags = htole16(ic->ic_curchan->ic_flags);
+ rtap->wr_dbm_antsignal = rssi;
+ rtap->wr_dbm_antnoise = rx_stats.c_nf;
+ }
+
+ if (ieee80211_hw_check(hw, RX_INCLUDES_FCS))
+ m_adj(m, -IEEE80211_CRC_LEN);
+
+#if 0
+ if (list != NULL) {
+ /*
+ * Normally this would be queued up and delivered by
+ * netif_receive_skb_list(), napi_gro_receive(), or the like.
+ * See mt76::mac80211.c as only current possible consumer.
+ */
+ IMPROVE("we simply pass the packet to net80211 to deal with.");
+ }
+#endif
+
+ /* Attach meta-information to the mbuf for the deferred RX path. */
+ if (ni != NULL) {
+#ifdef LKPI_80211_USE_MTAG
+ struct m_tag *mtag;
+ struct lkpi_80211_tag_rxni *rxni;
+
+ mtag = m_tag_alloc(MTAG_ABI_LKPI80211, LKPI80211_TAG_RXNI,
+ sizeof(*rxni), IEEE80211_M_NOWAIT);
+ if (mtag == NULL) {
+ m_freem(m);
+ counter_u64_add(ic->ic_ierrors, 1);
+ goto err;
+ }
+ rxni = (struct lkpi_80211_tag_rxni *)(mtag + 1);
+ rxni->ni = ni; /* We hold a reference. */
+ m_tag_prepend(m, mtag);
+#else
+ m->m_pkthdr.PH_loc.ptr = ni; /* We hold a reference. */
+#endif
+ }
+
+ LKPI_80211_LHW_RXQ_LOCK(lhw);
+ if (lhw->rxq_stopped) {
+ LKPI_80211_LHW_RXQ_UNLOCK(lhw);
+ m_freem(m);
+ counter_u64_add(ic->ic_ierrors, 1);
+ goto err;
+ }
+
+ error = mbufq_enqueue(&lhw->rxq, m);
+ if (error != 0) {
+ LKPI_80211_LHW_RXQ_UNLOCK(lhw);
+ m_freem(m);
+ counter_u64_add(ic->ic_ierrors, 1);
+#ifdef LINUXKPI_DEBUG_80211
+ if (linuxkpi_debug_80211 & D80211_TRACE_RX)
+ ic_printf(ni->ni_ic, "%s: mbufq_enqueue failed: %d\n",
+ __func__, error);
+#endif
+ goto err;
+ }
+ taskqueue_enqueue(taskqueue_thread, &lhw->rxq_task);
+ LKPI_80211_LHW_RXQ_UNLOCK(lhw);
+
+ IMPROVE();
+
+err:
+ /* The skb is ours so we can free it :-) */
+ kfree_skb(skb);
+}
+
+uint8_t
+linuxkpi_ieee80211_get_tid(struct ieee80211_hdr *hdr, bool nonqos_ok)
+{
+ const struct ieee80211_frame *wh;
+ uint8_t tid;
+
+ /* Linux seems to assume this is a QOS-Data-Frame */
+ KASSERT(nonqos_ok || ieee80211_is_data_qos(hdr->frame_control),
+ ("%s: hdr %p fc %#06x not qos_data\n", __func__, hdr,
+ hdr->frame_control));
+
+ wh = (const struct ieee80211_frame *)hdr;
+ tid = ieee80211_gettid(wh);
+ KASSERT(nonqos_ok || tid == (tid & IEEE80211_QOS_TID), ("%s: tid %u "
+ "not expected (%u?)\n", __func__, tid, IEEE80211_NONQOS_TID));
+
+ return (tid);
+}
+
+/* -------------------------------------------------------------------------- */
+
+static void
+lkpi_wiphy_work(struct work_struct *work)
+{
+ struct lkpi_wiphy *lwiphy;
+ struct wiphy *wiphy;
+ struct wiphy_work *wk;
+
+ lwiphy = container_of(work, struct lkpi_wiphy, wwk);
+ wiphy = LWIPHY_TO_WIPHY(lwiphy);
+
+ wiphy_lock(wiphy);
+
+ LKPI_80211_LWIPHY_WORK_LOCK(lwiphy);
+ wk = list_first_entry_or_null(&lwiphy->wwk_list, struct wiphy_work, entry);
+ /* If there is nothing we do nothing. */
+ if (wk == NULL) {
+ LKPI_80211_LWIPHY_WORK_UNLOCK(lwiphy);
+ wiphy_unlock(wiphy);
+ return;
+ }
+ list_del_init(&wk->entry);
+
+ /* More work to do? */
+ if (!list_empty(&lwiphy->wwk_list))
+ schedule_work(work);
+ LKPI_80211_LWIPHY_WORK_UNLOCK(lwiphy);
+
+ /* Finally call the (*wiphy_work_fn)() function. */
+ wk->fn(wiphy, wk);
+
+ wiphy_unlock(wiphy);
+}
+
+void
+linuxkpi_wiphy_work_queue(struct wiphy *wiphy, struct wiphy_work *wwk)
+{
+ struct lkpi_wiphy *lwiphy;
+
+ lwiphy = WIPHY_TO_LWIPHY(wiphy);
+
+ LKPI_80211_LWIPHY_WORK_LOCK(lwiphy);
+ /* Do not double-queue. */
+ if (list_empty(&wwk->entry))
+ list_add_tail(&wwk->entry, &lwiphy->wwk_list);
+ LKPI_80211_LWIPHY_WORK_UNLOCK(lwiphy);
+
+ /*
+ * See how ieee80211_queue_work() work continues in Linux or if things
+ * migrate here over time?
+ * Use a system queue from linux/workqueue.h for now.
+ */
+ queue_work(system_wq, &lwiphy->wwk);
+}
+
+void
+linuxkpi_wiphy_work_cancel(struct wiphy *wiphy, struct wiphy_work *wwk)
+{
+ struct lkpi_wiphy *lwiphy;
+
+ lwiphy = WIPHY_TO_LWIPHY(wiphy);
+
+ LKPI_80211_LWIPHY_WORK_LOCK(lwiphy);
+ /* Only cancel if queued. */
+ if (!list_empty(&wwk->entry))
+ list_del_init(&wwk->entry);
+ LKPI_80211_LWIPHY_WORK_UNLOCK(lwiphy);
+}
+
+void
+linuxkpi_wiphy_work_flush(struct wiphy *wiphy, struct wiphy_work *wwk)
+{
+ struct lkpi_wiphy *lwiphy;
+ struct wiphy_work *wk;
+
+ lwiphy = WIPHY_TO_LWIPHY(wiphy);
+ LKPI_80211_LWIPHY_WORK_LOCK(lwiphy);
+ /* If wwk is unset, flush everything; called when wiphy is shut down. */
+ if (wwk != NULL && list_empty(&wwk->entry)) {
+ LKPI_80211_LWIPHY_WORK_UNLOCK(lwiphy);
+ return;
+ }
+
+ while (!list_empty(&lwiphy->wwk_list)) {
+
+ wk = list_first_entry(&lwiphy->wwk_list, struct wiphy_work,
+ entry);
+ list_del_init(&wk->entry);
+ LKPI_80211_LWIPHY_WORK_UNLOCK(lwiphy);
+ wk->fn(wiphy, wk);
+ LKPI_80211_LWIPHY_WORK_LOCK(lwiphy);
+ if (wk == wwk)
+ break;
+ }
+ LKPI_80211_LWIPHY_WORK_UNLOCK(lwiphy);
+}
+
+void
+lkpi_wiphy_delayed_work_timer(struct timer_list *tl)
+{
+ struct wiphy_delayed_work *wdwk;
+
+ wdwk = timer_container_of(wdwk, tl, timer);
+ wiphy_work_queue(wdwk->wiphy, &wdwk->work);
+}
+
+void
+linuxkpi_wiphy_delayed_work_queue(struct wiphy *wiphy,
+ struct wiphy_delayed_work *wdwk, unsigned long delay)
+{
+ if (delay == 0) {
+ /* Run right away. */
+ del_timer(&wdwk->timer);
+ wiphy_work_queue(wiphy, &wdwk->work);
+ } else {
+ wdwk->wiphy = wiphy;
+ mod_timer(&wdwk->timer, jiffies + delay);
+ }
+}
+
+void
+linuxkpi_wiphy_delayed_work_cancel(struct wiphy *wiphy,
+ struct wiphy_delayed_work *wdwk)
+{
+ del_timer_sync(&wdwk->timer);
+ wiphy_work_cancel(wiphy, &wdwk->work);
+}
+
+void
+linuxkpi_wiphy_delayed_work_flush(struct wiphy *wiphy,
+ struct wiphy_delayed_work *wdwk)
+{
+ lockdep_assert_held(&wiphy->mtx);
+
+ del_timer_sync(&wdwk->timer);
+ wiphy_work_flush(wiphy, &wdwk->work);
+}
+
+/* -------------------------------------------------------------------------- */
+
+struct wiphy *
+linuxkpi_wiphy_new(const struct cfg80211_ops *ops, size_t priv_len)
+{
+ struct lkpi_wiphy *lwiphy;
+ struct wiphy *wiphy;
+
+ lwiphy = kzalloc(sizeof(*lwiphy) + priv_len, GFP_KERNEL);
+ if (lwiphy == NULL)
+ return (NULL);
+ lwiphy->ops = ops;
+
+ LKPI_80211_LWIPHY_WORK_LOCK_INIT(lwiphy);
+ INIT_LIST_HEAD(&lwiphy->wwk_list);
+ INIT_WORK(&lwiphy->wwk, lkpi_wiphy_work);
+
+ wiphy = LWIPHY_TO_WIPHY(lwiphy);
+
+ mutex_init(&wiphy->mtx);
+ TODO();
+
+ return (wiphy);
+}
+
+void
+linuxkpi_wiphy_free(struct wiphy *wiphy)
+{
+ struct lkpi_wiphy *lwiphy;
+
+ if (wiphy == NULL)
+ return;
+
+ linuxkpi_wiphy_work_flush(wiphy, NULL);
+ mutex_destroy(&wiphy->mtx);
+
+ lwiphy = WIPHY_TO_LWIPHY(wiphy);
+ LKPI_80211_LWIPHY_WORK_LOCK_DESTROY(lwiphy);
+
+ kfree(lwiphy);
+}
+
+static uint32_t
+lkpi_cfg80211_calculate_bitrate_ht(struct rate_info *rate)
+{
+ TODO("cfg80211_calculate_bitrate_ht");
+ return (rate->legacy);
+}
+
+static uint32_t
+lkpi_cfg80211_calculate_bitrate_vht(struct rate_info *rate)
+{
+ TODO("cfg80211_calculate_bitrate_vht");
+ return (rate->legacy);
+}
+
+uint32_t
+linuxkpi_cfg80211_calculate_bitrate(struct rate_info *rate)
+{
+
+ /* Beware: order! */
+ if (rate->flags & RATE_INFO_FLAGS_MCS)
+ return (lkpi_cfg80211_calculate_bitrate_ht(rate));
+
+ if (rate->flags & RATE_INFO_FLAGS_VHT_MCS)
+ return (lkpi_cfg80211_calculate_bitrate_vht(rate));
+
+ IMPROVE("HE/EHT/...");
+
+ return (rate->legacy);
+}
+
+uint32_t
+linuxkpi_ieee80211_channel_to_frequency(uint32_t channel,
+ enum nl80211_band band)
+{
+
+ switch (band) {
+ case NL80211_BAND_2GHZ:
+ return (ieee80211_ieee2mhz(channel, IEEE80211_CHAN_2GHZ));
+ break;
+ case NL80211_BAND_5GHZ:
+ return (ieee80211_ieee2mhz(channel, IEEE80211_CHAN_5GHZ));
+ break;
+ default:
+ /* XXX abort, retry, error, panic? */
+ break;
+ }
+
+ return (0);
+}
+
+uint32_t
+linuxkpi_ieee80211_frequency_to_channel(uint32_t freq, uint32_t flags __unused)
+{
+
+ return (ieee80211_mhz2ieee(freq, 0));
+}
+
+#if 0
+static struct lkpi_sta *
+lkpi_find_lsta_by_ni(struct lkpi_vif *lvif, struct ieee80211_node *ni)
+{
+ struct lkpi_sta *lsta, *temp;
+
+ rcu_read_lock();
+ list_for_each_entry_rcu(lsta, &lvif->lsta_list, lsta_list) {
+ if (lsta->ni == ni) {
+ rcu_read_unlock();
+ return (lsta);
+ }
+ }
+ rcu_read_unlock();
+
+ return (NULL);
+}
+#endif
+
+struct ieee80211_sta *
+linuxkpi_ieee80211_find_sta(struct ieee80211_vif *vif, const u8 *peer)
+{
+ struct lkpi_vif *lvif;
+ struct lkpi_sta *lsta;
+ struct ieee80211_sta *sta;
+
+ lvif = VIF_TO_LVIF(vif);
+
+ rcu_read_lock();
+ list_for_each_entry_rcu(lsta, &lvif->lsta_list, lsta_list) {
+ sta = LSTA_TO_STA(lsta);
+ if (IEEE80211_ADDR_EQ(sta->addr, peer)) {
+ rcu_read_unlock();
+ return (sta);
+ }
+ }
+ rcu_read_unlock();
+ return (NULL);
+}
+
+struct ieee80211_sta *
+linuxkpi_ieee80211_find_sta_by_ifaddr(struct ieee80211_hw *hw,
+ const uint8_t *addr, const uint8_t *ourvifaddr)
+{
+ struct lkpi_hw *lhw;
+ struct lkpi_vif *lvif;
+ struct lkpi_sta *lsta;
+ struct ieee80211_vif *vif;
+ struct ieee80211_sta *sta;
+
+ lhw = wiphy_priv(hw->wiphy);
+ sta = NULL;
+
+ LKPI_80211_LHW_LVIF_LOCK(lhw);
+ TAILQ_FOREACH(lvif, &lhw->lvif_head, lvif_entry) {
+
+ /* XXX-BZ check our address from the vif. */
+
+ vif = LVIF_TO_VIF(lvif);
+ if (ourvifaddr != NULL &&
+ !IEEE80211_ADDR_EQ(vif->addr, ourvifaddr))
+ continue;
+ sta = linuxkpi_ieee80211_find_sta(vif, addr);
+ if (sta != NULL)
+ break;
+ }
+ LKPI_80211_LHW_LVIF_UNLOCK(lhw);
+
+ if (sta != NULL) {
+ lsta = STA_TO_LSTA(sta);
+ if (!lsta->added_to_drv)
+ return (NULL);
+ }
+
+ return (sta);
+}
+
+struct sk_buff *
+linuxkpi_ieee80211_tx_dequeue(struct ieee80211_hw *hw,
+ struct ieee80211_txq *txq)
+{
+ struct lkpi_txq *ltxq;
+ struct lkpi_vif *lvif;
+ struct sk_buff *skb;
+
+ IMPROVE("wiphy_lock? or assert?");
+ skb = NULL;
+ ltxq = TXQ_TO_LTXQ(txq);
+ ltxq->seen_dequeue = true;
+
+ if (ltxq->stopped)
+ goto stopped;
+
+ lvif = VIF_TO_LVIF(ltxq->txq.vif);
+ if (lvif->hw_queue_stopped[ltxq->txq.ac]) {
+ ltxq->stopped = true;
+ goto stopped;
+ }
+
+ IMPROVE("hw(TX_FRAG_LIST)");
+
+ LKPI_80211_LTXQ_LOCK(ltxq);
+ skb = skb_dequeue(&ltxq->skbq);
+ LKPI_80211_LTXQ_UNLOCK(ltxq);
+
+stopped:
+ return (skb);
+}
+
+void
+linuxkpi_ieee80211_txq_get_depth(struct ieee80211_txq *txq,
+ unsigned long *frame_cnt, unsigned long *byte_cnt)
+{
+ struct lkpi_txq *ltxq;
+ struct sk_buff *skb;
+ unsigned long fc, bc;
+
+ ltxq = TXQ_TO_LTXQ(txq);
+
+ fc = bc = 0;
+ LKPI_80211_LTXQ_LOCK(ltxq);
+ skb_queue_walk(&ltxq->skbq, skb) {
+ fc++;
+ bc += skb->len;
+ }
+ LKPI_80211_LTXQ_UNLOCK(ltxq);
+ if (frame_cnt)
+ *frame_cnt = fc;
+ if (byte_cnt)
+ *byte_cnt = bc;
+
+ /* Validate that this is doing the correct thing. */
+ /* Should we keep track on en/dequeue? */
+ IMPROVE();
+}
+
+/*
+ * We are called from ieee80211_free_txskb() or ieee80211_tx_status().
+ * The latter tries to derive the success status from the info flags
+ * passed back from the driver. rawx_mit() saves the ni on the m and the
+ * m on the skb for us to be able to give feedback to net80211.
+ */
+static void
+_lkpi_ieee80211_free_txskb(struct ieee80211_hw *hw, struct sk_buff *skb,
+ int status)
+{
+ struct ieee80211_node *ni;
+ struct mbuf *m;
+
+ m = skb->m;
+ skb->m = NULL;
+
+ if (m != NULL) {
+ ni = m->m_pkthdr.PH_loc.ptr;
+ /* Status: 0 is ok, != 0 is error. */
+ ieee80211_tx_complete(ni, m, status);
+ /* ni & mbuf were consumed. */
+ }
+}
+
+void
+linuxkpi_ieee80211_free_txskb(struct ieee80211_hw *hw, struct sk_buff *skb,
+ int status)
+{
+
+ _lkpi_ieee80211_free_txskb(hw, skb, status);
+ kfree_skb(skb);
+}
+
+void
+linuxkpi_ieee80211_tx_status_ext(struct ieee80211_hw *hw,
+ struct ieee80211_tx_status *txstat)
+{
+ struct sk_buff *skb;
+ struct ieee80211_tx_info *info;
+ struct ieee80211_ratectl_tx_status txs;
+ struct ieee80211_node *ni;
+ int status;
+
+ skb = txstat->skb;
+ if (skb->m != NULL) {
+ struct mbuf *m;
+
+ m = skb->m;
+ ni = m->m_pkthdr.PH_loc.ptr;
+ memset(&txs, 0, sizeof(txs));
+ } else {
+ ni = NULL;
+ }
+
+ info = txstat->info;
+ if (info->flags & IEEE80211_TX_STAT_ACK) {
+ status = 0; /* No error. */
+ txs.status = IEEE80211_RATECTL_TX_SUCCESS;
+ } else {
+ status = 1;
+ txs.status = IEEE80211_RATECTL_TX_FAIL_UNSPECIFIED;
+ }
+
+ if (ni != NULL) {
+ txs.pktlen = skb->len;
+ txs.flags |= IEEE80211_RATECTL_STATUS_PKTLEN;
+ if (info->status.rates[0].count > 1) {
+ txs.long_retries = info->status.rates[0].count - 1; /* 1 + retries in drivers. */
+ txs.flags |= IEEE80211_RATECTL_STATUS_LONG_RETRY;
+ }
+#if 0 /* Unused in net80211 currently. */
+ /* XXX-BZ convert check .flags for MCS/VHT/.. */
+ txs.final_rate = info->status.rates[0].idx;
+ txs.flags |= IEEE80211_RATECTL_STATUS_FINAL_RATE;
+#endif
+ if (info->status.flags & IEEE80211_TX_STATUS_ACK_SIGNAL_VALID) {
+ txs.rssi = info->status.ack_signal; /* XXX-BZ CONVERT? */
+ txs.flags |= IEEE80211_RATECTL_STATUS_RSSI;
+ }
+
+ IMPROVE("only update rate if needed but that requires us to get a proper rate from mo_sta_statistics");
+ ieee80211_ratectl_tx_complete(ni, &txs);
+ ieee80211_ratectl_rate(ni->ni_vap->iv_bss, NULL, 0);
+
+#ifdef LINUXKPI_DEBUG_80211
+ if (linuxkpi_debug_80211 & D80211_TRACE_TX) {
+ printf("TX-RATE: %s: long_retries %d\n", __func__,
+ txs.long_retries);
+ }
+#endif
+ }
+
+#ifdef LINUXKPI_DEBUG_80211
+ if (linuxkpi_debug_80211 & D80211_TRACE_TX)
+ printf("TX-STATUS: %s: hw %p skb %p status %d : flags %#x "
+ "band %u hw_queue %u tx_time_est %d : "
+ "rates [ %u %u %#x, %u %u %#x, %u %u %#x, %u %u %#x ] "
+ "ack_signal %u ampdu_ack_len %u ampdu_len %u antenna %u "
+ "tx_time %u flags %#x "
+ "status_driver_data [ %p %p ]\n",
+ __func__, hw, skb, status, info->flags,
+ info->band, info->hw_queue, info->tx_time_est,
+ info->status.rates[0].idx, info->status.rates[0].count,
+ info->status.rates[0].flags,
+ info->status.rates[1].idx, info->status.rates[1].count,
+ info->status.rates[1].flags,
+ info->status.rates[2].idx, info->status.rates[2].count,
+ info->status.rates[2].flags,
+ info->status.rates[3].idx, info->status.rates[3].count,
+ info->status.rates[3].flags,
+ info->status.ack_signal, info->status.ampdu_ack_len,
+ info->status.ampdu_len, info->status.antenna,
+ info->status.tx_time, info->status.flags,
+ info->status.status_driver_data[0],
+ info->status.status_driver_data[1]);
+#endif
+
+ if (txstat->free_list) {
+ _lkpi_ieee80211_free_txskb(hw, skb, status);
+ list_add_tail(&skb->list, txstat->free_list);
+ } else {
+ linuxkpi_ieee80211_free_txskb(hw, skb, status);
+ }
+}
+
+void
+linuxkpi_ieee80211_tx_status(struct ieee80211_hw *hw, struct sk_buff *skb)
+{
+ struct ieee80211_tx_status status;
+
+ memset(&status, 0, sizeof(status));
+ status.info = IEEE80211_SKB_CB(skb);
+ status.skb = skb;
+ /* sta, n_rates, rates, free_list? */
+
+ ieee80211_tx_status_ext(hw, &status);
+}
+
+/*
+ * This is an internal bandaid for the moment for the way we glue
+ * skbs and mbufs together for TX. Once we have skbs backed by
+ * mbufs this should go away.
+ * This is a public function but kept on the private KPI (lkpi_)
+ * and is not exposed by a header file.
+ */
+static void
+lkpi_ieee80211_free_skb_mbuf(void *p)
+{
+ struct ieee80211_node *ni;
+ struct mbuf *m;
+
+ if (p == NULL)
+ return;
+
+ m = (struct mbuf *)p;
+ M_ASSERTPKTHDR(m);
+
+ ni = m->m_pkthdr.PH_loc.ptr;
+ m->m_pkthdr.PH_loc.ptr = NULL;
+ if (ni != NULL)
+ ieee80211_free_node(ni);
+ m_freem(m);
+}
+
+void
+linuxkpi_ieee80211_queue_delayed_work(struct ieee80211_hw *hw,
+ struct delayed_work *w, int delay)
+{
+ struct lkpi_hw *lhw;
+
+ /* Need to make sure hw is in a stable (non-suspended) state. */
+ IMPROVE();
+
+ lhw = HW_TO_LHW(hw);
+ queue_delayed_work(lhw->workq, w, delay);
+}
+
+void
+linuxkpi_ieee80211_queue_work(struct ieee80211_hw *hw,
+ struct work_struct *w)
+{
+ struct lkpi_hw *lhw;
+
+ /* Need to make sure hw is in a stable (non-suspended) state. */
+ IMPROVE();
+
+ lhw = HW_TO_LHW(hw);
+ queue_work(lhw->workq, w);
+}
+
+struct sk_buff *
+linuxkpi_ieee80211_probereq_get(struct ieee80211_hw *hw, const uint8_t *addr,
+ const uint8_t *ssid, size_t ssid_len, size_t tailroom)
+{
+ struct sk_buff *skb;
+ struct ieee80211_frame *wh;
+ uint8_t *p;
+ size_t len;
+
+ len = sizeof(*wh);
+ len += 2 + ssid_len;
+
+ skb = dev_alloc_skb(hw->extra_tx_headroom + len + tailroom);
+ if (skb == NULL)
+ return (NULL);
+
+ skb_reserve(skb, hw->extra_tx_headroom);
+
+ wh = skb_put_zero(skb, sizeof(*wh));
+ wh->i_fc[0] = IEEE80211_FC0_VERSION_0;
+ wh->i_fc[0] |= IEEE80211_FC0_SUBTYPE_PROBE_REQ | IEEE80211_FC0_TYPE_MGT;
+ IEEE80211_ADDR_COPY(wh->i_addr1, ieee80211broadcastaddr);
+ IEEE80211_ADDR_COPY(wh->i_addr2, addr);
+ IEEE80211_ADDR_COPY(wh->i_addr3, ieee80211broadcastaddr);
+
+ p = skb_put(skb, 2 + ssid_len);
+ *p++ = IEEE80211_ELEMID_SSID;
+ *p++ = ssid_len;
+ if (ssid_len > 0)
+ memcpy(p, ssid, ssid_len);
+
+ return (skb);
+}
+
+struct sk_buff *
+linuxkpi_ieee80211_pspoll_get(struct ieee80211_hw *hw,
+ struct ieee80211_vif *vif)
+{
+ struct lkpi_vif *lvif;
+ struct ieee80211vap *vap;
+ struct sk_buff *skb;
+ struct ieee80211_frame_pspoll *psp;
+ uint16_t v;
+
+ skb = dev_alloc_skb(hw->extra_tx_headroom + sizeof(*psp));
+ if (skb == NULL)
+ return (NULL);
+
+ skb_reserve(skb, hw->extra_tx_headroom);
+
+ lvif = VIF_TO_LVIF(vif);
+ vap = LVIF_TO_VAP(lvif);
+
+ psp = skb_put_zero(skb, sizeof(*psp));
+ psp->i_fc[0] = IEEE80211_FC0_VERSION_0;
+ psp->i_fc[0] |= IEEE80211_FC0_SUBTYPE_PS_POLL | IEEE80211_FC0_TYPE_CTL;
+ v = htole16(vif->cfg.aid | 1<<15 | 1<<16);
+ memcpy(&psp->i_aid, &v, sizeof(v));
+ IEEE80211_ADDR_COPY(psp->i_bssid, vap->iv_bss->ni_macaddr);
+ IEEE80211_ADDR_COPY(psp->i_ta, vif->addr);
+
+ return (skb);
+}
+
+struct sk_buff *
+linuxkpi_ieee80211_nullfunc_get(struct ieee80211_hw *hw,
+ struct ieee80211_vif *vif, int linkid, bool qos)
+{
+ struct lkpi_vif *lvif;
+ struct ieee80211vap *vap;
+ struct sk_buff *skb;
+ struct ieee80211_frame *nullf;
+
+ IMPROVE("linkid");
+
+ skb = dev_alloc_skb(hw->extra_tx_headroom + sizeof(*nullf));
+ if (skb == NULL)
+ return (NULL);
+
+ skb_reserve(skb, hw->extra_tx_headroom);
+
+ lvif = VIF_TO_LVIF(vif);
+ vap = LVIF_TO_VAP(lvif);
+
+ nullf = skb_put_zero(skb, sizeof(*nullf));
+ nullf->i_fc[0] = IEEE80211_FC0_VERSION_0;
+ nullf->i_fc[0] |= IEEE80211_FC0_SUBTYPE_NODATA | IEEE80211_FC0_TYPE_DATA;
+ nullf->i_fc[1] = IEEE80211_FC1_DIR_TODS;
+
+ IEEE80211_ADDR_COPY(nullf->i_addr1, vap->iv_bss->ni_bssid);
+ IEEE80211_ADDR_COPY(nullf->i_addr2, vif->addr);
+ IEEE80211_ADDR_COPY(nullf->i_addr3, vap->iv_bss->ni_macaddr);
+
+ return (skb);
+}
+
+struct wireless_dev *
+linuxkpi_ieee80211_vif_to_wdev(struct ieee80211_vif *vif)
+{
+ struct lkpi_vif *lvif;
+
+ lvif = VIF_TO_LVIF(vif);
+ return (&lvif->wdev);
+}
+
+void
+linuxkpi_ieee80211_connection_loss(struct ieee80211_vif *vif)
+{
+ struct lkpi_vif *lvif;
+ struct ieee80211vap *vap;
+ enum ieee80211_state nstate;
+ int arg;
+
+ lvif = VIF_TO_LVIF(vif);
+ vap = LVIF_TO_VAP(lvif);
+
+ /*
+ * Go to init; otherwise we need to elaborately check state and
+ * handle accordingly, e.g., if in RUN we could call iv_bmiss.
+ * Let the statemachine handle all neccessary changes.
+ */
+ nstate = IEEE80211_S_INIT;
+ arg = 0; /* Not a valid reason. */
+
+ ic_printf(vap->iv_ic, "%s: vif %p vap %p state %s (synched %d, assoc %d "
+ "beacons %d dtim_period %d)\n", __func__, vif, vap,
+ ieee80211_state_name[vap->iv_state],
+ lvif->lvif_bss_synched, vif->cfg.assoc, lvif->beacons,
+ vif->bss_conf.dtim_period);
+ ieee80211_new_state(vap, nstate, arg);
+}
+
+void
+linuxkpi_ieee80211_beacon_loss(struct ieee80211_vif *vif)
+{
+ struct lkpi_vif *lvif;
+ struct ieee80211vap *vap;
+
+ lvif = VIF_TO_LVIF(vif);
+ vap = LVIF_TO_VAP(lvif);
+
+ ic_printf(vap->iv_ic, "%s: vif %p vap %p state %s (synched %d, assoc %d "
+ "beacons %d dtim_period %d)\n", __func__, vif, vap,
+ ieee80211_state_name[vap->iv_state],
+ lvif->lvif_bss_synched, vif->cfg.assoc, lvif->beacons,
+ vif->bss_conf.dtim_period);
+ ieee80211_beacon_miss(vap->iv_ic);
+}
+
+/* -------------------------------------------------------------------------- */
+
+void
+linuxkpi_ieee80211_stop_queue(struct ieee80211_hw *hw, int qnum)
+{
+ struct lkpi_hw *lhw;
+ struct lkpi_vif *lvif;
+ struct ieee80211_vif *vif;
+ int ac_count, ac;
+
+ KASSERT(qnum < hw->queues, ("%s: qnum %d >= hw->queues %d, hw %p\n",
+ __func__, qnum, hw->queues, hw));
+
+ lhw = wiphy_priv(hw->wiphy);
+
+ /* See lkpi_ic_vap_create(). */
+ if (hw->queues >= IEEE80211_NUM_ACS)
+ ac_count = IEEE80211_NUM_ACS;
+ else
+ ac_count = 1;
+
+ LKPI_80211_LHW_LVIF_LOCK(lhw);
+ TAILQ_FOREACH(lvif, &lhw->lvif_head, lvif_entry) {
+
+ vif = LVIF_TO_VIF(lvif);
+ for (ac = 0; ac < ac_count; ac++) {
+ IMPROVE_TXQ("LOCKING");
+ if (qnum == vif->hw_queue[ac]) {
+#ifdef LINUXKPI_DEBUG_80211
+ /*
+ * For now log this to better understand
+ * how this is supposed to work.
+ */
+ if (lvif->hw_queue_stopped[ac] &&
+ (linuxkpi_debug_80211 & D80211_IMPROVE_TXQ) != 0)
+ ic_printf(lhw->ic, "%s:%d: lhw %p hw %p "
+ "lvif %p vif %p ac %d qnum %d already "
+ "stopped\n", __func__, __LINE__,
+ lhw, hw, lvif, vif, ac, qnum);
+#endif
+ lvif->hw_queue_stopped[ac] = true;
+ }
+ }
+ }
+ LKPI_80211_LHW_LVIF_UNLOCK(lhw);
+}
+
+void
+linuxkpi_ieee80211_stop_queues(struct ieee80211_hw *hw)
+{
+ int i;
+
+ IMPROVE_TXQ("Locking; do we need further info?");
+ for (i = 0; i < hw->queues; i++)
+ linuxkpi_ieee80211_stop_queue(hw, i);
+}
+
+
+static void
+lkpi_ieee80211_wake_queues(struct ieee80211_hw *hw, int hwq)
+{
+ struct lkpi_hw *lhw;
+ struct lkpi_vif *lvif;
+ struct lkpi_sta *lsta;
+ int ac_count, ac, tid;
+
+ /* See lkpi_ic_vap_create(). */
+ if (hw->queues >= IEEE80211_NUM_ACS)
+ ac_count = IEEE80211_NUM_ACS;
+ else
+ ac_count = 1;
+
+ lhw = wiphy_priv(hw->wiphy);
+
+ IMPROVE_TXQ("Locking");
+ LKPI_80211_LHW_LVIF_LOCK(lhw);
+ TAILQ_FOREACH(lvif, &lhw->lvif_head, lvif_entry) {
+ struct ieee80211_vif *vif;
+
+ vif = LVIF_TO_VIF(lvif);
+ for (ac = 0; ac < ac_count; ac++) {
+
+ if (hwq == vif->hw_queue[ac]) {
+
+ /* XXX-BZ what about software scan? */
+
+#ifdef LINUXKPI_DEBUG_80211
+ /*
+ * For now log this to better understand
+ * how this is supposed to work.
+ */
+ if (!lvif->hw_queue_stopped[ac] &&
+ (linuxkpi_debug_80211 & D80211_IMPROVE_TXQ) != 0)
+ ic_printf(lhw->ic, "%s:%d: lhw %p hw %p "
+ "lvif %p vif %p ac %d hw_q not stopped\n",
+ __func__, __LINE__,
+ lhw, hw, lvif, vif, ac);
+#endif
+ lvif->hw_queue_stopped[ac] = false;
+
+ rcu_read_lock();
+ list_for_each_entry_rcu(lsta, &lvif->lsta_list, lsta_list) {
+ struct ieee80211_sta *sta;
+
+ sta = LSTA_TO_STA(lsta);
+ for (tid = 0; tid < nitems(sta->txq); tid++) {
+ struct lkpi_txq *ltxq;
+
+ if (sta->txq[tid] == NULL)
+ continue;
+
+ if (sta->txq[tid]->ac != ac)
+ continue;
+
+ ltxq = TXQ_TO_LTXQ(sta->txq[tid]);
+ if (!ltxq->stopped)
+ continue;
+
+ ltxq->stopped = false;
+
+ if (!skb_queue_empty(&ltxq->skbq))
+ lkpi_80211_mo_wake_tx_queue(hw, sta->txq[tid]);
+ }
+ }
+ rcu_read_unlock();
+ }
+ }
+ }
+ LKPI_80211_LHW_LVIF_UNLOCK(lhw);
+}
+
+static void
+lkpi_ieee80211_wake_queues_locked(struct ieee80211_hw *hw)
+{
+ int i;
+
+ IMPROVE_TXQ("Is this all/enough here?");
+ for (i = 0; i < hw->queues; i++)
+ lkpi_ieee80211_wake_queues(hw, i);
+}
+
+void
+linuxkpi_ieee80211_wake_queues(struct ieee80211_hw *hw)
+{
+ struct lkpi_hw *lhw;
+ unsigned long flags;
+
+ lhw = HW_TO_LHW(hw);
+
+ spin_lock_irqsave(&lhw->txq_lock, flags);
+ lkpi_ieee80211_wake_queues_locked(hw);
+ spin_unlock_irqrestore(&lhw->txq_lock, flags);
+}
+
+void
+linuxkpi_ieee80211_wake_queue(struct ieee80211_hw *hw, int qnum)
+{
+ struct lkpi_hw *lhw;
+ unsigned long flags;
+
+ KASSERT(qnum < hw->queues, ("%s: qnum %d >= hw->queues %d, hw %p\n",
+ __func__, qnum, hw->queues, hw));
+
+ lhw = HW_TO_LHW(hw);
+
+ spin_lock_irqsave(&lhw->txq_lock, flags);
+ lkpi_ieee80211_wake_queues(hw, qnum);
+ spin_unlock_irqrestore(&lhw->txq_lock, flags);
+}
+
+/* This is just hardware queues. */
+void
+linuxkpi_ieee80211_txq_schedule_start(struct ieee80211_hw *hw, uint8_t ac)
+{
+ struct lkpi_hw *lhw;
+
+ lhw = HW_TO_LHW(hw);
+
+ IMPROVE_TXQ("Are there reasons why we wouldn't schedule?");
+ IMPROVE_TXQ("LOCKING");
+ if (++lhw->txq_generation[ac] == 0)
+ lhw->txq_generation[ac]++;
+}
+
+struct ieee80211_txq *
+linuxkpi_ieee80211_next_txq(struct ieee80211_hw *hw, uint8_t ac)
+{
+ struct lkpi_hw *lhw;
+ struct ieee80211_txq *txq;
+ struct lkpi_txq *ltxq;
+
+ lhw = HW_TO_LHW(hw);
+ txq = NULL;
+
+ IMPROVE_TXQ("LOCKING");
+
+ /* Check that we are scheduled. */
+ if (lhw->txq_generation[ac] == 0)
+ goto out;
+
+ ltxq = TAILQ_FIRST(&lhw->scheduled_txqs[ac]);
+ if (ltxq == NULL)
+ goto out;
+ if (ltxq->txq_generation == lhw->txq_generation[ac])
+ goto out;
+
+ ltxq->txq_generation = lhw->txq_generation[ac];
+ TAILQ_REMOVE(&lhw->scheduled_txqs[ac], ltxq, txq_entry);
+ txq = &ltxq->txq;
+ TAILQ_ELEM_INIT(ltxq, txq_entry);
+
+out:
+ return (txq);
+}
+
+void linuxkpi_ieee80211_schedule_txq(struct ieee80211_hw *hw,
+ struct ieee80211_txq *txq, bool withoutpkts)
+{
+ struct lkpi_hw *lhw;
+ struct lkpi_txq *ltxq;
+ bool ltxq_empty;
+
+ ltxq = TXQ_TO_LTXQ(txq);
+
+ IMPROVE_TXQ("LOCKING");
+
+ /* Only schedule if work to do or asked to anyway. */
+ LKPI_80211_LTXQ_LOCK(ltxq);
+ ltxq_empty = skb_queue_empty(&ltxq->skbq);
+ LKPI_80211_LTXQ_UNLOCK(ltxq);
+ if (!withoutpkts && ltxq_empty)
+ goto out;
+
+ /*
+ * Make sure we do not double-schedule. We do this by checking tqe_prev,
+ * the previous entry in our tailq. tqe_prev is always valid if this entry
+ * is queued, tqe_next may be NULL if this is the only element in the list.
+ */
+ if (ltxq->txq_entry.tqe_prev != NULL)
+ goto out;
+
+ lhw = HW_TO_LHW(hw);
+ TAILQ_INSERT_TAIL(&lhw->scheduled_txqs[txq->ac], ltxq, txq_entry);
+out:
+ return;
+}
+
+void
+linuxkpi_ieee80211_handle_wake_tx_queue(struct ieee80211_hw *hw,
+ struct ieee80211_txq *txq)
+{
+ struct lkpi_hw *lhw;
+ struct ieee80211_txq *ntxq;
+ struct ieee80211_tx_control control;
+ struct sk_buff *skb;
+
+ lhw = HW_TO_LHW(hw);
+
+ LKPI_80211_LHW_TXQ_LOCK(lhw);
+ ieee80211_txq_schedule_start(hw, txq->ac);
+ do {
+ ntxq = ieee80211_next_txq(hw, txq->ac);
+ if (ntxq == NULL)
+ break;
+
+ memset(&control, 0, sizeof(control));
+ control.sta = ntxq->sta;
+ do {
+ skb = linuxkpi_ieee80211_tx_dequeue(hw, ntxq);
+ if (skb == NULL)
+ break;
+ lkpi_80211_mo_tx(hw, &control, skb);
+ } while(1);
+
+ ieee80211_return_txq(hw, ntxq, false);
+ } while (1);
+ ieee80211_txq_schedule_end(hw, txq->ac);
+ LKPI_80211_LHW_TXQ_UNLOCK(lhw);
+}
+
+/* -------------------------------------------------------------------------- */
+
+struct lkpi_cfg80211_bss {
+ u_int refcnt;
+ struct cfg80211_bss bss;
+};
+
+struct lkpi_cfg80211_get_bss_iter_lookup {
+ struct wiphy *wiphy;
+ struct linuxkpi_ieee80211_channel *chan;
+ const uint8_t *bssid;
+ const uint8_t *ssid;
+ size_t ssid_len;
+ enum ieee80211_bss_type bss_type;
+ enum ieee80211_privacy privacy;
+
+ /*
+ * Something to store a copy of the result as the net80211 scan cache
+ * is not refoucnted so a scan entry might go away any time.
+ */
+ bool match;
+ struct cfg80211_bss *bss;
+};
+
+static void
+lkpi_cfg80211_get_bss_iterf(void *arg, const struct ieee80211_scan_entry *se)
+{
+ struct lkpi_cfg80211_get_bss_iter_lookup *lookup;
+ size_t ielen;
+
+ lookup = arg;
+
+ /* Do not try to find another match. */
+ if (lookup->match)
+ return;
+
+ /* Nothing to store result. */
+ if (lookup->bss == NULL)
+ return;
+
+ if (lookup->privacy != IEEE80211_PRIVACY_ANY) {
+ /* if (se->se_capinfo & IEEE80211_CAPINFO_PRIVACY) */
+ /* We have no idea what to compare to as the drivers only request ANY */
+ return;
+ }
+
+ if (lookup->bss_type != IEEE80211_BSS_TYPE_ANY) {
+ /* if (se->se_capinfo & (IEEE80211_CAPINFO_IBSS|IEEE80211_CAPINFO_ESS)) */
+ /* We have no idea what to compare to as the drivers only request ANY */
+ return;
+ }
+
+ if (lookup->chan != NULL) {
+ struct linuxkpi_ieee80211_channel *chan;
+
+ chan = linuxkpi_ieee80211_get_channel(lookup->wiphy,
+ se->se_chan->ic_freq);
+ if (chan == NULL || chan != lookup->chan)
+ return;
+ }
+
+ if (lookup->bssid && !IEEE80211_ADDR_EQ(lookup->bssid, se->se_bssid))
+ return;
+
+ if (lookup->ssid) {
+ if (lookup->ssid_len != se->se_ssid[1] ||
+ se->se_ssid[1] == 0)
+ return;
+ if (memcmp(lookup->ssid, se->se_ssid+2, lookup->ssid_len) != 0)
+ return;
+ }
+
+ ielen = se->se_ies.len;
+
+ lookup->bss->ies = malloc(sizeof(*lookup->bss->ies) + ielen,
+ M_LKPI80211, M_NOWAIT | M_ZERO);
+ if (lookup->bss->ies == NULL)
+ return;
+
+ lookup->bss->ies->data = (uint8_t *)lookup->bss->ies + sizeof(*lookup->bss->ies);
+ lookup->bss->ies->len = ielen;
+ if (ielen)
+ memcpy(lookup->bss->ies->data, se->se_ies.data, ielen);
+
+ lookup->match = true;
+}
+
+struct cfg80211_bss *
+linuxkpi_cfg80211_get_bss(struct wiphy *wiphy, struct linuxkpi_ieee80211_channel *chan,
+ const uint8_t *bssid, const uint8_t *ssid, size_t ssid_len,
+ enum ieee80211_bss_type bss_type, enum ieee80211_privacy privacy)
+{
+ struct lkpi_cfg80211_bss *lbss;
+ struct lkpi_cfg80211_get_bss_iter_lookup lookup;
+ struct lkpi_hw *lhw;
+ struct ieee80211vap *vap;
+
+ lhw = wiphy_priv(wiphy);
+
+ /* Let's hope we can alloc. */
+ lbss = malloc(sizeof(*lbss), M_LKPI80211, M_NOWAIT | M_ZERO);
+ if (lbss == NULL) {
+ ic_printf(lhw->ic, "%s: alloc failed.\n", __func__);
+ return (NULL);
+ }
+
+ lookup.wiphy = wiphy;
+ lookup.chan = chan;
+ lookup.bssid = bssid;
+ lookup.ssid = ssid;
+ lookup.ssid_len = ssid_len;
+ lookup.bss_type = bss_type;
+ lookup.privacy = privacy;
+ lookup.match = false;
+ lookup.bss = &lbss->bss;
+
+ IMPROVE("Iterate over all VAPs comparing perm_addr and addresses?");
+ vap = TAILQ_FIRST(&lhw->ic->ic_vaps);
+ ieee80211_scan_iterate(vap, lkpi_cfg80211_get_bss_iterf, &lookup);
+ if (!lookup.match) {
+ free(lbss, M_LKPI80211);
+ return (NULL);
+ }
+
+ refcount_init(&lbss->refcnt, 1);
+ return (&lbss->bss);
+}
+
+void
+linuxkpi_cfg80211_put_bss(struct wiphy *wiphy, struct cfg80211_bss *bss)
+{
+ struct lkpi_cfg80211_bss *lbss;
+
+ lbss = container_of(bss, struct lkpi_cfg80211_bss, bss);
+
+ /* Free everything again on refcount ... */
+ if (refcount_release(&lbss->refcnt)) {
+ free(lbss->bss.ies, M_LKPI80211);
+ free(lbss, M_LKPI80211);
+ }
+}
+
+void
+linuxkpi_cfg80211_bss_flush(struct wiphy *wiphy)
+{
+ struct lkpi_hw *lhw;
+ struct ieee80211com *ic;
+ struct ieee80211vap *vap;
+
+ lhw = wiphy_priv(wiphy);
+ ic = lhw->ic;
+
+ /*
+ * If we haven't called ieee80211_ifattach() yet
+ * or there is no VAP, there are no scans to flush.
+ */
+ if (ic == NULL ||
+ (lhw->sc_flags & LKPI_MAC80211_DRV_STARTED) == 0)
+ return;
+
+ /* Should only happen on the current one? Not seen it late enough. */
+ IEEE80211_LOCK(ic);
+ TAILQ_FOREACH(vap, &ic->ic_vaps, iv_next)
+ ieee80211_scan_flush(vap);
+ IEEE80211_UNLOCK(ic);
+}
+
+/* -------------------------------------------------------------------------- */
+
+/*
+ * hw->conf get initialized/set in various places for us:
+ * - linuxkpi_ieee80211_alloc_hw(): flags
+ * - linuxkpi_ieee80211_ifattach(): chandef
+ * - lkpi_ic_vap_create(): listen_interval
+ * - lkpi_ic_set_channel(): chandef, flags
+ */
+
+int lkpi_80211_update_chandef(struct ieee80211_hw *hw,
+ struct ieee80211_chanctx_conf *new)
+{
+ struct cfg80211_chan_def *cd;
+ uint32_t changed;
+ int error;
+
+ changed = 0;
+ if (new == NULL || new->def.chan == NULL)
+ cd = NULL;
+ else
+ cd = &new->def;
+
+ if (cd && cd->chan != hw->conf.chandef.chan) {
+ /* Copy; the chan pointer is fine and will stay valid. */
+ hw->conf.chandef = *cd;
+ changed |= IEEE80211_CONF_CHANGE_CHANNEL;
+ }
+ IMPROVE("IEEE80211_CONF_CHANGE_PS, IEEE80211_CONF_CHANGE_POWER");
+
+ if (changed == 0)
+ return (0);
+
+ error = lkpi_80211_mo_config(hw, changed);
+ return (error);
+}
+
+/* -------------------------------------------------------------------------- */
+
+MODULE_VERSION(linuxkpi_wlan, 1);
+MODULE_DEPEND(linuxkpi_wlan, linuxkpi, 1, 1, 1);
+MODULE_DEPEND(linuxkpi_wlan, wlan, 1, 1, 1);
diff --git a/sys/compat/linuxkpi/common/src/linux_80211.h b/sys/compat/linuxkpi/common/src/linux_80211.h
new file mode 100644
index 000000000000..0dfcd7646c34
--- /dev/null
+++ b/sys/compat/linuxkpi/common/src/linux_80211.h
@@ -0,0 +1,491 @@
+/*-
+ * Copyright (c) 2020-2023 The FreeBSD Foundation
+ * Copyright (c) 2020-2021 Bjoern A. Zeeb
+ *
+ * This software was developed by Björn Zeeb under sponsorship from
+ * the FreeBSD Foundation.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``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 OR CONTRIBUTORS 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.
+ */
+
+/*
+ * Public functions are called linuxkpi_*().
+ * Internal (static) functions are called lkpi_*().
+ *
+ * The internal structures holding metadata over public structures are also
+ * called lkpi_xxx (usually with a member at the end called xxx).
+ * Note: we do not replicate the structure names but the general variable names
+ * for these (e.g., struct hw -> struct lkpi_hw, struct sta -> struct lkpi_sta).
+ * There are macros to access one from the other.
+ * We call the internal versions lxxx (e.g., hw -> lhw, sta -> lsta).
+ */
+
+#ifndef _LKPI_SRC_LINUX_80211_H
+#define _LKPI_SRC_LINUX_80211_H
+
+#include "opt_wlan.h"
+
+#if defined(IEEE80211_DEBUG) && !defined(LINUXKPI_DEBUG_80211)
+#define LINUXKPI_DEBUG_80211
+#endif
+
+/* #define LINUXKPI_DEBUG_80211 */
+
+#ifndef D80211_TODO
+#define D80211_TODO 0x00000001
+#endif
+#ifndef D80211_IMPROVE
+#define D80211_IMPROVE 0x00000002
+#endif
+#define D80211_IMPROVE_TXQ 0x00000004
+#define D80211_TRACE 0x00000010
+#define D80211_TRACEOK 0x00000020
+#define D80211_SCAN 0x00000040
+#define D80211_SCAN_BEACON 0x00000080
+#define D80211_TRACE_TX 0x00000100
+#define D80211_TRACE_TX_DUMP 0x00000200
+#define D80211_TRACE_RX 0x00001000
+#define D80211_TRACE_RX_DUMP 0x00002000
+#define D80211_TRACE_RX_BEACONS 0x00004000
+#define D80211_TRACEX (D80211_TRACE_TX|D80211_TRACE_RX)
+#define D80211_TRACEX_DUMP (D80211_TRACE_TX_DUMP|D80211_TRACE_RX_DUMP)
+#define D80211_TRACE_STA 0x00010000
+#define D80211_TRACE_HW_CRYPTO 0x00020000
+#define D80211_TRACE_MO 0x00100000
+#define D80211_TRACE_MODE 0x0f000000
+#define D80211_TRACE_MODE_HT 0x01000000
+#define D80211_TRACE_MODE_VHT 0x02000000
+#define D80211_TRACE_MODE_HE 0x04000000
+#define D80211_TRACE_MODE_EHT 0x08000000
+
+#ifdef LINUXKPI_DEBUG_80211
+#define TRACE_SCAN(ic, fmt, ...) \
+ if (linuxkpi_debug_80211 & D80211_SCAN) \
+ printf("%s:%d: %s SCAN " fmt "\n", \
+ __func__, __LINE__, ic->ic_name, ##__VA_ARGS__)
+#define TRACE_SCAN_BEACON(ic, fmt, ...) \
+ if (linuxkpi_debug_80211 & D80211_SCAN_BEACON) \
+ printf("%s:%d: %s SCAN " fmt "\n", \
+ __func__, __LINE__, ic->ic_name, ##__VA_ARGS__)
+#else
+#define TRACE_SCAN(...) do {} while (0)
+#define TRACE_SCAN_BEACON(...) do {} while (0)
+#endif
+
+#define IMPROVE_TXQ(...) \
+ if (linuxkpi_debug_80211 & D80211_IMPROVE_TXQ) \
+ printf("%s:%d: XXX LKPI80211 IMPROVE_TXQ\n", __func__, __LINE__)
+
+#define IMPROVE_HT(fmt, ...) \
+ if (linuxkpi_debug_80211 & D80211_TRACE_MODE_HT) \
+ printf("%s:%d: XXX LKPI80211 IMPROVE_HT " fmt "\n", \
+ __func__, __LINE__, ##__VA_ARGS__);
+
+#define MTAG_ABI_LKPI80211 1707696513 /* LinuxKPI 802.11 KBI */
+
+#ifdef LKPI_80211_USE_MTAG
+/*
+ * Deferred RX path.
+ * We need to pass *ni along (and possibly more in the future so
+ * we use a struct right from the start.
+ */
+#define LKPI80211_TAG_RXNI 0 /* deferred RX path */
+struct lkpi_80211_tag_rxni {
+ struct ieee80211_node *ni; /* MUST hold a reference to it. */
+};
+#endif
+
+struct lkpi_radiotap_tx_hdr {
+ struct ieee80211_radiotap_header wt_ihdr;
+ uint8_t wt_flags;
+ uint8_t wt_rate;
+ uint16_t wt_chan_freq;
+ uint16_t wt_chan_flags;
+} __packed;
+#define LKPI_RTAP_TX_FLAGS_PRESENT \
+ ((1 << IEEE80211_RADIOTAP_FLAGS) | \
+ (1 << IEEE80211_RADIOTAP_RATE) | \
+ (1 << IEEE80211_RADIOTAP_CHANNEL))
+
+struct lkpi_radiotap_rx_hdr {
+ struct ieee80211_radiotap_header wr_ihdr;
+ uint64_t wr_tsft;
+ uint8_t wr_flags;
+ uint8_t wr_rate;
+ uint16_t wr_chan_freq;
+ uint16_t wr_chan_flags;
+ int8_t wr_dbm_antsignal;
+ int8_t wr_dbm_antnoise;
+} __packed __aligned(8);
+#define LKPI_RTAP_RX_FLAGS_PRESENT \
+ ((1 << IEEE80211_RADIOTAP_TSFT) | \
+ (1 << IEEE80211_RADIOTAP_FLAGS) | \
+ (1 << IEEE80211_RADIOTAP_RATE) | \
+ (1 << IEEE80211_RADIOTAP_CHANNEL) | \
+ (1 << IEEE80211_RADIOTAP_DBM_ANTSIGNAL) | \
+ (1 << IEEE80211_RADIOTAP_DBM_ANTNOISE))
+
+struct lkpi_hw;
+
+struct lkpi_txq {
+ TAILQ_ENTRY(lkpi_txq) txq_entry;
+
+ struct mtx ltxq_mtx;
+ bool seen_dequeue;
+ bool stopped;
+ uint32_t txq_generation;
+ struct sk_buff_head skbq;
+
+ /* Must be last! */
+ struct ieee80211_txq txq __aligned(CACHE_LINE_SIZE);
+};
+#define TXQ_TO_LTXQ(_txq) container_of(_txq, struct lkpi_txq, txq)
+
+
+struct lkpi_sta {
+ struct list_head lsta_list;
+ struct ieee80211_node *ni;
+ struct ieee80211_hw *hw; /* back pointer f. locking. */
+
+ /* Deferred TX path. */
+ /* Eventually we might want to migrate this into net80211 entirely. */
+ /* XXX-BZ can we use sta->txq[] instead directly? */
+ struct task txq_task;
+ struct mbufq txq;
+ struct mtx txq_mtx;
+
+ struct ieee80211_key_conf *kc[IEEE80211_WEP_NKID];
+ enum ieee80211_sta_state state;
+ bool txq_ready; /* Can we run the taskq? */
+ bool added_to_drv; /* Driver knows; i.e. we called ...(). */
+ bool in_mgd; /* XXX-BZ should this be per-vif? */
+
+ struct station_info sinfo; /* statistics */
+
+ /* Must be last! */
+ struct ieee80211_sta sta __aligned(CACHE_LINE_SIZE);
+};
+#define STA_TO_LSTA(_sta) container_of(_sta, struct lkpi_sta, sta)
+#define LSTA_TO_STA(_lsta) (&(_lsta)->sta)
+
+/* Either protected by wiphy lock or rcu for the list. */
+struct lkpi_vif {
+ TAILQ_ENTRY(lkpi_vif) lvif_entry;
+ struct ieee80211vap iv_vap;
+ eventhandler_tag lvif_ifllevent;
+
+ struct sysctl_ctx_list sysctl_ctx;
+
+ struct mtx mtx;
+ struct wireless_dev wdev;
+
+ /* Other local stuff. */
+ int (*iv_newstate)(struct ieee80211vap *,
+ enum ieee80211_state, int);
+ struct ieee80211_node * (*iv_update_bss)(struct ieee80211vap *,
+ struct ieee80211_node *);
+ void (*iv_recv_mgmt)(struct ieee80211_node *,
+ struct mbuf *, int,
+ const struct ieee80211_rx_stats *,
+ int, int);
+ struct task sw_scan_task;
+
+ struct list_head lsta_list;
+
+ struct lkpi_sta *lvif_bss;
+
+ struct ieee80211_node *key_update_iv_bss;
+ int ic_unlocked; /* Count of ic unlocks pending (*mo_set_key) */
+ int nt_unlocked; /* Count of nt unlocks pending (*mo_set_key) */
+ int beacons; /* # of beacons since assoc */
+ bool lvif_bss_synched;
+ bool added_to_drv; /* Driver knows; i.e. we called add_interface(). */
+
+ bool hw_queue_stopped[IEEE80211_NUM_ACS];
+
+ /* Must be last! */
+ struct ieee80211_vif vif __aligned(CACHE_LINE_SIZE);
+};
+#define VAP_TO_LVIF(_vap) container_of(_vap, struct lkpi_vif, iv_vap)
+#define LVIF_TO_VAP(_lvif) (&(_lvif)->iv_vap)
+#define VIF_TO_LVIF(_vif) container_of(_vif, struct lkpi_vif, vif)
+#define LVIF_TO_VIF(_lvif) (&(_lvif)->vif)
+
+
+struct lkpi_hw { /* name it mac80211_sc? */
+ const struct ieee80211_ops *ops;
+ struct ieee80211_scan_request *hw_req;
+ struct workqueue_struct *workq;
+
+ /* FreeBSD specific compat. */
+ /* Linux device is in hw.wiphy->dev after SET_IEEE80211_DEV(). */
+ struct ieee80211com *ic;
+ struct lkpi_radiotap_tx_hdr rtap_tx;
+ struct lkpi_radiotap_rx_hdr rtap_rx;
+
+ TAILQ_HEAD(, lkpi_vif) lvif_head;
+ struct sx lvif_sx;
+
+ struct list_head lchanctx_list;
+ struct netdev_hw_addr_list mc_list;
+ unsigned int mc_flags;
+ struct sx mc_sx;
+
+ struct mtx txq_mtx;
+ uint32_t txq_generation[IEEE80211_NUM_ACS];
+ TAILQ_HEAD(, lkpi_txq) scheduled_txqs[IEEE80211_NUM_ACS];
+ spinlock_t txq_lock;
+
+ /* Deferred RX path. */
+ struct task rxq_task;
+ struct mbufq rxq;
+ struct mtx rxq_mtx;
+
+ /* Scan functions we overload to handle depending on scan mode. */
+ void (*ic_scan_curchan)(struct ieee80211_scan_state *,
+ unsigned long);
+ void (*ic_scan_mindwell)(struct ieee80211_scan_state *);
+
+ /* Node functions we overload to sync state. */
+ struct ieee80211_node * (*ic_node_alloc)(struct ieee80211vap *,
+ const uint8_t [IEEE80211_ADDR_LEN]);
+ int (*ic_node_init)(struct ieee80211_node *);
+ void (*ic_node_cleanup)(struct ieee80211_node *);
+ void (*ic_node_free)(struct ieee80211_node *);
+
+ /* HT and later functions. */
+ int (*ic_recv_action)(struct ieee80211_node *,
+ const struct ieee80211_frame *,
+ const uint8_t *, const uint8_t *);
+ int (*ic_send_action)(struct ieee80211_node *,
+ int, int, void *);
+ int (*ic_ampdu_enable)(struct ieee80211_node *,
+ struct ieee80211_tx_ampdu *);
+ int (*ic_addba_request)(struct ieee80211_node *,
+ struct ieee80211_tx_ampdu *, int, int, int);
+ int (*ic_addba_response)(struct ieee80211_node *,
+ struct ieee80211_tx_ampdu *, int, int, int);
+ void (*ic_addba_stop)(struct ieee80211_node *,
+ struct ieee80211_tx_ampdu *);
+ void (*ic_addba_response_timeout)(struct ieee80211_node *,
+ struct ieee80211_tx_ampdu *);
+ void (*ic_bar_response)(struct ieee80211_node *,
+ struct ieee80211_tx_ampdu *, int);
+ int (*ic_ampdu_rx_start)(struct ieee80211_node *,
+ struct ieee80211_rx_ampdu *, int, int, int);
+ void (*ic_ampdu_rx_stop)(struct ieee80211_node *,
+ struct ieee80211_rx_ampdu *);
+
+#define LKPI_MAC80211_DRV_STARTED 0x00000001
+ uint32_t sc_flags;
+#define LKPI_LHW_SCAN_RUNNING 0x00000001
+#define LKPI_LHW_SCAN_HW 0x00000002
+ uint32_t scan_flags;
+ struct mtx scan_mtx;
+
+ int supbands; /* Number of supported bands. */
+ int max_rates; /* Maximum number of bitrates supported in any channel. */
+ int scan_ie_len; /* Length of common per-band scan IEs. */
+
+ bool mc_all_multi;
+ bool update_wme;
+ bool rxq_stopped;
+
+ /* Must be last! */
+ struct ieee80211_hw hw __aligned(CACHE_LINE_SIZE);
+};
+#define LHW_TO_HW(_lhw) (&(_lhw)->hw)
+#define HW_TO_LHW(_hw) container_of(_hw, struct lkpi_hw, hw)
+
+#define LKPI_LHW_SCAN_BITS \
+ "\010\1RUNING\2HW"
+
+struct lkpi_chanctx {
+ struct list_head entry;
+
+ bool added_to_drv; /* Managed by MO */
+
+ struct ieee80211_chanctx_conf chanctx_conf __aligned(CACHE_LINE_SIZE);
+};
+#define LCHANCTX_TO_CHANCTX_CONF(_lchanctx) \
+ (&(_lchanctx)->chanctx_conf)
+#define CHANCTX_CONF_TO_LCHANCTX(_conf) \
+ container_of(_conf, struct lkpi_chanctx, chanctx_conf)
+
+struct lkpi_wiphy {
+ const struct cfg80211_ops *ops;
+
+ struct work_struct wwk;
+ struct list_head wwk_list;
+ struct mtx wwk_mtx;
+
+ /* Must be last! */
+ struct wiphy wiphy __aligned(CACHE_LINE_SIZE);
+};
+#define WIPHY_TO_LWIPHY(_wiphy) container_of(_wiphy, struct lkpi_wiphy, wiphy)
+#define LWIPHY_TO_WIPHY(_lwiphy) (&(_lwiphy)->wiphy)
+
+#define LKPI_80211_LWIPHY_WORK_LOCK_INIT(_lwiphy) \
+ mtx_init(&(_lwiphy)->wwk_mtx, "lwiphy-work", NULL, MTX_DEF);
+#define LKPI_80211_LWIPHY_WORK_LOCK_DESTROY(_lwiphy) \
+ mtx_destroy(&(_lwiphy)->wwk_mtx)
+#define LKPI_80211_LWIPHY_WORK_LOCK(_lwiphy) \
+ mtx_lock(&(_lwiphy)->wwk_mtx)
+#define LKPI_80211_LWIPHY_WORK_UNLOCK(_lwiphy) \
+ mtx_unlock(&(_lwiphy)->wwk_mtx)
+#define LKPI_80211_LWIPHY_WORK_LOCK_ASSERT(_lwiphy) \
+ mtx_assert(&(_lwiphy)->wwk_mtx, MA_OWNED)
+#define LKPI_80211_LWIPHY_WORK_UNLOCK_ASSERT(_lwiphy) \
+ mtx_assert(&(_lwiphy)->wwk_mtx, MA_NOTOWNED)
+
+#define LKPI_80211_LHW_SCAN_LOCK_INIT(_lhw) \
+ mtx_init(&(_lhw)->scan_mtx, "lhw-scan", NULL, MTX_DEF | MTX_RECURSE);
+#define LKPI_80211_LHW_SCAN_LOCK_DESTROY(_lhw) \
+ mtx_destroy(&(_lhw)->scan_mtx);
+#define LKPI_80211_LHW_SCAN_LOCK(_lhw) \
+ mtx_lock(&(_lhw)->scan_mtx)
+#define LKPI_80211_LHW_SCAN_UNLOCK(_lhw) \
+ mtx_unlock(&(_lhw)->scan_mtx)
+#define LKPI_80211_LHW_SCAN_LOCK_ASSERT(_lhw) \
+ mtx_assert(&(_lhw)->scan_mtx, MA_OWNED)
+#define LKPI_80211_LHW_SCAN_UNLOCK_ASSERT(_lhw) \
+ mtx_assert(&(_lhw)->scan_mtx, MA_NOTOWNED)
+
+#define LKPI_80211_LHW_TXQ_LOCK_INIT(_lhw) \
+ mtx_init(&(_lhw)->txq_mtx, "lhw-txq", NULL, MTX_DEF | MTX_RECURSE);
+#define LKPI_80211_LHW_TXQ_LOCK_DESTROY(_lhw) \
+ mtx_destroy(&(_lhw)->txq_mtx);
+#define LKPI_80211_LHW_TXQ_LOCK(_lhw) \
+ mtx_lock(&(_lhw)->txq_mtx)
+#define LKPI_80211_LHW_TXQ_UNLOCK(_lhw) \
+ mtx_unlock(&(_lhw)->txq_mtx)
+#define LKPI_80211_LHW_TXQ_LOCK_ASSERT(_lhw) \
+ mtx_assert(&(_lhw)->txq_mtx, MA_OWNED)
+#define LKPI_80211_LHW_TXQ_UNLOCK_ASSERT(_lhw) \
+ mtx_assert(&(_lhw)->txq_mtx, MA_NOTOWNED)
+
+#define LKPI_80211_LHW_RXQ_LOCK_INIT(_lhw) \
+ mtx_init(&(_lhw)->rxq_mtx, "lhw-rxq", NULL, MTX_DEF | MTX_RECURSE);
+#define LKPI_80211_LHW_RXQ_LOCK_DESTROY(_lhw) \
+ mtx_destroy(&(_lhw)->rxq_mtx);
+#define LKPI_80211_LHW_RXQ_LOCK(_lhw) \
+ mtx_lock(&(_lhw)->rxq_mtx)
+#define LKPI_80211_LHW_RXQ_UNLOCK(_lhw) \
+ mtx_unlock(&(_lhw)->rxq_mtx)
+#define LKPI_80211_LHW_RXQ_LOCK_ASSERT(_lhw) \
+ mtx_assert(&(_lhw)->rxq_mtx, MA_OWNED)
+#define LKPI_80211_LHW_RXQ_UNLOCK_ASSERT(_lhw) \
+ mtx_assert(&(_lhw)->rxq_mtx, MA_NOTOWNED)
+
+#define LKPI_80211_LHW_LVIF_LOCK(_lhw) sx_xlock(&(_lhw)->lvif_sx)
+#define LKPI_80211_LHW_LVIF_UNLOCK(_lhw) sx_xunlock(&(_lhw)->lvif_sx)
+
+#define LKPI_80211_LHW_MC_LOCK_INIT(_lhw) \
+ sx_init_flags(&lhw->mc_sx, "lhw-mc", 0);
+#define LKPI_80211_LHW_MC_LOCK_DESTROY(_lhw) \
+ sx_destroy(&lhw->mc_sx);
+#define LKPI_80211_LHW_MC_LOCK(_lhw) sx_xlock(&(_lhw)->mc_sx)
+#define LKPI_80211_LHW_MC_UNLOCK(_lhw) sx_xunlock(&(_lhw)->mc_sx)
+
+#define LKPI_80211_LVIF_LOCK(_lvif) mtx_lock(&(_lvif)->mtx)
+#define LKPI_80211_LVIF_UNLOCK(_lvif) mtx_unlock(&(_lvif)->mtx)
+
+#define LKPI_80211_LSTA_TXQ_LOCK_INIT(_lsta) \
+ mtx_init(&(_lsta)->txq_mtx, "lsta-txq", NULL, MTX_DEF);
+#define LKPI_80211_LSTA_TXQ_LOCK_DESTROY(_lsta) \
+ mtx_destroy(&(_lsta)->txq_mtx);
+#define LKPI_80211_LSTA_TXQ_LOCK(_lsta) \
+ mtx_lock(&(_lsta)->txq_mtx)
+#define LKPI_80211_LSTA_TXQ_UNLOCK(_lsta) \
+ mtx_unlock(&(_lsta)->txq_mtx)
+#define LKPI_80211_LSTA_TXQ_LOCK_ASSERT(_lsta) \
+ mtx_assert(&(_lsta)->txq_mtx, MA_OWNED)
+#define LKPI_80211_LSTA_TXQ_UNLOCK_ASSERT(_lsta) \
+ mtx_assert(&(_lsta)->txq_mtx, MA_NOTOWNED)
+
+#define LKPI_80211_LTXQ_LOCK_INIT(_ltxq) \
+ mtx_init(&(_ltxq)->ltxq_mtx, "ltxq", NULL, MTX_DEF);
+#define LKPI_80211_LTXQ_LOCK_DESTROY(_ltxq) \
+ mtx_destroy(&(_ltxq)->ltxq_mtx);
+#define LKPI_80211_LTXQ_LOCK(_ltxq) \
+ mtx_lock(&(_ltxq)->ltxq_mtx)
+#define LKPI_80211_LTXQ_UNLOCK(_ltxq) \
+ mtx_unlock(&(_ltxq)->ltxq_mtx)
+#define LKPI_80211_LTXQ_LOCK_ASSERT(_ltxq) \
+ mtx_assert(&(_ltxq)->ltxq_mtx, MA_OWNED)
+#define LKPI_80211_LTXQ_UNLOCK_ASSERT(_ltxq) \
+ mtx_assert(&(_ltxq)->ltxq_mtx, MA_NOTOWNED)
+
+int lkpi_80211_mo_start(struct ieee80211_hw *);
+void lkpi_80211_mo_stop(struct ieee80211_hw *, bool);
+int lkpi_80211_mo_get_antenna(struct ieee80211_hw *, u32 *, u32 *);
+int lkpi_80211_mo_set_frag_threshold(struct ieee80211_hw *, uint32_t);
+int lkpi_80211_mo_set_rts_threshold(struct ieee80211_hw *, uint32_t);
+int lkpi_80211_mo_add_interface(struct ieee80211_hw *, struct ieee80211_vif *);
+void lkpi_80211_mo_remove_interface(struct ieee80211_hw *, struct ieee80211_vif *);
+int lkpi_80211_mo_hw_scan(struct ieee80211_hw *, struct ieee80211_vif *,
+ struct ieee80211_scan_request *);
+void lkpi_80211_mo_cancel_hw_scan(struct ieee80211_hw *, struct ieee80211_vif *);
+void lkpi_80211_mo_sw_scan_complete(struct ieee80211_hw *, struct ieee80211_vif *);
+void lkpi_80211_mo_sw_scan_start(struct ieee80211_hw *, struct ieee80211_vif *,
+ const u8 *);
+u64 lkpi_80211_mo_prepare_multicast(struct ieee80211_hw *,
+ struct netdev_hw_addr_list *);
+void lkpi_80211_mo_configure_filter(struct ieee80211_hw *, unsigned int,
+ unsigned int *, u64);
+int lkpi_80211_mo_sta_state(struct ieee80211_hw *, struct ieee80211_vif *,
+ struct lkpi_sta *, enum ieee80211_sta_state);
+int lkpi_80211_mo_config(struct ieee80211_hw *, uint32_t);
+int lkpi_80211_mo_assign_vif_chanctx(struct ieee80211_hw *, struct ieee80211_vif *,
+ struct ieee80211_bss_conf *, struct ieee80211_chanctx_conf *);
+void lkpi_80211_mo_unassign_vif_chanctx(struct ieee80211_hw *, struct ieee80211_vif *,
+ struct ieee80211_bss_conf *, struct ieee80211_chanctx_conf *);
+int lkpi_80211_mo_add_chanctx(struct ieee80211_hw *, struct ieee80211_chanctx_conf *);
+void lkpi_80211_mo_change_chanctx(struct ieee80211_hw *,
+ struct ieee80211_chanctx_conf *, uint32_t);
+void lkpi_80211_mo_remove_chanctx(struct ieee80211_hw *,
+ struct ieee80211_chanctx_conf *);
+void lkpi_80211_mo_bss_info_changed(struct ieee80211_hw *, struct ieee80211_vif *,
+ struct ieee80211_bss_conf *, uint64_t);
+int lkpi_80211_mo_conf_tx(struct ieee80211_hw *, struct ieee80211_vif *,
+ uint32_t, uint16_t, const struct ieee80211_tx_queue_params *);
+void lkpi_80211_mo_flush(struct ieee80211_hw *, struct ieee80211_vif *,
+ uint32_t, bool);
+void lkpi_80211_mo_mgd_prepare_tx(struct ieee80211_hw *, struct ieee80211_vif *,
+ struct ieee80211_prep_tx_info *);
+void lkpi_80211_mo_mgd_complete_tx(struct ieee80211_hw *, struct ieee80211_vif *,
+ struct ieee80211_prep_tx_info *);
+void lkpi_80211_mo_tx(struct ieee80211_hw *, struct ieee80211_tx_control *,
+ struct sk_buff *);
+void lkpi_80211_mo_wake_tx_queue(struct ieee80211_hw *, struct ieee80211_txq *);
+void lkpi_80211_mo_sync_rx_queues(struct ieee80211_hw *);
+void lkpi_80211_mo_sta_pre_rcu_remove(struct ieee80211_hw *,
+ struct ieee80211_vif *, struct ieee80211_sta *);
+int lkpi_80211_mo_set_key(struct ieee80211_hw *, enum set_key_cmd,
+ struct ieee80211_vif *, struct ieee80211_sta *,
+ struct ieee80211_key_conf *);
+int lkpi_80211_mo_ampdu_action(struct ieee80211_hw *, struct ieee80211_vif *,
+ struct ieee80211_ampdu_params *);
+int lkpi_80211_mo_sta_statistics(struct ieee80211_hw *, struct ieee80211_vif *,
+ struct ieee80211_sta *, struct station_info *);
+
+#endif /* _LKPI_SRC_LINUX_80211_H */
diff --git a/sys/compat/linuxkpi/common/src/linux_80211_macops.c b/sys/compat/linuxkpi/common/src/linux_80211_macops.c
new file mode 100644
index 000000000000..d9e82a6d64ee
--- /dev/null
+++ b/sys/compat/linuxkpi/common/src/linux_80211_macops.c
@@ -0,0 +1,762 @@
+/*-
+ * Copyright (c) 2021-2022 The FreeBSD Foundation
+ *
+ * This software was developed by Björn Zeeb under sponsorship from
+ * the FreeBSD Foundation.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``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 OR CONTRIBUTORS 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.
+ */
+
+#include <sys/param.h>
+#include <sys/types.h>
+#include <sys/kernel.h>
+#include <sys/errno.h>
+
+#define LINUXKPI_NET80211
+#include <net/mac80211.h>
+
+#include "linux_80211.h"
+
+/* Could be a different tracing framework later. */
+#ifdef LINUXKPI_DEBUG_80211
+#define LKPI_80211_TRACE_MO(fmt, ...) \
+ if (linuxkpi_debug_80211 & D80211_TRACE_MO) \
+ printf("LKPI_80211_TRACE_MO %s:%d: %d %d %lu: " fmt "\n", \
+ __func__, __LINE__, curcpu, curthread->td_tid, \
+ jiffies, ##__VA_ARGS__)
+#else
+#define LKPI_80211_TRACE_MO(...) do { } while(0)
+#endif
+
+int
+lkpi_80211_mo_start(struct ieee80211_hw *hw)
+{
+ struct lkpi_hw *lhw;
+ int error;
+
+ lockdep_assert_wiphy(hw->wiphy);
+
+ lhw = HW_TO_LHW(hw);
+ if (lhw->ops->start == NULL) {
+ error = EOPNOTSUPP;
+ goto out;
+ }
+
+ if ((lhw->sc_flags & LKPI_MAC80211_DRV_STARTED)) {
+ /* Trying to start twice is an error. */
+ error = EEXIST;
+ goto out;
+ }
+ LKPI_80211_TRACE_MO("hw %p", hw);
+ error = lhw->ops->start(hw);
+ if (error == 0)
+ lhw->sc_flags |= LKPI_MAC80211_DRV_STARTED;
+
+out:
+ return (error);
+}
+
+void
+lkpi_80211_mo_stop(struct ieee80211_hw *hw, bool suspend)
+{
+ struct lkpi_hw *lhw;
+
+ lhw = HW_TO_LHW(hw);
+ if (lhw->ops->stop == NULL)
+ return;
+
+ LKPI_80211_TRACE_MO("hw %p suspend %d", hw, suspend);
+ lhw->ops->stop(hw, suspend);
+ lhw->sc_flags &= ~LKPI_MAC80211_DRV_STARTED;
+}
+
+int
+lkpi_80211_mo_get_antenna(struct ieee80211_hw *hw, u32 *txs, u32 *rxs)
+{
+ struct lkpi_hw *lhw;
+ int error;
+
+ lhw = HW_TO_LHW(hw);
+ if (lhw->ops->get_antenna == NULL) {
+ error = EOPNOTSUPP;
+ goto out;
+ }
+
+ LKPI_80211_TRACE_MO("hw %p", hw);
+ LKPI_80211_TRACE_MO("TODO link/radio_idx");
+ error = lhw->ops->get_antenna(hw, 0, txs, rxs);
+
+out:
+ return (error);
+}
+
+int
+lkpi_80211_mo_set_frag_threshold(struct ieee80211_hw *hw, uint32_t frag_th)
+{
+ struct lkpi_hw *lhw;
+ int error;
+
+ lhw = HW_TO_LHW(hw);
+ if (lhw->ops->set_frag_threshold == NULL) {
+ error = EOPNOTSUPP;
+ goto out;
+ }
+
+ LKPI_80211_TRACE_MO("hw %p frag_th %u", hw, frag_th);
+ LKPI_80211_TRACE_MO("TODO link/radio_idx");
+ error = lhw->ops->set_frag_threshold(hw, 0, frag_th);
+
+out:
+ return (error);
+}
+
+int
+lkpi_80211_mo_set_rts_threshold(struct ieee80211_hw *hw, uint32_t rts_th)
+{
+ struct lkpi_hw *lhw;
+ int error;
+
+ lhw = HW_TO_LHW(hw);
+ if (lhw->ops->set_rts_threshold == NULL) {
+ error = EOPNOTSUPP;
+ goto out;
+ }
+
+ LKPI_80211_TRACE_MO("hw %p rts_th %u", hw, rts_th);
+ LKPI_80211_TRACE_MO("TODO link/radio_idx");
+ error = lhw->ops->set_rts_threshold(hw, 0, rts_th);
+
+out:
+ return (error);
+}
+
+
+int
+lkpi_80211_mo_add_interface(struct ieee80211_hw *hw, struct ieee80211_vif *vif)
+{
+ struct lkpi_hw *lhw;
+ struct lkpi_vif *lvif;
+ int error;
+
+ lhw = HW_TO_LHW(hw);
+ if (lhw->ops->add_interface == NULL) {
+ error = EOPNOTSUPP;
+ goto out;
+ }
+
+ lvif = VIF_TO_LVIF(vif);
+ LKPI_80211_LVIF_LOCK(lvif);
+ if (lvif->added_to_drv) {
+ LKPI_80211_LVIF_UNLOCK(lvif);
+ /* Trying to add twice is an error. */
+ error = EEXIST;
+ goto out;
+ }
+ LKPI_80211_LVIF_UNLOCK(lvif);
+
+ LKPI_80211_TRACE_MO("hw %p vif %p", hw, vif);
+ error = lhw->ops->add_interface(hw, vif);
+ if (error == 0) {
+ LKPI_80211_LVIF_LOCK(lvif);
+ lvif->added_to_drv = true;
+ LKPI_80211_LVIF_UNLOCK(lvif);
+ }
+
+out:
+ return (error);
+}
+
+void
+lkpi_80211_mo_remove_interface(struct ieee80211_hw *hw, struct ieee80211_vif *vif)
+{
+ struct lkpi_hw *lhw;
+ struct lkpi_vif *lvif;
+
+ lhw = HW_TO_LHW(hw);
+ if (lhw->ops->remove_interface == NULL)
+ return;
+
+ lvif = VIF_TO_LVIF(vif);
+ LKPI_80211_LVIF_LOCK(lvif);
+ if (!lvif->added_to_drv) {
+ LKPI_80211_LVIF_UNLOCK(lvif);
+ return;
+ }
+ LKPI_80211_LVIF_UNLOCK(lvif);
+
+ LKPI_80211_TRACE_MO("hw %p vif %p", hw, vif);
+ lhw->ops->remove_interface(hw, vif);
+ LKPI_80211_LVIF_LOCK(lvif);
+ lvif->added_to_drv = false;
+ LKPI_80211_LVIF_UNLOCK(lvif);
+}
+
+
+int
+lkpi_80211_mo_hw_scan(struct ieee80211_hw *hw, struct ieee80211_vif *vif,
+ struct ieee80211_scan_request *sr)
+{
+ struct lkpi_hw *lhw;
+ int error;
+
+ /*
+ * MUST NOT return EPERM as that is a "magic number 1" based on rtw88
+ * driver indicating hw_scan is not supported despite the ops call
+ * being available.
+ */
+
+ lhw = HW_TO_LHW(hw);
+ if (lhw->ops->hw_scan == NULL) {
+ /* Return magic number to use sw scan. */
+ error = 1;
+ goto out;
+ }
+
+ LKPI_80211_TRACE_MO("CALLING hw %p vif %p sr %p", hw, vif, sr);
+ error = lhw->ops->hw_scan(hw, vif, sr);
+ LKPI_80211_TRACE_MO("RETURNING hw %p vif %p sr %p error %d", hw, vif, sr, error);
+
+out:
+ return (error);
+}
+
+void
+lkpi_80211_mo_cancel_hw_scan(struct ieee80211_hw *hw, struct ieee80211_vif *vif)
+{
+ struct lkpi_hw *lhw;
+
+ lhw = HW_TO_LHW(hw);
+ if (lhw->ops->cancel_hw_scan == NULL)
+ return;
+
+ LKPI_80211_TRACE_MO("hw %p vif %p", hw, vif);
+ lhw->ops->cancel_hw_scan(hw, vif);
+}
+
+void
+lkpi_80211_mo_sw_scan_complete(struct ieee80211_hw *hw, struct ieee80211_vif *vif)
+{
+ struct lkpi_hw *lhw;
+
+ lhw = HW_TO_LHW(hw);
+ if (lhw->ops->sw_scan_complete == NULL)
+ return;
+
+ LKPI_80211_TRACE_MO("hw %p vif %p", hw, vif);
+ lhw->ops->sw_scan_complete(hw, vif);
+ lhw->scan_flags &= ~LKPI_LHW_SCAN_RUNNING;
+}
+
+void
+lkpi_80211_mo_sw_scan_start(struct ieee80211_hw *hw, struct ieee80211_vif *vif,
+ const u8 *addr)
+{
+ struct lkpi_hw *lhw;
+
+ lhw = HW_TO_LHW(hw);
+ if (lhw->ops->sw_scan_start == NULL)
+ return;
+
+ LKPI_80211_TRACE_MO("hw %p vif %p", hw, vif);
+ lhw->ops->sw_scan_start(hw, vif, addr);
+}
+
+
+/*
+ * We keep the Linux type here; it really is an uintptr_t.
+ */
+u64
+lkpi_80211_mo_prepare_multicast(struct ieee80211_hw *hw,
+ struct netdev_hw_addr_list *mc_list)
+{
+ struct lkpi_hw *lhw;
+ u64 ptr;
+
+ lhw = HW_TO_LHW(hw);
+ if (lhw->ops->prepare_multicast == NULL)
+ return (0);
+
+ LKPI_80211_TRACE_MO("hw %p mc_list %p", hw, mc_list);
+ ptr = lhw->ops->prepare_multicast(hw, mc_list);
+ return (ptr);
+}
+
+void
+lkpi_80211_mo_configure_filter(struct ieee80211_hw *hw, unsigned int changed_flags,
+ unsigned int *total_flags, u64 mc_ptr)
+{
+ struct lkpi_hw *lhw;
+
+ lhw = HW_TO_LHW(hw);
+ if (lhw->ops->configure_filter == NULL)
+ return;
+
+ if (mc_ptr == 0)
+ return;
+
+ LKPI_80211_TRACE_MO("hw %p changed_flags %#x total_flags %p mc_ptr %ju", hw, changed_flags, total_flags, (uintmax_t)mc_ptr);
+ lhw->ops->configure_filter(hw, changed_flags, total_flags, mc_ptr);
+}
+
+
+/*
+ * So far we only called sta_{add,remove} as an alternative to sta_state.
+ * Let's keep the implementation simpler and hide sta_{add,remove} under the
+ * hood here calling them if state_state is not available from mo_sta_state.
+ */
+static int
+lkpi_80211_mo_sta_add(struct ieee80211_hw *hw, struct ieee80211_vif *vif,
+ struct ieee80211_sta *sta)
+{
+ struct lkpi_hw *lhw;
+ struct lkpi_sta *lsta;
+ int error;
+
+ lhw = HW_TO_LHW(hw);
+ if (lhw->ops->sta_add == NULL) {
+ error = EOPNOTSUPP;
+ goto out;
+ }
+
+ lsta = STA_TO_LSTA(sta);
+ if (lsta->added_to_drv) {
+ error = EEXIST;
+ goto out;
+ }
+
+ LKPI_80211_TRACE_MO("hw %p vif %p sta %p", hw, vif, sta);
+ error = lhw->ops->sta_add(hw, vif, sta);
+ if (error == 0)
+ lsta->added_to_drv = true;
+
+out:
+ return error;
+}
+
+static int
+lkpi_80211_mo_sta_remove(struct ieee80211_hw *hw, struct ieee80211_vif *vif,
+ struct ieee80211_sta *sta)
+{
+ struct lkpi_hw *lhw;
+ struct lkpi_sta *lsta;
+ int error;
+
+ lhw = HW_TO_LHW(hw);
+ if (lhw->ops->sta_remove == NULL) {
+ error = EOPNOTSUPP;
+ goto out;
+ }
+
+ lsta = STA_TO_LSTA(sta);
+ if (!lsta->added_to_drv) {
+ /* If we never added the sta, do not complain on cleanup. */
+ error = 0;
+ goto out;
+ }
+
+ LKPI_80211_TRACE_MO("hw %p vif %p sta %p", hw, vif, sta);
+ error = lhw->ops->sta_remove(hw, vif, sta);
+ if (error == 0)
+ lsta->added_to_drv = false;
+
+out:
+ return error;
+}
+
+int
+lkpi_80211_mo_sta_state(struct ieee80211_hw *hw, struct ieee80211_vif *vif,
+ struct lkpi_sta *lsta, enum ieee80211_sta_state nstate)
+{
+ struct lkpi_hw *lhw;
+ struct ieee80211_sta *sta;
+ int error;
+
+ lhw = HW_TO_LHW(hw);
+ sta = LSTA_TO_STA(lsta);
+ if (lhw->ops->sta_state != NULL) {
+ LKPI_80211_TRACE_MO("hw %p vif %p sta %p nstate %d", hw, vif, sta, nstate);
+ error = lhw->ops->sta_state(hw, vif, sta, lsta->state, nstate);
+ if (error == 0) {
+ if (nstate == IEEE80211_STA_NOTEXIST)
+ lsta->added_to_drv = false;
+ else
+ lsta->added_to_drv = true;
+ lsta->state = nstate;
+ }
+ goto out;
+ }
+
+ /* XXX-BZ is the change state AUTH or ASSOC here? */
+ if (lsta->state < IEEE80211_STA_ASSOC && nstate == IEEE80211_STA_ASSOC) {
+ error = lkpi_80211_mo_sta_add(hw, vif, sta);
+ if (error == 0)
+ lsta->added_to_drv = true;
+ } else if (lsta->state >= IEEE80211_STA_ASSOC &&
+ nstate < IEEE80211_STA_ASSOC) {
+ error = lkpi_80211_mo_sta_remove(hw, vif, sta);
+ if (error == 0)
+ lsta->added_to_drv = false;
+ } else
+ /* Nothing to do. */
+ error = 0;
+ if (error == 0)
+ lsta->state = nstate;
+
+out:
+ /* XXX-BZ should we manage state in here? */
+ return (error);
+}
+
+int
+lkpi_80211_mo_config(struct ieee80211_hw *hw, uint32_t changed)
+{
+ struct lkpi_hw *lhw;
+ int error;
+
+ lhw = HW_TO_LHW(hw);
+ if (lhw->ops->config == NULL) {
+ error = EOPNOTSUPP;
+ goto out;
+ }
+
+ LKPI_80211_TRACE_MO("hw %p changed %u", hw, changed);
+ LKPI_80211_TRACE_MO("TODO link/radio_idx");
+ error = lhw->ops->config(hw, 0, changed);
+
+out:
+ return (error);
+}
+
+
+int
+lkpi_80211_mo_assign_vif_chanctx(struct ieee80211_hw *hw, struct ieee80211_vif *vif,
+ struct ieee80211_bss_conf *conf, struct ieee80211_chanctx_conf *chanctx_conf)
+{
+ struct lkpi_hw *lhw;
+ int error;
+
+ lhw = HW_TO_LHW(hw);
+ if (lhw->ops->assign_vif_chanctx == NULL) {
+ error = EOPNOTSUPP;
+ goto out;
+ }
+
+ LKPI_80211_TRACE_MO("hw %p vif %p bss_conf %p chanctx_conf %p",
+ hw, vif, conf, chanctx_conf);
+ error = lhw->ops->assign_vif_chanctx(hw, vif, conf, chanctx_conf);
+ if (error == 0)
+ vif->bss_conf.chanctx_conf = chanctx_conf;
+
+out:
+ return (error);
+}
+
+void
+lkpi_80211_mo_unassign_vif_chanctx(struct ieee80211_hw *hw, struct ieee80211_vif *vif,
+ struct ieee80211_bss_conf *conf, struct ieee80211_chanctx_conf *chanctx_conf)
+{
+ struct lkpi_hw *lhw;
+
+ might_sleep();
+ lockdep_assert_wiphy(hw->wiphy);
+
+ lhw = HW_TO_LHW(hw);
+ if (lhw->ops->unassign_vif_chanctx == NULL)
+ return;
+
+ if (chanctx_conf == NULL)
+ return;
+
+ LKPI_80211_TRACE_MO("hw %p vif %p bss_conf %p chanctx_conf %p",
+ hw, vif, conf, chanctx_conf);
+ lhw->ops->unassign_vif_chanctx(hw, vif, conf, chanctx_conf);
+}
+
+
+int
+lkpi_80211_mo_add_chanctx(struct ieee80211_hw *hw,
+ struct ieee80211_chanctx_conf *chanctx_conf)
+{
+ struct lkpi_hw *lhw;
+ struct lkpi_chanctx *lchanctx;
+ int error;
+
+ lhw = HW_TO_LHW(hw);
+ if (lhw->ops->add_chanctx == NULL) {
+ error = EOPNOTSUPP;
+ goto out;
+ }
+
+ LKPI_80211_TRACE_MO("hw %p chanctx_conf %p", hw, chanctx_conf);
+ error = lhw->ops->add_chanctx(hw, chanctx_conf);
+ if (error == 0) {
+ lchanctx = CHANCTX_CONF_TO_LCHANCTX(chanctx_conf);
+ lchanctx->added_to_drv = true;
+ }
+
+out:
+ return (error);
+}
+
+void
+lkpi_80211_mo_change_chanctx(struct ieee80211_hw *hw,
+ struct ieee80211_chanctx_conf *chanctx_conf, uint32_t changed)
+{
+ struct lkpi_hw *lhw;
+
+ lhw = HW_TO_LHW(hw);
+ if (lhw->ops->change_chanctx == NULL)
+ return;
+
+ LKPI_80211_TRACE_MO("hw %p chanctx_conf %p changed %u", hw, chanctx_conf, changed);
+ lhw->ops->change_chanctx(hw, chanctx_conf, changed);
+}
+
+void
+lkpi_80211_mo_remove_chanctx(struct ieee80211_hw *hw,
+ struct ieee80211_chanctx_conf *chanctx_conf)
+{
+ struct lkpi_hw *lhw;
+ struct lkpi_chanctx *lchanctx;
+
+ lhw = HW_TO_LHW(hw);
+ if (lhw->ops->remove_chanctx == NULL)
+ return;
+
+ LKPI_80211_TRACE_MO("hw %p chanctx_conf %p", hw, chanctx_conf);
+ lhw->ops->remove_chanctx(hw, chanctx_conf);
+ lchanctx = CHANCTX_CONF_TO_LCHANCTX(chanctx_conf);
+ lchanctx->added_to_drv = false;
+}
+
+void
+lkpi_80211_mo_bss_info_changed(struct ieee80211_hw *hw, struct ieee80211_vif *vif,
+ struct ieee80211_bss_conf *conf, uint64_t changed)
+{
+ struct lkpi_hw *lhw;
+
+ lhw = HW_TO_LHW(hw);
+ if (lhw->ops->link_info_changed == NULL &&
+ lhw->ops->bss_info_changed == NULL)
+ return;
+
+ if (changed == 0)
+ return;
+
+ LKPI_80211_TRACE_MO("hw %p vif %p conf %p changed %#jx", hw, vif, conf, (uintmax_t)changed);
+ if (lhw->ops->link_info_changed != NULL)
+ lhw->ops->link_info_changed(hw, vif, conf, changed);
+ else
+ lhw->ops->bss_info_changed(hw, vif, conf, changed);
+}
+
+int
+lkpi_80211_mo_conf_tx(struct ieee80211_hw *hw, struct ieee80211_vif *vif,
+ uint32_t link_id, uint16_t ac, const struct ieee80211_tx_queue_params *txqp)
+{
+ struct lkpi_hw *lhw;
+ int error;
+
+ lhw = HW_TO_LHW(hw);
+ if (lhw->ops->conf_tx == NULL) {
+ error = EOPNOTSUPP;
+ goto out;
+ }
+
+ LKPI_80211_TRACE_MO("hw %p vif %p link_id %u ac %u txpq %p",
+ hw, vif, link_id, ac, txqp);
+ error = lhw->ops->conf_tx(hw, vif, link_id, ac, txqp);
+
+out:
+ return (error);
+}
+
+void
+lkpi_80211_mo_flush(struct ieee80211_hw *hw, struct ieee80211_vif *vif,
+ uint32_t nqueues, bool drop)
+{
+ struct lkpi_hw *lhw;
+
+ lhw = HW_TO_LHW(hw);
+ if (lhw->ops->flush == NULL)
+ return;
+
+ LKPI_80211_TRACE_MO("hw %p vif %p nqueues %u drop %d", hw, vif, nqueues, drop);
+ lhw->ops->flush(hw, vif, nqueues, drop);
+}
+
+void
+lkpi_80211_mo_mgd_prepare_tx(struct ieee80211_hw *hw, struct ieee80211_vif *vif,
+ struct ieee80211_prep_tx_info *txinfo)
+{
+ struct lkpi_hw *lhw;
+
+ lhw = HW_TO_LHW(hw);
+ if (lhw->ops->mgd_prepare_tx == NULL)
+ return;
+
+ LKPI_80211_TRACE_MO("hw %p vif %p txinfo %p", hw, vif, txinfo);
+ lhw->ops->mgd_prepare_tx(hw, vif, txinfo);
+}
+
+void
+lkpi_80211_mo_mgd_complete_tx(struct ieee80211_hw *hw, struct ieee80211_vif *vif,
+ struct ieee80211_prep_tx_info *txinfo)
+{
+ struct lkpi_hw *lhw;
+
+ lhw = HW_TO_LHW(hw);
+ if (lhw->ops->mgd_complete_tx == NULL)
+ return;
+
+ LKPI_80211_TRACE_MO("hw %p vif %p txinfo %p", hw, vif, txinfo);
+ lhw->ops->mgd_complete_tx(hw, vif, txinfo);
+}
+
+void
+lkpi_80211_mo_tx(struct ieee80211_hw *hw, struct ieee80211_tx_control *txctrl,
+ struct sk_buff *skb)
+{
+ struct lkpi_hw *lhw;
+
+ lhw = HW_TO_LHW(hw);
+ if (lhw->ops->tx == NULL)
+ return;
+
+ LKPI_80211_TRACE_MO("hw %p txctrl %p skb %p", hw, txctrl, skb);
+ lhw->ops->tx(hw, txctrl, skb);
+}
+
+void
+lkpi_80211_mo_wake_tx_queue(struct ieee80211_hw *hw, struct ieee80211_txq *txq)
+{
+ struct lkpi_hw *lhw;
+
+ lhw = HW_TO_LHW(hw);
+ if (lhw->ops->wake_tx_queue == NULL)
+ return;
+
+ LKPI_80211_TRACE_MO("hw %p txq %p", hw, txq);
+ lhw->ops->wake_tx_queue(hw, txq);
+}
+
+void
+lkpi_80211_mo_sync_rx_queues(struct ieee80211_hw *hw)
+{
+ struct lkpi_hw *lhw;
+
+ lhw = HW_TO_LHW(hw);
+ if (lhw->ops->sync_rx_queues == NULL)
+ return;
+
+ LKPI_80211_TRACE_MO("hw %p", hw);
+ lhw->ops->sync_rx_queues(hw);
+}
+
+void
+lkpi_80211_mo_sta_pre_rcu_remove(struct ieee80211_hw *hw,
+ struct ieee80211_vif *vif, struct ieee80211_sta *sta)
+{
+ struct lkpi_hw *lhw;
+
+ lhw = HW_TO_LHW(hw);
+ if (lhw->ops->sta_pre_rcu_remove == NULL)
+ return;
+
+ LKPI_80211_TRACE_MO("hw %p vif %p sta %p", hw, vif, sta);
+ lhw->ops->sta_pre_rcu_remove(hw, vif, sta);
+}
+
+int
+lkpi_80211_mo_set_key(struct ieee80211_hw *hw, enum set_key_cmd cmd,
+ struct ieee80211_vif *vif, struct ieee80211_sta *sta,
+ struct ieee80211_key_conf *kc)
+{
+ struct lkpi_hw *lhw;
+ int error;
+
+ lockdep_assert_wiphy(hw->wiphy);
+
+ lhw = HW_TO_LHW(hw);
+ if (lhw->ops->set_key == NULL) {
+ error = EOPNOTSUPP;
+ goto out;
+ }
+
+ LKPI_80211_TRACE_MO("hw %p cmd %d vif %p sta %p kc %p", hw, cmd, vif, sta, kc);
+ error = lhw->ops->set_key(hw, cmd, vif, sta, kc);
+
+out:
+ return (error);
+}
+
+int
+lkpi_80211_mo_ampdu_action(struct ieee80211_hw *hw, struct ieee80211_vif *vif,
+ struct ieee80211_ampdu_params *params)
+{
+ struct lkpi_hw *lhw;
+ int error;
+
+ lhw = HW_TO_LHW(hw);
+ if (lhw->ops->ampdu_action == NULL) {
+ error = EOPNOTSUPP;
+ goto out;
+ }
+
+ LKPI_80211_TRACE_MO("hw %p vif %p params %p { %p, %d, %u, %u, %u, %u, %d }",
+ hw, vif, params, params->sta, params->action, params->buf_size,
+ params->timeout, params->ssn, params->tid, params->amsdu);
+ error = lhw->ops->ampdu_action(hw, vif, params);
+
+out:
+ return (error);
+}
+
+int
+lkpi_80211_mo_sta_statistics(struct ieee80211_hw *hw, struct ieee80211_vif *vif,
+ struct ieee80211_sta *sta, struct station_info *sinfo)
+{
+ struct lkpi_hw *lhw;
+ struct lkpi_sta *lsta;
+ int error;
+
+ lhw = HW_TO_LHW(hw);
+ if (lhw->ops->sta_statistics == NULL) {
+ error = EOPNOTSUPP;
+ goto out;
+ }
+
+ lsta = STA_TO_LSTA(sta);
+ if (!lsta->added_to_drv) {
+ error = EEXIST;
+ goto out;
+ }
+
+ lockdep_assert_wiphy(hw->wiphy);
+
+ LKPI_80211_TRACE_MO("hw %p vif %p sta %p sinfo %p", hw, vif, sta, sinfo);
+ lhw->ops->sta_statistics(hw, vif, sta, sinfo);
+ error = 0;
+
+out:
+ return (error);
+}
diff --git a/sys/compat/linuxkpi/common/src/linux_acpi.c b/sys/compat/linuxkpi/common/src/linux_acpi.c
index 5eb60941abac..c7d62c745c7e 100644
--- a/sys/compat/linuxkpi/common/src/linux_acpi.c
+++ b/sys/compat/linuxkpi/common/src/linux_acpi.c
@@ -1,5 +1,5 @@
/*-
- * SPDX-License-Identifier: BSD-2-Clause-FreeBSD
+ * SPDX-License-Identifier: BSD-2-Clause
*
* Copyright (c) 2018 Johannes Lundberg <johalun@FreeBSD.org>
* Copyright (c) 2020 Vladimir Kondratyev <wulf@FreeBSD.org>
@@ -25,8 +25,6 @@
* 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.
- *
- * $FreeBSD$
*/
#include "opt_acpi.h"
@@ -35,11 +33,14 @@
#include <sys/bus.h>
#include <sys/eventhandler.h>
#include <sys/kernel.h>
+#include <sys/power.h>
#include <contrib/dev/acpica/include/acpi.h>
#include <dev/acpica/acpivar.h>
#include <linux/notifier.h>
+#include <linux/suspend.h>
+#include <linux/uuid.h>
#include <acpi/acpi_bus.h>
#include <acpi/video.h>
@@ -58,6 +59,8 @@ _Static_assert(LINUX_ACPI_TAGS <= LINUX_NOTIFY_TAGS,
#ifdef DEV_ACPI
+suspend_state_t pm_suspend_target_state = PM_SUSPEND_ON;
+
static uint32_t linux_acpi_target_sleep_state = ACPI_STATE_S0;
static eventhandler_tag resume_tag;
@@ -70,8 +73,9 @@ bsd_acpi_get_handle(device_t bsddev)
}
bool
-acpi_check_dsm(ACPI_HANDLE handle, const char *uuid, int rev, uint64_t funcs)
+acpi_check_dsm(ACPI_HANDLE handle, const guid_t *uuid, int rev, uint64_t funcs)
{
+ UINT64 ret;
if (funcs == 0)
return (false);
@@ -85,35 +89,65 @@ acpi_check_dsm(ACPI_HANDLE handle, const char *uuid, int rev, uint64_t funcs)
*/
funcs |= 1 << 0;
- return ((acpi_DSMQuery(handle, uuid, rev) & funcs) == funcs);
+ ret = acpi_DSMQuery(handle, (const uint8_t *)uuid, rev);
+ return ((ret & funcs) == funcs);
}
ACPI_OBJECT *
-acpi_evaluate_dsm_typed(ACPI_HANDLE handle, const char *uuid, int rev,
+acpi_evaluate_dsm_typed(ACPI_HANDLE handle, const guid_t *uuid, int rev,
int func, ACPI_OBJECT *argv4, ACPI_OBJECT_TYPE type)
{
ACPI_BUFFER buf;
+ ACPI_STATUS status;
+
+ status = acpi_EvaluateDSMTyped(handle, (const uint8_t *)uuid, rev, func,
+ argv4, &buf, type);
+ return (ACPI_SUCCESS(status) ? (ACPI_OBJECT *)buf.Pointer : NULL);
+}
+
+union linuxkpi_acpi_object *
+acpi_evaluate_dsm(ACPI_HANDLE ObjHandle, const guid_t *guid,
+ UINT64 rev, UINT64 func, union linuxkpi_acpi_object *pkg)
+{
+ ACPI_BUFFER buf;
+ ACPI_STATUS status;
- return (ACPI_SUCCESS(acpi_EvaluateDSMTyped(handle, uuid, rev, func,
- argv4, &buf, type)) ? (ACPI_OBJECT *)buf.Pointer : NULL);
+ status = acpi_EvaluateDSM(ObjHandle, (const uint8_t *)guid, rev, func,
+ (ACPI_OBJECT *)pkg, &buf);
+ return (ACPI_SUCCESS(status) ?
+ (union linuxkpi_acpi_object *)buf.Pointer : NULL);
}
static void
-linux_handle_power_suspend_event(void *arg __unused)
+linux_handle_power_suspend_event(void *arg __unused, enum power_stype stype)
{
- /*
- * Only support S3 for now.
- * acpi_sleep_event isn't always called so we use power_suspend_early
- * instead which means we don't know what state we're switching to.
- * TODO: Make acpi_sleep_event consistent
- */
- linux_acpi_target_sleep_state = ACPI_STATE_S3;
+ switch (stype) {
+ case POWER_STYPE_SUSPEND_TO_IDLE:
+ /*
+ * XXX: obiwac Not 100% sure this is correct, but
+ * acpi_target_sleep_state does seem to be set to
+ * ACPI_STATE_S3 during s2idle on Linux.
+ */
+ linux_acpi_target_sleep_state = ACPI_STATE_S3;
+ pm_suspend_target_state = PM_SUSPEND_TO_IDLE;
+ break;
+ case POWER_STYPE_SUSPEND_TO_MEM:
+ linux_acpi_target_sleep_state = ACPI_STATE_S3;
+ pm_suspend_target_state = PM_SUSPEND_MEM;
+ break;
+ default:
+ printf("%s: sleep type %d not yet supported\n",
+ __func__, stype);
+ break;
+ }
}
static void
-linux_handle_power_resume_event(void *arg __unused)
+linux_handle_power_resume_event(void *arg __unused,
+ enum power_stype stype __unused)
{
linux_acpi_target_sleep_state = ACPI_STATE_S0;
+ pm_suspend_target_state = PM_SUSPEND_ON;
}
static void
@@ -173,6 +207,104 @@ acpi_target_system_state(void)
return (linux_acpi_target_sleep_state);
}
+struct acpi_dev_present_ctx {
+ const char *hid;
+ const char *uid;
+ int64_t hrv;
+ struct acpi_device *dev;
+};
+
+static ACPI_STATUS
+acpi_dev_present_cb(ACPI_HANDLE handle, UINT32 level, void *context,
+ void **result)
+{
+ ACPI_DEVICE_INFO *devinfo;
+ struct acpi_device *dev;
+ struct acpi_dev_present_ctx *match = context;
+ bool present = false;
+ UINT32 sta, hrv;
+ int i;
+
+ if (handle == NULL)
+ return (AE_OK);
+
+ if (!ACPI_FAILURE(acpi_GetInteger(handle, "_STA", &sta)) &&
+ !ACPI_DEVICE_PRESENT(sta))
+ return (AE_OK);
+
+ if (ACPI_FAILURE(AcpiGetObjectInfo(handle, &devinfo)))
+ return (AE_OK);
+
+ if ((devinfo->Valid & ACPI_VALID_HID) != 0 &&
+ strcmp(match->hid, devinfo->HardwareId.String) == 0) {
+ present = true;
+ } else if ((devinfo->Valid & ACPI_VALID_CID) != 0) {
+ for (i = 0; i < devinfo->CompatibleIdList.Count; i++) {
+ if (strcmp(match->hid,
+ devinfo->CompatibleIdList.Ids[i].String) == 0) {
+ present = true;
+ break;
+ }
+ }
+ }
+ if (present && match->uid != NULL &&
+ ((devinfo->Valid & ACPI_VALID_UID) == 0 ||
+ strcmp(match->uid, devinfo->UniqueId.String) != 0))
+ present = false;
+
+ AcpiOsFree(devinfo);
+ if (!present)
+ return (AE_OK);
+
+ if (match->hrv != -1) {
+ if (ACPI_FAILURE(acpi_GetInteger(handle, "_HRV", &hrv)))
+ return (AE_OK);
+ if (hrv != match->hrv)
+ return (AE_OK);
+ }
+
+ dev = acpi_get_device(handle);
+ if (dev == NULL)
+ return (AE_OK);
+ match->dev = dev;
+
+ return (AE_ERROR);
+}
+
+bool
+lkpi_acpi_dev_present(const char *hid, const char *uid, int64_t hrv)
+{
+ struct acpi_dev_present_ctx match;
+ int rv;
+
+ match.hid = hid;
+ match.uid = uid;
+ match.hrv = hrv;
+
+ rv = AcpiWalkNamespace(ACPI_TYPE_DEVICE, ACPI_ROOT_OBJECT,
+ ACPI_UINT32_MAX, acpi_dev_present_cb, NULL, &match, NULL);
+
+ return (rv == AE_ERROR);
+}
+
+struct acpi_device *
+lkpi_acpi_dev_get_first_match_dev(const char *hid, const char *uid,
+ int64_t hrv)
+{
+ struct acpi_dev_present_ctx match;
+ int rv;
+
+ match.hid = hid;
+ match.uid = uid;
+ match.hrv = hrv;
+ match.dev = NULL;
+
+ rv = AcpiWalkNamespace(ACPI_TYPE_DEVICE, ACPI_ROOT_OBJECT,
+ ACPI_UINT32_MAX, acpi_dev_present_cb, NULL, &match, NULL);
+
+ return (rv == AE_ERROR ? match.dev : NULL);
+}
+
static void
linux_register_acpi_event_handlers(void *arg __unused)
{
@@ -210,18 +342,25 @@ bsd_acpi_get_handle(device_t bsddev)
}
bool
-acpi_check_dsm(ACPI_HANDLE handle, const char *uuid, int rev, uint64_t funcs)
+acpi_check_dsm(ACPI_HANDLE handle, const guid_t *uuid, int rev, uint64_t funcs)
{
return (false);
}
ACPI_OBJECT *
-acpi_evaluate_dsm_typed(ACPI_HANDLE handle, const char *uuid, int rev,
+acpi_evaluate_dsm_typed(ACPI_HANDLE handle, const guid_t *uuid, int rev,
int func, ACPI_OBJECT *argv4, ACPI_OBJECT_TYPE type)
{
return (NULL);
}
+union linuxkpi_acpi_object *
+acpi_evaluate_dsm(ACPI_HANDLE ObjHandle, const guid_t *guid,
+ UINT64 rev, UINT64 func, union linuxkpi_acpi_object *pkg)
+{
+ return (NULL);
+}
+
int
register_acpi_notifier(struct notifier_block *nb)
{
@@ -240,4 +379,17 @@ acpi_target_system_state(void)
return (ACPI_STATE_S0);
}
+bool
+lkpi_acpi_dev_present(const char *hid, const char *uid, int64_t hrv)
+{
+ return (false);
+}
+
+struct acpi_device *
+lkpi_acpi_dev_get_first_match_dev(const char *hid, const char *uid,
+ int64_t hrv)
+{
+ return (NULL);
+}
+
#endif /* !DEV_ACPI */
diff --git a/sys/compat/linuxkpi/common/src/linux_aperture.c b/sys/compat/linuxkpi/common/src/linux_aperture.c
new file mode 100644
index 000000000000..21c7041fc851
--- /dev/null
+++ b/sys/compat/linuxkpi/common/src/linux_aperture.c
@@ -0,0 +1,387 @@
+// SPDX-License-Identifier: MIT
+
+#include <linux/aperture.h>
+#include <linux/device.h>
+#include <linux/list.h>
+#include <linux/mutex.h>
+#include <linux/pci.h>
+#include <linux/platform_device.h>
+#include <linux/slab.h>
+#include <linux/sysfb.h>
+#include <linux/types.h>
+#include <linux/vgaarb.h>
+
+#include <video/vga.h>
+
+/**
+ * DOC: overview
+ *
+ * A graphics device might be supported by different drivers, but only one
+ * driver can be active at any given time. Many systems load a generic
+ * graphics drivers, such as EFI-GOP or VESA, early during the boot process.
+ * During later boot stages, they replace the generic driver with a dedicated,
+ * hardware-specific driver. To take over the device, the dedicated driver
+ * first has to remove the generic driver. Aperture functions manage
+ * ownership of framebuffer memory and hand-over between drivers.
+ *
+ * Graphics drivers should call aperture_remove_conflicting_devices()
+ * at the top of their probe function. The function removes any generic
+ * driver that is currently associated with the given framebuffer memory.
+ * An example for a graphics device on the platform bus is shown below.
+ *
+ * .. code-block:: c
+ *
+ * static int example_probe(struct platform_device *pdev)
+ * {
+ * struct resource *mem;
+ * resource_size_t base, size;
+ * int ret;
+ *
+ * mem = platform_get_resource(pdev, IORESOURCE_MEM, 0);
+ * if (!mem)
+ * return -ENODEV;
+ * base = mem->start;
+ * size = resource_size(mem);
+ *
+ * ret = aperture_remove_conflicting_devices(base, size, "example");
+ * if (ret)
+ * return ret;
+ *
+ * // Initialize the hardware
+ * ...
+ *
+ * return 0;
+ * }
+ *
+ * static const struct platform_driver example_driver = {
+ * .probe = example_probe,
+ * ...
+ * };
+ *
+ * The given example reads the platform device's I/O-memory range from the
+ * device instance. An active framebuffer will be located within this range.
+ * The call to aperture_remove_conflicting_devices() releases drivers that
+ * have previously claimed ownership of the range and are currently driving
+ * output on the framebuffer. If successful, the new driver can take over
+ * the device.
+ *
+ * While the given example uses a platform device, the aperture helpers work
+ * with every bus that has an addressable framebuffer. In the case of PCI,
+ * device drivers can also call aperture_remove_conflicting_pci_devices() and
+ * let the function detect the apertures automatically. Device drivers without
+ * knowledge of the framebuffer's location can call
+ * aperture_remove_all_conflicting_devices(), which removes all known devices.
+ *
+ * Drivers that are susceptible to being removed by other drivers, such as
+ * generic EFI or VESA drivers, have to register themselves as owners of their
+ * framebuffer apertures. Ownership of the framebuffer memory is achieved
+ * by calling devm_aperture_acquire_for_platform_device(). If successful, the
+ * driver is the owner of the framebuffer range. The function fails if the
+ * framebuffer is already owned by another driver. See below for an example.
+ *
+ * .. code-block:: c
+ *
+ * static int generic_probe(struct platform_device *pdev)
+ * {
+ * struct resource *mem;
+ * resource_size_t base, size;
+ *
+ * mem = platform_get_resource(pdev, IORESOURCE_MEM, 0);
+ * if (!mem)
+ * return -ENODEV;
+ * base = mem->start;
+ * size = resource_size(mem);
+ *
+ * ret = devm_aperture_acquire_for_platform_device(pdev, base, size);
+ * if (ret)
+ * return ret;
+ *
+ * // Initialize the hardware
+ * ...
+ *
+ * return 0;
+ * }
+ *
+ * static int generic_remove(struct platform_device *)
+ * {
+ * // Hot-unplug the device
+ * ...
+ *
+ * return 0;
+ * }
+ *
+ * static const struct platform_driver generic_driver = {
+ * .probe = generic_probe,
+ * .remove = generic_remove,
+ * ...
+ * };
+ *
+ * The similar to the previous example, the generic driver claims ownership
+ * of the framebuffer memory from its probe function. This will fail if the
+ * memory range, or parts of it, is already owned by another driver.
+ *
+ * If successful, the generic driver is now subject to forced removal by
+ * another driver. This only works for platform drivers that support hot
+ * unplugging. When a driver calls aperture_remove_conflicting_devices()
+ * et al for the registered framebuffer range, the aperture helpers call
+ * platform_device_unregister() and the generic driver unloads itself. The
+ * generic driver also has to provide a remove function to make this work.
+ * Once hot unplugged from hardware, it may not access the device's
+ * registers, framebuffer memory, ROM, etc afterwards.
+ */
+
+struct aperture_range {
+ struct device *dev;
+ resource_size_t base;
+ resource_size_t size;
+ struct list_head lh;
+ void (*detach)(struct device *dev);
+};
+
+static LIST_HEAD(apertures);
+static DEFINE_MUTEX(apertures_lock);
+
+static bool overlap(resource_size_t base1, resource_size_t end1,
+ resource_size_t base2, resource_size_t end2)
+{
+ return (base1 < end2) && (end1 > base2);
+}
+
+static void devm_aperture_acquire_release(void *data)
+{
+ struct aperture_range *ap = data;
+ bool detached = !ap->dev;
+
+ if (detached)
+ return;
+
+ mutex_lock(&apertures_lock);
+ list_del(&ap->lh);
+ mutex_unlock(&apertures_lock);
+}
+
+static int devm_aperture_acquire(struct device *dev,
+ resource_size_t base, resource_size_t size,
+ void (*detach)(struct device *))
+{
+ size_t end = base + size;
+ struct list_head *pos;
+ struct aperture_range *ap;
+
+ mutex_lock(&apertures_lock);
+
+ list_for_each(pos, &apertures) {
+ ap = container_of(pos, struct aperture_range, lh);
+ if (overlap(base, end, ap->base, ap->base + ap->size)) {
+ mutex_unlock(&apertures_lock);
+ return -EBUSY;
+ }
+ }
+
+ ap = devm_kzalloc(dev, sizeof(*ap), GFP_KERNEL);
+ if (!ap) {
+ mutex_unlock(&apertures_lock);
+ return -ENOMEM;
+ }
+
+ ap->dev = dev;
+ ap->base = base;
+ ap->size = size;
+ ap->detach = detach;
+ INIT_LIST_HEAD(&ap->lh);
+
+ list_add(&ap->lh, &apertures);
+
+ mutex_unlock(&apertures_lock);
+
+ return devm_add_action_or_reset(dev, devm_aperture_acquire_release, ap);
+}
+
+static void aperture_detach_platform_device(struct device *dev)
+{
+ struct platform_device *pdev = to_platform_device(dev);
+
+ /*
+ * Remove the device from the device hierarchy. This is the right thing
+ * to do for firmware-based fb drivers, such as EFI, VESA or VGA. After
+ * the new driver takes over the hardware, the firmware device's state
+ * will be lost.
+ *
+ * For non-platform devices, a new callback would be required.
+ *
+ * If the aperture helpers ever need to handle native drivers, this call
+ * would only have to unplug the DRM device, so that the hardware device
+ * stays around after detachment.
+ */
+ platform_device_unregister(pdev);
+}
+
+/**
+ * devm_aperture_acquire_for_platform_device - Acquires ownership of an aperture
+ * on behalf of a platform device.
+ * @pdev: the platform device to own the aperture
+ * @base: the aperture's byte offset in physical memory
+ * @size: the aperture size in bytes
+ *
+ * Installs the given device as the new owner of the aperture. The function
+ * expects the aperture to be provided by a platform device. If another
+ * driver takes over ownership of the aperture, aperture helpers will then
+ * unregister the platform device automatically. All acquired apertures are
+ * released automatically when the underlying device goes away.
+ *
+ * The function fails if the aperture, or parts of it, is currently
+ * owned by another device. To evict current owners, callers should use
+ * remove_conflicting_devices() et al. before calling this function.
+ *
+ * Returns:
+ * 0 on success, or a negative errno value otherwise.
+ */
+int devm_aperture_acquire_for_platform_device(struct platform_device *pdev,
+ resource_size_t base,
+ resource_size_t size)
+{
+ return devm_aperture_acquire(&pdev->dev, base, size, aperture_detach_platform_device);
+}
+EXPORT_SYMBOL(devm_aperture_acquire_for_platform_device);
+
+static void aperture_detach_devices(resource_size_t base, resource_size_t size)
+{
+ resource_size_t end = base + size;
+ struct list_head *pos, *n;
+
+ mutex_lock(&apertures_lock);
+
+ list_for_each_safe(pos, n, &apertures) {
+ struct aperture_range *ap = container_of(pos, struct aperture_range, lh);
+ struct device *dev = ap->dev;
+
+ if (WARN_ON_ONCE(!dev))
+ continue;
+
+ if (!overlap(base, end, ap->base, ap->base + ap->size))
+ continue;
+
+ ap->dev = NULL; /* detach from device */
+ list_del(&ap->lh);
+
+ ap->detach(dev);
+ }
+
+ mutex_unlock(&apertures_lock);
+}
+
+/**
+ * aperture_remove_conflicting_devices - remove devices in the given range
+ * @base: the aperture's base address in physical memory
+ * @size: aperture size in bytes
+ * @name: a descriptive name of the requesting driver
+ *
+ * This function removes devices that own apertures within @base and @size.
+ *
+ * Returns:
+ * 0 on success, or a negative errno code otherwise
+ */
+int aperture_remove_conflicting_devices(resource_size_t base, resource_size_t size,
+ const char *name)
+{
+ /*
+ * If a driver asked to unregister a platform device registered by
+ * sysfb, then can be assumed that this is a driver for a display
+ * that is set up by the system firmware and has a generic driver.
+ *
+ * Drivers for devices that don't have a generic driver will never
+ * ask for this, so let's assume that a real driver for the display
+ * was already probed and prevent sysfb to register devices later.
+ */
+#ifdef __linux__
+ sysfb_disable();
+#endif
+
+ aperture_detach_devices(base, size);
+
+ return 0;
+}
+EXPORT_SYMBOL(aperture_remove_conflicting_devices);
+
+/**
+ * __aperture_remove_legacy_vga_devices - remove legacy VGA devices of a PCI devices
+ * @pdev: PCI device
+ *
+ * This function removes VGA devices provided by @pdev, such as a VGA
+ * framebuffer or a console. This is useful if you have a VGA-compatible
+ * PCI graphics device with framebuffers in non-BAR locations. Drivers
+ * should acquire ownership of those memory areas and afterwards call
+ * this helper to release remaining VGA devices.
+ *
+ * If your hardware has its framebuffers accessible via PCI BARS, use
+ * aperture_remove_conflicting_pci_devices() instead. The function will
+ * release any VGA devices automatically.
+ *
+ * WARNING: Apparently we must remove graphics drivers before calling
+ * this helper. Otherwise the vga fbdev driver falls over if
+ * we have vgacon configured.
+ *
+ * Returns:
+ * 0 on success, or a negative errno code otherwise
+ */
+int __aperture_remove_legacy_vga_devices(struct pci_dev *pdev)
+{
+ /* VGA framebuffer */
+ aperture_detach_devices(VGA_FB_PHYS_BASE, VGA_FB_PHYS_SIZE);
+
+ /* VGA textmode console */
+#ifdef __linux__
+ return vga_remove_vgacon(pdev);
+#elif defined(__FreeBSD__)
+ return 0;
+#endif
+}
+EXPORT_SYMBOL(__aperture_remove_legacy_vga_devices);
+
+/**
+ * aperture_remove_conflicting_pci_devices - remove existing framebuffers for PCI devices
+ * @pdev: PCI device
+ * @name: a descriptive name of the requesting driver
+ *
+ * This function removes devices that own apertures within any of @pdev's
+ * memory bars. The function assumes that PCI device with shadowed ROM
+ * drives a primary display and therefore kicks out vga16fb as well.
+ *
+ * Returns:
+ * 0 on success, or a negative errno code otherwise
+ */
+int aperture_remove_conflicting_pci_devices(struct pci_dev *pdev, const char *name)
+{
+ bool primary = false;
+ resource_size_t base, size;
+ int bar, ret = 0;
+
+#ifdef __linux__
+ if (pdev == vga_default_device())
+ primary = true;
+
+ if (primary)
+ sysfb_disable();
+#endif
+
+ for (bar = 0; bar < PCI_STD_NUM_BARS; ++bar) {
+ if (!(pci_resource_flags(pdev, bar) & IORESOURCE_MEM))
+ continue;
+
+ base = pci_resource_start(pdev, bar);
+ size = pci_resource_len(pdev, bar);
+ aperture_detach_devices(base, size);
+ }
+
+ /*
+ * If this is the primary adapter, there could be a VGA device
+ * that consumes the VGA framebuffer I/O range. Remove this
+ * device as well.
+ */
+ if (primary)
+ ret = __aperture_remove_legacy_vga_devices(pdev);
+
+ return ret;
+
+}
+EXPORT_SYMBOL(aperture_remove_conflicting_pci_devices);
diff --git a/sys/compat/linuxkpi/common/src/linux_cmdline.c b/sys/compat/linuxkpi/common/src/linux_cmdline.c
new file mode 100644
index 000000000000..0cfa1d56ee6a
--- /dev/null
+++ b/sys/compat/linuxkpi/common/src/linux_cmdline.c
@@ -0,0 +1,63 @@
+/*-
+ * Copyright (c) 2022 Beckhoff Automation GmbH & Co. KG
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``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 OR CONTRIBUTORS 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.
+ *
+ */
+
+#include <sys/param.h>
+#include <sys/systm.h>
+
+#include <video/cmdline.h>
+
+const char *
+video_get_options(const char *connector_name)
+{
+ char tunable[64];
+ const char *options;
+
+ /*
+ * A user may use loader tunables to set a specific mode for the
+ * console. Tunables are read in the following order:
+ * 1. kern.vt.fb.modes.$connector_name
+ * 2. kern.vt.fb.default_mode
+ *
+ * Example of a mode specific to the LVDS connector:
+ * kern.vt.fb.modes.LVDS="1024x768"
+ *
+ * Example of a mode applied to all connectors not having a
+ * connector-specific mode:
+ * kern.vt.fb.default_mode="640x480"
+ */
+ snprintf(tunable, sizeof(tunable), "kern.vt.fb.modes.%s",
+ connector_name);
+ if (bootverbose) {
+ printf("[drm] Connector %s: get mode from tunables:\n", connector_name);
+ printf("[drm] - %s\n", tunable);
+ printf("[drm] - kern.vt.fb.default_mode\n");
+ }
+ options = kern_getenv(tunable);
+ if (options == NULL)
+ options = kern_getenv("kern.vt.fb.default_mode");
+
+ return (options);
+}
diff --git a/sys/compat/linuxkpi/common/src/linux_compat.c b/sys/compat/linuxkpi/common/src/linux_compat.c
index 6440f7bdcff4..ff0f477ea8cc 100644
--- a/sys/compat/linuxkpi/common/src/linux_compat.c
+++ b/sys/compat/linuxkpi/common/src/linux_compat.c
@@ -28,8 +28,7 @@
*/
#include <sys/cdefs.h>
-__FBSDID("$FreeBSD$");
-
+#include "opt_global.h"
#include "opt_stack.h"
#include <sys/param.h>
@@ -51,6 +50,7 @@ __FBSDID("$FreeBSD$");
#include <sys/rwlock.h>
#include <sys/mman.h>
#include <sys/stack.h>
+#include <sys/stdarg.h>
#include <sys/sysent.h>
#include <sys/time.h>
#include <sys/user.h>
@@ -60,10 +60,10 @@ __FBSDID("$FreeBSD$");
#include <vm/vm_object.h>
#include <vm/vm_page.h>
#include <vm/vm_pager.h>
-
-#include <machine/stdarg.h>
+#include <vm/vm_radix.h>
#if defined(__i386__) || defined(__amd64__)
+#include <machine/cputypes.h>
#include <machine/md_var.h>
#endif
@@ -75,6 +75,7 @@ __FBSDID("$FreeBSD$");
#include <linux/moduleparam.h>
#include <linux/cdev.h>
#include <linux/file.h>
+#include <linux/fs.h>
#include <linux/sysfs.h>
#include <linux/mm.h>
#include <linux/io.h>
@@ -83,17 +84,33 @@ __FBSDID("$FreeBSD$");
#include <linux/timer.h>
#include <linux/interrupt.h>
#include <linux/uaccess.h>
+#include <linux/utsname.h>
#include <linux/list.h>
#include <linux/kthread.h>
#include <linux/kernel.h>
#include <linux/compat.h>
+#include <linux/io-mapping.h>
#include <linux/poll.h>
#include <linux/smp.h>
#include <linux/wait_bit.h>
#include <linux/rcupdate.h>
+#include <linux/interval_tree.h>
+#include <linux/interval_tree_generic.h>
+#include <linux/printk.h>
+#include <linux/seq_file.h>
#if defined(__i386__) || defined(__amd64__)
#include <asm/smp.h>
+#include <asm/processor.h>
+#endif
+
+#include <xen/xen.h>
+#ifdef XENHVM
+#undef xen_pv_domain
+#undef xen_initial_domain
+/* xen/xen-os.h redefines __must_check */
+#undef __must_check
+#include <xen/xen-os.h>
#endif
SYSCTL_NODE(_compat, OID_AUTO, linuxkpi, CTLFLAG_RW | CTLFLAG_MPSAFE, 0,
@@ -103,6 +120,10 @@ int linuxkpi_debug;
SYSCTL_INT(_compat_linuxkpi, OID_AUTO, debug, CTLFLAG_RWTUN,
&linuxkpi_debug, 0, "Set to enable pr_debug() prints. Clear to disable.");
+int linuxkpi_rcu_debug;
+SYSCTL_INT(_compat_linuxkpi, OID_AUTO, rcu_debug, CTLFLAG_RWTUN,
+ &linuxkpi_rcu_debug, 0, "Set to enable RCU warning. Clear to disable.");
+
int linuxkpi_warn_dump_stack = 0;
SYSCTL_INT(_compat_linuxkpi, OID_AUTO, warn_dump_stack, CTLFLAG_RWTUN,
&linuxkpi_warn_dump_stack, 0,
@@ -128,12 +149,15 @@ static void linux_cdev_deref(struct linux_cdev *ldev);
static struct vm_area_struct *linux_cdev_handle_find(void *handle);
cpumask_t cpu_online_mask;
+static cpumask_t **static_single_cpu_mask;
+static cpumask_t *static_single_cpu_mask_lcs;
struct kobject linux_class_root;
struct device linux_root_device;
struct class linux_class_misc;
struct list_head pci_drivers;
struct list_head pci_devices;
spinlock_t pci_lock;
+struct uts_namespace init_uts_ns;
unsigned long linux_timer_hz_mask;
@@ -148,131 +172,11 @@ panic_cmp(struct rb_node *one, struct rb_node *two)
RB_GENERATE(linux_root, rb_node, __entry, panic_cmp);
-int
-kobject_set_name_vargs(struct kobject *kobj, const char *fmt, va_list args)
-{
- va_list tmp_va;
- int len;
- char *old;
- char *name;
- char dummy;
-
- old = kobj->name;
-
- if (old && fmt == NULL)
- return (0);
-
- /* compute length of string */
- va_copy(tmp_va, args);
- len = vsnprintf(&dummy, 0, fmt, tmp_va);
- va_end(tmp_va);
-
- /* account for zero termination */
- len++;
-
- /* check for error */
- if (len < 1)
- return (-EINVAL);
-
- /* allocate memory for string */
- name = kzalloc(len, GFP_KERNEL);
- if (name == NULL)
- return (-ENOMEM);
- vsnprintf(name, len, fmt, args);
- kobj->name = name;
-
- /* free old string */
- kfree(old);
-
- /* filter new string */
- for (; *name != '\0'; name++)
- if (*name == '/')
- *name = '!';
- return (0);
-}
-
-int
-kobject_set_name(struct kobject *kobj, const char *fmt, ...)
-{
- va_list args;
- int error;
-
- va_start(args, fmt);
- error = kobject_set_name_vargs(kobj, fmt, args);
- va_end(args);
-
- return (error);
-}
-
-static int
-kobject_add_complete(struct kobject *kobj, struct kobject *parent)
-{
- const struct kobj_type *t;
- int error;
-
- kobj->parent = parent;
- error = sysfs_create_dir(kobj);
- if (error == 0 && kobj->ktype && kobj->ktype->default_attrs) {
- struct attribute **attr;
- t = kobj->ktype;
-
- for (attr = t->default_attrs; *attr != NULL; attr++) {
- error = sysfs_create_file(kobj, *attr);
- if (error)
- break;
- }
- if (error)
- sysfs_remove_dir(kobj);
- }
- return (error);
-}
-
-int
-kobject_add(struct kobject *kobj, struct kobject *parent, const char *fmt, ...)
-{
- va_list args;
- int error;
-
- va_start(args, fmt);
- error = kobject_set_name_vargs(kobj, fmt, args);
- va_end(args);
- if (error)
- return (error);
-
- return kobject_add_complete(kobj, parent);
-}
-
-void
-linux_kobject_release(struct kref *kref)
-{
- struct kobject *kobj;
- char *name;
-
- kobj = container_of(kref, struct kobject, kref);
- sysfs_remove_dir(kobj);
- name = kobj->name;
- if (kobj->ktype && kobj->ktype->release)
- kobj->ktype->release(kobj);
- kfree(name);
-}
-
-static void
-linux_kobject_kfree(struct kobject *kobj)
-{
- kfree(kobj);
-}
-
-static void
-linux_kobject_kfree_name(struct kobject *kobj)
-{
- if (kobj) {
- kfree(kobj->name);
- }
-}
+#define START(node) ((node)->start)
+#define LAST(node) ((node)->last)
-const struct kobj_type linux_kfree_type = {
- .release = linux_kobject_kfree
-};
+INTERVAL_TREE_DEFINE(struct interval_tree_node, rb, unsigned long,, START,
+ LAST,, lkpi_interval_tree)
static void
linux_device_release(struct device *dev)
@@ -403,24 +307,63 @@ device_create(struct class *class, struct device *parent, dev_t devt,
return (dev);
}
-int
-kobject_init_and_add(struct kobject *kobj, const struct kobj_type *ktype,
- struct kobject *parent, const char *fmt, ...)
+struct device *
+device_create_groups_vargs(struct class *class, struct device *parent,
+ dev_t devt, void *drvdata, const struct attribute_group **groups,
+ const char *fmt, va_list args)
{
- va_list args;
+ struct device *dev = NULL;
+ int retval = -ENODEV;
+
+ if (class == NULL || IS_ERR(class))
+ goto error;
+
+ dev = kzalloc(sizeof(*dev), GFP_KERNEL);
+ if (!dev) {
+ retval = -ENOMEM;
+ goto error;
+ }
+
+ dev->devt = devt;
+ dev->class = class;
+ dev->parent = parent;
+ dev->groups = groups;
+ dev->release = device_create_release;
+ /* device_initialize() needs the class and parent to be set */
+ device_initialize(dev);
+ dev_set_drvdata(dev, drvdata);
+
+ retval = kobject_set_name_vargs(&dev->kobj, fmt, args);
+ if (retval)
+ goto error;
+
+ retval = device_add(dev);
+ if (retval)
+ goto error;
+
+ return dev;
+
+error:
+ put_device(dev);
+ return ERR_PTR(retval);
+}
+
+struct class *
+lkpi_class_create(const char *name)
+{
+ struct class *class;
int error;
- kobject_init(kobj, ktype);
- kobj->ktype = ktype;
- kobj->parent = parent;
- kobj->name = NULL;
+ class = kzalloc(sizeof(*class), M_WAITOK);
+ class->name = name;
+ class->class_release = linux_class_kfree;
+ error = class_register(class);
+ if (error) {
+ kfree(class);
+ return (NULL);
+ }
- va_start(args, fmt);
- error = kobject_set_name_vargs(kobj, fmt, args);
- va_end(args);
- if (error)
- return (error);
- return kobject_add_complete(kobj, parent);
+ return (class);
}
static void
@@ -445,9 +388,9 @@ linux_kq_assert_lock(void *arg, int what)
spinlock_t *s = arg;
if (what == LA_LOCKED)
- mtx_assert(&s->m, MA_OWNED);
+ mtx_assert(s, MA_OWNED);
else
- mtx_assert(&s->m, MA_NOTOWNED);
+ mtx_assert(s, MA_NOTOWNED);
#endif
}
@@ -490,6 +433,17 @@ linux_file_free(struct linux_file *filp)
}
}
+struct linux_cdev *
+cdev_alloc(void)
+{
+ struct linux_cdev *cdev;
+
+ cdev = kzalloc(sizeof(struct linux_cdev), M_WAITOK);
+ kobject_init(&cdev->kobj, &linux_cdev_ktype);
+ cdev->refs = 1;
+ return (cdev);
+}
+
static int
linux_cdev_pager_fault(vm_object_t vm_obj, vm_ooffset_t offset, int prot,
vm_page_t *mres)
@@ -693,6 +647,7 @@ int
zap_vma_ptes(struct vm_area_struct *vma, unsigned long address,
unsigned long size)
{
+ struct pctrie_iter pages;
vm_object_t obj;
vm_page_t m;
@@ -700,14 +655,25 @@ zap_vma_ptes(struct vm_area_struct *vma, unsigned long address,
if (obj == NULL || (obj->flags & OBJ_UNMANAGED) != 0)
return (-ENOTSUP);
VM_OBJECT_RLOCK(obj);
- for (m = vm_page_find_least(obj, OFF_TO_IDX(address));
- m != NULL && m->pindex < OFF_TO_IDX(address + size);
- m = TAILQ_NEXT(m, listq))
+ vm_page_iter_limit_init(&pages, obj, OFF_TO_IDX(address + size));
+ VM_RADIX_FOREACH_FROM(m, &pages, OFF_TO_IDX(address))
pmap_remove_all(m);
VM_OBJECT_RUNLOCK(obj);
return (0);
}
+void
+vma_set_file(struct vm_area_struct *vma, struct linux_file *file)
+{
+ struct linux_file *tmp;
+
+ /* Changing an anonymous vma with this is illegal */
+ get_file(file);
+ tmp = vma->vm_file;
+ vma->vm_file = file;
+ fput(tmp);
+}
+
static struct file_operations dummy_ldev_ops = {
/* XXXKIB */
};
@@ -809,7 +775,7 @@ linux_dev_fdopen(struct cdev *dev, int fflags, struct thread *td,
}
/* hold on to the vnode - used for fstat() */
- vhold(filp->f_vnode);
+ vref(filp->f_vnode);
/* release the file from devfs */
finit(file, filp->f_mode, DTYPE_DEV, filp, &linuxfileops);
@@ -1119,6 +1085,58 @@ linux_poll_wakeup(struct linux_file *filp)
spin_unlock(&filp->f_kqlock);
}
+static struct linux_file *
+__get_file_rcu(struct linux_file **f)
+{
+ struct linux_file *file1, *file2;
+
+ file1 = READ_ONCE(*f);
+ if (file1 == NULL)
+ return (NULL);
+
+ if (!refcount_acquire_if_not_zero(
+ file1->_file == NULL ? &file1->f_count : &file1->_file->f_count))
+ return (ERR_PTR(-EAGAIN));
+
+ file2 = READ_ONCE(*f);
+ if (file2 == file1)
+ return (file2);
+
+ fput(file1);
+ return (ERR_PTR(-EAGAIN));
+}
+
+struct linux_file *
+linux_get_file_rcu(struct linux_file **f)
+{
+ struct linux_file *file1;
+
+ for (;;) {
+ file1 = __get_file_rcu(f);
+ if (file1 == NULL)
+ return (NULL);
+
+ if (IS_ERR(file1))
+ continue;
+
+ return (file1);
+ }
+}
+
+struct linux_file *
+get_file_active(struct linux_file **f)
+{
+ struct linux_file *file1;
+
+ rcu_read_lock();
+ file1 = __get_file_rcu(f);
+ rcu_read_unlock();
+ if (IS_ERR(file1))
+ file1 = NULL;
+
+ return (file1);
+}
+
static void
linux_file_kqfilter_detach(struct knote *kn)
{
@@ -1134,7 +1152,7 @@ linux_file_kqfilter_read_event(struct knote *kn, long hint)
{
struct linux_file *filp = kn->kn_hook;
- mtx_assert(&filp->f_kqlock.m, MA_OWNED);
+ mtx_assert(&filp->f_kqlock, MA_OWNED);
return ((filp->f_kqflags & LINUX_KQ_FLAG_NEED_READ) ? 1 : 0);
}
@@ -1144,21 +1162,23 @@ linux_file_kqfilter_write_event(struct knote *kn, long hint)
{
struct linux_file *filp = kn->kn_hook;
- mtx_assert(&filp->f_kqlock.m, MA_OWNED);
+ mtx_assert(&filp->f_kqlock, MA_OWNED);
return ((filp->f_kqflags & LINUX_KQ_FLAG_NEED_WRITE) ? 1 : 0);
}
-static struct filterops linux_dev_kqfiltops_read = {
+static const struct filterops linux_dev_kqfiltops_read = {
.f_isfd = 1,
.f_detach = linux_file_kqfilter_detach,
.f_event = linux_file_kqfilter_read_event,
+ .f_copy = knote_triv_copy,
};
-static struct filterops linux_dev_kqfiltops_write = {
+static const struct filterops linux_dev_kqfiltops_write = {
.f_isfd = 1,
.f_detach = linux_file_kqfilter_detach,
.f_event = linux_file_kqfilter_write_event,
+ .f_copy = knote_triv_copy,
};
static void
@@ -1541,7 +1561,7 @@ linux_file_close(struct file *file, struct thread *td)
error = -OPW(file, td, release(filp->f_vnode, filp));
funsetown(&filp->f_sigio);
if (filp->f_vnode != NULL)
- vdrop(filp->f_vnode);
+ vrele(filp->f_vnode);
linux_drop_fop(ldev);
ldev = filp->f_cdev;
if (ldev != NULL)
@@ -1761,7 +1781,20 @@ linux_iminor(struct inode *inode)
return (minor(ldev->dev));
}
-struct fileops linuxfileops = {
+static int
+linux_file_kcmp(struct file *fp1, struct file *fp2, struct thread *td)
+{
+ struct linux_file *filp1, *filp2;
+
+ if (fp2->f_type != DTYPE_DEV)
+ return (3);
+
+ filp1 = fp1->f_data;
+ filp2 = fp2->f_data;
+ return (kcmp_cmp((uintptr_t)filp1->f_cdev, (uintptr_t)filp2->f_cdev));
+}
+
+const struct fileops linuxfileops = {
.fo_read = linux_file_read,
.fo_write = linux_file_write,
.fo_truncate = invfo_truncate,
@@ -1775,6 +1808,7 @@ struct fileops linuxfileops = {
.fo_chmod = invfo_chmod,
.fo_chown = invfo_chown,
.fo_sendfile = invfo_sendfile,
+ .fo_cmp = linux_file_kcmp,
.fo_flags = DFLAG_PASSABLE,
};
@@ -1851,7 +1885,7 @@ iounmap(void *addr)
if (vmmap == NULL)
return;
#if defined(__i386__) || defined(__amd64__) || defined(__powerpc__) || defined(__aarch64__) || defined(__riscv)
- pmap_unmapdev((vm_offset_t)addr, vmmap->vm_size);
+ pmap_unmapdev(addr, vmmap->vm_size);
#endif
kfree(vmmap);
}
@@ -1939,6 +1973,84 @@ kasprintf(gfp_t gfp, const char *fmt, ...)
return (p);
}
+int
+__lkpi_hexdump_printf(void *arg1 __unused, const char *fmt, ...)
+{
+ va_list ap;
+ int result;
+
+ va_start(ap, fmt);
+ result = vprintf(fmt, ap);
+ va_end(ap);
+ return (result);
+}
+
+int
+__lkpi_hexdump_sbuf_printf(void *arg1, const char *fmt, ...)
+{
+ va_list ap;
+ int result;
+
+ va_start(ap, fmt);
+ result = sbuf_vprintf(arg1, fmt, ap);
+ va_end(ap);
+ return (result);
+}
+
+void
+lkpi_hex_dump(int(*_fpf)(void *, const char *, ...), void *arg1,
+ const char *level, const char *prefix_str,
+ const int prefix_type, const int rowsize, const int groupsize,
+ const void *buf, size_t len, const bool ascii)
+{
+ typedef const struct { long long value; } __packed *print_64p_t;
+ typedef const struct { uint32_t value; } __packed *print_32p_t;
+ typedef const struct { uint16_t value; } __packed *print_16p_t;
+ const void *buf_old = buf;
+ int row;
+
+ while (len > 0) {
+ if (level != NULL)
+ _fpf(arg1, "%s", level);
+ if (prefix_str != NULL)
+ _fpf(arg1, "%s ", prefix_str);
+
+ switch (prefix_type) {
+ case DUMP_PREFIX_ADDRESS:
+ _fpf(arg1, "[%p] ", buf);
+ break;
+ case DUMP_PREFIX_OFFSET:
+ _fpf(arg1, "[%#tx] ", ((const char *)buf -
+ (const char *)buf_old));
+ break;
+ default:
+ break;
+ }
+ for (row = 0; row != rowsize; row++) {
+ if (groupsize == 8 && len > 7) {
+ _fpf(arg1, "%016llx ", ((print_64p_t)buf)->value);
+ buf = (const uint8_t *)buf + 8;
+ len -= 8;
+ } else if (groupsize == 4 && len > 3) {
+ _fpf(arg1, "%08x ", ((print_32p_t)buf)->value);
+ buf = (const uint8_t *)buf + 4;
+ len -= 4;
+ } else if (groupsize == 2 && len > 1) {
+ _fpf(arg1, "%04x ", ((print_16p_t)buf)->value);
+ buf = (const uint8_t *)buf + 2;
+ len -= 2;
+ } else if (len > 0) {
+ _fpf(arg1, "%02x ", *(const uint8_t *)buf);
+ buf = (const uint8_t *)buf + 1;
+ len--;
+ } else {
+ break;
+ }
+ }
+ _fpf(arg1, "\n");
+ }
+}
+
static void
linux_timer_callback_wrapper(void *context)
{
@@ -1946,6 +2058,10 @@ linux_timer_callback_wrapper(void *context)
timer = context;
+ /* the timer is about to be shutdown permanently */
+ if (timer->function == NULL)
+ return;
+
if (linux_set_current_flags(curthread, M_NOWAIT)) {
/* try again later */
callout_reset(&timer->callout, 1,
@@ -1956,8 +2072,24 @@ linux_timer_callback_wrapper(void *context)
timer->function(timer->data);
}
+static int
+linux_timer_jiffies_until(unsigned long expires)
+{
+ unsigned long delta = expires - jiffies;
+
+ /*
+ * Guard against already expired values and make sure that the value can
+ * be used as a tick count, rather than a jiffies count.
+ */
+ if ((long)delta < 1)
+ delta = 1;
+ else if (delta > INT_MAX)
+ delta = INT_MAX;
+ return ((int)delta);
+}
+
int
-mod_timer(struct timer_list *timer, int expires)
+mod_timer(struct timer_list *timer, unsigned long expires)
{
int ret;
@@ -1990,7 +2122,7 @@ add_timer_on(struct timer_list *timer, int cpu)
}
int
-del_timer(struct timer_list *timer)
+timer_delete(struct timer_list *timer)
{
if (callout_stop(&(timer)->callout) == -1)
@@ -1999,7 +2131,7 @@ del_timer(struct timer_list *timer)
}
int
-del_timer_sync(struct timer_list *timer)
+timer_delete_sync(struct timer_list *timer)
{
if (callout_drain(&(timer)->callout) == -1)
@@ -2007,6 +2139,14 @@ del_timer_sync(struct timer_list *timer)
return (1);
}
+int
+timer_shutdown_sync(struct timer_list *timer)
+{
+
+ timer->function = NULL;
+ return (del_timer_sync(timer));
+}
+
/* greatest common divisor, Euclid equation */
static uint64_t
lkpi_gcd_64(uint64_t a, uint64_t b)
@@ -2076,20 +2216,16 @@ SYSINIT(linux_timer, SI_SUB_DRIVERS, SI_ORDER_FIRST, linux_timer_init, NULL);
void
linux_complete_common(struct completion *c, int all)
{
- int wakeup_swapper;
-
sleepq_lock(c);
if (all) {
c->done = UINT_MAX;
- wakeup_swapper = sleepq_broadcast(c, SLEEPQ_SLEEP, 0, 0);
+ sleepq_broadcast(c, SLEEPQ_SLEEP, 0, 0);
} else {
if (c->done != UINT_MAX)
c->done++;
- wakeup_swapper = sleepq_signal(c, SLEEPQ_SLEEP, 0, 0);
+ sleepq_signal(c, SLEEPQ_SLEEP, 0, 0);
}
sleepq_release(c);
- if (wakeup_swapper)
- kick_proc0();
}
/*
@@ -2142,12 +2278,12 @@ intr:
/*
* Time limited wait for done != 0 with or without signals.
*/
-int
-linux_wait_for_timeout_common(struct completion *c, int timeout, int flags)
+unsigned long
+linux_wait_for_timeout_common(struct completion *c, unsigned long timeout,
+ int flags)
{
struct task_struct *task;
- int end = jiffies + timeout;
- int error;
+ unsigned long end = jiffies + timeout, error;
if (SCHEDULER_STOPPED())
return (0);
@@ -2437,7 +2573,7 @@ struct list_sort_thunk {
};
static inline int
-linux_le_cmp(void *priv, const void *d1, const void *d2)
+linux_le_cmp(const void *d1, const void *d2, void *priv)
{
struct list_head *le1, *le2;
struct list_sort_thunk *thunk;
@@ -2465,7 +2601,7 @@ list_sort(void *priv, struct list_head *head, int (*cmp)(void *priv,
ar[i++] = le;
thunk.cmp = cmp;
thunk.priv = priv;
- qsort_r(ar, count, sizeof(struct list_head *), &thunk, linux_le_cmp);
+ qsort_r(ar, count, sizeof(struct list_head *), linux_le_cmp, &thunk);
INIT_LIST_HEAD(head);
for (i = 0; i < count; i++)
list_add_tail(ar[i], head);
@@ -2580,7 +2716,6 @@ linux_dump_stack(void)
#ifdef STACK
struct stack st;
- stack_zero(&st);
stack_save(&st);
stack_print(&st);
#endif
@@ -2594,10 +2729,103 @@ linuxkpi_net_ratelimit(void)
lkpi_net_maxpps));
}
+struct io_mapping *
+io_mapping_create_wc(resource_size_t base, unsigned long size)
+{
+ struct io_mapping *mapping;
+
+ mapping = kmalloc(sizeof(*mapping), GFP_KERNEL);
+ if (mapping == NULL)
+ return (NULL);
+ return (io_mapping_init_wc(mapping, base, size));
+}
+
+/* We likely want a linuxkpi_device.c at some point. */
+bool
+device_can_wakeup(struct device *dev)
+{
+
+ if (dev == NULL)
+ return (false);
+ /*
+ * XXX-BZ iwlwifi queries it as part of enabling WoWLAN.
+ * Normally this would be based on a bool in dev->power.XXX.
+ * Check such as PCI PCIM_PCAP_*PME. We have no way to enable this yet.
+ * We may get away by directly calling into bsddev for as long as
+ * we can assume PCI only avoiding changing struct device breaking KBI.
+ */
+ pr_debug("%s:%d: not enabled; see comment.\n", __func__, __LINE__);
+ return (false);
+}
+
+static void
+devm_device_group_remove(struct device *dev, void *p)
+{
+ const struct attribute_group **dr = p;
+ const struct attribute_group *group = *dr;
+
+ sysfs_remove_group(&dev->kobj, group);
+}
+
+int
+lkpi_devm_device_add_group(struct device *dev,
+ const struct attribute_group *group)
+{
+ const struct attribute_group **dr;
+ int ret;
+
+ dr = devres_alloc(devm_device_group_remove, sizeof(*dr), GFP_KERNEL);
+ if (dr == NULL)
+ return (-ENOMEM);
+
+ ret = sysfs_create_group(&dev->kobj, group);
+ if (ret == 0) {
+ *dr = group;
+ devres_add(dev, dr);
+ } else
+ devres_free(dr);
+
+ return (ret);
+}
+
#if defined(__i386__) || defined(__amd64__)
bool linux_cpu_has_clflush;
+struct cpuinfo_x86 boot_cpu_data;
+struct cpuinfo_x86 *__cpu_data;
#endif
+cpumask_t *
+lkpi_get_static_single_cpu_mask(int cpuid)
+{
+
+ KASSERT((cpuid >= 0 && cpuid <= mp_maxid), ("%s: invalid cpuid %d\n",
+ __func__, cpuid));
+ KASSERT(!CPU_ABSENT(cpuid), ("%s: cpu with cpuid %d is absent\n",
+ __func__, cpuid));
+
+ return (static_single_cpu_mask[cpuid]);
+}
+
+bool
+lkpi_xen_initial_domain(void)
+{
+#ifdef XENHVM
+ return (xen_initial_domain());
+#else
+ return (false);
+#endif
+}
+
+bool
+lkpi_xen_pv_domain(void)
+{
+#ifdef XENHVM
+ return (xen_pv_domain());
+#else
+ return (false);
+#endif
+}
+
static void
linux_compat_init(void *arg)
{
@@ -2605,7 +2833,40 @@ linux_compat_init(void *arg)
int i;
#if defined(__i386__) || defined(__amd64__)
+ static const uint32_t x86_vendors[X86_VENDOR_NUM] = {
+ [X86_VENDOR_INTEL] = CPU_VENDOR_INTEL,
+ [X86_VENDOR_CYRIX] = CPU_VENDOR_CYRIX,
+ [X86_VENDOR_AMD] = CPU_VENDOR_AMD,
+ [X86_VENDOR_UMC] = CPU_VENDOR_UMC,
+ [X86_VENDOR_CENTAUR] = CPU_VENDOR_CENTAUR,
+ [X86_VENDOR_TRANSMETA] = CPU_VENDOR_TRANSMETA,
+ [X86_VENDOR_NSC] = CPU_VENDOR_NSC,
+ [X86_VENDOR_HYGON] = CPU_VENDOR_HYGON,
+ };
+ uint8_t x86_vendor = X86_VENDOR_UNKNOWN;
+
+ for (i = 0; i < X86_VENDOR_NUM; i++) {
+ if (cpu_vendor_id != 0 && cpu_vendor_id == x86_vendors[i]) {
+ x86_vendor = i;
+ break;
+ }
+ }
linux_cpu_has_clflush = (cpu_feature & CPUID_CLFSH);
+ boot_cpu_data.x86_clflush_size = cpu_clflush_line_size;
+ boot_cpu_data.x86_max_cores = mp_ncpus;
+ boot_cpu_data.x86 = CPUID_TO_FAMILY(cpu_id);
+ boot_cpu_data.x86_model = CPUID_TO_MODEL(cpu_id);
+ boot_cpu_data.x86_vendor = x86_vendor;
+
+ __cpu_data = kmalloc_array(mp_maxid + 1,
+ sizeof(*__cpu_data), M_WAITOK | M_ZERO);
+ CPU_FOREACH(i) {
+ __cpu_data[i].x86_clflush_size = cpu_clflush_line_size;
+ __cpu_data[i].x86_max_cores = mp_ncpus;
+ __cpu_data[i].x86 = CPUID_TO_FAMILY(cpu_id);
+ __cpu_data[i].x86_model = CPUID_TO_MODEL(cpu_id);
+ __cpu_data[i].x86_vendor = x86_vendor;
+ }
#endif
rw_init(&linux_vma_lock, "lkpi-vma-lock");
@@ -2633,6 +2894,96 @@ linux_compat_init(void *arg)
init_waitqueue_head(&linux_var_waitq);
CPU_COPY(&all_cpus, &cpu_online_mask);
+ /*
+ * Generate a single-CPU cpumask_t for each CPU (possibly) in the system.
+ * CPUs are indexed from 0..(mp_maxid). The entry for cpuid 0 will only
+ * have itself in the cpumask, cupid 1 only itself on entry 1, and so on.
+ * This is used by cpumask_of() (and possibly others in the future) for,
+ * e.g., drivers to pass hints to irq_set_affinity_hint().
+ */
+ static_single_cpu_mask = kmalloc_array(mp_maxid + 1,
+ sizeof(static_single_cpu_mask), M_WAITOK | M_ZERO);
+
+ /*
+ * When the number of CPUs reach a threshold, we start to save memory
+ * given the sets are static by overlapping those having their single
+ * bit set at same position in a bitset word. Asymptotically, this
+ * regular scheme is in O(n²) whereas the overlapping one is in O(n)
+ * only with n being the maximum number of CPUs, so the gain will become
+ * huge quite quickly. The threshold for 64-bit architectures is 128
+ * CPUs.
+ */
+ if (mp_ncpus < (2 * _BITSET_BITS)) {
+ cpumask_t *sscm_ptr;
+
+ /*
+ * This represents 'mp_ncpus * __bitset_words(CPU_SETSIZE) *
+ * (_BITSET_BITS / 8)' bytes (for comparison with the
+ * overlapping scheme).
+ */
+ static_single_cpu_mask_lcs = kmalloc_array(mp_ncpus,
+ sizeof(*static_single_cpu_mask_lcs),
+ M_WAITOK | M_ZERO);
+
+ sscm_ptr = static_single_cpu_mask_lcs;
+ CPU_FOREACH(i) {
+ static_single_cpu_mask[i] = sscm_ptr++;
+ CPU_SET(i, static_single_cpu_mask[i]);
+ }
+ } else {
+ /* Pointer to a bitset word. */
+ __typeof(((cpuset_t *)NULL)->__bits[0]) *bwp;
+
+ /*
+ * Allocate memory for (static) spans of 'cpumask_t' ('cpuset_t'
+ * really) with a single bit set that can be reused for all
+ * single CPU masks by making them start at different offsets.
+ * We need '__bitset_words(CPU_SETSIZE) - 1' bitset words before
+ * the word having its single bit set, and the same amount
+ * after.
+ */
+ static_single_cpu_mask_lcs = mallocarray(_BITSET_BITS,
+ (2 * __bitset_words(CPU_SETSIZE) - 1) * (_BITSET_BITS / 8),
+ M_KMALLOC, M_WAITOK | M_ZERO);
+
+ /*
+ * We rely below on cpuset_t and the bitset generic
+ * implementation assigning words in the '__bits' array in the
+ * same order of bits (i.e., little-endian ordering, not to be
+ * confused with machine endianness, which concerns bits in
+ * words and other integers). This is an imperfect test, but it
+ * will detect a change to big-endian ordering.
+ */
+ _Static_assert(
+ __bitset_word(_BITSET_BITS + 1, _BITSET_BITS) == 1,
+ "Assumes a bitset implementation that is little-endian "
+ "on its words");
+
+ /* Initialize the single bit of each static span. */
+ bwp = (__typeof(bwp))static_single_cpu_mask_lcs +
+ (__bitset_words(CPU_SETSIZE) - 1);
+ for (i = 0; i < _BITSET_BITS; i++) {
+ CPU_SET(i, (cpuset_t *)bwp);
+ bwp += (2 * __bitset_words(CPU_SETSIZE) - 1);
+ }
+
+ /*
+ * Finally set all CPU masks to the proper word in their
+ * relevant span.
+ */
+ CPU_FOREACH(i) {
+ bwp = (__typeof(bwp))static_single_cpu_mask_lcs;
+ /* Find the non-zero word of the relevant span. */
+ bwp += (2 * __bitset_words(CPU_SETSIZE) - 1) *
+ (i % _BITSET_BITS) +
+ __bitset_words(CPU_SETSIZE) - 1;
+ /* Shift to find the CPU mask start. */
+ bwp -= (i / _BITSET_BITS);
+ static_single_cpu_mask[i] = (cpuset_t *)bwp;
+ }
+ }
+
+ strlcpy(init_uts_ns.name.release, osrelease, sizeof(init_uts_ns.name.release));
}
SYSINIT(linux_compat, SI_SUB_DRIVERS, SI_ORDER_SECOND, linux_compat_init, NULL);
@@ -2643,6 +2994,12 @@ linux_compat_uninit(void *arg)
linux_kobject_kfree_name(&linux_root_device.kobj);
linux_kobject_kfree_name(&linux_class_misc.kobj);
+ free(static_single_cpu_mask_lcs, M_KMALLOC);
+ free(static_single_cpu_mask, M_KMALLOC);
+#if defined(__i386__) || defined(__amd64__)
+ free(__cpu_data, M_KMALLOC);
+#endif
+
mtx_destroy(&vmmaplock);
spin_lock_destroy(&pci_lock);
rw_destroy(&linux_vma_lock);
diff --git a/sys/compat/linuxkpi/common/src/linux_current.c b/sys/compat/linuxkpi/common/src/linux_current.c
index 925d96770cc2..c342eb279caa 100644
--- a/sys/compat/linuxkpi/common/src/linux_current.c
+++ b/sys/compat/linuxkpi/common/src/linux_current.c
@@ -25,7 +25,11 @@
*/
#include <sys/cdefs.h>
-__FBSDID("$FreeBSD$");
+#ifdef __amd64__
+#define DEV_APIC
+#elif defined(__i386__)
+#include "opt_apic.h"
+#endif
#include <linux/compat.h>
#include <linux/completion.h>
@@ -39,7 +43,7 @@ __FBSDID("$FreeBSD$");
#include <sys/sysctl.h>
#include <vm/uma.h>
-#if defined(__i386__) || defined(__amd64__)
+#ifdef DEV_APIC
extern u_int first_msi_irq, num_msi_irqs;
#endif
@@ -274,7 +278,7 @@ linux_current_init(void *arg __unused)
TUNABLE_INT_FETCH("compat.linuxkpi.task_struct_reserve",
&lkpi_task_resrv);
if (lkpi_task_resrv == 0) {
-#if defined(__i386__) || defined(__amd64__)
+#ifdef DEV_APIC
/*
* Number of interrupt threads plus per-cpu callout
* SWI threads.
@@ -290,7 +294,7 @@ linux_current_init(void *arg __unused)
uma_zone_reserve(linux_current_zone, lkpi_task_resrv);
uma_prealloc(linux_current_zone, lkpi_task_resrv);
linux_mm_zone = uma_zcreate("lkpimm",
- sizeof(struct task_struct), NULL, NULL, NULL, NULL,
+ sizeof(struct mm_struct), NULL, NULL, NULL, NULL,
UMA_ALIGN_PTR, 0);
uma_zone_reserve(linux_mm_zone, lkpi_task_resrv);
uma_prealloc(linux_mm_zone, lkpi_task_resrv);
@@ -301,7 +305,7 @@ linux_current_init(void *arg __unused)
linuxkpi_thread_dtor, NULL, EVENTHANDLER_PRI_ANY);
lkpi_alloc_current = linux_alloc_current;
}
-SYSINIT(linux_current, SI_SUB_EVENTHANDLER, SI_ORDER_SECOND,
+SYSINIT(linux_current, SI_SUB_EVENTHANDLER + 1, SI_ORDER_SECOND,
linux_current_init, NULL);
static void
@@ -335,5 +339,5 @@ linux_current_uninit(void *arg __unused)
uma_zdestroy(linux_current_zone);
uma_zdestroy(linux_mm_zone);
}
-SYSUNINIT(linux_current, SI_SUB_EVENTHANDLER, SI_ORDER_SECOND,
+SYSUNINIT(linux_current, SI_SUB_EVENTHANDLER + 1, SI_ORDER_SECOND,
linux_current_uninit, NULL);
diff --git a/sys/compat/linuxkpi/common/src/linux_devres.c b/sys/compat/linuxkpi/common/src/linux_devres.c
index 96ff3e486d1d..23c91cb5ab2f 100644
--- a/sys/compat/linuxkpi/common/src/linux_devres.c
+++ b/sys/compat/linuxkpi/common/src/linux_devres.c
@@ -1,7 +1,7 @@
/*-
* SPDX-License-Identifier: BSD-2-Clause
*
- * Copyright (c) 2020-2021 The FreeBSD Foundation
+ * Copyright (c) 2020-2025 The FreeBSD Foundation
*
* This software was developed by Bj\xc3\xb6rn Zeeb under sponsorship from
* the FreeBSD Foundation.
@@ -29,8 +29,6 @@
*/
#include <sys/cdefs.h>
-__FBSDID("$FreeBSD$");
-
#include <linux/kernel.h>
#include <linux/device.h>
#include <linux/slab.h>
@@ -224,3 +222,70 @@ lkpi_devm_kmalloc_release(struct device *dev __unused, void *p __unused)
/* Nothing to do. Freed with the devres. */
}
+
+static int
+lkpi_devm_kmalloc_match(struct device *dev __unused, void *p, void *mp)
+{
+ return (p == mp);
+}
+
+void
+lkpi_devm_kfree(struct device *dev, const void *p)
+{
+ void *mp;
+ int error;
+
+ if (p == NULL)
+ return;
+
+ /* I assume Linux simply casts the const away... */
+ mp = __DECONST(void *, p);
+ error = lkpi_devres_destroy(dev, lkpi_devm_kmalloc_release,
+ lkpi_devm_kmalloc_match, mp);
+ if (error != 0)
+ dev_warn(dev, "%s: lkpi_devres_destroy failed with %d\n",
+ __func__, error);
+}
+
+struct devres_action {
+ void *data;
+ void (*action)(void *);
+};
+
+static void
+lkpi_devm_action_release(struct device *dev, void *res)
+{
+ struct devres_action *devres;
+
+ devres = (struct devres_action *)res;
+ devres->action(devres->data);
+}
+
+int
+lkpi_devm_add_action(struct device *dev, void (*action)(void *), void *data)
+{
+ struct devres_action *devres;
+
+ KASSERT(action != NULL, ("%s: action is NULL\n", __func__));
+ devres = lkpi_devres_alloc(lkpi_devm_action_release,
+ sizeof(struct devres_action), GFP_KERNEL);
+ if (devres == NULL)
+ return (-ENOMEM);
+ devres->data = data;
+ devres->action = action;
+ devres_add(dev, devres);
+
+ return (0);
+}
+
+int
+lkpi_devm_add_action_or_reset(struct device *dev, void (*action)(void *), void *data)
+{
+ int rv;
+
+ rv = lkpi_devm_add_action(dev, action, data);
+ if (rv != 0)
+ action(data);
+
+ return (rv);
+}
diff --git a/sys/compat/linuxkpi/common/src/linux_dmi.c b/sys/compat/linuxkpi/common/src/linux_dmi.c
index c0bb9a9f50d6..9e3faaeddeb9 100644
--- a/sys/compat/linuxkpi/common/src/linux_dmi.c
+++ b/sys/compat/linuxkpi/common/src/linux_dmi.c
@@ -24,8 +24,6 @@
* 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.
- *
- * $FreeBSD$
*/
#include <sys/param.h>
@@ -77,16 +75,25 @@ linux_dmi_match(enum dmi_field f, const char *str)
static bool
linux_dmi_matches(const struct dmi_system_id *dsi)
{
+ enum dmi_field slot;
int i;
for (i = 0; i < nitems(dsi->matches); i++) {
- if (dsi->matches[i].slot == DMI_NONE)
+ slot = dsi->matches[i].slot;
+ if (slot == DMI_NONE)
break;
- if (dmi_match(dsi->matches[i].slot,
- dsi->matches[i].substr) == false)
+ if (slot >= DMI_STRING_MAX ||
+ dmi_data[slot] == NULL)
return (false);
+ if (dsi->matches[i].exact_match) {
+ if (dmi_match(slot, dsi->matches[i].substr))
+ continue;
+ } else if (strstr(dmi_data[slot],
+ dsi->matches[i].substr) != NULL) {
+ continue;
+ }
+ return (false);
}
-
return (true);
}
diff --git a/sys/compat/linuxkpi/common/src/linux_domain.c b/sys/compat/linuxkpi/common/src/linux_domain.c
index acbf8821d42b..8e936aac4719 100644
--- a/sys/compat/linuxkpi/common/src/linux_domain.c
+++ b/sys/compat/linuxkpi/common/src/linux_domain.c
@@ -24,9 +24,6 @@
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
-#include <sys/cdefs.h>
-__FBSDID("$FreeBSD$");
-
#include <sys/param.h>
#include <sys/systm.h>
#include <sys/domainset.h>
diff --git a/sys/compat/linuxkpi/common/src/linux_firmware.c b/sys/compat/linuxkpi/common/src/linux_firmware.c
index 47cccd42da20..12658df5ce83 100644
--- a/sys/compat/linuxkpi/common/src/linux_firmware.c
+++ b/sys/compat/linuxkpi/common/src/linux_firmware.c
@@ -2,6 +2,7 @@
* SPDX-License-Identifier: BSD-2-Clause
*
* Copyright (c) 2020-2021 The FreeBSD Foundation
+ * Copyright (c) 2022 Bjoern A. Zeeb
*
* This software was developed by Björn Zeeb under sponsorship from
* the FreeBSD Foundation.
@@ -26,8 +27,6 @@
* 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.
- *
- * $FreeBSD$
*/
#include <sys/param.h>
@@ -89,17 +88,17 @@ _linuxkpi_request_firmware(const char *fw_name, const struct linuxkpi_firmware *
* way rather than adding more name-mangling-hacks here in the future
* (though we could if needed).
*/
- /* (1) Try any name removed of path. */
- fwimg = strrchr(fw_name, '/');
- if (fwimg != NULL)
- fwimg++;
- if (fwimg == NULL || *fwimg == '\0')
- fwimg = fw_name;
- fbdfw = firmware_get_flags(fwimg, flags);
- /* (2) Try the original name if we have not yet. */
- if (fbdfw == NULL && fwimg != fw_name) {
- fwimg = fw_name;
- fbdfw = firmware_get_flags(fwimg, flags);
+ /* (1) Try the original name. */
+ fbdfw = firmware_get_flags(fw_name, flags);
+ /* (2) Try any name removed of path, if we have not yet. */
+ if (fbdfw == NULL) {
+ fwimg = strrchr(fw_name, '/');
+ if (fwimg != NULL)
+ fwimg++;
+ if (fwimg == NULL || *fwimg == '\0')
+ fwimg = fw_name;
+ if (fwimg != fw_name)
+ fbdfw = firmware_get_flags(fwimg, flags);
}
/* (3) Flatten '/', '.' and '-' to '_' and try with adjusted name. */
if (fbdfw == NULL &&
@@ -223,3 +222,26 @@ linuxkpi_release_firmware(const struct linuxkpi_firmware *fw)
firmware_put(fw->fbdfw, FIRMWARE_UNLOAD);
free(__DECONST(void *, fw), M_LKPI_FW);
}
+
+int
+linuxkpi_request_partial_firmware_into_buf(const struct linuxkpi_firmware **fw,
+ const char *fw_name, struct device *dev, uint8_t *buf, size_t buflen,
+ size_t offset)
+{
+ const struct linuxkpi_firmware *lfw;
+ int error;
+
+ error = linuxkpi_request_firmware(fw, fw_name, dev);
+ if (error != 0)
+ return (error);
+
+ lfw = *fw;
+ if ((offset + buflen) >= lfw->size) {
+ linuxkpi_release_firmware(lfw);
+ return (-ERANGE);
+ }
+
+ memcpy(buf, lfw->data + offset, buflen);
+
+ return (0);
+}
diff --git a/sys/compat/linuxkpi/common/src/linux_folio.c b/sys/compat/linuxkpi/common/src/linux_folio.c
new file mode 100644
index 000000000000..c2af7792be04
--- /dev/null
+++ b/sys/compat/linuxkpi/common/src/linux_folio.c
@@ -0,0 +1,58 @@
+/*-
+ * Copyright (c) 2024-2025 The FreeBSD Foundation
+ * Copyright (c) 2024-2025 Jean-Sébastien Pédron
+ *
+ * This software was developed by Jean-Sébastien Pédron under sponsorship
+ * from the FreeBSD Foundation.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``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 OR CONTRIBUTORS 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.
+ */
+
+#include <linux/gfp.h>
+#include <linux/mm.h>
+#include <linux/mm_types.h>
+#include <linux/page.h>
+#include <linux/pagevec.h>
+
+struct folio *
+folio_alloc(gfp_t gfp, unsigned int order)
+{
+ struct page *page;
+ struct folio *folio;
+
+ /*
+ * Allocated pages are wired already. There is no need to increase a
+ * refcount here.
+ */
+ page = alloc_pages(gfp | __GFP_COMP, order);
+ folio = (struct folio *)page;
+
+ return (folio);
+}
+
+void
+__folio_batch_release(struct folio_batch *fbatch)
+{
+ release_pages(fbatch->folios, folio_batch_count(fbatch));
+
+ folio_batch_reinit(fbatch);
+}
diff --git a/sys/compat/linuxkpi/common/src/linux_fpu.c b/sys/compat/linuxkpi/common/src/linux_fpu.c
index 08f7e075d827..4e40a2b004bb 100644
--- a/sys/compat/linuxkpi/common/src/linux_fpu.c
+++ b/sys/compat/linuxkpi/common/src/linux_fpu.c
@@ -1,7 +1,7 @@
/*-
- * SPDX-License-Identifier: BSD-2-Clause-FreeBSD
+ * SPDX-License-Identifier: BSD-2-Clause
*
- * Copyright (c) 2020 Greg V <greg@unrelenting.technology>
+ * Copyright (c) 2020 Val Packett <val@packett.cool>
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
@@ -30,11 +30,13 @@
#include <sys/proc.h>
#include <sys/kernel.h>
+#include <linux/compat.h>
#include <linux/sched.h>
#include <asm/fpu/api.h>
-#if defined(__aarch64__) || defined(__amd64__) || defined(__i386__)
+#if defined(__aarch64__) || defined(__arm__) || defined(__amd64__) || \
+ defined(__i386__) || defined(__powerpc64__)
#include <machine/fpu.h>
@@ -58,6 +60,24 @@ lkpi_kernel_fpu_end(void)
fpu_kern_leave(curthread, NULL);
}
+void
+lkpi_fpu_safe_exec(fpu_safe_exec_cb_t func, void *ctx)
+{
+ unsigned int save_fpu_level;
+
+ save_fpu_level =
+ __current_unallocated(curthread) ? 0 : current->fpu_ctx_level;
+ if (__predict_false(save_fpu_level != 0)) {
+ current->fpu_ctx_level = 1;
+ kernel_fpu_end();
+ }
+ func(ctx);
+ if (__predict_false(save_fpu_level != 0)) {
+ kernel_fpu_begin();
+ current->fpu_ctx_level = save_fpu_level;
+ }
+}
+
#else
void
@@ -70,4 +90,10 @@ lkpi_kernel_fpu_end(void)
{
}
+void
+lkpi_fpu_safe_exec(fpu_safe_exec_cb_t func, void *ctx)
+{
+ func(ctx);
+}
+
#endif
diff --git a/sys/compat/linuxkpi/common/src/linux_hdmi.c b/sys/compat/linuxkpi/common/src/linux_hdmi.c
new file mode 100644
index 000000000000..fc47693e913c
--- /dev/null
+++ b/sys/compat/linuxkpi/common/src/linux_hdmi.c
@@ -0,0 +1,1959 @@
+/*
+ * Copyright (C) 2012 Avionic Design GmbH
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sub license,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice (including the
+ * next paragraph) shall be included in all copies or substantial portions
+ * of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL
+ * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+ * DEALINGS IN THE SOFTWARE.
+ */
+
+#ifdef __linux__
+#include <drm/display/drm_dp.h>
+#endif
+#include <linux/bitops.h>
+#include <linux/bug.h>
+#include <linux/errno.h>
+#include <linux/export.h>
+#include <linux/hdmi.h>
+#include <linux/string.h>
+#include <linux/device.h>
+
+#define hdmi_log(fmt, ...) dev_printk(level, dev, fmt, ##__VA_ARGS__)
+
+static u8 hdmi_infoframe_checksum(const u8 *ptr, size_t size)
+{
+ u8 csum = 0;
+ size_t i;
+
+ /* compute checksum */
+ for (i = 0; i < size; i++)
+ csum += ptr[i];
+
+ return 256 - csum;
+}
+
+static void hdmi_infoframe_set_checksum(void *buffer, size_t size)
+{
+ u8 *ptr = buffer;
+
+ ptr[3] = hdmi_infoframe_checksum(buffer, size);
+}
+
+/**
+ * hdmi_avi_infoframe_init() - initialize an HDMI AVI infoframe
+ * @frame: HDMI AVI infoframe
+ */
+void hdmi_avi_infoframe_init(struct hdmi_avi_infoframe *frame)
+{
+ memset(frame, 0, sizeof(*frame));
+
+ frame->type = HDMI_INFOFRAME_TYPE_AVI;
+ frame->version = 2;
+ frame->length = HDMI_AVI_INFOFRAME_SIZE;
+}
+EXPORT_SYMBOL(hdmi_avi_infoframe_init);
+
+static int hdmi_avi_infoframe_check_only(const struct hdmi_avi_infoframe *frame)
+{
+ if (frame->type != HDMI_INFOFRAME_TYPE_AVI ||
+ frame->version != 2 ||
+ frame->length != HDMI_AVI_INFOFRAME_SIZE)
+ return -EINVAL;
+
+ if (frame->picture_aspect > HDMI_PICTURE_ASPECT_16_9)
+ return -EINVAL;
+
+ return 0;
+}
+
+/**
+ * hdmi_avi_infoframe_check() - check a HDMI AVI infoframe
+ * @frame: HDMI AVI infoframe
+ *
+ * Validates that the infoframe is consistent and updates derived fields
+ * (eg. length) based on other fields.
+ *
+ * Returns 0 on success or a negative error code on failure.
+ */
+int hdmi_avi_infoframe_check(struct hdmi_avi_infoframe *frame)
+{
+ return hdmi_avi_infoframe_check_only(frame);
+}
+EXPORT_SYMBOL(hdmi_avi_infoframe_check);
+
+/**
+ * hdmi_avi_infoframe_pack_only() - write HDMI AVI infoframe to binary buffer
+ * @frame: HDMI AVI infoframe
+ * @buffer: destination buffer
+ * @size: size of buffer
+ *
+ * Packs the information contained in the @frame structure into a binary
+ * representation that can be written into the corresponding controller
+ * registers. Also computes the checksum as required by section 5.3.5 of
+ * the HDMI 1.4 specification.
+ *
+ * Returns the number of bytes packed into the binary buffer or a negative
+ * error code on failure.
+ */
+ssize_t hdmi_avi_infoframe_pack_only(const struct hdmi_avi_infoframe *frame,
+ void *buffer, size_t size)
+{
+ u8 *ptr = buffer;
+ size_t length;
+ int ret;
+
+ ret = hdmi_avi_infoframe_check_only(frame);
+ if (ret)
+ return ret;
+
+ length = HDMI_INFOFRAME_HEADER_SIZE + frame->length;
+
+ if (size < length)
+ return -ENOSPC;
+
+ memset(buffer, 0, size);
+
+ ptr[0] = frame->type;
+ ptr[1] = frame->version;
+ ptr[2] = frame->length;
+ ptr[3] = 0; /* checksum */
+
+ /* start infoframe payload */
+ ptr += HDMI_INFOFRAME_HEADER_SIZE;
+
+ ptr[0] = ((frame->colorspace & 0x3) << 5) | (frame->scan_mode & 0x3);
+
+ /*
+ * Data byte 1, bit 4 has to be set if we provide the active format
+ * aspect ratio
+ */
+ if (frame->active_aspect & 0xf)
+ ptr[0] |= BIT(4);
+
+ /* Bit 3 and 2 indicate if we transmit horizontal/vertical bar data */
+ if (frame->top_bar || frame->bottom_bar)
+ ptr[0] |= BIT(3);
+
+ if (frame->left_bar || frame->right_bar)
+ ptr[0] |= BIT(2);
+
+ ptr[1] = ((frame->colorimetry & 0x3) << 6) |
+ ((frame->picture_aspect & 0x3) << 4) |
+ (frame->active_aspect & 0xf);
+
+ ptr[2] = ((frame->extended_colorimetry & 0x7) << 4) |
+ ((frame->quantization_range & 0x3) << 2) |
+ (frame->nups & 0x3);
+
+ if (frame->itc)
+ ptr[2] |= BIT(7);
+
+ ptr[3] = frame->video_code & 0x7f;
+
+ ptr[4] = ((frame->ycc_quantization_range & 0x3) << 6) |
+ ((frame->content_type & 0x3) << 4) |
+ (frame->pixel_repeat & 0xf);
+
+ ptr[5] = frame->top_bar & 0xff;
+ ptr[6] = (frame->top_bar >> 8) & 0xff;
+ ptr[7] = frame->bottom_bar & 0xff;
+ ptr[8] = (frame->bottom_bar >> 8) & 0xff;
+ ptr[9] = frame->left_bar & 0xff;
+ ptr[10] = (frame->left_bar >> 8) & 0xff;
+ ptr[11] = frame->right_bar & 0xff;
+ ptr[12] = (frame->right_bar >> 8) & 0xff;
+
+ hdmi_infoframe_set_checksum(buffer, length);
+
+ return length;
+}
+EXPORT_SYMBOL(hdmi_avi_infoframe_pack_only);
+
+/**
+ * hdmi_avi_infoframe_pack() - check a HDMI AVI infoframe,
+ * and write it to binary buffer
+ * @frame: HDMI AVI infoframe
+ * @buffer: destination buffer
+ * @size: size of buffer
+ *
+ * Validates that the infoframe is consistent and updates derived fields
+ * (eg. length) based on other fields, after which it packs the information
+ * contained in the @frame structure into a binary representation that
+ * can be written into the corresponding controller registers. This function
+ * also computes the checksum as required by section 5.3.5 of the HDMI 1.4
+ * specification.
+ *
+ * Returns the number of bytes packed into the binary buffer or a negative
+ * error code on failure.
+ */
+ssize_t hdmi_avi_infoframe_pack(struct hdmi_avi_infoframe *frame,
+ void *buffer, size_t size)
+{
+ int ret;
+
+ ret = hdmi_avi_infoframe_check(frame);
+ if (ret)
+ return ret;
+
+ return hdmi_avi_infoframe_pack_only(frame, buffer, size);
+}
+EXPORT_SYMBOL(hdmi_avi_infoframe_pack);
+
+/**
+ * hdmi_spd_infoframe_init() - initialize an HDMI SPD infoframe
+ * @frame: HDMI SPD infoframe
+ * @vendor: vendor string
+ * @product: product string
+ *
+ * Returns 0 on success or a negative error code on failure.
+ */
+int hdmi_spd_infoframe_init(struct hdmi_spd_infoframe *frame,
+ const char *vendor, const char *product)
+{
+ size_t len;
+
+ memset(frame, 0, sizeof(*frame));
+
+ frame->type = HDMI_INFOFRAME_TYPE_SPD;
+ frame->version = 1;
+ frame->length = HDMI_SPD_INFOFRAME_SIZE;
+
+ len = strlen(vendor);
+ memcpy(frame->vendor, vendor, min(len, sizeof(frame->vendor)));
+ len = strlen(product);
+ memcpy(frame->product, product, min(len, sizeof(frame->product)));
+
+ return 0;
+}
+EXPORT_SYMBOL(hdmi_spd_infoframe_init);
+
+static int hdmi_spd_infoframe_check_only(const struct hdmi_spd_infoframe *frame)
+{
+ if (frame->type != HDMI_INFOFRAME_TYPE_SPD ||
+ frame->version != 1 ||
+ frame->length != HDMI_SPD_INFOFRAME_SIZE)
+ return -EINVAL;
+
+ return 0;
+}
+
+/**
+ * hdmi_spd_infoframe_check() - check a HDMI SPD infoframe
+ * @frame: HDMI SPD infoframe
+ *
+ * Validates that the infoframe is consistent and updates derived fields
+ * (eg. length) based on other fields.
+ *
+ * Returns 0 on success or a negative error code on failure.
+ */
+int hdmi_spd_infoframe_check(struct hdmi_spd_infoframe *frame)
+{
+ return hdmi_spd_infoframe_check_only(frame);
+}
+EXPORT_SYMBOL(hdmi_spd_infoframe_check);
+
+/**
+ * hdmi_spd_infoframe_pack_only() - write HDMI SPD infoframe to binary buffer
+ * @frame: HDMI SPD infoframe
+ * @buffer: destination buffer
+ * @size: size of buffer
+ *
+ * Packs the information contained in the @frame structure into a binary
+ * representation that can be written into the corresponding controller
+ * registers. Also computes the checksum as required by section 5.3.5 of
+ * the HDMI 1.4 specification.
+ *
+ * Returns the number of bytes packed into the binary buffer or a negative
+ * error code on failure.
+ */
+ssize_t hdmi_spd_infoframe_pack_only(const struct hdmi_spd_infoframe *frame,
+ void *buffer, size_t size)
+{
+ u8 *ptr = buffer;
+ size_t length;
+ int ret;
+
+ ret = hdmi_spd_infoframe_check_only(frame);
+ if (ret)
+ return ret;
+
+ length = HDMI_INFOFRAME_HEADER_SIZE + frame->length;
+
+ if (size < length)
+ return -ENOSPC;
+
+ memset(buffer, 0, size);
+
+ ptr[0] = frame->type;
+ ptr[1] = frame->version;
+ ptr[2] = frame->length;
+ ptr[3] = 0; /* checksum */
+
+ /* start infoframe payload */
+ ptr += HDMI_INFOFRAME_HEADER_SIZE;
+
+ memcpy(ptr, frame->vendor, sizeof(frame->vendor));
+ memcpy(ptr + 8, frame->product, sizeof(frame->product));
+
+ ptr[24] = frame->sdi;
+
+ hdmi_infoframe_set_checksum(buffer, length);
+
+ return length;
+}
+EXPORT_SYMBOL(hdmi_spd_infoframe_pack_only);
+
+/**
+ * hdmi_spd_infoframe_pack() - check a HDMI SPD infoframe,
+ * and write it to binary buffer
+ * @frame: HDMI SPD infoframe
+ * @buffer: destination buffer
+ * @size: size of buffer
+ *
+ * Validates that the infoframe is consistent and updates derived fields
+ * (eg. length) based on other fields, after which it packs the information
+ * contained in the @frame structure into a binary representation that
+ * can be written into the corresponding controller registers. This function
+ * also computes the checksum as required by section 5.3.5 of the HDMI 1.4
+ * specification.
+ *
+ * Returns the number of bytes packed into the binary buffer or a negative
+ * error code on failure.
+ */
+ssize_t hdmi_spd_infoframe_pack(struct hdmi_spd_infoframe *frame,
+ void *buffer, size_t size)
+{
+ int ret;
+
+ ret = hdmi_spd_infoframe_check(frame);
+ if (ret)
+ return ret;
+
+ return hdmi_spd_infoframe_pack_only(frame, buffer, size);
+}
+EXPORT_SYMBOL(hdmi_spd_infoframe_pack);
+
+/**
+ * hdmi_audio_infoframe_init() - initialize an HDMI audio infoframe
+ * @frame: HDMI audio infoframe
+ *
+ * Returns 0 on success or a negative error code on failure.
+ */
+int hdmi_audio_infoframe_init(struct hdmi_audio_infoframe *frame)
+{
+ memset(frame, 0, sizeof(*frame));
+
+ frame->type = HDMI_INFOFRAME_TYPE_AUDIO;
+ frame->version = 1;
+ frame->length = HDMI_AUDIO_INFOFRAME_SIZE;
+
+ return 0;
+}
+EXPORT_SYMBOL(hdmi_audio_infoframe_init);
+
+static int hdmi_audio_infoframe_check_only(const struct hdmi_audio_infoframe *frame)
+{
+ if (frame->type != HDMI_INFOFRAME_TYPE_AUDIO ||
+ frame->version != 1 ||
+ frame->length != HDMI_AUDIO_INFOFRAME_SIZE)
+ return -EINVAL;
+
+ return 0;
+}
+
+/**
+ * hdmi_audio_infoframe_check() - check a HDMI audio infoframe
+ * @frame: HDMI audio infoframe
+ *
+ * Validates that the infoframe is consistent and updates derived fields
+ * (eg. length) based on other fields.
+ *
+ * Returns 0 on success or a negative error code on failure.
+ */
+int hdmi_audio_infoframe_check(const struct hdmi_audio_infoframe *frame)
+{
+ return hdmi_audio_infoframe_check_only(frame);
+}
+EXPORT_SYMBOL(hdmi_audio_infoframe_check);
+
+static void
+hdmi_audio_infoframe_pack_payload(const struct hdmi_audio_infoframe *frame,
+ u8 *buffer)
+{
+ u8 channels;
+
+ if (frame->channels >= 2)
+ channels = frame->channels - 1;
+ else
+ channels = 0;
+
+ buffer[0] = ((frame->coding_type & 0xf) << 4) | (channels & 0x7);
+ buffer[1] = ((frame->sample_frequency & 0x7) << 2) |
+ (frame->sample_size & 0x3);
+ buffer[2] = frame->coding_type_ext & 0x1f;
+ buffer[3] = frame->channel_allocation;
+ buffer[4] = (frame->level_shift_value & 0xf) << 3;
+
+ if (frame->downmix_inhibit)
+ buffer[4] |= BIT(7);
+}
+
+/**
+ * hdmi_audio_infoframe_pack_only() - write HDMI audio infoframe to binary buffer
+ * @frame: HDMI audio infoframe
+ * @buffer: destination buffer
+ * @size: size of buffer
+ *
+ * Packs the information contained in the @frame structure into a binary
+ * representation that can be written into the corresponding controller
+ * registers. Also computes the checksum as required by section 5.3.5 of
+ * the HDMI 1.4 specification.
+ *
+ * Returns the number of bytes packed into the binary buffer or a negative
+ * error code on failure.
+ */
+ssize_t hdmi_audio_infoframe_pack_only(const struct hdmi_audio_infoframe *frame,
+ void *buffer, size_t size)
+{
+ u8 *ptr = buffer;
+ size_t length;
+ int ret;
+
+ ret = hdmi_audio_infoframe_check_only(frame);
+ if (ret)
+ return ret;
+
+ length = HDMI_INFOFRAME_HEADER_SIZE + frame->length;
+
+ if (size < length)
+ return -ENOSPC;
+
+ memset(buffer, 0, size);
+
+ ptr[0] = frame->type;
+ ptr[1] = frame->version;
+ ptr[2] = frame->length;
+ ptr[3] = 0; /* checksum */
+
+ hdmi_audio_infoframe_pack_payload(frame,
+ ptr + HDMI_INFOFRAME_HEADER_SIZE);
+
+ hdmi_infoframe_set_checksum(buffer, length);
+
+ return length;
+}
+EXPORT_SYMBOL(hdmi_audio_infoframe_pack_only);
+
+/**
+ * hdmi_audio_infoframe_pack() - check a HDMI Audio infoframe,
+ * and write it to binary buffer
+ * @frame: HDMI Audio infoframe
+ * @buffer: destination buffer
+ * @size: size of buffer
+ *
+ * Validates that the infoframe is consistent and updates derived fields
+ * (eg. length) based on other fields, after which it packs the information
+ * contained in the @frame structure into a binary representation that
+ * can be written into the corresponding controller registers. This function
+ * also computes the checksum as required by section 5.3.5 of the HDMI 1.4
+ * specification.
+ *
+ * Returns the number of bytes packed into the binary buffer or a negative
+ * error code on failure.
+ */
+ssize_t hdmi_audio_infoframe_pack(struct hdmi_audio_infoframe *frame,
+ void *buffer, size_t size)
+{
+ int ret;
+
+ ret = hdmi_audio_infoframe_check(frame);
+ if (ret)
+ return ret;
+
+ return hdmi_audio_infoframe_pack_only(frame, buffer, size);
+}
+EXPORT_SYMBOL(hdmi_audio_infoframe_pack);
+
+#ifdef __linux__
+/**
+ * hdmi_audio_infoframe_pack_for_dp - Pack a HDMI Audio infoframe for DisplayPort
+ *
+ * @frame: HDMI Audio infoframe
+ * @sdp: Secondary data packet for DisplayPort.
+ * @dp_version: DisplayPort version to be encoded in the header
+ *
+ * Packs a HDMI Audio Infoframe to be sent over DisplayPort. This function
+ * fills the secondary data packet to be used for DisplayPort.
+ *
+ * Return: Number of total written bytes or a negative errno on failure.
+ */
+ssize_t
+hdmi_audio_infoframe_pack_for_dp(const struct hdmi_audio_infoframe *frame,
+ struct dp_sdp *sdp, u8 dp_version)
+{
+ int ret;
+
+ ret = hdmi_audio_infoframe_check(frame);
+ if (ret)
+ return ret;
+
+ memset(sdp->db, 0, sizeof(sdp->db));
+
+ /* Secondary-data packet header */
+ sdp->sdp_header.HB0 = 0;
+ sdp->sdp_header.HB1 = frame->type;
+ sdp->sdp_header.HB2 = DP_SDP_AUDIO_INFOFRAME_HB2;
+ sdp->sdp_header.HB3 = (dp_version & 0x3f) << 2;
+
+ hdmi_audio_infoframe_pack_payload(frame, sdp->db);
+
+ /* Return size = frame length + four HB for sdp_header */
+ return frame->length + 4;
+}
+EXPORT_SYMBOL(hdmi_audio_infoframe_pack_for_dp);
+#endif
+
+/**
+ * hdmi_vendor_infoframe_init() - initialize an HDMI vendor infoframe
+ * @frame: HDMI vendor infoframe
+ *
+ * Returns 0 on success or a negative error code on failure.
+ */
+int hdmi_vendor_infoframe_init(struct hdmi_vendor_infoframe *frame)
+{
+ memset(frame, 0, sizeof(*frame));
+
+ frame->type = HDMI_INFOFRAME_TYPE_VENDOR;
+ frame->version = 1;
+
+ frame->oui = HDMI_IEEE_OUI;
+
+ /*
+ * 0 is a valid value for s3d_struct, so we use a special "not set"
+ * value
+ */
+ frame->s3d_struct = HDMI_3D_STRUCTURE_INVALID;
+ frame->length = HDMI_VENDOR_INFOFRAME_SIZE;
+
+ return 0;
+}
+EXPORT_SYMBOL(hdmi_vendor_infoframe_init);
+
+static int hdmi_vendor_infoframe_length(const struct hdmi_vendor_infoframe *frame)
+{
+ /* for side by side (half) we also need to provide 3D_Ext_Data */
+ if (frame->s3d_struct >= HDMI_3D_STRUCTURE_SIDE_BY_SIDE_HALF)
+ return 6;
+ else if (frame->vic != 0 || frame->s3d_struct != HDMI_3D_STRUCTURE_INVALID)
+ return 5;
+ else
+ return 4;
+}
+
+static int hdmi_vendor_infoframe_check_only(const struct hdmi_vendor_infoframe *frame)
+{
+ if (frame->type != HDMI_INFOFRAME_TYPE_VENDOR ||
+ frame->version != 1 ||
+ frame->oui != HDMI_IEEE_OUI)
+ return -EINVAL;
+
+ /* only one of those can be supplied */
+ if (frame->vic != 0 && frame->s3d_struct != HDMI_3D_STRUCTURE_INVALID)
+ return -EINVAL;
+
+ if (frame->length != hdmi_vendor_infoframe_length(frame))
+ return -EINVAL;
+
+ return 0;
+}
+
+/**
+ * hdmi_vendor_infoframe_check() - check a HDMI vendor infoframe
+ * @frame: HDMI infoframe
+ *
+ * Validates that the infoframe is consistent and updates derived fields
+ * (eg. length) based on other fields.
+ *
+ * Returns 0 on success or a negative error code on failure.
+ */
+int hdmi_vendor_infoframe_check(struct hdmi_vendor_infoframe *frame)
+{
+ frame->length = hdmi_vendor_infoframe_length(frame);
+
+ return hdmi_vendor_infoframe_check_only(frame);
+}
+EXPORT_SYMBOL(hdmi_vendor_infoframe_check);
+
+/**
+ * hdmi_vendor_infoframe_pack_only() - write a HDMI vendor infoframe to binary buffer
+ * @frame: HDMI infoframe
+ * @buffer: destination buffer
+ * @size: size of buffer
+ *
+ * Packs the information contained in the @frame structure into a binary
+ * representation that can be written into the corresponding controller
+ * registers. Also computes the checksum as required by section 5.3.5 of
+ * the HDMI 1.4 specification.
+ *
+ * Returns the number of bytes packed into the binary buffer or a negative
+ * error code on failure.
+ */
+ssize_t hdmi_vendor_infoframe_pack_only(const struct hdmi_vendor_infoframe *frame,
+ void *buffer, size_t size)
+{
+ u8 *ptr = buffer;
+ size_t length;
+ int ret;
+
+ ret = hdmi_vendor_infoframe_check_only(frame);
+ if (ret)
+ return ret;
+
+ length = HDMI_INFOFRAME_HEADER_SIZE + frame->length;
+
+ if (size < length)
+ return -ENOSPC;
+
+ memset(buffer, 0, size);
+
+ ptr[0] = frame->type;
+ ptr[1] = frame->version;
+ ptr[2] = frame->length;
+ ptr[3] = 0; /* checksum */
+
+ /* HDMI OUI */
+ ptr[4] = 0x03;
+ ptr[5] = 0x0c;
+ ptr[6] = 0x00;
+
+ if (frame->s3d_struct != HDMI_3D_STRUCTURE_INVALID) {
+ ptr[7] = 0x2 << 5; /* video format */
+ ptr[8] = (frame->s3d_struct & 0xf) << 4;
+ if (frame->s3d_struct >= HDMI_3D_STRUCTURE_SIDE_BY_SIDE_HALF)
+ ptr[9] = (frame->s3d_ext_data & 0xf) << 4;
+ } else if (frame->vic) {
+ ptr[7] = 0x1 << 5; /* video format */
+ ptr[8] = frame->vic;
+ } else {
+ ptr[7] = 0x0 << 5; /* video format */
+ }
+
+ hdmi_infoframe_set_checksum(buffer, length);
+
+ return length;
+}
+EXPORT_SYMBOL(hdmi_vendor_infoframe_pack_only);
+
+/**
+ * hdmi_vendor_infoframe_pack() - check a HDMI Vendor infoframe,
+ * and write it to binary buffer
+ * @frame: HDMI Vendor infoframe
+ * @buffer: destination buffer
+ * @size: size of buffer
+ *
+ * Validates that the infoframe is consistent and updates derived fields
+ * (eg. length) based on other fields, after which it packs the information
+ * contained in the @frame structure into a binary representation that
+ * can be written into the corresponding controller registers. This function
+ * also computes the checksum as required by section 5.3.5 of the HDMI 1.4
+ * specification.
+ *
+ * Returns the number of bytes packed into the binary buffer or a negative
+ * error code on failure.
+ */
+ssize_t hdmi_vendor_infoframe_pack(struct hdmi_vendor_infoframe *frame,
+ void *buffer, size_t size)
+{
+ int ret;
+
+ ret = hdmi_vendor_infoframe_check(frame);
+ if (ret)
+ return ret;
+
+ return hdmi_vendor_infoframe_pack_only(frame, buffer, size);
+}
+EXPORT_SYMBOL(hdmi_vendor_infoframe_pack);
+
+static int
+hdmi_vendor_any_infoframe_check_only(const union hdmi_vendor_any_infoframe *frame)
+{
+ if (frame->any.type != HDMI_INFOFRAME_TYPE_VENDOR ||
+ frame->any.version != 1)
+ return -EINVAL;
+
+ return 0;
+}
+
+/**
+ * hdmi_drm_infoframe_init() - initialize an HDMI Dynaminc Range and
+ * mastering infoframe
+ * @frame: HDMI DRM infoframe
+ *
+ * Returns 0 on success or a negative error code on failure.
+ */
+int hdmi_drm_infoframe_init(struct hdmi_drm_infoframe *frame)
+{
+ memset(frame, 0, sizeof(*frame));
+
+ frame->type = HDMI_INFOFRAME_TYPE_DRM;
+ frame->version = 1;
+ frame->length = HDMI_DRM_INFOFRAME_SIZE;
+
+ return 0;
+}
+EXPORT_SYMBOL(hdmi_drm_infoframe_init);
+
+static int hdmi_drm_infoframe_check_only(const struct hdmi_drm_infoframe *frame)
+{
+ if (frame->type != HDMI_INFOFRAME_TYPE_DRM ||
+ frame->version != 1)
+ return -EINVAL;
+
+ if (frame->length != HDMI_DRM_INFOFRAME_SIZE)
+ return -EINVAL;
+
+ return 0;
+}
+
+/**
+ * hdmi_drm_infoframe_check() - check a HDMI DRM infoframe
+ * @frame: HDMI DRM infoframe
+ *
+ * Validates that the infoframe is consistent.
+ * Returns 0 on success or a negative error code on failure.
+ */
+int hdmi_drm_infoframe_check(struct hdmi_drm_infoframe *frame)
+{
+ return hdmi_drm_infoframe_check_only(frame);
+}
+EXPORT_SYMBOL(hdmi_drm_infoframe_check);
+
+/**
+ * hdmi_drm_infoframe_pack_only() - write HDMI DRM infoframe to binary buffer
+ * @frame: HDMI DRM infoframe
+ * @buffer: destination buffer
+ * @size: size of buffer
+ *
+ * Packs the information contained in the @frame structure into a binary
+ * representation that can be written into the corresponding controller
+ * registers. Also computes the checksum as required by section 5.3.5 of
+ * the HDMI 1.4 specification.
+ *
+ * Returns the number of bytes packed into the binary buffer or a negative
+ * error code on failure.
+ */
+ssize_t hdmi_drm_infoframe_pack_only(const struct hdmi_drm_infoframe *frame,
+ void *buffer, size_t size)
+{
+ u8 *ptr = buffer;
+ size_t length;
+ int i;
+
+ length = HDMI_INFOFRAME_HEADER_SIZE + frame->length;
+
+ if (size < length)
+ return -ENOSPC;
+
+ memset(buffer, 0, size);
+
+ ptr[0] = frame->type;
+ ptr[1] = frame->version;
+ ptr[2] = frame->length;
+ ptr[3] = 0; /* checksum */
+
+ /* start infoframe payload */
+ ptr += HDMI_INFOFRAME_HEADER_SIZE;
+
+ *ptr++ = frame->eotf;
+ *ptr++ = frame->metadata_type;
+
+ for (i = 0; i < 3; i++) {
+ *ptr++ = frame->display_primaries[i].x;
+ *ptr++ = frame->display_primaries[i].x >> 8;
+ *ptr++ = frame->display_primaries[i].y;
+ *ptr++ = frame->display_primaries[i].y >> 8;
+ }
+
+ *ptr++ = frame->white_point.x;
+ *ptr++ = frame->white_point.x >> 8;
+
+ *ptr++ = frame->white_point.y;
+ *ptr++ = frame->white_point.y >> 8;
+
+ *ptr++ = frame->max_display_mastering_luminance;
+ *ptr++ = frame->max_display_mastering_luminance >> 8;
+
+ *ptr++ = frame->min_display_mastering_luminance;
+ *ptr++ = frame->min_display_mastering_luminance >> 8;
+
+ *ptr++ = frame->max_cll;
+ *ptr++ = frame->max_cll >> 8;
+
+ *ptr++ = frame->max_fall;
+ *ptr++ = frame->max_fall >> 8;
+
+ hdmi_infoframe_set_checksum(buffer, length);
+
+ return length;
+}
+EXPORT_SYMBOL(hdmi_drm_infoframe_pack_only);
+
+/**
+ * hdmi_drm_infoframe_pack() - check a HDMI DRM infoframe,
+ * and write it to binary buffer
+ * @frame: HDMI DRM infoframe
+ * @buffer: destination buffer
+ * @size: size of buffer
+ *
+ * Validates that the infoframe is consistent and updates derived fields
+ * (eg. length) based on other fields, after which it packs the information
+ * contained in the @frame structure into a binary representation that
+ * can be written into the corresponding controller registers. This function
+ * also computes the checksum as required by section 5.3.5 of the HDMI 1.4
+ * specification.
+ *
+ * Returns the number of bytes packed into the binary buffer or a negative
+ * error code on failure.
+ */
+ssize_t hdmi_drm_infoframe_pack(struct hdmi_drm_infoframe *frame,
+ void *buffer, size_t size)
+{
+ int ret;
+
+ ret = hdmi_drm_infoframe_check(frame);
+ if (ret)
+ return ret;
+
+ return hdmi_drm_infoframe_pack_only(frame, buffer, size);
+}
+EXPORT_SYMBOL(hdmi_drm_infoframe_pack);
+
+/*
+ * hdmi_vendor_any_infoframe_check() - check a vendor infoframe
+ */
+static int
+hdmi_vendor_any_infoframe_check(union hdmi_vendor_any_infoframe *frame)
+{
+ int ret;
+
+ ret = hdmi_vendor_any_infoframe_check_only(frame);
+ if (ret)
+ return ret;
+
+ /* we only know about HDMI vendor infoframes */
+ if (frame->any.oui != HDMI_IEEE_OUI)
+ return -EINVAL;
+
+ return hdmi_vendor_infoframe_check(&frame->hdmi);
+}
+
+/*
+ * hdmi_vendor_any_infoframe_pack_only() - write a vendor infoframe to binary buffer
+ */
+static ssize_t
+hdmi_vendor_any_infoframe_pack_only(const union hdmi_vendor_any_infoframe *frame,
+ void *buffer, size_t size)
+{
+ int ret;
+
+ ret = hdmi_vendor_any_infoframe_check_only(frame);
+ if (ret)
+ return ret;
+
+ /* we only know about HDMI vendor infoframes */
+ if (frame->any.oui != HDMI_IEEE_OUI)
+ return -EINVAL;
+
+ return hdmi_vendor_infoframe_pack_only(&frame->hdmi, buffer, size);
+}
+
+/*
+ * hdmi_vendor_any_infoframe_pack() - check a vendor infoframe,
+ * and write it to binary buffer
+ */
+static ssize_t
+hdmi_vendor_any_infoframe_pack(union hdmi_vendor_any_infoframe *frame,
+ void *buffer, size_t size)
+{
+ int ret;
+
+ ret = hdmi_vendor_any_infoframe_check(frame);
+ if (ret)
+ return ret;
+
+ return hdmi_vendor_any_infoframe_pack_only(frame, buffer, size);
+}
+
+/**
+ * hdmi_infoframe_check() - check a HDMI infoframe
+ * @frame: HDMI infoframe
+ *
+ * Validates that the infoframe is consistent and updates derived fields
+ * (eg. length) based on other fields.
+ *
+ * Returns 0 on success or a negative error code on failure.
+ */
+int
+hdmi_infoframe_check(union hdmi_infoframe *frame)
+{
+ switch (frame->any.type) {
+ case HDMI_INFOFRAME_TYPE_AVI:
+ return hdmi_avi_infoframe_check(&frame->avi);
+ case HDMI_INFOFRAME_TYPE_SPD:
+ return hdmi_spd_infoframe_check(&frame->spd);
+ case HDMI_INFOFRAME_TYPE_AUDIO:
+ return hdmi_audio_infoframe_check(&frame->audio);
+ case HDMI_INFOFRAME_TYPE_VENDOR:
+ return hdmi_vendor_any_infoframe_check(&frame->vendor);
+ default:
+ WARN(1, "Bad infoframe type %d\n", frame->any.type);
+ return -EINVAL;
+ }
+}
+EXPORT_SYMBOL(hdmi_infoframe_check);
+
+/**
+ * hdmi_infoframe_pack_only() - write a HDMI infoframe to binary buffer
+ * @frame: HDMI infoframe
+ * @buffer: destination buffer
+ * @size: size of buffer
+ *
+ * Packs the information contained in the @frame structure into a binary
+ * representation that can be written into the corresponding controller
+ * registers. Also computes the checksum as required by section 5.3.5 of
+ * the HDMI 1.4 specification.
+ *
+ * Returns the number of bytes packed into the binary buffer or a negative
+ * error code on failure.
+ */
+ssize_t
+hdmi_infoframe_pack_only(const union hdmi_infoframe *frame, void *buffer, size_t size)
+{
+ ssize_t length;
+
+ switch (frame->any.type) {
+ case HDMI_INFOFRAME_TYPE_AVI:
+ length = hdmi_avi_infoframe_pack_only(&frame->avi,
+ buffer, size);
+ break;
+ case HDMI_INFOFRAME_TYPE_DRM:
+ length = hdmi_drm_infoframe_pack_only(&frame->drm,
+ buffer, size);
+ break;
+ case HDMI_INFOFRAME_TYPE_SPD:
+ length = hdmi_spd_infoframe_pack_only(&frame->spd,
+ buffer, size);
+ break;
+ case HDMI_INFOFRAME_TYPE_AUDIO:
+ length = hdmi_audio_infoframe_pack_only(&frame->audio,
+ buffer, size);
+ break;
+ case HDMI_INFOFRAME_TYPE_VENDOR:
+ length = hdmi_vendor_any_infoframe_pack_only(&frame->vendor,
+ buffer, size);
+ break;
+ default:
+ WARN(1, "Bad infoframe type %d\n", frame->any.type);
+ length = -EINVAL;
+ }
+
+ return length;
+}
+EXPORT_SYMBOL(hdmi_infoframe_pack_only);
+
+/**
+ * hdmi_infoframe_pack() - check a HDMI infoframe,
+ * and write it to binary buffer
+ * @frame: HDMI infoframe
+ * @buffer: destination buffer
+ * @size: size of buffer
+ *
+ * Validates that the infoframe is consistent and updates derived fields
+ * (eg. length) based on other fields, after which it packs the information
+ * contained in the @frame structure into a binary representation that
+ * can be written into the corresponding controller registers. This function
+ * also computes the checksum as required by section 5.3.5 of the HDMI 1.4
+ * specification.
+ *
+ * Returns the number of bytes packed into the binary buffer or a negative
+ * error code on failure.
+ */
+ssize_t
+hdmi_infoframe_pack(union hdmi_infoframe *frame,
+ void *buffer, size_t size)
+{
+ ssize_t length;
+
+ switch (frame->any.type) {
+ case HDMI_INFOFRAME_TYPE_AVI:
+ length = hdmi_avi_infoframe_pack(&frame->avi, buffer, size);
+ break;
+ case HDMI_INFOFRAME_TYPE_DRM:
+ length = hdmi_drm_infoframe_pack(&frame->drm, buffer, size);
+ break;
+ case HDMI_INFOFRAME_TYPE_SPD:
+ length = hdmi_spd_infoframe_pack(&frame->spd, buffer, size);
+ break;
+ case HDMI_INFOFRAME_TYPE_AUDIO:
+ length = hdmi_audio_infoframe_pack(&frame->audio, buffer, size);
+ break;
+ case HDMI_INFOFRAME_TYPE_VENDOR:
+ length = hdmi_vendor_any_infoframe_pack(&frame->vendor,
+ buffer, size);
+ break;
+ default:
+ WARN(1, "Bad infoframe type %d\n", frame->any.type);
+ length = -EINVAL;
+ }
+
+ return length;
+}
+EXPORT_SYMBOL(hdmi_infoframe_pack);
+
+static const char *hdmi_infoframe_type_get_name(enum hdmi_infoframe_type type)
+{
+ if (type < 0x80 || type > 0x9f)
+ return "Invalid";
+ switch (type) {
+ case HDMI_INFOFRAME_TYPE_VENDOR:
+ return "Vendor";
+ case HDMI_INFOFRAME_TYPE_AVI:
+ return "Auxiliary Video Information (AVI)";
+ case HDMI_INFOFRAME_TYPE_SPD:
+ return "Source Product Description (SPD)";
+ case HDMI_INFOFRAME_TYPE_AUDIO:
+ return "Audio";
+ case HDMI_INFOFRAME_TYPE_DRM:
+ return "Dynamic Range and Mastering";
+ }
+ return "Reserved";
+}
+
+static void hdmi_infoframe_log_header(const char *level,
+ struct device *dev,
+ const struct hdmi_any_infoframe *frame)
+{
+ hdmi_log("HDMI infoframe: %s, version %u, length %u\n",
+ hdmi_infoframe_type_get_name(frame->type),
+ frame->version, frame->length);
+}
+
+static const char *hdmi_colorspace_get_name(enum hdmi_colorspace colorspace)
+{
+ switch (colorspace) {
+ case HDMI_COLORSPACE_RGB:
+ return "RGB";
+ case HDMI_COLORSPACE_YUV422:
+ return "YCbCr 4:2:2";
+ case HDMI_COLORSPACE_YUV444:
+ return "YCbCr 4:4:4";
+ case HDMI_COLORSPACE_YUV420:
+ return "YCbCr 4:2:0";
+ case HDMI_COLORSPACE_RESERVED4:
+ return "Reserved (4)";
+ case HDMI_COLORSPACE_RESERVED5:
+ return "Reserved (5)";
+ case HDMI_COLORSPACE_RESERVED6:
+ return "Reserved (6)";
+ case HDMI_COLORSPACE_IDO_DEFINED:
+ return "IDO Defined";
+ }
+ return "Invalid";
+}
+
+static const char *hdmi_scan_mode_get_name(enum hdmi_scan_mode scan_mode)
+{
+ switch (scan_mode) {
+ case HDMI_SCAN_MODE_NONE:
+ return "No Data";
+ case HDMI_SCAN_MODE_OVERSCAN:
+ return "Overscan";
+ case HDMI_SCAN_MODE_UNDERSCAN:
+ return "Underscan";
+ case HDMI_SCAN_MODE_RESERVED:
+ return "Reserved";
+ }
+ return "Invalid";
+}
+
+static const char *hdmi_colorimetry_get_name(enum hdmi_colorimetry colorimetry)
+{
+ switch (colorimetry) {
+ case HDMI_COLORIMETRY_NONE:
+ return "No Data";
+ case HDMI_COLORIMETRY_ITU_601:
+ return "ITU601";
+ case HDMI_COLORIMETRY_ITU_709:
+ return "ITU709";
+ case HDMI_COLORIMETRY_EXTENDED:
+ return "Extended";
+ }
+ return "Invalid";
+}
+
+static const char *
+hdmi_picture_aspect_get_name(enum hdmi_picture_aspect picture_aspect)
+{
+ switch (picture_aspect) {
+ case HDMI_PICTURE_ASPECT_NONE:
+ return "No Data";
+ case HDMI_PICTURE_ASPECT_4_3:
+ return "4:3";
+ case HDMI_PICTURE_ASPECT_16_9:
+ return "16:9";
+ case HDMI_PICTURE_ASPECT_64_27:
+ return "64:27";
+ case HDMI_PICTURE_ASPECT_256_135:
+ return "256:135";
+ case HDMI_PICTURE_ASPECT_RESERVED:
+ return "Reserved";
+ }
+ return "Invalid";
+}
+
+static const char *
+hdmi_active_aspect_get_name(enum hdmi_active_aspect active_aspect)
+{
+ if (active_aspect < 0 || active_aspect > 0xf)
+ return "Invalid";
+
+ switch (active_aspect) {
+ case HDMI_ACTIVE_ASPECT_16_9_TOP:
+ return "16:9 Top";
+ case HDMI_ACTIVE_ASPECT_14_9_TOP:
+ return "14:9 Top";
+ case HDMI_ACTIVE_ASPECT_16_9_CENTER:
+ return "16:9 Center";
+ case HDMI_ACTIVE_ASPECT_PICTURE:
+ return "Same as Picture";
+ case HDMI_ACTIVE_ASPECT_4_3:
+ return "4:3";
+ case HDMI_ACTIVE_ASPECT_16_9:
+ return "16:9";
+ case HDMI_ACTIVE_ASPECT_14_9:
+ return "14:9";
+ case HDMI_ACTIVE_ASPECT_4_3_SP_14_9:
+ return "4:3 SP 14:9";
+ case HDMI_ACTIVE_ASPECT_16_9_SP_14_9:
+ return "16:9 SP 14:9";
+ case HDMI_ACTIVE_ASPECT_16_9_SP_4_3:
+ return "16:9 SP 4:3";
+ }
+ return "Reserved";
+}
+
+static const char *
+hdmi_extended_colorimetry_get_name(enum hdmi_extended_colorimetry ext_col)
+{
+ switch (ext_col) {
+ case HDMI_EXTENDED_COLORIMETRY_XV_YCC_601:
+ return "xvYCC 601";
+ case HDMI_EXTENDED_COLORIMETRY_XV_YCC_709:
+ return "xvYCC 709";
+ case HDMI_EXTENDED_COLORIMETRY_S_YCC_601:
+ return "sYCC 601";
+ case HDMI_EXTENDED_COLORIMETRY_OPYCC_601:
+ return "opYCC 601";
+ case HDMI_EXTENDED_COLORIMETRY_OPRGB:
+ return "opRGB";
+ case HDMI_EXTENDED_COLORIMETRY_BT2020_CONST_LUM:
+ return "BT.2020 Constant Luminance";
+ case HDMI_EXTENDED_COLORIMETRY_BT2020:
+ return "BT.2020";
+ case HDMI_EXTENDED_COLORIMETRY_RESERVED:
+ return "Reserved";
+ }
+ return "Invalid";
+}
+
+static const char *
+hdmi_quantization_range_get_name(enum hdmi_quantization_range qrange)
+{
+ switch (qrange) {
+ case HDMI_QUANTIZATION_RANGE_DEFAULT:
+ return "Default";
+ case HDMI_QUANTIZATION_RANGE_LIMITED:
+ return "Limited";
+ case HDMI_QUANTIZATION_RANGE_FULL:
+ return "Full";
+ case HDMI_QUANTIZATION_RANGE_RESERVED:
+ return "Reserved";
+ }
+ return "Invalid";
+}
+
+static const char *hdmi_nups_get_name(enum hdmi_nups nups)
+{
+ switch (nups) {
+ case HDMI_NUPS_UNKNOWN:
+ return "Unknown Non-uniform Scaling";
+ case HDMI_NUPS_HORIZONTAL:
+ return "Horizontally Scaled";
+ case HDMI_NUPS_VERTICAL:
+ return "Vertically Scaled";
+ case HDMI_NUPS_BOTH:
+ return "Horizontally and Vertically Scaled";
+ }
+ return "Invalid";
+}
+
+static const char *
+hdmi_ycc_quantization_range_get_name(enum hdmi_ycc_quantization_range qrange)
+{
+ switch (qrange) {
+ case HDMI_YCC_QUANTIZATION_RANGE_LIMITED:
+ return "Limited";
+ case HDMI_YCC_QUANTIZATION_RANGE_FULL:
+ return "Full";
+ }
+ return "Invalid";
+}
+
+static const char *
+hdmi_content_type_get_name(enum hdmi_content_type content_type)
+{
+ switch (content_type) {
+ case HDMI_CONTENT_TYPE_GRAPHICS:
+ return "Graphics";
+ case HDMI_CONTENT_TYPE_PHOTO:
+ return "Photo";
+ case HDMI_CONTENT_TYPE_CINEMA:
+ return "Cinema";
+ case HDMI_CONTENT_TYPE_GAME:
+ return "Game";
+ }
+ return "Invalid";
+}
+
+static void hdmi_avi_infoframe_log(const char *level,
+ struct device *dev,
+ const struct hdmi_avi_infoframe *frame)
+{
+ hdmi_infoframe_log_header(level, dev,
+ (const struct hdmi_any_infoframe *)frame);
+
+ hdmi_log(" colorspace: %s\n",
+ hdmi_colorspace_get_name(frame->colorspace));
+ hdmi_log(" scan mode: %s\n",
+ hdmi_scan_mode_get_name(frame->scan_mode));
+ hdmi_log(" colorimetry: %s\n",
+ hdmi_colorimetry_get_name(frame->colorimetry));
+ hdmi_log(" picture aspect: %s\n",
+ hdmi_picture_aspect_get_name(frame->picture_aspect));
+ hdmi_log(" active aspect: %s\n",
+ hdmi_active_aspect_get_name(frame->active_aspect));
+ hdmi_log(" itc: %s\n", frame->itc ? "IT Content" : "No Data");
+ hdmi_log(" extended colorimetry: %s\n",
+ hdmi_extended_colorimetry_get_name(frame->extended_colorimetry));
+ hdmi_log(" quantization range: %s\n",
+ hdmi_quantization_range_get_name(frame->quantization_range));
+ hdmi_log(" nups: %s\n", hdmi_nups_get_name(frame->nups));
+ hdmi_log(" video code: %u\n", frame->video_code);
+ hdmi_log(" ycc quantization range: %s\n",
+ hdmi_ycc_quantization_range_get_name(frame->ycc_quantization_range));
+ hdmi_log(" hdmi content type: %s\n",
+ hdmi_content_type_get_name(frame->content_type));
+ hdmi_log(" pixel repeat: %u\n", frame->pixel_repeat);
+ hdmi_log(" bar top %u, bottom %u, left %u, right %u\n",
+ frame->top_bar, frame->bottom_bar,
+ frame->left_bar, frame->right_bar);
+}
+
+static const char *hdmi_spd_sdi_get_name(enum hdmi_spd_sdi sdi)
+{
+ if (sdi < 0 || sdi > 0xff)
+ return "Invalid";
+ switch (sdi) {
+ case HDMI_SPD_SDI_UNKNOWN:
+ return "Unknown";
+ case HDMI_SPD_SDI_DSTB:
+ return "Digital STB";
+ case HDMI_SPD_SDI_DVDP:
+ return "DVD Player";
+ case HDMI_SPD_SDI_DVHS:
+ return "D-VHS";
+ case HDMI_SPD_SDI_HDDVR:
+ return "HDD Videorecorder";
+ case HDMI_SPD_SDI_DVC:
+ return "DVC";
+ case HDMI_SPD_SDI_DSC:
+ return "DSC";
+ case HDMI_SPD_SDI_VCD:
+ return "Video CD";
+ case HDMI_SPD_SDI_GAME:
+ return "Game";
+ case HDMI_SPD_SDI_PC:
+ return "PC General";
+ case HDMI_SPD_SDI_BD:
+ return "Blu-Ray Disc (BD)";
+ case HDMI_SPD_SDI_SACD:
+ return "Super Audio CD";
+ case HDMI_SPD_SDI_HDDVD:
+ return "HD DVD";
+ case HDMI_SPD_SDI_PMP:
+ return "PMP";
+ }
+ return "Reserved";
+}
+
+static void hdmi_spd_infoframe_log(const char *level,
+ struct device *dev,
+ const struct hdmi_spd_infoframe *frame)
+{
+ u8 buf[17];
+
+ hdmi_infoframe_log_header(level, dev,
+ (const struct hdmi_any_infoframe *)frame);
+
+ memset(buf, 0, sizeof(buf));
+
+ strncpy(buf, frame->vendor, 8);
+ hdmi_log(" vendor: %s\n", buf);
+ strncpy(buf, frame->product, 16);
+ hdmi_log(" product: %s\n", buf);
+ hdmi_log(" source device information: %s (0x%x)\n",
+ hdmi_spd_sdi_get_name(frame->sdi), frame->sdi);
+}
+
+static const char *
+hdmi_audio_coding_type_get_name(enum hdmi_audio_coding_type coding_type)
+{
+ switch (coding_type) {
+ case HDMI_AUDIO_CODING_TYPE_STREAM:
+ return "Refer to Stream Header";
+ case HDMI_AUDIO_CODING_TYPE_PCM:
+ return "PCM";
+ case HDMI_AUDIO_CODING_TYPE_AC3:
+ return "AC-3";
+ case HDMI_AUDIO_CODING_TYPE_MPEG1:
+ return "MPEG1";
+ case HDMI_AUDIO_CODING_TYPE_MP3:
+ return "MP3";
+ case HDMI_AUDIO_CODING_TYPE_MPEG2:
+ return "MPEG2";
+ case HDMI_AUDIO_CODING_TYPE_AAC_LC:
+ return "AAC";
+ case HDMI_AUDIO_CODING_TYPE_DTS:
+ return "DTS";
+ case HDMI_AUDIO_CODING_TYPE_ATRAC:
+ return "ATRAC";
+ case HDMI_AUDIO_CODING_TYPE_DSD:
+ return "One Bit Audio";
+ case HDMI_AUDIO_CODING_TYPE_EAC3:
+ return "Dolby Digital +";
+ case HDMI_AUDIO_CODING_TYPE_DTS_HD:
+ return "DTS-HD";
+ case HDMI_AUDIO_CODING_TYPE_MLP:
+ return "MAT (MLP)";
+ case HDMI_AUDIO_CODING_TYPE_DST:
+ return "DST";
+ case HDMI_AUDIO_CODING_TYPE_WMA_PRO:
+ return "WMA PRO";
+ case HDMI_AUDIO_CODING_TYPE_CXT:
+ return "Refer to CXT";
+ }
+ return "Invalid";
+}
+
+static const char *
+hdmi_audio_sample_size_get_name(enum hdmi_audio_sample_size sample_size)
+{
+ switch (sample_size) {
+ case HDMI_AUDIO_SAMPLE_SIZE_STREAM:
+ return "Refer to Stream Header";
+ case HDMI_AUDIO_SAMPLE_SIZE_16:
+ return "16 bit";
+ case HDMI_AUDIO_SAMPLE_SIZE_20:
+ return "20 bit";
+ case HDMI_AUDIO_SAMPLE_SIZE_24:
+ return "24 bit";
+ }
+ return "Invalid";
+}
+
+static const char *
+hdmi_audio_sample_frequency_get_name(enum hdmi_audio_sample_frequency freq)
+{
+ switch (freq) {
+ case HDMI_AUDIO_SAMPLE_FREQUENCY_STREAM:
+ return "Refer to Stream Header";
+ case HDMI_AUDIO_SAMPLE_FREQUENCY_32000:
+ return "32 kHz";
+ case HDMI_AUDIO_SAMPLE_FREQUENCY_44100:
+ return "44.1 kHz (CD)";
+ case HDMI_AUDIO_SAMPLE_FREQUENCY_48000:
+ return "48 kHz";
+ case HDMI_AUDIO_SAMPLE_FREQUENCY_88200:
+ return "88.2 kHz";
+ case HDMI_AUDIO_SAMPLE_FREQUENCY_96000:
+ return "96 kHz";
+ case HDMI_AUDIO_SAMPLE_FREQUENCY_176400:
+ return "176.4 kHz";
+ case HDMI_AUDIO_SAMPLE_FREQUENCY_192000:
+ return "192 kHz";
+ }
+ return "Invalid";
+}
+
+static const char *
+hdmi_audio_coding_type_ext_get_name(enum hdmi_audio_coding_type_ext ctx)
+{
+ if (ctx < 0 || ctx > 0x1f)
+ return "Invalid";
+
+ switch (ctx) {
+ case HDMI_AUDIO_CODING_TYPE_EXT_CT:
+ return "Refer to CT";
+ case HDMI_AUDIO_CODING_TYPE_EXT_HE_AAC:
+ return "HE AAC";
+ case HDMI_AUDIO_CODING_TYPE_EXT_HE_AAC_V2:
+ return "HE AAC v2";
+ case HDMI_AUDIO_CODING_TYPE_EXT_MPEG_SURROUND:
+ return "MPEG SURROUND";
+ case HDMI_AUDIO_CODING_TYPE_EXT_MPEG4_HE_AAC:
+ return "MPEG-4 HE AAC";
+ case HDMI_AUDIO_CODING_TYPE_EXT_MPEG4_HE_AAC_V2:
+ return "MPEG-4 HE AAC v2";
+ case HDMI_AUDIO_CODING_TYPE_EXT_MPEG4_AAC_LC:
+ return "MPEG-4 AAC LC";
+ case HDMI_AUDIO_CODING_TYPE_EXT_DRA:
+ return "DRA";
+ case HDMI_AUDIO_CODING_TYPE_EXT_MPEG4_HE_AAC_SURROUND:
+ return "MPEG-4 HE AAC + MPEG Surround";
+ case HDMI_AUDIO_CODING_TYPE_EXT_MPEG4_AAC_LC_SURROUND:
+ return "MPEG-4 AAC LC + MPEG Surround";
+ }
+ return "Reserved";
+}
+
+static void hdmi_audio_infoframe_log(const char *level,
+ struct device *dev,
+ const struct hdmi_audio_infoframe *frame)
+{
+ hdmi_infoframe_log_header(level, dev,
+ (const struct hdmi_any_infoframe *)frame);
+
+ if (frame->channels)
+ hdmi_log(" channels: %u\n", frame->channels - 1);
+ else
+ hdmi_log(" channels: Refer to stream header\n");
+ hdmi_log(" coding type: %s\n",
+ hdmi_audio_coding_type_get_name(frame->coding_type));
+ hdmi_log(" sample size: %s\n",
+ hdmi_audio_sample_size_get_name(frame->sample_size));
+ hdmi_log(" sample frequency: %s\n",
+ hdmi_audio_sample_frequency_get_name(frame->sample_frequency));
+ hdmi_log(" coding type ext: %s\n",
+ hdmi_audio_coding_type_ext_get_name(frame->coding_type_ext));
+ hdmi_log(" channel allocation: 0x%x\n",
+ frame->channel_allocation);
+ hdmi_log(" level shift value: %u dB\n",
+ frame->level_shift_value);
+ hdmi_log(" downmix inhibit: %s\n",
+ frame->downmix_inhibit ? "Yes" : "No");
+}
+
+static void hdmi_drm_infoframe_log(const char *level,
+ struct device *dev,
+ const struct hdmi_drm_infoframe *frame)
+{
+ int i;
+
+ hdmi_infoframe_log_header(level, dev,
+ (struct hdmi_any_infoframe *)frame);
+ hdmi_log("length: %d\n", frame->length);
+ hdmi_log("metadata type: %d\n", frame->metadata_type);
+ hdmi_log("eotf: %d\n", frame->eotf);
+ for (i = 0; i < 3; i++) {
+ hdmi_log("x[%d]: %d\n", i, frame->display_primaries[i].x);
+ hdmi_log("y[%d]: %d\n", i, frame->display_primaries[i].y);
+ }
+
+ hdmi_log("white point x: %d\n", frame->white_point.x);
+ hdmi_log("white point y: %d\n", frame->white_point.y);
+
+ hdmi_log("max_display_mastering_luminance: %d\n",
+ frame->max_display_mastering_luminance);
+ hdmi_log("min_display_mastering_luminance: %d\n",
+ frame->min_display_mastering_luminance);
+
+ hdmi_log("max_cll: %d\n", frame->max_cll);
+ hdmi_log("max_fall: %d\n", frame->max_fall);
+}
+
+static const char *
+hdmi_3d_structure_get_name(enum hdmi_3d_structure s3d_struct)
+{
+ if (s3d_struct < 0 || s3d_struct > 0xf)
+ return "Invalid";
+
+ switch (s3d_struct) {
+ case HDMI_3D_STRUCTURE_FRAME_PACKING:
+ return "Frame Packing";
+ case HDMI_3D_STRUCTURE_FIELD_ALTERNATIVE:
+ return "Field Alternative";
+ case HDMI_3D_STRUCTURE_LINE_ALTERNATIVE:
+ return "Line Alternative";
+ case HDMI_3D_STRUCTURE_SIDE_BY_SIDE_FULL:
+ return "Side-by-side (Full)";
+ case HDMI_3D_STRUCTURE_L_DEPTH:
+ return "L + Depth";
+ case HDMI_3D_STRUCTURE_L_DEPTH_GFX_GFX_DEPTH:
+ return "L + Depth + Graphics + Graphics-depth";
+ case HDMI_3D_STRUCTURE_TOP_AND_BOTTOM:
+ return "Top-and-Bottom";
+ case HDMI_3D_STRUCTURE_SIDE_BY_SIDE_HALF:
+ return "Side-by-side (Half)";
+ default:
+ break;
+ }
+ return "Reserved";
+}
+
+static void
+hdmi_vendor_any_infoframe_log(const char *level,
+ struct device *dev,
+ const union hdmi_vendor_any_infoframe *frame)
+{
+ const struct hdmi_vendor_infoframe *hvf = &frame->hdmi;
+
+ hdmi_infoframe_log_header(level, dev,
+ (const struct hdmi_any_infoframe *)frame);
+
+ if (frame->any.oui != HDMI_IEEE_OUI) {
+ hdmi_log(" not a HDMI vendor infoframe\n");
+ return;
+ }
+ if (hvf->vic == 0 && hvf->s3d_struct == HDMI_3D_STRUCTURE_INVALID) {
+ hdmi_log(" empty frame\n");
+ return;
+ }
+
+ if (hvf->vic)
+ hdmi_log(" HDMI VIC: %u\n", hvf->vic);
+ if (hvf->s3d_struct != HDMI_3D_STRUCTURE_INVALID) {
+ hdmi_log(" 3D structure: %s\n",
+ hdmi_3d_structure_get_name(hvf->s3d_struct));
+ if (hvf->s3d_struct >= HDMI_3D_STRUCTURE_SIDE_BY_SIDE_HALF)
+ hdmi_log(" 3D extension data: %d\n",
+ hvf->s3d_ext_data);
+ }
+}
+
+/**
+ * hdmi_infoframe_log() - log info of HDMI infoframe
+ * @level: logging level
+ * @dev: device
+ * @frame: HDMI infoframe
+ */
+void hdmi_infoframe_log(const char *level,
+ struct device *dev,
+ const union hdmi_infoframe *frame)
+{
+ switch (frame->any.type) {
+ case HDMI_INFOFRAME_TYPE_AVI:
+ hdmi_avi_infoframe_log(level, dev, &frame->avi);
+ break;
+ case HDMI_INFOFRAME_TYPE_SPD:
+ hdmi_spd_infoframe_log(level, dev, &frame->spd);
+ break;
+ case HDMI_INFOFRAME_TYPE_AUDIO:
+ hdmi_audio_infoframe_log(level, dev, &frame->audio);
+ break;
+ case HDMI_INFOFRAME_TYPE_VENDOR:
+ hdmi_vendor_any_infoframe_log(level, dev, &frame->vendor);
+ break;
+ case HDMI_INFOFRAME_TYPE_DRM:
+ hdmi_drm_infoframe_log(level, dev, &frame->drm);
+ break;
+ }
+}
+EXPORT_SYMBOL(hdmi_infoframe_log);
+
+/**
+ * hdmi_avi_infoframe_unpack() - unpack binary buffer to a HDMI AVI infoframe
+ * @frame: HDMI AVI infoframe
+ * @buffer: source buffer
+ * @size: size of buffer
+ *
+ * Unpacks the information contained in binary @buffer into a structured
+ * @frame of the HDMI Auxiliary Video (AVI) information frame.
+ * Also verifies the checksum as required by section 5.3.5 of the HDMI 1.4
+ * specification.
+ *
+ * Returns 0 on success or a negative error code on failure.
+ */
+static int hdmi_avi_infoframe_unpack(struct hdmi_avi_infoframe *frame,
+ const void *buffer, size_t size)
+{
+ const u8 *ptr = buffer;
+
+ if (size < HDMI_INFOFRAME_SIZE(AVI))
+ return -EINVAL;
+
+ if (ptr[0] != HDMI_INFOFRAME_TYPE_AVI ||
+ ptr[1] != 2 ||
+ ptr[2] != HDMI_AVI_INFOFRAME_SIZE)
+ return -EINVAL;
+
+ if (hdmi_infoframe_checksum(buffer, HDMI_INFOFRAME_SIZE(AVI)) != 0)
+ return -EINVAL;
+
+ hdmi_avi_infoframe_init(frame);
+
+ ptr += HDMI_INFOFRAME_HEADER_SIZE;
+
+ frame->colorspace = (ptr[0] >> 5) & 0x3;
+ if (ptr[0] & 0x10)
+ frame->active_aspect = ptr[1] & 0xf;
+ if (ptr[0] & 0x8) {
+ frame->top_bar = (ptr[6] << 8) | ptr[5];
+ frame->bottom_bar = (ptr[8] << 8) | ptr[7];
+ }
+ if (ptr[0] & 0x4) {
+ frame->left_bar = (ptr[10] << 8) | ptr[9];
+ frame->right_bar = (ptr[12] << 8) | ptr[11];
+ }
+ frame->scan_mode = ptr[0] & 0x3;
+
+ frame->colorimetry = (ptr[1] >> 6) & 0x3;
+ frame->picture_aspect = (ptr[1] >> 4) & 0x3;
+ frame->active_aspect = ptr[1] & 0xf;
+
+ frame->itc = ptr[2] & 0x80 ? true : false;
+ frame->extended_colorimetry = (ptr[2] >> 4) & 0x7;
+ frame->quantization_range = (ptr[2] >> 2) & 0x3;
+ frame->nups = ptr[2] & 0x3;
+
+ frame->video_code = ptr[3] & 0x7f;
+ frame->ycc_quantization_range = (ptr[4] >> 6) & 0x3;
+ frame->content_type = (ptr[4] >> 4) & 0x3;
+
+ frame->pixel_repeat = ptr[4] & 0xf;
+
+ return 0;
+}
+
+/**
+ * hdmi_spd_infoframe_unpack() - unpack binary buffer to a HDMI SPD infoframe
+ * @frame: HDMI SPD infoframe
+ * @buffer: source buffer
+ * @size: size of buffer
+ *
+ * Unpacks the information contained in binary @buffer into a structured
+ * @frame of the HDMI Source Product Description (SPD) information frame.
+ * Also verifies the checksum as required by section 5.3.5 of the HDMI 1.4
+ * specification.
+ *
+ * Returns 0 on success or a negative error code on failure.
+ */
+static int hdmi_spd_infoframe_unpack(struct hdmi_spd_infoframe *frame,
+ const void *buffer, size_t size)
+{
+ const u8 *ptr = buffer;
+ int ret;
+
+ if (size < HDMI_INFOFRAME_SIZE(SPD))
+ return -EINVAL;
+
+ if (ptr[0] != HDMI_INFOFRAME_TYPE_SPD ||
+ ptr[1] != 1 ||
+ ptr[2] != HDMI_SPD_INFOFRAME_SIZE) {
+ return -EINVAL;
+ }
+
+ if (hdmi_infoframe_checksum(buffer, HDMI_INFOFRAME_SIZE(SPD)) != 0)
+ return -EINVAL;
+
+ ptr += HDMI_INFOFRAME_HEADER_SIZE;
+
+ ret = hdmi_spd_infoframe_init(frame, ptr, ptr + 8);
+ if (ret)
+ return ret;
+
+ frame->sdi = ptr[24];
+
+ return 0;
+}
+
+/**
+ * hdmi_audio_infoframe_unpack() - unpack binary buffer to a HDMI AUDIO infoframe
+ * @frame: HDMI Audio infoframe
+ * @buffer: source buffer
+ * @size: size of buffer
+ *
+ * Unpacks the information contained in binary @buffer into a structured
+ * @frame of the HDMI Audio information frame.
+ * Also verifies the checksum as required by section 5.3.5 of the HDMI 1.4
+ * specification.
+ *
+ * Returns 0 on success or a negative error code on failure.
+ */
+static int hdmi_audio_infoframe_unpack(struct hdmi_audio_infoframe *frame,
+ const void *buffer, size_t size)
+{
+ const u8 *ptr = buffer;
+ int ret;
+
+ if (size < HDMI_INFOFRAME_SIZE(AUDIO))
+ return -EINVAL;
+
+ if (ptr[0] != HDMI_INFOFRAME_TYPE_AUDIO ||
+ ptr[1] != 1 ||
+ ptr[2] != HDMI_AUDIO_INFOFRAME_SIZE) {
+ return -EINVAL;
+ }
+
+ if (hdmi_infoframe_checksum(buffer, HDMI_INFOFRAME_SIZE(AUDIO)) != 0)
+ return -EINVAL;
+
+ ret = hdmi_audio_infoframe_init(frame);
+ if (ret)
+ return ret;
+
+ ptr += HDMI_INFOFRAME_HEADER_SIZE;
+
+ frame->channels = ptr[0] & 0x7;
+ frame->coding_type = (ptr[0] >> 4) & 0xf;
+ frame->sample_size = ptr[1] & 0x3;
+ frame->sample_frequency = (ptr[1] >> 2) & 0x7;
+ frame->coding_type_ext = ptr[2] & 0x1f;
+ frame->channel_allocation = ptr[3];
+ frame->level_shift_value = (ptr[4] >> 3) & 0xf;
+ frame->downmix_inhibit = ptr[4] & 0x80 ? true : false;
+
+ return 0;
+}
+
+/**
+ * hdmi_vendor_any_infoframe_unpack() - unpack binary buffer to a HDMI
+ * vendor infoframe
+ * @frame: HDMI Vendor infoframe
+ * @buffer: source buffer
+ * @size: size of buffer
+ *
+ * Unpacks the information contained in binary @buffer into a structured
+ * @frame of the HDMI Vendor information frame.
+ * Also verifies the checksum as required by section 5.3.5 of the HDMI 1.4
+ * specification.
+ *
+ * Returns 0 on success or a negative error code on failure.
+ */
+static int
+hdmi_vendor_any_infoframe_unpack(union hdmi_vendor_any_infoframe *frame,
+ const void *buffer, size_t size)
+{
+ const u8 *ptr = buffer;
+ size_t length;
+ int ret;
+ u8 hdmi_video_format;
+ struct hdmi_vendor_infoframe *hvf = &frame->hdmi;
+
+ if (size < HDMI_INFOFRAME_HEADER_SIZE)
+ return -EINVAL;
+
+ if (ptr[0] != HDMI_INFOFRAME_TYPE_VENDOR ||
+ ptr[1] != 1 ||
+ (ptr[2] != 4 && ptr[2] != 5 && ptr[2] != 6))
+ return -EINVAL;
+
+ length = ptr[2];
+
+ if (size < HDMI_INFOFRAME_HEADER_SIZE + length)
+ return -EINVAL;
+
+ if (hdmi_infoframe_checksum(buffer,
+ HDMI_INFOFRAME_HEADER_SIZE + length) != 0)
+ return -EINVAL;
+
+ ptr += HDMI_INFOFRAME_HEADER_SIZE;
+
+ /* HDMI OUI */
+ if ((ptr[0] != 0x03) ||
+ (ptr[1] != 0x0c) ||
+ (ptr[2] != 0x00))
+ return -EINVAL;
+
+ hdmi_video_format = ptr[3] >> 5;
+
+ if (hdmi_video_format > 0x2)
+ return -EINVAL;
+
+ ret = hdmi_vendor_infoframe_init(hvf);
+ if (ret)
+ return ret;
+
+ hvf->length = length;
+
+ if (hdmi_video_format == 0x2) {
+ if (length != 5 && length != 6)
+ return -EINVAL;
+ hvf->s3d_struct = ptr[4] >> 4;
+ if (hvf->s3d_struct >= HDMI_3D_STRUCTURE_SIDE_BY_SIDE_HALF) {
+ if (length != 6)
+ return -EINVAL;
+ hvf->s3d_ext_data = ptr[5] >> 4;
+ }
+ } else if (hdmi_video_format == 0x1) {
+ if (length != 5)
+ return -EINVAL;
+ hvf->vic = ptr[4];
+ } else {
+ if (length != 4)
+ return -EINVAL;
+ }
+
+ return 0;
+}
+
+/**
+ * hdmi_drm_infoframe_unpack_only() - unpack binary buffer of CTA-861-G DRM
+ * infoframe DataBytes to a HDMI DRM
+ * infoframe
+ * @frame: HDMI DRM infoframe
+ * @buffer: source buffer
+ * @size: size of buffer
+ *
+ * Unpacks CTA-861-G DRM infoframe DataBytes contained in the binary @buffer
+ * into a structured @frame of the HDMI Dynamic Range and Mastering (DRM)
+ * infoframe.
+ *
+ * Returns 0 on success or a negative error code on failure.
+ */
+int hdmi_drm_infoframe_unpack_only(struct hdmi_drm_infoframe *frame,
+ const void *buffer, size_t size)
+{
+ const u8 *ptr = buffer;
+ const u8 *temp;
+ u8 x_lsb, x_msb;
+ u8 y_lsb, y_msb;
+ int ret;
+ int i;
+
+ if (size < HDMI_DRM_INFOFRAME_SIZE)
+ return -EINVAL;
+
+ ret = hdmi_drm_infoframe_init(frame);
+ if (ret)
+ return ret;
+
+ frame->eotf = ptr[0] & 0x7;
+ frame->metadata_type = ptr[1] & 0x7;
+
+ temp = ptr + 2;
+ for (i = 0; i < 3; i++) {
+ x_lsb = *temp++;
+ x_msb = *temp++;
+ frame->display_primaries[i].x = (x_msb << 8) | x_lsb;
+ y_lsb = *temp++;
+ y_msb = *temp++;
+ frame->display_primaries[i].y = (y_msb << 8) | y_lsb;
+ }
+
+ frame->white_point.x = (ptr[15] << 8) | ptr[14];
+ frame->white_point.y = (ptr[17] << 8) | ptr[16];
+
+ frame->max_display_mastering_luminance = (ptr[19] << 8) | ptr[18];
+ frame->min_display_mastering_luminance = (ptr[21] << 8) | ptr[20];
+ frame->max_cll = (ptr[23] << 8) | ptr[22];
+ frame->max_fall = (ptr[25] << 8) | ptr[24];
+
+ return 0;
+}
+EXPORT_SYMBOL(hdmi_drm_infoframe_unpack_only);
+
+/**
+ * hdmi_drm_infoframe_unpack() - unpack binary buffer to a HDMI DRM infoframe
+ * @frame: HDMI DRM infoframe
+ * @buffer: source buffer
+ * @size: size of buffer
+ *
+ * Unpacks the CTA-861-G DRM infoframe contained in the binary @buffer into
+ * a structured @frame of the HDMI Dynamic Range and Mastering (DRM)
+ * infoframe. It also verifies the checksum as required by section 5.3.5 of
+ * the HDMI 1.4 specification.
+ *
+ * Returns 0 on success or a negative error code on failure.
+ */
+static int hdmi_drm_infoframe_unpack(struct hdmi_drm_infoframe *frame,
+ const void *buffer, size_t size)
+{
+ const u8 *ptr = buffer;
+ int ret;
+
+ if (size < HDMI_INFOFRAME_SIZE(DRM))
+ return -EINVAL;
+
+ if (ptr[0] != HDMI_INFOFRAME_TYPE_DRM ||
+ ptr[1] != 1 ||
+ ptr[2] != HDMI_DRM_INFOFRAME_SIZE)
+ return -EINVAL;
+
+ if (hdmi_infoframe_checksum(buffer, HDMI_INFOFRAME_SIZE(DRM)) != 0)
+ return -EINVAL;
+
+ ret = hdmi_drm_infoframe_unpack_only(frame, ptr + HDMI_INFOFRAME_HEADER_SIZE,
+ size - HDMI_INFOFRAME_HEADER_SIZE);
+ return ret;
+}
+
+/**
+ * hdmi_infoframe_unpack() - unpack binary buffer to a HDMI infoframe
+ * @frame: HDMI infoframe
+ * @buffer: source buffer
+ * @size: size of buffer
+ *
+ * Unpacks the information contained in binary buffer @buffer into a structured
+ * @frame of a HDMI infoframe.
+ * Also verifies the checksum as required by section 5.3.5 of the HDMI 1.4
+ * specification.
+ *
+ * Returns 0 on success or a negative error code on failure.
+ */
+int hdmi_infoframe_unpack(union hdmi_infoframe *frame,
+ const void *buffer, size_t size)
+{
+ int ret;
+ const u8 *ptr = buffer;
+
+ if (size < HDMI_INFOFRAME_HEADER_SIZE)
+ return -EINVAL;
+
+ switch (ptr[0]) {
+ case HDMI_INFOFRAME_TYPE_AVI:
+ ret = hdmi_avi_infoframe_unpack(&frame->avi, buffer, size);
+ break;
+ case HDMI_INFOFRAME_TYPE_DRM:
+ ret = hdmi_drm_infoframe_unpack(&frame->drm, buffer, size);
+ break;
+ case HDMI_INFOFRAME_TYPE_SPD:
+ ret = hdmi_spd_infoframe_unpack(&frame->spd, buffer, size);
+ break;
+ case HDMI_INFOFRAME_TYPE_AUDIO:
+ ret = hdmi_audio_infoframe_unpack(&frame->audio, buffer, size);
+ break;
+ case HDMI_INFOFRAME_TYPE_VENDOR:
+ ret = hdmi_vendor_any_infoframe_unpack(&frame->vendor, buffer, size);
+ break;
+ default:
+ ret = -EINVAL;
+ break;
+ }
+
+ return ret;
+}
+EXPORT_SYMBOL(hdmi_infoframe_unpack);
diff --git a/sys/compat/linuxkpi/common/src/linux_hrtimer.c b/sys/compat/linuxkpi/common/src/linux_hrtimer.c
index a56485512a14..dca5d5cf709b 100644
--- a/sys/compat/linuxkpi/common/src/linux_hrtimer.c
+++ b/sys/compat/linuxkpi/common/src/linux_hrtimer.c
@@ -23,9 +23,6 @@
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
-#include <sys/cdefs.h>
-__FBSDID("$FreeBSD$");
-
#include <sys/param.h>
#include <sys/systm.h>
#include <sys/lock.h>
@@ -66,6 +63,28 @@ linux_hrtimer_active(struct hrtimer *hrtimer)
}
/*
+ * Try to cancel active hrtimer.
+ * Return 1 if timer was active and cancellation succeeded, 0 if timer was
+ * inactive, or -1 if the timer is being serviced and can't be cancelled.
+ */
+int
+linux_hrtimer_try_to_cancel(struct hrtimer *hrtimer)
+{
+ int ret;
+
+ mtx_lock(&hrtimer->mtx);
+ ret = callout_stop(&hrtimer->callout);
+ mtx_unlock(&hrtimer->mtx);
+ if (ret > 0) {
+ return (1);
+ } else if (ret < 0) {
+ return (0);
+ } else {
+ return (-1);
+ }
+}
+
+/*
* Cancel active hrtimer.
* Return 1 if timer was active and cancellation succeeded, or 0 otherwise.
*/
diff --git a/sys/compat/linuxkpi/common/src/linux_i2c.c b/sys/compat/linuxkpi/common/src/linux_i2c.c
new file mode 100644
index 000000000000..f18570202f74
--- /dev/null
+++ b/sys/compat/linuxkpi/common/src/linux_i2c.c
@@ -0,0 +1,381 @@
+/*-
+ * Copyright (c) 2021 Beckhoff Automation GmbH & Co. KG
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``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 OR CONTRIBUTORS 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.
+ *
+ */
+
+#include <sys/param.h>
+#include <sys/systm.h>
+#include <sys/bus.h>
+#include <sys/malloc.h>
+
+#include <dev/iicbus/iicbus.h>
+#include <dev/iicbus/iiconf.h>
+
+#include <linux/device.h>
+#include <linux/i2c.h>
+#include <linux/i2c-algo-bit.h>
+#include <linux/list.h>
+#include <linux/pci.h>
+
+#include "iicbus_if.h"
+#include "iicbb_if.h"
+#include "lkpi_iic_if.h"
+
+static int lkpi_i2c_transfer(device_t dev, struct iic_msg *msgs, uint32_t nmsgs);
+static int lkpi_i2c_reset(device_t dev, u_char speed, u_char addr, u_char *oldaddr);
+
+struct lkpi_iic_softc {
+ device_t iicbus;
+ struct i2c_adapter *adapter;
+};
+
+static struct sx lkpi_sx_i2c;
+
+static void
+lkpi_sysinit_i2c(void *arg __unused)
+{
+
+ sx_init(&lkpi_sx_i2c, "lkpi-i2c");
+}
+
+static void
+lkpi_sysuninit_i2c(void *arg __unused)
+{
+
+ sx_destroy(&lkpi_sx_i2c);
+}
+
+SYSINIT(lkpi_i2c, SI_SUB_DRIVERS, SI_ORDER_ANY,
+ lkpi_sysinit_i2c, NULL);
+SYSUNINIT(lkpi_i2c, SI_SUB_DRIVERS, SI_ORDER_ANY,
+ lkpi_sysuninit_i2c, NULL);
+
+static int
+lkpi_iic_probe(device_t dev)
+{
+
+ device_set_desc(dev, "LinuxKPI I2C");
+ return (BUS_PROBE_NOWILDCARD);
+}
+
+static int
+lkpi_iic_attach(device_t dev)
+{
+ struct lkpi_iic_softc *sc;
+
+ sc = device_get_softc(dev);
+ sc->iicbus = device_add_child(dev, "iicbus", DEVICE_UNIT_ANY);
+ if (sc->iicbus == NULL) {
+ device_printf(dev, "Couldn't add iicbus child, aborting\n");
+ return (ENXIO);
+ }
+ bus_attach_children(dev);
+ return (0);
+}
+
+static int
+lkpi_iic_detach(device_t dev)
+{
+ struct lkpi_iic_softc *sc;
+
+ sc = device_get_softc(dev);
+ if (sc->iicbus)
+ device_delete_child(dev, sc->iicbus);
+ return (0);
+}
+
+static int
+lkpi_iic_add_adapter(device_t dev, struct i2c_adapter *adapter)
+{
+ struct lkpi_iic_softc *sc;
+
+ sc = device_get_softc(dev);
+ sc->adapter = adapter;
+
+ return (0);
+}
+
+static struct i2c_adapter *
+lkpi_iic_get_adapter(device_t dev)
+{
+ struct lkpi_iic_softc *sc;
+
+ sc = device_get_softc(dev);
+ return (sc->adapter);
+}
+
+static device_method_t lkpi_iic_methods[] = {
+ /* device interface */
+ DEVMETHOD(device_probe, lkpi_iic_probe),
+ DEVMETHOD(device_attach, lkpi_iic_attach),
+ DEVMETHOD(device_detach, lkpi_iic_detach),
+ DEVMETHOD(device_suspend, bus_generic_suspend),
+ DEVMETHOD(device_resume, bus_generic_resume),
+
+ /* iicbus interface */
+ DEVMETHOD(iicbus_transfer, lkpi_i2c_transfer),
+ DEVMETHOD(iicbus_reset, lkpi_i2c_reset),
+ DEVMETHOD(iicbus_callback, iicbus_null_callback),
+
+ /* lkpi_iic interface */
+ DEVMETHOD(lkpi_iic_add_adapter, lkpi_iic_add_adapter),
+ DEVMETHOD(lkpi_iic_get_adapter, lkpi_iic_get_adapter),
+
+ DEVMETHOD_END
+};
+
+driver_t lkpi_iic_driver = {
+ "lkpi_iic",
+ lkpi_iic_methods,
+ sizeof(struct lkpi_iic_softc),
+};
+
+DRIVER_MODULE(lkpi_iic, drmn, lkpi_iic_driver, 0, 0);
+DRIVER_MODULE(lkpi_iic, drm, lkpi_iic_driver, 0, 0);
+DRIVER_MODULE(iicbus, lkpi_iic, iicbus_driver, 0, 0);
+MODULE_DEPEND(linuxkpi, iicbus, IICBUS_MINVER, IICBUS_PREFVER, IICBUS_MAXVER);
+
+static int
+lkpi_i2c_reset(device_t dev, u_char speed, u_char addr, u_char *oldaddr)
+{
+
+ /* That doesn't seems to be supported in linux */
+ return (0);
+}
+
+static int i2c_check_for_quirks(struct i2c_adapter *adapter,
+ struct iic_msg *msgs, uint32_t nmsgs)
+{
+ const struct i2c_adapter_quirks *quirks;
+ device_t dev;
+ int i, max_nmsgs;
+ bool check_len;
+
+ dev = adapter->dev.parent->bsddev;
+ quirks = adapter->quirks;
+ if (quirks == NULL)
+ return (0);
+
+ check_len = true;
+ max_nmsgs = quirks->max_num_msgs;
+
+ if (quirks->flags & I2C_AQ_COMB) {
+ max_nmsgs = 2;
+
+ if (nmsgs == 2) {
+ if (quirks->flags & I2C_AQ_COMB_WRITE_FIRST &&
+ msgs[0].flags & IIC_M_RD) {
+ device_printf(dev,
+ "Error: "
+ "first combined message must be write\n");
+ return (EOPNOTSUPP);
+ }
+ if (quirks->flags & I2C_AQ_COMB_READ_SECOND &&
+ !(msgs[1].flags & IIC_M_RD)) {
+ device_printf(dev,
+ "Error: "
+ "second combined message must be read\n");
+ return (EOPNOTSUPP);
+ }
+
+ if (quirks->flags & I2C_AQ_COMB_SAME_ADDR &&
+ msgs[0].slave != msgs[1].slave) {
+ device_printf(dev,
+ "Error: "
+ "combined message must be use the same "
+ "address\n");
+ return (EOPNOTSUPP);
+ }
+
+ if (quirks->max_comb_1st_msg_len &&
+ msgs[0].len > quirks->max_comb_1st_msg_len) {
+ device_printf(dev,
+ "Error: "
+ "message too long: %hu > %hu max\n",
+ msgs[0].len,
+ quirks->max_comb_1st_msg_len);
+ return (EOPNOTSUPP);
+ }
+ if (quirks->max_comb_2nd_msg_len &&
+ msgs[1].len > quirks->max_comb_2nd_msg_len) {
+ device_printf(dev,
+ "Error: "
+ "message too long: %hu > %hu max\n",
+ msgs[1].len,
+ quirks->max_comb_2nd_msg_len);
+ return (EOPNOTSUPP);
+ }
+
+ check_len = false;
+ }
+ }
+
+ if (max_nmsgs && nmsgs > max_nmsgs) {
+ device_printf(dev,
+ "Error: too many messages: %d > %d max\n",
+ nmsgs, max_nmsgs);
+ return (EOPNOTSUPP);
+ }
+
+ for (i = 0; i < nmsgs; i++) {
+ if (msgs[i].flags & IIC_M_RD) {
+ if (check_len && quirks->max_read_len &&
+ msgs[i].len > quirks->max_read_len) {
+ device_printf(dev,
+ "Error: "
+ "message %d too long: %hu > %hu max\n",
+ i, msgs[i].len, quirks->max_read_len);
+ return (EOPNOTSUPP);
+ }
+ if (quirks->flags & I2C_AQ_NO_ZERO_LEN_READ &&
+ msgs[i].len == 0) {
+ device_printf(dev,
+ "Error: message %d of length 0\n", i);
+ return (EOPNOTSUPP);
+ }
+ } else {
+ if (check_len && quirks->max_write_len &&
+ msgs[i].len > quirks->max_write_len) {
+ device_printf(dev,
+ "Message %d too long: %hu > %hu max\n",
+ i, msgs[i].len, quirks->max_write_len);
+ return (EOPNOTSUPP);
+ }
+ if (quirks->flags & I2C_AQ_NO_ZERO_LEN_WRITE &&
+ msgs[i].len == 0) {
+ device_printf(dev,
+ "Error: message %d of length 0\n", i);
+ return (EOPNOTSUPP);
+ }
+ }
+ }
+
+ return (0);
+}
+
+static int
+lkpi_i2c_transfer(device_t dev, struct iic_msg *msgs, uint32_t nmsgs)
+{
+ struct lkpi_iic_softc *sc;
+ struct i2c_msg *linux_msgs;
+ int i, ret = 0;
+
+ sc = device_get_softc(dev);
+ if (sc->adapter == NULL)
+ return (ENXIO);
+ ret = i2c_check_for_quirks(sc->adapter, msgs, nmsgs);
+ if (ret != 0)
+ return (ret);
+ linux_set_current(curthread);
+
+ linux_msgs = malloc(sizeof(struct i2c_msg) * nmsgs,
+ M_DEVBUF, M_WAITOK | M_ZERO);
+
+ for (i = 0; i < nmsgs; i++) {
+ linux_msgs[i].addr = msgs[i].slave >> 1;
+ linux_msgs[i].len = msgs[i].len;
+ linux_msgs[i].buf = msgs[i].buf;
+ if (msgs[i].flags & IIC_M_RD) {
+ linux_msgs[i].flags |= I2C_M_RD;
+ for (int j = 0; j < msgs[i].len; j++)
+ msgs[i].buf[j] = 0;
+ }
+ if (msgs[i].flags & IIC_M_NOSTART)
+ linux_msgs[i].flags |= I2C_M_NOSTART;
+ }
+ ret = i2c_transfer(sc->adapter, linux_msgs, nmsgs);
+ free(linux_msgs, M_DEVBUF);
+
+ if (ret < 0)
+ return (-ret);
+ return (0);
+}
+
+int
+lkpi_i2c_add_adapter(struct i2c_adapter *adapter)
+{
+ device_t lkpi_iic;
+
+ if (adapter->name[0] == '\0')
+ return (-EINVAL);
+ if (bootverbose)
+ device_printf(adapter->dev.parent->bsddev,
+ "Adding i2c adapter %s\n", adapter->name);
+ sx_xlock(&lkpi_sx_i2c);
+ lkpi_iic = device_add_child(adapter->dev.parent->bsddev, "lkpi_iic",
+ DEVICE_UNIT_ANY);
+ if (lkpi_iic == NULL) {
+ device_printf(adapter->dev.parent->bsddev, "Couldn't add lkpi_iic\n");
+ sx_xunlock(&lkpi_sx_i2c);
+ return (ENXIO);
+ }
+
+ bus_topo_lock();
+ bus_attach_children(adapter->dev.parent->bsddev);
+ bus_topo_unlock();
+ LKPI_IIC_ADD_ADAPTER(lkpi_iic, adapter);
+ sx_xunlock(&lkpi_sx_i2c);
+ return (0);
+}
+
+int
+lkpi_i2c_del_adapter(struct i2c_adapter *adapter)
+{
+ device_t child;
+ int unit, rv;
+
+ if (adapter == NULL)
+ return (-EINVAL);
+ if (bootverbose)
+ device_printf(adapter->dev.parent->bsddev,
+ "Removing i2c adapter %s\n", adapter->name);
+ sx_xlock(&lkpi_sx_i2c);
+ unit = 0;
+ while ((child = device_find_child(adapter->dev.parent->bsddev, "lkpi_iic", unit++)) != NULL) {
+
+ if (adapter == LKPI_IIC_GET_ADAPTER(child)) {
+ bus_topo_lock();
+ device_delete_child(adapter->dev.parent->bsddev, child);
+ bus_topo_unlock();
+ rv = 0;
+ goto out;
+ }
+ }
+
+ unit = 0;
+ while ((child = device_find_child(adapter->dev.parent->bsddev, "lkpi_iicbb", unit++)) != NULL) {
+
+ if (adapter == LKPI_IIC_GET_ADAPTER(child)) {
+ bus_topo_lock();
+ device_delete_child(adapter->dev.parent->bsddev, child);
+ bus_topo_unlock();
+ rv = 0;
+ goto out;
+ }
+ }
+ rv = -EINVAL;
+out:
+ sx_xunlock(&lkpi_sx_i2c);
+ return (rv);
+}
diff --git a/sys/compat/linuxkpi/common/src/linux_i2cbb.c b/sys/compat/linuxkpi/common/src/linux_i2cbb.c
new file mode 100644
index 000000000000..48a018ec2533
--- /dev/null
+++ b/sys/compat/linuxkpi/common/src/linux_i2cbb.c
@@ -0,0 +1,325 @@
+/*-
+ * Copyright (c) 2021 Beckhoff Automation GmbH & Co. KG
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``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 OR CONTRIBUTORS 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.
+ *
+ */
+
+#include <sys/param.h>
+#include <sys/systm.h>
+#include <sys/bus.h>
+#include <sys/malloc.h>
+
+#include <dev/iicbus/iicbus.h>
+#include <dev/iicbus/iiconf.h>
+
+#include <linux/device.h>
+#include <linux/i2c.h>
+#include <linux/i2c-algo-bit.h>
+#include <linux/list.h>
+#include <linux/pci.h>
+
+#include "iicbus_if.h"
+#include "iicbb_if.h"
+#include "lkpi_iic_if.h"
+
+static void lkpi_iicbb_setsda(device_t dev, int val);
+static void lkpi_iicbb_setscl(device_t dev, int val);
+static int lkpi_iicbb_getscl(device_t dev);
+static int lkpi_iicbb_getsda(device_t dev);
+static int lkpi_iicbb_reset(device_t dev, u_char speed, u_char addr, u_char *oldaddr);
+static int lkpi_iicbb_pre_xfer(device_t dev);
+static void lkpi_iicbb_post_xfer(device_t dev);
+
+struct lkpi_iicbb_softc {
+ device_t iicbb;
+ struct i2c_adapter *adapter;
+};
+
+static struct sx lkpi_sx_i2cbb;
+
+static void
+lkpi_sysinit_i2cbb(void *arg __unused)
+{
+
+ sx_init(&lkpi_sx_i2cbb, "lkpi-i2cbb");
+}
+
+static void
+lkpi_sysuninit_i2cbb(void *arg __unused)
+{
+
+ sx_destroy(&lkpi_sx_i2cbb);
+}
+
+SYSINIT(lkpi_i2cbb, SI_SUB_DRIVERS, SI_ORDER_ANY,
+ lkpi_sysinit_i2cbb, NULL);
+SYSUNINIT(lkpi_i2cbb, SI_SUB_DRIVERS, SI_ORDER_ANY,
+ lkpi_sysuninit_i2cbb, NULL);
+
+static int
+lkpi_iicbb_probe(device_t dev)
+{
+
+ device_set_desc(dev, "LinuxKPI I2CBB");
+ return (BUS_PROBE_NOWILDCARD);
+}
+
+static int
+lkpi_iicbb_attach(device_t dev)
+{
+ struct lkpi_iicbb_softc *sc;
+
+ sc = device_get_softc(dev);
+ sc->iicbb = device_add_child(dev, "iicbb", DEVICE_UNIT_ANY);
+ if (sc->iicbb == NULL) {
+ device_printf(dev, "Couldn't add iicbb child, aborting\n");
+ return (ENXIO);
+ }
+ bus_attach_children(dev);
+ return (0);
+}
+
+static int
+lkpi_iicbb_detach(device_t dev)
+{
+ struct lkpi_iicbb_softc *sc;
+
+ sc = device_get_softc(dev);
+ if (sc->iicbb)
+ device_delete_child(dev, sc->iicbb);
+ return (0);
+}
+
+static int
+lkpi_iicbb_add_adapter(device_t dev, struct i2c_adapter *adapter)
+{
+ struct lkpi_iicbb_softc *sc;
+ struct i2c_algo_bit_data *algo_data;
+
+ sc = device_get_softc(dev);
+ sc->adapter = adapter;
+
+ /*
+ * Set iicbb timing parameters deriving speed from the protocol delay.
+ */
+ algo_data = adapter->algo_data;
+ if (algo_data->udelay != 0)
+ IICBUS_RESET(sc->iicbb, 1000000 / algo_data->udelay, 0, NULL);
+ return (0);
+}
+
+static struct i2c_adapter *
+lkpi_iicbb_get_adapter(device_t dev)
+{
+ struct lkpi_iicbb_softc *sc;
+
+ sc = device_get_softc(dev);
+ return (sc->adapter);
+}
+
+static device_method_t lkpi_iicbb_methods[] = {
+ /* device interface */
+ DEVMETHOD(device_probe, lkpi_iicbb_probe),
+ DEVMETHOD(device_attach, lkpi_iicbb_attach),
+ DEVMETHOD(device_detach, lkpi_iicbb_detach),
+ DEVMETHOD(device_suspend, bus_generic_suspend),
+ DEVMETHOD(device_resume, bus_generic_resume),
+
+ /* iicbb interface */
+ DEVMETHOD(iicbb_setsda, lkpi_iicbb_setsda),
+ DEVMETHOD(iicbb_setscl, lkpi_iicbb_setscl),
+ DEVMETHOD(iicbb_getsda, lkpi_iicbb_getsda),
+ DEVMETHOD(iicbb_getscl, lkpi_iicbb_getscl),
+ DEVMETHOD(iicbb_reset, lkpi_iicbb_reset),
+ DEVMETHOD(iicbb_pre_xfer, lkpi_iicbb_pre_xfer),
+ DEVMETHOD(iicbb_post_xfer, lkpi_iicbb_post_xfer),
+
+ /* lkpi_iicbb interface */
+ DEVMETHOD(lkpi_iic_add_adapter, lkpi_iicbb_add_adapter),
+ DEVMETHOD(lkpi_iic_get_adapter, lkpi_iicbb_get_adapter),
+
+ DEVMETHOD_END
+};
+
+driver_t lkpi_iicbb_driver = {
+ "lkpi_iicbb",
+ lkpi_iicbb_methods,
+ sizeof(struct lkpi_iicbb_softc),
+};
+
+DRIVER_MODULE(lkpi_iicbb, drmn, lkpi_iicbb_driver, 0, 0);
+DRIVER_MODULE(lkpi_iicbb, drm, lkpi_iicbb_driver, 0, 0);
+DRIVER_MODULE(iicbb, lkpi_iicbb, iicbb_driver, 0, 0);
+MODULE_DEPEND(linuxkpi, iicbb, IICBUS_MINVER, IICBUS_PREFVER, IICBUS_MAXVER);
+
+static void
+lkpi_iicbb_setsda(device_t dev, int val)
+{
+ struct lkpi_iicbb_softc *sc;
+ struct i2c_algo_bit_data *algo_data;
+
+ sc = device_get_softc(dev);
+ algo_data = sc->adapter->algo_data;
+ algo_data->setsda(algo_data->data, val);
+}
+
+static void
+lkpi_iicbb_setscl(device_t dev, int val)
+{
+ struct lkpi_iicbb_softc *sc;
+ struct i2c_algo_bit_data *algo_data;
+
+ sc = device_get_softc(dev);
+ algo_data = sc->adapter->algo_data;
+ algo_data->setscl(algo_data->data, val);
+}
+
+static int
+lkpi_iicbb_getscl(device_t dev)
+{
+ struct lkpi_iicbb_softc *sc;
+ struct i2c_algo_bit_data *algo_data;
+ int ret;
+
+ sc = device_get_softc(dev);
+ algo_data = sc->adapter->algo_data;
+ ret = algo_data->getscl(algo_data->data);
+ return (ret);
+}
+
+static int
+lkpi_iicbb_getsda(device_t dev)
+{
+ struct lkpi_iicbb_softc *sc;
+ struct i2c_algo_bit_data *algo_data;
+ int ret;
+
+ sc = device_get_softc(dev);
+ algo_data = sc->adapter->algo_data;
+ ret = algo_data->getsda(algo_data->data);
+ return (ret);
+}
+
+static int
+lkpi_iicbb_reset(device_t dev, u_char speed, u_char addr, u_char *oldaddr)
+{
+
+ /* That doesn't seems to be supported in linux */
+ return (0);
+}
+
+static int
+lkpi_iicbb_pre_xfer(device_t dev)
+{
+ struct lkpi_iicbb_softc *sc;
+ struct i2c_algo_bit_data *algo_data;
+ int rc = 0;
+
+ sc = device_get_softc(dev);
+ algo_data = sc->adapter->algo_data;
+ if (algo_data->pre_xfer != 0)
+ rc = algo_data->pre_xfer(sc->adapter);
+ return (rc);
+}
+
+static void
+lkpi_iicbb_post_xfer(device_t dev)
+{
+ struct lkpi_iicbb_softc *sc;
+ struct i2c_algo_bit_data *algo_data;
+
+ sc = device_get_softc(dev);
+ algo_data = sc->adapter->algo_data;
+ if (algo_data->post_xfer != NULL)
+ algo_data->post_xfer(sc->adapter);
+}
+
+int
+lkpi_i2cbb_transfer(struct i2c_adapter *adapter, struct i2c_msg *msgs,
+ int nmsgs)
+{
+ struct iic_msg *bsd_msgs;
+ int ret = ENXIO;
+
+ linux_set_current(curthread);
+
+ bsd_msgs = malloc(sizeof(struct iic_msg) * nmsgs,
+ M_DEVBUF, M_WAITOK | M_ZERO);
+
+ for (int i = 0; i < nmsgs; i++) {
+ bsd_msgs[i].slave = msgs[i].addr << 1;
+ bsd_msgs[i].len = msgs[i].len;
+ bsd_msgs[i].buf = msgs[i].buf;
+ if (msgs[i].flags & I2C_M_RD)
+ bsd_msgs[i].flags |= IIC_M_RD;
+ if (msgs[i].flags & I2C_M_NOSTART)
+ bsd_msgs[i].flags |= IIC_M_NOSTART;
+ }
+
+ for (int unit = 0; ; unit++) {
+ device_t child;
+ struct lkpi_iicbb_softc *sc;
+
+ child = device_find_child(adapter->dev.parent->bsddev,
+ "lkpi_iicbb", unit);
+ if (child == NULL)
+ break;
+ if (adapter == LKPI_IIC_GET_ADAPTER(child)) {
+ sc = device_get_softc(child);
+ ret = IICBUS_TRANSFER(sc->iicbb, bsd_msgs, nmsgs);
+ ret = iic2errno(ret);
+ break;
+ }
+ }
+
+ free(bsd_msgs, M_DEVBUF);
+
+ if (ret != 0)
+ return (-ret);
+ return (nmsgs);
+}
+
+int
+lkpi_i2c_bit_add_bus(struct i2c_adapter *adapter)
+{
+ device_t lkpi_iicbb;
+
+ if (bootverbose)
+ device_printf(adapter->dev.parent->bsddev,
+ "Adding i2c adapter %s\n", adapter->name);
+ sx_xlock(&lkpi_sx_i2cbb);
+ lkpi_iicbb = device_add_child(adapter->dev.parent->bsddev, "lkpi_iicbb",
+ DEVICE_UNIT_ANY);
+ if (lkpi_iicbb == NULL) {
+ device_printf(adapter->dev.parent->bsddev, "Couldn't add lkpi_iicbb\n");
+ sx_xunlock(&lkpi_sx_i2cbb);
+ return (ENXIO);
+ }
+
+ bus_topo_lock();
+ bus_attach_children(adapter->dev.parent->bsddev);
+ bus_topo_unlock();
+ LKPI_IIC_ADD_ADAPTER(lkpi_iicbb, adapter);
+ sx_xunlock(&lkpi_sx_i2cbb);
+ return (0);
+}
diff --git a/sys/compat/linuxkpi/common/src/linux_idr.c b/sys/compat/linuxkpi/common/src/linux_idr.c
index b5007a89966b..664177835c85 100644
--- a/sys/compat/linuxkpi/common/src/linux_idr.c
+++ b/sys/compat/linuxkpi/common/src/linux_idr.c
@@ -27,9 +27,6 @@
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
-#include <sys/cdefs.h>
-__FBSDID("$FreeBSD$");
-
#include <sys/param.h>
#include <sys/systm.h>
#include <sys/malloc.h>
@@ -37,8 +34,7 @@ __FBSDID("$FreeBSD$");
#include <sys/sysctl.h>
#include <sys/lock.h>
#include <sys/mutex.h>
-
-#include <machine/stdarg.h>
+#include <sys/stdarg.h>
#include <linux/bitmap.h>
#include <linux/kobject.h>
@@ -72,7 +68,7 @@ idr_preload_dequeue_locked(struct linux_idr_cache *lic)
struct idr_layer *retval;
/* check if wrong thread is trying to dequeue */
- if (mtx_owned(&lic->lock.m) == 0)
+ if (mtx_owned(&lic->lock) == 0)
return (NULL);
retval = lic->head;
@@ -181,6 +177,14 @@ idr_destroy(struct idr *idr)
{
struct idr_layer *il, *iln;
+ /*
+ * This idr can be reused, and this function might be called multiple times
+ * without a idr_init(). Check if this is the case. If we do not do this
+ * then the mutex will panic while asserting that it is valid.
+ */
+ if (mtx_initialized(&idr->lock) == 0)
+ return;
+
idr_remove_all(idr);
mtx_lock(&idr->lock);
for (il = idr->free; il != NULL; il = iln) {
@@ -757,10 +761,9 @@ ida_simple_get(struct ida *ida, unsigned int start, unsigned int end,
unsigned int max;
MPASS((int)start >= 0);
- MPASS((int)end >= 0);
- if (end == 0)
- max = 0x80000000;
+ if ((int)end <= 0)
+ max = INT_MAX;
else {
MPASS(end > start);
max = end - 1;
@@ -806,4 +809,5 @@ ida_destroy(struct ida *ida)
{
idr_destroy(&ida->idr);
free(ida->free_bitmap, M_IDR);
+ ida->free_bitmap = NULL;
}
diff --git a/sys/compat/linuxkpi/common/src/linux_interrupt.c b/sys/compat/linuxkpi/common/src/linux_interrupt.c
index f96a47137fab..378088246f21 100644
--- a/sys/compat/linuxkpi/common/src/linux_interrupt.c
+++ b/sys/compat/linuxkpi/common/src/linux_interrupt.c
@@ -25,8 +25,6 @@
* 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.
- *
- * $FreeBSD$
*/
#include <linux/device.h>
@@ -119,17 +117,20 @@ lkpi_request_irq(struct device *xdev, unsigned int irq,
struct resource *res;
struct irq_ent *irqe;
struct device *dev;
+ unsigned resflags;
int error;
int rid;
- dev = linux_pci_find_irq_dev(irq);
+ dev = lkpi_pci_find_irq_dev(irq);
if (dev == NULL)
return -ENXIO;
if (xdev != NULL && xdev != dev)
return -ENXIO;
rid = lkpi_irq_rid(dev, irq);
- res = bus_alloc_resource_any(dev->bsddev, SYS_RES_IRQ, &rid,
- flags | RF_ACTIVE);
+ resflags = RF_ACTIVE;
+ if ((flags & IRQF_SHARED) != 0)
+ resflags |= RF_SHAREABLE;
+ res = bus_alloc_resource_any(dev->bsddev, SYS_RES_IRQ, &rid, resflags);
if (res == NULL)
return (-ENXIO);
if (xdev != NULL)
@@ -169,7 +170,7 @@ lkpi_enable_irq(unsigned int irq)
struct irq_ent *irqe;
struct device *dev;
- dev = linux_pci_find_irq_dev(irq);
+ dev = lkpi_pci_find_irq_dev(irq);
if (dev == NULL)
return -EINVAL;
irqe = lkpi_irq_ent(dev, irq);
@@ -185,7 +186,7 @@ lkpi_disable_irq(unsigned int irq)
struct irq_ent *irqe;
struct device *dev;
- dev = linux_pci_find_irq_dev(irq);
+ dev = lkpi_pci_find_irq_dev(irq);
if (dev == NULL)
return;
irqe = lkpi_irq_ent(dev, irq);
@@ -202,7 +203,7 @@ lkpi_bind_irq_to_cpu(unsigned int irq, int cpu_id)
struct irq_ent *irqe;
struct device *dev;
- dev = linux_pci_find_irq_dev(irq);
+ dev = lkpi_pci_find_irq_dev(irq);
if (dev == NULL)
return (-ENOENT);
@@ -219,7 +220,7 @@ lkpi_free_irq(unsigned int irq, void *device __unused)
struct irq_ent *irqe;
struct device *dev;
- dev = linux_pci_find_irq_dev(irq);
+ dev = lkpi_pci_find_irq_dev(irq);
if (dev == NULL)
return;
irqe = lkpi_irq_ent(dev, irq);
@@ -235,7 +236,7 @@ lkpi_devm_free_irq(struct device *xdev, unsigned int irq, void *p __unused)
struct device *dev;
struct irq_ent *irqe;
- dev = linux_pci_find_irq_dev(irq);
+ dev = lkpi_pci_find_irq_dev(irq);
if (dev == NULL)
return;
if (xdev != dev)
diff --git a/sys/compat/linuxkpi/common/src/linux_kmod.c b/sys/compat/linuxkpi/common/src/linux_kmod.c
index 7fd73f0a7f45..04ae20915cb6 100644
--- a/sys/compat/linuxkpi/common/src/linux_kmod.c
+++ b/sys/compat/linuxkpi/common/src/linux_kmod.c
@@ -24,9 +24,6 @@
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
-#include <sys/cdefs.h>
-__FBSDID("$FreeBSD$");
-
#include <sys/param.h>
#include <sys/module.h>
diff --git a/sys/compat/linuxkpi/common/src/linux_kobject.c b/sys/compat/linuxkpi/common/src/linux_kobject.c
new file mode 100644
index 000000000000..2b9d3dcffa4b
--- /dev/null
+++ b/sys/compat/linuxkpi/common/src/linux_kobject.c
@@ -0,0 +1,354 @@
+/*-
+ * Copyright (c) 2010 Isilon Systems, Inc.
+ * Copyright (c) 2010 iX Systems, Inc.
+ * Copyright (c) 2010 Panasas, Inc.
+ * Copyright (c) 2013-2021 Mellanox Technologies, Ltd.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice unmodified, this list of conditions, and the following
+ * disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``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.
+ */
+
+#include <linux/kobject.h>
+#include <linux/sysfs.h>
+
+static void kset_join(struct kobject *kobj);
+static void kset_leave(struct kobject *kobj);
+static void kset_kfree(struct kobject *kobj);
+
+struct kobject *
+kobject_create(void)
+{
+ struct kobject *kobj;
+
+ kobj = kzalloc(sizeof(*kobj), GFP_KERNEL);
+ if (kobj == NULL)
+ return (NULL);
+ kobject_init(kobj, &linux_kfree_type);
+
+ return (kobj);
+}
+
+
+int
+kobject_set_name_vargs(struct kobject *kobj, const char *fmt, va_list args)
+{
+ va_list tmp_va;
+ int len;
+ char *old;
+ char *name;
+ char dummy;
+
+ old = kobj->name;
+
+ if (old && fmt == NULL)
+ return (0);
+
+ /* compute length of string */
+ va_copy(tmp_va, args);
+ len = vsnprintf(&dummy, 0, fmt, tmp_va);
+ va_end(tmp_va);
+
+ /* account for zero termination */
+ len++;
+
+ /* check for error */
+ if (len < 1)
+ return (-EINVAL);
+
+ /* allocate memory for string */
+ name = kzalloc(len, GFP_KERNEL);
+ if (name == NULL)
+ return (-ENOMEM);
+ vsnprintf(name, len, fmt, args);
+ kobj->name = name;
+
+ /* free old string */
+ kfree(old);
+
+ /* filter new string */
+ for (; *name != '\0'; name++)
+ if (*name == '/')
+ *name = '!';
+ return (0);
+}
+
+int
+kobject_set_name(struct kobject *kobj, const char *fmt, ...)
+{
+ va_list args;
+ int error;
+
+ va_start(args, fmt);
+ error = kobject_set_name_vargs(kobj, fmt, args);
+ va_end(args);
+
+ return (error);
+}
+
+static int
+kobject_add_complete(struct kobject *kobj)
+{
+ const struct kobj_type *t;
+ int error;
+
+ if (kobj->kset != NULL) {
+ kset_join(kobj);
+ kobj->parent = &kobj->kset->kobj;
+ }
+
+ error = sysfs_create_dir(kobj);
+ if (error == 0 && kobj->ktype && kobj->ktype->default_attrs) {
+ struct attribute **attr;
+ t = kobj->ktype;
+
+ for (attr = t->default_attrs; *attr != NULL; attr++) {
+ error = sysfs_create_file(kobj, *attr);
+ if (error != 0)
+ break;
+ }
+ if (error != 0)
+ sysfs_remove_dir(kobj);
+ }
+
+ if (error != 0)
+ kset_leave(kobj);
+
+ return (error);
+}
+
+int
+kobject_add(struct kobject *kobj, struct kobject *parent, const char *fmt, ...)
+{
+ va_list args;
+ int error;
+
+ kobj->parent = parent;
+
+ va_start(args, fmt);
+ error = kobject_set_name_vargs(kobj, fmt, args);
+ va_end(args);
+ if (error)
+ return (error);
+
+ return kobject_add_complete(kobj);
+}
+
+int
+kobject_init_and_add(struct kobject *kobj, const struct kobj_type *ktype,
+ struct kobject *parent, const char *fmt, ...)
+{
+ va_list args;
+ int error;
+
+ kobject_init(kobj, ktype);
+ kobj->ktype = ktype;
+ kobj->parent = parent;
+ kobj->name = NULL;
+
+ va_start(args, fmt);
+ error = kobject_set_name_vargs(kobj, fmt, args);
+ va_end(args);
+ if (error)
+ return (error);
+ return kobject_add_complete(kobj);
+}
+
+void
+linux_kobject_release(struct kref *kref)
+{
+ struct kobject *kobj;
+ char *name;
+
+ kobj = container_of(kref, struct kobject, kref);
+ sysfs_remove_dir(kobj);
+ kset_leave(kobj);
+ name = kobj->name;
+ if (kobj->ktype && kobj->ktype->release)
+ kobj->ktype->release(kobj);
+ kfree(name);
+}
+
+static void
+linux_kobject_kfree(struct kobject *kobj)
+{
+ kfree(kobj);
+}
+
+const struct kobj_type linux_kfree_type = {
+ .release = linux_kobject_kfree
+};
+
+void
+linux_kobject_kfree_name(struct kobject *kobj)
+{
+ if (kobj) {
+ kfree(kobj->name);
+ }
+}
+
+static ssize_t
+lkpi_kobj_attr_show(struct kobject *kobj, struct attribute *attr, char *buf)
+{
+ struct kobj_attribute *ka =
+ container_of(attr, struct kobj_attribute, attr);
+
+ if (ka->show == NULL)
+ return (-EIO);
+
+ return (ka->show(kobj, ka, buf));
+}
+
+static ssize_t
+lkpi_kobj_attr_store(struct kobject *kobj, struct attribute *attr,
+ const char *buf, size_t count)
+{
+ struct kobj_attribute *ka =
+ container_of(attr, struct kobj_attribute, attr);
+
+ if (ka->store == NULL)
+ return (-EIO);
+
+ return (ka->store(kobj, ka, buf, count));
+}
+
+const struct sysfs_ops kobj_sysfs_ops = {
+ .show = lkpi_kobj_attr_show,
+ .store = lkpi_kobj_attr_store,
+};
+
+const struct kobj_type linux_kset_kfree_type = {
+ .release = kset_kfree
+};
+
+static struct kset *
+kset_create(const char *name,
+ const struct kset_uevent_ops *uevent_ops,
+ struct kobject *parent_kobj)
+{
+ struct kset *kset;
+
+ kset = kzalloc(sizeof(*kset), GFP_KERNEL);
+ if (kset == NULL)
+ return (NULL);
+
+ kset->uevent_ops = uevent_ops;
+
+ kobject_set_name(&kset->kobj, "%s", name);
+ kset->kobj.parent = parent_kobj;
+ kset->kobj.kset = NULL;
+
+ return (kset);
+}
+
+void
+kset_init(struct kset *kset)
+{
+ kobject_init(&kset->kobj, &linux_kset_kfree_type);
+ INIT_LIST_HEAD(&kset->list);
+ spin_lock_init(&kset->list_lock);
+}
+
+static void
+kset_join(struct kobject *kobj)
+{
+ struct kset *kset;
+
+ kset = kobj->kset;
+ if (kset == NULL)
+ return;
+
+ kset_get(kobj->kset);
+
+ spin_lock(&kset->list_lock);
+ list_add_tail(&kobj->entry, &kset->list);
+ spin_unlock(&kset->list_lock);
+}
+
+static void
+kset_leave(struct kobject *kobj)
+{
+ struct kset *kset;
+
+ kset = kobj->kset;
+ if (kset == NULL)
+ return;
+
+ spin_lock(&kset->list_lock);
+ list_del_init(&kobj->entry);
+ spin_unlock(&kset->list_lock);
+
+ kset_put(kobj->kset);
+}
+
+struct kset *
+kset_create_and_add(const char *name, const struct kset_uevent_ops *u,
+ struct kobject *parent_kobj)
+{
+ int ret;
+ struct kset *kset;
+
+ kset = kset_create(name, u, parent_kobj);
+ if (kset == NULL)
+ return (NULL);
+
+ ret = kset_register(kset);
+ if (ret != 0) {
+ linux_kobject_kfree_name(&kset->kobj);
+ kfree(kset);
+ return (NULL);
+ }
+
+ return (kset);
+}
+
+int
+kset_register(struct kset *kset)
+{
+ int ret;
+
+ if (kset == NULL)
+ return -EINVAL;
+
+ kset_init(kset);
+ ret = kobject_add_complete(&kset->kobj);
+
+ return ret;
+}
+
+void
+kset_unregister(struct kset *kset)
+{
+ if (kset == NULL)
+ return;
+
+ kobject_del(&kset->kobj);
+ kobject_put(&kset->kobj);
+}
+
+static void
+kset_kfree(struct kobject *kobj)
+{
+ struct kset *kset;
+
+ kset = to_kset(kobj);
+ kfree(kset);
+}
diff --git a/sys/compat/linuxkpi/common/src/linux_kthread.c b/sys/compat/linuxkpi/common/src/linux_kthread.c
index 26afe005ea59..2fba700fa283 100644
--- a/sys/compat/linuxkpi/common/src/linux_kthread.c
+++ b/sys/compat/linuxkpi/common/src/linux_kthread.c
@@ -25,8 +25,6 @@
*/
#include <sys/cdefs.h>
-__FBSDID("$FreeBSD$");
-
#include <linux/compat.h>
#include <linux/kthread.h>
#include <linux/sched.h>
@@ -165,3 +163,19 @@ linux_kthread_fn(void *arg __unused)
}
kthread_exit();
}
+
+void
+lkpi_kthread_work_fn(void *context, int pending __unused)
+{
+ struct kthread_work *work = context;
+
+ work->func(work);
+}
+
+void
+lkpi_kthread_worker_init_fn(void *context, int pending __unused)
+{
+ struct kthread_worker *worker = context;
+
+ worker->task = current;
+}
diff --git a/sys/compat/linuxkpi/common/src/linux_lock.c b/sys/compat/linuxkpi/common/src/linux_lock.c
index b04a7738d036..3cebfc6ae3bb 100644
--- a/sys/compat/linuxkpi/common/src/linux_lock.c
+++ b/sys/compat/linuxkpi/common/src/linux_lock.c
@@ -22,8 +22,6 @@
* 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.
- *
- * $FreeBSD$
*/
#include <sys/queue.h>
@@ -160,6 +158,19 @@ linux_mutex_lock_interruptible(mutex_t *m)
}
int
+linux_down_read_killable(struct rw_semaphore *rw)
+{
+ int error;
+
+ error = -sx_slock_sig(&rw->sx);
+ if (error != 0) {
+ linux_schedule_save_interrupt_value(current, error);
+ error = -EINTR;
+ }
+ return (error);
+}
+
+int
linux_down_write_killable(struct rw_semaphore *rw)
{
int error;
diff --git a/sys/compat/linuxkpi/common/src/linux_mhi.c b/sys/compat/linuxkpi/common/src/linux_mhi.c
new file mode 100644
index 000000000000..5d3c391f91ab
--- /dev/null
+++ b/sys/compat/linuxkpi/common/src/linux_mhi.c
@@ -0,0 +1,89 @@
+/*-
+ * SPDX-License-Identifier: BSD-2-Clause
+ *
+ * Copyright (c) 2022 Bjoern A. Zeeb
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``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 OR CONTRIBUTORS 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.
+ */
+
+#include <sys/param.h>
+#include <sys/types.h>
+#include <sys/kernel.h>
+#include <sys/malloc.h>
+
+#include <linux/kernel.h> /* pr_debug */
+#include <linux/mhi.h>
+
+static MALLOC_DEFINE(M_LKPIMHI, "lkpimhi", "LinuxKPI MHI compat");
+
+struct mhi_controller *
+linuxkpi_mhi_alloc_controller(void)
+{
+ struct mhi_controller *mhi_ctrl;
+
+ mhi_ctrl = malloc(sizeof(*mhi_ctrl), M_LKPIMHI, M_NOWAIT | M_ZERO);
+
+ return (mhi_ctrl);
+}
+
+void
+linuxkpi_mhi_free_controller(struct mhi_controller *mhi_ctrl)
+{
+
+ /* What else do we need to check that it is gone? */
+ free(mhi_ctrl, M_LKPIMHI);
+}
+
+int
+linuxkpi_mhi_register_controller(struct mhi_controller *mhi_ctrl,
+ const struct mhi_controller_config *cfg)
+{
+
+ if (mhi_ctrl == NULL || cfg == NULL)
+ return (-EINVAL);
+
+#define CHECK_FIELD(_f) \
+ if (!mhi_ctrl->_f) \
+ return (-ENXIO);
+ CHECK_FIELD(cntrl_dev);
+ CHECK_FIELD(regs);
+ CHECK_FIELD(irq);
+ CHECK_FIELD(reg_len);
+ CHECK_FIELD(nr_irqs);
+
+ CHECK_FIELD(runtime_get);
+ CHECK_FIELD(runtime_put);
+ CHECK_FIELD(status_cb);
+ CHECK_FIELD(read_reg);
+ CHECK_FIELD(write_reg);
+#undef CHECK_FIELD
+
+ printf("%s: XXX-BZ TODO\n", __func__);
+ return (0);
+}
+
+void
+linuxkpi_mhi_unregister_controller(struct mhi_controller *mhi_ctrl)
+{
+
+ pr_debug("%s: TODO\n", __func__);
+}
diff --git a/sys/compat/linuxkpi/common/src/linux_netdev.c b/sys/compat/linuxkpi/common/src/linux_netdev.c
new file mode 100644
index 000000000000..ce9153614104
--- /dev/null
+++ b/sys/compat/linuxkpi/common/src/linux_netdev.c
@@ -0,0 +1,436 @@
+/*-
+ * Copyright (c) 2021 The FreeBSD Foundation
+ * Copyright (c) 2022 Bjoern A. Zeeb
+ *
+ * This software was developed by Björn Zeeb under sponsorship from
+ * the FreeBSD Foundation.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``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 OR CONTRIBUTORS 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.
+ */
+
+#include <sys/param.h>
+#include <sys/types.h>
+#include <sys/kernel.h>
+#include <sys/sysctl.h>
+
+#include <linux/bitops.h>
+#include <linux/list.h>
+#include <linux/netdevice.h>
+
+MALLOC_DEFINE(M_NETDEV, "lkpindev", "Linux KPI netdevice compat");
+
+#define NAPI_LOCK_INIT(_ndev) \
+ mtx_init(&(_ndev)->napi_mtx, "napi_mtx", NULL, MTX_DEF)
+#define NAPI_LOCK_DESTROY(_ndev) mtx_destroy(&(_ndev)->napi_mtx)
+#define NAPI_LOCK_ASSERT(_ndev) mtx_assert(&(_ndev)->napi_mtx, MA_OWNED)
+#define NAPI_LOCK(_ndev) mtx_lock(&(_ndev)->napi_mtx)
+#define NAPI_UNLOCK(_ndev) mtx_unlock(&(_ndev)->napi_mtx)
+
+/* -------------------------------------------------------------------------- */
+
+#define LKPI_NAPI_FLAGS \
+ "\20\1DISABLE_PENDING\2IS_SCHEDULED\3LOST_RACE_TRY_AGAIN"
+
+/* #define NAPI_DEBUG */
+#ifdef NAPI_DEBUG
+static int debug_napi;
+SYSCTL_INT(_compat_linuxkpi, OID_AUTO, debug_napi, CTLFLAG_RWTUN,
+ &debug_napi, 0, "NAPI debug level");
+
+#define DNAPI_TODO 0x01
+#define DNAPI_IMPROVE 0x02
+#define DNAPI_TRACE 0x10
+#define DNAPI_TRACE_TASK 0x20
+#define DNAPI_DIRECT_DISPATCH 0x1000
+
+#define NAPI_TRACE(_n) if (debug_napi & DNAPI_TRACE) \
+ printf("NAPI_TRACE %s:%d %lu %p (%#jx %b)\n", __func__, __LINE__, \
+ jiffies, _n, (uintmax_t)(_n)->state, \
+ (int)(_n)->state, LKPI_NAPI_FLAGS)
+#define NAPI_TRACE2D(_n, _d) if (debug_napi & DNAPI_TRACE) \
+ printf("NAPI_TRACE %s:%d %lu %p (%#jx %b) %d\n", __func__, __LINE__, \
+ jiffies, _n, (uintmax_t)(_n)->state, \
+ (int)(_n)->state, LKPI_NAPI_FLAGS, _d)
+#define NAPI_TRACE_TASK(_n, _p, _c) if (debug_napi & DNAPI_TRACE_TASK) \
+ printf("NAPI_TRACE %s:%d %lu %p (%#jx %b) pending %d count %d " \
+ "rx_count %d\n", __func__, __LINE__, \
+ jiffies, _n, (uintmax_t)(_n)->state, \
+ (int)(_n)->state, LKPI_NAPI_FLAGS, _p, _c, (_n)->rx_count)
+#define NAPI_TODO() if (debug_napi & DNAPI_TODO) \
+ printf("NAPI_TODO %s:%d %lu\n", __func__, __LINE__, jiffies)
+#define NAPI_IMPROVE() if (debug_napi & DNAPI_IMPROVE) \
+ printf("NAPI_IMPROVE %s:%d %lu\n", __func__, __LINE__, jiffies)
+
+#define NAPI_DIRECT_DISPATCH() ((debug_napi & DNAPI_DIRECT_DISPATCH) != 0)
+#else
+#define NAPI_TRACE(_n) do { } while(0)
+#define NAPI_TRACE2D(_n, _d) do { } while(0)
+#define NAPI_TRACE_TASK(_n, _p, _c) do { } while(0)
+#define NAPI_TODO() do { } while(0)
+#define NAPI_IMPROVE() do { } while(0)
+
+#define NAPI_DIRECT_DISPATCH() (0)
+#endif
+
+/* -------------------------------------------------------------------------- */
+
+/*
+ * Check if a poll is running or can run and and if the latter
+ * make us as running. That way we ensure that only one poll
+ * can only ever run at the same time. Returns true if no poll
+ * was scheduled yet.
+ */
+bool
+linuxkpi_napi_schedule_prep(struct napi_struct *napi)
+{
+ unsigned long old, new;
+
+ NAPI_TRACE(napi);
+
+ /* Can can only update/return if all flags agree. */
+ do {
+ old = READ_ONCE(napi->state);
+
+ /* If we are stopping, cannot run again. */
+ if ((old & BIT(LKPI_NAPI_FLAG_DISABLE_PENDING)) != 0) {
+ NAPI_TRACE(napi);
+ return (false);
+ }
+
+ new = old;
+ /* We were already scheduled. Need to try again? */
+ if ((old & BIT(LKPI_NAPI_FLAG_IS_SCHEDULED)) != 0)
+ new |= BIT(LKPI_NAPI_FLAG_LOST_RACE_TRY_AGAIN);
+ new |= BIT(LKPI_NAPI_FLAG_IS_SCHEDULED);
+
+ } while (atomic_cmpset_acq_long(&napi->state, old, new) == 0);
+
+ NAPI_TRACE(napi);
+ return ((old & BIT(LKPI_NAPI_FLAG_IS_SCHEDULED)) == 0);
+}
+
+static void
+lkpi___napi_schedule_dd(struct napi_struct *napi)
+{
+ unsigned long old, new;
+ int rc;
+
+ rc = 0;
+again:
+ NAPI_TRACE2D(napi, rc);
+ if (napi->poll != NULL)
+ rc = napi->poll(napi, napi->budget);
+ napi->rx_count += rc;
+
+ /* Check if interrupts are still disabled, more work to do. */
+ /* Bandaid for now. */
+ if (rc >= napi->budget)
+ goto again;
+
+ /* Bandaid for now. */
+ if (test_bit(LKPI_NAPI_FLAG_LOST_RACE_TRY_AGAIN, &napi->state))
+ goto again;
+
+ do {
+ new = old = READ_ONCE(napi->state);
+ clear_bit(LKPI_NAPI_FLAG_LOST_RACE_TRY_AGAIN, &new);
+ clear_bit(LKPI_NAPI_FLAG_IS_SCHEDULED, &new);
+ } while (atomic_cmpset_acq_long(&napi->state, old, new) == 0);
+
+ NAPI_TRACE2D(napi, rc);
+}
+
+void
+linuxkpi___napi_schedule(struct napi_struct *napi)
+{
+ int rc;
+
+ NAPI_TRACE(napi);
+ if (test_bit(LKPI_NAPI_FLAG_SHUTDOWN, &napi->state)) {
+ clear_bit(LKPI_NAPI_FLAG_LOST_RACE_TRY_AGAIN, &napi->state);
+ clear_bit(LKPI_NAPI_FLAG_IS_SCHEDULED, &napi->state);
+ NAPI_TRACE(napi);
+ return;
+ }
+
+ if (NAPI_DIRECT_DISPATCH()) {
+ lkpi___napi_schedule_dd(napi);
+ } else {
+ rc = taskqueue_enqueue(napi->dev->napi_tq, &napi->napi_task);
+ NAPI_TRACE2D(napi, rc);
+ if (rc != 0) {
+ /* Should we assert EPIPE? */
+ return;
+ }
+ }
+}
+
+bool
+linuxkpi_napi_schedule(struct napi_struct *napi)
+{
+
+ NAPI_TRACE(napi);
+
+ /*
+ * iwlwifi calls this sequence instead of napi_schedule()
+ * to be able to test the prep result.
+ */
+ if (napi_schedule_prep(napi)) {
+ __napi_schedule(napi);
+ return (true);
+ }
+
+ return (false);
+}
+
+void
+linuxkpi_napi_reschedule(struct napi_struct *napi)
+{
+
+ NAPI_TRACE(napi);
+
+ /* Not sure what is different to napi_schedule yet. */
+ if (napi_schedule_prep(napi))
+ __napi_schedule(napi);
+}
+
+bool
+linuxkpi_napi_complete_done(struct napi_struct *napi, int ret)
+{
+ unsigned long old, new;
+
+ NAPI_TRACE(napi);
+ if (NAPI_DIRECT_DISPATCH())
+ return (true);
+
+ do {
+ new = old = READ_ONCE(napi->state);
+
+ /*
+ * If we lost a race before, we need to re-schedule.
+ * Leave IS_SCHEDULED set essentially doing "_prep".
+ */
+ if (!test_bit(LKPI_NAPI_FLAG_LOST_RACE_TRY_AGAIN, &old))
+ clear_bit(LKPI_NAPI_FLAG_IS_SCHEDULED, &new);
+ clear_bit(LKPI_NAPI_FLAG_LOST_RACE_TRY_AGAIN, &new);
+ } while (atomic_cmpset_acq_long(&napi->state, old, new) == 0);
+
+ NAPI_TRACE(napi);
+
+ /* Someone tried to schedule while poll was running. Re-sched. */
+ if (test_bit(LKPI_NAPI_FLAG_LOST_RACE_TRY_AGAIN, &old)) {
+ __napi_schedule(napi);
+ return (false);
+ }
+
+ return (true);
+}
+
+bool
+linuxkpi_napi_complete(struct napi_struct *napi)
+{
+
+ NAPI_TRACE(napi);
+ return (napi_complete_done(napi, 0));
+}
+
+void
+linuxkpi_napi_disable(struct napi_struct *napi)
+{
+ NAPI_TRACE(napi);
+ set_bit(LKPI_NAPI_FLAG_DISABLE_PENDING, &napi->state);
+ while (test_bit(LKPI_NAPI_FLAG_IS_SCHEDULED, &napi->state))
+ pause_sbt("napidslp", SBT_1MS, 0, C_HARDCLOCK);
+ clear_bit(LKPI_NAPI_FLAG_DISABLE_PENDING, &napi->state);
+}
+
+void
+linuxkpi_napi_enable(struct napi_struct *napi)
+{
+
+ NAPI_TRACE(napi);
+ KASSERT(!test_bit(LKPI_NAPI_FLAG_IS_SCHEDULED, &napi->state),
+ ("%s: enabling napi %p already scheduled\n", __func__, napi));
+ mb();
+ /* Let us be scheduled. */
+ clear_bit(LKPI_NAPI_FLAG_IS_SCHEDULED, &napi->state);
+}
+
+void
+linuxkpi_napi_synchronize(struct napi_struct *napi)
+{
+ NAPI_TRACE(napi);
+#if defined(SMP)
+ /* Check & sleep while a napi is scheduled. */
+ while (test_bit(LKPI_NAPI_FLAG_IS_SCHEDULED, &napi->state))
+ pause_sbt("napisslp", SBT_1MS, 0, C_HARDCLOCK);
+#else
+ mb();
+#endif
+}
+
+/* -------------------------------------------------------------------------- */
+
+static void
+lkpi_napi_task(void *ctx, int pending)
+{
+ struct napi_struct *napi;
+ int count;
+
+ KASSERT(ctx != NULL, ("%s: napi %p, pending %d\n",
+ __func__, ctx, pending));
+ napi = ctx;
+ KASSERT(napi->poll != NULL, ("%s: napi %p poll is NULL\n",
+ __func__, napi));
+
+ NAPI_TRACE_TASK(napi, pending, napi->budget);
+ count = napi->poll(napi, napi->budget);
+ napi->rx_count += count;
+ NAPI_TRACE_TASK(napi, pending, count);
+
+ /*
+ * We must not check against count < pending here. There are situations
+ * when a driver may "poll" and we may not have any work to do and that
+ * would make us re-schedule ourseless for ever.
+ */
+ if (count >= napi->budget) {
+ /*
+ * Have to re-schedule ourselves. napi_complete() was not run
+ * in this case which means we are still SCHEDULED.
+ * In order to queue another task we have to directly call
+ * __napi_schedule() without _prep() in the way.
+ */
+ __napi_schedule(napi);
+ }
+}
+
+/* -------------------------------------------------------------------------- */
+
+void
+linuxkpi_netif_napi_add(struct net_device *ndev, struct napi_struct *napi,
+ int(*napi_poll)(struct napi_struct *, int))
+{
+
+ napi->dev = ndev;
+ napi->poll = napi_poll;
+ napi->budget = NAPI_POLL_WEIGHT;
+
+ INIT_LIST_HEAD(&napi->rx_list);
+ napi->rx_count = 0;
+
+ TASK_INIT(&napi->napi_task, 0, lkpi_napi_task, napi);
+
+ NAPI_LOCK(ndev);
+ TAILQ_INSERT_TAIL(&ndev->napi_head, napi, entry);
+ NAPI_UNLOCK(ndev);
+
+ /* Anything else to do on the ndev? */
+ clear_bit(LKPI_NAPI_FLAG_SHUTDOWN, &napi->state);
+}
+
+static void
+lkpi_netif_napi_del_locked(struct napi_struct *napi)
+{
+ struct net_device *ndev;
+
+ ndev = napi->dev;
+ NAPI_LOCK_ASSERT(ndev);
+
+ set_bit(LKPI_NAPI_FLAG_SHUTDOWN, &napi->state);
+ TAILQ_REMOVE(&ndev->napi_head, napi, entry);
+ while (taskqueue_cancel(ndev->napi_tq, &napi->napi_task, NULL) != 0)
+ taskqueue_drain(ndev->napi_tq, &napi->napi_task);
+}
+
+void
+linuxkpi_netif_napi_del(struct napi_struct *napi)
+{
+ struct net_device *ndev;
+
+ ndev = napi->dev;
+ NAPI_LOCK(ndev);
+ lkpi_netif_napi_del_locked(napi);
+ NAPI_UNLOCK(ndev);
+}
+
+/* -------------------------------------------------------------------------- */
+
+void
+linuxkpi_init_dummy_netdev(struct net_device *ndev)
+{
+
+ memset(ndev, 0, sizeof(*ndev));
+
+ ndev->reg_state = NETREG_DUMMY;
+ NAPI_LOCK_INIT(ndev);
+ TAILQ_INIT(&ndev->napi_head);
+ /* Anything else? */
+
+ ndev->napi_tq = taskqueue_create("tq_ndev_napi", M_WAITOK,
+ taskqueue_thread_enqueue, &ndev->napi_tq);
+ /* One thread for now. */
+ (void) taskqueue_start_threads(&ndev->napi_tq, 1, PWAIT,
+ "ndev napi taskq");
+}
+
+struct net_device *
+linuxkpi_alloc_netdev(size_t len, const char *name, uint32_t flags,
+ void(*setup_func)(struct net_device *))
+{
+ struct net_device *ndev;
+
+ ndev = malloc(sizeof(*ndev) + len, M_NETDEV, M_NOWAIT);
+ if (ndev == NULL)
+ return (ndev);
+
+ /* Always first as it zeros! */
+ linuxkpi_init_dummy_netdev(ndev);
+
+ strlcpy(ndev->name, name, sizeof(*ndev->name));
+
+ /* This needs extending as we support more. */
+
+ if (setup_func != NULL)
+ setup_func(ndev);
+
+ return (ndev);
+}
+
+void
+linuxkpi_free_netdev(struct net_device *ndev)
+{
+ struct napi_struct *napi, *temp;
+
+ NAPI_LOCK(ndev);
+ TAILQ_FOREACH_SAFE(napi, &ndev->napi_head, entry, temp) {
+ lkpi_netif_napi_del_locked(napi);
+ }
+ NAPI_UNLOCK(ndev);
+
+ taskqueue_free(ndev->napi_tq);
+ ndev->napi_tq = NULL;
+ NAPI_LOCK_DESTROY(ndev);
+
+ /* This needs extending as we support more. */
+
+ free(ndev, M_NETDEV);
+}
diff --git a/sys/compat/linuxkpi/common/src/linux_page.c b/sys/compat/linuxkpi/common/src/linux_page.c
index 3c8bc2bd3c5b..628af17df853 100644
--- a/sys/compat/linuxkpi/common/src/linux_page.c
+++ b/sys/compat/linuxkpi/common/src/linux_page.c
@@ -26,9 +26,6 @@
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
-#include <sys/cdefs.h>
-__FBSDID("$FreeBSD$");
-
#include <sys/param.h>
#include <sys/systm.h>
#include <sys/malloc.h>
@@ -39,6 +36,7 @@ __FBSDID("$FreeBSD$");
#include <sys/rwlock.h>
#include <sys/proc.h>
#include <sys/sched.h>
+#include <sys/memrange.h>
#include <machine/bus.h>
@@ -63,32 +61,44 @@ __FBSDID("$FreeBSD$");
#include <linux/preempt.h>
#include <linux/fs.h>
#include <linux/shmem_fs.h>
+#include <linux/kernel.h>
+#include <linux/idr.h>
+#include <linux/io.h>
+#include <linux/io-mapping.h>
+
+#ifdef __i386__
+DEFINE_IDR(mtrr_idr);
+static MALLOC_DEFINE(M_LKMTRR, "idr", "Linux MTRR compat");
+extern int pat_works;
+#endif
void
si_meminfo(struct sysinfo *si)
{
si->totalram = physmem;
+ si->freeram = vm_free_count();
si->totalhigh = 0;
+ si->freehigh = 0;
si->mem_unit = PAGE_SIZE;
}
void *
-linux_page_address(struct page *page)
+linux_page_address(const struct page *page)
{
if (page->object != kernel_object) {
return (PMAP_HAS_DMAP ?
- ((void *)(uintptr_t)PHYS_TO_DMAP(VM_PAGE_TO_PHYS(page))) :
+ ((void *)(uintptr_t)PHYS_TO_DMAP(page_to_phys(page))) :
NULL);
}
return ((void *)(uintptr_t)(VM_MIN_KERNEL_ADDRESS +
IDX_TO_OFF(page->pindex)));
}
-vm_page_t
+struct page *
linux_alloc_pages(gfp_t flags, unsigned int order)
{
- vm_page_t page;
+ struct page *page;
if (PMAP_HAS_DMAP) {
unsigned long npages = 1UL << order;
@@ -96,6 +106,7 @@ linux_alloc_pages(gfp_t flags, unsigned int order)
if ((flags & M_ZERO) != 0)
req |= VM_ALLOC_ZERO;
+
if (order == 0 && (flags & GFP_DMA32) == 0) {
page = vm_page_alloc_noobj(req);
if (page == NULL)
@@ -103,15 +114,22 @@ linux_alloc_pages(gfp_t flags, unsigned int order)
} else {
vm_paddr_t pmax = (flags & GFP_DMA32) ?
BUS_SPACE_MAXADDR_32BIT : BUS_SPACE_MAXADDR;
+
+ if ((flags & __GFP_NORETRY) != 0)
+ req |= VM_ALLOC_NORECLAIM;
+
retry:
page = vm_page_alloc_noobj_contig(req, npages, 0, pmax,
PAGE_SIZE, 0, VM_MEMATTR_DEFAULT);
if (page == NULL) {
- if (flags & M_WAITOK) {
- if (!vm_page_reclaim_contig(req,
- npages, 0, pmax, PAGE_SIZE, 0)) {
+ if ((flags & (M_WAITOK | __GFP_NORETRY)) ==
+ M_WAITOK) {
+ int err = vm_page_reclaim_contig(req,
+ npages, 0, pmax, PAGE_SIZE, 0);
+ if (err == ENOMEM)
vm_wait(NULL);
- }
+ else if (err != 0)
+ return (NULL);
flags &= ~M_WAITOK;
goto retry;
}
@@ -125,7 +143,7 @@ linux_alloc_pages(gfp_t flags, unsigned int order)
if (vaddr == 0)
return (NULL);
- page = PHYS_TO_VM_PAGE(vtophys((void *)vaddr));
+ page = virt_to_page((void *)vaddr);
KASSERT(vaddr == (vm_offset_t)page_address(page),
("Page address mismatch"));
@@ -134,8 +152,16 @@ linux_alloc_pages(gfp_t flags, unsigned int order)
return (page);
}
+static void
+_linux_free_kmem(vm_offset_t addr, unsigned int order)
+{
+ size_t size = ((size_t)PAGE_SIZE) << order;
+
+ kmem_free((void *)addr, size);
+}
+
void
-linux_free_pages(vm_page_t page, unsigned int order)
+linux_free_pages(struct page *page, unsigned int order)
{
if (PMAP_HAS_DMAP) {
unsigned long npages = 1UL << order;
@@ -144,39 +170,72 @@ linux_free_pages(vm_page_t page, unsigned int order)
for (x = 0; x != npages; x++) {
vm_page_t pgo = page + x;
- if (vm_page_unwire_noq(pgo))
- vm_page_free(pgo);
+ /*
+ * The "free page" function is used in several
+ * contexts.
+ *
+ * Some pages are allocated by `linux_alloc_pages()`
+ * above, but not all of them are. For instance in the
+ * DRM drivers, some pages come from
+ * `shmem_read_mapping_page_gfp()`.
+ *
+ * That's why we need to check if the page is managed
+ * or not here.
+ */
+ if ((pgo->oflags & VPO_UNMANAGED) == 0) {
+ vm_page_unwire(pgo, PQ_ACTIVE);
+ } else {
+ if (vm_page_unwire_noq(pgo))
+ vm_page_free(pgo);
+ }
}
} else {
vm_offset_t vaddr;
vaddr = (vm_offset_t)page_address(page);
- linux_free_kmem(vaddr, order);
+ _linux_free_kmem(vaddr, order);
}
}
+void
+linux_release_pages(release_pages_arg arg, int nr)
+{
+ int i;
+
+ CTASSERT(offsetof(struct folio, page) == 0);
+
+ for (i = 0; i < nr; i++)
+ __free_page(arg.pages[i]);
+}
+
vm_offset_t
linux_alloc_kmem(gfp_t flags, unsigned int order)
{
size_t size = ((size_t)PAGE_SIZE) << order;
- vm_offset_t addr;
+ void *addr;
- if ((flags & GFP_DMA32) == 0) {
- addr = kmem_malloc(size, flags & GFP_NATIVE_MASK);
- } else {
- addr = kmem_alloc_contig(size, flags & GFP_NATIVE_MASK, 0,
- BUS_SPACE_MAXADDR_32BIT, PAGE_SIZE, 0, VM_MEMATTR_DEFAULT);
- }
- return (addr);
+ addr = kmem_alloc_contig(size, flags & GFP_NATIVE_MASK, 0,
+ ((flags & GFP_DMA32) == 0) ? -1UL : BUS_SPACE_MAXADDR_32BIT,
+ PAGE_SIZE, 0, VM_MEMATTR_DEFAULT);
+
+ return ((vm_offset_t)addr);
}
void
linux_free_kmem(vm_offset_t addr, unsigned int order)
{
- size_t size = ((size_t)PAGE_SIZE) << order;
+ KASSERT((addr & ~PAGE_MASK) == 0,
+ ("%s: addr %p is not page aligned", __func__, (void *)addr));
+
+ if (addr >= VM_MIN_KERNEL_ADDRESS && addr < VM_MAX_KERNEL_ADDRESS) {
+ _linux_free_kmem(addr, order);
+ } else {
+ vm_page_t page;
- kmem_free(addr, size);
+ page = PHYS_TO_VM_PAGE(DMAP_TO_PHYS(addr));
+ linux_free_pages(page, order);
+ }
}
static int
@@ -238,7 +297,7 @@ __get_user_pages_fast(unsigned long start, int nr_pages, int write,
long
get_user_pages_remote(struct task_struct *task, struct mm_struct *mm,
- unsigned long start, unsigned long nr_pages, int gup_flags,
+ unsigned long start, unsigned long nr_pages, unsigned int gup_flags,
struct page **pages, struct vm_area_struct **vmas)
{
vm_map_t map;
@@ -249,8 +308,8 @@ get_user_pages_remote(struct task_struct *task, struct mm_struct *mm,
}
long
-get_user_pages(unsigned long start, unsigned long nr_pages, int gup_flags,
- struct page **pages, struct vm_area_struct **vmas)
+lkpi_get_user_pages(unsigned long start, unsigned long nr_pages,
+ unsigned int gup_flags, struct page **pages)
{
vm_map_t map;
@@ -269,23 +328,27 @@ vm_fault_t
lkpi_vmf_insert_pfn_prot_locked(struct vm_area_struct *vma, unsigned long addr,
unsigned long pfn, pgprot_t prot)
{
+ struct pctrie_iter pages;
vm_object_t vm_obj = vma->vm_obj;
vm_object_t tmp_obj;
vm_page_t page;
vm_pindex_t pindex;
VM_OBJECT_ASSERT_WLOCKED(vm_obj);
+ vm_page_iter_init(&pages, vm_obj);
pindex = OFF_TO_IDX(addr - vma->vm_start);
if (vma->vm_pfn_count == 0)
vma->vm_pfn_first = pindex;
MPASS(pindex <= OFF_TO_IDX(vma->vm_end));
retry:
- page = vm_page_grab(vm_obj, pindex, VM_ALLOC_NOCREAT);
+ page = vm_page_grab_iter(vm_obj, pindex, VM_ALLOC_NOCREAT, &pages);
if (page == NULL) {
page = PHYS_TO_VM_PAGE(IDX_TO_OFF(pfn));
- if (!vm_page_busy_acquire(page, VM_ALLOC_WAITFAIL))
+ if (!vm_page_busy_acquire(page, VM_ALLOC_WAITFAIL)) {
+ pctrie_iter_reset(&pages);
goto retry;
+ }
if (page->object != NULL) {
tmp_obj = page->object;
vm_page_xunbusy(page);
@@ -309,10 +372,11 @@ retry:
vm_page_remove(page);
}
VM_OBJECT_WUNLOCK(tmp_obj);
+ pctrie_iter_reset(&pages);
VM_OBJECT_WLOCK(vm_obj);
goto retry;
}
- if (vm_page_insert(page, vm_obj, pindex)) {
+ if (vm_page_iter_insert(page, vm_obj, pindex, &pages) != 0) {
vm_page_xunbusy(page);
return (VM_FAULT_OOM);
}
@@ -324,6 +388,63 @@ retry:
return (VM_FAULT_NOPAGE);
}
+int
+lkpi_remap_pfn_range(struct vm_area_struct *vma, unsigned long start_addr,
+ unsigned long start_pfn, unsigned long size, pgprot_t prot)
+{
+ vm_object_t vm_obj;
+ unsigned long addr, pfn;
+ int err = 0;
+
+ vm_obj = vma->vm_obj;
+
+ VM_OBJECT_WLOCK(vm_obj);
+ for (addr = start_addr, pfn = start_pfn;
+ addr < start_addr + size;
+ addr += PAGE_SIZE) {
+ vm_fault_t ret;
+retry:
+ ret = lkpi_vmf_insert_pfn_prot_locked(vma, addr, pfn, prot);
+
+ if ((ret & VM_FAULT_OOM) != 0) {
+ VM_OBJECT_WUNLOCK(vm_obj);
+ vm_wait(NULL);
+ VM_OBJECT_WLOCK(vm_obj);
+ goto retry;
+ }
+
+ if ((ret & VM_FAULT_ERROR) != 0) {
+ err = -EFAULT;
+ break;
+ }
+
+ pfn++;
+ }
+ VM_OBJECT_WUNLOCK(vm_obj);
+
+ if (unlikely(err)) {
+ zap_vma_ptes(vma, start_addr,
+ (pfn - start_pfn) << PAGE_SHIFT);
+ return (err);
+ }
+
+ return (0);
+}
+
+int
+lkpi_io_mapping_map_user(struct io_mapping *iomap,
+ struct vm_area_struct *vma, unsigned long addr,
+ unsigned long pfn, unsigned long size)
+{
+ pgprot_t prot;
+ int ret;
+
+ prot = cachemode2protval(iomap->attr);
+ ret = lkpi_remap_pfn_range(vma, addr, pfn, size, prot);
+
+ return (ret);
+}
+
/*
* Although FreeBSD version of unmap_mapping_range has semantics and types of
* parameters compatible with Linux version, the values passed in are different
@@ -333,27 +454,122 @@ retry:
*/
void
lkpi_unmap_mapping_range(void *obj, loff_t const holebegin __unused,
- loff_t const holelen, int even_cows __unused)
+ loff_t const holelen __unused, int even_cows __unused)
{
vm_object_t devobj;
- vm_page_t page;
- int i, page_count;
devobj = cdev_pager_lookup(obj);
if (devobj != NULL) {
- page_count = OFF_TO_IDX(holelen);
+ cdev_mgtdev_pager_free_pages(devobj);
+ vm_object_deallocate(devobj);
+ }
+}
- VM_OBJECT_WLOCK(devobj);
-retry:
- for (i = 0; i < page_count; i++) {
- page = vm_page_lookup(devobj, i);
- if (page == NULL)
- continue;
- if (!vm_page_busy_acquire(page, VM_ALLOC_WAITFAIL))
- goto retry;
- cdev_pager_free_page(devobj, page);
+int
+lkpi_arch_phys_wc_add(unsigned long base, unsigned long size)
+{
+#ifdef __i386__
+ struct mem_range_desc *mrdesc;
+ int error, id, act;
+
+ /* If PAT is available, do nothing */
+ if (pat_works)
+ return (0);
+
+ mrdesc = malloc(sizeof(*mrdesc), M_LKMTRR, M_WAITOK);
+ mrdesc->mr_base = base;
+ mrdesc->mr_len = size;
+ mrdesc->mr_flags = MDF_WRITECOMBINE;
+ strlcpy(mrdesc->mr_owner, "drm", sizeof(mrdesc->mr_owner));
+ act = MEMRANGE_SET_UPDATE;
+ error = mem_range_attr_set(mrdesc, &act);
+ if (error == 0) {
+ error = idr_get_new(&mtrr_idr, mrdesc, &id);
+ MPASS(idr_find(&mtrr_idr, id) == mrdesc);
+ if (error != 0) {
+ act = MEMRANGE_SET_REMOVE;
+ mem_range_attr_set(mrdesc, &act);
}
- VM_OBJECT_WUNLOCK(devobj);
- vm_object_deallocate(devobj);
}
+ if (error != 0) {
+ free(mrdesc, M_LKMTRR);
+ pr_warn(
+ "Failed to add WC MTRR for [%p-%p]: %d; "
+ "performance may suffer\n",
+ (void *)base, (void *)(base + size - 1), error);
+ } else
+ pr_warn("Successfully added WC MTRR for [%p-%p]\n",
+ (void *)base, (void *)(base + size - 1));
+
+ return (error != 0 ? -error : id + __MTRR_ID_BASE);
+#else
+ return (0);
+#endif
+}
+
+void
+lkpi_arch_phys_wc_del(int reg)
+{
+#ifdef __i386__
+ struct mem_range_desc *mrdesc;
+ int act;
+
+ /* Check if arch_phys_wc_add() failed. */
+ if (reg < __MTRR_ID_BASE)
+ return;
+
+ mrdesc = idr_find(&mtrr_idr, reg - __MTRR_ID_BASE);
+ MPASS(mrdesc != NULL);
+ idr_remove(&mtrr_idr, reg - __MTRR_ID_BASE);
+ act = MEMRANGE_SET_REMOVE;
+ mem_range_attr_set(mrdesc, &act);
+ free(mrdesc, M_LKMTRR);
+#endif
+}
+
+/*
+ * This is a highly simplified version of the Linux page_frag_cache.
+ * We only support up-to 1 single page as fragment size and we will
+ * always return a full page. This may be wasteful on small objects
+ * but the only known consumer (mt76) is either asking for a half-page
+ * or a full page. If this was to become a problem we can implement
+ * a more elaborate version.
+ */
+void *
+linuxkpi_page_frag_alloc(struct page_frag_cache *pfc,
+ size_t fragsz, gfp_t gfp)
+{
+ vm_page_t pages;
+
+ if (fragsz == 0)
+ return (NULL);
+
+ KASSERT(fragsz <= PAGE_SIZE, ("%s: fragsz %zu > PAGE_SIZE not yet "
+ "supported", __func__, fragsz));
+
+ pages = alloc_pages(gfp, flsl(howmany(fragsz, PAGE_SIZE) - 1));
+ if (pages == NULL)
+ return (NULL);
+ pfc->va = linux_page_address(pages);
+
+ /* Passed in as "count" to __page_frag_cache_drain(). Unused by us. */
+ pfc->pagecnt_bias = 0;
+
+ return (pfc->va);
+}
+
+void
+linuxkpi_page_frag_free(void *addr)
+{
+ vm_page_t page;
+
+ page = virt_to_page(addr);
+ linux_free_pages(page, 0);
+}
+
+void
+linuxkpi__page_frag_cache_drain(struct page *page, size_t count __unused)
+{
+
+ linux_free_pages(page, 0);
}
diff --git a/sys/compat/linuxkpi/common/src/linux_pci.c b/sys/compat/linuxkpi/common/src/linux_pci.c
index bf28c10fbf96..8507a59a8df3 100644
--- a/sys/compat/linuxkpi/common/src/linux_pci.c
+++ b/sys/compat/linuxkpi/common/src/linux_pci.c
@@ -1,7 +1,7 @@
/*-
* Copyright (c) 2015-2016 Mellanox Technologies, Ltd.
* All rights reserved.
- * Copyright (c) 2020-2021 The FreeBSD Foundation
+ * Copyright (c) 2020-2025 The FreeBSD Foundation
*
* Portions of this software were developed by Björn Zeeb
* under sponsorship from the FreeBSD Foundation.
@@ -28,9 +28,6 @@
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
-#include <sys/cdefs.h>
-__FBSDID("$FreeBSD$");
-
#include <sys/param.h>
#include <sys/systm.h>
#include <sys/bus.h>
@@ -44,18 +41,22 @@ __FBSDID("$FreeBSD$");
#include <sys/filio.h>
#include <sys/pciio.h>
#include <sys/pctrie.h>
+#include <sys/rman.h>
#include <sys/rwlock.h>
+#include <sys/stdarg.h>
#include <vm/vm.h>
#include <vm/pmap.h>
-#include <machine/stdarg.h>
+#include <machine/bus.h>
+#include <machine/resource.h>
#include <dev/pci/pcivar.h>
#include <dev/pci/pci_private.h>
#include <dev/pci/pci_iov.h>
#include <dev/backlight/backlight.h>
+#include <linux/kernel.h>
#include <linux/kobject.h>
#include <linux/device.h>
#include <linux/slab.h>
@@ -66,6 +67,7 @@ __FBSDID("$FreeBSD$");
#include <linux/mm.h>
#include <linux/io.h>
#include <linux/vmalloc.h>
+#define WANT_NATIVE_PCI_GET_SLOT
#include <linux/pci.h>
#include <linux/compat.h>
@@ -77,6 +79,14 @@ __FBSDID("$FreeBSD$");
/* Undef the linux function macro defined in linux/pci.h */
#undef pci_get_class
+extern int linuxkpi_debug;
+
+SYSCTL_DECL(_compat_linuxkpi);
+
+static counter_u64_t lkpi_pci_nseg1_fail;
+SYSCTL_COUNTER_U64(_compat_linuxkpi, OID_AUTO, lkpi_pci_nseg1_fail, CTLFLAG_RD,
+ &lkpi_pci_nseg1_fail, "Count of busdma mapping failures of single-segment");
+
static device_probe_t linux_pci_probe;
static device_attach_t linux_pci_attach;
static device_detach_t linux_pci_detach;
@@ -89,6 +99,7 @@ static pci_iov_add_vf_t linux_pci_iov_add_vf;
static int linux_backlight_get_status(device_t dev, struct backlight_props *props);
static int linux_backlight_update_status(device_t dev, struct backlight_props *props);
static int linux_backlight_get_info(device_t dev, struct backlight_info *info);
+static void lkpi_pcim_iomap_table_release(struct device *, void *);
static device_method_t pci_methods[] = {
DEVMETHOD(device_probe, linux_pci_probe),
@@ -101,6 +112,9 @@ static device_method_t pci_methods[] = {
DEVMETHOD(pci_iov_uninit, linux_pci_iov_uninit),
DEVMETHOD(pci_iov_add_vf, linux_pci_iov_add_vf),
+ /* Bus interface. */
+ DEVMETHOD(bus_add_child, bus_generic_add_child),
+
/* backlight interface */
DEVMETHOD(backlight_update_status, linux_backlight_update_status),
DEVMETHOD(backlight_get_status, linux_backlight_get_status),
@@ -108,6 +122,22 @@ static device_method_t pci_methods[] = {
DEVMETHOD_END
};
+const char *pci_power_names[] = {
+ "UNKNOWN", "D0", "D1", "D2", "D3hot", "D3cold"
+};
+
+/* We need some meta-struct to keep track of these for devres. */
+struct pci_devres {
+ bool enable_io;
+ /* PCIR_MAX_BAR_0 + 1 = 6 => BIT(0..5). */
+ uint8_t region_mask;
+ struct resource *region_table[PCIR_MAX_BAR_0 + 1]; /* Not needed. */
+};
+struct pcim_iomap_devres {
+ void *mmio_table[PCIR_MAX_BAR_0 + 1];
+ struct resource *res_table[PCIR_MAX_BAR_0 + 1];
+};
+
struct linux_dma_priv {
uint64_t dma_mask;
bus_dma_tag_t dmat;
@@ -119,6 +149,23 @@ struct linux_dma_priv {
#define DMA_PRIV_LOCK(priv) mtx_lock(&(priv)->lock)
#define DMA_PRIV_UNLOCK(priv) mtx_unlock(&(priv)->lock)
+static void
+lkpi_set_pcim_iomap_devres(struct pcim_iomap_devres *dr, int bar,
+ void *res)
+{
+ dr->mmio_table[bar] = (void *)rman_get_bushandle(res);
+ dr->res_table[bar] = res;
+}
+
+static bool
+lkpi_pci_bar_id_valid(int bar)
+{
+ if (bar < 0 || bar > PCIR_MAX_BAR_0)
+ return (false);
+
+ return (true);
+}
+
static int
linux_pdev_dma_uninit(struct pci_dev *pdev)
{
@@ -258,6 +305,33 @@ linux_pci_find(device_t dev, const struct pci_device_id **idp)
return (NULL);
}
+struct pci_dev *
+lkpi_pci_get_device(uint32_t vendor, uint32_t device, struct pci_dev *odev)
+{
+ struct pci_dev *pdev, *found;
+
+ found = NULL;
+ spin_lock(&pci_lock);
+ list_for_each_entry(pdev, &pci_devices, links) {
+ /* Walk until we find odev. */
+ if (odev != NULL) {
+ if (pdev == odev)
+ odev = NULL;
+ continue;
+ }
+
+ if ((pdev->vendor == vendor || vendor == PCI_ANY_ID) &&
+ (pdev->device == device || device == PCI_ANY_ID)) {
+ found = pdev;
+ break;
+ }
+ }
+ pci_dev_get(found);
+ spin_unlock(&pci_lock);
+
+ return (found);
+}
+
static void
lkpi_pci_dev_release(struct device *dev)
{
@@ -266,9 +340,19 @@ lkpi_pci_dev_release(struct device *dev)
spin_lock_destroy(&dev->devres_lock);
}
-static void
+static int
lkpifill_pci_dev(device_t dev, struct pci_dev *pdev)
{
+ struct pci_devinfo *dinfo;
+ int error;
+
+ error = kobject_init_and_add(&pdev->dev.kobj, &linux_dev_ktype,
+ &linux_root_device.kobj, device_get_nameunit(dev));
+ if (error != 0) {
+ printf("%s:%d: kobject_init_and_add returned %d\n",
+ __func__, __LINE__, error);
+ return (error);
+ }
pdev->devfn = PCI_DEVFN(pci_get_slot(dev), pci_get_function(dev));
pdev->vendor = pci_get_vendor(dev);
@@ -277,31 +361,60 @@ lkpifill_pci_dev(device_t dev, struct pci_dev *pdev)
pdev->subsystem_device = pci_get_subdevice(dev);
pdev->class = pci_get_class(dev);
pdev->revision = pci_get_revid(dev);
+ pdev->path_name = kasprintf(GFP_KERNEL, "%04d:%02d:%02d.%d",
+ pci_get_domain(dev), pci_get_bus(dev), pci_get_slot(dev),
+ pci_get_function(dev));
+
pdev->bus = malloc(sizeof(*pdev->bus), M_DEVBUF, M_WAITOK | M_ZERO);
- pdev->bus->self = pdev;
pdev->bus->number = pci_get_bus(dev);
pdev->bus->domain = pci_get_domain(dev);
+
+ /* Check if we have reached the root to satisfy pci_is_root_bus() */
+ dinfo = device_get_ivars(dev);
+ if (dinfo->cfg.pcie.pcie_location != 0 &&
+ dinfo->cfg.pcie.pcie_type == PCIEM_TYPE_ROOT_PORT) {
+ pdev->bus->self = NULL;
+ } else {
+ /*
+ * This should be the upstream bridge; pci_upstream_bridge()
+ * handles that case on demand as otherwise we'll shadow the
+ * entire PCI hierarchy.
+ */
+ pdev->bus->self = pdev;
+ }
pdev->dev.bsddev = dev;
pdev->dev.parent = &linux_root_device;
pdev->dev.release = lkpi_pci_dev_release;
INIT_LIST_HEAD(&pdev->dev.irqents);
- kobject_init(&pdev->dev.kobj, &linux_dev_ktype);
- kobject_set_name(&pdev->dev.kobj, device_get_nameunit(dev));
- kobject_add(&pdev->dev.kobj, &linux_root_device.kobj,
- kobject_name(&pdev->dev.kobj));
+
+ if (pci_msi_count(dev) > 0)
+ pdev->msi_desc = malloc(pci_msi_count(dev) *
+ sizeof(*pdev->msi_desc), M_DEVBUF, M_WAITOK | M_ZERO);
+
spin_lock_init(&pdev->dev.devres_lock);
INIT_LIST_HEAD(&pdev->dev.devres_head);
+
+ return (0);
}
static void
lkpinew_pci_dev_release(struct device *dev)
{
struct pci_dev *pdev;
+ int i;
pdev = to_pci_dev(dev);
if (pdev->root != NULL)
pci_dev_put(pdev->root);
+ if (pdev->bus->self != pdev && pdev->bus->self != NULL)
+ pci_dev_put(pdev->bus->self);
free(pdev->bus, M_DEVBUF);
+ if (pdev->msi_desc != NULL) {
+ for (i = pci_msi_count(pdev->dev.bsddev) - 1; i >= 0; i--)
+ free(pdev->msi_desc[i], M_DEVBUF);
+ free(pdev->msi_desc, M_DEVBUF);
+ }
+ kfree(pdev->path_name);
free(pdev, M_DEVBUF);
}
@@ -309,9 +422,14 @@ struct pci_dev *
lkpinew_pci_dev(device_t dev)
{
struct pci_dev *pdev;
+ int error;
pdev = malloc(sizeof(*pdev), M_DEVBUF, M_WAITOK|M_ZERO);
- lkpifill_pci_dev(dev, pdev);
+ error = lkpifill_pci_dev(dev, pdev);
+ if (error != 0) {
+ free(pdev, M_DEVBUF);
+ return (NULL);
+ }
pdev->dev.release = lkpinew_pci_dev_release;
return (pdev);
@@ -336,6 +454,24 @@ lkpi_pci_get_class(unsigned int class, struct pci_dev *from)
}
struct pci_dev *
+lkpi_pci_get_base_class(unsigned int baseclass, struct pci_dev *from)
+{
+ device_t dev;
+ device_t devfrom = NULL;
+ struct pci_dev *pdev;
+
+ if (from != NULL)
+ devfrom = from->dev.bsddev;
+
+ dev = pci_find_base_class_from(baseclass, devfrom);
+ if (dev == NULL)
+ return (NULL);
+
+ pdev = lkpinew_pci_dev(dev);
+ return (pdev);
+}
+
+struct pci_dev *
lkpi_pci_get_domain_bus_and_slot(int domain, unsigned int bus,
unsigned int devfn)
{
@@ -350,6 +486,20 @@ lkpi_pci_get_domain_bus_and_slot(int domain, unsigned int bus,
return (pdev);
}
+struct pci_dev *
+lkpi_pci_get_slot(struct pci_bus *pbus, unsigned int devfn)
+{
+ device_t dev;
+ struct pci_dev *pdev;
+
+ dev = pci_find_bsf(pbus->number, PCI_SLOT(devfn), PCI_FUNC(devfn));
+ if (dev == NULL)
+ return (NULL);
+
+ pdev = lkpinew_pci_dev(dev);
+ return (pdev);
+}
+
static int
linux_pci_probe(device_t dev)
{
@@ -361,7 +511,12 @@ linux_pci_probe(device_t dev)
if (device_get_driver(dev) != &pdrv->bsddriver)
return (ENXIO);
device_set_desc(dev, pdrv->name);
- return (0);
+
+ /* Assume BSS initialized (should never return BUS_PROBE_SPECIFIC). */
+ if (pdrv->bsd_probe_return == 0)
+ return (BUS_PROBE_DEFAULT);
+ else
+ return (pdrv->bsd_probe_return);
}
static int
@@ -380,12 +535,48 @@ linux_pci_attach(device_t dev)
return (linux_pci_attach_device(dev, pdrv, id, pdev));
}
+static struct resource_list_entry *
+linux_pci_reserve_bar(struct pci_dev *pdev, struct resource_list *rl,
+ int type, int rid)
+{
+ device_t dev;
+ struct resource *res;
+
+ KASSERT(type == SYS_RES_IOPORT || type == SYS_RES_MEMORY,
+ ("trying to reserve non-BAR type %d", type));
+
+ dev = pdev->pdrv != NULL && pdev->pdrv->isdrm ?
+ device_get_parent(pdev->dev.bsddev) : pdev->dev.bsddev;
+ res = pci_reserve_map(device_get_parent(dev), dev, type, &rid, 0, ~0,
+ 1, 1, 0);
+ if (res == NULL)
+ return (NULL);
+ return (resource_list_find(rl, type, rid));
+}
+
+static struct resource_list_entry *
+linux_pci_get_rle(struct pci_dev *pdev, int type, int rid, bool reserve_bar)
+{
+ struct pci_devinfo *dinfo;
+ struct resource_list *rl;
+ struct resource_list_entry *rle;
+
+ dinfo = device_get_ivars(pdev->dev.bsddev);
+ rl = &dinfo->resources;
+ rle = resource_list_find(rl, type, rid);
+ /* Reserve resources for this BAR if needed. */
+ if (rle == NULL && reserve_bar)
+ rle = linux_pci_reserve_bar(pdev, rl, type, rid);
+ return (rle);
+}
+
int
linux_pci_attach_device(device_t dev, struct pci_driver *pdrv,
const struct pci_device_id *id, struct pci_dev *pdev)
{
struct resource_list_entry *rle;
device_t parent;
+ struct pci_dev *pbus, *ppbus;
uintptr_t rid;
int error;
bool isdrm;
@@ -402,7 +593,10 @@ linux_pci_attach_device(device_t dev, struct pci_driver *pdrv,
device_set_ivars(dev, dinfo);
}
- lkpifill_pci_dev(dev, pdev);
+ error = lkpifill_pci_dev(dev, pdev);
+ if (error != 0)
+ return (error);
+
if (isdrm)
PCI_GET_ID(device_get_parent(parent), parent, PCI_ID_RID, &rid);
else
@@ -420,11 +614,33 @@ linux_pci_attach_device(device_t dev, struct pci_driver *pdrv,
goto out_dma_init;
TAILQ_INIT(&pdev->mmio);
+ spin_lock_init(&pdev->pcie_cap_lock);
spin_lock(&pci_lock);
list_add(&pdev->links, &pci_devices);
spin_unlock(&pci_lock);
+ /*
+ * Create the hierarchy now as we cannot on demand later.
+ * Take special care of DRM as there is a non-PCI device in the chain.
+ */
+ pbus = pdev;
+ if (isdrm) {
+ pbus = lkpinew_pci_dev(parent);
+ if (pbus == NULL) {
+ error = ENXIO;
+ goto out_dma_init;
+ }
+ }
+ pcie_find_root_port(pbus);
+ if (isdrm)
+ pdev->root = pbus->root;
+ ppbus = pci_upstream_bridge(pbus);
+ while (ppbus != NULL && ppbus != pbus) {
+ pbus = ppbus;
+ ppbus = pci_upstream_bridge(pbus);
+ }
+
if (pdrv != NULL) {
error = pdrv->probe(pdev, id);
if (error)
@@ -432,8 +648,10 @@ linux_pci_attach_device(device_t dev, struct pci_driver *pdrv,
}
return (0);
+/* XXX the cleanup does not match the allocation up there. */
out_probe:
free(pdev->bus, M_DEVBUF);
+ spin_lock_destroy(&pdev->pcie_cap_lock);
linux_pdev_dma_uninit(pdev);
out_dma_init:
spin_lock(&pci_lock);
@@ -474,6 +692,7 @@ linux_pci_detach_device(struct pci_dev *pdev)
spin_lock(&pci_lock);
list_del(&pdev->links);
spin_unlock(&pci_lock);
+ spin_lock_destroy(&pdev->pcie_cap_lock);
put_device(&pdev->dev);
return (0);
@@ -488,6 +707,31 @@ lkpi_pci_disable_dev(struct device *dev)
return (0);
}
+static struct pci_devres *
+lkpi_pci_devres_get_alloc(struct pci_dev *pdev)
+{
+ struct pci_devres *dr;
+
+ dr = lkpi_devres_find(&pdev->dev, lkpi_pci_devres_release, NULL, NULL);
+ if (dr == NULL) {
+ dr = lkpi_devres_alloc(lkpi_pci_devres_release, sizeof(*dr),
+ GFP_KERNEL | __GFP_ZERO);
+ if (dr != NULL)
+ lkpi_devres_add(&pdev->dev, dr);
+ }
+
+ return (dr);
+}
+
+static struct pci_devres *
+lkpi_pci_devres_find(struct pci_dev *pdev)
+{
+ if (!pdev->managed)
+ return (NULL);
+
+ return (lkpi_pci_devres_get_alloc(pdev));
+}
+
void
lkpi_pci_devres_release(struct device *dev, void *p)
{
@@ -516,7 +760,242 @@ lkpi_pci_devres_release(struct device *dev, void *p)
}
}
+int
+linuxkpi_pcim_enable_device(struct pci_dev *pdev)
+{
+ struct pci_devres *dr;
+ int error;
+
+ /* Here we cannot run through the pdev->managed check. */
+ dr = lkpi_pci_devres_get_alloc(pdev);
+ if (dr == NULL)
+ return (-ENOMEM);
+
+ /* If resources were enabled before do not do it again. */
+ if (dr->enable_io)
+ return (0);
+
+ error = pci_enable_device(pdev);
+ if (error == 0)
+ dr->enable_io = true;
+
+ /* This device is not managed. */
+ pdev->managed = true;
+
+ return (error);
+}
+
+static struct pcim_iomap_devres *
+lkpi_pcim_iomap_devres_find(struct pci_dev *pdev)
+{
+ struct pcim_iomap_devres *dr;
+
+ dr = lkpi_devres_find(&pdev->dev, lkpi_pcim_iomap_table_release,
+ NULL, NULL);
+ if (dr == NULL) {
+ dr = lkpi_devres_alloc(lkpi_pcim_iomap_table_release,
+ sizeof(*dr), GFP_KERNEL | __GFP_ZERO);
+ if (dr != NULL)
+ lkpi_devres_add(&pdev->dev, dr);
+ }
+
+ if (dr == NULL)
+ device_printf(pdev->dev.bsddev, "%s: NULL\n", __func__);
+
+ return (dr);
+}
+
+void __iomem **
+linuxkpi_pcim_iomap_table(struct pci_dev *pdev)
+{
+ struct pcim_iomap_devres *dr;
+
+ dr = lkpi_pcim_iomap_devres_find(pdev);
+ if (dr == NULL)
+ return (NULL);
+
+ /*
+ * If the driver has manually set a flag to be able to request the
+ * resource to use bus_read/write_<n>, return the shadow table.
+ */
+ if (pdev->want_iomap_res)
+ return ((void **)dr->res_table);
+
+ /* This is the Linux default. */
+ return (dr->mmio_table);
+}
+
+static struct resource *
+_lkpi_pci_iomap(struct pci_dev *pdev, int bar, unsigned long maxlen __unused)
+{
+ struct pci_mmio_region *mmio, *p;
+ int type;
+
+ if (!lkpi_pci_bar_id_valid(bar))
+ return (NULL);
+
+ type = pci_resource_type(pdev, bar);
+ if (type < 0) {
+ device_printf(pdev->dev.bsddev, "%s: bar %d type %d\n",
+ __func__, bar, type);
+ return (NULL);
+ }
+
+ /*
+ * Check for duplicate mappings.
+ * This can happen if a driver calls pci_request_region() first.
+ */
+ TAILQ_FOREACH_SAFE(mmio, &pdev->mmio, next, p) {
+ if (mmio->type == type && mmio->rid == PCIR_BAR(bar)) {
+ return (mmio->res);
+ }
+ }
+
+ mmio = malloc(sizeof(*mmio), M_DEVBUF, M_WAITOK | M_ZERO);
+ mmio->rid = PCIR_BAR(bar);
+ mmio->type = type;
+ mmio->res = bus_alloc_resource_any(pdev->dev.bsddev, mmio->type,
+ &mmio->rid, RF_ACTIVE|RF_SHAREABLE);
+ if (mmio->res == NULL) {
+ device_printf(pdev->dev.bsddev, "%s: failed to alloc "
+ "bar %d type %d rid %d\n",
+ __func__, bar, type, PCIR_BAR(bar));
+ free(mmio, M_DEVBUF);
+ return (NULL);
+ }
+ TAILQ_INSERT_TAIL(&pdev->mmio, mmio, next);
+
+ return (mmio->res);
+}
+
+void *
+linuxkpi_pci_iomap_range(struct pci_dev *pdev, int bar,
+ unsigned long off, unsigned long maxlen)
+{
+ struct resource *res;
+
+ if (!lkpi_pci_bar_id_valid(bar))
+ return (NULL);
+
+ res = _lkpi_pci_iomap(pdev, bar, maxlen);
+ if (res == NULL)
+ return (NULL);
+ /* This is a FreeBSD extension so we can use bus_*(). */
+ if (pdev->want_iomap_res)
+ return (res);
+ MPASS(off < rman_get_size(res));
+ return ((void *)(rman_get_bushandle(res) + off));
+}
+
+void *
+linuxkpi_pci_iomap(struct pci_dev *pdev, int bar, unsigned long maxlen)
+{
+ if (!lkpi_pci_bar_id_valid(bar))
+ return (NULL);
+
+ return (linuxkpi_pci_iomap_range(pdev, bar, 0, maxlen));
+}
+
+void *
+linuxkpi_pcim_iomap(struct pci_dev *pdev, int bar, unsigned long maxlen)
+{
+ struct pcim_iomap_devres *dr;
+ void *res;
+
+ if (!lkpi_pci_bar_id_valid(bar))
+ return (NULL);
+
+ dr = lkpi_pcim_iomap_devres_find(pdev);
+ if (dr == NULL)
+ return (NULL);
+
+ if (dr->res_table[bar] != NULL)
+ return (dr->res_table[bar]);
+
+ res = linuxkpi_pci_iomap(pdev, bar, maxlen);
+ if (res == NULL) {
+ /*
+ * Do not free the devres in case there were
+ * other valid mappings before already.
+ */
+ return (NULL);
+ }
+ lkpi_set_pcim_iomap_devres(dr, bar, res);
+
+ return (res);
+}
+
void
+linuxkpi_pci_iounmap(struct pci_dev *pdev, void *res)
+{
+ struct pci_mmio_region *mmio, *p;
+ bus_space_handle_t bh = (bus_space_handle_t)res;
+
+ TAILQ_FOREACH_SAFE(mmio, &pdev->mmio, next, p) {
+ if (pdev->want_iomap_res) {
+ if (res != mmio->res)
+ continue;
+ } else {
+ if (bh < rman_get_bushandle(mmio->res) ||
+ bh >= rman_get_bushandle(mmio->res) +
+ rman_get_size(mmio->res))
+ continue;
+ }
+ bus_release_resource(pdev->dev.bsddev,
+ mmio->type, mmio->rid, mmio->res);
+ TAILQ_REMOVE(&pdev->mmio, mmio, next);
+ free(mmio, M_DEVBUF);
+ return;
+ }
+}
+
+int
+linuxkpi_pcim_iomap_regions(struct pci_dev *pdev, uint32_t mask, const char *name)
+{
+ struct pcim_iomap_devres *dr;
+ void *res;
+ uint32_t mappings;
+ int bar;
+
+ dr = lkpi_pcim_iomap_devres_find(pdev);
+ if (dr == NULL)
+ return (-ENOMEM);
+
+ /* Now iomap all the requested (by "mask") ones. */
+ for (bar = mappings = 0; mappings != mask; bar++) {
+ if ((mask & (1 << bar)) == 0)
+ continue;
+
+ /* Request double is not allowed. */
+ if (dr->mmio_table[bar] != NULL) {
+ device_printf(pdev->dev.bsddev, "%s: bar %d %p\n",
+ __func__, bar, dr->mmio_table[bar]);
+ goto err;
+ }
+
+ res = _lkpi_pci_iomap(pdev, bar, 0);
+ if (res == NULL)
+ goto err;
+ lkpi_set_pcim_iomap_devres(dr, bar, res);
+
+ mappings |= (1 << bar);
+ }
+
+ return (0);
+err:
+ for (bar = PCIR_MAX_BAR_0; bar >= 0; bar--) {
+ if ((mappings & (1 << bar)) != 0) {
+ res = dr->mmio_table[bar];
+ if (res == NULL)
+ continue;
+ pci_iounmap(pdev, res);
+ }
+ }
+
+ return (-EINVAL);
+}
+
+static void
lkpi_pcim_iomap_table_release(struct device *dev, void *p)
{
struct pcim_iomap_devres *dr;
@@ -553,6 +1032,8 @@ linux_pci_suspend(device_t dev)
error = -pmops->suspend(&pdev->dev);
if (error == 0 && pmops->suspend_late != NULL)
error = -pmops->suspend_late(&pdev->dev);
+ if (error == 0 && pmops->suspend_noirq != NULL)
+ error = -pmops->suspend_noirq(&pdev->dev);
}
return (error);
}
@@ -642,14 +1123,15 @@ _linux_pci_register_driver(struct pci_driver *pdrv, devclass_t dc)
spin_lock(&pci_lock);
list_add(&pdrv->node, &pci_drivers);
spin_unlock(&pci_lock);
- pdrv->bsddriver.name = pdrv->name;
+ if (pdrv->bsddriver.name == NULL)
+ pdrv->bsddriver.name = pdrv->name;
pdrv->bsddriver.methods = pci_methods;
pdrv->bsddriver.size = sizeof(struct pci_dev);
- mtx_lock(&Giant);
+ bus_topo_lock();
error = devclass_add_driver(dc, &pdrv->bsddriver,
BUS_PASS_DEFAULT, &pdrv->bsdclass);
- mtx_unlock(&Giant);
+ bus_topo_unlock();
return (-error);
}
@@ -658,30 +1140,42 @@ linux_pci_register_driver(struct pci_driver *pdrv)
{
devclass_t dc;
- dc = devclass_find("pci");
+ pdrv->isdrm = strcmp(pdrv->name, "drmn") == 0;
+ dc = pdrv->isdrm ? devclass_create("vgapci") : devclass_find("pci");
if (dc == NULL)
return (-ENXIO);
- pdrv->isdrm = false;
return (_linux_pci_register_driver(pdrv, dc));
}
-struct resource_list_entry *
-linux_pci_reserve_bar(struct pci_dev *pdev, struct resource_list *rl,
- int type, int rid)
+static struct resource_list_entry *
+lkpi_pci_get_bar(struct pci_dev *pdev, int bar, bool reserve)
{
- device_t dev;
- struct resource *res;
+ int type;
- KASSERT(type == SYS_RES_IOPORT || type == SYS_RES_MEMORY,
- ("trying to reserve non-BAR type %d", type));
-
- dev = pdev->pdrv != NULL && pdev->pdrv->isdrm ?
- device_get_parent(pdev->dev.bsddev) : pdev->dev.bsddev;
- res = pci_reserve_map(device_get_parent(dev), dev, type, &rid, 0, ~0,
- 1, 1, 0);
- if (res == NULL)
+ type = pci_resource_type(pdev, bar);
+ if (type < 0)
return (NULL);
- return (resource_list_find(rl, type, rid));
+ bar = PCIR_BAR(bar);
+ return (linux_pci_get_rle(pdev, type, bar, reserve));
+}
+
+struct device *
+lkpi_pci_find_irq_dev(unsigned int irq)
+{
+ struct pci_dev *pdev;
+ struct device *found;
+
+ found = NULL;
+ spin_lock(&pci_lock);
+ list_for_each_entry(pdev, &pci_devices, links) {
+ if (irq == pdev->dev.irq ||
+ (irq >= pdev->dev.irq_start && irq < pdev->dev.irq_end)) {
+ found = &pdev->dev;
+ break;
+ }
+ }
+ spin_unlock(&pci_lock);
+ return (found);
}
unsigned long
@@ -692,7 +1186,7 @@ pci_resource_start(struct pci_dev *pdev, int bar)
device_t dev;
int error;
- if ((rle = linux_pci_get_bar(pdev, bar, true)) == NULL)
+ if ((rle = lkpi_pci_get_bar(pdev, bar, true)) == NULL)
return (0);
dev = pdev->pdrv != NULL && pdev->pdrv->isdrm ?
device_get_parent(pdev->dev.bsddev) : pdev->dev.bsddev;
@@ -711,11 +1205,154 @@ pci_resource_len(struct pci_dev *pdev, int bar)
{
struct resource_list_entry *rle;
- if ((rle = linux_pci_get_bar(pdev, bar, true)) == NULL)
+ if ((rle = lkpi_pci_get_bar(pdev, bar, true)) == NULL)
return (0);
return (rle->count);
}
+static int
+lkpi_pci_request_region(struct pci_dev *pdev, int bar, const char *res_name,
+ bool managed)
+{
+ struct resource *res;
+ struct pci_devres *dr;
+ struct pci_mmio_region *mmio;
+ int rid;
+ int type;
+
+ if (!lkpi_pci_bar_id_valid(bar))
+ return (-EINVAL);
+
+ /*
+ * If the bar is not valid, return success without adding the BAR;
+ * otherwise linuxkpi_pcim_request_all_regions() will error.
+ */
+ if (pci_resource_len(pdev, bar) == 0)
+ return (0);
+ /* Likewise if it is neither IO nor MEM, nothing to do for us. */
+ type = pci_resource_type(pdev, bar);
+ if (type < 0)
+ return (0);
+
+ rid = PCIR_BAR(bar);
+ res = bus_alloc_resource_any(pdev->dev.bsddev, type, &rid,
+ RF_ACTIVE|RF_SHAREABLE);
+ if (res == NULL) {
+ device_printf(pdev->dev.bsddev, "%s: failed to alloc "
+ "bar %d type %d rid %d\n",
+ __func__, bar, type, PCIR_BAR(bar));
+ return (-ENODEV);
+ }
+
+ /*
+ * It seems there is an implicit devres tracking on these if the device
+ * is managed (lkpi_pci_devres_find() case); otherwise the resources are
+ * not automatically freed on FreeBSD/LinuxKPI though they should be/are
+ * expected to be by Linux drivers.
+ * Otherwise if we are called from a pcim-function with the managed
+ * argument set, we need to track devres independent of pdev->managed.
+ */
+ if (managed)
+ dr = lkpi_pci_devres_get_alloc(pdev);
+ else
+ dr = lkpi_pci_devres_find(pdev);
+ if (dr != NULL) {
+ dr->region_mask |= (1 << bar);
+ dr->region_table[bar] = res;
+ }
+
+ /* Even if the device is not managed we need to track it for iomap. */
+ mmio = malloc(sizeof(*mmio), M_DEVBUF, M_WAITOK | M_ZERO);
+ mmio->rid = PCIR_BAR(bar);
+ mmio->type = type;
+ mmio->res = res;
+ TAILQ_INSERT_TAIL(&pdev->mmio, mmio, next);
+
+ return (0);
+}
+
+int
+linuxkpi_pci_request_region(struct pci_dev *pdev, int bar, const char *res_name)
+{
+ return (lkpi_pci_request_region(pdev, bar, res_name, false));
+}
+
+int
+linuxkpi_pci_request_regions(struct pci_dev *pdev, const char *res_name)
+{
+ int error;
+ int i;
+
+ for (i = 0; i <= PCIR_MAX_BAR_0; i++) {
+ error = pci_request_region(pdev, i, res_name);
+ if (error && error != -ENODEV) {
+ pci_release_regions(pdev);
+ return (error);
+ }
+ }
+ return (0);
+}
+
+int
+linuxkpi_pcim_request_all_regions(struct pci_dev *pdev, const char *res_name)
+{
+ int bar, error;
+
+ for (bar = 0; bar <= PCIR_MAX_BAR_0; bar++) {
+ error = lkpi_pci_request_region(pdev, bar, res_name, true);
+ if (error != 0) {
+ device_printf(pdev->dev.bsddev, "%s: bar %d res_name '%s': "
+ "lkpi_pci_request_region returned %d\n", __func__,
+ bar, res_name, error);
+ pci_release_regions(pdev);
+ return (error);
+ }
+ }
+ return (0);
+}
+
+void
+linuxkpi_pci_release_region(struct pci_dev *pdev, int bar)
+{
+ struct resource_list_entry *rle;
+ struct pci_devres *dr;
+ struct pci_mmio_region *mmio, *p;
+
+ if ((rle = lkpi_pci_get_bar(pdev, bar, false)) == NULL)
+ return;
+
+ /*
+ * As we implicitly track the requests we also need to clear them on
+ * release. Do clear before resource release.
+ */
+ dr = lkpi_pci_devres_find(pdev);
+ if (dr != NULL) {
+ KASSERT(dr->region_table[bar] == rle->res, ("%s: pdev %p bar %d"
+ " region_table res %p != rel->res %p\n", __func__, pdev,
+ bar, dr->region_table[bar], rle->res));
+ dr->region_table[bar] = NULL;
+ dr->region_mask &= ~(1 << bar);
+ }
+
+ TAILQ_FOREACH_SAFE(mmio, &pdev->mmio, next, p) {
+ if (rle->res != (void *)rman_get_bushandle(mmio->res))
+ continue;
+ TAILQ_REMOVE(&pdev->mmio, mmio, next);
+ free(mmio, M_DEVBUF);
+ }
+
+ bus_release_resource(pdev->dev.bsddev, rle->type, rle->rid, rle->res);
+}
+
+void
+linuxkpi_pci_release_regions(struct pci_dev *pdev)
+{
+ int i;
+
+ for (i = 0; i <= PCIR_MAX_BAR_0; i++)
+ pci_release_region(pdev, i);
+}
+
int
linux_pci_register_drm_driver(struct pci_driver *pdrv)
{
@@ -734,15 +1371,15 @@ linux_pci_unregister_driver(struct pci_driver *pdrv)
{
devclass_t bus;
- bus = devclass_find("pci");
+ bus = devclass_find(pdrv->isdrm ? "vgapci" : "pci");
spin_lock(&pci_lock);
list_del(&pdrv->node);
spin_unlock(&pci_lock);
- mtx_lock(&Giant);
+ bus_topo_lock();
if (bus != NULL)
devclass_delete_driver(bus, &pdrv->bsddriver);
- mtx_unlock(&Giant);
+ bus_topo_unlock();
}
void
@@ -755,10 +1392,166 @@ linux_pci_unregister_drm_driver(struct pci_driver *pdrv)
spin_lock(&pci_lock);
list_del(&pdrv->node);
spin_unlock(&pci_lock);
- mtx_lock(&Giant);
+ bus_topo_lock();
if (bus != NULL)
devclass_delete_driver(bus, &pdrv->bsddriver);
- mtx_unlock(&Giant);
+ bus_topo_unlock();
+}
+
+int
+linuxkpi_pci_enable_msix(struct pci_dev *pdev, struct msix_entry *entries,
+ int nreq)
+{
+ struct resource_list_entry *rle;
+ int error;
+ int avail;
+ int i;
+
+ avail = pci_msix_count(pdev->dev.bsddev);
+ if (avail < nreq) {
+ if (avail == 0)
+ return -EINVAL;
+ return avail;
+ }
+ avail = nreq;
+ if ((error = -pci_alloc_msix(pdev->dev.bsddev, &avail)) != 0)
+ return error;
+ /*
+ * Handle case where "pci_alloc_msix()" may allocate less
+ * interrupts than available and return with no error:
+ */
+ if (avail < nreq) {
+ pci_release_msi(pdev->dev.bsddev);
+ return avail;
+ }
+ rle = linux_pci_get_rle(pdev, SYS_RES_IRQ, 1, false);
+ pdev->dev.irq_start = rle->start;
+ pdev->dev.irq_end = rle->start + avail;
+ for (i = 0; i < nreq; i++)
+ entries[i].vector = pdev->dev.irq_start + i;
+ pdev->msix_enabled = true;
+ return (0);
+}
+
+int
+_lkpi_pci_enable_msi_range(struct pci_dev *pdev, int minvec, int maxvec)
+{
+ struct resource_list_entry *rle;
+ int error;
+ int nvec;
+
+ if (maxvec < minvec)
+ return (-EINVAL);
+
+ nvec = pci_msi_count(pdev->dev.bsddev);
+ if (nvec < 1 || nvec < minvec)
+ return (-ENOSPC);
+
+ nvec = min(nvec, maxvec);
+ if ((error = -pci_alloc_msi(pdev->dev.bsddev, &nvec)) != 0)
+ return error;
+
+ /* Native PCI might only ever ask for 32 vectors. */
+ if (nvec < minvec) {
+ pci_release_msi(pdev->dev.bsddev);
+ return (-ENOSPC);
+ }
+
+ rle = linux_pci_get_rle(pdev, SYS_RES_IRQ, 1, false);
+ pdev->dev.irq_start = rle->start;
+ pdev->dev.irq_end = rle->start + nvec;
+ pdev->irq = rle->start;
+ pdev->msi_enabled = true;
+ return (0);
+}
+
+int
+pci_alloc_irq_vectors(struct pci_dev *pdev, int minv, int maxv,
+ unsigned int flags)
+{
+ int error;
+
+ if (flags & PCI_IRQ_MSIX) {
+ struct msix_entry *entries;
+ int i;
+
+ entries = kcalloc(maxv, sizeof(*entries), GFP_KERNEL);
+ if (entries == NULL) {
+ error = -ENOMEM;
+ goto out;
+ }
+ for (i = 0; i < maxv; ++i)
+ entries[i].entry = i;
+ error = pci_enable_msix(pdev, entries, maxv);
+out:
+ kfree(entries);
+ if (error == 0 && pdev->msix_enabled)
+ return (pdev->dev.irq_end - pdev->dev.irq_start);
+ }
+ if (flags & PCI_IRQ_MSI) {
+ if (pci_msi_count(pdev->dev.bsddev) < minv)
+ return (-ENOSPC);
+ error = _lkpi_pci_enable_msi_range(pdev, minv, maxv);
+ if (error == 0 && pdev->msi_enabled)
+ return (pdev->dev.irq_end - pdev->dev.irq_start);
+ }
+ if (flags & PCI_IRQ_INTX) {
+ if (pdev->irq)
+ return (1);
+ }
+
+ return (-EINVAL);
+}
+
+struct msi_desc *
+lkpi_pci_msi_desc_alloc(int irq)
+{
+ struct device *dev;
+ struct pci_dev *pdev;
+ struct msi_desc *desc;
+ struct pci_devinfo *dinfo;
+ struct pcicfg_msi *msi;
+ int vec;
+
+ dev = lkpi_pci_find_irq_dev(irq);
+ if (dev == NULL)
+ return (NULL);
+
+ pdev = to_pci_dev(dev);
+
+ if (pdev->msi_desc == NULL)
+ return (NULL);
+
+ if (irq < pdev->dev.irq_start || irq >= pdev->dev.irq_end)
+ return (NULL);
+
+ vec = pdev->dev.irq_start - irq;
+
+ if (pdev->msi_desc[vec] != NULL)
+ return (pdev->msi_desc[vec]);
+
+ dinfo = device_get_ivars(dev->bsddev);
+ msi = &dinfo->cfg.msi;
+
+ desc = malloc(sizeof(*desc), M_DEVBUF, M_WAITOK | M_ZERO);
+
+ desc->pci.msi_attrib.is_64 =
+ (msi->msi_ctrl & PCIM_MSICTRL_64BIT) ? true : false;
+ desc->msg.data = msi->msi_data;
+
+ pdev->msi_desc[vec] = desc;
+
+ return (desc);
+}
+
+bool
+pci_device_is_present(struct pci_dev *pdev)
+{
+ device_t dev;
+
+ dev = pdev->dev.bsddev;
+
+ return (bus_child_present(dev));
}
CTASSERT(sizeof(dma_addr_t) <= sizeof(uint64_t));
@@ -783,7 +1576,7 @@ linux_dma_init(void *arg)
linux_dma_obj_zone = uma_zcreate("linux_dma_object",
sizeof(struct linux_dma_obj), NULL, NULL, NULL, NULL,
UMA_ALIGN_PTR, 0);
-
+ lkpi_pci_nseg1_fail = counter_u64_alloc(M_WAITOK);
}
SYSINIT(linux_dma, SI_SUB_DRIVERS, SI_ORDER_THIRD, linux_dma_init, NULL);
@@ -791,6 +1584,7 @@ static void
linux_dma_uninit(void *arg)
{
+ counter_u64_free(lkpi_pci_nseg1_fail);
uma_zdestroy(linux_dma_obj_zone);
uma_zdestroy(linux_dma_trie_zone);
}
@@ -848,11 +1642,19 @@ linux_dma_map_phys_common(struct device *dev, vm_paddr_t phys, size_t len,
}
nseg = -1;
- if (_bus_dmamap_load_phys(obj->dmat, obj->dmamap, phys, len,
- BUS_DMA_NOWAIT, &seg, &nseg) != 0) {
+ error = _bus_dmamap_load_phys(obj->dmat, obj->dmamap, phys, len,
+ BUS_DMA_NOWAIT, &seg, &nseg);
+ if (error != 0) {
bus_dmamap_destroy(obj->dmat, obj->dmamap);
DMA_PRIV_UNLOCK(priv);
uma_zfree(linux_dma_obj_zone, obj);
+ counter_u64_add(lkpi_pci_nseg1_fail, 1);
+ if (linuxkpi_debug) {
+ device_printf(dev->bsddev, "%s: _bus_dmamap_load_phys "
+ "error %d, phys %#018jx len %zu\n", __func__,
+ error, (uintmax_t)phys, len);
+ dump_stack();
+ }
return (0);
}
@@ -880,17 +1682,34 @@ linux_dma_map_phys_common(struct device *dev __unused, vm_paddr_t phys,
#endif
dma_addr_t
-linux_dma_map_phys(struct device *dev, vm_paddr_t phys, size_t len)
+lkpi_dma_map_phys(struct device *dev, vm_paddr_t phys, size_t len,
+ enum dma_data_direction direction, unsigned long attrs)
{
struct linux_dma_priv *priv;
+ dma_addr_t dma;
priv = dev->dma_priv;
- return (linux_dma_map_phys_common(dev, phys, len, priv->dmat));
+ dma = linux_dma_map_phys_common(dev, phys, len, priv->dmat);
+ if (dma_mapping_error(dev, dma))
+ return (dma);
+
+ if ((attrs & DMA_ATTR_SKIP_CPU_SYNC) == 0)
+ dma_sync_single_for_device(dev, dma, len, direction);
+
+ return (dma);
+}
+
+/* For backward compat only so we can MFC this. Remove before 15. */
+dma_addr_t
+linux_dma_map_phys(struct device *dev, vm_paddr_t phys, size_t len)
+{
+ return (lkpi_dma_map_phys(dev, phys, len, DMA_NONE, 0));
}
#if defined(__i386__) || defined(__amd64__) || defined(__aarch64__)
void
-linux_dma_unmap(struct device *dev, dma_addr_t dma_addr, size_t len)
+lkpi_dma_unmap(struct device *dev, dma_addr_t dma_addr, size_t len,
+ enum dma_data_direction direction, unsigned long attrs)
{
struct linux_dma_priv *priv;
struct linux_dma_obj *obj;
@@ -907,6 +1726,10 @@ linux_dma_unmap(struct device *dev, dma_addr_t dma_addr, size_t len)
return;
}
LINUX_DMA_PCTRIE_REMOVE(&priv->ptree, dma_addr);
+
+ if ((attrs & DMA_ATTR_SKIP_CPU_SYNC) == 0)
+ dma_sync_single_for_cpu(dev, dma_addr, len, direction);
+
bus_dmamap_unload(obj->dmat, obj->dmamap);
bus_dmamap_destroy(obj->dmat, obj->dmamap);
DMA_PRIV_UNLOCK(priv);
@@ -915,11 +1738,19 @@ linux_dma_unmap(struct device *dev, dma_addr_t dma_addr, size_t len)
}
#else
void
-linux_dma_unmap(struct device *dev, dma_addr_t dma_addr, size_t len)
+lkpi_dma_unmap(struct device *dev, dma_addr_t dma_addr, size_t len,
+ enum dma_data_direction direction, unsigned long attrs)
{
}
#endif
+/* For backward compat only so we can MFC this. Remove before 15. */
+void
+linux_dma_unmap(struct device *dev, dma_addr_t dma_addr, size_t len)
+{
+ lkpi_dma_unmap(dev, dma_addr, len, DMA_NONE, 0);
+}
+
void *
linux_dma_alloc_coherent(struct device *dev, size_t size,
dma_addr_t *dma_handle, gfp_t flag)
@@ -942,13 +1773,13 @@ linux_dma_alloc_coherent(struct device *dev, size_t size,
align = PAGE_SIZE << get_order(size);
/* Always zero the allocation. */
flag |= M_ZERO;
- mem = (void *)kmem_alloc_contig(size, flag & GFP_NATIVE_MASK, 0, high,
+ mem = kmem_alloc_contig(size, flag & GFP_NATIVE_MASK, 0, high,
align, 0, VM_MEMATTR_DEFAULT);
if (mem != NULL) {
*dma_handle = linux_dma_map_phys_common(dev, vtophys(mem), size,
priv->dmat_coherent);
if (*dma_handle == 0) {
- kmem_free((vm_offset_t)mem, size);
+ kmem_free(mem, size);
mem = NULL;
}
} else {
@@ -957,9 +1788,71 @@ linux_dma_alloc_coherent(struct device *dev, size_t size,
return (mem);
}
+struct lkpi_devres_dmam_coherent {
+ size_t size;
+ dma_addr_t *handle;
+ void *mem;
+};
+
+static void
+lkpi_dmam_free_coherent(struct device *dev, void *p)
+{
+ struct lkpi_devres_dmam_coherent *dr;
+
+ dr = p;
+ dma_free_coherent(dev, dr->size, dr->mem, *dr->handle);
+}
+
+void *
+linuxkpi_dmam_alloc_coherent(struct device *dev, size_t size, dma_addr_t *dma_handle,
+ gfp_t flag)
+{
+ struct lkpi_devres_dmam_coherent *dr;
+
+ dr = lkpi_devres_alloc(lkpi_dmam_free_coherent,
+ sizeof(*dr), GFP_KERNEL | __GFP_ZERO);
+
+ if (dr == NULL)
+ return (NULL);
+
+ dr->size = size;
+ dr->mem = linux_dma_alloc_coherent(dev, size, dma_handle, flag);
+ dr->handle = dma_handle;
+ if (dr->mem == NULL) {
+ lkpi_devres_free(dr);
+ return (NULL);
+ }
+
+ lkpi_devres_add(dev, dr);
+ return (dr->mem);
+}
+
+void
+linuxkpi_dma_sync(struct device *dev, dma_addr_t dma_addr, size_t size,
+ bus_dmasync_op_t op)
+{
+ struct linux_dma_priv *priv;
+ struct linux_dma_obj *obj;
+
+ priv = dev->dma_priv;
+
+ if (pctrie_is_empty(&priv->ptree))
+ return;
+
+ DMA_PRIV_LOCK(priv);
+ obj = LINUX_DMA_PCTRIE_LOOKUP(&priv->ptree, dma_addr);
+ if (obj == NULL) {
+ DMA_PRIV_UNLOCK(priv);
+ return;
+ }
+
+ bus_dmamap_sync(obj->dmat, obj->dmamap, op);
+ DMA_PRIV_UNLOCK(priv);
+}
+
int
linux_dma_map_sg_attrs(struct device *dev, struct scatterlist *sgl, int nents,
- enum dma_data_direction dir __unused, unsigned long attrs __unused)
+ enum dma_data_direction direction, unsigned long attrs)
{
struct linux_dma_priv *priv;
struct scatterlist *sg;
@@ -992,6 +1885,25 @@ linux_dma_map_sg_attrs(struct device *dev, struct scatterlist *sgl, int nents,
sg_dma_address(sg) = seg.ds_addr;
}
+
+ if ((attrs & DMA_ATTR_SKIP_CPU_SYNC) != 0)
+ goto skip_sync;
+
+ switch (direction) {
+ case DMA_BIDIRECTIONAL:
+ bus_dmamap_sync(priv->dmat, sgl->dma_map, BUS_DMASYNC_PREWRITE);
+ break;
+ case DMA_TO_DEVICE:
+ bus_dmamap_sync(priv->dmat, sgl->dma_map, BUS_DMASYNC_PREREAD);
+ break;
+ case DMA_FROM_DEVICE:
+ bus_dmamap_sync(priv->dmat, sgl->dma_map, BUS_DMASYNC_PREWRITE);
+ break;
+ default:
+ break;
+ }
+skip_sync:
+
DMA_PRIV_UNLOCK(priv);
return (nents);
@@ -999,14 +1911,34 @@ linux_dma_map_sg_attrs(struct device *dev, struct scatterlist *sgl, int nents,
void
linux_dma_unmap_sg_attrs(struct device *dev, struct scatterlist *sgl,
- int nents __unused, enum dma_data_direction dir __unused,
- unsigned long attrs __unused)
+ int nents __unused, enum dma_data_direction direction,
+ unsigned long attrs)
{
struct linux_dma_priv *priv;
priv = dev->dma_priv;
DMA_PRIV_LOCK(priv);
+
+ if ((attrs & DMA_ATTR_SKIP_CPU_SYNC) != 0)
+ goto skip_sync;
+
+ switch (direction) {
+ case DMA_BIDIRECTIONAL:
+ bus_dmamap_sync(priv->dmat, sgl->dma_map, BUS_DMASYNC_POSTREAD);
+ bus_dmamap_sync(priv->dmat, sgl->dma_map, BUS_DMASYNC_PREREAD);
+ break;
+ case DMA_TO_DEVICE:
+ bus_dmamap_sync(priv->dmat, sgl->dma_map, BUS_DMASYNC_POSTWRITE);
+ break;
+ case DMA_FROM_DEVICE:
+ bus_dmamap_sync(priv->dmat, sgl->dma_map, BUS_DMASYNC_POSTREAD);
+ break;
+ default:
+ break;
+ }
+skip_sync:
+
bus_dmamap_unload(priv->dmat, sgl->dma_map);
bus_dmamap_destroy(priv->dmat, sgl->dma_map);
DMA_PRIV_UNLOCK(priv);
diff --git a/sys/compat/linuxkpi/common/src/linux_radix.c b/sys/compat/linuxkpi/common/src/linux_radix.c
index abf217de7f98..af53d8bff366 100644
--- a/sys/compat/linuxkpi/common/src/linux_radix.c
+++ b/sys/compat/linuxkpi/common/src/linux_radix.c
@@ -27,9 +27,6 @@
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
-#include <sys/cdefs.h>
-__FBSDID("$FreeBSD$");
-
#include <sys/param.h>
#include <sys/systm.h>
#include <sys/malloc.h>
diff --git a/sys/compat/linuxkpi/common/src/linux_rcu.c b/sys/compat/linuxkpi/common/src/linux_rcu.c
index 2179faa2c05e..c0b864d269b3 100644
--- a/sys/compat/linuxkpi/common/src/linux_rcu.c
+++ b/sys/compat/linuxkpi/common/src/linux_rcu.c
@@ -2,6 +2,10 @@
* Copyright (c) 2016 Matthew Macy (mmacy@mattmacy.io)
* Copyright (c) 2017-2021 Hans Petter Selasky (hselasky@freebsd.org)
* All rights reserved.
+ * Copyright (c) 2024 The FreeBSD Foundation
+ *
+ * Portions of this software were developed by Björn Zeeb
+ * under sponsorship from the FreeBSD Foundation.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
@@ -25,9 +29,6 @@
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
-#include <sys/cdefs.h>
-__FBSDID("$FreeBSD$");
-
#include <sys/types.h>
#include <sys/systm.h>
#include <sys/malloc.h>
@@ -44,6 +45,7 @@ __FBSDID("$FreeBSD$");
#include <ck_epoch.h>
#include <linux/rcupdate.h>
+#include <linux/sched.h>
#include <linux/srcu.h>
#include <linux/slab.h>
#include <linux/kernel.h>
@@ -247,6 +249,33 @@ linux_rcu_read_unlock(unsigned type)
sched_unpin();
}
+bool
+linux_rcu_read_lock_held(unsigned type)
+{
+#ifdef INVARINATS
+ struct linux_epoch_record *record __diagused;
+ struct task_struct *ts;
+
+ MPASS(type < RCU_TYPE_MAX);
+
+ if (RCU_SKIP())
+ return (false);
+
+ if (__current_unallocated(curthread))
+ return (false);
+
+ ts = current;
+ if (ts->rcu_recurse[type] == 0)
+ return (false);
+
+ MPASS(curthread->td_pinned != 0);
+ MPASS((record = &DPCPU_GET(linux_epoch_record[type])) &&
+ record->epoch_record.active != 0);
+#endif
+
+ return (true);
+}
+
static void
linux_synchronize_rcu_cb(ck_epoch_t *epoch __unused, ck_epoch_record_t *epoch_record, void *arg __unused)
{
diff --git a/sys/compat/linuxkpi/common/src/linux_schedule.c b/sys/compat/linuxkpi/common/src/linux_schedule.c
index 656d8697d169..c6b7a2ebbd66 100644
--- a/sys/compat/linuxkpi/common/src/linux_schedule.c
+++ b/sys/compat/linuxkpi/common/src/linux_schedule.c
@@ -24,9 +24,6 @@
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
-#include <sys/cdefs.h>
-__FBSDID("$FreeBSD$");
-
#include <sys/param.h>
#include <sys/systm.h>
#include <sys/proc.h>
@@ -41,29 +38,47 @@ __FBSDID("$FreeBSD$");
#include <linux/spinlock.h>
#include <linux/wait.h>
+/*
+ * Convert a relative time in jiffies to a tick count, suitable for use with
+ * native FreeBSD interfaces (callouts, sleepqueues, etc.).
+ */
+static int
+linux_jiffies_timeout_to_ticks(long timeout)
+{
+ if (timeout < 1)
+ return (1);
+ else if (timeout == MAX_SCHEDULE_TIMEOUT)
+ return (0);
+ else if (timeout > INT_MAX)
+ return (INT_MAX);
+ else
+ return (timeout);
+}
+
static int
linux_add_to_sleepqueue(void *wchan, struct task_struct *task,
- const char *wmesg, int timeout, int state)
+ const char *wmesg, long timeout, int state)
{
- int flags, ret;
+ int flags, ret, stimeout;
MPASS((state & ~(TASK_PARKED | TASK_NORMAL)) == 0);
flags = SLEEPQ_SLEEP | ((state & TASK_INTERRUPTIBLE) != 0 ?
SLEEPQ_INTERRUPTIBLE : 0);
+ stimeout = linux_jiffies_timeout_to_ticks(timeout);
sleepq_add(wchan, NULL, wmesg, flags, 0);
- if (timeout != 0)
- sleepq_set_timeout(wchan, timeout);
+ if (stimeout != 0)
+ sleepq_set_timeout(wchan, stimeout);
DROP_GIANT();
if ((state & TASK_INTERRUPTIBLE) != 0) {
- if (timeout == 0)
+ if (stimeout == 0)
ret = -sleepq_wait_sig(wchan, 0);
else
ret = -sleepq_timedwait_sig(wchan, 0);
} else {
- if (timeout == 0) {
+ if (stimeout == 0) {
sleepq_wait(wchan, 0);
ret = 0;
} else
@@ -101,18 +116,16 @@ linux_msleep_interruptible(unsigned int ms)
static int
wake_up_task(struct task_struct *task, unsigned int state)
{
- int ret, wakeup_swapper;
+ int ret;
- ret = wakeup_swapper = 0;
+ ret = 0;
sleepq_lock(task);
if ((atomic_read(&task->state) & state) != 0) {
set_task_state(task, TASK_WAKING);
- wakeup_swapper = sleepq_signal(task, SLEEPQ_SLEEP, 0, 0);
+ sleepq_signal(task, SLEEPQ_SLEEP, 0, 0);
ret = 1;
}
sleepq_release(task);
- if (wakeup_swapper)
- kick_proc0();
return (ret);
}
@@ -187,6 +200,65 @@ default_wake_function(wait_queue_t *wq, unsigned int state, int flags,
return (wake_up_task(wq->private, state));
}
+long
+linux_wait_woken(wait_queue_t *wq, unsigned state, long timeout)
+{
+ void *wchan;
+ struct task_struct *task;
+ int ret;
+ int remainder;
+
+ task = current;
+ wchan = wq->private;
+
+ remainder = jiffies + timeout;
+
+ set_task_state(task, state);
+
+ sleepq_lock(wchan);
+ if (!(wq->flags & WQ_FLAG_WOKEN)) {
+ ret = linux_add_to_sleepqueue(wchan, task, "woken",
+ timeout, state);
+ } else {
+ sleepq_release(wchan);
+ ret = 0;
+ }
+
+ set_task_state(task, TASK_RUNNING);
+ wq->flags &= ~WQ_FLAG_WOKEN;
+
+ if (timeout == MAX_SCHEDULE_TIMEOUT)
+ return (MAX_SCHEDULE_TIMEOUT);
+
+ /* range check return value */
+ remainder -= jiffies;
+
+ /* range check return value */
+ if (ret == -ERESTARTSYS && remainder < 1)
+ remainder = 1;
+ else if (remainder < 0)
+ remainder = 0;
+ else if (remainder > timeout)
+ remainder = timeout;
+ return (remainder);
+}
+
+int
+woken_wake_function(wait_queue_t *wq, unsigned int state,
+ int flags __unused, void *key __unused)
+{
+ void *wchan;
+
+ wchan = wq->private;
+
+ sleepq_lock(wchan);
+ wq->flags |= WQ_FLAG_WOKEN;
+ sleepq_signal(wchan, SLEEPQ_SLEEP, 0, 0);
+ sleepq_release(wchan);
+
+ return (1);
+}
+
void
linux_init_wait_entry(wait_queue_t *wq, int flags)
{
@@ -254,7 +326,7 @@ linux_waitqueue_active(wait_queue_head_t *wqh)
}
int
-linux_wait_event_common(wait_queue_head_t *wqh, wait_queue_t *wq, int timeout,
+linux_wait_event_common(wait_queue_head_t *wqh, wait_queue_t *wq, long timeout,
unsigned int state, spinlock_t *lock)
{
struct task_struct *task;
@@ -263,19 +335,8 @@ linux_wait_event_common(wait_queue_head_t *wqh, wait_queue_t *wq, int timeout,
if (lock != NULL)
spin_unlock_irq(lock);
- /* range check timeout */
- if (timeout < 1)
- timeout = 1;
- else if (timeout == MAX_SCHEDULE_TIMEOUT)
- timeout = 0;
-
task = current;
- /*
- * Our wait queue entry is on the stack - make sure it doesn't
- * get swapped out while we sleep.
- */
- PHOLD(task->task_thread->td_proc);
sleepq_lock(task);
if (atomic_read(&task->state) != TASK_WAKING) {
ret = linux_add_to_sleepqueue(task, task, "wevent", timeout,
@@ -284,30 +345,22 @@ linux_wait_event_common(wait_queue_head_t *wqh, wait_queue_t *wq, int timeout,
sleepq_release(task);
ret = 0;
}
- PRELE(task->task_thread->td_proc);
if (lock != NULL)
spin_lock_irq(lock);
return (ret);
}
-int
-linux_schedule_timeout(int timeout)
+long
+linux_schedule_timeout(long timeout)
{
struct task_struct *task;
- int ret;
- int state;
- int remainder;
+ long remainder;
+ int ret, state;
task = current;
- /* range check timeout */
- if (timeout < 1)
- timeout = 1;
- else if (timeout == MAX_SCHEDULE_TIMEOUT)
- timeout = 0;
-
- remainder = ticks + timeout;
+ remainder = jiffies + timeout;
sleepq_lock(task);
state = atomic_read(&task->state);
@@ -320,11 +373,11 @@ linux_schedule_timeout(int timeout)
}
set_task_state(task, TASK_RUNNING);
- if (timeout == 0)
+ if (timeout == MAX_SCHEDULE_TIMEOUT)
return (MAX_SCHEDULE_TIMEOUT);
/* range check return value */
- remainder -= ticks;
+ remainder -= jiffies;
/* range check return value */
if (ret == -ERESTARTSYS && remainder < 1)
@@ -339,13 +392,9 @@ linux_schedule_timeout(int timeout)
static void
wake_up_sleepers(void *wchan)
{
- int wakeup_swapper;
-
sleepq_lock(wchan);
- wakeup_swapper = sleepq_signal(wchan, SLEEPQ_SLEEP, 0, 0);
+ sleepq_signal(wchan, SLEEPQ_SLEEP, 0, 0);
sleepq_release(wchan);
- if (wakeup_swapper)
- kick_proc0();
}
#define bit_to_wchan(word, bit) ((void *)(((uintptr_t)(word) << 6) | (bit)))
@@ -359,18 +408,12 @@ linux_wake_up_bit(void *word, int bit)
int
linux_wait_on_bit_timeout(unsigned long *word, int bit, unsigned int state,
- int timeout)
+ long timeout)
{
struct task_struct *task;
void *wchan;
int ret;
- /* range check timeout */
- if (timeout < 1)
- timeout = 1;
- else if (timeout == MAX_SCHEDULE_TIMEOUT)
- timeout = 0;
-
task = current;
wchan = bit_to_wchan(word, bit);
for (;;) {
diff --git a/sys/compat/linuxkpi/common/src/linux_seq_file.c b/sys/compat/linuxkpi/common/src/linux_seq_file.c
index 6f4f1a368c4a..9c06fe27bebe 100644
--- a/sys/compat/linuxkpi/common/src/linux_seq_file.c
+++ b/sys/compat/linuxkpi/common/src/linux_seq_file.c
@@ -1,5 +1,5 @@
/*-
- * SPDX-License-Identifier: BSD-2-Clause-FreeBSD
+ * SPDX-License-Identifier: BSD-2-Clause
*
* Copyright (c) 2016-2018, Matthew Macy <mmacy@freebsd.org>
*
@@ -26,9 +26,6 @@
*
*/
-#include <sys/cdefs.h>
-__FBSDID("$FreeBSD$");
-
#include <sys/types.h>
#include <sys/systm.h>
#include <sys/param.h>
@@ -45,23 +42,64 @@ MALLOC_DEFINE(M_LSEQ, "seq_file", "seq_file");
ssize_t
seq_read(struct linux_file *f, char *ubuf, size_t size, off_t *ppos)
{
- struct seq_file *m = f->private_data;
+ struct seq_file *m;
+ struct sbuf *sbuf;
void *p;
- int rc;
- off_t pos = 0;
+ ssize_t rc;
- p = m->op->start(m, &pos);
+ m = f->private_data;
+ sbuf = m->buf;
+
+ p = m->op->start(m, ppos);
rc = m->op->show(m, p);
if (rc)
return (rc);
+
+ rc = sbuf_finish(sbuf);
+ if (rc)
+ return (rc);
+
+ rc = sbuf_len(sbuf);
+ if (*ppos >= rc || size < 1)
+ return (-EINVAL);
+
+ size = min(rc - *ppos, size);
+ memcpy(ubuf, sbuf_data(sbuf) + *ppos, size);
+ *ppos += size;
+
return (size);
}
int
seq_write(struct seq_file *seq, const void *data, size_t len)
{
+ int ret;
+
+ ret = sbuf_bcpy(seq->buf, data, len);
+ if (ret == 0)
+ seq->size = sbuf_len(seq->buf);
+
+ return (ret);
+}
+
+void
+seq_putc(struct seq_file *seq, char c)
+{
+ int ret;
+
+ ret = sbuf_putc(seq->buf, c);
+ if (ret == 0)
+ seq->size = sbuf_len(seq->buf);
+}
+
+void
+seq_puts(struct seq_file *seq, const char *str)
+{
+ int ret;
- return (sbuf_bcpy(seq->buf, data, len));
+ ret = sbuf_printf(seq->buf, "%s", str);
+ if (ret == 0)
+ seq->size = sbuf_len(seq->buf);
}
/*
@@ -96,25 +134,57 @@ single_stop(struct seq_file *p, void *v)
{
}
-int
-seq_open(struct linux_file *f, const struct seq_operations *op)
+static int
+_seq_open_without_sbuf(struct linux_file *f, const struct seq_operations *op)
{
struct seq_file *p;
- if (f->private_data != NULL)
- log(LOG_WARNING, "%s private_data not NULL", __func__);
-
if ((p = malloc(sizeof(*p), M_LSEQ, M_NOWAIT|M_ZERO)) == NULL)
return (-ENOMEM);
- f->private_data = p;
- p->op = op;
p->file = f;
+ p->op = op;
+ f->private_data = (void *) p;
return (0);
}
int
-single_open(struct linux_file *f, int (*show)(struct seq_file *, void *), void *d)
+seq_open(struct linux_file *f, const struct seq_operations *op)
+{
+ int ret;
+
+ ret = _seq_open_without_sbuf(f, op);
+ if (ret == 0)
+ ((struct seq_file *)f->private_data)->buf = sbuf_new_auto();
+
+ return (ret);
+}
+
+void *
+__seq_open_private(struct linux_file *f, const struct seq_operations *op, int size)
+{
+ struct seq_file *seq_file;
+ void *private;
+ int error;
+
+ private = malloc(size, M_LSEQ, M_NOWAIT|M_ZERO);
+ if (private == NULL)
+ return (NULL);
+
+ error = seq_open(f, op);
+ if (error < 0) {
+ free(private, M_LSEQ);
+ return (NULL);
+ }
+
+ seq_file = (struct seq_file *)f->private_data;
+ seq_file->private = private;
+
+ return (private);
+}
+
+static int
+_single_open_without_sbuf(struct linux_file *f, int (*show)(struct seq_file *, void *), void *d)
{
struct seq_operations *op;
int rc = -ENOMEM;
@@ -125,7 +195,7 @@ single_open(struct linux_file *f, int (*show)(struct seq_file *, void *), void *
op->next = single_next;
op->stop = single_stop;
op->show = show;
- rc = seq_open(f, op);
+ rc = _seq_open_without_sbuf(f, op);
if (rc)
free(op, M_LSEQ);
else
@@ -135,22 +205,94 @@ single_open(struct linux_file *f, int (*show)(struct seq_file *, void *), void *
}
int
+single_open(struct linux_file *f, int (*show)(struct seq_file *, void *), void *d)
+{
+ int ret;
+
+ ret = _single_open_without_sbuf(f, show, d);
+ if (ret == 0)
+ ((struct seq_file *)f->private_data)->buf = sbuf_new_auto();
+
+ return (ret);
+}
+
+int
+single_open_size(struct linux_file *f, int (*show)(struct seq_file *, void *), void *d, size_t size)
+{
+ int ret;
+
+ ret = _single_open_without_sbuf(f, show, d);
+ if (ret == 0)
+ ((struct seq_file *)f->private_data)->buf = sbuf_new(
+ NULL, NULL, size, SBUF_AUTOEXTEND);
+
+ return (ret);
+}
+
+int
seq_release(struct inode *inode __unused, struct linux_file *file)
{
struct seq_file *m;
+ struct sbuf *s;
m = file->private_data;
+ s = m->buf;
+
+ sbuf_delete(s);
free(m, M_LSEQ);
+
return (0);
}
int
+seq_release_private(struct inode *inode __unused, struct linux_file *f)
+{
+ struct seq_file *seq;
+
+ seq = (struct seq_file *)f->private_data;
+ free(seq->private, M_LSEQ);
+ return (seq_release(inode, f));
+}
+
+int
single_release(struct vnode *v, struct linux_file *f)
{
- const struct seq_operations *op = ((struct seq_file *)f->private_data)->op;
+ const struct seq_operations *op;
+ struct seq_file *m;
int rc;
+ /* be NULL safe */
+ if ((m = f->private_data) == NULL)
+ return (0);
+
+ op = m->op;
rc = seq_release(v, f);
free(__DECONST(void *, op), M_LSEQ);
return (rc);
}
+
+void
+lkpi_seq_vprintf(struct seq_file *m, const char *fmt, va_list args)
+{
+ int ret;
+
+ ret = sbuf_vprintf(m->buf, fmt, args);
+ if (ret == 0)
+ m->size = sbuf_len(m->buf);
+}
+
+void
+lkpi_seq_printf(struct seq_file *m, const char *fmt, ...)
+{
+ va_list args;
+
+ va_start(args, fmt);
+ lkpi_seq_vprintf(m, fmt, args);
+ va_end(args);
+}
+
+bool
+seq_has_overflowed(struct seq_file *m)
+{
+ return (sbuf_len(m->buf) == -1);
+}
diff --git a/sys/compat/linuxkpi/common/src/linux_shmemfs.c b/sys/compat/linuxkpi/common/src/linux_shmemfs.c
index ead9cc9d9f40..1fb17bc5c0cb 100644
--- a/sys/compat/linuxkpi/common/src/linux_shmemfs.c
+++ b/sys/compat/linuxkpi/common/src/linux_shmemfs.c
@@ -26,9 +26,6 @@
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
-#include <sys/cdefs.h>
-__FBSDID("$FreeBSD$");
-
#include <sys/param.h>
#include <sys/systm.h>
#include <sys/rwlock.h>
@@ -47,7 +44,7 @@ __FBSDID("$FreeBSD$");
struct page *
linux_shmem_read_mapping_page_gfp(vm_object_t obj, int pindex, gfp_t gfp)
{
- vm_page_t page;
+ struct page *page;
int rv;
if ((gfp & GFP_NOWAIT) != 0)
@@ -84,7 +81,7 @@ linux_shmem_file_setup(const char *name, loff_t size, unsigned long flags)
filp->f_count = 1;
filp->f_vnode = vp;
- filp->f_shmem = vm_pager_allocate(OBJT_DEFAULT, NULL, size,
+ filp->f_shmem = vm_pager_allocate(OBJT_SWAP, NULL, size,
VM_PROT_READ | VM_PROT_WRITE, 0, curthread->td_ucred);
if (filp->f_shmem == NULL) {
error = -ENOMEM;
diff --git a/sys/compat/linuxkpi/common/src/linux_shrinker.c b/sys/compat/linuxkpi/common/src/linux_shrinker.c
index b66316c22013..e06490b92ed1 100644
--- a/sys/compat/linuxkpi/common/src/linux_shrinker.c
+++ b/sys/compat/linuxkpi/common/src/linux_shrinker.c
@@ -21,26 +21,36 @@
* 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.
- *
- * $FreeBSD$
*/
-
-#include <sys/cdefs.h>
-__FBSDID("$FreeBSD$");
-
#include <sys/param.h>
#include <sys/systm.h>
#include <sys/kernel.h>
#include <sys/queue.h>
#include <sys/eventhandler.h>
-#include <sys/mutex.h>
+#include <sys/sx.h>
#include <linux/compat.h>
#include <linux/shrinker.h>
+#include <linux/slab.h>
TAILQ_HEAD(, shrinker) lkpi_shrinkers = TAILQ_HEAD_INITIALIZER(lkpi_shrinkers);
-static struct mtx mtx_shrinker;
+static struct sx sx_shrinker;
+
+struct shrinker *
+linuxkpi_shrinker_alloc(unsigned int flags, const char *fmt, ...)
+{
+ struct shrinker *shrinker;
+
+ shrinker = kzalloc(sizeof(*shrinker), GFP_KERNEL);
+ if (shrinker == NULL)
+ return (NULL);
+
+ shrinker->flags = flags | SHRINKER_ALLOCATED;
+ shrinker->seeks = DEFAULT_SEEKS;
+
+ return (shrinker);
+}
int
linuxkpi_register_shrinker(struct shrinker *s)
@@ -49,9 +59,10 @@ linuxkpi_register_shrinker(struct shrinker *s)
KASSERT(s != NULL, ("NULL shrinker"));
KASSERT(s->count_objects != NULL, ("NULL shrinker"));
KASSERT(s->scan_objects != NULL, ("NULL shrinker"));
- mtx_lock(&mtx_shrinker);
+ sx_xlock(&sx_shrinker);
+ s->flags |= SHRINKER_REGISTERED;
TAILQ_INSERT_TAIL(&lkpi_shrinkers, s, next);
- mtx_unlock(&mtx_shrinker);
+ sx_xunlock(&sx_shrinker);
return (0);
}
@@ -59,9 +70,28 @@ void
linuxkpi_unregister_shrinker(struct shrinker *s)
{
- mtx_lock(&mtx_shrinker);
+ sx_xlock(&sx_shrinker);
TAILQ_REMOVE(&lkpi_shrinkers, s, next);
- mtx_unlock(&mtx_shrinker);
+ s->flags &= ~SHRINKER_REGISTERED;
+ sx_xunlock(&sx_shrinker);
+}
+
+void
+linuxkpi_shrinker_free(struct shrinker *shrinker)
+{
+
+ if (shrinker->flags & SHRINKER_REGISTERED)
+ unregister_shrinker(shrinker);
+
+ kfree(shrinker);
+}
+
+void
+linuxkpi_synchronize_shrinkers(void)
+{
+
+ sx_xlock(&sx_shrinker);
+ sx_xunlock(&sx_shrinker);
}
#define SHRINKER_BATCH 512
@@ -90,16 +120,15 @@ shrinker_shrink(struct shrinker *s)
}
static void
-linuxkpi_vm_lowmem(void *arg __unused)
+linuxkpi_vm_lowmem(void *arg __unused, int flags __unused)
{
struct shrinker *s;
- linux_set_current(curthread);
- mtx_lock(&mtx_shrinker);
+ sx_xlock(&sx_shrinker);
TAILQ_FOREACH(s, &lkpi_shrinkers, next) {
shrinker_shrink(s);
}
- mtx_unlock(&mtx_shrinker);
+ sx_xunlock(&sx_shrinker);
}
static eventhandler_tag lowmem_tag;
@@ -108,7 +137,7 @@ static void
linuxkpi_sysinit_shrinker(void *arg __unused)
{
- mtx_init(&mtx_shrinker, "lkpi-shrinker", NULL, MTX_DEF);
+ sx_init(&sx_shrinker, "lkpi-shrinker");
lowmem_tag = EVENTHANDLER_REGISTER(vm_lowmem, linuxkpi_vm_lowmem,
NULL, EVENTHANDLER_PRI_FIRST);
}
@@ -117,7 +146,7 @@ static void
linuxkpi_sysuninit_shrinker(void *arg __unused)
{
- mtx_destroy(&mtx_shrinker);
+ sx_destroy(&sx_shrinker);
EVENTHANDLER_DEREGISTER(vm_lowmem, lowmem_tag);
}
diff --git a/sys/compat/linuxkpi/common/src/linux_simple_attr.c b/sys/compat/linuxkpi/common/src/linux_simple_attr.c
new file mode 100644
index 000000000000..8cc9ec7ecbc9
--- /dev/null
+++ b/sys/compat/linuxkpi/common/src/linux_simple_attr.c
@@ -0,0 +1,207 @@
+/*-
+ * SPDX-License-Identifier: BSD-2-Clause
+ *
+ * Copyright (c) 2022, Jake Freeland <jfree@freebsd.org>
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``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 OR CONTRIBUTORS 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.
+ */
+
+#include <sys/types.h>
+#include <linux/fs.h>
+
+MALLOC_DEFINE(M_LSATTR, "simple_attr", "Linux Simple Attribute File");
+
+struct simple_attr {
+ int (*get)(void *, uint64_t *);
+ int (*set)(void *, uint64_t);
+ void *data;
+ const char *fmt;
+ struct mutex mutex;
+};
+
+/*
+ * simple_attr_open: open and populate simple attribute data
+ *
+ * @inode: file inode
+ * @filp: file pointer
+ * @get: ->get() for reading file data
+ * @set: ->set() for writing file data
+ * @fmt: format specifier for data returned by @get
+ *
+ * Memory allocate a simple_attr and appropriately initialize its members.
+ * The simple_attr must be stored in filp->private_data.
+ * Simple attr files do not support seeking. Open the file as nonseekable.
+ *
+ * Return value: simple attribute file descriptor
+ */
+int
+simple_attr_open(struct inode *inode, struct file *filp,
+ int (*get)(void *, uint64_t *), int (*set)(void *, uint64_t),
+ const char *fmt)
+{
+ struct simple_attr *sattr;
+ sattr = malloc(sizeof(*sattr), M_LSATTR, M_ZERO | M_NOWAIT);
+ if (sattr == NULL)
+ return (-ENOMEM);
+
+ sattr->get = get;
+ sattr->set = set;
+ sattr->data = inode->i_private;
+ sattr->fmt = fmt;
+ mutex_init(&sattr->mutex);
+
+ filp->private_data = (void *) sattr;
+
+ return (nonseekable_open(inode, filp));
+}
+
+int
+simple_attr_release(struct inode *inode, struct file *filp)
+{
+ free(filp->private_data, M_LSATTR);
+ return (0);
+}
+
+/*
+ * simple_attr_read: read simple attr data and transfer into buffer
+ *
+ * @filp: file pointer
+ * @buf: kernel space buffer
+ * @read_size: number of bytes to be transferred
+ * @ppos: starting pointer position for transfer
+ *
+ * The simple_attr structure is stored in filp->private_data.
+ * ->get() retrieves raw file data.
+ * The ->fmt specifier can format this data to be human readable.
+ * This output is then transferred into the @buf buffer.
+ *
+ * Return value:
+ * On success, number of bytes transferred
+ * On failure, negative signed ERRNO
+ */
+ssize_t
+simple_attr_read(struct file *filp, char *buf, size_t read_size, loff_t *ppos)
+{
+ struct simple_attr *sattr;
+ uint64_t data;
+ ssize_t ret;
+ char prebuf[24];
+
+ sattr = filp->private_data;
+
+ if (sattr->get == NULL)
+ return (-EFAULT);
+
+ mutex_lock(&sattr->mutex);
+
+ ret = sattr->get(sattr->data, &data);
+ if (ret)
+ goto unlock;
+
+ scnprintf(prebuf, sizeof(prebuf), sattr->fmt, data);
+
+ ret = strlen(prebuf) + 1;
+ if (*ppos >= ret || read_size < 1) {
+ ret = -EINVAL;
+ goto unlock;
+ }
+
+ read_size = min(ret - *ppos, read_size);
+ ret = strscpy(buf, prebuf + *ppos, read_size);
+
+ /* add 1 for null terminator */
+ if (ret > 0)
+ ret += 1;
+
+unlock:
+ mutex_unlock(&sattr->mutex);
+ return (ret);
+}
+
+/*
+ * simple_attr_write_common: write contents of buffer into simple attribute file
+ *
+ * @filp: file pointer
+ * @buf: kernel space buffer
+ * @write_size: number bytes to be transferred
+ * @ppos: starting pointer position for transfer
+ * @is_signed: signedness of data in @buf
+ *
+ * The simple_attr structure is stored in filp->private_data.
+ * Convert the @buf string to unsigned long long.
+ * ->set() writes unsigned long long data into the simple attr file.
+ *
+ * Return value:
+ * On success, number of bytes written to simple attr
+ * On failure, negative signed ERRNO
+ */
+static ssize_t
+simple_attr_write_common(struct file *filp, const char *buf, size_t write_size,
+ loff_t *ppos, bool is_signed)
+{
+ struct simple_attr *sattr;
+ unsigned long long data;
+ size_t bufsize;
+ ssize_t ret;
+
+ sattr = filp->private_data;
+ bufsize = strlen(buf) + 1;
+
+ if (sattr->set == NULL)
+ return (-EFAULT);
+
+ if (*ppos >= bufsize || write_size < 1)
+ return (-EINVAL);
+
+ mutex_lock(&sattr->mutex);
+
+ if (is_signed)
+ ret = kstrtoll(buf + *ppos, 0, &data);
+ else
+ ret = kstrtoull(buf + *ppos, 0, &data);
+ if (ret)
+ goto unlock;
+
+ ret = sattr->set(sattr->data, data);
+ if (ret)
+ goto unlock;
+
+ ret = bufsize - *ppos;
+
+unlock:
+ mutex_unlock(&sattr->mutex);
+ return (ret);
+}
+
+ssize_t
+simple_attr_write(struct file *filp, const char *buf, size_t write_size,
+ loff_t *ppos)
+{
+ return (simple_attr_write_common(filp, buf, write_size, ppos, false));
+}
+
+ssize_t
+simple_attr_write_signed(struct file *filp, const char *buf, size_t write_size,
+ loff_t *ppos)
+{
+ return (simple_attr_write_common(filp, buf, write_size, ppos, true));
+}
diff --git a/sys/compat/linuxkpi/common/src/linux_skbuff.c b/sys/compat/linuxkpi/common/src/linux_skbuff.c
new file mode 100644
index 000000000000..abfb642ba708
--- /dev/null
+++ b/sys/compat/linuxkpi/common/src/linux_skbuff.c
@@ -0,0 +1,361 @@
+/*-
+ * Copyright (c) 2020-2025 The FreeBSD Foundation
+ * Copyright (c) 2021-2022 Bjoern A. Zeeb
+ *
+ * This software was developed by Björn Zeeb under sponsorship from
+ * the FreeBSD Foundation.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``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 OR CONTRIBUTORS 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.
+ */
+
+/*
+ * NOTE: this socket buffer compatibility code is highly EXPERIMENTAL.
+ * Do not rely on the internals of this implementation. They are highly
+ * likely to change as we will improve the integration to FreeBSD mbufs.
+ */
+
+#include <sys/cdefs.h>
+#include "opt_ddb.h"
+
+#include <sys/param.h>
+#include <sys/types.h>
+#include <sys/kernel.h>
+#include <sys/malloc.h>
+#include <sys/sysctl.h>
+
+#include <vm/uma.h>
+
+#ifdef DDB
+#include <ddb/ddb.h>
+#endif
+
+#include <linux/skbuff.h>
+#include <linux/slab.h>
+#include <linux/gfp.h>
+#ifdef __LP64__
+#include <linux/log2.h>
+#endif
+
+SYSCTL_DECL(_compat_linuxkpi);
+SYSCTL_NODE(_compat_linuxkpi, OID_AUTO, skb, CTLFLAG_RW | CTLFLAG_MPSAFE, 0,
+ "LinuxKPI skbuff");
+
+#ifdef SKB_DEBUG
+int linuxkpi_debug_skb;
+SYSCTL_INT(_compat_linuxkpi_skb, OID_AUTO, debug, CTLFLAG_RWTUN,
+ &linuxkpi_debug_skb, 0, "SKB debug level");
+#endif
+
+static uma_zone_t skbzone;
+
+#define SKB_DMA32_MALLOC
+#ifdef SKB_DMA32_MALLOC
+/*
+ * Realtek wireless drivers (e.g., rtw88) require 32bit DMA in a single segment.
+ * busdma(9) has a hard time providing this currently for 3-ish pages at large
+ * quantities (see lkpi_pci_nseg1_fail in linux_pci.c).
+ * Work around this for now by allowing a tunable to enforce physical addresses
+ * allocation limits using "old-school" contigmalloc(9) to avoid bouncing.
+ * Note: with the malloc/contigmalloc + kmalloc changes also providing physical
+ * contiguous memory, and the nseg=1 limit for bouncing we should in theory be
+ * fine now and not need any of this anymore, however busdma still has troubles
+ * boncing three contiguous pages so for now this stays.
+ */
+static int linuxkpi_skb_memlimit;
+SYSCTL_INT(_compat_linuxkpi_skb, OID_AUTO, mem_limit, CTLFLAG_RDTUN,
+ &linuxkpi_skb_memlimit, 0, "SKB memory limit: 0=no limit, "
+ "1=32bit, 2=36bit, other=undef (currently 32bit)");
+
+static MALLOC_DEFINE(M_LKPISKB, "lkpiskb", "Linux KPI skbuff compat");
+#endif
+
+struct sk_buff *
+linuxkpi_alloc_skb(size_t size, gfp_t gfp)
+{
+ struct sk_buff *skb;
+ void *p;
+ size_t len;
+
+ skb = uma_zalloc(skbzone, linux_check_m_flags(gfp) | M_ZERO);
+ if (skb == NULL)
+ return (NULL);
+
+ skb->prev = skb->next = skb;
+ skb->truesize = size;
+ skb->shinfo = (struct skb_shared_info *)(skb + 1);
+
+ if (size == 0)
+ return (skb);
+
+ len = size;
+#ifdef SKB_DMA32_MALLOC
+ /*
+ * Using our own type here not backing my kmalloc.
+ * We assume no one calls kfree directly on the skb.
+ */
+ if (__predict_false(linuxkpi_skb_memlimit != 0)) {
+ vm_paddr_t high;
+
+ switch (linuxkpi_skb_memlimit) {
+#ifdef __LP64__
+ case 2:
+ high = (0xfffffffff); /* 1<<36 really. */
+ break;
+#endif
+ case 1:
+ default:
+ high = (0xffffffff); /* 1<<32 really. */
+ break;
+ }
+ len = roundup_pow_of_two(len);
+ p = contigmalloc(len, M_LKPISKB,
+ linux_check_m_flags(gfp) | M_ZERO, 0, high, PAGE_SIZE, 0);
+ } else
+#endif
+ p = __kmalloc(len, linux_check_m_flags(gfp) | M_ZERO);
+ if (p == NULL) {
+ uma_zfree(skbzone, skb);
+ return (NULL);
+ }
+
+ skb->head = skb->data = (uint8_t *)p;
+ skb_reset_tail_pointer(skb);
+ skb->end = skb->head + size;
+
+ SKB_TRACE_FMT(skb, "data %p size %zu", (skb) ? skb->data : NULL, size);
+ return (skb);
+}
+
+struct sk_buff *
+linuxkpi_dev_alloc_skb(size_t size, gfp_t gfp)
+{
+ struct sk_buff *skb;
+ size_t len;
+
+ len = size + NET_SKB_PAD;
+ skb = linuxkpi_alloc_skb(len, gfp);
+
+ if (skb != NULL)
+ skb_reserve(skb, NET_SKB_PAD);
+
+ SKB_TRACE_FMT(skb, "data %p size %zu len %zu",
+ (skb) ? skb->data : NULL, size, len);
+ return (skb);
+}
+
+struct sk_buff *
+linuxkpi_build_skb(void *data, size_t fragsz)
+{
+ struct sk_buff *skb;
+
+ if (data == NULL || fragsz == 0)
+ return (NULL);
+
+ /* Just allocate a skb without data area. */
+ skb = linuxkpi_alloc_skb(0, GFP_KERNEL);
+ if (skb == NULL)
+ return (NULL);
+
+ skb->_flags |= _SKB_FLAGS_SKBEXTFRAG;
+ skb->truesize = fragsz;
+ skb->head = skb->data = data;
+ skb_reset_tail_pointer(skb);
+ skb->end = skb->head + fragsz;
+
+ return (skb);
+}
+
+struct sk_buff *
+linuxkpi_skb_copy(const struct sk_buff *skb, gfp_t gfp)
+{
+ struct sk_buff *new;
+ struct skb_shared_info *shinfo;
+ size_t len;
+ unsigned int headroom;
+
+ /* Full buffer size + any fragments. */
+ len = skb->end - skb->head + skb->data_len;
+
+ new = linuxkpi_alloc_skb(len, gfp);
+ if (new == NULL)
+ return (NULL);
+
+ headroom = skb_headroom(skb);
+ /* Fixup head and end. */
+ skb_reserve(new, headroom); /* data and tail move headroom forward. */
+ skb_put(new, skb->len); /* tail and len get adjusted */
+
+ /* Copy data. */
+ memcpy(new->head, skb->data - headroom, headroom + skb->len);
+
+ /* Deal with fragments. */
+ shinfo = skb->shinfo;
+ if (shinfo->nr_frags > 0) {
+ printf("%s:%d: NOT YET SUPPORTED; missing %d frags\n",
+ __func__, __LINE__, shinfo->nr_frags);
+ SKB_TODO();
+ }
+
+ /* Deal with header fields. */
+ memcpy(new->cb, skb->cb, sizeof(skb->cb));
+ SKB_IMPROVE("more header fields to copy?");
+
+ return (new);
+}
+
+void
+linuxkpi_kfree_skb(struct sk_buff *skb)
+{
+ struct skb_shared_info *shinfo;
+ uint16_t fragno, count;
+
+ SKB_TRACE(skb);
+ if (skb == NULL)
+ return;
+
+ /*
+ * XXX TODO this will go away once we have skb backed by mbuf.
+ * currently we allow the mbuf to stay around and use a private
+ * free function to allow secondary resources to be freed along.
+ */
+ if (skb->m != NULL) {
+ void *m;
+
+ m = skb->m;
+ skb->m = NULL;
+
+ KASSERT(skb->m_free_func != NULL, ("%s: skb %p has m %p but no "
+ "m_free_func %p\n", __func__, skb, m, skb->m_free_func));
+ skb->m_free_func(m);
+ }
+ KASSERT(skb->m == NULL,
+ ("%s: skb %p m %p != NULL\n", __func__, skb, skb->m));
+
+ shinfo = skb->shinfo;
+ for (count = fragno = 0;
+ count < shinfo->nr_frags && fragno < nitems(shinfo->frags);
+ fragno++) {
+
+ if (shinfo->frags[fragno].page != NULL) {
+ struct page *p;
+
+ p = shinfo->frags[fragno].page;
+ shinfo->frags[fragno].size = 0;
+ shinfo->frags[fragno].offset = 0;
+ shinfo->frags[fragno].page = NULL;
+ __free_page(p);
+ count++;
+ }
+ }
+
+ if ((skb->_flags & _SKB_FLAGS_SKBEXTFRAG) != 0) {
+ void *p;
+
+ p = skb->head;
+ skb_free_frag(p);
+ skb->head = NULL;
+ }
+
+#ifdef SKB_DMA32_MALLOC
+ if (__predict_false(linuxkpi_skb_memlimit != 0))
+ free(skb->head, M_LKPISKB);
+ else
+#endif
+ kfree(skb->head);
+ uma_zfree(skbzone, skb);
+}
+
+static void
+lkpi_skbuff_init(void *arg __unused)
+{
+ skbzone = uma_zcreate("skbuff",
+ sizeof(struct sk_buff) + sizeof(struct skb_shared_info),
+ NULL, NULL, NULL, NULL, UMA_ALIGN_PTR, 0);
+ /* Do we need to apply limits? */
+}
+SYSINIT(linuxkpi_skbuff, SI_SUB_DRIVERS, SI_ORDER_FIRST, lkpi_skbuff_init, NULL);
+
+static void
+lkpi_skbuff_destroy(void *arg __unused)
+{
+ uma_zdestroy(skbzone);
+}
+SYSUNINIT(linuxkpi_skbuff, SI_SUB_DRIVERS, SI_ORDER_SECOND, lkpi_skbuff_destroy, NULL);
+
+#ifdef DDB
+DB_SHOW_COMMAND(skb, db_show_skb)
+{
+ struct sk_buff *skb;
+ int i;
+
+ if (!have_addr) {
+ db_printf("usage: show skb <addr>\n");
+ return;
+ }
+
+ skb = (struct sk_buff *)addr;
+
+ db_printf("skb %p\n", skb);
+ db_printf("\tnext %p prev %p\n", skb->next, skb->prev);
+ db_printf("\tlist %p\n", &skb->list);
+ db_printf("\tlen %u data_len %u truesize %u mac_len %u\n",
+ skb->len, skb->data_len, skb->truesize, skb->mac_len);
+ db_printf("\tcsum %#06x l3hdroff %u l4hdroff %u priority %u qmap %u\n",
+ skb->csum, skb->l3hdroff, skb->l4hdroff, skb->priority, skb->qmap);
+ db_printf("\tpkt_type %d dev %p sk %p\n",
+ skb->pkt_type, skb->dev, skb->sk);
+ db_printf("\tcsum_offset %d csum_start %d ip_summed %d protocol %d\n",
+ skb->csum_offset, skb->csum_start, skb->ip_summed, skb->protocol);
+ db_printf("\t_flags %#06x\n", skb->_flags); /* XXX-BZ print names? */
+ db_printf("\thead %p data %p tail %p end %p\n",
+ skb->head, skb->data, skb->tail, skb->end);
+ db_printf("\tshinfo %p m %p m_free_func %p\n",
+ skb->shinfo, skb->m, skb->m_free_func);
+
+ if (skb->shinfo != NULL) {
+ struct skb_shared_info *shinfo;
+
+ shinfo = skb->shinfo;
+ db_printf("\t\tgso_type %d gso_size %u nr_frags %u\n",
+ shinfo->gso_type, shinfo->gso_size, shinfo->nr_frags);
+ for (i = 0; i < nitems(shinfo->frags); i++) {
+ struct skb_frag *frag;
+
+ frag = &shinfo->frags[i];
+ if (frag == NULL || frag->page == NULL)
+ continue;
+ db_printf("\t\t\tfrag %p fragno %d page %p %p "
+ "offset %ju size %zu\n",
+ frag, i, frag->page, linux_page_address(frag->page),
+ (uintmax_t)frag->offset, frag->size);
+ }
+ }
+ db_printf("\tcb[] %p {", skb->cb);
+ for (i = 0; i < nitems(skb->cb); i++) {
+ db_printf("%#04x%s",
+ skb->cb[i], (i < (nitems(skb->cb)-1)) ? ", " : "");
+ }
+ db_printf("}\n");
+
+ db_printf("\t__scratch[0] %p\n", skb->__scratch);
+};
+#endif
diff --git a/sys/compat/linuxkpi/common/src/linux_slab.c b/sys/compat/linuxkpi/common/src/linux_slab.c
index e062f0535fda..6f71d17a3770 100644
--- a/sys/compat/linuxkpi/common/src/linux_slab.c
+++ b/sys/compat/linuxkpi/common/src/linux_slab.c
@@ -1,6 +1,10 @@
/*-
* Copyright (c) 2017 Mellanox Technologies, Ltd.
* All rights reserved.
+ * Copyright (c) 2024-2025 The FreeBSD Foundation
+ *
+ * Portions of this software were developed by Björn Zeeb
+ * under sponsorship from the FreeBSD Foundation.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
@@ -25,8 +29,7 @@
*/
#include <sys/cdefs.h>
-__FBSDID("$FreeBSD$");
-
+#include <linux/compat.h>
#include <linux/slab.h>
#include <linux/rcupdate.h>
#include <linux/kernel.h>
@@ -208,6 +211,108 @@ linux_kmem_cache_destroy(struct linux_kmem_cache *c)
free(c, M_KMALLOC);
}
+void *
+lkpi___kmalloc_node(size_t size, gfp_t flags, int node)
+{
+ if (size <= PAGE_SIZE)
+ return (malloc_domainset(size, M_KMALLOC,
+ linux_get_vm_domain_set(node), linux_check_m_flags(flags)));
+ else
+ return (contigmalloc_domainset(size, M_KMALLOC,
+ linux_get_vm_domain_set(node), linux_check_m_flags(flags),
+ 0, -1UL, PAGE_SIZE, 0));
+}
+
+void *
+lkpi___kmalloc(size_t size, gfp_t flags)
+{
+ size_t _s;
+
+ /* sizeof(struct llist_node) is used for kfree_async(). */
+ _s = MAX(size, sizeof(struct llist_node));
+
+ if (_s <= PAGE_SIZE)
+ return (malloc(_s, M_KMALLOC, linux_check_m_flags(flags)));
+ else
+ return (contigmalloc(_s, M_KMALLOC, linux_check_m_flags(flags),
+ 0, -1UL, PAGE_SIZE, 0));
+}
+
+void *
+lkpi_krealloc(void *ptr, size_t size, gfp_t flags)
+{
+ void *nptr;
+ size_t osize;
+
+ /*
+ * First handle invariants based on function arguments.
+ */
+ if (ptr == NULL)
+ return (kmalloc(size, flags));
+
+ osize = ksize(ptr);
+ if (size <= osize)
+ return (ptr);
+
+ /*
+ * We know the new size > original size. realloc(9) does not (and cannot)
+ * know about our requirements for physically contiguous memory, so we can
+ * only call it for sizes up to and including PAGE_SIZE, and otherwise have
+ * to replicate its functionality using kmalloc to get the contigmalloc(9)
+ * backing.
+ */
+ if (size <= PAGE_SIZE)
+ return (realloc(ptr, size, M_KMALLOC, linux_check_m_flags(flags)));
+
+ nptr = kmalloc(size, flags);
+ if (nptr == NULL)
+ return (NULL);
+
+ memcpy(nptr, ptr, osize);
+ kfree(ptr);
+ return (nptr);
+}
+
+struct lkpi_kmalloc_ctx {
+ size_t size;
+ gfp_t flags;
+ void *addr;
+};
+
+static void
+lkpi_kmalloc_cb(void *ctx)
+{
+ struct lkpi_kmalloc_ctx *lmc = ctx;
+
+ lmc->addr = __kmalloc(lmc->size, lmc->flags);
+}
+
+void *
+lkpi_kmalloc(size_t size, gfp_t flags)
+{
+ struct lkpi_kmalloc_ctx lmc = { .size = size, .flags = flags };
+
+ lkpi_fpu_safe_exec(&lkpi_kmalloc_cb, &lmc);
+ return(lmc.addr);
+}
+
+static void
+lkpi_kvmalloc_cb(void *ctx)
+{
+ struct lkpi_kmalloc_ctx *lmc = ctx;
+
+ lmc->addr = malloc(lmc->size, M_KMALLOC, linux_check_m_flags(lmc->flags));
+}
+
+void *
+lkpi_kvmalloc(size_t size, gfp_t flags)
+{
+ struct lkpi_kmalloc_ctx lmc = { .size = size, .flags = flags };
+
+ lkpi_fpu_safe_exec(&lkpi_kvmalloc_cb, &lmc);
+ return(lmc.addr);
+}
+
static void
linux_kfree_async_fn(void *context, int pending)
{
@@ -219,7 +324,7 @@ linux_kfree_async_fn(void *context, int pending)
static struct task linux_kfree_async_task =
TASK_INITIALIZER(0, linux_kfree_async_fn, &linux_kfree_async_task);
-void
+static void
linux_kfree_async(void *addr)
{
if (addr == NULL)
@@ -227,3 +332,16 @@ linux_kfree_async(void *addr)
llist_add(addr, &linux_kfree_async_list);
taskqueue_enqueue(linux_irq_work_tq, &linux_kfree_async_task);
}
+
+void
+lkpi_kfree(const void *ptr)
+{
+ if (ZERO_OR_NULL_PTR(ptr))
+ return;
+
+ if (curthread->td_critnest != 0)
+ linux_kfree_async(__DECONST(void *, ptr));
+ else
+ free(__DECONST(void *, ptr), M_KMALLOC);
+}
+
diff --git a/sys/compat/linuxkpi/common/src/linux_tasklet.c b/sys/compat/linuxkpi/common/src/linux_tasklet.c
index 26e7bb75cf19..e443ab3958b4 100644
--- a/sys/compat/linuxkpi/common/src/linux_tasklet.c
+++ b/sys/compat/linuxkpi/common/src/linux_tasklet.c
@@ -24,9 +24,6 @@
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
-#include <sys/cdefs.h>
-__FBSDID("$FreeBSD$");
-
#include <sys/types.h>
#include <sys/malloc.h>
#include <sys/gtaskqueue.h>
@@ -85,7 +82,10 @@ tasklet_handler(void *arg)
/* reset executing state */
TASKLET_ST_SET(ts, TASKLET_ST_EXEC);
- ts->func(ts->data);
+ if (ts->use_callback)
+ ts->callback(ts);
+ else
+ ts->func(ts->data);
} while (TASKLET_ST_CMPSET(ts, TASKLET_ST_EXEC,
TASKLET_ST_IDLE) == 0);
@@ -149,9 +149,24 @@ tasklet_init(struct tasklet_struct *ts,
ts->entry.tqe_prev = NULL;
ts->entry.tqe_next = NULL;
ts->func = func;
+ ts->callback = NULL;
ts->data = data;
atomic_set_int(&ts->tasklet_state, TASKLET_ST_IDLE);
atomic_set(&ts->count, 0);
+ ts->use_callback = false;
+}
+
+void
+tasklet_setup(struct tasklet_struct *ts, tasklet_callback_t *c)
+{
+ ts->entry.tqe_prev = NULL;
+ ts->entry.tqe_next = NULL;
+ ts->func = NULL;
+ ts->callback = c;
+ ts->data = 0;
+ atomic_set_int(&ts->tasklet_state, TASKLET_ST_IDLE);
+ atomic_set(&ts->count, 0);
+ ts->use_callback = true;
}
void
diff --git a/sys/compat/linuxkpi/common/src/linux_usb.c b/sys/compat/linuxkpi/common/src/linux_usb.c
index 72aa561fcfbb..cdd3d9a01f35 100644
--- a/sys/compat/linuxkpi/common/src/linux_usb.c
+++ b/sys/compat/linuxkpi/common/src/linux_usb.c
@@ -1,4 +1,3 @@
-/* $FreeBSD$ */
/*-
* Copyright (c) 2007 Luigi Rizzo - Universita` di Pisa. All rights reserved.
* Copyright (c) 2007 Hans Petter Selasky. All rights reserved.
@@ -122,9 +121,7 @@ static driver_t usb_linux_driver = {
.size = sizeof(struct usb_linux_softc),
};
-static devclass_t usb_linux_devclass;
-
-DRIVER_MODULE(usb_linux, uhub, usb_linux_driver, usb_linux_devclass, NULL, 0);
+DRIVER_MODULE(usb_linux, uhub, usb_linux_driver, NULL, NULL);
MODULE_VERSION(usb_linux, 1);
/*------------------------------------------------------------------------*
@@ -221,7 +218,7 @@ usb_linux_probe(device_t dev)
mtx_lock(&Giant);
LIST_FOREACH(udrv, &usb_linux_driver_list, linux_driver_list) {
if (usb_linux_lookup_id(udrv->id_table, uaa)) {
- err = 0;
+ err = BUS_PROBE_DEFAULT;
break;
}
}
@@ -341,11 +338,14 @@ usb_linux_suspend(device_t dev)
{
struct usb_linux_softc *sc = device_get_softc(dev);
struct usb_driver *udrv = usb_linux_get_usb_driver(sc);
+ pm_message_t pm_msg;
int err;
err = 0;
- if (udrv && udrv->suspend)
- err = (udrv->suspend) (sc->sc_ui, 0);
+ if (udrv && udrv->suspend) {
+ pm_msg.event = 0; /* XXX */
+ err = (udrv->suspend) (sc->sc_ui, pm_msg);
+ }
return (-err);
}
@@ -1166,7 +1166,9 @@ repeat:
LIST_FOREACH(sc, &usb_linux_attached_list, sc_attached_list) {
if (sc->sc_udrv == drv) {
mtx_unlock(&Giant);
+ bus_topo_lock();
device_detach(sc->sc_fbsd_dev);
+ bus_topo_unlock();
goto repeat;
}
}
diff --git a/sys/compat/linuxkpi/common/src/linux_work.c b/sys/compat/linuxkpi/common/src/linux_work.c
index f9cf62928760..b1975d16025e 100644
--- a/sys/compat/linuxkpi/common/src/linux_work.c
+++ b/sys/compat/linuxkpi/common/src/linux_work.c
@@ -25,8 +25,6 @@
*/
#include <sys/cdefs.h>
-__FBSDID("$FreeBSD$");
-
#include <linux/workqueue.h>
#include <linux/wait.h>
#include <linux/compat.h>
@@ -89,7 +87,7 @@ linux_update_state(atomic_t *v, const uint8_t *pstate)
* completed. This function gives the linux_work_fn() function a hint,
* that the task is not going away and can have its state checked
* again. Without this extra hint LinuxKPI tasks cannot be serialized
- * accross multiple worker threads.
+ * across multiple worker threads.
*/
static bool
linux_work_exec_unblock(struct work_struct *work)
@@ -208,13 +206,13 @@ linux_flush_rcu_work(struct rcu_work *rwork)
/*
* This function queues the given work structure on the given
- * workqueue after a given delay in ticks. It returns non-zero if the
+ * workqueue after a given delay in ticks. It returns true if the
* work was successfully [re-]queued. Else the work is already pending
* for completion.
*/
bool
linux_queue_delayed_work_on(int cpu, struct workqueue_struct *wq,
- struct delayed_work *dwork, unsigned delay)
+ struct delayed_work *dwork, unsigned long delay)
{
static const uint8_t states[WORK_ST_MAX] __aligned(8) = {
[WORK_ST_IDLE] = WORK_ST_TIMER, /* start timeout */
@@ -223,16 +221,26 @@ linux_queue_delayed_work_on(int cpu, struct workqueue_struct *wq,
[WORK_ST_EXEC] = WORK_ST_TIMER, /* start timeout */
[WORK_ST_CANCEL] = WORK_ST_TIMER, /* start timeout */
};
+ bool res;
if (atomic_read(&wq->draining) != 0)
return (!work_pending(&dwork->work));
+ /*
+ * Clamp the delay to a valid ticks value, some consumers pass
+ * MAX_SCHEDULE_TIMEOUT.
+ */
+ if (delay > INT_MAX)
+ delay = INT_MAX;
+
+ mtx_lock(&dwork->timer.mtx);
switch (linux_update_state(&dwork->work.state, states)) {
case WORK_ST_EXEC:
case WORK_ST_CANCEL:
- if (delay == 0 && linux_work_exec_unblock(&dwork->work) != 0) {
+ if (delay == 0 && linux_work_exec_unblock(&dwork->work)) {
dwork->timer.expires = jiffies;
- return (true);
+ res = true;
+ goto out;
}
/* FALLTHROUGH */
case WORK_ST_IDLE:
@@ -242,20 +250,21 @@ linux_queue_delayed_work_on(int cpu, struct workqueue_struct *wq,
if (delay == 0) {
linux_delayed_work_enqueue(dwork);
} else if (unlikely(cpu != WORK_CPU_UNBOUND)) {
- mtx_lock(&dwork->timer.mtx);
callout_reset_on(&dwork->timer.callout, delay,
&linux_delayed_work_timer_fn, dwork, cpu);
- mtx_unlock(&dwork->timer.mtx);
} else {
- mtx_lock(&dwork->timer.mtx);
callout_reset(&dwork->timer.callout, delay,
&linux_delayed_work_timer_fn, dwork);
- mtx_unlock(&dwork->timer.mtx);
}
- return (true);
+ res = true;
+ break;
default:
- return (false); /* already on a queue */
+ res = false;
+ break;
}
+out:
+ mtx_unlock(&dwork->timer.mtx);
+ return (res);
}
void
@@ -359,6 +368,38 @@ linux_delayed_work_timer_fn(void *arg)
}
/*
+ * This function cancels the given work structure in a
+ * non-blocking fashion. It returns non-zero if the work was
+ * successfully cancelled. Else the work may still be busy or already
+ * cancelled.
+ */
+bool
+linux_cancel_work(struct work_struct *work)
+{
+ static const uint8_t states[WORK_ST_MAX] __aligned(8) = {
+ [WORK_ST_IDLE] = WORK_ST_IDLE, /* NOP */
+ [WORK_ST_TIMER] = WORK_ST_TIMER, /* can't happen */
+ [WORK_ST_TASK] = WORK_ST_IDLE, /* cancel */
+ [WORK_ST_EXEC] = WORK_ST_EXEC, /* NOP */
+ [WORK_ST_CANCEL] = WORK_ST_IDLE, /* can't happen */
+ };
+ struct taskqueue *tq;
+
+ MPASS(atomic_read(&work->state) != WORK_ST_TIMER);
+ MPASS(atomic_read(&work->state) != WORK_ST_CANCEL);
+
+ switch (linux_update_state(&work->state, states)) {
+ case WORK_ST_TASK:
+ tq = work->work_queue->taskqueue;
+ if (taskqueue_cancel(tq, &work->work_task, NULL) == 0)
+ return (true);
+ /* FALLTHROUGH */
+ default:
+ return (false);
+ }
+}
+
+/*
* This function cancels the given work structure in a synchronous
* fashion. It returns non-zero if the work was successfully
* cancelled. Else the work was already cancelled.
@@ -466,11 +507,11 @@ linux_cancel_delayed_work(struct delayed_work *dwork)
/*
* This function cancels the given work structure in a synchronous
- * fashion. It returns non-zero if the work was successfully
+ * fashion. It returns true if the work was successfully
* cancelled. Else the work was already cancelled.
*/
-bool
-linux_cancel_delayed_work_sync(struct delayed_work *dwork)
+static bool
+linux_cancel_delayed_work_sync_int(struct delayed_work *dwork)
{
static const uint8_t states[WORK_ST_MAX] __aligned(8) = {
[WORK_ST_IDLE] = WORK_ST_IDLE, /* NOP */
@@ -480,7 +521,6 @@ linux_cancel_delayed_work_sync(struct delayed_work *dwork)
[WORK_ST_CANCEL] = WORK_ST_IDLE, /* cancel and drain */
};
struct taskqueue *tq;
- bool retval = false;
int ret, state;
bool cancelled;
@@ -492,7 +532,7 @@ linux_cancel_delayed_work_sync(struct delayed_work *dwork)
switch (state) {
case WORK_ST_IDLE:
mtx_unlock(&dwork->timer.mtx);
- return (retval);
+ return (false);
case WORK_ST_TIMER:
case WORK_ST_CANCEL:
cancelled = (callout_stop(&dwork->timer.callout) == 1);
@@ -514,6 +554,17 @@ linux_cancel_delayed_work_sync(struct delayed_work *dwork)
}
}
+bool
+linux_cancel_delayed_work_sync(struct delayed_work *dwork)
+{
+ bool res;
+
+ res = false;
+ while (linux_cancel_delayed_work_sync_int(dwork))
+ res = true;
+ return (res);
+}
+
/*
* This function waits until the given work structure is completed.
* It returns non-zero if the work was successfully
diff --git a/sys/compat/linuxkpi/common/src/linux_xarray.c b/sys/compat/linuxkpi/common/src/linux_xarray.c
index 52be490c100e..3f07f6d7c59f 100644
--- a/sys/compat/linuxkpi/common/src/linux_xarray.c
+++ b/sys/compat/linuxkpi/common/src/linux_xarray.c
@@ -25,22 +25,38 @@
*/
#include <sys/cdefs.h>
-__FBSDID("$FreeBSD$");
-
#include <linux/xarray.h>
#include <vm/vm_pageout.h>
/*
+ * Linux' XArray allows to store a NULL pointer as a value. xa_load() would
+ * return NULL for both an unused index and an index set to NULL. But it
+ * impacts xa_alloc() which needs to find the next available index.
+ *
+ * However, our implementation relies on a radix tree (see `linux_radix.c`)
+ * which does not accept NULL pointers as values. I'm not sure this is a
+ * limitation or a feature, so to work around this, a NULL value is replaced by
+ * `NULL_VALUE`, an unlikely address, when we pass it to linux_radix.
+ */
+#define NULL_VALUE (void *)0x1
+
+/*
* This function removes the element at the given index and returns
* the pointer to the removed element, if any.
*/
void *
__xa_erase(struct xarray *xa, uint32_t index)
{
+ void *retval;
+
XA_ASSERT_LOCKED(xa);
- return (radix_tree_delete(&xa->root, index));
+ retval = radix_tree_delete(&xa->xa_head, index);
+ if (retval == NULL_VALUE)
+ retval = NULL;
+
+ return (retval);
}
void *
@@ -65,9 +81,12 @@ xa_load(struct xarray *xa, uint32_t index)
void *retval;
xa_lock(xa);
- retval = radix_tree_lookup(&xa->root, index);
+ retval = radix_tree_lookup(&xa->xa_head, index);
xa_unlock(xa);
+ if (retval == NULL_VALUE)
+ retval = NULL;
+
return (retval);
}
@@ -102,15 +121,17 @@ __xa_alloc(struct xarray *xa, uint32_t *pindex, void *ptr, uint32_t mask, gfp_t
XA_ASSERT_LOCKED(xa);
- /* mask cannot be zero */
- MPASS(mask != 0);
+ /* mask should allow to allocate at least one item */
+ MPASS(mask > ((xa->xa_flags & XA_FLAGS_ALLOC1) != 0 ? 1 : 0));
/* mask can be any power of two value minus one */
MPASS((mask & (mask + 1)) == 0);
- *pindex = 0;
+ *pindex = (xa->xa_flags & XA_FLAGS_ALLOC1) != 0 ? 1 : 0;
+ if (ptr == NULL)
+ ptr = NULL_VALUE;
retry:
- retval = radix_tree_insert(&xa->root, *pindex, ptr);
+ retval = radix_tree_insert(&xa->xa_head, *pindex, ptr);
switch (retval) {
case -EEXIST:
@@ -137,6 +158,9 @@ xa_alloc(struct xarray *xa, uint32_t *pindex, void *ptr, uint32_t mask, gfp_t gf
{
int retval;
+ if (ptr == NULL)
+ ptr = NULL_VALUE;
+
xa_lock(xa);
retval = __xa_alloc(xa, pindex, ptr, mask, gfp);
xa_unlock(xa);
@@ -159,15 +183,17 @@ __xa_alloc_cyclic(struct xarray *xa, uint32_t *pindex, void *ptr, uint32_t mask,
XA_ASSERT_LOCKED(xa);
- /* mask cannot be zero */
- MPASS(mask != 0);
+ /* mask should allow to allocate at least one item */
+ MPASS(mask > ((xa->xa_flags & XA_FLAGS_ALLOC1) != 0 ? 1 : 0));
/* mask can be any power of two value minus one */
MPASS((mask & (mask + 1)) == 0);
- *pnext_index = 0;
+ *pnext_index = (xa->xa_flags & XA_FLAGS_ALLOC1) != 0 ? 1 : 0;
+ if (ptr == NULL)
+ ptr = NULL_VALUE;
retry:
- retval = radix_tree_insert(&xa->root, *pnext_index, ptr);
+ retval = radix_tree_insert(&xa->xa_head, *pnext_index, ptr);
switch (retval) {
case -EEXIST:
@@ -177,6 +203,8 @@ retry:
}
(*pnext_index)++;
(*pnext_index) &= mask;
+ if (*pnext_index == 0 && (xa->xa_flags & XA_FLAGS_ALLOC1) != 0)
+ (*pnext_index)++;
goto retry;
case -ENOMEM:
if (likely(gfp & M_WAITOK)) {
@@ -205,6 +233,19 @@ xa_alloc_cyclic(struct xarray *xa, uint32_t *pindex, void *ptr, uint32_t mask,
return (retval);
}
+int
+xa_alloc_cyclic_irq(struct xarray *xa, uint32_t *pindex, void *ptr,
+ uint32_t mask, uint32_t *pnext_index, gfp_t gfp)
+{
+ int retval;
+
+ xa_lock_irq(xa);
+ retval = __xa_alloc_cyclic(xa, pindex, ptr, mask, pnext_index, gfp);
+ xa_unlock_irq(xa);
+
+ return (retval);
+}
+
/*
* This function tries to insert an element at the given index. The
* "gfp" argument basically decides of this function can sleep or not
@@ -218,8 +259,10 @@ __xa_insert(struct xarray *xa, uint32_t index, void *ptr, gfp_t gfp)
int retval;
XA_ASSERT_LOCKED(xa);
+ if (ptr == NULL)
+ ptr = NULL_VALUE;
retry:
- retval = radix_tree_insert(&xa->root, index, ptr);
+ retval = radix_tree_insert(&xa->xa_head, index, ptr);
switch (retval) {
case -ENOMEM:
@@ -260,11 +303,15 @@ __xa_store(struct xarray *xa, uint32_t index, void *ptr, gfp_t gfp)
int retval;
XA_ASSERT_LOCKED(xa);
+ if (ptr == NULL)
+ ptr = NULL_VALUE;
retry:
- retval = radix_tree_store(&xa->root, index, &ptr);
+ retval = radix_tree_store(&xa->xa_head, index, &ptr);
switch (retval) {
case 0:
+ if (ptr == NULL_VALUE)
+ ptr = NULL;
break;
case -ENOMEM:
if (likely(gfp & M_WAITOK)) {
@@ -300,8 +347,9 @@ xa_init_flags(struct xarray *xa, uint32_t flags)
{
memset(xa, 0, sizeof(*xa));
- mtx_init(&xa->mtx, "lkpi-xarray", NULL, MTX_DEF | MTX_RECURSE);
- xa->root.gfp_mask = GFP_NOWAIT;
+ mtx_init(&xa->xa_lock, "lkpi-xarray", NULL, MTX_DEF | MTX_RECURSE);
+ xa->xa_head.gfp_mask = GFP_NOWAIT;
+ xa->xa_flags = flags;
}
/*
@@ -314,9 +362,19 @@ xa_destroy(struct xarray *xa)
struct radix_tree_iter iter;
void **ppslot;
- radix_tree_for_each_slot(ppslot, &xa->root, &iter, 0)
- radix_tree_iter_delete(&xa->root, &iter, ppslot);
- mtx_destroy(&xa->mtx);
+ xa_lock(xa);
+ radix_tree_for_each_slot(ppslot, &xa->xa_head, &iter, 0)
+ radix_tree_iter_delete(&xa->xa_head, &iter, ppslot);
+ xa_unlock(xa);
+
+ /*
+ * The mutex initialized in `xa_init_flags()` is not destroyed here on
+ * purpose. The reason is that on Linux, the xarray remains usable
+ * after a call to `xa_destroy()`. For instance the i915 DRM driver
+ * relies on that during the initialixation of its GuC. Basically,
+ * `xa_destroy()` "resets" the structure to zero but doesn't really
+ * destroy it.
+ */
}
/*
@@ -331,7 +389,7 @@ __xa_empty(struct xarray *xa)
XA_ASSERT_LOCKED(xa);
- return (!radix_tree_iter_find(&xa->root, &iter, &temp));
+ return (!radix_tree_iter_find(&xa->xa_head, &iter, &temp));
}
bool
@@ -368,9 +426,11 @@ __xa_next(struct xarray *xa, unsigned long *pindex, bool not_first)
return (NULL);
}
- found = radix_tree_iter_find(&xa->root, &iter, &ppslot);
+ found = radix_tree_iter_find(&xa->xa_head, &iter, &ppslot);
if (likely(found)) {
retval = *ppslot;
+ if (retval == NULL_VALUE)
+ retval = NULL;
*pindex = iter.index;
} else {
retval = NULL;
diff --git a/sys/compat/linuxkpi/common/src/linuxkpi_hdmikmod.c b/sys/compat/linuxkpi/common/src/linuxkpi_hdmikmod.c
new file mode 100644
index 000000000000..b0d4c013a6f3
--- /dev/null
+++ b/sys/compat/linuxkpi/common/src/linuxkpi_hdmikmod.c
@@ -0,0 +1,7 @@
+/* Public domain. */
+
+#include <sys/param.h>
+#include <sys/module.h>
+
+MODULE_VERSION(linuxkpi_hdmi, 1);
+MODULE_DEPEND(linuxkpi_hdmi, linuxkpi, 1, 1, 1);
diff --git a/sys/compat/linuxkpi/common/src/linuxkpi_videokmod.c b/sys/compat/linuxkpi/common/src/linuxkpi_videokmod.c
new file mode 100644
index 000000000000..8881adc0d657
--- /dev/null
+++ b/sys/compat/linuxkpi/common/src/linuxkpi_videokmod.c
@@ -0,0 +1,7 @@
+/* Public domain. */
+
+#include <sys/param.h>
+#include <sys/module.h>
+
+MODULE_VERSION(linuxkpi_video, 1);
+MODULE_DEPEND(linuxkpi_video, linuxkpi, 1, 1, 1);
diff --git a/sys/compat/linuxkpi/common/src/lkpi_iic_if.m b/sys/compat/linuxkpi/common/src/lkpi_iic_if.m
new file mode 100644
index 000000000000..64db427864db
--- /dev/null
+++ b/sys/compat/linuxkpi/common/src/lkpi_iic_if.m
@@ -0,0 +1,41 @@
+#-
+# SPDX-License-Identifier: BSD-2-Clause
+#
+# Copyright (c) 2021 Beckhoff Automation GmbH & Co. KG
+#
+# Redistribution and use in source and binary forms, with or without
+# modification, are permitted provided that the following conditions
+# are met:
+# 1. Redistributions of source code must retain the above copyright
+# notice, this list of conditions and the following disclaimer.
+# 2. Redistributions in binary form must reproduce the above copyright
+# notice, this list of conditions and the following disclaimer in the
+# documentation and/or other materials provided with the distribution.
+#
+# THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``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 OR CONTRIBUTORS 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.
+#
+
+INTERFACE lkpi_iic;
+
+HEADER {
+ struct i2c_adapter;
+}
+
+METHOD int add_adapter {
+ device_t dev;
+ struct i2c_adapter *adapter;
+};
+
+METHOD struct i2c_adapter * get_adapter {
+ device_t dev;
+};
diff --git a/sys/compat/linuxkpi/dummy/include/acpi/button.h b/sys/compat/linuxkpi/dummy/include/acpi/button.h
new file mode 100644
index 000000000000..e69de29bb2d1
--- /dev/null
+++ b/sys/compat/linuxkpi/dummy/include/acpi/button.h
diff --git a/sys/compat/linuxkpi/dummy/include/asm/agp.h b/sys/compat/linuxkpi/dummy/include/asm/agp.h
new file mode 100644
index 000000000000..e69de29bb2d1
--- /dev/null
+++ b/sys/compat/linuxkpi/dummy/include/asm/agp.h
diff --git a/sys/compat/linuxkpi/dummy/include/asm/cacheflush.h b/sys/compat/linuxkpi/dummy/include/asm/cacheflush.h
new file mode 100644
index 000000000000..e69de29bb2d1
--- /dev/null
+++ b/sys/compat/linuxkpi/dummy/include/asm/cacheflush.h
diff --git a/sys/compat/linuxkpi/dummy/include/asm/div64.h b/sys/compat/linuxkpi/dummy/include/asm/div64.h
new file mode 100644
index 000000000000..e69de29bb2d1
--- /dev/null
+++ b/sys/compat/linuxkpi/dummy/include/asm/div64.h
diff --git a/sys/compat/linuxkpi/dummy/include/asm/intel-mid.h b/sys/compat/linuxkpi/dummy/include/asm/intel-mid.h
new file mode 100644
index 000000000000..e69de29bb2d1
--- /dev/null
+++ b/sys/compat/linuxkpi/dummy/include/asm/intel-mid.h
diff --git a/sys/compat/linuxkpi/dummy/include/asm/ioctl.h b/sys/compat/linuxkpi/dummy/include/asm/ioctl.h
new file mode 100644
index 000000000000..e69de29bb2d1
--- /dev/null
+++ b/sys/compat/linuxkpi/dummy/include/asm/ioctl.h
diff --git a/sys/compat/linuxkpi/dummy/include/asm/msr-index.h b/sys/compat/linuxkpi/dummy/include/asm/msr-index.h
new file mode 100644
index 000000000000..e69de29bb2d1
--- /dev/null
+++ b/sys/compat/linuxkpi/dummy/include/asm/msr-index.h
diff --git a/sys/compat/linuxkpi/dummy/include/asm/tsc.h b/sys/compat/linuxkpi/dummy/include/asm/tsc.h
new file mode 100644
index 000000000000..e69de29bb2d1
--- /dev/null
+++ b/sys/compat/linuxkpi/dummy/include/asm/tsc.h
diff --git a/sys/compat/linuxkpi/dummy/include/kunit/skbuff.h b/sys/compat/linuxkpi/dummy/include/kunit/skbuff.h
new file mode 100644
index 000000000000..e69de29bb2d1
--- /dev/null
+++ b/sys/compat/linuxkpi/dummy/include/kunit/skbuff.h
diff --git a/sys/compat/linuxkpi/dummy/include/kunit/test-bug.h b/sys/compat/linuxkpi/dummy/include/kunit/test-bug.h
new file mode 100644
index 000000000000..e69de29bb2d1
--- /dev/null
+++ b/sys/compat/linuxkpi/dummy/include/kunit/test-bug.h
diff --git a/sys/compat/linuxkpi/dummy/include/kunit/test.h b/sys/compat/linuxkpi/dummy/include/kunit/test.h
new file mode 100644
index 000000000000..e69de29bb2d1
--- /dev/null
+++ b/sys/compat/linuxkpi/dummy/include/kunit/test.h
diff --git a/sys/compat/linuxkpi/dummy/include/kunit/visibility.h b/sys/compat/linuxkpi/dummy/include/kunit/visibility.h
new file mode 100644
index 000000000000..e69de29bb2d1
--- /dev/null
+++ b/sys/compat/linuxkpi/dummy/include/kunit/visibility.h
diff --git a/sys/compat/linuxkpi/dummy/include/linux/aer.h b/sys/compat/linuxkpi/dummy/include/linux/aer.h
new file mode 100644
index 000000000000..e69de29bb2d1
--- /dev/null
+++ b/sys/compat/linuxkpi/dummy/include/linux/aer.h
diff --git a/sys/compat/linuxkpi/dummy/include/linux/ascii85.h b/sys/compat/linuxkpi/dummy/include/linux/ascii85.h
new file mode 100644
index 000000000000..e69de29bb2d1
--- /dev/null
+++ b/sys/compat/linuxkpi/dummy/include/linux/ascii85.h
diff --git a/sys/compat/linuxkpi/dummy/include/linux/async.h b/sys/compat/linuxkpi/dummy/include/linux/async.h
new file mode 100644
index 000000000000..e69de29bb2d1
--- /dev/null
+++ b/sys/compat/linuxkpi/dummy/include/linux/async.h
diff --git a/sys/compat/linuxkpi/dummy/include/linux/bits.h b/sys/compat/linuxkpi/dummy/include/linux/bits.h
new file mode 100644
index 000000000000..e69de29bb2d1
--- /dev/null
+++ b/sys/compat/linuxkpi/dummy/include/linux/bits.h
diff --git a/sys/compat/linuxkpi/dummy/include/linux/bug.h b/sys/compat/linuxkpi/dummy/include/linux/bug.h
new file mode 100644
index 000000000000..e69de29bb2d1
--- /dev/null
+++ b/sys/compat/linuxkpi/dummy/include/linux/bug.h
diff --git a/sys/compat/linuxkpi/dummy/include/linux/byteorder/generic.h b/sys/compat/linuxkpi/dummy/include/linux/byteorder/generic.h
new file mode 100644
index 000000000000..e69de29bb2d1
--- /dev/null
+++ b/sys/compat/linuxkpi/dummy/include/linux/byteorder/generic.h
diff --git a/sys/compat/linuxkpi/dummy/include/linux/component.h b/sys/compat/linuxkpi/dummy/include/linux/component.h
new file mode 100644
index 000000000000..e69de29bb2d1
--- /dev/null
+++ b/sys/compat/linuxkpi/dummy/include/linux/component.h
diff --git a/sys/compat/linuxkpi/dummy/include/linux/const.h b/sys/compat/linuxkpi/dummy/include/linux/const.h
new file mode 100644
index 000000000000..e69de29bb2d1
--- /dev/null
+++ b/sys/compat/linuxkpi/dummy/include/linux/const.h
diff --git a/sys/compat/linuxkpi/dummy/include/linux/cpufreq.h b/sys/compat/linuxkpi/dummy/include/linux/cpufreq.h
new file mode 100644
index 000000000000..e69de29bb2d1
--- /dev/null
+++ b/sys/compat/linuxkpi/dummy/include/linux/cpufreq.h
diff --git a/sys/compat/linuxkpi/dummy/include/linux/ctype.h b/sys/compat/linuxkpi/dummy/include/linux/ctype.h
new file mode 100644
index 000000000000..e69de29bb2d1
--- /dev/null
+++ b/sys/compat/linuxkpi/dummy/include/linux/ctype.h
diff --git a/sys/compat/linuxkpi/dummy/include/linux/debugobjects.h b/sys/compat/linuxkpi/dummy/include/linux/debugobjects.h
new file mode 100644
index 000000000000..e69de29bb2d1
--- /dev/null
+++ b/sys/compat/linuxkpi/dummy/include/linux/debugobjects.h
diff --git a/sys/compat/linuxkpi/dummy/include/linux/dev_printk.h b/sys/compat/linuxkpi/dummy/include/linux/dev_printk.h
new file mode 100644
index 000000000000..e69de29bb2d1
--- /dev/null
+++ b/sys/compat/linuxkpi/dummy/include/linux/dev_printk.h
diff --git a/sys/compat/linuxkpi/dummy/include/linux/device/bus.h b/sys/compat/linuxkpi/dummy/include/linux/device/bus.h
new file mode 100644
index 000000000000..e69de29bb2d1
--- /dev/null
+++ b/sys/compat/linuxkpi/dummy/include/linux/device/bus.h
diff --git a/sys/compat/linuxkpi/dummy/include/linux/dma-direction.h b/sys/compat/linuxkpi/dummy/include/linux/dma-direction.h
new file mode 100644
index 000000000000..e69de29bb2d1
--- /dev/null
+++ b/sys/compat/linuxkpi/dummy/include/linux/dma-direction.h
diff --git a/sys/compat/linuxkpi/dummy/include/linux/elf.h b/sys/compat/linuxkpi/dummy/include/linux/elf.h
new file mode 100644
index 000000000000..e69de29bb2d1
--- /dev/null
+++ b/sys/compat/linuxkpi/dummy/include/linux/elf.h
diff --git a/sys/compat/linuxkpi/dummy/include/linux/eventfd.h b/sys/compat/linuxkpi/dummy/include/linux/eventfd.h
new file mode 100644
index 000000000000..e69de29bb2d1
--- /dev/null
+++ b/sys/compat/linuxkpi/dummy/include/linux/eventfd.h
diff --git a/sys/compat/linuxkpi/dummy/include/linux/fault-inject.h b/sys/compat/linuxkpi/dummy/include/linux/fault-inject.h
new file mode 100644
index 000000000000..e69de29bb2d1
--- /dev/null
+++ b/sys/compat/linuxkpi/dummy/include/linux/fault-inject.h
diff --git a/sys/compat/linuxkpi/dummy/include/linux/fdtable.h b/sys/compat/linuxkpi/dummy/include/linux/fdtable.h
new file mode 100644
index 000000000000..e69de29bb2d1
--- /dev/null
+++ b/sys/compat/linuxkpi/dummy/include/linux/fdtable.h
diff --git a/sys/compat/linuxkpi/dummy/include/linux/hmm.h b/sys/compat/linuxkpi/dummy/include/linux/hmm.h
new file mode 100644
index 000000000000..e69de29bb2d1
--- /dev/null
+++ b/sys/compat/linuxkpi/dummy/include/linux/hmm.h
diff --git a/sys/compat/linuxkpi/dummy/include/linux/hwmon-sysfs.h b/sys/compat/linuxkpi/dummy/include/linux/hwmon-sysfs.h
new file mode 100644
index 000000000000..e69de29bb2d1
--- /dev/null
+++ b/sys/compat/linuxkpi/dummy/include/linux/hwmon-sysfs.h
diff --git a/sys/compat/linuxkpi/dummy/include/linux/hwmon.h b/sys/compat/linuxkpi/dummy/include/linux/hwmon.h
new file mode 100644
index 000000000000..e69de29bb2d1
--- /dev/null
+++ b/sys/compat/linuxkpi/dummy/include/linux/hwmon.h
diff --git a/sys/compat/linuxkpi/dummy/include/linux/if.h b/sys/compat/linuxkpi/dummy/include/linux/if.h
new file mode 100644
index 000000000000..e69de29bb2d1
--- /dev/null
+++ b/sys/compat/linuxkpi/dummy/include/linux/if.h
diff --git a/sys/compat/linuxkpi/dummy/include/linux/init.h b/sys/compat/linuxkpi/dummy/include/linux/init.h
new file mode 100644
index 000000000000..e69de29bb2d1
--- /dev/null
+++ b/sys/compat/linuxkpi/dummy/include/linux/init.h
diff --git a/sys/compat/linuxkpi/dummy/include/linux/input.h b/sys/compat/linuxkpi/dummy/include/linux/input.h
new file mode 100644
index 000000000000..e69de29bb2d1
--- /dev/null
+++ b/sys/compat/linuxkpi/dummy/include/linux/input.h
diff --git a/sys/compat/linuxkpi/dummy/include/linux/intel-iommu.h b/sys/compat/linuxkpi/dummy/include/linux/intel-iommu.h
new file mode 100644
index 000000000000..e69de29bb2d1
--- /dev/null
+++ b/sys/compat/linuxkpi/dummy/include/linux/intel-iommu.h
diff --git a/sys/compat/linuxkpi/dummy/include/linux/irq.h b/sys/compat/linuxkpi/dummy/include/linux/irq.h
new file mode 100644
index 000000000000..e69de29bb2d1
--- /dev/null
+++ b/sys/compat/linuxkpi/dummy/include/linux/irq.h
diff --git a/sys/compat/linuxkpi/dummy/include/linux/irqflags.h b/sys/compat/linuxkpi/dummy/include/linux/irqflags.h
new file mode 100644
index 000000000000..e69de29bb2d1
--- /dev/null
+++ b/sys/compat/linuxkpi/dummy/include/linux/irqflags.h
diff --git a/sys/compat/linuxkpi/dummy/include/linux/kgdb.h b/sys/compat/linuxkpi/dummy/include/linux/kgdb.h
new file mode 100644
index 000000000000..e69de29bb2d1
--- /dev/null
+++ b/sys/compat/linuxkpi/dummy/include/linux/kgdb.h
diff --git a/sys/compat/linuxkpi/dummy/include/linux/list_sort.h b/sys/compat/linuxkpi/dummy/include/linux/list_sort.h
new file mode 100644
index 000000000000..e69de29bb2d1
--- /dev/null
+++ b/sys/compat/linuxkpi/dummy/include/linux/list_sort.h
diff --git a/sys/compat/linuxkpi/dummy/include/linux/mei_aux.h b/sys/compat/linuxkpi/dummy/include/linux/mei_aux.h
new file mode 100644
index 000000000000..e69de29bb2d1
--- /dev/null
+++ b/sys/compat/linuxkpi/dummy/include/linux/mei_aux.h
diff --git a/sys/compat/linuxkpi/dummy/include/linux/mem_encrypt.h b/sys/compat/linuxkpi/dummy/include/linux/mem_encrypt.h
new file mode 100644
index 000000000000..e69de29bb2d1
--- /dev/null
+++ b/sys/compat/linuxkpi/dummy/include/linux/mem_encrypt.h
diff --git a/sys/compat/linuxkpi/dummy/include/linux/mempolicy.h b/sys/compat/linuxkpi/dummy/include/linux/mempolicy.h
new file mode 100644
index 000000000000..e69de29bb2d1
--- /dev/null
+++ b/sys/compat/linuxkpi/dummy/include/linux/mempolicy.h
diff --git a/sys/compat/linuxkpi/dummy/include/linux/memremap.h b/sys/compat/linuxkpi/dummy/include/linux/memremap.h
new file mode 100644
index 000000000000..e69de29bb2d1
--- /dev/null
+++ b/sys/compat/linuxkpi/dummy/include/linux/memremap.h
diff --git a/sys/compat/linuxkpi/dummy/include/linux/mfd/core.h b/sys/compat/linuxkpi/dummy/include/linux/mfd/core.h
new file mode 100644
index 000000000000..e69de29bb2d1
--- /dev/null
+++ b/sys/compat/linuxkpi/dummy/include/linux/mfd/core.h
diff --git a/sys/compat/linuxkpi/dummy/include/linux/mfd/intel_soc_pmic.h b/sys/compat/linuxkpi/dummy/include/linux/mfd/intel_soc_pmic.h
new file mode 100644
index 000000000000..e69de29bb2d1
--- /dev/null
+++ b/sys/compat/linuxkpi/dummy/include/linux/mfd/intel_soc_pmic.h
diff --git a/sys/compat/linuxkpi/dummy/include/linux/mmc/card.h b/sys/compat/linuxkpi/dummy/include/linux/mmc/card.h
new file mode 100644
index 000000000000..e69de29bb2d1
--- /dev/null
+++ b/sys/compat/linuxkpi/dummy/include/linux/mmc/card.h
diff --git a/sys/compat/linuxkpi/dummy/include/linux/mmc/core.h b/sys/compat/linuxkpi/dummy/include/linux/mmc/core.h
new file mode 100644
index 000000000000..e69de29bb2d1
--- /dev/null
+++ b/sys/compat/linuxkpi/dummy/include/linux/mmc/core.h
diff --git a/sys/compat/linuxkpi/dummy/include/linux/mmc/host.h b/sys/compat/linuxkpi/dummy/include/linux/mmc/host.h
new file mode 100644
index 000000000000..e69de29bb2d1
--- /dev/null
+++ b/sys/compat/linuxkpi/dummy/include/linux/mmc/host.h
diff --git a/sys/compat/linuxkpi/dummy/include/linux/mmc/mmc.h b/sys/compat/linuxkpi/dummy/include/linux/mmc/mmc.h
new file mode 100644
index 000000000000..e69de29bb2d1
--- /dev/null
+++ b/sys/compat/linuxkpi/dummy/include/linux/mmc/mmc.h
diff --git a/sys/compat/linuxkpi/dummy/include/linux/mmc/sd.h b/sys/compat/linuxkpi/dummy/include/linux/mmc/sd.h
new file mode 100644
index 000000000000..e69de29bb2d1
--- /dev/null
+++ b/sys/compat/linuxkpi/dummy/include/linux/mmc/sd.h
diff --git a/sys/compat/linuxkpi/dummy/include/linux/mmc/sdio.h b/sys/compat/linuxkpi/dummy/include/linux/mmc/sdio.h
new file mode 100644
index 000000000000..e69de29bb2d1
--- /dev/null
+++ b/sys/compat/linuxkpi/dummy/include/linux/mmc/sdio.h
diff --git a/sys/compat/linuxkpi/dummy/include/linux/mmc/sdio_func.h b/sys/compat/linuxkpi/dummy/include/linux/mmc/sdio_func.h
new file mode 100644
index 000000000000..e69de29bb2d1
--- /dev/null
+++ b/sys/compat/linuxkpi/dummy/include/linux/mmc/sdio_func.h
diff --git a/sys/compat/linuxkpi/dummy/include/linux/mmc/sdio_ids.h b/sys/compat/linuxkpi/dummy/include/linux/mmc/sdio_ids.h
new file mode 100644
index 000000000000..e69de29bb2d1
--- /dev/null
+++ b/sys/compat/linuxkpi/dummy/include/linux/mmc/sdio_ids.h
diff --git a/sys/compat/linuxkpi/dummy/include/linux/mount.h b/sys/compat/linuxkpi/dummy/include/linux/mount.h
new file mode 100644
index 000000000000..e69de29bb2d1
--- /dev/null
+++ b/sys/compat/linuxkpi/dummy/include/linux/mount.h
diff --git a/sys/compat/linuxkpi/dummy/include/linux/msi.h b/sys/compat/linuxkpi/dummy/include/linux/msi.h
new file mode 100644
index 000000000000..e69de29bb2d1
--- /dev/null
+++ b/sys/compat/linuxkpi/dummy/include/linux/msi.h
diff --git a/sys/compat/linuxkpi/dummy/include/linux/nmi.h b/sys/compat/linuxkpi/dummy/include/linux/nmi.h
new file mode 100644
index 000000000000..e69de29bb2d1
--- /dev/null
+++ b/sys/compat/linuxkpi/dummy/include/linux/nmi.h
diff --git a/sys/compat/linuxkpi/dummy/include/linux/nvmem-consumer.h b/sys/compat/linuxkpi/dummy/include/linux/nvmem-consumer.h
new file mode 100644
index 000000000000..e69de29bb2d1
--- /dev/null
+++ b/sys/compat/linuxkpi/dummy/include/linux/nvmem-consumer.h
diff --git a/sys/compat/linuxkpi/dummy/include/linux/of_address.h b/sys/compat/linuxkpi/dummy/include/linux/of_address.h
new file mode 100644
index 000000000000..e69de29bb2d1
--- /dev/null
+++ b/sys/compat/linuxkpi/dummy/include/linux/of_address.h
diff --git a/sys/compat/linuxkpi/dummy/include/linux/of_device.h b/sys/compat/linuxkpi/dummy/include/linux/of_device.h
new file mode 100644
index 000000000000..e69de29bb2d1
--- /dev/null
+++ b/sys/compat/linuxkpi/dummy/include/linux/of_device.h
diff --git a/sys/compat/linuxkpi/dummy/include/linux/of_irq.h b/sys/compat/linuxkpi/dummy/include/linux/of_irq.h
new file mode 100644
index 000000000000..e69de29bb2d1
--- /dev/null
+++ b/sys/compat/linuxkpi/dummy/include/linux/of_irq.h
diff --git a/sys/compat/linuxkpi/dummy/include/linux/of_net.h b/sys/compat/linuxkpi/dummy/include/linux/of_net.h
new file mode 100644
index 000000000000..e69de29bb2d1
--- /dev/null
+++ b/sys/compat/linuxkpi/dummy/include/linux/of_net.h
diff --git a/sys/compat/linuxkpi/dummy/include/linux/oom.h b/sys/compat/linuxkpi/dummy/include/linux/oom.h
new file mode 100644
index 000000000000..e69de29bb2d1
--- /dev/null
+++ b/sys/compat/linuxkpi/dummy/include/linux/oom.h
diff --git a/sys/compat/linuxkpi/dummy/include/linux/pci-p2pdma.h b/sys/compat/linuxkpi/dummy/include/linux/pci-p2pdma.h
new file mode 100644
index 000000000000..e69de29bb2d1
--- /dev/null
+++ b/sys/compat/linuxkpi/dummy/include/linux/pci-p2pdma.h
diff --git a/sys/compat/linuxkpi/dummy/include/linux/pgtable.h b/sys/compat/linuxkpi/dummy/include/linux/pgtable.h
new file mode 100644
index 000000000000..e69de29bb2d1
--- /dev/null
+++ b/sys/compat/linuxkpi/dummy/include/linux/pgtable.h
diff --git a/sys/compat/linuxkpi/dummy/include/linux/pnp.h b/sys/compat/linuxkpi/dummy/include/linux/pnp.h
new file mode 100644
index 000000000000..e69de29bb2d1
--- /dev/null
+++ b/sys/compat/linuxkpi/dummy/include/linux/pnp.h
diff --git a/sys/compat/linuxkpi/dummy/include/linux/prandom.h b/sys/compat/linuxkpi/dummy/include/linux/prandom.h
new file mode 100644
index 000000000000..e69de29bb2d1
--- /dev/null
+++ b/sys/compat/linuxkpi/dummy/include/linux/prandom.h
diff --git a/sys/compat/linuxkpi/dummy/include/linux/property.h b/sys/compat/linuxkpi/dummy/include/linux/property.h
new file mode 100644
index 000000000000..e69de29bb2d1
--- /dev/null
+++ b/sys/compat/linuxkpi/dummy/include/linux/property.h
diff --git a/sys/compat/linuxkpi/dummy/include/linux/pseudo_fs.h b/sys/compat/linuxkpi/dummy/include/linux/pseudo_fs.h
new file mode 100644
index 000000000000..e69de29bb2d1
--- /dev/null
+++ b/sys/compat/linuxkpi/dummy/include/linux/pseudo_fs.h
diff --git a/sys/compat/linuxkpi/dummy/include/linux/regmap.h b/sys/compat/linuxkpi/dummy/include/linux/regmap.h
new file mode 100644
index 000000000000..e69de29bb2d1
--- /dev/null
+++ b/sys/compat/linuxkpi/dummy/include/linux/regmap.h
diff --git a/sys/compat/linuxkpi/dummy/include/linux/relay.h b/sys/compat/linuxkpi/dummy/include/linux/relay.h
new file mode 100644
index 000000000000..e69de29bb2d1
--- /dev/null
+++ b/sys/compat/linuxkpi/dummy/include/linux/relay.h
diff --git a/sys/compat/linuxkpi/dummy/include/linux/remoteproc.h b/sys/compat/linuxkpi/dummy/include/linux/remoteproc.h
new file mode 100644
index 000000000000..e69de29bb2d1
--- /dev/null
+++ b/sys/compat/linuxkpi/dummy/include/linux/remoteproc.h
diff --git a/sys/compat/linuxkpi/dummy/include/linux/rtnetlink.h b/sys/compat/linuxkpi/dummy/include/linux/rtnetlink.h
new file mode 100644
index 000000000000..e69de29bb2d1
--- /dev/null
+++ b/sys/compat/linuxkpi/dummy/include/linux/rtnetlink.h
diff --git a/sys/compat/linuxkpi/dummy/include/linux/sched/clock.h b/sys/compat/linuxkpi/dummy/include/linux/sched/clock.h
new file mode 100644
index 000000000000..e69de29bb2d1
--- /dev/null
+++ b/sys/compat/linuxkpi/dummy/include/linux/sched/clock.h
diff --git a/sys/compat/linuxkpi/dummy/include/linux/sched/signal.h b/sys/compat/linuxkpi/dummy/include/linux/sched/signal.h
new file mode 100644
index 000000000000..e69de29bb2d1
--- /dev/null
+++ b/sys/compat/linuxkpi/dummy/include/linux/sched/signal.h
diff --git a/sys/compat/linuxkpi/dummy/include/linux/sched/task.h b/sys/compat/linuxkpi/dummy/include/linux/sched/task.h
new file mode 100644
index 000000000000..e69de29bb2d1
--- /dev/null
+++ b/sys/compat/linuxkpi/dummy/include/linux/sched/task.h
diff --git a/sys/compat/linuxkpi/dummy/include/linux/spinlock_types.h b/sys/compat/linuxkpi/dummy/include/linux/spinlock_types.h
new file mode 100644
index 000000000000..e69de29bb2d1
--- /dev/null
+++ b/sys/compat/linuxkpi/dummy/include/linux/spinlock_types.h
diff --git a/sys/compat/linuxkpi/dummy/include/linux/stacktrace.h b/sys/compat/linuxkpi/dummy/include/linux/stacktrace.h
new file mode 100644
index 000000000000..e69de29bb2d1
--- /dev/null
+++ b/sys/compat/linuxkpi/dummy/include/linux/stacktrace.h
diff --git a/sys/compat/linuxkpi/dummy/include/linux/stat.h b/sys/compat/linuxkpi/dummy/include/linux/stat.h
new file mode 100644
index 000000000000..e69de29bb2d1
--- /dev/null
+++ b/sys/compat/linuxkpi/dummy/include/linux/stat.h
diff --git a/sys/compat/linuxkpi/dummy/include/linux/stop_machine.h b/sys/compat/linuxkpi/dummy/include/linux/stop_machine.h
new file mode 100644
index 000000000000..e69de29bb2d1
--- /dev/null
+++ b/sys/compat/linuxkpi/dummy/include/linux/stop_machine.h
diff --git a/sys/compat/linuxkpi/dummy/include/linux/swiotlb.h b/sys/compat/linuxkpi/dummy/include/linux/swiotlb.h
new file mode 100644
index 000000000000..e69de29bb2d1
--- /dev/null
+++ b/sys/compat/linuxkpi/dummy/include/linux/swiotlb.h
diff --git a/sys/compat/linuxkpi/dummy/include/linux/syscalls.h b/sys/compat/linuxkpi/dummy/include/linux/syscalls.h
new file mode 100644
index 000000000000..e69de29bb2d1
--- /dev/null
+++ b/sys/compat/linuxkpi/dummy/include/linux/syscalls.h
diff --git a/sys/compat/linuxkpi/dummy/include/linux/sysfb.h b/sys/compat/linuxkpi/dummy/include/linux/sysfb.h
new file mode 100644
index 000000000000..e69de29bb2d1
--- /dev/null
+++ b/sys/compat/linuxkpi/dummy/include/linux/sysfb.h
diff --git a/sys/compat/linuxkpi/dummy/include/linux/sysrq.h b/sys/compat/linuxkpi/dummy/include/linux/sysrq.h
new file mode 100644
index 000000000000..e69de29bb2d1
--- /dev/null
+++ b/sys/compat/linuxkpi/dummy/include/linux/sysrq.h
diff --git a/sys/compat/linuxkpi/dummy/include/linux/thermal.h b/sys/compat/linuxkpi/dummy/include/linux/thermal.h
new file mode 100644
index 000000000000..e69de29bb2d1
--- /dev/null
+++ b/sys/compat/linuxkpi/dummy/include/linux/thermal.h
diff --git a/sys/compat/linuxkpi/dummy/include/linux/time64.h b/sys/compat/linuxkpi/dummy/include/linux/time64.h
new file mode 100644
index 000000000000..e69de29bb2d1
--- /dev/null
+++ b/sys/compat/linuxkpi/dummy/include/linux/time64.h
diff --git a/sys/compat/linuxkpi/dummy/include/linux/timekeeping.h b/sys/compat/linuxkpi/dummy/include/linux/timekeeping.h
new file mode 100644
index 000000000000..e69de29bb2d1
--- /dev/null
+++ b/sys/compat/linuxkpi/dummy/include/linux/timekeeping.h
diff --git a/sys/compat/linuxkpi/dummy/include/linux/tty.h b/sys/compat/linuxkpi/dummy/include/linux/tty.h
new file mode 100644
index 000000000000..e69de29bb2d1
--- /dev/null
+++ b/sys/compat/linuxkpi/dummy/include/linux/tty.h
diff --git a/sys/compat/linuxkpi/dummy/include/linux/unaligned.h b/sys/compat/linuxkpi/dummy/include/linux/unaligned.h
new file mode 100644
index 000000000000..e69de29bb2d1
--- /dev/null
+++ b/sys/compat/linuxkpi/dummy/include/linux/unaligned.h
diff --git a/sys/compat/linuxkpi/dummy/include/linux/util_macros.h b/sys/compat/linuxkpi/dummy/include/linux/util_macros.h
new file mode 100644
index 000000000000..e69de29bb2d1
--- /dev/null
+++ b/sys/compat/linuxkpi/dummy/include/linux/util_macros.h
diff --git a/sys/compat/linuxkpi/dummy/include/linux/version.h b/sys/compat/linuxkpi/dummy/include/linux/version.h
new file mode 100644
index 000000000000..e69de29bb2d1
--- /dev/null
+++ b/sys/compat/linuxkpi/dummy/include/linux/version.h
diff --git a/sys/compat/linuxkpi/dummy/include/linux/vt.h b/sys/compat/linuxkpi/dummy/include/linux/vt.h
new file mode 100644
index 000000000000..e69de29bb2d1
--- /dev/null
+++ b/sys/compat/linuxkpi/dummy/include/linux/vt.h
diff --git a/sys/compat/linuxkpi/dummy/include/linux/zlib.h b/sys/compat/linuxkpi/dummy/include/linux/zlib.h
new file mode 100644
index 000000000000..e69de29bb2d1
--- /dev/null
+++ b/sys/compat/linuxkpi/dummy/include/linux/zlib.h
diff --git a/sys/compat/linuxkpi/dummy/include/media/cec-notifier.h b/sys/compat/linuxkpi/dummy/include/media/cec-notifier.h
new file mode 100644
index 000000000000..e69de29bb2d1
--- /dev/null
+++ b/sys/compat/linuxkpi/dummy/include/media/cec-notifier.h
diff --git a/sys/compat/linuxkpi/dummy/include/net/gso.h b/sys/compat/linuxkpi/dummy/include/net/gso.h
new file mode 100644
index 000000000000..e69de29bb2d1
--- /dev/null
+++ b/sys/compat/linuxkpi/dummy/include/net/gso.h
diff --git a/sys/compat/linuxkpi/dummy/include/net/page_pool/helpers.h b/sys/compat/linuxkpi/dummy/include/net/page_pool/helpers.h
new file mode 100644
index 000000000000..e69de29bb2d1
--- /dev/null
+++ b/sys/compat/linuxkpi/dummy/include/net/page_pool/helpers.h
diff --git a/sys/compat/linuxkpi/dummy/include/net/rtnetlink.h b/sys/compat/linuxkpi/dummy/include/net/rtnetlink.h
new file mode 100644
index 000000000000..e69de29bb2d1
--- /dev/null
+++ b/sys/compat/linuxkpi/dummy/include/net/rtnetlink.h
diff --git a/sys/compat/linuxkpi/dummy/include/trace/define_trace.h b/sys/compat/linuxkpi/dummy/include/trace/define_trace.h
new file mode 100644
index 000000000000..e69de29bb2d1
--- /dev/null
+++ b/sys/compat/linuxkpi/dummy/include/trace/define_trace.h
diff --git a/sys/compat/linuxkpi/dummy/include/uapi/linux/if_arp.h b/sys/compat/linuxkpi/dummy/include/uapi/linux/if_arp.h
new file mode 100644
index 000000000000..e69de29bb2d1
--- /dev/null
+++ b/sys/compat/linuxkpi/dummy/include/uapi/linux/if_arp.h
diff --git a/sys/compat/linuxkpi/dummy/include/uapi/linux/sched/types.h b/sys/compat/linuxkpi/dummy/include/uapi/linux/sched/types.h
new file mode 100644
index 000000000000..e69de29bb2d1
--- /dev/null
+++ b/sys/compat/linuxkpi/dummy/include/uapi/linux/sched/types.h
diff --git a/sys/compat/linuxkpi/dummy/include/video/nomodeset.h b/sys/compat/linuxkpi/dummy/include/video/nomodeset.h
new file mode 100644
index 000000000000..e69de29bb2d1
--- /dev/null
+++ b/sys/compat/linuxkpi/dummy/include/video/nomodeset.h
diff --git a/sys/compat/linuxkpi/dummy/include/video/of_display_timing.h b/sys/compat/linuxkpi/dummy/include/video/of_display_timing.h
new file mode 100644
index 000000000000..e69de29bb2d1
--- /dev/null
+++ b/sys/compat/linuxkpi/dummy/include/video/of_display_timing.h
diff --git a/sys/compat/linuxkpi/dummy/include/video/of_videomode.h b/sys/compat/linuxkpi/dummy/include/video/of_videomode.h
new file mode 100644
index 000000000000..e69de29bb2d1
--- /dev/null
+++ b/sys/compat/linuxkpi/dummy/include/video/of_videomode.h
diff --git a/sys/compat/linuxkpi/dummy/include/video/videomode.h b/sys/compat/linuxkpi/dummy/include/video/videomode.h
new file mode 100644
index 000000000000..e69de29bb2d1
--- /dev/null
+++ b/sys/compat/linuxkpi/dummy/include/video/videomode.h
diff --git a/sys/compat/x86bios/x86bios.c b/sys/compat/x86bios/x86bios.c
index f6350b8f6388..41b72080177c 100644
--- a/sys/compat/x86bios/x86bios.c
+++ b/sys/compat/x86bios/x86bios.c
@@ -26,8 +26,6 @@
*/
#include <sys/cdefs.h>
-__FBSDID("$FreeBSD$");
-
#include "opt_x86bios.h"
#include <sys/param.h>
@@ -164,7 +162,7 @@ x86bios_free(void *addr, size_t size)
x86bios_vmc.npages--;
}
mtx_unlock(&x86bios_lock);
- contigfree(addr, size, M_DEVBUF);
+ free(addr, M_DEVBUF);
}
void
@@ -566,7 +564,7 @@ x86bios_free(void *addr, size_t size)
bzero(x86bios_map + paddr / X86BIOS_PAGE_SIZE,
sizeof(*x86bios_map) * howmany(size, X86BIOS_PAGE_SIZE));
mtx_unlock(&x86bios_lock);
- contigfree(addr, size, M_DEVBUF);
+ free(addr, M_DEVBUF);
}
void
@@ -662,16 +660,16 @@ x86bios_unmap_mem(void)
}
if (x86bios_ivt != NULL) {
#ifdef X86BIOS_NATIVE_ARCH
- pmap_unmapbios((vm_offset_t)x86bios_ivt, X86BIOS_IVT_SIZE);
+ pmap_unmapbios(x86bios_ivt, X86BIOS_IVT_SIZE);
#else
free(x86bios_ivt, M_DEVBUF);
x86bios_ivt = NULL;
#endif
}
if (x86bios_rom != NULL)
- pmap_unmapdev((vm_offset_t)x86bios_rom, X86BIOS_ROM_SIZE);
+ pmap_unmapdev(x86bios_rom, X86BIOS_ROM_SIZE);
if (x86bios_seg != NULL) {
- contigfree(x86bios_seg, X86BIOS_SEG_SIZE, M_DEVBUF);
+ free(x86bios_seg, M_DEVBUF);
x86bios_seg = NULL;
}
}
diff --git a/sys/compat/x86bios/x86bios.h b/sys/compat/x86bios/x86bios.h
index f12c800d8b33..46983589ce04 100644
--- a/sys/compat/x86bios/x86bios.h
+++ b/sys/compat/x86bios/x86bios.h
@@ -22,8 +22,6 @@
* 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.
- *
- * $FreeBSD$
*/
/*
* x86 registers were borrowed from x86emu.h x86emu_regs.h