2014-10-08 09:19:35 +00:00
|
|
|
/*
|
2015-05-06 10:45:13 +00:00
|
|
|
* Copyright (c) 2015, AVAGO Tech. All rights reserved. Author: Kashyap Desai,
|
2014-10-08 10:14:37 +00:00
|
|
|
* Copyright (c) 2014, LSI Corp. All rights reserved. Author: Kashyap Desai,
|
2015-05-06 10:45:13 +00:00
|
|
|
* Sibananda Sahu Support: freebsdraid@avagotech.com
|
2014-10-08 09:19:35 +00:00
|
|
|
*
|
|
|
|
* Redistribution and use in source and binary forms, with or without
|
2014-10-08 10:14:37 +00:00
|
|
|
* modification, are permitted provided that the following conditions are
|
|
|
|
* met:
|
2014-10-08 09:19:35 +00:00
|
|
|
*
|
2014-10-08 10:14:37 +00:00
|
|
|
* 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. 3. Neither the name of the
|
|
|
|
* <ORGANIZATION> nor the names of its contributors may be used to endorse or
|
|
|
|
* promote products derived from this software without specific prior written
|
|
|
|
* permission.
|
2014-10-08 09:19:35 +00:00
|
|
|
*
|
2014-10-08 10:14:37 +00:00
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS 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 COPYRIGHT HOLDER 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
|
2014-10-08 09:19:35 +00:00
|
|
|
* POSSIBILITY OF SUCH DAMAGE.
|
|
|
|
*
|
2014-10-08 10:14:37 +00:00
|
|
|
* The views and conclusions contained in the software and documentation are
|
|
|
|
* those of the authors and should not be interpreted as representing
|
2014-10-08 09:19:35 +00:00
|
|
|
* official policies,either expressed or implied, of the FreeBSD Project.
|
|
|
|
*
|
2015-05-06 10:45:13 +00:00
|
|
|
* Send feedback to: <megaraidfbsd@avagotech.com> Mail to: AVAGO TECHNOLOGIES, 1621
|
2014-10-08 10:14:37 +00:00
|
|
|
* Barber Lane, Milpitas, CA 95035 ATTN: MegaRaid FreeBSD
|
2014-10-08 09:19:35 +00:00
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <sys/cdefs.h>
|
2014-10-08 10:14:37 +00:00
|
|
|
__FBSDID("$FreeBSD$");
|
2014-10-08 09:19:35 +00:00
|
|
|
|
|
|
|
#include <sys/param.h>
|
|
|
|
#include <sys/systm.h>
|
|
|
|
|
2016-09-20 12:59:30 +00:00
|
|
|
#if (__FreeBSD_version >= 1001511)
|
|
|
|
#include <sys/capsicum.h>
|
|
|
|
#elif (__FreeBSD_version > 900000)
|
2017-01-23 21:09:27 +00:00
|
|
|
#include <sys/capability.h>
|
2014-10-08 09:19:35 +00:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#include <sys/conf.h>
|
|
|
|
#include <sys/kernel.h>
|
|
|
|
#include <sys/module.h>
|
|
|
|
#include <sys/file.h>
|
|
|
|
#include <sys/proc.h>
|
|
|
|
#include <machine/bus.h>
|
|
|
|
|
2014-10-08 10:14:37 +00:00
|
|
|
#if defined(__amd64__) /* Assume amd64 wants 32 bit Linux */
|
2014-10-08 09:19:35 +00:00
|
|
|
#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_ioctl.h>
|
|
|
|
#include <compat/linux/linux_util.h>
|
|
|
|
|
|
|
|
#include <dev/mrsas/mrsas.h>
|
|
|
|
#include <dev/mrsas/mrsas_ioctl.h>
|
|
|
|
|
|
|
|
/* There are multiple ioctl number ranges that need to be handled */
|
2014-10-08 10:14:37 +00:00
|
|
|
#define MRSAS_LINUX_IOCTL_MIN 0x4d00
|
|
|
|
#define MRSAS_LINUX_IOCTL_MAX 0x4d01
|
2014-10-08 09:19:35 +00:00
|
|
|
|
|
|
|
static linux_ioctl_function_t mrsas_linux_ioctl;
|
|
|
|
static struct linux_ioctl_handler mrsas_linux_handler = {mrsas_linux_ioctl,
|
2014-10-08 10:14:37 +00:00
|
|
|
MRSAS_LINUX_IOCTL_MIN,
|
|
|
|
MRSAS_LINUX_IOCTL_MAX};
|
2014-10-08 09:19:35 +00:00
|
|
|
|
2014-10-08 10:14:37 +00:00
|
|
|
SYSINIT(mrsas_register, SI_SUB_KLD, SI_ORDER_MIDDLE,
|
|
|
|
linux_ioctl_register_handler, &mrsas_linux_handler);
|
2014-10-08 09:19:35 +00:00
|
|
|
SYSUNINIT(mrsas_unregister, SI_SUB_KLD, SI_ORDER_MIDDLE,
|
2014-10-08 10:14:37 +00:00
|
|
|
linux_ioctl_unregister_handler, &mrsas_linux_handler);
|
2014-10-08 09:19:35 +00:00
|
|
|
|
|
|
|
static struct linux_device_handler mrsas_device_handler =
|
2014-10-08 10:14:37 +00:00
|
|
|
{"mrsas", "megaraid_sas", "mrsas0", "megaraid_sas_ioctl_node", -1, 0, 1};
|
2014-10-08 09:19:35 +00:00
|
|
|
|
2014-10-08 10:14:37 +00:00
|
|
|
SYSINIT(mrsas_register2, SI_SUB_KLD, SI_ORDER_MIDDLE,
|
|
|
|
linux_device_register_handler, &mrsas_device_handler);
|
2014-10-08 09:19:35 +00:00
|
|
|
SYSUNINIT(mrsas_unregister2, SI_SUB_KLD, SI_ORDER_MIDDLE,
|
2014-10-08 10:14:37 +00:00
|
|
|
linux_device_unregister_handler, &mrsas_device_handler);
|
2014-10-08 09:19:35 +00:00
|
|
|
|
|
|
|
static int
|
|
|
|
mrsas_linux_modevent(module_t mod __unused, int cmd __unused, void *data __unused)
|
|
|
|
{
|
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
2014-10-08 10:14:37 +00:00
|
|
|
/*
|
|
|
|
* mrsas_linux_ioctl: linux emulator IOCtl commands entry point.
|
|
|
|
*
|
|
|
|
* This function is the entry point for IOCtls from linux binaries.
|
|
|
|
* It calls the mrsas_ioctl function for processing
|
|
|
|
* depending on the IOCTL command received.
|
|
|
|
*/
|
2014-10-08 09:19:35 +00:00
|
|
|
static int
|
|
|
|
mrsas_linux_ioctl(struct thread *p, struct linux_ioctl_args *args)
|
|
|
|
{
|
2014-10-08 10:14:37 +00:00
|
|
|
#if (__FreeBSD_version >= 1000000)
|
2014-10-08 09:19:35 +00:00
|
|
|
cap_rights_t rights;
|
2014-10-08 10:14:37 +00:00
|
|
|
|
|
|
|
#endif
|
2014-10-08 09:19:35 +00:00
|
|
|
struct file *fp;
|
|
|
|
int error;
|
|
|
|
u_long cmd = args->cmd;
|
|
|
|
|
2014-10-08 10:14:37 +00:00
|
|
|
if (cmd != MRSAS_LINUX_CMD32) {
|
2014-10-08 09:19:35 +00:00
|
|
|
error = ENOTSUP;
|
|
|
|
goto END;
|
|
|
|
}
|
2014-10-08 10:14:37 +00:00
|
|
|
#if (__FreeBSD_version >= 1000000)
|
2014-10-08 09:19:35 +00:00
|
|
|
error = fget(p, args->fd, cap_rights_init(&rights, CAP_IOCTL), &fp);
|
2014-10-08 10:14:37 +00:00
|
|
|
#elif (__FreeBSD_version <= 900000)
|
2014-10-08 09:19:35 +00:00
|
|
|
error = fget(p, args->fd, &fp);
|
2014-10-08 10:14:37 +00:00
|
|
|
#else /* For FreeBSD version greater than
|
|
|
|
* 9.0.0 but less than 10.0.0 */
|
2014-10-08 09:19:35 +00:00
|
|
|
error = fget(p, args->fd, CAP_IOCTL, &fp);
|
2014-10-08 10:14:37 +00:00
|
|
|
#endif
|
2014-10-08 09:19:35 +00:00
|
|
|
if (error != 0)
|
|
|
|
goto END;
|
|
|
|
|
|
|
|
error = fo_ioctl(fp, cmd, (caddr_t)args->arg, p->td_ucred, p);
|
|
|
|
fdrop(fp, p);
|
|
|
|
END:
|
|
|
|
return (error);
|
|
|
|
}
|
|
|
|
|
|
|
|
DEV_MODULE(mrsas_linux, mrsas_linux_modevent, NULL);
|
|
|
|
MODULE_DEPEND(mrsas, linux, 1, 1, 1);
|