gpio: rcar: Fix runtime PM imbalance on error
[linux/fpc-iii.git] / drivers / net / wireless / intel / ipw2x00 / libipw_geo.c
blobf2ae3f8f2f5cb36c62f0bf2e57fa1210a158ca0f
1 // SPDX-License-Identifier: GPL-2.0-only
2 /******************************************************************************
4 Copyright(c) 2005 Intel Corporation. All rights reserved.
7 Contact Information:
8 Intel Linux Wireless <ilw@linux.intel.com>
9 Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497
11 ******************************************************************************/
12 #include <linux/compiler.h>
13 #include <linux/errno.h>
14 #include <linux/if_arp.h>
15 #include <linux/in6.h>
16 #include <linux/in.h>
17 #include <linux/ip.h>
18 #include <linux/kernel.h>
19 #include <linux/module.h>
20 #include <linux/netdevice.h>
21 #include <linux/proc_fs.h>
22 #include <linux/skbuff.h>
23 #include <linux/tcp.h>
24 #include <linux/types.h>
25 #include <linux/wireless.h>
26 #include <linux/etherdevice.h>
27 #include <linux/uaccess.h>
29 #include "libipw.h"
31 int libipw_is_valid_channel(struct libipw_device *ieee, u8 channel)
33 int i;
35 /* Driver needs to initialize the geography map before using
36 * these helper functions */
37 if (ieee->geo.bg_channels == 0 && ieee->geo.a_channels == 0)
38 return 0;
40 if (ieee->freq_band & LIBIPW_24GHZ_BAND)
41 for (i = 0; i < ieee->geo.bg_channels; i++)
42 /* NOTE: If G mode is currently supported but
43 * this is a B only channel, we don't see it
44 * as valid. */
45 if ((ieee->geo.bg[i].channel == channel) &&
46 !(ieee->geo.bg[i].flags & LIBIPW_CH_INVALID) &&
47 (!(ieee->mode & IEEE_G) ||
48 !(ieee->geo.bg[i].flags & LIBIPW_CH_B_ONLY)))
49 return LIBIPW_24GHZ_BAND;
51 if (ieee->freq_band & LIBIPW_52GHZ_BAND)
52 for (i = 0; i < ieee->geo.a_channels; i++)
53 if ((ieee->geo.a[i].channel == channel) &&
54 !(ieee->geo.a[i].flags & LIBIPW_CH_INVALID))
55 return LIBIPW_52GHZ_BAND;
57 return 0;
60 int libipw_channel_to_index(struct libipw_device *ieee, u8 channel)
62 int i;
64 /* Driver needs to initialize the geography map before using
65 * these helper functions */
66 if (ieee->geo.bg_channels == 0 && ieee->geo.a_channels == 0)
67 return -1;
69 if (ieee->freq_band & LIBIPW_24GHZ_BAND)
70 for (i = 0; i < ieee->geo.bg_channels; i++)
71 if (ieee->geo.bg[i].channel == channel)
72 return i;
74 if (ieee->freq_band & LIBIPW_52GHZ_BAND)
75 for (i = 0; i < ieee->geo.a_channels; i++)
76 if (ieee->geo.a[i].channel == channel)
77 return i;
79 return -1;
82 u32 libipw_channel_to_freq(struct libipw_device * ieee, u8 channel)
84 const struct libipw_channel * ch;
86 /* Driver needs to initialize the geography map before using
87 * these helper functions */
88 if (ieee->geo.bg_channels == 0 && ieee->geo.a_channels == 0)
89 return 0;
91 ch = libipw_get_channel(ieee, channel);
92 if (!ch->channel)
93 return 0;
94 return ch->freq;
97 u8 libipw_freq_to_channel(struct libipw_device * ieee, u32 freq)
99 int i;
101 /* Driver needs to initialize the geography map before using
102 * these helper functions */
103 if (ieee->geo.bg_channels == 0 && ieee->geo.a_channels == 0)
104 return 0;
106 freq /= 100000;
108 if (ieee->freq_band & LIBIPW_24GHZ_BAND)
109 for (i = 0; i < ieee->geo.bg_channels; i++)
110 if (ieee->geo.bg[i].freq == freq)
111 return ieee->geo.bg[i].channel;
113 if (ieee->freq_band & LIBIPW_52GHZ_BAND)
114 for (i = 0; i < ieee->geo.a_channels; i++)
115 if (ieee->geo.a[i].freq == freq)
116 return ieee->geo.a[i].channel;
118 return 0;
121 void libipw_set_geo(struct libipw_device *ieee,
122 const struct libipw_geo *geo)
124 memcpy(ieee->geo.name, geo->name, 3);
125 ieee->geo.name[3] = '\0';
126 ieee->geo.bg_channels = geo->bg_channels;
127 ieee->geo.a_channels = geo->a_channels;
128 memcpy(ieee->geo.bg, geo->bg, geo->bg_channels *
129 sizeof(struct libipw_channel));
130 memcpy(ieee->geo.a, geo->a, ieee->geo.a_channels *
131 sizeof(struct libipw_channel));
134 const struct libipw_geo *libipw_get_geo(struct libipw_device *ieee)
136 return &ieee->geo;
139 u8 libipw_get_channel_flags(struct libipw_device * ieee, u8 channel)
141 int index = libipw_channel_to_index(ieee, channel);
143 if (index == -1)
144 return LIBIPW_CH_INVALID;
146 if (channel <= LIBIPW_24GHZ_CHANNELS)
147 return ieee->geo.bg[index].flags;
149 return ieee->geo.a[index].flags;
152 static const struct libipw_channel bad_channel = {
153 .channel = 0,
154 .flags = LIBIPW_CH_INVALID,
155 .max_power = 0,
158 const struct libipw_channel *libipw_get_channel(struct libipw_device
159 *ieee, u8 channel)
161 int index = libipw_channel_to_index(ieee, channel);
163 if (index == -1)
164 return &bad_channel;
166 if (channel <= LIBIPW_24GHZ_CHANNELS)
167 return &ieee->geo.bg[index];
169 return &ieee->geo.a[index];
172 EXPORT_SYMBOL(libipw_get_channel);
173 EXPORT_SYMBOL(libipw_get_channel_flags);
174 EXPORT_SYMBOL(libipw_is_valid_channel);
175 EXPORT_SYMBOL(libipw_freq_to_channel);
176 EXPORT_SYMBOL(libipw_channel_to_freq);
177 EXPORT_SYMBOL(libipw_channel_to_index);
178 EXPORT_SYMBOL(libipw_set_geo);
179 EXPORT_SYMBOL(libipw_get_geo);