Inaky Perez-Gonzalez | 183b9b5 | 2008-09-17 16:34:06 +0100 | [diff] [blame] | 1 | /* |
| 2 | * Ultra Wide Band |
| 3 | * Driver initialization, etc |
| 4 | * |
| 5 | * Copyright (C) 2005-2006 Intel Corporation |
| 6 | * Inaky Perez-Gonzalez <inaky.perez-gonzalez@intel.com> |
| 7 | * |
| 8 | * This program is free software; you can redistribute it and/or |
| 9 | * modify it under the terms of the GNU General Public License version |
| 10 | * 2 as published by the Free Software Foundation. |
| 11 | * |
| 12 | * This program is distributed in the hope that it will be useful, |
| 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 15 | * GNU General Public License for more details. |
| 16 | * |
| 17 | * You should have received a copy of the GNU General Public License |
| 18 | * along with this program; if not, write to the Free Software |
| 19 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA |
| 20 | * 02110-1301, USA. |
| 21 | * |
| 22 | * |
| 23 | * FIXME: docs |
| 24 | * |
| 25 | * Life cycle: FIXME: explain |
| 26 | * |
| 27 | * UWB radio controller: |
| 28 | * |
| 29 | * 1. alloc a uwb_rc, zero it |
| 30 | * 2. call uwb_rc_init() on it to set it up + ops (won't do any |
| 31 | * kind of allocation) |
| 32 | * 3. register (now it is owned by the UWB stack--deregister before |
| 33 | * freeing/destroying). |
| 34 | * 4. It lives on it's own now (UWB stack handles)--when it |
| 35 | * disconnects, call unregister() |
| 36 | * 5. free it. |
| 37 | * |
| 38 | * Make sure you have a reference to the uwb_rc before calling |
| 39 | * any of the UWB API functions. |
| 40 | * |
| 41 | * TODO: |
| 42 | * |
| 43 | * 1. Locking and life cycle management is crappy still. All entry |
| 44 | * points to the UWB HCD API assume you have a reference on the |
| 45 | * uwb_rc structure and that it won't go away. They mutex lock it |
| 46 | * before doing anything. |
| 47 | */ |
| 48 | |
| 49 | #include <linux/kernel.h> |
| 50 | #include <linux/init.h> |
| 51 | #include <linux/module.h> |
| 52 | #include <linux/device.h> |
| 53 | #include <linux/err.h> |
| 54 | #include <linux/kdev_t.h> |
| 55 | #include <linux/random.h> |
David Vrabel | a01777e | 2008-12-22 18:30:29 +0000 | [diff] [blame] | 56 | |
Inaky Perez-Gonzalez | 183b9b5 | 2008-09-17 16:34:06 +0100 | [diff] [blame] | 57 | #include "uwb-internal.h" |
| 58 | |
| 59 | |
| 60 | /* UWB stack attributes (or 'global' constants) */ |
| 61 | |
| 62 | |
| 63 | /** |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 64 | * If a beacon disappears for longer than this, then we consider the |
Inaky Perez-Gonzalez | 183b9b5 | 2008-09-17 16:34:06 +0100 | [diff] [blame] | 65 | * device who was represented by that beacon to be gone. |
| 66 | * |
| 67 | * ECMA-368[17.2.3, last para] establishes that a device must not |
| 68 | * consider a device to be its neighbour if he doesn't receive a beacon |
| 69 | * for more than mMaxLostBeacons. mMaxLostBeacons is defined in |
| 70 | * ECMA-368[17.16] as 3; because we can get only one beacon per |
| 71 | * superframe, that'd be 3 * 65ms = 195 ~ 200 ms. Let's give it time |
| 72 | * for jitter and stuff and make it 500 ms. |
| 73 | */ |
| 74 | unsigned long beacon_timeout_ms = 500; |
| 75 | |
| 76 | static |
Andi Kleen | 28812fe | 2010-01-05 12:48:07 +0100 | [diff] [blame] | 77 | ssize_t beacon_timeout_ms_show(struct class *class, |
| 78 | struct class_attribute *attr, |
| 79 | char *buf) |
Inaky Perez-Gonzalez | 183b9b5 | 2008-09-17 16:34:06 +0100 | [diff] [blame] | 80 | { |
| 81 | return scnprintf(buf, PAGE_SIZE, "%lu\n", beacon_timeout_ms); |
| 82 | } |
| 83 | |
| 84 | static |
| 85 | ssize_t beacon_timeout_ms_store(struct class *class, |
Andi Kleen | 28812fe | 2010-01-05 12:48:07 +0100 | [diff] [blame] | 86 | struct class_attribute *attr, |
Inaky Perez-Gonzalez | 183b9b5 | 2008-09-17 16:34:06 +0100 | [diff] [blame] | 87 | const char *buf, size_t size) |
| 88 | { |
| 89 | unsigned long bt; |
| 90 | ssize_t result; |
| 91 | result = sscanf(buf, "%lu", &bt); |
| 92 | if (result != 1) |
| 93 | return -EINVAL; |
| 94 | beacon_timeout_ms = bt; |
| 95 | return size; |
| 96 | } |
Greg Kroah-Hartman | 84c317e | 2017-06-08 10:12:36 +0200 | [diff] [blame] | 97 | static CLASS_ATTR_RW(beacon_timeout_ms); |
Inaky Perez-Gonzalez | 183b9b5 | 2008-09-17 16:34:06 +0100 | [diff] [blame] | 98 | |
Greg Kroah-Hartman | 84c317e | 2017-06-08 10:12:36 +0200 | [diff] [blame] | 99 | static struct attribute *uwb_class_attrs[] = { |
| 100 | &class_attr_beacon_timeout_ms.attr, |
| 101 | NULL, |
Inaky Perez-Gonzalez | 183b9b5 | 2008-09-17 16:34:06 +0100 | [diff] [blame] | 102 | }; |
Greg Kroah-Hartman | 84c317e | 2017-06-08 10:12:36 +0200 | [diff] [blame] | 103 | ATTRIBUTE_GROUPS(uwb_class); |
Inaky Perez-Gonzalez | 183b9b5 | 2008-09-17 16:34:06 +0100 | [diff] [blame] | 104 | |
| 105 | /** Device model classes */ |
| 106 | struct class uwb_rc_class = { |
| 107 | .name = "uwb_rc", |
Greg Kroah-Hartman | 84c317e | 2017-06-08 10:12:36 +0200 | [diff] [blame] | 108 | .class_groups = uwb_class_groups, |
Inaky Perez-Gonzalez | 183b9b5 | 2008-09-17 16:34:06 +0100 | [diff] [blame] | 109 | }; |
| 110 | |
| 111 | |
| 112 | static int __init uwb_subsys_init(void) |
| 113 | { |
| 114 | int result = 0; |
| 115 | |
| 116 | result = uwb_est_create(); |
| 117 | if (result < 0) { |
| 118 | printk(KERN_ERR "uwb: Can't initialize EST subsystem\n"); |
| 119 | goto error_est_init; |
| 120 | } |
| 121 | |
| 122 | result = class_register(&uwb_rc_class); |
| 123 | if (result < 0) |
| 124 | goto error_uwb_rc_class_register; |
Thomas Pugliese | 8488793 | 2014-09-16 15:53:08 -0500 | [diff] [blame] | 125 | |
| 126 | /* Register the UWB bus */ |
| 127 | result = bus_register(&uwb_bus_type); |
| 128 | if (result) { |
| 129 | pr_err("%s - registering bus driver failed\n", __func__); |
| 130 | goto exit_bus; |
| 131 | } |
| 132 | |
David Vrabel | 9d53b1b | 2008-09-17 16:34:34 +0100 | [diff] [blame] | 133 | uwb_dbg_init(); |
Inaky Perez-Gonzalez | 183b9b5 | 2008-09-17 16:34:06 +0100 | [diff] [blame] | 134 | return 0; |
| 135 | |
Thomas Pugliese | 8488793 | 2014-09-16 15:53:08 -0500 | [diff] [blame] | 136 | exit_bus: |
| 137 | class_unregister(&uwb_rc_class); |
Inaky Perez-Gonzalez | 183b9b5 | 2008-09-17 16:34:06 +0100 | [diff] [blame] | 138 | error_uwb_rc_class_register: |
| 139 | uwb_est_destroy(); |
| 140 | error_est_init: |
| 141 | return result; |
| 142 | } |
| 143 | module_init(uwb_subsys_init); |
| 144 | |
| 145 | static void __exit uwb_subsys_exit(void) |
| 146 | { |
David Vrabel | 9d53b1b | 2008-09-17 16:34:34 +0100 | [diff] [blame] | 147 | uwb_dbg_exit(); |
Thomas Pugliese | 8488793 | 2014-09-16 15:53:08 -0500 | [diff] [blame] | 148 | bus_unregister(&uwb_bus_type); |
Inaky Perez-Gonzalez | 183b9b5 | 2008-09-17 16:34:06 +0100 | [diff] [blame] | 149 | class_unregister(&uwb_rc_class); |
| 150 | uwb_est_destroy(); |
| 151 | return; |
| 152 | } |
| 153 | module_exit(uwb_subsys_exit); |
| 154 | |
| 155 | MODULE_AUTHOR("Inaky Perez-Gonzalez <inaky.perez-gonzalez@intel.com>"); |
| 156 | MODULE_DESCRIPTION("Ultra Wide Band core"); |
| 157 | MODULE_LICENSE("GPL"); |