1/*- 2 * Copyright (c) 2010 Isilon Systems, Inc. 3 * Copyright (c) 2010 iX Systems, Inc. 4 * Copyright (c) 2010 Panasas, Inc. 5 * Copyright (c) 2013, 2014 Mellanox Technologies, Ltd. 6 * All rights reserved. 7 * 8 * Redistribution and use in source and binary forms, with or without 9 * modification, are permitted provided that the following conditions 10 * are met: 11 * 1. Redistributions of source code must retain the above copyright 12 * notice unmodified, this list of conditions, and the following 13 * disclaimer. 14 * 2. Redistributions in binary form must reproduce the above copyright 15 * notice, this list of conditions and the following disclaimer in the 16 * documentation and/or other materials provided with the distribution. 17 * 18 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 19 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 20 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 21 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 22 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 23 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 24 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 25 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 26 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 27 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 28 */ 29#ifndef _LINUXKPI_LINUX_MODULE_H_ 30#define _LINUXKPI_LINUX_MODULE_H_ 31 32#include <sys/cdefs.h> 33#include <sys/kernel.h> 34#include <sys/types.h> 35 36#include <linux/list.h> 37#include <linux/compiler.h> 38#include <linux/moduleparam.h> 39#include "linux/kernel.h" 40 41#define MODULE_AUTHOR(name) 42#define MODULE_DESCRIPTION(name) 43#define MODULE_INFO(tag, info) 44#define MODULE_FIRMWARE(firmware) 45#define MODULE_VERSION(version) 46#define MODULE_SUPPORTED_DEVICE(name) 47#define MODULE_IMPORT_NS(_name) 48 49struct module { 50}; 51 52#define THIS_MODULE ((struct module *)0) 53 54#define __MODULE_STRING(x) __stringify(x) 55 56/* OFED pre-module initialization */ 57#define SI_SUB_OFED_PREINIT (SI_SUB_ROOT_CONF - 2) 58/* OFED default module initialization */ 59#define SI_SUB_OFED_MODINIT (SI_SUB_ROOT_CONF - 1) 60#define SI_SUB_POST_CORE_INIT (SI_SUB_DRIVERS + 1) 61#define SI_SUB_ARCH_INIT (SI_SUB_DRIVERS + 2) 62#define SI_SUB_SUBSYS_INIT (SI_SUB_DRIVERS + 3) 63 64static inline void 65_module_run(void *arg) 66{ 67 int (*fn)(void); 68 fn = arg; 69 if (fn == NULL) { 70 PRINTK("_module_run null ptr! \n"); 71 return; 72 } 73 int ret = fn(); 74 if (ret) { 75 PRINTK("_module_run function callback ret:%d! \n", ret); 76 } 77} 78 79#define module_init(fn) \ 80 SYSINIT(fn, SI_SUB_OFED_MODINIT, SI_ORDER_FIRST, _module_run, (fn)) 81 82#define module_exit(fn) \ 83 SYSUNINIT(fn, SI_SUB_OFED_MODINIT, SI_ORDER_SECOND, _module_run, (fn)) 84 85/* 86 * The following two macros are a workaround for not having a module 87 * load and unload order resolver: 88 */ 89#define module_init_order(fn, order) \ 90 SYSINIT(fn, SI_SUB_OFED_MODINIT, (order), _module_run, (fn)) 91 92#define module_exit_order(fn, order) \ 93 SYSUNINIT(fn, SI_SUB_OFED_MODINIT, (order), _module_run, (fn)) 94 95#define module_get(module) 96#define module_put(module) 97#define try_module_get(module) 1 98 99/* 100 * The sysinit table itself. Items are checked off as the are run. 101 * If we want to register new sysinit types, add them to newsysinit. 102 */ 103SET_DECLARE(sysinit_set, struct sysinit); 104#define postcore_initcall(fn) SYSINIT(fn, SI_SUB_POST_CORE_INIT, SI_ORDER_FIRST, _module_run, (fn)) 105#define arch_initcall(fn) SYSINIT(fn, SI_SUB_ARCH_INIT, SI_ORDER_FIRST, _module_run, (fn)) 106#define subsys_initcall(fn) SYSINIT(fn, SI_SUB_SUBSYS_INIT, SI_ORDER_FIRST, _module_run, (fn)) 107 108static inline void mi_startup(enum sysinit_sub_id sub_id) 109{ 110 struct sysinit **sipp = NULL; /* system initialization*/ 111 struct sysinit **xipp = NULL; /* interior loop of sort*/ 112 struct sysinit *save = NULL; /* bubble*/ 113 struct sysinit **sysinit = SET_BEGIN(sysinit_set); 114 struct sysinit **sysinit_end = SET_LIMIT(sysinit_set); 115 116 /* 117 * Perform a bubble sort of the system initialization objects by 118 * their subsystem (primary key) and order (secondary key). 119 */ 120 for (sipp = sysinit; sipp < sysinit_end; sipp++) { 121 for (xipp = sipp + 1; xipp < sysinit_end; xipp++) { 122 if ((*sipp)->subsystem < (*xipp)->subsystem || 123 ((*sipp)->subsystem == (*xipp)->subsystem && 124 (*sipp)->order <= (*xipp)->order)) 125 continue; /* skip*/ 126 save = *sipp; 127 *sipp = *xipp; 128 *xipp = save; 129 } 130 } 131 132 /* 133 * Traverse the (now) ordered list of system initialization tasks. 134 * Perform each task, and continue on to the next task. 135 */ 136 for (sipp = sysinit; sipp < sysinit_end; sipp++) { 137 if ((*sipp)->subsystem > sub_id) { 138 break; 139 } 140 /* Call function */ 141 (*((*sipp)->func))((*sipp)->udata); 142 } 143} 144 145#endif /* _LINUXKPI_LINUX_MODULE_H_ */ 146