diff options
author | Tomas Winkler <tomas.winkler@intel.com> | 2008-11-07 12:58:41 -0500 |
---|---|---|
committer | John W. Linville <linville@tuxdriver.com> | 2008-11-21 11:07:23 -0500 |
commit | 21c339bf51ad46c6f8143df907b4bcce99dbe0b8 (patch) | |
tree | 6f3c6eff45fc7b7308a3c2fe467291bb7e452d5a /drivers/net | |
parent | 4ddbb7d060061e584cb2137f4c7e41e502a560b4 (diff) |
iwlwifi: move spectrum measurement code to iwl-spectrum.c file
This patch moves spectrum measurement code into iwl-sepctrum.c file.
Signed-off-by: Tomas Winkler <tomas.winkler@intel.com>
Signed-off-by: Reinette Chatre <reinette.chatre@intel.com>
Signed-off-by: John W. Linville <linville@tuxdriver.com>
Diffstat (limited to 'drivers/net')
-rw-r--r-- | drivers/net/wireless/iwlwifi/Makefile | 1 | ||||
-rw-r--r-- | drivers/net/wireless/iwlwifi/iwl-agn.c | 229 | ||||
-rw-r--r-- | drivers/net/wireless/iwlwifi/iwl-core.h | 8 | ||||
-rw-r--r-- | drivers/net/wireless/iwlwifi/iwl-spectrum.c | 198 | ||||
-rw-r--r-- | drivers/net/wireless/iwlwifi/iwl-spectrum.h | 1 |
5 files changed, 209 insertions, 228 deletions
diff --git a/drivers/net/wireless/iwlwifi/Makefile b/drivers/net/wireless/iwlwifi/Makefile index 47aa28f6a513..8b45b30e6d5c 100644 --- a/drivers/net/wireless/iwlwifi/Makefile +++ b/drivers/net/wireless/iwlwifi/Makefile | |||
@@ -5,6 +5,7 @@ iwlcore-objs += iwl-scan.o | |||
5 | iwlcore-$(CONFIG_IWLWIFI_DEBUGFS) += iwl-debugfs.o | 5 | iwlcore-$(CONFIG_IWLWIFI_DEBUGFS) += iwl-debugfs.o |
6 | iwlcore-$(CONFIG_IWLWIFI_LEDS) += iwl-led.o | 6 | iwlcore-$(CONFIG_IWLWIFI_LEDS) += iwl-led.o |
7 | iwlcore-$(CONFIG_IWLWIFI_RFKILL) += iwl-rfkill.o | 7 | iwlcore-$(CONFIG_IWLWIFI_RFKILL) += iwl-rfkill.o |
8 | iwlcore-$(CONFIG_IWLAGN_SPECTRUM_MEASUREMENT) += iwl-spectrum.o | ||
8 | 9 | ||
9 | obj-$(CONFIG_IWLAGN) += iwlagn.o | 10 | obj-$(CONFIG_IWLAGN) += iwlagn.o |
10 | iwlagn-objs := iwl-agn.o iwl-agn-rs.o | 11 | iwlagn-objs := iwl-agn.o iwl-agn-rs.o |
diff --git a/drivers/net/wireless/iwlwifi/iwl-agn.c b/drivers/net/wireless/iwlwifi/iwl-agn.c index a9000f14e704..8fa4f7a2dc1a 100644 --- a/drivers/net/wireless/iwlwifi/iwl-agn.c +++ b/drivers/net/wireless/iwlwifi/iwl-agn.c | |||
@@ -871,138 +871,6 @@ static void iwl_set_rate(struct iwl_priv *priv) | |||
871 | (IWL_OFDM_BASIC_RATES_MASK >> IWL_FIRST_OFDM_RATE) & 0xFF; | 871 | (IWL_OFDM_BASIC_RATES_MASK >> IWL_FIRST_OFDM_RATE) & 0xFF; |
872 | } | 872 | } |
873 | 873 | ||
874 | #ifdef CONFIG_IWLAGN_SPECTRUM_MEASUREMENT | ||
875 | |||
876 | #include "iwl-spectrum.h" | ||
877 | |||
878 | #define BEACON_TIME_MASK_LOW 0x00FFFFFF | ||
879 | #define BEACON_TIME_MASK_HIGH 0xFF000000 | ||
880 | #define TIME_UNIT 1024 | ||
881 | |||
882 | /* | ||
883 | * extended beacon time format | ||
884 | * time in usec will be changed into a 32-bit value in 8:24 format | ||
885 | * the high 1 byte is the beacon counts | ||
886 | * the lower 3 bytes is the time in usec within one beacon interval | ||
887 | */ | ||
888 | |||
889 | static u32 iwl_usecs_to_beacons(u32 usec, u32 beacon_interval) | ||
890 | { | ||
891 | u32 quot; | ||
892 | u32 rem; | ||
893 | u32 interval = beacon_interval * 1024; | ||
894 | |||
895 | if (!interval || !usec) | ||
896 | return 0; | ||
897 | |||
898 | quot = (usec / interval) & (BEACON_TIME_MASK_HIGH >> 24); | ||
899 | rem = (usec % interval) & BEACON_TIME_MASK_LOW; | ||
900 | |||
901 | return (quot << 24) + rem; | ||
902 | } | ||
903 | |||
904 | /* base is usually what we get from ucode with each received frame, | ||
905 | * the same as HW timer counter counting down | ||
906 | */ | ||
907 | |||
908 | static __le32 iwl_add_beacon_time(u32 base, u32 addon, u32 beacon_interval) | ||
909 | { | ||
910 | u32 base_low = base & BEACON_TIME_MASK_LOW; | ||
911 | u32 addon_low = addon & BEACON_TIME_MASK_LOW; | ||
912 | u32 interval = beacon_interval * TIME_UNIT; | ||
913 | u32 res = (base & BEACON_TIME_MASK_HIGH) + | ||
914 | (addon & BEACON_TIME_MASK_HIGH); | ||
915 | |||
916 | if (base_low > addon_low) | ||
917 | res += base_low - addon_low; | ||
918 | else if (base_low < addon_low) { | ||
919 | res += interval + base_low - addon_low; | ||
920 | res += (1 << 24); | ||
921 | } else | ||
922 | res += (1 << 24); | ||
923 | |||
924 | return cpu_to_le32(res); | ||
925 | } | ||
926 | |||
927 | static int iwl_get_measurement(struct iwl_priv *priv, | ||
928 | struct ieee80211_measurement_params *params, | ||
929 | u8 type) | ||
930 | { | ||
931 | struct iwl4965_spectrum_cmd spectrum; | ||
932 | struct iwl_rx_packet *res; | ||
933 | struct iwl_host_cmd cmd = { | ||
934 | .id = REPLY_SPECTRUM_MEASUREMENT_CMD, | ||
935 | .data = (void *)&spectrum, | ||
936 | .meta.flags = CMD_WANT_SKB, | ||
937 | }; | ||
938 | u32 add_time = le64_to_cpu(params->start_time); | ||
939 | int rc; | ||
940 | int spectrum_resp_status; | ||
941 | int duration = le16_to_cpu(params->duration); | ||
942 | |||
943 | if (iwl_is_associated(priv)) | ||
944 | add_time = | ||
945 | iwl_usecs_to_beacons( | ||
946 | le64_to_cpu(params->start_time) - priv->last_tsf, | ||
947 | le16_to_cpu(priv->rxon_timing.beacon_interval)); | ||
948 | |||
949 | memset(&spectrum, 0, sizeof(spectrum)); | ||
950 | |||
951 | spectrum.channel_count = cpu_to_le16(1); | ||
952 | spectrum.flags = | ||
953 | RXON_FLG_TSF2HOST_MSK | RXON_FLG_ANT_A_MSK | RXON_FLG_DIS_DIV_MSK; | ||
954 | spectrum.filter_flags = MEASUREMENT_FILTER_FLAG; | ||
955 | cmd.len = sizeof(spectrum); | ||
956 | spectrum.len = cpu_to_le16(cmd.len - sizeof(spectrum.len)); | ||
957 | |||
958 | if (iwl_is_associated(priv)) | ||
959 | spectrum.start_time = | ||
960 | iwl_add_beacon_time(priv->last_beacon_time, | ||
961 | add_time, | ||
962 | le16_to_cpu(priv->rxon_timing.beacon_interval)); | ||
963 | else | ||
964 | spectrum.start_time = 0; | ||
965 | |||
966 | spectrum.channels[0].duration = cpu_to_le32(duration * TIME_UNIT); | ||
967 | spectrum.channels[0].channel = params->channel; | ||
968 | spectrum.channels[0].type = type; | ||
969 | if (priv->active_rxon.flags & RXON_FLG_BAND_24G_MSK) | ||
970 | spectrum.flags |= RXON_FLG_BAND_24G_MSK | | ||
971 | RXON_FLG_AUTO_DETECT_MSK | RXON_FLG_TGG_PROTECT_MSK; | ||
972 | |||
973 | rc = iwl_send_cmd_sync(priv, &cmd); | ||
974 | if (rc) | ||
975 | return rc; | ||
976 | |||
977 | res = (struct iwl_rx_packet *)cmd.meta.u.skb->data; | ||
978 | if (res->hdr.flags & IWL_CMD_FAILED_MSK) { | ||
979 | IWL_ERROR("Bad return from REPLY_RX_ON_ASSOC command\n"); | ||
980 | rc = -EIO; | ||
981 | } | ||
982 | |||
983 | spectrum_resp_status = le16_to_cpu(res->u.spectrum.status); | ||
984 | switch (spectrum_resp_status) { | ||
985 | case 0: /* Command will be handled */ | ||
986 | if (res->u.spectrum.id != 0xff) { | ||
987 | IWL_DEBUG_INFO | ||
988 | ("Replaced existing measurement: %d\n", | ||
989 | res->u.spectrum.id); | ||
990 | priv->measurement_status &= ~MEASUREMENT_READY; | ||
991 | } | ||
992 | priv->measurement_status |= MEASUREMENT_ACTIVE; | ||
993 | rc = 0; | ||
994 | break; | ||
995 | |||
996 | case 1: /* Command will not be handled */ | ||
997 | rc = -EAGAIN; | ||
998 | break; | ||
999 | } | ||
1000 | |||
1001 | dev_kfree_skb_any(cmd.meta.u.skb); | ||
1002 | |||
1003 | return rc; | ||
1004 | } | ||
1005 | #endif | ||
1006 | 874 | ||
1007 | /****************************************************************************** | 875 | /****************************************************************************** |
1008 | * | 876 | * |
@@ -1072,24 +940,6 @@ static void iwl_rx_csa(struct iwl_priv *priv, struct iwl_rx_mem_buffer *rxb) | |||
1072 | priv->staging_rxon.channel = csa->channel; | 940 | priv->staging_rxon.channel = csa->channel; |
1073 | } | 941 | } |
1074 | 942 | ||
1075 | static void iwl_rx_spectrum_measure_notif(struct iwl_priv *priv, | ||
1076 | struct iwl_rx_mem_buffer *rxb) | ||
1077 | { | ||
1078 | #ifdef CONFIG_IWLAGN_SPECTRUM_MEASUREMENT | ||
1079 | struct iwl_rx_packet *pkt = (struct iwl_rx_packet *)rxb->skb->data; | ||
1080 | struct iwl4965_spectrum_notification *report = &(pkt->u.spectrum_notif); | ||
1081 | |||
1082 | if (!report->state) { | ||
1083 | IWL_DEBUG(IWL_DL_11H, | ||
1084 | "Spectrum Measure Notification: Start\n"); | ||
1085 | return; | ||
1086 | } | ||
1087 | |||
1088 | memcpy(&priv->measure_report, report, sizeof(*report)); | ||
1089 | priv->measurement_status |= MEASUREMENT_READY; | ||
1090 | #endif | ||
1091 | } | ||
1092 | |||
1093 | static void iwl_rx_pm_sleep_notif(struct iwl_priv *priv, | 943 | static void iwl_rx_pm_sleep_notif(struct iwl_priv *priv, |
1094 | struct iwl_rx_mem_buffer *rxb) | 944 | struct iwl_rx_mem_buffer *rxb) |
1095 | { | 945 | { |
@@ -1298,8 +1148,6 @@ static void iwl_setup_rx_handlers(struct iwl_priv *priv) | |||
1298 | priv->rx_handlers[REPLY_ALIVE] = iwl_rx_reply_alive; | 1148 | priv->rx_handlers[REPLY_ALIVE] = iwl_rx_reply_alive; |
1299 | priv->rx_handlers[REPLY_ERROR] = iwl_rx_reply_error; | 1149 | priv->rx_handlers[REPLY_ERROR] = iwl_rx_reply_error; |
1300 | priv->rx_handlers[CHANNEL_SWITCH_NOTIFICATION] = iwl_rx_csa; | 1150 | priv->rx_handlers[CHANNEL_SWITCH_NOTIFICATION] = iwl_rx_csa; |
1301 | priv->rx_handlers[SPECTRUM_MEASURE_NOTIFICATION] = | ||
1302 | iwl_rx_spectrum_measure_notif; | ||
1303 | priv->rx_handlers[PM_SLEEP_NOTIFICATION] = iwl_rx_pm_sleep_notif; | 1151 | priv->rx_handlers[PM_SLEEP_NOTIFICATION] = iwl_rx_pm_sleep_notif; |
1304 | priv->rx_handlers[PM_DEBUG_STATISTIC_NOTIFIC] = | 1152 | priv->rx_handlers[PM_DEBUG_STATISTIC_NOTIFIC] = |
1305 | iwl_rx_pm_debug_statistics_notif; | 1153 | iwl_rx_pm_debug_statistics_notif; |
@@ -1313,6 +1161,7 @@ static void iwl_setup_rx_handlers(struct iwl_priv *priv) | |||
1313 | priv->rx_handlers[REPLY_STATISTICS_CMD] = iwl_rx_statistics; | 1161 | priv->rx_handlers[REPLY_STATISTICS_CMD] = iwl_rx_statistics; |
1314 | priv->rx_handlers[STATISTICS_NOTIFICATION] = iwl_rx_statistics; | 1162 | priv->rx_handlers[STATISTICS_NOTIFICATION] = iwl_rx_statistics; |
1315 | 1163 | ||
1164 | iwl_setup_spectrum_handlers(priv); | ||
1316 | iwl_setup_rx_scan_handlers(priv); | 1165 | iwl_setup_rx_scan_handlers(priv); |
1317 | 1166 | ||
1318 | /* status change handler */ | 1167 | /* status change handler */ |
@@ -3767,79 +3616,6 @@ static ssize_t store_filter_flags(struct device *d, | |||
3767 | static DEVICE_ATTR(filter_flags, S_IWUSR | S_IRUGO, show_filter_flags, | 3616 | static DEVICE_ATTR(filter_flags, S_IWUSR | S_IRUGO, show_filter_flags, |
3768 | store_filter_flags); | 3617 | store_filter_flags); |
3769 | 3618 | ||
3770 | #ifdef CONFIG_IWLAGN_SPECTRUM_MEASUREMENT | ||
3771 | |||
3772 | static ssize_t show_measurement(struct device *d, | ||
3773 | struct device_attribute *attr, char *buf) | ||
3774 | { | ||
3775 | struct iwl_priv *priv = dev_get_drvdata(d); | ||
3776 | struct iwl4965_spectrum_notification measure_report; | ||
3777 | u32 size = sizeof(measure_report), len = 0, ofs = 0; | ||
3778 | u8 *data = (u8 *)&measure_report; | ||
3779 | unsigned long flags; | ||
3780 | |||
3781 | spin_lock_irqsave(&priv->lock, flags); | ||
3782 | if (!(priv->measurement_status & MEASUREMENT_READY)) { | ||
3783 | spin_unlock_irqrestore(&priv->lock, flags); | ||
3784 | return 0; | ||
3785 | } | ||
3786 | memcpy(&measure_report, &priv->measure_report, size); | ||
3787 | priv->measurement_status = 0; | ||
3788 | spin_unlock_irqrestore(&priv->lock, flags); | ||
3789 | |||
3790 | while (size && (PAGE_SIZE - len)) { | ||
3791 | hex_dump_to_buffer(data + ofs, size, 16, 1, buf + len, | ||
3792 | PAGE_SIZE - len, 1); | ||
3793 | len = strlen(buf); | ||
3794 | if (PAGE_SIZE - len) | ||
3795 | buf[len++] = '\n'; | ||
3796 | |||
3797 | ofs += 16; | ||
3798 | size -= min(size, 16U); | ||
3799 | } | ||
3800 | |||
3801 | return len; | ||
3802 | } | ||
3803 | |||
3804 | static ssize_t store_measurement(struct device *d, | ||
3805 | struct device_attribute *attr, | ||
3806 | const char *buf, size_t count) | ||
3807 | { | ||
3808 | struct iwl_priv *priv = dev_get_drvdata(d); | ||
3809 | struct ieee80211_measurement_params params = { | ||
3810 | .channel = le16_to_cpu(priv->active_rxon.channel), | ||
3811 | .start_time = cpu_to_le64(priv->last_tsf), | ||
3812 | .duration = cpu_to_le16(1), | ||
3813 | }; | ||
3814 | u8 type = IWL_MEASURE_BASIC; | ||
3815 | u8 buffer[32]; | ||
3816 | u8 channel; | ||
3817 | |||
3818 | if (count) { | ||
3819 | char *p = buffer; | ||
3820 | strncpy(buffer, buf, min(sizeof(buffer), count)); | ||
3821 | channel = simple_strtoul(p, NULL, 0); | ||
3822 | if (channel) | ||
3823 | params.channel = channel; | ||
3824 | |||
3825 | p = buffer; | ||
3826 | while (*p && *p != ' ') | ||
3827 | p++; | ||
3828 | if (*p) | ||
3829 | type = simple_strtoul(p + 1, NULL, 0); | ||
3830 | } | ||
3831 | |||
3832 | IWL_DEBUG_INFO("Invoking measurement of type %d on " | ||
3833 | "channel %d (for '%s')\n", type, params.channel, buf); | ||
3834 | iwl_get_measurement(priv, ¶ms, type); | ||
3835 | |||
3836 | return count; | ||
3837 | } | ||
3838 | |||
3839 | static DEVICE_ATTR(measurement, S_IRUSR | S_IWUSR, | ||
3840 | show_measurement, store_measurement); | ||
3841 | #endif /* CONFIG_IWLAGN_SPECTRUM_MEASUREMENT */ | ||
3842 | |||
3843 | static ssize_t store_retry_rate(struct device *d, | 3619 | static ssize_t store_retry_rate(struct device *d, |
3844 | struct device_attribute *attr, | 3620 | struct device_attribute *attr, |
3845 | const char *buf, size_t count) | 3621 | const char *buf, size_t count) |
@@ -4092,9 +3868,6 @@ static struct attribute *iwl_sysfs_entries[] = { | |||
4092 | &dev_attr_channels.attr, | 3868 | &dev_attr_channels.attr, |
4093 | &dev_attr_flags.attr, | 3869 | &dev_attr_flags.attr, |
4094 | &dev_attr_filter_flags.attr, | 3870 | &dev_attr_filter_flags.attr, |
4095 | #ifdef CONFIG_IWLAGN_SPECTRUM_MEASUREMENT | ||
4096 | &dev_attr_measurement.attr, | ||
4097 | #endif | ||
4098 | &dev_attr_power_level.attr, | 3871 | &dev_attr_power_level.attr, |
4099 | &dev_attr_retry_rate.attr, | 3872 | &dev_attr_retry_rate.attr, |
4100 | &dev_attr_statistics.attr, | 3873 | &dev_attr_statistics.attr, |
diff --git a/drivers/net/wireless/iwlwifi/iwl-core.h b/drivers/net/wireless/iwlwifi/iwl-core.h index 1ae7a11e80d4..ff966b8a0c6d 100644 --- a/drivers/net/wireless/iwlwifi/iwl-core.h +++ b/drivers/net/wireless/iwlwifi/iwl-core.h | |||
@@ -289,6 +289,14 @@ int iwl_send_calib_results(struct iwl_priv *priv); | |||
289 | int iwl_calib_set(struct iwl_calib_result *res, const u8 *buf, int len); | 289 | int iwl_calib_set(struct iwl_calib_result *res, const u8 *buf, int len); |
290 | void iwl_calib_free_results(struct iwl_priv *priv); | 290 | void iwl_calib_free_results(struct iwl_priv *priv); |
291 | 291 | ||
292 | /******************************************************************************* | ||
293 | * Spectrum Measureemtns in iwl-spectrum.c | ||
294 | ******************************************************************************/ | ||
295 | #ifdef CONFIG_IWLAGN_SPECTRUM_MEASUREMENT | ||
296 | void iwl_setup_spectrum_handlers(struct iwl_priv *priv); | ||
297 | #else | ||
298 | static inline void iwl_setup_spectrum_handlers(struct iwl_priv *priv) {} | ||
299 | #endif | ||
292 | /***************************************************** | 300 | /***************************************************** |
293 | * S e n d i n g H o s t C o m m a n d s * | 301 | * S e n d i n g H o s t C o m m a n d s * |
294 | *****************************************************/ | 302 | *****************************************************/ |
diff --git a/drivers/net/wireless/iwlwifi/iwl-spectrum.c b/drivers/net/wireless/iwlwifi/iwl-spectrum.c new file mode 100644 index 000000000000..ad319a178a90 --- /dev/null +++ b/drivers/net/wireless/iwlwifi/iwl-spectrum.c | |||
@@ -0,0 +1,198 @@ | |||
1 | /****************************************************************************** | ||
2 | * | ||
3 | * Copyright(c) 2003 - 2008 Intel Corporation. All rights reserved. | ||
4 | * | ||
5 | * Portions of this file are derived from the ipw3945 project, as well | ||
6 | * as portions of the ieee80211 subsystem header files. | ||
7 | * | ||
8 | * This program is free software; you can redistribute it and/or modify it | ||
9 | * under the terms of version 2 of the GNU General Public License as | ||
10 | * published by the Free Software Foundation. | ||
11 | * | ||
12 | * This program is distributed in the hope that it will be useful, but WITHOUT | ||
13 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | ||
14 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for | ||
15 | * more details. | ||
16 | * | ||
17 | * You should have received a copy of the GNU General Public License along with | ||
18 | * this program; if not, write to the Free Software Foundation, Inc., | ||
19 | * 51 Franklin Street, Fifth Floor, Boston, MA 02110, USA | ||
20 | * | ||
21 | * The full GNU General Public License is included in this distribution in the | ||
22 | * file called LICENSE. | ||
23 | * | ||
24 | * Contact Information: | ||
25 | * Intel Linux Wireless <ilw@linux.intel.com> | ||
26 | * Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497 | ||
27 | * | ||
28 | *****************************************************************************/ | ||
29 | |||
30 | #include <linux/kernel.h> | ||
31 | #include <linux/module.h> | ||
32 | #include <linux/init.h> | ||
33 | #include <linux/pci.h> | ||
34 | #include <linux/delay.h> | ||
35 | #include <linux/skbuff.h> | ||
36 | #include <linux/netdevice.h> | ||
37 | #include <linux/wireless.h> | ||
38 | |||
39 | #include <net/mac80211.h> | ||
40 | |||
41 | #include "iwl-eeprom.h" | ||
42 | #include "iwl-dev.h" | ||
43 | #include "iwl-core.h" | ||
44 | #include "iwl-io.h" | ||
45 | #include "iwl-spectrum.h" | ||
46 | |||
47 | #define BEACON_TIME_MASK_LOW 0x00FFFFFF | ||
48 | #define BEACON_TIME_MASK_HIGH 0xFF000000 | ||
49 | #define TIME_UNIT 1024 | ||
50 | |||
51 | /* | ||
52 | * extended beacon time format | ||
53 | * time in usec will be changed into a 32-bit value in 8:24 format | ||
54 | * the high 1 byte is the beacon counts | ||
55 | * the lower 3 bytes is the time in usec within one beacon interval | ||
56 | */ | ||
57 | |||
58 | /* TOOD: was used in sysfs debug interface need to add to mac */ | ||
59 | #if 0 | ||
60 | static u32 iwl_usecs_to_beacons(u32 usec, u32 beacon_interval) | ||
61 | { | ||
62 | u32 quot; | ||
63 | u32 rem; | ||
64 | u32 interval = beacon_interval * 1024; | ||
65 | |||
66 | if (!interval || !usec) | ||
67 | return 0; | ||
68 | |||
69 | quot = (usec / interval) & (BEACON_TIME_MASK_HIGH >> 24); | ||
70 | rem = (usec % interval) & BEACON_TIME_MASK_LOW; | ||
71 | |||
72 | return (quot << 24) + rem; | ||
73 | } | ||
74 | |||
75 | /* base is usually what we get from ucode with each received frame, | ||
76 | * the same as HW timer counter counting down | ||
77 | */ | ||
78 | |||
79 | static __le32 iwl_add_beacon_time(u32 base, u32 addon, u32 beacon_interval) | ||
80 | { | ||
81 | u32 base_low = base & BEACON_TIME_MASK_LOW; | ||
82 | u32 addon_low = addon & BEACON_TIME_MASK_LOW; | ||
83 | u32 interval = beacon_interval * TIME_UNIT; | ||
84 | u32 res = (base & BEACON_TIME_MASK_HIGH) + | ||
85 | (addon & BEACON_TIME_MASK_HIGH); | ||
86 | |||
87 | if (base_low > addon_low) | ||
88 | res += base_low - addon_low; | ||
89 | else if (base_low < addon_low) { | ||
90 | res += interval + base_low - addon_low; | ||
91 | res += (1 << 24); | ||
92 | } else | ||
93 | res += (1 << 24); | ||
94 | |||
95 | return cpu_to_le32(res); | ||
96 | } | ||
97 | static int iwl_get_measurement(struct iwl_priv *priv, | ||
98 | struct ieee80211_measurement_params *params, | ||
99 | u8 type) | ||
100 | { | ||
101 | struct iwl4965_spectrum_cmd spectrum; | ||
102 | struct iwl_rx_packet *res; | ||
103 | struct iwl_host_cmd cmd = { | ||
104 | .id = REPLY_SPECTRUM_MEASUREMENT_CMD, | ||
105 | .data = (void *)&spectrum, | ||
106 | .meta.flags = CMD_WANT_SKB, | ||
107 | }; | ||
108 | u32 add_time = le64_to_cpu(params->start_time); | ||
109 | int rc; | ||
110 | int spectrum_resp_status; | ||
111 | int duration = le16_to_cpu(params->duration); | ||
112 | |||
113 | if (iwl_is_associated(priv)) | ||
114 | add_time = | ||
115 | iwl_usecs_to_beacons( | ||
116 | le64_to_cpu(params->start_time) - priv->last_tsf, | ||
117 | le16_to_cpu(priv->rxon_timing.beacon_interval)); | ||
118 | |||
119 | memset(&spectrum, 0, sizeof(spectrum)); | ||
120 | |||
121 | spectrum.channel_count = cpu_to_le16(1); | ||
122 | spectrum.flags = | ||
123 | RXON_FLG_TSF2HOST_MSK | RXON_FLG_ANT_A_MSK | RXON_FLG_DIS_DIV_MSK; | ||
124 | spectrum.filter_flags = MEASUREMENT_FILTER_FLAG; | ||
125 | cmd.len = sizeof(spectrum); | ||
126 | spectrum.len = cpu_to_le16(cmd.len - sizeof(spectrum.len)); | ||
127 | |||
128 | if (iwl_is_associated(priv)) | ||
129 | spectrum.start_time = | ||
130 | iwl_add_beacon_time(priv->last_beacon_time, | ||
131 | add_time, | ||
132 | le16_to_cpu(priv->rxon_timing.beacon_interval)); | ||
133 | else | ||
134 | spectrum.start_time = 0; | ||
135 | |||
136 | spectrum.channels[0].duration = cpu_to_le32(duration * TIME_UNIT); | ||
137 | spectrum.channels[0].channel = params->channel; | ||
138 | spectrum.channels[0].type = type; | ||
139 | if (priv->active_rxon.flags & RXON_FLG_BAND_24G_MSK) | ||
140 | spectrum.flags |= RXON_FLG_BAND_24G_MSK | | ||
141 | RXON_FLG_AUTO_DETECT_MSK | RXON_FLG_TGG_PROTECT_MSK; | ||
142 | |||
143 | rc = iwl_send_cmd_sync(priv, &cmd); | ||
144 | if (rc) | ||
145 | return rc; | ||
146 | |||
147 | res = (struct iwl_rx_packet *)cmd.meta.u.skb->data; | ||
148 | if (res->hdr.flags & IWL_CMD_FAILED_MSK) { | ||
149 | IWL_ERROR("Bad return from REPLY_RX_ON_ASSOC command\n"); | ||
150 | rc = -EIO; | ||
151 | } | ||
152 | |||
153 | spectrum_resp_status = le16_to_cpu(res->u.spectrum.status); | ||
154 | switch (spectrum_resp_status) { | ||
155 | case 0: /* Command will be handled */ | ||
156 | if (res->u.spectrum.id != 0xff) { | ||
157 | IWL_DEBUG_INFO | ||
158 | ("Replaced existing measurement: %d\n", | ||
159 | res->u.spectrum.id); | ||
160 | priv->measurement_status &= ~MEASUREMENT_READY; | ||
161 | } | ||
162 | priv->measurement_status |= MEASUREMENT_ACTIVE; | ||
163 | rc = 0; | ||
164 | break; | ||
165 | |||
166 | case 1: /* Command will not be handled */ | ||
167 | rc = -EAGAIN; | ||
168 | break; | ||
169 | } | ||
170 | |||
171 | dev_kfree_skb_any(cmd.meta.u.skb); | ||
172 | |||
173 | return rc; | ||
174 | } | ||
175 | #endif | ||
176 | |||
177 | static void iwl_rx_spectrum_measure_notif(struct iwl_priv *priv, | ||
178 | struct iwl_rx_mem_buffer *rxb) | ||
179 | { | ||
180 | struct iwl_rx_packet *pkt = (struct iwl_rx_packet *)rxb->skb->data; | ||
181 | struct iwl4965_spectrum_notification *report = &(pkt->u.spectrum_notif); | ||
182 | |||
183 | if (!report->state) { | ||
184 | IWL_DEBUG(IWL_DL_11H, | ||
185 | "Spectrum Measure Notification: Start\n"); | ||
186 | return; | ||
187 | } | ||
188 | |||
189 | memcpy(&priv->measure_report, report, sizeof(*report)); | ||
190 | priv->measurement_status |= MEASUREMENT_READY; | ||
191 | } | ||
192 | |||
193 | void iwl_setup_spectrum_handlers(struct iwl_priv *priv) | ||
194 | { | ||
195 | priv->rx_handlers[SPECTRUM_MEASURE_NOTIFICATION] = | ||
196 | iwl_rx_spectrum_measure_notif; | ||
197 | } | ||
198 | EXPORT_SYMBOL(iwl_setup_spectrum_handlers); | ||
diff --git a/drivers/net/wireless/iwlwifi/iwl-spectrum.h b/drivers/net/wireless/iwlwifi/iwl-spectrum.h index a40a2174df98..fa990a102515 100644 --- a/drivers/net/wireless/iwlwifi/iwl-spectrum.h +++ b/drivers/net/wireless/iwlwifi/iwl-spectrum.h | |||
@@ -88,4 +88,5 @@ struct ieee80211_measurement_report { | |||
88 | struct ieee80211_basic_report basic[0]; | 88 | struct ieee80211_basic_report basic[0]; |
89 | } u; | 89 | } u; |
90 | } __attribute__ ((packed)); | 90 | } __attribute__ ((packed)); |
91 | |||
91 | #endif | 92 | #endif |