From owner-svn-src-head@freebsd.org Wed May 25 12:12:16 2016 Return-Path: Delivered-To: svn-src-head@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id 05A71B495A0; Wed, 25 May 2016 12:12:16 +0000 (UTC) (envelope-from hselasky@FreeBSD.org) Received: from repo.freebsd.org (repo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mx1.freebsd.org (Postfix) with ESMTPS id D2D0D1143; Wed, 25 May 2016 12:12:15 +0000 (UTC) (envelope-from hselasky@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id u4PCCFQo012594; Wed, 25 May 2016 12:12:15 GMT (envelope-from hselasky@FreeBSD.org) Received: (from hselasky@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id u4PCCEfJ012592; Wed, 25 May 2016 12:12:14 GMT (envelope-from hselasky@FreeBSD.org) Message-Id: <201605251212.u4PCCEfJ012592@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: hselasky set sender to hselasky@FreeBSD.org using -f From: Hans Petter Selasky Date: Wed, 25 May 2016 12:12:14 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r300677 - in head/sys/compat/linuxkpi/common: include/linux src X-SVN-Group: head MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-head@freebsd.org X-Mailman-Version: 2.1.22 Precedence: list List-Id: SVN commit messages for the src tree for head/-current List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 25 May 2016 12:12:16 -0000 Author: hselasky Date: Wed May 25 12:12:14 2016 New Revision: 300677 URL: https://svnweb.freebsd.org/changeset/base/300677 Log: Implement Linux module parameters as read-only tunable SYSCTLs. Bool module parameters are no longer supported, because there is no equivalent in FreeBSD. There are two macros available which control the behaviour of the LinuxKPI module parameters: - LINUXKPI_PARAM_PARENT allows the consumer to set the SYSCTL parent where the modules parameters will be created. - LINUXKPI_PARAM_PREFIX defines a parameter name prefix, which is added to all created module parameters. Sponsored by: Mellanox Technologies MFC after: 1 week Modified: head/sys/compat/linuxkpi/common/include/linux/moduleparam.h head/sys/compat/linuxkpi/common/src/linux_compat.c Modified: head/sys/compat/linuxkpi/common/include/linux/moduleparam.h ============================================================================== --- head/sys/compat/linuxkpi/common/include/linux/moduleparam.h Wed May 25 12:03:21 2016 (r300676) +++ head/sys/compat/linuxkpi/common/include/linux/moduleparam.h Wed May 25 12:12:14 2016 (r300677) @@ -2,7 +2,7 @@ * Copyright (c) 2010 Isilon Systems, Inc. * Copyright (c) 2010 iX Systems, Inc. * Copyright (c) 2010 Panasas, Inc. - * Copyright (c) 2013, 2014 Mellanox Technologies, Ltd. + * Copyright (c) 2013-2016 Mellanox Technologies, Ltd. * All rights reserved. * * Redistribution and use in source and binary forms, with or without @@ -31,204 +31,84 @@ #ifndef _LINUX_MODULEPARAM_H_ #define _LINUX_MODULEPARAM_H_ -#include - -/* - * These are presently not hooked up to anything. In linux the parameters - * can be set when modules are loaded. On FreeBSD these could be mapped - * to kenv in the future. - */ -struct kernel_param; - -typedef int (*param_set_fn)(const char *val, struct kernel_param *kp); -typedef int (*param_get_fn)(char *buffer, struct kernel_param *kp); - -struct kernel_param { - const char *name; - u16 perm; - u16 flags; - param_set_fn set; - param_get_fn get; - union { - void *arg; - struct kparam_string *str; - struct kparam_array *arr; - } un; -}; - -#define KPARAM_ISBOOL 2 - -struct kparam_string { - unsigned int maxlen; - char *string; -}; - -struct kparam_array -{ - unsigned int max; - unsigned int *num; - param_set_fn set; - param_get_fn get; - unsigned int elemsize; - void *elem; -}; - -static inline void -param_sysinit(struct kernel_param *param) -{ -} - -#define module_param_call(name, set, get, arg, perm) \ - static struct kernel_param __param_##name = \ - { #name, perm, 0, set, get, { arg } }; \ - SYSINIT(name##_param_sysinit, SI_SUB_DRIVERS, SI_ORDER_FIRST, \ - param_sysinit, &__param_##name); - -#define module_param_string(name, string, len, perm) - -#define module_param_named(name, var, type, mode) \ - module_param_call(name, param_set_##type, param_get_##type, &var, mode) - -#define module_param(var, type, mode) \ - module_param_named(var, var, type, mode) - -#define module_param_array(var, type, addr_argc, mode) \ - module_param_named(var, var, type, mode) - -#define MODULE_PARM_DESC(name, desc) - -static inline int -param_set_byte(const char *val, struct kernel_param *kp) -{ - - return 0; -} - -static inline int -param_get_byte(char *buffer, struct kernel_param *kp) -{ - - return 0; -} - - -static inline int -param_set_short(const char *val, struct kernel_param *kp) -{ - - return 0; -} - -static inline int -param_get_short(char *buffer, struct kernel_param *kp) -{ - - return 0; -} - - -static inline int -param_set_ushort(const char *val, struct kernel_param *kp) -{ - - return 0; -} - -static inline int -param_get_ushort(char *buffer, struct kernel_param *kp) -{ - - return 0; -} - - -static inline int -param_set_int(const char *val, struct kernel_param *kp) -{ - - return 0; -} - -static inline int -param_get_int(char *buffer, struct kernel_param *kp) -{ - - return 0; -} - - -static inline int -param_set_uint(const char *val, struct kernel_param *kp) -{ - - return 0; -} - -static inline int -param_get_uint(char *buffer, struct kernel_param *kp) -{ - - return 0; -} - - -static inline int -param_set_long(const char *val, struct kernel_param *kp) -{ - - return 0; -} - -static inline int -param_get_long(char *buffer, struct kernel_param *kp) -{ - - return 0; -} - - -static inline int -param_set_ulong(const char *val, struct kernel_param *kp) -{ - - return 0; -} - -static inline int -param_get_ulong(char *buffer, struct kernel_param *kp) -{ - - return 0; -} - - -static inline int -param_set_charp(const char *val, struct kernel_param *kp) -{ - - return 0; -} - -static inline int -param_get_charp(char *buffer, struct kernel_param *kp) -{ - - return 0; -} +#include +#include +#include -static inline int -param_set_bool(const char *val, struct kernel_param *kp) -{ +#ifndef LINUXKPI_PARAM_PARENT +#define LINUXKPI_PARAM_PARENT _compat_linuxkpi +#endif + +#ifndef LINUXKPI_PARAM_PREFIX +#define LINUXKPI_PARAM_PREFIX /* empty prefix is the default */ +#endif + +#define LINUXKPI_PARAM_CONCAT_SUB(a,b,c,d) a##b##c##d +#define LINUXKPI_PARAM_CONCAT(...) LINUXKPI_PARAM_CONCAT_SUB(__VA_ARGS__) +#define LINUXKPI_PARAM_PASS(...) __VA_ARGS__ +#define LINUXKPI_PARAM_DESC(name) LINUXKPI_PARAM_CONCAT(linuxkpi_,LINUXKPI_PARAM_PREFIX,name,_desc) +#define LINUXKPI_PARAM_NAME(name) LINUXKPI_PARAM_CONCAT(LINUXKPI_PARAM_PREFIX,name,,) + +#define LINUXKPI_PARAM_byte(name, var) \ + extern const char LINUXKPI_PARAM_DESC(name)[]; \ + LINUXKPI_PARAM_PASS(SYSCTL_U8(LINUXKPI_PARAM_PARENT, OID_AUTO, \ + LINUXKPI_PARAM_NAME(name), CTLFLAG_RDTUN, &(var), 0, \ + LINUXKPI_PARAM_DESC(name))) + +#define LINUXKPI_PARAM_short(name, var) \ + extern const char LINUXKPI_PARAM_DESC(name)[]; \ + LINUXKPI_PARAM_PASS(SYSCTL_S16(LINUXKPI_PARAM_PARENT, OID_AUTO, \ + LINUXKPI_PARAM_NAME(name), CTLFLAG_RDTUN, &(var), 0, \ + LINUXKPI_PARAM_DESC(name))) + +#define LINUXKPI_PARAM_ushort(name, var) \ + extern const char LINUXKPI_PARAM_DESC(name)[]; \ + LINUXKPI_PARAM_PASS(SYSCTL_U16(LINUXKPI_PARAM_PARENT, OID_AUTO, \ + LINUXKPI_PARAM_NAME(name), CTLFLAG_RDTUN, &(var), 0, \ + LINUXKPI_PARAM_DESC(name))) + +#define LINUXKPI_PARAM_int(name, var) \ + extern const char LINUXKPI_PARAM_DESC(name)[]; \ + LINUXKPI_PARAM_PASS(SYSCTL_INT(LINUXKPI_PARAM_PARENT, OID_AUTO, \ + LINUXKPI_PARAM_NAME(name), CTLFLAG_RDTUN, &(var), 0, \ + LINUXKPI_PARAM_DESC(name))) + +#define LINUXKPI_PARAM_uint(name, var) \ + extern const char LINUXKPI_PARAM_DESC(name)[]; \ + LINUXKPI_PARAM_PASS(SYSCTL_UINT(LINUXKPI_PARAM_PARENT, OID_AUTO, \ + LINUXKPI_PARAM_NAME(name), CTLFLAG_RDTUN, &(var), 0, \ + LINUXKPI_PARAM_DESC(name))) + +#define LINUXKPI_PARAM_long(name, var) \ + extern const char LINUXKPI_PARAM_DESC(name)[]; \ + LINUXKPI_PARAM_PASS(SYSCTL_LONG(LINUXKPI_PARAM_PARENT, OID_AUTO, \ + LINUXKPI_PARAM_NAME(name), CTLFLAG_RDTUN, &(var), 0, \ + LINUXKPI_PARAM_DESC(name))) + +#define LINUXKPI_PARAM_ulong(name, var) \ + extern const char LINUXKPI_PARAM_DESC(name)[]; \ + LINUXKPI_PARAM_PASS(SYSCTL_ULONG(LINUXKPI_PARAM_PARENT, OID_AUTO, \ + LINUXKPI_PARAM_NAME(name), CTLFLAG_RDTUN, &(var), 0, \ + LINUXKPI_PARAM_DESC(name))) + +#define module_param_string(name, str, len, perm) \ + extern const char LINUXKPI_PARAM_DESC(name)[]; \ + LINUXKPI_PARAM_PASS(SYSCTL_STRING(LINUXKPI_PARAM_PARENT, OID_AUTO, \ + LINUXKPI_PARAM_NAME(name), CTLFLAG_RDTUN, (str), (len), \ + LINUXKPI_PARAM_DESC(name))) + +#define module_param_named(name, var, type, mode) \ + LINUXKPI_PARAM_##type(name, var) + +#define module_param(var, type, mode) \ + LINUXKPI_PARAM_##type(var, var) - return 0; -} +#define module_param_array(var, type, addr_argc, mode) -static inline int -param_get_bool(char *buffer, struct kernel_param *kp) -{ +#define MODULE_PARM_DESC(name, desc) \ + const char LINUXKPI_PARAM_DESC(name)[] = { desc } - return 0; -} +SYSCTL_DECL(_compat_linuxkpi); -#endif /* _LINUX_MODULEPARAM_H_ */ +#endif /* _LINUX_MODULEPARAM_H_ */ Modified: head/sys/compat/linuxkpi/common/src/linux_compat.c ============================================================================== --- head/sys/compat/linuxkpi/common/src/linux_compat.c Wed May 25 12:03:21 2016 (r300676) +++ head/sys/compat/linuxkpi/common/src/linux_compat.c Wed May 25 12:12:14 2016 (r300677) @@ -59,6 +59,7 @@ __FBSDID("$FreeBSD$"); #include #include #include +#include #include #include #include @@ -77,6 +78,8 @@ __FBSDID("$FreeBSD$"); #include +SYSCTL_NODE(_compat, OID_AUTO, linuxkpi, CTLFLAG_RW, 0, "LinuxKPI parameters"); + MALLOC_DEFINE(M_KMALLOC, "linux", "Linux kmalloc compat"); #include