1741367d5SDoug Ambrisko /*-
2*4d846d26SWarner Losh * SPDX-License-Identifier: BSD-2-Clause
3718cf2ccSPedro F. Giffuni *
4741367d5SDoug Ambrisko * Copyright (c) 2006 IronPort Systems
5741367d5SDoug Ambrisko * All rights reserved.
6741367d5SDoug Ambrisko *
7741367d5SDoug Ambrisko * Redistribution and use in source and binary forms, with or without
8741367d5SDoug Ambrisko * modification, are permitted provided that the following conditions
9741367d5SDoug Ambrisko * are met:
10741367d5SDoug Ambrisko * 1. Redistributions of source code must retain the above copyright
11741367d5SDoug Ambrisko * notice, this list of conditions and the following disclaimer.
12741367d5SDoug Ambrisko * 2. Redistributions in binary form must reproduce the above copyright
13741367d5SDoug Ambrisko * notice, this list of conditions and the following disclaimer in the
14741367d5SDoug Ambrisko * documentation and/or other materials provided with the distribution.
15741367d5SDoug Ambrisko *
16741367d5SDoug Ambrisko * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
17741367d5SDoug Ambrisko * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18741367d5SDoug Ambrisko * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19741367d5SDoug Ambrisko * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
20741367d5SDoug Ambrisko * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
21741367d5SDoug Ambrisko * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
22741367d5SDoug Ambrisko * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
23741367d5SDoug Ambrisko * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
24741367d5SDoug Ambrisko * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
25741367d5SDoug Ambrisko * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
26741367d5SDoug Ambrisko * SUCH DAMAGE.
27741367d5SDoug Ambrisko */
28741367d5SDoug Ambrisko
29741367d5SDoug Ambrisko #include <sys/param.h>
30741367d5SDoug Ambrisko #include <sys/systm.h>
314a144410SRobert Watson #include <sys/capsicum.h>
32741367d5SDoug Ambrisko #include <sys/conf.h>
33741367d5SDoug Ambrisko #include <sys/kernel.h>
34741367d5SDoug Ambrisko #include <sys/module.h>
35741367d5SDoug Ambrisko #include <sys/file.h>
36741367d5SDoug Ambrisko #include <sys/proc.h>
370d9a4ef3SDoug Ambrisko #include <machine/bus.h>
38741367d5SDoug Ambrisko
39741367d5SDoug Ambrisko #if defined(__amd64__) /* Assume amd64 wants 32 bit Linux */
40741367d5SDoug Ambrisko #include <machine/../linux32/linux.h>
41741367d5SDoug Ambrisko #include <machine/../linux32/linux32_proto.h>
42741367d5SDoug Ambrisko #else
43741367d5SDoug Ambrisko #include <machine/../linux/linux.h>
44741367d5SDoug Ambrisko #include <machine/../linux/linux_proto.h>
45741367d5SDoug Ambrisko #endif
46741367d5SDoug Ambrisko #include <compat/linux/linux_ioctl.h>
47741367d5SDoug Ambrisko #include <compat/linux/linux_util.h>
48741367d5SDoug Ambrisko
49c2be47f2SDoug Ambrisko #include <dev/mfi/mfireg.h>
50c2be47f2SDoug Ambrisko #include <dev/mfi/mfi_ioctl.h>
51c2be47f2SDoug Ambrisko
52741367d5SDoug Ambrisko /* There are multiple ioctl number ranges that need to be handled */
53741367d5SDoug Ambrisko #define MFI_LINUX_IOCTL_MIN 0x4d00
54741367d5SDoug Ambrisko #define MFI_LINUX_IOCTL_MAX 0x4d04
55741367d5SDoug Ambrisko
56741367d5SDoug Ambrisko static linux_ioctl_function_t mfi_linux_ioctl;
57741367d5SDoug Ambrisko static struct linux_ioctl_handler mfi_linux_handler = {mfi_linux_ioctl,
58741367d5SDoug Ambrisko MFI_LINUX_IOCTL_MIN,
59741367d5SDoug Ambrisko MFI_LINUX_IOCTL_MAX};
60741367d5SDoug Ambrisko
61741367d5SDoug Ambrisko SYSINIT (mfi_register, SI_SUB_KLD, SI_ORDER_MIDDLE,
62741367d5SDoug Ambrisko linux_ioctl_register_handler, &mfi_linux_handler);
63741367d5SDoug Ambrisko SYSUNINIT(mfi_unregister, SI_SUB_KLD, SI_ORDER_MIDDLE,
64741367d5SDoug Ambrisko linux_ioctl_unregister_handler, &mfi_linux_handler);
65741367d5SDoug Ambrisko
66741367d5SDoug Ambrisko static struct linux_device_handler mfi_device_handler =
67741367d5SDoug Ambrisko { "mfi", "megaraid_sas", "mfi0", "megaraid_sas_ioctl_node", -1, 0, 1};
68741367d5SDoug Ambrisko
69741367d5SDoug Ambrisko SYSINIT (mfi_register2, SI_SUB_KLD, SI_ORDER_MIDDLE,
70741367d5SDoug Ambrisko linux_device_register_handler, &mfi_device_handler);
71741367d5SDoug Ambrisko SYSUNINIT(mfi_unregister2, SI_SUB_KLD, SI_ORDER_MIDDLE,
72741367d5SDoug Ambrisko linux_device_unregister_handler, &mfi_device_handler);
73741367d5SDoug Ambrisko
74741367d5SDoug Ambrisko static int
mfi_linux_modevent(module_t mod,int cmd,void * data)75741367d5SDoug Ambrisko mfi_linux_modevent(module_t mod, int cmd, void *data)
76741367d5SDoug Ambrisko {
77741367d5SDoug Ambrisko return (0);
78741367d5SDoug Ambrisko }
79741367d5SDoug Ambrisko
80741367d5SDoug Ambrisko DEV_MODULE(mfi_linux, mfi_linux_modevent, NULL);
81741367d5SDoug Ambrisko MODULE_DEPEND(mfi, linux, 1, 1, 1);
82741367d5SDoug Ambrisko
83741367d5SDoug Ambrisko static int
mfi_linux_ioctl(struct thread * p,struct linux_ioctl_args * args)8400b4e54aSWarner Losh mfi_linux_ioctl(struct thread *p, struct linux_ioctl_args *args)
85741367d5SDoug Ambrisko {
867008be5bSPawel Jakub Dawidek cap_rights_t rights;
87741367d5SDoug Ambrisko struct file *fp;
88741367d5SDoug Ambrisko int error;
89c2be47f2SDoug Ambrisko u_long cmd = args->cmd;
90c2be47f2SDoug Ambrisko
91c2be47f2SDoug Ambrisko switch (cmd) {
92c2be47f2SDoug Ambrisko case MFI_LINUX_CMD:
93c2be47f2SDoug Ambrisko cmd = MFI_LINUX_CMD_2;
94c2be47f2SDoug Ambrisko break;
95c2be47f2SDoug Ambrisko case MFI_LINUX_SET_AEN:
96c2be47f2SDoug Ambrisko cmd = MFI_LINUX_SET_AEN_2;
97c2be47f2SDoug Ambrisko break;
98c2be47f2SDoug Ambrisko }
99741367d5SDoug Ambrisko
1006b3a9a0fSMateusz Guzik error = fget(p, args->fd, cap_rights_init_one(&rights, CAP_IOCTL), &fp);
1017008be5bSPawel Jakub Dawidek if (error != 0)
102741367d5SDoug Ambrisko return (error);
103c2be47f2SDoug Ambrisko error = fo_ioctl(fp, cmd, (caddr_t)args->arg, p->td_ucred, p);
104741367d5SDoug Ambrisko fdrop(fp, p);
105741367d5SDoug Ambrisko return (error);
106741367d5SDoug Ambrisko }
107