alex.bluesman.smirnov@gmail.com | e1e49b6 | 2012-05-15 20:50:30 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Loopback IEEE 802.15.4 interface |
| 3 | * |
| 4 | * Copyright 2007-2012 Siemens AG |
| 5 | * |
| 6 | * This program is free software; you can redistribute it and/or modify |
| 7 | * it under the terms of the GNU General Public License version 2 |
| 8 | * as published by the Free Software Foundation. |
| 9 | * |
| 10 | * This program is distributed in the hope that it will be useful, |
| 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 13 | * GNU General Public License for more details. |
| 14 | * |
alex.bluesman.smirnov@gmail.com | e1e49b6 | 2012-05-15 20:50:30 +0000 | [diff] [blame] | 15 | * Written by: |
| 16 | * Sergey Lapin <slapin@ossfans.org> |
| 17 | * Dmitry Eremin-Solenikov <dbaryshkov@gmail.com> |
| 18 | * Alexander Smirnov <alex.bluesman.smirnov@gmail.com> |
| 19 | */ |
| 20 | |
| 21 | #include <linux/module.h> |
| 22 | #include <linux/timer.h> |
| 23 | #include <linux/platform_device.h> |
| 24 | #include <linux/netdevice.h> |
Himangi Saraogi | 12b5c38 | 2014-05-19 22:25:11 +0530 | [diff] [blame] | 25 | #include <linux/device.h> |
alex.bluesman.smirnov@gmail.com | e1e49b6 | 2012-05-15 20:50:30 +0000 | [diff] [blame] | 26 | #include <linux/spinlock.h> |
| 27 | #include <net/mac802154.h> |
Alexander Aring | 5ad60d3 | 2014-10-25 09:41:02 +0200 | [diff] [blame] | 28 | #include <net/cfg802154.h> |
alex.bluesman.smirnov@gmail.com | e1e49b6 | 2012-05-15 20:50:30 +0000 | [diff] [blame] | 29 | |
Alexander Aring | 7e57905 | 2015-05-17 21:44:58 +0200 | [diff] [blame] | 30 | static int numlbs = 2; |
Alexander Aring | e369dc8 | 2015-05-17 21:45:05 +0200 | [diff] [blame] | 31 | |
Alexander Aring | b82b99f | 2015-05-17 21:45:03 +0200 | [diff] [blame] | 32 | static LIST_HEAD(fakelb_phys); |
Alexander Aring | e369dc8 | 2015-05-17 21:45:05 +0200 | [diff] [blame] | 33 | static DEFINE_SPINLOCK(fakelb_phys_lock); |
| 34 | |
| 35 | static LIST_HEAD(fakelb_ifup_phys); |
| 36 | static DEFINE_RWLOCK(fakelb_ifup_phys_lock); |
alex.bluesman.smirnov@gmail.com | e1e49b6 | 2012-05-15 20:50:30 +0000 | [diff] [blame] | 37 | |
Alexander Aring | db3f5d0 | 2015-05-17 21:45:00 +0200 | [diff] [blame] | 38 | struct fakelb_phy { |
Alexander Aring | 5a50439 | 2014-10-25 17:16:34 +0200 | [diff] [blame] | 39 | struct ieee802154_hw *hw; |
alex.bluesman.smirnov@gmail.com | e1e49b6 | 2012-05-15 20:50:30 +0000 | [diff] [blame] | 40 | |
Alexander Aring | 12da8d9 | 2015-05-17 21:45:06 +0200 | [diff] [blame] | 41 | u8 page; |
| 42 | u8 channel; |
| 43 | |
Alexander Aring | 789a99e | 2015-06-14 16:48:44 +0200 | [diff] [blame] | 44 | bool suspended; |
| 45 | |
alex.bluesman.smirnov@gmail.com | e1e49b6 | 2012-05-15 20:50:30 +0000 | [diff] [blame] | 46 | struct list_head list; |
Alexander Aring | e369dc8 | 2015-05-17 21:45:05 +0200 | [diff] [blame] | 47 | struct list_head list_ifup; |
alex.bluesman.smirnov@gmail.com | e1e49b6 | 2012-05-15 20:50:30 +0000 | [diff] [blame] | 48 | }; |
| 49 | |
Alexander Aring | 39572ab | 2015-05-17 21:45:10 +0200 | [diff] [blame] | 50 | static int fakelb_hw_ed(struct ieee802154_hw *hw, u8 *level) |
alex.bluesman.smirnov@gmail.com | e1e49b6 | 2012-05-15 20:50:30 +0000 | [diff] [blame] | 51 | { |
alex.bluesman.smirnov@gmail.com | e1e49b6 | 2012-05-15 20:50:30 +0000 | [diff] [blame] | 52 | BUG_ON(!level); |
| 53 | *level = 0xbe; |
| 54 | |
| 55 | return 0; |
| 56 | } |
| 57 | |
Alexander Aring | 39572ab | 2015-05-17 21:45:10 +0200 | [diff] [blame] | 58 | static int fakelb_hw_channel(struct ieee802154_hw *hw, u8 page, u8 channel) |
alex.bluesman.smirnov@gmail.com | e1e49b6 | 2012-05-15 20:50:30 +0000 | [diff] [blame] | 59 | { |
Alexander Aring | 12da8d9 | 2015-05-17 21:45:06 +0200 | [diff] [blame] | 60 | struct fakelb_phy *phy = hw->priv; |
alex.bluesman.smirnov@gmail.com | e1e49b6 | 2012-05-15 20:50:30 +0000 | [diff] [blame] | 61 | |
Alexander Aring | 12da8d9 | 2015-05-17 21:45:06 +0200 | [diff] [blame] | 62 | write_lock_bh(&fakelb_ifup_phys_lock); |
| 63 | phy->page = page; |
| 64 | phy->channel = channel; |
| 65 | write_unlock_bh(&fakelb_ifup_phys_lock); |
alex.bluesman.smirnov@gmail.com | e1e49b6 | 2012-05-15 20:50:30 +0000 | [diff] [blame] | 66 | return 0; |
| 67 | } |
| 68 | |
Alexander Aring | 39572ab | 2015-05-17 21:45:10 +0200 | [diff] [blame] | 69 | static int fakelb_hw_xmit(struct ieee802154_hw *hw, struct sk_buff *skb) |
alex.bluesman.smirnov@gmail.com | e1e49b6 | 2012-05-15 20:50:30 +0000 | [diff] [blame] | 70 | { |
Alexander Aring | 39572ab | 2015-05-17 21:45:10 +0200 | [diff] [blame] | 71 | struct fakelb_phy *current_phy = hw->priv, *phy; |
alex.bluesman.smirnov@gmail.com | e1e49b6 | 2012-05-15 20:50:30 +0000 | [diff] [blame] | 72 | |
Alexander Aring | e369dc8 | 2015-05-17 21:45:05 +0200 | [diff] [blame] | 73 | read_lock_bh(&fakelb_ifup_phys_lock); |
Alexander Aring | 789a99e | 2015-06-14 16:48:44 +0200 | [diff] [blame] | 74 | WARN_ON(current_phy->suspended); |
Alexander Aring | e369dc8 | 2015-05-17 21:45:05 +0200 | [diff] [blame] | 75 | list_for_each_entry(phy, &fakelb_ifup_phys, list_ifup) { |
Alexander Aring | 9f8b97f | 2015-05-17 21:45:01 +0200 | [diff] [blame] | 76 | if (current_phy == phy) |
| 77 | continue; |
Alexander Aring | db3f5d0 | 2015-05-17 21:45:00 +0200 | [diff] [blame] | 78 | |
Alexander Aring | 12da8d9 | 2015-05-17 21:45:06 +0200 | [diff] [blame] | 79 | if (current_phy->page == phy->page && |
Alexander Aring | 98be165 | 2015-05-17 21:45:08 +0200 | [diff] [blame] | 80 | current_phy->channel == phy->channel) { |
| 81 | struct sk_buff *newskb = pskb_copy(skb, GFP_ATOMIC); |
| 82 | |
| 83 | if (newskb) |
| 84 | ieee802154_rx_irqsafe(phy->hw, newskb, 0xcc); |
| 85 | } |
alex.bluesman.smirnov@gmail.com | e1e49b6 | 2012-05-15 20:50:30 +0000 | [diff] [blame] | 86 | } |
Alexander Aring | e369dc8 | 2015-05-17 21:45:05 +0200 | [diff] [blame] | 87 | read_unlock_bh(&fakelb_ifup_phys_lock); |
alex.bluesman.smirnov@gmail.com | e1e49b6 | 2012-05-15 20:50:30 +0000 | [diff] [blame] | 88 | |
Alexander Aring | a09c07a | 2015-05-17 21:45:09 +0200 | [diff] [blame] | 89 | ieee802154_xmit_complete(hw, skb, false); |
alex.bluesman.smirnov@gmail.com | e1e49b6 | 2012-05-15 20:50:30 +0000 | [diff] [blame] | 90 | return 0; |
| 91 | } |
| 92 | |
Alexander Aring | 39572ab | 2015-05-17 21:45:10 +0200 | [diff] [blame] | 93 | static int fakelb_hw_start(struct ieee802154_hw *hw) |
| 94 | { |
Alexander Aring | db3f5d0 | 2015-05-17 21:45:00 +0200 | [diff] [blame] | 95 | struct fakelb_phy *phy = hw->priv; |
alex.bluesman.smirnov@gmail.com | e1e49b6 | 2012-05-15 20:50:30 +0000 | [diff] [blame] | 96 | |
Alexander Aring | e369dc8 | 2015-05-17 21:45:05 +0200 | [diff] [blame] | 97 | write_lock_bh(&fakelb_ifup_phys_lock); |
Alexander Aring | 789a99e | 2015-06-14 16:48:44 +0200 | [diff] [blame] | 98 | phy->suspended = false; |
Alexander Aring | e369dc8 | 2015-05-17 21:45:05 +0200 | [diff] [blame] | 99 | list_add(&phy->list_ifup, &fakelb_ifup_phys); |
| 100 | write_unlock_bh(&fakelb_ifup_phys_lock); |
alex.bluesman.smirnov@gmail.com | e1e49b6 | 2012-05-15 20:50:30 +0000 | [diff] [blame] | 101 | |
Alexander Aring | e369dc8 | 2015-05-17 21:45:05 +0200 | [diff] [blame] | 102 | return 0; |
alex.bluesman.smirnov@gmail.com | e1e49b6 | 2012-05-15 20:50:30 +0000 | [diff] [blame] | 103 | } |
| 104 | |
Alexander Aring | 39572ab | 2015-05-17 21:45:10 +0200 | [diff] [blame] | 105 | static void fakelb_hw_stop(struct ieee802154_hw *hw) |
| 106 | { |
Alexander Aring | db3f5d0 | 2015-05-17 21:45:00 +0200 | [diff] [blame] | 107 | struct fakelb_phy *phy = hw->priv; |
alex.bluesman.smirnov@gmail.com | e1e49b6 | 2012-05-15 20:50:30 +0000 | [diff] [blame] | 108 | |
Alexander Aring | e369dc8 | 2015-05-17 21:45:05 +0200 | [diff] [blame] | 109 | write_lock_bh(&fakelb_ifup_phys_lock); |
Alexander Aring | 789a99e | 2015-06-14 16:48:44 +0200 | [diff] [blame] | 110 | phy->suspended = true; |
Alexander Aring | e369dc8 | 2015-05-17 21:45:05 +0200 | [diff] [blame] | 111 | list_del(&phy->list_ifup); |
| 112 | write_unlock_bh(&fakelb_ifup_phys_lock); |
alex.bluesman.smirnov@gmail.com | e1e49b6 | 2012-05-15 20:50:30 +0000 | [diff] [blame] | 113 | } |
| 114 | |
Alexander Aring | 1630186 | 2014-10-28 18:21:18 +0100 | [diff] [blame] | 115 | static const struct ieee802154_ops fakelb_ops = { |
alex.bluesman.smirnov@gmail.com | e1e49b6 | 2012-05-15 20:50:30 +0000 | [diff] [blame] | 116 | .owner = THIS_MODULE, |
Alexander Aring | a09c07a | 2015-05-17 21:45:09 +0200 | [diff] [blame] | 117 | .xmit_async = fakelb_hw_xmit, |
alex.bluesman.smirnov@gmail.com | e1e49b6 | 2012-05-15 20:50:30 +0000 | [diff] [blame] | 118 | .ed = fakelb_hw_ed, |
| 119 | .set_channel = fakelb_hw_channel, |
| 120 | .start = fakelb_hw_start, |
| 121 | .stop = fakelb_hw_stop, |
| 122 | }; |
| 123 | |
| 124 | /* Number of dummy devices to be set up by this module. */ |
| 125 | module_param(numlbs, int, 0); |
| 126 | MODULE_PARM_DESC(numlbs, " number of pseudo devices"); |
| 127 | |
Alexander Aring | b82b99f | 2015-05-17 21:45:03 +0200 | [diff] [blame] | 128 | static int fakelb_add_one(struct device *dev) |
alex.bluesman.smirnov@gmail.com | e1e49b6 | 2012-05-15 20:50:30 +0000 | [diff] [blame] | 129 | { |
Alexander Aring | 39572ab | 2015-05-17 21:45:10 +0200 | [diff] [blame] | 130 | struct ieee802154_hw *hw; |
Alexander Aring | db3f5d0 | 2015-05-17 21:45:00 +0200 | [diff] [blame] | 131 | struct fakelb_phy *phy; |
alex.bluesman.smirnov@gmail.com | e1e49b6 | 2012-05-15 20:50:30 +0000 | [diff] [blame] | 132 | int err; |
alex.bluesman.smirnov@gmail.com | e1e49b6 | 2012-05-15 20:50:30 +0000 | [diff] [blame] | 133 | |
Alexander Aring | db3f5d0 | 2015-05-17 21:45:00 +0200 | [diff] [blame] | 134 | hw = ieee802154_alloc_hw(sizeof(*phy), &fakelb_ops); |
Alexander Aring | 5a50439 | 2014-10-25 17:16:34 +0200 | [diff] [blame] | 135 | if (!hw) |
alex.bluesman.smirnov@gmail.com | e1e49b6 | 2012-05-15 20:50:30 +0000 | [diff] [blame] | 136 | return -ENOMEM; |
| 137 | |
Alexander Aring | db3f5d0 | 2015-05-17 21:45:00 +0200 | [diff] [blame] | 138 | phy = hw->priv; |
| 139 | phy->hw = hw; |
alex.bluesman.smirnov@gmail.com | e1e49b6 | 2012-05-15 20:50:30 +0000 | [diff] [blame] | 140 | |
| 141 | /* 868 MHz BPSK 802.15.4-2003 */ |
Alexander Aring | 72f655e | 2015-05-17 21:44:42 +0200 | [diff] [blame] | 142 | hw->phy->supported.channels[0] |= 1; |
alex.bluesman.smirnov@gmail.com | e1e49b6 | 2012-05-15 20:50:30 +0000 | [diff] [blame] | 143 | /* 915 MHz BPSK 802.15.4-2003 */ |
Alexander Aring | 72f655e | 2015-05-17 21:44:42 +0200 | [diff] [blame] | 144 | hw->phy->supported.channels[0] |= 0x7fe; |
alex.bluesman.smirnov@gmail.com | e1e49b6 | 2012-05-15 20:50:30 +0000 | [diff] [blame] | 145 | /* 2.4 GHz O-QPSK 802.15.4-2003 */ |
Alexander Aring | 72f655e | 2015-05-17 21:44:42 +0200 | [diff] [blame] | 146 | hw->phy->supported.channels[0] |= 0x7FFF800; |
alex.bluesman.smirnov@gmail.com | e1e49b6 | 2012-05-15 20:50:30 +0000 | [diff] [blame] | 147 | /* 868 MHz ASK 802.15.4-2006 */ |
Alexander Aring | 72f655e | 2015-05-17 21:44:42 +0200 | [diff] [blame] | 148 | hw->phy->supported.channels[1] |= 1; |
alex.bluesman.smirnov@gmail.com | e1e49b6 | 2012-05-15 20:50:30 +0000 | [diff] [blame] | 149 | /* 915 MHz ASK 802.15.4-2006 */ |
Alexander Aring | 72f655e | 2015-05-17 21:44:42 +0200 | [diff] [blame] | 150 | hw->phy->supported.channels[1] |= 0x7fe; |
alex.bluesman.smirnov@gmail.com | e1e49b6 | 2012-05-15 20:50:30 +0000 | [diff] [blame] | 151 | /* 868 MHz O-QPSK 802.15.4-2006 */ |
Alexander Aring | 72f655e | 2015-05-17 21:44:42 +0200 | [diff] [blame] | 152 | hw->phy->supported.channels[2] |= 1; |
alex.bluesman.smirnov@gmail.com | e1e49b6 | 2012-05-15 20:50:30 +0000 | [diff] [blame] | 153 | /* 915 MHz O-QPSK 802.15.4-2006 */ |
Alexander Aring | 72f655e | 2015-05-17 21:44:42 +0200 | [diff] [blame] | 154 | hw->phy->supported.channels[2] |= 0x7fe; |
alex.bluesman.smirnov@gmail.com | e1e49b6 | 2012-05-15 20:50:30 +0000 | [diff] [blame] | 155 | /* 2.4 GHz CSS 802.15.4a-2007 */ |
Alexander Aring | 72f655e | 2015-05-17 21:44:42 +0200 | [diff] [blame] | 156 | hw->phy->supported.channels[3] |= 0x3fff; |
alex.bluesman.smirnov@gmail.com | e1e49b6 | 2012-05-15 20:50:30 +0000 | [diff] [blame] | 157 | /* UWB Sub-gigahertz 802.15.4a-2007 */ |
Alexander Aring | 72f655e | 2015-05-17 21:44:42 +0200 | [diff] [blame] | 158 | hw->phy->supported.channels[4] |= 1; |
alex.bluesman.smirnov@gmail.com | e1e49b6 | 2012-05-15 20:50:30 +0000 | [diff] [blame] | 159 | /* UWB Low band 802.15.4a-2007 */ |
Alexander Aring | 72f655e | 2015-05-17 21:44:42 +0200 | [diff] [blame] | 160 | hw->phy->supported.channels[4] |= 0x1e; |
alex.bluesman.smirnov@gmail.com | e1e49b6 | 2012-05-15 20:50:30 +0000 | [diff] [blame] | 161 | /* UWB High band 802.15.4a-2007 */ |
Alexander Aring | 72f655e | 2015-05-17 21:44:42 +0200 | [diff] [blame] | 162 | hw->phy->supported.channels[4] |= 0xffe0; |
alex.bluesman.smirnov@gmail.com | e1e49b6 | 2012-05-15 20:50:30 +0000 | [diff] [blame] | 163 | /* 750 MHz O-QPSK 802.15.4c-2009 */ |
Alexander Aring | 72f655e | 2015-05-17 21:44:42 +0200 | [diff] [blame] | 164 | hw->phy->supported.channels[5] |= 0xf; |
alex.bluesman.smirnov@gmail.com | e1e49b6 | 2012-05-15 20:50:30 +0000 | [diff] [blame] | 165 | /* 750 MHz MPSK 802.15.4c-2009 */ |
Alexander Aring | 72f655e | 2015-05-17 21:44:42 +0200 | [diff] [blame] | 166 | hw->phy->supported.channels[5] |= 0xf0; |
alex.bluesman.smirnov@gmail.com | e1e49b6 | 2012-05-15 20:50:30 +0000 | [diff] [blame] | 167 | /* 950 MHz BPSK 802.15.4d-2009 */ |
Alexander Aring | 72f655e | 2015-05-17 21:44:42 +0200 | [diff] [blame] | 168 | hw->phy->supported.channels[6] |= 0x3ff; |
alex.bluesman.smirnov@gmail.com | e1e49b6 | 2012-05-15 20:50:30 +0000 | [diff] [blame] | 169 | /* 950 MHz GFSK 802.15.4d-2009 */ |
Alexander Aring | 72f655e | 2015-05-17 21:44:42 +0200 | [diff] [blame] | 170 | hw->phy->supported.channels[6] |= 0x3ffc00; |
alex.bluesman.smirnov@gmail.com | e1e49b6 | 2012-05-15 20:50:30 +0000 | [diff] [blame] | 171 | |
Alexander Aring | e214a90 | 2015-05-17 21:45:07 +0200 | [diff] [blame] | 172 | ieee802154_random_extended_addr(&hw->phy->perm_extended_addr); |
| 173 | /* fake phy channel 13 as default */ |
| 174 | hw->phy->current_channel = 13; |
| 175 | phy->channel = hw->phy->current_channel; |
| 176 | |
Alexander Aring | 5a50439 | 2014-10-25 17:16:34 +0200 | [diff] [blame] | 177 | hw->parent = dev; |
alex.bluesman.smirnov@gmail.com | e1e49b6 | 2012-05-15 20:50:30 +0000 | [diff] [blame] | 178 | |
Alexander Aring | 5a50439 | 2014-10-25 17:16:34 +0200 | [diff] [blame] | 179 | err = ieee802154_register_hw(hw); |
alex.bluesman.smirnov@gmail.com | e1e49b6 | 2012-05-15 20:50:30 +0000 | [diff] [blame] | 180 | if (err) |
| 181 | goto err_reg; |
| 182 | |
Alexander Aring | e369dc8 | 2015-05-17 21:45:05 +0200 | [diff] [blame] | 183 | spin_lock(&fakelb_phys_lock); |
Alexander Aring | b82b99f | 2015-05-17 21:45:03 +0200 | [diff] [blame] | 184 | list_add_tail(&phy->list, &fakelb_phys); |
Alexander Aring | e369dc8 | 2015-05-17 21:45:05 +0200 | [diff] [blame] | 185 | spin_unlock(&fakelb_phys_lock); |
alex.bluesman.smirnov@gmail.com | e1e49b6 | 2012-05-15 20:50:30 +0000 | [diff] [blame] | 186 | |
| 187 | return 0; |
| 188 | |
| 189 | err_reg: |
Alexander Aring | db3f5d0 | 2015-05-17 21:45:00 +0200 | [diff] [blame] | 190 | ieee802154_free_hw(phy->hw); |
alex.bluesman.smirnov@gmail.com | e1e49b6 | 2012-05-15 20:50:30 +0000 | [diff] [blame] | 191 | return err; |
| 192 | } |
| 193 | |
Alexander Aring | db3f5d0 | 2015-05-17 21:45:00 +0200 | [diff] [blame] | 194 | static void fakelb_del(struct fakelb_phy *phy) |
alex.bluesman.smirnov@gmail.com | e1e49b6 | 2012-05-15 20:50:30 +0000 | [diff] [blame] | 195 | { |
Alexander Aring | db3f5d0 | 2015-05-17 21:45:00 +0200 | [diff] [blame] | 196 | list_del(&phy->list); |
alex.bluesman.smirnov@gmail.com | e1e49b6 | 2012-05-15 20:50:30 +0000 | [diff] [blame] | 197 | |
Alexander Aring | db3f5d0 | 2015-05-17 21:45:00 +0200 | [diff] [blame] | 198 | ieee802154_unregister_hw(phy->hw); |
| 199 | ieee802154_free_hw(phy->hw); |
alex.bluesman.smirnov@gmail.com | e1e49b6 | 2012-05-15 20:50:30 +0000 | [diff] [blame] | 200 | } |
| 201 | |
Bill Pemberton | bb1f460 | 2012-12-03 09:24:12 -0500 | [diff] [blame] | 202 | static int fakelb_probe(struct platform_device *pdev) |
alex.bluesman.smirnov@gmail.com | e1e49b6 | 2012-05-15 20:50:30 +0000 | [diff] [blame] | 203 | { |
Alexander Aring | db3f5d0 | 2015-05-17 21:45:00 +0200 | [diff] [blame] | 204 | struct fakelb_phy *phy, *tmp; |
Alexander Aring | 39572ab | 2015-05-17 21:45:10 +0200 | [diff] [blame] | 205 | int err, i; |
alex.bluesman.smirnov@gmail.com | e1e49b6 | 2012-05-15 20:50:30 +0000 | [diff] [blame] | 206 | |
alex.bluesman.smirnov@gmail.com | e1e49b6 | 2012-05-15 20:50:30 +0000 | [diff] [blame] | 207 | for (i = 0; i < numlbs; i++) { |
Alexander Aring | b82b99f | 2015-05-17 21:45:03 +0200 | [diff] [blame] | 208 | err = fakelb_add_one(&pdev->dev); |
alex.bluesman.smirnov@gmail.com | e1e49b6 | 2012-05-15 20:50:30 +0000 | [diff] [blame] | 209 | if (err < 0) |
| 210 | goto err_slave; |
| 211 | } |
| 212 | |
alex.bluesman.smirnov@gmail.com | e1e49b6 | 2012-05-15 20:50:30 +0000 | [diff] [blame] | 213 | dev_info(&pdev->dev, "added ieee802154 hardware\n"); |
| 214 | return 0; |
| 215 | |
| 216 | err_slave: |
Alexander Aring | e369dc8 | 2015-05-17 21:45:05 +0200 | [diff] [blame] | 217 | spin_lock(&fakelb_phys_lock); |
Alexander Aring | b82b99f | 2015-05-17 21:45:03 +0200 | [diff] [blame] | 218 | list_for_each_entry_safe(phy, tmp, &fakelb_phys, list) |
Alexander Aring | db3f5d0 | 2015-05-17 21:45:00 +0200 | [diff] [blame] | 219 | fakelb_del(phy); |
Alexander Aring | e369dc8 | 2015-05-17 21:45:05 +0200 | [diff] [blame] | 220 | spin_unlock(&fakelb_phys_lock); |
alex.bluesman.smirnov@gmail.com | e1e49b6 | 2012-05-15 20:50:30 +0000 | [diff] [blame] | 221 | return err; |
| 222 | } |
| 223 | |
Bill Pemberton | bb1f460 | 2012-12-03 09:24:12 -0500 | [diff] [blame] | 224 | static int fakelb_remove(struct platform_device *pdev) |
alex.bluesman.smirnov@gmail.com | e1e49b6 | 2012-05-15 20:50:30 +0000 | [diff] [blame] | 225 | { |
Alexander Aring | 39572ab | 2015-05-17 21:45:10 +0200 | [diff] [blame] | 226 | struct fakelb_phy *phy, *tmp; |
alex.bluesman.smirnov@gmail.com | e1e49b6 | 2012-05-15 20:50:30 +0000 | [diff] [blame] | 227 | |
Alexander Aring | e369dc8 | 2015-05-17 21:45:05 +0200 | [diff] [blame] | 228 | spin_lock(&fakelb_phys_lock); |
Alexander Aring | 39572ab | 2015-05-17 21:45:10 +0200 | [diff] [blame] | 229 | list_for_each_entry_safe(phy, tmp, &fakelb_phys, list) |
Alexander Aring | db3f5d0 | 2015-05-17 21:45:00 +0200 | [diff] [blame] | 230 | fakelb_del(phy); |
Alexander Aring | e369dc8 | 2015-05-17 21:45:05 +0200 | [diff] [blame] | 231 | spin_unlock(&fakelb_phys_lock); |
alex.bluesman.smirnov@gmail.com | e1e49b6 | 2012-05-15 20:50:30 +0000 | [diff] [blame] | 232 | return 0; |
| 233 | } |
| 234 | |
| 235 | static struct platform_device *ieee802154fake_dev; |
| 236 | |
| 237 | static struct platform_driver ieee802154fake_driver = { |
| 238 | .probe = fakelb_probe, |
Bill Pemberton | bb1f460 | 2012-12-03 09:24:12 -0500 | [diff] [blame] | 239 | .remove = fakelb_remove, |
alex.bluesman.smirnov@gmail.com | e1e49b6 | 2012-05-15 20:50:30 +0000 | [diff] [blame] | 240 | .driver = { |
| 241 | .name = "ieee802154fakelb", |
alex.bluesman.smirnov@gmail.com | e1e49b6 | 2012-05-15 20:50:30 +0000 | [diff] [blame] | 242 | }, |
| 243 | }; |
| 244 | |
| 245 | static __init int fakelb_init_module(void) |
| 246 | { |
| 247 | ieee802154fake_dev = platform_device_register_simple( |
| 248 | "ieee802154fakelb", -1, NULL, 0); |
| 249 | return platform_driver_register(&ieee802154fake_driver); |
| 250 | } |
| 251 | |
| 252 | static __exit void fake_remove_module(void) |
| 253 | { |
| 254 | platform_driver_unregister(&ieee802154fake_driver); |
| 255 | platform_device_unregister(ieee802154fake_dev); |
| 256 | } |
| 257 | |
| 258 | module_init(fakelb_init_module); |
| 259 | module_exit(fake_remove_module); |
| 260 | MODULE_LICENSE("GPL"); |