2 * Copyright (c) 2006 Jiri Benc <jbenc@suse.cz>
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License version 2 as
6 * published by the Free Software Foundation.
9 #include <linux/kernel.h>
10 #include <linux/interrupt.h>
12 #include <linux/if_ether.h>
13 #include <linux/netdevice.h>
14 #include <net/d80211.h>
15 #include "ieee80211_i.h"
16 #include "ieee80211_led.h"
18 struct ieee80211_dev_list {
19 struct list_head list;
21 struct ieee80211_local *local;
24 static LIST_HEAD(dev_list);
25 static DEFINE_SPINLOCK(dev_list_lock);
28 /* Caller must hold dev_list_lock */
29 static struct ieee80211_dev_list *__ieee80211_dev_find(int index)
31 struct ieee80211_dev_list *dev_item;
33 list_for_each_entry(dev_item, &dev_list, list) {
34 if (dev_item->dev_index == index)
40 int ieee80211_dev_alloc_index(struct ieee80211_local *local)
42 struct ieee80211_dev_list *dev_item, *new;
45 new = kmalloc(sizeof(struct ieee80211_dev_list), GFP_KERNEL);
49 spin_lock(&dev_list_lock);
50 list_for_each_entry(dev_item, &dev_list, list) {
51 if (index < dev_item->dev_index)
55 new->dev_index = index;
56 list_add_tail(&new->list, &dev_item->list);
57 spin_unlock(&dev_list_lock);
58 local->hw.index = index;
62 void ieee80211_dev_free_index(struct ieee80211_local *local)
64 struct ieee80211_dev_list *dev_item;
66 spin_lock(&dev_list_lock);
67 dev_item = __ieee80211_dev_find(local->hw.index);
69 list_del(&dev_item->list);
70 spin_unlock(&dev_list_lock);
76 struct ieee80211_local *ieee80211_dev_find(int index)
78 struct ieee80211_dev_list *dev_item;
80 spin_lock(&dev_list_lock);
81 dev_item = __ieee80211_dev_find(index);
82 spin_unlock(&dev_list_lock);
83 return dev_item ? dev_item->local : NULL;
86 int ieee80211_dev_find_index(struct ieee80211_local *local)
88 struct ieee80211_dev_list *dev_item;
91 spin_lock(&dev_list_lock);
92 list_for_each_entry(dev_item, &dev_list, list) {
93 if (dev_item->local == local) {
94 index = dev_item->dev_index;
98 spin_unlock(&dev_list_lock);
102 struct ieee80211_local *ieee80211_dev_alloc(gfp_t flags)
104 struct ieee80211_local *local;
106 local = kzalloc(sizeof(struct ieee80211_local), flags);
109 local->hw.index = -1;
110 ieee80211_dev_sysfs_init(local);
114 void ieee80211_dev_free(struct ieee80211_local *local)
116 ieee80211_dev_sysfs_put(local);